@cocreate/elements 1.26.2 → 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 +7 -0
- package/package.json +1 -1
- package/src/index.js +31 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
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
|
+
|
|
1
8
|
## [1.26.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.26.1...v1.26.2) (2023-11-12)
|
|
2
9
|
|
|
3
10
|
|
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",
|
package/src/index.js
CHANGED
|
@@ -60,8 +60,8 @@ async function init(element) {
|
|
|
60
60
|
|
|
61
61
|
if (dataObjects && dataObjects.size > 0) {
|
|
62
62
|
for (let key of dataObjects.keys()) {
|
|
63
|
-
let { data } = keys.get(key)
|
|
64
|
-
read(Array.from(
|
|
63
|
+
let { data, elements } = keys.get(key)
|
|
64
|
+
read(Array.from(elements.keys()), data, { string: key });
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
}
|
|
@@ -125,15 +125,11 @@ async function initElement(el) {
|
|
|
125
125
|
|
|
126
126
|
el.setFilter = (filter) => {
|
|
127
127
|
data.$filter = filter
|
|
128
|
-
let dataKey = initDataKey(el, data)
|
|
129
|
-
read(el, data
|
|
128
|
+
// let dataKey = initDataKey(el, data)
|
|
129
|
+
read(el, data)
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
const isRead = el.getAttribute('read');
|
|
134
|
-
if (isRead === 'false')
|
|
135
|
-
return;
|
|
136
|
-
|
|
137
133
|
return data;
|
|
138
134
|
}
|
|
139
135
|
|
|
@@ -223,6 +219,8 @@ async function read(element, data, dataKey) {
|
|
|
223
219
|
if (!data)
|
|
224
220
|
data = { ...keys.get(dataKey).dataKey.object }
|
|
225
221
|
|
|
222
|
+
if (!data.type)
|
|
223
|
+
return
|
|
226
224
|
if (!data.$filter && (!data[data.type] || !data[data.type].length))
|
|
227
225
|
return
|
|
228
226
|
|
|
@@ -236,8 +234,14 @@ async function read(element, data, dataKey) {
|
|
|
236
234
|
if (!delay.elements)
|
|
237
235
|
delay.elements = new Map()
|
|
238
236
|
|
|
239
|
-
for (let el of element)
|
|
240
|
-
|
|
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
|
|
241
245
|
|
|
242
246
|
clearTimeout(delay.timer);
|
|
243
247
|
delay.timer = setTimeout(function () {
|
|
@@ -256,14 +260,14 @@ async function read(element, data, dataKey) {
|
|
|
256
260
|
|
|
257
261
|
data.method = data.type + '.read'
|
|
258
262
|
|
|
259
|
-
CRUD.send(data).then((
|
|
263
|
+
CRUD.send(data).then((Data) => {
|
|
260
264
|
debounce.delete(dataKey.string)
|
|
261
265
|
let els = Array.from(delay.elements.keys())
|
|
262
266
|
clearTimeout(delay.timer);
|
|
263
267
|
delete delay.elements
|
|
264
268
|
delete delay.timer
|
|
265
269
|
|
|
266
|
-
setData(els,
|
|
270
|
+
setData(els, Data);
|
|
267
271
|
})
|
|
268
272
|
}, 500);
|
|
269
273
|
}
|
|
@@ -322,10 +326,10 @@ async function filterData(element, data, type, key) {
|
|
|
322
326
|
Data.push(doc[key])
|
|
323
327
|
}
|
|
324
328
|
}
|
|
325
|
-
if (Data.length === 1) {
|
|
326
|
-
|
|
327
|
-
} else
|
|
328
|
-
|
|
329
|
+
// if (Data.length === 1) {
|
|
330
|
+
// data = { [key]: Data[0] }
|
|
331
|
+
// } else
|
|
332
|
+
data = Data
|
|
329
333
|
} else {
|
|
330
334
|
data = { [key]: data[type][key] }
|
|
331
335
|
}
|
|
@@ -338,7 +342,8 @@ async function filterData(element, data, type, key) {
|
|
|
338
342
|
} else if (data)
|
|
339
343
|
element.setValue(data)
|
|
340
344
|
|
|
341
|
-
|
|
345
|
+
if (data.$filter)
|
|
346
|
+
filter.filters.get(element).index = data.$filter.index
|
|
342
347
|
|
|
343
348
|
const evt = new CustomEvent('fetchedData', { bubbles: true });
|
|
344
349
|
element.dispatchEvent(evt);
|
|
@@ -690,7 +695,7 @@ async function save(element) {
|
|
|
690
695
|
|
|
691
696
|
let Data = []
|
|
692
697
|
for (let i = 0; i < data.length; i++) {
|
|
693
|
-
if (data[i].type === 'object'
|
|
698
|
+
if (data[i].type === 'object') {
|
|
694
699
|
if (typeof data[i].object === 'string') {
|
|
695
700
|
if (!data[i]._id)
|
|
696
701
|
data[i].method = 'object.create'
|
|
@@ -882,7 +887,9 @@ async function remove(element) {
|
|
|
882
887
|
if (!form.elements.size)
|
|
883
888
|
forms.delete(form)
|
|
884
889
|
}
|
|
885
|
-
}
|
|
890
|
+
} else
|
|
891
|
+
elements.delete(element[i])
|
|
892
|
+
|
|
886
893
|
}
|
|
887
894
|
}
|
|
888
895
|
}
|
|
@@ -1073,8 +1080,11 @@ Observer.init({
|
|
|
1073
1080
|
attributeName: ['storage', 'database', 'array', 'index', 'object', 'key'],
|
|
1074
1081
|
// target: selector, // blocks mutations when applied
|
|
1075
1082
|
callback: function (mutation) {
|
|
1076
|
-
|
|
1077
|
-
|
|
1083
|
+
let currentValue = mutation.target.getAttribute(mutation.attributeName)
|
|
1084
|
+
if (currentValue !== mutation.oldValue) {
|
|
1085
|
+
remove(mutation.target)
|
|
1086
|
+
init([mutation.target])
|
|
1087
|
+
}
|
|
1078
1088
|
}
|
|
1079
1089
|
});
|
|
1080
1090
|
|