@chaibuilder/sdk 3.0.8 → 3.0.10

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.
@@ -1,573 +0,0 @@
1
- import { getRegisteredChaiBlock as G } from "@chaibuilder/runtime";
2
- import { memoize as U, get as d, cloneDeep as L, forEach as $, keys as R, isString as N, startsWith as v, isArray as C, isEmpty as _, includes as f, flatten as Q, flatMapDeep as ee, set as x, has as I, filter as W, find as y, some as te, compact as ae, map as se, trim as re, capitalize as ne } from "lodash-es";
3
- import { twMerge as ie } from "tailwind-merge";
4
- import { g as oe, c as B } from "./common-functions-BGzDsf1z.js";
5
- import { parse as ce, stringify as E } from "himalaya";
6
- const b = "#styles:", Ee = "__ADD_BLOCK_INTERNAL_ROOT", Te = "@", le = "#", Y = (e) => {
7
- if (e = e.replace(b, ""), !e) return { baseClasses: "", classes: "" };
8
- const s = e.split(/,(?![^\[]*\])/);
9
- if (s.length === 1)
10
- return { baseClasses: "", classes: s[0].trim() };
11
- const [t, ...a] = s;
12
- return {
13
- baseClasses: t.trim(),
14
- classes: a.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 s in e) {
44
- const t = Y(`${b}${s}`);
45
- expect(t).toEqual(e[s]);
46
- }
47
- });
48
- });
49
- function Ie(e, s, t) {
50
- const a = d(t, "i18nProps", []);
51
- if (_(s) || _(a)) return e;
52
- const r = L(e);
53
- return $(R(r), (i) => {
54
- if (f(a, i) && !_(s)) {
55
- const c = d(r, `${i}-${s}`, ""), n = d(r, i, "");
56
- r[i] = N(c) && c.trim() || n;
57
- }
58
- }), r;
59
- }
60
- const pe = U((e) => {
61
- const { baseClasses: s, classes: t } = Y(e);
62
- return ie(s, t);
63
- });
64
- function ue(e, s) {
65
- return d(e, `${s}_attrs`, {});
66
- }
67
- function Ce(e, s = !0) {
68
- const t = {};
69
- return Object.keys(e).forEach((a) => {
70
- if (N(e[a]) && e[a].startsWith(b)) {
71
- const r = pe(e[a]), i = ue(e, a);
72
- t[a] = {
73
- ...!_(r) && { className: r },
74
- ...i,
75
- ...s ? {
76
- "data-style-prop": a,
77
- "data-block-parent": e._id,
78
- "data-style-id": `${a}-${e._id}`
79
- } : {}
80
- };
81
- }
82
- }), t;
83
- }
84
- const Ne = U((e) => {
85
- const s = G(e), t = d(s, "schema.properties", {});
86
- return Object.fromEntries(Object.entries(t).filter(([, a]) => d(a, "runtime", !1)));
87
- }), Be = (e, s) => {
88
- if (!C(e)) return e;
89
- let t = e, a;
90
- return typeof s.limit == "number" && s.limit > 0 && (a = s.limit), a !== void 0 && (t = t.slice(0, a)), t;
91
- }, De = (e, s) => {
92
- const t = L(e);
93
- return $(R(t), (a) => {
94
- if (N(t[a]) && !v(a, "_")) {
95
- let r = t[a];
96
- a === "repeaterItems" && (t.repeaterItemsBinding = r);
97
- const i = /\{\{(.*?)\}\}/g, c = r.match(i);
98
- c && c.forEach((n) => {
99
- let p = n.slice(2, -2);
100
- const h = d(s, p, n);
101
- r = C(h) ? h : r.replace(n, h);
102
- }), t[a] = r;
103
- }
104
- }), t;
105
- }, de = (e) => {
106
- const s = /(?: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
- return s.test(e) || t.test(e);
108
- }, he = (e) => {
109
- if (_(e)) return e;
110
- const s = /<video[^>]+src=['"]([^'">]+)['"]/, t = /<iframe[^>]+src=['"]([^'">]+)['"]/, a = e.match(s), r = e.match(t), i = a ? a[1] : r ? r[1] : null, c = /(?: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/;
111
- return i && (c.test(i) || n.test(i)) ? i : e;
112
- }, K = ["chai-name", "data-chai-name"], ge = {
113
- img: { alt: "alt", width: "width", height: "height", src: "image" },
114
- video: {
115
- src: "url",
116
- autoplay: "controls.autoPlay",
117
- muted: "controls.muted",
118
- loop: "controls.loop",
119
- controls: "controls.widgets"
120
- },
121
- a: {
122
- href: "link.href",
123
- target: "link.target",
124
- type: ""
125
- // @TODO: Detect here what to url, email, phone, elementId
126
- },
127
- input: {
128
- placeholder: "placeholder",
129
- required: "required",
130
- type: "inputType",
131
- name: "fieldName"
132
- },
133
- textarea: {
134
- placeholder: "placeholder",
135
- required: "required",
136
- type: "inputType",
137
- name: "fieldName"
138
- },
139
- select: {
140
- placeholder: "placeholder",
141
- required: "required",
142
- multiple: "multiple",
143
- name: "fieldName"
144
- },
145
- form: {
146
- action: "action"
147
- }
148
- }, ye = (e, s) => e.children.length === 1 && f(
149
- ["Heading", "Paragraph", "Span", "ListItem", "Button", "Label", "TableCell", "Link", "RichText"],
150
- s._type
151
- ), D = (e) => e.map((s) => s.type === "text" ? d(s, "content", "") : _(s.children) ? "" : D(s.children)).join(""), j = (e) => e === null ? "" : e, X = (e) => {
152
- const s = ae(se(e.split(/\s+/), re)), t = y(s, (n) => /^w-/.test(n)), a = y(s, (n) => /^h-/.test(n));
153
- if (!a || !t) return { height: "", width: "" };
154
- const r = (n) => {
155
- if (!n) return;
156
- const p = n.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);
157
- if (!p) return;
158
- if (p[1]) return p[1];
159
- const h = p[2];
160
- return /^\d+(\.\d+)?$/.test(h) ? `${Number(h) * 4}px` : h === "auto" || f(h, "%") ? h : "16px";
161
- }, i = r(t), c = r(a);
162
- return {
163
- width: f(i, "px") ? i : "16px",
164
- height: f(c, "px") ? c : "16px"
165
- };
166
- }, F = (e) => {
167
- if (e.tagName === "svg") return {};
168
- const s = {}, t = ge[e.tagName] || {}, a = e.attributes;
169
- return $(a, ({ key: r, value: i }) => {
170
- if (!f(K, r))
171
- if (t[r]) {
172
- if (e.tagName === "img" && r === "src" && !i.startsWith("http")) {
173
- const c = y(e.attributes, { key: "width" }), n = y(e.attributes, { key: "height" });
174
- c && n ? i = `https://via.placeholder.com/${c == null ? void 0 : c.value}x${n == null ? void 0 : n.value}` : i = "https://via.placeholder.com/150x150";
175
- }
176
- x(s, t[r], j(i));
177
- } else f(["style", "class", "srcset"], r) || (I(s, "styles_attrs") || (s.styles_attrs = {}), v(r, "@") && (r = r.replace("@", "x-on:")), s.styles_attrs[`${r}`] = j(i));
178
- }), delete s.class, s;
179
- }, me = (e, s = "styles") => {
180
- if (!e.attributes) return { [s]: `${b},` };
181
- const t = y(e.attributes, { key: "class" });
182
- if (t) {
183
- const a = t.value;
184
- return { [s]: `${b},${a}` };
185
- }
186
- return { [s]: `${b},` };
187
- }, be = (e) => {
188
- const s = d(e, "attributes", []), t = s.find((n) => n.key === "data-chai-richtext" || n.key === "chai-richtext"), a = s.find((n) => n.key === "data-chai-lightbox" || n.key === "chai-lightbox"), r = s.find((n) => n.key === "data-chai-dropdown" || n.key === "chai-dropdown"), i = s.find(
189
- (n) => n.key === "data-chai-dropdown-button" || n.key === "chai-dropdown-button"
190
- ), c = s.find(
191
- (n) => n.key === "data-chai-dropdown-content" || n.key === "chai-dropdown-content"
192
- );
193
- if (r)
194
- return { _type: "Dropdown" };
195
- if (i)
196
- return { _type: "DropdownButton" };
197
- if (c)
198
- return { _type: "DropdownContent" };
199
- if (t)
200
- return { _type: "RichText" };
201
- if (a)
202
- return { _type: "LightBoxLink" };
203
- switch (e.tagName) {
204
- // self closing tags
205
- case "img":
206
- return { _type: "Image" };
207
- case "input":
208
- return { _type: "Input", showLabel: !1 };
209
- // showLabel: hiding default block label
210
- case "hr":
211
- return { _type: "Divider" };
212
- case "br":
213
- return { _type: "LineBreak" };
214
- case "textarea":
215
- return { _type: "TextArea", showLabel: !1 };
216
- case "audio":
217
- return { _type: "Audio" };
218
- case "canvas":
219
- return { _type: "Canvas" };
220
- case "video":
221
- case "iframe":
222
- return { _type: "CustomHTML" };
223
- case "svg":
224
- return { _type: "Icon" };
225
- // non self closing tags
226
- // fixed structure
227
- case "select":
228
- return { _type: "Select", options: [] };
229
- case "option":
230
- return { _type: "Option" };
231
- case "ul":
232
- case "ol":
233
- case "dl":
234
- return {
235
- _type: "List",
236
- tag: e.tagName,
237
- _listType: e.tagName === "ol" ? "list-decimal" : "list-none"
238
- };
239
- case "li":
240
- case "dt":
241
- return { _type: "ListItem", tag: e.tagName };
242
- // non self closing tags
243
- // free flow structure
244
- case "span":
245
- case "figcaption":
246
- case "legend":
247
- return { _type: "Span", tag: e.tagName };
248
- case "p":
249
- return { _type: "Paragraph", content: "" };
250
- case "a":
251
- return { _type: "Link" };
252
- case "form":
253
- return { _type: "Form" };
254
- case "label":
255
- return { _type: "Label" };
256
- case "button":
257
- return { _type: "Button" };
258
- case "code":
259
- return { _type: "Box", _name: "Code" };
260
- case "h1":
261
- case "h2":
262
- case "h3":
263
- case "h4":
264
- case "h5":
265
- case "h6":
266
- return { _type: "Heading", tag: e.tagName };
267
- case "table":
268
- return { _type: "Table" };
269
- case "tr":
270
- return { _type: "TableRow" };
271
- case "td":
272
- case "th":
273
- return { _type: "TableCell", tag: e.tagName };
274
- case "thead":
275
- return { _type: "TableHead" };
276
- case "tbody":
277
- return { _type: "TableBody" };
278
- case "tfoot":
279
- return { _type: "TableFooter" };
280
- default: {
281
- const n = d(e, "children", []).length > 0 ? "Box" : "EmptyBox";
282
- return {
283
- _type: n,
284
- tag: e.tagName,
285
- _name: n == "EmptyBox" || e.tagName === "div" ? n : ne(e.tagName)
286
- };
287
- }
288
- }
289
- }, Z = (e, s = null) => ee(e, (t) => {
290
- var A, S, H, M, P, q, z, J, O, V;
291
- if (t.type === "comment") return [];
292
- let a = { _id: oe() };
293
- if (s && (a._parent = s.block._id), t.type === "text")
294
- return _(d(t, "content", "")) ? [] : s && ye(s.node, s.block) ? (x(s, "block.content", d(t, "content", "")), []) : { ...a, _type: "Text", content: d(t, "content", "") };
295
- const r = d(t, "attributes", []), i = r.find(
296
- (o) => o.key === "data-chai-richtext" || o.key === "chai-richtext"
297
- ), c = r.find(
298
- (o) => o.key === "data-chai-lightbox" || o.key === "chai-lightbox"
299
- ), n = r.find(
300
- (o) => o.key === "data-chai-dropdown" || o.key === "chai-dropdown"
301
- ), p = r.find(
302
- (o) => o.key === "data-chai-dropdown-button" || o.key === "chai-dropdown-button"
303
- ), h = r.find(
304
- (o) => o.key === "data-chai-dropdown-content" || o.key === "chai-dropdown-content"
305
- );
306
- if (a = {
307
- ...a,
308
- ...be(t),
309
- ...F(t),
310
- ...me(t)
311
- }, t.attributes) {
312
- const o = t.attributes.find((l) => f(K, l.key));
313
- o && (a._name = o.value);
314
- }
315
- if (i)
316
- return a.content = E(t.children), I(a, "styles_attrs.data-chai-richtext") && delete a.styles_attrs["data-chai-richtext"], I(a, "styles_attrs.chai-richtext") && delete a.styles_attrs["chai-richtext"], [a];
317
- if (c) {
318
- const o = [
319
- "data-chai-lightbox",
320
- "chai-lightbox",
321
- "data-vbtype",
322
- "data-autoplay",
323
- "data-maxwidth",
324
- "data-overlay",
325
- "data-gall",
326
- "href"
327
- ];
328
- a = {
329
- ...a,
330
- href: ((A = r.find((l) => l.key === "href")) == null ? void 0 : A.value) || "",
331
- hrefType: ((S = r.find((l) => l.key === "data-vbtype")) == null ? void 0 : S.value) || "video",
332
- autoplay: ((H = r.find((l) => l.key === "data-autoplay")) == null ? void 0 : H.value) === "true" ? "true" : "false",
333
- maxWidth: ((P = (M = r.find((l) => l.key === "data-maxwidth")) == null ? void 0 : M.value) == null ? void 0 : P.replace("px", "")) || "",
334
- backdropColor: ((q = r.find((l) => l.key === "data-overlay")) == null ? void 0 : q.value) || "",
335
- galleryName: ((z = r.find((l) => l.key === "data-gall")) == null ? void 0 : z.value) || ""
336
- }, $(o, (l) => {
337
- I(a, `styles_attrs.${l}`) && delete a.styles_attrs[l];
338
- });
339
- }
340
- if (n && (delete a.styles_attrs, a.showDropdown = !1), h && delete a.styles_attrs, p) {
341
- delete a.styles_attrs;
342
- const o = W(t.children || [], (u) => (u == null ? void 0 : u.tagName) !== "span");
343
- a.content = D(o);
344
- const l = y(
345
- t.children || [],
346
- (u) => (u == null ? void 0 : u.tagName) === "span" && te(u.children || [], (g) => (g == null ? void 0 : g.tagName) === "svg")
347
- );
348
- if (l) {
349
- const u = y(l.children || [], (g) => (g == null ? void 0 : g.tagName) === "svg");
350
- if (u) {
351
- a.icon = E([u]);
352
- const { height: g, width: w } = fe(u, "16px", "16px");
353
- a.iconHeight = g, a.iconWidth = w;
354
- }
355
- }
356
- return [a];
357
- }
358
- if (a._type === "Input") {
359
- const o = a.inputType || "text";
360
- o === "checkbox" ? x(a, "_type", "Checkbox") : o === "radio" && x(a, "_type", "Radio");
361
- } else if (t.tagName === "video" || t.tagName === "iframe") {
362
- const o = E([t]);
363
- return de(o) && (x(a, "_type", "Video"), x(a, "url", he(o)), x(a, "styles", `${b},`), x(a, "controls", { autoPlay: !1, muted: !0, loop: !1, controls: !1 })), a.content = o, [a];
364
- } else if (t.tagName === "svg") {
365
- const o = d(y(t.attributes, { key: "class" }), "value", ""), { height: l, width: u } = X(o);
366
- if (l && u)
367
- a.styles = `${b}, ${B(`w-${u} h-${l}`, o)}`.trim(), a.height = l == null ? void 0 : l.replace("px", ""), a.width = u == null ? void 0 : u.replace("px", "");
368
- else {
369
- const g = (J = y(t.attributes, { key: "height" })) == null ? void 0 : J.value, w = (O = y(t.attributes, { key: "width" })) == null ? void 0 : O.value;
370
- g && w ? (a.styles = `${b}, ${B(`w-[${w}px] h-[${g}px]`, o)}`.trim(), a.height = g, a.width = w) : a.styles = `${b}, ${B("w-full h-full", o)}`.trim();
371
- }
372
- return t.attributes = W(t.attributes, (g) => !f(["style", "width", "height", "class"], g.key)), a.icon = E([t]), [a];
373
- } else if (t.tagName == "option" && s && ((V = s.block) == null ? void 0 : V._type) === "Select")
374
- return s.block.options.push({
375
- label: D(t.children),
376
- ...F(t)
377
- }), [];
378
- const k = Z(t.children, { block: a, node: t });
379
- return [a, ...k];
380
- }), fe = (e, s, t) => {
381
- var p, h;
382
- const a = d(e, "attributes", []), { height: r, width: i } = X(
383
- d(y(a, { key: "class" }), "value", "")
384
- );
385
- if (r && i)
386
- return {
387
- height: `[${r}px]`,
388
- width: `[${i}px]`
389
- };
390
- const c = (p = y(a, { key: "height" })) == null ? void 0 : p.value, n = (h = y(a, { key: "width" })) == null ? void 0 : h.value;
391
- return {
392
- height: c ? `[${c}px]` : t,
393
- width: n ? `[${n}px]` : s
394
- };
395
- }, xe = (e) => {
396
- e = e.replace(/(\w+)=\\?"(.*?)\\?"/g, (a, r, i) => {
397
- let c = i.replace(/\\"/g, '"');
398
- return c = c.replace(/{([^}]+)}/g, (n) => n.replace(/"/g, '\\"')), `${r}="${c.replace(/\\"/g, '"')}"`;
399
- }), e = e.replace(/\\n/g, "").replace(/\\\\/g, "").replace(/\\([/<>])/g, "$1").replace(/\\./g, "").replace(/[\n\r\t\f\v]/g, ""), e = e.replace(/\$name="[^"]*"/g, "");
400
- const s = e.match(/<body[^>]*>[\s\S]*?<\/body>/);
401
- return (s && s.length > 0 ? s[0].replace(/<body/, "<div").replace(/<\/body>/, "</div>") : e).replace(/\s+/g, " ").replaceAll("> <", "><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").trim();
402
- }, Le = (e) => {
403
- const s = ce(xe(e));
404
- return _(e) ? [] : Q(Z(s));
405
- }, m = (e, s, { index: t, key: a }) => {
406
- if (N(e)) {
407
- let r = e;
408
- const i = /\{\{(.*?)\}\}/g, c = e.match(i);
409
- return c && c.forEach((n) => {
410
- let p = n.slice(2, -2).trim(), h = a.slice(2, -2).trim();
411
- t !== -1 && v(p, "$index.") ? p = `${h}.${t}.${p.slice(7)}` : t !== -1 && v(p, "$index") && (p = `${h}.${t}`);
412
- const k = d(s, p);
413
- k === void 0 ? r = r.replace(n, "") : r = C(k) ? k : r.replace(n, k);
414
- }), r;
415
- }
416
- if (C(e))
417
- return e.map((r) => m(r, s, { index: t, key: a }));
418
- if (e && typeof e == "object") {
419
- const r = {};
420
- return $(R(e), (i) => {
421
- !v(i, "_") && i !== "$repeaterItemsKey" ? r[i] = m(e[i], s, { index: t, key: a }) : r[i] = e[i];
422
- }), r;
423
- }
424
- return e;
425
- }, T = (e, s, { index: t, key: a }) => {
426
- let r = L(e);
427
- return r.repeaterItems && (r.$repeaterItemsKey = r.repeaterItems, v(r.repeaterItems, `{{${le}`) && (r.$repeaterItemsKey = r.repeaterItems = `${r.repeaterItems.replace("}}", `/${r._id}}}`)}`)), m(r, s, { index: t, key: a });
428
- };
429
- import.meta.vitest && (describe("applyBindingToValue", () => {
430
- it("should handle string values with bindings", () => {
431
- const t = m("Hello {{user.name}}", { user: { name: "John" } }, { index: -1, key: "" });
432
- expect(t).toBe("Hello John");
433
- }), it("should handle nested object properties", () => {
434
- const t = m({
435
- name: "John",
436
- address: {
437
- city: "{{user.city}}",
438
- street: "123 Main St"
439
- }
440
- }, { user: { city: "New York" } }, { index: -1, key: "" });
441
- expect(t).toEqual({
442
- name: "John",
443
- address: {
444
- city: "New York",
445
- street: "123 Main St"
446
- }
447
- });
448
- }), it("should handle arrays of values", () => {
449
- const t = m(["Hello {{user.name}}", "Welcome {{user.role}}"], { user: { name: "John", role: "Admin" } }, { index: -1, key: "" });
450
- expect(t).toEqual(["Hello John", "Welcome Admin"]);
451
- }), it("should handle $index binding in repeater context", () => {
452
- const t = m("Item {{$index}}", { items: ["a", "b", "c"] }, { index: 1, key: "{{items}}" });
453
- expect(t).toBe("Item b");
454
- }), it("should handle $index binding with dot notation", () => {
455
- const t = m("Item {{$index.value}}", { items: [{ value: "apple" }, { value: "banana" }, { value: "cherry" }] }, { index: 1, key: "{{items}}" });
456
- expect(t).toBe("Item banana");
457
- }), it("should return an empty string for non-existing bindings", () => {
458
- const t = m("Hello {{user.nonexistent}}", { user: { name: "John" } }, { index: -1, key: "" });
459
- expect(t).toBe("Hello ");
460
- }), it("should preserve private properties starting with _", () => {
461
- const s = m({
462
- name: "John",
463
- _private: "secret"
464
- }, {}, { index: -1, key: "" });
465
- expect(s).toEqual({
466
- name: "John",
467
- _private: "secret"
468
- });
469
- });
470
- }), describe("applyBindingToBlockProps", () => {
471
- it("should handle basic block with bindings", () => {
472
- const t = T({
473
- _id: "test-block",
474
- _type: "text",
475
- type: "text",
476
- content: "Hello {{user.name}}",
477
- style: {
478
- color: "{{theme.color}}"
479
- }
480
- }, { user: { name: "John" }, theme: { color: "blue" } }, { index: -1, key: "" });
481
- expect(t).toEqual({
482
- _id: "test-block",
483
- _type: "text",
484
- type: "text",
485
- content: "Hello John",
486
- style: {
487
- color: "blue"
488
- }
489
- });
490
- }), it("should handle repeaterItems and repeaterItemsBinding", () => {
491
- const t = T({
492
- _id: "test-block",
493
- _type: "repeater",
494
- type: "repeater",
495
- repeaterItems: "{{items}}",
496
- items: ["a", "b", "c"]
497
- }, { items: ["x", "y", "z"] }, { index: -1, key: "" });
498
- expect(t).toEqual({
499
- _id: "test-block",
500
- _type: "repeater",
501
- type: "repeater",
502
- $repeaterItemsKey: "{{items}}",
503
- repeaterItems: ["x", "y", "z"],
504
- items: ["a", "b", "c"]
505
- });
506
- }), it("should handle nested blocks with bindings", () => {
507
- const t = T({
508
- _id: "test-block",
509
- _type: "container",
510
- type: "container",
511
- children: [
512
- {
513
- _id: "child-block",
514
- _type: "text",
515
- type: "text",
516
- content: "Item {{$index}}",
517
- style: {
518
- color: "{{theme.color}}"
519
- }
520
- }
521
- ]
522
- }, { theme: { color: "red" }, items: ["x", "y", "z"] }, { index: 2, key: "{{items}}" });
523
- expect(t).toEqual({
524
- _id: "test-block",
525
- _type: "container",
526
- type: "container",
527
- children: [
528
- {
529
- _id: "child-block",
530
- _type: "text",
531
- type: "text",
532
- content: "Item z",
533
- style: {
534
- color: "red"
535
- }
536
- }
537
- ]
538
- });
539
- }), it("should handle arrays of blocks", () => {
540
- const t = T({
541
- _id: "test-block",
542
- _type: "list",
543
- type: "list",
544
- items: [
545
- { _id: "item1", content: "Item {{$index}}" },
546
- { _id: "item2", content: "Item {{$index}}" }
547
- ]
548
- }, { items: ["x", "y", "z"] }, { index: 0, key: "{{items}}" });
549
- expect(t).toEqual({
550
- _id: "test-block",
551
- _type: "list",
552
- type: "list",
553
- items: [
554
- { _id: "item1", content: "Item x" },
555
- { _id: "item2", content: "Item x" }
556
- ]
557
- });
558
- });
559
- }));
560
- export {
561
- le as C,
562
- Te as R,
563
- b as S,
564
- T as a,
565
- Ie as b,
566
- Ne as c,
567
- Be as d,
568
- De as e,
569
- Le as f,
570
- Ce as g,
571
- Y as h,
572
- Ee as i
573
- };