@cocreate/elements 1.35.7 → 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 +19 -0
- package/package.json +6 -6
- package/src/form.js +19 -1
- package/src/index.js +9 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,22 @@
|
|
|
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
|
+
|
|
13
|
+
## [1.35.8](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.35.7...v1.35.8) (2024-06-23)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Bug Fixes
|
|
17
|
+
|
|
18
|
+
* bump dependencies ([9d08d3b](https://github.com/CoCreate-app/CoCreate-elements/commit/9d08d3b3e3614efcdbd79312ffa456529b8e89bd))
|
|
19
|
+
|
|
1
20
|
## [1.35.7](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.35.6...v1.35.7) (2024-06-23)
|
|
2
21
|
|
|
3
22
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.
|
|
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",
|
|
@@ -58,12 +58,12 @@
|
|
|
58
58
|
"webpack-log": "^3.0.1"
|
|
59
59
|
},
|
|
60
60
|
"dependencies": {
|
|
61
|
-
"@cocreate/actions": "^1.18.
|
|
62
|
-
"@cocreate/crud-client": "^1.11
|
|
61
|
+
"@cocreate/actions": "^1.18.4",
|
|
62
|
+
"@cocreate/crud-client": "^1.33.11",
|
|
63
63
|
"@cocreate/element-prototype": "^1.23.0",
|
|
64
64
|
"@cocreate/filter": "^1.15.1",
|
|
65
|
-
"@cocreate/observer": "^1.16.
|
|
66
|
-
"@cocreate/render": "^1.
|
|
67
|
-
"@cocreate/utils": "^1.34.
|
|
65
|
+
"@cocreate/observer": "^1.16.3",
|
|
66
|
+
"@cocreate/render": "^1.41.3",
|
|
67
|
+
"@cocreate/utils": "^1.34.1"
|
|
68
68
|
}
|
|
69
69
|
}
|
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
|
}
|