@cocreate/elements 1.29.0 → 1.30.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 +19 -0
- package/package.json +1 -1
- package/src/index.js +23 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
# [1.30.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.29.1...v1.30.0) (2023-12-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* spread render import ([19e7abd](https://github.com/CoCreate-app/CoCreate-elements/commit/19e7abdb4ebcccfd05a79d17ad4c8681546b4ce5))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* handle resolved property and set index for create ([5e0d92d](https://github.com/CoCreate-app/CoCreate-elements/commit/5e0d92d37f26e2916f5c2b748d8c571f9814198a))
|
|
12
|
+
|
|
13
|
+
## [1.29.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.29.0...v1.29.1) (2023-12-15)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* handle arrays ([7ea1e12](https://github.com/CoCreate-app/CoCreate-elements/commit/7ea1e12d89d95aae1dca23b38d80b899fa4cddd6))
|
|
19
|
+
|
|
1
20
|
# [1.29.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.28.0...v1.29.0) (2023-11-25)
|
|
2
21
|
|
|
3
22
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.30.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/index.js
CHANGED
|
@@ -27,7 +27,7 @@ import Actions from '@cocreate/actions';
|
|
|
27
27
|
import CRUD from '@cocreate/crud-client';
|
|
28
28
|
import { dotNotationToObject, queryElements, queryData, sortData, getAttributes, getAttributeNames, checkValue } from '@cocreate/utils';
|
|
29
29
|
import filter from '@cocreate/filter';
|
|
30
|
-
import render from '@cocreate/render';
|
|
30
|
+
import { render, renderValue, renderedNodes } from '@cocreate/render';
|
|
31
31
|
import '@cocreate/element-prototype';
|
|
32
32
|
import './fetchSrc';
|
|
33
33
|
import { reset } from './form'
|
|
@@ -86,13 +86,13 @@ async function initElement(el) {
|
|
|
86
86
|
// if found add the node as an element, if the element has crud attributes also add as the element
|
|
87
87
|
for (let attribute of el.attributes) {
|
|
88
88
|
if (attribute.match(/{{(.*?)}}/)) {
|
|
89
|
-
let value =
|
|
89
|
+
let value = renderValue(attribute, undefined, attribute.value)
|
|
90
90
|
if (value)
|
|
91
91
|
attribute.value = value
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
94
|
if (el.innerHTML.match(/{{(.*?)}}/)) {
|
|
95
|
-
let value =
|
|
95
|
+
let value = renderValue(el, undefined, el.innerHTML)
|
|
96
96
|
if (value)
|
|
97
97
|
attribute.value = value
|
|
98
98
|
}
|
|
@@ -333,6 +333,12 @@ async function filterData(element, data, type, key) {
|
|
|
333
333
|
if (Array.isArray(data[type])) {
|
|
334
334
|
let Data = []
|
|
335
335
|
for (let doc of data[type]) {
|
|
336
|
+
// TODO: should have been handled by getDataElements()
|
|
337
|
+
if (type === 'object') {
|
|
338
|
+
let _id = element.getAttribute('object')
|
|
339
|
+
if (_id && doc._id !== _id)
|
|
340
|
+
return
|
|
341
|
+
}
|
|
336
342
|
if (doc[key]) {
|
|
337
343
|
if (Array.isArray(doc[key]))
|
|
338
344
|
Data.push(...doc[key])
|
|
@@ -435,6 +441,8 @@ function checkIndex(element, data, Data, newData, type, filter) {
|
|
|
435
441
|
data.$filter.create = true
|
|
436
442
|
if (filter && filter.sort)
|
|
437
443
|
newData.isNewData = true
|
|
444
|
+
else
|
|
445
|
+
index = Data.length
|
|
438
446
|
Data.push(newData)
|
|
439
447
|
}
|
|
440
448
|
} else {
|
|
@@ -525,11 +533,6 @@ function getDataKeys(data) {
|
|
|
525
533
|
const matches = sortedKey.data[key].some(value => {
|
|
526
534
|
if (key === 'object') {
|
|
527
535
|
return data[key].some(obj => {
|
|
528
|
-
if (data.array.includes('users'))
|
|
529
|
-
console.log('users')
|
|
530
|
-
if (data.array.includes('questions'))
|
|
531
|
-
console.log('questions')
|
|
532
|
-
|
|
533
536
|
return obj._id === value._id
|
|
534
537
|
});
|
|
535
538
|
} else {
|
|
@@ -602,13 +605,20 @@ async function getData(form) {
|
|
|
602
605
|
}
|
|
603
606
|
}
|
|
604
607
|
|
|
605
|
-
|
|
606
608
|
if (Data.type = 'object') {
|
|
607
609
|
if (typeof Data[Data.type] === 'string')
|
|
608
610
|
if (Data.key == '{}')
|
|
609
611
|
Data[Data.type] = { _id: Data[Data.type], ...value }
|
|
610
612
|
else
|
|
611
613
|
Data[Data.type] = { _id: Data[Data.type], [Data.key]: value }
|
|
614
|
+
else if (Array.isArray(Data[Data.type]))
|
|
615
|
+
if (Data.key == '{}')
|
|
616
|
+
Data[Data.type][0] = { ...Data[Data.type][0], ...value }
|
|
617
|
+
else {
|
|
618
|
+
Data[Data.type][0][Data.key] = value
|
|
619
|
+
if (!Data[Data.type][0]._id)
|
|
620
|
+
Data.method = Data.type + '.create'
|
|
621
|
+
}
|
|
612
622
|
else if (typeof Data[Data.type] === 'object')
|
|
613
623
|
if (Data.key == '{}')
|
|
614
624
|
Data[Data.type] = { ...Data[Data.type], ...value }
|
|
@@ -937,6 +947,8 @@ function initSocket() {
|
|
|
937
947
|
const action = type[i] + '.' + method[j];
|
|
938
948
|
|
|
939
949
|
CRUD.listen(action, function (data) {
|
|
950
|
+
if (data.resolved && data.status === 'received' && CRUD.socket.clientId === data.clientId)
|
|
951
|
+
return
|
|
940
952
|
setData(null, data);
|
|
941
953
|
});
|
|
942
954
|
}
|
|
@@ -952,7 +964,7 @@ Observer.init({
|
|
|
952
964
|
clearTimeout(delayTimer);
|
|
953
965
|
debounce.delete(mutation.target)
|
|
954
966
|
|
|
955
|
-
let renderedNode =
|
|
967
|
+
let renderedNode = renderedNodes.get(mutation.target)
|
|
956
968
|
if (!renderedNode) return
|
|
957
969
|
|
|
958
970
|
if (!mutation.movedFrom) return
|
|
@@ -1059,7 +1071,7 @@ function dndNewData(element, data) {
|
|
|
1059
1071
|
|
|
1060
1072
|
let keyPath, clonesMap, clones, index
|
|
1061
1073
|
|
|
1062
|
-
let renderedNode =
|
|
1074
|
+
let renderedNode = renderedNodes.get(element)
|
|
1063
1075
|
if (renderedNode) {
|
|
1064
1076
|
keyPath = renderedNode.keyPath
|
|
1065
1077
|
clonesMap = renderedNode.template.clones
|