@chaibuilder/pages 0.16.23 → 0.16.25
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/{2AITGKQY-BH_4lP5P.cjs → 2AITGKQY-Be359164.cjs} +1 -1
- package/dist/{2AITGKQY-BuWtti7-.js → 2AITGKQY-CoZaZMrf.js} +2 -2
- package/dist/{NCMVHL6D-DbC9VYfW.js → NCMVHL6D-C2p_bwgN.js} +2 -2
- package/dist/{NCMVHL6D-CfRPe-3L.cjs → NCMVHL6D-CmKLw38-.cjs} +1 -1
- package/dist/{ZDWCUMSJ-BxhCnC2U.cjs → ZDWCUMSJ-DDHOTUX8.cjs} +1 -1
- package/dist/{ZDWCUMSJ-CE0Md3aC.js → ZDWCUMSJ-DmZy2MGb.js} +1 -1
- package/dist/{active-in-another-tab-C4o8FQXv.js → active-in-another-tab-At1yEu4g.js} +1 -1
- package/dist/{active-in-another-tab-SSCyhy2-.cjs → active-in-another-tab-B1PAoWFL.cjs} +1 -1
- package/dist/{add-new-language-page-DUkVmwsT.cjs → add-new-language-page-B7fKZbYT.cjs} +1 -1
- package/dist/{add-new-language-page-BCu4Npk2.js → add-new-language-page-BfPVFqO4.js} +2 -2
- package/dist/{add-new-page-BDpRUueB.cjs → add-new-page-DBVt7xSO.cjs} +1 -1
- package/dist/{add-new-page-D1pc9kLA.js → add-new-page-GZdKxwCY.js} +1 -1
- package/dist/{ai-panel-content-Dg6P7vk7.js → ai-panel-content-CWw-2gPV.js} +2 -2
- package/dist/{ai-panel-content-Bq3BC1Dm.cjs → ai-panel-content-Cv67WLJd.cjs} +1 -1
- package/dist/{ai-panel-default-lang-BxYd_6VF.js → ai-panel-default-lang-B1WScOB4.js} +3 -3
- package/dist/{ai-panel-default-lang-C0X_Srso.cjs → ai-panel-default-lang-BBk6sSyh.cjs} +2 -2
- package/dist/{ai-panel-other-lang-BOu1wJ5J.cjs → ai-panel-other-lang-BrVV9nKv.cjs} +1 -1
- package/dist/{ai-panel-other-lang-CBAP_iX-.js → ai-panel-other-lang-DgNon2GH.js} +3 -3
- package/dist/{ai-prompt-input-CiZCB6jc.js → ai-prompt-input-B6KsNLgP.js} +2 -2
- package/dist/ai-prompt-input-DSmIbsS_.cjs +1 -0
- package/dist/{ai-translation-prompt-Cas13J-r.cjs → ai-translation-prompt-BYTviKVU.cjs} +1 -1
- package/dist/{ai-translation-prompt-D3XU5z3f.js → ai-translation-prompt-CfnXqyai.js} +1 -1
- package/dist/button-CMMN5Cp4.cjs +1 -0
- package/dist/button-CggatMM3.js +48 -0
- package/dist/{continue-editing-in-this-client-DbHzW_zt.cjs → continue-editing-in-this-client--Fzos10u.cjs} +1 -1
- package/dist/{continue-editing-in-this-client-DIpi2ZSi.js → continue-editing-in-this-client--RRixZUo.js} +1 -1
- package/dist/{delete-page-DPHNAOC6.cjs → delete-page-BOuq3v6x.cjs} +1 -1
- package/dist/{delete-page-CODOstkw.js → delete-page-CeJdK5hc.js} +1 -1
- package/dist/{digital-asset-manager-BllbsemN.cjs → digital-asset-manager-BUEa7fSG.cjs} +1 -1
- package/dist/{digital-asset-manager-BuYVjKfQ.js → digital-asset-manager-D6GbpYDo.js} +1 -1
- package/dist/{duplicate-page-DfH67AsW.js → duplicate-page-C7FjAbqP.js} +2 -2
- package/dist/{duplicate-page-Dc6_UBNZ.cjs → duplicate-page-Ch9Fn-Gu.cjs} +1 -1
- package/dist/{dynamic-page-selector-Dd8Orls1.cjs → dynamic-page-selector-CZNYCxbJ.cjs} +1 -1
- package/dist/{dynamic-page-selector-C2UK6qGj.js → dynamic-page-selector-C_-ihnB7.js} +1 -1
- package/dist/index-CJcS3b8n.cjs +5 -0
- package/dist/{index-B_T6ZeA4.js → index-CtRx3Y3K.js} +1130 -1115
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +7 -7
- package/dist/{json-diff-viewer-D8uyTokS.js → json-diff-viewer-DX4sQltt.js} +1 -1
- package/dist/{json-diff-viewer-1IHmR_Nt.cjs → json-diff-viewer-DluaC8tY.cjs} +1 -1
- package/dist/{lang-panel-D-Pbw2bR.cjs → lang-panel-DFe4DfU4.cjs} +1 -1
- package/dist/{lang-panel-d7376A7w.js → lang-panel-p7OYw-2c.js} +2 -2
- package/dist/{mark-as-template-DHFkkBvV.cjs → mark-as-template-Biqpp8uM.cjs} +1 -1
- package/dist/{mark-as-template-Bx-MAB5M.js → mark-as-template-CuPKgc5N.js} +1 -1
- package/dist/{no-language-page-content-if-qlxZz.js → no-language-page-content-B_zNVuVO.js} +1 -1
- package/dist/{no-language-page-content-DkK7mBnG.cjs → no-language-page-content-oy4ZcH34.cjs} +1 -1
- package/dist/{no-language-page-dialog-49fBehZo.cjs → no-language-page-dialog-CTRG81hU.cjs} +1 -1
- package/dist/{no-language-page-dialog-CCLWQP1E.js → no-language-page-dialog-Q2rvsEP6.js} +2 -2
- package/dist/{page-creator-DlJXKAhw.cjs → page-creator-CVrbjJa-.cjs} +1 -1
- package/dist/{page-creator-DRDoy3nM.js → page-creator-b6UTCFeu.js} +2 -2
- package/dist/{page-lock-DOnPhjGp.cjs → page-lock-DUwWdppB.cjs} +1 -1
- package/dist/{page-lock-pwxPivz-.js → page-lock-Dl5CmUgk.js} +2 -2
- package/dist/{page-locked-dialog-DKn93bBu.cjs → page-locked-dialog-DeUMR-pV.cjs} +1 -1
- package/dist/{page-locked-dialog-238NohyB.js → page-locked-dialog-MJ3kA-oQ.js} +1 -1
- package/dist/page-manager-new-C3XuiDiM.cjs +1 -0
- package/dist/page-manager-new-C8PGR_4a.js +394 -0
- package/dist/{page-manager-search-and-filter-4JatGyBT.cjs → page-manager-search-and-filter-BdfXZwwH.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-B86rQEO4.js → page-manager-search-and-filter-DIz68YHL.js} +1 -1
- package/dist/{page-revisions-content-V9S1rPUy.js → page-revisions-content-BvYTXKgT.js} +2 -2
- package/dist/{page-revisions-content-ChOACVs4.cjs → page-revisions-content-CwrPL9kp.cjs} +1 -1
- package/dist/pages.css +1 -1
- package/dist/{publish-pages-content-GKnG7R5W.js → publish-pages-content-9VBFj6LH.js} +2 -2
- package/dist/{publish-pages-content-CXKknMnI.cjs → publish-pages-content-DTPjR33T.cjs} +1 -1
- package/dist/{save-to-lib-BO3WEr-u.js → save-to-lib-Bkou78G6.js} +1 -1
- package/dist/{save-to-lib-BderZ0Qz.cjs → save-to-lib-ByoB0FW5.cjs} +1 -1
- package/dist/selected-block-display-Auur5nl7.cjs +16 -0
- package/dist/selected-block-display-D1L4e4Cb.js +355 -0
- package/dist/{seo-panel-DuC3gQQy.js → seo-panel-KjxjFcdp.js} +16 -16
- package/dist/{seo-panel-C2WY1dTf.cjs → seo-panel-Mjkh_Urn.cjs} +1 -1
- package/dist/server.d.ts +8 -0
- package/dist/{shared-json-ld-ChfktUpf.cjs → shared-json-ld-DYD7q8ST.cjs} +1 -1
- package/dist/{shared-json-ld-DMpCm3M4.js → shared-json-ld-S9OIaOTA.js} +1 -1
- package/dist/{slug-input-CrjrFrxP.cjs → slug-input-C0BtQs2w.cjs} +1 -1
- package/dist/{slug-input-CO6AGAQD.js → slug-input-CUTtvZQ9.js} +1 -1
- package/dist/{take-over-request-Du7grW5x.js → take-over-request-CXED2804.js} +1 -1
- package/dist/{take-over-request-mNydSSFX.cjs → take-over-request-Dh9HVZPO.cjs} +1 -1
- package/dist/{theme-panel-footer-CSC6DpWO.js → theme-panel-footer-CftO53LS.js} +1 -1
- package/dist/{theme-panel-footer-eZ1bbLzq.cjs → theme-panel-footer-tdNtbqZs.cjs} +1 -1
- package/dist/{unmark-as-template-dEb6wFT9.js → unmark-as-template-Dp6S9dY3.js} +1 -1
- package/dist/{unmark-as-template-DzU6-XK7.cjs → unmark-as-template-DyUqAa9Z.cjs} +1 -1
- package/dist/{unpublish-page-CxAB3-Cj.js → unpublish-page-c382vh74.js} +1 -1
- package/dist/{unpublish-page-DGd2Kktq.cjs → unpublish-page-ch791au1.cjs} +1 -1
- package/dist/{web-preview-yBF4EXzm.js → web-preview-DiOChE4E.js} +1 -1
- package/dist/{web-preview-B6G0vdiq.cjs → web-preview-cls5-Dlv.cjs} +1 -1
- package/package.json +3 -3
- package/dist/ai-prompt-input-bqLGbsQ2.cjs +0 -1
- package/dist/index--Lu_Q_nO.cjs +0 -5
- package/dist/page-manager-new-Ch0UNJM1.cjs +0 -1
- package/dist/page-manager-new-hEQwUorR.js +0 -354
- package/dist/selected-block-display-DAe0XQgw.js +0 -394
- package/dist/selected-block-display-yB5bvo9w.cjs +0 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),F=require("lodash-es"),f=require("lucide-react"),u=require("react"),fe=require("react-dropzone"),g=require("./index--Lu_Q_nO.cjs"),w=require("sonner"),Y=require("./image-compression-DZ9WMmyn.cjs"),z=require("@tanstack/react-query"),pe=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>{const o=i.map(async l=>x(n,{action:g.ACTIONS.UPLOAD_ASSET,data:l}));return await Promise.all(o)},onSuccess:i=>{var o;if(i!=null&&i.some(s=>s.error))throw new Error(((o=i==null?void 0:i.find(s=>s.error))==null?void 0:o.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]});const s=i==null?void 0:i.length;w.toast.success(`${s===1?"Asset":s+" Assets"} uploaded successfully`)}},onError:()=>{w.toast.error("Failed to upload asset")}})},ge=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.DELETE_ASSET,data:{id:i}}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),w.toast.success("Asset deleted successfully")},onError:()=>{w.toast.error("Failed to delete asset")}})},je=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.UPDATE_ASSET,data:i}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),i!=null&&i.id&&r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSET,i.id]}),w.toast.success("Asset updated successfully")},onError:()=>{w.toast.error("Failed to update asset")}})};function ve({currentPage:n,totalPages:r,onPageChange:x,pageRangeDisplayed:i=3,showPageInput:o=!0,className:s=""}){const[l,E]=u.useState(String(n)),N=u.useMemo(()=>{const c=Math.floor(i/2);let m=Math.max(1,n-c),d=Math.min(r,n+c);d-m+1<i&&(m===1?d=Math.min(r,m+i-1):d===r&&(m=Math.max(1,d-i+1)));const p=[];m>1&&(p.push(1),m>2&&p.push("..."));for(let y=m;y<=d;y++)p.push(y);return d<r&&(d<r-1&&p.push("..."),p.push(r)),p},[n,r,i]),v=c=>{c!==n&&c>=1&&c<=r&&(x(c),E(String(c)))},j=()=>{n>1&&v(n-1)},b=()=>{n<r&&v(n+1)},C=()=>{const c=Number(l);!isNaN(c)&&c>=1&&c<=r&&v(c)},A=c=>{c.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${s}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:j,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(f.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((c,m)=>{if(c==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const d=c,p=d===n;return e.jsx(a.Button,{variant:p?"default":"outline",size:"sm",onClick:()=>v(d),className:p?"border-blue-600 bg-blue-600 px-3 py-1 text-sm text-white":"border px-3 py-1 text-sm hover:bg-gray-50 hover:text-black",children:d},d)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:b,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(f.ChevronRight,{className:" h-4 w-4"})]})]}),o&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Go to"}),e.jsx(a.Input,{type:"number",min:1,max:r,value:l,onChange:c=>{const m=c.target.value.replace(/[^\d]/g,"");E(m)},onKeyDown:A,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:l===""||Number(l)<1||Number(l)>r,children:"Go"})]})]})}const ye=(n={})=>{const r=g.useAssetsApiUrl(),x=g.useFetch(),{search:i,page:o=1,limit:s=30}=n;return z.useQuery({queryKey:[g.ACTIONS.GET_ASSETS,i,o,s],queryFn:async()=>{const l=await x(r,{action:g.ACTIONS.GET_ASSETS,data:{search:i,page:o,limit:s}});return l.page=o,l.limit=s,l},staleTime:1/0,retry:1})},Ne=n=>{const r=g.useAssetsApiUrl(),x=g.useFetch();return z.useQuery({queryKey:[g.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await x(r,{action:g.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function be(n){const r=isNaN(n)?0:typeof n=="number"?n:parseInt(n);return r?r<1024?`${r.toFixed(2)} B`:r<1024*1024?`${(r/1024).toFixed(2)} KB`:`${(r/(1024*1024)).toFixed(2)} MB`:"0 B"}function Z(n){if(!n)return"N/A";const r=new Date(n);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)}function J(n,r){let x=n,i=r==null?void 0:r.description;return(!i||typeof i!="string")&&(i=""),(!x||typeof x!="string")&&(x=""),x!==i}const we=({assetId:n,onBack:r,onEdit:x,onSave:i,isSaving:o})=>{var c,m;const{t:s}=M.useTranslation(),{data:l,isLoading:E,isError:N}=Ne(n||""),[v,j]=u.useState(""),[b,C]=u.useState(!1);u.useEffect(()=>{const d=new Image;return d.src=(l==null?void 0:l.url)||"",d.onload=()=>C(!0),()=>{d.onload=null}},[l]);const A=async(d,p)=>{try{await navigator.clipboard.writeText(d),w.toast.success(s("{{type}} copied to clipboard",{type:p}))}catch(y){w.toast.error(s("Failed to copy {{type}}",{type:p}),{description:y==null?void 0:y.message})}};return u.useEffect(()=>{l!=null&&l.description&&j(l.description)},[l]),E||!b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}):N||!(l!=null&&l.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(f.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:s("No Asset Found")}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:s(N?"There was an error loading the asset. Please try again later.":"The asset you're looking for doesn't exist or has been removed.")}),e.jsxs("div",{className:"flex justify-center gap-4",children:[e.jsx(a.Button,{variant:"outline",onClick:r,children:s("Back to Assets")}),N&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:s("Try Again")})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:r,disabled:o,children:[e.jsx(f.ChevronLeft,{className:"h-4 w-4"}),s("Back to Assets")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:o,children:s("Cancel")}),e.jsxs(a.Button,{variant:"outline",onClick:()=>A(l.url,s("Asset URL")),disabled:o,children:[e.jsx(f.Copy,{className:"h-4 w-4 mr-2"}),s("Copy URL")]}),e.jsxs(a.Button,{variant:"default",onClick:()=>x(l),disabled:o,children:[e.jsx(f.Pencil,{className:"h-4 w-4"}),s("Edit Image")]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:l.url,alt:l.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Details")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:s("File Name"),value:l.name},{label:s("Type"),value:l.type,capitalize:!0},{label:s("Format"),value:((c=l.metadata)==null?void 0:c.format)||l.type,capitalize:!0},{label:s("Size"),value:be(l.size)},{label:s("Dimensions"),value:`${l.width||0} × ${l.height||0}`},{label:s("Created"),value:Z(l.createdAt)},{label:s("Updated"),value:Z(((m=l.metadata)==null?void 0:m.updatedAt)||(l==null?void 0:l.updatedAt)||l.createdAt)},{label:s("URL"),value:l.url,copyable:!0}].map(d=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:d.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(d.capitalize?" capitalize":""),children:d.value}),d.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>A(d.value,d.label),children:e.jsx(f.Link,{className:"h-3 w-3"})})]})]},d.label))})]}),l.usedOn&&l.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:s("Used On")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:l.usedOn.map((d,p)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:d.name}),e.jsxs("div",{className:"text-gray-500",children:["(",d.slug,")"]})]},p))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Description")}),e.jsx(a.Textarea,{id:"description",value:v,placeholder:s("Enter a description for the asset"),onChange:d=>j(d.target.value),rows:3,disabled:o,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>i(v),disabled:o||!J(v,l),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${o||!J(v,l)?"opacity-50 cursor-not-allowed":""}`,children:o?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),s("Saving...")]}):s("Save")})})]})]})]})]})},Ce=u.lazy(()=>Promise.resolve().then(()=>require("./image-editor-CnDnY97s.cjs"))),Ae=25*1024*1024,Se=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:x,isUploadingAsset:i,onUploaded:o})=>{const{t:s}=M.useTranslation(),[l,E]=u.useState(()=>{const c=localStorage.getItem("chai_optimize_images");return c!==null?c==="true":!0});u.useEffect(()=>{localStorage.setItem("chai_optimize_images",l.toString())},[l]);const N=n||i,v=u.useCallback(async c=>{try{const m=c;if(!m.every(S=>S.type.startsWith("image/")))return w.toast.error(s("Invalid file type. Please upload a valid file.")),Promise.reject(new Error("Invalid file type"));const d=m.map(async S=>{let U=S;return S.type.startsWith("image/")&&(U=await Y.compressImageIfNeeded(S)),new Promise((_,B)=>{const L=new FileReader;L.readAsDataURL(U),L.onload=async()=>{_({file:L.result,folderId:void 0,name:S.name,optimize:l})},L.onerror=()=>B(null)})}),p=await Promise.all(d),y=await x(p);return(y==null?void 0:y.length)===1&&o(y[0]),y}catch(m){return Promise.reject(m)}},[x,l,o,s]),j=c=>{const m=[];let d=0;return c.forEach(p=>{p.size>Ae?d++:m.push(p)}),d>0&&w.toast.error(`${d===1&&c.length===1?s("File"):d+s(d===1?" file":" files")} ${s("exceed the maximum size limit of 10MB.")}`),F.isEmpty(m)?[]:v(m)},{getRootProps:b,getInputProps:C,isDragActive:A}=fe.useDropzone({onDrop:j,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||i,multiple:!0});return e.jsx("div",{className:`flex h-[60px] w-full flex-col items-center justify-center rounded-lg border-2 border-dashed border-slate-300 p-0 py-2 hover:border-black/50 ${N?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...b(),className:M.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",N?"items-start":"items-center",A?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...C()}),N?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(f.Loader,{className:"h-4 w-4 animate-spin text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:s(n?"Updating file...":"Uploading file...")}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:[s("Please wait while we")," ",s(n?"update":"upload")," ",s("your file...")]})]})]})}):e.jsxs("div",{className:"flex w-full items-center justify-between px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full border border-indigo-500 bg-indigo-100 p-2",children:e.jsx(f.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:[s("Drop your file here or")," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:s("browse")})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:[s("Accepted file types:")," ",e.jsx("span",{className:"capitalize text-indigo-400",children:r.join(", ")})]})})]})]})}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:[s("Optimization:")," "," ",e.jsx("span",{className:l?"text-indigo-600":"text-gray-400",children:s(l?"On":"Off")})]}),e.jsx(a.Switch,{checked:l,onCheckedChange:c=>{E(c)},onClick:c=>{c.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`flex cursor-help items-center text-amber-500 ${l?"invisible":""}`,children:e.jsx(f.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsx("p",{className:"text-xs text-white",children:s("Warning: Unoptimized images may affect performance and page load times")})})]})})]})]})]})})};function Te({close:n,onSelect:r,mode:x="image",assetId:i}){const{t:o}=M.useTranslation(),s=!1,l=10,E=u.useMemo(()=>[x],[x]),[N,v]=u.useState(null),[j,b]=u.useState(null),[C,A]=u.useState(null),[c,m]=u.useState({show:!1,file:""}),[d,p]=u.useState(!1),[y,S]=u.useState(i?"details":"grid"),[U,_]=u.useState(""),[B,L]=u.useState(""),[P,Q]=u.useState(1),[R]=u.useState(30),[T,G]=u.useState([]);u.useEffect(()=>{i&&(v(i),S("details"))},[i]),u.useEffect(()=>{const t=setTimeout(()=>{_(B),Q(1)},300);return()=>clearTimeout(t)},[B]);const{data:q,isLoading:$,refetch:ee}=ye({search:U.toLowerCase().trim(),page:P,limit:R}),D=(q==null?void 0:q.assets)||[],te=(q==null?void 0:q.total)||0,I=Math.ceil(te/R);u.useEffect(()=>{$||I<=0||Q(t=>t>I?I:t<1?1:t)},[$,I]);const se=(D==null?void 0:D.length)>0,{mutate:ie}=ge(),{mutateAsync:K,isPending:le}=pe(),{mutateAsync:W,isPending:ae}=je(),V=u.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,I));h!==P&&Q(h)},[I,P]),re=t=>{L(t.target.value)},ne=u.useCallback(t=>{G(h=>F.find(h,{id:t.id})?[]:[t])},[s]),oe=u.useCallback(()=>{G([])},[]),H=t=>{(t==null?void 0:t.length)!==0&&(r(F.pick(F.first(t||T),["id","url","width","height","description"])),n())},ce=async t=>{b(t)},de=async()=>{j&&(A(j==null?void 0:j.id),await ie(j.id,{onSuccess:()=>{A(null),b(null)},onError:()=>{A(null)}}),b(null))},ue=t=>{v(t.id),S("details")},me=async(t,h)=>{try{const O=localStorage.getItem("chai_optimize_images")!=="false";if(h){const k=await K([{file:t,folderId:void 0,name:c.name||"",optimize:O}]);if((k==null?void 0:k.length)>0){const X=k[0];r({...F.pick(X,["id","width","height","description"]),url:X.url})}}else{const k=await W({id:c.id||"",file:t});k&&r({...F.pick(k,["id","width","height","description"]),url:k.url})}m({show:!1,file:""}),n()}catch(O){console.error(o("Error saving edited image:"),O)}},he=u.useCallback(t=>{G([t])},[]),xe=u.useCallback(t=>{V(t)},[V]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-[80vh] max-h-[1232px] w-[80vw] max-w-[1232px] flex-col space-y-4",children:[e.jsx("h1",{className:"text-lg font-medium",children:o("Digital Asset Manager")}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Se,{maxFileSize:l,allowedTypes:E,uploadAssets:K,isUpdatingAsset:ae,isUploadingAsset:le,onUploaded:he}),e.jsxs("div",{className:"relative flex flex-1 flex-col gap-y-3 overflow-hidden rounded-lg border p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2",children:[e.jsx(f.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${B.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:o("Search assets..."),onChange:re,value:B,className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[T.length>0?e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[T.length>0&&e.jsx(e.Fragment,{children:e.jsx(a.Button,{variant:"outline",size:"sm",onClick:()=>oe(),title:o("Clear selection"),children:o("Clear")})}),e.jsx(a.Button,{size:"sm",onClick:()=>H(T),disabled:T.length===0,children:o("Select Asset")})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>ee(),children:e.jsx(f.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:$?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"})]}):!$&&!se?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center rounded-lg border",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(f.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:o("No assets found")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:U.length>0?o("No assets found for your search: {{query}}",{query:U}):o("Start uploading assets to get started")}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:D==null?void 0:D.map(t=>e.jsxs("div",{className:M.mergeClasses("group relative flex max-h-[180px] max-w-[180px] cursor-pointer flex-col justify-between overflow-hidden rounded-lg border-2 transition-all",T.some(h=>h.id===t.id)?"border-blue-500":"hover:border-black/90",C&&(j==null?void 0:j.id)===t.id?"pointer-events-none opacity-50":"",C===t.id?"pointer-events-none opacity-50":""),onClick:()=>ne(t),onDoubleClick:()=>H([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[C===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin text-white"})}):null,t.type==="image"?e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:`h-full min-h-[80px] w-full object-contain ${T.some(h=>h.id===t.id)?"":"group-hover:blur group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex h-full items-center justify-center",children:[e.jsx(f.Film,{className:"h-12 w-12 text-muted-foreground"}),t.thumbnailUrl&&e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:"absolute inset-0 h-full w-full object-cover"})]})]}),e.jsxs("div",{className:"flex items-end justify-between border-t-[1px] border-black/10 bg-white px-2 py-1",children:[e.jsx("div",{className:"truncate text-xs leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"flex items-center justify-between whitespace-nowrap text-[9px] font-light text-muted-foreground",children:e.jsx("span",{children:Y.formatFileSize((t==null?void 0:t.size)||0)})})]}),!T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2 p-2",children:[e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ue(t)},children:e.jsx(f.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("View Details")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),navigator.clipboard.writeText(t.url),w.toast.success(o("Asset URL copied to clipboard"))},children:e.jsx(f.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Copy URL")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),m({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Edit Image")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ce(t)},children:e.jsx(f.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Delete Asset")})})]})})]})}),T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute right-1 top-1 h-max rounded-full border border-white bg-blue-500 p-1",children:e.jsx(f.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),I>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(g.ErrorBoundary,{fallback:e.jsx("div",{className:"text-red-500",children:o("Error loading pagination")}),children:e.jsx(ve,{currentPage:P,totalPages:I,onPageChange:xe,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(we,{assetId:N||i||"",onBack:()=>{S("grid"),v(null)},onEdit:t=>{m({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(N){p(!0);try{const h=D.find(O=>O.id===N);h&&await W(F.merge(h,{description:t}))}finally{p(!1)}}},isSaving:d})]}),c.show&&e.jsx(u.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ce,{imageUrl:c.file,onSave:me,onClose:()=>m({show:!1,file:""}),defaultSavedImageName:c.name,isEditing:!!c.id})}),j&&e.jsx(a.Dialog,{open:!!j,onOpenChange:()=>b(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:o("Delete Asset")}),e.jsx(a.DialogDescription,{children:o('Are you sure you want to delete "{{name}}"? This action cannot be undone.',{name:j.name})})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>b(null),children:o("Cancel")}),e.jsx(a.Button,{variant:"destructive",onClick:de,children:o("Delete")})]})]})})]})}exports.default=Te;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),F=require("lodash-es"),f=require("lucide-react"),u=require("react"),fe=require("react-dropzone"),g=require("./index-CJcS3b8n.cjs"),w=require("sonner"),Y=require("./image-compression-DZ9WMmyn.cjs"),z=require("@tanstack/react-query"),pe=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>{const o=i.map(async l=>x(n,{action:g.ACTIONS.UPLOAD_ASSET,data:l}));return await Promise.all(o)},onSuccess:i=>{var o;if(i!=null&&i.some(s=>s.error))throw new Error(((o=i==null?void 0:i.find(s=>s.error))==null?void 0:o.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]});const s=i==null?void 0:i.length;w.toast.success(`${s===1?"Asset":s+" Assets"} uploaded successfully`)}},onError:()=>{w.toast.error("Failed to upload asset")}})},ge=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.DELETE_ASSET,data:{id:i}}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),w.toast.success("Asset deleted successfully")},onError:()=>{w.toast.error("Failed to delete asset")}})},je=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.UPDATE_ASSET,data:i}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),i!=null&&i.id&&r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSET,i.id]}),w.toast.success("Asset updated successfully")},onError:()=>{w.toast.error("Failed to update asset")}})};function ve({currentPage:n,totalPages:r,onPageChange:x,pageRangeDisplayed:i=3,showPageInput:o=!0,className:s=""}){const[l,E]=u.useState(String(n)),N=u.useMemo(()=>{const c=Math.floor(i/2);let m=Math.max(1,n-c),d=Math.min(r,n+c);d-m+1<i&&(m===1?d=Math.min(r,m+i-1):d===r&&(m=Math.max(1,d-i+1)));const p=[];m>1&&(p.push(1),m>2&&p.push("..."));for(let y=m;y<=d;y++)p.push(y);return d<r&&(d<r-1&&p.push("..."),p.push(r)),p},[n,r,i]),v=c=>{c!==n&&c>=1&&c<=r&&(x(c),E(String(c)))},j=()=>{n>1&&v(n-1)},b=()=>{n<r&&v(n+1)},C=()=>{const c=Number(l);!isNaN(c)&&c>=1&&c<=r&&v(c)},A=c=>{c.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${s}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:j,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(f.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((c,m)=>{if(c==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const d=c,p=d===n;return e.jsx(a.Button,{variant:p?"default":"outline",size:"sm",onClick:()=>v(d),className:p?"border-blue-600 bg-blue-600 px-3 py-1 text-sm text-white":"border px-3 py-1 text-sm hover:bg-gray-50 hover:text-black",children:d},d)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:b,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(f.ChevronRight,{className:" h-4 w-4"})]})]}),o&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Go to"}),e.jsx(a.Input,{type:"number",min:1,max:r,value:l,onChange:c=>{const m=c.target.value.replace(/[^\d]/g,"");E(m)},onKeyDown:A,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:l===""||Number(l)<1||Number(l)>r,children:"Go"})]})]})}const ye=(n={})=>{const r=g.useAssetsApiUrl(),x=g.useFetch(),{search:i,page:o=1,limit:s=30}=n;return z.useQuery({queryKey:[g.ACTIONS.GET_ASSETS,i,o,s],queryFn:async()=>{const l=await x(r,{action:g.ACTIONS.GET_ASSETS,data:{search:i,page:o,limit:s}});return l.page=o,l.limit=s,l},staleTime:1/0,retry:1})},Ne=n=>{const r=g.useAssetsApiUrl(),x=g.useFetch();return z.useQuery({queryKey:[g.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await x(r,{action:g.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function be(n){const r=isNaN(n)?0:typeof n=="number"?n:parseInt(n);return r?r<1024?`${r.toFixed(2)} B`:r<1024*1024?`${(r/1024).toFixed(2)} KB`:`${(r/(1024*1024)).toFixed(2)} MB`:"0 B"}function Z(n){if(!n)return"N/A";const r=new Date(n);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)}function J(n,r){let x=n,i=r==null?void 0:r.description;return(!i||typeof i!="string")&&(i=""),(!x||typeof x!="string")&&(x=""),x!==i}const we=({assetId:n,onBack:r,onEdit:x,onSave:i,isSaving:o})=>{var c,m;const{t:s}=M.useTranslation(),{data:l,isLoading:E,isError:N}=Ne(n||""),[v,j]=u.useState(""),[b,C]=u.useState(!1);u.useEffect(()=>{const d=new Image;return d.src=(l==null?void 0:l.url)||"",d.onload=()=>C(!0),()=>{d.onload=null}},[l]);const A=async(d,p)=>{try{await navigator.clipboard.writeText(d),w.toast.success(s("{{type}} copied to clipboard",{type:p}))}catch(y){w.toast.error(s("Failed to copy {{type}}",{type:p}),{description:y==null?void 0:y.message})}};return u.useEffect(()=>{l!=null&&l.description&&j(l.description)},[l]),E||!b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}):N||!(l!=null&&l.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(f.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:s("No Asset Found")}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:s(N?"There was an error loading the asset. Please try again later.":"The asset you're looking for doesn't exist or has been removed.")}),e.jsxs("div",{className:"flex justify-center gap-4",children:[e.jsx(a.Button,{variant:"outline",onClick:r,children:s("Back to Assets")}),N&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:s("Try Again")})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:r,disabled:o,children:[e.jsx(f.ChevronLeft,{className:"h-4 w-4"}),s("Back to Assets")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:o,children:s("Cancel")}),e.jsxs(a.Button,{variant:"outline",onClick:()=>A(l.url,s("Asset URL")),disabled:o,children:[e.jsx(f.Copy,{className:"h-4 w-4 mr-2"}),s("Copy URL")]}),e.jsxs(a.Button,{variant:"default",onClick:()=>x(l),disabled:o,children:[e.jsx(f.Pencil,{className:"h-4 w-4"}),s("Edit Image")]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:l.url,alt:l.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Details")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:s("File Name"),value:l.name},{label:s("Type"),value:l.type,capitalize:!0},{label:s("Format"),value:((c=l.metadata)==null?void 0:c.format)||l.type,capitalize:!0},{label:s("Size"),value:be(l.size)},{label:s("Dimensions"),value:`${l.width||0} × ${l.height||0}`},{label:s("Created"),value:Z(l.createdAt)},{label:s("Updated"),value:Z(((m=l.metadata)==null?void 0:m.updatedAt)||(l==null?void 0:l.updatedAt)||l.createdAt)},{label:s("URL"),value:l.url,copyable:!0}].map(d=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:d.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(d.capitalize?" capitalize":""),children:d.value}),d.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>A(d.value,d.label),children:e.jsx(f.Link,{className:"h-3 w-3"})})]})]},d.label))})]}),l.usedOn&&l.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:s("Used On")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:l.usedOn.map((d,p)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:d.name}),e.jsxs("div",{className:"text-gray-500",children:["(",d.slug,")"]})]},p))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(a.Label,{className:"w-full text-center",children:s("Description")}),e.jsx(a.Textarea,{id:"description",value:v,placeholder:s("Enter a description for the asset"),onChange:d=>j(d.target.value),rows:3,disabled:o,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>i(v),disabled:o||!J(v,l),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${o||!J(v,l)?"opacity-50 cursor-not-allowed":""}`,children:o?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),s("Saving...")]}):s("Save")})})]})]})]})]})},Ce=u.lazy(()=>Promise.resolve().then(()=>require("./image-editor-CnDnY97s.cjs"))),Ae=25*1024*1024,Se=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:x,isUploadingAsset:i,onUploaded:o})=>{const{t:s}=M.useTranslation(),[l,E]=u.useState(()=>{const c=localStorage.getItem("chai_optimize_images");return c!==null?c==="true":!0});u.useEffect(()=>{localStorage.setItem("chai_optimize_images",l.toString())},[l]);const N=n||i,v=u.useCallback(async c=>{try{const m=c;if(!m.every(S=>S.type.startsWith("image/")))return w.toast.error(s("Invalid file type. Please upload a valid file.")),Promise.reject(new Error("Invalid file type"));const d=m.map(async S=>{let U=S;return S.type.startsWith("image/")&&(U=await Y.compressImageIfNeeded(S)),new Promise((_,B)=>{const L=new FileReader;L.readAsDataURL(U),L.onload=async()=>{_({file:L.result,folderId:void 0,name:S.name,optimize:l})},L.onerror=()=>B(null)})}),p=await Promise.all(d),y=await x(p);return(y==null?void 0:y.length)===1&&o(y[0]),y}catch(m){return Promise.reject(m)}},[x,l,o,s]),j=c=>{const m=[];let d=0;return c.forEach(p=>{p.size>Ae?d++:m.push(p)}),d>0&&w.toast.error(`${d===1&&c.length===1?s("File"):d+s(d===1?" file":" files")} ${s("exceed the maximum size limit of 10MB.")}`),F.isEmpty(m)?[]:v(m)},{getRootProps:b,getInputProps:C,isDragActive:A}=fe.useDropzone({onDrop:j,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||i,multiple:!0});return e.jsx("div",{className:`flex h-[60px] w-full flex-col items-center justify-center rounded-lg border-2 border-dashed border-slate-300 p-0 py-2 hover:border-black/50 ${N?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...b(),className:M.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",N?"items-start":"items-center",A?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...C()}),N?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(f.Loader,{className:"h-4 w-4 animate-spin text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:s(n?"Updating file...":"Uploading file...")}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:[s("Please wait while we")," ",s(n?"update":"upload")," ",s("your file...")]})]})]})}):e.jsxs("div",{className:"flex w-full items-center justify-between px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full border border-indigo-500 bg-indigo-100 p-2",children:e.jsx(f.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:[s("Drop your file here or")," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:s("browse")})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:[s("Accepted file types:")," ",e.jsx("span",{className:"capitalize text-indigo-400",children:r.join(", ")})]})})]})]})}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:[s("Optimization:")," "," ",e.jsx("span",{className:l?"text-indigo-600":"text-gray-400",children:s(l?"On":"Off")})]}),e.jsx(a.Switch,{checked:l,onCheckedChange:c=>{E(c)},onClick:c=>{c.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`flex cursor-help items-center text-amber-500 ${l?"invisible":""}`,children:e.jsx(f.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsx("p",{className:"text-xs text-white",children:s("Warning: Unoptimized images may affect performance and page load times")})})]})})]})]})]})})};function Te({close:n,onSelect:r,mode:x="image",assetId:i}){const{t:o}=M.useTranslation(),s=!1,l=10,E=u.useMemo(()=>[x],[x]),[N,v]=u.useState(null),[j,b]=u.useState(null),[C,A]=u.useState(null),[c,m]=u.useState({show:!1,file:""}),[d,p]=u.useState(!1),[y,S]=u.useState(i?"details":"grid"),[U,_]=u.useState(""),[B,L]=u.useState(""),[P,Q]=u.useState(1),[R]=u.useState(30),[T,G]=u.useState([]);u.useEffect(()=>{i&&(v(i),S("details"))},[i]),u.useEffect(()=>{const t=setTimeout(()=>{_(B),Q(1)},300);return()=>clearTimeout(t)},[B]);const{data:q,isLoading:$,refetch:ee}=ye({search:U.toLowerCase().trim(),page:P,limit:R}),D=(q==null?void 0:q.assets)||[],te=(q==null?void 0:q.total)||0,I=Math.ceil(te/R);u.useEffect(()=>{$||I<=0||Q(t=>t>I?I:t<1?1:t)},[$,I]);const se=(D==null?void 0:D.length)>0,{mutate:ie}=ge(),{mutateAsync:K,isPending:le}=pe(),{mutateAsync:W,isPending:ae}=je(),V=u.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,I));h!==P&&Q(h)},[I,P]),re=t=>{L(t.target.value)},ne=u.useCallback(t=>{G(h=>F.find(h,{id:t.id})?[]:[t])},[s]),oe=u.useCallback(()=>{G([])},[]),H=t=>{(t==null?void 0:t.length)!==0&&(r(F.pick(F.first(t||T),["id","url","width","height","description"])),n())},ce=async t=>{b(t)},de=async()=>{j&&(A(j==null?void 0:j.id),await ie(j.id,{onSuccess:()=>{A(null),b(null)},onError:()=>{A(null)}}),b(null))},ue=t=>{v(t.id),S("details")},me=async(t,h)=>{try{const O=localStorage.getItem("chai_optimize_images")!=="false";if(h){const k=await K([{file:t,folderId:void 0,name:c.name||"",optimize:O}]);if((k==null?void 0:k.length)>0){const X=k[0];r({...F.pick(X,["id","width","height","description"]),url:X.url})}}else{const k=await W({id:c.id||"",file:t});k&&r({...F.pick(k,["id","width","height","description"]),url:k.url})}m({show:!1,file:""}),n()}catch(O){console.error(o("Error saving edited image:"),O)}},he=u.useCallback(t=>{G([t])},[]),xe=u.useCallback(t=>{V(t)},[V]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-[80vh] max-h-[1232px] w-[80vw] max-w-[1232px] flex-col space-y-4",children:[e.jsx("h1",{className:"text-lg font-medium",children:o("Digital Asset Manager")}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Se,{maxFileSize:l,allowedTypes:E,uploadAssets:K,isUpdatingAsset:ae,isUploadingAsset:le,onUploaded:he}),e.jsxs("div",{className:"relative flex flex-1 flex-col gap-y-3 overflow-hidden rounded-lg border p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2",children:[e.jsx(f.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${B.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:o("Search assets..."),onChange:re,value:B,className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[T.length>0?e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[T.length>0&&e.jsx(e.Fragment,{children:e.jsx(a.Button,{variant:"outline",size:"sm",onClick:()=>oe(),title:o("Clear selection"),children:o("Clear")})}),e.jsx(a.Button,{size:"sm",onClick:()=>H(T),disabled:T.length===0,children:o("Select Asset")})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>ee(),children:e.jsx(f.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:$?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"})]}):!$&&!se?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center rounded-lg border",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(f.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:o("No assets found")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:U.length>0?o("No assets found for your search: {{query}}",{query:U}):o("Start uploading assets to get started")}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:D==null?void 0:D.map(t=>e.jsxs("div",{className:M.mergeClasses("group relative flex max-h-[180px] max-w-[180px] cursor-pointer flex-col justify-between overflow-hidden rounded-lg border-2 transition-all",T.some(h=>h.id===t.id)?"border-blue-500":"hover:border-black/90",C&&(j==null?void 0:j.id)===t.id?"pointer-events-none opacity-50":"",C===t.id?"pointer-events-none opacity-50":""),onClick:()=>ne(t),onDoubleClick:()=>H([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[C===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin text-white"})}):null,t.type==="image"?e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:`h-full min-h-[80px] w-full object-contain ${T.some(h=>h.id===t.id)?"":"group-hover:blur group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex h-full items-center justify-center",children:[e.jsx(f.Film,{className:"h-12 w-12 text-muted-foreground"}),t.thumbnailUrl&&e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:"absolute inset-0 h-full w-full object-cover"})]})]}),e.jsxs("div",{className:"flex items-end justify-between border-t-[1px] border-black/10 bg-white px-2 py-1",children:[e.jsx("div",{className:"truncate text-xs leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"flex items-center justify-between whitespace-nowrap text-[9px] font-light text-muted-foreground",children:e.jsx("span",{children:Y.formatFileSize((t==null?void 0:t.size)||0)})})]}),!T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2 p-2",children:[e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ue(t)},children:e.jsx(f.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("View Details")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),navigator.clipboard.writeText(t.url),w.toast.success(o("Asset URL copied to clipboard"))},children:e.jsx(f.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Copy URL")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),m({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Edit Image")})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ce(t)},children:e.jsx(f.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("Delete Asset")})})]})})]})}),T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute right-1 top-1 h-max rounded-full border border-white bg-blue-500 p-1",children:e.jsx(f.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),I>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(g.ErrorBoundary,{fallback:e.jsx("div",{className:"text-red-500",children:o("Error loading pagination")}),children:e.jsx(ve,{currentPage:P,totalPages:I,onPageChange:xe,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(we,{assetId:N||i||"",onBack:()=>{S("grid"),v(null)},onEdit:t=>{m({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(N){p(!0);try{const h=D.find(O=>O.id===N);h&&await W(F.merge(h,{description:t}))}finally{p(!1)}}},isSaving:d})]}),c.show&&e.jsx(u.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ce,{imageUrl:c.file,onSave:me,onClose:()=>m({show:!1,file:""}),defaultSavedImageName:c.name,isEditing:!!c.id})}),j&&e.jsx(a.Dialog,{open:!!j,onOpenChange:()=>b(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:o("Delete Asset")}),e.jsx(a.DialogDescription,{children:o('Are you sure you want to delete "{{name}}"? This action cannot be undone.',{name:j.name})})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>b(null),children:o("Cancel")}),e.jsx(a.Button,{variant:"destructive",onClick:de,children:o("Delete")})]})]})})]})}exports.default=Te;
|
|
@@ -5,7 +5,7 @@ import { find as Ge, merge as Oe, pick as Y, first as Be, isEmpty as Ke } from "
|
|
|
5
5
|
import { ChevronLeft as he, ChevronRight as Qe, Loader as B, AlertCircle as Re, Copy as fe, Pencil as We, Link as Ve, Search as He, RefreshCwIcon as Xe, Archive as Ze, Film as Je, ImageIcon as Ye, Edit as et, Trash2 as tt, Check as it, Upload as lt, AlertTriangle as at } from "lucide-react";
|
|
6
6
|
import pe, { useState as y, useMemo as ge, useEffect as O, useCallback as M, Suspense as rt } from "react";
|
|
7
7
|
import { useDropzone as nt } from "react-dropzone";
|
|
8
|
-
import {
|
|
8
|
+
import { aQ as K, ar as Q, A as b, aR as st } from "./index-CtRx3Y3K.js";
|
|
9
9
|
import { toast as A } from "sonner";
|
|
10
10
|
import { f as ct, c as ot } from "./image-compression-DsZ1oqpb.js";
|
|
11
11
|
import { useQueryClient as te, useMutation as ie, useQuery as xe } from "@tanstack/react-query";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as t, jsxs as a } from "react/jsx-runtime";
|
|
2
|
-
import { aq as C, ar as A, A as T, as as w } from "./index-
|
|
2
|
+
import { aq as C, ar as A, A as T, as as w } from "./index-CtRx3Y3K.js";
|
|
3
3
|
import { useQueryClient as q, useMutation as F } from "@tanstack/react-query";
|
|
4
4
|
import { toast as v } from "sonner";
|
|
5
5
|
import { useTranslation as _ } from "@chaibuilder/sdk";
|
|
@@ -7,7 +7,7 @@ import { Dialog as G, DialogContent as L, DialogHeader as U, DialogTitle as j, D
|
|
|
7
7
|
import { isEmpty as M, initial as Q } from "lodash-es";
|
|
8
8
|
import { AlertCircle as V } from "lucide-react";
|
|
9
9
|
import { useState as p } from "react";
|
|
10
|
-
import { S as k } from "./slug-input-
|
|
10
|
+
import { S as k } from "./slug-input-CUTtvZQ9.js";
|
|
11
11
|
const H = () => {
|
|
12
12
|
const s = C(), o = q(), g = A();
|
|
13
13
|
return F({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index-CJcS3b8n.cjs"),N=require("@tanstack/react-query"),v=require("sonner"),E=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),P=require("lodash-es"),C=require("lucide-react"),g=require("react"),A=require("./slug-input-C0BtQs2w.cjs"),T=()=>{const t=p.useApiUrl(),u=N.useQueryClient(),h=p.useFetch();return N.useMutation({mutationFn:async({pageId:s,name:x,slug:r})=>{const o={pageId:s,name:x};return r&&(o.slug=r),await h(t,{action:"DUPLICATE_PAGE",data:o})},onSuccess:()=>{u.invalidateQueries({queryKey:[p.ACTIONS.GET_WEBSITE_PAGES]}),v.toast.success("Page duplicated successfully")},onError:s=>{v.toast.error("Failed to duplicate page",{description:s.message||"An error occurred while duplicating the page"})}})},w=({page:t,onClose:u,closePanel:h=()=>{}})=>{const{t:s}=E.useTranslation(),{mutate:x,isPending:r}=T(),[o,i]=g.useState(null),[d,D]=g.useState(`${t.name} (Copy)`),b=p.useChangePage(),n=P.isEmpty(t.slug),[m,I]=g.useState(n?"":`${t.slug.split("/").pop()}-copy`),f=n?"":P.initial(t.slug.split("/")).join("/"),[y,j]=g.useState(!1),q=l=>{if(l.preventDefault(),!d.trim()){i(s("Name is required"));return}if(!n&&!m.trim()){i(s("Slug is required"));return}i(null),j(!0);const S={pageId:t.id,name:d};n||(S.slug=`${f}/${m}`),x(S,{onSuccess:c=>{j(!1),u(),b(c.id,h)},onError:c=>{j(!1),c.code==="SLUG_EXISTS"?i(s("A page with this slug already exists. Please choose a different slug.")):c.code==="INVALID_SLUG"?i(s("The slug format is invalid. Please use only lowercase letters, numbers, and hyphens.")):c.code==="PERMISSION_DENIED"?i(s("You don't have permission to duplicate this page.")):i(c.message||s("Failed to duplicate page. Please try again later."))}})};return e.jsx(a.Dialog,{open:!!t,onOpenChange:u,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:s("Duplicate Page")}),e.jsx(a.DialogDescription,{children:s("Create a copy of the page with a new name and slug")})]}),e.jsxs("div",{className:"mb-4 rounded-md bg-gray-50 p-3",children:[e.jsxs("h3",{className:"mb-1 text-sm font-medium",children:[s("Duplicating:"),":"]}),e.jsxs("div",{className:"flex flex-col gap-1 text-sm text-gray-700",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Name"),":"]})," ",t.name]}),!n&&e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Slug"),":"]})," ",t.slug]}),e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Type"),":"]})," ",t.pageType]})]})]}),e.jsxs("form",{onSubmit:q,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:s("Name")}),e.jsx(a.Input,{id:"name",value:d,onChange:l=>D(l.target.value),required:!0})]}),!n&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"slug",className:"text-sm",children:s("Slug")}),e.jsx(A.SlugInput,{value:m,onChange:l=>I(l),parentSlug:f,onValidationChange:l=>{i(l?null:s("Invalid slug"))}})]}),o&&e.jsxs(a.Alert,{variant:"destructive",className:"py-2",children:[e.jsx(C.AlertCircle,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:o})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(a.Button,{type:"button",variant:"outline",onClick:u,disabled:r,children:s("Cancel")}),e.jsx(a.Button,{type:"submit",disabled:!d.trim()||!n&&!m.trim()||r||y,children:s(r||y?"Duplicating...":"Duplicate")})]})]})]})})};exports.default=w;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),h=require("lodash-es"),p=require("lucide-react"),d=require("react"),g=require("./index
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),x=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),h=require("lodash-es"),p=require("lucide-react"),d=require("react"),g=require("./index-CJcS3b8n.cjs"),f=({isDefaultLang:r,searchQuery:l,setSearchQuery:c})=>e.jsx(a.Input,{type:"text",autoFocus:!0,value:r?l:"",onChange:t=>c(t.target.value),placeholder:r?"Search pages...":"To search select default language",disabled:!r,onKeyDown:t=>t.stopPropagation()}),m=({dynamicPage:r,setDynamicPage:l,searchQuery:c,setSearchQuery:t,dynamicPages:n})=>{const{selectedLang:o,fallbackLang:i}=x.useLanguages(),u=(o==null?void 0:o.length)===0;return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",className:"w-max focus:outline-none focus:ring-0 border-[0px] rounded-md py-1 text-sm h-max border border-gray-200 hover:bg-gray-100 pl-4",children:[r?h.get(r,"name"):"Select Page",e.jsx(p.ChevronDown,{className:"ml-2 h-4 w-4"})]})}),e.jsxs(a.DropdownMenuContent,{className:"w-96 divide-y shadow-xl p-0 max-h-[75vh]",children:[e.jsx("div",{className:"p-1.5 bg-gray-50/30",children:e.jsx(f,{isDefaultLang:u,searchQuery:c,setSearchQuery:t})}),(n==null?void 0:n.length)===0?e.jsx("div",{className:"h-24 text-xs flex items-center justify-center",children:"No pages found"}):n==null?void 0:n.map(s=>e.jsx(a.DropdownMenuItem,{onClick:()=>l(s),disabled:u?i!==s.lang:o!==s.lang,className:`flex flex-col justify-start cursor-pointer overflow-x-auto whitespace-nowrap no-scrollbar ${s.id===(r==null?void 0:r.id)?"bg-blue-50":"hover:bg-gray-50"}`,children:e.jsx("div",{className:"w-full text-xs whitespace-nowrap px-2 py-[2px]",children:e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsx("span",{className:"font-mono font-medium text-gray-500 text-xs rounded-full px-2 py-[1px] border border-gray-300 truncate",children:s.slug})]})})},s.id))]})]})},j=()=>{const{dynamicPage:r,dynamicPages:l,allLangPages:c,selectedLang:t,searchQuery:n,updateDynamicPage:o,updateSearchQuery:i,onChangeLanguage:u}=g.useDynamicPageSelector(),s=d.useRef(void 0);return d.useEffect(()=>{s.current!==t&&r&&(u(),s.current=t)},[t,l]),e.jsx("div",{className:"relative",children:e.jsx(m,{dynamicPage:r,setDynamicPage:o,searchQuery:n,setSearchQuery:i,dynamicPages:c})})};exports.default=j;
|
|
@@ -4,7 +4,7 @@ import { DropdownMenu as h, DropdownMenuTrigger as p, Button as m, DropdownMenuC
|
|
|
4
4
|
import { get as v } from "lodash-es";
|
|
5
5
|
import { ChevronDown as w } from "lucide-react";
|
|
6
6
|
import { useRef as b, useEffect as N } from "react";
|
|
7
|
-
import { n as y } from "./index-
|
|
7
|
+
import { n as y } from "./index-CtRx3Y3K.js";
|
|
8
8
|
const D = ({
|
|
9
9
|
isDefaultLang: e,
|
|
10
10
|
searchQuery: l,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var xs=e=>{throw TypeError(e)};var ws=(e,t,s)=>t.has(e)||xs("Cannot "+s);var _=(e,t,s)=>(ws(e,t,"read from private field"),s?s.call(e):t.get(e)),R=(e,t,s)=>t.has(e)?xs("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),O=(e,t,s,n)=>(ws(e,t,"write to private field"),n?n.call(e,s):t.set(e,s),s);const o=require("react/jsx-runtime"),p=require("lodash-es"),h=require("react"),H=require("jotai"),S=require("@tanstack/react-query"),P=require("@chaibuilder/sdk"),g=require("@chaibuilder/sdk/ui"),x=require("lucide-react"),F=require("sonner"),Bs=require("@chaibuilder/runtime"),ar=require("@chaibuilder/sdk/web-blocks");function ir(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const z=ir(h),ze={ab:"Abkhazian",aa:"Afar",af:"Afrikaans",ak:"Akan",sq:"Albanian",am:"Amharic",ar:"Arabic",an:"Aragonese",hy:"Armenian",as:"Assamese",av:"Avaric",ae:"Avestan",ay:"Aymara",az:"Azerbaijani",bm:"Bambara",ba:"Bashkir",eu:"Basque",be:"Belarusian",bn:"Bengali",bh:"Bihari",bi:"Bislama",bs:"Bosnian",br:"Breton",bg:"Bulgarian",my:"Burmese",ca:"Catalan",ch:"Chamorro",ce:"Chechen",ny:"Chichewa",zh:"Chinese","zh-Hans":"Chinese (Simplified)","zh-Hant":"Chinese (Traditional)",cv:"Chuvash",kw:"Cornish",co:"Corsican",cr:"Cree",hr:"Croatian",cs:"Czech",da:"Danish",dv:"Maldivian",nl:"Dutch",dz:"Dzongkha",en:"English",eo:"Esperanto",et:"Estonian",ee:"Ewe",fo:"Faroese",fj:"Fijian",fi:"Finnish",fr:"French",ff:"Fula, Pular",gl:"Galician",gd:"Gaelic (Scottish)",gv:"Manx",ka:"Georgian",de:"German",el:"Greek",kl:"Kalaallisut",gn:"Guarani",gu:"Gujarati",ht:"Haitian Creole",ha:"Hausa",he:"Hebrew",hz:"Herero",hi:"Hindi",ho:"Hiri Motu",hu:"Hungarian",is:"Icelandic",io:"Ido",ig:"Igbo",id:"Indonesian",ia:"Interlingua",ie:"Interlingue",iu:"Inuktitut",ik:"Inupiak",ga:"Irish",it:"Italian",ja:"Japanese",jv:"Javanese",kn:"Kannada",kr:"Kanuri",ks:"Kashmiri",kk:"Kazakh",km:"Khmer",ki:"Kikuyu",rw:"Kinyarwanda",rn:"Kirundi",ky:"Kyrgyz",kv:"Komi",kg:"Kongo",ko:"Korean",ku:"Kurdish",kj:"Kwanyama",lo:"Lao",la:"Latin",lv:"Latvian",li:"Limburgish",ln:"Lingala",lt:"Lithuanian",lu:"Luga-Katanga",lg:"Luganda, Ganda",lb:"Luxembourgish",mk:"Macedonian",mg:"Malagasy",ms:"Malay",ml:"Malayalam",mt:"Maltese",mi:"Maori",mr:"Marathi",mh:"Marshallese",mo:"Moldavian",mn:"Mongolian",na:"Nauru",nv:"Navajo",ng:"Ndonga",nd:"Northern Ndebele",ne:"Nepali",no:"Norwegian",nb:"Norwegian bokmål",nn:"Norwegian nynorsk",ii:"Sichuan Yi",oc:"Occitan",oj:"Ojibwe",cu:"Old Church Slavonic",or:"Oriya",om:"Oromo",os:"Ossetian",pi:"Pāli",ps:"Pashto, Pushto",fa:"Persian (Farsi)",pl:"Polish",pt:"Portuguese",pa:"Punjabi (Eastern)",qu:"Quechua",rm:"Romansh",ro:"Romanian",ru:"Russian",se:"Sami",sm:"Samoan",sg:"Sango",sa:"Sanskrit",sr:"Serbian",sh:"Serbo-Croatian",st:"Sesotho",tn:"Setswana",sn:"Shona",sd:"Sindhi",si:"Sinhalese",ss:"Swati",sk:"Slovak",sl:"Slovenian",so:"Somali",nr:"Southern Ndebele",es:"Spanish",su:"Sundanese",sw:"Swahili (Kiswahili)",sv:"Swedish",tl:"Tagalog",ty:"Tahitian",tg:"Tajik",ta:"Tamil",tt:"Tatar",te:"Telugu",th:"Thai",bo:"Tibetan",ti:"Tigrinya",to:"Tonga",ts:"Tsonga",tr:"Turkish",tk:"Turkmen",tw:"Twi",ug:"Uyghur",uk:"Ukrainian",ur:"Urdu",uz:"Uzbek",ve:"Venda",vi:"Vietnamese",vo:"Volapük",wa:"Wallon",cy:"Welsh",wo:"Wolof",fy:"Western Frisian",xh:"Xhosa",yi:"Yiddish",yo:"Yoruba",za:"Zhuang, Chuang",zu:"Zulu"},y={GET_GLOBAL_JSONLD_ITEMS:"GET_GLOBAL_JSONLD_ITEMS",GENERATE_SEO_FIELD:"GENERATE_SEO_FIELD",UPDATE_PAGE_METADATA:"UPDATE_PAGE_METADATA",GET_BLOCK_ASYNC_PROPS:"GET_BLOCK_ASYNC_PROPS",ASK_AI:"ASK_AI",GET_DRAFT_PAGE:"GET_DRAFT_PAGE",CREATE_PAGE:"CREATE_PAGE",UPDATE_PAGE:"UPDATE_PAGE",DELETE_PAGE:"DELETE_PAGE",DUPLICATE_PAGE:"DUPLICATE_PAGE",CHANGE_SLUG:"CHANGE_SLUG",TAKE_OFFLINE:"TAKE_OFFLINE",PUBLISH_PAGE:"PUBLISH_PAGE",PUBLISH_CHANGES:"PUBLISH_CHANGES",ADD_NEW_LANGUAGE:"ADD_NEW_LANGUAGE",EDIT_LANGUAGE:"EDIT_LANGUAGE",DELETE_LANGUAGE:"DELETE_LANGUAGE",GET_CHANGES:"GET_CHANGES",GET_SERVER_BLOCK:"GET_SERVER_BLOCK",GET_LANGUAGE_PAGES:"GET_LANGUAGE_PAGES",GET_PROJECT_PAGES:"GET_PROJECT_PAGES",GET_WEBSITE_PAGES:"GET_WEBSITE_PAGES",UPDATE_WEBSITE_SETTINGS:"UPDATE_WEBSITE_SETTINGS",GET_COLLECTIONS:"GET_COLLECTIONS",GET_PAGE_TYPES:"GET_PAGE_TYPES",SEARCH_PAGES:"SEARCH_PAGES",GET_WEBSITE_DRAFT_SETTINGS:"GET_WEBSITE_DRAFT_SETTINGS",AI_CONTEXT:"AI_CONTEXT",GET_WEBSITE_DATA:"GET_WEBSITE_DATA",UPDATE_WEBSITE_DATA:"UPDATE_WEBSITE_DATA",GET_CHAI_USER:"GET_CHAI_USER",GET_SEO_FIELDS:"GET_SEO_FIELDS",GET_BUILDER_PAGE_DATA:"GET_BUILDER_PAGE_DATA",GET_PAGE_REVISIONS:"GET_PAGE_REVISIONS",DELETE_PAGE_REVISION:"DELETE_PAGE_REVISION",RESTORE_PAGE_REVISION:"RESTORE_PAGE_REVISION",GET_REVISION_DATA:"GET_REVISION_DATA",GET_PAGE_DATA:"GET_PAGE_DATA",GET_COMPARE_DATA:"GET_COMPARE_DATA",GET_ROLE_AND_PERMISSIONS:"GET_ROLE_AND_PERMISSIONS",UPSERT_LIBRARY_ITEM:"UPSERT_LIBRARY_ITEM",GET_LIBRARIES:"GET_LIBRARIES",GET_LIBRARY_ITEM:"GET_LIBRARY_ITEM",GET_LIBRARY_ITEMS:"GET_LIBRARY_ITEMS",DELETE_LIBRARY_ITEM:"DELETE_LIBRARY_ITEM",MARK_AS_TEMPLATE:"MARK_AS_TEMPLATE",UNMARK_AS_TEMPLATE:"UNMARK_AS_TEMPLATE",GET_TEMPLATES_BY_TYPE:"GET_TEMPLATES_BY_TYPE",GET_DYNAMIC_PAGES:"GET_DYNAMIC_PAGES",GET_APP_SHARED_JSONLD:"GET_APP_SHARED_JSONLD",UPDATE_APP_SHARED_JSONLD:"UPDATE_APP_SHARED_JSONLD",ADD_GLOBAL_SCHEMA:"ADD_GLOBAL_SCHEMA",UPDATE_GLOBAL_SCHEMA:"UPDATE_GLOBAL_SCHEMA",DELETE_GLOBAL_SCHEMA:"DELETE_GLOBAL_SCHEMA",TOGGLE_PAGE_GLOBAL_SCHEMA:"TOGGLE_PAGE_GLOBAL_SCHEMA",APPLY_SCHEMA_TO_ALL_PAGES:"APPLY_SCHEMA_TO_ALL_PAGES",REMOVE_SCHEMA_FROM_ALL_PAGES:"REMOVE_SCHEMA_FROM_ALL_PAGES",UPLOAD_ASSET:"UPLOAD_ASSET",DELETE_ASSET:"DELETE_ASSET",UPDATE_ASSET:"UPDATE_ASSET",GET_ASSETS:"GET_ASSETS",GET_ASSET:"GET_ASSET"},or=H.atom({}),kt=()=>H.useAtom(or),ne=(e,t)=>{const[s]=kt();return h.useMemo(()=>p.get(s,e,t),[s,e,t])},j=()=>ne("apiUrl","/chai/api"),Fs=()=>ne("usersApiUrl","/chai/users"),lr=()=>ne("assetsApiUrl","/chai/assets"),qs=()=>ne("websocket",null),cr=async(e,t,s={})=>await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",...s},body:JSON.stringify(t)}),ur=()=>{const e=N(),t=j();return h.useCallback(async({body:s,headers:n={},url:r=t,streamResponse:a=!1})=>e(r,s,n,a),[e])},N=()=>{const e=ne("onLogout"),t=ne("getAccessToken"),s=j();return h.useCallback(async(n=s,r,a={},i=!1)=>{const l=await t();try{const c=p.get(r,"action","").toLowerCase(),d=await cr(n+(c?`?action=${c}`:""),r,{...a,Authorization:`Bearer ${l}`});if(i)return d;if(d.status===401)return console.log("401 Response",d),e(),window.location.reload(),null;if(!d.ok){const u=await d.json();throw console.error(`API Error (${d.status}):`,u),{status:d.status,statusText:d.statusText,...u,message:u.error||u.message||`Server error: ${d.status}`}}return await d.json()}catch(c){throw console.error("API request failed:",r,c),c}},[e,t])};function le(){const[e,t]=h.useState(new URLSearchParams(window.location.search));return h.useEffect(()=>{const s=()=>{t(new URLSearchParams(window.location.search))};return window.addEventListener("popstate",s),()=>{window.removeEventListener("popstate",s)}},[]),[e,t]}const Ae=e=>{const t=j(),[s]=le(),n=e??s.get("page"),r=N();return S.useQuery({queryKey:[y.GET_LANGUAGE_PAGES,n],staleTime:1/0,gcTime:0,placeholderData:[],queryFn:async()=>{if(!n)return null;const a=await r(t,{action:y.GET_LANGUAGE_PAGES,data:{id:n}});return p.reverse(p.sortBy(a,"primaryPage"))},enabled:!!n})},dr=H.atom(null),Ks=()=>H.useAtom(dr),as=()=>{const[e]=Ks();return(e==null?void 0:e.slug)||""};function fr(e,t){const[s,n]=h.useState(e);return h.useEffect(()=>{const r=setTimeout(()=>n(e),t);return()=>clearTimeout(r)},[e,t]),s}const hr=({query:e,uuid:t})=>{const{selectedLang:s,fallbackLang:n}=P.useLanguages(),{data:r}=te(),a=r==null?void 0:r.pageType,i=j(),l=N(),{data:c,isFetching:d}=S.useQuery({queryKey:[y.GET_DYNAMIC_PAGES,e,a,t],staleTime:60*60*1e3,placeholderData:[],queryFn:async()=>await l(i,{action:y.GET_DYNAMIC_PAGES,data:{query:e,pageType:a,uuid:t}})||[],enabled:!!a}),u=h.useMemo(()=>s===""?c.filter(f=>f.lang===""||f.lang===n):c.filter(f=>f.lang===s),[s,n,c]);return{allLangPages:c,data:u,isFetching:d}},Vs=()=>{const{selectedLang:e,fallbackLang:t}=P.useLanguages(),[s,n]=Ks(),[r,a]=h.useState(""),i=fr(r,500),{allLangPages:l,data:c,isFetching:d}=hr({query:i}),u=h.useCallback(m=>n(m),[n]),f=h.useCallback(m=>a(m),[a]),E=h.useCallback(()=>{if(!s)return;const m=!(s!=null&&s.primaryPage),A=e.length===0,w=m?s==null?void 0:s.id:s==null?void 0:s.primaryPage,M=l.filter(T=>(T==null?void 0:T.primaryPage)===w||T.id===w).find(T=>A?T.lang===e||T.lang===t:T.lang===e);n(M||s)},[s,e,l,n,t]);return{isFetching:d,dynamicPage:s,searchQuery:r,selectedLang:e,dynamicPages:c,allLangPages:l,updateDynamicPage:u,updateSearchQuery:f,onChangeLanguage:E}},gr=H.atom({lastSaved:void 0}),is=()=>H.useAtom(gr),te=()=>{const[e]=le(),t=e.get("page"),{data:s,isFetching:n}=Ae();return{data:h.useMemo(()=>({...p.find(s,{id:t})||{}}),[s,t]),isFetching:n}},he=()=>{const[e]=le(),t=e.get("lang")??"",{data:s,isFetching:n}=Ae();return{data:h.useMemo(()=>p.find(s,{lang:t})||{},[s,t]),isFetching:n}},mr=H.atom({}),Er=()=>H.useAtom(mr),pr=()=>{const{data:e}=he(),t=as(),s=ne("getLiveUrl",p.noop),n=e==null?void 0:e.slug,r=s(n||"/");return t?r+t:r},Te=()=>{const e=j(),t=N();return S.useQuery({queryKey:[y.GET_WEBSITE_DRAFT_SETTINGS],staleTime:5*60*1e3,placeholderData:{languages:[],theme:{fontFamily:"",borderRadius:"",colors:{}},appKey:"",fallbackLang:"",designTokens:{}},queryFn:async()=>t(e,{action:y.GET_WEBSITE_DRAFT_SETTINGS,data:{draft:!0}})})};function os(e,t,s=!1){const n=e.toString()?`?${e.toString()}`:"/";s?window.history.replaceState(null,"",n):window.history.pushState({},"",n),t(e),window.dispatchEvent(new PopStateEvent("popstate"))}const Ot=H.atom(null),Rt=()=>{const e=ne("currentUser"),t=ne("onLogout");return{isLoggedIn:!!e,user:e,logout:t}},J={LOCKED:"LOCKED",EDITING:"EDITING",CHECKING:"CHECKING",TAKE_OVER_REQUESTED:"TAKE_OVER_REQUESTED",ACTIVE_IN_ANOTHER_TAB:"ACTIVE_IN_ANOTHER_TAB",FORCE_TAKE_OVER:"FORCE_TAKE_OVER",CONNECTION_LOST:"CONNECTION_LOST"},X={FORCE_TAKE_OVER:"FORCE_TAKE_OVER",TAKE_OVER_REQUEST:"TAKE_OVER_REQUEST",TAKE_OVER_APPROVED:"TAKE_OVER_APPROVED",TAKE_OVER_REJECTED:"TAKE_OVER_REJECTED",FORCE_TAKE_OVER_REQUEST:"FORCE_TAKE_OVER_REQUEST",CONTINUE_EDITING_IN_THIS_CLIENT:"CONTINUE_EDITING_IN_THIS_CLIENT",CONTINUE_EDITING_IN_THIS_TAB_REQUEST:"CONTINUE_EDITING_IN_THIS_TAB_REQUEST"},yr=["sync","join","leave"],Ar=[X.FORCE_TAKE_OVER,X.TAKE_OVER_REQUEST,X.TAKE_OVER_APPROVED,X.TAKE_OVER_REJECTED,X.FORCE_TAKE_OVER_REQUEST,X.CONTINUE_EDITING_IN_THIS_CLIENT,X.CONTINUE_EDITING_IN_THIS_TAB_REQUEST],Tr=H.atom({}),Hs=H.atom(null),Sr=H.atom(J.CHECKING),Pr=H.atom({}),_r=e=>{const t={},s=p.groupBy(p.values(e).map(p.first).filter(Boolean),"pageId");return Object.entries(s).forEach(([n,r])=>t[n]=p.minBy(r,"onlineAt")),t},xr=e=>{const t=p.minBy(p.values(e).map(p.first).filter(Boolean),"onlineAt"),s=t==null?void 0:t.onlineAt;return s?s-100:+new Date-1e3*60*60*4},Et=()=>{const{user:e}=Rt();return e==null?void 0:e.id},wr=()=>{const{data:e}=Te();return`WEBSITE:${e==null?void 0:e.appKey}`},pt=()=>{const{data:e}=te();return e==null?void 0:e.id},xe=crypto.randomUUID();let Vt=null;const ls=()=>{const[e,t]=H.useAtom(Tr);return{pageToUser:e,setPageToUser:t}},re=()=>{const[e,t]=H.useAtom(Sr),s=[J.LOCKED,J.ACTIVE_IN_ANOTHER_TAB].includes(e),n=[J.EDITING].includes(e);return{pageStatus:e,setPageStatus:t,isLocked:s,isEditing:n}},cs=()=>{const[e,t]=H.useAtom(Pr);return{pageLockMeta:e,setPageLockMeta:t}},Qs=()=>{const e=pt(),{pageToUser:t}=ls();return h.useMemo(()=>t[e],[t,e])},us=()=>{const e=qs(),{setPageStatus:t}=re(),[s]=H.useAtom(Hs);return h.useEffect(()=>{if(clearTimeout(Vt),!e)return Vt=setTimeout(()=>{e||t(J.EDITING)},500),()=>clearTimeout(Vt)},[e,t]),s},vr=()=>{const e=pt(),t=Et(),s=us(),{setPageToUser:n}=ls(),{setPageStatus:r,pageStatus:a}=re(),i=h.useRef(e);return i.current=e,h.useCallback(l=>{const c=l||s;if(!c)return[];const d=c==null?void 0:c.presenceState(),u=_r(d);n(u);const f=u[i.current];if(!f)r(J.CHECKING);else if(!t)r(J.CHECKING);else if(f.userId===t&&f.clientId===xe){if(a===J.TAKE_OVER_REQUESTED)return;r(J.EDITING)}else f.userId===t&&f.clientId!==xe?r(J.ACTIVE_IN_ANOTHER_TAB):r(J.LOCKED)},[s,n,r,t,a])},zs=()=>{const e=Et(),t=pt(),s=us(),n=Qs(),{setPageLockMeta:r}=cs(),a=h.useRef(t);return a.current=t,h.useCallback(async(i,l)=>{if(!s)return;const c=l||{};c.userId=e,c.pageId=a.current,c.senderClientId=xe,c.receiverClientId=(l==null?void 0:l.requestingClientId)||(n==null?void 0:n.clientId),await s.send({event:i,payload:c,type:"broadcast"}),r({})},[s,e,n,r])},br=()=>{const e=Et(),t=pt(),s=us(),{setPageStatus:n}=re(),{setPageLockMeta:r}=cs(),a=zs(),i=h.useRef(t),{savePageAsync:l}=P.useSavePage();return i.current=t,h.useCallback(c=>async({payload:d})=>{const u=d||{};if(!(!(u!=null&&u.pageId)||(u==null?void 0:u.pageId)!==i.current||(u==null?void 0:u.receiverClientId)!==xe))switch(r({}),c){case X.FORCE_TAKE_OVER_REQUEST:case X.CONTINUE_EDITING_IN_THIS_TAB_REQUEST:{try{await l(!0)}catch(f){console.error("Failed to save page before releasing lock:",f)}await a(X.CONTINUE_EDITING_IN_THIS_CLIENT,{requestingClientId:u==null?void 0:u.senderClientId}),setTimeout(()=>r({type:c}),0);break}case X.TAKE_OVER_REQUEST:{r({requestingUserId:u==null?void 0:u.userId,requestingClientId:u==null?void 0:u.senderClientId}),n(J.TAKE_OVER_REQUESTED);break}case X.CONTINUE_EDITING_IN_THIS_CLIENT:{const f=xr(s==null?void 0:s.presenceState());n(J.CHECKING),await(s==null?void 0:s.track({onlineAt:f,pageId:i.current,userId:e,clientId:xe}));break}case X.TAKE_OVER_REJECTED:{r({type:X.TAKE_OVER_REJECTED});break}}},[a,r,n,s,e,l])},Ir=()=>{const e=qs(),t=Et(),s=pt(),n=wr(),[r,a]=H.useAtom(Hs),i=br(),l=vr(),c=h.useRef(i),d=h.useRef(l);h.useEffect(()=>{c.current=i,d.current=l},[i,l]),h.useEffect(()=>{const u=()=>{document.visibilityState==="visible"&&r&&r.subscribe()};return document.addEventListener("visibilitychange",u),()=>{document.removeEventListener("visibilitychange",u)}},[r]),h.useEffect(()=>{if(!e||!t||!n||r&&r.topic===n)return;const u=e.channel(n,{config:{presence:{key:xe}}});return Ar.forEach(f=>{u.on("broadcast",{event:f},E=>{c.current(f)(E)})}),yr.forEach(f=>{u.on("presence",{event:f},()=>{d.current(u)})}),u.subscribe(async f=>{f==="SUBSCRIBED"?a(u):(f==="CHANNEL_ERROR"||f==="TIMED_OUT")&&console.log("Realtime connection failed",f)}),()=>{u.unsubscribe()}},[e,t,n,a]),h.useEffect(()=>(r&&s&&t&&r.track({pageId:s,userId:t,clientId:xe,onlineAt:+new Date}),()=>{r&&s&&r.untrack()}),[r,s,t])},Mt=()=>{const{data:e}=Te();return h.useMemo(()=>(e==null?void 0:e.fallbackLang)||"en",[e])},ds=()=>{const e=N(),t=j();return S.useQuery({queryKey:[y.GET_WEBSITE_PAGES],staleTime:1e3*60*5,queryFn:async()=>e(t,{action:y.GET_WEBSITE_PAGES})||[],placeholderData:s=>s||[]})},Cr=e=>{const t=N(),s=j(),n=Mt();return S.useQuery({queryKey:[y.GET_WEBSITE_PAGES,e,n],staleTime:1e3*60*5,enabled:!!e,queryFn:async()=>{if(n===e)return{};const r=await t(s,{action:y.GET_WEBSITE_PAGES,data:{lang:e}})||[];return p.keyBy(p.map(r,a=>({...a,lang:e})),"primaryPage")},placeholderData:r=>r||{}})},Lr=h.lazy(()=>Promise.resolve().then(()=>require("./page-manager-new-C3XuiDiM.cjs"))),$s=({children:e})=>{const{t}=P.useTranslation(),[s,n]=le(),r=s.get("page"),{data:a,isFetching:i}=te(),{data:l,isFetching:c}=ds(),[d,u]=h.useState(!1),[f,E]=h.useState(!0),{savePage:m}=P.useSavePage(),A=!!r&&!p.isEmpty(a),{isLocked:w}=re(),v=h.useMemo(()=>{if(!l||c)return!1;const L=l.find(q=>q.slug==="/");return L==null?void 0:L.id},[l,c]);h.useEffect(()=>{if(c||!v||l.some(D=>D.id===r))return;const q=new URLSearchParams({page:v});os(q,n),!c&&l&&E(!1)},[r,c,l,v,n]);const M=!f&&!r,T=!f&&!i&&p.isEmpty(a),C=d||M||T;return o.jsxs(o.Fragment,{children:[o.jsx("div",{className:"flex items-center gap-x-1",children:o.jsx("div",{className:"relative",children:o.jsxs(g.Tooltip,{children:[o.jsx(g.TooltipTrigger,{asChild:!0,onClick:()=>{w||m(),u(!0)},children:e||o.jsx(g.Button,{variant:"outline",className:"flex w-full items-center space-x-2 py-1",children:o.jsx(x.LogsIcon,{className:"h-4 w-4"})},"template-viewer")}),o.jsx(g.TooltipContent,{side:"right",children:o.jsx("p",{children:t("Open pages manager")})})]})})}),o.jsx(g.Sheet,{open:C,onOpenChange:L=>!L&&A&&u(!1),children:o.jsxs(g.SheetContent,{side:"left","aria-describedby":"pages-manager-description",className:`z-50 !min-w-[50vh] !max-w-[800px] border-border p-0 ${A?"":"sheet-hide-close-btn"}`,children:[o.jsxs(g.SheetHeader,{className:"mb-3 px-4 pt-4",children:[o.jsxs(g.SheetTitle,{className:"flex items-center gap-2 text-sm font-semibold",children:[o.jsx("div",{className:"flex h-9 w-9 items-center justify-center rounded-lg bg-primary text-primary-foreground",children:o.jsx(x.Folder,{className:"h-4 w-4"})}),o.jsxs("div",{className:"flex flex-col",children:[o.jsx("span",{className:"text-sm font-semibold",children:t("Pages")}),o.jsx("span",{id:"pages-manager-description",className:"text-xs font-normal text-muted-foreground",children:t("Manage your site structure")})]})]}),o.jsx(g.SheetDescription,{className:"sr-only",children:t("Manage your site structure")})]}),o.jsx("div",{className:"h-[calc(100vh-80px)] overflow-y-auto",children:C&&o.jsx(h.Suspense,{children:o.jsx(Lr,{close:()=>u(!1)})})})]})})]})},Nr=h.lazy(()=>Promise.resolve().then(()=>require("./add-new-language-page-B7fKZbYT.cjs"))),jr=()=>{const e=ne("topLeftCorner",null);return e?o.jsx("div",{className:"max-h-9 w-full overflow-hidden pr-2",children:h.createElement(e,{})}):null},Ws=({showAdd:e=!0,variant:t="ghost",goToDefaultLang:s=!1})=>{const{fallbackLang:n,languages:r,selectedLang:a,setSelectedLang:i}=P.useLanguages(),l=p.isEmpty(a)?n:a,[,c]=le(),{isLocked:d}=re(),{t:u}=P.useTranslation();h.useEffect(()=>{const T=new URLSearchParams(window.location.search),C=T.get("lang");C&&(r.includes(C)?i(C):(T.delete("lang"),c(T),i("")))},[r,c,i]);const[,f]=H.useAtom(Ot),{data:E}=te(),{data:m}=Te(),{data:A}=Ae(),w=h.useMemo(()=>{const T=p.compact(p.map(p.get(m,"languages"),C=>{const L=p.find(A,{lang:C});return{key:C,value:p.get(ze,C,C),isLangPageAdded:!!L}})).filter(Boolean);return[{key:n,value:p.get(ze,n),isLangPageAdded:!0},...T]},[n,A,m]),v=T=>{if(document.querySelector('[data-panel-id="seo"]')){const L=new CustomEvent("seo-language-switch-check",{detail:{fromLang:l,toLang:T,switchHandler:()=>M(T)}});window.dispatchEvent(L);return}M(T)},M=T=>{i(T);const C=new URLSearchParams(window.location.search);T===n?C.delete("lang"):C.set("lang",T),os(C,c)};return p.isEmpty(r)?null:d?o.jsxs(g.Button,{variant:"ghost",size:"sm",className:"ml-px h-max cursor-not-allowed gap-2 py-1.5 opacity-50",children:[o.jsx(x.Languages,{className:"h-4 w-4"}),p.get(ze,l,l),o.jsx(x.ChevronDown,{className:"h-4 w-4"})]}):s?o.jsx(g.Button,{onClick:()=>M(n),variant:"link",size:"sm",children:u("Switch to default language")}):o.jsx(o.Fragment,{children:o.jsxs(g.DropdownMenu,{children:[o.jsx(g.DropdownMenuTrigger,{asChild:!0,className:"focus:outline-none",children:o.jsxs(g.Button,{disabled:!!d,variant:t,size:"sm",className:"ml-px h-max gap-2 py-1.5",children:[o.jsx(x.Languages,{className:"h-4 w-4"}),p.get(ze,l,l),o.jsx(x.ChevronDown,{className:"h-4 w-4"})]})}),o.jsxs(g.DropdownMenuContent,{className:"space-y-1 border-border",children:[p.map(w.filter(T=>T.isLangPageAdded),T=>o.jsxs(g.DropdownMenuItem,{className:P.mergeClasses("flex cursor-pointer items-center justify-between text-xs font-medium text-gray-800",T.key===l&&"!bg-gray-200 text-gray-700"),onClick:()=>v(T.key),children:[o.jsx("div",{className:"text-slate-600",children:T.value}),T.key===n&&o.jsxs("small",{className:"flex items-center gap-x-1 text-[9px] leading-none text-orange-500",children:[o.jsx(x.Star,{fill:"orange",className:"h-2 w-2"}),"Primary"]})]},T.value)),e&&!p.isEmpty(w.filter(T=>!T.isLangPageAdded))&&o.jsxs(o.Fragment,{children:[o.jsx(g.Separator,{}),o.jsxs(g.Button,{size:"sm",variant:"ghost",onClick:()=>{E&&f({edit:!1,primaryPage:E.id})},className:"text-xs font-normal duration-200 hover:bg-slate-300 hover:text-slate-800",children:[o.jsx(x.Plus,{className:"mr-1 h-3 w-3"})," Add Langauge"]})]})]})]})})};function Dr(){const[e,t]=H.useAtom(Ot);return o.jsxs("div",{className:"relative z-10 flex items-center justify-end gap-1",children:[o.jsx(jr,{}),o.jsx($s,{}),e&&o.jsx(h.Suspense,{children:o.jsx(Nr,{isOpen:!0,id:e==null?void 0:e.id,edit:!!(e!=null&&e.id),primaryPage:e==null?void 0:e.primaryPage,preselectedLang:e==null?void 0:e.preselectedLang,onClose:()=>t(null)})})]})}function Gr(){return o.jsx("div",{className:"mt-2 space-y-2",children:Array.from({length:5}).map((e,t)=>o.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[o.jsxs("div",{className:"flex-1 space-y-1",children:[o.jsx(g.Skeleton,{className:"h-4 w-3/4"}),o.jsx(g.Skeleton,{className:"h-3 w-1/2"}),o.jsx(g.Skeleton,{className:"mt-1 h-5 w-20"})]}),o.jsx(g.Skeleton,{className:"h-8 w-8 rounded-full"})]},t))})}const kr=z.lazy(()=>Promise.resolve().then(()=>require("./page-revisions-content-CwrPL9kp.cjs")));function Or(){const[e,t]=z.useState(!1);return o.jsx(g.TooltipProvider,{children:o.jsxs(g.Tooltip,{delayDuration:0,children:[o.jsxs(g.Sheet,{open:e,onOpenChange:t,children:[o.jsx(g.SheetTrigger,{asChild:!0,children:o.jsx(g.TooltipTrigger,{asChild:!0,children:o.jsxs("span",{className:"flex items-center gap-2",children:[o.jsxs(g.Button,{variant:"ghost",size:"icon",className:"h-8 w-8",children:[o.jsx(x.History,{className:"h-4 w-4"}),o.jsx("span",{className:"sr-only",children:"View revision history"})]}),o.jsx("div",{className:"h-4 w-px bg-gray-200 dark:bg-gray-700"})]})})}),o.jsx(g.SheetContent,{className:"flex h-[100vh] flex-col",children:e&&o.jsx(h.Suspense,{fallback:o.jsx(Gr,{}),children:o.jsx(kr,{isOpen:e})})})]}),o.jsx(g.TooltipContent,{side:"bottom",children:o.jsx("p",{children:"Revision history"})})]})})}const _t=({permission:e,permissions:t,children:s,fallback:n=null})=>{const{hasPermission:r}=P.usePermissions();return e&&!r(e)||t&&!t.some(a=>r(a))?n:s},Rr={SLUG_ALREADY_USED:"This slug is already in use. Please choose a different one."},ge=()=>{const e=j(),t=N();return S.useQuery({queryKey:[y.GET_PAGE_TYPES],staleTime:1/0,placeholderData:[],queryFn:async()=>t(e,{action:y.GET_PAGE_TYPES})})},Ys=e=>{const{data:t}=ge();return h.useMemo(()=>t==null?void 0:t.find(s=>s.key===e),[t,e])},Mr=()=>{const e=j(),t=N();return S.useMutation({mutationFn:async({pageType:s,query:n})=>{try{return t(e,{action:y.SEARCH_PAGES,data:{pageType:s,query:Array.isArray(n)&&n.length>0?n[0]:n}})||[]}catch(r){return console.error(r),[]}}})},Ur=()=>{const e=j(),t=S.useQueryClient(),s=N(),{data:n}=ge();return S.useMutation({mutationFn:async r=>await s(e,{action:y.CREATE_PAGE,data:r}),onSuccess:(r,a)=>{var l;a&&(a!=null&&a.primaryPage)?(t.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES,a==null?void 0:a.primaryPage]}),t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES,a==null?void 0:a.lang]})):t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]});const i=a.template?`Page created from "${a.template.name}" template`:a.hasSlug===!1?"New "+((l=p.find(n,{key:a.pageType}))==null?void 0:l.name)+" added successfully":"New page added successfully";F.toast.success(i)},onError:(r,a)=>{const i=p.find(n,{key:a.pageType});F.toast.error(`Failed to add new ${i!=null&&i.hasSlug?"page":i.name}.`,{description:p.get(Rr,r.message,r.message)})}})},Br=()=>{const e=j(),t=S.useQueryClient(),s=N(),{data:n}=he(),{data:r}=ge();return S.useMutation({mutationFn:async a=>await s(e,{action:y.UPDATE_PAGE,data:a}),onSuccess:(a,i)=>{(n==null?void 0:n.id)===(i==null?void 0:i.id)&&t.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES]}),i&&(i!=null&&i.primaryPage||i!=null&&i.seo)?(t.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES,i==null?void 0:i.primaryPage]}),t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]})):t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]})},onError:(a,i)=>{const l=p.find(r,{key:i.pageType});F.toast.error(`Failed to update ${l!=null&&l.hasSlug?"page":l.name}.`,{description:a.message})}})},Fr=()=>{const e=j(),t=S.useQueryClient(),s=N(),{data:n}=ge();return S.useMutation({mutationFn:async r=>s(e,{action:y.DELETE_PAGE,data:{id:r==null?void 0:r.id}}),onSuccess:(r,a)=>{if(r.code==="PAGE_LOCKED"){F.toast.error("Delete not allowed",{description:"Page is currently being edited by another user."});return}a&&(a!=null&&a.primaryPage)?(t.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES,a==null?void 0:a.primaryPage]}),t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]})):t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]})},onError:(r,a)=>{const i=p.find(n,{key:a.pageType});F.toast.error(`Failed to delete ${i!=null&&i.hasSlug?"page":i.name}.`,{description:r.message})}})},qr=()=>{const e=j(),t=S.useQueryClient(),s=N(),{data:n}=ge();return S.useMutation({mutationFn:async r=>s(e,{action:y.TAKE_OFFLINE,data:{id:r==null?void 0:r.id}}),onSuccess:(r,a)=>{a&&(a!=null&&a.primaryPage)?t.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES,a==null?void 0:a.primaryPage]}):t.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]});const i=p.find(n,{key:a.pageType});F.toast.success(i!=null&&i.hasSlug?"Page unpublished successfully.":"New "+i.name+" added successfully.")},onError:(r,a)=>{const i=p.find(n,{key:a.pageType});F.toast.error(`Failed to take offline ${i!=null&&i.hasSlug?"page":i.name}.`,{description:r.message})}})},fs=()=>{const e=j(),t=N(),s=S.useQueryClient(),{data:n}=te(),{savePageAsync:r}=P.useSavePage();return S.useMutation({mutationFn:async({ids:a})=>(await r(),t(e,{action:y.PUBLISH_CHANGES,data:{ids:a}})),onSuccess:()=>{s.invalidateQueries({queryKey:[y.GET_CHANGES]}),s.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]}),s.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES,n==null?void 0:n.id]})},onError:a=>{console.log("##",a),F.toast.error("Failed to publish pages.")}})},Kr=()=>{const e=j(),t=N(),s=S.useQueryClient();return S.useMutation({mutationFn:async n=>{var r;return t(e,{action:y.MARK_AS_TEMPLATE,data:{id:(r=n.page)==null?void 0:r.id,name:n.name,description:n.description,pageType:n.pageType,previewImage:n.previewImage}})},onSuccess:()=>{s.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]}),F.toast.success("Page marked as template successfully.")},onError:()=>{F.toast.error("Failed to mark page as template.")}})},Vr=()=>{const e=j(),t=N(),s=S.useQueryClient();return S.useMutation({mutationFn:async n=>t(e,{action:y.UNMARK_AS_TEMPLATE,data:{id:n==null?void 0:n.id}}),onSuccess:()=>{s.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]}),F.toast.success("Page unmarked as template successfully.")},onError:()=>{F.toast.error("Failed to unmark page as template.")}})},Hr=()=>{const e=j(),t=N(),s=S.useQueryClient();return S.useMutation({mutationFn:async({id:n,slug:r})=>t(e,{action:y.CHANGE_SLUG,data:{id:n,slug:r}}),onSuccess:(n,{primaryPage:r})=>{F.toast.success("Slug changed successfully."),r?s.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES,r]}):s.invalidateQueries({queryKey:[y.GET_WEBSITE_PAGES]})},onError:()=>{F.toast.error("Failed to change slug")}})},Qr=h.lazy(()=>Promise.resolve().then(()=>require("./publish-pages-content-DTPjR33T.cjs")));function zr({showModal:e=!1,onClose:t=()=>console.log("Cancelled")}){const{mutate:s,isPending:n}=fs();return o.jsx(g.Dialog,{open:e,onOpenChange:n?()=>{}:t,children:e&&o.jsx(h.Suspense,{fallback:o.jsx("div",{className:"h-96 w-96 animate-pulse bg-gray-100"}),children:o.jsx(Qr,{onClose:t,isPending:n,publishPage:s})})})}const se={...P.PERMISSIONS,ADD_PAGE:"add_page",EDIT_PAGE:"edit_page",EDIT_SLUG:"edit_slug",DELETE_PAGE:"delete_page",CHANGE_PAGE_TYPE:"change_page_type",PUBLISH_PAGE:"publish_page",UNPUBLISH_PAGE:"unpublish_page",MARK_AS_TEMPLATE:"mark_as_template",UNMARK_AS_TEMPLATE:"unmark_as_template",ADD_PARTIAL:"add_partial",EDIT_PARTIAL:"edit_partial",DELETE_PARTIAL:"delete_partial",PUBLISH_PARTIAL:"publish_partial",UNPUBLISH_PARTIAL:"unpublish_partial",EDIT_SEO:"edit_seo",RESTORE_REVISION:"restore_revision",DELETE_REVISION:"delete_revision",PUBLISH_THEME:"publish_theme",EDIT_SETTINGS:"edit_settings",ADD_LIBRARY_BLOCK:"create_library_block",ADD_LIBRARY_TEMPLATE:"add_library_template",EDIT_LIBRARY_BLOCK:"edit_library_block",EDIT_LIBRARY_TEMPLATE:"edit_library_template",DELETE_LIBRARY_BLOCK:"delete_library_block",DELETE_LIBRARY_TEMPLATE:"delete_library_template",ADD_MEDIA:"add_media",EDIT_MEDIA:"edit_media",DELETE_MEDIA:"delete_media"},Js=e=>{const{fallbackLang:t}=P.useLanguages(),{data:s}=Te(),{data:n,isFetching:r}=Ae(),a=h.useMemo(()=>{const i={[t]:!0};return p.each(p.get(s,"languages"),l=>{const c=p.find(n,{lang:l});i[l]=!!c}),i},[t,n,s]);return r||p.isEmpty(e)||e&&a[e]},$r={particleCount:350,spread:120,origin:{y:.6},angle:90},Wr={TOP_RIGHT:{angle:225,origin:{x:.9,y:0}},BOTTOM_RIGHT:{angle:100,origin:{x:.9,y:.9}}},Yr=async()=>{const{default:e}=await Promise.resolve().then(()=>require("./confetti.module-BuUnQuWk.cjs"));return e},xt=e=>{let t=Wr[e];t||(t={});const s={...$r,...t};Yr().then(n=>n(s))};function Ut({children:e,content:t,side:s="bottom",delayDuration:n=700,showTooltip:r=!0}){return r?o.jsx(g.TooltipProvider,{children:o.jsxs(g.Tooltip,{delayDuration:n,children:[o.jsx(g.TooltipTrigger,{asChild:!0,children:e}),o.jsx(g.TooltipContent,{side:s,sideOffset:10,children:o.jsx("p",{children:t})})]})}):e}const Jr=h.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-ch791au1.cjs"))),Zr=h.lazy(()=>Promise.resolve().then(()=>require("./translation-warning-modal-Kctu12rQ.cjs"))),Xr=()=>{const{t:e}=P.useTranslation(),{selectedLang:t,fallbackLang:s}=P.useLanguages(),n=ne("getPreviewUrl",async E=>E),[r,a]=h.useState(""),{data:i}=te(),{data:l}=Ae(),{data:c}=ge(),d=h.useMemo(()=>{var E;return(E=l==null?void 0:l.find(m=>(m==null?void 0:m.lang)===t))==null?void 0:E.slug},[t,l]),u=h.useCallback(E=>{var m;return(m=p.find(c,{key:E}))==null?void 0:m.hasSlug},[c]),f=t===s?"":t;return h.useEffect(()=>{(async()=>{if(typeof n=="function"){const E=!u(i==null?void 0:i.pageType),m=await n(E?`${f!==""?f+"/":""}${i==null?void 0:i.id}`:d||"");a(m)}else a("")})()},[n,d,i==null?void 0:i.pageType,u,i==null?void 0:i.id,f]),o.jsx(o.Fragment,{children:o.jsx(Ut,{content:e("Open preview in new tab"),delayDuration:0,children:o.jsx("a",{href:r,target:"_blank",rel:"noopener noreferrer",children:o.jsx(g.Button,{variant:"ghost",size:"sm",className:"gap-2",children:o.jsx(x.Play,{className:"h-4 w-4"})})})})})},ea=()=>{const{t:e}=P.useTranslation(),[t,s]=P.useRightPanel();return o.jsxs(o.Fragment,{children:[o.jsx(Ut,{content:e("Theme"),delayDuration:0,children:o.jsx(g.Button,{variant:t==="theme"?"outline":"ghost",size:"icon",className:"gap-2",onClick:()=>s(t==="theme"?"block":"theme"),children:o.jsx(x.Palette,{className:"h-4 w-4"})})}),o.jsx("div",{className:"h-4 w-px bg-gray-200 dark:bg-gray-700"})]})},ta=()=>{const{t:e}=P.useTranslation(),[t,s]=h.useState(!1),{isLocked:n}=re(),{savePageAsync:r,saveState:a}=P.useSavePage();h.useEffect(()=>{const u=f=>{a==="UNSAVED"&&(f.preventDefault(),f.returnValue=!1)};return a==="UNSAVED"&&window.addEventListener("beforeunload",u),()=>{window.removeEventListener("beforeunload",u)}},[a]);const i=h.useCallback(async()=>{t||(s(!0),await r(),s(!1))},[r,t]),{buttonIcon:l,buttonClass:c,tooltipContent:d}=h.useMemo(()=>{switch(a){case"UNSAVED":return{tooltipContent:e("Save draft"),buttonIcon:o.jsx(x.Save,{className:"h-4 w-4"}),buttonClass:"gap-x-1"};case"SAVING":return{tooltipContent:e("Saving"),buttonIcon:o.jsx(x.Loader,{className:"h-4 w-4 animate-spin text-sky-700"}),buttonClass:"gap-x-1"};case"SAVED":return{tooltipContent:e("Saved"),buttonIcon:o.jsx(x.CheckCircle,{className:"h-4 w-4"}),buttonClass:"text-green-500 gap-x-1"}}},[a,e]);return n?null:o.jsxs(g.Button,{size:"sm",variant:"ghost",onClick:i,className:`${c} w-24 max-w-24`,children:[l," ",d]})},sa=()=>{const{t:e}=P.useTranslation(),{selectedLang:t}=P.useLanguages(),{data:s}=he(),{data:n}=Ae(),[r,a]=h.useState(!1),[i,l]=h.useState(!1),[c,d]=h.useState(null),{savePageAsync:u}=P.useSavePage(),[f,E]=h.useState(!1),{data:m}=te(),{mutate:A,isPending:w}=fs(),{needTranslations:v}=P.useSavePage(),M=v(),{buttonText:T,buttonClassName:C,isPublished:L}=h.useMemo(()=>{const I=m&&(m==null?void 0:m.online);return{buttonClassName:I?"hover:bg-green-600 bg-green-500":"",isPublished:I,buttonText:e(I?"Published":"Publish")}},[m,e]),q=async()=>{if(M){E(!0);return}D()},D=()=>{const I=[s==null?void 0:s.id,s==null?void 0:s.primaryPage];A({ids:p.compact(I)},{onSuccess:()=>xt("TOP_RIGHT")})},ce=()=>{E(!1),D()},ue=async()=>{E(!1),await u()},K=h.useMemo(()=>p.map(n??[],"id"),[n]);return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex",children:[o.jsxs(g.Button,{size:"sm",onClick:q,disabled:w||!(m!=null&&m.id),className:`relative flex items-center gap-1 overflow-hidden rounded-r-none text-white transition-all duration-300 ease-in-out ${C}`,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),children:[o.jsx("span",{className:`flex items-center transition-transform duration-300 ease-in-out ${i?"-translate-y-10":""}`,children:L?o.jsx(x.Send,{className:"h-4 w-4"}):o.jsx(x.Rocket,{className:"h-4 w-4"})}),o.jsx("span",{className:`absolute inset-0 left-3 flex items-center transition-transform duration-300 ease-in-out ${i?"":"translate-y-10"}`,children:L?o.jsx(x.Rocket,{className:"h-4 w-4"}):o.jsx(x.Send,{className:"h-4 w-4"})}),o.jsx("span",{children:T}),t?`(${p.upperCase(t)})`:""]}),o.jsxs(g.DropdownMenu,{children:[o.jsx(g.DropdownMenuTrigger,{asChild:!0,children:o.jsx(g.Button,{size:"sm",disabled:w||!(m!=null&&m.id),className:`rounded-l-none border-l border-white/50 px-2 text-white ${C}`,children:o.jsx(x.ChevronDown,{className:"h-4 w-4"})})}),o.jsxs(g.DropdownMenuContent,{align:"end",className:"w-52",children:[o.jsxs(g.DropdownMenuItem,{disabled:w,className:"cursor-pointer text-xs",onClick:()=>A({ids:K},{onSuccess:()=>xt("TOP_RIGHT")}),children:[e("Publish")," with translation pages"]}),!L&&o.jsxs(g.DropdownMenuItem,{disabled:w,className:"cursor-pointer text-xs",onClick:()=>A({ids:[m==null?void 0:m.id]},{onSuccess:()=>xt("TOP_RIGHT")}),children:[e("Publish")," page"]}),o.jsxs(g.DropdownMenuItem,{onClick:()=>a(!0),className:"cursor-pointer text-xs",children:[e("Open")," publish menu"]}),L&&o.jsxs(g.DropdownMenuItem,{onClick:()=>d(s),className:"cursor-pointer text-xs",children:[e("Unpublish")," page ",t?`(${p.upperCase(t)})`:""]})]})]})]}),o.jsx(zr,{showModal:r,onClose:()=>a(!1)}),c&&o.jsx(h.Suspense,{children:o.jsx(Jr,{page:c,onClose:()=>d(null)})}),f&&o.jsx(h.Suspense,{children:o.jsx(Zr,{isOpen:f,onClose:ue,onContinue:ce,isPending:w})})]})};function na(){const{isLocked:e}=re(),[t]=le(),s=t.get("lang"),n=Js(s);return e||!n?o.jsx("div",{}):o.jsxs("div",{className:"flex items-center justify-end gap-1",children:[o.jsx(Or,{}),o.jsx(_t,{permission:se.EDIT_THEME,children:o.jsx(ea,{})}),o.jsx(Xr,{}),o.jsx(_t,{permission:se.SAVE_PAGE,children:o.jsx(ta,{})}),o.jsx(_t,{permission:se.PUBLISH_PAGE,children:o.jsx(sa,{})})]})}const Zs=({page:e,setDuplicatePage:t,setAddEditPage:s,setUnpublishPage:n,setDeletePage:r,setMarkAsTemplate:a,setUnmarkAsTemplate:i,children:l,isLanguagePage:c})=>{const{t:d}=P.useTranslation(),{hasPermission:u}=P.usePermissions(),{data:f}=ge(),E=h.useMemo(()=>p.find(f,{key:e.pageType}),[f,e.pageType]),m=h.useMemo(()=>!!e.isTemplate,[e.isTemplate]),A=h.useMemo(()=>!!(E!=null&&E.hasSlug),[E==null?void 0:E.hasSlug]);return!u(se.EDIT_PAGE)&&!u(se.DELETE_PAGE)&&!u(se.UNPUBLISH_PAGE)||!e?null:o.jsxs(g.DropdownMenu,{children:[o.jsx(g.DropdownMenuTrigger,{asChild:!0,onClick:v=>v.stopPropagation(),children:l}),o.jsxs(g.DropdownMenuContent,{align:"center",className:"text-sm",children:[u(se.ADD_PAGE)&&!c&&o.jsxs(g.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:v=>{v.stopPropagation(),t(e)},children:[o.jsx(x.CopyPlusIcon,{className:"size-3"}),"Duplicate page"]}),u(se.EDIT_PAGE)&&o.jsxs(g.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:v=>{v.stopPropagation(),s({...e,global:!(E!=null&&E.hasSlug)})},children:[o.jsx(x.Pencil,{className:"size-3"}),"Edit"]}),(e==null?void 0:e.online)&&u(se.UNPUBLISH_PAGE)&&o.jsxs(g.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:v=>{v.stopPropagation(),n(e)},children:[o.jsx(x.Power,{className:"size-3"}),d("Unpublish")]}),u(se.DELETE_PAGE)&&o.jsxs(g.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:v=>{v.stopPropagation(),r(e)},children:[o.jsx(x.Trash,{className:"size-3"}),d("Delete")]}),u(se.MARK_AS_TEMPLATE)&&A&&!c&&o.jsx(o.Fragment,{children:m?o.jsxs(g.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:v=>{v.stopPropagation(),i(e)},children:[o.jsx(x.SquareLibrary,{className:"size-3"}),d("Unmark as template")]}):o.jsxs(g.DropdownMenuItem,{className:"flex cursor-pointer items-center gap-2",onClick:v=>{v.stopPropagation(),a(e)},children:[o.jsx(x.SquareLibrary,{className:"size-3"}),d("Mark as template")]})})]})]})},ra=h.lazy(()=>Promise.resolve().then(()=>require("./add-new-page-DBVt7xSO.cjs"))),aa=h.lazy(()=>Promise.resolve().then(()=>require("./delete-page-BOuq3v6x.cjs"))),ia=h.lazy(()=>Promise.resolve().then(()=>require("./duplicate-page-Ch9Fn-Gu.cjs"))),oa=h.lazy(()=>Promise.resolve().then(()=>require("./mark-as-template-Biqpp8uM.cjs"))),la=h.lazy(()=>Promise.resolve().then(()=>require("./unmark-as-template-DyUqAa9Z.cjs"))),ca=h.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-ch791au1.cjs"))),ua=()=>{const[e,t]=h.useState(null),[s,n]=h.useState(null),[r,a]=h.useState(null),[i,l]=h.useState(null),[c,d]=h.useState(null),[u,f]=h.useState(null),{data:E,isFetching:m}=he(),{selectedLang:A,fallbackLang:w}=P.useLanguages(),{data:v}=Ae(),M=v==null?void 0:v.find(D=>D.lang===A),{isLocked:T}=re(),C=!(E!=null&&E.slug),[,L]=H.useAtom(Ot);if(!E)return null;const q=D=>{A.length>0&&A!==w?L({edit:!0,id:D==null?void 0:D.id,primaryPage:D==null?void 0:D.primaryPage}):f(D)};return o.jsxs(o.Fragment,{children:[o.jsxs("div",{className:"flex items-center justify-between rounded px-[2px] transition-colors duration-200",children:[o.jsx($s,{children:o.jsx(g.Button,{className:"flex h-7 max-w-[200px] cursor-pointer items-center truncate rounded px-1 text-xs font-medium",variant:"ghost",children:m?o.jsx(x.Loader,{className:"h-4 w-4 animate-spin text-slate-400"}):o.jsxs("span",{className:"flex w-full cursor-pointer items-end overflow-hidden text-ellipsis whitespace-nowrap rounded-sm text-xs font-medium",children:[C?o.jsx(x.Hash,{className:"mr-1 h-4 w-4"}):o.jsx(x.File,{className:"mr-1 h-4 w-4"}),p.get(M||E,"name")??""]})})}),T?o.jsx(g.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 cursor-not-allowed rounded opacity-50 hover:bg-transparent",children:o.jsx(x.MoreHorizontal,{className:"h-4 w-4"})}):o.jsx(Zs,{page:E,setDuplicatePage:D=>d(D),setAddEditPage:D=>q(D),setUnpublishPage:D=>n(D),setDeletePage:D=>t(D),setMarkAsTemplate:D=>a(D),setUnmarkAsTemplate:D=>l(D),isLanguagePage:A.length>0&&A!==w,children:o.jsx(g.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded",children:o.jsx(x.MoreHorizontal,{className:"h-4 w-4"})})})]}),u&&o.jsx(h.Suspense,{children:o.jsx(ra,{closePanel:()=>f(null),editPage:()=>{},addEditPage:u,setAddEditPage:f})}),e&&o.jsx(h.Suspense,{children:o.jsx(aa,{page:e,onClose:()=>t(null)})}),s&&o.jsx(h.Suspense,{children:o.jsx(ca,{page:s,onClose:()=>n(null)})}),r&&o.jsx(h.Suspense,{children:o.jsx(oa,{page:r,onClose:()=>a(null)})}),i&&o.jsx(h.Suspense,{children:o.jsx(la,{page:i,onClose:()=>l(null)})}),c&&o.jsx(h.Suspense,{children:o.jsx(ia,{page:c,onClose:()=>d(null),closePanel:()=>f(null)})})]})},hs=({children:e,className:t=""})=>o.jsx("div",{className:P.mergeClasses("fixed bottom-0 left-0 right-0 top-[50px] z-[20] flex w-screen flex-col items-center justify-center bg-black/40 transition-all",t),children:e}),da=({hasDynamicPage:e})=>o.jsx(hs,{children:o.jsxs("div",{className:"flex min-w-[300px] max-w-[400px] flex-col items-center justify-center rounded-lg border bg-white p-4 shadow-lg",children:[o.jsx("h1",{className:"text-lg font-medium",children:e?"Select a page":"No pages found"}),o.jsx("p",{className:"pt-2 text-center text-sm font-light text-gray-600",children:e?"Please select a page from the list in the top header. This will enable you to edit the page.":"Please add a new page"})]})}),fa=h.lazy(()=>Promise.resolve().then(()=>require("./dynamic-page-selector-CZNYCxbJ.cjs"))),ha=()=>{const{dynamicPage:e,allLangPages:t,isFetching:s}=Vs(),n=t.length>0;return s?null:o.jsxs("div",{className:"relative",children:[!e&&o.jsx(da,{hasDynamicPage:n}),o.jsx(h.Suspense,{children:o.jsx(fa,{})})]})},ga=()=>{const{data:e,isFetching:t}=he(),{data:s,isFetching:n}=te(),r=p.get(s,"dynamic",!1),a=as(),i=P.useChaiFeatureFlag("dynamic-page-selector"),l=e==null?void 0:e.slug,c=!l,d=pr(),u=t||n,E=(c?`Partial: ${e==null?void 0:e.name} `:`${l}${a}`).replace(window.location.host,"");return o.jsxs("div",{className:"relative flex items-center gap-x-1",children:[o.jsx("div",{className:P.mergeClasses("flex h-8 w-auto max-w-[600px] items-center rounded-md border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800",u&&"max-w-0 overflow-hidden opacity-0"),children:o.jsx(ua,{})}),o.jsxs("div",{className:P.mergeClasses("flex h-8 w-auto max-w-[600px] items-center rounded-md border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800"+(c?" pr-2":""),u&&"max-w-0 overflow-hidden opacity-0"),children:[o.jsx(Ws,{}),o.jsxs("div",{className:"flex w-full items-center overflow-hidden",children:[o.jsx("div",{className:`w-full max-w-[200px] overflow-hidden overflow-ellipsis whitespace-nowrap pl-1 text-xs ${c?"italic text-gray-400":"font-mono text-gray-500"}`,children:E==="/"?o.jsxs("span",{className:"text-gray-900",children:["/",o.jsx("span",{className:"text-[11px] font-light italic text-gray-400",children:"(Homepage)"})]}):E}),!c&&o.jsx("a",{href:d,target:"_blank",rel:"noopener noreferrer",children:o.jsx("div",{className:"ml-2 mr-px flex-shrink-0 rounded-sm p-1.5 text-gray-500 hover:bg-gray-100 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300",children:o.jsx(x.ExternalLink,{className:"h-4 w-4",strokeWidth:1})})})]})]}),r&&i&&o.jsx(ha,{})]})},ma=()=>o.jsxs("div",{className:"flex h-full w-full items-center justify-between px-2",children:[o.jsx(Dr,{}),o.jsx(ga,{}),o.jsx(na,{})]}),Xs=()=>{const e=S.useQueryClient(),{data:t}=S.useQuery({queryKey:[y.AI_CONTEXT],initialData:"",queryFn:()=>"",staleTime:0});return{setAiContext:h.useCallback(n=>{e.setQueryData([y.AI_CONTEXT],n)},[e]),aiContext:t}},Ea=()=>{const e=j(),{aiContext:t}=Xs(),s=N();return h.useCallback(async(n,r,a,i)=>s(e,{action:y.ASK_AI,data:{type:n,prompt:r,blocks:a,context:t,lang:i}}),[e,t,s])},pa=(e,t)=>t.map(s=>{if(p.has(e,s._type)){const n=Bs.getDefaultBlockProps(s._type);return{...n,...p.pick(s,[...p.keys(n),"_type","_id","_name","_parent","_bindings"]),...p.pickBy(s,(r,a)=>p.endsWith(a,"_attrs")),...s}}return s}),ya=e=>{const t=Bs.useRegisteredChaiBlocks();return h.useMemo(()=>{if(!e||p.isEmpty(e))return{blocks:[]};const s=p.filter(e,n=>!p.includes(n==null?void 0:n._type,"@chai/"));return{blocks:pa(t,s)}},[e,t])},Aa=()=>{const[e]=le(),t=e.get("page"),s=j(),{setAiContext:n}=Xs(),[,r]=is(),[,a]=Er(),[,i]=P.useIsPageLoaded(),l=N();return S.useQuery({queryKey:[y.GET_DRAFT_PAGE,t],staleTime:1/0,gcTime:0,queryFn:async()=>{i(!1);const c=await l(s,{action:y.GET_DRAFT_PAGE,data:{id:t,draft:!0}}),d=c.blocks??[],u=p.find(d,{_type:"@chai/ai-context"});return n(p.get(u,"_value","")||""),r(f=>({...f,lastSaved:c.lastSaved})),a(p.get(c,"metadata",{})),setTimeout(()=>i(!0),500),d},enabled:!!t})},en=()=>{const{data:e}=te(),{data:t}=he(),s=j(),n=N(),r=Mt(),a=as();return S.useQuery({queryKey:[y.GET_BUILDER_PAGE_DATA,t==null?void 0:t.id,a],staleTime:1/0,gcTime:0,queryFn:async()=>n(s,{action:y.GET_BUILDER_PAGE_DATA,data:{pageType:e==null?void 0:e.pageType,lang:(t==null?void 0:t.lang)||r,dynamic:e==null?void 0:e.dynamic,pageProps:{slug:(t==null?void 0:t.slug)+a,searchParams:{},pageType:t==null?void 0:t.pageType,fallbackLang:r,lastSaved:t.lastSaved,pageId:e.id,primaryPageId:t.primaryPage||e.id,pageBaseSlug:t==null?void 0:t.slug,dynamic:e==null?void 0:e.dynamic,languagePageId:t.id,metadata:e.metadata||{}}}}),enabled:!!(e!=null&&e.pageType)&&!!t.id})},tn=()=>{const e=j(),t=S.useQueryClient(),s=N();return S.useMutation({mutationFn:async n=>s(e,{action:y.UPDATE_WEBSITE_SETTINGS,data:n}),onSuccess:(n,r)=>{var a;t.invalidateQueries({queryKey:[y.GET_WEBSITE_DRAFT_SETTINGS]}),(a=r==null?void 0:r.settings)!=null&&a.theme||F.toast.success("Website settings updated successfully.")},onError:n=>{F.toast.error("Failed to update website settings",{description:n.message})}})},Ta=()=>{const e=j(),t=S.useQueryClient(),s=N(),{selectedLang:n}=P.useLanguages();return S.useMutation({mutationFn:async r=>s(e,{action:y.ADD_GLOBAL_SCHEMA,data:{...r,lang:n}}),onSuccess:()=>{t.invalidateQueries({queryKey:[y.GET_GLOBAL_JSONLD_ITEMS]}),F.toast.success("Schema added successfully.")},onError:r=>{F.toast.error("Failed to add schema",{description:r.message})}})},Sa=()=>{const e=j(),t=S.useQueryClient(),s=N(),{selectedLang:n}=P.useLanguages();return S.useMutation({mutationFn:async r=>s(e,{action:y.UPDATE_GLOBAL_SCHEMA,data:{...r,lang:n}}),onSuccess:()=>{t.invalidateQueries({queryKey:[y.GET_GLOBAL_JSONLD_ITEMS]}),F.toast.success("Schema updated successfully.")},onError:r=>{F.toast.error("Failed to update schema",{description:r.message})}})},Pa=()=>{const e=j(),t=S.useQueryClient(),s=N();return S.useMutation({mutationFn:async n=>s(e,{action:y.DELETE_GLOBAL_SCHEMA,data:{id:n}}),onSuccess:()=>{t.invalidateQueries({queryKey:[y.GET_GLOBAL_JSONLD_ITEMS]}),F.toast.success("Schema deleted successfully.")},onError:n=>{F.toast.error("Failed to delete schema",{description:n.message})}})},_a=()=>{const e=j(),t=N();return S.useMutation({mutationFn:async s=>t(e,{action:y.TOGGLE_PAGE_GLOBAL_SCHEMA,data:s}),onError:s=>{F.toast.error("Failed to toggle schema",{description:s.message})}})},xa=()=>{const e=j(),t=N();return S.useMutation({mutationFn:async s=>t(e,{action:y.APPLY_SCHEMA_TO_ALL_PAGES,data:{schemaId:s}}),onSuccess:s=>{F.toast.success(`Schema applied to ${s.count} page(s)`)},onError:s=>{F.toast.error("Failed to apply schema to all pages",{description:s.message})}})},wa=()=>{const e=j(),t=N();return S.useMutation({mutationFn:async s=>t(e,{action:y.REMOVE_SCHEMA_FROM_ALL_PAGES,data:{schemaId:s}}),onSuccess:s=>{F.toast.success(`Schema removed from ${s.count} page(s)`)},onError:s=>{F.toast.error("Failed to remove schema from all pages",{description:s.message})}})},vs={async getUILibraryBlock(e,t,s){const n=await t(s,{action:"GET_LIBRARY_ITEM",data:{id:e.id}}),r=p.get(n,"html",""),a=p.get(n,"blocks",[]);return p.isArray(a)?a:P.getBlocksFromHTML(r)},async getUILibraryBlocks(e,t,s){try{return(await t(s,{action:"GET_LIBRARY_ITEMS",data:{id:e.id}})).map(r=>({...r}))}catch(n){return console.error(n),[]}}},va=()=>{const e=j(),t=N();return S.useQuery({queryKey:["uiLibraries"],staleTime:"static",queryFn:async()=>{const n=(await t(e,{action:"GET_LIBRARIES"})).map(r=>({...r}));return n.forEach(r=>{P.registerChaiLibrary(r.id,{name:r.isSiteLibrary?r.name+" (Current Site) ":r.name,description:r.description,getBlocksList:a=>vs.getUILibraryBlocks(a,t,e),getBlock:({block:a})=>vs.getUILibraryBlock(a,t,e)})}),n}})},sn=()=>{const e=Fs(),t=N(),{user:s}=Rt(),n=s==null?void 0:s.id;return S.useQuery({queryKey:[y.GET_ROLE_AND_PERMISSIONS,n],queryFn:()=>t(e,{action:y.GET_ROLE_AND_PERMISSIONS,data:{userId:n}}),enabled:!!n,staleTime:1/0})},ba=()=>{const e=j(),t=N(),[,s]=is();return{onSave:async({page:r,blocks:a,needTranslations:i})=>{try{const l=await t(e,{action:"UPDATE_PAGE",data:{id:r,blocks:a,needTranslations:i}});return l.code==="PAGE_LOCKED"?!0:(s(c=>({...c,lastSaved:new Date().toISOString()})),l)}catch(l){return console.error(l),new Error("Failed to save blocks")}}}},Ia=()=>{const{data:e}=ds(),t=j(),s=N();return{getPartialBlocks:h.useCallback(async()=>{const n={};for(const r of e??[])p.isEmpty(r==null?void 0:r.slug)&&(n[r.id]={type:r.pageType,name:p.startCase(r.name??r.slug),description:""});return n},[e]),getPartialBlockBlocks:h.useCallback(async n=>{if(!n)return[];try{const r=await s(t,{action:"GET_DRAFT_PAGE",data:{id:n,draft:!0,editor:!1}});return p.filter(r.blocks,a=>p.has(a,"_id"))}catch(r){return console.error(r),[]}},[s,t])}},Ca=h.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-content-Cv67WLJd.cjs")).then(e=>e.aiPanelContent)),nn="chai-chat-panel",La=({className:e="h-full w-full"})=>o.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 512 512",version:"1.1",className:e,children:[o.jsx("title",{children:"ai"}),o.jsx("g",{id:"Page-1",stroke:"none",strokeWidth:"1",fill:"none",fillRule:"evenodd",children:o.jsx("g",{id:"icon",fill:"currentColor",transform:"translate(64.000000, 64.000000)",children:o.jsx("path",{d:"M320,64 L320,320 L64,320 L64,64 L320,64 Z M171.749388,128 L146.817842,128 L99.4840387,256 L121.976629,256 L130.913039,230.977 L187.575039,230.977 L196.319607,256 L220.167172,256 L171.749388,128 Z M260.093778,128 L237.691519,128 L237.691519,256 L260.093778,256 L260.093778,128 Z M159.094727,149.47526 L181.409039,213.333 L137.135039,213.333 L159.094727,149.47526 Z M341.333333,256 L384,256 L384,298.666667 L341.333333,298.666667 L341.333333,256 Z M85.3333333,341.333333 L128,341.333333 L128,384 L85.3333333,384 L85.3333333,341.333333 Z M170.666667,341.333333 L213.333333,341.333333 L213.333333,384 L170.666667,384 L170.666667,341.333333 Z M85.3333333,0 L128,0 L128,42.6666667 L85.3333333,42.6666667 L85.3333333,0 Z M256,341.333333 L298.666667,341.333333 L298.666667,384 L256,384 L256,341.333333 Z M170.666667,0 L213.333333,0 L213.333333,42.6666667 L170.666667,42.6666667 L170.666667,0 Z M256,0 L298.666667,0 L298.666667,42.6666667 L256,42.6666667 L256,0 Z M341.333333,170.666667 L384,170.666667 L384,213.333333 L341.333333,213.333333 L341.333333,170.666667 Z M0,256 L42.6666667,256 L42.6666667,298.666667 L0,298.666667 L0,256 Z M341.333333,85.3333333 L384,85.3333333 L384,128 L341.333333,128 L341.333333,85.3333333 Z M0,170.666667 L42.6666667,170.666667 L42.6666667,213.333333 L0,213.333333 L0,170.666667 Z M0,85.3333333 L42.6666667,85.3333333 L42.6666667,128 L0,128 L0,85.3333333 Z",id:"Combined-Shape"})})})]}),Na=({isActive:e,show:t})=>o.jsx(g.Button,{size:"icon",className:"p-0 [&_svg]:size-6",onClick:t,variant:e?"default":"ghost",children:o.jsx(La,{className:e?"h-5 w-5 text-white":"h-5 w-5 text-primary"})}),ja={id:nn,label:"AI Assistant",button:Na,panel:Ca,position:"top"},Da=h.lazy(()=>Promise.resolve().then(()=>require("./lang-panel-DFe4DfU4.cjs"))),Ga=({isActive:e,show:t})=>{const{data:s}=Te();return!p.has(s,"languages")||!p.get(s,"languages",[]).length?null:o.jsx(g.Button,{size:"sm",onClick:t,variant:e?"default":"ghost",children:o.jsx(x.LanguagesIcon,{className:"h-4 w-4"})})},rn="lang",ka={id:rn,label:"Languages",position:"top",panel:Da,button:Ga,view:"modal",width:400},Oa=h.lazy(()=>Promise.resolve().then(()=>require("./seo-panel-Mjkh_Urn.cjs"))),an="seo",Ra=({isActive:e,show:t})=>{const{data:s}=te(),n=Ys(s==null?void 0:s.pageType);return!p.has(n,"hasSlug")||!n.hasSlug?null:o.jsx(g.Button,{size:"icon",className:"my-1 p-0",onClick:t,variant:e?"default":"ghost",children:o.jsxs("svg",{stroke:"currentColor",fill:"none",style:{height:"20px",width:"20px"},strokeWidth:"2",viewBox:"0 0 24 24",strokeLinecap:"round",strokeLinejoin:"round",children:[o.jsx("path",{d:"M7 8h-3a1 1 0 0 0 -1 1v2a1 1 0 0 0 1 1h2a1 1 0 0 1 1 1v2a1 1 0 0 1 -1 1h-3"}),o.jsx("path",{d:"M14 16h-4v-8h4"}),o.jsx("path",{d:"M11 12h2"}),o.jsx("path",{d:"M17 8m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v6a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z"})]})})},Ma={id:an,label:"SEO",panel:Oa,button:Ra,position:"top",width:600,view:"modal"},on="user-info",Ua=()=>{const{t:e}=P.useTranslation(),{user:t,logout:s}=Rt(),n=ne("onLogout",p.noop);return t?o.jsxs(g.HoverCard,{children:[o.jsx(g.HoverCardTrigger,{asChild:!0,children:o.jsx(g.Button,{variant:"ghost",className:"text-sm font-medium",children:o.jsx(x.User,{className:"h-4 w-4"})})}),o.jsxs(g.HoverCardContent,{className:"w-auto space-y-2 p-4",children:[o.jsx("div",{className:"text-sm font-medium",children:t.name??t.email}),o.jsx("div",{className:"text-xs text-muted-foreground",children:t.email}),o.jsxs(g.AlertDialog,{children:[o.jsx(g.AlertDialogTrigger,{asChild:!0,children:o.jsx(g.Button,{variant:"outline",size:"sm",className:"w-full",children:e("Logout")})}),o.jsxs(g.AlertDialogContent,{children:[o.jsxs(g.AlertDialogHeader,{children:[o.jsx(g.AlertDialogTitle,{children:e("Are you sure you want to logout?")}),o.jsx(g.AlertDialogDescription,{children:e("You will be redirected to the login page.")})]}),o.jsxs(g.AlertDialogFooter,{children:[o.jsx(g.AlertDialogCancel,{children:e("Cancel")}),o.jsx(g.AlertDialogAction,{onClick:()=>{s(),p.isFunction(n)&&n()},children:e("Logout")})]})]})]})]})]}):null},Ba={id:on,label:"User Info",button:Ua,position:"bottom"},Fa=()=>{P.registerChaiSidebarPanel(an,Ma),P.registerChaiSidebarPanel(rn,ka),P.registerChaiSidebarPanel(on,Ba),(localStorage.getItem("chai-feature-flags")??"").includes("enable-ai-chat-panel")&&P.registerChaiSidebarPanel(nn,ja)};var b={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return bs(this.context.count)},getNextContextId(){return bs(this.context.count++)}};function bs(e){const t=String(e),s=t.length-1;return b.context.id+(s?String.fromCharCode(96+s):"")+t}function $e(e){b.context=e}var ln=!1,qa=(e,t)=>e===t,bt=Symbol("solid-proxy"),cn=typeof Proxy=="function",gs=Symbol("solid-track"),It={equals:qa},un=yn,me=1,Ct=2,dn={owned:null,cleanups:null,context:null,owner:null},Ht={},k=null,Qt=null,Ka=null,U=null,Z=null,fe=null,Bt=0;function Ee(e,t){const s=U,n=k,r=e.length===0,a=t===void 0?n:t,i=r?dn:{owned:null,cleanups:null,context:a?a.context:null,owner:a},l=r?e:()=>e(()=>Y(()=>Xe(i)));k=i,U=null;try{return oe(l,!0)}finally{U=s,k=n}}function V(e,t){t=t?Object.assign({},It,t):It;const s={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0},n=r=>(typeof r=="function"&&(r=r(s.value)),pn(s,r));return[En.bind(s),n]}function fn(e,t,s){const n=Ft(e,t,!0,me);Qe(n)}function pe(e,t,s){const n=Ft(e,t,!1,me);Qe(n)}function ms(e,t,s){un=si;const n=Ft(e,t,!1,me);(!s||!s.render)&&(n.user=!0),fe?fe.push(n):Qe(n)}function $(e,t,s){s=s?Object.assign({},It,s):It;const n=Ft(e,t,!0,0);return n.observers=null,n.observerSlots=null,n.comparator=s.equals||void 0,Qe(n),En.bind(n)}function Va(e){return e&&typeof e=="object"&&"then"in e}function Ha(e,t,s){let n,r,a;n=!0,r=e,a={};let i=null,l=Ht,c=null,d=!1,u="initialValue"in a,f=typeof n=="function"&&$(n);const E=new Set,[m,A]=(a.storage||V)(a.initialValue),[w,v]=V(void 0),[M,T]=V(void 0,{equals:!1}),[C,L]=V(u?"ready":"unresolved");b.context&&(c=b.getNextContextId(),a.ssrLoadFrom==="initial"?l=a.initialValue:b.load&&b.has(c)&&(l=b.load(c)));function q(I,G,W,Q){return i===I&&(i=null,Q!==void 0&&(u=!0),(I===l||G===l)&&a.onHydrated&&queueMicrotask(()=>a.onHydrated(Q,{value:G})),l=Ht,D(G,W)),G}function D(I,G){oe(()=>{G===void 0&&A(()=>I),L(G!==void 0?"errored":u?"ready":"unresolved"),v(G);for(const W of E.keys())W.decrement();E.clear()},!1)}function ce(){const I=Xa,G=m(),W=w();if(W!==void 0&&!i)throw W;return U&&U.user,G}function ue(I=!0){if(I!==!1&&d)return;d=!1;const G=f?f():n;if(G==null||G===!1){q(i,Y(m));return}let W;const Q=l!==Ht?l:Y(()=>{try{return r(G,{value:m(),refetching:I})}catch(ae){W=ae}});if(W!==void 0){q(i,void 0,wt(W),G);return}else if(!Va(Q))return q(i,Q,void 0,G),Q;return i=Q,"v"in Q?(Q.s===1?q(i,Q.v,void 0,G):q(i,void 0,wt(Q.v),G),Q):(d=!0,queueMicrotask(()=>d=!1),oe(()=>{L(u?"refreshing":"pending"),T()},!1),Q.then(ae=>q(Q,ae,void 0,G),ae=>q(Q,void 0,wt(ae),G)))}Object.defineProperties(ce,{state:{get:()=>C()},error:{get:()=>w()},loading:{get(){const I=C();return I==="pending"||I==="refreshing"}},latest:{get(){if(!u)return ce();const I=w();if(I&&!i)throw I;return m()}}});let K=k;return f?fn(()=>(K=k,ue(!1))):ue(!1),[ce,{refetch:I=>gn(K,()=>ue(I)),mutate:A}]}function Qa(e){return oe(e,!1)}function Y(e){if(U===null)return e();const t=U;U=null;try{return e()}finally{U=t}}function za(e,t,s){const n=Array.isArray(e);let r,a=s&&s.defer;return i=>{let l;if(n){l=Array(e.length);for(let d=0;d<e.length;d++)l[d]=e[d]()}else l=e();if(a)return a=!1,i;const c=Y(()=>t(l,r,i));return r=l,c}}function hn(e){ms(()=>Y(e))}function Ve(e){return k===null||(k.cleanups===null?k.cleanups=[e]:k.cleanups.push(e)),e}function Is(){return k}function gn(e,t){const s=k,n=U;k=e,U=null;try{return oe(t,!0)}catch(r){Es(r)}finally{k=s,U=n}}function $a(e){const t=U,s=k;return Promise.resolve().then(()=>{U=t,k=s;let n;return oe(e,!1),U=k=null,n?n.done:void 0})}var[Wa,ll]=V(!1);function Ya(){return[Wa,$a]}function Ja(e,t){const s=Symbol("context");return{id:s,Provider:ni(s),defaultValue:e}}function Za(e){let t;return k&&k.context&&(t=k.context[e.id])!==void 0?t:e.defaultValue}function mn(e){const t=$(e),s=$(()=>Yt(t()));return s.toArray=()=>{const n=s();return Array.isArray(n)?n:n!=null?[n]:[]},s}var Xa;function En(){if(this.sources&&this.state)if(this.state===me)Qe(this);else{const e=Z;Z=null,oe(()=>Nt(this),!1),Z=e}if(U){const e=this.observers?this.observers.length:0;U.sources?(U.sources.push(this),U.sourceSlots.push(e)):(U.sources=[this],U.sourceSlots=[e]),this.observers?(this.observers.push(U),this.observerSlots.push(U.sources.length-1)):(this.observers=[U],this.observerSlots=[U.sources.length-1])}return this.value}function pn(e,t,s){let n=e.value;return(!e.comparator||!e.comparator(n,t))&&(e.value=t,e.observers&&e.observers.length&&oe(()=>{for(let r=0;r<e.observers.length;r+=1){const a=e.observers[r],i=Qt&&Qt.running;i&&Qt.disposed.has(a),(i?!a.tState:!a.state)&&(a.pure?Z.push(a):fe.push(a),a.observers&&An(a)),i||(a.state=me)}if(Z.length>1e6)throw Z=[],new Error},!1)),t}function Qe(e){if(!e.fn)return;Xe(e);const t=Bt;ei(e,e.value,t)}function ei(e,t,s){let n;const r=k,a=U;U=k=e;try{n=e.fn(t)}catch(i){return e.pure&&(e.state=me,e.owned&&e.owned.forEach(Xe),e.owned=null),e.updatedAt=s+1,Es(i)}finally{U=a,k=r}(!e.updatedAt||e.updatedAt<=s)&&(e.updatedAt!=null&&"observers"in e?pn(e,n):e.value=n,e.updatedAt=s)}function Ft(e,t,s,n=me,r){const a={fn:e,state:n,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:k,context:k?k.context:null,pure:s};return k===null||k!==dn&&(k.owned?k.owned.push(a):k.owned=[a]),a}function Lt(e){if(e.state===0)return;if(e.state===Ct)return Nt(e);if(e.suspense&&Y(e.suspense.inFallback))return e.suspense.effects.push(e);const t=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<Bt);)e.state&&t.push(e);for(let s=t.length-1;s>=0;s--)if(e=t[s],e.state===me)Qe(e);else if(e.state===Ct){const n=Z;Z=null,oe(()=>Nt(e,t[0]),!1),Z=n}}function oe(e,t){if(Z)return e();let s=!1;t||(Z=[]),fe?s=!0:fe=[],Bt++;try{const n=e();return ti(s),n}catch(n){s||(fe=null),Z=null,Es(n)}}function ti(e){if(Z&&(yn(Z),Z=null),e)return;const t=fe;fe=null,t.length&&oe(()=>un(t),!1)}function yn(e){for(let t=0;t<e.length;t++)Lt(e[t])}function si(e){let t,s=0;for(t=0;t<e.length;t++){const n=e[t];n.user?e[s++]=n:Lt(n)}if(b.context){if(b.count){b.effects||(b.effects=[]),b.effects.push(...e.slice(0,s));return}$e()}for(b.effects&&(b.done||!b.count)&&(e=[...b.effects,...e],s+=b.effects.length,delete b.effects),t=0;t<s;t++)Lt(e[t])}function Nt(e,t){e.state=0;for(let s=0;s<e.sources.length;s+=1){const n=e.sources[s];if(n.sources){const r=n.state;r===me?n!==t&&(!n.updatedAt||n.updatedAt<Bt)&&Lt(n):r===Ct&&Nt(n,t)}}}function An(e){for(let t=0;t<e.observers.length;t+=1){const s=e.observers[t];s.state||(s.state=Ct,s.pure?Z.push(s):fe.push(s),s.observers&&An(s))}}function Xe(e){let t;if(e.sources)for(;e.sources.length;){const s=e.sources.pop(),n=e.sourceSlots.pop(),r=s.observers;if(r&&r.length){const a=r.pop(),i=s.observerSlots.pop();n<r.length&&(a.sourceSlots[i]=n,r[n]=a,s.observerSlots[n]=i)}}if(e.tOwned){for(t=e.tOwned.length-1;t>=0;t--)Xe(e.tOwned[t]);delete e.tOwned}if(e.owned){for(t=e.owned.length-1;t>=0;t--)Xe(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}e.state=0}function wt(e){return e instanceof Error?e:new Error(typeof e=="string"?e:"Unknown error",{cause:e})}function Es(e,t=k){throw wt(e)}function Yt(e){if(typeof e=="function"&&!e.length)return Yt(e());if(Array.isArray(e)){const t=[];for(let s=0;s<e.length;s++){const n=Yt(e[s]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function ni(e,t){return function(n){let r;return pe(()=>r=Y(()=>(k.context={...k.context,[e]:n.value},mn(()=>n.children))),void 0),r}}var Jt=Symbol("fallback");function jt(e){for(let t=0;t<e.length;t++)e[t]()}function ri(e,t,s={}){let n=[],r=[],a=[],i=0,l=t.length>1?[]:null;return Ve(()=>jt(a)),()=>{let c=e()||[],d=c.length,u,f;return c[gs],Y(()=>{let m,A,w,v,M,T,C,L,q;if(d===0)i!==0&&(jt(a),a=[],n=[],r=[],i=0,l&&(l=[])),s.fallback&&(n=[Jt],r[0]=Ee(D=>(a[0]=D,s.fallback())),i=1);else if(i===0){for(r=new Array(d),f=0;f<d;f++)n[f]=c[f],r[f]=Ee(E);i=d}else{for(w=new Array(d),v=new Array(d),l&&(M=new Array(d)),T=0,C=Math.min(i,d);T<C&&n[T]===c[T];T++);for(C=i-1,L=d-1;C>=T&&L>=T&&n[C]===c[L];C--,L--)w[L]=r[C],v[L]=a[C],l&&(M[L]=l[C]);for(m=new Map,A=new Array(L+1),f=L;f>=T;f--)q=c[f],u=m.get(q),A[f]=u===void 0?-1:u,m.set(q,f);for(u=T;u<=C;u++)q=n[u],f=m.get(q),f!==void 0&&f!==-1?(w[f]=r[u],v[f]=a[u],l&&(M[f]=l[u]),f=A[f],m.set(q,f)):a[u]();for(f=T;f<d;f++)f in w?(r[f]=w[f],a[f]=v[f],l&&(l[f]=M[f],l[f](f))):r[f]=Ee(E);r=r.slice(0,i=d),n=c.slice(0)}return r});function E(m){if(a[f]=m,l){const[A,w]=V(f);return l[f]=w,t(c[f],A)}return t(c[f])}}}function ai(e,t,s={}){let n=[],r=[],a=[],i=[],l=0,c;return Ve(()=>jt(a)),()=>{const d=e()||[],u=d.length;return d[gs],Y(()=>{if(u===0)return l!==0&&(jt(a),a=[],n=[],r=[],l=0,i=[]),s.fallback&&(n=[Jt],r[0]=Ee(E=>(a[0]=E,s.fallback())),l=1),r;for(n[0]===Jt&&(a[0](),a=[],n=[],r=[],l=0),c=0;c<u;c++)c<n.length&&n[c]!==d[c]?i[c](()=>d[c]):c>=n.length&&(r[c]=Ee(f));for(;c<n.length;c++)a[c]();return l=i.length=a.length=u,n=d.slice(0),r=r.slice(0,l)});function f(E){a[c]=E;const[m,A]=V(d[c]);return i[c]=A,t(m,c)}}}function ps(e,t){return Y(()=>e(t||{}))}function Tt(){return!0}var Zt={get(e,t,s){return t===bt?s:e.get(t)},has(e,t){return t===bt?!0:e.has(t)},set:Tt,deleteProperty:Tt,getOwnPropertyDescriptor(e,t){return{configurable:!0,enumerable:!0,get(){return e.get(t)},set:Tt,deleteProperty:Tt}},ownKeys(e){return e.keys()}};function zt(e){return(e=typeof e=="function"?e():e)?e:{}}function ii(){for(let e=0,t=this.length;e<t;++e){const s=this[e]();if(s!==void 0)return s}}function ys(...e){let t=!1;for(let i=0;i<e.length;i++){const l=e[i];t=t||!!l&&bt in l,e[i]=typeof l=="function"?(t=!0,$(l)):l}if(cn&&t)return new Proxy({get(i){for(let l=e.length-1;l>=0;l--){const c=zt(e[l])[i];if(c!==void 0)return c}},has(i){for(let l=e.length-1;l>=0;l--)if(i in zt(e[l]))return!0;return!1},keys(){const i=[];for(let l=0;l<e.length;l++)i.push(...Object.keys(zt(e[l])));return[...new Set(i)]}},Zt);const s={},n=Object.create(null);for(let i=e.length-1;i>=0;i--){const l=e[i];if(!l)continue;const c=Object.getOwnPropertyNames(l);for(let d=c.length-1;d>=0;d--){const u=c[d];if(u==="__proto__"||u==="constructor")continue;const f=Object.getOwnPropertyDescriptor(l,u);if(!n[u])n[u]=f.get?{enumerable:!0,configurable:!0,get:ii.bind(s[u]=[f.get.bind(l)])}:f.value!==void 0?f:void 0;else{const E=s[u];E&&(f.get?E.push(f.get.bind(l)):f.value!==void 0&&E.push(()=>f.value))}}}const r={},a=Object.keys(n);for(let i=a.length-1;i>=0;i--){const l=a[i],c=n[l];c&&c.get?Object.defineProperty(r,l,c):r[l]=c?c.value:void 0}return r}function Tn(e,...t){if(cn&&bt in e){const r=new Set(t.length>1?t.flat():t[0]),a=t.map(i=>new Proxy({get(l){return i.includes(l)?e[l]:void 0},has(l){return i.includes(l)&&l in e},keys(){return i.filter(l=>l in e)}},Zt));return a.push(new Proxy({get(i){return r.has(i)?void 0:e[i]},has(i){return r.has(i)?!1:i in e},keys(){return Object.keys(e).filter(i=>!r.has(i))}},Zt)),a}const s={},n=t.map(()=>({}));for(const r of Object.getOwnPropertyNames(e)){const a=Object.getOwnPropertyDescriptor(e,r),i=!a.get&&!a.set&&a.enumerable&&a.writable&&a.configurable;let l=!1,c=0;for(const d of t)d.includes(r)&&(l=!0,i?n[c][r]=a.value:Object.defineProperty(n[c],r,a)),++c;l||(i?s[r]=a.value:Object.defineProperty(s,r,a))}return[...n,s]}function Sn(e){let t,s;const n=r=>{const a=b.context;if(a){const[l,c]=V();b.count||(b.count=0),b.count++,(s||(s=e())).then(d=>{!b.done&&$e(a),b.count--,c(()=>d.default),$e()}),t=l}else if(!t){const[l]=Ha(()=>(s||(s=e())).then(c=>c.default));t=l}let i;return $(()=>(i=t())?Y(()=>{if(!a||b.done)return i(r);const l=b.context;$e(a);const c=i(r);return $e(l),c}):"")};return n.preload=()=>s||((s=e()).then(r=>t=()=>r.default),s),n}var oi=0;function li(){return b.context?b.getNextContextId():`cl-${oi++}`}var Pn=e=>`Stale read from <${e}>.`;function ci(e){const t="fallback"in e&&{fallback:()=>e.fallback};return $(ri(()=>e.each,e.children,t||void 0))}function ui(e){const t="fallback"in e&&{fallback:()=>e.fallback};return $(ai(()=>e.each,e.children,t||void 0))}function di(e){const t=e.keyed,s=$(()=>e.when,void 0,void 0),n=t?s:$(s,void 0,{equals:(r,a)=>!r==!a});return $(()=>{const r=n();if(r){const a=e.children;return typeof a=="function"&&a.length>0?Y(()=>a(t?r:()=>{if(!Y(n))throw Pn("Show");return s()})):a}return e.fallback},void 0,void 0)}function fi(e){const t=mn(()=>e.children),s=$(()=>{const n=t(),r=Array.isArray(n)?n:[n];let a=()=>{};for(let i=0;i<r.length;i++){const l=i,c=r[i],d=a,u=$(()=>d()?void 0:c.when,void 0,void 0),f=c.keyed?u:$(u,void 0,{equals:(E,m)=>!E==!m});a=()=>d()||(f()?[l,u,c]:void 0)}return a});return $(()=>{const n=s()();if(!n)return e.fallback;const[r,a,i]=n,l=i.children;return typeof l=="function"&&l.length>0?Y(()=>l(i.keyed?a():()=>{var d;if(((d=Y(s)())==null?void 0:d[0])!==r)throw Pn("Match");return a()})):l},void 0,void 0)}function hi(e){return e}var gi=["allowfullscreen","async","autofocus","autoplay","checked","controls","default","disabled","formnovalidate","hidden","indeterminate","inert","ismap","loop","multiple","muted","nomodule","novalidate","open","playsinline","readonly","required","reversed","seamless","selected"],mi=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline",...gi]),Ei=new Set(["innerHTML","textContent","innerText","children"]),pi=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),yi=Object.assign(Object.create(null),{class:"className",novalidate:{$:"noValidate",FORM:1},formnovalidate:{$:"formNoValidate",BUTTON:1,INPUT:1},ismap:{$:"isMap",IMG:1},nomodule:{$:"noModule",SCRIPT:1},playsinline:{$:"playsInline",VIDEO:1},readonly:{$:"readOnly",INPUT:1,TEXTAREA:1}});function Ai(e,t){const s=yi[e];return typeof s=="object"?s[t]?s.$:void 0:s}var Ti=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),Si=new Set(["altGlyph","altGlyphDef","altGlyphItem","animate","animateColor","animateMotion","animateTransform","circle","clipPath","color-profile","cursor","defs","desc","ellipse","feBlend","feColorMatrix","feComponentTransfer","feComposite","feConvolveMatrix","feDiffuseLighting","feDisplacementMap","feDistantLight","feDropShadow","feFlood","feFuncA","feFuncB","feFuncG","feFuncR","feGaussianBlur","feImage","feMerge","feMergeNode","feMorphology","feOffset","fePointLight","feSpecularLighting","feSpotLight","feTile","feTurbulence","filter","font","font-face","font-face-format","font-face-name","font-face-src","font-face-uri","foreignObject","g","glyph","glyphRef","hkern","image","line","linearGradient","marker","mask","metadata","missing-glyph","mpath","path","pattern","polygon","polyline","radialGradient","rect","set","stop","svg","switch","symbol","text","textPath","tref","tspan","use","view","vkern"]),Pi={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},_i=e=>$(()=>e());function xi(e,t,s){let n=s.length,r=t.length,a=n,i=0,l=0,c=t[r-1].nextSibling,d=null;for(;i<r||l<a;){if(t[i]===s[l]){i++,l++;continue}for(;t[r-1]===s[a-1];)r--,a--;if(r===i){const u=a<n?l?s[l-1].nextSibling:s[a-l]:c;for(;l<a;)e.insertBefore(s[l++],u)}else if(a===l)for(;i<r;)(!d||!d.has(t[i]))&&t[i].remove(),i++;else if(t[i]===s[a-1]&&s[l]===t[r-1]){const u=t[--r].nextSibling;e.insertBefore(s[l++],t[i++].nextSibling),e.insertBefore(s[--a],u),t[r]=s[a]}else{if(!d){d=new Map;let f=l;for(;f<a;)d.set(s[f],f++)}const u=d.get(t[i]);if(u!=null)if(l<u&&u<a){let f=i,E=1,m;for(;++f<r&&f<a&&!((m=d.get(t[f]))==null||m!==u+E);)E++;if(E>u-l){const A=t[i];for(;l<u;)e.insertBefore(s[l++],A)}else e.replaceChild(s[l++],t[i++])}else i++;else t[i++].remove()}}}var Je="_$DX_DELEGATE";function _n(e,t,s,n={}){let r;return Ee(a=>{r=a,t===document?e():Gt(t,e(),t.firstChild?null:void 0,s)},n.owner),()=>{r(),t.textContent=""}}function wi(e,t,s,n){let r;const a=()=>{const l=document.createElement("template");return l.innerHTML=e,l.content.firstChild},i=()=>(r||(r=a())).cloneNode(!0);return i.cloneNode=i,i}function xn(e,t=window.document){const s=t[Je]||(t[Je]=new Set);for(let n=0,r=e.length;n<r;n++){const a=e[n];s.has(a)||(s.add(a),t.addEventListener(a,Cn))}}function vi(e=window.document){if(e[Je]){for(let t of e[Je].keys())e.removeEventListener(t,Cn);delete e[Je]}}function Dt(e,t,s){we(e)||(s==null?e.removeAttribute(t):e.setAttribute(t,s))}function bi(e,t,s,n){we(e)||(n==null?e.removeAttributeNS(t,s):e.setAttributeNS(t,s,n))}function Ii(e,t,s){we(e)||(s?e.setAttribute(t,""):e.removeAttribute(t))}function wn(e,t){we(e)||(t==null?e.removeAttribute("class"):e.className=t)}function vn(e,t,s,n){if(n)Array.isArray(s)?(e[`$$${t}`]=s[0],e[`$$${t}Data`]=s[1]):e[`$$${t}`]=s;else if(Array.isArray(s)){const r=s[0];e.addEventListener(t,s[0]=a=>r.call(e,s[1],a))}else e.addEventListener(t,s,typeof s!="function"&&s)}function Ci(e,t,s={}){const n=Object.keys(t||{}),r=Object.keys(s);let a,i;for(a=0,i=r.length;a<i;a++){const l=r[a];!l||l==="undefined"||t[l]||(Cs(e,l,!1),delete s[l])}for(a=0,i=n.length;a<i;a++){const l=n[a],c=!!t[l];!l||l==="undefined"||s[l]===c||!c||(Cs(e,l,!0),s[l]=c)}return s}function Li(e,t,s){if(!t)return s?Dt(e,"style"):t;const n=e.style;if(typeof t=="string")return n.cssText=t;typeof s=="string"&&(n.cssText=s=void 0),s||(s={}),t||(t={});let r,a;for(a in s)t[a]==null&&n.removeProperty(a),delete s[a];for(a in t)r=t[a],r!==s[a]&&(n.setProperty(a,r),s[a]=r);return s}function bn(e,t={},s,n){const r={};return n||pe(()=>r.children=et(e,t.children,r.children)),pe(()=>typeof t.ref=="function"&&In(t.ref,e)),pe(()=>Ni(e,t,s,!0,r,!0)),r}function In(e,t,s){return Y(()=>e(t,s))}function Gt(e,t,s,n){if(s!==void 0&&!n&&(n=[]),typeof t!="function")return et(e,t,n,s);pe(r=>et(e,t(),r,s),n)}function Ni(e,t,s,n,r={},a=!1){t||(t={});for(const i in r)if(!(i in t)){if(i==="children")continue;r[i]=Ls(e,i,null,r[i],s,a,t)}for(const i in t){if(i==="children")continue;const l=t[i];r[i]=Ls(e,i,l,r[i],s,a,t)}}function ji(e){let t,s;return!we()||!(t=b.registry.get(s=Gi()))?e():(b.completed&&b.completed.add(t),b.registry.delete(s),t)}function we(e){return!!b.context&&!b.done&&(!e||e.isConnected)}function Di(e){return e.toLowerCase().replace(/-([a-z])/g,(t,s)=>s.toUpperCase())}function Cs(e,t,s){const n=t.trim().split(/\s+/);for(let r=0,a=n.length;r<a;r++)e.classList.toggle(n[r],s)}function Ls(e,t,s,n,r,a,i){let l,c,d,u,f;if(t==="style")return Li(e,s,n);if(t==="classList")return Ci(e,s,n);if(s===n)return n;if(t==="ref")a||s(e);else if(t.slice(0,3)==="on:"){const E=t.slice(3);n&&e.removeEventListener(E,n,typeof n!="function"&&n),s&&e.addEventListener(E,s,typeof s!="function"&&s)}else if(t.slice(0,10)==="oncapture:"){const E=t.slice(10);n&&e.removeEventListener(E,n,!0),s&&e.addEventListener(E,s,!0)}else if(t.slice(0,2)==="on"){const E=t.slice(2).toLowerCase(),m=Ti.has(E);if(!m&&n){const A=Array.isArray(n)?n[0]:n;e.removeEventListener(E,A)}(m||s)&&(vn(e,E,s,m),m&&xn([E]))}else if(t.slice(0,5)==="attr:")Dt(e,t.slice(5),s);else if(t.slice(0,5)==="bool:")Ii(e,t.slice(5),s);else if((f=t.slice(0,5)==="prop:")||(d=Ei.has(t))||!r&&((u=Ai(t,e.tagName))||(c=mi.has(t)))||(l=e.nodeName.includes("-")||"is"in i)){if(f)t=t.slice(5),c=!0;else if(we(e))return s;t==="class"||t==="className"?wn(e,s):l&&!c&&!d?e[Di(t)]=s:e[u||t]=s}else{const E=r&&t.indexOf(":")>-1&&Pi[t.split(":")[0]];E?bi(e,E,t,s):Dt(e,pi[t]||t,s)}return s}function Cn(e){if(b.registry&&b.events&&b.events.find(([c,d])=>d===e))return;let t=e.target;const s=`$$${e.type}`,n=e.target,r=e.currentTarget,a=c=>Object.defineProperty(e,"target",{configurable:!0,value:c}),i=()=>{const c=t[s];if(c&&!t.disabled){const d=t[`${s}Data`];if(d!==void 0?c.call(t,d,e):c.call(t,e),e.cancelBubble)return}return t.host&&typeof t.host!="string"&&!t.host._$host&&t.contains(e.target)&&a(t.host),!0},l=()=>{for(;i()&&(t=t._$host||t.parentNode||t.host););};if(Object.defineProperty(e,"currentTarget",{configurable:!0,get(){return t||document}}),b.registry&&!b.done&&(b.done=_$HY.done=!0),e.composedPath){const c=e.composedPath();a(c[0]);for(let d=0;d<c.length-2&&(t=c[d],!!i());d++){if(t._$host){t=t._$host,l();break}if(t.parentNode===r)break}}else l();a(n)}function et(e,t,s,n,r){const a=we(e);if(a){!s&&(s=[...e.childNodes]);let c=[];for(let d=0;d<s.length;d++){const u=s[d];u.nodeType===8&&u.data.slice(0,2)==="!$"?u.remove():c.push(u)}s=c}for(;typeof s=="function";)s=s();if(t===s)return s;const i=typeof t,l=n!==void 0;if(e=l&&s[0]&&s[0].parentNode||e,i==="string"||i==="number"){if(a||i==="number"&&(t=t.toString(),t===s))return s;if(l){let c=s[0];c&&c.nodeType===3?c.data!==t&&(c.data=t):c=document.createTextNode(t),s=be(e,s,n,c)}else s!==""&&typeof s=="string"?s=e.firstChild.data=t:s=e.textContent=t}else if(t==null||i==="boolean"){if(a)return s;s=be(e,s,n)}else{if(i==="function")return pe(()=>{let c=t();for(;typeof c=="function";)c=c();s=et(e,c,s,n)}),()=>s;if(Array.isArray(t)){const c=[],d=s&&Array.isArray(s);if(Xt(c,t,s,r))return pe(()=>s=et(e,c,s,n,!0)),()=>s;if(a){if(!c.length)return s;if(n===void 0)return s=[...e.childNodes];let u=c[0];if(u.parentNode!==e)return s;const f=[u];for(;(u=u.nextSibling)!==n;)f.push(u);return s=f}if(c.length===0){if(s=be(e,s,n),l)return s}else d?s.length===0?Ns(e,c,n):xi(e,s,c):(s&&be(e),Ns(e,c));s=c}else if(t.nodeType){if(a&&t.parentNode)return s=l?[t]:t;if(Array.isArray(s)){if(l)return s=be(e,s,n,t);be(e,s,null,t)}else s==null||s===""||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);s=t}}return s}function Xt(e,t,s,n){let r=!1;for(let a=0,i=t.length;a<i;a++){let l=t[a],c=s&&s[e.length],d;if(!(l==null||l===!0||l===!1))if((d=typeof l)=="object"&&l.nodeType)e.push(l);else if(Array.isArray(l))r=Xt(e,l,c)||r;else if(d==="function")if(n){for(;typeof l=="function";)l=l();r=Xt(e,Array.isArray(l)?l:[l],Array.isArray(c)?c:[c])||r}else e.push(l),r=!0;else{const u=String(l);c&&c.nodeType===3&&c.data===u?e.push(c):e.push(document.createTextNode(u))}}return r}function Ns(e,t,s=null){for(let n=0,r=t.length;n<r;n++)e.insertBefore(t[n],s)}function be(e,t,s,n){if(s===void 0)return e.textContent="";const r=n||document.createTextNode("");if(t.length){let a=!1;for(let i=t.length-1;i>=0;i--){const l=t[i];if(r!==l){const c=l.parentNode===e;!a&&!i?c?e.replaceChild(r,l):e.insertBefore(r,s):c&&l.remove()}else a=!0}}else e.insertBefore(r,s);return[r]}function Gi(){return b.getNextContextId()}var ki="http://www.w3.org/2000/svg";function Ln(e,t=!1){return t?document.createElementNS(ki,e):document.createElement(e)}function Oi(e){const{useShadow:t}=e,s=document.createTextNode(""),n=()=>e.mount||document.body,r=Is();let a,i=!!b.context;return ms(()=>{i&&(Is().user=i=!1),a||(a=gn(r,()=>$(()=>e.children)));const l=n();if(l instanceof HTMLHeadElement){const[c,d]=V(!1),u=()=>d(!0);Ee(f=>Gt(l,()=>c()?f():a(),null)),Ve(u)}else{const c=Ln(e.isSVG?"g":"div",e.isSVG),d=t&&c.attachShadow?c.attachShadow({mode:"open"}):c;Object.defineProperty(c,"_$host",{get(){return s.parentNode},configurable:!0}),Gt(d,a),l.appendChild(c),e.ref&&e.ref(c),Ve(()=>l.removeChild(c))}},void 0,{render:!i}),s}function Ri(e,t){const s=$(e);return $(()=>{const n=s();switch(typeof n){case"function":return Y(()=>n(t));case"string":const r=Si.has(n),a=b.context?ji():Ln(n,r);return bn(a,t,r),a}})}function Mi(e){const[,t]=Tn(e,["component"]);return Ri(()=>e.component,t)}var Ui=class{constructor(){this.keyToValue=new Map,this.valueToKey=new Map}set(e,t){this.keyToValue.set(e,t),this.valueToKey.set(t,e)}getByKey(e){return this.keyToValue.get(e)}getByValue(e){return this.valueToKey.get(e)}clear(){this.keyToValue.clear(),this.valueToKey.clear()}},Nn=class{constructor(e){this.generateIdentifier=e,this.kv=new Ui}register(e,t){this.kv.getByValue(e)||(t||(t=this.generateIdentifier(e)),this.kv.set(t,e))}clear(){this.kv.clear()}getIdentifier(e){return this.kv.getByValue(e)}getValue(e){return this.kv.getByKey(e)}},Bi=class extends Nn{constructor(){super(e=>e.name),this.classToAllowedProps=new Map}register(e,t){typeof t=="object"?(t.allowProps&&this.classToAllowedProps.set(e,t.allowProps),super.register(e,t.identifier)):super.register(e,t)}getAllowedProps(e){return this.classToAllowedProps.get(e)}};function Fi(e){if("values"in Object)return Object.values(e);const t=[];for(const s in e)e.hasOwnProperty(s)&&t.push(e[s]);return t}function qi(e,t){const s=Fi(e);if("find"in s)return s.find(t);const n=s;for(let r=0;r<n.length;r++){const a=n[r];if(t(a))return a}}function He(e,t){Object.entries(e).forEach(([s,n])=>t(n,s))}function vt(e,t){return e.indexOf(t)!==-1}function js(e,t){for(let s=0;s<e.length;s++){const n=e[s];if(t(n))return n}}var Ki=class{constructor(){this.transfomers={}}register(e){this.transfomers[e.name]=e}findApplicable(e){return qi(this.transfomers,t=>t.isApplicable(e))}findByName(e){return this.transfomers[e]}},Vi=e=>Object.prototype.toString.call(e).slice(8,-1),jn=e=>typeof e>"u",Hi=e=>e===null,tt=e=>typeof e!="object"||e===null||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:Object.getPrototypeOf(e)===Object.prototype,es=e=>tt(e)&&Object.keys(e).length===0,ye=e=>Array.isArray(e),Qi=e=>typeof e=="string",zi=e=>typeof e=="number"&&!isNaN(e),$i=e=>typeof e=="boolean",Wi=e=>e instanceof RegExp,st=e=>e instanceof Map,nt=e=>e instanceof Set,Dn=e=>Vi(e)==="Symbol",Yi=e=>e instanceof Date&&!isNaN(e.valueOf()),Ji=e=>e instanceof Error,Ds=e=>typeof e=="number"&&isNaN(e),Zi=e=>$i(e)||Hi(e)||jn(e)||zi(e)||Qi(e)||Dn(e),Xi=e=>typeof e=="bigint",eo=e=>e===1/0||e===-1/0,to=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),so=e=>e instanceof URL,Gn=e=>e.replace(/\./g,"\\."),$t=e=>e.map(String).map(Gn).join("."),Ze=e=>{const t=[];let s="";for(let r=0;r<e.length;r++){let a=e.charAt(r);if(a==="\\"&&e.charAt(r+1)==="."){s+=".",r++;continue}if(a==="."){t.push(s),s="";continue}s+=a}const n=s;return t.push(n),t};function ie(e,t,s,n){return{isApplicable:e,annotation:t,transform:s,untransform:n}}var kn=[ie(jn,"undefined",()=>null,()=>{}),ie(Xi,"bigint",e=>e.toString(),e=>typeof BigInt<"u"?BigInt(e):e),ie(Yi,"Date",e=>e.toISOString(),e=>new Date(e)),ie(Ji,"Error",(e,t)=>{const s={name:e.name,message:e.message};return t.allowedErrorProps.forEach(n=>{s[n]=e[n]}),s},(e,t)=>{const s=new Error(e.message);return s.name=e.name,s.stack=e.stack,t.allowedErrorProps.forEach(n=>{s[n]=e[n]}),s}),ie(Wi,"regexp",e=>""+e,e=>{const t=e.slice(1,e.lastIndexOf("/")),s=e.slice(e.lastIndexOf("/")+1);return new RegExp(t,s)}),ie(nt,"set",e=>[...e.values()],e=>new Set(e)),ie(st,"map",e=>[...e.entries()],e=>new Map(e)),ie(e=>Ds(e)||eo(e),"number",e=>Ds(e)?"NaN":e>0?"Infinity":"-Infinity",Number),ie(e=>e===0&&1/e===-1/0,"number",()=>"-0",Number),ie(so,"URL",e=>e.toString(),e=>new URL(e))];function qt(e,t,s,n){return{isApplicable:e,annotation:t,transform:s,untransform:n}}var On=qt((e,t)=>Dn(e)?!!t.symbolRegistry.getIdentifier(e):!1,(e,t)=>["symbol",t.symbolRegistry.getIdentifier(e)],e=>e.description,(e,t,s)=>{const n=s.symbolRegistry.getValue(t[1]);if(!n)throw new Error("Trying to deserialize unknown symbol");return n}),no=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce((e,t)=>(e[t.name]=t,e),{}),Rn=qt(to,e=>["typed-array",e.constructor.name],e=>[...e],(e,t)=>{const s=no[t[1]];if(!s)throw new Error("Trying to deserialize unknown typed array");return new s(e)});function Mn(e,t){return e!=null&&e.constructor?!!t.classRegistry.getIdentifier(e.constructor):!1}var Un=qt(Mn,(e,t)=>["class",t.classRegistry.getIdentifier(e.constructor)],(e,t)=>{const s=t.classRegistry.getAllowedProps(e.constructor);if(!s)return{...e};const n={};return s.forEach(r=>{n[r]=e[r]}),n},(e,t,s)=>{const n=s.classRegistry.getValue(t[1]);if(!n)throw new Error(`Trying to deserialize unknown class '${t[1]}' - check https://github.com/blitz-js/superjson/issues/116#issuecomment-773996564`);return Object.assign(Object.create(n.prototype),e)}),Bn=qt((e,t)=>!!t.customTransformerRegistry.findApplicable(e),(e,t)=>["custom",t.customTransformerRegistry.findApplicable(e).name],(e,t)=>t.customTransformerRegistry.findApplicable(e).serialize(e),(e,t,s)=>{const n=s.customTransformerRegistry.findByName(t[1]);if(!n)throw new Error("Trying to deserialize unknown custom value");return n.deserialize(e)}),ro=[Un,On,Bn,Rn],Gs=(e,t)=>{const s=js(ro,r=>r.isApplicable(e,t));if(s)return{value:s.transform(e,t),type:s.annotation(e,t)};const n=js(kn,r=>r.isApplicable(e,t));if(n)return{value:n.transform(e,t),type:n.annotation}},Fn={};kn.forEach(e=>{Fn[e.annotation]=e});var ao=(e,t,s)=>{if(ye(t))switch(t[0]){case"symbol":return On.untransform(e,t,s);case"class":return Un.untransform(e,t,s);case"custom":return Bn.untransform(e,t,s);case"typed-array":return Rn.untransform(e,t,s);default:throw new Error("Unknown transformation: "+t)}else{const n=Fn[t];if(!n)throw new Error("Unknown transformation: "+t);return n.untransform(e,s)}},Ie=(e,t)=>{if(t>e.size)throw new Error("index out of bounds");const s=e.keys();for(;t>0;)s.next(),t--;return s.next().value};function qn(e){if(vt(e,"__proto__"))throw new Error("__proto__ is not allowed as a property");if(vt(e,"prototype"))throw new Error("prototype is not allowed as a property");if(vt(e,"constructor"))throw new Error("constructor is not allowed as a property")}var io=(e,t)=>{qn(t);for(let s=0;s<t.length;s++){const n=t[s];if(nt(e))e=Ie(e,+n);else if(st(e)){const r=+n,a=+t[++s]==0?"key":"value",i=Ie(e,r);switch(a){case"key":e=i;break;case"value":e=e.get(i);break}}else e=e[n]}return e},ts=(e,t,s)=>{if(qn(t),t.length===0)return s(e);let n=e;for(let a=0;a<t.length-1;a++){const i=t[a];if(ye(n)){const l=+i;n=n[l]}else if(tt(n))n=n[i];else if(nt(n)){const l=+i;n=Ie(n,l)}else if(st(n)){if(a===t.length-2)break;const c=+i,d=+t[++a]==0?"key":"value",u=Ie(n,c);switch(d){case"key":n=u;break;case"value":n=n.get(u);break}}}const r=t[t.length-1];if(ye(n)?n[+r]=s(n[+r]):tt(n)&&(n[r]=s(n[r])),nt(n)){const a=Ie(n,+r),i=s(a);a!==i&&(n.delete(a),n.add(i))}if(st(n)){const a=+t[t.length-2],i=Ie(n,a);switch(+r==0?"key":"value"){case"key":{const c=s(i);n.set(c,n.get(i)),c!==i&&n.delete(i);break}case"value":{n.set(i,s(n.get(i)));break}}}return e};function ss(e,t,s=[]){if(!e)return;if(!ye(e)){He(e,(a,i)=>ss(a,t,[...s,...Ze(i)]));return}const[n,r]=e;r&&He(r,(a,i)=>{ss(a,t,[...s,...Ze(i)])}),t(n,s)}function oo(e,t,s){return ss(t,(n,r)=>{e=ts(e,r,a=>ao(a,n,s))}),e}function lo(e,t){function s(n,r){const a=io(e,Ze(r));n.map(Ze).forEach(i=>{e=ts(e,i,()=>a)})}if(ye(t)){const[n,r]=t;n.forEach(a=>{e=ts(e,Ze(a),()=>e)}),r&&He(r,s)}else He(t,s);return e}var co=(e,t)=>tt(e)||ye(e)||st(e)||nt(e)||Mn(e,t);function uo(e,t,s){const n=s.get(e);n?n.push(t):s.set(e,[t])}function fo(e,t){const s={};let n;return e.forEach(r=>{if(r.length<=1)return;t||(r=r.map(l=>l.map(String)).sort((l,c)=>l.length-c.length));const[a,...i]=r;a.length===0?n=i.map($t):s[$t(a)]=i.map($t)}),n?es(s)?[n]:[n,s]:es(s)?void 0:s}var Kn=(e,t,s,n,r=[],a=[],i=new Map)=>{const l=Zi(e);if(!l){uo(e,r,t);const m=i.get(e);if(m)return n?{transformedValue:null}:m}if(!co(e,s)){const m=Gs(e,s),A=m?{transformedValue:m.value,annotations:[m.type]}:{transformedValue:e};return l||i.set(e,A),A}if(vt(a,e))return{transformedValue:null};const c=Gs(e,s),d=(c==null?void 0:c.value)??e,u=ye(d)?[]:{},f={};He(d,(m,A)=>{if(A==="__proto__"||A==="constructor"||A==="prototype")throw new Error(`Detected property ${A}. This is a prototype pollution risk, please remove it from your object.`);const w=Kn(m,t,s,n,[...r,A],[...a,e],i);u[A]=w.transformedValue,ye(w.annotations)?f[A]=w.annotations:tt(w.annotations)&&He(w.annotations,(v,M)=>{f[Gn(A)+"."+M]=v})});const E=es(f)?{transformedValue:u,annotations:c?[c.type]:void 0}:{transformedValue:u,annotations:c?[c.type,f]:f};return l||i.set(e,E),E};function Vn(e){return Object.prototype.toString.call(e).slice(8,-1)}function ks(e){return Vn(e)==="Array"}function ho(e){if(Vn(e)!=="Object")return!1;const t=Object.getPrototypeOf(e);return!!t&&t.constructor===Object&&t===Object.prototype}function go(e,t,s,n,r){const a={}.propertyIsEnumerable.call(n,t)?"enumerable":"nonenumerable";a==="enumerable"&&(e[t]=s),r&&a==="nonenumerable"&&Object.defineProperty(e,t,{value:s,enumerable:!1,writable:!0,configurable:!0})}function ns(e,t={}){if(ks(e))return e.map(r=>ns(r,t));if(!ho(e))return e;const s=Object.getOwnPropertyNames(e),n=Object.getOwnPropertySymbols(e);return[...s,...n].reduce((r,a)=>{if(ks(t.props)&&!t.props.includes(a))return r;const i=e[a],l=ns(i,t);return go(r,a,l,e,t.nonenumerable),r},{})}var B=class{constructor({dedupe:e=!1}={}){this.classRegistry=new Bi,this.symbolRegistry=new Nn(t=>t.description??""),this.customTransformerRegistry=new Ki,this.allowedErrorProps=[],this.dedupe=e}serialize(e){const t=new Map,s=Kn(e,t,this,this.dedupe),n={json:s.transformedValue};s.annotations&&(n.meta={...n.meta,values:s.annotations});const r=fo(t,this.dedupe);return r&&(n.meta={...n.meta,referentialEqualities:r}),n}deserialize(e){const{json:t,meta:s}=e;let n=ns(t);return s!=null&&s.values&&(n=oo(n,s.values,this)),s!=null&&s.referentialEqualities&&(n=lo(n,s.referentialEqualities)),n}stringify(e){return JSON.stringify(this.serialize(e))}parse(e){return this.deserialize(JSON.parse(e))}registerClass(e,t){this.classRegistry.register(e,t)}registerSymbol(e,t){this.symbolRegistry.register(e,t)}registerCustom(e,t){this.customTransformerRegistry.register({name:t,...e})}allowErrorProps(...e){this.allowedErrorProps.push(...e)}};B.defaultInstance=new B;B.serialize=B.defaultInstance.serialize.bind(B.defaultInstance);B.deserialize=B.defaultInstance.deserialize.bind(B.defaultInstance);B.stringify=B.defaultInstance.stringify.bind(B.defaultInstance);B.parse=B.defaultInstance.parse.bind(B.defaultInstance);B.registerClass=B.defaultInstance.registerClass.bind(B.defaultInstance);B.registerSymbol=B.defaultInstance.registerSymbol.bind(B.defaultInstance);B.registerCustom=B.defaultInstance.registerCustom.bind(B.defaultInstance);B.allowErrorProps=B.defaultInstance.allowErrorProps.bind(B.defaultInstance);var Hn=B.serialize,mo=B.stringify;function Eo(e){return e.state.fetchStatus==="fetching"?"fetching":e.getObserversCount()?e.state.fetchStatus==="paused"?"paused":e.isStale()?"stale":"fresh":"inactive"}function po(e,t){return`${e}${t.charAt(0).toUpperCase()+t.slice(1)}`}function yo({queryState:e,observerCount:t,isStale:s}){return e.fetchStatus==="fetching"?"blue":t?e.fetchStatus==="paused"?"purple":s?"yellow":"green":"gray"}function Ao({status:e,isPaused:t}){return t?"purple":e==="error"?"red":e==="pending"?"yellow":e==="success"?"green":"gray"}function To(e){return e==="fresh"?"green":e==="stale"?"yellow":e==="paused"?"purple":e==="inactive"?"gray":"blue"}var So=(e,t=!1)=>{const{json:s}=Hn(e);return JSON.stringify(s,null,t?2:void 0)},St=e=>e.state.fetchStatus!=="idle"?0:e.getObserversCount()?e.isStale()?2:1:3,Po=(e,t)=>e.queryHash.localeCompare(t.queryHash),Qn=(e,t)=>e.state.dataUpdatedAt<t.state.dataUpdatedAt?1:-1,_o=(e,t)=>St(e)===St(t)?Qn(e,t):St(e)>St(t)?1:-1,xo={status:_o,"query hash":Po,"last updated":Qn},Pt=e=>e.state.isPaused?0:e.state.status==="error"?2:e.state.status==="pending"?1:3,zn=(e,t)=>e.state.submittedAt<t.state.submittedAt?1:-1,wo=(e,t)=>Pt(e)===Pt(t)?zn(e,t):Pt(e)>Pt(t)?1:-1,vo={status:wo,"last updated":zn},bo=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),Io=()=>{const[e,t]=V("dark");return hn(()=>{const s=window.matchMedia("(prefers-color-scheme: dark)");t(s.matches?"dark":"light");const n=r=>{t(r.matches?"dark":"light")};s.addEventListener("change",n),Ve(()=>s.removeEventListener("change",n))}),e},We=(e,t,s)=>{if(t.length===0)return s;if(e instanceof Map){const n=new Map(e);if(t.length===1)return n.set(t[0],s),n;const[r,...a]=t;return n.set(r,We(n.get(r),a,s)),n}if(e instanceof Set){const n=We(Array.from(e),t,s);return new Set(n)}if(Array.isArray(e)){const n=[...e];if(t.length===1)return n[t[0]]=s,n;const[r,...a]=t;return n[r]=We(n[r],a,s),n}if(e instanceof Object){const n={...e};if(t.length===1)return n[t[0]]=s,n;const[r,...a]=t;return n[r]=We(n[r],a,s),n}return e},Ye=(e,t)=>{if(e instanceof Map){const s=new Map(e);if(t.length===1)return s.delete(t[0]),s;const[n,...r]=t;return s.set(n,Ye(s.get(n),r)),s}if(e instanceof Set){const s=Ye(Array.from(e),t);return new Set(s)}if(Array.isArray(e)){const s=[...e];if(t.length===1)return s.filter((a,i)=>i.toString()!==t[0]);const[n,...r]=t;return s[n]=Ye(s[n],r),s}if(e instanceof Object){const s={...e};if(t.length===1)return delete s[t[0]],s;const[n,...r]=t;return s[n]=Ye(s[n],r),s}return e},$n=(e,t)=>{if(!e||document.querySelector("#_goober")||(t==null?void 0:t.querySelector("#_goober")))return;const n=document.createElement("style"),r=document.createTextNode("");n.appendChild(r),n.id="_goober",n.setAttribute("nonce",e),t?t.appendChild(n):document.head.appendChild(n)},Ce,rt,at,it,Pe,ot,Le,Ne,je,De,Ge,lt,ke,ct,Ms,Co=(Ms=class{constructor(e){R(this,Ce);R(this,rt);R(this,at);R(this,it);R(this,Pe,!1);R(this,ot);R(this,Le);R(this,Ne);R(this,je);R(this,De);R(this,Ge);R(this,lt);R(this,ke);R(this,ct);const{client:t,queryFlavor:s,version:n,onlineManager:r,buttonPosition:a,position:i,initialIsOpen:l,errorTypes:c,styleNonce:d,shadowDOMTarget:u,hideDisabledQueries:f}=e;O(this,Ce,V(t)),O(this,at,s),O(this,it,n),O(this,rt,r),O(this,ot,d),O(this,Le,u),O(this,Ne,V(a)),O(this,je,V(i)),O(this,De,V(l)),O(this,Ge,V(c)),O(this,lt,V(f))}setButtonPosition(e){_(this,Ne)[1](e)}setPosition(e){_(this,je)[1](e)}setInitialIsOpen(e){_(this,De)[1](e)}setErrorTypes(e){_(this,Ge)[1](e)}setClient(e){_(this,Ce)[1](e)}mount(e){if(_(this,Pe))throw new Error("Devtools is already mounted");const t=_n(()=>{const s=this,[n]=_(this,Ne),[r]=_(this,je),[a]=_(this,De),[i]=_(this,Ge),[l]=_(this,lt),[c]=_(this,Ce);let d;return _(this,ke)?d=_(this,ke):(d=Sn(()=>Promise.resolve().then(()=>require("./NCMVHL6D-CmKLw38-.cjs"))),O(this,ke,d)),$n(_(this,ot),_(this,Le)),ps(d,ys({get queryFlavor(){return _(s,at)},get version(){return _(s,it)},get onlineManager(){return _(s,rt)},get shadowDOMTarget(){return _(s,Le)}},{get client(){return c()},get buttonPosition(){return n()},get position(){return r()},get initialIsOpen(){return a()},get errorTypes(){return i()},get hideDisabledQueries(){return l()}}))},e);O(this,Pe,!0),O(this,ct,t)}unmount(){var e;if(!_(this,Pe))throw new Error("Devtools is not mounted");(e=_(this,ct))==null||e.call(this),O(this,Pe,!1)}},Ce=new WeakMap,rt=new WeakMap,at=new WeakMap,it=new WeakMap,Pe=new WeakMap,ot=new WeakMap,Le=new WeakMap,Ne=new WeakMap,je=new WeakMap,De=new WeakMap,Ge=new WeakMap,lt=new WeakMap,ke=new WeakMap,ct=new WeakMap,Ms),Oe,ut,dt,ft,_e,ht,Re,Me,Ue,Be,Fe,gt,qe,Ke,mt,Us,Lo=(Us=class{constructor(e){R(this,Oe);R(this,ut);R(this,dt);R(this,ft);R(this,_e,!1);R(this,ht);R(this,Re);R(this,Me);R(this,Ue);R(this,Be);R(this,Fe);R(this,gt);R(this,qe);R(this,Ke);R(this,mt);const{client:t,queryFlavor:s,version:n,onlineManager:r,buttonPosition:a,position:i,initialIsOpen:l,errorTypes:c,styleNonce:d,shadowDOMTarget:u,onClose:f,hideDisabledQueries:E}=e;O(this,Oe,V(t)),O(this,dt,s),O(this,ft,n),O(this,ut,r),O(this,ht,d),O(this,Re,u),O(this,Me,V(a)),O(this,Ue,V(i)),O(this,Be,V(l)),O(this,Fe,V(c)),O(this,gt,V(E)),O(this,qe,V(f))}setButtonPosition(e){_(this,Me)[1](e)}setPosition(e){_(this,Ue)[1](e)}setInitialIsOpen(e){_(this,Be)[1](e)}setErrorTypes(e){_(this,Fe)[1](e)}setClient(e){_(this,Oe)[1](e)}setOnClose(e){_(this,qe)[1](()=>e)}mount(e){if(_(this,_e))throw new Error("Devtools is already mounted");const t=_n(()=>{const s=this,[n]=_(this,Me),[r]=_(this,Ue),[a]=_(this,Be),[i]=_(this,Fe),[l]=_(this,gt),[c]=_(this,Oe),[d]=_(this,qe);let u;return _(this,Ke)?u=_(this,Ke):(u=Sn(()=>Promise.resolve().then(()=>require("./2AITGKQY-Be359164.cjs"))),O(this,Ke,u)),$n(_(this,ht),_(this,Re)),ps(u,ys({get queryFlavor(){return _(s,dt)},get version(){return _(s,ft)},get onlineManager(){return _(s,ut)},get shadowDOMTarget(){return _(s,Re)}},{get client(){return c()},get buttonPosition(){return n()},get position(){return r()},get initialIsOpen(){return a()},get errorTypes(){return i()},get hideDisabledQueries(){return l()},get onClose(){return d()}}))},e);O(this,_e,!0),O(this,mt,t)}unmount(){var e;if(!_(this,_e))throw new Error("Devtools is not mounted");(e=_(this,mt))==null||e.call(this),O(this,_e,!1)}},Oe=new WeakMap,ut=new WeakMap,dt=new WeakMap,ft=new WeakMap,_e=new WeakMap,ht=new WeakMap,Re=new WeakMap,Me=new WeakMap,Ue=new WeakMap,Be=new WeakMap,Fe=new WeakMap,gt=new WeakMap,qe=new WeakMap,Ke=new WeakMap,mt=new WeakMap,Us);function No(e){const t=S.useQueryClient(e.client),s=z.useRef(null),{buttonPosition:n,position:r,initialIsOpen:a,errorTypes:i,styleNonce:l,shadowDOMTarget:c,hideDisabledQueries:d}=e,[u]=z.useState(new Co({client:t,queryFlavor:"React Query",version:"5",onlineManager:S.onlineManager,buttonPosition:n,position:r,initialIsOpen:a,errorTypes:i,styleNonce:l,shadowDOMTarget:c,hideDisabledQueries:d}));return z.useEffect(()=>{u.setClient(t)},[t,u]),z.useEffect(()=>{n&&u.setButtonPosition(n)},[n,u]),z.useEffect(()=>{r&&u.setPosition(r)},[r,u]),z.useEffect(()=>{u.setInitialIsOpen(a||!1)},[a,u]),z.useEffect(()=>{u.setErrorTypes(i||[])},[i,u]),z.useEffect(()=>(s.current&&u.mount(s.current),()=>{u.unmount()}),[u]),o.jsx("div",{dir:"ltr",className:"tsqd-parent-container",ref:s})}function jo(e){const t=S.useQueryClient(e.client),s=z.useRef(null),{errorTypes:n,styleNonce:r,shadowDOMTarget:a,hideDisabledQueries:i}=e,[l]=z.useState(new Lo({client:t,queryFlavor:"React Query",version:"5",onlineManager:S.onlineManager,buttonPosition:"bottom-left",position:"bottom",initialIsOpen:!0,errorTypes:n,styleNonce:r,shadowDOMTarget:a,onClose:e.onClose,hideDisabledQueries:i}));return z.useEffect(()=>{l.setClient(t)},[t,l]),z.useEffect(()=>{l.setOnClose(e.onClose??(()=>{}))},[e.onClose,l]),z.useEffect(()=>{l.setErrorTypes(n||[])},[n,l]),z.useEffect(()=>(s.current&&l.mount(s.current),()=>{l.unmount()}),[l]),o.jsx("div",{style:{height:"500px",...e.style},className:"tsqd-parent-container",ref:s})}var Os=process.env.NODE_ENV!=="development"?function(){return null}:No;process.env.NODE_ENV;const Wn=H.atom(""),Do=()=>{P.registerChaiFeatureFlag("dynamic-page-selector",{description:"Dynamic page selector"}),P.registerChaiFeatureFlag("enable-add-page-dropdown",{description:"Enable add page dropdown"}),P.registerChaiFeatureFlag("enable-ai-chat-panel",{description:"Enable AI chat panel"})},Go=()=>{const e=j(),t=N();return S.useQuery({queryKey:[y.GET_COLLECTIONS],staleTime:1/0,queryFn:async()=>t(e,{action:y.GET_COLLECTIONS})})},ko=()=>{const{data:e}=te(),{data:t}=he(),{data:s}=Te(),n=j(),r=N(),a=h.useMemo(()=>(s==null?void 0:s.fallbackLang)||"en",[s==null?void 0:s.fallbackLang]),i=h.useRef(new Map);return S.useMutation({mutationFn:async({block:l})=>{const c=l._id,d=(t==null?void 0:t.lang)||a,u=`${c}:${d}`;if(i.current.has(u))return i.current.get(u);const f=r(n,{action:y.GET_BLOCK_ASYNC_PROPS,data:{block:l,lang:d,pageProps:{slug:t==null?void 0:t.slug,searchParams:{},pageType:t==null?void 0:t.pageType,fallbackLang:a,lastSaved:t.lastSaved,pageId:e.id,primaryPageId:t.primaryPage||e.id,pageBaseSlug:t==null?void 0:t.slug,dynamic:e==null?void 0:e.dynamic,languagePageId:t.id}}});return i.current.set(u,f),f.finally(()=>{i.current.delete(u)}),f}})},Yn=()=>{const[,e]=le();return h.useCallback((t,s)=>{const r=new URLSearchParams(window.location.search).get("lang"),a=new URLSearchParams({page:t});r&&a.set("lang",r),window.history.pushState({},"",`?${a.toString()}`),e(a),window.dispatchEvent(new PopStateEvent("popstate")),s==null||s()},[e])},Jn=()=>{const e=Yn();return h.useCallback(({pageId:t})=>{e(t)},[e])},Oo={SITE_WIDE_USAGE:"SITE_WIDE_USAGE"},Ro=e=>{const t=N(),s=j();return S.useQuery({queryKey:[Oo.SITE_WIDE_USAGE],queryFn:async()=>e?t(s,{action:"GET_SITE_WIDE_USAGE"}):{},retry:!1})},Mo=h.lazy(()=>Promise.resolve().then(()=>require("./page-lock-DUwWdppB.cjs"))),Uo=h.lazy(()=>Promise.resolve().then(()=>require("./no-language-page-dialog-CTRG81hU.cjs"))),Bo=h.lazy(()=>Promise.resolve().then(()=>require("./digital-asset-manager-BUEa7fSG.cjs"))),Fo=h.lazy(()=>Promise.resolve().then(()=>require("./save-to-lib-ByoB0FW5.cjs"))),qo=h.lazy(()=>Promise.resolve().then(()=>require("./theme-panel-footer-tdNtbqZs.cjs"))),Ko=h.lazy(()=>Promise.resolve().then(()=>require("./web-preview-cls5-Dlv.cjs")));Do();ar.loadWebBlocks();P.registerChaiTopBar(ma);Fa();P.registerChaiMediaManager(Bo);P.registerChaiSaveToLibrary(Fo);const Vo={role:"",permissions:null},Rs=e=>{var Ss;const{data:t}=va(),s=Mt(),{data:n=Vo,isFetching:r}=sn(),{data:a,isFetching:i}=ge(),{data:l,isFetching:c}=Go(),{data:d,isFetching:u}=Te(),f=r||i||c||u,[E]=le(),m=E.get("page"),{data:A}=te(),{data:w,isFetching:v}=Aa(),{blocks:M}=ya(w),{data:T,isFetching:C}=en(),{pageStatus:L}=re(),q=Ea(),{onSave:D}=ba(),{mutateAsync:ce}=ko(),{getPartialBlocks:ue,getPartialBlockBlocks:K}=Ia(),{mutateAsync:I}=Mr(),{mutateAsync:G}=tn(),{data:W}=Ro(((Ss=e.flags)==null?void 0:Ss.designTokens)??!1),Q=Jn(),[ae,yt]=h.useState(!1),de=h.useRef([]),ve=h.useMemo(()=>p.get(d,"theme",{})||{},[d]),Se=L===J.EDITING,er=L===J.CHECKING,As=v||er||C;de.current=M;const[tr]=H.useAtom(Wn);h.useEffect(()=>{const ee=()=>{document.hidden?yt(!0):yt(!1)};return window.addEventListener("visibilitychange",ee),()=>window.removeEventListener("visibilitychange",ee)},[]);const sr=h.useMemo(()=>{const ee={};return n&&(ee.permissions=p.get(n,"permissions",null),ee.role=p.get(n,"role","user")),ee},[n]),Ts=h.useMemo(()=>t==null?void 0:t.some(ee=>ee.isSiteLibrary),[t]),nr=h.useCallback(async(ee,At)=>await I({pageType:ee,query:At}),[I]);return o.jsxs(o.Fragment,{children:[As&&o.jsx(hs,{className:f?"fixed inset-0 bg-white":"bg-white/75",children:o.jsx(x.Loader,{className:`animate-spin text-primary ${f?"h-6 w-6":"h-5 w-5"}`})}),tr&&o.jsx(h.Suspense,{fallback:o.jsx("div",{className:"absolute inset-0 z-[999999] flex min-h-screen w-screen items-center justify-center bg-gray-100",children:o.jsx(x.Loader,{className:"h-6 w-6 animate-spin text-primary"})}),children:o.jsx(Ko,{})}),o.jsx(P.ChaiBuilderEditor,{siteWideUsage:W??{},flags:e.flags?{...e.flags,librarySite:Ts}:{librarySite:Ts},gotoPage:Q,collections:l??[],getBlockAsyncProps:ce,pageExternalData:T,themePresets:e.themePresets??[],pageId:A==null?void 0:A.id,loading:v,fallbackLang:s,languages:(d==null?void 0:d.languages)||[],brandingOptions:(d==null?void 0:d.theme)||{},designTokens:(d==null?void 0:d.designTokens)||{},translations:e.translations||{},locale:e.locale||"en",htmlDir:e.htmlDir||"ltr",autoSave:!ae&&Se&&(e.autoSave??!0),autoSaveActionsCount:e.autoSaveActionsCount??10,onError:e.onError||console.error,getPartialBlockBlocks:K,getPartialBlocks:ue,blocks:v?[]:M,theme:p.cloneDeep(ve),pageTypes:a,searchPageTypeItems:nr,askAiCallBack:q,onSave:async({blocks:ee,theme:At,needTranslations:rr,designTokens:Ps})=>{if(!m)return!0;de.current=ee;const _s=[...ee];await D({page:m,blocks:_s,needTranslations:rr}),de.current=_s;const Kt={};return p.isEqual(At,ve)||(Kt.theme=At),p.isEqual(Ps,d==null?void 0:d.designTokens)||(Kt.designTokens=Ps),await G({settings:Kt}),!0},themePanelComponent:qo,...sr,children:o.jsx(Mo,{isFetchingPageData:As})}),o.jsx("div",{children:o.jsx(Uo,{})})]})},Ho=new S.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1}}}),Qo=e=>{const[,t]=kt(),[s,n]=h.useState(!1);return h.useEffect(()=>(t(p.pick(e,["apiUrl","usersApiUrl","assetsApiUrl","getPreviewUrl","getLiveUrl","topLeftCorner","onLogout","getAccessToken","websocket","getLoggedInUser","features","currentUser"])),setTimeout(()=>{n(!0)},200),()=>{n(!1),t({})}),[e,t]),s?p.get(e,"hasReactQueryProvider",!1)===!0?o.jsxs(o.Fragment,{children:[o.jsx(Rs,{...e}),o.jsx(Os,{})]}):o.jsxs(S.QueryClientProvider,{client:Ho,children:[o.jsx(Rs,{...e}),o.jsx(Os,{})]}):o.jsx("div",{})},zo=z.lazy(()=>Promise.resolve().then(()=>require("./nested-path-selector-content-D_iF9Sm3.cjs")));function Zn({data:e,onSelect:t,dataType:s="value",disabled:n=!1}){const[r,a]=z.useState(!1);return o.jsxs(g.Popover,{open:r,onOpenChange:a,children:[o.jsxs(g.Tooltip,{children:[o.jsx(g.TooltipTrigger,{asChild:!0,children:o.jsx(g.PopoverTrigger,{asChild:!0,children:o.jsx(g.Button,{size:"sm",variant:"outline",className:"h-6 w-6 px-1 py-0 text-[9px] text-muted-foreground",role:"combobox","aria-expanded":r,disabled:n,children:o.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24px",height:"24px",viewBox:"0 0 24 24",fill:"none",children:o.jsx("path",{d:"M9.5 5H9C7.89543 5 7 5.89543 7 7V9C7 10 6.4 12 4 12C5 12 7 12.6 7 15V17.0002C7 18.1048 7.89543 19 9 19H9.5M14.5 5H15C16.1046 5 17 5.89543 17 7V9C17 10 17.6 12 20 12C19 12 17 12.6 17 15V17.0002C17 18.1048 16.1046 19 15 19H14.5",stroke:"#000000",strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:"2"})})})})}),o.jsx(g.TooltipContent,{children:"Add field"})]}),r&&o.jsx(z.Suspense,{children:o.jsx(zo,{data:e,onSelect:t,dataType:s,open:r,setOpen:a})})]})}const $o=()=>{const{savePageAsync:e}=P.useSavePage(),t=S.useQueryClient(),{isLocked:s}=re();return h.useCallback(async()=>{s||await e(),t.invalidateQueries({queryKey:[y.GET_DRAFT_PAGE]}),t.invalidateQueries({queryKey:[y.GET_BUILDER_PAGE_DATA]})},[e,t,s])},Wo=()=>{const e=S.useQueryClient();return h.useCallback(()=>{e.clear()},[e])},Yo=()=>{const e=j(),t=N(),{data:s}=he(),n=S.useQueryClient();return S.useMutation({mutationFn:async r=>{if(!(s!=null&&s.id))throw new Error("No active page found");return await t(`${e}`,{action:y.UPDATE_PAGE_METADATA,data:{id:s.id,metadata:r}})},onSuccess:()=>{n.invalidateQueries({queryKey:[y.GET_BUILDER_PAGE_DATA]}),n.invalidateQueries({queryKey:[y.GET_LANGUAGE_PAGES]})},onError:()=>{console.error("Failed to update metadata")}})},Jo=h.lazy(()=>Promise.resolve().then(()=>require("./digital-asset-manager-BUEa7fSG.cjs"))),Zo=({assetId:e,assetUrl:t,onChange:s,className:n="",placeholder:r="Select an image",disabled:a=!1})=>{const{t:i}=P.useTranslation(),[l,c]=h.useState(!1),d=()=>{a||c(!0)},u=()=>{c(!1)},f=A=>{const w=Array.isArray(A)?A[0]:A;w!=null&&w.url&&s(p.pick(w,["url","id"])),c(!1)},E=()=>{s({url:"",id:""})},m=(t==null?void 0:t.startsWith("{{"))&&(t==null?void 0:t.endsWith("}}"));return o.jsxs("div",{className:`w-full ${n}`,children:[t?o.jsxs("div",{className:"relative overflow-hidden rounded-md border",children:[m?o.jsx("div",{className:"flex h-12 items-center bg-gray-100 px-4",children:o.jsx("p",{className:"text-xs text-gray-500",children:t})}):o.jsx("img",{onClick:d,src:t,alt:i("Selected image"),className:"h-auto max-h-[100px] w-full bg-gray-100 object-contain"}),o.jsxs("div",{className:"absolute right-2 top-2 flex gap-2",children:[o.jsx(g.Button,{type:"button",variant:"outline",size:"icon",className:"h-8 w-8 rounded-full bg-white text-red-500",onClick:E,disabled:a,children:m?o.jsx(x.X,{className:"h-4 w-4"}):o.jsx(x.Trash2,{className:"h-4 w-4"})}),!m&&o.jsx(g.Button,{type:"button",variant:"outline",size:"icon",className:"h-8 w-8 rounded-full bg-white/80 hover:bg-white/90",onClick:d,disabled:a,children:o.jsx(x.ImageIcon,{className:"h-4 w-4"})})]})]}):o.jsx("div",{className:`flex cursor-pointer items-center justify-center rounded-md border border-dashed p-6 ${a?"cursor-not-allowed opacity-50":"hover:border-gray-400"}`,onClick:d,children:o.jsxs("div",{className:"flex flex-col items-center gap-2",children:[o.jsx(x.ImageIcon,{className:"h-10 w-10 text-gray-400"}),o.jsx("p",{className:"text-sm text-gray-500",children:r})]})}),o.jsx(g.Dialog,{open:l,onOpenChange:c,children:o.jsxs(g.DialogContent,{className:"h-fit w-full max-w-7xl overflow-hidden p-0",children:[o.jsxs(g.DialogHeader,{className:"hidden border-b px-4 py-2",children:[o.jsx(g.DialogTitle,{children:i("Select Image")}),o.jsx(g.Button,{type:"button",variant:"ghost",size:"icon",className:"absolute right-4 top-2",onClick:u,children:o.jsx(x.X,{className:"h-4 w-4"})})]}),o.jsx("div",{className:"h-full flex-1 p-4",children:o.jsx(h.Suspense,{children:o.jsx(Jo,{close:u,onSelect:f,mode:"image",assetId:e})})})]})})]})},Xo=h.createContext(null),Wt={didCatch:!1,error:null};class Xn extends h.Component{constructor(t){super(t),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=Wt}static getDerivedStateFromError(t){return{didCatch:!0,error:t}}resetErrorBoundary(){const{error:t}=this.state;if(t!==null){for(var s,n,r=arguments.length,a=new Array(r),i=0;i<r;i++)a[i]=arguments[i];(s=(n=this.props).onReset)===null||s===void 0||s.call(n,{args:a,reason:"imperative-api"}),this.setState(Wt)}}componentDidCatch(t,s){var n,r;(n=(r=this.props).onError)===null||n===void 0||n.call(r,t,s)}componentDidUpdate(t,s){const{didCatch:n}=this.state,{resetKeys:r}=this.props;if(n&&s.error!==null&&el(t.resetKeys,r)){var a,i;(a=(i=this.props).onReset)===null||a===void 0||a.call(i,{next:r,prev:t.resetKeys,reason:"keys"}),this.setState(Wt)}}render(){const{children:t,fallbackRender:s,FallbackComponent:n,fallback:r}=this.props,{didCatch:a,error:i}=this.state;let l=t;if(a){const c={error:i,resetErrorBoundary:this.resetErrorBoundary};if(typeof s=="function")l=s(c);else if(n)l=h.createElement(n,c);else if(r!==void 0)l=r;else throw i}return h.createElement(Xo.Provider,{value:{didCatch:a,error:i,resetErrorBoundary:this.resetErrorBoundary}},l)}}function el(){let e=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],t=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];return e.length!==t.length||e.some((s,n)=>!Object.is(s,t[n]))}const tl=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),rs=e=>{if(!e.trim())return{isValid:!1,parsed:null,placeholders:[],error:{message:"JSON is empty"}};try{return{isValid:!0,parsed:JSON.parse(e),error:null,placeholders:[]}}catch{}const t=/{{([^{}]+)}}/g,s=[];let n=e,r;for(;(r=t.exec(e))!==null;){const a=r[0],i=r.index,l=`"__placeholder_${s.length}__"`;s.push({original:a,replaced:l,position:i}),n=n.replace(a,l)}try{return{isValid:!0,parsed:JSON.parse(n),error:null,placeholders:s}}catch(a){const i=a,l=i.message.match(/position (\d+)/),c=l?parseInt(l[1]):void 0;let d,u;if(c!==void 0){const f=n.substring(0,c).split(`
|
|
2
|
+
`);d=f.length,u=f[f.length-1].length+1}return{isValid:!1,parsed:null,placeholders:s,error:{message:i.message,line:d,column:u,position:c}}}},sl=(e,t)=>{let n=JSON.stringify(e,null,2);return t.forEach(({original:r},a)=>{const i=`"__placeholder_${a}__"`,l=new RegExp(tl(i),"g");n=n.replace(l,r)}),n},nl=(e,t)=>{if(!e)return"";let s=JSON.stringify(e,null,2);const n=/{{([^{}]+)}}/g;let r;for(;(r=n.exec(s))!==null;){const a=r[1],i=p.get(t,a,null);s=s.replace(r[0],i)}return s},rl=h.lazy(()=>Promise.resolve().then(()=>require("./shared-json-ld-DYD7q8ST.cjs"))),al=({value:e,onChange:t,disabled:s=!1,readOnly:n=!1,placeholder:r="Enter JSON",rows:a=6,id:i="json-input",pageData:l={},handleFieldInsert:c,hasJsonLdForSelectedLang:d,copyJsonLDFromDefaultPage:u})=>{const[f,E]=h.useState("edit"),[m,A]=h.useState(null),[w,v]=h.useState(""),M=h.useRef(null),[T]=kt(),C=i==="jsonLD"&&p.get(T,"features.sharedJsonLD",!1),L=i==="jsonLD"&&!d&&!!u;h.useEffect(()=>{e.trim()===""&&t("{}")},[e,t]);const q=K=>{if(n)return;const I=K.target.value;t(I)},D=K=>{if(K.key==="Tab"){K.preventDefault();const I=K.currentTarget,G=I.selectionStart,W=I.selectionEnd;if(G!==W){const ae=e.substring(G,W).split(`
|
|
3
|
+
`);if(K.shiftKey){const de=ae.map(Se=>Se.startsWith(" ")?Se.substring(2):Se).join(`
|
|
4
|
+
`),ve=e.substring(0,G)+de+e.substring(W);t(ve),setTimeout(()=>{I.selectionStart=G,I.selectionEnd=G+de.length},0)}else{const de=ae.map(Se=>` ${Se}`).join(`
|
|
5
|
+
`),ve=e.substring(0,G)+de+e.substring(W);t(ve),setTimeout(()=>{I.selectionStart=G,I.selectionEnd=G+de.length},0)}}else{const Q=e.substring(0,G)+" "+e.substring(W);t(Q),setTimeout(()=>{I.selectionStart=I.selectionEnd=G+2},0)}}};h.useEffect(()=>{const K=rs(e);if(K.isValid)if(A(null),K.parsed){const I=nl(K.parsed,l);v(I)}else v("");else A(K.error),v("")},[e,l]);const ce=()=>{const K=rs(e);if(K.isValid&&K.parsed){const I=sl(K.parsed,K.placeholders);t(I)}},ue=()=>{m!=null&&m.position&&M.current&&(M.current.focus(),M.current.setSelectionRange(m.position,m.position+1))};return o.jsx(Xn,{fallback:o.jsx("div",{children:"Some error"}),children:o.jsx("div",{className:"space-y-2",children:o.jsxs(g.Tabs,{value:f,onValueChange:E,className:"w-full",children:[o.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[o.jsxs(g.TabsList,{className:"w-max",children:[o.jsxs(g.TabsTrigger,{value:"edit",className:"flex items-center gap-1",children:[o.jsx(x.Code,{className:"h-4 w-4"}),o.jsx("span",{children:"Edit"})]}),o.jsxs(g.TabsTrigger,{value:"preview",className:"flex items-center gap-1",disabled:!e.trim()||m!==null||L,children:[o.jsx(x.Eye,{className:"h-4 w-4"}),o.jsx("span",{children:"Preview"})]}),C&&o.jsxs(g.TabsTrigger,{value:"shared",className:"flex items-center gap-1",disabled:!e.trim()||m!==null,children:[o.jsx(x.Share2,{className:"h-4 w-4"}),o.jsx("span",{children:"Shared"})]})]}),L?null:f==="edit"&&!n&&o.jsx("div",{className:"flex items-center gap-2",children:o.jsx(Zn,{dataType:"value",data:l??{},onSelect:K=>c&&c(K,i)})})]}),o.jsxs(g.TabsContent,{value:"edit",className:"relative mt-0",children:[!L&&f==="edit"&&o.jsx(Ut,{content:"Format JSON",side:"right",showTooltip:!s&&!m,children:o.jsx(g.Button,{type:"button",variant:"outline",size:"icon",onClick:ce,className:"absolute right-1 top-1 h-6 w-6 p-1",disabled:!e.trim()||s||m!==null,children:o.jsx(x.FileCode2,{})})}),L?o.jsx("div",{className:"flex h-40 items-center justify-center rounded-md bg-black/20",children:o.jsxs("div",{className:"flex max-w-[400px] flex-col items-center gap-2 rounded-md bg-white p-4 shadow-lg",children:[o.jsx("div",{className:"max-w-xl text-center text-xs text-gray-500",children:"JSON-LD for is not added for selected language. JSON LD will be used from default language."}),o.jsxs(g.Button,{type:"button",variant:"default",size:"sm",onClick:u,children:[o.jsx(x.Plus,{}),"Copy & Edit from default language"]})]})}):o.jsx(g.Textarea,{ref:M,id:i,name:i,className:`rounded-md border border-input text-xs ${m?"border-red-500":""}`,onChange:q,onKeyDown:D,value:e,placeholder:r,rows:a,disabled:s,readOnly:n}),m&&o.jsxs(g.Alert,{variant:"destructive",className:"mt-2",children:[o.jsx(x.AlertTriangle,{className:"h-4 w-4"}),o.jsxs(g.AlertDescription,{className:"flex flex-col",children:[o.jsx("span",{className:"font-medium",children:"Invalid JSON"}),o.jsx("span",{className:"text-sm",children:m.message}),m.line&&m.column&&o.jsxs("span",{className:"text-sm",children:["Error at line ",m.line,", column ",m.column]}),o.jsx(g.Button,{type:"button",variant:"link",size:"sm",className:"mt-1 h-auto self-start p-0 text-sm",onClick:ue,children:"Show position"})]})]})]}),o.jsxs(g.TabsContent,{value:"preview",className:"mt-0",children:[o.jsx(g.Textarea,{rows:a,value:w,readOnly:!0,className:"cursor-default bg-muted font-mono text-sm"}),o.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:"This is how the JSON will look after placeholder substitution."})]}),C&&o.jsx(g.TabsContent,{value:"shared",className:"mt-0",children:o.jsx(h.Suspense,{children:o.jsx(rl,{})})})]})})})},il=e=>{const t=Fs(),s=N();return S.useQuery({queryKey:[y.GET_CHAI_USER,e],queryFn:async()=>{const r=await s(t,{action:y.GET_CHAI_USER,data:{userId:e}});return{...r,name:r.name||r.email}},enabled:!p.isEmpty(e),staleTime:"static"})};if(typeof window>"u")throw new Error("@chaibuilder/pages is not available on the server");exports.$TRACK=gs;exports.ACTIONS=y;exports.BlurContainer=hs;exports.ChaiBuilderPages=Qo;exports.Dynamic=Mi;exports.EVENT=X;exports.ErrorBoundary=Xn;exports.For=ci;exports.ImagePicker=Zo;exports.Index=ui;exports.LANGUAGES=ze;exports.LanguageSwitcher=Ws;exports.Match=hi;exports.NestedPathSelector=Zn;exports.PAGES_PERMISSIONS=se;exports.PAGE_STATUS=J;exports.PageActionsDropdown=Zs;exports.PermissionChecker=_t;exports.Portal=Oi;exports.Show=di;exports.SmartJsonInput=al;exports.Switch=fi;exports.Tooltip=Ut;exports.addEventListener=vn;exports.addNewLangAtom=Ot;exports.batch=Qa;exports.className=wn;exports.clearDelegatedEvents=vi;exports.convertRemToPixels=bo;exports.createComponent=ps;exports.createComputed=fn;exports.createContext=Ja;exports.createEffect=ms;exports.createMemo=$;exports.createRenderEffect=pe;exports.createRoot=Ee;exports.createSignal=V;exports.createUniqueId=li;exports.delegateEvents=xn;exports.deleteNestedDataByPath=Ye;exports.displayValue=So;exports.getMutationStatusColor=Ao;exports.getPreferredColorScheme=Io;exports.getQueryStatusColor=yo;exports.getQueryStatusColorByLabel=To;exports.getQueryStatusLabel=Eo;exports.getSidedProp=po;exports.insert=Gt;exports.memo=_i;exports.mergeProps=ys;exports.mutationSortFns=vo;exports.navigateToPage=os;exports.on=za;exports.onCleanup=Ve;exports.onMount=hn;exports.parseJSONWithPlaceholders=rs;exports.previewUrlAtom=Wn;exports.serialize=Hn;exports.setAttribute=Dt;exports.sortFns=xo;exports.splitProps=Tn;exports.spread=bn;exports.stringify=mo;exports.template=wi;exports.throwConfetti=xt;exports.untrack=Y;exports.updateNestedDataByPath=We;exports.use=In;exports.useActivePage=he;exports.useAddGlobalSchema=Ta;exports.useApiUrl=j;exports.useApplySchemaToAllPages=xa;exports.useAssetsApiUrl=lr;exports.useBuilderFetch=ur;exports.useBuilderPageData=en;exports.useChaiAuth=Rt;exports.useChaiUserInfo=il;exports.useChaibuilderRealtime=Ir;exports.useChangePage=Yn;exports.useChangeSlug=Hr;exports.useClearAll=Wo;exports.useContext=Za;exports.useCreatePage=Ur;exports.useCurrentPage=te;exports.useCurrentPageOwner=Qs;exports.useDeleteGlobalSchema=Pa;exports.useDeletePage=Fr;exports.useDynamicPageSelector=Vs;exports.useFallbackLang=Mt;exports.useFetch=N;exports.useGotoPage=Jn;exports.useIsLanguagePageCreated=Js;exports.useLanguagePages=Ae;exports.useMarkAsTemplate=Kr;exports.usePageEditInfo=is;exports.usePageLockMeta=cs;exports.usePageLockStatus=re;exports.usePageToUser=ls;exports.usePageType=Ys;exports.usePageTypes=ge;exports.usePagesProps=kt;exports.usePublishPages=fs;exports.useReloadPage=$o;exports.useRemoveSchemaFromAllPages=wa;exports.useSearchParams=le;exports.useSendRealtimeEvent=zs;exports.useTogglePageGlobalSchema=_a;exports.useTransition=Ya;exports.useUnmarkAsTemplate=Vr;exports.useUnpublishPage=qr;exports.useUpdateActivePageMetadata=Yo;exports.useUpdateGlobalSchema=Sa;exports.useUpdatePage=Br;exports.useUpdateWebsiteSettings=tn;exports.useUserId=Et;exports.useUserRoleAndPermissions=sn;exports.useWebsiteLanguagePages=Cr;exports.useWebsitePages=ds;exports.useWebsiteSetting=Te;
|