@cocreate/elements 1.20.1 → 1.21.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/CoCreate.config.js +25 -25
- package/package.json +1 -1
- package/src/index.js +52 -37
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
# [1.21.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.20.2...v1.21.0) (2023-09-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* filter renamed to $filter ([02ecdcf](https://github.com/CoCreate-app/CoCreate-elements/commit/02ecdcf8f12fc49b7e1537caa7b1f56625b693be))
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* support key {}, merges object with value ([dba003a](https://github.com/CoCreate-app/CoCreate-elements/commit/dba003a8bd327021f639ba93f4cba662a8c5ea43))
|
|
12
|
+
|
|
13
|
+
## [1.20.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.20.1...v1.20.2) (2023-09-07)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* get type from method ([274751e](https://github.com/CoCreate-app/CoCreate-elements/commit/274751e8ef66e8ef19cf8d323297599e78c82ef9))
|
|
19
|
+
|
|
1
20
|
## [1.20.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.20.0...v1.20.1) (2023-08-21)
|
|
2
21
|
|
|
3
22
|
|
package/CoCreate.config.js
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
module.exports = {
|
|
2
|
-
"organization_id": "",
|
|
3
|
-
"key": "",
|
|
4
|
-
"host": "",
|
|
5
|
-
"sources": [
|
|
6
|
-
{
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
"
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
}
|
|
1
|
+
module.exports = {
|
|
2
|
+
"organization_id": "",
|
|
3
|
+
"key": "",
|
|
4
|
+
"host": "",
|
|
5
|
+
"sources": [
|
|
6
|
+
{
|
|
7
|
+
"entry": "./docs",
|
|
8
|
+
"exclude": [
|
|
9
|
+
"demo"
|
|
10
|
+
],
|
|
11
|
+
"array": "files",
|
|
12
|
+
"object": {
|
|
13
|
+
"name": "{{name}}",
|
|
14
|
+
"src": "{{source}}",
|
|
15
|
+
"host": [
|
|
16
|
+
"*"
|
|
17
|
+
],
|
|
18
|
+
"directory": "/docs/{{directory}}",
|
|
19
|
+
"path": "{{path}}",
|
|
20
|
+
"content-type": "{{content-type}}",
|
|
21
|
+
"public": "true"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.21.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
|
@@ -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
|
})
|
|
@@ -240,7 +244,7 @@ async function read(element, data, dataKey) {
|
|
|
240
244
|
debounce.set(dataKey.string, delayTimer)
|
|
241
245
|
}
|
|
242
246
|
|
|
243
|
-
function setData(element, data
|
|
247
|
+
function setData(element, data) {
|
|
244
248
|
if (!element) {
|
|
245
249
|
element = getDataElements(data)
|
|
246
250
|
if (!element.length) return
|
|
@@ -250,8 +254,8 @@ function setData(element, data, action) {
|
|
|
250
254
|
element = [element]
|
|
251
255
|
|
|
252
256
|
let type = data.type
|
|
253
|
-
if (!type &&
|
|
254
|
-
type =
|
|
257
|
+
if (!type && data.method) {
|
|
258
|
+
type = data.method.split('.')[1]
|
|
255
259
|
} else if (type == 'key')
|
|
256
260
|
type = 'object'
|
|
257
261
|
|
|
@@ -263,7 +267,7 @@ function setData(element, data, action) {
|
|
|
263
267
|
if (!data[type])
|
|
264
268
|
continue;
|
|
265
269
|
|
|
266
|
-
action = el.getAttribute('actions')
|
|
270
|
+
let action = el.getAttribute('actions')
|
|
267
271
|
if (action && ['database', 'array', 'object', 'key'].includes(action)) continue;
|
|
268
272
|
|
|
269
273
|
const { key, isRead, isListen, isCrdt } = getAttributes(el);
|
|
@@ -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') {
|
|
@@ -751,13 +763,13 @@ function initSocket() {
|
|
|
751
763
|
const action = array[i] + '.' + attributes[j];
|
|
752
764
|
|
|
753
765
|
CRUD.listen(action, function (data) {
|
|
754
|
-
setData(null, data
|
|
766
|
+
setData(null, data);
|
|
755
767
|
});
|
|
756
768
|
}
|
|
757
769
|
}
|
|
758
770
|
|
|
759
771
|
CRUD.listen('sync', function (data) {
|
|
760
|
-
setData(null, data
|
|
772
|
+
setData(null, data);
|
|
761
773
|
});
|
|
762
774
|
|
|
763
775
|
}
|
|
@@ -838,6 +850,8 @@ function dndCrudData(element, parent, operator) {
|
|
|
838
850
|
newData[newData.type].push({ ...previousData, ...Data })
|
|
839
851
|
}
|
|
840
852
|
}
|
|
853
|
+
|
|
854
|
+
|
|
841
855
|
} else {
|
|
842
856
|
newData[newData.type] = [{ ...data[data.type][index], ...Data }]
|
|
843
857
|
}
|
|
@@ -847,7 +861,7 @@ function dndCrudData(element, parent, operator) {
|
|
|
847
861
|
|
|
848
862
|
function dndNewData(element, data) {
|
|
849
863
|
let Data = {}
|
|
850
|
-
let query = data
|
|
864
|
+
let query = data.$filter.query
|
|
851
865
|
if (query && query.length) {
|
|
852
866
|
for (let i = 0; i < query.length; i++) {
|
|
853
867
|
if (query.operator === "$eq")
|
|
@@ -858,7 +872,7 @@ function dndNewData(element, data) {
|
|
|
858
872
|
}
|
|
859
873
|
|
|
860
874
|
let sortName, sortDirection
|
|
861
|
-
let sort = data
|
|
875
|
+
let sort = data.$filter.sort
|
|
862
876
|
if (sort && sort.length) {
|
|
863
877
|
// for (let i = 0; i < sort.length; i++) {
|
|
864
878
|
for (let i = sort.length - 1; i >= 0; i--) {
|
|
@@ -870,6 +884,7 @@ function dndNewData(element, data) {
|
|
|
870
884
|
}
|
|
871
885
|
}
|
|
872
886
|
|
|
887
|
+
|
|
873
888
|
let keyPath, clonesMap, clones, index
|
|
874
889
|
|
|
875
890
|
let renderedNode = CoCreate.render.renderedNodes.get(element)
|