@chaibuilder/sdk 1.0.4 → 1.0.5
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/{AddBlocks-6523b7b7.js → AddBlocks-94cf46d7.js} +1 -1
- package/dist/{AddBlocks-a3edbae6.cjs → AddBlocks-bebc8e38.cjs} +1 -1
- package/dist/{BrandingOptions-86fbef54.cjs → BrandingOptions-703e2c8b.cjs} +1 -1
- package/dist/{BrandingOptions-39e8c4e1.js → BrandingOptions-c22ad026.js} +1 -1
- package/dist/{CanvasArea-e0331b42.js → CanvasArea-90b0f63d.js} +2 -2
- package/dist/{CanvasArea-67938f1e.cjs → CanvasArea-cd4da772.cjs} +2 -2
- package/dist/{CurrentPage-fa958150.cjs → CurrentPage-7a6d4643.cjs} +1 -1
- package/dist/{CurrentPage-762b1ead.js → CurrentPage-aa4de22f.js} +1 -1
- package/dist/{Layers-37a6caaa.cjs → Layers-94260926.cjs} +1 -1
- package/dist/{Layers-b3e2a0e5.js → Layers-cff22f39.js} +2 -2
- package/dist/{MarkAsGlobalBlock-cf9e148b.cjs → MarkAsGlobalBlock-4f1e20b0.cjs} +1 -1
- package/dist/{MarkAsGlobalBlock-90d59ed2.js → MarkAsGlobalBlock-d9bcd24a.js} +1 -1
- package/dist/{PagesPanel-2aa9a842.cjs → PagesPanel-53b0eff4.cjs} +1 -1
- package/dist/{PagesPanel-275d771f.js → PagesPanel-bb740126.js} +2 -2
- package/dist/{ProjectPanel-434f563e.js → ProjectPanel-7dab69b4.js} +2 -2
- package/dist/{ProjectPanel-2bfe31f7.cjs → ProjectPanel-c0f6a656.cjs} +1 -1
- package/dist/{Settings-bcf29a2e.js → Settings-00337fa2.js} +1 -1
- package/dist/{Settings-447d24b0.cjs → Settings-f4f20456.cjs} +1 -1
- package/dist/{SidePanels-810faeb5.cjs → SidePanels-b3e85d16.cjs} +1 -1
- package/dist/{SidePanels-251520d4.js → SidePanels-ef5cf825.js} +2 -2
- package/dist/{Topbar-7abf6d32.js → Topbar-3c249ffe.js} +1 -1
- package/dist/{Topbar-bcd336bc.cjs → Topbar-58a2d4b3.cjs} +1 -1
- package/dist/{add-page-modal-357bdb9c.js → add-page-modal-7ccb5b8e.js} +1 -1
- package/dist/{add-page-modal-cc7664e9.cjs → add-page-modal-7f75bbb5.cjs} +1 -1
- package/dist/core.cjs +1 -1
- package/dist/core.js +1 -1
- package/dist/{delete-page-modal-2303a1ac.js → delete-page-modal-4af2dc82.js} +1 -1
- package/dist/{delete-page-modal-6eebd86d.cjs → delete-page-modal-a88a20fd.cjs} +1 -1
- package/dist/{index-5cde5d49.js → index-11d42656.js} +6 -5
- package/dist/{index-f34c9f39.cjs → index-b7e3f3cb.cjs} +2 -2
- package/dist/{page-viewer-da81d5fa.cjs → page-viewer-2936d827.cjs} +1 -1
- package/dist/{page-viewer-49860cf4.js → page-viewer-f4770b77.js} +2 -2
- package/dist/{project-general-setting-243ab375.js → project-general-setting-61e24f3d.js} +1 -1
- package/dist/{project-general-setting-2ae3e26b.cjs → project-general-setting-6f0e0138.cjs} +1 -1
- package/dist/{single-page-detail-335e2d59.js → single-page-detail-515b1f19.js} +2 -2
- package/dist/{single-page-detail-8843206c.cjs → single-page-detail-abca8ffb.cjs} +1 -1
- package/package.json +1 -1
|
@@ -160,5 +160,5 @@ object-assign/index.js:
|
|
|
160
160
|
(c) Sindre Sorhus
|
|
161
161
|
@license MIT
|
|
162
162
|
*)
|
|
163
|
-
*/q();var cB=process.env.NODE_ENV!=="production"?lB:()=>null;const uB={};class sS extends g.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?ee.jsxRuntimeExports.jsxs("div",{className:"bg-red-200 h-full w-full rounded-md text-red-500 p-4",id:"errorBoundary",children:[ee.jsxRuntimeExports.jsx("p",{className:"font-semibold",children:"Oops! Something went wrong."}),ee.jsxRuntimeExports.jsx("p",{children:"Please try again later."})]}):this.props.children}}const fB=e=>{const t=e.replace(ze.STYLES_KEY,"").split(",");return{baseClasses:t[0],classes:t[1]}},dB=new og({children:"blockNodes"}),iS=(e,t=null)=>B.flatten(e.map(r=>{if(r=t!==null?{...r,parent:t}:r,r.children&&r.children.length){const n=[...r.children];return delete r.children,B.flatten([r,...iS(n,r._id)])}return r}));function lS(e,t,r){const n=B.filter(e,o=>o._parent===t),a=[];for(let o=0;o<n.length;o++){const s=cS(n[o]);if(Object.keys(s).length>0&&Object.keys(s).forEach(i=>{n[o][i]=`slot:${vt.generateUUID()}`}),B.filter(e,{_parent:n[o]._id}).length>0){const i=vt.generateUUID();a.push({...n[o],oldId:n[o]._id,_id:i,_parent:r}),a.push(B.flatten(lS(e,n[o]._id,i)))}else a.push({...n[o],oldId:n[o]._id,_id:vt.generateUUID(),_parent:r})}return B.flatten(a)}function pB(e){let t=dB.convert(e.map(r=>B.omit(r,["settings"])));return t=!t.type&&t.blockNodes?t.blockNodes:B.isEmpty(t)?[]:[t],t}const cS=e=>{const t={};return Object.keys(e).forEach(r=>{B.isString(e[r])&&e[r].startsWith("slot")&&(t[r]=e[r].replace("slot:",""))}),t},hB=(e,t,r=null)=>{let n=B.find(e,{_id:t});n={...n,oldId:n._id,_id:vt.generateUUID()},r&&(n={...n,_parent:r});const a=[n];B.filter(e,{_parent:t}).length>0&&a.push(B.flatten(lS(e,t,n._id)));const o=B.flatten(a);return B.map(o,s=>{const i=s,l=cS(i);return Object.keys(l).length>0&&Object.keys(l).forEach(u=>{const c=B.find(o,{oldId:l[u].replace("slot:","")});i[u]=`slot:${c._id}`}),B.omit(i,["global","oldId"])})},bB=Xa((e=[],t)=>{switch(t.type){case"add_new_blocks":case"add_duplicate_blocks":return[...e,...t.payload];case"create_snapshot":return[...e];case"set_blocks":case"set_page_blocks":return[...t.payload];case"update_props":case"update_props_realtime":const{payload:r}=t;return e.map(n=>(r.ids.includes(n._id)&&!B.isEmpty(t.payload.props)&&Object.keys(t.payload.props).forEach(a=>{B.set(n,a,t.payload.props[a])}),n));default:return e}},{debug:!1,ignoreInitialState:!1,limit:30,filter:Xa.excludeAction(["update_props_realtime","add_duplicate_blocks","set_page_blocks"])}),ec=tj({past:[],present:[],future:[]},bB);ec.debugLabel="pageBlocksAtom";const Kt=G.atom(e=>{var t;return(t=e(ec))==null?void 0:t.present});Kt.debugLabel="presentBlocksAtom";const td=sj(Kt);td.debugLabel="pageBlocksAtomsAtom";const uS=G.atom(e=>pB(e(Kt)));uS.debugLabel="pageBlocksTreeAtom";const mB=G.atom("");mB.debugLabel="builderActivePageAtom";const gB=G.atom(-1);gB.debugLabel="destinationDropIndexAtom";const fS=G.atom(!1);fS.debugLabel="addBlocksModalAtom";const Wt=()=>{const[,e]=G.useAtom(ec);return e},vB=()=>{const e=Wt(),t=G.useAtomValue(uS),r=g.useCallback(n=>{const a=iS(n);e({type:"set_page_blocks",payload:a})},[e]);return[t,r]},dS=()=>{const e=Wt();return[g.useCallback(r=>{e({type:"set_page_blocks",payload:r})},[e])]},Nu=e=>["Box","Slot","Form","DataProvider","Link","List","ListItem","Row","Column","Table","TableCell"].includes(e),yB=e=>!["Slot"].includes(e),wB=e=>!["Slot"].includes(e);function SB(e,t){return e==="Slot"||t==="List"&&e!=="ListItem"||t==="Row"&&e!=="Column"?!1:Nu(t)}const AB=(e,{dragSource:t,dropTarget:r})=>{const n=B.get(t,"data._type",""),a=B.get(r,"data._type","");return n==="Slot"||B.get(t,"id")&&B.get(t,"id")===B.get(r,"id")?!1:B.isEmpty(a)?!0:SB(n,a)},rd=G.atom([]);rd.debugLabel="selectedBlockIdsAtom";const nd=G.atom(e=>{const t=e(Kt),r=e(rd);return B.map(B.filter(t,({_id:n})=>B.includes(r,n)),n=>({...n}))});nd.debugLabel="selectedBlocksAtom";const ad=G.atom(e=>{const t=e(nd);return t.length===0?null:t.length===1?t[0]:{type:"Multiple",id:B.map(t,"id")}});ad.debugLabel="selectedBlockAtom";const EB=e=>B.get(e,"parent",null),OB=G.atom(e=>{const t=e(nd),r=B.map(t,EB);return B.filter(e(Kt),n=>B.includes(r,n._id))});OB.debugLabel="selectedBlocksParentsAtom";const pS=G.atom(()=>!1);pS.debugLabel="selectedBlockFlexChildAtom";const hS=G.atom(()=>!1);hS.debugLabel="selectedBlockGridChildAtom";const od=G.atom("");od.debugLabel="styleStateAtom";const bS=At("styleBreakpoint","xs");bS.debugLabel="styleBreakpointAtom";const CB=()=>({flexChild:G.useAtomValue(pS),gridChild:G.useAtomValue(hS)}),IB=()=>G.useAtomValue(ad),Zr=()=>{const[e,t]=G.useAtom(rd),r=g.useCallback(n=>{t(a=>B.includes(a,n)?B.without(a,n):[...a,n])},[t]);return[e,t,r]},Mu=(e,t="")=>{switch(e.type){case"singular":return e.uiSchema;case"model":const{properties:r}=e,n={};return Object.keys(r).forEach(s=>{const i=r[s];if(B.includes(["slot","styles"],i.type))return;const l=B.get(i,"i18n",!1)?`${s}-${t}`:s;n[l]=Mu(i,t)}),n;case"list":const{itemProperties:a}=e,o={items:{}};return Object.keys(a).forEach(s=>{const i=a[s];if(B.includes(["slot","styles"],i.type))return;const l=B.get(i,"i18n",!1)?`${s}-${t}`:s;o.items[l]=Mu(i,t)}),o;default:return{}}},Tu=(e,t="")=>{switch(e.type){case"singular":return e.schema;case"model":const{properties:r,title:n}=e,a={title:n,type:"object",properties:{}};return Object.keys(r).forEach(l=>{const u=r[l];if(B.includes(["slot","styles"],u.type))return;const c=B.get(u,"i18n",!1)?`${l}-${t}`:l;a.properties[c]=Tu(u,t)}),a;case"list":const{itemProperties:o,title:s}=e,i={title:s,type:"array",items:{type:"object",properties:{}}};return Object.keys(o).forEach(l=>{const u=o[l];if(B.includes(["slot","styles"],u.type))return;const c=B.get(u,"i18n",!1)?`${l}-${t}`:l;i.items.properties[c]=Tu(u,t),B.set(i.items,"title",B.get(u,"itemTitle",`${s} item`))}),i;default:return{}}},mS=e=>{const t={};return Object.keys(e).forEach(r=>{t[r]=PB(e[r])}),t},kB=e=>{if(B.isEmpty(e.default))return[];const{itemProperties:t}=e;return B.map(e.default,r=>{const n={...r};return B.forIn(r,(a,o)=>{B.has(t,o)&&B.get(t[o],"i18n",!1)&&(n[o]=ze.I18N_KEY)}),n})},PB=e=>{switch(e.type){case"styles":return e.default;case"slot":return`${ze.SLOT_KEY}${vt.generateUUID()}`;case"singular":const{i18n:t,schema:r}=e;return t?ze.I18N_KEY:B.get(r,"default","");case"model":return mS(e.properties);case"list":return kB(e);default:return""}},gS=()=>G.useAtomValue(Kt);function im(e,t,r,n,a){if(t===null)return[...e,...n];if(r!==null){const l=B.findIndex(e,{_parent:t}),u=(l===-1?0:l)+r;return e.splice(u,0,...n),e}if(!a){const u=B.findIndex(e,{_id:t})+1;return e.splice(u,0,...n),e}let o=B.findIndex(e,{_id:t});const s=B.filter(e,{_parent:t});B.isEmpty(s)||(o=B.findIndex(e,{_id:B.last(s)._id}));const i=o+1;return e.splice(i,0,...n),e}const xB=()=>{const e=Wt(),t=gS(),[,r]=Zr(),n=g.useCallback((o,s,i)=>{var c;for(let f=0;f<o.length;f++){const{_id:d}=o[f];o[f]._id=vt.generateUUID();const p=B.filter(o,{_parent:d});for(let b=0;b<p.length;b++)p[b]._parent=o[f]._id}let l;s&&(l=B.find(t,{_id:s}),o[0]._parent=s);const u=l?Nu(l._type):!0;return!u&&l&&(o[0]._parent=l._parent),e({type:"set_blocks",payload:im(t,s||null,i||null,o,u)}),r([(c=B.first(o))==null?void 0:c._id]),B.first(o)},[t,e,r]);return{addCoreBlock:g.useCallback((o,s,i)=>{if(B.has(o,"blocks")){const h=o.blocks;return n(h,s,i)}const l=vt.generateUUID(),u=mS(o.props),c=[];B.forIn(u,(h,m)=>{if(B.startsWith(h,ze.SLOT_KEY)){const v=h.replace(ze.SLOT_KEY,"");c.push({_id:v,_type:"Slot",_parent:l,_name:o.props[m].name,_styles:o.props[m].styles,_emptyStyles:o.props[m].emptyStyles})}});const f={_type:o.type,_id:l,...u};let d;s&&(d=B.find(t,{_id:s}),f._parent=s);const p=d?Nu(d._type):!0;!p&&d&&(f._parent=d._parent);const b=[f,...c];return e({type:"set_blocks",payload:im(t,s||null,i||null,b,p)}),r([f._id]),f},[n,t,e,r]),addPredefinedBlock:n}},lm={xs:420,sm:620,md:768,lg:1024,xl:1280,"2xl":1536},cm=["xs","sm","md","lg","xl","2xl"];function RB(e,t){if(t===null)return"baseClasses";const r=t.mq;if(r==="xs"||t.dark||t.mod!=="")return"classes";let n="baseClasses",a=cm.indexOf(r);for(;a>0;){const o=cm[a-1];if(B.find(e,{mq:o,property:t.property})){n="classes";break}a--}return n}const um=[];function NB(e="",t="",r=[]){e=e.trim().replace(/ +/g,"");let n=B.filter(B.map(e.split(" "),vt.constructClassObject),u=>!B.isNull(u)),a=B.filter(B.map(t.split(" "),vt.constructClassObject),u=>!B.isNull(u));a=B.filter(a,u=>!B.includes(um,u.property));const o=[],s=[];B.each(r,u=>{const c=vt.constructClassObject(u),f=B.find(n,B.pick(c,["dark","mq","mod","property"]));if(f&&(n=B.filter(n,d=>d.fullCls!==(f==null?void 0:f.fullCls))),o.push(c),c.mq==="xs"&&!c.dark&&c.mod===""&&(a=B.filter(a,d=>d.property!==c.property)),RB(n,c)==="baseClasses"&&!B.includes(um,c.property)){const d=B.find(a,B.pick(c,["property"]));f&&(a=B.filter(a,p=>p.fullCls!==(d==null?void 0:d.fullCls))),s.push({...c,fullCls:c.cls,mq:"xs"})}});const i=B.map(B.sortBy([...n,...o],u=>lm[u.mq]),"fullCls").join(" ");return`${B.map(B.sortBy([...a,...s],u=>lm[u.mq]),"fullCls").join(" ").trim()},${i.trim()}`.trim().replace(/ +/g,"")}const Ko=G.atom([]);Ko.debugLabel="selectedStylingBlocksAtom";const sd=()=>G.useAtom(Ko),MB=e=>{const t=e.replace(ze.STYLES_KEY,"").split(",");return{baseClasses:t[0],classes:t[1]}},TB=G.atom(null,(e,t,{blockIds:r,newClasses:n,dispatch:a})=>{const o=B.filter(e(td),i=>r.includes(e(i)._id)),s=B.first(e(Ko));B.each(o,i=>{const l=e(i),u=B.get(l,s.prop,`${ze.STYLES_KEY},`),{baseClasses:c,classes:f}=MB(u);a({type:"update_props_realtime",payload:{ids:[l._id],props:{[s.prop]:`${ze.STYLES_KEY}${NB(f,c,n)}`}}})})}),jB=()=>{const e=Wt(),t=G.useSetAtom(TB);return g.useCallback((r,n,a)=>{t({blockIds:r,newClasses:n,dispatch:e}),a&&setTimeout(()=>e({type:"create_snapshot"}),500)},[e,t])},vS=G.atom([]);vS.debugLabel="buildingBlocksAtom";const zB=G.atom(e=>{const t=e(vS);return B.filter(t,r=>B.has(r,"blockId"))}),qB=()=>{},yS=()=>{const e=sg.useChaiBlocks(),t=G.useAtomValue(zB),r=()=>{},n=g.useCallback(()=>qB(),[]);return[e,t,r,n]},FB=G.atom(!1),id=()=>{const[e,t]=G.useAtom(FB);return[e,t]},DB=G.atom(ze.BRANDING_OPTIONS_DEFAULTS),ld=()=>{const[e,t]=G.useAtom(DB);return[B.isObject(e)?{...ze.BRANDING_OPTIONS_DEFAULTS,...e}:ze.BRANDING_OPTIONS_DEFAULTS,t]},BB=G.atom(null),wS=()=>({currentPage:G.useAtomValue(BB)}),SS=new og({});function VB(e){let t=SS.convert(e);return t=!t.type&&t.children&&t.children.length?t.children:B.isEmpty(t)?[]:[t],t}const cd=(e,t)=>B.flatten(e.map(r=>{if(r=t?{...r,parent:t}:{...r},r.children){const n=[...r.children];return delete r.children,B.flatten([r,...cd(n,r._id)])}return r}));function ud(e,t=!1){for(let r=0;r<e.length;r++){const n=e[r];n.global&&!t?e[r]={type:"GlobalBlock",_parent:B.get(n,"parent",null),blockId:n.blockId,_id:n._id}:n.children&&n.children.length&&ud(n.children)}}function AS(e){let t=[],r=B.filter(e,{type:"GlobalBlock"});return r.length>0&&(r=B.map(r,ES),B.each(r,n=>{t=[...t,...LB(n)]})),t}function LB(e){let t=[];const r=B.get(B.first(e),"parent",null);B.set(B.first(e),"parent",null);const n=[SS.convert(OS(e))];ud(n,!0);let a=cd(n,e[0]._id);return a=B.set(a,"0.parent",r),t=[...t,a,...AS(a)],t}function ES(e){const t=B.find(ju,{_id:e._id});if(!t)return[];const r=[t],n=B.filter(ju,{_parent:e._id});return n.length?B.flatten([...r,...B.flatten(B.map(n,ES))]):B.flatten(r)}const OS=e=>JSON.parse(JSON.stringify(e));let ju=[];function KB(e){ju=e;const t=VB(OS(e));ud(t);const r=cd(t,null),n=AS(r),a={};return B.each(n,o=>B.set(a,B.first(o).blockId,o)),[r,a]}const fd=()=>{const[e]=ld(),{currentPage:t}=wS(),r=G.useAtomValue(Kt);return g.useCallback(()=>{const n=B.map(r,s=>B.omit(s,["expanded","order","title","siblings","tempClasses"])),[a=[],o=[]]=KB(n);return{currentPage:t,blocks:a,globalBlocks:o}},[e,t,r])};At("blockStylingActiveTab",1);G.atom([]);const CS=G.atom(!1);CS.debugLabel="readOnlyModeAtom";const IS=G.atom(!1);IS.debugLabel="inlineEditingActiveAtom";const kS=G.atom(!1);kS.debugLabel="advanceStylingOpenAtom";const PS=G.atom("online");PS.debugLabel="networkModeAtom";At("currentUiLibrary","");const WB=G.atom(!1);WB.debugLabel="codeEditorOpenAtom";const xS=G.atom(!1);xS.debugLabel="editLayerNameAtom";const UB=G.atom("");UB.debugLabel="activeLanguageAtom";const ZB=G.atom("");ZB.debugLabel="primaryLanguageAtom";const RS=G.atom(null);RS.debugLabel="canvasIframeAtom";const NS=G.atom("layers");NS.debugLabel="activePanelAtom";const MS=G.atom(!1);MS.debugLabel="addBlockOffCanvasAtom";const TS=G.atom("");TS.debugLabel="showPredefinedBlockCategoryAtom";const tc=G.atom({undoCount:0,redoCount:0});tc.debugLabel="historyStatesAtom";const dd=G.atom([]);dd.debugLabel="dataProvidersAtom";const jS=()=>G.useAtom(dd),Wo=G.atom("SAVED");Wo.debugLabel="pageSyncStateAtom";const JB=()=>{const[e,t]=G.useAtom(Wo),r=je.useBuilderProp("onSaveBlocks",async()=>{}),n=je.useBuilderProp("onSavePage",async()=>{}),a=je.useBuilderProp("onSyncStatusChange",()=>{}),o=fd(),s=G.useSetAtom(tc),{undoCount:i,redoCount:l}=Uo(),[u]=jS();return{savePage:KA.useThrottledCallback(async()=>{t("SAVING"),a("SAVING");const f=o();return await Promise.all([r({blocks:f.blocks,providers:[],identifier:"pageData.id"}),n({blocks:f.blocks,providers:u})]),setTimeout(()=>{s({undoCount:i,redoCount:l}),t("SAVED"),a("SAVED")},100),!0},[o,t,a,r],5e3),syncState:e,setSyncState:t}},Uo=()=>{const e=G.useAtomValue(ec),[{undoCount:t,redoCount:r}]=G.useAtom(tc),n=Wt(),[a]=id(),[,o]=Zr(),[,s]=sd(),[i,l]=G.useAtom(Wo),u=je.useBuilderProp("onSyncStatusChange",()=>{}),c=g.useCallback(()=>{n({type:"create_snapshot"})},[n]);return g.useEffect(()=>{(i==="SAVED"&&t!==(e==null?void 0:e.past.length)||r!==(e==null?void 0:e.future.length))&&(l("UNSAVED"),u("UNSAVED"))},[e==null?void 0:e.past.length,e==null?void 0:e.future.length,t,r,u,l,i]),{undoCount:e==null?void 0:e.past.length,redoCount:e==null?void 0:e.future.length,undo:g.useCallback(()=>{a||(n(Xa.ActionCreators.undo()),setTimeout(()=>{s([]),o([])},200))},[n,a,o,s]),redo:g.useCallback(()=>{a||(n(Xa.ActionCreators.redo()),setTimeout(()=>{s([]),o([])},200))},[a,n,s,o]),clear:()=>{n(Xa.ActionCreators.clearHistory())},createSnapshot:c}},zS=()=>G.useAtom(bS),qS=At("canvasWidth",800),FS=G.atom(e=>{const t=e(qS);return vt.getBreakpointValue(t).toLowerCase()}),GB=()=>{const[e,t]=G.useAtom(qS),r=G.useAtomValue(FS),[n,a]=zS();return g.useEffect(()=>{n!=="xs"&&a(r)},[r,n,a]),[e,r,t]},YB=At("canvasZoom",100),HB=()=>G.useAtom(YB),DS=G.atom([]),pd=()=>{const[e,t]=G.useAtom(DS),r=G.useSetAtom(hd),n=g.useCallback(a=>{t(a),r([])},[t,r]);return[e,n]},hd=G.atom([]),BS=()=>{const[e,t]=G.useAtom(hd),r=G.useSetAtom(DS),n=g.useCallback(a=>{t(a),r([])},[t,r]);return[e,n]},VS=At("darkMode",!1),QB=()=>{const[e,t]=G.useAtom(VS);return[e,t]},XB=G.atom(!1),_B=()=>{const[e,t]=G.useAtom(XB);return[e,t]},bd=()=>{const e=Wt(),t=G.useAtomValue(Kt),[,r]=Zr();return g.useCallback((n,a=null)=>{const o=[];B.each(n,s=>{const l=hB(t,s,a===s?null:a);o.push(B.get(l,"0._id","")),e({type:"add_duplicate_blocks",payload:l})}),r(o),e({type:"create_snapshot"})},[t,r,e])},$B=G.atom([]),eV=()=>{const[e,t]=G.useAtom($B),r=g.useCallback(n=>{t(a=>B.includes(a,n)?B.without(a,n):[...a,n])},[t]);return[e,t,r]},tV=G.atom(""),LS=()=>G.useAtom(tV),rV=()=>{const e=G.useAtomValue(Kt),t=Wt(),r=fd(),[,,n]=yS();return g.useCallback(async(a,o)=>{const s=vt.generateUUID(16),i=B.map(e,l=>(l._id===a&&(l._globalBlockId=s,l._name=o),l));t({type:"set_page_blocks",payload:i}),n()},[e,t,r,n])},nV=()=>({}),aV=()=>{const e=G.useAtomValue(Kt),t=Wt();return g.useCallback((r,n)=>{const a=B.map(e,o=>(B.includes(r,B.get(o,"_id"))&&B.set(o,"_parent",n),o));t({type:"set_blocks",payload:a})},[e,t])},KS=()=>{const e=G.useAtomValue(hd),[t,r]=pd(),n=bd(),a=aV();return{canPaste:g.useMemo(()=>t.length>0||e.length>0,[e,t]),pasteBlocks:g.useCallback(s=>{B.isEmpty(e)?a(t,s):n(e,s),r(()=>[])},[t,e,n,a,r])}},oV=G.atom(""),sV=()=>{const e=G.useAtomValue(oV),t=g.useCallback(()=>{},[]),r=g.useCallback(()=>{},[]),n=g.useCallback(()=>{},[]);return{currentProject:e,createProject:n,deleteProject:t,updateProject:r}},WS=(e,t)=>{const r=[],n=B.filter(e,a=>B.includes(t,a._id)||B.includes(t,a._parent)?(r.push(a._id),!1):!0);return B.isEmpty(r)?n:WS(n,r)},US=()=>{const e=Wt(),t=G.useAtomValue(Kt),[r,n]=Zr();return g.useCallback(a=>{var i;const o=((i=B.find(t,{_id:a[0]}))==null?void 0:i._parent)||null,s=WS(t,a);e({type:"set_blocks",payload:s}),n(o?[o]:[])},[t,n,e,r])},iV=G.atom(null,(e,t,{blockIds:r,fullClasses:n,dispatch:a})=>{const o=B.first(e(Ko)),s=B.filter(e(td),i=>r.includes(e(i)._id));B.each(s,i=>{const l=e(i),u=n;let{classes:c,baseClasses:f}=fB(B.get(l,o.prop,"styles:,"));B.each(u,d=>{const p=new RegExp(`(^| )${d.replace("[","\\[").replace("]","\\]")}($| )`,"g");c=c.replace(p," ").replace(/ +/g," ").trim();const b=B.first(d.split(":"));B.includes(["2xl","xl","lg","md","sm"],b)&&u.push(d.split(":").pop().trim())}),B.each(u,d=>{const p=new RegExp(`(^| )${d.replace("[","\\[").replace("]","\\]")}($| )`,"g");f=f.replace(p," ").replace(/ +/g," ").trim()}),a({type:"update_props_realtime",payload:{ids:[l._id],props:{[o.prop]:`${ze.STYLES_KEY}${f},${c}`}}})})}),lV=()=>{const e=Wt(),t=G.useSetAtom(iV);return g.useCallback((r,n)=>{t({blockIds:r,fullClasses:n,dispatch:e}),setTimeout(()=>e({type:"create_snapshot"}))},[e,t])},ZS=G.atom(e=>{const t=B.first(e(Ko)),r=e(ad);if(!t||t.blockId!==B.get(r,"_id",null))return[];const a=B.get(r,t.prop,`${ze.STYLES_KEY},`).replace(ze.STYLES_KEY,"").split(",").join(" ");return B.filter(B.map(a.trim().split(" "),vt.constructClassObject),o=>!B.isNull(o))}),cV=()=>G.useAtomValue(ZS),fm={xs:0,sm:1,md:2,lg:3,xl:4,"2xl":5},uV=G.atom(e=>{const t=e(FS),r=e(od),n=e(VS),a=fV(t);let o=B.filter(e(ZS),{mod:r});return B.startsWith(r,"_")||(o=B.filter(o,s=>a.includes(s.mq))),o=o.sort((s,i)=>fm[s.mq]-fm[i.mq]),n||(o=B.filter(o,{dark:!1})),o}),fV=e=>{let t=[];switch(e){case"xs":t=["xs"];break;case"sm":t=["xs","sm"];break;case"md":t=["xs","sm","md"];break;case"lg":t=["xs","sm","md","lg"];break;case"xl":t=["xs","sm","md","lg","xl"];break;case"2xl":t=["xs","sm","md","lg","xl","2xl"];break;default:t=["xs"];break}return t},dV=()=>G.useAtomValue(uV),pV=()=>G.useAtom(od),JS=G.atom(null,(e,t,{blockIds:r,props:n,dispatch:a})=>{a({type:"update_props_realtime",payload:{ids:r,props:n}})}),hV=()=>{const{createSnapshot:e}=Uo(),t=Wt(),r=G.useSetAtom(JS);return g.useCallback((n,a)=>{r({blockIds:n,props:a,dispatch:t}),e()},[e,t,r])},bV=()=>{const e=Wt(),t=G.useSetAtom(JS);return g.useCallback((r,n)=>{t({blockIds:r,props:n,dispatch:e})},[e,t])},GS={name:"",props:{},modalProps:{},backdropClose:!0},mV=G.atom(GS),gV=()=>{const[e,t]=G.useAtom(mV),r=g.useCallback((a,o={},s={})=>{t({name:a,props:o,modalProps:s})},[t]),n=g.useCallback((...a)=>{B.get(e,"props.onClose",()=>{})(...a),t(GS)},[t,e]);return{activeModal:e,openModal:r,closeModal:n}},vV=()=>G.useAtomValue(CS),yV=G.atom(""),wV=G.atom(null),SV=()=>G.useAtom(yV),AV=()=>G.useAtom(wV),EV=At("selectedBreakpoints",["XS","MD","XL"]),OV=()=>{const[e,t]=G.useAtom(EV);return[e,t]},md=()=>{const e=G.useSetAtom(tc),{clear:t}=Uo(),[,r]=Zr(),[,n]=LS(),[,a]=sd();return()=>{r([]),a([]),n(""),t(),e({undoCount:0,redoCount:0})}},CV=G.atom({en:{}}),IV=()=>{const[e,t]=G.useAtom(CV),r=g.useCallback((n,a,o)=>{B.set(e,`${n}.${a}`,o),t(e)},[e,t]);return[e,r]},kV=(e,t)=>{const[r]=G.useAtom(je.chaiBuilderPropsAtom);return B.get(r,e,t)},PV=G.atom([]),xV=()=>{const[e,t]=g.useState(!1),[r,n]=G.useAtom(PV),a=je.useBuilderProp("getUILibraryBlocks",()=>[]);return g.useEffect(()=>{(async()=>r.length>0||(t(!0),n(await a()),t(!1)))()},[]),{data:r,isLoading:e}},RV=G.atom("en"),NV=G.atom("en"),MV=G.atom(["en"]),YS=()=>G.useAtom(RV),TV=()=>G.useAtom(NV),jV=()=>G.useAtom(MV),zV=(e,t)=>{const[r]=YS(),n=`${e}${r?`-${r}`:""}`;return{content:B.get(t,n,B.get(t,e,"")),propKey:e}},qV=()=>{const[e,t]=id(),r=je.useBuilderProp("previewComponent");return ee.jsxRuntimeExports.jsxs("div",{className:LA.cn("fixed inset-0 z-[999] bg-background",e?"block":"hidden"),children:[ee.jsxRuntimeExports.jsx(je.Button,{size:"sm",className:"absolute right-0 top-0 m-4",onClick:()=>t(!1),children:"Close Preview"}),ee.jsxRuntimeExports.jsx("div",{children:r?ee.jsxRuntimeExports.jsx(g.Suspense,{fallback:ee.jsxRuntimeExports.jsx(je.Skeleton,{className:"h-96 w-full"}),children:g.createElement(r)}):null})]})},FV=()=>{const[e,t]=Zr(),[,r]=BS(),n=US(),a=bd(),[,o]=pd(),{pasteBlocks:s}=KS(),{undo:i,redo:l}=Uo();Ar.useHotkeys("esc",()=>t([]),{},[t]),Ar.useHotkeys("ctrl+c,command+c",()=>r(e),{},[e,r]),Ar.useHotkeys("ctrl+d,command+d",()=>a(e),{preventDefault:!0},[e,a]),Ar.useHotkeys("ctrl+x,command+x",()=>o(e),{},[e,o]),Ar.useHotkeys("ctrl+v,command+v",()=>e.length===1?s(e[0]):null,{},[e,s]),Ar.useHotkeys("ctrl+z,command+z",()=>i(),{},[i]),Ar.useHotkeys("ctrl+y,command+y",()=>l(),{},[l]),Ar.useHotkeys("del, backspace",u=>{u.preventDefault(),n(e)},{},[e,n])},DV=(e,t)=>{const r=[];let n=B.find(e,{_id:t}),a=B.get(n,"_parent","");for(;B.isString(a)&&!B.isEmpty(a);)r.push(n==null?void 0:n._parent),n=B.find(e,{_id:a}),a=n==null?void 0:n._parent;return B.flatten(r)},HS=G.atom([]),BV=()=>{const[e]=Zr(),t=G.useAtomValue(Kt),[,r]=G.useAtom(HS);g.useEffect(()=>{let n=[];const a=B.first(e);B.isString(a)&&(n=[a,...DV(t,a)]),r(n)},[e,t,r])},VV=()=>G.useAtomValue(HS),LV=g.lazy(()=>Promise.resolve().then(()=>require("./SidePanels-810faeb5.cjs"))),KV=g.lazy(()=>Promise.resolve().then(()=>require("./Topbar-bcd336bc.cjs"))),WV=g.lazy(()=>Promise.resolve().then(()=>require("./CanvasArea-67938f1e.cjs"))),UV=g.lazy(()=>Promise.resolve().then(()=>require("./Settings-447d24b0.cjs"))),ZV=()=>{const[e]=G.useAtom(Wo),t=a=>{a.preventDefault()};FV(),BV(),g.useEffect(()=>(e!=="SAVED"?window.onbeforeunload=()=>"":window.onbeforeunload=null,()=>{window.onbeforeunload=null}),[e]);const r=je.useBuilderProp("editable",!0),n=je.useBuilderProp("nonEditableComponent",null);return ee.jsxRuntimeExports.jsx("div",{className:"h-screen w-screen bg-background text-foreground",children:ee.jsxRuntimeExports.jsxs(je.TooltipProvider,{children:[ee.jsxRuntimeExports.jsxs("div",{onContextMenu:t,className:"flex h-screen flex-col overflow-hidden bg-background text-foreground",children:[ee.jsxRuntimeExports.jsx("div",{className:"h-14 w-screen shrink-0 border-b border-border",children:ee.jsxRuntimeExports.jsx(g.Suspense,{children:ee.jsxRuntimeExports.jsx(KV,{})})}),ee.jsxRuntimeExports.jsxs("main",{className:"flex h-full flex-row relative",children:[r?null:ee.jsxRuntimeExports.jsx("div",{className:"absolute backdrop-blur-[2px] flex items-center justify-center inset-0 z-[500] h-full w-full",children:ee.jsxRuntimeExports.jsx(g.Suspense,{children:g.createElement(n)})}),ee.jsxRuntimeExports.jsx("div",{className:"flex h-full w-fit border-border max-h-full",style:{maxHeight:"calc(100vh - 56px)"},children:ee.jsxRuntimeExports.jsx(g.Suspense,{children:ee.jsxRuntimeExports.jsx(LV,{})})}),ee.jsxRuntimeExports.jsx("div",{className:"h-full flex-1 bg-slate-800/20",children:ee.jsxRuntimeExports.jsx(g.Suspense,{children:ee.jsxRuntimeExports.jsx(WV,{})})}),ee.jsxRuntimeExports.jsx("div",{className:"flex h-full w-[280px] min-w-[280px] border-l border-border",children:ee.jsxRuntimeExports.jsx(g.Suspense,{children:ee.jsxRuntimeExports.jsx(UV,{})})})]})]}),ee.jsxRuntimeExports.jsx(qV,{})]})})},dm=G.getDefaultStore();G.atom({});function pm(e,t,r,n,a){for(t=t.split?t.split("."):t,n=0;n<t.length;n++)e=e?e[t[n]]:a;return e===a?r:e}var Ps="undefined",hm="object",QS="any",XS="*",wn="__",vl=typeof process<"u"?process:{};vl.env&&vl.env.NODE_ENV;var Qt=typeof document<"u";vl.versions!=null&&vl.versions.node!=null;typeof Deno<"u"&&Deno.core;Qt&&window.name==="nodejs"||typeof navigator<"u"&&navigator.userAgent!==void 0&&(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom"));function _S(e,t){return t.charAt(0)[e]()+t.slice(1)}var JV=_S.bind(null,"toUpperCase"),GV=_S.bind(null,"toLowerCase");function YV(e){return $S(e)?JV("null"):typeof e=="object"?$V(e):Object.prototype.toString.call(e).slice(8,-1)}function yl(e,t){t===void 0&&(t=!0);var r=YV(e);return t?GV(r):r}function Zo(e,t){return typeof t===e}var sr=Zo.bind(null,"function"),Yn=Zo.bind(null,"string"),Wn=Zo.bind(null,"undefined"),HV=Zo.bind(null,"boolean");Zo.bind(null,"symbol");function $S(e){return e===null}function QV(e){return yl(e)==="number"&&!isNaN(e)}function XV(e){return yl(e)==="array"}function It(e){if(!_V(e))return!1;for(var t=e;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function _V(e){return e&&(typeof e=="object"||e!==null)}function $V(e){return sr(e.constructor)?e.constructor.name:null}function eL(e){return e instanceof Error||Yn(e.message)&&e.constructor&&QV(e.constructor.stackTraceLimit)}function eA(e,t){if(typeof t!="object"||$S(t))return!1;if(t instanceof e)return!0;var r=yl(new e(""));if(eL(t))for(;t;){if(yl(t)===r)return!0;t=Object.getPrototypeOf(t)}return!1}eA.bind(null,TypeError);eA.bind(null,SyntaxError);function rc(e,t){var r=e instanceof Element||e instanceof HTMLDocument;return r&&t?tL(e,t):r}function tL(e,t){return t===void 0&&(t=""),e&&e.nodeName===t.toUpperCase()}function nc(e){var t=[].slice.call(arguments,1);return function(){return e.apply(void 0,[].slice.call(arguments).concat(t))}}nc(rc,"form");nc(rc,"button");nc(rc,"input");nc(rc,"select");function bm(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch{return null}}function rL(){if(Qt){var e=navigator,t=e.languages;return e.userLanguage||(t&&t.length?t[0]:e.language)}}function nL(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}function aL(e){return function(t){for(var r,n=Object.create(null),a=/([^&=]+)=?([^&]*)/g;r=a.exec(t);){var o=bm(r[1]),s=bm(r[2]);o.substring(o.length-2)==="[]"?(n[o=o.substring(0,o.length-2)]||(n[o]=[])).push(s):n[o]=s===""||s}for(var i in n){var l=i.split("[");l.length>1&&(oL(n,l.map(function(u){return u.replace(/[?[\]\\ ]/g,"")}),n[i]),delete n[i])}return n}(function(t){if(t){var r=t.match(/\?(.*)/);return r&&r[1]?r[1].split("#")[0]:""}return Qt&&window.location.search.substring(1)}(e))}function oL(e,t,r){for(var n=t.length-1,a=0;a<n;++a){var o=t[a];if(o==="__proto__"||o==="constructor")break;o in e||(e[o]={}),e=e[o]}e[t[n]]=r}function ac(){for(var e="",t=0,r=4294967295*Math.random()|0;t++<36;){var n="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"[t-1],a=15&r;e+=n=="-"||n=="4"?n:(n=="x"?a:3&a|8).toString(16),r=t%8==0?4294967295*Math.random()|0:r>>4}return e}var ao="global",Ea=wn+"global"+wn,Oa=typeof self===hm&&self.self===self&&self||typeof global===hm&&global.global===global&&global||void 0;function Sn(e){return Oa[Ea][e]}function An(e,t){return Oa[Ea][e]=t}function Ma(e){delete Oa[Ea][e]}function Ta(e,t,r){var n;try{if(gd(e)){var a=window[e];n=a[t].bind(a)}}catch{}return n||r}Oa[Ea]||(Oa[Ea]={});var xs={};function gd(e){if(typeof xs[e]!==Ps)return xs[e];try{var t=window[e];t.setItem(Ps,Ps),t.removeItem(Ps)}catch{return xs[e]=!1}return xs[e]=!0}function ye(){return ye=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},ye.apply(this,arguments)}var Pr="function",mr="undefined",sL="@@redux/"+Math.random().toString(36),mm=function(){return typeof Symbol===Pr&&Symbol.observable||"@@observable"}(),Rs=" != "+Pr;function tA(e,t,r){var n;if(typeof t===Pr&&typeof r===mr&&(r=t,t=void 0),typeof r!==mr){if(typeof r!==Pr)throw new Error("enhancer"+Rs);return r(tA)(e,t)}if(typeof e!==Pr)throw new Error("reducer"+Rs);var a=e,o=t,s=[],i=s,l=!1;function u(){i===s&&(i=s.slice())}function c(){return o}function f(p){if(typeof p!==Pr)throw new Error("Listener"+Rs);var b=!0;return u(),i.push(p),function(){if(b){b=!1,u();var h=i.indexOf(p);i.splice(h,1)}}}function d(p){if(!It(p))throw new Error("Act != obj");if(typeof p.type===mr)throw new Error("ActType "+mr);if(l)throw new Error("Dispatch in reducer");try{l=!0,o=a(o,p)}finally{l=!1}for(var b=s=i,h=0;h<b.length;h++)(0,b[h])();return p}return d({type:"@@redux/INIT"}),(n={dispatch:d,subscribe:f,getState:c,replaceReducer:function(p){if(typeof p!==Pr)throw new Error("next reducer"+Rs);a=p,d({type:"@@redux/INIT"})}})[mm]=function(){var p,b=f;return(p={subscribe:function(h){if(typeof h!="object")throw new TypeError("Observer != obj");function m(){h.next&&h.next(c())}return m(),{unsubscribe:b(m)}}})[mm]=function(){return this},p},n}function iL(e,t){var r=t&&t.type;return"action "+(r&&r.toString()||"?")+"reducer "+e+" returns "+mr}function Ca(){var e=[].slice.call(arguments);return e.length===0?function(t){return t}:e.length===1?e[0]:e.reduce(function(t,r){return function(){return t(r.apply(void 0,[].slice.call(arguments)))}})}function lL(){var e=arguments;return function(t){return function(r,n,a){var o,s=t(r,n,a),i=s.dispatch,l={getState:s.getState,dispatch:function(u){return i(u)}};return o=[].slice.call(e).map(function(u){return u(l)}),ye({},s,{dispatch:i=Ca.apply(void 0,o)(s.dispatch)})}}}var Vr=wn+"anon_id",mn=wn+"user_id",Hn=wn+"user_traits",kr="userId",Un="anonymousId",Ws=["bootstrap","params","campaign","initializeStart","initialize","initializeEnd","ready","resetStart","reset","resetEnd","pageStart","page","pageEnd","pageAborted","trackStart","track","trackEnd","trackAborted","identifyStart","identify","identifyEnd","identifyAborted","userIdChanged","registerPlugins","enablePlugin","disablePlugin","online","offline","setItemStart","setItem","setItemEnd","setItemAborted","removeItemStart","removeItem","removeItemEnd","removeItemAborted"],zu=["name","EVENTS","config","loaded"],ve=Ws.reduce(function(e,t){return e[t]=t,e},{registerPluginType:function(e){return"registerPlugin:"+e},pluginReadyType:function(e){return"ready:"+e}}),gm=/^utm_/,vm=/^an_prop_/,ym=/^an_trait_/;function cL(e){var t=e.storage.setItem;return function(r){return function(n){return function(a){if(a.type===ve.bootstrap){var o=a.params,s=a.user,i=a.persistedUser,l=a.initialUser,u=i.userId===s.userId;i.anonymousId!==s.anonymousId&&t(Vr,s.anonymousId),u||t(mn,s.userId),l.traits&&t(Hn,ye({},u&&i.traits?i.traits:{},l.traits));var c=Object.keys(a.params);if(c.length){var f=o.an_uid,d=o.an_event,p=c.reduce(function(b,h){if(h.match(gm)||h.match(/^(d|g)clid/)){var m=h.replace(gm,"");b.campaign[m==="campaign"?"name":m]=o[h]}return h.match(vm)&&(b.props[h.replace(vm,"")]=o[h]),h.match(ym)&&(b.traits[h.replace(ym,"")]=o[h]),b},{campaign:{},props:{},traits:{}});r.dispatch(ye({type:ve.params,raw:o},p,f?{userId:f}:{})),f&&setTimeout(function(){return e.identify(f,p.traits)},0),d&&setTimeout(function(){return e.track(d,p.props)},0),Object.keys(p.campaign).length&&r.dispatch({type:ve.campaign,campaign:p.campaign})}}return n(a)}}}}function uL(e){return function(t,r){if(t===void 0&&(t={}),r===void 0&&(r={}),r.type===ve.setItemEnd){if(r.key===Vr)return ye({},t,{anonymousId:r.value});if(r.key===mn)return ye({},t,{userId:r.value})}switch(r.type){case ve.identify:return Object.assign({},t,{userId:r.userId,traits:ye({},t.traits,r.traits)});case ve.reset:return[mn,Vr,Hn].forEach(function(n){e.removeItem(n)}),Object.assign({},t,{userId:null,anonymousId:null,traits:{}});default:return t}}}function wm(e){return{userId:e.getItem(mn),anonymousId:e.getItem(Vr),traits:e.getItem(Hn)}}var qu=function(e){return wn+"TEMP"+wn+e};function fL(e){var t=e.storage,r=t.setItem,n=t.removeItem,a=t.getItem;return function(o){return function(s){return function(i){var l=i.userId,u=i.traits,c=i.options;if(i.type===ve.reset&&([mn,Hn,Vr].forEach(function(p){n(p)}),[kr,Un,"traits"].forEach(function(p){Ma(qu(p))})),i.type===ve.identify){a(Vr)||r(Vr,ac());var f=a(mn),d=a(Hn)||{};f&&f!==l&&o.dispatch({type:ve.userIdChanged,old:{userId:f,traits:d},new:{userId:l,traits:u},options:c}),l&&r(mn,l),u&&r(Hn,ye({},d,u))}return s(i)}}}}var Ha={};function Sm(e,t){Ha[e]&&sr(Ha[e])&&(Ha[e](t),delete Ha[e])}function rA(e,t,r){return new Promise(function(n,a){return t()?n(e):r<1?a(ye({},e,{queue:!0})):new Promise(function(o){return setTimeout(o,10)}).then(function(o){return rA(e,t,r-10).then(n,a)})})}function nA(e,t,r){var n=t(),a=e.getState(),o=a.plugins,s=a.queue,i=a.user;if(!a.context.offline&&s&&s.actions&&s.actions.length){var l=s.actions.reduce(function(c,f,d){return o[f.plugin].loaded?(c.process.push(f),c.processIndex.push(d)):(c.requeue.push(f),c.requeueIndex.push(d)),c},{processIndex:[],process:[],requeue:[],requeueIndex:[]});if(l.processIndex&&l.processIndex.length){l.processIndex.forEach(function(c){var f=s.actions[c],d=f.plugin,p=f.payload.type,b=n[d][p];if(b&&sr(b)){var h=function(v,y){return v===void 0&&(v={}),y===void 0&&(y={}),[kr,Un].reduce(function(w,A){return v.hasOwnProperty(A)&&y[A]&&y[A]!==v[A]&&(w[A]=y[A]),w},v)}(f.payload,i);b({payload:h,config:o[d].config,instance:r});var m=p+":"+d;e.dispatch(ye({},h,{type:m,_:{called:m,from:"queueDrain"}}))}});var u=s.actions.filter(function(c,f){return!~l.processIndex.indexOf(f)});s.actions=u}}}var _c=function(e){var t=e.data,r=e.action,n=e.instance,a=e.state,o=e.allPlugins,s=e.allMatches,i=e.store,l=e.EVENTS;try{var u=a.plugins,c=a.context,f=r.type,d=f.match(Qn),p=t.exact.map(function(m){return m.pluginName});d&&(p=s.during.map(function(m){return m.pluginName}));var b=function(m,v){return function(y,w,A){var S=w.config,E=w.name,C=E+"."+y.type;A&&(C=A.event);var P=y.type.match(Qn)?function(I,T,z,N,W){return function(F,V){var _=N?N.name:I,U=V&&mo(V)?V:z;if(N&&(!(U=V&&mo(V)?V:[I]).includes(I)||U.length!==1))throw new Error("Method "+T+" can only abort "+I+" plugin. "+JSON.stringify(U)+" input valid");return ye({},W,{abort:{reason:F,plugins:U,caller:T,_}})}}(E,C,v,A,y):function(I,T){return function(){throw new Error(I.type+" action not cancellable. Remove abort in "+T)}}(y,C);return{payload:dL(y),instance:m,config:S||{},abort:P}}}(n,p),h=t.exact.reduce(function(m,v){var y=v.pluginName,w=v.methodName,A=!1;return w.match(/^initialize/)||w.match(/^reset/)||(A=!u[y].loaded),c.offline&&w.match(/^(page|track|identify)/)&&(A=!0),m[""+y]=A,m},{});return Promise.resolve(t.exact.reduce(function(m,v,y){try{var w=v.pluginName;return Promise.resolve(m).then(function(A){function S(){return Promise.resolve(A)}var E=function(){if(t.namespaced&&t.namespaced[w])return Promise.resolve(t.namespaced[w].reduce(function(C,P,I){try{return Promise.resolve(C).then(function(T){return P.method&&sr(P.method)?(function(F,V){var _=Pm(F);if(_&&_.name===V){var U=Pm(_.method);throw new Error([V+" plugin is calling method "+F,"Plugins cant call self","Use "+_.method+" "+(U?"or "+U.method:"")+" in "+V+" plugin insteadof "+F].join(`
|
|
164
|
-
`))}}(P.methodName,P.pluginName),Promise.resolve(P.method({payload:T,instance:n,abort:(z=T,N=w,W=P.pluginName,function(F,V){return ye({},z,{abort:{reason:F,plugins:V||[N],caller:f,from:W||N}})}),config:Om(P.pluginName,u,o),plugins:u})).then(function(F){var V=It(F)?F:{};return Promise.resolve(ye({},T,V))})):T;var z,N,W})}catch(T){return Promise.reject(T)}},Promise.resolve(r))).then(function(C){A[w]=C});A[w]=r}();return E&&E.then?E.then(S):S()})}catch(A){return Promise.reject(A)}},Promise.resolve({}))).then(function(m){return Promise.resolve(t.exact.reduce(function(v,y,w){try{var A=t.exact.length===w+1,S=y.pluginName,E=o[S];return Promise.resolve(v).then(function(C){var P=m[S]?m[S]:{};if(d&&(P=C),eu(P,S))return $c({data:P,method:f,instance:n,pluginName:S,store:i}),Promise.resolve(C);if(eu(C,S))return A&&$c({data:C,method:f,instance:n,store:i}),Promise.resolve(C);if(h.hasOwnProperty(S)&&h[S]===!0)return i.dispatch({type:"queue",plugin:S,payload:P,_:{called:"queue",from:"queueMechanism"}}),Promise.resolve(C);var I=b(m[S],o[S]);return Promise.resolve(E[f]({abort:I.abort,payload:P,instance:n,config:Om(S,u,o),plugins:u})).then(function(T){var z=It(T)?T:{},N=ye({},C,z),W=m[S];if(eu(W,S))$c({data:W,method:f,instance:n,pluginName:S,store:i});else{var F=f+":"+S;(F.match(/:/g)||[]).length<2&&!f.match(Am)&&!f.match(Em)&&n.dispatch(ye({},d?N:P,{type:F,_:{called:F,from:"submethod"}}))}return Promise.resolve(N)})})}catch(C){return Promise.reject(C)}},Promise.resolve(r))).then(function(v){if(!(f.match(Qn)||f.match(/^registerPlugin/)||f.match(Em)||f.match(Am)||f.match(/^params/)||f.match(/^userIdChanged/))){if(l.plugins.includes(f),v._&&v._.originalAction===f)return v;var y=ye({},v,{_:{originalAction:v.type,called:v.type,from:"engineEnd"}});aA(v,t.exact.length)&&!f.match(/End$/)&&(y=ye({},y,{type:v.type+"Aborted"})),i.dispatch(y)}return v})})}catch(m){return Promise.reject(m)}},Qn=/Start$/,Am=/^bootstrap/,Em=/^ready/;function $c(e){var t=e.pluginName,r=e.method+"Aborted"+(t?":"+t:"");e.store.dispatch(ye({},e.data,{type:r,_:{called:r,from:"abort"}}))}function Om(e,t,r){var n=t[e]||r[e];return n&&n.config?n.config:{}}function Cm(e,t){return t.reduce(function(r,n){return n[e]?r.concat({methodName:e,pluginName:n.name,method:n[e]}):r},[])}function Im(e,t){var r=e.replace(Qn,""),n=t?":"+t:"";return[""+e+n,""+r+n,r+"End"+n]}function eu(e,t){var r=e.abort;return!!r&&(r===!0||km(r,t)||r&&km(r.plugins,t))}function aA(e,t){var r=e.abort;if(!r)return!1;if(r===!0||Yn(r))return!0;var n=r.plugins;return mo(r)&&r.length===t||mo(n)&&n.length===t}function mo(e){return Array.isArray(e)}function km(e,t){return!(!e||!mo(e))&&e.includes(t)}function Pm(e){var t=e.match(/(.*):(.*)/);return!!t&&{method:t[1],name:t[2]}}function dL(e){return Object.keys(e).reduce(function(t,r){return r==="type"||(t[r]=It(e[r])?Object.assign({},e[r]):e[r]),t},{})}function pL(e,t,r){var n={};return function(a){return function(o){return function(s){try{var i,l=function(A){return i?A:o(f)},u=s.type,c=s.plugins,f=s;if(s.abort)return Promise.resolve(o(s));if(u===ve.enablePlugin&&a.dispatch({type:ve.initializeStart,plugins:c,disabled:[],fromEnable:!0,meta:s.meta}),u===ve.disablePlugin&&setTimeout(function(){return Sm(s.meta.rid,{payload:s})},0),u===ve.initializeEnd){var d=t(),p=Object.keys(d),b=p.filter(function(A){return c.includes(A)}).map(function(A){return d[A]}),h=[],m=[],v=s.disabled,y=b.map(function(A){var S=A.loaded,E=A.name,C=A.config;return rA(A,function(){return S({config:C})},1e4).then(function(P){return n[E]||(a.dispatch({type:ve.pluginReadyType(E),name:E,events:Object.keys(A).filter(function(I){return!zu.includes(I)})}),n[E]=!0),h=h.concat(E),A}).catch(function(P){if(P instanceof Error)throw new Error(P);return m=m.concat(P.name),P})});Promise.all(y).then(function(A){var S={plugins:h,failed:m,disabled:v};setTimeout(function(){p.length===y.length+v.length&&a.dispatch(ye({},{type:ve.ready},S))},0)})}var w=function(){if(u!==ve.bootstrap)return/^ready:([^:]*)$/.test(u)&&setTimeout(function(){return nA(a,t,e)},0),Promise.resolve(function(A,S,E,C,P){try{var I=sr(S)?S():S,T=A.type,z=T.replace(Qn,"");if(A._&&A._.called)return Promise.resolve(A);var N=E.getState(),W=(_=I,(U=N.plugins)===void 0&&(U={}),(Z=A.options)===void 0&&(Z={}),Object.keys(_).filter(function(O){var R=Z.plugins||{};return HV(R[O])?R[O]:R.all!==!1&&(!U[O]||U[O].enabled!==!1)}).map(function(O){return _[O]}));T===ve.initializeStart&&A.fromEnable&&(W=Object.keys(N.plugins).filter(function(O){var R=N.plugins[O];return A.plugins.includes(O)&&!R.initialized}).map(function(O){return I[O]}));var F=W.map(function(O){return O.name}),V=function(O,R,J){var D=Im(O).map(function(K){return Cm(K,R)});return R.reduce(function(K,$){var ne=$.name,X=Im(O,ne).map(function(ue){return Cm(ue,R)}),se=X[0],te=X[1],ae=X[2];return se.length&&(K.beforeNS[ne]=se),te.length&&(K.duringNS[ne]=te),ae.length&&(K.afterNS[ne]=ae),K},{before:D[0],beforeNS:{},during:D[1],duringNS:{},after:D[2],afterNS:{}})}(T,W);return Promise.resolve(_c({action:A,data:{exact:V.before,namespaced:V.beforeNS},state:N,allPlugins:I,allMatches:V,instance:E,store:C,EVENTS:P})).then(function(O){function R(){var K=function(){if(T.match(Qn))return Promise.resolve(_c({action:ye({},J,{type:z+"End"}),data:{exact:V.after,namespaced:V.afterNS},state:N,allPlugins:I,allMatches:V,instance:E,store:C,EVENTS:P})).then(function($){$.meta&&$.meta.hasCallback&&Sm($.meta.rid,{payload:$})})}();return K&&K.then?K.then(function(){return O}):O}if(aA(O,F.length))return O;var J,D=function(){if(T!==z)return Promise.resolve(_c({action:ye({},O,{type:z}),data:{exact:V.during,namespaced:V.duringNS},state:N,allPlugins:I,allMatches:V,instance:E,store:C,EVENTS:P})).then(function(K){J=K});J=O}();return D&&D.then?D.then(R):R()})}catch(O){return Promise.reject(O)}var _,U,Z}(s,t,e,a,r)).then(function(A){return i=1,o(A)})}();return Promise.resolve(w&&w.then?w.then(l):l(w))}catch(A){return Promise.reject(A)}}}}}function hL(e){return function(t){return function(r){return function(n){var a=n.type,o=n.key,s=n.value,i=n.options;if(a===ve.setItem||a===ve.removeItem){if(n.abort)return r(n);a===ve.setItem?e.setItem(o,s,i):e.removeItem(o,i)}return r(n)}}}}var bL=function(){var e=this;this.before=[],this.after=[],this.addMiddleware=function(t,r){e[r]=e[r].concat(t)},this.removeMiddleware=function(t,r){var n=e[r].findIndex(function(a){return a===t});n!==-1&&(e[r]=[].concat(e[r].slice(0,n),e[r].slice(n+1)))},this.dynamicMiddlewares=function(t){return function(r){return function(n){return function(a){var o={getState:r.getState,dispatch:function(i){return r.dispatch(i)}},s=e[t].map(function(i){return i(o)});return Ca.apply(void 0,s)(n)(a)}}}}};function mL(e){return function(t,r){t===void 0&&(t={});var n={};if(r.type==="initialize:aborted")return t;if(/^registerPlugin:([^:]*)$/.test(r.type)){var a=xm(r.type,"registerPlugin"),o=e()[a];if(!o||!a)return t;var s=r.enabled,i=o.config;return n[a]={enabled:s,initialized:!!s&&!o.initialize,loaded:!!s&&!!o.loaded({config:i}),config:i},ye({},t,n)}if(/^initialize:([^:]*)$/.test(r.type)){var l=xm(r.type,ve.initialize),u=e()[l];return u&&l?(n[l]=ye({},t[l],{initialized:!0,loaded:!!u.loaded({config:u.config})}),ye({},t,n)):t}if(/^ready:([^:]*)$/.test(r.type))return n[r.name]=ye({},t[r.name],{loaded:!0}),ye({},t,n);switch(r.type){case ve.disablePlugin:return ye({},t,Rm(r.plugins,!1,t));case ve.enablePlugin:return ye({},t,Rm(r.plugins,!0,t));default:return t}}}function xm(e,t){return e.substring(t.length+1,e.length)}function Rm(e,t,r){return e.reduce(function(n,a){return n[a]=ye({},r[a],{enabled:t}),n},r)}function oA(e){try{return JSON.parse(JSON.stringify(e))}catch{}return e}var gL={last:{},history:[]};function vL(e,t){e===void 0&&(e=gL);var r=t.options,n=t.meta;if(t.type===ve.track){var a=oA(ye({event:t.event,properties:t.properties},Object.keys(r).length&&{options:r},{meta:n}));return ye({},e,{last:a,history:e.history.concat(a)})}return e}var yL={actions:[]};function wL(e,t){e===void 0&&(e=yL);var r=t.payload;switch(t.type){case"queue":var n;return n=r&&r.type&&r.type===ve.identify?[t].concat(e.actions):e.actions.concat(t),ye({},e,{actions:n});case"dequeue":return[];default:return e}}var sA=/#.*$/;function SL(e){var t=/(http[s]?:\/\/)?([^\/\s]+\/)(.*)/g.exec(e);return"/"+(t&&t[3]?t[3].split("?")[0].replace(sA,""):"")}var iA,lA,cA,uA,AL=function(e){if(e===void 0&&(e={}),!Qt)return e;var t=document,r=t.title,n=t.referrer,a=window,o=a.location,s=a.innerWidth,i=a.innerHeight,l=o.hash,u=o.search,c=function(d){var p=function(){if(Qt){for(var b,h=document.getElementsByTagName("link"),m=0;b=h[m];m++)if(b.getAttribute("rel")==="canonical")return b.getAttribute("href")}}();return p?p.match(/\?/)?p:p+d:window.location.href.replace(sA,"")}(u),f={title:r,url:c,path:SL(c),hash:l,search:u,width:s,height:i};return n&&n!==""&&(f.referrer=n),ye({},f,e)},EL={last:{},history:[]};function OL(e,t){e===void 0&&(e=EL);var r=t.options;if(t.type===ve.page){var n=oA(ye({properties:t.properties,meta:t.meta},Object.keys(r).length&&{options:r}));return ye({},e,{last:n,history:e.history.concat(n)})}return e}iA=function(){if(!Qt)return!1;var e=navigator.appVersion;return~e.indexOf("Win")?"Windows":~e.indexOf("Mac")?"MacOS":~e.indexOf("X11")?"UNIX":~e.indexOf("Linux")?"Linux":"Unknown OS"}(),lA=Qt?document.referrer:null,cA=rL(),uA=nL();var Nm={initialized:!1,sessionId:ac(),app:null,version:null,debug:!1,offline:!!Qt&&!navigator.onLine,os:{name:iA},userAgent:Qt?navigator.userAgent:"node",library:{name:"analytics",version:"0.12.5"},timezone:uA,locale:cA,campaign:{},referrer:lA};function CL(e,t){e===void 0&&(e=Nm);var r=e.initialized,n=t.campaign;switch(t.type){case ve.campaign:return ye({},e,{campaign:n});case ve.offline:return ye({},e,{offline:!0});case ve.online:return ye({},e,{offline:!1});default:return r?e:ye({},Nm,e,{initialized:!0})}}var IL=["plugins","reducers","storage"];function kL(e,t,r){if(Qt){var n=window[(r?"add":"remove")+"EventListener"];e.split(" ").forEach(function(a){n(a,t)})}}function PL(e){var t=kL.bind(null,"online offline",function(r){return Promise.resolve(!navigator.onLine).then(e)});return t(!0),function(r){return t(!1)}}function fA(){return An("analytics",[]),function(e){return function(t,r,n){var a=e(t,r,n),o=a.dispatch;return Object.assign(a,{dispatch:function(s){return Oa[Ea].analytics.push(s.action||s),o(s)}})}}}function Mm(e){return function(){return Ca(Ca.apply(null,arguments),fA())}}function tu(e){return e?XV(e)?e:[e]:[]}function Tm(e,t,r){e===void 0&&(e={});var n,a,o=ac();return t&&(Ha[o]=(n=t,a=function(s){for(var i,l=s||Array.prototype.slice.call(arguments),u=0;u<l.length;u++)if(sr(l[u])){i=l[u];break}return i}(r),function(s){a&&a(s),n(s)})),ye({},e,{rid:o,ts:new Date().getTime()},t?{hasCallback:!0}:{})}function xL(e){e===void 0&&(e={});var t=e.reducers||{},r=e.initialUser||{},n=(e.plugins||[]).reduce(function(O,R){if(sr(R))return O.middlewares=O.middlewares.concat(R),O;if(R.NAMESPACE&&(R.name=R.NAMESPACE),!R.name)throw new Error("https://lytics.dev/errors/1");R.config||(R.config={});var J=R.EVENTS?Object.keys(R.EVENTS).map(function($){return R.EVENTS[$]}):[];O.pluginEnabled[R.name]=!(R.enabled===!1||R.config.enabled===!1),delete R.enabled,R.methods&&(O.methods[R.name]=Object.keys(R.methods).reduce(function($,ne){var X;return $[ne]=(X=R.methods[ne],function(){for(var se=Array.prototype.slice.call(arguments),te=new Array(X.length),ae=0;ae<se.length;ae++)te[ae]=se[ae];return te[te.length]=S,X.apply({instance:S},te)}),$},{}),delete R.methods);var D=Object.keys(R).concat(J),K=new Set(O.events.concat(D));if(O.events=Array.from(K),O.pluginsArray=O.pluginsArray.concat(R),O.plugins[R.name])throw new Error(R.name+"AlreadyLoaded");return O.plugins[R.name]=R,O.plugins[R.name].loaded||(O.plugins[R.name].loaded=function(){return!0}),O},{plugins:{},pluginEnabled:{},methods:{},pluginsArray:[],middlewares:[],events:[]}),a=e.storage?e.storage:{getItem:Sn,setItem:An,removeItem:Ma},o=function(O){return function(R,J,D){return J.getState("user")[R]||(D&&It(D)&&D[R]?D[R]:wm(O)[R]||Sn(qu(R))||null)}}(a),s=n.plugins,i=n.events.filter(function(O){return!zu.includes(O)}).sort(),l=new Set(i.concat(Ws).filter(function(O){return!zu.includes(O)})),u=Array.from(l).sort(),c=function(){return s},f=new bL,d=f.addMiddleware,p=f.removeMiddleware,b=f.dynamicMiddlewares,h=function(){throw new Error("Abort disabled inListener")},m=aL(),v=wm(a),y=ye({},v,r,m.an_uid?{userId:m.an_uid}:{},m.an_aid?{anonymousId:m.an_aid}:{});y.anonymousId||(y.anonymousId=ac());var w=ye({enable:function(O,R){return new Promise(function(J){V.dispatch({type:ve.enablePlugin,plugins:tu(O),_:{originalAction:ve.enablePlugin}},J,[R])})},disable:function(O,R){return new Promise(function(J){V.dispatch({type:ve.disablePlugin,plugins:tu(O),_:{originalAction:ve.disablePlugin}},J,[R])})}},n.methods),A=!1,S={identify:function(O,R,J,D){try{var K=Yn(O)?O:null,$=It(O)?O:R,ne=J||{},X=S.user();An(qu(kr),K);var se=K||$.userId||o(kr,S,$);return Promise.resolve(new Promise(function(te){V.dispatch(ye({type:ve.identifyStart,userId:se,traits:$||{},options:ne,anonymousId:X.anonymousId},X.id&&X.id!==K&&{previousId:X.id}),te,[R,J,D])}))}catch(te){return Promise.reject(te)}},track:function(O,R,J,D){try{var K=It(O)?O.event:O;if(!K||!Yn(K))throw new Error("EventMissing");var $=It(O)?O:R||{},ne=It(J)?J:{};return Promise.resolve(new Promise(function(X){V.dispatch({type:ve.trackStart,event:K,properties:$,options:ne,userId:o(kr,S,R),anonymousId:o(Un,S,R)},X,[R,J,D])}))}catch(X){return Promise.reject(X)}},page:function(O,R,J){try{var D=It(O)?O:{},K=It(R)?R:{};return Promise.resolve(new Promise(function($){V.dispatch({type:ve.pageStart,properties:AL(D),options:K,userId:o(kr,S,D),anonymousId:o(Un,S,D)},$,[O,R,J])}))}catch($){return Promise.reject($)}},user:function(O){if(O===kr||O==="id")return o(kr,S);if(O===Un||O==="anonId")return o(Un,S);var R=S.getState("user");return O?pm(R,O):R},reset:function(O){return new Promise(function(R){V.dispatch({type:ve.resetStart},R,O)})},ready:function(O){return A&&O({plugins:w,instance:S}),S.on(ve.ready,function(R){O(R),A=!0})},on:function(O,R){if(!O||!sr(R))return!1;if(O===ve.bootstrap)throw new Error(".on disabled for "+O);var J=/Start$|Start:/;if(O==="*"){var D=function(X){return function(se){return function(te){return te.type.match(J)&&R({payload:te,instance:S,plugins:s}),se(te)}}},K=function(X){return function(se){return function(te){return te.type.match(J)||R({payload:te,instance:S,plugins:s}),se(te)}}};return d(D,Ns),d(K,Ms),function(){p(D,Ns),p(K,Ms)}}var $=O.match(J)?Ns:Ms,ne=function(X){return function(se){return function(te){return te.type===O&&R({payload:te,instance:S,plugins:s,abort:h}),se(te)}}};return d(ne,$),function(){return p(ne,$)}},once:function(O,R){if(!O||!sr(R))return!1;if(O===ve.bootstrap)throw new Error(".once disabled for "+O);var J=S.on(O,function(D){R({payload:D.payload,instance:S,plugins:s,abort:h}),J()});return J},getState:function(O){var R=V.getState();return O?pm(R,O):Object.assign({},R)},dispatch:function(O){var R=Yn(O)?{type:O}:O;if(Ws.includes(R.type))throw new Error("reserved action "+R.type);var J=ye({},R,{_:ye({originalAction:R.type},O._||{})});V.dispatch(J)},enablePlugin:w.enable,disablePlugin:w.disable,plugins:w,storage:{getItem:a.getItem,setItem:function(O,R,J){V.dispatch({type:ve.setItemStart,key:O,value:R,options:J})},removeItem:function(O,R){V.dispatch({type:ve.removeItemStart,key:O,options:R})}},setAnonymousId:function(O,R){S.storage.setItem(Vr,O,R)},events:{core:Ws,plugins:i}},E=n.middlewares.concat([function(O){return function(R){return function(J){return J.meta||(J.meta=Tm()),R(J)}}},b(Ns),pL(S,c,{all:u,plugins:i}),hL(a),cL(S),fL(S),b(Ms)]),C={context:CL,user:uL(a),page:OL,track:vL,plugins:mL(c),queue:wL},P=Ca,I=Ca;if(Qt&&e.debug){var T=window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;T&&(P=T({trace:!0,traceLimit:25})),I=function(){return arguments.length===0?fA():It(typeof arguments[0])?Mm():Mm().apply(null,arguments)}}var z,N=function(O){return Object.keys(O).reduce(function(R,J){return IL.includes(J)||(R[J]=O[J]),R},{})}(e),W=n.pluginsArray.reduce(function(O,R){var J=R.name,D=R.config,K=R.loaded,$=n.pluginEnabled[J];return O[J]={enabled:$,initialized:!!$&&!R.initialize,loaded:!!K({config:D}),config:D},O},{}),F={context:N,user:y,plugins:W},V=tA(function(O){for(var R=Object.keys(O),J={},D=0;D<R.length;D++){var K=R[D];typeof O[K]===Pr&&(J[K]=O[K])}var $,ne=Object.keys(J);try{(function(X){Object.keys(X).forEach(function(se){var te=X[se];if(typeof te(void 0,{type:"@@redux/INIT"})===mr||typeof te(void 0,{type:sL})===mr)throw new Error("reducer "+se+" "+mr)})})(J)}catch(X){$=X}return function(X,se){if(X===void 0&&(X={}),$)throw $;for(var te=!1,ae={},ue=0;ue<ne.length;ue++){var de=ne[ue],H=X[de],Q=(0,J[de])(H,se);if(typeof Q===mr){var ge=iL(de,se);throw new Error(ge)}ae[de]=Q,te=te||Q!==H}return te?ae:X}}(ye({},C,t)),F,I(P(lL.apply(void 0,E))));V.dispatch=(z=V.dispatch,function(O,R,J){var D=ye({},O,{meta:Tm(O.meta,R,tu(J))});return z.apply(null,[D])});var _=Object.keys(s);V.dispatch({type:ve.bootstrap,plugins:_,config:N,params:m,user:y,initialUser:r,persistedUser:v});var U=_.filter(function(O){return n.pluginEnabled[O]}),Z=_.filter(function(O){return!n.pluginEnabled[O]});return V.dispatch({type:ve.registerPlugins,plugins:_,enabled:n.pluginEnabled}),n.pluginsArray.map(function(O,R){var J=O.bootstrap,D=O.config,K=O.name;J&&sr(J)&&J({instance:S,config:D,payload:O}),V.dispatch({type:ve.registerPluginType(K),name:K,enabled:n.pluginEnabled[K],plugin:O}),n.pluginsArray.length===R+1&&V.dispatch({type:ve.initializeStart,plugins:U,disabled:Z})}),PL(function(O){V.dispatch({type:O?ve.offline:ve.online})}),function(O,R,J){setInterval(function(){return nA(O,R,J)},3e3)}(V,c,S),S}var Ns="before",Ms="after",oo="cookie",tn=hA(),dA=oc,RL=oc;function pA(e){return tn?oc(e,"",-1):Ma(e)}function hA(){if(tn!==void 0)return tn;var e="cookiecookie";try{oc(e,e),tn=document.cookie.indexOf(e)!==-1,pA(e)}catch{tn=!1}return tn}function oc(e,t,r,n,a,o){if(typeof window<"u"){var s=arguments.length>1;return tn===!1&&(s?An(e,t):Sn(e)),s?document.cookie=e+"="+encodeURIComponent(t)+(r?"; expires="+new Date(+new Date+1e3*r).toUTCString()+(n?"; path="+n:"")+(a?"; domain="+a:"")+(o?"; secure":""):""):decodeURIComponent((("; "+document.cookie).split("; "+e+"=")[1]||"").split(";")[0])}}var so="localStorage",NL=gd.bind(null,"localStorage");Ta("localStorage","getItem",Sn);Ta("localStorage","setItem",An);Ta("localStorage","removeItem",Ma);var io="sessionStorage",ML=gd.bind(null,"sessionStorage");Ta("sessionStorage","getItem",Sn);Ta("sessionStorage","setItem",An);Ta("sessionStorage","removeItem",Ma);function Xn(e){var t=e;try{if((t=JSON.parse(e))==="true")return!0;if(t==="false")return!1;if(It(t))return t;parseFloat(t)===t&&(t=parseFloat(t))}catch{}if(t!==null&&t!=="")return t}var TL=NL(),jL=ML(),zL=hA();function bA(e,t){if(e){var r=vd(t),n=!Ad(r),a=yd(r)?Xn(localStorage.getItem(e)):void 0;if(n&&!Wn(a))return a;var o=wd(r)?Xn(dA(e)):void 0;if(n&&o)return o;var s=Sd(r)?Xn(sessionStorage.getItem(e)):void 0;if(n&&s)return s;var i=Sn(e);return n?i:{localStorage:a,sessionStorage:s,cookie:o,global:i}}}function qL(e,t,r){if(e&&!Wn(t)){var n={},a=vd(r),o=JSON.stringify(t),s=!Ad(a);return yd(a)&&(n[so]=Ts(so,t,Xn(localStorage.getItem(e))),localStorage.setItem(e,o),s)?n[so]:wd(a)&&(n[oo]=Ts(oo,t,Xn(dA(e))),RL(e,o),s)?n[oo]:Sd(a)&&(n[io]=Ts(io,t,Xn(sessionStorage.getItem(e))),sessionStorage.setItem(e,o),s)?n[io]:(n[ao]=Ts(ao,t,Sn(e)),An(e,t),s?n[ao]:n)}}function FL(e,t){if(e){var r=vd(t),n=bA(e,XS),a={};return!Wn(n.localStorage)&&yd(r)&&(localStorage.removeItem(e),a[so]=n.localStorage),!Wn(n.cookie)&&wd(r)&&(pA(e),a[oo]=n.cookie),!Wn(n.sessionStorage)&&Sd(r)&&(sessionStorage.removeItem(e),a[io]=n.sessionStorage),!Wn(n.global)&&sc(r,ao)&&(Ma(e),a[ao]=n.global),a}}function vd(e){return e?Yn(e)?e:e.storage:QS}function yd(e){return TL&&sc(e,so)}function wd(e){return zL&&sc(e,oo)}function Sd(e){return jL&&sc(e,io)}function Ad(e){return e===XS||e==="all"}function sc(e,t){return e===QS||e===t||Ad(e)}function Ts(e,t,r){return{location:e,current:t,previous:r}}var DL={setItem:qL,getItem:bA,removeItem:FL};function BL(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function jm(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable})),r.push.apply(r,n)}return r}function zm(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?jm(Object(r),!0).forEach(function(n){BL(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):jm(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function VL(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t={storage:DL};return xL(zm(zm({},t),e))}const LL="@chaibuilder/sdk",KL="1.0.4",WL="module",UL=["dist"],ZL="dist/core.js",JL=!1,GL={".":{import:"./dist/core.js",require:"./dist/core.cjs",types:"./dist/core.d.ts"},"./render":{import:"./dist/render.js",require:"./dist/render.cjs",types:"./dist/render.d.ts"},"./ui":{import:"./dist/ui.js",require:"./dist/ui.cjs",types:"./dist/ui.d.ts"},"./lib":{import:"./dist/lib.js",require:"./dist/lib.cjs",types:"./dist/lib.d.ts"},"./server":{import:"./dist/server.js",require:"./dist/server.cjs",types:"./dist/server.d.ts"},"./styles":{import:"./dist/style.css",require:"./dist/style.css"}},YL={dev:"vite",build:"tsc && vite build",lint:"eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",preview:"vite preview",test:"jest --colors","test:watch":"jest --watch --colors","test:coverage":"jest --coverage --colors",e2e:"playwright test","e2e:report":"playwright show-report","e2e:ui":"playwright test --ui",docs:"jsdoc -c jsdoc.conf.json"},HL={"@bobthered/tailwindcss-palette-generator":"3.1.1","@chaibuilder/blocks":"^0.2.0","@floating-ui/dom":"1.4.5","@floating-ui/react-dom":"2.0.1","@mhsdesign/jit-browser-tailwindcss":"0.3.0","@minoru/react-dnd-treeview":"3.4.4","@radix-ui/react-accordion":"^1.1.2","@radix-ui/react-alert-dialog":"^1.0.4","@radix-ui/react-context-menu":"^2.1.4","@radix-ui/react-dialog":"^1.0.4","@radix-ui/react-dropdown-menu":"^2.0.5","@radix-ui/react-hover-card":"^1.0.6","@radix-ui/react-icons":"^1.3.0","@radix-ui/react-label":"^2.0.2","@radix-ui/react-menubar":"^1.0.3","@radix-ui/react-navigation-menu":"^1.1.3","@radix-ui/react-popover":"^1.0.6","@radix-ui/react-scroll-area":"^1.0.4","@radix-ui/react-select":"^1.2.2","@radix-ui/react-separator":"^1.0.3","@radix-ui/react-slot":"^1.0.2","@radix-ui/react-switch":"^1.0.3","@radix-ui/react-tabs":"^1.0.4","@radix-ui/react-toast":"^1.1.4","@radix-ui/react-toggle":"^1.0.3","@radix-ui/react-tooltip":"^1.0.6","@react-hookz/web":"23.1.0","@rjsf/core":"5.11.2","@rjsf/utils":"5.11.2","@rjsf/validator-ajv8":"5.11.2","@tailwindcss/aspect-ratio":"0.4.2","@tailwindcss/forms":"^0.5.6","@tailwindcss/line-clamp":"^0.4.4","@tailwindcss/typography":"^0.5.10","@tanstack/react-query":"^5.8.4",analytics:"^0.8.9","class-variance-authority":"0.6.1",clsx:"1.2.1",cmdk:"0.2.0","date-fns":"^2.30.0",flagged:"2.0.9","flat-to-nested":"1.1.1","focus-trap-react":"^10.2.1","forgiving-xml-parser":"1.4.0","framer-motion":"^10.12.18","fuse.js":"6.6.2","gray-matter":"^4.0.3",himalaya:"^1.1.0","html-formatter":"0.1.9",i18next:"^23.2.8",jotai:"2.2.2",lodash:"4.17.21","lucide-react":"^0.244.0",nanoid:"^4.0.2","post-robot":"10.0.46",react:"^18","react-autosuggest":"10.1.0","react-colorful":"5.6.1","react-dnd":"16.0.1","react-dnd-html5-backend":"16.0.1","react-dom":"^18","react-hotkeys-hook":"4.4.1","react-i18next":"13.0.1","react-icons":"^4.10.1","react-icons-picker":"^1.0.9","react-json-view":"^1.21.3","react-quill":"^2.0.0","react-textarea-autosize":"^8.5.2","react-wrap-balancer":"^1.0.0","redux-undo":"1.1.0",sonner:"^1.2.0","tailwind-merge":"1.13.2","tailwindcss-animate":"1.0.6","tippy.js":"^6.3.7","unist-util-visit":"^4.1.2","unsplash-js":"^7.0.18"},QL={"@commitlint/cli":"17.7.1","@commitlint/config-conventional":"17.7.0","@emotion/react":"^11.11.1","@faker-js/faker":"^8.3.1","@nozbe/watermelondb":"^0.27.1","@playwright/test":"^1.39.0","@tanstack/eslint-plugin-query":"^5.8.4","@testing-library/react-hooks":"^8.0.1","@types/better-sqlite3":"^7.6.7","@types/jest":"^29.5.7","@types/lodash":"^4.14.200","@types/node":"^20.8.10","@types/react":"^18.2.15","@types/react-dom":"^18.2.7","@typescript-eslint/eslint-plugin":"^6.0.0","@typescript-eslint/parser":"^6.0.0","@vitejs/plugin-react-swc":"^3.3.2",autoprefixer:"^10.4.16","better-docs":"^2.7.2","better-sqlite3":"^9.1.1","drizzle-kit":"^0.20.4","drizzle-orm":"^0.29.0",eslint:"^8.45.0","eslint-plugin-react-hooks":"^4.6.0","eslint-plugin-react-refresh":"^0.4.3",jest:"^29.7.0","jest-environment-jsdom":"^29.7.0","jotai-devtools":"^0.7.1",jsdoc:"^4.0.2",msw:"^2.0.8",postcss:"^8.4.31",prettier:"^3.0.3","prettier-plugin-tailwindcss":"^0.5.6","prop-types":"^15.8.1","react-router-dom":"^6.19.0",tailwindcss:"^3.3.5","ts-jest":"^29.1.1",typescript:"^5.0.2",vite:"^4.4.5","vite-plugin-dts":"^3.6.3"},XL={workerDirectory:"public"},_L={name:LL,private:!1,version:KL,type:WL,files:UL,main:ZL,sideEffects:JL,exports:GL,scripts:YL,dependencies:HL,devDependencies:QL,msw:XL},qm="https://api.chaibuilder.com",Fm=()=>typeof window>"u"?!1:window.location.href.includes("localhost");function $L(){return{name:"chaibuilder-analytics",config:{},initialize:()=>{if(typeof window>"u")return!1;window.chaibuilderAnalyticsLoaded=!0},page:e=>{if(typeof window>"u")return!1;if(Fm())return;const{payload:t}=e;fetch(`${qm}/v1/log`,{method:"post",body:JSON.stringify(t)}).then(r=>r.json())},track:({payload:e})=>{if(typeof window>"u")return!1;Fm()||fetch(`${qm}/v1/log`,{method:"post",body:JSON.stringify(e)})},loaded:()=>typeof window>"u"?!0:!!window.chaibuilderAnalyticsLoaded}}const eK=VL({app:"chaibuilder",version:_L.version,plugins:[$L()]});({}).NODE_ENV==="development"&&console.log("Chai Builder:",QA);const tK=e=>ee.jsxRuntimeExports.jsx(ee.jsxRuntimeExports.Fragment,{children:e.children}),rK=e=>{const{dndOptions:t={backend:Pd.MultiBackend}}=e,[r]=dS(),[,n]=ld(),a=md();return g.useEffect(()=>{dm.set(je.chaiBuilderPropsAtom,B.omit(e,["blocks","subPages","brandingOptions","dataProvidersAtom"]))},[e]),g.useEffect(()=>{dm.set(dd,e.dataProviders||[])},[e.dataProviders]),g.useEffect(()=>{r(sg.syncBlocksWithDefaults(e.blocks||[])),a()},[e.blocks]),g.useEffect(()=>{n(e.brandingOptions)},[e.brandingOptions,n]),g.useEffect(()=>{eK.page()},[]),ee.jsxRuntimeExports.jsx(VA.DndProvider,{...t,options:Pd.getBackendOptions(),children:ee.jsxRuntimeExports.jsx(tK,{children:ee.jsxRuntimeExports.jsx(ZV,{})})})},mA=e=>ee.jsxRuntimeExports.jsxs(sS,{children:[ee.jsxRuntimeExports.jsxs(BA.FlagsProvider,{features:uB,children:[ee.jsxRuntimeExports.jsx(cB,{}),ee.jsxRuntimeExports.jsx(rK,{...e})]}),ee.jsxRuntimeExports.jsx(je.Toaster,{})]});var ja=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},Ia=typeof window>"u"||"Deno"in window;function Vt(){}function nK(e,t){return typeof e=="function"?e(t):e}function Fu(e){return typeof e=="number"&&e>=0&&e!==1/0}function gA(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Dm(e,t){const{type:r="all",exact:n,fetchStatus:a,predicate:o,queryKey:s,stale:i}=e;if(s){if(n){if(t.queryHash!==Ed(s,t.options))return!1}else if(!vo(t.queryKey,s))return!1}if(r!=="all"){const l=t.isActive();if(r==="active"&&!l||r==="inactive"&&l)return!1}return!(typeof i=="boolean"&&t.isStale()!==i||typeof a<"u"&&a!==t.state.fetchStatus||o&&!o(t))}function Bm(e,t){const{exact:r,status:n,predicate:a,mutationKey:o}=e;if(o){if(!t.options.mutationKey)return!1;if(r){if(go(t.options.mutationKey)!==go(o))return!1}else if(!vo(t.options.mutationKey,o))return!1}return!(n&&t.state.status!==n||a&&!a(t))}function Ed(e,t){return((t==null?void 0:t.queryKeyHashFn)||go)(e)}function go(e){return JSON.stringify(e,(t,r)=>Du(r)?Object.keys(r).sort().reduce((n,a)=>(n[a]=r[a],n),{}):r)}function vo(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(r=>!vo(e[r],t[r])):!1}function vA(e,t){if(e===t)return e;const r=Vm(e)&&Vm(t);if(r||Du(e)&&Du(t)){const n=r?e.length:Object.keys(e).length,a=r?t:Object.keys(t),o=a.length,s=r?[]:{};let i=0;for(let l=0;l<o;l++){const u=r?l:a[l];s[u]=vA(e[u],t[u]),s[u]===e[u]&&i++}return n===o&&i===n?e:s}return t}function wl(e,t){if(e&&!t||t&&!e)return!1;for(const r in e)if(e[r]!==t[r])return!1;return!0}function Vm(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function Du(e){if(!Lm(e))return!1;const t=e.constructor;if(typeof t>"u")return!0;const r=t.prototype;return!(!Lm(r)||!r.hasOwnProperty("isPrototypeOf"))}function Lm(e){return Object.prototype.toString.call(e)==="[object Object]"}function yA(e){return new Promise(t=>{setTimeout(t,e)})}function Km(e){yA(0).then(e)}function Bu(e,t,r){return typeof r.structuralSharing=="function"?r.structuralSharing(e,t):r.structuralSharing!==!1?vA(e,t):t}function aK(e,t,r=0){const n=[...e,t];return r&&n.length>r?n.slice(1):n}function oK(e,t,r=0){const n=[t,...e];return r&&n.length>r?n.slice(0,-1):n}var an,xr,_n,Gm,sK=(Gm=class extends ja{constructor(){super();fe(this,an,void 0);fe(this,xr,void 0);fe(this,_n,void 0);ie(this,_n,t=>{if(!Ia&&window.addEventListener){const r=()=>t();return window.addEventListener("visibilitychange",r,!1),()=>{window.removeEventListener("visibilitychange",r)}}})}onSubscribe(){x(this,xr)||this.setEventListener(x(this,_n))}onUnsubscribe(){var t;this.hasListeners()||((t=x(this,xr))==null||t.call(this),ie(this,xr,void 0))}setEventListener(t){var r;ie(this,_n,t),(r=x(this,xr))==null||r.call(this),ie(this,xr,t(n=>{typeof n=="boolean"?this.setFocused(n):this.onFocus()}))}setFocused(t){x(this,an)!==t&&(ie(this,an,t),this.onFocus())}onFocus(){this.listeners.forEach(t=>{t()})}isFocused(){var t;return typeof x(this,an)=="boolean"?x(this,an):((t=globalThis.document)==null?void 0:t.visibilityState)!=="hidden"}},an=new WeakMap,xr=new WeakMap,_n=new WeakMap,Gm),Sl=new sK,$n,Rr,ea,Ym,iK=(Ym=class extends ja{constructor(){super();fe(this,$n,!0);fe(this,Rr,void 0);fe(this,ea,void 0);ie(this,ea,t=>{if(!Ia&&window.addEventListener){const r=()=>t(!0),n=()=>t(!1);return window.addEventListener("online",r,!1),window.addEventListener("offline",n,!1),()=>{window.removeEventListener("online",r),window.removeEventListener("offline",n)}}})}onSubscribe(){x(this,Rr)||this.setEventListener(x(this,ea))}onUnsubscribe(){var t;this.hasListeners()||((t=x(this,Rr))==null||t.call(this),ie(this,Rr,void 0))}setEventListener(t){var r;ie(this,ea,t),(r=x(this,Rr))==null||r.call(this),ie(this,Rr,t(this.setOnline.bind(this)))}setOnline(t){x(this,$n)!==t&&(ie(this,$n,t),this.listeners.forEach(n=>{n(t)}))}isOnline(){return x(this,$n)}},$n=new WeakMap,Rr=new WeakMap,ea=new WeakMap,Ym),Al=new iK;function lK(e){return Math.min(1e3*2**e,3e4)}function ic(e){return(e??"online")==="online"?Al.isOnline():!0}var wA=class{constructor(e){this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}};function ru(e){return e instanceof wA}function SA(e){let t=!1,r=0,n=!1,a,o,s;const i=new Promise((m,v)=>{o=m,s=v}),l=m=>{var v;n||(p(new wA(m)),(v=e.abort)==null||v.call(e))},u=()=>{t=!0},c=()=>{t=!1},f=()=>!Sl.isFocused()||e.networkMode!=="always"&&!Al.isOnline(),d=m=>{var v;n||(n=!0,(v=e.onSuccess)==null||v.call(e,m),a==null||a(),o(m))},p=m=>{var v;n||(n=!0,(v=e.onError)==null||v.call(e,m),a==null||a(),s(m))},b=()=>new Promise(m=>{var v;a=y=>{const w=n||!f();return w&&m(y),w},(v=e.onPause)==null||v.call(e)}).then(()=>{var m;a=void 0,n||(m=e.onContinue)==null||m.call(e)}),h=()=>{if(n)return;let m;try{m=e.fn()}catch(v){m=Promise.reject(v)}Promise.resolve(m).then(d).catch(v=>{var E;if(n)return;const y=e.retry??(Ia?0:3),w=e.retryDelay??lK,A=typeof w=="function"?w(r,v):w,S=y===!0||typeof y=="number"&&r<y||typeof y=="function"&&y(r,v);if(t||!S){p(v);return}r++,(E=e.onFail)==null||E.call(e,r,v),yA(A).then(()=>{if(f())return b()}).then(()=>{t?p(v):h()})})};return ic(e.networkMode)?h():b().then(h),{promise:i,cancel:l,continue:()=>(a==null?void 0:a())?i:Promise.resolve(),cancelRetry:u,continueRetry:c}}function cK(){let e=[],t=0,r=c=>{c()},n=c=>{c()};const a=c=>{let f;t++;try{f=c()}finally{t--,t||i()}return f},o=c=>{t?e.push(c):Km(()=>{r(c)})},s=c=>(...f)=>{o(()=>{c(...f)})},i=()=>{const c=e;e=[],c.length&&Km(()=>{n(()=>{c.forEach(f=>{r(f)})})})};return{batch:a,batchCalls:s,schedule:o,setNotifyFunction:c=>{r=c},setBatchNotifyFunction:c=>{n=c}}}var Xe=cK(),on,Hm,AA=(Hm=class{constructor(){fe(this,on,void 0)}destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Fu(this.gcTime)&&ie(this,on,setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(Ia?1/0:5*60*1e3))}clearGcTimeout(){x(this,on)&&(clearTimeout(x(this,on)),ie(this,on,void 0))}},on=new WeakMap,Hm),ta,ra,qt,Nr,Ft,$e,yo,sn,na,Us,Yt,dr,Qm,uK=(Qm=class extends AA{constructor(t){super();fe(this,na);fe(this,Yt);fe(this,ta,void 0);fe(this,ra,void 0);fe(this,qt,void 0);fe(this,Nr,void 0);fe(this,Ft,void 0);fe(this,$e,void 0);fe(this,yo,void 0);fe(this,sn,void 0);ie(this,sn,!1),ie(this,yo,t.defaultOptions),Se(this,na,Us).call(this,t.options),ie(this,$e,[]),ie(this,qt,t.cache),this.queryKey=t.queryKey,this.queryHash=t.queryHash,ie(this,ta,t.state||fK(this.options)),this.state=x(this,ta),this.scheduleGc()}get meta(){return this.options.meta}optionalRemove(){!x(this,$e).length&&this.state.fetchStatus==="idle"&&x(this,qt).remove(this)}setData(t,r){const n=Bu(this.state.data,t,this.options);return Se(this,Yt,dr).call(this,{data:n,type:"success",dataUpdatedAt:r==null?void 0:r.updatedAt,manual:r==null?void 0:r.manual}),n}setState(t,r){Se(this,Yt,dr).call(this,{type:"setState",state:t,setStateOptions:r})}cancel(t){var n;const r=x(this,Nr);return(n=x(this,Ft))==null||n.cancel(t),r?r.then(Vt).catch(Vt):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(x(this,ta))}isActive(){return x(this,$e).some(t=>t.options.enabled!==!1)}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return this.state.isInvalidated||!this.state.dataUpdatedAt||x(this,$e).some(t=>t.getCurrentResult().isStale)}isStaleByTime(t=0){return this.state.isInvalidated||!this.state.dataUpdatedAt||!gA(this.state.dataUpdatedAt,t)}onFocus(){var r;const t=x(this,$e).find(n=>n.shouldFetchOnWindowFocus());t==null||t.refetch({cancelRefetch:!1}),(r=x(this,Ft))==null||r.continue()}onOnline(){var r;const t=x(this,$e).find(n=>n.shouldFetchOnReconnect());t==null||t.refetch({cancelRefetch:!1}),(r=x(this,Ft))==null||r.continue()}addObserver(t){x(this,$e).includes(t)||(x(this,$e).push(t),this.clearGcTimeout(),x(this,qt).notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){x(this,$e).includes(t)&&(ie(this,$e,x(this,$e).filter(r=>r!==t)),x(this,$e).length||(x(this,Ft)&&(x(this,sn)?x(this,Ft).cancel({revert:!0}):x(this,Ft).cancelRetry()),this.scheduleGc()),x(this,qt).notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return x(this,$e).length}invalidate(){this.state.isInvalidated||Se(this,Yt,dr).call(this,{type:"invalidate"})}fetch(t,r){var u,c,f,d;if(this.state.fetchStatus!=="idle"){if(this.state.dataUpdatedAt&&(r!=null&&r.cancelRefetch))this.cancel({silent:!0});else if(x(this,Nr))return(u=x(this,Ft))==null||u.continueRetry(),x(this,Nr)}if(t&&Se(this,na,Us).call(this,t),!this.options.queryFn){const p=x(this,$e).find(b=>b.options.queryFn);p&&Se(this,na,Us).call(this,p.options)}process.env.NODE_ENV!=="production"&&(Array.isArray(this.options.queryKey)||console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"));const n=new AbortController,a={queryKey:this.queryKey,meta:this.meta},o=p=>{Object.defineProperty(p,"signal",{enumerable:!0,get:()=>(ie(this,sn,!0),n.signal)})};o(a);const s=()=>this.options.queryFn?(ie(this,sn,!1),this.options.persister?this.options.persister(this.options.queryFn,a,this):this.options.queryFn(a)):Promise.reject(new Error(`Missing queryFn: '${this.options.queryHash}'`)),i={fetchOptions:r,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:s};o(i),(c=this.options.behavior)==null||c.onFetch(i,this),ie(this,ra,this.state),(this.state.fetchStatus==="idle"||this.state.fetchMeta!==((f=i.fetchOptions)==null?void 0:f.meta))&&Se(this,Yt,dr).call(this,{type:"fetch",meta:(d=i.fetchOptions)==null?void 0:d.meta});const l=p=>{var b,h,m,v;ru(p)&&p.silent||Se(this,Yt,dr).call(this,{type:"error",error:p}),ru(p)||((h=(b=x(this,qt).config).onError)==null||h.call(b,p,this),(v=(m=x(this,qt).config).onSettled)==null||v.call(m,this.state.data,p,this)),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1};return ie(this,Ft,SA({fn:i.fetchFn,abort:n.abort.bind(n),onSuccess:p=>{var b,h,m,v;if(typeof p>"u"){process.env.NODE_ENV!=="production"&&console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`),l(new Error(`${this.queryHash} data is undefined`));return}this.setData(p),(h=(b=x(this,qt).config).onSuccess)==null||h.call(b,p,this),(v=(m=x(this,qt).config).onSettled)==null||v.call(m,p,this.state.error,this),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1},onError:l,onFail:(p,b)=>{Se(this,Yt,dr).call(this,{type:"failed",failureCount:p,error:b})},onPause:()=>{Se(this,Yt,dr).call(this,{type:"pause"})},onContinue:()=>{Se(this,Yt,dr).call(this,{type:"continue"})},retry:i.options.retry,retryDelay:i.options.retryDelay,networkMode:i.options.networkMode})),ie(this,Nr,x(this,Ft).promise),x(this,Nr)}},ta=new WeakMap,ra=new WeakMap,qt=new WeakMap,Nr=new WeakMap,Ft=new WeakMap,$e=new WeakMap,yo=new WeakMap,sn=new WeakMap,na=new WeakSet,Us=function(t){this.options={...x(this,yo),...t},this.updateGcTime(this.options.gcTime)},Yt=new WeakSet,dr=function(t){const r=n=>{switch(t.type){case"failed":return{...n,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...n,fetchStatus:"paused"};case"continue":return{...n,fetchStatus:"fetching"};case"fetch":return{...n,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:t.meta??null,fetchStatus:ic(this.options.networkMode)?"fetching":"paused",...!n.dataUpdatedAt&&{error:null,status:"pending"}};case"success":return{...n,data:t.data,dataUpdateCount:n.dataUpdateCount+1,dataUpdatedAt:t.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":const a=t.error;return ru(a)&&a.revert&&x(this,ra)?{...x(this,ra),fetchStatus:"idle"}:{...n,error:a,errorUpdateCount:n.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:n.fetchFailureCount+1,fetchFailureReason:a,fetchStatus:"idle",status:"error"};case"invalidate":return{...n,isInvalidated:!0};case"setState":return{...n,...t.state}}};this.state=r(this.state),Xe.batch(()=>{x(this,$e).forEach(n=>{n.onQueryUpdate()}),x(this,qt).notify({query:this,type:"updated",action:t})})},Qm);function fK(e){const t=typeof e.initialData=="function"?e.initialData():e.initialData,r=typeof t<"u",n=r?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:r?n??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:r?"success":"pending",fetchStatus:"idle"}}var $t,Xm,dK=(Xm=class extends ja{constructor(t={}){super();fe(this,$t,void 0);this.config=t,ie(this,$t,new Map)}build(t,r,n){const a=r.queryKey,o=r.queryHash??Ed(a,r);let s=this.get(o);return s||(s=new uK({cache:this,queryKey:a,queryHash:o,options:t.defaultQueryOptions(r),state:n,defaultOptions:t.getQueryDefaults(a)}),this.add(s)),s}add(t){x(this,$t).has(t.queryHash)||(x(this,$t).set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const r=x(this,$t).get(t.queryHash);r&&(t.destroy(),r===t&&x(this,$t).delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){Xe.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return x(this,$t).get(t)}getAll(){return[...x(this,$t).values()]}find(t){const r={exact:!0,...t};return this.getAll().find(n=>Dm(r,n))}findAll(t={}){const r=this.getAll();return Object.keys(t).length>0?r.filter(n=>Dm(t,n)):r}notify(t){Xe.batch(()=>{this.listeners.forEach(r=>{r(t)})})}onFocus(){Xe.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){Xe.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},$t=new WeakMap,Xm),er,wo,Ct,aa,tr,Ir,_m,pK=(_m=class extends AA{constructor(t){super();fe(this,tr);fe(this,er,void 0);fe(this,wo,void 0);fe(this,Ct,void 0);fe(this,aa,void 0);this.mutationId=t.mutationId,ie(this,wo,t.defaultOptions),ie(this,Ct,t.mutationCache),ie(this,er,[]),this.state=t.state||EA(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options={...x(this,wo),...t},this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){x(this,er).includes(t)||(x(this,er).push(t),this.clearGcTimeout(),x(this,Ct).notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){ie(this,er,x(this,er).filter(r=>r!==t)),this.scheduleGc(),x(this,Ct).notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){x(this,er).length||(this.state.status==="pending"?this.scheduleGc():x(this,Ct).remove(this))}continue(){var t;return((t=x(this,aa))==null?void 0:t.continue())??this.execute(this.state.variables)}async execute(t){var a,o,s,i,l,u,c,f,d,p,b,h,m,v,y,w,A,S,E,C;const r=()=>(ie(this,aa,SA({fn:()=>this.options.mutationFn?this.options.mutationFn(t):Promise.reject(new Error("No mutationFn found")),onFail:(P,I)=>{Se(this,tr,Ir).call(this,{type:"failed",failureCount:P,error:I})},onPause:()=>{Se(this,tr,Ir).call(this,{type:"pause"})},onContinue:()=>{Se(this,tr,Ir).call(this,{type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode})),x(this,aa).promise),n=this.state.status==="pending";try{if(!n){Se(this,tr,Ir).call(this,{type:"pending",variables:t}),await((o=(a=x(this,Ct).config).onMutate)==null?void 0:o.call(a,t,this));const I=await((i=(s=this.options).onMutate)==null?void 0:i.call(s,t));I!==this.state.context&&Se(this,tr,Ir).call(this,{type:"pending",context:I,variables:t})}const P=await r();return await((u=(l=x(this,Ct).config).onSuccess)==null?void 0:u.call(l,P,t,this.state.context,this)),await((f=(c=this.options).onSuccess)==null?void 0:f.call(c,P,t,this.state.context)),await((p=(d=x(this,Ct).config).onSettled)==null?void 0:p.call(d,P,null,this.state.variables,this.state.context,this)),await((h=(b=this.options).onSettled)==null?void 0:h.call(b,P,null,t,this.state.context)),Se(this,tr,Ir).call(this,{type:"success",data:P}),P}catch(P){try{throw await((v=(m=x(this,Ct).config).onError)==null?void 0:v.call(m,P,t,this.state.context,this)),await((w=(y=this.options).onError)==null?void 0:w.call(y,P,t,this.state.context)),await((S=(A=x(this,Ct).config).onSettled)==null?void 0:S.call(A,void 0,P,this.state.variables,this.state.context,this)),await((C=(E=this.options).onSettled)==null?void 0:C.call(E,void 0,P,t,this.state.context)),P}finally{Se(this,tr,Ir).call(this,{type:"error",error:P})}}}},er=new WeakMap,wo=new WeakMap,Ct=new WeakMap,aa=new WeakMap,tr=new WeakSet,Ir=function(t){const r=n=>{switch(t.type){case"failed":return{...n,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...n,isPaused:!0};case"continue":return{...n,isPaused:!1};case"pending":return{...n,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:!ic(this.options.networkMode),status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...n,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...n,data:void 0,error:t.error,failureCount:n.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=r(this.state),Xe.batch(()=>{x(this,er).forEach(n=>{n.onMutationUpdate(t)}),x(this,Ct).notify({mutation:this,type:"updated",action:t})})},_m);function EA(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var Dt,So,ln,$m,hK=($m=class extends ja{constructor(t={}){super();fe(this,Dt,void 0);fe(this,So,void 0);fe(this,ln,void 0);this.config=t,ie(this,Dt,[]),ie(this,So,0)}build(t,r,n){const a=new pK({mutationCache:this,mutationId:++ns(this,So)._,options:t.defaultMutationOptions(r),state:n});return this.add(a),a}add(t){x(this,Dt).push(t),this.notify({type:"added",mutation:t})}remove(t){ie(this,Dt,x(this,Dt).filter(r=>r!==t)),this.notify({type:"removed",mutation:t})}clear(){Xe.batch(()=>{x(this,Dt).forEach(t=>{this.remove(t)})})}getAll(){return x(this,Dt)}find(t){const r={exact:!0,...t};return x(this,Dt).find(n=>Bm(r,n))}findAll(t={}){return x(this,Dt).filter(r=>Bm(t,r))}notify(t){Xe.batch(()=>{this.listeners.forEach(r=>{r(t)})})}resumePausedMutations(){return ie(this,ln,(x(this,ln)??Promise.resolve()).then(()=>{const t=x(this,Dt).filter(r=>r.state.isPaused);return Xe.batch(()=>t.reduce((r,n)=>r.then(()=>n.continue().catch(Vt)),Promise.resolve()))}).then(()=>{ie(this,ln,void 0)})),x(this,ln)}},Dt=new WeakMap,So=new WeakMap,ln=new WeakMap,$m);function bK(e){return{onFetch:(t,r)=>{const n=async()=>{var b,h,m,v,y;const a=t.options,o=(m=(h=(b=t.fetchOptions)==null?void 0:b.meta)==null?void 0:h.fetchMore)==null?void 0:m.direction,s=((v=t.state.data)==null?void 0:v.pages)||[],i=((y=t.state.data)==null?void 0:y.pageParams)||[],l={pages:[],pageParams:[]};let u=!1;const c=w=>{Object.defineProperty(w,"signal",{enumerable:!0,get:()=>(t.signal.aborted?u=!0:t.signal.addEventListener("abort",()=>{u=!0}),t.signal)})},f=t.options.queryFn||(()=>Promise.reject(new Error(`Missing queryFn: '${t.options.queryHash}'`))),d=async(w,A,S)=>{if(u)return Promise.reject();if(A==null&&w.pages.length)return Promise.resolve(w);const E={queryKey:t.queryKey,pageParam:A,direction:S?"backward":"forward",meta:t.options.meta};c(E);const C=await f(E),{maxPages:P}=t.options,I=S?oK:aK;return{pages:I(w.pages,C,P),pageParams:I(w.pageParams,A,P)}};let p;if(o&&s.length){const w=o==="backward",A=w?mK:Wm,S={pages:s,pageParams:i},E=A(a,S);p=await d(S,E,w)}else{p=await d(l,i[0]??a.initialPageParam);const w=e??s.length;for(let A=1;A<w;A++){const S=Wm(a,p);p=await d(p,S)}}return p};t.options.persister?t.fetchFn=()=>{var a,o;return(o=(a=t.options).persister)==null?void 0:o.call(a,n,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},r)}:t.fetchFn=n}}}function Wm(e,{pages:t,pageParams:r}){const n=t.length-1;return e.getNextPageParam(t[n],t,r[n],r)}function mK(e,{pages:t,pageParams:r}){var n;return(n=e.getPreviousPageParam)==null?void 0:n.call(e,t[0],t,r[0],r)}var Ye,Mr,Tr,oa,sa,jr,ia,la,eg,gK=(eg=class{constructor(e={}){fe(this,Ye,void 0);fe(this,Mr,void 0);fe(this,Tr,void 0);fe(this,oa,void 0);fe(this,sa,void 0);fe(this,jr,void 0);fe(this,ia,void 0);fe(this,la,void 0);ie(this,Ye,e.queryCache||new dK),ie(this,Mr,e.mutationCache||new hK),ie(this,Tr,e.defaultOptions||{}),ie(this,oa,new Map),ie(this,sa,new Map),ie(this,jr,0)}mount(){ns(this,jr)._++,x(this,jr)===1&&(ie(this,ia,Sl.subscribe(()=>{Sl.isFocused()&&(this.resumePausedMutations(),x(this,Ye).onFocus())})),ie(this,la,Al.subscribe(()=>{Al.isOnline()&&(this.resumePausedMutations(),x(this,Ye).onOnline())})))}unmount(){var e,t;ns(this,jr)._--,x(this,jr)===0&&((e=x(this,ia))==null||e.call(this),ie(this,ia,void 0),(t=x(this,la))==null||t.call(this),ie(this,la,void 0))}isFetching(e){return x(this,Ye).findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return x(this,Mr).findAll({...e,status:"pending"}).length}getQueryData(e){var t;return(t=x(this,Ye).find({queryKey:e}))==null?void 0:t.state.data}ensureQueryData(e){const t=this.getQueryData(e.queryKey);return t!==void 0?Promise.resolve(t):this.fetchQuery(e)}getQueriesData(e){return this.getQueryCache().findAll(e).map(({queryKey:t,state:r})=>{const n=r.data;return[t,n]})}setQueryData(e,t,r){const n=x(this,Ye).find({queryKey:e}),a=n==null?void 0:n.state.data,o=nK(t,a);if(typeof o>"u")return;const s=this.defaultQueryOptions({queryKey:e});return x(this,Ye).build(this,s).setData(o,{...r,manual:!0})}setQueriesData(e,t,r){return Xe.batch(()=>this.getQueryCache().findAll(e).map(({queryKey:n})=>[n,this.setQueryData(n,t,r)]))}getQueryState(e){var t;return(t=x(this,Ye).find({queryKey:e}))==null?void 0:t.state}removeQueries(e){const t=x(this,Ye);Xe.batch(()=>{t.findAll(e).forEach(r=>{t.remove(r)})})}resetQueries(e,t){const r=x(this,Ye),n={type:"active",...e};return Xe.batch(()=>(r.findAll(e).forEach(a=>{a.reset()}),this.refetchQueries(n,t)))}cancelQueries(e={},t={}){const r={revert:!0,...t},n=Xe.batch(()=>x(this,Ye).findAll(e).map(a=>a.cancel(r)));return Promise.all(n).then(Vt).catch(Vt)}invalidateQueries(e={},t={}){return Xe.batch(()=>{if(x(this,Ye).findAll(e).forEach(n=>{n.invalidate()}),e.refetchType==="none")return Promise.resolve();const r={...e,type:e.refetchType??e.type??"active"};return this.refetchQueries(r,t)})}refetchQueries(e={},t){const r={...t,cancelRefetch:(t==null?void 0:t.cancelRefetch)??!0},n=Xe.batch(()=>x(this,Ye).findAll(e).filter(a=>!a.isDisabled()).map(a=>{let o=a.fetch(void 0,r);return r.throwOnError||(o=o.catch(Vt)),a.state.fetchStatus==="paused"?Promise.resolve():o}));return Promise.all(n).then(Vt)}fetchQuery(e){const t=this.defaultQueryOptions(e);typeof t.retry>"u"&&(t.retry=!1);const r=x(this,Ye).build(this,t);return r.isStaleByTime(t.staleTime)?r.fetch(t):Promise.resolve(r.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Vt).catch(Vt)}fetchInfiniteQuery(e){return e.behavior=bK(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Vt).catch(Vt)}resumePausedMutations(){return x(this,Mr).resumePausedMutations()}getQueryCache(){return x(this,Ye)}getMutationCache(){return x(this,Mr)}getDefaultOptions(){return x(this,Tr)}setDefaultOptions(e){ie(this,Tr,e)}setQueryDefaults(e,t){x(this,oa).set(go(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...x(this,oa).values()];let r={};return t.forEach(n=>{vo(e,n.queryKey)&&(r={...r,...n.defaultOptions})}),r}setMutationDefaults(e,t){x(this,sa).set(go(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...x(this,sa).values()];let r={};return t.forEach(n=>{vo(e,n.mutationKey)&&(r={...r,...n.defaultOptions})}),r}defaultQueryOptions(e){if(e!=null&&e._defaulted)return e;const t={...x(this,Tr).queries,...(e==null?void 0:e.queryKey)&&this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=Ed(t.queryKey,t)),typeof t.refetchOnReconnect>"u"&&(t.refetchOnReconnect=t.networkMode!=="always"),typeof t.throwOnError>"u"&&(t.throwOnError=!!t.suspense),typeof t.networkMode>"u"&&t.persister&&(t.networkMode="offlineFirst"),t}defaultMutationOptions(e){return e!=null&&e._defaulted?e:{...x(this,Tr).mutations,...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){x(this,Ye).clear(),x(this,Mr).clear()}},Ye=new WeakMap,Mr=new WeakMap,Tr=new WeakMap,oa=new WeakMap,sa=new WeakMap,jr=new WeakMap,ia=new WeakMap,la=new WeakMap,eg),mt,Me,ca,ot,cn,ua,rr,Ao,fa,da,un,fn,zr,dn,pn,Qa,Eo,Vu,Oo,Lu,Co,Ku,Io,Wu,ko,Uu,Po,Zu,xo,Ju,El,OA,tg,vK=(tg=class extends ja{constructor(t,r){super();fe(this,pn);fe(this,Eo);fe(this,Oo);fe(this,Co);fe(this,Io);fe(this,ko);fe(this,Po);fe(this,xo);fe(this,El);fe(this,mt,void 0);fe(this,Me,void 0);fe(this,ca,void 0);fe(this,ot,void 0);fe(this,cn,void 0);fe(this,ua,void 0);fe(this,rr,void 0);fe(this,Ao,void 0);fe(this,fa,void 0);fe(this,da,void 0);fe(this,un,void 0);fe(this,fn,void 0);fe(this,zr,void 0);fe(this,dn,void 0);ie(this,Me,void 0),ie(this,ca,void 0),ie(this,ot,void 0),ie(this,dn,new Set),ie(this,mt,t),this.options=r,ie(this,rr,null),this.bindMethods(),this.setOptions(r)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(x(this,Me).addObserver(this),Um(x(this,Me),this.options)?Se(this,pn,Qa).call(this):this.updateResult(),Se(this,Io,Wu).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return Gu(x(this,Me),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return Gu(x(this,Me),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,Se(this,ko,Uu).call(this),Se(this,Po,Zu).call(this),x(this,Me).removeObserver(this)}setOptions(t,r){const n=this.options,a=x(this,Me);if(this.options=x(this,mt).defaultQueryOptions(t),wl(n,this.options)||x(this,mt).getQueryCache().notify({type:"observerOptionsUpdated",query:x(this,Me),observer:this}),typeof this.options.enabled<"u"&&typeof this.options.enabled!="boolean")throw new Error("Expected enabled to be a boolean");this.options.queryKey||(this.options.queryKey=n.queryKey),Se(this,xo,Ju).call(this);const o=this.hasListeners();o&&Zm(x(this,Me),a,this.options,n)&&Se(this,pn,Qa).call(this),this.updateResult(r),o&&(x(this,Me)!==a||this.options.enabled!==n.enabled||this.options.staleTime!==n.staleTime)&&Se(this,Eo,Vu).call(this);const s=Se(this,Oo,Lu).call(this);o&&(x(this,Me)!==a||this.options.enabled!==n.enabled||s!==x(this,zr))&&Se(this,Co,Ku).call(this,s)}getOptimisticResult(t){const r=x(this,mt).getQueryCache().build(x(this,mt),t),n=this.createResult(r,t);return wK(this,n)&&(ie(this,ot,n),ie(this,ua,this.options),ie(this,cn,x(this,Me).state)),n}getCurrentResult(){return x(this,ot)}trackResult(t){const r={};return Object.keys(t).forEach(n=>{Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:()=>(x(this,dn).add(n),t[n])})}),r}getCurrentQuery(){return x(this,Me)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const r=x(this,mt).defaultQueryOptions(t),n=x(this,mt).getQueryCache().build(x(this,mt),r);return n.isFetchingOptimistic=!0,n.fetch().then(()=>this.createResult(n,r))}fetch(t){return Se(this,pn,Qa).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),x(this,ot)))}createResult(t,r){var E;const n=x(this,Me),a=this.options,o=x(this,ot),s=x(this,cn),i=x(this,ua),u=t!==n?t.state:x(this,ca),{state:c}=t;let{error:f,errorUpdatedAt:d,fetchStatus:p,status:b}=c,h=!1,m;if(r._optimisticResults){const C=this.hasListeners(),P=!C&&Um(t,r),I=C&&Zm(t,n,r,a);(P||I)&&(p=ic(t.options.networkMode)?"fetching":"paused",c.dataUpdatedAt||(b="pending")),r._optimisticResults==="isRestoring"&&(p="idle")}if(r.select&&typeof c.data<"u")if(o&&c.data===(s==null?void 0:s.data)&&r.select===x(this,Ao))m=x(this,fa);else try{ie(this,Ao,r.select),m=r.select(c.data),m=Bu(o==null?void 0:o.data,m,r),ie(this,fa,m),ie(this,rr,null)}catch(C){ie(this,rr,C)}else m=c.data;if(typeof r.placeholderData<"u"&&typeof m>"u"&&b==="pending"){let C;if(o!=null&&o.isPlaceholderData&&r.placeholderData===(i==null?void 0:i.placeholderData))C=o.data;else if(C=typeof r.placeholderData=="function"?r.placeholderData((E=x(this,da))==null?void 0:E.state.data,x(this,da)):r.placeholderData,r.select&&typeof C<"u")try{C=r.select(C),ie(this,rr,null)}catch(P){ie(this,rr,P)}typeof C<"u"&&(b="success",m=Bu(o==null?void 0:o.data,C,r),h=!0)}x(this,rr)&&(f=x(this,rr),m=x(this,fa),d=Date.now(),b="error");const v=p==="fetching",y=b==="pending",w=b==="error",A=y&&v;return{status:b,fetchStatus:p,isPending:y,isSuccess:b==="success",isError:w,isInitialLoading:A,isLoading:A,data:m,dataUpdatedAt:c.dataUpdatedAt,error:f,errorUpdatedAt:d,failureCount:c.fetchFailureCount,failureReason:c.fetchFailureReason,errorUpdateCount:c.errorUpdateCount,isFetched:c.dataUpdateCount>0||c.errorUpdateCount>0,isFetchedAfterMount:c.dataUpdateCount>u.dataUpdateCount||c.errorUpdateCount>u.errorUpdateCount,isFetching:v,isRefetching:v&&!y,isLoadingError:w&&c.dataUpdatedAt===0,isPaused:p==="paused",isPlaceholderData:h,isRefetchError:w&&c.dataUpdatedAt!==0,isStale:Od(t,r),refetch:this.refetch}}updateResult(t){const r=x(this,ot),n=this.createResult(x(this,Me),this.options);if(ie(this,cn,x(this,Me).state),ie(this,ua,this.options),x(this,cn).data!==void 0&&ie(this,da,x(this,Me)),wl(n,r))return;ie(this,ot,n);const a={},o=()=>{if(!r)return!0;const{notifyOnChangeProps:s}=this.options,i=typeof s=="function"?s():s;if(i==="all"||!i&&!x(this,dn).size)return!0;const l=new Set(i??x(this,dn));return this.options.throwOnError&&l.add("error"),Object.keys(x(this,ot)).some(u=>{const c=u;return x(this,ot)[c]!==r[c]&&l.has(c)})};(t==null?void 0:t.listeners)!==!1&&o()&&(a.listeners=!0),Se(this,El,OA).call(this,{...a,...t})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&Se(this,Io,Wu).call(this)}},mt=new WeakMap,Me=new WeakMap,ca=new WeakMap,ot=new WeakMap,cn=new WeakMap,ua=new WeakMap,rr=new WeakMap,Ao=new WeakMap,fa=new WeakMap,da=new WeakMap,un=new WeakMap,fn=new WeakMap,zr=new WeakMap,dn=new WeakMap,pn=new WeakSet,Qa=function(t){Se(this,xo,Ju).call(this);let r=x(this,Me).fetch(this.options,t);return t!=null&&t.throwOnError||(r=r.catch(Vt)),r},Eo=new WeakSet,Vu=function(){if(Se(this,ko,Uu).call(this),Ia||x(this,ot).isStale||!Fu(this.options.staleTime))return;const r=gA(x(this,ot).dataUpdatedAt,this.options.staleTime)+1;ie(this,un,setTimeout(()=>{x(this,ot).isStale||this.updateResult()},r))},Oo=new WeakSet,Lu=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(x(this,Me)):this.options.refetchInterval)??!1},Co=new WeakSet,Ku=function(t){Se(this,Po,Zu).call(this),ie(this,zr,t),!(Ia||this.options.enabled===!1||!Fu(x(this,zr))||x(this,zr)===0)&&ie(this,fn,setInterval(()=>{(this.options.refetchIntervalInBackground||Sl.isFocused())&&Se(this,pn,Qa).call(this)},x(this,zr)))},Io=new WeakSet,Wu=function(){Se(this,Eo,Vu).call(this),Se(this,Co,Ku).call(this,Se(this,Oo,Lu).call(this))},ko=new WeakSet,Uu=function(){x(this,un)&&(clearTimeout(x(this,un)),ie(this,un,void 0))},Po=new WeakSet,Zu=function(){x(this,fn)&&(clearInterval(x(this,fn)),ie(this,fn,void 0))},xo=new WeakSet,Ju=function(){const t=x(this,mt).getQueryCache().build(x(this,mt),this.options);if(t===x(this,Me))return;const r=x(this,Me);ie(this,Me,t),ie(this,ca,t.state),this.hasListeners()&&(r==null||r.removeObserver(this),t.addObserver(this))},El=new WeakSet,OA=function(t){Xe.batch(()=>{t.listeners&&this.listeners.forEach(r=>{r(x(this,ot))}),x(this,mt).getQueryCache().notify({query:x(this,Me),type:"observerResultsUpdated"})})},tg);function yK(e,t){return t.enabled!==!1&&!e.state.dataUpdatedAt&&!(e.state.status==="error"&&t.retryOnMount===!1)}function Um(e,t){return yK(e,t)||e.state.dataUpdatedAt>0&&Gu(e,t,t.refetchOnMount)}function Gu(e,t,r){if(t.enabled!==!1){const n=typeof r=="function"?r(e):r;return n==="always"||n!==!1&&Od(e,t)}return!1}function Zm(e,t,r,n){return r.enabled!==!1&&(e!==t||n.enabled===!1)&&(!r.suspense||e.state.status!=="error")&&Od(e,r)}function Od(e,t){return e.isStaleByTime(t.staleTime)}function wK(e,t){return!wl(e.getCurrentResult(),t)}var qr,lt,Bt,hr,pa,Zs,Ro,Yu,rg,SK=(rg=class extends ja{constructor(t,r){super();fe(this,pa);fe(this,Ro);fe(this,qr,void 0);fe(this,lt,void 0);fe(this,Bt,void 0);fe(this,hr,void 0);ie(this,lt,void 0),ie(this,qr,t),this.setOptions(r),this.bindMethods(),Se(this,pa,Zs).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var n;const r=this.options;this.options=x(this,qr).defaultMutationOptions(t),wl(r,this.options)||x(this,qr).getMutationCache().notify({type:"observerOptionsUpdated",mutation:x(this,Bt),observer:this}),(n=x(this,Bt))==null||n.setOptions(this.options)}onUnsubscribe(){var t;this.hasListeners()||(t=x(this,Bt))==null||t.removeObserver(this)}onMutationUpdate(t){Se(this,pa,Zs).call(this),Se(this,Ro,Yu).call(this,t)}getCurrentResult(){return x(this,lt)}reset(){ie(this,Bt,void 0),Se(this,pa,Zs).call(this),Se(this,Ro,Yu).call(this)}mutate(t,r){var n;return ie(this,hr,r),(n=x(this,Bt))==null||n.removeObserver(this),ie(this,Bt,x(this,qr).getMutationCache().build(x(this,qr),this.options)),x(this,Bt).addObserver(this),x(this,Bt).execute(t)}},qr=new WeakMap,lt=new WeakMap,Bt=new WeakMap,hr=new WeakMap,pa=new WeakSet,Zs=function(){var r;const t=((r=x(this,Bt))==null?void 0:r.state)??EA();ie(this,lt,{...t,isPending:t.status==="pending",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset})},Ro=new WeakSet,Yu=function(t){Xe.batch(()=>{var r,n,a,o,s,i,l,u;x(this,hr)&&this.hasListeners()&&((t==null?void 0:t.type)==="success"?((n=(r=x(this,hr)).onSuccess)==null||n.call(r,t.data,x(this,lt).variables,x(this,lt).context),(o=(a=x(this,hr)).onSettled)==null||o.call(a,t.data,null,x(this,lt).variables,x(this,lt).context)):(t==null?void 0:t.type)==="error"&&((i=(s=x(this,hr)).onError)==null||i.call(s,t.error,x(this,lt).variables,x(this,lt).context),(u=(l=x(this,hr)).onSettled)==null||u.call(l,void 0,t.error,x(this,lt).variables,x(this,lt).context))),this.listeners.forEach(c=>{c(x(this,lt))})})},rg),CA=k.createContext(void 0),Mt=e=>{const t=k.useContext(CA);if(e)return e;if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},AK=({client:e,children:t})=>(k.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),k.createElement(CA.Provider,{value:e},t)),IA=k.createContext(!1),EK=()=>k.useContext(IA);IA.Provider;function OK(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var CK=k.createContext(OK()),IK=()=>k.useContext(CK);function kA(e,t){return typeof e=="function"?e(...t):!!e}var kK=(e,t)=>{(e.suspense||e.throwOnError)&&(t.isReset()||(e.retryOnMount=!1))},PK=e=>{k.useEffect(()=>{e.clearReset()},[e])},xK=({result:e,errorResetBoundary:t,throwOnError:r,query:n})=>e.isError&&!t.isReset()&&!e.isFetching&&kA(r,[e.error,n]),RK=e=>{e.suspense&&typeof e.staleTime!="number"&&(e.staleTime=1e3)},NK=(e,t)=>(e==null?void 0:e.suspense)&&t.isPending,MK=(e,t,r)=>t.fetchOptimistic(e).catch(()=>{r.clearReset()});function TK(e,t,r){if(process.env.NODE_ENV!=="production"&&(typeof e!="object"||Array.isArray(e)))throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');const n=Mt(r),a=EK(),o=IK(),s=n.defaultQueryOptions(e);s._optimisticResults=a?"isRestoring":"optimistic",RK(s),kK(s,o),PK(o);const[i]=k.useState(()=>new t(n,s)),l=i.getOptimisticResult(s);if(k.useSyncExternalStore(k.useCallback(u=>{const c=a?()=>{}:i.subscribe(Xe.batchCalls(u));return i.updateResult(),c},[i,a]),()=>i.getCurrentResult(),()=>i.getCurrentResult()),k.useEffect(()=>{i.setOptions(s,{listeners:!1})},[s,i]),NK(s,l))throw MK(s,i,o);if(xK({result:l,errorResetBoundary:o,throwOnError:s.throwOnError,query:i.getCurrentQuery()}))throw l.error;return s.notifyOnChangeProps?l:i.trackResult(l)}function Jo(e,t){return TK(e,vK,t)}function Xt(e,t){const r=Mt(t),[n]=k.useState(()=>new SK(r,e));k.useEffect(()=>{n.setOptions(e)},[n,e]);const a=k.useSyncExternalStore(k.useCallback(s=>n.subscribe(Xe.batchCalls(s)),[n]),()=>n.getCurrentResult(),()=>n.getCurrentResult()),o=k.useCallback((s,i)=>{n.mutate(s,i).catch(jK)},[n]);if(a.error&&kA(n.options.throwOnError,[a.error]))throw a.error;return{...a,mutate:o,mutateAsync:a.mutate}}function jK(){}function it(){return Mt().getQueryData(["apiBaseUrl"])||"/api/chaibuilder"}const Jr=()=>{const{data:e,refetch:t}=Jo({queryKey:["currentPage"],queryFn:()=>localStorage.getItem("currentPage")||""});return[e,r=>{r&&(localStorage.setItem("currentPage",r||""),t())}]};let js="";const Go=()=>js||(js=localStorage.getItem("__chai_at"),js);function zK(e){const t={method:"GET",headers:{"x-chai-access-token":Go()}};return fetch(e,t)}function qK(e,t){const r={method:"POST",headers:{"x-chai-access-token":Go()},body:JSON.stringify(t)};return fetch(e,r)}function FK(e,t){const r={method:"PUT",headers:{"x-chai-access-token":Go()},body:JSON.stringify(t)};return fetch(e,r)}function DK(e,t){const r={method:"DELETE",headers:{"x-chai-access-token":Go()},body:JSON.stringify(t)};return fetch(e,r)}const Tt={get:zK,post:qK,put:FK,delete:DK},lc=()=>{const[e,t]=Jr(),r=it();return Jo({queryKey:["project"],queryFn:async()=>{const{data:n}=await Tt.get(`${r}/project`).then(a=>a.json());if(!e&&n){const a=localStorage.getItem("currentPage");t(a||(n==null?void 0:n.homepage))}return n}})},Cd=()=>{const e=it();return Jo({queryKey:["pages"],queryFn:async()=>{const{data:t}=await Tt.get(`${e}/pages`).then(r=>r.json());return t||[]}})},PA=()=>{const[e,t]=Jr(),{data:r}=lc(),n=it();return Jo({queryKey:["page_data",e],queryFn:async()=>{const{data:a}=await Tt.get(`${n}/page?uuid=${e}`).then(o=>o.json());return a.ok?a.json():(t(r.homepage),null)},enabled:!!e,staleTime:3e3})},Hu=()=>ee.jsxRuntimeExports.jsx("div",{className:"h-screen w-screen bg-gray-200",children:ee.jsxRuntimeExports.jsxs("div",{className:"flex flex-col h-full w-full justify-center items-center",children:[ee.jsxRuntimeExports.jsxs("div",{className:"flex flex-row gap-2",children:[ee.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-orange-600 animate-bounce [animation-delay:.6s]"}),ee.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-blue-600 animate-bounce [animation-delay:.4s]"}),ee.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-green-600 animate-bounce [animation-delay:.2s]"}),ee.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-yellow-600 animate-bounce [animation-delay:.0s]"})]}),ee.jsxRuntimeExports.jsx("div",{className:"text-gray-700 font-thin",children:"Loading Builder..."})]})}),xA=(e="Project updated successfully.")=>{const t=Mt(),r=it();return Xt({mutationFn:async n=>await Tt.put(`${r}/project`,n).then(a=>a.json()),onSuccess:()=>{t.invalidateQueries({queryKey:["project"]}),ir.toast.success(e)}})},RA=()=>{const[e]=["SAVED"],[t,r]=Jr(),n=md();return a=>e!=="SAVED"?(ir.toast.error("You have unsaved changes. Please save before changing the page."),!1):t===a.uuid?!1:(n(),setTimeout(()=>{r(a.uuid)},100),!0)},BK=()=>{const e=Mt(),t=RA(),r=it();return Xt({mutationFn:async n=>Tt.post(`${r}/pages`,n).then(a=>a.json()),onSuccess:n=>{e.invalidateQueries({queryKey:["pages"]}),t({uuid:n.uuid,slug:n.slug}),ir.toast.success("Page added successfully.")}})},NA=()=>{const e=it(),[t]=Jr(),r=Mt();return Xt({mutationFn:async n=>Tt.put(`${e}/page`,n).then(a=>a.json()),onSuccess:async n=>{var o;const a=await n.json();if(a.result==="error"&&((o=a.error)==null?void 0:o.code)=="PAGE_LOCKED"){r.invalidateQueries({queryKey:["page_data",t]});return}ir.toast.success("Page saved successfully.")}})},VK=()=>{const e=it(),{data:t}=Cd(),[r]=Jr(),{data:n}=lc(),a=Mt();return Xt({mutationFn:async()=>{const o=t.find(s=>s.uuid===r).slug;return await Tt.post(`${e}/publish`,{slug:o,uuid:r,isHomepage:(n==null?void 0:n.homepage)===r}).then(s=>s.json())},onSuccess:async o=>{var i;const s=await o.json();if(s.result==="error"&&((i=s.error)==null?void 0:i.code)=="PAGE_LOCKED"){a.invalidateQueries({queryKey:["page_data",r]});return}ir.toast.success("Page published successfully.",{position:"top-right",duration:2e3})}})},LK=()=>{const e=Mt(),t=it();return Xt({mutationFn:async r=>Tt.delete(`${t}/page`,r).then(n=>n.json()),onSuccess:()=>{ir.toast.success("Page deleted successfully."),e.invalidateQueries({queryKey:["pages"]})}})},KK=()=>{const e=Mt(),t=it();return Xt({mutationFn:async r=>Tt.post(`${t}/take-control`,{uuid:r}).then(n=>n.json()),onSuccess:(r,n)=>{e.invalidateQueries({queryKey:["page_data",n]})}})},WK=()=>{const e=it();return Xt({mutationFn:async()=>{const{data:t}=await Tt.get(`${e}/library`).then(r=>r.json());return B.sortBy(B.filter(t,r=>!B.has(r,"hidden")),"group")}})},UK=()=>{const e=it();return Xt({mutationFn:async t=>{if(!t||!t.uuid)return[];try{const{data:r}=await Tt.get(`${e}/block?uuid=${t.uuid}&format=${t.format}`).then(async n=>t.format==="html"?vt.getBlocksFromHTML(await n.text()):await n.json());return B.set(r,"0._name",B.capitalize(t.group)),r||[]}catch{return[]}}})},ZK=()=>{const e=it();return Xt({mutationFn:async t=>{const r=new FormData;r.append("file",t);const{data:n}=await fetch(`${e}/upload`,{method:"POST",headers:{"x-chai-access-token":Go()},body:r}).then(a=>a.json());return n}})},JK=()=>{const{mutate:e,isPending:t}=KK(),[r]=Jr(),{data:n}=PA(),a=B.get(n,"lockedBy.name",""),o=B.get(n,"lockedBy.email","");return ee.jsxRuntimeExports.jsxs("div",{className:"p-5 w-fit text-center bg-white mx-auto border rounded-md shadow-xl text-red-500",children:["This page is currently locked for editing by another user. ",ee.jsxRuntimeExports.jsx("br",{}),' If you take over editing, "',a,"<",o,'>" will be blocked from editing.',ee.jsxRuntimeExports.jsx("br",{})," ",ee.jsxRuntimeExports.jsx("br",{}),ee.jsxRuntimeExports.jsx(je.Button,{disabled:t,onClick:()=>e(r),children:t?"Processing...":"Take Over"})," "]})},GK=()=>{const e=it(),t=Mt();return Xt({mutationFn:async r=>{const n=await fetch(`${e}/login`,{method:"POST",body:JSON.stringify(r)});if(n.ok)return await n.json();throw n.status===401?new Error("Invalid login credentials"):new Error("Invalid")},onSuccess:r=>{if(!r.accessToken){ir.toast.error("Something went wrong. Please try again.",{position:"top-center"});return}localStorage.setItem("__chai_at",r.accessToken),localStorage.setItem("__chai_ur",JSON.stringify(B.omit(r,["accessToken"]))),t.invalidateQueries({queryKey:["verify"]}),ir.toast.success("Logged in successfully.")},onError:()=>{ir.toast.error("Invalid login credentials. Please try again.",{position:"top-center"})}})},YK=()=>{const e=it();return Jo({queryKey:["verify"],queryFn:async()=>{if(!localStorage.getItem("__chai_at"))return{valid:!1};const r=await Tt.get(`${e}/verify`);return r.ok?(await r.json()).result==="success"?{valid:!0}:(localStorage.removeItem("__chai_at"),{valid:!1}):(localStorage.removeItem("__chai_at"),{valid:!0})}})},HK=()=>{const e=it(),t=Mt();return Xt({mutationFn:async()=>{const{result:r}=await Tt.post(`${e}/logout`).then(n=>n.json());if(r==="success")return localStorage.clear(),t.invalidateQueries({queryKey:["verify"]}),{logout:!0};throw new Error("Invalid session")}})},QK=({children:e})=>{const t=HK();return ee.jsxRuntimeExports.jsxs(je.AlertDialog,{children:[ee.jsxRuntimeExports.jsx(je.AlertDialogTrigger,{asChild:!0,children:e}),ee.jsxRuntimeExports.jsxs(je.AlertDialogContent,{children:[ee.jsxRuntimeExports.jsxs(je.AlertDialogHeader,{children:[ee.jsxRuntimeExports.jsxs(je.AlertDialogTitle,{children:["Are you sure, you want to ",ee.jsxRuntimeExports.jsx("span",{className:"text-red-500",children:"Sign Out"}),"?"]}),ee.jsxRuntimeExports.jsx(je.AlertDialogDescription,{children:"Kindly ensure that all your data is saved before proceeding with the sign-out process to prevent any potential loss of unsaved information"})]}),ee.jsxRuntimeExports.jsxs(je.AlertDialogFooter,{children:[ee.jsxRuntimeExports.jsx(je.AlertDialogCancel,{disabled:t.isPending,children:"Cancel"}),ee.jsxRuntimeExports.jsxs("button",{disabled:t.isPending,onClick:()=>t.mutate(),className:"rounded-md text-white w-28 text-center justify-center bg-red-600 hover:bg-red-700 flex items-center gap-x-2",children:[t.isPending&&ee.jsxRuntimeExports.jsx(ig.Loader2,{className:"animate-spin w-5 h-5"}),"Sign Out"]})]})]})]})},XK=()=>ee.jsxRuntimeExports.jsx(QK,{children:ee.jsxRuntimeExports.jsx("button",{className:"border-gray-200 rounded-md p-2 mb-2 border",children:ee.jsxRuntimeExports.jsx(ig.LogOutIcon,{className:"w-4 h-4 text-red-500 cursor-pointer hover:text-red-300 duration-300"})})}),_K=XK,$K=g.lazy(()=>Promise.resolve().then(()=>require("./PagesPanel-2aa9a842.cjs"))),eW=g.lazy(()=>Promise.resolve().then(()=>require("./ProjectPanel-2bfe31f7.cjs"))),tW=g.lazy(()=>Promise.resolve().then(()=>require("./CurrentPage-fa958150.cjs"))),rW=()=>ee.jsxRuntimeExports.jsx("h2",{children:"Your Logo"}),nW=()=>{const{mutate:e}=VK();return je.useBuilderProp("editable",!0)?ee.jsxRuntimeExports.jsx(je.Button,{onClick:e,className:"bg-blue-600 text-white",children:"Publish"}):null},aW=e=>{const{data:t,isLoading:r}=lc(),{data:n,isLoading:a}=Cd(),{data:o}=PA(),{mutate:s}=xA(),{mutate:i}=NA(),[l]=Jr(),u=ZK(),c=WK(),f=UK(),d=it(),p=g.useCallback(async y=>await u.mutateAsync(y),[u]),b=g.useCallback(async()=>await c.mutateAsync(),[c]),h=g.useCallback(async y=>await f.mutateAsync(y),[f]),m=async(y=20,w=0)=>{const A=`limit=${y}&offset=${w}`;return await fetch(`${d}/assets?${A}`).then(S=>S.json())},{logo:v=rW}=e;return r||!t?ee.jsxRuntimeExports.jsx(Hu,{}):a||!n?ee.jsxRuntimeExports.jsx(Hu,{}):ee.jsxRuntimeExports.jsx("div",{className:"bg-background text-foreground",children:ee.jsxRuntimeExports.jsx(mA,{editable:o!=null&&o.lockedBy?o==null?void 0:o.lockedBy.self:!0,nonEditableComponent:JK,blocks:(o==null?void 0:o.blocks)||[],brandingOptions:t.brandingOptions,darkMode:e.darkMode||!1,dataProviders:(o==null?void 0:o.providers)||[],onSavePage:async({blocks:y,providers:w})=>(await i({blocks:y,providers:w,uuid:l}),!0),onSaveBrandingOptions:async y=>(await s({brandingOptions:y}),!0),topBarComponents:{left:[v],center:[tW],right:[nW]},sideBarComponents:{top:[{icon:Js.FileTextIcon,name:"pages",panel:$K},{icon:Js.GearIcon,name:"settings",panel:eW}],bottom:[_K]},uploadMediaCallback:p,fetchMediaCallback:m,getUILibraryBlocks:b,getExternalPredefinedBlock:h,getPages:()=>n,unsplashAccessKey:e.unsplashAccessKey||""})})};var MA={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Jm=g.createContext&&g.createContext(MA),Lr=globalThis&&globalThis.__assign||function(){return Lr=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},Lr.apply(this,arguments)},oW=globalThis&&globalThis.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(r[n[a]]=e[n[a]]);return r};function TA(e){return e&&e.map(function(t,r){return g.createElement(t.tag,Lr({key:r},t.attr),TA(t.child))})}function sW(e){return function(t){return g.createElement(iW,Lr({attr:Lr({},e.attr)},t),TA(e.child))}}function iW(e){var t=function(r){var n=e.attr,a=e.size,o=e.title,s=oW(e,["attr","size","title"]),i=a||r.size||"1em",l;return r.className&&(l=r.className),e.className&&(l=(l?l+" ":"")+e.className),g.createElement("svg",Lr({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},r.attr,n,s,{className:l,style:Lr(Lr({color:e.color||r.color},r.style),e.style),height:i,width:i,xmlns:"http://www.w3.org/2000/svg"}),o&&g.createElement("title",null,o),e.children)};return Jm!==void 0?g.createElement(Jm.Consumer,null,function(r){return t(r)}):t(MA)}function lW(e){return sW({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"}},{tag:"path",attr:{d:"M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"}}]})(e)}const cW=({logo:e})=>{const[t,r]=g.useState(!1),[n,a]=g.useState(""),[o,s]=g.useState(""),{mutate:i,isPending:l}=GK(),u=c=>{c.preventDefault(),i({email:n,password:o})};return ee.jsxRuntimeExports.jsx("section",{className:"h-screen w-screen flex items-center justify-center bg-[radial-gradient(#AAA,transparent_0.5px)] duration-300 [background-size:6px_6px]",children:ee.jsxRuntimeExports.jsx("div",{className:"overflow-hidden bg-white rounded-xl w-96 drop-shadow-2xl duration-300",children:ee.jsxRuntimeExports.jsxs("div",{className:"p-12",children:[ee.jsxRuntimeExports.jsxs("div",{className:"max-w-2xl mx-auto text-center",children:[ee.jsxRuntimeExports.jsx(g.Suspense,{children:e?g.createElement(e):""}),ee.jsxRuntimeExports.jsx("p",{className:"max-w-xl mx-auto text-base leading-relaxed text-gray-700 font-thin",children:"Enter your login credential to continue"})]}),ee.jsxRuntimeExports.jsx("div",{className:"mt-8",children:ee.jsxRuntimeExports.jsxs("form",{method:"POST",onSubmit:u,className:"space-y-5",children:[ee.jsxRuntimeExports.jsx("div",{children:ee.jsxRuntimeExports.jsxs("div",{className:"mt-2.5 relative text-gray-400 focus-within:text-gray-600",children:[ee.jsxRuntimeExports.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none",children:ee.jsxRuntimeExports.jsx(lW,{})}),ee.jsxRuntimeExports.jsx("input",{value:n,onChange:c=>a(c.target.value),type:"email",id:"email",placeholder:"Enter email",className:"block w-full py-4 px-10 text-black placeholder-gray-500 transition-all duration-200 bg-white border border-gray-200 rounded-md focus:outline-none focus:border-blue-600 caret-blue-600"})]})}),ee.jsxRuntimeExports.jsx("div",{children:ee.jsxRuntimeExports.jsxs("div",{className:"mt-2.5 relative text-gray-400 focus-within:text-gray-600",children:[ee.jsxRuntimeExports.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none",children:ee.jsxRuntimeExports.jsx("svg",{className:"w-5 h-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:ee.jsxRuntimeExports.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 11c0 3.517-1.009 6.799-2.753 9.571m-3.44-2.04l.054-.09A13.916 13.916 0 008 11a4 4 0 118 0c0 1.017-.07 2.019-.203 3m-2.118 6.844A21.88 21.88 0 0015.171 17m3.839 1.132c.645-2.266.99-4.659.99-7.132A8 8 0 008 4.07M3 15.364c.64-1.319 1-2.8 1-4.364 0-1.457.39-2.823 1.07-4"})})}),ee.jsxRuntimeExports.jsx("input",{value:o,onChange:c=>s(c.target.value),type:t?"text":"password",id:"pwd",placeholder:"Enter password",className:"block w-full py-4 px-10 text-black placeholder-gray-500 transition-all duration-200 bg-white border border-gray-200 rounded-md focus:outline-none focus:border-blue-600 caret-blue-600"}),ee.jsxRuntimeExports.jsx("button",{type:"button",className:"absolute inset-y-0 right-4 flex items-center pl-3 cursor-pointer",onClick:()=>r(!t),children:t?ee.jsxRuntimeExports.jsx(Js.EyeClosedIcon,{}):ee.jsxRuntimeExports.jsx(Js.EyeOpenIcon,{})})]})}),ee.jsxRuntimeExports.jsx("div",{children:ee.jsxRuntimeExports.jsx("button",{disabled:l||B.size(n)<2||B.size(o)<2,type:"submit",className:"inline-flex disabled:bg-gray-400 items-center justify-center w-full px-4 py-4 text-base font-semibold text-white transition-all duration-200 bg-blue-600 border border-transparent rounded-md focus:outline-none hover:bg-blue-700 focus:bg-blue-700",children:l?"Signing in...":"Login"})})]})})]})})})},uW=e=>{const{data:t,isLoading:r}=YK(),n=Mt();return g.useEffect(()=>{n.setQueryData(["apiBaseUrl"],e.apiBaseUrl||"/api/chaibuilder")},[e.apiBaseUrl,n]),r?ee.jsxRuntimeExports.jsx(Hu,{}):t!=null&&t.valid?ee.jsxRuntimeExports.jsx(aW,{...e}):ee.jsxRuntimeExports.jsx(cW,{logo:e.logo})},fW=new gK,dW=e=>ee.jsxRuntimeExports.jsxs(AK,{client:fW,children:[ee.jsxRuntimeExports.jsx(ir.Toaster,{richColors:!0}),ee.jsxRuntimeExports.jsx(uW,{...e})]});exports.ChaiBuilderEditor=mA;exports.ChaiBuilderStudio=dW;exports.ErrorBoundary=sS;exports.activePanelAtom=NS;exports.addBlockOffCanvasAtom=MS;exports.addBlocksModalAtom=fS;exports.advanceStylingOpenAtom=kS;exports.canDeleteBlock=wB;exports.canDropBlock=AB;exports.canDuplicateBlock=yB;exports.canvasIframeAtom=RS;exports.editLayerNameAtom=xS;exports.getBlockJSONFromSchemas=Tu;exports.getBlockJSONFromUISchemas=Mu;exports.inlineEditingActiveAtom=IS;exports.networkModeAtom=PS;exports.pageSyncStateAtom=Wo;exports.reactIsExports=vg;exports.showPredefinedBlockCategoryAtom=TS;exports.useActiveLanguage=YS;exports.useActiveModal=gV;exports.useActivePanel=SV;exports.useAddBlock=xB;exports.useAddBlockParent=AV;exports.useAddClassesToBlocks=jB;exports.useAddPage=BK;exports.useAllBlocks=gS;exports.useBlockContentByLanguage=zV;exports.useBrandingOptions=ld;exports.useBuilderReset=md;exports.useBuildingBlocks=yS;exports.useCanvasHistory=Uo;exports.useCanvasWidth=GB;exports.useCanvasZoom=HB;exports.useChangePage=RA;exports.useCopyBlockIds=BS;exports.useCurrentPage=Jr;exports.useCurrentPage$1=wS;exports.useCutBlockIds=pd;exports.useDarkMode=QB;exports.useDeletePage=LK;exports.useDeveloperPreviewMode=_B;exports.useDuplicateBlocks=bd;exports.useExpandedIds=VV;exports.useFeatureSupport=kV;exports.useGetPageData=fd;exports.useHiddenBlockIds=eV;exports.useHighlightBlockId=LS;exports.useLanguages=jV;exports.useMarkAsGlobalBlock=rV;exports.useMoveBlocks=nV;exports.usePageDataProviders=jS;exports.usePages=Cd;exports.usePasteBlocks=KS;exports.usePreviewMode=id;exports.usePrimaryLanguage=TV;exports.useProject=lc;exports.useProject$1=sV;exports.useQueryClient=Mt;exports.useReadOnlyMode=vV;exports.useRemoveBlocks=US;exports.useRemoveClassesFromBlocks=lV;exports.useSavePage=JB;exports.useSelectedBlock=IB;exports.useSelectedBlockAllClasses=cV;exports.useSelectedBlockCurrentClasses=dV;exports.useSelectedBlockIds=Zr;exports.useSelectedBlocksDisplayChild=CB;exports.useSelectedBreakpoints=OV;exports.useSelectedStylingBlocks=sd;exports.useSetAllBlocks=dS;exports.useStylingBreakpoint=zS;exports.useStylingState=pV;exports.useTranslations=IV;exports.useTreeData=vB;exports.useUILibraryBlocks=xV;exports.useUpdateBlocksProps=hV;exports.useUpdateBlocksPropsRealtime=bV;exports.useUpdatePage=NA;exports.useUpdateProject=xA;
|
|
163
|
+
*/q();var cB=process.env.NODE_ENV!=="production"?lB:()=>null;const uB={};class sS extends g.Component{constructor(t){super(t),this.state={hasError:!1}}static getDerivedStateFromError(){return{hasError:!0}}render(){return this.state.hasError?ee.jsxRuntimeExports.jsxs("div",{className:"bg-red-200 h-full w-full rounded-md text-red-500 p-4",id:"errorBoundary",children:[ee.jsxRuntimeExports.jsx("p",{className:"font-semibold",children:"Oops! Something went wrong."}),ee.jsxRuntimeExports.jsx("p",{children:"Please try again later."})]}):this.props.children}}const fB=e=>{const t=e.replace(ze.STYLES_KEY,"").split(",");return{baseClasses:t[0],classes:t[1]}},dB=new og({children:"blockNodes"}),iS=(e,t=null)=>B.flatten(e.map(r=>{if(r=t!==null?{...r,parent:t}:r,r.children&&r.children.length){const n=[...r.children];return delete r.children,B.flatten([r,...iS(n,r._id)])}return r}));function lS(e,t,r){const n=B.filter(e,o=>o._parent===t),a=[];for(let o=0;o<n.length;o++){const s=cS(n[o]);if(Object.keys(s).length>0&&Object.keys(s).forEach(i=>{n[o][i]=`slot:${vt.generateUUID()}`}),B.filter(e,{_parent:n[o]._id}).length>0){const i=vt.generateUUID();a.push({...n[o],oldId:n[o]._id,_id:i,_parent:r}),a.push(B.flatten(lS(e,n[o]._id,i)))}else a.push({...n[o],oldId:n[o]._id,_id:vt.generateUUID(),_parent:r})}return B.flatten(a)}function pB(e){let t=dB.convert(e.map(r=>B.omit(r,["settings"])));return t=!t.type&&t.blockNodes?t.blockNodes:B.isEmpty(t)?[]:[t],t}const cS=e=>{const t={};return Object.keys(e).forEach(r=>{B.isString(e[r])&&e[r].startsWith("slot")&&(t[r]=e[r].replace("slot:",""))}),t},hB=(e,t,r=null)=>{let n=B.find(e,{_id:t});n={...n,oldId:n._id,_id:vt.generateUUID()},r&&(n={...n,_parent:r});const a=[n];B.filter(e,{_parent:t}).length>0&&a.push(B.flatten(lS(e,t,n._id)));const o=B.flatten(a);return B.map(o,s=>{const i=s,l=cS(i);return Object.keys(l).length>0&&Object.keys(l).forEach(u=>{const c=B.find(o,{oldId:l[u].replace("slot:","")});i[u]=`slot:${c._id}`}),B.omit(i,["global","oldId"])})},bB=Xa((e=[],t)=>{switch(t.type){case"add_new_blocks":case"add_duplicate_blocks":return[...e,...t.payload];case"create_snapshot":return[...e];case"set_blocks":case"set_page_blocks":return[...t.payload];case"update_props":case"update_props_realtime":const{payload:r}=t;return e.map(n=>(r.ids.includes(n._id)&&!B.isEmpty(t.payload.props)&&Object.keys(t.payload.props).forEach(a=>{B.set(n,a,t.payload.props[a])}),n));default:return e}},{debug:!1,ignoreInitialState:!1,limit:30,filter:Xa.excludeAction(["update_props_realtime","add_duplicate_blocks","set_page_blocks"])}),ec=tj({past:[],present:[],future:[]},bB);ec.debugLabel="pageBlocksAtom";const Kt=G.atom(e=>{var t;return(t=e(ec))==null?void 0:t.present});Kt.debugLabel="presentBlocksAtom";const td=sj(Kt);td.debugLabel="pageBlocksAtomsAtom";const uS=G.atom(e=>pB(e(Kt)));uS.debugLabel="pageBlocksTreeAtom";const mB=G.atom("");mB.debugLabel="builderActivePageAtom";const gB=G.atom(-1);gB.debugLabel="destinationDropIndexAtom";const fS=G.atom(!1);fS.debugLabel="addBlocksModalAtom";const Wt=()=>{const[,e]=G.useAtom(ec);return e},vB=()=>{const e=Wt(),t=G.useAtomValue(uS),r=g.useCallback(n=>{const a=iS(n);e({type:"set_page_blocks",payload:a})},[e]);return[t,r]},dS=()=>{const e=Wt();return[g.useCallback(r=>{e({type:"set_page_blocks",payload:r})},[e])]},Nu=e=>["Box","Slot","Form","DataProvider","Link","List","ListItem","Row","Column","Table","TableCell"].includes(e),yB=e=>!["Slot"].includes(e),wB=e=>!["Slot"].includes(e);function SB(e,t){return e==="Slot"||t==="List"&&e!=="ListItem"||t==="Row"&&e!=="Column"?!1:Nu(t)}const AB=(e,{dragSource:t,dropTarget:r})=>{const n=B.get(t,"data._type",""),a=B.get(r,"data._type","");return n==="Slot"||B.get(t,"id")&&B.get(t,"id")===B.get(r,"id")?!1:B.isEmpty(a)?!0:SB(n,a)},rd=G.atom([]);rd.debugLabel="selectedBlockIdsAtom";const nd=G.atom(e=>{const t=e(Kt),r=e(rd);return B.map(B.filter(t,({_id:n})=>B.includes(r,n)),n=>({...n}))});nd.debugLabel="selectedBlocksAtom";const ad=G.atom(e=>{const t=e(nd);return t.length===0?null:t.length===1?t[0]:{type:"Multiple",id:B.map(t,"id")}});ad.debugLabel="selectedBlockAtom";const EB=e=>B.get(e,"parent",null),OB=G.atom(e=>{const t=e(nd),r=B.map(t,EB);return B.filter(e(Kt),n=>B.includes(r,n._id))});OB.debugLabel="selectedBlocksParentsAtom";const pS=G.atom(()=>!1);pS.debugLabel="selectedBlockFlexChildAtom";const hS=G.atom(()=>!1);hS.debugLabel="selectedBlockGridChildAtom";const od=G.atom("");od.debugLabel="styleStateAtom";const bS=At("styleBreakpoint","xs");bS.debugLabel="styleBreakpointAtom";const CB=()=>({flexChild:G.useAtomValue(pS),gridChild:G.useAtomValue(hS)}),IB=()=>G.useAtomValue(ad),Zr=()=>{const[e,t]=G.useAtom(rd),r=g.useCallback(n=>{t(a=>B.includes(a,n)?B.without(a,n):[...a,n])},[t]);return[e,t,r]},Mu=(e,t="")=>{switch(e.type){case"singular":return e.uiSchema;case"model":const{properties:r}=e,n={};return Object.keys(r).forEach(s=>{const i=r[s];if(B.includes(["slot","styles"],i.type))return;const l=B.get(i,"i18n",!1)?`${s}-${t}`:s;n[l]=Mu(i,t)}),n;case"list":const{itemProperties:a}=e,o={items:{}};return Object.keys(a).forEach(s=>{const i=a[s];if(B.includes(["slot","styles"],i.type))return;const l=B.get(i,"i18n",!1)?`${s}-${t}`:s;o.items[l]=Mu(i,t)}),o;default:return{}}},Tu=(e,t="")=>{switch(e.type){case"singular":return e.schema;case"model":const{properties:r,title:n}=e,a={title:n,type:"object",properties:{}};return Object.keys(r).forEach(l=>{const u=r[l];if(B.includes(["slot","styles"],u.type))return;const c=B.get(u,"i18n",!1)?`${l}-${t}`:l;a.properties[c]=Tu(u,t)}),a;case"list":const{itemProperties:o,title:s}=e,i={title:s,type:"array",items:{type:"object",properties:{}}};return Object.keys(o).forEach(l=>{const u=o[l];if(B.includes(["slot","styles"],u.type))return;const c=B.get(u,"i18n",!1)?`${l}-${t}`:l;i.items.properties[c]=Tu(u,t),B.set(i.items,"title",B.get(u,"itemTitle",`${s} item`))}),i;default:return{}}},mS=e=>{const t={};return Object.keys(e).forEach(r=>{t[r]=PB(e[r])}),t},kB=e=>{if(B.isEmpty(e.default))return[];const{itemProperties:t}=e;return B.map(e.default,r=>{const n={...r};return B.forIn(r,(a,o)=>{B.has(t,o)&&B.get(t[o],"i18n",!1)&&(n[o]=ze.I18N_KEY)}),n})},PB=e=>{switch(e.type){case"styles":return e.default;case"slot":return`${ze.SLOT_KEY}${vt.generateUUID()}`;case"singular":const{i18n:t,schema:r}=e;return t?ze.I18N_KEY:B.get(r,"default","");case"model":return mS(e.properties);case"list":return kB(e);default:return""}},gS=()=>G.useAtomValue(Kt);function im(e,t,r,n,a){if(t===null)return[...e,...n];if(r!==null){const l=B.findIndex(e,{_parent:t}),u=(l===-1?0:l)+r;return e.splice(u,0,...n),e}if(!a){const u=B.findIndex(e,{_id:t})+1;return e.splice(u,0,...n),e}let o=B.findIndex(e,{_id:t});const s=B.filter(e,{_parent:t});B.isEmpty(s)||(o=B.findIndex(e,{_id:B.last(s)._id}));const i=o+1;return e.splice(i,0,...n),e}const xB=()=>{const e=Wt(),t=gS(),[,r]=Zr(),n=g.useCallback((o,s,i)=>{var c;for(let f=0;f<o.length;f++){const{_id:d}=o[f];o[f]._id=vt.generateUUID();const p=B.filter(o,{_parent:d});for(let b=0;b<p.length;b++)p[b]._parent=o[f]._id}let l;s&&(l=B.find(t,{_id:s}),o[0]._parent=s);const u=l?Nu(l._type):!0;return!u&&l&&(o[0]._parent=l._parent),e({type:"set_blocks",payload:im(t,s||null,i||null,o,u)}),r([(c=B.first(o))==null?void 0:c._id]),B.first(o)},[t,e,r]);return{addCoreBlock:g.useCallback((o,s,i)=>{if(B.has(o,"blocks")){const h=o.blocks;return n(h,s,i)}const l=vt.generateUUID(),u=mS(o.props),c=[];B.forIn(u,(h,m)=>{if(B.startsWith(h,ze.SLOT_KEY)){const v=h.replace(ze.SLOT_KEY,"");c.push({_id:v,_type:"Slot",_parent:l,_name:o.props[m].name,_styles:o.props[m].styles,_emptyStyles:o.props[m].emptyStyles})}});const f={_type:o.type,_id:l,...u};let d;s&&(d=B.find(t,{_id:s}),f._parent=s);const p=d?Nu(d._type):!0;!p&&d&&(f._parent=d._parent);const b=[f,...c];return e({type:"set_blocks",payload:im(t,s||null,i||null,b,p)}),r([f._id]),f},[n,t,e,r]),addPredefinedBlock:n}},lm={xs:420,sm:620,md:768,lg:1024,xl:1280,"2xl":1536},cm=["xs","sm","md","lg","xl","2xl"];function RB(e,t){if(t===null)return"baseClasses";const r=t.mq;if(r==="xs"||t.dark||t.mod!=="")return"classes";let n="baseClasses",a=cm.indexOf(r);for(;a>0;){const o=cm[a-1];if(B.find(e,{mq:o,property:t.property})){n="classes";break}a--}return n}const um=[];function NB(e="",t="",r=[]){e=e.trim().replace(/ +/g,"");let n=B.filter(B.map(e.split(" "),vt.constructClassObject),u=>!B.isNull(u)),a=B.filter(B.map(t.split(" "),vt.constructClassObject),u=>!B.isNull(u));a=B.filter(a,u=>!B.includes(um,u.property));const o=[],s=[];B.each(r,u=>{const c=vt.constructClassObject(u),f=B.find(n,B.pick(c,["dark","mq","mod","property"]));if(f&&(n=B.filter(n,d=>d.fullCls!==(f==null?void 0:f.fullCls))),o.push(c),c.mq==="xs"&&!c.dark&&c.mod===""&&(a=B.filter(a,d=>d.property!==c.property)),RB(n,c)==="baseClasses"&&!B.includes(um,c.property)){const d=B.find(a,B.pick(c,["property"]));f&&(a=B.filter(a,p=>p.fullCls!==(d==null?void 0:d.fullCls))),s.push({...c,fullCls:c.cls,mq:"xs"})}});const i=B.map(B.sortBy([...n,...o],u=>lm[u.mq]),"fullCls").join(" ");return`${B.map(B.sortBy([...a,...s],u=>lm[u.mq]),"fullCls").join(" ").trim()},${i.trim()}`.trim().replace(/ +/g,"")}const Ko=G.atom([]);Ko.debugLabel="selectedStylingBlocksAtom";const sd=()=>G.useAtom(Ko),MB=e=>{const t=e.replace(ze.STYLES_KEY,"").split(",");return{baseClasses:t[0],classes:t[1]}},TB=G.atom(null,(e,t,{blockIds:r,newClasses:n,dispatch:a})=>{const o=B.filter(e(td),i=>r.includes(e(i)._id)),s=B.first(e(Ko));B.each(o,i=>{const l=e(i),u=B.get(l,s.prop,`${ze.STYLES_KEY},`),{baseClasses:c,classes:f}=MB(u);a({type:"update_props_realtime",payload:{ids:[l._id],props:{[s.prop]:`${ze.STYLES_KEY}${NB(f,c,n)}`}}})})}),jB=()=>{const e=Wt(),t=G.useSetAtom(TB);return g.useCallback((r,n,a)=>{t({blockIds:r,newClasses:n,dispatch:e}),a&&setTimeout(()=>e({type:"create_snapshot"}),500)},[e,t])},vS=G.atom([]);vS.debugLabel="buildingBlocksAtom";const zB=G.atom(e=>{const t=e(vS);return B.filter(t,r=>B.has(r,"blockId"))}),qB=()=>{},yS=()=>{const e=sg.useChaiBlocks(),t=G.useAtomValue(zB),r=()=>{},n=g.useCallback(()=>qB(),[]);return[e,t,r,n]},FB=G.atom(!1),id=()=>{const[e,t]=G.useAtom(FB);return[e,t]},DB=G.atom(ze.BRANDING_OPTIONS_DEFAULTS),ld=()=>{const[e,t]=G.useAtom(DB);return[B.isObject(e)?{...ze.BRANDING_OPTIONS_DEFAULTS,...e}:ze.BRANDING_OPTIONS_DEFAULTS,t]},BB=G.atom(null),wS=()=>({currentPage:G.useAtomValue(BB)}),SS=new og({});function VB(e){let t=SS.convert(e);return t=!t.type&&t.children&&t.children.length?t.children:B.isEmpty(t)?[]:[t],t}const cd=(e,t)=>B.flatten(e.map(r=>{if(r=t?{...r,parent:t}:{...r},r.children){const n=[...r.children];return delete r.children,B.flatten([r,...cd(n,r._id)])}return r}));function ud(e,t=!1){for(let r=0;r<e.length;r++){const n=e[r];n.global&&!t?e[r]={type:"GlobalBlock",_parent:B.get(n,"parent",null),blockId:n.blockId,_id:n._id}:n.children&&n.children.length&&ud(n.children)}}function AS(e){let t=[],r=B.filter(e,{type:"GlobalBlock"});return r.length>0&&(r=B.map(r,ES),B.each(r,n=>{t=[...t,...LB(n)]})),t}function LB(e){let t=[];const r=B.get(B.first(e),"parent",null);B.set(B.first(e),"parent",null);const n=[SS.convert(OS(e))];ud(n,!0);let a=cd(n,e[0]._id);return a=B.set(a,"0.parent",r),t=[...t,a,...AS(a)],t}function ES(e){const t=B.find(ju,{_id:e._id});if(!t)return[];const r=[t],n=B.filter(ju,{_parent:e._id});return n.length?B.flatten([...r,...B.flatten(B.map(n,ES))]):B.flatten(r)}const OS=e=>JSON.parse(JSON.stringify(e));let ju=[];function KB(e){ju=e;const t=VB(OS(e));ud(t);const r=cd(t,null),n=AS(r),a={};return B.each(n,o=>B.set(a,B.first(o).blockId,o)),[r,a]}const fd=()=>{const[e]=ld(),{currentPage:t}=wS(),r=G.useAtomValue(Kt);return g.useCallback(()=>{const n=B.map(r,s=>B.omit(s,["expanded","order","title","siblings","tempClasses"])),[a=[],o=[]]=KB(n);return{currentPage:t,blocks:a,globalBlocks:o}},[e,t,r])};At("blockStylingActiveTab",1);G.atom([]);const CS=G.atom(!1);CS.debugLabel="readOnlyModeAtom";const IS=G.atom(!1);IS.debugLabel="inlineEditingActiveAtom";const kS=G.atom(!1);kS.debugLabel="advanceStylingOpenAtom";const PS=G.atom("online");PS.debugLabel="networkModeAtom";At("currentUiLibrary","");const WB=G.atom(!1);WB.debugLabel="codeEditorOpenAtom";const xS=G.atom(!1);xS.debugLabel="editLayerNameAtom";const UB=G.atom("");UB.debugLabel="activeLanguageAtom";const ZB=G.atom("");ZB.debugLabel="primaryLanguageAtom";const RS=G.atom(null);RS.debugLabel="canvasIframeAtom";const NS=G.atom("layers");NS.debugLabel="activePanelAtom";const MS=G.atom(!1);MS.debugLabel="addBlockOffCanvasAtom";const TS=G.atom("");TS.debugLabel="showPredefinedBlockCategoryAtom";const tc=G.atom({undoCount:0,redoCount:0});tc.debugLabel="historyStatesAtom";const dd=G.atom([]);dd.debugLabel="dataProvidersAtom";const jS=()=>G.useAtom(dd),Wo=G.atom("SAVED");Wo.debugLabel="pageSyncStateAtom";const JB=()=>{const[e,t]=G.useAtom(Wo),r=je.useBuilderProp("onSaveBlocks",async()=>{}),n=je.useBuilderProp("onSavePage",async()=>{}),a=je.useBuilderProp("onSyncStatusChange",()=>{}),o=fd(),s=G.useSetAtom(tc),{undoCount:i,redoCount:l}=Uo(),[u]=jS();return{savePage:KA.useThrottledCallback(async()=>{t("SAVING"),a("SAVING");const f=o();return await Promise.all([r({blocks:f.blocks,providers:[],identifier:"pageData.id"}),n({blocks:f.blocks,providers:u})]),setTimeout(()=>{s({undoCount:i,redoCount:l}),t("SAVED"),a("SAVED")},100),!0},[o,t,a,r],5e3),syncState:e,setSyncState:t}},Uo=()=>{const e=G.useAtomValue(ec),[{undoCount:t,redoCount:r}]=G.useAtom(tc),n=Wt(),[a]=id(),[,o]=Zr(),[,s]=sd(),[i,l]=G.useAtom(Wo),u=je.useBuilderProp("onSyncStatusChange",()=>{}),c=g.useCallback(()=>{n({type:"create_snapshot"})},[n]);return g.useEffect(()=>{(i==="SAVED"&&t!==(e==null?void 0:e.past.length)||r!==(e==null?void 0:e.future.length))&&(l("UNSAVED"),u("UNSAVED"))},[e==null?void 0:e.past.length,e==null?void 0:e.future.length,t,r,u,l,i]),{undoCount:e==null?void 0:e.past.length,redoCount:e==null?void 0:e.future.length,undo:g.useCallback(()=>{a||(n(Xa.ActionCreators.undo()),setTimeout(()=>{s([]),o([])},200))},[n,a,o,s]),redo:g.useCallback(()=>{a||(n(Xa.ActionCreators.redo()),setTimeout(()=>{s([]),o([])},200))},[a,n,s,o]),clear:()=>{n(Xa.ActionCreators.clearHistory())},createSnapshot:c}},zS=()=>G.useAtom(bS),qS=At("canvasWidth",800),FS=G.atom(e=>{const t=e(qS);return vt.getBreakpointValue(t).toLowerCase()}),GB=()=>{const[e,t]=G.useAtom(qS),r=G.useAtomValue(FS),[n,a]=zS();return g.useEffect(()=>{n!=="xs"&&a(r)},[r,n,a]),[e,r,t]},YB=At("canvasZoom",100),HB=()=>G.useAtom(YB),DS=G.atom([]),pd=()=>{const[e,t]=G.useAtom(DS),r=G.useSetAtom(hd),n=g.useCallback(a=>{t(a),r([])},[t,r]);return[e,n]},hd=G.atom([]),BS=()=>{const[e,t]=G.useAtom(hd),r=G.useSetAtom(DS),n=g.useCallback(a=>{t(a),r([])},[t,r]);return[e,n]},VS=At("darkMode",!1),QB=()=>{const[e,t]=G.useAtom(VS);return[e,t]},XB=G.atom(!1),_B=()=>{const[e,t]=G.useAtom(XB);return[e,t]},bd=()=>{const e=Wt(),t=G.useAtomValue(Kt),[,r]=Zr();return g.useCallback((n,a=null)=>{const o=[];B.each(n,s=>{const l=hB(t,s,a===s?null:a);o.push(B.get(l,"0._id","")),e({type:"add_duplicate_blocks",payload:l})}),r(o),e({type:"create_snapshot"})},[t,r,e])},$B=G.atom([]),eV=()=>{const[e,t]=G.useAtom($B),r=g.useCallback(n=>{t(a=>B.includes(a,n)?B.without(a,n):[...a,n])},[t]);return[e,t,r]},tV=G.atom(""),LS=()=>G.useAtom(tV),rV=()=>{const e=G.useAtomValue(Kt),t=Wt(),r=fd(),[,,n]=yS();return g.useCallback(async(a,o)=>{const s=vt.generateUUID(16),i=B.map(e,l=>(l._id===a&&(l._globalBlockId=s,l._name=o),l));t({type:"set_page_blocks",payload:i}),n()},[e,t,r,n])},nV=()=>({}),aV=()=>{const e=G.useAtomValue(Kt),t=Wt();return g.useCallback((r,n)=>{const a=B.map(e,o=>(B.includes(r,B.get(o,"_id"))&&B.set(o,"_parent",n),o));t({type:"set_blocks",payload:a})},[e,t])},KS=()=>{const e=G.useAtomValue(hd),[t,r]=pd(),n=bd(),a=aV();return{canPaste:g.useMemo(()=>t.length>0||e.length>0,[e,t]),pasteBlocks:g.useCallback(s=>{B.isEmpty(e)?a(t,s):n(e,s),r(()=>[])},[t,e,n,a,r])}},oV=G.atom(""),sV=()=>{const e=G.useAtomValue(oV),t=g.useCallback(()=>{},[]),r=g.useCallback(()=>{},[]),n=g.useCallback(()=>{},[]);return{currentProject:e,createProject:n,deleteProject:t,updateProject:r}},WS=(e,t)=>{const r=[],n=B.filter(e,a=>B.includes(t,a._id)||B.includes(t,a._parent)?(r.push(a._id),!1):!0);return B.isEmpty(r)?n:WS(n,r)},US=()=>{const e=Wt(),t=G.useAtomValue(Kt),[r,n]=Zr();return g.useCallback(a=>{var i;const o=((i=B.find(t,{_id:a[0]}))==null?void 0:i._parent)||null,s=WS(t,a);e({type:"set_blocks",payload:s}),n(o?[o]:[])},[t,n,e,r])},iV=G.atom(null,(e,t,{blockIds:r,fullClasses:n,dispatch:a})=>{const o=B.first(e(Ko)),s=B.filter(e(td),i=>r.includes(e(i)._id));B.each(s,i=>{const l=e(i),u=n;let{classes:c,baseClasses:f}=fB(B.get(l,o.prop,"styles:,"));B.each(u,d=>{const p=new RegExp(`(^| )${d.replace("[","\\[").replace("]","\\]")}($| )`,"g");c=c.replace(p," ").replace(/ +/g," ").trim();const b=B.first(d.split(":"));B.includes(["2xl","xl","lg","md","sm"],b)&&u.push(d.split(":").pop().trim())}),B.each(u,d=>{const p=new RegExp(`(^| )${d.replace("[","\\[").replace("]","\\]")}($| )`,"g");f=f.replace(p," ").replace(/ +/g," ").trim()}),a({type:"update_props_realtime",payload:{ids:[l._id],props:{[o.prop]:`${ze.STYLES_KEY}${f},${c}`}}})})}),lV=()=>{const e=Wt(),t=G.useSetAtom(iV);return g.useCallback((r,n)=>{t({blockIds:r,fullClasses:n,dispatch:e}),setTimeout(()=>e({type:"create_snapshot"}))},[e,t])},ZS=G.atom(e=>{const t=B.first(e(Ko)),r=e(ad);if(!t||t.blockId!==B.get(r,"_id",null))return[];const a=B.get(r,t.prop,`${ze.STYLES_KEY},`).replace(ze.STYLES_KEY,"").split(",").join(" ");return B.filter(B.map(a.trim().split(" "),vt.constructClassObject),o=>!B.isNull(o))}),cV=()=>G.useAtomValue(ZS),fm={xs:0,sm:1,md:2,lg:3,xl:4,"2xl":5},uV=G.atom(e=>{const t=e(FS),r=e(od),n=e(VS),a=fV(t);let o=B.filter(e(ZS),{mod:r});return B.startsWith(r,"_")||(o=B.filter(o,s=>a.includes(s.mq))),o=o.sort((s,i)=>fm[s.mq]-fm[i.mq]),n||(o=B.filter(o,{dark:!1})),o}),fV=e=>{let t=[];switch(e){case"xs":t=["xs"];break;case"sm":t=["xs","sm"];break;case"md":t=["xs","sm","md"];break;case"lg":t=["xs","sm","md","lg"];break;case"xl":t=["xs","sm","md","lg","xl"];break;case"2xl":t=["xs","sm","md","lg","xl","2xl"];break;default:t=["xs"];break}return t},dV=()=>G.useAtomValue(uV),pV=()=>G.useAtom(od),JS=G.atom(null,(e,t,{blockIds:r,props:n,dispatch:a})=>{a({type:"update_props_realtime",payload:{ids:r,props:n}})}),hV=()=>{const{createSnapshot:e}=Uo(),t=Wt(),r=G.useSetAtom(JS);return g.useCallback((n,a)=>{r({blockIds:n,props:a,dispatch:t}),e()},[e,t,r])},bV=()=>{const e=Wt(),t=G.useSetAtom(JS);return g.useCallback((r,n)=>{t({blockIds:r,props:n,dispatch:e})},[e,t])},GS={name:"",props:{},modalProps:{},backdropClose:!0},mV=G.atom(GS),gV=()=>{const[e,t]=G.useAtom(mV),r=g.useCallback((a,o={},s={})=>{t({name:a,props:o,modalProps:s})},[t]),n=g.useCallback((...a)=>{B.get(e,"props.onClose",()=>{})(...a),t(GS)},[t,e]);return{activeModal:e,openModal:r,closeModal:n}},vV=()=>G.useAtomValue(CS),yV=G.atom(""),wV=G.atom(null),SV=()=>G.useAtom(yV),AV=()=>G.useAtom(wV),EV=At("selectedBreakpoints",["XS","MD","XL"]),OV=()=>{const[e,t]=G.useAtom(EV);return[e,t]},md=()=>{const e=G.useSetAtom(tc),{clear:t}=Uo(),[,r]=Zr(),[,n]=LS(),[,a]=sd();return()=>{r([]),a([]),n(""),t(),e({undoCount:0,redoCount:0})}},CV=G.atom({en:{}}),IV=()=>{const[e,t]=G.useAtom(CV),r=g.useCallback((n,a,o)=>{B.set(e,`${n}.${a}`,o),t(e)},[e,t]);return[e,r]},kV=(e,t)=>{const[r]=G.useAtom(je.chaiBuilderPropsAtom);return B.get(r,e,t)},PV=G.atom([]),xV=()=>{const[e,t]=g.useState(!1),[r,n]=G.useAtom(PV),a=je.useBuilderProp("getUILibraryBlocks",()=>[]);return g.useEffect(()=>{(async()=>r.length>0||(t(!0),n(await a()),t(!1)))()},[]),{data:r,isLoading:e}},RV=G.atom("en"),NV=G.atom("en"),MV=G.atom(["en"]),YS=()=>G.useAtom(RV),TV=()=>G.useAtom(NV),jV=()=>G.useAtom(MV),zV=(e,t)=>{const[r]=YS(),n=`${e}${r?`-${r}`:""}`;return{content:B.get(t,n,B.get(t,e,"")),propKey:e}},qV=()=>{const[e,t]=id(),r=je.useBuilderProp("previewComponent");return ee.jsxRuntimeExports.jsxs("div",{className:LA.cn("fixed inset-0 z-[999] bg-background",e?"block":"hidden"),children:[ee.jsxRuntimeExports.jsx(je.Button,{size:"sm",className:"absolute right-0 top-0 m-4",onClick:()=>t(!1),children:"Close Preview"}),ee.jsxRuntimeExports.jsx("div",{children:r?ee.jsxRuntimeExports.jsx(g.Suspense,{fallback:ee.jsxRuntimeExports.jsx(je.Skeleton,{className:"h-96 w-full"}),children:g.createElement(r)}):null})]})},FV=()=>{const[e,t]=Zr(),[,r]=BS(),n=US(),a=bd(),[,o]=pd(),{pasteBlocks:s}=KS(),{undo:i,redo:l}=Uo();Ar.useHotkeys("esc",()=>t([]),{},[t]),Ar.useHotkeys("ctrl+c,command+c",()=>r(e),{},[e,r]),Ar.useHotkeys("ctrl+d,command+d",()=>a(e),{preventDefault:!0},[e,a]),Ar.useHotkeys("ctrl+x,command+x",()=>o(e),{},[e,o]),Ar.useHotkeys("ctrl+v,command+v",()=>e.length===1?s(e[0]):null,{},[e,s]),Ar.useHotkeys("ctrl+z,command+z",()=>i(),{},[i]),Ar.useHotkeys("ctrl+y,command+y",()=>l(),{},[l]),Ar.useHotkeys("del, backspace",u=>{u.preventDefault(),n(e)},{},[e,n])},DV=(e,t)=>{const r=[];let n=B.find(e,{_id:t}),a=B.get(n,"_parent","");for(;B.isString(a)&&!B.isEmpty(a);)r.push(n==null?void 0:n._parent),n=B.find(e,{_id:a}),a=n==null?void 0:n._parent;return B.flatten(r)},HS=G.atom([]),BV=()=>{const[e]=Zr(),t=G.useAtomValue(Kt),[,r]=G.useAtom(HS);g.useEffect(()=>{let n=[];const a=B.first(e);B.isString(a)&&(n=[a,...DV(t,a)]),r(n)},[e,t,r])},VV=()=>G.useAtomValue(HS),LV=g.lazy(()=>Promise.resolve().then(()=>require("./SidePanels-b3e85d16.cjs"))),KV=g.lazy(()=>Promise.resolve().then(()=>require("./Topbar-58a2d4b3.cjs"))),WV=g.lazy(()=>Promise.resolve().then(()=>require("./CanvasArea-cd4da772.cjs"))),UV=g.lazy(()=>Promise.resolve().then(()=>require("./Settings-f4f20456.cjs"))),ZV=()=>{const[e]=G.useAtom(Wo),t=a=>{a.preventDefault()};FV(),BV(),g.useEffect(()=>(e!=="SAVED"?window.onbeforeunload=()=>"":window.onbeforeunload=null,()=>{window.onbeforeunload=null}),[e]);const r=je.useBuilderProp("editable",!0),n=je.useBuilderProp("nonEditableComponent",null);return ee.jsxRuntimeExports.jsx("div",{className:"h-screen w-screen bg-background text-foreground",children:ee.jsxRuntimeExports.jsxs(je.TooltipProvider,{children:[ee.jsxRuntimeExports.jsxs("div",{onContextMenu:t,className:"flex h-screen flex-col overflow-hidden bg-background text-foreground",children:[ee.jsxRuntimeExports.jsx("div",{className:"h-14 w-screen shrink-0 border-b border-border",children:ee.jsxRuntimeExports.jsx(g.Suspense,{children:ee.jsxRuntimeExports.jsx(KV,{})})}),ee.jsxRuntimeExports.jsxs("main",{className:"flex h-full flex-row relative",children:[r?null:ee.jsxRuntimeExports.jsx("div",{className:"absolute backdrop-blur-[2px] flex items-center justify-center inset-0 z-[500] h-full w-full",children:ee.jsxRuntimeExports.jsx(g.Suspense,{children:g.createElement(n)})}),ee.jsxRuntimeExports.jsx("div",{className:"flex h-full w-fit border-border max-h-full",style:{maxHeight:"calc(100vh - 56px)"},children:ee.jsxRuntimeExports.jsx(g.Suspense,{children:ee.jsxRuntimeExports.jsx(LV,{})})}),ee.jsxRuntimeExports.jsx("div",{className:"h-full flex-1 bg-slate-800/20",children:ee.jsxRuntimeExports.jsx(g.Suspense,{children:ee.jsxRuntimeExports.jsx(WV,{})})}),ee.jsxRuntimeExports.jsx("div",{className:"flex h-full w-[280px] min-w-[280px] border-l border-border",children:ee.jsxRuntimeExports.jsx(g.Suspense,{children:ee.jsxRuntimeExports.jsx(UV,{})})})]})]}),ee.jsxRuntimeExports.jsx(qV,{})]})})},dm=G.getDefaultStore();G.atom({});function pm(e,t,r,n,a){for(t=t.split?t.split("."):t,n=0;n<t.length;n++)e=e?e[t[n]]:a;return e===a?r:e}var Ps="undefined",hm="object",QS="any",XS="*",wn="__",vl=typeof process<"u"?process:{};vl.env&&vl.env.NODE_ENV;var Qt=typeof document<"u";vl.versions!=null&&vl.versions.node!=null;typeof Deno<"u"&&Deno.core;Qt&&window.name==="nodejs"||typeof navigator<"u"&&navigator.userAgent!==void 0&&(navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom"));function _S(e,t){return t.charAt(0)[e]()+t.slice(1)}var JV=_S.bind(null,"toUpperCase"),GV=_S.bind(null,"toLowerCase");function YV(e){return $S(e)?JV("null"):typeof e=="object"?$V(e):Object.prototype.toString.call(e).slice(8,-1)}function yl(e,t){t===void 0&&(t=!0);var r=YV(e);return t?GV(r):r}function Zo(e,t){return typeof t===e}var sr=Zo.bind(null,"function"),Yn=Zo.bind(null,"string"),Wn=Zo.bind(null,"undefined"),HV=Zo.bind(null,"boolean");Zo.bind(null,"symbol");function $S(e){return e===null}function QV(e){return yl(e)==="number"&&!isNaN(e)}function XV(e){return yl(e)==="array"}function It(e){if(!_V(e))return!1;for(var t=e;Object.getPrototypeOf(t)!==null;)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function _V(e){return e&&(typeof e=="object"||e!==null)}function $V(e){return sr(e.constructor)?e.constructor.name:null}function eL(e){return e instanceof Error||Yn(e.message)&&e.constructor&&QV(e.constructor.stackTraceLimit)}function eA(e,t){if(typeof t!="object"||$S(t))return!1;if(t instanceof e)return!0;var r=yl(new e(""));if(eL(t))for(;t;){if(yl(t)===r)return!0;t=Object.getPrototypeOf(t)}return!1}eA.bind(null,TypeError);eA.bind(null,SyntaxError);function rc(e,t){var r=e instanceof Element||e instanceof HTMLDocument;return r&&t?tL(e,t):r}function tL(e,t){return t===void 0&&(t=""),e&&e.nodeName===t.toUpperCase()}function nc(e){var t=[].slice.call(arguments,1);return function(){return e.apply(void 0,[].slice.call(arguments).concat(t))}}nc(rc,"form");nc(rc,"button");nc(rc,"input");nc(rc,"select");function bm(e){try{return decodeURIComponent(e.replace(/\+/g," "))}catch{return null}}function rL(){if(Qt){var e=navigator,t=e.languages;return e.userLanguage||(t&&t.length?t[0]:e.language)}}function nL(){try{return Intl.DateTimeFormat().resolvedOptions().timeZone}catch{}}function aL(e){return function(t){for(var r,n=Object.create(null),a=/([^&=]+)=?([^&]*)/g;r=a.exec(t);){var o=bm(r[1]),s=bm(r[2]);o.substring(o.length-2)==="[]"?(n[o=o.substring(0,o.length-2)]||(n[o]=[])).push(s):n[o]=s===""||s}for(var i in n){var l=i.split("[");l.length>1&&(oL(n,l.map(function(u){return u.replace(/[?[\]\\ ]/g,"")}),n[i]),delete n[i])}return n}(function(t){if(t){var r=t.match(/\?(.*)/);return r&&r[1]?r[1].split("#")[0]:""}return Qt&&window.location.search.substring(1)}(e))}function oL(e,t,r){for(var n=t.length-1,a=0;a<n;++a){var o=t[a];if(o==="__proto__"||o==="constructor")break;o in e||(e[o]={}),e=e[o]}e[t[n]]=r}function ac(){for(var e="",t=0,r=4294967295*Math.random()|0;t++<36;){var n="xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"[t-1],a=15&r;e+=n=="-"||n=="4"?n:(n=="x"?a:3&a|8).toString(16),r=t%8==0?4294967295*Math.random()|0:r>>4}return e}var ao="global",Ea=wn+"global"+wn,Oa=typeof self===hm&&self.self===self&&self||typeof global===hm&&global.global===global&&global||void 0;function Sn(e){return Oa[Ea][e]}function An(e,t){return Oa[Ea][e]=t}function Ma(e){delete Oa[Ea][e]}function Ta(e,t,r){var n;try{if(gd(e)){var a=window[e];n=a[t].bind(a)}}catch{}return n||r}Oa[Ea]||(Oa[Ea]={});var xs={};function gd(e){if(typeof xs[e]!==Ps)return xs[e];try{var t=window[e];t.setItem(Ps,Ps),t.removeItem(Ps)}catch{return xs[e]=!1}return xs[e]=!0}function ye(){return ye=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},ye.apply(this,arguments)}var Pr="function",mr="undefined",sL="@@redux/"+Math.random().toString(36),mm=function(){return typeof Symbol===Pr&&Symbol.observable||"@@observable"}(),Rs=" != "+Pr;function tA(e,t,r){var n;if(typeof t===Pr&&typeof r===mr&&(r=t,t=void 0),typeof r!==mr){if(typeof r!==Pr)throw new Error("enhancer"+Rs);return r(tA)(e,t)}if(typeof e!==Pr)throw new Error("reducer"+Rs);var a=e,o=t,s=[],i=s,l=!1;function u(){i===s&&(i=s.slice())}function c(){return o}function f(p){if(typeof p!==Pr)throw new Error("Listener"+Rs);var b=!0;return u(),i.push(p),function(){if(b){b=!1,u();var h=i.indexOf(p);i.splice(h,1)}}}function d(p){if(!It(p))throw new Error("Act != obj");if(typeof p.type===mr)throw new Error("ActType "+mr);if(l)throw new Error("Dispatch in reducer");try{l=!0,o=a(o,p)}finally{l=!1}for(var b=s=i,h=0;h<b.length;h++)(0,b[h])();return p}return d({type:"@@redux/INIT"}),(n={dispatch:d,subscribe:f,getState:c,replaceReducer:function(p){if(typeof p!==Pr)throw new Error("next reducer"+Rs);a=p,d({type:"@@redux/INIT"})}})[mm]=function(){var p,b=f;return(p={subscribe:function(h){if(typeof h!="object")throw new TypeError("Observer != obj");function m(){h.next&&h.next(c())}return m(),{unsubscribe:b(m)}}})[mm]=function(){return this},p},n}function iL(e,t){var r=t&&t.type;return"action "+(r&&r.toString()||"?")+"reducer "+e+" returns "+mr}function Ca(){var e=[].slice.call(arguments);return e.length===0?function(t){return t}:e.length===1?e[0]:e.reduce(function(t,r){return function(){return t(r.apply(void 0,[].slice.call(arguments)))}})}function lL(){var e=arguments;return function(t){return function(r,n,a){var o,s=t(r,n,a),i=s.dispatch,l={getState:s.getState,dispatch:function(u){return i(u)}};return o=[].slice.call(e).map(function(u){return u(l)}),ye({},s,{dispatch:i=Ca.apply(void 0,o)(s.dispatch)})}}}var Vr=wn+"anon_id",mn=wn+"user_id",Hn=wn+"user_traits",kr="userId",Un="anonymousId",Ws=["bootstrap","params","campaign","initializeStart","initialize","initializeEnd","ready","resetStart","reset","resetEnd","pageStart","page","pageEnd","pageAborted","trackStart","track","trackEnd","trackAborted","identifyStart","identify","identifyEnd","identifyAborted","userIdChanged","registerPlugins","enablePlugin","disablePlugin","online","offline","setItemStart","setItem","setItemEnd","setItemAborted","removeItemStart","removeItem","removeItemEnd","removeItemAborted"],zu=["name","EVENTS","config","loaded"],ve=Ws.reduce(function(e,t){return e[t]=t,e},{registerPluginType:function(e){return"registerPlugin:"+e},pluginReadyType:function(e){return"ready:"+e}}),gm=/^utm_/,vm=/^an_prop_/,ym=/^an_trait_/;function cL(e){var t=e.storage.setItem;return function(r){return function(n){return function(a){if(a.type===ve.bootstrap){var o=a.params,s=a.user,i=a.persistedUser,l=a.initialUser,u=i.userId===s.userId;i.anonymousId!==s.anonymousId&&t(Vr,s.anonymousId),u||t(mn,s.userId),l.traits&&t(Hn,ye({},u&&i.traits?i.traits:{},l.traits));var c=Object.keys(a.params);if(c.length){var f=o.an_uid,d=o.an_event,p=c.reduce(function(b,h){if(h.match(gm)||h.match(/^(d|g)clid/)){var m=h.replace(gm,"");b.campaign[m==="campaign"?"name":m]=o[h]}return h.match(vm)&&(b.props[h.replace(vm,"")]=o[h]),h.match(ym)&&(b.traits[h.replace(ym,"")]=o[h]),b},{campaign:{},props:{},traits:{}});r.dispatch(ye({type:ve.params,raw:o},p,f?{userId:f}:{})),f&&setTimeout(function(){return e.identify(f,p.traits)},0),d&&setTimeout(function(){return e.track(d,p.props)},0),Object.keys(p.campaign).length&&r.dispatch({type:ve.campaign,campaign:p.campaign})}}return n(a)}}}}function uL(e){return function(t,r){if(t===void 0&&(t={}),r===void 0&&(r={}),r.type===ve.setItemEnd){if(r.key===Vr)return ye({},t,{anonymousId:r.value});if(r.key===mn)return ye({},t,{userId:r.value})}switch(r.type){case ve.identify:return Object.assign({},t,{userId:r.userId,traits:ye({},t.traits,r.traits)});case ve.reset:return[mn,Vr,Hn].forEach(function(n){e.removeItem(n)}),Object.assign({},t,{userId:null,anonymousId:null,traits:{}});default:return t}}}function wm(e){return{userId:e.getItem(mn),anonymousId:e.getItem(Vr),traits:e.getItem(Hn)}}var qu=function(e){return wn+"TEMP"+wn+e};function fL(e){var t=e.storage,r=t.setItem,n=t.removeItem,a=t.getItem;return function(o){return function(s){return function(i){var l=i.userId,u=i.traits,c=i.options;if(i.type===ve.reset&&([mn,Hn,Vr].forEach(function(p){n(p)}),[kr,Un,"traits"].forEach(function(p){Ma(qu(p))})),i.type===ve.identify){a(Vr)||r(Vr,ac());var f=a(mn),d=a(Hn)||{};f&&f!==l&&o.dispatch({type:ve.userIdChanged,old:{userId:f,traits:d},new:{userId:l,traits:u},options:c}),l&&r(mn,l),u&&r(Hn,ye({},d,u))}return s(i)}}}}var Ha={};function Sm(e,t){Ha[e]&&sr(Ha[e])&&(Ha[e](t),delete Ha[e])}function rA(e,t,r){return new Promise(function(n,a){return t()?n(e):r<1?a(ye({},e,{queue:!0})):new Promise(function(o){return setTimeout(o,10)}).then(function(o){return rA(e,t,r-10).then(n,a)})})}function nA(e,t,r){var n=t(),a=e.getState(),o=a.plugins,s=a.queue,i=a.user;if(!a.context.offline&&s&&s.actions&&s.actions.length){var l=s.actions.reduce(function(c,f,d){return o[f.plugin].loaded?(c.process.push(f),c.processIndex.push(d)):(c.requeue.push(f),c.requeueIndex.push(d)),c},{processIndex:[],process:[],requeue:[],requeueIndex:[]});if(l.processIndex&&l.processIndex.length){l.processIndex.forEach(function(c){var f=s.actions[c],d=f.plugin,p=f.payload.type,b=n[d][p];if(b&&sr(b)){var h=function(v,y){return v===void 0&&(v={}),y===void 0&&(y={}),[kr,Un].reduce(function(w,A){return v.hasOwnProperty(A)&&y[A]&&y[A]!==v[A]&&(w[A]=y[A]),w},v)}(f.payload,i);b({payload:h,config:o[d].config,instance:r});var m=p+":"+d;e.dispatch(ye({},h,{type:m,_:{called:m,from:"queueDrain"}}))}});var u=s.actions.filter(function(c,f){return!~l.processIndex.indexOf(f)});s.actions=u}}}var _c=function(e){var t=e.data,r=e.action,n=e.instance,a=e.state,o=e.allPlugins,s=e.allMatches,i=e.store,l=e.EVENTS;try{var u=a.plugins,c=a.context,f=r.type,d=f.match(Qn),p=t.exact.map(function(m){return m.pluginName});d&&(p=s.during.map(function(m){return m.pluginName}));var b=function(m,v){return function(y,w,A){var S=w.config,E=w.name,C=E+"."+y.type;A&&(C=A.event);var P=y.type.match(Qn)?function(I,T,z,N,W){return function(F,V){var _=N?N.name:I,U=V&&mo(V)?V:z;if(N&&(!(U=V&&mo(V)?V:[I]).includes(I)||U.length!==1))throw new Error("Method "+T+" can only abort "+I+" plugin. "+JSON.stringify(U)+" input valid");return ye({},W,{abort:{reason:F,plugins:U,caller:T,_}})}}(E,C,v,A,y):function(I,T){return function(){throw new Error(I.type+" action not cancellable. Remove abort in "+T)}}(y,C);return{payload:dL(y),instance:m,config:S||{},abort:P}}}(n,p),h=t.exact.reduce(function(m,v){var y=v.pluginName,w=v.methodName,A=!1;return w.match(/^initialize/)||w.match(/^reset/)||(A=!u[y].loaded),c.offline&&w.match(/^(page|track|identify)/)&&(A=!0),m[""+y]=A,m},{});return Promise.resolve(t.exact.reduce(function(m,v,y){try{var w=v.pluginName;return Promise.resolve(m).then(function(A){function S(){return Promise.resolve(A)}var E=function(){if(t.namespaced&&t.namespaced[w])return Promise.resolve(t.namespaced[w].reduce(function(C,P,I){try{return Promise.resolve(C).then(function(T){return P.method&&sr(P.method)?(function(F,V){var _=Pm(F);if(_&&_.name===V){var U=Pm(_.method);throw new Error([V+" plugin is calling method "+F,"Plugins cant call self","Use "+_.method+" "+(U?"or "+U.method:"")+" in "+V+" plugin insteadof "+F].join(`
|
|
164
|
+
`))}}(P.methodName,P.pluginName),Promise.resolve(P.method({payload:T,instance:n,abort:(z=T,N=w,W=P.pluginName,function(F,V){return ye({},z,{abort:{reason:F,plugins:V||[N],caller:f,from:W||N}})}),config:Om(P.pluginName,u,o),plugins:u})).then(function(F){var V=It(F)?F:{};return Promise.resolve(ye({},T,V))})):T;var z,N,W})}catch(T){return Promise.reject(T)}},Promise.resolve(r))).then(function(C){A[w]=C});A[w]=r}();return E&&E.then?E.then(S):S()})}catch(A){return Promise.reject(A)}},Promise.resolve({}))).then(function(m){return Promise.resolve(t.exact.reduce(function(v,y,w){try{var A=t.exact.length===w+1,S=y.pluginName,E=o[S];return Promise.resolve(v).then(function(C){var P=m[S]?m[S]:{};if(d&&(P=C),eu(P,S))return $c({data:P,method:f,instance:n,pluginName:S,store:i}),Promise.resolve(C);if(eu(C,S))return A&&$c({data:C,method:f,instance:n,store:i}),Promise.resolve(C);if(h.hasOwnProperty(S)&&h[S]===!0)return i.dispatch({type:"queue",plugin:S,payload:P,_:{called:"queue",from:"queueMechanism"}}),Promise.resolve(C);var I=b(m[S],o[S]);return Promise.resolve(E[f]({abort:I.abort,payload:P,instance:n,config:Om(S,u,o),plugins:u})).then(function(T){var z=It(T)?T:{},N=ye({},C,z),W=m[S];if(eu(W,S))$c({data:W,method:f,instance:n,pluginName:S,store:i});else{var F=f+":"+S;(F.match(/:/g)||[]).length<2&&!f.match(Am)&&!f.match(Em)&&n.dispatch(ye({},d?N:P,{type:F,_:{called:F,from:"submethod"}}))}return Promise.resolve(N)})})}catch(C){return Promise.reject(C)}},Promise.resolve(r))).then(function(v){if(!(f.match(Qn)||f.match(/^registerPlugin/)||f.match(Em)||f.match(Am)||f.match(/^params/)||f.match(/^userIdChanged/))){if(l.plugins.includes(f),v._&&v._.originalAction===f)return v;var y=ye({},v,{_:{originalAction:v.type,called:v.type,from:"engineEnd"}});aA(v,t.exact.length)&&!f.match(/End$/)&&(y=ye({},y,{type:v.type+"Aborted"})),i.dispatch(y)}return v})})}catch(m){return Promise.reject(m)}},Qn=/Start$/,Am=/^bootstrap/,Em=/^ready/;function $c(e){var t=e.pluginName,r=e.method+"Aborted"+(t?":"+t:"");e.store.dispatch(ye({},e.data,{type:r,_:{called:r,from:"abort"}}))}function Om(e,t,r){var n=t[e]||r[e];return n&&n.config?n.config:{}}function Cm(e,t){return t.reduce(function(r,n){return n[e]?r.concat({methodName:e,pluginName:n.name,method:n[e]}):r},[])}function Im(e,t){var r=e.replace(Qn,""),n=t?":"+t:"";return[""+e+n,""+r+n,r+"End"+n]}function eu(e,t){var r=e.abort;return!!r&&(r===!0||km(r,t)||r&&km(r.plugins,t))}function aA(e,t){var r=e.abort;if(!r)return!1;if(r===!0||Yn(r))return!0;var n=r.plugins;return mo(r)&&r.length===t||mo(n)&&n.length===t}function mo(e){return Array.isArray(e)}function km(e,t){return!(!e||!mo(e))&&e.includes(t)}function Pm(e){var t=e.match(/(.*):(.*)/);return!!t&&{method:t[1],name:t[2]}}function dL(e){return Object.keys(e).reduce(function(t,r){return r==="type"||(t[r]=It(e[r])?Object.assign({},e[r]):e[r]),t},{})}function pL(e,t,r){var n={};return function(a){return function(o){return function(s){try{var i,l=function(A){return i?A:o(f)},u=s.type,c=s.plugins,f=s;if(s.abort)return Promise.resolve(o(s));if(u===ve.enablePlugin&&a.dispatch({type:ve.initializeStart,plugins:c,disabled:[],fromEnable:!0,meta:s.meta}),u===ve.disablePlugin&&setTimeout(function(){return Sm(s.meta.rid,{payload:s})},0),u===ve.initializeEnd){var d=t(),p=Object.keys(d),b=p.filter(function(A){return c.includes(A)}).map(function(A){return d[A]}),h=[],m=[],v=s.disabled,y=b.map(function(A){var S=A.loaded,E=A.name,C=A.config;return rA(A,function(){return S({config:C})},1e4).then(function(P){return n[E]||(a.dispatch({type:ve.pluginReadyType(E),name:E,events:Object.keys(A).filter(function(I){return!zu.includes(I)})}),n[E]=!0),h=h.concat(E),A}).catch(function(P){if(P instanceof Error)throw new Error(P);return m=m.concat(P.name),P})});Promise.all(y).then(function(A){var S={plugins:h,failed:m,disabled:v};setTimeout(function(){p.length===y.length+v.length&&a.dispatch(ye({},{type:ve.ready},S))},0)})}var w=function(){if(u!==ve.bootstrap)return/^ready:([^:]*)$/.test(u)&&setTimeout(function(){return nA(a,t,e)},0),Promise.resolve(function(A,S,E,C,P){try{var I=sr(S)?S():S,T=A.type,z=T.replace(Qn,"");if(A._&&A._.called)return Promise.resolve(A);var N=E.getState(),W=(_=I,(U=N.plugins)===void 0&&(U={}),(Z=A.options)===void 0&&(Z={}),Object.keys(_).filter(function(O){var R=Z.plugins||{};return HV(R[O])?R[O]:R.all!==!1&&(!U[O]||U[O].enabled!==!1)}).map(function(O){return _[O]}));T===ve.initializeStart&&A.fromEnable&&(W=Object.keys(N.plugins).filter(function(O){var R=N.plugins[O];return A.plugins.includes(O)&&!R.initialized}).map(function(O){return I[O]}));var F=W.map(function(O){return O.name}),V=function(O,R,J){var D=Im(O).map(function(K){return Cm(K,R)});return R.reduce(function(K,$){var ne=$.name,X=Im(O,ne).map(function(ue){return Cm(ue,R)}),se=X[0],te=X[1],ae=X[2];return se.length&&(K.beforeNS[ne]=se),te.length&&(K.duringNS[ne]=te),ae.length&&(K.afterNS[ne]=ae),K},{before:D[0],beforeNS:{},during:D[1],duringNS:{},after:D[2],afterNS:{}})}(T,W);return Promise.resolve(_c({action:A,data:{exact:V.before,namespaced:V.beforeNS},state:N,allPlugins:I,allMatches:V,instance:E,store:C,EVENTS:P})).then(function(O){function R(){var K=function(){if(T.match(Qn))return Promise.resolve(_c({action:ye({},J,{type:z+"End"}),data:{exact:V.after,namespaced:V.afterNS},state:N,allPlugins:I,allMatches:V,instance:E,store:C,EVENTS:P})).then(function($){$.meta&&$.meta.hasCallback&&Sm($.meta.rid,{payload:$})})}();return K&&K.then?K.then(function(){return O}):O}if(aA(O,F.length))return O;var J,D=function(){if(T!==z)return Promise.resolve(_c({action:ye({},O,{type:z}),data:{exact:V.during,namespaced:V.duringNS},state:N,allPlugins:I,allMatches:V,instance:E,store:C,EVENTS:P})).then(function(K){J=K});J=O}();return D&&D.then?D.then(R):R()})}catch(O){return Promise.reject(O)}var _,U,Z}(s,t,e,a,r)).then(function(A){return i=1,o(A)})}();return Promise.resolve(w&&w.then?w.then(l):l(w))}catch(A){return Promise.reject(A)}}}}}function hL(e){return function(t){return function(r){return function(n){var a=n.type,o=n.key,s=n.value,i=n.options;if(a===ve.setItem||a===ve.removeItem){if(n.abort)return r(n);a===ve.setItem?e.setItem(o,s,i):e.removeItem(o,i)}return r(n)}}}}var bL=function(){var e=this;this.before=[],this.after=[],this.addMiddleware=function(t,r){e[r]=e[r].concat(t)},this.removeMiddleware=function(t,r){var n=e[r].findIndex(function(a){return a===t});n!==-1&&(e[r]=[].concat(e[r].slice(0,n),e[r].slice(n+1)))},this.dynamicMiddlewares=function(t){return function(r){return function(n){return function(a){var o={getState:r.getState,dispatch:function(i){return r.dispatch(i)}},s=e[t].map(function(i){return i(o)});return Ca.apply(void 0,s)(n)(a)}}}}};function mL(e){return function(t,r){t===void 0&&(t={});var n={};if(r.type==="initialize:aborted")return t;if(/^registerPlugin:([^:]*)$/.test(r.type)){var a=xm(r.type,"registerPlugin"),o=e()[a];if(!o||!a)return t;var s=r.enabled,i=o.config;return n[a]={enabled:s,initialized:!!s&&!o.initialize,loaded:!!s&&!!o.loaded({config:i}),config:i},ye({},t,n)}if(/^initialize:([^:]*)$/.test(r.type)){var l=xm(r.type,ve.initialize),u=e()[l];return u&&l?(n[l]=ye({},t[l],{initialized:!0,loaded:!!u.loaded({config:u.config})}),ye({},t,n)):t}if(/^ready:([^:]*)$/.test(r.type))return n[r.name]=ye({},t[r.name],{loaded:!0}),ye({},t,n);switch(r.type){case ve.disablePlugin:return ye({},t,Rm(r.plugins,!1,t));case ve.enablePlugin:return ye({},t,Rm(r.plugins,!0,t));default:return t}}}function xm(e,t){return e.substring(t.length+1,e.length)}function Rm(e,t,r){return e.reduce(function(n,a){return n[a]=ye({},r[a],{enabled:t}),n},r)}function oA(e){try{return JSON.parse(JSON.stringify(e))}catch{}return e}var gL={last:{},history:[]};function vL(e,t){e===void 0&&(e=gL);var r=t.options,n=t.meta;if(t.type===ve.track){var a=oA(ye({event:t.event,properties:t.properties},Object.keys(r).length&&{options:r},{meta:n}));return ye({},e,{last:a,history:e.history.concat(a)})}return e}var yL={actions:[]};function wL(e,t){e===void 0&&(e=yL);var r=t.payload;switch(t.type){case"queue":var n;return n=r&&r.type&&r.type===ve.identify?[t].concat(e.actions):e.actions.concat(t),ye({},e,{actions:n});case"dequeue":return[];default:return e}}var sA=/#.*$/;function SL(e){var t=/(http[s]?:\/\/)?([^\/\s]+\/)(.*)/g.exec(e);return"/"+(t&&t[3]?t[3].split("?")[0].replace(sA,""):"")}var iA,lA,cA,uA,AL=function(e){if(e===void 0&&(e={}),!Qt)return e;var t=document,r=t.title,n=t.referrer,a=window,o=a.location,s=a.innerWidth,i=a.innerHeight,l=o.hash,u=o.search,c=function(d){var p=function(){if(Qt){for(var b,h=document.getElementsByTagName("link"),m=0;b=h[m];m++)if(b.getAttribute("rel")==="canonical")return b.getAttribute("href")}}();return p?p.match(/\?/)?p:p+d:window.location.href.replace(sA,"")}(u),f={title:r,url:c,path:SL(c),hash:l,search:u,width:s,height:i};return n&&n!==""&&(f.referrer=n),ye({},f,e)},EL={last:{},history:[]};function OL(e,t){e===void 0&&(e=EL);var r=t.options;if(t.type===ve.page){var n=oA(ye({properties:t.properties,meta:t.meta},Object.keys(r).length&&{options:r}));return ye({},e,{last:n,history:e.history.concat(n)})}return e}iA=function(){if(!Qt)return!1;var e=navigator.appVersion;return~e.indexOf("Win")?"Windows":~e.indexOf("Mac")?"MacOS":~e.indexOf("X11")?"UNIX":~e.indexOf("Linux")?"Linux":"Unknown OS"}(),lA=Qt?document.referrer:null,cA=rL(),uA=nL();var Nm={initialized:!1,sessionId:ac(),app:null,version:null,debug:!1,offline:!!Qt&&!navigator.onLine,os:{name:iA},userAgent:Qt?navigator.userAgent:"node",library:{name:"analytics",version:"0.12.5"},timezone:uA,locale:cA,campaign:{},referrer:lA};function CL(e,t){e===void 0&&(e=Nm);var r=e.initialized,n=t.campaign;switch(t.type){case ve.campaign:return ye({},e,{campaign:n});case ve.offline:return ye({},e,{offline:!0});case ve.online:return ye({},e,{offline:!1});default:return r?e:ye({},Nm,e,{initialized:!0})}}var IL=["plugins","reducers","storage"];function kL(e,t,r){if(Qt){var n=window[(r?"add":"remove")+"EventListener"];e.split(" ").forEach(function(a){n(a,t)})}}function PL(e){var t=kL.bind(null,"online offline",function(r){return Promise.resolve(!navigator.onLine).then(e)});return t(!0),function(r){return t(!1)}}function fA(){return An("analytics",[]),function(e){return function(t,r,n){var a=e(t,r,n),o=a.dispatch;return Object.assign(a,{dispatch:function(s){return Oa[Ea].analytics.push(s.action||s),o(s)}})}}}function Mm(e){return function(){return Ca(Ca.apply(null,arguments),fA())}}function tu(e){return e?XV(e)?e:[e]:[]}function Tm(e,t,r){e===void 0&&(e={});var n,a,o=ac();return t&&(Ha[o]=(n=t,a=function(s){for(var i,l=s||Array.prototype.slice.call(arguments),u=0;u<l.length;u++)if(sr(l[u])){i=l[u];break}return i}(r),function(s){a&&a(s),n(s)})),ye({},e,{rid:o,ts:new Date().getTime()},t?{hasCallback:!0}:{})}function xL(e){e===void 0&&(e={});var t=e.reducers||{},r=e.initialUser||{},n=(e.plugins||[]).reduce(function(O,R){if(sr(R))return O.middlewares=O.middlewares.concat(R),O;if(R.NAMESPACE&&(R.name=R.NAMESPACE),!R.name)throw new Error("https://lytics.dev/errors/1");R.config||(R.config={});var J=R.EVENTS?Object.keys(R.EVENTS).map(function($){return R.EVENTS[$]}):[];O.pluginEnabled[R.name]=!(R.enabled===!1||R.config.enabled===!1),delete R.enabled,R.methods&&(O.methods[R.name]=Object.keys(R.methods).reduce(function($,ne){var X;return $[ne]=(X=R.methods[ne],function(){for(var se=Array.prototype.slice.call(arguments),te=new Array(X.length),ae=0;ae<se.length;ae++)te[ae]=se[ae];return te[te.length]=S,X.apply({instance:S},te)}),$},{}),delete R.methods);var D=Object.keys(R).concat(J),K=new Set(O.events.concat(D));if(O.events=Array.from(K),O.pluginsArray=O.pluginsArray.concat(R),O.plugins[R.name])throw new Error(R.name+"AlreadyLoaded");return O.plugins[R.name]=R,O.plugins[R.name].loaded||(O.plugins[R.name].loaded=function(){return!0}),O},{plugins:{},pluginEnabled:{},methods:{},pluginsArray:[],middlewares:[],events:[]}),a=e.storage?e.storage:{getItem:Sn,setItem:An,removeItem:Ma},o=function(O){return function(R,J,D){return J.getState("user")[R]||(D&&It(D)&&D[R]?D[R]:wm(O)[R]||Sn(qu(R))||null)}}(a),s=n.plugins,i=n.events.filter(function(O){return!zu.includes(O)}).sort(),l=new Set(i.concat(Ws).filter(function(O){return!zu.includes(O)})),u=Array.from(l).sort(),c=function(){return s},f=new bL,d=f.addMiddleware,p=f.removeMiddleware,b=f.dynamicMiddlewares,h=function(){throw new Error("Abort disabled inListener")},m=aL(),v=wm(a),y=ye({},v,r,m.an_uid?{userId:m.an_uid}:{},m.an_aid?{anonymousId:m.an_aid}:{});y.anonymousId||(y.anonymousId=ac());var w=ye({enable:function(O,R){return new Promise(function(J){V.dispatch({type:ve.enablePlugin,plugins:tu(O),_:{originalAction:ve.enablePlugin}},J,[R])})},disable:function(O,R){return new Promise(function(J){V.dispatch({type:ve.disablePlugin,plugins:tu(O),_:{originalAction:ve.disablePlugin}},J,[R])})}},n.methods),A=!1,S={identify:function(O,R,J,D){try{var K=Yn(O)?O:null,$=It(O)?O:R,ne=J||{},X=S.user();An(qu(kr),K);var se=K||$.userId||o(kr,S,$);return Promise.resolve(new Promise(function(te){V.dispatch(ye({type:ve.identifyStart,userId:se,traits:$||{},options:ne,anonymousId:X.anonymousId},X.id&&X.id!==K&&{previousId:X.id}),te,[R,J,D])}))}catch(te){return Promise.reject(te)}},track:function(O,R,J,D){try{var K=It(O)?O.event:O;if(!K||!Yn(K))throw new Error("EventMissing");var $=It(O)?O:R||{},ne=It(J)?J:{};return Promise.resolve(new Promise(function(X){V.dispatch({type:ve.trackStart,event:K,properties:$,options:ne,userId:o(kr,S,R),anonymousId:o(Un,S,R)},X,[R,J,D])}))}catch(X){return Promise.reject(X)}},page:function(O,R,J){try{var D=It(O)?O:{},K=It(R)?R:{};return Promise.resolve(new Promise(function($){V.dispatch({type:ve.pageStart,properties:AL(D),options:K,userId:o(kr,S,D),anonymousId:o(Un,S,D)},$,[O,R,J])}))}catch($){return Promise.reject($)}},user:function(O){if(O===kr||O==="id")return o(kr,S);if(O===Un||O==="anonId")return o(Un,S);var R=S.getState("user");return O?pm(R,O):R},reset:function(O){return new Promise(function(R){V.dispatch({type:ve.resetStart},R,O)})},ready:function(O){return A&&O({plugins:w,instance:S}),S.on(ve.ready,function(R){O(R),A=!0})},on:function(O,R){if(!O||!sr(R))return!1;if(O===ve.bootstrap)throw new Error(".on disabled for "+O);var J=/Start$|Start:/;if(O==="*"){var D=function(X){return function(se){return function(te){return te.type.match(J)&&R({payload:te,instance:S,plugins:s}),se(te)}}},K=function(X){return function(se){return function(te){return te.type.match(J)||R({payload:te,instance:S,plugins:s}),se(te)}}};return d(D,Ns),d(K,Ms),function(){p(D,Ns),p(K,Ms)}}var $=O.match(J)?Ns:Ms,ne=function(X){return function(se){return function(te){return te.type===O&&R({payload:te,instance:S,plugins:s,abort:h}),se(te)}}};return d(ne,$),function(){return p(ne,$)}},once:function(O,R){if(!O||!sr(R))return!1;if(O===ve.bootstrap)throw new Error(".once disabled for "+O);var J=S.on(O,function(D){R({payload:D.payload,instance:S,plugins:s,abort:h}),J()});return J},getState:function(O){var R=V.getState();return O?pm(R,O):Object.assign({},R)},dispatch:function(O){var R=Yn(O)?{type:O}:O;if(Ws.includes(R.type))throw new Error("reserved action "+R.type);var J=ye({},R,{_:ye({originalAction:R.type},O._||{})});V.dispatch(J)},enablePlugin:w.enable,disablePlugin:w.disable,plugins:w,storage:{getItem:a.getItem,setItem:function(O,R,J){V.dispatch({type:ve.setItemStart,key:O,value:R,options:J})},removeItem:function(O,R){V.dispatch({type:ve.removeItemStart,key:O,options:R})}},setAnonymousId:function(O,R){S.storage.setItem(Vr,O,R)},events:{core:Ws,plugins:i}},E=n.middlewares.concat([function(O){return function(R){return function(J){return J.meta||(J.meta=Tm()),R(J)}}},b(Ns),pL(S,c,{all:u,plugins:i}),hL(a),cL(S),fL(S),b(Ms)]),C={context:CL,user:uL(a),page:OL,track:vL,plugins:mL(c),queue:wL},P=Ca,I=Ca;if(Qt&&e.debug){var T=window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;T&&(P=T({trace:!0,traceLimit:25})),I=function(){return arguments.length===0?fA():It(typeof arguments[0])?Mm():Mm().apply(null,arguments)}}var z,N=function(O){return Object.keys(O).reduce(function(R,J){return IL.includes(J)||(R[J]=O[J]),R},{})}(e),W=n.pluginsArray.reduce(function(O,R){var J=R.name,D=R.config,K=R.loaded,$=n.pluginEnabled[J];return O[J]={enabled:$,initialized:!!$&&!R.initialize,loaded:!!K({config:D}),config:D},O},{}),F={context:N,user:y,plugins:W},V=tA(function(O){for(var R=Object.keys(O),J={},D=0;D<R.length;D++){var K=R[D];typeof O[K]===Pr&&(J[K]=O[K])}var $,ne=Object.keys(J);try{(function(X){Object.keys(X).forEach(function(se){var te=X[se];if(typeof te(void 0,{type:"@@redux/INIT"})===mr||typeof te(void 0,{type:sL})===mr)throw new Error("reducer "+se+" "+mr)})})(J)}catch(X){$=X}return function(X,se){if(X===void 0&&(X={}),$)throw $;for(var te=!1,ae={},ue=0;ue<ne.length;ue++){var de=ne[ue],H=X[de],Q=(0,J[de])(H,se);if(typeof Q===mr){var ge=iL(de,se);throw new Error(ge)}ae[de]=Q,te=te||Q!==H}return te?ae:X}}(ye({},C,t)),F,I(P(lL.apply(void 0,E))));V.dispatch=(z=V.dispatch,function(O,R,J){var D=ye({},O,{meta:Tm(O.meta,R,tu(J))});return z.apply(null,[D])});var _=Object.keys(s);V.dispatch({type:ve.bootstrap,plugins:_,config:N,params:m,user:y,initialUser:r,persistedUser:v});var U=_.filter(function(O){return n.pluginEnabled[O]}),Z=_.filter(function(O){return!n.pluginEnabled[O]});return V.dispatch({type:ve.registerPlugins,plugins:_,enabled:n.pluginEnabled}),n.pluginsArray.map(function(O,R){var J=O.bootstrap,D=O.config,K=O.name;J&&sr(J)&&J({instance:S,config:D,payload:O}),V.dispatch({type:ve.registerPluginType(K),name:K,enabled:n.pluginEnabled[K],plugin:O}),n.pluginsArray.length===R+1&&V.dispatch({type:ve.initializeStart,plugins:U,disabled:Z})}),PL(function(O){V.dispatch({type:O?ve.offline:ve.online})}),function(O,R,J){setInterval(function(){return nA(O,R,J)},3e3)}(V,c,S),S}var Ns="before",Ms="after",oo="cookie",tn=hA(),dA=oc,RL=oc;function pA(e){return tn?oc(e,"",-1):Ma(e)}function hA(){if(tn!==void 0)return tn;var e="cookiecookie";try{oc(e,e),tn=document.cookie.indexOf(e)!==-1,pA(e)}catch{tn=!1}return tn}function oc(e,t,r,n,a,o){if(typeof window<"u"){var s=arguments.length>1;return tn===!1&&(s?An(e,t):Sn(e)),s?document.cookie=e+"="+encodeURIComponent(t)+(r?"; expires="+new Date(+new Date+1e3*r).toUTCString()+(n?"; path="+n:"")+(a?"; domain="+a:"")+(o?"; secure":""):""):decodeURIComponent((("; "+document.cookie).split("; "+e+"=")[1]||"").split(";")[0])}}var so="localStorage",NL=gd.bind(null,"localStorage");Ta("localStorage","getItem",Sn);Ta("localStorage","setItem",An);Ta("localStorage","removeItem",Ma);var io="sessionStorage",ML=gd.bind(null,"sessionStorage");Ta("sessionStorage","getItem",Sn);Ta("sessionStorage","setItem",An);Ta("sessionStorage","removeItem",Ma);function Xn(e){var t=e;try{if((t=JSON.parse(e))==="true")return!0;if(t==="false")return!1;if(It(t))return t;parseFloat(t)===t&&(t=parseFloat(t))}catch{}if(t!==null&&t!=="")return t}var TL=NL(),jL=ML(),zL=hA();function bA(e,t){if(e){var r=vd(t),n=!Ad(r),a=yd(r)?Xn(localStorage.getItem(e)):void 0;if(n&&!Wn(a))return a;var o=wd(r)?Xn(dA(e)):void 0;if(n&&o)return o;var s=Sd(r)?Xn(sessionStorage.getItem(e)):void 0;if(n&&s)return s;var i=Sn(e);return n?i:{localStorage:a,sessionStorage:s,cookie:o,global:i}}}function qL(e,t,r){if(e&&!Wn(t)){var n={},a=vd(r),o=JSON.stringify(t),s=!Ad(a);return yd(a)&&(n[so]=Ts(so,t,Xn(localStorage.getItem(e))),localStorage.setItem(e,o),s)?n[so]:wd(a)&&(n[oo]=Ts(oo,t,Xn(dA(e))),RL(e,o),s)?n[oo]:Sd(a)&&(n[io]=Ts(io,t,Xn(sessionStorage.getItem(e))),sessionStorage.setItem(e,o),s)?n[io]:(n[ao]=Ts(ao,t,Sn(e)),An(e,t),s?n[ao]:n)}}function FL(e,t){if(e){var r=vd(t),n=bA(e,XS),a={};return!Wn(n.localStorage)&&yd(r)&&(localStorage.removeItem(e),a[so]=n.localStorage),!Wn(n.cookie)&&wd(r)&&(pA(e),a[oo]=n.cookie),!Wn(n.sessionStorage)&&Sd(r)&&(sessionStorage.removeItem(e),a[io]=n.sessionStorage),!Wn(n.global)&&sc(r,ao)&&(Ma(e),a[ao]=n.global),a}}function vd(e){return e?Yn(e)?e:e.storage:QS}function yd(e){return TL&&sc(e,so)}function wd(e){return zL&&sc(e,oo)}function Sd(e){return jL&&sc(e,io)}function Ad(e){return e===XS||e==="all"}function sc(e,t){return e===QS||e===t||Ad(e)}function Ts(e,t,r){return{location:e,current:t,previous:r}}var DL={setItem:qL,getItem:bA,removeItem:FL};function BL(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function jm(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter(function(a){return Object.getOwnPropertyDescriptor(e,a).enumerable})),r.push.apply(r,n)}return r}function zm(e){for(var t=1;t<arguments.length;t++){var r=arguments[t]!=null?arguments[t]:{};t%2?jm(Object(r),!0).forEach(function(n){BL(e,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):jm(Object(r)).forEach(function(n){Object.defineProperty(e,n,Object.getOwnPropertyDescriptor(r,n))})}return e}function VL(){var e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:{},t={storage:DL};return xL(zm(zm({},t),e))}const LL="@chaibuilder/sdk",KL="1.0.5",WL="module",UL=["dist"],ZL="dist/core.js",JL=!1,GL={".":{import:"./dist/core.js",require:"./dist/core.cjs",types:"./dist/core.d.ts"},"./render":{import:"./dist/render.js",require:"./dist/render.cjs",types:"./dist/render.d.ts"},"./ui":{import:"./dist/ui.js",require:"./dist/ui.cjs",types:"./dist/ui.d.ts"},"./lib":{import:"./dist/lib.js",require:"./dist/lib.cjs",types:"./dist/lib.d.ts"},"./server":{import:"./dist/server.js",require:"./dist/server.cjs",types:"./dist/server.d.ts"},"./styles":{import:"./dist/style.css",require:"./dist/style.css"}},YL={dev:"vite",build:"tsc && vite build",lint:"eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",preview:"vite preview",test:"jest --colors","test:watch":"jest --watch --colors","test:coverage":"jest --coverage --colors",e2e:"playwright test","e2e:report":"playwright show-report","e2e:ui":"playwright test --ui",docs:"jsdoc -c jsdoc.conf.json"},HL={"@bobthered/tailwindcss-palette-generator":"3.1.1","@chaibuilder/blocks":"^0.2.0","@floating-ui/dom":"1.4.5","@floating-ui/react-dom":"2.0.1","@mhsdesign/jit-browser-tailwindcss":"0.3.0","@minoru/react-dnd-treeview":"3.4.4","@radix-ui/react-accordion":"^1.1.2","@radix-ui/react-alert-dialog":"^1.0.4","@radix-ui/react-context-menu":"^2.1.4","@radix-ui/react-dialog":"^1.0.4","@radix-ui/react-dropdown-menu":"^2.0.5","@radix-ui/react-hover-card":"^1.0.6","@radix-ui/react-icons":"^1.3.0","@radix-ui/react-label":"^2.0.2","@radix-ui/react-menubar":"^1.0.3","@radix-ui/react-navigation-menu":"^1.1.3","@radix-ui/react-popover":"^1.0.6","@radix-ui/react-scroll-area":"^1.0.4","@radix-ui/react-select":"^1.2.2","@radix-ui/react-separator":"^1.0.3","@radix-ui/react-slot":"^1.0.2","@radix-ui/react-switch":"^1.0.3","@radix-ui/react-tabs":"^1.0.4","@radix-ui/react-toast":"^1.1.4","@radix-ui/react-toggle":"^1.0.3","@radix-ui/react-tooltip":"^1.0.6","@react-hookz/web":"23.1.0","@rjsf/core":"5.11.2","@rjsf/utils":"5.11.2","@rjsf/validator-ajv8":"5.11.2","@tailwindcss/aspect-ratio":"0.4.2","@tailwindcss/forms":"^0.5.6","@tailwindcss/line-clamp":"^0.4.4","@tailwindcss/typography":"^0.5.10","@tanstack/react-query":"^5.8.4",analytics:"^0.8.9","class-variance-authority":"0.6.1",clsx:"1.2.1",cmdk:"0.2.0","date-fns":"^2.30.0",flagged:"2.0.9","flat-to-nested":"1.1.1","focus-trap-react":"^10.2.1","forgiving-xml-parser":"1.4.0","framer-motion":"^10.12.18","fuse.js":"6.6.2","gray-matter":"^4.0.3",himalaya:"^1.1.0","html-formatter":"0.1.9",i18next:"^23.2.8",jotai:"2.2.2",lodash:"4.17.21","lucide-react":"^0.244.0",nanoid:"^4.0.2","post-robot":"10.0.46",react:"^18","react-autosuggest":"10.1.0","react-colorful":"5.6.1","react-dnd":"16.0.1","react-dnd-html5-backend":"16.0.1","react-dom":"^18","react-hotkeys-hook":"4.4.1","react-i18next":"13.0.1","react-icons":"^4.10.1","react-icons-picker":"^1.0.9","react-json-view":"^1.21.3","react-quill":"^2.0.0","react-textarea-autosize":"^8.5.2","react-wrap-balancer":"^1.0.0","redux-undo":"1.1.0",sonner:"^1.2.0","tailwind-merge":"1.13.2","tailwindcss-animate":"1.0.6","tippy.js":"^6.3.7","unist-util-visit":"^4.1.2","unsplash-js":"^7.0.18"},QL={"@commitlint/cli":"17.7.1","@commitlint/config-conventional":"17.7.0","@emotion/react":"^11.11.1","@faker-js/faker":"^8.3.1","@nozbe/watermelondb":"^0.27.1","@playwright/test":"^1.39.0","@tanstack/eslint-plugin-query":"^5.8.4","@testing-library/react-hooks":"^8.0.1","@types/better-sqlite3":"^7.6.7","@types/jest":"^29.5.7","@types/lodash":"^4.14.200","@types/node":"^20.8.10","@types/react":"^18.2.15","@types/react-dom":"^18.2.7","@typescript-eslint/eslint-plugin":"^6.0.0","@typescript-eslint/parser":"^6.0.0","@vitejs/plugin-react-swc":"^3.3.2",autoprefixer:"^10.4.16","better-docs":"^2.7.2","better-sqlite3":"^9.1.1","drizzle-kit":"^0.20.4","drizzle-orm":"^0.29.0",eslint:"^8.45.0","eslint-plugin-react-hooks":"^4.6.0","eslint-plugin-react-refresh":"^0.4.3",jest:"^29.7.0","jest-environment-jsdom":"^29.7.0","jotai-devtools":"^0.7.1",jsdoc:"^4.0.2",msw:"^2.0.8",postcss:"^8.4.31",prettier:"^3.0.3","prettier-plugin-tailwindcss":"^0.5.6","prop-types":"^15.8.1","react-router-dom":"^6.19.0",tailwindcss:"^3.3.5","ts-jest":"^29.1.1",typescript:"^5.0.2",vite:"^4.4.5","vite-plugin-dts":"^3.6.3"},XL={workerDirectory:"public"},_L={name:LL,private:!1,version:KL,type:WL,files:UL,main:ZL,sideEffects:JL,exports:GL,scripts:YL,dependencies:HL,devDependencies:QL,msw:XL},qm="https://api.chaibuilder.com",Fm=()=>typeof window>"u"?!1:window.location.href.includes("localhost");function $L(){return{name:"chaibuilder-analytics",config:{},initialize:()=>{if(typeof window>"u")return!1;window.chaibuilderAnalyticsLoaded=!0},page:e=>{if(typeof window>"u")return!1;if(Fm())return;const{payload:t}=e;fetch(`${qm}/v1/log`,{method:"post",body:JSON.stringify(t)}).then(r=>r.json())},track:({payload:e})=>{if(typeof window>"u")return!1;Fm()||fetch(`${qm}/v1/log`,{method:"post",body:JSON.stringify(e)})},loaded:()=>typeof window>"u"?!0:!!window.chaibuilderAnalyticsLoaded}}const eK=VL({app:"chaibuilder",version:_L.version,plugins:[$L()]});({}).NODE_ENV==="development"&&console.log("Chai Builder:",QA);const tK=e=>ee.jsxRuntimeExports.jsx(ee.jsxRuntimeExports.Fragment,{children:e.children}),rK=e=>{const{dndOptions:t={backend:Pd.MultiBackend}}=e,[r]=dS(),[,n]=ld(),a=md();return g.useEffect(()=>{dm.set(je.chaiBuilderPropsAtom,B.omit(e,["blocks","subPages","brandingOptions","dataProvidersAtom"]))},[e]),g.useEffect(()=>{dm.set(dd,e.dataProviders||[])},[e.dataProviders]),g.useEffect(()=>{r(sg.syncBlocksWithDefaults(e.blocks||[])),a()},[e.blocks]),g.useEffect(()=>{n(e.brandingOptions)},[e.brandingOptions,n]),g.useEffect(()=>{eK.page()},[]),ee.jsxRuntimeExports.jsx(VA.DndProvider,{...t,options:Pd.getBackendOptions(),children:ee.jsxRuntimeExports.jsx(tK,{children:ee.jsxRuntimeExports.jsx(ZV,{})})})},mA=e=>ee.jsxRuntimeExports.jsxs(sS,{children:[ee.jsxRuntimeExports.jsxs(BA.FlagsProvider,{features:uB,children:[ee.jsxRuntimeExports.jsx(cB,{}),ee.jsxRuntimeExports.jsx(rK,{...e})]}),ee.jsxRuntimeExports.jsx(je.Toaster,{})]});var ja=class{constructor(){this.listeners=new Set,this.subscribe=this.subscribe.bind(this)}subscribe(e){return this.listeners.add(e),this.onSubscribe(),()=>{this.listeners.delete(e),this.onUnsubscribe()}}hasListeners(){return this.listeners.size>0}onSubscribe(){}onUnsubscribe(){}},Ia=typeof window>"u"||"Deno"in window;function Vt(){}function nK(e,t){return typeof e=="function"?e(t):e}function Fu(e){return typeof e=="number"&&e>=0&&e!==1/0}function gA(e,t){return Math.max(e+(t||0)-Date.now(),0)}function Dm(e,t){const{type:r="all",exact:n,fetchStatus:a,predicate:o,queryKey:s,stale:i}=e;if(s){if(n){if(t.queryHash!==Ed(s,t.options))return!1}else if(!vo(t.queryKey,s))return!1}if(r!=="all"){const l=t.isActive();if(r==="active"&&!l||r==="inactive"&&l)return!1}return!(typeof i=="boolean"&&t.isStale()!==i||typeof a<"u"&&a!==t.state.fetchStatus||o&&!o(t))}function Bm(e,t){const{exact:r,status:n,predicate:a,mutationKey:o}=e;if(o){if(!t.options.mutationKey)return!1;if(r){if(go(t.options.mutationKey)!==go(o))return!1}else if(!vo(t.options.mutationKey,o))return!1}return!(n&&t.state.status!==n||a&&!a(t))}function Ed(e,t){return((t==null?void 0:t.queryKeyHashFn)||go)(e)}function go(e){return JSON.stringify(e,(t,r)=>Du(r)?Object.keys(r).sort().reduce((n,a)=>(n[a]=r[a],n),{}):r)}function vo(e,t){return e===t?!0:typeof e!=typeof t?!1:e&&t&&typeof e=="object"&&typeof t=="object"?!Object.keys(t).some(r=>!vo(e[r],t[r])):!1}function vA(e,t){if(e===t)return e;const r=Vm(e)&&Vm(t);if(r||Du(e)&&Du(t)){const n=r?e.length:Object.keys(e).length,a=r?t:Object.keys(t),o=a.length,s=r?[]:{};let i=0;for(let l=0;l<o;l++){const u=r?l:a[l];s[u]=vA(e[u],t[u]),s[u]===e[u]&&i++}return n===o&&i===n?e:s}return t}function wl(e,t){if(e&&!t||t&&!e)return!1;for(const r in e)if(e[r]!==t[r])return!1;return!0}function Vm(e){return Array.isArray(e)&&e.length===Object.keys(e).length}function Du(e){if(!Lm(e))return!1;const t=e.constructor;if(typeof t>"u")return!0;const r=t.prototype;return!(!Lm(r)||!r.hasOwnProperty("isPrototypeOf"))}function Lm(e){return Object.prototype.toString.call(e)==="[object Object]"}function yA(e){return new Promise(t=>{setTimeout(t,e)})}function Km(e){yA(0).then(e)}function Bu(e,t,r){return typeof r.structuralSharing=="function"?r.structuralSharing(e,t):r.structuralSharing!==!1?vA(e,t):t}function aK(e,t,r=0){const n=[...e,t];return r&&n.length>r?n.slice(1):n}function oK(e,t,r=0){const n=[t,...e];return r&&n.length>r?n.slice(0,-1):n}var an,xr,_n,Gm,sK=(Gm=class extends ja{constructor(){super();fe(this,an,void 0);fe(this,xr,void 0);fe(this,_n,void 0);ie(this,_n,t=>{if(!Ia&&window.addEventListener){const r=()=>t();return window.addEventListener("visibilitychange",r,!1),()=>{window.removeEventListener("visibilitychange",r)}}})}onSubscribe(){x(this,xr)||this.setEventListener(x(this,_n))}onUnsubscribe(){var t;this.hasListeners()||((t=x(this,xr))==null||t.call(this),ie(this,xr,void 0))}setEventListener(t){var r;ie(this,_n,t),(r=x(this,xr))==null||r.call(this),ie(this,xr,t(n=>{typeof n=="boolean"?this.setFocused(n):this.onFocus()}))}setFocused(t){x(this,an)!==t&&(ie(this,an,t),this.onFocus())}onFocus(){this.listeners.forEach(t=>{t()})}isFocused(){var t;return typeof x(this,an)=="boolean"?x(this,an):((t=globalThis.document)==null?void 0:t.visibilityState)!=="hidden"}},an=new WeakMap,xr=new WeakMap,_n=new WeakMap,Gm),Sl=new sK,$n,Rr,ea,Ym,iK=(Ym=class extends ja{constructor(){super();fe(this,$n,!0);fe(this,Rr,void 0);fe(this,ea,void 0);ie(this,ea,t=>{if(!Ia&&window.addEventListener){const r=()=>t(!0),n=()=>t(!1);return window.addEventListener("online",r,!1),window.addEventListener("offline",n,!1),()=>{window.removeEventListener("online",r),window.removeEventListener("offline",n)}}})}onSubscribe(){x(this,Rr)||this.setEventListener(x(this,ea))}onUnsubscribe(){var t;this.hasListeners()||((t=x(this,Rr))==null||t.call(this),ie(this,Rr,void 0))}setEventListener(t){var r;ie(this,ea,t),(r=x(this,Rr))==null||r.call(this),ie(this,Rr,t(this.setOnline.bind(this)))}setOnline(t){x(this,$n)!==t&&(ie(this,$n,t),this.listeners.forEach(n=>{n(t)}))}isOnline(){return x(this,$n)}},$n=new WeakMap,Rr=new WeakMap,ea=new WeakMap,Ym),Al=new iK;function lK(e){return Math.min(1e3*2**e,3e4)}function ic(e){return(e??"online")==="online"?Al.isOnline():!0}var wA=class{constructor(e){this.revert=e==null?void 0:e.revert,this.silent=e==null?void 0:e.silent}};function ru(e){return e instanceof wA}function SA(e){let t=!1,r=0,n=!1,a,o,s;const i=new Promise((m,v)=>{o=m,s=v}),l=m=>{var v;n||(p(new wA(m)),(v=e.abort)==null||v.call(e))},u=()=>{t=!0},c=()=>{t=!1},f=()=>!Sl.isFocused()||e.networkMode!=="always"&&!Al.isOnline(),d=m=>{var v;n||(n=!0,(v=e.onSuccess)==null||v.call(e,m),a==null||a(),o(m))},p=m=>{var v;n||(n=!0,(v=e.onError)==null||v.call(e,m),a==null||a(),s(m))},b=()=>new Promise(m=>{var v;a=y=>{const w=n||!f();return w&&m(y),w},(v=e.onPause)==null||v.call(e)}).then(()=>{var m;a=void 0,n||(m=e.onContinue)==null||m.call(e)}),h=()=>{if(n)return;let m;try{m=e.fn()}catch(v){m=Promise.reject(v)}Promise.resolve(m).then(d).catch(v=>{var E;if(n)return;const y=e.retry??(Ia?0:3),w=e.retryDelay??lK,A=typeof w=="function"?w(r,v):w,S=y===!0||typeof y=="number"&&r<y||typeof y=="function"&&y(r,v);if(t||!S){p(v);return}r++,(E=e.onFail)==null||E.call(e,r,v),yA(A).then(()=>{if(f())return b()}).then(()=>{t?p(v):h()})})};return ic(e.networkMode)?h():b().then(h),{promise:i,cancel:l,continue:()=>(a==null?void 0:a())?i:Promise.resolve(),cancelRetry:u,continueRetry:c}}function cK(){let e=[],t=0,r=c=>{c()},n=c=>{c()};const a=c=>{let f;t++;try{f=c()}finally{t--,t||i()}return f},o=c=>{t?e.push(c):Km(()=>{r(c)})},s=c=>(...f)=>{o(()=>{c(...f)})},i=()=>{const c=e;e=[],c.length&&Km(()=>{n(()=>{c.forEach(f=>{r(f)})})})};return{batch:a,batchCalls:s,schedule:o,setNotifyFunction:c=>{r=c},setBatchNotifyFunction:c=>{n=c}}}var Xe=cK(),on,Hm,AA=(Hm=class{constructor(){fe(this,on,void 0)}destroy(){this.clearGcTimeout()}scheduleGc(){this.clearGcTimeout(),Fu(this.gcTime)&&ie(this,on,setTimeout(()=>{this.optionalRemove()},this.gcTime))}updateGcTime(e){this.gcTime=Math.max(this.gcTime||0,e??(Ia?1/0:5*60*1e3))}clearGcTimeout(){x(this,on)&&(clearTimeout(x(this,on)),ie(this,on,void 0))}},on=new WeakMap,Hm),ta,ra,qt,Nr,Ft,$e,yo,sn,na,Us,Yt,dr,Qm,uK=(Qm=class extends AA{constructor(t){super();fe(this,na);fe(this,Yt);fe(this,ta,void 0);fe(this,ra,void 0);fe(this,qt,void 0);fe(this,Nr,void 0);fe(this,Ft,void 0);fe(this,$e,void 0);fe(this,yo,void 0);fe(this,sn,void 0);ie(this,sn,!1),ie(this,yo,t.defaultOptions),Se(this,na,Us).call(this,t.options),ie(this,$e,[]),ie(this,qt,t.cache),this.queryKey=t.queryKey,this.queryHash=t.queryHash,ie(this,ta,t.state||fK(this.options)),this.state=x(this,ta),this.scheduleGc()}get meta(){return this.options.meta}optionalRemove(){!x(this,$e).length&&this.state.fetchStatus==="idle"&&x(this,qt).remove(this)}setData(t,r){const n=Bu(this.state.data,t,this.options);return Se(this,Yt,dr).call(this,{data:n,type:"success",dataUpdatedAt:r==null?void 0:r.updatedAt,manual:r==null?void 0:r.manual}),n}setState(t,r){Se(this,Yt,dr).call(this,{type:"setState",state:t,setStateOptions:r})}cancel(t){var n;const r=x(this,Nr);return(n=x(this,Ft))==null||n.cancel(t),r?r.then(Vt).catch(Vt):Promise.resolve()}destroy(){super.destroy(),this.cancel({silent:!0})}reset(){this.destroy(),this.setState(x(this,ta))}isActive(){return x(this,$e).some(t=>t.options.enabled!==!1)}isDisabled(){return this.getObserversCount()>0&&!this.isActive()}isStale(){return this.state.isInvalidated||!this.state.dataUpdatedAt||x(this,$e).some(t=>t.getCurrentResult().isStale)}isStaleByTime(t=0){return this.state.isInvalidated||!this.state.dataUpdatedAt||!gA(this.state.dataUpdatedAt,t)}onFocus(){var r;const t=x(this,$e).find(n=>n.shouldFetchOnWindowFocus());t==null||t.refetch({cancelRefetch:!1}),(r=x(this,Ft))==null||r.continue()}onOnline(){var r;const t=x(this,$e).find(n=>n.shouldFetchOnReconnect());t==null||t.refetch({cancelRefetch:!1}),(r=x(this,Ft))==null||r.continue()}addObserver(t){x(this,$e).includes(t)||(x(this,$e).push(t),this.clearGcTimeout(),x(this,qt).notify({type:"observerAdded",query:this,observer:t}))}removeObserver(t){x(this,$e).includes(t)&&(ie(this,$e,x(this,$e).filter(r=>r!==t)),x(this,$e).length||(x(this,Ft)&&(x(this,sn)?x(this,Ft).cancel({revert:!0}):x(this,Ft).cancelRetry()),this.scheduleGc()),x(this,qt).notify({type:"observerRemoved",query:this,observer:t}))}getObserversCount(){return x(this,$e).length}invalidate(){this.state.isInvalidated||Se(this,Yt,dr).call(this,{type:"invalidate"})}fetch(t,r){var u,c,f,d;if(this.state.fetchStatus!=="idle"){if(this.state.dataUpdatedAt&&(r!=null&&r.cancelRefetch))this.cancel({silent:!0});else if(x(this,Nr))return(u=x(this,Ft))==null||u.continueRetry(),x(this,Nr)}if(t&&Se(this,na,Us).call(this,t),!this.options.queryFn){const p=x(this,$e).find(b=>b.options.queryFn);p&&Se(this,na,Us).call(this,p.options)}process.env.NODE_ENV!=="production"&&(Array.isArray(this.options.queryKey)||console.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']"));const n=new AbortController,a={queryKey:this.queryKey,meta:this.meta},o=p=>{Object.defineProperty(p,"signal",{enumerable:!0,get:()=>(ie(this,sn,!0),n.signal)})};o(a);const s=()=>this.options.queryFn?(ie(this,sn,!1),this.options.persister?this.options.persister(this.options.queryFn,a,this):this.options.queryFn(a)):Promise.reject(new Error(`Missing queryFn: '${this.options.queryHash}'`)),i={fetchOptions:r,options:this.options,queryKey:this.queryKey,state:this.state,fetchFn:s};o(i),(c=this.options.behavior)==null||c.onFetch(i,this),ie(this,ra,this.state),(this.state.fetchStatus==="idle"||this.state.fetchMeta!==((f=i.fetchOptions)==null?void 0:f.meta))&&Se(this,Yt,dr).call(this,{type:"fetch",meta:(d=i.fetchOptions)==null?void 0:d.meta});const l=p=>{var b,h,m,v;ru(p)&&p.silent||Se(this,Yt,dr).call(this,{type:"error",error:p}),ru(p)||((h=(b=x(this,qt).config).onError)==null||h.call(b,p,this),(v=(m=x(this,qt).config).onSettled)==null||v.call(m,this.state.data,p,this)),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1};return ie(this,Ft,SA({fn:i.fetchFn,abort:n.abort.bind(n),onSuccess:p=>{var b,h,m,v;if(typeof p>"u"){process.env.NODE_ENV!=="production"&&console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`),l(new Error(`${this.queryHash} data is undefined`));return}this.setData(p),(h=(b=x(this,qt).config).onSuccess)==null||h.call(b,p,this),(v=(m=x(this,qt).config).onSettled)==null||v.call(m,p,this.state.error,this),this.isFetchingOptimistic||this.scheduleGc(),this.isFetchingOptimistic=!1},onError:l,onFail:(p,b)=>{Se(this,Yt,dr).call(this,{type:"failed",failureCount:p,error:b})},onPause:()=>{Se(this,Yt,dr).call(this,{type:"pause"})},onContinue:()=>{Se(this,Yt,dr).call(this,{type:"continue"})},retry:i.options.retry,retryDelay:i.options.retryDelay,networkMode:i.options.networkMode})),ie(this,Nr,x(this,Ft).promise),x(this,Nr)}},ta=new WeakMap,ra=new WeakMap,qt=new WeakMap,Nr=new WeakMap,Ft=new WeakMap,$e=new WeakMap,yo=new WeakMap,sn=new WeakMap,na=new WeakSet,Us=function(t){this.options={...x(this,yo),...t},this.updateGcTime(this.options.gcTime)},Yt=new WeakSet,dr=function(t){const r=n=>{switch(t.type){case"failed":return{...n,fetchFailureCount:t.failureCount,fetchFailureReason:t.error};case"pause":return{...n,fetchStatus:"paused"};case"continue":return{...n,fetchStatus:"fetching"};case"fetch":return{...n,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:t.meta??null,fetchStatus:ic(this.options.networkMode)?"fetching":"paused",...!n.dataUpdatedAt&&{error:null,status:"pending"}};case"success":return{...n,data:t.data,dataUpdateCount:n.dataUpdateCount+1,dataUpdatedAt:t.dataUpdatedAt??Date.now(),error:null,isInvalidated:!1,status:"success",...!t.manual&&{fetchStatus:"idle",fetchFailureCount:0,fetchFailureReason:null}};case"error":const a=t.error;return ru(a)&&a.revert&&x(this,ra)?{...x(this,ra),fetchStatus:"idle"}:{...n,error:a,errorUpdateCount:n.errorUpdateCount+1,errorUpdatedAt:Date.now(),fetchFailureCount:n.fetchFailureCount+1,fetchFailureReason:a,fetchStatus:"idle",status:"error"};case"invalidate":return{...n,isInvalidated:!0};case"setState":return{...n,...t.state}}};this.state=r(this.state),Xe.batch(()=>{x(this,$e).forEach(n=>{n.onQueryUpdate()}),x(this,qt).notify({query:this,type:"updated",action:t})})},Qm);function fK(e){const t=typeof e.initialData=="function"?e.initialData():e.initialData,r=typeof t<"u",n=r?typeof e.initialDataUpdatedAt=="function"?e.initialDataUpdatedAt():e.initialDataUpdatedAt:0;return{data:t,dataUpdateCount:0,dataUpdatedAt:r?n??Date.now():0,error:null,errorUpdateCount:0,errorUpdatedAt:0,fetchFailureCount:0,fetchFailureReason:null,fetchMeta:null,isInvalidated:!1,status:r?"success":"pending",fetchStatus:"idle"}}var $t,Xm,dK=(Xm=class extends ja{constructor(t={}){super();fe(this,$t,void 0);this.config=t,ie(this,$t,new Map)}build(t,r,n){const a=r.queryKey,o=r.queryHash??Ed(a,r);let s=this.get(o);return s||(s=new uK({cache:this,queryKey:a,queryHash:o,options:t.defaultQueryOptions(r),state:n,defaultOptions:t.getQueryDefaults(a)}),this.add(s)),s}add(t){x(this,$t).has(t.queryHash)||(x(this,$t).set(t.queryHash,t),this.notify({type:"added",query:t}))}remove(t){const r=x(this,$t).get(t.queryHash);r&&(t.destroy(),r===t&&x(this,$t).delete(t.queryHash),this.notify({type:"removed",query:t}))}clear(){Xe.batch(()=>{this.getAll().forEach(t=>{this.remove(t)})})}get(t){return x(this,$t).get(t)}getAll(){return[...x(this,$t).values()]}find(t){const r={exact:!0,...t};return this.getAll().find(n=>Dm(r,n))}findAll(t={}){const r=this.getAll();return Object.keys(t).length>0?r.filter(n=>Dm(t,n)):r}notify(t){Xe.batch(()=>{this.listeners.forEach(r=>{r(t)})})}onFocus(){Xe.batch(()=>{this.getAll().forEach(t=>{t.onFocus()})})}onOnline(){Xe.batch(()=>{this.getAll().forEach(t=>{t.onOnline()})})}},$t=new WeakMap,Xm),er,wo,Ct,aa,tr,Ir,_m,pK=(_m=class extends AA{constructor(t){super();fe(this,tr);fe(this,er,void 0);fe(this,wo,void 0);fe(this,Ct,void 0);fe(this,aa,void 0);this.mutationId=t.mutationId,ie(this,wo,t.defaultOptions),ie(this,Ct,t.mutationCache),ie(this,er,[]),this.state=t.state||EA(),this.setOptions(t.options),this.scheduleGc()}setOptions(t){this.options={...x(this,wo),...t},this.updateGcTime(this.options.gcTime)}get meta(){return this.options.meta}addObserver(t){x(this,er).includes(t)||(x(this,er).push(t),this.clearGcTimeout(),x(this,Ct).notify({type:"observerAdded",mutation:this,observer:t}))}removeObserver(t){ie(this,er,x(this,er).filter(r=>r!==t)),this.scheduleGc(),x(this,Ct).notify({type:"observerRemoved",mutation:this,observer:t})}optionalRemove(){x(this,er).length||(this.state.status==="pending"?this.scheduleGc():x(this,Ct).remove(this))}continue(){var t;return((t=x(this,aa))==null?void 0:t.continue())??this.execute(this.state.variables)}async execute(t){var a,o,s,i,l,u,c,f,d,p,b,h,m,v,y,w,A,S,E,C;const r=()=>(ie(this,aa,SA({fn:()=>this.options.mutationFn?this.options.mutationFn(t):Promise.reject(new Error("No mutationFn found")),onFail:(P,I)=>{Se(this,tr,Ir).call(this,{type:"failed",failureCount:P,error:I})},onPause:()=>{Se(this,tr,Ir).call(this,{type:"pause"})},onContinue:()=>{Se(this,tr,Ir).call(this,{type:"continue"})},retry:this.options.retry??0,retryDelay:this.options.retryDelay,networkMode:this.options.networkMode})),x(this,aa).promise),n=this.state.status==="pending";try{if(!n){Se(this,tr,Ir).call(this,{type:"pending",variables:t}),await((o=(a=x(this,Ct).config).onMutate)==null?void 0:o.call(a,t,this));const I=await((i=(s=this.options).onMutate)==null?void 0:i.call(s,t));I!==this.state.context&&Se(this,tr,Ir).call(this,{type:"pending",context:I,variables:t})}const P=await r();return await((u=(l=x(this,Ct).config).onSuccess)==null?void 0:u.call(l,P,t,this.state.context,this)),await((f=(c=this.options).onSuccess)==null?void 0:f.call(c,P,t,this.state.context)),await((p=(d=x(this,Ct).config).onSettled)==null?void 0:p.call(d,P,null,this.state.variables,this.state.context,this)),await((h=(b=this.options).onSettled)==null?void 0:h.call(b,P,null,t,this.state.context)),Se(this,tr,Ir).call(this,{type:"success",data:P}),P}catch(P){try{throw await((v=(m=x(this,Ct).config).onError)==null?void 0:v.call(m,P,t,this.state.context,this)),await((w=(y=this.options).onError)==null?void 0:w.call(y,P,t,this.state.context)),await((S=(A=x(this,Ct).config).onSettled)==null?void 0:S.call(A,void 0,P,this.state.variables,this.state.context,this)),await((C=(E=this.options).onSettled)==null?void 0:C.call(E,void 0,P,t,this.state.context)),P}finally{Se(this,tr,Ir).call(this,{type:"error",error:P})}}}},er=new WeakMap,wo=new WeakMap,Ct=new WeakMap,aa=new WeakMap,tr=new WeakSet,Ir=function(t){const r=n=>{switch(t.type){case"failed":return{...n,failureCount:t.failureCount,failureReason:t.error};case"pause":return{...n,isPaused:!0};case"continue":return{...n,isPaused:!1};case"pending":return{...n,context:t.context,data:void 0,failureCount:0,failureReason:null,error:null,isPaused:!ic(this.options.networkMode),status:"pending",variables:t.variables,submittedAt:Date.now()};case"success":return{...n,data:t.data,failureCount:0,failureReason:null,error:null,status:"success",isPaused:!1};case"error":return{...n,data:void 0,error:t.error,failureCount:n.failureCount+1,failureReason:t.error,isPaused:!1,status:"error"}}};this.state=r(this.state),Xe.batch(()=>{x(this,er).forEach(n=>{n.onMutationUpdate(t)}),x(this,Ct).notify({mutation:this,type:"updated",action:t})})},_m);function EA(){return{context:void 0,data:void 0,error:null,failureCount:0,failureReason:null,isPaused:!1,status:"idle",variables:void 0,submittedAt:0}}var Dt,So,ln,$m,hK=($m=class extends ja{constructor(t={}){super();fe(this,Dt,void 0);fe(this,So,void 0);fe(this,ln,void 0);this.config=t,ie(this,Dt,[]),ie(this,So,0)}build(t,r,n){const a=new pK({mutationCache:this,mutationId:++ns(this,So)._,options:t.defaultMutationOptions(r),state:n});return this.add(a),a}add(t){x(this,Dt).push(t),this.notify({type:"added",mutation:t})}remove(t){ie(this,Dt,x(this,Dt).filter(r=>r!==t)),this.notify({type:"removed",mutation:t})}clear(){Xe.batch(()=>{x(this,Dt).forEach(t=>{this.remove(t)})})}getAll(){return x(this,Dt)}find(t){const r={exact:!0,...t};return x(this,Dt).find(n=>Bm(r,n))}findAll(t={}){return x(this,Dt).filter(r=>Bm(t,r))}notify(t){Xe.batch(()=>{this.listeners.forEach(r=>{r(t)})})}resumePausedMutations(){return ie(this,ln,(x(this,ln)??Promise.resolve()).then(()=>{const t=x(this,Dt).filter(r=>r.state.isPaused);return Xe.batch(()=>t.reduce((r,n)=>r.then(()=>n.continue().catch(Vt)),Promise.resolve()))}).then(()=>{ie(this,ln,void 0)})),x(this,ln)}},Dt=new WeakMap,So=new WeakMap,ln=new WeakMap,$m);function bK(e){return{onFetch:(t,r)=>{const n=async()=>{var b,h,m,v,y;const a=t.options,o=(m=(h=(b=t.fetchOptions)==null?void 0:b.meta)==null?void 0:h.fetchMore)==null?void 0:m.direction,s=((v=t.state.data)==null?void 0:v.pages)||[],i=((y=t.state.data)==null?void 0:y.pageParams)||[],l={pages:[],pageParams:[]};let u=!1;const c=w=>{Object.defineProperty(w,"signal",{enumerable:!0,get:()=>(t.signal.aborted?u=!0:t.signal.addEventListener("abort",()=>{u=!0}),t.signal)})},f=t.options.queryFn||(()=>Promise.reject(new Error(`Missing queryFn: '${t.options.queryHash}'`))),d=async(w,A,S)=>{if(u)return Promise.reject();if(A==null&&w.pages.length)return Promise.resolve(w);const E={queryKey:t.queryKey,pageParam:A,direction:S?"backward":"forward",meta:t.options.meta};c(E);const C=await f(E),{maxPages:P}=t.options,I=S?oK:aK;return{pages:I(w.pages,C,P),pageParams:I(w.pageParams,A,P)}};let p;if(o&&s.length){const w=o==="backward",A=w?mK:Wm,S={pages:s,pageParams:i},E=A(a,S);p=await d(S,E,w)}else{p=await d(l,i[0]??a.initialPageParam);const w=e??s.length;for(let A=1;A<w;A++){const S=Wm(a,p);p=await d(p,S)}}return p};t.options.persister?t.fetchFn=()=>{var a,o;return(o=(a=t.options).persister)==null?void 0:o.call(a,n,{queryKey:t.queryKey,meta:t.options.meta,signal:t.signal},r)}:t.fetchFn=n}}}function Wm(e,{pages:t,pageParams:r}){const n=t.length-1;return e.getNextPageParam(t[n],t,r[n],r)}function mK(e,{pages:t,pageParams:r}){var n;return(n=e.getPreviousPageParam)==null?void 0:n.call(e,t[0],t,r[0],r)}var Ye,Mr,Tr,oa,sa,jr,ia,la,eg,gK=(eg=class{constructor(e={}){fe(this,Ye,void 0);fe(this,Mr,void 0);fe(this,Tr,void 0);fe(this,oa,void 0);fe(this,sa,void 0);fe(this,jr,void 0);fe(this,ia,void 0);fe(this,la,void 0);ie(this,Ye,e.queryCache||new dK),ie(this,Mr,e.mutationCache||new hK),ie(this,Tr,e.defaultOptions||{}),ie(this,oa,new Map),ie(this,sa,new Map),ie(this,jr,0)}mount(){ns(this,jr)._++,x(this,jr)===1&&(ie(this,ia,Sl.subscribe(()=>{Sl.isFocused()&&(this.resumePausedMutations(),x(this,Ye).onFocus())})),ie(this,la,Al.subscribe(()=>{Al.isOnline()&&(this.resumePausedMutations(),x(this,Ye).onOnline())})))}unmount(){var e,t;ns(this,jr)._--,x(this,jr)===0&&((e=x(this,ia))==null||e.call(this),ie(this,ia,void 0),(t=x(this,la))==null||t.call(this),ie(this,la,void 0))}isFetching(e){return x(this,Ye).findAll({...e,fetchStatus:"fetching"}).length}isMutating(e){return x(this,Mr).findAll({...e,status:"pending"}).length}getQueryData(e){var t;return(t=x(this,Ye).find({queryKey:e}))==null?void 0:t.state.data}ensureQueryData(e){const t=this.getQueryData(e.queryKey);return t!==void 0?Promise.resolve(t):this.fetchQuery(e)}getQueriesData(e){return this.getQueryCache().findAll(e).map(({queryKey:t,state:r})=>{const n=r.data;return[t,n]})}setQueryData(e,t,r){const n=x(this,Ye).find({queryKey:e}),a=n==null?void 0:n.state.data,o=nK(t,a);if(typeof o>"u")return;const s=this.defaultQueryOptions({queryKey:e});return x(this,Ye).build(this,s).setData(o,{...r,manual:!0})}setQueriesData(e,t,r){return Xe.batch(()=>this.getQueryCache().findAll(e).map(({queryKey:n})=>[n,this.setQueryData(n,t,r)]))}getQueryState(e){var t;return(t=x(this,Ye).find({queryKey:e}))==null?void 0:t.state}removeQueries(e){const t=x(this,Ye);Xe.batch(()=>{t.findAll(e).forEach(r=>{t.remove(r)})})}resetQueries(e,t){const r=x(this,Ye),n={type:"active",...e};return Xe.batch(()=>(r.findAll(e).forEach(a=>{a.reset()}),this.refetchQueries(n,t)))}cancelQueries(e={},t={}){const r={revert:!0,...t},n=Xe.batch(()=>x(this,Ye).findAll(e).map(a=>a.cancel(r)));return Promise.all(n).then(Vt).catch(Vt)}invalidateQueries(e={},t={}){return Xe.batch(()=>{if(x(this,Ye).findAll(e).forEach(n=>{n.invalidate()}),e.refetchType==="none")return Promise.resolve();const r={...e,type:e.refetchType??e.type??"active"};return this.refetchQueries(r,t)})}refetchQueries(e={},t){const r={...t,cancelRefetch:(t==null?void 0:t.cancelRefetch)??!0},n=Xe.batch(()=>x(this,Ye).findAll(e).filter(a=>!a.isDisabled()).map(a=>{let o=a.fetch(void 0,r);return r.throwOnError||(o=o.catch(Vt)),a.state.fetchStatus==="paused"?Promise.resolve():o}));return Promise.all(n).then(Vt)}fetchQuery(e){const t=this.defaultQueryOptions(e);typeof t.retry>"u"&&(t.retry=!1);const r=x(this,Ye).build(this,t);return r.isStaleByTime(t.staleTime)?r.fetch(t):Promise.resolve(r.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(Vt).catch(Vt)}fetchInfiniteQuery(e){return e.behavior=bK(e.pages),this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(Vt).catch(Vt)}resumePausedMutations(){return x(this,Mr).resumePausedMutations()}getQueryCache(){return x(this,Ye)}getMutationCache(){return x(this,Mr)}getDefaultOptions(){return x(this,Tr)}setDefaultOptions(e){ie(this,Tr,e)}setQueryDefaults(e,t){x(this,oa).set(go(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){const t=[...x(this,oa).values()];let r={};return t.forEach(n=>{vo(e,n.queryKey)&&(r={...r,...n.defaultOptions})}),r}setMutationDefaults(e,t){x(this,sa).set(go(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){const t=[...x(this,sa).values()];let r={};return t.forEach(n=>{vo(e,n.mutationKey)&&(r={...r,...n.defaultOptions})}),r}defaultQueryOptions(e){if(e!=null&&e._defaulted)return e;const t={...x(this,Tr).queries,...(e==null?void 0:e.queryKey)&&this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||(t.queryHash=Ed(t.queryKey,t)),typeof t.refetchOnReconnect>"u"&&(t.refetchOnReconnect=t.networkMode!=="always"),typeof t.throwOnError>"u"&&(t.throwOnError=!!t.suspense),typeof t.networkMode>"u"&&t.persister&&(t.networkMode="offlineFirst"),t}defaultMutationOptions(e){return e!=null&&e._defaulted?e:{...x(this,Tr).mutations,...(e==null?void 0:e.mutationKey)&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){x(this,Ye).clear(),x(this,Mr).clear()}},Ye=new WeakMap,Mr=new WeakMap,Tr=new WeakMap,oa=new WeakMap,sa=new WeakMap,jr=new WeakMap,ia=new WeakMap,la=new WeakMap,eg),mt,Me,ca,ot,cn,ua,rr,Ao,fa,da,un,fn,zr,dn,pn,Qa,Eo,Vu,Oo,Lu,Co,Ku,Io,Wu,ko,Uu,Po,Zu,xo,Ju,El,OA,tg,vK=(tg=class extends ja{constructor(t,r){super();fe(this,pn);fe(this,Eo);fe(this,Oo);fe(this,Co);fe(this,Io);fe(this,ko);fe(this,Po);fe(this,xo);fe(this,El);fe(this,mt,void 0);fe(this,Me,void 0);fe(this,ca,void 0);fe(this,ot,void 0);fe(this,cn,void 0);fe(this,ua,void 0);fe(this,rr,void 0);fe(this,Ao,void 0);fe(this,fa,void 0);fe(this,da,void 0);fe(this,un,void 0);fe(this,fn,void 0);fe(this,zr,void 0);fe(this,dn,void 0);ie(this,Me,void 0),ie(this,ca,void 0),ie(this,ot,void 0),ie(this,dn,new Set),ie(this,mt,t),this.options=r,ie(this,rr,null),this.bindMethods(),this.setOptions(r)}bindMethods(){this.refetch=this.refetch.bind(this)}onSubscribe(){this.listeners.size===1&&(x(this,Me).addObserver(this),Um(x(this,Me),this.options)?Se(this,pn,Qa).call(this):this.updateResult(),Se(this,Io,Wu).call(this))}onUnsubscribe(){this.hasListeners()||this.destroy()}shouldFetchOnReconnect(){return Gu(x(this,Me),this.options,this.options.refetchOnReconnect)}shouldFetchOnWindowFocus(){return Gu(x(this,Me),this.options,this.options.refetchOnWindowFocus)}destroy(){this.listeners=new Set,Se(this,ko,Uu).call(this),Se(this,Po,Zu).call(this),x(this,Me).removeObserver(this)}setOptions(t,r){const n=this.options,a=x(this,Me);if(this.options=x(this,mt).defaultQueryOptions(t),wl(n,this.options)||x(this,mt).getQueryCache().notify({type:"observerOptionsUpdated",query:x(this,Me),observer:this}),typeof this.options.enabled<"u"&&typeof this.options.enabled!="boolean")throw new Error("Expected enabled to be a boolean");this.options.queryKey||(this.options.queryKey=n.queryKey),Se(this,xo,Ju).call(this);const o=this.hasListeners();o&&Zm(x(this,Me),a,this.options,n)&&Se(this,pn,Qa).call(this),this.updateResult(r),o&&(x(this,Me)!==a||this.options.enabled!==n.enabled||this.options.staleTime!==n.staleTime)&&Se(this,Eo,Vu).call(this);const s=Se(this,Oo,Lu).call(this);o&&(x(this,Me)!==a||this.options.enabled!==n.enabled||s!==x(this,zr))&&Se(this,Co,Ku).call(this,s)}getOptimisticResult(t){const r=x(this,mt).getQueryCache().build(x(this,mt),t),n=this.createResult(r,t);return wK(this,n)&&(ie(this,ot,n),ie(this,ua,this.options),ie(this,cn,x(this,Me).state)),n}getCurrentResult(){return x(this,ot)}trackResult(t){const r={};return Object.keys(t).forEach(n=>{Object.defineProperty(r,n,{configurable:!1,enumerable:!0,get:()=>(x(this,dn).add(n),t[n])})}),r}getCurrentQuery(){return x(this,Me)}refetch({...t}={}){return this.fetch({...t})}fetchOptimistic(t){const r=x(this,mt).defaultQueryOptions(t),n=x(this,mt).getQueryCache().build(x(this,mt),r);return n.isFetchingOptimistic=!0,n.fetch().then(()=>this.createResult(n,r))}fetch(t){return Se(this,pn,Qa).call(this,{...t,cancelRefetch:t.cancelRefetch??!0}).then(()=>(this.updateResult(),x(this,ot)))}createResult(t,r){var E;const n=x(this,Me),a=this.options,o=x(this,ot),s=x(this,cn),i=x(this,ua),u=t!==n?t.state:x(this,ca),{state:c}=t;let{error:f,errorUpdatedAt:d,fetchStatus:p,status:b}=c,h=!1,m;if(r._optimisticResults){const C=this.hasListeners(),P=!C&&Um(t,r),I=C&&Zm(t,n,r,a);(P||I)&&(p=ic(t.options.networkMode)?"fetching":"paused",c.dataUpdatedAt||(b="pending")),r._optimisticResults==="isRestoring"&&(p="idle")}if(r.select&&typeof c.data<"u")if(o&&c.data===(s==null?void 0:s.data)&&r.select===x(this,Ao))m=x(this,fa);else try{ie(this,Ao,r.select),m=r.select(c.data),m=Bu(o==null?void 0:o.data,m,r),ie(this,fa,m),ie(this,rr,null)}catch(C){ie(this,rr,C)}else m=c.data;if(typeof r.placeholderData<"u"&&typeof m>"u"&&b==="pending"){let C;if(o!=null&&o.isPlaceholderData&&r.placeholderData===(i==null?void 0:i.placeholderData))C=o.data;else if(C=typeof r.placeholderData=="function"?r.placeholderData((E=x(this,da))==null?void 0:E.state.data,x(this,da)):r.placeholderData,r.select&&typeof C<"u")try{C=r.select(C),ie(this,rr,null)}catch(P){ie(this,rr,P)}typeof C<"u"&&(b="success",m=Bu(o==null?void 0:o.data,C,r),h=!0)}x(this,rr)&&(f=x(this,rr),m=x(this,fa),d=Date.now(),b="error");const v=p==="fetching",y=b==="pending",w=b==="error",A=y&&v;return{status:b,fetchStatus:p,isPending:y,isSuccess:b==="success",isError:w,isInitialLoading:A,isLoading:A,data:m,dataUpdatedAt:c.dataUpdatedAt,error:f,errorUpdatedAt:d,failureCount:c.fetchFailureCount,failureReason:c.fetchFailureReason,errorUpdateCount:c.errorUpdateCount,isFetched:c.dataUpdateCount>0||c.errorUpdateCount>0,isFetchedAfterMount:c.dataUpdateCount>u.dataUpdateCount||c.errorUpdateCount>u.errorUpdateCount,isFetching:v,isRefetching:v&&!y,isLoadingError:w&&c.dataUpdatedAt===0,isPaused:p==="paused",isPlaceholderData:h,isRefetchError:w&&c.dataUpdatedAt!==0,isStale:Od(t,r),refetch:this.refetch}}updateResult(t){const r=x(this,ot),n=this.createResult(x(this,Me),this.options);if(ie(this,cn,x(this,Me).state),ie(this,ua,this.options),x(this,cn).data!==void 0&&ie(this,da,x(this,Me)),wl(n,r))return;ie(this,ot,n);const a={},o=()=>{if(!r)return!0;const{notifyOnChangeProps:s}=this.options,i=typeof s=="function"?s():s;if(i==="all"||!i&&!x(this,dn).size)return!0;const l=new Set(i??x(this,dn));return this.options.throwOnError&&l.add("error"),Object.keys(x(this,ot)).some(u=>{const c=u;return x(this,ot)[c]!==r[c]&&l.has(c)})};(t==null?void 0:t.listeners)!==!1&&o()&&(a.listeners=!0),Se(this,El,OA).call(this,{...a,...t})}onQueryUpdate(){this.updateResult(),this.hasListeners()&&Se(this,Io,Wu).call(this)}},mt=new WeakMap,Me=new WeakMap,ca=new WeakMap,ot=new WeakMap,cn=new WeakMap,ua=new WeakMap,rr=new WeakMap,Ao=new WeakMap,fa=new WeakMap,da=new WeakMap,un=new WeakMap,fn=new WeakMap,zr=new WeakMap,dn=new WeakMap,pn=new WeakSet,Qa=function(t){Se(this,xo,Ju).call(this);let r=x(this,Me).fetch(this.options,t);return t!=null&&t.throwOnError||(r=r.catch(Vt)),r},Eo=new WeakSet,Vu=function(){if(Se(this,ko,Uu).call(this),Ia||x(this,ot).isStale||!Fu(this.options.staleTime))return;const r=gA(x(this,ot).dataUpdatedAt,this.options.staleTime)+1;ie(this,un,setTimeout(()=>{x(this,ot).isStale||this.updateResult()},r))},Oo=new WeakSet,Lu=function(){return(typeof this.options.refetchInterval=="function"?this.options.refetchInterval(x(this,Me)):this.options.refetchInterval)??!1},Co=new WeakSet,Ku=function(t){Se(this,Po,Zu).call(this),ie(this,zr,t),!(Ia||this.options.enabled===!1||!Fu(x(this,zr))||x(this,zr)===0)&&ie(this,fn,setInterval(()=>{(this.options.refetchIntervalInBackground||Sl.isFocused())&&Se(this,pn,Qa).call(this)},x(this,zr)))},Io=new WeakSet,Wu=function(){Se(this,Eo,Vu).call(this),Se(this,Co,Ku).call(this,Se(this,Oo,Lu).call(this))},ko=new WeakSet,Uu=function(){x(this,un)&&(clearTimeout(x(this,un)),ie(this,un,void 0))},Po=new WeakSet,Zu=function(){x(this,fn)&&(clearInterval(x(this,fn)),ie(this,fn,void 0))},xo=new WeakSet,Ju=function(){const t=x(this,mt).getQueryCache().build(x(this,mt),this.options);if(t===x(this,Me))return;const r=x(this,Me);ie(this,Me,t),ie(this,ca,t.state),this.hasListeners()&&(r==null||r.removeObserver(this),t.addObserver(this))},El=new WeakSet,OA=function(t){Xe.batch(()=>{t.listeners&&this.listeners.forEach(r=>{r(x(this,ot))}),x(this,mt).getQueryCache().notify({query:x(this,Me),type:"observerResultsUpdated"})})},tg);function yK(e,t){return t.enabled!==!1&&!e.state.dataUpdatedAt&&!(e.state.status==="error"&&t.retryOnMount===!1)}function Um(e,t){return yK(e,t)||e.state.dataUpdatedAt>0&&Gu(e,t,t.refetchOnMount)}function Gu(e,t,r){if(t.enabled!==!1){const n=typeof r=="function"?r(e):r;return n==="always"||n!==!1&&Od(e,t)}return!1}function Zm(e,t,r,n){return r.enabled!==!1&&(e!==t||n.enabled===!1)&&(!r.suspense||e.state.status!=="error")&&Od(e,r)}function Od(e,t){return e.isStaleByTime(t.staleTime)}function wK(e,t){return!wl(e.getCurrentResult(),t)}var qr,lt,Bt,hr,pa,Zs,Ro,Yu,rg,SK=(rg=class extends ja{constructor(t,r){super();fe(this,pa);fe(this,Ro);fe(this,qr,void 0);fe(this,lt,void 0);fe(this,Bt,void 0);fe(this,hr,void 0);ie(this,lt,void 0),ie(this,qr,t),this.setOptions(r),this.bindMethods(),Se(this,pa,Zs).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var n;const r=this.options;this.options=x(this,qr).defaultMutationOptions(t),wl(r,this.options)||x(this,qr).getMutationCache().notify({type:"observerOptionsUpdated",mutation:x(this,Bt),observer:this}),(n=x(this,Bt))==null||n.setOptions(this.options)}onUnsubscribe(){var t;this.hasListeners()||(t=x(this,Bt))==null||t.removeObserver(this)}onMutationUpdate(t){Se(this,pa,Zs).call(this),Se(this,Ro,Yu).call(this,t)}getCurrentResult(){return x(this,lt)}reset(){ie(this,Bt,void 0),Se(this,pa,Zs).call(this),Se(this,Ro,Yu).call(this)}mutate(t,r){var n;return ie(this,hr,r),(n=x(this,Bt))==null||n.removeObserver(this),ie(this,Bt,x(this,qr).getMutationCache().build(x(this,qr),this.options)),x(this,Bt).addObserver(this),x(this,Bt).execute(t)}},qr=new WeakMap,lt=new WeakMap,Bt=new WeakMap,hr=new WeakMap,pa=new WeakSet,Zs=function(){var r;const t=((r=x(this,Bt))==null?void 0:r.state)??EA();ie(this,lt,{...t,isPending:t.status==="pending",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset})},Ro=new WeakSet,Yu=function(t){Xe.batch(()=>{var r,n,a,o,s,i,l,u;x(this,hr)&&this.hasListeners()&&((t==null?void 0:t.type)==="success"?((n=(r=x(this,hr)).onSuccess)==null||n.call(r,t.data,x(this,lt).variables,x(this,lt).context),(o=(a=x(this,hr)).onSettled)==null||o.call(a,t.data,null,x(this,lt).variables,x(this,lt).context)):(t==null?void 0:t.type)==="error"&&((i=(s=x(this,hr)).onError)==null||i.call(s,t.error,x(this,lt).variables,x(this,lt).context),(u=(l=x(this,hr)).onSettled)==null||u.call(l,void 0,t.error,x(this,lt).variables,x(this,lt).context))),this.listeners.forEach(c=>{c(x(this,lt))})})},rg),CA=k.createContext(void 0),Mt=e=>{const t=k.useContext(CA);if(e)return e;if(!t)throw new Error("No QueryClient set, use QueryClientProvider to set one");return t},AK=({client:e,children:t})=>(k.useEffect(()=>(e.mount(),()=>{e.unmount()}),[e]),k.createElement(CA.Provider,{value:e},t)),IA=k.createContext(!1),EK=()=>k.useContext(IA);IA.Provider;function OK(){let e=!1;return{clearReset:()=>{e=!1},reset:()=>{e=!0},isReset:()=>e}}var CK=k.createContext(OK()),IK=()=>k.useContext(CK);function kA(e,t){return typeof e=="function"?e(...t):!!e}var kK=(e,t)=>{(e.suspense||e.throwOnError)&&(t.isReset()||(e.retryOnMount=!1))},PK=e=>{k.useEffect(()=>{e.clearReset()},[e])},xK=({result:e,errorResetBoundary:t,throwOnError:r,query:n})=>e.isError&&!t.isReset()&&!e.isFetching&&kA(r,[e.error,n]),RK=e=>{e.suspense&&typeof e.staleTime!="number"&&(e.staleTime=1e3)},NK=(e,t)=>(e==null?void 0:e.suspense)&&t.isPending,MK=(e,t,r)=>t.fetchOptimistic(e).catch(()=>{r.clearReset()});function TK(e,t,r){if(process.env.NODE_ENV!=="production"&&(typeof e!="object"||Array.isArray(e)))throw new Error('Bad argument type. Starting with v5, only the "Object" form is allowed when calling query related functions. Please use the error stack to find the culprit call. More info here: https://tanstack.com/query/latest/docs/react/guides/migrating-to-v5#supports-a-single-signature-one-object');const n=Mt(r),a=EK(),o=IK(),s=n.defaultQueryOptions(e);s._optimisticResults=a?"isRestoring":"optimistic",RK(s),kK(s,o),PK(o);const[i]=k.useState(()=>new t(n,s)),l=i.getOptimisticResult(s);if(k.useSyncExternalStore(k.useCallback(u=>{const c=a?()=>{}:i.subscribe(Xe.batchCalls(u));return i.updateResult(),c},[i,a]),()=>i.getCurrentResult(),()=>i.getCurrentResult()),k.useEffect(()=>{i.setOptions(s,{listeners:!1})},[s,i]),NK(s,l))throw MK(s,i,o);if(xK({result:l,errorResetBoundary:o,throwOnError:s.throwOnError,query:i.getCurrentQuery()}))throw l.error;return s.notifyOnChangeProps?l:i.trackResult(l)}function Jo(e,t){return TK(e,vK,t)}function Xt(e,t){const r=Mt(t),[n]=k.useState(()=>new SK(r,e));k.useEffect(()=>{n.setOptions(e)},[n,e]);const a=k.useSyncExternalStore(k.useCallback(s=>n.subscribe(Xe.batchCalls(s)),[n]),()=>n.getCurrentResult(),()=>n.getCurrentResult()),o=k.useCallback((s,i)=>{n.mutate(s,i).catch(jK)},[n]);if(a.error&&kA(n.options.throwOnError,[a.error]))throw a.error;return{...a,mutate:o,mutateAsync:a.mutate}}function jK(){}function it(){return Mt().getQueryData(["apiBaseUrl"])||"/api/chaibuilder"}const Jr=()=>{const{data:e,refetch:t}=Jo({queryKey:["currentPage"],queryFn:()=>localStorage.getItem("currentPage")||""});return[e,r=>{r&&(localStorage.setItem("currentPage",r||""),t())}]};let js="";const Go=()=>js||(js=localStorage.getItem("__chai_at"),js);function zK(e){const t={method:"GET",headers:{"x-chai-access-token":Go()}};return fetch(e,t)}function qK(e,t){const r={method:"POST",headers:{"x-chai-access-token":Go()},body:JSON.stringify(t)};return fetch(e,r)}function FK(e,t){const r={method:"PUT",headers:{"x-chai-access-token":Go()},body:JSON.stringify(t)};return fetch(e,r)}function DK(e,t){const r={method:"DELETE",headers:{"x-chai-access-token":Go()},body:JSON.stringify(t)};return fetch(e,r)}const Tt={get:zK,post:qK,put:FK,delete:DK},lc=()=>{const[e,t]=Jr(),r=it();return Jo({queryKey:["project"],queryFn:async()=>{const{data:n}=await Tt.get(`${r}/project`).then(a=>a.json());if(!e&&n){const a=localStorage.getItem("currentPage");t(a||(n==null?void 0:n.homepage))}return n}})},Cd=()=>{const e=it();return Jo({queryKey:["pages"],queryFn:async()=>{const{data:t}=await Tt.get(`${e}/pages`).then(r=>r.json());return t||[]}})},PA=()=>{const[e,t]=Jr(),{data:r}=lc(),n=it();return Jo({queryKey:["page_data",e],queryFn:async()=>{const{data:a}=await Tt.get(`${n}/page?uuid=${e}`).then(o=>o.json());return a.ok?a.json():(t(r.homepage),null)},enabled:!!e,staleTime:3e3})},Hu=()=>ee.jsxRuntimeExports.jsx("div",{className:"h-screen w-screen bg-gray-200",children:ee.jsxRuntimeExports.jsxs("div",{className:"flex flex-col h-full w-full justify-center items-center",children:[ee.jsxRuntimeExports.jsxs("div",{className:"flex flex-row gap-2",children:[ee.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-orange-600 animate-bounce [animation-delay:.6s]"}),ee.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-blue-600 animate-bounce [animation-delay:.4s]"}),ee.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-green-600 animate-bounce [animation-delay:.2s]"}),ee.jsxRuntimeExports.jsx("div",{className:"w-4 h-4 rounded-full bg-yellow-600 animate-bounce [animation-delay:.0s]"})]}),ee.jsxRuntimeExports.jsx("div",{className:"text-gray-700 font-thin",children:"Loading Builder..."})]})}),xA=(e="Project updated successfully.")=>{const t=Mt(),r=it();return Xt({mutationFn:async n=>await Tt.put(`${r}/project`,n).then(a=>a.json()),onSuccess:()=>{t.invalidateQueries({queryKey:["project"]}),ir.toast.success(e)}})},RA=()=>{const[e]=["SAVED"],[t,r]=Jr(),n=md();return a=>e!=="SAVED"?(ir.toast.error("You have unsaved changes. Please save before changing the page."),!1):t===a.uuid?!1:(n(),setTimeout(()=>{r(a.uuid)},100),!0)},BK=()=>{const e=Mt(),t=RA(),r=it();return Xt({mutationFn:async n=>Tt.post(`${r}/pages`,n).then(a=>a.json()),onSuccess:n=>{e.invalidateQueries({queryKey:["pages"]}),t({uuid:n.uuid,slug:n.slug}),ir.toast.success("Page added successfully.")}})},NA=()=>{const e=it(),[t]=Jr(),r=Mt();return Xt({mutationFn:async n=>Tt.put(`${e}/page`,n).then(a=>a.json()),onSuccess:async n=>{var o;const a=await n.json();if(a.result==="error"&&((o=a.error)==null?void 0:o.code)=="PAGE_LOCKED"){r.invalidateQueries({queryKey:["page_data",t]});return}ir.toast.success("Page saved successfully.")}})},VK=()=>{const e=it(),{data:t}=Cd(),[r]=Jr(),{data:n}=lc(),a=Mt();return Xt({mutationFn:async()=>{const o=t.find(s=>s.uuid===r).slug;return await Tt.post(`${e}/publish`,{slug:o,uuid:r,isHomepage:(n==null?void 0:n.homepage)===r}).then(s=>s.json())},onSuccess:async o=>{var i;const s=await o.json();if(s.result==="error"&&((i=s.error)==null?void 0:i.code)=="PAGE_LOCKED"){a.invalidateQueries({queryKey:["page_data",r]});return}ir.toast.success("Page published successfully.",{position:"top-right",duration:2e3})}})},LK=()=>{const e=Mt(),t=it();return Xt({mutationFn:async r=>Tt.delete(`${t}/page`,r).then(n=>n.json()),onSuccess:()=>{ir.toast.success("Page deleted successfully."),e.invalidateQueries({queryKey:["pages"]})}})},KK=()=>{const e=Mt(),t=it();return Xt({mutationFn:async r=>Tt.post(`${t}/take-control`,{uuid:r}).then(n=>n.json()),onSuccess:(r,n)=>{e.invalidateQueries({queryKey:["page_data",n]})}})},WK=()=>{const e=it();return Xt({mutationFn:async()=>{const{data:t}=await Tt.get(`${e}/library`).then(r=>r.json());return B.sortBy(B.filter(t,r=>!B.has(r,"hidden")),"group")}})},UK=()=>{const e=it();return Xt({mutationFn:async t=>{if(!t||!t.uuid)return[];try{const{data:r}=await Tt.get(`${e}/block?uuid=${t.uuid}&format=${t.format}`).then(async n=>t.format==="html"?vt.getBlocksFromHTML(await n.text()):await n.json());return B.set(r,"0._name",B.capitalize(t.group)),r||[]}catch{return[]}}})},ZK=()=>{const e=it();return Xt({mutationFn:async t=>{const r=new FormData;r.append("file",t);const{data:n}=await fetch(`${e}/upload`,{method:"POST",headers:{"x-chai-access-token":Go()},body:r}).then(a=>a.json());return n}})},JK=()=>{const{mutate:e,isPending:t}=KK(),[r]=Jr(),{data:n}=PA(),a=B.get(n,"lockedBy.name",""),o=B.get(n,"lockedBy.email","");return ee.jsxRuntimeExports.jsxs("div",{className:"p-5 w-fit text-center bg-white mx-auto border rounded-md shadow-xl text-red-500",children:["This page is currently locked for editing by another user. ",ee.jsxRuntimeExports.jsx("br",{}),' If you take over editing, "',a,"<",o,'>" will be blocked from editing.',ee.jsxRuntimeExports.jsx("br",{})," ",ee.jsxRuntimeExports.jsx("br",{}),ee.jsxRuntimeExports.jsx(je.Button,{disabled:t,onClick:()=>e(r),children:t?"Processing...":"Take Over"})," "]})},GK=()=>{const e=it(),t=Mt();return Xt({mutationFn:async r=>{const n=await fetch(`${e}/login`,{method:"POST",body:JSON.stringify(r)});if(n.ok)return await n.json();throw n.status===401?new Error("Invalid login credentials"):new Error("Invalid")},onSuccess:r=>{const{data:n}=r;if(!n.accessToken){ir.toast.error("Something went wrong. Please try again.",{position:"top-center"});return}localStorage.setItem("__chai_at",n.accessToken),localStorage.setItem("__chai_ur",JSON.stringify(B.omit(n,["accessToken"]))),t.invalidateQueries({queryKey:["verify"]}),ir.toast.success("Logged in successfully.")},onError:()=>{ir.toast.error("Invalid login credentials. Please try again.",{position:"top-center"})}})},YK=()=>{const e=it();return Jo({queryKey:["verify"],queryFn:async()=>{if(!localStorage.getItem("__chai_at"))return{valid:!1};const r=await Tt.get(`${e}/verify`);return r.ok?(await r.json()).result==="success"?{valid:!0}:(localStorage.removeItem("__chai_at"),{valid:!1}):(localStorage.removeItem("__chai_at"),{valid:!0})}})},HK=()=>{const e=it(),t=Mt();return Xt({mutationFn:async()=>{const{result:r}=await Tt.post(`${e}/logout`).then(n=>n.json());if(r==="success")return localStorage.clear(),t.invalidateQueries({queryKey:["verify"]}),{logout:!0};throw new Error("Invalid session")}})},QK=({children:e})=>{const t=HK();return ee.jsxRuntimeExports.jsxs(je.AlertDialog,{children:[ee.jsxRuntimeExports.jsx(je.AlertDialogTrigger,{asChild:!0,children:e}),ee.jsxRuntimeExports.jsxs(je.AlertDialogContent,{children:[ee.jsxRuntimeExports.jsxs(je.AlertDialogHeader,{children:[ee.jsxRuntimeExports.jsxs(je.AlertDialogTitle,{children:["Are you sure, you want to ",ee.jsxRuntimeExports.jsx("span",{className:"text-red-500",children:"Sign Out"}),"?"]}),ee.jsxRuntimeExports.jsx(je.AlertDialogDescription,{children:"Kindly ensure that all your data is saved before proceeding with the sign-out process to prevent any potential loss of unsaved information"})]}),ee.jsxRuntimeExports.jsxs(je.AlertDialogFooter,{children:[ee.jsxRuntimeExports.jsx(je.AlertDialogCancel,{disabled:t.isPending,children:"Cancel"}),ee.jsxRuntimeExports.jsxs("button",{disabled:t.isPending,onClick:()=>t.mutate(),className:"rounded-md text-white w-28 text-center justify-center bg-red-600 hover:bg-red-700 flex items-center gap-x-2",children:[t.isPending&&ee.jsxRuntimeExports.jsx(ig.Loader2,{className:"animate-spin w-5 h-5"}),"Sign Out"]})]})]})]})},XK=()=>ee.jsxRuntimeExports.jsx(QK,{children:ee.jsxRuntimeExports.jsx("button",{className:"border-gray-200 rounded-md p-2 mb-2 border",children:ee.jsxRuntimeExports.jsx(ig.LogOutIcon,{className:"w-4 h-4 text-red-500 cursor-pointer hover:text-red-300 duration-300"})})}),_K=XK,$K=g.lazy(()=>Promise.resolve().then(()=>require("./PagesPanel-53b0eff4.cjs"))),eW=g.lazy(()=>Promise.resolve().then(()=>require("./ProjectPanel-c0f6a656.cjs"))),tW=g.lazy(()=>Promise.resolve().then(()=>require("./CurrentPage-7a6d4643.cjs"))),rW=()=>ee.jsxRuntimeExports.jsx("h2",{children:"Your Logo"}),nW=()=>{const{mutate:e}=VK();return je.useBuilderProp("editable",!0)?ee.jsxRuntimeExports.jsx(je.Button,{onClick:e,className:"bg-blue-600 text-white",children:"Publish"}):null},aW=e=>{const{data:t,isLoading:r}=lc(),{data:n,isLoading:a}=Cd(),{data:o}=PA(),{mutate:s}=xA(),{mutate:i}=NA(),[l]=Jr(),u=ZK(),c=WK(),f=UK(),d=it(),p=g.useCallback(async y=>await u.mutateAsync(y),[u]),b=g.useCallback(async()=>await c.mutateAsync(),[c]),h=g.useCallback(async y=>await f.mutateAsync(y),[f]),m=async(y=20,w=0)=>{const A=`limit=${y}&offset=${w}`;return await fetch(`${d}/assets?${A}`).then(S=>S.json())},{logo:v=rW}=e;return r||!t?ee.jsxRuntimeExports.jsx(Hu,{}):a||!n?ee.jsxRuntimeExports.jsx(Hu,{}):ee.jsxRuntimeExports.jsx("div",{className:"bg-background text-foreground",children:ee.jsxRuntimeExports.jsx(mA,{editable:o!=null&&o.lockedBy?o==null?void 0:o.lockedBy.self:!0,nonEditableComponent:JK,blocks:(o==null?void 0:o.blocks)||[],brandingOptions:t.brandingOptions,darkMode:e.darkMode||!1,dataProviders:(o==null?void 0:o.providers)||[],onSavePage:async({blocks:y,providers:w})=>(await i({blocks:y,providers:w,uuid:l}),!0),onSaveBrandingOptions:async y=>(await s({brandingOptions:y}),!0),topBarComponents:{left:[v],center:[tW],right:[nW]},sideBarComponents:{top:[{icon:Js.FileTextIcon,name:"pages",panel:$K},{icon:Js.GearIcon,name:"settings",panel:eW}],bottom:[_K]},uploadMediaCallback:p,fetchMediaCallback:m,getUILibraryBlocks:b,getExternalPredefinedBlock:h,getPages:()=>n,unsplashAccessKey:e.unsplashAccessKey||""})})};var MA={color:void 0,size:void 0,className:void 0,style:void 0,attr:void 0},Jm=g.createContext&&g.createContext(MA),Lr=globalThis&&globalThis.__assign||function(){return Lr=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++){t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},Lr.apply(this,arguments)},oW=globalThis&&globalThis.__rest||function(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(e!=null&&typeof Object.getOwnPropertySymbols=="function")for(var a=0,n=Object.getOwnPropertySymbols(e);a<n.length;a++)t.indexOf(n[a])<0&&Object.prototype.propertyIsEnumerable.call(e,n[a])&&(r[n[a]]=e[n[a]]);return r};function TA(e){return e&&e.map(function(t,r){return g.createElement(t.tag,Lr({key:r},t.attr),TA(t.child))})}function sW(e){return function(t){return g.createElement(iW,Lr({attr:Lr({},e.attr)},t),TA(e.child))}}function iW(e){var t=function(r){var n=e.attr,a=e.size,o=e.title,s=oW(e,["attr","size","title"]),i=a||r.size||"1em",l;return r.className&&(l=r.className),e.className&&(l=(l?l+" ":"")+e.className),g.createElement("svg",Lr({stroke:"currentColor",fill:"currentColor",strokeWidth:"0"},r.attr,n,s,{className:l,style:Lr(Lr({color:e.color||r.color},r.style),e.style),height:i,width:i,xmlns:"http://www.w3.org/2000/svg"}),o&&g.createElement("title",null,o),e.children)};return Jm!==void 0?g.createElement(Jm.Consumer,null,function(r){return t(r)}):t(MA)}function lW(e){return sW({tag:"svg",attr:{viewBox:"0 0 24 24"},child:[{tag:"path",attr:{fill:"none",d:"M0 0h24v24H0z"}},{tag:"path",attr:{d:"M20 4H4c-1.1 0-1.99.9-1.99 2L2 18c0 1.1.9 2 2 2h16c1.1 0 2-.9 2-2V6c0-1.1-.9-2-2-2zm0 4l-8 5-8-5V6l8 5 8-5v2z"}}]})(e)}const cW=({logo:e})=>{const[t,r]=g.useState(!1),[n,a]=g.useState(""),[o,s]=g.useState(""),{mutate:i,isPending:l}=GK(),u=c=>{c.preventDefault(),i({email:n,password:o})};return ee.jsxRuntimeExports.jsx("section",{className:"h-screen w-screen flex items-center justify-center bg-[radial-gradient(#AAA,transparent_0.5px)] duration-300 [background-size:6px_6px]",children:ee.jsxRuntimeExports.jsx("div",{className:"overflow-hidden bg-white rounded-xl w-96 drop-shadow-2xl duration-300",children:ee.jsxRuntimeExports.jsxs("div",{className:"p-12",children:[ee.jsxRuntimeExports.jsxs("div",{className:"max-w-2xl mx-auto text-center",children:[ee.jsxRuntimeExports.jsx(g.Suspense,{children:e?g.createElement(e):""}),ee.jsxRuntimeExports.jsx("p",{className:"max-w-xl mx-auto text-base leading-relaxed text-gray-700 font-thin",children:"Enter your login credential to continue"})]}),ee.jsxRuntimeExports.jsx("div",{className:"mt-8",children:ee.jsxRuntimeExports.jsxs("form",{method:"POST",onSubmit:u,className:"space-y-5",children:[ee.jsxRuntimeExports.jsx("div",{children:ee.jsxRuntimeExports.jsxs("div",{className:"mt-2.5 relative text-gray-400 focus-within:text-gray-600",children:[ee.jsxRuntimeExports.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none",children:ee.jsxRuntimeExports.jsx(lW,{})}),ee.jsxRuntimeExports.jsx("input",{value:n,onChange:c=>a(c.target.value),type:"email",id:"email",placeholder:"Enter email",className:"block w-full py-4 px-10 text-black placeholder-gray-500 transition-all duration-200 bg-white border border-gray-200 rounded-md focus:outline-none focus:border-blue-600 caret-blue-600"})]})}),ee.jsxRuntimeExports.jsx("div",{children:ee.jsxRuntimeExports.jsxs("div",{className:"mt-2.5 relative text-gray-400 focus-within:text-gray-600",children:[ee.jsxRuntimeExports.jsx("div",{className:"absolute inset-y-0 left-0 flex items-center pl-3 pointer-events-none",children:ee.jsxRuntimeExports.jsx("svg",{className:"w-5 h-5",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",children:ee.jsxRuntimeExports.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2",d:"M12 11c0 3.517-1.009 6.799-2.753 9.571m-3.44-2.04l.054-.09A13.916 13.916 0 008 11a4 4 0 118 0c0 1.017-.07 2.019-.203 3m-2.118 6.844A21.88 21.88 0 0015.171 17m3.839 1.132c.645-2.266.99-4.659.99-7.132A8 8 0 008 4.07M3 15.364c.64-1.319 1-2.8 1-4.364 0-1.457.39-2.823 1.07-4"})})}),ee.jsxRuntimeExports.jsx("input",{value:o,onChange:c=>s(c.target.value),type:t?"text":"password",id:"pwd",placeholder:"Enter password",className:"block w-full py-4 px-10 text-black placeholder-gray-500 transition-all duration-200 bg-white border border-gray-200 rounded-md focus:outline-none focus:border-blue-600 caret-blue-600"}),ee.jsxRuntimeExports.jsx("button",{type:"button",className:"absolute inset-y-0 right-4 flex items-center pl-3 cursor-pointer",onClick:()=>r(!t),children:t?ee.jsxRuntimeExports.jsx(Js.EyeClosedIcon,{}):ee.jsxRuntimeExports.jsx(Js.EyeOpenIcon,{})})]})}),ee.jsxRuntimeExports.jsx("div",{children:ee.jsxRuntimeExports.jsx("button",{disabled:l||B.size(n)<2||B.size(o)<2,type:"submit",className:"inline-flex disabled:bg-gray-400 items-center justify-center w-full px-4 py-4 text-base font-semibold text-white transition-all duration-200 bg-blue-600 border border-transparent rounded-md focus:outline-none hover:bg-blue-700 focus:bg-blue-700",children:l?"Signing in...":"Login"})})]})})]})})})},uW=e=>{const{data:t,isLoading:r}=YK(),n=Mt();return g.useEffect(()=>{n.setQueryData(["apiBaseUrl"],e.apiBaseUrl||"/api/chaibuilder")},[e.apiBaseUrl,n]),r?ee.jsxRuntimeExports.jsx(Hu,{}):t!=null&&t.valid?ee.jsxRuntimeExports.jsx(aW,{...e}):ee.jsxRuntimeExports.jsx(cW,{logo:e.logo})},fW=new gK,dW=e=>ee.jsxRuntimeExports.jsxs(AK,{client:fW,children:[ee.jsxRuntimeExports.jsx(ir.Toaster,{richColors:!0}),ee.jsxRuntimeExports.jsx(uW,{...e})]});exports.ChaiBuilderEditor=mA;exports.ChaiBuilderStudio=dW;exports.ErrorBoundary=sS;exports.activePanelAtom=NS;exports.addBlockOffCanvasAtom=MS;exports.addBlocksModalAtom=fS;exports.advanceStylingOpenAtom=kS;exports.canDeleteBlock=wB;exports.canDropBlock=AB;exports.canDuplicateBlock=yB;exports.canvasIframeAtom=RS;exports.editLayerNameAtom=xS;exports.getBlockJSONFromSchemas=Tu;exports.getBlockJSONFromUISchemas=Mu;exports.inlineEditingActiveAtom=IS;exports.networkModeAtom=PS;exports.pageSyncStateAtom=Wo;exports.reactIsExports=vg;exports.showPredefinedBlockCategoryAtom=TS;exports.useActiveLanguage=YS;exports.useActiveModal=gV;exports.useActivePanel=SV;exports.useAddBlock=xB;exports.useAddBlockParent=AV;exports.useAddClassesToBlocks=jB;exports.useAddPage=BK;exports.useAllBlocks=gS;exports.useBlockContentByLanguage=zV;exports.useBrandingOptions=ld;exports.useBuilderReset=md;exports.useBuildingBlocks=yS;exports.useCanvasHistory=Uo;exports.useCanvasWidth=GB;exports.useCanvasZoom=HB;exports.useChangePage=RA;exports.useCopyBlockIds=BS;exports.useCurrentPage=Jr;exports.useCurrentPage$1=wS;exports.useCutBlockIds=pd;exports.useDarkMode=QB;exports.useDeletePage=LK;exports.useDeveloperPreviewMode=_B;exports.useDuplicateBlocks=bd;exports.useExpandedIds=VV;exports.useFeatureSupport=kV;exports.useGetPageData=fd;exports.useHiddenBlockIds=eV;exports.useHighlightBlockId=LS;exports.useLanguages=jV;exports.useMarkAsGlobalBlock=rV;exports.useMoveBlocks=nV;exports.usePageDataProviders=jS;exports.usePages=Cd;exports.usePasteBlocks=KS;exports.usePreviewMode=id;exports.usePrimaryLanguage=TV;exports.useProject=lc;exports.useProject$1=sV;exports.useQueryClient=Mt;exports.useReadOnlyMode=vV;exports.useRemoveBlocks=US;exports.useRemoveClassesFromBlocks=lV;exports.useSavePage=JB;exports.useSelectedBlock=IB;exports.useSelectedBlockAllClasses=cV;exports.useSelectedBlockCurrentClasses=dV;exports.useSelectedBlockIds=Zr;exports.useSelectedBlocksDisplayChild=CB;exports.useSelectedBreakpoints=OV;exports.useSelectedStylingBlocks=sd;exports.useSetAllBlocks=dS;exports.useStylingBreakpoint=zS;exports.useStylingState=pV;exports.useTranslations=IV;exports.useTreeData=vB;exports.useUILibraryBlocks=xV;exports.useUpdateBlocksProps=hV;exports.useUpdateBlocksPropsRealtime=bV;exports.useUpdatePage=NA;exports.useUpdateProject=xA;
|