@cocreate/elements 1.35.2 → 1.35.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 CHANGED
@@ -1,3 +1,12 @@
1
+ ## [1.35.3](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.35.2...v1.35.3) (2024-05-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * handling of data upsert ([9884f90](https://github.com/CoCreate-app/CoCreate-elements/commit/9884f90b3b9e0016b266a36e6e5b377dc93fc6b7))
7
+ * replace form object attribute with id if pending ([33838fb](https://github.com/CoCreate-app/CoCreate-elements/commit/33838fbe3e12f6a6b4e8fbcaa76822315b61ccdd))
8
+ * typo with for loop index j ([8872c9f](https://github.com/CoCreate-app/CoCreate-elements/commit/8872c9f7b009638018ac48ffec41898a618b0cdd))
9
+
1
10
  ## [1.35.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.35.1...v1.35.2) (2024-04-29)
2
11
 
3
12
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/elements",
3
- "version": "1.35.2",
3
+ "version": "1.35.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/index.js CHANGED
@@ -78,13 +78,19 @@ async function init(element) {
78
78
  read(Array.from(elements.keys()), data, { string: key });
79
79
  }
80
80
  }
81
+
82
+ // const evt = new CustomEvent('elementsInitialized', { bubbles: true });
83
+ // document.dispatchEvent(evt);
84
+
81
85
  }
82
86
 
83
87
  async function initElement(el) {
84
88
  // if (el.closest('.template')) return;
85
89
 
86
90
  let data = getObject(el);
87
- if (!data || !data.type) return
91
+ if (!data || !data.type)
92
+ return
93
+
88
94
  if (data.object && data.object !== 'pending' && !(/^[0-9a-fA-F]{24}$/.test(data.object)))
89
95
  return
90
96
 
@@ -134,7 +140,7 @@ function getObject(element) {
134
140
  data[crudType[i]] = []
135
141
 
136
142
  for (let j = 0; j < array.length; j++) {
137
- array[i].trim()
143
+ array[j].trim()
138
144
  if (crudType[i] === 'object') {
139
145
  data[crudType[i]].push({ _id: array[j] })
140
146
  } else {
@@ -247,8 +253,18 @@ async function read(element, data, dataKey) {
247
253
  data.object = { _id: data.object[0]._id }
248
254
  } else if (!data.object._id.match(/^[0-9a-fA-F]{24}$/))
249
255
  return
256
+ // if (data.object._id.startsWith('$'))
257
+ // return
250
258
  }
251
259
 
260
+ // if (data.object && !Array.isArray(data.object) && data.object._id.startsWith('$'))
261
+ // return
262
+
263
+ // if (data.$filter && data.$filter.query) {
264
+ // if (!Object.keys(data.$filter.query).length)
265
+ // return
266
+ // }
267
+
252
268
  data.method = data.type + '.read'
253
269
 
254
270
  CRUD.send(data).then((Data) => {
@@ -863,6 +879,11 @@ async function save(element) {
863
879
  }
864
880
  }
865
881
 
882
+ if (data[i].isUpsert) {
883
+ data[i].upsert = true
884
+ delete data[i].isUpsert
885
+ }
886
+
866
887
  if (data[i].method && data[i].method.endsWith('.create')) {
867
888
  element.setAttribute(data[i].type, 'pending');
868
889
  } else if (data[i].method && data[i].method.endsWith('.update') && data[i].type == 'object' && typeof value == 'string' && window.CoCreate.crdt && !'crdt') {
@@ -910,6 +931,9 @@ function setTypeValue(element, data) {
910
931
  }
911
932
  } else {
912
933
  let formObject = forms.get(form)
934
+ if (form.getAttribute('object') === 'pending')
935
+ form.setAttribute('object', data.object[0]._id)
936
+
913
937
  let elements = formObject.types.get(data.type)
914
938
 
915
939
  for (let [el, Data] of elements.entries()) {