@cocreate/elements 1.35.2 → 1.35.4
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 +16 -0
- package/package.json +1 -1
- package/src/index.js +39 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## [1.35.4](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.35.3...v1.35.4) (2024-05-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* handle if item is already read ([2407f9b](https://github.com/CoCreate-app/CoCreate-elements/commit/2407f9b3789173fddb8f8ed6b4bb90f7f8d17864))
|
|
7
|
+
|
|
8
|
+
## [1.35.3](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.35.2...v1.35.3) (2024-05-08)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* handling of data upsert ([9884f90](https://github.com/CoCreate-app/CoCreate-elements/commit/9884f90b3b9e0016b266a36e6e5b377dc93fc6b7))
|
|
14
|
+
* replace form object attribute with id if pending ([33838fb](https://github.com/CoCreate-app/CoCreate-elements/commit/33838fbe3e12f6a6b4e8fbcaa76822315b61ccdd))
|
|
15
|
+
* typo with for loop index j ([8872c9f](https://github.com/CoCreate-app/CoCreate-elements/commit/8872c9f7b009638018ac48ffec41898a618b0cdd))
|
|
16
|
+
|
|
1
17
|
## [1.35.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.35.1...v1.35.2) (2024-04-29)
|
|
2
18
|
|
|
3
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.35.
|
|
3
|
+
"version": "1.35.4",
|
|
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
|
@@ -78,13 +78,19 @@ async function init(element) {
|
|
|
78
78
|
read(Array.from(elements.keys()), data, { string: key });
|
|
79
79
|
}
|
|
80
80
|
}
|
|
81
|
+
|
|
82
|
+
// const evt = new CustomEvent('elementsInitialized', { bubbles: true });
|
|
83
|
+
// document.dispatchEvent(evt);
|
|
84
|
+
|
|
81
85
|
}
|
|
82
86
|
|
|
83
87
|
async function initElement(el) {
|
|
84
88
|
// if (el.closest('.template')) return;
|
|
85
89
|
|
|
86
90
|
let data = getObject(el);
|
|
87
|
-
if (!data || !data.type)
|
|
91
|
+
if (!data || !data.type)
|
|
92
|
+
return
|
|
93
|
+
|
|
88
94
|
if (data.object && data.object !== 'pending' && !(/^[0-9a-fA-F]{24}$/.test(data.object)))
|
|
89
95
|
return
|
|
90
96
|
|
|
@@ -113,6 +119,7 @@ async function initElement(el) {
|
|
|
113
119
|
|
|
114
120
|
el.setFilter = (filter) => {
|
|
115
121
|
data.$filter = filter
|
|
122
|
+
el.hasRead = false
|
|
116
123
|
// let dataKey = initDataKey(el, data)
|
|
117
124
|
read(el, data)
|
|
118
125
|
}
|
|
@@ -134,7 +141,7 @@ function getObject(element) {
|
|
|
134
141
|
data[crudType[i]] = []
|
|
135
142
|
|
|
136
143
|
for (let j = 0; j < array.length; j++) {
|
|
137
|
-
array[
|
|
144
|
+
array[j].trim()
|
|
138
145
|
if (crudType[i] === 'object') {
|
|
139
146
|
data[crudType[i]].push({ _id: array[j] })
|
|
140
147
|
} else {
|
|
@@ -227,8 +234,12 @@ async function read(element, data, dataKey) {
|
|
|
227
234
|
|
|
228
235
|
for (let el of element) {
|
|
229
236
|
const isRead = el.getAttribute('read');
|
|
230
|
-
if (isRead !== 'false')
|
|
237
|
+
if (isRead !== 'false' && !el.hasRead) {
|
|
238
|
+
el.hasRead = true
|
|
231
239
|
delay.elements.set(el, true)
|
|
240
|
+
} else {
|
|
241
|
+
console.log('read skipped', el)
|
|
242
|
+
}
|
|
232
243
|
}
|
|
233
244
|
|
|
234
245
|
if (!delay.elements.size)
|
|
@@ -247,8 +258,18 @@ async function read(element, data, dataKey) {
|
|
|
247
258
|
data.object = { _id: data.object[0]._id }
|
|
248
259
|
} else if (!data.object._id.match(/^[0-9a-fA-F]{24}$/))
|
|
249
260
|
return
|
|
261
|
+
// if (data.object._id.startsWith('$'))
|
|
262
|
+
// return
|
|
250
263
|
}
|
|
251
264
|
|
|
265
|
+
// if (data.object && !Array.isArray(data.object) && data.object._id.startsWith('$'))
|
|
266
|
+
// return
|
|
267
|
+
|
|
268
|
+
// if (data.$filter && data.$filter.query) {
|
|
269
|
+
// if (!Object.keys(data.$filter.query).length)
|
|
270
|
+
// return
|
|
271
|
+
// }
|
|
272
|
+
|
|
252
273
|
data.method = data.type + '.read'
|
|
253
274
|
|
|
254
275
|
CRUD.send(data).then((Data) => {
|
|
@@ -393,7 +414,7 @@ async function filterData(element, data, type, key) {
|
|
|
393
414
|
let property = key.replace(operator + '.', '')
|
|
394
415
|
|
|
395
416
|
if (Array.isArray(data[type])) {
|
|
396
|
-
let Data = []
|
|
417
|
+
let Data = [], isObject
|
|
397
418
|
for (let doc of data[type]) {
|
|
398
419
|
// TODO: should have been handled by getDataElements()
|
|
399
420
|
if (type === 'object') {
|
|
@@ -410,14 +431,17 @@ async function filterData(element, data, type, key) {
|
|
|
410
431
|
if (doc[property]) {
|
|
411
432
|
if (Array.isArray(doc[property]))
|
|
412
433
|
Data.push(...doc[property])
|
|
413
|
-
else
|
|
434
|
+
else {
|
|
435
|
+
isObject = true
|
|
414
436
|
Data.push(doc[property])
|
|
437
|
+
}
|
|
415
438
|
} else
|
|
416
439
|
return
|
|
417
440
|
}
|
|
418
|
-
|
|
441
|
+
|
|
442
|
+
// if (isObject && Data.length === 1) {
|
|
419
443
|
// data = { [property]: Data[0] }
|
|
420
|
-
// } else
|
|
444
|
+
// } else
|
|
421
445
|
if (!operator)
|
|
422
446
|
data = Data
|
|
423
447
|
else if (operator === '$sum') {
|
|
@@ -863,6 +887,11 @@ async function save(element) {
|
|
|
863
887
|
}
|
|
864
888
|
}
|
|
865
889
|
|
|
890
|
+
if (data[i].isUpsert) {
|
|
891
|
+
data[i].upsert = true
|
|
892
|
+
delete data[i].isUpsert
|
|
893
|
+
}
|
|
894
|
+
|
|
866
895
|
if (data[i].method && data[i].method.endsWith('.create')) {
|
|
867
896
|
element.setAttribute(data[i].type, 'pending');
|
|
868
897
|
} else if (data[i].method && data[i].method.endsWith('.update') && data[i].type == 'object' && typeof value == 'string' && window.CoCreate.crdt && !'crdt') {
|
|
@@ -910,6 +939,9 @@ function setTypeValue(element, data) {
|
|
|
910
939
|
}
|
|
911
940
|
} else {
|
|
912
941
|
let formObject = forms.get(form)
|
|
942
|
+
if (form.getAttribute('object') === 'pending')
|
|
943
|
+
form.setAttribute('object', data.object[0]._id)
|
|
944
|
+
|
|
913
945
|
let elements = formObject.types.get(data.type)
|
|
914
946
|
|
|
915
947
|
for (let [el, Data] of elements.entries()) {
|