@cocreate/elements 1.24.1 → 1.24.3
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/form.js +0 -2
- package/src/index.js +25 -17
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
|
+
## [1.24.3](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.24.2...v1.24.3) (2023-10-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* condition on read ([fe53a8e](https://github.com/CoCreate-app/CoCreate-elements/commit/fe53a8ea9808502af64a8298a14dd38bbfd07940))
|
|
7
|
+
|
|
8
|
+
## [1.24.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.24.1...v1.24.2) (2023-10-19)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* create.object condition undefined ([50e8a14](https://github.com/CoCreate-app/CoCreate-elements/commit/50e8a140da1b7de9a7ae93a12c7b35a884931283))
|
|
14
|
+
* declartion of render functions using object spread ([d4ecf62](https://github.com/CoCreate-app/CoCreate-elements/commit/d4ecf623f83869b54dc2938ccbebd26358597bdb))
|
|
15
|
+
|
|
1
16
|
## [1.24.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.24.0...v1.24.1) (2023-10-17)
|
|
2
17
|
|
|
3
18
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.24.
|
|
3
|
+
"version": "1.24.3",
|
|
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'
|
|
@@ -233,11 +233,10 @@ async function read(element, data, dataKey) {
|
|
|
233
233
|
if (!data.$filter && data.type === 'object') {
|
|
234
234
|
if (typeof data.object === 'string')
|
|
235
235
|
data.object = { _id: data.object }
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
if (!data.object._id.match(/^[0-9a-fA-F]{24}$/))
|
|
236
|
+
else if (Array.isArray(data.object)) {
|
|
237
|
+
if (data.object.length)
|
|
238
|
+
data.object = { _id: data.object[0]._id }
|
|
239
|
+
} else if (!data.object._id.match(/^[0-9a-fA-F]{24}$/))
|
|
241
240
|
return
|
|
242
241
|
}
|
|
243
242
|
|
|
@@ -284,7 +283,7 @@ async function setData(element, data) {
|
|
|
284
283
|
if (key) {
|
|
285
284
|
if (!data[type].length) continue;
|
|
286
285
|
if (isRead == "false" || isCrdt == "true") continue;
|
|
287
|
-
if (isListen == "false" && !data.method.startsWith('read')) continue;
|
|
286
|
+
if (isListen == "false" && !data.method.startsWith('read.')) continue;
|
|
288
287
|
}
|
|
289
288
|
// TODO: update.object data returned from server will not include $operator
|
|
290
289
|
el.setValue(value);
|
|
@@ -311,7 +310,7 @@ async function filterData(element, data, type, key) {
|
|
|
311
310
|
}
|
|
312
311
|
}
|
|
313
312
|
|
|
314
|
-
if (element.getFilter && data.method && !data.method.startsWith('read'))
|
|
313
|
+
if (element.getFilter && data.method && !data.method.startsWith('read.'))
|
|
315
314
|
await checkFilters(element, data, type)
|
|
316
315
|
else if (element.renderValue)
|
|
317
316
|
element.renderValue(data);
|
|
@@ -554,8 +553,11 @@ async function getData(form) {
|
|
|
554
553
|
else if (typeof Data[Data.type] === 'object')
|
|
555
554
|
if (Data.key == '{}')
|
|
556
555
|
Data[Data.type] = { ...Data[Data.type], ...value }
|
|
557
|
-
else
|
|
556
|
+
else {
|
|
558
557
|
Data[Data.type][Data.key] = value
|
|
558
|
+
if (!Data[Data.type]._id)
|
|
559
|
+
Data.method = 'create.' + Data.type
|
|
560
|
+
}
|
|
559
561
|
} else {
|
|
560
562
|
Data[Data.type] = { [Data[Data.type]]: value }
|
|
561
563
|
}
|
|
@@ -664,7 +666,7 @@ async function save(element) {
|
|
|
664
666
|
}
|
|
665
667
|
|
|
666
668
|
|
|
667
|
-
|
|
669
|
+
let Data = []
|
|
668
670
|
for (let i = 0; i < data.length; i++) {
|
|
669
671
|
if (data[i].type === 'object' && !data[i].method) {
|
|
670
672
|
if (typeof data[i].object === 'string') {
|
|
@@ -694,9 +696,9 @@ async function save(element) {
|
|
|
694
696
|
}
|
|
695
697
|
}
|
|
696
698
|
|
|
697
|
-
if (data[i].method && data[i].method.startsWith('create')) {
|
|
699
|
+
if (data[i].method && data[i].method.startsWith('create.')) {
|
|
698
700
|
element.setAttribute(data[i].type, 'pending');
|
|
699
|
-
} else if (data[i].method && data[i].method.startsWith('update') && data[i].type == 'object' && typeof value == 'string' && window.CoCreate.crdt && !'crdt') {
|
|
701
|
+
} else if (data[i].method && data[i].method.startsWith('update.') && data[i].type == 'object' && typeof value == 'string' && window.CoCreate.crdt && !'crdt') {
|
|
700
702
|
return window.CoCreate.crdt.replaceText({
|
|
701
703
|
array: data[i].array,
|
|
702
704
|
key: data[i].key,
|
|
@@ -705,9 +707,12 @@ async function save(element) {
|
|
|
705
707
|
});
|
|
706
708
|
}
|
|
707
709
|
|
|
710
|
+
|
|
708
711
|
data[i] = await CRUD.send(data[i]);
|
|
709
712
|
|
|
710
|
-
|
|
713
|
+
Data.push(data[i])
|
|
714
|
+
|
|
715
|
+
if (data[i] && (data[i].method.startsWith('create.') || data[i].type !== 'object' && data[i].method.startsWith('update.'))) {
|
|
711
716
|
setTypeValue(element, data[i])
|
|
712
717
|
} else if (data[i])
|
|
713
718
|
document.dispatchEvent(new CustomEvent('saved', {
|
|
@@ -716,6 +721,7 @@ async function save(element) {
|
|
|
716
721
|
|
|
717
722
|
}
|
|
718
723
|
|
|
724
|
+
return Data
|
|
719
725
|
}
|
|
720
726
|
|
|
721
727
|
function setTypeValue(element, data) {
|
|
@@ -815,7 +821,10 @@ async function remove(element) {
|
|
|
815
821
|
element = [element]
|
|
816
822
|
for (let i = 0; i < element.length; i++) {
|
|
817
823
|
if (element[i].tagName === 'FORM') {
|
|
818
|
-
let form = forms.get(element[i])
|
|
824
|
+
let form = forms.get(element[i])
|
|
825
|
+
if (!form) return
|
|
826
|
+
|
|
827
|
+
form = form.elements
|
|
819
828
|
for (let el of form.keys()) {
|
|
820
829
|
let key = elements.get(el)
|
|
821
830
|
if (key) {
|
|
@@ -871,7 +880,7 @@ Observer.init({
|
|
|
871
880
|
clearTimeout(delayTimer);
|
|
872
881
|
debounce.delete(mutation.target)
|
|
873
882
|
|
|
874
|
-
let renderedNode =
|
|
883
|
+
let renderedNode = renderedNodes.get(mutation.target)
|
|
875
884
|
if (!renderedNode) return
|
|
876
885
|
|
|
877
886
|
if (!mutation.movedFrom) return
|
|
@@ -976,10 +985,9 @@ function dndNewData(element, data) {
|
|
|
976
985
|
}
|
|
977
986
|
}
|
|
978
987
|
|
|
979
|
-
|
|
980
988
|
let keyPath, clonesMap, clones, index
|
|
981
989
|
|
|
982
|
-
let renderedNode =
|
|
990
|
+
let renderedNode = renderedNodes.get(element)
|
|
983
991
|
if (renderedNode) {
|
|
984
992
|
keyPath = renderedNode.keyPath
|
|
985
993
|
clonesMap = renderedNode.template.clones
|