@cocreate/elements 1.20.2 → 1.21.1
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/CoCreate.config.js +2 -1
- package/package.json +8 -8
- package/src/index.js +43 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,23 @@
|
|
|
1
|
+
## [1.21.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.21.0...v1.21.1) (2023-09-18)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Add path and pathname ([3335926](https://github.com/CoCreate-app/CoCreate-elements/commit/3335926a4b9e1a16a4da399e0c92f2322c1f9f6d))
|
|
7
|
+
* Update dCoCreate dpendencies to latest versions ([0c93f61](https://github.com/CoCreate-app/CoCreate-elements/commit/0c93f6190b77ca92d49a8066736ff00ec0ecec0e))
|
|
8
|
+
|
|
9
|
+
# [1.21.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.20.2...v1.21.0) (2023-09-17)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* filter renamed to $filter ([02ecdcf](https://github.com/CoCreate-app/CoCreate-elements/commit/02ecdcf8f12fc49b7e1537caa7b1f56625b693be))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* support key {}, merges object with value ([dba003a](https://github.com/CoCreate-app/CoCreate-elements/commit/dba003a8bd327021f639ba93f4cba662a8c5ea43))
|
|
20
|
+
|
|
1
21
|
## [1.20.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.20.1...v1.20.2) (2023-09-07)
|
|
2
22
|
|
|
3
23
|
|
package/CoCreate.config.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.1",
|
|
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.11.
|
|
62
|
-
"@cocreate/crud-client": "^1.
|
|
63
|
-
"@cocreate/element-prototype": "^1.11.
|
|
64
|
-
"@cocreate/filter": "^1.22.
|
|
65
|
-
"@cocreate/observer": "^1.11.
|
|
66
|
-
"@cocreate/render": "^1.27.
|
|
67
|
-
"@cocreate/utils": "^1.24.
|
|
61
|
+
"@cocreate/actions": "^1.11.1",
|
|
62
|
+
"@cocreate/crud-client": "^1.25.0",
|
|
63
|
+
"@cocreate/element-prototype": "^1.11.1",
|
|
64
|
+
"@cocreate/filter": "^1.22.1",
|
|
65
|
+
"@cocreate/observer": "^1.11.1",
|
|
66
|
+
"@cocreate/render": "^1.27.2",
|
|
67
|
+
"@cocreate/utils": "^1.24.1"
|
|
68
68
|
}
|
|
69
69
|
}
|
package/src/index.js
CHANGED
|
@@ -15,10 +15,13 @@
|
|
|
15
15
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
16
16
|
********************************************************************************/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
/**
|
|
19
|
+
* Commercial Licensing Information:
|
|
20
|
+
* For commercial use of this software without the copyleft provisions of the AGPLv3,
|
|
21
|
+
* you must obtain a commercial license from CoCreate LLC.
|
|
22
|
+
* For details, visit <https://cocreate.app/licenses/> or contact us at sales@cocreate.app.
|
|
23
|
+
*/
|
|
24
|
+
/** */
|
|
22
25
|
|
|
23
26
|
import Observer from '@cocreate/observer';
|
|
24
27
|
import Actions from '@cocreate/actions';
|
|
@@ -118,9 +121,9 @@ function initElement(el) {
|
|
|
118
121
|
}
|
|
119
122
|
|
|
120
123
|
if (el.getFilter) {
|
|
121
|
-
data
|
|
124
|
+
data.$filter = el.getFilter();
|
|
122
125
|
el.setFilter = (filter) => {
|
|
123
|
-
data
|
|
126
|
+
data.$filter = filter
|
|
124
127
|
let dataKey = initDataKey(el, data)
|
|
125
128
|
read(el, data, dataKey)
|
|
126
129
|
}
|
|
@@ -217,7 +220,7 @@ async function read(element, data, dataKey) {
|
|
|
217
220
|
if (!dataKey)
|
|
218
221
|
dataKey = elements.get(element)
|
|
219
222
|
if (!data)
|
|
220
|
-
data = { ...keys.get(dataKey).
|
|
223
|
+
data = { ...keys.get(dataKey).dataKey.object }
|
|
221
224
|
|
|
222
225
|
let delayTimer = debounce.get(dataKey.string)
|
|
223
226
|
clearTimeout(delayTimer);
|
|
@@ -232,7 +235,8 @@ async function read(element, data, dataKey) {
|
|
|
232
235
|
return
|
|
233
236
|
}
|
|
234
237
|
|
|
235
|
-
data.method = 'read
|
|
238
|
+
data.method = 'read.' + data.type
|
|
239
|
+
|
|
236
240
|
CRUD.send(data).then((data) => {
|
|
237
241
|
setData(element, data);
|
|
238
242
|
})
|
|
@@ -364,20 +368,20 @@ function checkIndex(element, data, Data, newData, type, filter, action) {
|
|
|
364
368
|
index = Data.findIndex(obj => obj.name === newData.name);
|
|
365
369
|
}
|
|
366
370
|
|
|
367
|
-
if (!data
|
|
368
|
-
data
|
|
371
|
+
if (!data.$filter)
|
|
372
|
+
data.$filter = {}
|
|
369
373
|
|
|
370
374
|
if (action.startsWith('delete')) {
|
|
371
375
|
if (!index && index !== 0)
|
|
372
376
|
return
|
|
373
|
-
data
|
|
377
|
+
data.$filter.remove = true
|
|
374
378
|
} else {
|
|
375
379
|
if (!index && index !== 0) {
|
|
376
|
-
data
|
|
380
|
+
data.$filter.create = true
|
|
377
381
|
Data.push(newData)
|
|
378
382
|
} else {
|
|
379
|
-
data
|
|
380
|
-
data
|
|
383
|
+
data.$filter.update = true
|
|
384
|
+
data.$filter.currentIndex = index
|
|
381
385
|
Data[index] = dotNotationToObject(newData, Data[index])
|
|
382
386
|
}
|
|
383
387
|
|
|
@@ -388,9 +392,9 @@ function checkIndex(element, data, Data, newData, type, filter, action) {
|
|
|
388
392
|
}
|
|
389
393
|
|
|
390
394
|
if (index >= 0) {
|
|
391
|
-
if (data
|
|
392
|
-
delete data
|
|
393
|
-
data
|
|
395
|
+
if (data.$filter.currentIndex === index)
|
|
396
|
+
delete data.$filter.currentIndex
|
|
397
|
+
data.$filter.index = index
|
|
394
398
|
if (element.renderValue)
|
|
395
399
|
element.renderValue(data);
|
|
396
400
|
// render({ element, data, key: type });
|
|
@@ -585,17 +589,22 @@ async function save(element) {
|
|
|
585
589
|
return save(form);
|
|
586
590
|
|
|
587
591
|
let dataKey = elements.get(element)
|
|
588
|
-
data = { ...keys.get(dataKey).
|
|
592
|
+
data = { ...keys.get(dataKey).dataKey.object }
|
|
589
593
|
|
|
590
594
|
value = element.getValue();
|
|
591
595
|
|
|
592
|
-
|
|
593
|
-
data[data.type] = { _id: data[data.type], [data.key]: value }
|
|
594
|
-
else if (Array.isArray(data[data.type])) {
|
|
595
|
-
console.log('data.type is an array function incomplete')
|
|
596
|
-
} else if (typeof data[data.type] === 'object')
|
|
597
|
-
data[data.type][data.key] = value
|
|
596
|
+
let key = element.getAttribute('key')
|
|
598
597
|
|
|
598
|
+
if (typeof data[data.type] === 'string')
|
|
599
|
+
if (key == '{}')
|
|
600
|
+
data[data.type] = { _id: data[data.type], ...value }
|
|
601
|
+
else
|
|
602
|
+
data[data.type] = { _id: data[data.type], [key]: value }
|
|
603
|
+
else if (typeof data[data.type] === 'object')
|
|
604
|
+
if (key == '{}')
|
|
605
|
+
data[data.type] = { ...data[data.type], ...value }
|
|
606
|
+
else
|
|
607
|
+
data[data.type][key] = value
|
|
599
608
|
|
|
600
609
|
if (/\.([0-9]*)/g.test(data.key)) {
|
|
601
610
|
let splice = element.getAttribute('splice')
|
|
@@ -603,14 +612,15 @@ async function save(element) {
|
|
|
603
612
|
let update = element.getAttribute('update')
|
|
604
613
|
|
|
605
614
|
if (splice || splice === "") {
|
|
606
|
-
data[data.type][
|
|
615
|
+
data[data.type][key] = { $splice: value }
|
|
607
616
|
} else if (slice) {
|
|
608
|
-
data[data.type][
|
|
617
|
+
data[data.type][key] = '$delete'
|
|
609
618
|
} else if (update) {
|
|
610
619
|
value = data.key.replace(/\[.*?\]/, '[' + value + ']')
|
|
611
|
-
data.updateKey[
|
|
612
|
-
data[data.type][
|
|
613
|
-
|
|
620
|
+
data.updateKey[key] = value
|
|
621
|
+
data[data.type][key] = { $update: value } // $update is string use the value as the key name
|
|
622
|
+
|
|
623
|
+
// data[data.type][key] = { $update: {[value]: value} } // $update is an object use the key as the value to use for the new key
|
|
614
624
|
}
|
|
615
625
|
|
|
616
626
|
}
|
|
@@ -619,6 +629,8 @@ async function save(element) {
|
|
|
619
629
|
}
|
|
620
630
|
|
|
621
631
|
for (let i = 0; i < data.length; i++) {
|
|
632
|
+
data[i].method = 'update.' + data[i].type
|
|
633
|
+
|
|
622
634
|
if (data[i].method && data[i].method.startsWith('create'))
|
|
623
635
|
element.setAttribute(data[i].type, 'pending');
|
|
624
636
|
else if (data[i].method && data[i].method.startsWith('update') && data[i].type == 'object' && typeof value == 'string' && window.CoCreate.crdt && !'crdt') {
|
|
@@ -849,7 +861,7 @@ function dndCrudData(element, parent, operator) {
|
|
|
849
861
|
|
|
850
862
|
function dndNewData(element, data) {
|
|
851
863
|
let Data = {}
|
|
852
|
-
let query = data
|
|
864
|
+
let query = data.$filter.query
|
|
853
865
|
if (query && query.length) {
|
|
854
866
|
for (let i = 0; i < query.length; i++) {
|
|
855
867
|
if (query.operator === "$eq")
|
|
@@ -860,7 +872,7 @@ function dndNewData(element, data) {
|
|
|
860
872
|
}
|
|
861
873
|
|
|
862
874
|
let sortName, sortDirection
|
|
863
|
-
let sort = data
|
|
875
|
+
let sort = data.$filter.sort
|
|
864
876
|
if (sort && sort.length) {
|
|
865
877
|
// for (let i = 0; i < sort.length; i++) {
|
|
866
878
|
for (let i = sort.length - 1; i >= 0; i--) {
|