@cocreate/elements 1.42.5 → 1.42.7

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,20 @@
1
+ ## [1.42.7](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.6...v1.42.7) (2025-11-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * correct formatting in save function to ensure proper data handling ([19e0bdc](https://github.com/CoCreate-app/CoCreate-elements/commit/19e0bdccd02e95ffc4c0db22b7a96ad18bad663a))
7
+ * enhance setAttribute function to respect form-attributes and streamline attribute setting ([ce6c03b](https://github.com/CoCreate-app/CoCreate-elements/commit/ce6c03bfca08ac4634320725a72820fde49f604e))
8
+ * update filterData function to handle key-based data rendering ([2b4aecb](https://github.com/CoCreate-app/CoCreate-elements/commit/2b4aecb4f56ec0eb2666a56041b41f6191cb4e5e))
9
+ * update initElements function to correctly handle 'rendered' attribute and improve src validation ([a371968](https://github.com/CoCreate-app/CoCreate-elements/commit/a371968596c5c50a7f53c6f822ab7e432e985bad))
10
+
11
+ ## [1.42.6](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.5...v1.42.6) (2025-10-10)
12
+
13
+
14
+ ### Bug Fixes
15
+
16
+ * enhance form attribute handling and improve element initialization logic ([6a3eeb3](https://github.com/CoCreate-app/CoCreate-elements/commit/6a3eeb35ccfd1656f71c7e51d0d604d8ccc28071))
17
+
1
18
  ## [1.42.5](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.4...v1.42.5) (2025-10-08)
2
19
 
3
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/elements",
3
- "version": "1.42.5",
3
+ "version": "1.42.7",
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,8 +37,12 @@ async function initElements(elements) {
37
37
  if (element.tagName === "AUDIO" || element.tagName === "VIDEO") {
38
38
  initMediaSource(element, src);
39
39
  } else {
40
- element.removeAttribute("rendered");
40
+ if (src && !textExtensions.includes(src.split('.').pop())) continue
41
41
 
42
+ if (element.hasAttribute("rendered")) {
43
+ element.removeAttribute("rendered");
44
+ // continue;
45
+ }
42
46
  let text = await response.text();
43
47
  if (text) {
44
48
  let path = "";
package/src/form.js CHANGED
@@ -54,30 +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
- );
65
-
66
- 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
- }
80
- }
73
+ if (!elements) elements = form.querySelectorAll(formAttributesSelector);
74
+ for (let el of elements) {
75
+ if (el.getAttribute("form-attributes") === "false") continue;
76
+ for (let attribute of form.attributes) {
77
+ if (!formAttributes.includes(attribute.name)) continue;
78
+ // let elArray = el.getAttribute("array");
79
+ // if (elArray && attribute.name === "array" && elArray !== attribute.value) break;
80
+ // Set the value of the attribute.
81
+ // TODO: form-attributes="false" 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
82
+ el.setAttribute(attribute.name, attribute.value);
81
83
  }
82
84
  }
83
85
  }
@@ -208,11 +210,10 @@ Observer.init({
208
210
  Observer.init({
209
211
  name: "CoCreateFormElements",
210
212
  types: ["addedNodes"],
211
- selector:
212
- "[organization_id], [host], [storage], [database], [array], [index], [object], [key]",
213
+ selector: formAttributesSelector,
213
214
  callback: function (mutation) {
214
- if (mutation.target.form)
215
- setAttribute(mutation.target.form, [mutation.target]);
215
+ let form = mutation.target.form || mutation.target.closest("form");
216
+ if (form) setAttribute(form, [mutation.target]);
216
217
  }
217
218
  });
218
219
 
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
  }
@@ -551,6 +551,8 @@ async function filterData(element, data, type, key) {
551
551
  ) {
552
552
  await checkFilters(element, data, type);
553
553
  } else if (element.renderValue) {
554
+ if (key)
555
+ data = {[key]: data}
554
556
  await element.renderValue(data);
555
557
  } else if (key === "$length") {
556
558
  element.setValue(data[type].length);
@@ -1114,7 +1116,7 @@ async function save(element, action) {
1114
1116
  data[i].method = "object.update";
1115
1117
  if (upsert) data[i].upsert = true;
1116
1118
  }
1117
- }
1119
+ }
1118
1120
  }
1119
1121
 
1120
1122
  if (data[i].isUpsert) {