@cocreate/elements 1.24.0 → 1.24.2
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/form.js +0 -2
- package/src/index.js +43 -31
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
## [1.24.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.24.1...v1.24.2) (2023-10-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* create.object condition undefined ([50e8a14](https://github.com/CoCreate-app/CoCreate-elements/commit/50e8a140da1b7de9a7ae93a12c7b35a884931283))
|
|
7
|
+
* declartion of render functions using object spread ([d4ecf62](https://github.com/CoCreate-app/CoCreate-elements/commit/d4ecf623f83869b54dc2938ccbebd26358597bdb))
|
|
8
|
+
|
|
9
|
+
## [1.24.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.24.0...v1.24.1) (2023-10-17)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* await getValue() ([5970879](https://github.com/CoCreate-app/CoCreate-elements/commit/5970879904665a1f8c6659141928b0ea4de32d9f))
|
|
15
|
+
* create item in rendered element ([3b68724](https://github.com/CoCreate-app/CoCreate-elements/commit/3b687245207d1d06c1ddbe8bece64893b6e46478))
|
|
16
|
+
|
|
1
17
|
# [1.24.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.23.5...v1.24.0) (2023-10-16)
|
|
2
18
|
|
|
3
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.2",
|
|
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/form.js
CHANGED
package/src/index.js
CHANGED
|
@@ -28,7 +28,7 @@ import Actions from '@cocreate/actions';
|
|
|
28
28
|
import CRUD from '@cocreate/crud-client';
|
|
29
29
|
import { dotNotationToObject, queryElements, queryData, sortData, getAttributes, getAttributeNames, checkValue } from '@cocreate/utils';
|
|
30
30
|
import filter from '@cocreate/filter';
|
|
31
|
-
import render from '@cocreate/render';
|
|
31
|
+
import { render, renderedNodes } from '@cocreate/render';
|
|
32
32
|
import '@cocreate/element-prototype';
|
|
33
33
|
import './fetchSrc';
|
|
34
34
|
import { reset } from './form'
|
|
@@ -250,9 +250,7 @@ async function read(element, data, dataKey) {
|
|
|
250
250
|
debounce.set(dataKey.string, delayTimer)
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
function setData(element, data) {
|
|
254
|
-
if (data.method === 'delete.object')
|
|
255
|
-
console.log('test')
|
|
253
|
+
async function setData(element, data) {
|
|
256
254
|
if (!element) {
|
|
257
255
|
element = getDataElements(data)
|
|
258
256
|
if (!element.length) return
|
|
@@ -280,7 +278,7 @@ function setData(element, data) {
|
|
|
280
278
|
|
|
281
279
|
const { key, isRead, isListen, isCrdt } = getAttributes(el);
|
|
282
280
|
if (el.getFilter || el.renderValue)
|
|
283
|
-
filterData(el, data, type, key)
|
|
281
|
+
await filterData(el, data, type, key)
|
|
284
282
|
else {
|
|
285
283
|
let value = CRUD.getValueFromObject(data[type][0], key);
|
|
286
284
|
if (key) {
|
|
@@ -294,7 +292,7 @@ function setData(element, data) {
|
|
|
294
292
|
}
|
|
295
293
|
}
|
|
296
294
|
|
|
297
|
-
function filterData(element, data, type, key) {
|
|
295
|
+
async function filterData(element, data, type, key) {
|
|
298
296
|
if (key) {
|
|
299
297
|
if (!data.type) return
|
|
300
298
|
if (Array.isArray(data[type])) {
|
|
@@ -314,7 +312,7 @@ function filterData(element, data, type, key) {
|
|
|
314
312
|
}
|
|
315
313
|
|
|
316
314
|
if (element.getFilter && data.method && !data.method.startsWith('read'))
|
|
317
|
-
checkFilters(element, data, type)
|
|
315
|
+
await checkFilters(element, data, type)
|
|
318
316
|
else if (element.renderValue)
|
|
319
317
|
element.renderValue(data);
|
|
320
318
|
// render({ element, data, key: type });
|
|
@@ -325,8 +323,8 @@ function filterData(element, data, type, key) {
|
|
|
325
323
|
element.dispatchEvent(evt);
|
|
326
324
|
}
|
|
327
325
|
|
|
328
|
-
function checkFilters(element, data, type) {
|
|
329
|
-
let Data = element.getData()
|
|
326
|
+
async function checkFilters(element, data, type) {
|
|
327
|
+
let Data = await element.getData()
|
|
330
328
|
if (!Data) return
|
|
331
329
|
|
|
332
330
|
let newData
|
|
@@ -386,25 +384,32 @@ function checkIndex(element, data, Data, newData, type, filter) {
|
|
|
386
384
|
if (!data.$filter)
|
|
387
385
|
data.$filter = {}
|
|
388
386
|
|
|
389
|
-
if (data.method.startsWith('delete')) {
|
|
387
|
+
if (data.method.startsWith('delete.')) {
|
|
390
388
|
if (!index && index !== 0)
|
|
391
389
|
return
|
|
392
390
|
data.$filter.remove = true
|
|
393
391
|
} else {
|
|
394
|
-
if (
|
|
395
|
-
|
|
396
|
-
|
|
392
|
+
if (data.method.startsWith('create.')) {
|
|
393
|
+
if (index === -1) {
|
|
394
|
+
data.$filter.create = true
|
|
395
|
+
if (filter && filter.sort)
|
|
396
|
+
newData.isNewData = true
|
|
397
|
+
Data.push(newData)
|
|
398
|
+
}
|
|
397
399
|
} else {
|
|
398
400
|
data.$filter.update = true
|
|
399
401
|
data.$filter.currentIndex = index
|
|
400
402
|
Data[index] = dotNotationToObject(newData, Data[index])
|
|
403
|
+
if (filter && filter.sort) {
|
|
404
|
+
Data[index].isNewData = true
|
|
405
|
+
}
|
|
401
406
|
}
|
|
402
407
|
|
|
403
408
|
if (filter && filter.sort) {
|
|
404
|
-
Data[index].isNewData = true
|
|
405
409
|
Data = sortData(Data, filter.sort)
|
|
406
410
|
index = Data.findIndex(obj => obj.isNewData);
|
|
407
411
|
}
|
|
412
|
+
|
|
408
413
|
}
|
|
409
414
|
|
|
410
415
|
if (index >= 0) {
|
|
@@ -463,7 +468,9 @@ function getDataKeys(data) {
|
|
|
463
468
|
let hasMatch = true;
|
|
464
469
|
|
|
465
470
|
for (const key of targetKeys) {
|
|
466
|
-
if (data.
|
|
471
|
+
if (!data.$filter && (data.type === key || key === '$filter'))
|
|
472
|
+
hasMatch = true
|
|
473
|
+
else if (data.hasOwnProperty(key)) {
|
|
467
474
|
if (!sortedKey.data.hasOwnProperty(key)) {
|
|
468
475
|
hasMatch = false;
|
|
469
476
|
break;
|
|
@@ -496,7 +503,7 @@ function getDataKeys(data) {
|
|
|
496
503
|
return matchingKeyStrings;
|
|
497
504
|
}
|
|
498
505
|
|
|
499
|
-
function getData(form) {
|
|
506
|
+
async function getData(form) {
|
|
500
507
|
let dataKeys = new Map()
|
|
501
508
|
let formObject = forms.get(form)
|
|
502
509
|
for (let type of formObject.types.values()) {
|
|
@@ -510,9 +517,9 @@ function getData(form) {
|
|
|
510
517
|
}
|
|
511
518
|
let Data = { ...data }
|
|
512
519
|
let dataKey = elements.get(element)
|
|
513
|
-
let value = element.getValue()
|
|
514
|
-
// console.log(type, value, data)
|
|
520
|
+
let value = await element.getValue()
|
|
515
521
|
|
|
522
|
+
// console.log(type, value, data)
|
|
516
523
|
if (!Data[Data.type] && Data.key) {
|
|
517
524
|
Data.method = 'create.' + Data.type
|
|
518
525
|
if (Data.type === 'object') {
|
|
@@ -547,8 +554,11 @@ function getData(form) {
|
|
|
547
554
|
else if (typeof Data[Data.type] === 'object')
|
|
548
555
|
if (Data.key == '{}')
|
|
549
556
|
Data[Data.type] = { ...Data[Data.type], ...value }
|
|
550
|
-
else
|
|
557
|
+
else {
|
|
551
558
|
Data[Data.type][Data.key] = value
|
|
559
|
+
if (!Data[Data.type]._id)
|
|
560
|
+
Data.method = 'create.' + Data.type
|
|
561
|
+
}
|
|
552
562
|
} else {
|
|
553
563
|
Data[Data.type] = { [Data[Data.type]]: value }
|
|
554
564
|
}
|
|
@@ -608,7 +618,7 @@ async function save(element) {
|
|
|
608
618
|
if (upsert !== undefined || upsert !== null)
|
|
609
619
|
upsert = true
|
|
610
620
|
if (element.tagName === "FORM") {
|
|
611
|
-
data = element.getData()
|
|
621
|
+
data = await element.getData()
|
|
612
622
|
} else {
|
|
613
623
|
let isSave = element.getAttribute('save')
|
|
614
624
|
if (isSave === 'false') return
|
|
@@ -620,8 +630,7 @@ async function save(element) {
|
|
|
620
630
|
let dataKey = elements.get(element)
|
|
621
631
|
data = { ...keys.get(dataKey).dataKey.object }
|
|
622
632
|
|
|
623
|
-
value = element.getValue();
|
|
624
|
-
|
|
633
|
+
value = await element.getValue();
|
|
625
634
|
let key = element.getAttribute('key')
|
|
626
635
|
|
|
627
636
|
if (typeof data[data.type] === 'string')
|
|
@@ -658,7 +667,7 @@ async function save(element) {
|
|
|
658
667
|
}
|
|
659
668
|
|
|
660
669
|
|
|
661
|
-
|
|
670
|
+
let Data = []
|
|
662
671
|
for (let i = 0; i < data.length; i++) {
|
|
663
672
|
if (data[i].type === 'object' && !data[i].method) {
|
|
664
673
|
if (typeof data[i].object === 'string') {
|
|
@@ -699,8 +708,11 @@ async function save(element) {
|
|
|
699
708
|
});
|
|
700
709
|
}
|
|
701
710
|
|
|
711
|
+
|
|
702
712
|
data[i] = await CRUD.send(data[i]);
|
|
703
713
|
|
|
714
|
+
Data.push(data[i])
|
|
715
|
+
|
|
704
716
|
if (data[i] && (data[i].method.startsWith('create') || data[i].type !== 'object' && data[i].method.startsWith('update'))) {
|
|
705
717
|
setTypeValue(element, data[i])
|
|
706
718
|
} else if (data[i])
|
|
@@ -710,6 +722,7 @@ async function save(element) {
|
|
|
710
722
|
|
|
711
723
|
}
|
|
712
724
|
|
|
725
|
+
return Data
|
|
713
726
|
}
|
|
714
727
|
|
|
715
728
|
function setTypeValue(element, data) {
|
|
@@ -865,7 +878,7 @@ Observer.init({
|
|
|
865
878
|
clearTimeout(delayTimer);
|
|
866
879
|
debounce.delete(mutation.target)
|
|
867
880
|
|
|
868
|
-
let renderedNode =
|
|
881
|
+
let renderedNode = renderedNodes.get(mutation.target)
|
|
869
882
|
if (!renderedNode) return
|
|
870
883
|
|
|
871
884
|
if (!mutation.movedFrom) return
|
|
@@ -880,9 +893,9 @@ Observer.init({
|
|
|
880
893
|
})
|
|
881
894
|
|
|
882
895
|
// TODO: has the potential to work on most of the crud elements specifically if the value is an object or an array
|
|
883
|
-
function dndCrud(draggedEl, draggedFrom, droppedEl, droppedIn) {
|
|
884
|
-
let from = dndCrudData(draggedEl, draggedFrom, 'remove')
|
|
885
|
-
let to = dndCrudData(droppedEl, droppedIn, 'add')
|
|
896
|
+
async function dndCrud(draggedEl, draggedFrom, droppedEl, droppedIn) {
|
|
897
|
+
let from = await dndCrudData(draggedEl, draggedFrom, 'remove')
|
|
898
|
+
let to = await dndCrudData(droppedEl, droppedIn, 'add')
|
|
886
899
|
|
|
887
900
|
if (from && to && !draggedFrom.isSameNode(droppedIn)) {
|
|
888
901
|
let element = getDataElements(from.data)
|
|
@@ -916,9 +929,9 @@ function dndCrud(draggedEl, draggedFrom, droppedEl, droppedIn) {
|
|
|
916
929
|
|
|
917
930
|
}
|
|
918
931
|
|
|
919
|
-
function dndCrudData(element, parent, operator) {
|
|
932
|
+
async function dndCrudData(element, parent, operator) {
|
|
920
933
|
if (!elements.has(parent)) return
|
|
921
|
-
let data = parent.getData()
|
|
934
|
+
let data = await parent.getData()
|
|
922
935
|
let newData = getObject(parent)
|
|
923
936
|
|
|
924
937
|
let { Data, sortName, sortDirection, keyPath, clones, index } = dndNewData(element, data)
|
|
@@ -970,10 +983,9 @@ function dndNewData(element, data) {
|
|
|
970
983
|
}
|
|
971
984
|
}
|
|
972
985
|
|
|
973
|
-
|
|
974
986
|
let keyPath, clonesMap, clones, index
|
|
975
987
|
|
|
976
|
-
let renderedNode =
|
|
988
|
+
let renderedNode = renderedNodes.get(element)
|
|
977
989
|
if (renderedNode) {
|
|
978
990
|
keyPath = renderedNode.keyPath
|
|
979
991
|
clonesMap = renderedNode.template.clones
|