@chaibuilder/sdk 4.0.0-beta.1 → 4.0.0-beta.3
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 +27 -20
- package/dist/2SSKDMRQ-BnsZi3K3.cjs +1 -0
- package/dist/2SSKDMRQ-CnSDkQcy.js +42 -0
- package/dist/AP7HFJJL-B31839PG.cjs +1228 -0
- package/dist/AP7HFJJL-CymCmW14.js +9214 -0
- package/dist/IconPicker-B1rWC-Ex.js +59 -0
- package/dist/IconPicker-DREyo007.cjs +1 -0
- package/dist/WDYDFRGG-BUVnbAci.js +33 -0
- package/dist/WDYDFRGG-BxhOCHc3.cjs +1 -0
- package/dist/_commonjsHelpers-C6fGbg64.js +6 -0
- package/dist/_commonjsHelpers-DwGv2jUC.cjs +1 -0
- package/dist/actions-registery-CZ1w0NKa.js +15545 -0
- package/dist/actions-registery-YnFmU21O.cjs +418 -0
- package/dist/actions.cjs +1 -0
- package/dist/actions.d.ts +3202 -0
- package/dist/actions.js +216 -0
- package/dist/active-in-another-tab-B47YjQGN.cjs +1 -0
- package/dist/active-in-another-tab-CyjngVA6.js +34 -0
- package/dist/add-new-language-page-88xzrUy8.cjs +1 -0
- package/dist/add-new-language-page-WmlCnytQ.js +401 -0
- package/dist/add-new-page-VW2wAYZp.js +31 -0
- package/dist/add-new-page-soZ8GAkN.cjs +1 -0
- package/dist/ai-panel-content-7zCil042.cjs +1 -0
- package/dist/ai-panel-content-D_o7Q_A-.js +61 -0
- package/dist/ai-panel-default-lang-COYaxNwn.cjs +3 -0
- package/dist/ai-panel-default-lang-DnElspF0.js +341 -0
- package/dist/ai-panel-other-lang-CkynNlAU.cjs +1 -0
- package/dist/ai-panel-other-lang-Dp0E9_Hx.js +162 -0
- package/dist/ai-prompt-input-Bhc0ds7X.js +655 -0
- package/dist/ai-prompt-input-CThbVp0_.cjs +1 -0
- package/dist/ai-translation-prompt-C2kJQFDX.cjs +1 -0
- package/dist/ai-translation-prompt-CZ55HQmo.js +28 -0
- package/dist/apply-binding-6iwlED02.js +833 -0
- package/dist/apply-binding-KKp5PnpZ.cjs +1 -0
- package/dist/code-display-BnqzqzoP.cjs +1 -0
- package/dist/{code-display-337R7Dev.js → code-display-DhD_RBcg.js} +1 -1
- package/dist/code-editor-DRIAnNbb.js +50 -0
- package/dist/code-editor-o3___nu2.cjs +1 -0
- package/dist/common-functions-B3a4xKt_.cjs +1 -0
- package/dist/common-functions-D2lMFR6K.js +13 -0
- package/dist/continue-editing-in-this-client-CS2aQ7yY.js +24 -0
- package/dist/continue-editing-in-this-client-CtMYsk-A.cjs +1 -0
- package/dist/core-BoRDjj4h.cjs +1 -0
- package/dist/core-yvI6kCyw.js +56 -0
- package/dist/core.cjs +1 -1
- package/dist/core.d.ts +51 -383
- package/dist/core.js +39 -106
- package/dist/{css-import-modal-DA2L6kwP.js → css-import-modal-Byg6wV0O.js} +36 -36
- package/dist/css-import-modal-CyqkXWCO.cjs +13 -0
- package/dist/delete-design-token-BRZZiWtQ.js +40 -0
- package/dist/delete-design-token-DkVs1oBf.cjs +1 -0
- package/dist/delete-page-BzyX9TN-.js +70 -0
- package/dist/delete-page-DxX7PFIE.cjs +1 -0
- package/dist/design-token-usage-CAHzEGgJ.cjs +1 -0
- package/dist/design-token-usage-xQs6SlaJ.js +113 -0
- package/dist/digital-asset-manager--uO8Agia.cjs +1 -0
- package/dist/digital-asset-manager-DbtwzxRz.js +876 -0
- package/dist/duplicate-page-BR7Dlo9d.js +133 -0
- package/dist/duplicate-page-CaNAbXwV.cjs +1 -0
- package/dist/dynamic-page-selector-Cb5r_W8s.js +85 -0
- package/dist/dynamic-page-selector-Cxk_gjni.cjs +1 -0
- package/dist/fonts-B-Xt29pe.cjs +1 -0
- package/dist/fonts-DRly3Wzd.js +78 -0
- package/dist/{get-chai-builder-tailwind-config-C6MHaUM0.cjs → get-chai-builder-tailwind-config-B9rCyiQo.cjs} +1 -1
- package/dist/{get-chai-builder-tailwind-config-BqaIvg8p.js → get-chai-builder-tailwind-config-DjoVOuAf.js} +13 -10
- package/dist/{get-chai-builder-theme-D0IsUvK4.js → get-chai-builder-theme-BYtp20KD.js} +4 -4
- package/dist/get-chai-builder-theme-Dl72X7cz.cjs +1 -0
- package/dist/get-seo-defaults-9zHebckY.js +65 -0
- package/dist/get-seo-defaults-Cw7vFt-B.cjs +1 -0
- package/dist/image-compression-DZ9WMmyn.cjs +1 -0
- package/dist/image-compression-DsZ1oqpb.js +37 -0
- package/dist/image-editor-DV8kUKhl.js +108 -0
- package/dist/image-editor-G-K28aTS.cjs +1 -0
- package/dist/index-B-rSiAp_.cjs +1 -0
- package/dist/index-Ct7ElCGK.js +19069 -0
- package/dist/index-DF5DEvqb.cjs +160 -0
- package/dist/index-Dxfyt4d4.js +39 -0
- package/dist/index-WQwzsC7A.cjs +5 -0
- package/dist/index-ZuacEL1j.js +4732 -0
- package/dist/json-diff-viewer-D7z4zNvv.cjs +8 -0
- package/dist/json-diff-viewer-krslPepD.js +258 -0
- package/dist/lang-panel-BwIewMyw.js +215 -0
- package/dist/lang-panel-DT96k1xg.cjs +1 -0
- package/dist/manage-design-tokens-Caz_20VK.js +240 -0
- package/dist/manage-design-tokens-CrmLe7UT.cjs +1 -0
- package/dist/mark-as-template-D295ZQtU.js +156 -0
- package/dist/mark-as-template-W3LmpiqN.cjs +1 -0
- package/dist/models-5gOsRC56.cjs +1 -0
- package/dist/models-D95ZYr_x.js +70 -0
- package/dist/nested-path-selector-content-CKYYK-C5.js +87 -0
- package/dist/nested-path-selector-content-CoS_d3dc.cjs +1 -0
- package/dist/no-language-page-content-BvqRBP6y.js +42 -0
- package/dist/no-language-page-content-DkfeMl90.cjs +1 -0
- package/dist/no-language-page-dialog-BcEoqyQB.cjs +1 -0
- package/dist/no-language-page-dialog-PjNqTUpl.js +10 -0
- package/dist/page-creator-C4gc5NSC.cjs +1 -0
- package/dist/page-creator-DiOITEMw.js +795 -0
- package/dist/page-lock-BdYmCks0.cjs +1 -0
- package/dist/page-lock-Bfbs6RgL.js +30 -0
- package/dist/page-locked-dialog-B1FAtK92.cjs +1 -0
- package/dist/page-locked-dialog-B6MKTRfY.js +133 -0
- package/dist/page-manager-new-CHDueBDk.cjs +1 -0
- package/dist/page-manager-new-CzX22g2n.js +394 -0
- package/dist/page-manager-search-and-filter-CM0UMb6U.js +201 -0
- package/dist/page-manager-search-and-filter-DkkRIH86.cjs +1 -0
- package/dist/page-revisions-content-ChY-4f2V.cjs +1 -0
- package/dist/page-revisions-content-NH9JK4Ey.js +445 -0
- package/dist/pages.cjs +1 -0
- package/dist/pages.d.ts +491 -0
- package/dist/pages.js +27 -0
- package/dist/plugin-3ZKK6RXm.js +245 -0
- package/dist/plugin-C6rgJDNQ.cjs +22 -0
- package/dist/publish-pages-content-D9aixMN5.js +178 -0
- package/dist/publish-pages-content-x-JuSFJ9.cjs +1 -0
- package/dist/register-partial-type-BjtdfKHE.js +36 -0
- package/dist/register-partial-type-ig9fUWIJ.cjs +1 -0
- package/dist/render.cjs +2 -2
- package/dist/render.d.ts +26 -13
- package/dist/render.js +130 -124
- package/dist/rte-widget-modal-BaHIuEjF.cjs +1 -0
- package/dist/rte-widget-modal-DOJEXLIf.js +38 -0
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.d.ts +306 -7
- package/dist/runtime.js +44 -1
- package/dist/save-to-lib-Cgpxw8-g.cjs +1 -0
- package/dist/save-to-lib-eiOc_SSN.js +422 -0
- package/dist/sdk.css +1 -1
- package/dist/selected-block-display-BgRY82CT.cjs +16 -0
- package/dist/selected-block-display-CBFePS19.js +319 -0
- package/dist/seo-panel-C1-iMOR1.js +798 -0
- package/dist/seo-panel-DfAb8U7W.cjs +2 -0
- package/dist/shared-json-ld-B4PxAM_0.js +565 -0
- package/dist/shared-json-ld-DzG398hr.cjs +1 -0
- package/dist/slug-input-AwNJs9im.js +86 -0
- package/dist/slug-input-C_ijLQ_X.cjs +1 -0
- package/dist/supabase-actions.cjs +1 -0
- package/dist/supabase-actions.d.ts +284 -0
- package/dist/supabase-actions.js +524 -0
- package/dist/take-over-request-BNxcjY2j.cjs +1 -0
- package/dist/take-over-request-C4FeDtN_.js +63 -0
- package/dist/theme-panel-footer-Cq9pljro.cjs +1 -0
- package/dist/theme-panel-footer-uBQqSJXm.js +25 -0
- package/dist/translation-warning-modal-B64YqlbI.js +26 -0
- package/dist/translation-warning-modal-BZAcwM2_.cjs +1 -0
- package/dist/unmark-as-template-CZ9sQp_P.js +39 -0
- package/dist/unmark-as-template-EVvk0vmp.cjs +1 -0
- package/dist/unpublish-page-D4VwOlxc.js +27 -0
- package/dist/unpublish-page-bdSmwAVQ.cjs +1 -0
- package/dist/use-page-expand-manager-B6XTvk0E.cjs +1 -0
- package/dist/use-page-expand-manager-Cf4MUEJw.js +85 -0
- package/dist/{tailwind.cjs → utils.cjs} +1 -1
- package/dist/{tailwind.d.ts → utils.d.ts} +12 -11
- package/dist/utils.js +7 -0
- package/dist/web-blocks.cjs +1 -1
- package/dist/web-blocks.d.ts +0 -6
- package/dist/web-blocks.js +248 -241
- package/dist/web-preview-Cio70gk5.cjs +1 -0
- package/dist/web-preview-Djy6WIyj.js +73 -0
- package/package.json +175 -105
- package/dist/IconPicker-CGWn9C4u.cjs +0 -1
- package/dist/IconPicker-QvxJ-4Ez.js +0 -64
- package/dist/apply-binding-DCno1xQL.js +0 -711
- package/dist/apply-binding-DvHNFLQD.cjs +0 -1
- package/dist/code-display-BZ1x7SqI.cjs +0 -1
- package/dist/code-editor-B28LoECM.cjs +0 -1
- package/dist/code-editor-CfG2FhJ-.js +0 -58
- package/dist/common-functions-BGzDsf1z.js +0 -14
- package/dist/common-functions-BZmyleS1.cjs +0 -1
- package/dist/css-import-modal-CENUYvcl.cjs +0 -13
- package/dist/get-chai-builder-theme-Ck_Z4Q-M.cjs +0 -1
- package/dist/index-CaGNHF7f.js +0 -12209
- package/dist/index-Gn6pJt2v.cjs +0 -166
- package/dist/mockServiceWorker.js +0 -307
- package/dist/plugin-B5627hMN.js +0 -195
- package/dist/plugin-UxTRfDum.cjs +0 -22
- package/dist/rte-widget-modal-DL739qeQ.cjs +0 -1
- package/dist/rte-widget-modal-Dte0od04.js +0 -41
- package/dist/tailwind.js +0 -7
- package/dist/tooltip-A4qGk781.cjs +0 -1
- package/dist/tooltip-tLiIOgjq.js +0 -1067
- package/dist/ui.cjs +0 -1
- package/dist/ui.d.ts +0 -415
- package/dist/ui.js +0 -129
- package/dist/vite.svg +0 -1
|
@@ -0,0 +1,833 @@
|
|
|
1
|
+
import { g as lt, c as P } from "./common-functions-D2lMFR6K.js";
|
|
2
|
+
import { memoize as rt, get as y, cloneDeep as q, forEach as N, keys as R, isString as $, startsWith as k, isArray as I, isEmpty as _, includes as B, flatten as ct, flatMapDeep as pt, set as w, find as m, startCase as ut, camelCase as dt, has as A, filter as G, some as yt, capitalize as ht, compact as mt, map as gt, trim as bt, each as xt, last as ft } from "lodash-es";
|
|
3
|
+
import { parse as _t, stringify as C } from "himalaya";
|
|
4
|
+
import { e as kt, i as vt } from "./core-yvI6kCyw.js";
|
|
5
|
+
import { twMerge as wt } from "tailwind-merge";
|
|
6
|
+
const x = "#styles:", jt = "__ADD_BLOCK_INTERNAL_ROOT", qt = "@", Bt = "#", Q = "dt#", et = (e) => {
|
|
7
|
+
if (e = e.replace(x, ""), !e) return { baseClasses: "", classes: "" };
|
|
8
|
+
const n = e.split(/,(?![^\[]*\])/);
|
|
9
|
+
if (n.length === 1)
|
|
10
|
+
return { baseClasses: "", classes: n[0].trim() };
|
|
11
|
+
const [t, ...s] = n;
|
|
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 n in e) {
|
|
44
|
+
const t = et(`${x}${n}`);
|
|
45
|
+
expect(t).toEqual(e[n]);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
function Mt(e, n, t) {
|
|
50
|
+
const s = y(t, "i18nProps", []);
|
|
51
|
+
if (_(n) || _(s)) return e;
|
|
52
|
+
const a = q(e);
|
|
53
|
+
return N(R(a), (o) => {
|
|
54
|
+
if (B(s, o) && !_(n)) {
|
|
55
|
+
const i = y(a, o), l = y(a, `${o}-${n}`, "");
|
|
56
|
+
$(i) ? a[o] = $(l) && !_(l.trim()) && l.trimStart() || i : a[o] = _(l) ? i : l;
|
|
57
|
+
}
|
|
58
|
+
}), a;
|
|
59
|
+
}
|
|
60
|
+
const st = (e, n) => {
|
|
61
|
+
const { baseClasses: t, classes: s } = et(e), o = s.split(" ").filter((l) => l.startsWith(Q)).map((l) => {
|
|
62
|
+
var u;
|
|
63
|
+
return (u = n[l]) == null ? void 0 : u.value;
|
|
64
|
+
}), i = s.split(" ").filter((l) => !l.startsWith(Q)).join(" ");
|
|
65
|
+
return wt.apply(null, [t, ...o, i]);
|
|
66
|
+
};
|
|
67
|
+
function Tt(e, n) {
|
|
68
|
+
return y(e, `${n}_attrs`, {});
|
|
69
|
+
}
|
|
70
|
+
function Ot(e, n = !0, t = {}) {
|
|
71
|
+
const s = {};
|
|
72
|
+
return Object.keys(e).forEach((a) => {
|
|
73
|
+
if ($(e[a]) && e[a].startsWith(x)) {
|
|
74
|
+
const o = st(e[a], t), i = Tt(e, a);
|
|
75
|
+
s[a] = {
|
|
76
|
+
...!_(o) && { className: o },
|
|
77
|
+
...i,
|
|
78
|
+
...n ? {
|
|
79
|
+
"data-style-prop": a,
|
|
80
|
+
"data-block-parent": e._id,
|
|
81
|
+
"data-style-id": `${a}-${e._id}`
|
|
82
|
+
} : {}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
}), s;
|
|
86
|
+
}
|
|
87
|
+
const Vt = rt((e) => {
|
|
88
|
+
const n = kt(e), t = y(n, "schema.properties", {});
|
|
89
|
+
return Object.fromEntries(Object.entries(t).filter(([, s]) => y(s, "runtime", !1)));
|
|
90
|
+
}), Jt = (e, n) => {
|
|
91
|
+
if (!I(e)) return e;
|
|
92
|
+
let t = e, s;
|
|
93
|
+
return typeof n.limit == "number" && n.limit > 0 && (s = n.limit), s !== void 0 && (t = t.slice(0, s)), t;
|
|
94
|
+
}, zt = (e, n) => {
|
|
95
|
+
const t = q(e);
|
|
96
|
+
return N(R(t), (s) => {
|
|
97
|
+
if ($(t[s]) && !k(s, "_")) {
|
|
98
|
+
let a = t[s];
|
|
99
|
+
s === "repeaterItems" && (t.repeaterItemsBinding = a);
|
|
100
|
+
const o = /\{\{(.*?)\}\}/g, i = a.match(o);
|
|
101
|
+
i && i.forEach((l) => {
|
|
102
|
+
let u = l.slice(2, -2);
|
|
103
|
+
const r = y(n, u, l);
|
|
104
|
+
a = I(r) ? r : a.replace(l, r);
|
|
105
|
+
}), t[s] = a;
|
|
106
|
+
}
|
|
107
|
+
}), t;
|
|
108
|
+
}, Et = (e) => {
|
|
109
|
+
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/;
|
|
110
|
+
return n.test(e) || t.test(e);
|
|
111
|
+
}, $t = (e) => {
|
|
112
|
+
if (_(e)) return e;
|
|
113
|
+
const n = /<video[^>]+src=['"]([^'">]+)['"]/, t = /<iframe[^>]+src=['"]([^'">]+)['"]/, s = e.match(n), a = e.match(t), o = s ? s[1] : a ? a[1] : null, i = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, l = /(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;
|
|
114
|
+
return o && (i.test(o) || l.test(o)) ? o : e;
|
|
115
|
+
}, at = ["chai-name", "data-chai-name"], Nt = {
|
|
116
|
+
img: { alt: "alt", width: "width", height: "height", src: "image" },
|
|
117
|
+
video: {
|
|
118
|
+
src: "url",
|
|
119
|
+
autoplay: "controls.autoPlay",
|
|
120
|
+
muted: "controls.muted",
|
|
121
|
+
loop: "controls.loop",
|
|
122
|
+
controls: "controls.widgets"
|
|
123
|
+
},
|
|
124
|
+
a: {
|
|
125
|
+
href: "link.href",
|
|
126
|
+
target: "link.target",
|
|
127
|
+
type: ""
|
|
128
|
+
// @TODO: Detect here what to url, email, phone, elementId
|
|
129
|
+
},
|
|
130
|
+
input: {
|
|
131
|
+
placeholder: "placeholder",
|
|
132
|
+
required: "required",
|
|
133
|
+
type: "inputType",
|
|
134
|
+
name: "fieldName"
|
|
135
|
+
},
|
|
136
|
+
textarea: {
|
|
137
|
+
placeholder: "placeholder",
|
|
138
|
+
required: "required",
|
|
139
|
+
type: "inputType",
|
|
140
|
+
name: "fieldName"
|
|
141
|
+
},
|
|
142
|
+
select: {
|
|
143
|
+
placeholder: "placeholder",
|
|
144
|
+
required: "required",
|
|
145
|
+
multiple: "multiple",
|
|
146
|
+
name: "fieldName"
|
|
147
|
+
},
|
|
148
|
+
form: {
|
|
149
|
+
action: "action"
|
|
150
|
+
}
|
|
151
|
+
}, St = (e, n) => e.children.length === 1 && B(
|
|
152
|
+
["Heading", "Paragraph", "Span", "ListItem", "Button", "Label", "TableCell", "Link", "RichText"],
|
|
153
|
+
n._type
|
|
154
|
+
), H = (e) => e.map((n) => n.type === "text" ? y(n, "content", "") : _(n.children) ? "" : H(n.children)).join(""), W = (e) => e === null ? "" : e, nt = (e) => {
|
|
155
|
+
const n = mt(gt(e.split(/\s+/), bt)), t = m(n, (l) => /^w-/.test(l)), s = m(n, (l) => /^h-/.test(l));
|
|
156
|
+
if (!s || !t) return { height: "", width: "" };
|
|
157
|
+
const a = (l) => {
|
|
158
|
+
if (!l) return;
|
|
159
|
+
const u = l.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);
|
|
160
|
+
if (!u) return;
|
|
161
|
+
if (u[1]) return u[1];
|
|
162
|
+
const r = u[2];
|
|
163
|
+
return /^\d+(\.\d+)?$/.test(r) ? `${Number(r) * 4}px` : r === "auto" || B(r, "%") ? r : "16px";
|
|
164
|
+
}, o = a(t), i = a(s);
|
|
165
|
+
return {
|
|
166
|
+
width: B(o, "px") ? o : "16px",
|
|
167
|
+
height: B(i, "px") ? i : "16px"
|
|
168
|
+
};
|
|
169
|
+
}, tt = (e) => {
|
|
170
|
+
if (e.tagName === "svg") return {};
|
|
171
|
+
const n = {}, t = Nt[e.tagName] || {}, s = e.attributes;
|
|
172
|
+
return N(s, ({ key: a, value: o }) => {
|
|
173
|
+
var i;
|
|
174
|
+
if (!B(at, a))
|
|
175
|
+
if (a === "bid" && (n._bid = W(o)), t[a]) {
|
|
176
|
+
if (e.tagName === "img" && a === "src" && !o.startsWith("http")) {
|
|
177
|
+
const l = m(e.attributes, { key: "width" }), u = m(e.attributes, { key: "height" });
|
|
178
|
+
l && u ? o = `https://picsum.photos/${l == null ? void 0 : l.value}x${u == null ? void 0 : u.value}` : o = "https://picsum.photos/150x150";
|
|
179
|
+
} else if (e.tagName === "a") {
|
|
180
|
+
const l = m(e.attributes, { key: "href" });
|
|
181
|
+
l && typeof (l == null ? void 0 : l.value) == "string" && ((i = l == null ? void 0 : l.value) != null && i.startsWith("pageType:")) && w(n, "link.type", "pageType");
|
|
182
|
+
}
|
|
183
|
+
w(n, t[a], W(o));
|
|
184
|
+
} else B(["style", "class", "srcset", "bid"], a) || (A(n, "styles_attrs") || (n.styles_attrs = {}), k(a, "@") && (a = a.replace("@", "x-on:")), n.styles_attrs[`${a}`] = W(o));
|
|
185
|
+
}), delete n.class, n;
|
|
186
|
+
}, It = (e, n = "styles") => {
|
|
187
|
+
if (!e.attributes) return { [n]: `${x},` };
|
|
188
|
+
const t = m(e.attributes, { key: "class" });
|
|
189
|
+
if (t) {
|
|
190
|
+
const s = t.value;
|
|
191
|
+
return { [n]: `${x},${s}` };
|
|
192
|
+
}
|
|
193
|
+
return { [n]: `${x},` };
|
|
194
|
+
}, Dt = (e) => {
|
|
195
|
+
const n = y(e, "attributes", []), t = n.find((r) => r.key === "data-chai-richtext" || r.key === "chai-richtext"), s = n.find((r) => r.key === "data-chai-lightbox" || r.key === "chai-lightbox"), a = n.find((r) => r.key === "data-chai-dropdown" || r.key === "chai-dropdown"), o = n.find(
|
|
196
|
+
(r) => r.key === "data-chai-dropdown-button" || r.key === "chai-dropdown-button"
|
|
197
|
+
), i = n.find(
|
|
198
|
+
(r) => r.key === "data-chai-dropdown-content" || r.key === "chai-dropdown-content"
|
|
199
|
+
), l = n.find((r) => r.key === "class"), u = l && l.value.split(/\s+/).includes("rte");
|
|
200
|
+
if (a)
|
|
201
|
+
return { _type: "Dropdown" };
|
|
202
|
+
if (o)
|
|
203
|
+
return { _type: "DropdownButton" };
|
|
204
|
+
if (i)
|
|
205
|
+
return { _type: "DropdownContent" };
|
|
206
|
+
if (t || u)
|
|
207
|
+
return { _type: "Paragraph" };
|
|
208
|
+
if (s)
|
|
209
|
+
return { _type: "LightBoxLink" };
|
|
210
|
+
switch (e.tagName) {
|
|
211
|
+
// self closing tags
|
|
212
|
+
case "img":
|
|
213
|
+
return { _type: "Image" };
|
|
214
|
+
case "input":
|
|
215
|
+
return { _type: "Input", showLabel: !1 };
|
|
216
|
+
// showLabel: hiding default block label
|
|
217
|
+
case "hr":
|
|
218
|
+
return { _type: "Divider" };
|
|
219
|
+
case "br":
|
|
220
|
+
return { _type: "LineBreak" };
|
|
221
|
+
case "textarea":
|
|
222
|
+
return { _type: "TextArea", showLabel: !1 };
|
|
223
|
+
case "audio":
|
|
224
|
+
return { _type: "Audio" };
|
|
225
|
+
case "canvas":
|
|
226
|
+
return { _type: "Canvas" };
|
|
227
|
+
case "video":
|
|
228
|
+
case "iframe":
|
|
229
|
+
return { _type: "CustomHTML" };
|
|
230
|
+
case "svg":
|
|
231
|
+
return { _type: "Icon" };
|
|
232
|
+
// non self closing tags
|
|
233
|
+
// fixed structure
|
|
234
|
+
case "select":
|
|
235
|
+
return { _type: "Select", options: [] };
|
|
236
|
+
case "option":
|
|
237
|
+
return { _type: "Option" };
|
|
238
|
+
case "ul":
|
|
239
|
+
case "ol":
|
|
240
|
+
case "dl":
|
|
241
|
+
return {
|
|
242
|
+
_type: "List",
|
|
243
|
+
tag: e.tagName,
|
|
244
|
+
_listType: e.tagName === "ol" ? "list-decimal" : "list-none"
|
|
245
|
+
};
|
|
246
|
+
case "li":
|
|
247
|
+
case "dt":
|
|
248
|
+
return { _type: "ListItem", tag: e.tagName };
|
|
249
|
+
// non self closing tags
|
|
250
|
+
// free flow structure
|
|
251
|
+
case "span":
|
|
252
|
+
case "figcaption":
|
|
253
|
+
case "legend":
|
|
254
|
+
return { _type: "Span", tag: e.tagName };
|
|
255
|
+
case "p":
|
|
256
|
+
return { _type: "Paragraph", content: "" };
|
|
257
|
+
case "a":
|
|
258
|
+
return { _type: "Link" };
|
|
259
|
+
case "form":
|
|
260
|
+
return { _type: "Form" };
|
|
261
|
+
case "label":
|
|
262
|
+
return { _type: "Label" };
|
|
263
|
+
case "button":
|
|
264
|
+
return { _type: "Button" };
|
|
265
|
+
case "code":
|
|
266
|
+
return { _type: "Box", _name: "Code" };
|
|
267
|
+
case "h1":
|
|
268
|
+
case "h2":
|
|
269
|
+
case "h3":
|
|
270
|
+
case "h4":
|
|
271
|
+
case "h5":
|
|
272
|
+
case "h6":
|
|
273
|
+
return { _type: "Heading", tag: e.tagName };
|
|
274
|
+
case "table":
|
|
275
|
+
return { _type: "Table" };
|
|
276
|
+
case "tr":
|
|
277
|
+
return { _type: "TableRow" };
|
|
278
|
+
case "td":
|
|
279
|
+
case "th":
|
|
280
|
+
return { _type: "TableCell", tag: e.tagName };
|
|
281
|
+
case "thead":
|
|
282
|
+
return { _type: "TableHead" };
|
|
283
|
+
case "tbody":
|
|
284
|
+
return { _type: "TableBody" };
|
|
285
|
+
case "tfoot":
|
|
286
|
+
return { _type: "TableFooter" };
|
|
287
|
+
default: {
|
|
288
|
+
const r = y(e, "children", []).length > 0 ? "Box" : "EmptyBox";
|
|
289
|
+
return {
|
|
290
|
+
_type: r,
|
|
291
|
+
tag: e.tagName,
|
|
292
|
+
_name: r == "EmptyBox" || e.tagName === "div" ? r : ht(e.tagName)
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}, j = (e, n = null) => pt(e, (t) => {
|
|
297
|
+
var M, O, V, J, z, F, U, Y, K, X;
|
|
298
|
+
if (t.type === "comment") return [];
|
|
299
|
+
let s = { _id: lt() };
|
|
300
|
+
if (n && (s._parent = n.block._id), t.type === "text")
|
|
301
|
+
return _(y(t, "content", "")) ? [] : n && St(n.node, n.block) ? (w(n, "block.content", y(t, "content", "")), []) : { ...s, _type: "Text", content: y(t, "content", "") };
|
|
302
|
+
if (k(t.tagName, "chai-")) {
|
|
303
|
+
const c = t.attributes, p = m(c, { key: "chai-type" }), d = (p == null ? void 0 : p.value) || ut(t.tagName.replace("chai-", "")).replace(/\s+/g, "");
|
|
304
|
+
s._type = d, N(c, ({ key: g, value: Z }) => {
|
|
305
|
+
if (g === "about-this-component" || g === "chai-type" || g === "can-move" || g === "can-delete") return;
|
|
306
|
+
if (g === "id") {
|
|
307
|
+
s._id = Z;
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
const ot = k(g, "_") ? g : dt(g);
|
|
311
|
+
let S = W(Z);
|
|
312
|
+
typeof S == "string" && k(S, "#styles:") && (S = S.replace("#styles:", "#styles:,")), s[ot] = S;
|
|
313
|
+
});
|
|
314
|
+
const h = j(t.children, { block: s, node: t });
|
|
315
|
+
return [s, ...h];
|
|
316
|
+
}
|
|
317
|
+
const a = y(t, "attributes", []), o = t.tagName === "p" || a.find((c) => c.key === "data-chai-richtext" || c.key === "chai-richtext"), i = a.find((c) => c.key === "class"), l = i && i.value.split(/\s+/).includes("rte"), u = a.find(
|
|
318
|
+
(c) => c.key === "data-chai-lightbox" || c.key === "chai-lightbox"
|
|
319
|
+
), r = a.find(
|
|
320
|
+
(c) => c.key === "data-chai-dropdown" || c.key === "chai-dropdown"
|
|
321
|
+
), T = a.find(
|
|
322
|
+
(c) => c.key === "data-chai-dropdown-button" || c.key === "chai-dropdown-button"
|
|
323
|
+
), D = a.find(
|
|
324
|
+
(c) => c.key === "data-chai-dropdown-content" || c.key === "chai-dropdown-content"
|
|
325
|
+
);
|
|
326
|
+
if (s = {
|
|
327
|
+
...s,
|
|
328
|
+
...Dt(t),
|
|
329
|
+
...tt(t),
|
|
330
|
+
...It(t)
|
|
331
|
+
}, t.attributes) {
|
|
332
|
+
const c = t.attributes.find((p) => B(at, p.key));
|
|
333
|
+
c && (s._name = c.value);
|
|
334
|
+
}
|
|
335
|
+
if (o || l)
|
|
336
|
+
return s.content = `<p>${C(t.children || [])}</p>`, 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];
|
|
337
|
+
if (u) {
|
|
338
|
+
const c = [
|
|
339
|
+
"data-chai-lightbox",
|
|
340
|
+
"chai-lightbox",
|
|
341
|
+
"data-vbtype",
|
|
342
|
+
"data-autoplay",
|
|
343
|
+
"data-maxwidth",
|
|
344
|
+
"data-overlay",
|
|
345
|
+
"data-gall",
|
|
346
|
+
"href"
|
|
347
|
+
];
|
|
348
|
+
s = {
|
|
349
|
+
...s,
|
|
350
|
+
href: ((M = a.find((p) => p.key === "href")) == null ? void 0 : M.value) || "",
|
|
351
|
+
hrefType: ((O = a.find((p) => p.key === "data-vbtype")) == null ? void 0 : O.value) || "video",
|
|
352
|
+
autoplay: ((V = a.find((p) => p.key === "data-autoplay")) == null ? void 0 : V.value) === "true" ? "true" : "false",
|
|
353
|
+
maxWidth: ((z = (J = a.find((p) => p.key === "data-maxwidth")) == null ? void 0 : J.value) == null ? void 0 : z.replace("px", "")) || "",
|
|
354
|
+
backdropColor: ((F = a.find((p) => p.key === "data-overlay")) == null ? void 0 : F.value) || "",
|
|
355
|
+
galleryName: ((U = a.find((p) => p.key === "data-gall")) == null ? void 0 : U.value) || ""
|
|
356
|
+
}, N(c, (p) => {
|
|
357
|
+
A(s, `styles_attrs.${p}`) && delete s.styles_attrs[p];
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
if (r && (delete s.styles_attrs, s.showDropdown = !1), D && delete s.styles_attrs, T) {
|
|
361
|
+
delete s.styles_attrs;
|
|
362
|
+
const c = G(t.children || [], (d) => (d == null ? void 0 : d.tagName) !== "span");
|
|
363
|
+
s.content = H(c);
|
|
364
|
+
const p = m(
|
|
365
|
+
t.children || [],
|
|
366
|
+
(d) => (d == null ? void 0 : d.tagName) === "span" && yt(d.children || [], (h) => (h == null ? void 0 : h.tagName) === "svg")
|
|
367
|
+
);
|
|
368
|
+
if (p) {
|
|
369
|
+
const d = m(p.children || [], (h) => (h == null ? void 0 : h.tagName) === "svg");
|
|
370
|
+
if (d) {
|
|
371
|
+
s.icon = C([d]);
|
|
372
|
+
const { height: h, width: g } = Ct(d, "16px", "16px");
|
|
373
|
+
s.iconHeight = h, s.iconWidth = g;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
return [s];
|
|
377
|
+
}
|
|
378
|
+
if (s._type === "Input") {
|
|
379
|
+
const c = s.inputType || "text";
|
|
380
|
+
c === "checkbox" ? w(s, "_type", "Checkbox") : c === "radio" && w(s, "_type", "Radio");
|
|
381
|
+
} else if (t.tagName === "video" || t.tagName === "iframe") {
|
|
382
|
+
const c = C([t]);
|
|
383
|
+
return Et(c) && (w(s, "_type", "Video"), w(s, "url", $t(c)), w(s, "styles", `${x},`), w(s, "controls", { autoPlay: !1, muted: !0, loop: !1, controls: !1 })), s.content = c, [s];
|
|
384
|
+
} else if (t.tagName === "svg") {
|
|
385
|
+
const c = y(m(t.attributes, { key: "class" }), "value", ""), { height: p, width: d } = nt(c);
|
|
386
|
+
if (p && d)
|
|
387
|
+
s.styles = `${x}, ${P(`w-${d} h-${p}`, c)}`.trim(), s.height = p == null ? void 0 : p.replace("px", ""), s.width = d == null ? void 0 : d.replace("px", "");
|
|
388
|
+
else {
|
|
389
|
+
const h = (Y = m(t.attributes, { key: "height" })) == null ? void 0 : Y.value, g = (K = m(t.attributes, { key: "width" })) == null ? void 0 : K.value;
|
|
390
|
+
h && g ? (s.styles = `${x}, ${P(`w-[${g}px] h-[${h}px]`, c)}`.trim(), s.height = h, s.width = g) : s.styles = `${x}, ${P("w-full h-full", c)}`.trim();
|
|
391
|
+
}
|
|
392
|
+
return t.attributes = G(t.attributes, (h) => !B(["style", "width", "height", "class"], h.key)), s.icon = C([t]), [s];
|
|
393
|
+
} else if (t.tagName == "option" && n && ((X = n.block) == null ? void 0 : X._type) === "Select")
|
|
394
|
+
return n.block.options.push({
|
|
395
|
+
label: H(t.children),
|
|
396
|
+
...tt(t)
|
|
397
|
+
}), [];
|
|
398
|
+
const E = j(t.children, { block: s, node: t });
|
|
399
|
+
return [s, ...E];
|
|
400
|
+
}), Ct = (e, n, t) => {
|
|
401
|
+
var u, r;
|
|
402
|
+
const s = y(e, "attributes", []), { height: a, width: o } = nt(
|
|
403
|
+
y(m(s, { key: "class" }), "value", "")
|
|
404
|
+
);
|
|
405
|
+
if (a && o)
|
|
406
|
+
return {
|
|
407
|
+
height: `[${a}px]`,
|
|
408
|
+
width: `[${o}px]`
|
|
409
|
+
};
|
|
410
|
+
const i = (u = m(s, { key: "height" })) == null ? void 0 : u.value, l = (r = m(s, { key: "width" })) == null ? void 0 : r.value;
|
|
411
|
+
return {
|
|
412
|
+
height: i ? `[${i}px]` : t,
|
|
413
|
+
width: l ? `[${l}px]` : n
|
|
414
|
+
};
|
|
415
|
+
}, Lt = (e) => {
|
|
416
|
+
e = e.replace(/(\w+)=\\?"(.*?)\\?"/g, (s, a, o) => {
|
|
417
|
+
let i = o.replace(/\\"/g, '"');
|
|
418
|
+
return i = i.replace(/{([^}]+)}/g, (l) => l.replace(/"/g, '\\"')), `${a}="${i.replace(/\\"/g, '"')}"`;
|
|
419
|
+
}), e = e.replace(/\\n/g, "").replace(/\\\\/g, "").replace(/\\([/<>])/g, "$1").replace(/\\./g, "").replace(/[\n\r\t\f\v]/g, ""), e = e.replace(/\$name="[^"]*"/g, "");
|
|
420
|
+
const n = e.match(/<body[^>]*>[\s\S]*?<\/body>/);
|
|
421
|
+
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();
|
|
422
|
+
}, Ft = (e) => {
|
|
423
|
+
const n = _t(Lt(e));
|
|
424
|
+
if (_(e)) return [];
|
|
425
|
+
const t = ct(j(n));
|
|
426
|
+
return vt(t);
|
|
427
|
+
}, f = (e, n) => e.map((t) => {
|
|
428
|
+
const s = R(t).filter((a) => $(t[a]) && t[a].startsWith(x));
|
|
429
|
+
return xt(s, (a) => {
|
|
430
|
+
t[a] = `${x},${st(t[a], n)}`;
|
|
431
|
+
}), t;
|
|
432
|
+
});
|
|
433
|
+
import.meta.vitest && describe("applyDesignTokens", () => {
|
|
434
|
+
const e = {
|
|
435
|
+
"dt#token1": { name: "primary-color", value: "bg-blue-500" },
|
|
436
|
+
"dt#token2": { name: "text-size", value: "text-lg" },
|
|
437
|
+
"dt#token3": { name: "spacing", value: "p-4" }
|
|
438
|
+
}, n = [
|
|
439
|
+
{
|
|
440
|
+
_id: "block1",
|
|
441
|
+
_type: "div",
|
|
442
|
+
styles: "#styles:,dt#token1 bg-white text-sm",
|
|
443
|
+
className: "#styles:,dt#token2 dt#token3",
|
|
444
|
+
otherProp: "not-a-style",
|
|
445
|
+
_name: "Test Block"
|
|
446
|
+
},
|
|
447
|
+
{
|
|
448
|
+
_id: "block2",
|
|
449
|
+
_type: "button",
|
|
450
|
+
styles: "#styles:bg-red-500",
|
|
451
|
+
nonStringProp: 123,
|
|
452
|
+
_name: "Button Block"
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
_id: "block3",
|
|
456
|
+
_type: "span",
|
|
457
|
+
noStyles: "regular-string",
|
|
458
|
+
_name: "No Styles Block"
|
|
459
|
+
}
|
|
460
|
+
];
|
|
461
|
+
it("should process blocks and replace style properties with generated class names", () => {
|
|
462
|
+
const t = f(n, e);
|
|
463
|
+
expect(t).toHaveLength(3), expect(t[0].styles).toBe("#styles:,bg-white text-sm"), expect(t[0].className).toBe("#styles:,text-lg p-4"), expect(t[0].otherProp).toBe("not-a-style"), expect(t[0]._id).toBe("block1"), expect(t[0]._type).toBe("div");
|
|
464
|
+
}), it("should handle blocks with no style properties", () => {
|
|
465
|
+
const t = f(n, e);
|
|
466
|
+
expect(t[2].noStyles).toBe("regular-string"), expect(t[2]._id).toBe("block3");
|
|
467
|
+
}), it("should handle empty blocks array", () => {
|
|
468
|
+
const t = f([], e);
|
|
469
|
+
expect(t).toEqual([]);
|
|
470
|
+
}), it("should handle empty design tokens", () => {
|
|
471
|
+
const t = f(n, {});
|
|
472
|
+
expect(t[0].styles).toBe("#styles:,bg-white text-sm");
|
|
473
|
+
}), it("should handle blocks with only style prefix", () => {
|
|
474
|
+
const s = f([
|
|
475
|
+
{
|
|
476
|
+
_id: "block1",
|
|
477
|
+
_type: "div",
|
|
478
|
+
styles: "#styles:",
|
|
479
|
+
_name: "Prefix Only"
|
|
480
|
+
}
|
|
481
|
+
], e);
|
|
482
|
+
expect(s[0].styles).toBe("#styles:,");
|
|
483
|
+
}), it("should handle blocks with multiple style properties", () => {
|
|
484
|
+
const s = f([
|
|
485
|
+
{
|
|
486
|
+
_id: "block1",
|
|
487
|
+
_type: "div",
|
|
488
|
+
styles: "#styles:bg-white dt#token1",
|
|
489
|
+
hoverStyles: "#styles:bg-gray-100 dt#token2",
|
|
490
|
+
focusStyles: "#styles:outline-none dt#token3",
|
|
491
|
+
_name: "Multi Style"
|
|
492
|
+
}
|
|
493
|
+
], e);
|
|
494
|
+
expect(s[0].styles).toBe("#styles:,bg-white"), expect(s[0].hoverStyles).toBe("#styles:,text-lg bg-gray-100"), expect(s[0].focusStyles).toBe("#styles:,p-4 outline-none");
|
|
495
|
+
}), it("should not modify non-string properties that start with #styles:", () => {
|
|
496
|
+
const s = f([
|
|
497
|
+
{
|
|
498
|
+
_id: "block1",
|
|
499
|
+
_type: "div",
|
|
500
|
+
styles: "#styles:bg-white",
|
|
501
|
+
objectStyles: { startsWith: "#styles:" },
|
|
502
|
+
arrayStyles: ["#styles:bg-red-500"],
|
|
503
|
+
_name: "Non String Styles"
|
|
504
|
+
}
|
|
505
|
+
], e);
|
|
506
|
+
expect(s[0].styles).toBe("#styles:,bg-white"), expect(s[0].objectStyles).toEqual({ startsWith: "#styles:" }), expect(s[0].arrayStyles).toEqual(["#styles:bg-red-500"]);
|
|
507
|
+
}), it("should handle undefined and null values", () => {
|
|
508
|
+
const s = f([
|
|
509
|
+
{
|
|
510
|
+
_id: "block1",
|
|
511
|
+
_type: "div",
|
|
512
|
+
styles: "#styles:bg-white",
|
|
513
|
+
nullStyles: null,
|
|
514
|
+
undefinedStyles: void 0,
|
|
515
|
+
_name: " Null Undefined"
|
|
516
|
+
}
|
|
517
|
+
], e);
|
|
518
|
+
expect(s[0].styles).toBe("#styles:,bg-white"), expect(s[0].nullStyles).toBeNull(), expect(s[0].undefinedStyles).toBeUndefined();
|
|
519
|
+
}), it("should preserve block structure and non-style properties", () => {
|
|
520
|
+
f(n, e).forEach((s, a) => {
|
|
521
|
+
expect(s._id).toBe(n[a]._id), expect(s._type).toBe(n[a]._type), expect(s._name).toBe(n[a]._name);
|
|
522
|
+
});
|
|
523
|
+
}), it("should handle complex design token values", () => {
|
|
524
|
+
const a = f([
|
|
525
|
+
{
|
|
526
|
+
_id: "block1",
|
|
527
|
+
_type: "div",
|
|
528
|
+
styles: "#styles:bg-white dt#complex1",
|
|
529
|
+
_name: "Complex Tokens"
|
|
530
|
+
}
|
|
531
|
+
], {
|
|
532
|
+
"dt#complex1": { name: "complex-token", value: "hover:bg-blue-600 focus:outline-none transition-colors" },
|
|
533
|
+
"dt#complex2": { name: "spacing-token", value: "px-6 py-3 m-2" }
|
|
534
|
+
});
|
|
535
|
+
expect(a[0].styles).toBe("#styles:,hover:bg-blue-600 focus:outline-none transition-colors bg-white");
|
|
536
|
+
}), it("should handle tokens with empty values", () => {
|
|
537
|
+
const a = f([
|
|
538
|
+
{
|
|
539
|
+
_id: "block1",
|
|
540
|
+
_type: "div",
|
|
541
|
+
styles: "#styles:bg-white dt#empty1 dt#valid1",
|
|
542
|
+
_name: "Empty Value Tokens"
|
|
543
|
+
}
|
|
544
|
+
], {
|
|
545
|
+
"dt#empty1": { name: "empty-token", value: "" },
|
|
546
|
+
"dt#valid1": { name: "valid-token", value: "bg-green-500" }
|
|
547
|
+
});
|
|
548
|
+
expect(a[0].styles).toBe("#styles:,bg-white");
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
const v = (e) => {
|
|
552
|
+
const n = ft(e);
|
|
553
|
+
return e.map((t) => {
|
|
554
|
+
const s = Object.keys(t);
|
|
555
|
+
for (let a = 0; a < s.length; a++)
|
|
556
|
+
if ($(t[s[a]]) && k(s[a], "content")) {
|
|
557
|
+
const o = t === n ? "" : " ";
|
|
558
|
+
t[s[a]] = `${t[s[a]].trim()}${o}`;
|
|
559
|
+
}
|
|
560
|
+
return t;
|
|
561
|
+
});
|
|
562
|
+
};
|
|
563
|
+
if (import.meta.vitest) {
|
|
564
|
+
const { describe: e, it: n, expect: t } = import.meta.vitest;
|
|
565
|
+
e("adjustSpacingInContentBlocks", () => {
|
|
566
|
+
n("should add space after content fields except for the last block", () => {
|
|
567
|
+
const a = v([
|
|
568
|
+
{ _id: "1", _type: "Text", content: "First" },
|
|
569
|
+
{ _id: "2", _type: "Text", content: "Second" },
|
|
570
|
+
{ _id: "3", _type: "Text", content: "Third" }
|
|
571
|
+
]);
|
|
572
|
+
t(a[0].content).toBe("First "), t(a[1].content).toBe("Second "), t(a[2].content).toBe("Third");
|
|
573
|
+
}), n("should trim whitespace from content before adding space", () => {
|
|
574
|
+
const a = v([
|
|
575
|
+
{ _id: "1", _type: "Text", content: " First " },
|
|
576
|
+
{ _id: "2", _type: "Text", content: " Second " }
|
|
577
|
+
]);
|
|
578
|
+
t(a[0].content).toBe("First "), t(a[1].content).toBe("Second");
|
|
579
|
+
}), n("should handle multiple content fields in a single block", () => {
|
|
580
|
+
const a = v([
|
|
581
|
+
{ _id: "1", _type: "Text", content: "Main", contentAlt: "Alt" },
|
|
582
|
+
{ _id: "2", _type: "Text", content: "Last", contentSecondary: "Secondary" }
|
|
583
|
+
]);
|
|
584
|
+
t(a[0].content).toBe("Main "), t(a[0].contentAlt).toBe("Alt "), t(a[1].content).toBe("Last"), t(a[1].contentSecondary).toBe("Secondary");
|
|
585
|
+
}), n("should only process fields that start with 'content'", () => {
|
|
586
|
+
const a = v([
|
|
587
|
+
{ _id: "1", _type: "Text", content: "Text", title: "Title", text: "Text" },
|
|
588
|
+
{ _id: "2", _type: "Text", content: "Last" }
|
|
589
|
+
]);
|
|
590
|
+
t(a[0].content).toBe("Text "), t(a[0].title).toBe("Title"), t(a[0].text).toBe("Text"), t(a[1].content).toBe("Last");
|
|
591
|
+
}), n("should handle empty array", () => {
|
|
592
|
+
const a = v([]);
|
|
593
|
+
t(a).toEqual([]);
|
|
594
|
+
}), n("should handle single block", () => {
|
|
595
|
+
const a = v([{ _id: "1", _type: "Text", content: "Only" }]);
|
|
596
|
+
t(a[0].content).toBe("Only");
|
|
597
|
+
}), n("should handle blocks without content fields", () => {
|
|
598
|
+
const a = v([
|
|
599
|
+
{ _id: "1", _type: "Container", title: "Title" },
|
|
600
|
+
{ _id: "2", _type: "Container", name: "Name" }
|
|
601
|
+
]);
|
|
602
|
+
t(a[0].title).toBe("Title"), t(a[1].name).toBe("Name");
|
|
603
|
+
}), n("should handle blocks with non-string content fields", () => {
|
|
604
|
+
const a = v([
|
|
605
|
+
{ _id: "1", _type: "Text", content: "Text", contentNum: 123 },
|
|
606
|
+
{ _id: "2", _type: "Text", content: "Last", contentBool: !0 }
|
|
607
|
+
]);
|
|
608
|
+
t(a[0].content).toBe("Text "), t(a[0].contentNum).toBe(123), t(a[1].content).toBe("Last"), t(a[1].contentBool).toBe(!0);
|
|
609
|
+
}), n("should handle empty string content", () => {
|
|
610
|
+
const a = v([
|
|
611
|
+
{ _id: "1", _type: "Text", content: "" },
|
|
612
|
+
{ _id: "2", _type: "Text", content: "Last" }
|
|
613
|
+
]);
|
|
614
|
+
t(a[0].content).toBe(" "), t(a[1].content).toBe("Last");
|
|
615
|
+
});
|
|
616
|
+
});
|
|
617
|
+
}
|
|
618
|
+
const b = (e, n, { index: t, key: s }, a) => {
|
|
619
|
+
if ($(e)) {
|
|
620
|
+
let o = e;
|
|
621
|
+
const i = /\{\{(.*?)\}\}/g, l = e.match(i);
|
|
622
|
+
if (l) {
|
|
623
|
+
const u = a === "image" || a === "mobileImage";
|
|
624
|
+
l.forEach((r) => {
|
|
625
|
+
let T = r.slice(2, -2).trim(), D = s.slice(2, -2).trim();
|
|
626
|
+
t !== -1 && k(T, "$index.") ? T = `${D}.${t}.${T.slice(7)}` : t !== -1 && k(T, "$index") && (T = `${D}.${t}`);
|
|
627
|
+
const E = y(n, T);
|
|
628
|
+
E === void 0 ? o = o.replace(r, "") : u && !I(E) ? o = E : o = I(E) ? E : o.replace(r, E);
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
return o;
|
|
632
|
+
}
|
|
633
|
+
if (I(e))
|
|
634
|
+
return e.map((o) => b(o, n, { index: t, key: s }, a));
|
|
635
|
+
if (e && typeof e == "object") {
|
|
636
|
+
const o = {};
|
|
637
|
+
return N(R(e), (i) => {
|
|
638
|
+
!k(i, "_") && i !== "$repeaterItemsKey" ? o[i] = b(e[i], n, { index: t, key: s }, i) : o[i] = e[i];
|
|
639
|
+
}), o;
|
|
640
|
+
}
|
|
641
|
+
return e;
|
|
642
|
+
}, L = (e, n, { index: t, key: s }) => {
|
|
643
|
+
let a = q(e);
|
|
644
|
+
return a.repeaterItems && (a.$repeaterItemsKey = a.repeaterItems, k(a.repeaterItems, `{{${Bt}`) && (a.$repeaterItemsKey = a.repeaterItems = `${a.repeaterItems.replace("}}", `/${a._id}}}`)}`), !_(a.repeaterItems) && a.pagination && (a.repeaterTotalItems = `${a.repeaterItems.replace("}}", `/${a._id}/totalItems}}`)}`)), b(a, n, { index: t, key: s });
|
|
645
|
+
};
|
|
646
|
+
import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
647
|
+
it("should handle string values with bindings", () => {
|
|
648
|
+
const t = b("Hello {{user.name}}", { user: { name: "John" } }, { index: -1, key: "" });
|
|
649
|
+
expect(t).toBe("Hello John");
|
|
650
|
+
}), it("should handle nested object properties", () => {
|
|
651
|
+
const t = b({
|
|
652
|
+
name: "John",
|
|
653
|
+
address: {
|
|
654
|
+
city: "{{user.city}}",
|
|
655
|
+
street: "123 Main St"
|
|
656
|
+
}
|
|
657
|
+
}, { user: { city: "New York" } }, { index: -1, key: "" });
|
|
658
|
+
expect(t).toEqual({
|
|
659
|
+
name: "John",
|
|
660
|
+
address: {
|
|
661
|
+
city: "New York",
|
|
662
|
+
street: "123 Main St"
|
|
663
|
+
}
|
|
664
|
+
});
|
|
665
|
+
}), it("should handle arrays of values", () => {
|
|
666
|
+
const t = b(["Hello {{user.name}}", "Welcome {{user.role}}"], { user: { name: "John", role: "Admin" } }, { index: -1, key: "" });
|
|
667
|
+
expect(t).toEqual(["Hello John", "Welcome Admin"]);
|
|
668
|
+
}), it("should handle $index binding in repeater context", () => {
|
|
669
|
+
const t = b("Item {{$index}}", { items: ["a", "b", "c"] }, { index: 1, key: "{{items}}" });
|
|
670
|
+
expect(t).toBe("Item b");
|
|
671
|
+
}), it("should handle $index binding with dot notation", () => {
|
|
672
|
+
const t = b("Item {{$index.value}}", { items: [{ value: "apple" }, { value: "banana" }, { value: "cherry" }] }, { index: 1, key: "{{items}}" });
|
|
673
|
+
expect(t).toBe("Item banana");
|
|
674
|
+
}), it("should return an empty string for non-existing bindings", () => {
|
|
675
|
+
const t = b("Hello {{user.nonexistent}}", { user: { name: "John" } }, { index: -1, key: "" });
|
|
676
|
+
expect(t).toBe("Hello ");
|
|
677
|
+
}), it("should preserve private properties starting with _", () => {
|
|
678
|
+
const n = b({
|
|
679
|
+
name: "John",
|
|
680
|
+
_private: "secret"
|
|
681
|
+
}, {}, { index: -1, key: "" });
|
|
682
|
+
expect(n).toEqual({
|
|
683
|
+
name: "John",
|
|
684
|
+
_private: "secret"
|
|
685
|
+
});
|
|
686
|
+
}), it("should completely replace image property value when binding exists", () => {
|
|
687
|
+
const t = b({
|
|
688
|
+
image: "https://default.jpg{{user.avatar}}",
|
|
689
|
+
title: "Hello {{user.name}}"
|
|
690
|
+
}, { user: { avatar: "https://avatar.jpg", name: "John" } }, { index: -1, key: "" });
|
|
691
|
+
expect(t).toEqual({
|
|
692
|
+
image: "https://avatar.jpg",
|
|
693
|
+
// Completely replaced, not concatenated
|
|
694
|
+
title: "Hello John"
|
|
695
|
+
// Normal replacement
|
|
696
|
+
});
|
|
697
|
+
}), it("should completely replace mobileImage property value when binding exists", () => {
|
|
698
|
+
const t = b({
|
|
699
|
+
mobileImage: "https://default-mobile.jpg{{user.mobileAvatar}}",
|
|
700
|
+
alt: "Avatar for {{user.name}}"
|
|
701
|
+
}, { user: { mobileAvatar: "https://mobile-avatar.jpg", name: "John" } }, { index: -1, key: "" });
|
|
702
|
+
expect(t).toEqual({
|
|
703
|
+
mobileImage: "https://mobile-avatar.jpg",
|
|
704
|
+
// Completely replaced
|
|
705
|
+
alt: "Avatar for John"
|
|
706
|
+
// Normal replacement
|
|
707
|
+
});
|
|
708
|
+
}), it("should handle image binding with only binding syntax", () => {
|
|
709
|
+
const t = b({
|
|
710
|
+
image: "{{product.thumbnail}}"
|
|
711
|
+
}, { product: { thumbnail: "https://product.jpg" } }, { index: -1, key: "" });
|
|
712
|
+
expect(t).toEqual({
|
|
713
|
+
image: "https://product.jpg"
|
|
714
|
+
});
|
|
715
|
+
}), it("should not affect non-image properties with similar bindings", () => {
|
|
716
|
+
const t = b({
|
|
717
|
+
url: "https://default.com{{page.slug}}",
|
|
718
|
+
link: "https://example.com/{{page.id}}"
|
|
719
|
+
}, { page: { slug: "/about", id: "123" } }, { index: -1, key: "" });
|
|
720
|
+
expect(t).toEqual({
|
|
721
|
+
url: "https://default.com/about",
|
|
722
|
+
// Concatenated normally
|
|
723
|
+
link: "https://example.com/123"
|
|
724
|
+
// Concatenated normally
|
|
725
|
+
});
|
|
726
|
+
});
|
|
727
|
+
}), describe("applyBindingToBlockProps", () => {
|
|
728
|
+
it("should handle basic block with bindings", () => {
|
|
729
|
+
const t = L({
|
|
730
|
+
_id: "test-block",
|
|
731
|
+
_type: "text",
|
|
732
|
+
type: "text",
|
|
733
|
+
content: "Hello {{user.name}}",
|
|
734
|
+
style: {
|
|
735
|
+
color: "{{theme.color}}"
|
|
736
|
+
}
|
|
737
|
+
}, { user: { name: "John" }, theme: { color: "blue" } }, { index: -1, key: "" });
|
|
738
|
+
expect(t).toEqual({
|
|
739
|
+
_id: "test-block",
|
|
740
|
+
_type: "text",
|
|
741
|
+
type: "text",
|
|
742
|
+
content: "Hello John",
|
|
743
|
+
style: {
|
|
744
|
+
color: "blue"
|
|
745
|
+
}
|
|
746
|
+
});
|
|
747
|
+
}), it("should handle repeaterItems and repeaterItemsBinding", () => {
|
|
748
|
+
const t = L({
|
|
749
|
+
_id: "test-block",
|
|
750
|
+
_type: "repeater",
|
|
751
|
+
type: "repeater",
|
|
752
|
+
repeaterItems: "{{items}}",
|
|
753
|
+
items: ["a", "b", "c"]
|
|
754
|
+
}, { items: ["x", "y", "z"] }, { index: -1, key: "" });
|
|
755
|
+
expect(t).toEqual({
|
|
756
|
+
_id: "test-block",
|
|
757
|
+
_type: "repeater",
|
|
758
|
+
type: "repeater",
|
|
759
|
+
$repeaterItemsKey: "{{items}}",
|
|
760
|
+
repeaterItems: ["x", "y", "z"],
|
|
761
|
+
items: ["a", "b", "c"]
|
|
762
|
+
});
|
|
763
|
+
}), it("should handle nested blocks with bindings", () => {
|
|
764
|
+
const t = L({
|
|
765
|
+
_id: "test-block",
|
|
766
|
+
_type: "container",
|
|
767
|
+
type: "container",
|
|
768
|
+
children: [
|
|
769
|
+
{
|
|
770
|
+
_id: "child-block",
|
|
771
|
+
_type: "text",
|
|
772
|
+
type: "text",
|
|
773
|
+
content: "Item {{$index}}",
|
|
774
|
+
style: {
|
|
775
|
+
color: "{{theme.color}}"
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
]
|
|
779
|
+
}, { theme: { color: "red" }, items: ["x", "y", "z"] }, { index: 2, key: "{{items}}" });
|
|
780
|
+
expect(t).toEqual({
|
|
781
|
+
_id: "test-block",
|
|
782
|
+
_type: "container",
|
|
783
|
+
type: "container",
|
|
784
|
+
children: [
|
|
785
|
+
{
|
|
786
|
+
_id: "child-block",
|
|
787
|
+
_type: "text",
|
|
788
|
+
type: "text",
|
|
789
|
+
content: "Item z",
|
|
790
|
+
style: {
|
|
791
|
+
color: "red"
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
]
|
|
795
|
+
});
|
|
796
|
+
}), it("should handle arrays of blocks", () => {
|
|
797
|
+
const t = L({
|
|
798
|
+
_id: "test-block",
|
|
799
|
+
_type: "list",
|
|
800
|
+
type: "list",
|
|
801
|
+
items: [
|
|
802
|
+
{ _id: "item1", content: "Item {{$index}}" },
|
|
803
|
+
{ _id: "item2", content: "Item {{$index}}" }
|
|
804
|
+
]
|
|
805
|
+
}, { items: ["x", "y", "z"] }, { index: 0, key: "{{items}}" });
|
|
806
|
+
expect(t).toEqual({
|
|
807
|
+
_id: "test-block",
|
|
808
|
+
_type: "list",
|
|
809
|
+
type: "list",
|
|
810
|
+
items: [
|
|
811
|
+
{ _id: "item1", content: "Item x" },
|
|
812
|
+
{ _id: "item2", content: "Item x" }
|
|
813
|
+
]
|
|
814
|
+
});
|
|
815
|
+
});
|
|
816
|
+
}));
|
|
817
|
+
export {
|
|
818
|
+
Bt as C,
|
|
819
|
+
Q as D,
|
|
820
|
+
qt as R,
|
|
821
|
+
x as S,
|
|
822
|
+
L as a,
|
|
823
|
+
Mt as b,
|
|
824
|
+
Ot as c,
|
|
825
|
+
Vt as d,
|
|
826
|
+
Jt as e,
|
|
827
|
+
v as f,
|
|
828
|
+
Ft as g,
|
|
829
|
+
zt as h,
|
|
830
|
+
f as i,
|
|
831
|
+
et as j,
|
|
832
|
+
jt as k
|
|
833
|
+
};
|