@cocreate/elements 1.26.2 → 1.26.4

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,18 @@
1
+ ## [1.26.4](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.26.3...v1.26.4) (2023-11-18)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * dataKey.string ([57cc534](https://github.com/CoCreate-app/CoCreate-elements/commit/57cc5344e7ba3d66e949c9f6999aaf90d066d2d3))
7
+ * return if no dataKey ([ace669b](https://github.com/CoCreate-app/CoCreate-elements/commit/ace669b19c59f37d1a0a2e62043171fd0b0999d2))
8
+
9
+ ## [1.26.3](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.26.2...v1.26.3) (2023-11-16)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * element grouping ([0507b00](https://github.com/CoCreate-app/CoCreate-elements/commit/0507b00fa53a2c1ec774885d6da515c48fcc4f85))
15
+
1
16
  ## [1.26.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.26.1...v1.26.2) (2023-11-12)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/elements",
3
- "version": "1.26.2",
3
+ "version": "1.26.4",
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
@@ -60,8 +60,8 @@ async function init(element) {
60
60
 
61
61
  if (dataObjects && dataObjects.size > 0) {
62
62
  for (let key of dataObjects.keys()) {
63
- let { data } = keys.get(key)
64
- read(Array.from(element), data, { string: key });
63
+ let { data, elements } = keys.get(key)
64
+ read(Array.from(elements.keys()), data, { string: key });
65
65
  }
66
66
  }
67
67
  }
@@ -125,15 +125,11 @@ async function initElement(el) {
125
125
 
126
126
  el.setFilter = (filter) => {
127
127
  data.$filter = filter
128
- let dataKey = initDataKey(el, data)
129
- read(el, data, dataKey)
128
+ // let dataKey = initDataKey(el, data)
129
+ read(el, data)
130
130
  }
131
131
  }
132
132
 
133
- const isRead = el.getAttribute('read');
134
- if (isRead === 'false')
135
- return;
136
-
137
133
  return data;
138
134
  }
139
135
 
@@ -219,10 +215,12 @@ function initDataKey(element, data) {
219
215
 
220
216
  async function read(element, data, dataKey) {
221
217
  if (!dataKey)
222
- dataKey = elements.get(element)
218
+ dataKey = { string: elements.get(element) }
223
219
  if (!data)
224
220
  data = { ...keys.get(dataKey).dataKey.object }
225
221
 
222
+ if (!dataKey || !data.type)
223
+ return
226
224
  if (!data.$filter && (!data[data.type] || !data[data.type].length))
227
225
  return
228
226
 
@@ -236,8 +234,14 @@ async function read(element, data, dataKey) {
236
234
  if (!delay.elements)
237
235
  delay.elements = new Map()
238
236
 
239
- for (let el of element)
240
- delay.elements.set(el, true)
237
+ for (let el of element) {
238
+ const isRead = el.getAttribute('read');
239
+ if (isRead !== 'false')
240
+ delay.elements.set(el, true)
241
+ }
242
+
243
+ if (!delay.elements.size)
244
+ return
241
245
 
242
246
  clearTimeout(delay.timer);
243
247
  delay.timer = setTimeout(function () {
@@ -256,14 +260,14 @@ async function read(element, data, dataKey) {
256
260
 
257
261
  data.method = data.type + '.read'
258
262
 
259
- CRUD.send(data).then((data) => {
263
+ CRUD.send(data).then((Data) => {
260
264
  debounce.delete(dataKey.string)
261
265
  let els = Array.from(delay.elements.keys())
262
266
  clearTimeout(delay.timer);
263
267
  delete delay.elements
264
268
  delete delay.timer
265
269
 
266
- setData(els, data);
270
+ setData(els, Data);
267
271
  })
268
272
  }, 500);
269
273
  }
@@ -322,10 +326,10 @@ async function filterData(element, data, type, key) {
322
326
  Data.push(doc[key])
323
327
  }
324
328
  }
325
- if (Data.length === 1) {
326
- data = { [key]: Data[0] }
327
- } else
328
- data = Data
329
+ // if (Data.length === 1) {
330
+ // data = { [key]: Data[0] }
331
+ // } else
332
+ data = Data
329
333
  } else {
330
334
  data = { [key]: data[type][key] }
331
335
  }
@@ -338,7 +342,8 @@ async function filterData(element, data, type, key) {
338
342
  } else if (data)
339
343
  element.setValue(data)
340
344
 
341
- filter.filters.get(element).index = data.$filter.index
345
+ if (data.$filter)
346
+ filter.filters.get(element).index = data.$filter.index
342
347
 
343
348
  const evt = new CustomEvent('fetchedData', { bubbles: true });
344
349
  element.dispatchEvent(evt);
@@ -529,8 +534,9 @@ async function getData(form) {
529
534
  let formObject = forms.get(form)
530
535
  for (let type of formObject.types.values()) {
531
536
  for (let [element, data] of type.entries()) {
532
- if (!element.hasAttribute('key'))
537
+ if (!element.hasAttribute('key') || element.getAttribute('save') === 'false')
533
538
  continue
539
+
534
540
  if (element.hasAttribute('actions')) {
535
541
  let attribute = element.getAttribute('actions')
536
542
  if (attribute.includes('save', 'delete'))
@@ -690,7 +696,7 @@ async function save(element) {
690
696
 
691
697
  let Data = []
692
698
  for (let i = 0; i < data.length; i++) {
693
- if (data[i].type === 'object' && !data[i].method) {
699
+ if (data[i].type === 'object') {
694
700
  if (typeof data[i].object === 'string') {
695
701
  if (!data[i]._id)
696
702
  data[i].method = 'object.create'
@@ -778,6 +784,8 @@ function setTypeValue(element, data) {
778
784
  el.setAttribute(data.type, data[data.type].name)
779
785
  }
780
786
  }
787
+ setData(Array.from(elements.keys()), data)
788
+
781
789
 
782
790
  // const pass_ids = new Map();
783
791
 
@@ -882,7 +890,9 @@ async function remove(element) {
882
890
  if (!form.elements.size)
883
891
  forms.delete(form)
884
892
  }
885
- }
893
+ } else
894
+ elements.delete(element[i])
895
+
886
896
  }
887
897
  }
888
898
  }
@@ -1073,8 +1083,11 @@ Observer.init({
1073
1083
  attributeName: ['storage', 'database', 'array', 'index', 'object', 'key'],
1074
1084
  // target: selector, // blocks mutations when applied
1075
1085
  callback: function (mutation) {
1076
- remove(mutation.target)
1077
- init([mutation.target]);
1086
+ let currentValue = mutation.target.getAttribute(mutation.attributeName)
1087
+ if (currentValue !== mutation.oldValue) {
1088
+ remove(mutation.target)
1089
+ init([mutation.target])
1090
+ }
1078
1091
  }
1079
1092
  });
1080
1093