@chaibuilder/sdk 2.2.12 → 2.2.14

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/core.cjs CHANGED
@@ -57,7 +57,7 @@
57
57
  outline: 1px solid ${a.length===1?"#42a1fc !important":"orange !important"}; outline-offset: -1px;
58
58
  }`)},[a,m]),React.useEffect(()=>{x.textContent=i?`[data-block-id="${i._id}"], [data-block-id="${i._id}"] > * { pointer-events: none !important; opacity: 0.6 !important}`:""},[i,x]),React.useEffect(()=>{u&&(u.textContent='[data-highlighted="true"]{ outline: 1px solid #42a1fc !important; outline-offset: -1px;}')},[u]),React.useEffect(()=>{h&&(h.textContent=`${lodashEs.map(l,({id:k})=>`[data-style-id="${k}"]`).join(",")}{
59
59
  outline: 1px solid orange !important; outline-offset: -1px;
60
- }`)},[l,h]),React.useEffect(()=>{c.querySelector("#drop-target-block").innerHTML=d?`[data-block-id="${d}"]{ outline: 1px dashed orange !important; outline-offset: -1px;}`:""},[d,c]);const f=React.useMemo(()=>{const{heading:k,body:S}={heading:lodashEs.get(o,"fontFamily.heading"),body:lodashEs.get(o,"fontFamily.body")};return g.filter(v=>v.family===k||v.family===S)},[o==null?void 0:o.fontFamily,g]),j=React.useMemo(()=>plugin.getThemeFontsLinkMarkup(lodashEs.filter(f,k=>lodashEs.has(k,"url"))),[f]),b=React.useMemo(()=>plugin.getThemeCustomFontFace(lodashEs.filter(f,k=>lodashEs.has(k,"src"))),[f]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(CssThemeVariables,{theme:o}),jsxRuntime.jsx("span",{id:"chai-fonts",dangerouslySetInnerHTML:{__html:j}}),jsxRuntime.jsx("style",{id:"chai-custom-fonts",dangerouslySetInnerHTML:{__html:b}})]})},ResizableCanvasWrapper=({children:o,onMount:n,onResize:a})=>{const[,r]=useSelectedBlockIds(),[,l]=useSelectedStylingBlocks(),i=React.useRef(null),d=web.useDebouncedCallback(()=>{const{clientWidth:p}=i.current;a(p)},[i.current],100);web.useResizeObserver(i.current,d,i.current!==null),React.useEffect(()=>{const{clientWidth:p}=i.current;n(p)},[]);const c=()=>{r([]),l([])};return jsxRuntime.jsx("div",{id:"main-content",onClick:c,className:"h-full w-full p-8 pb-0",ref:i,children:o})},useBlockRuntimeProps=()=>{const[o]=useBlocksStore();return React.useCallback((n,a)=>lodashEs.isEmpty(a)?{}:Object.entries(a).reduce((r,[l,i])=>{const d=[];let c=lodashEs.find(o,{_id:n});for(;c;)d.push(c),c=lodashEs.find(o,{_id:c._parent});const p=lodashEs.find(d,{_type:i.block});return p&&(r[l]=lodashEs.get(p,lodashEs.get(i,"prop"),null)),r},{}),[o])},RepeaterContext=React.createContext({index:-1,key:""}),BlockRenderer=({blockAtom:o,children:n})=>{const[a]=jotai.useAtom(o),r=React.useMemo(()=>runtime.getRegisteredChaiBlock(a._type),[a._type]),{selectedLang:l,fallbackLang:i}=useLanguages(),d=useBlockRuntimeProps(),c=usePageExternalData(),[p]=useHiddenBlockIds(),[u]=jotai.useAtom(dataBindingActiveAtom),m=lodashEs.get(r,"component",null),{index:h,key:x}=React.useContext(RepeaterContext),g=React.useMemo(()=>u?newBlocksRenderHelpers.applyBinding(newBlocksRenderHelpers.applyLanguage(a,l,r),c,{index:h,key:x}):newBlocksRenderHelpers.applyLanguage(a,l,r),[a,l,r,c,u,h,x]),f=React.useMemo(()=>newBlocksRenderHelpers.getBlockTagAttributes(a),[a,newBlocksRenderHelpers.getBlockTagAttributes]),j=React.useMemo(()=>d(a._id,newBlocksRenderHelpers.getBlockRuntimeProps(a._type)),[a._id,a._type,d,newBlocksRenderHelpers.getBlockRuntimeProps]),b=React.useMemo(()=>!lodashEs.has(r,"dataProvider")||!lodashEs.isFunction(r.dataProvider)?{}:r.dataProvider({block:a,draft:!0,inBuilder:!0,lang:l||i,pageProps:{}}),[a,l,i,r,c]),k=React.useMemo(()=>({blockProps:{"data-block-id":a._id,"data-block-type":a._type},inBuilder:!0,lang:l||i,...g,...f,...j,...b}),[a._id,a._type,l,i,g,f,j,b]);return lodashEs.isNull(m)||p.includes(a._id)?null:jsxRuntime.jsx(React.Suspense,{children:React.createElement(m,{...k,children:n({_id:a._id,_type:a._type,...lodashEs.isArray(g.repeaterItems)?{repeaterItems:newBlocksRenderHelpers.applyLimit(g.repeaterItems,a),repeaterItemsBinding:g.repeaterItemsBinding}:{},...a.partialBlockId?{partialBlockId:a.partialBlockId}:"",...a.globalBlock?{partialBlockId:a.globalBlock}:""})})})},PartialBlocksRenderer=({partialBlockId:o})=>{const{getPartailBlocks:n}=usePartialBlocksStore(),a=React.useMemo(()=>n(o),[n,o]),r=React.useMemo(()=>utils.splitAtom(jotai.atom(a)),[a]);return lodashEs.isEmpty(a)?null:jsxRuntime.jsx(BlocksRenderer,{splitAtoms:r,blocks:a})},BlocksRenderer=({blocks:o,parent:n=null,splitAtoms:a=void 0})=>{const r=useGetBlockAtom(a),l=React.useMemo(()=>lodashEs.filter(o,d=>lodashEs.has(d,"_id")&&(lodashEs.isEmpty(n)?!d._parent:d._parent===n)),[o,n]),i=React.useCallback(d=>lodashEs.filter(o,c=>c._parent===d).length>0,[o]);return lodashEs.map(l,d=>{const c=r(d._id);return c?jsxRuntime.jsx(BlockRenderer,{blockAtom:c,children:({_id:p,_type:u,partialBlockId:m,repeaterItems:h,repeaterItemsBinding:x})=>u==="Repeater"?lodashEs.isArray(h)&&h.map((g,f)=>jsxRuntime.jsx(RepeaterContext.Provider,{value:{index:f,key:x},children:jsxRuntime.jsx(BlocksRenderer,{splitAtoms:a,blocks:o,parent:d._id})})):u==="GlobalBlock"||u==="PartialBlock"?jsxRuntime.jsx(jotai.Provider,{store:builderStore,children:jsxRuntime.jsx(PartialBlocksRenderer,{partialBlockId:m})}):i(p)?jsxRuntime.jsx(BlocksRenderer,{splitAtoms:a,blocks:o,parent:d._id}):null},d._id):null})},PageBlocksRenderer=()=>{const[o]=useBlocksStore();return jsxRuntime.jsx(BlocksRenderer,{splitAtoms:pageBlocksAtomsAtom,blocks:o})},StaticBlocksRenderer=()=>{const[o]=useBlocksStore(),n=lodashEs.isEmpty(o)?null:jsxRuntime.jsx(PageBlocksRenderer,{});return jsxRuntime.jsx(jsxRuntime.Fragment,{children:n})},useCanvasScale=o=>{const[n]=useCanvasDisplayWidth(),[,a]=useCanvasZoom(),r=useBuilderProp("htmlDir","ltr"),[l,i]=React.useState({}),d=React.useCallback(()=>{const{width:c,height:p}=o;if(c<n){const u=parseFloat((c/n).toFixed(2).toString());let m={};const h=p*u,x=c*u;p&&(m={height:100+(p-h)/h*100+"%",width:100+(c-x)/x*100+"%"}),i({position:"relative",top:0,transform:`scale(${u})`,transformOrigin:r==="rtl"?"top right":"top left",...m,maxWidth:"none"}),a(u*100)}else i({}),a(100)},[n,o,r,a]);return React.useEffect(()=>{d()},[n,o,a,d]),l},getElementByStyleId=(o,n)=>o.querySelector(`[data-style-id="${n}"]`),StaticCanvas=()=>{const[o]=jotai.useAtom(networkModeAtom),[n]=useCanvasDisplayWidth(),[,a]=useSelectedBlockIds(),r=useSelectedBlock(),[,l]=useHighlightBlockId(),i=React.useRef(null),d=React.useRef(null),[c,p]=React.useState({width:0,height:0}),u=useCanvasScale(c),[m,h]=React.useState([]),[,x]=React.useState([]),[,g]=jotai.useAtom(canvasIframeAtom),[f,j]=useSelectedStylingBlocks(),b=useBuilderProp("loading",!1),k=useBuilderProp("htmlDir","ltr"),S=B=>{p(R=>({...R,width:B}))};React.useEffect(()=>{if(!d.current)return;const{clientWidth:B,clientHeight:R}=d.current;p({width:B,height:R})},[d,n]);const v=(B,R=0)=>{const{top:C}=B.getBoundingClientRect();return C+R>=0&&C-R<=window.innerHeight};React.useEffect(()=>{var B,R;if(r!=null&&r._id&&r.type!=="Multiple"&&i.current){const C=getElementByDataBlockId(i.current.contentDocument,r._id);C&&(v(C)||(R=(B=i.current)==null?void 0:B.contentWindow)==null||R.scrollTo({top:C.offsetTop,behavior:"smooth"}),h([C]))}},[r==null?void 0:r._id,r==null?void 0:r.type]),React.useEffect(()=>{if(!lodashEs.isEmpty(f)&&i.current){const B=getElementByStyleId(i.current.contentDocument,lodashEs.first(f).id);x(B?[B]:[null])}else x([null])},[f]);const A=React.useMemo(()=>{let B=IframeInitialContent;return B=B.replace("__HTML_DIR__",k),o==="offline"&&(B=B.replace("https://chaibuilder.com/offline/tailwind.cdn.js","/offline/tailwind.cdn.js")),B},[o,k]);return jsxRuntime.jsx(ResizableCanvasWrapper,{onMount:S,onResize:S,children:jsxRuntime.jsx("div",{onClick:()=>{a([]),j([])},onMouseLeave:()=>setTimeout(()=>l(""),300),className:"relative mx-auto h-full w-full overflow-hidden",ref:d,children:jsxRuntime.jsxs(ChaiFrame,{contentDidMount:()=>g(i.current),ref:i,id:"canvas-iframe",style:{...u,...lodashEs.isEmpty(u)?{width:`${n}px`}:{}},className:"relative mx-auto box-content h-full w-full max-w-full shadow-lg transition-all duration-300 ease-linear",initialContent:A,children:[jsxRuntime.jsx(KeyboardHandler,{}),jsxRuntime.jsx(BlockFloatingSelector,{block:r,selectedBlockElement:lodashEs.first(m)}),jsxRuntime.jsx(HeadTags,{}),jsxRuntime.jsx(reactWrapBalancer.Provider,{children:jsxRuntime.jsxs(Canvas,{children:[b?jsxRuntime.jsx("div",{className:"h-full p-4",children:jsxRuntime.jsx(sooner.Skeleton,{className:"h-full"})}):jsxRuntime.jsx(StaticBlocksRenderer,{}),jsxRuntime.jsx(AddBlockAtBottom,{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]})}),jsxRuntime.jsx("div",{id:"placeholder",className:"pointer-events-none absolute z-[99999] max-w-full bg-green-500 transition-transform"})]})})})},FallbackError=()=>jsxRuntime.jsx("div",{className:"h-full w-full rounded-md bg-red-200 p-4 text-red-500",children:jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center",children:[jsxRuntime.jsx("p",{className:"font-semibold",children:"Oops! Something went wrong."}),jsxRuntime.jsx("p",{children:"Please try again."})]})}),CodeEditor$1=React.lazy(()=>Promise.resolve().then(()=>require("./code-editor-Dkq7gsQH.cjs"))),CanvasArea=()=>{const[o]=useCodeEditor(),n=useBuilderProp("onError",lodashEs.noop);return jsxRuntime.jsx("div",{className:"flex h-full max-h-full w-full flex-1 flex-col",children:jsxRuntime.jsxs("div",{className:"relative flex h-full max-h-full flex-col overflow-hidden bg-gray-100/40 px-2",children:[jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx(sooner.Skeleton,{className:"h-full"}),children:jsxRuntime.jsx(reactErrorBoundary.ErrorBoundary,{fallback:jsxRuntime.jsx(FallbackError,{}),onError:n,children:jsxRuntime.jsx(StaticCanvas,{})})}),o?jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx(sooner.Skeleton,{className:"h-full"}),children:jsxRuntime.jsx(reResizable.Resizable,{enable:{top:!0,bottom:!1},className:"max-h-[400px] min-h-[200px]",children:jsxRuntime.jsx(CodeEditor$1,{})})}):null,jsxRuntime.jsx(Breadcrumb,{})]})})};function NestedPathSelector({data:o,onSelect:n,dataType:a="value"}){const[r,l]=React__namespace.useState(!1),[i,d]=React__namespace.useState([]),[c,p]=React__namespace.useState(o);React.useEffect(()=>{r||d([]),p(o)},[r,o]);const u=g=>Array.isArray(g)?"array":typeof g=="object"&&g!==null?"object":"value",m=React__namespace.useCallback(g=>{const f=j=>a==="value"?j==="value"||j==="object":a==="array"?j==="array":j===a;g.type==="object"?(d(j=>[...j,g.key]),p(g.value)):f(g.type)&&(n([...i,g.key].join("."),a),l(!1))},[i,n,a]),h=React__namespace.useCallback(()=>{if(i.length>0){const g=i.slice(0,-1);d(g),p(g.reduce((f,j)=>f[j],o))}},[i,o]),x=React__namespace.useMemo(()=>Object.entries(c).map(([g,f])=>({key:g,value:f,type:u(f)})).filter(g=>a==="value"?g.type==="value"||g.type==="object":a==="array"?g.type==="array"||g.type==="object":a==="object"?g.type==="object":!0),[c,a]);return jsxRuntime.jsxs(sooner.Popover,{open:r,onOpenChange:l,children:[jsxRuntime.jsxs(sooner.Tooltip,{children:[jsxRuntime.jsx(sooner.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(sooner.PopoverTrigger,{asChild:!0,children:jsxRuntime.jsx(sooner.Button,{size:"sm",variant:"outline",className:"h-5 rounded-sm px-1 py-0 text-[9px] text-muted-foreground",role:"combobox","aria-expanded":r,children:jsxRuntime.jsx(lucideReact.DatabaseIcon,{className:"h-2.5 w-2.5"})})})}),jsxRuntime.jsx(sooner.TooltipContent,{children:"Add field"})]}),jsxRuntime.jsx(sooner.PopoverContent,{className:"z-[1000]! relative mr-3 w-[300px] p-0",children:jsxRuntime.jsxs(sooner.Command,{className:"fields-command",children:[jsxRuntime.jsx(sooner.CommandInput,{className:"border-none",placeholder:"Search..."}),jsxRuntime.jsxs(sooner.CommandList,{children:[jsxRuntime.jsx(sooner.CommandEmpty,{children:"No option found."}),jsxRuntime.jsxs(sooner.CommandGroup,{children:[i.length>0&&jsxRuntime.jsxs(sooner.CommandItem,{onSelect:h,className:"flex items-center text-sm",children:[jsxRuntime.jsx(lucideReact.ChevronLeft,{className:"mr-2 h-4 w-4"}),"Back"]}),x.map(g=>jsxRuntime.jsxs(sooner.CommandItem,{value:g.key,disabled:!1,onSelect:()=>m(g),className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"flex items-center gap-x-2",children:[lodashEs.startsWith(g.key,"#")?jsxRuntime.jsx(reactIcons.LoopIcon,{}):null,lodashEs.startsWith(g.key,"#")?"Repeater Data":g.key]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[a==="object"&&g.type==="object"&&jsxRuntime.jsx(sooner.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 hover:bg-primary hover:text-primary-foreground",onClick:f=>{f.stopPropagation(),n([...i,g.key].join("."),a),l(!1)},children:"Select"}),g.type==="object"&&jsxRuntime.jsx("div",{className:"cursor-pointer rounded p-1 hover:bg-muted",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4 opacity-50"})})]})]},g.key))]})]})]})})]})}const JSONFormFieldTemplate=({id:o,classNames:n,label:a,children:r,errors:l,help:i,description:d,hidden:c,required:p,schema:u,formData:m,onChange:h})=>{const{selectedLang:x,fallbackLang:g,languages:f}=useLanguages(),j=lodashEs.isEmpty(f)?"":lodashEs.isEmpty(x)?g:x,b=lodashEs.get(LANGUAGES,j,j),k=usePageExternalData(),S=useSelectedBlock(),v=runtime.useRegisteredChaiBlocks(),A=lodashEs.get(v,[S==null?void 0:S._type,"i18nProps"],[])||[],[B,R]=React.useState(null),C=useSelectedBlockHierarchy(),N=React.useMemo(()=>C.length===1?"":`#${lodashEs.get(C.find(T=>T._type==="Repeater"),"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1")}`,[C]),E=React.useMemo(()=>lodashEs.first(lodashEs.get(k,N.replace("#",""),[])),[N,k]),y=React.useCallback((_,L)=>{if(_=lodashEs.isEmpty(N)?_:_.replace(`${N}.`,"$index."),L==="array"||L==="object"){h(`{{${_}}}`,{},o);return}const T=D=>/[.,!?;:]/.test(D),O=(D,M,U)=>{let $="",W="";const V=M>0?D[M-1]:"",F=M<D.length?D[M]:"";return M>0&&(V==="."||!T(V)&&V!==" ")&&($=" "),M<D.length&&!T(F)&&F!==" "&&(W=" "),{text:$+U+W,prefixLength:$.length,suffixLength:W.length}},H=document.getElementById(o);if(!H)return;const P=document.getElementById(`chai-rte-${o}`)||document.getElementById(`chai-rte-modal-${o}`);if(P&&(P.querySelector(".ProseMirror")||P.__chaiRTE)){const D=P.__chaiRTE;if(D){const M=`{{${_}}}`;D.commands.focus();const{from:U,to:$}=D.state.selection;if(U!==$)D.chain().deleteSelection().insertContent(M).run();else{const{state:V}=D,F=V.selection.from,K=V.doc.textBetween(Math.max(0,F-1),F),G=V.doc.textBetween(F,Math.min(F+1,V.doc.content.size));let Y="";F>0&&K!==" "&&!T(K)&&(Y=" ");let X="";G&&G!==" "&&!T(G)&&(X=" "),D.chain().insertContent(Y+M+X).run()}setTimeout(()=>h(D.getHTML(),{},o),100);return}}else{const D=H,M=D.selectionStart||0,U=D.value||"",$=D.selectionEnd||M;if($>M){const G=`{{${_}}}`,{text:Y}=O(U,M,G),X=U.slice(0,M)+Y+U.slice($);h(X,{},o);return}const V=`{{${_}}}`,{text:F}=O(U,M,V),K=U.slice(0,M)+F+U.slice(M);h(K,{},o)}},[o,h,m,S==null?void 0:S._id,N]);if(c)return null;if(u.type==="boolean")return jsxRuntime.jsx("div",{className:n,children:r});const I=A==null?void 0:A.includes(o.replace("root.",""));if(u.type==="array"){const _=B===o;return jsxRuntime.jsxs("div",{className:`${n} relative`,children:[u.title&&jsxRuntime.jsxs("label",{htmlFor:o,onClick:()=>R(_?null:o),className:"flex cursor-pointer items-center gap-x-1 py-1 leading-tight duration-200 hover:bg-slate-100",children:[_?jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-3 w-3"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-3 w-3"}),jsxRuntime.jsx(lucideReact.List,{className:"h-3 w-3"}),jsxRuntime.jsx("span",{className:"leading-tight",children:a})," ",jsxRuntime.jsx(sooner.Badge,{className:"m-0 bg-gray-200 px-2 leading-tight text-gray-500 hover:bg-gray-200 hover:text-gray-500",children:jsxRuntime.jsx("span",{className:"text-[9px] font-medium text-slate-600",children:m==null?void 0:m.length})})]}),(m==null?void 0:m.length)===0?jsxRuntime.jsx("div",{className:"h-0 overflow-hidden",children:r}):jsxRuntime.jsxs("div",{className:`${_?"pt-0.5":"h-0 overflow-hidden"}`,children:[d,r,l,i]})]})}return jsxRuntime.jsxs("div",{className:n,children:[u.title&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("label",{htmlFor:o,className:u.type==="object"?"pb-2":"",children:[a," ",I&&jsxRuntime.jsxs("small",{className:"text-[9px] text-zinc-400",children:[" ",b]}),p&&u.type!=="object"?" *":null]}),!u.enum&&!u.oneOf&&k&&jsxRuntime.jsx(NestedPathSelector,{data:{...E&&{[N]:E},...k},onSelect:y,dataType:u.binding==="array"?"array":"value"})]}),d,r,l,i]})},RJSF_EXTENSIONS={},registerBlockSettingWidget=(o,n)=>{RJSF_EXTENSIONS[o]={id:o,component:n,type:"widget"}},registerBlockSettingField=(o,n)=>{RJSF_EXTENSIONS[o]={id:o,component:n,type:"field"}},registerBlockSettingTemplate=(o,n)=>{RJSF_EXTENSIONS[o]={id:o,component:n,type:"template"}},useBlockSettingComponents=o=>Object.values(RJSF_EXTENSIONS).filter(n=>n.type===o).reduce((n,a)=>(n[a.id]=a.component,n),{}),removeSizeAttributes=o=>{try{return o.replace(/<svg([^>]*)\sheight="[^"]*"([^>]*)>/gi,"<svg$1$2>").replace(/<svg([^>]*)\swidth="[^"]*"([^>]*)>/gi,"<svg$1$2>")}catch{return o}},IconPickerField=({value:o,onChange:n,id:a})=>{const{t:r}=reactI18next.useTranslation(),[l,i]=React.useState(o||"");React.useEffect(()=>{i(o||"")},[o]);const d=c=>{i(c);const p=removeSizeAttributes(c);n(p)};return jsxRuntime.jsxs("div",{className:"mt-1 flex flex-col gap-2",id:"icon-picker-field",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("div",{className:"flex h-12 w-12 items-center justify-center overflow-hidden rounded-lg border bg-gray-50",children:l?jsxRuntime.jsx("div",{className:"h-6 w-6",dangerouslySetInnerHTML:{__html:l}}):jsxRuntime.jsx("span",{className:"text-xs text-gray-400",children:"SVG"})}),jsxRuntime.jsx("textarea",{id:a,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",value:l,onChange:c=>d(c.target.value),placeholder:r("Enter SVG code here"),rows:2,className:"no-scrollbar w-full rounded-md border border-border bg-background px-3 py-1.5 text-xs shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"})]}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:r("Paste SVG code to use as an icon")})]})},DefaultMediaManager=({close:o,onSelect:n,mode:a="image"})=>{const[r,l]=React.useState(""),[i,d]=React.useState(!1),[c,p]=React.useState(!1),[u,m]=React.useState(null),h=async g=>{if(!g.trim()){p(!1),m("Please enter a URL");return}try{d(!0),m(null),p(!0),m(null)}catch{p(!1),m("Error validating URL")}finally{d(!1)}},{t:x}=reactI18next.useTranslation();return jsxRuntime.jsxs("div",{className:"flex w-96 flex-col gap-4 p-4",children:[jsxRuntime.jsx("h2",{className:"text-xl font-semibold",children:x(`${a.charAt(0).toUpperCase()+a.slice(1)} Manager`)}),u&&jsxRuntime.jsxs(sooner.Alert,{variant:"destructive",children:[jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-4 w-4"}),jsxRuntime.jsx(sooner.AlertDescription,{children:u})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-4",children:[jsxRuntime.jsx(sooner.Input,{placeholder:x(`Enter ${a} URL`),value:r,onChange:g=>l(g.target.value),onKeyUp:()=>h(r)}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-2",children:[jsxRuntime.jsx(sooner.Button,{variant:"outline",onClick:o,children:x("Cancel")}),jsxRuntime.jsx(sooner.Button,{onClick:()=>n({id:"dam-id",url:r,width:600,height:400,description:"This is image description"}),disabled:!c||i,children:x("Insert")})]})]})]})},MEDIA_MANAGER={component:DefaultMediaManager},registerChaiMediaManager=o=>{MEDIA_MANAGER.component=o},useMediaManagerComponent=()=>React.useMemo(()=>MEDIA_MANAGER.component,[]),MediaManagerModal=({assetId:o,children:n,onSelect:a,mode:r="image"})=>{const[l,i]=React.useState(!1),d=useMediaManagerComponent(),c=(...p)=>{a.call(void 0,...p),i(!1)};return jsxRuntime.jsxs(sooner.Dialog,{open:l,onOpenChange:p=>i(p),children:[jsxRuntime.jsx(sooner.DialogTrigger,{asChild:!0,children:n}),jsxRuntime.jsx(sooner.DialogContent,{className:"flex max-h-[90vh] max-w-7xl border-border md:w-fit",children:jsxRuntime.jsx("div",{className:"h-full w-full",children:d?jsxRuntime.jsx(d,{close:()=>i(!1),onSelect:c,mode:r,assetId:o}):null})})]})};MediaManagerModal.displayName="MediaManagerModal";const ImagePickerField=({value:o,onChange:n,id:a,onBlur:r})=>{const{t:l}=reactI18next.useTranslation(),i=useSelectedBlock(),d=useUpdateBlocksProps(),c=m=>{const h=lodashEs.isArray(m)?lodashEs.first(m):m;if(h){n(h==null?void 0:h.url);const x=h==null?void 0:h.width,g=h==null?void 0:h.height;if(i!=null&&i._id){const f={...x&&{width:x},...g&&{height:g},...h.description&&{alt:h.description},...h.id&&{assetId:h.id}};if(lodashEs.isEmpty(f))return;d([i._id],f)}}},p=React.useCallback(()=>{n("https://placehold.co/400"),i!=null&&i._id&&d([i._id],{assetId:""})},[n,i==null?void 0:i._id,d]),u=lodashEs.get(i,"assetId","");return jsxRuntime.jsxs("div",{className:"mt-1.5 flex items-center gap-x-3",children:[o?jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx("img",{src:o,className:"h-20 w-20 overflow-hidden rounded-md border border-border object-cover",alt:""}),jsxRuntime.jsx("button",{type:"button",onClick:p,className:"absolute -right-2 -top-2 rounded-full bg-destructive p-1 text-destructive-foreground hover:bg-destructive/90",children:jsxRuntime.jsx(lucideReact.X,{className:"h-3 w-3"})})]}):jsxRuntime.jsx(MediaManagerModal,{onSelect:c,mode:"image",assetId:u,children:jsxRuntime.jsx("div",{className:"h-20 w-20 cursor-pointer rounded-md border border-border bg-[radial-gradient(#AAA,transparent_1px)] duration-300 [background-size:10px_10px]"})}),jsxRuntime.jsxs("div",{className:"flex w-3/5 flex-col",children:[jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(MediaManagerModal,{onSelect:c,assetId:u,children:jsxRuntime.jsx("small",{className:"h-6 cursor-pointer rounded-md bg-secondary px-2 py-1 text-center text-xs text-secondary-foreground hover:bg-secondary/80",children:o||!lodashEs.isEmpty(o)?l("Replace image"):l("Choose image")})}),jsxRuntime.jsx("small",{className:"-pl-4 pt-2 text-center text-xs text-secondary-foreground",children:"OR"})]}),jsxRuntime.jsx("input",{id:a,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",type:"url",className:"text-xs",placeholder:l("Enter image URL"),value:o,onBlur:({target:{value:m}})=>r(a,m),onChange:m=>n(m.target.value)})]})]})},PageTypeField=({href:o,pageTypes:n,onChange:a})=>{var N;const{t:r}=reactI18next.useTranslation(),l=useBuilderProp("searchPageTypeItems",(E,y)=>[]),[i,d]=React.useState(!1),[c,p]=React.useState(!1),[u,m]=React.useState("page"),[h,x]=React.useState(""),[g,f]=React.useState([]),[j,b]=React.useState(-1),k=React.useRef(null),S=(N=n==null?void 0:n.find(E=>E.key===u))==null?void 0:N.name;React.useEffect(()=>{if(x(""),f([]),b(-1),p(!1),!o||i||!lodashEs.startsWith(o,"pageType:"))return;const E=lodashEs.split(o,":"),y=lodashEs.get(E,1,"page")||"page";m(y),(async()=>{const w=await l(y,[lodashEs.get(E,2,"page")]);w&&Array.isArray(w)&&x(lodashEs.get(w,[0,"name"],""))})()},[o]);const v=web.useDebouncedCallback(async E=>{if(lodashEs.isEmpty(E))f([]);else{const y=await l(u,E);f(y)}d(!1),b(-1)},[u],300),A=E=>{const y=["pageType",u,E.id];y[1]&&(a(y.join(":")),x(E.name),p(!1),f([]),b(-1))},B=E=>{switch(E.key){case"ArrowDown":E.preventDefault(),b(y=>y<g.length-1?y+1:y);break;case"ArrowUp":E.preventDefault(),b(y=>y>0?y-1:y);break;case"Enter":if(E.preventDefault(),g.length===0)return;j>=0&&A(g[j]);break;case"Escape":E.preventDefault(),R();break}};React.useEffect(()=>{if(j>=0&&k.current){const E=k.current.children[j];E==null||E.scrollIntoView({block:"nearest"})}},[j]);const R=()=>{x(""),f([]),b(-1),p(!1),a("")},C=E=>{x(E),p(!lodashEs.isEmpty(E)),d(!0),v(E)};return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("select",{name:"pageType",value:u,onChange:E=>m(E.target.value),children:lodashEs.map(n,E=>jsxRuntime.jsx("option",{value:E.key,children:E.name},E.key))}),u&&jsxRuntime.jsxs("div",{className:"group relative mt-2 flex items-center",children:[jsxRuntime.jsx("input",{type:"text",value:h,onChange:E=>C(E.target.value),onKeyDown:B,placeholder:r(`Search ${S??""}`),className:"w-full rounded-md border border-gray-300 p-2 pr-16"}),jsxRuntime.jsx("div",{className:"absolute bottom-2 right-2 top-3 flex items-center gap-1.5",children:h&&jsxRuntime.jsx("button",{onClick:R,className:"text-gray-400 hover:text-gray-600",title:r("Clear search"),children:jsxRuntime.jsx(lucideReact.X,{className:"h-4 w-4"})})})]}),(i||!lodashEs.isEmpty(g)||c&&lodashEs.isEmpty(g))&&jsxRuntime.jsx("div",{className:"absolute z-40 mt-2 max-h-40 w-full max-w-[250px] overflow-y-auto rounded-md border border-border bg-background shadow-lg",children:i?jsxRuntime.jsxs("div",{className:"space-y-1 p-2",children:[jsxRuntime.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),jsxRuntime.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):c&&lodashEs.isEmpty(g)?jsxRuntime.jsxs("div",{className:"flex items-center justify-center p-4 text-sm text-gray-500",children:[r("No results found for"),' "',h,'"']}):jsxRuntime.jsx("ul",{ref:k,children:lodashEs.map(g==null?void 0:g.slice(0,20),(E,y)=>jsxRuntime.jsxs("li",{onClick:()=>A(E),className:`cursor-pointer p-2 text-xs ${o!=null&&o.includes(E.id)?"bg-blue-200":y===j?"bg-gray-100":"hover:bg-gray-100"}`,children:[E.name," ",E.slug&&jsxRuntime.jsxs("small",{className:"font-light text-gray-500",children:["( ",E.slug," )"]})]},E.id))})})]})},LinkField=({schema:o,formData:n,onChange:a})=>{const{t:r}=reactI18next.useTranslation(),{type:l="pageType",href:i="",target:d="self"}=n,c=useBuilderProp("pageTypes",[]),p=l==="pageType"&&lodashEs.isEmpty(c)?"url":l;return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-xs font-medium",children:(o==null?void 0:o.title)??"Link"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxRuntime.jsx("select",{name:"type",value:l,onChange:u=>a({...n,type:u.target.value}),children:lodashEs.map([...lodashEs.isEmpty(c)?[]:[{const:"pageType",title:r("Goto Page")}],{const:"url",title:r("Open URL")},{const:"email",title:r("Compose Email")},{const:"telephone",title:r("Call Phone")},{const:"scroll",title:r("Scroll to element")}],u=>jsxRuntime.jsx("option",{value:u.const,children:u.title},u.const))}),p==="pageType"&&!lodashEs.isEmpty(c)?jsxRuntime.jsx(PageTypeField,{href:i,pageTypes:c,onChange:u=>a({...n,href:u})}):jsxRuntime.jsx("input",{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",name:"href",type:"text",value:i,onChange:u=>a({...n,href:u.target.value}),placeholder:r(l==="url"?"Enter URL":l==="scroll"?"#ElementID":"Enter details")}),p==="url"&&jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 text-muted-foreground",children:[jsxRuntime.jsx("input",{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",type:"checkbox",defaultChecked:d==="_blank",className:"!w-fit cursor-pointer rounded-md border border-border",onChange:()=>a({...n,target:d==="_blank"?"_self":"_blank"})}),jsxRuntime.jsx("span",{className:"pt-1 text-xs",children:r("Open in new tab")})]})]})]})},RowColField=()=>{const o=useSelectedBlock(),n=useWrapperBlock(),{addCoreBlock:a}=useAddBlock();if(!o&&!n)return null;const r=(o==null?void 0:o._type)==="Row"?o:n;return jsxRuntime.jsx("div",{className:"pt-1",children:jsxRuntime.jsxs("button",{type:"button",className:"duratiom-300 flex items-center gap-x-1 rounded border border-gray-400 bg-gray-100 px-4 py-1 text-[11px] font-medium leading-tight hover:bg-slate-200",onClick:()=>a({type:"Column",styles:"#styles:,"},r==null?void 0:r._id),children:[jsxRuntime.jsx(lucideReact.Plus,{className:"h-4 w-4"})," Add Column"]})})};function cn(...o){return tailwindMerge.twMerge(clsx.clsx(o))}const MenuBar=({editor:o,onExpand:n})=>{if(!o)return null;const a=()=>{const l=window.prompt("URL");l&&o.chain().focus().extendMarkRange("link").setLink({href:l}).run()},r=()=>{o.chain().focus().unsetLink().run()};return jsxRuntime.jsxs("div",{className:"mb-1 flex flex-wrap gap-1 rounded-md border border-border p-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleBold().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("bold")}),title:"Bold",children:jsxRuntime.jsx(lucideReact.Bold,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleItalic().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("italic")}),title:"Italic",children:jsxRuntime.jsx(lucideReact.Italic,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleUnderline().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("underline")}),title:"Underline",children:jsxRuntime.jsx(lucideReact.Underline,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleStrike().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("strike")}),title:"Strike",children:jsxRuntime.jsx(lucideReact.Strikethrough,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleBulletList().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("bulletList")}),title:"Bullet List",children:jsxRuntime.jsx(lucideReact.List,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleOrderedList().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("orderedList")}),title:"Ordered List",children:jsxRuntime.jsx(lucideReact.ListOrdered,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().setTextAlign("left").run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive({textAlign:"left"})}),title:"Align Left",children:jsxRuntime.jsx(lucideReact.AlignLeft,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().setTextAlign("center").run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive({textAlign:"center"})}),title:"Align Center",children:jsxRuntime.jsx(lucideReact.AlignCenter,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().setTextAlign("right").run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive({textAlign:"right"})}),title:"Align Right",children:jsxRuntime.jsx(lucideReact.AlignRight,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:a,className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("link")}),title:"Add Link",children:jsxRuntime.jsx(lucideReact.Link,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:r,className:cn("rounded p-1 hover:bg-muted"),title:"Remove Link",disabled:!o.isActive("link"),children:jsxRuntime.jsx(lucideReact.Unlink,{className:"h-4 w-4"})}),n&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:n,className:"rounded p-1 hover:bg-muted",title:"Open in full screen mode",children:jsxRuntime.jsx(lucideReact.Maximize2,{className:"h-4 w-4"})})]})]})},RTEModal=({isOpen:o,onClose:n,id:a,value:r,onChange:l,onBlur:i})=>{const d=React.useRef(null),c=React.useRef(r||""),p=usePageExternalData();React.useEffect(()=>{if(o){const h=document.createElement("style");return h.id="rte-modal-styles",h.innerHTML=`
60
+ }`)},[l,h]),React.useEffect(()=>{c.querySelector("#drop-target-block").innerHTML=d?`[data-block-id="${d}"]{ outline: 1px dashed orange !important; outline-offset: -1px;}`:""},[d,c]);const f=React.useMemo(()=>{const{heading:k,body:S}={heading:lodashEs.get(o,"fontFamily.heading"),body:lodashEs.get(o,"fontFamily.body")};return g.filter(v=>v.family===k||v.family===S)},[o==null?void 0:o.fontFamily,g]),j=React.useMemo(()=>plugin.getThemeFontsLinkMarkup(lodashEs.filter(f,k=>lodashEs.has(k,"url"))),[f]),b=React.useMemo(()=>plugin.getThemeCustomFontFace(lodashEs.filter(f,k=>lodashEs.has(k,"src"))),[f]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(CssThemeVariables,{theme:o}),jsxRuntime.jsx("span",{id:"chai-fonts",dangerouslySetInnerHTML:{__html:j}}),jsxRuntime.jsx("style",{id:"chai-custom-fonts",dangerouslySetInnerHTML:{__html:b}})]})},ResizableCanvasWrapper=({children:o,onMount:n,onResize:a})=>{const[,r]=useSelectedBlockIds(),[,l]=useSelectedStylingBlocks(),i=React.useRef(null),d=web.useDebouncedCallback(()=>{const{clientWidth:p}=i.current;a(p)},[i.current],100);web.useResizeObserver(i.current,d,i.current!==null),React.useEffect(()=>{const{clientWidth:p}=i.current;n(p)},[]);const c=()=>{r([]),l([])};return jsxRuntime.jsx("div",{id:"main-content",onClick:c,className:"h-full w-full p-8 pb-0",ref:i,children:o})},ErrorFallback=()=>jsxRuntime.jsx("div",{className:"flex min-h-[100px] items-center justify-center bg-red-50 p-2 text-center text-red-500",children:"Something went wrong."}),useBlockRuntimeProps=()=>{const[o]=useBlocksStore();return React.useCallback((n,a)=>lodashEs.isEmpty(a)?{}:Object.entries(a).reduce((r,[l,i])=>{const d=[];let c=lodashEs.find(o,{_id:n});for(;c;)d.push(c),c=lodashEs.find(o,{_id:c._parent});const p=lodashEs.find(d,{_type:i.block});return p&&(r[l]=lodashEs.get(p,lodashEs.get(i,"prop"),null)),r},{}),[o])},RepeaterContext=React.createContext({index:-1,key:""}),CORE_BLOCKS=["Box","Repeater","GlobalBlock","PartialBlock","Heading","Text","RichText","Span","Image","Button","Paragraph","Link","Video","Audio","Icon","List","ListItem","CustomScript","CustomHTML"],BlockRenderer=({blockAtom:o,children:n})=>{const[a]=jotai.useAtom(o),r=React.useMemo(()=>runtime.getRegisteredChaiBlock(a._type),[a._type]),{selectedLang:l,fallbackLang:i}=useLanguages(),d=useBlockRuntimeProps(),c=usePageExternalData(),[p]=useHiddenBlockIds(),[u]=jotai.useAtom(dataBindingActiveAtom),m=lodashEs.get(r,"component",null),{index:h,key:x}=React.useContext(RepeaterContext),g=React.useMemo(()=>u?newBlocksRenderHelpers.applyBinding(newBlocksRenderHelpers.applyLanguage(a,l,r),c,{index:h,key:x}):newBlocksRenderHelpers.applyLanguage(a,l,r),[a,l,r,c,u,h,x]),f=React.useMemo(()=>newBlocksRenderHelpers.getBlockTagAttributes(a),[a,newBlocksRenderHelpers.getBlockTagAttributes]),j=React.useMemo(()=>d(a._id,newBlocksRenderHelpers.getBlockRuntimeProps(a._type)),[a._id,a._type,d,newBlocksRenderHelpers.getBlockRuntimeProps]),b=React.useMemo(()=>!lodashEs.has(r,"dataProvider")||!lodashEs.isFunction(r.dataProvider)?{}:r.dataProvider({block:a,draft:!0,inBuilder:!0,lang:l||i,pageProps:{}}),[a,l,i,r,c]),k=React.useMemo(()=>({blockProps:{"data-block-id":a._id,"data-block-type":a._type},inBuilder:!0,lang:l||i,...g,...f,...j,...b}),[a._id,a._type,l,i,g,f,j,b]),S=React.useMemo(()=>!CORE_BLOCKS.includes(a._type),[a._type]);if(console.log("block",a._type,S),lodashEs.isNull(m)||p.includes(a._id))return null;const v=jsxRuntime.jsx(React.Suspense,{children:React.createElement(m,{...k,children:n({_id:a._id,_type:a._type,...lodashEs.isArray(g.repeaterItems)?{repeaterItems:newBlocksRenderHelpers.applyLimit(g.repeaterItems,a),repeaterItemsBinding:g.repeaterItemsBinding}:{},...a.partialBlockId?{partialBlockId:a.partialBlockId}:"",...a.globalBlock?{partialBlockId:a.globalBlock}:""})})});return S?jsxRuntime.jsx(reactErrorBoundary.ErrorBoundary,{fallbackRender:ErrorFallback,children:v}):v},PartialBlocksRenderer=({partialBlockId:o})=>{const{getPartailBlocks:n}=usePartialBlocksStore(),a=React.useMemo(()=>n(o),[n,o]),r=React.useMemo(()=>utils.splitAtom(jotai.atom(a)),[a]);return lodashEs.isEmpty(a)?null:jsxRuntime.jsx(BlocksRenderer,{splitAtoms:r,blocks:a})},BlocksRenderer=({blocks:o,parent:n=null,splitAtoms:a=void 0})=>{const r=useGetBlockAtom(a),l=React.useMemo(()=>lodashEs.filter(o,d=>lodashEs.has(d,"_id")&&(lodashEs.isEmpty(n)?!d._parent:d._parent===n)),[o,n]),i=React.useCallback(d=>lodashEs.filter(o,c=>c._parent===d).length>0,[o]);return lodashEs.map(l,d=>{const c=r(d._id);return c?jsxRuntime.jsx(BlockRenderer,{blockAtom:c,children:({_id:p,_type:u,partialBlockId:m,repeaterItems:h,repeaterItemsBinding:x})=>u==="Repeater"?lodashEs.isArray(h)&&h.map((g,f)=>jsxRuntime.jsx(RepeaterContext.Provider,{value:{index:f,key:x},children:jsxRuntime.jsx(BlocksRenderer,{splitAtoms:a,blocks:o,parent:d._id})})):u==="GlobalBlock"||u==="PartialBlock"?jsxRuntime.jsx(jotai.Provider,{store:builderStore,children:jsxRuntime.jsx(PartialBlocksRenderer,{partialBlockId:m})}):i(p)?jsxRuntime.jsx(BlocksRenderer,{splitAtoms:a,blocks:o,parent:d._id}):null},d._id):null})},PageBlocksRenderer=()=>{const[o]=useBlocksStore();return jsxRuntime.jsx(BlocksRenderer,{splitAtoms:pageBlocksAtomsAtom,blocks:o})},StaticBlocksRenderer=()=>{const[o]=useBlocksStore(),n=lodashEs.isEmpty(o)?null:jsxRuntime.jsx(PageBlocksRenderer,{});return jsxRuntime.jsx(jsxRuntime.Fragment,{children:n})},useCanvasScale=o=>{const[n]=useCanvasDisplayWidth(),[,a]=useCanvasZoom(),r=useBuilderProp("htmlDir","ltr"),[l,i]=React.useState({}),d=React.useCallback(()=>{const{width:c,height:p}=o;if(c<n){const u=parseFloat((c/n).toFixed(2).toString());let m={};const h=p*u,x=c*u;p&&(m={height:100+(p-h)/h*100+"%",width:100+(c-x)/x*100+"%"}),i({position:"relative",top:0,transform:`scale(${u})`,transformOrigin:r==="rtl"?"top right":"top left",...m,maxWidth:"none"}),a(u*100)}else i({}),a(100)},[n,o,r,a]);return React.useEffect(()=>{d()},[n,o,a,d]),l},getElementByStyleId=(o,n)=>o.querySelector(`[data-style-id="${n}"]`),StaticCanvas=()=>{const[o]=jotai.useAtom(networkModeAtom),[n]=useCanvasDisplayWidth(),[,a]=useSelectedBlockIds(),r=useSelectedBlock(),[,l]=useHighlightBlockId(),i=React.useRef(null),d=React.useRef(null),[c,p]=React.useState({width:0,height:0}),u=useCanvasScale(c),[m,h]=React.useState([]),[,x]=React.useState([]),[,g]=jotai.useAtom(canvasIframeAtom),[f,j]=useSelectedStylingBlocks(),b=useBuilderProp("loading",!1),k=useBuilderProp("htmlDir","ltr"),S=B=>{p(R=>({...R,width:B}))};React.useEffect(()=>{if(!d.current)return;const{clientWidth:B,clientHeight:R}=d.current;p({width:B,height:R})},[d,n]);const v=(B,R=0)=>{const{top:C}=B.getBoundingClientRect();return C+R>=0&&C-R<=window.innerHeight};React.useEffect(()=>{var B,R;if(r!=null&&r._id&&r.type!=="Multiple"&&i.current){const C=getElementByDataBlockId(i.current.contentDocument,r._id);C&&(v(C)||(R=(B=i.current)==null?void 0:B.contentWindow)==null||R.scrollTo({top:C.offsetTop,behavior:"smooth"}),h([C]))}},[r==null?void 0:r._id,r==null?void 0:r.type]),React.useEffect(()=>{if(!lodashEs.isEmpty(f)&&i.current){const B=getElementByStyleId(i.current.contentDocument,lodashEs.first(f).id);x(B?[B]:[null])}else x([null])},[f]);const A=React.useMemo(()=>{let B=IframeInitialContent;return B=B.replace("__HTML_DIR__",k),o==="offline"&&(B=B.replace("https://chaibuilder.com/offline/tailwind.cdn.js","/offline/tailwind.cdn.js")),B},[o,k]);return jsxRuntime.jsx(ResizableCanvasWrapper,{onMount:S,onResize:S,children:jsxRuntime.jsx("div",{onClick:()=>{a([]),j([])},onMouseLeave:()=>setTimeout(()=>l(""),300),className:"relative mx-auto h-full w-full overflow-hidden",ref:d,children:jsxRuntime.jsxs(ChaiFrame,{contentDidMount:()=>g(i.current),ref:i,id:"canvas-iframe",style:{...u,...lodashEs.isEmpty(u)?{width:`${n}px`}:{}},className:"relative mx-auto box-content h-full w-full max-w-full shadow-lg transition-all duration-300 ease-linear",initialContent:A,children:[jsxRuntime.jsx(KeyboardHandler,{}),jsxRuntime.jsx(BlockFloatingSelector,{block:r,selectedBlockElement:lodashEs.first(m)}),jsxRuntime.jsx(HeadTags,{}),jsxRuntime.jsx(reactWrapBalancer.Provider,{children:jsxRuntime.jsxs(Canvas,{children:[b?jsxRuntime.jsx("div",{className:"h-full p-4",children:jsxRuntime.jsx(sooner.Skeleton,{className:"h-full"})}):jsxRuntime.jsx(StaticBlocksRenderer,{}),jsxRuntime.jsx(AddBlockAtBottom,{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]})}),jsxRuntime.jsx("div",{id:"placeholder",className:"pointer-events-none absolute z-[99999] max-w-full bg-green-500 transition-transform"})]})})})},FallbackError=()=>jsxRuntime.jsx("div",{className:"h-full w-full rounded-md bg-red-200 p-4 text-red-500",children:jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center",children:[jsxRuntime.jsx("p",{className:"font-semibold",children:"Oops! Something went wrong."}),jsxRuntime.jsx("p",{children:"Please try again."})]})}),CodeEditor$1=React.lazy(()=>Promise.resolve().then(()=>require("./code-editor-Dkq7gsQH.cjs"))),CanvasArea=()=>{const[o]=useCodeEditor(),n=useBuilderProp("onError",lodashEs.noop);return jsxRuntime.jsx("div",{className:"flex h-full max-h-full w-full flex-1 flex-col",children:jsxRuntime.jsxs("div",{className:"relative flex h-full max-h-full flex-col overflow-hidden bg-gray-100/40 px-2",children:[jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx(sooner.Skeleton,{className:"h-full"}),children:jsxRuntime.jsx(reactErrorBoundary.ErrorBoundary,{fallback:jsxRuntime.jsx(FallbackError,{}),onError:n,children:jsxRuntime.jsx(StaticCanvas,{})})}),o?jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx(sooner.Skeleton,{className:"h-full"}),children:jsxRuntime.jsx(reResizable.Resizable,{enable:{top:!0,bottom:!1},className:"max-h-[400px] min-h-[200px]",children:jsxRuntime.jsx(CodeEditor$1,{})})}):null,jsxRuntime.jsx(Breadcrumb,{})]})})};function NestedPathSelector({data:o,onSelect:n,dataType:a="value"}){const[r,l]=React__namespace.useState(!1),[i,d]=React__namespace.useState([]),[c,p]=React__namespace.useState(o);React.useEffect(()=>{r||d([]),p(o)},[r,o]);const u=g=>Array.isArray(g)?"array":typeof g=="object"&&g!==null?"object":"value",m=React__namespace.useCallback(g=>{const f=j=>a==="value"?j==="value"||j==="object":a==="array"?j==="array":j===a;g.type==="object"?(d(j=>[...j,g.key]),p(g.value)):f(g.type)&&(n([...i,g.key].join("."),a),l(!1))},[i,n,a]),h=React__namespace.useCallback(()=>{if(i.length>0){const g=i.slice(0,-1);d(g),p(g.reduce((f,j)=>f[j],o))}},[i,o]),x=React__namespace.useMemo(()=>Object.entries(c).map(([g,f])=>({key:g,value:f,type:u(f)})).filter(g=>a==="value"?g.type==="value"||g.type==="object":a==="array"?g.type==="array"||g.type==="object":a==="object"?g.type==="object":!0),[c,a]);return jsxRuntime.jsxs(sooner.Popover,{open:r,onOpenChange:l,children:[jsxRuntime.jsxs(sooner.Tooltip,{children:[jsxRuntime.jsx(sooner.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(sooner.PopoverTrigger,{asChild:!0,children:jsxRuntime.jsx(sooner.Button,{size:"sm",variant:"outline",className:"h-5 rounded-sm px-1 py-0 text-[9px] text-muted-foreground",role:"combobox","aria-expanded":r,children:jsxRuntime.jsx(lucideReact.DatabaseIcon,{className:"h-2.5 w-2.5"})})})}),jsxRuntime.jsx(sooner.TooltipContent,{children:"Add field"})]}),jsxRuntime.jsx(sooner.PopoverContent,{className:"z-[1000]! relative mr-3 w-[300px] p-0",children:jsxRuntime.jsxs(sooner.Command,{className:"fields-command",children:[jsxRuntime.jsx(sooner.CommandInput,{className:"border-none",placeholder:"Search..."}),jsxRuntime.jsxs(sooner.CommandList,{children:[jsxRuntime.jsx(sooner.CommandEmpty,{children:"No option found."}),jsxRuntime.jsxs(sooner.CommandGroup,{children:[i.length>0&&jsxRuntime.jsxs(sooner.CommandItem,{onSelect:h,className:"flex items-center text-sm",children:[jsxRuntime.jsx(lucideReact.ChevronLeft,{className:"mr-2 h-4 w-4"}),"Back"]}),x.map(g=>jsxRuntime.jsxs(sooner.CommandItem,{value:g.key,disabled:!1,onSelect:()=>m(g),className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"flex items-center gap-x-2",children:[lodashEs.startsWith(g.key,"#")?jsxRuntime.jsx(reactIcons.LoopIcon,{}):null,lodashEs.startsWith(g.key,"#")?"Repeater Data":g.key]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[a==="object"&&g.type==="object"&&jsxRuntime.jsx(sooner.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 hover:bg-primary hover:text-primary-foreground",onClick:f=>{f.stopPropagation(),n([...i,g.key].join("."),a),l(!1)},children:"Select"}),g.type==="object"&&jsxRuntime.jsx("div",{className:"cursor-pointer rounded p-1 hover:bg-muted",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4 opacity-50"})})]})]},g.key))]})]})]})})]})}const JSONFormFieldTemplate=({id:o,classNames:n,label:a,children:r,errors:l,help:i,description:d,hidden:c,required:p,schema:u,formData:m,onChange:h})=>{const{selectedLang:x,fallbackLang:g,languages:f}=useLanguages(),j=lodashEs.isEmpty(f)?"":lodashEs.isEmpty(x)?g:x,b=lodashEs.get(LANGUAGES,j,j),k=usePageExternalData(),S=useSelectedBlock(),v=runtime.useRegisteredChaiBlocks(),A=lodashEs.get(v,[S==null?void 0:S._type,"i18nProps"],[])||[],[B,R]=React.useState(null),C=useSelectedBlockHierarchy(),N=React.useMemo(()=>C.length===1?"":`#${lodashEs.get(C.find(T=>T._type==="Repeater"),"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1")}`,[C]),E=React.useMemo(()=>lodashEs.first(lodashEs.get(k,N.replace("#",""),[])),[N,k]),y=React.useCallback((_,L)=>{if(_=lodashEs.isEmpty(N)?_:_.replace(`${N}.`,"$index."),L==="array"||L==="object"){h(`{{${_}}}`,{},o);return}const T=D=>/[.,!?;:]/.test(D),O=(D,M,U)=>{let $="",W="";const V=M>0?D[M-1]:"",F=M<D.length?D[M]:"";return M>0&&(V==="."||!T(V)&&V!==" ")&&($=" "),M<D.length&&!T(F)&&F!==" "&&(W=" "),{text:$+U+W,prefixLength:$.length,suffixLength:W.length}},H=document.getElementById(o);if(!H)return;const P=document.getElementById(`chai-rte-${o}`)||document.getElementById(`chai-rte-modal-${o}`);if(P&&(P.querySelector(".ProseMirror")||P.__chaiRTE)){const D=P.__chaiRTE;if(D){const M=`{{${_}}}`;D.commands.focus();const{from:U,to:$}=D.state.selection;if(U!==$)D.chain().deleteSelection().insertContent(M).run();else{const{state:V}=D,F=V.selection.from,K=V.doc.textBetween(Math.max(0,F-1),F),G=V.doc.textBetween(F,Math.min(F+1,V.doc.content.size));let Y="";F>0&&K!==" "&&!T(K)&&(Y=" ");let X="";G&&G!==" "&&!T(G)&&(X=" "),D.chain().insertContent(Y+M+X).run()}setTimeout(()=>h(D.getHTML(),{},o),100);return}}else{const D=H,M=D.selectionStart||0,U=D.value||"",$=D.selectionEnd||M;if($>M){const G=`{{${_}}}`,{text:Y}=O(U,M,G),X=U.slice(0,M)+Y+U.slice($);h(X,{},o);return}const V=`{{${_}}}`,{text:F}=O(U,M,V),K=U.slice(0,M)+F+U.slice(M);h(K,{},o)}},[o,h,m,S==null?void 0:S._id,N]);if(c)return null;if(u.type==="boolean")return jsxRuntime.jsx("div",{className:n,children:r});const I=A==null?void 0:A.includes(o.replace("root.",""));if(u.type==="array"){const _=B===o;return jsxRuntime.jsxs("div",{className:`${n} relative`,children:[u.title&&jsxRuntime.jsxs("label",{htmlFor:o,onClick:()=>R(_?null:o),className:"flex cursor-pointer items-center gap-x-1 py-1 leading-tight duration-200 hover:bg-slate-100",children:[_?jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-3 w-3"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-3 w-3"}),jsxRuntime.jsx(lucideReact.List,{className:"h-3 w-3"}),jsxRuntime.jsx("span",{className:"leading-tight",children:a})," ",jsxRuntime.jsx(sooner.Badge,{className:"m-0 bg-gray-200 px-2 leading-tight text-gray-500 hover:bg-gray-200 hover:text-gray-500",children:jsxRuntime.jsx("span",{className:"text-[9px] font-medium text-slate-600",children:m==null?void 0:m.length})})]}),(m==null?void 0:m.length)===0?jsxRuntime.jsx("div",{className:"h-0 overflow-hidden",children:r}):jsxRuntime.jsxs("div",{className:`${_?"pt-0.5":"h-0 overflow-hidden"}`,children:[d,r,l,i]})]})}return jsxRuntime.jsxs("div",{className:n,children:[u.title&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("label",{htmlFor:o,className:u.type==="object"?"pb-2":"",children:[a," ",I&&jsxRuntime.jsxs("small",{className:"text-[9px] text-zinc-400",children:[" ",b]}),p&&u.type!=="object"?" *":null]}),!u.enum&&!u.oneOf&&k&&jsxRuntime.jsx(NestedPathSelector,{data:{...E&&{[N]:E},...k},onSelect:y,dataType:u.binding==="array"?"array":"value"})]}),d,r,l,i]})},RJSF_EXTENSIONS={},registerBlockSettingWidget=(o,n)=>{RJSF_EXTENSIONS[o]={id:o,component:n,type:"widget"}},registerBlockSettingField=(o,n)=>{RJSF_EXTENSIONS[o]={id:o,component:n,type:"field"}},registerBlockSettingTemplate=(o,n)=>{RJSF_EXTENSIONS[o]={id:o,component:n,type:"template"}},useBlockSettingComponents=o=>Object.values(RJSF_EXTENSIONS).filter(n=>n.type===o).reduce((n,a)=>(n[a.id]=a.component,n),{}),removeSizeAttributes=o=>{try{return o.replace(/<svg([^>]*)\sheight="[^"]*"([^>]*)>/gi,"<svg$1$2>").replace(/<svg([^>]*)\swidth="[^"]*"([^>]*)>/gi,"<svg$1$2>")}catch{return o}},IconPickerField=({value:o,onChange:n,id:a})=>{const{t:r}=reactI18next.useTranslation(),[l,i]=React.useState(o||"");React.useEffect(()=>{i(o||"")},[o]);const d=c=>{i(c);const p=removeSizeAttributes(c);n(p)};return jsxRuntime.jsxs("div",{className:"mt-1 flex flex-col gap-2",id:"icon-picker-field",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2",children:[jsxRuntime.jsx("div",{className:"flex h-12 w-12 items-center justify-center overflow-hidden rounded-lg border bg-gray-50",children:l?jsxRuntime.jsx("div",{className:"h-6 w-6",dangerouslySetInnerHTML:{__html:l}}):jsxRuntime.jsx("span",{className:"text-xs text-gray-400",children:"SVG"})}),jsxRuntime.jsx("textarea",{id:a,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",value:l,onChange:c=>d(c.target.value),placeholder:r("Enter SVG code here"),rows:2,className:"no-scrollbar w-full rounded-md border border-border bg-background px-3 py-1.5 text-xs shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"})]}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:r("Paste SVG code to use as an icon")})]})},DefaultMediaManager=({close:o,onSelect:n,mode:a="image"})=>{const[r,l]=React.useState(""),[i,d]=React.useState(!1),[c,p]=React.useState(!1),[u,m]=React.useState(null),h=async g=>{if(!g.trim()){p(!1),m("Please enter a URL");return}try{d(!0),m(null),p(!0),m(null)}catch{p(!1),m("Error validating URL")}finally{d(!1)}},{t:x}=reactI18next.useTranslation();return jsxRuntime.jsxs("div",{className:"flex w-96 flex-col gap-4 p-4",children:[jsxRuntime.jsx("h2",{className:"text-xl font-semibold",children:x(`${a.charAt(0).toUpperCase()+a.slice(1)} Manager`)}),u&&jsxRuntime.jsxs(sooner.Alert,{variant:"destructive",children:[jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-4 w-4"}),jsxRuntime.jsx(sooner.AlertDescription,{children:u})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-4",children:[jsxRuntime.jsx(sooner.Input,{placeholder:x(`Enter ${a} URL`),value:r,onChange:g=>l(g.target.value),onKeyUp:()=>h(r)}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-2",children:[jsxRuntime.jsx(sooner.Button,{variant:"outline",onClick:o,children:x("Cancel")}),jsxRuntime.jsx(sooner.Button,{onClick:()=>n({id:"dam-id",url:r,width:600,height:400,description:"This is image description"}),disabled:!c||i,children:x("Insert")})]})]})]})},MEDIA_MANAGER={component:DefaultMediaManager},registerChaiMediaManager=o=>{MEDIA_MANAGER.component=o},useMediaManagerComponent=()=>React.useMemo(()=>MEDIA_MANAGER.component,[]),MediaManagerModal=({assetId:o,children:n,onSelect:a,mode:r="image"})=>{const[l,i]=React.useState(!1),d=useMediaManagerComponent(),c=(...p)=>{a.call(void 0,...p),i(!1)};return jsxRuntime.jsxs(sooner.Dialog,{open:l,onOpenChange:p=>i(p),children:[jsxRuntime.jsx(sooner.DialogTrigger,{asChild:!0,children:n}),jsxRuntime.jsx(sooner.DialogContent,{className:"flex max-h-[90vh] max-w-7xl border-border md:w-fit",children:jsxRuntime.jsx("div",{className:"h-full w-full",children:d?jsxRuntime.jsx(d,{close:()=>i(!1),onSelect:c,mode:r,assetId:o}):null})})]})};MediaManagerModal.displayName="MediaManagerModal";const ImagePickerField=({value:o,onChange:n,id:a,onBlur:r})=>{const{t:l}=reactI18next.useTranslation(),i=useSelectedBlock(),d=useUpdateBlocksProps(),c=m=>{const h=lodashEs.isArray(m)?lodashEs.first(m):m;if(h){n(h==null?void 0:h.url);const x=h==null?void 0:h.width,g=h==null?void 0:h.height;if(i!=null&&i._id){const f={...x&&{width:x},...g&&{height:g},...h.description&&{alt:h.description},...h.id&&{assetId:h.id}};if(lodashEs.isEmpty(f))return;d([i._id],f)}}},p=React.useCallback(()=>{n("https://placehold.co/400"),i!=null&&i._id&&d([i._id],{assetId:""})},[n,i==null?void 0:i._id,d]),u=lodashEs.get(i,"assetId","");return jsxRuntime.jsxs("div",{className:"mt-1.5 flex items-center gap-x-3",children:[o?jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx("img",{src:o,className:"h-20 w-20 overflow-hidden rounded-md border border-border object-cover",alt:""}),jsxRuntime.jsx("button",{type:"button",onClick:p,className:"absolute -right-2 -top-2 rounded-full bg-destructive p-1 text-destructive-foreground hover:bg-destructive/90",children:jsxRuntime.jsx(lucideReact.X,{className:"h-3 w-3"})})]}):jsxRuntime.jsx(MediaManagerModal,{onSelect:c,mode:"image",assetId:u,children:jsxRuntime.jsx("div",{className:"h-20 w-20 cursor-pointer rounded-md border border-border bg-[radial-gradient(#AAA,transparent_1px)] duration-300 [background-size:10px_10px]"})}),jsxRuntime.jsxs("div",{className:"flex w-3/5 flex-col",children:[jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(MediaManagerModal,{onSelect:c,assetId:u,children:jsxRuntime.jsx("small",{className:"h-6 cursor-pointer rounded-md bg-secondary px-2 py-1 text-center text-xs text-secondary-foreground hover:bg-secondary/80",children:o||!lodashEs.isEmpty(o)?l("Replace image"):l("Choose image")})}),jsxRuntime.jsx("small",{className:"-pl-4 pt-2 text-center text-xs text-secondary-foreground",children:"OR"})]}),jsxRuntime.jsx("input",{id:a,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",type:"url",className:"text-xs",placeholder:l("Enter image URL"),value:o,onBlur:({target:{value:m}})=>r(a,m),onChange:m=>n(m.target.value)})]})]})},PageTypeField=({href:o,pageTypes:n,onChange:a})=>{var N;const{t:r}=reactI18next.useTranslation(),l=useBuilderProp("searchPageTypeItems",(E,y)=>[]),[i,d]=React.useState(!1),[c,p]=React.useState(!1),[u,m]=React.useState("page"),[h,x]=React.useState(""),[g,f]=React.useState([]),[j,b]=React.useState(-1),k=React.useRef(null),S=(N=n==null?void 0:n.find(E=>E.key===u))==null?void 0:N.name;React.useEffect(()=>{if(x(""),f([]),b(-1),p(!1),!o||i||!lodashEs.startsWith(o,"pageType:"))return;const E=lodashEs.split(o,":"),y=lodashEs.get(E,1,"page")||"page";m(y),(async()=>{const w=await l(y,[lodashEs.get(E,2,"page")]);w&&Array.isArray(w)&&x(lodashEs.get(w,[0,"name"],""))})()},[o]);const v=web.useDebouncedCallback(async E=>{if(lodashEs.isEmpty(E))f([]);else{const y=await l(u,E);f(y)}d(!1),b(-1)},[u],300),A=E=>{const y=["pageType",u,E.id];y[1]&&(a(y.join(":")),x(E.name),p(!1),f([]),b(-1))},B=E=>{switch(E.key){case"ArrowDown":E.preventDefault(),b(y=>y<g.length-1?y+1:y);break;case"ArrowUp":E.preventDefault(),b(y=>y>0?y-1:y);break;case"Enter":if(E.preventDefault(),g.length===0)return;j>=0&&A(g[j]);break;case"Escape":E.preventDefault(),R();break}};React.useEffect(()=>{if(j>=0&&k.current){const E=k.current.children[j];E==null||E.scrollIntoView({block:"nearest"})}},[j]);const R=()=>{x(""),f([]),b(-1),p(!1),a("")},C=E=>{x(E),p(!lodashEs.isEmpty(E)),d(!0),v(E)};return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("select",{name:"pageType",value:u,onChange:E=>m(E.target.value),children:lodashEs.map(n,E=>jsxRuntime.jsx("option",{value:E.key,children:E.name},E.key))}),u&&jsxRuntime.jsxs("div",{className:"group relative mt-2 flex items-center",children:[jsxRuntime.jsx("input",{type:"text",value:h,onChange:E=>C(E.target.value),onKeyDown:B,placeholder:r(`Search ${S??""}`),className:"w-full rounded-md border border-gray-300 p-2 pr-16"}),jsxRuntime.jsx("div",{className:"absolute bottom-2 right-2 top-3 flex items-center gap-1.5",children:h&&jsxRuntime.jsx("button",{onClick:R,className:"text-gray-400 hover:text-gray-600",title:r("Clear search"),children:jsxRuntime.jsx(lucideReact.X,{className:"h-4 w-4"})})})]}),(i||!lodashEs.isEmpty(g)||c&&lodashEs.isEmpty(g))&&jsxRuntime.jsx("div",{className:"absolute z-40 mt-2 max-h-40 w-full max-w-[250px] overflow-y-auto rounded-md border border-border bg-background shadow-lg",children:i?jsxRuntime.jsxs("div",{className:"space-y-1 p-2",children:[jsxRuntime.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),jsxRuntime.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):c&&lodashEs.isEmpty(g)?jsxRuntime.jsxs("div",{className:"flex items-center justify-center p-4 text-sm text-gray-500",children:[r("No results found for"),' "',h,'"']}):jsxRuntime.jsx("ul",{ref:k,children:lodashEs.map(g==null?void 0:g.slice(0,20),(E,y)=>jsxRuntime.jsxs("li",{onClick:()=>A(E),className:`cursor-pointer p-2 text-xs ${o!=null&&o.includes(E.id)?"bg-blue-200":y===j?"bg-gray-100":"hover:bg-gray-100"}`,children:[E.name," ",E.slug&&jsxRuntime.jsxs("small",{className:"font-light text-gray-500",children:["( ",E.slug," )"]})]},E.id))})})]})},LinkField=({schema:o,formData:n,onChange:a})=>{const{t:r}=reactI18next.useTranslation(),{type:l="pageType",href:i="",target:d="self"}=n,c=useBuilderProp("pageTypes",[]),p=l==="pageType"&&lodashEs.isEmpty(c)?"url":l;return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("span",{className:"text-xs font-medium",children:(o==null?void 0:o.title)??"Link"}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxRuntime.jsx("select",{name:"type",value:l,onChange:u=>a({...n,type:u.target.value}),children:lodashEs.map([...lodashEs.isEmpty(c)?[]:[{const:"pageType",title:r("Goto Page")}],{const:"url",title:r("Open URL")},{const:"email",title:r("Compose Email")},{const:"telephone",title:r("Call Phone")},{const:"scroll",title:r("Scroll to element")}],u=>jsxRuntime.jsx("option",{value:u.const,children:u.title},u.const))}),p==="pageType"&&!lodashEs.isEmpty(c)?jsxRuntime.jsx(PageTypeField,{href:i,pageTypes:c,onChange:u=>a({...n,href:u})}):jsxRuntime.jsx("input",{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",name:"href",type:"text",value:i,onChange:u=>a({...n,href:u.target.value}),placeholder:r(l==="url"?"Enter URL":l==="scroll"?"#ElementID":"Enter details")}),p==="url"&&jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 text-muted-foreground",children:[jsxRuntime.jsx("input",{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",type:"checkbox",defaultChecked:d==="_blank",className:"!w-fit cursor-pointer rounded-md border border-border",onChange:()=>a({...n,target:d==="_blank"?"_self":"_blank"})}),jsxRuntime.jsx("span",{className:"pt-1 text-xs",children:r("Open in new tab")})]})]})]})},RowColField=()=>{const o=useSelectedBlock(),n=useWrapperBlock(),{addCoreBlock:a}=useAddBlock();if(!o&&!n)return null;const r=(o==null?void 0:o._type)==="Row"?o:n;return jsxRuntime.jsx("div",{className:"pt-1",children:jsxRuntime.jsxs("button",{type:"button",className:"duratiom-300 flex items-center gap-x-1 rounded border border-gray-400 bg-gray-100 px-4 py-1 text-[11px] font-medium leading-tight hover:bg-slate-200",onClick:()=>a({type:"Column",styles:"#styles:,"},r==null?void 0:r._id),children:[jsxRuntime.jsx(lucideReact.Plus,{className:"h-4 w-4"})," Add Column"]})})};function cn(...o){return tailwindMerge.twMerge(clsx.clsx(o))}const MenuBar=({editor:o,onExpand:n})=>{if(!o)return null;const a=()=>{const l=window.prompt("URL");l&&o.chain().focus().extendMarkRange("link").setLink({href:l}).run()},r=()=>{o.chain().focus().unsetLink().run()};return jsxRuntime.jsxs("div",{className:"mb-1 flex flex-wrap gap-1 rounded-md border border-border p-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleBold().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("bold")}),title:"Bold",children:jsxRuntime.jsx(lucideReact.Bold,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleItalic().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("italic")}),title:"Italic",children:jsxRuntime.jsx(lucideReact.Italic,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleUnderline().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("underline")}),title:"Underline",children:jsxRuntime.jsx(lucideReact.Underline,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleStrike().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("strike")}),title:"Strike",children:jsxRuntime.jsx(lucideReact.Strikethrough,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleBulletList().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("bulletList")}),title:"Bullet List",children:jsxRuntime.jsx(lucideReact.List,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleOrderedList().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("orderedList")}),title:"Ordered List",children:jsxRuntime.jsx(lucideReact.ListOrdered,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().setTextAlign("left").run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive({textAlign:"left"})}),title:"Align Left",children:jsxRuntime.jsx(lucideReact.AlignLeft,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().setTextAlign("center").run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive({textAlign:"center"})}),title:"Align Center",children:jsxRuntime.jsx(lucideReact.AlignCenter,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().setTextAlign("right").run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive({textAlign:"right"})}),title:"Align Right",children:jsxRuntime.jsx(lucideReact.AlignRight,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:a,className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("link")}),title:"Add Link",children:jsxRuntime.jsx(lucideReact.Link,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:r,className:cn("rounded p-1 hover:bg-muted"),title:"Remove Link",disabled:!o.isActive("link"),children:jsxRuntime.jsx(lucideReact.Unlink,{className:"h-4 w-4"})}),n&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:n,className:"rounded p-1 hover:bg-muted",title:"Open in full screen mode",children:jsxRuntime.jsx(lucideReact.Maximize2,{className:"h-4 w-4"})})]})]})},RTEModal=({isOpen:o,onClose:n,id:a,value:r,onChange:l,onBlur:i})=>{const d=React.useRef(null),c=React.useRef(r||""),p=usePageExternalData();React.useEffect(()=>{if(o){const h=document.createElement("style");return h.id="rte-modal-styles",h.innerHTML=`
61
61
  /* Ensure the NestedPathSelector popover appears above the dialog */
