@cocreate/elements 1.42.3 → 1.42.5

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,19 @@
1
+ ## [1.42.5](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.4...v1.42.5) (2025-10-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * ensure key checks in setData and filterData handle undefined values correctly ([fd04107](https://github.com/CoCreate-app/CoCreate-elements/commit/fd04107fde4d1d51ce215d3da5f241c47565aa92))
7
+ * import getRelativePath and remove unused getPath function in fetchSrc.js ([363497c](https://github.com/CoCreate-app/CoCreate-elements/commit/363497cd9fa0b2e920e226766488593e46f6db8f))
8
+
9
+ ## [1.42.4](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.3...v1.42.4) (2025-09-07)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * enhance path handling in initElements and improve data assignment logic in setData ([5c710c5](https://github.com/CoCreate-app/CoCreate-elements/commit/5c710c594d584598ced06a9bcf7954ec30d048d2))
15
+ * streamline relative path handling by removing trailing slashes in replacement and ensuring current path ends with a slash ([03ba778](https://github.com/CoCreate-app/CoCreate-elements/commit/03ba77826700c56a7f07b86f8f6588aaece9a3a4))
16
+
1
17
  ## [1.42.3](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.2...v1.42.3) (2025-09-01)
2
18
 
3
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/elements",
3
- "version": "1.42.3",
3
+ "version": "1.42.5",
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,5 +1,5 @@
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]";
@@ -41,19 +41,20 @@ async function initElements(elements) {
41
41
 
42
42
  let text = await response.text();
43
43
  if (text) {
44
+ let path = "";
44
45
  let pathElement = element.closest("[path]");
45
46
  if (pathElement) {
46
- let path =
47
- pathElement.getAttribute("path") || getPath();
48
- if (path) {
49
- // Remove trailing slash if present
50
- if (path.endsWith("/")) {
51
- path = path.slice(0, -1);
52
- }
53
- text = text.replaceAll("$relativePath", path);
54
- }
47
+ path =
48
+ pathElement.getAttribute("path") ||
49
+ getRelativePath();
50
+ } else {
51
+ path = getRelativePath();
55
52
  }
56
-
53
+ // Replace $relativePath in the fetched text
54
+ if (path) {
55
+ text = text.replaceAll(/\$relativePath\/?/g, path);
56
+ }
57
+ // Replace ObjectId() with a new ObjectId
57
58
  text = text.replaceAll("ObjectId()", () => {
58
59
  // Generate a NEW ObjectId inside the function
59
60
  return ObjectId().toString(); // Return its string representation
@@ -67,13 +68,6 @@ async function initElements(elements) {
67
68
  }
68
69
  }
69
70
 
70
- function getPath() {
71
- let currentPath = window.location.pathname.replace(/\/[^\/]*$/, ""); // Remove file from path
72
- let depth = currentPath.split("/").filter(Boolean).length; // Count depth levels
73
-
74
- return depth > 0 ? "../".repeat(depth) : "./"; // Return the correct relative path
75
- }
76
-
77
71
  async function initMediaSource(element, src) {
78
72
  try {
79
73
  let mediaConfig = await response.json();
package/src/index.js CHANGED
@@ -400,6 +400,10 @@ async function setData(element, data) {
400
400
  if (action && ["database", "array", "object", "key"].includes(action))
401
401
  continue;
402
402
 
403
+ if (data.array.includes("aiConversations")) {
404
+ console.log("testing ai conversations");
405
+ }
406
+
403
407
  const { key, isRead, isUpdate, isListen, isCrdt } = getAttributes(el);
404
408
  let elementType = el.getAttribute("type");
405
409
  if (elementType !== "file" && (el.getFilter || el.renderValue))
@@ -424,6 +428,14 @@ async function setData(element, data) {
424
428
  if ($update) {
425
429
  delete data[type][0].$update;
426
430
  data[type][0] = { ...data[type][0], ...$update };
431
+ } else if (key === "$data") {
432
+ value = data;
433
+ } else if (key && key.startsWith("$data")) {
434
+ value = CRUD.getValueFromObject(data, key.slice(1));
435
+ } else if (key === `$${type}`) {
436
+ value = data[type];
437
+ } else if (key && key.startsWith(`$${type}`)) {
438
+ value = CRUD.getValueFromObject(data, key.slice(1));
427
439
  } else if (key === "{}") {
428
440
  value = data[type][0];
429
441
  if (reference === "false") {
@@ -548,8 +560,21 @@ async function filterData(element, data, type, key) {
548
560
  key.replace(/\.\$length$/, "")
549
561
  );
550
562
  element.setValue(value.length);
563
+ } else if (key === "$data") {
564
+ value = data;
565
+ } else if (key && key.startsWith("$data")) {
566
+ value = CRUD.getValueFromObject(data, key.slice(1));
567
+ } else if (key === `$${type}`) {
568
+ value = data[type];
569
+ } else if (key && key.startsWith(`$${type}`)) {
570
+ value = CRUD.getValueFromObject(data, key.slice(1));
551
571
  } else if (key === "{}") {
552
- element.setValue(data[type]);
572
+ value = data[type][0];
573
+ // if (reference === "false") {
574
+ // delete data[type][0].$storage;
575
+ // delete data[type][0].$database;
576
+ // delete data[type][0].$array;
577
+ // }
553
578
  } else if (data) element.setValue(data);
554
579
 
555
580
  if (data.$filter) {