@chaibuilder/sdk 2.6.2 → 2.6.4
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-CxkQxWx3.cjs +1 -0
- package/dist/apply-binding-OTp8TO_7.js +570 -0
- package/dist/core.cjs +4 -4
- package/dist/core.js +2446 -2694
- package/dist/render.cjs +2 -2
- package/dist/render.d.ts +7 -0
- package/dist/render.js +42 -41
- package/dist/web-blocks.cjs +1 -1
- package/dist/web-blocks.js +125 -139
- package/package.json +3 -3
- package/dist/apply-binding-BL-JPMms.js +0 -267
- package/dist/apply-binding-T3HdSezj.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";const H=require("@chaibuilder/runtime"),t=require("lodash-es"),V=require("tailwind-merge"),x=require("./common-functions-BZmyleS1.cjs"),b=require("himalaya"),y="#styles:",W="__ADD_BLOCK_INTERNAL_ROOT",O="@",S="#",A=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[a,...s]=i;return{baseClasses:a.trim(),classes:s.join(",").trim().replace(/ +(?= )/g,"")}};function z(e,i,a){const s=t.get(a,"i18nProps",[]);if(t.isEmpty(i)||t.isEmpty(s))return e;const n=t.cloneDeep(e);return t.forEach(t.keys(n),l=>{if(t.includes(s,l)&&!t.isEmpty(i)){const c=t.get(n,`${l}-${i}`,""),r=t.get(n,l,"");n[l]=t.isString(c)&&c.trim()||r}}),n}const F=t.memoize(e=>{const{baseClasses:i,classes:a}=A(e);return V.twMerge(i,a)});function J(e,i){return t.get(e,`${i}_attrs`,{})}function Y(e,i=!0){const a={};return Object.keys(e).forEach(s=>{if(t.isString(e[s])&&e[s].startsWith(y)){const n=F(e[s]),l=J(e,s);a[s]={...!t.isEmpty(n)&&{className:n},...l,...i?{"data-style-prop":s,"data-block-parent":e._id,"data-style-id":`${s}-${e._id}`}:{}}}}),a}const j=t.memoize(e=>{const i=H.getRegisteredChaiBlock(e),a=t.get(i,"schema.properties",{});return Object.fromEntries(Object.entries(a).filter(([,s])=>t.get(s,"runtime",!1)))}),K=(e,i)=>{if(!t.isArray(e))return e;let a=e,s;return typeof i.limit=="number"&&i.limit>0&&(s=i.limit),s!==void 0&&(a=a.slice(0,s)),a},U=(e,i)=>{const a=t.cloneDeep(e);return t.forEach(t.keys(a),s=>{if(t.isString(a[s])&&!t.startsWith(s,"_")){let n=a[s];s==="repeaterItems"&&(a.repeaterItemsBinding=n);const l=/\{\{(.*?)\}\}/g,c=n.match(l);c&&c.forEach(r=>{let u=r.slice(2,-2);const g=t.get(i,u,r);n=t.isArray(g)?g:n.replace(r,g)}),a[s]=n}}),a},X=e=>{const i=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,a=/(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;return i.test(e)||a.test(e)},Z=e=>{if(t.isEmpty(e))return e;const i=/<video[^>]+src=['"]([^'">]+)['"]/,a=/<iframe[^>]+src=['"]([^'">]+)['"]/,s=e.match(i),n=e.match(a),l=s?s[1]:n?n[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/;return l&&(c.test(l)||r.test(l))?l: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(""),L=e=>e===null?"":e,M=e=>{const i=t.compact(t.map(e.split(/\s+/),t.trim)),a=t.find(i,r=>/^w-/.test(r)),s=t.find(i,r=>/^h-/.test(r));if(!s||!a)return{height:"",width:""};const n=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"},l=n(a),c=n(s);return{width:t.includes(l,"px")?l:"16px",height:t.includes(c,"px")?c:"16px"}},R=e=>{if(e.tagName==="svg")return{};const i={},a=G[e.tagName]||{},s=e.attributes;return t.forEach(s,({key:n,value:l})=>{if(!t.includes(P,n))if(a[n]){if(e.tagName==="img"&&n==="src"&&!l.startsWith("http")){const c=t.find(e.attributes,{key:"width"}),r=t.find(e.attributes,{key:"height"});c&&r?l=`https://via.placeholder.com/${c==null?void 0:c.value}x${r==null?void 0:r.value}`:l="https://via.placeholder.com/150x150"}t.set(i,a[n],L(l))}else t.includes(["style","class","srcset"],n)||(t.has(i,"styles_attrs")||(i.styles_attrs={}),t.startsWith(n,"@")&&(n=n.replace("@","x-on:")),i.styles_attrs[`${n}`]=L(l))}),delete i.class,i},ee=(e,i="styles")=>{if(!e.attributes)return{[i]:`${y},`};const a=t.find(e.attributes,{key:"class"});if(a){const s=a.value;return{[i]:`${y},${s}`}}return{[i]:`${y},`}},te=e=>{const i=t.get(e,"attributes",[]),a=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"),n=i.find(r=>r.key==="data-chai-dropdown"||r.key==="chai-dropdown"),l=i.find(r=>r.key==="data-chai-dropdown-button"||r.key==="chai-dropdown-button"),c=i.find(r=>r.key==="data-chai-dropdown-content"||r.key==="chai-dropdown-content");if(n)return{_type:"Dropdown"};if(l)return{_type:"DropdownButton"};if(c)return{_type:"DropdownContent"};if(a)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)}}}},q=(e,i=null)=>t.flatMapDeep(e,a=>{var w,E,v,T,$,B,C,I,N,D;if(a.type==="comment")return[];let s={_id:x.generateUUID()};if(i&&(s._parent=i.block._id),a.type==="text")return t.isEmpty(t.get(a,"content",""))?[]:i&&Q(i.node,i.block)?(t.set(i,"block.content",t.get(a,"content","")),[]):{...s,_type:"Text",content:t.get(a,"content","")};const n=t.get(a,"attributes",[]),l=n.find(o=>o.key==="data-chai-richtext"||o.key==="chai-richtext"),c=n.find(o=>o.key==="data-chai-lightbox"||o.key==="chai-lightbox"),r=n.find(o=>o.key==="data-chai-dropdown"||o.key==="chai-dropdown"),u=n.find(o=>o.key==="data-chai-dropdown-button"||o.key==="chai-dropdown-button"),g=n.find(o=>o.key==="data-chai-dropdown-content"||o.key==="chai-dropdown-content");if(s={...s,...te(a),...R(a),...ee(a)},a.attributes){const o=a.attributes.find(p=>t.includes(P,p.key));o&&(s._name=o.value)}if(l)return s.content=b.stringify(a.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(c){const o=["data-chai-lightbox","chai-lightbox","data-vbtype","data-autoplay","data-maxwidth","data-overlay","data-gall","href"];s={...s,href:((w=n.find(p=>p.key==="href"))==null?void 0:w.value)||"",hrefType:((E=n.find(p=>p.key==="data-vbtype"))==null?void 0:E.value)||"video",autoplay:((v=n.find(p=>p.key==="data-autoplay"))==null?void 0:v.value)==="true"?"true":"false",maxWidth:(($=(T=n.find(p=>p.key==="data-maxwidth"))==null?void 0:T.value)==null?void 0:$.replace("px",""))||"",backdropColor:((B=n.find(p=>p.key==="data-overlay"))==null?void 0:B.value)||"",galleryName:((C=n.find(p=>p.key==="data-gall"))==null?void 0:C.value)||""},t.forEach(o,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 o=t.filter(a.children||[],d=>(d==null?void 0:d.tagName)!=="span");s.content=_(o);const p=t.find(a.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=b.stringify([d]);const{height:h,width:f}=se(d,"16px","16px");s.iconHeight=h,s.iconWidth=f}}return[s]}if(s._type==="Input"){const o=s.inputType||"text";o==="checkbox"?t.set(s,"_type","Checkbox"):o==="radio"&&t.set(s,"_type","Radio")}else if(a.tagName==="video"||a.tagName==="iframe"){const o=b.stringify([a]);return X(o)&&(t.set(s,"_type","Video"),t.set(s,"url",Z(o)),t.set(s,"styles",`${y},`),t.set(s,"controls",{autoPlay:!1,muted:!0,loop:!1,controls:!1})),s.content=o,[s]}else if(a.tagName==="svg"){const o=t.get(t.find(a.attributes,{key:"class"}),"value",""),{height:p,width:d}=M(o);if(p&&d)s.styles=`${y}, ${x.cn(`w-${d} h-${p}`,o)}`.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(a.attributes,{key:"height"}))==null?void 0:I.value,f=(N=t.find(a.attributes,{key:"width"}))==null?void 0:N.value;h&&f?(s.styles=`${y}, ${x.cn(`w-[${f}px] h-[${h}px]`,o)}`.trim(),s.height=h,s.width=f):s.styles=`${y}, ${x.cn("w-full h-full",o)}`.trim()}return a.attributes=t.filter(a.attributes,h=>!t.includes(["style","width","height","class"],h.key)),s.icon=b.stringify([a]),[s]}else if(a.tagName=="option"&&i&&((D=i.block)==null?void 0:D._type)==="Select")return i.block.options.push({label:_(a.children),...R(a)}),[];const m=q(a.children,{block:s,node:a});return[s,...m]}),se=(e,i,a)=>{var u,g;const s=t.get(e,"attributes",[]),{height:n,width:l}=M(t.get(t.find(s,{key:"class"}),"value",""));if(n&&l)return{height:`[${n}px]`,width:`[${l}px]`};const c=(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:c?`[${c}px]`:a,width:r?`[${r}px]`:i}},ae=e=>{e=e.replace(/(\w+)=\\?"(.*?)\\?"/g,(s,n,l)=>{let c=l.replace(/\\"/g,'"');return c=c.replace(/{([^}]+)}/g,r=>r.replace(/"/g,'\\"')),`${n}="${c.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()},ie=e=>{const i=b.parse(ae(e));return t.isEmpty(e)?[]:t.flatten(q(i))},k=(e,i,{index:a,key:s})=>{if(t.isString(e)){let n=e;const l=/\{\{(.*?)\}\}/g,c=e.match(l);return c&&c.forEach(r=>{let u=r.slice(2,-2).trim(),g=s.slice(2,-2).trim();a!==-1&&t.startsWith(u,"$index.")?u=`${g}.${a}.${u.slice(7)}`:a!==-1&&t.startsWith(u,"$index")&&(u=`${g}.${a}`);const m=t.get(i,u,r);n=t.isArray(m)?m:n.replace(r,m)}),n}if(t.isArray(e))return e.map(n=>k(n,i,{index:a,key:s}));if(e&&typeof e=="object"){const n={};return t.forEach(t.keys(e),l=>{!t.startsWith(l,"_")&&l!=="$repeaterItemsKey"?n[l]=k(e[l],i,{index:a,key:s}):n[l]=e[l]}),n}return e},ne=(e,i,{index:a,key:s})=>{let n=t.cloneDeep(e);return n.repeaterItems&&(n.$repeaterItemsKey=n.repeaterItems,t.startsWith(n.repeaterItems,`{{${S}`)&&(n.$repeaterItemsKey=n.repeaterItems=`${n.repeaterItems.replace("}}",`/${n._id}}}`)}`)),k(n,i,{index:a,key:s})};exports.COLLECTION_PREFIX=S;exports.REPEATER_PREFIX=O;exports.ROOT_TEMP_KEY=W;exports.STYLES_KEY=y;exports.applyBindingToBlockProps=ne;exports.applyChaiDataBinding=U;exports.applyLanguage=z;exports.applyLimit=K;exports.getBlockRuntimeProps=j;exports.getBlockTagAttributes=Y;exports.getBlocksFromHTML=ie;exports.getSplitChaiClasses=A;
|
|
@@ -0,0 +1,570 @@
|
|
|
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 k, isArray as C, isEmpty as _, includes as f, flatten as Q, flatMapDeep as ee, set as x, has as I, filter as J, find as y, some as te, compact as se, map as ae, 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 T } from "himalaya";
|
|
6
|
+
const m = "#styles:", Te = "__ADD_BLOCK_INTERNAL_ROOT", Ee = "@", le = "#", Y = (e) => {
|
|
7
|
+
if (e = e.replace(m, ""), !e) return { baseClasses: "", classes: "" };
|
|
8
|
+
const a = e.split(/,(?![^\[]*\])/);
|
|
9
|
+
if (a.length === 1)
|
|
10
|
+
return { baseClasses: "", classes: a[0].trim() };
|
|
11
|
+
const [t, ...s] = a;
|
|
12
|
+
return {
|
|
13
|
+
baseClasses: t.trim(),
|
|
14
|
+
classes: s.join(",").trim().replace(/ +(?= )/g, "")
|
|
15
|
+
};
|
|
16
|
+
};
|
|
17
|
+
import.meta.vitest && describe("getSplitChaiClasses", () => {
|
|
18
|
+
it("should return the base classes and the classes", () => {
|
|
19
|
+
const e = {
|
|
20
|
+
",styles-2": { baseClasses: "", classes: "styles-2" },
|
|
21
|
+
"styles-1,styles-2": { baseClasses: "styles-1", classes: "styles-2" },
|
|
22
|
+
",bg-[linear-gradient(-10deg,black,transparent_100%)]": {
|
|
23
|
+
baseClasses: "",
|
|
24
|
+
classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
|
|
25
|
+
},
|
|
26
|
+
"styles-1,bg-[linear-gradient(-10deg,black,transparent_100%)]": {
|
|
27
|
+
baseClasses: "styles-1",
|
|
28
|
+
classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
|
|
29
|
+
},
|
|
30
|
+
someclass: {
|
|
31
|
+
baseClasses: "",
|
|
32
|
+
classes: "someclass"
|
|
33
|
+
},
|
|
34
|
+
",bg-red-500 text-center font-bold": {
|
|
35
|
+
baseClasses: "",
|
|
36
|
+
classes: "bg-red-500 text-center font-bold"
|
|
37
|
+
},
|
|
38
|
+
"bg-[linear-gradient(-10deg,black,transparent_100%)], bg-[linear-gradient(-10deg,black,transparent_100%)]": {
|
|
39
|
+
baseClasses: "bg-[linear-gradient(-10deg,black,transparent_100%)]",
|
|
40
|
+
classes: "bg-[linear-gradient(-10deg,black,transparent_100%)]"
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
for (let a in e) {
|
|
44
|
+
const t = Y(`${m}${a}`);
|
|
45
|
+
expect(t).toEqual(e[a]);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
function Ie(e, a, t) {
|
|
50
|
+
const s = d(t, "i18nProps", []);
|
|
51
|
+
if (_(a) || _(s)) return e;
|
|
52
|
+
const r = L(e);
|
|
53
|
+
return $(R(r), (i) => {
|
|
54
|
+
if (f(s, i) && !_(a)) {
|
|
55
|
+
const c = d(r, `${i}-${a}`, ""), n = d(r, i, "");
|
|
56
|
+
r[i] = N(c) && c.trim() || n;
|
|
57
|
+
}
|
|
58
|
+
}), r;
|
|
59
|
+
}
|
|
60
|
+
const pe = U((e) => {
|
|
61
|
+
const { baseClasses: a, classes: t } = Y(e);
|
|
62
|
+
return ie(a, t);
|
|
63
|
+
});
|
|
64
|
+
function ue(e, a) {
|
|
65
|
+
return d(e, `${a}_attrs`, {});
|
|
66
|
+
}
|
|
67
|
+
function Ce(e, a = !0) {
|
|
68
|
+
const t = {};
|
|
69
|
+
return Object.keys(e).forEach((s) => {
|
|
70
|
+
if (N(e[s]) && e[s].startsWith(m)) {
|
|
71
|
+
const r = pe(e[s]), i = ue(e, s);
|
|
72
|
+
t[s] = {
|
|
73
|
+
...!_(r) && { className: r },
|
|
74
|
+
...i,
|
|
75
|
+
...a ? {
|
|
76
|
+
"data-style-prop": s,
|
|
77
|
+
"data-block-parent": e._id,
|
|
78
|
+
"data-style-id": `${s}-${e._id}`
|
|
79
|
+
} : {}
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
}), t;
|
|
83
|
+
}
|
|
84
|
+
const Ne = U((e) => {
|
|
85
|
+
const a = G(e), t = d(a, "schema.properties", {});
|
|
86
|
+
return Object.fromEntries(Object.entries(t).filter(([, s]) => d(s, "runtime", !1)));
|
|
87
|
+
}), Be = (e, a) => {
|
|
88
|
+
if (!C(e)) return e;
|
|
89
|
+
let t = e, s;
|
|
90
|
+
return typeof a.limit == "number" && a.limit > 0 && (s = a.limit), s !== void 0 && (t = t.slice(0, s)), t;
|
|
91
|
+
}, De = (e, a) => {
|
|
92
|
+
const t = L(e);
|
|
93
|
+
return $(R(t), (s) => {
|
|
94
|
+
if (N(t[s]) && !k(s, "_")) {
|
|
95
|
+
let r = t[s];
|
|
96
|
+
s === "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(a, p, n);
|
|
101
|
+
r = C(h) ? h : r.replace(n, h);
|
|
102
|
+
}), t[s] = r;
|
|
103
|
+
}
|
|
104
|
+
}), t;
|
|
105
|
+
}, de = (e) => {
|
|
106
|
+
const a = /(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/, t = /(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;
|
|
107
|
+
return a.test(e) || t.test(e);
|
|
108
|
+
}, he = (e) => {
|
|
109
|
+
if (_(e)) return e;
|
|
110
|
+
const a = /<video[^>]+src=['"]([^'">]+)['"]/, t = /<iframe[^>]+src=['"]([^'">]+)['"]/, s = e.match(a), r = e.match(t), i = s ? s[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, a) => e.children.length === 1 && f(
|
|
149
|
+
["Heading", "Paragraph", "Span", "ListItem", "Button", "Label", "TableCell", "Link", "RichText"],
|
|
150
|
+
a._type
|
|
151
|
+
), D = (e) => e.map((a) => a.type === "text" ? d(a, "content", "") : _(a.children) ? "" : D(a.children)).join(""), j = (e) => e === null ? "" : e, X = (e) => {
|
|
152
|
+
const a = se(ae(e.split(/\s+/), re)), t = y(a, (n) => /^w-/.test(n)), s = y(a, (n) => /^h-/.test(n));
|
|
153
|
+
if (!s || !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(s);
|
|
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 a = {}, t = ge[e.tagName] || {}, s = e.attributes;
|
|
169
|
+
return $(s, ({ 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(a, t[r], j(i));
|
|
177
|
+
} else f(["style", "class", "srcset"], r) || (I(a, "styles_attrs") || (a.styles_attrs = {}), k(r, "@") && (r = r.replace("@", "x-on:")), a.styles_attrs[`${r}`] = j(i));
|
|
178
|
+
}), delete a.class, a;
|
|
179
|
+
}, me = (e, a = "styles") => {
|
|
180
|
+
if (!e.attributes) return { [a]: `${m},` };
|
|
181
|
+
const t = y(e.attributes, { key: "class" });
|
|
182
|
+
if (t) {
|
|
183
|
+
const s = t.value;
|
|
184
|
+
return { [a]: `${m},${s}` };
|
|
185
|
+
}
|
|
186
|
+
return { [a]: `${m},` };
|
|
187
|
+
}, be = (e) => {
|
|
188
|
+
const a = d(e, "attributes", []), t = a.find((n) => n.key === "data-chai-richtext" || n.key === "chai-richtext"), s = a.find((n) => n.key === "data-chai-lightbox" || n.key === "chai-lightbox"), r = a.find((n) => n.key === "data-chai-dropdown" || n.key === "chai-dropdown"), i = a.find(
|
|
189
|
+
(n) => n.key === "data-chai-dropdown-button" || n.key === "chai-dropdown-button"
|
|
190
|
+
), c = a.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 (s)
|
|
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, a = null) => ee(e, (t) => {
|
|
290
|
+
var A, S, H, M, P, q, z, O, V, W;
|
|
291
|
+
if (t.type === "comment") return [];
|
|
292
|
+
let s = { _id: oe() };
|
|
293
|
+
if (a && (s._parent = a.block._id), t.type === "text")
|
|
294
|
+
return _(d(t, "content", "")) ? [] : a && ye(a.node, a.block) ? (x(a, "block.content", d(t, "content", "")), []) : { ...s, _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 (s = {
|
|
307
|
+
...s,
|
|
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 && (s._name = o.value);
|
|
314
|
+
}
|
|
315
|
+
if (i)
|
|
316
|
+
return s.content = T(t.children), I(s, "styles_attrs.data-chai-richtext") && delete s.styles_attrs["data-chai-richtext"], I(s, "styles_attrs.chai-richtext") && delete s.styles_attrs["chai-richtext"], [s];
|
|
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
|
+
s = {
|
|
329
|
+
...s,
|
|
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(s, `styles_attrs.${l}`) && delete s.styles_attrs[l];
|
|
338
|
+
});
|
|
339
|
+
}
|
|
340
|
+
if (n && (delete s.styles_attrs, s.showDropdown = !1), h && delete s.styles_attrs, p) {
|
|
341
|
+
delete s.styles_attrs;
|
|
342
|
+
const o = J(t.children || [], (u) => (u == null ? void 0 : u.tagName) !== "span");
|
|
343
|
+
s.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
|
+
s.icon = T([u]);
|
|
352
|
+
const { height: g, width: v } = fe(u, "16px", "16px");
|
|
353
|
+
s.iconHeight = g, s.iconWidth = v;
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
return [s];
|
|
357
|
+
}
|
|
358
|
+
if (s._type === "Input") {
|
|
359
|
+
const o = s.inputType || "text";
|
|
360
|
+
o === "checkbox" ? x(s, "_type", "Checkbox") : o === "radio" && x(s, "_type", "Radio");
|
|
361
|
+
} else if (t.tagName === "video" || t.tagName === "iframe") {
|
|
362
|
+
const o = T([t]);
|
|
363
|
+
return de(o) && (x(s, "_type", "Video"), x(s, "url", he(o)), x(s, "styles", `${m},`), x(s, "controls", { autoPlay: !1, muted: !0, loop: !1, controls: !1 })), s.content = o, [s];
|
|
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
|
+
s.styles = `${m}, ${B(`w-${u} h-${l}`, o)}`.trim(), s.height = l == null ? void 0 : l.replace("px", ""), s.width = u == null ? void 0 : u.replace("px", "");
|
|
368
|
+
else {
|
|
369
|
+
const g = (O = y(t.attributes, { key: "height" })) == null ? void 0 : O.value, v = (V = y(t.attributes, { key: "width" })) == null ? void 0 : V.value;
|
|
370
|
+
g && v ? (s.styles = `${m}, ${B(`w-[${v}px] h-[${g}px]`, o)}`.trim(), s.height = g, s.width = v) : s.styles = `${m}, ${B("w-full h-full", o)}`.trim();
|
|
371
|
+
}
|
|
372
|
+
return t.attributes = J(t.attributes, (g) => !f(["style", "width", "height", "class"], g.key)), s.icon = T([t]), [s];
|
|
373
|
+
} else if (t.tagName == "option" && a && ((W = a.block) == null ? void 0 : W._type) === "Select")
|
|
374
|
+
return a.block.options.push({
|
|
375
|
+
label: D(t.children),
|
|
376
|
+
...F(t)
|
|
377
|
+
}), [];
|
|
378
|
+
const w = Z(t.children, { block: s, node: t });
|
|
379
|
+
return [s, ...w];
|
|
380
|
+
}), fe = (e, a, t) => {
|
|
381
|
+
var p, h;
|
|
382
|
+
const s = d(e, "attributes", []), { height: r, width: i } = X(
|
|
383
|
+
d(y(s, { key: "class" }), "value", "")
|
|
384
|
+
);
|
|
385
|
+
if (r && i)
|
|
386
|
+
return {
|
|
387
|
+
height: `[${r}px]`,
|
|
388
|
+
width: `[${i}px]`
|
|
389
|
+
};
|
|
390
|
+
const c = (p = y(s, { key: "height" })) == null ? void 0 : p.value, n = (h = y(s, { key: "width" })) == null ? void 0 : h.value;
|
|
391
|
+
return {
|
|
392
|
+
height: c ? `[${c}px]` : t,
|
|
393
|
+
width: n ? `[${n}px]` : a
|
|
394
|
+
};
|
|
395
|
+
}, xe = (e) => {
|
|
396
|
+
e = e.replace(/(\w+)=\\?"(.*?)\\?"/g, (s, 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 a = e.match(/<body[^>]*>[\s\S]*?<\/body>/);
|
|
401
|
+
return (a && a.length > 0 ? a[0].replace(/<body/, "<div").replace(/<\/body>/, "</div>") : e).replace(/\s+/g, " ").replaceAll("> <", "><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, "").trim();
|
|
402
|
+
}, Le = (e) => {
|
|
403
|
+
const a = ce(xe(e));
|
|
404
|
+
return _(e) ? [] : Q(Z(a));
|
|
405
|
+
}, b = (e, a, { index: t, key: s }) => {
|
|
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 = s.slice(2, -2).trim();
|
|
411
|
+
t !== -1 && k(p, "$index.") ? p = `${h}.${t}.${p.slice(7)}` : t !== -1 && k(p, "$index") && (p = `${h}.${t}`);
|
|
412
|
+
const w = d(a, p, n);
|
|
413
|
+
r = C(w) ? w : r.replace(n, w);
|
|
414
|
+
}), r;
|
|
415
|
+
}
|
|
416
|
+
if (C(e))
|
|
417
|
+
return e.map((r) => b(r, a, { index: t, key: s }));
|
|
418
|
+
if (e && typeof e == "object") {
|
|
419
|
+
const r = {};
|
|
420
|
+
return $(R(e), (i) => {
|
|
421
|
+
!k(i, "_") && i !== "$repeaterItemsKey" ? r[i] = b(e[i], a, { index: t, key: s }) : r[i] = e[i];
|
|
422
|
+
}), r;
|
|
423
|
+
}
|
|
424
|
+
return e;
|
|
425
|
+
}, E = (e, a, { index: t, key: s }) => {
|
|
426
|
+
let r = L(e);
|
|
427
|
+
return r.repeaterItems && (r.$repeaterItemsKey = r.repeaterItems, k(r.repeaterItems, `{{${le}`) && (r.$repeaterItemsKey = r.repeaterItems = `${r.repeaterItems.replace("}}", `/${r._id}}}`)}`)), b(r, a, { index: t, key: s });
|
|
428
|
+
};
|
|
429
|
+
import.meta.vitest && (describe("applyBindingToValue", () => {
|
|
430
|
+
it("should handle string values with bindings", () => {
|
|
431
|
+
const t = b("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 = b({
|
|
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 = b(["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 = b("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 = b("Item {{$index.value}}", { items: [{ value: "apple" }, { value: "banana" }, { value: "cherry" }] }, { index: 1, key: "{{items}}" });
|
|
456
|
+
expect(t).toBe("Item banana");
|
|
457
|
+
}), it("should preserve private properties starting with _", () => {
|
|
458
|
+
const a = b({
|
|
459
|
+
name: "John",
|
|
460
|
+
_private: "secret"
|
|
461
|
+
}, {}, { index: -1, key: "" });
|
|
462
|
+
expect(a).toEqual({
|
|
463
|
+
name: "John",
|
|
464
|
+
_private: "secret"
|
|
465
|
+
});
|
|
466
|
+
});
|
|
467
|
+
}), describe("applyBindingToBlockProps", () => {
|
|
468
|
+
it("should handle basic block with bindings", () => {
|
|
469
|
+
const t = E({
|
|
470
|
+
_id: "test-block",
|
|
471
|
+
_type: "text",
|
|
472
|
+
type: "text",
|
|
473
|
+
content: "Hello {{user.name}}",
|
|
474
|
+
style: {
|
|
475
|
+
color: "{{theme.color}}"
|
|
476
|
+
}
|
|
477
|
+
}, { user: { name: "John" }, theme: { color: "blue" } }, { index: -1, key: "" });
|
|
478
|
+
expect(t).toEqual({
|
|
479
|
+
_id: "test-block",
|
|
480
|
+
_type: "text",
|
|
481
|
+
type: "text",
|
|
482
|
+
content: "Hello John",
|
|
483
|
+
style: {
|
|
484
|
+
color: "blue"
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
}), it("should handle repeaterItems and repeaterItemsBinding", () => {
|
|
488
|
+
const t = E({
|
|
489
|
+
_id: "test-block",
|
|
490
|
+
_type: "repeater",
|
|
491
|
+
type: "repeater",
|
|
492
|
+
repeaterItems: "{{items}}",
|
|
493
|
+
items: ["a", "b", "c"]
|
|
494
|
+
}, { items: ["x", "y", "z"] }, { index: -1, key: "" });
|
|
495
|
+
expect(t).toEqual({
|
|
496
|
+
_id: "test-block",
|
|
497
|
+
_type: "repeater",
|
|
498
|
+
type: "repeater",
|
|
499
|
+
$repeaterItemsKey: "{{items}}",
|
|
500
|
+
repeaterItems: ["x", "y", "z"],
|
|
501
|
+
items: ["a", "b", "c"]
|
|
502
|
+
});
|
|
503
|
+
}), it("should handle nested blocks with bindings", () => {
|
|
504
|
+
const t = E({
|
|
505
|
+
_id: "test-block",
|
|
506
|
+
_type: "container",
|
|
507
|
+
type: "container",
|
|
508
|
+
children: [
|
|
509
|
+
{
|
|
510
|
+
_id: "child-block",
|
|
511
|
+
_type: "text",
|
|
512
|
+
type: "text",
|
|
513
|
+
content: "Item {{$index}}",
|
|
514
|
+
style: {
|
|
515
|
+
color: "{{theme.color}}"
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
]
|
|
519
|
+
}, { theme: { color: "red" }, items: ["x", "y", "z"] }, { index: 2, key: "{{items}}" });
|
|
520
|
+
expect(t).toEqual({
|
|
521
|
+
_id: "test-block",
|
|
522
|
+
_type: "container",
|
|
523
|
+
type: "container",
|
|
524
|
+
children: [
|
|
525
|
+
{
|
|
526
|
+
_id: "child-block",
|
|
527
|
+
_type: "text",
|
|
528
|
+
type: "text",
|
|
529
|
+
content: "Item z",
|
|
530
|
+
style: {
|
|
531
|
+
color: "red"
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
]
|
|
535
|
+
});
|
|
536
|
+
}), it("should handle arrays of blocks", () => {
|
|
537
|
+
const t = E({
|
|
538
|
+
_id: "test-block",
|
|
539
|
+
_type: "list",
|
|
540
|
+
type: "list",
|
|
541
|
+
items: [
|
|
542
|
+
{ _id: "item1", content: "Item {{$index}}" },
|
|
543
|
+
{ _id: "item2", content: "Item {{$index}}" }
|
|
544
|
+
]
|
|
545
|
+
}, { items: ["x", "y", "z"] }, { index: 0, key: "{{items}}" });
|
|
546
|
+
expect(t).toEqual({
|
|
547
|
+
_id: "test-block",
|
|
548
|
+
_type: "list",
|
|
549
|
+
type: "list",
|
|
550
|
+
items: [
|
|
551
|
+
{ _id: "item1", content: "Item x" },
|
|
552
|
+
{ _id: "item2", content: "Item x" }
|
|
553
|
+
]
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
}));
|
|
557
|
+
export {
|
|
558
|
+
le as C,
|
|
559
|
+
Ee as R,
|
|
560
|
+
m as S,
|
|
561
|
+
E as a,
|
|
562
|
+
Ie as b,
|
|
563
|
+
Ne as c,
|
|
564
|
+
Be as d,
|
|
565
|
+
De as e,
|
|
566
|
+
Le as f,
|
|
567
|
+
Ce as g,
|
|
568
|
+
Y as h,
|
|
569
|
+
Te as i
|
|
570
|
+
};
|