@cocreate/elements 1.42.5 → 1.42.6
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 +7 -0
- package/package.json +1 -1
- package/src/fetchSrc.js +2 -1
- package/src/form.js +23 -21
- package/src/index.js +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.42.6](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.5...v1.42.6) (2025-10-10)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* enhance form attribute handling and improve element initialization logic ([6a3eeb3](https://github.com/CoCreate-app/CoCreate-elements/commit/6a3eeb35ccfd1656f71c7e51d0d604d8ccc28071))
|
|
7
|
+
|
|
1
8
|
## [1.42.5](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.4...v1.42.5) (2025-10-08)
|
|
2
9
|
|
|
3
10
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.42.
|
|
3
|
+
"version": "1.42.6",
|
|
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/fetchSrc.js
CHANGED
|
@@ -3,7 +3,7 @@ import { getRelativePath, ObjectId } from "@cocreate/utils";
|
|
|
3
3
|
|
|
4
4
|
const selector =
|
|
5
5
|
"[src]:not(img, video, audio, script, input, iframe, frame, link, source), [source], [stream]";
|
|
6
|
-
const initializing = new Map();
|
|
6
|
+
const textExtensions = ['html','htm','xhtml','css','js','mjs','cjs','json','jsonc','json5','xml','xsd','xsl','xslt','svg','md','markdown','scss','sass','less','vue','jsx','tsx','graphql','gql','htc','webmanifest','txt','csv','tsv','yaml','yml','toml','ini','log','dat','env','c','cc','cpp','cxx','h','hh','hpp','hxx','m','mm','cs','java','jsp','properties','py','pyc','pyd','pyo','rb','erb','php','phtml','php3','php4','php5','php7','phps','go','rs','swift','kt','kts','ts','pl','pm','pod','sh','bash','zsh','ksh','csh','tcsh','ps1','psm1','psd1','bat','cmd','sql','r','Rprofile','Rmd','lua','hs','lhs','erl','hrl','scala','sbt','d','f','for','f77','f90','f95','f03','f08','adb','ads','cbl','cob','cpy','lisp','lsp','scm','ss','pro','plg','vb','vbs','dart','asm','s','conf','cfg','config','ini','env','npmrc','yarnrc','gitattributes','gitignore','gitmodules','gitkeep','editorconfig','prettierrc','eslintrc','eslintignore','browserslistrc','package.json','package-lock.json','tsconfig.json','babelrc','vite.config.js','rollup.config.js','webpack.config.js','procfile','dockerfile','dockerignore','makefile','gradle','groovy','pom','properties','service','target','rst','adoc','asciidoc','tex','latex','textile','org','wiki','nfo','rtf','gcode','patch','diff','log','reg','map','sub','srt','dic','wml','rss','atom','gpx','kml','kmz','vcf','vcard','ics','ical','ps','eps','mf','lic','license','pem','key','crt','cert','pub','tpl','liquid','mustache','hbs','twig','blade.php','ejs','coffee','litcoffee','jl','nim','zig','wgsl']; const initializing = new Map();
|
|
7
7
|
|
|
8
8
|
function init(elements) {
|
|
9
9
|
if (elements && !Array.isArray(elements)) elements = [elements];
|
|
@@ -37,6 +37,7 @@ async function initElements(elements) {
|
|
|
37
37
|
if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
|
|
38
38
|
initMediaSource(element, src);
|
|
39
39
|
} else {
|
|
40
|
+
if (src && !textExtensions.includes(src.split('.').pop())) return
|
|
40
41
|
element.removeAttribute("rendered");
|
|
41
42
|
|
|
42
43
|
let text = await response.text();
|
package/src/form.js
CHANGED
|
@@ -54,29 +54,32 @@ function runObjectId(form) {
|
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
+
const formAttributes = [
|
|
58
|
+
"organization_id",
|
|
59
|
+
"host",
|
|
60
|
+
"storage",
|
|
61
|
+
"database",
|
|
62
|
+
"array",
|
|
63
|
+
"index",
|
|
64
|
+
"object",
|
|
65
|
+
"key"
|
|
66
|
+
];
|
|
67
|
+
const formAttributesSelector = formAttributes.map((attr) => `[${attr}]`).join(", ");
|
|
68
|
+
|
|
57
69
|
/**
|
|
58
70
|
* @param form
|
|
59
71
|
*/
|
|
60
72
|
function setAttribute(form, elements) {
|
|
61
|
-
if (!elements)
|
|
62
|
-
elements = form.querySelectorAll(
|
|
63
|
-
"[organization_id], [host], [storage], [database], [array], [index], [object], [key]"
|
|
64
|
-
);
|
|
73
|
+
if (!elements) elements = form.querySelectorAll(formAttributesSelector);
|
|
65
74
|
|
|
66
75
|
for (let attribute of form.attributes) {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
for
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
if (
|
|
75
|
-
!el.getAttribute(attribute.name) &&
|
|
76
|
-
!el.hasAttribute("skip-attribute")
|
|
77
|
-
) {
|
|
78
|
-
el.setAttribute(attribute.name, attribute.value);
|
|
79
|
-
}
|
|
76
|
+
if (!formAttributes.includes(attribute.name)) continue;
|
|
77
|
+
|
|
78
|
+
for (let el of elements) {
|
|
79
|
+
// Set the value of the attribute.
|
|
80
|
+
// TODO: skip-attribute naming convention, perhaps skip by defualt if storage, database, array not the same and use attribute to apply for cases where one _id will be used across 2 arrays
|
|
81
|
+
if ( !el.hasAttribute("skip-attribute") ) {
|
|
82
|
+
el.setAttribute(attribute.name, attribute.value);
|
|
80
83
|
}
|
|
81
84
|
}
|
|
82
85
|
}
|
|
@@ -208,11 +211,10 @@ Observer.init({
|
|
|
208
211
|
Observer.init({
|
|
209
212
|
name: "CoCreateFormElements",
|
|
210
213
|
types: ["addedNodes"],
|
|
211
|
-
selector:
|
|
212
|
-
"[organization_id], [host], [storage], [database], [array], [index], [object], [key]",
|
|
214
|
+
selector: formAttributesSelector,
|
|
213
215
|
callback: function (mutation) {
|
|
214
|
-
|
|
215
|
-
|
|
216
|
+
let form = mutation.target.form || mutation.target.closest("form");
|
|
217
|
+
if (form) setAttribute(form, [mutation.target]);
|
|
216
218
|
}
|
|
217
219
|
});
|
|
218
220
|
|
package/src/index.js
CHANGED
|
@@ -123,7 +123,7 @@ async function initElement(el) {
|
|
|
123
123
|
["INPUT", "TEXTAREA", "SELECT"].includes(el.tagName) ||
|
|
124
124
|
(el.hasAttribute("contenteditable") &&
|
|
125
125
|
el.getAttribute("contenteditable") !== "false") ||
|
|
126
|
-
el.contenteditable
|
|
126
|
+
el.contenteditable || el.value !== undefined || el.hasAttribute("value")
|
|
127
127
|
) {
|
|
128
128
|
if (el.tagName == "IFRAME") {
|
|
129
129
|
// ToDo: saving on contenteditable elements when an objectId does not exist in order to crud or crdt
|
|
@@ -143,7 +143,7 @@ async function initElement(el) {
|
|
|
143
143
|
if (e.detail && e.detail.skip == true) return;
|
|
144
144
|
if (data.type !== "object" && data[data.type] === "pending")
|
|
145
145
|
return;
|
|
146
|
-
|
|
146
|
+
if (!el.value && !el.hasAttribute("value") && el.contenteditable && !el.hasAttribute("contenteditable")) return;
|
|
147
147
|
save(el);
|
|
148
148
|
});
|
|
149
149
|
}
|