@chaibuilder/sdk 3.0.9 → 3.0.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/apply-binding-B0CX8mDS.js +641 -0
- package/dist/apply-binding-DSgP62np.cjs +1 -0
- package/dist/core.cjs +3 -3
- package/dist/core.js +797 -697
- package/dist/render.cjs +2 -2
- package/dist/render.js +72 -69
- package/dist/web-blocks.cjs +1 -1
- package/dist/web-blocks.js +369 -300
- package/package.json +2 -3
- package/dist/apply-binding-HQ9gBNJP.cjs +0 -1
- package/dist/apply-binding-tfi-KyyV.js +0 -573
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"author": "Suraj Air",
|
|
6
6
|
"license": "BSD-3-Clause",
|
|
7
7
|
"homepage": "https://chaibuilder.com",
|
|
8
|
-
"version": "3.0.
|
|
8
|
+
"version": "3.0.11",
|
|
9
9
|
"type": "module",
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -132,7 +132,7 @@
|
|
|
132
132
|
"react-colorful": "5.6.1",
|
|
133
133
|
"react-error-boundary": "^6.0.0",
|
|
134
134
|
"react-hotkeys-hook": "5.1.0",
|
|
135
|
-
"react-i18next": "
|
|
135
|
+
"react-i18next": "16.0.0",
|
|
136
136
|
"react-wrap-balancer": "^1.1.1",
|
|
137
137
|
"sonner": "^2.0.7",
|
|
138
138
|
"tailwind-merge": "^3.3.1",
|
|
@@ -163,7 +163,6 @@
|
|
|
163
163
|
"eslint-plugin-react-refresh": "^0.4.18",
|
|
164
164
|
"husky": "^9.1.7",
|
|
165
165
|
"jest-environment-jsdom": "^29.7.0",
|
|
166
|
-
"jotai-devtools": "0.13.0",
|
|
167
166
|
"jsdoc": "^4.0.4",
|
|
168
167
|
"msw": "^2.7.0",
|
|
169
168
|
"postcss": "^8.5.1",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";const q=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 n=e.split(/,(?![^\[]*\])/);if(n.length===1)return{baseClasses:"",classes:n[0].trim()};const[a,...s]=n;return{baseClasses:a.trim(),classes:s.join(",").trim().replace(/ +(?= )/g,"")}};function z(e,n,a){const s=t.get(a,"i18nProps",[]);if(t.isEmpty(n)||t.isEmpty(s))return e;const i=t.cloneDeep(e);return t.forEach(t.keys(i),l=>{if(t.includes(s,l)&&!t.isEmpty(n)){const c=t.get(i,`${l}-${n}`,""),r=t.get(i,l,"");i[l]=t.isString(c)&&c.trim()||r}}),i}const F=t.memoize(e=>{const{baseClasses:n,classes:a}=A(e);return V.twMerge(n,a)});function J(e,n){return t.get(e,`${n}_attrs`,{})}function Y(e,n=!0){const a={};return Object.keys(e).forEach(s=>{if(t.isString(e[s])&&e[s].startsWith(y)){const i=F(e[s]),l=J(e,s);a[s]={...!t.isEmpty(i)&&{className:i},...l,...n?{"data-style-prop":s,"data-block-parent":e._id,"data-style-id":`${s}-${e._id}`}:{}}}}),a}const j=t.memoize(e=>{const n=q.getRegisteredChaiBlock(e),a=t.get(n,"schema.properties",{});return Object.fromEntries(Object.entries(a).filter(([,s])=>t.get(s,"runtime",!1)))}),K=(e,n)=>{if(!t.isArray(e))return e;let a=e,s;return typeof n.limit=="number"&&n.limit>0&&(s=n.limit),s!==void 0&&(a=a.slice(0,s)),a},U=(e,n)=>{const a=t.cloneDeep(e);return t.forEach(t.keys(a),s=>{if(t.isString(a[s])&&!t.startsWith(s,"_")){let i=a[s];s==="repeaterItems"&&(a.repeaterItemsBinding=i);const l=/\{\{(.*?)\}\}/g,c=i.match(l);c&&c.forEach(r=>{let u=r.slice(2,-2);const g=t.get(n,u,r);i=t.isArray(g)?g:i.replace(r,g)}),a[s]=i}}),a},X=e=>{const n=/(?: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 n.test(e)||a.test(e)},Z=e=>{if(t.isEmpty(e))return e;const n=/<video[^>]+src=['"]([^'">]+)['"]/,a=/<iframe[^>]+src=['"]([^'">]+)['"]/,s=e.match(n),i=e.match(a),l=s?s[1]:i?i[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,n)=>e.children.length===1&&t.includes(["Heading","Paragraph","Span","ListItem","Button","Label","TableCell","Link","RichText"],n._type),_=e=>e.map(n=>n.type==="text"?t.get(n,"content",""):t.isEmpty(n.children)?"":_(n.children)).join(""),L=e=>e===null?"":e,H=e=>{const n=t.compact(t.map(e.split(/\s+/),t.trim)),a=t.find(n,r=>/^w-/.test(r)),s=t.find(n,r=>/^h-/.test(r));if(!s||!a)return{height:"",width:""};const i=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=i(a),c=i(s);return{width:t.includes(l,"px")?l:"16px",height:t.includes(c,"px")?c:"16px"}},R=e=>{if(e.tagName==="svg")return{};const n={},a=G[e.tagName]||{},s=e.attributes;return t.forEach(s,({key:i,value:l})=>{if(!t.includes(P,i))if(a[i]){if(e.tagName==="img"&&i==="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(n,a[i],L(l))}else t.includes(["style","class","srcset"],i)||(t.has(n,"styles_attrs")||(n.styles_attrs={}),t.startsWith(i,"@")&&(i=i.replace("@","x-on:")),n.styles_attrs[`${i}`]=L(l))}),delete n.class,n},ee=(e,n="styles")=>{if(!e.attributes)return{[n]:`${y},`};const a=t.find(e.attributes,{key:"class"});if(a){const s=a.value;return{[n]:`${y},${s}`}}return{[n]:`${y},`}},te=e=>{const n=t.get(e,"attributes",[]),a=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"),i=n.find(r=>r.key==="data-chai-dropdown"||r.key==="chai-dropdown"),l=n.find(r=>r.key==="data-chai-dropdown-button"||r.key==="chai-dropdown-button"),c=n.find(r=>r.key==="data-chai-dropdown-content"||r.key==="chai-dropdown-content");if(i)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)}}}},M=(e,n=null)=>t.flatMapDeep(e,a=>{var E,w,v,T,$,B,C,I,D,N;if(a.type==="comment")return[];let s={_id:x.generateUUID()};if(n&&(s._parent=n.block._id),a.type==="text")return t.isEmpty(t.get(a,"content",""))?[]:n&&Q(n.node,n.block)?(t.set(n,"block.content",t.get(a,"content","")),[]):{...s,_type:"Text",content:t.get(a,"content","")};const i=t.get(a,"attributes",[]),l=i.find(o=>o.key==="data-chai-richtext"||o.key==="chai-richtext"),c=i.find(o=>o.key==="data-chai-lightbox"||o.key==="chai-lightbox"),r=i.find(o=>o.key==="data-chai-dropdown"||o.key==="chai-dropdown"),u=i.find(o=>o.key==="data-chai-dropdown-button"||o.key==="chai-dropdown-button"),g=i.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:((E=i.find(p=>p.key==="href"))==null?void 0:E.value)||"",hrefType:((w=i.find(p=>p.key==="data-vbtype"))==null?void 0:w.value)||"video",autoplay:((v=i.find(p=>p.key==="data-autoplay"))==null?void 0:v.value)==="true"?"true":"false",maxWidth:(($=(T=i.find(p=>p.key==="data-maxwidth"))==null?void 0:T.value)==null?void 0:$.replace("px",""))||"",backdropColor:((B=i.find(p=>p.key==="data-overlay"))==null?void 0:B.value)||"",galleryName:((C=i.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}=H(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=(D=t.find(a.attributes,{key:"width"}))==null?void 0:D.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"&&n&&((N=n.block)==null?void 0:N._type)==="Select")return n.block.options.push({label:_(a.children),...R(a)}),[];const m=M(a.children,{block:s,node:a});return[s,...m]}),se=(e,n,a)=>{var u,g;const s=t.get(e,"attributes",[]),{height:i,width:l}=H(t.get(t.find(s,{key:"class"}),"value",""));if(i&&l)return{height:`[${i}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]`:n}},ae=e=>{e=e.replace(/(\w+)=\\?"(.*?)\\?"/g,(s,i,l)=>{let c=l.replace(/\\"/g,'"');return c=c.replace(/{([^}]+)}/g,r=>r.replace(/"/g,'\\"')),`${i}="${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 n=e.match(/<body[^>]*>[\s\S]*?<\/body>/);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()},ne=e=>{const n=b.parse(ae(e));return t.isEmpty(e)?[]:t.flatten(M(n))},k=(e,n,{index:a,key:s})=>{if(t.isString(e)){let i=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(n,u);m===void 0?i=i.replace(r,""):i=t.isArray(m)?m:i.replace(r,m)}),i}if(t.isArray(e))return e.map(i=>k(i,n,{index:a,key:s}));if(e&&typeof e=="object"){const i={};return t.forEach(t.keys(e),l=>{!t.startsWith(l,"_")&&l!=="$repeaterItemsKey"?i[l]=k(e[l],n,{index:a,key:s}):i[l]=e[l]}),i}return e},ie=(e,n,{index:a,key:s})=>{let i=t.cloneDeep(e);return i.repeaterItems&&(i.$repeaterItemsKey=i.repeaterItems,t.startsWith(i.repeaterItems,`{{${S}`)&&(i.$repeaterItemsKey=i.repeaterItems=`${i.repeaterItems.replace("}}",`/${i._id}}}`)}`)),k(i,n,{index:a,key:s})};exports.COLLECTION_PREFIX=S;exports.REPEATER_PREFIX=O;exports.ROOT_TEMP_KEY=W;exports.STYLES_KEY=y;exports.applyBindingToBlockProps=ie;exports.applyChaiDataBinding=U;exports.applyLanguage=z;exports.applyLimit=K;exports.getBlockRuntimeProps=j;exports.getBlockTagAttributes=Y;exports.getBlocksFromHTML=ne;exports.getSplitChaiClasses=A;
|
|
@@ -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
|
-
};
|