@cocreate/elements 1.26.1 → 1.26.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/package.json +8 -8
- package/src/index.js +56 -33
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## [1.26.3](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.26.2...v1.26.3) (2023-11-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* element grouping ([0507b00](https://github.com/CoCreate-app/CoCreate-elements/commit/0507b00fa53a2c1ec774885d6da515c48fcc4f85))
|
|
7
|
+
|
|
8
|
+
## [1.26.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.26.1...v1.26.2) (2023-11-12)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* await renderValue ([b08c609](https://github.com/CoCreate-app/CoCreate-elements/commit/b08c6093c9f6451ea7d54d20811aff81fd276cec))
|
|
14
|
+
* bump dependencies for latest features ([fdbaa9a](https://github.com/CoCreate-app/CoCreate-elements/commit/fdbaa9adb52b50b9e5db149e0c76472e0ea51d88))
|
|
15
|
+
* crud listeners ([68c014e](https://github.com/CoCreate-app/CoCreate-elements/commit/68c014eaa99eaf5fc2de45c8ebdce58bc36fba97))
|
|
16
|
+
* improve removeNodes ([f34e0cf](https://github.com/CoCreate-app/CoCreate-elements/commit/f34e0cfb43367ddcd2dd2b80422e9ade7d69a7f1))
|
|
17
|
+
* removed dead code ([22cb1fb](https://github.com/CoCreate-app/CoCreate-elements/commit/22cb1fb810a8ff5b4b61d4746cfe23b9cf6adefd))
|
|
18
|
+
* set $filter.index ([c51ffa8](https://github.com/CoCreate-app/CoCreate-elements/commit/c51ffa8aca3182fa4b9b85a76c226852614470b4))
|
|
19
|
+
* typo in handeling form ([71361e2](https://github.com/CoCreate-app/CoCreate-elements/commit/71361e2423231767138dd35cf62e7c443a823130))
|
|
20
|
+
|
|
1
21
|
## [1.26.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.26.0...v1.26.1) (2023-11-09)
|
|
2
22
|
|
|
3
23
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.26.
|
|
3
|
+
"version": "1.26.3",
|
|
4
4
|
"description": "Fetch content into any html element by using html5 attributes to query data stored in CoCreate headless CMS. If data is changed it will instantly reflect in html tags as changes are broadcasted in realtime",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"elements",
|
|
@@ -58,12 +58,12 @@
|
|
|
58
58
|
"webpack-log": "^3.0.1"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@cocreate/actions": "^1.12.
|
|
62
|
-
"@cocreate/crud-client": "^1.28.
|
|
63
|
-
"@cocreate/element-prototype": "^1.
|
|
64
|
-
"@cocreate/filter": "^1.23.
|
|
65
|
-
"@cocreate/observer": "^1.11.
|
|
66
|
-
"@cocreate/render": "^1.
|
|
67
|
-
"@cocreate/utils": "^1.
|
|
61
|
+
"@cocreate/actions": "^1.12.3",
|
|
62
|
+
"@cocreate/crud-client": "^1.28.14",
|
|
63
|
+
"@cocreate/element-prototype": "^1.13.0",
|
|
64
|
+
"@cocreate/filter": "^1.23.8",
|
|
65
|
+
"@cocreate/observer": "^1.11.9",
|
|
66
|
+
"@cocreate/render": "^1.30.1",
|
|
67
|
+
"@cocreate/utils": "^1.27.1"
|
|
68
68
|
}
|
|
69
69
|
}
|
package/src/index.js
CHANGED
|
@@ -38,7 +38,6 @@ const keys = new Map();
|
|
|
38
38
|
const forms = new Map();
|
|
39
39
|
const debounce = new Map();
|
|
40
40
|
|
|
41
|
-
/** */
|
|
42
41
|
async function init(element) {
|
|
43
42
|
if (element && !(element instanceof HTMLCollection) && !Array.isArray(element))
|
|
44
43
|
element = [element]
|
|
@@ -49,7 +48,7 @@ async function init(element) {
|
|
|
49
48
|
|
|
50
49
|
let dataObjects = new Map();
|
|
51
50
|
for (let i = 0; i < element.length; i++) {
|
|
52
|
-
if (elements.has(element[i]) || element.tagName === 'FORM')
|
|
51
|
+
if (elements.has(element[i]) || element[i].tagName === 'FORM')
|
|
53
52
|
continue
|
|
54
53
|
|
|
55
54
|
let data = await initElement(element[i]);
|
|
@@ -61,8 +60,8 @@ async function init(element) {
|
|
|
61
60
|
|
|
62
61
|
if (dataObjects && dataObjects.size > 0) {
|
|
63
62
|
for (let key of dataObjects.keys()) {
|
|
64
|
-
let { data } = keys.get(key)
|
|
65
|
-
read(Array.from(
|
|
63
|
+
let { data, elements } = keys.get(key)
|
|
64
|
+
read(Array.from(elements.keys()), data, { string: key });
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
}
|
|
@@ -126,15 +125,11 @@ async function initElement(el) {
|
|
|
126
125
|
|
|
127
126
|
el.setFilter = (filter) => {
|
|
128
127
|
data.$filter = filter
|
|
129
|
-
let dataKey = initDataKey(el, data)
|
|
130
|
-
read(el, data
|
|
128
|
+
// let dataKey = initDataKey(el, data)
|
|
129
|
+
read(el, data)
|
|
131
130
|
}
|
|
132
131
|
}
|
|
133
132
|
|
|
134
|
-
const isRead = el.getAttribute('read');
|
|
135
|
-
if (isRead === 'false')
|
|
136
|
-
return;
|
|
137
|
-
|
|
138
133
|
return data;
|
|
139
134
|
}
|
|
140
135
|
|
|
@@ -161,7 +156,7 @@ function getObject(element) {
|
|
|
161
156
|
}
|
|
162
157
|
}
|
|
163
158
|
|
|
164
|
-
if (data.object || data.object === '') {
|
|
159
|
+
if (data.object || data.object === '' || data.key || data.key === '') {
|
|
165
160
|
if (!data.array || data.array && !data.array.length) return
|
|
166
161
|
data.type = 'object'
|
|
167
162
|
} else if (data.index || data.index === '') {
|
|
@@ -224,6 +219,11 @@ async function read(element, data, dataKey) {
|
|
|
224
219
|
if (!data)
|
|
225
220
|
data = { ...keys.get(dataKey).dataKey.object }
|
|
226
221
|
|
|
222
|
+
if (!data.type)
|
|
223
|
+
return
|
|
224
|
+
if (!data.$filter && (!data[data.type] || !data[data.type].length))
|
|
225
|
+
return
|
|
226
|
+
|
|
227
227
|
if (!(element instanceof HTMLCollection) && !Array.isArray(element))
|
|
228
228
|
element = [element]
|
|
229
229
|
|
|
@@ -234,8 +234,14 @@ async function read(element, data, dataKey) {
|
|
|
234
234
|
if (!delay.elements)
|
|
235
235
|
delay.elements = new Map()
|
|
236
236
|
|
|
237
|
-
for (let el of element)
|
|
238
|
-
|
|
237
|
+
for (let el of element) {
|
|
238
|
+
const isRead = el.getAttribute('read');
|
|
239
|
+
if (isRead !== 'false')
|
|
240
|
+
delay.elements.set(el, true)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
if (!delay.elements.size)
|
|
244
|
+
return
|
|
239
245
|
|
|
240
246
|
clearTimeout(delay.timer);
|
|
241
247
|
delay.timer = setTimeout(function () {
|
|
@@ -254,14 +260,14 @@ async function read(element, data, dataKey) {
|
|
|
254
260
|
|
|
255
261
|
data.method = data.type + '.read'
|
|
256
262
|
|
|
257
|
-
CRUD.send(data).then((
|
|
263
|
+
CRUD.send(data).then((Data) => {
|
|
258
264
|
debounce.delete(dataKey.string)
|
|
259
265
|
let els = Array.from(delay.elements.keys())
|
|
260
266
|
clearTimeout(delay.timer);
|
|
261
267
|
delete delay.elements
|
|
262
268
|
delete delay.timer
|
|
263
269
|
|
|
264
|
-
setData(els,
|
|
270
|
+
setData(els, Data);
|
|
265
271
|
})
|
|
266
272
|
}, 500);
|
|
267
273
|
}
|
|
@@ -320,10 +326,10 @@ async function filterData(element, data, type, key) {
|
|
|
320
326
|
Data.push(doc[key])
|
|
321
327
|
}
|
|
322
328
|
}
|
|
323
|
-
if (Data.length === 1) {
|
|
324
|
-
|
|
325
|
-
} else
|
|
326
|
-
|
|
329
|
+
// if (Data.length === 1) {
|
|
330
|
+
// data = { [key]: Data[0] }
|
|
331
|
+
// } else
|
|
332
|
+
data = Data
|
|
327
333
|
} else {
|
|
328
334
|
data = { [key]: data[type][key] }
|
|
329
335
|
}
|
|
@@ -331,12 +337,14 @@ async function filterData(element, data, type, key) {
|
|
|
331
337
|
|
|
332
338
|
if (element.getFilter && data.method && !data.method.endsWith('.read'))
|
|
333
339
|
await checkFilters(element, data, type)
|
|
334
|
-
else if (element.renderValue)
|
|
335
|
-
element.renderValue(data);
|
|
336
|
-
|
|
337
|
-
else if (data)
|
|
340
|
+
else if (element.renderValue) {
|
|
341
|
+
await element.renderValue(data);
|
|
342
|
+
} else if (data)
|
|
338
343
|
element.setValue(data)
|
|
339
344
|
|
|
345
|
+
if (data.$filter)
|
|
346
|
+
filter.filters.get(element).index = data.$filter.index
|
|
347
|
+
|
|
340
348
|
const evt = new CustomEvent('fetchedData', { bubbles: true });
|
|
341
349
|
element.dispatchEvent(evt);
|
|
342
350
|
}
|
|
@@ -687,7 +695,7 @@ async function save(element) {
|
|
|
687
695
|
|
|
688
696
|
let Data = []
|
|
689
697
|
for (let i = 0; i < data.length; i++) {
|
|
690
|
-
if (data[i].type === 'object'
|
|
698
|
+
if (data[i].type === 'object') {
|
|
691
699
|
if (typeof data[i].object === 'string') {
|
|
692
700
|
if (!data[i]._id)
|
|
693
701
|
data[i].method = 'object.create'
|
|
@@ -855,6 +863,8 @@ async function remove(element) {
|
|
|
855
863
|
let key = elements.get(element[i])
|
|
856
864
|
if (key) {
|
|
857
865
|
keys.get(key).elements.delete(element[i])
|
|
866
|
+
if (!keys.get(key).elements.size)
|
|
867
|
+
keys.delete(key)
|
|
858
868
|
}
|
|
859
869
|
elements.delete(element[i])
|
|
860
870
|
forms.delete(element[i])
|
|
@@ -862,26 +872,35 @@ async function remove(element) {
|
|
|
862
872
|
|
|
863
873
|
let key = elements.get(element[i])
|
|
864
874
|
if (key) {
|
|
875
|
+
if (element[i].getFilter)
|
|
876
|
+
filter.filters.delete(element[i])
|
|
865
877
|
keys.get(key).elements.delete(element[i])
|
|
866
878
|
elements.delete(element[i])
|
|
879
|
+
if (!keys.get(key).elements.size)
|
|
880
|
+
keys.delete(key)
|
|
881
|
+
|
|
867
882
|
// debounce.delete(key)
|
|
868
883
|
let form = element[i].closest('form')
|
|
869
884
|
form = forms.get(form)
|
|
870
885
|
if (form) {
|
|
871
886
|
form.elements.delete(element[i])
|
|
887
|
+
if (!form.elements.size)
|
|
888
|
+
forms.delete(form)
|
|
872
889
|
}
|
|
873
|
-
}
|
|
890
|
+
} else
|
|
891
|
+
elements.delete(element[i])
|
|
892
|
+
|
|
874
893
|
}
|
|
875
894
|
}
|
|
876
895
|
}
|
|
877
896
|
|
|
878
897
|
function initSocket() {
|
|
879
|
-
const
|
|
880
|
-
const
|
|
898
|
+
const type = ["storage", "database", "array", "index", "object", 'filter'];
|
|
899
|
+
const method = ['create', 'update', 'delete'];
|
|
881
900
|
|
|
882
|
-
for (let i = 0; i <
|
|
883
|
-
for (let j = 0; j <
|
|
884
|
-
const action =
|
|
901
|
+
for (let i = 0; i < type.length; i++) {
|
|
902
|
+
for (let j = 0; j < method.length; j++) {
|
|
903
|
+
const action = type[i] + '.' + method[j];
|
|
885
904
|
|
|
886
905
|
CRUD.listen(action, function (data) {
|
|
887
906
|
setData(null, data);
|
|
@@ -1049,7 +1068,8 @@ Observer.init({
|
|
|
1049
1068
|
// }, 3000);
|
|
1050
1069
|
// debounce.set(mutation.target, delayTimer)
|
|
1051
1070
|
// } else
|
|
1052
|
-
if (mutation.target.hasAttribute('render-clone'))
|
|
1071
|
+
if (mutation.target.hasAttribute('render-clone'))
|
|
1072
|
+
return
|
|
1053
1073
|
remove(mutation.target)
|
|
1054
1074
|
}
|
|
1055
1075
|
});
|
|
@@ -1060,8 +1080,11 @@ Observer.init({
|
|
|
1060
1080
|
attributeName: ['storage', 'database', 'array', 'index', 'object', 'key'],
|
|
1061
1081
|
// target: selector, // blocks mutations when applied
|
|
1062
1082
|
callback: function (mutation) {
|
|
1063
|
-
|
|
1064
|
-
|
|
1083
|
+
let currentValue = mutation.target.getAttribute(mutation.attributeName)
|
|
1084
|
+
if (currentValue !== mutation.oldValue) {
|
|
1085
|
+
remove(mutation.target)
|
|
1086
|
+
init([mutation.target])
|
|
1087
|
+
}
|
|
1065
1088
|
}
|
|
1066
1089
|
});
|
|
1067
1090
|
|