@cocreate/elements 1.42.4 → 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 CHANGED
@@ -1,3 +1,18 @@
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
+
8
+ ## [1.42.5](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.4...v1.42.5) (2025-10-08)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * ensure key checks in setData and filterData handle undefined values correctly ([fd04107](https://github.com/CoCreate-app/CoCreate-elements/commit/fd04107fde4d1d51ce215d3da5f241c47565aa92))
14
+ * import getRelativePath and remove unused getPath function in fetchSrc.js ([363497c](https://github.com/CoCreate-app/CoCreate-elements/commit/363497cd9fa0b2e920e226766488593e46f6db8f))
15
+
1
16
  ## [1.42.4](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.3...v1.42.4) (2025-09-07)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/elements",
3
- "version": "1.42.4",
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
@@ -1,9 +1,9 @@
1
1
  import observer from "@cocreate/observer";
2
- import { ObjectId } from "@cocreate/utils";
2
+ 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();
@@ -44,9 +45,11 @@ async function initElements(elements) {
44
45
  let path = "";
45
46
  let pathElement = element.closest("[path]");
46
47
  if (pathElement) {
47
- path = pathElement.getAttribute("path") || getPath();
48
+ path =
49
+ pathElement.getAttribute("path") ||
50
+ getRelativePath();
48
51
  } else {
49
- path = getPath();
52
+ path = getRelativePath();
50
53
  }
51
54
  // Replace $relativePath in the fetched text
52
55
  if (path) {
@@ -66,16 +69,6 @@ async function initElements(elements) {
66
69
  }
67
70
  }
68
71
 
69
- function getPath() {
70
- let currentPath = window.location.pathname.replace(/\/[^\/]*$/, ""); // Remove file from path
71
- if (!currentPath.endsWith("/")) {
72
- currentPath += "/";
73
- }
74
- let depth = currentPath.split("/").filter(Boolean).length; // Count depth levels
75
-
76
- return depth > 0 ? "../".repeat(depth) : "./"; // Return the correct relative path
77
- }
78
-
79
72
  async function initMediaSource(element, src) {
80
73
  try {
81
74
  let mediaConfig = await response.json();
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
- let variable = window.CoCreateConfig.attributes[attribute.name];
68
-
69
- // Set the attribute of all elements in the variable
70
- if (variable) {
71
- for (let el of elements) {
72
- // Set the value of the attribute.
73
- // 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
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
- if (mutation.target.form)
215
- setAttribute(mutation.target.form, [mutation.target]);
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
  }
@@ -430,11 +430,11 @@ async function setData(element, data) {
430
430
  data[type][0] = { ...data[type][0], ...$update };
431
431
  } else if (key === "$data") {
432
432
  value = data;
433
- } else if (key.startsWith("$data")) {
433
+ } else if (key && key.startsWith("$data")) {
434
434
  value = CRUD.getValueFromObject(data, key.slice(1));
435
435
  } else if (key === `$${type}`) {
436
436
  value = data[type];
437
- } else if (key.startsWith(`$${type}`)) {
437
+ } else if (key && key.startsWith(`$${type}`)) {
438
438
  value = CRUD.getValueFromObject(data, key.slice(1));
439
439
  } else if (key === "{}") {
440
440
  value = data[type][0];
@@ -562,11 +562,11 @@ async function filterData(element, data, type, key) {
562
562
  element.setValue(value.length);
563
563
  } else if (key === "$data") {
564
564
  value = data;
565
- } else if (key.startsWith("$data")) {
565
+ } else if (key && key.startsWith("$data")) {
566
566
  value = CRUD.getValueFromObject(data, key.slice(1));
567
567
  } else if (key === `$${type}`) {
568
568
  value = data[type];
569
- } else if (key.startsWith(`$${type}`)) {
569
+ } else if (key && key.startsWith(`$${type}`)) {
570
570
  value = CRUD.getValueFromObject(data, key.slice(1));
571
571
  } else if (key === "{}") {
572
572
  value = data[type][0];