@cocreate/elements 1.23.5 → 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 +23 -0
- package/package.json +1 -1
- package/src/index.js +70 -39
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
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
|
+
|
|
9
|
+
# [1.24.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.23.5...v1.24.0) (2023-10-16)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* data[i].method ([71c0b7c](https://github.com/CoCreate-app/CoCreate-elements/commit/71c0b7ccd28d0f4bbf03b7d8cec615f21479af18))
|
|
15
|
+
* delete for loop ([5507a86](https://github.com/CoCreate-app/CoCreate-elements/commit/5507a86526bdee6b7ac8f74d6ae051068ff9e736))
|
|
16
|
+
* export getObject ([42bd4b3](https://github.com/CoCreate-app/CoCreate-elements/commit/42bd4b3fa66de724a94230c1c3ccfa7faea3a8b8))
|
|
17
|
+
* replaced deleteDocuments with delete ([8e06633](https://github.com/CoCreate-app/CoCreate-elements/commit/8e0663351d459bd79a9f955a0a296df46ed3d580))
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* delete-selector w/ fallback to clicked el ([4143fbb](https://github.com/CoCreate-app/CoCreate-elements/commit/4143fbbfade97c3073e8df6b1ce5b8051b5d5fe0))
|
|
23
|
+
|
|
1
24
|
## [1.23.5](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.23.4...v1.23.5) (2023-10-14)
|
|
2
25
|
|
|
3
26
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
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
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
import Observer from '@cocreate/observer';
|
|
27
27
|
import Actions from '@cocreate/actions';
|
|
28
28
|
import CRUD from '@cocreate/crud-client';
|
|
29
|
-
import { dotNotationToObject, queryData, sortData, getAttributes, getAttributeNames, checkValue } from '@cocreate/utils';
|
|
29
|
+
import { dotNotationToObject, queryElements, queryData, sortData, getAttributes, getAttributeNames, checkValue } from '@cocreate/utils';
|
|
30
30
|
import filter from '@cocreate/filter';
|
|
31
31
|
import render from '@cocreate/render';
|
|
32
32
|
import '@cocreate/element-prototype';
|
|
@@ -250,7 +250,7 @@ async function read(element, data, dataKey) {
|
|
|
250
250
|
debounce.set(dataKey.string, delayTimer)
|
|
251
251
|
}
|
|
252
252
|
|
|
253
|
-
function setData(element, data) {
|
|
253
|
+
async function setData(element, data) {
|
|
254
254
|
if (!element) {
|
|
255
255
|
element = getDataElements(data)
|
|
256
256
|
if (!element.length) return
|
|
@@ -278,7 +278,7 @@ function setData(element, data) {
|
|
|
278
278
|
|
|
279
279
|
const { key, isRead, isListen, isCrdt } = getAttributes(el);
|
|
280
280
|
if (el.getFilter || el.renderValue)
|
|
281
|
-
filterData(el, data, type, key)
|
|
281
|
+
await filterData(el, data, type, key)
|
|
282
282
|
else {
|
|
283
283
|
let value = CRUD.getValueFromObject(data[type][0], key);
|
|
284
284
|
if (key) {
|
|
@@ -292,7 +292,7 @@ function setData(element, data) {
|
|
|
292
292
|
}
|
|
293
293
|
}
|
|
294
294
|
|
|
295
|
-
function filterData(element, data, type, key) {
|
|
295
|
+
async function filterData(element, data, type, key) {
|
|
296
296
|
if (key) {
|
|
297
297
|
if (!data.type) return
|
|
298
298
|
if (Array.isArray(data[type])) {
|
|
@@ -312,7 +312,7 @@ function filterData(element, data, type, key) {
|
|
|
312
312
|
}
|
|
313
313
|
|
|
314
314
|
if (element.getFilter && data.method && !data.method.startsWith('read'))
|
|
315
|
-
checkFilters(element, data, type)
|
|
315
|
+
await checkFilters(element, data, type)
|
|
316
316
|
else if (element.renderValue)
|
|
317
317
|
element.renderValue(data);
|
|
318
318
|
// render({ element, data, key: type });
|
|
@@ -323,8 +323,8 @@ function filterData(element, data, type, key) {
|
|
|
323
323
|
element.dispatchEvent(evt);
|
|
324
324
|
}
|
|
325
325
|
|
|
326
|
-
function checkFilters(element, data, type) {
|
|
327
|
-
let Data = element.getData()
|
|
326
|
+
async function checkFilters(element, data, type) {
|
|
327
|
+
let Data = await element.getData()
|
|
328
328
|
if (!Data) return
|
|
329
329
|
|
|
330
330
|
let newData
|
|
@@ -384,38 +384,44 @@ function checkIndex(element, data, Data, newData, type, filter) {
|
|
|
384
384
|
if (!data.$filter)
|
|
385
385
|
data.$filter = {}
|
|
386
386
|
|
|
387
|
-
if (data.method.startsWith('delete')) {
|
|
387
|
+
if (data.method.startsWith('delete.')) {
|
|
388
388
|
if (!index && index !== 0)
|
|
389
389
|
return
|
|
390
390
|
data.$filter.remove = true
|
|
391
391
|
} else {
|
|
392
|
-
if (
|
|
393
|
-
|
|
394
|
-
|
|
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
|
+
}
|
|
395
399
|
} else {
|
|
396
400
|
data.$filter.update = true
|
|
397
401
|
data.$filter.currentIndex = index
|
|
398
402
|
Data[index] = dotNotationToObject(newData, Data[index])
|
|
403
|
+
if (filter && filter.sort) {
|
|
404
|
+
Data[index].isNewData = true
|
|
405
|
+
}
|
|
399
406
|
}
|
|
400
407
|
|
|
401
408
|
if (filter && filter.sort) {
|
|
402
|
-
Data[index].isNewData = true
|
|
403
409
|
Data = sortData(Data, filter.sort)
|
|
404
410
|
index = Data.findIndex(obj => obj.isNewData);
|
|
405
411
|
}
|
|
406
412
|
|
|
407
|
-
|
|
408
|
-
if (data.$filter.currentIndex === index)
|
|
409
|
-
delete data.$filter.currentIndex
|
|
410
|
-
data.$filter.index = index
|
|
411
|
-
if (element.renderValue)
|
|
412
|
-
element.renderValue(data);
|
|
413
|
-
// render({ element, data, key: type });
|
|
414
|
-
else if (data)
|
|
415
|
-
element.setValue(data)
|
|
416
|
-
}
|
|
413
|
+
}
|
|
417
414
|
|
|
415
|
+
if (index >= 0) {
|
|
416
|
+
if (data.$filter.currentIndex === index)
|
|
417
|
+
delete data.$filter.currentIndex
|
|
418
|
+
data.$filter.index = index
|
|
419
|
+
if (element.renderValue)
|
|
420
|
+
element.renderValue(data);
|
|
421
|
+
else if (data)
|
|
422
|
+
element.setValue(data)
|
|
418
423
|
}
|
|
424
|
+
|
|
419
425
|
}
|
|
420
426
|
|
|
421
427
|
function getDataKey(data) {
|
|
@@ -462,7 +468,9 @@ function getDataKeys(data) {
|
|
|
462
468
|
let hasMatch = true;
|
|
463
469
|
|
|
464
470
|
for (const key of targetKeys) {
|
|
465
|
-
if (data.
|
|
471
|
+
if (!data.$filter && (data.type === key || key === '$filter'))
|
|
472
|
+
hasMatch = true
|
|
473
|
+
else if (data.hasOwnProperty(key)) {
|
|
466
474
|
if (!sortedKey.data.hasOwnProperty(key)) {
|
|
467
475
|
hasMatch = false;
|
|
468
476
|
break;
|
|
@@ -495,7 +503,7 @@ function getDataKeys(data) {
|
|
|
495
503
|
return matchingKeyStrings;
|
|
496
504
|
}
|
|
497
505
|
|
|
498
|
-
function getData(form) {
|
|
506
|
+
async function getData(form) {
|
|
499
507
|
let dataKeys = new Map()
|
|
500
508
|
let formObject = forms.get(form)
|
|
501
509
|
for (let type of formObject.types.values()) {
|
|
@@ -509,9 +517,9 @@ function getData(form) {
|
|
|
509
517
|
}
|
|
510
518
|
let Data = { ...data }
|
|
511
519
|
let dataKey = elements.get(element)
|
|
512
|
-
let value = element.getValue()
|
|
513
|
-
// console.log(type, value, data)
|
|
520
|
+
let value = await element.getValue()
|
|
514
521
|
|
|
522
|
+
// console.log(type, value, data)
|
|
515
523
|
if (!Data[Data.type] && Data.key) {
|
|
516
524
|
Data.method = 'create.' + Data.type
|
|
517
525
|
if (Data.type === 'object') {
|
|
@@ -607,7 +615,7 @@ async function save(element) {
|
|
|
607
615
|
if (upsert !== undefined || upsert !== null)
|
|
608
616
|
upsert = true
|
|
609
617
|
if (element.tagName === "FORM") {
|
|
610
|
-
data = element.getData()
|
|
618
|
+
data = await element.getData()
|
|
611
619
|
} else {
|
|
612
620
|
let isSave = element.getAttribute('save')
|
|
613
621
|
if (isSave === 'false') return
|
|
@@ -619,8 +627,7 @@ async function save(element) {
|
|
|
619
627
|
let dataKey = elements.get(element)
|
|
620
628
|
data = { ...keys.get(dataKey).dataKey.object }
|
|
621
629
|
|
|
622
|
-
value = element.getValue();
|
|
623
|
-
|
|
630
|
+
value = await element.getValue();
|
|
624
631
|
let key = element.getAttribute('key')
|
|
625
632
|
|
|
626
633
|
if (typeof data[data.type] === 'string')
|
|
@@ -656,8 +663,10 @@ async function save(element) {
|
|
|
656
663
|
data = [data]
|
|
657
664
|
}
|
|
658
665
|
|
|
666
|
+
|
|
667
|
+
|
|
659
668
|
for (let i = 0; i < data.length; i++) {
|
|
660
|
-
if (data[i].type === 'object' && !data[i]) {
|
|
669
|
+
if (data[i].type === 'object' && !data[i].method) {
|
|
661
670
|
if (typeof data[i].object === 'string') {
|
|
662
671
|
if (!data[i]._id)
|
|
663
672
|
data[i].method = 'create.object'
|
|
@@ -877,9 +886,9 @@ Observer.init({
|
|
|
877
886
|
})
|
|
878
887
|
|
|
879
888
|
// TODO: has the potential to work on most of the crud elements specifically if the value is an object or an array
|
|
880
|
-
function dndCrud(draggedEl, draggedFrom, droppedEl, droppedIn) {
|
|
881
|
-
let from = dndCrudData(draggedEl, draggedFrom, 'remove')
|
|
882
|
-
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')
|
|
883
892
|
|
|
884
893
|
if (from && to && !draggedFrom.isSameNode(droppedIn)) {
|
|
885
894
|
let element = getDataElements(from.data)
|
|
@@ -913,9 +922,9 @@ function dndCrud(draggedEl, draggedFrom, droppedEl, droppedIn) {
|
|
|
913
922
|
|
|
914
923
|
}
|
|
915
924
|
|
|
916
|
-
function dndCrudData(element, parent, operator) {
|
|
925
|
+
async function dndCrudData(element, parent, operator) {
|
|
917
926
|
if (!elements.has(parent)) return
|
|
918
|
-
let data = parent.getData()
|
|
927
|
+
let data = await parent.getData()
|
|
919
928
|
let newData = getObject(parent)
|
|
920
929
|
|
|
921
930
|
let { Data, sortName, sortDirection, keyPath, clones, index } = dndNewData(element, data)
|
|
@@ -1042,10 +1051,32 @@ Actions.init({
|
|
|
1042
1051
|
name: "delete",
|
|
1043
1052
|
endEvent: "deleted",
|
|
1044
1053
|
callback: async (action) => {
|
|
1045
|
-
|
|
1046
|
-
if (
|
|
1054
|
+
let elements = queryElements({ element: action.element, prefix: 'delete' });
|
|
1055
|
+
if (elements === false)
|
|
1056
|
+
elements = [action.element]
|
|
1057
|
+
|
|
1058
|
+
for (let i = 0; i < elements.length; i++) {
|
|
1059
|
+
const data = getObject(elements[i]);
|
|
1060
|
+
if (!data) return
|
|
1047
1061
|
data.method = 'delete.' + data.type
|
|
1048
|
-
|
|
1062
|
+
|
|
1063
|
+
if (elements[i].renderValue) {
|
|
1064
|
+
let selected = elements[i].querySelectorAll('.selected')
|
|
1065
|
+
data[data.type] = []
|
|
1066
|
+
for (let j = 0; j < selected.length; j++) {
|
|
1067
|
+
let attribute = selected[j].getAttribute(data.type)
|
|
1068
|
+
if (attribute) {
|
|
1069
|
+
attribute = attribute.split(',')
|
|
1070
|
+
for (let k = 0; k < attribute.length; k++) {
|
|
1071
|
+
if (data.type === 'object')
|
|
1072
|
+
data[data.type].push({ _id: attribute[k] })
|
|
1073
|
+
else {
|
|
1074
|
+
data[data.type].push(attribute[k])
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
} else if (data.type === 'object' && typeof data[data.type] === 'string')
|
|
1049
1080
|
data[data.type] = { _id: data[data.type] }
|
|
1050
1081
|
|
|
1051
1082
|
let response = await CRUD.send(data)
|
|
@@ -1058,4 +1089,4 @@ Actions.init({
|
|
|
1058
1089
|
|
|
1059
1090
|
init();
|
|
1060
1091
|
|
|
1061
|
-
export default { init, read, save, getData, reset, elements, keys, forms, debounce, getAttributes };
|
|
1092
|
+
export default { init, read, save, getData, getObject, reset, elements, keys, forms, debounce, getAttributes };
|