@chaibuilder/sdk 2.5.5 → 2.5.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/core.cjs CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";var V=Object.defineProperty;var U=(o,n,a)=>n in o?V(o,n,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[n]=a;var H=(o,n,a)=>U(o,typeof n!="symbol"?n+"":n,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const jsxRuntime=require("react/jsx-runtime"),runtime=require("@chaibuilder/runtime"),reactIcons=require("@radix-ui/react-icons"),lodashEs=require("lodash-es"),React=require("react"),jotai=require("jotai"),utils=require("jotai/utils"),commonFunctions=require("./common-functions-BZmyleS1.cjs"),toggle=require("./toggle-BgZfmuec.cjs"),lucideReact=require("lucide-react"),clsx=require("clsx"),tailwindMerge=require("tailwind-merge"),TreeModel=require("tree-model"),applyBinding=require("./apply-binding-T3HdSezj.cjs"),plugin=require("./plugin-CSgw-f78.cjs"),utils$1=require("@rjsf/utils"),web=require("@react-hookz/web"),sonner=require("sonner"),reactI18next=require("react-i18next"),Fuse=require("fuse.js"),UndoManager=require("undo-manager"),Link=require("@tiptap/extension-link"),TextAlign=require("@tiptap/extension-text-align"),Underline=require("@tiptap/extension-underline"),Placeholder=require("@tiptap/extension-placeholder"),react=require("@tiptap/react"),StarterKit=require("@tiptap/starter-kit"),RjForm=require("@rjsf/core"),validator=require("@rjsf/validator-ajv8"),Autosuggest=require("react-autosuggest"),flagged=require("flagged"),himalaya=require("himalaya"),reactArborist=require("react-arborist"),i18n=require("i18next"),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"),reactErrorBoundary=require("react-error-boundary"),framerMotion=require("framer-motion"),reactHotkeysHook=require("react-hotkeys-hook"),dom=require("@floating-ui/dom"),reactDom=require("@floating-ui/react-dom"),ReactDOM=require("react-dom"),reactWrapBalancer=require("react-wrap-balancer"),reResizable=require("re-resizable");function _interopNamespaceDefault(o){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const a in o)if(a!=="default"){const l=Object.getOwnPropertyDescriptor(o,a);Object.defineProperty(n,a,l.get?l:{enumerable:!0,get:()=>o[a]})}}return n.default=o,Object.freeze(n)}const React__namespace=_interopNamespaceDefault(React),ICON_CLASS="h-3 w-3 stroke-[2]",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.BoxModelIcon,{className:ICON_CLASS})},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 r;return(o==null?void 0:o.contentDocument)||((r=o==null?void 0:o.contentWindow)==null?void 0:r.document)},[o]),a=React.useCallback(r=>{if(n)if(lastHighlighted&&lastHighlighted.removeAttribute("data-highlighted"),typeof r!="string")r.setAttribute("data-highlighted","true"),lastHighlighted=r;else if(typeof r=="string"){const i=n.querySelector(`[data-block-id="${r}"]`);i&&(i.setAttribute("data-highlighted","true"),lastHighlighted=i)}else lastHighlighted=null},[n]),l=React.useCallback(()=>{lastHighlighted&&(lastHighlighted.removeAttribute("data-highlighted"),lastHighlighted=null)},[]);return{highlightBlock:a,clearHighlight:l,lastHighlighted}};function duplicateBlocks(o,n,a){const l=lodashEs.filter(o,i=>i._parent===n),r=[];for(let i=0;i<l.length;i++)if(lodashEs.filter(o,{_parent:l[i]._id}).length>0){const c=commonFunctions.generateUUID();r.push({...l[i],oldId:l[i]._id,_id:c,_parent:a}),r.push(lodashEs.flatten(duplicateBlocks(o,l[i]._id,c)))}else r.push({...l[i],oldId:l[i]._id,_id:commonFunctions.generateUUID(),_parent:a});return lodashEs.flatten(r)}function convertToBlocksTree(o){const n={};o.forEach(l=>{n[l._id]={...l,children:[]}});const a=[];return o.forEach(l=>{if(l._parent){const r=n[l._parent];r&&r.children.push(n[l._id])}else a.push(n[l._id])}),a}const getDuplicatedBlocks=(o,n,a=null)=>{let l=lodashEs.find(o,{_id:n});l={...l,oldId:l._id,_id:commonFunctions.generateUUID()},a!==(l==null?void 0:l._parent)&&(l={...l,_parent:a});const r=[l];return lodashEs.filter(o,{_parent:n}).length>0&&r.push(lodashEs.flatten(duplicateBlocks(o,n,l._id))),lodashEs.flatten(r)},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 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:l})=>lodashEs.includes(a,l)),l=>({...l}))});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),l=>lodashEs.includes(a,l._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 l=n;const r=[n];do{const i=a.find(({_id:c})=>c===(l==null?void 0:l._parent));l=i,i&&r.push(i)}while(l!=null&&l._parent);return r}),useSelectedBlockHierarchy=()=>lodashEs.compact(jotai.useAtomValue(selectedBlockHierarchy)),useSelectedBlockIds=()=>{const[o,n]=jotai.useAtom(selectedBlockIdsAtom),a=React.useCallback(l=>{n(r=>lodashEs.includes(r,l)?lodashEs.without(r,l):[...r,l])},[n]);return[o,n,a]},Breadcrumb=()=>{const o=useSelectedBlockHierarchy(),[,n]=useSelectedBlockIds(),{highlightBlock:a}=useBlockHighlight();return jsxRuntime.jsx("div",{className:"-mx-2 border-t border-border bg-background px-2 py-1 text-xs text-muted-foreground",children:jsxRuntime.jsxs("ol",{className:"flex items-center whitespace-nowrap",children:[jsxRuntime.jsxs("li",{className:"inline-flex items-center",children:[jsxRuntime.jsx(toggle.Button,{onClick:()=>n([]),variant:"ghost",className:"h-fit p-1 text-xs font-normal",children:"Body"}),jsxRuntime.jsx(lucideReact.ChevronRight,{className:"rtl:rotate-180",size:16})]}),lodashEs.reverse(o).map((l,r)=>jsxRuntime.jsxs("li",{className:"inline-flex items-center",children:[jsxRuntime.jsxs(toggle.Button,{onMouseEnter:()=>{a(l==null?void 0:l._id)},onClick:()=>n([l==null?void 0:l._id]),variant:"ghost",className:"h-fit gap-x-1 p-1 text-xs font-normal",children:[jsxRuntime.jsx(TypeIcon,{type:l==null?void 0:l._type}),l._name||l._type]}),r!==o.length-1&&jsxRuntime.jsx(lucideReact.ChevronRight,{className:"rtl:rotate-180",size:16})]},r))]})})},CHAI_BUILDER_EVENTS={OPEN_ADD_BLOCK:"OPEN_ADD_BLOCK",CLOSE_ADD_BLOCK:"CLOSE_ADD_BLOCK",SHOW_BLOCK_SETTINGS:"SHOW_BLOCK_SETTINGS",CLEAR_CANVAS_SELECTION:"CLEAR_CANVAS_SELECTION",CANVAS_BLOCK_SELECTED:"CANVAS_BLOCK_SELECTED",CANVAS_BLOCK_STYLE_SELECTED:"CANVAS_BLOCK_STYLE_SELECTED"},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 l=lodashEs.get(n,"data._type",""),r=lodashEs.get(a,"data._type","");return canAcceptChildBlock(r,l)};class PubSub{constructor(){H(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 l=this.subscribers.get(n);l&&(l.delete(a),l.size===0&&this.subscribers.delete(n))}}publish(n,a){const l=this.subscribers.get(n);l&&l.forEach(r=>r(a))}}const pubsub=new PubSub,AddBlockDropdown=({block:o,children:n})=>{const{t:a}=reactI18next.useTranslation(),[l]=useBlocksStore(),{hasPermission:r}=usePermissions(),i=lodashEs.get(o,"_id"),c=lodashEs.get(o,"_parent"),d=lodashEs.filter(l,g=>c?lodashEs.get(g,"_parent")===c:!lodashEs.get(g,"_parent")),m=canAddChildBlock(lodashEs.get(o,"_type","")),u=lodashEs.findIndex(d,{_id:i}),p=g=>{if(g==="CHILD")pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,o);else{const x={_id:c||"",position:d==null?void 0:d.length};g==="BEFORE"?x.position=Math.max(u,0):g==="AFTER"&&(x.position=u+1),pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,x)}};return r(PERMISSIONS.ADD_BLOCK)?jsxRuntime.jsxs(toggle.DropdownMenu,{children:[jsxRuntime.jsx(toggle.DropdownMenuTrigger,{children:n}),jsxRuntime.jsxs(toggle.DropdownMenuContent,{className:"border border-blue-500 bg-primary text-white shadow-2xl",children:[m&&jsxRuntime.jsx(toggle.DropdownMenuItem,{className:"cursor-pointer text-xs",onClick:()=>p("CHILD"),children:a("Add inside")}),jsxRuntime.jsx(toggle.DropdownMenuItem,{className:"cursor-pointer text-xs",onClick:()=>p("BEFORE"),children:a("Add before")}),jsxRuntime.jsx(toggle.DropdownMenuItem,{className:"cursor-pointer text-xs",onClick:()=>p("AFTER"),children:a("Add after")})]})]}):null},draggedBlockAtom=jotai.atom(null);jotai.atom(null);function getOrientation(o,n=null){const a=window.getComputedStyle(o),l=n?window.getComputedStyle(n):null,r=a.display,i=l?l.display:null;if(r==="flex"||r==="inline-flex"){const c=a.flexDirection;return c==="column"||c==="column-reverse"?"vertical":"horizontal"}else if(r==="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(i==="inline-block"||i==="inline")return"horizontal";return"vertical"}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;function insertBlocksAtPosition(o,n,a,l){const r=[...n];let i=[...o];if(a){const u=o.find(p=>p._id===a);if(u&&u.content!==void 0&&u.content!==""&&!o.some(g=>g._parent===a)){const x={_id:commonFunctions.generateUUID(),_parent:a,_type:"Text",content:u.content};Object.keys(u).forEach(f=>{f.startsWith("content-")&&(x[f]=u[f])}),r.unshift(x),i=i.map(f=>{if(f._id===a){const h={...f,content:""};return Object.keys(h).forEach(j=>{j.startsWith("content-")&&(h[j]="")}),h}return f})}}let c=i.filter(u=>!u._parent);a&&(c=i.filter(u=>u._parent===a));const d=!isNaN(l)||l>-1?Math.min(l,c.length):c.length;let m=i.length;for(let u=0,p=0;u<i.length;u++)if(a!==void 0?i[u]._parent===a:!i[u]._parent){if(p===d){m=u;break}p++}return!a&&l!==void 0&&l>=c.length&&(m=i.length),[...i.slice(0,m),...r,...i.slice(m)]}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,l){var u,p;const r=findNodeById(o,n),i=findNodeById(o,a);if(!r||!i)return!1;i.children||(i.model.children=[]);let c=(u=i==null?void 0:i.children)==null?void 0:u.findIndex(g=>g.model._id===n);r.drop(),c=Math.max(c,0);const m=(((p=r==null?void 0:r.model)==null?void 0:p._parent)||"root")===a&&c<=l?l-1:l;try{i.addChildAtIndex(r,m)}catch(g){return console.error("Error adding child to parent:",g),!1}return!0}function handleOldParentTextBlock(o,n){if(!n||!n._parent)return o;const a=n._parent,l=o.find(i=>i._id===a);if(!l)return o;const r=o.filter(i=>i._parent===a);if(r.length===2){const i=r.find(c=>c._id!==n._id);if(i&&i._type==="Text"&&"content"in l)return o.map(d=>{if(d._id===a){const m={...d,content:i.content};return Object.keys(i).forEach(u=>{u.startsWith("content-")&&(m[u]=i[u])}),m}return d}).filter(d=>d._id!==i._id)}return o}function handleNewParentTextBlock(o,n,a){if(!a||a==="root")return o;const l=o.find(r=>r._id===a);if(!l)return o;if(l.content!==void 0&&l.content!==""&&!o.some(i=>i._parent===a&&i._id!==n._id)){const c={_id:commonFunctions.generateUUID(),_parent:a,_type:"Text",content:l.content};Object.keys(l).forEach(u=>{u.startsWith("content-")&&(c[u]=l[u])});const d=o.map(u=>{if(u._id===a){const p={...u,content:""};return Object.keys(p).forEach(g=>{g.startsWith("content-")&&(p[g]="")}),p}return u}),m=d.findIndex(u=>u._id===n._id);return m!==-1?[...d.slice(0,m),c,...d.slice(m)]:[c,...d]}return o}function moveBlocksWithChildren(o,n,a,l){if(!n)return o;const r=o.find(u=>u._id===n);if(!r)return o;let i=handleOldParentTextBlock(o,r);const c=a||"root",m=new TreeModel().parse({_id:"root",children:getBlocksTree(i)});if(moveNode(m,n,c,l)){let u=flattenTree(m);const p=u.find(g=>g._id===n);return p&&(p._parent=c==="root"?null:c),u.shift(),a&&(u=handleNewParentTextBlock(u,r,a)),u}return i}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=l=>{console.log("error",l)},broadcastChannel.onmessage=l=>{l.data.type==="blocks-updated"&&l.data.pageId===n&&o(l.data.blocks),l.data.type==="blocks-props-updated"&&l.data.pageId===n&&a(l.data.blocks)},()=>{broadcastChannel.onmessage=null,broadcastChannel.onmessageerror=null}),[o,n])},removeNestedBlocks=(o,n)=>{let a=[...o],l=[];n.forEach(d=>{const m=a.find(g=>g._id===d);if(!m||!m._parent)return;const u=m._parent,p=a.filter(g=>g._parent===u);if(p.length===2){const g=p.find(x=>x._id!==d);if(g&&g._type==="Text"){const x=a.find(f=>f._id===u);x&&"content"in x&&(a=a.map(f=>{if(f._id===u){const h={...f,content:g.content};return Object.keys(g).forEach(j=>{j.startsWith("content-")&&(h[j]=g[j])}),h}return f}),l.push(g._id))}}});const r=[...n,...l],i=[],c=lodashEs.filter(a,d=>lodashEs.includes(r,d._id)||lodashEs.includes(r,d._parent)?(i.push(d._id),!1):!0);return lodashEs.isEmpty(i)?c:removeNestedBlocks(c,i)},useRemoveBlocks=()=>{const[o]=useBlocksStore(),[n,a]=useSelectedBlockIds(),{setNewBlocks:l}=useBlocksStoreUndoableActions(),{hasPermission:r}=usePermissions();return React.useCallback(i=>{var d;if(!r(PERMISSIONS.DELETE_BLOCK))return;const c=((d=lodashEs.find(o,{_id:i[0]}))==null?void 0:d._parent)||null;l(removeNestedBlocks(o,i)),setTimeout(()=>a(c?[c]:[]),200)},[o,a,n,r])},builderStore=jotai.getDefaultStore(),writeAtomValue=jotai.atom(null,(o,n,{id:a,props:l})=>{const r=o(pageBlocksAtomsAtom),i=lodashEs.find(r,c=>o(c)._id===a);return i?n(i,{...o(i),...l}):null}),useUpdateBlockAtom=()=>jotai.useSetAtom(writeAtomValue),useGetBlockAtom=o=>utils.useAtomCallback(React.useCallback((n,a,l)=>{const r=n(o);if(!r||!r.length)return console.warn("No blocks available in splitAtoms"),null;const i=lodashEs.find(r,c=>n(c)._id===(lodashEs.isString(l)?l:n(l)._id));return i||(console.warn(`Block with id ${l} not found`),null)},[o]),{store:builderStore}),useBlocksStoreManager=()=>{const[,o]=useBlocksStore(),{postMessage:n}=useBroadcastChannel(),a=useUpdateBlockAtom();return{setNewBlocks:l=>{o(l),n({type:"blocks-updated",blocks:l})},addBlocks:(l,r,i)=>{o(c=>{const d=insertBlocksAtPosition(c,l,r,i);return n({type:"blocks-updated",blocks:d}),d})},removeBlocks:l=>{o(r=>{const i=removeNestedBlocks(r,l);return n({type:"blocks-updated",blocks:i}),i})},moveBlocks:(l,r,i)=>{o(c=>{let d=[...c];for(let m=0;m<l.length;m++)d=moveBlocksWithChildren(d,l[m],r,i);return lodashEs.each(l,m=>{const u=lodashEs.find(d,p=>p._id===m);u&&a({id:m,props:{_parent:u._parent||null}})}),n({type:"blocks-updated",blocks:d}),d})},updateBlocksProps:l=>{l.forEach(r=>{const i=lodashEs.omit(r,"_id");a({id:r._id,props:i})}),n({type:"blocks-props-updated",blocks:l})}}},blockRepeaterDataAtom=jotai.atom({});blockRepeaterDataAtom.debugLabel="blockRepeaterDataAtom";const useBlockRepeaterDataAtom=()=>jotai.useAtom(blockRepeaterDataAtom),useAsyncProps=(o,n,a,l)=>{const[r,i]=React.useState({status:"idle",props:{},error:void 0}),c=useUpdateBlocksPropsRealtime(),d=useBuilderProp("getBlockAsyncProps",async f=>({})),m=jotai.useSetAtom(blockRepeaterDataAtom),u=JSON.stringify([o==null?void 0:o._id,...lodashEs.values(lodashEs.pick(o,a??[]))]),p=(o==null?void 0:o._type)==="Repeater"&&lodashEs.startsWith(o.repeaterItems,`{{${applyBinding.COLLECTION_PREFIX}`),g=(o==null?void 0:o._type)!=="Repeater"&&n==="live";return React.useEffect(()=>{if(n==="mock"){if(lodashEs.isFunction(l)){i(h=>({...h,status:"loading",props:{}}));const f=l({block:o});if(!utils$1.isObject(f))throw new Error("mockDataProvider should return an object");i(h=>({...h,status:"loaded",props:f}))}return}n==="live"&&(!p&&!g||(i(f=>({...f,status:"loading",props:{}})),d({block:o}).then((f={})=>{p?(m(h=>({...h,[o._id]:{status:"loaded",props:lodashEs.get(f,"items",[]),repeaterItems:o.repeaterItems}})),i(h=>({...h,status:"loaded",props:{totalItems:lodashEs.get(f,"totalItems")}})),c([o._id],{totalItems:lodashEs.get(f,"totalItems")})):i(h=>({...h,status:"loaded",props:utils$1.isObject(f)?f:{}}))}).catch(f=>{p?(m(h=>({...h,[o._id]:{status:"error",error:f,props:[]}})),i(h=>({...h,status:"error",error:f,props:{}}))):i(h=>({...h,status:"error",error:f,props:{}}))})))},[o==null?void 0:o._id,u,p,g,l,n]),{$loading:lodashEs.get(r,"status")==="loading",...o?lodashEs.get(r,"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 usePageExternalData=()=>{const[o]=useBlockRepeaterDataAtom(),n=React.useMemo(()=>{const l={};return Object.entries(o).forEach(([r,i])=>{i.status==="loaded"&&(l[i.repeaterItems.replace("}}",`/${r}`).replace("{{","")]=i.props)}),l},[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(l=>lodashEs.get(a[l],"builderProp",!1)||lodashEs.get(a[l],"runtime",!1)?l:null))}),useGetPageData=()=>{const[o]=useBrandingOptions(),{currentPage:n}=useCurrentPage(),[a]=useBlocksStore();return React.useCallback(()=>{const l=lodashEs.map(a,r=>lodashEs.omit(r,getBlockBuilderProps(r._type)));return{currentPage:n,blocks:l}},[o,n,a])},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,[l,r])=>({...a,[l.replace("font-","")]:r}),n.fontFamily)),n.borderRadius=o.borderRadius,o.colors&&(n.colors=o.colors.reduce((a,l)=>(Object.entries(l.items).forEach(([r,i])=>{a[r]=i}),a),n.colors)),n},chaiThemeValuesAtom=jotai.atom({}),useTheme=()=>{const o=useThemeOptions(),n=React.useMemo(()=>getDefaultThemeValues(o),[o]),a=useBuilderProp("theme",{}),[l,r]=jotai.useAtom(chaiThemeValuesAtom);return[React.useMemo(()=>({...n,...!lodashEs.isEmpty(a)&&a,...!lodashEs.isEmpty(l)&&l}),[n,a,l]),r]},useThemeOptions=()=>{const o=useBuilderProp("themeOptions",a=>a);return React.useMemo(()=>o(plugin.defaultThemeOptions),[o])},rightPanelAtom=jotai.atom("block"),useRightPanel=()=>jotai.useAtom(rightPanelAtom),languageAtom=jotai.atom("");languageAtom.debugLabel="selectedLanguageAtom";const useLanguages=()=>{const o=useBuilderProp("languages",[]),n=useBuilderProp("fallbackLang","en"),[a,l]=jotai.useAtom(languageAtom),r=i=>{l(n===i?"":i)};return{languages:o==null?void 0:o.filter(i=>i!==n),fallbackLang:n,selectedLang:a,setSelectedLang:r}},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 l=runtime.getRegisteredChaiBlock(a._type);return l?(lodashEs.has(l,"i18nProps")?l.i18nProps:[]).some(i=>{const c=`${i}-${n}`;return!a[c]||lodashEs.isEmpty(a[c])}):!1}catch(l){return console.warn(`Failed to get block definition for type: ${a._type}`,l),!1}}):!1,useSavePage=()=>{const[o,n]=jotai.useAtom(builderSaveStateAtom),a=useBuilderProp("onSave",async x=>{}),l=useBuilderProp("onSaveStateChange",lodashEs.noop),r=useGetPageData(),[i]=useTheme(),{hasPermission:c}=usePermissions(),{selectedLang:d,fallbackLang:m}=useLanguages(),u=()=>{const x=r();return!d||d===m?!1:checkMissingTranslations(x.blocks||[],d)};return{savePage:web.useThrottledCallback(async(x=!1)=>{if(!c("save_page"))return;n("SAVING"),l("SAVING");const f=r();return await a({autoSave:x,blocks:f.blocks,theme:i,needTranslations:u()}),setTimeout(()=>{n("SAVED"),l("SAVED")},100),!0},[r,n,i,a,l],3e3),savePageAsync:async()=>{if(!c("save_page"))return;n("SAVING"),l("SAVING");const x=r();return await a({autoSave:!0,blocks:x.blocks,theme:i,needTranslations:u()}),setTimeout(()=>{n("SAVED"),l("SAVED")},100),!0},saveState:o,setSaveState:n,needTranslations:u}},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),l=useBuilderProp("onSaveStateChange",lodashEs.noop),r=React.useCallback(()=>{const u={canUndo:undoManager.hasUndo(),canRedo:undoManager.hasRedo()};a(u),o("UNSAVED"),l("UNSAVED")},[a,o,l]);React.useEffect(()=>(undoManager.setCallback(r),()=>{undoManager.setCallback(lodashEs.noop)}),[r]);const i=React.useCallback(u=>{undoManager.add(u),r()},[r]),c=React.useCallback(()=>{undoManager.undo(),r()},[r]),d=React.useCallback(()=>{undoManager.redo(),r()},[r]),m=React.useCallback(()=>{undoManager.clear(),a({canUndo:!1,canRedo:!1})},[a]);return React.useMemo(()=>({add:i,undo:c,redo:d,hasUndo:()=>n.canUndo,hasRedo:()=>n.canRedo,clear:m}),[i,c,d,n.canUndo,n.canRedo,m])},useBlocksStore=()=>jotai.useAtom(presentBlocksAtom),useBlocksStoreUndoableActions=()=>{const{add:o}=useUndoManager(),[n]=useBlocksStore(),{setNewBlocks:a,addBlocks:l,removeBlocks:r,moveBlocks:i,updateBlocksProps:c}=useBlocksStoreManager();return{moveBlocks:(h,j,b)=>{const C=lodashEs.map(h,w=>{const S=n.find(A=>A._id===w)._parent||null,E=n.filter(A=>S?A._parent===S:!A._parent).map(A=>A._id).indexOf(w);return{_id:w,oldParent:S,oldPosition:E}}),B=C.find(({_id:w})=>w===h[0]);B&&B.oldParent===j&&B.oldPosition===b||(i(h,j,b),o({undo:()=>lodashEs.each(C,({_id:w,oldParent:_,oldPosition:S})=>{i([w],_,S)}),redo:()=>i(h,j,b)}))},addBlocks:(h,j,b)=>{l(h,j,b),o({undo:()=>r(lodashEs.map(h,"_id")),redo:()=>l(h,j,b)})},removeBlocks:h=>{var B;const j=(B=lodashEs.first(h))==null?void 0:B._parent,C=n.filter(w=>j?w._parent===j:!w._parent).indexOf(lodashEs.first(h));r(lodashEs.map(h,"_id")),o({undo:()=>l(h,j,C),redo:()=>r(lodashEs.map(h,"_id"))})},updateBlocks:(h,j,b)=>{let C=[];if(b)C=lodashEs.map(h,B=>({_id:B,...b}));else{const B=lodashEs.keys(j);C=lodashEs.map(h,w=>{const _=n.find(y=>y._id===w),S={_id:w};return lodashEs.each(B,y=>S[y]=_[y]),S})}c(lodashEs.map(h,B=>({_id:B,...j}))),o({undo:()=>c(C),redo:()=>c(lodashEs.map(h,B=>({_id:B,...j})))})},updateBlocksRuntime:(h,j)=>{c(lodashEs.map(h,b=>({_id:b,...j})))},setNewBlocks:h=>{a(h),o({undo:()=>a(n),redo:()=>a(h)})},updateMultipleBlocksProps:h=>{let j=[];j=lodashEs.map(h,b=>{const C=lodashEs.keys(b),B=n.find(_=>_._id===b._id),w={};return lodashEs.each(C,_=>w[_]=B[_]),w}),c(h),o({undo:()=>c(j),redo:()=>c(h)})}}},useAddBlock=()=>{const[o]=useBlocksStore(),[,n]=useSelectedBlockIds(),{addBlocks:a}=useBlocksStoreUndoableActions(),l=React.useCallback((i,c,d)=>{var x;for(let f=0;f<i.length;f++){const{_id:h}=i[f];i[f]._id=commonFunctions.generateUUID();const j=lodashEs.filter(i,{_parent:h});for(let b=0;b<j.length;b++)j[b]._parent=i[f]._id}const m=lodashEs.first(i);let u,p;return c&&(u=lodashEs.find(o,{_id:c}),i[0]._parent=c,p=c),!(u?canAcceptChildBlock(u==null?void 0:u._type,m._type):!0)&&u&&(i[0]._parent=u._parent,p=u._parent),a(i,p,d),n([(x=lodashEs.first(i))==null?void 0:x._id]),lodashEs.first(i)},[a,o,n]);return{addCoreBlock:React.useCallback((i,c,d)=>{if(lodashEs.has(i,"blocks")){const j=i.blocks;return l(j,c,d)}const m=commonFunctions.generateUUID(),u=runtime.getDefaultBlockProps(i.type),p={_type:i.type,_id:m,...u,...lodashEs.has(i,"_name")&&{_name:i._name},...lodashEs.has(i,"partialBlockId")&&{partialBlockId:i.partialBlockId}};let g,x;return c&&(g=lodashEs.find(o,{_id:c}),p._parent=c,x=c),!canAcceptChildBlock(g==null?void 0:g._type,p._type)&&g&&(p._parent=g._parent,x=g._parent),a([p],x,d),n([p._id]),p},[a,l,o,n]),addPredefinedBlock:l}},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 l=lodashEs.flattenDeep(lodashEs.map(o.colors,({items:r})=>lodashEs.keys(r)));a=lodashEs.flattenDeep(lodashEs.map(l,r=>lodashEs.flatten(lodashEs.map(colorKeys,i=>`${i}-${r}`))))}return o.fontFamily&&(a=[...a,...lodashEs.map(lodashEs.keys(o.fontFamily),l=>`${l}`)]),lodashEs.map(a,l=>({name:l}))},[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 r=lodashEs.flattenDeep(lodashEs.map(o.colors,({items:i})=>lodashEs.keys(i)));lodashEs.each(CLASSES_LIST,(i,c)=>{lodashEs.set(CLASSES_LIST,`${c}.regExp`,i.regExp.replace("__THEME_COLORS_REGEXP__",r.join("|")))})}return CLASSES_LIST},[o]),a=React.useCallback((r,i)=>{const c=lodashEs.get(n,`${r}.regExp`,"");return i.match(new RegExp(c))},[n]),l=React.useCallback((r,i=[])=>lodashEs.get(n,`${r}.classes`,i),[n]);return{match:a,getClasses:l}};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,l=>`${l}:`).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 l=lodashEs.get(CLASSES_LIST,`${a}.regExp`,"");if(new RegExp(l,"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((l,r)=>a.indexOf(l.mq)-a.indexOf(r.mq)).map(l=>l.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 l=o;if(a.length===1)return a[0].fullCls;for(const r of a){const i=r.property,c=n.indexOf(r.mq);for(let d=c+1;d<n.length;d++){const m=n[d],u=a.find(p=>p.property===i&&p.mq===m);if(u&&u.cls===r.cls)l=l.replace(u.fullCls,"");else if(u&&u.cls!==r.cls)break}}return l.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:l})=>{const r=lodashEs.filter(o(pageBlocksAtomsAtom),c=>a.includes(o(c)._id)),i=lodashEs.first(o(selectedStylingBlocksAtom));return lodashEs.map(r,c=>{const d=o(c),m=lodashEs.get(d,i.prop,`${applyBinding.STYLES_KEY},`),{classes:u}=applyBinding.getSplitChaiClasses(m);return{ids:[d._id],props:{[i.prop]:`${applyBinding.STYLES_KEY},${orderClassesByBreakpoint(removeDuplicateClasses(tailwindMerge.twMerge(u,l)))}`}}})}),useAddClassesToBlocks=()=>{const o=jotai.useSetAtom(addClassesToBlocksAtom),{updateBlocks:n,updateBlocksRuntime:a}=useBlocksStoreUndoableActions();return React.useCallback((l,r,i=!1)=>{const c=o({blockIds:l,newClasses:r});if(!i){a(l,c[0].props);return}n(l,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 l=runtime.getRegisteredChaiBlock(lodashEs.get(a,"_type"));if(!l)return o;const r={...o};return lodashEs.forEach(lodashEs.keys(o),i=>{if(lodashEs.includes(lodashEs.get(l,"i18nProps",[]),i)&&!lodashEs.isEmpty(n)){const c=`${i}-${n}`;lodashEs.set(r,c,o[i]),lodashEs.unset(r,i)}}),r},useUpdateBlocksProps=()=>{const{updateBlocks:o}=useBlocksStoreUndoableActions(),{selectedLang:n}=useLanguages(),a=useSelectedBlock();return React.useCallback((l,r,i)=>{const c=updatePropsForLanguage(r,n,a);o(l,c,i)},[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,l=30)=>{const r=lodashEs.keys(lodashEs.omit(a,["_id"]));for(const i of r){const c=a[i];if(lodashEs.isString(c)){const d=lodashEs.chunk(c.split(""),12);let m="";o([n],{[i]:""});for(let u=0;u<d.length;u++)m+=d[u].join(""),o([n],{[i]:m}),await new Promise(p=>setTimeout(p,l))}}},[o])},useStreamMultipleBlocksProps=()=>{const{updateMultipleBlocksProps:o}=useBlocksStoreUndoableActions(),n=useFakeStreamEffect();return React.useCallback(async a=>{for(const l of a)await n(l._id,l);o(a)},[n,o])},useUpdateBlocksPropsRealtime=()=>{const{updateBlocksRuntime:o}=useBlocksStoreUndoableActions(),{selectedLang:n}=useLanguages(),a=useSelectedBlock();return React.useCallback((l,r)=>{const i=updatePropsForLanguage(r,n,a);o(l,i)},[n,a,o])};function getChildBlocks(o,n,a){a.push(lodashEs.find(o,{_id:n}));const l=lodashEs.filter(o,{_parent:n});for(const r of l)a.push(...getBlockWithChildren(r._id,o));return a}const getBlockWithChildren=(o,n)=>{let a=[];return a=lodashEs.flattenDeep([...a,...getChildBlocks(n,o,a)]),a},pickOnlyAIProps=(o,n)=>lodashEs.compact(o.map(a=>{const l=["_id","_type","_parent"],r=lodashEs.pick(a,l),i=runtime.getRegisteredChaiBlock(a._type),c={},d=lodashEs.get(i,"aiProps",[]);for(const m in a)l.includes(m)||d.includes(m)&&(c[m]=lodashEs.get(a,`${m}-${n}`,a[m]));return lodashEs.isEmpty(c)?!1:(lodashEs.has(r,"_parent")&&lodashEs.isEmpty(r._parent)&&delete r._parent,{...r,...c})})),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,l]=React.useState(null),r=useBuilderProp("askAiCallBack",null),i=useStreamMultipleBlocksProps(),c=useUpdateMultipleBlocksProps(),[d]=useBlocksStore(),{selectedLang:m,fallbackLang:u}=useLanguages(),p=m.length?m:u,g=(x,f)=>{const h=lodashEs.cloneDeep(f.find(j=>j._id===x));for(const j in h){const b=h[j];if(typeof b=="string"&&lodashEs.startsWith(b,applyBinding.STYLES_KEY)){const{baseClasses:C,classes:B}=applyBinding.getSplitChaiClasses(b);h[j]=lodashEs.compact(lodashEs.flattenDeep([C,B])).join(" ")}else j!=="_id"&&delete h[j]}return h};return{askAi:React.useCallback(async(x,f,h,j)=>{if(r){n(!0),l(null);try{const b=m===u?"":m,C=x==="content"?pickOnlyAIProps(lodashEs.cloneDeep(getBlockWithChildren(f,d)),m):[g(f,d)],B=await r(x,addLangToPrompt(h,p,x),C,b),{blocks:w,error:_}=B;if(_){l(_);return}if(x==="styles"){const S=w.map(y=>{for(const E in y)E!=="_id"&&(y[E]=`${applyBinding.STYLES_KEY},${y[E]}`);return y});c(S)}else i(w);j&&j(B)}catch(b){l(b)}finally{n(!1),j&&j()}}},[r,n,m,u,d,p,c,i]),loading:o,error:a}},useAiAssistant=()=>{const[,o]=useRightPanel();return React.useCallback(n=>{o(n?"ai":"block")},[o])},partialBlocksStoreAtom=jotai.atom({}),partialBlocksLoadingStateAtom=jotai.atom({}),usePartialBlocksStore=()=>{const[o,n]=jotai.useAtom(partialBlocksStoreAtom),a=React.useCallback(r=>lodashEs.get(o,r,[]),[o]),l=React.useCallback(()=>n({}),[n]);return{getPartailBlocks:a,reset:l}},useWatchPartailBlocks=()=>{const[o]=useBlocksStore(),[n,a]=jotai.useAtom(partialBlocksStoreAtom),[l,r]=jotai.useAtom(partialBlocksLoadingStateAtom),i=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(l,`${d}.loading`,!1)||(r(m=>({...m,[d]:{loading:!0,error:null}})),i(d).then(m=>{a(u=>({...u,[d]:m})),r(u=>({...u,[d]:{loading:!1,error:null}}))}).catch(m=>{r(u=>({...u,[d]:{loading:!1,error:m.message}}))}))})},[i,n,l,a,r,c])},partialBlocksListAtom=jotai.atom({}),usePartialBlocksList=()=>{const[o,n]=React.useState(!1),[a,l]=React.useState(null),[r,i]=jotai.useAtom(partialBlocksListAtom),c=useBuilderProp("getPartialBlocks",async()=>[]),d=React.useCallback(async()=>{n(!0),l(null);try{const m=await c();i(m),n(!1)}catch(m){l(m instanceof Error?m.message:"Failed to fetch partial blocks"),n(!1)}},[c,i]);return React.useEffect(()=>{d()},[]),{data:r,isLoading:o,refetch:d,error:a}},useBuilderReset=()=>{const{clear:o}=useUndoManager(),[,n]=useSelectedBlockIds(),{clearHighlight:a}=useBlockHighlight(),[,l]=useSelectedStylingBlocks(),[,r]=jotai.useAtom(aiAssistantActiveAtom),{reset:i}=usePartialBlocksStore(),{setSaveState:c}=useSavePage(),[,d]=useBlockRepeaterDataAtom();return()=>{d({}),n([]),l([]),a(),o(),r(!1),i(),c("SAVED")}},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),l=React.useCallback(r=>{n(r),a([])},[n,a]);return[o,l]},copiedBlockIdsAtom=jotai.atom([]),useCopyBlocks=()=>{const[o]=useBlocksStore(),[n,a]=jotai.useAtom(copiedBlockIdsAtom),l=jotai.useSetAtom(cutBlockIdsAtom),{getPartailBlocks:r}=usePartialBlocksStore(),i=React.useCallback(d=>d.some(m=>getDuplicatedBlocks(o,m,null).some(p=>p._type==="PartialBlock"||p._type==="GlobalBlock")),[o]),c=React.useCallback(async(d,m=!1)=>{try{if(lodashEs.isEmpty(d))return;a(d),l([]);const u={_chai_copied_blocks:d.flatMap(p=>{const g=getDuplicatedBlocks(o,p,null);if(!m)return g;let x=[];for(const f of g)if(f._type==="PartialBlock"||f._type==="GlobalBlock"){let h=r(f.partialBlockId);f._parent&&(h==null?void 0:h.length)>0&&(h=h.map(j=>(lodashEs.isEmpty(j._parent)&&lodashEs.set(j,"_parent",f._parent),j))),x=[...x,...h]}else x.push(f);return x})};if(!navigator.clipboard){sonner.toast.error("Clipboard not available.");return}sonner.toast.promise(navigator.clipboard.writeText(JSON.stringify(u)),{success:"Blocks copied successfully",error:"Failed to copy blocks to clipboard"})}catch(u){sonner.toast.error("Failed to copy blocks to clipboard"),console.error("Failed to copy blocks to clipboard:",u)}},[a,l,o]);return[n,c,i]},useCopyToClipboard=()=>{const[o,n]=React.useState(null),a=React.useCallback(async l=>{if(!(navigator!=null&&navigator.clipboard))return console.warn("Clipboard not supported"),!1;try{return await navigator.clipboard.writeText(l),n(l),!0}catch(r){return console.warn("Copy failed",r),n(null),!1}},[]);return[o,a]},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((l,r=null)=>{const i=[];lodashEs.each(l,c=>{const d=o.find(x=>x._id===c);r?r==="root"&&(r=null):r=d._parent;const p=lodashEs.filter(o,x=>lodashEs.isString(r)?x._parent===r:!x._parent).indexOf(d)+1,g=getDuplicatedBlocks(o,c,r);a(g,r,p),i.push(lodashEs.get(g,"0._id",""))}),n(i)},[o,n])},hiddenBlockIdsAtom=jotai.atom([]),useHiddenBlockIds=()=>{const[o,n]=jotai.useAtom(hiddenBlockIdsAtom),a=React.useCallback(l=>{n(r=>lodashEs.includes(r,l)?lodashEs.without(r,l):[...r,l])},[n]);return[o,n,a]},highlightBlockIdAtom=jotai.atom(""),useHighlightBlockId=()=>jotai.useAtom(highlightBlockIdAtom),libraryBlocksAtom=jotai.atom({}),useLibraryBlocks=o=>{const[n,a]=jotai.useAtom(libraryBlocksAtom),l=React.useMemo(()=>(o==null?void 0:o.getBlocksList)||(()=>[]),[o]),r=lodashEs.get(n,`${o==null?void 0:o.id}.blocks`,null),i=lodashEs.get(n,`${o==null?void 0:o.id}.loading`,"idle"),c=React.useRef("idle");React.useEffect(()=>{(async()=>{if(!(i==="complete"||c.current==="loading")){c.current="loading",a(m=>({...m,[o==null?void 0:o.id]:{loading:"loading",blocks:[]}}));try{const m=await l(o);c.current="idle",a(u=>({...u,[o==null?void 0:o.id]:{loading:"complete",blocks:m||[]}}))}catch{c.current="idle",a(u=>({...u,[o==null?void 0:o.id]:{loading:"complete",blocks:[]}}))}}})()},[o,r,i,c,a,l]);const d=React.useCallback(m=>{a(u=>({...u,[m]:{loading:"idle",blocks:[]}}))},[a]);return{data:r||[],isLoading:i==="loading",resetLibrary:d}},useCanPaste=()=>{const[o]=useBlocksStore();return(n,a)=>{var i;const l=((i=lodashEs.find(o,{_id:a}))==null?void 0:i._type)||null,r=lodashEs.first(n.map(c=>{var d;return(d=lodashEs.find(o,{_id:c}))==null?void 0:d._type}));return canAcceptChildBlock(l,r)}},useMoveCutBlocks=()=>{const o=jotai.useAtomValue(presentBlocksAtom),{moveBlocks:n}=useBlocksStoreUndoableActions();return React.useCallback((a,l)=>{const r=Array.isArray(l)?l[0]:l;if(l==="root"){const i=o==null?void 0:o.filter(c=>!c._parent);n(a,null,(i==null?void 0:i.length)||0)}else{const i=o==null?void 0:o.filter(c=>c._parent===r);n(a,r,(i==null?void 0:i.length)||0)}},[n,o])},usePasteBlocks=()=>{const[o,n]=useCutBlockIds(),a=useMoveCutBlocks(),{addPredefinedBlock:l}=useAddBlock(),r=useCanPaste();return{canPaste:React.useCallback(async c=>{if(o.length>0)return r(o,c);try{const d=await navigator.clipboard.readText();if(d){const m=JSON.parse(d);return lodashEs.has(m,"_chai_copied_blocks")}}catch{return!1}return!1},[r,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 m=await navigator.clipboard.readText();if(m){const u=JSON.parse(m);if(lodashEs.has(u,"_chai_copied_blocks"))l(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:l})=>{const r=lodashEs.first(o(selectedStylingBlocksAtom)),i=lodashEs.filter(o(pageBlocksAtomsAtom),c=>a.includes(o(c)._id));return lodashEs.map(i,c=>{const d=o(c),m=l;let{classes:u,baseClasses:p}=applyBinding.getSplitChaiClasses(lodashEs.get(d,r.prop,`${applyBinding.STYLES_KEY},`));return lodashEs.each(m,g=>{const x=g.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),f=new RegExp(`(^|\\s)${x}(?=\\s|$)`,"g");u=u.replace(f," ").replace(/\s+/g," ").trim();const h=lodashEs.first(g.split(":"));lodashEs.includes(["2xl","xl","lg","md","sm"],h)&&m.push(g.split(":").pop().trim())}),lodashEs.each(m,g=>{const x=g.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),f=new RegExp(`(^|\\s)${x}(?=\\s|$)`,"g");p=p.replace(f," ").replace(/\s+/g," ").trim()}),{ids:[d._id],props:{[r.prop]:`${applyBinding.STYLES_KEY}${p},${u}`}}})}),removeAllClassesForBlock=o=>{const n=Object.keys(o).filter(l=>typeof o[l]=="string"&&o[l].startsWith(applyBinding.STYLES_KEY)),a={};return n.forEach(l=>{a[l]=`${applyBinding.STYLES_KEY},`}),{ids:[o._id],props:a}},useRemoveAllClassesForBlock=()=>{const{updateBlocks:o,updateBlocksRuntime:n}=useBlocksStoreUndoableActions();return React.useCallback((a,l=!1)=>{const{ids:r,props:i}=removeAllClassesForBlock(a);l?o(r,i):n(r,i)},[o,n])},useRemoveClassesFromBlocks=()=>{const{updateBlocks:o,updateBlocksRuntime:n}=useBlocksStoreUndoableActions(),a=jotai.useSetAtom(removeClassFromBlocksAtom);return React.useCallback((l,r,i=!1)=>{const c=a({blockIds:l,fullClasses:r});i?o(l,c[0].props):n(l,c[0].props)},[a])},useResetBlockStyles=()=>{const o=useSelectedBlock(),n=useUpdateBlocksProps(),a=React.useCallback(c=>runtime.getDefaultBlockProps(c)||{},[]),l=React.useCallback(c=>Object.keys(c).filter(d=>typeof c[d]=="string"&&c[d].startsWith("#styles:")),[]),r=React.useCallback(c=>{if(!o)return;const m=a(o._type)[c]??"#styles:,";n([o._id],{[c]:m})},[o,a,n]);return{resetAll:React.useCallback(()=>{if(!o)return;const c=l(o);if(c.length===0)return;const d=a(o._type),m=lodashEs.pick(d,c);n([o._id],m)},[o,l,a,n]),reset:r}},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),[l,r]=useStylingBreakpoint();return React.useEffect(()=>{l!=="xs"&&r(a)},[a,l,r]),[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 l=lodashEs.get(a,n.prop,`${applyBinding.STYLES_KEY},`),{classes:r}=applyBinding.getSplitChaiClasses(l);return lodashEs.filter(lodashEs.map(r.trim().split(" "),constructClassObject),i=>!lodashEs.isNull(i))}),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),l=o(darkModeAtom),r=getQueries(n);let i=lodashEs.filter(o(selectedBlockAllClassesAtom),{mod:a});return lodashEs.startsWith(a,"_")||(i=lodashEs.filter(i,c=>r.includes(c.mq))),i=i.sort((c,d)=>MQ[c.mq]-MQ[d.mq]),l||(i=lodashEs.filter(i,{dark:!1})),i}),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),l=a.length===1?a[0]:null;if(!l)return null;const r=lodashEs.find(n,{_id:l});if(!r)return null;let i=r._parent;for(;i;){const d=lodashEs.find(n,{_id:i});if(!d)return null;if((c=runtime.getRegisteredChaiBlock(d._type))!=null&&c.wrapper)return d;i=d._parent}return null});wrapperBlockAtom.debugLabel="wrapperBlockAtom";const useWrapperBlock=()=>jotai.useAtomValue(wrapperBlockAtom),inlineEditingActiveAtom=jotai.atom("");inlineEditingActiveAtom.debugLabel="inlineEditingActiveAtom";const inlineEditingItemIndexAtom=jotai.atom(0);inlineEditingItemIndexAtom.debugLabel="inlineEditingItemIndexAtom";const useInlineEditing=()=>{const[o,n]=jotai.useAtom(inlineEditingActiveAtom),[a,l]=jotai.useAtom(inlineEditingItemIndexAtom);return{editingBlockId:o,editingItemIndex:a,setEditingBlockId:n,setEditingItemIndex:l}},useSelectedLibrary=()=>jotai.useAtom(selectedLibraryAtom),sidebarActivePanelAtom=jotai.atom("outline");sidebarActivePanelAtom.debugLabel="sidebarActivePanelAtom";const useSidebarActivePanel=()=>jotai.useAtom(sidebarActivePanelAtom),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 l=`[data-block-id='${o}']`,r=a==null?void 0:a.querySelector(l);if(r){const i=a==null?void 0:a.querySelector(`[data-block-id='${n}']`);return getOrientation(r,i).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:l}=useFrame(),{moveBlocks:r}=useBlocksStoreUndoableActions(),i=lodashEs.get(o,"_id"),c=lodashEs.get(o,"_parent"),d=lodashEs.filter(a,h=>c?lodashEs.get(h,"_parent")===c:!lodashEs.get(h,"_parent")),m=(d==null?void 0:d.length)<=1,u=lodashEs.findIndex(d,{_id:i}),p=u<=0,g=u+1===(d==null?void 0:d.length),x=getParentBlockOrientation(c,i,l),f=React.useCallback(h=>{isDisabledControl(p,g,h)||m||(h==="UP"||h==="LEFT"?r([i],c||null,u-1):(h==="DOWN"||h==="RIGHT")&&r([i],c||null,u+2),n())},[p,g,m,u,i,c,n]);return reactHotkeysHook.useHotkeys("shift+up, shift+down, shift+left, shift+right",({key:h})=>{var j;f((j=h==null?void 0:h.replace("Arrow",""))==null?void 0:j.toUpperCase())},{document:l==null?void 0:l.contentDocument},[f]),{isOnlyChild:m,isFirstBlock:p,isLastBlock:g,moveBlock:f,orientation:x}},BlockController=({block:o,updateFloatingBar:n})=>{const{isOnlyChild:a,isFirstBlock:l,isLastBlock:r,moveBlock:i,orientation:c}=useBlockController(o,n);return a?null:jsxRuntime.jsx(jsxRuntime.Fragment,{children:CONTROLS.map(({ControlIcon:d,dir:m,key:u})=>{if(c!==m)return null;const p=isDisabledControl(l,r,u);return p?null:jsxRuntime.jsx(d,{onClick:()=>i(u),className:`${p?"pointer-events-none cursor-not-allowed opacity-50":"duration-300 hover:scale-95 hover:opacity-80"}`},u)})})};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"],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"},isInlineEditable=(o,n)=>{if(isRichTextParent(o))return!0;const a=o==null?void 0:o.getAttribute("data-block-type");return!a||o&&o.children.length>0||a==="Button"?!1:INLINE_EDITABLE_BLOCKS.includes(a)},useHandleCanvasDblClick=()=>{const{editingBlockId:o,setEditingBlockId:n,setEditingItemIndex:a}=useInlineEditing();return React.useCallback(l=>{var d;if(l==null||l.preventDefault(),l==null||l.stopPropagation(),o)return;const r=getTargetedBlock(l.target);if(!isInlineEditable(r))return;const i=r.getAttribute("data-block-id");if(!i||!r)return;const c=r.closest('[data-block-type="Repeater"]');c?(d=c==null?void 0:c.childNodes)==null||d.forEach((m,u)=>{m.contains(r)&&a(u)}):a(-1),n(i)},[o,n,a])},useHandleCanvasClick=()=>{const{editingBlockId:o}=useInlineEditing(),{clearHighlight:n}=useBlockHighlight(),a=React.useRef(0);return React.useCallback(l=>{const r=new Date().getTime();if(o||(l.stopPropagation(),r-a.current<400))return;const c=getTargetedBlock(l.target);if(c!=null&&c.getAttribute("data-block-id")&&(c==null?void 0:c.getAttribute("data-block-id"))==="container"){pubsub.publish(CHAI_BUILDER_EVENTS.CLEAR_CANVAS_SELECTION);return}if(c!=null&&c.getAttribute("data-block-parent")){const d=c.getAttribute("data-style-prop"),m=c.getAttribute("data-style-id"),u=c.getAttribute("data-block-parent");pubsub.publish(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_STYLE_SELECTED,{blockId:u,styleId:m,styleProp:d})}else if(c!=null&&c.getAttribute("data-block-id")){const d=c.getAttribute("data-block-id");pubsub.publish(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_SELECTED,d==="canvas"?[]:[d])}n(),a.current=new Date().getTime()},[o])},useHandleMouseMove=()=>{const{editingBlockId:o}=useInlineEditing(),{highlightBlock:n}=useBlockHighlight();return web.useThrottledCallback(a=>{if(o)return;const l=getTargetedBlock(a.target);l&&n(l)},[o,n],100)},useHandleMouseLeave=()=>{const{clearHighlight:o}=useBlockHighlight();return React.useCallback(()=>o(),[o])},Canvas=({children:o})=>{const n=useHandleCanvasDblClick(),a=useHandleCanvasClick(),l=useHandleMouseMove(),r=useHandleMouseLeave();return jsxRuntime.jsx("div",{"data-block-id":"canvas",id:"canvas",onClick:a,onDoubleClick:n,onMouseMove:l,onMouseLeave:r,className:"relative h-full max-w-full p-px",children:o})},getElementByDataBlockId=(o,n)=>o.querySelector(`[data-block-id="${n}"]`),BlockActionLabel=({block:o,label:n})=>{const[,a]=useSelectedBlockIds(),[,l]=useHighlightBlockId(),[,r]=jotai.useAtom(draggedBlockAtom),i=flagged.useFeature("dnd");return jsxRuntime.jsxs("div",{className:"mr-10 flex cursor-default items-center space-x-1 px-1",draggable:i?"true":"false",onDragStart:c=>{c.dataTransfer.setData("text/plain",JSON.stringify(lodashEs.pick(o,["_id","_type","_name"]))),r(o),setTimeout(()=>{a([]),l(null)},200)},children:[jsxRuntime.jsx(reactIcons.DragHandleDots2Icon,{}),n]})},getElementByStyleId=(o,n)=>o.querySelector(`[data-style-id="${n}"]`),BlockSelectionHighlighter=()=>{const o=useSelectedBlock(),{document:n}=useFrame(),[a]=useSelectedStylingBlocks(),[l,r]=React.useState([]),[,i]=React.useState([]),c=(d,m=0)=>{const{top:u}=d.getBoundingClientRect();return u+m>=0&&u-m<=window.innerHeight};return React.useEffect(()=>{var d;if(o!=null&&o._id&&o.type!=="Multiple"&&n){const m=getElementByDataBlockId(n,o._id);m&&(c(m)||(d=n.defaultView)==null||d.scrollTo({top:m.offsetTop,behavior:"smooth"}),r([m]))}},[o==null?void 0:o._id,o==null?void 0:o.type,n]),React.useEffect(()=>{if(!lodashEs.isEmpty(a)&&n){const d=getElementByStyleId(n,lodashEs.first(a).id);i(d?[d]:[null])}else i([null])},[a,n]),jsxRuntime.jsx(BlockFloatingSelector,{block:o,selectedBlockElement:l[0]})},BlockFloatingSelector=({block:o,selectedBlockElement:n})=>{const a=useRemoveBlocks(),l=useDuplicateBlocks(),[,r]=useSelectedBlockIds(),[,i]=useHighlightBlockId(),[,c]=useSelectedStylingBlocks(),{hasPermission:d}=usePermissions(),{editingBlockId:m}=useInlineEditing(),{document:u}=useFrame(),{floatingStyles:p,refs:g,update:x}=reactDom.useFloating({placement:"top-start",middleware:[reactDom.shift({boundary:u==null?void 0:u.body,limiter:dom.limitShift({offset:8,mainAxis:!0,crossAxis:!0})}),dom.flip({boundary:u==null?void 0:u.body,fallbackPlacements:["bottom-start","top-end","bottom-end","inside"]}),dom.size({boundary:u==null?void 0:u.body,apply({availableWidth:j,availableHeight:b,elements:C}){Object.assign(C.floating.style,{maxWidth:`${Math.max(200,j)}px`,maxHeight:`${Math.max(100,b)}px`})}})],elements:{reference:n}});web.useResizeObserver(n,()=>x(),n!==null),web.useResizeObserver(u==null?void 0:u.body,()=>x(),(u==null?void 0:u.body)!==null);const f=lodashEs.get(o,"_parent",null),h=lodashEs.isEmpty(lodashEs.get(o,"_name",""))?lodashEs.get(o,"_type",""):lodashEs.get(o,"_name","");return React.useEffect(()=>{if(n){const j=setTimeout(()=>x(),500);return()=>clearTimeout(j)}else x()},[n]),!n||!o||m?null:jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{role:"button",tabIndex:0,ref:g.setFloating,style:p,onClick:j=>{j.stopPropagation(),j.preventDefault()},onMouseEnter:j=>{j.stopPropagation(),i(null)},onKeyDown:j=>j.stopPropagation(),className:"isolate z-[999] flex h-6 items-center bg-blue-500 py-2 text-xs text-white",children:[f&&jsxRuntime.jsx(reactIcons.ArrowUpIcon,{className:"hover:scale-105",onClick:()=>{c([]),r([f])}}),jsxRuntime.jsx(BlockActionLabel,{label:h,block:o}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 pl-1 pr-1.5",children:[jsxRuntime.jsx(AddBlockDropdown,{block:o,children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:"hover:scale-105"})}),canDuplicateBlock(lodashEs.get(o,"_type",""))&&d(PERMISSIONS.ADD_BLOCK)?jsxRuntime.jsx(reactIcons.CopyIcon,{className:"hover:scale-105",onClick:()=>l([o==null?void 0:o._id])}):null,canDeleteBlock(lodashEs.get(o,"_type",""))&&d(PERMISSIONS.DELETE_BLOCK)?jsxRuntime.jsx(reactIcons.TrashIcon,{className:"hover:scale-105",onClick:()=>a([o==null?void 0:o._id])}):null,d(PERMISSIONS.MOVE_BLOCK)&&jsxRuntime.jsx(BlockController,{block:o,updateFloatingBar:x})]})]})})},IframeInitialContent=`<!doctype html>
1
+ "use strict";var V=Object.defineProperty;var U=(o,n,a)=>n in o?V(o,n,{enumerable:!0,configurable:!0,writable:!0,value:a}):o[n]=a;var H=(o,n,a)=>U(o,typeof n!="symbol"?n+"":n,a);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const jsxRuntime=require("react/jsx-runtime"),runtime=require("@chaibuilder/runtime"),reactIcons=require("@radix-ui/react-icons"),lodashEs=require("lodash-es"),React=require("react"),jotai=require("jotai"),utils=require("jotai/utils"),commonFunctions=require("./common-functions-BZmyleS1.cjs"),toggle=require("./toggle-BgZfmuec.cjs"),lucideReact=require("lucide-react"),clsx=require("clsx"),tailwindMerge=require("tailwind-merge"),TreeModel=require("tree-model"),applyBinding=require("./apply-binding-T3HdSezj.cjs"),plugin=require("./plugin-CSgw-f78.cjs"),utils$1=require("@rjsf/utils"),web=require("@react-hookz/web"),sonner=require("sonner"),reactI18next=require("react-i18next"),Fuse=require("fuse.js"),UndoManager=require("undo-manager"),Link=require("@tiptap/extension-link"),TextAlign=require("@tiptap/extension-text-align"),Underline=require("@tiptap/extension-underline"),Placeholder=require("@tiptap/extension-placeholder"),react=require("@tiptap/react"),StarterKit=require("@tiptap/starter-kit"),RjForm=require("@rjsf/core"),validator=require("@rjsf/validator-ajv8"),Autosuggest=require("react-autosuggest"),flagged=require("flagged"),himalaya=require("himalaya"),reactArborist=require("react-arborist"),i18n=require("i18next"),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"),reactErrorBoundary=require("react-error-boundary"),framerMotion=require("framer-motion"),reactHotkeysHook=require("react-hotkeys-hook"),dom=require("@floating-ui/dom"),reactDom=require("@floating-ui/react-dom"),ReactDOM=require("react-dom"),reactWrapBalancer=require("react-wrap-balancer"),reResizable=require("re-resizable");function _interopNamespaceDefault(o){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(o){for(const a in o)if(a!=="default"){const l=Object.getOwnPropertyDescriptor(o,a);Object.defineProperty(n,a,l.get?l:{enumerable:!0,get:()=>o[a]})}}return n.default=o,Object.freeze(n)}const React__namespace=_interopNamespaceDefault(React),ICON_CLASS="h-3 w-3 stroke-[2]",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.BoxModelIcon,{className:ICON_CLASS})},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 r;return(o==null?void 0:o.contentDocument)||((r=o==null?void 0:o.contentWindow)==null?void 0:r.document)},[o]),a=React.useCallback(r=>{if(n)if(lastHighlighted&&lastHighlighted.removeAttribute("data-highlighted"),typeof r!="string")r.setAttribute("data-highlighted","true"),lastHighlighted=r;else if(typeof r=="string"){const i=n.querySelector(`[data-block-id="${r}"]`);i&&(i.setAttribute("data-highlighted","true"),lastHighlighted=i)}else lastHighlighted=null},[n]),l=React.useCallback(()=>{lastHighlighted&&(lastHighlighted.removeAttribute("data-highlighted"),lastHighlighted=null)},[]);return{highlightBlock:a,clearHighlight:l,lastHighlighted}};function duplicateBlocks(o,n,a){const l=lodashEs.filter(o,i=>i._parent===n),r=[];for(let i=0;i<l.length;i++)if(lodashEs.filter(o,{_parent:l[i]._id}).length>0){const c=commonFunctions.generateUUID();r.push({...l[i],oldId:l[i]._id,_id:c,_parent:a}),r.push(lodashEs.flatten(duplicateBlocks(o,l[i]._id,c)))}else r.push({...l[i],oldId:l[i]._id,_id:commonFunctions.generateUUID(),_parent:a});return lodashEs.flatten(r)}function convertToBlocksTree(o){const n={};o.forEach(l=>{n[l._id]={...l,children:[]}});const a=[];return o.forEach(l=>{if(l._parent){const r=n[l._parent];r&&r.children.push(n[l._id])}else a.push(n[l._id])}),a}const getDuplicatedBlocks=(o,n,a=null)=>{let l=lodashEs.find(o,{_id:n});l={...l,oldId:l._id,_id:commonFunctions.generateUUID()},a!==(l==null?void 0:l._parent)&&(l={...l,_parent:a});const r=[l];return lodashEs.filter(o,{_parent:n}).length>0&&r.push(lodashEs.flatten(duplicateBlocks(o,n,l._id))),lodashEs.flatten(r)},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 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:l})=>lodashEs.includes(a,l)),l=>({...l}))});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),l=>lodashEs.includes(a,l._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 l=n;const r=[n];do{const i=a.find(({_id:c})=>c===(l==null?void 0:l._parent));l=i,i&&r.push(i)}while(l!=null&&l._parent);return r}),useSelectedBlockHierarchy=()=>lodashEs.compact(jotai.useAtomValue(selectedBlockHierarchy)),useSelectedBlockIds=()=>{const[o,n]=jotai.useAtom(selectedBlockIdsAtom),a=React.useCallback(l=>{n(r=>lodashEs.includes(r,l)?lodashEs.without(r,l):[...r,l])},[n]);return[o,n,a]},Breadcrumb=()=>{const o=useSelectedBlockHierarchy(),[,n]=useSelectedBlockIds(),{highlightBlock:a}=useBlockHighlight();return jsxRuntime.jsx("div",{className:"-mx-2 border-t border-border bg-background px-2 py-1 text-xs text-muted-foreground",children:jsxRuntime.jsxs("ol",{className:"flex items-center whitespace-nowrap",children:[jsxRuntime.jsxs("li",{className:"inline-flex items-center",children:[jsxRuntime.jsx(toggle.Button,{onClick:()=>n([]),variant:"ghost",className:"h-fit p-1 text-xs font-normal",children:"Body"}),jsxRuntime.jsx(lucideReact.ChevronRight,{className:"rtl:rotate-180",size:16})]}),lodashEs.reverse(o).map((l,r)=>jsxRuntime.jsxs("li",{className:"inline-flex items-center",children:[jsxRuntime.jsxs(toggle.Button,{onMouseEnter:()=>{a(l==null?void 0:l._id)},onClick:()=>n([l==null?void 0:l._id]),variant:"ghost",className:"h-fit gap-x-1 p-1 text-xs font-normal",children:[jsxRuntime.jsx(TypeIcon,{type:l==null?void 0:l._type}),l._name||l._type]}),r!==o.length-1&&jsxRuntime.jsx(lucideReact.ChevronRight,{className:"rtl:rotate-180",size:16})]},r))]})})},CHAI_BUILDER_EVENTS={OPEN_ADD_BLOCK:"OPEN_ADD_BLOCK",CLOSE_ADD_BLOCK:"CLOSE_ADD_BLOCK",SHOW_BLOCK_SETTINGS:"SHOW_BLOCK_SETTINGS",CLEAR_CANVAS_SELECTION:"CLEAR_CANVAS_SELECTION",CANVAS_BLOCK_SELECTED:"CANVAS_BLOCK_SELECTED",CANVAS_BLOCK_STYLE_SELECTED:"CANVAS_BLOCK_STYLE_SELECTED"},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 l=lodashEs.get(n,"data._type",""),r=lodashEs.get(a,"data._type","");return canAcceptChildBlock(r,l)};class PubSub{constructor(){H(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 l=this.subscribers.get(n);l&&(l.delete(a),l.size===0&&this.subscribers.delete(n))}}publish(n,a){const l=this.subscribers.get(n);l&&l.forEach(r=>r(a))}}const pubsub=new PubSub,AddBlockDropdown=({block:o,children:n})=>{const{t:a}=reactI18next.useTranslation(),[l]=useBlocksStore(),{hasPermission:r}=usePermissions(),i=lodashEs.get(o,"_id"),c=lodashEs.get(o,"_parent"),d=lodashEs.filter(l,g=>c?lodashEs.get(g,"_parent")===c:!lodashEs.get(g,"_parent")),m=canAddChildBlock(lodashEs.get(o,"_type","")),u=lodashEs.findIndex(d,{_id:i}),p=g=>{if(g==="CHILD")pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,o);else{const x={_id:c||"",position:d==null?void 0:d.length};g==="BEFORE"?x.position=Math.max(u,0):g==="AFTER"&&(x.position=u+1),pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,x)}};return r(PERMISSIONS.ADD_BLOCK)?jsxRuntime.jsxs(toggle.DropdownMenu,{children:[jsxRuntime.jsx(toggle.DropdownMenuTrigger,{children:n}),jsxRuntime.jsxs(toggle.DropdownMenuContent,{className:"border border-blue-500 bg-primary text-white shadow-2xl",children:[m&&jsxRuntime.jsx(toggle.DropdownMenuItem,{className:"cursor-pointer text-xs",onClick:()=>p("CHILD"),children:a("Add inside")}),jsxRuntime.jsx(toggle.DropdownMenuItem,{className:"cursor-pointer text-xs",onClick:()=>p("BEFORE"),children:a("Add before")}),jsxRuntime.jsx(toggle.DropdownMenuItem,{className:"cursor-pointer text-xs",onClick:()=>p("AFTER"),children:a("Add after")})]})]}):null},draggedBlockAtom=jotai.atom(null);jotai.atom(null);function getOrientation(o,n=null){const a=window.getComputedStyle(o),l=n?window.getComputedStyle(n):null,r=a.display,i=l?l.display:null;if(r==="flex"||r==="inline-flex"){const c=a.flexDirection;return c==="column"||c==="column-reverse"?"vertical":"horizontal"}else if(r==="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(i==="inline-block"||i==="inline")return"horizontal";return"vertical"}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;function insertBlocksAtPosition(o,n,a,l){const r=[...n];let i=[...o];if(a){const u=o.find(p=>p._id===a);if(u&&u.content!==void 0&&u.content!==""&&!o.some(g=>g._parent===a)){const x={_id:commonFunctions.generateUUID(),_parent:a,_type:"Text",content:u.content};Object.keys(u).forEach(f=>{f.startsWith("content-")&&(x[f]=u[f])}),r.unshift(x),i=i.map(f=>{if(f._id===a){const h={...f,content:""};return Object.keys(h).forEach(j=>{j.startsWith("content-")&&(h[j]="")}),h}return f})}}let c=i.filter(u=>!u._parent);a&&(c=i.filter(u=>u._parent===a));const d=!isNaN(l)||l>-1?Math.min(l,c.length):c.length;let m=i.length;for(let u=0,p=0;u<i.length;u++)if(a!==void 0?i[u]._parent===a:!i[u]._parent){if(p===d){m=u;break}p++}return!a&&l!==void 0&&l>=c.length&&(m=i.length),[...i.slice(0,m),...r,...i.slice(m)]}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,l){var u,p;const r=findNodeById(o,n),i=findNodeById(o,a);if(!r||!i)return!1;i.children||(i.model.children=[]);let c=(u=i==null?void 0:i.children)==null?void 0:u.findIndex(g=>g.model._id===n);r.drop(),c=Math.max(c,0);const m=(((p=r==null?void 0:r.model)==null?void 0:p._parent)||"root")===a&&c<=l?l-1:l;try{i.addChildAtIndex(r,m)}catch(g){return console.error("Error adding child to parent:",g),!1}return!0}function handleOldParentTextBlock(o,n){if(!n||!n._parent)return o;const a=n._parent,l=o.find(i=>i._id===a);if(!l)return o;const r=o.filter(i=>i._parent===a);if(r.length===2){const i=r.find(c=>c._id!==n._id);if(i&&i._type==="Text"&&"content"in l)return o.map(d=>{if(d._id===a){const m={...d,content:i.content};return Object.keys(i).forEach(u=>{u.startsWith("content-")&&(m[u]=i[u])}),m}return d}).filter(d=>d._id!==i._id)}return o}function handleNewParentTextBlock(o,n,a){if(!a||a==="root")return o;const l=o.find(r=>r._id===a);if(!l)return o;if(l.content!==void 0&&l.content!==""&&!o.some(i=>i._parent===a&&i._id!==n._id)){const c={_id:commonFunctions.generateUUID(),_parent:a,_type:"Text",content:l.content};Object.keys(l).forEach(u=>{u.startsWith("content-")&&(c[u]=l[u])});const d=o.map(u=>{if(u._id===a){const p={...u,content:""};return Object.keys(p).forEach(g=>{g.startsWith("content-")&&(p[g]="")}),p}return u}),m=d.findIndex(u=>u._id===n._id);return m!==-1?[...d.slice(0,m),c,...d.slice(m)]:[c,...d]}return o}function moveBlocksWithChildren(o,n,a,l){if(!n)return o;const r=o.find(u=>u._id===n);if(!r)return o;let i=handleOldParentTextBlock(o,r);const c=a||"root",m=new TreeModel().parse({_id:"root",children:getBlocksTree(i)});if(moveNode(m,n,c,l)){let u=flattenTree(m);const p=u.find(g=>g._id===n);return p&&(p._parent=c==="root"?null:c),u.shift(),a&&(u=handleNewParentTextBlock(u,r,a)),u}return i}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=l=>{console.log("error",l)},broadcastChannel.onmessage=l=>{l.data.type==="blocks-updated"&&l.data.pageId===n&&o(l.data.blocks),l.data.type==="blocks-props-updated"&&l.data.pageId===n&&a(l.data.blocks)},()=>{broadcastChannel.onmessage=null,broadcastChannel.onmessageerror=null}),[o,n])},removeNestedBlocks=(o,n)=>{let a=[...o],l=[];n.forEach(d=>{const m=a.find(g=>g._id===d);if(!m||!m._parent)return;const u=m._parent,p=a.filter(g=>g._parent===u);if(p.length===2){const g=p.find(x=>x._id!==d);if(g&&g._type==="Text"){const x=a.find(f=>f._id===u);x&&"content"in x&&(a=a.map(f=>{if(f._id===u){const h={...f,content:g.content};return Object.keys(g).forEach(j=>{j.startsWith("content-")&&(h[j]=g[j])}),h}return f}),l.push(g._id))}}});const r=[...n,...l],i=[],c=lodashEs.filter(a,d=>lodashEs.includes(r,d._id)||lodashEs.includes(r,d._parent)?(i.push(d._id),!1):!0);return lodashEs.isEmpty(i)?c:removeNestedBlocks(c,i)},useRemoveBlocks=()=>{const[o]=useBlocksStore(),[n,a]=useSelectedBlockIds(),{setNewBlocks:l}=useBlocksStoreUndoableActions(),{hasPermission:r}=usePermissions();return React.useCallback(i=>{var d;if(!r(PERMISSIONS.DELETE_BLOCK))return;const c=((d=lodashEs.find(o,{_id:i[0]}))==null?void 0:d._parent)||null;l(removeNestedBlocks(o,i)),setTimeout(()=>a(c?[c]:[]),200)},[o,a,n,r])},builderStore=jotai.getDefaultStore(),writeAtomValue=jotai.atom(null,(o,n,{id:a,props:l})=>{const r=o(pageBlocksAtomsAtom),i=lodashEs.find(r,c=>o(c)._id===a);return i?n(i,{...o(i),...l}):null}),useUpdateBlockAtom=()=>jotai.useSetAtom(writeAtomValue),useGetBlockAtom=o=>utils.useAtomCallback(React.useCallback((n,a,l)=>{const r=n(o);if(!r||!r.length)return console.warn("No blocks available in splitAtoms"),null;const i=lodashEs.find(r,c=>n(c)._id===(lodashEs.isString(l)?l:n(l)._id));return i||(console.warn(`Block with id ${l} not found`),null)},[o]),{store:builderStore}),useBlocksStoreManager=()=>{const[,o]=useBlocksStore(),{postMessage:n}=useBroadcastChannel(),a=useUpdateBlockAtom();return{setNewBlocks:l=>{o(l),n({type:"blocks-updated",blocks:l})},addBlocks:(l,r,i)=>{o(c=>{const d=insertBlocksAtPosition(c,l,r,i);return n({type:"blocks-updated",blocks:d}),d})},removeBlocks:l=>{o(r=>{const i=removeNestedBlocks(r,l);return n({type:"blocks-updated",blocks:i}),i})},moveBlocks:(l,r,i)=>{o(c=>{let d=[...c];for(let m=0;m<l.length;m++)d=moveBlocksWithChildren(d,l[m],r,i);return lodashEs.each(l,m=>{const u=lodashEs.find(d,p=>p._id===m);u&&a({id:m,props:{_parent:u._parent||null}})}),n({type:"blocks-updated",blocks:d}),d})},updateBlocksProps:l=>{l.forEach(r=>{const i=lodashEs.omit(r,"_id");a({id:r._id,props:i})}),n({type:"blocks-props-updated",blocks:l})}}},blockRepeaterDataAtom=jotai.atom({});blockRepeaterDataAtom.debugLabel="blockRepeaterDataAtom";const useBlockRepeaterDataAtom=()=>jotai.useAtom(blockRepeaterDataAtom),useAsyncProps=(o,n,a,l)=>{const[r,i]=React.useState({status:"idle",props:{},error:void 0}),c=useUpdateBlocksPropsRealtime(),d=useBuilderProp("getBlockAsyncProps",async f=>({})),m=jotai.useSetAtom(blockRepeaterDataAtom),u=JSON.stringify([o==null?void 0:o._id,...lodashEs.values(lodashEs.pick(o,a??[]))]),p=(o==null?void 0:o._type)==="Repeater"&&lodashEs.startsWith(o.repeaterItems,`{{${applyBinding.COLLECTION_PREFIX}`),g=(o==null?void 0:o._type)!=="Repeater"&&n==="live";return React.useEffect(()=>{if(n==="mock"){if(lodashEs.isFunction(l)){i(h=>({...h,status:"loading",props:{}}));const f=l({block:o});if(!utils$1.isObject(f))throw new Error("mockDataProvider should return an object");i(h=>({...h,status:"loaded",props:f}))}return}n==="live"&&(!p&&!g||(i(f=>({...f,status:"loading",props:{}})),d({block:o}).then((f={})=>{p?(m(h=>({...h,[o._id]:{status:"loaded",props:lodashEs.get(f,"items",[]),repeaterItems:o.repeaterItems}})),i(h=>({...h,status:"loaded",props:{totalItems:lodashEs.get(f,"totalItems")}})),c([o._id],{totalItems:lodashEs.get(f,"totalItems")})):i(h=>({...h,status:"loaded",props:utils$1.isObject(f)?f:{}}))}).catch(f=>{p?(m(h=>({...h,[o._id]:{status:"error",error:f,props:[]}})),i(h=>({...h,status:"error",error:f,props:{}}))):i(h=>({...h,status:"error",error:f,props:{}}))})))},[o==null?void 0:o._id,u,p,g,l,n]),{$loading:lodashEs.get(r,"status")==="loading",...o?lodashEs.get(r,"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 usePageExternalData=()=>{const[o]=useBlockRepeaterDataAtom(),n=React.useMemo(()=>{const l={};return Object.entries(o).forEach(([r,i])=>{i.status==="loaded"&&(l[i.repeaterItems.replace("}}",`/${r}`).replace("{{","")]=i.props)}),l},[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(l=>lodashEs.get(a[l],"builderProp",!1)||lodashEs.get(a[l],"runtime",!1)?l:null))}),useGetPageData=()=>{const[o]=useBrandingOptions(),{currentPage:n}=useCurrentPage(),[a]=useBlocksStore();return React.useCallback(()=>{const l=lodashEs.map(a,r=>lodashEs.omit(r,getBlockBuilderProps(r._type)));return{currentPage:n,blocks:l}},[o,n,a])},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,[l,r])=>({...a,[l.replace("font-","")]:r}),n.fontFamily)),n.borderRadius=o.borderRadius,o.colors&&(n.colors=o.colors.reduce((a,l)=>(Object.entries(l.items).forEach(([r,i])=>{a[r]=i}),a),n.colors)),n},chaiThemeValuesAtom=jotai.atom({}),useTheme=()=>{const o=useThemeOptions(),n=React.useMemo(()=>getDefaultThemeValues(o),[o]),a=useBuilderProp("theme",{}),[l,r]=jotai.useAtom(chaiThemeValuesAtom);return[React.useMemo(()=>({...n,...!lodashEs.isEmpty(a)&&a,...!lodashEs.isEmpty(l)&&l}),[n,a,l]),r]},useThemeOptions=()=>{const o=useBuilderProp("themeOptions",a=>a);return React.useMemo(()=>o(plugin.defaultThemeOptions),[o])},rightPanelAtom=jotai.atom("block"),useRightPanel=()=>jotai.useAtom(rightPanelAtom),languageAtom=jotai.atom("");languageAtom.debugLabel="selectedLanguageAtom";const useLanguages=()=>{const o=useBuilderProp("languages",[]),n=useBuilderProp("fallbackLang","en"),[a,l]=jotai.useAtom(languageAtom),r=i=>{l(n===i?"":i)};return{languages:o==null?void 0:o.filter(i=>i!==n),fallbackLang:n,selectedLang:a,setSelectedLang:r}},isPageLoadedAtom=jotai.atom(!1),useIsPageLoaded=()=>{const[o]=jotai.useAtom(isPageLoadedAtom);return o},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 l=runtime.getRegisteredChaiBlock(a._type);return l?(lodashEs.has(l,"i18nProps")?l.i18nProps:[]).some(i=>{const c=`${i}-${n}`;return!a[c]||lodashEs.isEmpty(a[c])}):!1}catch(l){return console.warn(`Failed to get block definition for type: ${a._type}`,l),!1}}):!1,useSavePage=()=>{const[o,n]=jotai.useAtom(builderSaveStateAtom),a=useBuilderProp("onSave",async f=>{}),l=useBuilderProp("onSaveStateChange",lodashEs.noop),r=useGetPageData(),[i]=useTheme(),{hasPermission:c}=usePermissions(),{selectedLang:d,fallbackLang:m}=useLanguages(),u=useIsPageLoaded(),p=()=>{const f=r();return!d||d===m?!1:checkMissingTranslations(f.blocks||[],d)};return{savePage:web.useThrottledCallback(async(f=!1)=>{if(!c("save_page")||!u)return;n("SAVING"),l("SAVING");const h=r();return await a({autoSave:f,blocks:h.blocks,theme:i,needTranslations:p()}),setTimeout(()=>{n("SAVED"),l("SAVED")},100),!0},[r,n,i,a,l,u],3e3),savePageAsync:async()=>{if(!c("save_page")||!u)return;n("SAVING"),l("SAVING");const f=r();return await a({autoSave:!0,blocks:f.blocks,theme:i,needTranslations:p()}),setTimeout(()=>{n("SAVED"),l("SAVED")},100),!0},saveState:o,setSaveState:n,needTranslations:p}},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),l=useBuilderProp("onSaveStateChange",lodashEs.noop),r=React.useCallback(()=>{const u={canUndo:undoManager.hasUndo(),canRedo:undoManager.hasRedo()};a(u),o("UNSAVED"),l("UNSAVED")},[a,o,l]);React.useEffect(()=>(undoManager.setCallback(r),()=>{undoManager.setCallback(lodashEs.noop)}),[r]);const i=React.useCallback(u=>{undoManager.add(u),r()},[r]),c=React.useCallback(()=>{undoManager.undo(),r()},[r]),d=React.useCallback(()=>{undoManager.redo(),r()},[r]),m=React.useCallback(()=>{undoManager.clear(),a({canUndo:!1,canRedo:!1})},[a]);return React.useMemo(()=>({add:i,undo:c,redo:d,hasUndo:()=>n.canUndo,hasRedo:()=>n.canRedo,clear:m}),[i,c,d,n.canUndo,n.canRedo,m])},useBlocksStore=()=>jotai.useAtom(presentBlocksAtom),useBlocksStoreUndoableActions=()=>{const{add:o}=useUndoManager(),[n]=useBlocksStore(),{setNewBlocks:a,addBlocks:l,removeBlocks:r,moveBlocks:i,updateBlocksProps:c}=useBlocksStoreManager();return{moveBlocks:(h,j,b)=>{const C=lodashEs.map(h,B=>{const S=n.find(w=>w._id===B)._parent||null,E=n.filter(w=>S?w._parent===S:!w._parent).map(w=>w._id).indexOf(B);return{_id:B,oldParent:S,oldPosition:E}}),A=C.find(({_id:B})=>B===h[0]);A&&A.oldParent===j&&A.oldPosition===b||(i(h,j,b),o({undo:()=>lodashEs.each(C,({_id:B,oldParent:_,oldPosition:S})=>{i([B],_,S)}),redo:()=>i(h,j,b)}))},addBlocks:(h,j,b)=>{l(h,j,b),o({undo:()=>r(lodashEs.map(h,"_id")),redo:()=>l(h,j,b)})},removeBlocks:h=>{var A;const j=(A=lodashEs.first(h))==null?void 0:A._parent,C=n.filter(B=>j?B._parent===j:!B._parent).indexOf(lodashEs.first(h));r(lodashEs.map(h,"_id")),o({undo:()=>l(h,j,C),redo:()=>r(lodashEs.map(h,"_id"))})},updateBlocks:(h,j,b)=>{let C=[];if(b)C=lodashEs.map(h,A=>({_id:A,...b}));else{const A=lodashEs.keys(j);C=lodashEs.map(h,B=>{const _=n.find(y=>y._id===B),S={_id:B};return lodashEs.each(A,y=>S[y]=_[y]),S})}c(lodashEs.map(h,A=>({_id:A,...j}))),o({undo:()=>c(C),redo:()=>c(lodashEs.map(h,A=>({_id:A,...j})))})},updateBlocksRuntime:(h,j)=>{c(lodashEs.map(h,b=>({_id:b,...j})))},setNewBlocks:h=>{a(h),o({undo:()=>a(n),redo:()=>a(h)})},updateMultipleBlocksProps:h=>{let j=[];j=lodashEs.map(h,b=>{const C=lodashEs.keys(b),A=n.find(_=>_._id===b._id),B={};return lodashEs.each(C,_=>B[_]=A[_]),B}),c(h),o({undo:()=>c(j),redo:()=>c(h)})}}},useAddBlock=()=>{const[o]=useBlocksStore(),[,n]=useSelectedBlockIds(),{addBlocks:a}=useBlocksStoreUndoableActions(),l=React.useCallback((i,c,d)=>{var x;for(let f=0;f<i.length;f++){const{_id:h}=i[f];i[f]._id=commonFunctions.generateUUID();const j=lodashEs.filter(i,{_parent:h});for(let b=0;b<j.length;b++)j[b]._parent=i[f]._id}const m=lodashEs.first(i);let u,p;return c&&(u=lodashEs.find(o,{_id:c}),i[0]._parent=c,p=c),!(u?canAcceptChildBlock(u==null?void 0:u._type,m._type):!0)&&u&&(i[0]._parent=u._parent,p=u._parent),a(i,p,d),n([(x=lodashEs.first(i))==null?void 0:x._id]),lodashEs.first(i)},[a,o,n]);return{addCoreBlock:React.useCallback((i,c,d)=>{if(lodashEs.has(i,"blocks")){const j=i.blocks;return l(j,c,d)}const m=commonFunctions.generateUUID(),u=runtime.getDefaultBlockProps(i.type),p={_type:i.type,_id:m,...u,...lodashEs.has(i,"_name")&&{_name:i._name},...lodashEs.has(i,"partialBlockId")&&{partialBlockId:i.partialBlockId}};let g,x;return c&&(g=lodashEs.find(o,{_id:c}),p._parent=c,x=c),!canAcceptChildBlock(g==null?void 0:g._type,p._type)&&g&&(p._parent=g._parent,x=g._parent),a([p],x,d),n([p._id]),p},[a,l,o,n]),addPredefinedBlock:l}},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 l=lodashEs.flattenDeep(lodashEs.map(o.colors,({items:r})=>lodashEs.keys(r)));a=lodashEs.flattenDeep(lodashEs.map(l,r=>lodashEs.flatten(lodashEs.map(colorKeys,i=>`${i}-${r}`))))}return o.fontFamily&&(a=[...a,...lodashEs.map(lodashEs.keys(o.fontFamily),l=>`${l}`)]),lodashEs.map(a,l=>({name:l}))},[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 r=lodashEs.flattenDeep(lodashEs.map(o.colors,({items:i})=>lodashEs.keys(i)));lodashEs.each(CLASSES_LIST,(i,c)=>{lodashEs.set(CLASSES_LIST,`${c}.regExp`,i.regExp.replace("__THEME_COLORS_REGEXP__",r.join("|")))})}return CLASSES_LIST},[o]),a=React.useCallback((r,i)=>{const c=lodashEs.get(n,`${r}.regExp`,"");return i.match(new RegExp(c))},[n]),l=React.useCallback((r,i=[])=>lodashEs.get(n,`${r}.classes`,i),[n]);return{match:a,getClasses:l}};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,l=>`${l}:`).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 l=lodashEs.get(CLASSES_LIST,`${a}.regExp`,"");if(new RegExp(l,"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((l,r)=>a.indexOf(l.mq)-a.indexOf(r.mq)).map(l=>l.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 l=o;if(a.length===1)return a[0].fullCls;for(const r of a){const i=r.property,c=n.indexOf(r.mq);for(let d=c+1;d<n.length;d++){const m=n[d],u=a.find(p=>p.property===i&&p.mq===m);if(u&&u.cls===r.cls)l=l.replace(u.fullCls,"");else if(u&&u.cls!==r.cls)break}}return l.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:l})=>{const r=lodashEs.filter(o(pageBlocksAtomsAtom),c=>a.includes(o(c)._id)),i=lodashEs.first(o(selectedStylingBlocksAtom));return lodashEs.map(r,c=>{const d=o(c),m=lodashEs.get(d,i.prop,`${applyBinding.STYLES_KEY},`),{classes:u}=applyBinding.getSplitChaiClasses(m);return{ids:[d._id],props:{[i.prop]:`${applyBinding.STYLES_KEY},${orderClassesByBreakpoint(removeDuplicateClasses(tailwindMerge.twMerge(u,l)))}`}}})}),useAddClassesToBlocks=()=>{const o=jotai.useSetAtom(addClassesToBlocksAtom),{updateBlocks:n,updateBlocksRuntime:a}=useBlocksStoreUndoableActions();return React.useCallback((l,r,i=!1)=>{const c=o({blockIds:l,newClasses:r});if(!i){a(l,c[0].props);return}n(l,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 l=runtime.getRegisteredChaiBlock(lodashEs.get(a,"_type"));if(!l)return o;const r={...o};return lodashEs.forEach(lodashEs.keys(o),i=>{if(lodashEs.includes(lodashEs.get(l,"i18nProps",[]),i)&&!lodashEs.isEmpty(n)){const c=`${i}-${n}`;lodashEs.set(r,c,o[i]),lodashEs.unset(r,i)}}),r},useUpdateBlocksProps=()=>{const{updateBlocks:o}=useBlocksStoreUndoableActions(),{selectedLang:n}=useLanguages(),a=useSelectedBlock();return React.useCallback((l,r,i)=>{const c=updatePropsForLanguage(r,n,a);o(l,c,i)},[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,l=30)=>{const r=lodashEs.keys(lodashEs.omit(a,["_id"]));for(const i of r){const c=a[i];if(lodashEs.isString(c)){const d=lodashEs.chunk(c.split(""),12);let m="";o([n],{[i]:""});for(let u=0;u<d.length;u++)m+=d[u].join(""),o([n],{[i]:m}),await new Promise(p=>setTimeout(p,l))}}},[o])},useStreamMultipleBlocksProps=()=>{const{updateMultipleBlocksProps:o}=useBlocksStoreUndoableActions(),n=useFakeStreamEffect();return React.useCallback(async a=>{for(const l of a)await n(l._id,l);o(a)},[n,o])},useUpdateBlocksPropsRealtime=()=>{const{updateBlocksRuntime:o}=useBlocksStoreUndoableActions(),{selectedLang:n}=useLanguages(),a=useSelectedBlock();return React.useCallback((l,r)=>{const i=updatePropsForLanguage(r,n,a);o(l,i)},[n,a,o])};function getChildBlocks(o,n,a){a.push(lodashEs.find(o,{_id:n}));const l=lodashEs.filter(o,{_parent:n});for(const r of l)a.push(...getBlockWithChildren(r._id,o));return a}const getBlockWithChildren=(o,n)=>{let a=[];return a=lodashEs.flattenDeep([...a,...getChildBlocks(n,o,a)]),a},pickOnlyAIProps=(o,n,a)=>lodashEs.compact(o.map(l=>{const r=["_id","_type","_parent"],i=lodashEs.pick(l,r),c=runtime.getRegisteredChaiBlock(l._type),d={},m=lodashEs.get(c,"aiProps",[]);for(const u in l)if(!r.includes(u)&&m.includes(u)){const p=lodashEs.get(l,`${u}-${n}`,""),g=lodashEs.get(l,u,"");d[u]=lodashEs.isString(p)&&p.trim()||g,a&&(d[u]=g)}return lodashEs.isEmpty(d)?!1:(lodashEs.has(i,"_parent")&&lodashEs.isEmpty(i._parent)&&delete i._parent,{...i,...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,l]=React.useState(null),r=useBuilderProp("askAiCallBack",null),i=useStreamMultipleBlocksProps(),c=useUpdateMultipleBlocksProps(),[d]=useBlocksStore(),{selectedLang:m,fallbackLang:u}=useLanguages(),p=m.length?m:u,g=(x,f)=>{const h=lodashEs.cloneDeep(f.find(j=>j._id===x));for(const j in h){const b=h[j];if(typeof b=="string"&&lodashEs.startsWith(b,applyBinding.STYLES_KEY)){const{baseClasses:C,classes:A}=applyBinding.getSplitChaiClasses(b);h[j]=lodashEs.compact(lodashEs.flattenDeep([C,A])).join(" ")}else j!=="_id"&&delete h[j]}return h};return{askAi:React.useCallback(async(x,f,h,j)=>{if(r){n(!0),l(null);try{const b=m===u?"":m;console.log("prompt",h);const C=h.toLowerCase().includes("translate the content"),A=x==="content"?pickOnlyAIProps(lodashEs.cloneDeep(getBlockWithChildren(f,d)),m,C):[g(f,d)],B=await r(x,addLangToPrompt(h,p,x),A,b),{blocks:_,error:S}=B;if(S){l(S);return}if(x==="styles"){const y=_.map(E=>{for(const w in E)w!=="_id"&&(E[w]=`${applyBinding.STYLES_KEY},${E[w]}`);return E});c(y)}else i(_);j&&j(B)}catch(b){l(b)}finally{n(!1),j&&j()}}},[r,n,m,u,d,p,c,i]),loading:o,error:a}},useAiAssistant=()=>{const[,o]=useRightPanel();return React.useCallback(n=>{o(n?"ai":"block")},[o])},partialBlocksStoreAtom=jotai.atom({}),partialBlocksLoadingStateAtom=jotai.atom({}),usePartialBlocksStore=()=>{const[o,n]=jotai.useAtom(partialBlocksStoreAtom),a=React.useCallback(r=>lodashEs.get(o,r,[]),[o]),l=React.useCallback(()=>n({}),[n]);return{getPartailBlocks:a,reset:l}},useWatchPartailBlocks=()=>{const[o]=useBlocksStore(),[n,a]=jotai.useAtom(partialBlocksStoreAtom),[l,r]=jotai.useAtom(partialBlocksLoadingStateAtom),i=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(l,`${d}.loading`,!1)||(r(m=>({...m,[d]:{loading:!0,error:null}})),i(d).then(m=>{a(u=>({...u,[d]:m})),r(u=>({...u,[d]:{loading:!1,error:null}}))}).catch(m=>{r(u=>({...u,[d]:{loading:!1,error:m.message}}))}))})},[i,n,l,a,r,c])},partialBlocksListAtom=jotai.atom({}),usePartialBlocksList=()=>{const[o,n]=React.useState(!1),[a,l]=React.useState(null),[r,i]=jotai.useAtom(partialBlocksListAtom),c=useBuilderProp("getPartialBlocks",async()=>[]),d=React.useCallback(async()=>{n(!0),l(null);try{const m=await c();i(m),n(!1)}catch(m){l(m instanceof Error?m.message:"Failed to fetch partial blocks"),n(!1)}},[c,i]);return React.useEffect(()=>{d()},[]),{data:r,isLoading:o,refetch:d,error:a}},useBuilderReset=()=>{const{clear:o}=useUndoManager(),[,n]=useSelectedBlockIds(),{clearHighlight:a}=useBlockHighlight(),[,l]=useSelectedStylingBlocks(),[,r]=jotai.useAtom(aiAssistantActiveAtom),{reset:i}=usePartialBlocksStore(),{setSaveState:c}=useSavePage(),[,d]=useBlockRepeaterDataAtom();return()=>{d({}),n([]),l([]),a(),o(),r(!1),i(),c("SAVED")}},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),l=React.useCallback(r=>{n(r),a([])},[n,a]);return[o,l]},copiedBlockIdsAtom=jotai.atom([]),useCopyBlocks=()=>{const[o]=useBlocksStore(),[n,a]=jotai.useAtom(copiedBlockIdsAtom),l=jotai.useSetAtom(cutBlockIdsAtom),{getPartailBlocks:r}=usePartialBlocksStore(),i=React.useCallback(d=>d.some(m=>getDuplicatedBlocks(o,m,null).some(p=>p._type==="PartialBlock"||p._type==="GlobalBlock")),[o]),c=React.useCallback(async(d,m=!1)=>{try{if(lodashEs.isEmpty(d))return;a(d),l([]);const u={_chai_copied_blocks:d.flatMap(p=>{const g=getDuplicatedBlocks(o,p,null);if(!m)return g;let x=[];for(const f of g)if(f._type==="PartialBlock"||f._type==="GlobalBlock"){let h=r(f.partialBlockId);f._parent&&(h==null?void 0:h.length)>0&&(h=h.map(j=>(lodashEs.isEmpty(j._parent)&&lodashEs.set(j,"_parent",f._parent),j))),x=[...x,...h]}else x.push(f);return x})};if(!navigator.clipboard){sonner.toast.error("Clipboard not available.");return}sonner.toast.promise(navigator.clipboard.writeText(JSON.stringify(u)),{success:"Blocks copied successfully",error:"Failed to copy blocks to clipboard"})}catch(u){sonner.toast.error("Failed to copy blocks to clipboard"),console.error("Failed to copy blocks to clipboard:",u)}},[a,l,o]);return[n,c,i]},useCopyToClipboard=()=>{const[o,n]=React.useState(null),a=React.useCallback(async l=>{if(!(navigator!=null&&navigator.clipboard))return console.warn("Clipboard not supported"),!1;try{return await navigator.clipboard.writeText(l),n(l),!0}catch(r){return console.warn("Copy failed",r),n(null),!1}},[]);return[o,a]},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((l,r=null)=>{const i=[];lodashEs.each(l,c=>{const d=o.find(x=>x._id===c);r?r==="root"&&(r=null):r=d._parent;const p=lodashEs.filter(o,x=>lodashEs.isString(r)?x._parent===r:!x._parent).indexOf(d)+1,g=getDuplicatedBlocks(o,c,r);a(g,r,p),i.push(lodashEs.get(g,"0._id",""))}),n(i)},[o,n])},hiddenBlockIdsAtom=jotai.atom([]),useHiddenBlockIds=()=>{const[o,n]=jotai.useAtom(hiddenBlockIdsAtom),a=React.useCallback(l=>{n(r=>lodashEs.includes(r,l)?lodashEs.without(r,l):[...r,l])},[n]);return[o,n,a]},highlightBlockIdAtom=jotai.atom(""),useHighlightBlockId=()=>jotai.useAtom(highlightBlockIdAtom),libraryBlocksAtom=jotai.atom({}),useLibraryBlocks=o=>{const[n,a]=jotai.useAtom(libraryBlocksAtom),l=React.useMemo(()=>(o==null?void 0:o.getBlocksList)||(()=>[]),[o]),r=lodashEs.get(n,`${o==null?void 0:o.id}.blocks`,null),i=lodashEs.get(n,`${o==null?void 0:o.id}.loading`,"idle"),c=React.useRef("idle");React.useEffect(()=>{(async()=>{if(!(i==="complete"||c.current==="loading")){c.current="loading",a(m=>({...m,[o==null?void 0:o.id]:{loading:"loading",blocks:[]}}));try{const m=await l(o);c.current="idle",a(u=>({...u,[o==null?void 0:o.id]:{loading:"complete",blocks:m||[]}}))}catch{c.current="idle",a(u=>({...u,[o==null?void 0:o.id]:{loading:"complete",blocks:[]}}))}}})()},[o,r,i,c,a,l]);const d=React.useCallback(m=>{a(u=>({...u,[m]:{loading:"idle",blocks:[]}}))},[a]);return{data:r||[],isLoading:i==="loading",resetLibrary:d}},useCanPaste=()=>{const[o]=useBlocksStore();return(n,a)=>{var i;const l=((i=lodashEs.find(o,{_id:a}))==null?void 0:i._type)||null,r=lodashEs.first(n.map(c=>{var d;return(d=lodashEs.find(o,{_id:c}))==null?void 0:d._type}));return canAcceptChildBlock(l,r)}},useMoveCutBlocks=()=>{const o=jotai.useAtomValue(presentBlocksAtom),{moveBlocks:n}=useBlocksStoreUndoableActions();return React.useCallback((a,l)=>{const r=Array.isArray(l)?l[0]:l;if(l==="root"){const i=o==null?void 0:o.filter(c=>!c._parent);n(a,null,(i==null?void 0:i.length)||0)}else{const i=o==null?void 0:o.filter(c=>c._parent===r);n(a,r,(i==null?void 0:i.length)||0)}},[n,o])},usePasteBlocks=()=>{const[o,n]=useCutBlockIds(),a=useMoveCutBlocks(),{addPredefinedBlock:l}=useAddBlock(),r=useCanPaste();return{canPaste:React.useCallback(async c=>{if(o.length>0)return r(o,c);try{const d=await navigator.clipboard.readText();if(d){const m=JSON.parse(d);return lodashEs.has(m,"_chai_copied_blocks")}}catch{return!1}return!1},[r,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 m=await navigator.clipboard.readText();if(m){const u=JSON.parse(m);if(lodashEs.has(u,"_chai_copied_blocks"))l(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:l})=>{const r=lodashEs.first(o(selectedStylingBlocksAtom)),i=lodashEs.filter(o(pageBlocksAtomsAtom),c=>a.includes(o(c)._id));return lodashEs.map(i,c=>{const d=o(c),m=l;let{classes:u,baseClasses:p}=applyBinding.getSplitChaiClasses(lodashEs.get(d,r.prop,`${applyBinding.STYLES_KEY},`));return lodashEs.each(m,g=>{const x=g.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),f=new RegExp(`(^|\\s)${x}(?=\\s|$)`,"g");u=u.replace(f," ").replace(/\s+/g," ").trim();const h=lodashEs.first(g.split(":"));lodashEs.includes(["2xl","xl","lg","md","sm"],h)&&m.push(g.split(":").pop().trim())}),lodashEs.each(m,g=>{const x=g.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),f=new RegExp(`(^|\\s)${x}(?=\\s|$)`,"g");p=p.replace(f," ").replace(/\s+/g," ").trim()}),{ids:[d._id],props:{[r.prop]:`${applyBinding.STYLES_KEY}${p},${u}`}}})}),removeAllClassesForBlock=o=>{const n=Object.keys(o).filter(l=>typeof o[l]=="string"&&o[l].startsWith(applyBinding.STYLES_KEY)),a={};return n.forEach(l=>{a[l]=`${applyBinding.STYLES_KEY},`}),{ids:[o._id],props:a}},useRemoveAllClassesForBlock=()=>{const{updateBlocks:o,updateBlocksRuntime:n}=useBlocksStoreUndoableActions();return React.useCallback((a,l=!1)=>{const{ids:r,props:i}=removeAllClassesForBlock(a);l?o(r,i):n(r,i)},[o,n])},useRemoveClassesFromBlocks=()=>{const{updateBlocks:o,updateBlocksRuntime:n}=useBlocksStoreUndoableActions(),a=jotai.useSetAtom(removeClassFromBlocksAtom);return React.useCallback((l,r,i=!1)=>{const c=a({blockIds:l,fullClasses:r});i?o(l,c[0].props):n(l,c[0].props)},[a])},useResetBlockStyles=()=>{const o=useSelectedBlock(),n=useUpdateBlocksProps(),a=React.useCallback(c=>runtime.getDefaultBlockProps(c)||{},[]),l=React.useCallback(c=>Object.keys(c).filter(d=>typeof c[d]=="string"&&c[d].startsWith("#styles:")),[]),r=React.useCallback(c=>{if(!o)return;const m=a(o._type)[c]??"#styles:,";n([o._id],{[c]:m})},[o,a,n]);return{resetAll:React.useCallback(()=>{if(!o)return;const c=l(o);if(c.length===0)return;const d=a(o._type),m=lodashEs.pick(d,c);n([o._id],m)},[o,l,a,n]),reset:r}},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),[l,r]=useStylingBreakpoint();return React.useEffect(()=>{l!=="xs"&&r(a)},[a,l,r]),[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 l=lodashEs.get(a,n.prop,`${applyBinding.STYLES_KEY},`),{classes:r}=applyBinding.getSplitChaiClasses(l);return lodashEs.filter(lodashEs.map(r.trim().split(" "),constructClassObject),i=>!lodashEs.isNull(i))}),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),l=o(darkModeAtom),r=getQueries(n);let i=lodashEs.filter(o(selectedBlockAllClassesAtom),{mod:a});return lodashEs.startsWith(a,"_")||(i=lodashEs.filter(i,c=>r.includes(c.mq))),i=i.sort((c,d)=>MQ[c.mq]-MQ[d.mq]),l||(i=lodashEs.filter(i,{dark:!1})),i}),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),l=a.length===1?a[0]:null;if(!l)return null;const r=lodashEs.find(n,{_id:l});if(!r)return null;let i=r._parent;for(;i;){const d=lodashEs.find(n,{_id:i});if(!d)return null;if((c=runtime.getRegisteredChaiBlock(d._type))!=null&&c.wrapper)return d;i=d._parent}return null});wrapperBlockAtom.debugLabel="wrapperBlockAtom";const useWrapperBlock=()=>jotai.useAtomValue(wrapperBlockAtom),inlineEditingActiveAtom=jotai.atom("");inlineEditingActiveAtom.debugLabel="inlineEditingActiveAtom";const inlineEditingItemIndexAtom=jotai.atom(0);inlineEditingItemIndexAtom.debugLabel="inlineEditingItemIndexAtom";const useInlineEditing=()=>{const[o,n]=jotai.useAtom(inlineEditingActiveAtom),[a,l]=jotai.useAtom(inlineEditingItemIndexAtom);return{editingBlockId:o,editingItemIndex:a,setEditingBlockId:n,setEditingItemIndex:l}},useSelectedLibrary=()=>jotai.useAtom(selectedLibraryAtom),sidebarActivePanelAtom=jotai.atom("outline");sidebarActivePanelAtom.debugLabel="sidebarActivePanelAtom";const useSidebarActivePanel=()=>jotai.useAtom(sidebarActivePanelAtom),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 l=`[data-block-id='${o}']`,r=a==null?void 0:a.querySelector(l);if(r){const i=a==null?void 0:a.querySelector(`[data-block-id='${n}']`);return getOrientation(r,i).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:l}=useFrame(),{moveBlocks:r}=useBlocksStoreUndoableActions(),i=lodashEs.get(o,"_id"),c=lodashEs.get(o,"_parent"),d=lodashEs.filter(a,h=>c?lodashEs.get(h,"_parent")===c:!lodashEs.get(h,"_parent")),m=(d==null?void 0:d.length)<=1,u=lodashEs.findIndex(d,{_id:i}),p=u<=0,g=u+1===(d==null?void 0:d.length),x=getParentBlockOrientation(c,i,l),f=React.useCallback(h=>{isDisabledControl(p,g,h)||m||(h==="UP"||h==="LEFT"?r([i],c||null,u-1):(h==="DOWN"||h==="RIGHT")&&r([i],c||null,u+2),n())},[p,g,m,u,i,c,n]);return reactHotkeysHook.useHotkeys("shift+up, shift+down, shift+left, shift+right",({key:h})=>{var j;f((j=h==null?void 0:h.replace("Arrow",""))==null?void 0:j.toUpperCase())},{document:l==null?void 0:l.contentDocument},[f]),{isOnlyChild:m,isFirstBlock:p,isLastBlock:g,moveBlock:f,orientation:x}},BlockController=({block:o,updateFloatingBar:n})=>{const{isOnlyChild:a,isFirstBlock:l,isLastBlock:r,moveBlock:i,orientation:c}=useBlockController(o,n);return a?null:jsxRuntime.jsx(jsxRuntime.Fragment,{children:CONTROLS.map(({ControlIcon:d,dir:m,key:u})=>{if(c!==m)return null;const p=isDisabledControl(l,r,u);return p?null:jsxRuntime.jsx(d,{onClick:()=>i(u),className:`${p?"pointer-events-none cursor-not-allowed opacity-50":"duration-300 hover:scale-95 hover:opacity-80"}`},u)})})};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"],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"},isInlineEditable=(o,n)=>{if(isRichTextParent(o))return!0;const a=o==null?void 0:o.getAttribute("data-block-type");return!a||o&&o.children.length>0||a==="Button"?!1:INLINE_EDITABLE_BLOCKS.includes(a)},useHandleCanvasDblClick=()=>{const{editingBlockId:o,setEditingBlockId:n,setEditingItemIndex:a}=useInlineEditing();return React.useCallback(l=>{var d;if(l==null||l.preventDefault(),l==null||l.stopPropagation(),o)return;const r=getTargetedBlock(l.target);if(!isInlineEditable(r))return;const i=r.getAttribute("data-block-id");if(!i||!r)return;const c=r.closest('[data-block-type="Repeater"]');c?(d=c==null?void 0:c.childNodes)==null||d.forEach((m,u)=>{m.contains(r)&&a(u)}):a(-1),n(i)},[o,n,a])},useHandleCanvasClick=()=>{const{editingBlockId:o}=useInlineEditing(),{clearHighlight:n}=useBlockHighlight(),a=React.useRef(0);return React.useCallback(l=>{const r=new Date().getTime();if(o||(l.stopPropagation(),r-a.current<400))return;const c=getTargetedBlock(l.target);if(c!=null&&c.getAttribute("data-block-id")&&(c==null?void 0:c.getAttribute("data-block-id"))==="container"){pubsub.publish(CHAI_BUILDER_EVENTS.CLEAR_CANVAS_SELECTION);return}if(c!=null&&c.getAttribute("data-block-parent")){const d=c.getAttribute("data-style-prop"),m=c.getAttribute("data-style-id"),u=c.getAttribute("data-block-parent");pubsub.publish(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_STYLE_SELECTED,{blockId:u,styleId:m,styleProp:d})}else if(c!=null&&c.getAttribute("data-block-id")){const d=c.getAttribute("data-block-id");pubsub.publish(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_SELECTED,d==="canvas"?[]:[d])}n(),a.current=new Date().getTime()},[o])},useHandleMouseMove=()=>{const{editingBlockId:o}=useInlineEditing(),{highlightBlock:n}=useBlockHighlight();return web.useThrottledCallback(a=>{if(o)return;const l=getTargetedBlock(a.target);l&&n(l)},[o,n],100)},useHandleMouseLeave=()=>{const{clearHighlight:o}=useBlockHighlight();return React.useCallback(()=>o(),[o])},Canvas=({children:o})=>{const n=useHandleCanvasDblClick(),a=useHandleCanvasClick(),l=useHandleMouseMove(),r=useHandleMouseLeave();return jsxRuntime.jsx("div",{"data-block-id":"canvas",id:"canvas",onClick:a,onDoubleClick:n,onMouseMove:l,onMouseLeave:r,className:"relative h-full max-w-full p-px",children:o})},getElementByDataBlockId=(o,n)=>o.querySelector(`[data-block-id="${n}"]`),BlockActionLabel=({block:o,label:n})=>{const[,a]=useSelectedBlockIds(),[,l]=useHighlightBlockId(),[,r]=jotai.useAtom(draggedBlockAtom),i=flagged.useFeature("dnd");return jsxRuntime.jsxs("div",{className:"mr-10 flex cursor-default items-center space-x-1 px-1",draggable:i?"true":"false",onDragStart:c=>{c.dataTransfer.setData("text/plain",JSON.stringify(lodashEs.pick(o,["_id","_type","_name"]))),r(o),setTimeout(()=>{a([]),l(null)},200)},children:[jsxRuntime.jsx(reactIcons.DragHandleDots2Icon,{}),n]})},getElementByStyleId=(o,n)=>o.querySelector(`[data-style-id="${n}"]`),BlockSelectionHighlighter=()=>{const o=useSelectedBlock(),{document:n}=useFrame(),[a]=useSelectedStylingBlocks(),[l,r]=React.useState([]),[,i]=React.useState([]),c=(d,m=0)=>{const{top:u}=d.getBoundingClientRect();return u+m>=0&&u-m<=window.innerHeight};return React.useEffect(()=>{var d;if(o!=null&&o._id&&o.type!=="Multiple"&&n){const m=getElementByDataBlockId(n,o._id);m&&(c(m)||(d=n.defaultView)==null||d.scrollTo({top:m.offsetTop,behavior:"smooth"}),r([m]))}},[o==null?void 0:o._id,o==null?void 0:o.type,n]),React.useEffect(()=>{if(!lodashEs.isEmpty(a)&&n){const d=getElementByStyleId(n,lodashEs.first(a).id);i(d?[d]:[null])}else i([null])},[a,n]),jsxRuntime.jsx(BlockFloatingSelector,{block:o,selectedBlockElement:l[0]})},BlockFloatingSelector=({block:o,selectedBlockElement:n})=>{const a=useRemoveBlocks(),l=useDuplicateBlocks(),[,r]=useSelectedBlockIds(),[,i]=useHighlightBlockId(),[,c]=useSelectedStylingBlocks(),{hasPermission:d}=usePermissions(),{editingBlockId:m}=useInlineEditing(),{document:u}=useFrame(),{floatingStyles:p,refs:g,update:x}=reactDom.useFloating({placement:"top-start",middleware:[reactDom.shift({boundary:u==null?void 0:u.body,limiter:dom.limitShift({offset:8,mainAxis:!0,crossAxis:!0})}),dom.flip({boundary:u==null?void 0:u.body,fallbackPlacements:["bottom-start","top-end","bottom-end","inside"]}),dom.size({boundary:u==null?void 0:u.body,apply({availableWidth:j,availableHeight:b,elements:C}){Object.assign(C.floating.style,{maxWidth:`${Math.max(200,j)}px`,maxHeight:`${Math.max(100,b)}px`})}})],elements:{reference:n}});web.useResizeObserver(n,()=>x(),n!==null),web.useResizeObserver(u==null?void 0:u.body,()=>x(),(u==null?void 0:u.body)!==null);const f=lodashEs.get(o,"_parent",null),h=lodashEs.isEmpty(lodashEs.get(o,"_name",""))?lodashEs.get(o,"_type",""):lodashEs.get(o,"_name","");return React.useEffect(()=>{if(n){const j=setTimeout(()=>x(),500);return()=>clearTimeout(j)}else x()},[n]),!n||!o||m?null:jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{role:"button",tabIndex:0,ref:g.setFloating,style:p,onClick:j=>{j.stopPropagation(),j.preventDefault()},onMouseEnter:j=>{j.stopPropagation(),i(null)},onKeyDown:j=>j.stopPropagation(),className:"isolate z-[999] flex h-6 items-center bg-blue-500 py-2 text-xs text-white",children:[f&&jsxRuntime.jsx(reactIcons.ArrowUpIcon,{className:"hover:scale-105",onClick:()=>{c([]),r([f])}}),jsxRuntime.jsx(BlockActionLabel,{label:h,block:o}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 pl-1 pr-1.5",children:[jsxRuntime.jsx(AddBlockDropdown,{block:o,children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:"hover:scale-105"})}),canDuplicateBlock(lodashEs.get(o,"_type",""))&&d(PERMISSIONS.ADD_BLOCK)?jsxRuntime.jsx(reactIcons.CopyIcon,{className:"hover:scale-105",onClick:()=>l([o==null?void 0:o._id])}):null,canDeleteBlock(lodashEs.get(o,"_type",""))&&d(PERMISSIONS.DELETE_BLOCK)?jsxRuntime.jsx(reactIcons.TrashIcon,{className:"hover:scale-105",onClick:()=>a([o==null?void 0:o._id])}):null,d(PERMISSIONS.MOVE_BLOCK)&&jsxRuntime.jsx(BlockController,{block:o,updateFloatingBar:x})]})]})})},IframeInitialContent=`<!doctype html>
2
2
  <html lang="en" dir="__HTML_DIR__" class="scroll-smooth h-full overflow-y-auto">
3
3
  <head>
4
4
  <meta charset="UTF-8">
@@ -58,10 +58,10 @@
58
58
  outline: 1px solid ${n.length>0?"#42a1fc":"#de8f09"} !important; outline-offset: -1px;
59
59
  }`,[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(",")}{
60
60
  outline: 1px solid #42a1fc !important; outline-offset: -1px;
61
- }`,[o]);return jsxRuntime.jsx("style",{id:"selected-blocks",dangerouslySetInnerHTML:{__html:n}})},Fonts=()=>{const[o]=useTheme(),n=runtime.useRegisteredFonts(),a=React.useMemo(()=>{const{heading:i,body:c}={heading:lodashEs.get(o,"fontFamily.heading"),body:lodashEs.get(o,"fontFamily.body")};return n.filter(d=>d.family===i||d.family===c)},[o==null?void 0:o.fontFamily,n]),l=React.useMemo(()=>plugin.getThemeFontsUrls(lodashEs.filter(a,i=>lodashEs.has(i,"url"))),[a]),r=React.useMemo(()=>plugin.getThemeCustomFontFace(lodashEs.filter(a,i=>lodashEs.has(i,"src"))),[a]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[l.map((i,c)=>jsxRuntime.jsx("link",{rel:"stylesheet",href:i},`google-font-${c}`)),jsxRuntime.jsx("style",{id:"chai-custom-fonts",dangerouslySetInnerHTML:{__html:r}})]})},ResizableCanvasWrapper=({children:o,onMount:n,onResize:a})=>{const[,l]=useSelectedBlockIds(),[,r]=useSelectedStylingBlocks(),i=React.useRef(null),c=web.useDebouncedCallback(()=>{const{clientWidth:m}=i.current;a(m)},[i.current],100);web.useResizeObserver(i.current,c,i.current!==null),React.useEffect(()=>{const{clientWidth:m}=i.current;n(m)},[]);const d=React.useCallback(()=>{l([]),r([])},[l,r]);return jsxRuntime.jsx("div",{id:"main-content",onClick:d,className:"h-full w-full p-8 pb-0",ref:i,children:o})},MayBeAsyncPropsWrapper=({children:o,block:n})=>{const a=React.useMemo(()=>runtime.getRegisteredChaiBlock(n._type),[n._type]),l=lodashEs.get(a,"dataProviderDependencies"),r=lodashEs.get(a,"dataProvider"),i=lodashEs.get(a,"dataProviderMode","mock"),c=useAsyncProps(n,i,l,r);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((l,[r,i])=>{const c=[];let d=lodashEs.find(o,{_id:n});for(;d;)c.push(d),d=lodashEs.find(o,{_id:d._parent});const m=lodashEs.find(c,{_type:i.block});return m&&(l[r]=lodashEs.get(m,lodashEs.get(i,"prop"),null)),l},{}),[o])},BUBBLE_MENU_ICONS={bold:reactIcons.FontBoldIcon,italic:reactIcons.FontItalicIcon,underline:reactIcons.UnderlineIcon,strikethrough:reactIcons.StrikethroughIcon,code:reactIcons.CodeIcon,link:reactIcons.Link1Icon,bulletList:reactIcons.ListBulletIcon,orderedList:reactIcons.ListBulletIcon,heading1:reactIcons.HeadingIcon,heading2:reactIcons.HeadingIcon,heading3:reactIcons.HeadingIcon,quote:reactIcons.QuoteIcon,alignLeft:reactIcons.TextAlignLeftIcon,alignCenter:reactIcons.TextAlignCenterIcon,alignRight:reactIcons.TextAlignRightIcon},BubbleMenuButton=({icon:o,title:n,onClick:a,isActive:l})=>{const r=BUBBLE_MENU_ICONS[o];return jsxRuntime.jsx("button",{onClick:a,className:toggle.cn("rounded-md p-1.5 transition-colors duration-200",l?"bg-white/20":"hover:bg-white/10"),title:n,children:jsxRuntime.jsx(r,{className:"h-4 w-4"})})},BubbleMenu=({editor:o})=>{if(!o)return null;const n=()=>{const a=window.prompt("Enter URL");a&&o.chain().focus().setLink({href:a}).run()};return jsxRuntime.jsx("div",{className:"flex items-center overflow-hidden rounded-lg border border-blue-500/20 bg-blue-600 text-white shadow-lg",children:jsxRuntime.jsxs("div",{className:"flex items-center p-1",children:[jsxRuntime.jsx(BubbleMenuButton,{icon:"bold",title:"Bold",onClick:()=>o.chain().focus().toggleBold().run(),isActive:o.isActive("bold")}),jsxRuntime.jsx(BubbleMenuButton,{icon:"italic",title:"Italic",onClick:()=>o.chain().focus().toggleItalic().run(),isActive:o.isActive("italic")}),jsxRuntime.jsx(BubbleMenuButton,{icon:"underline",title:"Underline",onClick:()=>o.chain().focus().toggleUnderline().run(),isActive:o.isActive("underline")}),jsxRuntime.jsx(BubbleMenuButton,{icon:"strikethrough",title:"Strikethrough",onClick:()=>o.chain().focus().toggleStrike().run(),isActive:o.isActive("strike")}),jsxRuntime.jsx("div",{className:"mx-1 h-4 w-[1px] bg-white/20"}),jsxRuntime.jsx(BubbleMenuButton,{icon:"link",title:o.isActive("link")?"Remove link":"Add link",onClick:()=>{o.isActive("link")?o.chain().focus().unsetLink().run():n()},isActive:o.isActive("link")}),jsxRuntime.jsx("div",{className:"mx-1 h-4 w-[1px] bg-white/20"}),jsxRuntime.jsx(BubbleMenuButton,{icon:"bulletList",title:"Bullet list",onClick:()=>o.chain().focus().toggleBulletList().run(),isActive:o.isActive("bulletList")}),jsxRuntime.jsx(BubbleMenuButton,{icon:"orderedList",title:"Numbered list",onClick:()=>o.chain().focus().toggleOrderedList().run(),isActive:o.isActive("orderedList")}),jsxRuntime.jsx("div",{className:"mx-1 h-4 w-[1px] bg-white/20"}),jsxRuntime.jsx(BubbleMenuButton,{icon:"alignLeft",title:"Align left",onClick:()=>o.chain().focus().setTextAlign("left").run(),isActive:o.isActive({textAlign:"left"})}),jsxRuntime.jsx(BubbleMenuButton,{icon:"alignCenter",title:"Align center",onClick:()=>o.chain().focus().setTextAlign("center").run(),isActive:o.isActive({textAlign:"center"})}),jsxRuntime.jsx(BubbleMenuButton,{icon:"alignRight",title:"Align right",onClick:()=>o.chain().focus().setTextAlign("right").run(),isActive:o.isActive({textAlign:"right"})})]})})},RichTextEditor=React.memo(({blockContent:o,editingElement:n,onClose:a,onChange:l,onEscape:r})=>{const{document:i}=useFrame(),c=react.useEditor({editable:!0,content:o,extensions:[StarterKit,Underline,TextAlign.configure({types:["heading","paragraph"]}),Link.configure({openOnClick:!1,HTMLAttributes:{class:"text-blue-500 hover:text-blue-600 underline"}}),Placeholder.configure({placeholder:"Enter text here",emptyEditorClass:"cursor-text before:content-[attr(data-placeholder)] before:absolute before:opacity-50 before:pointer-events-none"})],onUpdate:({editor:u})=>l((u==null?void 0:u.getHTML())||""),onBlur:({editor:u,event:p})=>{const g=p.relatedTarget,x=i.querySelector(".ProseMirror"),f=i.querySelector(".tippy-box"),h=x==null?void 0:x.contains(g),j=f==null?void 0:f.contains(g);if(!h&&!j){const b=(u==null?void 0:u.getHTML())||"";a(b)}}},[]);React.useEffect(()=>{var u;(u=c==null?void 0:c.commands)==null||u.focus(),c==null||c.emit("focus",{editor:c,event:new FocusEvent("focus"),transaction:[]})},[c]);const d=React.useMemo(()=>{var g;const u="max-w-none shadow-none outline outline-[2px] outline-green-500 [&_*]:shadow-none";if(!n)return u;const p=((g=n==null?void 0:n.className)==null?void 0:g.replace("sr-only",""))||"";return`${u} ${p}`},[n]),m=React.useCallback(u=>{u.key==="Escape"&&r(u)},[r]);return jsxRuntime.jsxs("div",{onKeyDown:m,onClick:u=>u.stopPropagation(),children:[c&&jsxRuntime.jsx(react.BubbleMenu,{editor:c,tippyOptions:{duration:100},children:jsxRuntime.jsx(BubbleMenu,{editor:c})}),jsxRuntime.jsx(react.EditorContent,{editor:c,className:d})]})}),MemoizedEditor=React.memo(({editingElement:o,blockContent:n,onClose:a,editorRef:l,onChange:r,onEscape:i})=>{const{document:c,window:d}=useFrame();React.useEffect(()=>{if(l.current){l.current.innerText=n,l.current.focus();const x=c.createRange(),f=d.getSelection();x.selectNodeContents(l.current),x.collapse(!1),f==null||f.removeAllRanges(),f==null||f.addRange(x),l.current.focus()}else a()},[c,d]);const m=React.useMemo(()=>{var f;const x=((f=o==null?void 0:o.tagName)==null?void 0:f.toLowerCase())||"div";return x==="button"?"div":x},[o]),u=React.useCallback(x=>{(x.key==="Enter"||x.key==="Escape")&&i(x)},[i]),p=React.useCallback(()=>{a()},[a]),g=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:f=>{const h=f.target;h&&(h.innerText.trim()===""?(h.setAttribute("data-placeholder","Enter text here"),h.children.length>0&&h.children[0].remove()):f.target.removeAttribute("data-placeholder"),r(f.target.innerText))},onClick:f=>{f.stopPropagation(),f.preventDefault()}}},[o==null?void 0:o.className,o==null?void 0:o.style]);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:React.createElement(m,{ref:l,onBlur:p,onKeyDown:u,...g})})}),WithBlockTextEditor=React.memo(({block:o,children:n})=>{const a="content",{document:l}=useFrame(),{editingBlockId:r,editingItemIndex:i,setEditingBlockId:c,setEditingItemIndex:d}=useInlineEditing(),[m,u]=React.useState(null),p=React.useRef(null),{clearHighlight:g}=useBlockHighlight(),x=useUpdateBlocksProps(),{selectedLang:f}=useLanguages(),[,h]=useSelectedBlockIds(),j=React.useRef(null),b=r,{blockContent:C,blockType:B}=React.useMemo(()=>{var v;const E=o._type;let A=o[a];const R=runtime.getRegisteredChaiBlock(o._type);return f&&((v=R==null?void 0:R.i18nProps)==null?void 0:v.includes(a))&&lodashEs.has(o,`${a}-${f}`)&&(A=lodashEs.get(o,`${a}-${f}`)),{blockContent:A,blockType:E}},[o,f]),w=React.useCallback(E=>{var R;const A=E||((R=p.current)==null?void 0:R.innerText);x([b],{[a]:A}),u(null),c(null),d(-1),h(b?[b]:[])},[b,x,c,h,f]),_=web.useDebouncedCallback(E=>{x([b],{[a]:E})},[b,o,x,f],1e3),S=React.useCallback(E=>{E.preventDefault(),b&&(j.current=b),w(),setTimeout(()=>{const A=j.current;j.current=null,h([A])},100)},[h,b,f]);React.useEffect(()=>{var k;if(!b)return;const E=`[data-block-id="${b}"]`,A=i>=0?`[data-block-index="${i}"]`:"",R=l.querySelector(`${E}${A}`);R&&((k=R==null?void 0:R.classList)==null||k.add("sr-only"),u(R))},[b,B,l,i]);const y=React.useMemo(()=>m?(g(),B==="RichText"?jsxRuntime.jsx(RichTextEditor,{blockContent:C,editingElement:m,onChange:_,onClose:w,onEscape:S}):jsxRuntime.jsx(MemoizedEditor,{editorRef:p,blockContent:C,editingElement:m,onClose:w,onChange:_,onEscape:S})):null,[m,b,B,C,w,f]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[y,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:l,editingItemIndex:r}=useInlineEditing(),[i]=jotai.useAtom(n),c=React.useMemo(()=>runtime.getRegisteredChaiBlock(i._type),[i._type]),{selectedLang:d,fallbackLang:m}=useLanguages(),u=useBlockRuntimeProps(),p=usePageExternalData(),[g]=useHiddenBlockIds(),[x]=jotai.useAtom(dataBindingActiveAtom),f=lodashEs.get(c,"component",null),{index:h,key:j}=React.useContext(RepeaterContext),b=React.useMemo(()=>x?applyBinding.applyBindingToBlockProps(applyBinding.applyLanguage(i,d,c),p,{index:h,key:j}):applyBinding.applyLanguage(i,d,c),[i,d,c,p,x,h,j]),C=React.useMemo(()=>applyBinding.getBlockTagAttributes(i),[i,applyBinding.getBlockTagAttributes]),B=React.useMemo(()=>u(i._id,applyBinding.getBlockRuntimeProps(i._type)),[i._id,i._type,u,applyBinding.getBlockRuntimeProps]),w=React.useMemo(()=>({blockProps:{"data-block-id":i._id,"data-block-type":i._type,"data-block-index":h},inBuilder:!0,lang:d||m,...b,...C,...B,...o}),[i._id,i._type,d,m,b,C,B,o]),_=React.useMemo(()=>!CORE_BLOCKS.includes(i._type),[i._type]);if(lodashEs.isNull(f)||g.includes(i._id))return null;let S=jsxRuntime.jsx(React.Suspense,{children:React.createElement(f,{...w,children:a({_id:i._id,_type:i._type,...lodashEs.isArray(b.repeaterItems)?{repeaterItems:applyBinding.applyLimit(b.repeaterItems,i),$repeaterItemsKey:b.$repeaterItemsKey}:{},...i.partialBlockId?{partialBlockId:i.partialBlockId}:"",...i.globalBlock?{partialBlockId:i.globalBlock}:""})})});const y=l===i._id&&(r===h||h<0)?jsxRuntime.jsx(WithBlockTextEditor,{block:i,children:S}):S;return _?jsxRuntime.jsx(reactErrorBoundary.ErrorBoundary,{fallbackRender:ErrorFallback,children:y}):y},PartialWrapper=({children:o,partialBlockId:n})=>{const a=useBuilderProp("gotoPage",lodashEs.noop),{saveState:l}=useSavePage(),{selectedLang:r,fallbackLang:i}=useLanguages(),c=React.useCallback(d=>{if(d.stopPropagation(),l!=="SAVED"){sonner.toast.error("You have unsaved changes. Please save the page first.");return}a({pageId:n,lang:r||i})},[l,a,n,r,i]);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]),l=React.useMemo(()=>utils.splitAtom(jotai.atom(a)),[a]);return lodashEs.isEmpty(a)?null:jsxRuntime.jsx(PartialWrapper,{partialBlockId:o,children:jsxRuntime.jsx(BlocksRenderer,{splitAtoms:l,blocks:a})})},BlocksRenderer=({blocks:o,parent:n=null,splitAtoms:a=void 0})=>{const l=useGetBlockAtom(a),r=React.useMemo(()=>lodashEs.filter(o,c=>lodashEs.has(c,"_id")&&(lodashEs.isEmpty(n)?!c._parent:c._parent===n)),[o,n]),i=React.useCallback(c=>lodashEs.filter(o,d=>d._parent===c).length>0,[o]);return lodashEs.map(r,c=>{const d=l(c._id);return d?jsxRuntime.jsx(MayBeAsyncPropsWrapper,{block:c,children:m=>jsxRuntime.jsx(BlockRenderer,{blockAtom:d,asyncProps:m,children:({_id:u,_type:p,partialBlockId:g,repeaterItems:x,$repeaterItemsKey:f})=>p==="Repeater"?lodashEs.isArray(x)&&x.map((h,j)=>jsxRuntime.jsx(RepeaterContext.Provider,{value:{index:j,key:f},children:jsxRuntime.jsx(BlocksRenderer,{splitAtoms:a,blocks:o,parent:c._id})},`${u}-${j}`)):p==="GlobalBlock"||p==="PartialBlock"?jsxRuntime.jsx(jotai.Provider,{store:builderStore,children:jsxRuntime.jsx(PartialBlocksRenderer,{partialBlockId:g})}):i(u)?jsxRuntime.jsx(BlocksRenderer,{splitAtoms:a,blocks:o,parent:c._id}):null})},c._id):null})},PageBlocksRenderer=()=>{const[o]=useBlocksStore();return jsxRuntime.jsx(BlocksRenderer,{splitAtoms:pageBlocksAtomsAtom,blocks:o})},StaticBlocksRenderer=()=>{const[o]=useBlocksStore(),n=lodashEs.isEmpty(o)?null:jsxRuntime.jsx(PageBlocksRenderer,{});return jsxRuntime.jsx(jsxRuntime.Fragment,{children:n})},useCanvasScale=o=>{const[n]=useCanvasDisplayWidth(),[,a]=useCanvasZoom(),l=useBuilderProp("htmlDir","ltr"),[r,i]=React.useState({}),c=React.useCallback(()=>{const{width:d,height:m}=o;if(d<n){const u=parseFloat((d/n).toFixed(2).toString());let p={};const g=m*u,x=d*u;m&&(p={height:100+(m-g)/g*100+"%",width:100+(d-x)/x*100+"%"}),i({position:"relative",top:0,transform:`scale(${u})`,transformOrigin:l==="rtl"?"top right":"top left",...p,maxWidth:"none"}),a(u*100)}else i({}),a(100)},[n,o,l,a]);return React.useEffect(()=>{c()},[n,o,a,c]),r};function usePubSub(o,n){React.useEffect(()=>{const a=pubsub.subscribe(o,n);return()=>a()},[o,n])}const CanvasEventsWatcher=()=>{const[,o]=useSelectedBlockIds(),[n,a]=useSelectedStylingBlocks(),{document:l}=useFrame(),{clearHighlight:r}=useBlockHighlight(),[i]=useSelectedBlockIds(),[c]=jotai.useAtom(treeRefAtom);return React.useEffect(()=>{setTimeout(()=>{if(!lodashEs.isEmpty(n))return;const d=getElementByDataBlockId(l,lodashEs.first(i));if(d){const m=d.getAttribute("data-style-prop");if(m){const u=d.getAttribute("data-style-id"),p=d.getAttribute("data-block-parent");a([{id:u,prop:m,blockId:p}])}}},100)},[l,i,a,n]),React.useEffect(()=>()=>r(),[r]),usePubSub(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_SELECTED,d=>{d&&(!lodashEs.isEmpty(d)&&!lodashEs.includes(i,lodashEs.first(d))&&(c==null||c.closeAll()),o(d))}),usePubSub(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_STYLE_SELECTED,d=>{if(!d)return;const{blockId:m,styleId:u,styleProp:p}=d;m&&(lodashEs.includes(i,m)||c==null||c.closeAll(),a([{id:u,prop:p,blockId:m}]),o([m]))}),usePubSub(CHAI_BUILDER_EVENTS.CLEAR_CANVAS_SELECTION,()=>{r(),o([]),a([])}),null},StaticCanvas=()=>{const[o]=useCanvasDisplayWidth(),[,n]=useHighlightBlockId(),a=React.useRef(null),l=React.useRef(null),[r,i]=React.useState({width:0,height:0}),c=useCanvasScale(r),[,d]=jotai.useAtom(canvasIframeAtom),m=useBuilderProp("loading",!1),u=useBuilderProp("htmlDir","ltr"),p=React.useCallback(x=>{i(f=>({...f,width:x}))},[i]);React.useEffect(()=>{if(!l.current)return;const{clientWidth:x,clientHeight:f}=l.current;i({width:x,height:f})},[l,o]);const g=React.useMemo(()=>{let x=IframeInitialContent;return x=x.replace("__HTML_DIR__",u),x},[u]);return jsxRuntime.jsx(ResizableCanvasWrapper,{onMount:p,onResize:p,children:jsxRuntime.jsx("div",{onMouseLeave:()=>setTimeout(()=>n(""),300),className:"relative mx-auto h-full w-full overflow-hidden",ref:l,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:g,children:[jsxRuntime.jsx(KeyboardHandler,{}),jsxRuntime.jsx(BlockSelectionHighlighter,{}),jsxRuntime.jsx(HeadTags,{}),jsxRuntime.jsxs(reactWrapBalancer.Provider,{children:[jsxRuntime.jsxs(Canvas,{children:[m?jsxRuntime.jsx("div",{className:"h-full p-4",children:jsxRuntime.jsx(toggle.Skeleton,{className:"h-full"})}):jsxRuntime.jsx(StaticBlocksRenderer,{}),jsxRuntime.jsx(AddBlockAtBottom,{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]}),jsxRuntime.jsx(CanvasEventsWatcher,{})]}),jsxRuntime.jsx("div",{id:"placeholder",className:"pointer-events-none absolute z-[99999] max-w-full bg-green-500 transition-transform"})]})})})},FallbackError=()=>jsxRuntime.jsx("div",{className:"h-full w-full rounded-md bg-red-200 p-4 text-red-500",children:jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center",children:[jsxRuntime.jsx("p",{className:"font-semibold",children:"Oops! Something went wrong."}),jsxRuntime.jsx("p",{children:"Please try again."})]})}),CodeEditor$1=React.lazy(()=>Promise.resolve().then(()=>require("./code-editor-67qfXwGU.cjs"))),CanvasArea=()=>{const[o]=useCodeEditor(),n=useBuilderProp("onError",lodashEs.noop);return jsxRuntime.jsx("div",{className:"flex h-full max-h-full w-full flex-1 flex-col",children:jsxRuntime.jsxs("div",{className:"relative flex h-full max-h-full flex-col overflow-hidden bg-gray-100/40 px-2",children:[jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx(toggle.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(toggle.Skeleton,{className:"h-full"}),children:jsxRuntime.jsx(reResizable.Resizable,{enable:{top:!0,bottom:!1},className:"max-h-[400px] min-h-[200px]",children:jsxRuntime.jsx(CodeEditor$1,{})})}):null,jsxRuntime.jsx(Breadcrumb,{})]})})},RJSF_EXTENSIONS={},registerBlockSettingWidget=(o,n)=>{RJSF_EXTENSIONS[o]={id:o,component:n,type:"widget"}},registerBlockSettingField=(o,n)=>{RJSF_EXTENSIONS[o]={id:o,component:n,type:"field"}},registerBlockSettingTemplate=(o,n)=>{RJSF_EXTENSIONS[o]={id:o,component:n,type:"template"}},useBlockSettingComponents=o=>Object.values(RJSF_EXTENSIONS).filter(n=>n.type===o).reduce((n,a)=>(n[a.id]=a.component,n),{}),removeSizeAttributes=o=>{try{return o.replace(/<svg([^>]*)\sheight="[^"]*"([^>]*)>/gi,"<svg$1$2>").replace(/<svg([^>]*)\swidth="[^"]*"([^>]*)>/gi,"<svg$1$2>")}catch{return o}},IconPickerField=({value:o,onChange:n,id:a})=>{const{t:l}=reactI18next.useTranslation(),[r,i]=React.useState(o||"");React.useEffect(()=>{i(o||"")},[o]);const c=d=>{i(d);const m=removeSizeAttributes(d);n(m)};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:r?jsxRuntime.jsx("div",{className:"h-6 w-6",dangerouslySetInnerHTML:{__html:r}}):jsxRuntime.jsx("span",{className:"text-xs text-gray-400",children:"SVG"})}),jsxRuntime.jsx("textarea",{id:a,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",value:r,onChange:d=>c(d.target.value),placeholder:l("Enter SVG code here"),rows:2,className:"no-scrollbar w-full rounded-md border border-border bg-background px-3 py-1.5 text-xs shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"})]}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:l("Paste SVG code to use as an icon")})]})},DefaultMediaManager=({close:o,onSelect:n,mode:a="image"})=>{const[l,r]=React.useState(""),[i,c]=React.useState(!1),[d,m]=React.useState(!1),[u,p]=React.useState(null),g=async f=>{if(!f.trim()){m(!1),p("Please enter a URL");return}try{c(!0),p(null),m(!0),p(null)}catch{m(!1),p("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(toggle.Alert,{variant:"destructive",children:[jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-4 w-4"}),jsxRuntime.jsx(toggle.AlertDescription,{children:u})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-4",children:[jsxRuntime.jsx(toggle.Input,{placeholder:x(`Enter ${a} URL`),value:l,onChange:f=>r(f.target.value),onKeyUp:()=>g(l)}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-2",children:[jsxRuntime.jsx(toggle.Button,{variant:"outline",onClick:o,children:x("Cancel")}),jsxRuntime.jsx(toggle.Button,{onClick:()=>n({id:"dam-id",url:l,width:600,height:400,description:"This is image description"}),disabled:!d||i,children:x("Insert")})]})]})]})},MEDIA_MANAGER={component:DefaultMediaManager},registerChaiMediaManager=o=>{MEDIA_MANAGER.component=o},useMediaManagerComponent=()=>React.useMemo(()=>MEDIA_MANAGER.component,[]),MediaManagerModal=({assetId:o,children:n,onSelect:a,mode:l="image"})=>{const[r,i]=React.useState(!1),c=useMediaManagerComponent(),d=(...m)=>{a.call(void 0,...m),i(!1)};return jsxRuntime.jsxs(toggle.Dialog,{open:r,onOpenChange:m=>i(m),children:[jsxRuntime.jsx(toggle.DialogTrigger,{asChild:!0,children:n}),jsxRuntime.jsxs(toggle.DialogContent,{className:"flex max-h-[90vh] max-w-7xl border-border md:w-fit",children:[jsxRuntime.jsx(toggle.DialogTitle,{className:"sr-only",children:"Media Manager"}),jsxRuntime.jsx("div",{className:"h-full w-full",children:c?jsxRuntime.jsx(c,{close:()=>i(!1),onSelect:d,mode:l,assetId:o}):null})]})]})};MediaManagerModal.displayName="MediaManagerModal";const PLACEHOLDER_IMAGE="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTAwIiBoZWlnaHQ9IjQwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZjNmNGY2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCwgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNiIgZmlsbD0iI2Q1ZDdkYSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPkltYWdlIFBsYWNlaG9sZGVyPC90ZXh0Pjwvc3ZnPg==",ImagePickerField=({value:o,onChange:n,id:a,onBlur:l})=>{const{t:r}=reactI18next.useTranslation(),{selectedLang:i}=useLanguages(),c=useSelectedBlock(),d=useUpdateBlocksProps(),m=a.split(".").pop()||"",u=i?`_${m}Id-${i}`:`_${m}Id`,p=lodashEs.isEmpty(i)&&(c==null?void 0:c._type)==="Image"&&lodashEs.has(c,"assetId"),g=lodashEs.get(c,u,p?c==null?void 0:c.assetId:""),x=!!g,f=j=>{const b=lodashEs.isArray(j)?lodashEs.first(j):j;if(b){n(b==null?void 0:b.url);const C=b==null?void 0:b.width,B=b==null?void 0:b.height;if(c!=null&&c._id){const w={...C&&{width:C},...B&&{height:B},...b.description&&{alt:b.description}};if(lodashEs.set(w,u,b.id),lodashEs.isEmpty(w))return;d([c._id],w)}}},h=React.useCallback(()=>{n(PLACEHOLDER_IMAGE),c!=null&&c._id&&d([c._id],{assetId:""})},[n,c==null?void 0:c._id,d]);return jsxRuntime.jsxs("div",{className:"mt-1.5 flex items-center gap-x-3",children:[o?jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsx("img",{src:o,className:"h-20 w-20 overflow-hidden rounded-md border border-border object-cover transition duration-200 "+(g&&g!==""?"cursor-pointer group-hover:blur-sm":""),alt:""}),x&&jsxRuntime.jsx("button",{type:"button",onClick:h,className:"absolute -right-2 -top-2 z-20 rounded-full bg-destructive p-1 text-destructive-foreground hover:bg-destructive/90",children:jsxRuntime.jsx(lucideReact.X,{className:"h-3 w-3"})}),g&&g!==""&&jsxRuntime.jsx(MediaManagerModal,{onSelect:f,assetId:g,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(lucideReact.Edit2Icon,{className:"h-4 w-4 text-white"})})})]}):jsxRuntime.jsx(MediaManagerModal,{onSelect:f,mode:"image",assetId:g,children:jsxRuntime.jsx("div",{className:"h-20 w-20 cursor-pointer rounded-md border border-border bg-[radial-gradient(#AAA,transparent_1px)] duration-300 [background-size:10px_10px]"})}),jsxRuntime.jsxs("div",{className:"flex w-3/5 flex-col",children:[jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(MediaManagerModal,{onSelect:f,assetId:"",children:jsxRuntime.jsx("small",{className:"h-6 cursor-pointer rounded-md bg-secondary px-2 py-1 text-center text-xs text-secondary-foreground hover:bg-secondary/80",children:o||!lodashEs.isEmpty(o)?r("Replace image"):r("Choose image")})}),jsxRuntime.jsx("small",{className:"-pl-4 pt-2 text-center text-xs text-secondary-foreground",children:"OR"})]}),jsxRuntime.jsx("input",{id:a,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",type:"url",className:"text-xs",placeholder:r("Enter image URL"),value:o,onBlur:({target:{value:j}})=>l(a,j),onChange:j=>n(j.target.value)})]})]})},PathDropdown=({data:o,onSelect:n,dataType:a})=>{const[l,r]=React.useState([]),[i,c]=React.useState(o),d=g=>Array.isArray(g)?"array":typeof g=="object"&&g!==null?"object":"value",m=React.useCallback(g=>{const x=f=>a==="value"?f==="value"||f==="object":a==="array"?f==="array":f===a;g.type==="object"?(r(f=>[...f,g.key]),c(g.value)):x(g.type)&&n([...l,g.key].join("."),a)},[l,n,a]),u=React.useCallback(()=>{if(l.length>0){const g=l.slice(0,-1);r(g),c(g.reduce((x,f)=>x[f],o))}},[l,o]),p=React.useMemo(()=>i?Object.entries(i).map(([g,x])=>({key:g,value:x,type:d(x)})).filter(g=>!lodashEs.startsWith(g.key,applyBinding.REPEATER_PREFIX)&&g.key.includes("/")?!1:a==="value"?g.type==="value"||g.type==="object":a==="array"?g.type==="array"||g.type==="object":a==="object"?g.type==="object":!0):[],[i,a]);return jsxRuntime.jsxs(toggle.Command,{className:"fields-command",children:[jsxRuntime.jsx(toggle.CommandInput,{className:"border-none",placeholder:"Search..."}),jsxRuntime.jsxs(toggle.CommandList,{children:[jsxRuntime.jsx(toggle.CommandEmpty,{children:"No option found."}),jsxRuntime.jsxs(toggle.CommandGroup,{children:[l.length>0&&jsxRuntime.jsxs(toggle.CommandItem,{onSelect:u,className:"flex items-center text-sm",children:[jsxRuntime.jsx(lucideReact.ChevronLeft,{className:"mr-2 h-4 w-4"}),"Back"]}),p.map(g=>jsxRuntime.jsxs(toggle.CommandItem,{value:g.key,disabled:!1,onSelect:()=>m(g),className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"flex items-center gap-x-2",children:[lodashEs.startsWith(g.key,applyBinding.REPEATER_PREFIX)?jsxRuntime.jsx(reactIcons.LoopIcon,{}):lodashEs.startsWith(g.key,applyBinding.COLLECTION_PREFIX)?jsxRuntime.jsx(lucideReact.DatabaseIcon,{}):null,lodashEs.startsWith(g.key,applyBinding.REPEATER_PREFIX)?"Repeater Data":lodashEs.startsWith(g.key,applyBinding.COLLECTION_PREFIX)?g.key.replace(applyBinding.COLLECTION_PREFIX,""):g.key]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[a==="object"&&g.type==="object"&&jsxRuntime.jsx(toggle.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 hover:bg-primary hover:text-primary-foreground",onClick:x=>{x.stopPropagation(),n([...l,g.key].join("."),a)},children:"Select"}),g.type==="object"&&jsxRuntime.jsx("div",{className:"cursor-pointer rounded p-1 hover:bg-muted",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4 opacity-50"})})]})]},g.key))]})]})]})};function NestedPathSelector({data:o,onSelect:n,dataType:a="value"}){const[l,r]=React.useState(!1),i=useBuilderProp("collections",[]),c=React.useMemo(()=>a==="array"?{...i.map(m=>m.id).reduce((m,u)=>({...m,[applyBinding.COLLECTION_PREFIX+u]:[]}),{}),...o}:o,[o,i,a]);return jsxRuntime.jsxs(toggle.Popover,{open:l,onOpenChange:r,children:[jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.PopoverTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{size:"sm",variant:"outline",className:"h-5 rounded-sm px-1 py-0 text-[9px] text-muted-foreground",role:"combobox","aria-expanded":l,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(toggle.TooltipContent,{children:"Add field"})]}),jsxRuntime.jsx(toggle.PopoverContent,{className:"z-[1000]! relative mr-3 w-[300px] p-0",children:jsxRuntime.jsx(PathDropdown,{data:c,onSelect:(d,m)=>{n(d,m),r(!1)},dataType:a})})]})}const DataBindingSelector=({schema:o,onChange:n,id:a,formData:l})=>{const r=usePageExternalData(),i=useSelectedBlockHierarchy(),c=useSelectedBlock(),d=React.useMemo(()=>{if(i.length===1)return"";const p=i.find(f=>f._type==="Repeater"),x=lodashEs.get(p,"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1");return`${applyBinding.REPEATER_PREFIX}${lodashEs.startsWith(x,applyBinding.COLLECTION_PREFIX)?`${x}/${p._id}`:x}`},[i]),m=React.useMemo(()=>lodashEs.first(lodashEs.get(r,d.replace(applyBinding.REPEATER_PREFIX,""),[])),[d,r]),u=React.useCallback((p,g)=>{if(p=lodashEs.isEmpty(d)?p:p.replace(`${d}`,"$index"),g==="array"||g==="object"){n(`{{${p}}}`,{},a);return}const x=b=>/[.,!?;:]/.test(b),f=(b,C,B)=>{let w="",_="";const S=C>0?b[C-1]:"",y=C<b.length?b[C]:"";return C>0&&(S==="."||!x(S)&&S!==" ")&&(w=" "),C<b.length&&!x(y)&&y!==" "&&(_=" "),{text:w+B+_,prefixLength:w.length,suffixLength:_.length}},h=document.getElementById(a);if(!h)return;const j=document.getElementById(`chai-rte-${a}`)||document.getElementById(`chai-rte-modal-${a}`);if(j&&(j.querySelector(".ProseMirror")||j.__chaiRTE)){const b=j.__chaiRTE;if(b){const C=`{{${p}}}`;b.commands.focus();const{from:B,to:w}=b.state.selection;if(B!==w)b.chain().deleteSelection().insertContent(C).run();else{const{state:S}=b,y=S.selection.from,E=S.doc.textBetween(Math.max(0,y-1),y),A=S.doc.textBetween(y,Math.min(y+1,S.doc.content.size));let R="";y>0&&E!==" "&&!x(E)&&(R=" ");let k="";A&&A!==" "&&!x(A)&&(k=" "),b.chain().insertContent(R+C+k).run()}setTimeout(()=>n(b.getHTML(),{},a),100);return}}else{const b=h,C=b.selectionStart||0,B=b.value||"",w=b.selectionEnd||C;if(w>C){const A=`{{${p}}}`,{text:R}=f(B,C,A),k=B.slice(0,C)+R+B.slice(w);n(k,{},a);return}const S=`{{${p}}}`,{text:y}=f(B,C,S),E=B.slice(0,C)+y+B.slice(C);n(E,{},a)}},[a,n,l,c==null?void 0:c._id,d]);return jsxRuntime.jsx(NestedPathSelector,{data:{...m&&{[d]:m},...r},onSelect:u,dataType:o.binding==="array"?"array":"value"})},PageTypeField=({href:o,pageTypes:n,onChange:a})=>{var A;const{t:l}=reactI18next.useTranslation(),r=useBuilderProp("searchPageTypeItems",(R,k)=>[]),[i,c]=React.useState(!1),[d,m]=React.useState(!1),[u,p]=React.useState("page"),[g,x]=React.useState(""),[f,h]=React.useState([]),[j,b]=React.useState(-1),C=React.useRef(null),B=(A=n==null?void 0:n.find(R=>R.key===u))==null?void 0:A.name;React.useEffect(()=>{if(x(""),h([]),b(-1),m(!1),!o||i||!lodashEs.startsWith(o,"pageType:"))return;const R=lodashEs.split(o,":"),k=lodashEs.get(R,1,"page")||"page";p(k),(async()=>{const v=await r(k,[lodashEs.get(R,2,"page")]);v&&Array.isArray(v)&&x(lodashEs.get(v,[0,"name"],""))})()},[o]);const w=web.useDebouncedCallback(async R=>{if(lodashEs.isEmpty(R))h([]);else{const k=await r(u,R);h(k)}c(!1),b(-1)},[u],300),_=R=>{const k=["pageType",u,R.id];k[1]&&(a(k.join(":")),x(R.name),m(!1),h([]),b(-1))},S=R=>{switch(R.key){case"ArrowDown":R.preventDefault(),b(k=>k<f.length-1?k+1:k);break;case"ArrowUp":R.preventDefault(),b(k=>k>0?k-1:k);break;case"Enter":if(R.preventDefault(),f.length===0)return;j>=0&&_(f[j]);break;case"Escape":R.preventDefault(),y();break}};React.useEffect(()=>{if(j>=0&&C.current){const R=C.current.children[j];R==null||R.scrollIntoView({block:"nearest"})}},[j]);const y=()=>{x(""),h([]),b(-1),m(!1),a("")},E=R=>{x(R),m(!lodashEs.isEmpty(R)),c(!0),w(R)};return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("select",{name:"pageType",value:u,onChange:R=>p(R.target.value),children:lodashEs.map(n,R=>jsxRuntime.jsx("option",{value:R.key,children:R.name},R.key))}),u&&jsxRuntime.jsxs("div",{className:"group relative mt-2 flex items-center",children:[jsxRuntime.jsx("input",{type:"text",value:g,onChange:R=>E(R.target.value),onKeyDown:S,placeholder:l(`Search ${B??""}`),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:g&&jsxRuntime.jsx("button",{onClick:y,className:"text-gray-400 hover:text-gray-600",title:l("Clear search"),children:jsxRuntime.jsx(lucideReact.X,{className:"h-4 w-4"})})})]}),(i||!lodashEs.isEmpty(f)||d&&lodashEs.isEmpty(f))&&jsxRuntime.jsx("div",{className:"absolute z-40 mt-2 max-h-40 w-full max-w-[250px] overflow-y-auto rounded-md border border-border bg-background shadow-lg",children:i?jsxRuntime.jsxs("div",{className:"space-y-1 p-2",children:[jsxRuntime.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),jsxRuntime.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):d&&lodashEs.isEmpty(f)?jsxRuntime.jsxs("div",{className:"flex items-center justify-center p-4 text-sm text-gray-500",children:[l("No results found for"),' "',g,'"']}):jsxRuntime.jsx("ul",{ref:C,children:lodashEs.map(f==null?void 0:f.slice(0,20),(R,k)=>jsxRuntime.jsxs("li",{onClick:()=>_(R),className:`cursor-pointer p-2 text-xs ${o!=null&&o.includes(R.id)?"bg-blue-200":k===j?"bg-gray-100":"hover:bg-gray-100"}`,children:[R.name," ",R.slug&&jsxRuntime.jsxs("small",{className:"font-light text-gray-500",children:["( ",R.slug," )"]})]},R.id))})})]})},LinkField=({schema:o,formData:n,onChange:a,name:l})=>{const{t:r}=reactI18next.useTranslation(),{type:i="pageType",href:c="",target:d="self"}=n,m=useBuilderProp("pageTypes",[]),u=i==="pageType"&&lodashEs.isEmpty(m)?"url":i;return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"flex items-center justify-between gap-x-2 text-xs font-medium",children:[(o==null?void 0:o.title)??"Link",jsxRuntime.jsx(DataBindingSelector,{schema:o,onChange:p=>{console.log("value",n,p),a({...n,href:p,...u==="pageType"?{type:"url"}:{}})},id:`root.${l}.href`,formData:n})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxRuntime.jsx("select",{name:"type",value:i,onChange:p=>a({...n,type:p.target.value}),children:lodashEs.map([...lodashEs.isEmpty(m)?[]:[{const:"pageType",title:r("Goto Page")}],{const:"url",title:r("Open URL")},{const:"email",title:r("Compose Email")},{const:"telephone",title:r("Call Phone")},{const:"scroll",title:r("Scroll to element")}],p=>jsxRuntime.jsx("option",{value:p.const,children:p.title},p.const))}),u==="pageType"&&!lodashEs.isEmpty(m)?jsxRuntime.jsx(PageTypeField,{href:c,pageTypes:m,onChange:p=>a({...n,href:p})}):null,jsxRuntime.jsx("input",{id:`root.${l}.href`,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",name:"href",type:"text",className:u==="pageType"?"!hidden":"",value:c,onChange:p=>a({...n,href:p.target.value}),placeholder:r(i==="url"?"Enter URL":i==="scroll"?"#ElementID":"Enter details")}),u==="url"&&jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 text-muted-foreground",children:[jsxRuntime.jsx("input",{id:`root.${l}.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:r("Open in new tab")})]})]})]})},RowColField=()=>{const o=useSelectedBlock(),n=useWrapperBlock(),{addCoreBlock:a}=useAddBlock();if(!o&&!n)return null;const l=(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:,"},l==null?void 0:l._id),children:[jsxRuntime.jsx(lucideReact.Plus,{className:"h-4 w-4"})," Add Column"]})})};function cn(...o){return tailwindMerge.twMerge(clsx.clsx(o))}const MenuBar=({editor:o,onExpand:n})=>{if(!o)return null;const a=()=>{const r=window.prompt("URL");r&&o.chain().focus().extendMarkRange("link").setLink({href:r}).run()},l=()=>{o.chain().focus().unsetLink().run()};return jsxRuntime.jsxs("div",{className:"mb-1 flex flex-wrap gap-1 rounded-md border border-border p-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleBold().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("bold")}),title:"Bold",children:jsxRuntime.jsx(lucideReact.Bold,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleItalic().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("italic")}),title:"Italic",children:jsxRuntime.jsx(lucideReact.Italic,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleUnderline().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("underline")}),title:"Underline",children:jsxRuntime.jsx(lucideReact.Underline,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleStrike().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("strike")}),title:"Strike",children:jsxRuntime.jsx(lucideReact.Strikethrough,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleBulletList().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("bulletList")}),title:"Bullet List",children:jsxRuntime.jsx(lucideReact.List,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleOrderedList().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("orderedList")}),title:"Ordered List",children:jsxRuntime.jsx(lucideReact.ListOrdered,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().setTextAlign("left").run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive({textAlign:"left"})}),title:"Align Left",children:jsxRuntime.jsx(lucideReact.AlignLeft,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().setTextAlign("center").run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive({textAlign:"center"})}),title:"Align Center",children:jsxRuntime.jsx(lucideReact.AlignCenter,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().setTextAlign("right").run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive({textAlign:"right"})}),title:"Align Right",children:jsxRuntime.jsx(lucideReact.AlignRight,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:a,className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("link")}),title:"Add Link",children:jsxRuntime.jsx(lucideReact.Link,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:l,className:cn("rounded p-1 hover:bg-muted"),title:"Remove Link",disabled:!o.isActive("link"),children:jsxRuntime.jsx(lucideReact.Unlink,{className:"h-4 w-4"})}),n&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:n,className:"rounded p-1 hover:bg-muted",title:"Open in full screen mode",children:jsxRuntime.jsx(lucideReact.Maximize2,{className:"h-4 w-4"})})]})]})},RTEModal=({isOpen:o,onClose:n,id:a,value:l,onChange:r,onBlur:i})=>{const c=React.useRef(null),d=React.useRef(l||""),m=usePageExternalData();React.useEffect(()=>{if(o){const g=document.createElement("style");return g.id="rte-modal-styles",g.innerHTML=`
61
+ }`,[o]);return jsxRuntime.jsx("style",{id:"selected-blocks",dangerouslySetInnerHTML:{__html:n}})},Fonts=()=>{const[o]=useTheme(),n=runtime.useRegisteredFonts(),a=React.useMemo(()=>{const{heading:i,body:c}={heading:lodashEs.get(o,"fontFamily.heading"),body:lodashEs.get(o,"fontFamily.body")};return n.filter(d=>d.family===i||d.family===c)},[o==null?void 0:o.fontFamily,n]),l=React.useMemo(()=>plugin.getThemeFontsUrls(lodashEs.filter(a,i=>lodashEs.has(i,"url"))),[a]),r=React.useMemo(()=>plugin.getThemeCustomFontFace(lodashEs.filter(a,i=>lodashEs.has(i,"src"))),[a]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[l.map((i,c)=>jsxRuntime.jsx("link",{rel:"stylesheet",href:i},`google-font-${c}`)),jsxRuntime.jsx("style",{id:"chai-custom-fonts",dangerouslySetInnerHTML:{__html:r}})]})},ResizableCanvasWrapper=({children:o,onMount:n,onResize:a})=>{const[,l]=useSelectedBlockIds(),[,r]=useSelectedStylingBlocks(),i=React.useRef(null),c=web.useDebouncedCallback(()=>{const{clientWidth:m}=i.current;a(m)},[i.current],100);web.useResizeObserver(i.current,c,i.current!==null),React.useEffect(()=>{const{clientWidth:m}=i.current;n(m)},[]);const d=React.useCallback(()=>{l([]),r([])},[l,r]);return jsxRuntime.jsx("div",{id:"main-content",onClick:d,className:"h-full w-full p-8 pb-0",ref:i,children:o})},MayBeAsyncPropsWrapper=({children:o,block:n})=>{const a=React.useMemo(()=>runtime.getRegisteredChaiBlock(n._type),[n._type]),l=lodashEs.get(a,"dataProviderDependencies"),r=lodashEs.get(a,"dataProvider"),i=lodashEs.get(a,"dataProviderMode","mock"),c=useAsyncProps(n,i,l,r);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((l,[r,i])=>{const c=[];let d=lodashEs.find(o,{_id:n});for(;d;)c.push(d),d=lodashEs.find(o,{_id:d._parent});const m=lodashEs.find(c,{_type:i.block});return m&&(l[r]=lodashEs.get(m,lodashEs.get(i,"prop"),null)),l},{}),[o])},BUBBLE_MENU_ICONS={bold:reactIcons.FontBoldIcon,italic:reactIcons.FontItalicIcon,underline:reactIcons.UnderlineIcon,strikethrough:reactIcons.StrikethroughIcon,code:reactIcons.CodeIcon,link:reactIcons.Link1Icon,bulletList:reactIcons.ListBulletIcon,orderedList:reactIcons.ListBulletIcon,heading1:reactIcons.HeadingIcon,heading2:reactIcons.HeadingIcon,heading3:reactIcons.HeadingIcon,quote:reactIcons.QuoteIcon,alignLeft:reactIcons.TextAlignLeftIcon,alignCenter:reactIcons.TextAlignCenterIcon,alignRight:reactIcons.TextAlignRightIcon},BubbleMenuButton=({icon:o,title:n,onClick:a,isActive:l})=>{const r=BUBBLE_MENU_ICONS[o];return jsxRuntime.jsx("button",{onClick:a,className:toggle.cn("rounded-md p-1.5 transition-colors duration-200",l?"bg-white/20":"hover:bg-white/10"),title:n,children:jsxRuntime.jsx(r,{className:"h-4 w-4"})})},BubbleMenu=({editor:o})=>{if(!o)return null;const n=()=>{const a=window.prompt("Enter URL");a&&o.chain().focus().setLink({href:a}).run()};return jsxRuntime.jsx("div",{className:"flex items-center overflow-hidden rounded-lg border border-blue-500/20 bg-blue-600 text-white shadow-lg",children:jsxRuntime.jsxs("div",{className:"flex items-center p-1",children:[jsxRuntime.jsx(BubbleMenuButton,{icon:"bold",title:"Bold",onClick:()=>o.chain().focus().toggleBold().run(),isActive:o.isActive("bold")}),jsxRuntime.jsx(BubbleMenuButton,{icon:"italic",title:"Italic",onClick:()=>o.chain().focus().toggleItalic().run(),isActive:o.isActive("italic")}),jsxRuntime.jsx(BubbleMenuButton,{icon:"underline",title:"Underline",onClick:()=>o.chain().focus().toggleUnderline().run(),isActive:o.isActive("underline")}),jsxRuntime.jsx(BubbleMenuButton,{icon:"strikethrough",title:"Strikethrough",onClick:()=>o.chain().focus().toggleStrike().run(),isActive:o.isActive("strike")}),jsxRuntime.jsx("div",{className:"mx-1 h-4 w-[1px] bg-white/20"}),jsxRuntime.jsx(BubbleMenuButton,{icon:"link",title:o.isActive("link")?"Remove link":"Add link",onClick:()=>{o.isActive("link")?o.chain().focus().unsetLink().run():n()},isActive:o.isActive("link")}),jsxRuntime.jsx("div",{className:"mx-1 h-4 w-[1px] bg-white/20"}),jsxRuntime.jsx(BubbleMenuButton,{icon:"bulletList",title:"Bullet list",onClick:()=>o.chain().focus().toggleBulletList().run(),isActive:o.isActive("bulletList")}),jsxRuntime.jsx(BubbleMenuButton,{icon:"orderedList",title:"Numbered list",onClick:()=>o.chain().focus().toggleOrderedList().run(),isActive:o.isActive("orderedList")}),jsxRuntime.jsx("div",{className:"mx-1 h-4 w-[1px] bg-white/20"}),jsxRuntime.jsx(BubbleMenuButton,{icon:"alignLeft",title:"Align left",onClick:()=>o.chain().focus().setTextAlign("left").run(),isActive:o.isActive({textAlign:"left"})}),jsxRuntime.jsx(BubbleMenuButton,{icon:"alignCenter",title:"Align center",onClick:()=>o.chain().focus().setTextAlign("center").run(),isActive:o.isActive({textAlign:"center"})}),jsxRuntime.jsx(BubbleMenuButton,{icon:"alignRight",title:"Align right",onClick:()=>o.chain().focus().setTextAlign("right").run(),isActive:o.isActive({textAlign:"right"})})]})})},RichTextEditor=React.memo(({blockContent:o,editingElement:n,onClose:a,onChange:l,onEscape:r})=>{const{document:i}=useFrame(),c=react.useEditor({editable:!0,content:o,extensions:[StarterKit,Underline,TextAlign.configure({types:["heading","paragraph"]}),Link.configure({openOnClick:!1,HTMLAttributes:{class:"text-blue-500 hover:text-blue-600 underline"}}),Placeholder.configure({placeholder:"Enter text here",emptyEditorClass:"cursor-text before:content-[attr(data-placeholder)] before:absolute before:opacity-50 before:pointer-events-none"})],onUpdate:({editor:u})=>l((u==null?void 0:u.getHTML())||""),onBlur:({editor:u,event:p})=>{const g=p.relatedTarget,x=i.querySelector(".ProseMirror"),f=i.querySelector(".tippy-box"),h=x==null?void 0:x.contains(g),j=f==null?void 0:f.contains(g);if(!h&&!j){const b=(u==null?void 0:u.getHTML())||"";a(b)}}},[]);React.useEffect(()=>{var u;(u=c==null?void 0:c.commands)==null||u.focus(),c==null||c.emit("focus",{editor:c,event:new FocusEvent("focus"),transaction:[]})},[c]);const d=React.useMemo(()=>{var g;const u="max-w-none shadow-none outline outline-[2px] outline-green-500 [&_*]:shadow-none";if(!n)return u;const p=((g=n==null?void 0:n.className)==null?void 0:g.replace("sr-only",""))||"";return`${u} ${p}`},[n]),m=React.useCallback(u=>{u.key==="Escape"&&r(u)},[r]);return jsxRuntime.jsxs("div",{onKeyDown:m,onClick:u=>u.stopPropagation(),children:[c&&jsxRuntime.jsx(react.BubbleMenu,{editor:c,tippyOptions:{duration:100},children:jsxRuntime.jsx(BubbleMenu,{editor:c})}),jsxRuntime.jsx(react.EditorContent,{editor:c,className:d})]})}),MemoizedEditor=React.memo(({editingElement:o,blockContent:n,onClose:a,editorRef:l,onChange:r,onEscape:i})=>{const{document:c,window:d}=useFrame();React.useEffect(()=>{if(l.current){l.current.innerText=n,l.current.focus();const x=c.createRange(),f=d.getSelection();x.selectNodeContents(l.current),x.collapse(!1),f==null||f.removeAllRanges(),f==null||f.addRange(x),l.current.focus()}else a()},[c,d]);const m=React.useMemo(()=>{var f;const x=((f=o==null?void 0:o.tagName)==null?void 0:f.toLowerCase())||"div";return x==="button"?"div":x},[o]),u=React.useCallback(x=>{(x.key==="Enter"||x.key==="Escape")&&i(x)},[i]),p=React.useCallback(()=>{a()},[a]),g=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:f=>{const h=f.target;h&&(h.innerText.trim()===""?(h.setAttribute("data-placeholder","Enter text here"),h.children.length>0&&h.children[0].remove()):f.target.removeAttribute("data-placeholder"),r(f.target.innerText))},onClick:f=>{f.stopPropagation(),f.preventDefault()}}},[o==null?void 0:o.className,o==null?void 0:o.style]);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:React.createElement(m,{ref:l,onBlur:p,onKeyDown:u,...g})})}),WithBlockTextEditor=React.memo(({block:o,children:n})=>{const a="content",{document:l}=useFrame(),{editingBlockId:r,editingItemIndex:i,setEditingBlockId:c,setEditingItemIndex:d}=useInlineEditing(),[m,u]=React.useState(null),p=React.useRef(null),{clearHighlight:g}=useBlockHighlight(),x=useUpdateBlocksProps(),{selectedLang:f}=useLanguages(),[,h]=useSelectedBlockIds(),j=React.useRef(null),b=r,{blockContent:C,blockType:A}=React.useMemo(()=>{var v;const E=o._type;let w=o[a];const R=runtime.getRegisteredChaiBlock(o._type);return f&&((v=R==null?void 0:R.i18nProps)==null?void 0:v.includes(a))&&lodashEs.has(o,`${a}-${f}`)&&(w=lodashEs.get(o,`${a}-${f}`)),{blockContent:w,blockType:E}},[o,f]),B=React.useCallback(E=>{var R;const w=E||((R=p.current)==null?void 0:R.innerText);x([b],{[a]:w}),u(null),c(null),d(-1),h(b?[b]:[])},[b,x,c,h,f]),_=web.useDebouncedCallback(E=>{x([b],{[a]:E})},[b,o,x,f],1e3),S=React.useCallback(E=>{E.preventDefault(),b&&(j.current=b),B(),setTimeout(()=>{const w=j.current;j.current=null,h([w])},100)},[h,b,f]);React.useEffect(()=>{var k;if(!b)return;const E=`[data-block-id="${b}"]`,w=i>=0?`[data-block-index="${i}"]`:"",R=l.querySelector(`${E}${w}`);R&&((k=R==null?void 0:R.classList)==null||k.add("sr-only"),u(R))},[b,A,l,i]);const y=React.useMemo(()=>m?(g(),A==="RichText"?jsxRuntime.jsx(RichTextEditor,{blockContent:C,editingElement:m,onChange:_,onClose:B,onEscape:S}):jsxRuntime.jsx(MemoizedEditor,{editorRef:p,blockContent:C,editingElement:m,onClose:B,onChange:_,onEscape:S})):null,[m,b,A,C,B,f]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[y,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:l,editingItemIndex:r}=useInlineEditing(),[i]=jotai.useAtom(n),c=React.useMemo(()=>runtime.getRegisteredChaiBlock(i._type),[i._type]),{selectedLang:d,fallbackLang:m}=useLanguages(),u=useBlockRuntimeProps(),p=usePageExternalData(),[g]=useHiddenBlockIds(),[x]=jotai.useAtom(dataBindingActiveAtom),f=lodashEs.get(c,"component",null),{index:h,key:j}=React.useContext(RepeaterContext),b=React.useMemo(()=>x?applyBinding.applyBindingToBlockProps(applyBinding.applyLanguage(i,d,c),p,{index:h,key:j}):applyBinding.applyLanguage(i,d,c),[i,d,c,p,x,h,j]),C=React.useMemo(()=>applyBinding.getBlockTagAttributes(i),[i,applyBinding.getBlockTagAttributes]),A=React.useMemo(()=>u(i._id,applyBinding.getBlockRuntimeProps(i._type)),[i._id,i._type,u,applyBinding.getBlockRuntimeProps]),B=React.useMemo(()=>({blockProps:{"data-block-id":i._id,"data-block-type":i._type,"data-block-index":h},inBuilder:!0,lang:d||m,...b,...C,...A,...o}),[i._id,i._type,d,m,b,C,A,o]),_=React.useMemo(()=>!CORE_BLOCKS.includes(i._type),[i._type]);if(lodashEs.isNull(f)||g.includes(i._id))return null;let S=jsxRuntime.jsx(React.Suspense,{children:React.createElement(f,{...B,children:a({_id:i._id,_type:i._type,...lodashEs.isArray(b.repeaterItems)?{repeaterItems:applyBinding.applyLimit(b.repeaterItems,i),$repeaterItemsKey:b.$repeaterItemsKey}:{},...i.partialBlockId?{partialBlockId:i.partialBlockId}:"",...i.globalBlock?{partialBlockId:i.globalBlock}:""})})});const y=l===i._id&&(r===h||h<0)?jsxRuntime.jsx(WithBlockTextEditor,{block:i,children:S}):S;return _?jsxRuntime.jsx(reactErrorBoundary.ErrorBoundary,{fallbackRender:ErrorFallback,children:y}):y},PartialWrapper=({children:o,partialBlockId:n})=>{const a=useBuilderProp("gotoPage",lodashEs.noop),{saveState:l}=useSavePage(),{selectedLang:r,fallbackLang:i}=useLanguages(),c=React.useCallback(d=>{if(d.stopPropagation(),l!=="SAVED"){sonner.toast.error("You have unsaved changes. Please save the page first.");return}a({pageId:n,lang:r||i})},[l,a,n,r,i]);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]),l=React.useMemo(()=>utils.splitAtom(jotai.atom(a)),[a]);return lodashEs.isEmpty(a)?null:jsxRuntime.jsx(PartialWrapper,{partialBlockId:o,children:jsxRuntime.jsx(BlocksRenderer,{splitAtoms:l,blocks:a})})},BlocksRenderer=({blocks:o,parent:n=null,splitAtoms:a=void 0})=>{const l=useGetBlockAtom(a),r=React.useMemo(()=>lodashEs.filter(o,c=>lodashEs.has(c,"_id")&&(lodashEs.isEmpty(n)?!c._parent:c._parent===n)),[o,n]),i=React.useCallback(c=>lodashEs.filter(o,d=>d._parent===c).length>0,[o]);return lodashEs.map(r,c=>{const d=l(c._id);return d?jsxRuntime.jsx(MayBeAsyncPropsWrapper,{block:c,children:m=>jsxRuntime.jsx(BlockRenderer,{blockAtom:d,asyncProps:m,children:({_id:u,_type:p,partialBlockId:g,repeaterItems:x,$repeaterItemsKey:f})=>p==="Repeater"?lodashEs.isArray(x)&&x.map((h,j)=>jsxRuntime.jsx(RepeaterContext.Provider,{value:{index:j,key:f},children:jsxRuntime.jsx(BlocksRenderer,{splitAtoms:a,blocks:o,parent:c._id})},`${u}-${j}`)):p==="GlobalBlock"||p==="PartialBlock"?jsxRuntime.jsx(jotai.Provider,{store:builderStore,children:jsxRuntime.jsx(PartialBlocksRenderer,{partialBlockId:g})}):i(u)?jsxRuntime.jsx(BlocksRenderer,{splitAtoms:a,blocks:o,parent:c._id}):null})},c._id):null})},PageBlocksRenderer=()=>{const[o]=useBlocksStore();return jsxRuntime.jsx(BlocksRenderer,{splitAtoms:pageBlocksAtomsAtom,blocks:o})},StaticBlocksRenderer=()=>{const[o]=useBlocksStore(),n=lodashEs.isEmpty(o)?null:jsxRuntime.jsx(PageBlocksRenderer,{});return jsxRuntime.jsx(jsxRuntime.Fragment,{children:n})},useCanvasScale=o=>{const[n]=useCanvasDisplayWidth(),[,a]=useCanvasZoom(),l=useBuilderProp("htmlDir","ltr"),[r,i]=React.useState({}),c=React.useCallback(()=>{const{width:d,height:m}=o;if(d<n){const u=parseFloat((d/n).toFixed(2).toString());let p={};const g=m*u,x=d*u;m&&(p={height:100+(m-g)/g*100+"%",width:100+(d-x)/x*100+"%"}),i({position:"relative",top:0,transform:`scale(${u})`,transformOrigin:l==="rtl"?"top right":"top left",...p,maxWidth:"none"}),a(u*100)}else i({}),a(100)},[n,o,l,a]);return React.useEffect(()=>{c()},[n,o,a,c]),r};function usePubSub(o,n){React.useEffect(()=>{const a=pubsub.subscribe(o,n);return()=>a()},[o,n])}const CanvasEventsWatcher=()=>{const[,o]=useSelectedBlockIds(),[n,a]=useSelectedStylingBlocks(),{document:l}=useFrame(),{clearHighlight:r}=useBlockHighlight(),[i]=useSelectedBlockIds(),[c]=jotai.useAtom(treeRefAtom);return React.useEffect(()=>{setTimeout(()=>{if(!lodashEs.isEmpty(n))return;const d=getElementByDataBlockId(l,lodashEs.first(i));if(d){const m=d.getAttribute("data-style-prop");if(m){const u=d.getAttribute("data-style-id"),p=d.getAttribute("data-block-parent");a([{id:u,prop:m,blockId:p}])}}},100)},[l,i,a,n]),React.useEffect(()=>()=>r(),[r]),usePubSub(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_SELECTED,d=>{d&&(!lodashEs.isEmpty(d)&&!lodashEs.includes(i,lodashEs.first(d))&&(c==null||c.closeAll()),o(d))}),usePubSub(CHAI_BUILDER_EVENTS.CANVAS_BLOCK_STYLE_SELECTED,d=>{if(!d)return;const{blockId:m,styleId:u,styleProp:p}=d;m&&(lodashEs.includes(i,m)||c==null||c.closeAll(),a([{id:u,prop:p,blockId:m}]),o([m]))}),usePubSub(CHAI_BUILDER_EVENTS.CLEAR_CANVAS_SELECTION,()=>{r(),o([]),a([])}),null},StaticCanvas=()=>{const[o]=useCanvasDisplayWidth(),[,n]=useHighlightBlockId(),a=React.useRef(null),l=React.useRef(null),[r,i]=React.useState({width:0,height:0}),c=useCanvasScale(r),[,d]=jotai.useAtom(canvasIframeAtom),m=useBuilderProp("loading",!1),u=useBuilderProp("htmlDir","ltr"),p=React.useCallback(x=>{i(f=>({...f,width:x}))},[i]);React.useEffect(()=>{if(!l.current)return;const{clientWidth:x,clientHeight:f}=l.current;i({width:x,height:f})},[l,o]);const g=React.useMemo(()=>{let x=IframeInitialContent;return x=x.replace("__HTML_DIR__",u),x},[u]);return jsxRuntime.jsx(ResizableCanvasWrapper,{onMount:p,onResize:p,children:jsxRuntime.jsx("div",{onMouseLeave:()=>setTimeout(()=>n(""),300),className:"relative mx-auto h-full w-full overflow-hidden",ref:l,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:g,children:[jsxRuntime.jsx(KeyboardHandler,{}),jsxRuntime.jsx(BlockSelectionHighlighter,{}),jsxRuntime.jsx(HeadTags,{}),jsxRuntime.jsxs(reactWrapBalancer.Provider,{children:[jsxRuntime.jsxs(Canvas,{children:[m?jsxRuntime.jsx("div",{className:"h-full p-4",children:jsxRuntime.jsx(toggle.Skeleton,{className:"h-full"})}):jsxRuntime.jsx(StaticBlocksRenderer,{}),jsxRuntime.jsx(AddBlockAtBottom,{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]}),jsxRuntime.jsx(CanvasEventsWatcher,{})]}),jsxRuntime.jsx("div",{id:"placeholder",className:"pointer-events-none absolute z-[99999] max-w-full bg-green-500 transition-transform"})]})})})},FallbackError=()=>jsxRuntime.jsx("div",{className:"h-full w-full rounded-md bg-red-200 p-4 text-red-500",children:jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col items-center justify-center",children:[jsxRuntime.jsx("p",{className:"font-semibold",children:"Oops! Something went wrong."}),jsxRuntime.jsx("p",{children:"Please try again."})]})}),CodeEditor$1=React.lazy(()=>Promise.resolve().then(()=>require("./code-editor-67qfXwGU.cjs"))),CanvasArea=()=>{const[o]=useCodeEditor(),n=useBuilderProp("onError",lodashEs.noop);return jsxRuntime.jsx("div",{className:"flex h-full max-h-full w-full flex-1 flex-col",children:jsxRuntime.jsxs("div",{className:"relative flex h-full max-h-full flex-col overflow-hidden bg-gray-100/40 px-2",children:[jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx(toggle.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(toggle.Skeleton,{className:"h-full"}),children:jsxRuntime.jsx(reResizable.Resizable,{enable:{top:!0,bottom:!1},className:"max-h-[400px] min-h-[200px]",children:jsxRuntime.jsx(CodeEditor$1,{})})}):null,jsxRuntime.jsx(Breadcrumb,{})]})})},RJSF_EXTENSIONS={},registerBlockSettingWidget=(o,n)=>{RJSF_EXTENSIONS[o]={id:o,component:n,type:"widget"}},registerBlockSettingField=(o,n)=>{RJSF_EXTENSIONS[o]={id:o,component:n,type:"field"}},registerBlockSettingTemplate=(o,n)=>{RJSF_EXTENSIONS[o]={id:o,component:n,type:"template"}},useBlockSettingComponents=o=>Object.values(RJSF_EXTENSIONS).filter(n=>n.type===o).reduce((n,a)=>(n[a.id]=a.component,n),{}),removeSizeAttributes=o=>{try{return o.replace(/<svg([^>]*)\sheight="[^"]*"([^>]*)>/gi,"<svg$1$2>").replace(/<svg([^>]*)\swidth="[^"]*"([^>]*)>/gi,"<svg$1$2>")}catch{return o}},IconPickerField=({value:o,onChange:n,id:a})=>{const{t:l}=reactI18next.useTranslation(),[r,i]=React.useState(o||"");React.useEffect(()=>{i(o||"")},[o]);const c=d=>{i(d);const m=removeSizeAttributes(d);n(m)};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:r?jsxRuntime.jsx("div",{className:"h-6 w-6",dangerouslySetInnerHTML:{__html:r}}):jsxRuntime.jsx("span",{className:"text-xs text-gray-400",children:"SVG"})}),jsxRuntime.jsx("textarea",{id:a,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",value:r,onChange:d=>c(d.target.value),placeholder:l("Enter SVG code here"),rows:2,className:"no-scrollbar w-full rounded-md border border-border bg-background px-3 py-1.5 text-xs shadow-sm transition-colors placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50"})]}),jsxRuntime.jsx("p",{className:"text-xs text-muted-foreground",children:l("Paste SVG code to use as an icon")})]})},DefaultMediaManager=({close:o,onSelect:n,mode:a="image"})=>{const[l,r]=React.useState(""),[i,c]=React.useState(!1),[d,m]=React.useState(!1),[u,p]=React.useState(null),g=async f=>{if(!f.trim()){m(!1),p("Please enter a URL");return}try{c(!0),p(null),m(!0),p(null)}catch{m(!1),p("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(toggle.Alert,{variant:"destructive",children:[jsxRuntime.jsx(lucideReact.AlertCircle,{className:"h-4 w-4"}),jsxRuntime.jsx(toggle.AlertDescription,{children:u})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-4",children:[jsxRuntime.jsx(toggle.Input,{placeholder:x(`Enter ${a} URL`),value:l,onChange:f=>r(f.target.value),onKeyUp:()=>g(l)}),jsxRuntime.jsxs("div",{className:"flex justify-end gap-2",children:[jsxRuntime.jsx(toggle.Button,{variant:"outline",onClick:o,children:x("Cancel")}),jsxRuntime.jsx(toggle.Button,{onClick:()=>n({id:"dam-id",url:l,width:600,height:400,description:"This is image description"}),disabled:!d||i,children:x("Insert")})]})]})]})},MEDIA_MANAGER={component:DefaultMediaManager},registerChaiMediaManager=o=>{MEDIA_MANAGER.component=o},useMediaManagerComponent=()=>React.useMemo(()=>MEDIA_MANAGER.component,[]),MediaManagerModal=({assetId:o,children:n,onSelect:a,mode:l="image"})=>{const[r,i]=React.useState(!1),c=useMediaManagerComponent(),d=(...m)=>{a.call(void 0,...m),i(!1)};return jsxRuntime.jsxs(toggle.Dialog,{open:r,onOpenChange:m=>i(m),children:[jsxRuntime.jsx(toggle.DialogTrigger,{asChild:!0,children:n}),jsxRuntime.jsxs(toggle.DialogContent,{className:"flex max-h-[90vh] max-w-7xl border-border md:w-fit",children:[jsxRuntime.jsx(toggle.DialogTitle,{className:"sr-only",children:"Media Manager"}),jsxRuntime.jsx("div",{className:"h-full w-full",children:c?jsxRuntime.jsx(c,{close:()=>i(!1),onSelect:d,mode:l,assetId:o}):null})]})]})};MediaManagerModal.displayName="MediaManagerModal";const PLACEHOLDER_IMAGE="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTAwIiBoZWlnaHQ9IjQwMCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMTAwJSIgaGVpZ2h0PSIxMDAlIiBmaWxsPSIjZjNmNGY2Ii8+PHRleHQgeD0iNTAlIiB5PSI1MCUiIGZvbnQtZmFtaWx5PSJBcmlhbCwgc2Fucy1zZXJpZiIgZm9udC1zaXplPSIxNiIgZmlsbD0iI2Q1ZDdkYSIgdGV4dC1hbmNob3I9Im1pZGRsZSIgZHk9Ii4zZW0iPkltYWdlIFBsYWNlaG9sZGVyPC90ZXh0Pjwvc3ZnPg==",ImagePickerField=({value:o,onChange:n,id:a,onBlur:l})=>{const{t:r}=reactI18next.useTranslation(),{selectedLang:i}=useLanguages(),c=useSelectedBlock(),d=useUpdateBlocksProps(),m=a.split(".").pop()||"",u=i?`_${m}Id-${i}`:`_${m}Id`,p=lodashEs.isEmpty(i)&&(c==null?void 0:c._type)==="Image"&&lodashEs.has(c,"assetId"),g=lodashEs.get(c,u,p?c==null?void 0:c.assetId:""),x=!!g,f=j=>{const b=lodashEs.isArray(j)?lodashEs.first(j):j;if(b){n(b==null?void 0:b.url);const C=b==null?void 0:b.width,A=b==null?void 0:b.height;if(c!=null&&c._id){const B={...C&&{width:C},...A&&{height:A},...b.description&&{alt:b.description}};if(lodashEs.set(B,u,b.id),lodashEs.isEmpty(B))return;d([c._id],B)}}},h=React.useCallback(()=>{n(PLACEHOLDER_IMAGE),c!=null&&c._id&&d([c._id],{assetId:""})},[n,c==null?void 0:c._id,d]);return jsxRuntime.jsxs("div",{className:"mt-1.5 flex items-center gap-x-3",children:[o?jsxRuntime.jsxs("div",{className:"group relative",children:[jsxRuntime.jsx("img",{src:o,className:"h-20 w-20 overflow-hidden rounded-md border border-border object-cover transition duration-200 "+(g&&g!==""?"cursor-pointer group-hover:blur-sm":""),alt:""}),x&&jsxRuntime.jsx("button",{type:"button",onClick:h,className:"absolute -right-2 -top-2 z-20 rounded-full bg-destructive p-1 text-destructive-foreground hover:bg-destructive/90",children:jsxRuntime.jsx(lucideReact.X,{className:"h-3 w-3"})}),g&&g!==""&&jsxRuntime.jsx(MediaManagerModal,{onSelect:f,assetId:g,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(lucideReact.Edit2Icon,{className:"h-4 w-4 text-white"})})})]}):jsxRuntime.jsx(MediaManagerModal,{onSelect:f,mode:"image",assetId:g,children:jsxRuntime.jsx("div",{className:"h-20 w-20 cursor-pointer rounded-md border border-border bg-[radial-gradient(#AAA,transparent_1px)] duration-300 [background-size:10px_10px]"})}),jsxRuntime.jsxs("div",{className:"flex w-3/5 flex-col",children:[jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(MediaManagerModal,{onSelect:f,assetId:"",children:jsxRuntime.jsx("small",{className:"h-6 cursor-pointer rounded-md bg-secondary px-2 py-1 text-center text-xs text-secondary-foreground hover:bg-secondary/80",children:o||!lodashEs.isEmpty(o)?r("Replace image"):r("Choose image")})}),jsxRuntime.jsx("small",{className:"-pl-4 pt-2 text-center text-xs text-secondary-foreground",children:"OR"})]}),jsxRuntime.jsx("input",{id:a,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",type:"url",className:"text-xs",placeholder:r("Enter image URL"),value:o,onBlur:({target:{value:j}})=>l(a,j),onChange:j=>n(j.target.value)})]})]})},PathDropdown=({data:o,onSelect:n,dataType:a})=>{const[l,r]=React.useState([]),[i,c]=React.useState(o),d=g=>Array.isArray(g)?"array":typeof g=="object"&&g!==null?"object":"value",m=React.useCallback(g=>{const x=f=>a==="value"?f==="value"||f==="object":a==="array"?f==="array":f===a;g.type==="object"?(r(f=>[...f,g.key]),c(g.value)):x(g.type)&&n([...l,g.key].join("."),a)},[l,n,a]),u=React.useCallback(()=>{if(l.length>0){const g=l.slice(0,-1);r(g),c(g.reduce((x,f)=>x[f],o))}},[l,o]),p=React.useMemo(()=>i?Object.entries(i).map(([g,x])=>({key:g,value:x,type:d(x)})).filter(g=>!lodashEs.startsWith(g.key,applyBinding.REPEATER_PREFIX)&&g.key.includes("/")?!1:a==="value"?g.type==="value"||g.type==="object":a==="array"?g.type==="array"||g.type==="object":a==="object"?g.type==="object":!0):[],[i,a]);return jsxRuntime.jsxs(toggle.Command,{className:"fields-command",children:[jsxRuntime.jsx(toggle.CommandInput,{className:"border-none",placeholder:"Search..."}),jsxRuntime.jsxs(toggle.CommandList,{children:[jsxRuntime.jsx(toggle.CommandEmpty,{children:"No option found."}),jsxRuntime.jsxs(toggle.CommandGroup,{children:[l.length>0&&jsxRuntime.jsxs(toggle.CommandItem,{onSelect:u,className:"flex items-center text-sm",children:[jsxRuntime.jsx(lucideReact.ChevronLeft,{className:"mr-2 h-4 w-4"}),"Back"]}),p.map(g=>jsxRuntime.jsxs(toggle.CommandItem,{value:g.key,disabled:!1,onSelect:()=>m(g),className:"flex items-center justify-between",children:[jsxRuntime.jsxs("span",{className:"flex items-center gap-x-2",children:[lodashEs.startsWith(g.key,applyBinding.REPEATER_PREFIX)?jsxRuntime.jsx(reactIcons.LoopIcon,{}):lodashEs.startsWith(g.key,applyBinding.COLLECTION_PREFIX)?jsxRuntime.jsx(lucideReact.DatabaseIcon,{}):null,lodashEs.startsWith(g.key,applyBinding.REPEATER_PREFIX)?"Repeater Data":lodashEs.startsWith(g.key,applyBinding.COLLECTION_PREFIX)?g.key.replace(applyBinding.COLLECTION_PREFIX,""):g.key]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[a==="object"&&g.type==="object"&&jsxRuntime.jsx(toggle.Button,{size:"sm",variant:"ghost",className:"h-6 px-2 hover:bg-primary hover:text-primary-foreground",onClick:x=>{x.stopPropagation(),n([...l,g.key].join("."),a)},children:"Select"}),g.type==="object"&&jsxRuntime.jsx("div",{className:"cursor-pointer rounded p-1 hover:bg-muted",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4 opacity-50"})})]})]},g.key))]})]})]})};function NestedPathSelector({data:o,onSelect:n,dataType:a="value"}){const[l,r]=React.useState(!1),i=useBuilderProp("collections",[]),c=React.useMemo(()=>a==="array"?{...i.map(m=>m.id).reduce((m,u)=>({...m,[applyBinding.COLLECTION_PREFIX+u]:[]}),{}),...o}:o,[o,i,a]);return jsxRuntime.jsxs(toggle.Popover,{open:l,onOpenChange:r,children:[jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.PopoverTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{size:"sm",variant:"outline",className:"h-5 rounded-sm px-1 py-0 text-[9px] text-muted-foreground",role:"combobox","aria-expanded":l,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(toggle.TooltipContent,{children:"Add field"})]}),jsxRuntime.jsx(toggle.PopoverContent,{className:"z-[1000]! relative mr-3 w-[300px] p-0",children:jsxRuntime.jsx(PathDropdown,{data:c,onSelect:(d,m)=>{n(d,m),r(!1)},dataType:a})})]})}const DataBindingSelector=({schema:o,onChange:n,id:a,formData:l})=>{const r=usePageExternalData(),i=useSelectedBlockHierarchy(),c=useSelectedBlock(),d=React.useMemo(()=>{if(i.length===1)return"";const p=i.find(f=>f._type==="Repeater"),x=lodashEs.get(p,"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1");return`${applyBinding.REPEATER_PREFIX}${lodashEs.startsWith(x,applyBinding.COLLECTION_PREFIX)?`${x}/${p._id}`:x}`},[i]),m=React.useMemo(()=>lodashEs.first(lodashEs.get(r,d.replace(applyBinding.REPEATER_PREFIX,""),[])),[d,r]),u=React.useCallback((p,g)=>{if(p=lodashEs.isEmpty(d)?p:p.replace(`${d}`,"$index"),g==="array"||g==="object"){n(`{{${p}}}`,{},a);return}const x=b=>/[.,!?;:]/.test(b),f=(b,C,A)=>{let B="",_="";const S=C>0?b[C-1]:"",y=C<b.length?b[C]:"";return C>0&&(S==="."||!x(S)&&S!==" ")&&(B=" "),C<b.length&&!x(y)&&y!==" "&&(_=" "),{text:B+A+_,prefixLength:B.length,suffixLength:_.length}},h=document.getElementById(a);if(!h)return;const j=document.getElementById(`chai-rte-${a}`)||document.getElementById(`chai-rte-modal-${a}`);if(j&&(j.querySelector(".ProseMirror")||j.__chaiRTE)){const b=j.__chaiRTE;if(b){const C=`{{${p}}}`;b.commands.focus();const{from:A,to:B}=b.state.selection;if(A!==B)b.chain().deleteSelection().insertContent(C).run();else{const{state:S}=b,y=S.selection.from,E=S.doc.textBetween(Math.max(0,y-1),y),w=S.doc.textBetween(y,Math.min(y+1,S.doc.content.size));let R="";y>0&&E!==" "&&!x(E)&&(R=" ");let k="";w&&w!==" "&&!x(w)&&(k=" "),b.chain().insertContent(R+C+k).run()}setTimeout(()=>n(b.getHTML(),{},a),100);return}}else{const b=h,C=b.selectionStart||0,A=b.value||"",B=b.selectionEnd||C;if(B>C){const w=`{{${p}}}`,{text:R}=f(A,C,w),k=A.slice(0,C)+R+A.slice(B);n(k,{},a);return}const S=`{{${p}}}`,{text:y}=f(A,C,S),E=A.slice(0,C)+y+A.slice(C);n(E,{},a)}},[a,n,l,c==null?void 0:c._id,d]);return jsxRuntime.jsx(NestedPathSelector,{data:{...m&&{[d]:m},...r},onSelect:u,dataType:o.binding==="array"?"array":"value"})},PageTypeField=({href:o,pageTypes:n,onChange:a})=>{var w;const{t:l}=reactI18next.useTranslation(),r=useBuilderProp("searchPageTypeItems",(R,k)=>[]),[i,c]=React.useState(!1),[d,m]=React.useState(!1),[u,p]=React.useState("page"),[g,x]=React.useState(""),[f,h]=React.useState([]),[j,b]=React.useState(-1),C=React.useRef(null),A=(w=n==null?void 0:n.find(R=>R.key===u))==null?void 0:w.name;React.useEffect(()=>{if(x(""),h([]),b(-1),m(!1),!o||i||!lodashEs.startsWith(o,"pageType:"))return;const R=lodashEs.split(o,":"),k=lodashEs.get(R,1,"page")||"page";p(k),(async()=>{const v=await r(k,[lodashEs.get(R,2,"page")]);v&&Array.isArray(v)&&x(lodashEs.get(v,[0,"name"],""))})()},[o]);const B=web.useDebouncedCallback(async R=>{if(lodashEs.isEmpty(R))h([]);else{const k=await r(u,R);h(k)}c(!1),b(-1)},[u],300),_=R=>{const k=["pageType",u,R.id];k[1]&&(a(k.join(":")),x(R.name),m(!1),h([]),b(-1))},S=R=>{switch(R.key){case"ArrowDown":R.preventDefault(),b(k=>k<f.length-1?k+1:k);break;case"ArrowUp":R.preventDefault(),b(k=>k>0?k-1:k);break;case"Enter":if(R.preventDefault(),f.length===0)return;j>=0&&_(f[j]);break;case"Escape":R.preventDefault(),y();break}};React.useEffect(()=>{if(j>=0&&C.current){const R=C.current.children[j];R==null||R.scrollIntoView({block:"nearest"})}},[j]);const y=()=>{x(""),h([]),b(-1),m(!1),a("")},E=R=>{x(R),m(!lodashEs.isEmpty(R)),c(!0),B(R)};return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsx("select",{name:"pageType",value:u,onChange:R=>p(R.target.value),children:lodashEs.map(n,R=>jsxRuntime.jsx("option",{value:R.key,children:R.name},R.key))}),u&&jsxRuntime.jsxs("div",{className:"group relative mt-2 flex items-center",children:[jsxRuntime.jsx("input",{type:"text",value:g,onChange:R=>E(R.target.value),onKeyDown:S,placeholder:l(`Search ${A??""}`),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:g&&jsxRuntime.jsx("button",{onClick:y,className:"text-gray-400 hover:text-gray-600",title:l("Clear search"),children:jsxRuntime.jsx(lucideReact.X,{className:"h-4 w-4"})})})]}),(i||!lodashEs.isEmpty(f)||d&&lodashEs.isEmpty(f))&&jsxRuntime.jsx("div",{className:"absolute z-40 mt-2 max-h-40 w-full max-w-[250px] overflow-y-auto rounded-md border border-border bg-background shadow-lg",children:i?jsxRuntime.jsxs("div",{className:"space-y-1 p-2",children:[jsxRuntime.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),jsxRuntime.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):d&&lodashEs.isEmpty(f)?jsxRuntime.jsxs("div",{className:"flex items-center justify-center p-4 text-sm text-gray-500",children:[l("No results found for"),' "',g,'"']}):jsxRuntime.jsx("ul",{ref:C,children:lodashEs.map(f==null?void 0:f.slice(0,20),(R,k)=>jsxRuntime.jsxs("li",{onClick:()=>_(R),className:`cursor-pointer p-2 text-xs ${o!=null&&o.includes(R.id)?"bg-blue-200":k===j?"bg-gray-100":"hover:bg-gray-100"}`,children:[R.name," ",R.slug&&jsxRuntime.jsxs("small",{className:"font-light text-gray-500",children:["( ",R.slug," )"]})]},R.id))})})]})},LinkField=({schema:o,formData:n,onChange:a,name:l})=>{const{t:r}=reactI18next.useTranslation(),{type:i="pageType",href:c="",target:d="self"}=n,m=useBuilderProp("pageTypes",[]),u=i==="pageType"&&lodashEs.isEmpty(m)?"url":i;return jsxRuntime.jsxs("div",{children:[jsxRuntime.jsxs("span",{className:"flex items-center justify-between gap-x-2 text-xs font-medium",children:[(o==null?void 0:o.title)??"Link",jsxRuntime.jsx(DataBindingSelector,{schema:o,onChange:p=>{console.log("value",n,p),a({...n,href:p,...u==="pageType"?{type:"url"}:{}})},id:`root.${l}.href`,formData:n})]}),jsxRuntime.jsxs("div",{className:"flex flex-col gap-y-1.5",children:[jsxRuntime.jsx("select",{name:"type",value:i,onChange:p=>a({...n,type:p.target.value}),children:lodashEs.map([...lodashEs.isEmpty(m)?[]:[{const:"pageType",title:r("Goto Page")}],{const:"url",title:r("Open URL")},{const:"email",title:r("Compose Email")},{const:"telephone",title:r("Call Phone")},{const:"scroll",title:r("Scroll to element")}],p=>jsxRuntime.jsx("option",{value:p.const,children:p.title},p.const))}),u==="pageType"&&!lodashEs.isEmpty(m)?jsxRuntime.jsx(PageTypeField,{href:c,pageTypes:m,onChange:p=>a({...n,href:p})}):null,jsxRuntime.jsx("input",{id:`root.${l}.href`,autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",name:"href",type:"text",className:u==="pageType"?"!hidden":"",value:c,onChange:p=>a({...n,href:p.target.value}),placeholder:r(i==="url"?"Enter URL":i==="scroll"?"#ElementID":"Enter details")}),u==="url"&&jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 text-muted-foreground",children:[jsxRuntime.jsx("input",{id:`root.${l}.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:r("Open in new tab")})]})]})]})},RowColField=()=>{const o=useSelectedBlock(),n=useWrapperBlock(),{addCoreBlock:a}=useAddBlock();if(!o&&!n)return null;const l=(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:,"},l==null?void 0:l._id),children:[jsxRuntime.jsx(lucideReact.Plus,{className:"h-4 w-4"})," Add Column"]})})};function cn(...o){return tailwindMerge.twMerge(clsx.clsx(o))}const MenuBar=({editor:o,onExpand:n})=>{if(!o)return null;const a=()=>{const r=window.prompt("URL");r&&o.chain().focus().extendMarkRange("link").setLink({href:r}).run()},l=()=>{o.chain().focus().unsetLink().run()};return jsxRuntime.jsxs("div",{className:"mb-1 flex flex-wrap gap-1 rounded-md border border-border p-1",children:[jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleBold().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("bold")}),title:"Bold",children:jsxRuntime.jsx(lucideReact.Bold,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleItalic().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("italic")}),title:"Italic",children:jsxRuntime.jsx(lucideReact.Italic,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleUnderline().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("underline")}),title:"Underline",children:jsxRuntime.jsx(lucideReact.Underline,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleStrike().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("strike")}),title:"Strike",children:jsxRuntime.jsx(lucideReact.Strikethrough,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleBulletList().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("bulletList")}),title:"Bullet List",children:jsxRuntime.jsx(lucideReact.List,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().toggleOrderedList().run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("orderedList")}),title:"Ordered List",children:jsxRuntime.jsx(lucideReact.ListOrdered,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().setTextAlign("left").run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive({textAlign:"left"})}),title:"Align Left",children:jsxRuntime.jsx(lucideReact.AlignLeft,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().setTextAlign("center").run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive({textAlign:"center"})}),title:"Align Center",children:jsxRuntime.jsx(lucideReact.AlignCenter,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:()=>o.chain().focus().setTextAlign("right").run(),className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive({textAlign:"right"})}),title:"Align Right",children:jsxRuntime.jsx(lucideReact.AlignRight,{className:"h-4 w-4"})}),jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:a,className:cn("rounded p-1 hover:bg-muted",{"bg-muted":o.isActive("link")}),title:"Add Link",children:jsxRuntime.jsx(lucideReact.Link,{className:"h-4 w-4"})}),jsxRuntime.jsx("button",{type:"button",onClick:l,className:cn("rounded p-1 hover:bg-muted"),title:"Remove Link",disabled:!o.isActive("link"),children:jsxRuntime.jsx(lucideReact.Unlink,{className:"h-4 w-4"})}),n&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"mx-1 h-6 w-px self-center bg-border"}),jsxRuntime.jsx("button",{type:"button",onClick:n,className:"rounded p-1 hover:bg-muted",title:"Open in full screen mode",children:jsxRuntime.jsx(lucideReact.Maximize2,{className:"h-4 w-4"})})]})]})},RTEModal=({isOpen:o,onClose:n,id:a,value:l,onChange:r,onBlur:i})=>{const c=React.useRef(null),d=React.useRef(l||""),m=usePageExternalData();React.useEffect(()=>{if(o){const g=document.createElement("style");return g.id="rte-modal-styles",g.innerHTML=`
62
62
  /* Ensure the NestedPathSelector popover appears above the dialog */
63
63
  .rte-path-selector + [data-radix-popper-content-wrapper],
64
64
  [data-radix-popper-content-wrapper] {
65
65
  z-index: 9999 !important;
66
66
  }
67
- `,document.head.appendChild(g),()=>{const x=document.getElementById("rte-modal-styles");x&&x.remove()}}},[o]);const u=react.useEditor({extensions:[StarterKit,Link.configure({openOnClick:!1,HTMLAttributes:{class:"text-primary underline"}}),TextAlign.configure({types:["heading","paragraph"],alignments:["left","center","right"],defaultAlignment:"left"}),Underline,Placeholder.configure({placeholder:"Enter text here",emptyEditorClass:"cursor-text before:content-[attr(data-placeholder)] before:absolute before:opacity-50 before:pointer-events-none"})],content:l||"",onUpdate:({editor:g})=>{const x=g.getHTML();r(x)},onBlur:({editor:g})=>{const x=g.getHTML();i(a,x)},editorProps:{attributes:{class:"prose prose-sm focus:outline-none min-h-[300px] p-2 dark:prose-invert prose-p:m-0 prose-blockquote:m-2 prose-blockquote:ml-4 prose-ul:m-0 prose-ol:m-0 prose-li:m-0"}}});React.useEffect(()=>{o&&u&&(d.current!==l&&(d.current=l||"",u.commands.setContent(l||"")),setTimeout(()=>{u.commands.focus()},100))},[o,u]),React.useEffect(()=>{c.current&&u&&(c.current.__chaiRTE=u)},[u,o]);const p=g=>{if(!u)return;const x=`{{${g}}}`;u.commands.focus();const{from:f,to:h}=u.state.selection;if(f!==h)u.chain().deleteSelection().insertContent(x).run();else{const{state:b}=u,C=b.selection.from,B=b.doc.textBetween(Math.max(0,C-1),C),w=b.doc.textBetween(C,Math.min(C+1,b.doc.content.size));let _="";C>0&&B!==" "&&!/[.,!?;:]/.test(B)&&(_=" ");let S="";w&&w!==" "&&!/[.,!?;:]/.test(w)&&(S=" "),u.chain().insertContent(_+x+S).run()}};return jsxRuntime.jsx(toggle.Dialog,{open:o,onOpenChange:g=>!g&&n(),children:jsxRuntime.jsxs(toggle.DialogContent,{className:"max-h-[90vh] overflow-y-auto sm:max-w-[800px]",children:[jsxRuntime.jsx(toggle.DialogHeader,{children:jsxRuntime.jsxs(toggle.DialogTitle,{className:"flex items-center justify-between pr-8",children:[jsxRuntime.jsx("span",{children:"Rich Text Editor"}),Object.keys(m).length>0&&jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx("span",{className:"mr-2 text-sm text-muted-foreground",children:"Add field:"}),jsxRuntime.jsx("div",{className:"rte-path-selector",children:jsxRuntime.jsx(NestedPathSelector,{data:m,onSelect:p})})]})]})}),jsxRuntime.jsxs("div",{id:`chai-rte-modal-${a}`,ref:c,className:"rounded-md border border-input",children:[jsxRuntime.jsx(MenuBar,{editor:u}),jsxRuntime.jsx(react.EditorContent,{editor:u,id:`modal-${a}`,className:"p-2"})]}),jsxRuntime.jsx("div",{className:"mt-4 flex justify-end",children:jsxRuntime.jsx(toggle.Button,{onClick:n,children:"Done"})})]})})},RichTextEditorField=({id:o,placeholder:n,value:a,onChange:l,onBlur:r})=>{const i=React.useRef(null),[c,d]=React.useState(!1),[m,u]=React.useState(""),p=react.useEditor({extensions:[StarterKit,Link.configure({openOnClick:!1,HTMLAttributes:{class:"text-primary underline"}}),TextAlign.configure({types:["heading","paragraph"],alignments:["left","center","right"],defaultAlignment:"left"}),Underline,Placeholder.configure({placeholder:n||"Enter text here",emptyEditorClass:"cursor-text before:content-[attr(data-placeholder)] before:absolute before:opacity-50 before:pointer-events-none"})],content:a||"",onUpdate:({editor:f})=>{const h=f.getHTML();l(h),c||u(h)},onBlur:({editor:f})=>{const h=f.getHTML();r(o,h)},editorProps:{attributes:{class:"prose prose-sm focus:outline-none min-h-[100px] p-1 dark:prose-invert prose-p:m-0 prose-blockquote:m-2 prose-blockquote:ml-4 prose-ul:m-0 prose-ol:m-0 prose-li:m-0"}}});React.useEffect(()=>{i.current.__chaiRTE=p},[p]),React.useEffect(()=>{u(a||"")},[a]);const g=f=>{l(f)},x=()=>{d(!1),p&&p.commands.setContent(m)};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"relative",children:jsxRuntime.jsxs("div",{id:`chai-rte-${o}`,ref:i,className:"mt-1 rounded-md border border-input",children:[jsxRuntime.jsx(MenuBar,{editor:p,onExpand:()=>d(!0)}),jsxRuntime.jsx(react.EditorContent,{editor:p,id:o,placeholder:n})]})}),c&&jsxRuntime.jsx(RTEModal,{isOpen:c,onClose:x,id:o,value:m,onChange:g,onBlur:r})]})},SliderField=({formData:o,onChange:n})=>{const[a]=useBlocksStore(),l=useSelectedBlock(),r=useWrapperBlock(),{addCoreBlock:i}=useAddBlock(),[,c]=useSelectedBlockIds();if(!l&&!r)return null;const d=(l==null?void 0:l._type)==="Slider"?l:r,m=lodashEs.find(a,{_parent:d==null?void 0:d._id,_type:"Slides"});if(!m)return null;const u=lodashEs.filter(a,{_parent:m==null?void 0:m._id,_type:"Slide"}),p=(o==null?void 0:o.currentSlide)||lodashEs.get(u,"0._id");React.useEffect(()=>{(l==null?void 0:l._type)==="Slide"&&(o==null?void 0:o.currentSlide)!==(l==null?void 0:l._id)&&n({...o,currentSlide:l==null?void 0:l._id})},[l]),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 g=()=>{const h=lodashEs.findIndex(u,{_id:p});if(h>-1){const j=(h+1)%u.length,b=lodashEs.get(u,[j,"_id"]);if(!b)return;n({...o,currentSlide:b}),c([b])}},x=()=>{const h=lodashEs.findIndex(u,{_id:p});if(h>-1){const j=(h-1+u.length)%u.length,b=lodashEs.get(u,[j,"_id"]);if(!b)return;n({...o,currentSlide:b}),c([b])}},f=()=>{const h=i({styles:"#styles:,h-full w-full min-w-full",type:"Slide"},m==null?void 0:m._id),j=h==null?void 0:h._id;j&&(n({...o,currentSlide:j}),c([j]))};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(lucideReact.ChevronLeft,{className:"h-3 w-3 stroke-[3]"})}),jsxRuntime.jsx("div",{className:"whitespace-nowrap text-center text-[10px] text-slate-500",children:p?jsxRuntime.jsxs("span",{className:"",children:[jsxRuntime.jsxs("b",{className:"text-[12px]",children:[" ",lodashEs.findIndex(u,{_id:p})+1]}),"/",u.length]}):"-"}),jsxRuntime.jsx("button",{onClick:g,className:"rounded bg-gray-200 p-1.5 hover:opacity-80",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-3 w-3 stroke-[3]"})}),jsxRuntime.jsxs("button",{onClick:f,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(lucideReact.PlusCircle,{className:"h-3 w-3 stroke-[2]"}),"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:h=>{let j=h.target.value;j.length&&(j=j.replace("-","")),n({...o,autoplayInterval:j})}})]})]})})]})},SourcesField=({formData:o,onChange:n})=>{const a=lodashEs.get(o,"srcsets",[])||[],l=(c,d)=>{const m=c.target.name,u=c.target.value;n({srcsets:lodashEs.map(a,(p,g)=>g===d?{...p,[m]:u}:p)})},r=()=>{n({srcsets:[...a,{}]})},i=c=>{n({srcsets:lodashEs.reject(a,(d,m)=>m===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:r,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(lucideReact.Plus,{size:12})})]}),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:()=>i(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(lucideReact.X,{size:10,className:"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:m=>l(m,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:m=>l(m,d)})]})]},d))})]})},CodeEditor=({id:o,placeholder:n})=>{const{t:a}=reactI18next.useTranslation(),[,l]=useCodeEditor(),r=useSelectedBlock();if(typeof window>"u")return null;const i=o.replace("root.",""),c=lodashEs.get(r,i,""),d=()=>{const m=r==null?void 0:r._id;l({blockId:m,blockProp:i,placeholder:n,initialCode:lodashEs.get(r,i,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(toggle.Button,{onClick:d,size:"sm",variant:"outline",className:"w-fit",children:a("Open code editor")})]})},CollectionFilterSortField=({id:o,value:n,onChange:a,onBlur:l})=>{const r=useBuilderProp("collections",[]),i=useSelectedBlock(),c=lodashEs.get(i,"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1").replace(applyBinding.COLLECTION_PREFIX,""),d=lodashEs.find(r,{id:c}),m=o==="root.filter"?"filters":"sorts",u=lodashEs.get(d,m,[]);return jsxRuntime.jsx("div",{children:jsxRuntime.jsxs("select",{value:n,onChange:p=>a(p.target.value),onBlur:p=>l(o,p.target.value),children:[jsxRuntime.jsx("option",{value:"",children:"Select"}),u.map(p=>jsxRuntime.jsx("option",{value:p.id,children:p.name},p.id))]})})},JSONFormFieldTemplate=({id:o,classNames:n,label:a,children:l,errors:r,help:i,hidden:c,required:d,schema:m,formData:u,onChange:p})=>{const{selectedLang:g,fallbackLang:x,languages:f}=useLanguages(),h=React.useMemo(()=>lodashEs.isEmpty(f)?"":lodashEs.isEmpty(g)?x:g,[f,g,x]),j=React.useMemo(()=>lodashEs.get(LANGUAGES,h,h),[h]),b=usePageExternalData(),C=useSelectedBlock(),B=runtime.useRegisteredChaiBlocks(),w=React.useMemo(()=>lodashEs.get(B,[C==null?void 0:C._type,"i18nProps"],[]),[B,C==null?void 0:C._type]),[_,S]=React.useState(null);if(c)return null;if(m.type==="boolean")return jsxRuntime.jsx("div",{className:n,children:l});const E=w==null?void 0:w.includes(o.replace("root.",""));if(m.type==="array"){const A=_===o;return jsxRuntime.jsxs("div",{className:`${n} relative`,children:[m.title&&jsxRuntime.jsx("div",{className:"flex items-center justify-between gap-1",children:jsxRuntime.jsxs("label",{htmlFor:o,onClick:()=>S(A?null:o),className:"flex cursor-pointer items-center gap-x-1 py-1 leading-tight duration-200 hover:bg-slate-100",children:[A?jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-3 w-3"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-3 w-3"}),jsxRuntime.jsx(lucideReact.List,{className:"h-3 w-3"}),jsxRuntime.jsx("span",{className:"leading-tight",children:a})," ",jsxRuntime.jsx(toggle.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:u==null?void 0:u.length})}),m.description&&jsxRuntime.jsx(toggle.TooltipProvider,{children:jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(lucideReact.Info,{className:"h-3 w-3 text-muted-foreground/70",onClick:R=>R.stopPropagation(),onMouseDown:R=>R.stopPropagation()})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"max-w-xs",children:m.description})]})})]})}),(u==null?void 0:u.length)===0?jsxRuntime.jsx("div",{className:"h-0 overflow-hidden",children:l}):jsxRuntime.jsxs("div",{className:`${A?"pt-0.5":"h-0 overflow-hidden"}`,children:[l,r,i]})]})}return jsxRuntime.jsxs("div",{className:n,children:[m.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:o,className:m.type==="object"?"pb-2":"",children:[a," ",E&&jsxRuntime.jsxs("small",{className:"text-[9px] text-zinc-400",children:[" ",j]}),d&&m.type!=="object"?" *":null]}),m.description&&jsxRuntime.jsx(toggle.TooltipProvider,{children:jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(lucideReact.Info,{className:"h-3 w-3 text-muted-foreground/70"})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"max-w-xs",children:m.description})]})})]}),!m.enum&&!m.oneOf&&b&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(DataBindingSelector,{schema:m,onChange:A=>{p(A,u,o)},id:o,formData:u})})]}),l,r,i]})},RepeaterBindingWidget=({value:o,onChange:n})=>{var i;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(lucideReact.File,{className:"h-4 w-4"})," Choose a collection"]});const a=`{{${applyBinding.COLLECTION_PREFIX}`,l=o==null?void 0:o.startsWith(a);let r=o;return l&&(r=(i=o==null?void 0:o.replace(a,""))==null?void 0:i.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:[" ",l?jsxRuntime.jsx(lucideReact.Database,{className:"h-3 min-h-3 w-3 min-w-3"}):null,jsxRuntime.jsxs(toggle.Tooltip,{delayDuration:500,children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx("span",{className:"cursor-default truncate",children:r})}),jsxRuntime.jsx(toggle.TooltipContent,{side:"left",hidden:r.length<50,children:r})]})]}),jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.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(lucideReact.X,{className:"h-4 w-4"})})}),jsxRuntime.jsx(toggle.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(lucideReact.Plus,{className:"h-3 w-3"})," ",jsxRuntime.jsx("span",{children:"Add"})]})}),JSONForm=React.memo(({blockId:o,schema:n,uiSchema:a,formData:l,onChange:r})=>{const{selectedLang:i}=useLanguages(),c=useBlockSettingComponents("widget"),d=useBlockSettingComponents("field"),m=useBlockSettingComponents("template"),u=web.useThrottledCallback(async({formData:p},g)=>{lodashEs.get(p,g)===void 0&&lodashEs.set(p,g,""),r({formData:p},g)},[r,i],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},...m},idSeparator:".",autoComplete:"off",omitExtraData:!1,liveOmit:!1,liveValidate:!1,validator,uiSchema:a,schema:n,formData:l,onChange:({formData:p},g)=>{if(!g||o!==(p==null?void 0:p._id))return;const x=lodashEs.take(g.split("."),2).join(".").replace("root.","");u({formData:p},x)}},i)}),formDataWithSelectedLang=(o,n,a)=>{const l=lodashEs.cloneDeep(o);return lodashEs.forEach(lodashEs.keys(o),r=>{lodashEs.includes(lodashEs.get(a,"i18nProps",[]),r)&&!lodashEs.isEmpty(n)&&(l[r]=lodashEs.get(o,`${r}-${n}`))}),l};function BlockSettings(){const{selectedLang:o}=useLanguages(),n=useSelectedBlock(),a=useUpdateBlocksPropsRealtime(),l=useUpdateBlocksProps(),r=runtime.getRegisteredChaiBlock(n==null?void 0:n._type),i=formDataWithSelectedLang(n,o,r),[c,d]=React.useState(i),[m,u]=React.useState(!1),p=useWrapperBlock(),g=runtime.getRegisteredChaiBlock(p==null?void 0:p._type),x=formDataWithSelectedLang(p,o,g),f=({formData:S},y,E)=>{y&&(c==null?void 0:c._id)===n._id&&l([n._id],{[y]:lodashEs.get(S,y)},E)},h=React.useCallback(lodashEs.debounce(({formData:S},y,E)=>{f({formData:S},y,E),d(S)},1500),[n==null?void 0:n._id,o]),j=({formData:S},y)=>{y&&(a([n._id],{[y]:lodashEs.get(S,y)}),h({formData:S},y,{[y]:lodashEs.get(c,y)}))},b=({formData:S},y)=>{y&&(a([p._id],{[y]:lodashEs.get(S,y)}),h({formData:S},y,{[y]:lodashEs.get(c,y)}))},{schema:C,uiSchema:B}=React.useMemo(()=>{const S=n==null?void 0:n._type;if(!S)return{schema:{},uiSchema:{}};try{const{schema:y,uiSchema:E}=runtime.getBlockFormSchemas(S);if(S==="Repeater"){const A=lodashEs.get(n,"repeaterItems","");lodashEs.startsWith(A,`{{${applyBinding.COLLECTION_PREFIX}`)?(lodashEs.set(E,"filter",{"ui:widget":"collectionSelect"}),lodashEs.set(E,"sort",{"ui:widget":"collectionSelect"})):(lodashEs.set(E,"filter",{"ui:widget":"hidden"}),lodashEs.set(E,"sort",{"ui:widget":"hidden"}))}return{schema:y,uiSchema:E}}catch{return{schema:{},uiSchema:{}}}},[n]),{wrapperSchema:w,wrapperUiSchema:_}=React.useMemo(()=>{if(!p||!(p!=null&&p._type))return{wrapperSchema:{},wrapperUiSchema:{}};const S=p==null?void 0:p._type,{schema:y={},uiSchema:E={}}=runtime.getBlockFormSchemas(S);return{wrapperSchema:y,wrapperUiSchema:E}},[p]);return jsxRuntime.jsxs("div",{className:"no-scrollbar overflow-x-hidden px-px",children:[!lodashEs.isEmpty(p)&&jsxRuntime.jsxs("div",{className:"mb-4 rounded border bg-zinc-100 px-1",children:[jsxRuntime.jsxs("div",{onClick:()=>u(S=>!S),className:"flex cursor-pointer items-center gap-x-1 py-2 text-xs font-medium leading-tight hover:bg-slate-100",children:[m?jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-4 w-4 stroke-[3] text-slate-400"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4 stroke-[3] text-slate-400"}),lodashEs.startCase(p._type)," settings"," ",p._name&&jsxRuntime.jsxs("span",{className:"text-[11px] font-light text-slate-400",children:["(",p._name,")"]})]}),jsxRuntime.jsx("div",{className:m?"h-auto":"invisible h-0",children:jsxRuntime.jsx(JSONForm,{blockId:p==null?void 0:p._id,onChange:b,formData:x,schema:w,uiSchema:_})})]}),lodashEs.isEmpty(C)?null:jsxRuntime.jsx(JSONForm,{blockId:n==null?void 0:n._id,onChange:j,formData:i,schema:C,uiSchema:B})]})}const BlockStylingProps=()=>{var f;const o=useSelectedBlock(),[n,a]=useSelectedStylingBlocks(),l=useRemoveClassesFromBlocks(),[r]=useSelectedBlockIds(),{t:i}=reactI18next.useTranslation();if(!o)return null;const c=Object.keys(o).filter(h=>typeof o[h]=="string"&&o[h].startsWith("#styles:")),{reset:d}=useResetBlockStyles(),m=!lodashEs.isEmpty(c)&&c.length>1,u=lodashEs.get(o,(f=n[0])==null?void 0:f.prop,""),{classes:p=""}=applyBinding.getSplitChaiClasses(u)||{},g=p?p.split(" ").filter(h=>!lodashEs.isEmpty(h)):[],x=h=>lodashEs.find(n,j=>j.prop===h);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:m&&jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-1",children:[jsxRuntime.jsxs("label",{htmlFor:"block-styling-props",className:"py-1 text-xs",children:[i("Style element"),":"]}),jsxRuntime.jsx("div",{className:"flex flex-wrap gap-2",children:lodashEs.map(c,h=>jsxRuntime.jsxs(toggle.Badge,{className:"flex cursor-pointer items-center gap-1 pr-1",variant:x(h)?"default":"secondary",onClick:()=>{a([{id:`${h}-${o._id}`,blockId:o._id,prop:h}])},children:[lodashEs.startCase(h),jsxRuntime.jsxs(toggle.DropdownMenu,{children:[jsxRuntime.jsx(toggle.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:j=>j.stopPropagation(),children:jsxRuntime.jsx(lucideReact.MoreVertical,{className:"h-3 w-3"})})}),jsxRuntime.jsxs(toggle.DropdownMenuContent,{side:"bottom",className:"border-border text-xs",children:[jsxRuntime.jsx(toggle.DropdownMenuItem,{className:"text-xs",onClick:()=>{d(h)},children:i("Reset style")}),jsxRuntime.jsx(toggle.DropdownMenuItem,{className:"text-xs",onClick:()=>{l(r,g,!0)},children:i("Clear styles")})]})]})]},h))}),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 l=n.length?new RegExp(n.join("|"),"g"):/XXXXXX/g;a=a.replace(l,"");const r=o.match(l),i=r&&r.length>1,c=!lodashEs.isEmpty(a)&&Number.isNaN(Number(a));return i||c?{error:"Invalid value"}:r&&(r[0]==="auto"||r[0]==="none")?{value:r[0],unit:""}:{value:a,unit:r?r[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 l=o.match(/border-?(x|y|t|r|b|l)?\d+/g);if(l)return{value:l[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[l,r]=lodashEs.map(a.split("/"),i=>parseInt(i,10));return{value:n+(l/r*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,""),l=o.startsWith("-")?"-":"",r=lodashEs.first(a.match(/\d+.\d+|\d+/g));return{value:`${l}${r}`,unit:a.replace(r,"")}},getValueAndUnitForTWClass=o=>lodashEs.isEmpty(o)?{value:"",unit:""}:getTwClassValue(o),DragStyleButton=({unit:o,currentValue:n,onDrag:a,onDragEnd:l,onDragStart:r,negative:i,cssProperty:c})=>{const{setDragData:d}=React.useContext(BlockSettingsContext);return jsxRuntime.jsx("button",{type:"button",onMouseDown:m=>{const u={onDrag:a,onDragEnd:l,dragging:!0,dragStartY:m.pageY,dragStartValue:`${n}`,dragUnit:o,negative:i,cssProperty:c};r(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(l=>jsxRuntime.jsx(toggle.Button,{className:"h-max rounded-none px-1 py-1 text-right text-[11px] hover:bg-blue-400",color:n===l?"primary":void 0,size:"sm",onClick:r=>{r.stopPropagation(),o(l)},children:l},l))}),THROTTLE_TIME=50,AdvanceChoices=o=>{const[n,a]=React.useState(!1),[l,r]=React.useState(""),{currentClass:i,onChange:c,classPrefix:d,cssProperty:m,units:u,negative:p}=o,[g,x]=React.useState(m!=null&&m.toLowerCase().includes("width")?"%":u[0]),[f,h]=React.useState(!1),[j,b]=React.useState(""),[C,B]=React.useState(!1),[w,_]=React.useState(!1);React.useEffect(()=>{const{value:R,unit:k}=getClassValueAndUnit(i);if(k===""){r(R),x(m!=null&&m.toLowerCase().includes("width")?"%":lodashEs.first(u));return}x(k),r(k==="class"||lodashEs.isEmpty(R)?"":R)},[i,m,u]);const S=web.useThrottledCallback(R=>c(R),[c],THROTTLE_TIME),y=web.useThrottledCallback(R=>c(R,!1),[c],THROTTLE_TIME),E=React.useCallback((R=!1)=>{const k=getUserInputValues(`${l}`,u);if(lodashEs.get(k,"error",!1)){h(!0);return}const v=lodashEs.get(k,"unit")!==""?lodashEs.get(k,"unit"):g;if(v==="auto"||v==="none"){S(`${d}${v}`);return}if(lodashEs.get(k,"value")==="")return;const I=`${lodashEs.get(k,"value","").startsWith("-")?"-":""}${d}[${lodashEs.get(k,"value","").replace("-","")}${v==="-"?"":v}]`;R?y(I):S(I)},[S,y,l,g,d,u]),A=React.useCallback(R=>{const k=getUserInputValues(`${l}`,u);if(lodashEs.get(k,"error",!1)){h(!0);return}if(R==="auto"||R==="none"){S(`${d}${R}`);return}if(lodashEs.get(k,"value")==="")return;const v=lodashEs.get(k,"unit")!==""?lodashEs.get(k,"unit"):R,I=`${lodashEs.get(k,"value","").startsWith("-")?"-":""}${d}[${lodashEs.get(k,"value","").replace("-","")}${v==="-"?"":v}]`;S(I)},[S,l,d,u]);return jsxRuntime.jsx("div",{className:"flex w-full flex-col",children:jsxRuntime.jsx("div",{className:"flex items-center justify-start",children:g==="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:i}),jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.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(toggle.TooltipContent,{children:"Current value is using a Tailwind preset class."})]})]}):jsxRuntime.jsxs("div",{className:`group relative flex items-center ${C?"z-auto":""}`,children:[jsxRuntime.jsxs("div",{className:"flex items-center rounded-md border border-border",children:[["none","auto"].indexOf(g)!==-1?null:jsxRuntime.jsx("input",{readOnly:g==="class",onKeyPress:R=>{R.key==="Enter"&&E()},onKeyDown:R=>{if(R.keyCode!==38&&R.keyCode!==40)return;R.preventDefault(),_(!0);const k=lodashEs.parseInt(R.target.value);let v=lodashEs.isNaN(k)?0:k;R.keyCode===38&&(v+=1),R.keyCode===40&&(v-=1);const N=`${v}`,L=`${N.startsWith("-")?"-":""}${d}[${N.replace("-","")}${g==="-"?"":g}]`;y(L)},onKeyUp:R=>{w&&(R.preventDefault(),_(!1))},onBlur:()=>E(),onChange:R=>{h(!1),r(R.target.value)},onClick:R=>{var k;(k=R==null?void 0:R.target)==null||k.select(),a(!1)},value:C?j:l,className:"h-6 w-14 rounded rounded-r-none border border-transparent bg-background pl-2 text-sm focus-visible:outline-0".concat(" ",f?"border-red-500 text-red-500":"border-foreground/20")}),jsxRuntime.jsxs(toggle.Tooltip,{open:n,delayDuration:100,children:[jsxRuntime.jsx(toggle.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:g}),u.length>1?jsxRuntime.jsx(reactIcons.TriangleDownIcon,{}):null]})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"bg-background",children:jsxRuntime.jsx(UnitSelection,{units:u,current:g,onSelect:R=>{a(!1),x(R),A(R)}})})]})]}),["none","auto"].indexOf(g)!==-1||C?null:jsxRuntime.jsx(DragStyleButton,{onDragStart:()=>B(!0),onDragEnd:R=>{if(b(()=>""),B(!1),lodashEs.isEmpty(R))return;const k=`${R}`,N=`${k.startsWith("-")?"-":""}${d}[${k.replace("-","")}${g==="-"?"":g}]`;S(N)},onDrag:R=>{if(lodashEs.isEmpty(R))return;b(R);const k=`${R}`,N=`${k.startsWith("-")?"-":""}${d}[${k.replace("-","")}${g==="-"?"":g}]`;y(N)},currentValue:l,unit:g,negative:p,cssProperty:m})]})})})},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:l}=useTailwindClassList(),r=l(n),i=useCurrentClassByProperty(n),c=React.useMemo(()=>lodashEs.get(i,"cls",""),[i]),{canChange:d}=React.useContext(StyleContext),m=/\[.*\]/g.test(c);return jsxRuntime.jsx("div",{className:o?"w-full rounded":"grow",children:m?jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx(toggle.Input,{className:"w-[70%] rounded py-1",readOnly:!0,value:c}),jsxRuntime.jsxs(toggle.Tooltip,{delayDuration:100,children:[jsxRuntime.jsx(toggle.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(toggle.TooltipContent,{children:"Current value is using a Tailwind arbitrary value."})]})]}):jsxRuntime.jsx(DropDown,{rounded:o,onChange:u=>a(u,n),selected:c,options:r,disabled:!d})})};function DropDown({selected:o,onChange:n,rounded:a=!1,options:l,disabled:r=!1}){const i=o.replace(/.*:/g,"").trim(),{undo:c,redo:d}=useUndoManager();return jsxRuntime.jsxs("select",{disabled:!l.length||r,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:m=>n(m.target.value),onKeyDown:m=>{m.ctrlKey&&(m.key==="z"&&c(),m.key==="y"&&d())},value:i,children:[jsxRuntime.jsx("option",{className:"bg-transparent",value:""}),l.map((m,u)=>jsxRuntime.jsx("option",{className:"bg-transparent",value:m,children:m},`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),l=React.useMemo(()=>lodashEs.get(a,"cls",""),[a]),{canChange:r}=React.useContext(StyleContext),[i,c]=React.useState([]),[d,m]=React.useState({color:"",shade:""}),u=l.split("-"),p=lodashEs.get(u,"1",""),g=lodashEs.get(u,"2",""),x=React.useCallback(j=>{["current","inherit","transparent","black","white"].includes(j)?(c([]),m({color:j})):(c(["50","100","200","300","400","500","600","700","800","900"]),m(b=>({...b,color:j,shade:b.shade?b.shade:"500"})))},[c,m]);React.useEffect(()=>{if(["current","inherit","transparent","black","white"].includes(p))return c([]);c(["50","100","200","300","400","500","600","700","800","900"])},[p]);const f=React.useCallback(j=>{m({color:p,shade:j})},[p]);React.useEffect(()=>{m({color:"",shade:""})},[a]);const{match:h}=useTailwindClassList();return React.useEffect(()=>{const b=`${lodashEs.get(COLOR_PROP,o,"")}-${d.color}${d.shade?`-${d.shade}`:""}`;h(o,b)&&n(b,o)},[h,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:!r,rounded:!0,selected:p,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:g,disabled:!p||!r,onChange:f,options:i})})]})},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(),l=a(o),{canChange:r}=React.useContext(StyleContext),i=useCurrentClassByProperty(o),c=React.useMemo(()=>lodashEs.get(i,"cls",""),[i]);return jsxRuntime.jsx("div",{className:"flex grow flex-wrap gap-1",children:lodashEs.map(l,d=>jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx("button",{type:"button",disabled:!r,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(toggle.TooltipContent,{children:lodashEs.startCase(lodashEs.toLower(d))})]}))})},RangeChoices=({property:o,onChange:n})=>{const{canReset:a,canChange:l}=React.useContext(StyleContext),r=useCurrentClassByProperty(o),i=React.useMemo(()=>lodashEs.get(r,"cls",""),[r]),{getClasses:c}=useTailwindClassList(),d=c(o,[""]),m=d.indexOf(i)>-1?d.indexOf(i):0,u=/\[.*\]/g.test(i);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:i}):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:!l&&(!a||m-1<0),onClick:()=>n(lodashEs.nth(d,m-1),o),children:jsxRuntime.jsx("span",{className:"flex items-center justify-center",children:jsxRuntime.jsx(reactIcons.MinusIcon,{className:!l&&(!a||m-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:!l&&(!a||m+1>=d.length),onClick:()=>n(lodashEs.nth(d,m+1),o),children:jsxRuntime.jsx("span",{className:"flex items-center justify-center",children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:!l&&(!a||m+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:l,property:r,onEmitChange:i=()=>{},units:c,negative:d=!1}=o,[m]=useDarkMode(),[u]=useStylingState(),[,p]=useScreenSizeWidth(),g=useCurrentClassByProperty(r),x=useAddClassesToBlocks(),f=useRemoveClassesFromBlocks(),[h]=useSelectedBlockIds(),j=React.useMemo(()=>lodashEs.get(g,"fullCls",""),[g]),b=React.useCallback((y,E=!0)=>{const A={dark:m,mq:p,mod:u,cls:y,property:r,fullCls:""};(m||u!=="")&&(A.mq="xs");const R=generateFullClsName(A);x(h,[R],E)},[h,m,p,u,r,x]),C=React.useCallback(()=>{f(h,[j],!0)},[h,j,f]),B=React.useMemo(()=>canChangeClass(g,p),[g,p]);React.useEffect(()=>{i(B,g)},[B,i,g]);const[,,w]=useScreenSizeWidth(),_=React.useCallback(y=>{w({xs:400,sm:640,md:800,lg:1024,xl:1420,"2xl":1920}[y])},[w]),S=lodashEs.get(g,"dark",null)===m&&lodashEs.get(g,"mod",null)===u&&lodashEs.get(g,"mq",null)===p;return jsxRuntime.jsx(BlockStyleProvider,{canChange:B,canReset:g&&S,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] ${g&&!S?"text-foreground":""}`,children:n(l)})}),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(g,"cls",""),classPrefix:lodashEs.get(CLASS_PREFIXES,r,""),units:c||[],onChange:b,negative:d,cssProperty:r}):null,a==="icons"&&jsxRuntime.jsx(IconChoices,{property:r,onChange:b}),a==="range"&&jsxRuntime.jsx(RangeChoices,{property:r,onChange:b}),a==="color"&&jsxRuntime.jsx(ColorChoice,{property:r,onChange:b}),a==="dropdown"&&jsxRuntime.jsx(DropDownChoices,{label:l,property:r,onChange:b})]}),jsxRuntime.jsx("div",{className:`w-[30px] cursor-pointer ${j?"visible":"invisible"}`,children:S?jsxRuntime.jsx("button",{type:"button",onClick:()=>C(),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"})}):B&&g?jsxRuntime.jsxs(toggle.Tooltip,{delayDuration:100,children:[jsxRuntime.jsx(toggle.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(toggle.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(g,"mq")),m&&!g.dark?"(Light mode)":""]}),jsxRuntime.jsx("br",{}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>_(lodashEs.get(g,"mq")),className:"block w-full cursor-default text-right font-semibold text-blue-500",children:["Switch to ",lodashEs.get(g,"mq").toUpperCase()]})]})})})]}):null})]})]})})},basicUnits=["px","%","em","rem","ch","vh","vw"],MultipleChoices=({label:o,options:n,borderB:a=!1,borderT:l=!1,type:r="arbitrary",units:i=basicUnits,negative:c=!1})=>{const{t:d}=reactI18next.useTranslation(),[m,u]=React.useState(n[0].key),p=useSelectedBlockCurrentClasses(),g=React.useCallback(x=>lodashEs.map(p,"property").includes(x),[p]);return jsxRuntime.jsxs("div",{className:`mb-2 border-border py-2 first:pt-0 last:pb-0 ${a?"border-b":""} ${l?"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:f},h)=>jsxRuntime.jsx("div",{className:"first:rounded-l last:rounded-r",children:jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("button",{type:"button",onClick:()=>u(f),className:`relative cursor-pointer rounded-full p-1 text-[8px] ${f===m?"bg-[#3E57F0] text-white":"text-gray-600 dark:text-gray-300"}`,children:[React.createElement("div",{className:g(f)?"-bottom-1.5 absolute bg-[#3E57F0] h-[2px] left-0 w-full":""}),React.createElement(lodashEs.get(EDITOR_ICONS,f,reactIcons.BoxIcon),{className:"text-inherit w-3 h-3"})]})}),jsxRuntime.jsx(toggle.TooltipContent,{children:lodashEs.startCase(lodashEs.toLower(x))})]})},`option-${h}`))})]}),jsxRuntime.jsx("div",{className:"mt-0 flex items-center",children:jsxRuntime.jsx(BlockStyle,{type:r,units:[...i],label:"",property:m,negative:c})})]})},NestedOptions=({heading:o,items:n})=>{const{t:a}=reactI18next.useTranslation(),l=useSelectedBlockCurrentClasses(),r=React.useMemo(()=>{const i=m=>lodashEs.flatten(m.map(u=>u.styleType==="multiple"?lodashEs.map(u.options,"key"):u.property)),c=lodashEs.flatten(n.map(m=>m.styleType==="accordion"?i(m.items):m.styleType==="multiple"?lodashEs.map(m.options,"key"):m.property)),d=lodashEs.map(l,"property");return lodashEs.intersection(c,d).length>0},[l,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())),r?jsxRuntime.jsx("span",{className:`ml-1 mr-2 inline-block h-[8px] w-[8px] rounded-full ${r?"bg-primary":"bg-gray-300"}`}):null]})}),jsxRuntime.jsx("div",{className:"p-2",children:n.map(i=>i.styleType==="multiple"?jsxRuntime.jsx(MultipleChoices,{...i},i.label):jsxRuntime.jsx(BlockStyle,{...i},i.label))})]})},SectionContext=React.createContext({}),StylingGroup=({section:o,showAccordian:n})=>{const{t:a}=reactI18next.useTranslation(),l=useSelectedBlockCurrentClasses(),r=React.useCallback((c=[])=>{const d={};for(let u=0;u<l.length;u++)d[l[u].property]=l[u].cls;let m=!0;for(const u in c)if(!lodashEs.has(d,u)||d[u]!==c[u]){m=!1;break}return m},[l]),i=React.useMemo(()=>({}),[]);return jsxRuntime.jsx(SectionContext.Provider,{value:i,children:n?jsxRuntime.jsxs(toggle.AccordionItem,{value:o.heading,className:"border-none",children:[jsxRuntime.jsx(toggle.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(toggle.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"&&r(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"&&r(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})=>jsxRuntime.jsx("svg",{className:o?"rotate-90":"",stroke:"currentColor",fill:"currentColor",strokeWidth:"0",viewBox:"0 0 448 512",height:"14px",width:"14px",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,{}),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:"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,{}),width:1420},{title:"Large Desktop (2XL)",content:"Styles set here are applied at 1536px and up",breakpoint:"2xl",icon:jsxRuntime.jsx(reactIcons.DesktopIcon,{}),width:1920}],BreakpointCard=({canvas:o=!1,openDelay:n=400,tooltip:a=!0,title:l,content:r,currentBreakpoint:i,breakpoint:c,width:d,icon:m,onClick:u})=>{const{t:p}=reactI18next.useTranslation();return a?jsxRuntime.jsxs(toggle.HoverCard,{openDelay:n,children:[jsxRuntime.jsx(toggle.HoverCardTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{onClick:()=>u(d),size:"sm",className:"h-7 w-7 rounded-md p-1",variant:c===i?"outline":"ghost",children:m})}),jsxRuntime.jsx(toggle.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:p(l)}),o&&jsxRuntime.jsx("p",{className:"text-xs",children:p(r)})]})})})]}):jsxRuntime.jsx(toggle.Button,{onClick:()=>u(d),size:"sm",className:"h-7 w-7 rounded-md p-1",variant:c===i?"outline":"ghost",children:m})},Breakpoints$1=({openDelay:o=400,canvas:n=!1,tooltip:a=!0})=>{const[l,,r]=useScreenSizeWidth(),[i,c]=useCanvasDisplayWidth(),[d,m]=useSelectedBreakpoints(),u=d,p=m,{t:g}=reactI18next.useTranslation(),x=useBuilderProp("breakpoints",WEB_BREAKPOINTS),f=b=>{u.includes(b)?u.length>2&&p(u.filter(C=>C!==b)):p(C=>[...C,b])},h=b=>{n||r(b),c(b)},j=commonFunctions.getBreakpointValue(n?i:l).toLowerCase();return x.length<4?jsxRuntime.jsx("div",{className:"flex items-center rounded-md",children:lodashEs.map(x,b=>React.createElement(BreakpointCard,{canvas:n,...b,onClick:h,key:b.breakpoint,currentBreakpoint:j}))}):jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between rounded-md",children:[jsxRuntime.jsx("div",{className:"flex items-center",children:lodashEs.map(x.filter(b=>lodashEs.includes(u,lodashEs.toUpper(b.breakpoint))),b=>React.createElement(BreakpointCard,{canvas:n,openDelay:o,tooltip:a,...b,onClick:h,key:b.breakpoint,currentBreakpoint:j}))}),jsxRuntime.jsxs(toggle.DropdownMenu,{children:[jsxRuntime.jsx(toggle.DropdownMenuTrigger,{asChild:!0,children:jsxRuntime.jsx("span",{className:"cursor-pointer px-2.5 hover:opacity-80",children:jsxRuntime.jsx(reactIcons.DotsVerticalIcon,{className:"scale-90 transform"})})}),jsxRuntime.jsxs(toggle.DropdownMenuContent,{className:"w-56 border-border text-xs",children:[jsxRuntime.jsx(toggle.DropdownMenuLabel,{children:g("Screen sizes")}),jsxRuntime.jsx(toggle.DropdownMenuSeparator,{}),lodashEs.map(x,b=>jsxRuntime.jsx(toggle.DropdownMenuCheckboxItem,{disabled:b.breakpoint==="xs",onCheckedChange:()=>f(lodashEs.toUpper(b.breakpoint)),checked:lodashEs.includes(u,lodashEs.toUpper(b.breakpoint)),children:g(b.title)},b.breakpoint))]})]})]})};function BreakpointSelector(){const[,o]=useScreenSizeWidth(),n=React.useMemo(()=>{const a=WEB_BREAKPOINTS.find(l=>l.breakpoint===o);return a==null?void 0:a.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.jsx("p",{className:"text-xs text-muted-foreground",children:"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]})})})]})}const SECONDS=10;function Countdown(){const[o,n]=React.useState(SECONDS),[a,l]=React.useState(!1);React.useEffect(()=>{if(a&&o>0){const m=setTimeout(()=>{n(o-.1)},100);return()=>clearTimeout(m)}else o<=0&&(l(!1),n(SECONDS))},[a,o]);const r=()=>{l(!0),n(SECONDS)};React.useEffect(()=>{o===SECONDS&&r()},[o]);const i=18,c=2*Math.PI*i,d=c*(1-(SECONDS-o)/SECONDS);return jsxRuntime.jsxs("div",{className:"relative h-4 w-4",children:[jsxRuntime.jsxs("svg",{className:"h-full w-full",viewBox:"0 0 40 40",children:[jsxRuntime.jsx("circle",{className:"text-gray-300",strokeWidth:"4",stroke:"currentColor",fill:"transparent",r:i,cx:"20",cy:"20"}),jsxRuntime.jsx("circle",{className:"text-blue-600",strokeWidth:"4",strokeDasharray:c,strokeDashoffset:d,strokeLinecap:"round",stroke:"currentColor",fill:"transparent",r:i,cx:"20",cy:"20"})]}),jsxRuntime.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:jsxRuntime.jsx("span",{className:"text-xs font-semibold",children:" "})})]})}const AskAIStyles=({blockId:o})=>{const{t:n}=reactI18next.useTranslation(),{askAi:a,loading:l,error:r}=useAskAi(),[i,c]=React.useState(""),d=React.useRef(null),m=React.useRef(null),[u,p]=React.useState();React.useEffect(()=>{var x;(x=d.current)==null||x.focus()},[]);const g=x=>{const{usage:f}=x||{};!r&&f&&p(f),m.current=setTimeout(()=>p(void 0),1e4),r||c("")};return jsxRuntime.jsxs("div",{className:"",children:[jsxRuntime.jsx("h2",{className:"mb-1 text-sm font-semibold leading-none tracking-tight",children:n("Ask AI")}),jsxRuntime.jsx(toggle.Textarea,{ref:d,value:i,onChange:x=>c(x.target.value),placeholder:n("Ask AI to edit styles"),className:"no-scrollbar my-2 w-full border border-border p-2 text-xs",rows:4,onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),m.current&&clearTimeout(m.current),p(void 0),a("styles",o,i,g))}}),jsxRuntime.jsxs("div",{className:"my-2 flex items-center gap-2",children:[l?null:jsxRuntime.jsx(toggle.Button,{disabled:i.trim().length<5||l,onClick:()=>{m.current&&clearTimeout(m.current),p(void 0),a("styles",o,i,g)},variant:"default",className:"w-fit",size:"sm",children:l?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader,{className:"h-5 w-5 animate-spin"}),n("Generating... Please wait...")]}):n("Edit with AI")}),l?jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsxs(toggle.Skeleton,{className:"flex w-full items-center space-x-1 px-4 py-1 pl-2",children:[jsxRuntime.jsx(lucideReact.Loader,{className:"h-4 w-4 animate-spin text-gray-500",size:16}),jsxRuntime.jsx("p",{className:"text-xs",children:n("Generating... Please wait...")})]}),jsxRuntime.jsx(toggle.Button,{variant:"destructive",onClick:()=>stop(),className:"hidden w-fit",size:"sm",children:n("Stop")})]}):null]}),u?jsxRuntime.jsx("div",{className:"max-w-full",children:jsxRuntime.jsxs("p",{className:"mb-1 flex justify-between break-words rounded border border-blue-500 bg-blue-100 p-1 text-xs text-blue-500",children:[jsxRuntime.jsxs("span",{children:[n("Total tokens used"),": ",u.totalTokens]}),jsxRuntime.jsx(Countdown,{})]})}):null,jsxRuntime.jsx("div",{className:"max-w-full",children:r&&jsxRuntime.jsx("p",{className:"break-words rounded border border-red-500 bg-red-100 p-1 text-xs text-red-500",children:r.message})})]})};function ManualClasses(){var N;const o=React.useRef(null),[n,a]=React.useState(""),[l,r]=React.useState(-1),i=useFuseSearch(),{t:c}=reactI18next.useTranslation(),[d]=useSelectedStylingBlocks(),m=useSelectedBlock(),u=useAddClassesToBlocks(),p=useRemoveClassesFromBlocks(),[g]=useSelectedBlockIds(),x=useBuilderProp("askAiCallBack",null),[f,h]=React.useState(""),j=(N=lodashEs.first(d))==null?void 0:N.prop,{classes:b}=applyBinding.getSplitChaiClasses(lodashEs.get(m,j,"")),C=b.split(" ").filter(I=>!lodashEs.isEmpty(I)),B=()=>{const I=f.trim().toLowerCase().replace(/ +(?= )/g,"").split(" ");u(g,I,!0),h("")},[w,_]=React.useState([]),S=({value:I})=>{const L=I.trim().toLowerCase(),T=L.match(/.+:/g);let D=[];if(T&&T.length>0){const[P]=T,M=L.replace(P,"");D=i.search(M).map(O=>({...O,item:{...O.item,name:P+O.item.name}}))}else D=i.search(L);return _(lodashEs.map(D,"item"))},y=()=>{_([])},E=I=>I.name,A=I=>jsxRuntime.jsx("div",{className:"rounded-md p-1",children:I.name}),R=React.useMemo(()=>({ref:o,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,placeholder:c("Enter classes separated by space"),value:f,onFocus:I=>{setTimeout(()=>{I.target&&I.target.select()},0)},onKeyDown:I=>{I.key==="Enter"&&f.trim()!==""&&B()},onChange:(I,{newValue:L})=>h(L),className:"w-full rounded-md text-xs px-2 hover:outline-0 bg-background border-border py-1"}),[f,c,o]),k=I=>{debugger;const L=n.trim().toLowerCase().replace(/ +(?= )/g,"").split(" ");p(g,[I]),u(g,L,!0),a(""),r(-1)},v=()=>{if(navigator.clipboard===void 0){sonner.toast.error(c("Clipboard not supported"));return}navigator.clipboard.writeText(C.join(" ")),sonner.toast.success(c("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.jsxs("div",{className:"flex items-center justify-between gap-x-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 text-muted-foreground",children:[jsxRuntime.jsx("span",{children:c("Classes")}),jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactIcons.CopyIcon,{onClick:v,className:"cursor-pointer"})}),jsxRuntime.jsx(toggle.TooltipContent,{children:jsxRuntime.jsx("p",{children:c("Copy classes to clipboard")})})]})]}),x?jsxRuntime.jsxs(toggle.Popover,{children:[jsxRuntime.jsx(toggle.PopoverTrigger,{asChild:!0,children:jsxRuntime.jsxs(toggle.Button,{variant:"default",className:"h-6 w-fit",size:"sm",children:[jsxRuntime.jsx(lucideReact.SparklesIcon,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{className:"ml-2",children:c("Ask AI")})]})}),jsxRuntime.jsx(toggle.PopoverContent,{side:"left",className:"p-2",children:jsxRuntime.jsx(AskAIStyles,{blockId:m==null?void 0:m._id})})]}):null]}),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:S,onSuggestionsClearRequested:y,getSuggestionValue:E,renderSuggestion:A,inputProps:R,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(toggle.Button,{variant:"outline",className:"h-6 border-border",onClick:B,disabled:f.trim()==="",size:"sm",children:jsxRuntime.jsx(reactIcons.PlusIcon,{})})]}),jsxRuntime.jsx("div",{className:"flex w-full flex-wrap gap-2 overflow-x-hidden",children:C.map((I,L)=>l===L?jsxRuntime.jsx("input",{ref:o,value:n,onChange:T=>a(T.target.value),onBlur:()=>{k(I)},onKeyDown:T=>{T.key==="Enter"&&k(I)},onFocus:T=>{setTimeout(()=>{T.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"},I):jsxRuntime.jsx("div",{className:"group relative flex max-w-[260px] items-center",children:jsxRuntime.jsxs("button",{onDoubleClick:()=>{h(I),p(g,[I]),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:()=>p(g,[I],!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"}),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:I})]})},I))})]})}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",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",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(),[l,r]=React.useState(""),[i,c]=React.useState({onDrag:u=>u,onDragEnd:u=>u,dragStartY:0,dragging:!1,dragStartValue:0,dragUnit:"",negative:!1,cssProperty:""}),d=web.useThrottledCallback(u=>{const p=!lodashEs.get(i,"negative",!1),g=lodashEs.get(i,"cssProperty","");let x=parseFloat(i.dragStartValue);x=isNaN(x)?0:x;let f=MAPPER[i.dragUnit];(lodashEs.startsWith(g,"scale")||g==="opacity")&&(f=10);let j=(i.dragStartY-u.pageY)/f+x;p&&j<0&&(j=0),g==="opacity"&&j>1&&(j=1),i.onDrag(`${j}`),r(`${j}`)},[i],50),m=React.useCallback(()=>{setTimeout(()=>i.onDragEnd(`${l}`),100),c({onDrag:u=>u,onDragEnd:u=>u,dragStartY:0,dragging:!1,dragStartValue:0,dragUnit:"",negative:!1,cssProperty:""})},[i,l,c]);return lodashEs.isEmpty(a)?null:jsxRuntime.jsxs(BlockSettingsContext.Provider,{value:{setDragData:c},children:[i.dragging?jsxRuntime.jsx("div",{onMouseMove:d,onMouseUp:()=>m(),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(toggle.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:l})=>{const[,r]=jotai.useAtom(draggedBlockAtom),{type:i,icon:c,label:d}=o,{addCoreBlock:m,addPredefinedBlock:u}=useAddBlock(),[,p]=useSelectedBlockIds(),{clearHighlight:g}=useBlockHighlight(),x=()=>{if(lodashEs.has(o,"blocks")){const j=lodashEs.isFunction(o.blocks)?o.blocks():o.blocks;u(runtime.syncBlocksWithDefaults(j),a||null,l)}else m(o,a||null,l);pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)},f=flagged.useFeature("dnd"),{t:h}=reactI18next.useTranslation();return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("button",{disabled:n,onClick:x,type:"button",onDragStart:j=>{j.dataTransfer.setData("text/plain",JSON.stringify(lodashEs.omit(o,["component","icon"]))),j.dataTransfer.setDragImage(new Image,0,0),r(lodashEs.omit(o,["component","icon"])),setTimeout(()=>{p([]),g()},200)},draggable:f?"true":"false",className:"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",children:[React.createElement(c||reactIcons.BoxIcon,{className:"w-4 h-4 mx-auto"}),jsxRuntime.jsx("p",{className:"truncate text-xs",children:lodashEs.capitalize(h(d||i))})]})}),jsxRuntime.jsx(toggle.TooltipContent,{children:jsxRuntime.jsx("p",{children:h(d||i)})})]})})},DefaultChaiBlocks=({parentId:o,position:n,gridCols:a="grid-cols-2"})=>{const l=runtime.useRegisteredChaiBlocks(),r=lodashEs.groupBy(l,"category"),i=lodashEs.uniq(lodashEs.map(r.core,"group"));return jsxRuntime.jsx(ChaiBuilderBlocks,{gridCols:a,parentId:o,position:n,groups:i,blocks:r.core})},hasVideoEmbed=o=>{const n=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,a=/(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;return n.test(o)||a.test(o)},getVideoURLFromHTML=o=>{if(lodashEs.isEmpty(o))return o;const n=/<video[^>]+src=['"]([^'">]+)['"]/,a=/<iframe[^>]+src=['"]([^'">]+)['"]/,l=o.match(n),r=o.match(a),i=l?l[1]:r?r[1]:null,c=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,d=/(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;return i&&(c.test(i)||d.test(i))?i:o},NAME_ATTRIBUTES=["chai-name","data-chai-name"],ATTRIBUTE_MAP={img:{alt:"alt",width:"width",height:"height",src:"image"},video:{src:"url",autoplay:"controls.autoPlay",muted:"controls.muted",loop:"controls.loop",controls:"controls.widgets"},a:{href:"link.href",target:"link.target",type:""},input:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},textarea:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},select:{placeholder:"placeholder",required:"required",multiple:"multiple",name:"fieldName"},form:{action:"action"}},shouldAddText=(o,n)=>o.children.length===1&&lodashEs.includes(["Heading","Paragraph","Span","ListItem","Button","Label","TableCell","Link","RichText"],n._type),getTextContent=o=>o.map(n=>n.type==="text"?lodashEs.get(n,"content",""):lodashEs.isEmpty(n.children)?"":getTextContent(n.children)).join(""),getSanitizedValue=o=>o===null?"":o,getHeightAndWidthFromClass=o=>{const n=lodashEs.compact(lodashEs.map(o.split(/\s+/),lodashEs.trim)),a=lodashEs.find(n,d=>/^w-/.test(d)),l=lodashEs.find(n,d=>/^h-/.test(d));if(!l||!a)return{height:"",width:""};const r=d=>{if(!d)return;const m=d.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);if(!m)return;if(m[1])return m[1];const u=m[2];return/^\d+(\.\d+)?$/.test(u)?`${Number(u)*4}px`:u==="auto"||lodashEs.includes(u,"%")?u:"16px"},i=r(a),c=r(l);return{width:lodashEs.includes(i,"px")?i:"16px",height:lodashEs.includes(c,"px")?c:"16px"}},getAttrs=o=>{if(o.tagName==="svg")return{};const n={},a=ATTRIBUTE_MAP[o.tagName]||{},l=o.attributes;return lodashEs.forEach(l,({key:r,value:i})=>{if(!lodashEs.includes(NAME_ATTRIBUTES,r))if(a[r]){if(o.tagName==="img"&&r==="src"&&!i.startsWith("http")){const c=lodashEs.find(o.attributes,{key:"width"}),d=lodashEs.find(o.attributes,{key:"height"});c&&d?i=`https://via.placeholder.com/${c==null?void 0:c.value}x${d==null?void 0:d.value}`:i="https://via.placeholder.com/150x150"}lodashEs.set(n,a[r],getSanitizedValue(i))}else lodashEs.includes(["style","class","srcset"],r)||(lodashEs.has(n,"styles_attrs")||(n.styles_attrs={}),lodashEs.startsWith(r,"@")&&(r=r.replace("@","x-on:")),n.styles_attrs[`${r}`]=getSanitizedValue(i))}),delete n.class,n},getStyles=(o,n="styles")=>{if(!o.attributes)return{[n]:`${applyBinding.STYLES_KEY},`};const a=lodashEs.find(o.attributes,{key:"class"});if(a){const l=a.value;return{[n]:`${applyBinding.STYLES_KEY},${l}`}}return{[n]:`${applyBinding.STYLES_KEY},`}},getBlockProps=o=>{const n=lodashEs.get(o,"attributes",[]),a=n.find(d=>d.key==="data-chai-richtext"||d.key==="chai-richtext"),l=n.find(d=>d.key==="data-chai-lightbox"||d.key==="chai-lightbox"),r=n.find(d=>d.key==="data-chai-dropdown"||d.key==="chai-dropdown"),i=n.find(d=>d.key==="data-chai-dropdown-button"||d.key==="chai-dropdown-button"),c=n.find(d=>d.key==="data-chai-dropdown-content"||d.key==="chai-dropdown-content");if(r)return{_type:"Dropdown"};if(i)return{_type:"DropdownButton"};if(c)return{_type:"DropdownContent"};if(a)return{_type:"RichText"};if(l)return{_type:"LightBoxLink"};switch(o.tagName){case"img":return{_type:"Image"};case"input":return{_type:"Input",showLabel:!1};case"hr":return{_type:"Divider"};case"br":return{_type:"LineBreak"};case"textarea":return{_type:"TextArea",showLabel:!1};case"audio":return{_type:"Audio"};case"canvas":return{_type:"Canvas"};case"video":case"iframe":return{_type:"CustomHTML"};case"svg":return{_type:"Icon"};case"select":return{_type:"Select",options:[]};case"option":return{_type:"Option"};case"ul":case"ol":case"dl":return{_type:"List",tag:o.tagName,_listType:o.tagName==="ol"?"list-decimal":"list-none"};case"li":case"dt":return{_type:"ListItem",tag:o.tagName};case"span":case"figcaption":case"legend":return{_type:"Span",tag:o.tagName};case"p":return{_type:"Paragraph",content:""};case"a":return{_type:"Link"};case"form":return{_type:"Form"};case"label":return{_type:"Label"};case"button":return{_type:"Button"};case"code":return{_type:"Box",_name:"Code"};case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":return{_type:"Heading",tag:o.tagName};case"table":return{_type:"Table"};case"tr":return{_type:"TableRow"};case"td":case"th":return{_type:"TableCell",tag:o.tagName};case"thead":return{_type:"TableHead"};case"tbody":return{_type:"TableBody"};case"tfoot":return{_type:"TableFooter"};default:{const d=lodashEs.get(o,"children",[]).length>0?"Box":"EmptyBox";return{_type:d,tag:o.tagName,_name:d=="EmptyBox"||o.tagName==="div"?d:lodashEs.capitalize(o.tagName)}}}},traverseNodes=(o,n=null)=>lodashEs.flatMapDeep(o,a=>{var g,x,f,h,j,b,C,B,w,_;if(a.type==="comment")return[];let l={_id:commonFunctions.generateUUID()};if(n&&(l._parent=n.block._id),a.type==="text")return lodashEs.isEmpty(lodashEs.get(a,"content",""))?[]:n&&shouldAddText(n.node,n.block)?(lodashEs.set(n,"block.content",lodashEs.get(a,"content","")),[]):{...l,_type:"Text",content:lodashEs.get(a,"content","")};const r=lodashEs.get(a,"attributes",[]),i=r.find(S=>S.key==="data-chai-richtext"||S.key==="chai-richtext"),c=r.find(S=>S.key==="data-chai-lightbox"||S.key==="chai-lightbox"),d=r.find(S=>S.key==="data-chai-dropdown"||S.key==="chai-dropdown"),m=r.find(S=>S.key==="data-chai-dropdown-button"||S.key==="chai-dropdown-button"),u=r.find(S=>S.key==="data-chai-dropdown-content"||S.key==="chai-dropdown-content");if(l={...l,...getBlockProps(a),...getAttrs(a),...getStyles(a)},a.attributes){const S=a.attributes.find(y=>lodashEs.includes(NAME_ATTRIBUTES,y.key));S&&(l._name=S.value)}if(i)return l.content=himalaya.stringify(a.children),lodashEs.has(l,"styles_attrs.data-chai-richtext")&&delete l.styles_attrs["data-chai-richtext"],lodashEs.has(l,"styles_attrs.chai-richtext")&&delete l.styles_attrs["chai-richtext"],[l];if(c){const S=["data-chai-lightbox","chai-lightbox","data-vbtype","data-autoplay","data-maxwidth","data-overlay","data-gall","href"];l={...l,href:((g=r.find(y=>y.key==="href"))==null?void 0:g.value)||"",hrefType:((x=r.find(y=>y.key==="data-vbtype"))==null?void 0:x.value)||"video",autoplay:((f=r.find(y=>y.key==="data-autoplay"))==null?void 0:f.value)==="true"?"true":"false",maxWidth:((j=(h=r.find(y=>y.key==="data-maxwidth"))==null?void 0:h.value)==null?void 0:j.replace("px",""))||"",backdropColor:((b=r.find(y=>y.key==="data-overlay"))==null?void 0:b.value)||"",galleryName:((C=r.find(y=>y.key==="data-gall"))==null?void 0:C.value)||""},lodashEs.forEach(S,y=>{lodashEs.has(l,`styles_attrs.${y}`)&&delete l.styles_attrs[y]})}if(d&&(delete l.styles_attrs,l.showDropdown=!1),u&&delete l.styles_attrs,m){delete l.styles_attrs;const S=lodashEs.filter(a.children||[],E=>(E==null?void 0:E.tagName)!=="span");l.content=getTextContent(S);const y=lodashEs.find(a.children||[],E=>(E==null?void 0:E.tagName)==="span"&&lodashEs.some(E.children||[],A=>(A==null?void 0:A.tagName)==="svg"));if(y){const E=lodashEs.find(y.children||[],A=>(A==null?void 0:A.tagName)==="svg");if(E){l.icon=himalaya.stringify([E]);const{height:A,width:R}=getSvgDimensions(E,"16px","16px");l.iconHeight=A,l.iconWidth=R}}return[l]}if(l._type==="Input"){const S=l.inputType||"text";S==="checkbox"?lodashEs.set(l,"_type","Checkbox"):S==="radio"&&lodashEs.set(l,"_type","Radio")}else if(a.tagName==="video"||a.tagName==="iframe"){const S=himalaya.stringify([a]);return hasVideoEmbed(S)&&(lodashEs.set(l,"_type","Video"),lodashEs.set(l,"url",getVideoURLFromHTML(S)),lodashEs.set(l,"styles",`${applyBinding.STYLES_KEY},`),lodashEs.set(l,"controls",{autoPlay:!1,muted:!0,loop:!1,controls:!1})),l.content=S,[l]}else if(a.tagName==="svg"){const S=lodashEs.get(lodashEs.find(a.attributes,{key:"class"}),"value",""),{height:y,width:E}=getHeightAndWidthFromClass(S);if(y&&E)l.styles=`${applyBinding.STYLES_KEY}, ${commonFunctions.cn(`w-${E} h-${y}`,S)}`.trim(),l.height=y==null?void 0:y.replace("px",""),l.width=E==null?void 0:E.replace("px","");else{const A=(B=lodashEs.find(a.attributes,{key:"height"}))==null?void 0:B.value,R=(w=lodashEs.find(a.attributes,{key:"width"}))==null?void 0:w.value;A&&R?(l.styles=`${applyBinding.STYLES_KEY}, ${commonFunctions.cn(`w-[${R}px] h-[${A}px]`,S)}`.trim(),l.height=A,l.width=R):l.styles=`${applyBinding.STYLES_KEY}, ${commonFunctions.cn("w-full h-full",S)}`.trim()}return a.attributes=lodashEs.filter(a.attributes,A=>!lodashEs.includes(["style","width","height","class"],A.key)),l.icon=himalaya.stringify([a]),[l]}else if(a.tagName=="option"&&n&&((_=n.block)==null?void 0:_._type)==="Select")return n.block.options.push({label:getTextContent(a.children),...getAttrs(a)}),[];const p=traverseNodes(a.children,{block:l,node:a});return[l,...p]}),getSvgDimensions=(o,n,a)=>{var m,u;const l=lodashEs.get(o,"attributes",[]),{height:r,width:i}=getHeightAndWidthFromClass(lodashEs.get(lodashEs.find(l,{key:"class"}),"value",""));if(r&&i)return{height:`[${r}px]`,width:`[${i}px]`};const c=(m=lodashEs.find(l,{key:"height"}))==null?void 0:m.value,d=(u=lodashEs.find(l,{key:"width"}))==null?void 0:u.value;return{height:c?`[${c}px]`:a,width:d?`[${d}px]`:n}},getSanitizedHTML=o=>{o=o.replace(/(\w+)=\\?"(.*?)\\?"/g,(l,r,i)=>{let c=i.replace(/\\"/g,'"');return c=c.replace(/{([^}]+)}/g,d=>d.replace(/"/g,'\\"')),`${r}="${c.replace(/\\"/g,'"')}"`}),o=o.replace(/\\n/g,"").replace(/\\\\/g,"").replace(/\\([/<>])/g,"$1").replace(/\\./g,"").replace(/[\n\r\t\f\v]/g,""),o=o.replace(/\$name="[^"]*"/g,"");const n=o.match(/<body[^>]*>[\s\S]*?<\/body>/);return(n&&n.length>0?n[0].replace(/<body/,"<div").replace(/<\/body>/,"</div>"):o).replace(/\s+/g," ").replaceAll("> <","><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").trim()},getBlocksFromHTML=o=>{const n=himalaya.parse(getSanitizedHTML(o));return lodashEs.isEmpty(o)?[]:lodashEs.flatten(traverseNodes(n))},ImportHTML=({parentId:o,position:n})=>{const{t:a}=reactI18next.useTranslation(),[l,r]=React.useState(""),{addPredefinedBlock:i}=useAddBlock(),c=()=>{const d=getBlocksFromHTML(l);i([...d],o,n),r(""),pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)};return jsxRuntime.jsxs(toggle.Card,{className:"border-border/0 p-0 shadow-none",children:[jsxRuntime.jsx(toggle.CardHeader,{className:"p-3",children:jsxRuntime.jsx(toggle.CardDescription,{children:a("Use HTML snippets from Tailwind CSS component libraries")})}),jsxRuntime.jsx(toggle.CardContent,{className:"space-y-2 px-3 py-0",children:jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx(toggle.Label,{htmlFor:"current",className:"text-sm",children:a("Tailwind HTML snippet")}),jsxRuntime.jsx(toggle.Textarea,{autoFocus:!0,tabIndex:1,ref:d=>d&&d.focus(),onChange:d=>r(d.target.value),rows:12,value:l,placeholder:a("Enter your code snippet here"),className:"resize-none overflow-x-auto whitespace-pre bg-background font-mono text-xs font-normal"})]})}),jsxRuntime.jsx(toggle.CardFooter,{className:"flex flex-col justify-end p-3",children:jsxRuntime.jsx(toggle.Button,{disabled:l.trim()==="",onClick:()=>c(),size:"sm",className:"w-fit",children:a("Import HTML")})})]})},ChaiSelect=({defaultValue:o="",onValueChange:n,options:a,placeholder:l="Select",className:r="",height:i=""})=>{const[c,d]=React.useState(o),m=u=>{const p=u.target.value;d(p),n(p)};return jsxRuntime.jsx("div",{className:commonFunctions.cn("relative inline-block w-full",r),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",i),value:c,onChange:m,children:[jsxRuntime.jsx("option",{value:"",disabled:!0,children:l}),a.map(u=>jsxRuntime.jsx("option",{value:u.value,children:u.label},u.value))]})})};function UILibrariesSelect({uiLibraries:o,library:n,setLibrary:a}){const{t:l}=reactI18next.useTranslation();return n?jsxRuntime.jsxs("div",{className:"h-12",children:[jsxRuntime.jsx("p",{className:"text-xs font-bold text-gray-500",children:l("Choose library")}),jsxRuntime.jsx(ChaiSelect,{className:"mb-1",options:o.map(r=>({value:r.id,label:r.name})),defaultValue:n,onValueChange:r=>a(r)})]}):null}let LIBRARIES_REGISTRY={};const registerChaiLibrary=(o,n)=>{LIBRARIES_REGISTRY[o]={...n,id:o}},useChaiLibraries=()=>lodashEs.values(LIBRARIES_REGISTRY),BlockCard=({block:o,library:n,parentId:a=void 0,position:l=-1})=>{const[r,i]=React.useState(!1),c=React.useMemo(()=>(n==null?void 0:n.getBlock)||(()=>[]),[n]),{addCoreBlock:d,addPredefinedBlock:m}=useAddBlock(),[,u]=useSelectedBlockIds(),{clearHighlight:p}=useBlockHighlight(),g=lodashEs.get(o,"name",lodashEs.get(o,"label")),x=lodashEs.get(o,"description",""),f=flagged.useFeature("dnd"),[,h]=jotai.useAtom(draggedBlockAtom),j=B=>{const w=lodashEs.has(B,"styles_attrs.data-page-section");return B._type==="Box"&&w},b=React.useCallback(async B=>{if(B.stopPropagation(),lodashEs.has(o,"component")){d(o,a,l),pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK);return}i(!0);let w=await c({library:n,block:o});typeof w=="string"&&(w=getBlocksFromHTML(w)),lodashEs.isEmpty(w)||m(runtime.syncBlocksWithDefaults(w),a,l),pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)},[d,m,o,c,n,a,l]),C=async B=>{const w=await c({library:n,block:o});let _=a;if(j(lodashEs.first(w))&&(_=null),!lodashEs.isEmpty(w)){const S={blocks:w,uiLibrary:!0,parent:_};if(B.dataTransfer.setData("text/plain",JSON.stringify(S)),o.preview){const y=new Image;y.src=o.preview,y.onload=()=>{B.dataTransfer.setDragImage(y,0,0)}}else B.dataTransfer.setDragImage(new Image,0,0);h(S),setTimeout(()=>{u([]),p(),pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)},200)}};return jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{onClick:r?()=>{}:b,draggable:f?"true":"false",onDragStart:C,className:clsx("relative mt-2 cursor-pointer overflow-hidden rounded-md border border-border duration-200 hover:border-blue-500 hover:shadow-xl"),children:[r&&jsxRuntime.jsxs("div",{className:"absolute flex h-full w-full items-center justify-center bg-black/70",children:[jsxRuntime.jsx(lucideReact.Loader,{className:"animate-spin",size:15,color:"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:g}):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:g}),x&&jsxRuntime.jsx("p",{className:"text-sm text-gray-600",children:x})]})]})}),jsxRuntime.jsx(toggle.TooltipContent,{children:jsxRuntime.jsxs("div",{className:"max-w-xs",children:[jsxRuntime.jsx("p",{className:"font-medium",children:g}),x&&o.preview&&jsxRuntime.jsx("p",{className:"mt-1 text-xs text-primary-foreground",children:x})]})})]})},UILibrarySection=({parentId:o,position:n})=>{const[a,l]=useSelectedLibrary(),r=useChaiLibraries(),i=r.find(k=>k.id===a)||lodashEs.first(r),{data:c,isLoading:d,resetLibrary:m}=useLibraryBlocks(i),[u,p]=React.useState(""),[g,x]=React.useState([]),f=React.useRef(null);React.useEffect(()=>{c&&c.length>0&&(f.current=new Fuse(c,{keys:["name","label","description","group"],threshold:.4,ignoreLocation:!0}))},[c]),React.useEffect(()=>{if(!u.trim()||!f.current){x([]);return}const k=f.current.search(u).map(v=>v.item);x(k)},[u]);const h=u.trim()&&!lodashEs.isEmpty(g)?g:c,j=lodashEs.groupBy(h,"group"),[b,C]=React.useState(null);React.useEffect(()=>{if(lodashEs.isEmpty(lodashEs.keys(j))){C(null);return}if(!b||!j[b]){C(lodashEs.first(lodashEs.keys(j)));return}},[j,b]);const B=lodashEs.get(j,b,[]),w=React.useRef(null),{t:_}=reactI18next.useTranslation(),S=k=>{w.current&&(clearTimeout(w.current),w.current=null),w.current=setTimeout(()=>{w.current&&C(k)},400)},y=()=>{i!=null&&i.id&&m(i.id)},E=()=>{p("")};if(d)return jsxRuntime.jsxs("div",{className:"mt-4 grid h-full w-full grid-cols-12 gap-2",children:[jsxRuntime.jsx(toggle.Skeleton,{className:"col-span-3 h-full"}),jsxRuntime.jsx(toggle.Skeleton,{className:"col-span-9 h-full"})]});const A=lodashEs.filter(B,(k,v)=>v%2===0),R=lodashEs.filter(B,(k,v)=>v%2===1);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"flex h-full max-h-full flex-col",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-2 border-border py-2",children:jsxRuntime.jsxs("div",{className:"relative w-full",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-2 top-2.5 h-4 w-4 text-muted-foreground"}),jsxRuntime.jsx(toggle.Input,{placeholder:_("Search blocks..."),value:u,onChange:k=>p(k.target.value),className:"w-full pl-8 pr-8"}),u&&jsxRuntime.jsx("button",{onClick:E,className:"absolute right-2 top-2.5 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(lucideReact.X,{className:"h-4 w-4"})})]})}),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",children:[jsxRuntime.jsxs("div",{className:"flex h-full max-h-full w-60 min-w-60 max-w-60 flex-col gap-1 px-1 pr-2",children:[jsxRuntime.jsx(UILibrariesSelect,{library:i==null?void 0:i.id,setLibrary:l,uiLibraries:r}),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:_("Groups")}),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 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:u?jsxRuntime.jsx("p",{className:"text-sm",children:_("No matching blocks found")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("p",{className:"text-sm",children:_("Failed to load the UI library. Try again")}),jsxRuntime.jsxs(toggle.Button,{onClick:y,variant:"outline",size:"sm",className:"gap-2",children:[jsxRuntime.jsx(lucideReact.RefreshCw,{className:"h-4 w-4"}),_("Retry")]})]})}):lodashEs.map(j,(k,v)=>jsxRuntime.jsxs("div",{onMouseEnter:()=>S(v),onMouseLeave:()=>clearTimeout(w.current),role:"button",onClick:()=>C(v),className:commonFunctions.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",v===b?"bg-primary text-primary-foreground hover:bg-primary/80":""),children:[jsxRuntime.jsx("span",{children:lodashEs.capitalize(_(v.toLowerCase()))}),jsxRuntime.jsx(reactIcons.CaretRightIcon,{className:"ml-2 h-5 w-5"})]},v))})]})]}),jsxRuntime.jsx("div",{className:"flex h-full max-h-full w-full flex-col border-l border-border",children:jsxRuntime.jsxs(toggle.ScrollArea,{onMouseEnter:()=>w.current?clearTimeout(w.current):null,className:"z-10 flex h-full max-h-full w-full flex-col gap-2 transition-all ease-linear",children:[lodashEs.isEmpty(B)&&!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:_("No blocks found in this group")})}):jsxRuntime.jsxs("div",{className:"grid w-full grid-cols-2 gap-2 px-2",children:[jsxRuntime.jsx("div",{className:"flex flex-col gap-1",children:A.map((k,v)=>jsxRuntime.jsx(BlockCard,{parentId:o,position:n,block:k,library:i},`block-${v}`))}),jsxRuntime.jsx("div",{className:"flex flex-col gap-1",children:R.map((k,v)=>jsxRuntime.jsx(BlockCard,{parentId:o,position:n,block:k,library:i},`block-second-${v}`))})]}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]})})]})})]})})},UILibrariesPanel=({parentId:o,position:n})=>jsxRuntime.jsx(UILibrarySection,{parentId:o,position:n}),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"})=>{const{data:l,isLoading:r,refetch:i,error:c}=usePartialBlocksList(),[d,m]=jotai.useAtom(partialBlocksDataAtom),[u,p]=jotai.useAtom(hasInitializedPartialBlocksAtom);React.useEffect(()=>{if(!u||Object.keys(d.blocks).length===0)if(c)m({blocks:[],groups:[],isLoading:!1,error:c}),p(!0);else if(!r&&Object.keys(l||{}).length>0){const x=Object.entries(l).map(([h,j])=>{const b=j,C=b.type||"partial",B=formatReadableName(C);return{type:"PartialBlock",label:formatReadableName(b.name||h),description:b.description||"",icon:lucideReact.Globe,group:B,category:"partial",partialBlockId:h,_name:b.name}}),f=lodashEs.uniq(lodashEs.map(x,"group"));m({blocks:x,groups:f,isLoading:!1,error:null}),p(!0)}else r?m(x=>({...x,isLoading:!0,error:null})):!r&&Object.keys(l||{}).length===0&&(m({blocks:[],groups:[],isLoading:!1,error:"No partial blocks available"}),p(!0))},[r,l,u,p,m,d.blocks,c]);const g=()=>{m(x=>({...x,isLoading:!0,error:null})),p(!1),i()};return d.isLoading?jsxRuntime.jsx("div",{className:"flex items-center justify-center p-8 text-center text-muted-foreground",children:"Loading partial blocks..."}):d.error||d.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:d.error||"No partial blocks available"}),jsxRuntime.jsx("button",{onClick:g,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:d.groups,blocks:d.blocks})},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:l,gridCols:r="grid-cols-4"})=>{var R;const{t:i}=reactI18next.useTranslation(),[c]=useBlocksStore(),[d,m]=React.useState(""),u=React.useRef(null),[p]=jotai.useAtom(addBlockTabAtom),g=(R=lodashEs.find(c,k=>k._id===a))==null?void 0:R._type,[x,f]=React.useState("all"),[h,j]=React.useState(null),b=React.useRef(null);React.useEffect(()=>{const k=setTimeout(()=>{var v;(v=u.current)==null||v.focus()},0);return()=>clearTimeout(k)},[p]),React.useEffect(()=>{d&&(f("all"),j(null))},[d]),React.useEffect(()=>(b.current=lodashEs.debounce(k=>{f(k)},500),()=>{b.current&&b.current.cancel()}),[]);const C=React.useCallback(k=>{j(k),b.current&&b.current(k)},[]),B=React.useCallback(()=>{j(null),b.current&&b.current.cancel()},[]),w=React.useCallback(k=>{b.current&&b.current.cancel(),f(k),j(null)},[]),_=React.useMemo(()=>d?lodashEs.values(n).filter(k=>{var v,N;return(((v=k.label)==null?void 0:v.toLowerCase())+" "+((N=k.type)==null?void 0:N.toLowerCase())).includes(d.toLowerCase())}):n,[n,d]),S=React.useMemo(()=>d?o.filter(k=>lodashEs.reject(lodashEs.filter(lodashEs.values(_),{group:k}),{hidden:!0}).length>0):o.filter(k=>lodashEs.reject(lodashEs.filter(lodashEs.values(n),{group:k}),{hidden:!0}).length>0),[n,_,o,d]),y=React.useMemo(()=>lodashEs.sortBy(S,k=>CORE_GROUPS.indexOf(k)===-1?99:CORE_GROUPS.indexOf(k)),[S]),E=React.useMemo(()=>x==="all"?_:lodashEs.filter(lodashEs.values(_),{group:x}),[_,x]),A=React.useMemo(()=>x==="all"?y:[x],[y,x]);return jsxRuntime.jsxs("div",{className:"mx-auto flex h-full w-full max-w-3xl flex-col",children:[jsxRuntime.jsx("div",{className:"sticky top-0 z-10 bg-background/80 px-4 py-2 backdrop-blur-sm",children:jsxRuntime.jsx(toggle.Input,{ref:u,type:"search",placeholder:i("Search blocks..."),value:d,className:"-ml-2",onChange:k=>m(k.target.value)})}),jsxRuntime.jsxs("div",{className:"sticky top-10 flex h-[calc(100%-48px)] overflow-hidden",children:[y.length>0&&jsxRuntime.jsx("div",{className:"w-1/4 min-w-[120px] border-r border-border",children:jsxRuntime.jsx(toggle.ScrollArea,{className:"h-full",children:jsxRuntime.jsxs("div",{className:"space-y-1 p-2",children:[jsxRuntime.jsx("button",{onClick:()=>w("all"),onMouseEnter:()=>C("all"),onMouseLeave:B,className:`w-full rounded-md px-2 py-1.5 text-left text-sm font-medium ${x==="all"||h==="all"?"bg-primary text-primary-foreground":"hover:bg-primary/50 hover:text-primary-foreground"}`,children:i("All")},"sidebar-all"),y.map(k=>jsxRuntime.jsx("button",{onClick:()=>w(k),onMouseEnter:()=>C(k),onMouseLeave:B,className:`w-full rounded-md px-2 py-1.5 text-left text-sm ${x===k||h===k?"bg-primary text-primary-foreground":"hover:bg-primary/50 hover:text-primary-foreground"}`,children:lodashEs.capitalize(i(k.toLowerCase()))},`sidebar-${k}`))]})})}),jsxRuntime.jsx("div",{className:"h-full w-3/4 flex-1 overflow-hidden",children:jsxRuntime.jsx(toggle.ScrollArea,{id:"add-blocks-scroll-area",className:"no-scrollbar mr-4 h-full",children:S.length===0&&d?jsxRuntime.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center text-muted-foreground",children:jsxRuntime.jsxs("p",{children:[i("No blocks found matching"),' "',d,'"']})}):jsxRuntime.jsx("div",{className:"space-y-6 p-4",children:A.map(k=>jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("h3",{className:"px-1 text-sm font-medium",children:lodashEs.capitalize(i(k.toLowerCase()))}),jsxRuntime.jsx("div",{className:"grid gap-2 "+r,children:lodashEs.reject(x==="all"?lodashEs.filter(lodashEs.values(E),{group:k}):lodashEs.values(E),{hidden:!0}).map(v=>jsxRuntime.jsx(CoreBlock,{parentId:a,position:l,block:v,disabled:!canAcceptChildBlock(g,v.type)||!canBeNestedInside(g,v.type)},v.type))})]},k))})})})]})]})},addBlockTabAtom=utils.atomWithStorage("__add_block_tab","library"),AddBlocksPanel=({className:o,showHeading:n=!0,parentId:a=void 0,position:l=-1})=>{const{t:r}=reactI18next.useTranslation(),[i,c]=jotai.useAtom(addBlockTabAtom),[,d]=jotai.useAtom(showPredefinedBlockCategoryAtom),m=useBuilderProp("importHTMLSupport",!0),{data:u}=usePartialBlocksList(),p=Object.keys(u||{}).length>0,{hasPermission:g}=usePermissions();React.useEffect(()=>{i==="partials"&&!p&&c("library")},[i,p,c]);const x=React.useCallback(()=>{pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)},[]),f=useChaiAddBlockTabs(),h=m&&g(PERMISSIONS.IMPORT_HTML),b=useChaiLibraries().length>0;return React.useEffect(()=>{i==="library"&&!b&&c("core")},[i,b,c]),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:r("Add block")}),jsxRuntime.jsx("span",{className:"p-0 text-xs font-light leading-3 opacity-80 xl:pl-1",children:r(i==="html"?"Enter or paste TailwindCSS HTML snippet":"Click to add block to page")})]}):null,jsxRuntime.jsxs(toggle.Tabs,{onValueChange:C=>{d(""),c(C)},value:i,className:"flex h-full max-h-full flex-col overflow-hidden",children:[jsxRuntime.jsxs(toggle.TabsList,{className:"flex w-full items-center",children:[b&&jsxRuntime.jsx(toggle.TabsTrigger,{value:"library",children:r("Library")}),jsxRuntime.jsx(toggle.TabsTrigger,{value:"core",children:r("Blocks")}),p&&jsxRuntime.jsx(toggle.TabsTrigger,{value:"partials",children:r("Partials")}),h?jsxRuntime.jsx(toggle.TabsTrigger,{value:"html",children:r("Import")}):null,lodashEs.map(f,C=>jsxRuntime.jsx(toggle.TabsTrigger,{value:C.id,children:React.createElement(C.tab)},`tab-add-block-${C.id}`))]}),jsxRuntime.jsx(toggle.TabsContent,{value:"core",className:"h-full max-h-full flex-1 pb-20",children:jsxRuntime.jsx("div",{className:"-mx-1.5 h-full max-h-full overflow-hidden",children:jsxRuntime.jsx("div",{className:"mt-2 h-full w-full",children:jsxRuntime.jsx(DefaultChaiBlocks,{gridCols:"grid-cols-4",parentId:a,position:l})})})}),b&&jsxRuntime.jsx(toggle.TabsContent,{value:"library",className:"h-full max-h-full flex-1 pb-20",children:jsxRuntime.jsx(UILibrariesPanel,{parentId:a,position:l})}),p&&jsxRuntime.jsx(toggle.TabsContent,{value:"partials",className:"h-full max-h-full flex-1 pb-20",children:jsxRuntime.jsx("div",{className:"-mx-1.5 h-full max-h-full overflow-hidden",children:jsxRuntime.jsx("div",{className:"mt-2 h-full w-full",children:jsxRuntime.jsx(PartialBlocks,{gridCols:"grid-cols-4",parentId:a,position:l})})})}),h?jsxRuntime.jsx(toggle.TabsContent,{value:"html",className:"h-full max-h-full flex-1 pb-20",children:jsxRuntime.jsx(ImportHTML,{parentId:a,position:l})}):null,lodashEs.map(f,C=>jsxRuntime.jsx(toggle.TabsContent,{value:C.id,children:React.createElement(C.tabContent,{close:x,parentId:a,position:l})},`panel-add-block-${C.id}`))]})]})},placeholderStyle={display:"flex",alignItems:"center",zIndex:1},DefaultCursor=React.memo(function({top:n,left:a}){const l={position:"absolute",pointerEvents:"none",top:n+"px",left:a+"px",right:0};return jsxRuntime.jsx("div",{style:{...placeholderStyle,...l},children:jsxRuntime.jsx("div",{className:"h-0.5 flex-1 rounded-[1px] bg-green-500"})})}),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[l]=useBlocksStore(),r=React.useMemo(()=>l.find(c=>c._id===o),[l,o]),i=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:i,children:jsxRuntime.jsxs("button",{type:"button",className:"flex !cursor-grab items-center p-0.5","aria-label":`Type: ${r==null?void 0:r._type}`,children:[jsxRuntime.jsx("div",{className:"-mt-0.5 h-3 w-3",children:jsxRuntime.jsx(TypeIcon,{type:r==null?void 0:r._type})}),jsxRuntime.jsx("div",{className:"ml-2 truncate text-[11px]",children:(r==null?void 0:r._name)||(r==null?void 0:r._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 l;const a=((l=o.selectedIds[0])==null?void 0:l.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()};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 l=[...a];return a.forEach(r=>{l.push(...getBlocks(o,r==null?void 0:r._id))}),l},SaveToLibraryModal=()=>{const[o,n]=jotai.useAtom(saveToLibraryModalAtom),{t:a}=reactI18next.useTranslation(),[l]=useBlocksStore(),r=()=>n({isOpen:!1,blockId:null}),i=useSaveToLibraryComponent(),c=React.useMemo(()=>{if(!o.blockId)return[];const d=lodashEs.find(l,{_id:o.blockId});return d==null||delete d._parent,[d,...getBlocks(l,d==null?void 0:d._id)]},[o.blockId,l]);return jsxRuntime.jsx(toggle.Dialog,{open:o.isOpen,onOpenChange:d=>!d&&r(),children:jsxRuntime.jsxs(toggle.DialogContent,{className:"p-4 sm:max-w-[450px]",children:[jsxRuntime.jsx(toggle.DialogHeader,{className:"pb-2",children:jsxRuntime.jsx(toggle.DialogTitle,{children:a("Save to Library")})}),i&&!lodashEs.isEmpty(o.blockId)&&jsxRuntime.jsx(i,{blockId:o.blockId,blocks:c,close:r})]})})},SaveToLibrary=()=>{const o=useSelectedBlock(),{t:n}=reactI18next.useTranslation(),[,a]=jotai.useAtom(saveToLibraryModalAtom),l=useSaveToLibraryComponent(),r=()=>{o&&a({isOpen:!0,blockId:o._id})};return l?jsxRuntime.jsxs(toggle.DropdownMenuItem,{className:"flex items-center gap-x-4 text-xs",onClick:r,children:[jsxRuntime.jsx(lucideReact.SaveIcon,{className:"h-4 w-4"})," ",n(o!=null&&o._libBlockId?"Update library block":"Save to library")]}):null},UnlinkLibraryBlock=()=>{const{t:o}=reactI18next.useTranslation(),n=useSelectedBlock(),a=useUpdateBlocksProps(),l=()=>{a([n._id],{_libBlockId:null})};return jsxRuntime.jsxs(toggle.DropdownMenuItem,{onClick:l,className:"flex items-center gap-x-4 text-xs",children:[jsxRuntime.jsx(lucideReact.UnlinkIcon,{className:"h-4 w-4"})," ",o("Unlink from library")]})},CANNOT_COPY_BLOCKS=!navigator.clipboard,CopyPasteBlocks=()=>{const[o]=useBlocksStore(),[n]=useSelectedBlockIds(),{pasteBlocks:a}=usePasteBlocks(),[,l,r]=useCopyBlocks(),{t:i}=reactI18next.useTranslation(),c=useSelectedBlock(),d=React.useCallback(()=>{const m=n.map(u=>{const p=o.find(g=>g._id===u);return{id:u,data:p}});r(m.map(u=>u.id))?sonner.toast.warning("Partial blocks detected. Clone partial blocks?",{cancel:{label:i("No"),onClick:()=>{l(m.map(u=>u.id)),sonner.toast.dismiss()}},action:{label:i("Yes"),onClick:()=>{l(m.map(u=>u.id),!0),sonner.toast.dismiss()}},position:"top-center"}):l(m.map(u=>u.id))},[n,o,l,r]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!CANNOT_COPY_BLOCKS&&jsxRuntime.jsxs(toggle.DropdownMenuItem,{disabled:!canDuplicateBlock(c==null?void 0:c._type),onClick:d,className:"flex items-center gap-x-4 text-xs",children:[jsxRuntime.jsx(reactIcons.CopyIcon,{})," ",i("Copy")]}),jsxRuntime.jsxs(toggle.DropdownMenuItem,{className:"flex items-center gap-x-4 text-xs",onClick:()=>{a(n)},children:[jsxRuntime.jsx(reactIcons.CardStackIcon,{})," ",i("Paste")]})]})},CutBlocks=()=>{const[o]=useSelectedBlockIds(),[,n]=useCutBlockIds(),{t:a}=reactI18next.useTranslation();return jsxRuntime.jsxs(toggle.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:l}=reactI18next.useTranslation();return jsxRuntime.jsxs(toggle.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,{})," ",l("Remove")]})},RenameBlock=({node:o})=>{const{t:n}=reactI18next.useTranslation();return jsxRuntime.jsxs(toggle.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),o.edit(),o.deselect()},className:"flex items-center gap-x-4 text-xs",children:[jsxRuntime.jsx(lucideReact.PencilIcon,{className:"h-4 w-4"})," ",n("Rename")]})},BlockContextMenuContent=({node:o})=>{const{t:n}=reactI18next.useTranslation(),[a]=useSelectedBlockIds(),l=useDuplicateBlocks(),r=useSelectedBlock(),{hasPermission:i}=usePermissions(),c=React.useCallback(()=>{l(a)},[a,l]),d=React.useMemo(()=>lodashEs.has(r,"_libBlockId")&&!lodashEs.isEmpty(r._libBlockId),[r==null?void 0:r._libBlockId]);return jsxRuntime.jsxs(toggle.DropdownMenuContent,{side:"bottom",className:"border-border text-xs",children:[i(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(toggle.DropdownMenuItem,{disabled:!canAddChildBlock(r==null?void 0:r._type),className:"flex items-center gap-x-4 text-xs",onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,r),children:[jsxRuntime.jsx(lucideReact.PlusIcon,{size:"14"})," ",n("Add block")]}),jsxRuntime.jsxs(toggle.DropdownMenuItem,{disabled:!canDuplicateBlock(r==null?void 0:r._type),className:"flex items-center gap-x-4 text-xs",onClick:c,children:[jsxRuntime.jsx(reactIcons.CardStackPlusIcon,{})," ",n("Duplicate")]})]}),jsxRuntime.jsx(RenameBlock,{node:o}),i(PERMISSIONS.MOVE_BLOCK)&&jsxRuntime.jsx(CutBlocks,{}),i(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsx(CopyPasteBlocks,{}),d&&jsxRuntime.jsx(UnlinkLibraryBlock,{}),i(PERMISSIONS.CREATE_LIBRARY_BLOCK)&&jsxRuntime.jsx(SaveToLibrary,{}),i(PERMISSIONS.DELETE_BLOCK)&&jsxRuntime.jsx(RemoveBlocks,{})]})},BlockMoreOptions=({children:o,id:n,node:a})=>{const[,l]=useSelectedBlockIds();return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs(toggle.DropdownMenu,{onOpenChange:r=>{r&&l([n])},children:[jsxRuntime.jsx(toggle.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 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:l=>l.currentTarget.select(),onBlur:l=>o.submit(l.currentTarget.value),onKeyDown:l=>{l.key==="Enter"&&o.submit(l.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())||""},Node=React.memo(({node:o,style:n,dragHandle:a})=>{var L;const{t:l}=reactI18next.useTranslation(),[r,,i]=useHiddenBlockIds(),[c]=jotai.useAtom(canvasIframeAtom),{hasPermission:d}=usePermissions();let m=null;const u=o.children.length>0,{highlightBlock:p,clearHighlight:g}=useBlockHighlight(),{id:x,data:f,isSelected:h,willReceiveDrop:j,isDragging:b,isEditing:C,handleClick:B}=o,w=T=>{T.stopPropagation(),!r.includes(x)&&o.toggle()},_=T=>{T.isInternal&&(m=T.isOpen,T.isOpen&&T.close())},S=T=>{T.isInternal&&m!==null&&(m?T.open():T.close(),m=null)},[y,E]=jotai.useAtom(currentAddSelection),A=()=>{var T;R(),o.parent.isSelected||E((T=o==null?void 0:o.parent)==null?void 0:T.id)},R=()=>{E(null)},k=T=>{R(),T.stopPropagation(),!o.isOpen&&!r.includes(x)&&o.toggle(),B(T)};React.useEffect(()=>{const T=setTimeout(()=>{j&&!o.isOpen&&!b&&!r.includes(x)&&o.toggle()},500);return()=>clearTimeout(T)},[j,o,b]);const v=(T,D)=>{const P=c.contentDocument||c.contentWindow.document,M=P.querySelector(`[data-block-id=${T}]`);M&&M.setAttribute("data-drop",D);const F=M.getBoundingClientRect(),O=c.getBoundingClientRect();F.top>=O.top&&F.left>=O.left&&F.bottom<=O.bottom&&F.right<=O.right||(P.documentElement.scrollTop=M.offsetTop-O.top)},N=T=>{R();const D=lodashEs.get(o,"parent.id");D!=="__REACT_ARBORIST_INTERNAL_ROOT__"?pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,{_id:D,position:T}):pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,{position:T})};if(x===applyBinding.ROOT_TEMP_KEY)return jsxRuntime.jsxs("div",{className:"group relative w-full cursor-pointer",children:[jsxRuntime.jsx("br",{}),d(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsx("div",{role:"button",onClick:()=>N(-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:"h-2 w-2 stroke-[3]"})," ",l("Add block")]})}),jsxRuntime.jsx("br",{})]});const I=React.useMemo(()=>lodashEs.has(f,"_libBlockId")&&!lodashEs.isEmpty(f._libBlockId)&&(d(PERMISSIONS.CREATE_LIBRARY_BLOCK)||d(PERMISSIONS.EDIT_LIBRARY_BLOCK)),[f,d]);return jsxRuntime.jsx("div",{className:"w-full",children:jsxRuntime.jsxs("div",{onMouseEnter:()=>p(x),onMouseLeave:()=>g(),onClick:k,style:n,"data-node-id":x,ref:r.includes(x)?null:a,onDragStart:()=>_(o),onDragEnd:()=>S(o),onDragOver:T=>{T.preventDefault(),v(x,"yes")},onDragLeave:T=>{T.preventDefault(),v(x,"no")},onDrop:T=>{T.preventDefault(),v(x,"no")},children:[d(PERMISSIONS.ADD_BLOCK)&&(o==null?void 0:o.rowIndex)>0&&(o.parent.isOpen&&canAddChildBlock(lodashEs.get(o,"parent.data._type"))||((L=o==null?void 0:o.parent)==null?void 0:L.id)==="__REACT_ARBORIST_INTERNAL_ROOT__")&&jsxRuntime.jsx("div",{className:"group relative ml-5 h-full w-full cursor-pointer",children:jsxRuntime.jsx("div",{onClick:T=>{T.stopPropagation(),N(o.childIndex)},onMouseEnter:A,onMouseLeave:R,className:"absolute -top-0.5 h-1 w-[90%] rounded bg-primary 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 p-1 outline outline-2 outline-white hover:bg-primary",children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-3 w-3 stroke-[4] text-white"})})})}),jsxRuntime.jsxs("div",{className:cn("group flex w-full cursor-pointer items-center justify-between space-x-px !rounded p-1 outline-none",h?"bg-primary text-primary-foreground":"hover:bg-primary/10 dark:hover:bg-gray-800",j&&canAcceptChildBlock(f._type,"Icon")?"bg-green-200":"",(o==null?void 0:o.id)===y?"bg-primary/10":"",b&&"opacity-20",r.includes(x)?"opacity-50":"",I&&h&&"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:u&&jsxRuntime.jsx("button",{onClick:w,type:"button",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:`h-3 w-3 stroke-[3] ${h?"text-white":"text-slate-400"}`})})}),jsxRuntime.jsxs("div",{className:cn("leading-1 flex items-center",I&&"text-primary/60",I&&h&&"text-primary/80"),children:[jsxRuntime.jsx(TypeIcon,{type:f==null?void 0:f._type}),C?jsxRuntime.jsx(Input,{node:o}):jsxRuntime.jsx("div",{className:"ml-1.5 flex items-center gap-x-1 truncate text-[13px]",onDoubleClick:T=>{T.stopPropagation(),o.edit(),o.deselect()},children:jsxRuntime.jsx("span",{children:getBlockDisplayName(f)})})]})]}),jsxRuntime.jsxs("div",{className:"invisible flex items-center space-x-1.5 pr-2 group-hover:visible",children:[canAddChildBlock(f==null?void 0:f._type)&&!r.includes(x)&&d(PERMISSIONS.ADD_BLOCK)?jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,{_id:x}),className:"cursor-pointer rounded bg-transparent",asChild:!0,children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-3 w-3"})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"isolate z-[9999]",side:"bottom",children:l("Add block")})]}):null,jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{onClick:T=>{T.stopPropagation(),i(x),o.isOpen&&o.toggle()},className:"cursor-pointer rounded bg-transparent",asChild:!0,children:jsxRuntime.jsx(lucideReact.EyeOffIcon,{size:"15"})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"isolate z-[9999]",side:"bottom",children:l("Hide block")})]}),jsxRuntime.jsx(BlockMoreOptions,{node:o,id:x,children:jsxRuntime.jsx(lucideReact.MoreVertical,{size:"15"})})]})]})]})})}),PasteAtRootContextMenu=({parentContext:o,setParentContext:n})=>{const{t:a}=reactI18next.useTranslation(),{canPaste:l,pasteBlocks:r}=usePasteBlocks();return React.useEffect(()=>{l("root")||n(null)},[l("root")]),!o||!l("root")?null:jsxRuntime.jsx("div",{className:"absolute inset-0",children:jsxRuntime.jsxs(toggle.DropdownMenu,{open:!0,onOpenChange:()=>n(null),children:[jsxRuntime.jsx(toggle.DropdownMenuTrigger,{className:"hidden"}),jsxRuntime.jsx(toggle.DropdownMenuContent,{className:"absolute w-28 p-1 text-xs",style:{top:o.y,left:o.x},children:jsxRuntime.jsxs(toggle.DropdownMenuItem,{className:"flex items-center gap-x-4 text-xs",onClick:()=>{r("root"),n(null)},children:[jsxRuntime.jsx(reactIcons.CardStackIcon,{})," ",a("Paste")]})})]})})},useCanMove=()=>{const[o]=useBlocksStore();return(n,a)=>{var i;const l=(i=lodashEs.find(o,{_id:a}))==null?void 0:i._type,r=lodashEs.first(n.map(c=>{var d;return(d=lodashEs.find(o,{_id:c}))==null?void 0:d._type}));return canAcceptChildBlock(l,r)}},ListTree=()=>{const[treeData]=jotai.useAtom(treeDSBlocks),[ids,setIds]=useSelectedBlockIds(),[cutBlocksIds]=useCutBlockIds(),[,setHiddenBlocks]=useHiddenBlockIds(),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,l)=>a.filter(r=>!l.includes(r._id)).map(r=>({...r,children:r.children?o(r.children,l):[]}));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 l;o.preventDefault(),parentContext&&setParentContext(null);const n=o.target,a=n.getAttribute("data-node-id")||((l=n.closest("[data-node-id]"))==null?void 0:l.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 text-center",children:jsxRuntime.jsxs("p",{className:"mb-1.5 text-sm",children:[t("This page is empty"),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),hasPermission(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsxs(toggle.Button,{disabled:!hasPermission(PERMISSIONS.ADD_BLOCK),onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK),variant:"default",size:"sm",children:["+ ",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-2 pb-2 text-sm text-muted-foreground",children:[jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{onClick:()=>setHiddenBlocks([]),variant:"outline",className:"h-fit p-1 disabled:cursor-not-allowed disabled:opacity-50",size:"sm",children:jsxRuntime.jsx(lucideReact.Eye,{className:"h-4 w-4"})})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"isolate z-[9999]",children:t("Show hidden blocks")})]}),jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{className:"h-fit p-1",onClick:()=>{var o;return(o=treeRef==null?void 0:treeRef.current)==null?void 0:o.openAll()},variant:"outline",size:"sm",children:jsxRuntime.jsx(lucideReact.ChevronsUpDown,{size:14})})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"isolate z-[9999]",children:t("Expand all")})]}),jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{className:"h-fit p-1",onClick:()=>{var o;return(o=treeRef==null?void 0:treeRef.current)==null?void 0:o.closeAll()},variant:"outline",size:"sm",children:jsxRuntime.jsx(lucideReact.ChevronsDownUp,{size:14})})}),jsxRuntime.jsx(toggle.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(lucideReact.PlusIcon,{className:"h-3 w-3 stroke-[3] text-white"})})})}),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:28,renderDragPreview:DefaultDragPreview,indent:10,onContextMenu,disableDrop:debouncedDisableDrop,idAccessor:"_id",children:Node})]})}),jsxRuntime.jsx(SaveToLibraryModal,{}),jsxRuntime.jsx(PasteAtRootContextMenu,{parentContext,setParentContext})]})},BorderRadiusInput=({value:o,onChange:n,disabled:a})=>{const[l,r]=React.useState(o),i=web.useThrottledCallback(n,[o],200,!0);return jsxRuntime.jsx(toggle.Slider,{min:0,step:1,max:50,disabled:a,value:[Number(l.replace("px",""))],onValueChange:c=>{r(c[0].toString()+"px"),i(c[0].toString())},className:"flex-1 cursor-pointer"})},ColorPickerInput=({value:o,onChange:n})=>{const a=lodashEs.debounce(l=>n(l),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:l=>{const r=l.target.value;/^#[0-9A-F]{6}$/i.test(r)&&a(r)},className:"absolute inset-0 h-full w-full cursor-pointer rounded-lg border-0 opacity-0"})})},FontSelector=({label:o,value:n,onChange:a})=>{const l=runtime.useRegisteredFonts();return React.useEffect(()=>{l.some(r=>r.family===n)||a(l[0].family)},[n,a]),jsxRuntime.jsxs("div",{className:"space-y-0.5",children:[jsxRuntime.jsx(toggle.Label,{className:"mb-1 block text-xs text-gray-600",children:lodashEs.startCase(o)}),jsxRuntime.jsxs(toggle.Select,{value:n,onValueChange:a,children:[jsxRuntime.jsx(toggle.SelectTrigger,{className:"h-8 w-full text-xs text-black",children:jsxRuntime.jsx(toggle.SelectValue,{placeholder:"Select font"})}),jsxRuntime.jsx(toggle.SelectContent,{children:l.map(r=>jsxRuntime.jsx(toggle.SelectItem,{value:r.family,children:r.family},r.family))})]})]})},LazyCssImportModal=React.lazy(()=>Promise.resolve().then(()=>require("./css-import-modal-CdOK43Be.cjs")).then(o=>({default:o.CssImportModal}))),PREV_THEME_KEY="chai-builder-previous-theme",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(),[l,r]=React__namespace.useState(""),[i,c]=React__namespace.useState(!1),d=useBuilderProp("themePresets",[]),m=useBuilderProp("themePanelComponent",null),{hasPermission:u}=usePermissions(),[p,g]=useTheme(),x=useThemeOptions(),{t:f}=reactI18next.useTranslation(),h=React__namespace.useCallback(S=>{const y={...p};setPreviousTheme(y),g(S),sonner.toast.success("Theme updated",{action:{label:jsxRuntime.jsxs("span",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Undo,{className:"h-4 w-4"})," Undo"]}),onClick:()=>{g(y),clearPreviousTheme(),sonner.toast.dismiss()}},closeButton:!0,duration:15e3})},[p,g]),j=()=>{const S=d.find(y=>Object.keys(y)[0]===l);if(S){const y=Object.values(S)[0];y&&typeof y=="object"&&"fontFamily"in y&&"borderRadius"in y&&"colors"in y?(h(y),r("")):console.error("Invalid preset structure:",y)}else console.error("Preset not found:",l)},b=S=>{h(S),r("")},C=web.useDebouncedCallback((S,y)=>{g(()=>({...p,fontFamily:{...p.fontFamily,[S.replace(/font-/g,"")]:y}}))},[p],200),B=React__namespace.useCallback(S=>{g(()=>({...p,borderRadius:`${S}px`}))},[p]),w=web.useDebouncedCallback((S,y)=>{g(()=>{const E=lodashEs.get(p,`colors.${S}`);return n?lodashEs.set(E,1,y):lodashEs.set(E,0,y),{...p,colors:{...p.colors,[S]:E}}})},[p],200),_=S=>jsxRuntime.jsx("div",{className:"grid grid-cols-1",children:Object.entries(S.items).map(([y])=>{const E=lodashEs.get(p,`colors.${y}.${n?1:0}`);return E?jsxRuntime.jsxs("div",{className:"mt-1 flex items-center gap-x-2",children:[jsxRuntime.jsx(ColorPickerInput,{value:E,onChange:A=>w(y,A)}),jsxRuntime.jsx(toggle.Label,{className:"text-xs font-normal leading-tight",children:y.split(/(?=[A-Z])/).join(" ").replace(/-/g," ").split(" ").map(A=>A.charAt(0).toUpperCase()+A.slice(1)).join(" ")+(!y.toLowerCase().includes("foreground")&&!y.toLowerCase().includes("border")&&!y.toLowerCase().includes("input")&&!y.toLowerCase().includes("ring")&&!y.toLowerCase().includes("background")?" Background":"")})]},y):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(toggle.Label,{className:"text-sm",children:f("Presets")}),jsxRuntime.jsx("div",{className:"flex gap-2",children:jsxRuntime.jsxs(toggle.Button,{className:"px-1",variant:"link",size:"sm",onClick:()=>c(!0),children:[jsxRuntime.jsx(lucideReact.ImportIcon,{className:"h-4 w-4"}),f("Import theme")]})})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-0",children:[jsxRuntime.jsx("div",{className:"w-[70%]",children:jsxRuntime.jsxs(toggle.Select,{value:l,onValueChange:r,children:[jsxRuntime.jsx(toggle.SelectTrigger,{className:"h-9 w-full text-sm",children:jsxRuntime.jsx(toggle.SelectValue,{placeholder:"Select preset"})}),jsxRuntime.jsx(toggle.SelectContent,{children:Array.isArray(d)&&d.map(S=>{const y=Object.keys(S)[0],E=y.replaceAll("_"," ");return jsxRuntime.jsx(toggle.SelectItem,{value:y,children:lodashEs.capitalize(E)},y)})})]})}),jsxRuntime.jsx("div",{className:"w-[25%]",children:jsxRuntime.jsx(toggle.Button,{className:"w-full text-sm",disabled:!l,onClick:j,children:f("Apply")})})]})]}),jsxRuntime.jsx(toggle.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(lucideReact.Type,{className:"h-3 w-3 text-gray-600"}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-gray-700",children:"Typography"})]}),(x==null?void 0:x.fontFamily)&&jsxRuntime.jsx("div",{className:"space-y-2",children:Object.entries(x.fontFamily).map(([S,y])=>jsxRuntime.jsx(FontSelector,{label:S,value:p.fontFamily[S.replace(/font-/g,"")]||y[Object.keys(y)[0]],onChange:E=>C(S,E)},S))}),jsxRuntime.jsx(toggle.Separator,{}),(x==null?void 0:x.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(lucideReact.CornerUpRight,{className:"h-3 w-3 text-gray-600"}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-gray-700",children:"Border Radius"})]}),jsxRuntime.jsx(toggle.Badge,{variant:"secondary",className:"text-xs",children:p.borderRadius})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-4 py-2",children:jsxRuntime.jsx(BorderRadiusInput,{value:p.borderRadius,onChange:B})})]}),jsxRuntime.jsx(toggle.Separator,{}),(x==null?void 0:x.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(lucideReact.Palette,{className:"h-3 w-3 text-gray-600"}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-gray-700",children:"Colors"})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Sun,{className:"h-4 w-4"}),jsxRuntime.jsx(toggle.Switch,{checked:n,onCheckedChange:S=>a(S),"aria-label":"Toggle dark mode",className:"mx-1"}),jsxRuntime.jsx(lucideReact.Moon,{className:"h-4 w-4"})]})})]}),jsxRuntime.jsx("div",{className:"space-y-2",children:x.colors.map(S=>_(S))})]}),jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx("div",{children:"Loading..."}),children:i&&jsxRuntime.jsx(LazyCssImportModal,{open:i,onOpenChange:c,onImport:b})})]}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]}),m&&jsxRuntime.jsx("div",{className:"absolute bottom-4 w-full",children:React__namespace.createElement(m)})]}):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:"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="Styling",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",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",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"},Undo="Undo",Redo="Redo",Duplicate="Duplicate",Close="Close",Selected="Selected",Select="Select",Attributes="Attributes",apply="apply",presets="presets",Orientation="Orientation",Color="Color",Upload="Upload",lngEn={"Add block":"Add Block","Add blocks":"Add blocks","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,"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","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","Fix grammar":"Fix grammar","Make longer":"Make longer","Make shorter":"Make shorter","Add emojis":"Add emojis",Randomize,"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)"},"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,"Copy classes to clipboard":"Copy classes to clipboard","Classes copied to clipboard":"Classes copied to clipboard","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}"};i18n.use(reactI18next.initReactI18next).init({resources:{en:{translation:lngEn}},lng:"en",fallbackLng:"en",interpolation:{escapeValue:!1}});const 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(r=>r!==o)):a([...n,o])}},IfChaiFeatureFlag=({flagKey:o,children:n})=>useChaiFeatureFlag(o)?n:null,registerFeatureFlags=()=>{registerChaiFeatureFlag("enable-ai-chat-left",{description:"Enable AI chat on the left side"})},QUICK_PROMPTS=[{name:"Improve writing",icon:lucideReact.FileEdit,prompt:"Improving writing in all text elements. Replacing placeholder content with meaningful relevant content."},{name:"Replace placeholder content",icon:lucideReact.Recycle,prompt:"Discard current placeholder content and replace with meaningful relevant content."},{name:"Fix grammar",icon:reactIcons.CheckIcon,prompt:"Fix grammar in all text elements. Ensuring the text is grammatically correct and free of errors."},{name:"Make longer",icon:reactIcons.ArrowUpIcon,prompt:"Make all text elements longer."},{name:"Make shorter",icon:reactIcons.ArrowDownIcon,prompt:"Make all text elements shorter."},{name:"Add emojis",icon:lucideReact.SmileIcon,prompt:"Add emojis to text elements if relevant."},{name:"Randomize",icon:lucideReact.ShuffleIcon,prompt:"Randomize all text elements."}];function QuickPrompts({onClick:o}){const{loading:n}=useAskAi(),{t:a}=reactI18next.useTranslation(),{selectedLang:l,fallbackLang:r}=useLanguages(),i=[...QUICK_PROMPTS];return l&&l!==r&&i.splice(0,0,{name:`Translate to ${lodashEs.get(LANGUAGES,l,l)}`,icon:lucideReact.Languages,prompt:`Translate the content to ${lodashEs.get(LANGUAGES,l,l)}. Maintain same tone, style and length.`}),jsxRuntime.jsx("div",{className:n?"pointer-events-none opacity-50":"",children:jsxRuntime.jsx("ul",{className:"space-y-2",children:i.map(({name:c,icon:d,subMenus:m,prompt:u})=>m?jsxRuntime.jsxs(toggle.Popover,{children:[jsxRuntime.jsx(toggle.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(d,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:c})]},c)}),jsxRuntime.jsx(toggle.PopoverContent,{side:"right",children:jsxRuntime.jsx("ul",{children:jsxRuntime.jsx("li",{children:"Happy"})})})]}):jsxRuntime.jsxs("li",{onClick:()=>o(u),className:"flex cursor-pointer items-center space-x-2 rounded p-1 text-sm hover:bg-gray-100 dark:hover:bg-gray-800",children:[jsxRuntime.jsx(d,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:a(c)})]},c))})})}const AIUserPrompt=({blockId:o})=>{const{t:n}=reactI18next.useTranslation(),{askAi:a,loading:l,error:r}=useAskAi(),[i,c]=React.useState(""),[d,m]=React.useState(!0),[u,p]=React.useState(),g=React.useRef(null),x=React.useRef(null);React.useEffect(()=>{var h;(h=g.current)==null||h.focus()},[]);const f=h=>{const{usage:j}=h||{};!r&&j&&p(j),x.current=setTimeout(()=>p(void 0),1e4),r||c("")};return jsxRuntime.jsxs("div",{className:"",children:[jsxRuntime.jsxs("div",{onClick:()=>m(!d),className:"flex cursor-pointer items-center justify-between border-t border-border py-2 text-sm font-medium hover:underline",children:[jsxRuntime.jsx("span",{children:n("Ask AI")}),jsxRuntime.jsx("span",{children:jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-4 w-4 text-gray-500 "+(d?"rotate-180":"")})})]}),d&&o?jsxRuntime.jsxs("div",{className:"mt-2",children:[jsxRuntime.jsx(toggle.Textarea,{ref:g,value:i,onChange:h=>c(h.target.value),placeholder:n("Ask AI to edit content"),className:"w-full",rows:3,onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),x.current&&clearTimeout(x.current),p(void 0),a("content",o,i,f))}}),jsxRuntime.jsxs("div",{className:"my-2 flex items-center gap-2",children:[l?null:jsxRuntime.jsx(toggle.Button,{disabled:i.trim().length<5||l,onClick:()=>{x.current&&clearTimeout(x.current),p(void 0),a("content",o,i,f)},variant:"default",className:"w-fit",size:"sm",children:l?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader,{className:"h-5 w-5 animate-spin"}),n("Generating... Please wait...")]}):n("Edit with AI")}),l?jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsxs(toggle.Skeleton,{className:"flex w-full items-center space-x-1 px-4 py-1 pl-2",children:[jsxRuntime.jsx(lucideReact.Loader,{className:"h-4 w-4 animate-spin text-gray-500"}),jsxRuntime.jsx("p",{className:"text-xs",children:n("Generating... Please wait...")})]}),jsxRuntime.jsx(toggle.Button,{variant:"destructive",onClick:()=>stop(),className:"hidden w-fit",size:"sm",children:n("Stop")})]}):null]}),u?jsxRuntime.jsx("div",{className:"max-w-full",children:jsxRuntime.jsxs("p",{className:"mb-1 flex justify-between break-words rounded border border-blue-500 bg-blue-100 p-1 text-xs text-blue-500",children:[jsxRuntime.jsxs("span",{children:[n("Total tokens used"),": ",u.totalTokens]}),jsxRuntime.jsx(Countdown,{})]})}):null,jsxRuntime.jsx("div",{className:"max-w-full",children:r&&jsxRuntime.jsx("p",{className:"break-words rounded border border-red-500 bg-red-100 p-1 text-xs text-red-500",children:r.message})}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx(QuickPrompts,{onClick:h=>{x.current&&clearTimeout(x.current),p(void 0),a("content",o,h,f)}})]}):d?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(lucideReact.SparklesIcon,{className:"mx-auto text-3xl text-muted-foreground"}),jsxRuntime.jsx("h1",{children:n("Please select a block to Ask AI")})]})}):null]})},AISetContext=()=>{const{t:o}=reactI18next.useTranslation(),n=useBuilderProp("aiContext",""),[a,l]=React.useState(n),r=React.useRef(null),i=useBuilderProp("saveAiContextCallback",lodashEs.noop),[c,d]=React.useState(!1),[m,u]=React.useState(null),[,p]=React.useState(!1),g=React.useRef(null);React.useEffect(()=>{n&&l(n)},[n]);const x=async()=>{try{d(!0),u(null),await i(a),sonner.toast.success(o("Updated AI Context")),g.current.click()}catch(f){u(f)}finally{d(!1)}};return jsxRuntime.jsx(toggle.Accordion,{onValueChange:f=>{p(f!=="")},type:"single",collapsible:!0,children:jsxRuntime.jsxs(toggle.AccordionItem,{value:"set-context",className:"border-none",children:[jsxRuntime.jsx(toggle.AccordionTrigger,{ref:g,className:"border-0 border-border py-2",children:jsxRuntime.jsx("div",{className:"flex w-full items-center justify-between",children:jsxRuntime.jsx("span",{className:"font-medium",children:o("AI Context")})})}),jsxRuntime.jsxs(toggle.AccordionContent,{children:[jsxRuntime.jsx(toggle.Textarea,{ref:r,value:a,onChange:f=>l(f.target.value),placeholder:o("Tell about this page eg this page is about"),className:"mt-1 w-full",rows:10,onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),x())}}),n.trim().length===0?jsxRuntime.jsx("p",{className:"mt-2 text-xs text-gray-500",children:o("Eg: This page is about an AI assistant app called Chai Studio. It allows users to create beautiful webpages and edit content with AI.")}):null,jsxRuntime.jsxs("div",{className:"mt-2 flex items-center",children:[jsxRuntime.jsx(toggle.Button,{disabled:a.trim().length<5,onClick:()=>x(),variant:"default",className:"w-fit",size:"sm",children:c?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader,{className:"h-5 w-5 animate-spin"}),o("Saving... Please wait...")]}):o("Save")}),n.trim().length>0?jsxRuntime.jsxs(toggle.AlertDialog,{children:[jsxRuntime.jsx(toggle.AlertDialogTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{disabled:n.trim().length===0,variant:"ghost",className:"w-fit",size:"sm",children:c?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader,{className:"h-5 w-5 animate-spin"}),o("Deleting... Please wait...")]}):o("Delete")})}),jsxRuntime.jsxs(toggle.AlertDialogContent,{children:[jsxRuntime.jsxs(toggle.AlertDialogHeader,{children:[jsxRuntime.jsxs(toggle.AlertDialogTitle,{children:[o("Delete context")," ?"]}),jsxRuntime.jsx(toggle.AlertDialogDescription,{})]}),jsxRuntime.jsxs(toggle.AlertDialogFooter,{children:[jsxRuntime.jsx(toggle.AlertDialogCancel,{children:o("Cancel")}),jsxRuntime.jsx(toggle.AlertDialogAction,{onClick:()=>{l(""),x()},children:o("Yes, Delete")})]})]})]}):null]}),jsxRuntime.jsx("div",{className:"mt-2 max-w-full",children:m&&jsxRuntime.jsx("p",{className:"break-words rounded border border-red-500 bg-red-100 p-1 text-xs text-red-500",children:m.message})})]})]})})},AskAI=()=>{const[o]=useSelectedBlockIds();return jsxRuntime.jsxs("div",{className:"no-scrollbar mt-2 flex-1 overflow-y-auto",children:[jsxRuntime.jsx(AISetContext,{}),jsxRuntime.jsx(AIUserPrompt,{blockId:lodashEs.first(o)})]})};function DarkMode(){const[o,n]=useDarkMode();return jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx(lucideReact.SunIcon,{className:"size-4 shrink-0"}),jsxRuntime.jsx(toggle.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-[40px] 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`})}),jsxRuntime.jsx(lucideReact.Moon,{className:"ml-3 size-4 shrink-0",size:16})]})}const UndoRedo=()=>{const{hasUndo:o,hasRedo:n,undo:a,redo:l}=useUndoManager();return jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx(toggle.Button,{disabled:!o(),size:"sm",onClick:a,className:"rounded-full",variant:"ghost",children:jsxRuntime.jsx(reactIcons.ResetIcon,{})}),jsxRuntime.jsx(toggle.Button,{disabled:!n(),onClick:l,size:"sm",className:"rounded-full",variant:"ghost",children:jsxRuntime.jsx(reactIcons.ResetIcon,{className:"rotate-180 scale-y-[-1] transform"})})]})};function AIChatPanel(){const[o,n]=React.useState([]),[a,l]=React.useState(""),[r,i]=React.useState(!1),[c,d]=React.useState(null),m=React.useRef(null),u=React.useRef(null),p=React.useRef(null);React.useEffect(()=>{var b;(b=u.current)==null||b.scrollIntoView({behavior:"smooth"})},[o]),React.useEffect(()=>{p.current&&(p.current.style.height="auto",p.current.style.height=`${Math.min(p.current.scrollHeight,120)}px`)},[a]);const g=async()=>{if(!a.trim()&&!c)return;const b={id:Date.now().toString(),role:"user",content:a,timestamp:new Date};n(C=>[...C,b]),l(""),i(!0),setTimeout(()=>{const C={id:(Date.now()+1).toString(),role:"assistant",content:"This is a sample response from the AI assistant. In a real implementation, this would be replaced with an actual response from the AI model.",timestamp:new Date};n(B=>[...B,C]),i(!1),d(null)},1500)},x=b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),g())},f=b=>{var B;const C=(B=b.target.files)==null?void 0:B[0];if(C){const w=new FileReader;w.onload=_=>{var S;d((S=_.target)==null?void 0:S.result)},w.readAsDataURL(C)}},h=()=>{var b;(b=m.current)==null||b.click()},j=()=>{d(null),m.current&&(m.current.value="")};return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col rounded-lg bg-background shadow-sm",children:[jsxRuntime.jsx(toggle.ScrollArea,{className:"flex-1 p-3",children:o.length===0?jsxRuntime.jsxs("div",{className:"mt-10 flex h-full flex-col items-center justify-center p-4 text-center text-muted-foreground",children:[jsxRuntime.jsx(lucideReact.Sparkles,{className:"mb-2 h-8 w-8 text-primary/50"}),jsxRuntime.jsx("p",{className:"text-sm",children:"Ask me anything to get started"})]}):jsxRuntime.jsxs("div",{className:"space-y-4",children:[o.map(b=>jsxRuntime.jsxs("div",{className:toggle.cn("flex max-w-full gap-2",b.role==="assistant"?"items-start":"items-start justify-end"),children:[b.role==="assistant"&&jsxRuntime.jsx(toggle.Avatar,{className:"h-6 w-6 bg-primary/10",children:jsxRuntime.jsx(lucideReact.Sparkles,{className:"h-3 w-3 text-primary"})}),jsxRuntime.jsx("div",{className:toggle.cn("rounded-lg px-3 py-2 text-sm",b.role==="assistant"?"bg-muted text-foreground":"bg-primary text-primary-foreground"),children:b.content}),b.role==="user"&&jsxRuntime.jsx(toggle.Avatar,{className:"h-6 w-6 bg-primary",children:jsxRuntime.jsx("span",{className:"text-xs text-primary-foreground",children:"You"})})]},b.id)),r&&jsxRuntime.jsxs("div",{className:"flex items-start gap-2",children:[jsxRuntime.jsx(toggle.Avatar,{className:"h-6 w-6 bg-primary/10",children:jsxRuntime.jsx(lucideReact.Sparkles,{className:"h-3 w-3 text-primary"})}),jsxRuntime.jsx("div",{className:"rounded-lg bg-muted px-3 py-2",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),jsxRuntime.jsx("div",{ref:u})]})}),c&&jsxRuntime.jsx("div",{className:"px-3 pt-2",children:jsxRuntime.jsxs("div",{className:"relative h-20 w-20 overflow-hidden rounded-md",children:[jsxRuntime.jsx("img",{src:c||"/placeholder.svg",alt:"Attachment",className:"h-full w-full object-cover"}),jsxRuntime.jsx(toggle.Button,{size:"icon",variant:"destructive",className:"absolute right-0 top-0 h-5 w-5 rounded-full p-0",onClick:j,children:jsxRuntime.jsx(lucideReact.X,{className:"h-3 w-3"})})]})}),jsxRuntime.jsx("div",{className:"mt-auto p-3",children:jsxRuntime.jsxs("div",{className:"flex items-end gap-2",children:[jsxRuntime.jsxs("div",{className:"relative flex-1",children:[jsxRuntime.jsx(toggle.Textarea,{ref:p,value:a,onChange:b=>l(b.target.value),onKeyDown:x,placeholder:"Ask something...",className:"max-h-[120px] min-h-[40px] resize-none border-0 bg-muted/50 py-2.5 pr-10 focus-visible:ring-1"}),jsxRuntime.jsx("input",{type:"file",ref:m,onChange:f,accept:"image/*",className:"hidden"}),jsxRuntime.jsx(toggle.Button,{size:"icon",variant:"ghost",className:"absolute bottom-2 right-2 h-6 w-6",onClick:h,children:jsxRuntime.jsx(lucideReact.Image,{className:"h-4 w-4 text-muted-foreground"})})]}),jsxRuntime.jsxs(toggle.Button,{size:"sm",className:"h-10 px-3",onClick:g,disabled:r||!a.trim()&&!c,children:[jsxRuntime.jsx(lucideReact.Send,{className:"mr-1 h-4 w-4"}),"Send"]})]})})]})}const AiAssistant=()=>{const o=useAiAssistant(),[n]=useRightPanel(),a=useBuilderProp("askAiCallBack",null),{t:l}=reactI18next.useTranslation(),{hasPermission:r}=usePermissions();return useChaiFeatureFlag("enable-ai-chat-left")||!a||!r(PERMISSIONS.EDIT_BLOCK)?null:jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsxs(toggle.Label,{htmlFor:"ai-assistant",className:"flex items-center gap-x-1 text-sm text-yellow-600",children:[jsxRuntime.jsx(lucideReact.SparklesIcon,{className:"w-4"}),l("AI Assistant")]}),jsxRuntime.jsx(toggle.Switch,{className:"scale-90",checked:n==="ai",onCheckedChange:c=>{o(c)},id:"ai-assistant"})]})},ClearCanvas=()=>{const{t:o}=reactI18next.useTranslation(),{setNewBlocks:n}=useBlocksStoreUndoableActions(),[,a]=useSelectedBlockIds(),[,l]=useSelectedStylingBlocks(),r=React.useCallback(()=>{n([]),a([]),l([])},[n]);return jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs(toggle.AlertDialog,{children:[jsxRuntime.jsx(toggle.AlertDialogTrigger,{asChild:!0,children:jsxRuntime.jsxs(toggle.Button,{size:"sm",variant:"ghost",className:"flex items-center gap-x-1",children:[jsxRuntime.jsx(reactIcons.EraserIcon,{})," ",o("Clear")]})}),jsxRuntime.jsxs(toggle.AlertDialogContent,{className:"border-border",children:[jsxRuntime.jsxs(toggle.AlertDialogHeader,{children:[jsxRuntime.jsx(toggle.AlertDialogTitle,{className:"text-foreground",children:o("Clear whole canvas? ")}),jsxRuntime.jsx(toggle.AlertDialogDescription,{children:o("Are you sure you want to clear the page?")})]}),jsxRuntime.jsxs(toggle.AlertDialogFooter,{children:[jsxRuntime.jsx(toggle.AlertDialogCancel,{className:"text-foreground",children:o("Cancel")}),jsxRuntime.jsx(toggle.AlertDialogAction,{onClick:r,children:o("Yes")})]})]})]})})},DataBinding=()=>{const o=usePageExternalData(),[n,a]=jotai.useAtom(dataBindingActiveAtom),{t:l}=reactI18next.useTranslation();return lodashEs.isEmpty(o)?null:jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{className:"rounded-full",variant:"ghost",onClick:()=>a(!n),children:jsxRuntime.jsx(lucideReact.DatabaseZapIcon,{className:commonFunctions.cn("h-4 w-4",n?"text-green-500":"text-gray-500")})})}),jsxRuntime.jsx(toggle.TooltipContent,{children:jsxRuntime.jsx("p",{children:l("Toggle Data Binding")})})]})})},CanvasTopBar=()=>{const o=useBuilderProp("darkMode",!0),n=flagged.useFeature("aiChat"),[a]=useCanvasZoom();return jsxRuntime.jsxs("div",{className:"flex h-10 items-center justify-between border-b border-border bg-background/70 px-2",children:[jsxRuntime.jsxs("div",{className:"flex h-full space-x-2",children:[jsxRuntime.jsx(Breakpoints$1,{canvas:!0,openDelay:400}),jsxRuntime.jsx(toggle.Separator,{orientation:"vertical"}),o?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(DarkMode,{}),jsxRuntime.jsx(toggle.Separator,{orientation:"vertical"})]}):null,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(a,0),"%"]})]}),jsxRuntime.jsx(toggle.Separator,{orientation:"vertical"}),jsxRuntime.jsx(UndoRedo,{}),jsxRuntime.jsx(DataBinding,{})]}),jsxRuntime.jsxs("div",{className:"flex h-full items-center space-x-2",children:[jsxRuntime.jsx(ClearCanvas,{}),n?null:jsxRuntime.jsx(AiAssistant,{})]})]})},AddBlocksDialog=()=>{const{t:o}=reactI18next.useTranslation(),[n,a]=React.useState(""),[l,r]=React.useState(-1),[i,c]=React.useState(!1);return usePubSub(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,d=>{a(d?d._id:null),r(isNaN(d==null?void 0:d.position)?-1:d==null?void 0:d.position),c(!0)}),usePubSub(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK,()=>{a(""),r(-1),c(!1)}),jsxRuntime.jsx(toggle.AlertDialog,{open:i,onOpenChange:()=>i?c(!1):"",children:jsxRuntime.jsxs(toggle.AlertDialogContent,{className:"max-w-5xl overflow-hidden border-border",children:[jsxRuntime.jsxs(toggle.AlertDialogHeader,{className:"flex flex-row items-center justify-between",children:[jsxRuntime.jsx(toggle.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:l,showHeading:!1})})]})})},AttrsEditor=React.memo(function o({preloadedAttributes:n=[],onAttributesChange:a}){const[l,r]=React.useState([]),[i,c]=React.useState(""),[d,m]=React.useState(""),[u,p]=React.useState(null),[g,x]=React.useState(""),f=React.useRef(null),h=React.useRef(null),j=usePageExternalData();React.useEffect(()=>{r(n)},[n]);const b=()=>{if(i.startsWith("@")){x("Attribute keys cannot start with '@'");return}if(i){const y=[...l,{key:i,value:d}];a(y),r(l),c(""),m(""),x("")}},C=y=>{const E=l.filter((A,R)=>R!==y);a(E),r(E)},B=y=>{p(y),c(l[y].key),m(l[y].value)},w=()=>{if(i.startsWith("@")){x("Attribute keys cannot start with '@'");return}if(u!==null&&i){const y=[...l];y[u]={key:i,value:d},a(y),r(y),p(null),c(""),m(""),x("")}},_=y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),u!==null?w():b())},S=React.useCallback(y=>{const E=k=>/[.,!?;:]/.test(k),A=(k,v,N)=>{let I="",L="";const T=v>0?k[v-1]:"",D=v<k.length?k[v]:"";return v>0&&(T==="."||!E(T)&&T!==" ")&&(I=" "),v<k.length&&!E(D)&&D!==" "&&(L=" "),{text:I+N+L,prefixLength:I.length,suffixLength:L.length}},R=h.current;if(R){const k=R.selectionStart||0,v=R.value||"",N=R.selectionEnd||k;if(N>k){const P=`{{${y}}}`,{text:M}=A(v,k,P),F=v.slice(0,k)+M+v.slice(N);m(F);return}const L=`{{${y}}}`,{text:T}=A(v,k,L),D=v.slice(0,k)+T+v.slice(k);m(D)}},[]);return jsxRuntime.jsxs("div",{className:"flex max-h-full flex-1 flex-col",children:[jsxRuntime.jsxs("form",{onSubmit:y=>{y.preventDefault(),u!==null?w():b()},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(toggle.Label,{htmlFor:"attrKey",className:"text-[11px] font-normal leading-tight text-slate-600",children:"Key"}),jsxRuntime.jsx(toggle.Input,{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",id:"attrKey",ref:f,value:i,onChange:y=>c(y.target.value),placeholder:"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(toggle.Label,{htmlFor:"attrValue",className:"text-[11px] font-normal text-slate-600",children:"Value"}),!lodashEs.isEmpty(j)&&jsxRuntime.jsx(NestedPathSelector,{data:j,onSelect:S})]}),jsxRuntime.jsx(toggle.Textarea,{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",id:"attrValue",rows:2,ref:h,value:d,onChange:y=>m(y.target.value),onKeyDown:_,placeholder:"Enter Value",className:"text-xs font-normal leading-tight placeholder:text-slate-400"})]})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(toggle.Button,{type:"submit",disabled:!i.length,variant:"default",size:"sm",className:"h-8 w-24 text-xs",children:u!==null?"Save":"Add"})}),g&&jsxRuntime.jsx("p",{className:"text-xs text-red-500",children:g})]}),jsxRuntime.jsx("div",{className:"space-y-1 py-4",children:l.map((y,E)=>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:y.key}),jsxRuntime.jsx("span",{className:"max-w-[200px] text-wrap font-normal",children:y.value.toString()})]}),jsxRuntime.jsxs("div",{className:"flex-shrink-0 text-slate-400",children:[jsxRuntime.jsx(toggle.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>B(E),children:jsxRuntime.jsx(lucideReact.Edit2,{className:"h-3 w-3"})}),jsxRuntime.jsx(toggle.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>C(E),children:jsxRuntime.jsx(lucideReact.X,{className:"h-3 w-3"})})]})]},E))})]})}),BlockAttributesEditor=React__namespace.memo(()=>{const o=useSelectedBlock(),[n,a]=React.useState([]),[l]=useSelectedStylingBlocks(),r=useUpdateBlocksProps(),i=`${lodashEs.get(l,"0.prop")}_attrs`;React__namespace.useEffect(()=>{const d=lodashEs.map(lodashEs.get(o,i),(m,u)=>({key:u,value:m}));lodashEs.isEmpty(d)?a([]):a(d)},[lodashEs.get(o,i)]);const c=React__namespace.useCallback((d=[])=>{const m={};lodashEs.forEach(d,u=>{lodashEs.isEmpty(u.key)||lodashEs.set(m,u.key,u.value)}),r([lodashEs.get(o,"_id")],{[i]:m})},[o,r,i]);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(),l=useRemoveAllClassesForBlock(),{t:r}=reactI18next.useTranslation();return!n||lodashEs.isEmpty(a)?null:jsxRuntime.jsxs(toggle.DropdownMenu,{children:[jsxRuntime.jsx(toggle.DropdownMenuTrigger,{asChild:!0,children:jsxRuntime.jsx("div",{className:"inline-flex rounded-sm p-0.5 hover:bg-gray-300",onClick:i=>i.stopPropagation(),children:jsxRuntime.jsx(lucideReact.MoreVertical,{className:"h-3 w-3"})})}),jsxRuntime.jsxs(toggle.DropdownMenuContent,{side:"bottom",className:"border-border text-xs",children:[jsxRuntime.jsxs(toggle.DropdownMenuItem,{className:"flex items-center gap-1 text-xs",onClick:()=>{o()},children:[jsxRuntime.jsx(reactIcons.ResetIcon,{className:"h-3 w-3"}),r("Reset styles")]}),jsxRuntime.jsxs(toggle.DropdownMenuItem,{className:"text-xs",onClick:()=>{n&&l(n,!0)},children:[jsxRuntime.jsx(reactIcons.Cross2Icon,{className:"h-3 w-3"}),r("Clear styles")]})]})]})};function BlockAttributesToggle(){const{t:o}=reactI18next.useTranslation(),[n,a]=React.useState(!0),[l]=useSelectedStylingBlocks();return lodashEs.isEmpty(l)?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(lucideReact.ChevronDown,{className:"h-4 w-4 text-gray-500 "+(n?"rotate-180":"")})})]}),n&&jsxRuntime.jsx(BlockAttributesEditor,{})]})}const SettingsPanel=()=>{const o=useSelectedBlock(),{t:n}=reactI18next.useTranslation(),a=useBuilderProp("onError",lodashEs.noop),{hasPermission:l}=usePermissions();let r=!l(PERMISSIONS.EDIT_BLOCK);const i=!l(PERMISSIONS.EDIT_STYLES);return 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")})]})}):r&&i?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")})]})}):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",children:[jsxRuntime.jsx(BlockSettings,{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]})}):r?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(toggle.Tabs,{defaultValue:"settings",className:"flex flex-1 flex-col",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between",children:jsxRuntime.jsxs(toggle.TabsList,{className:"grid h-auto w-full grid-cols-2 p-1 py-1",children:[jsxRuntime.jsx(toggle.TabsTrigger,{value:"settings",className:"text-xs",children:"Settings"}),jsxRuntime.jsx(toggle.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:"Styles"}),jsxRuntime.jsx("span",{className:"w-[10%]",children:jsxRuntime.jsx(ResetStylesButton,{})})]})})]})}),jsxRuntime.jsxs(toggle.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(toggle.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]),DefaultTopBar=()=>jsxRuntime.jsx("div",{}),TOP_BAR={component:DefaultTopBar},registerChaiTopBar=o=>{TOP_BAR.component=o},useTopBarComponent=()=>React.useMemo(()=>TOP_BAR.component,[]),DEFAULT_PANEL_WIDTH=280,OutlineButton=({isActive:o,show:n})=>jsxRuntime.jsx(toggle.Button,{variant:o?"default":"ghost",size:"icon",onClick:n,children:jsxRuntime.jsx(lucideReact.Layers,{size:20})}),AiButton=({isActive:o,show:n})=>jsxRuntime.jsx(toggle.Button,{variant:o?"default":"ghost",size:"icon",onClick:n,children:jsxRuntime.jsx(reactIcons.LightningBoltIcon,{className:"rtl:ml-2"})}),AskAiButton=({isActive:o,show:n})=>jsxRuntime.jsx(toggle.Button,{variant:o?"default":"ghost",size:"icon",onClick:n,children:jsxRuntime.jsx(lucideReact.SparklesIcon,{className:"rtl:ml-2"})});function useSidebarDefaultPanels(){const o=useBuilderProp("askAiCallBack",null),n=flagged.useFeature("aiChat"),a=useChaiFeatureFlag("enable-ai-chat-left");return React.useMemo(()=>{const l=[];return l.push({id:"outline",label:"Outline",isInternal:!0,width:DEFAULT_PANEL_WIDTH,button:OutlineButton,panel:()=>jsxRuntime.jsx("div",{className:"-mt-8",children:jsxRuntime.jsx(ListTree,{})})}),a&&l.unshift({id:"ask-ai",button:AskAiButton,label:"Ask AI",isInternal:!0,width:DEFAULT_PANEL_WIDTH,panel:()=>jsxRuntime.jsx("div",{className:"",children:jsxRuntime.jsx(AskAI,{})})}),o&&n&&l.unshift({id:"ai",button:AiButton,label:"AI Assistant",isInternal:!0,width:450,panel:()=>jsxRuntime.jsx("div",{className:"-mt-8 h-full max-h-full",children:jsxRuntime.jsx(AIChatPanel,{})})}),lodashEs.compact(l)},[o,n,a])}const RootLayout=()=>{const o=useTopBarComponent(),[n,a]=useSidebarActivePanel(),l=React.useRef("outline"),[r,i]=React.useState(DEFAULT_PANEL_WIDTH),[c,d]=useRightPanel();usePubSub(CHAI_BUILDER_EVENTS.SHOW_BLOCK_SETTINGS,()=>{a("outline")});const m=useSidebarDefaultPanels(),u=useChaiSidebarPanels("top"),p=useChaiSidebarPanels("bottom"),g=React.useCallback(y=>{y.preventDefault()},[]),x=React.useCallback(y=>{a(n===y?null:y)},[n]),{t:f}=reactI18next.useTranslation(),h=React.useMemo(()=>[...m,...u,...p],[m,u,p]),j=useBuilderProp("htmlDir","ltr"),b=lodashEs.find(h,{id:n})??lodashEs.first(h),C=lodashEs.get(b,"width",DEFAULT_PANEL_WIDTH);React.useEffect(()=>{if(n!==null){const y=lodashEs.find(h,{id:n});y&&lodashEs.get(y,"view","standard")==="standard"&&(l.current=n,i(lodashEs.get(y,"width",DEFAULT_PANEL_WIDTH)))}},[n,h]);const B=React.useMemo(()=>{if(n===null)return 0;const y=lodashEs.find(h,{id:n});return lodashEs.get(y,"view","standard")==="standard"?C:r},[n,C,r,h]),w=React.useCallback(()=>{a(l.current)},[a]),_=React.useCallback(()=>{a("outline")},[a]);React.useEffect(()=>{lodashEs.find(h,{id:n})||a("outline")},[n,h]);const S=React.useCallback(y=>{x(y)},[x]);return jsxRuntime.jsx("div",{dir:j,className:"h-screen max-h-full w-screen overflow-x-hidden bg-background text-foreground",children:jsxRuntime.jsxs(toggle.TooltipProvider,{children:[jsxRuntime.jsxs("div",{onContextMenu:g,className:"flex h-screen 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:[m,u].flat().map((y,E)=>jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:React.createElement(lodashEs.get(y,"button",NoopComponent),{position:"top",panelId:y.id,isActive:n===y.id,show:()=>S(y.id)})}),jsxRuntime.jsx(toggle.TooltipContent,{side:"right",children:jsxRuntime.jsx("p",{children:f(y.label)})})]},"button-top-"+E))}),jsxRuntime.jsx("div",{className:"flex flex-col space-y-1"}),jsxRuntime.jsx("div",{className:"flex flex-col",children:p==null?void 0:p.map((y,E)=>jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:React.createElement(lodashEs.get(y,"button",NoopComponent),{position:"bottom",panelId:y.id,isActive:n===y.id,show:()=>S(y.id)})}),jsxRuntime.jsx(toggle.TooltipContent,{side:"right",children:jsxRuntime.jsx("p",{children:f(y.label)})})]},"button-bottom-"+E))})]}),jsxRuntime.jsx(framerMotion.motion.div,{id:"left-panel",className:"h-full max-h-full border-r border-border",initial:{width:B},animate:{width:B},transition:{duration:.3,ease:"easeInOut"},children:n!==null&&lodashEs.get(b,"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(b,"isInternal",!1)?"":"w-64"}`,children:jsxRuntime.jsx("span",{children:f(lodashEs.get(b,"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(b,"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==="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(lucideReact.Palette,{className:"w-4 h-4 text-gray-600"}),f("Theme Settings")]}),jsxRuntime.jsx(toggle.Button,{onClick:()=>d("block"),variant:"ghost",size:"icon",className:"text-xs",children:jsxRuntime.jsx(lucideReact.X,{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==="theme"?jsxRuntime.jsx(ThemeConfigPanel,{}):jsxRuntime.jsx(SettingsPanel,{})})})]})})})]})]}),jsxRuntime.jsx(AddBlocksDialog,{}),n!==null&&lodashEs.get(b,"view")==="drawer"&&jsxRuntime.jsx(toggle.Sheet,{open:!0,onOpenChange:()=>w(),children:jsxRuntime.jsxs(toggle.SheetContent,{side:"left",className:"flex flex-col gap-0 p-0 sm:max-w-full",style:{width:`${C}px`},children:[jsxRuntime.jsx(toggle.SheetHeader,{className:"border-b border-border px-2 py-2.5",children:jsxRuntime.jsxs(toggle.SheetTitle,{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"inline-block",children:lodashEs.get(b,"icon",null)}),jsxRuntime.jsx("span",{children:f(lodashEs.get(b,"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(b,"panel",NoopComponent),{close:_})})})]})})," ",n!==null&&lodashEs.get(b,"view")==="modal"&&jsxRuntime.jsx(toggle.Dialog,{open:!0,onOpenChange:()=>w(),children:jsxRuntime.jsxs(toggle.DialogContent,{className:"gap-0 p-0",style:{maxWidth:`${C}px`},children:[jsxRuntime.jsx(toggle.DialogHeader,{className:"border-b border-border px-2 py-3.5",children:jsxRuntime.jsxs(toggle.DialogTitle,{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"inline-block",children:lodashEs.get(b,"icon",null)}),jsxRuntime.jsx("span",{children:f(lodashEs.get(b,"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(b,"panel",NoopComponent),{close:_})})})]})}),n!==null&&lodashEs.get(b,"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(b,"icon",null)}),jsxRuntime.jsx("span",{children:f(lodashEs.get(b,"label",""))})]}),jsxRuntime.jsx(toggle.Button,{onClick:()=>w(),variant:"ghost",size:"icon",className:"",children:jsxRuntime.jsx(lucideReact.X,{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(b,"panel",NoopComponent),{close:_})})})]})})})]})})},PreviewScreen=()=>{const[o,n]=usePreviewMode(),{t:a}=reactI18next.useTranslation(),l=useBuilderProp("previewComponent",null);return o?jsxRuntime.jsxs("div",{className:commonFunctions.cn("fixed inset-0 z-[999] bg-background",o?"block":"hidden"),children:[jsxRuntime.jsxs(toggle.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:l?jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx(toggle.Skeleton,{className:"h-96 w-full"}),children:React.createElement(l)}):null})]}):null},FeatureToggle=({featureKey:o,options:n})=>{const a=useToggleChaiFeatureFlag(o),l=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(toggle.Switch,{checked:l,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 l=useChaiFeatureFlags(),[r,i]=React.useState(""),[c,d]=React.useState(!1),[m,u]=React.useState({x:0,y:0}),p=React.useMemo(()=>{if(!r.trim())return l;const h=r.toLowerCase();return Object.fromEntries(Object.entries(l).filter(([j,b])=>{var C;return(j==null?void 0:j.toLowerCase().includes(h))||((C=b==null?void 0:b.description)==null?void 0:C.toLowerCase().includes(h))}))},[l,r]),g=h=>{d(!0),u({x:h.clientX-n.x,y:h.clientY-n.y})},x=h=>{if(!c)return;const j=h.clientX-m.x,b=h.clientY-m.y,C=h.currentTarget,B=C.offsetWidth,w=C.offsetHeight,_=window.innerWidth-B,S=window.innerHeight-w,y=Math.max(0,Math.min(j,_)),E=Math.max(0,Math.min(b,S));a(y,E)},f=()=>{d(!1)};return React.useEffect(()=>{const h=()=>{c&&d(!1)};return window.addEventListener("mouseup",h),()=>window.removeEventListener("mouseup",h)},[c]),!n||n.x<0||n.y<0?null:jsxRuntime.jsxs("div",{onMouseDown:g,onMouseMove:x,onMouseUp:f,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(toggle.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(lucideReact.X,{className:"h-4 w-4"})})]}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),jsxRuntime.jsx(toggle.Input,{type:"search",placeholder:"Search features...",className:"w-full pl-8",value:r,onChange:h=>i(h.target.value),autoFocus:!0})]})]}),jsxRuntime.jsx("div",{className:"max-h-96 overflow-y-auto py-2",children:Object.keys(p).length>0?jsxRuntime.jsx("div",{className:"space-y-1",children:Object.entries(p).map(([h,j])=>jsxRuntime.jsx(FeatureToggle,{featureKey:h,options:j},h))}):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 "',r,'"']})})})]})},ChaiFeatureFlagsWidget=()=>{const[o,n]=jotai.useAtom(showFeatureFlagAtom);return reactHotkeysHook.useHotkeys("ctrl+shift+1,command+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,l)=>n(r=>({...r,x:a,y:l}))}):null},setDebugLogs=o=>{},getParentNodeIds=(o,n)=>{const a=[];let l=lodashEs.find(o,{_id:n}),r=lodashEs.get(l,"_parent","");for(;lodashEs.isString(r)&&!lodashEs.isEmpty(r);)a.push(l==null?void 0:l._parent),l=lodashEs.find(o,{_id:r}),r=l==null?void 0:l._parent;return lodashEs.flatten(a)},expandedIdsAtom=jotai.atom([]),useExpandTree=()=>{const[o]=useSelectedBlockIds(),n=jotai.useAtomValue(presentBlocksAtom),[,a]=jotai.useAtom(expandedIdsAtom);React.useEffect(()=>{let l=[];const r=lodashEs.first(o);lodashEs.isString(r)&&(l=[r,...getParentNodeIds(n,r)]),a(l)},[o,n,a])},ScreenTooSmall=()=>jsxRuntime.jsx("section",{className:"fixed inset-0 z-50 flex h-screen w-screen items-center justify-center bg-white 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 xl:hidden",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"]})})]})})}),isSelfAtom=(o,n)=>o.unstable_is?o.unstable_is(n):n===o,hasInitialValue=o=>"init"in o,isActuallyWritableAtom=o=>!!o.write,isAtomStateInitialized=o=>"v"in o||"e"in o,returnAtomValue=o=>{if("e"in o)throw o.e;return o.v},promiseStateMap=new WeakMap,isPendingPromise=o=>{var n;return isPromiseLike$1(o)&&!!((n=promiseStateMap.get(o))!=null&&n[0])},abortPromise=o=>{const n=promiseStateMap.get(o);n!=null&&n[0]&&(n[0]=!1,n[1].forEach(a=>a()))},registerAbortHandler=(o,n)=>{let a=promiseStateMap.get(o);if(!a){a=[!0,new Set],promiseStateMap.set(o,a);const l=()=>{a[0]=!1};o.then(l,l)}a[1].add(n)},isPromiseLike$1=o=>typeof(o==null?void 0:o.then)=="function",addPendingPromiseToDependency=(o,n,a)=>{a.p.has(o)||(a.p.add(o),n.then(()=>{a.p.delete(o)},()=>{a.p.delete(o)}))},setAtomStateValueOrPromise=(o,n,a)=>{const l=a(o),r="v"in l,i=l.v;if(isPromiseLike$1(n))for(const c of l.d.keys())addPendingPromiseToDependency(o,n,a(c));l.v=n,delete l.e,(!r||!Object.is(i,l.v))&&(++l.n,isPromiseLike$1(i)&&abortPromise(i))},getMountedOrPendingDependents=(o,n,a)=>{var l;const r=new Set;for(const i of((l=a.get(o))==null?void 0:l.t)||[])a.has(i)&&r.add(i);for(const i of n.p)r.add(i);return r},BUILDING_BLOCKS=Symbol(),buildStore=(o=new WeakMap,n=new WeakMap,a=new WeakMap,l=new Set,r=new Set,i=new Set,c={},d=(x,...f)=>x.read(...f),m=(x,...f)=>x.write(...f),u=(x,f)=>{var h;return(h=x.unstable_onInit)==null?void 0:h.call(x,f)},p=(x,f)=>{var h;return(h=x.onMount)==null?void 0:h.call(x,f)},...g)=>{const x=g[0]||(E=>{let A=o.get(E);return A||(A={d:new Map,p:new Set,n:0},o.set(E,A),u==null||u(E,y)),A}),f=g[1]||(()=>{const E=[],A=R=>{try{R()}catch(k){E.push(k)}};do{c.f&&A(c.f);const R=new Set,k=R.add.bind(R);l.forEach(v=>{var N;return(N=n.get(v))==null?void 0:N.l.forEach(k)}),l.clear(),i.forEach(k),i.clear(),r.forEach(k),r.clear(),R.forEach(A),l.size&&h()}while(l.size||i.size||r.size);if(E.length)throw new AggregateError(E)}),h=g[2]||(()=>{const E=[],A=new WeakSet,R=new WeakSet,k=Array.from(l);for(;k.length;){const v=k[k.length-1],N=x(v);if(R.has(v)){k.pop();continue}if(A.has(v)){a.get(v)===N.n&&E.push([v,N]),R.add(v),k.pop();continue}A.add(v);for(const I of getMountedOrPendingDependents(v,N,n))A.has(I)||k.push(I)}for(let v=E.length-1;v>=0;--v){const[N,I]=E[v];let L=!1;for(const T of I.d.keys())if(T!==N&&l.has(T)){L=!0;break}L&&(j(N),B(N)),a.delete(N)}}),j=g[3]||(E=>{var A;const R=x(E);if(isAtomStateInitialized(R)&&(n.has(E)&&a.get(E)!==R.n||Array.from(R.d).every(([P,M])=>j(P).n===M)))return R;R.d.clear();let k=!0;const v=()=>{n.has(E)&&(B(E),h(),f())},N=P=>{var M;if(isSelfAtom(E,P)){const O=x(P);if(!isAtomStateInitialized(O))if(hasInitialValue(P))setAtomStateValueOrPromise(P,P.init,x);else throw new Error("no atom init");return returnAtomValue(O)}const F=j(P);try{return returnAtomValue(F)}finally{R.d.set(P,F.n),isPendingPromise(R.v)&&addPendingPromiseToDependency(E,R.v,F),(M=n.get(P))==null||M.t.add(E),k||v()}};let I,L;const T={get signal(){return I||(I=new AbortController),I.signal},get setSelf(){return!L&&isActuallyWritableAtom(E)&&(L=(...P)=>{if(!k)try{return C(E,...P)}finally{h(),f()}}),L}},D=R.n;try{const P=d(E,N,T);return setAtomStateValueOrPromise(E,P,x),isPromiseLike$1(P)&&(registerAbortHandler(P,()=>I==null?void 0:I.abort()),P.then(v,v)),R}catch(P){return delete R.v,R.e=P,++R.n,R}finally{k=!1,D!==R.n&&a.get(E)===D&&(a.set(E,R.n),l.add(E),(A=c.c)==null||A.call(c,E))}}),b=g[4]||(E=>{const A=[E];for(;A.length;){const R=A.pop(),k=x(R);for(const v of getMountedOrPendingDependents(R,k,n)){const N=x(v);a.set(v,N.n),A.push(v)}}}),C=g[5]||((E,...A)=>{let R=!0;const k=N=>returnAtomValue(j(N)),v=(N,...I)=>{var L;const T=x(N);try{if(isSelfAtom(E,N)){if(!hasInitialValue(N))throw new Error("atom not writable");const D=T.n,P=I[0];setAtomStateValueOrPromise(N,P,x),B(N),D!==T.n&&(l.add(N),(L=c.c)==null||L.call(c,N),b(N));return}else return C(N,...I)}finally{R||(h(),f())}};try{return m(E,k,v,...A)}finally{R=!1}}),B=g[6]||(E=>{var A;const R=x(E),k=n.get(E);if(k&&!isPendingPromise(R.v)){for(const[v,N]of R.d)if(!k.d.has(v)){const I=x(v);w(v).t.add(E),k.d.add(v),N!==I.n&&(l.add(v),(A=c.c)==null||A.call(c,v),b(v))}for(const v of k.d||[])if(!R.d.has(v)){k.d.delete(v);const N=_(v);N==null||N.t.delete(E)}}}),w=g[7]||(E=>{var A;const R=x(E);let k=n.get(E);if(!k){j(E);for(const v of R.d.keys())w(v).t.add(E);if(k={l:new Set,d:new Set(R.d.keys()),t:new Set},n.set(E,k),(A=c.m)==null||A.call(c,E),isActuallyWritableAtom(E)){const v=()=>{let N=!0;const I=(...L)=>{try{return C(E,...L)}finally{N||(h(),f())}};try{const L=p(E,I);L&&(k.u=()=>{N=!0;try{L()}finally{N=!1}})}finally{N=!1}};r.add(v)}}return k}),_=g[8]||(E=>{var A;const R=x(E);let k=n.get(E);if(k&&!k.l.size&&!Array.from(k.t).some(v=>{var N;return(N=n.get(v))==null?void 0:N.d.has(E)})){k.u&&i.add(k.u),k=void 0,n.delete(E),(A=c.u)==null||A.call(c,E);for(const v of R.d.keys()){const N=_(v);N==null||N.t.delete(E)}return}return k}),S=[o,n,a,l,r,i,c,d,m,u,p,x,f,h,j,b,C,B,w,_],y={get:E=>returnAtomValue(j(E)),set:(E,...A)=>{try{return C(E,...A)}finally{h(),f()}},sub:(E,A)=>{const k=w(E).l;return k.add(A),f(),()=>{k.delete(A),_(E),f()}}};return Object.defineProperty(y,BUILDING_BLOCKS,{value:S}),y},INTERNAL_buildStoreRev1=buildStore,INTERNAL_registerAbortHandler=registerAbortHandler;function createStore(){return INTERNAL_buildStoreRev1()}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((l,r)=>{let i=o;const c=u=>p=>{i===u&&l(p)},d=u=>p=>{i===u&&r(p)},m=()=>{try{const u=n();isPromiseLike(u)?(continuablePromiseMap.set(u,a),i=u,u.then(c(u),d(u)),INTERNAL_registerAbortHandler(u,m)):l(u)}catch(u){r(u)}};o.then(c(o),d(o)),INTERNAL_registerAbortHandler(o,m)}),continuablePromiseMap.set(o,a)),a};function useAtomValue(o,n){const{delay:a,unstable_promiseStatus:l=!React.use}={},r=useStore(),[[i,c,d],m]=React.useReducer(p=>{const g=r.get(o);return Object.is(p[0],g)&&p[1]===r&&p[2]===o?p:[g,r,o]},void 0,()=>[r.get(o),r,o]);let u=i;if((c!==r||d!==o)&&(m(),u=r.get(o)),React.useEffect(()=>{const p=r.sub(o,()=>{if(l)try{const g=r.get(o);isPromiseLike(g)&&attachPromiseStatus(createContinuablePromise(g,()=>r.get(o)))}catch{}if(typeof a=="number"){setTimeout(m,a);return}m()});return m(),p},[r,o,a,l]),React.useDebugValue(u),isPromiseLike(u)){const p=createContinuablePromise(u,()=>r.get(o));return l&&attachPromiseStatus(p),use(p)}return u}function useSetAtom(o,n){const a=useStore();return React.useCallback((...r)=>a.set(o,...r),[a,o])}function useAtom(o,n){return[useAtomValue(o),useSetAtom(o)]}const useAutoSave=()=>{const{savePage:o}=useSavePage(),n=useBuilderProp("autoSaveSupport",!0),a=useBuilderProp("autoSaveInterval",60);web.useIntervalEffect(()=>{n&&o(!0)},a*1e3)},ChaiWatchers=o=>{const[,n]=useBlocksStore(),a=useBuilderReset(),[l]=useAtom(builderSaveStateAtom);useAtom(selectedLibraryAtom),useKeyEventWatcher(),useExpandTree(),useAutoSave(),useWatchPartailBlocks(),useUnmountBroadcastChannel();const{postMessage:r}=useBroadcastChannel();return React.useEffect(()=>{builderStore.set(chaiBuilderPropsAtom,lodashEs.omit(o,["blocks","translations","pageExternalData"]))},[o]),React.useEffect(()=>{builderStore.set(chaiPageExternalDataAtom,o.pageExternalData||{})},[o.pageExternalData]),React.useEffect(()=>{setTimeout(()=>{const i=runtime.syncBlocksWithDefaults(o.blocks||[]);n(i),i&&i.length>0&&r({type:"blocks-updated",blocks:i}),a()},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,(i,c)=>{i18n.addResourceBundle(c,"translation",i,!0,!0)})},[o.translations]),React.useEffect(()=>(l!=="SAVED"?window.onbeforeunload=()=>"":window.onbeforeunload=null,()=>{window.onbeforeunload=null}),[l]),null},ChaiBuilderComponent=o=>{const n=React.useMemo(()=>o.layout||RootLayout,[o.layout]),a=useBuilderProp("builderTheme",plugin.defaultThemeValues);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(CssThemeVariables,{theme:a}),jsxRuntime.jsx(n,{})]})},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.");registerFeatureFlags();exports.generateBlockId=commonFunctions.generateUUID;exports.mergeClasses=commonFunctions.cn;Object.defineProperty(exports,"useTranslation",{enumerable:!0,get:()=>reactI18next.useTranslation});exports.i18n=i18n;exports.ChaiAddBlocksDialog=AddBlocksDialog;exports.ChaiAddBlocksPanel=AddBlocksPanel;exports.ChaiAskAiPanel=AISetContext;exports.ChaiAskAiUserPrompt=AIUserPrompt;exports.ChaiBlockAttributesEditor=BlockAttributesEditor;exports.ChaiBlockPropsEditor=BlockSettings;exports.ChaiBlockStyleEditor=BlockStyling;exports.ChaiBuilderCanvas=CanvasArea;exports.ChaiBuilderEditor=ChaiBuilderEditor;exports.ChaiDarkModeSwitcher=DarkMode;exports.ChaiDefaultBlocks=DefaultChaiBlocks;exports.ChaiImportHTML=ImportHTML;exports.ChaiOutline=ListTree;exports.ChaiScreenSizes=Breakpoints$1;exports.ChaiThemeConfigPanel=ThemeConfigPanel;exports.ChaiUILibrariesPanel=UILibrariesPanel;exports.ChaiUndoRedo=UndoRedo;exports.IfChaiFeatureFlag=IfChaiFeatureFlag;exports.PERMISSIONS=PERMISSIONS;exports.convertHTMLToChaiBlocks=getBlocksFromHTML;exports.getBlocksFromHTML=getBlocksFromHTML;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.registerChaiSaveToLibrary=registerChaiSaveToLibrary;exports.registerChaiSidebarPanel=registerChaiSidebarPanel;exports.registerChaiTopBar=registerChaiTopBar;exports.useAddBlock=useAddBlock;exports.useAddClassesToBlocks=useAddClassesToBlocks;exports.useAskAi=useAskAi;exports.useBlockHighlight=useBlockHighlight;exports.useBlocksStore=useBlocksStore;exports.useBlocksStoreUndoableActions=useBlocksStoreUndoableActions;exports.useBrandingOptions=useBrandingOptions;exports.useBuilderProp=useBuilderProp;exports.useBuilderReset=useBuilderReset;exports.useCanvasDisplayWidth=useCanvasDisplayWidth;exports.useCanvasZoom=useCanvasZoom;exports.useChaiFeatureFlag=useChaiFeatureFlag;exports.useChaiFeatureFlags=useChaiFeatureFlags;exports.useCodeEditor=useCodeEditor;exports.useCopyBlockIds=useCopyBlocks;exports.useCopyToClipboard=useCopyToClipboard;exports.useCurrentPage=useCurrentPage;exports.useCutBlockIds=useCutBlockIds;exports.useDarkMode=useDarkMode;exports.useDuplicateBlocks=useDuplicateBlocks;exports.useHiddenBlockIds=useHiddenBlockIds;exports.useHighlightBlockId=useHighlightBlockId;exports.useInlineEditing=useInlineEditing;exports.useLanguages=useLanguages;exports.useLibraryBlocks=useLibraryBlocks;exports.useMediaManagerComponent=useMediaManagerComponent;exports.usePartailBlocksStore=usePartialBlocksStore;exports.usePartialBlocksList=usePartialBlocksList;exports.usePasteBlocks=usePasteBlocks;exports.usePermissions=usePermissions;exports.usePreviewMode=usePreviewMode;exports.useRemoveAllClassesForBlock=useRemoveAllClassesForBlock;exports.useRemoveBlocks=useRemoveBlocks;exports.useRemoveClassesFromBlocks=useRemoveClassesFromBlocks;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.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;
67
+ `,document.head.appendChild(g),()=>{const x=document.getElementById("rte-modal-styles");x&&x.remove()}}},[o]);const u=react.useEditor({extensions:[StarterKit,Link.configure({openOnClick:!1,HTMLAttributes:{class:"text-primary underline"}}),TextAlign.configure({types:["heading","paragraph"],alignments:["left","center","right"],defaultAlignment:"left"}),Underline,Placeholder.configure({placeholder:"Enter text here",emptyEditorClass:"cursor-text before:content-[attr(data-placeholder)] before:absolute before:opacity-50 before:pointer-events-none"})],content:l||"",onUpdate:({editor:g})=>{const x=g.getHTML();r(x)},onBlur:({editor:g})=>{const x=g.getHTML();i(a,x)},editorProps:{attributes:{class:"prose prose-sm focus:outline-none min-h-[300px] p-2 dark:prose-invert prose-p:m-0 prose-blockquote:m-2 prose-blockquote:ml-4 prose-ul:m-0 prose-ol:m-0 prose-li:m-0"}}});React.useEffect(()=>{o&&u&&(d.current!==l&&(d.current=l||"",u.commands.setContent(l||"")),setTimeout(()=>{u.commands.focus()},100))},[o,u]),React.useEffect(()=>{c.current&&u&&(c.current.__chaiRTE=u)},[u,o]);const p=g=>{if(!u)return;const x=`{{${g}}}`;u.commands.focus();const{from:f,to:h}=u.state.selection;if(f!==h)u.chain().deleteSelection().insertContent(x).run();else{const{state:b}=u,C=b.selection.from,A=b.doc.textBetween(Math.max(0,C-1),C),B=b.doc.textBetween(C,Math.min(C+1,b.doc.content.size));let _="";C>0&&A!==" "&&!/[.,!?;:]/.test(A)&&(_=" ");let S="";B&&B!==" "&&!/[.,!?;:]/.test(B)&&(S=" "),u.chain().insertContent(_+x+S).run()}};return jsxRuntime.jsx(toggle.Dialog,{open:o,onOpenChange:g=>!g&&n(),children:jsxRuntime.jsxs(toggle.DialogContent,{className:"max-h-[90vh] overflow-y-auto sm:max-w-[800px]",children:[jsxRuntime.jsx(toggle.DialogHeader,{children:jsxRuntime.jsxs(toggle.DialogTitle,{className:"flex items-center justify-between pr-8",children:[jsxRuntime.jsx("span",{children:"Rich Text Editor"}),Object.keys(m).length>0&&jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx("span",{className:"mr-2 text-sm text-muted-foreground",children:"Add field:"}),jsxRuntime.jsx("div",{className:"rte-path-selector",children:jsxRuntime.jsx(NestedPathSelector,{data:m,onSelect:p})})]})]})}),jsxRuntime.jsxs("div",{id:`chai-rte-modal-${a}`,ref:c,className:"rounded-md border border-input",children:[jsxRuntime.jsx(MenuBar,{editor:u}),jsxRuntime.jsx(react.EditorContent,{editor:u,id:`modal-${a}`,className:"p-2"})]}),jsxRuntime.jsx("div",{className:"mt-4 flex justify-end",children:jsxRuntime.jsx(toggle.Button,{onClick:n,children:"Done"})})]})})},RichTextEditorField=({id:o,placeholder:n,value:a,onChange:l,onBlur:r})=>{const i=React.useRef(null),[c,d]=React.useState(!1),[m,u]=React.useState(""),p=react.useEditor({extensions:[StarterKit,Link.configure({openOnClick:!1,HTMLAttributes:{class:"text-primary underline"}}),TextAlign.configure({types:["heading","paragraph"],alignments:["left","center","right"],defaultAlignment:"left"}),Underline,Placeholder.configure({placeholder:n||"Enter text here",emptyEditorClass:"cursor-text before:content-[attr(data-placeholder)] before:absolute before:opacity-50 before:pointer-events-none"})],content:a||"",onUpdate:({editor:f})=>{const h=f.getHTML();l(h),c||u(h)},onBlur:({editor:f})=>{const h=f.getHTML();r(o,h)},editorProps:{attributes:{class:"prose prose-sm focus:outline-none min-h-[100px] p-1 dark:prose-invert prose-p:m-0 prose-blockquote:m-2 prose-blockquote:ml-4 prose-ul:m-0 prose-ol:m-0 prose-li:m-0"}}});React.useEffect(()=>{i.current.__chaiRTE=p},[p]),React.useEffect(()=>{u(a||"")},[a]);const g=f=>{l(f)},x=()=>{d(!1),p&&p.commands.setContent(m)};return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("div",{className:"relative",children:jsxRuntime.jsxs("div",{id:`chai-rte-${o}`,ref:i,className:"mt-1 rounded-md border border-input",children:[jsxRuntime.jsx(MenuBar,{editor:p,onExpand:()=>d(!0)}),jsxRuntime.jsx(react.EditorContent,{editor:p,id:o,placeholder:n})]})}),c&&jsxRuntime.jsx(RTEModal,{isOpen:c,onClose:x,id:o,value:m,onChange:g,onBlur:r})]})},SliderField=({formData:o,onChange:n})=>{const[a]=useBlocksStore(),l=useSelectedBlock(),r=useWrapperBlock(),{addCoreBlock:i}=useAddBlock(),[,c]=useSelectedBlockIds();if(!l&&!r)return null;const d=(l==null?void 0:l._type)==="Slider"?l:r,m=lodashEs.find(a,{_parent:d==null?void 0:d._id,_type:"Slides"});if(!m)return null;const u=lodashEs.filter(a,{_parent:m==null?void 0:m._id,_type:"Slide"}),p=(o==null?void 0:o.currentSlide)||lodashEs.get(u,"0._id");React.useEffect(()=>{(l==null?void 0:l._type)==="Slide"&&(o==null?void 0:o.currentSlide)!==(l==null?void 0:l._id)&&n({...o,currentSlide:l==null?void 0:l._id})},[l]),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 g=()=>{const h=lodashEs.findIndex(u,{_id:p});if(h>-1){const j=(h+1)%u.length,b=lodashEs.get(u,[j,"_id"]);if(!b)return;n({...o,currentSlide:b}),c([b])}},x=()=>{const h=lodashEs.findIndex(u,{_id:p});if(h>-1){const j=(h-1+u.length)%u.length,b=lodashEs.get(u,[j,"_id"]);if(!b)return;n({...o,currentSlide:b}),c([b])}},f=()=>{const h=i({styles:"#styles:,h-full w-full min-w-full",type:"Slide"},m==null?void 0:m._id),j=h==null?void 0:h._id;j&&(n({...o,currentSlide:j}),c([j]))};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(lucideReact.ChevronLeft,{className:"h-3 w-3 stroke-[3]"})}),jsxRuntime.jsx("div",{className:"whitespace-nowrap text-center text-[10px] text-slate-500",children:p?jsxRuntime.jsxs("span",{className:"",children:[jsxRuntime.jsxs("b",{className:"text-[12px]",children:[" ",lodashEs.findIndex(u,{_id:p})+1]}),"/",u.length]}):"-"}),jsxRuntime.jsx("button",{onClick:g,className:"rounded bg-gray-200 p-1.5 hover:opacity-80",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-3 w-3 stroke-[3]"})}),jsxRuntime.jsxs("button",{onClick:f,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(lucideReact.PlusCircle,{className:"h-3 w-3 stroke-[2]"}),"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:h=>{let j=h.target.value;j.length&&(j=j.replace("-","")),n({...o,autoplayInterval:j})}})]})]})})]})},SourcesField=({formData:o,onChange:n})=>{const a=lodashEs.get(o,"srcsets",[])||[],l=(c,d)=>{const m=c.target.name,u=c.target.value;n({srcsets:lodashEs.map(a,(p,g)=>g===d?{...p,[m]:u}:p)})},r=()=>{n({srcsets:[...a,{}]})},i=c=>{n({srcsets:lodashEs.reject(a,(d,m)=>m===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:r,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(lucideReact.Plus,{size:12})})]}),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:()=>i(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(lucideReact.X,{size:10,className:"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:m=>l(m,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:m=>l(m,d)})]})]},d))})]})},CodeEditor=({id:o,placeholder:n})=>{const{t:a}=reactI18next.useTranslation(),[,l]=useCodeEditor(),r=useSelectedBlock();if(typeof window>"u")return null;const i=o.replace("root.",""),c=lodashEs.get(r,i,""),d=()=>{const m=r==null?void 0:r._id;l({blockId:m,blockProp:i,placeholder:n,initialCode:lodashEs.get(r,i,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(toggle.Button,{onClick:d,size:"sm",variant:"outline",className:"w-fit",children:a("Open code editor")})]})},CollectionFilterSortField=({id:o,value:n,onChange:a,onBlur:l})=>{const r=useBuilderProp("collections",[]),i=useSelectedBlock(),c=lodashEs.get(i,"repeaterItems","").replace(/\{\{(.*)\}\}/g,"$1").replace(applyBinding.COLLECTION_PREFIX,""),d=lodashEs.find(r,{id:c}),m=o==="root.filter"?"filters":"sorts",u=lodashEs.get(d,m,[]);return jsxRuntime.jsx("div",{children:jsxRuntime.jsxs("select",{value:n,onChange:p=>a(p.target.value),onBlur:p=>l(o,p.target.value),children:[jsxRuntime.jsx("option",{value:"",children:"Select"}),u.map(p=>jsxRuntime.jsx("option",{value:p.id,children:p.name},p.id))]})})},JSONFormFieldTemplate=({id:o,classNames:n,label:a,children:l,errors:r,help:i,hidden:c,required:d,schema:m,formData:u,onChange:p})=>{const{selectedLang:g,fallbackLang:x,languages:f}=useLanguages(),h=React.useMemo(()=>lodashEs.isEmpty(f)?"":lodashEs.isEmpty(g)?x:g,[f,g,x]),j=React.useMemo(()=>lodashEs.get(LANGUAGES,h,h),[h]),b=usePageExternalData(),C=useSelectedBlock(),A=runtime.useRegisteredChaiBlocks(),B=React.useMemo(()=>lodashEs.get(A,[C==null?void 0:C._type,"i18nProps"],[]),[A,C==null?void 0:C._type]),[_,S]=React.useState(null);if(c)return null;if(m.type==="boolean")return jsxRuntime.jsx("div",{className:n,children:l});const E=B==null?void 0:B.includes(o.replace("root.",""));if(m.type==="array"){const w=_===o;return jsxRuntime.jsxs("div",{className:`${n} relative`,children:[m.title&&jsxRuntime.jsx("div",{className:"flex items-center justify-between gap-1",children:jsxRuntime.jsxs("label",{htmlFor:o,onClick:()=>S(w?null:o),className:"flex cursor-pointer items-center gap-x-1 py-1 leading-tight duration-200 hover:bg-slate-100",children:[w?jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-3 w-3"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-3 w-3"}),jsxRuntime.jsx(lucideReact.List,{className:"h-3 w-3"}),jsxRuntime.jsx("span",{className:"leading-tight",children:a})," ",jsxRuntime.jsx(toggle.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:u==null?void 0:u.length})}),m.description&&jsxRuntime.jsx(toggle.TooltipProvider,{children:jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(lucideReact.Info,{className:"h-3 w-3 text-muted-foreground/70",onClick:R=>R.stopPropagation(),onMouseDown:R=>R.stopPropagation()})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"max-w-xs",children:m.description})]})})]})}),(u==null?void 0:u.length)===0?jsxRuntime.jsx("div",{className:"h-0 overflow-hidden",children:l}):jsxRuntime.jsxs("div",{className:`${w?"pt-0.5":"h-0 overflow-hidden"}`,children:[l,r,i]})]})}return jsxRuntime.jsxs("div",{className:n,children:[m.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:o,className:m.type==="object"?"pb-2":"",children:[a," ",E&&jsxRuntime.jsxs("small",{className:"text-[9px] text-zinc-400",children:[" ",j]}),d&&m.type!=="object"?" *":null]}),m.description&&jsxRuntime.jsx(toggle.TooltipProvider,{children:jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(lucideReact.Info,{className:"h-3 w-3 text-muted-foreground/70"})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"max-w-xs",children:m.description})]})})]}),!m.enum&&!m.oneOf&&b&&jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsx(DataBindingSelector,{schema:m,onChange:w=>{p(w,u,o)},id:o,formData:u})})]}),l,r,i]})},RepeaterBindingWidget=({value:o,onChange:n})=>{var i;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(lucideReact.File,{className:"h-4 w-4"})," Choose a collection"]});const a=`{{${applyBinding.COLLECTION_PREFIX}`,l=o==null?void 0:o.startsWith(a);let r=o;return l&&(r=(i=o==null?void 0:o.replace(a,""))==null?void 0:i.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:[" ",l?jsxRuntime.jsx(lucideReact.Database,{className:"h-3 min-h-3 w-3 min-w-3"}):null,jsxRuntime.jsxs(toggle.Tooltip,{delayDuration:500,children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx("span",{className:"cursor-default truncate",children:r})}),jsxRuntime.jsx(toggle.TooltipContent,{side:"left",hidden:r.length<50,children:r})]})]}),jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.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(lucideReact.X,{className:"h-4 w-4"})})}),jsxRuntime.jsx(toggle.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(lucideReact.Plus,{className:"h-3 w-3"})," ",jsxRuntime.jsx("span",{children:"Add"})]})}),JSONForm=React.memo(({blockId:o,schema:n,uiSchema:a,formData:l,onChange:r})=>{const{selectedLang:i}=useLanguages(),c=useBlockSettingComponents("widget"),d=useBlockSettingComponents("field"),m=useBlockSettingComponents("template"),u=web.useThrottledCallback(async({formData:p},g)=>{lodashEs.get(p,g)===void 0&&lodashEs.set(p,g,""),r({formData:p},g)},[r,i],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},...m},idSeparator:".",autoComplete:"off",omitExtraData:!1,liveOmit:!1,liveValidate:!1,validator,uiSchema:a,schema:n,formData:l,onChange:({formData:p},g)=>{if(!g||o!==(p==null?void 0:p._id))return;const x=lodashEs.take(g.split("."),2).join(".").replace("root.","");u({formData:p},x)}},i)}),formDataWithSelectedLang=(o,n,a)=>{const l=lodashEs.cloneDeep(o);return lodashEs.forEach(lodashEs.keys(o),r=>{lodashEs.includes(lodashEs.get(a,"i18nProps",[]),r)&&!lodashEs.isEmpty(n)&&(l[r]=lodashEs.get(o,`${r}-${n}`))}),l};function BlockSettings(){const{selectedLang:o}=useLanguages(),n=useSelectedBlock(),a=useUpdateBlocksPropsRealtime(),l=useUpdateBlocksProps(),r=runtime.getRegisteredChaiBlock(n==null?void 0:n._type),i=formDataWithSelectedLang(n,o,r),[c,d]=React.useState(i),[m,u]=React.useState(!1),p=useWrapperBlock(),g=runtime.getRegisteredChaiBlock(p==null?void 0:p._type),x=formDataWithSelectedLang(p,o,g),f=({formData:S},y,E)=>{y&&(c==null?void 0:c._id)===n._id&&l([n._id],{[y]:lodashEs.get(S,y)},E)},h=React.useCallback(lodashEs.debounce(({formData:S},y,E)=>{f({formData:S},y,E),d(S)},1500),[n==null?void 0:n._id,o]),j=({formData:S},y)=>{y&&(a([n._id],{[y]:lodashEs.get(S,y)}),h({formData:S},y,{[y]:lodashEs.get(c,y)}))},b=({formData:S},y)=>{y&&(a([p._id],{[y]:lodashEs.get(S,y)}),h({formData:S},y,{[y]:lodashEs.get(c,y)}))},{schema:C,uiSchema:A}=React.useMemo(()=>{const S=n==null?void 0:n._type;if(!S)return{schema:{},uiSchema:{}};try{const{schema:y,uiSchema:E}=runtime.getBlockFormSchemas(S);if(S==="Repeater"){const w=lodashEs.get(n,"repeaterItems","");lodashEs.startsWith(w,`{{${applyBinding.COLLECTION_PREFIX}`)?(lodashEs.set(E,"filter",{"ui:widget":"collectionSelect"}),lodashEs.set(E,"sort",{"ui:widget":"collectionSelect"})):(lodashEs.set(E,"filter",{"ui:widget":"hidden"}),lodashEs.set(E,"sort",{"ui:widget":"hidden"}))}return{schema:y,uiSchema:E}}catch{return{schema:{},uiSchema:{}}}},[n]),{wrapperSchema:B,wrapperUiSchema:_}=React.useMemo(()=>{if(!p||!(p!=null&&p._type))return{wrapperSchema:{},wrapperUiSchema:{}};const S=p==null?void 0:p._type,{schema:y={},uiSchema:E={}}=runtime.getBlockFormSchemas(S);return{wrapperSchema:y,wrapperUiSchema:E}},[p]);return jsxRuntime.jsxs("div",{className:"no-scrollbar overflow-x-hidden px-px",children:[!lodashEs.isEmpty(p)&&jsxRuntime.jsxs("div",{className:"mb-4 rounded border bg-zinc-100 px-1",children:[jsxRuntime.jsxs("div",{onClick:()=>u(S=>!S),className:"flex cursor-pointer items-center gap-x-1 py-2 text-xs font-medium leading-tight hover:bg-slate-100",children:[m?jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-4 w-4 stroke-[3] text-slate-400"}):jsxRuntime.jsx(lucideReact.ChevronRight,{className:"h-4 w-4 stroke-[3] text-slate-400"}),lodashEs.startCase(p._type)," settings"," ",p._name&&jsxRuntime.jsxs("span",{className:"text-[11px] font-light text-slate-400",children:["(",p._name,")"]})]}),jsxRuntime.jsx("div",{className:m?"h-auto":"invisible h-0",children:jsxRuntime.jsx(JSONForm,{blockId:p==null?void 0:p._id,onChange:b,formData:x,schema:B,uiSchema:_})})]}),lodashEs.isEmpty(C)?null:jsxRuntime.jsx(JSONForm,{blockId:n==null?void 0:n._id,onChange:j,formData:i,schema:C,uiSchema:A})]})}const BlockStylingProps=()=>{var f;const o=useSelectedBlock(),[n,a]=useSelectedStylingBlocks(),l=useRemoveClassesFromBlocks(),[r]=useSelectedBlockIds(),{t:i}=reactI18next.useTranslation();if(!o)return null;const c=Object.keys(o).filter(h=>typeof o[h]=="string"&&o[h].startsWith("#styles:")),{reset:d}=useResetBlockStyles(),m=!lodashEs.isEmpty(c)&&c.length>1,u=lodashEs.get(o,(f=n[0])==null?void 0:f.prop,""),{classes:p=""}=applyBinding.getSplitChaiClasses(u)||{},g=p?p.split(" ").filter(h=>!lodashEs.isEmpty(h)):[],x=h=>lodashEs.find(n,j=>j.prop===h);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:m&&jsxRuntime.jsxs("div",{className:"flex flex-wrap gap-1",children:[jsxRuntime.jsxs("label",{htmlFor:"block-styling-props",className:"py-1 text-xs",children:[i("Style element"),":"]}),jsxRuntime.jsx("div",{className:"flex flex-wrap gap-2",children:lodashEs.map(c,h=>jsxRuntime.jsxs(toggle.Badge,{className:"flex cursor-pointer items-center gap-1 pr-1",variant:x(h)?"default":"secondary",onClick:()=>{a([{id:`${h}-${o._id}`,blockId:o._id,prop:h}])},children:[lodashEs.startCase(h),jsxRuntime.jsxs(toggle.DropdownMenu,{children:[jsxRuntime.jsx(toggle.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:j=>j.stopPropagation(),children:jsxRuntime.jsx(lucideReact.MoreVertical,{className:"h-3 w-3"})})}),jsxRuntime.jsxs(toggle.DropdownMenuContent,{side:"bottom",className:"border-border text-xs",children:[jsxRuntime.jsx(toggle.DropdownMenuItem,{className:"text-xs",onClick:()=>{d(h)},children:i("Reset style")}),jsxRuntime.jsx(toggle.DropdownMenuItem,{className:"text-xs",onClick:()=>{l(r,g,!0)},children:i("Clear styles")})]})]})]},h))}),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 l=n.length?new RegExp(n.join("|"),"g"):/XXXXXX/g;a=a.replace(l,"");const r=o.match(l),i=r&&r.length>1,c=!lodashEs.isEmpty(a)&&Number.isNaN(Number(a));return i||c?{error:"Invalid value"}:r&&(r[0]==="auto"||r[0]==="none")?{value:r[0],unit:""}:{value:a,unit:r?r[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 l=o.match(/border-?(x|y|t|r|b|l)?\d+/g);if(l)return{value:l[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[l,r]=lodashEs.map(a.split("/"),i=>parseInt(i,10));return{value:n+(l/r*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,""),l=o.startsWith("-")?"-":"",r=lodashEs.first(a.match(/\d+.\d+|\d+/g));return{value:`${l}${r}`,unit:a.replace(r,"")}},getValueAndUnitForTWClass=o=>lodashEs.isEmpty(o)?{value:"",unit:""}:getTwClassValue(o),DragStyleButton=({unit:o,currentValue:n,onDrag:a,onDragEnd:l,onDragStart:r,negative:i,cssProperty:c})=>{const{setDragData:d}=React.useContext(BlockSettingsContext);return jsxRuntime.jsx("button",{type:"button",onMouseDown:m=>{const u={onDrag:a,onDragEnd:l,dragging:!0,dragStartY:m.pageY,dragStartValue:`${n}`,dragUnit:o,negative:i,cssProperty:c};r(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(l=>jsxRuntime.jsx(toggle.Button,{className:"h-max rounded-none px-1 py-1 text-right text-[11px] hover:bg-blue-400",color:n===l?"primary":void 0,size:"sm",onClick:r=>{r.stopPropagation(),o(l)},children:l},l))}),THROTTLE_TIME=50,AdvanceChoices=o=>{const[n,a]=React.useState(!1),[l,r]=React.useState(""),{currentClass:i,onChange:c,classPrefix:d,cssProperty:m,units:u,negative:p}=o,[g,x]=React.useState(m!=null&&m.toLowerCase().includes("width")?"%":u[0]),[f,h]=React.useState(!1),[j,b]=React.useState(""),[C,A]=React.useState(!1),[B,_]=React.useState(!1);React.useEffect(()=>{const{value:R,unit:k}=getClassValueAndUnit(i);if(k===""){r(R),x(m!=null&&m.toLowerCase().includes("width")?"%":lodashEs.first(u));return}x(k),r(k==="class"||lodashEs.isEmpty(R)?"":R)},[i,m,u]);const S=web.useThrottledCallback(R=>c(R),[c],THROTTLE_TIME),y=web.useThrottledCallback(R=>c(R,!1),[c],THROTTLE_TIME),E=React.useCallback((R=!1)=>{const k=getUserInputValues(`${l}`,u);if(lodashEs.get(k,"error",!1)){h(!0);return}const v=lodashEs.get(k,"unit")!==""?lodashEs.get(k,"unit"):g;if(v==="auto"||v==="none"){S(`${d}${v}`);return}if(lodashEs.get(k,"value")==="")return;const N=`${lodashEs.get(k,"value","").startsWith("-")?"-":""}${d}[${lodashEs.get(k,"value","").replace("-","")}${v==="-"?"":v}]`;R?y(N):S(N)},[S,y,l,g,d,u]),w=React.useCallback(R=>{const k=getUserInputValues(`${l}`,u);if(lodashEs.get(k,"error",!1)){h(!0);return}if(R==="auto"||R==="none"){S(`${d}${R}`);return}if(lodashEs.get(k,"value")==="")return;const v=lodashEs.get(k,"unit")!==""?lodashEs.get(k,"unit"):R,N=`${lodashEs.get(k,"value","").startsWith("-")?"-":""}${d}[${lodashEs.get(k,"value","").replace("-","")}${v==="-"?"":v}]`;S(N)},[S,l,d,u]);return jsxRuntime.jsx("div",{className:"flex w-full flex-col",children:jsxRuntime.jsx("div",{className:"flex items-center justify-start",children:g==="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:i}),jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.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(toggle.TooltipContent,{children:"Current value is using a Tailwind preset class."})]})]}):jsxRuntime.jsxs("div",{className:`group relative flex items-center ${C?"z-auto":""}`,children:[jsxRuntime.jsxs("div",{className:"flex items-center rounded-md border border-border",children:[["none","auto"].indexOf(g)!==-1?null:jsxRuntime.jsx("input",{readOnly:g==="class",onKeyPress:R=>{R.key==="Enter"&&E()},onKeyDown:R=>{if(R.keyCode!==38&&R.keyCode!==40)return;R.preventDefault(),_(!0);const k=lodashEs.parseInt(R.target.value);let v=lodashEs.isNaN(k)?0:k;R.keyCode===38&&(v+=1),R.keyCode===40&&(v-=1);const I=`${v}`,L=`${I.startsWith("-")?"-":""}${d}[${I.replace("-","")}${g==="-"?"":g}]`;y(L)},onKeyUp:R=>{B&&(R.preventDefault(),_(!1))},onBlur:()=>E(),onChange:R=>{h(!1),r(R.target.value)},onClick:R=>{var k;(k=R==null?void 0:R.target)==null||k.select(),a(!1)},value:C?j:l,className:"h-6 w-14 rounded rounded-r-none border border-transparent bg-background pl-2 text-sm focus-visible:outline-0".concat(" ",f?"border-red-500 text-red-500":"border-foreground/20")}),jsxRuntime.jsxs(toggle.Tooltip,{open:n,delayDuration:100,children:[jsxRuntime.jsx(toggle.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:g}),u.length>1?jsxRuntime.jsx(reactIcons.TriangleDownIcon,{}):null]})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"bg-background",children:jsxRuntime.jsx(UnitSelection,{units:u,current:g,onSelect:R=>{a(!1),x(R),w(R)}})})]})]}),["none","auto"].indexOf(g)!==-1||C?null:jsxRuntime.jsx(DragStyleButton,{onDragStart:()=>A(!0),onDragEnd:R=>{if(b(()=>""),A(!1),lodashEs.isEmpty(R))return;const k=`${R}`,I=`${k.startsWith("-")?"-":""}${d}[${k.replace("-","")}${g==="-"?"":g}]`;S(I)},onDrag:R=>{if(lodashEs.isEmpty(R))return;b(R);const k=`${R}`,I=`${k.startsWith("-")?"-":""}${d}[${k.replace("-","")}${g==="-"?"":g}]`;y(I)},currentValue:l,unit:g,negative:p,cssProperty:m})]})})})},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:l}=useTailwindClassList(),r=l(n),i=useCurrentClassByProperty(n),c=React.useMemo(()=>lodashEs.get(i,"cls",""),[i]),{canChange:d}=React.useContext(StyleContext),m=/\[.*\]/g.test(c);return jsxRuntime.jsx("div",{className:o?"w-full rounded":"grow",children:m?jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx(toggle.Input,{className:"w-[70%] rounded py-1",readOnly:!0,value:c}),jsxRuntime.jsxs(toggle.Tooltip,{delayDuration:100,children:[jsxRuntime.jsx(toggle.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(toggle.TooltipContent,{children:"Current value is using a Tailwind arbitrary value."})]})]}):jsxRuntime.jsx(DropDown,{rounded:o,onChange:u=>a(u,n),selected:c,options:r,disabled:!d})})};function DropDown({selected:o,onChange:n,rounded:a=!1,options:l,disabled:r=!1}){const i=o.replace(/.*:/g,"").trim(),{undo:c,redo:d}=useUndoManager();return jsxRuntime.jsxs("select",{disabled:!l.length||r,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:m=>n(m.target.value),onKeyDown:m=>{m.ctrlKey&&(m.key==="z"&&c(),m.key==="y"&&d())},value:i,children:[jsxRuntime.jsx("option",{className:"bg-transparent",value:""}),l.map((m,u)=>jsxRuntime.jsx("option",{className:"bg-transparent",value:m,children:m},`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),l=React.useMemo(()=>lodashEs.get(a,"cls",""),[a]),{canChange:r}=React.useContext(StyleContext),[i,c]=React.useState([]),[d,m]=React.useState({color:"",shade:""}),u=l.split("-"),p=lodashEs.get(u,"1",""),g=lodashEs.get(u,"2",""),x=React.useCallback(j=>{["current","inherit","transparent","black","white"].includes(j)?(c([]),m({color:j})):(c(["50","100","200","300","400","500","600","700","800","900"]),m(b=>({...b,color:j,shade:b.shade?b.shade:"500"})))},[c,m]);React.useEffect(()=>{if(["current","inherit","transparent","black","white"].includes(p))return c([]);c(["50","100","200","300","400","500","600","700","800","900"])},[p]);const f=React.useCallback(j=>{m({color:p,shade:j})},[p]);React.useEffect(()=>{m({color:"",shade:""})},[a]);const{match:h}=useTailwindClassList();return React.useEffect(()=>{const b=`${lodashEs.get(COLOR_PROP,o,"")}-${d.color}${d.shade?`-${d.shade}`:""}`;h(o,b)&&n(b,o)},[h,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:!r,rounded:!0,selected:p,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:g,disabled:!p||!r,onChange:f,options:i})})]})},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(),l=a(o),{canChange:r}=React.useContext(StyleContext),i=useCurrentClassByProperty(o),c=React.useMemo(()=>lodashEs.get(i,"cls",""),[i]);return jsxRuntime.jsx("div",{className:"flex grow flex-wrap gap-1",children:lodashEs.map(l,d=>jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx("button",{type:"button",disabled:!r,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(toggle.TooltipContent,{children:lodashEs.startCase(lodashEs.toLower(d))})]}))})},RangeChoices=({property:o,onChange:n})=>{const{canReset:a,canChange:l}=React.useContext(StyleContext),r=useCurrentClassByProperty(o),i=React.useMemo(()=>lodashEs.get(r,"cls",""),[r]),{getClasses:c}=useTailwindClassList(),d=c(o,[""]),m=d.indexOf(i)>-1?d.indexOf(i):0,u=/\[.*\]/g.test(i);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:i}):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:!l&&(!a||m-1<0),onClick:()=>n(lodashEs.nth(d,m-1),o),children:jsxRuntime.jsx("span",{className:"flex items-center justify-center",children:jsxRuntime.jsx(reactIcons.MinusIcon,{className:!l&&(!a||m-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:!l&&(!a||m+1>=d.length),onClick:()=>n(lodashEs.nth(d,m+1),o),children:jsxRuntime.jsx("span",{className:"flex items-center justify-center",children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:!l&&(!a||m+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:l,property:r,onEmitChange:i=()=>{},units:c,negative:d=!1}=o,[m]=useDarkMode(),[u]=useStylingState(),[,p]=useScreenSizeWidth(),g=useCurrentClassByProperty(r),x=useAddClassesToBlocks(),f=useRemoveClassesFromBlocks(),[h]=useSelectedBlockIds(),j=React.useMemo(()=>lodashEs.get(g,"fullCls",""),[g]),b=React.useCallback((y,E=!0)=>{const w={dark:m,mq:p,mod:u,cls:y,property:r,fullCls:""};(m||u!=="")&&(w.mq="xs");const R=generateFullClsName(w);x(h,[R],E)},[h,m,p,u,r,x]),C=React.useCallback(()=>{f(h,[j],!0)},[h,j,f]),A=React.useMemo(()=>canChangeClass(g,p),[g,p]);React.useEffect(()=>{i(A,g)},[A,i,g]);const[,,B]=useScreenSizeWidth(),_=React.useCallback(y=>{B({xs:400,sm:640,md:800,lg:1024,xl:1420,"2xl":1920}[y])},[B]),S=lodashEs.get(g,"dark",null)===m&&lodashEs.get(g,"mod",null)===u&&lodashEs.get(g,"mq",null)===p;return jsxRuntime.jsx(BlockStyleProvider,{canChange:A,canReset:g&&S,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] ${g&&!S?"text-foreground":""}`,children:n(l)})}),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(g,"cls",""),classPrefix:lodashEs.get(CLASS_PREFIXES,r,""),units:c||[],onChange:b,negative:d,cssProperty:r}):null,a==="icons"&&jsxRuntime.jsx(IconChoices,{property:r,onChange:b}),a==="range"&&jsxRuntime.jsx(RangeChoices,{property:r,onChange:b}),a==="color"&&jsxRuntime.jsx(ColorChoice,{property:r,onChange:b}),a==="dropdown"&&jsxRuntime.jsx(DropDownChoices,{label:l,property:r,onChange:b})]}),jsxRuntime.jsx("div",{className:`w-[30px] cursor-pointer ${j?"visible":"invisible"}`,children:S?jsxRuntime.jsx("button",{type:"button",onClick:()=>C(),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"})}):A&&g?jsxRuntime.jsxs(toggle.Tooltip,{delayDuration:100,children:[jsxRuntime.jsx(toggle.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(toggle.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(g,"mq")),m&&!g.dark?"(Light mode)":""]}),jsxRuntime.jsx("br",{}),jsxRuntime.jsxs("button",{type:"button",onClick:()=>_(lodashEs.get(g,"mq")),className:"block w-full cursor-default text-right font-semibold text-blue-500",children:["Switch to ",lodashEs.get(g,"mq").toUpperCase()]})]})})})]}):null})]})]})})},basicUnits=["px","%","em","rem","ch","vh","vw"],MultipleChoices=({label:o,options:n,borderB:a=!1,borderT:l=!1,type:r="arbitrary",units:i=basicUnits,negative:c=!1})=>{const{t:d}=reactI18next.useTranslation(),[m,u]=React.useState(n[0].key),p=useSelectedBlockCurrentClasses(),g=React.useCallback(x=>lodashEs.map(p,"property").includes(x),[p]);return jsxRuntime.jsxs("div",{className:`mb-2 border-border py-2 first:pt-0 last:pb-0 ${a?"border-b":""} ${l?"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:f},h)=>jsxRuntime.jsx("div",{className:"first:rounded-l last:rounded-r",children:jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("button",{type:"button",onClick:()=>u(f),className:`relative cursor-pointer rounded-full p-1 text-[8px] ${f===m?"bg-[#3E57F0] text-white":"text-gray-600 dark:text-gray-300"}`,children:[React.createElement("div",{className:g(f)?"-bottom-1.5 absolute bg-[#3E57F0] h-[2px] left-0 w-full":""}),React.createElement(lodashEs.get(EDITOR_ICONS,f,reactIcons.BoxIcon),{className:"text-inherit w-3 h-3"})]})}),jsxRuntime.jsx(toggle.TooltipContent,{children:lodashEs.startCase(lodashEs.toLower(x))})]})},`option-${h}`))})]}),jsxRuntime.jsx("div",{className:"mt-0 flex items-center",children:jsxRuntime.jsx(BlockStyle,{type:r,units:[...i],label:"",property:m,negative:c})})]})},NestedOptions=({heading:o,items:n})=>{const{t:a}=reactI18next.useTranslation(),l=useSelectedBlockCurrentClasses(),r=React.useMemo(()=>{const i=m=>lodashEs.flatten(m.map(u=>u.styleType==="multiple"?lodashEs.map(u.options,"key"):u.property)),c=lodashEs.flatten(n.map(m=>m.styleType==="accordion"?i(m.items):m.styleType==="multiple"?lodashEs.map(m.options,"key"):m.property)),d=lodashEs.map(l,"property");return lodashEs.intersection(c,d).length>0},[l,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())),r?jsxRuntime.jsx("span",{className:`ml-1 mr-2 inline-block h-[8px] w-[8px] rounded-full ${r?"bg-primary":"bg-gray-300"}`}):null]})}),jsxRuntime.jsx("div",{className:"p-2",children:n.map(i=>i.styleType==="multiple"?jsxRuntime.jsx(MultipleChoices,{...i},i.label):jsxRuntime.jsx(BlockStyle,{...i},i.label))})]})},SectionContext=React.createContext({}),StylingGroup=({section:o,showAccordian:n})=>{const{t:a}=reactI18next.useTranslation(),l=useSelectedBlockCurrentClasses(),r=React.useCallback((c=[])=>{const d={};for(let u=0;u<l.length;u++)d[l[u].property]=l[u].cls;let m=!0;for(const u in c)if(!lodashEs.has(d,u)||d[u]!==c[u]){m=!1;break}return m},[l]),i=React.useMemo(()=>({}),[]);return jsxRuntime.jsx(SectionContext.Provider,{value:i,children:n?jsxRuntime.jsxs(toggle.AccordionItem,{value:o.heading,className:"border-none",children:[jsxRuntime.jsx(toggle.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(toggle.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"&&r(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"&&r(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})=>jsxRuntime.jsx("svg",{className:o?"rotate-90":"",stroke:"currentColor",fill:"currentColor",strokeWidth:"0",viewBox:"0 0 448 512",height:"14px",width:"14px",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,{}),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:"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,{}),width:1420},{title:"Large Desktop (2XL)",content:"Styles set here are applied at 1536px and up",breakpoint:"2xl",icon:jsxRuntime.jsx(reactIcons.DesktopIcon,{}),width:1920}],BreakpointCard=({canvas:o=!1,openDelay:n=400,tooltip:a=!0,title:l,content:r,currentBreakpoint:i,breakpoint:c,width:d,icon:m,onClick:u})=>{const{t:p}=reactI18next.useTranslation();return a?jsxRuntime.jsxs(toggle.HoverCard,{openDelay:n,children:[jsxRuntime.jsx(toggle.HoverCardTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{onClick:()=>u(d),size:"sm",className:"h-7 w-7 rounded-md p-1",variant:c===i?"outline":"ghost",children:m})}),jsxRuntime.jsx(toggle.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:p(l)}),o&&jsxRuntime.jsx("p",{className:"text-xs",children:p(r)})]})})})]}):jsxRuntime.jsx(toggle.Button,{onClick:()=>u(d),size:"sm",className:"h-7 w-7 rounded-md p-1",variant:c===i?"outline":"ghost",children:m})},Breakpoints$1=({openDelay:o=400,canvas:n=!1,tooltip:a=!0})=>{const[l,,r]=useScreenSizeWidth(),[i,c]=useCanvasDisplayWidth(),[d,m]=useSelectedBreakpoints(),u=d,p=m,{t:g}=reactI18next.useTranslation(),x=useBuilderProp("breakpoints",WEB_BREAKPOINTS),f=b=>{u.includes(b)?u.length>2&&p(u.filter(C=>C!==b)):p(C=>[...C,b])},h=b=>{n||r(b),c(b)},j=commonFunctions.getBreakpointValue(n?i:l).toLowerCase();return x.length<4?jsxRuntime.jsx("div",{className:"flex items-center rounded-md",children:lodashEs.map(x,b=>React.createElement(BreakpointCard,{canvas:n,...b,onClick:h,key:b.breakpoint,currentBreakpoint:j}))}):jsxRuntime.jsxs("div",{className:"flex w-full items-center justify-between rounded-md",children:[jsxRuntime.jsx("div",{className:"flex items-center",children:lodashEs.map(x.filter(b=>lodashEs.includes(u,lodashEs.toUpper(b.breakpoint))),b=>React.createElement(BreakpointCard,{canvas:n,openDelay:o,tooltip:a,...b,onClick:h,key:b.breakpoint,currentBreakpoint:j}))}),jsxRuntime.jsxs(toggle.DropdownMenu,{children:[jsxRuntime.jsx(toggle.DropdownMenuTrigger,{asChild:!0,children:jsxRuntime.jsx("span",{className:"cursor-pointer px-2.5 hover:opacity-80",children:jsxRuntime.jsx(reactIcons.DotsVerticalIcon,{className:"scale-90 transform"})})}),jsxRuntime.jsxs(toggle.DropdownMenuContent,{className:"w-56 border-border text-xs",children:[jsxRuntime.jsx(toggle.DropdownMenuLabel,{children:g("Screen sizes")}),jsxRuntime.jsx(toggle.DropdownMenuSeparator,{}),lodashEs.map(x,b=>jsxRuntime.jsx(toggle.DropdownMenuCheckboxItem,{disabled:b.breakpoint==="xs",onCheckedChange:()=>f(lodashEs.toUpper(b.breakpoint)),checked:lodashEs.includes(u,lodashEs.toUpper(b.breakpoint)),children:g(b.title)},b.breakpoint))]})]})]})};function BreakpointSelector(){const[,o]=useScreenSizeWidth(),n=React.useMemo(()=>{const a=WEB_BREAKPOINTS.find(l=>l.breakpoint===o);return a==null?void 0:a.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.jsx("p",{className:"text-xs text-muted-foreground",children:"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]})})})]})}const SECONDS=10;function Countdown(){const[o,n]=React.useState(SECONDS),[a,l]=React.useState(!1);React.useEffect(()=>{if(a&&o>0){const m=setTimeout(()=>{n(o-.1)},100);return()=>clearTimeout(m)}else o<=0&&(l(!1),n(SECONDS))},[a,o]);const r=()=>{l(!0),n(SECONDS)};React.useEffect(()=>{o===SECONDS&&r()},[o]);const i=18,c=2*Math.PI*i,d=c*(1-(SECONDS-o)/SECONDS);return jsxRuntime.jsxs("div",{className:"relative h-4 w-4",children:[jsxRuntime.jsxs("svg",{className:"h-full w-full",viewBox:"0 0 40 40",children:[jsxRuntime.jsx("circle",{className:"text-gray-300",strokeWidth:"4",stroke:"currentColor",fill:"transparent",r:i,cx:"20",cy:"20"}),jsxRuntime.jsx("circle",{className:"text-blue-600",strokeWidth:"4",strokeDasharray:c,strokeDashoffset:d,strokeLinecap:"round",stroke:"currentColor",fill:"transparent",r:i,cx:"20",cy:"20"})]}),jsxRuntime.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:jsxRuntime.jsx("span",{className:"text-xs font-semibold",children:" "})})]})}const AskAIStyles=({blockId:o})=>{const{t:n}=reactI18next.useTranslation(),{askAi:a,loading:l,error:r}=useAskAi(),[i,c]=React.useState(""),d=React.useRef(null),m=React.useRef(null),[u,p]=React.useState();React.useEffect(()=>{var x;(x=d.current)==null||x.focus()},[]);const g=x=>{const{usage:f}=x||{};!r&&f&&p(f),m.current=setTimeout(()=>p(void 0),1e4),r||c("")};return jsxRuntime.jsxs("div",{className:"",children:[jsxRuntime.jsx("h2",{className:"mb-1 text-sm font-semibold leading-none tracking-tight",children:n("Ask AI")}),jsxRuntime.jsx(toggle.Textarea,{ref:d,value:i,onChange:x=>c(x.target.value),placeholder:n("Ask AI to edit styles"),className:"no-scrollbar my-2 w-full border border-border p-2 text-xs",rows:4,onKeyDown:x=>{x.key==="Enter"&&(x.preventDefault(),m.current&&clearTimeout(m.current),p(void 0),a("styles",o,i,g))}}),jsxRuntime.jsxs("div",{className:"my-2 flex items-center gap-2",children:[l?null:jsxRuntime.jsx(toggle.Button,{disabled:i.trim().length<5||l,onClick:()=>{m.current&&clearTimeout(m.current),p(void 0),a("styles",o,i,g)},variant:"default",className:"w-fit",size:"sm",children:l?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader,{className:"h-5 w-5 animate-spin"}),n("Generating... Please wait...")]}):n("Edit with AI")}),l?jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsxs(toggle.Skeleton,{className:"flex w-full items-center space-x-1 px-4 py-1 pl-2",children:[jsxRuntime.jsx(lucideReact.Loader,{className:"h-4 w-4 animate-spin text-gray-500",size:16}),jsxRuntime.jsx("p",{className:"text-xs",children:n("Generating... Please wait...")})]}),jsxRuntime.jsx(toggle.Button,{variant:"destructive",onClick:()=>stop(),className:"hidden w-fit",size:"sm",children:n("Stop")})]}):null]}),u?jsxRuntime.jsx("div",{className:"max-w-full",children:jsxRuntime.jsxs("p",{className:"mb-1 flex justify-between break-words rounded border border-blue-500 bg-blue-100 p-1 text-xs text-blue-500",children:[jsxRuntime.jsxs("span",{children:[n("Total tokens used"),": ",u.totalTokens]}),jsxRuntime.jsx(Countdown,{})]})}):null,jsxRuntime.jsx("div",{className:"max-w-full",children:r&&jsxRuntime.jsx("p",{className:"break-words rounded border border-red-500 bg-red-100 p-1 text-xs text-red-500",children:r.message})})]})};function ManualClasses(){var I;const o=React.useRef(null),[n,a]=React.useState(""),[l,r]=React.useState(-1),i=useFuseSearch(),{t:c}=reactI18next.useTranslation(),[d]=useSelectedStylingBlocks(),m=useSelectedBlock(),u=useAddClassesToBlocks(),p=useRemoveClassesFromBlocks(),[g]=useSelectedBlockIds(),x=useBuilderProp("askAiCallBack",null),[f,h]=React.useState(""),j=(I=lodashEs.first(d))==null?void 0:I.prop,{classes:b}=applyBinding.getSplitChaiClasses(lodashEs.get(m,j,"")),C=b.split(" ").filter(N=>!lodashEs.isEmpty(N)),A=()=>{const N=f.trim().toLowerCase().replace(/ +(?= )/g,"").split(" ");u(g,N,!0),h("")},[B,_]=React.useState([]),S=({value:N})=>{const L=N.trim().toLowerCase(),T=L.match(/.+:/g);let D=[];if(T&&T.length>0){const[P]=T,M=L.replace(P,"");D=i.search(M).map(O=>({...O,item:{...O.item,name:P+O.item.name}}))}else D=i.search(L);return _(lodashEs.map(D,"item"))},y=()=>{_([])},E=N=>N.name,w=N=>jsxRuntime.jsx("div",{className:"rounded-md p-1",children:N.name}),R=React.useMemo(()=>({ref:o,autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,placeholder:c("Enter classes separated by space"),value:f,onFocus:N=>{setTimeout(()=>{N.target&&N.target.select()},0)},onKeyDown:N=>{N.key==="Enter"&&f.trim()!==""&&A()},onChange:(N,{newValue:L})=>h(L),className:"w-full rounded-md text-xs px-2 hover:outline-0 bg-background border-border py-1"}),[f,c,o]),k=N=>{debugger;const L=n.trim().toLowerCase().replace(/ +(?= )/g,"").split(" ");p(g,[N]),u(g,L,!0),a(""),r(-1)},v=()=>{if(navigator.clipboard===void 0){sonner.toast.error(c("Clipboard not supported"));return}navigator.clipboard.writeText(C.join(" ")),sonner.toast.success(c("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.jsxs("div",{className:"flex items-center justify-between gap-x-2",children:[jsxRuntime.jsxs("div",{className:"flex items-center gap-x-2 text-muted-foreground",children:[jsxRuntime.jsx("span",{children:c("Classes")}),jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(reactIcons.CopyIcon,{onClick:v,className:"cursor-pointer"})}),jsxRuntime.jsx(toggle.TooltipContent,{children:jsxRuntime.jsx("p",{children:c("Copy classes to clipboard")})})]})]}),x?jsxRuntime.jsxs(toggle.Popover,{children:[jsxRuntime.jsx(toggle.PopoverTrigger,{asChild:!0,children:jsxRuntime.jsxs(toggle.Button,{variant:"default",className:"h-6 w-fit",size:"sm",children:[jsxRuntime.jsx(lucideReact.SparklesIcon,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{className:"ml-2",children:c("Ask AI")})]})}),jsxRuntime.jsx(toggle.PopoverContent,{side:"left",className:"p-2",children:jsxRuntime.jsx(AskAIStyles,{blockId:m==null?void 0:m._id})})]}):null]}),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:B,onSuggestionsFetchRequested:S,onSuggestionsClearRequested:y,getSuggestionValue:E,renderSuggestion:w,inputProps:R,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(toggle.Button,{variant:"outline",className:"h-6 border-border",onClick:A,disabled:f.trim()==="",size:"sm",children:jsxRuntime.jsx(reactIcons.PlusIcon,{})})]}),jsxRuntime.jsx("div",{className:"flex w-full flex-wrap gap-2 overflow-x-hidden",children:C.map((N,L)=>l===L?jsxRuntime.jsx("input",{ref:o,value:n,onChange:T=>a(T.target.value),onBlur:()=>{k(N)},onKeyDown:T=>{T.key==="Enter"&&k(N)},onFocus:T=>{setTimeout(()=>{T.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"},N):jsxRuntime.jsx("div",{className:"group relative flex max-w-[260px] items-center",children:jsxRuntime.jsxs("button",{onDoubleClick:()=>{h(N),p(g,[N]),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:()=>p(g,[N],!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"}),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:N})]})},N))})]})}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",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",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(),[l,r]=React.useState(""),[i,c]=React.useState({onDrag:u=>u,onDragEnd:u=>u,dragStartY:0,dragging:!1,dragStartValue:0,dragUnit:"",negative:!1,cssProperty:""}),d=web.useThrottledCallback(u=>{const p=!lodashEs.get(i,"negative",!1),g=lodashEs.get(i,"cssProperty","");let x=parseFloat(i.dragStartValue);x=isNaN(x)?0:x;let f=MAPPER[i.dragUnit];(lodashEs.startsWith(g,"scale")||g==="opacity")&&(f=10);let j=(i.dragStartY-u.pageY)/f+x;p&&j<0&&(j=0),g==="opacity"&&j>1&&(j=1),i.onDrag(`${j}`),r(`${j}`)},[i],50),m=React.useCallback(()=>{setTimeout(()=>i.onDragEnd(`${l}`),100),c({onDrag:u=>u,onDragEnd:u=>u,dragStartY:0,dragging:!1,dragStartValue:0,dragUnit:"",negative:!1,cssProperty:""})},[i,l,c]);return lodashEs.isEmpty(a)?null:jsxRuntime.jsxs(BlockSettingsContext.Provider,{value:{setDragData:c},children:[i.dragging?jsxRuntime.jsx("div",{onMouseMove:d,onMouseUp:()=>m(),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(toggle.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:l})=>{const[,r]=jotai.useAtom(draggedBlockAtom),{type:i,icon:c,label:d}=o,{addCoreBlock:m,addPredefinedBlock:u}=useAddBlock(),[,p]=useSelectedBlockIds(),{clearHighlight:g}=useBlockHighlight(),x=()=>{if(lodashEs.has(o,"blocks")){const j=lodashEs.isFunction(o.blocks)?o.blocks():o.blocks;u(runtime.syncBlocksWithDefaults(j),a||null,l)}else m(o,a||null,l);pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)},f=flagged.useFeature("dnd"),{t:h}=reactI18next.useTranslation();return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("button",{disabled:n,onClick:x,type:"button",onDragStart:j=>{j.dataTransfer.setData("text/plain",JSON.stringify(lodashEs.omit(o,["component","icon"]))),j.dataTransfer.setDragImage(new Image,0,0),r(lodashEs.omit(o,["component","icon"])),setTimeout(()=>{p([]),g()},200)},draggable:f?"true":"false",className:"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",children:[React.createElement(c||reactIcons.BoxIcon,{className:"w-4 h-4 mx-auto"}),jsxRuntime.jsx("p",{className:"truncate text-xs",children:lodashEs.capitalize(h(d||i))})]})}),jsxRuntime.jsx(toggle.TooltipContent,{children:jsxRuntime.jsx("p",{children:h(d||i)})})]})})},DefaultChaiBlocks=({parentId:o,position:n,gridCols:a="grid-cols-2"})=>{const l=runtime.useRegisteredChaiBlocks(),r=lodashEs.groupBy(l,"category"),i=lodashEs.uniq(lodashEs.map(r.core,"group"));return jsxRuntime.jsx(ChaiBuilderBlocks,{gridCols:a,parentId:o,position:n,groups:i,blocks:r.core})},hasVideoEmbed=o=>{const n=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,a=/(?:https?:\/\/)?(?:www\.)?(player)?.vimeo\.com/;return n.test(o)||a.test(o)},getVideoURLFromHTML=o=>{if(lodashEs.isEmpty(o))return o;const n=/<video[^>]+src=['"]([^'">]+)['"]/,a=/<iframe[^>]+src=['"]([^'">]+)['"]/,l=o.match(n),r=o.match(a),i=l?l[1]:r?r[1]:null,c=/(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})/,d=/(?:https?:\/\/)?(?:www\.)?player.vimeo\.com/;return i&&(c.test(i)||d.test(i))?i:o},NAME_ATTRIBUTES=["chai-name","data-chai-name"],ATTRIBUTE_MAP={img:{alt:"alt",width:"width",height:"height",src:"image"},video:{src:"url",autoplay:"controls.autoPlay",muted:"controls.muted",loop:"controls.loop",controls:"controls.widgets"},a:{href:"link.href",target:"link.target",type:""},input:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},textarea:{placeholder:"placeholder",required:"required",type:"inputType",name:"fieldName"},select:{placeholder:"placeholder",required:"required",multiple:"multiple",name:"fieldName"},form:{action:"action"}},shouldAddText=(o,n)=>o.children.length===1&&lodashEs.includes(["Heading","Paragraph","Span","ListItem","Button","Label","TableCell","Link","RichText"],n._type),getTextContent=o=>o.map(n=>n.type==="text"?lodashEs.get(n,"content",""):lodashEs.isEmpty(n.children)?"":getTextContent(n.children)).join(""),getSanitizedValue=o=>o===null?"":o,getHeightAndWidthFromClass=o=>{const n=lodashEs.compact(lodashEs.map(o.split(/\s+/),lodashEs.trim)),a=lodashEs.find(n,d=>/^w-/.test(d)),l=lodashEs.find(n,d=>/^h-/.test(d));if(!l||!a)return{height:"",width:""};const r=d=>{if(!d)return;const m=d.match(/^[wh]-(?:\[(.*?)\]|(.+))$/);if(!m)return;if(m[1])return m[1];const u=m[2];return/^\d+(\.\d+)?$/.test(u)?`${Number(u)*4}px`:u==="auto"||lodashEs.includes(u,"%")?u:"16px"},i=r(a),c=r(l);return{width:lodashEs.includes(i,"px")?i:"16px",height:lodashEs.includes(c,"px")?c:"16px"}},getAttrs=o=>{if(o.tagName==="svg")return{};const n={},a=ATTRIBUTE_MAP[o.tagName]||{},l=o.attributes;return lodashEs.forEach(l,({key:r,value:i})=>{if(!lodashEs.includes(NAME_ATTRIBUTES,r))if(a[r]){if(o.tagName==="img"&&r==="src"&&!i.startsWith("http")){const c=lodashEs.find(o.attributes,{key:"width"}),d=lodashEs.find(o.attributes,{key:"height"});c&&d?i=`https://via.placeholder.com/${c==null?void 0:c.value}x${d==null?void 0:d.value}`:i="https://via.placeholder.com/150x150"}lodashEs.set(n,a[r],getSanitizedValue(i))}else lodashEs.includes(["style","class","srcset"],r)||(lodashEs.has(n,"styles_attrs")||(n.styles_attrs={}),lodashEs.startsWith(r,"@")&&(r=r.replace("@","x-on:")),n.styles_attrs[`${r}`]=getSanitizedValue(i))}),delete n.class,n},getStyles=(o,n="styles")=>{if(!o.attributes)return{[n]:`${applyBinding.STYLES_KEY},`};const a=lodashEs.find(o.attributes,{key:"class"});if(a){const l=a.value;return{[n]:`${applyBinding.STYLES_KEY},${l}`}}return{[n]:`${applyBinding.STYLES_KEY},`}},getBlockProps=o=>{const n=lodashEs.get(o,"attributes",[]),a=n.find(d=>d.key==="data-chai-richtext"||d.key==="chai-richtext"),l=n.find(d=>d.key==="data-chai-lightbox"||d.key==="chai-lightbox"),r=n.find(d=>d.key==="data-chai-dropdown"||d.key==="chai-dropdown"),i=n.find(d=>d.key==="data-chai-dropdown-button"||d.key==="chai-dropdown-button"),c=n.find(d=>d.key==="data-chai-dropdown-content"||d.key==="chai-dropdown-content");if(r)return{_type:"Dropdown"};if(i)return{_type:"DropdownButton"};if(c)return{_type:"DropdownContent"};if(a)return{_type:"RichText"};if(l)return{_type:"LightBoxLink"};switch(o.tagName){case"img":return{_type:"Image"};case"input":return{_type:"Input",showLabel:!1};case"hr":return{_type:"Divider"};case"br":return{_type:"LineBreak"};case"textarea":return{_type:"TextArea",showLabel:!1};case"audio":return{_type:"Audio"};case"canvas":return{_type:"Canvas"};case"video":case"iframe":return{_type:"CustomHTML"};case"svg":return{_type:"Icon"};case"select":return{_type:"Select",options:[]};case"option":return{_type:"Option"};case"ul":case"ol":case"dl":return{_type:"List",tag:o.tagName,_listType:o.tagName==="ol"?"list-decimal":"list-none"};case"li":case"dt":return{_type:"ListItem",tag:o.tagName};case"span":case"figcaption":case"legend":return{_type:"Span",tag:o.tagName};case"p":return{_type:"Paragraph",content:""};case"a":return{_type:"Link"};case"form":return{_type:"Form"};case"label":return{_type:"Label"};case"button":return{_type:"Button"};case"code":return{_type:"Box",_name:"Code"};case"h1":case"h2":case"h3":case"h4":case"h5":case"h6":return{_type:"Heading",tag:o.tagName};case"table":return{_type:"Table"};case"tr":return{_type:"TableRow"};case"td":case"th":return{_type:"TableCell",tag:o.tagName};case"thead":return{_type:"TableHead"};case"tbody":return{_type:"TableBody"};case"tfoot":return{_type:"TableFooter"};default:{const d=lodashEs.get(o,"children",[]).length>0?"Box":"EmptyBox";return{_type:d,tag:o.tagName,_name:d=="EmptyBox"||o.tagName==="div"?d:lodashEs.capitalize(o.tagName)}}}},traverseNodes=(o,n=null)=>lodashEs.flatMapDeep(o,a=>{var g,x,f,h,j,b,C,A,B,_;if(a.type==="comment")return[];let l={_id:commonFunctions.generateUUID()};if(n&&(l._parent=n.block._id),a.type==="text")return lodashEs.isEmpty(lodashEs.get(a,"content",""))?[]:n&&shouldAddText(n.node,n.block)?(lodashEs.set(n,"block.content",lodashEs.get(a,"content","")),[]):{...l,_type:"Text",content:lodashEs.get(a,"content","")};const r=lodashEs.get(a,"attributes",[]),i=r.find(S=>S.key==="data-chai-richtext"||S.key==="chai-richtext"),c=r.find(S=>S.key==="data-chai-lightbox"||S.key==="chai-lightbox"),d=r.find(S=>S.key==="data-chai-dropdown"||S.key==="chai-dropdown"),m=r.find(S=>S.key==="data-chai-dropdown-button"||S.key==="chai-dropdown-button"),u=r.find(S=>S.key==="data-chai-dropdown-content"||S.key==="chai-dropdown-content");if(l={...l,...getBlockProps(a),...getAttrs(a),...getStyles(a)},a.attributes){const S=a.attributes.find(y=>lodashEs.includes(NAME_ATTRIBUTES,y.key));S&&(l._name=S.value)}if(i)return l.content=himalaya.stringify(a.children),lodashEs.has(l,"styles_attrs.data-chai-richtext")&&delete l.styles_attrs["data-chai-richtext"],lodashEs.has(l,"styles_attrs.chai-richtext")&&delete l.styles_attrs["chai-richtext"],[l];if(c){const S=["data-chai-lightbox","chai-lightbox","data-vbtype","data-autoplay","data-maxwidth","data-overlay","data-gall","href"];l={...l,href:((g=r.find(y=>y.key==="href"))==null?void 0:g.value)||"",hrefType:((x=r.find(y=>y.key==="data-vbtype"))==null?void 0:x.value)||"video",autoplay:((f=r.find(y=>y.key==="data-autoplay"))==null?void 0:f.value)==="true"?"true":"false",maxWidth:((j=(h=r.find(y=>y.key==="data-maxwidth"))==null?void 0:h.value)==null?void 0:j.replace("px",""))||"",backdropColor:((b=r.find(y=>y.key==="data-overlay"))==null?void 0:b.value)||"",galleryName:((C=r.find(y=>y.key==="data-gall"))==null?void 0:C.value)||""},lodashEs.forEach(S,y=>{lodashEs.has(l,`styles_attrs.${y}`)&&delete l.styles_attrs[y]})}if(d&&(delete l.styles_attrs,l.showDropdown=!1),u&&delete l.styles_attrs,m){delete l.styles_attrs;const S=lodashEs.filter(a.children||[],E=>(E==null?void 0:E.tagName)!=="span");l.content=getTextContent(S);const y=lodashEs.find(a.children||[],E=>(E==null?void 0:E.tagName)==="span"&&lodashEs.some(E.children||[],w=>(w==null?void 0:w.tagName)==="svg"));if(y){const E=lodashEs.find(y.children||[],w=>(w==null?void 0:w.tagName)==="svg");if(E){l.icon=himalaya.stringify([E]);const{height:w,width:R}=getSvgDimensions(E,"16px","16px");l.iconHeight=w,l.iconWidth=R}}return[l]}if(l._type==="Input"){const S=l.inputType||"text";S==="checkbox"?lodashEs.set(l,"_type","Checkbox"):S==="radio"&&lodashEs.set(l,"_type","Radio")}else if(a.tagName==="video"||a.tagName==="iframe"){const S=himalaya.stringify([a]);return hasVideoEmbed(S)&&(lodashEs.set(l,"_type","Video"),lodashEs.set(l,"url",getVideoURLFromHTML(S)),lodashEs.set(l,"styles",`${applyBinding.STYLES_KEY},`),lodashEs.set(l,"controls",{autoPlay:!1,muted:!0,loop:!1,controls:!1})),l.content=S,[l]}else if(a.tagName==="svg"){const S=lodashEs.get(lodashEs.find(a.attributes,{key:"class"}),"value",""),{height:y,width:E}=getHeightAndWidthFromClass(S);if(y&&E)l.styles=`${applyBinding.STYLES_KEY}, ${commonFunctions.cn(`w-${E} h-${y}`,S)}`.trim(),l.height=y==null?void 0:y.replace("px",""),l.width=E==null?void 0:E.replace("px","");else{const w=(A=lodashEs.find(a.attributes,{key:"height"}))==null?void 0:A.value,R=(B=lodashEs.find(a.attributes,{key:"width"}))==null?void 0:B.value;w&&R?(l.styles=`${applyBinding.STYLES_KEY}, ${commonFunctions.cn(`w-[${R}px] h-[${w}px]`,S)}`.trim(),l.height=w,l.width=R):l.styles=`${applyBinding.STYLES_KEY}, ${commonFunctions.cn("w-full h-full",S)}`.trim()}return a.attributes=lodashEs.filter(a.attributes,w=>!lodashEs.includes(["style","width","height","class"],w.key)),l.icon=himalaya.stringify([a]),[l]}else if(a.tagName=="option"&&n&&((_=n.block)==null?void 0:_._type)==="Select")return n.block.options.push({label:getTextContent(a.children),...getAttrs(a)}),[];const p=traverseNodes(a.children,{block:l,node:a});return[l,...p]}),getSvgDimensions=(o,n,a)=>{var m,u;const l=lodashEs.get(o,"attributes",[]),{height:r,width:i}=getHeightAndWidthFromClass(lodashEs.get(lodashEs.find(l,{key:"class"}),"value",""));if(r&&i)return{height:`[${r}px]`,width:`[${i}px]`};const c=(m=lodashEs.find(l,{key:"height"}))==null?void 0:m.value,d=(u=lodashEs.find(l,{key:"width"}))==null?void 0:u.value;return{height:c?`[${c}px]`:a,width:d?`[${d}px]`:n}},getSanitizedHTML=o=>{o=o.replace(/(\w+)=\\?"(.*?)\\?"/g,(l,r,i)=>{let c=i.replace(/\\"/g,'"');return c=c.replace(/{([^}]+)}/g,d=>d.replace(/"/g,'\\"')),`${r}="${c.replace(/\\"/g,'"')}"`}),o=o.replace(/\\n/g,"").replace(/\\\\/g,"").replace(/\\([/<>])/g,"$1").replace(/\\./g,"").replace(/[\n\r\t\f\v]/g,""),o=o.replace(/\$name="[^"]*"/g,"");const n=o.match(/<body[^>]*>[\s\S]*?<\/body>/);return(n&&n.length>0?n[0].replace(/<body/,"<div").replace(/<\/body>/,"</div>"):o).replace(/\s+/g," ").replaceAll("> <","><").replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,"").trim()},getBlocksFromHTML=o=>{const n=himalaya.parse(getSanitizedHTML(o));return lodashEs.isEmpty(o)?[]:lodashEs.flatten(traverseNodes(n))},ImportHTML=({parentId:o,position:n})=>{const{t:a}=reactI18next.useTranslation(),[l,r]=React.useState(""),{addPredefinedBlock:i}=useAddBlock(),c=()=>{const d=getBlocksFromHTML(l);i([...d],o,n),r(""),pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)};return jsxRuntime.jsxs(toggle.Card,{className:"border-border/0 p-0 shadow-none",children:[jsxRuntime.jsx(toggle.CardHeader,{className:"p-3",children:jsxRuntime.jsx(toggle.CardDescription,{children:a("Use HTML snippets from Tailwind CSS component libraries")})}),jsxRuntime.jsx(toggle.CardContent,{className:"space-y-2 px-3 py-0",children:jsxRuntime.jsxs("div",{className:"space-y-1",children:[jsxRuntime.jsx(toggle.Label,{htmlFor:"current",className:"text-sm",children:a("Tailwind HTML snippet")}),jsxRuntime.jsx(toggle.Textarea,{autoFocus:!0,tabIndex:1,ref:d=>d&&d.focus(),onChange:d=>r(d.target.value),rows:12,value:l,placeholder:a("Enter your code snippet here"),className:"resize-none overflow-x-auto whitespace-pre bg-background font-mono text-xs font-normal"})]})}),jsxRuntime.jsx(toggle.CardFooter,{className:"flex flex-col justify-end p-3",children:jsxRuntime.jsx(toggle.Button,{disabled:l.trim()==="",onClick:()=>c(),size:"sm",className:"w-fit",children:a("Import HTML")})})]})},ChaiSelect=({defaultValue:o="",onValueChange:n,options:a,placeholder:l="Select",className:r="",height:i=""})=>{const[c,d]=React.useState(o),m=u=>{const p=u.target.value;d(p),n(p)};return jsxRuntime.jsx("div",{className:commonFunctions.cn("relative inline-block w-full",r),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",i),value:c,onChange:m,children:[jsxRuntime.jsx("option",{value:"",disabled:!0,children:l}),a.map(u=>jsxRuntime.jsx("option",{value:u.value,children:u.label},u.value))]})})};function UILibrariesSelect({uiLibraries:o,library:n,setLibrary:a}){const{t:l}=reactI18next.useTranslation();return n?jsxRuntime.jsxs("div",{className:"h-12",children:[jsxRuntime.jsx("p",{className:"text-xs font-bold text-gray-500",children:l("Choose library")}),jsxRuntime.jsx(ChaiSelect,{className:"mb-1",options:o.map(r=>({value:r.id,label:r.name})),defaultValue:n,onValueChange:r=>a(r)})]}):null}let LIBRARIES_REGISTRY={};const registerChaiLibrary=(o,n)=>{LIBRARIES_REGISTRY[o]={...n,id:o}},useChaiLibraries=()=>lodashEs.values(LIBRARIES_REGISTRY),BlockCard=({block:o,library:n,parentId:a=void 0,position:l=-1})=>{const[r,i]=React.useState(!1),c=React.useMemo(()=>(n==null?void 0:n.getBlock)||(()=>[]),[n]),{addCoreBlock:d,addPredefinedBlock:m}=useAddBlock(),[,u]=useSelectedBlockIds(),{clearHighlight:p}=useBlockHighlight(),g=lodashEs.get(o,"name",lodashEs.get(o,"label")),x=lodashEs.get(o,"description",""),f=flagged.useFeature("dnd"),[,h]=jotai.useAtom(draggedBlockAtom),j=A=>{const B=lodashEs.has(A,"styles_attrs.data-page-section");return A._type==="Box"&&B},b=React.useCallback(async A=>{if(A.stopPropagation(),lodashEs.has(o,"component")){d(o,a,l),pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK);return}i(!0);let B=await c({library:n,block:o});typeof B=="string"&&(B=getBlocksFromHTML(B)),lodashEs.isEmpty(B)||m(runtime.syncBlocksWithDefaults(B),a,l),pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)},[d,m,o,c,n,a,l]),C=async A=>{const B=await c({library:n,block:o});let _=a;if(j(lodashEs.first(B))&&(_=null),!lodashEs.isEmpty(B)){const S={blocks:B,uiLibrary:!0,parent:_};if(A.dataTransfer.setData("text/plain",JSON.stringify(S)),o.preview){const y=new Image;y.src=o.preview,y.onload=()=>{A.dataTransfer.setDragImage(y,0,0)}}else A.dataTransfer.setDragImage(new Image,0,0);h(S),setTimeout(()=>{u([]),p(),pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)},200)}};return jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsxs("div",{onClick:r?()=>{}:b,draggable:f?"true":"false",onDragStart:C,className:clsx("relative mt-2 cursor-pointer overflow-hidden rounded-md border border-border duration-200 hover:border-blue-500 hover:shadow-xl"),children:[r&&jsxRuntime.jsxs("div",{className:"absolute flex h-full w-full items-center justify-center bg-black/70",children:[jsxRuntime.jsx(lucideReact.Loader,{className:"animate-spin",size:15,color:"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:g}):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:g}),x&&jsxRuntime.jsx("p",{className:"text-sm text-gray-600",children:x})]})]})}),jsxRuntime.jsx(toggle.TooltipContent,{children:jsxRuntime.jsxs("div",{className:"max-w-xs",children:[jsxRuntime.jsx("p",{className:"font-medium",children:g}),x&&o.preview&&jsxRuntime.jsx("p",{className:"mt-1 text-xs text-primary-foreground",children:x})]})})]})},UILibrarySection=({parentId:o,position:n})=>{const[a,l]=useSelectedLibrary(),r=useChaiLibraries(),i=r.find(k=>k.id===a)||lodashEs.first(r),{data:c,isLoading:d,resetLibrary:m}=useLibraryBlocks(i),[u,p]=React.useState(""),[g,x]=React.useState([]),f=React.useRef(null);React.useEffect(()=>{c&&c.length>0&&(f.current=new Fuse(c,{keys:["name","label","description","group"],threshold:.4,ignoreLocation:!0}))},[c]),React.useEffect(()=>{if(!u.trim()||!f.current){x([]);return}const k=f.current.search(u).map(v=>v.item);x(k)},[u]);const h=u.trim()&&!lodashEs.isEmpty(g)?g:c,j=lodashEs.groupBy(h,"group"),[b,C]=React.useState(null);React.useEffect(()=>{if(lodashEs.isEmpty(lodashEs.keys(j))){C(null);return}if(!b||!j[b]){C(lodashEs.first(lodashEs.keys(j)));return}},[j,b]);const A=lodashEs.get(j,b,[]),B=React.useRef(null),{t:_}=reactI18next.useTranslation(),S=k=>{B.current&&(clearTimeout(B.current),B.current=null),B.current=setTimeout(()=>{B.current&&C(k)},400)},y=()=>{i!=null&&i.id&&m(i.id)},E=()=>{p("")};if(d)return jsxRuntime.jsxs("div",{className:"mt-4 grid h-full w-full grid-cols-12 gap-2",children:[jsxRuntime.jsx(toggle.Skeleton,{className:"col-span-3 h-full"}),jsxRuntime.jsx(toggle.Skeleton,{className:"col-span-9 h-full"})]});const w=lodashEs.filter(A,(k,v)=>v%2===0),R=lodashEs.filter(A,(k,v)=>v%2===1);return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs("div",{className:"flex h-full max-h-full flex-col",children:[jsxRuntime.jsx("div",{className:"flex items-center gap-2 border-border py-2",children:jsxRuntime.jsxs("div",{className:"relative w-full",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-2 top-2.5 h-4 w-4 text-muted-foreground"}),jsxRuntime.jsx(toggle.Input,{placeholder:_("Search blocks..."),value:u,onChange:k=>p(k.target.value),className:"w-full pl-8 pr-8"}),u&&jsxRuntime.jsx("button",{onClick:E,className:"absolute right-2 top-2.5 text-muted-foreground hover:text-foreground",children:jsxRuntime.jsx(lucideReact.X,{className:"h-4 w-4"})})]})}),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",children:[jsxRuntime.jsxs("div",{className:"flex h-full max-h-full w-60 min-w-60 max-w-60 flex-col gap-1 px-1 pr-2",children:[jsxRuntime.jsx(UILibrariesSelect,{library:i==null?void 0:i.id,setLibrary:l,uiLibraries:r}),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:_("Groups")}),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 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:u?jsxRuntime.jsx("p",{className:"text-sm",children:_("No matching blocks found")}):jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx("p",{className:"text-sm",children:_("Failed to load the UI library. Try again")}),jsxRuntime.jsxs(toggle.Button,{onClick:y,variant:"outline",size:"sm",className:"gap-2",children:[jsxRuntime.jsx(lucideReact.RefreshCw,{className:"h-4 w-4"}),_("Retry")]})]})}):lodashEs.map(j,(k,v)=>jsxRuntime.jsxs("div",{onMouseEnter:()=>S(v),onMouseLeave:()=>clearTimeout(B.current),role:"button",onClick:()=>C(v),className:commonFunctions.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",v===b?"bg-primary text-primary-foreground hover:bg-primary/80":""),children:[jsxRuntime.jsx("span",{children:lodashEs.capitalize(_(v.toLowerCase()))}),jsxRuntime.jsx(reactIcons.CaretRightIcon,{className:"ml-2 h-5 w-5"})]},v))})]})]}),jsxRuntime.jsx("div",{className:"flex h-full max-h-full w-full flex-col border-l border-border",children:jsxRuntime.jsxs(toggle.ScrollArea,{onMouseEnter:()=>B.current?clearTimeout(B.current):null,className:"z-10 flex h-full max-h-full w-full flex-col gap-2 transition-all ease-linear",children:[lodashEs.isEmpty(A)&&!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:_("No blocks found in this group")})}):jsxRuntime.jsxs("div",{className:"grid w-full grid-cols-2 gap-2 px-2",children:[jsxRuntime.jsx("div",{className:"flex flex-col gap-1",children:w.map((k,v)=>jsxRuntime.jsx(BlockCard,{parentId:o,position:n,block:k,library:i},`block-${v}`))}),jsxRuntime.jsx("div",{className:"flex flex-col gap-1",children:R.map((k,v)=>jsxRuntime.jsx(BlockCard,{parentId:o,position:n,block:k,library:i},`block-second-${v}`))})]}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]})})]})})]})})},UILibrariesPanel=({parentId:o,position:n})=>jsxRuntime.jsx(UILibrarySection,{parentId:o,position:n}),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"})=>{const{data:l,isLoading:r,refetch:i,error:c}=usePartialBlocksList(),[d,m]=jotai.useAtom(partialBlocksDataAtom),[u,p]=jotai.useAtom(hasInitializedPartialBlocksAtom);React.useEffect(()=>{if(!u||Object.keys(d.blocks).length===0)if(c)m({blocks:[],groups:[],isLoading:!1,error:c}),p(!0);else if(!r&&Object.keys(l||{}).length>0){const x=Object.entries(l).map(([h,j])=>{const b=j,C=b.type||"partial",A=formatReadableName(C);return{type:"PartialBlock",label:formatReadableName(b.name||h),description:b.description||"",icon:lucideReact.Globe,group:A,category:"partial",partialBlockId:h,_name:b.name}}),f=lodashEs.uniq(lodashEs.map(x,"group"));m({blocks:x,groups:f,isLoading:!1,error:null}),p(!0)}else r?m(x=>({...x,isLoading:!0,error:null})):!r&&Object.keys(l||{}).length===0&&(m({blocks:[],groups:[],isLoading:!1,error:"No partial blocks available"}),p(!0))},[r,l,u,p,m,d.blocks,c]);const g=()=>{m(x=>({...x,isLoading:!0,error:null})),p(!1),i()};return d.isLoading?jsxRuntime.jsx("div",{className:"flex items-center justify-center p-8 text-center text-muted-foreground",children:"Loading partial blocks..."}):d.error||d.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:d.error||"No partial blocks available"}),jsxRuntime.jsx("button",{onClick:g,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:d.groups,blocks:d.blocks})},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:l,gridCols:r="grid-cols-4"})=>{var R;const{t:i}=reactI18next.useTranslation(),[c]=useBlocksStore(),[d,m]=React.useState(""),u=React.useRef(null),[p]=jotai.useAtom(addBlockTabAtom),g=(R=lodashEs.find(c,k=>k._id===a))==null?void 0:R._type,[x,f]=React.useState("all"),[h,j]=React.useState(null),b=React.useRef(null);React.useEffect(()=>{const k=setTimeout(()=>{var v;(v=u.current)==null||v.focus()},0);return()=>clearTimeout(k)},[p]),React.useEffect(()=>{d&&(f("all"),j(null))},[d]),React.useEffect(()=>(b.current=lodashEs.debounce(k=>{f(k)},500),()=>{b.current&&b.current.cancel()}),[]);const C=React.useCallback(k=>{j(k),b.current&&b.current(k)},[]),A=React.useCallback(()=>{j(null),b.current&&b.current.cancel()},[]),B=React.useCallback(k=>{b.current&&b.current.cancel(),f(k),j(null)},[]),_=React.useMemo(()=>d?lodashEs.values(n).filter(k=>{var v,I;return(((v=k.label)==null?void 0:v.toLowerCase())+" "+((I=k.type)==null?void 0:I.toLowerCase())).includes(d.toLowerCase())}):n,[n,d]),S=React.useMemo(()=>d?o.filter(k=>lodashEs.reject(lodashEs.filter(lodashEs.values(_),{group:k}),{hidden:!0}).length>0):o.filter(k=>lodashEs.reject(lodashEs.filter(lodashEs.values(n),{group:k}),{hidden:!0}).length>0),[n,_,o,d]),y=React.useMemo(()=>lodashEs.sortBy(S,k=>CORE_GROUPS.indexOf(k)===-1?99:CORE_GROUPS.indexOf(k)),[S]),E=React.useMemo(()=>x==="all"?_:lodashEs.filter(lodashEs.values(_),{group:x}),[_,x]),w=React.useMemo(()=>x==="all"?y:[x],[y,x]);return jsxRuntime.jsxs("div",{className:"mx-auto flex h-full w-full max-w-3xl flex-col",children:[jsxRuntime.jsx("div",{className:"sticky top-0 z-10 bg-background/80 px-4 py-2 backdrop-blur-sm",children:jsxRuntime.jsx(toggle.Input,{ref:u,type:"search",placeholder:i("Search blocks..."),value:d,className:"-ml-2",onChange:k=>m(k.target.value)})}),jsxRuntime.jsxs("div",{className:"sticky top-10 flex h-[calc(100%-48px)] overflow-hidden",children:[y.length>0&&jsxRuntime.jsx("div",{className:"w-1/4 min-w-[120px] border-r border-border",children:jsxRuntime.jsx(toggle.ScrollArea,{className:"h-full",children:jsxRuntime.jsxs("div",{className:"space-y-1 p-2",children:[jsxRuntime.jsx("button",{onClick:()=>B("all"),onMouseEnter:()=>C("all"),onMouseLeave:A,className:`w-full rounded-md px-2 py-1.5 text-left text-sm font-medium ${x==="all"||h==="all"?"bg-primary text-primary-foreground":"hover:bg-primary/50 hover:text-primary-foreground"}`,children:i("All")},"sidebar-all"),y.map(k=>jsxRuntime.jsx("button",{onClick:()=>B(k),onMouseEnter:()=>C(k),onMouseLeave:A,className:`w-full rounded-md px-2 py-1.5 text-left text-sm ${x===k||h===k?"bg-primary text-primary-foreground":"hover:bg-primary/50 hover:text-primary-foreground"}`,children:lodashEs.capitalize(i(k.toLowerCase()))},`sidebar-${k}`))]})})}),jsxRuntime.jsx("div",{className:"h-full w-3/4 flex-1 overflow-hidden",children:jsxRuntime.jsx(toggle.ScrollArea,{id:"add-blocks-scroll-area",className:"no-scrollbar mr-4 h-full",children:S.length===0&&d?jsxRuntime.jsx("div",{className:"flex flex-col items-center justify-center p-8 text-center text-muted-foreground",children:jsxRuntime.jsxs("p",{children:[i("No blocks found matching"),' "',d,'"']})}):jsxRuntime.jsx("div",{className:"space-y-6 p-4",children:w.map(k=>jsxRuntime.jsxs("div",{className:"space-y-3",children:[jsxRuntime.jsx("h3",{className:"px-1 text-sm font-medium",children:lodashEs.capitalize(i(k.toLowerCase()))}),jsxRuntime.jsx("div",{className:"grid gap-2 "+r,children:lodashEs.reject(x==="all"?lodashEs.filter(lodashEs.values(E),{group:k}):lodashEs.values(E),{hidden:!0}).map(v=>jsxRuntime.jsx(CoreBlock,{parentId:a,position:l,block:v,disabled:!canAcceptChildBlock(g,v.type)||!canBeNestedInside(g,v.type)},v.type))})]},k))})})})]})]})},addBlockTabAtom=utils.atomWithStorage("__add_block_tab","library"),AddBlocksPanel=({className:o,showHeading:n=!0,parentId:a=void 0,position:l=-1})=>{const{t:r}=reactI18next.useTranslation(),[i,c]=jotai.useAtom(addBlockTabAtom),[,d]=jotai.useAtom(showPredefinedBlockCategoryAtom),m=useBuilderProp("importHTMLSupport",!0),{data:u}=usePartialBlocksList(),p=Object.keys(u||{}).length>0,{hasPermission:g}=usePermissions();React.useEffect(()=>{i==="partials"&&!p&&c("library")},[i,p,c]);const x=React.useCallback(()=>{pubsub.publish(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK)},[]),f=useChaiAddBlockTabs(),h=m&&g(PERMISSIONS.IMPORT_HTML),b=useChaiLibraries().length>0;return React.useEffect(()=>{i==="library"&&!b&&c("core")},[i,b,c]),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:r("Add block")}),jsxRuntime.jsx("span",{className:"p-0 text-xs font-light leading-3 opacity-80 xl:pl-1",children:r(i==="html"?"Enter or paste TailwindCSS HTML snippet":"Click to add block to page")})]}):null,jsxRuntime.jsxs(toggle.Tabs,{onValueChange:C=>{d(""),c(C)},value:i,className:"flex h-full max-h-full flex-col overflow-hidden",children:[jsxRuntime.jsxs(toggle.TabsList,{className:"flex w-full items-center",children:[b&&jsxRuntime.jsx(toggle.TabsTrigger,{value:"library",children:r("Library")}),jsxRuntime.jsx(toggle.TabsTrigger,{value:"core",children:r("Blocks")}),p&&jsxRuntime.jsx(toggle.TabsTrigger,{value:"partials",children:r("Partials")}),h?jsxRuntime.jsx(toggle.TabsTrigger,{value:"html",children:r("Import")}):null,lodashEs.map(f,C=>jsxRuntime.jsx(toggle.TabsTrigger,{value:C.id,children:React.createElement(C.tab)},`tab-add-block-${C.id}`))]}),jsxRuntime.jsx(toggle.TabsContent,{value:"core",className:"h-full max-h-full flex-1 pb-20",children:jsxRuntime.jsx("div",{className:"-mx-1.5 h-full max-h-full overflow-hidden",children:jsxRuntime.jsx("div",{className:"mt-2 h-full w-full",children:jsxRuntime.jsx(DefaultChaiBlocks,{gridCols:"grid-cols-4",parentId:a,position:l})})})}),b&&jsxRuntime.jsx(toggle.TabsContent,{value:"library",className:"h-full max-h-full flex-1 pb-20",children:jsxRuntime.jsx(UILibrariesPanel,{parentId:a,position:l})}),p&&jsxRuntime.jsx(toggle.TabsContent,{value:"partials",className:"h-full max-h-full flex-1 pb-20",children:jsxRuntime.jsx("div",{className:"-mx-1.5 h-full max-h-full overflow-hidden",children:jsxRuntime.jsx("div",{className:"mt-2 h-full w-full",children:jsxRuntime.jsx(PartialBlocks,{gridCols:"grid-cols-4",parentId:a,position:l})})})}),h?jsxRuntime.jsx(toggle.TabsContent,{value:"html",className:"h-full max-h-full flex-1 pb-20",children:jsxRuntime.jsx(ImportHTML,{parentId:a,position:l})}):null,lodashEs.map(f,C=>jsxRuntime.jsx(toggle.TabsContent,{value:C.id,children:React.createElement(C.tabContent,{close:x,parentId:a,position:l})},`panel-add-block-${C.id}`))]})]})},placeholderStyle={display:"flex",alignItems:"center",zIndex:1},DefaultCursor=React.memo(function({top:n,left:a}){const l={position:"absolute",pointerEvents:"none",top:n+"px",left:a+"px",right:0};return jsxRuntime.jsx("div",{style:{...placeholderStyle,...l},children:jsxRuntime.jsx("div",{className:"h-0.5 flex-1 rounded-[1px] bg-green-500"})})}),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[l]=useBlocksStore(),r=React.useMemo(()=>l.find(c=>c._id===o),[l,o]),i=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:i,children:jsxRuntime.jsxs("button",{type:"button",className:"flex !cursor-grab items-center p-0.5","aria-label":`Type: ${r==null?void 0:r._type}`,children:[jsxRuntime.jsx("div",{className:"-mt-0.5 h-3 w-3",children:jsxRuntime.jsx(TypeIcon,{type:r==null?void 0:r._type})}),jsxRuntime.jsx("div",{className:"ml-2 truncate text-[11px]",children:(r==null?void 0:r._name)||(r==null?void 0:r._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 l;const a=((l=o.selectedIds[0])==null?void 0:l.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()};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 l=[...a];return a.forEach(r=>{l.push(...getBlocks(o,r==null?void 0:r._id))}),l},SaveToLibraryModal=()=>{const[o,n]=jotai.useAtom(saveToLibraryModalAtom),{t:a}=reactI18next.useTranslation(),[l]=useBlocksStore(),r=()=>n({isOpen:!1,blockId:null}),i=useSaveToLibraryComponent(),c=React.useMemo(()=>{if(!o.blockId)return[];const d=lodashEs.find(l,{_id:o.blockId});return d==null||delete d._parent,[d,...getBlocks(l,d==null?void 0:d._id)]},[o.blockId,l]);return jsxRuntime.jsx(toggle.Dialog,{open:o.isOpen,onOpenChange:d=>!d&&r(),children:jsxRuntime.jsxs(toggle.DialogContent,{className:"p-4 sm:max-w-[450px]",children:[jsxRuntime.jsx(toggle.DialogHeader,{className:"pb-2",children:jsxRuntime.jsx(toggle.DialogTitle,{children:a("Save to Library")})}),i&&!lodashEs.isEmpty(o.blockId)&&jsxRuntime.jsx(i,{blockId:o.blockId,blocks:c,close:r})]})})},SaveToLibrary=()=>{const o=useSelectedBlock(),{t:n}=reactI18next.useTranslation(),[,a]=jotai.useAtom(saveToLibraryModalAtom),l=useSaveToLibraryComponent(),r=()=>{o&&a({isOpen:!0,blockId:o._id})};return l?jsxRuntime.jsxs(toggle.DropdownMenuItem,{className:"flex items-center gap-x-4 text-xs",onClick:r,children:[jsxRuntime.jsx(lucideReact.SaveIcon,{className:"h-4 w-4"})," ",n(o!=null&&o._libBlockId?"Update library block":"Save to library")]}):null},UnlinkLibraryBlock=()=>{const{t:o}=reactI18next.useTranslation(),n=useSelectedBlock(),a=useUpdateBlocksProps(),l=()=>{a([n._id],{_libBlockId:null})};return jsxRuntime.jsxs(toggle.DropdownMenuItem,{onClick:l,className:"flex items-center gap-x-4 text-xs",children:[jsxRuntime.jsx(lucideReact.UnlinkIcon,{className:"h-4 w-4"})," ",o("Unlink from library")]})},CANNOT_COPY_BLOCKS=!navigator.clipboard,CopyPasteBlocks=()=>{const[o]=useBlocksStore(),[n]=useSelectedBlockIds(),{pasteBlocks:a}=usePasteBlocks(),[,l,r]=useCopyBlocks(),{t:i}=reactI18next.useTranslation(),c=useSelectedBlock(),d=React.useCallback(()=>{const m=n.map(u=>{const p=o.find(g=>g._id===u);return{id:u,data:p}});r(m.map(u=>u.id))?sonner.toast.warning("Partial blocks detected. Clone partial blocks?",{cancel:{label:i("No"),onClick:()=>{l(m.map(u=>u.id)),sonner.toast.dismiss()}},action:{label:i("Yes"),onClick:()=>{l(m.map(u=>u.id),!0),sonner.toast.dismiss()}},position:"top-center"}):l(m.map(u=>u.id))},[n,o,l,r]);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[!CANNOT_COPY_BLOCKS&&jsxRuntime.jsxs(toggle.DropdownMenuItem,{disabled:!canDuplicateBlock(c==null?void 0:c._type),onClick:d,className:"flex items-center gap-x-4 text-xs",children:[jsxRuntime.jsx(reactIcons.CopyIcon,{})," ",i("Copy")]}),jsxRuntime.jsxs(toggle.DropdownMenuItem,{className:"flex items-center gap-x-4 text-xs",onClick:()=>{a(n)},children:[jsxRuntime.jsx(reactIcons.CardStackIcon,{})," ",i("Paste")]})]})},CutBlocks=()=>{const[o]=useSelectedBlockIds(),[,n]=useCutBlockIds(),{t:a}=reactI18next.useTranslation();return jsxRuntime.jsxs(toggle.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:l}=reactI18next.useTranslation();return jsxRuntime.jsxs(toggle.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,{})," ",l("Remove")]})},RenameBlock=({node:o})=>{const{t:n}=reactI18next.useTranslation();return jsxRuntime.jsxs(toggle.DropdownMenuItem,{onClick:a=>{a.stopPropagation(),o.edit(),o.deselect()},className:"flex items-center gap-x-4 text-xs",children:[jsxRuntime.jsx(lucideReact.PencilIcon,{className:"h-4 w-4"})," ",n("Rename")]})},BlockContextMenuContent=({node:o})=>{const{t:n}=reactI18next.useTranslation(),[a]=useSelectedBlockIds(),l=useDuplicateBlocks(),r=useSelectedBlock(),{hasPermission:i}=usePermissions(),c=React.useCallback(()=>{l(a)},[a,l]),d=React.useMemo(()=>lodashEs.has(r,"_libBlockId")&&!lodashEs.isEmpty(r._libBlockId),[r==null?void 0:r._libBlockId]);return jsxRuntime.jsxs(toggle.DropdownMenuContent,{side:"bottom",className:"border-border text-xs",children:[i(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsxs(toggle.DropdownMenuItem,{disabled:!canAddChildBlock(r==null?void 0:r._type),className:"flex items-center gap-x-4 text-xs",onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,r),children:[jsxRuntime.jsx(lucideReact.PlusIcon,{size:"14"})," ",n("Add block")]}),jsxRuntime.jsxs(toggle.DropdownMenuItem,{disabled:!canDuplicateBlock(r==null?void 0:r._type),className:"flex items-center gap-x-4 text-xs",onClick:c,children:[jsxRuntime.jsx(reactIcons.CardStackPlusIcon,{})," ",n("Duplicate")]})]}),jsxRuntime.jsx(RenameBlock,{node:o}),i(PERMISSIONS.MOVE_BLOCK)&&jsxRuntime.jsx(CutBlocks,{}),i(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsx(CopyPasteBlocks,{}),d&&jsxRuntime.jsx(UnlinkLibraryBlock,{}),i(PERMISSIONS.CREATE_LIBRARY_BLOCK)&&jsxRuntime.jsx(SaveToLibrary,{}),i(PERMISSIONS.DELETE_BLOCK)&&jsxRuntime.jsx(RemoveBlocks,{})]})},BlockMoreOptions=({children:o,id:n,node:a})=>{const[,l]=useSelectedBlockIds();return jsxRuntime.jsx(jsxRuntime.Fragment,{children:jsxRuntime.jsxs(toggle.DropdownMenu,{onOpenChange:r=>{r&&l([n])},children:[jsxRuntime.jsx(toggle.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 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:l=>l.currentTarget.select(),onBlur:l=>o.submit(l.currentTarget.value),onKeyDown:l=>{l.key==="Enter"&&o.submit(l.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())||""},Node=React.memo(({node:o,style:n,dragHandle:a})=>{var L;const{t:l}=reactI18next.useTranslation(),[r,,i]=useHiddenBlockIds(),[c]=jotai.useAtom(canvasIframeAtom),{hasPermission:d}=usePermissions();let m=null;const u=o.children.length>0,{highlightBlock:p,clearHighlight:g}=useBlockHighlight(),{id:x,data:f,isSelected:h,willReceiveDrop:j,isDragging:b,isEditing:C,handleClick:A}=o,B=T=>{T.stopPropagation(),!r.includes(x)&&o.toggle()},_=T=>{T.isInternal&&(m=T.isOpen,T.isOpen&&T.close())},S=T=>{T.isInternal&&m!==null&&(m?T.open():T.close(),m=null)},[y,E]=jotai.useAtom(currentAddSelection),w=()=>{var T;R(),o.parent.isSelected||E((T=o==null?void 0:o.parent)==null?void 0:T.id)},R=()=>{E(null)},k=T=>{R(),T.stopPropagation(),!o.isOpen&&!r.includes(x)&&o.toggle(),A(T)};React.useEffect(()=>{const T=setTimeout(()=>{j&&!o.isOpen&&!b&&!r.includes(x)&&o.toggle()},500);return()=>clearTimeout(T)},[j,o,b]);const v=(T,D)=>{const P=c.contentDocument||c.contentWindow.document,M=P.querySelector(`[data-block-id=${T}]`);M&&M.setAttribute("data-drop",D);const F=M.getBoundingClientRect(),O=c.getBoundingClientRect();F.top>=O.top&&F.left>=O.left&&F.bottom<=O.bottom&&F.right<=O.right||(P.documentElement.scrollTop=M.offsetTop-O.top)},I=T=>{R();const D=lodashEs.get(o,"parent.id");D!=="__REACT_ARBORIST_INTERNAL_ROOT__"?pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,{_id:D,position:T}):pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,{position:T})};if(x===applyBinding.ROOT_TEMP_KEY)return jsxRuntime.jsxs("div",{className:"group relative w-full cursor-pointer",children:[jsxRuntime.jsx("br",{}),d(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsx("div",{role:"button",onClick:()=>I(-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:"h-2 w-2 stroke-[3]"})," ",l("Add block")]})}),jsxRuntime.jsx("br",{})]});const N=React.useMemo(()=>lodashEs.has(f,"_libBlockId")&&!lodashEs.isEmpty(f._libBlockId)&&(d(PERMISSIONS.CREATE_LIBRARY_BLOCK)||d(PERMISSIONS.EDIT_LIBRARY_BLOCK)),[f,d]);return jsxRuntime.jsx("div",{className:"w-full",children:jsxRuntime.jsxs("div",{onMouseEnter:()=>p(x),onMouseLeave:()=>g(),onClick:k,style:n,"data-node-id":x,ref:r.includes(x)?null:a,onDragStart:()=>_(o),onDragEnd:()=>S(o),onDragOver:T=>{T.preventDefault(),v(x,"yes")},onDragLeave:T=>{T.preventDefault(),v(x,"no")},onDrop:T=>{T.preventDefault(),v(x,"no")},children:[d(PERMISSIONS.ADD_BLOCK)&&(o==null?void 0:o.rowIndex)>0&&(o.parent.isOpen&&canAddChildBlock(lodashEs.get(o,"parent.data._type"))||((L=o==null?void 0:o.parent)==null?void 0:L.id)==="__REACT_ARBORIST_INTERNAL_ROOT__")&&jsxRuntime.jsx("div",{className:"group relative ml-5 h-full w-full cursor-pointer",children:jsxRuntime.jsx("div",{onClick:T=>{T.stopPropagation(),I(o.childIndex)},onMouseEnter:w,onMouseLeave:R,className:"absolute -top-0.5 h-1 w-[90%] rounded bg-primary 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 p-1 outline outline-2 outline-white hover:bg-primary",children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-3 w-3 stroke-[4] text-white"})})})}),jsxRuntime.jsxs("div",{className:cn("group flex w-full cursor-pointer items-center justify-between space-x-px !rounded p-1 outline-none",h?"bg-primary text-primary-foreground":"hover:bg-primary/10 dark:hover:bg-gray-800",j&&canAcceptChildBlock(f._type,"Icon")?"bg-green-200":"",(o==null?void 0:o.id)===y?"bg-primary/10":"",b&&"opacity-20",r.includes(x)?"opacity-50":"",N&&h&&"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:u&&jsxRuntime.jsx("button",{onClick:B,type:"button",children:jsxRuntime.jsx(lucideReact.ChevronRight,{className:`h-3 w-3 stroke-[3] ${h?"text-white":"text-slate-400"}`})})}),jsxRuntime.jsxs("div",{className:cn("leading-1 flex items-center",N&&"text-primary/60",N&&h&&"text-primary/80"),children:[jsxRuntime.jsx(TypeIcon,{type:f==null?void 0:f._type}),C?jsxRuntime.jsx(Input,{node:o}):jsxRuntime.jsx("div",{className:"ml-1.5 flex items-center gap-x-1 truncate text-[13px]",onDoubleClick:T=>{T.stopPropagation(),o.edit(),o.deselect()},children:jsxRuntime.jsx("span",{children:getBlockDisplayName(f)})})]})]}),jsxRuntime.jsxs("div",{className:"invisible flex items-center space-x-1.5 pr-2 group-hover:visible",children:[canAddChildBlock(f==null?void 0:f._type)&&!r.includes(x)&&d(PERMISSIONS.ADD_BLOCK)?jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,{_id:x}),className:"cursor-pointer rounded bg-transparent",asChild:!0,children:jsxRuntime.jsx(reactIcons.PlusIcon,{className:"h-3 w-3"})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"isolate z-[9999]",side:"bottom",children:l("Add block")})]}):null,jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{onClick:T=>{T.stopPropagation(),i(x),o.isOpen&&o.toggle()},className:"cursor-pointer rounded bg-transparent",asChild:!0,children:jsxRuntime.jsx(lucideReact.EyeOffIcon,{size:"15"})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"isolate z-[9999]",side:"bottom",children:l("Hide block")})]}),jsxRuntime.jsx(BlockMoreOptions,{node:o,id:x,children:jsxRuntime.jsx(lucideReact.MoreVertical,{size:"15"})})]})]})]})})}),PasteAtRootContextMenu=({parentContext:o,setParentContext:n})=>{const{t:a}=reactI18next.useTranslation(),{canPaste:l,pasteBlocks:r}=usePasteBlocks();return React.useEffect(()=>{l("root")||n(null)},[l("root")]),!o||!l("root")?null:jsxRuntime.jsx("div",{className:"absolute inset-0",children:jsxRuntime.jsxs(toggle.DropdownMenu,{open:!0,onOpenChange:()=>n(null),children:[jsxRuntime.jsx(toggle.DropdownMenuTrigger,{className:"hidden"}),jsxRuntime.jsx(toggle.DropdownMenuContent,{className:"absolute w-28 p-1 text-xs",style:{top:o.y,left:o.x},children:jsxRuntime.jsxs(toggle.DropdownMenuItem,{className:"flex items-center gap-x-4 text-xs",onClick:()=>{r("root"),n(null)},children:[jsxRuntime.jsx(reactIcons.CardStackIcon,{})," ",a("Paste")]})})]})})},useCanMove=()=>{const[o]=useBlocksStore();return(n,a)=>{var i;const l=(i=lodashEs.find(o,{_id:a}))==null?void 0:i._type,r=lodashEs.first(n.map(c=>{var d;return(d=lodashEs.find(o,{_id:c}))==null?void 0:d._type}));return canAcceptChildBlock(l,r)}},ListTree=()=>{const[treeData]=jotai.useAtom(treeDSBlocks),[ids,setIds]=useSelectedBlockIds(),[cutBlocksIds]=useCutBlockIds(),[,setHiddenBlocks]=useHiddenBlockIds(),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,l)=>a.filter(r=>!l.includes(r._id)).map(r=>({...r,children:r.children?o(r.children,l):[]}));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 l;o.preventDefault(),parentContext&&setParentContext(null);const n=o.target,a=n.getAttribute("data-node-id")||((l=n.closest("[data-node-id]"))==null?void 0:l.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 text-center",children:jsxRuntime.jsxs("p",{className:"mb-1.5 text-sm",children:[t("This page is empty"),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),hasPermission(PERMISSIONS.ADD_BLOCK)&&jsxRuntime.jsxs(toggle.Button,{disabled:!hasPermission(PERMISSIONS.ADD_BLOCK),onClick:()=>pubsub.publish(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK),variant:"default",size:"sm",children:["+ ",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-2 pb-2 text-sm text-muted-foreground",children:[jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{onClick:()=>setHiddenBlocks([]),variant:"outline",className:"h-fit p-1 disabled:cursor-not-allowed disabled:opacity-50",size:"sm",children:jsxRuntime.jsx(lucideReact.Eye,{className:"h-4 w-4"})})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"isolate z-[9999]",children:t("Show hidden blocks")})]}),jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{className:"h-fit p-1",onClick:()=>{var o;return(o=treeRef==null?void 0:treeRef.current)==null?void 0:o.openAll()},variant:"outline",size:"sm",children:jsxRuntime.jsx(lucideReact.ChevronsUpDown,{size:14})})}),jsxRuntime.jsx(toggle.TooltipContent,{className:"isolate z-[9999]",children:t("Expand all")})]}),jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{className:"h-fit p-1",onClick:()=>{var o;return(o=treeRef==null?void 0:treeRef.current)==null?void 0:o.closeAll()},variant:"outline",size:"sm",children:jsxRuntime.jsx(lucideReact.ChevronsDownUp,{size:14})})}),jsxRuntime.jsx(toggle.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(lucideReact.PlusIcon,{className:"h-3 w-3 stroke-[3] text-white"})})})}),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:28,renderDragPreview:DefaultDragPreview,indent:10,onContextMenu,disableDrop:debouncedDisableDrop,idAccessor:"_id",children:Node})]})}),jsxRuntime.jsx(SaveToLibraryModal,{}),jsxRuntime.jsx(PasteAtRootContextMenu,{parentContext,setParentContext})]})},BorderRadiusInput=({value:o,onChange:n,disabled:a})=>{const[l,r]=React.useState(o),i=web.useThrottledCallback(n,[o],200,!0);return jsxRuntime.jsx(toggle.Slider,{min:0,step:1,max:50,disabled:a,value:[Number(l.replace("px",""))],onValueChange:c=>{r(c[0].toString()+"px"),i(c[0].toString())},className:"flex-1 cursor-pointer"})},ColorPickerInput=({value:o,onChange:n})=>{const a=lodashEs.debounce(l=>n(l),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:l=>{const r=l.target.value;/^#[0-9A-F]{6}$/i.test(r)&&a(r)},className:"absolute inset-0 h-full w-full cursor-pointer rounded-lg border-0 opacity-0"})})},FontSelector=({label:o,value:n,onChange:a})=>{const l=runtime.useRegisteredFonts();return React.useEffect(()=>{l.some(r=>r.family===n)||a(l[0].family)},[n,a]),jsxRuntime.jsxs("div",{className:"space-y-0.5",children:[jsxRuntime.jsx(toggle.Label,{className:"mb-1 block text-xs text-gray-600",children:lodashEs.startCase(o)}),jsxRuntime.jsxs(toggle.Select,{value:n,onValueChange:a,children:[jsxRuntime.jsx(toggle.SelectTrigger,{className:"h-8 w-full text-xs text-black",children:jsxRuntime.jsx(toggle.SelectValue,{placeholder:"Select font"})}),jsxRuntime.jsx(toggle.SelectContent,{children:l.map(r=>jsxRuntime.jsx(toggle.SelectItem,{value:r.family,children:r.family},r.family))})]})]})},defaultShadcnPreset={fontFamily:{heading:"Inter",body:"Inter"},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"]}},LazyCssImportModal=React.lazy(()=>Promise.resolve().then(()=>require("./css-import-modal-CdOK43Be.cjs")).then(o=>({default:o.CssImportModal}))),PREV_THEME_KEY="chai-builder-previous-theme",DEFAULT_THEME_PRESET=[{shadcn_default:defaultShadcnPreset}],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(),[l,r]=React__namespace.useState(""),[i,c]=React__namespace.useState(!1),d=useBuilderProp("themePresets",[]),m=useBuilderProp("themePanelComponent",null),{hasPermission:u}=usePermissions();d&&!d.some(S=>Object.keys(S)[0]==="shadcn_default")&&d.push(...DEFAULT_THEME_PRESET);const[p,g]=useTheme(),x=useThemeOptions(),{t:f}=reactI18next.useTranslation(),h=React__namespace.useCallback(S=>{const y={...p};setPreviousTheme(y),g(S),sonner.toast.success("Theme updated",{action:{label:jsxRuntime.jsxs("span",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Undo,{className:"h-4 w-4"})," Undo"]}),onClick:()=>{g(y),clearPreviousTheme(),sonner.toast.dismiss()}},closeButton:!0,duration:15e3})},[p,g]),j=()=>{const S=d.find(y=>Object.keys(y)[0]===l);if(S){const y=Object.values(S)[0];y&&typeof y=="object"&&"fontFamily"in y&&"borderRadius"in y&&"colors"in y?(h(y),r("")):console.error("Invalid preset structure:",y)}else console.error("Preset not found:",l)},b=S=>{h(S),r("")},C=web.useDebouncedCallback((S,y)=>{g(()=>({...p,fontFamily:{...p.fontFamily,[S.replace(/font-/g,"")]:y}}))},[p],200),A=React__namespace.useCallback(S=>{g(()=>({...p,borderRadius:`${S}px`}))},[p]),B=web.useDebouncedCallback((S,y)=>{g(()=>{const E=lodashEs.get(p,`colors.${S}`);return n?lodashEs.set(E,1,y):lodashEs.set(E,0,y),{...p,colors:{...p.colors,[S]:E}}})},[p],200),_=S=>jsxRuntime.jsx("div",{className:"grid grid-cols-1",children:Object.entries(S.items).map(([y])=>{const E=lodashEs.get(p,`colors.${y}.${n?1:0}`);return E?jsxRuntime.jsxs("div",{className:"mt-1 flex items-center gap-x-2",children:[jsxRuntime.jsx(ColorPickerInput,{value:E,onChange:w=>B(y,w)}),jsxRuntime.jsx(toggle.Label,{className:"text-xs font-normal leading-tight",children:y.split(/(?=[A-Z])/).join(" ").replace(/-/g," ").split(" ").map(w=>w.charAt(0).toUpperCase()+w.slice(1)).join(" ")+(!y.toLowerCase().includes("foreground")&&!y.toLowerCase().includes("border")&&!y.toLowerCase().includes("input")&&!y.toLowerCase().includes("ring")&&!y.toLowerCase().includes("background")?" Background":"")})]},y):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(toggle.Label,{className:"text-sm",children:f("Presets")}),jsxRuntime.jsx("div",{className:"flex gap-2",children:jsxRuntime.jsxs(toggle.Button,{className:"px-1",variant:"link",size:"sm",onClick:()=>c(!0),children:[jsxRuntime.jsx(lucideReact.ImportIcon,{className:"h-4 w-4"}),f("Import theme")]})})]}),jsxRuntime.jsxs("div",{className:"flex items-center gap-2 px-0",children:[jsxRuntime.jsx("div",{className:"w-[70%]",children:jsxRuntime.jsxs(toggle.Select,{value:l,onValueChange:r,children:[jsxRuntime.jsx(toggle.SelectTrigger,{className:"h-9 w-full text-sm",children:jsxRuntime.jsx(toggle.SelectValue,{placeholder:"Select preset"})}),jsxRuntime.jsx(toggle.SelectContent,{children:Array.isArray(d)&&d.map(S=>{const y=Object.keys(S)[0],E=y.replaceAll("_"," ");return jsxRuntime.jsx(toggle.SelectItem,{value:y,children:lodashEs.capitalize(E)},y)})})]})}),jsxRuntime.jsx("div",{className:"w-[25%]",children:jsxRuntime.jsx(toggle.Button,{className:"w-full text-sm",disabled:!l,onClick:j,children:f("Apply")})})]})]}),jsxRuntime.jsx(toggle.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(lucideReact.Type,{className:"h-3 w-3 text-gray-600"}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-gray-700",children:"Typography"})]}),(x==null?void 0:x.fontFamily)&&jsxRuntime.jsx("div",{className:"space-y-2",children:Object.entries(x.fontFamily).map(([S,y])=>jsxRuntime.jsx(FontSelector,{label:S,value:p.fontFamily[S.replace(/font-/g,"")]||y[Object.keys(y)[0]],onChange:E=>C(S,E)},S))}),jsxRuntime.jsx(toggle.Separator,{}),(x==null?void 0:x.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(lucideReact.CornerUpRight,{className:"h-3 w-3 text-gray-600"}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-gray-700",children:"Border Radius"})]}),jsxRuntime.jsx(toggle.Badge,{variant:"secondary",className:"text-xs",children:p.borderRadius})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-4 py-2",children:jsxRuntime.jsx(BorderRadiusInput,{value:p.borderRadius,onChange:A})})]}),jsxRuntime.jsx(toggle.Separator,{}),(x==null?void 0:x.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(lucideReact.Palette,{className:"h-3 w-3 text-gray-600"}),jsxRuntime.jsx("span",{className:"text-xs font-medium text-gray-700",children:"Colors"})]}),jsxRuntime.jsx("div",{className:"flex items-center gap-2",children:jsxRuntime.jsxs("div",{className:"flex items-center gap-2",children:[jsxRuntime.jsx(lucideReact.Sun,{className:"h-4 w-4"}),jsxRuntime.jsx(toggle.Switch,{checked:n,onCheckedChange:S=>a(S),"aria-label":"Toggle dark mode",className:"mx-1"}),jsxRuntime.jsx(lucideReact.Moon,{className:"h-4 w-4"})]})})]}),jsxRuntime.jsx("div",{className:"space-y-2",children:x.colors.map(S=>_(S))})]}),jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx("div",{children:"Loading..."}),children:i&&jsxRuntime.jsx(LazyCssImportModal,{open:i,onOpenChange:c,onImport:b})})]}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]}),m&&jsxRuntime.jsx("div",{className:"absolute bottom-4 w-full",children:React__namespace.createElement(m)})]}):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:"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="Styling",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",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",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"},Undo="Undo",Redo="Redo",Duplicate="Duplicate",Close="Close",Selected="Selected",Select="Select",Attributes="Attributes",apply="apply",presets="presets",Orientation="Orientation",Color="Color",Upload="Upload",lngEn={"Add block":"Add Block","Add blocks":"Add blocks","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,"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","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","Fix grammar":"Fix grammar","Make longer":"Make longer","Make shorter":"Make shorter","Add emojis":"Add emojis",Randomize,"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)"},"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,"Copy classes to clipboard":"Copy classes to clipboard","Classes copied to clipboard":"Classes copied to clipboard","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}"};i18n.use(reactI18next.initReactI18next).init({resources:{en:{translation:lngEn}},lng:"en",fallbackLng:"en",interpolation:{escapeValue:!1}});const 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(r=>r!==o)):a([...n,o])}},IfChaiFeatureFlag=({flagKey:o,children:n})=>useChaiFeatureFlag(o)?n:null,registerFeatureFlags=()=>{registerChaiFeatureFlag("enable-ai-chat-left",{description:"Enable AI chat on the left side"})},QUICK_PROMPTS=[{name:"Improve writing",icon:lucideReact.FileEdit,prompt:"Improving writing in all text elements. Replacing placeholder content with meaningful relevant content."},{name:"Replace placeholder content",icon:lucideReact.Recycle,prompt:"Discard current placeholder content and replace with meaningful relevant content."},{name:"Fix grammar",icon:reactIcons.CheckIcon,prompt:"Fix grammar in all text elements. Ensuring the text is grammatically correct and free of errors."},{name:"Make longer",icon:reactIcons.ArrowUpIcon,prompt:"Make all text elements longer."},{name:"Make shorter",icon:reactIcons.ArrowDownIcon,prompt:"Make all text elements shorter."},{name:"Add emojis",icon:lucideReact.SmileIcon,prompt:"Add emojis to text elements if relevant."},{name:"Randomize",icon:lucideReact.ShuffleIcon,prompt:"Randomize all text elements."}];function QuickPrompts({onClick:o}){const{loading:n}=useAskAi(),{t:a}=reactI18next.useTranslation(),{selectedLang:l,fallbackLang:r}=useLanguages(),i=[...QUICK_PROMPTS];return l&&l!==r&&i.splice(0,0,{name:`Translate to ${lodashEs.get(LANGUAGES,l,l)}`,icon:lucideReact.Languages,prompt:`Translate the content to ${lodashEs.get(LANGUAGES,l,l)}. Maintain same tone, style and length.`}),jsxRuntime.jsx("div",{className:n?"pointer-events-none opacity-50":"",children:jsxRuntime.jsx("ul",{className:"space-y-2",children:i.map(({name:c,icon:d,subMenus:m,prompt:u})=>m?jsxRuntime.jsxs(toggle.Popover,{children:[jsxRuntime.jsx(toggle.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(d,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:c})]},c)}),jsxRuntime.jsx(toggle.PopoverContent,{side:"right",children:jsxRuntime.jsx("ul",{children:jsxRuntime.jsx("li",{children:"Happy"})})})]}):jsxRuntime.jsxs("li",{onClick:()=>o(u),className:"flex cursor-pointer items-center space-x-2 rounded p-1 text-sm hover:bg-gray-100 dark:hover:bg-gray-800",children:[jsxRuntime.jsx(d,{className:"h-4 w-4"}),jsxRuntime.jsx("span",{children:a(c)})]},c))})})}const AIUserPrompt=({blockId:o})=>{const{t:n}=reactI18next.useTranslation(),{askAi:a,loading:l,error:r}=useAskAi(),[i,c]=React.useState(""),[d,m]=React.useState(!0),[u,p]=React.useState(),g=React.useRef(null),x=React.useRef(null);React.useEffect(()=>{var h;(h=g.current)==null||h.focus()},[]);const f=h=>{const{usage:j}=h||{};!r&&j&&p(j),x.current=setTimeout(()=>p(void 0),1e4),r||c("")};return jsxRuntime.jsxs("div",{className:"",children:[jsxRuntime.jsxs("div",{onClick:()=>m(!d),className:"flex cursor-pointer items-center justify-between border-t border-border py-2 text-sm font-medium hover:underline",children:[jsxRuntime.jsx("span",{children:n("Ask AI")}),jsxRuntime.jsx("span",{children:jsxRuntime.jsx(lucideReact.ChevronDown,{className:"h-4 w-4 text-gray-500 "+(d?"rotate-180":"")})})]}),d&&o?jsxRuntime.jsxs("div",{className:"mt-2",children:[jsxRuntime.jsx(toggle.Textarea,{ref:g,value:i,onChange:h=>c(h.target.value),placeholder:n("Ask AI to edit content"),className:"w-full",rows:3,onKeyDown:h=>{h.key==="Enter"&&(h.preventDefault(),x.current&&clearTimeout(x.current),p(void 0),a("content",o,i,f))}}),jsxRuntime.jsxs("div",{className:"my-2 flex items-center gap-2",children:[l?null:jsxRuntime.jsx(toggle.Button,{disabled:i.trim().length<5||l,onClick:()=>{x.current&&clearTimeout(x.current),p(void 0),a("content",o,i,f)},variant:"default",className:"w-fit",size:"sm",children:l?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader,{className:"h-5 w-5 animate-spin"}),n("Generating... Please wait...")]}):n("Edit with AI")}),l?jsxRuntime.jsxs("div",{className:"flex flex-col gap-2",children:[jsxRuntime.jsxs(toggle.Skeleton,{className:"flex w-full items-center space-x-1 px-4 py-1 pl-2",children:[jsxRuntime.jsx(lucideReact.Loader,{className:"h-4 w-4 animate-spin text-gray-500"}),jsxRuntime.jsx("p",{className:"text-xs",children:n("Generating... Please wait...")})]}),jsxRuntime.jsx(toggle.Button,{variant:"destructive",onClick:()=>stop(),className:"hidden w-fit",size:"sm",children:n("Stop")})]}):null]}),u?jsxRuntime.jsx("div",{className:"max-w-full",children:jsxRuntime.jsxs("p",{className:"mb-1 flex justify-between break-words rounded border border-blue-500 bg-blue-100 p-1 text-xs text-blue-500",children:[jsxRuntime.jsxs("span",{children:[n("Total tokens used"),": ",u.totalTokens]}),jsxRuntime.jsx(Countdown,{})]})}):null,jsxRuntime.jsx("div",{className:"max-w-full",children:r&&jsxRuntime.jsx("p",{className:"break-words rounded border border-red-500 bg-red-100 p-1 text-xs text-red-500",children:r.message})}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx(QuickPrompts,{onClick:h=>{x.current&&clearTimeout(x.current),p(void 0),a("content",o,h,f)}})]}):d?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(lucideReact.SparklesIcon,{className:"mx-auto text-3xl text-muted-foreground"}),jsxRuntime.jsx("h1",{children:n("Please select a block to Ask AI")})]})}):null]})},AISetContext=()=>{const{t:o}=reactI18next.useTranslation(),n=useBuilderProp("aiContext",""),[a,l]=React.useState(n),r=React.useRef(null),i=useBuilderProp("saveAiContextCallback",lodashEs.noop),[c,d]=React.useState(!1),[m,u]=React.useState(null),[,p]=React.useState(!1),g=React.useRef(null);React.useEffect(()=>{n&&l(n)},[n]);const x=async()=>{try{d(!0),u(null),await i(a),sonner.toast.success(o("Updated AI Context")),g.current.click()}catch(f){u(f)}finally{d(!1)}};return jsxRuntime.jsx(toggle.Accordion,{onValueChange:f=>{p(f!=="")},type:"single",collapsible:!0,children:jsxRuntime.jsxs(toggle.AccordionItem,{value:"set-context",className:"border-none",children:[jsxRuntime.jsx(toggle.AccordionTrigger,{ref:g,className:"border-0 border-border py-2",children:jsxRuntime.jsx("div",{className:"flex w-full items-center justify-between",children:jsxRuntime.jsx("span",{className:"font-medium",children:o("AI Context")})})}),jsxRuntime.jsxs(toggle.AccordionContent,{children:[jsxRuntime.jsx(toggle.Textarea,{ref:r,value:a,onChange:f=>l(f.target.value),placeholder:o("Tell about this page eg this page is about"),className:"mt-1 w-full",rows:10,onKeyDown:f=>{f.key==="Enter"&&(f.preventDefault(),x())}}),n.trim().length===0?jsxRuntime.jsx("p",{className:"mt-2 text-xs text-gray-500",children:o("Eg: This page is about an AI assistant app called Chai Studio. It allows users to create beautiful webpages and edit content with AI.")}):null,jsxRuntime.jsxs("div",{className:"mt-2 flex items-center",children:[jsxRuntime.jsx(toggle.Button,{disabled:a.trim().length<5,onClick:()=>x(),variant:"default",className:"w-fit",size:"sm",children:c?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader,{className:"h-5 w-5 animate-spin"}),o("Saving... Please wait...")]}):o("Save")}),n.trim().length>0?jsxRuntime.jsxs(toggle.AlertDialog,{children:[jsxRuntime.jsx(toggle.AlertDialogTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{disabled:n.trim().length===0,variant:"ghost",className:"w-fit",size:"sm",children:c?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(lucideReact.Loader,{className:"h-5 w-5 animate-spin"}),o("Deleting... Please wait...")]}):o("Delete")})}),jsxRuntime.jsxs(toggle.AlertDialogContent,{children:[jsxRuntime.jsxs(toggle.AlertDialogHeader,{children:[jsxRuntime.jsxs(toggle.AlertDialogTitle,{children:[o("Delete context")," ?"]}),jsxRuntime.jsx(toggle.AlertDialogDescription,{})]}),jsxRuntime.jsxs(toggle.AlertDialogFooter,{children:[jsxRuntime.jsx(toggle.AlertDialogCancel,{children:o("Cancel")}),jsxRuntime.jsx(toggle.AlertDialogAction,{onClick:()=>{l(""),x()},children:o("Yes, Delete")})]})]})]}):null]}),jsxRuntime.jsx("div",{className:"mt-2 max-w-full",children:m&&jsxRuntime.jsx("p",{className:"break-words rounded border border-red-500 bg-red-100 p-1 text-xs text-red-500",children:m.message})})]})]})})},AskAI=()=>{const[o]=useSelectedBlockIds();return jsxRuntime.jsxs("div",{className:"no-scrollbar mt-2 flex-1 overflow-y-auto",children:[jsxRuntime.jsx(AISetContext,{}),jsxRuntime.jsx(AIUserPrompt,{blockId:lodashEs.first(o)})]})};function DarkMode(){const[o,n]=useDarkMode();return jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx(lucideReact.SunIcon,{className:"size-4 shrink-0"}),jsxRuntime.jsx(toggle.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-[40px] 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`})}),jsxRuntime.jsx(lucideReact.Moon,{className:"ml-3 size-4 shrink-0",size:16})]})}const UndoRedo=()=>{const{hasUndo:o,hasRedo:n,undo:a,redo:l}=useUndoManager();return jsxRuntime.jsxs("div",{className:"flex items-center",children:[jsxRuntime.jsx(toggle.Button,{disabled:!o(),size:"sm",onClick:a,className:"rounded-full",variant:"ghost",children:jsxRuntime.jsx(reactIcons.ResetIcon,{})}),jsxRuntime.jsx(toggle.Button,{disabled:!n(),onClick:l,size:"sm",className:"rounded-full",variant:"ghost",children:jsxRuntime.jsx(reactIcons.ResetIcon,{className:"rotate-180 scale-y-[-1] transform"})})]})};function AIChatPanel(){const[o,n]=React.useState([]),[a,l]=React.useState(""),[r,i]=React.useState(!1),[c,d]=React.useState(null),m=React.useRef(null),u=React.useRef(null),p=React.useRef(null);React.useEffect(()=>{var b;(b=u.current)==null||b.scrollIntoView({behavior:"smooth"})},[o]),React.useEffect(()=>{p.current&&(p.current.style.height="auto",p.current.style.height=`${Math.min(p.current.scrollHeight,120)}px`)},[a]);const g=async()=>{if(!a.trim()&&!c)return;const b={id:Date.now().toString(),role:"user",content:a,timestamp:new Date};n(C=>[...C,b]),l(""),i(!0),setTimeout(()=>{const C={id:(Date.now()+1).toString(),role:"assistant",content:"This is a sample response from the AI assistant. In a real implementation, this would be replaced with an actual response from the AI model.",timestamp:new Date};n(A=>[...A,C]),i(!1),d(null)},1500)},x=b=>{b.key==="Enter"&&!b.shiftKey&&(b.preventDefault(),g())},f=b=>{var A;const C=(A=b.target.files)==null?void 0:A[0];if(C){const B=new FileReader;B.onload=_=>{var S;d((S=_.target)==null?void 0:S.result)},B.readAsDataURL(C)}},h=()=>{var b;(b=m.current)==null||b.click()},j=()=>{d(null),m.current&&(m.current.value="")};return jsxRuntime.jsxs("div",{className:"flex h-full w-full flex-col rounded-lg bg-background shadow-sm",children:[jsxRuntime.jsx(toggle.ScrollArea,{className:"flex-1 p-3",children:o.length===0?jsxRuntime.jsxs("div",{className:"mt-10 flex h-full flex-col items-center justify-center p-4 text-center text-muted-foreground",children:[jsxRuntime.jsx(lucideReact.Sparkles,{className:"mb-2 h-8 w-8 text-primary/50"}),jsxRuntime.jsx("p",{className:"text-sm",children:"Ask me anything to get started"})]}):jsxRuntime.jsxs("div",{className:"space-y-4",children:[o.map(b=>jsxRuntime.jsxs("div",{className:toggle.cn("flex max-w-full gap-2",b.role==="assistant"?"items-start":"items-start justify-end"),children:[b.role==="assistant"&&jsxRuntime.jsx(toggle.Avatar,{className:"h-6 w-6 bg-primary/10",children:jsxRuntime.jsx(lucideReact.Sparkles,{className:"h-3 w-3 text-primary"})}),jsxRuntime.jsx("div",{className:toggle.cn("rounded-lg px-3 py-2 text-sm",b.role==="assistant"?"bg-muted text-foreground":"bg-primary text-primary-foreground"),children:b.content}),b.role==="user"&&jsxRuntime.jsx(toggle.Avatar,{className:"h-6 w-6 bg-primary",children:jsxRuntime.jsx("span",{className:"text-xs text-primary-foreground",children:"You"})})]},b.id)),r&&jsxRuntime.jsxs("div",{className:"flex items-start gap-2",children:[jsxRuntime.jsx(toggle.Avatar,{className:"h-6 w-6 bg-primary/10",children:jsxRuntime.jsx(lucideReact.Sparkles,{className:"h-3 w-3 text-primary"})}),jsxRuntime.jsx("div",{className:"rounded-lg bg-muted px-3 py-2",children:jsxRuntime.jsx(lucideReact.Loader2,{className:"h-4 w-4 animate-spin text-muted-foreground"})})]}),jsxRuntime.jsx("div",{ref:u})]})}),c&&jsxRuntime.jsx("div",{className:"px-3 pt-2",children:jsxRuntime.jsxs("div",{className:"relative h-20 w-20 overflow-hidden rounded-md",children:[jsxRuntime.jsx("img",{src:c||"/placeholder.svg",alt:"Attachment",className:"h-full w-full object-cover"}),jsxRuntime.jsx(toggle.Button,{size:"icon",variant:"destructive",className:"absolute right-0 top-0 h-5 w-5 rounded-full p-0",onClick:j,children:jsxRuntime.jsx(lucideReact.X,{className:"h-3 w-3"})})]})}),jsxRuntime.jsx("div",{className:"mt-auto p-3",children:jsxRuntime.jsxs("div",{className:"flex items-end gap-2",children:[jsxRuntime.jsxs("div",{className:"relative flex-1",children:[jsxRuntime.jsx(toggle.Textarea,{ref:p,value:a,onChange:b=>l(b.target.value),onKeyDown:x,placeholder:"Ask something...",className:"max-h-[120px] min-h-[40px] resize-none border-0 bg-muted/50 py-2.5 pr-10 focus-visible:ring-1"}),jsxRuntime.jsx("input",{type:"file",ref:m,onChange:f,accept:"image/*",className:"hidden"}),jsxRuntime.jsx(toggle.Button,{size:"icon",variant:"ghost",className:"absolute bottom-2 right-2 h-6 w-6",onClick:h,children:jsxRuntime.jsx(lucideReact.Image,{className:"h-4 w-4 text-muted-foreground"})})]}),jsxRuntime.jsxs(toggle.Button,{size:"sm",className:"h-10 px-3",onClick:g,disabled:r||!a.trim()&&!c,children:[jsxRuntime.jsx(lucideReact.Send,{className:"mr-1 h-4 w-4"}),"Send"]})]})})]})}const AiAssistant=()=>{const o=useAiAssistant(),[n]=useRightPanel(),a=useBuilderProp("askAiCallBack",null),{t:l}=reactI18next.useTranslation(),{hasPermission:r}=usePermissions();return useChaiFeatureFlag("enable-ai-chat-left")||!a||!r(PERMISSIONS.EDIT_BLOCK)?null:jsxRuntime.jsxs("div",{className:"flex items-center space-x-2",children:[jsxRuntime.jsxs(toggle.Label,{htmlFor:"ai-assistant",className:"flex items-center gap-x-1 text-sm text-yellow-600",children:[jsxRuntime.jsx(lucideReact.SparklesIcon,{className:"w-4"}),l("AI Assistant")]}),jsxRuntime.jsx(toggle.Switch,{className:"scale-90",checked:n==="ai",onCheckedChange:c=>{o(c)},id:"ai-assistant"})]})},ClearCanvas=()=>{const{t:o}=reactI18next.useTranslation(),{setNewBlocks:n}=useBlocksStoreUndoableActions(),[,a]=useSelectedBlockIds(),[,l]=useSelectedStylingBlocks(),r=React.useCallback(()=>{n([]),a([]),l([])},[n]);return jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs(toggle.AlertDialog,{children:[jsxRuntime.jsx(toggle.AlertDialogTrigger,{asChild:!0,children:jsxRuntime.jsxs(toggle.Button,{size:"sm",variant:"ghost",className:"flex items-center gap-x-1",children:[jsxRuntime.jsx(reactIcons.EraserIcon,{})," ",o("Clear")]})}),jsxRuntime.jsxs(toggle.AlertDialogContent,{className:"border-border",children:[jsxRuntime.jsxs(toggle.AlertDialogHeader,{children:[jsxRuntime.jsx(toggle.AlertDialogTitle,{className:"text-foreground",children:o("Clear whole canvas? ")}),jsxRuntime.jsx(toggle.AlertDialogDescription,{children:o("Are you sure you want to clear the page?")})]}),jsxRuntime.jsxs(toggle.AlertDialogFooter,{children:[jsxRuntime.jsx(toggle.AlertDialogCancel,{className:"text-foreground",children:o("Cancel")}),jsxRuntime.jsx(toggle.AlertDialogAction,{onClick:r,children:o("Yes")})]})]})]})})},DataBinding=()=>{const o=usePageExternalData(),[n,a]=jotai.useAtom(dataBindingActiveAtom),{t:l}=reactI18next.useTranslation();return lodashEs.isEmpty(o)?null:jsxRuntime.jsx("div",{className:"flex items-center",children:jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:jsxRuntime.jsx(toggle.Button,{className:"rounded-full",variant:"ghost",onClick:()=>a(!n),children:jsxRuntime.jsx(lucideReact.DatabaseZapIcon,{className:commonFunctions.cn("h-4 w-4",n?"text-green-500":"text-gray-500")})})}),jsxRuntime.jsx(toggle.TooltipContent,{children:jsxRuntime.jsx("p",{children:l("Toggle Data Binding")})})]})})},CanvasTopBar=()=>{const o=useBuilderProp("darkMode",!0),n=flagged.useFeature("aiChat"),[a]=useCanvasZoom();return jsxRuntime.jsxs("div",{className:"flex h-10 items-center justify-between border-b border-border bg-background/70 px-2",children:[jsxRuntime.jsxs("div",{className:"flex h-full space-x-2",children:[jsxRuntime.jsx(Breakpoints$1,{canvas:!0,openDelay:400}),jsxRuntime.jsx(toggle.Separator,{orientation:"vertical"}),o?jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(DarkMode,{}),jsxRuntime.jsx(toggle.Separator,{orientation:"vertical"})]}):null,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(a,0),"%"]})]}),jsxRuntime.jsx(toggle.Separator,{orientation:"vertical"}),jsxRuntime.jsx(UndoRedo,{}),jsxRuntime.jsx(DataBinding,{})]}),jsxRuntime.jsxs("div",{className:"flex h-full items-center space-x-2",children:[jsxRuntime.jsx(ClearCanvas,{}),n?null:jsxRuntime.jsx(AiAssistant,{})]})]})},AddBlocksDialog=()=>{const{t:o}=reactI18next.useTranslation(),[n,a]=React.useState(""),[l,r]=React.useState(-1),[i,c]=React.useState(!1);return usePubSub(CHAI_BUILDER_EVENTS.OPEN_ADD_BLOCK,d=>{a(d?d._id:null),r(isNaN(d==null?void 0:d.position)?-1:d==null?void 0:d.position),c(!0)}),usePubSub(CHAI_BUILDER_EVENTS.CLOSE_ADD_BLOCK,()=>{a(""),r(-1),c(!1)}),jsxRuntime.jsx(toggle.AlertDialog,{open:i,onOpenChange:()=>i?c(!1):"",children:jsxRuntime.jsxs(toggle.AlertDialogContent,{className:"max-w-5xl overflow-hidden border-border",children:[jsxRuntime.jsxs(toggle.AlertDialogHeader,{className:"flex flex-row items-center justify-between",children:[jsxRuntime.jsx(toggle.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:l,showHeading:!1})})]})})},AttrsEditor=React.memo(function o({preloadedAttributes:n=[],onAttributesChange:a}){const[l,r]=React.useState([]),[i,c]=React.useState(""),[d,m]=React.useState(""),[u,p]=React.useState(null),[g,x]=React.useState(""),f=React.useRef(null),h=React.useRef(null),j=usePageExternalData();React.useEffect(()=>{r(n)},[n]);const b=()=>{if(i.startsWith("@")){x("Attribute keys cannot start with '@'");return}if(i){const y=[...l,{key:i,value:d}];a(y),r(l),c(""),m(""),x("")}},C=y=>{const E=l.filter((w,R)=>R!==y);a(E),r(E)},A=y=>{p(y),c(l[y].key),m(l[y].value)},B=()=>{if(i.startsWith("@")){x("Attribute keys cannot start with '@'");return}if(u!==null&&i){const y=[...l];y[u]={key:i,value:d},a(y),r(y),p(null),c(""),m(""),x("")}},_=y=>{y.key==="Enter"&&!y.shiftKey&&(y.preventDefault(),u!==null?B():b())},S=React.useCallback(y=>{const E=k=>/[.,!?;:]/.test(k),w=(k,v,I)=>{let N="",L="";const T=v>0?k[v-1]:"",D=v<k.length?k[v]:"";return v>0&&(T==="."||!E(T)&&T!==" ")&&(N=" "),v<k.length&&!E(D)&&D!==" "&&(L=" "),{text:N+I+L,prefixLength:N.length,suffixLength:L.length}},R=h.current;if(R){const k=R.selectionStart||0,v=R.value||"",I=R.selectionEnd||k;if(I>k){const P=`{{${y}}}`,{text:M}=w(v,k,P),F=v.slice(0,k)+M+v.slice(I);m(F);return}const L=`{{${y}}}`,{text:T}=w(v,k,L),D=v.slice(0,k)+T+v.slice(k);m(D)}},[]);return jsxRuntime.jsxs("div",{className:"flex max-h-full flex-1 flex-col",children:[jsxRuntime.jsxs("form",{onSubmit:y=>{y.preventDefault(),u!==null?B():b()},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(toggle.Label,{htmlFor:"attrKey",className:"text-[11px] font-normal leading-tight text-slate-600",children:"Key"}),jsxRuntime.jsx(toggle.Input,{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",id:"attrKey",ref:f,value:i,onChange:y=>c(y.target.value),placeholder:"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(toggle.Label,{htmlFor:"attrValue",className:"text-[11px] font-normal text-slate-600",children:"Value"}),!lodashEs.isEmpty(j)&&jsxRuntime.jsx(NestedPathSelector,{data:j,onSelect:S})]}),jsxRuntime.jsx(toggle.Textarea,{autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",id:"attrValue",rows:2,ref:h,value:d,onChange:y=>m(y.target.value),onKeyDown:_,placeholder:"Enter Value",className:"text-xs font-normal leading-tight placeholder:text-slate-400"})]})]}),jsxRuntime.jsx("div",{className:"flex justify-end",children:jsxRuntime.jsx(toggle.Button,{type:"submit",disabled:!i.length,variant:"default",size:"sm",className:"h-8 w-24 text-xs",children:u!==null?"Save":"Add"})}),g&&jsxRuntime.jsx("p",{className:"text-xs text-red-500",children:g})]}),jsxRuntime.jsx("div",{className:"space-y-1 py-4",children:l.map((y,E)=>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:y.key}),jsxRuntime.jsx("span",{className:"max-w-[200px] text-wrap font-normal",children:y.value.toString()})]}),jsxRuntime.jsxs("div",{className:"flex-shrink-0 text-slate-400",children:[jsxRuntime.jsx(toggle.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>A(E),children:jsxRuntime.jsx(lucideReact.Edit2,{className:"h-3 w-3"})}),jsxRuntime.jsx(toggle.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>C(E),children:jsxRuntime.jsx(lucideReact.X,{className:"h-3 w-3"})})]})]},E))})]})}),BlockAttributesEditor=React__namespace.memo(()=>{const o=useSelectedBlock(),[n,a]=React.useState([]),[l]=useSelectedStylingBlocks(),r=useUpdateBlocksProps(),i=`${lodashEs.get(l,"0.prop")}_attrs`;React__namespace.useEffect(()=>{const d=lodashEs.map(lodashEs.get(o,i),(m,u)=>({key:u,value:m}));lodashEs.isEmpty(d)?a([]):a(d)},[lodashEs.get(o,i)]);const c=React__namespace.useCallback((d=[])=>{const m={};lodashEs.forEach(d,u=>{lodashEs.isEmpty(u.key)||lodashEs.set(m,u.key,u.value)}),r([lodashEs.get(o,"_id")],{[i]:m})},[o,r,i]);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(),l=useRemoveAllClassesForBlock(),{t:r}=reactI18next.useTranslation();return!n||lodashEs.isEmpty(a)?null:jsxRuntime.jsxs(toggle.DropdownMenu,{children:[jsxRuntime.jsx(toggle.DropdownMenuTrigger,{asChild:!0,children:jsxRuntime.jsx("div",{className:"inline-flex rounded-sm p-0.5 hover:bg-gray-300",onClick:i=>i.stopPropagation(),children:jsxRuntime.jsx(lucideReact.MoreVertical,{className:"h-3 w-3"})})}),jsxRuntime.jsxs(toggle.DropdownMenuContent,{side:"bottom",className:"border-border text-xs",children:[jsxRuntime.jsxs(toggle.DropdownMenuItem,{className:"flex items-center gap-1 text-xs",onClick:()=>{o()},children:[jsxRuntime.jsx(reactIcons.ResetIcon,{className:"h-3 w-3"}),r("Reset styles")]}),jsxRuntime.jsxs(toggle.DropdownMenuItem,{className:"text-xs",onClick:()=>{n&&l(n,!0)},children:[jsxRuntime.jsx(reactIcons.Cross2Icon,{className:"h-3 w-3"}),r("Clear styles")]})]})]})};function BlockAttributesToggle(){const{t:o}=reactI18next.useTranslation(),[n,a]=React.useState(!0),[l]=useSelectedStylingBlocks();return lodashEs.isEmpty(l)?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(lucideReact.ChevronDown,{className:"h-4 w-4 text-gray-500 "+(n?"rotate-180":"")})})]}),n&&jsxRuntime.jsx(BlockAttributesEditor,{})]})}const SettingsPanel=()=>{const o=useSelectedBlock(),{t:n}=reactI18next.useTranslation(),a=useBuilderProp("onError",lodashEs.noop),{hasPermission:l}=usePermissions();let r=!l(PERMISSIONS.EDIT_BLOCK);const i=!l(PERMISSIONS.EDIT_STYLES);return 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")})]})}):r&&i?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")})]})}):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",children:[jsxRuntime.jsx(BlockSettings,{}),jsxRuntime.jsx("br",{}),jsxRuntime.jsx("br",{})]})}):r?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(toggle.Tabs,{defaultValue:"settings",className:"flex flex-1 flex-col",children:[jsxRuntime.jsx("div",{className:"flex items-center justify-between",children:jsxRuntime.jsxs(toggle.TabsList,{className:"grid h-auto w-full grid-cols-2 p-1 py-1",children:[jsxRuntime.jsx(toggle.TabsTrigger,{value:"settings",className:"text-xs",children:"Settings"}),jsxRuntime.jsx(toggle.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:"Styles"}),jsxRuntime.jsx("span",{className:"w-[10%]",children:jsxRuntime.jsx(ResetStylesButton,{})})]})})]})}),jsxRuntime.jsxs(toggle.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(toggle.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]),DefaultTopBar=()=>jsxRuntime.jsx("div",{}),TOP_BAR={component:DefaultTopBar},registerChaiTopBar=o=>{TOP_BAR.component=o},useTopBarComponent=()=>React.useMemo(()=>TOP_BAR.component,[]),DEFAULT_PANEL_WIDTH=280,OutlineButton=({isActive:o,show:n})=>jsxRuntime.jsx(toggle.Button,{variant:o?"default":"ghost",size:"icon",onClick:n,children:jsxRuntime.jsx(lucideReact.Layers,{size:20})}),AiButton=({isActive:o,show:n})=>jsxRuntime.jsx(toggle.Button,{variant:o?"default":"ghost",size:"icon",onClick:n,children:jsxRuntime.jsx(reactIcons.LightningBoltIcon,{className:"rtl:ml-2"})}),AskAiButton=({isActive:o,show:n})=>jsxRuntime.jsx(toggle.Button,{variant:o?"default":"ghost",size:"icon",onClick:n,children:jsxRuntime.jsx(lucideReact.SparklesIcon,{className:"rtl:ml-2"})});function useSidebarDefaultPanels(){const o=useBuilderProp("askAiCallBack",null),n=flagged.useFeature("aiChat"),a=useChaiFeatureFlag("enable-ai-chat-left");return React.useMemo(()=>{const l=[];return l.push({id:"outline",label:"Outline",isInternal:!0,width:DEFAULT_PANEL_WIDTH,button:OutlineButton,panel:()=>jsxRuntime.jsx("div",{className:"-mt-8",children:jsxRuntime.jsx(ListTree,{})})}),a&&l.unshift({id:"ask-ai",button:AskAiButton,label:"Ask AI",isInternal:!0,width:DEFAULT_PANEL_WIDTH,panel:()=>jsxRuntime.jsx("div",{className:"",children:jsxRuntime.jsx(AskAI,{})})}),o&&n&&l.unshift({id:"ai",button:AiButton,label:"AI Assistant",isInternal:!0,width:450,panel:()=>jsxRuntime.jsx("div",{className:"-mt-8 h-full max-h-full",children:jsxRuntime.jsx(AIChatPanel,{})})}),lodashEs.compact(l)},[o,n,a])}const RootLayout=()=>{const o=useTopBarComponent(),[n,a]=useSidebarActivePanel(),l=React.useRef("outline"),[r,i]=React.useState(DEFAULT_PANEL_WIDTH),[c,d]=useRightPanel();usePubSub(CHAI_BUILDER_EVENTS.SHOW_BLOCK_SETTINGS,()=>{a("outline")});const m=useSidebarDefaultPanels(),u=useChaiSidebarPanels("top"),p=useChaiSidebarPanels("bottom"),g=React.useCallback(y=>{y.preventDefault()},[]),x=React.useCallback(y=>{a(n===y?null:y)},[n]),{t:f}=reactI18next.useTranslation(),h=React.useMemo(()=>[...m,...u,...p],[m,u,p]),j=useBuilderProp("htmlDir","ltr"),b=lodashEs.find(h,{id:n})??lodashEs.first(h),C=lodashEs.get(b,"width",DEFAULT_PANEL_WIDTH);React.useEffect(()=>{if(n!==null){const y=lodashEs.find(h,{id:n});y&&lodashEs.get(y,"view","standard")==="standard"&&(l.current=n,i(lodashEs.get(y,"width",DEFAULT_PANEL_WIDTH)))}},[n,h]);const A=React.useMemo(()=>{if(n===null)return 0;const y=lodashEs.find(h,{id:n});return lodashEs.get(y,"view","standard")==="standard"?C:r},[n,C,r,h]),B=React.useCallback(()=>{a(l.current)},[a]),_=React.useCallback(()=>{a("outline")},[a]);React.useEffect(()=>{lodashEs.find(h,{id:n})||a("outline")},[n,h]);const S=React.useCallback(y=>{x(y)},[x]);return jsxRuntime.jsx("div",{dir:j,className:"h-screen max-h-full w-screen overflow-x-hidden bg-background text-foreground",children:jsxRuntime.jsxs(toggle.TooltipProvider,{children:[jsxRuntime.jsxs("div",{onContextMenu:g,className:"flex h-screen 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:[m,u].flat().map((y,E)=>jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:React.createElement(lodashEs.get(y,"button",NoopComponent),{position:"top",panelId:y.id,isActive:n===y.id,show:()=>S(y.id)})}),jsxRuntime.jsx(toggle.TooltipContent,{side:"right",children:jsxRuntime.jsx("p",{children:f(y.label)})})]},"button-top-"+E))}),jsxRuntime.jsx("div",{className:"flex flex-col space-y-1"}),jsxRuntime.jsx("div",{className:"flex flex-col",children:p==null?void 0:p.map((y,E)=>jsxRuntime.jsxs(toggle.Tooltip,{children:[jsxRuntime.jsx(toggle.TooltipTrigger,{asChild:!0,children:React.createElement(lodashEs.get(y,"button",NoopComponent),{position:"bottom",panelId:y.id,isActive:n===y.id,show:()=>S(y.id)})}),jsxRuntime.jsx(toggle.TooltipContent,{side:"right",children:jsxRuntime.jsx("p",{children:f(y.label)})})]},"button-bottom-"+E))})]}),jsxRuntime.jsx(framerMotion.motion.div,{id:"left-panel",className:"h-full max-h-full border-r border-border",initial:{width:A},animate:{width:A},transition:{duration:.3,ease:"easeInOut"},children:n!==null&&lodashEs.get(b,"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(b,"isInternal",!1)?"":"w-64"}`,children:jsxRuntime.jsx("span",{children:f(lodashEs.get(b,"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(b,"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==="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(lucideReact.Palette,{className:"w-4 h-4 text-gray-600"}),f("Theme Settings")]}),jsxRuntime.jsx(toggle.Button,{onClick:()=>d("block"),variant:"ghost",size:"icon",className:"text-xs",children:jsxRuntime.jsx(lucideReact.X,{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==="theme"?jsxRuntime.jsx(ThemeConfigPanel,{}):jsxRuntime.jsx(SettingsPanel,{})})})]})})})]})]}),jsxRuntime.jsx(AddBlocksDialog,{}),n!==null&&lodashEs.get(b,"view")==="drawer"&&jsxRuntime.jsx(toggle.Sheet,{open:!0,onOpenChange:()=>B(),children:jsxRuntime.jsxs(toggle.SheetContent,{side:"left",className:"flex flex-col gap-0 p-0 sm:max-w-full",style:{width:`${C}px`},children:[jsxRuntime.jsx(toggle.SheetHeader,{className:"border-b border-border px-2 py-2.5",children:jsxRuntime.jsxs(toggle.SheetTitle,{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"inline-block",children:lodashEs.get(b,"icon",null)}),jsxRuntime.jsx("span",{children:f(lodashEs.get(b,"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(b,"panel",NoopComponent),{close:_})})})]})})," ",n!==null&&lodashEs.get(b,"view")==="modal"&&jsxRuntime.jsx(toggle.Dialog,{open:!0,onOpenChange:()=>B(),children:jsxRuntime.jsxs(toggle.DialogContent,{className:"gap-0 p-0",style:{maxWidth:`${C}px`},children:[jsxRuntime.jsx(toggle.DialogHeader,{className:"border-b border-border px-2 py-3.5",children:jsxRuntime.jsxs(toggle.DialogTitle,{className:"flex items-center gap-2",children:[jsxRuntime.jsx("span",{className:"inline-block",children:lodashEs.get(b,"icon",null)}),jsxRuntime.jsx("span",{children:f(lodashEs.get(b,"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(b,"panel",NoopComponent),{close:_})})})]})}),n!==null&&lodashEs.get(b,"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(b,"icon",null)}),jsxRuntime.jsx("span",{children:f(lodashEs.get(b,"label",""))})]}),jsxRuntime.jsx(toggle.Button,{onClick:()=>B(),variant:"ghost",size:"icon",className:"",children:jsxRuntime.jsx(lucideReact.X,{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(b,"panel",NoopComponent),{close:_})})})]})})})]})})},PreviewScreen=()=>{const[o,n]=usePreviewMode(),{t:a}=reactI18next.useTranslation(),l=useBuilderProp("previewComponent",null);return o?jsxRuntime.jsxs("div",{className:commonFunctions.cn("fixed inset-0 z-[999] bg-background",o?"block":"hidden"),children:[jsxRuntime.jsxs(toggle.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:l?jsxRuntime.jsx(React.Suspense,{fallback:jsxRuntime.jsx(toggle.Skeleton,{className:"h-96 w-full"}),children:React.createElement(l)}):null})]}):null},FeatureToggle=({featureKey:o,options:n})=>{const a=useToggleChaiFeatureFlag(o),l=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(toggle.Switch,{checked:l,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 l=useChaiFeatureFlags(),[r,i]=React.useState(""),[c,d]=React.useState(!1),[m,u]=React.useState({x:0,y:0}),p=React.useMemo(()=>{if(!r.trim())return l;const h=r.toLowerCase();return Object.fromEntries(Object.entries(l).filter(([j,b])=>{var C;return(j==null?void 0:j.toLowerCase().includes(h))||((C=b==null?void 0:b.description)==null?void 0:C.toLowerCase().includes(h))}))},[l,r]),g=h=>{d(!0),u({x:h.clientX-n.x,y:h.clientY-n.y})},x=h=>{if(!c)return;const j=h.clientX-m.x,b=h.clientY-m.y,C=h.currentTarget,A=C.offsetWidth,B=C.offsetHeight,_=window.innerWidth-A,S=window.innerHeight-B,y=Math.max(0,Math.min(j,_)),E=Math.max(0,Math.min(b,S));a(y,E)},f=()=>{d(!1)};return React.useEffect(()=>{const h=()=>{c&&d(!1)};return window.addEventListener("mouseup",h),()=>window.removeEventListener("mouseup",h)},[c]),!n||n.x<0||n.y<0?null:jsxRuntime.jsxs("div",{onMouseDown:g,onMouseMove:x,onMouseUp:f,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(toggle.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(lucideReact.X,{className:"h-4 w-4"})})]}),jsxRuntime.jsxs("div",{className:"relative",children:[jsxRuntime.jsx(lucideReact.Search,{className:"absolute left-2.5 top-2.5 h-4 w-4 text-gray-400"}),jsxRuntime.jsx(toggle.Input,{type:"search",placeholder:"Search features...",className:"w-full pl-8",value:r,onChange:h=>i(h.target.value),autoFocus:!0})]})]}),jsxRuntime.jsx("div",{className:"max-h-96 overflow-y-auto py-2",children:Object.keys(p).length>0?jsxRuntime.jsx("div",{className:"space-y-1",children:Object.entries(p).map(([h,j])=>jsxRuntime.jsx(FeatureToggle,{featureKey:h,options:j},h))}):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 "',r,'"']})})})]})},ChaiFeatureFlagsWidget=()=>{const[o,n]=jotai.useAtom(showFeatureFlagAtom);return reactHotkeysHook.useHotkeys("ctrl+shift+1,command+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,l)=>n(r=>({...r,x:a,y:l}))}):null},setDebugLogs=o=>{},getParentNodeIds=(o,n)=>{const a=[];let l=lodashEs.find(o,{_id:n}),r=lodashEs.get(l,"_parent","");for(;lodashEs.isString(r)&&!lodashEs.isEmpty(r);)a.push(l==null?void 0:l._parent),l=lodashEs.find(o,{_id:r}),r=l==null?void 0:l._parent;return lodashEs.flatten(a)},expandedIdsAtom=jotai.atom([]),useExpandTree=()=>{const[o]=useSelectedBlockIds(),n=jotai.useAtomValue(presentBlocksAtom),[,a]=jotai.useAtom(expandedIdsAtom);React.useEffect(()=>{let l=[];const r=lodashEs.first(o);lodashEs.isString(r)&&(l=[r,...getParentNodeIds(n,r)]),a(l)},[o,n,a])},ScreenTooSmall=()=>jsxRuntime.jsx("section",{className:"fixed inset-0 z-50 flex h-screen w-screen items-center justify-center bg-white 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 xl:hidden",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"]})})]})})}),isSelfAtom=(o,n)=>o.unstable_is?o.unstable_is(n):n===o,hasInitialValue=o=>"init"in o,isActuallyWritableAtom=o=>!!o.write,isAtomStateInitialized=o=>"v"in o||"e"in o,returnAtomValue=o=>{if("e"in o)throw o.e;return o.v},promiseStateMap=new WeakMap,isPendingPromise=o=>{var n;return isPromiseLike$1(o)&&!!((n=promiseStateMap.get(o))!=null&&n[0])},abortPromise=o=>{const n=promiseStateMap.get(o);n!=null&&n[0]&&(n[0]=!1,n[1].forEach(a=>a()))},registerAbortHandler=(o,n)=>{let a=promiseStateMap.get(o);if(!a){a=[!0,new Set],promiseStateMap.set(o,a);const l=()=>{a[0]=!1};o.then(l,l)}a[1].add(n)},isPromiseLike$1=o=>typeof(o==null?void 0:o.then)=="function",addPendingPromiseToDependency=(o,n,a)=>{a.p.has(o)||(a.p.add(o),n.then(()=>{a.p.delete(o)},()=>{a.p.delete(o)}))},setAtomStateValueOrPromise=(o,n,a)=>{const l=a(o),r="v"in l,i=l.v;if(isPromiseLike$1(n))for(const c of l.d.keys())addPendingPromiseToDependency(o,n,a(c));l.v=n,delete l.e,(!r||!Object.is(i,l.v))&&(++l.n,isPromiseLike$1(i)&&abortPromise(i))},getMountedOrPendingDependents=(o,n,a)=>{var l;const r=new Set;for(const i of((l=a.get(o))==null?void 0:l.t)||[])a.has(i)&&r.add(i);for(const i of n.p)r.add(i);return r},BUILDING_BLOCKS=Symbol(),buildStore=(o=new WeakMap,n=new WeakMap,a=new WeakMap,l=new Set,r=new Set,i=new Set,c={},d=(x,...f)=>x.read(...f),m=(x,...f)=>x.write(...f),u=(x,f)=>{var h;return(h=x.unstable_onInit)==null?void 0:h.call(x,f)},p=(x,f)=>{var h;return(h=x.onMount)==null?void 0:h.call(x,f)},...g)=>{const x=g[0]||(E=>{let w=o.get(E);return w||(w={d:new Map,p:new Set,n:0},o.set(E,w),u==null||u(E,y)),w}),f=g[1]||(()=>{const E=[],w=R=>{try{R()}catch(k){E.push(k)}};do{c.f&&w(c.f);const R=new Set,k=R.add.bind(R);l.forEach(v=>{var I;return(I=n.get(v))==null?void 0:I.l.forEach(k)}),l.clear(),i.forEach(k),i.clear(),r.forEach(k),r.clear(),R.forEach(w),l.size&&h()}while(l.size||i.size||r.size);if(E.length)throw new AggregateError(E)}),h=g[2]||(()=>{const E=[],w=new WeakSet,R=new WeakSet,k=Array.from(l);for(;k.length;){const v=k[k.length-1],I=x(v);if(R.has(v)){k.pop();continue}if(w.has(v)){a.get(v)===I.n&&E.push([v,I]),R.add(v),k.pop();continue}w.add(v);for(const N of getMountedOrPendingDependents(v,I,n))w.has(N)||k.push(N)}for(let v=E.length-1;v>=0;--v){const[I,N]=E[v];let L=!1;for(const T of N.d.keys())if(T!==I&&l.has(T)){L=!0;break}L&&(j(I),A(I)),a.delete(I)}}),j=g[3]||(E=>{var w;const R=x(E);if(isAtomStateInitialized(R)&&(n.has(E)&&a.get(E)!==R.n||Array.from(R.d).every(([P,M])=>j(P).n===M)))return R;R.d.clear();let k=!0;const v=()=>{n.has(E)&&(A(E),h(),f())},I=P=>{var M;if(isSelfAtom(E,P)){const O=x(P);if(!isAtomStateInitialized(O))if(hasInitialValue(P))setAtomStateValueOrPromise(P,P.init,x);else throw new Error("no atom init");return returnAtomValue(O)}const F=j(P);try{return returnAtomValue(F)}finally{R.d.set(P,F.n),isPendingPromise(R.v)&&addPendingPromiseToDependency(E,R.v,F),(M=n.get(P))==null||M.t.add(E),k||v()}};let N,L;const T={get signal(){return N||(N=new AbortController),N.signal},get setSelf(){return!L&&isActuallyWritableAtom(E)&&(L=(...P)=>{if(!k)try{return C(E,...P)}finally{h(),f()}}),L}},D=R.n;try{const P=d(E,I,T);return setAtomStateValueOrPromise(E,P,x),isPromiseLike$1(P)&&(registerAbortHandler(P,()=>N==null?void 0:N.abort()),P.then(v,v)),R}catch(P){return delete R.v,R.e=P,++R.n,R}finally{k=!1,D!==R.n&&a.get(E)===D&&(a.set(E,R.n),l.add(E),(w=c.c)==null||w.call(c,E))}}),b=g[4]||(E=>{const w=[E];for(;w.length;){const R=w.pop(),k=x(R);for(const v of getMountedOrPendingDependents(R,k,n)){const I=x(v);a.set(v,I.n),w.push(v)}}}),C=g[5]||((E,...w)=>{let R=!0;const k=I=>returnAtomValue(j(I)),v=(I,...N)=>{var L;const T=x(I);try{if(isSelfAtom(E,I)){if(!hasInitialValue(I))throw new Error("atom not writable");const D=T.n,P=N[0];setAtomStateValueOrPromise(I,P,x),A(I),D!==T.n&&(l.add(I),(L=c.c)==null||L.call(c,I),b(I));return}else return C(I,...N)}finally{R||(h(),f())}};try{return m(E,k,v,...w)}finally{R=!1}}),A=g[6]||(E=>{var w;const R=x(E),k=n.get(E);if(k&&!isPendingPromise(R.v)){for(const[v,I]of R.d)if(!k.d.has(v)){const N=x(v);B(v).t.add(E),k.d.add(v),I!==N.n&&(l.add(v),(w=c.c)==null||w.call(c,v),b(v))}for(const v of k.d||[])if(!R.d.has(v)){k.d.delete(v);const I=_(v);I==null||I.t.delete(E)}}}),B=g[7]||(E=>{var w;const R=x(E);let k=n.get(E);if(!k){j(E);for(const v of R.d.keys())B(v).t.add(E);if(k={l:new Set,d:new Set(R.d.keys()),t:new Set},n.set(E,k),(w=c.m)==null||w.call(c,E),isActuallyWritableAtom(E)){const v=()=>{let I=!0;const N=(...L)=>{try{return C(E,...L)}finally{I||(h(),f())}};try{const L=p(E,N);L&&(k.u=()=>{I=!0;try{L()}finally{I=!1}})}finally{I=!1}};r.add(v)}}return k}),_=g[8]||(E=>{var w;const R=x(E);let k=n.get(E);if(k&&!k.l.size&&!Array.from(k.t).some(v=>{var I;return(I=n.get(v))==null?void 0:I.d.has(E)})){k.u&&i.add(k.u),k=void 0,n.delete(E),(w=c.u)==null||w.call(c,E);for(const v of R.d.keys()){const I=_(v);I==null||I.t.delete(E)}return}return k}),S=[o,n,a,l,r,i,c,d,m,u,p,x,f,h,j,b,C,A,B,_],y={get:E=>returnAtomValue(j(E)),set:(E,...w)=>{try{return C(E,...w)}finally{h(),f()}},sub:(E,w)=>{const k=B(E).l;return k.add(w),f(),()=>{k.delete(w),_(E),f()}}};return Object.defineProperty(y,BUILDING_BLOCKS,{value:S}),y},INTERNAL_buildStoreRev1=buildStore,INTERNAL_registerAbortHandler=registerAbortHandler;function createStore(){return INTERNAL_buildStoreRev1()}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((l,r)=>{let i=o;const c=u=>p=>{i===u&&l(p)},d=u=>p=>{i===u&&r(p)},m=()=>{try{const u=n();isPromiseLike(u)?(continuablePromiseMap.set(u,a),i=u,u.then(c(u),d(u)),INTERNAL_registerAbortHandler(u,m)):l(u)}catch(u){r(u)}};o.then(c(o),d(o)),INTERNAL_registerAbortHandler(o,m)}),continuablePromiseMap.set(o,a)),a};function useAtomValue(o,n){const{delay:a,unstable_promiseStatus:l=!React.use}={},r=useStore(),[[i,c,d],m]=React.useReducer(p=>{const g=r.get(o);return Object.is(p[0],g)&&p[1]===r&&p[2]===o?p:[g,r,o]},void 0,()=>[r.get(o),r,o]);let u=i;if((c!==r||d!==o)&&(m(),u=r.get(o)),React.useEffect(()=>{const p=r.sub(o,()=>{if(l)try{const g=r.get(o);isPromiseLike(g)&&attachPromiseStatus(createContinuablePromise(g,()=>r.get(o)))}catch{}if(typeof a=="number"){setTimeout(m,a);return}m()});return m(),p},[r,o,a,l]),React.useDebugValue(u),isPromiseLike(u)){const p=createContinuablePromise(u,()=>r.get(o));return l&&attachPromiseStatus(p),use(p)}return u}function useSetAtom(o,n){const a=useStore();return React.useCallback((...r)=>a.set(o,...r),[a,o])}function useAtom(o,n){return[useAtomValue(o),useSetAtom(o)]}const useAutoSave=()=>{const{savePage:o}=useSavePage(),n=useBuilderProp("autoSaveSupport",!0),a=useBuilderProp("autoSaveInterval",60);web.useIntervalEffect(()=>{n&&o(!0)},a*1e3)},ChaiWatchers=o=>{const[,n]=useBlocksStore(),a=useBuilderReset(),[l]=useAtom(builderSaveStateAtom);useAtom(selectedLibraryAtom),useKeyEventWatcher(),useExpandTree(),useAutoSave(),useWatchPartailBlocks(),useUnmountBroadcastChannel();const{postMessage:r}=useBroadcastChannel(),[,i]=useAtom(isPageLoadedAtom);return React.useEffect(()=>{builderStore.set(chaiBuilderPropsAtom,lodashEs.omit(o,["blocks","translations","pageExternalData"]))},[o]),React.useEffect(()=>{builderStore.set(chaiPageExternalDataAtom,o.pageExternalData||{})},[o.pageExternalData]),React.useEffect(()=>{i(!1),setTimeout(()=>{const c=runtime.syncBlocksWithDefaults(o.blocks||[]);n(c),c&&c.length>0&&r({type:"blocks-updated",blocks:c}),a(),i(!0)},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,(c,d)=>{i18n.addResourceBundle(d,"translation",c,!0,!0)})},[o.translations]),React.useEffect(()=>(l!=="SAVED"?window.onbeforeunload=()=>"":window.onbeforeunload=null,()=>{window.onbeforeunload=null}),[l]),null},ChaiBuilderComponent=o=>{const n=React.useMemo(()=>o.layout||RootLayout,[o.layout]),a=useBuilderProp("builderTheme",plugin.defaultThemeValues);return jsxRuntime.jsxs(jsxRuntime.Fragment,{children:[jsxRuntime.jsx(CssThemeVariables,{theme:a}),jsxRuntime.jsx(n,{})]})},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.");registerFeatureFlags();exports.generateBlockId=commonFunctions.generateUUID;exports.mergeClasses=commonFunctions.cn;Object.defineProperty(exports,"useTranslation",{enumerable:!0,get:()=>reactI18next.useTranslation});exports.i18n=i18n;exports.ChaiAddBlocksDialog=AddBlocksDialog;exports.ChaiAddBlocksPanel=AddBlocksPanel;exports.ChaiAskAiPanel=AISetContext;exports.ChaiAskAiUserPrompt=AIUserPrompt;exports.ChaiBlockAttributesEditor=BlockAttributesEditor;exports.ChaiBlockPropsEditor=BlockSettings;exports.ChaiBlockStyleEditor=BlockStyling;exports.ChaiBuilderCanvas=CanvasArea;exports.ChaiBuilderEditor=ChaiBuilderEditor;exports.ChaiDarkModeSwitcher=DarkMode;exports.ChaiDefaultBlocks=DefaultChaiBlocks;exports.ChaiImportHTML=ImportHTML;exports.ChaiOutline=ListTree;exports.ChaiScreenSizes=Breakpoints$1;exports.ChaiThemeConfigPanel=ThemeConfigPanel;exports.ChaiUILibrariesPanel=UILibrariesPanel;exports.ChaiUndoRedo=UndoRedo;exports.IfChaiFeatureFlag=IfChaiFeatureFlag;exports.PERMISSIONS=PERMISSIONS;exports.convertHTMLToChaiBlocks=getBlocksFromHTML;exports.getBlocksFromHTML=getBlocksFromHTML;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.registerChaiSaveToLibrary=registerChaiSaveToLibrary;exports.registerChaiSidebarPanel=registerChaiSidebarPanel;exports.registerChaiTopBar=registerChaiTopBar;exports.useAddBlock=useAddBlock;exports.useAddClassesToBlocks=useAddClassesToBlocks;exports.useAskAi=useAskAi;exports.useBlockHighlight=useBlockHighlight;exports.useBlocksStore=useBlocksStore;exports.useBlocksStoreUndoableActions=useBlocksStoreUndoableActions;exports.useBrandingOptions=useBrandingOptions;exports.useBuilderProp=useBuilderProp;exports.useBuilderReset=useBuilderReset;exports.useCanvasDisplayWidth=useCanvasDisplayWidth;exports.useCanvasZoom=useCanvasZoom;exports.useChaiFeatureFlag=useChaiFeatureFlag;exports.useChaiFeatureFlags=useChaiFeatureFlags;exports.useCodeEditor=useCodeEditor;exports.useCopyBlockIds=useCopyBlocks;exports.useCopyToClipboard=useCopyToClipboard;exports.useCurrentPage=useCurrentPage;exports.useCutBlockIds=useCutBlockIds;exports.useDarkMode=useDarkMode;exports.useDuplicateBlocks=useDuplicateBlocks;exports.useHiddenBlockIds=useHiddenBlockIds;exports.useHighlightBlockId=useHighlightBlockId;exports.useInlineEditing=useInlineEditing;exports.useIsPageLoaded=useIsPageLoaded;exports.useLanguages=useLanguages;exports.useLibraryBlocks=useLibraryBlocks;exports.useMediaManagerComponent=useMediaManagerComponent;exports.usePartailBlocksStore=usePartialBlocksStore;exports.usePartialBlocksList=usePartialBlocksList;exports.usePasteBlocks=usePasteBlocks;exports.usePermissions=usePermissions;exports.usePreviewMode=usePreviewMode;exports.useRemoveAllClassesForBlock=useRemoveAllClassesForBlock;exports.useRemoveBlocks=useRemoveBlocks;exports.useRemoveClassesFromBlocks=useRemoveClassesFromBlocks;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.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;