@chaibuilder/sdk 3.0.10 → 3.0.11
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/{apply-binding-CSYk-NOA.js → apply-binding-B0CX8mDS.js} +50 -50
- package/dist/{apply-binding-C4AQBX3p.cjs → apply-binding-DSgP62np.cjs} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +1 -1
- package/dist/render.cjs +2 -2
- package/dist/render.js +5 -3
- package/dist/web-blocks.cjs +1 -1
- package/dist/web-blocks.js +350 -293
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { getRegisteredChaiBlock as Q } from "@chaibuilder/runtime";
|
|
2
|
-
import { memoize as Y, get as u, cloneDeep as S, forEach as $, keys as A, isString as T, startsWith as v, isArray as
|
|
2
|
+
import { memoize as Y, get as u, cloneDeep as S, forEach as $, keys as A, isString as T, startsWith as v, isArray as N, isEmpty as g, includes as _, flatten as tt, flatMapDeep as et, set as k, has as C, filter as V, find as m, some as st, compact as at, map as nt, trim as rt, capitalize as ot, last as ct } from "lodash-es";
|
|
3
3
|
import { twMerge as lt } from "tailwind-merge";
|
|
4
4
|
import { g as pt, c as D } from "./common-functions-BGzDsf1z.js";
|
|
5
5
|
import { parse as dt, stringify as E } from "himalaya";
|
|
6
|
-
const f = "#styles:",
|
|
6
|
+
const f = "#styles:", It = "__ADD_BLOCK_INTERNAL_ROOT", Ct = "@", ut = "#", K = (e) => {
|
|
7
7
|
if (e = e.replace(f, ""), !e) return { baseClasses: "", classes: "" };
|
|
8
8
|
const n = e.split(/,(?![^\[]*\])/);
|
|
9
9
|
if (n.length === 1)
|
|
@@ -46,14 +46,14 @@ import.meta.vitest && describe("getSplitChaiClasses", () => {
|
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
|
-
function
|
|
49
|
+
function Nt(e, n, t) {
|
|
50
50
|
const a = u(t, "i18nProps", []);
|
|
51
|
-
if (
|
|
51
|
+
if (g(n) || g(a)) return e;
|
|
52
52
|
const s = S(e);
|
|
53
53
|
return $(A(s), (o) => {
|
|
54
|
-
if (_(a, o) && !
|
|
54
|
+
if (_(a, o) && !g(n)) {
|
|
55
55
|
const c = u(s, o), r = u(s, `${o}-${n}`, "");
|
|
56
|
-
T(c) ? s[o] = T(r) && !
|
|
56
|
+
T(c) ? s[o] = T(r) && !g(r.trim()) && r.trimStart() || c : s[o] = g(r) ? c : r;
|
|
57
57
|
}
|
|
58
58
|
}), s;
|
|
59
59
|
}
|
|
@@ -70,7 +70,7 @@ function Dt(e, n = !0) {
|
|
|
70
70
|
if (T(e[a]) && e[a].startsWith(f)) {
|
|
71
71
|
const s = ht(e[a]), o = yt(e, a);
|
|
72
72
|
t[a] = {
|
|
73
|
-
...!
|
|
73
|
+
...!g(s) && { className: s },
|
|
74
74
|
...o,
|
|
75
75
|
...n ? {
|
|
76
76
|
"data-style-prop": a,
|
|
@@ -85,7 +85,7 @@ const Lt = Y((e) => {
|
|
|
85
85
|
const n = Q(e), t = u(n, "schema.properties", {});
|
|
86
86
|
return Object.fromEntries(Object.entries(t).filter(([, a]) => u(a, "runtime", !1)));
|
|
87
87
|
}), St = (e, n) => {
|
|
88
|
-
if (!
|
|
88
|
+
if (!N(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) => {
|
|
@@ -98,15 +98,15 @@ const Lt = Y((e) => {
|
|
|
98
98
|
c && c.forEach((r) => {
|
|
99
99
|
let p = r.slice(2, -2);
|
|
100
100
|
const h = u(n, p, r);
|
|
101
|
-
s =
|
|
101
|
+
s = N(h) ? h : s.replace(r, h);
|
|
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 (
|
|
108
|
+
}, gt = (e) => {
|
|
109
|
+
if (g(e)) return e;
|
|
110
110
|
const n = /<video[^>]+src=['"]([^'">]+)['"]/, t = /<iframe[^>]+src=['"]([^'">]+)['"]/, a = e.match(n), s = e.match(t), o = a ? a[1] : s ? s[1] : null, c = /(?: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
111
|
return o && (c.test(o) || r.test(o)) ? o : e;
|
|
112
112
|
}, X = ["chai-name", "data-chai-name"], bt = {
|
|
@@ -148,8 +148,8 @@ const Lt = Y((e) => {
|
|
|
148
148
|
}, ft = (e, n) => e.children.length === 1 && _(
|
|
149
149
|
["Heading", "Paragraph", "Span", "ListItem", "Button", "Label", "TableCell", "Link", "RichText"],
|
|
150
150
|
n._type
|
|
151
|
-
), L = (e) => e.map((n) => n.type === "text" ? u(n, "content", "") :
|
|
152
|
-
const n = at(nt(e.split(/\s+/), rt)), t =
|
|
151
|
+
), L = (e) => e.map((n) => n.type === "text" ? u(n, "content", "") : g(n.children) ? "" : L(n.children)).join(""), W = (e) => e === null ? "" : e, Z = (e) => {
|
|
152
|
+
const n = at(nt(e.split(/\s+/), rt)), t = m(n, (r) => /^w-/.test(r)), a = m(n, (r) => /^h-/.test(r));
|
|
153
153
|
if (!a || !t) return { height: "", width: "" };
|
|
154
154
|
const s = (r) => {
|
|
155
155
|
if (!r) return;
|
|
@@ -170,15 +170,15 @@ const Lt = Y((e) => {
|
|
|
170
170
|
if (!_(X, s))
|
|
171
171
|
if (t[s]) {
|
|
172
172
|
if (e.tagName === "img" && s === "src" && !o.startsWith("http")) {
|
|
173
|
-
const c =
|
|
173
|
+
const c = m(e.attributes, { key: "width" }), r = m(e.attributes, { key: "height" });
|
|
174
174
|
c && r ? o = `https://via.placeholder.com/${c == null ? void 0 : c.value}x${r == null ? void 0 : r.value}` : o = "https://via.placeholder.com/150x150";
|
|
175
175
|
}
|
|
176
176
|
k(n, t[s], W(o));
|
|
177
|
-
} else _(["style", "class", "srcset"], s) || (
|
|
177
|
+
} else _(["style", "class", "srcset"], s) || (C(n, "styles_attrs") || (n.styles_attrs = {}), v(s, "@") && (s = s.replace("@", "x-on:")), n.styles_attrs[`${s}`] = W(o));
|
|
178
178
|
}), delete n.class, n;
|
|
179
179
|
}, xt = (e, n = "styles") => {
|
|
180
180
|
if (!e.attributes) return { [n]: `${f},` };
|
|
181
|
-
const t =
|
|
181
|
+
const t = m(e.attributes, { key: "class" });
|
|
182
182
|
if (t) {
|
|
183
183
|
const a = t.value;
|
|
184
184
|
return { [n]: `${f},${a}` };
|
|
@@ -291,7 +291,7 @@ const Lt = Y((e) => {
|
|
|
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
|
|
294
|
+
return g(u(t, "content", "")) ? [] : n && ft(n.node, n.block) ? (k(n, "block.content", u(t, "content", "")), []) : { ...a, _type: "Text", content: u(t, "content", "") };
|
|
295
295
|
const s = u(t, "attributes", []), o = s.find(
|
|
296
296
|
(i) => i.key === "data-chai-richtext" || i.key === "chai-richtext"
|
|
297
297
|
), c = s.find(
|
|
@@ -313,7 +313,7 @@ const Lt = Y((e) => {
|
|
|
313
313
|
i && (a._name = i.value);
|
|
314
314
|
}
|
|
315
315
|
if (o)
|
|
316
|
-
return a.content = E(t.children),
|
|
316
|
+
return a.content = E(t.children), C(a, "styles_attrs.data-chai-richtext") && delete a.styles_attrs["data-chai-richtext"], C(a, "styles_attrs.chai-richtext") && delete a.styles_attrs["chai-richtext"], [a];
|
|
317
317
|
if (c) {
|
|
318
318
|
const i = [
|
|
319
319
|
"data-chai-lightbox",
|
|
@@ -334,19 +334,19 @@ const Lt = Y((e) => {
|
|
|
334
334
|
backdropColor: ((O = s.find((l) => l.key === "data-overlay")) == null ? void 0 : O.value) || "",
|
|
335
335
|
galleryName: ((j = s.find((l) => l.key === "data-gall")) == null ? void 0 : j.value) || ""
|
|
336
336
|
}, $(i, (l) => {
|
|
337
|
-
|
|
337
|
+
C(a, `styles_attrs.${l}`) && delete a.styles_attrs[l];
|
|
338
338
|
});
|
|
339
339
|
}
|
|
340
340
|
if (r && (delete a.styles_attrs, a.showDropdown = !1), h && delete a.styles_attrs, p) {
|
|
341
341
|
delete a.styles_attrs;
|
|
342
342
|
const i = V(t.children || [], (d) => (d == null ? void 0 : d.tagName) !== "span");
|
|
343
343
|
a.content = L(i);
|
|
344
|
-
const l =
|
|
344
|
+
const l = m(
|
|
345
345
|
t.children || [],
|
|
346
346
|
(d) => (d == null ? void 0 : d.tagName) === "span" && st(d.children || [], (y) => (y == null ? void 0 : y.tagName) === "svg")
|
|
347
347
|
);
|
|
348
348
|
if (l) {
|
|
349
|
-
const d =
|
|
349
|
+
const d = m(l.children || [], (y) => (y == null ? void 0 : y.tagName) === "svg");
|
|
350
350
|
if (d) {
|
|
351
351
|
a.icon = E([d]);
|
|
352
352
|
const { height: y, width: B } = kt(d, "16px", "16px");
|
|
@@ -360,13 +360,13 @@ const Lt = Y((e) => {
|
|
|
360
360
|
i === "checkbox" ? k(a, "_type", "Checkbox") : i === "radio" && k(a, "_type", "Radio");
|
|
361
361
|
} else if (t.tagName === "video" || t.tagName === "iframe") {
|
|
362
362
|
const i = E([t]);
|
|
363
|
-
return
|
|
363
|
+
return mt(i) && (k(a, "_type", "Video"), k(a, "url", gt(i)), k(a, "styles", `${f},`), k(a, "controls", { autoPlay: !1, muted: !0, loop: !1, controls: !1 })), a.content = i, [a];
|
|
364
364
|
} else if (t.tagName === "svg") {
|
|
365
|
-
const i = u(
|
|
365
|
+
const i = u(m(t.attributes, { key: "class" }), "value", ""), { height: l, width: d } = Z(i);
|
|
366
366
|
if (l && d)
|
|
367
367
|
a.styles = `${f}, ${D(`w-${d} h-${l}`, i)}`.trim(), a.height = l == null ? void 0 : l.replace("px", ""), a.width = d == null ? void 0 : d.replace("px", "");
|
|
368
368
|
else {
|
|
369
|
-
const y = (z =
|
|
369
|
+
const y = (z = m(t.attributes, { key: "height" })) == null ? void 0 : z.value, B = (F = m(t.attributes, { key: "width" })) == null ? void 0 : F.value;
|
|
370
370
|
y && B ? (a.styles = `${f}, ${D(`w-[${B}px] h-[${y}px]`, i)}`.trim(), a.height = y, a.width = B) : a.styles = `${f}, ${D("w-full h-full", i)}`.trim();
|
|
371
371
|
}
|
|
372
372
|
return t.attributes = V(t.attributes, (y) => !_(["style", "width", "height", "class"], y.key)), a.icon = E([t]), [a];
|
|
@@ -380,14 +380,14 @@ const Lt = Y((e) => {
|
|
|
380
380
|
}), kt = (e, n, t) => {
|
|
381
381
|
var p, h;
|
|
382
382
|
const a = u(e, "attributes", []), { height: s, width: o } = Z(
|
|
383
|
-
u(
|
|
383
|
+
u(m(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 c = (p =
|
|
390
|
+
const c = (p = m(a, { key: "height" })) == null ? void 0 : p.value, r = (h = m(a, { key: "width" })) == null ? void 0 : h.value;
|
|
391
391
|
return {
|
|
392
392
|
height: c ? `[${c}px]` : t,
|
|
393
393
|
width: r ? `[${r}px]` : n
|
|
@@ -401,7 +401,7 @@ const Lt = Y((e) => {
|
|
|
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
403
|
const n = dt(vt(e));
|
|
404
|
-
return
|
|
404
|
+
return g(e) ? [] : tt(G(n));
|
|
405
405
|
}, x = (e) => {
|
|
406
406
|
const n = ct(e);
|
|
407
407
|
return e.map((t) => {
|
|
@@ -469,7 +469,7 @@ if (import.meta.vitest) {
|
|
|
469
469
|
});
|
|
470
470
|
});
|
|
471
471
|
}
|
|
472
|
-
const
|
|
472
|
+
const b = (e, n, { index: t, key: a }) => {
|
|
473
473
|
if (T(e)) {
|
|
474
474
|
let s = e;
|
|
475
475
|
const o = /\{\{(.*?)\}\}/g, c = e.match(o);
|
|
@@ -477,28 +477,28 @@ const m = (e, n, { index: t, key: a }) => {
|
|
|
477
477
|
let p = r.slice(2, -2).trim(), h = a.slice(2, -2).trim();
|
|
478
478
|
t !== -1 && v(p, "$index.") ? p = `${h}.${t}.${p.slice(7)}` : t !== -1 && v(p, "$index") && (p = `${h}.${t}`);
|
|
479
479
|
const w = u(n, p);
|
|
480
|
-
w === void 0 ? s = s.replace(r, "") : s =
|
|
480
|
+
w === void 0 ? s = s.replace(r, "") : s = N(w) ? w : s.replace(r, w);
|
|
481
481
|
}), s;
|
|
482
482
|
}
|
|
483
|
-
if (
|
|
484
|
-
return e.map((s) =>
|
|
483
|
+
if (N(e))
|
|
484
|
+
return e.map((s) => b(s, n, { index: t, key: a }));
|
|
485
485
|
if (e && typeof e == "object") {
|
|
486
486
|
const s = {};
|
|
487
487
|
return $(A(e), (o) => {
|
|
488
|
-
!v(o, "_") && o !== "$repeaterItemsKey" ? s[o] =
|
|
488
|
+
!v(o, "_") && o !== "$repeaterItemsKey" ? s[o] = b(e[o], n, { index: t, key: a }) : s[o] = e[o];
|
|
489
489
|
}), s;
|
|
490
490
|
}
|
|
491
491
|
return e;
|
|
492
|
-
},
|
|
492
|
+
}, I = (e, n, { index: t, key: a }) => {
|
|
493
493
|
let s = S(e);
|
|
494
|
-
return s.repeaterItems && (s.$repeaterItemsKey = s.repeaterItems, v(s.repeaterItems, `{{${ut}`) && (s.$repeaterItemsKey = s.repeaterItems = `${s.repeaterItems.replace("}}", `/${s._id}}}`)}`)),
|
|
494
|
+
return s.repeaterItems && (s.$repeaterItemsKey = s.repeaterItems, v(s.repeaterItems, `{{${ut}`) && (s.$repeaterItemsKey = s.repeaterItems = `${s.repeaterItems.replace("}}", `/${s._id}}}`)}`), !g(s.repeaterItems) && s.pagination && (s.repeaterTotalItems = `${s.repeaterItems.replace("}}", `/${s._id}/totalItems}}`)}`)), b(s, n, { index: t, key: a });
|
|
495
495
|
};
|
|
496
496
|
import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
497
497
|
it("should handle string values with bindings", () => {
|
|
498
|
-
const t =
|
|
498
|
+
const t = b("Hello {{user.name}}", { user: { name: "John" } }, { index: -1, key: "" });
|
|
499
499
|
expect(t).toBe("Hello John");
|
|
500
500
|
}), it("should handle nested object properties", () => {
|
|
501
|
-
const t =
|
|
501
|
+
const t = b({
|
|
502
502
|
name: "John",
|
|
503
503
|
address: {
|
|
504
504
|
city: "{{user.city}}",
|
|
@@ -513,19 +513,19 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
|
513
513
|
}
|
|
514
514
|
});
|
|
515
515
|
}), it("should handle arrays of values", () => {
|
|
516
|
-
const t =
|
|
516
|
+
const t = b(["Hello {{user.name}}", "Welcome {{user.role}}"], { user: { name: "John", role: "Admin" } }, { index: -1, key: "" });
|
|
517
517
|
expect(t).toEqual(["Hello John", "Welcome Admin"]);
|
|
518
518
|
}), it("should handle $index binding in repeater context", () => {
|
|
519
|
-
const t =
|
|
519
|
+
const t = b("Item {{$index}}", { items: ["a", "b", "c"] }, { index: 1, key: "{{items}}" });
|
|
520
520
|
expect(t).toBe("Item b");
|
|
521
521
|
}), it("should handle $index binding with dot notation", () => {
|
|
522
|
-
const t =
|
|
522
|
+
const t = b("Item {{$index.value}}", { items: [{ value: "apple" }, { value: "banana" }, { value: "cherry" }] }, { index: 1, key: "{{items}}" });
|
|
523
523
|
expect(t).toBe("Item banana");
|
|
524
524
|
}), it("should return an empty string for non-existing bindings", () => {
|
|
525
|
-
const t =
|
|
525
|
+
const t = b("Hello {{user.nonexistent}}", { user: { name: "John" } }, { index: -1, key: "" });
|
|
526
526
|
expect(t).toBe("Hello ");
|
|
527
527
|
}), it("should preserve private properties starting with _", () => {
|
|
528
|
-
const n =
|
|
528
|
+
const n = b({
|
|
529
529
|
name: "John",
|
|
530
530
|
_private: "secret"
|
|
531
531
|
}, {}, { index: -1, key: "" });
|
|
@@ -536,7 +536,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
|
536
536
|
});
|
|
537
537
|
}), describe("applyBindingToBlockProps", () => {
|
|
538
538
|
it("should handle basic block with bindings", () => {
|
|
539
|
-
const t =
|
|
539
|
+
const t = I({
|
|
540
540
|
_id: "test-block",
|
|
541
541
|
_type: "text",
|
|
542
542
|
type: "text",
|
|
@@ -555,7 +555,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
|
555
555
|
}
|
|
556
556
|
});
|
|
557
557
|
}), it("should handle repeaterItems and repeaterItemsBinding", () => {
|
|
558
|
-
const t =
|
|
558
|
+
const t = I({
|
|
559
559
|
_id: "test-block",
|
|
560
560
|
_type: "repeater",
|
|
561
561
|
type: "repeater",
|
|
@@ -571,7 +571,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
|
571
571
|
items: ["a", "b", "c"]
|
|
572
572
|
});
|
|
573
573
|
}), it("should handle nested blocks with bindings", () => {
|
|
574
|
-
const t =
|
|
574
|
+
const t = I({
|
|
575
575
|
_id: "test-block",
|
|
576
576
|
_type: "container",
|
|
577
577
|
type: "container",
|
|
@@ -604,7 +604,7 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
|
604
604
|
]
|
|
605
605
|
});
|
|
606
606
|
}), it("should handle arrays of blocks", () => {
|
|
607
|
-
const t =
|
|
607
|
+
const t = I({
|
|
608
608
|
_id: "test-block",
|
|
609
609
|
_type: "list",
|
|
610
610
|
type: "list",
|
|
@@ -626,10 +626,10 @@ import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
|
626
626
|
}));
|
|
627
627
|
export {
|
|
628
628
|
ut as C,
|
|
629
|
-
|
|
629
|
+
Ct as R,
|
|
630
630
|
f as S,
|
|
631
|
-
|
|
632
|
-
|
|
631
|
+
I as a,
|
|
632
|
+
Nt as b,
|
|
633
633
|
Lt as c,
|
|
634
634
|
St as d,
|
|
635
635
|
x as e,
|
|
@@ -637,5 +637,5 @@ export {
|
|
|
637
637
|
Dt as g,
|
|
638
638
|
Rt as h,
|
|
639
639
|
K as i,
|
|
640
|
-
|
|
640
|
+
It as j
|
|
641
641
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const j=require("@chaibuilder/runtime"),t=require("lodash-es"),q=require("tailwind-merge"),b=require("./common-functions-BZmyleS1.cjs"),x=require("himalaya"),y="#styles:",O="__ADD_BLOCK_INTERNAL_ROOT",V="@",A="#",R=e=>{if(e=e.replace(y,""),!e)return{baseClasses:"",classes:""};const i=e.split(/,(?![^\[]*\])/);if(i.length===1)return{baseClasses:"",classes:i[0].trim()};const[n,...s]=i;return{baseClasses:n.trim(),classes:s.join(",").trim().replace(/ +(?= )/g,"")}};function W(e,i,n){const s=t.get(n,"i18nProps",[]);if(t.isEmpty(i)||t.isEmpty(s))return e;const a=t.cloneDeep(e);return t.forEach(t.keys(a),o=>{if(t.includes(s,o)&&!t.isEmpty(i)){const l=t.get(a,o),r=t.get(a,`${o}-${i}`,"");t.isString(l)?a[o]=t.isString(r)&&!t.isEmpty(r.trim())&&r.trimStart()||l:a[o]=t.isEmpty(r)?l:r}}),a}const F=t.memoize(e=>{const{baseClasses:i,classes:n}=R(e);return q.twMerge(i,n)});function z(e,i){return t.get(e,`${i}_attrs`,{})}function J(e,i=!0){const n={};return Object.keys(e).forEach(s=>{if(t.isString(e[s])&&e[s].startsWith(y)){const a=F(e[s]),o=z(e,s);n[s]={...!t.isEmpty(a)&&{className:a},...o,...i?{"data-style-prop":s,"data-block-parent":e._id,"data-style-id":`${s}-${e._id}`}:{}}}}),n}const Y=t.memoize(e=>{const i=j.getRegisteredChaiBlock(e),n=t.get(i,"schema.properties",{});return Object.fromEntries(Object.entries(n).filter(([,s])=>t.get(s,"runtime",!1)))}),K=(e,i)=>{if(!t.isArray(e))return e;let n=e,s;return typeof i.limit=="number"&&i.limit>0&&(s=i.limit),s!==void 0&&(n=n.slice(0,s)),n},U=(e,i)=>{const n=t.cloneDeep(e);return t.forEach(t.keys(n),s=>{if(t.isString(n[s])&&!t.startsWith(s,"_")){let a=n[s];s==="repeaterItems"&&(n.repeaterItemsBinding=a);const o=/\{\{(.*?)\}\}/g,l=a.match(o);l&&l.forEach(r=>{let u=r.slice(2,-2);const g=t.get(i,u,r);a=t.isArray(g)?g:a.replace(r,g)}),n[s]=a}}),n},X=e=>{const i=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,n=/(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;return i.test(e)||n.test(e)},Z=e=>{if(t.isEmpty(e))return e;const i=/<video[^>]+src=['"]([^'">]+)['"]/,n=/<iframe[^>]+src=['"]([^'">]+)['"]/,s=e.match(i),a=e.match(n),o=s?s[1]:a?a[1]:null,l=/(?: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/;return o&&(l.test(o)||r.test(o))?o:e},P=["chai-name","data-chai-name"],G={img:{alt:"alt",width:"width",height:"height",src:"image"},video:{src:"url",autoplay:"controls.autoPlay",muted:"controls.muted",loop:"controls.loop",controls:"controls.widgets"},a:{href:"link.href",target:"link.target",type:""},input:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},textarea:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},select:{placeholder:"placeholder",required:"required",multiple:"multiple",name:"fieldName"},form:{action:"action"}},Q=(e,i)=>e.children.length===1&&t.includes(["Heading","Paragraph","Span","ListItem","Button","Label","TableCell","Link","RichText"],i._type),_=e=>e.map(i=>i.type==="text"?t.get(i,"content",""):t.isEmpty(i.children)?"":_(i.children)).join(""),N=e=>e===null?"":e,M=e=>{const i=t.compact(t.map(e.split(/\s+/),t.trim)),n=t.find(i,r=>/^w-/.test(r)),s=t.find(i,r=>/^h-/.test(r));if(!s||!n)return{height:"",width:""};const a=r=>{if(!r)return;const u=r.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);if(!u)return;if(u[1])return u[1];const g=u[2];return/^\d+(\.\d+)?$/.test(g)?`${Number(g)*4}px`:g==="auto"||t.includes(g,"%")?g:"16px"},o=a(n),l=a(s);return{width:t.includes(o,"px")?o:"16px",height:t.includes(l,"px")?l:"16px"}},D=e=>{if(e.tagName==="svg")return{};const i={},n=G[e.tagName]||{},s=e.attributes;return t.forEach(s,({key:a,value:o})=>{if(!t.includes(P,a))if(n[a]){if(e.tagName==="img"&&a==="src"&&!o.startsWith("http")){const l=t.find(e.attributes,{key:"width"}),r=t.find(e.attributes,{key:"height"});l&&r?o=`https://via.placeholder.com/${l==null?void 0:l.value}x${r==null?void 0:r.value}`:o="https://via.placeholder.com/150x150"}t.set(i,n[a],N(o))}else t.includes(["style","class","srcset"],a)||(t.has(i,"styles_attrs")||(i.styles_attrs={}),t.startsWith(a,"@")&&(a=a.replace("@","x-on:")),i.styles_attrs[`${a}`]=N(o))}),delete i.class,i},tt=(e,i="styles")=>{if(!e.attributes)return{[i]:`${y},`};const n=t.find(e.attributes,{key:"class"});if(n){const s=n.value;return{[i]:`${y},${s}`}}return{[i]:`${y},`}},et=e=>{const i=t.get(e,"attributes",[]),n=i.find(r=>r.key==="data-chai-richtext"||r.key==="chai-richtext"),s=i.find(r=>r.key==="data-chai-lightbox"||r.key==="chai-lightbox"),a=i.find(r=>r.key==="data-chai-dropdown"||r.key==="chai-dropdown"),o=i.find(r=>r.key==="data-chai-dropdown-button"||r.key==="chai-dropdown-button"),l=i.find(r=>r.key==="data-chai-dropdown-content"||r.key==="chai-dropdown-content");if(a)return{_type:"Dropdown"};if(o)return{_type:"DropdownButton"};if(l)return{_type:"DropdownContent"};if(n)return{_type:"RichText"};if(s)return{_type:"LightBoxLink"};switch(e.tagName){case"img":return{_type:"Image"};case"input":return{_type:"Input",showLabel:!1};case"hr":return{_type:"Divider"};case"br":return{_type:"LineBreak"};case"textarea":return{_type:"TextArea",showLabel:!1};case"audio":return{_type:"Audio"};case"canvas":return{_type:"Canvas"};case"video":case"iframe":return{_type:"CustomHTML"};case"svg":return{_type:"Icon"};case"select":return{_type:"Select",options:[]};case"option":return{_type:"Option"};case"ul":case"ol":case"dl":return{_type:"List",tag:e.tagName,_listType:e.tagName==="ol"?"list-decimal":"list-none"};case"li":case"dt":return{_type:"ListItem",tag:e.tagName};case"span":case"figcaption":case"legend":return{_type:"Span",tag:e.tagName};case"p":return{_type:"Paragraph",content:""};case"a":return{_type:"Link"};case"form":return{_type:"Form"};case"label":return{_type:"Label"};case"button":return{_type:"Button"};case"code":return{_type:"Box",_name:"Code"};case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":return{_type:"Heading",tag:e.tagName};case"table":return{_type:"Table"};case"tr":return{_type:"TableRow"};case"td":case"th":return{_type:"TableCell",tag:e.tagName};case"thead":return{_type:"TableHead"};case"tbody":return{_type:"TableBody"};case"tfoot":return{_type:"TableFooter"};default:{const r=t.get(e,"children",[]).length>0?"Box":"EmptyBox";return{_type:r,tag:e.tagName,_name:r=="EmptyBox"||e.tagName==="div"?r:t.capitalize(e.tagName)}}}},H=(e,i=null)=>t.flatMapDeep(e,n=>{var T,B,w,E,v,$,C,I,S,L;if(n.type==="comment")return[];let s={_id:b.generateUUID()};if(i&&(s._parent=i.block._id),n.type==="text")return t.isEmpty(t.get(n,"content",""))?[]:i&&Q(i.node,i.block)?(t.set(i,"block.content",t.get(n,"content","")),[]):{...s,_type:"Text",content:t.get(n,"content","")};const a=t.get(n,"attributes",[]),o=a.find(c=>c.key==="data-chai-richtext"||c.key==="chai-richtext"),l=a.find(c=>c.key==="data-chai-lightbox"||c.key==="chai-lightbox"),r=a.find(c=>c.key==="data-chai-dropdown"||c.key==="chai-dropdown"),u=a.find(c=>c.key==="data-chai-dropdown-button"||c.key==="chai-dropdown-button"),g=a.find(c=>c.key==="data-chai-dropdown-content"||c.key==="chai-dropdown-content");if(s={...s,...et(n),...D(n),...tt(n)},n.attributes){const c=n.attributes.find(p=>t.includes(P,p.key));c&&(s._name=c.value)}if(o)return s.content=x.stringify(n.children),t.has(s,"styles_attrs.data-chai-richtext")&&delete s.styles_attrs["data-chai-richtext"],t.has(s,"styles_attrs.chai-richtext")&&delete s.styles_attrs["chai-richtext"],[s];if(l){const c=["data-chai-lightbox","chai-lightbox","data-vbtype","data-autoplay","data-maxwidth","data-overlay","data-gall","href"];s={...s,href:((T=a.find(p=>p.key==="href"))==null?void 0:T.value)||"",hrefType:((B=a.find(p=>p.key==="data-vbtype"))==null?void 0:B.value)||"video",autoplay:((w=a.find(p=>p.key==="data-autoplay"))==null?void 0:w.value)==="true"?"true":"false",maxWidth:((v=(E=a.find(p=>p.key==="data-maxwidth"))==null?void 0:E.value)==null?void 0:v.replace("px",""))||"",backdropColor:(($=a.find(p=>p.key==="data-overlay"))==null?void 0:$.value)||"",galleryName:((C=a.find(p=>p.key==="data-gall"))==null?void 0:C.value)||""},t.forEach(c,p=>{t.has(s,`styles_attrs.${p}`)&&delete s.styles_attrs[p]})}if(r&&(delete s.styles_attrs,s.showDropdown=!1),g&&delete s.styles_attrs,u){delete s.styles_attrs;const c=t.filter(n.children||[],d=>(d==null?void 0:d.tagName)!=="span");s.content=_(c);const p=t.find(n.children||[],d=>(d==null?void 0:d.tagName)==="span"&&t.some(d.children||[],h=>(h==null?void 0:h.tagName)==="svg"));if(p){const d=t.find(p.children||[],h=>(h==null?void 0:h.tagName)==="svg");if(d){s.icon=x.stringify([d]);const{height:h,width:f}=st(d,"16px","16px");s.iconHeight=h,s.iconWidth=f}}return[s]}if(s._type==="Input"){const c=s.inputType||"text";c==="checkbox"?t.set(s,"_type","Checkbox"):c==="radio"&&t.set(s,"_type","Radio")}else if(n.tagName==="video"||n.tagName==="iframe"){const c=x.stringify([n]);return X(c)&&(t.set(s,"_type","Video"),t.set(s,"url",Z(c)),t.set(s,"styles",`${y},`),t.set(s,"controls",{autoPlay:!1,muted:!0,loop:!1,controls:!1})),s.content=c,[s]}else if(n.tagName==="svg"){const c=t.get(t.find(n.attributes,{key:"class"}),"value",""),{height:p,width:d}=M(c);if(p&&d)s.styles=`${y}, ${b.cn(`w-${d} h-${p}`,c)}`.trim(),s.height=p==null?void 0:p.replace("px",""),s.width=d==null?void 0:d.replace("px","");else{const h=(I=t.find(n.attributes,{key:"height"}))==null?void 0:I.value,f=(S=t.find(n.attributes,{key:"width"}))==null?void 0:S.value;h&&f?(s.styles=`${y}, ${b.cn(`w-[${f}px] h-[${h}px]`,c)}`.trim(),s.height=h,s.width=f):s.styles=`${y}, ${b.cn("w-full h-full",c)}`.trim()}return n.attributes=t.filter(n.attributes,h=>!t.includes(["style","width","height","class"],h.key)),s.icon=x.stringify([n]),[s]}else if(n.tagName=="option"&&i&&((L=i.block)==null?void 0:L._type)==="Select")return i.block.options.push({label:_(n.children),...D(n)}),[];const m=H(n.children,{block:s,node:n});return[s,...m]}),st=(e,i,n)=>{var u,g;const s=t.get(e,"attributes",[]),{height:a,width:o}=M(t.get(t.find(s,{key:"class"}),"value",""));if(a&&o)return{height:`[${a}px]`,width:`[${o}px]`};const l=(u=t.find(s,{key:"height"}))==null?void 0:u.value,r=(g=t.find(s,{key:"width"}))==null?void 0:g.value;return{height:l?`[${l}px]`:n,width:r?`[${r}px]`:i}},nt=e=>{e=e.replace(/(\w+)=\\?"(.*?)\\?"/g,(s,a,o)=>{let l=o.replace(/\\"/g,'"');return l=l.replace(/{([^}]+)}/g,r=>r.replace(/"/g,'\\"')),`${a}="${l.replace(/\\"/g,'"')}"`}),e=e.replace(/\\n/g,"").replace(/\\\\/g,"").replace(/\\([/<>])/g,"$1").replace(/\\./g,"").replace(/[\n\r\t\f\v]/g,""),e=e.replace(/\$name="[^"]*"/g,"");const i=e.match(/<body[^>]*>[\s\S]*?<\/body>/);return(i&&i.length>0?i[0].replace(/<body/,"<div").replace(/<\/body>/,"</div>"):e).replace(/\s+/g," ").replaceAll("> <","><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").trim()},at=e=>{const i=x.parse(nt(e));return t.isEmpty(e)?[]:t.flatten(H(i))},rt=e=>{const i=t.last(e);return e.map(n=>{const s=Object.keys(n);for(let a=0;a<s.length;a++)if(t.isString(n[s[a]])&&t.startsWith(s[a],"content")){const o=n===i?"":" ";n[s[a]]=`${n[s[a]].trim()}${o}`}return n})},k=(e,i,{index:n,key:s})=>{if(t.isString(e)){let a=e;const o=/\{\{(.*?)\}\}/g,l=e.match(o);return l&&l.forEach(r=>{let u=r.slice(2,-2).trim(),g=s.slice(2,-2).trim();n!==-1&&t.startsWith(u,"$index.")?u=`${g}.${n}.${u.slice(7)}`:n!==-1&&t.startsWith(u,"$index")&&(u=`${g}.${n}`);const m=t.get(i,u);m===void 0?a=a.replace(r,""):a=t.isArray(m)?m:a.replace(r,m)}),a}if(t.isArray(e))return e.map(a=>k(a,i,{index:n,key:s}));if(e&&typeof e=="object"){const a={};return t.forEach(t.keys(e),o=>{!t.startsWith(o,"_")&&o!=="$repeaterItemsKey"?a[o]=k(e[o],i,{index:n,key:s}):a[o]=e[o]}),a}return e},ot=(e,i,{index:n,key:s})=>{let a=t.cloneDeep(e);return a.repeaterItems&&(a.$repeaterItemsKey=a.repeaterItems,t.startsWith(a.repeaterItems,`{{${A}`)&&(a.$repeaterItemsKey=a.repeaterItems=`${a.repeaterItems.replace("}}",`/${a._id}}}`)}`)),k(a,i,{index:n,key:s})};exports.COLLECTION_PREFIX=A;exports.REPEATER_PREFIX=V;exports.ROOT_TEMP_KEY=O;exports.STYLES_KEY=y;exports.adjustSpacingInContentBlocks=rt;exports.applyBindingToBlockProps=ot;exports.applyChaiDataBinding=U;exports.applyLanguage=W;exports.applyLimit=K;exports.getBlockRuntimeProps=Y;exports.getBlockTagAttributes=J;exports.getBlocksFromHTML=at;exports.getSplitChaiClasses=R;
|
|
1
|
+
"use strict";const j=require("@chaibuilder/runtime"),t=require("lodash-es"),q=require("tailwind-merge"),b=require("./common-functions-BZmyleS1.cjs"),x=require("himalaya"),h="#styles:",O="__ADD_BLOCK_INTERNAL_ROOT",V="@",A="#",R=e=>{if(e=e.replace(h,""),!e)return{baseClasses:"",classes:""};const i=e.split(/,(?![^\[]*\])/);if(i.length===1)return{baseClasses:"",classes:i[0].trim()};const[n,...s]=i;return{baseClasses:n.trim(),classes:s.join(",").trim().replace(/ +(?= )/g,"")}};function W(e,i,n){const s=t.get(n,"i18nProps",[]);if(t.isEmpty(i)||t.isEmpty(s))return e;const a=t.cloneDeep(e);return t.forEach(t.keys(a),o=>{if(t.includes(s,o)&&!t.isEmpty(i)){const l=t.get(a,o),r=t.get(a,`${o}-${i}`,"");t.isString(l)?a[o]=t.isString(r)&&!t.isEmpty(r.trim())&&r.trimStart()||l:a[o]=t.isEmpty(r)?l:r}}),a}const F=t.memoize(e=>{const{baseClasses:i,classes:n}=R(e);return q.twMerge(i,n)});function z(e,i){return t.get(e,`${i}_attrs`,{})}function J(e,i=!0){const n={};return Object.keys(e).forEach(s=>{if(t.isString(e[s])&&e[s].startsWith(h)){const a=F(e[s]),o=z(e,s);n[s]={...!t.isEmpty(a)&&{className:a},...o,...i?{"data-style-prop":s,"data-block-parent":e._id,"data-style-id":`${s}-${e._id}`}:{}}}}),n}const Y=t.memoize(e=>{const i=j.getRegisteredChaiBlock(e),n=t.get(i,"schema.properties",{});return Object.fromEntries(Object.entries(n).filter(([,s])=>t.get(s,"runtime",!1)))}),K=(e,i)=>{if(!t.isArray(e))return e;let n=e,s;return typeof i.limit=="number"&&i.limit>0&&(s=i.limit),s!==void 0&&(n=n.slice(0,s)),n},U=(e,i)=>{const n=t.cloneDeep(e);return t.forEach(t.keys(n),s=>{if(t.isString(n[s])&&!t.startsWith(s,"_")){let a=n[s];s==="repeaterItems"&&(n.repeaterItemsBinding=a);const o=/\{\{(.*?)\}\}/g,l=a.match(o);l&&l.forEach(r=>{let u=r.slice(2,-2);const g=t.get(i,u,r);a=t.isArray(g)?g:a.replace(r,g)}),n[s]=a}}),n},X=e=>{const i=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,n=/(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;return i.test(e)||n.test(e)},Z=e=>{if(t.isEmpty(e))return e;const i=/<video[^>]+src=['"]([^'">]+)['"]/,n=/<iframe[^>]+src=['"]([^'">]+)['"]/,s=e.match(i),a=e.match(n),o=s?s[1]:a?a[1]:null,l=/(?: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/;return o&&(l.test(o)||r.test(o))?o:e},P=["chai-name","data-chai-name"],G={img:{alt:"alt",width:"width",height:"height",src:"image"},video:{src:"url",autoplay:"controls.autoPlay",muted:"controls.muted",loop:"controls.loop",controls:"controls.widgets"},a:{href:"link.href",target:"link.target",type:""},input:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},textarea:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},select:{placeholder:"placeholder",required:"required",multiple:"multiple",name:"fieldName"},form:{action:"action"}},Q=(e,i)=>e.children.length===1&&t.includes(["Heading","Paragraph","Span","ListItem","Button","Label","TableCell","Link","RichText"],i._type),_=e=>e.map(i=>i.type==="text"?t.get(i,"content",""):t.isEmpty(i.children)?"":_(i.children)).join(""),N=e=>e===null?"":e,M=e=>{const i=t.compact(t.map(e.split(/\s+/),t.trim)),n=t.find(i,r=>/^w-/.test(r)),s=t.find(i,r=>/^h-/.test(r));if(!s||!n)return{height:"",width:""};const a=r=>{if(!r)return;const u=r.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);if(!u)return;if(u[1])return u[1];const g=u[2];return/^\d+(\.\d+)?$/.test(g)?`${Number(g)*4}px`:g==="auto"||t.includes(g,"%")?g:"16px"},o=a(n),l=a(s);return{width:t.includes(o,"px")?o:"16px",height:t.includes(l,"px")?l:"16px"}},D=e=>{if(e.tagName==="svg")return{};const i={},n=G[e.tagName]||{},s=e.attributes;return t.forEach(s,({key:a,value:o})=>{if(!t.includes(P,a))if(n[a]){if(e.tagName==="img"&&a==="src"&&!o.startsWith("http")){const l=t.find(e.attributes,{key:"width"}),r=t.find(e.attributes,{key:"height"});l&&r?o=`https://via.placeholder.com/${l==null?void 0:l.value}x${r==null?void 0:r.value}`:o="https://via.placeholder.com/150x150"}t.set(i,n[a],N(o))}else t.includes(["style","class","srcset"],a)||(t.has(i,"styles_attrs")||(i.styles_attrs={}),t.startsWith(a,"@")&&(a=a.replace("@","x-on:")),i.styles_attrs[`${a}`]=N(o))}),delete i.class,i},tt=(e,i="styles")=>{if(!e.attributes)return{[i]:`${h},`};const n=t.find(e.attributes,{key:"class"});if(n){const s=n.value;return{[i]:`${h},${s}`}}return{[i]:`${h},`}},et=e=>{const i=t.get(e,"attributes",[]),n=i.find(r=>r.key==="data-chai-richtext"||r.key==="chai-richtext"),s=i.find(r=>r.key==="data-chai-lightbox"||r.key==="chai-lightbox"),a=i.find(r=>r.key==="data-chai-dropdown"||r.key==="chai-dropdown"),o=i.find(r=>r.key==="data-chai-dropdown-button"||r.key==="chai-dropdown-button"),l=i.find(r=>r.key==="data-chai-dropdown-content"||r.key==="chai-dropdown-content");if(a)return{_type:"Dropdown"};if(o)return{_type:"DropdownButton"};if(l)return{_type:"DropdownContent"};if(n)return{_type:"RichText"};if(s)return{_type:"LightBoxLink"};switch(e.tagName){case"img":return{_type:"Image"};case"input":return{_type:"Input",showLabel:!1};case"hr":return{_type:"Divider"};case"br":return{_type:"LineBreak"};case"textarea":return{_type:"TextArea",showLabel:!1};case"audio":return{_type:"Audio"};case"canvas":return{_type:"Canvas"};case"video":case"iframe":return{_type:"CustomHTML"};case"svg":return{_type:"Icon"};case"select":return{_type:"Select",options:[]};case"option":return{_type:"Option"};case"ul":case"ol":case"dl":return{_type:"List",tag:e.tagName,_listType:e.tagName==="ol"?"list-decimal":"list-none"};case"li":case"dt":return{_type:"ListItem",tag:e.tagName};case"span":case"figcaption":case"legend":return{_type:"Span",tag:e.tagName};case"p":return{_type:"Paragraph",content:""};case"a":return{_type:"Link"};case"form":return{_type:"Form"};case"label":return{_type:"Label"};case"button":return{_type:"Button"};case"code":return{_type:"Box",_name:"Code"};case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":return{_type:"Heading",tag:e.tagName};case"table":return{_type:"Table"};case"tr":return{_type:"TableRow"};case"td":case"th":return{_type:"TableCell",tag:e.tagName};case"thead":return{_type:"TableHead"};case"tbody":return{_type:"TableBody"};case"tfoot":return{_type:"TableFooter"};default:{const r=t.get(e,"children",[]).length>0?"Box":"EmptyBox";return{_type:r,tag:e.tagName,_name:r=="EmptyBox"||e.tagName==="div"?r:t.capitalize(e.tagName)}}}},H=(e,i=null)=>t.flatMapDeep(e,n=>{var T,B,E,w,v,$,C,I,S,L;if(n.type==="comment")return[];let s={_id:b.generateUUID()};if(i&&(s._parent=i.block._id),n.type==="text")return t.isEmpty(t.get(n,"content",""))?[]:i&&Q(i.node,i.block)?(t.set(i,"block.content",t.get(n,"content","")),[]):{...s,_type:"Text",content:t.get(n,"content","")};const a=t.get(n,"attributes",[]),o=a.find(c=>c.key==="data-chai-richtext"||c.key==="chai-richtext"),l=a.find(c=>c.key==="data-chai-lightbox"||c.key==="chai-lightbox"),r=a.find(c=>c.key==="data-chai-dropdown"||c.key==="chai-dropdown"),u=a.find(c=>c.key==="data-chai-dropdown-button"||c.key==="chai-dropdown-button"),g=a.find(c=>c.key==="data-chai-dropdown-content"||c.key==="chai-dropdown-content");if(s={...s,...et(n),...D(n),...tt(n)},n.attributes){const c=n.attributes.find(p=>t.includes(P,p.key));c&&(s._name=c.value)}if(o)return s.content=x.stringify(n.children),t.has(s,"styles_attrs.data-chai-richtext")&&delete s.styles_attrs["data-chai-richtext"],t.has(s,"styles_attrs.chai-richtext")&&delete s.styles_attrs["chai-richtext"],[s];if(l){const c=["data-chai-lightbox","chai-lightbox","data-vbtype","data-autoplay","data-maxwidth","data-overlay","data-gall","href"];s={...s,href:((T=a.find(p=>p.key==="href"))==null?void 0:T.value)||"",hrefType:((B=a.find(p=>p.key==="data-vbtype"))==null?void 0:B.value)||"video",autoplay:((E=a.find(p=>p.key==="data-autoplay"))==null?void 0:E.value)==="true"?"true":"false",maxWidth:((v=(w=a.find(p=>p.key==="data-maxwidth"))==null?void 0:w.value)==null?void 0:v.replace("px",""))||"",backdropColor:(($=a.find(p=>p.key==="data-overlay"))==null?void 0:$.value)||"",galleryName:((C=a.find(p=>p.key==="data-gall"))==null?void 0:C.value)||""},t.forEach(c,p=>{t.has(s,`styles_attrs.${p}`)&&delete s.styles_attrs[p]})}if(r&&(delete s.styles_attrs,s.showDropdown=!1),g&&delete s.styles_attrs,u){delete s.styles_attrs;const c=t.filter(n.children||[],d=>(d==null?void 0:d.tagName)!=="span");s.content=_(c);const p=t.find(n.children||[],d=>(d==null?void 0:d.tagName)==="span"&&t.some(d.children||[],y=>(y==null?void 0:y.tagName)==="svg"));if(p){const d=t.find(p.children||[],y=>(y==null?void 0:y.tagName)==="svg");if(d){s.icon=x.stringify([d]);const{height:y,width:f}=st(d,"16px","16px");s.iconHeight=y,s.iconWidth=f}}return[s]}if(s._type==="Input"){const c=s.inputType||"text";c==="checkbox"?t.set(s,"_type","Checkbox"):c==="radio"&&t.set(s,"_type","Radio")}else if(n.tagName==="video"||n.tagName==="iframe"){const c=x.stringify([n]);return X(c)&&(t.set(s,"_type","Video"),t.set(s,"url",Z(c)),t.set(s,"styles",`${h},`),t.set(s,"controls",{autoPlay:!1,muted:!0,loop:!1,controls:!1})),s.content=c,[s]}else if(n.tagName==="svg"){const c=t.get(t.find(n.attributes,{key:"class"}),"value",""),{height:p,width:d}=M(c);if(p&&d)s.styles=`${h}, ${b.cn(`w-${d} h-${p}`,c)}`.trim(),s.height=p==null?void 0:p.replace("px",""),s.width=d==null?void 0:d.replace("px","");else{const y=(I=t.find(n.attributes,{key:"height"}))==null?void 0:I.value,f=(S=t.find(n.attributes,{key:"width"}))==null?void 0:S.value;y&&f?(s.styles=`${h}, ${b.cn(`w-[${f}px] h-[${y}px]`,c)}`.trim(),s.height=y,s.width=f):s.styles=`${h}, ${b.cn("w-full h-full",c)}`.trim()}return n.attributes=t.filter(n.attributes,y=>!t.includes(["style","width","height","class"],y.key)),s.icon=x.stringify([n]),[s]}else if(n.tagName=="option"&&i&&((L=i.block)==null?void 0:L._type)==="Select")return i.block.options.push({label:_(n.children),...D(n)}),[];const m=H(n.children,{block:s,node:n});return[s,...m]}),st=(e,i,n)=>{var u,g;const s=t.get(e,"attributes",[]),{height:a,width:o}=M(t.get(t.find(s,{key:"class"}),"value",""));if(a&&o)return{height:`[${a}px]`,width:`[${o}px]`};const l=(u=t.find(s,{key:"height"}))==null?void 0:u.value,r=(g=t.find(s,{key:"width"}))==null?void 0:g.value;return{height:l?`[${l}px]`:n,width:r?`[${r}px]`:i}},nt=e=>{e=e.replace(/(\w+)=\\?"(.*?)\\?"/g,(s,a,o)=>{let l=o.replace(/\\"/g,'"');return l=l.replace(/{([^}]+)}/g,r=>r.replace(/"/g,'\\"')),`${a}="${l.replace(/\\"/g,'"')}"`}),e=e.replace(/\\n/g,"").replace(/\\\\/g,"").replace(/\\([/<>])/g,"$1").replace(/\\./g,"").replace(/[\n\r\t\f\v]/g,""),e=e.replace(/\$name="[^"]*"/g,"");const i=e.match(/<body[^>]*>[\s\S]*?<\/body>/);return(i&&i.length>0?i[0].replace(/<body/,"<div").replace(/<\/body>/,"</div>"):e).replace(/\s+/g," ").replaceAll("> <","><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").trim()},at=e=>{const i=x.parse(nt(e));return t.isEmpty(e)?[]:t.flatten(H(i))},rt=e=>{const i=t.last(e);return e.map(n=>{const s=Object.keys(n);for(let a=0;a<s.length;a++)if(t.isString(n[s[a]])&&t.startsWith(s[a],"content")){const o=n===i?"":" ";n[s[a]]=`${n[s[a]].trim()}${o}`}return n})},k=(e,i,{index:n,key:s})=>{if(t.isString(e)){let a=e;const o=/\{\{(.*?)\}\}/g,l=e.match(o);return l&&l.forEach(r=>{let u=r.slice(2,-2).trim(),g=s.slice(2,-2).trim();n!==-1&&t.startsWith(u,"$index.")?u=`${g}.${n}.${u.slice(7)}`:n!==-1&&t.startsWith(u,"$index")&&(u=`${g}.${n}`);const m=t.get(i,u);m===void 0?a=a.replace(r,""):a=t.isArray(m)?m:a.replace(r,m)}),a}if(t.isArray(e))return e.map(a=>k(a,i,{index:n,key:s}));if(e&&typeof e=="object"){const a={};return t.forEach(t.keys(e),o=>{!t.startsWith(o,"_")&&o!=="$repeaterItemsKey"?a[o]=k(e[o],i,{index:n,key:s}):a[o]=e[o]}),a}return e},ot=(e,i,{index:n,key:s})=>{let a=t.cloneDeep(e);return a.repeaterItems&&(a.$repeaterItemsKey=a.repeaterItems,t.startsWith(a.repeaterItems,`{{${A}`)&&(a.$repeaterItemsKey=a.repeaterItems=`${a.repeaterItems.replace("}}",`/${a._id}}}`)}`),!t.isEmpty(a.repeaterItems)&&a.pagination&&(a.repeaterTotalItems=`${a.repeaterItems.replace("}}",`/${a._id}/totalItems}}`)}`)),k(a,i,{index:n,key:s})};exports.COLLECTION_PREFIX=A;exports.REPEATER_PREFIX=V;exports.ROOT_TEMP_KEY=O;exports.STYLES_KEY=h;exports.adjustSpacingInContentBlocks=rt;exports.applyBindingToBlockProps=ot;exports.applyChaiDataBinding=U;exports.applyLanguage=W;exports.applyLimit=K;exports.getBlockRuntimeProps=Y;exports.getBlockTagAttributes=J;exports.getBlocksFromHTML=at;exports.getSplitChaiClasses=R;
|