@chaibuilder/sdk 3.0.18 → 3.0.20
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/README.md +1 -1
- package/dist/apply-binding-BIYK6lOq.cjs +1 -0
- package/dist/{apply-binding-B0CX8mDS.js → apply-binding-YbVf4970.js} +214 -170
- package/dist/{code-editor-e5WfREx8.js → code-editor-D2wFgjMt.js} +11 -11
- package/dist/code-editor-DJwScFxt.cjs +1 -0
- package/dist/core.cjs +1 -126
- package/dist/core.js +97 -10670
- package/dist/css-import-modal-BQLoUINw.cjs +13 -0
- package/dist/{css-import-modal-CSVrt6lz.js → css-import-modal-DaH4zyxk.js} +1 -1
- package/dist/index-DVZxqBpz.js +10686 -0
- package/dist/index-JBLy9hg-.cjs +128 -0
- package/dist/render.cjs +1 -1
- package/dist/render.js +2 -2
- package/dist/rte-widget-modal-CnY4bSfN.cjs +1 -0
- package/dist/rte-widget-modal-gfRmNGNM.js +41 -0
- package/dist/sdk.css +1 -1
- package/dist/{toggle-C5YXnEL9.js → tooltip-Bz2MxMHf.js} +405 -405
- package/dist/tooltip-CzZ7Fvt7.cjs +1 -0
- package/dist/ui.cjs +1 -1
- package/dist/ui.js +1 -1
- package/dist/web-blocks.cjs +1 -1
- package/dist/web-blocks.js +25 -27
- package/package.json +2 -1
- package/dist/apply-binding-DSgP62np.cjs +0 -1
- package/dist/code-editor-D5uDqrW1.cjs +0 -1
- package/dist/css-import-modal-Cm49bHmT.cjs +0 -13
- package/dist/toggle-Ca6BayTf.cjs +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { getRegisteredChaiBlock as Q } from "@chaibuilder/runtime";
|
|
2
|
-
import { memoize as Y, get as
|
|
3
|
-
import { twMerge as
|
|
4
|
-
import { g as pt, c as
|
|
5
|
-
import { parse as
|
|
6
|
-
const
|
|
7
|
-
if (e = e.replace(
|
|
2
|
+
import { memoize as Y, get as d, cloneDeep as R, forEach as D, keys as H, isString as B, startsWith as T, isArray as I, isEmpty as b, includes as k, flatten as tt, flatMapDeep as et, set as w, has as L, filter as V, find as y, some as at, compact as st, map as nt, trim as rt, capitalize as ot, last as lt } from "lodash-es";
|
|
3
|
+
import { twMerge as ct } from "tailwind-merge";
|
|
4
|
+
import { g as pt, c as S } from "./common-functions-BGzDsf1z.js";
|
|
5
|
+
import { parse as ut, stringify as C } from "himalaya";
|
|
6
|
+
const x = "#styles:", It = "__ADD_BLOCK_INTERNAL_ROOT", Dt = "@", dt = "#", K = (e) => {
|
|
7
|
+
if (e = e.replace(x, ""), !e) return { baseClasses: "", classes: "" };
|
|
8
8
|
const n = e.split(/,(?![^\[]*\])/);
|
|
9
9
|
if (n.length === 1)
|
|
10
10
|
return { baseClasses: "", classes: n[0].trim() };
|
|
@@ -41,36 +41,36 @@ import.meta.vitest && describe("getSplitChaiClasses", () => {
|
|
|
41
41
|
}
|
|
42
42
|
};
|
|
43
43
|
for (let n in e) {
|
|
44
|
-
const t = K(`${
|
|
44
|
+
const t = K(`${x}${n}`);
|
|
45
45
|
expect(t).toEqual(e[n]);
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
|
-
function
|
|
50
|
-
const a =
|
|
51
|
-
if (
|
|
52
|
-
const s =
|
|
53
|
-
return
|
|
54
|
-
if (
|
|
55
|
-
const
|
|
56
|
-
|
|
49
|
+
function Ct(e, n, t) {
|
|
50
|
+
const a = d(t, "i18nProps", []);
|
|
51
|
+
if (b(n) || b(a)) return e;
|
|
52
|
+
const s = R(e);
|
|
53
|
+
return D(H(s), (o) => {
|
|
54
|
+
if (k(a, o) && !b(n)) {
|
|
55
|
+
const i = d(s, o), r = d(s, `${o}-${n}`, "");
|
|
56
|
+
B(i) ? s[o] = B(r) && !b(r.trim()) && r.trimStart() || i : s[o] = b(r) ? i : r;
|
|
57
57
|
}
|
|
58
58
|
}), s;
|
|
59
59
|
}
|
|
60
60
|
const ht = Y((e) => {
|
|
61
61
|
const { baseClasses: n, classes: t } = K(e);
|
|
62
|
-
return
|
|
62
|
+
return ct(n, t);
|
|
63
63
|
});
|
|
64
|
-
function
|
|
65
|
-
return
|
|
64
|
+
function gt(e, n) {
|
|
65
|
+
return d(e, `${n}_attrs`, {});
|
|
66
66
|
}
|
|
67
|
-
function
|
|
67
|
+
function Nt(e, n = !0) {
|
|
68
68
|
const t = {};
|
|
69
69
|
return Object.keys(e).forEach((a) => {
|
|
70
|
-
if (
|
|
71
|
-
const s = ht(e[a]), o =
|
|
70
|
+
if (B(e[a]) && e[a].startsWith(x)) {
|
|
71
|
+
const s = ht(e[a]), o = gt(e, a);
|
|
72
72
|
t[a] = {
|
|
73
|
-
...!
|
|
73
|
+
...!b(s) && { className: s },
|
|
74
74
|
...o,
|
|
75
75
|
...n ? {
|
|
76
76
|
"data-style-prop": a,
|
|
@@ -82,33 +82,33 @@ function Dt(e, n = !0) {
|
|
|
82
82
|
}), t;
|
|
83
83
|
}
|
|
84
84
|
const Lt = Y((e) => {
|
|
85
|
-
const n = Q(e), t =
|
|
86
|
-
return Object.fromEntries(Object.entries(t).filter(([, a]) =>
|
|
85
|
+
const n = Q(e), t = d(n, "schema.properties", {});
|
|
86
|
+
return Object.fromEntries(Object.entries(t).filter(([, a]) => d(a, "runtime", !1)));
|
|
87
87
|
}), St = (e, n) => {
|
|
88
|
-
if (!
|
|
88
|
+
if (!I(e)) return e;
|
|
89
89
|
let t = e, a;
|
|
90
90
|
return typeof n.limit == "number" && n.limit > 0 && (a = n.limit), a !== void 0 && (t = t.slice(0, a)), t;
|
|
91
91
|
}, At = (e, n) => {
|
|
92
|
-
const t =
|
|
93
|
-
return
|
|
94
|
-
if (
|
|
92
|
+
const t = R(e);
|
|
93
|
+
return D(H(t), (a) => {
|
|
94
|
+
if (B(t[a]) && !T(a, "_")) {
|
|
95
95
|
let s = t[a];
|
|
96
96
|
a === "repeaterItems" && (t.repeaterItemsBinding = s);
|
|
97
|
-
const o = /\{\{(.*?)\}\}/g,
|
|
98
|
-
|
|
99
|
-
let
|
|
100
|
-
const
|
|
101
|
-
s =
|
|
97
|
+
const o = /\{\{(.*?)\}\}/g, i = s.match(o);
|
|
98
|
+
i && i.forEach((r) => {
|
|
99
|
+
let m = r.slice(2, -2);
|
|
100
|
+
const p = d(n, m, r);
|
|
101
|
+
s = I(p) ? p : s.replace(r, p);
|
|
102
102
|
}), t[a] = s;
|
|
103
103
|
}
|
|
104
104
|
}), t;
|
|
105
105
|
}, mt = (e) => {
|
|
106
106
|
const n = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, t = /(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;
|
|
107
107
|
return n.test(e) || t.test(e);
|
|
108
|
-
},
|
|
109
|
-
if (
|
|
110
|
-
const n = /<video[^>]+src=['"]([^'">]+)['"]/, t = /<iframe[^>]+src=['"]([^'">]+)['"]/, a = e.match(n), s = e.match(t), o = a ? a[1] : s ? s[1] : null,
|
|
111
|
-
return o && (
|
|
108
|
+
}, yt = (e) => {
|
|
109
|
+
if (b(e)) return e;
|
|
110
|
+
const n = /<video[^>]+src=['"]([^'">]+)['"]/, t = /<iframe[^>]+src=['"]([^'">]+)['"]/, a = e.match(n), s = e.match(t), o = a ? a[1] : s ? s[1] : null, i = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, r = /(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;
|
|
111
|
+
return o && (i.test(o) || r.test(o)) ? o : e;
|
|
112
112
|
}, X = ["chai-name", "data-chai-name"], bt = {
|
|
113
113
|
img: { alt: "alt", width: "width", height: "height", src: "image" },
|
|
114
114
|
video: {
|
|
@@ -145,56 +145,56 @@ const Lt = Y((e) => {
|
|
|
145
145
|
form: {
|
|
146
146
|
action: "action"
|
|
147
147
|
}
|
|
148
|
-
},
|
|
148
|
+
}, xt = (e, n) => e.children.length === 1 && k(
|
|
149
149
|
["Heading", "Paragraph", "Span", "ListItem", "Button", "Label", "TableCell", "Link", "RichText"],
|
|
150
150
|
n._type
|
|
151
|
-
),
|
|
152
|
-
const n =
|
|
151
|
+
), A = (e) => e.map((n) => n.type === "text" ? d(n, "content", "") : b(n.children) ? "" : A(n.children)).join(""), W = (e) => e === null ? "" : e, Z = (e) => {
|
|
152
|
+
const n = st(nt(e.split(/\s+/), rt)), t = y(n, (r) => /^w-/.test(r)), a = y(n, (r) => /^h-/.test(r));
|
|
153
153
|
if (!a || !t) return { height: "", width: "" };
|
|
154
154
|
const s = (r) => {
|
|
155
155
|
if (!r) return;
|
|
156
|
-
const
|
|
157
|
-
if (!
|
|
158
|
-
if (
|
|
159
|
-
const
|
|
160
|
-
return /^\d+(\.\d+)?$/.test(
|
|
161
|
-
}, o = s(t),
|
|
156
|
+
const m = r.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);
|
|
157
|
+
if (!m) return;
|
|
158
|
+
if (m[1]) return m[1];
|
|
159
|
+
const p = m[2];
|
|
160
|
+
return /^\d+(\.\d+)?$/.test(p) ? `${Number(p) * 4}px` : p === "auto" || k(p, "%") ? p : "16px";
|
|
161
|
+
}, o = s(t), i = s(a);
|
|
162
162
|
return {
|
|
163
|
-
width:
|
|
164
|
-
height:
|
|
163
|
+
width: k(o, "px") ? o : "16px",
|
|
164
|
+
height: k(i, "px") ? i : "16px"
|
|
165
165
|
};
|
|
166
166
|
}, U = (e) => {
|
|
167
167
|
if (e.tagName === "svg") return {};
|
|
168
168
|
const n = {}, t = bt[e.tagName] || {}, a = e.attributes;
|
|
169
|
-
return
|
|
170
|
-
if (!
|
|
169
|
+
return D(a, ({ key: s, value: o }) => {
|
|
170
|
+
if (!k(X, s))
|
|
171
171
|
if (t[s]) {
|
|
172
172
|
if (e.tagName === "img" && s === "src" && !o.startsWith("http")) {
|
|
173
|
-
const
|
|
174
|
-
|
|
173
|
+
const i = y(e.attributes, { key: "width" }), r = y(e.attributes, { key: "height" });
|
|
174
|
+
i && r ? o = `https://via.placeholder.com/${i == null ? void 0 : i.value}x${r == null ? void 0 : r.value}` : o = "https://via.placeholder.com/150x150";
|
|
175
175
|
}
|
|
176
|
-
|
|
177
|
-
} else
|
|
176
|
+
w(n, t[s], W(o));
|
|
177
|
+
} else k(["style", "class", "srcset"], s) || (L(n, "styles_attrs") || (n.styles_attrs = {}), T(s, "@") && (s = s.replace("@", "x-on:")), n.styles_attrs[`${s}`] = W(o));
|
|
178
178
|
}), delete n.class, n;
|
|
179
|
-
},
|
|
180
|
-
if (!e.attributes) return { [n]: `${
|
|
181
|
-
const t =
|
|
179
|
+
}, ft = (e, n = "styles") => {
|
|
180
|
+
if (!e.attributes) return { [n]: `${x},` };
|
|
181
|
+
const t = y(e.attributes, { key: "class" });
|
|
182
182
|
if (t) {
|
|
183
183
|
const a = t.value;
|
|
184
|
-
return { [n]: `${
|
|
184
|
+
return { [n]: `${x},${a}` };
|
|
185
185
|
}
|
|
186
|
-
return { [n]: `${
|
|
186
|
+
return { [n]: `${x},` };
|
|
187
187
|
}, _t = (e) => {
|
|
188
|
-
const n =
|
|
188
|
+
const n = d(e, "attributes", []), t = n.find((r) => r.key === "data-chai-richtext" || r.key === "chai-richtext"), a = n.find((r) => r.key === "data-chai-lightbox" || r.key === "chai-lightbox"), s = n.find((r) => r.key === "data-chai-dropdown" || r.key === "chai-dropdown"), o = n.find(
|
|
189
189
|
(r) => r.key === "data-chai-dropdown-button" || r.key === "chai-dropdown-button"
|
|
190
|
-
),
|
|
190
|
+
), i = n.find(
|
|
191
191
|
(r) => r.key === "data-chai-dropdown-content" || r.key === "chai-dropdown-content"
|
|
192
192
|
);
|
|
193
193
|
if (s)
|
|
194
194
|
return { _type: "Dropdown" };
|
|
195
195
|
if (o)
|
|
196
196
|
return { _type: "DropdownButton" };
|
|
197
|
-
if (
|
|
197
|
+
if (i)
|
|
198
198
|
return { _type: "DropdownContent" };
|
|
199
199
|
if (t)
|
|
200
200
|
return { _type: "RichText" };
|
|
@@ -278,7 +278,7 @@ const Lt = Y((e) => {
|
|
|
278
278
|
case "tfoot":
|
|
279
279
|
return { _type: "TableFooter" };
|
|
280
280
|
default: {
|
|
281
|
-
const r =
|
|
281
|
+
const r = d(e, "children", []).length > 0 ? "Box" : "EmptyBox";
|
|
282
282
|
return {
|
|
283
283
|
_type: r,
|
|
284
284
|
tag: e.tagName,
|
|
@@ -287,35 +287,35 @@ const Lt = Y((e) => {
|
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
}, G = (e, n = null) => et(e, (t) => {
|
|
290
|
-
var
|
|
290
|
+
var E, f, j, q, M, P, J, O, z, F;
|
|
291
291
|
if (t.type === "comment") return [];
|
|
292
292
|
let a = { _id: pt() };
|
|
293
293
|
if (n && (a._parent = n.block._id), t.type === "text")
|
|
294
|
-
return
|
|
295
|
-
const s =
|
|
296
|
-
(
|
|
297
|
-
),
|
|
298
|
-
(
|
|
294
|
+
return b(d(t, "content", "")) ? [] : n && xt(n.node, n.block) ? (w(n, "block.content", d(t, "content", "")), []) : { ...a, _type: "Text", content: d(t, "content", "") };
|
|
295
|
+
const s = d(t, "attributes", []), o = s.find(
|
|
296
|
+
(l) => l.key === "data-chai-richtext" || l.key === "chai-richtext"
|
|
297
|
+
), i = s.find(
|
|
298
|
+
(l) => l.key === "data-chai-lightbox" || l.key === "chai-lightbox"
|
|
299
299
|
), r = s.find(
|
|
300
|
-
(
|
|
300
|
+
(l) => l.key === "data-chai-dropdown" || l.key === "chai-dropdown"
|
|
301
|
+
), m = s.find(
|
|
302
|
+
(l) => l.key === "data-chai-dropdown-button" || l.key === "chai-dropdown-button"
|
|
301
303
|
), p = s.find(
|
|
302
|
-
(
|
|
303
|
-
), h = s.find(
|
|
304
|
-
(i) => i.key === "data-chai-dropdown-content" || i.key === "chai-dropdown-content"
|
|
304
|
+
(l) => l.key === "data-chai-dropdown-content" || l.key === "chai-dropdown-content"
|
|
305
305
|
);
|
|
306
306
|
if (a = {
|
|
307
307
|
...a,
|
|
308
308
|
..._t(t),
|
|
309
309
|
...U(t),
|
|
310
|
-
...
|
|
310
|
+
...ft(t)
|
|
311
311
|
}, t.attributes) {
|
|
312
|
-
const
|
|
313
|
-
|
|
312
|
+
const l = t.attributes.find((c) => k(X, c.key));
|
|
313
|
+
l && (a._name = l.value);
|
|
314
314
|
}
|
|
315
315
|
if (o)
|
|
316
|
-
return a.content =
|
|
317
|
-
if (
|
|
318
|
-
const
|
|
316
|
+
return a.content = C(t.children), L(a, "styles_attrs.data-chai-richtext") && delete a.styles_attrs["data-chai-richtext"], L(a, "styles_attrs.chai-richtext") && delete a.styles_attrs["chai-richtext"], [a];
|
|
317
|
+
if (i) {
|
|
318
|
+
const l = [
|
|
319
319
|
"data-chai-lightbox",
|
|
320
320
|
"chai-lightbox",
|
|
321
321
|
"data-vbtype",
|
|
@@ -327,87 +327,87 @@ const Lt = Y((e) => {
|
|
|
327
327
|
];
|
|
328
328
|
a = {
|
|
329
329
|
...a,
|
|
330
|
-
href: ((
|
|
331
|
-
hrefType: ((
|
|
332
|
-
autoplay: ((
|
|
333
|
-
maxWidth: ((
|
|
334
|
-
backdropColor: ((
|
|
335
|
-
galleryName: ((
|
|
336
|
-
},
|
|
337
|
-
|
|
330
|
+
href: ((E = s.find((c) => c.key === "href")) == null ? void 0 : E.value) || "",
|
|
331
|
+
hrefType: ((f = s.find((c) => c.key === "data-vbtype")) == null ? void 0 : f.value) || "video",
|
|
332
|
+
autoplay: ((j = s.find((c) => c.key === "data-autoplay")) == null ? void 0 : j.value) === "true" ? "true" : "false",
|
|
333
|
+
maxWidth: ((M = (q = s.find((c) => c.key === "data-maxwidth")) == null ? void 0 : q.value) == null ? void 0 : M.replace("px", "")) || "",
|
|
334
|
+
backdropColor: ((P = s.find((c) => c.key === "data-overlay")) == null ? void 0 : P.value) || "",
|
|
335
|
+
galleryName: ((J = s.find((c) => c.key === "data-gall")) == null ? void 0 : J.value) || ""
|
|
336
|
+
}, D(l, (c) => {
|
|
337
|
+
L(a, `styles_attrs.${c}`) && delete a.styles_attrs[c];
|
|
338
338
|
});
|
|
339
339
|
}
|
|
340
|
-
if (r && (delete a.styles_attrs, a.showDropdown = !1),
|
|
340
|
+
if (r && (delete a.styles_attrs, a.showDropdown = !1), p && delete a.styles_attrs, m) {
|
|
341
341
|
delete a.styles_attrs;
|
|
342
|
-
const
|
|
343
|
-
a.content =
|
|
344
|
-
const
|
|
342
|
+
const l = V(t.children || [], (u) => (u == null ? void 0 : u.tagName) !== "span");
|
|
343
|
+
a.content = A(l);
|
|
344
|
+
const c = y(
|
|
345
345
|
t.children || [],
|
|
346
|
-
(
|
|
346
|
+
(u) => (u == null ? void 0 : u.tagName) === "span" && at(u.children || [], (h) => (h == null ? void 0 : h.tagName) === "svg")
|
|
347
347
|
);
|
|
348
|
-
if (
|
|
349
|
-
const
|
|
350
|
-
if (
|
|
351
|
-
a.icon =
|
|
352
|
-
const { height:
|
|
353
|
-
a.iconHeight =
|
|
348
|
+
if (c) {
|
|
349
|
+
const u = y(c.children || [], (h) => (h == null ? void 0 : h.tagName) === "svg");
|
|
350
|
+
if (u) {
|
|
351
|
+
a.icon = C([u]);
|
|
352
|
+
const { height: h, width: $ } = kt(u, "16px", "16px");
|
|
353
|
+
a.iconHeight = h, a.iconWidth = $;
|
|
354
354
|
}
|
|
355
355
|
}
|
|
356
356
|
return [a];
|
|
357
357
|
}
|
|
358
358
|
if (a._type === "Input") {
|
|
359
|
-
const
|
|
360
|
-
|
|
359
|
+
const l = a.inputType || "text";
|
|
360
|
+
l === "checkbox" ? w(a, "_type", "Checkbox") : l === "radio" && w(a, "_type", "Radio");
|
|
361
361
|
} else if (t.tagName === "video" || t.tagName === "iframe") {
|
|
362
|
-
const
|
|
363
|
-
return mt(
|
|
362
|
+
const l = C([t]);
|
|
363
|
+
return mt(l) && (w(a, "_type", "Video"), w(a, "url", yt(l)), w(a, "styles", `${x},`), w(a, "controls", { autoPlay: !1, muted: !0, loop: !1, controls: !1 })), a.content = l, [a];
|
|
364
364
|
} else if (t.tagName === "svg") {
|
|
365
|
-
const
|
|
366
|
-
if (
|
|
367
|
-
a.styles = `${
|
|
365
|
+
const l = d(y(t.attributes, { key: "class" }), "value", ""), { height: c, width: u } = Z(l);
|
|
366
|
+
if (c && u)
|
|
367
|
+
a.styles = `${x}, ${S(`w-${u} h-${c}`, l)}`.trim(), a.height = c == null ? void 0 : c.replace("px", ""), a.width = u == null ? void 0 : u.replace("px", "");
|
|
368
368
|
else {
|
|
369
|
-
const
|
|
370
|
-
|
|
369
|
+
const h = (O = y(t.attributes, { key: "height" })) == null ? void 0 : O.value, $ = (z = y(t.attributes, { key: "width" })) == null ? void 0 : z.value;
|
|
370
|
+
h && $ ? (a.styles = `${x}, ${S(`w-[${$}px] h-[${h}px]`, l)}`.trim(), a.height = h, a.width = $) : a.styles = `${x}, ${S("w-full h-full", l)}`.trim();
|
|
371
371
|
}
|
|
372
|
-
return t.attributes = V(t.attributes, (
|
|
373
|
-
} else if (t.tagName == "option" && n && ((
|
|
372
|
+
return t.attributes = V(t.attributes, (h) => !k(["style", "width", "height", "class"], h.key)), a.icon = C([t]), [a];
|
|
373
|
+
} else if (t.tagName == "option" && n && ((F = n.block) == null ? void 0 : F._type) === "Select")
|
|
374
374
|
return n.block.options.push({
|
|
375
|
-
label:
|
|
375
|
+
label: A(t.children),
|
|
376
376
|
...U(t)
|
|
377
377
|
}), [];
|
|
378
|
-
const
|
|
379
|
-
return [a, ...
|
|
378
|
+
const v = G(t.children, { block: a, node: t });
|
|
379
|
+
return [a, ...v];
|
|
380
380
|
}), kt = (e, n, t) => {
|
|
381
|
-
var
|
|
382
|
-
const a =
|
|
383
|
-
|
|
381
|
+
var m, p;
|
|
382
|
+
const a = d(e, "attributes", []), { height: s, width: o } = Z(
|
|
383
|
+
d(y(a, { key: "class" }), "value", "")
|
|
384
384
|
);
|
|
385
385
|
if (s && o)
|
|
386
386
|
return {
|
|
387
387
|
height: `[${s}px]`,
|
|
388
388
|
width: `[${o}px]`
|
|
389
389
|
};
|
|
390
|
-
const
|
|
390
|
+
const i = (m = y(a, { key: "height" })) == null ? void 0 : m.value, r = (p = y(a, { key: "width" })) == null ? void 0 : p.value;
|
|
391
391
|
return {
|
|
392
|
-
height:
|
|
392
|
+
height: i ? `[${i}px]` : t,
|
|
393
393
|
width: r ? `[${r}px]` : n
|
|
394
394
|
};
|
|
395
395
|
}, vt = (e) => {
|
|
396
396
|
e = e.replace(/(\w+)=\\?"(.*?)\\?"/g, (a, s, o) => {
|
|
397
|
-
let
|
|
398
|
-
return
|
|
397
|
+
let i = o.replace(/\\"/g, '"');
|
|
398
|
+
return i = i.replace(/{([^}]+)}/g, (r) => r.replace(/"/g, '\\"')), `${s}="${i.replace(/\\"/g, '"')}"`;
|
|
399
399
|
}), e = e.replace(/\\n/g, "").replace(/\\\\/g, "").replace(/\\([/<>])/g, "$1").replace(/\\./g, "").replace(/[\n\r\t\f\v]/g, ""), e = e.replace(/\$name="[^"]*"/g, "");
|
|
400
400
|
const n = e.match(/<body[^>]*>[\s\S]*?<\/body>/);
|
|
401
401
|
return (n && n.length > 0 ? n[0].replace(/<body/, "<div").replace(/<\/body>/, "</div>") : e).replace(/\s+/g, " ").replaceAll("> <", "><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").trim();
|
|
402
402
|
}, Rt = (e) => {
|
|
403
|
-
const n =
|
|
404
|
-
return
|
|
405
|
-
},
|
|
406
|
-
const n =
|
|
403
|
+
const n = ut(vt(e));
|
|
404
|
+
return b(e) ? [] : tt(G(n));
|
|
405
|
+
}, _ = (e) => {
|
|
406
|
+
const n = lt(e);
|
|
407
407
|
return e.map((t) => {
|
|
408
408
|
const a = Object.keys(t);
|
|
409
409
|
for (let s = 0; s < a.length; s++)
|
|
410
|
-
if (
|
|
410
|
+
if (B(t[a[s]]) && T(a[s], "content")) {
|
|
411
411
|
const o = t === n ? "" : " ";
|
|
412
412
|
t[a[s]] = `${t[a[s]].trim()}${o}`;
|
|
413
413
|
}
|
|
@@ -418,50 +418,50 @@ if (import.meta.vitest) {
|
|
|
418
418
|
const { describe: e, it: n, expect: t } = import.meta.vitest;
|
|
419
419
|
e("adjustSpacingInContentBlocks", () => {
|
|
420
420
|
n("should add space after content fields except for the last block", () => {
|
|
421
|
-
const s =
|
|
421
|
+
const s = _([
|
|
422
422
|
{ _id: "1", _type: "Text", content: "First" },
|
|
423
423
|
{ _id: "2", _type: "Text", content: "Second" },
|
|
424
424
|
{ _id: "3", _type: "Text", content: "Third" }
|
|
425
425
|
]);
|
|
426
426
|
t(s[0].content).toBe("First "), t(s[1].content).toBe("Second "), t(s[2].content).toBe("Third");
|
|
427
427
|
}), n("should trim whitespace from content before adding space", () => {
|
|
428
|
-
const s =
|
|
428
|
+
const s = _([
|
|
429
429
|
{ _id: "1", _type: "Text", content: " First " },
|
|
430
430
|
{ _id: "2", _type: "Text", content: " Second " }
|
|
431
431
|
]);
|
|
432
432
|
t(s[0].content).toBe("First "), t(s[1].content).toBe("Second");
|
|
433
433
|
}), n("should handle multiple content fields in a single block", () => {
|
|
434
|
-
const s =
|
|
434
|
+
const s = _([
|
|
435
435
|
{ _id: "1", _type: "Text", content: "Main", contentAlt: "Alt" },
|
|
436
436
|
{ _id: "2", _type: "Text", content: "Last", contentSecondary: "Secondary" }
|
|
437
437
|
]);
|
|
438
438
|
t(s[0].content).toBe("Main "), t(s[0].contentAlt).toBe("Alt "), t(s[1].content).toBe("Last"), t(s[1].contentSecondary).toBe("Secondary");
|
|
439
439
|
}), n("should only process fields that start with 'content'", () => {
|
|
440
|
-
const s =
|
|
440
|
+
const s = _([
|
|
441
441
|
{ _id: "1", _type: "Text", content: "Text", title: "Title", text: "Text" },
|
|
442
442
|
{ _id: "2", _type: "Text", content: "Last" }
|
|
443
443
|
]);
|
|
444
444
|
t(s[0].content).toBe("Text "), t(s[0].title).toBe("Title"), t(s[0].text).toBe("Text"), t(s[1].content).toBe("Last");
|
|
445
445
|
}), n("should handle empty array", () => {
|
|
446
|
-
const s =
|
|
446
|
+
const s = _([]);
|
|
447
447
|
t(s).toEqual([]);
|
|
448
448
|
}), n("should handle single block", () => {
|
|
449
|
-
const s =
|
|
449
|
+
const s = _([{ _id: "1", _type: "Text", content: "Only" }]);
|
|
450
450
|
t(s[0].content).toBe("Only");
|
|
451
451
|
}), n("should handle blocks without content fields", () => {
|
|
452
|
-
const s =
|
|
452
|
+
const s = _([
|
|
453
453
|
{ _id: "1", _type: "Container", title: "Title" },
|
|
454
454
|
{ _id: "2", _type: "Container", name: "Name" }
|
|
455
455
|
]);
|
|
456
456
|
t(s[0].title).toBe("Title"), t(s[1].name).toBe("Name");
|
|
457
457
|
}), n("should handle blocks with non-string content fields", () => {
|
|
458
|
-
const s =
|
|
458
|
+
const s = _([
|
|
459
459
|
{ _id: "1", _type: "Text", content: "Text", contentNum: 123 },
|
|
460
460
|
{ _id: "2", _type: "Text", content: "Last", contentBool: !0 }
|
|
461
461
|
]);
|
|
462
462
|
t(s[0].content).toBe("Text "), t(s[0].contentNum).toBe(123), t(s[1].content).toBe("Last"), t(s[1].contentBool).toBe(!0);
|
|
463
463
|
}), n("should handle empty string content", () => {
|
|
464
|
-
const s =
|
|
464
|
+
const s = _([
|
|
465
465
|
{ _id: "1", _type: "Text", content: "" },
|
|
466
466
|
{ _id: "2", _type: "Text", content: "Last" }
|
|
467
467
|
]);
|
|
@@ -469,36 +469,40 @@ if (import.meta.vitest) {
|
|
|
469
469
|
});
|
|
470
470
|
});
|
|
471
471
|
}
|
|
472
|
-
const
|
|
473
|
-
if (
|
|
474
|
-
let
|
|
475
|
-
const
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
472
|
+
const g = (e, n, { index: t, key: a }, s) => {
|
|
473
|
+
if (B(e)) {
|
|
474
|
+
let o = e;
|
|
475
|
+
const i = /\{\{(.*?)\}\}/g, r = e.match(i);
|
|
476
|
+
if (r) {
|
|
477
|
+
const m = s === "image" || s === "mobileImage";
|
|
478
|
+
r.forEach((p) => {
|
|
479
|
+
let v = p.slice(2, -2).trim(), E = a.slice(2, -2).trim();
|
|
480
|
+
t !== -1 && T(v, "$index.") ? v = `${E}.${t}.${v.slice(7)}` : t !== -1 && T(v, "$index") && (v = `${E}.${t}`);
|
|
481
|
+
const f = d(n, v);
|
|
482
|
+
f === void 0 ? o = o.replace(p, "") : m && !I(f) ? o = f : o = I(f) ? f : o.replace(p, f);
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
return o;
|
|
482
486
|
}
|
|
483
|
-
if (
|
|
484
|
-
return e.map((
|
|
487
|
+
if (I(e))
|
|
488
|
+
return e.map((o) => g(o, n, { index: t, key: a }, s));
|
|
485
489
|
if (e && typeof e == "object") {
|
|
486
|
-
const
|
|
487
|
-
return
|
|
488
|
-
!
|
|
489
|
-
}),
|
|
490
|
+
const o = {};
|
|
491
|
+
return D(H(e), (i) => {
|
|
492
|
+
!T(i, "_") && i !== "$repeaterItemsKey" ? o[i] = g(e[i], n, { index: t, key: a }, i) : o[i] = e[i];
|
|
493
|
+
}), o;
|
|
490
494
|
}
|
|
491
495
|
return e;
|
|
492
|
-
},
|
|
493
|
-
let s =
|
|
494
|
-
return s.repeaterItems && (s.$repeaterItemsKey = s.repeaterItems,
|
|
496
|
+
}, N = (e, n, { index: t, key: a }) => {
|
|
497
|
+
let s = R(e);
|
|
498
|
+
return s.repeaterItems && (s.$repeaterItemsKey = s.repeaterItems, T(s.repeaterItems, `{{${dt}`) && (s.$repeaterItemsKey = s.repeaterItems = `${s.repeaterItems.replace("}}", `/${s._id}}}`)}`), !b(s.repeaterItems) && s.pagination && (s.repeaterTotalItems = `${s.repeaterItems.replace("}}", `/${s._id}/totalItems}}`)}`)), g(s, n, { index: t, key: a });
|
|
495
499
|
};
|
|
496
500
|
import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
497
501
|
it("should handle string values with bindings", () => {
|
|
498
|
-
const t =
|
|
502
|
+
const t = g("Hello {{user.name}}", { user: { name: "John" } }, { index: -1, key: "" });
|
|
499
503
|
expect(t).toBe("Hello John");
|
|
500
504
|
}), it("should handle nested object properties", () => {
|
|
501
|
-
const t =
|
|
505
|
+
const t = g({
|
|
502
506
|
name: "John",
|
|
503
507
|
address: {
|
|
504
508
|
city: "{{user.city}}",
|
|
@@ -513,19 +517,19 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
|
513
517
|
}
|
|
514
518
|
});
|
|
515
519
|
}), it("should handle arrays of values", () => {
|
|
516
|
-
const t =
|
|
520
|
+
const t = g(["Hello {{user.name}}", "Welcome {{user.role}}"], { user: { name: "John", role: "Admin" } }, { index: -1, key: "" });
|
|
517
521
|
expect(t).toEqual(["Hello John", "Welcome Admin"]);
|
|
518
522
|
}), it("should handle $index binding in repeater context", () => {
|
|
519
|
-
const t =
|
|
523
|
+
const t = g("Item {{$index}}", { items: ["a", "b", "c"] }, { index: 1, key: "{{items}}" });
|
|
520
524
|
expect(t).toBe("Item b");
|
|
521
525
|
}), it("should handle $index binding with dot notation", () => {
|
|
522
|
-
const t =
|
|
526
|
+
const t = g("Item {{$index.value}}", { items: [{ value: "apple" }, { value: "banana" }, { value: "cherry" }] }, { index: 1, key: "{{items}}" });
|
|
523
527
|
expect(t).toBe("Item banana");
|
|
524
528
|
}), it("should return an empty string for non-existing bindings", () => {
|
|
525
|
-
const t =
|
|
529
|
+
const t = g("Hello {{user.nonexistent}}", { user: { name: "John" } }, { index: -1, key: "" });
|
|
526
530
|
expect(t).toBe("Hello ");
|
|
527
531
|
}), it("should preserve private properties starting with _", () => {
|
|
528
|
-
const n =
|
|
532
|
+
const n = g({
|
|
529
533
|
name: "John",
|
|
530
534
|
_private: "secret"
|
|
531
535
|
}, {}, { index: -1, key: "" });
|
|
@@ -533,10 +537,50 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
|
533
537
|
name: "John",
|
|
534
538
|
_private: "secret"
|
|
535
539
|
});
|
|
540
|
+
}), it("should completely replace image property value when binding exists", () => {
|
|
541
|
+
const t = g({
|
|
542
|
+
image: "https://default.jpg{{user.avatar}}",
|
|
543
|
+
title: "Hello {{user.name}}"
|
|
544
|
+
}, { user: { avatar: "https://avatar.jpg", name: "John" } }, { index: -1, key: "" });
|
|
545
|
+
expect(t).toEqual({
|
|
546
|
+
image: "https://avatar.jpg",
|
|
547
|
+
// Completely replaced, not concatenated
|
|
548
|
+
title: "Hello John"
|
|
549
|
+
// Normal replacement
|
|
550
|
+
});
|
|
551
|
+
}), it("should completely replace mobileImage property value when binding exists", () => {
|
|
552
|
+
const t = g({
|
|
553
|
+
mobileImage: "https://default-mobile.jpg{{user.mobileAvatar}}",
|
|
554
|
+
alt: "Avatar for {{user.name}}"
|
|
555
|
+
}, { user: { mobileAvatar: "https://mobile-avatar.jpg", name: "John" } }, { index: -1, key: "" });
|
|
556
|
+
expect(t).toEqual({
|
|
557
|
+
mobileImage: "https://mobile-avatar.jpg",
|
|
558
|
+
// Completely replaced
|
|
559
|
+
alt: "Avatar for John"
|
|
560
|
+
// Normal replacement
|
|
561
|
+
});
|
|
562
|
+
}), it("should handle image binding with only binding syntax", () => {
|
|
563
|
+
const t = g({
|
|
564
|
+
image: "{{product.thumbnail}}"
|
|
565
|
+
}, { product: { thumbnail: "https://product.jpg" } }, { index: -1, key: "" });
|
|
566
|
+
expect(t).toEqual({
|
|
567
|
+
image: "https://product.jpg"
|
|
568
|
+
});
|
|
569
|
+
}), it("should not affect non-image properties with similar bindings", () => {
|
|
570
|
+
const t = g({
|
|
571
|
+
url: "https://default.com{{page.slug}}",
|
|
572
|
+
link: "https://example.com/{{page.id}}"
|
|
573
|
+
}, { page: { slug: "/about", id: "123" } }, { index: -1, key: "" });
|
|
574
|
+
expect(t).toEqual({
|
|
575
|
+
url: "https://default.com/about",
|
|
576
|
+
// Concatenated normally
|
|
577
|
+
link: "https://example.com/123"
|
|
578
|
+
// Concatenated normally
|
|
579
|
+
});
|
|
536
580
|
});
|
|
537
581
|
}), describe("applyBindingToBlockProps", () => {
|
|
538
582
|
it("should handle basic block with bindings", () => {
|
|
539
|
-
const t =
|
|
583
|
+
const t = N({
|
|
540
584
|
_id: "test-block",
|
|
541
585
|
_type: "text",
|
|
542
586
|
type: "text",
|
|
@@ -555,7 +599,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
|
555
599
|
}
|
|
556
600
|
});
|
|
557
601
|
}), it("should handle repeaterItems and repeaterItemsBinding", () => {
|
|
558
|
-
const t =
|
|
602
|
+
const t = N({
|
|
559
603
|
_id: "test-block",
|
|
560
604
|
_type: "repeater",
|
|
561
605
|
type: "repeater",
|
|
@@ -571,7 +615,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
|
571
615
|
items: ["a", "b", "c"]
|
|
572
616
|
});
|
|
573
617
|
}), it("should handle nested blocks with bindings", () => {
|
|
574
|
-
const t =
|
|
618
|
+
const t = N({
|
|
575
619
|
_id: "test-block",
|
|
576
620
|
_type: "container",
|
|
577
621
|
type: "container",
|
|
@@ -604,7 +648,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
|
604
648
|
]
|
|
605
649
|
});
|
|
606
650
|
}), it("should handle arrays of blocks", () => {
|
|
607
|
-
const t =
|
|
651
|
+
const t = N({
|
|
608
652
|
_id: "test-block",
|
|
609
653
|
_type: "list",
|
|
610
654
|
type: "list",
|
|
@@ -625,16 +669,16 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
|
625
669
|
});
|
|
626
670
|
}));
|
|
627
671
|
export {
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
672
|
+
dt as C,
|
|
673
|
+
Dt as R,
|
|
674
|
+
x as S,
|
|
675
|
+
N as a,
|
|
676
|
+
Ct as b,
|
|
633
677
|
Lt as c,
|
|
634
678
|
St as d,
|
|
635
|
-
|
|
679
|
+
_ as e,
|
|
636
680
|
At as f,
|
|
637
|
-
|
|
681
|
+
Nt as g,
|
|
638
682
|
Rt as h,
|
|
639
683
|
K as i,
|
|
640
684
|
It as j
|