@chaibuilder/sdk 3.0.29 → 3.1.1

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.
@@ -0,0 +1 @@
1
+ "use strict";const B=require("./common-functions-BZmyleS1.cjs"),t=require("lodash-es"),_=require("himalaya"),O=require("@chaibuilder/runtime"),F=require("tailwind-merge"),m="#styles:",J="__ADD_BLOCK_INTERNAL_ROOT",z="@",H="#",V=s=>{if(s=s.replace(m,""),!s)return{baseClasses:"",classes:""};const n=s.split(/,(?![^\[]*\])/);if(n.length===1)return{baseClasses:"",classes:n[0].trim()};const[a,...e]=n;return{baseClasses:a.trim(),classes:e.join(",").trim().replace(/ +(?= )/g,"")}},Y=s=>{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(s)||a.test(s)},U=s=>{if(t.isEmpty(s))return s;const n=/<video[^>]+src=['"]([^'">]+)['"]/,a=/<iframe[^>]+src=['"]([^'">]+)['"]/,e=s.match(n),i=s.match(a),r=e?e[1]:i?i[1]:null,l=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,p=/(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;return r&&(l.test(r)||p.test(r))?r:s},M=["chai-name","data-chai-name"],K={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"}},X=(s,n)=>s.children.length===1&&t.includes(["Heading","Paragraph","Span","ListItem","Button","Label","TableCell","Link","RichText"],n._type),T=s=>s.map(n=>n.type==="text"?t.get(n,"content",""):t.isEmpty(n.children)?"":T(n.children)).join(""),v=s=>s===null?"":s,W=s=>{const n=t.compact(t.map(s.split(/\s+/),t.trim)),a=t.find(n,p=>/^w-/.test(p)),e=t.find(n,p=>/^h-/.test(p));if(!e||!a)return{height:"",width:""};const i=p=>{if(!p)return;const h=p.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);if(!h)return;if(h[1])return h[1];const o=h[2];return/^\d+(\.\d+)?$/.test(o)?`${Number(o)*4}px`:o==="auto"||t.includes(o,"%")?o:"16px"},r=i(a),l=i(e);return{width:t.includes(r,"px")?r:"16px",height:t.includes(l,"px")?l:"16px"}},q=s=>{if(s.tagName==="svg")return{};const n={},a=K[s.tagName]||{},e=s.attributes;return t.forEach(e,({key:i,value:r})=>{if(!t.includes(M,i))if(a[i]){if(s.tagName==="img"&&i==="src"&&!r.startsWith("http")){const l=t.find(s.attributes,{key:"width"}),p=t.find(s.attributes,{key:"height"});l&&p?r=`https://via.placeholder.com/${l==null?void 0:l.value}x${p==null?void 0:p.value}`:r="https://via.placeholder.com/150x150"}t.set(n,a[i],v(r))}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}`]=v(r))}),delete n.class,n},Z=(s,n="styles")=>{if(!s.attributes)return{[n]:`${m},`};const a=t.find(s.attributes,{key:"class"});if(a){const e=a.value;return{[n]:`${m},${e}`}}return{[n]:`${m},`}},G=s=>{const n=t.get(s,"attributes",[]),a=n.find(o=>o.key==="data-chai-richtext"||o.key==="chai-richtext"),e=n.find(o=>o.key==="data-chai-lightbox"||o.key==="chai-lightbox"),i=n.find(o=>o.key==="data-chai-dropdown"||o.key==="chai-dropdown"),r=n.find(o=>o.key==="data-chai-dropdown-button"||o.key==="chai-dropdown-button"),l=n.find(o=>o.key==="data-chai-dropdown-content"||o.key==="chai-dropdown-content"),p=n.find(o=>o.key==="class"),h=p&&p.value.split(/\s+/).includes("rte");if(i)return{_type:"Dropdown"};if(r)return{_type:"DropdownButton"};if(l)return{_type:"DropdownContent"};if(a||h)return{_type:"Paragraph"};if(e)return{_type:"LightBoxLink"};switch(s.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:s.tagName,_listType:s.tagName==="ol"?"list-decimal":"list-none"};case"li":case"dt":return{_type:"ListItem",tag:s.tagName};case"span":case"figcaption":case"legend":return{_type:"Span",tag:s.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:s.tagName};case"table":return{_type:"Table"};case"tr":return{_type:"TableRow"};case"td":case"th":return{_type:"TableCell",tag:s.tagName};case"thead":return{_type:"TableHead"};case"tbody":return{_type:"TableBody"};case"tfoot":return{_type:"TableFooter"};default:{const o=t.get(s,"children",[]).length>0?"Box":"EmptyBox";return{_type:o,tag:s.tagName,_name:o=="EmptyBox"||s.tagName==="div"?o:t.capitalize(s.tagName)}}}},E=(s,n=null)=>t.flatMapDeep(s,a=>{var I,$,C,S,D,N,L,A,R,j;if(a.type==="comment")return[];let e={_id:B.generateUUID()};if(n&&(e._parent=n.block._id),a.type==="text")return t.isEmpty(t.get(a,"content",""))?[]:n&&X(n.node,n.block)?(t.set(n,"block.content",t.get(a,"content","")),[]):{...e,_type:"Text",content:t.get(a,"content","")};if(t.startsWith(a.tagName,"chai-")){const c=a.attributes,u=t.find(c,{key:"chai-type"}),d=(u==null?void 0:u.value)||t.startCase(a.tagName.replace("chai-","")).replace(/\s+/g,"");e._type=d,t.forEach(c,({key:y,value:P})=>{if(y==="about-this-component"||y==="chai-type"||y==="can-move"||y==="can-delete")return;if(y==="id"){e._id=P;return}let b=v(P);typeof b=="string"&&t.startsWith(b,"#styles:")&&(b=b.replace("#styles:","#styles:,")),e[y]=b});const g=E(a.children,{block:e,node:a});return[e,...g]}const i=t.get(a,"attributes",[]),r=i.find(c=>c.key==="data-chai-richtext"||c.key==="chai-richtext"),l=i.find(c=>c.key==="class"),p=l&&l.value.split(/\s+/).includes("rte"),h=i.find(c=>c.key==="data-chai-lightbox"||c.key==="chai-lightbox"),o=i.find(c=>c.key==="data-chai-dropdown"||c.key==="chai-dropdown"),f=i.find(c=>c.key==="data-chai-dropdown-button"||c.key==="chai-dropdown-button"),k=i.find(c=>c.key==="data-chai-dropdown-content"||c.key==="chai-dropdown-content");if(e={...e,...G(a),...q(a),...Z(a)},a.attributes){const c=a.attributes.find(u=>t.includes(M,u.key));c&&(e._name=c.value)}if(r||p)return e.content=_.stringify(a.children),t.has(e,"styles_attrs.data-chai-richtext")&&delete e.styles_attrs["data-chai-richtext"],t.has(e,"styles_attrs.chai-richtext")&&delete e.styles_attrs["chai-richtext"],[e];if(h){const c=["data-chai-lightbox","chai-lightbox","data-vbtype","data-autoplay","data-maxwidth","data-overlay","data-gall","href"];e={...e,href:((I=i.find(u=>u.key==="href"))==null?void 0:I.value)||"",hrefType:(($=i.find(u=>u.key==="data-vbtype"))==null?void 0:$.value)||"video",autoplay:((C=i.find(u=>u.key==="data-autoplay"))==null?void 0:C.value)==="true"?"true":"false",maxWidth:((D=(S=i.find(u=>u.key==="data-maxwidth"))==null?void 0:S.value)==null?void 0:D.replace("px",""))||"",backdropColor:((N=i.find(u=>u.key==="data-overlay"))==null?void 0:N.value)||"",galleryName:((L=i.find(u=>u.key==="data-gall"))==null?void 0:L.value)||""},t.forEach(c,u=>{t.has(e,`styles_attrs.${u}`)&&delete e.styles_attrs[u]})}if(o&&(delete e.styles_attrs,e.showDropdown=!1),k&&delete e.styles_attrs,f){delete e.styles_attrs;const c=t.filter(a.children||[],d=>(d==null?void 0:d.tagName)!=="span");e.content=T(c);const u=t.find(a.children||[],d=>(d==null?void 0:d.tagName)==="span"&&t.some(d.children||[],g=>(g==null?void 0:g.tagName)==="svg"));if(u){const d=t.find(u.children||[],g=>(g==null?void 0:g.tagName)==="svg");if(d){e.icon=_.stringify([d]);const{height:g,width:y}=Q(d,"16px","16px");e.iconHeight=g,e.iconWidth=y}}return[e]}if(e._type==="Input"){const c=e.inputType||"text";c==="checkbox"?t.set(e,"_type","Checkbox"):c==="radio"&&t.set(e,"_type","Radio")}else if(a.tagName==="video"||a.tagName==="iframe"){const c=_.stringify([a]);return Y(c)&&(t.set(e,"_type","Video"),t.set(e,"url",U(c)),t.set(e,"styles",`${m},`),t.set(e,"controls",{autoPlay:!1,muted:!0,loop:!1,controls:!1})),e.content=c,[e]}else if(a.tagName==="svg"){const c=t.get(t.find(a.attributes,{key:"class"}),"value",""),{height:u,width:d}=W(c);if(u&&d)e.styles=`${m}, ${B.cn(`w-${d} h-${u}`,c)}`.trim(),e.height=u==null?void 0:u.replace("px",""),e.width=d==null?void 0:d.replace("px","");else{const g=(A=t.find(a.attributes,{key:"height"}))==null?void 0:A.value,y=(R=t.find(a.attributes,{key:"width"}))==null?void 0:R.value;g&&y?(e.styles=`${m}, ${B.cn(`w-[${y}px] h-[${g}px]`,c)}`.trim(),e.height=g,e.width=y):e.styles=`${m}, ${B.cn("w-full h-full",c)}`.trim()}return a.attributes=t.filter(a.attributes,g=>!t.includes(["style","width","height","class"],g.key)),e.icon=_.stringify([a]),[e]}else if(a.tagName=="option"&&n&&((j=n.block)==null?void 0:j._type)==="Select")return n.block.options.push({label:T(a.children),...q(a)}),[];const x=E(a.children,{block:e,node:a});return[e,...x]}),Q=(s,n,a)=>{var h,o;const e=t.get(s,"attributes",[]),{height:i,width:r}=W(t.get(t.find(e,{key:"class"}),"value",""));if(i&&r)return{height:`[${i}px]`,width:`[${r}px]`};const l=(h=t.find(e,{key:"height"}))==null?void 0:h.value,p=(o=t.find(e,{key:"width"}))==null?void 0:o.value;return{height:l?`[${l}px]`:a,width:p?`[${p}px]`:n}},tt=s=>{s=s.replace(/(\w+)=\\?"(.*?)\\?"/g,(e,i,r)=>{let l=r.replace(/\\"/g,'"');return l=l.replace(/{([^}]+)}/g,p=>p.replace(/"/g,'\\"')),`${i}="${l.replace(/\\"/g,'"')}"`}),s=s.replace(/\\n/g,"").replace(/\\\\/g,"").replace(/\\([/<>])/g,"$1").replace(/\\./g,"").replace(/[\n\r\t\f\v]/g,""),s=s.replace(/\$name="[^"]*"/g,"");const n=s.match(/<body[^>]*>[\s\S]*?<\/body>/);return(n&&n.length>0?n[0].replace(/<body/,"<div").replace(/<\/body>/,"</div>"):s).replace(/\s+/g," ").replaceAll("> <","><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").trim()},et=(s,n)=>t.find(s,{_id:n}),st=(s,n)=>t.isEmpty(n)?s:t.map(s,a=>{const e=et(n,a._id);return e?{...e,...a}:a}),at=s=>{const n=_.parse(tt(s));return t.isEmpty(s)?[]:t.flatten(E(n))};function nt(s,n,a){const e=t.get(a,"i18nProps",[]);if(t.isEmpty(n)||t.isEmpty(e))return s;const i=t.cloneDeep(s);return t.forEach(t.keys(i),r=>{if(t.includes(e,r)&&!t.isEmpty(n)){const l=t.get(i,r),p=t.get(i,`${r}-${n}`,"");t.isString(l)?i[r]=t.isString(p)&&!t.isEmpty(p.trim())&&p.trimStart()||l:i[r]=t.isEmpty(p)?l:p}}),i}const rt=t.memoize(s=>{const{baseClasses:n,classes:a}=V(s);return F.twMerge(n,a)});function ot(s,n){return t.get(s,`${n}_attrs`,{})}function lt(s,n=!0){const a={};return Object.keys(s).forEach(e=>{if(t.isString(s[e])&&s[e].startsWith(m)){const i=rt(s[e]),r=ot(s,e);a[e]={...!t.isEmpty(i)&&{className:i},...r,...n?{"data-style-prop":e,"data-block-parent":s._id,"data-style-id":`${e}-${s._id}`}:{}}}}),a}const ct=t.memoize(s=>{const n=O.getRegisteredChaiBlock(s),a=t.get(n,"schema.properties",{});return Object.fromEntries(Object.entries(a).filter(([,e])=>t.get(e,"runtime",!1)))}),pt=(s,n)=>{if(!t.isArray(s))return s;let a=s,e;return typeof n.limit=="number"&&n.limit>0&&(e=n.limit),e!==void 0&&(a=a.slice(0,e)),a},ut=(s,n)=>{const a=t.cloneDeep(s);return t.forEach(t.keys(a),e=>{if(t.isString(a[e])&&!t.startsWith(e,"_")){let i=a[e];e==="repeaterItems"&&(a.repeaterItemsBinding=i);const r=/\{\{(.*?)\}\}/g,l=i.match(r);l&&l.forEach(p=>{let h=p.slice(2,-2);const o=t.get(n,h,p);i=t.isArray(o)?o:i.replace(p,o)}),a[e]=i}}),a},dt=s=>{const n=t.last(s);return s.map(a=>{const e=Object.keys(a);for(let i=0;i<e.length;i++)if(t.isString(a[e[i]])&&t.startsWith(e[i],"content")){const r=a===n?"":" ";a[e[i]]=`${a[e[i]].trim()}${r}`}return a})},w=(s,n,{index:a,key:e},i)=>{if(t.isString(s)){let r=s;const l=/\{\{(.*?)\}\}/g,p=s.match(l);if(p){const h=i==="image"||i==="mobileImage";p.forEach(o=>{let f=o.slice(2,-2).trim(),k=e.slice(2,-2).trim();a!==-1&&t.startsWith(f,"$index.")?f=`${k}.${a}.${f.slice(7)}`:a!==-1&&t.startsWith(f,"$index")&&(f=`${k}.${a}`);const x=t.get(n,f);x===void 0?r=r.replace(o,""):h&&!t.isArray(x)?r=x:r=t.isArray(x)?x:r.replace(o,x)})}return r}if(t.isArray(s))return s.map(r=>w(r,n,{index:a,key:e},i));if(s&&typeof s=="object"){const r={};return t.forEach(t.keys(s),l=>{!t.startsWith(l,"_")&&l!=="$repeaterItemsKey"?r[l]=w(s[l],n,{index:a,key:e},l):r[l]=s[l]}),r}return s},gt=(s,n,{index:a,key:e})=>{let i=t.cloneDeep(s);return i.repeaterItems&&(i.$repeaterItemsKey=i.repeaterItems,t.startsWith(i.repeaterItems,`{{${H}`)&&(i.$repeaterItemsKey=i.repeaterItems=`${i.repeaterItems.replace("}}",`/${i._id}}}`)}`),!t.isEmpty(i.repeaterItems)&&i.pagination&&(i.repeaterTotalItems=`${i.repeaterItems.replace("}}",`/${i._id}/totalItems}}`)}`)),w(i,n,{index:a,key:e})};exports.COLLECTION_PREFIX=H;exports.REPEATER_PREFIX=z;exports.ROOT_TEMP_KEY=J;exports.STYLES_KEY=m;exports.adjustSpacingInContentBlocks=dt;exports.applyBindingToBlockProps=gt;exports.applyChaiDataBinding=ut;exports.applyLanguage=nt;exports.applyLimit=pt;exports.getBlockRuntimeProps=ct;exports.getBlockTagAttributes=lt;exports.getBlocksFromHTML=at;exports.getSplitChaiClasses=V;exports.mergeBlocksWithExisting=st;