62
62
  .rte-path-selector + [data-radix-popper-content-wrapper],
63
63
  [data-radix-popper-content-wrapper] {
package/dist/core.js CHANGED
@@ -3261,7 +3261,7 @@ const useHandleCanvasDblClick = (o, r) => {
3261
3261
  }, []), /* @__PURE__ */ jsx("div", { id: "main-content", onClick: () => {
3262
3262
  a([]), l([]);
3263
3263
  }, className: "h-full w-full p-8 pb-0", ref: i, children: o });
3264
- }, useBlockRuntimeProps = () => {
3264
+ }, ErrorFallback = () => /* @__PURE__ */ jsx("div", { className: "flex min-h-[100px] items-center justify-center bg-red-50 p-2 text-center text-red-500", children: "Something went wrong." }), useBlockRuntimeProps = () => {
3265
3265
  const [o] = useBlocksStore();
3266
3266
  return useCallback(
3267
3267
  (r, n) => isEmpty(n) ? {} : Object.entries(n).reduce((a, [l, i]) => {
@@ -3277,7 +3277,27 @@ const useHandleCanvasDblClick = (o, r) => {
3277
3277
  }, RepeaterContext = createContext({
3278
3278
  index: -1,
3279
3279
  key: ""
3280
- }), BlockRenderer = ({
3280
+ }), CORE_BLOCKS = [
3281
+ "Box",
3282
+ "Repeater",
3283
+ "GlobalBlock",
3284
+ "PartialBlock",
3285
+ "Heading",
3286
+ "Text",
3287
+ "RichText",
3288
+ "Span",
3289
+ "Image",
3290
+ "Button",
3291
+ "Paragraph",
3292
+ "Link",
3293
+ "Video",
3294
+ "Audio",
3295
+ "Icon",
3296
+ "List",
3297
+ "ListItem",
3298
+ "CustomScript",
3299
+ "CustomHTML"
3300
+ ], BlockRenderer = ({
3281
3301
  blockAtom: o,
3282
3302
  children: r
3283
3303
  }) => {
@@ -3316,8 +3336,9 @@ const useHandleCanvasDblClick = (o, r) => {
3316
3336
  y,
3317
3337
  b
3318
3338
  ]
3319
- );
3320
- return isNull(g) || p.includes(n._id) ? null : /* @__PURE__ */ jsx(Suspense, { children: createElement(g, {
3339
+ ), w = useMemo(() => !CORE_BLOCKS.includes(n._type), [n._type]);
3340
+ if (console.log("block", n._type, w), isNull(g) || p.includes(n._id)) return null;
3341
+ const A = /* @__PURE__ */ jsx(Suspense, { children: createElement(g, {
3321
3342
  ...v,
3322
3343
  children: r({
3323
3344
  _id: n._id,
@@ -3330,6 +3351,7 @@ const useHandleCanvasDblClick = (o, r) => {
3330
3351
  ...n.globalBlock ? { partialBlockId: n.globalBlock } : ""
3331
3352
  })
3332
3353
  }) });
3354
+ return w ? /* @__PURE__ */ jsx(ErrorBoundary, { fallbackRender: ErrorFallback, children: A }) : A;
3333
3355
  }, PartialBlocksRenderer = ({ partialBlockId: o }) => {
3334
3356
  const { getPartailBlocks: r } = usePartialBlocksStore(), n = useMemo(() => r(o), [r, o]), a = useMemo(() => splitAtom(atom(n)), [n]);
3335
3357
  return isEmpty(n) ? null : /* @__PURE__ */ jsx(BlocksRenderer, { splitAtoms: a, blocks: n });
package/dist/render.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./plugin-C01tjI6V.cjs"),p=require("./new-blocks-render-helpers-DRQ8Buz8.cjs"),r=require("lodash-es"),x=require("@tailwindcss/aspect-ratio"),q=require("@tailwindcss/forms"),I=require("@tailwindcss/typography");require("tailwindcss-animate");const R=require("./get-chai-builder-theme-CeaKvOZ8.cjs"),j=require("@mhsdesign/jit-browser-tailwindcss"),F=require("@tailwindcss/container-queries"),u=require("react/jsx-runtime"),m=require("react"),L=require("@chaibuilder/runtime"),E=e=>{if(!e)return[];try{return JSON.parse(O(e)).filter(a=>!a._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function O(e){const t=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(t,a=>{const n=decodeURIComponent(a),s=n.indexOf("public");return s!==-1?n.substring(s+6):n})}async function A(e,t,a=[],n="",s){return await j.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:R.getChaiBuilderTheme(e)},plugins:[q,I,x,F,h.chaiBuilderPlugin],corePlugins:{preflight:s},...n?{prefix:`${n}`}:{}}}).generateStylesFromContent(` ${s?"@tailwind base;":""}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const k=require("./plugin-C01tjI6V.cjs"),p=require("./new-blocks-render-helpers-DRQ8Buz8.cjs"),r=require("lodash-es"),x=require("@tailwindcss/aspect-ratio"),q=require("@tailwindcss/forms"),I=require("@tailwindcss/typography");require("tailwindcss-animate");const R=require("./get-chai-builder-theme-CeaKvOZ8.cjs"),F=require("@mhsdesign/jit-browser-tailwindcss"),j=require("@tailwindcss/container-queries"),u=require("react/jsx-runtime"),m=require("react"),L=require("@chaibuilder/runtime"),E=e=>{if(!e)return[];try{return JSON.parse(O(e)).filter(a=>!a._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function O(e){const t=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(t,a=>{const n=decodeURIComponent(a),s=n.indexOf("public");return s!==-1?n.substring(s+6):n})}async function A(e,t,a=[],n="",s){return await F.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:R.getChaiBuilderTheme(e)},plugins:[q,I,x,j,k.chaiBuilderPlugin],corePlugins:{preflight:s},...n?{prefix:`${n}`}:{}}}).generateStylesFromContent(` ${s?"@tailwind base;":""}
2
2
  @tailwind components;
3
- @tailwind utilities;`,t)}const D=(e,t,a)=>{const n=JSON.stringify(e).replace(/#styles:([^"]*)/g,(s,o)=>`#styles:${o.replace(/,/g," ")}`.replace(/#styles:/g,""));return A(t,[n],[],"",a)},M=async(e,t=h.defaultThemeOptions,a=!1)=>await D(e,t,a);async function $(e){const t=await e.dataProvider({pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:!1});return r.has(t,"$metadata")&&e.dataProviderMetadataCallback(e.block,t.$metadata),e.children({...r.omit(t,"$metadata")})}const N=()=>u.jsx("div",{}),J=e=>{const{block:t,lang:a,fallbackLang:n,children:s,externalData:o,blocks:i,draft:l,pageProps:g,dataProviderMetadataCallback:f}=e,c=L.getRegisteredChaiBlock(t._type),k=r.get(c,"component",null),y=r.get(e.repeaterData,"index",-1),P=r.get(e.repeaterData,"dataKey",""),_=a===n?"":a,d=p.applyBinding(p.applyLanguage(t,_,c),o,{index:y,key:P}),w=p.getBlockTagAttributes(t,!1),C=K(i,t._id,p.getBlockRuntimeProps(t._type)),S=r.has(c,"dataProvider")&&r.isFunction(c.dataProvider),B={blockProps:{},inBuilder:!1,lang:a||n,...d,...w,...C};if(r.isNull(k))return null;if(S){const v=r.get(c,"suspenseFallback",N);return u.jsx(m.Suspense,{fallback:m.createElement(v),children:u.jsx($,{lang:a,pageProps:g,block:t,dataProvider:c.dataProvider,dataProviderMetadataCallback:f,draft:l,children:T=>m.createElement(k,{...B,...T,children:s({_id:t._id,_type:t._type,...r.isArray(d.repeaterItems)?{repeaterItems:p.applyLimit(d.repeaterItems,t),repeaterItemsBinding:d.repeaterItemsBinding}:{}})})})})}return u.jsx(m.Suspense,{children:m.createElement(k,{...B,children:s({_id:t._id,_type:t._type,...r.isArray(d.repeaterItems)?{repeaterItems:p.applyLimit(d.repeaterItems,t),repeaterItemsBinding:d.repeaterItemsBinding}:{}})})})},b=e=>{const{blocks:t,parent:a,repeaterData:n}=e,s=r.filter(t,i=>r.has(i,"_id")&&(r.isEmpty(a)?!i._parent:i._parent===a)),o=i=>r.filter(t,l=>l._parent===i).length>0;return r.map(s,i=>i?m.createElement(J,{...e,key:i._id,block:i},({_id:l,_type:g,repeaterItems:f,repeaterItemsBinding:c})=>g==="Repeater"?r.isArray(f)&&f.map((k,y)=>u.jsx(b,{...e,parent:i._id,repeaterData:{index:y,dataKey:c}})):o(l)?u.jsx(b,{...e,parent:i._id,repeaterData:n}):null):null)},K=(e,t,a)=>r.isEmpty(a)?{}:Object.entries(a).reduce((n,[s,o])=>{const i=[];let l=r.find(e,{_id:t});for(;l;)i.push(l),l=r.find(e,{_id:l._parent});const g=r.find(i,{_type:o.block});return g&&(n[s]=r.get(g,r.get(o,"prop"),null)),n},{});function V(e){if(r.has(e,"metadata")&&console.warn(" metadata is deprecated and will be removed in upcoming version, use pageProps instead"),r.isEmpty(e.lang)&&!r.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");const t=e.lang??"en",a=e.fallbackLang??t;return u.jsx(b,{...e,lang:t,fallbackLang:a})}exports.getChaiThemeCssVariables=h.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=h.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=h.getThemeFontsLinkMarkup;exports.RenderChaiBlocks=V;exports.convertToBlocks=E;exports.getStylesForBlocks=M;
3
+ @tailwind utilities;`,t)}const D=(e,t,a)=>{const n=JSON.stringify(e).replace(/#styles:([^"]*)/g,(s,c)=>`#styles:${c.replace(/,/g," ")}`.replace(/#styles:/g,""));return A(t,[n],[],"",a)},M=async(e,t=k.defaultThemeOptions,a=!1)=>await D(e,t,a);async function $(e){const t=await e.dataProvider({pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:!1});return r.has(t,"$metadata")&&r.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,t.$metadata),e.children({...r.omit(t,"$metadata")})}const N=()=>u.jsx("div",{}),J=e=>{const{block:t,lang:a,fallbackLang:n,children:s,externalData:c,blocks:i,draft:l,pageProps:g,dataProviderMetadataCallback:h}=e,o=L.getRegisteredChaiBlock(t._type),f=r.get(o,"component",null),y=r.get(e.repeaterData,"index",-1),B=r.get(e.repeaterData,"dataKey",""),_=a===n?"":a,d=p.applyBinding(p.applyLanguage(t,_,o),c,{index:y,key:B}),w=p.getBlockTagAttributes(t,!1),C=K(i,t._id,p.getBlockRuntimeProps(t._type)),S=r.has(o,"dataProvider")&&r.isFunction(o.dataProvider),P={blockProps:{},inBuilder:!1,lang:a||n,...d,...w,...C};if(r.isNull(f))return null;if(S){const v=r.get(o,"suspenseFallback",N);return u.jsx(m.Suspense,{fallback:m.createElement(v),children:u.jsx($,{lang:a,pageProps:g,block:t,dataProvider:o.dataProvider,...h?{dataProviderMetadataCallback:h}:{},draft:l,children:T=>m.createElement(f,{...P,...T,children:s({_id:t._id,_type:t._type,...r.isArray(d.repeaterItems)?{repeaterItems:p.applyLimit(d.repeaterItems,t),repeaterItemsBinding:d.repeaterItemsBinding}:{}})})})})}return u.jsx(m.Suspense,{children:m.createElement(f,{...P,children:s({_id:t._id,_type:t._type,...r.isArray(d.repeaterItems)?{repeaterItems:p.applyLimit(d.repeaterItems,t),repeaterItemsBinding:d.repeaterItemsBinding}:{}})})})},b=e=>{const{blocks:t,parent:a,repeaterData:n}=e,s=r.filter(t,i=>r.has(i,"_id")&&(r.isEmpty(a)?!i._parent:i._parent===a)),c=i=>r.filter(t,l=>l._parent===i).length>0;return r.map(s,i=>i?m.createElement(J,{...e,key:i._id,block:i},({_id:l,_type:g,repeaterItems:h,repeaterItemsBinding:o})=>g==="Repeater"?r.isArray(h)&&h.map((f,y)=>u.jsx(b,{...e,parent:i._id,repeaterData:{index:y,dataKey:o}})):c(l)?u.jsx(b,{...e,parent:i._id,repeaterData:n}):null):null)},K=(e,t,a)=>r.isEmpty(a)?{}:Object.entries(a).reduce((n,[s,c])=>{const i=[];let l=r.find(e,{_id:t});for(;l;)i.push(l),l=r.find(e,{_id:l._parent});const g=r.find(i,{_type:c.block});return g&&(n[s]=r.get(g,r.get(c,"prop"),null)),n},{});function V(e){if(r.has(e,"metadata")&&console.warn(" metadata is deprecated and will be removed in upcoming version, use pageProps instead"),r.isEmpty(e.lang)&&!r.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");const t=e.lang??"en",a=e.fallbackLang??t;return u.jsx(b,{...e,lang:t,fallbackLang:a})}exports.getChaiThemeCssVariables=k.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=k.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=k.getThemeFontsLinkMarkup;exports.RenderChaiBlocks=V;exports.convertToBlocks=E;exports.getStylesForBlocks=M;
package/dist/render.js CHANGED
@@ -1,7 +1,7 @@
1
- import { d as F, c as D } from "./plugin-fnBB3TCm.js";
2
- import { a as Pe, b as we, e as Be } from "./plugin-fnBB3TCm.js";
3
- import { a as O, b as $, g as A, c as N, d as B } from "./new-blocks-render-helpers-BGcG63he.js";
4
- import { has as k, omit as J, get as g, isFunction as M, isNull as E, isArray as _, filter as v, isEmpty as h, map as K, find as y } from "lodash-es";
1
+ import { d as D, c as O } from "./plugin-fnBB3TCm.js";
2
+ import { a as _e, b as we, e as Be } from "./plugin-fnBB3TCm.js";
3
+ import { a as $, b as A, g as M, c as N, d as B } from "./new-blocks-render-helpers-BGcG63he.js";
4
+ import { has as k, isFunction as S, omit as J, get as g, isNull as E, isArray as P, filter as v, isEmpty as h, map as K, find as y } from "lodash-es";
5
5
  import j from "@tailwindcss/aspect-ratio";
6
6
  import U from "@tailwindcss/forms";
7
7
  import V from "@tailwindcss/typography";
@@ -33,7 +33,7 @@ async function Q(e, t, a = [], r = "", i) {
33
33
  darkMode: "class",
34
34
  safelist: a,
35
35
  theme: { extend: q(e) },
36
- plugins: [U, V, j, z, D],
36
+ plugins: [U, V, j, z, O],
37
37
  corePlugins: { preflight: i },
38
38
  ...r ? { prefix: `${r}` } : {}
39
39
  }
@@ -47,7 +47,7 @@ async function Q(e, t, a = [], r = "", i) {
47
47
  const X = (e, t, a) => {
48
48
  const r = JSON.stringify(e).replace(/#styles:([^"]*)/g, (i, o) => `#styles:${o.replace(/,/g, " ")}`.replace(/#styles:/g, ""));
49
49
  return Q(t, [r], [], "", a);
50
- }, ke = async (e, t = F, a = !1) => await X(e, t, a);
50
+ }, ke = async (e, t = D, a = !1) => await X(e, t, a);
51
51
  async function Y(e) {
52
52
  const t = await e.dataProvider({
53
53
  pageProps: e.pageProps,
@@ -56,41 +56,41 @@ async function Y(e) {
56
56
  draft: e.draft,
57
57
  inBuilder: !1
58
58
  });
59
- return k(t, "$metadata") && e.dataProviderMetadataCallback(e.block, t.$metadata), e.children({
59
+ return k(t, "$metadata") && S(e.dataProviderMetadataCallback) && e.dataProviderMetadataCallback(e.block, t.$metadata), e.children({
60
60
  ...J(t, "$metadata")
61
61
  });
62
62
  }
63
63
  const Z = () => /* @__PURE__ */ d("div", {}), ee = (e) => {
64
- const { block: t, lang: a, fallbackLang: r, children: i, externalData: o, blocks: n, draft: s, pageProps: p, dataProviderMetadataCallback: m } = e, l = G(t._type), u = g(l, "component", null), b = g(e.repeaterData, "index", -1), S = g(e.repeaterData, "dataKey", ""), c = O($(t, a === r ? "" : a, l), o, {
64
+ const { block: t, lang: a, fallbackLang: r, children: i, externalData: o, blocks: n, draft: s, pageProps: p, dataProviderMetadataCallback: m } = e, l = G(t._type), u = g(l, "component", null), b = g(e.repeaterData, "index", -1), x = g(e.repeaterData, "dataKey", ""), c = $(A(t, a === r ? "" : a, l), o, {
65
65
  index: b,
66
- key: S
67
- }), x = A(t, !1), I = te(n, t._id, N(t._type)), T = k(l, "dataProvider") && M(l.dataProvider), w = {
66
+ key: x
67
+ }), I = M(t, !1), T = te(n, t._id, N(t._type)), L = k(l, "dataProvider") && S(l.dataProvider), w = {
68
68
  blockProps: {},
69
69
  inBuilder: !1,
70
70
  lang: a || r,
71
71
  ...c,
72
- ...x,
73
- ...I
72
+ ...I,
73
+ ...T
74
74
  };
75
75
  if (E(u)) return null;
76
- if (T) {
77
- const L = g(l, "suspenseFallback", Z);
78
- return /* @__PURE__ */ d(C, { fallback: f(L), children: /* @__PURE__ */ d(
76
+ if (L) {
77
+ const R = g(l, "suspenseFallback", Z);
78
+ return /* @__PURE__ */ d(C, { fallback: f(R), children: /* @__PURE__ */ d(
79
79
  Y,
80
80
  {
81
81
  lang: a,
82
82
  pageProps: p,
83
83
  block: t,
84
84
  dataProvider: l.dataProvider,
85
- dataProviderMetadataCallback: m,
85
+ ...m ? { dataProviderMetadataCallback: m } : {},
86
86
  draft: s,
87
- children: (R) => f(u, {
87
+ children: (F) => f(u, {
88
88
  ...w,
89
- ...R,
89
+ ...F,
90
90
  children: i({
91
91
  _id: t._id,
92
92
  _type: t._type,
93
- ..._(c.repeaterItems) ? {
93
+ ...P(c.repeaterItems) ? {
94
94
  repeaterItems: B(c.repeaterItems, t),
95
95
  repeaterItemsBinding: c.repeaterItemsBinding
96
96
  } : {}
@@ -104,18 +104,18 @@ const Z = () => /* @__PURE__ */ d("div", {}), ee = (e) => {
104
104
  children: i({
105
105
  _id: t._id,
106
106
  _type: t._type,
107
- ..._(c.repeaterItems) ? {
107
+ ...P(c.repeaterItems) ? {
108
108
  repeaterItems: B(c.repeaterItems, t),
109
109
  repeaterItemsBinding: c.repeaterItemsBinding
110
110
  } : {}
111
111
  })
112
112
  }) });
113
- }, P = (e) => {
113
+ }, _ = (e) => {
114
114
  const { blocks: t, parent: a, repeaterData: r } = e, i = v(
115
115
  t,
116
116
  (n) => k(n, "_id") && (h(a) ? !n._parent : n._parent === a)
117
117
  ), o = (n) => v(t, (s) => s._parent === n).length > 0;
118
- return K(i, (n) => n ? /* @__PURE__ */ f(ee, { ...e, key: n._id, block: n }, ({ _id: s, _type: p, repeaterItems: m, repeaterItemsBinding: l }) => p === "Repeater" ? _(m) && m.map((u, b) => /* @__PURE__ */ d(P, { ...e, parent: n._id, repeaterData: { index: b, dataKey: l } })) : o(s) ? /* @__PURE__ */ d(P, { ...e, parent: n._id, repeaterData: r }) : null) : null);
118
+ return K(i, (n) => n ? /* @__PURE__ */ f(ee, { ...e, key: n._id, block: n }, ({ _id: s, _type: p, repeaterItems: m, repeaterItemsBinding: l }) => p === "Repeater" ? P(m) && m.map((u, b) => /* @__PURE__ */ d(_, { ...e, parent: n._id, repeaterData: { index: b, dataKey: l } })) : o(s) ? /* @__PURE__ */ d(_, { ...e, parent: n._id, repeaterData: r }) : null) : null);
119
119
  }, te = (e, t, a) => h(a) ? {} : Object.entries(a).reduce((r, [i, o]) => {
120
120
  const n = [];
121
121
  let s = y(e, { _id: t });
@@ -128,12 +128,12 @@ function be(e) {
128
128
  if (k(e, "metadata") && console.warn(" metadata is deprecated and will be removed in upcoming version, use pageProps instead"), h(e.lang) && !h(e.fallbackLang))
129
129
  throw new Error("lang prop is required when fallbackLang is provided");
130
130
  const t = e.lang ?? "en", a = e.fallbackLang ?? t;
131
- return /* @__PURE__ */ d(P, { ...e, lang: t, fallbackLang: a });
131
+ return /* @__PURE__ */ d(_, { ...e, lang: t, fallbackLang: a });
132
132
  }
133
133
  export {
134
134
  be as RenderChaiBlocks,
135
135
  he as convertToBlocks,
136
- Pe as getChaiThemeCssVariables,
136
+ _e as getChaiThemeCssVariables,
137
137
  ke as getStylesForBlocks,
138
138
  we as getThemeFontsCSSImport,
139
139
  Be as getThemeFontsLinkMarkup
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": "2.2.12",
8
+ "version": "2.2.14",
9
9
  "type": "module",
10
10
  "repository": {
11
11
  "type": "git",