@cocreate/elements 1.35.8 → 1.36.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,15 @@
1
+ # [1.36.0](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.35.8...v1.36.0) (2024-06-30)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * re init form elements ([7b28c19](https://github.com/CoCreate-app/CoCreate-elements/commit/7b28c19fe31bed297b930d113c98cfd9f913b0fe))
7
+
8
+
9
+ ### Features
10
+
11
+ * form.setValue() will set value in elements if value is object else it if string will fallback elementPrototype setVlaue() ([e76df88](https://github.com/CoCreate-app/CoCreate-elements/commit/e76df88fb1755aeffa8f15587d304e2df6497801))
12
+
1
13
  ## [1.35.8](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.35.7...v1.35.8) (2024-06-23)
2
14
 
3
15
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/elements",
3
- "version": "1.35.8",
3
+ "version": "1.36.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
@@ -1,7 +1,7 @@
1
1
  import Observer from '@cocreate/observer';
2
2
  import { getAttributeNames, ObjectId } from '@cocreate/utils';
3
3
  import Action from '@cocreate/actions';
4
- import '@cocreate/element-prototype';
4
+ import elementPrototype from '@cocreate/element-prototype';
5
5
 
6
6
 
7
7
  /**
@@ -33,6 +33,7 @@ function init(elements) {
33
33
  runObjectId(element);
34
34
  setAttribute(element);
35
35
  disableAutoFill(element);
36
+ setValue(element)
36
37
  element.addEventListener('submit', function (event) {
37
38
  if (!element.hasAttribute('action')) {
38
39
  event.preventDefault();
@@ -134,6 +135,23 @@ function reset(form) {
134
135
  }));
135
136
  }
136
137
 
138
+ function setValue(form) {
139
+ form.setValue = (value) => {
140
+ if (typeof value !== "object")
141
+ elementPrototype.setValue(form, value);
142
+ else {
143
+ const inputs = form.querySelectorAll('[name], [key]');
144
+ inputs.forEach(element => {
145
+ const key = element.getAttribute('key') || element.getAttribute('name');
146
+ if (value[key]) {
147
+ element.setValue(value[key]);
148
+ }
149
+ });
150
+
151
+ }
152
+ }
153
+ }
154
+
137
155
  Observer.init({
138
156
  name: 'CoCreateForm',
139
157
  observe: ['addedNodes'],
package/src/index.js CHANGED
@@ -53,7 +53,7 @@ const debounce = new Map();
53
53
  * any of these CRUD attributes: "storage", "database", "array", "render-json".
54
54
  */
55
55
  async function init(element) {
56
- if (element && !(element instanceof HTMLCollection) && !Array.isArray(element))
56
+ if (element && !(element instanceof HTMLCollection) && !(element instanceof NodeList) && !Array.isArray(element))
57
57
  element = [element]
58
58
  else if (!element) {
59
59
  element = document.querySelectorAll(selector)
@@ -716,6 +716,12 @@ function getDataKeys(data) {
716
716
  async function getData(form) {
717
717
  let dataKeys = new Map()
718
718
  let formObject = forms.get(form)
719
+ if (!formObject) {
720
+ let elements = form.querySelectorAll(selector)
721
+ await init(elements)
722
+ return await getData(form)
723
+ }
724
+
719
725
  for (let type of formObject.types.values()) {
720
726
  for (let [element, data] of type.entries()) {
721
727
  if (!element.hasAttribute('key') || element.getAttribute('save') === 'false')
@@ -1317,6 +1323,8 @@ Observer.init({
1317
1323
  let currentValue = mutation.target.getAttribute(mutation.attributeName)
1318
1324
  if (currentValue !== mutation.oldValue) {
1319
1325
  remove(mutation.target)
1326
+ if (mutation.target.tagName === 'FORM')
1327
+ return
1320
1328
  init([mutation.target])
1321
1329
  }
1322
1330
  }