@cocreate/elements 1.42.3 → 1.42.4
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 +8 -0
- package/package.json +1 -1
- package/src/fetchSrc.js +12 -10
- package/src/index.js +26 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## [1.42.4](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.3...v1.42.4) (2025-09-07)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* enhance path handling in initElements and improve data assignment logic in setData ([5c710c5](https://github.com/CoCreate-app/CoCreate-elements/commit/5c710c594d584598ced06a9bcf7954ec30d048d2))
|
|
7
|
+
* 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))
|
|
8
|
+
|
|
1
9
|
## [1.42.3](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.2...v1.42.3) (2025-09-01)
|
|
2
10
|
|
|
3
11
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cocreate/elements",
|
|
3
|
-
"version": "1.42.
|
|
3
|
+
"version": "1.42.4",
|
|
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
|
@@ -41,19 +41,18 @@ 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
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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 = pathElement.getAttribute("path") || getPath();
|
|
48
|
+
} else {
|
|
49
|
+
path = getPath();
|
|
55
50
|
}
|
|
56
|
-
|
|
51
|
+
// Replace $relativePath in the fetched text
|
|
52
|
+
if (path) {
|
|
53
|
+
text = text.replaceAll(/\$relativePath\/?/g, path);
|
|
54
|
+
}
|
|
55
|
+
// Replace ObjectId() with a new ObjectId
|
|
57
56
|
text = text.replaceAll("ObjectId()", () => {
|
|
58
57
|
// Generate a NEW ObjectId inside the function
|
|
59
58
|
return ObjectId().toString(); // Return its string representation
|
|
@@ -69,6 +68,9 @@ async function initElements(elements) {
|
|
|
69
68
|
|
|
70
69
|
function getPath() {
|
|
71
70
|
let currentPath = window.location.pathname.replace(/\/[^\/]*$/, ""); // Remove file from path
|
|
71
|
+
if (!currentPath.endsWith("/")) {
|
|
72
|
+
currentPath += "/";
|
|
73
|
+
}
|
|
72
74
|
let depth = currentPath.split("/").filter(Boolean).length; // Count depth levels
|
|
73
75
|
|
|
74
76
|
return depth > 0 ? "../".repeat(depth) : "./"; // Return the correct relative path
|
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.startsWith("$data")) {
|
|
434
|
+
value = CRUD.getValueFromObject(data, key.slice(1));
|
|
435
|
+
} else if (key === `$${type}`) {
|
|
436
|
+
value = data[type];
|
|
437
|
+
} else if (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.startsWith("$data")) {
|
|
566
|
+
value = CRUD.getValueFromObject(data, key.slice(1));
|
|
567
|
+
} else if (key === `$${type}`) {
|
|
568
|
+
value = data[type];
|
|
569
|
+
} else if (key.startsWith(`$${type}`)) {
|
|
570
|
+
value = CRUD.getValueFromObject(data, key.slice(1));
|
|
551
571
|
} else if (key === "{}") {
|
|
552
|
-
|
|
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) {
|