@chaibuilder/sdk 3.2.1 → 3.2.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{apply-binding-CSWwWMjY.js → apply-binding-B11pPFEE.js} +15 -17
- package/dist/apply-binding-DOJpwjiG.cjs +1 -0
- package/dist/{code-editor-DKqeEOn5.cjs → code-editor-CUimilR9.cjs} +1 -1
- package/dist/{code-editor-BNuPxnsb.js → code-editor-aEl9qnMt.js} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.d.ts +4 -0
- package/dist/core.js +2 -2
- package/dist/{index-CXFBOH6M.js → index-Cb4I9wM_.js} +97 -94
- package/dist/index-ClDik0i4.cjs +154 -0
- package/dist/render.cjs +1 -1
- package/dist/render.js +2 -2
- package/dist/{rte-widget-modal-DuUAGYPy.js → rte-widget-modal-BC3QU74X.js} +1 -1
- package/dist/{rte-widget-modal-BTpBxi3g.cjs → rte-widget-modal-Cr2Sx0uo.cjs} +1 -1
- package/dist/web-blocks.cjs +1 -1
- package/dist/web-blocks.js +1 -1
- package/package.json +1 -1
- package/dist/apply-binding-DLHh7HoS.cjs +0 -1
- package/dist/index-CjZEAWCM.cjs +0 -154
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";var Y=Object.defineProperty;var X=(o,n,a)=>n in o?Y(o,n,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[n]=a;var G=(o,n,a)=>X(o,typeof n!="symbol"?n+"":n,a);const jsxRuntime=require("react/jsx-runtime"),runtime=require("@chaibuilder/runtime"),lodashEs=require("lodash-es"),commonFunctions=require("./common-functions-B3a4xKt_.cjs"),jotai=require("jotai"),utils=require("jotai/utils"),clsx=require("clsx"),nanoid=require("nanoid"),tailwindMerge=require("tailwind-merge"),TreeModel=require("tree-model"),React=require("react"),applyBinding=require("./apply-binding-DOJpwjiG.cjs"),plugin=require("./plugin-CSgw-f78.cjs"),utils$1=require("@rjsf/utils"),sonner=require("sonner"),reactI18next=require("react-i18next"),web=require("@react-hookz/web"),Fuse=require("fuse.js"),UndoManager=require("undo-manager"),tooltip=require("./tooltip-Ba1-8jmj.cjs"),reactIcons=require("@radix-ui/react-icons"),i18n=require("i18next"),ReactDOM=require("react-dom"),reactColorful=require("react-colorful"),Highlight=require("@tiptap/extension-highlight"),Link=require("@tiptap/extension-link"),Placeholder=require("@tiptap/extension-placeholder"),TextAlign=require("@tiptap/extension-text-align"),extensionTextStyle=require("@tiptap/extension-text-style"),Underline=require("@tiptap/extension-underline"),react=require("@tiptap/react"),StarterKit=require("@tiptap/starter-kit"),RjForm=require("@rjsf/core"),validator=require("@rjsf/validator-ajv8"),Autosuggest=require("react-autosuggest"),reactArborist=require("react-arborist"),himalaya=require("himalaya"),tailwindAspectRatio=require("@tailwindcss/aspect-ratio"),tailwindForms=require("@tailwindcss/forms"),tailwindTypography=require("@tailwindcss/typography");require("tailwindcss-animate");require("@mhsdesign/jit-browser-tailwindcss");const twContainer=require("@tailwindcss/container-queries"),reactHotkeysHook=require("react-hotkeys-hook"),reactErrorBoundary=require("react-error-boundary"),getChaiBuilderTailwindConfig=require("./get-chai-builder-tailwind-config-C6MHaUM0.cjs"),framerMotion=require("framer-motion"),dom=require("@floating-ui/dom"),reactDom=require("@floating-ui/react-dom"),reactWrapBalancer=require("react-wrap-balancer");function _interopNamespaceDefault(o){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const a in o)if(a!=="default"){const r=Object.getOwnPropertyDescriptor(o,a);Object.defineProperty(n,a,r.get?r:{enumerable:!0,get:()=>o[a]})}}return n.default=o,Object.freeze(n)}const React__namespace=_interopNamespaceDefault(React),CHAI_BUILDER_EVENTS={OPEN_ADD_BLOCK:"OPEN_ADD_BLOCK",CLOSE_ADD_BLOCK:"CLOSE_ADD_BLOCK",SHOW_BLOCK_SETTINGS:"SHOW_BLOCK_SETTINGS",GOTO_BLOCK_SETTINGS:"GOTO_BLOCK_SETTINGS",OPEN_AI_PANEL:"OPEN_AI_PANEL",CLEAR_CANVAS_SELECTION:"CLEAR_CANVAS_SELECTION",CANVAS_BLOCK_SELECTED:"CANVAS_BLOCK_SELECTED",CANVAS_BLOCK_STYLE_SELECTED:"CANVAS_BLOCK_STYLE_SELECTED",OPEN_EXPORT_CODE:"OPEN_EXPORT_CODE"},canAcceptChildBlock=(o,n)=>{if(!o)return!0;const a=runtime.getRegisteredChaiBlock(o);return a&&lodashEs.has(a,"canAcceptBlock")?a.canAcceptBlock(n):!1},canAddChildBlock=o=>{const n=runtime.getRegisteredChaiBlock(o);return n?lodashEs.has(n,"canAcceptBlock"):!1},canBeNestedInside=(o,n)=>{const a=runtime.getRegisteredChaiBlock(n);return a&&lodashEs.has(a,"canBeNested")?a.canBeNested(o):!0},canDuplicateBlock=o=>{const n=runtime.getRegisteredChaiBlock(o);return n&&lodashEs.has(n,"canDuplicate")?n.canDuplicate():!0},canDeleteBlock=o=>{const n=runtime.getRegisteredChaiBlock(o);return n&&lodashEs.has(n,"canDelete")?n.canDelete():!0},canDropBlock=(o,{dragSource:n,dropTarget:a})=>{const r=lodashEs.get(n,"data._type",""),i=lodashEs.get(a,"data._type","");return canAcceptChildBlock(i,r)};class PubSub{constructor(){G(this,"subscribers",new Map)}subscribe(n,a){return this.subscribers.has(n)||this.subscribers.set(n,new Set),this.subscribers.get(n).add(a),()=>{const r=this.subscribers.get(n);r&&(r.delete(a),r.size===0&&this.subscribers.delete(n))}}publish(n,a){const r=this.subscribers.get(n);r&&r.forEach(i=>i(a))}}const pubsub=new PubSub,AddBlockDropdown=({block:o,children:n})=>{const{t:a}=reactI18next.useTranslation(),[r]=useBlocksStore(),{hasPermission:i}=usePermissions(),l=lodashEs.get(o,"_id"),c=lodashEs.get(o,"_parent"),d=lodashEs.filter(r,h=>c?lodashEs.get(h,"_parent")===c:!lodashEs.get(h,"_parent")),p=canAddChildBlock(lodashEs.get(o,"_type","")),u=lodashEs.findIndex(d,{_id:l}),m=h=>{if(h==="CHILD")pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,o);else{const x={_id:c||"",position:d==null?void 0:d.length};h==="BEFORE"?x.position=Math.max(u,0):h==="AFTER"&&(x.position=u+1),pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,x)}};return i(PERMISSIONS.ADD_BLOCK)?jsxRuntime.jsxs(tooltip.DropdownMenu,{children:[jsxRuntime.jsx(tooltip.DropdownMenuTrigger,{children:n}),jsxRuntime.jsxs(tooltip.DropdownMenuContent,{className:"border border-blue-500 bg-primary text-white shadow-2xl",children:[p&&jsxRuntime.jsx(tooltip.DropdownMenuItem,{className:"cursor-pointer text-xs",onClick:()=>m("CHILD"),children:a("Add inside")}),jsxRuntime.jsx(tooltip.DropdownMenuItem,{className:"cursor-pointer text-xs",onClick:()=>m("BEFORE"),children:a("Add before")}),jsxRuntime.jsx(tooltip.DropdownMenuItem,{className:"cursor-pointer text-xs",onClick:()=>m("AFTER"),children:a("Add after")})]})]}):null};function duplicateBlocks(o,n,a){const r=lodashEs.filter(o,l=>l._parent===n),i=[];for(let l=0;l<r.length;l++)if(lodashEs.filter(o,{_parent:r[l]._id}).length>0){const c=commonFunctions.generateUUID();i.push({...r[l],oldId:r[l]._id,_id:c,_parent:a}),i.push(lodashEs.flatten(duplicateBlocks(o,r[l]._id,c)))}else i.push({...r[l],oldId:r[l]._id,_id:commonFunctions.generateUUID(),_parent:a});return lodashEs.flatten(i)}function convertToBlocksTree(o){const n={};o.forEach(r=>{n[r._id]={...r,children:[]}});const a=[];return o.forEach(r=>{if(r._parent){const i=n[r._parent];i&&i.children.push(n[r._id])}else a.push(n[r._id])}),a}const getDuplicatedBlocks=(o,n,a=null)=>{let r=lodashEs.find(o,{_id:n});r={...r,oldId:r._id,_id:commonFunctions.generateUUID()},a!==(r==null?void 0:r._parent)&&(r={...r,_parent:a});const i=[r];return lodashEs.filter(o,{_parent:n}).length>0&&i.push(lodashEs.flatten(duplicateBlocks(o,n,r._id))),lodashEs.flatten(i)},presentBlocksAtom=jotai.atom([]);presentBlocksAtom.debugLabel="presentBlocksAtom";const treeDSBlocks=jotai.atom(o=>{const n=o(presentBlocksAtom);return convertToBlocksTree([...n])});treeDSBlocks.debugLabel="treeDSBlocks";const pageBlocksAtomsAtom=utils.splitAtom(presentBlocksAtom);pageBlocksAtomsAtom.debugLabel="pageBlocksAtomsAtom";const builderActivePageAtom=jotai.atom("");builderActivePageAtom.debugLabel="builderActivePageAtom";const destinationDropIndexAtom=jotai.atom(-1);destinationDropIndexAtom.debugLabel="destinationDropIndexAtom";const buildingBlocksAtom=jotai.atom([]);buildingBlocksAtom.debugLabel="buildingBlocksAtom";const globalBlocksAtom=jotai.atom(o=>{const n=o(buildingBlocksAtom);return lodashEs.filter(n,a=>lodashEs.has(a,"blockId"))});globalBlocksAtom.debugLabel="globalBlocksAtom";const structureErrorsAtom=jotai.atom([]);structureErrorsAtom.debugLabel="structureErrorsAtom";const structureValidationValidAtom=jotai.atom(!0);structureValidationValidAtom.debugLabel="structureValidationValidAtom";const hasStructureErrorsAtom=jotai.atom(!1);hasStructureErrorsAtom.debugLabel="hasStructureErrorsAtom";const hasStructureWarningsAtom=jotai.atom(!1);hasStructureWarningsAtom.debugLabel="hasStructureWarningsAtom";const structureErrorCountAtom=jotai.atom(o=>o(structureErrorsAtom).filter(a=>a.severity==="error").length);structureErrorCountAtom.debugLabel="structureErrorCountAtom";const structureWarningCountAtom=jotai.atom(o=>o(structureErrorsAtom).filter(a=>a.severity==="warning").length);structureWarningCountAtom.debugLabel="structureWarningCountAtom";const structureErrorsByBlockAtom=jotai.atom(o=>{const n=o(structureErrorsAtom),a={};return n.forEach(r=>{r.blockId&&(a[r.blockId]||(a[r.blockId]=[]),a[r.blockId].push(r))}),a});structureErrorsByBlockAtom.debugLabel="structureErrorsByBlockAtom";function insertBlocksAtPosition(o,n,a,r){const i=[...n];let l=[...o];if(a){const u=o.find(m=>m._id===a);if(u&&u.content!==void 0&&u.content!==""&&!o.some(h=>h._parent===a)){const x={_id:commonFunctions.generateUUID(),_parent:a,_type:"Text",content:u.content};Object.keys(u).forEach(g=>{g.startsWith("content-")&&(x[g]=u[g])}),i.unshift(x),l=l.map(g=>{if(g._id===a){const f={...g,content:""};return Object.keys(f).forEach(b=>{b.startsWith("content-")&&(f[b]="")}),f}return g})}}let c=l.filter(u=>!u._parent);a&&(c=l.filter(u=>u._parent===a));const d=!isNaN(r)||r>-1?Math.min(r,c.length):c.length;let p=l.length;for(let u=0,m=0;u<l.length;u++)if(a!==void 0?l[u]._parent===a:!l[u]._parent){if(m===d){p=u;break}m++}return!a&&r!==void 0&&r>=c.length&&(p=l.length),[...l.slice(0,p),...i,...l.slice(p)]}function getBlocksTree(o){return convertToBlocksTree(o)}function flattenTree(o){let n=[];return o.walk(a=>(delete a.model.children,n.push(a.model),!0)),n}function findNodeById(o,n){return o.first(a=>a.model._id===n)||null}function moveNode(o,n,a,r){var u,m;const i=findNodeById(o,n),l=findNodeById(o,a);if(!i||!l)return!1;l.children||(l.model.children=[]);let c=(u=l==null?void 0:l.children)==null?void 0:u.findIndex(h=>h.model._id===n);i.drop(),c=Math.max(c,0);const p=(((m=i==null?void 0:i.model)==null?void 0:m._parent)||"root")===a&&c<=r?r-1:r;try{l.addChildAtIndex(i,p)}catch(h){return console.error("Error adding child to parent:",h),!1}return!0}function handleOldParentTextBlock(o,n){if(!n||!n._parent)return o;const a=n._parent,r=o.find(l=>l._id===a);if(!r)return o;const i=o.filter(l=>l._parent===a);if(i.length===2){const l=i.find(c=>c._id!==n._id);if(l&&l._type==="Text"&&"content"in r)return o.map(d=>{if(d._id===a){const p={...d,content:l.content};return Object.keys(l).forEach(u=>{u.startsWith("content-")&&(p[u]=l[u])}),p}return d}).filter(d=>d._id!==l._id)}return o}function handleNewParentTextBlock(o,n,a){if(!a||a==="root")return o;const r=o.find(i=>i._id===a);if(!r)return o;if(r.content!==void 0&&r.content!==""&&!o.some(l=>l._parent===a&&l._id!==n._id)){const c={_id:commonFunctions.generateUUID(),_parent:a,_type:"Text",content:r.content};Object.keys(r).forEach(u=>{u.startsWith("content-")&&(c[u]=r[u])});const d=o.map(u=>{if(u._id===a){const m={...u,content:""};return Object.keys(m).forEach(h=>{h.startsWith("content-")&&(m[h]="")}),m}return u}),p=d.findIndex(u=>u._id===n._id);return p!==-1?[...d.slice(0,p),c,...d.slice(p)]:[c,...d]}return o}function moveBlocksWithChildren(o,n,a,r){if(!n)return o;const i=o.find(u=>u._id===n);if(!i)return o;let l=handleOldParentTextBlock(o,i);const c=a||"root",p=new TreeModel().parse({_id:"root",children:getBlocksTree(l)});if(moveNode(p,n,c,r)){let u=flattenTree(p);const m=u.find(h=>h._id===n);return m&&(m._parent=c==="root"?null:c),u.shift(),a&&(u=handleNewParentTextBlock(u,i,a)),u}return l}const broadcastChannel=new BroadcastChannel("chaibuilder"),useBroadcastChannel=()=>{const o=useBuilderProp("pageId","chaibuilder_page");return{postMessage:web.useDebouncedCallback(a=>broadcastChannel.postMessage({...a,pageId:o}),[o],200)}},useUnmountBroadcastChannel=()=>{const[,o]=useBlocksStore(),n=useBuilderProp("pageId","chaibuilder_page"),{updateBlocksProps:a}=useBlocksStoreManager();React.useEffect(()=>(broadcastChannel.onmessageerror=r=>{console.log("error",r)},broadcastChannel.onmessage=r=>{r.data.type==="blocks-updated"&&r.data.pageId===n&&o(r.data.blocks),r.data.type==="blocks-props-updated"&&r.data.pageId===n&&a(r.data.blocks)},()=>{broadcastChannel.onmessage=null,broadcastChannel.onmessageerror=null}),[o,n])},selectedBlockIdsAtom=jotai.atom([]);selectedBlockIdsAtom.debugLabel="selectedBlockIdsAtom";const selectedBlocksAtom=jotai.atom(o=>{const n=o(presentBlocksAtom),a=o(selectedBlockIdsAtom);return lodashEs.map(lodashEs.filter(n,({_id:r})=>lodashEs.includes(a,r)),r=>({...r}))});selectedBlocksAtom.debugLabel="selectedBlocksAtom";const selectedBlockAtom=jotai.atom(o=>{const n=o(selectedBlocksAtom);if(n.length===0)return null;if(n.length===1)return n[0]});selectedBlockAtom.debugLabel="selectedBlockAtom";const useSelectedBlock=()=>jotai.useAtomValue(selectedBlockAtom),getParentId=o=>lodashEs.get(o,"_parent",null),selectedBlocksParentsAtom=jotai.atom(o=>{const n=o(selectedBlocksAtom),a=lodashEs.map(n,getParentId);return lodashEs.filter(o(presentBlocksAtom),r=>lodashEs.includes(a,r._id))});selectedBlocksParentsAtom.debugLabel="selectedBlocksParentsAtom";const selectedBlockFlexChildAtom=jotai.atom(()=>!1);selectedBlockFlexChildAtom.debugLabel="selectedBlockFlexChildAtom";const selectedBlockGridChildAtom=jotai.atom(()=>!1);selectedBlockGridChildAtom.debugLabel="selectedBlockGridChildAtom";const styleStateAtom=jotai.atom("");styleStateAtom.debugLabel="styleStateAtom";const styleBreakpointAtom=utils.atomWithStorage("styleBreakpoint","xs");styleBreakpointAtom.debugLabel="styleBreakpointAtom";const useSelectedBlocksDisplayChild=()=>({flexChild:jotai.useAtomValue(selectedBlockFlexChildAtom),gridChild:jotai.useAtomValue(selectedBlockGridChildAtom)}),selectedBlockHierarchy=jotai.atom(o=>{const n=o(selectedBlockAtom),a=o(presentBlocksAtom);let r=n;const i=[n];do{const l=a.find(({_id:c})=>c===(r==null?void 0:r._parent));r=l,l&&i.push(l)}while(r!=null&&r._parent);return i}),useSelectedBlockHierarchy=()=>lodashEs.compact(jotai.useAtomValue(selectedBlockHierarchy)),useSelectedBlockIds=()=>{const[o,n]=jotai.useAtom(selectedBlockIdsAtom),a=React.useCallback(r=>{n(i=>lodashEs.includes(i,r)?lodashEs.without(i,r):[...i,r])},[n]);return[o,n,a]},removeNestedBlocks=(o,n)=>{let a=[...o],r=[];n.forEach(d=>{const p=a.find(h=>h._id===d);if(!p||!p._parent)return;const u=p._parent,m=a.filter(h=>h._parent===u);if(m.length===2){const h=m.find(x=>x._id!==d);if(h&&h._type==="Text"){const x=a.find(g=>g._id===u);x&&"content"in x&&(a=a.map(g=>{if(g._id===u){const f={...g,content:h.content};return Object.keys(h).forEach(b=>{b.startsWith("content-")&&(f[b]=h[b])}),f}return g}),r.push(h._id))}}});const i=[...n,...r],l=[],c=lodashEs.filter(a,d=>lodashEs.includes(i,d._id)||lodashEs.includes(i,d._parent)?(l.push(d._id),!1):!0);return lodashEs.isEmpty(l)?c:removeNestedBlocks(c,l)},useRemoveBlocks=()=>{const[o]=useBlocksStore(),[n,a]=useSelectedBlockIds(),{setNewBlocks:r}=useBlocksStoreUndoableActions(),{hasPermission:i}=usePermissions();return React.useCallback(l=>{var d;if(!i(PERMISSIONS.DELETE_BLOCK))return;const c=((d=lodashEs.find(o,{_id:l[0]}))==null?void 0:d._parent)||null;r(removeNestedBlocks(o,l)),setTimeout(()=>a(c?[c]:[]),200)},[o,a,n,i])},builderStore=jotai.getDefaultStore(),writeAtomValue=jotai.atom(null,(o,n,{id:a,props:r})=>{const i=o(pageBlocksAtomsAtom),l=lodashEs.find(i,c=>o(c)._id===a);return l?n(l,{...o(l),...r}):null}),useUpdateBlockAtom=()=>jotai.useSetAtom(writeAtomValue),useGetBlockAtom=o=>utils.useAtomCallback(React.useCallback((n,a,r)=>{const i=n(o);if(!i||!i.length)return console.warn("No blocks available in splitAtoms"),null;const l=lodashEs.find(i,c=>n(c)._id===(lodashEs.isString(r)?r:n(r)._id));return l||(console.warn(`Block with id ${r} not found`),null)},[o]),{store:builderStore}),userActionsCountAtom=jotai.atom(0),useAutoSave=()=>{const{savePage:o,saveState:n}=useSavePage(),a=useBuilderProp("autoSave",!0),r=useBuilderProp("autoSaveActionsCount",10),[i]=jotai.useAtom(userActionsCountAtom);React.useEffect(()=>{a&&(n==="SAVED"||n==="SAVING"||i>=r&&o(!0))},[a,n,i,r])},useIncrementActionsCount=()=>{const[,o]=jotai.useAtom(userActionsCountAtom);return React.useCallback(()=>{o(n=>n+1)},[o])},CORE_STRUCTURE_RULES=[{name:"no-nested-div-in-p",description:"Prevents div elements from being nested inside paragraph elements",validate:(o,n)=>{const a=[],r=(i,l=!1)=>{i.forEach(c=>{const d=c._type==="Paragraph";c._type==="Box"&&l&&a.push({id:`div-in-paragraph-${c._id}`,message:"Box (div) cannot be nested inside Paragraph elements",severity:"error",blockId:c._id}),c.children&&c.children.length>0&&r(c.children,d)})};return r(n),a}},{name:"no-interactive-nesting",description:"Prevents interactive elements (links, buttons with href) from being nested inside other interactive elements",validate:(o,n)=>{const a=[],r=(l,c=!1,d=[])=>{l.forEach(p=>{const u=[...d,p._id],m=p._type==="Link",h=p._type==="Button"&&p.link&&p.link.href&&p.link.href.trim()!=="",x=m||h;if(x&&c){const g=m?"Link":"Button with href";a.push({id:`nested-interactive-tree-${p._id}`,message:`${g} cannot be nested inside another interactive element (link or button with href)`,severity:"error",blockId:p._id})}p.children&&p.children.length>0&&r(p.children,x,u)})},i=l=>{l.filter(d=>d._type==="Link"||d._type==="Button"&&d.link&&d.link.href&&d.link.href.trim()!=="").forEach(d=>{if(d._parent){const p=l.find(x=>x._id===d._parent),u=p&&p._type==="Link",m=p&&p._type==="Button"&&p.link&&p.link.href&&p.link.href.trim()!=="";if(u||m){const x=d._type==="Link"?"Link":"Button with href",g=u?"Link":"Button with href";a.push({id:`nested-interactive-parent-${d._id}`,message:`${x} cannot be nested inside ${g}`,severity:"error",blockId:d._id})}let h=p;for(;h&&h._parent;){const x=l.find(g=>g._id===h._parent);if(x){const g=x._type==="Link",f=x._type==="Button"&&x.link&&x.link.href&&x.link.href.trim()!=="";if(g||f){const b=d._type==="Link"?"Link":"Button with href",j=g?"Link":"Button with href";a.push({id:`nested-interactive-ancestor-${d._id}`,message:`${b} cannot be nested inside ${j}`,severity:"error",blockId:d._id});break}}h=x}}})};return r(n),i(o),a}},{name:"listitem-in-list",description:"Ensures ListItems are only inside List containers",validate:(o,n)=>{const a=[],r=(i,l=null)=>{i.forEach(c=>{c._type==="ListItem"&&l!=="List"&&a.push({id:`listitem-outside-list-${c._id}`,message:"List Item must be inside a List container",severity:"error",blockId:c._id}),c.children&&c.children.length>0&&r(c.children,c._type)})};return r(n),a}},{name:"table-cell-structure",description:"Validates proper table hierarchy (TableCell -> TableRow -> TableHead/Body -> Table)",validate:(o,n)=>{const a=[],r=(i,l=[])=>{i.forEach(c=>{const d=[...l,c._type];if(c._type==="TableCell"){const p=d.includes("TableRow"),u=d.includes("TableHead")||d.includes("TableBody"),m=d.includes("Table");(!p||!u||!m)&&a.push({id:`table-cell-structure-${c._id}`,message:"Table Cell must be inside a Table Row, which must be inside Table Head/Body, which must be inside a Table",severity:"error",blockId:c._id})}c._type==="TableRow"&&!d.slice(0,-1).includes("Table")&&a.push({id:`table-row-outside-table-${c._id}`,message:"Table Row must be inside a Table (Table Head or Table Body)",severity:"error",blockId:c._id}),(c._type==="TableHead"||c._type==="TableBody")&&!d.slice(0,-1).includes("Table")&&a.push({id:`table-section-outside-table-${c._id}`,message:"Table Head/Body must be inside a Table",severity:"error",blockId:c._id}),c.children&&c.children.length>0&&r(c.children,d)})};return r(n),a}},{name:"no-nested-buttons",description:"Prevents buttons from being nested inside other buttons",validate:(o,n)=>{const a=[],r=(i,l=!1)=>{i.forEach(c=>{const d=c._type==="Button";d&&l&&a.push({id:`nested-button-${c._id}`,message:"Button cannot be nested inside another button",severity:"error",blockId:c._id}),c.children&&c.children.length>0&&r(c.children,d)})};return r(n),a}},{name:"no-nested-paragraphs",description:"Prevents paragraph elements from being nested inside other paragraph elements at any level",validate:(o,n)=>{const a=[],r=(i,l=[])=>{i.forEach(c=>{const d=c._type==="Paragraph";if(d&&l.length>0&&a.push({id:`nested-paragraph-${c._id}`,message:"Paragraph cannot be nested inside another paragraph",severity:"error",blockId:c._id}),c.children&&c.children.length>0){const p=d?[...l,c._id]:l;r(c.children,p)}})};return r(n),a}},{name:"heading-structure",description:"Checks for proper heading hierarchy and warns about skipped levels",validate:(o,n)=>{const a=[],r=[],i=(l,c=[])=>{l.forEach(d=>{if(d._type==="Heading"){const p=d.tag||"h2",u=parseInt(p.replace("h",""))||2;r.push({level:u,blockId:d._id,path:[...c,d._id]})}d.children&&d.children.length>0&&i(d.children,[...c,d._id])})};i(n);for(let l=1;l<r.length;l++){const c=r[l],d=r[l-1];c.level>d.level+1&&a.push({id:`heading-level-skip-${c.blockId}`,message:`Heading level skipped: h${d.level} followed by h${c.level}. Consider using h${d.level+1}`,severity:"warning",blockId:c.blockId})}return a}}],ACCESSIBILITY_RULES=[{name:"image-alt-text",description:"Warns if images are missing alt text",validate:(o,n)=>{const a=[],r=i=>{i.forEach(l=>{l._type==="Image"&&!l.alt&&a.push({id:`image-missing-alt-${l._id}`,message:"Image should have alt text for accessibility",severity:"warning",blockId:l._id}),l.children&&l.children.length>0&&r(l.children)})};return r(n),a}},{name:"button-accessibility",description:"Ensures buttons have accessible labels",validate:(o,n)=>{const a=[],r=i=>{i.forEach(l=>{l._type==="Button"&&(l.content||l.children&&l.children.length>0||a.push({id:`button-no-label-${l._id}`,message:"Button should have accessible content (text or icon)",severity:"warning",blockId:l._id})),l.children&&l.children.length>0&&r(l.children)})};return r(n),a}}];class StructureRuleRegistry{constructor(){G(this,"rules",[...CORE_STRUCTURE_RULES])}addRule(n){this.rules.push(n)}removeRule(n){const a=this.rules.findIndex(r=>r.name===n);return a>-1?(this.rules.splice(a,1),!0):!1}getRules(){return[...this.rules]}enableAccessibilityRules(){this.rules.push(...ACCESSIBILITY_RULES)}getRuleNames(){return this.rules.map(n=>n.name)}}const defaultRuleRegistry=new StructureRuleRegistry,useCheckStructure=(o={})=>{const n=useBuilderProp("flags.validateStructure",!0),a=jotai.useSetAtom(structureErrorsAtom),r=jotai.useSetAtom(structureValidationValidAtom),i=jotai.useSetAtom(hasStructureErrorsAtom),l=jotai.useSetAtom(hasStructureWarningsAtom);return React.useCallback(d=>{const p=d;if(!n||p.length===0)return;const u=convertToBlocksTree(p),m=[];let h=defaultRuleRegistry.getRules();o.enableAccessibilityRules&&(defaultRuleRegistry.enableAccessibilityRules(),h=defaultRuleRegistry.getRules()),o.customRules&&o.customRules.length>0&&h.push(...o.customRules),h.forEach(b=>{try{const j=b.validate(p,u);m.push(...j)}catch(j){console.error(`Error running structure rule "${b.name}":`,j)}});const x=m.filter(b=>b.severity==="error").length>0,g=m.filter(b=>b.severity==="warning").length>0,f=!x;a(m),r(f),i(x),l(g)},[n,o,a,r,i,l])},useBlocksStoreManager=()=>{const[,o]=useBlocksStore(),{postMessage:n}=useBroadcastChannel(),a=useUpdateBlockAtom(),r=useCheckStructure(),i=useIncrementActionsCount();return{setNewBlocks:l=>{o(l),n({type:"blocks-updated",blocks:l})},addBlocks:(l,c,d)=>{o(p=>{const u=insertBlocksAtPosition(p,l,c,d);return n({type:"blocks-updated",blocks:u}),r(u),i(),u})},removeBlocks:l=>{o(c=>{const d=removeNestedBlocks(c,l);return n({type:"blocks-updated",blocks:d}),r(d),i(),d})},moveBlocks:(l,c,d)=>{o(p=>{let u=[...p];for(let m=0;m<l.length;m++)u=moveBlocksWithChildren(u,l[m],c,d);return lodashEs.each(l,m=>{const h=lodashEs.find(u,x=>x._id===m);h&&a({id:m,props:{_parent:h._parent||null}})}),n({type:"blocks-updated",blocks:u}),r(u),i(),u})},updateBlocksProps:l=>{l.forEach(c=>{const d=lodashEs.omit(c,"_id");a({id:c._id,props:d})}),n({type:"blocks-props-updated",blocks:l}),i()}}},blockRepeaterDataAtom=jotai.atom({});blockRepeaterDataAtom.debugLabel="blockRepeaterDataAtom";const useBlockRepeaterDataAtom=()=>jotai.useAtom(blockRepeaterDataAtom),useAsyncProps=(o,n,a,r)=>{const[i,l]=React.useState({status:"idle",props:{},error:void 0}),c=useUpdateBlocksPropsRealtime(),d=useBuilderProp("getBlockAsyncProps",async g=>({})),p=jotai.useSetAtom(blockRepeaterDataAtom),u=JSON.stringify([o==null?void 0:o._id,...lodashEs.values(lodashEs.pick(o,a??[]))]),m=(o==null?void 0:o._type)==="Repeater"&&lodashEs.startsWith(o.repeaterItems,`{{${applyBinding.COLLECTION_PREFIX}`),h=(o==null?void 0:o._type)!=="Repeater"&&n==="live";return React.useEffect(()=>{if(n==="mock"){if(lodashEs.isFunction(r)){l(f=>({...f,status:"loading",props:{}}));const g=r({block:o});if(!utils$1.isObject(g))throw new Error("mockDataProvider should return an object");l(f=>({...f,status:"loaded",props:g}))}return}n==="live"&&(!m&&!h||(l(g=>({...g,status:"loading",props:{}})),d({block:o}).then((g={})=>{m?(p(f=>({...f,[o._id]:{status:"loaded",props:lodashEs.get(g,"items",[]),repeaterItems:o.repeaterItems}})),l(f=>({...f,status:"loaded",props:{totalItems:lodashEs.get(g,"totalItems")}})),c([o._id],{totalItems:lodashEs.get(g,"totalItems")})):l(f=>({...f,status:"loaded",props:utils$1.isObject(g)?g:{}}))}).catch(g=>{m?(p(f=>({...f,[o._id]:{status:"error",error:g,props:[]}})),l(f=>({...f,status:"error",error:g,props:{}}))):l(f=>({...f,status:"error",error:g,props:{}}))})))},[o==null?void 0:o._id,u,m,h,r,n]),{$loading:lodashEs.get(i,"status")==="loading",...o?lodashEs.get(i,"props",{}):{}}},chaiBuilderPropsAtom=jotai.atom(null);chaiBuilderPropsAtom.debugLabel="chaiBuilderPropsAtom";const chaiExternalDataAtom=jotai.atom({});chaiExternalDataAtom.debugLabel="chaiExternalDataAtom";const chaiRjsfFieldsAtom=jotai.atom({});chaiRjsfFieldsAtom.debugLabel="chaiRjsfFieldsAtom";const chaiRjsfWidgetsAtom=jotai.atom({});chaiRjsfWidgetsAtom.debugLabel="chaiRjsfWidgetsAtom";const chaiRjsfTemplatesAtom=jotai.atom({});chaiRjsfTemplatesAtom.debugLabel="chaiRjsfTemplatesAtom";const chaiPageExternalDataAtom=jotai.atom({});chaiPageExternalDataAtom.debugLabel="chaiPageExternalDataAtom";const chaiDesignTokensAtom=jotai.atom({});chaiDesignTokensAtom.debugLabel="chaiDesignTokensAtom";const usePageExternalData=()=>{const[o]=useBlockRepeaterDataAtom(),n=React.useMemo(()=>{const r={};return Object.entries(o).forEach(([i,l])=>{l.status==="loaded"&&(r[l.repeaterItems.replace("}}",`/${i}`).replace("{{","")]=l.props)}),r},[o]);return{...jotai.useAtomValue(chaiPageExternalDataAtom),...n}},useBuilderProp=(o,n=void 0)=>{const a=jotai.useAtomValue(chaiBuilderPropsAtom);return React.useMemo(()=>lodashEs.get(a,o,n),[a,o,n])},MODIFIERS=["hover","focus","focus-within","focus-visible","active","visited","target","first","last","only","odd","even","first-of-type","last-of-type","only-of-type","empty","disabled","checked","indeterminate","default","required","valid","invalid","in-range","out-of-range","placeholder-shown","autofill","read-only","open","before","after","first-letter","first-line","marker","selection","file","placeholder","hs-collapse-open","hs-accordion-active"],BRANDING_OPTIONS_DEFAULTS={bodyFont:"Inter",headingFont:"Inter",roundedCorners:5,primaryColor:"#570df8",secondaryColor:"#f002b8",bodyBgDarkColor:"#031022",bodyBgLightColor:"#fcfcfc",bodyTextDarkColor:"#ffffff",bodyTextLightColor:"#000000"},brandingOptionsAtom=jotai.atom(BRANDING_OPTIONS_DEFAULTS);jotai.atom(null);const useBrandingOptions=()=>{const[o,n]=jotai.useAtom(brandingOptionsAtom);return[lodashEs.isObject(o)?{...BRANDING_OPTIONS_DEFAULTS,...o}:BRANDING_OPTIONS_DEFAULTS,n]},currentPageAtom=jotai.atom(null),useCurrentPage=()=>({currentPage:jotai.useAtomValue(currentPageAtom)}),getBlockBuilderProps=lodashEs.memoize(o=>{const n=runtime.getRegisteredChaiBlock(o),a=lodashEs.get(n,"schema.properties",{});return lodashEs.compact(Object.keys(a).map(r=>lodashEs.get(a[r],"builderProp",!1)||lodashEs.get(a[r],"runtime",!1)?r:null))}),useGetPageData=()=>{const[o]=useBrandingOptions(),{currentPage:n}=useCurrentPage(),[a]=useBlocksStore();return React.useCallback(()=>{const r=lodashEs.map(a,i=>lodashEs.omit(i,getBlockBuilderProps(i._type)));return{currentPage:n,blocks:r}},[o,n,a])},isPageLoadedAtom=jotai.atom(!1),useIsPageLoaded=()=>jotai.useAtom(isPageLoadedAtom),languageAtom=jotai.atom("");languageAtom.debugLabel="selectedLanguageAtom";const useLanguages=()=>{const o=useBuilderProp("languages",[]),n=useBuilderProp("fallbackLang","en"),[a,r]=jotai.useAtom(languageAtom),i=l=>{r(n===l?"":l)};return{languages:o==null?void 0:o.filter(l=>l!==n),fallbackLang:n,selectedLang:a,setSelectedLang:i}},usePermissions=()=>{const o=useBuilderProp("permissions",void 0);return{hasPermission:React.useCallback(a=>o?o.includes(a):!0,[o])}},getDefaultThemeValues=(o=plugin.defaultThemeOptions)=>{const n=plugin.defaultThemeValues;return o.fontFamily&&(n.fontFamily=Object.entries(o.fontFamily).reduce((a,[r,i])=>({...a,[r.replace("font-","")]:i}),n.fontFamily)),n.borderRadius=o.borderRadius,o.colors&&(n.colors=o.colors.reduce((a,r)=>(Object.entries(r.items).forEach(([i,l])=>{a[i]=l}),a),n.colors)),n},chaiThemeValuesAtom=jotai.atom({}),useTheme=()=>{const o=useThemeOptions(),n=React.useMemo(()=>getDefaultThemeValues(o),[o]),a=useBuilderProp("theme",{}),[r,i]=jotai.useAtom(chaiThemeValuesAtom);return[React.useMemo(()=>({...n,...!lodashEs.isEmpty(a)&&a,...!lodashEs.isEmpty(r)&&r}),[n,a,r]),i]},useThemeOptions=()=>{const o=useBuilderProp("themeOptions",a=>a);return React.useMemo(()=>o(plugin.defaultThemeOptions),[o])},rightPanelAtom=jotai.atom("block"),useRightPanel=()=>jotai.useAtom(rightPanelAtom),builderSaveStateAtom=jotai.atom("SAVED");builderSaveStateAtom.debugLabel="builderSaveStateAtom";const checkMissingTranslations=(o,n)=>n?o.some(a=>{if(!(a!=null&&a._type)||a._type==="PartialBlock")return!1;try{const r=runtime.getRegisteredChaiBlock(a._type);return r?(lodashEs.has(r,"i18nProps")?r.i18nProps:[]).some(l=>{const c=`${l}-${n}`;return!a[c]||lodashEs.isEmpty(a[c])}):!1}catch(r){return console.warn(`Failed to get block definition for type: ${a._type}`,r),!1}}):!1,useSavePage=()=>{const[o,n]=jotai.useAtom(builderSaveStateAtom),a=useBuilderProp("onSave",async j=>{}),r=useBuilderProp("onSaveStateChange",lodashEs.noop),i=useGetPageData(),[l]=useTheme(),{hasPermission:c}=usePermissions(),{selectedLang:d,fallbackLang:p}=useLanguages(),[u]=useIsPageLoaded(),m=jotai.useAtomValue(chaiDesignTokensAtom),h=useCheckStructure(),[,x]=jotai.useAtom(userActionsCountAtom),g=()=>{const j=i();return!d||d===p?!1:checkMissingTranslations(j.blocks||[],d)};return{savePage:web.useThrottledCallback(async(j=!1,R=!1)=>{if(!R&&(!c("save_page")||!u))return;const y=i();return y!=null&&y.blocks&&h(y.blocks),n("SAVING"),r("SAVING"),x(0),await a({autoSave:j,blocks:y.blocks,theme:l,needTranslations:g(),designTokens:m}),setTimeout(()=>{n("SAVED"),r("SAVED")},100),!0},[i,n,m,l,x,a,r,u,h],3e3),savePageAsync:async(j=!1)=>{if(!j&&(!c("save_page")||!u))return;n("SAVING"),r("SAVING");const R=i();return x(0),await a({autoSave:!0,blocks:R.blocks,theme:l,needTranslations:g(),designTokens:m}),setTimeout(()=>{n("SAVED"),r("SAVED")},100),!0},saveState:o,setSaveState:n,needTranslations:g}},undoManager=new UndoManager;undoManager.setLimit(50);const undoRedoStateAtom=jotai.atom({canUndo:!1,canRedo:!1}),useUndoManager=()=>{const[,o]=jotai.useAtom(builderSaveStateAtom),[n,a]=jotai.useAtom(undoRedoStateAtom),r=useBuilderProp("onSaveStateChange",lodashEs.noop),i=React.useCallback(()=>{const u={canUndo:undoManager.hasUndo(),canRedo:undoManager.hasRedo()};a(u),o("UNSAVED"),r("UNSAVED")},[a,o,r]);React.useEffect(()=>(undoManager.setCallback(i),()=>{undoManager.setCallback(lodashEs.noop)}),[i]);const l=React.useCallback(u=>{undoManager.add(u),i()},[i]),c=React.useCallback(()=>{undoManager.undo(),i()},[i]),d=React.useCallback(()=>{undoManager.redo(),i()},[i]),p=React.useCallback(()=>{undoManager.clear(),a({canUndo:!1,canRedo:!1})},[a]);return React.useMemo(()=>({add:l,undo:c,redo:d,hasUndo:()=>n.canUndo,hasRedo:()=>n.canRedo,clear:p}),[l,c,d,n.canUndo,n.canRedo,p])},useBlocksStore=()=>jotai.useAtom(presentBlocksAtom),useBlocksStoreUndoableActions=()=>{const{add:o}=useUndoManager(),[n]=useBlocksStore(),{setNewBlocks:a,addBlocks:r,removeBlocks:i,moveBlocks:l,updateBlocksProps:c}=useBlocksStoreManager();return{moveBlocks:(f,b,j)=>{const R=lodashEs.map(f,k=>{const v=n.find(w=>w._id===k)._parent||null,C=n.filter(w=>v?w._parent===v:!w._parent).map(w=>w._id).indexOf(k);return{_id:k,oldParent:v,oldPosition:C}}),y=R.find(({_id:k})=>k===f[0]);y&&y.oldParent===b&&y.oldPosition===j||(l(f,b,j),o({undo:()=>lodashEs.each(R,({_id:k,oldParent:S,oldPosition:v})=>{l([k],S,v)}),redo:()=>l(f,b,j)}))},addBlocks:(f,b,j)=>{r(f,b,j),o({undo:()=>i(lodashEs.map(f,"_id")),redo:()=>r(f,b,j)})},removeBlocks:f=>{var y;const b=(y=lodashEs.first(f))==null?void 0:y._parent,R=n.filter(k=>b?k._parent===b:!k._parent).indexOf(lodashEs.first(f));i(lodashEs.map(f,"_id")),o({undo:()=>r(f,b,R),redo:()=>i(lodashEs.map(f,"_id"))})},updateBlocks:(f,b,j)=>{let R=[];if(j)R=lodashEs.map(f,y=>({_id:y,...j}));else{const y=lodashEs.keys(b);R=lodashEs.map(f,k=>{const S=n.find(B=>B._id===k),v={_id:k};return lodashEs.each(y,B=>v[B]=S[B]),v})}c(lodashEs.map(f,y=>({_id:y,...b}))),o({undo:()=>c(R),redo:()=>c(lodashEs.map(f,y=>({_id:y,...b})))})},updateBlocksRuntime:(f,b)=>{c(lodashEs.map(f,j=>({_id:j,...b})))},setNewBlocks:f=>{a(f),o({undo:()=>a(n),redo:()=>a(f)})},updateMultipleBlocksProps:f=>{let b=[];b=lodashEs.map(f,j=>{const R=lodashEs.keys(j),y=n.find(S=>S._id===j._id),k={};return lodashEs.each(R,S=>k[S]=y[S]),k}),c(f),o({undo:()=>c(b),redo:()=>c(f)})}}},BLOCK_SELECTION_DELAY_MS=100,useAddBlock=()=>{const[o]=useBlocksStore(),[,n]=useSelectedBlockIds(),{addBlocks:a}=useBlocksStoreUndoableActions(),r=React.useCallback((l,c,d)=>{var x;for(let g=0;g<l.length;g++){const{_id:f}=l[g];l[g]._id=commonFunctions.generateUUID();const b=lodashEs.filter(l,{_parent:f});for(let j=0;j<b.length;j++)b[j]._parent=l[g]._id}const p=lodashEs.first(l);let u,m;return c&&(u=lodashEs.find(o,{_id:c}),l[0]._parent=c,lodashEs.forEach(l,g=>{g!=null&&g._parent||(g._parent=c)}),m=c),!(u?canAcceptChildBlock(u==null?void 0:u._type,p._type):!0)&&u&&(l[0]._parent=u._parent,m=u._parent),a(l,m,d),n([(x=lodashEs.first(l))==null?void 0:x._id]),lodashEs.first(l)},[a,o,n]);return{addCoreBlock:React.useCallback((l,c,d)=>{if(lodashEs.has(l,"blocks")){const b=l.blocks;return r(b,c,d)}const p=commonFunctions.generateUUID(),u=runtime.getDefaultBlockProps(l.type),m={_type:l.type,_id:p,...u,...lodashEs.has(l,"_name")&&{_name:l._name},...lodashEs.has(l,"partialBlockId")&&{partialBlockId:l.partialBlockId}};let h,x;return c&&(h=lodashEs.find(o,{_id:c}),m._parent=c,x=c),!canAcceptChildBlock(h==null?void 0:h._type,m._type)&&h&&(m._parent=h._parent,x=h._parent),a([m],x,d),setTimeout(()=>n([m._id]),BLOCK_SELECTION_DELAY_MS),m},[a,r,o,n]),addPredefinedBlock:r}},STANDARD=[0,1,2,3,4,5,6,7,8,9,10,11,12,14,16,20,24,28,32,36,40,44,48,52,56,60,64,72,80,96],CLASS_VALUES={columns:[...lodashEs.range(1,13),"auto","3xs","2xs","xs","sm","md","lg","xl",...lodashEs.map(lodashEs.range(2,8),o=>`${o}xl`)],breakAfter:["auto","avoid","all","avoid-page","page","left","right","column"],breakInside:["auto","avoid","avoid-page","avoid-column"],display:["block","flex","grid","inline-block","inline","hidden"],objectFit:["contain","cover","fill","none","scale-down"],objectPosition:["bottom","center","left","left-bottom","left-top","right","right-bottom","right-top","top"],overflow:["auto","hidden","clip","visible","scroll"],overscroll:["auto","contain","none"],trbl:[0,"px","0.5",1,1.5,2,2.5,3,3.5,...lodashEs.range(4,13),14,16,20,24,28,32,36,40,44,48,52,56,60,64,72,80,96,"auto","1/2","1/3","2/3","1/4","2/4","3/4","full"],flexBasis:[...STANDARD,"auto","px","0.5","1.5","2.5","3.5","1/2","1/3","2/3","1/4","2/4","3/4","1/5","2/5","3/5","4/5","1/6","2/6","3/6","4/6","5/6","1/12","2/12","3/12","4/12","5/12","6/12","7/12","8/12","9/12","10/12","11/12","full"],padding:[...STANDARD,"px","0.5","1.5","2.5","3.5"],margin:["auto",...STANDARD,"px","0.5","1.5","2.5","3.5"],scale:[0,50,75,90,95,100,105,110,125,150],origin:["center","top","top-right","right","bottom-right","bottom","bottom-left","left","top-left"],blendEffect:["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],borderWidth:[0,2,4,8],borderRadius:["global","none","sm","md","lg","xl","2xl","3xl","full"],indent:[0,"px","0.5",1,1.5,2,2.5,3,3.5,...lodashEs.range(4,13),14,16,20,24,28,32,36,40,44,48,52,56,60,64,72,80,96],maxHeight:[0,"px","0.5",1,1.5,2,2.5,3,3.5,...lodashEs.range(4,13),14,16,20,24,28,32,36,40,44,48,52,56,60,64,72,80,96,"full","screen","min","max","fit"],space:[0,"px","0.5",1,1.5,2,2.5,3,3.5,...lodashEs.range(4,13),14,16,20,24,28,32,36,40,44,48,52,56,60,64,72,80,96,"px","reverse"],width:["0","px","0.5","1","1.5","2","2.5","3","3.5","4","5","6","7","8","9","10","11","12","14","16","20","24","28","32","36","40","44","48","52","56","60","64","72","80","96","auto","1/2","1/3","2/3","1/4","2/4","3/4","1/5","2/5","3/5","4/5","1/6","2/6","3/6","4/6","5/6","1/12","2/12","3/12","4/12","5/12","6/12","7/12","8/12","9/12","10/12","11/12"],maxWidth:["0","none","xs","sm","md","lg","xl","2xl","3xl","4xl","5xl","6xl","7xl","full","min","max","fit","prose","screen-sm","screen-md","screen-lg","screen-xl","screen-2xl"],height:["0","px","0.5","1","1.5","2","2.5","3","3.5","4","5","6","7","8","9","10","11","12","14","16","20","24","28","32","36","40","44","48","52","56","60","64","72","80","96","auto","1/2","1/3","2/3","1/4","2/4","3/4","1/5","2/5","3/5","4/5","1/6","2/6","3/6","4/6","5/6","full","screen","min","max","fit"]},CLASSES_LIST={textColor:{classes:[],regExp:"text-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},aspectRatio:{classes:["aspect-auto","aspect-square","aspect-video"],regExp:"aspect-(auto|square|video)"},container:{classes:["container"],regExp:"container"},columns:{classes:lodashEs.map(CLASS_VALUES.columns,o=>`columns-${o}`),regExp:"columns-(auto|[0-9]xl|[0-9]xs|xs|sm|md|lg|xl|\\d+)"},breakAfter:{classes:lodashEs.map(CLASS_VALUES.breakAfter,o=>`break-after-${o}`),regExp:"break-after-\\S+"},breakBefore:{classes:lodashEs.map(CLASS_VALUES.breakAfter,o=>`break-before-${o}`),regExp:"break-before-\\S+"},breakInside:{classes:lodashEs.map(CLASS_VALUES.breakInside,o=>`break-inside-${o}`),regExp:"break-inside-\\S+"},boxDecoration:{classes:["box-decoration-clone","box-decoration-slice"],regExp:"box-decoration-\\S+"},boxSizing:{classes:["box-border","box-content"],regExp:"box-(border|content)"},flexDirection:{classes:["flex-row","flex-row-reverse","flex-col","flex-col-reverse"],regExp:"flex-(row|row-reverse|col|col-reverse)"},flexWrap:{classes:["flex-wrap","flex-wrap-reverse","flex-nowrap"],regExp:"flex-(wrap|wrap-reverse|nowrap)"},flexGrowShrink:{classes:["flex-1","flex-auto","flex-initial","flex-none"],regExp:"flex-1|flex-auto|flex-initial|flex-none"},gridColumns:{classes:lodashEs.map([...lodashEs.range(0,13),"none"],o=>`grid-cols-${o}`),regExp:"grid-cols-(\\d+|none)"},gridFlow:{classes:["grid-flow-row","grid-flow-col","grid-flow-row-dense","grid-flow-col-dense"],regExp:"grid-flow-(row|col|row-dense|col-dense)"},outlineStyle:{classes:lodashEs.map(["none","dashed","dotted","double","hidden"],o=>`outline-${o}`),regExp:"outline-(none|dashed|dotted|double|hidden)"},borderStyle:{classes:lodashEs.map(["solid","dashed","dotted","double","hidden","none"],o=>`border-${o}`),regExp:"border-(solid|dashed|dotted|double|hidden|none)"},overflow:{classes:lodashEs.map(CLASS_VALUES.overflow,o=>`overflow-${o}`),regExp:`overflow-(${CLASS_VALUES.overflow.join("|")})`},overflowX:{classes:lodashEs.map(CLASS_VALUES.overflow,o=>`overflow-x-${o}`),regExp:`overflow-x-(${CLASS_VALUES.overflow.join("|")})`},overflowY:{classes:lodashEs.map(CLASS_VALUES.overflow,o=>`overflow-y-${o}`),regExp:`overflow-y-(${CLASS_VALUES.overflow.join("|")})`},gridRows:{classes:lodashEs.map([1,2,3,4,5,6,"none"],o=>`grid-rows-${o}`),regExp:"grid-rows-(\\d|none)"},display:{classes:lodashEs.map(CLASS_VALUES.display,o=>o.toString()),regExp:`(${CLASS_VALUES.display.join("|")})`},float:{classes:["float-right","float-left","float-none"],regExp:"float-\\S+"},clear:{classes:["clear-right","clear-left","clear-none","clear-both"],regExp:"clear-\\S+"},isolation:{classes:["isolate","isolation-auto"],regExp:"isolate|isolation-auto"},objectFit:{classes:lodashEs.map(CLASS_VALUES.objectFit,o=>`object-${o}`),regExp:"object-(contain|cover|fill|none|scale-down)"},objectPosition:{classes:lodashEs.map(CLASS_VALUES.objectPosition,o=>`object-${o}`),regExp:`object-(${CLASS_VALUES.objectPosition.join("|")})`},overscroll:{classes:lodashEs.map(CLASS_VALUES.overscroll,o=>`overscroll-${o}`),regExp:`overscroll-(${CLASS_VALUES.overscroll.join("|")})`},overscrollX:{classes:lodashEs.map(CLASS_VALUES.overscroll,o=>`overscroll-x-${o}`),regExp:`overscroll-x-(${CLASS_VALUES.overscroll.join("|")})`},overscrollY:{classes:lodashEs.map(CLASS_VALUES.overscroll,o=>`overscroll-y-${o}`),regExp:`overscroll-y-(${CLASS_VALUES.overscroll.join("|")})`},inset:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`inset-${o}`),regExp:"-?inset-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},insetX:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`inset-x-${o}`),regExp:"-?inset-x-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},insetY:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`inset-y-${o}`),regExp:"-?inset-y-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},top:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`top-${o}`),regExp:"-?top-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},topX:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`top-x-${o}`),regExp:"-?top-x-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},topY:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`top-y-${o}`),regExp:"-?top-y-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},right:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`right-${o}`),regExp:"-?right-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},rightX:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`right-x-${o}`),regExp:"-?right-x-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},rightY:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`right-y-${o}`),regExp:"-?right-y-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},bottom:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`bottom-${o}`),regExp:"-?bottom-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},bottomX:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`bottom-x-${o}`),regExp:"-?bottom-x-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},bottomY:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`bottom-y-${o}`),regExp:"-?bottom-y-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},left:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`left-${o}`),regExp:"-?left-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},leftX:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`left-x-${o}`),regExp:"-?left-x-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},leftY:{classes:lodashEs.map(CLASS_VALUES.trbl,o=>`left-y-${o}`),regExp:"-?left-y-(px|\\d\\/\\d|\\d\\.\\d|\\d+|full|auto|\\[.*\\])"},visibility:{classes:["visible","invisible"],regExp:"invisible|visible"},zIndex:{classes:lodashEs.map(["0",10,20,30,40,50,"auto"],o=>`z-${o}`),regExp:"-?z-(\\d+|auto|\\[.*\\])"},flexBasis:{classes:lodashEs.map(CLASS_VALUES.flexBasis,o=>`basis-${o}`),regExp:"basis-(\\d+|\\S+)"},flexGrow:{classes:["grow","grow-0"],regExp:"grow(-0)?"},flexShrink:{classes:["shrink","shrink-0"],regExp:"shrink(-0)?"},gridColSpan:{classes:["col-auto",...lodashEs.map(lodashEs.range(1,13),o=>`col-span-${o}`),"col-span-full"],regExp:"col-(auto|span-(\\d+|full))"},gridColStart:{classes:[...lodashEs.map(lodashEs.range(1,14),o=>`col-start-${o}`),"col-start-auto"],regExp:"col-start-(\\d+|auto)"},gridColEnd:{classes:[...lodashEs.map(lodashEs.range(1,14),o=>`col-end-${o}`),"col-end-auto"],regExp:"col-end-(\\d+|auto)"},gridRowSpan:{classes:["row-auto",...lodashEs.map(lodashEs.range(1,7),o=>`row-span-${o}`),"row-span-full"],regExp:"row-(auto|span-(\\d+|full))"},gridRowStart:{classes:[...lodashEs.map(lodashEs.range(1,8),o=>`row-start-${o}`),"row-start-auto"],regExp:"row-start-(\\d+|auto)"},gridRowEnd:{classes:[...lodashEs.map(lodashEs.range(1,8),o=>`row-end-${o}`),"row-end-auto"],regExp:"row-end-(\\d+|auto)"},gridAutoColumns:{classes:["auto-cols-auto","auto-cols-min","auto-cols-max","auto-cols-fr"],regExp:"auto-cols-(auto|min|max|fr)"},gridAutoRows:{classes:["auto-rows-auto","auto-rows-min","auto-rows-max","auto-rows-fr"],regExp:"auto-rows-(auto|min|max|fr)"},gap:{classes:lodashEs.map(CLASS_VALUES.indent,o=>`gap-${o}`),regExp:"gap-(px|\\d.\\d|\\d|\\[.*\\])"},gapX:{classes:lodashEs.map(CLASS_VALUES.indent,o=>`gap-x-${o}`),regExp:"gap-x-(px|\\d.\\d|\\d|\\[.*\\])"},gapY:{classes:lodashEs.map(CLASS_VALUES.indent,o=>`gap-y-${o}`),regExp:"gap-y-(px|\\d.\\d|\\d|\\[.*\\])"},justifyContent:{classes:["justify-start","justify-end","justify-center","justify-between","justify-around","justify-evenly"],regExp:"justify-(start|end|center|between|around|evenly)"},justifyItems:{classes:["justify-items-start","justify-items-end","justify-items-center","justify-items-stretch"],regExp:"justify-items-(start|end|center|stretch)"},justifySelf:{classes:["justify-self-auto","justify-self-start","justify-self-end","justify-self-center","justify-self-stretch"],regExp:"justify-self-(auto|start|end|center|stretch)"},placeContent:{classes:["place-content-center","place-content-start","place-content-end","place-content-between","place-content-around","place-content-evenly","place-content-stretch"],regExp:"place-content-(center|start|end|between|around|evenly|stretch)"},placeItems:{classes:["place-items-start","place-items-end","place-items-center","place-items-stretch"],regExp:"place-items-(start|end|center|stretch)"},placeSelf:{classes:["place-self-auto","place-self-start","place-self-end","place-self-center","place-self-stretch"],regExp:"place-self-(auto|start|end|center|stretch)"},alignContent:{classes:["content-center","content-start","content-end","content-between","content-around","content-evenly"],regExp:"content-(center|start|end|between|around|evenly)"},alignItems:{classes:["items-start","items-end","items-center","items-baseline","items-stretch"],regExp:"items-(start|end|center|baseline|stretch)"},alignSelf:{classes:["self-auto","self-start","self-end","self-center","self-stretch","self-baseline"],regExp:"self-(auto|start|end|center|stretch|baseline)"},backgroundClip:{classes:["bg-clip-border","bg-clip-padding","bg-clip-content","bg-clip-text"],regExp:"bg-clip-(border|padding|content|text)"},dropShadow:{classes:lodashEs.map(["sm","md","lg","xl","2xl","none"],o=>`drop-shadow-${o}`),regExp:"drop-shadow-(sm|md|lg|xl|2xl|none)"},backdropBlur:{classes:lodashEs.map(["none","sm","md","lg","xl","2xl","3xl"],o=>`backdrop-blur-${o}`),regExp:"backdrop-blur-(none|sm|md|lg|xl|2xl|3xl)"},backdropBrightness:{classes:lodashEs.map([0,50,75,90,95,100,105,110,125,150,200],o=>`backdrop-brightness-${o}`),regExp:"backdrop-brightness-(\\d+)"},backdropContrast:{classes:lodashEs.map([0,50,75,100,125,150,200],o=>`backdrop-contrast-${o}`),regExp:"backdrop-contrast-(\\d+)"},backdropGrayScale:{classes:["backdrop-grayscale-0","backdrop-grayscale"],regExp:"backdrop-grayscale(-0)?"},backdropHueRotate:{classes:lodashEs.map([0,15,30,60,90,180],o=>`backdrop-hue-rotate-${o}`),regExp:"-?backdrop-hue-rotate-(\\d+)"},backdropInvert:{classes:["backdrop-invert-0","backdrop-invert"],regExp:"backdrop-invert(-0)?"},backdropOpacity:{classes:lodashEs.map([0,5,10,20,25,30,40,50,60,70,75,80,90,95,100],o=>`backdrop-opacity-${o}`),regExp:"backdrop-opacity-(\\d+)"},backdropSaturate:{classes:lodashEs.map([0,50,100,150,200],o=>`backdrop-saturate-${o}`),regExp:"backdrop-saturate-(\\d+)"},backdropSepia:{classes:["backdrop-sepia-0, backdrop-sepia"],regExp:"backdrop-sepia(-0)?"},backgroundOrigin:{classes:["bg-origin-border","bg-origin-padding","bg-origin-content"],regExp:"bg-origin-(border|padding|content)"},transformOrigin:{classes:lodashEs.map(CLASS_VALUES.origin,o=>`origin-${o}`),regExp:"origin-(\\d+|\\S+)"},padding:{classes:lodashEs.map(CLASS_VALUES.padding,o=>`p-${o}`),regExp:"p-(\\d+|\\S+|\\[.*\\])"},paddingX:{classes:lodashEs.map(CLASS_VALUES.padding,o=>`px-${o}`),regExp:"px-(\\d+|\\S+|\\[.*\\])"},paddingY:{classes:lodashEs.map(CLASS_VALUES.padding,o=>`py-${o}`),regExp:"py-(\\d+|\\S+|\\[.*\\])"},paddingTop:{classes:lodashEs.map(CLASS_VALUES.padding,o=>`pt-${o}`),regExp:"pt-(\\d+|\\S+|\\[.*\\])"},paddingRight:{classes:lodashEs.map(CLASS_VALUES.padding,o=>`pr-${o}`),regExp:"pr-(\\d+|\\S+|\\[.*\\])"},paddingBottom:{classes:lodashEs.map(CLASS_VALUES.padding,o=>`pb-${o}`),regExp:"pb-(\\d+|\\S+|\\[.*\\])"},paddingLeft:{classes:lodashEs.map(CLASS_VALUES.padding,o=>`pl-${o}`),regExp:"pl-(\\d+|\\S+|\\[.*\\])"},textDecorationStyle:{classes:["decoration-solid","decoration-double","decoration-dotted","decoration-dashed","decoration-wavy"],regExp:"decoration-(solid|double|dotted|dashed|wavy)"},textDecorationThickness:{classes:lodashEs.map(["auto","from-font","0",1,2,4,8],o=>`decoration-${o}`),regExp:"decoration-(auto|from-font|\\d+|\\S+)"},fromColor:{classes:[],regExp:"from-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},margin:{classes:lodashEs.map(CLASS_VALUES.margin,o=>`m-${o}`),regExp:"-?m-(\\d+|\\S+|\\[.*\\])"},marginX:{classes:lodashEs.map(CLASS_VALUES.margin,o=>`mx-${o}`),regExp:"-?mx-(\\d+|\\S+|\\[.*\\])"},marginY:{classes:lodashEs.map(CLASS_VALUES.margin,o=>`my-${o}`),regExp:"-?my-(\\d+|\\S+|\\[.*\\])"},marginTop:{classes:lodashEs.map(CLASS_VALUES.margin,o=>`mt-${o}`),regExp:"-?mt-(\\d+|\\S+|\\[.*\\])"},marginRight:{classes:lodashEs.map(CLASS_VALUES.margin,o=>`mr-${o}`),regExp:"-?mr-(\\d+|\\S+|\\[.*\\])"},marginBottom:{classes:lodashEs.map(CLASS_VALUES.margin,o=>`mb-${o}`),regExp:"-?mb-(\\d+|\\S+|\\[.*\\])"},marginLeft:{classes:lodashEs.map(CLASS_VALUES.margin,o=>`ml-${o}`),regExp:"-?ml-(\\d+|\\S+|\\[.*\\])"},spaceX:{classes:lodashEs.map(CLASS_VALUES.space,o=>`space-x-${o}`),regExp:"-?space-x-(\\d+|\\S+|\\[.*\\])"},spaceY:{classes:lodashEs.map(CLASS_VALUES.space,o=>`space-y-${o}`),regExp:"-?space-y-(\\d+|\\S+|\\[.*\\])"},boxShadow:{classes:lodashEs.map(["sm","md","lg","xl","2xl","inner","none"],o=>`shadow-${o}`),regExp:"shadow-(sm|md|lg|xl|2xl|inner|none)"},minWidth:{classes:["min-w-0","min-w-full","min-w-min","min-w-max","min-w-fit"],regExp:"min-w-(\\d+|\\S+|\\[.*\\])"},maxWidth:{classes:lodashEs.map(CLASS_VALUES.maxWidth,o=>`max-w-${o}`),regExp:"max-w-(\\d+|\\S+|\\[.*\\])"},width:{classes:lodashEs.map([...CLASS_VALUES.width,"full","screen","min","max","fit"],o=>`w-${o}`),regExp:"w-(\\d+.\\d+|\\d+|px|auto|full|screen|min|max|fit|\\[.*\\])$"},minHeight:{classes:["min-h-0","min-h-full","min-h-screen","min-h-min","min-h-max","min-h-fit"],regExp:"min-h-(\\d+|\\S+|\\[.*\\])"},maxHeight:{classes:lodashEs.map(CLASS_VALUES.maxHeight,o=>`max-h-${o}`),regExp:"max-h-(\\d+|\\S+|\\[.*\\])"},height:{classes:lodashEs.map(CLASS_VALUES.height,o=>`h-${o}`),regExp:"h-(\\d+.\\d+|\\d+|px|auto|full|screen|min|max|fit|\\[.*\\])"},fontFamily:{classes:["font-heading","font-body","font-sans","font-serif","font-mono"],regExp:"font-(heading|body|sans|serif|mono)"},textAlign:{classes:["text-left","text-center","text-right","text-justify"],regExp:"text-(left|center|right|justify)"},textOverflow:{classes:["truncate","text-ellipsis","text-clip"],regExp:"truncate|text-ellipsis|text-clip"},verticalAlign:{classes:["align-baseline","align-top","align-middle","align-bottom","align-text-top","align-text-bottom","align-sub","align-super"],regExp:"align-(baseline|top|middle|bottom|text-top|text-bottom|sub|super)"},fontSize:{classes:["text-xs","text-sm","text-base","text-lg","text-xl","text-2xl","text-3xl","text-4xl","text-5xl","text-6xl","text-7xl","text-8xl","text-9xl"],regExp:"text-(\\d+|\\S+|\\[.*\\])"},fontSmoothing:{classes:["antialiased","subpixel-antialiased"],regExp:"antialiased|subpixel-antialiased"},fontStyle:{classes:["italic","not-italic"],regExp:"not-italic|italic"},fontWeight:{classes:["font-thin","font-extralight","font-light","font-normal","font-medium","font-semibold","font-bold","font-extrabold","font-black"],regExp:"font-(thin|extralight|light|normal|medium|semibold|bold|extrabold|black)"},fontVariantNum:{classes:["normal-nums","ordinal","diagonal-fractions","stacked-fractions","tabular-nums","oldstyle-nums","proportional-nums","lining-nums","slashed-zero"],regExp:"normal-nums|ordinal|diagonal-fractions|stacked-fractions|tabular-nums|oldstyle-nums|proportional-nums|lining-nums|slashed-zero"},letterSpacing:{classes:["tracking-tighter","tracking-tight","tracking-normal","tracking-wide","tracking-wider","tracking-widest"],regExp:"-?tracking-(tighter|tight|normal|wide|wider|widest|\\[.*\\])"},lineHeight:{classes:["leading-none","leading-tight","leading-snug","leading-normal","leading-relaxed","leading-loose","leading-3","leading-4","leading-5","leading-6","leading-7","leading-8","leading-9","leading-10"],regExp:"leading-(none|tight|snug|normal|relaxed|loose|\\[.*\\]|\\d+)"},listStyleType:{classes:["list-none","list-disc","list-decimal"],regExp:"list-(none|disc|decimal)"},listStylePosition:{classes:["list-inside","list-outside"],regExp:"list-(inside|outside)"},textUnderlineOffset:{classes:["underline-offset-auto","underline-offset-0","underline-offset-1","underline-offset-2","underline-offset-4","underline-offset-8"],regExp:"underline-offset-(auto|\\d+|\\S+)"},textDecoration:{classes:["underline","overline","line-through","no-underline"],regExp:"underline|overline|line-through|no-underline"},textDecorationColor:{classes:[],regExp:"decoration-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},textTransform:{classes:["uppercase","lowercase","capitalize","normal-case"],regExp:"uppercase|lowercase|capitalize|normal-case"},textIndent:{classes:lodashEs.map(CLASS_VALUES.indent,o=>`indent-${o}`),regExp:"-?indent-(\\d+|\\S+)"},whitespace:{classes:["whitespace-normal","whitespace-nowrap","whitespace-pre","whitespace-pre-line","whitespace-pre-wrap"],regExp:"whitespace-(normal|nowrap|pre|pre-line|pre-wrap)"},wordBreak:{classes:["break-normal","break-words","break-all"],regExp:"break-(normal|words|all)"},content:{classes:["content-none"],regExp:"content-none"},backgroundAttachment:{classes:lodashEs.map(["fixed","local","scroll"],o=>`bg-${o}`),regExp:"bg-(fixed|local|scroll)"},backgroundColor:{classes:[],regExp:"bg-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},backgroundPosition:{classes:["bg-bottom","bg-center","bg-left","bg-left-bottom","bg-left-top","bg-right","bg-right-bottom","bg-right-top","bg-top"],regExp:"bg-(bottom|center|left|left-bottom|left-top|right|right-bottom|right-top|top)"},backgroundRepeat:{classes:["bg-repeat","bg-repeat-x","bg-repeat-y","bg-no-repeat","bg-repeat-round","bg-repeat-space"],regExp:"bg-(repeat|repeat-x|repeat-y|no-repeat|repeat-round|repeat-space)"},backgroundSize:{classes:["bg-auto","bg-cover","bg-contain"],regExp:"bg-(auto|cover|contain)"},backgroundGradient:{classes:["bg-gradient-none","bg-gradient-to-t","bg-gradient-to-tr","bg-gradient-to-r","bg-gradient-to-br","bg-gradient-to-b","bg-gradient-to-bl","bg-gradient-to-l","bg-gradient-to-tl"],regExp:"bg-gradient-(none|to-(t|tr|r|br|b|bl|l|tl))"},viaColor:{classes:[],regExp:"via-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},toColor:{classes:[],regExp:"to-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},position:{classes:["static","fixed","absolute","relative","sticky"],regExp:"(static|fixed|absolute|relative|sticky)"},borderRadiusTopLeft:{classes:["rounded-tl",...lodashEs.map(CLASS_VALUES.borderRadius,o=>`rounded-tl-${o}`)],regExp:"rounded-tl-?(\\d+|\\S+)?"},borderRadiusTopRight:{classes:["rounded-tr",...lodashEs.map(CLASS_VALUES.borderRadius,o=>`rounded-tr-${o}`)],regExp:"rounded-tr-?(\\d+|\\S+)?"},borderRadiusBottomRight:{classes:["rounded-br",...lodashEs.map(CLASS_VALUES.borderRadius,o=>`rounded-br-${o}`)],regExp:"rounded-br-?(\\d+|\\S+)?"},borderRadiusBottomLeft:{classes:["rounded-bl",...lodashEs.map(CLASS_VALUES.borderRadius,o=>`rounded-bl-${o}`)],regExp:"rounded-bl-?(\\d+|\\S+)?"},borderRadiusTop:{classes:["rounded-t",...lodashEs.map(CLASS_VALUES.borderRadius,o=>`rounded-t-${o}`)],regExp:"rounded-t-?(\\d+|\\S+)?"},borderRadiusRight:{classes:["rounded-r",...lodashEs.map(CLASS_VALUES.borderRadius,o=>`rounded-r-${o}`)],regExp:"rounded-r-?(\\d+|\\S+)?"},borderRadiusBottom:{classes:["rounded-b",...lodashEs.map(CLASS_VALUES.borderRadius,o=>`rounded-b-${o}`)],regExp:"rounded-b-?(\\d+|\\S+)?"},borderRadiusLeft:{classes:["rounded-l",...lodashEs.map(CLASS_VALUES.borderRadius,o=>`rounded-l-${o}`)],regExp:`(rounded-l-(${CLASS_VALUES.borderRadius.join("|")})|rounded-l$)`},borderRadius:{classes:["rounded",...lodashEs.map(CLASS_VALUES.borderRadius,o=>`rounded-${o}`)],regExp:`(rounded-(${CLASS_VALUES.borderRadius.join("|")}$)|rounded)`},borderX:{classes:["border-x",...lodashEs.map(CLASS_VALUES.borderWidth,o=>`border-x-${o}`)],regExp:"border-x-?(\\d+|\\S+|\\[.*\\])?"},borderY:{classes:["border-y",...lodashEs.map(CLASS_VALUES.borderWidth,o=>`border-y-${o}`)],regExp:"border-y-?(\\d+|\\S+|\\[.*\\])?"},borderTop:{classes:["border-t",...lodashEs.map(CLASS_VALUES.borderWidth,o=>`border-t-${o}`)],regExp:"border-t-?(\\d+|\\S+|\\[.*\\])?"},borderRight:{classes:["border-r",...lodashEs.map(CLASS_VALUES.borderWidth,o=>`border-r-${o}`)],regExp:"border-r-?(\\d+|\\S+|\\[.*\\])?"},borderBottom:{classes:["border-b",...lodashEs.map(CLASS_VALUES.borderWidth,o=>`border-b-${o}`)],regExp:"border-b-?(\\d+|\\S+|\\[.*\\])?"},borderLeft:{classes:["border-l",...lodashEs.map(CLASS_VALUES.borderWidth,o=>`border-l-${o}`)],regExp:"border-l-?(\\d+|\\S+|\\[.*\\])?"},borderColor:{classes:[],regExp:"^border-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\w+-\\d+|\\[#[0-9a-fA-F]+\\])$"},border:{classes:["border",...lodashEs.map(CLASS_VALUES.borderWidth,o=>`border-${o}`)],regExp:"^border(-\\d+|\\[\\d+px\\])?$"},order:{classes:lodashEs.map([...lodashEs.range(0,13),"first","last","none"],o=>`order-${o}`),regExp:"-?order-(\\d+|first|last|none)"},divideXWidth:{classes:lodashEs.map(["0",2,4,8],o=>`divide-x-${o}`),regExp:"divide-x-(\\d+|\\[.*\\])"},divideYWidth:{classes:lodashEs.map(["0",2,4,8],o=>`divide-y-${o}`),regExp:"divide-y-(\\d+|\\[.*\\])"},divideColor:{classes:[],regExp:"divide-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},divideStyle:{classes:lodashEs.map(["solid","dashed","dotted","double","none"],o=>`divide-${o}`),regExp:"divide-(solid|dashed|dotted|double|none)"},outlineWidth:{classes:lodashEs.map([0,1,2,4,8],o=>`outline-${o}`),regExp:"outline-(\\d+)"},outlineOffset:{classes:lodashEs.map([0,1,2,4,8],o=>`outline-offset-${o}`),regExp:"outline-offset-(\\d+)"},outlineColor:{classes:[],regExp:"outline-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},ringWidth:{classes:lodashEs.map([0,1,2,4,8,"inset"],o=>`ring-${o}`),regExp:"ring-(\\d+|inset)"},ringOffsetWidth:{classes:lodashEs.map([0,1,2,4,8],o=>`ring-offset-${o}`),regExp:"ring-offset-(\\d+)"},ringOffsetColor:{classes:[],regExp:"ring-offset-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},ringColor:{classes:[],regExp:"ring-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},boxShadowColor:{classes:[],regExp:"shadow-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},opacity:{classes:lodashEs.map([0,5,10,20,25,30,40,50,60,70,75,80,90,95,100],o=>`opacity-${o}`),regExp:"opacity-(\\d+|\\[.*\\])"},mixBlendMode:{classes:lodashEs.map(CLASS_VALUES.blendEffect,o=>`mix-blend-${o}`),regExp:"mix-blend-(\\d+|\\S+)"},bgBlendMode:{classes:lodashEs.map(CLASS_VALUES.blendEffect,o=>`bg-blend-${o}`),regExp:"bg-blend-(\\d+|\\S+)"},blur:{classes:lodashEs.map(["none","sm","md","lg","xl","2xl","3xl"],o=>`blur-${o}`),regExp:"blur-(none|sm|md|lg|xl|2xl|3xl)"},brightness:{classes:lodashEs.map([0,50,75,90,95,100,105,110,125,150,200],o=>`brightness-${o}`),regExp:"brightness-(\\d+)"},contrast:{classes:lodashEs.map([0,50,75,100,125,150,200],o=>`contrast-${o}`),regExp:"contrast-(\\d+)"},grayScale:{classes:["grayscale-0","grayscale"],regExp:"grayscale(-0)?"},hueRotate:{classes:lodashEs.map([0,15,30,60,90,180],o=>`hue-rotate-${o}`),regExp:"-?hue-rotate-(\\d+)"},invert:{classes:["invert-0","invert"],regExp:"invert(-0)?"},saturate:{classes:lodashEs.map([0,50,100,150,200],o=>`saturate-${o}`),regExp:"saturate-(\\d+)"},sepia:{classes:["sepia-0","sepia"],regExp:"sepia(-0)?"},transition:{classes:["transition-none","transition-all","transition-colors","transition-opacity","transition-shadow","transition-transform"],regExp:"transition-(none|all|colors|opacity|shadow|transform)"},duration:{classes:lodashEs.map([75,100,150,200,300,500,700,1e3],o=>`duration-${o}`),regExp:"duration-(\\d+|\\[.*\\])"},transitionEase:{classes:["ease-linear","ease-in","ease-out","ease-in-out"],regExp:"eas(e-linear|e-in|e-out|e-in-out)"},transitionDelay:{classes:lodashEs.map([75,100,150,200,300,500,700,1e3],o=>`delay-${o}`),regExp:"delay-(\\d+|\\[.*\\])"},animation:{classes:["animate-none","animate-spin","animate-ping"],regExp:"animate-(none|spin|ping)"},scaleX:{classes:lodashEs.map(CLASS_VALUES.scale,o=>`scale-x-${o}`),regExp:"-?scale-x-(\\d+|\\S+|\\[.*\\])"},scaleY:{classes:lodashEs.map(CLASS_VALUES.scale,o=>`scale-y-${o}`),regExp:"-?scale-y-(\\d+|\\S+|\\[.*\\])"},scale:{classes:lodashEs.map(CLASS_VALUES.scale,o=>`scale-${o}`),regExp:"-?scale-(\\d+|\\S+|\\[.*\\])"},rotate:{classes:lodashEs.map([0,1,2,3,6,12,45,90,180],o=>`rotate-${o}`),regExp:"-?rotate-(\\d+|\\S+|\\[.*\\])"},translateX:{classes:lodashEs.map([0,"px","0.5",1],o=>`translate-x-${o}`),regExp:"-?translate-x-(\\d+|\\S+|\\[.*\\])"},translateY:{classes:lodashEs.map([0,"px","0.5",1],o=>`translate-y-${o}`),regExp:"-?translate-y-(\\d+|\\S+|\\[.*\\])"},skewX:{classes:lodashEs.map([0,1,2,3,6,12],o=>`skew-x-${o}`),regExp:"-?skew-x-(\\d+|\\S+|\\[.*\\])"},skewY:{classes:lodashEs.map([0,1,2,3,6,12],o=>`skew-y-${o}`),regExp:"-?skew-y-(\\d+|\\S+|\\[.*\\])"},accentColor:{classes:[],regExp:"accent-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},appearance:{classes:["appearance-none"],regExp:"appearance-none"},cursor:{classes:["cursor-auto","cursor-default","cursor-pointer","cursor-wait","cursor-text","cursor-move","cursor-help","cursor-not-allowed"],regExp:"cursor-(auto|default|pointer|wait|text|move|help|not-allowed)"},caretColor:{classes:[],regExp:"caret-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},pointerEvents:{classes:["pointer-events-none","pointer-events-auto"],regExp:"pointer-events-(none|auto)"},userSelect:{classes:["select-none","select-text","select-all","select-auto"],regExp:"select-(none|text|all|auto)"},fill:{classes:[],regExp:"caret-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},stroke:{classes:[],regExp:"caret-(black|transparent|current|white|__THEME_COLORS_REGEXP__|\\S+-\\d+)"},strokeWidth:{classes:["stroke-0","stroke-1","stroke-2"],regExp:"stroke-(\\d+|\\[.*\\])"}},colorOptions={backgroundColor:"bg",textColor:"text",borderColor:"border",boxShadowColor:"shadow",outlineColor:"outline",divideColor:"divide",fromColor:"from",viaColor:"via",toColor:"to",ringColor:"ring",ringOffsetColor:"ring-offset"},soloColors=["current","inherit","transparent","black","white"],shadedColors=["slate","gray","zinc","neutral","stone","red","orange","amber","yellow","lime","green","emerald","teal","cyan","sky","blue","indigo","violet","purple","fuchsia","pink","rose"],shades=["50","100","200","300","400","500","600","700","800","900"],colorKeys=lodashEs.map(lodashEs.values(colorOptions),o=>o),ALL_COLORS=lodashEs.flattenDeep([...lodashEs.map(soloColors,o=>lodashEs.flatten(lodashEs.map(colorKeys,n=>`${n}-${o}`))),...lodashEs.map(shadedColors,o=>lodashEs.flattenDeep(lodashEs.map(colorKeys,n=>lodashEs.flattenDeep(lodashEs.map(shades,a=>`${n}-${o}-${a}`)))))]),ALL_TW_CLASSES=lodashEs.map(lodashEs.flattenDeep(lodashEs.values(CLASSES_LIST).map(o=>o.classes).concat(ALL_COLORS)),o=>({name:o})),useFuseSearch=()=>{const o=useThemeOptions(),n=React.useMemo(()=>{let a=[];if(o.colors){const r=lodashEs.flattenDeep(lodashEs.map(o.colors,({items:i})=>lodashEs.keys(i)));a=lodashEs.flattenDeep(lodashEs.map(r,i=>lodashEs.flatten(lodashEs.map(colorKeys,l=>`${l}-${i}`))))}return o.fontFamily&&(a=[...a,...lodashEs.map(lodashEs.keys(o.fontFamily),r=>`${r}`)]),lodashEs.map(a,r=>({name:r}))},[o]);return React.useMemo(()=>new Fuse([...ALL_TW_CLASSES,...n],{isCaseSensitive:!1,threshold:.2,minMatchCharLength:2,keys:["name"]}),[n])},useTailwindClassList=()=>{const o=useThemeOptions(),n=React.useMemo(()=>{if(o.colors){const i=lodashEs.flattenDeep(lodashEs.map(o.colors,({items:l})=>lodashEs.keys(l)));lodashEs.each(CLASSES_LIST,(l,c)=>{lodashEs.set(CLASSES_LIST,`${c}.regExp`,l.regExp.replace("__THEME_COLORS_REGEXP__",i.join("|")))})}return CLASSES_LIST},[o]),a=React.useCallback((i,l)=>{const c=lodashEs.get(n,`${i}.regExp`,"");return l.match(new RegExp(c))},[n]),r=React.useCallback((i,l=[])=>lodashEs.get(n,`${i}.classes`,l),[n]);return{match:a,getClasses:r}};function getMqForCls(o){if(lodashEs.isEmpty(o.trim()))return"";const n=o.match(/sm:|md:|lg:|xl:|2xl:/g);return lodashEs.get(n,0,"xs").replace(":","")}function getModForCls(o){const n=lodashEs.map(MODIFIERS,r=>`${r}:`).join("|"),a=new RegExp(n,"g");return lodashEs.get(a.exec(o.trim()),0,"").replace(":","")}function getPureClsName(o){return o.trim().split(":").pop()||""}const memoizedProps={};function getPropertyForClass(o){if(lodashEs.isEmpty(o))return"";if(memoizedProps[o])return memoizedProps[o];let n="";for(const a in CLASSES_LIST){const r=lodashEs.get(CLASSES_LIST,`${a}.regExp`,"");if(new RegExp(r,"g").test(o)){n=a,memoizedProps[o]=n;break}}return n}function constructClassObject(o){return lodashEs.isEmpty(o)?null:{dark:lodashEs.startsWith(o,"dark:"),mq:getMqForCls(o),mod:getModForCls(o),cls:getPureClsName(o),fullCls:o,property:getPropertyForClass(o)}}function generateFullClsName(o){let n="";return o.dark&&(n+="dark:"),o.mq.toLowerCase()!=="xs"&&(n+=`${o.mq}:`),o.mod&&(n+=`${o.mod}:`),n+=o.cls,n}function orderClassesByBreakpoint(o){o=o.replace(/\s+/g," ");const n=o.split(" ").map(constructClassObject),a=["xs","sm","md","lg","xl","2xl"];return n.sort((r,i)=>a.indexOf(r.mq)-a.indexOf(i.mq)).map(r=>r.fullCls).join(" ")}function removeDuplicateClasses(o){if(o=o.replace(/\s+/g," "),!o)return"";const n=["xs","sm","md","lg","xl","2xl"],a=o.split(" ").map(constructClassObject);let r=o;if(a.length===1)return a[0].fullCls;for(const i of a){const l=i.property,c=n.indexOf(i.mq);for(let d=c+1;d<n.length;d++){const p=n[d],u=a.find(m=>m.property===l&&m.mq===p);if(u&&u.cls===i.cls)r=r.replace(u.fullCls,"");else if(u&&u.cls!==i.cls)break}}return r.replace(/\s+/g," ").trim()}const selectedStylingBlocksAtom=jotai.atom([]);selectedStylingBlocksAtom.debugLabel="selectedStylingBlocksAtom";const useSelectedStylingBlocks=()=>jotai.useAtom(selectedStylingBlocksAtom),addClassesToBlocksAtom=jotai.atom(null,(o,n,{blockIds:a,newClasses:r})=>{const i=lodashEs.filter(o(pageBlocksAtomsAtom),c=>a.includes(o(c)._id)),l=lodashEs.first(o(selectedStylingBlocksAtom));return lodashEs.map(i,c=>{const d=o(c),p=lodashEs.get(d,l.prop,`${applyBinding.STYLES_KEY},`),{classes:u}=applyBinding.getSplitChaiClasses(p);return{ids:[d._id],props:{[l.prop]:`${applyBinding.STYLES_KEY},${orderClassesByBreakpoint(removeDuplicateClasses(tailwindMerge.twMerge(u,r)))}`}}})}),useAddClassesToBlocks=()=>{const o=jotai.useSetAtom(addClassesToBlocksAtom),{updateBlocks:n,updateBlocksRuntime:a}=useBlocksStoreUndoableActions();return React.useCallback((r,i,l=!1)=>{const c=o({blockIds:r,newClasses:i});if(!l){a(r,c[0].props);return}n(r,c[0].props)},[o,n,a])},LANGUAGES={ab:"Abkhazian",aa:"Afar",af:"Afrikaans",ak:"Akan",sq:"Albanian",am:"Amharic",ar:"Arabic",an:"Aragonese",hy:"Armenian",as:"Assamese",av:"Avaric",ae:"Avestan",ay:"Aymara",az:"Azerbaijani",bm:"Bambara",ba:"Bashkir",eu:"Basque",be:"Belarusian",bn:"Bengali",bh:"Bihari",bi:"Bislama",bs:"Bosnian",br:"Breton",bg:"Bulgarian",my:"Burmese",ca:"Catalan",ch:"Chamorro",ce:"Chechen",ny:"Chichewa",zh:"Chinese","zh-Hans":"Chinese (Simplified)","zh-Hant":"Chinese (Traditional)",cv:"Chuvash",kw:"Cornish",co:"Corsican",cr:"Cree",hr:"Croatian",cs:"Czech",da:"Danish",dv:"Maldivian",nl:"Dutch",dz:"Dzongkha",en:"English",eo:"Esperanto",et:"Estonian",ee:"Ewe",fo:"Faroese",fj:"Fijian",fi:"Finnish",fr:"French",ff:"Fula, Pular",gl:"Galician",gd:"Gaelic (Scottish)",gv:"Manx",ka:"Georgian",de:"German",el:"Greek",kl:"Kalaallisut",gn:"Guarani",gu:"Gujarati",ht:"Haitian Creole",ha:"Hausa",he:"Hebrew",hz:"Herero",hi:"Hindi",ho:"Hiri Motu",hu:"Hungarian",is:"Icelandic",io:"Ido",ig:"Igbo",id:"Indonesian",ia:"Interlingua",ie:"Interlingue",iu:"Inuktitut",ik:"Inupiak",ga:"Irish",it:"Italian",ja:"Japanese",jv:"Javanese",kn:"Kannada",kr:"Kanuri",ks:"Kashmiri",kk:"Kazakh",km:"Khmer",ki:"Kikuyu",rw:"Kinyarwanda",rn:"Kirundi",ky:"Kyrgyz",kv:"Komi",kg:"Kongo",ko:"Korean",ku:"Kurdish",kj:"Kwanyama",lo:"Lao",la:"Latin",lv:"Latvian",li:"Limburgish",ln:"Lingala",lt:"Lithuanian",lu:"Luga-Katanga",lg:"Luganda, Ganda",lb:"Luxembourgish",mk:"Macedonian",mg:"Malagasy",ms:"Malay",ml:"Malayalam",mt:"Maltese",mi:"Maori",mr:"Marathi",mh:"Marshallese",mo:"Moldavian",mn:"Mongolian",na:"Nauru",nv:"Navajo",ng:"Ndonga",nd:"Northern Ndebele",ne:"Nepali",no:"Norwegian",nb:"Norwegian bokmål",nn:"Norwegian nynorsk",ii:"Sichuan Yi",oc:"Occitan",oj:"Ojibwe",cu:"Old Church Slavonic",or:"Oriya",om:"Oromo",os:"Ossetian",pi:"Pāli",ps:"Pashto, Pushto",fa:"Persian (Farsi)",pl:"Polish",pt:"Portuguese",pa:"Punjabi (Eastern)",qu:"Quechua",rm:"Romansh",ro:"Romanian",ru:"Russian",se:"Sami",sm:"Samoan",sg:"Sango",sa:"Sanskrit",sr:"Serbian",sh:"Serbo-Croatian",st:"Sesotho",tn:"Setswana",sn:"Shona",sd:"Sindhi",si:"Sinhalese",ss:"Swati",sk:"Slovak",sl:"Slovenian",so:"Somali",nr:"Southern Ndebele",es:"Spanish",su:"Sundanese",sw:"Swahili (Kiswahili)",sv:"Swedish",tl:"Tagalog",ty:"Tahitian",tg:"Tajik",ta:"Tamil",tt:"Tatar",te:"Telugu",th:"Thai",bo:"Tibetan",ti:"Tigrinya",to:"Tonga",ts:"Tsonga",tr:"Turkish",tk:"Turkmen",tw:"Twi",ug:"Uyghur",uk:"Ukrainian",ur:"Urdu",uz:"Uzbek",ve:"Venda",vi:"Vietnamese",vo:"Volapük",wa:"Wallon",cy:"Welsh",wo:"Wolof",fy:"Western Frisian",xh:"Xhosa",yi:"Yiddish",yo:"Yoruba",za:"Zhuang, Chuang",zu:"Zulu"},updatePropsForLanguage=(o,n,a)=>{const r=runtime.getRegisteredChaiBlock(lodashEs.get(a,"_type"));if(!r)return o;const i={...o};return lodashEs.forEach(lodashEs.keys(o),l=>{if(lodashEs.includes(lodashEs.get(r,"i18nProps",[]),l)&&!lodashEs.isEmpty(n)){const c=`${l}-${n}`;lodashEs.set(i,c,o[l]),lodashEs.unset(i,l)}}),i},useUpdateBlocksProps=()=>{const{updateBlocks:o}=useBlocksStoreUndoableActions(),{selectedLang:n}=useLanguages(),a=useSelectedBlock();return React.useCallback((r,i,l)=>{const c=updatePropsForLanguage(i,n,a);o(r,c,l)},[n,a,o])},useUpdateMultipleBlocksProps=()=>{const{updateMultipleBlocksProps:o}=useBlocksStoreUndoableActions();return React.useCallback(n=>{o(n)},[o])},useFakeStreamEffect=()=>{const{updateBlocksRuntime:o}=useBlocksStoreUndoableActions();return React.useCallback(async(n,a,r=30)=>{const i=lodashEs.keys(lodashEs.omit(a,["_id"]));for(const l of i){const c=a[l];if(lodashEs.isString(c)){const d=lodashEs.chunk(c.split(""),12);let p="";o([n],{[l]:""});for(let u=0;u<d.length;u++)p+=d[u].join(""),o([n],{[l]:p}),await new Promise(m=>setTimeout(m,r))}}},[o])},useStreamMultipleBlocksProps=()=>{const{updateMultipleBlocksProps:o}=useBlocksStoreUndoableActions(),n=useFakeStreamEffect();return React.useCallback(async a=>{for(const r of a)await n(r._id,r);o(a)},[n,o])},useUpdateBlocksPropsRealtime=()=>{const{updateBlocksRuntime:o}=useBlocksStoreUndoableActions(),{selectedLang:n}=useLanguages(),a=useSelectedBlock();return React.useCallback((r,i)=>{const l=updatePropsForLanguage(i,n,a);o(r,l)},[n,a,o])};function getChildBlocks$1(o,n,a){a.push(lodashEs.find(o,{_id:n}));const r=lodashEs.filter(o,{_parent:n});for(const i of r)a.push(...getBlockWithChildren(i._id,o));return a}const getBlockWithChildren=(o,n)=>{let a=[];return a=lodashEs.flattenDeep([...a,...getChildBlocks$1(n,o,a)]),a},pickOnlyAIProps=(o,n,a)=>lodashEs.compact(o.map(r=>{const i=["_id","_type","_parent"],l=lodashEs.pick(r,i),c=runtime.getRegisteredChaiBlock(r._type),d={},p=lodashEs.get(c,"aiProps",[]);for(const u in r)if(!i.includes(u)&&p.includes(u)){const m=lodashEs.get(r,`${u}-${n}`,""),h=lodashEs.get(r,u,"");d[u]=lodashEs.isString(m)&&m.trim()||h,a&&(d[u]=h)}return lodashEs.isEmpty(d)?!1:(lodashEs.has(l,"_parent")&&lodashEs.isEmpty(l._parent)&&delete l._parent,{...l,...d})})),addLangToPrompt=(o,n,a)=>!n||a!=="content"?o:`${o}. Generate content in ${lodashEs.get(LANGUAGES,n,n)} language.`,askAiProcessingAtom=jotai.atom(!1),useAskAi=()=>{const[o,n]=jotai.useAtom(askAiProcessingAtom),[a,r]=React.useState(null),i=useBuilderProp("askAiCallBack",null),l=useStreamMultipleBlocksProps(),c=useUpdateMultipleBlocksProps(),[d]=useBlocksStore(),{selectedLang:p,fallbackLang:u}=useLanguages(),m=p.length?p:u,h=(x,g)=>{const f=lodashEs.cloneDeep(g.find(b=>b._id===x));for(const b in f){const j=f[b];if(typeof j=="string"&&lodashEs.startsWith(j,applyBinding.STYLES_KEY)){const{baseClasses:R,classes:y}=applyBinding.getSplitChaiClasses(j);f[b]=lodashEs.compact(lodashEs.flattenDeep([R,y])).join(" ")}else b!=="_id"&&delete f[b]}return f};return{askAi:React.useCallback(async(x,g,f,b)=>{if(i){n(!0),r(null);try{const j=p===u?"":p,R=f.toLowerCase().includes("translate the content"),y=x==="content"?pickOnlyAIProps(lodashEs.cloneDeep(getBlockWithChildren(g,d)),p,R):[h(g,d)],k=await i(x,addLangToPrompt(f,m,x),y,j),{blocks:S,error:v}=k;if(v){r(v);return}if(x==="styles"){const B=S.map(C=>{for(const w in C)w!=="_id"&&(C[w]=`${applyBinding.STYLES_KEY},${C[w]}`);return C});c(B)}else l(S);b&&b(k)}catch(j){r(j)}finally{n(!1),b&&b()}}},[i,n,p,u,d,m,c,l]),loading:o,error:a}},readOnlyModeAtom=jotai.atom(!1);readOnlyModeAtom.debugLabel="readOnlyModeAtom";const networkModeAtom=jotai.atom("online");networkModeAtom.debugLabel="networkModeAtom";jotai.atom("");const editLayerNameAtom=jotai.atom(!1);editLayerNameAtom.debugLabel="editLayerNameAtom";const activeLanguageAtom=jotai.atom("");activeLanguageAtom.debugLabel="activeLanguageAtom";const primaryLanguageAtom=jotai.atom("");primaryLanguageAtom.debugLabel="primaryLanguageAtom";const canvasIframeAtom=jotai.atom(null);canvasIframeAtom.debugLabel="canvasIframeAtom";const activePanelAtom=jotai.atom("outline");activePanelAtom.debugLabel="activePanelAtom";const showPredefinedBlockCategoryAtom=jotai.atom("");showPredefinedBlockCategoryAtom.debugLabel="showPredefinedBlockCategoryAtom";const draggingFlagAtom=jotai.atom(!1);draggingFlagAtom.debugLabel="draggingFlagAtom";const treeRefAtom=jotai.atom(null);treeRefAtom.debugLabel="treeRefAtom";const canvasSettingsAtom=jotai.atom({});canvasSettingsAtom.debugLabel="canvasSettingsAtom";const aiAssistantActiveAtom=jotai.atom(!1);aiAssistantActiveAtom.debugLabel="aiAssistantActiveAtom";const codeEditorOpenAtom=jotai.atom(!1);codeEditorOpenAtom.debugLabel="codeEditorOpenAtom";const codeEditorHeightAtom=utils.atomWithStorage("codeEditorHeight",500);codeEditorHeightAtom.debugLabel="codeEditorHeightAtom";const xShowBlocksAtom=jotai.atom([]);xShowBlocksAtom.debugLabel="xShowBlocksAtom";const selectedLibraryAtom=utils.atomWithStorage("_selectedLibrary",null);selectedLibraryAtom.debugLabel="selectedLibraryAtom";const dataBindingActiveAtom=jotai.atom(!0);dataBindingActiveAtom.debugLabel="dataBindingActiveAtom";let lastHighlighted=null;const useBlockHighlight=()=>{const[o]=jotai.useAtom(canvasIframeAtom),n=React.useMemo(()=>{var i;return(o==null?void 0:o.contentDocument)||((i=o==null?void 0:o.contentWindow)==null?void 0:i.document)},[o]),a=React.useCallback(i=>{if(n)if(lastHighlighted&&lastHighlighted.removeAttribute("data-highlighted"),typeof i!="string")i.setAttribute("data-highlighted","true"),lastHighlighted=i;else if(typeof i=="string"){const l=n.querySelector(`[data-block-id="${i}"]`);l&&(l.setAttribute("data-highlighted","true"),lastHighlighted=l)}else lastHighlighted=null},[n]),r=React.useCallback(()=>{lastHighlighted&&(lastHighlighted.removeAttribute("data-highlighted"),lastHighlighted=null)},[]);return{highlightBlock:a,clearHighlight:r,lastHighlighted}},partialBlocksStoreAtom=jotai.atom({}),partialBlocksLoadingStateAtom=jotai.atom({}),usePartialBlocksStore=()=>{const[o,n]=jotai.useAtom(partialBlocksStoreAtom),a=React.useCallback(i=>lodashEs.get(o,i,[]),[o]),r=React.useCallback(()=>n({}),[n]);return{getPartailBlocks:a,reset:r}},useWatchPartailBlocks=()=>{const[o]=useBlocksStore(),[n,a]=jotai.useAtom(partialBlocksStoreAtom),[r,i]=jotai.useAtom(partialBlocksLoadingStateAtom),l=useBuilderProp("getPartialBlockBlocks",async d=>[]),c=React.useMemo(()=>o.filter(d=>d._type==="PartialBlock"||d._type==="GlobalBlock").map(d=>lodashEs.get(d,"partialBlockId",lodashEs.get(d,"globalBlock",""))),[o]);React.useEffect(()=>{lodashEs.forEach(c,d=>{lodashEs.has(n,d)||lodashEs.get(r,`${d}.loading`,!1)||(i(p=>({...p,[d]:{loading:!0,error:null}})),l(d).then(p=>{a(u=>({...u,[d]:p})),i(u=>({...u,[d]:{loading:!1,error:null}}))}).catch(p=>{i(u=>({...u,[d]:{loading:!1,error:p.message}}))}))})},[l,n,r,a,i,c])},partialBlocksListAtom=jotai.atom({}),usePartialBlocksList=()=>{const[o,n]=React.useState(!1),[a,r]=React.useState(null),[i,l]=jotai.useAtom(partialBlocksListAtom),c=useBuilderProp("getPartialBlocks",async()=>[]),d=React.useCallback(async()=>{n(!0),r(null);try{const p=await c();l(p),n(!1)}catch(p){r(p instanceof Error?p.message:"Failed to fetch partial blocks"),n(!1)}},[c,l]);return React.useEffect(()=>{d()},[]),{data:i,isLoading:o,refetch:d,error:a}},useBuilderReset=()=>{const{clear:o}=useUndoManager(),[,n]=useSelectedBlockIds(),{clearHighlight:a}=useBlockHighlight(),[,r]=useSelectedStylingBlocks(),[,i]=jotai.useAtom(aiAssistantActiveAtom),{reset:l}=usePartialBlocksStore(),{setSaveState:c}=useSavePage(),[,d]=useBlockRepeaterDataAtom(),[,p]=jotai.useAtom(userActionsCountAtom);return()=>{d({}),n([]),r([]),a(),o(),i(!1),l(),c("SAVED"),p(0)}},canvasZoomAtom=utils.atomWithStorage("canvasZoom",100),useCanvasZoom=()=>jotai.useAtom(canvasZoomAtom),codeEditorAtom=jotai.atom(null),useCodeEditor=()=>jotai.useAtom(codeEditorAtom),cutBlockIdsAtom=jotai.atom([]),useCutBlockIds=()=>{const[o,n]=jotai.useAtom(cutBlockIdsAtom),a=jotai.useSetAtom(copiedBlockIdsAtom),r=React.useCallback(i=>{n(i),a([])},[n,a]);return[o,r]},copiedBlockIdsAtom=jotai.atom([]),useCopyBlocks=()=>{const[o]=useBlocksStore(),[n,a]=jotai.useAtom(copiedBlockIdsAtom),r=jotai.useSetAtom(cutBlockIdsAtom),{getPartailBlocks:i}=usePartialBlocksStore(),l=useBuilderProp("flags.copyPaste",!0),c=React.useCallback(p=>p.some(u=>getDuplicatedBlocks(o,u,null).some(h=>h._type==="PartialBlock"||h._type==="GlobalBlock")),[o]),d=React.useCallback(async(p,u=!1)=>{try{if(lodashEs.isEmpty(p))return;a(p),r([]);const m={_chai_copied_blocks:p.flatMap(h=>{const x=getDuplicatedBlocks(o,h,null);if(!u)return x;let g=[];for(const f of x)if(f._type==="PartialBlock"||f._type==="GlobalBlock"){let b=i(f.partialBlockId);f._parent&&(b==null?void 0:b.length)>0&&(b=b.map(j=>(lodashEs.isEmpty(j._parent)&&lodashEs.set(j,"_parent",f._parent),j))),g=[...g,...b]}else g.push(f);return g})};if(!l)return;if(!navigator.clipboard){sonner.toast.error("Clipboard not available.");return}sonner.toast.promise(navigator.clipboard.writeText(JSON.stringify(m)),{success:"Blocks copied successfully",error:"Failed to copy blocks to clipboard"})}catch(m){sonner.toast.error("Failed to copy blocks to clipboard"),console.error("Failed to copy blocks to clipboard:",m)}},[a,r,o]);return[n,d,c]},useCopyToClipboard=()=>{const[o,n]=React.useState(null),a=useBuilderProp("flags.copyPaste",!0),r=React.useCallback(async i=>{if(!a)return console.warn("Clipboard feature is disabled"),!1;if(!(navigator!=null&&navigator.clipboard))return console.warn("Clipboard not supported"),!1;try{return await navigator.clipboard.writeText(i),n(i),!0}catch(l){return console.warn("Copy failed",l),n(null),!1}},[]);return[o,r]},darkModeAtom=utils.atomWithStorage("darkMode",!1),useDarkMode=()=>{const[o,n]=jotai.useAtom(darkModeAtom);return[o,n]},useDuplicateBlocks=()=>{const[o]=useBlocksStore(),[,n]=useSelectedBlockIds(),{addBlocks:a}=useBlocksStoreUndoableActions();return React.useCallback((r,i=null)=>{const l=[];lodashEs.each(r,c=>{const d=o.find(x=>x._id===c);i?i==="root"&&(i=null):i=d._parent;const m=lodashEs.filter(o,x=>lodashEs.isString(i)?x._parent===i:!x._parent).indexOf(d)+1,h=getDuplicatedBlocks(o,c,i);a(h,i,m),l.push(lodashEs.get(h,"0._id",""))}),n(l)},[o,n])},highlightBlockIdAtom=jotai.atom(""),useHighlightBlockId=()=>jotai.useAtom(highlightBlockIdAtom),libraryBlocksAtom=jotai.atom({}),useLibraryBlocks=o=>{const[n,a]=jotai.useAtom(libraryBlocksAtom),r=React.useMemo(()=>(o==null?void 0:o.getBlocksList)||(()=>[]),[o]),i=lodashEs.get(n,`${o==null?void 0:o.id}.blocks`,null),l=lodashEs.get(n,`${o==null?void 0:o.id}.loading`,"idle"),c=React.useRef("idle");React.useEffect(()=>{(async()=>{if(!(l==="complete"||c.current==="loading")){c.current="loading",a(p=>({...p,[o==null?void 0:o.id]:{loading:"loading",blocks:[]}}));try{const p=await r(o);c.current="idle",a(u=>({...u,[o==null?void 0:o.id]:{loading:"complete",blocks:p||[]}}))}catch{c.current="idle",a(u=>({...u,[o==null?void 0:o.id]:{loading:"complete",blocks:[]}}))}}})()},[o,i,l,c,a,r]);const d=React.useCallback(p=>{a(u=>({...u,[p]:{loading:"idle",blocks:[]}}))},[a]);return{data:i||[],isLoading:l==="loading",resetLibrary:d}},useCanPaste=()=>{const[o]=useBlocksStore();return(n,a)=>{var l;const r=((l=lodashEs.find(o,{_id:a}))==null?void 0:l._type)||null,i=lodashEs.first(n.map(c=>{var d;return(d=lodashEs.find(o,{_id:c}))==null?void 0:d._type}));return canAcceptChildBlock(r,i)}},useMoveCutBlocks=()=>{const o=jotai.useAtomValue(presentBlocksAtom),{moveBlocks:n}=useBlocksStoreUndoableActions();return React.useCallback((a,r)=>{const i=Array.isArray(r)?r[0]:r;if(r==="root"){const l=o==null?void 0:o.filter(c=>!c._parent);n(a,null,(l==null?void 0:l.length)||0)}else{const l=o==null?void 0:o.filter(c=>c._parent===i);n(a,i,(l==null?void 0:l.length)||0)}},[n,o])},usePasteBlocks=()=>{const[o,n]=useCutBlockIds(),a=useMoveCutBlocks(),{addPredefinedBlock:r}=useAddBlock(),i=useCanPaste();return{canPaste:React.useCallback(async c=>{if(o.length>0)return i(o,c);try{const d=await navigator.clipboard.readText();if(d){const p=JSON.parse(d);return lodashEs.has(p,"_chai_copied_blocks")}}catch{return!1}return!1},[i,o]),pasteBlocks:React.useCallback(async c=>{const d=Array.isArray(c)?c[0]:c;if(!(navigator!=null&&navigator.permissions)){sonner.toast.error("Cannot check clipboard permissions.");return}try{if((await navigator.permissions.query({name:"clipboard-read"})).state==="denied"){sonner.toast.error("Clipboard paste permission denied. Please allow clipboard access.");return}}catch{sonner.toast.error("Failed to check clipboard permissions. Please allow clipboard access.");return}if(!lodashEs.isEmpty(o)){a(o,c),n([]),await navigator.clipboard.writeText("");return}sonner.toast.promise(async()=>{const p=await navigator.clipboard.readText();if(p){const u=JSON.parse(p);if(lodashEs.has(u,"_chai_copied_blocks"))r(u._chai_copied_blocks,d==="root"?null:d);else throw new Error("Nothing to paste")}else throw new Error("Nothing to paste")},{success:()=>"Blocks pasted successfully",error:()=>"Nothing to paste"})},[o,a,n])}},previewModeAtom=jotai.atom(!1),usePreviewMode=()=>{const[o,n]=jotai.useAtom(previewModeAtom);return[o,n]},removeClassFromBlocksAtom=jotai.atom(null,(o,n,{blockIds:a,fullClasses:r})=>{const i=lodashEs.first(o(selectedStylingBlocksAtom)),l=lodashEs.filter(o(pageBlocksAtomsAtom),c=>a.includes(o(c)._id));return lodashEs.map(l,c=>{const d=o(c),p=r;let{classes:u,baseClasses:m}=applyBinding.getSplitChaiClasses(lodashEs.get(d,i.prop,`${applyBinding.STYLES_KEY},`));return lodashEs.each(p,h=>{const x=h.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),g=new RegExp(`(^|\\s)${x}(?=\\s|$)`,"g");u=u.replace(g," ").replace(/\s+/g," ").trim();const f=lodashEs.first(h.split(":"));lodashEs.includes(["2xl","xl","lg","md","sm"],f)&&p.push(h.split(":").pop().trim())}),lodashEs.each(p,h=>{const x=h.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),g=new RegExp(`(^|\\s)${x}(?=\\s|$)`,"g");m=m.replace(g," ").replace(/\s+/g," ").trim()}),{ids:[d._id],props:{[i.prop]:`${applyBinding.STYLES_KEY}${m},${u}`}}})}),removeAllClassesForBlock=o=>{const n=Object.keys(o).filter(r=>typeof o[r]=="string"&&o[r].startsWith(applyBinding.STYLES_KEY)),a={};return n.forEach(r=>{a[r]=`${applyBinding.STYLES_KEY},`}),{ids:[o._id],props:a}},useRemoveAllClassesForBlock=()=>{const{updateBlocks:o,updateBlocksRuntime:n}=useBlocksStoreUndoableActions();return React.useCallback((a,r=!1)=>{const{ids:i,props:l}=removeAllClassesForBlock(a);r?o(i,l):n(i,l)},[o,n])},useRemoveClassesFromBlocks=()=>{const{updateBlocks:o,updateBlocksRuntime:n}=useBlocksStoreUndoableActions(),a=jotai.useSetAtom(removeClassFromBlocksAtom);return React.useCallback((r,i,l=!1)=>{const c=a({blockIds:r,fullClasses:i});l?o(r,c[0].props):n(r,c[0].props)},[a])},useResetBlockStyles=()=>{const o=useSelectedBlock(),n=useUpdateBlocksProps(),a=React.useCallback(c=>runtime.getDefaultBlockProps(c)||{},[]),r=React.useCallback(c=>Object.keys(c).filter(d=>typeof c[d]=="string"&&c[d].startsWith("#styles:")),[]),i=React.useCallback(c=>{if(!o)return;const p=a(o._type)[c]??"#styles:,";n([o._id],{[c]:p})},[o,a,n]);return{resetAll:React.useCallback(()=>{if(!o)return;const c=r(o);if(c.length===0)return;const d=a(o._type),p=lodashEs.pick(d,c);n([o._id],p)},[o,r,a,n]),reset:i}},useStylingBreakpoint=()=>jotai.useAtom(styleBreakpointAtom),canvasWidthAtom=utils.atomWithStorage("canvasWidth",800),canvasDisplayWidthAtom=utils.atomWithStorage("canvasDisplayWidth",800),canvasBreakpointAtom=jotai.atom(o=>{const n=o(canvasWidthAtom);return commonFunctions.getBreakpointValue(n).toLowerCase()}),useScreenSizeWidth=()=>{const[o,n]=jotai.useAtom(canvasWidthAtom),a=jotai.useAtomValue(canvasBreakpointAtom),[r,i]=useStylingBreakpoint();return React.useEffect(()=>{r!=="xs"&&i(a)},[a,r,i]),[o,a,n]},useCanvasDisplayWidth=()=>{const[o,n]=jotai.useAtom(canvasDisplayWidthAtom);return[o,n]},selectedBlockAllClassesAtom=jotai.atom(o=>{const n=lodashEs.first(o(selectedStylingBlocksAtom)),a=o(selectedBlockAtom);if(!n||n.blockId!==lodashEs.get(a,"_id",null))return[];const r=lodashEs.get(a,n.prop,`${applyBinding.STYLES_KEY},`),{classes:i}=applyBinding.getSplitChaiClasses(r);return lodashEs.filter(lodashEs.map(i.trim().split(" "),constructClassObject),l=>!lodashEs.isNull(l))}),useSelectedBlockAllClasses=()=>jotai.useAtomValue(selectedBlockAllClassesAtom),MQ={xs:0,sm:1,md:2,lg:3,xl:4,"2xl":5},selectedBlockCurrentClassesAtom=jotai.atom(o=>{const n=o(canvasBreakpointAtom),a=o(styleStateAtom),r=o(darkModeAtom),i=getQueries(n);let l=lodashEs.filter(o(selectedBlockAllClassesAtom),{mod:a});return lodashEs.startsWith(a,"_")||(l=lodashEs.filter(l,c=>i.includes(c.mq))),l=l.sort((c,d)=>MQ[c.mq]-MQ[d.mq]),r||(l=lodashEs.filter(l,{dark:!1})),l}),getQueries=o=>{let n=[];switch(o){case"xs":n=["xs"];break;case"sm":n=["xs","sm"];break;case"md":n=["xs","sm","md"];break;case"lg":n=["xs","sm","md","lg"];break;case"xl":n=["xs","sm","md","lg","xl"];break;case"2xl":n=["xs","sm","md","lg","xl","2xl"];break;default:n=["xs"];break}return n},useSelectedBlockCurrentClasses=()=>jotai.useAtomValue(selectedBlockCurrentClassesAtom),selectedBreakpointsAtom=utils.atomWithStorage("selectedBreakpoints",["XS","MD","XL"]),useSelectedBreakpoints=()=>{const[o,n]=jotai.useAtom(selectedBreakpointsAtom);return[o,n]},useStylingState=()=>jotai.useAtom(styleStateAtom),wrapperBlockAtom=jotai.atom(o=>{var c;const n=o(presentBlocksAtom),a=o(selectedBlockIdsAtom),r=a.length===1?a[0]:null;if(!r)return null;const i=lodashEs.find(n,{_id:r});if(!i)return null;let l=i._parent;for(;l;){const d=lodashEs.find(n,{_id:l});if(!d)return null;if((c=runtime.getRegisteredChaiBlock(d._type))!=null&&c.wrapper)return d;l=d._parent}return null});wrapperBlockAtom.debugLabel="wrapperBlockAtom";const useWrapperBlock=()=>jotai.useAtomValue(wrapperBlockAtom),useCanvasIframe=()=>jotai.useAtom(canvasIframeAtom),ATTRIBUTES_TO_REMOVE=["data-block-index","draggable","data-drop","data-style-id","data-block-parent","data-style-prop","data-highlighted"],CORE_BLOCKS$1=["Box","Button","Checkbox","Divider","EmptyBox","Form","FormButton","Heading","Image","Input","Label","LineBreak","Link","List","ListItem","Paragraph","Radio","RichText","Select","Span","Text","TextArea","Video"],cleanNode=o=>o.type==="element"&&["script","style","link"].includes(o.tagName||"")||o.type==="comment"?null:o.type==="text"?o:o.type==="element"&&o.attributes&&o.attributes.find(n=>n.key==="id"&&n.value==="add-block-bottom")?null:(o.type==="element"&&o.attributes&&(o.attributes=o.attributes.filter(n=>!ATTRIBUTES_TO_REMOVE.includes(n.key))),o.children&&(o.children=o.children.map(cleanNode).filter(n=>n!==null)),o),transformNode=(o,n,a={})=>{var l;if(o.type!=="element"||!o.attributes)return o;o.tagName==="span"&&o.attributes.find(d=>d.key==="role"&&d.value==="link")&&(o.tagName="a",o.attributes=o.attributes.filter(d=>d.key!=="role"));const r=o.attributes.find(c=>c.key==="data-block-type"),i=o.attributes.find(c=>c.key==="data-block-id");if(r){const c=r.value;if(CORE_BLOCKS$1.includes(c)||(l=a==null?void 0:a.additionalCoreBlocks)!=null&&l.includes(c))o.attributes=o.attributes.filter(d=>d.key!=="data-block-type"),o.children&&(o.children=o.children.map(d=>transformNode(d,n,a)));else{const d=`chai-${lodashEs.kebabCase(c)}`;o.tagName=d,o.attributes=[],o.attributes.push({key:"chai-type",value:c});const p=runtime.getRegisteredChaiBlock(c),u=n.find(m=>m._id===(i==null?void 0:i.value));if(u&&o.attributes.push(...Object.entries(u).filter(([m])=>!["_id","_type","_parent","_index","_name"].includes(m)).map(([m,h])=>({key:m,value:typeof h=="string"?h:JSON.stringify(h)}))),p&&(p!=null&&p.description)&&o.attributes.push({key:"about-this-component",value:p.description}),p){if(p.canMove){const m=typeof p.canMove=="function"?p.canMove():p.canMove;o.attributes.push({key:"can-move",value:String(m)})}if(p.canDelete){const m=typeof p.canDelete=="function"?p.canDelete():p.canDelete;o.attributes.push({key:"can-delete",value:String(m)})}}c==="Icon"&&(o.attributes=o.attributes.filter(m=>m.key!=="icon")),p&&p.canAcceptBlock?o.children&&(o.children=o.children.map(m=>transformNode(m,n,a))):o.children=[]}}else o.children&&(o.children=o.children.map(c=>transformNode(c,n,a)));return i&&o.attributes.push({key:"bid",value:i.value}),o.attributes=o.attributes.filter(c=>c.key!=="data-block-type"&&c.key!=="data-block-id"),o},useBlocksHtmlForAi=()=>{const[o]=useBlocksStore(),[n]=useCanvasIframe();return React.useCallback(a=>{var u,m;if(!n)return"";const r=a!=null&&a.blockId?`[data-block-id="${a.blockId}"]`:"#canvas",i=(m=(u=n.contentDocument)==null?void 0:u.querySelector(r))==null?void 0:m[r==="#canvas"?"innerHTML":"outerHTML"];if(!i)return"";const d=himalaya.parse(i).map(cleanNode).filter(h=>h!==null).map(h=>transformNode(h,o,a));let p=himalaya.stringify(d);return p=p.replace(/#styles:,/g,"#styles:"),p.replace(/\s+/g," ").trim()},[n])},handlei18N=(o,n)=>o.map(a=>{const r=runtime.getRegisteredChaiBlock(a._type);if(!r)return a;const i=r.i18nProps;if(!i)return a;const l=lodashEs.filter(n,{_type:a._type}),c=lodashEs.pick(a,i);return lodashEs.each(c,(d,p)=>{const u=lodashEs.find(l,m=>{var g;const h=typeof m[p]=="string"?(g=m[p])==null?void 0:g.trim().toLowerCase():JSON.stringify(m[p]),x=typeof d=="string"?d.trim().toLowerCase():JSON.stringify(d);return h===x});if(u){const m=lodashEs.filter(Object.keys(u),x=>lodashEs.startsWith(x,`${p}-`)),h=lodashEs.pick(u,m);a={...a,...h}}}),a}),useHtmlToBlocks=()=>{const[o]=useBlocksStore();return React.useCallback(n=>{const a=runtime.syncBlocksWithDefaults(applyBinding.getBlocksFromHTML(n)),r=applyBinding.mergeBlocksWithExisting(a,o);return handlei18N(r,o)},[o])},getAllDescendantBlocks=(o,n)=>{const a=o.filter(i=>i._parent===n),r=a.flatMap(i=>getAllDescendantBlocks(o,i._id));return[...a,...r]},getBlockWithNestedChildren=(o,n)=>{const a=n.find(i=>i._id===o);if(!a)return[];const r=getAllDescendantBlocks(n,o);return[a,...r]},useI18nBlocks=()=>{const o=useSelectedBlock(),[n]=useBlocksStore();return React.useCallback((a="")=>{const r=o!=null&&o._id?getBlockWithNestedChildren(o._id,n):n;return r?lodashEs.compact(r.map(i=>{const l=runtime.getRegisteredChaiBlock(i._type);if(!l)return null;const c=(l==null?void 0:l.i18nProps)??[];if(c.length===0)return null;const d=a==="ALL"?Object.keys(i).filter(u=>c.find(m=>u.startsWith(m))):c.map(u=>a?`${u}-${a}`:u),p=lodashEs.pick(i,["_id"]);return lodashEs.each(d,u=>{p[u]=lodashEs.get(i,u,lodashEs.get(i,u.replace(`-${a}`,"")))}),p})):[]},[o==null?void 0:o._id,n])},inlineEditingActiveAtom=jotai.atom("");inlineEditingActiveAtom.debugLabel="inlineEditingActiveAtom";const inlineEditingItemIndexAtom=jotai.atom(0);inlineEditingItemIndexAtom.debugLabel="inlineEditingItemIndexAtom";const useInlineEditing=()=>{const[o,n]=jotai.useAtom(inlineEditingActiveAtom),[a,r]=jotai.useAtom(inlineEditingItemIndexAtom);return{editingBlockId:o,editingItemIndex:a,setEditingBlockId:n,setEditingItemIndex:r}};function usePubSub(o,n){React.useEffect(()=>{const a=pubsub.subscribe(o,n);return()=>a()},[o,n])}const getAllDescendantIds=(o,n)=>{const a=o.filter(l=>l._parent===n),r=a.map(l=>l._id),i=a.flatMap(l=>getAllDescendantIds(o,l._id));return[...r,...i]},replaceBlock=(o,n,a)=>{const r=lodashEs.find(o,{_id:n});if(!r)return o;const i=o.findIndex(h=>h._id===n),l=getAllDescendantIds(o,n),c=new Set([n,...l]),d=o.filter(h=>!c.has(h._id)),p=new Set(a.map(h=>h._id)),u=a.map(h=>!h._parent||!p.has(h._parent)?{...h,_parent:r._parent}:h);return[...d.slice(0,i),...u,...d.slice(i)]},useReplaceBlock=()=>{const[o]=useBlocksStore(),[,n]=useSelectedBlockIds(),{setNewBlocks:a}=useBlocksStoreUndoableActions(),{hasPermission:r}=usePermissions();return React.useCallback((i,l)=>{if(!r(PERMISSIONS.EDIT_BLOCK))return;const c=i?replaceBlock(o,i,l):l;a(c),l.length>0&&setTimeout(()=>n([l[0]._id]),200)},[o,n,a,r])},BREAKPOINTS$1=[{name:"xs",minWidth:0},{name:"sm",minWidth:640},{name:"md",minWidth:768},{name:"lg",minWidth:1024},{name:"xl",minWidth:1280},{name:"2xl",minWidth:1536}],getBreakpointForWidth=o=>{for(let n=BREAKPOINTS$1.length-1;n>=0;n-=1){const a=BREAKPOINTS$1[n];if(o>=a.minWidth)return a.name}return BREAKPOINTS$1[0].name},useCanvasWidth=()=>{const o=typeof window<"u"?window.innerWidth:BREAKPOINTS$1[0].minWidth,[n,a]=React.useState(o);React.useEffect(()=>{if(typeof window>"u")return;const i=()=>{a(window.innerWidth)};return window.addEventListener("resize",i),i(),()=>window.removeEventListener("resize",i)},[]);const r=React.useMemo(()=>getBreakpointForWidth(n),[n]);return[n,r]},useSelectedLibrary=()=>jotai.useAtom(selectedLibraryAtom),sidebarActivePanelAtom=jotai.atom("outline");sidebarActivePanelAtom.debugLabel="sidebarActivePanelAtom";const useSidebarActivePanel=()=>jotai.useAtom(sidebarActivePanelAtom),dragAndDropAtom=jotai.atom(null),dropIndicatorAtom=jotai.atom({isVisible:!1,isValid:!1,position:"inside",placeholderOrientation:"horizontal",isEmpty:!1,top:0,left:0,width:0,height:0});let isDragging=!1;const setIsDragging=o=>{isDragging=o},canvasRenderKeyAtom=jotai.atom(0);let lastDragHighlighted=null,floatingLabel=null;function createFloatingLabel(o,n){const a=o.getAttribute("data-block-name"),r=o.getAttribute("data-block-type"),i=a||r||"Container",l=n.createElement("div");return l.className="chai-drag-parent-label",l.textContent=i,l.className="absolute top-0 -left-0.5 -translate-x-0.5 -translate-y-full -mt-1 bg-green-500/95 text-white px-2 py-1 text-xs font-semibold font-sans leading-tight whitespace-nowrap shadow-lg z-[999999] pointer-events-none select-none",l}function removeFloatingLabel(){floatingLabel&&floatingLabel.parentNode&&(floatingLabel.parentNode.removeChild(floatingLabel),floatingLabel=null)}const useDragParentHighlight=()=>{const[o]=useCanvasIframe(),n=React.useMemo(()=>{var i;return(o==null?void 0:o.contentDocument)||((i=o==null?void 0:o.contentWindow)==null?void 0:i.document)},[o]),a=React.useCallback(i=>{if(!n)return;let l=null;if(!i){lastDragHighlighted&&(lastDragHighlighted.style.outline="",lastDragHighlighted.style.outlineOffset="",lastDragHighlighted.style.backgroundColor="",lastDragHighlighted.style.position="",lastDragHighlighted=null),removeFloatingLabel();return}typeof i!="string"?l=i:l=n.querySelector(`[data-block-id="${i}"]`),!(l===lastDragHighlighted&&floatingLabel&&floatingLabel.parentNode)&&(lastDragHighlighted&&lastDragHighlighted!==l&&(lastDragHighlighted.style.outline="",lastDragHighlighted.style.outlineOffset="",lastDragHighlighted.style.backgroundColor="",lastDragHighlighted.style.position=""),removeFloatingLabel(),l?(l.style.outline="2px dashed rgba(34, 197, 94, 1)",l.style.outlineOffset="2px",l.style.backgroundColor="rgba(34, 197, 94, 0.05)",window.getComputedStyle(l).position==="static"&&(l.style.position="relative"),floatingLabel=createFloatingLabel(l,n),l.appendChild(floatingLabel),lastDragHighlighted=l):lastDragHighlighted=null)},[n]),r=React.useCallback(()=>{lastDragHighlighted&&(lastDragHighlighted.style.outline="",lastDragHighlighted.style.outlineOffset="",lastDragHighlighted.style.backgroundColor="",window.getComputedStyle(lastDragHighlighted).position==="relative"&&lastDragHighlighted.style.position==="relative"&&(lastDragHighlighted.style.position=""),lastDragHighlighted=null),removeFloatingLabel()},[]);return{highlightParent:a,clearParentHighlight:r,lastDragHighlighted}},useBlockDragEnd=()=>{const[,o]=jotai.useAtom(dragAndDropAtom),[,n]=jotai.useAtom(dropIndicatorAtom),[a]=useCanvasIframe(),{clearParentHighlight:r}=useDragParentHighlight(),[i,l]=jotai.useAtom(canvasRenderKeyAtom),c=a==null?void 0:a.contentDocument;return React.useCallback(()=>{o(null),n({isVisible:!1,isValid:!1,position:"inside",placeholderOrientation:"horizontal",isEmpty:!1,top:0,left:0,width:0,height:0}),removeDropTargetAttributes$2(c),r(),c&&c.querySelectorAll("[data-dragging]").forEach(p=>{p.removeAttribute("data-dragging")}),setIsDragging(!1),l(i+1)},[o,n,c,r,i,l])};function removeDropTargetAttributes$2(o){if(!o)return;o.querySelectorAll("[data-drop-target]").forEach(a=>a.removeAttribute("data-drop-target"))}function getOrientation(o,n=null){const a=window.getComputedStyle(o),r=n?window.getComputedStyle(n):null,i=a.display,l=r?r.display:null;if(i==="flex"||i==="inline-flex"){const c=a.flexDirection;return c==="column"||c==="column-reverse"?"vertical":"horizontal"}else if(i==="grid"){const c=a.gridAutoFlow,d=a.gridTemplateColumns;return c.includes("column")||d&&d!=="none"&&d!==""&&!d.includes("calc")&&d.split(" ").length<=1?"vertical":"horizontal"}else if(l==="inline-block"||l==="inline")return"horizontal";return"vertical"}const LEAF_BLOCK_TYPES$1=["Heading","Text","Image","Paragraph","Icon","Input","Radio","Checkbox","Select","CustomHTML","TextArea","Divider","Repeater","Video"];function isLeafBlock(o){try{return LEAF_BLOCK_TYPES$1.includes(o)}catch{return!1}}const ZONE_CONFIG={MIN_EDGE_ZONE:10,MAX_EDGE_ZONE:30,EDGE_ZONE_PERCENTAGE:.2,GAP_THRESHOLD:8,MIN_SIZE_FOR_EDGE_ZONES:50,PARENT_EDGE_PROXIMITY:20};function calculateEdgeZoneSize(o){try{if(o<ZONE_CONFIG.MIN_SIZE_FOR_EDGE_ZONES)return 0;const n=o*ZONE_CONFIG.EDGE_ZONE_PERCENTAGE;return Math.max(ZONE_CONFIG.MIN_EDGE_ZONE,Math.min(ZONE_CONFIG.MAX_EDGE_ZONE,n))}catch{return ZONE_CONFIG.MIN_EDGE_ZONE}}function getChildBlocks(o){try{const n=[],a=o.children;for(let r=0;r<a.length;r++){const i=a[r];i.hasAttribute("data-block-id")&&n.push(i)}return n}catch{return[]}}function hasChildBlocks(o){try{return getChildBlocks(o).length>0}catch{return!1}}function detectGapZone(o,n,a,r){try{const i=getChildBlocks(o);if(i.length<2)return null;const l=findClosestSiblingInRow(i,n,a,r);if(l){const c=getSiblingsInSameRow(i,l,r);c.sort((d,p)=>{const u=d.getBoundingClientRect(),m=p.getBoundingClientRect();return r==="vertical"?u.top-m.top:u.left-m.left});for(let d=0;d<c.length-1;d++){const p=c[d],u=c[d+1],m=p.getBoundingClientRect(),h=u.getBoundingClientRect();if(r==="vertical"){const x=m.bottom,g=h.top,f=g-x,b=a>=x&&a<=g,j=n>=Math.min(m.left,h.left)&&n<=Math.max(m.right,h.right);if(b&&j&&f>=ZONE_CONFIG.GAP_THRESHOLD)return{before:p,after:u}}else{const x=m.right,g=h.left,f=g-x,b=n>=x&&n<=g,j=a>=Math.min(m.top,h.top)&&a<=Math.max(m.bottom,h.bottom);if(b&&j&&f>=ZONE_CONFIG.GAP_THRESHOLD)return{before:p,after:u}}}}for(let c=0;c<i.length-1;c++){const d=i[c],p=i[c+1],u=d.getBoundingClientRect(),m=p.getBoundingClientRect();if(r==="vertical"){const h=u.bottom,x=m.top,g=x-h,f=a>=h&&a<=x,b=n>=Math.min(u.left,m.left)&&n<=Math.max(u.right,m.right);if(f&&b&&g>=ZONE_CONFIG.GAP_THRESHOLD)return{before:d,after:p}}else{const h=u.right,x=m.left,g=x-h,f=n>=h&&n<=x,b=a>=Math.min(u.top,m.top)&&a<=Math.max(u.bottom,m.bottom);if(f&&b&&g>=ZONE_CONFIG.GAP_THRESHOLD)return{before:d,after:p}}}return null}catch{return null}}function detectParentEdgeProximity(o,n,a,r){try{const i=o.getBoundingClientRect(),l=ZONE_CONFIG.PARENT_EDGE_PROXIMITY;if(r==="vertical"){if(a<=i.top+l)return"start";if(a>=i.bottom-l)return"end"}else{if(n<=i.left+l)return"start";if(n>=i.right-l)return"end"}return null}catch{return null}}function calculateElementZone(o,n,a,r,i){const l=o.getBoundingClientRect();if(i==="vertical"){const d=(a-l.top)/l.height,p=calculateEdgeZoneSize(l.height),u=p/l.height;return r?p>0&&d<u?{position:"before",confidence:1-d/u}:p>0&&d>1-u?{position:"after",confidence:(d-(1-u))/u}:{position:"inside",confidence:1-Math.abs(d-.5)*2}:d<.5?{position:"before",confidence:1-d*2}:{position:"after",confidence:(d-.5)*2}}else{const d=(n-l.left)/l.width,p=calculateEdgeZoneSize(l.width),u=p/l.width;return r?p>0&&d<u?{position:"before",confidence:1-d/u}:p>0&&d>1-u?{position:"after",confidence:(d-(1-u))/u}:{position:"inside",confidence:1-Math.abs(d-.5)*2}:d<.5?{position:"before",confidence:1-d*2}:{position:"after",confidence:(d-.5)*2}}}function detectDropZone(o,n,a,r,i){var k,S,v,B;const l=o.getAttribute("data-block-id"),c=o.getAttribute("data-block-type")||"Box";if(!l)return null;let d=o.parentElement;for(;d&&!d.hasAttribute("data-block-id");)d=d.parentElement;const p=l==="canvas"?l:d==null?void 0:d.getAttribute("data-block-id"),u=d?getOrientation(d):"vertical",m=getOrientation(o),h=isLeafBlock(c),x=!h&&canAcceptChildBlock(c,r),g=((k=i.defaultView)==null?void 0:k.scrollY)||0,f=((S=i.defaultView)==null?void 0:S.scrollX)||0;if(l==="canvas"&&hasChildBlocks(o)){const C=getChildBlocks(o),w=C[C.length-1];if(w){const E=w.getBoundingClientRect(),A=o.getBoundingClientRect(),_=window.getComputedStyle(o),I=parseFloat(_.paddingLeft)||0,P=parseFloat(_.paddingRight)||0,L=A.width-I-P,D=A.left+f+I;return{position:"after",placeholderOrientation:"horizontal",rect:{top:E.bottom+g,left:D,width:L,height:4},targetElement:w,targetBlockId:w.getAttribute("data-block-id"),targetParentId:"canvas",isEmpty:!1,confidence:1}}}if(x&&!h&&hasChildBlocks(o)){const C=detectGapZone(o,n,a,m);if(C){const w=C.before.getBoundingClientRect(),E=C.after.getBoundingClientRect(),A=o.getBoundingClientRect(),_=window.getComputedStyle(o),I=parseFloat(_.paddingLeft)||0,P=parseFloat(_.paddingRight)||0,L=getChildBlocks(o),D=getSiblingsInSameRow(L,C.before,m);let H=0;if(D.forEach(V=>{const O=V.getBoundingClientRect();O.height>H&&(H=O.height)}),m==="vertical"){const V=A.width-I-P,O=A.left+f+I;return{position:"after",placeholderOrientation:"horizontal",rect:{top:w.bottom+g,left:O,width:V,height:4},targetElement:C.before,targetBlockId:C.before.getAttribute("data-block-id"),targetParentId:l,isGapZone:!0,confidence:1}}else{const V=w.top+g,O=H>0?H:Math.max(w.height,E.height);return{position:"after",placeholderOrientation:"vertical",rect:{top:V,left:w.right+f,width:4,height:O},targetElement:C.before,targetBlockId:C.before.getAttribute("data-block-id"),targetParentId:l,isGapZone:!0,confidence:1}}}}if(d&&p){const C=detectParentEdgeProximity(d,n,a,u);if(C){const w=d.getBoundingClientRect(),E=window.getComputedStyle(d),A=parseFloat(E.paddingLeft)||0,_=parseFloat(E.paddingRight)||0,I=parseFloat(E.paddingTop)||0,P=parseFloat(E.paddingBottom)||0,L=((v=i.defaultView)==null?void 0:v.scrollY)||0,D=((B=i.defaultView)==null?void 0:B.scrollX)||0,H=u==="vertical"?"horizontal":"vertical",V=getMaxSiblingDimensions(d);if(C==="start"){const O=getChildBlocks(d)[0];if(O){const T=O.getBoundingClientRect();if(u==="vertical"){const N=w.width-A-_,M=w.left+D+A;return{position:"before",placeholderOrientation:H,rect:{top:T.top+L-2,left:M,width:N,height:4},targetElement:O,targetBlockId:O.getAttribute("data-block-id"),targetParentId:p,confidence:.9}}else{const N=w.top+L+I,M=V.maxHeight>0?V.maxHeight:w.height-I-P;return{position:"before",placeholderOrientation:H,rect:{top:N,left:T.left+D-2,width:4,height:M},targetElement:O,targetBlockId:O.getAttribute("data-block-id"),targetParentId:p,confidence:.9}}}}else{const O=getChildBlocks(d),T=O[O.length-1];if(T){const N=T.getBoundingClientRect();if(u==="vertical"){const M=w.width-A-_,F=w.left+D+A;return{position:"after",placeholderOrientation:H,rect:{top:N.bottom+L-2,left:F,width:M,height:4},targetElement:T,targetBlockId:T.getAttribute("data-block-id"),targetParentId:p,confidence:.9}}else{const M=w.top+L+I,F=V.maxHeight>0?V.maxHeight:w.height-I-P;return{position:"after",placeholderOrientation:H,rect:{top:M,left:N.right+D-2,width:4,height:F},targetElement:T,targetBlockId:T.getAttribute("data-block-id"),targetParentId:p,confidence:.9}}}}}}let b=calculateElementZone(o,n,a,x,u);if(h&&b.position==="inside"){const C=o.getBoundingClientRect();u==="vertical"?b={position:(a-C.top)/C.height<.5?"before":"after",confidence:b.confidence}:b={position:(n-C.left)/C.width<.5?"before":"after",confidence:b.confidence}}let j;b.position==="inside"?j=m==="vertical"?"horizontal":"vertical":j=u==="vertical"?"horizontal":"vertical";const R=calculatePlaceholderRect(o,d,b.position,j,i),y=b.position==="inside"?l:p;return{position:b.position,placeholderOrientation:j,rect:R,targetElement:o,targetBlockId:l,targetParentId:y,isEmpty:b.position==="inside"&&!hasChildBlocks(o),confidence:b.confidence}}function findClosestSiblingInRow(o,n,a,r){if(o.length===0)return null;const i=o.filter(d=>{const p=d.getBoundingClientRect();return r==="vertical"?a>=p.top&&a<=p.bottom:n>=p.left&&n<=p.right});if(i.length===0){const d=new Map;o.forEach(m=>{const h=m.getBoundingClientRect(),x=Math.round(r==="vertical"?h.top:h.left);d.has(x)||d.set(x,[]),d.get(x).push(m)});let p=null,u=1/0;d.forEach((m,h)=>{const x=Math.abs(r==="vertical"?a-h:n-h);x<u&&(u=x,p=m)}),p&&p.length>0&&i.push(...p)}if(i.length===0)return null;let l=i[0],c=1/0;return i.forEach(d=>{const p=d.getBoundingClientRect(),u=p.left+p.width/2,m=p.top+p.height/2,h=Math.sqrt(Math.pow(n-u,2)+Math.pow(a-m,2));h<c&&(c=h,l=d)}),l}function getMaxSiblingDimensions(o){const n=getChildBlocks(o);if(n.length===0)return{maxWidth:0,maxHeight:0};let a=0,r=0;return n.forEach(i=>{const l=i.getBoundingClientRect();l.width>a&&(a=l.width),l.height>r&&(r=l.height)}),{maxWidth:a,maxHeight:r}}function getSiblingsInSameRow(o,n,a){const r=n.getBoundingClientRect(),i=5;return o.filter(l=>{const c=l.getBoundingClientRect();return a==="vertical"?Math.abs(c.top-r.top)<=i:Math.abs(c.left-r.left)<=i})}function calculatePlaceholderRect(o,n,a,r,i){var I,P;const l=o.getBoundingClientRect(),c=window.getComputedStyle(o),d=((I=i.defaultView)==null?void 0:I.scrollY)||0,p=((P=i.defaultView)==null?void 0:P.scrollX)||0,u=parseFloat(c.marginTop)||0,m=parseFloat(c.marginBottom)||0,h=parseFloat(c.marginLeft)||0,x=parseFloat(c.marginRight)||0,g=parseFloat(c.paddingTop)||0,f=parseFloat(c.paddingBottom)||0,b=parseFloat(c.paddingLeft)||0,j=parseFloat(c.paddingRight)||0,R=n==null?void 0:n.getBoundingClientRect(),y=n&&parseFloat(window.getComputedStyle(n).paddingLeft)||0,k=n&&parseFloat(window.getComputedStyle(n).paddingRight)||0,S=n&&parseFloat(window.getComputedStyle(n).paddingTop)||0,v=n&&parseFloat(window.getComputedStyle(n).paddingBottom)||0,B=n?getMaxSiblingDimensions(n):{maxWidth:0,maxHeight:0},C=n?getOrientation(n):"vertical",w=n?getChildBlocks(n):[],E=getSiblingsInSameRow(w,o,C);let A=0,_=0;if(E.forEach(L=>{const D=L.getBoundingClientRect();D.height>A&&(A=D.height),D.width>_&&(_=D.width)}),a==="before")if(r==="horizontal"){const L=R?R.width-y-k:l.width,D=R?R.left+p+y:l.left+p;return{top:l.top+d-u-2,left:D,width:L,height:4}}else{const L=l.top+d,D=C==="horizontal"&&A>0?A:B.maxHeight>0?B.maxHeight:R?R.height-S-v:l.height;return{top:L,left:l.left+p-h-2,width:4,height:D}}else if(a==="after")if(r==="horizontal"){const L=R?R.width-y-k:l.width,D=R?R.left+p+y:l.left+p;return{top:l.bottom+d+m-2,left:D,width:L,height:4}}else{const L=l.top+d,D=C==="horizontal"&&A>0?A:B.maxHeight>0?B.maxHeight:R?R.height-S-v:l.height;return{top:L,left:l.right+p+x-2,width:4,height:D}}else return hasChildBlocks(o)?getOrientation(o)==="vertical"?{top:l.bottom+d-f-2,left:l.left+p+b,width:l.width-b-j,height:4}:{top:l.top+d+g,left:l.right+p-j-2,width:4,height:l.height-g-f}:{top:l.top+d+g,left:l.left+p+b,width:l.width-b-j,height:Math.max(l.height-g-f,20)}}function isDescendantOf(o,n,a){if(!o||!n)return!1;if(o===n)return!0;const r=a.find(l=>l._id===o);if(!r)return!1;let i=r;for(;i._parent;){if(i._parent===n)return!0;const l=a.find(c=>c._id===i._parent);if(!l)break;i=l}return!1}function canDropWithoutCircularReference(o,n,a){return!o||!n?!0:!isDescendantOf(n,o,a)}function canDropAsSiblingWithoutCircularReference(o,n,a){if(!o)return!0;const r=a.find(l=>l._id===n);if(!r)return!0;const i=r._parent;return canDropWithoutCircularReference(o,i,a)}const LEAF_BLOCK_TYPES=["Heading","Text","Image","Paragraph","Icon","Input","Radio","Checkbox","Select","CustomHTML","TextArea","Divider","Repeater","Video"],AUTO_SCROLL_CONFIG={EDGE_ZONE:50,MAX_SCROLL_SPEED:10,MIN_SCROLL_SPEED:10},useBlockDragOver=()=>{const[o]=jotai.useAtom(dragAndDropAtom),[n]=useCanvasIframe(),[,a]=jotai.useAtom(dropIndicatorAtom),{clearParentHighlight:r,highlightParent:i}=useDragParentHighlight(),[l]=useBlocksStore(),c=n==null?void 0:n.contentDocument,d=React.useRef(null),p=React.useRef(0),u=React.useCallback(h=>{if(!(c!=null&&c.defaultView))return;const x=c.defaultView,g=x.innerHeight,f=x.scrollY,b=c.documentElement.scrollHeight;p.current=h;const j=h,R=g-h;let y=!1,k=null,S=0;if(j<AUTO_SCROLL_CONFIG.EDGE_ZONE&&f>0?(y=!0,k="up",S=j):R<AUTO_SCROLL_CONFIG.EDGE_ZONE&&f+g<b&&(y=!0,k="down",S=R),!y&&d.current!==null){cancelAnimationFrame(d.current),d.current=null;return}if(y&&k){const v=1-S/AUTO_SCROLL_CONFIG.EDGE_ZONE,B=AUTO_SCROLL_CONFIG.MIN_SCROLL_SPEED+(AUTO_SCROLL_CONFIG.MAX_SCROLL_SPEED-AUTO_SCROLL_CONFIG.MIN_SCROLL_SPEED)*v,C=()=>{if(!isDragging||!x){d.current=null;return}const w=k==="up"?-B:B;x.scrollBy(0,w);const E=x.scrollY,A=E>0,_=E+g<b,I=p.current,P=g-p.current;k==="up"&&A&&I<AUTO_SCROLL_CONFIG.EDGE_ZONE||k==="down"&&_&&P<AUTO_SCROLL_CONFIG.EDGE_ZONE?d.current=requestAnimationFrame(C):d.current=null};d.current===null&&(d.current=requestAnimationFrame(C))}},[c]);React.useEffect(()=>()=>{d.current!==null&&(cancelAnimationFrame(d.current),d.current=null)},[]),React.useEffect(()=>{!isDragging&&d.current!==null&&(cancelAnimationFrame(d.current),d.current=null)},[isDragging]);const m=React.useCallback(lodashEs.throttle(h=>{if(!isDragging||!o)return;r();const x=getTargetDetail(h),{element:g,targetBlockId:f,targetParentId:b}=x;if(!g||!f)return;const j=o._id;if(j&&(f===j||isDescendantOf(f,j,l)))return;const R=o._type||o.type;if(!R)return;const y=h.clientX,k=h.clientY;u(k);const S=detectDropZone(g,y,k,R,c);if(!S)return;const v=g.getAttribute("data-block-type")||"Box";let B=!1;const C=LEAF_BLOCK_TYPES.includes(v);if(S.position==="inside"){if(C||j&&!canDropWithoutCircularReference(j,f,l))return;B=canAcceptChildBlock(v,R)}else{let E=g.parentElement,A="Box";for(;E&&!E.hasAttribute("data-block-id");)E=E.parentElement;if(E&&(A=E.getAttribute("data-block-type")||"Box"),j&&!canDropAsSiblingWithoutCircularReference(j,f,l))return;B=canAcceptChildBlock(A,R)}if(!B)return;i(S.targetParentId);const w=S.targetParentId||b;a({isVisible:!0,isValid:!0,position:S.position,placeholderOrientation:S.placeholderOrientation,isEmpty:S.isEmpty,top:S.rect.top,left:S.rect.left,width:S.rect.width,height:S.rect.height,targetBlockId:S.targetBlockId,targetParentId:w}),removeDropTargetAttributes$1(c),S.targetElement.setAttribute("data-drop-target","true")},300),[c,o,a,r,i,l,u]);return React.useCallback(h=>{h.preventDefault(),h.stopPropagation(),m(h)},[m])};function getTargetDetail(o){let n=o.target;for(;n&&!n.hasAttribute("data-block-id");)n=n.parentElement;if(!n)return{element:null,targetBlockId:null,targetBlockType:null,targetParentId:null,targetParentType:null,orientation:"vertical"};const a=n.getAttribute("data-block-id"),r=n.getAttribute("data-block-type")||"Box";let i=n.parentElement;for(;i&&!i.hasAttribute("data-block-id");)i=i.parentElement;const l=(i==null?void 0:i.getAttribute("data-block-id"))||null,c=(i==null?void 0:i.getAttribute("data-block-type"))||"Box",d=getOrientation(n);return{element:n,targetBlockId:a,targetBlockType:r,targetParentId:l,targetParentType:c,orientation:d}}function removeDropTargetAttributes$1(o){if(!o)return;o.querySelectorAll("[data-drop-target]").forEach(a=>a.removeAttribute("data-drop-target"))}function createCoreDragImage(o){var l;const n=document.createElement("div");n.className="absolute -top-[1000px] -left-[1000px] pl-3 pr-1 py-1 bg-white/60 border border-blue-400/30 rounded shadow-md flex items-center gap-1.5 font-sans pointer-events-none z-[9999] scale-90";const a=o.type||o._type||"Box",r=document.createElement("div");r.className="w-3 h-3 flex items-center justify-center text-blue-600";try{a==="Image"?r.innerHTML='<svg class="w-3 h-3" fill="currentColor" viewBox="0 0 0.72 0.72"><path d="M.57.12H.15a.09.09 0 0 0-.09.09v.3A.09.09 0 0 0 .15.6h.42A.09.09 0 0 0 .66.51v-.3A.09.09 0 0 0 .57.12M.15.54A.03.03 0 0 1 .12.51V.437L.219.338a.03.03 0 0 1 .042 0L.462.54ZM.6.51a.03.03 0 0 1-.03.03H.547L.433.425.459.399a.03.03 0 0 1 .042 0L.6.498Zm0-.097L.544.357a.09.09 0 0 0-.127 0L.391.383.305.297a.09.09 0 0 0-.127 0L.12.353V.21A.03.03 0 0 1 .15.18h.42A.03.03 0 0 1 .6.21Z"/></svg>':r.innerHTML=((l=document.querySelector(`[data-add-core-block-icon="${a}"]`))==null?void 0:l.outerHTML)||'<svg class="w-3 h-3" fill="currentColor" viewBox="0 0 20 20"><path d="M3 4a1 1 0 011-1h12a1 1 0 011 1v12a1 1 0 01-1 1H4a1 1 0 01-1-1V4z"/></svg>'}catch{r.textContent=""}const i=document.createElement("span");return i.className="text-[10px] font-medium text-blue-600 whitespace-nowrap",i.textContent=o.label||o.type||o._name||o._type||"Block",n.appendChild(r),n.appendChild(i),document.body.appendChild(n),n}function cleanupDragImage(o){o&&o.parentNode&&o.parentNode.removeChild(o)}const useBlockDragStart=()=>{const[,o]=useSelectedBlockIds(),[,n]=useSelectedStylingBlocks(),{clearHighlight:a}=useBlockHighlight(),[,r]=jotai.useAtom(dragAndDropAtom),[,i]=jotai.useAtom(dropIndicatorAtom),l=React.useRef(null);return React.useCallback((c,d,p=!0)=>{var m;l.current&&(cleanupDragImage(l.current),l.current=null);const u=p?lodashEs.pick(d,["type","blocks","partialBlockId"]):d;if(r(u),c.dataTransfer.setData("text/plain",JSON.stringify({block:u})),c.dataTransfer.effectAllowed="move",!p&&d._id){const h=(m=document.getElementById("canvas-iframe"))==null?void 0:m.contentDocument;if(h){const x=h.querySelector(`[data-block-id="${d._id}"]`);x&&setTimeout(()=>{if(x){const f=x.getBoundingClientRect().height;getOrientation(x==null?void 0:x.parentElement)==="vertical"&&f>200&&(x.style.height="max-content",x.style.maxHeight="max-content",x.style.minHeight="0",x.style.overflow="hidden",x.innerHTML="<div class='flex items-center justify-center w-full h-full outline-[1px] outline-dashed font-medium outline-gray-500 bg-gray-500/10 py-4 text-transparent'>-</div>",x.style.opacity="0.4"),x.style.opacity="0.4",x.setAttribute("data-dragging","true")}},0)}}if(d!=null&&d._type||d!=null&&d.type){const h=createCoreDragImage(d);l.current=h,c.dataTransfer.setDragImage(h,0,0),setTimeout(()=>{l.current&&(cleanupDragImage(l.current),l.current=null)},50)}o([]),a(),n([]),pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK),setIsDragging(!0),i({isVisible:!0,isValid:!0,position:"inside",placeholderOrientation:"horizontal",isEmpty:!0,top:0,left:0,width:0,height:0,targetBlockId:"canvas",targetParentId:null})},[o,a,r,i])},useBlockDrop=()=>{const[o,n]=jotai.useAtom(dragAndDropAtom),[a,r]=jotai.useAtom(dropIndicatorAtom),[i]=useBlocksStore(),[l]=useCanvasIframe(),{addCoreBlock:c}=useAddBlock(),{moveBlocks:d}=useBlocksStoreUndoableActions(),[,p]=useSelectedBlockIds(),[,u]=useSelectedStylingBlocks(),{clearHighlight:m}=useBlockHighlight(),{clearParentHighlight:h}=useDragParentHighlight(),[x,g]=jotai.useAtom(canvasRenderKeyAtom),f=l==null?void 0:l.contentDocument;return React.useCallback(b=>{if(b.preventDefault(),b.stopPropagation(),setIsDragging(!1),restoreDraggedElementStyles(f),removeDropTargetAttributes(f),h(),r({isVisible:!1,isValid:!1,position:"inside",placeholderOrientation:"horizontal",isEmpty:!1,top:0,left:0,width:0,height:0}),setTimeout(()=>{h(),removeDropTargetAttributes(f),r({isVisible:!1,isValid:!1,position:"inside",placeholderOrientation:"horizontal",isEmpty:!1,top:0,left:0,width:0,height:0})},50),!o)return;if(!a.isValid||!a.targetBlockId){h();return}n(null);const j=a.targetBlockId,R=a.targetParentId;if(!j)return;const{parentId:y,index:k}=calculateInsertionIndex(i,j,R,a.position);if(o._id!==void 0)d([o._id],y===null?void 0:y,k),m(),u([]),p([o._id]);else{const v=o._type||o.type,B=o!=null&&o.blocks?lodashEs.isFunction(o==null?void 0:o.blocks)?runtime.syncBlocksWithDefaults(o==null?void 0:o.blocks()):o==null?void 0:o.blocks:null;c(v==="PartialBlock"?{blocks:[{_type:v,_id:"partial-block",partialBlockId:o.partialBlockId}]}:(B==null?void 0:B.length)>0?{blocks:[...B]}:{type:v},y,k)}setTimeout(()=>{g(x+1)},50)},[o,a,i,f,c,d,n,r,h,m,p,u,x,g])};function calculateInsertionIndex(o,n,a,r){try{if(n==="canvas"||r==="inside"&&n==="canvas")return{parentId:null,index:lodashEs.filter(o,m=>!(m!=null&&m._parent)).length};if(r==="inside"){const u=lodashEs.filter(o,{_parent:n});return{parentId:n,index:u.length}}const i=!a||a==="canvas",l=i?void 0:a,c=lodashEs.filter(o,u=>i?!(u!=null&&u._parent):(u==null?void 0:u._parent)===l),d=c.findIndex(u=>u._id===n);if(d===-1)return{parentId:i?null:a,index:c.length};const p=r==="before"?d:d+1;return{parentId:i?null:a,index:p}}catch{return{parentId:null,index:lodashEs.filter(o,c=>!(c!=null&&c._parent)).length}}}function removeDropTargetAttributes(o){if(!o)return;o.querySelectorAll("[data-drop-target]").forEach(a=>a.removeAttribute("data-drop-target"))}function restoreDraggedElementStyles(o){if(!o)return;o.querySelectorAll("[data-dragging]").forEach(a=>{a.removeAttribute("data-dragging")})}const useDragAndDrop=()=>{const o=useBlockDragStart(),n=useBlockDragOver(),a=useBlockDrop(),r=useBlockDragEnd();return{onDragStart:o,onDragOver:n,onDrop:a,onDragEnd:r,isDragging}},useDropIndicator=()=>{const[o]=jotai.useAtom(dropIndicatorAtom);return o},useIsDragAndDropEnabled=()=>{const{dragAndDrop:o}=useBuilderProp("flags",{dragAndDrop:!1});return o};let doc,win;typeof document<"u"&&(doc=document);typeof window<"u"&&(win=window);const FrameContext=React.createContext({document:doc,window:win}),useFrame=()=>React.useContext(FrameContext),{Provider:FrameContextProvider,Consumer:FrameContextConsumer}=FrameContext,CONTROLS=[{ControlIcon:reactIcons.PinTopIcon,dir:"VERTICAL",key:"UP"},{ControlIcon:reactIcons.PinBottomIcon,dir:"VERTICAL",key:"DOWN"},{ControlIcon:reactIcons.PinLeftIcon,dir:"HORIZONTAL",key:"LEFT"},{ControlIcon:reactIcons.PinRightIcon,dir:"HORIZONTAL",key:"RIGHT"}],getParentBlockOrientation=(o,n,a)=>{try{if(!o||!a)return"VERTICAL";const r=`[data-block-id='${o}']`,i=a==null?void 0:a.querySelector(r);if(i){const l=a==null?void 0:a.querySelector(`[data-block-id='${n}']`);return getOrientation(i,l).toUpperCase()}return"VERTICAL"}catch{return"VERTICAL"}},isDisabledControl=(o,n,a)=>!!(o&&(a==="UP"||a==="LEFT")||n&&(a==="DOWN"||a==="RIGHT")),useBlockController=(o,n)=>{const[a]=useBlocksStore(),{document:r}=useFrame(),{moveBlocks:i}=useBlocksStoreUndoableActions(),l=lodashEs.get(o,"_id"),c=lodashEs.get(o,"_parent"),d=lodashEs.filter(a,f=>c?lodashEs.get(f,"_parent")===c:!lodashEs.get(f,"_parent")),p=(d==null?void 0:d.length)<=1,u=lodashEs.findIndex(d,{_id:l}),m=u<=0,h=u+1===(d==null?void 0:d.length),x=getParentBlockOrientation(c,l,r),g=React.useCallback(f=>{isDisabledControl(m,h,f)||p||(f==="UP"||f==="LEFT"?i([l],c||null,u-1):(f==="DOWN"||f==="RIGHT")&&i([l],c||null,u+2),n())},[m,h,p,u,l,c,n]);return reactHotkeysHook.useHotkeys("shift+up, shift+down, shift+left, shift+right",({key:f})=>{var b;g((b=f==null?void 0:f.replace("Arrow",""))==null?void 0:b.toUpperCase())},{document:r==null?void 0:r.contentDocument},[g]),{isOnlyChild:p,isFirstBlock:m,isLastBlock:h,moveBlock:g,orientation:x}},BlockController=({block:o,updateFloatingBar:n})=>{const{isOnlyChild:a,isFirstBlock:r,isLastBlock:i,moveBlock:l,orientation:c}=useBlockController(o,n);return a?null:jsxRuntime.jsx(jsxRuntime.Fragment,{children:CONTROLS.map(({ControlIcon:d,dir:p,key:u})=>c!==p||isDisabledControl(r,i,u)?null:jsxRuntime.jsx(d,{onClick:()=>l(u),className:"rounded p-px hover:bg-white hover:text-blue-500"},u))})},AiIcon=({className:o="h-full w-full",onClick:n=lodashEs.noop})=>jsxRuntime.jsx("svg",{className:o,viewBox:"0 0 256 256",fill:"currentColor",onClick:n,children:jsxRuntime.jsx("path",{d:"m198.39 128.986-52.16-19.216-19.216-52.16a16 16 0 0 0-30.028 0L77.77 109.77l-52.16 19.216a16 16 0 0 0 0 30.028l52.16 19.216 19.216 52.16a16 16 0 0 0 30.028 0l19.216-52.16 52.16-19.216a16 16 0 0 0 0-30.028m-57.69 34.23a15.97 15.97 0 0 0-9.483 9.483l-19.22 52.152-19.214-52.15a15.97 15.97 0 0 0-9.482-9.484l-52.152-19.22 52.15-19.214a15.97 15.97 0 0 0 9.484-9.482l19.22-52.152 19.214 52.15a15.97 15.97 0 0 0 9.482 9.484l52.152 19.22ZM144 40a8 8 0 0 1 8-8h16V16a8 8 0 0 1 16 0v16h16a8 8 0 0 1 0 16h-16v16a8 8 0 0 1-16 0V48h-16a8 8 0 0 1-8-8m104 48a8 8 0 0 1-8 8h-8v8a8 8 0 0 1-16 0v-8h-8a8 8 0 0 1 0-16h8v-8a8 8 0 0 1 16 0v8h8a8 8 0 0 1 8 8"})}),GotoSettingsIcon=({blockId:o,className:n})=>{const a=()=>{o&&pubsub.publish(CHAI_BUILDER_EVENTS.GOTO_BLOCK_SETTINGS,o)};return jsxRuntime.jsx(reactIcons.GearIcon,{className:n,onClick:a})},lastClickTimeAtom=jotai.atom(0),clickCountAtom=jotai.atom(0);function getTargetedBlock(o){if(o.getAttribute("data-block-id")==="canvas")return null;if(o.getAttribute("data-block-id")||o.getAttribute("data-block-parent"))return o;const n=o.closest("[data-block-id]");return(n==null?void 0:n.getAttribute("data-block-id"))==="canvas"?null:n}const INLINE_EDITABLE_BLOCKS=["Heading","Paragraph","Text","Link","Span","Button"],isRichTextParent=o=>{var n;return(o==null?void 0:o.getAttribute("data-block-type"))==="RichText"||((n=o==null?void 0:o.parentElement)==null?void 0:n.getAttribute("data-block-type"))==="RichText"},hasDataBlockIdInChildren=o=>o?lodashEs.some(o.children,n=>{const a=n;return a.hasAttribute("data-block-id")||hasDataBlockIdInChildren(a)}):!1,isInlineEditable=(o,n)=>{if(isRichTextParent(o))return!0;const a=o==null?void 0:o.getAttribute("data-block-type");return a?INLINE_EDITABLE_BLOCKS.includes(a):!1},useHandleCanvasDblClick=()=>{const{editingBlockId:o,setEditingBlockId:n,setEditingItemIndex:a}=useInlineEditing();return React.useCallback(r=>{var d;if(r==null||r.preventDefault(),r==null||r.stopPropagation(),o)return;const i=getTargetedBlock(r.target);if(!isInlineEditable(i)||hasDataBlockIdInChildren(i))return;const l=i.getAttribute("data-block-id");if(!l||!i)return;const c=i.closest('[data-block-type="Repeater"]');c?(d=c==null?void 0:c.childNodes)==null||d.forEach((p,u)=>{p.contains(i)&&a(u)}):a(-1),n(l)},[o,n,a])},useHandleCanvasClick=()=>{const{editingBlockId:o}=useInlineEditing(),{clearHighlight:n}=useBlockHighlight(),[,a]=useSelectedStylingBlocks(),[r]=jotai.useAtom(clickCountAtom);return React.useCallback(i=>{if(o)return;i.stopPropagation();const l=getTargetedBlock(i.target);if(!l){n(),a([]),pubsub.publish(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_SELECTED,[]);return}if(r!==2){if(l!=null&&l.getAttribute("data-block-id")&&(l==null?void 0:l.getAttribute("data-block-id"))==="container"){pubsub.publish(CHAI_BUILDER_EVENTS.CLEAR_CANVAS_SELECTION);return}if(l!=null&&l.getAttribute("data-block-parent")){const c=l.getAttribute("data-style-prop"),d=l.getAttribute("data-style-id"),p=l.getAttribute("data-block-parent");pubsub.publish(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_STYLE_SELECTED,{blockId:p,styleId:d,styleProp:c})}else if(l!=null&&l.getAttribute("data-block-id")){const c=l.getAttribute("data-block-id");pubsub.publish(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_SELECTED,c==="canvas"?[]:[c])}n()}},[o,r,n,a])},useHandleMouseMove=()=>{const{editingBlockId:o}=useInlineEditing(),{highlightBlock:n}=useBlockHighlight();return web.useThrottledCallback(a=>{if(o)return;const r=getTargetedBlock(a.target);r&&n(r)},[o,n],100)},useHandleMouseLeave=()=>{const{clearHighlight:o}=useBlockHighlight();return React.useCallback(()=>o(),[o])},Canvas=({children:o})=>{const n=useHandleCanvasDblClick(),a=useHandleCanvasClick(),r=useHandleMouseMove(),i=useHandleMouseLeave();return jsxRuntime.jsx("div",{"data-block-id":"canvas",id:"canvas",onClick:a,onDoubleClick:n,onMouseMove:r,onMouseLeave:i,className:"relative h-full max-w-full p-px",children:o})},getElementByDataBlockId=(o,n)=>o.querySelector(`[data-block-id="${n}"]`),getElementByStyleId=(o,n)=>o.querySelector(`[data-style-id="${n}"]`),BlockSelectionHighlighter=()=>{const o=useSelectedBlock(),{document:n}=useFrame(),[a]=useSelectedStylingBlocks(),[r,i]=React.useState([]),[,l]=React.useState([]),{onDragStart:c,onDragEnd:d,isDragging:p}=useDragAndDrop(),[u,m]=React.useState(null),h=useIsDragAndDropEnabled(),x=(g,f=0)=>{const{top:b}=g.getBoundingClientRect();return b+f>=0&&b-f<=window.innerHeight};return React.useEffect(()=>{var g;if(o!=null&&o._id&&o.type!=="Multiple"&&n){const f=getElementByDataBlockId(n,o._id);f&&(x(f)||(g=n.defaultView)==null||g.scrollTo({top:f.offsetTop,behavior:"smooth"}),i([f]))}},[o==null?void 0:o._id,o==null?void 0:o.type,n]),React.useEffect(()=>{if(!lodashEs.isEmpty(a)&&n){const g=getElementByStyleId(n,lodashEs.first(a).id);l(g?[g]:[null])}else l([null])},[a,n]),jsxRuntime.jsx("div",{onDragEnd:()=>{m(null),d()},draggable:h&&!!o,onDragStart:g=>{m(r==null?void 0:r[0]),c(g,o,!1)},children:jsxRuntime.jsx(BlockFloatingSelector,{block:o,isDragging:p&&!!u,selectedBlockElement:r[0]||(p?u:null)})})},BlockFloatingSelector=({block:o,isDragging:n,selectedBlockElement:a})=>{const r=useRemoveBlocks(),i=useDuplicateBlocks(),[,l]=useSelectedBlockIds(),[,c]=useHighlightBlockId(),[,d]=useSelectedStylingBlocks(),{hasPermission:p}=usePermissions(),{editingBlockId:u}=useInlineEditing(),{document:m}=useFrame(),h=useIsDragAndDropEnabled(),x=useBuilderProp("flags.gotoSettings",!1),{floatingStyles:g,refs:f,update:b}=reactDom.useFloating({placement:"top-start",middleware:[reactDom.shift({boundary:m==null?void 0:m.body,limiter:dom.limitShift({offset:8,mainAxis:!0,crossAxis:!0})}),dom.flip({boundary:m==null?void 0:m.body,fallbackPlacements:["bottom-start","top-end","bottom-end","inside"]}),dom.size({boundary:m==null?void 0:m.body,apply({availableWidth:k,availableHeight:S,elements:v}){Object.assign(v.floating.style,{maxWidth:`${Math.max(200,k)}px`,maxHeight:`${Math.max(100,S)}px`})}})],elements:{reference:a}});web.useResizeObserver(a,()=>b(),a!==null),web.useResizeObserver(m==null?void 0:m.body,()=>b(),(m==null?void 0:m.body)!==null);const j=lodashEs.get(o,"_parent",null),R=lodashEs.isEmpty(lodashEs.get(o,"_name",""))?lodashEs.get(o,"_type",""):lodashEs.get(o,"_name","");React.useEffect(()=>{let k=null;return a?(k=setTimeout(()=>b(),500),()=>{k&&clearTimeout(k)}):(b(),()=>{k&&clearTimeout(k)})},[a,o==null?void 0:o._id]);const[,y]=useSidebarActivePanel();return!n&&(!a||!o||u)?null:jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx("div",{role:"button",tabIndex:0,ref:f.setFloating,style:g,onClick:k=>{k.stopPropagation(),k.preventDefault()},onMouseEnter:k=>{k.stopPropagation(),c(null)},onKeyDown:k=>k.stopPropagation(),className:`isolate z-[999] flex h-6 items-center justify-between bg-blue-500 py-2 text-xs text-white ${n?"opacity-0":""}`,children:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"flex items-center",children:[h&&jsxRuntime.jsx(reactIcons.DragHandleDots2Icon,{className:"flex-shrink-0 cursor-grab rounded p-0.5 hover:bg-white/20 active:cursor-grabbing"}),j&&jsxRuntime.jsx(reactIcons.ArrowUpIcon,{className:"flex-shrink-0 rounded p-0.5 hover:bg-white/20",onClick:()=>{d([]),l([j])}})]}),jsxRuntime.jsx("div",{className:`w-full ${h?"cursor-grab active:cursor-grabbing":""}`,children:jsxRuntime.jsx("div",{className:"mr-10 w-full items-center space-x-1 px-1 leading-tight",children:R})}),jsxRuntime.jsxs("div",{className:"flex items-center gap-1 pl-1 pr-1.5",children:[p(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsx(AiIcon,{className:"h-4 w-4 rounded hover:bg-white hover:text-blue-500",onClick:()=>{y("chai-chat-panel"),pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_AI_PANEL)}}),x&&jsxRuntime.jsx(GotoSettingsIcon,{blockId:o==null?void 0:o._id,className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500"}),!h&&jsxRuntime.jsx(AddBlockDropdown,{block:o,children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500"})}),canDuplicateBlock(lodashEs.get(o,"_type",""))&&p(PERMISSIONS.ADD_BLOCK)?jsxRuntime.jsx(reactIcons.CopyIcon,{className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500",onClick:()=>i([o==null?void 0:o._id])}):null,canDeleteBlock(lodashEs.get(o,"_type",""))&&p(PERMISSIONS.DELETE_BLOCK)?jsxRuntime.jsx(reactIcons.TrashIcon,{className:"h-4 w-4 rounded p-px hover:bg-white hover:text-blue-500",onClick:()=>r([o==null?void 0:o._id])}):null,p(PERMISSIONS.MOVE_BLOCK)&&jsxRuntime.jsx(BlockController,{block:o,updateFloatingBar:b})]})]})})})},IframeInitialContent=`<!doctype html>
|
|
2
|
+
<html lang="en" dir="__HTML_DIR__" class="scroll-smooth h-full overflow-y-auto">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
6
|
+
<script src="https://cdn.tailwindcss.com/3.4.17?plugins=forms@0.5.9,typography@0.5.15,aspect-ratio@0.4.2"><\/script>
|
|
7
|
+
<style>
|
|
8
|
+
html { height: 100%; overflow:auto; }
|
|
9
|
+
body { height: 100%; }
|
|
10
|
+
.air-highlight{ outline: 1px solid #42a1fc !important; outline-offset: -1px;}
|
|
11
|
+
.air-highlight-multi{ outline: 1px solid #29e503 !important; outline-offset: -1px;}
|
|
12
|
+
body{ -webkit-touch-callout: none; -webkit-user-select: none; -khtml-user-select: none;
|
|
13
|
+
-moz-user-select: none;-ms-user-select: none; user-select: none; }
|
|
14
|
+
html{
|
|
15
|
+
-ms-overflow-style: none; /* IE and Edge */
|
|
16
|
+
scrollbar-width: none; /* Firefox */
|
|
17
|
+
}
|
|
18
|
+
/** IMPORTANT: Make fields content editable in SAFARI */
|
|
19
|
+
[contenteditable] {-webkit-user-select: text;user-select: text;}
|
|
20
|
+
|
|
21
|
+
html::-webkit-scrollbar { width: 0 !important }
|
|
22
|
+
.aspect-auto{aspect-ratio: auto;}
|
|
23
|
+
.aspect-square{aspect-ratio: 1/1;}
|
|
24
|
+
.aspect-video{aspect-ratio: 16/9;}
|
|
25
|
+
.dragging [data-dnd="leaf"] { pointer-events: none; } .dragging [data-dnd="leaf"] * { pointer-events: none; }
|
|
26
|
+
.dragging [data-dnd="ignore"], .dragging [data-dnd="ignore"] * { pointer-events: none; }
|
|
27
|
+
a{ pointer-events: none !important; }
|
|
28
|
+
[contenteditable="true"], [contenteditable="true"] * { cursor: text !important; }
|
|
29
|
+
[contenteditable="true"] {
|
|
30
|
+
outline: none;
|
|
31
|
+
box-shadow: 0 0 0px 4px rgba(36, 150, 255, 0.2);
|
|
32
|
+
-webkit-user-select: text;
|
|
33
|
+
-moz-user-select: text;
|
|
34
|
+
user-select: text;
|
|
35
|
+
}
|
|
36
|
+
.frame-root .frame-content { height: 100%; }
|
|
37
|
+
[data-drop="yes"] { outline: 2px dashed orange !important; outline-offset: -2px }
|
|
38
|
+
[data-dnd="yes"] { pointer-events: auto !important}
|
|
39
|
+
[data-dnd="no"],[data-block-type="GlobalBlock"],[data-block-type="PartialBlock"] > * { pointer-events: none !important; }
|
|
40
|
+
[data-block-type="GlobalBlock"],[data-block-type="PartialBlock"] { position: relative !important; }
|
|
41
|
+
.partial-overlay { pointer-events: auto !important; }
|
|
42
|
+
[data-dnd-dragged="yes"] { opacity: 0.6; pointer-events: none; }
|
|
43
|
+
[data-dnd-dragged="no"] { opacity: 1; pointer-events: auto !important; }
|
|
44
|
+
[force-show] { display: block !important; }
|
|
45
|
+
[data-cut-block="yes"] { pointer-events: none !important; display: none !important; }
|
|
46
|
+
</style>
|
|
47
|
+
<style id="highlighted-block">
|
|
48
|
+
[data-highlighted]{
|
|
49
|
+
outline: 1px solid #42a1fc !important; outline-offset: -1px;
|
|
50
|
+
}
|
|
51
|
+
</style>
|
|
52
|
+
<style>
|
|
53
|
+
.react-colorful {
|
|
54
|
+
height: 120px !important;
|
|
55
|
+
width: 180px !important;
|
|
56
|
+
}
|
|
57
|
+
.react-colorful > div {
|
|
58
|
+
margin-bottom: 4px;
|
|
59
|
+
}
|
|
60
|
+
.react-colorful__saturation {
|
|
61
|
+
border-radius: 4px !important;
|
|
62
|
+
}
|
|
63
|
+
.react-colorful__hue,
|
|
64
|
+
.react-colorful__alpha {
|
|
65
|
+
height: 12px !important;
|
|
66
|
+
border-radius: 4px !important;
|
|
67
|
+
}
|
|
68
|
+
.react-colorful__pointer {
|
|
69
|
+
width: 16px !important;
|
|
70
|
+
height: 16px !important;
|
|
71
|
+
border: 1.5px solid #fff !important;
|
|
72
|
+
cursor: pointer !important;
|
|
73
|
+
z-index: 10002 !important;
|
|
74
|
+
}
|
|
75
|
+
#active-inline-editing-element{outline: 2px solid #00c951;}
|
|
76
|
+
</style>
|
|
77
|
+
<style type="text/tailwindcss">
|
|
78
|
+
@layer utilities {
|
|
79
|
+
.rte {
|
|
80
|
+
h1 {
|
|
81
|
+
@apply text-2xl;
|
|
82
|
+
}
|
|
83
|
+
h2 {
|
|
84
|
+
@apply text-xl;
|
|
85
|
+
}
|
|
86
|
+
h3 {
|
|
87
|
+
@apply text-lg;
|
|
88
|
+
}
|
|
89
|
+
h4 {
|
|
90
|
+
@apply text-base;
|
|
91
|
+
}
|
|
92
|
+
h5 {
|
|
93
|
+
@apply text-sm;
|
|
94
|
+
}
|
|
95
|
+
h6 {
|
|
96
|
+
@apply text-xs;
|
|
97
|
+
}
|
|
98
|
+
p {
|
|
99
|
+
&:empty {
|
|
100
|
+
@apply h-4;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
ul {
|
|
104
|
+
@apply list-disc pl-6 text-base;
|
|
105
|
+
}
|
|
106
|
+
ol {
|
|
107
|
+
@apply list-decimal pl-6 text-base;
|
|
108
|
+
}
|
|
109
|
+
li > p {
|
|
110
|
+
@apply m-0;
|
|
111
|
+
}
|
|
112
|
+
blockquote {
|
|
113
|
+
@apply pl-4 text-base;
|
|
114
|
+
p {
|
|
115
|
+
@apply pl-4 text-base;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
</style>
|
|
121
|
+
</head>
|
|
122
|
+
<body class="font-body antialiased h-full">
|
|
123
|
+
<div class="frame-root h-full"></div>
|
|
124
|
+
</body>
|
|
125
|
+
</html>`;class Content extends React.Component{componentDidMount(){this.props.contentDidMount()}componentDidUpdate(){this.props.contentDidUpdate()}render(){return React.Children.only(this.props.children)}}class Frame extends React.Component{constructor(a,r){super(a,r);G(this,"setRef",a=>{this.nodeRef.current=a;const{forwardedRef:r}=this.props;typeof r=="function"?r(a):r&&(r.current=a)});G(this,"handleLoad",()=>{clearInterval(this.loadCheck),this.state.iframeLoaded||this.setState({iframeLoaded:!0})});G(this,"loadCheck",()=>setInterval(()=>{this.handleLoad()},500));this._isMounted=!1,this.nodeRef=React.createRef(),this.state={iframeLoaded:!1}}componentDidMount(){this._isMounted=!0,this.getDoc()&&this.nodeRef.current.contentWindow.addEventListener("DOMContentLoaded",this.handleLoad)}componentWillUnmount(){this._isMounted=!1,this.nodeRef.current.removeEventListener("DOMContentLoaded",this.handleLoad)}getDoc(){return this.nodeRef.current?this.nodeRef.current.contentDocument:null}getMountTarget(){const a=this.getDoc();return this.props.mountTarget?a.querySelector(this.props.mountTarget):a.body.children[0]}renderFrameContents(){if(!this._isMounted)return null;const a=this.getDoc();if(!a)return null;const r=this.props.contentDidMount,i=this.props.contentDidUpdate,l=a.defaultView||a.parentView,c=jsxRuntime.jsx(Content,{contentDidMount:r,contentDidUpdate:i,children:jsxRuntime.jsx(FrameContextProvider,{value:{document:a,window:l},children:jsxRuntime.jsx("div",{className:"frame-content",children:this.props.children})})}),d=this.getMountTarget();return[ReactDOM.createPortal(this.props.head,this.getDoc().head),ReactDOM.createPortal(c,d)]}render(){const a={...this.props,srcDoc:this.props.initialContent,children:void 0};return delete a.head,delete a.initialContent,delete a.mountTarget,delete a.contentDidMount,delete a.contentDidUpdate,delete a.forwardedRef,jsxRuntime.jsx("iframe",{...a,ref:this.setRef,onLoad:this.handleLoad,children:this.state.iframeLoaded&&this.renderFrameContents()})}}G(Frame,"defaultProps",{style:{},head:null,children:void 0,mountTarget:void 0,contentDidMount:()=>{},contentDidUpdate:()=>{},initialContent:'<!DOCTYPE html><html><head></head><body><div class="frame-root"></div></body></html>'});const ChaiFrame=React.forwardRef((o,n)=>jsxRuntime.jsx(Frame,{...o,forwardedRef:n})),useKeyEventWatcher=o=>{const[n,a]=useSelectedBlockIds(),r=useSelectedBlock(),i=useRemoveBlocks(),l=useDuplicateBlocks(),{undo:c,redo:d}=useUndoManager(),[,p]=useCutBlockIds(),[,u]=useCopyBlocks(),{canPaste:m,pasteBlocks:h}=usePasteBlocks(),x=o?{document:o}:{};reactHotkeysHook.useHotkeys("ctrl+z,meta+z",g=>{g.preventDefault(),undoManager.hasUndo()&&c()},{...x,preventDefault:!0},[c]),reactHotkeysHook.useHotkeys("ctrl+y,meta+y",g=>{g.preventDefault(),undoManager.hasRedo()&&d()},{...x,preventDefault:!0},[d]),reactHotkeysHook.useHotkeys("ctrl+x,meta+x",g=>{g.preventDefault(),lodashEs.isEmpty(n)||p(n)},{...x,enabled:!lodashEs.isEmpty(n),preventDefault:!0},[n,p]),reactHotkeysHook.useHotkeys("ctrl+c,meta+c",()=>u(n),{...x,enabled:!lodashEs.isEmpty(n),preventDefault:!0},[n,u]),reactHotkeysHook.useHotkeys("ctrl+v,meta+v",()=>{m(n[0])&&h(n)},{...x,enabled:!lodashEs.isEmpty(n),preventDefault:!0},[n,m,h]),reactHotkeysHook.useHotkeys("esc",()=>a([]),x,[a]),reactHotkeysHook.useHotkeys("ctrl+d,meta+d",()=>l(n),{...x,enabled:!lodashEs.isEmpty(n),preventDefault:!0},[n,l]),reactHotkeysHook.useHotkeys("del, backspace",g=>{g.preventDefault(),canDeleteBlock(lodashEs.get(r,"_type",""))&&i(n)},x,[n,i])},KeyboardHandler=()=>{const{document:o}=useFrame();return useKeyEventWatcher(o),null},AddBlockAtBottom=()=>{const{t:o}=reactI18next.useTranslation(),{hasPermission:n}=usePermissions(),a=n(PERMISSIONS.ADD_BLOCK),r=useIsDragAndDropEnabled();return a?jsxRuntime.jsxs("div",{id:"add-block-bottom",className:"group relative w-full cursor-pointer py-2",children:[jsxRuntime.jsx("br",{}),!r&&jsxRuntime.jsx("div",{role:"button",onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK),className:"block h-1 rounded bg-primary opacity-0 duration-200 group-hover:opacity-100",children:jsxRuntime.jsxs("div",{className:"absolute left-1/2 flex -translate-x-1/2 -translate-y-1/2 transform items-center gap-x-1 rounded-full bg-primary px-3 py-1 text-xs leading-tight text-white hover:bg-primary",children:[jsxRuntime.jsx(reactIcons.PlusIcon,{className:"size-2.5 stroke-[3]"})," ",o("Add block")]})}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]}):null},CssThemeVariables=({theme:o})=>{const n=React.useMemo(()=>plugin.getChaiThemeCssVariables(o),[o]);return jsxRuntime.jsx("style",{id:"chai-theme",children:n})},HeadTags=()=>{const[o]=useTheme(),n=useThemeOptions(),[a]=useDarkMode(),{document:r,window:i}=useFrame();return React.useEffect(()=>{a?r==null||r.documentElement.classList.add("dark"):r==null||r.documentElement.classList.remove("dark")},[a,r]),React.useEffect(()=>{!i||!i.tailwind||(i.tailwind.config={darkMode:"class",theme:{extend:{container:{center:!0,padding:"1rem",screens:{"2xl":"1400px"}},...plugin.getChaiThemeOptions(n)}},plugins:[tailwindTypography,tailwindForms,tailwindAspectRatio,twContainer,plugin.plugin(function({addBase:l,theme:c}){l({"h1,h2,h3,h4,h5,h6":{fontFamily:c("fontFamily.heading")},body:{fontFamily:c("fontFamily.body"),color:c("colors.foreground"),backgroundColor:c("colors.background")}})})]})},[o,n,i]),jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(CssThemeVariables,{theme:o}),jsxRuntime.jsx(Fonts,{}),jsxRuntime.jsx(SelectedBlocks,{}),jsxRuntime.jsx(SelectedStylingBlocks,{})]})},SelectedStylingBlocks=()=>{const[o]=useSelectedStylingBlocks(),[n]=useSelectedBlockIds(),a=React.useMemo(()=>`${lodashEs.map(o,({id:r})=>`[data-style-id="${r}"]`).join(",")}{
|
|
126
|
+
outline: 1px solid ${n.length>0?"#42a1fc":"#de8f09"} !important; outline-offset: -1px;
|
|
127
|
+
}`,[o,n]);return jsxRuntime.jsx("style",{id:"selected-styling-blocks",dangerouslySetInnerHTML:{__html:a}})},SelectedBlocks=()=>{const[o]=useSelectedBlockIds(),n=React.useMemo(()=>`${lodashEs.map(o,a=>`[data-block-id="${a}"]`).join(",")}{
|
|
128
|
+
outline: 1px solid #42a1fc !important; outline-offset: -1px;
|
|
129
|
+
}`,[o]);return jsxRuntime.jsx("style",{id:"selected-blocks",dangerouslySetInnerHTML:{__html:n}})},Fonts=()=>{const[o]=useTheme(),n=runtime.useRegisteredFonts(),a=React.useMemo(()=>{const{heading:l,body:c}={heading:lodashEs.get(o,"fontFamily.heading"),body:lodashEs.get(o,"fontFamily.body")};return n.filter(d=>d.family===l||d.family===c)},[o==null?void 0:o.fontFamily,n]),r=React.useMemo(()=>plugin.getThemeFontsUrls(lodashEs.filter(a,l=>lodashEs.has(l,"url"))),[a]),i=React.useMemo(()=>plugin.getThemeCustomFontFace(lodashEs.filter(a,l=>lodashEs.has(l,"src"))),[a]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[r.map((l,c)=>jsxRuntime.jsx("link",{rel:"stylesheet",href:l},`google-font-${c}`)),jsxRuntime.jsx("style",{id:"chai-custom-fonts",dangerouslySetInnerHTML:{__html:i}})]})},ResizableCanvasWrapper=({children:o,onMount:n,onResize:a})=>{const[,r]=useSelectedBlockIds(),[,i]=useSelectedStylingBlocks(),l=React.useRef(null),c=web.useDebouncedCallback(()=>{const{clientWidth:p}=l.current;a(p)},[l.current],100);web.useResizeObserver(l.current,c,l.current!==null),React.useEffect(()=>{const{clientWidth:p}=l.current;n(p)},[]);const d=React.useCallback(()=>{r([]),i([])},[r,i]);return jsxRuntime.jsx("div",{id:"main-content",onClick:d,className:"h-full w-full border-l-4 border-r-4 pb-0",ref:l,children:o})},useDirectBlockDrag=()=>{const[,o]=useSelectedBlockIds(),{onDragStart:n,onDragEnd:a}=useDragAndDrop(),[r]=useBlocksStore(),i=React.useRef(null),[l,c]=jotai.useAtom(lastClickTimeAtom),[d,p]=jotai.useAtom(clickCountAtom),u=React.useCallback(x=>{var R;if(x.button!==0)return;const g=Date.now(),f=g-l;if(f<400&&f>0){p(2);return}c(g);const j=(R=x.target.closest("[data-block-id]"))==null?void 0:R.getAttribute("data-block-id");j&&(o([j]),i.current=j)},[o,l,c,d,p]),m=React.useCallback(x=>{if(!i.current)return;const g=lodashEs.find(r,{_id:i.current});g&&n(x,g,!1)},[r,n]),h=React.useCallback(()=>{a(),i.current=null},[a]);return{onMouseDown:u,onDragStart:m,onDragEnd:h}},editorModeAtom=jotai.atom("edit"),useEditorMode=()=>{const[o,n]=jotai.useAtom(editorModeAtom);return{mode:o,setMode:n}},MayBeAsyncPropsWrapper=({children:o,block:n})=>{const a=React.useMemo(()=>runtime.getRegisteredChaiBlock(n._type),[n._type]),r=lodashEs.get(a,"dataProviderDependencies"),i=lodashEs.get(a,"dataProvider"),l=lodashEs.get(a,"dataProviderMode","mock"),c=useAsyncProps(n,l,r,i);return o(c)},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,[i,l])=>{const c=[];let d=lodashEs.find(o,{_id:n});for(;d;)c.push(d),d=lodashEs.find(o,{_id:d._parent});const p=lodashEs.find(c,{_type:l.block});return p&&(r[i]=lodashEs.get(p,lodashEs.get(l,"prop"),null)),r},{}),[o])};function cn(...o){return tailwindMerge.twMerge(clsx.clsx(o))}const RteDropdownMenu=({editor:o,trigger:n,content:a,from:r,menuRef:i})=>{const{document:l}=useFrame(),[c,d]=React.useState({left:void 0,right:void 0,top:void 0,bottom:void 0}),[p,u]=React.useState(!1),m=React.useRef(null);if(React.useEffect(()=>{var R,y;if(!p){d({left:void 0,right:void 0,top:void 0,bottom:void 0});return}const h=(R=m.current)==null?void 0:R.getBoundingClientRect(),x=(y=i.current)==null?void 0:y.getBoundingClientRect();let g=h==null?void 0:h.left,f=(h==null?void 0:h.bottom)+4,b,j;(x==null?void 0:x.left)+(x==null?void 0:x.width)+50>=l.body.offsetWidth&&(g=void 0,b=l.body.offsetWidth-(h==null?void 0:h.right)),f+202>=l.body.clientHeight&&(f=null,j=l.body.clientHeight-(h==null?void 0:h.bottom)+(x==null?void 0:x.height)),d({left:g,top:f,right:b,bottom:j})},[p]),r==="canvas"){const h=()=>{u(!1),o&&(o==null||o.view.focus(),o==null||o.chain().focus().run())};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{ref:m,onClick:()=>u(x=>!x),className:"cursor-pointer",children:n}),p&&(c.left!==void 0||c.top!==void 0||c.right!==void 0||c.bottom!==void 0)&&ReactDOM.createPortal(jsxRuntime.jsx("div",{id:"chaibuilder-rte-dropdown-menu-content",onClick:h,className:"fixed inset-0 left-0 top-0 z-[10001] h-full w-screen",children:jsxRuntime.jsx("div",{onClick:x=>x.stopPropagation(),className:"absolute rounded-md border border-gray-500 bg-white p-1.5 text-xs shadow-2xl",style:Object.assign({},{left:c.left,top:c.top,right:c.right,bottom:c.bottom}),children:typeof a=="function"?a(h):a})}),l.body,"chaibuilder-rte-dropdown-menu")]})}return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs(tooltip.DropdownMenu,{open:p,onOpenChange:u,children:[jsxRuntime.jsx(tooltip.DropdownMenuTrigger,{className:"relative outline-none",asChild:!0,children:n}),jsxRuntime.jsx(tooltip.DropdownMenuContent,{className:"z-50 rounded-md border bg-white p-1 text-xs shadow-xl",children:p&&(typeof a=="function"?a(()=>u(!1)):a)})]})})};utils.atomWithStorage("chai-builder-blocks",[]);const lsThemeAtom=utils.atomWithStorage("chai-builder-theme",{});utils.atomWithStorage("chai-builder-design-tokens",{});utils.atomWithStorage("chai-builder-ai-context","");const getActiveClasses$1=(o,n,a)=>{const r=a==="settings",i=typeof n=="boolean"?n:n.some(l=>o.isActive(l));return{"rounded p-1":!0,"hover:bg-blue-900 hover:text-blue-100":!i&&!r,"hover:bg-blue-100 hover:text-blue-900":!i&&r,"bg-blue-500 text-white":i&&r,"bg-white text-blue-500":i&&!r}},Commons=({themeColors:o,onClose:n,color:a,onChange:r,onRemove:i})=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"flex w-[180px] flex-wrap gap-1 pb-2",children:(o==null?void 0:o.length)>0&&lodashEs.uniq(o).map(l=>{var c;return jsxRuntime.jsx("button",{className:cn("h-4 w-4 cursor-pointer rounded-full border border-gray-900 shadow duration-200 hover:scale-105 hover:shadow-xl",{"border-2":l===a}),style:{backgroundColor:l},onClick:()=>{r(l),n()},title:(c=l||"#000000")==null?void 0:c.toUpperCase()},l)})}),jsxRuntime.jsx(reactColorful.HexAlphaColorPicker,{color:a,onChange:r,style:{width:"200px",height:"200px"}}),jsxRuntime.jsxs("div",{className:"mt-1 flex items-center justify-between gap-1",children:[jsxRuntime.jsx(tooltip.Input,{type:"text",value:a||"#000000f2",onChange:l=>r(l.target.value,!0),className:"!h-5 !w-[105px] rounded-sm !p-0 text-center font-light uppercase text-gray-600 outline-none ring-0 focus:ring-0",placeholder:"#000000"}),jsxRuntime.jsxs("button",{className:"flex h-4 w-max cursor-pointer items-center gap-x-1 rounded-full bg-transparent px-1 text-red-600 shadow-none duration-200 hover:bg-red-100",onClick:()=>{i(),n()},title:"Remove",children:[jsxRuntime.jsx(reactIcons.Cross1Icon,{className:"h-3 w-3"})," Remove"]})]})]}),ColorPickerContent=({textColor:o,highlightColor:n,onChangeTextColor:a,onChangeHighlightColor:r,onRemoveTextColor:i,onRemoveHighlightColor:l,onClose:c})=>{const[d]=useDarkMode(),[p]=jotai.useAtom(lsThemeAtom),u=(p==null?void 0:p.colors)||{},m=Object.values(u).map(g=>lodashEs.get(g,d?"1":"0")),[h,x]=React.useState("TEXT");return jsxRuntime.jsxs("div",{id:"rte-widget-color-picker",className:"px-1",children:[jsxRuntime.jsxs("div",{className:"mb-2 flex items-center justify-between rounded-md border bg-muted",children:[jsxRuntime.jsx("div",{className:`w-full cursor-pointer rounded p-0.5 text-center ${h==="TEXT"?"bg-blue-500 text-white":"hover:bg-blue-100 hover:text-blue-500"}`,onClick:()=>x("TEXT"),children:"Text Color"}),jsxRuntime.jsx("div",{className:`w-full cursor-pointer rounded p-0.5 text-center ${h==="HIGHLIGHT"?"bg-blue-500 text-white":"hover:bg-blue-100 hover:text-blue-500"}`,onClick:()=>x("HIGHLIGHT"),children:"Highlight Color"})]}),h==="TEXT"?jsxRuntime.jsx(Commons,{themeColors:m,onClose:c,onChange:a,color:o,onRemove:i}):jsxRuntime.jsx(Commons,{themeColors:m,onClose:c,onChange:r,color:n,onRemove:l})]})},RteColorPicker=({editor:o,from:n,menuRef:a})=>{var y,k;const r=(y=o==null?void 0:o.getAttributes("textStyle"))==null?void 0:y.color,i=(k=o==null?void 0:o.getAttributes("highlight"))==null?void 0:k.color,[l,c]=React.useState(r||"#000000F2"),[d,p]=React.useState(i||"#00000057"),[u,m]=web.useDebouncedState(l,150),[h,x]=web.useDebouncedState(d,150),g=(S,v)=>{v?(c(S),m(S)):(o==null||o.chain().setColor(S).run(),c(S))},f=(S,v)=>{v?(p(S),x(S)):(o==null||o.chain().setHighlight({color:S}).run(),p(S))},b=()=>{o==null||o.chain().unsetColor().run(),c("#000000F2")},j=()=>{o==null||o.chain().unsetHighlight().run()};React.useEffect(()=>{i&&p(i)},[i]),React.useEffect(()=>{h!=null&&h.includes("#")&&(h==null?void 0:h.length)>=3&&(o==null||o.chain().setHighlight({color:h}).run())},[h]),React.useEffect(()=>{u!=null&&u.includes("#")&&(u==null?void 0:u.length)>=3&&(o==null||o.chain().setColor(u).run())},[u]);const R=!!r;return jsxRuntime.jsx(RteDropdownMenu,{editor:o,from:n,menuRef:a,trigger:jsxRuntime.jsxs("div",{className:cn("relative flex items-center",getActiveClasses$1(o,R,n)),title:"Text Color",children:[jsxRuntime.jsx("div",{className:"h-4 w-4 rounded-full",style:{backgroundColor:r||(n==="canvas"?"#FFFFFF":"#000000")}}),jsxRuntime.jsx(reactIcons.CaretDownIcon,{className:"h-3 w-3 opacity-50"})]}),content:S=>jsxRuntime.jsx(ColorPickerContent,{textColor:l,highlightColor:d,onChangeTextColor:g,onChangeHighlightColor:f,onRemoveTextColor:b,onRemoveHighlightColor:j,onClose:S})})},getActiveClasses=(o,n,a)=>{const r=a==="settings",i=typeof n=="boolean"?n:n.some(l=>o.isActive(l));return{"rounded p-1":!0,"hover:bg-blue-900 hover:text-blue-100":!i&&!r,"hover:bg-blue-100 hover:text-blue-900":!i&&r,"bg-blue-500 text-white":i&&r,"bg-white text-blue-500":i&&!r}},RteMenubar=({editor:o,from:n="settings",onExpand:a})=>{const r=React.useRef(null);if(!o)return null;const i=()=>{const c=window.prompt("URL");c&&o.chain().focus().extendMarkRange("link").setLink({href:c}).run()},l=()=>{o.chain().focus().unsetLink().run()};return jsxRuntime.jsxs("div",{ref:r,id:"chai-rich-text-menu-bar",className:cn("mb-1 flex flex-wrap gap-0.5 rounded-t-md border-b border-border bg-gray-50 p-1",{"mb-0 rounded-md border-none bg-blue-500 text-white":n==="canvas"}),children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleBold().run(),className:cn("",getActiveClasses(o,["bold"],n)),title:"Bold",children:jsxRuntime.jsx(reactIcons.FontBoldIcon,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleItalic().run(),className:cn("",getActiveClasses(o,["italic"],n)),title:"Italic",children:jsxRuntime.jsx(reactIcons.FontItalicIcon,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleUnderline().run(),className:cn("",getActiveClasses(o,["underline"],n)),title:"Underline",children:jsxRuntime.jsx(reactIcons.UnderlineIcon,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleStrike().run(),className:cn("",getActiveClasses(o,["strike"],n)),title:"Strike",children:jsxRuntime.jsx(reactIcons.StrikethroughIcon,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-5 w-px self-center bg-border"}),jsxRuntime.jsx(RteColorPicker,{editor:o,from:n,menuRef:r}),jsxRuntime.jsx("div",{className:"mx-1 h-5 w-px self-center bg-border"}),jsxRuntime.jsx(RteDropdownMenu,{editor:o,menuRef:r,from:n,trigger:jsxRuntime.jsxs("button",{type:"button",className:cn("flex items-center",getActiveClasses(o,["bulletList","orderedList"],n)),title:"Bullet List",children:[jsxRuntime.jsx(reactIcons.ListBulletIcon,{className:"h-4 w-4"}),jsxRuntime.jsx(reactIcons.CaretDownIcon,{className:"h-3 w-3 opacity-50"})]}),content:c=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{onClick:()=>{o.chain().focus().toggleBulletList().run(),c()},className:cn("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",getActiveClasses(o,["bulletList"],n)),children:[jsxRuntime.jsx(reactIcons.ListBulletIcon,{className:"h-4 w-4"})," Unordered List"]}),jsxRuntime.jsxs("div",{onClick:()=>{o.chain().focus().toggleOrderedList().run(),c()},className:cn("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",getActiveClasses(o,["orderedList"],n)),children:[jsxRuntime.jsx(reactIcons.ValueIcon,{className:"h-4 w-4"}),"Ordered List"]})]})}),jsxRuntime.jsx(RteDropdownMenu,{editor:o,menuRef:r,from:n,trigger:jsxRuntime.jsxs("button",{type:"button",className:cn("flex items-center",getActiveClasses(o,o.isActive({textAlign:"center"})||o.isActive({textAlign:"right"}),n)),title:"Text Alignment",children:[o.isActive({textAlign:"center"})?jsxRuntime.jsx(reactIcons.TextAlignCenterIcon,{className:"h-4 w-4"}):o.isActive({textAlign:"right"})?jsxRuntime.jsx(reactIcons.TextAlignRightIcon,{className:"h-4 w-4"}):jsxRuntime.jsx(reactIcons.TextAlignLeftIcon,{className:"h-4 w-4"}),jsxRuntime.jsx(reactIcons.CaretDownIcon,{className:"h-3 w-3 opacity-50"})]}),content:c=>jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{onClick:()=>{o.chain().focus().setTextAlign("left").run(),c()},className:cn("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",getActiveClasses(o,o.isActive({textAlign:"left"}),n)),children:[jsxRuntime.jsx(reactIcons.TextAlignLeftIcon,{className:"h-4 w-4"})," Align Left"]}),jsxRuntime.jsxs("div",{onClick:()=>{o.chain().focus().setTextAlign("center").run(),c()},className:cn("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",getActiveClasses(o,o.isActive({textAlign:"center"}),n)),children:[jsxRuntime.jsx(reactIcons.TextAlignCenterIcon,{className:"h-4 w-4"})," Align Center"]}),jsxRuntime.jsxs("div",{onClick:()=>{o.chain().focus().setTextAlign("right").run(),c()},className:cn("flex cursor-pointer items-center gap-x-1 outline-none hover:outline-none",getActiveClasses(o,o.isActive({textAlign:"right"}),n)),children:[jsxRuntime.jsx(reactIcons.TextAlignRightIcon,{className:"h-4 w-4"})," Align Right"]})]})}),o.isActive("link")?jsxRuntime.jsx("button",{type:"button",onClick:l,className:cn("",getActiveClasses(o,["link"],n)),title:"Remove Link",disabled:!o.isActive("link"),children:jsxRuntime.jsx(reactIcons.LinkBreak2Icon,{className:"h-3.5 w-3.5"})}):jsxRuntime.jsx("button",{type:"button",onClick:i,className:cn("",getActiveClasses(o,["link"],n)),title:"Add Link",children:jsxRuntime.jsx(reactIcons.Link2Icon,{className:"h-3.5 w-3.5"})}),a&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"mx-1 h-5 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:a,className:cn("",getActiveClasses(o,!1,n)),title:"Open in full screen mode",children:jsxRuntime.jsx(reactIcons.EnterFullScreenIcon,{className:"h-3.5 w-3.5"})})]})]})},useRTEditor=({blockId:o,value:n="",onUpdate:a=()=>{},onBlur:r=()=>{},placeholder:i="",from:l="settings",style:c={}})=>react.useEditor({extensions:[StarterKit,extensionTextStyle.TextStyle,extensionTextStyle.Color.configure({types:["textStyle"]}),Highlight.configure({multicolor:!0}),Link.configure({openOnClick:!1,HTMLAttributes:{class:"underline"}}),TextAlign.configure({types:["heading","paragraph"],alignments:["left","center","right"],defaultAlignment:"left"}),Underline,Placeholder.configure({placeholder:i||"Enter text here",emptyEditorClass:"cursor-text before:content-[attr(data-placeholder)] before:absolute before:opacity-50 before:pointer-events-none"})],content:n||"",onUpdate:a,onBlur:r,editorProps:{attributes:{...c?{style:c}:{},class:l!=="canvas"?"text-sm p-1 px-2 rte":"rte"}}},[o]);function getInitialTextAlign(o){let n=o;for(;n;){if(n.style&&n.style.textAlign)return n.style.textAlign;const a=window.getComputedStyle(n).textAlign;if(a&&a!=="start"&&a!=="initial"&&a!=="inherit")return a;n=n.parentElement}return null}const RichTextEditor=React.memo(({blockContent:o,editingElement:n,onClose:a,onChange:r,onEscape:i})=>{const{document:l}=useFrame(),c=useRTEditor({value:o,blockId:"active-inline-editing-element",placeholder:"Enter text here",onUpdate:({editor:u})=>r((u==null?void 0:u.getHTML())||""),onBlur:({editor:u,event:m})=>{const h=m==null?void 0:m.relatedTarget,x=l.querySelector(".ProseMirror"),g=l.querySelector(".tippy-box"),f=l.querySelector("#chai-rich-text-menu-bar"),b=x==null?void 0:x.contains(h),j=g==null?void 0:g.contains(h),R=f==null?void 0:f.contains(h),y=window.document.getElementById("rte-widget-color-picker");if(!b&&!j&&!R&&!y){const k=(u==null?void 0:u.getHTML())||"";a(k)}},from:"canvas"});React.useEffect(()=>{var m,h;const u=getInitialTextAlign(n);u&&((m=c==null?void 0:c.commands)==null||m.setTextAlign(u)),(h=c==null?void 0:c.commands)==null||h.focus(),c==null||c.emit("focus",{editor:c,event:new FocusEvent("focus"),transaction:[]})},[c]);const d=React.useMemo(()=>{var h;const u="max-w-none shadow-none outline outline-[2px] [&_*]:shadow-none";if(!n)return u;const m=((h=n==null?void 0:n.className)==null?void 0:h.replace("sr-only",""))||"";return`${u} ${m}`},[n]),p=u=>{u.key==="Escape"&&i(u)};return c&&jsxRuntime.jsxs("div",{onKeyDown:p,onClick:u=>u.stopPropagation(),className:"relative",children:[jsxRuntime.jsx(react.BubbleMenu,{editor:c,shouldShow:()=>c&&(c==null?void 0:c.isFocused),tippyOptions:{duration:100,arrow:!0,hideOnClick:!1},className:"w-max",children:jsxRuntime.jsx(RteMenubar,{editor:c,from:"canvas"})}),jsxRuntime.jsx(react.EditorContent,{id:"active-inline-editing-element",onKeyDown:p,value:o,editor:c,className:d})]})}),MemoizedEditor=React.memo(({editingElement:o,blockContent:n,onClose:a,editorRef:r,onChange:i,onEscape:l})=>{const{document:c,window:d}=useFrame();React.useEffect(()=>{if(r.current){r.current.innerHTML=n,r.current.focus();const x=c.createRange(),g=d.getSelection();x.selectNodeContents(r.current),x.collapse(!1),g==null||g.removeAllRanges(),g==null||g.addRange(x),r.current.focus()}else a()},[c,d]);const p=React.useMemo(()=>{var g;const x=((g=o==null?void 0:o.tagName)==null?void 0:g.toLowerCase())||"div";return x==="button"?"div":x},[o]),u=React.useCallback(x=>{(x.key==="Enter"||x.key==="Escape")&&l(x)},[l]),m=React.useCallback(()=>{a()},[a]),h=React.useMemo(()=>{var x;return{id:"active-inline-editing-element",contentEditable:!0,className:`${((x=o==null?void 0:o.className)==null?void 0:x.replace("sr-only",""))||""} outline outline-[2px] outline-green-500 shadow-none empty:before:content-[attr(data-placeholder)] empty:before:text-gray-400 empty:before:absolute empty:before:pointer-events-none empty:before:select-none empty:before:inset-0 empty:before:z-0 relative min-h-[1em]`,style:lodashEs.cloneDeep(o==null?void 0:o.style)||{},onInput:g=>{const f=g.target;f&&(f.innerText.trim()===""?(f.setAttribute("data-placeholder","Enter text here"),f.children.length>0&&f.children[0].remove()):g.target.removeAttribute("data-placeholder"),i(g.target.innerText))},onClick:g=>{g.stopPropagation(),g.preventDefault()}}},[o==null?void 0:o.className,o==null?void 0:o.style]);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:React.createElement(p,{ref:r,onBlur:m,onKeyDown:u,...h})})}),WithBlockTextEditor=React.memo(({block:o,children:n})=>{const a="content",{document:r}=useFrame(),{editingBlockId:i,editingItemIndex:l,setEditingBlockId:c,setEditingItemIndex:d}=useInlineEditing(),[p,u]=React.useState(null),m=React.useRef(null),{clearHighlight:h}=useBlockHighlight(),x=useUpdateBlocksProps(),{selectedLang:g}=useLanguages(),[,f]=useSelectedBlockIds(),b=React.useRef(null),j=i,{blockContent:R,blockType:y}=React.useMemo(()=>{var _;const C=o._type;let w=o[a];const E=runtime.getRegisteredChaiBlock(o._type);return g&&((_=E==null?void 0:E.i18nProps)==null?void 0:_.includes(a))&&lodashEs.has(o,`${a}-${g}`)&&(w=lodashEs.get(o,`${a}-${g}`)),{blockContent:w,blockType:C}},[o,g]),k=React.useCallback(C=>{var E;const w=C||((E=m.current)==null?void 0:E.innerText);x([j],{[a]:w}),u(null),c(null),d(-1),f([]),j&&setTimeout(()=>f([j]),100)},[j,x,c,f,g]),S=web.useDebouncedCallback(C=>{x([j],{[a]:C})},[j,o,x,g],1e3),v=React.useCallback(C=>{C.preventDefault(),j&&(b.current=j),k(),setTimeout(()=>{const w=b.current;b.current=null,f([w])},100)},[f,j,g]);React.useEffect(()=>{var A;if(!j)return;const C=`[data-block-id="${j}"]`,w=l>=0?`[data-block-index="${l}"]`:"",E=r.querySelector(`${C}${w}`);E&&((A=E==null?void 0:E.classList)==null||A.add("sr-only"),u(E))},[j,y,r,l]);const B=React.useMemo(()=>p?(h(),["RichText","Paragraph"].includes(y)?jsxRuntime.jsx(RichTextEditor,{blockContent:R,editingElement:p,onChange:S,onClose:k,onEscape:v}):jsxRuntime.jsx(MemoizedEditor,{editorRef:m,blockContent:R,editingElement:p,onClose:k,onChange:S,onEscape:v})):null,[p,j,y,R,k,g]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[B,n]})},(o,n)=>o.block._id===n.block._id&&o.block.content===n.block.content),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=({asyncProps:o,blockAtom:n,children:a})=>{const{editingBlockId:r,editingItemIndex:i}=useInlineEditing(),[l]=jotai.useAtom(n),c=React.useMemo(()=>runtime.getRegisteredChaiBlock(l._type),[l._type]),{selectedLang:d,fallbackLang:p}=useLanguages(),u=useBlockRuntimeProps(),m=usePageExternalData(),[h]=jotai.useAtom(dataBindingActiveAtom),x=lodashEs.get(c,"component",null),{index:g,key:f}=React.useContext(RepeaterContext),{mode:b}=useEditorMode(),j=jotai.useAtomValue(chaiDesignTokensAtom),R=useIsDragAndDropEnabled(),y=b==="edit",k=useDirectBlockDrag(),S=React.useMemo(()=>h?applyBinding.applyBindingToBlockProps(applyBinding.applyLanguage(l,d,c),m,{index:g,key:f}):applyBinding.applyLanguage(l,d,c),[l,d,c,m,h,g,f]),v=React.useMemo(()=>applyBinding.getBlockTagAttributes(l,!0,j),[l,applyBinding.getBlockTagAttributes,j]),B=React.useMemo(()=>u(l._id,applyBinding.getBlockRuntimeProps(l._type)),[l._id,l._type,u,applyBinding.getBlockRuntimeProps]),C=React.useMemo(()=>{const P={"data-block-id":l._id,"data-block-type":l._type,"data-block-index":g};return y&&R?{...P,draggable:!r,onMouseDown:k.onMouseDown,onDragStart:k.onDragStart,onDragEnd:k.onDragEnd}:P},[l._id,l._type,g,y,R,k,r]),w=React.useMemo(()=>({blockProps:C,inBuilder:b==="edit",lang:d||p,...S,...v,...B,...o}),[b,C,d,p,S,v,B,o]),E=React.useMemo(()=>!CORE_BLOCKS.includes(l._type),[l._type]),A=React.useMemo(()=>lodashEs.get(l,"_show",!0),[l]);if(lodashEs.isNull(x)||!A)return null;let _=jsxRuntime.jsx(React.Suspense,{children:React.createElement(x,{...w,children:a({_id:l._id,_type:l._type,...lodashEs.isArray(S.repeaterItems)?{repeaterItems:applyBinding.applyLimit(S.repeaterItems,l),$repeaterItemsKey:S.$repeaterItemsKey}:{},...l.partialBlockId?{partialBlockId:l.partialBlockId}:"",...l.globalBlock?{partialBlockId:l.globalBlock}:""})})});const I=r===l._id&&(i===g||g<0)?jsxRuntime.jsx(WithBlockTextEditor,{block:l,children:_}):_;return E?jsxRuntime.jsx(reactErrorBoundary.ErrorBoundary,{fallbackRender:ErrorFallback,children:I}):I},PartialWrapper$1=({children:o,partialBlockId:n})=>{const a=useBuilderProp("gotoPage",lodashEs.noop),{saveState:r}=useSavePage(),{selectedLang:i,fallbackLang:l}=useLanguages(),c=React.useCallback(d=>{if(d.stopPropagation(),r!=="SAVED"){sonner.toast.error("You have unsaved changes. Please save the page first.");return}a({pageId:n,lang:i||l})},[r,a,n,i,l]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[o,jsxRuntime.jsx("div",{className:"partial-overlay group absolute inset-0 z-50",children:jsxRuntime.jsx("div",{onDoubleClick:c,className:"flex h-full w-full items-center justify-center bg-black/10 opacity-0 transition-opacity duration-300 ease-in-out group-hover:opacity-100 group-hover:backdrop-opacity-85",children:jsxRuntime.jsx("p",{className:"rounded-md bg-white px-2 py-1 text-xs",children:"Partial block. Double click to edit."})})})]})},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(PartialWrapper$1,{partialBlockId:o,children:jsxRuntime.jsx(BlocksRenderer,{splitAtoms:r,blocks:a,type:"PartialBlock"})})},BlocksRenderer=({blocks:o,parent:n=null,splitAtoms:a=void 0,type:r=""})=>{const i=useGetBlockAtom(a);let l=React.useMemo(()=>lodashEs.filter(o,d=>lodashEs.has(d,"_id")&&(lodashEs.isEmpty(n)?!d._parent:d._parent===n)),[o,n]);const c=React.useCallback(d=>lodashEs.filter(o,p=>p._parent===d).length>0,[o]);return c&&(r==="Heading"||r==="Paragraph"||r==="Link")&&(l=applyBinding.adjustSpacingInContentBlocks(l)),lodashEs.map(l,d=>{const p=i(d._id);return p?jsxRuntime.jsx(MayBeAsyncPropsWrapper,{block:d,children:u=>jsxRuntime.jsx(BlockRenderer,{blockAtom:p,asyncProps:u,children:({_id:m,_type:h,partialBlockId:x,repeaterItems:g,$repeaterItemsKey:f})=>h==="Repeater"?lodashEs.isArray(g)&&g.map((b,j)=>jsxRuntime.jsx(RepeaterContext.Provider,{value:{index:j,key:f},children:jsxRuntime.jsx(BlocksRenderer,{splitAtoms:a,blocks:o,parent:d._id,type:h})},`${m}-${j}`)):h==="GlobalBlock"||h==="PartialBlock"?jsxRuntime.jsx(jotai.Provider,{store:builderStore,children:jsxRuntime.jsx(PartialBlocksRenderer,{partialBlockId:x})}):c(m)?jsxRuntime.jsx(BlocksRenderer,{splitAtoms:a,blocks:o,parent:d._id,type:h}):null})},d._id):null})},PageBlocksRenderer=()=>{const[o]=useBlocksStore();return jsxRuntime.jsx(BlocksRenderer,{splitAtoms:pageBlocksAtomsAtom,blocks:o})},StaticBlocksRenderer=()=>{const[o]=useBlocksStore(),[n]=jotai.useAtom(canvasRenderKeyAtom),a=lodashEs.isEmpty(o)?null:jsxRuntime.jsx(PageBlocksRenderer,{},n);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:a})},useCanvasScale=o=>{const[n]=useCanvasDisplayWidth(),[,a]=useCanvasZoom(),r=useBuilderProp("htmlDir","ltr"),[i,l]=React.useState({}),c=React.useCallback(()=>{const{width:d,height:p}=o;if(d<n){const u=parseFloat((d/n).toFixed(2).toString());let m={};const h=p*u,x=d*u;p&&(m={height:100+(p-h)/h*100+"%",width:100+(d-x)/x*100+"%"}),l({position:"relative",top:0,transform:`scale(${u})`,transformOrigin:r==="rtl"?"top right":"top left",...m,maxWidth:"none"}),a(u*100)}else l({}),a(100)},[n,o,r,a]);return React.useEffect(()=>{c()},[n,o,a,c]),i},CanvasEventsWatcher=()=>{const[,o]=useSelectedBlockIds(),[n,a]=useSelectedStylingBlocks(),{document:r}=useFrame(),{clearHighlight:i}=useBlockHighlight(),[l]=useSelectedBlockIds(),[c]=jotai.useAtom(treeRefAtom);return React.useEffect(()=>{setTimeout(()=>{if(!lodashEs.isEmpty(n))return;const d=getElementByDataBlockId(r,lodashEs.first(l));if(d){const p=d.getAttribute("data-style-prop");if(p){const u=d.getAttribute("data-style-id"),m=d.getAttribute("data-block-parent");a([{id:u,prop:p,blockId:m}])}}},100)},[r,l,a,n]),React.useEffect(()=>()=>i(),[i]),usePubSub(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_SELECTED,d=>{d&&(!lodashEs.isEmpty(d)&&!lodashEs.includes(l,lodashEs.first(d))&&(c==null||c.closeAll()),o(d))}),usePubSub(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_STYLE_SELECTED,d=>{if(!d)return;const{blockId:p,styleId:u,styleProp:m}=d;p&&(lodashEs.includes(l,p)||c==null||c.closeAll(),a([{id:u,prop:m,blockId:p}]),o([p]))}),usePubSub(CHAI_BUILDER_EVENTS.CLEAR_CANVAS_SELECTION,()=>{i(),o([]),a([])}),null},StaticCanvas=()=>{const[o]=useCanvasDisplayWidth(),[,n]=useHighlightBlockId(),a=React.useRef(null),r=React.useRef(null),[i,l]=React.useState({width:0,height:0}),c=useCanvasScale(i),[,d]=useCanvasIframe(),p=useBuilderProp("loading",!1),u=useBuilderProp("htmlDir","ltr"),{onDragOver:m,onDrop:h,onDragEnd:x}=useDragAndDrop(),g=useDropIndicator(),f=React.useCallback(j=>{l(R=>({...R,width:j}))},[l]);React.useEffect(()=>{if(!r.current)return;const{clientWidth:j,clientHeight:R}=r.current;l({width:j,height:R})},[r,o]);const b=React.useMemo(()=>{let j=IframeInitialContent;return j=j.replace("__HTML_DIR__",u),j},[u]);return jsxRuntime.jsx(ResizableCanvasWrapper,{onMount:f,onResize:f,children:jsxRuntime.jsx("div",{onMouseLeave:()=>setTimeout(()=>n(""),300),className:"relative mx-auto h-full w-full overflow-hidden",onDragOver:m,onDrop:h,onDragEnd:x,ref:r,children:jsxRuntime.jsxs(ChaiFrame,{contentDidMount:()=>d(a.current),ref:a,id:"canvas-iframe",style:{...c,...lodashEs.isEmpty(c)?{width:`${o}px`}:{}},className:"relative mx-auto box-content h-full w-full max-w-full shadow-lg transition-all duration-300 ease-linear",initialContent:b,children:[jsxRuntime.jsx(KeyboardHandler,{}),jsxRuntime.jsx(BlockSelectionHighlighter,{}),jsxRuntime.jsx(HeadTags,{}),jsxRuntime.jsxs(reactWrapBalancer.Provider,{children:[jsxRuntime.jsxs(Canvas,{children:[p?jsxRuntime.jsx("div",{className:"h-full p-4",children:jsxRuntime.jsx(tooltip.Skeleton,{className:"h-full"})}):jsxRuntime.jsx(StaticBlocksRenderer,{}),jsxRuntime.jsx(AddBlockAtBottom,{})]}),jsxRuntime.jsx(CanvasEventsWatcher,{})]}),g.isVisible&&jsxRuntime.jsx("div",{id:"placeholder",className:`pointer-events-none absolute z-[99999] max-w-full transition-all duration-150 ${g.isEmpty?"bg-purple-500/10 outline-dashed outline-2 -outline-offset-2 outline-purple-500":"rounded-full bg-green-500"}`,style:{top:g.top,left:g.left,width:g.width,height:g.height}})]})})})},FallbackError=()=>{const{t:o}=reactI18next.useTranslation();return 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:o("Oops! Something went wrong.")}),jsxRuntime.jsx("p",{children:o("Please try again.")})]})})},CodeEditor$1=React.lazy(()=>Promise.resolve().then(()=>require("./code-editor-CUimilR9.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",children:[jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx(tooltip.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(tooltip.Skeleton,{className:"h-full"}),children:jsxRuntime.jsx(CodeEditor$1,{})}):null]})})},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),{}),IconPicker=React.lazy(()=>Promise.resolve().then(()=>require("./IconPicker-DpQQDK_Q.cjs")).then(o=>({default:o.IconPicker}))),sanitizeSvg=o=>{try{let n=o.replace(/<svg([^>]*)\sheight="[^"]*"([^>]*)>/gi,"<svg$1$2>").replace(/<svg([^>]*)\swidth="[^"]*"([^>]*)>/gi,"<svg$1$2>");return n=n.replace(/>\s+</g,"><"),n=n.replace(/\n/g,"").replace(/\s{2,}/g," "),n=n.replace(/\s+=/g,"=").replace(/=\s+/g,"="),n=n.replace(/<!--[\s\S]*?-->/g,""),n.trim()}catch{return o}},IconPickerField=({value:o,onChange:n,id:a})=>{const{t:r}=reactI18next.useTranslation(),[i,l]=React.useState(o||"");React.useEffect(()=>{l(o||"")},[o]);const c=d=>{l(d);const p=sanitizeSvg(d);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:i?jsxRuntime.jsx("div",{className:"h-6 w-6",dangerouslySetInnerHTML:{__html:i}}):jsxRuntime.jsx("span",{className:"text-xs text-gray-400",children:"SVG"})}),jsxRuntime.jsx("textarea",{id:a,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",value:i,onChange:d=>c(d.target.value),placeholder:r("SVG_code"),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.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx("div",{className:"text-xs text-muted-foreground",children:"Loading..."}),children:jsxRuntime.jsx(IconPicker,{onSelectIcon:c})}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:r("Paste SVG_code")})]})]})},DefaultMediaManager=({close:o,onSelect:n,mode:a="image"})=>{const[r,i]=React.useState(""),[l,c]=React.useState(!1),[d,p]=React.useState(!1),[u,m]=React.useState(null),h=async g=>{if(!g.trim()){p(!1),m("Please enter a URL");return}try{c(!0),m(null),p(!0),m(null)}catch{p(!1),m("Error validating URL")}finally{c(!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(tooltip.Alert,{variant:"destructive",children:[jsxRuntime.jsx(reactIcons.ExclamationTriangleIcon,{className:"h-4 w-4"}),jsxRuntime.jsx(tooltip.AlertDescription,{children:u})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-4",children:[jsxRuntime.jsx(tooltip.Input,{placeholder:x(`Enter ${a} URL`),value:r,onChange:g=>i(g.target.value),onKeyUp:()=>h(r)}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-2",children:[jsxRuntime.jsx(tooltip.Button,{variant:"outline",onClick:o,children:x("Cancel")}),jsxRuntime.jsx(tooltip.Button,{onClick:()=>n({id:"dam-id",url:r,width:600,height:400,description:"This is image description"}),disabled:!d||l,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[i,l]=React.useState(!1),c=useMediaManagerComponent(),d=(...p)=>{a.call(void 0,...p),l(!1)};return jsxRuntime.jsxs(tooltip.Dialog,{open:i,onOpenChange:p=>l(p),children:[jsxRuntime.jsx(tooltip.DialogTrigger,{asChild:!0,children:n}),jsxRuntime.jsxs(tooltip.DialogContent,{className:"flex max-h-[90vh] max-w-7xl border-border md:w-fit",children:[jsxRuntime.jsx(tooltip.DialogTitle,{className:"sr-only",children:"Media Manager"}),jsxRuntime.jsx("div",{className:"h-full w-full",children:c?jsxRuntime.jsx(c,{close:()=>l(!1),onSelect:d,mode:r,assetId:o}):null})]})]})};MediaManagerModal.displayName="MediaManagerModal";const PLACEHOLDER_IMAGE="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTAwIiBoZWlnaHQ9IjQwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZjNmNGY2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCwgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNiIgZmlsbD0iI2Q1ZDdkYSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPkltYWdlIFBsYWNlaG9sZGVyPC90ZXh0Pjwvc3ZnPg==",getFileName=o=>{var i;if(!o||lodashEs.startsWith(o,"data"))return"";const n=((i=o.split("/").pop())==null?void 0:i.split("?")[0])||"";return[".jpg",".jpeg",".png",".gif",".webp",".svg",".bmp",".ico",".avif"].some(l=>n.toLowerCase().endsWith(l))?n:""},ImagePickerField=({value:o,onChange:n,id:a,onBlur:r})=>{const{t:i}=reactI18next.useTranslation(),{selectedLang:l}=useLanguages(),c=useSelectedBlock(),d=useUpdateBlocksProps(),p=usePageExternalData(),u=a.split(".").pop()||"",m=l?`_${u}Id-${l}`:`_${u}Id`,h=lodashEs.isEmpty(l)&&(c==null?void 0:c._type)==="Image"&&lodashEs.has(c,"assetId"),x=lodashEs.get(c,m,h?c==null?void 0:c.assetId:""),g=React.useMemo(()=>{if(!o||!c||!/\{\{.*?\}\}/.test(o))return o;const k={...c,[u]:o},S=applyBinding.applyBindingToBlockProps(k,p,{index:-1,key:""});return lodashEs.get(S,u,o)},[o,c,p,u]),f=!!x||g!==PLACEHOLDER_IMAGE,b=y=>{const k=lodashEs.isArray(y)?lodashEs.first(y):y;if(k){n(k==null?void 0:k.url);const S=k==null?void 0:k.width,v=k==null?void 0:k.height,B=m.includes("mobile");if(c!=null&&c._id){const C={...S&&{[B?"mobileWidth":"width"]:S},...v&&{[B?"mobileHeight":"height"]:v},...k.description&&{alt:k.description}};if(lodashEs.set(C,m,k.id),lodashEs.isEmpty(C))return;d([c._id],C)}}},j=React.useCallback(()=>{if(n(PLACEHOLDER_IMAGE),c!=null&&c._id){const y={},k=m.includes("mobile");lodashEs.set(y,m,""),lodashEs.set(y,k?"mobileWidth":"width",""),lodashEs.set(y,k?"mobileHeight":"height",""),d([c._id],y)}},[n,c==null?void 0:c._id,d,m]),R=getFileName(g);return jsxRuntime.jsxs("div",{className:"mt-1.5 flex items-start gap-x-3",children:[g?jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsx("img",{src:g,className:"h-14 w-14 overflow-hidden rounded-md border border-border object-cover transition duration-200 "+(x&&x!==""?"cursor-pointer group-hover:blur-sm":""),alt:""}),f&&jsxRuntime.jsx("button",{type:"button",onClick:j,className:"absolute -right-2 -top-2 z-20 rounded-full bg-destructive p-1 text-destructive-foreground hover:bg-destructive/90",children:jsxRuntime.jsx(reactIcons.Cross1Icon,{className:"h-3 w-3"})}),x&&x!==""&&jsxRuntime.jsx(MediaManagerModal,{onSelect:b,assetId:x,children:jsxRuntime.jsx("button",{type:"button",className:"absolute inset-0 z-10 flex cursor-pointer items-center justify-center bg-black/10 opacity-0 transition duration-200 group-hover:bg-black/30 group-hover:opacity-100",children:jsxRuntime.jsx(reactIcons.Pencil2Icon,{className:"h-4 w-4 text-white"})})})]}):jsxRuntime.jsx(MediaManagerModal,{onSelect:b,mode:"image",assetId:x,children:jsxRuntime.jsx("div",{className:"h-14 w-14 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("p",{className:"max-w-[250px] truncate pr-2 text-xs text-gray-400",children:R}),jsxRuntime.jsx(MediaManagerModal,{onSelect:b,assetId:"",children:jsxRuntime.jsx("small",{className:"h-6 mb-1 w-full cursor-pointer rounded-md bg-secondary px-1 py-1 text-center text-xs text-secondary-foreground hover:bg-secondary/80",children:!lodashEs.isEmpty(g)&&g!==PLACEHOLDER_IMAGE?i("Replace image"):i("Choose image")})}),jsxRuntime.jsx("div",{className:"text-center text-xs text-gray-400",children:"OR"})]}),jsxRuntime.jsx("input",{id:a,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",type:"url",className:"h-6 text-xs",placeholder:i("Enter image URL"),value:o===PLACEHOLDER_IMAGE?"":o,onBlur:({target:{value:y}})=>r(a,y),onChange:y=>n(y.target.value)})]})]})},PathDropdown=({data:o,onSelect:n,dataType:a})=>{const[r,i]=React.useState([]),[l,c]=React.useState(o),d=h=>Array.isArray(h)?"array":typeof h=="object"&&h!==null?"object":"value",p=React.useCallback(h=>{const x=g=>a==="value"?g==="value"||g==="object":a==="array"?g==="array":g===a;h.type==="object"?(i(g=>[...g,h.key]),c(h.value)):x(h.type)&&n([...r,h.key].join("."),a)},[r,n,a]),u=React.useCallback(()=>{if(r.length>0){const h=r.slice(0,-1);i(h),c(h.reduce((x,g)=>x[g],o))}},[r,o]),m=React.useMemo(()=>l?Object.entries(l).map(([h,x])=>({key:h,value:x,type:d(x)})).filter(h=>!lodashEs.startsWith(h.key,applyBinding.REPEATER_PREFIX)&&h.key.includes("/")?!1:a==="value"?h.type==="value"||h.type==="object":a==="array"?h.type==="array"||h.type==="object":a==="object"?h.type==="object":!0):[],[l,a]);return jsxRuntime.jsxs(tooltip.Command,{className:"fields-command",children:[jsxRuntime.jsx(tooltip.CommandInput,{className:"border-none",placeholder:"Search..."}),jsxRuntime.jsxs(tooltip.CommandList,{children:[jsxRuntime.jsx(tooltip.CommandEmpty,{children:i18n.t("No option found.")}),jsxRuntime.jsxs(tooltip.CommandGroup,{children:[r.length>0&&jsxRuntime.jsxs(tooltip.CommandItem,{onSelect:u,className:"flex items-center text-sm",children:[jsxRuntime.jsx(reactIcons.ChevronLeftIcon,{className:"mr-2 h-4 w-4"}),i18n.t("Back")]}),m.map(h=>jsxRuntime.jsxs(tooltip.CommandItem,{value:h.key,disabled:!1,onSelect:()=>p(h),className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"flex items-center gap-x-2",children:[lodashEs.startsWith(h.key,applyBinding.REPEATER_PREFIX)?jsxRuntime.jsx(reactIcons.LoopIcon,{}):lodashEs.startsWith(h.key,applyBinding.COLLECTION_PREFIX)?jsxRuntime.jsx(reactIcons.IdCardIcon,{}):null,lodashEs.startsWith(h.key,applyBinding.REPEATER_PREFIX)?i18n.t("Repeater Data"):lodashEs.startsWith(h.key,applyBinding.COLLECTION_PREFIX)?h.key.replace(applyBinding.COLLECTION_PREFIX,""):h.key]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[a==="object"&&h.type==="object"&&jsxRuntime.jsx(tooltip.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 hover:bg-primary hover:text-primary-foreground",onClick:x=>{x.stopPropagation(),n([...r,h.key].join("."),a)},children:i18n.t("Select")}),h.type==="object"&&jsxRuntime.jsx("div",{className:"cursor-pointer rounded p-1 hover:bg-muted",children:jsxRuntime.jsx(reactIcons.ChevronRightIcon,{className:"h-4 w-4 opacity-50"})})]})]},h.key))]})]})]})};function NestedPathSelector({data:o,onSelect:n,dataType:a="value"}){const[r,i]=React.useState(!1),l=useBuilderProp("collections",[]),c=React.useMemo(()=>a==="array"?{...l.map(p=>p.id).reduce((p,u)=>({...p,[applyBinding.COLLECTION_PREFIX+u]:[]}),{}),...o}:o,[o,l,a]);return jsxRuntime.jsxs(tooltip.Popover,{open:r,onOpenChange:i,children:[jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(tooltip.PopoverTrigger,{asChild:!0,children:jsxRuntime.jsx(tooltip.Button,{size:"sm",variant:"ghost",className:"h-5 rounded-sm px-1 py-0 text-[9px] text-muted-foreground",role:"combobox","aria-expanded":r,children:jsxRuntime.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24px",height:"24px",viewBox:"0 0 24 24",fill:"none",children:jsxRuntime.jsx("path",{d:"M9.5 5H9C7.89543 5 7 5.89543 7 7V9C7 10 6.4 12 4 12C5 12 7 12.6 7 15V17.0002C7 18.1048 7.89543 19 9 19H9.5M14.5 5H15C16.1046 5 17 5.89543 17 7V9C17 10 17.6 12 20 12C19 12 17 12.6 17 15V17.0002C17 18.1048 16.1046 19 15 19H14.5",stroke:"#000000",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2"})})})})}),jsxRuntime.jsx(tooltip.TooltipContent,{children:i18n.t("Add field")})]}),jsxRuntime.jsx(tooltip.PopoverContent,{className:"z-[1000]! relative mr-3 w-[300px] p-0",children:jsxRuntime.jsx(PathDropdown,{data:c,onSelect:(d,p)=>{n(d,p),i(!1)},dataType:a})})]})}const DataBindingSelector=({schema:o,onChange:n,id:a,formData:r})=>{const i=usePageExternalData(),l=useBuilderProp("flags.dataBinding",!0),c=useSelectedBlockHierarchy(),d=useSelectedBlock(),p=React.useMemo(()=>{if(c.length===1)return"";const h=c.find(f=>f._type==="Repeater"),g=lodashEs.get(h,"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1");return`${applyBinding.REPEATER_PREFIX}${lodashEs.startsWith(g,applyBinding.COLLECTION_PREFIX)?`${g}/${h._id}`:g}`},[c]),u=React.useMemo(()=>lodashEs.first(lodashEs.get(i,p.replace(applyBinding.REPEATER_PREFIX,""),[])),[p,i]),m=React.useCallback((h,x)=>{if(h=lodashEs.isEmpty(p)?h:h.replace(`${p}`,"$index"),x==="array"||x==="object"){n(`{{${h}}}`,{},a);return}const g=R=>/[.,!?;:]/.test(R),f=(R,y,k)=>{let S="",v="";const B=y>0?R[y-1]:"",C=y<R.length?R[y]:"";return y>0&&(B==="."||!g(B)&&B!==" ")&&(S=" "),y<R.length&&!g(C)&&C!==" "&&(v=" "),{text:S+k+v,prefixLength:S.length,suffixLength:v.length}},b=document.getElementById(a);if(!b)return;const j=document.getElementById(`chai-rte-${a}`)||document.getElementById(`chai-rte-modal-${a}`);if(j&&(j.querySelector(".ProseMirror")||j.__chaiRTE)){const R=j.__chaiRTE;if(R){const y=`{{${h}}}`;R.commands.focus();const{from:k,to:S}=R.state.selection;if(k!==S)R.chain().deleteSelection().insertContent(y).run();else{const{state:B}=R,C=B.selection.from,w=B.doc.textBetween(Math.max(0,C-1),C),E=B.doc.textBetween(C,Math.min(C+1,B.doc.content.size));let A="";C>0&&w!==" "&&!g(w)&&(A=" ");let _="";E&&E!==" "&&!g(E)&&(_=" "),R.chain().insertContent(A+y+_).run()}setTimeout(()=>n(R.getHTML(),{},a),100);return}}else{const R=b,y=R.selectionStart||0,k=R.value||"",S=R.selectionEnd||y;if(S>y){const E=`{{${h}}}`,{text:A}=f(k,y,E),_=k.slice(0,y)+A+k.slice(S);n(_,{},a);return}const B=`{{${h}}}`,{text:C}=f(k,y,B),w=k.slice(0,y)+C+k.slice(y);n(w,{},a)}},[a,n,r,d==null?void 0:d._id,p]);return l?jsxRuntime.jsx(NestedPathSelector,{data:{...u&&{[p]:u},...i},onSelect:m,dataType:o.binding==="array"?"array":"value"}):null},PageTypeField=({href:o,pageTypes:n,onChange:a})=>{var w;const{t:r}=reactI18next.useTranslation(),i=useBuilderProp("searchPageTypeItems",(E,A)=>[]),[l,c]=React.useState(!1),[d,p]=React.useState(!1),[u,m]=React.useState("page"),[h,x]=React.useState(""),[g,f]=React.useState([]),[b,j]=React.useState(-1),R=React.useRef(null),y=(w=n==null?void 0:n.find(E=>E.key===u))==null?void 0:w.name;React.useEffect(()=>{if(x(""),f([]),j(-1),p(!1),!o||l||!lodashEs.startsWith(o,"pageType:"))return;const E=lodashEs.split(o,":"),A=lodashEs.get(E,1,"page")||"page";m(A),(async()=>{const _=await i(A,[lodashEs.get(E,2,"page")]);_&&Array.isArray(_)&&x(lodashEs.get(_,[0,"name"],""))})()},[o]);const k=web.useDebouncedCallback(async E=>{if(lodashEs.isEmpty(E))f([]);else{const A=await i(u,E);f(A)}c(!1),j(-1)},[u],300),S=E=>{const A=["pageType",u,E.id];A[1]&&(a(A.join(":")),x(E.name),p(!1),f([]),j(-1))},v=E=>{switch(E.key){case"ArrowDown":E.preventDefault(),j(A=>A<g.length-1?A+1:A);break;case"ArrowUp":E.preventDefault(),j(A=>A>0?A-1:A);break;case"Enter":if(E.preventDefault(),g.length===0)return;b>=0&&S(g[b]);break;case"Escape":E.preventDefault(),B();break}};React.useEffect(()=>{if(b>=0&&R.current){const E=R.current.children[b];E==null||E.scrollIntoView({block:"nearest"})}},[b]);const B=()=>{x(""),f([]),j(-1),p(!1),a("")},C=E=>{x(E),p(!lodashEs.isEmpty(E)),c(!0),k(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:v,placeholder:r(`Search ${y??""}`),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:B,className:"text-gray-400 hover:text-gray-600",title:r("Clear search"),children:jsxRuntime.jsx(reactIcons.Cross1Icon,{className:"h-4 w-4"})})})]}),(l||!lodashEs.isEmpty(g)||d&&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:l?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"})]}):d&&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:R,children:lodashEs.map(g==null?void 0:g.slice(0,20),(E,A)=>jsxRuntime.jsxs("li",{onClick:()=>S(E),className:`cursor-pointer p-2 text-xs ${o!=null&&o.includes(E.id)?"bg-blue-200":A===b?"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,name:r})=>{const{t:i}=reactI18next.useTranslation(),{type:l="pageType",href:c="",target:d="self"}=n??{},p=useBuilderProp("pageTypes",[]),{selectedLang:u,fallbackLang:m,languages:h}=useLanguages(),x=React.useMemo(()=>lodashEs.isEmpty(h)?"":lodashEs.isEmpty(u)?m:u,[h,u,m]),g=React.useMemo(()=>lodashEs.get(LANGUAGES,x,x),[x]),f=l==="pageType"&&lodashEs.isEmpty(p)?"url":l;return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"flex items-center justify-between gap-x-2 text-xs font-medium",children:[jsxRuntime.jsxs("span",{children:[(o==null?void 0:o.title)??"Link",jsxRuntime.jsx("span",{className:"pl-1 text-[9px] text-zinc-400",children:g})]}),jsxRuntime.jsx(DataBindingSelector,{schema:o,onChange:b=>{a({...n,href:b,...f==="pageType"?{type:"url"}:{}})},id:`root.${r}.href`,formData:n})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxRuntime.jsx("select",{name:"type",value:l,onChange:b=>a({...n,type:b.target.value}),children:lodashEs.map([...lodashEs.isEmpty(p)?[]:[{const:"pageType",title:i("Goto Page")}],{const:"url",title:i("Open URL")},{const:"email",title:i("Compose Email")},{const:"telephone",title:i("Call Phone")},{const:"scroll",title:i("Scroll to element")}],b=>jsxRuntime.jsx("option",{value:b.const,children:b.title},b.const))}),f==="pageType"&&!lodashEs.isEmpty(p)?jsxRuntime.jsx(PageTypeField,{href:c,pageTypes:p,onChange:b=>a({...n,href:b})}):null,jsxRuntime.jsx("input",{id:`root.${r}.href`,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",name:"href",type:"text",className:f==="pageType"?"!hidden":"",value:c,onChange:b=>a({...n,href:b.target.value}),placeholder:i(l==="url"?"Enter URL":l==="scroll"?"#ElementID":"Enter details")}),f==="url"&&jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 text-muted-foreground",children:[jsxRuntime.jsx("input",{id:`root.${r}.target`,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:i("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(reactIcons.PlusIcon,{className:"h-4 w-4"})," Add Column"]})})},RTEModal=React.lazy(()=>Promise.resolve().then(()=>require("./rte-widget-modal-Cr2Sx0uo.cjs"))),RichTextEditorFieldComp=({blockId:o,id:n,placeholder:a,value:r,onChange:i,onBlur:l})=>{const c=React.useRef(null),[d,p]=React.useState(!1),u=useRTEditor({blockId:o,value:r,placeholder:a,onBlur:({editor:x})=>{const g=x==null?void 0:x.getHTML();l(n,g)},onUpdate:({editor:x})=>{const g=x==null?void 0:x.getHTML();i(g)}});React.useEffect(()=>{c.current&&u&&(c.current.__chaiRTE=u)},[o,u]);const m=()=>{p(!1)},h=jsxRuntime.jsxs("div",{id:`chai-rte-${n}`,ref:c,className:"mt-1 rounded-md border border-input",children:[jsxRuntime.jsx(RteMenubar,{editor:u,onExpand:()=>p(!0)}),jsxRuntime.jsx(react.EditorContent,{editor:u,id:n,placeholder:a,className:`overflow-auto ${d?"max-h-[500px] min-h-[400px]":"max-h-[200px] min-h-[100px]"}`},n)]});return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[d&&jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx("div",{children:"Loading..."}),children:jsxRuntime.jsx(RTEModal,{isOpen:d,onClose:m,editor:u,rteElement:h})}),d?jsxRuntime.jsx("div",{children:"Open in modal"}):jsxRuntime.jsx("div",{className:"relative",children:h})]})},RichTextEditorField=o=>{const{editingBlockId:n}=useInlineEditing(),[a,r]=React.useState(null),i=useSelectedBlock(),l=i==null?void 0:i._id;return React.useEffect(()=>{r(l)},[l]),a&&a!==n?jsxRuntime.jsx(RichTextEditorFieldComp,{...o,blockId:a},a):null},SliderField=({formData:o,onChange:n})=>{const[a]=useBlocksStore(),r=useSelectedBlock(),i=useWrapperBlock(),{addCoreBlock:l}=useAddBlock(),[,c]=useSelectedBlockIds();if(!r&&!i)return null;const d=(r==null?void 0:r._type)==="Slider"?r:i,p=lodashEs.find(a,{_parent:d==null?void 0:d._id,_type:"Slides"});if(!p)return null;const u=lodashEs.filter(a,{_parent:p==null?void 0:p._id,_type:"Slide"}),m=(o==null?void 0:o.currentSlide)||lodashEs.get(u,"0._id");React.useEffect(()=>{(r==null?void 0:r._type)==="Slide"&&(o==null?void 0:o.currentSlide)!==(r==null?void 0:r._id)&&n({...o,currentSlide:r==null?void 0:r._id})},[r]),React.useEffect(()=>{u!=null&&u.length&&!lodashEs.find(u,{_id:o==null?void 0:o.currentSlide})&&n({...o,currentSlide:lodashEs.get(u,"0._id")})},[o,u]);const h=()=>{const f=lodashEs.findIndex(u,{_id:m});if(f>-1){const b=(f+1)%u.length,j=lodashEs.get(u,[b,"_id"]);if(!j)return;n({...o,currentSlide:j}),c([j])}},x=()=>{const f=lodashEs.findIndex(u,{_id:m});if(f>-1){const b=(f-1+u.length)%u.length,j=lodashEs.get(u,[b,"_id"]);if(!j)return;n({...o,currentSlide:j}),c([j])}},g=()=>{const f=l({styles:"#styles:,h-full w-full min-w-full",type:"Slide"},p==null?void 0:p._id),b=f==null?void 0:f._id;b&&(n({...o,currentSlide:b}),c([b]))};return jsxRuntime.jsxs("div",{className:"space-y-1.5 px-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 pb-2 text-[12px]",children:[jsxRuntime.jsx("button",{onClick:x,className:"rounded bg-gray-200 p-1.5 hover:opacity-80",children:jsxRuntime.jsx(reactIcons.ChevronLeftIcon,{className:"h-3 w-3"})}),jsxRuntime.jsx("div",{className:"whitespace-nowrap text-center text-[10px] text-slate-500",children:m?jsxRuntime.jsxs("span",{className:"",children:[jsxRuntime.jsxs("b",{className:"text-[12px]",children:[" ",lodashEs.findIndex(u,{_id:m})+1]}),"/",u.length]}):"-"}),jsxRuntime.jsx("button",{onClick:h,className:"rounded bg-gray-200 p-1.5 hover:opacity-80",children:jsxRuntime.jsx(reactIcons.ChevronRightIcon,{className:"h-3 w-3"})}),jsxRuntime.jsxs("button",{onClick:g,className:"flex w-full items-center justify-center gap-x-1 rounded bg-gray-200 p-1.5 text-xs font-medium leading-tight hover:opacity-80",children:[jsxRuntime.jsx(reactIcons.PlusCircledIcon,{className:"h-3 w-3"}),"Add Slide"]})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 leading-tight",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:!!(o!=null&&o.showSlideButton),onChange:()=>n({...o,showSlideButton:!(o!=null&&o.showSlideButton)}),className:"cursor-pointer"}),jsxRuntime.jsx("label",{htmlFor:"autoplay",className:"mt-0.5 text-[12px]",children:"Show Slide Buttons"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 leading-tight",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:!!(o!=null&&o.showSlideNavbar),onChange:()=>n({...o,showSlideNavbar:!(o!=null&&o.showSlideNavbar)}),className:"cursor-pointer"}),jsxRuntime.jsx("label",{htmlFor:"autoplay",className:"mt-0.5 text-[12px]",children:"Show Slide Navbar"})]}),jsxRuntime.jsx("div",{children:jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 leading-tight",children:[jsxRuntime.jsx("input",{type:"checkbox",checked:!!(o!=null&&o.autoplay),onChange:()=>n({...o,autoplay:!(o!=null&&o.autoplay)}),className:"cursor-pointer"}),jsxRuntime.jsx("label",{htmlFor:"autoplay",className:"mt-0.5 text-[12px]",children:"Autoplay slides"})]}),(o==null?void 0:o.autoplay)&&jsxRuntime.jsxs("div",{className:"pt-0.5 leading-tight",children:[jsxRuntime.jsxs("label",{htmlFor:"interval",className:"whitespace-nowrap text-[9px]",children:["Autoplay Interval ",jsxRuntime.jsx("span",{className:"font-light opacity-80",children:"(in seconds)"})]}),jsxRuntime.jsx("input",{type:"number",id:"interval",name:"interval",placeholder:"0",value:o==null?void 0:o.autoplayInterval,className:"text-xs",pattern:"[0-9]*",onChange:f=>{let b=f.target.value;b.length&&(b=b.replace("-","")),n({...o,autoplayInterval:b})}})]})]})})]})},SourcesField=({formData:o,onChange:n})=>{const a=lodashEs.get(o,"srcsets",[])||[],r=(c,d)=>{const p=c.target.name,u=c.target.value;n({srcsets:lodashEs.map(a,(m,h)=>h===d?{...m,[p]:u}:m)})},i=()=>{n({srcsets:[...a,{}]})},l=c=>{n({srcsets:lodashEs.reject(a,(d,p)=>p===c)})};return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between pb-2",children:[jsxRuntime.jsx("label",{children:"Responsive Video (optional)"}),jsxRuntime.jsx("button",{type:"button",onClick:i,className:"flex items-center gap-x-1 rounded-md border border-blue-500 bg-blue-100 px-2 py-px text-xs text-blue-600 hover:opacity-80",children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-3 w-3"})})]}),jsxRuntime.jsx("div",{className:"space-y-2",children:a.length===0?jsxRuntime.jsx("div",{className:"rounded border border-dashed border-gray-200 p-2 text-xs italic text-gray-500",children:"Add additional sources to create responsive videos"}):lodashEs.map(a,(c,d)=>jsxRuntime.jsxs("div",{className:"group relative space-y-1.5 rounded border border-gray-200 px-2 pb-1.5",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>l(d),className:"absolute -right-px -top-0 -translate-y-1/2 rounded-full bg-red-100 p-1 opacity-0 hover:bg-red-200 group-hover:opacity-100",children:jsxRuntime.jsx(reactIcons.Cross1Icon,{className:"h-2.5 w-2.5 text-red-500"})}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 rounded border",children:[jsxRuntime.jsx("label",{className:"flex !h-6 h-full w-1/4 items-center justify-center bg-gray-200 px-2 !text-[10px] !font-medium",children:"Width"}),jsxRuntime.jsx("input",{name:"width",placeholder:"Enter width (in px)",type:"number",value:lodashEs.get(c,"width"),onChange:p=>r(p,d),className:"!placeholder:text-gray-100 !mt-0 !rounded-none !border-0 !p-0 !text-xs"})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 rounded border",children:[jsxRuntime.jsx("label",{className:"flex !h-6 h-full w-1/4 items-center justify-center bg-gray-200 px-2 !text-[10px] !font-medium",children:"URL"}),jsxRuntime.jsx("input",{name:"url",placeholder:"Enter url",className:"!mt-0 !rounded-none !border-0 !p-0 !text-xs !shadow-none",value:lodashEs.get(c,"url",""),onChange:p=>r(p,d)})]})]},d))})]})},CodeEditor=({id:o,placeholder:n})=>{const{t:a}=reactI18next.useTranslation(),[,r]=useCodeEditor(),i=useSelectedBlock();if(typeof window>"u")return null;const l=o.replace("root.",""),c=lodashEs.get(i,l,""),d=()=>{const p=i==null?void 0:i._id;r({blockId:p,blockProp:l,placeholder:n,initialCode:lodashEs.get(i,l,c)})};return jsxRuntime.jsxs("div",{className:"mt-2 flex flex-col gap-y-1",children:[jsxRuntime.jsx("button",{onClick:d,className:"w-[90%] max-w-full cursor-default truncate text-pretty rounded border border-border bg-background p-2 text-left text-[10px]",children:c.trim().length>0?c.substring(0,46):n||"Eg: <script>console.log('Hello, world!');<\/script>"}),jsxRuntime.jsx(tooltip.Button,{onClick:d,size:"sm",variant:"outline",className:"w-fit",children:a("Open code editor")})]})},CollectionFilterSortField=({id:o,value:n,onChange:a,onBlur:r})=>{const i=useBuilderProp("collections",[]),l=useSelectedBlock(),c=lodashEs.get(l,"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1").replace(applyBinding.COLLECTION_PREFIX,""),d=lodashEs.find(i,{id:c}),p=o==="root.filter"?"filters":"sorts",u=lodashEs.get(d,p,[]);return jsxRuntime.jsx("div",{children:jsxRuntime.jsxs("select",{value:n,onChange:m=>a(m.target.value),onBlur:m=>r(o,m.target.value),children:[jsxRuntime.jsx("option",{value:"",children:"Select"}),u.map(m=>jsxRuntime.jsx("option",{value:m.id,children:m.name},m.id))]})})},JSONFormFieldTemplate=o=>{const{id:n,classNames:a,label:r,children:i,errors:l,help:c,hidden:d,required:p,schema:u,formData:m,onChange:h}=o,{selectedLang:x,fallbackLang:g,languages:f}=useLanguages(),b=React.useMemo(()=>lodashEs.isEmpty(f)?"":lodashEs.isEmpty(x)?g:x,[f,x,g]),j=React.useMemo(()=>lodashEs.get(LANGUAGES,b,b),[b]),R=usePageExternalData(),y=useSelectedBlock(),k=runtime.useRegisteredChaiBlocks(),S=React.useMemo(()=>lodashEs.get(k,[y==null?void 0:y._type,"i18nProps"],[]),[k,y==null?void 0:y._type]),[v,B]=React.useState(null);if(d)return null;if(u.type==="boolean")return jsxRuntime.jsx("div",{className:a,children:i});const w=S==null?void 0:S.includes(n.replace("root.",""));if(u.type==="array"){const _=v===n;return jsxRuntime.jsxs("div",{className:`${a} relative`,children:[u.title&&jsxRuntime.jsx("div",{className:"flex items-center justify-between gap-1",children:jsxRuntime.jsxs("label",{htmlFor:n,onClick:()=>B(_?null:n),className:"flex cursor-pointer items-center gap-x-1 py-1 leading-tight duration-200 hover:bg-slate-100",children:[_?jsxRuntime.jsx(reactIcons.ChevronDownIcon,{className:"h-3 w-3"}):jsxRuntime.jsx(reactIcons.ChevronRightIcon,{className:"h-3 w-3"}),jsxRuntime.jsx(reactIcons.ListBulletIcon,{className:"h-3 w-3"}),jsxRuntime.jsx("span",{className:"leading-tight",children:r})," ",jsxRuntime.jsx(tooltip.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})}),u.description&&jsxRuntime.jsx(tooltip.TooltipProvider,{children:jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactIcons.InfoCircledIcon,{className:"h-3 w-3 text-muted-foreground/70",onClick:I=>I.stopPropagation(),onMouseDown:I=>I.stopPropagation()})}),jsxRuntime.jsx(tooltip.TooltipContent,{className:"max-w-xs",children:u.description})]})})]})}),(m==null?void 0:m.length)===0?jsxRuntime.jsx("div",{className:"h-0 overflow-hidden",children:i}):jsxRuntime.jsxs("div",{className:`${_?"pt-0.5":"h-0 overflow-hidden"}`,children:[i,l,c]})]})}const E=n.replace("root.",""),A=S.includes(E)&&!lodashEs.isEmpty(x)&&lodashEs.isEmpty(m);return jsxRuntime.jsxs("div",{className:a,children:[u.title&&jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsxs("label",{htmlFor:n,className:u.type==="object"?"pb-2":"",children:[r," ",w&&jsxRuntime.jsxs("small",{className:"text-[9px] text-zinc-400",children:[" ",j]}),p&&u.type!=="object"?" *":null]}),u.description&&jsxRuntime.jsx(tooltip.TooltipProvider,{children:jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactIcons.InfoCircledIcon,{className:"h-3 w-3 text-muted-foreground/70"})}),jsxRuntime.jsx(tooltip.TooltipContent,{className:"max-w-xs",children:u.description})]})})]}),!u.enum&&!u.oneOf&&R&&jsxRuntime.jsxs("span",{className:"flex items-center space-x-1",children:[A?jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":"2","stroke-linecap":"round","stroke-linejoin":"round",className:"lucide lucide-triangle-alert-icon lucide-triangle-alert h-3 w-3 text-orange-400",children:[jsxRuntime.jsx("path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3"}),jsxRuntime.jsx("path",{d:"M12 9v4"}),jsxRuntime.jsx("path",{d:"M12 17h.01"})]})}),jsxRuntime.jsxs(tooltip.TooltipContent,{className:"max-w-xs",children:["No translation provided. ",jsxRuntime.jsx("br",{}),"Using default language value."]})]}):null,jsxRuntime.jsx(DataBindingSelector,{schema:u,onChange:_=>{h(_,m,n)},id:n,formData:m})]})]}),i,l,c]})},RepeaterBindingWidget=({value:o,onChange:n})=>{var l;if(!o)return jsxRuntime.jsxs("div",{className:"mt-1 flex items-center gap-2 rounded-md border border-gray-200 bg-gray-50 px-2 py-1.5 text-xs text-gray-500 text-gray-600",children:[jsxRuntime.jsx(reactIcons.FileIcon,{className:"h-4 w-4"})," Choose a collection"]});const a=`{{${applyBinding.COLLECTION_PREFIX}`,r=o==null?void 0:o.startsWith(a);let i=o;return r&&(i=(l=o==null?void 0:o.replace(a,""))==null?void 0:l.replace("}}","")),jsxRuntime.jsx("div",{className:"mt-1 flex flex-col gap-1",children:jsxRuntime.jsxs("div",{className:"flex items-center justify-between gap-2 rounded-md border border-blue-200 bg-blue-50 px-2 py-1 text-xs text-blue-600",children:[jsxRuntime.jsxs("span",{className:"flex max-w-[200px] items-center gap-2",children:[" ",r?jsxRuntime.jsx(reactIcons.IdCardIcon,{className:"h-3 min-h-3 w-3 min-w-3"}):null,jsxRuntime.jsxs(tooltip.Tooltip,{delayDuration:500,children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx("span",{className:"cursor-default truncate",children:i})}),jsxRuntime.jsx(tooltip.TooltipContent,{side:"left",hidden:i.length<50,children:i})]})]}),jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(tooltip.Button,{variant:"ghost",size:"icon",className:"h-5 w-5 rounded-full bg-gray-200 text-gray-900 hover:bg-gray-300",onClick:()=>n(""),children:jsxRuntime.jsx(reactIcons.Cross1Icon,{className:"h-4 w-4"})})}),jsxRuntime.jsx(tooltip.TooltipContent,{side:"left",children:"Remove binding"})]})]})})},CustomAddButton=o=>jsxRuntime.jsx("button",{...o,className:"duration absolute right-2 top-2 cursor-pointer text-blue-400 hover:text-blue-500",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-x-0.5 text-[11px] leading-tight",children:[jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-3 w-3"})," ",jsxRuntime.jsx("span",{children:"Add"})]})}),JSONForm=React.memo(({blockId:o,schema:n,uiSchema:a,formData:r,onChange:i})=>{const{selectedLang:l}=useLanguages(),c=useBlockSettingComponents("widget"),d=useBlockSettingComponents("field"),p=useBlockSettingComponents("template"),u=web.useThrottledCallback(async({formData:m},h)=>{lodashEs.get(m,h)===void 0&&lodashEs.set(m,h,""),i({formData:m},h)},[i,l],400);return jsxRuntime.jsx(RjForm,{widgets:{richtext:RichTextEditorField,icon:IconPickerField,image:ImagePickerField,code:CodeEditor,colCount:RowColField,collectionSelect:CollectionFilterSortField,repeaterBinding:RepeaterBindingWidget,...c},fields:{link:LinkField,slider:SliderField,sources:SourcesField,...d},templates:{FieldTemplate:JSONFormFieldTemplate,ButtonTemplates:{AddButton:CustomAddButton},...p},idSeparator:".",autoComplete:"off",omitExtraData:!1,liveOmit:!1,liveValidate:!1,validator,uiSchema:a,schema:n,formData:r,onChange:({formData:m},h)=>{if(!h||o!==(m==null?void 0:m._id))return;const x=lodashEs.take(h.split("."),2).join(".").replace("root.","");u({formData:m},x)}},l)}),formDataWithSelectedLang=(o,n,a)=>{const r=lodashEs.cloneDeep(o);return lodashEs.forEach(lodashEs.keys(o),i=>{lodashEs.includes(lodashEs.get(a,"i18nProps",[]),i)&&!lodashEs.isEmpty(n)&&(r[i]=lodashEs.get(o,`${i}-${n}`))}),r};function BlockSettings(){const{selectedLang:o}=useLanguages(),n=useSelectedBlock(),a=useUpdateBlocksPropsRealtime(),r=useUpdateBlocksProps(),i=runtime.getRegisteredChaiBlock(n==null?void 0:n._type),l=formDataWithSelectedLang(n,o,i),[c,d]=React.useState(l),[p,u]=React.useState(!1),m=useWrapperBlock(),h=runtime.getRegisteredChaiBlock(m==null?void 0:m._type),x=formDataWithSelectedLang(m,o,h),g=({formData:v},B,C)=>{B&&(c==null?void 0:c._id)===n._id&&r([n._id],{[B]:lodashEs.get(v,B)},C)},f=React.useCallback(lodashEs.debounce(({formData:v},B,C)=>{g({formData:v},B,C),d(v)},1500),[n==null?void 0:n._id,o]),b=({formData:v},B)=>{B&&(a([n._id],{[B]:lodashEs.get(v,B)}),f({formData:v},B,{[B]:lodashEs.get(c,B)}))},j=({formData:v},B)=>{B&&(a([m._id],{[B]:lodashEs.get(v,B)}),f({formData:v},B,{[B]:lodashEs.get(c,B)}))},{schema:R,uiSchema:y}=React.useMemo(()=>{const v=n==null?void 0:n._type;if(!v)return{schema:{},uiSchema:{}};try{const{schema:B,uiSchema:C}=runtime.getBlockFormSchemas(v);if(v==="Repeater"){const w=lodashEs.get(n,"repeaterItems","");lodashEs.startsWith(w,`{{${applyBinding.COLLECTION_PREFIX}`)?(lodashEs.set(C,"filter",{"ui:widget":"collectionSelect"}),lodashEs.set(C,"sort",{"ui:widget":"collectionSelect"})):(lodashEs.set(C,"filter",{"ui:widget":"hidden"}),lodashEs.set(C,"sort",{"ui:widget":"hidden"}))}return{schema:B,uiSchema:C}}catch{return{schema:{},uiSchema:{}}}},[n]),{wrapperSchema:k,wrapperUiSchema:S}=React.useMemo(()=>{if(!m||!(m!=null&&m._type))return{wrapperSchema:{},wrapperUiSchema:{}};const v=m==null?void 0:m._type,{schema:B={},uiSchema:C={}}=runtime.getBlockFormSchemas(v);return{wrapperSchema:B,wrapperUiSchema:C}},[m]);return jsxRuntime.jsxs("div",{className:"no-scrollbar overflow-x-hidden px-px",children:[!lodashEs.isEmpty(m)&&jsxRuntime.jsxs("div",{className:"mb-4 rounded border bg-zinc-100 px-1",children:[jsxRuntime.jsxs("div",{onClick:()=>u(v=>!v),className:"flex cursor-pointer items-center gap-x-1 py-2 text-xs font-medium leading-tight hover:bg-slate-100",children:[p?jsxRuntime.jsx(reactIcons.ChevronDownIcon,{className:"h-4 w-4 text-slate-400"}):jsxRuntime.jsx(reactIcons.ChevronRightIcon,{className:"h-4 w-4 text-slate-400"}),lodashEs.startCase(m._type)," settings"," ",m._name&&jsxRuntime.jsxs("span",{className:"text-[11px] font-light text-slate-400",children:["(",m._name,")"]})]}),jsxRuntime.jsx("div",{className:p?"h-auto":"invisible h-0",children:jsxRuntime.jsx(JSONForm,{blockId:m==null?void 0:m._id,onChange:j,formData:x,schema:k,uiSchema:S})})]}),lodashEs.isEmpty(R)?null:jsxRuntime.jsx(JSONForm,{blockId:n==null?void 0:n._id,onChange:b,formData:l,schema:R,uiSchema:y})]})}const BlockStylingProps=()=>{var g;const o=useSelectedBlock(),[n,a]=useSelectedStylingBlocks(),r=useRemoveClassesFromBlocks(),[i]=useSelectedBlockIds(),{t:l}=reactI18next.useTranslation();if(!o)return null;const c=Object.keys(o).filter(f=>typeof o[f]=="string"&&o[f].startsWith("#styles:")),{reset:d}=useResetBlockStyles(),p=!lodashEs.isEmpty(c)&&c.length>1,u=lodashEs.get(o,(g=n[0])==null?void 0:g.prop,""),{classes:m=""}=applyBinding.getSplitChaiClasses(u)||{},h=m?m.split(" ").filter(f=>!lodashEs.isEmpty(f)):[],x=f=>lodashEs.find(n,b=>b.prop===f);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:p&&jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-1",children:[jsxRuntime.jsxs("label",{htmlFor:"block-styling-props",className:"py-1 text-xs",children:[l("Style element"),":"]}),jsxRuntime.jsx("div",{className:"flex flex-wrap gap-2",children:lodashEs.map(c,f=>jsxRuntime.jsxs(tooltip.Badge,{className:"flex cursor-pointer items-center gap-1 pr-1",variant:x(f)?"default":"secondary",onClick:()=>{a([{id:`${f}-${o._id}`,blockId:o._id,prop:f}])},children:[lodashEs.startCase(f),jsxRuntime.jsxs(tooltip.DropdownMenu,{children:[jsxRuntime.jsx(tooltip.DropdownMenuTrigger,{asChild:!0,children:jsxRuntime.jsx("button",{type:"button",className:"ml-1 rounded-sm p-0.5 hover:bg-blue-300 hover:text-blue-600",onClick:b=>b.stopPropagation(),children:jsxRuntime.jsx(reactIcons.DotsVerticalIcon,{className:"h-3 w-3"})})}),jsxRuntime.jsxs(tooltip.DropdownMenuContent,{side:"bottom",className:"border-border text-xs",children:[jsxRuntime.jsx(tooltip.DropdownMenuItem,{className:"text-xs",onClick:()=>{d(f)},children:l("Reset style")}),jsxRuntime.jsx(tooltip.DropdownMenuItem,{className:"text-xs",onClick:()=>{r(i,h,!0)},children:l("Clear styles")})]})]})]},f))}),jsxRuntime.jsx("div",{className:"my-2 h-[1px] w-full bg-border"})]})})},BlockSettingsContext=React.createContext({setDragData:()=>{}}),getUserInputValues=(o,n)=>{o=o.toLowerCase();let a=o.trim().replace(/ |\+/g,"");if((a==="auto"||a==="none")&&n.includes(a))return{value:"",unit:a};const r=n.length?new RegExp(n.join("|"),"g"):/XXXXXX/g;a=a.replace(r,"");const i=o.match(r),l=i&&i.length>1,c=!lodashEs.isEmpty(a)&&Number.isNaN(Number(a));return l||c?{error:"Invalid value"}:i&&(i[0]==="auto"||i[0]==="none")?{value:i[0],unit:""}:{value:a,unit:i?i[0]:""}},getTwClassValue=o=>{const n=o.startsWith("-")?"-":"",a=o.split("-").pop();if(["auto","none"].includes(a))return{value:"",unit:a};if(a==="px")return{value:"1",unit:"px"};if(a==="screen")return{value:"100",unit:o.indexOf("w-")!==-1?"vw":"vh"};if(a==="full")return{value:"100",unit:"%"};if(lodashEs.includes(o,"skew-"))return{value:`${n}${a}`,unit:"deg"};if(lodashEs.includes(o,"rotate-"))return{value:`${n}${a}`,unit:"deg"};if(lodashEs.includes(o,"opacity-"))return{value:`${a/100}`,unit:"-"};if(lodashEs.includes(o,"duration-")||lodashEs.includes(o,"delay-"))return{value:`${a}`,unit:"ms"};if(lodashEs.includes(o,"translate-")&&!a.includes("/"))return{value:`${n}${`${a/4}`}`,unit:"rem"};if(lodashEs.includes(o,"scale-"))return{value:`${n}${`${a/100}`}`,unit:"-"};if(lodashEs.startsWith(o,"border")){const r=o.match(/border-?(x|y|t|r|b|l)?\d+/g);if(r)return{value:r[0].split("-").pop(),unit:"px"};if(o.match(/border-?(x|y|t|r|b|l)?/g))return{value:"1",unit:"px"}}if(lodashEs.startsWith(o,"max-w-")){if(o==="max-w-screen-sm")return{value:"640",unit:"px"};if(o==="max-w-screen-md")return{value:"768",unit:"px"};if(o==="max-w-screen-lg")return{value:"1024",unit:"px"};if(o==="max-w-screen-xl")return{value:"1280",unit:"px"};if(o==="max-w-screen-2xl")return{value:"1536",unit:"px"};if(a==="xs")return{value:"320",unit:"px"};if(a==="sm")return{value:"384",unit:"px"};if(a==="md")return{value:"448",unit:"px"};if(a==="lg")return{value:"512",unit:"px"};if(a==="xl")return{value:"576",unit:"px"};if(a==="2xl")return{value:"672",unit:"px"};if(a==="3xl")return{value:"768",unit:"px"};if(a==="4xl")return{value:"896",unit:"px"};if(a==="5xl")return{value:"1024",unit:"px"};if(a==="6xl")return{value:"1152",unit:"px"};if(a==="7xl")return{value:"1280",unit:"px"};if(a==="prose")return{value:"65",unit:"ch"}}if(lodashEs.startsWith(o,"text-")){if(a==="xs")return{value:"12",unit:"px"};if(a==="sm")return{value:"14",unit:"px"};if(a==="base")return{value:"16",unit:"px"};if(a==="lg")return{value:"18",unit:"px"};if(a==="xl")return{value:"20",unit:"px"};if(a==="2xl")return{value:"24",unit:"px"};if(a==="3xl")return{value:"30",unit:"px"};if(a==="4xl")return{value:"36",unit:"px"};if(a==="5xl")return{value:"48",unit:"px"};if(a==="6xl")return{value:"60",unit:"px"};if(a==="7xl")return{value:"72",unit:"px"};if(a==="8xl")return{value:"96",unit:"px"};if(a==="9xl")return{value:"128",unit:"px"}}if(lodashEs.startsWith(o,"leading-")){if(a==="none")return{value:"1",unit:"-"};if(a==="tight")return{value:"1.25",unit:"-"};if(a==="snug")return{value:"1.375",unit:"-"};if(a==="normal")return{value:"1.5",unit:"-"};if(a==="relaxed")return{value:"1.625",unit:"-"};if(a==="loose")return{value:"2",unit:"-"}}if(lodashEs.startsWith(o,"tracking-")){if(a==="tighter")return{value:"-0.05",unit:"em"};if(a==="tight")return{value:"-0.025",unit:"em"};if(a==="normal")return{value:"0",unit:"em"};if(a==="wide")return{value:"0.025",unit:"em"};if(a==="wider")return{value:"0.05",unit:"em"};if(a==="widest")return{value:"0.1",unit:"em"}}if(["max","min","fit"].includes(a))return{value:o,unit:"class"};if(a.includes("/")){const[r,i]=lodashEs.map(a.split("/"),l=>parseInt(l,10));return{value:n+(r/i*100).toFixed(2).replace(".00",""),unit:"%"}}return lodashEs.isNumber(parseFloat(a))?{value:`${n+parseFloat(a)*4}`,unit:"px"}:{value:a,unit:"class"}},getClassValueAndUnit=o=>{if(lodashEs.isEmpty(o))return{value:"",unit:""};const n=o.match(/\[.*\]/g);if(n===null)return getValueAndUnitForTWClass(o);const a=lodashEs.get(n,"0","").replace(/\[|\]/g,""),r=o.startsWith("-")?"-":"",i=lodashEs.first(a.match(/\d+.\d+|\d+/g));return{value:`${r}${i}`,unit:a.replace(i,"")}},getValueAndUnitForTWClass=o=>lodashEs.isEmpty(o)?{value:"",unit:""}:getTwClassValue(o),DragStyleButton=({unit:o,currentValue:n,onDrag:a,onDragEnd:r,onDragStart:i,negative:l,cssProperty:c})=>{const{setDragData:d}=React.useContext(BlockSettingsContext);return jsxRuntime.jsx("button",{type:"button",onMouseDown:p=>{const u={onDrag:a,onDragEnd:r,dragging:!0,dragStartY:p.pageY,dragStartValue:`${n}`,dragUnit:o,negative:l,cssProperty:c};i(u),d(u)},color:void 0,className:"relative z-50 ml-1 hidden h-6 cursor-row-resize rounded bg-background/70 px-2 group-hover:inline",children:jsxRuntime.jsx(reactIcons.RowSpacingIcon,{})})},UnitSelection=({onSelect:o,current:n,units:a})=>jsxRuntime.jsx("div",{"data-theme":"light",className:"-m-[7px] -mx-[13px] flex w-9 flex-col",children:a.map(r=>jsxRuntime.jsx(tooltip.Button,{className:"h-max rounded-none px-1 py-1 text-right text-[11px] hover:bg-blue-400",color:n===r?"primary":void 0,size:"sm",onClick:i=>{i.stopPropagation(),o(r)},children:r},r))}),THROTTLE_TIME=50,AdvanceChoices=o=>{const[n,a]=React.useState(!1),[r,i]=React.useState(""),{currentClass:l,onChange:c,classPrefix:d,cssProperty:p,units:u,negative:m}=o,[h,x]=React.useState(p!=null&&p.toLowerCase().includes("width")?"%":u[0]),[g,f]=React.useState(!1),[b,j]=React.useState(""),[R,y]=React.useState(!1),[k,S]=React.useState(!1);React.useEffect(()=>{const{value:E,unit:A}=getClassValueAndUnit(l);if(A===""){i(E),x(p!=null&&p.toLowerCase().includes("width")?"%":lodashEs.first(u));return}x(A),i(A==="class"||lodashEs.isEmpty(E)?"":E)},[l,p,u]);const v=web.useThrottledCallback(E=>c(E),[c],THROTTLE_TIME),B=web.useThrottledCallback(E=>c(E,!1),[c],THROTTLE_TIME),C=React.useCallback((E=!1)=>{const A=getUserInputValues(`${r}`,u);if(lodashEs.get(A,"error",!1)){f(!0);return}const _=lodashEs.get(A,"unit")!==""?lodashEs.get(A,"unit"):h;if(_==="auto"||_==="none"){v(`${d}${_}`);return}if(lodashEs.get(A,"value")==="")return;const P=`${lodashEs.get(A,"value","").startsWith("-")?"-":""}${d}[${lodashEs.get(A,"value","").replace("-","")}${_==="-"?"":_}]`;E?B(P):v(P)},[v,B,r,h,d,u]),w=React.useCallback(E=>{const A=getUserInputValues(`${r}`,u);if(lodashEs.get(A,"error",!1)){f(!0);return}if(E==="auto"||E==="none"){v(`${d}${E}`);return}if(lodashEs.get(A,"value")==="")return;const _=lodashEs.get(A,"unit")!==""?lodashEs.get(A,"unit"):E,P=`${lodashEs.get(A,"value","").startsWith("-")?"-":""}${d}[${lodashEs.get(A,"value","").replace("-","")}${_==="-"?"":_}]`;v(P)},[v,r,d,u]);return jsxRuntime.jsx("div",{className:"flex w-full flex-col",children:jsxRuntime.jsx("div",{className:"flex items-center justify-start",children:h==="class"?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("input",{className:"h-6 w-24 rounded border border-foreground/20 bg-background px-2 py-0.5 text-sm focus-visible:outline-0",readOnly:!0,value:l}),jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx("button",{type:"button",className:"invisible ml-3 mt-1 text-blue-600 group-hover:visible",children:jsxRuntime.jsx(reactIcons.InfoCircledIcon,{})})}),jsxRuntime.jsx(tooltip.TooltipContent,{children:"Current value is using a Tailwind preset class."})]})]}):jsxRuntime.jsxs("div",{className:`group relative flex items-center ${R?"z-auto":""}`,children:[jsxRuntime.jsxs("div",{className:"flex items-center rounded-md border border-border",children:[["none","auto"].indexOf(h)!==-1?null:jsxRuntime.jsx("input",{readOnly:h==="class",onKeyPress:E=>{E.key==="Enter"&&C()},onKeyDown:E=>{if(E.keyCode!==38&&E.keyCode!==40)return;E.preventDefault(),S(!0);const A=lodashEs.parseInt(E.target.value);let _=lodashEs.isNaN(A)?0:A;E.keyCode===38&&(_+=1),E.keyCode===40&&(_-=1);const I=`${_}`,L=`${I.startsWith("-")?"-":""}${d}[${I.replace("-","")}${h==="-"?"":h}]`;B(L)},onKeyUp:E=>{k&&(E.preventDefault(),S(!1))},onBlur:()=>C(),onChange:E=>{f(!1),i(E.target.value)},onClick:E=>{var A;(A=E==null?void 0:E.target)==null||A.select(),a(!1)},value:R?b:r,className:"h-6 w-14 rounded rounded-r-none border border-transparent bg-background pl-2 text-sm focus-visible:outline-0".concat(" ",g?"border-red-500 text-red-500":"border-foreground/20")}),jsxRuntime.jsxs(tooltip.Tooltip,{open:n,delayDuration:100,children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("button",{type:"button",onClick:()=>a(!n),className:"flex h-6 cursor-pointer items-center gap-x-1 rounded rounded-l-none bg-background p-px px-1 text-[11px] uppercase",children:[jsxRuntime.jsx("span",{className:`inline-block ${u.length===1?"px-2 font-semibold":""}`,children:h}),u.length>1?jsxRuntime.jsx(reactIcons.TriangleDownIcon,{}):null]})}),jsxRuntime.jsx(tooltip.TooltipContent,{className:"bg-background",children:jsxRuntime.jsx(UnitSelection,{units:u,current:h,onSelect:E=>{a(!1),x(E),w(E)}})})]})]}),["none","auto"].indexOf(h)!==-1||R?null:jsxRuntime.jsx(DragStyleButton,{onDragStart:()=>y(!0),onDragEnd:E=>{if(j(()=>""),y(!1),lodashEs.isEmpty(E))return;const A=`${E}`,I=`${A.startsWith("-")?"-":""}${d}[${A.replace("-","")}${h==="-"?"":h}]`;v(I)},onDrag:E=>{if(lodashEs.isEmpty(E))return;j(E);const A=`${E}`,I=`${A.startsWith("-")?"-":""}${d}[${A.replace("-","")}${h==="-"?"":h}]`;B(I)},currentValue:r,unit:h,negative:m,cssProperty:p})]})})})},StyleContext=React.createContext({canReset:!1,canChange:!0}),BlockStyleProvider=({children:o,canReset:n=!1,canChange:a=!0})=>jsxRuntime.jsx(StyleContext.Provider,{value:{canReset:n,canChange:a},children:o}),DropDownChoices=({label:o,property:n,onChange:a})=>{const{getClasses:r}=useTailwindClassList(),i=r(n),l=useCurrentClassByProperty(n),c=React.useMemo(()=>lodashEs.get(l,"cls",""),[l]),{canChange:d}=React.useContext(StyleContext),p=/\[.*\]/g.test(c);return jsxRuntime.jsx("div",{className:o?"w-full rounded":"grow",children:p?jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx(tooltip.Input,{className:"w-[70%] rounded py-1",readOnly:!0,value:c}),jsxRuntime.jsxs(tooltip.Tooltip,{delayDuration:100,children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx("button",{type:"button",className:"invisible ml-3 mt-1 text-blue-600 group-hover:visible",children:jsxRuntime.jsx(reactIcons.InfoCircledIcon,{})})}),jsxRuntime.jsx(tooltip.TooltipContent,{children:"Current value is using a Tailwind arbitrary value."})]})]}):jsxRuntime.jsx(DropDown,{rounded:o,onChange:u=>a(u,n),selected:c,options:i,disabled:!d})})};function DropDown({selected:o,onChange:n,rounded:a=!1,options:r,disabled:i=!1}){const l=o.replace(/.*:/g,"").trim(),{undo:c,redo:d}=useUndoManager();return jsxRuntime.jsxs("select",{disabled:!r.length||i,className:`${a?"rounded-md border border-border":"border-0"} disable:bg-gray-500 h-full w-full truncate rounded bg-background px-2 py-1 text-xs outline-none disabled:cursor-not-allowed`,onChange:p=>n(p.target.value),onKeyDown:p=>{p.ctrlKey&&(p.key==="z"&&c(),p.key==="y"&&d())},value:l,children:[jsxRuntime.jsx("option",{className:"bg-transparent",value:""}),r.map((p,u)=>jsxRuntime.jsx("option",{className:"bg-transparent",value:p,children:p},`option-${u}`))]})}const COLOR_PROP={backgroundColor:"bg",textColor:"text",borderColor:"border",boxShadowColor:"shadow",outlineColor:"outline",divideColor:"divide",fromColor:"from",viaColor:"via",toColor:"to",ringColor:"ring",ringOffsetColor:"ring-offset"},ColorChoice=({property:o,onChange:n})=>{const a=useCurrentClassByProperty(o),r=React.useMemo(()=>lodashEs.get(a,"cls",""),[a]),{canChange:i}=React.useContext(StyleContext),[l,c]=React.useState([]),[d,p]=React.useState({color:"",shade:""}),u=r.split("-"),m=lodashEs.get(u,"1",""),h=lodashEs.get(u,"2",""),x=React.useCallback(b=>{["current","inherit","transparent","black","white"].includes(b)?(c([]),p({color:b})):(c(["50","100","200","300","400","500","600","700","800","900"]),p(j=>({...j,color:b,shade:j.shade?j.shade:"500"})))},[c,p]);React.useEffect(()=>{if(["current","inherit","transparent","black","white"].includes(m))return c([]);c(["50","100","200","300","400","500","600","700","800","900"])},[m]);const g=React.useCallback(b=>{p({color:m,shade:b})},[m]);React.useEffect(()=>{p({color:"",shade:""})},[a]);const{match:f}=useTailwindClassList();return React.useEffect(()=>{const j=`${lodashEs.get(COLOR_PROP,o,"")}-${d.color}${d.shade?`-${d.shade}`:""}`;f(o,j)&&n(j,o)},[f,d,n,o]),jsxRuntime.jsxs("div",{className:"flex flex-row divide-x divide-solid divide-border rounded-lg border border-transparent text-xs",children:[jsxRuntime.jsx("div",{className:"grow text-center",children:jsxRuntime.jsx(DropDown,{disabled:!i,rounded:!0,selected:m,onChange:x,options:["current","transparent","primary","secondary","black","white","slate","gray","zinc","neutral","stone","red","orange","amber","yellow","lime","green","emerald","teal","cyan","sky","blue","indigo","violet","purple","fuchsia","pink","rose"]})}),jsxRuntime.jsx("button",{type:"button",className:"grow text-center",children:jsxRuntime.jsx(DropDown,{rounded:!0,selected:h,disabled:!m||!i,onChange:g,options:l})})]})},EDITOR_ICONS={"not-italic":()=>jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M9 3H11V5H9V11H11V13H5V11H7V5H5V3H9Z",fill:"white"})}),visible:reactIcons.EyeOpenIcon,invisible:reactIcons.EyeClosedIcon,hidden:reactIcons.EyeClosedIcon,gap:reactIcons.BorderAllIcon,gapX:reactIcons.WidthIcon,gapY:reactIcons.HeightIcon,spaceX:reactIcons.WidthIcon,spaceY:reactIcons.HeightIcon,overscroll:reactIcons.BorderAllIcon,overscrollX:reactIcons.WidthIcon,overscrollY:reactIcons.HeightIcon,overflow:reactIcons.BorderAllIcon,overflowX:reactIcons.WidthIcon,overflowY:reactIcons.HeightIcon,top:reactIcons.ArrowUpIcon,right:reactIcons.ArrowRightIcon,bottom:reactIcons.ArrowDownIcon,left:reactIcons.ArrowLeftIcon,inset:reactIcons.BorderAllIcon,insetX:reactIcons.WidthIcon,insetY:reactIcons.HeightIcon,border:reactIcons.BorderAllIcon,borderX:reactIcons.WidthIcon,borderY:reactIcons.HeightIcon,borderTop:reactIcons.ArrowUpIcon,borderRight:reactIcons.ArrowRightIcon,borderBottom:reactIcons.ArrowDownIcon,borderLeft:reactIcons.ArrowLeftIcon,borderRadius:reactIcons.BorderAllIcon,borderRadiusX:reactIcons.WidthIcon,borderRadiusY:reactIcons.HeightIcon,borderRadiusTop:reactIcons.ArrowUpIcon,borderRadiusRight:reactIcons.ArrowRightIcon,borderRadiusBottom:reactIcons.ArrowDownIcon,borderRadiusLeft:reactIcons.ArrowLeftIcon,borderRadiusTopLeft:reactIcons.ArrowTopLeftIcon,borderRadiusTopRight:reactIcons.ArrowTopRightIcon,borderRadiusBottomRight:reactIcons.ArrowBottomRightIcon,borderRadiusBottomLeft:reactIcons.ArrowBottomLeftIcon,divideXWidth:reactIcons.WidthIcon,divideYWidth:reactIcons.HeightIcon,scale:reactIcons.BorderAllIcon,scaleX:reactIcons.WidthIcon,scaleY:reactIcons.HeightIcon,skewX:reactIcons.WidthIcon,skewY:reactIcons.HeightIcon,translateX:reactIcons.WidthIcon,translateY:reactIcons.HeightIcon,padding:reactIcons.BorderAllIcon,paddingX:reactIcons.WidthIcon,paddingY:reactIcons.HeightIcon,paddingTop:reactIcons.ArrowUpIcon,paddingRight:reactIcons.ArrowRightIcon,paddingBottom:reactIcons.ArrowDownIcon,paddingLeft:reactIcons.ArrowLeftIcon,margin:reactIcons.BorderAllIcon,marginX:reactIcons.WidthIcon,marginY:reactIcons.HeightIcon,marginTop:reactIcons.ArrowUpIcon,marginRight:reactIcons.ArrowRightIcon,marginBottom:reactIcons.ArrowDownIcon,marginLeft:reactIcons.ArrowLeftIcon,textLeft:reactIcons.AlignLeftIcon,textCenter:reactIcons.AlignCenterHorizontallyIcon,textRight:reactIcons.AlignRightIcon,textJustify:reactIcons.StretchHorizontallyIcon,italic:reactIcons.FontItalicIcon,underline:reactIcons.UnderlineIcon,overline:reactIcons.OverlineIcon,uppercase:reactIcons.LetterCaseUppercaseIcon,block:()=>jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M2 2H14V14H2V2ZM1 1H15V15H1V1Z",fill:"currentColor"}),jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M7 4H4V12H7V4ZM9 4H12V12H9V4Z",fill:"currentColor"})]}),"float-right":()=>jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("path",{d:"M8 4H16V12H8V4Z",fill:"currentColor"}),jsxRuntime.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M0 4H6V6H0V4ZM0 7H6V9H0V7ZM4 10H0V12H4V10Z",fill:"currentColor"})]}),"float-left":()=>jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("path",{d:"M0 4H8V12H0V4Z",fill:"currentColor"}),jsxRuntime.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M10 4H16V6H10V4ZM10 7H16V9H10V7ZM14 10H10V12H14V10Z",fill:"currentColor"})]}),"float-none":reactIcons.Cross2Icon,fixed:()=>jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M15 2H14V4H13V5H14V6H15V2ZM10 5V4H9V2H1V8H2V5H10ZM7 4V3H5V4H7ZM4 4V3H2V4H4ZM1 13H7V14H1V13Z",fill:"currentColor"}),jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2H10V3H11V6H12V3H13V2H11ZM2 9H1V12H2V11H7V10H2V9ZM15 7H8V14H15V7Z",fill:"currentColor"})]}),absolute:()=>jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M14 2H15V6H14V2ZM9 3V2H1V8H2V3H9ZM7 13H1V14H7V13Z",fill:"currentColor"}),jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2H10V3H11V6H12V3H13V2H11ZM2 9H1V12H2V11H7V10H2V9ZM15 7H8V14H15V7Z",fill:"currentColor"})]}),relative:()=>jsxRuntime.jsx("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M11 2H9V3H11V6H12V3H14V2H11ZM2 8H1V13H2V11H7V10H2V8ZM15 7H8V14H15V7Z",fill:"currentColor"})}),sticky:()=>jsxRuntime.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:[jsxRuntime.jsx("path",{d:"M12.9998 7C13.6558 7 14.2937 6.78498 14.8158 6.38787C15.338 5.99076 15.7156 5.43345 15.8908 4.80128C16.066 4.16912 16.0292 3.49694 15.7859 2.8877C15.5427 2.27846 15.1065 1.76573 14.5441 1.42804C13.9817 1.09034 13.3241 0.946293 12.672 1.01795C12.02 1.08961 11.4094 1.37303 10.9337 1.8248C10.4581 2.27658 10.1436 2.8718 10.0385 3.51932C9.93341 4.16685 10.0434 4.83097 10.3518 5.41L6.88176 8.88C6.80034 8.96122 6.73572 9.05769 6.69158 9.16388C6.64744 9.27008 6.62465 9.38393 6.62451 9.49894C6.62437 9.61395 6.64689 9.72785 6.69077 9.83416C6.73465 9.94046 6.79904 10.0371 6.88026 10.1185C6.96149 10.1999 7.05795 10.2645 7.16415 10.3087C7.27035 10.3528 7.3842 10.3756 7.4992 10.3758C7.61421 10.3759 7.72812 10.3534 7.83442 10.3095C7.94072 10.2656 8.03734 10.2012 8.11876 10.12L11.5888 6.648C12.0088 6.873 12.4888 7 12.9988 7H12.9998Z",fill:"currentColor"}),jsxRuntime.jsx("path",{opacity:"0.6",fillRule:"evenodd",clipRule:"evenodd",d:"M9.535 2H1V14H15V7.465C14.69 7.645 14.355 7.783 14 7.875V13H2V5H9.126C8.86504 3.98486 9.01223 2.90789 9.536 2H9.535ZM7 3V4H5V3H7ZM4 3V4H2V3H4Z",fill:"currentColor"})]}),static:reactIcons.Cross1Icon},IconChoices=({property:o,onChange:n})=>{const{getClasses:a}=useTailwindClassList(),r=a(o),{canChange:i}=React.useContext(StyleContext),l=useCurrentClassByProperty(o),c=React.useMemo(()=>lodashEs.get(l,"cls",""),[l]);return jsxRuntime.jsx("div",{className:"flex grow flex-wrap gap-1",children:lodashEs.map(r,d=>jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx("button",{type:"button",disabled:!i,onClick:()=>n(d,o),className:`cursor-pointer rounded border border-border p-1 disabled:cursor-not-allowed ${c===d?"bg-primary text-white":"disabled:bg-gray-600 disabled:text-gray-400"}`,children:React.createElement(lodashEs.get(EDITOR_ICONS,d,reactIcons.BoxIcon))})}),jsxRuntime.jsx(tooltip.TooltipContent,{children:lodashEs.startCase(lodashEs.toLower(d))})]}))})},RangeChoices=({property:o,onChange:n})=>{const{canReset:a,canChange:r}=React.useContext(StyleContext),i=useCurrentClassByProperty(o),l=React.useMemo(()=>lodashEs.get(i,"cls",""),[i]),{getClasses:c}=useTailwindClassList(),d=c(o,[""]),p=d.indexOf(l)>-1?d.indexOf(l):0,u=/\[.*\]/g.test(l);return jsxRuntime.jsx("div",{className:"flex flex-row divide-x divide-solid divide-border rounded border border-border text-xs",children:u?jsxRuntime.jsx("div",{className:"px-2 py-[5px]",children:l}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("button",{type:"button",className:"hover:bg-bg-gray-700 box-border w-2/12 rounded-bl rounded-tl bg-background px-1 text-center disabled:cursor-not-allowed disabled:bg-gray-600",disabled:!r&&(!a||p-1<0),onClick:()=>n(lodashEs.nth(d,p-1),o),children:jsxRuntime.jsx("span",{className:"flex items-center justify-center",children:jsxRuntime.jsx(reactIcons.MinusIcon,{className:!r&&(!a||p-1<0)?"text-gray-500":"text-black/60 dark:text-white/60"})})}),jsxRuntime.jsx("div",{className:"w-8/12 text-center",children:jsxRuntime.jsx(DropDownChoices,{label:!1,property:o,onChange:n})}),jsxRuntime.jsx("button",{type:"button",className:"hover:bg-bg-gray-700 w-2/12 rounded-br rounded-tr bg-background px-1 text-center disabled:cursor-not-allowed disabled:bg-gray-600",disabled:!r&&(!a||p+1>=d.length),onClick:()=>n(lodashEs.nth(d,p+1),o),children:jsxRuntime.jsx("span",{className:"flex items-center justify-center",children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:!r&&(!a||p+1>=d.length)?"text-gray-500":"text-black/60 dark:text-white/60"})})})]})})},useCurrentClassByProperty=o=>{const n=useSelectedBlockCurrentClasses();return lodashEs.findLast(n,{property:o})},canChangeClass=(o,n)=>{const a={xs:0,sm:1,md:2,lg:3,xl:4,"2xl":5};return a[lodashEs.get(o,"mq","xs")]<=a[n]},CLASS_PREFIXES={width:"w-",height:"h-",minWidth:"min-w-",minHeight:"min-h-",maxWidth:"max-w-",maxHeight:"max-h-",zIndex:"z-",gap:"gap-",gapX:"gap-x-",gapY:"gap-y-",margin:"m-",marginX:"mx-",marginY:"my-",marginTop:"mt-",marginBottom:"mb-",marginLeft:"ml-",marginRight:"mr-",padding:"p-",paddingX:"px-",paddingY:"py-",paddingTop:"pt-",paddingBottom:"pb-",paddingLeft:"pl-",paddingRight:"pr-",spaceX:"space-x-",spaceY:"space-y-",border:"border-",borderTop:"border-t-",borderBottom:"border-b-",borderLeft:"border-l-",borderRight:"border-r-",borderX:"border-x-",borderY:"border-y-",borderRadius:"rounded-",borderRadiusTop:"rounded-t-",borderRadiusRight:"rounded-r-",borderRadiusBottom:"rounded-b-",borderRadiusLeft:"rounded-l-",borderRadiusTopLeft:"rounded-tl-",borderRadiusTopRight:"rounded-tr-",borderRadiusBottomRight:"rounded-br-",borderRadiusBottomLeft:"rounded-bl-",fontSize:"text-",lineHeight:"leading-",letterSpacing:"tracking-",textIndent:"indent-",rotate:"rotate-",duration:"duration-",transitionDelay:"delay-",scale:"scale-",scaleX:"scale-x-",scaleY:"scale-y-",translateX:"translate-x-",translateY:"translate-y-",skewX:"skew-x-",skewY:"skew-y-",top:"top-",bottom:"bottom-",left:"left-",right:"right-",inset:"inset-",insetX:"inset-x-",insetY:"inset-y-",opacity:"opacity-",flexBasis:"basis-"},BREAKPOINTS={xs:"",sm:"640px",md:"768px",lg:"1024px",xl:"1280px","2xl":"1536px"},getBreakpoint=o=>`${o.toUpperCase()} ${BREAKPOINTS[o]?`(${BREAKPOINTS[o]} & up)`:""}`,BlockStyle=o=>{const{t:n}=reactI18next.useTranslation(),{type:a="icons",label:r,property:i,onEmitChange:l=()=>{},units:c,negative:d=!1}=o,[p]=useDarkMode(),[u]=useStylingState(),[,m]=useScreenSizeWidth(),h=useCurrentClassByProperty(i),x=useAddClassesToBlocks(),g=useRemoveClassesFromBlocks(),[f]=useSelectedBlockIds(),b=React.useMemo(()=>lodashEs.get(h,"fullCls",""),[h]),j=React.useCallback((B,C=!0)=>{const w={dark:p,mq:m,mod:u,cls:B,property:i,fullCls:""};(p||u!=="")&&(w.mq="xs");const E=generateFullClsName(w);x(f,[E],C)},[f,p,m,u,i,x]),R=React.useCallback(()=>{g(f,[b],!0)},[f,b,g]),y=React.useMemo(()=>canChangeClass(h,m),[h,m]);React.useEffect(()=>{l(y,h)},[y,l,h]);const[,,k]=useScreenSizeWidth(),S=React.useCallback(B=>{k({xs:400,sm:640,md:800,lg:1024,xl:1420,"2xl":1920}[B])},[k]),v=lodashEs.get(h,"dark",null)===p&&lodashEs.get(h,"mod",null)===u&&lodashEs.get(h,"mq",null)===m;return jsxRuntime.jsx(BlockStyleProvider,{canChange:y,canReset:h&&v,children:jsxRuntime.jsxs("div",{className:"group flex flex-row items-center py-2 first:pt-0 last:pb-0",children:[jsxRuntime.jsx("div",{className:"relative w-[70px] truncate text-xs text-foreground",children:jsxRuntime.jsx("span",{className:`text-[11px] ${h&&!v?"text-foreground":""}`,children:n(r)})}),jsxRuntime.jsxs("div",{className:"flex flex-row items-center",children:[jsxRuntime.jsxs("div",{className:"w-[150px]",children:[a==="arbitrary"?jsxRuntime.jsx(AdvanceChoices,{currentClass:lodashEs.get(h,"cls",""),classPrefix:lodashEs.get(CLASS_PREFIXES,i,""),units:c||[],onChange:j,negative:d,cssProperty:i}):null,a==="icons"&&jsxRuntime.jsx(IconChoices,{property:i,onChange:j}),a==="range"&&jsxRuntime.jsx(RangeChoices,{property:i,onChange:j}),a==="color"&&jsxRuntime.jsx(ColorChoice,{property:i,onChange:j}),a==="dropdown"&&jsxRuntime.jsx(DropDownChoices,{label:r,property:i,onChange:j})]}),jsxRuntime.jsx("div",{className:`w-[30px] cursor-pointer ${b?"visible":"invisible"}`,children:v?jsxRuntime.jsx("button",{type:"button",onClick:()=>R(),title:"Reset",className:"flex px-1.5 text-xs",children:jsxRuntime.jsx(reactIcons.CrossCircledIcon,{className:"h-5 w-5 text-blue-500 hover:opacity-80"})}):y&&h?jsxRuntime.jsxs(tooltip.Tooltip,{delayDuration:100,children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx("button",{type:"button",className:"invisible ml-3 mt-1 rounded-full bg-primary text-white group-hover:visible",children:jsxRuntime.jsx(reactIcons.InfoCircledIcon,{})})}),jsxRuntime.jsx(tooltip.TooltipContent,{children:jsxRuntime.jsx("div",{className:"text-right",children:jsxRuntime.jsxs("div",{children:["Current style is set at ",jsxRuntime.jsxs("span",{className:"font-bold",children:[getBreakpoint(lodashEs.get(h,"mq")),p&&!h.dark?"(Light mode)":""]}),jsxRuntime.jsx("br",{}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>S(lodashEs.get(h,"mq")),className:"block w-full cursor-default text-right font-semibold text-blue-500",children:["Switch to ",lodashEs.get(h,"mq").toUpperCase()]})]})})})]}):null})]})]})})},basicUnits=["px","%","em","rem","ch","vh","vw"],MultipleChoices=({label:o,options:n,borderB:a=!1,borderT:r=!1,type:i="arbitrary",units:l=basicUnits,negative:c=!1})=>{const{t:d}=reactI18next.useTranslation(),[p,u]=React.useState(n[0].key),m=useSelectedBlockCurrentClasses(),h=React.useCallback(x=>lodashEs.map(m,"property").includes(x),[m]);return jsxRuntime.jsxs("div",{className:`mb-2 border-border py-2 first:pt-0 last:pb-0 ${a?"border-b":""} ${r?"border-t":""}`,children:[jsxRuntime.jsxs("div",{className:"flex flex-row text-xs",children:[o&&jsxRuntime.jsx("span",{className:"relative w-[70px] flex-none text-xs text-foreground",children:d(o)}),jsxRuntime.jsx("div",{className:"mb-3 flex grow flex-row flex-wrap gap-x-px",children:n.map(({label:x,key:g},f)=>jsxRuntime.jsx("div",{className:"first:rounded-l last:rounded-r",children:jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("button",{type:"button",onClick:()=>u(g),className:`relative cursor-pointer rounded-full p-1 text-[8px] ${g===p?"bg-[#3E57F0] text-white":"text-gray-600 dark:text-gray-300"}`,children:[React.createElement("div",{className:h(g)?"-bottom-1.5 absolute bg-[#3E57F0] h-[2px] left-0 w-full":""}),React.createElement(lodashEs.get(EDITOR_ICONS,g,reactIcons.BoxIcon),{className:"text-inherit w-3 h-3"})]})}),jsxRuntime.jsx(tooltip.TooltipContent,{children:lodashEs.startCase(lodashEs.toLower(x))})]})},`option-${f}`))})]}),jsxRuntime.jsx("div",{className:"mt-0 flex items-center",children:jsxRuntime.jsx(BlockStyle,{type:i,units:[...l],label:"",property:p,negative:c})})]})},NestedOptions=({heading:o,items:n})=>{const{t:a}=reactI18next.useTranslation(),r=useSelectedBlockCurrentClasses(),i=React.useMemo(()=>{const l=p=>lodashEs.flatten(p.map(u=>u.styleType==="multiple"?lodashEs.map(u.options,"key"):u.property)),c=lodashEs.flatten(n.map(p=>p.styleType==="accordion"?l(p.items):p.styleType==="multiple"?lodashEs.map(p.options,"key"):p.property)),d=lodashEs.map(r,"property");return lodashEs.intersection(c,d).length>0},[r,n]);return jsxRuntime.jsxs("details",{children:[jsxRuntime.jsx("summary",{className:"my-px cursor-default rounded-md bg-gray-50 p-px px-2 text-[11px] text-foreground dark:bg-gray-800",children:jsxRuntime.jsxs("div",{className:"inline",children:[lodashEs.startCase(a(o.toLowerCase())),i?jsxRuntime.jsx("span",{className:`ml-1 mr-2 inline-block h-[8px] w-[8px] rounded-full ${i?"bg-primary":"bg-gray-300"}`}):null]})}),jsxRuntime.jsx("div",{className:"p-2",children:n.map(l=>l.styleType==="multiple"?jsxRuntime.jsx(MultipleChoices,{...l},l.label):jsxRuntime.jsx(BlockStyle,{...l},l.label))})]})},SectionContext=React.createContext({}),StylingGroup=({section:o,showAccordian:n})=>{const{t:a}=reactI18next.useTranslation(),r=useSelectedBlockCurrentClasses(),i=React.useCallback((c=[])=>{const d={};for(let u=0;u<r.length;u++)d[r[u].property]=r[u].cls;let p=!0;for(const u in c)if(!lodashEs.has(d,u)||d[u]!==c[u]){p=!1;break}return p},[r]),l=React.useMemo(()=>({}),[]);return jsxRuntime.jsx(SectionContext.Provider,{value:l,children:n?jsxRuntime.jsxs(tooltip.AccordionItem,{value:o.heading,className:"border-none",children:[jsxRuntime.jsx(tooltip.AccordionTrigger,{className:"border-slate-150 border-t py-2 text-xs",children:jsxRuntime.jsx("div",{className:"flex items-center py-2",children:jsxRuntime.jsx("div",{className:"flex items-center gap-x-2 text-xs font-medium",children:lodashEs.startCase(a(o.heading))})})}),jsxRuntime.jsx(tooltip.AccordionContent,{className:"py-2",children:o.items.map(c=>lodashEs.has(c,"component")?React.createElement(c.component,{key:c.label}):lodashEs.has(c,"styleType")?c.styleType==="multiple"?jsxRuntime.jsx(MultipleChoices,{...c},c.label+"multiple-choices"):c.styleType==="accordion"&&i(c==null?void 0:c.conditions)?jsxRuntime.jsx(NestedOptions,{...c},c.label+"nested-options"):null:jsxRuntime.jsx(BlockStyle,{...c},c.label+"block-style"))})]}):jsxRuntime.jsx("div",{className:"py-2",children:o.items.map((c,d)=>lodashEs.has(c,"component")?React.createElement(c.component,{key:c.label}):lodashEs.has(c,"styleType")?c.styleType==="multiple"?jsxRuntime.jsx(MultipleChoices,{...c},c.label+"multiple-choices"+d):c.styleType==="accordion"&&i(c==null?void 0:c.conditions)?jsxRuntime.jsx(NestedOptions,{...c},c.label+"nested-options"+d):null:jsxRuntime.jsx(BlockStyle,{...c},c.label+"block-style"+d))})})},TabletIcon=({landscape:o=!1,className:n=""})=>jsxRuntime.jsx("svg",{className:commonFunctions.cn("h-3 w-3",o?"rotate-90":"",n),stroke:"currentColor",fill:"currentColor",strokeWidth:"0",viewBox:"0 0 448 512",xmlns:"http://www.w3.org/2000/svg",children:jsxRuntime.jsx("path",{d:"M400 0H48C21.5 0 0 21.5 0 48v416c0 26.5 21.5 48 48 48h352c26.5 0 48-21.5 48-48V48c0-26.5-21.5-48-48-48zM224 480c-17.7 0-32-14.3-32-32s14.3-32 32-32 32 14.3 32 32-14.3 32-32 32zm176-108c0 6.6-5.4 12-12 12H60c-6.6 0-12-5.4-12-12V60c0-6.6 5.4-12 12-12h328c6.6 0 12 5.4 12 12v312z"})}),WEB_BREAKPOINTS=[{title:"Mobile (Base)",content:"Styles set here are applied to all screen unless edited at higher breakpoint",breakpoint:"xs",icon:jsxRuntime.jsx(reactIcons.MobileIcon,{className:"h-4 w-4"}),width:400},{title:"Mobile landscape (SM)",content:"Styles set here are applied at 640px and up unless edited at higher breakpoint",breakpoint:"sm",icon:jsxRuntime.jsx(reactIcons.MobileIcon,{className:"h-4 w-4 rotate-90"}),width:640},{title:"Tablet (MD)",content:"Styles set here are applied at 768px and up",breakpoint:"md",icon:jsxRuntime.jsx(TabletIcon,{}),width:800},{title:"Tablet Landscape (LG)",content:"Styles set here are applied at 1024px and up unless edited at higher breakpoint",breakpoint:"lg",icon:jsxRuntime.jsx(TabletIcon,{landscape:!0}),width:1024},{title:"Desktop (XL)",content:"Styles set here are applied at 1280px and up unless edited at higher breakpoint",breakpoint:"xl",icon:jsxRuntime.jsx(reactIcons.LaptopIcon,{className:"h-4 w-4"}),width:1420},{title:"Large Desktop (2XL)",content:"Styles set here are applied at 1536px and up",breakpoint:"2xl",icon:jsxRuntime.jsx(reactIcons.DesktopIcon,{className:"h-4 w-4"}),width:1920}],BreakpointCard=({canvas:o=!1,openDelay:n=400,tooltip:a=!0,title:r,content:i,currentBreakpoint:l,breakpoint:c,width:d,icon:p,onClick:u,buttonClass:m="",activeButtonClass:h=""})=>{const{t:x}=reactI18next.useTranslation();return a?jsxRuntime.jsxs(tooltip.HoverCard,{openDelay:n,children:[jsxRuntime.jsx(tooltip.HoverCardTrigger,{asChild:!0,children:jsxRuntime.jsx(tooltip.Button,{onClick:()=>u(d),size:"sm",className:commonFunctions.cn("h-7 w-7 rounded-md p-1",c===l?h:m),variant:c===l?"outline":"ghost",children:p})}),jsxRuntime.jsx(tooltip.HoverCardContent,{className:"w-fit max-w-52 border-border",children:jsxRuntime.jsx("div",{className:"flex justify-between space-x-4",children:jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("h4",{className:"text-sm font-semibold",children:x(r)}),o&&jsxRuntime.jsx("p",{className:"text-xs",children:x(i)})]})})})]}):jsxRuntime.jsx(tooltip.Button,{onClick:()=>u(d),size:"sm",className:"h-7 w-7 rounded-md p-1",variant:c===l?"outline":"ghost",children:p})},Breakpoints$1=({openDelay:o=400,canvas:n=!1,tooltip:a=!0,buttonClass:r="",activeButtonClass:i=""})=>{const[l,,c]=useScreenSizeWidth(),[d,p]=useCanvasDisplayWidth(),[u,m]=useSelectedBreakpoints(),h=u,x=m,{t:g}=reactI18next.useTranslation(),f=useBuilderProp("breakpoints",WEB_BREAKPOINTS),b=y=>{h.includes(y)?h.length>2&&x(h.filter(k=>k!==y)):x(k=>[...k,y])},j=y=>{n||c(y),p(y)},R=commonFunctions.getBreakpointValue(n?d:l).toLowerCase();return f.length<4?jsxRuntime.jsx("div",{className:"flex items-center rounded-md",children:lodashEs.map(f,y=>React.createElement(BreakpointCard,{canvas:n,...y,onClick:j,key:y.breakpoint,currentBreakpoint:R}))}):jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between rounded-md",children:[jsxRuntime.jsx("div",{className:"flex items-center",children:lodashEs.map(f.filter(y=>lodashEs.includes(h,lodashEs.toUpper(y.breakpoint))),y=>React.createElement(BreakpointCard,{canvas:n,openDelay:o,tooltip:a,...y,onClick:j,key:y.breakpoint,currentBreakpoint:R,buttonClass:r,activeButtonClass:i}))}),jsxRuntime.jsxs(tooltip.DropdownMenu,{children:[jsxRuntime.jsx(tooltip.DropdownMenuTrigger,{asChild:!0,children:jsxRuntime.jsx("span",{className:"cursor-pointer rounded-md p-1 hover:bg-background",children:jsxRuntime.jsx(reactIcons.ChevronDownIcon,{className:"scale-90 transform"})})}),jsxRuntime.jsxs(tooltip.DropdownMenuContent,{className:"w-56 border-border text-xs",children:[jsxRuntime.jsx(tooltip.DropdownMenuLabel,{children:g("Screen sizes")}),jsxRuntime.jsx(tooltip.DropdownMenuSeparator,{}),lodashEs.map(f,y=>jsxRuntime.jsx(tooltip.DropdownMenuCheckboxItem,{disabled:y.breakpoint==="xs",onCheckedChange:()=>b(lodashEs.toUpper(y.breakpoint)),checked:lodashEs.includes(h,lodashEs.toUpper(y.breakpoint)),onSelect:k=>k.preventDefault(),children:g(y.title)},y.breakpoint))]})]})]})};function BreakpointSelector(){const[,o]=useScreenSizeWidth(),{t:n}=reactI18next.useTranslation(),a=React.useMemo(()=>{const r=WEB_BREAKPOINTS.find(i=>i.breakpoint===o);return r==null?void 0:r.content},[o,WEB_BREAKPOINTS]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{className:"sticky top-0 z-10 flex items-center justify-start bg-muted px-2 py-1 shadow-sm",children:[jsxRuntime.jsxs("p",{className:"text-xs text-muted-foreground",children:[n("Screen")," "]}),jsxRuntime.jsx(Breakpoints$1,{openDelay:1e3,tooltip:!1})]}),jsxRuntime.jsx("div",{className:"mb-2 flex items-center justify-between rounded-md rounded-t-none border border-border p-1",children:jsxRuntime.jsx("p",{className:"flex flex-1 items-center space-x-2 text-[10px] text-foreground",children:jsxRuntime.jsxs("span",{className:"text-xs text-foreground",children:[jsxRuntime.jsx("span",{className:"rounded-md bg-muted px-1 py-px text-xs font-bold uppercase text-muted-foreground",children:o==="xs"?"Base":o})," ",n(a)]})})})]})}const DesignTokensIcon=({className:o=""})=>jsxRuntime.jsx(reactIcons.FontStyleIcon,{className:o});function ManualClasses(){var O;const o=React.useRef(null),[n,a]=React.useState(""),[r,i]=React.useState(-1),[,l]=useRightPanel(),c=useFuseSearch(),{t:d}=reactI18next.useTranslation(),[p]=useSelectedStylingBlocks(),u=useSelectedBlock(),m=useAddClassesToBlocks(),h=useRemoveClassesFromBlocks(),[x]=useSelectedBlockIds(),[g,f]=React.useState(""),b=jotai.useAtomValue(chaiDesignTokensAtom),j=(O=lodashEs.first(p))==null?void 0:O.prop,{classes:R}=applyBinding.getSplitChaiClasses(lodashEs.get(u,j,"")),y=R.split(" ").filter(T=>!lodashEs.isEmpty(T)),k=React.useMemo(()=>[...y].sort((T,N)=>{const M=T.startsWith(applyBinding.DESIGN_TOKEN_PREFIX),F=N.startsWith(applyBinding.DESIGN_TOKEN_PREFIX);return M&&!F?-1:!M&&F?1:0}),[y]),S=useBuilderProp("flags.copyPaste",!0),v=T=>{if(T.startsWith(applyBinding.DESIGN_TOKEN_PREFIX)){const N=b[T];return N?N.name:T}return T},B=T=>{const N=Object.entries(b).find(([M,F])=>F.name===T);return N?`${N[0]}`:T},C=()=>{const T=g.trim().replace(/ +(?= )/g,"").split(" ").map(B);m(x,T,!0),f("")},[w,E]=React.useState([]),A=useBuilderProp("flags.designTokens",!1),_=({value:T})=>{const N=T.trim().toLowerCase(),M=N.match(/.+:/g);let F=[],W=[];if(A&&(N===""?W=Object.entries(b).map(([$,U])=>({name:U.name,id:`${$}`,isDesignToken:!0})):W=Object.entries(b).filter(([$,U])=>U.name.toLowerCase().includes(N)).map(([$,U])=>({name:U.name,id:`${$}`,isDesignToken:!0}))),M&&M.length>0){const[$]=M,U=N.replace($,"");F=c.search(U).map(K=>({...K,item:{...K.item,name:$+K.item.name}}))}else F=c.search(N);const z=[...W,...lodashEs.map(F,"item")];return E(z)},I=()=>{E([])},P=T=>T.name,L=T=>jsxRuntime.jsxs("div",{className:"flex items-center gap-2 rounded-md p-1",children:[T.isDesignToken&&jsxRuntime.jsx(DesignTokensIcon,{className:"h-4 w-4 text-gray-600"}),jsxRuntime.jsx("span",{children:T.name})]}),D=React.useMemo(()=>({ref:o,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,placeholder:d("Enter classes separated by space"),value:g,onFocus:T=>{setTimeout(()=>{T.target&&T.target.select()},0)},onKeyDown:T=>{T.key==="Enter"&&g.trim()!==""&&w.length===0&&C()},onChange:(T,{newValue:N})=>f(N),className:"w-full rounded-md text-xs px-2 hover:outline-0 bg-background border-border py-1"}),[g,d,o,w.length]),H=T=>{const N=n.trim().replace(/ +(?= )/g,"").split(" ").map(B);h(x,[T]),m(x,N,!0),a(""),i(-1)},V=()=>{if(navigator.clipboard===void 0){sonner.toast.error(d("Clipboard not supported"));return}navigator.clipboard.writeText(y.join(" ")),sonner.toast.success(d("Classes copied to clipboard"))};return jsxRuntime.jsxs("div",{className:"flex w-full flex-col gap-y-1.5 border-b border-border pb-4",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between gap-x-2",children:jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between gap-x-2 text-muted-foreground",children:[jsxRuntime.jsxs("span",{className:"flex items-center gap-x-1",children:[jsxRuntime.jsx("span",{children:d(A?"Styles":"Classes")}),S&&jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactIcons.CopyIcon,{onClick:V,className:"cursor-pointer"})}),jsxRuntime.jsx(tooltip.TooltipContent,{children:jsxRuntime.jsx("p",{children:d("Copy classes to clipboard")})})]})]}),A&&jsxRuntime.jsx(tooltip.Button,{variant:"link",className:"underline",onClick:()=>l("design-tokens"),children:d("Design Tokens")})]})}),jsxRuntime.jsxs("div",{className:"relative flex items-center gap-x-3",children:[jsxRuntime.jsx("div",{className:"relative flex w-full items-center gap-x-3",children:jsxRuntime.jsx(Autosuggest,{suggestions:w,onSuggestionsFetchRequested:_,onSuggestionsClearRequested:I,getSuggestionValue:P,renderSuggestion:L,inputProps:D,highlightFirstSuggestion:!0,onSuggestionSelected:(T,{suggestionValue:N})=>{const M=B(N);m(x,[M],!0),f("")},containerProps:{className:"relative h-8 w-full gap-y-1 py-1 border-border text-xs"},theme:{suggestion:"bg-transparent",suggestionHighlighted:"!bg-gray-300 dark:!bg-gray-800 cursor-pointer",suggestionsContainerOpen:"absolute bg-background no-scrollbar z-50 max-h-[230px] overflow-y-auto w-full border border-border rounded-md"}})}),jsxRuntime.jsx(tooltip.Button,{variant:"outline",className:"h-6 border-border",onClick:C,disabled:g.trim()==="",size:"sm",children:jsxRuntime.jsx(reactIcons.PlusIcon,{})})]}),jsxRuntime.jsx("div",{className:"flex w-full flex-wrap gap-2 overflow-x-hidden",children:k.map((T,N)=>r===N?jsxRuntime.jsx("input",{ref:o,value:n,onChange:M=>a(M.target.value),onBlur:()=>{H(T)},onKeyDown:M=>{M.key==="Enter"&&H(T)},onFocus:M=>{setTimeout(()=>{M.target.select()},0)},className:"group relative flex max-w-[260px] cursor-default items-center gap-x-1 truncate break-words rounded border border-border bg-gray-200 p-px px-1.5 pr-2 text-[11px] text-gray-600 hover:border-gray-300 dark:border-gray-700 dark:bg-gray-800 dark:text-gray-300"},T):jsxRuntime.jsx("div",{className:"group relative flex max-w-[260px] items-center",children:jsxRuntime.jsxs("button",{onDoubleClick:()=>{f(v(T)),h(x,[T]),setTimeout(()=>{o.current&&o.current.focus()},10)},className:"flex h-max cursor-default items-center gap-x-1 truncate break-words rounded bg-gray-200 py-px pl-0.5 pr-1 text-[11px] text-gray-600 dark:bg-gray-800 dark:text-gray-300",children:[jsxRuntime.jsxs("div",{className:"z-10 flex h-full w-max items-center justify-center",children:[jsxRuntime.jsx(reactIcons.Cross2Icon,{onClick:()=>h(x,[T],!0),className:"hidden h-max w-3.5 cursor-pointer rounded bg-gray-100 p-0.5 text-red-500 hover:bg-gray-50 group-hover:block"}),T.startsWith(applyBinding.DESIGN_TOKEN_PREFIX)?jsxRuntime.jsx(DesignTokensIcon,{className:"text-[rgba(55, 65, 81, 0.4)] h-3.5 w-3.5 group-hover:hidden"}):jsxRuntime.jsxs("svg",{className:"h-3.5 w-3.5 group-hover:hidden",fill:"rgba(55, 65, 81, 0.4)",viewBox:"0 0 24 24",xmlns:"http://www.w3.org/2000/svg",xmlSpace:"preserve",children:[jsxRuntime.jsx("g",{id:"SVGRepo_bgCarrier",strokeWidth:"0"}),jsxRuntime.jsx("g",{id:"SVGRepo_tracerCarrier",strokeLinecap:"round",strokeLinejoin:"round"}),jsxRuntime.jsx("g",{id:"SVGRepo_iconCarrier",children:jsxRuntime.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M12 6.036c-2.667 0-4.333 1.325-5 3.976 1-1.325 2.167-1.822 3.5-1.491.761.189 1.305.738 1.906 1.345C13.387 10.855 14.522 12 17 12c2.667 0 4.333-1.325 5-3.976-1 1.325-2.166 1.822-3.5 1.491-.761-.189-1.305-.738-1.907-1.345-.98-.99-2.114-2.134-4.593-2.134zM7 12c-2.667 0-4.333 1.325-5 3.976 1-1.326 2.167-1.822 3.5-1.491.761.189 1.305.738 1.907 1.345.98.989 2.115 2.134 4.594 2.134 2.667 0 4.333-1.325 5-3.976-1 1.325-2.167 1.822-3.5 1.491-.761-.189-1.305-.738-1.906-1.345C10.613 13.145 9.478 12 7 12z"})})]})]}),jsxRuntime.jsx("div",{children:v(T)})]})},T))})]})}const BASIC_UNITS=["px","%","em","rem","ch","vh","vw"],FLEX_CHILD_SECTION={heading:"flex.heading",items:[{type:"arbitrary",label:"flex.basis",units:BASIC_UNITS,property:"flexBasis"},{type:"range",label:"flex.order",property:"order"},{type:"dropdown",label:"flex.flex",property:"flexGrowShrink"},{type:"dropdown",label:"flex.grow",property:"flexGrow"},{type:"dropdown",label:"flex.shrink",property:"flexShrink"}]},GRID_CHILD_SECTION={heading:"grid.heading",items:[{type:"range",label:"grid.col_span",property:"gridColSpan"},{type:"range",label:"grid.col_start",property:"gridColStart"},{type:"range",label:"grid.col_end",property:"gridColEnd"},{type:"range",label:"grid.row_span",property:"gridRowSpan"},{type:"range",label:"grid.row_start",property:"gridRowStart"},{type:"range",label:"grid.row_end",property:"gridRowEnd"},{type:"range",label:"grid.order",property:"order"}]},SETTINGS_SECTIONS=[{heading:"Styles",items:[{component:ManualClasses},{component:BreakpointSelector},{type:"arbitrary",label:"layout.width",units:BASIC_UNITS.concat("auto"),property:"width"},{type:"arbitrary",label:"layout.height",units:BASIC_UNITS.concat("auto"),property:"height"},{styleType:"multiple",label:"layout.margin",negative:!0,units:[...BASIC_UNITS,"auto"],options:[{key:"margin",label:"layout.margin_all"},{key:"marginX",label:"layout.margin_lr"},{key:"marginY",label:"layout.margin_tb"},{key:"marginTop",label:"layout.margin_top"},{key:"marginRight",label:"layout.margin_right"},{key:"marginBottom",label:"layout.margin_bottom"},{key:"marginLeft",label:"layout.margin_left"}]},{styleType:"multiple",label:"layout.padding",options:[{key:"padding",label:"layout.padding_all"},{key:"paddingX",label:"layout.padding_lr"},{key:"paddingY",label:"layout.padding_tb"},{key:"paddingTop",label:"layout.padding_top"},{key:"paddingRight",label:"layout.padding_right"},{key:"paddingBottom",label:"layout.padding_bottom"},{key:"paddingLeft",label:"layout.padding_left"}]},{styleType:"accordion",heading:"typography.heading",items:[{type:"dropdown",property:"textAlign",label:"typography.align"},{type:"dropdown",property:"fontFamily",label:"typography.font"},{type:"arbitrary",property:"fontSize",label:"typography.size",units:BASIC_UNITS},{type:"arbitrary",property:"lineHeight",label:"typography.height",units:BASIC_UNITS.concat("-")},{type:"range",property:"fontWeight",label:"typography.weight"},{type:"color",property:"textColor",label:"typography.color"}]},{styleType:"accordion",heading:"background.heading",items:[{type:"color",label:"background.bgcolor",property:"backgroundColor"},{type:"dropdown",label:"background.attachment",property:"backgroundAttachment"},{type:"dropdown",label:"background.clipping",property:"backgroundClip"},{type:"dropdown",label:"background.origin",property:"backgroundOrigin"},{type:"dropdown",label:"background.position",property:"backgroundPosition"},{type:"dropdown",label:"background.repeat",property:"backgroundRepeat"},{type:"dropdown",label:"background.size",property:"backgroundSize"}]}]}];BASIC_UNITS.concat("auto"),BASIC_UNITS.concat("auto"),[...BASIC_UNITS],BASIC_UNITS.concat("auto"),BASIC_UNITS.concat("auto"),BASIC_UNITS.concat("auto"),BASIC_UNITS.concat("auto"),BASIC_UNITS.concat("-");const MAPPER={px:1,"%":1,em:100,rem:100,ch:1,vw:1,vh:1,"-":1,deg:1,ms:.1};function BlockStyling(){const{flexChild:o,gridChild:n}=useSelectedBlocksDisplayChild(),[a]=useSelectedStylingBlocks(),[r,i]=React.useState(""),[l,c]=React.useState({onDrag:u=>u,onDragEnd:u=>u,dragStartY:0,dragging:!1,dragStartValue:0,dragUnit:"",negative:!1,cssProperty:""}),d=web.useThrottledCallback(u=>{const m=!lodashEs.get(l,"negative",!1),h=lodashEs.get(l,"cssProperty","");let x=parseFloat(l.dragStartValue);x=isNaN(x)?0:x;let g=MAPPER[l.dragUnit];(lodashEs.startsWith(h,"scale")||h==="opacity")&&(g=10);let b=(l.dragStartY-u.pageY)/g+x;m&&b<0&&(b=0),h==="opacity"&&b>1&&(b=1),l.onDrag(`${b}`),i(`${b}`)},[l],50),p=React.useCallback(()=>{setTimeout(()=>l.onDragEnd(`${r}`),100),c({onDrag:u=>u,onDragEnd:u=>u,dragStartY:0,dragging:!1,dragStartValue:0,dragUnit:"",negative:!1,cssProperty:""})},[l,r,c]);return lodashEs.isEmpty(a)?null:jsxRuntime.jsxs(BlockSettingsContext.Provider,{value:{setDragData:c},children:[l.dragging?jsxRuntime.jsx("div",{onMouseMove:d,onMouseUp:()=>p(),className:"absolute inset-0 z-30 cursor-row-resize bg-gray-300/10"}):null,jsxRuntime.jsxs("div",{className:"flex flex-col",children:[jsxRuntime.jsx(BlockStylingProps,{}),jsxRuntime.jsxs(tooltip.Accordion,{defaultValue:["Styles"],type:"multiple",className:"w-full",children:[o&&jsxRuntime.jsx(StylingGroup,{section:FLEX_CHILD_SECTION,showAccordian:o||n}),n&&jsxRuntime.jsx(StylingGroup,{section:GRID_CHILD_SECTION,showAccordian:o||n}),SETTINGS_SECTIONS.map(u=>jsxRuntime.jsx(StylingGroup,{section:u,showAccordian:o||n},u.heading))]})]})]})}const CoreBlock=({block:o,disabled:n,parentId:a,position:r})=>{const{type:i,icon:l,label:c}=o,{addCoreBlock:d,addPredefinedBlock:p}=useAddBlock(),u=()=>{if(lodashEs.has(o,"blocks")){const f=lodashEs.isFunction(o.blocks)?o.blocks():o.blocks;p(runtime.syncBlocksWithDefaults(f),a||null,r)}else d(o,a||null,r);pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)},m=useIsDragAndDropEnabled(),{t:h}=reactI18next.useTranslation(),{onDragStart:x,onDragEnd:g}=useDragAndDrop();return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("button",{disabled:n,onClick:u,type:"button",onDragStart:f=>x(f,{...o,label:c,icon:l}),onDragEnd:g,draggable:m,className:`${lodashEs.kebabCase(`chai-block-${i}`)} ${m?"cursor-grab active:cursor-grabbing":"cursor-pointer"} space-y-2 rounded-lg border border-border p-3 text-center hover:bg-slate-300/50 disabled:cursor-not-allowed disabled:bg-gray-100 disabled:text-gray-400 dark:border-gray-700 dark:text-white dark:hover:bg-slate-800/50 dark:disabled:bg-gray-900 dark:disabled:text-foreground ${n?"opacity-50":""}`,children:[React.createElement(l||reactIcons.BoxIcon,{className:"w-4 h-4 mx-auto","data-add-core-block-icon":i}),jsxRuntime.jsx("p",{className:"truncate text-xs",children:lodashEs.capitalize(h(c||i))})]})}),jsxRuntime.jsx(tooltip.TooltipContent,{children:jsxRuntime.jsx("p",{children:h(c||i)})})]})})},DefaultChaiBlocks=({parentId:o,position:n,gridCols:a="grid-cols-2",disableBlockGroupsSidebar:r=!1})=>{const i=runtime.useRegisteredChaiBlocks(),l=lodashEs.groupBy(i,"category"),c=lodashEs.uniq(lodashEs.map(l.core,"group"));return jsxRuntime.jsx(ChaiBuilderBlocks,{gridCols:a,parentId:o,position:n,groups:c,blocks:l.core,disableBlockGroupsSidebar:r})};let PRE_IMPORT_HTML_HOOK=async o=>o;const registerChaiPreImportHTMLHook=o=>{PRE_IMPORT_HTML_HOOK=o},getPreImportHTML=async o=>await PRE_IMPORT_HTML_HOOK(o),ImportHTML=({parentId:o,position:n,fromSidebar:a})=>{const{t:r}=reactI18next.useTranslation(),[i,l]=React.useState(""),{addPredefinedBlock:c}=useAddBlock(),[d,p]=React.useState(!1),u=async()=>{p(!0);const m=await getPreImportHTML(i),h=applyBinding.getBlocksFromHTML(m);c([...h],o,n),l(""),p(!1),pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)};return jsxRuntime.jsxs(tooltip.Card,{className:`border-border/0 p-0 shadow-none ${a?"w-full":"max-w-full"}`,children:[jsxRuntime.jsx(tooltip.CardHeader,{className:a?"p-0":"p-3",children:jsxRuntime.jsx(tooltip.CardDescription,{className:a?"text-xs":"",children:r("Use HTML snippets from Tailwind CSS component libraries")})}),jsxRuntime.jsx(tooltip.CardContent,{className:`space-y-2 py-0 ${a?"p-0":"px-3"}`,children:jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx(tooltip.Label,{htmlFor:"current",className:"text-sm",children:r("Tailwind HTML snippet")}),jsxRuntime.jsx(tooltip.Textarea,{onChange:m=>l(m.target.value),rows:12,value:i,placeholder:r("Enter your code snippet here"),className:"resize-none overflow-x-auto whitespace-pre bg-background font-mono text-xs font-normal"})]})}),jsxRuntime.jsx(tooltip.CardFooter,{className:"flex flex-col justify-end p-3",children:jsxRuntime.jsx(tooltip.Button,{disabled:i.trim()===""||d,onClick:()=>u(),size:"sm",className:"w-fit",children:d?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(reactIcons.CircleIcon,{className:"mr-2 h-4 w-4 animate-spin"})," ",r("Importing...")]}):r("Import HTML")})})]})},ChaiSelect=({defaultValue:o="",onValueChange:n,options:a,placeholder:r="Select",className:i="",height:l=""})=>{const[c,d]=React.useState(o),p=u=>{const m=u.target.value;d(m),n(m)};return jsxRuntime.jsx("div",{className:commonFunctions.cn("relative inline-block w-full",i),children:jsxRuntime.jsxs("select",{className:commonFunctions.cn("mt-1 flex w-full rounded-md border border-border bg-background px-3 py-1 text-sm text-foreground shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",l),value:c,onChange:p,children:[jsxRuntime.jsx("option",{value:"",disabled:!0,children:r}),a.map(u=>jsxRuntime.jsx("option",{value:u.value,children:u.label},u.value))]})})};function UILibrariesSelect({uiLibraries:o,library:n,setLibrary:a}){const{t:r}=reactI18next.useTranslation();return n?jsxRuntime.jsxs("div",{className:"h-12",children:[jsxRuntime.jsx("p",{className:"text-xs font-bold text-gray-500",children:r("Choose library")}),jsxRuntime.jsx(ChaiSelect,{className:"mb-1",options:o.map(i=>({value:i.id,label:i.name})),defaultValue:n,onValueChange:i=>a(i)})]}):null}let LIBRARIES_REGISTRY={};const registerChaiLibrary=(o,n)=>{LIBRARIES_REGISTRY[o]={...n,id:o}},useChaiLibraries=()=>lodashEs.values(LIBRARIES_REGISTRY),ChaiDraggableBlock=({block:o,html:n,blocks:a,children:r,onDragStart:i,onDragEnd:l,draggable:c,className:d="",type:p="Box"})=>{const{onDragStart:u,onDragEnd:m}=useDragAndDrop(),h=useIsDragAndDropEnabled(),[,x]=useSelectedBlockIds(),{clearHighlight:g}=useBlockHighlight(),f=c!==void 0?c:h,b=async R=>{try{if(i){i(R);return}let y=null;if(p==="Image"){if(!(o!=null&&o.image))return;y={type:"Image",blocks:[{_type:"Image",styles:"#styles:,w-full h-full object-cover",image:o==null?void 0:o.image,alt:(o==null?void 0:o.alt)||"",_name:(o==null?void 0:o.name)||"Image"}]}}else if(n){const k=typeof n=="function"?await n():n,S=applyBinding.getBlocksFromHTML(k);if(lodashEs.isEmpty(S))return;y={type:"Box",blocks:S,name:lodashEs.get(S,"0._type","Block")}}else if(a){const k=typeof a=="function"?await a():a;if(lodashEs.isEmpty(k))return;y={type:"Box",blocks:k,name:lodashEs.get(k,"0._type","Block")}}else if(o){const k=typeof o=="function"?await o():o;y=typeof k=="object"?lodashEs.omit(k,["component","icon"]):k}if(!y)return;u(R,y,!0),setTimeout(()=>{x([]),g()},200)}catch(y){console.error("Error in ChaiDraggableBlock drag start:",y)}},j=R=>{l?l(R):m()};return jsxRuntime.jsx("div",{draggable:f,onDragStart:b,onDragEnd:j,className:`${f?"cursor-grab active:cursor-grabbing":""} ${d}`.trim(),children:r})};function SearchInput({value:o,setValue:n}){const{t:a}=reactI18next.useTranslation();return jsxRuntime.jsx("div",{className:"flex py-2",children:jsxRuntime.jsxs("div",{className:"relative flex w-full max-w-md items-center rounded border px-2",children:[jsxRuntime.jsxs("div",{className:"flex w-full items-center gap-x-2",children:[jsxRuntime.jsx(reactIcons.MagnifyingGlassIcon,{className:"h-5 w-5 flex-shrink-0 stroke-[1px] text-muted-foreground"}),jsxRuntime.jsx(tooltip.Input,{placeholder:a("Search blocks..."),value:o,onChange:r=>n(r.target.value),className:"w-full flex-1 border-none p-0 leading-tight outline-none"})]}),o&&jsxRuntime.jsx("button",{onClick:()=>n(""),className:"absolute right-2.5 top-2.5 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(reactIcons.Cross1Icon,{className:"h-3.5 w-3.5"})})]})})}const BlockCard=({block:o,library:n,parentId:a=void 0,position:r=-1})=>{const[i,l]=React.useState(!1),c=React.useMemo(()=>(n==null?void 0:n.getBlock)||(()=>[]),[n]),{addCoreBlock:d,addPredefinedBlock:p}=useAddBlock(),u=lodashEs.get(o,"name",lodashEs.get(o,"label")),m=lodashEs.get(o,"description",""),{onDragStart:h,onDragEnd:x}=useDragAndDrop(),g=useIsDragAndDropEnabled(),f=React.useCallback(async j=>{if(j.stopPropagation(),lodashEs.has(o,"component")){d(o,a,r),pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK);return}l(!0);let R=await c({library:n,block:o});typeof R=="string"&&(R=applyBinding.getBlocksFromHTML(R)),lodashEs.isEmpty(R)||p(runtime.syncBlocksWithDefaults(R),a,r),pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK),setTimeout(()=>l(!1),1e3)},[d,p,o,c,n,a,r]),b=async j=>{if(!g)return;let R=await c({library:n,block:o});typeof R=="string"&&(R=applyBinding.getBlocksFromHTML(R)),h(j,{type:"Box",blocks:R,name:u},!0)};return jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(ChaiDraggableBlock,{draggable:g,onDragStart:b,onDragEnd:x,children:jsxRuntime.jsxs("div",{onClick:i?()=>{}:f,className:clsx("relative mt-2 overflow-hidden rounded-md border border-border duration-200 hover:border-blue-500 hover:shadow-xl",g?"":"cursor-pointer"),children:[i&&jsxRuntime.jsxs("div",{className:"absolute flex h-full w-full items-center justify-center bg-black/70",children:[jsxRuntime.jsx(reactIcons.ReloadIcon,{className:"h-4 w-4 animate-spin text-white"}),jsxRuntime.jsx("span",{className:"pl-2 text-sm text-white",children:"Adding..."})]}),o.preview?jsxRuntime.jsx("img",{src:o.preview,className:"min-h-[45px] w-full rounded-md",alt:u}):jsxRuntime.jsxs("div",{className:"flex h-fit w-full flex-col items-center justify-center gap-1 rounded-md border border-border p-6 py-10 text-center",children:[jsxRuntime.jsx("p",{className:"font-medium text-gray-800",children:u}),m&&jsxRuntime.jsx("p",{className:"text-sm text-gray-600",children:m})]})]})})}),jsxRuntime.jsx(tooltip.TooltipContent,{children:jsxRuntime.jsx("div",{className:"max-w-xs",children:jsxRuntime.jsx("p",{className:"font-medium",children:u})})})]})},UILibrarySection=({parentId:o,position:n,fromSidebar:a})=>{const[r,i]=useSelectedLibrary(),l=useChaiLibraries(),c=l.find(_=>_.id===r)||lodashEs.first(l),{data:d,isLoading:p,resetLibrary:u}=useLibraryBlocks(c),[m,h]=React.useState(""),[x,g]=React.useState([]),f=React.useRef(null);React.useEffect(()=>{d&&d.length>0&&(f.current=new Fuse(d,{keys:["name","label","description","group"],threshold:.4,ignoreLocation:!0}))},[d]),React.useEffect(()=>{if(!m.trim()||!f.current){g([]);return}const _=f.current.search(m).map(I=>I.item);g(_)},[m]);const b=m.trim()&&!lodashEs.isEmpty(x)?x:d,j=lodashEs.groupBy(b,"group"),[R,y]=React.useState(null);React.useEffect(()=>{if(lodashEs.isEmpty(lodashEs.keys(j))){y(null);return}if(!R||!j[R]){y(lodashEs.first(lodashEs.keys(j)));return}},[j,R]);const k=lodashEs.get(j,R,[]),S=React.useRef(null),{t:v}=reactI18next.useTranslation(),B=React.useRef(null);React.useEffect(()=>{var I;const _=(I=B.current)==null?void 0:I.querySelector("[data-radix-scroll-area-viewport]");_&&_.scrollTo({top:0,behavior:"smooth"})},[c,R]);const C=_=>{S.current&&(clearTimeout(S.current),S.current=null),S.current=setTimeout(()=>{S.current&&y(_)},400)},w=()=>{c!=null&&c.id&&u(c.id)};if(p)return jsxRuntime.jsxs("div",{className:"mt-4 grid h-full w-full grid-cols-12 gap-2",children:[jsxRuntime.jsx(tooltip.Skeleton,{className:"col-span-3 h-full"}),jsxRuntime.jsx(tooltip.Skeleton,{className:"col-span-9 h-full"})]});const E=lodashEs.filter(k,(_,I)=>I%2===0),A=lodashEs.filter(k,(_,I)=>I%2===1);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"flex h-full max-h-full flex-col",children:[jsxRuntime.jsx(SearchInput,{value:m,setValue:h}),jsxRuntime.jsx("div",{className:"relative flex h-full max-h-full flex-1 overflow-hidden bg-background",children:jsxRuntime.jsxs("div",{className:`flex h-full flex-1 pt-2 ${a?"flex-col":""}`,children:[jsxRuntime.jsxs("div",{className:`flex max-h-full min-w-60 flex-col gap-1 ${a?"pb-2":"w-60 max-w-60 px-1 pr-2"}`,children:[jsxRuntime.jsx(UILibrariesSelect,{library:c==null?void 0:c.id,setLibrary:i,uiLibraries:l}),jsxRuntime.jsxs("div",{className:"mt-2 flex h-full max-h-full w-full flex-1 flex-col",children:[jsxRuntime.jsx("span",{className:"text-xs font-bold text-gray-500",children:v("Groups")}),!a&&jsxRuntime.jsx("hr",{className:"mt-1 border-border"}),jsxRuntime.jsx("div",{className:`no-scrollbar mt-2 h-full max-h-full flex-1 overflow-y-auto ${a?"":"pb-20"}`,children:lodashEs.isEmpty(j)?jsxRuntime.jsx("div",{className:"mt-4 flex flex-col items-center justify-center gap-3 p-4 text-center",children:m?jsxRuntime.jsx("p",{className:"text-sm",children:v("No matching blocks found")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("p",{className:"text-sm",children:v("Failed to load the UI library. Try again")}),jsxRuntime.jsxs(tooltip.Button,{onClick:w,variant:"outline",size:"sm",className:"gap-2",children:[jsxRuntime.jsx(reactIcons.ReloadIcon,{className:"h-4 w-4"}),v("Retry")]})]})}):a?jsxRuntime.jsxs(tooltip.Select,{value:R,onValueChange:y,children:[jsxRuntime.jsx(tooltip.SelectTrigger,{className:"w-full",children:jsxRuntime.jsx(tooltip.SelectValue,{placeholder:v("Select a group")})}),jsxRuntime.jsx(tooltip.SelectContent,{children:lodashEs.map(j,(_,I)=>jsxRuntime.jsx(tooltip.SelectItem,{value:I,children:lodashEs.capitalize(v(I.toLowerCase()))},I))})]}):lodashEs.map(j,(_,I)=>jsxRuntime.jsxs("div",{onMouseEnter:()=>C(I),onMouseLeave:()=>clearTimeout(S.current),role:"button",onClick:()=>y(I),className:tooltip.cn("flex w-full cursor-pointer items-center justify-between rounded-md p-2 text-sm text-foreground transition-all ease-in-out hover:bg-gray-200 dark:hover:bg-gray-800",I===R?"bg-primary text-primary-foreground hover:bg-primary/80":""),children:[jsxRuntime.jsx("span",{children:lodashEs.capitalize(v(I.toLowerCase()))}),jsxRuntime.jsx(reactIcons.CaretRightIcon,{className:"ml-2 h-5 w-5"})]},I))})]})]}),jsxRuntime.jsx("div",{className:`flex h-full max-h-full w-full flex-col border-border ${a?"":"border-l"}`,children:jsxRuntime.jsxs(tooltip.ScrollArea,{ref:B,onMouseEnter:()=>S.current?clearTimeout(S.current):null,className:"z-10 flex h-full max-h-full w-full flex-col gap-2 transition-all ease-linear",children:[lodashEs.isEmpty(k)&&!lodashEs.isEmpty(j)?jsxRuntime.jsx("div",{className:"flex h-full flex-col items-center justify-center p-6 text-center",children:jsxRuntime.jsx("p",{className:"text-sm",children:v("No blocks found in this group")})}):jsxRuntime.jsxs("div",{className:`grid w-full gap-2 ${a?"grid-cols-1 pb-20":"grid-cols-2 px-2"}`,children:[jsxRuntime.jsx("div",{className:"flex flex-col gap-1",children:E.map((_,I)=>jsxRuntime.jsx(BlockCard,{parentId:o,position:n,block:_,library:c},`block-${I}`))}),jsxRuntime.jsx("div",{className:"flex flex-col gap-1",children:A.map((_,I)=>jsxRuntime.jsx(BlockCard,{parentId:o,position:n,block:_,library:c},`block-second-${I}`))})]}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]})})]})})]})})},UILibrariesPanel=({parentId:o,position:n,fromSidebar:a})=>jsxRuntime.jsx(UILibrarySection,{parentId:o,position:n,fromSidebar:a}),partialBlocksDataAtom=jotai.atom({blocks:[],groups:[],isLoading:!0,error:null}),hasInitializedPartialBlocksAtom=jotai.atom(!1),formatReadableName=o=>{if(!o)return"";let n=o.replace(/[-_]/g," ");return n=n.replace(/([a-z])([A-Z])/g,"$1 $2"),n.split(" ").map(a=>a.charAt(0).toUpperCase()+a.slice(1).toLowerCase()).join(" ")},PartialBlocks=({parentId:o,position:n,gridCols:a="grid-cols-2",disableBlockGroupsSidebar:r=!1})=>{const{data:i,isLoading:l,refetch:c,error:d}=usePartialBlocksList(),[p,u]=jotai.useAtom(partialBlocksDataAtom),[m,h]=jotai.useAtom(hasInitializedPartialBlocksAtom);React.useEffect(()=>{if(!m||Object.keys(p.blocks).length===0)if(d)u({blocks:[],groups:[],isLoading:!1,error:d}),h(!0);else if(!l&&Object.keys(i||{}).length>0){const g=Object.entries(i).map(([b,j])=>{const R=j,y=R.type||"partial",k=formatReadableName(y);return{type:"PartialBlock",label:formatReadableName(R.name||b),description:R.description||"",icon:reactIcons.FrameIcon,group:k,category:"partial",partialBlockId:b,_name:R.name}}),f=lodashEs.uniq(lodashEs.map(g,"group"));u({blocks:g,groups:f,isLoading:!1,error:null}),h(!0)}else l?u(g=>({...g,isLoading:!0,error:null})):!l&&Object.keys(i||{}).length===0&&(u({blocks:[],groups:[],isLoading:!1,error:"No partial blocks available"}),h(!0))},[l,i,m,h,u,p.blocks,d]);const x=()=>{u(g=>({...g,isLoading:!0,error:null})),h(!1),c()};return p.isLoading?jsxRuntime.jsx("div",{className:"flex items-center justify-center p-8 text-center text-muted-foreground",children:"Loading partial blocks..."}):p.error||p.blocks.length===0?jsxRuntime.jsxs("div",{className:"flex flex-col items-center justify-center gap-4 p-8 text-center text-muted-foreground",children:[jsxRuntime.jsx("p",{children:p.error||"No partial blocks available"}),jsxRuntime.jsx("button",{onClick:x,className:"rounded-md bg-primary px-3 py-1 text-sm text-primary-foreground hover:bg-primary/90",children:"Refresh"})]}):jsxRuntime.jsx(ChaiBuilderBlocks,{gridCols:a,parentId:o,position:n,groups:p.groups,blocks:p.blocks,disableBlockGroupsSidebar:r})},ADD_BLOCK_TABS={},registerChaiAddBlockTab=(o,n)=>{lodashEs.has(ADD_BLOCK_TABS,o)&&console.warn(`Add block tab with id ${o} already registered`),lodashEs.set(ADD_BLOCK_TABS,o,{id:o,...n})},useChaiAddBlockTabs=()=>React.useMemo(()=>lodashEs.values(ADD_BLOCK_TABS),[]),CORE_GROUPS=["basic","typography","media","layout","form","advanced","other"],ChaiBuilderBlocks=({groups:o,blocks:n,parentId:a,position:r,gridCols:i="grid-cols-4",disableBlockGroupsSidebar:l})=>{var _;const{t:c}=reactI18next.useTranslation(),[d]=useBlocksStore(),[p,u]=React.useState(""),m=React.useRef(null),[h]=jotai.useAtom(addBlockTabAtom),x=(_=lodashEs.find(d,I=>I._id===a))==null?void 0:_._type,[g,f]=React.useState("all"),[b,j]=React.useState(null),R=React.useRef(null),y=useBuilderProp("flags.dragAndDrop",!1);React.useEffect(()=>{const I=setTimeout(()=>{var P;(P=m.current)==null||P.focus()},0);return()=>clearTimeout(I)},[h]),React.useEffect(()=>{p&&(f("all"),j(null))},[p]),React.useEffect(()=>(R.current=lodashEs.debounce(I=>{f(I)},500),()=>{R.current&&R.current.cancel()}),[]);const k=React.useCallback(I=>{j(I),R.current&&R.current(I)},[]),S=React.useCallback(()=>{j(null),R.current&&R.current.cancel()},[]),v=React.useCallback(I=>{R.current&&R.current.cancel(),f(I),j(null)},[]),B=React.useMemo(()=>p?lodashEs.values(n).filter(I=>{var P,L;return(((P=I.label)==null?void 0:P.toLowerCase())+" "+((L=I.type)==null?void 0:L.toLowerCase())).includes(p.toLowerCase())}):n,[n,p]),C=React.useMemo(()=>p?o.filter(I=>lodashEs.reject(lodashEs.filter(lodashEs.values(B),{group:I}),{hidden:!0}).length>0):o.filter(I=>lodashEs.reject(lodashEs.filter(lodashEs.values(n),{group:I}),{hidden:!0}).length>0),[n,B,o,p]),w=React.useMemo(()=>lodashEs.sortBy(C,I=>CORE_GROUPS.indexOf(I)===-1?99:CORE_GROUPS.indexOf(I)),[C]),E=React.useMemo(()=>g==="all"?B:lodashEs.filter(lodashEs.values(B),{group:g}),[B,g]),A=React.useMemo(()=>g==="all"?w:[g],[w,g]);return jsxRuntime.jsxs("div",{className:"mx-auto flex h-full w-full flex-col",children:[jsxRuntime.jsx(SearchInput,{value:p,setValue:u}),jsxRuntime.jsxs("div",{className:"sticky top-10 flex h-[calc(100%-48px)] overflow-hidden pt-2",children:[!l&&w.length>0&&jsxRuntime.jsx("div",{className:"w-1/4 min-w-[120px] border-r border-border",children:jsxRuntime.jsx(tooltip.ScrollArea,{className:"h-full",children:jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx("button",{onClick:()=>v("all"),onMouseEnter:()=>k("all"),onMouseLeave:S,className:`w-full rounded-md px-2 py-1.5 text-left text-sm font-medium ${g==="all"||b==="all"?"bg-primary text-primary-foreground":"hover:bg-primary/50 hover:text-primary-foreground"}`,children:c("All")},"sidebar-all"),w.map(I=>jsxRuntime.jsx("button",{onClick:()=>v(I),onMouseEnter:()=>k(I),onMouseLeave:S,className:`w-full rounded-md px-2 py-1.5 text-left text-sm ${g===I||b===I?"bg-primary text-primary-foreground":"hover:bg-primary/50 hover:text-primary-foreground"}`,children:lodashEs.capitalize(c(I.toLowerCase()))},`sidebar-${I}`))]})})}),jsxRuntime.jsx("div",{className:`h-full flex-1 overflow-hidden ${!l&&w.length>0?"w-3/4":"w-full"}`,children:jsxRuntime.jsx(tooltip.ScrollArea,{id:"add-blocks-scroll-area",className:"no-scrollbar h-full",children:C.length===0&&p?jsxRuntime.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center text-muted-foreground",children:jsxRuntime.jsxs("p",{children:[c("No blocks found matching"),' "',p,'"']})}):jsxRuntime.jsx("div",{className:`${l?"p-0":"p-4"} space-y-6`,children:A.map((I,P)=>jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("h3",{className:"px-1 text-sm font-medium",children:lodashEs.capitalize(c(I.toLowerCase()))}),jsxRuntime.jsx("div",{className:"grid gap-2 "+i,children:lodashEs.reject(g==="all"?lodashEs.filter(lodashEs.values(E),{group:I}):lodashEs.values(E),{hidden:!0}).map((L,D)=>jsxRuntime.jsx(CoreBlock,{parentId:a,position:r,block:L,disabled:!y&&(!canAcceptChildBlock(x,L.type)||!canBeNestedInside(x,L.type))},L.type+"-"+P+"-"+D))})]},I))})})})]})]})},addBlockTabAtom=utils.atomWithStorage("__add_block_tab","library"),AddBlocksPanel=({className:o,showHeading:n=!0,parentId:a=void 0,position:r=-1,fromSidebar:i=!1})=>{const{t:l}=reactI18next.useTranslation(),[c,d]=jotai.useAtom(addBlockTabAtom),[,p]=jotai.useAtom(showPredefinedBlockCategoryAtom),u=useBuilderProp("flags.importHtml",!0),{data:m}=usePartialBlocksList(),h=Object.keys(m||{}).length>0,{hasPermission:x}=usePermissions();React.useEffect(()=>{c==="partials"&&!h&&d("library")},[c,h,d]);const g=React.useCallback(()=>{pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)},[]),f=useChaiAddBlockTabs(),b=u&&x(PERMISSIONS.IMPORT_HTML),R=useChaiLibraries().length>0;return React.useEffect(()=>{c==="library"&&!R&&d("core")},[c,R,d]),jsxRuntime.jsxs("div",{className:commonFunctions.cn("flex h-full w-full flex-col overflow-hidden",o),children:[n?jsxRuntime.jsxs("div",{className:"mb-2 flex flex-col justify-between rounded-md bg-background/30 p-1",children:[jsxRuntime.jsx("h1",{className:"flex flex-col items-baseline px-1 text-xl font-semibold xl:flex-col",children:l("Add block")}),jsxRuntime.jsx("span",{className:"p-0 text-xs font-light leading-3 opacity-80 xl:pl-1",children:l(c==="html"?"Enter or paste TailwindCSS HTML snippet":"Click to add block to page")})]}):null,jsxRuntime.jsxs(tooltip.Tabs,{onValueChange:y=>{p(""),d(y)},value:c,className:"flex h-full max-h-full flex-col overflow-hidden",children:[jsxRuntime.jsxs(tooltip.TabsList,{className:`flex items-center ${i?"h-max w-max justify-start p-1":"w-full"}`,children:[R&&jsxRuntime.jsx(tooltip.TabsTrigger,{value:"library",className:i?"h-5 px-2 text-xs":"",children:l("Library")}),jsxRuntime.jsx(tooltip.TabsTrigger,{value:"core",className:i?"h-5 px-2 text-xs":"",children:l("Blocks")}),h&&jsxRuntime.jsx(tooltip.TabsTrigger,{value:"partials",className:i?"h-5 px-2 text-xs":"",children:l("Partials")}),b?jsxRuntime.jsx(tooltip.TabsTrigger,{value:"html",className:i?"h-5 px-2 text-xs":"",children:l("Import")}):null,lodashEs.map(f,y=>jsxRuntime.jsx(tooltip.TabsTrigger,{value:y.id,className:i?"h-5 px-2 text-xs":"",children:React.createElement(y.tab)},`tab-add-block-${y.id}`))]}),jsxRuntime.jsx(tooltip.TabsContent,{value:"core",className:"h-full max-h-full flex-1 pb-20",children:jsxRuntime.jsx("div",{className:"h-full max-h-full overflow-hidden",children:jsxRuntime.jsx("div",{className:"h-full w-full",children:jsxRuntime.jsx(DefaultChaiBlocks,{gridCols:i?"grid-cols-2":"grid-cols-4",parentId:a,position:r,disableBlockGroupsSidebar:i})})})}),R&&jsxRuntime.jsx(tooltip.TabsContent,{value:"library",className:"h-full max-h-full flex-1 pb-20",children:jsxRuntime.jsx(UILibrariesPanel,{fromSidebar:i,parentId:a,position:r})}),h&&jsxRuntime.jsx(tooltip.TabsContent,{value:"partials",className:"h-full max-h-full flex-1 pb-20",children:jsxRuntime.jsx("div",{className:"h-full max-h-full overflow-hidden",children:jsxRuntime.jsx("div",{className:"h-full w-full",children:jsxRuntime.jsx(PartialBlocks,{gridCols:i?"grid-cols-2":"grid-cols-4",parentId:a,position:r,disableBlockGroupsSidebar:i})})})}),b?jsxRuntime.jsx(tooltip.TabsContent,{value:"html",className:"h-full max-h-full flex-1 pb-20 ",children:jsxRuntime.jsx(ImportHTML,{parentId:a,position:r,fromSidebar:i})}):null,lodashEs.map(f,y=>jsxRuntime.jsx(tooltip.TabsContent,{value:y.id,children:React.createElement(y.tabContent,{close:g,parentId:a,position:r})},`panel-add-block-${y.id}`))]})]})},placeholderStyle={display:"flex",alignItems:"center",zIndex:1},DefaultCursor=React.memo(function({top:n,left:a}){const r={position:"absolute",pointerEvents:"none",top:n+"px",left:a+"px",right:0};return jsxRuntime.jsx("div",{style:{...placeholderStyle,...r},children:jsxRuntime.jsx("div",{className:"h-0.5 flex-1 rounded-[1px] bg-green-500"})})}),ICON_CLASS="h-3 w-3 flex-shrink-0",TypeIcon=o=>{const n=runtime.useRegisteredChaiBlocks(),a=lodashEs.get(n,[o==null?void 0:o.type,"icon"]);return a?React.createElement(a,{className:ICON_CLASS}):jsxRuntime.jsx(reactIcons.SquareIcon,{className:ICON_CLASS})},Overlay=React.memo(function({children:n,isDragging:a}){return a?jsxRuntime.jsx("div",{className:"pointer-events-none fixed left-0 top-0 z-[100] h-full w-full",children:n}):null}),DefaultDragPreview=React.memo(({id:o,isDragging:n,mouse:a})=>{const[r]=useBlocksStore(),i=React.useMemo(()=>r.find(c=>c._id===o),[r,o]),l=React.useMemo(()=>({transform:`translate(${(a==null?void 0:a.x)-10}px, ${(a==null?void 0:a.y)-10}px)`}),[a]);return a?jsxRuntime.jsx("div",{children:jsxRuntime.jsx(Overlay,{isDragging:n,children:jsxRuntime.jsx("div",{className:"pointer-events-none absolute z-50 rounded border border-border bg-gray-100/80 font-semibold text-blue-600 shadow-md dark:border-gray-700 dark:bg-gray-800",style:l,children:jsxRuntime.jsxs("button",{type:"button",className:"flex !cursor-grab items-center p-0.5","aria-label":`Type: ${i==null?void 0:i._type}`,children:[jsxRuntime.jsx("div",{className:"-mt-0.5 h-3 w-3",children:jsxRuntime.jsx(TypeIcon,{type:i==null?void 0:i._type})}),jsxRuntime.jsx("div",{className:"ml-2 truncate text-[11px]",children:(i==null?void 0:i._name)||(i==null?void 0:i._type)})]})})})}):jsxRuntime.jsx("div",{className:"hidden"})}),defaultShortcuts=[{key:"ArrowDown",command:"selectNext"},{key:"ArrowUp",command:"selectPrev"},{key:"ArrowLeft",command:"selectParent",when:"isLeaf || isClosed"},{key:"ArrowLeft",command:"close",when:"isOpen"},{key:"ArrowRight",command:"open",when:"isClosed"},{key:"ArrowRight",command:"selectNext",when:"isOpen"},{key:"Home",command:"selectFirst"},{key:"End",command:"selectLast"}];function selectFirst(o){o.firstNode&&o.select(o.firstNode.id)}function selectLast(o){o.lastNode&&o.select(o.lastNode.id)}function selectNext(o){const n=o.selectedNodes[0].next||o.firstNode;o.select(n.id)}function selectPrev(o){const n=o.selectedNodes[0].prev||o.lastNode;o.select(n.id)}const selectParent=(o,n)=>{var r;const a=((r=o.selectedIds[0])==null?void 0:r.parent)||null;a&&n&&o.select(a.id)},open=(o,n)=>{const a=o.selectedNodes[0];a.isInternal&&n&&a.open()},close=(o,n)=>{const a=o.selectedNodes[0];a.isInternal&&n&&a.close()},ClearCanvas=({children:o})=>{const{t:n}=reactI18next.useTranslation(),{setNewBlocks:a}=useBlocksStoreUndoableActions(),[,r]=useSelectedBlockIds(),[,i]=useSelectedStylingBlocks(),l=React.useCallback(()=>{a([]),r([]),i([])},[a]);return jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs(tooltip.AlertDialog,{children:[jsxRuntime.jsx(tooltip.AlertDialogTrigger,{asChild:!0,children:o||jsxRuntime.jsxs(tooltip.Button,{size:"sm",variant:"ghost",className:"flex items-center",children:[jsxRuntime.jsx(reactIcons.EraserIcon,{})," ",n("Clear")]})}),jsxRuntime.jsxs(tooltip.AlertDialogContent,{className:"border-border",children:[jsxRuntime.jsxs(tooltip.AlertDialogHeader,{children:[jsxRuntime.jsx(tooltip.AlertDialogTitle,{className:"text-foreground",children:n("Clear whole canvas?")}),jsxRuntime.jsx(tooltip.AlertDialogDescription,{children:n("Are you sure you want to clear the page?")})]}),jsxRuntime.jsxs(tooltip.AlertDialogFooter,{children:[jsxRuntime.jsx(tooltip.AlertDialogCancel,{className:"text-foreground",children:n("Cancel")}),jsxRuntime.jsx(tooltip.AlertDialogAction,{onClick:l,children:n("Yes")})]})]})]})})};let SAVE_TO_LIB_COMPONENT=null;const registerChaiSaveToLibrary=o=>{SAVE_TO_LIB_COMPONENT=o},useSaveToLibraryComponent=()=>React.useMemo(()=>SAVE_TO_LIB_COMPONENT,[]),saveToLibraryModalAtom=jotai.atom({isOpen:!1,blockId:null}),getBlocks=(o,n)=>{const a=lodashEs.filter(o,{_parent:n});if(a.length===0)return[];const r=[...a];return a.forEach(i=>{r.push(...getBlocks(o,i==null?void 0:i._id))}),r},SaveToLibraryModal=()=>{const[o,n]=jotai.useAtom(saveToLibraryModalAtom),{t:a}=reactI18next.useTranslation(),[r]=useBlocksStore(),i=()=>n({isOpen:!1,blockId:null}),l=useSaveToLibraryComponent(),c=React.useMemo(()=>{if(!o.blockId)return[];const d=lodashEs.find(r,{_id:o.blockId});return d==null||delete d._parent,[d,...getBlocks(r,d==null?void 0:d._id)]},[o.blockId,r]);return jsxRuntime.jsx(tooltip.Dialog,{open:o.isOpen,onOpenChange:d=>!d&&i(),children:jsxRuntime.jsxs(tooltip.DialogContent,{className:"p-4 sm:max-w-[450px]",children:[jsxRuntime.jsx(tooltip.DialogHeader,{className:"pb-2",children:jsxRuntime.jsx(tooltip.DialogTitle,{children:a("Save to Library")})}),l&&!lodashEs.isEmpty(o.blockId)&&jsxRuntime.jsx(l,{blockId:o.blockId,blocks:c,close:i})]})})},SaveToLibrary=()=>{const o=useSelectedBlock(),{t:n}=reactI18next.useTranslation(),[,a]=jotai.useAtom(saveToLibraryModalAtom),r=useSaveToLibraryComponent(),i=()=>{o&&a({isOpen:!0,blockId:o._id})};return r?jsxRuntime.jsxs(tooltip.DropdownMenuItem,{className:"flex items-center gap-x-4 text-xs",onClick:i,children:[jsxRuntime.jsx(reactIcons.CheckIcon,{className:"h-4 w-4"})," ",o!=null&&o._libBlockId?n("Update library block"):n("Save to library")]}):null},UnlinkLibraryBlock=()=>{const{t:o}=reactI18next.useTranslation(),n=useSelectedBlock(),a=useUpdateBlocksProps(),r=()=>{a([n._id],{_libBlockId:null})};return jsxRuntime.jsxs(tooltip.DropdownMenuItem,{onClick:r,className:"flex items-center gap-x-4 text-xs",children:[jsxRuntime.jsx(reactIcons.LinkBreak2Icon,{className:"h-4 w-4"})," ",o("Unlink from library")]})},ExportCode=()=>{const{t:o}=reactI18next.useTranslation(),[n]=useSelectedBlockIds();return useBuilderProp("flags.exportCode",!1)?jsxRuntime.jsxs(tooltip.DropdownMenuItem,{className:"flex items-center gap-x-4 text-xs",onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_EXPORT_CODE,n),children:[jsxRuntime.jsx(reactIcons.DownloadIcon,{})," ",o("Export")]}):null},CopyPasteBlocks=({isFromBody:o=!1})=>{const[n]=useBlocksStore(),[a]=useSelectedBlockIds(),{pasteBlocks:r}=usePasteBlocks(),[,i,l]=useCopyBlocks(),{t:c}=reactI18next.useTranslation(),d=useSelectedBlock(),p=useBuilderProp("flags.copyPaste",!0),u=React.useCallback(()=>{var x;const h=(o?(x=n==null?void 0:n.filter(g=>!(g!=null&&g._parent)))==null?void 0:x.map(g=>g==null?void 0:g._id):a).map(g=>{const f=n.find(b=>b._id===g);return{id:g,data:f}});l(h.map(g=>g.id))?sonner.toast.warning("Partial blocks detected. Clone partial blocks?",{cancel:{label:c("No"),onClick:()=>{i(h.map(g=>g.id)),sonner.toast.dismiss()}},action:{label:c("Yes"),onClick:()=>{i(h.map(g=>g.id),!0),sonner.toast.dismiss()}},position:"top-center"}):i(h.map(g=>g.id))},[a,n,i,l]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[p&&jsxRuntime.jsxs(tooltip.DropdownMenuItem,{disabled:!canDuplicateBlock(d==null?void 0:d._type),onClick:u,className:"flex items-center gap-x-4 text-xs",children:[jsxRuntime.jsx(reactIcons.CopyIcon,{})," ",c("Copy")]}),p&&jsxRuntime.jsxs(tooltip.DropdownMenuItem,{className:"flex items-center gap-x-4 text-xs",onClick:()=>{r(a)},children:[jsxRuntime.jsx(reactIcons.CardStackIcon,{})," ",c("Paste")]})]})},CutBlocks=()=>{const[o]=useSelectedBlockIds(),[,n]=useCutBlockIds(),{t:a}=reactI18next.useTranslation(),r=useBuilderProp("flags.copyPaste",!0);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:r&&jsxRuntime.jsxs(tooltip.DropdownMenuItem,{className:"flex items-center gap-x-4 text-xs",onClick:()=>n(o),children:[jsxRuntime.jsx(reactIcons.ScissorsIcon,{})," ",a("Cut")]})})},RemoveBlocks=()=>{const[o]=useSelectedBlockIds(),n=useRemoveBlocks(),a=useSelectedBlock(),{t:r}=reactI18next.useTranslation();return jsxRuntime.jsxs(tooltip.DropdownMenuItem,{disabled:!canDeleteBlock(a==null?void 0:a._type),className:"flex items-center gap-x-4 text-xs",onClick:()=>n(o),children:[jsxRuntime.jsx(reactIcons.TrashIcon,{})," ",r("Remove")]})},RenameBlock=({node:o})=>{const{t:n}=reactI18next.useTranslation();return jsxRuntime.jsxs(tooltip.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),o.edit(),o.deselect()},className:"flex items-center gap-x-4 text-xs",children:[jsxRuntime.jsx(reactIcons.Pencil2Icon,{className:"h-4 w-4"})," ",n("Rename")]})},BlockContextMenuContent=({node:o})=>{const{t:n}=reactI18next.useTranslation(),[a]=useSelectedBlockIds(),r=useDuplicateBlocks(),i=useSelectedBlock(),{hasPermission:l}=usePermissions(),{librarySite:c}=useBuilderProp("flags",{librarySite:!1}),d=useIsDragAndDropEnabled(),p=React.useCallback(()=>{r(a)},[a,r]),u=React.useMemo(()=>lodashEs.has(i,"_libBlockId")&&!lodashEs.isEmpty(i._libBlockId),[i==null?void 0:i._libBlockId]);return o==="BODY"?jsxRuntime.jsx(tooltip.DropdownMenuContent,{side:"bottom",className:"border-border text-xs",children:l(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(tooltip.DropdownMenuItem,{disabled:!1,className:"flex items-center gap-x-4 text-xs",onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,i),children:[jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-3.5 w-3.5"})," ",n("Add block")]}),l(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsx(CopyPasteBlocks,{isFromBody:!0}),jsxRuntime.jsx(ExportCode,{}),jsxRuntime.jsx(tooltip.DropdownMenuItem,{disabled:!1,onClick:m=>m.preventDefault(),className:"flex items-center gap-x-4 text-xs",children:jsxRuntime.jsx(ClearCanvas,{children:jsxRuntime.jsxs("div",{className:"flex items-center gap-x-4 text-xs",children:[jsxRuntime.jsx(reactIcons.EraserIcon,{})," ",n("Clear canvas")]})})})]})}):jsxRuntime.jsxs(tooltip.DropdownMenuContent,{side:"bottom",className:"border-border text-xs",children:[l(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!d&&jsxRuntime.jsxs(tooltip.DropdownMenuItem,{disabled:!canAddChildBlock(i==null?void 0:i._type),className:"flex items-center gap-x-4 text-xs",onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,i),children:[jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-3.5 w-3.5"})," ",n("Add block")]}),jsxRuntime.jsxs(tooltip.DropdownMenuItem,{disabled:!canDuplicateBlock(i==null?void 0:i._type),className:"flex items-center gap-x-4 text-xs",onClick:p,children:[jsxRuntime.jsx(reactIcons.CardStackPlusIcon,{})," ",n("Duplicate")]})]}),jsxRuntime.jsx(RenameBlock,{node:o}),l(PERMISSIONS.MOVE_BLOCK)&&jsxRuntime.jsx(CutBlocks,{}),l(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsx(CopyPasteBlocks,{}),u&&c&&jsxRuntime.jsx(UnlinkLibraryBlock,{}),l(PERMISSIONS.CREATE_LIBRARY_BLOCK)&&c&&jsxRuntime.jsx(SaveToLibrary,{}),jsxRuntime.jsx(ExportCode,{}),l(PERMISSIONS.DELETE_BLOCK)&&jsxRuntime.jsx(RemoveBlocks,{})]})},BlockMoreOptions=({children:o,id:n,node:a})=>{const[,r]=useSelectedBlockIds();return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs(tooltip.DropdownMenu,{onOpenChange:i=>{i&&r([n])},children:[jsxRuntime.jsx(tooltip.DropdownMenuTrigger,{children:o}),jsxRuntime.jsx(BlockContextMenuContent,{node:a})]})})},PERMISSIONS={ADD_BLOCK:"add_block",DELETE_BLOCK:"delete_block",EDIT_BLOCK:"edit_block",MOVE_BLOCK:"move_block",EDIT_THEME:"edit_theme",SAVE_PAGE:"save_page",EDIT_STYLES:"edit_styles",IMPORT_HTML:"import_html",CREATE_LIBRARY_BLOCK:"create_library_block",CREATE_LIBRARY_GROUP:"create_library_group",EDIT_LIBRARY_BLOCK:"edit_library_block",DELETE_LIBRARY_BLOCK:"delete_library_block"};Object.values(PERMISSIONS);const useStructureValidation=()=>{const[o]=jotai.useAtom(structureErrorsAtom),[n]=jotai.useAtom(structureValidationValidAtom),[a]=jotai.useAtom(hasStructureErrorsAtom),[r]=jotai.useAtom(hasStructureWarningsAtom),[i]=jotai.useAtom(structureErrorCountAtom),[l]=jotai.useAtom(structureWarningCountAtom),[c]=jotai.useAtom(structureErrorsByBlockAtom);return{errors:o,isValid:n,hasErrors:a,hasWarnings:r,errorCount:i,warningCount:l,errorsByBlock:c,getBlockErrors:d=>c[d]||[],getErrorsBySeverity:d=>o.filter(p=>p.severity===d),getErrorMessages:()=>o.map(d=>d.message),getErrorMessagesBySeverity:d=>o.filter(p=>p.severity===d).map(p=>p.message),getAllErrorMessages:()=>({errors:o.filter(d=>d.severity==="error").map(d=>d.message),warnings:o.filter(d=>d.severity==="warning").map(d=>d.message)})}},Input=({node:o})=>{var n,a;return jsxRuntime.jsx("input",{autoFocus:!0,className:cn("ml-2 !h-4 w-full rounded-sm border border-border bg-background px-1 text-[11px] leading-tight outline-none",o.isSelected?"text-black dark:text-white":""),type:"text",defaultValue:((n=o.data)==null?void 0:n._name)||((a=o.data)==null?void 0:a._type),onFocus:r=>r.currentTarget.select(),onBlur:r=>o.submit(r.currentTarget.value),onKeyDown:r=>{r.key==="Enter"&&o.submit(r.currentTarget.value)}})},currentAddSelection=jotai.atom(null),getBlockDisplayName=o=>{var n;return o!=null&&o._name?o._name:(o==null?void 0:o._type)==="Box"&&(o!=null&&o.tag)&&(o==null?void 0:o.tag)!=="div"?lodashEs.startCase(o.tag):((n=o==null?void 0:o._type)==null?void 0:n.split("/").pop())||""},truncateText=(o,n)=>o.length>n?o.substring(0,n)+"...":o,Node$1=React.memo(({node:o,style:n,dragHandle:a})=>{var T;const{t:r}=reactI18next.useTranslation(),i=useUpdateBlocksProps(),[l]=jotai.useAtom(canvasIframeAtom),{hasPermission:c}=usePermissions();let d=null;const p=o.children.length>0,{highlightBlock:u,clearHighlight:m}=useBlockHighlight(),h=useIsDragAndDropEnabled(),{id:x,data:g,isSelected:f,willReceiveDrop:b,isDragging:j,isEditing:R,handleClick:y}=o,k=useStructureValidation(),S=React.useMemo(()=>k.getBlockErrors(x),[k,x]),v=lodashEs.get(g,"_show",!0),B=N=>{N.stopPropagation(),v&&o.toggle()},C=N=>{N.isInternal&&(d=N.isOpen,N.isOpen&&N.close())},w=N=>{N.isInternal&&d!==null&&(d?N.open():N.close(),d=null)},[E,A]=jotai.useAtom(currentAddSelection),_=()=>{var N;I(),o.parent.isSelected||A((N=o==null?void 0:o.parent)==null?void 0:N.id)},I=()=>{A(null)},P=N=>{I(),N.stopPropagation(),!o.isOpen&&v&&o.toggle(),y(N)};React.useEffect(()=>{const N=setTimeout(()=>{b&&!o.isOpen&&!j&&v&&o.toggle()},500);return()=>clearTimeout(N)},[b,o,j]);const L=(N,M)=>{const F=l.contentDocument||l.contentWindow.document,W=F.querySelector(`[data-block-id=${N}]`);W&&W.setAttribute("data-drop",M);const z=W.getBoundingClientRect(),$=l.getBoundingClientRect();z.top>=$.top&&z.left>=$.left&&z.bottom<=$.bottom&&z.right<=$.right||(F.documentElement.scrollTop=W.offsetTop-$.top)},D=N=>{I();const M=lodashEs.get(o,"parent.id");M!=="__REACT_ARBORIST_INTERNAL_ROOT__"?pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,{_id:M,position:N}):pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,{position:N})};if(x===applyBinding.ROOT_TEMP_KEY)return jsxRuntime.jsxs("div",{className:"group relative mt-2 w-full cursor-pointer",children:[jsxRuntime.jsx("br",{}),c(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsx("div",{role:"button",onClick:()=>D(-1),className:"h-1 rounded bg-primary opacity-0 duration-200 group-hover:opacity-100",children:jsxRuntime.jsxs("div",{className:"absolute left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 transform items-center gap-x-1 rounded-full bg-primary px-3 py-1 text-[9px] leading-tight text-white hover:bg-primary",children:[jsxRuntime.jsx(reactIcons.PlusIcon,{className:"w-2.4 h-2.5 stroke-[5] text-white"})," ",r("Add block")]})}),jsxRuntime.jsx("br",{})]});const{librarySite:H}=useBuilderProp("flags",{librarySite:!1}),V=React.useMemo(()=>H&&lodashEs.has(g,"_libBlockId")&&!lodashEs.isEmpty(g._libBlockId)&&(c(PERMISSIONS.CREATE_LIBRARY_BLOCK)||c(PERMISSIONS.EDIT_LIBRARY_BLOCK)),[g,c,H]),O=React.useMemo(()=>(g==null?void 0:g._type)==="PartialBlock"||(g==null?void 0:g._type)==="GlobalBlock",[g]);return jsxRuntime.jsx("div",{className:"w-full",children:jsxRuntime.jsxs("div",{onMouseEnter:()=>u(x),onMouseLeave:()=>m(),onClick:P,style:n,"data-node-id":x,ref:a,onDragStart:()=>C(o),onDragEnd:()=>w(o),onDragOver:N=>{N.preventDefault(),L(x,"yes")},onDragLeave:N=>{N.preventDefault(),L(x,"no")},onDrop:N=>{N.preventDefault(),L(x,"no")},children:[c(PERMISSIONS.ADD_BLOCK)&&!h&&(o==null?void 0:o.rowIndex)>0&&(o.parent.isOpen&&canAddChildBlock(lodashEs.get(o,"parent.data._type"))||((T=o==null?void 0:o.parent)==null?void 0:T.id)==="__REACT_ARBORIST_INTERNAL_ROOT__")&&jsxRuntime.jsx("div",{className:"group relative ml-5 h-full w-full cursor-pointer",children:jsxRuntime.jsx("div",{onClick:N=>{N.stopPropagation(),D(o.childIndex)},onMouseEnter:_,onMouseLeave:I,className:"absolute -top-0.5 h-0.5 w-[90%] rounded bg-primary/80 opacity-0 delay-200 duration-200 group-hover:opacity-100",children:jsxRuntime.jsx("div",{className:"absolute left-1/2 top-1/2 flex h-4 w-4 -translate-x-1/2 -translate-y-1/2 transform items-center justify-center rounded-full bg-primary/80 p-1 outline outline-2 outline-white hover:bg-primary/80",children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-2 w-2 stroke-[2] text-white"})})})}),jsxRuntime.jsxs("div",{className:cn("group flex w-full cursor-pointer items-center justify-between space-x-px !rounded p-1 py-0 outline-none",f?"bg-primary/20":"hover:bg-primary/10",b&&canAcceptChildBlock(g._type,"Icon")?"bg-green-200":"",(o==null?void 0:o.id)===E?"bg-primary/10":"",j&&"opacity-20",v?"":"line-through opacity-50",V&&f&&"bg-primary/20 text-primary"),children:[jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx("div",{className:`flex h-4 w-4 rotate-0 transform cursor-pointer items-center justify-center transition-transform duration-100 ${o.isOpen?"rotate-90":""}`,children:p&&jsxRuntime.jsx("button",{onClick:B,type:"button",children:jsxRuntime.jsx(reactIcons.ChevronRightIcon,{className:"h-3 w-3"})})}),jsxRuntime.jsxs("div",{className:cn("leading-1 flex items-center",V&&"text-orange-600/90",V&&f&&"text-orange-800",O&&"text-purple-600/90",O&&f&&"text-purple-800"),children:[S.length>0?jsxRuntime.jsx("div",{className:"text-red-500",children:jsxRuntime.jsx(reactIcons.ExclamationTriangleIcon,{className:"h-3 w-3"})}):jsxRuntime.jsx(TypeIcon,{type:g==null?void 0:g._type}),R?jsxRuntime.jsx(Input,{node:o}):jsxRuntime.jsx("div",{className:"ml-1.5 flex items-center gap-x-1 truncate text-[13px]",onDoubleClick:N=>{N.stopPropagation(),o.edit(),o.deselect()},children:jsxRuntime.jsx("span",{title:getBlockDisplayName(g).length>17?getBlockDisplayName(g):"",children:truncateText(getBlockDisplayName(g),17)})})]})]}),jsxRuntime.jsxs("div",{className:"invisible flex items-center space-x-1.5 pr-px group-hover:visible",children:[canAddChildBlock(g==null?void 0:g._type)&&v&&c(PERMISSIONS.ADD_BLOCK)?jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,{_id:x}),className:"cursor-pointer rounded bg-transparent p-px hover:bg-primary/10",asChild:!0,children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-4 w-4"})}),jsxRuntime.jsx(tooltip.TooltipContent,{className:"isolate z-[9999]",side:"bottom",children:r("Add block inside")})]}):null,jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{onClick:N=>{N.stopPropagation(),i([x],{_show:!v}),o.isOpen&&o.toggle()},className:"cursor-pointer rounded bg-transparent p-0.5 hover:bg-primary/10",asChild:!0,children:v?jsxRuntime.jsx(reactIcons.EyeClosedIcon,{className:"h-4 w-4"}):jsxRuntime.jsx(reactIcons.EyeOpenIcon,{className:"h-4 w-4"})}),jsxRuntime.jsx(tooltip.TooltipContent,{className:"isolate z-[9999] text-xs",side:"bottom",children:r(v?"Hide the block from page":"Show the block on page")})]}),jsxRuntime.jsx(BlockMoreOptions,{node:o,id:x,children:jsxRuntime.jsx("div",{className:"cursor-pointer rounded bg-transparent p-px hover:bg-primary/10",children:jsxRuntime.jsx(reactIcons.DotsVerticalIcon,{className:"h-3 w-3"})})})]})]})]})})}),PasteAtRootContextMenu=({parentContext:o,setParentContext:n})=>{const{t:a}=reactI18next.useTranslation(),{canPaste:r,pasteBlocks:i}=usePasteBlocks(),l=useBuilderProp("flags.copyPaste",!0);return React.useEffect(()=>{r("root")||n(null)},[r("root")]),!o||!r("root")||!l?null:jsxRuntime.jsx("div",{className:"absolute inset-0",children:jsxRuntime.jsxs(tooltip.DropdownMenu,{open:!0,onOpenChange:()=>n(null),children:[jsxRuntime.jsx(tooltip.DropdownMenuTrigger,{className:"hidden"}),jsxRuntime.jsx(tooltip.DropdownMenuContent,{className:"absolute w-28 p-1 text-xs",style:{top:o.y,left:o.x},children:jsxRuntime.jsxs(tooltip.DropdownMenuItem,{className:"flex items-center gap-x-4 text-xs",onClick:()=>{i("root"),n(null)},children:[jsxRuntime.jsx(reactIcons.CardStackIcon,{})," ",a("Paste")]})})]})})},useCanMove=()=>{const[o]=useBlocksStore();return(n,a)=>{var l;const r=(l=lodashEs.find(o,{_id:a}))==null?void 0:l._type,i=lodashEs.first(n.map(c=>{var d;return(d=lodashEs.find(o,{_id:c}))==null?void 0:d._type}));return canAcceptChildBlock(r,i)}},ListTree=()=>{const[treeData]=jotai.useAtom(treeDSBlocks),[ids,setIds]=useSelectedBlockIds(),[cutBlocksIds]=useCutBlockIds(),updateBlockProps=useUpdateBlocksProps(),[,setStyleBlocks]=useSelectedStylingBlocks(),{moveBlocks}=useBlocksStoreUndoableActions(),canMove=useCanMove(),treeRef=React.useRef(null),[,setTreeRef]=jotai.useAtom(treeRefAtom),{t}=reactI18next.useTranslation(),[parentContext,setParentContext]=React.useState(null),clearSelection=()=>{setIds([]),setStyleBlocks([])},filteredTreeData=React.useMemo(()=>{const o=(a,r)=>a.filter(i=>!r.includes(i._id)).map(i=>({...i,children:i.children?o(i.children,r):[]}));return[...o(treeData,cutBlocksIds),{_type:applyBinding.ROOT_TEMP_KEY,_id:applyBinding.ROOT_TEMP_KEY,children:[]}]},[treeData,cutBlocksIds]),onRename=({id:o,name:n,node:a})=>{updateBlockProps([o],{_name:n},a.data._name)},onMove=({dragIds:o,parentId:n,index:a})=>{canMove(o,n)&&moveBlocks(o,n,a)},onSelect=o=>{if(o.length===0)return;const n=o[0]?o[0].id:"";setStyleBlocks([]),setIds([n])},onContextMenu=o=>{var r;o.preventDefault(),parentContext&&setParentContext(null);const n=o.target,a=n.getAttribute("data-node-id")||((r=n.closest("[data-node-id]"))==null?void 0:r.getAttribute("data-node-id"));a?(setStyleBlocks([]),setIds([a])):(setStyleBlocks([]),setIds([]),setParentContext({x:o.clientX,y:o.clientY}))},debouncedDisableDrop=web.useDebouncedCallback(({parentNode:o,dragNodes:n})=>{var a;return(o==null?void 0:o.data._type)===applyBinding.ROOT_TEMP_KEY||!canAcceptChildBlock(o==null?void 0:o.data._type,(a=n[0])==null?void 0:a.data._type)},[],300),handleKeyDown=e=>{if(!treeRef.current)return;const tree=treeRef.current,selectedNode=tree.selectedNodes[0];if(!selectedNode)return;setIds[selectedNode.id],setStyleBlocks([]);const isLeaf=!selectedNode.isInternal,isClosed=!selectedNode.isOpen,isOpen=selectedNode.isOpen,shortcut=defaultShortcuts.find(s=>s.key===e.key&&(!s.when||eval(s.when)));if(shortcut)switch(e.preventDefault(),shortcut.command){case"selectNext":selectNext(tree);break;case"selectPrev":selectPrev(tree);break;case"selectParent":selectParent(tree,isLeaf||isClosed);break;case"close":close(tree,isOpen);break;case"open":open(tree,isClosed);break;case"selectFirst":selectFirst(tree);break;case"selectLast":selectLast(tree);break}};React.useEffect(()=>{const o=()=>{treeRef.current&&setTreeRef(treeRef.current)};o();const n=new MutationObserver(o);return n.observe(document.body,{childList:!0,subtree:!0}),()=>n.disconnect()},[setTreeRef]);const{hasPermission}=usePermissions();return lodashEs.isEmpty(treeData)?jsxRuntime.jsx("div",{children:jsxRuntime.jsx("div",{className:"mt-10 flex h-full w-full items-center justify-center p-8",children:jsxRuntime.jsxs("div",{className:"flex flex-col items-center space-y-6 text-center",children:[jsxRuntime.jsx("div",{className:"rounded-full bg-muted p-6",children:jsxRuntime.jsx(reactIcons.StackIcon,{className:"h-12 w-12 text-muted-foreground"})}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("h3",{className:"text-lg font-semibold text-foreground",children:t("This page is empty")}),jsxRuntime.jsx("p",{className:"max-w-sm text-sm text-muted-foreground",children:t("Get started by adding your first block to begin building your page")})]}),hasPermission(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsxs(tooltip.Button,{onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK),className:"bg-primary shadow-sm hover:bg-primary/90",size:"sm",children:[jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-4 w-4"}),t("Add Block")]})]})})}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:commonFunctions.cn("flex h-full select-none flex-col space-y-1"),onClick:()=>clearSelection(),children:jsxRuntime.jsxs("div",{id:"outline-view ",className:"no-scrollbar h-full overflow-y-auto text-sm",onKeyDown:o=>{treeRef.current.isEditing||handleKeyDown(o)},children:[jsxRuntime.jsxs("div",{className:"mb-2 flex items-center justify-end gap-x-1 pb-2 text-sm text-muted-foreground",children:[jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(tooltip.Button,{className:"h-fit p-1",onClick:()=>{var o;return(o=treeRef==null?void 0:treeRef.current)==null?void 0:o.openAll()},variant:"ghost",size:"sm",children:jsxRuntime.jsx(reactIcons.DoubleArrowDownIcon,{className:"h-2 w-2"})})}),jsxRuntime.jsx(tooltip.TooltipContent,{className:"isolate z-[9999]",children:t("Expand all")})]}),jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(tooltip.Button,{className:"h-fit p-1",onClick:()=>{var o;return(o=treeRef==null?void 0:treeRef.current)==null?void 0:o.closeAll()},variant:"ghost",size:"sm",children:jsxRuntime.jsx(reactIcons.DoubleArrowUpIcon,{className:"h-2 w-2"})})}),jsxRuntime.jsx(tooltip.TooltipContent,{className:"isolate z-[9999]",children:t("Collapse all")})]})]}),jsxRuntime.jsx("div",{className:"group relative z-30 ml-5 w-full cursor-pointer",children:jsxRuntime.jsx("div",{onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,{position:0}),className:"h-1 w-[90%] rounded bg-primary opacity-0 duration-200 group-hover:opacity-100",children:jsxRuntime.jsx("div",{className:"absolute left-[45%] top-1/2 flex h-4 w-4 -translate-x-1/2 -translate-y-1/2 transform items-center justify-center rounded-full bg-primary p-1 outline outline-2 outline-white hover:bg-primary",children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-3 w-3 stroke-[3] text-white"})})})}),jsxRuntime.jsx("div",{children:jsxRuntime.jsx("div",{role:"treeitem","aria-level":0,"aria-selected":!0,"aria-expanded":!1,onClick:()=>setIds([]),className:"flex h-full items-center border-b border-transparent",children:jsxRuntime.jsxs("div",{className:commonFunctions.cn("group flex w-full cursor-pointer items-center justify-between space-x-px !rounded p-1 py-0 outline-none",ids.length===0?"bg-primary/20":""),children:[jsxRuntime.jsxs("div",{className:"leading-1 flex items-center",children:[jsxRuntime.jsx(reactIcons.CardStackIcon,{className:"h-3 w-3 flex-shrink-0 rotate-180"}),jsxRuntime.jsx("div",{className:"ml-1.5 flex items-center gap-x-1 truncate text-[13px]",children:"Body"})]}),jsxRuntime.jsx(BlockMoreOptions,{node:"BODY",id:"BODY",children:jsxRuntime.jsx("div",{className:"hidden cursor-pointer rounded bg-transparent p-px hover:bg-primary/10 group-hover:block",children:jsxRuntime.jsx(reactIcons.DotsVerticalIcon,{className:"h-3 w-3"})})})]})})}),jsxRuntime.jsx(reactArborist.Tree,{ref:treeRef,height:window.innerHeight-160,className:"no-scrollbar !h-full max-w-full space-y-1 !overflow-y-auto !overflow-x-hidden",rowClassName:"flex items-center h-full border-b border-transparent",selection:ids[0]||"",onRename,openByDefault:!1,onMove,data:[...filteredTreeData],renderCursor:DefaultCursor,onSelect,childrenAccessor:o=>o.children,width:"100%",rowHeight:25,renderDragPreview:DefaultDragPreview,indent:10,onContextMenu,disableDrop:debouncedDisableDrop,idAccessor:"_id",children:Node$1})]})}),jsxRuntime.jsx(SaveToLibraryModal,{}),jsxRuntime.jsx(PasteAtRootContextMenu,{parentContext,setParentContext})]})},BorderRadiusInput=({value:o,onChange:n,disabled:a})=>{const[r,i]=React.useState(o),l=web.useThrottledCallback(n,[o],200,!0);return jsxRuntime.jsx(tooltip.Slider,{min:0,step:1,max:50,disabled:a,value:[Number(r.replace("px",""))],onValueChange:c=>{i(c[0].toString()+"px"),l(c[0].toString())},className:"flex-1 cursor-pointer"})},ColorPickerInput=({value:o,onChange:n})=>{const a=lodashEs.debounce(r=>n(r),200);return jsxRuntime.jsx("div",{className:"relative flex h-6 w-6 cursor-pointer rounded-lg border border-border",style:{backgroundColor:o},children:jsxRuntime.jsx("input",{type:"color",value:o.startsWith("#")?o:"#000000",onChange:r=>{const i=r.target.value;/^#[0-9A-F]{6}$/i.test(i)&&a(i)},className:"absolute inset-0 h-full w-full cursor-pointer rounded-lg border-0 opacity-0"})})},FontSelector=({label:o,value:n,onChange:a})=>{const r=runtime.useRegisteredFonts(),{t:i}=reactI18next.useTranslation();return React.useEffect(()=>{r.some(l=>l.family===n)||a(r[0].family)},[n,a]),jsxRuntime.jsxs("div",{className:"space-y-0.5",children:[jsxRuntime.jsx(tooltip.Label,{className:"mb-1 block text-xs text-gray-600",children:i(lodashEs.startCase(o))}),jsxRuntime.jsxs(tooltip.Select,{value:n,onValueChange:a,children:[jsxRuntime.jsx(tooltip.SelectTrigger,{className:"h-8 w-full text-xs text-black",children:jsxRuntime.jsx(tooltip.SelectValue,{placeholder:i("Select font")})}),jsxRuntime.jsx(tooltip.SelectContent,{children:r.map(l=>jsxRuntime.jsx(tooltip.SelectItem,{value:l.family,children:l.family},l.family))})]})]})},defaultShadcnPreset={fontFamily:{heading:"Poppins",body:"Poppins"},borderRadius:"6px",colors:{background:["#ffffff","#0a0a0a"],foreground:["#0a0a0a","#fafafa"],primary:["#171717","#e5e5e5"],"primary-foreground":["#fafafa","#171717"],secondary:["#f5f5f5","#262626"],"secondary-foreground":["#171717","#fafafa"],muted:["#f5f5f5","#262626"],"muted-foreground":["#737373","#a1a1a1"],accent:["#f5f5f5","#404040"],"accent-foreground":["#171717","#fafafa"],destructive:["#e7000b","#ff6467"],"destructive-foreground":["#ffffff","#fafafa"],border:["#e5e5e5","#282828"],input:["#e5e5e5","#343434"],ring:["#a1a1a1","#737373"],card:["#ffffff","#171717"],"card-foreground":["#0a0a0a","#fafafa"],popover:["#ffffff","#262626"],"popover-foreground":["#0a0a0a","#fafafa"]}},twitter={fontFamily:{heading:"Poppins",body:"Poppins"},borderRadius:"4px",colors:{background:["#ffffff","#000000"],foreground:["#0f1419","#e7e9ea"],primary:["#1e9df1","#1c9cf0"],"primary-foreground":["#ffffff","#ffffff"],secondary:["#0f1419","#f0f3f4"],"secondary-foreground":["#ffffff","#0f1419"],muted:["#e5e5e6","#181818"],"muted-foreground":["#0f1419","#72767a"],accent:["#e3ecf6","#061622"],"accent-foreground":["#1e9df1","#1c9cf0"],destructive:["#f4212e","#f4212e"],"destructive-foreground":["#ffffff","#ffffff"],border:["#e1eaef","#242628"],input:["#f7f9fa","#22303c"],ring:["#1da1f2","#1da1f2"],card:["#f7f8f8","#17181c"],"card-foreground":["#0f1419","#d9d9d9"],popover:["#ffffff","#000000"],"popover-foreground":["#0f1419","#e7e9ea"],sidebar:["#f7f8f8","#17181c"],"sidebar-foreground":["#0f1419","#d9d9d9"],"sidebar-primary":["#1e9df1","#1da1f2"],"sidebar-primary-foreground":["#ffffff","#ffffff"],"sidebar-accent":["#e3ecf6","#061622"],"sidebar-accent-foreground":["#1e9df1","#1c9cf0"],"sidebar-border":["#e1e8ed","#38444d"],"sidebar-ring":["#1da1f2","#1da1f2"]}},solarized={fontFamily:{heading:"Geist",body:"Geist"},borderRadius:"4px",colors:{background:["#fdf6e3","#002b36"],foreground:["#073642","#93a1a1"],primary:["#d33682","#d33682"],"primary-foreground":["#ffffff","#ffffff"],secondary:["#2aa198","#2aa198"],"secondary-foreground":["#ffffff","#ffffff"],muted:["#93a1a1","#586e75"],"muted-foreground":["#073642","#93a1a1"],accent:["#cb4b16","#cb4b16"],"accent-foreground":["#ffffff","#ffffff"],destructive:["#dc322f","#dc322f"],"destructive-foreground":["#ffffff","#ffffff"],border:["#839496","#586e75"],input:["#839496","#586e75"],ring:["#d33682","#d33682"],card:["#eee8d5","#073642"],"card-foreground":["#073642","#93a1a1"],popover:["#eee8d5","#073642"],"popover-foreground":["#073642","#93a1a1"]}},claude={fontFamily:{heading:"Poppins",body:"Poppins"},borderRadius:"6px",colors:{background:["#faf9f5","#262624"],foreground:["#3d3929","#c3c0b6"],primary:["#c96442","#d97757"],"primary-foreground":["#ffffff","#ffffff"],secondary:["#e9e6dc","#faf9f5"],"secondary-foreground":["#535146","#30302e"],muted:["#ede9de","#1b1b19"],"muted-foreground":["#83827d","#b7b5a9"],accent:["#e9e6dc","#1a1915"],"accent-foreground":["#28261b","#f5f4ee"],destructive:["#141413","#ef4444"],"destructive-foreground":["#ffffff","#ffffff"],border:["#dad9d4","#3e3e38"],input:["#b4b2a7","#52514a"],ring:["#c96442","#d97757"],card:["#faf9f5","#262624"],"card-foreground":["#141413","#faf9f5"],popover:["#ffffff","#30302e"],"popover-foreground":["#28261b","#e5e5e2"]}},supabase={fontFamily:{heading:"Inter",body:"Inter"},borderRadius:"6px",colors:{background:["#fff9f5","#2a2024"],foreground:["#3d3436","#f2e9e4"],primary:["#ff7e5f","#ff7e5f"],"primary-foreground":["#ffffff","#ffffff"],secondary:["#ffedea","#463a41"],"secondary-foreground":["#b35340","#f2e9e4"],muted:["#fff0eb","#392f35"],"muted-foreground":["#78716c","#d7c6bc"],accent:["#feb47b","#feb47b"],"accent-foreground":["#3d3436","#2a2024"],destructive:["#e63946","#e63946"],"destructive-foreground":["#ffffff","#ffffff"],border:["#ffe0d6","#463a41"],input:["#ffe0d6","#463a41"],ring:["#ff7e5f","#ff7e5f"],card:["#ffffff","#392f35"],"card-foreground":["#3d3436","#f2e9e4"],popover:["#ffffff","#392f35"],"popover-foreground":["#3d3436","#f2e9e4"]}},LazyCssImportModal=React.lazy(()=>Promise.resolve().then(()=>require("./css-import-modal-bGWZSlqv.cjs")).then(o=>({default:o.CssImportModal}))),PREV_THEME_KEY="chai-builder-previous-theme",DEFAULT_THEME_PRESET=[{shadcn_default:defaultShadcnPreset},{twitter_theme:twitter},{solarized_theme:solarized},{claude_theme:claude},{supabase_theme:supabase}],setPreviousTheme=o=>{if(!(typeof window>"u"))try{localStorage.setItem(PREV_THEME_KEY,JSON.stringify(o))}catch(n){console.warn("Failed to save previous theme to localStorage:",n)}},clearPreviousTheme=()=>{if(!(typeof window>"u"))try{localStorage.removeItem(PREV_THEME_KEY)}catch(o){console.warn("Failed to clear previous theme from localStorage:",o)}},ThemeConfigPanel=React__namespace.memo(({className:o=""})=>{const[n,a]=useDarkMode(),[r,i]=React__namespace.useState(""),[l,c]=React__namespace.useState(!1),d=useBuilderProp("themePresets",[]),p=useBuilderProp("themePanelComponent",null),{hasPermission:u}=usePermissions(),m=useBuilderProp("flags.importTheme",!0),h=useBuilderProp("flags.darkMode",!0),x=useIncrementActionsCount();(!d||d.length===0)&&DEFAULT_THEME_PRESET.map(w=>{d.push(w)});const[g,f]=useTheme(),b=useThemeOptions(),{t:j}=reactI18next.useTranslation(),R=React__namespace.useCallback(w=>{const E={...g};setPreviousTheme(E),f(w),x(),sonner.toast.success("Theme updated",{action:{label:jsxRuntime.jsxs("span",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(reactIcons.ResetIcon,{className:"h-4 w-4"})," Undo"]}),onClick:()=>{f(E),clearPreviousTheme(),sonner.toast.dismiss()}},closeButton:!0,duration:15e3})},[g,f,x]),y=()=>{const w=d.find(E=>Object.keys(E)[0]===r);if(w){const E=Object.values(w)[0];E&&typeof E=="object"&&"fontFamily"in E&&"borderRadius"in E&&"colors"in E?(R(E),i(""),x()):console.error("Invalid preset structure:",E)}else console.error("Preset not found:",r)},k=w=>{R(w),i(""),x()},S=web.useDebouncedCallback((w,E)=>{f(()=>({...g,fontFamily:{...g.fontFamily,[w.replace(/font-/g,"")]:E}})),x()},[g,x],200),v=React__namespace.useCallback(w=>{f(()=>({...g,borderRadius:`${w}px`})),x()},[g,x]),B=web.useDebouncedCallback((w,E)=>{f(()=>{const A=lodashEs.get(g,`colors.${w}`);return n?lodashEs.set(A,1,E):lodashEs.set(A,0,E),x(),{...g,colors:{...g.colors,[w]:A}}})},[g,x],200),C=w=>jsxRuntime.jsx("div",{className:"grid grid-cols-1",children:Object.entries(w.items).map(([E])=>{const A=lodashEs.get(g,`colors.${E}.${n?1:0}`);return A?jsxRuntime.jsxs("div",{id:`theme-${E}`,className:"mt-1 flex items-center gap-x-2",children:[jsxRuntime.jsx(ColorPickerInput,{value:A,onChange:_=>B(E,_)}),jsxRuntime.jsx(tooltip.Label,{className:"text-xs font-normal leading-tight",children:E.split(/(?=[A-Z])/).join(" ").replace(/-/g," ").split(" ").map(_=>_.charAt(0).toUpperCase()+_.slice(1)).join(" ")+(!E.toLowerCase().includes("foreground")&&!E.toLowerCase().includes("border")&&!E.toLowerCase().includes("input")&&!E.toLowerCase().includes("ring")&&!E.toLowerCase().includes("background")?" Background":"")})]},E):null})});return u("edit_theme")?jsxRuntime.jsxs("div",{className:"relative w-full",children:[jsxRuntime.jsxs("div",{className:commonFunctions.cn("no-scrollbar h-full w-full overflow-y-auto",o),children:[d.length>0&&jsxRuntime.jsxs("div",{className:"mx-0 my-2 flex flex-col gap-1 py-2",children:[jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between",children:[jsxRuntime.jsx(tooltip.Label,{className:"text-sm",children:j("Presets")}),jsxRuntime.jsx("div",{className:"flex gap-2",children:m&&jsxRuntime.jsxs(tooltip.Button,{className:"px-1",variant:"link",size:"sm",onClick:()=>c(!0),children:[jsxRuntime.jsx(reactIcons.UploadIcon,{className:"h-4 w-4"}),j("Import theme")]})})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-0",children:[jsxRuntime.jsx("div",{className:"w-[70%]",children:jsxRuntime.jsxs(tooltip.Select,{value:r,onValueChange:i,children:[jsxRuntime.jsx(tooltip.SelectTrigger,{className:"h-9 w-full text-sm",children:jsxRuntime.jsx(tooltip.SelectValue,{placeholder:j("Select preset")})}),jsxRuntime.jsx(tooltip.SelectContent,{children:Array.isArray(d)&&d.map(w=>{const E=Object.keys(w)[0],A=E.replaceAll("_"," ");return jsxRuntime.jsx(tooltip.SelectItem,{value:E,children:lodashEs.capitalize(A)},E)})})]})}),jsxRuntime.jsx("div",{className:"w-[25%]",children:jsxRuntime.jsx(tooltip.Button,{className:"w-full text-sm",disabled:!r,onClick:y,children:j("Apply")})})]})]}),jsxRuntime.jsx(tooltip.Separator,{}),jsxRuntime.jsxs("div",{className:commonFunctions.cn("my-2 space-y-3",o),children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(reactIcons.TextIcon,{className:"h-3 w-3 text-gray-600"}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-gray-700",children:j("Typography")})]}),(b==null?void 0:b.fontFamily)&&jsxRuntime.jsx("div",{className:"space-y-2",children:Object.entries(b.fontFamily).map(([w,E])=>jsxRuntime.jsx(FontSelector,{label:w,value:g.fontFamily[w.replace(/font-/g,"")]||E[Object.keys(E)[0]],onChange:A=>S(w,A)},w))}),jsxRuntime.jsx(tooltip.Separator,{}),(b==null?void 0:b.borderRadius)&&jsxRuntime.jsxs("div",{className:"space-y-0.5",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(reactIcons.CornerTopRightIcon,{className:"h-3 w-3 text-gray-600"}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-gray-700",children:j("Border Radius")})]}),jsxRuntime.jsx(tooltip.Badge,{variant:"secondary",className:"text-xs",children:g.borderRadius})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-4 py-2",children:jsxRuntime.jsx(BorderRadiusInput,{value:g.borderRadius,onChange:v})})]}),jsxRuntime.jsx(tooltip.Separator,{}),(b==null?void 0:b.colors)&&jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(reactIcons.MixerHorizontalIcon,{className:"h-3 w-3 text-gray-600"}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-gray-700",children:j("Colors")})]}),h&&jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(reactIcons.SunIcon,{className:"h-4 w-4"}),jsxRuntime.jsx(tooltip.Switch,{checked:n,onCheckedChange:w=>a(w),"aria-label":j("Toggle dark mode"),className:"mx-1"}),jsxRuntime.jsx(reactIcons.MoonIcon,{className:"h-4 w-4"})]})]}),jsxRuntime.jsx("div",{className:"space-y-2",children:b.colors.map(w=>C(w))})]}),jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx("div",{children:j("Loading...")}),children:l&&m&&jsxRuntime.jsx(LazyCssImportModal,{open:l,onOpenChange:c,onImport:k})})]}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]}),p&&jsxRuntime.jsx("div",{className:"absolute bottom-4 w-full",children:React__namespace.createElement(p)})]}):jsxRuntime.jsx("div",{className:"relative w-full",children:jsxRuntime.jsx("div",{className:commonFunctions.cn("no-scrollbar h-full w-full overflow-y-auto text-center",o),children:jsxRuntime.jsx("div",{className:"mt-10 h-full items-center justify-center gap-2 text-muted-foreground",children:jsxRuntime.jsx("p",{className:"text-sm",children:j("You don't have permission to edit the theme. Please contact your administrator to get access.")})})})})}),Core="Core",Import="Import",Breakpoints="Breakpoints",Clear="Clear",Cancel="Cancel",Yes="Yes",Preview="Preview",Settings="Settings",Styling="Style",SVG_code="Enter SVG code here",Remove="Remove",Choose="Choose",Cut="Cut",Copy="Copy",Paste="Paste",Delete="Delete",classes="classes",Theme="Theme",Outline="Outline",Copied="Copied",Stop="Stop",Edit="Edit",Tag="Tag",Value="Value",URL$1="URL",Images="Images",Library="Library",Blocks="Blocks",Basic="Basic",Media="Media",Advanced="Advanced",Form="Form",Groups="Groups",Accordions="Accordions",Buttons="Buttons",Layouts="Layouts",FAQ="FAQ",Hero="Hero",Features="Features",Footer="Footer",Navbar="Navbar",Icons="Icons",Testimonials="Testimonials",Blog="Blog",Saved="Saved",Unsaved="Unsaved",Randomize="Randomize",Classes="Classes",All="All",Undo="Undo",Redo="Redo",Duplicate="Duplicate",Close="Close",Selected="Selected",Select="Select",Attributes="Attributes",apply="apply",presets="presets",Orientation="Orientation",Color="Color",Upload="Upload",Apply="Apply",Back="Back",Insert="Insert",Rename="Rename",Partials="Partials",Happy="Happy",Sad="Sad",Retry="Retry",canvas_empty="Canvas is empty",Presets="Presets",No="No",Saving="Saving",theme_config={heading_font:"Heading Font",body_font:"Body Font",rounded_corner:"Rounded Corners",primary:"Primary",secondary:"Secondary",background:"Background",text_color:"Text Color",background_dark_mode:"Background (Dark Mode)",text_color_dark_mode:"Text Color (Dark Mode)"},web_blocks={box:"box",tag:"Tag",div:"div",level:"Level",header:"header",footer:"footer",section:"section",article:"article",aside:"aside",main:"main",nav:"navigation",figure:"figure",details:"details",summary:"summary",dialog:"dialog",strike:"strike",caption:"caption",legend:"legend",figcaption:"figure caption",mark:"mark",background_image:"Background Image",label:"Label",default:"default",icon_size:"Icon Size",icon_position:"Icon Position",start:"Start",end:"End",button:"Button",custom_html:"Custom HTML",html_code:"HTML Code",default_snippet:"The HTML snippet goes here...",placeholder:"Enter custom HTML code here",custom_script:"Custom Script",dark_mode:"Dark Mode",divider:"Divider",empty_box:"Empty Box",heading:"Heading",image:"Image",alt:"Alt",width:"Width",height:"Height",video:"Video",span:"Span",content:"Content",icon:"Icon",richtext:"Rich Text",list:"List",list_type:"List Type",listitem:"List Item",link:"Link",list_item:"List Item",none:"None",disc:"Disc",number:"Number",paragraph:"Paragraph",lightbox_link:"Lightbox Link",href:"Link",type:"Type",iframe:"iframe",inline:"inline",ajax:"ajax",autoplay:"Video autoplay",max_width:"Max Width",backdrop_color:"Background Color",gallery_name:"Gallery Name",slot:"Slot",empty_slot:"Empty Slot",text:"Text",video_url:"Video URL",controls:"Show Controls",loop:"Loop",muted:"Muted",checkbox:"Checkbox",required:"Required",checked:"Checked",submit_button:"Submit Button",form:"Form",submit_url:"Submit URL",error_message:"Error Message",success_message:"Success Message",input:"Input",value:"Value",show_label:"Show Label",field_name:"Field Name",radio:"Radio",multiple:"Multiple",options:"Options",select:"Select",multiple_choice:"Multiple Choice",textarea:"Textarea",rows:"Rows"},Add="Add",Save="Save",Screen="Screen",lngEn={"Add block":"Add Block","Add Block":"Add Block","Add blocks":"Add blocks","Add inside":"Add inside","Add before":"Add before","Add after":"Add after","Add block inside":"Add block inside","Add field":"Add field","Enter or paste TailwindCSS HTML snippet":"Enter or paste TailwindCSS HTML snippet","Click to add block to page":"Click to add block to page",Core,"Custom Blocks":"Custom Blocks","UI Library":"UI Library",Import,"Use HTML snippets from Tailwind CSS component libraries":"Use HTML snippets from Tailwind CSS component libraries","Tailwind HTML snippet":"Tailwind HTML snippet","Enter your code snippet here":"Enter your code snippet here","Import HTML":"Import HTML","Imported HTML Note":"NOTE: Imported html will be added to the currently selected block. If no block is selected, the html will be added to the page.","Dark Mode":"Dark Mode","This page has no blocks. Add a block by clicking the + button":"This page has no blocks. Add a block by clicking the + button","This page is empty":"This page is empty","Please select a block to edit settings or styles":"Please select a block to edit settings or styles","Please select a block to Ask AI":"Please select a block to ask AI","Please select a styling block":"Please select a styling block","Drop your block here":"Drop your block here","Use setting":"Use setting","Mobile (XS)":"Mobile (XS)","Styles set here are applied to all screen unless edited at higher breakpoint":"Styles set here are applied to all screen unless edited at higher breakpoint","Mobile landscape (SM)":"Mobile landscape (SM)","Styles set here are applied at 640px and up unless edited at higher breakpoint":"Styles set here are applied at 640px and up unless edited at higher breakpoint","Tablet (MD)":"Tablet (MD)","Styles set here are applied at 768px and up":"Styles set here are applied at 768px and up","Tablet Landscape (LG)":"Tablet Landscape (LG)","Styles set here are applied at 1024px and up unless edited at higher breakpoint":"Styles set here are applied at 1024px and up unless edited at higher breakpoint","Desktop (XL)":"Desktop (XL)","Styles set here are applied at 1280px and up unless edited at higher breakpoint":"Styles set here are applied at 1280px and up unless edited at higher breakpoint","Large Desktop (2XL)":"Large Desktop (2XL)","Styles set here are applied at 1536px and up":"Styles set here are applied at 1536px and up",Breakpoints,Clear,"Clear whole canvas?":"Clear whole canvas?","Are you sure you want to clear the whole canvas?":"Are you sure you want to clear the whole canvas?",Cancel,Yes,Preview,Settings,Styling,SVG_code,"Paste SVG_code":"Choose icon or paste SVG code","Enter Key":"Enter Key","Data Provider":"Data Provider","Remove Provider Confirmation":"Are you sure you want to remove <span class='text-blue-500'>{name}</span> provider?","Your data provider will be removed from this page and all added data binding will be not visible on blocks.":"Your data provider will be removed from this page and all added data binding will be not visible on blocks.",Remove,"You have no data providers registered. Please add a data provider to your project.":"You have no data providers registered. Please add a data provider to your project.","Learn more":"Learn more","Add data providers:":"Add data providers:","Select a provider":"Select a provider",Choose,"Page data providers:":"Page data providers:","View Data":"View Data","Mark as Global":"Mark as Global","Note: Global blocks are single instances. Editing global blocks will be reflected on all pages using these blocks.":"Note: Global blocks are single instances. Editing global blocks will be reflected on all pages using these blocks.","Global blocks are indicated with":"Global blocks are indicated with","Global blocks are available under 'Global' category":"Global blocks are available under 'Global' category","Enter global block name":"Enter global block name","Eg: Header, Footer":"Eg: Header, Footer","{length} blocks selected.":"{length} blocks selected.",Cut,Copy,Paste,Delete,"Clear Selection":"Clear Selection","This is dev mode. Visit":"This is dev mode. Visit","to see page preview":"to see page preview",classes,Theme,Outline,"Not supported":"Not supported","Please use Chrome, Firefox or Safari":"Please use Chrome, Firefox or Safari","Download Complete":"Download complete",Copied,"Enter Classes":"Enter classes separated by space","Ask AI":"Ask AI","Edit with AI":"Edit with AI","Generating... Please wait...":"Generating... Please wait...","Saving... Please wait...":"Saving... Please wait...","Deleting... Please wait...":"Deleting... Please wait...",Stop,"E.g.: This page is about an AI assistant app called Chai Studio. It allows users to create beautiful webpages and edit content with AI":"E.g.: This page is about an AI assistant app called Chai Studio. It allows users to create beautiful webpages and edit content with AI.","Ask AI to edit styles":"Ask AI to edit styles","Ask AI to edit content":"Ask AI to edit content","AI Context":"AI Context","Select Block for AI":"Select a block to edit with AI","Select Block to Edit":"Please select a block to edit",Edit,"Describe this page. E.g.: This page is about...":"Describe this page. E.g.: This page is about...",Tag,Value,"Background Image":"Background Image","Enter image URL":"Enter image URL","Enter URL":"Enter URL",URL:URL$1,"Replace image":"Replace image","Choose image":"Choose image",Images,Library,Blocks,Basic,Media,Advanced,Form,"Choose Icon or SVG":"Choose an icon or enter SVG",Groups,"UI Libraries":"UI Libraries",Accordions,Buttons,Layouts,"Choose Library":"Choose library","No Library Found":"No library found.",FAQ,Hero,Features,Footer,Navbar,Icons,Testimonials,Blog,"Remove context":"Remove context","Yes, Delete":"Yes, Delete","AI Context Updated":"AI Context Updated","You can now ask AI to edit your content.":"You can now ask AI to edit your content.",Saved,Unsaved,"Saving...":"Saving...","Improve writing":"Improve writing","Replace placeholder content":"Replace placeholder content","Discard current placeholder content and replace with meaningful relevant content.":"Discard current placeholder content and replace with meaningful relevant content.","Fix grammar":"Fix grammar","Fix grammar in all text elements. Ensuring the text is grammatically correct and free of errors.":"Fix grammar in all text elements. Ensuring the text is grammatically correct and free of errors.","Make longer":"Make longer","Make all text elements longer.":"Make all text elements longer.","Make shorter":"Make shorter","Make all text elements shorter.":"Make all text elements shorter.","Add emojis":"Add emojis","Add emojis to text elements if relevant.":"Add emojis to text elements if relevant.",Randomize,"Randomize all text elements.":"Randomize all text elements.","Edit Block":"Edit Block","AI Assistant":"AI Assistant","Theme Config":{"Heading Font":"Heading Font","Body Font":"Body Font","Rounded Corner":"Rounded Corners",Primary:"Primary",Secondary:"Secondary",Background:"Background","Text Color":"Text Color","Background Dark Mode":"Background (Dark Mode)","Text Color Dark Mode":"Text Color (Dark Mode)","Reset styles":"Reset styles"},"Copy classes to clipboard":"Copy classes to clipboard","Classes copied to clipboard":"Classes copied to clipboard",Classes,All,"Enter classes separated by space":"Enter classes separated by space","Show hidden blocks":"Show hidden blocks","Expand all":"Expand all","Collapse all":"Collapse all","Choose library":"Choose library","Close Preview":"Close Preview",Error:"Error","Failed to copy template":"Failed to copy template","Total tokens used":"Total tokens used","Updated AI Context":"Updated AI Context","You can now Ask AI to edit your content":"You can now Ask AI to edit your content","Tell about this page eg this page is about":"Tell about this page eg this page is about..","Delete Context":"Delete Context","Keyboard shortcuts":"Keyboard shortcuts",Undo,Redo,Duplicate,"Deselect blocks":"Deselect blocks","Delete block":"Delete block","Save page":"Save page","Scripts will be only executed in preview and live mode.":"Scripts will be only executed in preview and live mode.","HTML Code Editor |":"HTML Code Editor |",Close,"Coming soon":"Coming soon",Selected,Select,"Choose Builder Layout":"Choose Builder Layout","Single side panel":"Single side panel","Suitable for smaller screens. Bigger canvas size.":"Suitable for smaller screens. Bigger canvas size.","Dual side panel":"Dual side panel","Suitable for larger screens. Smaller canvas size.":"Suitable for larger screens. Smaller canvas size.","Dual side panel advanced":"Dual side panel advanced","Suitable for heavy styling & block editing. Setting are always visible.":"Suitable for heavy styling & block editing. Setting are always visible.","Block Settings":"Block Settings","Visibility settings":"Visibility settings","Show on canvas":"Show on canvas",Attributes,"Apply Presets":"Apply Presets",apply,presets,"Global presets":"Global presets",Orientation,Color,"Please select an image":"Please select an image","click to upload":"click to upload","SVG, PNG, JPG or GIF (Max. 2mb)":"SVG, PNG, JPG or GIF (Max. 2mb)","Uploading...":"Uploading...",Upload,"Something went wrong":"Something went wrong","Fetching...":"Fetching...","No images found":"No images found","It looks like you haven't uploaded any images yet. Start by clicking the upload button above.":"It looks like you haven't uploaded any images yet. Start by clicking the upload button above.","Open Code Editor":"Open Code Editor","Clear search":"Clear search","No results found for":"No results found for","Search {{pageTypeName}}":"Search {{pageTypeName}}","Goto Page":"Goto Page","Open URL":"Open URL","Compose Email":"Compose Email","Call Phone":"Call Phone","Scroll to element":"Scroll to element","#ElementID":"#ElementID","Enter details":"Enter details","Open in new tab":"Open in new tab",Apply,Back,Insert,Rename,"Unlink from library":"Unlink from library","Save to Library":"Save to Library","No blocks found in this group":"No blocks found in this group","No blocks found matching":"No blocks found matching","No matching blocks found":"No matching blocks found","Search blocks...":"Search blocks...",Partials,Happy,Sad,"Importing...":"Importing...","Failed to load the UI library. Try again":"Failed to load the UI library. Try again",Retry,"Oops! Something went wrong.":"Oops! Something went wrong.","Please try again.":"Please try again.","No option found.":"No option found.","Clipboard not supported":"Clipboard not supported","Are you sure you want to clear the page?":"Are you sure you want to clear the page?",canvas_empty,Presets,"Reset style":"Reset style","Reset styles":"Reset styles","Clear styles":"Clear styles","Open code editor":"Open code editor","Style element":"Style element","Repeater Data":"Repeater Data","Toggle Data Binding":"Toggle Data Binding",No,Saving,"Screen sizes":"Screen sizes","Theme Settings":"Theme Settings","Import CSS Theme":"Import CSS Theme","Import theme":"Import theme","Import Theme":"Import Theme","CSS Variables":"CSS Variables","You don't have permission to edit settings or styles":"You don't have permission to edit settings or styles","Please contact your administrator to get access":"Please contact your administrator to get access","flex.heading":"Flex Child","flex.basis":"Basis","flex.order":"Order","flex.flex":"Flex","flex.grow":"Grow","flex.shrink":"Shrink","grid.heading":"Grid Child","grid.col_span":"Col Span","grid.col_start":"Col Start","grid.col_end":"Col End","grid.row_span":"Row Span","grid.row_start":"Row Start","grid.row_end":"Row End","grid.order":"Order","layout.heading":"Layout","layout.width":"Width","layout.height":"Height","layout.margin":"Margin","layout.margin_all":"All","layout.margin_lr":"Left-Right","layout.margin_tb":"Top-Bottom","layout.margin_top":"Top","layout.margin_right":"Right","layout.margin_bottom":"Bottom","layout.margin_left":"Left","layout.padding":"Padding","layout.padding_all":"All","layout.padding_lr":"Left-Right","layout.padding_tb":"Top-Bottom","layout.padding_top":"Top","layout.padding_right":"Right","layout.padding_bottom":"Bottom","layout.padding_left":"Left","layout.space_bt":"Space Bt.","layout.space_lr":"Left-Right","layout.space_tb":"Top-Bottom","size.heading":"Size","size.min_width_height":"Min width & height","size.min_width":"Min Width","size.min_height":"Min Height","size.max_width_height":"Max width & height","size.max_width":"Max Width","size.max_height":"Max Height","size.object_options_aspect_ratio":"Object options & aspect ratio","size.aspect":"Aspect","size.fit":"Fit","size.position":"Position","display.heading":"Display","display.display":"Display","display.flex_options":"Flex options","display.flex_direction":"Direction","display.flex_wrap":"Wrap","display.justify_content":"Justify","display.align_content":"Content","display.align_items":"Items","display.gap":"Gap","display.gap_all":"All","display.gap_lr":"Left-Right","display.gap_tb":"Top-Bottom","display.grid_options":"Grid options","display.grid_columns":"Columns","display.grid_rows":"Rows","display.grid_auto_flow":"Auto Flow","display.grid_auto_cols":"Auto Cols","display.grid_auto_rows":"Auto Rows","display.visibility_opacity":"Visibility & Opacity","display.visibility":"Visibility","display.opacity":"Opacity","position.heading":"Position","position.position":"Position","position.options":"Position options","position.direction":"Direction","position.top":"Top","position.right":"Right","position.bottom":"Bottom","position.left":"Left","position.inset":"Inset","position.all":"All","position.lr":"Left Right","position.tb":"Top Bottom","position.z_index":"Z-Index","position.float_clear":"Float & Clear","position.float":"Float","position.clear":"Clear","position.overflow_overscroll":"Overflow & Overscroll","position.overflow":"Overflow","position.overscroll":"Overscroll","typography.heading":"Typography","typography.font":"Font","typography.size":"Size","typography.height":"Height","typography.weight":"Weight","typography.color":"Color","typography.alignments":"Alignments","typography.align":"Align","typography.valign":"V. Align","typography.spacing_decoration_more":"Spacing, decoration & more","typography.spacing":"Spacing","typography.decoration":"Decoration","typography.thickness":"Thickness","typography.transform":"Transform","typography.whitespace_breaks":"White space & breaks","typography.whitespace":"Whitespace","typography.wordbreak":"Wordbreak","background.heading":"Background","background.bgcolor":"Bg. Color","background.position_size_more":"Position, Size & more","background.attachment":"Attachment","background.clipping":"Clipping","background.origin":"Origin","background.position":"Position","background.repeat":"Repeat","background.size":"Size","background.gradient":"Gradient","background.gradient_colors":"Gradient colors","background.from_color":"From","background.via_color":"Via","background.to_color":"To","border.heading":"Border & Outline","border.width":"Width","border.all":"All","border.lr":"Left Right","border.tb":"Top bottom","border.top":"Top","border.right":"Right","border.bottom":"Bottom","border.left":"Left","border.corners":"Corners","border.top_left":"Top Left","border.top_right":"Top right","border.bottom_right":"Bottom right","border.bottom_left":"Bottom left","border.color":"Color","border.style":"Style","border.divide_options":"Divide options","border.divide_color":"Color","border.divide_style":"Style","border.outline_styling":"Outline styling","border.outline_width":"Width","border.outline_offset":"Offset","border.outline_style":"Style","border.ring_options":"Ring options","border.ring_width":"Width","border.ring_color":"Color","border.ring_offset_width":"Offset","border.ring_offset_color":"Off. color","effect.heading":"Effect & Animation","effect.shadow":"Shadow","effect.color":"Color","effect.cursor":"Cursor","effect.blend_cursor":"Blend & Cursor","effect.mix_blend":"Mix Blend","effect.bg_blend":"Bg. Blend","effect.transform":"Transform","effect.origin":"Origin","effect.scale":"Scale","effect.all":"All","effect.lr":"Left-Right","effect.tb":"Top-Bottom","effect.skew":"Skew","effect.translate":"Translate","effect.rotate":"Rotate","effect.animation":"Animation","effect.transition":"Transition","effect.easing":"Easing","effect.duration":"Duration","effect.delay":"Delay","classes.heading":"Classes",theme_config,web_blocks,"Export Code":"Export Code","Exporting {{count}} blocks":"Exporting {{count}} blocks","Exporting all blocks":"Exporting all blocks","Export code copied!":"Export code copied!","Failed to copy export code":"Failed to copy export code","Export code downloaded successfully!":"Export code downloaded successfully!","Failed to generate export HTML":"Failed to generate export HTML","Enter value":"Enter value","Attribute keys cannot start with @":"Attribute keys cannot start with @","Enter key":"Enter key",Add,Save,Screen};i18n.use(reactI18next.initReactI18next).init({resources:{en:{translation:lngEn}},lng:"en",fallbackLng:"en",interpolation:{escapeValue:!1}});function QuickPrompts({onClick:o}){const{loading:n}=useAskAi(),{t:a}=reactI18next.useTranslation(),{selectedLang:r,fallbackLang:i}=useLanguages(),c=[...[{name:a("Improve writing"),icon:reactIcons.Pencil2Icon,prompt:a("Improving writing in all text elements. Replacing placeholder content with meaningful relevant content.")},{name:a("Replace placeholder content"),icon:reactIcons.LoopIcon,prompt:a("Discard current placeholder content and replace with meaningful relevant content.")},{name:a("Fix grammar"),icon:reactIcons.CheckIcon,prompt:a("Fix grammar in all text elements. Ensuring the text is grammatically correct and free of errors.")},{name:a("Make longer"),icon:reactIcons.ArrowUpIcon,prompt:a("Make all text elements longer.")},{name:a("Make shorter"),icon:reactIcons.ArrowDownIcon,prompt:a("Make all text elements shorter.")},{name:a("Add emojis"),icon:reactIcons.FaceIcon,prompt:a("Add emojis to text elements if relevant.")},{name:a("Randomize"),icon:reactIcons.ShuffleIcon,prompt:a("Randomize all text elements.")}]];return r&&r!==i&&c.splice(0,0,{name:a("Translate to {{lang}}",{lang:lodashEs.get(LANGUAGES,r,r)}),icon:reactIcons.ChatBubbleIcon,prompt:a("Translate the content to {{lang}}. Maintain same tone, style and length.",{lang:lodashEs.get(LANGUAGES,r,r)})}),jsxRuntime.jsx("div",{className:n?"pointer-events-none opacity-50":"",children:jsxRuntime.jsx("ul",{className:"space-y-1",children:c.map(({name:d,icon:p,subMenus:u,prompt:m})=>u?jsxRuntime.jsxs(tooltip.Popover,{children:[jsxRuntime.jsx(tooltip.PopoverTrigger,{asChild:!0,children:jsxRuntime.jsxs("li",{className:"flex cursor-pointer items-center space-x-2 rounded p-1 pl-2 text-sm hover:bg-gray-100 dark:hover:bg-gray-800",children:[jsxRuntime.jsx(p,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:d})]},d)}),jsxRuntime.jsx(tooltip.PopoverContent,{side:"right",children:jsxRuntime.jsx("ul",{children:jsxRuntime.jsx("li",{children:a("Happy")})})})]}):jsxRuntime.jsxs("li",{onClick:()=>o(m),className:"flex cursor-pointer items-center space-x-2 rounded p-1 text-xs hover:bg-primary/10 hover:text-primary dark:hover:bg-gray-800",children:[jsxRuntime.jsx(p,{className:"h-3.5 w-3.5"}),jsxRuntime.jsx("span",{children:a(d)})]},d))})})}const AIUserPrompt=({blockId:o})=>{const{t:n}=reactI18next.useTranslation(),{askAi:a,loading:r,error:i}=useAskAi(),[l,c]=React.useState(""),d=React.useRef(null),p=React.useRef(null),u=useSelectedBlock();React.useEffect(()=>{var h;(h=d.current)==null||h.focus()},[]);const m=()=>{i||c("")};return jsxRuntime.jsx("div",{className:"",children:o?jsxRuntime.jsxs("div",{className:"",children:[jsxRuntime.jsx("label",{className:"text-xs font-medium text-gray-500",children:n("Selected block")}),u&&jsxRuntime.jsxs("div",{className:"flex items-center gap-x-1 rounded border border-primary/20 bg-primary/10 p-1.5 text-xs text-primary",children:[jsxRuntime.jsx(TypeIcon,{type:u._type})," ",jsxRuntime.jsx("p",{className:"truncate whitespace-nowrap leading-none",children:u._name||u._type})]}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("label",{className:"text-xs font-medium text-gray-500",children:n("Quick actions")}),jsxRuntime.jsx("div",{className:"rounded border p-2 text-sm",children:jsxRuntime.jsx(QuickPrompts,{onClick:h=>{p.current&&clearTimeout(p.current),a("content",o,h,m)}})}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("label",{className:"text-xs font-medium text-gray-500",children:n("Ask AI")}),jsxRuntime.jsxs("div",{className:"rounded border p-2 text-xs focus-within:border-gray-300",children:[jsxRuntime.jsx(tooltip.Textarea,{ref:d,value:l,onChange:h=>c(h.target.value),placeholder:n("Ask AI to edit content"),className:"w-full resize-none border-none p-0 text-xs shadow-none outline-none",rows:3,onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),p.current&&clearTimeout(p.current),a("content",o,l,m))}}),jsxRuntime.jsxs("div",{className:"flex items-center justify-end",children:[r&&jsxRuntime.jsx(tooltip.Button,{variant:"destructive",onClick:()=>stop(),className:"hidden h-4 w-4",size:"icon",children:jsxRuntime.jsx(reactIcons.StopIcon,{className:"h-4 w-4"})}),jsxRuntime.jsx(tooltip.Button,{onClick:()=>{p.current&&clearTimeout(p.current),a("content",o,l,m)},variant:"default",className:"h-7 w-7",disabled:r||l.trim().length<1,size:"icon",children:r?jsxRuntime.jsx(reactIcons.ReloadIcon,{className:"h-4 w-4 animate-spin"}):jsxRuntime.jsx(reactIcons.ArrowTopRightIcon,{className:"h-4 w-4"})})]})]}),jsxRuntime.jsx("div",{className:"max-w-full pt-2",children:i&&jsxRuntime.jsx("p",{className:"break-words rounded border border-red-500 bg-red-100 p-1 text-xs text-red-500",children:i.message})})]}):jsxRuntime.jsx("div",{className:"p-4 text-center",children:jsxRuntime.jsxs("div",{className:"space-y-4 rounded-xl p-4 text-muted-foreground",children:[jsxRuntime.jsx(AiIcon,{className:"mx-auto h-7 w-7 text-muted-foreground"}),jsxRuntime.jsx("h1",{children:n("Please select a block to Ask AI")})]})})})},AskAI=()=>{const[o]=useSelectedBlockIds();return jsxRuntime.jsx("div",{className:"no-scrollbar mt-2 flex-1 overflow-y-auto",children:jsxRuntime.jsx(AIUserPrompt,{blockId:lodashEs.first(o)})})};function DarkMode(){const[o,n]=useDarkMode();return jsxRuntime.jsxs("div",{className:"flex items-center",children:[o?jsxRuntime.jsx(reactIcons.MoonIcon,{className:"size-4 shrink-0"}):jsxRuntime.jsx(reactIcons.SunIcon,{className:"size-4 shrink-0"}),jsxRuntime.jsx(tooltip.Switch,{id:"dark-mode-switch",checked:o,onCheckedChange:()=>{n(!o)},className:`${o?"bg-violet-600":"bg-violet-300"} relative ml-2 inline-flex h-[20px] w-[32px] shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus-visible:ring-2 focus-visible:ring-white focus-visible:ring-opacity-75`,children:jsxRuntime.jsx("span",{"aria-hidden":"true",className:`${o?"translate-x-5":"translate-x-0"} pointer-events-none -mt-px inline-block h-[18px] w-[20px] transform rounded-full bg-white shadow-lg ring-0 transition duration-200 ease-in-out`})})]})}const UndoRedo=()=>{const{hasUndo:o,hasRedo:n,undo:a,redo:r}=useUndoManager();return jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx(tooltip.Button,{disabled:!o(),size:"sm",onClick:a,className:"rounded-full",variant:"ghost",children:jsxRuntime.jsx(reactIcons.ResetIcon,{})}),jsxRuntime.jsx(tooltip.Button,{disabled:!n(),onClick:r,size:"sm",className:"rounded-full",variant:"ghost",children:jsxRuntime.jsx(reactIcons.ResetIcon,{className:"rotate-180 scale-y-[-1] transform"})})]})},ScalePercent=()=>{const[o]=useCanvasZoom();return jsxRuntime.jsxs("div",{className:"flex w-12 cursor-not-allowed items-center justify-center gap-x-1 space-x-0 font-medium text-gray-400",children:[jsxRuntime.jsx(reactIcons.ZoomInIcon,{className:"h-3.5 w-3.5 flex-shrink-0"})," ",jsxRuntime.jsxs("div",{className:"text-xs leading-3",children:[lodashEs.round(o,0),"%"]})]})},PageValidation=()=>{const{hasErrors:o,hasWarnings:n,errorCount:a,warningCount:r,errors:i}=useStructureValidation(),[,l]=useSelectedBlockIds(),{t:c}=reactI18next.useTranslation();if(!o&&!n)return null;const d=()=>o?"text-red-500":n?"text-orange-500":"text-gray-500",p=()=>o?jsxRuntime.jsx(reactIcons.ExclamationTriangleIcon,{className:"h-4 w-4"}):n?jsxRuntime.jsx(reactIcons.InfoCircledIcon,{className:"h-4 w-4"}):null,u=()=>o&&n?`${a} error${a>1?"s":""}, ${r} warning${r>1?"s":""}`:o?`${a} error${a>1?"s":""}`:n?`${r} warning${r>1?"s":""}`:"";return jsxRuntime.jsxs(tooltip.DropdownMenu,{children:[jsxRuntime.jsx(tooltip.DropdownMenuTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{className:`ml-2 flex cursor-pointer items-center gap-2 ${d()}`,children:[p(),jsxRuntime.jsx("span",{className:"text-xs font-medium",children:u()})]})}),jsxRuntime.jsx(tooltip.DropdownMenuContent,{side:"bottom",className:"max-w-xs p-2",align:"end",children:jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("h4",{className:"text-sm font-semibold",children:c("Invalid structure")}),i.length===0?jsxRuntime.jsx("p",{className:"text-xs",children:c("No validation issues found.")}):jsxRuntime.jsxs("div",{className:"space-y-1",children:[i.slice(0,5).map(m=>jsxRuntime.jsxs("div",{onClick:()=>{m.blockId&&l([m.blockId])},className:`cursor-pointer rounded p-2 text-xs transition-opacity hover:opacity-80 ${m.severity==="error"?"border border-red-200 bg-red-50 text-red-700":"border border-orange-200 bg-orange-50 text-orange-700"}`,children:[jsxRuntime.jsx("div",{className:"font-medium",children:m.severity==="error"?"Error:":"Warning:"}),jsxRuntime.jsx("div",{children:m.message})]},m.id)),i.length>5&&jsxRuntime.jsxs("p",{className:"text-xs italic text-gray-500",children:["... and ",i.length-5," more issues"]})]})]})})]})},CanvasTopBar=()=>{const o=useBuilderProp("flags.darkMode",!0),n=useBuilderProp("flags.dataBinding",!0),[a,r]=jotai.useAtom(dataBindingActiveAtom),{t:i}=reactI18next.useTranslation(),l=o,c=n;return jsxRuntime.jsxs("div",{className:"flex h-10 items-center justify-between border-b border-border bg-background/70 px-2 shadow-xl",children:[jsxRuntime.jsx("div",{className:"flex h-full space-x-2",children:l?jsxRuntime.jsx(DarkMode,{}):null}),jsxRuntime.jsxs("div",{className:"flex h-full items-center space-x-2",children:[jsxRuntime.jsx(Breakpoints$1,{canvas:!0,openDelay:400}),jsxRuntime.jsx(tooltip.Separator,{orientation:"vertical"}),jsxRuntime.jsx(ScalePercent,{}),jsxRuntime.jsx(tooltip.Separator,{orientation:"vertical"}),jsxRuntime.jsx(UndoRedo,{})]}),jsxRuntime.jsxs("div",{className:"flex h-full items-center",children:[c?jsxRuntime.jsxs(tooltip.DropdownMenu,{children:[jsxRuntime.jsx(tooltip.DropdownMenuTrigger,{asChild:!0,children:jsxRuntime.jsx(tooltip.Button,{size:"sm",variant:"ghost",className:"h-7 w-7 rounded-md p-1",children:jsxRuntime.jsx(reactIcons.DotsHorizontalIcon,{className:"h-4 w-4"})})}),jsxRuntime.jsx(tooltip.DropdownMenuContent,{className:"w-56 border-border text-xs",children:jsxRuntime.jsxs(tooltip.DropdownMenuItem,{className:"flex items-center gap-2",onSelect:d=>d.preventDefault(),children:[jsxRuntime.jsx(reactIcons.LightningBoltIcon,{className:"h-4 w-4 text-gray-500"}),jsxRuntime.jsx("span",{className:"flex-1",children:i("Data Binding")}),jsxRuntime.jsx(tooltip.Switch,{checked:a,onCheckedChange:()=>r(!a)})]})})]}):null,jsxRuntime.jsx(PageValidation,{}),jsxRuntime.jsx(ClearCanvas,{})]})]})},AddBlocksDialog=()=>{const{t:o}=reactI18next.useTranslation(),[n,a]=React.useState(""),[r,i]=React.useState(-1),[l,c]=React.useState(!1),d=useIsDragAndDropEnabled(),[,p]=useSidebarActivePanel();return usePubSub(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,u=>{d?p("add-block"):(a(u?u._id:null),i(isNaN(u==null?void 0:u.position)?-1:u==null?void 0:u.position),c(!0))}),usePubSub(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK,()=>{a(""),i(-1),c(!1)}),jsxRuntime.jsx(tooltip.AlertDialog,{open:l,onOpenChange:()=>l?c(!1):"",children:jsxRuntime.jsxs(tooltip.AlertDialogContent,{className:"max-w-5xl overflow-hidden border-border",children:[jsxRuntime.jsxs(tooltip.AlertDialogHeader,{className:"flex flex-row items-center justify-between",children:[jsxRuntime.jsx(tooltip.AlertDialogTitle,{className:"text-foreground",children:o("Add blocks")}),jsxRuntime.jsx("button",{onClick:()=>c(!1),className:"text-gray-500 hover:text-gray-600 dark:text-gray-400 dark:hover:text-gray-300",children:jsxRuntime.jsx(reactIcons.Cross2Icon,{className:"h-6 w-6"})})]}),jsxRuntime.jsx("div",{className:"no-scrollbar h-[500px] max-h-full overflow-hidden",children:jsxRuntime.jsx(AddBlocksPanel,{parentId:n,position:r,showHeading:!1})})]})})},AttrsEditor=React.memo(function o({preloadedAttributes:n=[],onAttributesChange:a}){const[r,i]=React.useState([]),[l,c]=React.useState(""),[d,p]=React.useState(""),[u,m]=React.useState(null),[h,x]=React.useState(""),g=React.useRef(null),f=React.useRef(null),b=usePageExternalData(),{t:j}=reactI18next.useTranslation();React.useEffect(()=>{i(n)},[n]);const R=()=>{if(l.startsWith("@")){x(j("Attribute keys cannot start with @"));return}if(l){const C=[...r,{key:l,value:d}];a(C),i(r),c(""),p(""),x("")}},y=C=>{const w=r.filter((E,A)=>A!==C);a(w),i(w)},k=C=>{m(C),c(r[C].key),p(r[C].value)},S=()=>{if(l.startsWith("@")){x(j("Attribute keys cannot start with @"));return}if(u!==null&&l){const C=[...r];C[u]={key:l,value:d},a(C),i(C),m(null),c(""),p(""),x("")}},v=C=>{C.key==="Enter"&&!C.shiftKey&&(C.preventDefault(),u!==null?S():R())},B=React.useCallback(C=>{const w=_=>/[.,!?;:]/.test(_),E=(_,I,P)=>{let L="",D="";const H=I>0?_[I-1]:"",V=I<_.length?_[I]:"";return I>0&&(H==="."||!w(H)&&H!==" ")&&(L=" "),I<_.length&&!w(V)&&V!==" "&&(D=" "),{text:L+P+D,prefixLength:L.length,suffixLength:D.length}},A=f.current;if(A){const _=A.selectionStart||0,I=A.value||"",P=A.selectionEnd||_;if(P>_){const O=`{{${C}}}`,{text:T}=E(I,_,O),N=I.slice(0,_)+T+I.slice(P);p(N);return}const D=`{{${C}}}`,{text:H}=E(I,_,D),V=I.slice(0,_)+H+I.slice(_);p(V)}},[]);return jsxRuntime.jsxs("div",{className:"flex max-h-full flex-1 flex-col",children:[jsxRuntime.jsxs("form",{onSubmit:C=>{C.preventDefault(),u!==null?S():R()},className:"space-y-3",children:[jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1",children:[jsxRuntime.jsxs("div",{className:"w-full",children:[jsxRuntime.jsx(tooltip.Label,{htmlFor:"attrKey",className:"text-[11px] font-normal leading-tight text-slate-600",children:j("Key")}),jsxRuntime.jsx(tooltip.Input,{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",id:"attrKey",ref:g,value:l,onChange:C=>c(C.target.value),placeholder:j("Enter key"),className:"py-0 text-xs font-normal leading-tight placeholder:text-slate-400"})]}),jsxRuntime.jsxs("div",{className:"w-full",children:[jsxRuntime.jsxs("div",{className:"flex items-center justify-between",children:[jsxRuntime.jsx(tooltip.Label,{htmlFor:"attrValue",className:"text-[11px] font-normal text-slate-600",children:j("Value")}),!lodashEs.isEmpty(b)&&jsxRuntime.jsx(NestedPathSelector,{data:b,onSelect:B})]}),jsxRuntime.jsx(tooltip.Textarea,{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",id:"attrValue",ref:f,value:d,onChange:C=>p(C.target.value),onKeyDown:v,placeholder:j("Enter value"),className:"text-xs font-normal leading-tight placeholder:text-slate-400"})]})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(tooltip.Button,{type:"submit",disabled:!l.length,variant:"default",size:"sm",className:"h-8 w-24 text-xs",children:j(u!==null?"Save":"Add")})}),h&&jsxRuntime.jsx("p",{className:"text-xs text-red-500",children:h})]}),jsxRuntime.jsx("div",{className:"space-y-1 py-4",children:r.map((C,w)=>jsxRuntime.jsxs("div",{className:"flex items-center justify-between rounded border p-2 text-sm",children:[jsxRuntime.jsxs("div",{className:"flex flex-col text-xs leading-tight",children:[jsxRuntime.jsx("span",{className:"truncate text-[12px] font-light text-muted-foreground",children:C.key}),jsxRuntime.jsx("span",{className:"max-w-[200px] text-wrap font-normal",children:C.value.toString()})]}),jsxRuntime.jsxs("div",{className:"flex-shrink-0 text-slate-400",children:[jsxRuntime.jsx(tooltip.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>k(w),children:jsxRuntime.jsx(reactIcons.Pencil2Icon,{className:"h-3 w-3"})}),jsxRuntime.jsx(tooltip.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>y(w),children:jsxRuntime.jsx(reactIcons.Cross1Icon,{className:"h-3 w-3"})})]})]},w))})]})}),BlockAttributesEditor=React__namespace.memo(()=>{const o=useSelectedBlock(),[n,a]=React.useState([]),[r]=useSelectedStylingBlocks(),i=useUpdateBlocksProps(),l=`${lodashEs.get(r,"0.prop")}_attrs`;React__namespace.useEffect(()=>{const d=lodashEs.map(lodashEs.get(o,l),(p,u)=>({key:u,value:p}));lodashEs.isEmpty(d)?a([]):a(d)},[lodashEs.get(o,l)]);const c=React__namespace.useCallback((d=[])=>{const p={};lodashEs.forEach(d,u=>{lodashEs.isEmpty(u.key)||lodashEs.set(p,u.key,u.value)}),i([lodashEs.get(o,"_id")],{[l]:p})},[o,i,l]);return jsxRuntime.jsx("div",{className:"flex-col gap-y-2",children:jsxRuntime.jsx("div",{className:"flex flex-col",children:jsxRuntime.jsx("div",{children:jsxRuntime.jsx(AttrsEditor,{preloadedAttributes:n,onAttributesChange:c})})})})}),NoopComponent=()=>null,ResetStylesButton=()=>{const{resetAll:o}=useResetBlockStyles(),n=useSelectedBlock(),[a]=useSelectedStylingBlocks(),r=useRemoveAllClassesForBlock(),{t:i}=reactI18next.useTranslation();return!n||lodashEs.isEmpty(a)?null:jsxRuntime.jsxs(tooltip.DropdownMenu,{children:[jsxRuntime.jsx(tooltip.DropdownMenuTrigger,{asChild:!0,children:jsxRuntime.jsx("div",{className:"inline-flex rounded-sm p-0.5 hover:bg-gray-300",onClick:l=>l.stopPropagation(),children:jsxRuntime.jsx(reactIcons.DotsVerticalIcon,{className:"h-3 w-3"})})}),jsxRuntime.jsxs(tooltip.DropdownMenuContent,{side:"bottom",className:"border-border text-xs",children:[jsxRuntime.jsxs(tooltip.DropdownMenuItem,{className:"flex items-center gap-1 text-xs",onClick:()=>{o()},children:[jsxRuntime.jsx(reactIcons.ResetIcon,{className:"h-3 w-3"}),i("Reset styles")]}),jsxRuntime.jsxs(tooltip.DropdownMenuItem,{className:"text-xs",onClick:()=>{n&&r(n,!0)},children:[jsxRuntime.jsx(reactIcons.Cross2Icon,{className:"h-3 w-3"}),i("Clear styles")]})]})]})};function BlockAttributesToggle(){const{t:o}=reactI18next.useTranslation(),[n,a]=React.useState(!0),[r]=useSelectedStylingBlocks();return lodashEs.isEmpty(r)?null:jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs("div",{onClick:()=>a(!n),className:"flex cursor-pointer items-center justify-between border-t border-border py-3 text-xs font-medium hover:underline",children:[jsxRuntime.jsx("span",{children:o("Attributes")}),jsxRuntime.jsx("span",{children:jsxRuntime.jsx(reactIcons.ChevronDownIcon,{className:"h-4 w-4 text-gray-500 "+(n?"rotate-180":"")})})]}),n&&jsxRuntime.jsx(BlockAttributesEditor,{})]})}const PartialWrapper=({partialBlockId:o})=>{const n=useBuilderProp("gotoPage",lodashEs.noop),{saveState:a}=useSavePage(),{selectedLang:r,fallbackLang:i}=useLanguages(),l=React.useCallback(c=>{if(c.stopPropagation(),a!=="SAVED"){sonner.toast.error("You have unsaved changes. Please save the page first.");return}n({pageId:o,lang:r||i})},[a,n,o,r,i]);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx("div",{className:"hidden",children:jsxRuntime.jsx("div",{onDoubleClick:l,className:"h-full w-full items-center justify-center",children:jsxRuntime.jsx("p",{className:"rounded-md bg-white px-2 py-1 text-xs",children:"Partial block. Double click to edit."})})})})},SettingsPanel=()=>{const o=useSelectedBlock(),{t:n}=reactI18next.useTranslation(),a=useBuilderProp("onError",lodashEs.noop),{hasPermission:r}=usePermissions();let i=!r(PERMISSIONS.EDIT_BLOCK);const l=!r(PERMISSIONS.EDIT_STYLES);return o&&o._type==="PartialBlock"?jsxRuntime.jsx(PartialWrapper,{partialBlockId:o.partialBlockId}):lodashEs.isNull(o)?jsxRuntime.jsx("div",{className:"p-4 text-center",children:jsxRuntime.jsxs("div",{className:"space-y-4 rounded-xl p-4 text-muted-foreground",children:[jsxRuntime.jsx(reactIcons.MixerHorizontalIcon,{className:"mx-auto text-3xl"}),jsxRuntime.jsx("h1",{children:n("Please select a block to edit settings or styles")})]})}):i&&l?jsxRuntime.jsx("div",{className:"p-4 text-center",children:jsxRuntime.jsxs("div",{className:"space-y-4 rounded-xl p-4 text-muted-foreground",children:[jsxRuntime.jsx(reactIcons.MixerHorizontalIcon,{className:"mx-auto text-3xl"}),jsxRuntime.jsx("h1",{children:n("You don't have permission to edit settings or styles")}),jsxRuntime.jsx("p",{children:n("Please contact your administrator to get access")})]})}):l?jsxRuntime.jsx(reactErrorBoundary.ErrorBoundary,{fallback:jsxRuntime.jsx(FallbackError,{}),onError:a,children:jsxRuntime.jsxs("div",{className:"no-scrollbar h-full max-h-min w-full overflow-y-auto",children:[jsxRuntime.jsx(BlockSettings,{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]})}):i?jsxRuntime.jsx(reactErrorBoundary.ErrorBoundary,{fallback:jsxRuntime.jsx(FallbackError,{}),onError:a,children:jsxRuntime.jsxs("div",{className:"no-scrollbar h-full max-h-min w-full overflow-y-auto overflow-x-hidden",children:[jsxRuntime.jsx("div",{className:"flex w-full items-center justify-end",children:jsxRuntime.jsx(ResetStylesButton,{})}),jsxRuntime.jsx(BlockStyling,{}),jsxRuntime.jsx(BlockAttributesToggle,{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]})}):jsxRuntime.jsx(reactErrorBoundary.ErrorBoundary,{fallback:jsxRuntime.jsx(FallbackError,{}),onError:a,children:jsxRuntime.jsxs(tooltip.Tabs,{defaultValue:"settings",className:"flex flex-1 flex-col",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between",children:jsxRuntime.jsxs(tooltip.TabsList,{className:"grid h-auto w-full grid-cols-2 p-1 py-1",children:[jsxRuntime.jsx(tooltip.TabsTrigger,{value:"settings",className:"text-xs",children:n("Settings")}),jsxRuntime.jsx(tooltip.TabsTrigger,{value:"styles",className:"text-xs",children:jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between",children:[jsxRuntime.jsx("span",{className:"w-[90%] text-center",children:n("Styling")}),jsxRuntime.jsx("span",{className:"w-[10%]",children:jsxRuntime.jsx(ResetStylesButton,{})})]})})]})}),jsxRuntime.jsxs(tooltip.TabsContent,{value:"settings",className:"no-scrollbar h-full max-h-min overflow-y-auto",children:[jsxRuntime.jsx(BlockSettings,{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]}),jsxRuntime.jsxs(tooltip.TabsContent,{value:"styles",className:"no-scrollbar h-full max-h-min max-w-full overflow-y-auto overflow-x-hidden",children:[jsxRuntime.jsx(BlockStyling,{}),jsxRuntime.jsx(BlockAttributesToggle,{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]})]})})},CHAI_BUILDER_PANELS={},registerChaiSidebarPanel=(o,n)=>{lodashEs.has(CHAI_BUILDER_PANELS,o)&&console.warn(`Panel ${o} already registered. Overriding...`),lodashEs.set(CHAI_BUILDER_PANELS,o,{id:o,...n})},useChaiSidebarPanels=o=>React.useMemo(()=>lodashEs.filter(lodashEs.values(CHAI_BUILDER_PANELS),n=>n.position===o),[o,CHAI_BUILDER_PANELS]),DefaultTopBar=()=>jsxRuntime.jsx("div",{}),TOP_BAR={component:DefaultTopBar},registerChaiTopBar=o=>{TOP_BAR.component=o},useTopBarComponent=()=>React.useMemo(()=>TOP_BAR.component,[]),TokenUsageSection=({title:o,items:n,emptyLabel:a,onSelect:r,icon:i})=>jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx("p",{className:"text-[11px] font-semibold uppercase tracking-wide text-muted-foreground",children:o}),n.length>0?jsxRuntime.jsx("div",{className:"space-y-1",children:n.map(l=>jsxRuntime.jsx("button",{type:"button",onClick:()=>r(l.id),className:tooltip.cn("group flex w-full items-center justify-between rounded-md border border-transparent bg-muted/40 px-3 py-1 text-left text-xs transition","hover:border-muted-foreground/20 hover:bg-muted/70 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-offset-1",l.isSelected&&"border-primary/40 bg-primary/10 text-primary"),children:jsxRuntime.jsxs("span",{className:"flex items-center space-x-2",children:[i&&i,jsxRuntime.jsx("span",{className:"truncate",children:l.label})]})},l.id))}):jsxRuntime.jsx("div",{className:"rounded border border-dashed border-muted px-3 py-1 text-xs text-muted-foreground",children:a})]}),STYLES_PREFIX="#styles:",getBlockLabel=o=>{const a=[typeof o._name=="string"?o._name:void 0,typeof o._type=="string"?o._type:void 0].filter(Boolean).find(r=>r.trim().length>0);return a?a.length>40?`${a.slice(0,37)}...`:a:o._id},collectTokenUsageOnPage=(o,n)=>{const a=`${n}`;return o.filter(r=>Object.values(r).some(i=>typeof i!="string"||!i.startsWith(STYLES_PREFIX)?!1:i.includes(a))).map(r=>({id:r._id,label:getBlockLabel(r)}))},TokenUsagePopover=({tokenId:o,tokenName:n})=>{const{t:a}=reactI18next.useTranslation(),[r]=useBlocksStore(),[i,l]=useSelectedBlockIds(),c=useBuilderProp("pageId"),d=useBuilderProp("siteWideUsage"),p=React.useMemo(()=>collectTokenUsageOnPage(r,o),[r,o]),u=React.useMemo(()=>p.map(k=>({id:k.id,label:k.label,isSelected:i.includes(k.id)})),[p,i]),m=React.useMemo(()=>d?Object.entries(d).reduce((k,[S,v])=>(S===c||!(v!=null&&v.designTokens)||!Object.keys(v.designTokens).some(C=>typeof C!="string"?!1:C===o)||k.push({id:S,name:v.name||S,isPartial:!!v.isPartial}),k),[]):[],[d,n,o,c]),h=React.useMemo(()=>m.filter(k=>!k.isPartial).map(k=>({id:k.id,label:k.name})),[m]),x=React.useMemo(()=>m.filter(k=>k.isPartial).map(k=>({id:k.id,label:k.name})),[m]),g=React.useCallback(k=>{l([k])},[l]),f=useBuilderProp("gotoPage",lodashEs.noop),{selectedLang:b,fallbackLang:j}=useLanguages(),{savePageAsync:R}=useSavePage(),y=async k=>{k&&(await R(!0),f({pageId:k,lang:b||j}))};return jsxRuntime.jsxs(tooltip.Popover,{children:[jsxRuntime.jsx(tooltip.PopoverTrigger,{asChild:!0,children:jsxRuntime.jsx(tooltip.Button,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",children:jsxRuntime.jsx(reactIcons.EyeOpenIcon,{className:"h-3 w-3"})})}),jsxRuntime.jsxs(tooltip.PopoverContent,{side:"bottom",align:"end",className:"w-80 p-0",children:[jsxRuntime.jsxs("div",{className:"space-y-1 px-4 py-3",children:[jsxRuntime.jsx("p",{className:"text-xs font-semibold",children:n}),jsxRuntime.jsx("p",{className:"text-[11px] text-muted-foreground",children:a("Usage summary for this design token across your site.")})]}),jsxRuntime.jsxs("div",{className:"no-scrollbar max-h-64 space-y-4 overflow-y-auto px-4 pb-4",children:[jsxRuntime.jsx(TokenUsageSection,{title:a("Blocks affected on this page"),items:u,emptyLabel:a("None"),onSelect:g,icon:jsxRuntime.jsx(reactIcons.ArrowRightIcon,{fontSize:4})}),jsxRuntime.jsx(TokenUsageSection,{title:a("Blocks affected on other pages"),items:h,emptyLabel:a("None"),onSelect:y,icon:jsxRuntime.jsx(reactIcons.FileIcon,{fontSize:8})}),jsxRuntime.jsx(TokenUsageSection,{title:a("Blocks affected on partial blocks"),items:x,emptyLabel:a("None"),onSelect:y,icon:jsxRuntime.jsx(reactIcons.GlobeIcon,{fontSize:8})})]})]})]})},ManageDesignTokens=({})=>{const{t:o}=reactI18next.useTranslation(),[n,a]=jotai.useAtom(chaiDesignTokensAtom),[r,i]=React.useState(!1),[l,c]=React.useState(null),[d,p]=React.useState(!1),[u,m]=React.useState(!1),[h,x]=React.useState(""),[g,f]=React.useState(""),[b,j]=React.useState(""),[R,y]=React.useState(""),[k,S]=React.useState(""),[v,B]=React.useState(""),C=useIncrementActionsCount(),w=T=>{const N=T.trim();return N.length===0||N.length>25?!1:/^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$/.test(N)},E=(T,N=!1,M)=>{const F=T.trim();return F.length===0?"":F.length>25?o("Token name must be 25 characters or less"):/^[a-zA-Z0-9]+(-[a-zA-Z0-9]+)*$/.test(F)?Object.entries(n).find(([$,U])=>U.name===F&&(!N||$!==M))?o("Token name already exists"):"":o("Only alphanumeric characters and hyphens allowed")},A=()=>{if(!h.trim()||!g.trim()){sonner.toast.error(o("Please fill in both token name and classes"));return}if(!w(h)){sonner.toast.error(o("Invalid design token name format"));return}if(Object.values(n).find(F=>F.name===h.trim())){sonner.toast.error(o("Token already exists"));return}const N=`${applyBinding.DESIGN_TOKEN_PREFIX}${nanoid.nanoid(12)}`,M={...n,[N]:{name:h.trim(),value:g.trim()}};a(M),x(""),f(""),i(!1),p(!1),C(),sonner.toast.success(o("Token added successfully"))},_=()=>{if(!b.trim()||!R.trim()){sonner.toast.error(o("Please fill in both token name and classes"));return}if(!w(b)){sonner.toast.error(o("Invalid design token name format"));return}if(Object.entries(n).find(([M,F])=>F.name===b.trim()&&M!==l)){sonner.toast.error(o("Token already exists"));return}if(!l)return;const N={...n,[l]:{name:b.trim(),value:R.trim()}};a(N),c(null),j(""),y(""),m(!1),C(),sonner.toast.success(o("Token updated successfully"))},I=T=>{const N={...n};delete N[T],a(N),C(),sonner.toast.success(o("Token deleted successfully"))},P=T=>{const N=n[T];N&&(c(T),j(N.name),y(N.value),i(!1),m(!0))},L=()=>{i(!0),c(null),x(""),f(""),S(""),p(!0)},D=()=>{c(null),j(""),y(""),B(""),m(!1)},H=()=>{i(!1),x(""),f(""),S(""),p(!1)},V=T=>{const N=T.replace(/\s+/g,"-");x(N),S(E(N))},O=T=>{const N=T.replace(/\s+/g,"-");j(N),B(E(N,!0,l||void 0))};return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col",children:[jsxRuntime.jsx("div",{className:"",children:jsxRuntime.jsx("div",{className:"flex items-center justify-between",children:jsxRuntime.jsxs(tooltip.Button,{variant:"outline",onClick:L,disabled:r||l!==null,size:"sm",className:"h-7 text-xs",children:[jsxRuntime.jsx(reactIcons.PlusIcon,{className:"mr-1 h-3 w-3"}),o("Add")]})})}),jsxRuntime.jsx("div",{className:"no-scrollbar flex flex-1 flex-col overflow-hidden pt-2",children:jsxRuntime.jsx(tooltip.ScrollArea,{className:"h-full flex-1",children:jsxRuntime.jsx("div",{className:"space-y-1",children:Object.entries(n).length===0?jsxRuntime.jsxs("div",{className:"py-6 text-center text-muted-foreground",children:[jsxRuntime.jsx("div",{className:"mb-1 text-2xl",children:"🎨"}),jsxRuntime.jsx("p",{className:"text-xs",children:o("No design tokens defined")})]}):Object.entries(n).map(([T,N])=>jsxRuntime.jsxs("div",{className:`group flex items-center justify-between hover:bg-muted/90 ${l===T?"bg-primary/10":""}`,children:[jsxRuntime.jsx("div",{className:"min-w-0 flex-1",children:jsxRuntime.jsx("span",{className:"flex items-center break-all pl-1 text-xs font-semibold",children:N.name})}),jsxRuntime.jsxs("div",{className:"flex flex-shrink-0 items-center opacity-0 group-hover:opacity-100",children:[jsxRuntime.jsx(TokenUsagePopover,{tokenId:T,tokenName:N.name}),jsxRuntime.jsx(tooltip.Button,{variant:"ghost",size:"sm",onClick:()=>P(T),disabled:r||l!==null,className:"h-6 w-6 p-0",children:jsxRuntime.jsx(reactIcons.Pencil1Icon,{className:"h-3 w-3"})}),jsxRuntime.jsxs(tooltip.AlertDialog,{children:[jsxRuntime.jsx(tooltip.AlertDialogTrigger,{asChild:!0,children:jsxRuntime.jsx(tooltip.Button,{variant:"ghost",size:"sm",disabled:r||l!==null,className:"h-6 w-6 p-0",children:jsxRuntime.jsx(reactIcons.TrashIcon,{className:"h-3 w-3 text-destructive"})})}),jsxRuntime.jsxs(tooltip.AlertDialogContent,{className:"max-w-md",children:[jsxRuntime.jsxs(tooltip.AlertDialogHeader,{children:[jsxRuntime.jsx(tooltip.AlertDialogTitle,{className:"text-base",children:o("Delete Token")}),jsxRuntime.jsxs(tooltip.AlertDialogDescription,{className:"text-sm",children:[o("Delete this token?"),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("code",{className:"mt-1 inline-block rounded bg-muted px-1 py-0.5 font-mono text-xs",children:N.name})]})]}),jsxRuntime.jsxs(tooltip.AlertDialogFooter,{children:[jsxRuntime.jsx(tooltip.AlertDialogCancel,{className:"h-7 text-xs",children:o("Cancel")}),jsxRuntime.jsx(tooltip.AlertDialogAction,{onClick:()=>I(T),className:"h-7 bg-destructive text-xs text-destructive-foreground hover:bg-destructive/90",children:o("Delete")})]})]})]})]})]},T))})})}),jsxRuntime.jsx(tooltip.Dialog,{open:d,onOpenChange:H,children:jsxRuntime.jsxs(tooltip.DialogContent,{className:"max-w-md",children:[jsxRuntime.jsxs(tooltip.DialogHeader,{children:[jsxRuntime.jsx(tooltip.DialogTitle,{className:"text-base",children:o("Add Design Token")}),jsxRuntime.jsx(tooltip.DialogDescription,{className:"text-sm",children:o("Create a new reusable design token with Tailwind classes.")})]}),jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(tooltip.Label,{htmlFor:"new-selector",className:"text-sm",children:o("Token Name")}),jsxRuntime.jsx(tooltip.Input,{id:"new-selector",placeholder:"Button-Primary",value:h,onChange:T=>V(T.target.value),className:"text-sm"}),k?jsxRuntime.jsx("span",{className:"text-sm text-destructive",children:k}):jsxRuntime.jsx("span",{className:"text-sm text-muted-foreground",children:o("Button-Primary, Card-Header, Text-Large")})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(tooltip.Label,{htmlFor:"new-classes",className:"text-sm",children:o("Tailwind Classes")}),jsxRuntime.jsx(tooltip.Textarea,{id:"new-classes",placeholder:"bg-blue-500 text-white px-4 py-2",value:g,onChange:T=>f(T.target.value),className:"min-h-[80px] resize-none font-mono text-xs"})]})]}),jsxRuntime.jsxs(tooltip.DialogFooter,{children:[jsxRuntime.jsx(tooltip.Button,{variant:"outline",onClick:H,className:"h-8 text-sm",children:o("Cancel")}),jsxRuntime.jsx(tooltip.Button,{onClick:A,className:"h-8 text-sm",children:o("Add Token")})]})]})}),jsxRuntime.jsx(tooltip.Dialog,{open:u,onOpenChange:D,children:jsxRuntime.jsxs(tooltip.DialogContent,{className:"max-w-md",children:[jsxRuntime.jsxs(tooltip.DialogHeader,{children:[jsxRuntime.jsx(tooltip.DialogTitle,{className:"text-base",children:o("Edit Design Token")}),jsxRuntime.jsx(tooltip.DialogDescription,{className:"text-sm",children:o("Update the design token name and classes.")})]}),jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(tooltip.Label,{htmlFor:"edit-selector",className:"text-sm",children:o("Token Name")}),jsxRuntime.jsx(tooltip.Input,{id:"edit-selector",value:b,onChange:T=>O(T.target.value),className:"text-sm"}),v&&jsxRuntime.jsx("span",{className:"text-sm text-destructive",children:v})]}),jsxRuntime.jsxs("div",{className:"space-y-2",children:[jsxRuntime.jsx(tooltip.Label,{htmlFor:"edit-classes",className:"text-sm",children:o("Classes")}),jsxRuntime.jsx(tooltip.Textarea,{id:"edit-classes",value:R,onChange:T=>y(T.target.value),className:"min-h-[80px] resize-none font-mono text-xs"})]})]}),jsxRuntime.jsxs(tooltip.DialogFooter,{children:[jsxRuntime.jsx(tooltip.Button,{variant:"outline",onClick:D,className:"h-8 text-sm",children:o("Cancel")}),jsxRuntime.jsx(tooltip.Button,{onClick:_,className:"h-8 text-sm",children:o("Update Token")})]})]})})]})},DEFAULT_PANEL_WIDTH=280,OutlineButton=({isActive:o,show:n})=>jsxRuntime.jsx(tooltip.Button,{variant:o?"default":"ghost",size:"icon",onClick:n,children:jsxRuntime.jsx(reactIcons.StackIcon,{className:"h-5 w-5"})}),AddBlocksButton=({isActive:o,show:n})=>useIsDragAndDropEnabled()&&jsxRuntime.jsx(tooltip.Button,{variant:o?"default":"ghost",size:"icon",onClick:n,children:jsxRuntime.jsx(reactIcons.PlusCircledIcon,{className:"h-5 w-5"})}),AskAiButton=({isActive:o,show:n})=>jsxRuntime.jsx(tooltip.Button,{variant:o?"default":"ghost",size:"icon",onClick:n,children:jsxRuntime.jsx(AiIcon,{})});registerChaiSidebarPanel("add-block",{button:AddBlocksButton,label:"Add Blocks",position:"top",isInternal:!0,width:DEFAULT_PANEL_WIDTH,panel:()=>jsxRuntime.jsx(AddBlocksPanel,{showHeading:!1,fromSidebar:!0,parentId:void 0,position:-1})});registerChaiSidebarPanel("chai-chat-panel",{button:AskAiButton,label:"Ask AI",position:"top",isInternal:!0,width:DEFAULT_PANEL_WIDTH,panel:()=>jsxRuntime.jsx("div",{className:"",children:jsxRuntime.jsx(AskAI,{})})});registerChaiSidebarPanel("outline",{button:OutlineButton,label:"Outline",position:"top",isInternal:!0,width:DEFAULT_PANEL_WIDTH,panel:()=>jsxRuntime.jsx("div",{className:"-mt-8",children:jsxRuntime.jsx(ListTree,{})})});const RootLayout=()=>{const o=useTopBarComponent(),[n,a]=useSidebarActivePanel(),r=React.useRef("outline"),[i,l]=React.useState(DEFAULT_PANEL_WIDTH),[c,d]=useRightPanel(),p=useChaiSidebarPanels("top"),u=useChaiSidebarPanels("bottom"),m=lodashEs.reverse([...u??[]]),h=React.useCallback(C=>{C.preventDefault()},[]),x=React.useMemo(()=>[p].flat(),[p]),g=React.useCallback(C=>{console.log("handleMenuItemClick",C,n),a(n===C?null:C)},[n,a]),{t:f}=reactI18next.useTranslation(),b=React.useMemo(()=>[...p,...u],[p,u]),j=useBuilderProp("htmlDir","ltr"),R=lodashEs.find(b,{id:n})??lodashEs.first(b),y=lodashEs.get(R,"width",DEFAULT_PANEL_WIDTH);React.useEffect(()=>{if(n!==null){const C=lodashEs.find(b,{id:n});C&&lodashEs.get(C,"view","standard")==="standard"&&(r.current=n,l(lodashEs.get(C,"width",DEFAULT_PANEL_WIDTH)))}},[n,b]);const k=React.useMemo(()=>{if(n===null)return 0;const C=lodashEs.find(b,{id:n});return lodashEs.get(C,"view","standard")==="standard"?y:i},[n,y,i,b]),S=React.useCallback(()=>{a(r.current)},[a,n]),v=React.useCallback(()=>{a("outline")},[a]);React.useEffect(()=>{n!==null&&!lodashEs.find(b,{id:n})&&a("outline")},[n,b]);const B=React.useCallback(C=>{g(C)},[g]);return jsxRuntime.jsx("div",{dir:j,className:"h-screen max-h-full w-screen overflow-x-hidden bg-background text-foreground",children:jsxRuntime.jsxs(tooltip.TooltipProvider,{children:[jsxRuntime.jsxs("div",{onContextMenu:h,className:"flex h-full max-h-full flex-col bg-background text-foreground",children:[jsxRuntime.jsx("div",{className:"flex h-[50px] w-screen items-center border-b border-border",children:jsxRuntime.jsx(React.Suspense,{children:jsxRuntime.jsx(o,{})})}),jsxRuntime.jsxs("main",{className:"relative flex h-[calc(100vh-56px)] max-w-full flex-1 flex-row",children:[jsxRuntime.jsxs("div",{id:"sidebar",className:"flex w-12 flex-col items-center justify-between border-r border-border py-2",children:[jsxRuntime.jsx("div",{className:"flex flex-col gap-y-1",children:x.map((C,w)=>jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:React.createElement(lodashEs.get(C,"button",NoopComponent),{position:"top",panelId:C.id,isActive:n===C.id,show:()=>B(C.id)})}),jsxRuntime.jsx(tooltip.TooltipContent,{side:"right",children:jsxRuntime.jsx("p",{children:f(C.label)})})]},"button-top-"+w))}),jsxRuntime.jsx("div",{className:"flex flex-col space-y-1"}),jsxRuntime.jsx("div",{className:"flex flex-col",children:m==null?void 0:m.map((C,w)=>jsxRuntime.jsxs(tooltip.Tooltip,{children:[jsxRuntime.jsx(tooltip.TooltipTrigger,{asChild:!0,children:React.createElement(lodashEs.get(C,"button",NoopComponent),{position:"bottom",panelId:C.id,isActive:n===C.id,show:()=>B(C.id)})}),jsxRuntime.jsx(tooltip.TooltipContent,{side:"right",children:jsxRuntime.jsx("p",{children:f(C.label)})})]},"button-bottom-"+w))})]}),jsxRuntime.jsx(framerMotion.motion.div,{id:"left-panel",className:"h-full max-h-full border-r border-border",initial:{width:k},animate:{width:k},transition:{duration:.3,ease:"easeInOut"},children:n!==null&&lodashEs.get(R,"view","standard")==="standard"&&jsxRuntime.jsxs("div",{className:"no-scrollbar flex h-full flex-col overflow-hidden px-3 py-2",children:[jsxRuntime.jsx("div",{className:`absolute top-2 flex h-10 items-center space-x-1 py-2 text-base font-bold ${lodashEs.get(R,"isInternal",!1)?"":"w-64"}`,children:jsxRuntime.jsx("span",{children:f(lodashEs.get(R,"label",""))})}),jsxRuntime.jsx("div",{className:"no-scrollbar h-full max-h-full overflow-y-auto pt-10",children:jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx("div",{children:"Loading..."}),children:React.createElement(lodashEs.get(R,"panel",NoopComponent),{})})})]})}),jsxRuntime.jsxs("div",{id:"canvas-container",className:"flex h-full max-h-full flex-1 flex-col bg-slate-800/20",children:[jsxRuntime.jsx(CanvasTopBar,{}),jsxRuntime.jsx(React.Suspense,{children:jsxRuntime.jsx(CanvasArea,{})})]}),jsxRuntime.jsx(framerMotion.motion.div,{id:"right-panel",className:"h-full max-h-full border-l border-border",initial:{width:n==="ai"?0:DEFAULT_PANEL_WIDTH},animate:{width:n==="ai"?0:DEFAULT_PANEL_WIDTH},transition:{duration:.3,ease:"easeInOut"},children:jsxRuntime.jsx("div",{className:"no-scrollbar overflow h-full max-h-full overflow-hidden",children:jsxRuntime.jsxs("div",{className:"flex h-full max-h-full flex-col overflow-hidden p-3",children:[jsxRuntime.jsx("h2",{className:"-mt-1 flex items-center space-x-1 text-base font-bold",children:jsxRuntime.jsx("div",{className:"flex grow items-center gap-2",children:jsxRuntime.jsx("div",{className:"flex w-full items-center justify-between gap-2",children:c==="ai"?jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(reactIcons.LightningBoltIcon,{className:"rtl:ml-2"})," ",f("AI Assistant")]})}):c==="design-tokens"?jsxRuntime.jsxs("div",{className:"mb-1 flex w-full items-center justify-between gap-2",children:[jsxRuntime.jsxs("span",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(DesignTokensIcon,{className:"h-4 w-4 text-gray-600"}),f("Design Tokens")]}),jsxRuntime.jsx(tooltip.Button,{onClick:()=>d("block"),variant:"ghost",size:"icon",className:"text-xs",children:jsxRuntime.jsx(reactIcons.Cross1Icon,{className:"h-4 w-4 rtl:ml-2"})})]}):c==="theme"?jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between gap-2",children:[jsxRuntime.jsxs("span",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(reactIcons.MixerHorizontalIcon,{className:"h-4 w-4 text-gray-600"}),f("Theme Settings")]}),jsxRuntime.jsx(tooltip.Button,{onClick:()=>d("block"),variant:"ghost",size:"icon",className:"text-xs",children:jsxRuntime.jsx(reactIcons.Cross1Icon,{className:"h-4 w-4 rtl:ml-2"})})]}):null})})}),jsxRuntime.jsx("div",{className:"flex h-full max-h-full w-full",children:jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx("div",{children:"Loading..."}),children:c==="ai"?jsxRuntime.jsx(AskAI,{}):c==="design-tokens"?jsxRuntime.jsx(ManageDesignTokens,{}):c==="theme"?jsxRuntime.jsx(ThemeConfigPanel,{}):jsxRuntime.jsx(SettingsPanel,{})})})]})})})]})]}),jsxRuntime.jsx(AddBlocksDialog,{}),n!==null&&lodashEs.get(R,"view")==="drawer"&&jsxRuntime.jsx(tooltip.Sheet,{open:!0,onOpenChange:()=>S(),children:jsxRuntime.jsxs(tooltip.SheetContent,{side:"left",className:"flex flex-col gap-0 p-0 sm:max-w-full",style:{width:`${y}px`},children:[jsxRuntime.jsx(tooltip.SheetHeader,{className:"border-b border-border px-2 py-2.5",children:jsxRuntime.jsxs(tooltip.SheetTitle,{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"inline-block",children:lodashEs.get(R,"icon",null)}),jsxRuntime.jsx("span",{children:f(lodashEs.get(R,"label",""))})]})}),jsxRuntime.jsx("div",{className:"h-full max-h-full overflow-y-auto p-4",children:jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx("div",{children:"Loading..."}),children:React.createElement(lodashEs.get(R,"panel",NoopComponent),{close:v})})})]})})," ",n!==null&&lodashEs.get(R,"view")==="modal"&&jsxRuntime.jsx(tooltip.Dialog,{open:!0,onOpenChange:()=>S(),children:jsxRuntime.jsxs(tooltip.DialogContent,{className:"gap-0 p-0",style:{maxWidth:`${y}px`},children:[jsxRuntime.jsx(tooltip.DialogHeader,{className:"border-b border-border px-2 py-3.5",children:jsxRuntime.jsxs(tooltip.DialogTitle,{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"inline-block",children:lodashEs.get(R,"icon",null)}),jsxRuntime.jsx("span",{children:f(lodashEs.get(R,"label",""))})]})}),jsxRuntime.jsx("div",{className:"max-h-[70vh] overflow-y-auto p-4",children:jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx("div",{children:"Loading..."}),children:React.createElement(lodashEs.get(R,"panel",NoopComponent),{close:v})})})]})}),n!==null&&lodashEs.get(R,"view")==="overlay"&&jsxRuntime.jsx(framerMotion.motion.div,{className:"absolute bottom-0 left-12 right-0 top-0 z-50",initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.3},children:jsxRuntime.jsx("div",{className:"h-full w-full",children:jsxRuntime.jsxs(framerMotion.motion.div,{className:"flex h-full w-full flex-col bg-background",initial:{y:-20,opacity:0},animate:{y:0,opacity:1},exit:{y:20,opacity:0},transition:{duration:.3,delay:.1},children:[jsxRuntime.jsxs("div",{className:"flex h-[50px] items-center justify-between border-b border-border p-4",children:[jsxRuntime.jsxs("div",{className:"-ml-2 flex items-center gap-2 text-lg font-bold",children:[jsxRuntime.jsx("span",{className:"rtl:ml-2 rtl:inline-block",children:lodashEs.get(R,"icon",null)}),jsxRuntime.jsx("span",{children:f(lodashEs.get(R,"label",""))})]}),jsxRuntime.jsx(tooltip.Button,{onClick:()=>S(),variant:"ghost",size:"icon",className:"",children:jsxRuntime.jsx(reactIcons.Cross1Icon,{className:"h-5 w-5"})})]}),jsxRuntime.jsx("div",{className:"flex-1 overflow-y-auto p-4",children:jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx("div",{children:"Loading..."}),children:React.createElement(lodashEs.get(R,"panel",NoopComponent),{close:v})})})]})})})]})})},PreviewScreen=()=>{const[o,n]=usePreviewMode(),{t:a}=reactI18next.useTranslation(),r=useBuilderProp("previewComponent",null);return o?jsxRuntime.jsxs("div",{className:commonFunctions.cn("fixed inset-0 z-[999] bg-background",o?"block":"hidden"),children:[jsxRuntime.jsxs(tooltip.Button,{size:"sm",className:"absolute right-0 top-0 m-4 space-x-2",onClick:()=>n(!1),children:[jsxRuntime.jsx(reactIcons.EyeClosedIcon,{}),jsxRuntime.jsx("span",{children:a("Close Preview")})]}),jsxRuntime.jsx("div",{children:r?jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx(tooltip.Skeleton,{className:"h-96 w-full"}),children:React.createElement(r)}):null})]}):null},CHAI_FEATURE_FLAGS={},registerChaiFeatureFlag=(o,n)=>{if(CHAI_FEATURE_FLAGS[o])throw new Error(`Flag ${o} already exists`);CHAI_FEATURE_FLAGS[o]={key:o,value:!1,...n}},registerChaiFeatureFlags=o=>{Object.entries(o).forEach(([n,a])=>{if(CHAI_FEATURE_FLAGS[n])throw new Error(`Flag ${n} already exists`);registerChaiFeatureFlag(n,a)})},useChaiFeatureFlags=()=>CHAI_FEATURE_FLAGS,featureFlagsAtom=utils.atomWithStorage("chai-feature-flags",[]),useChaiFeatureFlag=o=>{const[n]=jotai.useAtom(featureFlagsAtom);return n.includes(o)},useToggleChaiFeatureFlag=o=>{const[n,a]=jotai.useAtom(featureFlagsAtom);return()=>{n.includes(o)?a(n.filter(i=>i!==o)):a([...n,o])}},IfChaiFeatureFlag=({flagKey:o,children:n})=>useChaiFeatureFlag(o)?n:null,FeatureToggle=({featureKey:o,options:n})=>{const a=useToggleChaiFeatureFlag(o),r=useChaiFeatureFlag(o);return jsxRuntime.jsxs("div",{className:"flex items-center space-x-3 rounded-md p-2 transition-colors hover:bg-gray-50 dark:hover:bg-gray-800",children:[jsxRuntime.jsx(tooltip.Switch,{checked:r,onCheckedChange:a}),jsxRuntime.jsxs("div",{className:"flex-1",children:[jsxRuntime.jsx("p",{className:"text-sm font-medium text-gray-900 dark:text-gray-100",children:n.key}),n.description&&jsxRuntime.jsx("p",{className:"mt-0.5 text-xs text-gray-500 dark:text-gray-400",children:n.description})]})]})},showFeatureFlagAtom=utils.atomWithStorage("show-feature-flag",null),ChaiFeatureFlagsWidgetComponent=({close:o,position:n,updatePosition:a})=>{const r=useChaiFeatureFlags(),[i,l]=React.useState(""),[c,d]=React.useState(!1),[p,u]=React.useState({x:0,y:0}),m=React.useMemo(()=>{if(!i.trim())return r;const f=i.toLowerCase();return Object.fromEntries(Object.entries(r).filter(([b,j])=>{var R;return(b==null?void 0:b.toLowerCase().includes(f))||((R=j==null?void 0:j.description)==null?void 0:R.toLowerCase().includes(f))}))},[r,i]),h=f=>{d(!0),u({x:f.clientX-n.x,y:f.clientY-n.y})},x=f=>{if(!c)return;const b=f.clientX-p.x,j=f.clientY-p.y,R=f.currentTarget,y=R.offsetWidth,k=R.offsetHeight,S=window.innerWidth-y,v=window.innerHeight-k,B=Math.max(0,Math.min(b,S)),C=Math.max(0,Math.min(j,v));a(B,C)},g=()=>{d(!1)};return React.useEffect(()=>{const f=()=>{c&&d(!1)};return window.addEventListener("mouseup",f),()=>window.removeEventListener("mouseup",f)},[c]),!n||n.x<0||n.y<0?null:jsxRuntime.jsxs("div",{onMouseDown:h,onMouseMove:x,onMouseUp:g,className:"fixed z-[9999999] select-none rounded-md border border-gray-300 bg-white p-3 shadow-2xl",style:{left:n.x,top:n.y,cursor:c?"grabbing":"grab",userSelect:"none"},children:[jsxRuntime.jsxs("div",{className:"relative sticky top-0 rounded-t-lg bg-white",children:[jsxRuntime.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("h3",{className:"flex items-center gap-x-2 text-base font-semibold text-gray-900 dark:text-gray-100",children:[jsxRuntime.jsx(reactIcons.DragHandleDots2Icon,{})," Feature Flags"]}),jsxRuntime.jsxs("p",{className:"text-xs text-gray-400 dark:text-gray-400",children:["Toggle experimental features (",jsxRuntime.jsx("span",{className:"font-mono",children:"Ctrl+Shift+1"})," to toggle)"]})]}),jsxRuntime.jsx(tooltip.Button,{variant:"ghost",size:"sm",onClick:o,className:"absolute -right-2 -top-2 p-1 text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200",children:jsxRuntime.jsx(reactIcons.Cross1Icon,{className:"h-4 w-4"})})]}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(reactIcons.MagnifyingGlassIcon,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),jsxRuntime.jsx(tooltip.Input,{type:"search",placeholder:"Search features...",className:"w-full pl-8",value:i,onChange:f=>l(f.target.value),autoFocus:!0})]})]}),jsxRuntime.jsx("div",{className:"max-h-96 overflow-y-auto py-2",children:Object.keys(m).length>0?jsxRuntime.jsx("div",{className:"space-y-1",children:Object.entries(m).map(([f,b])=>jsxRuntime.jsx(FeatureToggle,{featureKey:f,options:b},f))}):jsxRuntime.jsx("div",{className:"py-8 text-center",children:jsxRuntime.jsxs("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:['No features found matching "',i,'"']})})})]})},ChaiFeatureFlagsWidget=()=>{const[o,n]=jotai.useAtom(showFeatureFlagAtom);return reactHotkeysHook.useHotkeys("ctrl+shift+1,meta+shift+1",()=>n(a=>a?{...a,show:!a.show}:{x:0,y:0,show:!0}),{enableOnFormTags:!0}),o!=null&&o.show?jsxRuntime.jsx(ChaiFeatureFlagsWidgetComponent,{position:o,close:()=>n(a=>({...a,show:!1})),updatePosition:(a,r)=>n(i=>({...i,x:a,y:r}))}):null},setDebugLogs=o=>{},getParentNodeIds=(o,n)=>{const a=[];let r=lodashEs.find(o,{_id:n}),i=lodashEs.get(r,"_parent","");for(;lodashEs.isString(i)&&!lodashEs.isEmpty(i);)a.push(r==null?void 0:r._parent),r=lodashEs.find(o,{_id:i}),i=r==null?void 0:r._parent;return lodashEs.flatten(a)},expandedIdsAtom=jotai.atom([]),useExpandTree=()=>{const[o]=useSelectedBlockIds(),n=jotai.useAtomValue(presentBlocksAtom),[,a]=jotai.useAtom(expandedIdsAtom);React.useEffect(()=>{let r=[];const i=lodashEs.first(o);lodashEs.isString(i)&&(r=[i,...getParentNodeIds(n,i)]),a(r)},[o,n,a])},ScreenTooSmall=()=>{const o=useBuilderProp("smallScreenComponent",null);return jsxRuntime.jsx("section",{className:"fixed inset-0 z-[99999] flex h-screen w-screen items-center justify-center bg-white xl:hidden",children:o?React.createElement(o):jsxRuntime.jsx("div",{className:"flex h-full w-full items-center justify-center bg-[linear-gradient(to_right,#f3f4f6_1px,transparent_1px),linear-gradient(to_bottom,#f3f4f6_1px,transparent_1px)] bg-[size:10px_10px] py-12 sm:py-16 lg:py-20",children:jsxRuntime.jsx("div",{className:"mx-auto max-w-7xl px-4 sm:px-6 lg:px-8",children:jsxRuntime.jsxs("div",{className:"mx-auto max-w-md space-y-6 text-center",children:[jsxRuntime.jsx("img",{src:"https://ucarecdn.com/fbfc3b05-cb73-4e99-92a2-3a367b7c36cd/",alt:"Chai Builder",className:"mx-auto h-20 w-20 rounded-full shadow-lg transition-transform duration-300 hover:scale-105"}),jsxRuntime.jsxs("div",{className:"space-y-4",children:[jsxRuntime.jsx("h2",{className:"text-5xl font-bold tracking-tight text-gray-900",children:"Screen too small"}),jsxRuntime.jsxs("p",{className:"mx-auto max-w-sm text-sm leading-7 text-gray-600",children:["Please view this page on greater than ",jsxRuntime.jsx("strong",{className:"font-medium",children:"1280px"})," screen width for the best experience."]})]}),jsxRuntime.jsx("div",{className:"pt-4",children:jsxRuntime.jsxs("div",{className:"inline-flex items-center rounded-full bg-gray-100 px-4 py-2 text-sm text-gray-700",children:[jsxRuntime.jsx("svg",{className:"mr-2 h-5 w-5",fill:"none",stroke:"currentColor",viewBox:"0 0 24 24",children:jsxRuntime.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z"})}),"Minimum width: 1280px"]})})]})})})})};function isSelfAtom(o,n){return o.unstable_is?o.unstable_is(n):n===o}function hasInitialValue(o){return"init"in o}function isActuallyWritableAtom(o){return!!o.write}function isAtomStateInitialized(o){return"v"in o||"e"in o}function returnAtomValue(o){if("e"in o)throw o.e;return o.v}const promiseStateMap=new WeakMap;function isPendingPromise(o){var n;return isPromiseLike$1(o)&&!!((n=promiseStateMap.get(o))!=null&&n[0])}function abortPromise(o){const n=promiseStateMap.get(o);n!=null&&n[0]&&(n[0]=!1,n[1].forEach(a=>a()))}function registerAbortHandler(o,n){let a=promiseStateMap.get(o);if(!a){a=[!0,new Set],promiseStateMap.set(o,a);const r=()=>{a[0]=!1};o.then(r,r)}a[1].add(n)}function isPromiseLike$1(o){return typeof(o==null?void 0:o.then)=="function"}function addPendingPromiseToDependency(o,n,a){if(!a.p.has(o)){a.p.add(o);const r=()=>a.p.delete(o);n.then(r,r)}}function getMountedOrPendingDependents(o,n,a){var r;const i=new Set;for(const l of((r=a.get(o))==null?void 0:r.t)||[])a.has(l)&&i.add(l);for(const l of n.p)i.add(l);return i}const atomRead=(o,n,...a)=>n.read(...a),atomWrite=(o,n,...a)=>n.write(...a),atomOnInit=(o,n)=>{var a;return(a=n.unstable_onInit)==null?void 0:a.call(n,o)},atomOnMount=(o,n,a)=>{var r;return(r=n.onMount)==null?void 0:r.call(n,a)},ensureAtomState=(o,n)=>{const a=getBuildingBlocks(o),r=a[0],i=a[9];let l=r.get(n);return l||(l={d:new Map,p:new Set,n:0},r.set(n,l),i==null||i(o,n)),l},flushCallbacks=o=>{const n=getBuildingBlocks(o),a=n[1],r=n[3],i=n[4],l=n[5],c=n[6],d=n[13],p=[],u=m=>{try{m()}catch(h){p.push(h)}};do{c.f&&u(c.f);const m=new Set,h=m.add.bind(m);r.forEach(x=>{var g;return(g=a.get(x))==null?void 0:g.l.forEach(h)}),r.clear(),l.forEach(h),l.clear(),i.forEach(h),i.clear(),m.forEach(u),r.size&&d(o)}while(r.size||l.size||i.size);if(p.length)throw new AggregateError(p)},recomputeInvalidatedAtoms=o=>{const n=getBuildingBlocks(o),a=n[1],r=n[2],i=n[3],l=n[11],c=n[14],d=n[17],p=[],u=new WeakSet,m=new WeakSet,h=Array.from(i);for(;h.length;){const x=h[h.length-1],g=l(o,x);if(m.has(x)){h.pop();continue}if(u.has(x)){r.get(x)===g.n&&p.push([x,g]),m.add(x),h.pop();continue}u.add(x);for(const f of getMountedOrPendingDependents(x,g,a))u.has(f)||h.push(f)}for(let x=p.length-1;x>=0;--x){const[g,f]=p[x];let b=!1;for(const j of f.d.keys())if(j!==g&&i.has(j)){b=!0;break}b&&(c(o,g),d(o,g)),r.delete(g)}},readAtomState=(o,n)=>{var a;const r=getBuildingBlocks(o),i=r[1],l=r[2],c=r[3],d=r[6],p=r[7],u=r[11],m=r[12],h=r[13],x=r[14],g=r[16],f=r[17],b=u(o,n);if(isAtomStateInitialized(b)&&(i.has(n)&&l.get(n)!==b.n||Array.from(b.d).every(([C,w])=>x(o,C).n===w)))return b;b.d.clear();let j=!0;function R(){i.has(n)&&(f(o,n),h(o),m(o))}function y(C){var w;if(isSelfAtom(n,C)){const A=u(o,C);if(!isAtomStateInitialized(A))if(hasInitialValue(C))setAtomStateValueOrPromise(o,C,C.init);else throw new Error("no atom init");return returnAtomValue(A)}const E=x(o,C);try{return returnAtomValue(E)}finally{b.d.set(C,E.n),isPendingPromise(b.v)&&addPendingPromiseToDependency(n,b.v,E),(w=i.get(C))==null||w.t.add(n),j||R()}}let k,S;const v={get signal(){return k||(k=new AbortController),k.signal},get setSelf(){return!S&&isActuallyWritableAtom(n)&&(S=(...C)=>{if(!j)try{return g(o,n,...C)}finally{h(o),m(o)}}),S}},B=b.n;try{const C=p(o,n,y,v);return setAtomStateValueOrPromise(o,n,C),isPromiseLike$1(C)&&(registerAbortHandler(C,()=>k==null?void 0:k.abort()),C.then(R,R)),b}catch(C){return delete b.v,b.e=C,++b.n,b}finally{j=!1,B!==b.n&&l.get(n)===B&&(l.set(n,b.n),c.add(n),(a=d.c)==null||a.call(d,n))}},invalidateDependents=(o,n)=>{const a=getBuildingBlocks(o),r=a[1],i=a[2],l=a[11],c=[n];for(;c.length;){const d=c.pop(),p=l(o,d);for(const u of getMountedOrPendingDependents(d,p,r)){const m=l(o,u);i.set(u,m.n),c.push(u)}}},writeAtomState=(o,n,...a)=>{const r=getBuildingBlocks(o),i=r[3],l=r[6],c=r[8],d=r[11],p=r[12],u=r[13],m=r[14],h=r[15],x=r[17];let g=!0;const f=j=>returnAtomValue(m(o,j)),b=(j,...R)=>{var y;const k=d(o,j);try{if(isSelfAtom(n,j)){if(!hasInitialValue(j))throw new Error("atom not writable");const S=k.n,v=R[0];setAtomStateValueOrPromise(o,j,v),x(o,j),S!==k.n&&(i.add(j),(y=l.c)==null||y.call(l,j),h(o,j));return}else return writeAtomState(o,j,...R)}finally{g||(u(o),p(o))}};try{return c(o,n,f,b,...a)}finally{g=!1}},mountDependencies=(o,n)=>{var a;const r=getBuildingBlocks(o),i=r[1],l=r[3],c=r[6],d=r[11],p=r[15],u=r[18],m=r[19],h=d(o,n),x=i.get(n);if(x&&!isPendingPromise(h.v)){for(const[g,f]of h.d)if(!x.d.has(g)){const b=d(o,g);u(o,g).t.add(n),x.d.add(g),f!==b.n&&(l.add(g),(a=c.c)==null||a.call(c,g),p(o,g))}for(const g of x.d||[])if(!h.d.has(g)){x.d.delete(g);const f=m(o,g);f==null||f.t.delete(n)}}},mountAtom=(o,n)=>{var a;const r=getBuildingBlocks(o),i=r[1],l=r[4],c=r[6],d=r[10],p=r[11],u=r[12],m=r[13],h=r[14],x=r[16],g=p(o,n);let f=i.get(n);if(!f){h(o,n);for(const b of g.d.keys())mountAtom(o,b).t.add(n);if(f={l:new Set,d:new Set(g.d.keys()),t:new Set},i.set(n,f),(a=c.m)==null||a.call(c,n),isActuallyWritableAtom(n)){const b=()=>{let j=!0;const R=(...y)=>{try{return x(o,n,...y)}finally{j||(m(o),u(o))}};try{const y=d(o,n,R);y&&(f.u=()=>{j=!0;try{y()}finally{j=!1}})}finally{j=!1}};l.add(b)}}return f},unmountAtom=(o,n)=>{var a;const r=getBuildingBlocks(o),i=r[1],l=r[5],c=r[6],d=r[11],p=r[19],u=d(o,n);let m=i.get(n);if(m&&!m.l.size&&!Array.from(m.t).some(h=>{var x;return(x=i.get(h))==null?void 0:x.d.has(n)})){m.u&&l.add(m.u),m=void 0,i.delete(n),(a=c.u)==null||a.call(c,n);for(const h of u.d.keys()){const x=p(o,h);x==null||x.t.delete(n)}return}return m},setAtomStateValueOrPromise=(o,n,a)=>{const r=getBuildingBlocks(o)[11],i=r(o,n),l="v"in i,c=i.v;if(isPromiseLike$1(a))for(const d of i.d.keys())addPendingPromiseToDependency(n,a,r(o,d));i.v=a,delete i.e,(!l||!Object.is(c,i.v))&&(++i.n,isPromiseLike$1(c)&&abortPromise(c))},storeGet=(o,n)=>{const a=getBuildingBlocks(o)[14];return returnAtomValue(a(o,n))},storeSet=(o,n,...a)=>{const r=getBuildingBlocks(o),i=r[12],l=r[13],c=r[16];try{return c(o,n,...a)}finally{l(o),i(o)}},storeSub=(o,n,a)=>{const r=getBuildingBlocks(o),i=r[12],l=r[18],c=r[19],p=l(o,n).l;return p.add(a),i(o),()=>{p.delete(a),c(o,n),i(o)}},buildingBlockMap=new WeakMap;function getBuildingBlocks(o){return buildingBlockMap.get(o)}function buildStore(...o){const n={get(r){const i=getBuildingBlocks(n)[21];return i(n,r)},set(r,...i){const l=getBuildingBlocks(n)[22];return l(n,r,...i)},sub(r,i){const l=getBuildingBlocks(n)[23];return l(n,r,i)}},a=[new WeakMap,new WeakMap,new WeakMap,new Set,new Set,new Set,{},atomRead,atomWrite,atomOnInit,atomOnMount,ensureAtomState,flushCallbacks,recomputeInvalidatedAtoms,readAtomState,invalidateDependents,writeAtomState,mountDependencies,mountAtom,unmountAtom,setAtomStateValueOrPromise,storeGet,storeSet,storeSub].map((r,i)=>o[i]||r);return buildingBlockMap.set(n,Object.freeze(a)),n}function createStore(){return buildStore()}let defaultStore;function getDefaultStore(){return defaultStore||(defaultStore=createStore()),defaultStore}const StoreContext=React.createContext(void 0);function useStore(o){return React.useContext(StoreContext)||getDefaultStore()}const isPromiseLike=o=>typeof(o==null?void 0:o.then)=="function",attachPromiseStatus=o=>{o.status||(o.status="pending",o.then(n=>{o.status="fulfilled",o.value=n},n=>{o.status="rejected",o.reason=n}))},use=React.use||(o=>{if(o.status==="pending")throw o;if(o.status==="fulfilled")return o.value;throw o.status==="rejected"?o.reason:(attachPromiseStatus(o),o)}),continuablePromiseMap=new WeakMap,createContinuablePromise=(o,n)=>{let a=continuablePromiseMap.get(o);return a||(a=new Promise((r,i)=>{let l=o;const c=u=>m=>{l===u&&r(m)},d=u=>m=>{l===u&&i(m)},p=()=>{try{const u=n();isPromiseLike(u)?(continuablePromiseMap.set(u,a),l=u,u.then(c(u),d(u)),registerAbortHandler(u,p)):r(u)}catch(u){i(u)}};o.then(c(o),d(o)),registerAbortHandler(o,p)}),continuablePromiseMap.set(o,a)),a};function useAtomValue(o,n){const{delay:a,unstable_promiseStatus:r=!React.use}={},i=useStore(),[[l,c,d],p]=React.useReducer(m=>{const h=i.get(o);return Object.is(m[0],h)&&m[1]===i&&m[2]===o?m:[h,i,o]},void 0,()=>[i.get(o),i,o]);let u=l;if((c!==i||d!==o)&&(p(),u=i.get(o)),React.useEffect(()=>{const m=i.sub(o,()=>{if(r)try{const h=i.get(o);isPromiseLike(h)&&attachPromiseStatus(createContinuablePromise(h,()=>i.get(o)))}catch{}if(typeof a=="number"){setTimeout(p,a);return}p()});return p(),m},[i,o,a,r]),React.useDebugValue(u),isPromiseLike(u)){const m=createContinuablePromise(u,()=>i.get(o));return r&&attachPromiseStatus(m),use(m)}return u}function useSetAtom(o,n){const a=useStore();return React.useCallback((...i)=>a.set(o,...i),[a,o])}function useAtom(o,n){return[useAtomValue(o),useSetAtom(o)]}function convertAttributeName(o){const n={class:"className",for:"htmlFor",tabindex:"tabIndex",readonly:"readOnly",maxlength:"maxLength",minlength:"minLength",autocomplete:"autoComplete",autofocus:"autoFocus",autoplay:"autoPlay",formaction:"formAction",formenctype:"formEncType",formmethod:"formMethod",formnovalidate:"formNoValidate",formtarget:"formTarget",novalidate:"noValidate",crossorigin:"crossOrigin",datetime:"dateTime",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",allowfullscreen:"allowFullScreen"};if(n[o.toLowerCase()])return n[o.toLowerCase()];const a={"accent-height":"accentHeight","alignment-baseline":"alignmentBaseline","arabic-form":"arabicForm","baseline-shift":"baselineShift","cap-height":"capHeight","clip-path":"clipPath","clip-rule":"clipRule","color-interpolation":"colorInterpolation","color-interpolation-filters":"colorInterpolationFilters","color-profile":"colorProfile","color-rendering":"colorRendering","dominant-baseline":"dominantBaseline","enable-background":"enableBackground","fill-opacity":"fillOpacity","fill-rule":"fillRule","flood-color":"floodColor","flood-opacity":"floodOpacity","font-family":"fontFamily","font-size":"fontSize","font-size-adjust":"fontSizeAdjust","font-stretch":"fontStretch","font-style":"fontStyle","font-variant":"fontVariant","font-weight":"fontWeight","glyph-name":"glyphName","glyph-orientation-horizontal":"glyphOrientationHorizontal","glyph-orientation-vertical":"glyphOrientationVertical","horiz-adv-x":"horizAdvX","horiz-origin-x":"horizOriginX","image-rendering":"imageRendering","letter-spacing":"letterSpacing","lighting-color":"lightingColor","marker-end":"markerEnd","marker-mid":"markerMid","marker-start":"markerStart","overline-position":"overlinePosition","overline-thickness":"overlineThickness","paint-order":"paintOrder","panose-1":"panose1","pointer-events":"pointerEvents","rendering-intent":"renderingIntent","shape-rendering":"shapeRendering","stop-color":"stopColor","stop-opacity":"stopOpacity","strikethrough-position":"strikethroughPosition","strikethrough-thickness":"strikethroughThickness","stroke-dasharray":"strokeDasharray","stroke-dashoffset":"strokeDashoffset","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","stroke-miterlimit":"strokeMiterlimit","stroke-opacity":"strokeOpacity","stroke-width":"strokeWidth","text-anchor":"textAnchor","text-decoration":"textDecoration","text-rendering":"textRendering","underline-position":"underlinePosition","underline-thickness":"underlineThickness","unicode-bidi":"unicodeBidi","unicode-range":"unicodeRange","units-per-em":"unitsPerEm","v-alphabetic":"vAlphabetic","v-hanging":"vHanging","v-ideographic":"vIdeographic","v-mathematical":"vMathematical","vector-effect":"vectorEffect","vert-adv-y":"vertAdvY","vert-origin-x":"vertOriginX","vert-origin-y":"vertOriginY","word-spacing":"wordSpacing","writing-mode":"writingMode","x-height":"xHeight"};return a[o]?a[o]:o}function domToJsx(o,n=0){var u;if(Array.isArray(o)){if(o.length===0)return"";if(o.length===1)return domToJsx(o[0],n);const m=" ".repeat(n);let h=`${m}<>
|
|
130
|
+
`;for(const x of o)h+=domToJsx(x,n+1);return h+=`${m}</>
|
|
131
|
+
`,h}const a=" ".repeat(n);if(o.nodeType===Node.TEXT_NODE){const m=(u=o.textContent)==null?void 0:u.trim();return m?`${a}${m}
|
|
132
|
+
`:""}if(o.nodeType!==Node.ELEMENT_NODE)return"";const r=o.tagName.toLowerCase();if(["img","br","hr","input","meta","link","area","base","col","embed","source","track","wbr"].includes(r)){const m=[];for(const x of o.attributes)if(x.name.startsWith("on")&&x.name!=="on"){const g=x.name.toLowerCase().replace(/on(\w)/,(f,b)=>"on"+b.toUpperCase());m.push(`${g}={${x.value}}`)}else if(x.name==="style"&&x.value){const g=x.value.split(";").reduce((f,b)=>{const[j,R]=b.split(":").map(y=>y.trim());if(j&&R){const y=j.replace(/-([a-z])/g,k=>k[1].toUpperCase());f[y]=R.replace(/['"]/g,"")}return f},{});m.push(`style={${JSON.stringify(g)}}`)}else{const g=convertAttributeName(x.name);m.push(`${g}="${x.value}"`)}const h=m.length>0?` ${m.join(" ")}`:"";return`${a}<${r}${h} />
|
|
133
|
+
`}let l=`${a}<${r}`;const c=[];for(const m of o.attributes)if(m.name.startsWith("on")&&m.name!=="on"){const h=m.name.toLowerCase().replace(/on(\w)/,(x,g)=>"on"+g.toUpperCase());c.push(`${h}={${m.value}}`)}else if(m.name==="style"&&m.value){const h=m.value.split(";").reduce((x,g)=>{const[f,b]=g.split(":").map(j=>j.trim());if(f&&b){const j=f.replace(/-([a-z])/g,R=>R[1].toUpperCase());x[j]=b.replace(/['"]/g,"")}return x},{});c.push(`style={${JSON.stringify(h)}}`)}else{const h=convertAttributeName(m.name);c.push(`${h}="${m.value}"`)}c.length>0&&(l+=" "+c.join(" "));const d=Array.from(o.childNodes);if(!d.some(m=>{var h;return m.nodeType===Node.TEXT_NODE?(h=m.textContent)==null?void 0:h.trim():!0}))l+=` />
|
|
134
|
+
`;else{l+=`>
|
|
135
|
+
`;for(const m of d)l+=domToJsx(m,n+1);l+=`${a}</${r}>
|
|
136
|
+
`}return l}function formatHtml(o){if(!o)return"";let n="",a=0;const r=" ";return o=o.replace(/>\s+</g,"><").trim(),o.split(/(<\/?[^>]+>)/g).filter(l=>l.trim()).forEach(l=>{l.match(/^<\/\w/)?(a=Math.max(0,a-1),n+=r.repeat(a)+l+`
|
|
137
|
+
`):l.match(/\/>$/)?n+=r.repeat(a)+l+`
|
|
138
|
+
`:l.match(/^<\w[^>]*[^\/]>$/)?(n+=r.repeat(a)+l+`
|
|
139
|
+
`,a++):l.trim()&&(n+=r.repeat(a)+l.trim()+`
|
|
140
|
+
`)}),n.trim()}const CodeDisplay=React.lazy(()=>Promise.resolve().then(()=>require("./code-display-Dw1tAwiJ.cjs")));async function convertHtmlToJsx(o){try{const n=document.createElement("div");n.innerHTML=o;const a=Array.from(n.children);return{jsx:domToJsx(a.length===1?a[0]:a),html:n.innerHTML}}catch{return{html:o,jsx:o}}}const getExportedCoded=async({selectedBlock:o,html:n,isTypeScript:a=!1})=>{let r=(o==null?void 0:o._name)||(o==null?void 0:o._type)||"Component";r=lodashEs.camelCase(r).replace(/^./,u=>u.toUpperCase());const i=" ";let{jsx:l,html:c}=await convertHtmlToJsx(n);return l=l==null?void 0:l.split(`
|
|
141
|
+
`).join(`
|
|
142
|
+
${i}${i}`),l=`${a?`import React from 'react';
|
|
143
|
+
|
|
144
|
+
`:""}export const ${r}${a?": React.FC":""} = () => {
|
|
145
|
+
${i}return (
|
|
146
|
+
${i}${i}${l==null?void 0:l.trimEnd()}
|
|
147
|
+
${i})
|
|
148
|
+
}`,{jsx:l,html:formatHtml(c),componentName:r}},ExportCodeModalContent=({tab:o})=>{var R;const{t:n}=reactI18next.useTranslation(),[a,r]=React.useState({html:"",jsx:""}),i=useSelectedBlock(),l=useBlocksHtmlForAi(),[c,d]=React.useState(""),[p,u]=React.useState(!1),m=()=>{switch(o){case"js":return`${c}.jsx`;case"ts":return`${c}.tsx`;case"html":return`${c}.html`;case"tailwind":return"tailwind.config.js"}},h=()=>{switch(o){case"js":case"ts":return"javascript";case"html":return"HTML";case"tailwind":return"JSON"}},x=React.useCallback(async()=>{try{u(!1);let y=l({blockId:i==null?void 0:i._id,additionalCoreBlocks:["Icon"]});y=y.replace(/\s*bid=["'][^"']*["']/g,"");const k=o==="ts",{jsx:S,html:v,componentName:B}=await getExportedCoded({selectedBlock:i,html:y,isTypeScript:k});r({html:v,jsx:S}),d(B),u(!0)}catch{const k="<div>Export failed. Close the modal and try again.</div>";r({html:k,jsx:k}),sonner.toast.error(n("Failed to generate export HTML"))}},[n,o,i,l]);React.useEffect(()=>{x()},[x,o]);const g=React.useCallback(async y=>{try{navigator.clipboard.writeText(y),sonner.toast.success(n("Export code copied!"))}catch{sonner.toast.error(n("Failed to copy export code"))}},[n]),f=y=>{const k=new Blob([y],{type:"text/jsx"}),S=URL.createObjectURL(k),v=document.createElement("a");v.href=S,v.download=m(),document.body.appendChild(v),v.click(),URL.revokeObjectURL(S),document.body.removeChild(v),sonner.toast.success(n("Export code downloaded successfully!"))},b=jsxRuntime.jsxs("span",{children:["Download ",jsxRuntime.jsx("span",{className:"font-mono text-xs font-light text-gray-300",children:m()})]}),j=React.useMemo(()=>{const y={extend:getChaiBuilderTailwindConfig.shadcnTheme()},k=JSON.stringify(y,null,2);return`{
|
|
149
|
+
// Your tailwind config ...
|
|
150
|
+
|
|
151
|
+
"theme": ${k==null?void 0:k.split(`
|
|
152
|
+
`).join(`
|
|
153
|
+
`)},
|
|
154
|
+
}`},[]);return((R=a==null?void 0:a.jsx)==null?void 0:R.length)>0&&p?jsxRuntime.jsx(CodeDisplay,{onCopy:g,code:o==="tailwind"?j:o==="html"?a.html:a.jsx,language:h(),downloadText:b,onDownload:f},o):jsxRuntime.jsx("div",{className:"flex h-[620px] w-full items-center justify-center p-4",children:"Generating code..."})},ExportCodeModal=()=>{const{t:o}=reactI18next.useTranslation(),[n,a]=React.useState(!1),{setMode:r}=useEditorMode(),[i,l]=React.useState("js"),c=React.useCallback(async()=>{l("js"),r("view"),a(!0)},[n]);usePubSub(CHAI_BUILDER_EVENTS.OPEN_EXPORT_CODE,c);const d=async()=>{r("edit"),await new Promise(p=>setTimeout(p,300)),a(!1)};return jsxRuntime.jsx(tooltip.Dialog,{open:n,onOpenChange:d,children:jsxRuntime.jsxs(tooltip.DialogContent,{className:"max-w-5xl overflow-hidden border-border",children:[jsxRuntime.jsxs(tooltip.DialogHeader,{className:"flex flex-row items-center justify-between",children:[jsxRuntime.jsx(tooltip.DialogTitle,{className:"text-foreground",children:o("Export Code")}),jsxRuntime.jsx(tooltip.Tabs,{defaultValue:"js",onValueChange:l,children:jsxRuntime.jsxs(tooltip.TabsList,{children:[jsxRuntime.jsx(tooltip.TabsTrigger,{value:"js",children:"Javascript"}),jsxRuntime.jsx(tooltip.TabsTrigger,{value:"ts",children:"Typescript"}),jsxRuntime.jsx(tooltip.TabsTrigger,{value:"html",children:"HTML"}),jsxRuntime.jsx(tooltip.TabsTrigger,{value:"tailwind",children:"Tailwind config"})]})}),jsxRuntime.jsx("div",{})]}),jsxRuntime.jsx("div",{className:"flex min-h-[400px] flex-col gap-4",children:n&&jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx("div",{className:"flex h-[400px] items-center justify-center text-muted-foreground",children:"Loading code editor..."}),children:jsxRuntime.jsx(reactErrorBoundary.ErrorBoundary,{fallback:jsxRuntime.jsx("div",{children:"Something went wrong"}),children:jsxRuntime.jsx(ExportCodeModalContent,{tab:i})})})})]})})},ChaiWatchers=o=>{const[,n]=useBlocksStore(),a=useBuilderReset(),[r]=useAtom(builderSaveStateAtom);useAtom(selectedLibraryAtom),useKeyEventWatcher(),useExpandTree(),useAutoSave(),useWatchPartailBlocks(),useUnmountBroadcastChannel();const{postMessage:i}=useBroadcastChannel(),[,l]=useAtom(isPageLoadedAtom),c=useCheckStructure();return React.useEffect(()=>{builderStore.set(chaiBuilderPropsAtom,lodashEs.omit(o,["blocks","translations","pageExternalData","globalStyles"]))},[o]),React.useEffect(()=>{builderStore.set(chaiPageExternalDataAtom,o.pageExternalData||{})},[o.pageExternalData]),React.useEffect(()=>{builderStore.set(chaiDesignTokensAtom,o.designTokens||{})},[o.designTokens]),React.useEffect(()=>{l(!1),setTimeout(()=>{const d=runtime.syncBlocksWithDefaults(o.blocks||[]);n(d),d&&d.length>0&&i({type:"blocks-updated",blocks:d}),a(),l(!0),c(d)},400)},[o.blocks]),React.useEffect(()=>{i18n.changeLanguage(o.locale||"en")},[o.locale]),React.useEffect(()=>{setDebugLogs(o.debugLogs)},[o.debugLogs]),React.useEffect(()=>{o.translations&&lodashEs.each(o.translations,(d,p)=>{i18n.addResourceBundle(p,"translation",d,!0,!0)})},[o.translations]),React.useEffect(()=>(r!=="SAVED"?window.onbeforeunload=()=>"":window.onbeforeunload=null,()=>{window.onbeforeunload=null}),[r]),null},ChaiBuilderComponent=o=>{const n=React.useMemo(()=>o.layout||RootLayout,[o.layout]),a=useBuilderProp("builderTheme",plugin.defaultThemeValues),r=useBuilderProp("flags.exportCode",!1);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[o.children,jsxRuntime.jsx(CssThemeVariables,{theme:a}),jsxRuntime.jsx(n,{}),r&&jsxRuntime.jsx(ExportCodeModal,{})]})},ChaiBuilderEditor=o=>{const n=o.onError||lodashEs.noop;return jsxRuntime.jsx("div",{className:"h-screen w-screen",children:jsxRuntime.jsxs(reactErrorBoundary.ErrorBoundary,{fallback:jsxRuntime.jsx(FallbackError,{}),onError:n,children:[jsxRuntime.jsx(ScreenTooSmall,{}),jsxRuntime.jsx(ChaiBuilderComponent,{...o}),jsxRuntime.jsx(ChaiWatchers,{...o}),jsxRuntime.jsx(PreviewScreen,{}),jsxRuntime.jsx(sonner.Toaster,{richColors:!0}),jsxRuntime.jsx(ChaiFeatureFlagsWidget,{})]})})};if(typeof window>"u")throw new Error("@chaibuilder/sdk is only supported in the browser. Avoid using it in the server side.");exports.AIUserPrompt=AIUserPrompt;exports.AddBlocksDialog=AddBlocksDialog;exports.AddBlocksPanel=AddBlocksPanel;exports.BlockAttributesEditor=BlockAttributesEditor;exports.BlockSettings=BlockSettings;exports.BlockStyling=BlockStyling;exports.Breakpoints=Breakpoints$1;exports.CanvasArea=CanvasArea;exports.ChaiBuilderEditor=ChaiBuilderEditor;exports.ChaiDraggableBlock=ChaiDraggableBlock;exports.DarkMode=DarkMode;exports.DefaultChaiBlocks=DefaultChaiBlocks;exports.ExportCodeModal=ExportCodeModal;exports.IfChaiFeatureFlag=IfChaiFeatureFlag;exports.ImportHTML=ImportHTML;exports.ListTree=ListTree;exports.NestedPathSelector=NestedPathSelector;exports.PERMISSIONS=PERMISSIONS;exports.ThemeConfigPanel=ThemeConfigPanel;exports.UILibrariesPanel=UILibrariesPanel;exports.UndoRedo=UndoRedo;exports.getClassValueAndUnit=getClassValueAndUnit;exports.registerBlockSettingField=registerBlockSettingField;exports.registerBlockSettingTemplate=registerBlockSettingTemplate;exports.registerBlockSettingWidget=registerBlockSettingWidget;exports.registerChaiAddBlockTab=registerChaiAddBlockTab;exports.registerChaiFeatureFlag=registerChaiFeatureFlag;exports.registerChaiFeatureFlags=registerChaiFeatureFlags;exports.registerChaiLibrary=registerChaiLibrary;exports.registerChaiMediaManager=registerChaiMediaManager;exports.registerChaiPreImportHTMLHook=registerChaiPreImportHTMLHook;exports.registerChaiSaveToLibrary=registerChaiSaveToLibrary;exports.registerChaiSidebarPanel=registerChaiSidebarPanel;exports.registerChaiTopBar=registerChaiTopBar;exports.useAddBlock=useAddBlock;exports.useAddClassesToBlocks=useAddClassesToBlocks;exports.useAskAi=useAskAi;exports.useBlockHighlight=useBlockHighlight;exports.useBlocksHtmlForAi=useBlocksHtmlForAi;exports.useBlocksStore=useBlocksStore;exports.useBlocksStoreUndoableActions=useBlocksStoreUndoableActions;exports.useBrandingOptions=useBrandingOptions;exports.useBuilderProp=useBuilderProp;exports.useBuilderReset=useBuilderReset;exports.useCanvasDisplayWidth=useCanvasDisplayWidth;exports.useCanvasWidth=useCanvasWidth;exports.useCanvasZoom=useCanvasZoom;exports.useChaiFeatureFlag=useChaiFeatureFlag;exports.useChaiFeatureFlags=useChaiFeatureFlags;exports.useCodeEditor=useCodeEditor;exports.useCopyBlocks=useCopyBlocks;exports.useCopyToClipboard=useCopyToClipboard;exports.useCurrentPage=useCurrentPage;exports.useCutBlockIds=useCutBlockIds;exports.useDarkMode=useDarkMode;exports.useDuplicateBlocks=useDuplicateBlocks;exports.useHighlightBlockId=useHighlightBlockId;exports.useHtmlToBlocks=useHtmlToBlocks;exports.useI18nBlocks=useI18nBlocks;exports.useInlineEditing=useInlineEditing;exports.useIsPageLoaded=useIsPageLoaded;exports.useLanguages=useLanguages;exports.useLibraryBlocks=useLibraryBlocks;exports.useMediaManagerComponent=useMediaManagerComponent;exports.usePageExternalData=usePageExternalData;exports.usePartialBlocksList=usePartialBlocksList;exports.usePartialBlocksStore=usePartialBlocksStore;exports.usePasteBlocks=usePasteBlocks;exports.usePermissions=usePermissions;exports.usePreviewMode=usePreviewMode;exports.usePubSub=usePubSub;exports.useRemoveAllClassesForBlock=useRemoveAllClassesForBlock;exports.useRemoveBlocks=useRemoveBlocks;exports.useRemoveClassesFromBlocks=useRemoveClassesFromBlocks;exports.useReplaceBlock=useReplaceBlock;exports.useResetBlockStyles=useResetBlockStyles;exports.useRightPanel=useRightPanel;exports.useSavePage=useSavePage;exports.useScreenSizeWidth=useScreenSizeWidth;exports.useSelectedBlock=useSelectedBlock;exports.useSelectedBlockAllClasses=useSelectedBlockAllClasses;exports.useSelectedBlockCurrentClasses=useSelectedBlockCurrentClasses;exports.useSelectedBlockIds=useSelectedBlockIds;exports.useSelectedBlocksDisplayChild=useSelectedBlocksDisplayChild;exports.useSelectedBreakpoints=useSelectedBreakpoints;exports.useSelectedLibrary=useSelectedLibrary;exports.useSelectedStylingBlocks=useSelectedStylingBlocks;exports.useSidebarActivePanel=useSidebarActivePanel;exports.useStreamMultipleBlocksProps=useStreamMultipleBlocksProps;exports.useStylingBreakpoint=useStylingBreakpoint;exports.useStylingState=useStylingState;exports.useTheme=useTheme;exports.useThemeOptions=useThemeOptions;exports.useToggleChaiFeatureFlag=useToggleChaiFeatureFlag;exports.useUndoManager=useUndoManager;exports.useUpdateBlocksProps=useUpdateBlocksProps;exports.useUpdateBlocksPropsRealtime=useUpdateBlocksPropsRealtime;exports.useWrapperBlock=useWrapperBlock;
|