@cocreate/elements 1.36.0 → 1.36.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 CHANGED
@@ -1,3 +1,14 @@
1
+ ## [1.36.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.36.0...v1.36.1) (2024-07-09)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * handleing of key="{}" where value is an array ([c86ffd9](https://github.com/CoCreate-app/CoCreate-elements/commit/c86ffd9697839611e8fb10a3f76e0a9bff9892cb))
7
+ * objectId() habndleing to add _id to element ([b2bb7b4](https://github.com/CoCreate-app/CoCreate-elements/commit/b2bb7b423ea2316be0087506fa094a3a8e8cce09))
8
+ * removed testing log ([1b4f38e](https://github.com/CoCreate-app/CoCreate-elements/commit/1b4f38e0cfc1b764dd695dc3288e74f6cb15b676))
9
+ * set flag rendered to prevent loop caused by fireListeners and sync ([3dd1267](https://github.com/CoCreate-app/CoCreate-elements/commit/3dd1267784617c1a666b032fc427671f0cf07375))
10
+ * use continue in for loop and continue if !data$storage ([32020f1](https://github.com/CoCreate-app/CoCreate-elements/commit/32020f17fecc6a578ff58b9fd1dec50a6f611b11))
11
+
1
12
  # [1.36.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.35.8...v1.36.0) (2024-06-30)
2
13
 
3
14
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/elements",
3
- "version": "1.36.0",
3
+ "version": "1.36.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/form.js CHANGED
@@ -46,20 +46,17 @@ function init(elements) {
46
46
  * @param form
47
47
  */
48
48
  function runObjectId(form) {
49
- let elements = form.querySelectorAll("[object='ObjectId()']")
50
- let arrays = []
51
- // Add a array to the array list
49
+ let elements = Array.from(form.querySelectorAll("[object='ObjectId()']"));
50
+
51
+ if (form.getAttribute('object') === "ObjectId()") {
52
+ elements.push(form);
53
+ }
52
54
  for (let i = 0; i < elements.length; i++) {
53
- elements[i].setAttribute('object', '')
54
55
  let array = elements[i].getAttribute('array')
55
- // Add a array to the array list.
56
- if (array && !arrays.includes(array))
57
- arrays.push(array)
58
- }
59
- // Sets the object id for each array in the array.
60
- for (let i = 0; i < arrays.length; i++) {
61
- // TODO: needs access to setTypeValue
62
- setTypeValue(form, { array: arrays[i], object: [{ _id: ObjectId().toString() }] });
56
+ if (!array)
57
+ continue
58
+ elements[i].setAttribute('object', ObjectId().toString())
59
+
63
60
  }
64
61
  }
65
62
 
package/src/index.js CHANGED
@@ -416,11 +416,13 @@ async function filterData(element, data, type, key) {
416
416
  if (Array.isArray(data[type])) {
417
417
  let Data = [], isObject
418
418
  for (let doc of data[type]) {
419
+ if (!doc.$storage)
420
+ continue
419
421
  // TODO: should have been handled by getDataElements()
420
422
  if (type === 'object') {
421
423
  let _id = element.getAttribute('object')
422
424
  if (_id && doc._id !== _id)
423
- return
425
+ continue
424
426
  let $update = doc.$update
425
427
  if ($update) {
426
428
  delete doc.$update
@@ -436,7 +438,7 @@ async function filterData(element, data, type, key) {
436
438
  Data.push(doc[property])
437
439
  }
438
440
  } else
439
- return
441
+ continue
440
442
  }
441
443
 
442
444
  // if (isObject && Data.length === 1) {
@@ -779,10 +781,21 @@ async function getData(form) {
779
781
  }
780
782
 
781
783
  if (Data.type = 'object') {
784
+ if (Data.key == '{}') {
785
+ if (!value)
786
+ continue
787
+ else if (Array.isArray(value) && !value.length)
788
+ continue
789
+ }
790
+
782
791
  if (typeof Data[Data.type] === 'string')
783
- if (Data.key == '{}')
784
- Data[Data.type] = { _id: Data[Data.type], ...value }
785
- else
792
+ if (Data.key == '{}') {
793
+ // TODO: handle if array length more than 1
794
+ if (Array.isArray(value))
795
+ Data[Data.type] = { _id: Data[Data.type], ...value[0] }
796
+ else
797
+ Data[Data.type] = { _id: Data[Data.type], ...value }
798
+ } else
786
799
  Data[Data.type] = { _id: Data[Data.type], [Data.key]: value }
787
800
  else if (Array.isArray(Data[Data.type]))
788
801
  if (Data.key == '{}')
@@ -1130,6 +1143,11 @@ function initSocket() {
1130
1143
  CRUD.listen(action, function (data) {
1131
1144
  if (data.resolved && data.status === 'received' && CRUD.socket.clientId === data.clientId)
1132
1145
  return
1146
+ if (data.rendered)
1147
+ return
1148
+
1149
+ data.rendered = true
1150
+
1133
1151
  setData(null, data);
1134
1152
  });
1135
1153
  }