@cocreate/elements 1.42.2 → 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 +16 -0
- package/package.json +1 -9
- package/src/fetchSrc.js +12 -4
- package/src/index.js +51 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
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
|
+
|
|
9
|
+
## [1.42.3](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.2...v1.42.3) (2025-09-01)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Bug Fixes
|
|
13
|
+
|
|
14
|
+
* handle trailing slashes in relative path replacement and improve mutation parent check ([b2f559a](https://github.com/CoCreate-app/CoCreate-elements/commit/b2f559a583e41a88b196f62395ba3f1759fe10f2))
|
|
15
|
+
* improve value checks and handling in getData and save functions ([d8fd81d](https://github.com/CoCreate-app/CoCreate-elements/commit/d8fd81d89ecdf1feb3d7e1074fe8afe21adcfba4))
|
|
16
|
+
|
|
1
17
|
## [1.42.2](https://github.com/CoCreate-app/CoCreate-elements/compare/v1.42.1...v1.42.2) (2025-05-01)
|
|
2
18
|
|
|
3
19
|
|
package/package.json
CHANGED
|
@@ -1,18 +1,10 @@
|
|
|
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",
|
|
7
|
-
"cocreate",
|
|
8
|
-
"low-code-framework",
|
|
9
|
-
"no-code-framework",
|
|
10
|
-
"cocreatejs",
|
|
11
|
-
"cocreatejs-component",
|
|
12
|
-
"cocreate-framework",
|
|
13
|
-
"no-code",
|
|
14
7
|
"low-code",
|
|
15
|
-
"collaborative-framework",
|
|
16
8
|
"realtime",
|
|
17
9
|
"realtime-framework",
|
|
18
10
|
"collaboration",
|
package/src/fetchSrc.js
CHANGED
|
@@ -41,13 +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
|
-
|
|
47
|
+
path = pathElement.getAttribute("path") || getPath();
|
|
48
|
+
} else {
|
|
49
|
+
path = getPath();
|
|
49
50
|
}
|
|
50
|
-
|
|
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
|
|
51
56
|
text = text.replaceAll("ObjectId()", () => {
|
|
52
57
|
// Generate a NEW ObjectId inside the function
|
|
53
58
|
return ObjectId().toString(); // Return its string representation
|
|
@@ -63,6 +68,9 @@ async function initElements(elements) {
|
|
|
63
68
|
|
|
64
69
|
function getPath() {
|
|
65
70
|
let currentPath = window.location.pathname.replace(/\/[^\/]*$/, ""); // Remove file from path
|
|
71
|
+
if (!currentPath.endsWith("/")) {
|
|
72
|
+
currentPath += "/";
|
|
73
|
+
}
|
|
66
74
|
let depth = currentPath.split("/").filter(Boolean).length; // Count depth levels
|
|
67
75
|
|
|
68
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) {
|
|
@@ -856,7 +881,7 @@ async function getData(form) {
|
|
|
856
881
|
}
|
|
857
882
|
|
|
858
883
|
let value = await element.getValue();
|
|
859
|
-
if (
|
|
884
|
+
if (value === undefined) continue;
|
|
860
885
|
|
|
861
886
|
let Data = { ...data };
|
|
862
887
|
let dataKey = elements.get(element);
|
|
@@ -1014,7 +1039,7 @@ async function getData(form) {
|
|
|
1014
1039
|
|
|
1015
1040
|
async function save(element, action) {
|
|
1016
1041
|
if (!element) return;
|
|
1017
|
-
let data, value;
|
|
1042
|
+
let data, value, form;
|
|
1018
1043
|
let upsert = element.getAttribute("upsert");
|
|
1019
1044
|
if (upsert && upsert !== "false") upsert = true;
|
|
1020
1045
|
if (element.tagName === "FORM") {
|
|
@@ -1022,9 +1047,12 @@ async function save(element, action) {
|
|
|
1022
1047
|
} else {
|
|
1023
1048
|
let isSave = element.getAttribute("save");
|
|
1024
1049
|
if (isSave === "false") return;
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1050
|
+
if (action) {
|
|
1051
|
+
form = element.closest("form");
|
|
1052
|
+
if (form) {
|
|
1053
|
+
return save(form);
|
|
1054
|
+
}
|
|
1055
|
+
}
|
|
1028
1056
|
|
|
1029
1057
|
let dataKey = elements.get(element);
|
|
1030
1058
|
data = { ...keys.get(dataKey).dataKey.object };
|
|
@@ -1064,21 +1092,25 @@ async function save(element, action) {
|
|
|
1064
1092
|
let Data = [];
|
|
1065
1093
|
for (let i = 0; i < data.length; i++) {
|
|
1066
1094
|
if (data[i].type === "object") {
|
|
1067
|
-
if (
|
|
1095
|
+
if (!data[i].object) {
|
|
1096
|
+
data[i].method = "object.create";
|
|
1097
|
+
} else if (typeof data[i].object === "string") {
|
|
1068
1098
|
if (!data[i]._id) data[i].method = "object.create";
|
|
1069
1099
|
else {
|
|
1070
1100
|
data[i].method = "object.update";
|
|
1071
1101
|
if (upsert) data[i].upsert = true;
|
|
1072
1102
|
}
|
|
1073
1103
|
} else if (Array.isArray(data[i].object)) {
|
|
1074
|
-
if (!data[i].object[0]._id)
|
|
1075
|
-
|
|
1104
|
+
if (!data[i].object[0]._id) {
|
|
1105
|
+
data[i].method = "object.create";
|
|
1106
|
+
} else {
|
|
1076
1107
|
data[i].method = "object.update";
|
|
1077
1108
|
if (upsert) data[i].upsert = true;
|
|
1078
1109
|
}
|
|
1079
1110
|
} else if (typeof data[i].object === "object") {
|
|
1080
|
-
if (!data[i].object._id)
|
|
1081
|
-
|
|
1111
|
+
if (!data[i].object._id) {
|
|
1112
|
+
data[i].method = "object.create";
|
|
1113
|
+
} else {
|
|
1082
1114
|
data[i].method = "object.update";
|
|
1083
1115
|
if (upsert) data[i].upsert = true;
|
|
1084
1116
|
}
|
|
@@ -1151,7 +1183,9 @@ function setTypeValue(element, data, action) {
|
|
|
1151
1183
|
|
|
1152
1184
|
if (!form) {
|
|
1153
1185
|
if (data.type === "object") {
|
|
1154
|
-
|
|
1186
|
+
if (data.object && data.object[0] && data.object[0]._id) {
|
|
1187
|
+
element.setAttribute("object", data.object[0]._id);
|
|
1188
|
+
}
|
|
1155
1189
|
} else {
|
|
1156
1190
|
element.setAttribute(data.type, data[data.type].name);
|
|
1157
1191
|
}
|
|
@@ -1310,9 +1344,6 @@ function initSocket() {
|
|
|
1310
1344
|
if (data.rendered) return;
|
|
1311
1345
|
|
|
1312
1346
|
data.rendered = true;
|
|
1313
|
-
if (data && data.key === "answers") {
|
|
1314
|
-
console.log("test");
|
|
1315
|
-
}
|
|
1316
1347
|
|
|
1317
1348
|
setData(null, data);
|
|
1318
1349
|
});
|
|
@@ -1325,7 +1356,11 @@ Observer.init({
|
|
|
1325
1356
|
types: ["addedNodes"],
|
|
1326
1357
|
selector: "[render-clone]",
|
|
1327
1358
|
callback: function (mutation) {
|
|
1328
|
-
if (
|
|
1359
|
+
if (
|
|
1360
|
+
mutation.parentElement &&
|
|
1361
|
+
!mutation.parentElement.hasAttribute("dnd")
|
|
1362
|
+
)
|
|
1363
|
+
return;
|
|
1329
1364
|
let delayTimer = debounce.get(mutation);
|
|
1330
1365
|
clearTimeout(delayTimer);
|
|
1331
1366
|
debounce.delete(mutation.target);
|