@chaibuilder/sdk 3.0.28 → 3.1.0
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/dist/{IconPicker-CluS-5Mv.js → IconPicker-DB-dcym6.js} +1 -1
- package/dist/{IconPicker-BWE43eMO.cjs → IconPicker-OPOFkNZu.cjs} +1 -1
- package/dist/apply-binding-BEdnEDe4.cjs +1 -0
- package/dist/apply-binding-FoDMumPo.js +704 -0
- package/dist/{code-editor-D9Lla5Lr.cjs → code-editor-BF_Dj7wT.cjs} +1 -1
- package/dist/{code-editor-DmN41-qr.js → code-editor-DHjchara.js} +2 -2
- package/dist/core.cjs +1 -1
- package/dist/core.d.ts +15 -2
- package/dist/core.js +82 -78
- package/dist/{css-import-modal-DaH4zyxk.js → css-import-modal-DK2j6oGY.js} +1 -1
- package/dist/{css-import-modal-BQLoUINw.cjs → css-import-modal-P7f5SEKA.cjs} +1 -1
- package/dist/{index-Ct0lOt4c.js → index-0I-fi22L.js} +1010 -1135
- package/dist/index-kJFsIwFo.cjs +128 -0
- package/dist/render.cjs +1 -1
- package/dist/render.js +2 -2
- package/dist/{rte-widget-modal-DzEtNny0.cjs → rte-widget-modal-BZJ8UA08.cjs} +1 -1
- package/dist/{rte-widget-modal-jYxk5Q4W.js → rte-widget-modal-DxyV3u6C.js} +2 -2
- package/dist/{tooltip-Bz2MxMHf.js → tooltip-4-b9QGDK.js} +0 -1
- package/dist/{tooltip-CzZ7Fvt7.cjs → tooltip-C2BCZ8Al.cjs} +1 -1
- package/dist/ui.cjs +1 -1
- package/dist/ui.js +1 -1
- package/dist/web-blocks.cjs +1 -1
- package/dist/web-blocks.js +326 -322
- package/package.json +2 -2
- package/dist/apply-binding-BIYK6lOq.cjs +0 -1
- package/dist/apply-binding-YbVf4970.js +0 -685
- package/dist/index-BtVNiUIw.cjs +0 -128
|
@@ -0,0 +1,704 @@
|
|
|
1
|
+
import { g as nt, c as S } from "./common-functions-BGzDsf1z.js";
|
|
2
|
+
import { isEmpty as f, flatten as rt, flatMapDeep as ot, get as d, set as E, startsWith as k, find as m, startCase as lt, forEach as B, includes as v, has as A, filter as Z, some as ct, map as Q, compact as pt, trim as ut, capitalize as dt, memoize as tt, cloneDeep as q, keys as M, isString as $, isArray as C, last as ht } from "lodash-es";
|
|
3
|
+
import { parse as gt, stringify as N } from "himalaya";
|
|
4
|
+
import { getRegisteredChaiBlock as mt } from "@chaibuilder/runtime";
|
|
5
|
+
import { twMerge as yt } from "tailwind-merge";
|
|
6
|
+
const x = "#styles:", St = "__ADD_BLOCK_INTERNAL_ROOT", Rt = "@", bt = "#", et = (e) => {
|
|
7
|
+
if (e = e.replace(x, ""), !e) return { baseClasses: "", classes: "" };
|
|
8
|
+
const a = e.split(/,(?![^\[]*\])/);
|
|
9
|
+
if (a.length === 1)
|
|
10
|
+
return { baseClasses: "", classes: a[0].trim() };
|
|
11
|
+
const [t, ...s] = a;
|
|
12
|
+
return {
|
|
13
|
+
baseClasses: t.trim(),
|
|
14
|
+
classes: s.join(",").trim().replace(/ +(?= )/g, "")
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
import.meta.vitest && describe("getSplitChaiClasses", () => {
|
|
18
|
+
it("should return the base classes and the classes", () => {
|
|
19
|
+
const e = {
|
|
20
|
+
",styles-2": { baseClasses: "", classes: "styles-2" },
|
|
21
|
+
"styles-1,styles-2": { baseClasses: "styles-1", classes: "styles-2" },
|
|
22
|
+
",bg-[linear-gradient(-10deg,black,transparent_100%)]": {
|
|
23
|
+
baseClasses: "",
|
|
24
|
+
classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
|
|
25
|
+
},
|
|
26
|
+
"styles-1,bg-[linear-gradient(-10deg,black,transparent_100%)]": {
|
|
27
|
+
baseClasses: "styles-1",
|
|
28
|
+
classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
|
|
29
|
+
},
|
|
30
|
+
someclass: {
|
|
31
|
+
baseClasses: "",
|
|
32
|
+
classes: "someclass"
|
|
33
|
+
},
|
|
34
|
+
",bg-red-500 text-center font-bold": {
|
|
35
|
+
baseClasses: "",
|
|
36
|
+
classes: "bg-red-500 text-center font-bold"
|
|
37
|
+
},
|
|
38
|
+
"bg-[linear-gradient(-10deg,black,transparent_100%)], bg-[linear-gradient(-10deg,black,transparent_100%)]": {
|
|
39
|
+
baseClasses: "bg-[linear-gradient(-10deg,black,transparent_100%)]",
|
|
40
|
+
classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
for (let a in e) {
|
|
44
|
+
const t = et(`${x}${a}`);
|
|
45
|
+
expect(t).toEqual(e[a]);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
const ft = (e) => {
|
|
50
|
+
const a = /(?: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/;
|
|
51
|
+
return a.test(e) || t.test(e);
|
|
52
|
+
}, xt = (e) => {
|
|
53
|
+
if (f(e)) return e;
|
|
54
|
+
const a = /<video[^>]+src=['"]([^'">]+)['"]/, t = /<iframe[^>]+src=['"]([^'">]+)['"]/, s = e.match(a), n = e.match(t), r = s ? s[1] : n ? n[1] : null, o = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, c = /(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;
|
|
55
|
+
return r && (o.test(r) || c.test(r)) ? r : e;
|
|
56
|
+
}, st = ["chai-name", "data-chai-name"], _t = {
|
|
57
|
+
img: { alt: "alt", width: "width", height: "height", src: "image" },
|
|
58
|
+
video: {
|
|
59
|
+
src: "url",
|
|
60
|
+
autoplay: "controls.autoPlay",
|
|
61
|
+
muted: "controls.muted",
|
|
62
|
+
loop: "controls.loop",
|
|
63
|
+
controls: "controls.widgets"
|
|
64
|
+
},
|
|
65
|
+
a: {
|
|
66
|
+
href: "link.href",
|
|
67
|
+
target: "link.target",
|
|
68
|
+
type: ""
|
|
69
|
+
// @TODO: Detect here what to url, email, phone, elementId
|
|
70
|
+
},
|
|
71
|
+
input: {
|
|
72
|
+
placeholder: "placeholder",
|
|
73
|
+
required: "required",
|
|
74
|
+
type: "inputType",
|
|
75
|
+
name: "fieldName"
|
|
76
|
+
},
|
|
77
|
+
textarea: {
|
|
78
|
+
placeholder: "placeholder",
|
|
79
|
+
required: "required",
|
|
80
|
+
type: "inputType",
|
|
81
|
+
name: "fieldName"
|
|
82
|
+
},
|
|
83
|
+
select: {
|
|
84
|
+
placeholder: "placeholder",
|
|
85
|
+
required: "required",
|
|
86
|
+
multiple: "multiple",
|
|
87
|
+
name: "fieldName"
|
|
88
|
+
},
|
|
89
|
+
form: {
|
|
90
|
+
action: "action"
|
|
91
|
+
}
|
|
92
|
+
}, kt = (e, a) => e.children.length === 1 && v(
|
|
93
|
+
["Heading", "Paragraph", "Span", "ListItem", "Button", "Label", "TableCell", "Link", "RichText"],
|
|
94
|
+
a._type
|
|
95
|
+
), R = (e) => e.map((a) => a.type === "text" ? d(a, "content", "") : f(a.children) ? "" : R(a.children)).join(""), H = (e) => e === null ? "" : e, at = (e) => {
|
|
96
|
+
const a = pt(Q(e.split(/\s+/), ut)), t = m(a, (c) => /^w-/.test(c)), s = m(a, (c) => /^h-/.test(c));
|
|
97
|
+
if (!s || !t) return { height: "", width: "" };
|
|
98
|
+
const n = (c) => {
|
|
99
|
+
if (!c) return;
|
|
100
|
+
const g = c.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);
|
|
101
|
+
if (!g) return;
|
|
102
|
+
if (g[1]) return g[1];
|
|
103
|
+
const i = g[2];
|
|
104
|
+
return /^\d+(\.\d+)?$/.test(i) ? `${Number(i) * 4}px` : i === "auto" || v(i, "%") ? i : "16px";
|
|
105
|
+
}, r = n(t), o = n(s);
|
|
106
|
+
return {
|
|
107
|
+
width: v(r, "px") ? r : "16px",
|
|
108
|
+
height: v(o, "px") ? o : "16px"
|
|
109
|
+
};
|
|
110
|
+
}, G = (e) => {
|
|
111
|
+
if (e.tagName === "svg") return {};
|
|
112
|
+
const a = {}, t = _t[e.tagName] || {}, s = e.attributes;
|
|
113
|
+
return B(s, ({ key: n, value: r }) => {
|
|
114
|
+
if (!v(st, n))
|
|
115
|
+
if (t[n]) {
|
|
116
|
+
if (e.tagName === "img" && n === "src" && !r.startsWith("http")) {
|
|
117
|
+
const o = m(e.attributes, { key: "width" }), c = m(e.attributes, { key: "height" });
|
|
118
|
+
o && c ? r = `https://via.placeholder.com/${o == null ? void 0 : o.value}x${c == null ? void 0 : c.value}` : r = "https://via.placeholder.com/150x150";
|
|
119
|
+
}
|
|
120
|
+
E(a, t[n], H(r));
|
|
121
|
+
} else v(["style", "class", "srcset"], n) || (A(a, "styles_attrs") || (a.styles_attrs = {}), k(n, "@") && (n = n.replace("@", "x-on:")), a.styles_attrs[`${n}`] = H(r));
|
|
122
|
+
}), delete a.class, a;
|
|
123
|
+
}, vt = (e, a = "styles") => {
|
|
124
|
+
if (!e.attributes) return { [a]: `${x},` };
|
|
125
|
+
const t = m(e.attributes, { key: "class" });
|
|
126
|
+
if (t) {
|
|
127
|
+
const s = t.value;
|
|
128
|
+
return { [a]: `${x},${s}` };
|
|
129
|
+
}
|
|
130
|
+
return { [a]: `${x},` };
|
|
131
|
+
}, wt = (e) => {
|
|
132
|
+
const a = d(e, "attributes", []), t = a.find((i) => i.key === "data-chai-richtext" || i.key === "chai-richtext"), s = a.find((i) => i.key === "data-chai-lightbox" || i.key === "chai-lightbox"), n = a.find((i) => i.key === "data-chai-dropdown" || i.key === "chai-dropdown"), r = a.find(
|
|
133
|
+
(i) => i.key === "data-chai-dropdown-button" || i.key === "chai-dropdown-button"
|
|
134
|
+
), o = a.find(
|
|
135
|
+
(i) => i.key === "data-chai-dropdown-content" || i.key === "chai-dropdown-content"
|
|
136
|
+
), c = a.find((i) => i.key === "class"), g = c && c.value.split(/\s+/).includes("rte");
|
|
137
|
+
if (n)
|
|
138
|
+
return { _type: "Dropdown" };
|
|
139
|
+
if (r)
|
|
140
|
+
return { _type: "DropdownButton" };
|
|
141
|
+
if (o)
|
|
142
|
+
return { _type: "DropdownContent" };
|
|
143
|
+
if (t || g)
|
|
144
|
+
return { _type: "Paragraph" };
|
|
145
|
+
if (s)
|
|
146
|
+
return { _type: "LightBoxLink" };
|
|
147
|
+
switch (e.tagName) {
|
|
148
|
+
// self closing tags
|
|
149
|
+
case "img":
|
|
150
|
+
return { _type: "Image" };
|
|
151
|
+
case "input":
|
|
152
|
+
return { _type: "Input", showLabel: !1 };
|
|
153
|
+
// showLabel: hiding default block label
|
|
154
|
+
case "hr":
|
|
155
|
+
return { _type: "Divider" };
|
|
156
|
+
case "br":
|
|
157
|
+
return { _type: "LineBreak" };
|
|
158
|
+
case "textarea":
|
|
159
|
+
return { _type: "TextArea", showLabel: !1 };
|
|
160
|
+
case "audio":
|
|
161
|
+
return { _type: "Audio" };
|
|
162
|
+
case "canvas":
|
|
163
|
+
return { _type: "Canvas" };
|
|
164
|
+
case "video":
|
|
165
|
+
case "iframe":
|
|
166
|
+
return { _type: "CustomHTML" };
|
|
167
|
+
case "svg":
|
|
168
|
+
return { _type: "Icon" };
|
|
169
|
+
// non self closing tags
|
|
170
|
+
// fixed structure
|
|
171
|
+
case "select":
|
|
172
|
+
return { _type: "Select", options: [] };
|
|
173
|
+
case "option":
|
|
174
|
+
return { _type: "Option" };
|
|
175
|
+
case "ul":
|
|
176
|
+
case "ol":
|
|
177
|
+
case "dl":
|
|
178
|
+
return {
|
|
179
|
+
_type: "List",
|
|
180
|
+
tag: e.tagName,
|
|
181
|
+
_listType: e.tagName === "ol" ? "list-decimal" : "list-none"
|
|
182
|
+
};
|
|
183
|
+
case "li":
|
|
184
|
+
case "dt":
|
|
185
|
+
return { _type: "ListItem", tag: e.tagName };
|
|
186
|
+
// non self closing tags
|
|
187
|
+
// free flow structure
|
|
188
|
+
case "span":
|
|
189
|
+
case "figcaption":
|
|
190
|
+
case "legend":
|
|
191
|
+
return { _type: "Span", tag: e.tagName };
|
|
192
|
+
case "p":
|
|
193
|
+
return { _type: "Paragraph", content: "" };
|
|
194
|
+
case "a":
|
|
195
|
+
return { _type: "Link" };
|
|
196
|
+
case "form":
|
|
197
|
+
return { _type: "Form" };
|
|
198
|
+
case "label":
|
|
199
|
+
return { _type: "Label" };
|
|
200
|
+
case "button":
|
|
201
|
+
return { _type: "Button" };
|
|
202
|
+
case "code":
|
|
203
|
+
return { _type: "Box", _name: "Code" };
|
|
204
|
+
case "h1":
|
|
205
|
+
case "h2":
|
|
206
|
+
case "h3":
|
|
207
|
+
case "h4":
|
|
208
|
+
case "h5":
|
|
209
|
+
case "h6":
|
|
210
|
+
return { _type: "Heading", tag: e.tagName };
|
|
211
|
+
case "table":
|
|
212
|
+
return { _type: "Table" };
|
|
213
|
+
case "tr":
|
|
214
|
+
return { _type: "TableRow" };
|
|
215
|
+
case "td":
|
|
216
|
+
case "th":
|
|
217
|
+
return { _type: "TableCell", tag: e.tagName };
|
|
218
|
+
case "thead":
|
|
219
|
+
return { _type: "TableHead" };
|
|
220
|
+
case "tbody":
|
|
221
|
+
return { _type: "TableBody" };
|
|
222
|
+
case "tfoot":
|
|
223
|
+
return { _type: "TableFooter" };
|
|
224
|
+
default: {
|
|
225
|
+
const i = d(e, "children", []).length > 0 ? "Box" : "EmptyBox";
|
|
226
|
+
return {
|
|
227
|
+
_type: i,
|
|
228
|
+
tag: e.tagName,
|
|
229
|
+
_name: i == "EmptyBox" || e.tagName === "div" ? i : dt(e.tagName)
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}, j = (e, a = null) => ot(e, (t) => {
|
|
234
|
+
var P, J, O, z, V, W, F, U, Y, K;
|
|
235
|
+
if (t.type === "comment") return [];
|
|
236
|
+
let s = { _id: nt() };
|
|
237
|
+
if (a && (s._parent = a.block._id), t.type === "text")
|
|
238
|
+
return f(d(t, "content", "")) ? [] : a && kt(a.node, a.block) ? (E(a, "block.content", d(t, "content", "")), []) : { ...s, _type: "Text", content: d(t, "content", "") };
|
|
239
|
+
if (k(t.tagName, "chai-")) {
|
|
240
|
+
const l = t.attributes, p = m(l, { key: "chai-type" }), u = (p == null ? void 0 : p.value) || lt(t.tagName.replace("chai-", "")).replace(/\s+/g, "");
|
|
241
|
+
s._type = u, B(l, ({ key: b, value: X }) => {
|
|
242
|
+
if (b === "about-this-component" || b === "chai-type" || b === "can-move" || b === "can-delete") return;
|
|
243
|
+
if (b === "id") {
|
|
244
|
+
s._id = X;
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
247
|
+
let I = H(X);
|
|
248
|
+
typeof I == "string" && k(I, "#styles:") && (I = I.replace("#styles:", "#styles:,")), s[b] = I;
|
|
249
|
+
});
|
|
250
|
+
const h = j(t.children, { block: s, node: t });
|
|
251
|
+
return [s, ...h];
|
|
252
|
+
}
|
|
253
|
+
const n = d(t, "attributes", []), r = n.find(
|
|
254
|
+
(l) => l.key === "data-chai-richtext" || l.key === "chai-richtext"
|
|
255
|
+
), o = n.find((l) => l.key === "class"), c = o && o.value.split(/\s+/).includes("rte"), g = n.find(
|
|
256
|
+
(l) => l.key === "data-chai-lightbox" || l.key === "chai-lightbox"
|
|
257
|
+
), i = n.find(
|
|
258
|
+
(l) => l.key === "data-chai-dropdown" || l.key === "chai-dropdown"
|
|
259
|
+
), w = n.find(
|
|
260
|
+
(l) => l.key === "data-chai-dropdown-button" || l.key === "chai-dropdown-button"
|
|
261
|
+
), D = n.find(
|
|
262
|
+
(l) => l.key === "data-chai-dropdown-content" || l.key === "chai-dropdown-content"
|
|
263
|
+
);
|
|
264
|
+
if (s = {
|
|
265
|
+
...s,
|
|
266
|
+
...wt(t),
|
|
267
|
+
...G(t),
|
|
268
|
+
...vt(t)
|
|
269
|
+
}, t.attributes) {
|
|
270
|
+
const l = t.attributes.find((p) => v(st, p.key));
|
|
271
|
+
l && (s._name = l.value);
|
|
272
|
+
}
|
|
273
|
+
if (r || c)
|
|
274
|
+
return s.content = N(t.children), A(s, "styles_attrs.data-chai-richtext") && delete s.styles_attrs["data-chai-richtext"], A(s, "styles_attrs.chai-richtext") && delete s.styles_attrs["chai-richtext"], [s];
|
|
275
|
+
if (g) {
|
|
276
|
+
const l = [
|
|
277
|
+
"data-chai-lightbox",
|
|
278
|
+
"chai-lightbox",
|
|
279
|
+
"data-vbtype",
|
|
280
|
+
"data-autoplay",
|
|
281
|
+
"data-maxwidth",
|
|
282
|
+
"data-overlay",
|
|
283
|
+
"data-gall",
|
|
284
|
+
"href"
|
|
285
|
+
];
|
|
286
|
+
s = {
|
|
287
|
+
...s,
|
|
288
|
+
href: ((P = n.find((p) => p.key === "href")) == null ? void 0 : P.value) || "",
|
|
289
|
+
hrefType: ((J = n.find((p) => p.key === "data-vbtype")) == null ? void 0 : J.value) || "video",
|
|
290
|
+
autoplay: ((O = n.find((p) => p.key === "data-autoplay")) == null ? void 0 : O.value) === "true" ? "true" : "false",
|
|
291
|
+
maxWidth: ((V = (z = n.find((p) => p.key === "data-maxwidth")) == null ? void 0 : z.value) == null ? void 0 : V.replace("px", "")) || "",
|
|
292
|
+
backdropColor: ((W = n.find((p) => p.key === "data-overlay")) == null ? void 0 : W.value) || "",
|
|
293
|
+
galleryName: ((F = n.find((p) => p.key === "data-gall")) == null ? void 0 : F.value) || ""
|
|
294
|
+
}, B(l, (p) => {
|
|
295
|
+
A(s, `styles_attrs.${p}`) && delete s.styles_attrs[p];
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
if (i && (delete s.styles_attrs, s.showDropdown = !1), D && delete s.styles_attrs, w) {
|
|
299
|
+
delete s.styles_attrs;
|
|
300
|
+
const l = Z(t.children || [], (u) => (u == null ? void 0 : u.tagName) !== "span");
|
|
301
|
+
s.content = R(l);
|
|
302
|
+
const p = m(
|
|
303
|
+
t.children || [],
|
|
304
|
+
(u) => (u == null ? void 0 : u.tagName) === "span" && ct(u.children || [], (h) => (h == null ? void 0 : h.tagName) === "svg")
|
|
305
|
+
);
|
|
306
|
+
if (p) {
|
|
307
|
+
const u = m(p.children || [], (h) => (h == null ? void 0 : h.tagName) === "svg");
|
|
308
|
+
if (u) {
|
|
309
|
+
s.icon = N([u]);
|
|
310
|
+
const { height: h, width: b } = Tt(u, "16px", "16px");
|
|
311
|
+
s.iconHeight = h, s.iconWidth = b;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
return [s];
|
|
315
|
+
}
|
|
316
|
+
if (s._type === "Input") {
|
|
317
|
+
const l = s.inputType || "text";
|
|
318
|
+
l === "checkbox" ? E(s, "_type", "Checkbox") : l === "radio" && E(s, "_type", "Radio");
|
|
319
|
+
} else if (t.tagName === "video" || t.tagName === "iframe") {
|
|
320
|
+
const l = N([t]);
|
|
321
|
+
return ft(l) && (E(s, "_type", "Video"), E(s, "url", xt(l)), E(s, "styles", `${x},`), E(s, "controls", { autoPlay: !1, muted: !0, loop: !1, controls: !1 })), s.content = l, [s];
|
|
322
|
+
} else if (t.tagName === "svg") {
|
|
323
|
+
const l = d(m(t.attributes, { key: "class" }), "value", ""), { height: p, width: u } = at(l);
|
|
324
|
+
if (p && u)
|
|
325
|
+
s.styles = `${x}, ${S(`w-${u} h-${p}`, l)}`.trim(), s.height = p == null ? void 0 : p.replace("px", ""), s.width = u == null ? void 0 : u.replace("px", "");
|
|
326
|
+
else {
|
|
327
|
+
const h = (U = m(t.attributes, { key: "height" })) == null ? void 0 : U.value, b = (Y = m(t.attributes, { key: "width" })) == null ? void 0 : Y.value;
|
|
328
|
+
h && b ? (s.styles = `${x}, ${S(`w-[${b}px] h-[${h}px]`, l)}`.trim(), s.height = h, s.width = b) : s.styles = `${x}, ${S("w-full h-full", l)}`.trim();
|
|
329
|
+
}
|
|
330
|
+
return t.attributes = Z(t.attributes, (h) => !v(["style", "width", "height", "class"], h.key)), s.icon = N([t]), [s];
|
|
331
|
+
} else if (t.tagName == "option" && a && ((K = a.block) == null ? void 0 : K._type) === "Select")
|
|
332
|
+
return a.block.options.push({
|
|
333
|
+
label: R(t.children),
|
|
334
|
+
...G(t)
|
|
335
|
+
}), [];
|
|
336
|
+
const T = j(t.children, { block: s, node: t });
|
|
337
|
+
return [s, ...T];
|
|
338
|
+
}), Tt = (e, a, t) => {
|
|
339
|
+
var g, i;
|
|
340
|
+
const s = d(e, "attributes", []), { height: n, width: r } = at(
|
|
341
|
+
d(m(s, { key: "class" }), "value", "")
|
|
342
|
+
);
|
|
343
|
+
if (n && r)
|
|
344
|
+
return {
|
|
345
|
+
height: `[${n}px]`,
|
|
346
|
+
width: `[${r}px]`
|
|
347
|
+
};
|
|
348
|
+
const o = (g = m(s, { key: "height" })) == null ? void 0 : g.value, c = (i = m(s, { key: "width" })) == null ? void 0 : i.value;
|
|
349
|
+
return {
|
|
350
|
+
height: o ? `[${o}px]` : t,
|
|
351
|
+
width: c ? `[${c}px]` : a
|
|
352
|
+
};
|
|
353
|
+
}, Et = (e) => {
|
|
354
|
+
e = e.replace(/(\w+)=\\?"(.*?)\\?"/g, (s, n, r) => {
|
|
355
|
+
let o = r.replace(/\\"/g, '"');
|
|
356
|
+
return o = o.replace(/{([^}]+)}/g, (c) => c.replace(/"/g, '\\"')), `${n}="${o.replace(/\\"/g, '"')}"`;
|
|
357
|
+
}), e = e.replace(/\\n/g, "").replace(/\\\\/g, "").replace(/\\([/<>])/g, "$1").replace(/\\./g, "").replace(/[\n\r\t\f\v]/g, ""), e = e.replace(/\$name="[^"]*"/g, "");
|
|
358
|
+
const a = e.match(/<body[^>]*>[\s\S]*?<\/body>/);
|
|
359
|
+
return (a && a.length > 0 ? a[0].replace(/<body/, "<div").replace(/<\/body>/, "</div>") : e).replace(/\s+/g, " ").replaceAll("> <", "><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").trim();
|
|
360
|
+
}, Bt = (e, a) => m(e, { _id: a }), Ht = (e, a) => f(a) ? e : Q(e, (t) => {
|
|
361
|
+
const s = Bt(a, t._id);
|
|
362
|
+
return s ? { ...s, ...t } : t;
|
|
363
|
+
}), jt = (e) => {
|
|
364
|
+
const a = gt(Et(e));
|
|
365
|
+
return f(e) ? [] : rt(j(a));
|
|
366
|
+
};
|
|
367
|
+
function qt(e, a, t) {
|
|
368
|
+
const s = d(t, "i18nProps", []);
|
|
369
|
+
if (f(a) || f(s)) return e;
|
|
370
|
+
const n = q(e);
|
|
371
|
+
return B(M(n), (r) => {
|
|
372
|
+
if (v(s, r) && !f(a)) {
|
|
373
|
+
const o = d(n, r), c = d(n, `${r}-${a}`, "");
|
|
374
|
+
$(o) ? n[r] = $(c) && !f(c.trim()) && c.trimStart() || o : n[r] = f(c) ? o : c;
|
|
375
|
+
}
|
|
376
|
+
}), n;
|
|
377
|
+
}
|
|
378
|
+
const $t = tt((e) => {
|
|
379
|
+
const { baseClasses: a, classes: t } = et(e);
|
|
380
|
+
return yt(a, t);
|
|
381
|
+
});
|
|
382
|
+
function It(e, a) {
|
|
383
|
+
return d(e, `${a}_attrs`, {});
|
|
384
|
+
}
|
|
385
|
+
function Mt(e, a = !0) {
|
|
386
|
+
const t = {};
|
|
387
|
+
return Object.keys(e).forEach((s) => {
|
|
388
|
+
if ($(e[s]) && e[s].startsWith(x)) {
|
|
389
|
+
const n = $t(e[s]), r = It(e, s);
|
|
390
|
+
t[s] = {
|
|
391
|
+
...!f(n) && { className: n },
|
|
392
|
+
...r,
|
|
393
|
+
...a ? {
|
|
394
|
+
"data-style-prop": s,
|
|
395
|
+
"data-block-parent": e._id,
|
|
396
|
+
"data-style-id": `${s}-${e._id}`
|
|
397
|
+
} : {}
|
|
398
|
+
};
|
|
399
|
+
}
|
|
400
|
+
}), t;
|
|
401
|
+
}
|
|
402
|
+
const Pt = tt((e) => {
|
|
403
|
+
const a = mt(e), t = d(a, "schema.properties", {});
|
|
404
|
+
return Object.fromEntries(Object.entries(t).filter(([, s]) => d(s, "runtime", !1)));
|
|
405
|
+
}), Jt = (e, a) => {
|
|
406
|
+
if (!C(e)) return e;
|
|
407
|
+
let t = e, s;
|
|
408
|
+
return typeof a.limit == "number" && a.limit > 0 && (s = a.limit), s !== void 0 && (t = t.slice(0, s)), t;
|
|
409
|
+
}, Ot = (e, a) => {
|
|
410
|
+
const t = q(e);
|
|
411
|
+
return B(M(t), (s) => {
|
|
412
|
+
if ($(t[s]) && !k(s, "_")) {
|
|
413
|
+
let n = t[s];
|
|
414
|
+
s === "repeaterItems" && (t.repeaterItemsBinding = n);
|
|
415
|
+
const r = /\{\{(.*?)\}\}/g, o = n.match(r);
|
|
416
|
+
o && o.forEach((c) => {
|
|
417
|
+
let g = c.slice(2, -2);
|
|
418
|
+
const i = d(a, g, c);
|
|
419
|
+
n = C(i) ? i : n.replace(c, i);
|
|
420
|
+
}), t[s] = n;
|
|
421
|
+
}
|
|
422
|
+
}), t;
|
|
423
|
+
}, _ = (e) => {
|
|
424
|
+
const a = ht(e);
|
|
425
|
+
return e.map((t) => {
|
|
426
|
+
const s = Object.keys(t);
|
|
427
|
+
for (let n = 0; n < s.length; n++)
|
|
428
|
+
if ($(t[s[n]]) && k(s[n], "content")) {
|
|
429
|
+
const r = t === a ? "" : " ";
|
|
430
|
+
t[s[n]] = `${t[s[n]].trim()}${r}`;
|
|
431
|
+
}
|
|
432
|
+
return t;
|
|
433
|
+
});
|
|
434
|
+
};
|
|
435
|
+
if (import.meta.vitest) {
|
|
436
|
+
const { describe: e, it: a, expect: t } = import.meta.vitest;
|
|
437
|
+
e("adjustSpacingInContentBlocks", () => {
|
|
438
|
+
a("should add space after content fields except for the last block", () => {
|
|
439
|
+
const n = _([
|
|
440
|
+
{ _id: "1", _type: "Text", content: "First" },
|
|
441
|
+
{ _id: "2", _type: "Text", content: "Second" },
|
|
442
|
+
{ _id: "3", _type: "Text", content: "Third" }
|
|
443
|
+
]);
|
|
444
|
+
t(n[0].content).toBe("First "), t(n[1].content).toBe("Second "), t(n[2].content).toBe("Third");
|
|
445
|
+
}), a("should trim whitespace from content before adding space", () => {
|
|
446
|
+
const n = _([
|
|
447
|
+
{ _id: "1", _type: "Text", content: " First " },
|
|
448
|
+
{ _id: "2", _type: "Text", content: " Second " }
|
|
449
|
+
]);
|
|
450
|
+
t(n[0].content).toBe("First "), t(n[1].content).toBe("Second");
|
|
451
|
+
}), a("should handle multiple content fields in a single block", () => {
|
|
452
|
+
const n = _([
|
|
453
|
+
{ _id: "1", _type: "Text", content: "Main", contentAlt: "Alt" },
|
|
454
|
+
{ _id: "2", _type: "Text", content: "Last", contentSecondary: "Secondary" }
|
|
455
|
+
]);
|
|
456
|
+
t(n[0].content).toBe("Main "), t(n[0].contentAlt).toBe("Alt "), t(n[1].content).toBe("Last"), t(n[1].contentSecondary).toBe("Secondary");
|
|
457
|
+
}), a("should only process fields that start with 'content'", () => {
|
|
458
|
+
const n = _([
|
|
459
|
+
{ _id: "1", _type: "Text", content: "Text", title: "Title", text: "Text" },
|
|
460
|
+
{ _id: "2", _type: "Text", content: "Last" }
|
|
461
|
+
]);
|
|
462
|
+
t(n[0].content).toBe("Text "), t(n[0].title).toBe("Title"), t(n[0].text).toBe("Text"), t(n[1].content).toBe("Last");
|
|
463
|
+
}), a("should handle empty array", () => {
|
|
464
|
+
const n = _([]);
|
|
465
|
+
t(n).toEqual([]);
|
|
466
|
+
}), a("should handle single block", () => {
|
|
467
|
+
const n = _([{ _id: "1", _type: "Text", content: "Only" }]);
|
|
468
|
+
t(n[0].content).toBe("Only");
|
|
469
|
+
}), a("should handle blocks without content fields", () => {
|
|
470
|
+
const n = _([
|
|
471
|
+
{ _id: "1", _type: "Container", title: "Title" },
|
|
472
|
+
{ _id: "2", _type: "Container", name: "Name" }
|
|
473
|
+
]);
|
|
474
|
+
t(n[0].title).toBe("Title"), t(n[1].name).toBe("Name");
|
|
475
|
+
}), a("should handle blocks with non-string content fields", () => {
|
|
476
|
+
const n = _([
|
|
477
|
+
{ _id: "1", _type: "Text", content: "Text", contentNum: 123 },
|
|
478
|
+
{ _id: "2", _type: "Text", content: "Last", contentBool: !0 }
|
|
479
|
+
]);
|
|
480
|
+
t(n[0].content).toBe("Text "), t(n[0].contentNum).toBe(123), t(n[1].content).toBe("Last"), t(n[1].contentBool).toBe(!0);
|
|
481
|
+
}), a("should handle empty string content", () => {
|
|
482
|
+
const n = _([
|
|
483
|
+
{ _id: "1", _type: "Text", content: "" },
|
|
484
|
+
{ _id: "2", _type: "Text", content: "Last" }
|
|
485
|
+
]);
|
|
486
|
+
t(n[0].content).toBe(" "), t(n[1].content).toBe("Last");
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
const y = (e, a, { index: t, key: s }, n) => {
|
|
491
|
+
if ($(e)) {
|
|
492
|
+
let r = e;
|
|
493
|
+
const o = /\{\{(.*?)\}\}/g, c = e.match(o);
|
|
494
|
+
if (c) {
|
|
495
|
+
const g = n === "image" || n === "mobileImage";
|
|
496
|
+
c.forEach((i) => {
|
|
497
|
+
let w = i.slice(2, -2).trim(), D = s.slice(2, -2).trim();
|
|
498
|
+
t !== -1 && k(w, "$index.") ? w = `${D}.${t}.${w.slice(7)}` : t !== -1 && k(w, "$index") && (w = `${D}.${t}`);
|
|
499
|
+
const T = d(a, w);
|
|
500
|
+
T === void 0 ? r = r.replace(i, "") : g && !C(T) ? r = T : r = C(T) ? T : r.replace(i, T);
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
return r;
|
|
504
|
+
}
|
|
505
|
+
if (C(e))
|
|
506
|
+
return e.map((r) => y(r, a, { index: t, key: s }, n));
|
|
507
|
+
if (e && typeof e == "object") {
|
|
508
|
+
const r = {};
|
|
509
|
+
return B(M(e), (o) => {
|
|
510
|
+
!k(o, "_") && o !== "$repeaterItemsKey" ? r[o] = y(e[o], a, { index: t, key: s }, o) : r[o] = e[o];
|
|
511
|
+
}), r;
|
|
512
|
+
}
|
|
513
|
+
return e;
|
|
514
|
+
}, L = (e, a, { index: t, key: s }) => {
|
|
515
|
+
let n = q(e);
|
|
516
|
+
return n.repeaterItems && (n.$repeaterItemsKey = n.repeaterItems, k(n.repeaterItems, `{{${bt}`) && (n.$repeaterItemsKey = n.repeaterItems = `${n.repeaterItems.replace("}}", `/${n._id}}}`)}`), !f(n.repeaterItems) && n.pagination && (n.repeaterTotalItems = `${n.repeaterItems.replace("}}", `/${n._id}/totalItems}}`)}`)), y(n, a, { index: t, key: s });
|
|
517
|
+
};
|
|
518
|
+
import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
519
|
+
it("should handle string values with bindings", () => {
|
|
520
|
+
const t = y("Hello {{user.name}}", { user: { name: "John" } }, { index: -1, key: "" });
|
|
521
|
+
expect(t).toBe("Hello John");
|
|
522
|
+
}), it("should handle nested object properties", () => {
|
|
523
|
+
const t = y({
|
|
524
|
+
name: "John",
|
|
525
|
+
address: {
|
|
526
|
+
city: "{{user.city}}",
|
|
527
|
+
street: "123 Main St"
|
|
528
|
+
}
|
|
529
|
+
}, { user: { city: "New York" } }, { index: -1, key: "" });
|
|
530
|
+
expect(t).toEqual({
|
|
531
|
+
name: "John",
|
|
532
|
+
address: {
|
|
533
|
+
city: "New York",
|
|
534
|
+
street: "123 Main St"
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
}), it("should handle arrays of values", () => {
|
|
538
|
+
const t = y(["Hello {{user.name}}", "Welcome {{user.role}}"], { user: { name: "John", role: "Admin" } }, { index: -1, key: "" });
|
|
539
|
+
expect(t).toEqual(["Hello John", "Welcome Admin"]);
|
|
540
|
+
}), it("should handle $index binding in repeater context", () => {
|
|
541
|
+
const t = y("Item {{$index}}", { items: ["a", "b", "c"] }, { index: 1, key: "{{items}}" });
|
|
542
|
+
expect(t).toBe("Item b");
|
|
543
|
+
}), it("should handle $index binding with dot notation", () => {
|
|
544
|
+
const t = y("Item {{$index.value}}", { items: [{ value: "apple" }, { value: "banana" }, { value: "cherry" }] }, { index: 1, key: "{{items}}" });
|
|
545
|
+
expect(t).toBe("Item banana");
|
|
546
|
+
}), it("should return an empty string for non-existing bindings", () => {
|
|
547
|
+
const t = y("Hello {{user.nonexistent}}", { user: { name: "John" } }, { index: -1, key: "" });
|
|
548
|
+
expect(t).toBe("Hello ");
|
|
549
|
+
}), it("should preserve private properties starting with _", () => {
|
|
550
|
+
const a = y({
|
|
551
|
+
name: "John",
|
|
552
|
+
_private: "secret"
|
|
553
|
+
}, {}, { index: -1, key: "" });
|
|
554
|
+
expect(a).toEqual({
|
|
555
|
+
name: "John",
|
|
556
|
+
_private: "secret"
|
|
557
|
+
});
|
|
558
|
+
}), it("should completely replace image property value when binding exists", () => {
|
|
559
|
+
const t = y({
|
|
560
|
+
image: "https://default.jpg{{user.avatar}}",
|
|
561
|
+
title: "Hello {{user.name}}"
|
|
562
|
+
}, { user: { avatar: "https://avatar.jpg", name: "John" } }, { index: -1, key: "" });
|
|
563
|
+
expect(t).toEqual({
|
|
564
|
+
image: "https://avatar.jpg",
|
|
565
|
+
// Completely replaced, not concatenated
|
|
566
|
+
title: "Hello John"
|
|
567
|
+
// Normal replacement
|
|
568
|
+
});
|
|
569
|
+
}), it("should completely replace mobileImage property value when binding exists", () => {
|
|
570
|
+
const t = y({
|
|
571
|
+
mobileImage: "https://default-mobile.jpg{{user.mobileAvatar}}",
|
|
572
|
+
alt: "Avatar for {{user.name}}"
|
|
573
|
+
}, { user: { mobileAvatar: "https://mobile-avatar.jpg", name: "John" } }, { index: -1, key: "" });
|
|
574
|
+
expect(t).toEqual({
|
|
575
|
+
mobileImage: "https://mobile-avatar.jpg",
|
|
576
|
+
// Completely replaced
|
|
577
|
+
alt: "Avatar for John"
|
|
578
|
+
// Normal replacement
|
|
579
|
+
});
|
|
580
|
+
}), it("should handle image binding with only binding syntax", () => {
|
|
581
|
+
const t = y({
|
|
582
|
+
image: "{{product.thumbnail}}"
|
|
583
|
+
}, { product: { thumbnail: "https://product.jpg" } }, { index: -1, key: "" });
|
|
584
|
+
expect(t).toEqual({
|
|
585
|
+
image: "https://product.jpg"
|
|
586
|
+
});
|
|
587
|
+
}), it("should not affect non-image properties with similar bindings", () => {
|
|
588
|
+
const t = y({
|
|
589
|
+
url: "https://default.com{{page.slug}}",
|
|
590
|
+
link: "https://example.com/{{page.id}}"
|
|
591
|
+
}, { page: { slug: "/about", id: "123" } }, { index: -1, key: "" });
|
|
592
|
+
expect(t).toEqual({
|
|
593
|
+
url: "https://default.com/about",
|
|
594
|
+
// Concatenated normally
|
|
595
|
+
link: "https://example.com/123"
|
|
596
|
+
// Concatenated normally
|
|
597
|
+
});
|
|
598
|
+
});
|
|
599
|
+
}), describe("applyBindingToBlockProps", () => {
|
|
600
|
+
it("should handle basic block with bindings", () => {
|
|
601
|
+
const t = L({
|
|
602
|
+
_id: "test-block",
|
|
603
|
+
_type: "text",
|
|
604
|
+
type: "text",
|
|
605
|
+
content: "Hello {{user.name}}",
|
|
606
|
+
style: {
|
|
607
|
+
color: "{{theme.color}}"
|
|
608
|
+
}
|
|
609
|
+
}, { user: { name: "John" }, theme: { color: "blue" } }, { index: -1, key: "" });
|
|
610
|
+
expect(t).toEqual({
|
|
611
|
+
_id: "test-block",
|
|
612
|
+
_type: "text",
|
|
613
|
+
type: "text",
|
|
614
|
+
content: "Hello John",
|
|
615
|
+
style: {
|
|
616
|
+
color: "blue"
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
}), it("should handle repeaterItems and repeaterItemsBinding", () => {
|
|
620
|
+
const t = L({
|
|
621
|
+
_id: "test-block",
|
|
622
|
+
_type: "repeater",
|
|
623
|
+
type: "repeater",
|
|
624
|
+
repeaterItems: "{{items}}",
|
|
625
|
+
items: ["a", "b", "c"]
|
|
626
|
+
}, { items: ["x", "y", "z"] }, { index: -1, key: "" });
|
|
627
|
+
expect(t).toEqual({
|
|
628
|
+
_id: "test-block",
|
|
629
|
+
_type: "repeater",
|
|
630
|
+
type: "repeater",
|
|
631
|
+
$repeaterItemsKey: "{{items}}",
|
|
632
|
+
repeaterItems: ["x", "y", "z"],
|
|
633
|
+
items: ["a", "b", "c"]
|
|
634
|
+
});
|
|
635
|
+
}), it("should handle nested blocks with bindings", () => {
|
|
636
|
+
const t = L({
|
|
637
|
+
_id: "test-block",
|
|
638
|
+
_type: "container",
|
|
639
|
+
type: "container",
|
|
640
|
+
children: [
|
|
641
|
+
{
|
|
642
|
+
_id: "child-block",
|
|
643
|
+
_type: "text",
|
|
644
|
+
type: "text",
|
|
645
|
+
content: "Item {{$index}}",
|
|
646
|
+
style: {
|
|
647
|
+
color: "{{theme.color}}"
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
]
|
|
651
|
+
}, { theme: { color: "red" }, items: ["x", "y", "z"] }, { index: 2, key: "{{items}}" });
|
|
652
|
+
expect(t).toEqual({
|
|
653
|
+
_id: "test-block",
|
|
654
|
+
_type: "container",
|
|
655
|
+
type: "container",
|
|
656
|
+
children: [
|
|
657
|
+
{
|
|
658
|
+
_id: "child-block",
|
|
659
|
+
_type: "text",
|
|
660
|
+
type: "text",
|
|
661
|
+
content: "Item z",
|
|
662
|
+
style: {
|
|
663
|
+
color: "red"
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
]
|
|
667
|
+
});
|
|
668
|
+
}), it("should handle arrays of blocks", () => {
|
|
669
|
+
const t = L({
|
|
670
|
+
_id: "test-block",
|
|
671
|
+
_type: "list",
|
|
672
|
+
type: "list",
|
|
673
|
+
items: [
|
|
674
|
+
{ _id: "item1", content: "Item {{$index}}" },
|
|
675
|
+
{ _id: "item2", content: "Item {{$index}}" }
|
|
676
|
+
]
|
|
677
|
+
}, { items: ["x", "y", "z"] }, { index: 0, key: "{{items}}" });
|
|
678
|
+
expect(t).toEqual({
|
|
679
|
+
_id: "test-block",
|
|
680
|
+
_type: "list",
|
|
681
|
+
type: "list",
|
|
682
|
+
items: [
|
|
683
|
+
{ _id: "item1", content: "Item x" },
|
|
684
|
+
{ _id: "item2", content: "Item x" }
|
|
685
|
+
]
|
|
686
|
+
});
|
|
687
|
+
});
|
|
688
|
+
}));
|
|
689
|
+
export {
|
|
690
|
+
bt as C,
|
|
691
|
+
Rt as R,
|
|
692
|
+
x as S,
|
|
693
|
+
L as a,
|
|
694
|
+
qt as b,
|
|
695
|
+
Pt as c,
|
|
696
|
+
Jt as d,
|
|
697
|
+
_ as e,
|
|
698
|
+
Ot as f,
|
|
699
|
+
Mt as g,
|
|
700
|
+
jt as h,
|
|
701
|
+
et as i,
|
|
702
|
+
St as j,
|
|
703
|
+
Ht as m
|
|
704
|
+
};
|