@cocreate/elements 1.36.1 → 1.37.0
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 +15 -0
- package/package.json +1 -1
- package/src/fetchSrc.js +1 -1
- package/src/index.js +37 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# [1.37.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.36.2...v1.37.0) (2024-09-21)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* update="" attribute support. improved data type handling ([fa478b0](https://github.com/CoCreate-app/CoCreate-elements/commit/fa478b008c85a78014f16f4800270af933767615))
|
|
7
|
+
|
|
8
|
+
## [1.36.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.36.1...v1.36.2) (2024-08-24)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* prevent duplicate input event listeners ([e7d5bfd](https://github.com/CoCreate-app/CoCreate-elements/commit/e7d5bfd7c254b9e4a76bd5eb55106b86357904c9))
|
|
14
|
+
* use continue in for loop ([e0febbc](https://github.com/CoCreate-app/CoCreate-elements/commit/e0febbcbf16486d54e312cd646f2d2a255e71848))
|
|
15
|
+
|
|
1
16
|
## [1.36.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.36.0...v1.36.1) (2024-07-09)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.37.0",
|
|
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/fetchSrc.js
CHANGED
|
@@ -19,7 +19,7 @@ async function initElements(elements) {
|
|
|
19
19
|
let src = element.getAttribute('src') || element.getAttribute('source') || element.getAttribute('stream');
|
|
20
20
|
|
|
21
21
|
if (!src || /{{\s*([\w\W]+)\s*}}/g.test(src))
|
|
22
|
-
|
|
22
|
+
continue;
|
|
23
23
|
|
|
24
24
|
let initialize = initializing.get(element)
|
|
25
25
|
if (!initialize || initialize.src != src) {
|
package/src/index.js
CHANGED
|
@@ -97,18 +97,26 @@ async function initElement(el) {
|
|
|
97
97
|
if (!elements.has(el)) {
|
|
98
98
|
elements.set(el, '')
|
|
99
99
|
|
|
100
|
-
if (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
el.
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
100
|
+
if (el.tagName === "EDITOR")
|
|
101
|
+
console.log('editor event added')
|
|
102
|
+
if (!el.elementsInputEvent) {
|
|
103
|
+
el.elementsInputEvent = true;
|
|
104
|
+
|
|
105
|
+
if (['INPUT', 'TEXTAREA', 'SELECT'].includes(el.tagName)
|
|
106
|
+
|| (el.hasAttribute('contenteditable') && el.getAttribute('contenteditable') !== 'false')
|
|
107
|
+
|| el.contenteditable) {
|
|
108
|
+
el.addEventListener('input', function (e) {
|
|
109
|
+
if (el.pendingObject) return
|
|
110
|
+
|
|
111
|
+
const { object, key, isRealtime, isCrdt } = getAttributes(el);
|
|
112
|
+
if (!isRealtime || isRealtime === "false" || key === "_id") return;
|
|
113
|
+
if (isCrdt == "true" && object && object !== 'pending') return
|
|
114
|
+
if (e.detail && e.detail.skip == true) return;
|
|
115
|
+
if (data.type !== 'object' && data[data.type] === 'pending') return
|
|
116
|
+
|
|
117
|
+
save(el);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
112
120
|
}
|
|
113
121
|
}
|
|
114
122
|
// let attributes = ['filter-key', 'filter-search', 'filter-sort-key', 'filter-on', 'filter-limit']
|
|
@@ -365,7 +373,7 @@ async function setData(element, data) {
|
|
|
365
373
|
let action = el.getAttribute('actions')
|
|
366
374
|
if (action && ['database', 'array', 'object', 'key'].includes(action)) continue;
|
|
367
375
|
|
|
368
|
-
const { key, isRead, isListen, isCrdt } = getAttributes(el);
|
|
376
|
+
const { key, isRead, isUpdate, isListen, isCrdt } = getAttributes(el);
|
|
369
377
|
if (el.getFilter || el.renderValue)
|
|
370
378
|
await filterData(el, data, type, key)
|
|
371
379
|
else {
|
|
@@ -390,8 +398,8 @@ async function setData(element, data) {
|
|
|
390
398
|
}
|
|
391
399
|
|
|
392
400
|
if (!data[type].length) continue;
|
|
393
|
-
if (isRead
|
|
394
|
-
if (isListen
|
|
401
|
+
if (isRead === "false" || isCrdt === "true") continue;
|
|
402
|
+
if (isUpdate === "false" || isListen === "false" && !data.method.endsWith('.read')) continue;
|
|
395
403
|
// TODO: object.update data returned from server will not include $operator
|
|
396
404
|
el.setValue(value);
|
|
397
405
|
|
|
@@ -519,7 +527,8 @@ async function checkFilters(element, data, type) {
|
|
|
519
527
|
// TODO: fix: getObject as this is related to render or form, but filter could exist on an input which does not have getObject
|
|
520
528
|
// TODO: generate an object of current element key: value to use with filter. because filter is used object is not defined
|
|
521
529
|
Data = getObject(element)
|
|
522
|
-
|
|
530
|
+
if (Array.isArray(Data[type]))
|
|
531
|
+
Data = Data[type][0]
|
|
523
532
|
} else
|
|
524
533
|
Data = await element.getData()
|
|
525
534
|
|
|
@@ -561,9 +570,20 @@ async function checkFilters(element, data, type) {
|
|
|
561
570
|
primaryKey = 'name';
|
|
562
571
|
}
|
|
563
572
|
|
|
564
|
-
if (
|
|
573
|
+
if (Array.isArray(newData)) {
|
|
574
|
+
for (let i = 0; i < newData.length; i++) {
|
|
575
|
+
if (typeof Data === 'string' && Data === newData[i][primaryKey]) {
|
|
576
|
+
Data = newData[i]
|
|
577
|
+
} else if (Data[primaryKey] === newData[i][primaryKey]) {
|
|
578
|
+
Data = dotNotationToObject(newData[i], Data)
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
} else if (typeof Data === 'string' && Data === newData[primaryKey]) {
|
|
582
|
+
Data = newData
|
|
583
|
+
} else if (Data[primaryKey] === newData[primaryKey]) {
|
|
565
584
|
Data = dotNotationToObject(newData, Data)
|
|
566
585
|
}
|
|
586
|
+
|
|
567
587
|
if (element.renderValue)
|
|
568
588
|
element.renderValue(data);
|
|
569
589
|
// render({ element, data, key: type });
|