@cocreate/elements 1.24.2 → 1.25.0

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.25.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.24.3...v1.25.0) (2023-10-22)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * conditions ([484ad35](https://github.com/CoCreate-app/CoCreate-elements/commit/484ad358f13fc07e92ebafbf710ccdc1fb740950))
7
+
8
+
9
+ ### Features
10
+
11
+ * ObjectId() returns an object containg the parts iof the _id along with a toString() function ([82e3956](https://github.com/CoCreate-app/CoCreate-elements/commit/82e3956db5c5bc966d160a04d9067bc039c34d37))
12
+
13
+ ## [1.24.3](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.24.2...v1.24.3) (2023-10-20)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * condition on read ([fe53a8e](https://github.com/CoCreate-app/CoCreate-elements/commit/fe53a8ea9808502af64a8298a14dd38bbfd07940))
19
+
1
20
  ## [1.24.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.24.1...v1.24.2) (2023-10-19)
2
21
 
3
22
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/elements",
3
- "version": "1.24.2",
3
+ "version": "1.25.0",
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
@@ -38,7 +38,7 @@ function runObjectId(form) {
38
38
  // Sets the object id for each array in the array.
39
39
  for (let i = 0; i < arrays.length; i++) {
40
40
  // TODO: needs access to setTypeValue
41
- setTypeValue(form, { array: arrays[i], object: [{ _id: ObjectId() }] });
41
+ setTypeValue(form, { array: arrays[i], object: [{ _id: ObjectId().toString() }] });
42
42
  }
43
43
  }
44
44
 
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, renderedNodes } from '@cocreate/render';
31
+ import render from '@cocreate/render';
32
32
  import '@cocreate/element-prototype';
33
33
  import './fetchSrc';
34
34
  import { reset } from './form'
@@ -73,13 +73,13 @@ async function initElement(el) {
73
73
  // if found add the node as an element, if the element has crud attributes also add as the element
74
74
  for (let attribute of el.attributes) {
75
75
  if (attribute.match(/{{(.*?)}}/)) {
76
- let value = renderValue(attribute, undefined, attribute.value)
76
+ let value = render.renderValue(attribute, undefined, attribute.value)
77
77
  if (value)
78
78
  attribute.value = value
79
79
  }
80
80
  }
81
81
  if (el.innerHTML.match(/{{(.*?)}}/)) {
82
- let value = renderValue(el, undefined, el.innerHTML)
82
+ let value = render.renderValue(el, undefined, el.innerHTML)
83
83
  if (value)
84
84
  attribute.value = value
85
85
  }
@@ -110,9 +110,8 @@ async function initElement(el) {
110
110
  el.addEventListener('input', function (e) {
111
111
  const { object, key, isRealtime, isCrdt } = getAttributes(el);
112
112
  if (isRealtime == "false" || key == "_id") return;
113
-
114
113
  if (isCrdt == "true" && object && object !== 'pending') return
115
- if (object && e.detail && e.detail.skip == true) return;
114
+ if (e.detail && e.detail.skip == true) return;
116
115
  if (data.type !== 'object' && data[data.type] === 'pending') return
117
116
 
118
117
  save(el);
@@ -231,13 +230,14 @@ async function read(element, data, dataKey) {
231
230
  debounce.delete(dataKey.string)
232
231
  // TODO: should server support string and string array for type object, methods create, read, delete
233
232
  if (!data.$filter && data.type === 'object') {
234
- if (typeof data.object === 'string')
233
+ if (!data.object)
234
+ return
235
+ else if (typeof data.object === 'string')
235
236
  data.object = { _id: data.object }
236
-
237
- if (Array.isArray(data.object))
238
- data.object = { _id: data.object[0]._id }
239
-
240
- if (!data.object._id.match(/^[0-9a-fA-F]{24}$/))
237
+ else if (Array.isArray(data.object)) {
238
+ if (data.object.length)
239
+ data.object = { _id: data.object[0]._id }
240
+ } else if (!data.object._id.match(/^[0-9a-fA-F]{24}$/))
241
241
  return
242
242
  }
243
243
 
@@ -284,7 +284,7 @@ async function setData(element, data) {
284
284
  if (key) {
285
285
  if (!data[type].length) continue;
286
286
  if (isRead == "false" || isCrdt == "true") continue;
287
- if (isListen == "false" && !data.method.startsWith('read')) continue;
287
+ if (isListen == "false" && !data.method.startsWith('read.')) continue;
288
288
  }
289
289
  // TODO: update.object data returned from server will not include $operator
290
290
  el.setValue(value);
@@ -311,7 +311,7 @@ async function filterData(element, data, type, key) {
311
311
  }
312
312
  }
313
313
 
314
- if (element.getFilter && data.method && !data.method.startsWith('read'))
314
+ if (element.getFilter && data.method && !data.method.startsWith('read.'))
315
315
  await checkFilters(element, data, type)
316
316
  else if (element.renderValue)
317
317
  element.renderValue(data);
@@ -697,9 +697,9 @@ async function save(element) {
697
697
  }
698
698
  }
699
699
 
700
- if (data[i].method && data[i].method.startsWith('create')) {
700
+ if (data[i].method && data[i].method.startsWith('create.')) {
701
701
  element.setAttribute(data[i].type, 'pending');
702
- } else if (data[i].method && data[i].method.startsWith('update') && data[i].type == 'object' && typeof value == 'string' && window.CoCreate.crdt && !'crdt') {
702
+ } else if (data[i].method && data[i].method.startsWith('update.') && data[i].type == 'object' && typeof value == 'string' && window.CoCreate.crdt && !'crdt') {
703
703
  return window.CoCreate.crdt.replaceText({
704
704
  array: data[i].array,
705
705
  key: data[i].key,
@@ -713,7 +713,7 @@ async function save(element) {
713
713
 
714
714
  Data.push(data[i])
715
715
 
716
- if (data[i] && (data[i].method.startsWith('create') || data[i].type !== 'object' && data[i].method.startsWith('update'))) {
716
+ if (data[i] && (data[i].method.startsWith('create.') || data[i].type !== 'object' && data[i].method.startsWith('update.'))) {
717
717
  setTypeValue(element, data[i])
718
718
  } else if (data[i])
719
719
  document.dispatchEvent(new CustomEvent('saved', {
@@ -822,7 +822,10 @@ async function remove(element) {
822
822
  element = [element]
823
823
  for (let i = 0; i < element.length; i++) {
824
824
  if (element[i].tagName === 'FORM') {
825
- let form = forms.get(element[i]).elements
825
+ let form = forms.get(element[i])
826
+ if (!form) return
827
+
828
+ form = form.elements
826
829
  for (let el of form.keys()) {
827
830
  let key = elements.get(el)
828
831
  if (key) {
@@ -878,7 +881,7 @@ Observer.init({
878
881
  clearTimeout(delayTimer);
879
882
  debounce.delete(mutation.target)
880
883
 
881
- let renderedNode = renderedNodes.get(mutation.target)
884
+ let renderedNode = render.renderedNodes.get(mutation.target)
882
885
  if (!renderedNode) return
883
886
 
884
887
  if (!mutation.movedFrom) return
@@ -985,7 +988,7 @@ function dndNewData(element, data) {
985
988
 
986
989
  let keyPath, clonesMap, clones, index
987
990
 
988
- let renderedNode = renderedNodes.get(element)
991
+ let renderedNode = render.renderedNodes.get(element)
989
992
  if (renderedNode) {
990
993
  keyPath = renderedNode.keyPath
991
994
  clonesMap = renderedNode.template.clones