@cocreate/elements 1.23.5 → 1.24.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 +15 -0
- package/package.json +1 -1
- package/src/index.js +42 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
# [1.24.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.23.5...v1.24.0) (2023-10-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* data[i].method ([71c0b7c](https://github.com/CoCreate-app/CoCreate-elements/commit/71c0b7ccd28d0f4bbf03b7d8cec615f21479af18))
|
|
7
|
+
* delete for loop ([5507a86](https://github.com/CoCreate-app/CoCreate-elements/commit/5507a86526bdee6b7ac8f74d6ae051068ff9e736))
|
|
8
|
+
* export getObject ([42bd4b3](https://github.com/CoCreate-app/CoCreate-elements/commit/42bd4b3fa66de724a94230c1c3ccfa7faea3a8b8))
|
|
9
|
+
* replaced deleteDocuments with delete ([8e06633](https://github.com/CoCreate-app/CoCreate-elements/commit/8e0663351d459bd79a9f955a0a296df46ed3d580))
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* delete-selector w/ fallback to clicked el ([4143fbb](https://github.com/CoCreate-app/CoCreate-elements/commit/4143fbbfade97c3073e8df6b1ce5b8051b5d5fe0))
|
|
15
|
+
|
|
1
16
|
## [1.23.5](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.23.4...v1.23.5) (2023-10-14)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.24.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
|
@@ -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';
|
|
@@ -251,6 +251,8 @@ async function read(element, data, dataKey) {
|
|
|
251
251
|
}
|
|
252
252
|
|
|
253
253
|
function setData(element, data) {
|
|
254
|
+
if (data.method === 'delete.object')
|
|
255
|
+
console.log('test')
|
|
254
256
|
if (!element) {
|
|
255
257
|
element = getDataElements(data)
|
|
256
258
|
if (!element.length) return
|
|
@@ -403,19 +405,18 @@ function checkIndex(element, data, Data, newData, type, filter) {
|
|
|
403
405
|
Data = sortData(Data, filter.sort)
|
|
404
406
|
index = Data.findIndex(obj => obj.isNewData);
|
|
405
407
|
}
|
|
408
|
+
}
|
|
406
409
|
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
element.setValue(data)
|
|
416
|
-
}
|
|
417
|
-
|
|
410
|
+
if (index >= 0) {
|
|
411
|
+
if (data.$filter.currentIndex === index)
|
|
412
|
+
delete data.$filter.currentIndex
|
|
413
|
+
data.$filter.index = index
|
|
414
|
+
if (element.renderValue)
|
|
415
|
+
element.renderValue(data);
|
|
416
|
+
else if (data)
|
|
417
|
+
element.setValue(data)
|
|
418
418
|
}
|
|
419
|
+
|
|
419
420
|
}
|
|
420
421
|
|
|
421
422
|
function getDataKey(data) {
|
|
@@ -656,8 +657,10 @@ async function save(element) {
|
|
|
656
657
|
data = [data]
|
|
657
658
|
}
|
|
658
659
|
|
|
660
|
+
|
|
661
|
+
|
|
659
662
|
for (let i = 0; i < data.length; i++) {
|
|
660
|
-
if (data[i].type === 'object' && !data[i]) {
|
|
663
|
+
if (data[i].type === 'object' && !data[i].method) {
|
|
661
664
|
if (typeof data[i].object === 'string') {
|
|
662
665
|
if (!data[i]._id)
|
|
663
666
|
data[i].method = 'create.object'
|
|
@@ -1042,10 +1045,32 @@ Actions.init({
|
|
|
1042
1045
|
name: "delete",
|
|
1043
1046
|
endEvent: "deleted",
|
|
1044
1047
|
callback: async (action) => {
|
|
1045
|
-
|
|
1046
|
-
if (
|
|
1048
|
+
let elements = queryElements({ element: action.element, prefix: 'delete' });
|
|
1049
|
+
if (elements === false)
|
|
1050
|
+
elements = [action.element]
|
|
1051
|
+
|
|
1052
|
+
for (let i = 0; i < elements.length; i++) {
|
|
1053
|
+
const data = getObject(elements[i]);
|
|
1054
|
+
if (!data) return
|
|
1047
1055
|
data.method = 'delete.' + data.type
|
|
1048
|
-
|
|
1056
|
+
|
|
1057
|
+
if (elements[i].renderValue) {
|
|
1058
|
+
let selected = elements[i].querySelectorAll('.selected')
|
|
1059
|
+
data[data.type] = []
|
|
1060
|
+
for (let j = 0; j < selected.length; j++) {
|
|
1061
|
+
let attribute = selected[j].getAttribute(data.type)
|
|
1062
|
+
if (attribute) {
|
|
1063
|
+
attribute = attribute.split(',')
|
|
1064
|
+
for (let k = 0; k < attribute.length; k++) {
|
|
1065
|
+
if (data.type === 'object')
|
|
1066
|
+
data[data.type].push({ _id: attribute[k] })
|
|
1067
|
+
else {
|
|
1068
|
+
data[data.type].push(attribute[k])
|
|
1069
|
+
}
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
} else if (data.type === 'object' && typeof data[data.type] === 'string')
|
|
1049
1074
|
data[data.type] = { _id: data[data.type] }
|
|
1050
1075
|
|
|
1051
1076
|
let response = await CRUD.send(data)
|
|
@@ -1058,4 +1083,4 @@ Actions.init({
|
|
|
1058
1083
|
|
|
1059
1084
|
init();
|
|
1060
1085
|
|
|
1061
|
-
export default { init, read, save, getData, reset, elements, keys, forms, debounce, getAttributes };
|
|
1086
|
+
export default { init, read, save, getData, getObject, reset, elements, keys, forms, debounce, getAttributes };
|