@chaibuilder/pages 0.16.18 → 0.16.20
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-DbBNqqNQ.cjs → 2AITGKQY-BH_4lP5P.cjs} +1 -1
- package/dist/{2AITGKQY-jev6nZ--.js → 2AITGKQY-BuWtti7-.js} +2 -2
- package/dist/{NCMVHL6D-BjH1Tg1s.cjs → NCMVHL6D-CfRPe-3L.cjs} +1 -1
- package/dist/{NCMVHL6D-BtVmDJZQ.js → NCMVHL6D-DbC9VYfW.js} +2 -2
- package/dist/{ZDWCUMSJ-Nezb42Bx.cjs → ZDWCUMSJ-BxhCnC2U.cjs} +1 -1
- package/dist/{ZDWCUMSJ-S9dikjgz.js → ZDWCUMSJ-CE0Md3aC.js} +1 -1
- package/dist/{active-in-another-tab-nD0Ct2zR.js → active-in-another-tab-C4o8FQXv.js} +1 -1
- package/dist/{active-in-another-tab-B2jwquvi.cjs → active-in-another-tab-SSCyhy2-.cjs} +1 -1
- package/dist/{add-new-language-page-BJk1ZO-t.js → add-new-language-page-BCu4Npk2.js} +2 -2
- package/dist/{add-new-language-page-B2CGLeBl.cjs → add-new-language-page-DUkVmwsT.cjs} +1 -1
- package/dist/{add-new-page-Y4l1kKgu.cjs → add-new-page-BDpRUueB.cjs} +1 -1
- package/dist/{add-new-page-DNMc1_m8.js → add-new-page-D1pc9kLA.js} +1 -1
- package/dist/{ai-panel-content-B2R5ac1Q.cjs → ai-panel-content-Bq3BC1Dm.cjs} +1 -1
- package/dist/{ai-panel-content-BZDagIjt.js → ai-panel-content-Dg6P7vk7.js} +2 -2
- package/dist/{ai-panel-default-lang-DFVRw2XO.js → ai-panel-default-lang-BxYd_6VF.js} +3 -3
- package/dist/{ai-panel-default-lang-DpRzlKuh.cjs → ai-panel-default-lang-C0X_Srso.cjs} +2 -2
- package/dist/{ai-panel-other-lang-mjWK495u.cjs → ai-panel-other-lang-BOu1wJ5J.cjs} +1 -1
- package/dist/{ai-panel-other-lang-CGiXHbUA.js → ai-panel-other-lang-CBAP_iX-.js} +3 -3
- package/dist/{ai-prompt-input-B6dhDx3f.js → ai-prompt-input-CiZCB6jc.js} +2 -2
- package/dist/{ai-prompt-input-B3799aqQ.cjs → ai-prompt-input-bqLGbsQ2.cjs} +1 -1
- package/dist/{ai-translation-prompt-C3SvF46x.cjs → ai-translation-prompt-Cas13J-r.cjs} +1 -1
- package/dist/{ai-translation-prompt-D5ndfcqu.js → ai-translation-prompt-D3XU5z3f.js} +1 -1
- package/dist/{continue-editing-in-this-client-BtPTGxtF.js → continue-editing-in-this-client-DIpi2ZSi.js} +1 -1
- package/dist/{continue-editing-in-this-client-ClnIhAB4.cjs → continue-editing-in-this-client-DbHzW_zt.cjs} +1 -1
- package/dist/{delete-page-CgbNmdX3.js → delete-page-CODOstkw.js} +1 -1
- package/dist/{delete-page-BWQiX4Qy.cjs → delete-page-DPHNAOC6.cjs} +1 -1
- package/dist/{digital-asset-manager-CHPG0akQ.cjs → digital-asset-manager-BllbsemN.cjs} +1 -1
- package/dist/{digital-asset-manager-D2DU2Arz.js → digital-asset-manager-BuYVjKfQ.js} +1 -1
- package/dist/{duplicate-page-D9YHfSTB.cjs → duplicate-page-Dc6_UBNZ.cjs} +1 -1
- package/dist/{duplicate-page-nhaRQq48.js → duplicate-page-DfH67AsW.js} +2 -2
- package/dist/{dynamic-page-selector-BpAx2T1D.js → dynamic-page-selector-C2UK6qGj.js} +1 -1
- package/dist/{dynamic-page-selector-BhFVhQXO.cjs → dynamic-page-selector-Dd8Orls1.cjs} +1 -1
- package/dist/index--Lu_Q_nO.cjs +5 -0
- package/dist/{index-tOCLaJS0.js → index-B_T6ZeA4.js} +106 -106
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/dist/{json-diff-viewer-B7VUOCAk.cjs → json-diff-viewer-1IHmR_Nt.cjs} +1 -1
- package/dist/{json-diff-viewer-BHsCH0rV.js → json-diff-viewer-D8uyTokS.js} +1 -1
- package/dist/{lang-panel-CBDont1C.cjs → lang-panel-D-Pbw2bR.cjs} +1 -1
- package/dist/{lang-panel-Bf4bybUW.js → lang-panel-d7376A7w.js} +2 -2
- package/dist/{mark-as-template-mD5zJnTi.js → mark-as-template-Bx-MAB5M.js} +1 -1
- package/dist/{mark-as-template-ClVxTs7-.cjs → mark-as-template-DHFkkBvV.cjs} +1 -1
- package/dist/{no-language-page-content-BGqiBsuw.cjs → no-language-page-content-DkK7mBnG.cjs} +1 -1
- package/dist/{no-language-page-content-C91jYzRM.js → no-language-page-content-if-qlxZz.js} +1 -1
- package/dist/{no-language-page-dialog-DnN17tvI.cjs → no-language-page-dialog-49fBehZo.cjs} +1 -1
- package/dist/{no-language-page-dialog-CU_Y_GF8.js → no-language-page-dialog-CCLWQP1E.js} +2 -2
- package/dist/{page-creator-Dwn4aALC.js → page-creator-DRDoy3nM.js} +2 -2
- package/dist/{page-creator-BYEKqyKF.cjs → page-creator-DlJXKAhw.cjs} +1 -1
- package/dist/{page-lock-DAWrc3GC.cjs → page-lock-DOnPhjGp.cjs} +1 -1
- package/dist/{page-lock-DHoFXsEj.js → page-lock-pwxPivz-.js} +2 -2
- package/dist/{page-locked-dialog-QL8ZUQQd.js → page-locked-dialog-238NohyB.js} +1 -1
- package/dist/{page-locked-dialog-DMDIpR6r.cjs → page-locked-dialog-DKn93bBu.cjs} +1 -1
- package/dist/{page-manager-new-r1540okw.cjs → page-manager-new-Ch0UNJM1.cjs} +1 -1
- package/dist/{page-manager-new-1RGAp9KU.js → page-manager-new-hEQwUorR.js} +2 -2
- package/dist/{page-manager-search-and-filter-Dp1Z6uDu.cjs → page-manager-search-and-filter-4JatGyBT.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-B9kZBAGe.js → page-manager-search-and-filter-B86rQEO4.js} +1 -1
- package/dist/{page-revisions-content-qrkR9Stz.cjs → page-revisions-content-ChOACVs4.cjs} +1 -1
- package/dist/{page-revisions-content-BLLa8Sar.js → page-revisions-content-V9S1rPUy.js} +2 -2
- package/dist/{publish-pages-content-DquiwxG5.cjs → publish-pages-content-CXKknMnI.cjs} +1 -1
- package/dist/{publish-pages-content-CML_ott4.js → publish-pages-content-GKnG7R5W.js} +2 -2
- package/dist/{save-to-lib-DZOs6H7V.js → save-to-lib-BO3WEr-u.js} +1 -1
- package/dist/{save-to-lib-BBZn9sEZ.cjs → save-to-lib-BderZ0Qz.cjs} +1 -1
- package/dist/{selected-block-display-qF0wXDpP.js → selected-block-display-DAe0XQgw.js} +1 -1
- package/dist/{selected-block-display-DWpFg5KU.cjs → selected-block-display-yB5bvo9w.cjs} +1 -1
- package/dist/{seo-panel-CmqA8v6p.cjs → seo-panel-C2WY1dTf.cjs} +1 -1
- package/dist/{seo-panel-DcTu-rLl.js → seo-panel-DuC3gQQy.js} +1 -1
- package/dist/{shared-json-ld-DZ2eZ35l.cjs → shared-json-ld-ChfktUpf.cjs} +1 -1
- package/dist/{shared-json-ld-Bs_lzQ6G.js → shared-json-ld-DMpCm3M4.js} +1 -1
- package/dist/{slug-input-Df9ug5YA.js → slug-input-CO6AGAQD.js} +1 -1
- package/dist/{slug-input-BvRnz9Xf.cjs → slug-input-CrjrFrxP.cjs} +1 -1
- package/dist/{take-over-request-BBmLlOro.js → take-over-request-Du7grW5x.js} +1 -1
- package/dist/{take-over-request-eUnq0CcU.cjs → take-over-request-mNydSSFX.cjs} +1 -1
- package/dist/{theme-panel-footer-BO6xk08X.js → theme-panel-footer-CSC6DpWO.js} +1 -1
- package/dist/{theme-panel-footer-CzntKXBS.cjs → theme-panel-footer-eZ1bbLzq.cjs} +1 -1
- package/dist/{unmark-as-template-BHbGyEJS.cjs → unmark-as-template-DzU6-XK7.cjs} +1 -1
- package/dist/{unmark-as-template-CSpTbvOz.js → unmark-as-template-dEb6wFT9.js} +1 -1
- package/dist/{unpublish-page-DTVEQJoy.js → unpublish-page-CxAB3-Cj.js} +1 -1
- package/dist/{unpublish-page-kHxAVlJS.cjs → unpublish-page-DGd2Kktq.cjs} +1 -1
- package/dist/{web-preview-CW4XBgip.cjs → web-preview-B6G0vdiq.cjs} +1 -1
- package/dist/{web-preview-SaTB5Pss.js → web-preview-yBF4EXzm.js} +1 -1
- package/package.json +3 -3
- package/dist/index-Nz9M0K-w.cjs +0 -5
|
@@ -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-Nz9M0K-w.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--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;
|
|
@@ -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 { aT as K, ar as Q, A as b, aU as st } from "./index-
|
|
8
|
+
import { aT as K, ar as Q, A as b, aU as st } from "./index-B_T6ZeA4.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 +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--Lu_Q_nO.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-CrjrFrxP.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,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-B_T6ZeA4.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-CO6AGAQD.js";
|
|
11
11
|
const H = () => {
|
|
12
12
|
const s = C(), o = q(), g = A();
|
|
13
13
|
return F({
|
|
@@ -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-B_T6ZeA4.js";
|
|
8
8
|
const D = ({
|
|
9
9
|
isDefaultLang: e,
|
|
10
10
|
searchQuery: l,
|
|
@@ -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--Lu_Q_nO.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;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";var Ss=e=>{throw TypeError(e)};var Ps=(e,t,s)=>t.has(e)||Ss("Cannot "+s);var x=(e,t,s)=>(Ps(e,t,"read from private field"),s?s.call(e):t.get(e)),R=(e,t,s)=>t.has(e)?Ss("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,s),O=(e,t,s,n)=>(Ps(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"),_=require("lucide-react"),F=require("sonner"),Rs=require("@chaibuilder/runtime"),tr=require("@chaibuilder/sdk/web-blocks");function sr(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=sr(h),$e={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"},nr=H.atom({}),kt=()=>H.useAtom(nr),ne=(e,t)=>{const[s]=kt();return h.useMemo(()=>p.get(s,e,t),[s,e,t])},G=()=>ne("apiUrl","/chai/api"),Ms=()=>ne("usersApiUrl","/chai/users"),rr=()=>ne("assetsApiUrl","/chai/assets"),Us=()=>ne("websocket",null),ar=async(e,t,s={})=>await fetch(e,{method:"POST",headers:{"Content-Type":"application/json",...s},body:JSON.stringify(t)}),ir=()=>{const e=N(),t=G();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=G();return h.useCallback(async(n=s,r,a={},i=!1)=>{const l=await t();try{const c=p.get(r,"action","").toLowerCase(),d=await ar(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=G(),[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})},or=H.atom(null),Bs=()=>H.useAtom(or),rs=()=>{const[e]=Bs();return(e==null?void 0:e.slug)||""};function lr(e,t){const[s,n]=h.useState(e);return h.useEffect(()=>{const r=setTimeout(()=>n(e),t);return()=>clearTimeout(r)},[e,t]),s}const cr=({query:e,uuid:t})=>{const{selectedLang:s,fallbackLang:n}=P.useLanguages(),{data:r}=te(),a=r==null?void 0:r.pageType,i=G(),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}},Fs=()=>{const{selectedLang:e,fallbackLang:t}=P.useLanguages(),[s,n]=Bs(),[r,a]=h.useState(""),i=lr(r,500),{allLangPages:l,data:c,isFetching:d}=cr({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}},ur=H.atom({lastSaved:void 0}),as=()=>H.useAtom(ur),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}},fe=()=>{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}},dr=H.atom({}),fr=()=>H.useAtom(dr),hr=()=>{const{data:e}=fe(),t=rs(),s=ne("getLiveUrl",p.noop),n=e==null?void 0:e.slug,r=s(n||"/");return t?r+t:r},Te=()=>{const e=G(),t=N();return S.useQuery({queryKey:[y.GET_WEBSITE_DRAFT_SETTINGS],staleTime:5*60*1e3,placeholderData:{languages:[],theme:{fontFamily:"",borderRadius:"",colors:{}},appKey:"",fallbackLang:""},queryFn:async()=>t(e,{action:y.GET_WEBSITE_DRAFT_SETTINGS,data:{draft:!0}})})};function is(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"},gr=["sync","join","leave"],mr=[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],Er=H.atom({}),qs=H.atom(null),pr=H.atom(J.CHECKING),yr=H.atom({}),Ar=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},Tr=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},pt=()=>{const{user:e}=Rt();return e==null?void 0:e.id},Sr=()=>{const{data:e}=Te();return`WEBSITE:${e==null?void 0:e.appKey}`},yt=()=>{const{data:e}=te();return e==null?void 0:e.id},_e=crypto.randomUUID();let Kt=null;const os=()=>{const[e,t]=H.useAtom(Er);return{pageToUser:e,setPageToUser:t}},ae=()=>{const[e,t]=H.useAtom(pr),s=[J.LOCKED,J.ACTIVE_IN_ANOTHER_TAB].includes(e),n=[J.EDITING].includes(e);return{pageStatus:e,setPageStatus:t,isLocked:s,isEditing:n}},ls=()=>{const[e,t]=H.useAtom(yr);return{pageLockMeta:e,setPageLockMeta:t}},Ks=()=>{const e=yt(),{pageToUser:t}=os();return h.useMemo(()=>t[e],[t,e])},cs=()=>{const e=Us(),{setPageStatus:t}=ae(),[s]=H.useAtom(qs);return h.useEffect(()=>{if(clearTimeout(Kt),!e)return Kt=setTimeout(()=>{e||t(J.EDITING)},500),()=>clearTimeout(Kt)},[e,t]),s},Pr=()=>{const e=yt(),t=pt(),s=cs(),{setPageToUser:n}=os(),{setPageStatus:r,pageStatus:a}=ae(),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=Ar(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===_e){if(a===J.TAKE_OVER_REQUESTED)return;r(J.EDITING)}else f.userId===t&&f.clientId!==_e?r(J.ACTIVE_IN_ANOTHER_TAB):r(J.LOCKED)},[s,n,r,t,a])},Vs=()=>{const e=pt(),t=yt(),s=cs(),n=Ks(),{setPageLockMeta:r}=ls(),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=_e,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])},xr=()=>{const e=pt(),t=yt(),s=cs(),{setPageStatus:n}=ae(),{setPageLockMeta:r}=ls(),a=Vs(),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)!==_e))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=Tr(s==null?void 0:s.presenceState());n(J.CHECKING),await(s==null?void 0:s.track({onlineAt:f,pageId:i.current,userId:e,clientId:_e}));break}case X.TAKE_OVER_REJECTED:{r({type:X.TAKE_OVER_REJECTED});break}}},[a,r,n,s,e,l])},_r=()=>{const e=Us(),t=pt(),s=yt(),n=Sr(),[r,a]=H.useAtom(qs),i=xr(),l=Pr(),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:_e}}});return mr.forEach(f=>{u.on("broadcast",{event:f},E=>{c.current(f)(E)})}),gr.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:_e,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])},us=()=>{const e=N(),t=G();return S.useQuery({queryKey:[y.GET_WEBSITE_PAGES],staleTime:1e3*60*5,queryFn:async()=>e(t,{action:y.GET_WEBSITE_PAGES})||[],placeholderData:s=>s||[]})},wr=e=>{const t=N(),s=G(),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||{}})},vr=h.lazy(()=>Promise.resolve().then(()=>require("./page-manager-new-Ch0UNJM1.cjs"))),Hs=({children:e})=>{const{t}=P.useTranslation(),[s,n]=le(),r=s.get("page"),{data:a,isFetching:i}=te(),{data:l,isFetching:c}=us(),[d,u]=h.useState(!1),[f,E]=h.useState(!0),{savePage:m}=P.useSavePage(),A=!!r&&!p.isEmpty(a),{isLocked:w}=ae(),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(j=>j.id===r))return;const q=new URLSearchParams({page:v});is(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(_.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(_.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(vr,{close:()=>u(!1)})})})]})})]})},br=h.lazy(()=>Promise.resolve().then(()=>require("./add-new-language-page-DUkVmwsT.cjs"))),Ir=()=>{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},Qs=({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}=ae(),{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($e,C,C),isLangPageAdded:!!L}})).filter(Boolean);return[{key:n,value:p.get($e,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),is(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(_.Languages,{className:"h-4 w-4"}),p.get($e,l,l),o.jsx(_.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(_.Languages,{className:"h-4 w-4"}),p.get($e,l,l),o.jsx(_.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(_.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(_.Plus,{className:"mr-1 h-3 w-3"})," Add Langauge"]})]})]})]})})};function Cr(){const[e,t]=H.useAtom(Ot);return o.jsxs("div",{className:"relative z-10 flex items-center justify-end gap-1",children:[o.jsx(Ir,{}),o.jsx(Hs,{}),e&&o.jsx(h.Suspense,{children:o.jsx(br,{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 Lr(){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 Nr=z.lazy(()=>Promise.resolve().then(()=>require("./page-revisions-content-ChOACVs4.cjs")));function jr(){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(_.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(Lr,{}),children:o.jsx(Nr,{isOpen:e})})})]}),o.jsx(g.TooltipContent,{side:"bottom",children:o.jsx("p",{children:"Revision history"})})]})})}const xt=({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},Dr={SLUG_ALREADY_USED:"This slug is already in use. Please choose a different one."},he=()=>{const e=G(),t=N();return S.useQuery({queryKey:[y.GET_PAGE_TYPES],staleTime:1/0,placeholderData:[],queryFn:async()=>t(e,{action:y.GET_PAGE_TYPES})})},zs=e=>{const{data:t}=he();return h.useMemo(()=>t==null?void 0:t.find(s=>s.key===e),[t,e])},Gr=()=>{const e=G(),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),[]}}})},kr=()=>{const e=G(),t=S.useQueryClient(),s=N(),{data:n}=he();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(Dr,r.message,r.message)})}})},Or=()=>{const e=G(),t=S.useQueryClient(),s=N(),{data:n}=fe(),{data:r}=he();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})}})},Rr=()=>{const e=G(),t=S.useQueryClient(),s=N(),{data:n}=he();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})}})},Mr=()=>{const e=G(),t=S.useQueryClient(),s=N(),{data:n}=he();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})}})},ds=()=>{const e=G(),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.")}})},Ur=()=>{const e=G(),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.")}})},Br=()=>{const e=G(),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.")}})},Fr=()=>{const e=G(),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-CXKknMnI.cjs")));function Kr({showModal:e=!1,onClose:t=()=>console.log("Cancelled")}){const{mutate:s,isPending:n}=ds();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"},$s=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]},Vr={particleCount:350,spread:120,origin:{y:.6},angle:90},Hr={TOP_RIGHT:{angle:225,origin:{x:.9,y:0}},BOTTOM_RIGHT:{angle:100,origin:{x:.9,y:.9}}},Qr=async()=>{const{default:e}=await Promise.resolve().then(()=>require("./confetti.module-BuUnQuWk.cjs"));return e},_t=e=>{let t=Hr[e];t||(t={});const s={...Vr,...t};Qr().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 zr=h.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-DGd2Kktq.cjs"))),$r=h.lazy(()=>Promise.resolve().then(()=>require("./translation-warning-modal-Kctu12rQ.cjs"))),Wr=()=>{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}=he(),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(_.Play,{className:"h-4 w-4"})})})})})},Yr=()=>{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(_.Palette,{className:"h-4 w-4"})})}),o.jsx("div",{className:"h-4 w-px bg-gray-200 dark:bg-gray-700"})]})},Jr=()=>{const{t:e}=P.useTranslation(),[t,s]=h.useState(!1),{isLocked:n}=ae(),{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(_.Save,{className:"h-4 w-4"}),buttonClass:"gap-x-1"};case"SAVING":return{tooltipContent:e("Saving"),buttonIcon:o.jsx(_.Loader,{className:"h-4 w-4 animate-spin text-sky-700"}),buttonClass:"gap-x-1"};case"SAVED":return{tooltipContent:e("Saved"),buttonIcon:o.jsx(_.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]})},Zr=()=>{const{t:e}=P.useTranslation(),{selectedLang:t}=P.useLanguages(),{data:s}=fe(),{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}=ds(),{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}j()},j=()=>{const I=[s==null?void 0:s.id,s==null?void 0:s.primaryPage];A({ids:p.compact(I)},{onSuccess:()=>_t("TOP_RIGHT")})},ce=()=>{E(!1),j()},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(_.Send,{className:"h-4 w-4"}):o.jsx(_.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(_.Rocket,{className:"h-4 w-4"}):o.jsx(_.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(_.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:()=>_t("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:()=>_t("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(Kr,{showModal:r,onClose:()=>a(!1)}),c&&o.jsx(h.Suspense,{children:o.jsx(zr,{page:c,onClose:()=>d(null)})}),f&&o.jsx(h.Suspense,{children:o.jsx($r,{isOpen:f,onClose:ue,onContinue:ce,isPending:w})})]})};function Xr(){const{isLocked:e}=ae(),[t]=le(),s=t.get("lang"),n=$s(s);return e||!n?o.jsx("div",{}):o.jsxs("div",{className:"flex items-center justify-end gap-1",children:[o.jsx(jr,{}),o.jsx(xt,{permission:se.EDIT_THEME,children:o.jsx(Yr,{})}),o.jsx(Wr,{}),o.jsx(xt,{permission:se.SAVE_PAGE,children:o.jsx(Jr,{})}),o.jsx(xt,{permission:se.PUBLISH_PAGE,children:o.jsx(Zr,{})})]})}const Ws=({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}=he(),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(_.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(_.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(_.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(_.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(_.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(_.SquareLibrary,{className:"size-3"}),d("Mark as template")]})})]})]})},ea=h.lazy(()=>Promise.resolve().then(()=>require("./add-new-page-BDpRUueB.cjs"))),ta=h.lazy(()=>Promise.resolve().then(()=>require("./delete-page-DPHNAOC6.cjs"))),sa=h.lazy(()=>Promise.resolve().then(()=>require("./duplicate-page-Dc6_UBNZ.cjs"))),na=h.lazy(()=>Promise.resolve().then(()=>require("./mark-as-template-DHFkkBvV.cjs"))),ra=h.lazy(()=>Promise.resolve().then(()=>require("./unmark-as-template-DzU6-XK7.cjs"))),aa=h.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-DGd2Kktq.cjs"))),ia=()=>{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}=fe(),{selectedLang:A,fallbackLang:w}=P.useLanguages(),{data:v}=Ae(),M=v==null?void 0:v.find(j=>j.lang===A),{isLocked:T}=ae(),C=!(E!=null&&E.slug),[,L]=H.useAtom(Ot);if(!E)return null;const q=j=>{A.length>0&&A!==w?L({edit:!0,id:j==null?void 0:j.id,primaryPage:j==null?void 0:j.primaryPage}):f(j)};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(Hs,{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(_.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(_.Hash,{className:"mr-1 h-4 w-4"}):o.jsx(_.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(_.MoreHorizontal,{className:"h-4 w-4"})}):o.jsx(Ws,{page:E,setDuplicatePage:j=>d(j),setAddEditPage:j=>q(j),setUnpublishPage:j=>n(j),setDeletePage:j=>t(j),setMarkAsTemplate:j=>a(j),setUnmarkAsTemplate:j=>l(j),isLanguagePage:A.length>0&&A!==w,children:o.jsx(g.Button,{variant:"ghost",size:"icon",className:"h-7 w-7 rounded",children:o.jsx(_.MoreHorizontal,{className:"h-4 w-4"})})})]}),u&&o.jsx(h.Suspense,{children:o.jsx(ea,{closePanel:()=>f(null),editPage:()=>{},addEditPage:u,setAddEditPage:f})}),e&&o.jsx(h.Suspense,{children:o.jsx(ta,{page:e,onClose:()=>t(null)})}),s&&o.jsx(h.Suspense,{children:o.jsx(aa,{page:s,onClose:()=>n(null)})}),r&&o.jsx(h.Suspense,{children:o.jsx(na,{page:r,onClose:()=>a(null)})}),i&&o.jsx(h.Suspense,{children:o.jsx(ra,{page:i,onClose:()=>l(null)})}),c&&o.jsx(h.Suspense,{children:o.jsx(sa,{page:c,onClose:()=>d(null),closePanel:()=>f(null)})})]})},fs=({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}),oa=({hasDynamicPage:e})=>o.jsx(fs,{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"})]})}),la=h.lazy(()=>Promise.resolve().then(()=>require("./dynamic-page-selector-Dd8Orls1.cjs"))),ca=()=>{const{dynamicPage:e,allLangPages:t,isFetching:s}=Fs(),n=t.length>0;return s?null:o.jsxs("div",{className:"relative",children:[!e&&o.jsx(oa,{hasDynamicPage:n}),o.jsx(h.Suspense,{children:o.jsx(la,{})})]})},ua=()=>{const{data:e,isFetching:t}=fe(),{data:s,isFetching:n}=te(),r=p.get(s,"dynamic",!1),a=rs(),i=P.useChaiFeatureFlag("dynamic-page-selector"),l=e==null?void 0:e.slug,c=!l,d=hr(),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(ia,{})}),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(Qs,{}),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(_.ExternalLink,{className:"h-4 w-4",strokeWidth:1})})})]})]}),r&&i&&o.jsx(ca,{})]})},da=()=>o.jsxs("div",{className:"flex h-full w-full items-center justify-between px-2",children:[o.jsx(Cr,{}),o.jsx(ua,{}),o.jsx(Xr,{})]}),Ys=()=>{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}},fa=()=>{const e=G(),{aiContext:t}=Ys(),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])},ha=(e,t)=>t.map(s=>{if(p.has(e,s._type)){const n=Rs.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}),ga=e=>{const t=Rs.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:ha(t,s)}},[e,t])},ma=()=>{const[e]=le(),t=e.get("page"),s=G(),{setAiContext:n}=Ys(),[,r]=as(),[,a]=fr(),[,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})},Js=()=>{const{data:e}=te(),{data:t}=fe(),s=G(),n=N(),r=Mt(),a=rs();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})},Zs=()=>{const e=G(),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})}})},Ea=()=>{const e=G(),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})}})},pa=()=>{const e=G(),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})}})},ya=()=>{const e=G(),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})}})},Aa=()=>{const e=G(),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})}})},Ta=()=>{const e=G(),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})}})},Sa=()=>{const e=G(),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})}})},xs={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),[]}}},Pa=()=>{const e=G(),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=>xs.getUILibraryBlocks(a,t,e),getBlock:({block:a})=>xs.getUILibraryBlock(a,t,e)})}),n}})},Xs=()=>{const e=Ms(),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})},xa=()=>{const e=G(),t=N(),[,s]=as();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")}}}},_a=()=>{const{data:e}=us(),t=G(),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])}},wa=h.lazy(()=>Promise.resolve().then(()=>require("./ai-panel-content-Bq3BC1Dm.cjs")).then(e=>e.aiPanelContent)),en="chai-chat-panel",va=({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"})})})]}),ba=({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(va,{className:e?"h-5 w-5 text-white":"h-5 w-5 text-primary"})}),Ia={id:en,label:"AI Assistant",button:ba,panel:wa,position:"top"},Ca=h.lazy(()=>Promise.resolve().then(()=>require("./lang-panel-D-Pbw2bR.cjs"))),La=({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(_.LanguagesIcon,{className:"h-4 w-4"})})},tn="lang",Na={id:tn,label:"Languages",position:"top",panel:Ca,button:La,view:"modal",width:400},ja=h.lazy(()=>Promise.resolve().then(()=>require("./seo-panel-C2WY1dTf.cjs"))),sn="seo",Da=({isActive:e,show:t})=>{const{data:s}=te(),n=zs(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"})]})})},Ga={id:sn,label:"SEO",panel:ja,button:Da,position:"top",width:600,view:"modal"},nn="user-info",ka=()=>{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(_.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},Oa={id:nn,label:"User Info",button:ka,position:"bottom"},Ra=()=>{P.registerChaiSidebarPanel(sn,Ga),P.registerChaiSidebarPanel(tn,Na),P.registerChaiSidebarPanel(nn,Oa),(localStorage.getItem("chai-feature-flags")??"").includes("enable-ai-chat-panel")&&P.registerChaiSidebarPanel(en,Ia)};var b={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return _s(this.context.count)},getNextContextId(){return _s(this.context.count++)}};function _s(e){const t=String(e),s=t.length-1;return b.context.id+(s?String.fromCharCode(96+s):"")+t}function We(e){b.context=e}var rn=!1,Ma=(e,t)=>e===t,bt=Symbol("solid-proxy"),an=typeof Proxy=="function",hs=Symbol("solid-track"),It={equals:Ma},on=mn,ge=1,Ct=2,ln={owned:null,cleanups:null,context:null,owner:null},Vt={},k=null,Ht=null,Ua=null,U=null,Z=null,de=null,Bt=0;function Ee(e,t){const s=U,n=k,r=e.length===0,a=t===void 0?n:t,i=r?ln:{owned:null,cleanups:null,context:a?a.context:null,owner:a},l=r?e:()=>e(()=>Y(()=>et(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)),gn(s,r));return[hn.bind(s),n]}function cn(e,t,s){const n=Ft(e,t,!0,ge);He(n)}function pe(e,t,s){const n=Ft(e,t,!1,ge);He(n)}function gs(e,t,s){on=Za;const n=Ft(e,t,!1,ge);(!s||!s.render)&&(n.user=!0),de?de.push(n):He(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,He(n),hn.bind(n)}function Ba(e){return e&&typeof e=="object"&&"then"in e}function Fa(e,t,s){let n,r,a;n=!0,r=e,a={};let i=null,l=Vt,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,D,W,Q){return i===I&&(i=null,Q!==void 0&&(u=!0),(I===l||D===l)&&a.onHydrated&&queueMicrotask(()=>a.onHydrated(Q,{value:D})),l=Vt,j(D,W)),D}function j(I,D){oe(()=>{D===void 0&&A(()=>I),L(D!==void 0?"errored":u?"ready":"unresolved"),v(D);for(const W of E.keys())W.decrement();E.clear()},!1)}function ce(){const I=Wa,D=m(),W=w();if(W!==void 0&&!i)throw W;return U&&U.user,D}function ue(I=!0){if(I!==!1&&d)return;d=!1;const D=f?f():n;if(D==null||D===!1){q(i,Y(m));return}let W;const Q=l!==Vt?l:Y(()=>{try{return r(D,{value:m(),refetching:I})}catch(re){W=re}});if(W!==void 0){q(i,void 0,wt(W),D);return}else if(!Ba(Q))return q(i,Q,void 0,D),Q;return i=Q,"v"in Q?(Q.s===1?q(i,Q.v,void 0,D):q(i,void 0,wt(Q.v),D),Q):(d=!0,queueMicrotask(()=>d=!1),oe(()=>{L(u?"refreshing":"pending"),T()},!1),Q.then(re=>q(Q,re,void 0,D),re=>q(Q,void 0,wt(re),D)))}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?cn(()=>(K=k,ue(!1))):ue(!1),[ce,{refetch:I=>dn(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 Ka(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 un(e){gs(()=>Y(e))}function Ke(e){return k===null||(k.cleanups===null?k.cleanups=[e]:k.cleanups.push(e)),e}function ws(){return k}function dn(e,t){const s=k,n=U;k=e,U=null;try{return oe(t,!0)}catch(r){ms(r)}finally{k=s,U=n}}function Va(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[Ha,sl]=V(!1);function Qa(){return[Ha,Va]}function za(e,t){const s=Symbol("context");return{id:s,Provider:Xa(s),defaultValue:e}}function $a(e){let t;return k&&k.context&&(t=k.context[e.id])!==void 0?t:e.defaultValue}function fn(e){const t=$(e),s=$(()=>Wt(t()));return s.toArray=()=>{const n=s();return Array.isArray(n)?n:n!=null?[n]:[]},s}var Wa;function hn(){if(this.sources&&this.state)if(this.state===ge)He(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 gn(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=Ht&&Ht.running;i&&Ht.disposed.has(a),(i?!a.tState:!a.state)&&(a.pure?Z.push(a):de.push(a),a.observers&&En(a)),i||(a.state=ge)}if(Z.length>1e6)throw Z=[],new Error},!1)),t}function He(e){if(!e.fn)return;et(e);const t=Bt;Ya(e,e.value,t)}function Ya(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=ge,e.owned&&e.owned.forEach(et),e.owned=null),e.updatedAt=s+1,ms(i)}finally{U=a,k=r}(!e.updatedAt||e.updatedAt<=s)&&(e.updatedAt!=null&&"observers"in e?gn(e,n):e.value=n,e.updatedAt=s)}function Ft(e,t,s,n=ge,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!==ln&&(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===ge)He(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=[]),de?s=!0:de=[],Bt++;try{const n=e();return Ja(s),n}catch(n){s||(de=null),Z=null,ms(n)}}function Ja(e){if(Z&&(mn(Z),Z=null),e)return;const t=de;de=null,t.length&&oe(()=>on(t),!1)}function mn(e){for(let t=0;t<e.length;t++)Lt(e[t])}function Za(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}We()}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===ge?n!==t&&(!n.updatedAt||n.updatedAt<Bt)&&Lt(n):r===Ct&&Nt(n,t)}}}function En(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):de.push(s),s.observers&&En(s))}}function et(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--)et(e.tOwned[t]);delete e.tOwned}if(e.owned){for(t=e.owned.length-1;t>=0;t--)et(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 ms(e,t=k){throw wt(e)}function Wt(e){if(typeof e=="function"&&!e.length)return Wt(e());if(Array.isArray(e)){const t=[];for(let s=0;s<e.length;s++){const n=Wt(e[s]);Array.isArray(n)?t.push.apply(t,n):t.push(n)}return t}return e}function Xa(e,t){return function(n){let r;return pe(()=>r=Y(()=>(k.context={...k.context,[e]:n.value},fn(()=>n.children))),void 0),r}}var Yt=Symbol("fallback");function jt(e){for(let t=0;t<e.length;t++)e[t]()}function ei(e,t,s={}){let n=[],r=[],a=[],i=0,l=t.length>1?[]:null;return Ke(()=>jt(a)),()=>{let c=e()||[],d=c.length,u,f;return c[hs],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=[Yt],r[0]=Ee(j=>(a[0]=j,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 ti(e,t,s={}){let n=[],r=[],a=[],i=[],l=0,c;return Ke(()=>jt(a)),()=>{const d=e()||[],u=d.length;return d[hs],Y(()=>{if(u===0)return l!==0&&(jt(a),a=[],n=[],r=[],l=0,i=[]),s.fallback&&(n=[Yt],r[0]=Ee(E=>(a[0]=E,s.fallback())),l=1),r;for(n[0]===Yt&&(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 Es(e,t){return Y(()=>e(t||{}))}function Tt(){return!0}var Jt={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 Qt(e){return(e=typeof e=="function"?e():e)?e:{}}function si(){for(let e=0,t=this.length;e<t;++e){const s=this[e]();if(s!==void 0)return s}}function ps(...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(an&&t)return new Proxy({get(i){for(let l=e.length-1;l>=0;l--){const c=Qt(e[l])[i];if(c!==void 0)return c}},has(i){for(let l=e.length-1;l>=0;l--)if(i in Qt(e[l]))return!0;return!1},keys(){const i=[];for(let l=0;l<e.length;l++)i.push(...Object.keys(Qt(e[l])));return[...new Set(i)]}},Jt);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:si.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 pn(e,...t){if(an&&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)}},Jt));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))}},Jt)),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 yn(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&&We(a),b.count--,c(()=>d.default),We()}),t=l}else if(!t){const[l]=Fa(()=>(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;We(a);const c=i(r);return We(l),c}):"")};return n.preload=()=>s||((s=e()).then(r=>t=()=>r.default),s),n}var ni=0;function ri(){return b.context?b.getNextContextId():`cl-${ni++}`}var An=e=>`Stale read from <${e}>.`;function ai(e){const t="fallback"in e&&{fallback:()=>e.fallback};return $(ei(()=>e.each,e.children,t||void 0))}function ii(e){const t="fallback"in e&&{fallback:()=>e.fallback};return $(ti(()=>e.each,e.children,t||void 0))}function oi(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 An("Show");return s()})):a}return e.fallback},void 0,void 0)}function li(e){const t=fn(()=>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 An("Match");return a()})):l},void 0,void 0)}function ci(e){return e}var ui=["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"],di=new Set(["className","value","readOnly","noValidate","formNoValidate","isMap","noModule","playsInline",...ui]),fi=new Set(["innerHTML","textContent","innerText","children"]),hi=Object.assign(Object.create(null),{className:"class",htmlFor:"for"}),gi=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 mi(e,t){const s=gi[e];return typeof s=="object"?s[t]?s.$:void 0:s}var Ei=new Set(["beforeinput","click","dblclick","contextmenu","focusin","focusout","input","keydown","keyup","mousedown","mousemove","mouseout","mouseover","mouseup","pointerdown","pointermove","pointerout","pointerover","pointerup","touchend","touchmove","touchstart"]),pi=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"]),yi={xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace"},Ai=e=>$(()=>e());function Ti(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 Ze="_$DX_DELEGATE";function Tn(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 Si(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 Sn(e,t=window.document){const s=t[Ze]||(t[Ze]=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,vn))}}function Pi(e=window.document){if(e[Ze]){for(let t of e[Ze].keys())e.removeEventListener(t,vn);delete e[Ze]}}function Dt(e,t,s){we(e)||(s==null?e.removeAttribute(t):e.setAttribute(t,s))}function xi(e,t,s,n){we(e)||(n==null?e.removeAttributeNS(t,s):e.setAttributeNS(t,s,n))}function _i(e,t,s){we(e)||(s?e.setAttribute(t,""):e.removeAttribute(t))}function Pn(e,t){we(e)||(t==null?e.removeAttribute("class"):e.className=t)}function xn(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 wi(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]||(vs(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||(vs(e,l,!0),s[l]=c)}return s}function vi(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 _n(e,t={},s,n){const r={};return n||pe(()=>r.children=tt(e,t.children,r.children)),pe(()=>typeof t.ref=="function"&&wn(t.ref,e)),pe(()=>bi(e,t,s,!0,r,!0)),r}function wn(e,t,s){return Y(()=>e(t,s))}function Gt(e,t,s,n){if(s!==void 0&&!n&&(n=[]),typeof t!="function")return tt(e,t,n,s);pe(r=>tt(e,t(),r,s),n)}function bi(e,t,s,n,r={},a=!1){t||(t={});for(const i in r)if(!(i in t)){if(i==="children")continue;r[i]=bs(e,i,null,r[i],s,a,t)}for(const i in t){if(i==="children")continue;const l=t[i];r[i]=bs(e,i,l,r[i],s,a,t)}}function Ii(e){let t,s;return!we()||!(t=b.registry.get(s=Li()))?e():(b.completed&&b.completed.add(t),b.registry.delete(s),t)}function we(e){return!!b.context&&!b.done&&(!e||e.isConnected)}function Ci(e){return e.toLowerCase().replace(/-([a-z])/g,(t,s)=>s.toUpperCase())}function vs(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 bs(e,t,s,n,r,a,i){let l,c,d,u,f;if(t==="style")return vi(e,s,n);if(t==="classList")return wi(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=Ei.has(E);if(!m&&n){const A=Array.isArray(n)?n[0]:n;e.removeEventListener(E,A)}(m||s)&&(xn(e,E,s,m),m&&Sn([E]))}else if(t.slice(0,5)==="attr:")Dt(e,t.slice(5),s);else if(t.slice(0,5)==="bool:")_i(e,t.slice(5),s);else if((f=t.slice(0,5)==="prop:")||(d=fi.has(t))||!r&&((u=mi(t,e.tagName))||(c=di.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"?Pn(e,s):l&&!c&&!d?e[Ci(t)]=s:e[u||t]=s}else{const E=r&&t.indexOf(":")>-1&&yi[t.split(":")[0]];E?xi(e,E,t,s):Dt(e,hi[t]||t,s)}return s}function vn(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 tt(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=ve(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=ve(e,s,n)}else{if(i==="function")return pe(()=>{let c=t();for(;typeof c=="function";)c=c();s=tt(e,c,s,n)}),()=>s;if(Array.isArray(t)){const c=[],d=s&&Array.isArray(s);if(Zt(c,t,s,r))return pe(()=>s=tt(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=ve(e,s,n),l)return s}else d?s.length===0?Is(e,c,n):Ti(e,s,c):(s&&ve(e),Is(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=ve(e,s,n,t);ve(e,s,null,t)}else s==null||s===""||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);s=t}}return s}function Zt(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=Zt(e,l,c)||r;else if(d==="function")if(n){for(;typeof l=="function";)l=l();r=Zt(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 Is(e,t,s=null){for(let n=0,r=t.length;n<r;n++)e.insertBefore(t[n],s)}function ve(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 Li(){return b.getNextContextId()}var Ni="http://www.w3.org/2000/svg";function bn(e,t=!1){return t?document.createElementNS(Ni,e):document.createElement(e)}function ji(e){const{useShadow:t}=e,s=document.createTextNode(""),n=()=>e.mount||document.body,r=ws();let a,i=!!b.context;return gs(()=>{i&&(ws().user=i=!1),a||(a=dn(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)),Ke(u)}else{const c=bn(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),Ke(()=>l.removeChild(c))}},void 0,{render:!i}),s}function Di(e,t){const s=$(e);return $(()=>{const n=s();switch(typeof n){case"function":return Y(()=>n(t));case"string":const r=pi.has(n),a=b.context?Ii():bn(n,r);return _n(a,t,r),a}})}function Gi(e){const[,t]=pn(e,["component"]);return Di(()=>e.component,t)}var ki=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()}},In=class{constructor(e){this.generateIdentifier=e,this.kv=new ki}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)}},Oi=class extends In{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 Ri(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 Mi(e,t){const s=Ri(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 Ve(e,t){Object.entries(e).forEach(([s,n])=>t(n,s))}function vt(e,t){return e.indexOf(t)!==-1}function Cs(e,t){for(let s=0;s<e.length;s++){const n=e[s];if(t(n))return n}}var Ui=class{constructor(){this.transfomers={}}register(e){this.transfomers[e.name]=e}findApplicable(e){return Mi(this.transfomers,t=>t.isApplicable(e))}findByName(e){return this.transfomers[e]}},Bi=e=>Object.prototype.toString.call(e).slice(8,-1),Cn=e=>typeof e>"u",Fi=e=>e===null,st=e=>typeof e!="object"||e===null||e===Object.prototype?!1:Object.getPrototypeOf(e)===null?!0:Object.getPrototypeOf(e)===Object.prototype,Xt=e=>st(e)&&Object.keys(e).length===0,ye=e=>Array.isArray(e),qi=e=>typeof e=="string",Ki=e=>typeof e=="number"&&!isNaN(e),Vi=e=>typeof e=="boolean",Hi=e=>e instanceof RegExp,nt=e=>e instanceof Map,rt=e=>e instanceof Set,Ln=e=>Bi(e)==="Symbol",Qi=e=>e instanceof Date&&!isNaN(e.valueOf()),zi=e=>e instanceof Error,Ls=e=>typeof e=="number"&&isNaN(e),$i=e=>Vi(e)||Fi(e)||Cn(e)||Ki(e)||qi(e)||Ln(e),Wi=e=>typeof e=="bigint",Yi=e=>e===1/0||e===-1/0,Ji=e=>ArrayBuffer.isView(e)&&!(e instanceof DataView),Zi=e=>e instanceof URL,Nn=e=>e.replace(/\./g,"\\."),zt=e=>e.map(String).map(Nn).join("."),Xe=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 jn=[ie(Cn,"undefined",()=>null,()=>{}),ie(Wi,"bigint",e=>e.toString(),e=>typeof BigInt<"u"?BigInt(e):e),ie(Qi,"Date",e=>e.toISOString(),e=>new Date(e)),ie(zi,"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(Hi,"regexp",e=>""+e,e=>{const t=e.slice(1,e.lastIndexOf("/")),s=e.slice(e.lastIndexOf("/")+1);return new RegExp(t,s)}),ie(rt,"set",e=>[...e.values()],e=>new Set(e)),ie(nt,"map",e=>[...e.entries()],e=>new Map(e)),ie(e=>Ls(e)||Yi(e),"number",e=>Ls(e)?"NaN":e>0?"Infinity":"-Infinity",Number),ie(e=>e===0&&1/e===-1/0,"number",()=>"-0",Number),ie(Zi,"URL",e=>e.toString(),e=>new URL(e))];function qt(e,t,s,n){return{isApplicable:e,annotation:t,transform:s,untransform:n}}var Dn=qt((e,t)=>Ln(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}),Xi=[Int8Array,Uint8Array,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array,Uint8ClampedArray].reduce((e,t)=>(e[t.name]=t,e),{}),Gn=qt(Ji,e=>["typed-array",e.constructor.name],e=>[...e],(e,t)=>{const s=Xi[t[1]];if(!s)throw new Error("Trying to deserialize unknown typed array");return new s(e)});function kn(e,t){return e!=null&&e.constructor?!!t.classRegistry.getIdentifier(e.constructor):!1}var On=qt(kn,(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)}),Rn=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)}),eo=[On,Dn,Rn,Gn],Ns=(e,t)=>{const s=Cs(eo,r=>r.isApplicable(e,t));if(s)return{value:s.transform(e,t),type:s.annotation(e,t)};const n=Cs(jn,r=>r.isApplicable(e,t));if(n)return{value:n.transform(e,t),type:n.annotation}},Mn={};jn.forEach(e=>{Mn[e.annotation]=e});var to=(e,t,s)=>{if(ye(t))switch(t[0]){case"symbol":return Dn.untransform(e,t,s);case"class":return On.untransform(e,t,s);case"custom":return Rn.untransform(e,t,s);case"typed-array":return Gn.untransform(e,t,s);default:throw new Error("Unknown transformation: "+t)}else{const n=Mn[t];if(!n)throw new Error("Unknown transformation: "+t);return n.untransform(e,s)}},be=(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 Un(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 so=(e,t)=>{Un(t);for(let s=0;s<t.length;s++){const n=t[s];if(rt(e))e=be(e,+n);else if(nt(e)){const r=+n,a=+t[++s]==0?"key":"value",i=be(e,r);switch(a){case"key":e=i;break;case"value":e=e.get(i);break}}else e=e[n]}return e},es=(e,t,s)=>{if(Un(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(st(n))n=n[i];else if(rt(n)){const l=+i;n=be(n,l)}else if(nt(n)){if(a===t.length-2)break;const c=+i,d=+t[++a]==0?"key":"value",u=be(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]):st(n)&&(n[r]=s(n[r])),rt(n)){const a=be(n,+r),i=s(a);a!==i&&(n.delete(a),n.add(i))}if(nt(n)){const a=+t[t.length-2],i=be(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 ts(e,t,s=[]){if(!e)return;if(!ye(e)){Ve(e,(a,i)=>ts(a,t,[...s,...Xe(i)]));return}const[n,r]=e;r&&Ve(r,(a,i)=>{ts(a,t,[...s,...Xe(i)])}),t(n,s)}function no(e,t,s){return ts(t,(n,r)=>{e=es(e,r,a=>to(a,n,s))}),e}function ro(e,t){function s(n,r){const a=so(e,Xe(r));n.map(Xe).forEach(i=>{e=es(e,i,()=>a)})}if(ye(t)){const[n,r]=t;n.forEach(a=>{e=es(e,Xe(a),()=>e)}),r&&Ve(r,s)}else Ve(t,s);return e}var ao=(e,t)=>st(e)||ye(e)||nt(e)||rt(e)||kn(e,t);function io(e,t,s){const n=s.get(e);n?n.push(t):s.set(e,[t])}function oo(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(zt):s[zt(a)]=i.map(zt)}),n?Xt(s)?[n]:[n,s]:Xt(s)?void 0:s}var Bn=(e,t,s,n,r=[],a=[],i=new Map)=>{const l=$i(e);if(!l){io(e,r,t);const m=i.get(e);if(m)return n?{transformedValue:null}:m}if(!ao(e,s)){const m=Ns(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=Ns(e,s),d=(c==null?void 0:c.value)??e,u=ye(d)?[]:{},f={};Ve(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=Bn(m,t,s,n,[...r,A],[...a,e],i);u[A]=w.transformedValue,ye(w.annotations)?f[A]=w.annotations:st(w.annotations)&&Ve(w.annotations,(v,M)=>{f[Nn(A)+"."+M]=v})});const E=Xt(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 Fn(e){return Object.prototype.toString.call(e).slice(8,-1)}function js(e){return Fn(e)==="Array"}function lo(e){if(Fn(e)!=="Object")return!1;const t=Object.getPrototypeOf(e);return!!t&&t.constructor===Object&&t===Object.prototype}function co(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 ss(e,t={}){if(js(e))return e.map(r=>ss(r,t));if(!lo(e))return e;const s=Object.getOwnPropertyNames(e),n=Object.getOwnPropertySymbols(e);return[...s,...n].reduce((r,a)=>{if(js(t.props)&&!t.props.includes(a))return r;const i=e[a],l=ss(i,t);return co(r,a,l,e,t.nonenumerable),r},{})}var B=class{constructor({dedupe:e=!1}={}){this.classRegistry=new Oi,this.symbolRegistry=new In(t=>t.description??""),this.customTransformerRegistry=new Ui,this.allowedErrorProps=[],this.dedupe=e}serialize(e){const t=new Map,s=Bn(e,t,this,this.dedupe),n={json:s.transformedValue};s.annotations&&(n.meta={...n.meta,values:s.annotations});const r=oo(t,this.dedupe);return r&&(n.meta={...n.meta,referentialEqualities:r}),n}deserialize(e){const{json:t,meta:s}=e;let n=ss(t);return s!=null&&s.values&&(n=no(n,s.values,this)),s!=null&&s.referentialEqualities&&(n=ro(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 qn=B.serialize,uo=B.stringify;function fo(e){return e.state.fetchStatus==="fetching"?"fetching":e.getObserversCount()?e.state.fetchStatus==="paused"?"paused":e.isStale()?"stale":"fresh":"inactive"}function ho(e,t){return`${e}${t.charAt(0).toUpperCase()+t.slice(1)}`}function go({queryState:e,observerCount:t,isStale:s}){return e.fetchStatus==="fetching"?"blue":t?e.fetchStatus==="paused"?"purple":s?"yellow":"green":"gray"}function mo({status:e,isPaused:t}){return t?"purple":e==="error"?"red":e==="pending"?"yellow":e==="success"?"green":"gray"}function Eo(e){return e==="fresh"?"green":e==="stale"?"yellow":e==="paused"?"purple":e==="inactive"?"gray":"blue"}var po=(e,t=!1)=>{const{json:s}=qn(e);return JSON.stringify(s,null,t?2:void 0)},St=e=>e.state.fetchStatus!=="idle"?0:e.getObserversCount()?e.isStale()?2:1:3,yo=(e,t)=>e.queryHash.localeCompare(t.queryHash),Kn=(e,t)=>e.state.dataUpdatedAt<t.state.dataUpdatedAt?1:-1,Ao=(e,t)=>St(e)===St(t)?Kn(e,t):St(e)>St(t)?1:-1,To={status:Ao,"query hash":yo,"last updated":Kn},Pt=e=>e.state.isPaused?0:e.state.status==="error"?2:e.state.status==="pending"?1:3,Vn=(e,t)=>e.state.submittedAt<t.state.submittedAt?1:-1,So=(e,t)=>Pt(e)===Pt(t)?Vn(e,t):Pt(e)>Pt(t)?1:-1,Po={status:So,"last updated":Vn},xo=e=>e*parseFloat(getComputedStyle(document.documentElement).fontSize),_o=()=>{const[e,t]=V("dark");return un(()=>{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),Ke(()=>s.removeEventListener("change",n))}),e},Ye=(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,Ye(n.get(r),a,s)),n}if(e instanceof Set){const n=Ye(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]=Ye(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]=Ye(n[r],a,s),n}return e},Je=(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,Je(s.get(n),r)),s}if(e instanceof Set){const s=Je(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]=Je(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]=Je(s[n],r),s}return e},Hn=(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)},Ie,at,it,ot,Pe,lt,Ce,Le,Ne,je,De,ct,Ge,ut,ks,wo=(ks=class{constructor(e){R(this,Ie);R(this,at);R(this,it);R(this,ot);R(this,Pe,!1);R(this,lt);R(this,Ce);R(this,Le);R(this,Ne);R(this,je);R(this,De);R(this,ct);R(this,Ge);R(this,ut);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,Ie,V(t)),O(this,it,s),O(this,ot,n),O(this,at,r),O(this,lt,d),O(this,Ce,u),O(this,Le,V(a)),O(this,Ne,V(i)),O(this,je,V(l)),O(this,De,V(c)),O(this,ct,V(f))}setButtonPosition(e){x(this,Le)[1](e)}setPosition(e){x(this,Ne)[1](e)}setInitialIsOpen(e){x(this,je)[1](e)}setErrorTypes(e){x(this,De)[1](e)}setClient(e){x(this,Ie)[1](e)}mount(e){if(x(this,Pe))throw new Error("Devtools is already mounted");const t=Tn(()=>{const s=this,[n]=x(this,Le),[r]=x(this,Ne),[a]=x(this,je),[i]=x(this,De),[l]=x(this,ct),[c]=x(this,Ie);let d;return x(this,Ge)?d=x(this,Ge):(d=yn(()=>Promise.resolve().then(()=>require("./NCMVHL6D-CfRPe-3L.cjs"))),O(this,Ge,d)),Hn(x(this,lt),x(this,Ce)),Es(d,ps({get queryFlavor(){return x(s,it)},get version(){return x(s,ot)},get onlineManager(){return x(s,at)},get shadowDOMTarget(){return x(s,Ce)}},{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,ut,t)}unmount(){var e;if(!x(this,Pe))throw new Error("Devtools is not mounted");(e=x(this,ut))==null||e.call(this),O(this,Pe,!1)}},Ie=new WeakMap,at=new WeakMap,it=new WeakMap,ot=new WeakMap,Pe=new WeakMap,lt=new WeakMap,Ce=new WeakMap,Le=new WeakMap,Ne=new WeakMap,je=new WeakMap,De=new WeakMap,ct=new WeakMap,Ge=new WeakMap,ut=new WeakMap,ks),ke,dt,ft,ht,xe,gt,Oe,Re,Me,Ue,Be,mt,Fe,qe,Et,Os,vo=(Os=class{constructor(e){R(this,ke);R(this,dt);R(this,ft);R(this,ht);R(this,xe,!1);R(this,gt);R(this,Oe);R(this,Re);R(this,Me);R(this,Ue);R(this,Be);R(this,mt);R(this,Fe);R(this,qe);R(this,Et);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,ke,V(t)),O(this,ft,s),O(this,ht,n),O(this,dt,r),O(this,gt,d),O(this,Oe,u),O(this,Re,V(a)),O(this,Me,V(i)),O(this,Ue,V(l)),O(this,Be,V(c)),O(this,mt,V(E)),O(this,Fe,V(f))}setButtonPosition(e){x(this,Re)[1](e)}setPosition(e){x(this,Me)[1](e)}setInitialIsOpen(e){x(this,Ue)[1](e)}setErrorTypes(e){x(this,Be)[1](e)}setClient(e){x(this,ke)[1](e)}setOnClose(e){x(this,Fe)[1](()=>e)}mount(e){if(x(this,xe))throw new Error("Devtools is already mounted");const t=Tn(()=>{const s=this,[n]=x(this,Re),[r]=x(this,Me),[a]=x(this,Ue),[i]=x(this,Be),[l]=x(this,mt),[c]=x(this,ke),[d]=x(this,Fe);let u;return x(this,qe)?u=x(this,qe):(u=yn(()=>Promise.resolve().then(()=>require("./2AITGKQY-BH_4lP5P.cjs"))),O(this,qe,u)),Hn(x(this,gt),x(this,Oe)),Es(u,ps({get queryFlavor(){return x(s,ft)},get version(){return x(s,ht)},get onlineManager(){return x(s,dt)},get shadowDOMTarget(){return x(s,Oe)}},{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,xe,!0),O(this,Et,t)}unmount(){var e;if(!x(this,xe))throw new Error("Devtools is not mounted");(e=x(this,Et))==null||e.call(this),O(this,xe,!1)}},ke=new WeakMap,dt=new WeakMap,ft=new WeakMap,ht=new WeakMap,xe=new WeakMap,gt=new WeakMap,Oe=new WeakMap,Re=new WeakMap,Me=new WeakMap,Ue=new WeakMap,Be=new WeakMap,mt=new WeakMap,Fe=new WeakMap,qe=new WeakMap,Et=new WeakMap,Os);function bo(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 wo({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 Io(e){const t=S.useQueryClient(e.client),s=z.useRef(null),{errorTypes:n,styleNonce:r,shadowDOMTarget:a,hideDisabledQueries:i}=e,[l]=z.useState(new vo({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 Ds=process.env.NODE_ENV!=="development"?function(){return null}:bo;process.env.NODE_ENV;const Qn=H.atom(""),Co=()=>{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"})},Lo=()=>{const e=G(),t=N();return S.useQuery({queryKey:[y.GET_COLLECTIONS],staleTime:1/0,queryFn:async()=>t(e,{action:y.GET_COLLECTIONS})})},No=()=>{const{data:e}=te(),{data:t}=fe(),{data:s}=Te(),n=G(),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}})},zn=()=>{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])},$n=()=>{const e=zn();return h.useCallback(({pageId:t})=>{e(t)},[e])},jo=h.lazy(()=>Promise.resolve().then(()=>require("./page-lock-DOnPhjGp.cjs"))),Do=h.lazy(()=>Promise.resolve().then(()=>require("./no-language-page-dialog-49fBehZo.cjs"))),Go=h.lazy(()=>Promise.resolve().then(()=>require("./digital-asset-manager-BllbsemN.cjs"))),ko=h.lazy(()=>Promise.resolve().then(()=>require("./save-to-lib-BderZ0Qz.cjs"))),Oo=h.lazy(()=>Promise.resolve().then(()=>require("./theme-panel-footer-eZ1bbLzq.cjs"))),Ro=h.lazy(()=>Promise.resolve().then(()=>require("./web-preview-B6G0vdiq.cjs")));Co();tr.loadWebBlocks();P.registerChaiTopBar(da);Ra();P.registerChaiMediaManager(Go);P.registerChaiSaveToLibrary(ko);const Mo={role:"",permissions:null},Gs=e=>{const{data:t}=Pa(),s=Mt(),{data:n=Mo,isFetching:r}=Xs(),{data:a,isFetching:i}=he(),{data:l,isFetching:c}=Lo(),{data:d,isFetching:u}=Te(),f=r||i||c||u,[E]=le(),m=E.get("page"),{data:A}=te(),{data:w,isFetching:v}=ma(),{blocks:M}=ga(w),{data:T,isFetching:C}=Js(),{pageStatus:L}=ae(),q=fa(),{onSave:j}=xa(),{mutateAsync:ce}=No(),{getPartialBlocks:ue,getPartialBlockBlocks:K}=_a(),{mutateAsync:I}=Gr(),{mutateAsync:D}=Zs(),W=$n(),[Q,re]=h.useState(!1),Qe=h.useRef([]),me=h.useMemo(()=>p.get(d,"theme",{})||{},[d]),ze=L===J.EDITING,Se=L===J.CHECKING,ys=v||Se||C;Qe.current=M;const[Jn]=H.useAtom(Qn);h.useEffect(()=>{const ee=()=>{document.hidden?re(!0):re(!1)};return window.addEventListener("visibilitychange",ee),()=>window.removeEventListener("visibilitychange",ee)},[]);const Zn=h.useMemo(()=>{const ee={};return n&&(ee.permissions=p.get(n,"permissions",null),ee.role=p.get(n,"role","user")),ee},[n]),As=h.useMemo(()=>t==null?void 0:t.some(ee=>ee.isSiteLibrary),[t]),Xn=h.useCallback(async(ee,At)=>await I({pageType:ee,query:At}),[I]);return o.jsxs(o.Fragment,{children:[ys&&o.jsx(fs,{className:f?"fixed inset-0 bg-white":"bg-white/75",children:o.jsx(_.Loader,{className:`animate-spin text-primary ${f?"h-6 w-6":"h-5 w-5"}`})}),Jn&&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(_.Loader,{className:"h-6 w-6 animate-spin text-primary"})}),children:o.jsx(Ro,{})}),o.jsx(P.ChaiBuilderEditor,{flags:e.flags?{...e.flags,librarySite:As}:{librarySite:As},gotoPage:W,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)||{},translations:e.translations||{},locale:e.locale||"en",htmlDir:e.htmlDir||"ltr",autoSave:!Q&&ze&&(e.autoSave??!0),autoSaveInterval:e.autoSaveInterval??15,onError:e.onError||console.error,getPartialBlockBlocks:K,getPartialBlocks:ue,blocks:v?[]:M,theme:p.cloneDeep(me),pageTypes:a,searchPageTypeItems:Xn,askAiCallBack:q,onSave:async({blocks:ee,theme:At,needTranslations:er})=>{if(!m)return!0;Qe.current=ee;const Ts=[...ee];return await j({page:m,blocks:Ts,needTranslations:er}),Qe.current=Ts,p.isEqual(At,me)||await D({settings:{theme:At}}),!0},themePanelComponent:Oo,...Zn,children:o.jsx(jo,{isFetchingPageData:ys})}),o.jsx("div",{children:o.jsx(Do,{})})]})},Uo=new S.QueryClient({defaultOptions:{queries:{refetchOnWindowFocus:!1,refetchOnReconnect:!1,refetchOnMount:!1}}}),Bo=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(Gs,{...e}),o.jsx(Ds,{})]}):o.jsxs(S.QueryClientProvider,{client:Uo,children:[o.jsx(Gs,{...e}),o.jsx(Ds,{})]}):o.jsx("div",{})},Fo=z.lazy(()=>Promise.resolve().then(()=>require("./nested-path-selector-content-D_iF9Sm3.cjs")));function Wn({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(Fo,{data:e,onSelect:t,dataType:s,open:r,setOpen:a})})]})}const qo=()=>{const{savePageAsync:e}=P.useSavePage(),t=S.useQueryClient(),{isLocked:s}=ae();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])},Ko=()=>{const e=S.useQueryClient();return h.useCallback(()=>{e.clear()},[e])},Vo=()=>{const e=G(),t=N(),{data:s}=fe(),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")}})},Ho=h.lazy(()=>Promise.resolve().then(()=>require("./digital-asset-manager-BllbsemN.cjs"))),Qo=({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,{className:"h-4 w-4"}):o.jsx(_.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(_.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(_.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,{className:"h-4 w-4"})})]}),o.jsx("div",{className:"h-full flex-1 p-4",children:o.jsx(h.Suspense,{children:o.jsx(Ho,{close:u,onSelect:f,mode:"image",assetId:e})})})]})})]})},zo=h.createContext(null),$t={didCatch:!1,error:null};class Yn extends h.Component{constructor(t){super(t),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=$t}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($t)}}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&&$o(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($t)}}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(zo.Provider,{value:{didCatch:a,error:i,resetErrorBoundary:this.resetErrorBoundary}},l)}}function $o(){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 Wo=e=>e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"),ns=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}}}},Yo=(e,t)=>{let n=JSON.stringify(e,null,2);return t.forEach(({original:r},a)=>{const i=`"__placeholder_${a}__"`,l=new RegExp(Wo(i),"g");n=n.replace(l,r)}),n},Jo=(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},Zo=h.lazy(()=>Promise.resolve().then(()=>require("./shared-json-ld-ChfktUpf.cjs"))),Xo=({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)},j=K=>{if(K.key==="Tab"){K.preventDefault();const I=K.currentTarget,D=I.selectionStart,W=I.selectionEnd;if(D!==W){const re=e.substring(D,W).split(`
|
|
3
|
+
`);if(K.shiftKey){const me=re.map(Se=>Se.startsWith(" ")?Se.substring(2):Se).join(`
|
|
4
|
+
`),ze=e.substring(0,D)+me+e.substring(W);t(ze),setTimeout(()=>{I.selectionStart=D,I.selectionEnd=D+me.length},0)}else{const me=re.map(Se=>` ${Se}`).join(`
|
|
5
|
+
`),ze=e.substring(0,D)+me+e.substring(W);t(ze),setTimeout(()=>{I.selectionStart=D,I.selectionEnd=D+me.length},0)}}else{const Q=e.substring(0,D)+" "+e.substring(W);t(Q),setTimeout(()=>{I.selectionStart=I.selectionEnd=D+2},0)}}};h.useEffect(()=>{const K=ns(e);if(K.isValid)if(A(null),K.parsed){const I=Jo(K.parsed,l);v(I)}else v("");else A(K.error),v("")},[e,l]);const ce=()=>{const K=ns(e);if(K.isValid&&K.parsed){const I=Yo(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(Yn,{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(_.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(_.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(_.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(Wn,{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(_.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(_.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:j,value:e,placeholder:r,rows:a,disabled:s,readOnly:n}),m&&o.jsxs(g.Alert,{variant:"destructive",className:"mt-2",children:[o.jsx(_.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(Zo,{})})})]})})})},el=e=>{const t=Ms(),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=hs;exports.ACTIONS=y;exports.BlurContainer=fs;exports.ChaiBuilderPages=Bo;exports.Dynamic=Gi;exports.EVENT=X;exports.ErrorBoundary=Yn;exports.For=ai;exports.ImagePicker=Qo;exports.Index=ii;exports.LANGUAGES=$e;exports.LanguageSwitcher=Qs;exports.Match=ci;exports.NestedPathSelector=Wn;exports.PAGES_PERMISSIONS=se;exports.PAGE_STATUS=J;exports.PageActionsDropdown=Ws;exports.PermissionChecker=xt;exports.Portal=ji;exports.Show=oi;exports.SmartJsonInput=Xo;exports.Switch=li;exports.Tooltip=Ut;exports.addEventListener=xn;exports.addNewLangAtom=Ot;exports.batch=qa;exports.className=Pn;exports.clearDelegatedEvents=Pi;exports.convertRemToPixels=xo;exports.createComponent=Es;exports.createComputed=cn;exports.createContext=za;exports.createEffect=gs;exports.createMemo=$;exports.createRenderEffect=pe;exports.createRoot=Ee;exports.createSignal=V;exports.createUniqueId=ri;exports.delegateEvents=Sn;exports.deleteNestedDataByPath=Je;exports.displayValue=po;exports.getMutationStatusColor=mo;exports.getPreferredColorScheme=_o;exports.getQueryStatusColor=go;exports.getQueryStatusColorByLabel=Eo;exports.getQueryStatusLabel=fo;exports.getSidedProp=ho;exports.insert=Gt;exports.memo=Ai;exports.mergeProps=ps;exports.mutationSortFns=Po;exports.navigateToPage=is;exports.on=Ka;exports.onCleanup=Ke;exports.onMount=un;exports.parseJSONWithPlaceholders=ns;exports.previewUrlAtom=Qn;exports.serialize=qn;exports.setAttribute=Dt;exports.sortFns=To;exports.splitProps=pn;exports.spread=_n;exports.stringify=uo;exports.template=Si;exports.throwConfetti=_t;exports.untrack=Y;exports.updateNestedDataByPath=Ye;exports.use=wn;exports.useActivePage=fe;exports.useAddGlobalSchema=Ea;exports.useApiUrl=G;exports.useApplySchemaToAllPages=Ta;exports.useAssetsApiUrl=rr;exports.useBuilderFetch=ir;exports.useBuilderPageData=Js;exports.useChaiAuth=Rt;exports.useChaiUserInfo=el;exports.useChaibuilderRealtime=_r;exports.useChangePage=zn;exports.useChangeSlug=Fr;exports.useClearAll=Ko;exports.useContext=$a;exports.useCreatePage=kr;exports.useCurrentPage=te;exports.useCurrentPageOwner=Ks;exports.useDeleteGlobalSchema=ya;exports.useDeletePage=Rr;exports.useDynamicPageSelector=Fs;exports.useFallbackLang=Mt;exports.useFetch=N;exports.useGotoPage=$n;exports.useIsLanguagePageCreated=$s;exports.useLanguagePages=Ae;exports.useMarkAsTemplate=Ur;exports.usePageEditInfo=as;exports.usePageLockMeta=ls;exports.usePageLockStatus=ae;exports.usePageToUser=os;exports.usePageType=zs;exports.usePageTypes=he;exports.usePagesProps=kt;exports.usePublishPages=ds;exports.useReloadPage=qo;exports.useRemoveSchemaFromAllPages=Sa;exports.useSearchParams=le;exports.useSendRealtimeEvent=Vs;exports.useTogglePageGlobalSchema=Aa;exports.useTransition=Qa;exports.useUnmarkAsTemplate=Br;exports.useUnpublishPage=Mr;exports.useUpdateActivePageMetadata=Vo;exports.useUpdateGlobalSchema=pa;exports.useUpdatePage=Or;exports.useUpdateWebsiteSettings=Zs;exports.useUserId=pt;exports.useUserRoleAndPermissions=Xs;exports.useWebsiteLanguagePages=wr;exports.useWebsitePages=us;exports.useWebsiteSetting=Te;
|