@cocreate/elements 1.36.0 → 1.36.2

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,22 @@
1
+ ## [1.36.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.36.1...v1.36.2) (2024-08-24)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * prevent duplicate input event listeners ([e7d5bfd](https://github.com/CoCreate-app/CoCreate-elements/commit/e7d5bfd7c254b9e4a76bd5eb55106b86357904c9))
7
+ * use continue in for loop ([e0febbc](https://github.com/CoCreate-app/CoCreate-elements/commit/e0febbcbf16486d54e312cd646f2d2a255e71848))
8
+
9
+ ## [1.36.1](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.36.0...v1.36.1) (2024-07-09)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * handleing of key="{}" where value is an array ([c86ffd9](https://github.com/CoCreate-app/CoCreate-elements/commit/c86ffd9697839611e8fb10a3f76e0a9bff9892cb))
15
+ * objectId() habndleing to add _id to element ([b2bb7b4](https://github.com/CoCreate-app/CoCreate-elements/commit/b2bb7b423ea2316be0087506fa094a3a8e8cce09))
16
+ * removed testing log ([1b4f38e](https://github.com/CoCreate-app/CoCreate-elements/commit/1b4f38e0cfc1b764dd695dc3288e74f6cb15b676))
17
+ * set flag rendered to prevent loop caused by fireListeners and sync ([3dd1267](https://github.com/CoCreate-app/CoCreate-elements/commit/3dd1267784617c1a666b032fc427671f0cf07375))
18
+ * use continue in for loop and continue if !data$storage ([32020f1](https://github.com/CoCreate-app/CoCreate-elements/commit/32020f17fecc6a578ff58b9fd1dec50a6f611b11))
19
+
1
20
  # [1.36.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.35.8...v1.36.0) (2024-06-30)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/elements",
3
- "version": "1.36.0",
3
+ "version": "1.36.2",
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/fetchSrc.js CHANGED
@@ -19,7 +19,7 @@ async function initElements(elements) {
19
19
  let src = element.getAttribute('src') || element.getAttribute('source') || element.getAttribute('stream');
20
20
 
21
21
  if (!src || /{{\s*([\w\W]+)\s*}}/g.test(src))
22
- return;
22
+ continue;
23
23
 
24
24
  let initialize = initializing.get(element)
25
25
  if (!initialize || initialize.src != src) {
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
@@ -97,18 +97,26 @@ async function initElement(el) {
97
97
  if (!elements.has(el)) {
98
98
  elements.set(el, '')
99
99
 
100
- if (['INPUT', 'TEXTAREA', 'SELECT'].includes(el.tagName)
101
- || (el.hasAttribute('contenteditable') && el.getAttribute('contenteditable') !== 'false')
102
- || el.contenteditable) {
103
- el.addEventListener('input', function (e) {
104
- const { object, key, isRealtime, isCrdt } = getAttributes(el);
105
- if (!isRealtime || isRealtime === "false" || key === "_id") return;
106
- if (isCrdt == "true" && object && object !== 'pending') return
107
- if (e.detail && e.detail.skip == true) return;
108
- if (data.type !== 'object' && data[data.type] === 'pending') return
109
-
110
- save(el);
111
- });
100
+ if (el.tagName === "EDITOR")
101
+ console.log('editor event added')
102
+ if (!el.elementsInputEvent) {
103
+ el.elementsInputEvent = true;
104
+
105
+ if (['INPUT', 'TEXTAREA', 'SELECT'].includes(el.tagName)
106
+ || (el.hasAttribute('contenteditable') && el.getAttribute('contenteditable') !== 'false')
107
+ || el.contenteditable) {
108
+ el.addEventListener('input', function (e) {
109
+ if (el.pendingObject) return
110
+
111
+ const { object, key, isRealtime, isCrdt } = getAttributes(el);
112
+ if (!isRealtime || isRealtime === "false" || key === "_id") return;
113
+ if (isCrdt == "true" && object && object !== 'pending') return
114
+ if (e.detail && e.detail.skip == true) return;
115
+ if (data.type !== 'object' && data[data.type] === 'pending') return
116
+
117
+ save(el);
118
+ });
119
+ }
112
120
  }
113
121
  }
114
122
  // let attributes = ['filter-key', 'filter-search', 'filter-sort-key', 'filter-on', 'filter-limit']
@@ -416,11 +424,13 @@ async function filterData(element, data, type, key) {
416
424
  if (Array.isArray(data[type])) {
417
425
  let Data = [], isObject
418
426
  for (let doc of data[type]) {
427
+ if (!doc.$storage)
428
+ continue
419
429
  // TODO: should have been handled by getDataElements()
420
430
  if (type === 'object') {
421
431
  let _id = element.getAttribute('object')
422
432
  if (_id && doc._id !== _id)
423
- return
433
+ continue
424
434
  let $update = doc.$update
425
435
  if ($update) {
426
436
  delete doc.$update
@@ -436,7 +446,7 @@ async function filterData(element, data, type, key) {
436
446
  Data.push(doc[property])
437
447
  }
438
448
  } else
439
- return
449
+ continue
440
450
  }
441
451
 
442
452
  // if (isObject && Data.length === 1) {
@@ -779,10 +789,21 @@ async function getData(form) {
779
789
  }
780
790
 
781
791
  if (Data.type = 'object') {
792
+ if (Data.key == '{}') {
793
+ if (!value)
794
+ continue
795
+ else if (Array.isArray(value) && !value.length)
796
+ continue
797
+ }
798
+
782
799
  if (typeof Data[Data.type] === 'string')
783
- if (Data.key == '{}')
784
- Data[Data.type] = { _id: Data[Data.type], ...value }
785
- else
800
+ if (Data.key == '{}') {
801
+ // TODO: handle if array length more than 1
802
+ if (Array.isArray(value))
803
+ Data[Data.type] = { _id: Data[Data.type], ...value[0] }
804
+ else
805
+ Data[Data.type] = { _id: Data[Data.type], ...value }
806
+ } else
786
807
  Data[Data.type] = { _id: Data[Data.type], [Data.key]: value }
787
808
  else if (Array.isArray(Data[Data.type]))
788
809
  if (Data.key == '{}')
@@ -1130,6 +1151,11 @@ function initSocket() {
1130
1151
  CRUD.listen(action, function (data) {
1131
1152
  if (data.resolved && data.status === 'received' && CRUD.socket.clientId === data.clientId)
1132
1153
  return
1154
+ if (data.rendered)
1155
+ return
1156
+
1157
+ data.rendered = true
1158
+
1133
1159
  setData(null, data);
1134
1160
  });
1135
1161
  }