@cocreate/elements 1.24.0 → 1.24.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 +8 -0
- package/package.json +1 -1
- package/src/index.js +31 -25
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [1.24.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.24.0...v1.24.1) (2023-10-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* await getValue() ([5970879](https://github.com/CoCreate-app/CoCreate-elements/commit/5970879904665a1f8c6659141928b0ea4de32d9f))
|
|
7
|
+
* create item in rendered element ([3b68724](https://github.com/CoCreate-app/CoCreate-elements/commit/3b687245207d1d06c1ddbe8bece64893b6e46478))
|
|
8
|
+
|
|
1
9
|
# [1.24.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.23.5...v1.24.0) (2023-10-16)
|
|
2
10
|
|
|
3
11
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.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",
|
package/src/index.js
CHANGED
|
@@ -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') {
|
|
@@ -608,7 +615,7 @@ async function save(element) {
|
|
|
608
615
|
if (upsert !== undefined || upsert !== null)
|
|
609
616
|
upsert = true
|
|
610
617
|
if (element.tagName === "FORM") {
|
|
611
|
-
data = element.getData()
|
|
618
|
+
data = await element.getData()
|
|
612
619
|
} else {
|
|
613
620
|
let isSave = element.getAttribute('save')
|
|
614
621
|
if (isSave === 'false') return
|
|
@@ -620,8 +627,7 @@ async function save(element) {
|
|
|
620
627
|
let dataKey = elements.get(element)
|
|
621
628
|
data = { ...keys.get(dataKey).dataKey.object }
|
|
622
629
|
|
|
623
|
-
value = element.getValue();
|
|
624
|
-
|
|
630
|
+
value = await element.getValue();
|
|
625
631
|
let key = element.getAttribute('key')
|
|
626
632
|
|
|
627
633
|
if (typeof data[data.type] === 'string')
|
|
@@ -880,9 +886,9 @@ Observer.init({
|
|
|
880
886
|
})
|
|
881
887
|
|
|
882
888
|
// 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')
|
|
889
|
+
async function dndCrud(draggedEl, draggedFrom, droppedEl, droppedIn) {
|
|
890
|
+
let from = await dndCrudData(draggedEl, draggedFrom, 'remove')
|
|
891
|
+
let to = await dndCrudData(droppedEl, droppedIn, 'add')
|
|
886
892
|
|
|
887
893
|
if (from && to && !draggedFrom.isSameNode(droppedIn)) {
|
|
888
894
|
let element = getDataElements(from.data)
|
|
@@ -916,9 +922,9 @@ function dndCrud(draggedEl, draggedFrom, droppedEl, droppedIn) {
|
|
|
916
922
|
|
|
917
923
|
}
|
|
918
924
|
|
|
919
|
-
function dndCrudData(element, parent, operator) {
|
|
925
|
+
async function dndCrudData(element, parent, operator) {
|
|
920
926
|
if (!elements.has(parent)) return
|
|
921
|
-
let data = parent.getData()
|
|
927
|
+
let data = await parent.getData()
|
|
922
928
|
let newData = getObject(parent)
|
|
923
929
|
|
|
924
930
|
let { Data, sortName, sortDirection, keyPath, clones, index } = dndNewData(element, data)
|