@chaibuilder/sdk 4.0.0-beta.49 → 4.0.0-beta.50
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/README.md +0 -5
- package/dist/{2SSKDMRQ-CjvuNdPo.cjs → 2SSKDMRQ-DRvGNTLs.cjs} +1 -1
- package/dist/{2SSKDMRQ-Dvf9zadl.js → 2SSKDMRQ-DqIyZppU.js} +2 -2
- package/dist/{AP7HFJJL-DYFttFoI.cjs → AP7HFJJL-BWwvxG86.cjs} +1 -1
- package/dist/{AP7HFJJL-q4dJdyFs.js → AP7HFJJL-DlUIW-7z.js} +1 -1
- package/dist/{WDYDFRGG-BEksfGMC.cjs → WDYDFRGG-N7kNyI7H.cjs} +1 -1
- package/dist/{WDYDFRGG-O9GIrtX0.js → WDYDFRGG-SsaVMSIa.js} +2 -2
- package/dist/{active-in-another-tab-B4Ur0JP7.js → active-in-another-tab-3S4Tzg0v.js} +1 -1
- package/dist/{active-in-another-tab-BPdx4lWh.cjs → active-in-another-tab-C83x4jHw.cjs} +1 -1
- package/dist/{add-new-language-page-CRR93tLq.js → add-new-language-page-BnPnQ-3A.js} +1 -1
- package/dist/{add-new-language-page-BfUp5Ua2.cjs → add-new-language-page-QIaeQ_fJ.cjs} +1 -1
- package/dist/{add-new-page-B8NGK6WS.cjs → add-new-page-Ddoy3kTu.cjs} +1 -1
- package/dist/{add-new-page-Ppy5-y5j.js → add-new-page-aLHfIIHC.js} +1 -1
- package/dist/{ai-panel-default-lang-BXYQye3N.js → ai-panel-default-lang-BOCTOIH_.js} +3 -3
- package/dist/{ai-panel-default-lang-VhgmHFoQ.cjs → ai-panel-default-lang-FNeOfRkj.cjs} +2 -2
- package/dist/{ai-panel-other-lang-DaCf-cq4.js → ai-panel-other-lang-C2j7qGZx.js} +3 -3
- package/dist/{ai-panel-other-lang-Ds0EXeUC.cjs → ai-panel-other-lang-DgRzCQGx.cjs} +1 -1
- package/dist/{ai-prompt-input-nZ5_Dm7X.cjs → ai-prompt-input-SJnya_UU.cjs} +1 -1
- package/dist/{ai-prompt-input-7iWk72w5.js → ai-prompt-input-p5KHwgCW.js} +1 -1
- package/dist/{ai-translation-prompt-1OUs1P7n.js → ai-translation-prompt-BTEXWPQq.js} +1 -1
- package/dist/{ai-translation-prompt-B16cK-1Q.cjs → ai-translation-prompt-Dhh-bNJr.cjs} +1 -1
- package/dist/{change-password-modal-CdvJR1Ln.js → change-password-modal-BkBFwrxi.js} +1 -1
- package/dist/{change-password-modal-D5eXjiYq.cjs → change-password-modal-BwBRdCeD.cjs} +1 -1
- package/dist/{continue-editing-in-this-client-BrSvK-Ay.js → continue-editing-in-this-client-DTmWmAee.js} +1 -1
- package/dist/{continue-editing-in-this-client-Cmi-GkYZ.cjs → continue-editing-in-this-client-DgtsPYZ4.cjs} +1 -1
- package/dist/{delete-page-DLohaU-U.cjs → delete-page-BNZclrjF.cjs} +1 -1
- package/dist/{delete-page-C99K2qzS.js → delete-page-BYh290jY.js} +1 -1
- package/dist/{digital-asset-manager-BZMb6sC7.js → digital-asset-manager-BINMP8H4.js} +1 -1
- package/dist/{digital-asset-manager-Z5aJxkq0.cjs → digital-asset-manager-DnNRvKt8.cjs} +1 -1
- package/dist/{duplicate-page-CDc2X0eW.js → duplicate-page-B_j9rgxU.js} +1 -1
- package/dist/{duplicate-page-D5Gtvqdv.cjs → duplicate-page-DgxKd840.cjs} +1 -1
- package/dist/{dynamic-page-selector-DvNBXo6o.js → dynamic-page-selector-B2HE4wRM.js} +1 -1
- package/dist/{dynamic-page-selector-DZHhX008.cjs → dynamic-page-selector-CDuWB_Yw.cjs} +1 -1
- package/dist/{index-BVwFJWDq.cjs → index-CzBSRTj0.cjs} +3 -3
- package/dist/{index-LBTm1Jmk.js → index-nzqILA37.js} +17 -17
- package/dist/{json-diff-viewer-Cb1CmRqP.cjs → json-diff-viewer-3C7leKFH.cjs} +1 -1
- package/dist/{json-diff-viewer-DG6qMOBS.js → json-diff-viewer-CMw5W_Li.js} +1 -1
- package/dist/{lang-panel-DxoJ0v4y.cjs → lang-panel-DIdkbjDj.cjs} +1 -1
- package/dist/{lang-panel-B3USOxGq.js → lang-panel-S3dD5t_t.js} +2 -2
- package/dist/{mark-as-template-B9yLcasI.cjs → mark-as-template-6kAFYYpY.cjs} +1 -1
- package/dist/{mark-as-template-CP_F9ZQ4.js → mark-as-template-BP6ltrws.js} +1 -1
- package/dist/{no-language-page-content-C-MCdPXt.cjs → no-language-page-content-HjxRSjI0.cjs} +1 -1
- package/dist/{no-language-page-content-D8t5dfgh.js → no-language-page-content-MPJjIXir.js} +1 -1
- package/dist/{no-language-page-dialog-D4QIAHnE.cjs → no-language-page-dialog-CoRH5H9v.cjs} +1 -1
- package/dist/{no-language-page-dialog-C_fHI2zI.js → no-language-page-dialog-D06JM3cU.js} +2 -2
- package/dist/{page-creator-DKEkuGCO.js → page-creator-Cu6i7LZ1.js} +134 -134
- package/dist/page-creator-QCmVlpyE.cjs +1 -0
- package/dist/{page-lock-DdCvtA-I.cjs → page-lock-D5BkmYCP.cjs} +1 -1
- package/dist/{page-lock-CwZKJ4IE.js → page-lock-csXU_vk5.js} +2 -2
- package/dist/{page-locked-dialog-CrTDBoC4.cjs → page-locked-dialog-BfmE52P5.cjs} +1 -1
- package/dist/{page-locked-dialog-DqLlooUz.js → page-locked-dialog-o9eCXo2g.js} +1 -1
- package/dist/{page-manager-new-ttsrxdW9.js → page-manager-new-CwYu8Am_.js} +2 -2
- package/dist/{page-manager-new-ah6QYar2.cjs → page-manager-new-KUeOWmce.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-D7AupT6_.cjs → page-manager-search-and-filter-BE7w_2hv.cjs} +1 -1
- package/dist/{page-manager-search-and-filter-bsqZ6wnI.js → page-manager-search-and-filter-BwxrJZgv.js} +1 -1
- package/dist/{page-revisions-content-C5O8_Fms.js → page-revisions-content-DmXFnqRE.js} +2 -2
- package/dist/{page-revisions-content-B6hsIla7.cjs → page-revisions-content-qIljNtcN.cjs} +1 -1
- package/dist/pages.cjs +1 -1
- package/dist/pages.js +1 -1
- package/dist/{publish-pages-content-KZVMHT6V.js → publish-pages-content-BmaVd0qz.js} +2 -2
- package/dist/{publish-pages-content-BrajJUcP.cjs → publish-pages-content-gMEMzV-_.cjs} +1 -1
- package/dist/{save-to-lib-DMnv7ENo.js → save-to-lib-CPqQG37K.js} +1 -1
- package/dist/{save-to-lib-Dc700Aop.cjs → save-to-lib-DMPQDhKe.cjs} +1 -1
- package/dist/{selected-block-display-CidmQ-wz.js → selected-block-display-C7iOI7Wd.js} +1 -1
- package/dist/{selected-block-display-CAFEOrLV.cjs → selected-block-display-CSYAaqzP.cjs} +1 -1
- package/dist/{seo-panel-CMY-adM-.cjs → seo-panel-CgDo_uDs.cjs} +1 -1
- package/dist/{seo-panel-Br8gxDxu.js → seo-panel-DUVBUbG3.js} +1 -1
- package/dist/{shared-json-ld-CMH-eRUq.cjs → shared-json-ld-Clk0cKIp.cjs} +1 -1
- package/dist/{shared-json-ld-uvMmwCYp.js → shared-json-ld-nS_mdAYR.js} +1 -1
- package/dist/{take-over-request-KdR1_h_K.js → take-over-request-Bjyi22us.js} +1 -1
- package/dist/{take-over-request-IRLgF1dG.cjs → take-over-request-GdscXVYh.cjs} +1 -1
- package/dist/{unmark-as-template-C5ovsEBP.js → unmark-as-template-BStQtwjr.js} +1 -1
- package/dist/{unmark-as-template-F7TdgWjI.cjs → unmark-as-template-D_-Bbbl_.cjs} +1 -1
- package/dist/{unpublish-page-CUr8Xub6.cjs → unpublish-page-CGZWa57H.cjs} +1 -1
- package/dist/{unpublish-page-0fR1o0b7.js → unpublish-page-Dsqk_IA1.js} +1 -1
- package/dist/{web-preview-D9pXonAv.js → web-preview-_TrLPhaZ.js} +1 -1
- package/dist/{web-preview-CuMYekVJ.cjs → web-preview-e2NMKzzH.cjs} +1 -1
- package/package.json +1 -1
- package/dist/page-creator-Cz_ah-qE.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),v=require("./register-chai-top-bar-DyW9GPzV.cjs"),a=require("./index-DCJDQs1a.cjs"),o=require("react"),_=require("./slug-input-CiHC5l3r.cjs"),w=require("lodash-es"),N=require("lucide-react"),k=require("./index-CzBSRTj0.cjs"),je=require("@tanstack/react-query"),J=require("sonner"),fe=require("./get-seo-defaults-Cw7vFt-B.cjs");function Ue({value:t,onChange:c,placeholder:j="Enter custom slug part",dynamicPattern:p,onValidationChange:i}){const[f,m]=o.useState(null),h=o.useRef(null),[g,T]=o.useState(p+t);o.useEffect(()=>{T(p+t)},[t,p]);const O=S=>{const C=S.target.value;if(!C.startsWith(p)){const W=C.replace(p,""),G=p+W;T(G),c(W);return}const l=C.substring(p.length).replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),n=(l.match(/\./g)||[]).length,x=n<=1;n>1?m("Invalid slug. Only one dot (.) is allowed in the slug"):m(null),i&&i(x);const y=p+l;T(y),c(l)},b=()=>{if(h.current){const S=h.current;setTimeout(()=>{const C=p.length;S.setSelectionRange(C,C)},0)}},R=S=>{const C=S.currentTarget;(C.selectionStart||0)<=p.length&&setTimeout(()=>{const l=p.length;C.setSelectionRange(l,l)},0)};return e.jsx("div",{children:e.jsxs("div",{className:"relative",children:[e.jsxs("p",{className:"mb-2 text-xs text-gray-500",children:[`${p}`," is a dynamic segment of slug"]}),e.jsx(v.Input,{ref:h,value:g,onChange:O,onFocus:b,onClick:R,placeholder:j,className:f?"border-red-500":""}),f&&e.jsx("div",{className:"mt-1 text-xs text-red-500",children:f})]})})}const X=({children:t,onWheel:c,...j})=>{const p=i=>{try{i.preventDefault();const f=i.currentTarget;f.scrollTop+=i.deltaY}catch{i.preventDefault()}c&&c(i)};return e.jsx(a.CommandList,{...j,onWheel:p,children:t})},te=(...t)=>t.filter(Boolean).join(" ");function ze({pages:t,selectedParentId:c,onChange:j,className:p,id:i="parentPage",currentPage:f}){const[m,h]=o.useState(!1),[g,T]=o.useState(""),O=v.useChaiFeatureFlag("enable-add-page-dropdown");O||(p="w-full rounded-md border border-gray-300 px-3 py-2");const b=o.useMemo(()=>!t||t.length===0?[]:t.filter(x=>!w.isEmpty(x.slug)).filter(x=>x.slug!=="/").sort((x,y)=>x.slug.localeCompare(y.slug)),[t]),R=o.useMemo(()=>{if(!g.trim())return b;const n=g.toLowerCase();return b.filter(x=>x.name.toLowerCase().includes(n)||x.slug.toLowerCase().includes(n))},[b,g]),S=n=>Math.max(0,(n.match(/\//g)||[]).length-1),C=n=>" ".repeat(n),d=n=>{if(n==="/")return"/";const x=n.split("/").filter(Boolean);if(x.length<=1){const y=x[0]||"";return`/${_.removeSlugExtension(y)}`}return`/${_.removeSlugExtension(x[x.length-1])}`},l=()=>{if(!c||c==="none")return"None";const n=b.find(x=>x.id===c);return n?`${n.name} (${d(n.slug)})`:"None"};return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:i,className:"text-sm",children:"Parent"}),O?e.jsxs(a.Popover,{open:m,onOpenChange:h,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(v.Button,{id:i,variant:"outline",role:"combobox",className:te("w-full justify-between",p),"data-testid":"parent-page-selector",children:[l(),e.jsx(N.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(a.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"relative border-none py-2",children:e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(N.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(v.Input,{placeholder:"Search pages...",className:"h-8 pl-8 text-xs",value:g,onChange:n=>T(n.target.value)})]})})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(a.CommandEmpty,{children:"No pages found."}),e.jsxs(a.CommandGroup,{children:[e.jsxs(a.CommandItem,{value:"none",onSelect:()=>{j(""),h(!1),T("")},className:"flex cursor-pointer items-center justify-between",children:[e.jsx("span",{children:"None"}),e.jsx(N.Check,{className:te("mr-2 h-4 w-4",c?"opacity-0":"opacity-100")})]}),R.map(n=>{const x=C(S(n.slug)),y=d(n.slug),W=e.jsxs("span",{className:"flex items-center text-sm",children:[x,n.name,e.jsxs("span",{className:"text-xs text-gray-500",children:[" (",y,")"]})]});return e.jsxs(a.CommandItem,{value:n.id,onSelect:()=>{j(n.id),h(!1),T("")},className:"flex cursor-pointer items-center justify-between whitespace-pre-wrap",children:[e.jsx("span",{children:W}),e.jsx(N.Check,{className:te("mr-2 h-4 w-4 shrink-0",c===n.id?"opacity-100":"opacity-0")})]},n.id)})]})]})]})})]}):e.jsxs("select",{id:i,value:c||"none",onChange:n=>j(n.target.value),className:p,"data-testid":"parent-page-selector",children:[e.jsx("option",{value:"none",children:"None"}),b.map(n=>{const x=S(n.slug),y=x>0?C(x):"",W=d(n.slug);return(f==null?void 0:f.id)&&(f.id===n.id||n.slug.startsWith(f.slug+"/"))?null:e.jsxs("option",{value:n.id,children:[y,n.name," (",W,")"]},n.id)})]})]})}const _e=(...t)=>t.filter(Boolean).join(" "),Ve=({templates:t,selectedTemplateId:c,onSelectTemplate:j,isLoading:p=!1})=>{const[i,f]=o.useState(""),[m,h]=o.useState(!1),[g,T]=o.useState(""),O=v.useChaiFeatureFlag("enable-add-page-dropdown");if(o.useEffect(()=>{if(c){const d=t.find(l=>l.id===c);o.startTransition(()=>f((d==null?void 0:d.preview)||""))}else o.startTransition(()=>f(""))},[c,t]),p)return e.jsx("div",{className:"flex h-fit items-center justify-center text-sm text-gray-500",children:"Loading templates..."});if(t.length===0)return null;const b={};t.forEach(d=>{const l=d.libraryName;b[l]||(b[l]=[]),b[l].push(d)});const R=Object.entries(b).reduce((d,[l,n])=>{const x=n.filter(y=>y.name.toLowerCase().includes(g.toLowerCase())||l.toLowerCase().includes(g.toLowerCase()));return x.length>0&&(d[l]=x),d},{}),S=t.find(d=>d.id===c),C=S?w.startCase(S.name):"No Template";return e.jsxs("div",{className:"space-y-4",children:[O?e.jsxs(a.Popover,{open:m,onOpenChange:h,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(v.Button,{variant:"outline",role:"combobox",className:"w-full justify-between",children:[C,e.jsx(N.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(a.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(N.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(v.Input,{placeholder:"Search templates...",className:"h-8 pl-8 text-xs",value:g,onChange:d=>T(d.target.value)})]})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(a.CommandEmpty,{children:"No templates found."}),Object.entries(R).map(([d,l])=>e.jsx(a.CommandGroup,{heading:d,children:l.map(n=>e.jsxs(a.CommandItem,{value:n.id,onSelect:()=>{j(n.id),h(!1),T("")},className:"flex cursor-pointer items-center justify-between",children:[w.startCase(n.name),e.jsx(N.Check,{className:_e("mr-2 h-4 w-4",c===n.id?"opacity-100":"opacity-0")})]},n.id))},d))]})]})})]}):e.jsxs("select",{className:"w-full rounded-md border border-gray-300 px-3 py-2",value:c,onChange:d=>j(d.target.value),children:[e.jsx("option",{value:"",children:"No Template"}),Object.entries(b).map(([d,l])=>e.jsx("optgroup",{label:d,children:l.map(n=>e.jsx("option",{value:n.id,children:w.startCase(n.name)},n.id))},d))]}),i&&e.jsxs("div",{className:"mt-3 overflow-hidden rounded border",children:[e.jsx("div",{className:"max-h-[200px] overflow-auto",children:e.jsx("img",{src:i,alt:"Template Preview",className:"w-full object-contain"})}),e.jsx("div",{className:"border-t bg-gray-50 p-2 text-xs text-gray-500",children:"Template preview"})]})]})},$e=()=>{const t=k.useApiUrl(),c=k.useFetch();return je.useQuery({queryKey:[k.ACTIONS.GET_LIBRARIES],staleTime:"static",queryFn:async()=>await c(t,{action:k.ACTIONS.GET_LIBRARIES})||[]})},Qe=t=>{const c=k.useApiUrl(),j=k.useFetch();return je.useQuery({queryKey:[k.ACTIONS.GET_TEMPLATES_BY_TYPE,t],staleTime:"static",enabled:!!t,queryFn:async()=>{const p=await j(c,{action:k.ACTIONS.GET_TEMPLATES_BY_TYPE,data:{pageType:t}});return(t?w.filter(p,{pageType:t}):p)||[]}})},Ye=t=>{const{data:c=[],isLoading:j}=Qe(t),{data:p=[],isLoading:i}=$e(),f=o.useMemo(()=>j||i?[]:c.map(h=>{const g=w.find(p,{id:h.library});return{...h,libraryName:(g==null?void 0:g.type)!=="shared"?"Site Library":(g==null?void 0:g.name)+" Library",libraryType:g==null?void 0:g.type}}),[c,p,j,i]),m=o.useMemo(()=>w.groupBy(f,"libraryName"),[f]);return{data:f,groupedData:m,isLoading:j||i}},z=(...t)=>t.filter(Boolean).join(" ");function He({addEditPage:t,close:c,closePanel:j}){var xe,ge;const{data:p}=k.usePageTypes(),i=o.useMemo(()=>p??[],[p]),f=k.useChangePage(),m=!!(t!=null&&t.id),{data:h}=k.useWebsitePrimaryPages(),{mutate:g,isPending:T}=k.useCreatePage(),{mutate:O,isPending:b}=k.useUpdatePage(),[R,S]=o.useState(null),[C,d]=o.useState(!0),[l,n]=o.useState((t==null?void 0:t.pageType)??"page"),{hasPermission:x}=a.usePermissions(),y=x(k.PAGES_PERMISSIONS.CHANGE_PAGE_TYPE),[W,G]=o.useState(!1),[ye,ve]=o.useState(""),{selectedLang:Se,fallbackLang:Ce}=a.useLanguages(),ne=Se||Ce,[V,H]=o.useState(""),[ae,Q]=o.useState(!1),le=o.useMemo(()=>{const s=i.find(u=>u.key===l);return(s==null?void 0:s.hasSlug)===!1},[l,i]),[D,Ne]=o.useState((t==null?void 0:t.parent)??""),[M,re]=o.useState((t==null?void 0:t.name)??""),[F,oe]=o.useState((t==null?void 0:t.dynamic)??!1),[B,Y]=o.useState(F?"":((t==null?void 0:t.slug)??"").split("/").pop()||""),[ie,ce]=o.useState((t==null?void 0:t.dynamicSlugCustom)??""),[ue,be]=o.useState(!0),[we,P]=o.useState(!1),[E,ke]=o.useState(""),{data:me,isLoading:Le}=Ye(l),$=T||b,he=v.useChaiFeatureFlag("enable-add-page-dropdown"),ee=o.useMemo(()=>!m||!(t!=null&&t.id)||!h?null:h.find(s=>s.id===t.id),[m,t==null?void 0:t.id,h]),Te=(ee==null?void 0:ee.online)||!1,De=o.useMemo(()=>!m||!(t!=null&&t.id)||!h?!1:h.some(s=>s.parent===t.id),[m,t==null?void 0:t.id,h]),r=i.find(s=>s.key===l),U=s=>{if(m&&l!==s){ve(s),G(!0),H(""),Q(!1);return}n(s),H(""),Q(!1)},pe=()=>{n(ye),G(!1),oe(!1)},Ie=s=>{oe(s),s?Y(""):ce("")},Fe=s=>{if(Ne(s),s&&s!=="none"){const u=h==null?void 0:h.find(L=>L.id===s),q=(u==null?void 0:u.slug)||"";if(B.startsWith(q)){const L=B.slice(q.length).replace(/^\/+/,"");Y(L)}else Y(B.replace(/^\/+/,""))}else Y(B?`${B}`:"")},Be=s=>{ke(s)},qe=()=>M.trim()?F&&!w.isEmpty(B)?(S("Slug must be empty when using dynamic slug"),!1):F&&!ue?(S("Dynamic slug is invalid"),!1):!0:(J.toast.error("Name is required"),!1),Ae=()=>{const s={pageType:r==null?void 0:r.key,name:M,slug:"",hasSlug:!1};m?O({id:t==null?void 0:t.id,name:M},{onSuccess:()=>{J.toast.success((r==null?void 0:r.name)+" updated successfully"),c()}}):g(s,{onSuccess:u=>{c(),f(u.page.id,j)}})},Oe=(s,u)=>{if(!s.trim()&&!F)return S("Child page slug is required"),!1;const q=_.removeSlugExtension(u),L=_.combineParentChildSlugs(q,s);return Object.keys(k.LANGUAGES).some(Z=>L===`/${Z}`||(L==null?void 0:L.startsWith(`/${Z}/`)))?(S("Slugs cannot start with a language code for primary page"),!1):!0},We=(s,u)=>{const q=_.removeSlugExtension(u),L=_.combineParentChildSlugs(q,s),I={pageType:l,name:M,slug:L.replace(/\/$/,""),parent:D,dynamic:F,hasSlug:!0,template:E||void 0,tracking:{},seo:{},jsonLD:{}};if(F&&(I.dynamicSlugCustom=ie),m){const A=w.pick(I,["pageType","parent","name","slug","dynamic","dynamicSlugCustom"]);O({id:t==null?void 0:t.id,...A},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}})}else{const A=w.find(i,{key:l});A!=null&&A.trackingDefault&&(I.tracking=A.trackingDefault);const{seo:Z,jsonLD:Ge}=fe.getSeoDefaults(A,ne);w.set(I,"seo",Z),w.set(I,"jsonLD",Ge),g(I,{onSuccess:Me=>{c(),f(Me.page.id,j)}})}},Re=()=>{const s={pageType:l,name:M,slug:B===""?"/":`/${B.replace(/\/$/,"")}`,template:E||void 0,parent:null,tracking:{}};if(m)O({id:t==null?void 0:t.id,...s},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}});else{const u=w.find(i,{key:l});u!=null&&u.trackingDefault&&(s.tracking=u.trackingDefault);const{seo:q,jsonLD:L}=fe.getSeoDefaults(u,ne);w.set(s,"seo",q),w.set(s,"jsonLD",L),g(s,{onSuccess:I=>{var A;(A=I==null?void 0:I.page)!=null&&A.id&&f(I.page.id,j),c()}})}},de=s=>{if(s.preventDefault(),S(null),!!qe()){if(!(r!=null&&r.hasSlug)){Ae();return}if(D&&D!=="none"){const u=h==null?void 0:h.find(L=>L.id===D),q=(u==null?void 0:u.slug)||"";if(!Oe(B,q))return;We(B,q)}else Re()}},{pagesType:se,partialsType:K}=o.useMemo(()=>{const s=u=>V?u.name.toLowerCase().includes(V.toLowerCase())||u.key.toLowerCase().includes(V.toLowerCase()):!0;return{pagesType:i.filter(u=>u.hasSlug!==!1&&s(u)),partialsType:i.filter(u=>u.hasSlug===!1&&s(u))}},[i,V]);return r!=null&&r.hasSlug?e.jsxs("form",{onSubmit:de,className:"mx-auto w-full max-w-md space-y-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(a.Popover,{open:ae,onOpenChange:Q,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(v.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:z("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(N.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(a.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(N.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(v.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:V,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"overflow-y-auto",children:[e.jsx(a.CommandEmpty,{children:"No page type found."}),m?le?e.jsx(a.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>U(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsx(a.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>U(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsxs(e.Fragment,{children:[se.length>0&&e.jsx(a.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>U(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}),K.length>0&&e.jsx(a.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>U(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))})]})]})]})})]}):e.jsx("select",{id:"pageType",value:l,disabled:m&&!y,onChange:s=>U(s.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${m&&!y?"cursor-not-allowed text-gray-500":""}`,children:m?le?e.jsx("optgroup",{label:"Partials",children:i.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsx("optgroup",{label:"Pages",children:i.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsxs(e.Fragment,{children:[e.jsx("optgroup",{label:"Pages",children:i.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}),e.jsx("optgroup",{label:"Partials",children:i.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})]})}),W&&e.jsxs("div",{className:"mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3",children:[e.jsx("p",{className:"text-sm text-yellow-800",children:"Changing the page type may impact the page data. Are you sure you want to proceed?"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(v.Button,{variant:"outline",size:"sm",onClick:()=>G(!1),children:"Cancel"}),e.jsx(v.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]})]}),!m&&(r==null?void 0:r.hasSlug)&&me.length>0&&e.jsxs("div",{className:"space-y-1",children:[e.jsx(a.Label,{className:"mb-1 block text-sm",children:"Template"}),e.jsx(Ve,{templates:me,selectedTemplateId:E,onSelectTemplate:Be,isLoading:Le})]}),e.jsx(ze,{pages:h,selectedParentId:D,onChange:Fe,currentPage:t}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(v.Input,{id:"name",value:M,onChange:s=>re(s.target.value),required:!0,"aria-required":"true",placeholder:"Enter page name"})]}),(r==null?void 0:r.dynamicSegments)&&D&&D!=="none"&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"useDynamicSlug",checked:F,onChange:s=>Ie(s.target.checked),className:"rounded border-gray-300"}),e.jsx(a.Label,{htmlFor:"useDynamicSlug",className:"text-sm",children:"Use Dynamic Slug"})]}),F&&e.jsx("div",{className:"space-y-2",children:e.jsx("div",{className:"space-y-0.5",children:e.jsx(Ue,{value:ie,onChange:ce,dynamicPattern:(r==null?void 0:r.dynamicSlug)||"{{id}}",placeholder:"Enter custom slug part (optional)",onValidationChange:be})})})]}),(!(r!=null&&r.dynamicSegments)||!F)&&e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),e.jsx(_.SlugInput,{value:B,onChange:s=>{var u;Y(s),m&&s!==(((u=t==null?void 0:t.slug)==null?void 0:u.split("/").pop())||"")?P(!!(Te||De)):P(!1)},placeholder:D&&D!=="none"?"Enter page slug":l==="page"?"Leave empty for home page":"Required - e.g. your-slug",parentSlug:D&&D!=="none"?(ge=h==null?void 0:h.find(s=>s.id===D))==null?void 0:ge.slug:void 0,onValidationChange:d}),R&&e.jsx("p",{className:"text-xs text-red-500",children:R}),we&&e.jsx("div",{className:"mt-4 rounded-md border border-amber-200 bg-amber-50 p-3",children:e.jsxs("div",{className:"flex items-start space-x-2",children:[e.jsx("div",{className:"flex-shrink-0",children:e.jsx("svg",{className:"h-5 w-5 text-amber-400",viewBox:"0 0 20 20",fill:"currentColor",children:e.jsx("path",{fillRule:"evenodd",d:"M8.257 3.099c.765-1.36 2.722-1.36 3.486 0l5.58 9.92c.75 1.334-.213 2.98-1.742 2.98H4.42c-1.53 0-2.493-1.646-1.743-2.98l5.58-9.92zM11 13a1 1 0 11-2 0 1 1 0 012 0zm-1-8a1 1 0 00-1 1v3a1 1 0 002 0V6a1 1 0 00-1-1z",clipRule:"evenodd"})})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"text-sm font-medium text-amber-800",children:"Slug Change Warning"}),e.jsx("div",{className:"mt-1 text-sm text-amber-700",children:e.jsx("p",{children:"The previous URL and any child pages will become inaccessible. You may want to set up a redirect to avoid broken links."})})]})]})})]}),e.jsx(v.Button,{disabled:$||!C&&(!(r!=null&&r.dynamicSegments)||!F)||F&&!ue,type:"submit",className:"w-full",children:m?$?"Updating...":"Update page":$?"Creating...":"Create Page"})]}):e.jsxs("form",{onSubmit:de,className:"mx-auto w-full max-w-md space-y-4",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(a.Popover,{open:ae,onOpenChange:Q,children:[e.jsx(a.PopoverTrigger,{asChild:!0,children:e.jsxs(v.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:z("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(N.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(a.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(a.Command,{shouldFilter:!1,children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white px-3 py-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(N.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(v.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:V,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"max-h-[200px] overflow-y-auto",children:[e.jsx(a.CommandEmpty,{children:"No page type found."}),e.jsx(a.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(a.CommandItem,{value:s.key,onSelect:()=>{U(s.key),Q(!1)},className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(N.Check,{className:z("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))})]})]})})]}):e.jsx("select",{id:"pageType",value:l,disabled:m&&!y,onChange:s=>U(s.target.value),className:`w-full rounded-md border border-gray-300 px-3 py-2 ${m&&!y?"cursor-not-allowed text-gray-500":""}`,children:e.jsx("optgroup",{label:"Partials",children:i.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})}),W&&e.jsxs("div",{className:"mt-2 rounded-md border border-yellow-200 bg-yellow-50 p-3",children:[e.jsx("p",{className:"text-sm text-yellow-800",children:"Changing the page type may impact the page data. Are you sure you want to proceed?"}),e.jsxs("div",{className:"mt-2 flex gap-2",children:[e.jsx(v.Button,{variant:"outline",size:"sm",onClick:()=>G(!1),children:"Cancel"}),e.jsx(v.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:(xe=i.find(s=>s.key===l))==null?void 0:xe.helpText})]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(v.Input,{id:"name",value:M,onChange:s=>re(s.target.value),required:!0,"aria-required":"true"})]}),e.jsx(v.Button,{disabled:$,type:"submit",className:"w-full",children:m?$?"Updating...":"Update "+(r==null?void 0:r.name):$?"Creating...":"Create "+(r==null?void 0:r.name)})]})}exports.default=He;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("react/jsx-runtime"),e=require("./index-CzBSRTj0.cjs"),E=require("@tanstack/react-query"),r=require("react"),c=r.lazy(()=>Promise.resolve().then(()=>require("./take-over-request-GdscXVYh.cjs"))),o=r.lazy(()=>Promise.resolve().then(()=>require("./page-locked-dialog-BfmE52P5.cjs"))),l=r.lazy(()=>Promise.resolve().then(()=>require("./active-in-another-tab-C83x4jHw.cjs"))),S=r.lazy(()=>Promise.resolve().then(()=>require("./continue-editing-in-this-client-DgtsPYZ4.cjs"))),s=n=>u.jsx(r.Suspense,{children:u.jsx(n,{})}),A=({isFetchingPageData:n})=>{e.useChaibuilderRealtime();const{pageStatus:t}=e.usePageLockStatus(),{pageLockMeta:a}=e.usePageLockMeta(),T=E.useQueryClient(),i=r.useRef(t);if(r.useEffect(()=>{t===e.PAGE_STATUS.EDITING&&i.current!==e.PAGE_STATUS.TAKE_OVER_REQUESTED&&T.invalidateQueries({queryKey:[e.ACTIONS.GET_DRAFT_PAGE]}),i.current=t},[t,T]),n)return null;switch(t){case e.PAGE_STATUS.EDITING:case e.PAGE_STATUS.CHECKING:case e.PAGE_STATUS.FORCE_TAKE_OVER:return a.type===e.EVENT.CONTINUE_EDITING_IN_THIS_CLIENT?s(S):null;case e.PAGE_STATUS.LOCKED:return s(o);case e.PAGE_STATUS.TAKE_OVER_REQUESTED:return s(c);case e.PAGE_STATUS.ACTIVE_IN_ANOTHER_TAB:return s(l);case e.PAGE_STATUS.CONNECTION_LOST:return u.jsx(e.BlurContainer,{children:null});default:return null}};exports.default=A;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as n } from "react/jsx-runtime";
|
|
2
|
-
import { u as E, a as c, b as T, P as e, A as l, B as I, E as _ } from "./index-
|
|
2
|
+
import { u as E, a as c, b as T, P as e, A as l, B as I, E as _ } from "./index-nzqILA37.js";
|
|
3
3
|
import { useQueryClient as C } from "@tanstack/react-query";
|
|
4
4
|
import { useRef as p, useEffect as N, Suspense as A, lazy as s } from "react";
|
|
5
|
-
const m = s(() => import("./take-over-request-
|
|
5
|
+
const m = s(() => import("./take-over-request-Bjyi22us.js")), f = s(() => import("./page-locked-dialog-o9eCXo2g.js")), O = s(() => import("./active-in-another-tab-3S4Tzg0v.js")), S = s(() => import("./continue-editing-in-this-client-DTmWmAee.js")), r = (a) => /* @__PURE__ */ n(A, { children: /* @__PURE__ */ n(a, {}) }), L = ({ isFetchingPageData: a }) => {
|
|
6
6
|
E();
|
|
7
7
|
const { pageStatus: t } = c(), { pageLockMeta: o } = T(), u = C(), i = p(t);
|
|
8
8
|
if (N(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("./index-DCJDQs1a.cjs"),p=require("./register-chai-top-bar-DyW9GPzV.cjs"),t=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("./index-DCJDQs1a.cjs"),p=require("./register-chai-top-bar-DyW9GPzV.cjs"),t=require("./index-CzBSRTj0.cjs"),c=require("lucide-react"),d=require("react"),O=require("react-i18next"),_=()=>{const m=t.useCurrentPageOwner(),f=t.useSendRealtimeEvent(),{setPageStatus:j}=t.usePageLockStatus(),{data:s,isFetching:v}=t.useChaiUserInfo((m==null?void 0:m.userId)||""),{pageLockMeta:o,setPageLockMeta:g}=t.usePageLockMeta(),{t:r}=O.useTranslation(),[u,i]=d.useState(""),[a,N]=d.useState({}),[T,k]=d.useState(!1),l=d.useRef(null);d.useEffect(()=>{o!=null&&o.type&&(l.current&&clearTimeout(l.current),d.startTransition(()=>{N(o),g({}),i("")}))},[o,g]);const b=()=>{u!==t.EVENT.TAKE_OVER_REQUEST&&(i(t.EVENT.TAKE_OVER_REQUEST),f(t.EVENT.TAKE_OVER_REQUEST),l.current=setTimeout(()=>i(""),2e4))},R=()=>{u!==t.EVENT.FORCE_TAKE_OVER_REQUEST&&(i(t.EVENT.FORCE_TAKE_OVER_REQUEST),f(t.EVENT.FORCE_TAKE_OVER_REQUEST),j(t.PAGE_STATUS.CHECKING),l.current=setTimeout(()=>i(""),2e4))},y=()=>{N({}),l.current&&clearTimeout(l.current),i("")},x=v?"Loading...":(s==null?void 0:s.name)||"Current editor",h=u===t.EVENT.TAKE_OVER_REQUEST,E=u===t.EVENT.FORCE_TAKE_OVER_REQUEST;return e.jsx(t.BlurContainer,{children:e.jsxs(n.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(n.CardHeader,{className:"space-y-1 border-b pb-3",children:e.jsxs(n.CardTitle,{className:"flex items-center gap-2 text-xl",children:[e.jsx(c.LockKeyhole,{className:"h-8 w-8 rounded-md bg-sky-500/20 p-1.5 text-sky-500"}),e.jsx("span",{children:r("Page Locked for Editing")})]})}),e.jsxs(n.CardContent,{className:"space-y-4 p-4",children:[e.jsxs("div",{className:"relative rounded-md border border-green-500 px-2 pb-2 pt-4",children:[e.jsx("div",{className:"absolute -top-2.5 left-3 w-max rounded-full bg-green-500 px-3 py-1 text-xs font-medium leading-3 text-white",children:"Current Editor"}),e.jsxs("div",{className:"flex items-center space-x-4 p-1",children:[s!=null&&s.avatar?e.jsx("img",{src:s.avatar,alt:s.name,className:"h-12 w-12 flex-shrink-0 rounded-full bg-black text-white"}):e.jsx(c.UserIcon,{className:"h-12 w-12 flex-shrink-0 rounded-full bg-black p-3 text-white"}),e.jsxs("div",{className:"flex-1 space-y-0",children:[e.jsx("div",{className:"truncate font-medium leading-tight text-black",children:x}),(s==null?void 0:s.email)&&e.jsx("p",{className:"truncate text-sm leading-tight text-muted-foreground",children:s.email})]})]})]}),((a==null?void 0:a.type)===t.EVENT.TAKE_OVER_REJECTED||(a==null?void 0:a.type)===t.EVENT.FORCE_TAKE_OVER_REQUEST)&&e.jsx("section",{className:"space-y-2",children:e.jsxs("div",{className:"flex items-center justify-between gap-x-2 rounded border border-red-500 bg-red-500/10 py-2 pl-3 pr-2 text-sm font-medium text-red-500",children:[e.jsxs("div",{className:"flex items-start gap-x-2",children:[e.jsx(c.AlertCircleIcon,{className:"mt-px flex h-4 w-4 shrink-0"}),e.jsxs("div",{className:"font-light leading-tight",children:[e.jsx("span",{className:"font-medium",children:(s==null?void 0:s.name)||"The current editor"}),(a==null?void 0:a.type)===t.EVENT.TAKE_OVER_REJECTED?" rejected your take over request.":" forcefully took over this page."]})]}),e.jsx(p.Button,{size:"icon",variant:"ghost",onClick:y,className:"flex-shrink-0",children:e.jsx(c.X,{className:"h-4 w-4"})})]})})]}),e.jsx(n.CardFooter,{className:"flex flex-col gap-3 border-t pt-3",children:e.jsxs("section",{className:"space-y-2",children:[e.jsx("h3",{className:"text-xs font-semibold uppercase tracking-wide text-muted-foreground",children:r("Take Over Options")}),e.jsxs("div",{className:"rounded-md border bg-muted/40 p-3",children:[e.jsxs("div",{className:"mb-2",children:[e.jsx("p",{className:"text-sm font-medium",children:r("Take Over Request:")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:r("Send a request to {{currentEditorName}} asking them to release the page. They can accept or decline your request.",{currentEditorName:x})})]}),e.jsxs(p.Button,{disabled:h,variant:"default",onClick:b,className:"mt-3 w-full gap-2",children:[e.jsx(c.Edit,{className:"h-4 w-4"}),h?"Take over request sent":"Send Take Over Request"]}),h&&e.jsx("p",{className:"mt-2 text-xs text-muted-foreground",children:r("Request sent. If no response, try again or use force take over.")})]}),e.jsx(n.Accordion,{type:"single",collapsible:!0,className:"w-full",children:e.jsxs(n.AccordionItem,{value:"force-takeover",className:"rounded-md border border-destructive/40 bg-destructive/5",children:[e.jsx(n.AccordionTrigger,{className:"px-3 py-2 hover:no-underline",children:e.jsx("div",{className:"flex items-center gap-2 text-left",children:e.jsxs("div",{children:[e.jsxs("p",{className:"flex items-center gap-x-2 text-sm font-medium text-destructive",children:[e.jsx(c.ShieldAlert,{className:"h-4 w-4 text-destructive"}),r("Force Take Over")]}),e.jsx("p",{className:"pl-6 text-xs font-normal leading-tight text-muted-foreground",children:r("Immediately take control (use with caution)")})]})})}),e.jsx(n.AccordionContent,{className:"px-3 pb-3",children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-destructive/40 bg-background p-2",children:[e.jsx("input",{type:"checkbox",id:"force-takeover",checked:T,onChange:C=>k(C.target.checked),className:"mt-0.5 h-4 w-4 rounded border-gray-300"}),e.jsx("label",{htmlFor:"force-takeover",className:"flex-1 text-xs text-muted-foreground",children:r("I understand this will immediately close the editor for {{currentEditorName}}. I am using this option with caution.",{currentEditorName:x})})]}),e.jsxs(p.Button,{disabled:!T||E,variant:"destructive",onClick:R,className:"w-full gap-2",children:[e.jsx(c.ShieldAlert,{className:"h-4 w-4"}),r(E?"Take over page...":"Force Take Over")]}),E&&e.jsx("p",{className:"text-xs text-muted-foreground",children:r("Attempting to forcefully take over this page. Please wait while we update the editing session.")})]})})]})})]})})]})})};exports.default=_;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as e, jsxs as t } from "react/jsx-runtime";
|
|
2
2
|
import { J as _, K as w, M as A, O as S, Q as K, R as F, U, V, W as I } from "./index-OuHV9Ann.js";
|
|
3
3
|
import { B as p } from "./register-chai-top-bar-D6GjnauV.js";
|
|
4
|
-
import { ap as Q, an as q, a as P, ao as j, b as B, B as D, E as a, P as J } from "./index-
|
|
4
|
+
import { ap as Q, an as q, a as P, ao as j, b as B, B as D, E as a, P as J } from "./index-nzqILA37.js";
|
|
5
5
|
import { LockKeyhole as L, UserIcon as G, AlertCircleIcon as H, X as z, Edit as W, ShieldAlert as v } from "lucide-react";
|
|
6
6
|
import { useState as f, useRef as X, useEffect as Y, startTransition as Z } from "react";
|
|
7
7
|
import { useTranslation as $ } from "react-i18next";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsxs as w, Fragment as q, jsx as t } from "react/jsx-runtime";
|
|
2
2
|
import { d as ie } from "./index-OuHV9Ann.js";
|
|
3
|
-
import { aA as be, aB as ge, ao as ke, i as de, T as D, aR as ve, L as Ne, k as Se, e as Le, c as Ce, au as Ae, aS as Ee, aT as $e } from "./index-
|
|
3
|
+
import { aA as be, aB as ge, ao as ke, i as de, T as D, aR as ve, L as Ne, k as Se, e as Le, c as Ce, au as Ae, aS as Ee, aT as $e } from "./index-nzqILA37.js";
|
|
4
4
|
import { u as J } from "./use-page-expand-manager-Cf4MUEJw.js";
|
|
5
5
|
import { compact as ue, filter as F, isEmpty as k, uniqBy as Te, keyBy as me, mapValues as Me, startCase as Ue, toLower as T, includes as _, get as R, find as W, map as Ie } from "lodash-es";
|
|
6
6
|
import { atom as Be, useAtom as Fe, useSetAtom as ze } from "jotai";
|
|
@@ -265,7 +265,7 @@ const ce = (e, s) => !e || !Array.isArray(e) ? [] : k(s) ? e : ue(
|
|
|
265
265
|
}
|
|
266
266
|
)
|
|
267
267
|
] }, x.id)) });
|
|
268
|
-
}, rt = M(() => import("./page-manager-search-and-filter-
|
|
268
|
+
}, rt = M(() => import("./page-manager-search-and-filter-BwxrJZgv.js")), ot = M(() => import("./add-new-page-aLHfIIHC.js")), it = M(() => import("./delete-page-BYh290jY.js")), lt = M(() => import("./duplicate-page-B_j9rgxU.js")), ct = M(() => import("./mark-as-template-BP6ltrws.js")), dt = M(() => import("./unmark-as-template-BStQtwjr.js")), ut = M(() => import("./unpublish-page-Dsqk_IA1.js")), kt = ({ close: e }) => {
|
|
269
269
|
const { t: s } = Qe(), { languages: a, setSelectedLang: n } = ie(), { data: i } = Se(), { data: o, isFetching: f } = Le(), [y, c] = Ce(), { updateForSelectedPage: x, expandPagesOnSearch: m } = J(null), l = de(), p = y.get("page"), [v, P] = N(""), [d, L] = N(null), [U, g] = N(null), [z, O] = N(null), [j, h] = N(null), [A, V] = N(""), [K, Z] = N(null), [ee, te] = N(null), [b, Q] = N(l), [pe, we] = N(!1), ne = ze(Ae), G = pe && b !== l, { data: I, isFetching: ye } = Ee(b), se = le(
|
|
270
270
|
(u) => {
|
|
271
271
|
var r;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),K=require("./index-DCJDQs1a.cjs"),y=require("./index-BVwFJWDq.cjs"),G=require("./use-page-expand-manager-B6XTvk0E.cjs"),n=require("lodash-es"),R=require("jotai"),k=require("lucide-react"),o=require("react"),oe=require("react-i18next"),ie=require("./register-chai-top-bar-DyW9GPzV.cjs"),Z=(e,r)=>!e||!Array.isArray(e)?[]:n.isEmpty(r)?e:n.compact(n.filter(e,a=>{const s=n.toLower(r);return n.includes(n.toLower((a==null?void 0:a.name)||""),s)||n.includes(n.toLower((a==null?void 0:a.slug)||""),s)})),le=(e,r)=>{const a=new Set,s=n.keyBy(e,"id");return r.forEach(c=>{let l=c;for(;l.parent&&s[l.parent];)a.add(l.parent),l=s[l.parent]}),Array.from(a).map(c=>s[c])},O=(e,r,a)=>n.isEmpty(r)?e:e.map(s=>{if(!a(s.pageType))return{...s,shouldExpandOnSearch:!0,children:s.children?O(s.children,r,a):[]};const c=s.children&&s.children.some(l=>n.includes(n.toLower(l.name||""),n.toLower(r))||n.includes(n.toLower(l.slug||""),n.toLower(r)));return{...s,shouldExpandOnSearch:c,children:s.children?O(s.children,r,a):[]}}),ce=e=>{if(!e||!e.length)return[];const r={};e.forEach(s=>{r[s.id]={...s,children:[]}});const a=[];return Object.values(r).forEach(s=>{s.parent&&r[s.parent]?r[s.parent].children.push(s):a.push(s)}),a},ee=e=>!e||!e.length?[]:[...e].sort((a,s)=>(a.name||"").localeCompare(s.name||"")).map(a=>({...a,children:a.children?ee(a.children):[]})),de=(e,r,a,s)=>{if(!e||!e.length)return[];let c=e;if(a!=="all"&&(c=n.compact(n.filter(e,{pageType:a}))),n.isEmpty(r))c=Z(c,r);else{const x=Z(c,r),d=le(e,x);c=n.uniqBy([...x,...d],"id")}const l=ee(ce(c)),p=O(l,r,s),g=n.filter(p,x=>s(x.pageType)).sort((x,d)=>(x.name||"").localeCompare(d.name||"")),u=n.filter(p,x=>!s(x.pageType));let P=[];if(a==="all"){const x=n.keyBy(u,"pageType");P=Object.values(n.mapValues(x,(d,w)=>({...d,id:w,name:n.startCase(w),isPartialGroup:!0,children:p.filter(v=>v.pageType===w)})))}else P=u.sort((x,d)=>(x.name||"").localeCompare(d.name||""));return[...g,...P]},ue=R.atom({pageId:null,position:{x:0,y:0}}),me=({pageId:e,children:r})=>{const[a,s]=R.useAtom(ue),c=o.useRef(null),l=a.pageId===e;o.useEffect(()=>{const u=()=>s({pageId:null,position:{x:0,y:0}});if(l)return document.addEventListener("click",u),()=>document.removeEventListener("click",u)},[l,s]);const p=u=>{u.preventDefault(),u.stopPropagation(),s({pageId:e,position:{x:u.clientX,y:u.clientY}})},g=()=>{const u=`${window.location.pathname}?page=${e}`;window.open(u,"_blank"),s({pageId:null,position:{x:0,y:0}})};return t.jsxs(t.Fragment,{children:[t.jsx("span",{onContextMenu:p,children:r}),l&&t.jsx("div",{ref:c,className:"fixed z-[9999] max-w-[160px] rounded-md border border-gray-200 bg-white",style:{top:a.position.y,left:a.position.x},children:t.jsx("div",{className:"",children:t.jsxs(ie.Button,{variant:"ghost",onClick:g,className:"w-full px-2.5 py-1 text-start text-sm text-gray-700 hover:bg-gray-100",children:[t.jsx(k.ExternalLink,{className:"h-4 w-4"}),"Open in new tab"]})})})]})},he=({page:e})=>{var s,c;const{isExpanded:r,toggleExpanded:a}=G.usePageExpandManager(e==null?void 0:e.id);return t.jsx("button",{onClick:l=>{l.stopPropagation(),a()},disabled:!((s=e==null?void 0:e.children)!=null&&s.length),className:`flex h-[calc(100%-2px)] w-5 items-center justify-center rounded text-gray-400 transition-colors hover:bg-gray-200 hover:px-1 hover:text-gray-500 ${(c=e==null?void 0:e.children)!=null&&c.length?"hover:text-blue-400":"opacity-0"}`,children:t.jsx(k.ChevronRight,{size:12,className:`stroke-[4] transition-transform duration-200 ${r?"rotate-90":""}`})})},xe=({page:e,pageType:r})=>t.jsx("div",{className:"flex h-full items-center justify-center gap-x-1",children:e.dynamic?t.jsx(k.StarsIcon,{size:12,className:"text-yellow-400"}):r!=null&&r.icon?t.jsx("div",{className:"flex h-4 max-h-4 w-4 max-w-4 items-center justify-center stroke-[1] text-slate-500",dangerouslySetInnerHTML:{__html:r.icon}}):r!=null&&r.hasSlug?t.jsx(k.File,{size:12,className:"stroke-[1] text-slate-500"}):t.jsx(k.Hash,{size:12,className:"stroke-[1] text-slate-500"})}),fe=({isOnline:e})=>t.jsx("div",{className:`h-2 w-2 rounded-full ${e?"bg-green-300":"bg-gray-300"}`}),ye=({page:e,pageTypes:r,currentPage:a,onClickAction:s,languagePages:c,selectedLanguage:l,showUntranslatedPages:p})=>{const g=y.useUserId(),{pageToUser:u}=y.usePageToUser(),P=n.get(u,[e==null?void 0:e.id,"userId"]),{data:x}=y.useChaiUserInfo(P),d=x&&g!==P?x==null?void 0:x.name:null,w=y.useFallbackLang(),v=a===e.id,j=o.useMemo(()=>n.find(r,{key:e.pageType}),[r,e.pageType]);let m=n.get(c,e==null?void 0:e.id);m=n.get(m,"lang")===l?m:null;const E=l===w||!!m,A=(m==null?void 0:m.name)||(e==null?void 0:e.name)||"No name";let S=(m==null?void 0:m.slug)||(e==null?void 0:e.slug)||"";const $=S+(e!=null&&e.dynamic?`/${j==null?void 0:j.dynamicSlug}`:"")+(e!=null&&e.dynamicSlugCustom?`${e.dynamicSlugCustom}`:"");if(S.startsWith("/")&&!p){const f=S.split("/").pop();S=S.endsWith(f)&&e.dynamic?"":`/${f}`}const q=o.useMemo(()=>{const f="flex h-7 min-w-0 flex-1 cursor-pointer select-none items-center gap-x-1.5 rounded px-px text-xs duration-300 border-[1px]",C=`${v?"border-primary/30 bg-primary/5":"border-transparent hover:border-gray-200 hover:bg-gray-100"}`;return E?`${f} ${C} ${d?"opacity-60":""}`:`${f} bg-gray-100 opacity-50 group-hover:border-gray-200 border-transparent group-hover:bg-blue-100`},[E,v,d]),I=o.useMemo(()=>{if(e.isPartialGroup)return!1;if(m){if(!m.online||n.isEmpty(m.changes))return!1}else if(e&&(!e.online||n.isEmpty(e.changes)))return!1;return!0},[m,e]);return t.jsxs("div",{className:"group relative",children:[t.jsx(me,{pageId:e.id,children:t.jsxs("div",{onClick:()=>!e.isPartialGroup&&E&&s("select",e==null?void 0:e.id),className:q,children:[t.jsx(he,{page:e}),!e.isPartialGroup&&t.jsx(fe,{isOnline:m?m.online:e.online}),!e.isPartialGroup&&t.jsx(xe,{page:e,pageType:j}),t.jsx(y.Tooltip,{content:A,side:"top",showTooltip:A.length>35,children:t.jsx("span",{className:"max-w-[40%] truncate font-medium text-black",children:A})}),(S||e.dynamic)&&t.jsx(y.Tooltip,{content:$,side:"top",showTooltip:!0,children:t.jsxs("span",{className:"max-w-[40%] truncate font-mono text-xs text-muted-foreground",children:[S,e.dynamic&&(j==null?void 0:j.dynamicSlug)&&t.jsxs("span",{className:"text-xs text-gray-500",children:["/",j==null?void 0:j.dynamicSlug,e.dynamicSlugCustom]})]})}),I&&t.jsx(y.Tooltip,{content:"Has unpublished changes",side:"top",children:t.jsx("span",{className:"text-amber-500",children:t.jsx(k.Pencil,{size:12,className:"stroke-[2]"})})}),!e.isPartialGroup&&E&&!d?t.jsx("div",{className:"duration absolute right-0.5 top-[3px]",children:t.jsx(y.PageActionsDropdown,{isLanguagePage:!!m,page:m||e,setDuplicatePage:f=>s("duplicate",f),setAddEditPage:f=>s("edit",m||f),setUnpublishPage:f=>s("unpublish",f),setDeletePage:f=>s("delete",m||f),children:t.jsx("div",{className:"m-0 cursor-pointer rounded border border-transparent p-0.5 duration-100 hover:border-gray-400 hover:bg-white",children:t.jsx(k.MoreHorizontal,{className:"h-4 w-4",onClick:f=>f.stopPropagation()})})})}):d?t.jsxs("span",{className:"duration absolute right-1.5 top-1/2 flex -translate-y-1/2 items-center gap-x-1 text-xs text-red-500",children:[t.jsx(k.Lock,{className:"h-3 w-3 fill-red-200 text-red-500"}),t.jsx(y.Tooltip,{content:`${d} is editing this page`,children:t.jsx("span",{className:"font-bold",children:d})})]}):null]})}),t.jsx(t.Fragment,{children:!E&&!e.isPartialGroup&&!d&&t.jsxs("button",{onClick:f=>{f.stopPropagation(),s("addLanguagePage",{language:l,page:e})},className:"absolute left-1/2 top-1 flex -translate-x-1/2 items-center gap-x-1 rounded bg-blue-500 px-2 py-0.5 text-xs text-white opacity-0 duration-200 hover:bg-blue-700 group-hover:opacity-100",children:[t.jsx(k.Plus,{size:12,className:"stroke-[3]"})," ",t.jsxs("span",{className:"text-[10px]",children:["Add ",n.get(y.LANGUAGES,l)," Page"]})]})})]})},te=({pages:e,tier:r,pageTypes:a,currentPage:s,onClickAction:c,languagePages:l,selectedLanguage:p,showUntranslatedPages:g})=>{const{expandedPages:u}=G.usePageExpandManager();return t.jsx("div",{className:"space-y-0.5",style:{paddingLeft:`${r*10}px`},children:e.map(P=>t.jsxs(t.Fragment,{children:[t.jsx(ye,{page:P,pageTypes:a,currentPage:s,onClickAction:c,languagePages:l,selectedLanguage:p,showUntranslatedPages:g}),P.children&&P.children.length>0&&(u==null?void 0:u.includes(P.id))&&t.jsx(te,{pages:P.children,tier:r+1,pageTypes:a,currentPage:s,onClickAction:c,languagePages:l,selectedLanguage:p,showUntranslatedPages:g})]},P.id))})},pe=o.lazy(()=>Promise.resolve().then(()=>require("./page-manager-search-and-filter-D7AupT6_.cjs"))),Pe=o.lazy(()=>Promise.resolve().then(()=>require("./add-new-page-B8NGK6WS.cjs"))),we=o.lazy(()=>Promise.resolve().then(()=>require("./delete-page-DLohaU-U.cjs"))),ge=o.lazy(()=>Promise.resolve().then(()=>require("./duplicate-page-D5Gtvqdv.cjs"))),je=o.lazy(()=>Promise.resolve().then(()=>require("./mark-as-template-B9yLcasI.cjs"))),be=o.lazy(()=>Promise.resolve().then(()=>require("./unmark-as-template-F7TdgWjI.cjs"))),Se=o.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-CUr8Xub6.cjs"))),ve=({close:e})=>{const{t:r}=oe.useTranslation(),{languages:a,setSelectedLang:s}=K.useLanguages(),{data:c}=y.usePageTypes(),{data:l,isFetching:p}=y.useWebsitePrimaryPages(),[g,u]=y.useSearchParams(),{updateForSelectedPage:P,expandPagesOnSearch:x}=G.usePageExpandManager(null),d=y.useFallbackLang(),w=g.get("page"),[v,j]=o.useState(""),[m,E]=o.useState(null),[A,S]=o.useState(null),[$,q]=o.useState(null),[I,f]=o.useState(null),[C,z]=o.useState(""),[D,W]=o.useState(null),[H,_]=o.useState(null),[b,F]=o.useState(d),[se,ne]=o.useState(!1),V=R.useSetAtom(y.addNewLangAtom),U=se&&b!==d,{data:M,isFetching:re}=y.useWebsiteLanguagePages(b),Q=o.useCallback(h=>{var i;return(i=n.find(c,{key:h}))==null?void 0:i.hasSlug},[c]),N=o.useMemo(()=>l?U?n.filter(l,h=>!(M!=null&&M[h.id])):de(l,v,C,Q):[],[l,Q,v,C,M,U]);o.useEffect(()=>{s(d)},[d,s]),o.useEffect(()=>{const h=g.get("lang");if(h){const i=a,L=a[0]??d,T=i.includes(h);o.startTransition(()=>{T&&b!==h?F(h):!T&&b!==L&&F(L)})}},[]),o.useEffect(()=>{if(!n.isEmpty(C))return;const h=sessionStorage.getItem("pageTypeFilter")||"all";!n.isEmpty(c)&&h&&(n.find(c,{key:h})?z(h):z("all"))},[c,C]),o.useEffect(()=>{if(w&&!p&&!n.find(l,{id:w})){const i=new URLSearchParams(g.toString());if(i.delete("page"),[...i.keys()].length>0){if(typeof window<"u"&&window.history&&window.location){const L=i.toString(),T=window.location.hash||"",J=window.location.pathname,ae=L?`${J}?${L}${T}`:`${J}${T}`;window.history.replaceState(window.history.state,"",ae)}u(i)}else typeof window<"u"&&window.history&&window.location&&(window.history.replaceState(window.history.state,"",window.location.pathname+window.location.hash),window.dispatchEvent(new PopStateEvent("popstate",{state:window.history.state}))),u(i)}},[l,w,p,u]),o.useEffect(()=>{w&&!p&&!n.isEmpty(N)&&P(N,w)},[w,p,N,P]),o.useEffect(()=>{!n.isEmpty(v)&&!n.isEmpty(N)&&x(N)},[v,N,x]);const{setSelectedLang:B}=K.useLanguages(),X=o.useCallback(h=>{const i=new URLSearchParams({page:h});b!==d?(i.set("lang",b),B(b)):B(""),y.navigateToPage(i,u),e()},[e,u,B,b,d]),Y=(h,i)=>{var L;if(i)switch(h){case"add":S(i);break;case"select":X(i);break;case"edit":b!==d?V({edit:!0,id:i==null?void 0:i.id,primaryPage:i==null?void 0:i.primaryPage}):S(i);break;case"delete":E(i);break;case"unpublish":q(i);break;case"markAsTemplate":f(i);break;case"unmarkAsTemplate":_(i);break;case"duplicate":W(i);break;case"addLanguagePage":V({edit:!1,primaryPage:((L=i==null?void 0:i.page)==null?void 0:L.id)||"",preselectedLang:(i==null?void 0:i.language)||b});break}};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex h-full flex-col justify-between",children:[t.jsx(o.Suspense,{children:t.jsx(pe,{pages:N,search:v,setSearch:j,languages:[d,...a],selectedLanguage:b,setSelectedLanguage:F,selectedPageType:C,setSelectedPageType:z,onAddPage:h=>Y("add",h),showUntranslatedPages:U,setShowUntranslatedPages:ne})}),t.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-6 pt-2",children:p||re?t.jsx("div",{className:"space-y-2",children:n.map([...Array(15).keys()],h=>t.jsx("div",{className:"h-7 w-full animate-pulse rounded border border-gray-300 bg-gray-200"},h))}):n.isEmpty(N)?t.jsxs("div",{className:"flex h-[70vh] flex-col items-center justify-center gap-y-1 text-sm font-medium text-slate-500",children:[t.jsx(k.File,{className:"h-6 w-6 stroke-[1]"}),r("Empty List!"),t.jsx("span",{className:"font-light",children:r("Add new page to start")})]}):t.jsx(te,{tier:0,pages:N,pageTypes:c,currentPage:w||"",onClickAction:Y,languagePages:M,selectedLanguage:b,showUntranslatedPages:U})})]}),A&&t.jsx(o.Suspense,{children:t.jsx(Pe,{closePanel:e,editPage:X,addEditPage:A,setAddEditPage:S})}),m&&t.jsx(o.Suspense,{children:t.jsx(we,{page:m,onClose:()=>E(null)})}),$&&t.jsx(o.Suspense,{children:t.jsx(Se,{page:$,onClose:()=>q(null)})}),I&&t.jsx(o.Suspense,{children:t.jsx(je,{page:I,onClose:()=>f(null)})}),H&&t.jsx(o.Suspense,{children:t.jsx(be,{page:H,onClose:()=>_(null)})}),D&&t.jsx(o.Suspense,{children:t.jsx(ge,{page:D,onClose:()=>W(null),closePanel:e})})]})};exports.default=ve;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("react/jsx-runtime"),K=require("./index-DCJDQs1a.cjs"),y=require("./index-CzBSRTj0.cjs"),G=require("./use-page-expand-manager-B6XTvk0E.cjs"),n=require("lodash-es"),R=require("jotai"),k=require("lucide-react"),o=require("react"),oe=require("react-i18next"),ie=require("./register-chai-top-bar-DyW9GPzV.cjs"),Z=(e,r)=>!e||!Array.isArray(e)?[]:n.isEmpty(r)?e:n.compact(n.filter(e,a=>{const s=n.toLower(r);return n.includes(n.toLower((a==null?void 0:a.name)||""),s)||n.includes(n.toLower((a==null?void 0:a.slug)||""),s)})),le=(e,r)=>{const a=new Set,s=n.keyBy(e,"id");return r.forEach(c=>{let l=c;for(;l.parent&&s[l.parent];)a.add(l.parent),l=s[l.parent]}),Array.from(a).map(c=>s[c])},O=(e,r,a)=>n.isEmpty(r)?e:e.map(s=>{if(!a(s.pageType))return{...s,shouldExpandOnSearch:!0,children:s.children?O(s.children,r,a):[]};const c=s.children&&s.children.some(l=>n.includes(n.toLower(l.name||""),n.toLower(r))||n.includes(n.toLower(l.slug||""),n.toLower(r)));return{...s,shouldExpandOnSearch:c,children:s.children?O(s.children,r,a):[]}}),ce=e=>{if(!e||!e.length)return[];const r={};e.forEach(s=>{r[s.id]={...s,children:[]}});const a=[];return Object.values(r).forEach(s=>{s.parent&&r[s.parent]?r[s.parent].children.push(s):a.push(s)}),a},ee=e=>!e||!e.length?[]:[...e].sort((a,s)=>(a.name||"").localeCompare(s.name||"")).map(a=>({...a,children:a.children?ee(a.children):[]})),de=(e,r,a,s)=>{if(!e||!e.length)return[];let c=e;if(a!=="all"&&(c=n.compact(n.filter(e,{pageType:a}))),n.isEmpty(r))c=Z(c,r);else{const x=Z(c,r),d=le(e,x);c=n.uniqBy([...x,...d],"id")}const l=ee(ce(c)),p=O(l,r,s),g=n.filter(p,x=>s(x.pageType)).sort((x,d)=>(x.name||"").localeCompare(d.name||"")),u=n.filter(p,x=>!s(x.pageType));let P=[];if(a==="all"){const x=n.keyBy(u,"pageType");P=Object.values(n.mapValues(x,(d,w)=>({...d,id:w,name:n.startCase(w),isPartialGroup:!0,children:p.filter(v=>v.pageType===w)})))}else P=u.sort((x,d)=>(x.name||"").localeCompare(d.name||""));return[...g,...P]},ue=R.atom({pageId:null,position:{x:0,y:0}}),me=({pageId:e,children:r})=>{const[a,s]=R.useAtom(ue),c=o.useRef(null),l=a.pageId===e;o.useEffect(()=>{const u=()=>s({pageId:null,position:{x:0,y:0}});if(l)return document.addEventListener("click",u),()=>document.removeEventListener("click",u)},[l,s]);const p=u=>{u.preventDefault(),u.stopPropagation(),s({pageId:e,position:{x:u.clientX,y:u.clientY}})},g=()=>{const u=`${window.location.pathname}?page=${e}`;window.open(u,"_blank"),s({pageId:null,position:{x:0,y:0}})};return t.jsxs(t.Fragment,{children:[t.jsx("span",{onContextMenu:p,children:r}),l&&t.jsx("div",{ref:c,className:"fixed z-[9999] max-w-[160px] rounded-md border border-gray-200 bg-white",style:{top:a.position.y,left:a.position.x},children:t.jsx("div",{className:"",children:t.jsxs(ie.Button,{variant:"ghost",onClick:g,className:"w-full px-2.5 py-1 text-start text-sm text-gray-700 hover:bg-gray-100",children:[t.jsx(k.ExternalLink,{className:"h-4 w-4"}),"Open in new tab"]})})})]})},he=({page:e})=>{var s,c;const{isExpanded:r,toggleExpanded:a}=G.usePageExpandManager(e==null?void 0:e.id);return t.jsx("button",{onClick:l=>{l.stopPropagation(),a()},disabled:!((s=e==null?void 0:e.children)!=null&&s.length),className:`flex h-[calc(100%-2px)] w-5 items-center justify-center rounded text-gray-400 transition-colors hover:bg-gray-200 hover:px-1 hover:text-gray-500 ${(c=e==null?void 0:e.children)!=null&&c.length?"hover:text-blue-400":"opacity-0"}`,children:t.jsx(k.ChevronRight,{size:12,className:`stroke-[4] transition-transform duration-200 ${r?"rotate-90":""}`})})},xe=({page:e,pageType:r})=>t.jsx("div",{className:"flex h-full items-center justify-center gap-x-1",children:e.dynamic?t.jsx(k.StarsIcon,{size:12,className:"text-yellow-400"}):r!=null&&r.icon?t.jsx("div",{className:"flex h-4 max-h-4 w-4 max-w-4 items-center justify-center stroke-[1] text-slate-500",dangerouslySetInnerHTML:{__html:r.icon}}):r!=null&&r.hasSlug?t.jsx(k.File,{size:12,className:"stroke-[1] text-slate-500"}):t.jsx(k.Hash,{size:12,className:"stroke-[1] text-slate-500"})}),fe=({isOnline:e})=>t.jsx("div",{className:`h-2 w-2 rounded-full ${e?"bg-green-300":"bg-gray-300"}`}),ye=({page:e,pageTypes:r,currentPage:a,onClickAction:s,languagePages:c,selectedLanguage:l,showUntranslatedPages:p})=>{const g=y.useUserId(),{pageToUser:u}=y.usePageToUser(),P=n.get(u,[e==null?void 0:e.id,"userId"]),{data:x}=y.useChaiUserInfo(P),d=x&&g!==P?x==null?void 0:x.name:null,w=y.useFallbackLang(),v=a===e.id,j=o.useMemo(()=>n.find(r,{key:e.pageType}),[r,e.pageType]);let m=n.get(c,e==null?void 0:e.id);m=n.get(m,"lang")===l?m:null;const E=l===w||!!m,A=(m==null?void 0:m.name)||(e==null?void 0:e.name)||"No name";let S=(m==null?void 0:m.slug)||(e==null?void 0:e.slug)||"";const $=S+(e!=null&&e.dynamic?`/${j==null?void 0:j.dynamicSlug}`:"")+(e!=null&&e.dynamicSlugCustom?`${e.dynamicSlugCustom}`:"");if(S.startsWith("/")&&!p){const f=S.split("/").pop();S=S.endsWith(f)&&e.dynamic?"":`/${f}`}const q=o.useMemo(()=>{const f="flex h-7 min-w-0 flex-1 cursor-pointer select-none items-center gap-x-1.5 rounded px-px text-xs duration-300 border-[1px]",C=`${v?"border-primary/30 bg-primary/5":"border-transparent hover:border-gray-200 hover:bg-gray-100"}`;return E?`${f} ${C} ${d?"opacity-60":""}`:`${f} bg-gray-100 opacity-50 group-hover:border-gray-200 border-transparent group-hover:bg-blue-100`},[E,v,d]),I=o.useMemo(()=>{if(e.isPartialGroup)return!1;if(m){if(!m.online||n.isEmpty(m.changes))return!1}else if(e&&(!e.online||n.isEmpty(e.changes)))return!1;return!0},[m,e]);return t.jsxs("div",{className:"group relative",children:[t.jsx(me,{pageId:e.id,children:t.jsxs("div",{onClick:()=>!e.isPartialGroup&&E&&s("select",e==null?void 0:e.id),className:q,children:[t.jsx(he,{page:e}),!e.isPartialGroup&&t.jsx(fe,{isOnline:m?m.online:e.online}),!e.isPartialGroup&&t.jsx(xe,{page:e,pageType:j}),t.jsx(y.Tooltip,{content:A,side:"top",showTooltip:A.length>35,children:t.jsx("span",{className:"max-w-[40%] truncate font-medium text-black",children:A})}),(S||e.dynamic)&&t.jsx(y.Tooltip,{content:$,side:"top",showTooltip:!0,children:t.jsxs("span",{className:"max-w-[40%] truncate font-mono text-xs text-muted-foreground",children:[S,e.dynamic&&(j==null?void 0:j.dynamicSlug)&&t.jsxs("span",{className:"text-xs text-gray-500",children:["/",j==null?void 0:j.dynamicSlug,e.dynamicSlugCustom]})]})}),I&&t.jsx(y.Tooltip,{content:"Has unpublished changes",side:"top",children:t.jsx("span",{className:"text-amber-500",children:t.jsx(k.Pencil,{size:12,className:"stroke-[2]"})})}),!e.isPartialGroup&&E&&!d?t.jsx("div",{className:"duration absolute right-0.5 top-[3px]",children:t.jsx(y.PageActionsDropdown,{isLanguagePage:!!m,page:m||e,setDuplicatePage:f=>s("duplicate",f),setAddEditPage:f=>s("edit",m||f),setUnpublishPage:f=>s("unpublish",f),setDeletePage:f=>s("delete",m||f),children:t.jsx("div",{className:"m-0 cursor-pointer rounded border border-transparent p-0.5 duration-100 hover:border-gray-400 hover:bg-white",children:t.jsx(k.MoreHorizontal,{className:"h-4 w-4",onClick:f=>f.stopPropagation()})})})}):d?t.jsxs("span",{className:"duration absolute right-1.5 top-1/2 flex -translate-y-1/2 items-center gap-x-1 text-xs text-red-500",children:[t.jsx(k.Lock,{className:"h-3 w-3 fill-red-200 text-red-500"}),t.jsx(y.Tooltip,{content:`${d} is editing this page`,children:t.jsx("span",{className:"font-bold",children:d})})]}):null]})}),t.jsx(t.Fragment,{children:!E&&!e.isPartialGroup&&!d&&t.jsxs("button",{onClick:f=>{f.stopPropagation(),s("addLanguagePage",{language:l,page:e})},className:"absolute left-1/2 top-1 flex -translate-x-1/2 items-center gap-x-1 rounded bg-blue-500 px-2 py-0.5 text-xs text-white opacity-0 duration-200 hover:bg-blue-700 group-hover:opacity-100",children:[t.jsx(k.Plus,{size:12,className:"stroke-[3]"})," ",t.jsxs("span",{className:"text-[10px]",children:["Add ",n.get(y.LANGUAGES,l)," Page"]})]})})]})},te=({pages:e,tier:r,pageTypes:a,currentPage:s,onClickAction:c,languagePages:l,selectedLanguage:p,showUntranslatedPages:g})=>{const{expandedPages:u}=G.usePageExpandManager();return t.jsx("div",{className:"space-y-0.5",style:{paddingLeft:`${r*10}px`},children:e.map(P=>t.jsxs(t.Fragment,{children:[t.jsx(ye,{page:P,pageTypes:a,currentPage:s,onClickAction:c,languagePages:l,selectedLanguage:p,showUntranslatedPages:g}),P.children&&P.children.length>0&&(u==null?void 0:u.includes(P.id))&&t.jsx(te,{pages:P.children,tier:r+1,pageTypes:a,currentPage:s,onClickAction:c,languagePages:l,selectedLanguage:p,showUntranslatedPages:g})]},P.id))})},pe=o.lazy(()=>Promise.resolve().then(()=>require("./page-manager-search-and-filter-BE7w_2hv.cjs"))),Pe=o.lazy(()=>Promise.resolve().then(()=>require("./add-new-page-Ddoy3kTu.cjs"))),we=o.lazy(()=>Promise.resolve().then(()=>require("./delete-page-BNZclrjF.cjs"))),ge=o.lazy(()=>Promise.resolve().then(()=>require("./duplicate-page-DgxKd840.cjs"))),je=o.lazy(()=>Promise.resolve().then(()=>require("./mark-as-template-6kAFYYpY.cjs"))),be=o.lazy(()=>Promise.resolve().then(()=>require("./unmark-as-template-D_-Bbbl_.cjs"))),Se=o.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-CGZWa57H.cjs"))),ve=({close:e})=>{const{t:r}=oe.useTranslation(),{languages:a,setSelectedLang:s}=K.useLanguages(),{data:c}=y.usePageTypes(),{data:l,isFetching:p}=y.useWebsitePrimaryPages(),[g,u]=y.useSearchParams(),{updateForSelectedPage:P,expandPagesOnSearch:x}=G.usePageExpandManager(null),d=y.useFallbackLang(),w=g.get("page"),[v,j]=o.useState(""),[m,E]=o.useState(null),[A,S]=o.useState(null),[$,q]=o.useState(null),[I,f]=o.useState(null),[C,z]=o.useState(""),[D,W]=o.useState(null),[H,_]=o.useState(null),[b,F]=o.useState(d),[se,ne]=o.useState(!1),V=R.useSetAtom(y.addNewLangAtom),U=se&&b!==d,{data:M,isFetching:re}=y.useWebsiteLanguagePages(b),Q=o.useCallback(h=>{var i;return(i=n.find(c,{key:h}))==null?void 0:i.hasSlug},[c]),N=o.useMemo(()=>l?U?n.filter(l,h=>!(M!=null&&M[h.id])):de(l,v,C,Q):[],[l,Q,v,C,M,U]);o.useEffect(()=>{s(d)},[d,s]),o.useEffect(()=>{const h=g.get("lang");if(h){const i=a,L=a[0]??d,T=i.includes(h);o.startTransition(()=>{T&&b!==h?F(h):!T&&b!==L&&F(L)})}},[]),o.useEffect(()=>{if(!n.isEmpty(C))return;const h=sessionStorage.getItem("pageTypeFilter")||"all";!n.isEmpty(c)&&h&&(n.find(c,{key:h})?z(h):z("all"))},[c,C]),o.useEffect(()=>{if(w&&!p&&!n.find(l,{id:w})){const i=new URLSearchParams(g.toString());if(i.delete("page"),[...i.keys()].length>0){if(typeof window<"u"&&window.history&&window.location){const L=i.toString(),T=window.location.hash||"",J=window.location.pathname,ae=L?`${J}?${L}${T}`:`${J}${T}`;window.history.replaceState(window.history.state,"",ae)}u(i)}else typeof window<"u"&&window.history&&window.location&&(window.history.replaceState(window.history.state,"",window.location.pathname+window.location.hash),window.dispatchEvent(new PopStateEvent("popstate",{state:window.history.state}))),u(i)}},[l,w,p,u]),o.useEffect(()=>{w&&!p&&!n.isEmpty(N)&&P(N,w)},[w,p,N,P]),o.useEffect(()=>{!n.isEmpty(v)&&!n.isEmpty(N)&&x(N)},[v,N,x]);const{setSelectedLang:B}=K.useLanguages(),X=o.useCallback(h=>{const i=new URLSearchParams({page:h});b!==d?(i.set("lang",b),B(b)):B(""),y.navigateToPage(i,u),e()},[e,u,B,b,d]),Y=(h,i)=>{var L;if(i)switch(h){case"add":S(i);break;case"select":X(i);break;case"edit":b!==d?V({edit:!0,id:i==null?void 0:i.id,primaryPage:i==null?void 0:i.primaryPage}):S(i);break;case"delete":E(i);break;case"unpublish":q(i);break;case"markAsTemplate":f(i);break;case"unmarkAsTemplate":_(i);break;case"duplicate":W(i);break;case"addLanguagePage":V({edit:!1,primaryPage:((L=i==null?void 0:i.page)==null?void 0:L.id)||"",preselectedLang:(i==null?void 0:i.language)||b});break}};return t.jsxs(t.Fragment,{children:[t.jsxs("div",{className:"flex h-full flex-col justify-between",children:[t.jsx(o.Suspense,{children:t.jsx(pe,{pages:N,search:v,setSearch:j,languages:[d,...a],selectedLanguage:b,setSelectedLanguage:F,selectedPageType:C,setSelectedPageType:z,onAddPage:h=>Y("add",h),showUntranslatedPages:U,setShowUntranslatedPages:ne})}),t.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-6 pt-2",children:p||re?t.jsx("div",{className:"space-y-2",children:n.map([...Array(15).keys()],h=>t.jsx("div",{className:"h-7 w-full animate-pulse rounded border border-gray-300 bg-gray-200"},h))}):n.isEmpty(N)?t.jsxs("div",{className:"flex h-[70vh] flex-col items-center justify-center gap-y-1 text-sm font-medium text-slate-500",children:[t.jsx(k.File,{className:"h-6 w-6 stroke-[1]"}),r("Empty List!"),t.jsx("span",{className:"font-light",children:r("Add new page to start")})]}):t.jsx(te,{tier:0,pages:N,pageTypes:c,currentPage:w||"",onClickAction:Y,languagePages:M,selectedLanguage:b,showUntranslatedPages:U})})]}),A&&t.jsx(o.Suspense,{children:t.jsx(Pe,{closePanel:e,editPage:X,addEditPage:A,setAddEditPage:S})}),m&&t.jsx(o.Suspense,{children:t.jsx(we,{page:m,onClose:()=>E(null)})}),$&&t.jsx(o.Suspense,{children:t.jsx(Se,{page:$,onClose:()=>q(null)})}),I&&t.jsx(o.Suspense,{children:t.jsx(je,{page:I,onClose:()=>f(null)})}),H&&t.jsx(o.Suspense,{children:t.jsx(be,{page:H,onClose:()=>_(null)})}),D&&t.jsx(o.Suspense,{children:t.jsx(ge,{page:D,onClose:()=>W(null),closePanel:e})})]})};exports.default=ve;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),h=require("./register-chai-top-bar-DyW9GPzV.cjs"),n=require("./index-DCJDQs1a.cjs"),v=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),h=require("./register-chai-top-bar-DyW9GPzV.cjs"),n=require("./index-DCJDQs1a.cjs"),v=require("./index-CzBSRTj0.cjs"),w=require("./use-page-expand-manager-B6XTvk0E.cjs"),S=require("@tanstack/react-query"),s=require("lodash-es"),x=require("lucide-react"),b=require("react"),j=require("react-i18next"),k=({selectedPageType:l,setSelectedPageType:a})=>{const{t:o}=j.useTranslation(),[r,i]=b.useState(""),{data:c}=v.usePageTypes(),m=b.useMemo(()=>c.some(t=>!["page","global"].includes(s.get(t,"key",""))),[c]);if(b.useEffect(()=>{!m&&l!=="all"&&a("all")},[m,l,a]),!m)return null;const u=t=>{if(!r)return!0;const d=r.toLowerCase(),g=f=>String(s.get(t,f,"")).toLowerCase().includes(d);return g("name")||g("key")},p=c.find(t=>t.key===l);return e.jsxs(n.Select,{onValueChange:a,value:l,children:[e.jsx(n.SelectTrigger,{className:`${l==="all"?"bg-gray-100/30 hover:bg-gray-100":"gap-x-1 border bg-gray-100/30 hover:bg-gray-100"} h-9 w-max min-w-[150px] overflow-hidden whitespace-nowrap rounded p-0 px-2 py-1 text-xs text-gray-600 shadow-none ring-0 focus:ring-0 [&>svg]:hidden`,children:e.jsxs("div",{className:"flex w-full items-center justify-between gap-x-1.5",children:[e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate whitespace-nowrap font-medium leading-tight",children:(p==null?void 0:p.name)||o("All")}),e.jsx(x.ListFilter,{className:`${l!=="all"?"fill-sky-50 text-sky-500":""} pointer-events-none h-4 w-4 text-muted-foreground hover:bg-blue-300`})]})}),e.jsxs(n.SelectContent,{children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white pb-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(x.Search,{strokeWidth:2,className:"absolute left-2 top-2.5 h-3.5 w-3.5 text-gray-400"}),e.jsx(h.Input,{placeholder:o("Search page types..."),className:"h-8 w-full rounded border pl-8 text-xs shadow-none",value:r,onChange:t=>i(t.target.value),onKeyDown:t=>t.stopPropagation()})]})}),e.jsx(n.SelectItem,{value:"all",children:o("All")}),!s.isEmpty(s.filter(c,t=>t.hasSlug&&u(t)))&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 border-t px-2 py-1.5 pt-2 text-xs font-semibold text-gray-500",children:o("Pages")}),s.map([...s.filter(c,t=>t.hasSlug&&u(t))].sort((t,d)=>s.get(t,"name","").localeCompare(s.get(d,"name",""))),t=>e.jsx(n.SelectItem,{value:s.get(t,"key"),children:s.get(t,"name")},s.get(t,"key")))]}),!s.isEmpty(s.filter(c,t=>!t.hasSlug&&u(t)))&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 border-t px-2 py-1.5 pt-2 text-xs font-semibold text-gray-500",children:o("Partials")}),s.map([...s.filter(c,t=>!t.hasSlug&&u(t))].sort((t,d)=>s.get(t,"name","").localeCompare(s.get(d,"name",""))),t=>e.jsx(n.SelectItem,{value:s.get(t,"key"),children:s.get(t,"name")},s.get(t,"key")))]}),s.isEmpty(s.filter(c,u))&&e.jsx("div",{className:"px-3 py-2 text-center text-sm text-gray-500",children:o("No matching page types found")})]})]})},T=({search:l,setSearch:a})=>{const{t:o}=j.useTranslation();return e.jsxs("div",{className:"relative flex h-9 flex-1 items-center gap-2 rounded-md border px-2.5",children:[e.jsx("label",{htmlFor:"page-search-input",className:"sr-only",children:o("Search Pages")}),e.jsx(x.Search,{className:`${l?"fill-sky-50 text-sky-500":""} pointer-events-none h-4 w-4 text-muted-foreground`,"aria-hidden":"true"}),e.jsx(h.Input,{id:"page-search-input",placeholder:o("Search pages"),value:l,onChange:r=>a(r.target.value),className:"border-none px-1.5 shadow-none outline-none ring-0 transition-none focus:outline-none focus:ring-0 focus-visible:ring-0",autoComplete:"off",autoFocus:!0})]})},E=({pages:l})=>{const{t:a}=j.useTranslation(),{expandAll:o,collapseAll:r,expandedPages:i}=w.usePageExpandManager(null);return e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(n.Tooltip,{children:[e.jsx(n.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{variant:"outline",size:"icon",onClick:()=>o(l),className:"rounded p-1 text-gray-500",children:e.jsx(x.ChevronsUpDown,{})})}),e.jsx(n.TooltipContent,{children:a("Expand All")})]}),e.jsxs(n.Tooltip,{children:[e.jsx(n.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{disabled:i.length===0,variant:"outline",size:"icon",onClick:()=>r(),className:"rounded p-1 text-gray-500",children:e.jsx(x.ChevronsDownUp,{})})}),e.jsx(n.TooltipContent,{children:a("Collapse All")})]})]})},C=({languages:l,selectedLanguage:a,setSelectedLanguage:o})=>{const r=v.useFallbackLang();return e.jsx("div",{className:"scrollbar-hide flex gap-1 overflow-x-auto pb-1",children:l.map(i=>e.jsxs(h.Button,{variant:a===i?"default":"outline",size:"sm",className:`h-6 flex-shrink-0 whitespace-nowrap rounded px-3 text-xs font-normal ${a===i?"bg-black text-white hover:bg-black":"text-gray-500"}`,onClick:()=>o(i.toLowerCase()),children:[i===r&&e.jsx(x.Star,{size:4,className:`p-0.5 ${a===r?"fill-white":"fill-black"}`}),v.LANGUAGES[i]||""]},i))})},y=()=>{const{t:l}=j.useTranslation(),a=S.useQueryClient();return e.jsxs(n.Tooltip,{children:[e.jsx(n.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{size:"sm",variant:"ghost",onClick:()=>a.invalidateQueries({queryKey:[v.ACTIONS.GET_WEBSITE_PAGES]}),className:"mt-1 h-6 w-6",children:e.jsx(x.RefreshCw,{})})}),e.jsx(n.TooltipContent,{side:"bottom",children:l("Refresh pages list")})]})},q=({pages:l,search:a,setSearch:o,languages:r,onAddPage:i,selectedLanguage:c,setSelectedLanguage:m,selectedPageType:u,setSelectedPageType:p,showUntranslatedPages:t,setShowUntranslatedPages:d})=>{const{t:g}=j.useTranslation(),f=r.length>1;return e.jsxs("div",{className:"space-y-3 border-b border-b-gray-200 px-4 pb-1",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(k,{selectedPageType:u,setSelectedPageType:p}),e.jsx(T,{search:a,setSearch:o}),e.jsx(E,{pages:l}),e.jsxs(h.Button,{variant:"default",onClick:i,className:"rounded px-3 font-normal",children:[e.jsx(x.Plus,{strokeWidth:2,className:"stroke-white stroke-[3]"}),e.jsx("span",{className:"font-normal text-white",children:g("Add Page")})]}),!f&&e.jsx(y,{})]}),f?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(C,{languages:r,selectedLanguage:c,setSelectedLanguage:N=>{m(N),d(t&&(r==null?void 0:r[0])!==c)}}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[(r==null?void 0:r[0])!==c&&e.jsxs(n.Tooltip,{children:[e.jsx(n.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{variant:"ghost",onClick:()=>d(!t),className:"h-6 rounded px-3 py-1 text-xs font-normal",children:t?e.jsx(x.FilterXIcon,{}):e.jsx(x.Filter,{})})}),e.jsx(n.TooltipContent,{side:"bottom",children:g("Toggle Untranslated Pages")})]}),e.jsx(y,{})]})]}):e.jsx("div",{className:"flex items-center justify-between gap-2"})]})};exports.LanguageSelector=C;exports.default=q;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as e, jsxs as a, Fragment as k } from "react/jsx-runtime";
|
|
2
2
|
import { B as m, z as E } from "./register-chai-top-bar-D6GjnauV.js";
|
|
3
3
|
import { z as b, A as y, E as N, S as L, F as I, G as P, H as w } from "./index-OuHV9Ann.js";
|
|
4
|
-
import { i as j, L as G, k as $, A as M } from "./index-
|
|
4
|
+
import { i as j, L as G, k as $, A as M } from "./index-nzqILA37.js";
|
|
5
5
|
import { u as B } from "./use-page-expand-manager-Cf4MUEJw.js";
|
|
6
6
|
import { useQueryClient as D } from "@tanstack/react-query";
|
|
7
7
|
import { get as c, isEmpty as C, filter as f, map as S } from "lodash-es";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs as a, Fragment as p, jsx as e } from "react/jsx-runtime";
|
|
2
2
|
import { B as g } from "./register-chai-top-bar-D6GjnauV.js";
|
|
3
3
|
import { d as le, ag as re, ah as ie, a7 as de, ai as v, I as ce, D as V, e as j, f as G, g as L, o as z, q as $, v as oe, w as ue, x as me, y as _, aj as he } from "./index-OuHV9Ann.js";
|
|
4
|
-
import { aq as C, ar as A, A as y, av as H, az as fe, ao as I, aw as E, ax as D } from "./index-
|
|
4
|
+
import { aq as C, ar as A, A as y, av as H, az as fe, ao as I, aw as E, ax as D } from "./index-nzqILA37.js";
|
|
5
5
|
import { useQuery as pe, useQueryClient as O, useMutation as P } from "@tanstack/react-query";
|
|
6
6
|
import { format as S, formatDistanceToNow as xe } from "date-fns";
|
|
7
7
|
import { isEmpty as ge } from "lodash-es";
|
|
@@ -50,7 +50,7 @@ const Ie = () => {
|
|
|
50
50
|
});
|
|
51
51
|
}
|
|
52
52
|
});
|
|
53
|
-
}, Te = Ce(() => import("./json-diff-viewer-
|
|
53
|
+
}, Te = Ce(() => import("./json-diff-viewer-CMw5W_Li.js")), N = ({ tag: t }) => t === "draft" ? /* @__PURE__ */ a("div", { className: "flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600", children: [
|
|
54
54
|
/* @__PURE__ */ a("span", { className: "relative flex h-2 w-2", children: [
|
|
55
55
|
/* @__PURE__ */ e("span", { className: "absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75" }),
|
|
56
56
|
/* @__PURE__ */ e("span", { className: "relative inline-flex h-2 w-2 rounded-full bg-amber-500" })
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),N=require("./register-chai-top-bar-DyW9GPzV.cjs"),i=require("./index-DCJDQs1a.cjs"),c=require("./index-BVwFJWDq.cjs"),y=require("@tanstack/react-query"),S=require("date-fns"),B=require("lodash-es"),f=require("lucide-react"),g=require("react");function L(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return n.default=s,Object.freeze(n)}const w=L(g);function Q(s){const n=c.useApiUrl(),t=c.useFetch();return y.useQuery({queryKey:[c.ACTIONS.GET_PAGE_REVISIONS,s],queryFn:async()=>await t(n,{action:c.ACTIONS.GET_PAGE_REVISIONS,data:{pageId:s}}),enabled:!!s,refetchOnMount:!0})}const z=()=>{const s=c.useApiUrl(),n=c.useFetch(),t=y.useQueryClient();return y.useMutation({mutationFn:async r=>await n(s,{action:c.ACTIONS.DELETE_PAGE_REVISION,data:{revisionId:r}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},H=()=>{const s=c.useApiUrl(),n=c.useFetch(),t=y.useQueryClient();return y.useMutation({mutationFn:async({revisionId:r,discardCurrent:l,pageId:d})=>await n(s,{action:c.ACTIONS.RESTORE_PAGE_REVISION,data:{revisionId:r,discardCurrent:l,...d&&{pageId:d}}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},$=g.lazy(()=>Promise.resolve().then(()=>require("./json-diff-viewer-Cb1CmRqP.cjs"))),b=({tag:s})=>s==="draft"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-amber-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Draft"})]}):s==="live"?e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-green-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Live"})]}):s==="published"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-green-500/10 px-1.5 py-0.5 text-xs text-green-600",children:[e.jsx(f.Rocket,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Published"})]}):s==="unsaved"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-red-500/10 px-1.5 py-0.5 text-xs text-red-600",children:[e.jsx(f.Save,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Unsaved changes"})]}):e.jsx("span",{className:"rounded bg-purple-500/10 px-1.5 py-0.5 font-mono text-xs font-bold text-purple-600",children:s});function J({compare:s,setCompare:n}){const{data:t}=c.usePrimaryPage(),{saveState:r}=i.useSavePage(),[l]=c.usePageEditInfo();if(!t)return null;const d=!!s.find(x=>{var a;return(a=x==null?void 0:x.uid)==null?void 0:a.startsWith("draft:")}),u=s.length>=2&&!d,m=r==="UNSAVED";return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border bg-primary/5 p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-1 text-sm font-medium leading-none",children:[e.jsx(b,{tag:"draft"}),e.jsx("span",{className:"text-xs font-bold",children:"Currently editing"})]})}),e.jsx("div",{className:"flex items-center pl-2 text-[11px] text-muted-foreground",children:!B.isEmpty(l.lastSaved)&&e.jsxs("span",{children:["Last updated"," ",S.formatDistanceToNow(new Date(l.lastSaved),{addSuffix:!0})]})}),e.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:m?e.jsx(b,{tag:"unsaved"}):null})]}),e.jsx(O,{checked:d,disabled:u,onChange:()=>{n(d?s.filter(x=>x.uid!==`draft:${t==null?void 0:t.id}`):[...s,{uid:`draft:${t==null?void 0:t.id}`,label:"draft",item:{createdAt:Date.now()}}])}})]})}function K(){return e.jsx("div",{className:"mt-2 space-y-2",children:Array.from({length:5}).map((s,n)=>e.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(i.Skeleton,{className:"h-4 w-3/4"}),e.jsx(i.Skeleton,{className:"h-3 w-1/2"}),e.jsx(i.Skeleton,{className:"mt-1 h-5 w-20"})]}),e.jsx(i.Skeleton,{className:"h-8 w-8 rounded-full"})]},n))})}function I({revision:s,isLatest:n,onRestore:t,onDelete:r,revisionNumber:l,compare:d,setCompare:u,pageId:m}){const{data:x}=c.useChaiUserInfo(s.currentEditor),a=(x==null?void 0:x.name)||"Unknown",p=!!d.find(h=>{var j;return n?(j=h==null?void 0:h.uid)==null?void 0:j.startsWith("live"):(h==null?void 0:h.uid)===s.uid}),D=d.length>=2&&!p;return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("p",{className:"flex items-center gap-1 text-xs leading-none",children:[e.jsx(b,{tag:n?"live":`#${l}`}),s.type==="published"?"Published":"Draft"," by ",e.jsx("span",{className:"text-xs font-bold",children:a})]})}),e.jsxs("div",{className:"flex items-center gap-x-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:s.type==="published"?e.jsx(b,{tag:"published"}):e.jsx(b,{tag:"draft"})}),e.jsx("div",{className:"flex items-center text-[10px] text-muted-foreground",children:e.jsx("span",{className:"leading-tight",children:S.format(s.createdAt,"MMM d, yyyy, h:mm a")})})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(c.PermissionChecker,{permissions:[c.PAGES_PERMISSIONS.RESTORE_REVISION,c.PAGES_PERMISSIONS.DELETE_REVISION],children:e.jsx(Y,{revision:s,onRestore:t,onDelete:r})})}),e.jsx(O,{checked:p,disabled:D,onChange:()=>{u(p?d.filter(h=>n?h.uid!==`live:${m}`:h.uid!==s.uid):[...d,{uid:n?`live:${m}`:s.uid,label:n?"live":`#${l}`,item:s}].sort((h,j)=>new Date(h.item.createdAt).getTime()-new Date(j.item.createdAt).getTime()))}})]})}function A({tab:s,onRemove:n}){return e.jsxs("span",{className:"flex items-center justify-between rounded border border-blue-100 p-1 font-medium",children:[e.jsx(b,{tag:s.label}),e.jsx("button",{className:"z-0 flex h-4 w-4 items-center justify-center rounded-full text-gray-400 hover:text-red-500",style:{lineHeight:1},onClick:()=>n(s.uid),"aria-label":"Remove selection",children:e.jsx(f.X,{className:"h-3 w-3"})})]})}function W({compare:s,setCompare:n,pageId:t}){const[r,l]=g.useState(!1),[d,u]=s;if(s.length===0)return null;const m=x=>n(s.filter(a=>a.uid!==x));return e.jsxs("div",{className:"mb-2 flex w-full max-w-md flex-col gap-1 rounded border bg-accent/60 p-2 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-x-2 text-xs",children:[e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"Compare"}),d&&e.jsx(A,{tab:d,onRemove:m}),e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"with"}),u?e.jsx(A,{tab:u,onRemove:m}):e.jsx("span",{className:"rounded border px-1 text-xs text-muted-foreground",children:"Choose another"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pb-0.5 pt-2",children:[e.jsx(N.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none text-gray-500",variant:"outline",onClick:()=>n([]),children:e.jsx("span",{children:" Clear"})}),e.jsxs(N.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none",variant:"default",onClick:()=>l(!0),disabled:s.length<2,children:[e.jsx(f.FileJson,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"pt-0.5",children:"Show JSON Diff"})]})]}),r&&(s==null?void 0:s.length)>1&&t&&e.jsx(g.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx("span",{className:"text-sm",children:"Loading diff viewer..."})}),children:e.jsx($,{open:r,onOpenChange:l,compare:s})})]})}function O({checked:s,disabled:n,onChange:t,label:r="Compare"}){return e.jsx("div",{className:"absolute bottom-2 right-2",children:e.jsxs("label",{className:`flex cursor-pointer items-center gap-x-1 text-[11px] ${n?"opacity-50":""}`,children:[e.jsx("input",{type:"checkbox",className:"h-3 w-3 cursor-pointer rounded focus:ring-0 focus:ring-offset-0",checked:s,disabled:n,onChange:t}),e.jsx("span",{className:"select-none leading-tight",children:r})]})})}function Y({revision:s,onRestore:n,onDelete:t}){return e.jsxs(i.DropdownMenu,{children:[e.jsx(i.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(N.Button,{variant:"ghost",size:"icon",className:"h-5 w-5",children:[e.jsx(f.MoreHorizontal,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More options"})]})}),e.jsxs(i.DropdownMenuContent,{align:"end",className:"text-xs",children:[e.jsx(c.PermissionChecker,{permission:c.PAGES_PERMISSIONS.RESTORE_REVISION,children:e.jsxs(i.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-sm",children:[e.jsx(f.Undo2,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Restore this version"})]})}),e.jsx(c.PermissionChecker,{permission:c.PAGES_PERMISSIONS.DELETE_REVISION,children:s.uid!=="current"&&e.jsxs(e.Fragment,{children:[e.jsx(i.DropdownMenuSeparator,{}),e.jsxs(i.DropdownMenuItem,{onClick:t,className:"cursor-pointer text-destructive",children:[e.jsx(f.Trash,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Delete this version"})]})]})})]})]})}function X({open:s,onOpenChange:n,revision:t,onRestore:r,isRestoring:l}){const{data:d}=c.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),u=(d==null?void 0:d.name)||"Unknown";return t?e.jsx(i.Dialog,{open:s,onOpenChange:m=>{l||n(m)},children:e.jsxs(i.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(i.DialogHeader,{children:[e.jsx(i.DialogTitle,{children:"Restore Revision"}),e.jsxs(i.DialogDescription,{children:["You are about to restore to revision ",t.uid.substring(0,8)," from"," ",S.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",u]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"How would you like to handle your current edits?"})}),e.jsxs(i.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(N.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>r(!1),disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Saving as draft..."]}):e.jsxs(e.Fragment,{children:[e.jsx(f.CloudOff,{className:"mr-2 h-4 w-4"}),"Save as draft"]})}),e.jsx(N.Button,{variant:"default",className:"sm:flex-1",onClick:()=>r(!0),disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Discarding current..."]}):e.jsxs(e.Fragment,{children:[e.jsx(f.Undo2,{className:"mr-2 h-4 w-4"}),"Discard current"]})})]})]})}):null}function Z({open:s,onOpenChange:n,revision:t,onDelete:r,isDeleting:l}){const{data:d}=c.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),u=(d==null?void 0:d.name)||"Unknown";return t?e.jsx(i.Dialog,{open:s,onOpenChange:m=>{l||n(m)},children:e.jsxs(i.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(i.DialogHeader,{children:[e.jsx(i.DialogTitle,{children:"Delete Revision"}),e.jsxs(i.DialogDescription,{children:["You are about to delete revision ",t.uid.substring(0,8)," from"," ",S.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",u]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"This action cannot be undone. Are you sure you want to proceed?"})}),e.jsxs(i.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(N.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>n(!1),disabled:l,children:"Cancel"}),e.jsx(N.Button,{variant:"destructive",className:"sm:flex-1",onClick:r,disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Deleting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(f.Trash,{className:"mr-2 h-4 w-4"}),"Delete Revision"]})})]})]})}):null}function ee({isOpen:s}){var R;const[n,t]=w.useState([]),[r,l]=w.useState(null),[d,u]=w.useState(!1),[m,x]=w.useState(!1),{data:a}=c.usePrimaryPage(),{data:p,isFetching:D,error:h,refetch:j}=Q(a==null?void 0:a.id),{mutate:T,isPending:M}=z(),{mutate:k,isPending:F}=H(),_=y.useQueryClient(),{selectedLang:P,fallbackLang:q}=i.useLanguages(),U=P||q;g.useEffect(()=>{g.startTransition(()=>t([]))},[a==null?void 0:a.id]);const G=o=>{r&&k({revisionId:r.uid,discardCurrent:o,...r.uid==="current"&&(a==null?void 0:a.id)&&{pageId:a.id}},{onSuccess:()=>{u(!1),l(null),_.invalidateQueries({queryKey:[c.ACTIONS.GET_DRAFT_PAGE]})}})},C=o=>{l(o),u(!0)},E=o=>{l(o),x(!0)},V=()=>{r&&T(r.uid,{onSuccess:()=>{x(!1),l(null)}})};return g.useEffect(()=>{s&&j()},[s,j]),e.jsxs(e.Fragment,{children:[e.jsxs(i.SheetHeader,{children:[e.jsx(i.SheetTitle,{children:"Revision History"}),(a==null?void 0:a.createdAt)&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Page created on ",S.format(new Date(a.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),D?e.jsx(K,{}):h?e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Failed to load revisions. Please try again."}):e.jsxs("div",{className:"mt-2 flex h-full min-h-0 flex-1 flex-col space-y-2",children:[e.jsx(W,{lang:U,compare:n,setCompare:t,pageId:a==null?void 0:a.id}),e.jsx(J,{compare:n,setCompare:t}),(R=p==null?void 0:p.filter(o=>o.uid==="current"))==null?void 0:R.map((o,v)=>e.jsx(I,{pageId:a==null?void 0:a.id,revision:o,isLatest:!0,onRestore:()=>C(o),onDelete:()=>E(o),revisionNumber:v,compare:n,setCompare:t},o.uid)),e.jsx(i.ScrollArea,{className:"min-h-0 flex-1",children:e.jsx("div",{className:"space-y-2",children:[...p??[]].filter(o=>o.uid!=="current").sort((o,v)=>new Date(v.createdAt).getTime()-new Date(o.createdAt).getTime()).map((o,v)=>e.jsx(I,{pageId:a==null?void 0:a.id,revision:o,isLatest:o.uid==="current",onRestore:()=>C(o),onDelete:()=>E(o),revisionNumber:v+1,compare:n,setCompare:t},o.uid))})})]}),e.jsx(X,{open:d,onOpenChange:u,revision:r,onRestore:G,isRestoring:F}),e.jsx(Z,{open:m,onOpenChange:x,revision:r,onDelete:V,isDeleting:M})]})}exports.default=ee;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),N=require("./register-chai-top-bar-DyW9GPzV.cjs"),i=require("./index-DCJDQs1a.cjs"),c=require("./index-CzBSRTj0.cjs"),y=require("@tanstack/react-query"),S=require("date-fns"),B=require("lodash-es"),f=require("lucide-react"),g=require("react");function L(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const r=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(n,t,r.get?r:{enumerable:!0,get:()=>s[t]})}}return n.default=s,Object.freeze(n)}const w=L(g);function Q(s){const n=c.useApiUrl(),t=c.useFetch();return y.useQuery({queryKey:[c.ACTIONS.GET_PAGE_REVISIONS,s],queryFn:async()=>await t(n,{action:c.ACTIONS.GET_PAGE_REVISIONS,data:{pageId:s}}),enabled:!!s,refetchOnMount:!0})}const z=()=>{const s=c.useApiUrl(),n=c.useFetch(),t=y.useQueryClient();return y.useMutation({mutationFn:async r=>await n(s,{action:c.ACTIONS.DELETE_PAGE_REVISION,data:{revisionId:r}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},H=()=>{const s=c.useApiUrl(),n=c.useFetch(),t=y.useQueryClient();return y.useMutation({mutationFn:async({revisionId:r,discardCurrent:l,pageId:d})=>await n(s,{action:c.ACTIONS.RESTORE_PAGE_REVISION,data:{revisionId:r,discardCurrent:l,...d&&{pageId:d}}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},$=g.lazy(()=>Promise.resolve().then(()=>require("./json-diff-viewer-3C7leKFH.cjs"))),b=({tag:s})=>s==="draft"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-amber-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Draft"})]}):s==="live"?e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-green-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Live"})]}):s==="published"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-green-500/10 px-1.5 py-0.5 text-xs text-green-600",children:[e.jsx(f.Rocket,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Published"})]}):s==="unsaved"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-red-500/10 px-1.5 py-0.5 text-xs text-red-600",children:[e.jsx(f.Save,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Unsaved changes"})]}):e.jsx("span",{className:"rounded bg-purple-500/10 px-1.5 py-0.5 font-mono text-xs font-bold text-purple-600",children:s});function J({compare:s,setCompare:n}){const{data:t}=c.usePrimaryPage(),{saveState:r}=i.useSavePage(),[l]=c.usePageEditInfo();if(!t)return null;const d=!!s.find(x=>{var a;return(a=x==null?void 0:x.uid)==null?void 0:a.startsWith("draft:")}),u=s.length>=2&&!d,m=r==="UNSAVED";return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border bg-primary/5 p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-1 text-sm font-medium leading-none",children:[e.jsx(b,{tag:"draft"}),e.jsx("span",{className:"text-xs font-bold",children:"Currently editing"})]})}),e.jsx("div",{className:"flex items-center pl-2 text-[11px] text-muted-foreground",children:!B.isEmpty(l.lastSaved)&&e.jsxs("span",{children:["Last updated"," ",S.formatDistanceToNow(new Date(l.lastSaved),{addSuffix:!0})]})}),e.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:m?e.jsx(b,{tag:"unsaved"}):null})]}),e.jsx(O,{checked:d,disabled:u,onChange:()=>{n(d?s.filter(x=>x.uid!==`draft:${t==null?void 0:t.id}`):[...s,{uid:`draft:${t==null?void 0:t.id}`,label:"draft",item:{createdAt:Date.now()}}])}})]})}function K(){return e.jsx("div",{className:"mt-2 space-y-2",children:Array.from({length:5}).map((s,n)=>e.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(i.Skeleton,{className:"h-4 w-3/4"}),e.jsx(i.Skeleton,{className:"h-3 w-1/2"}),e.jsx(i.Skeleton,{className:"mt-1 h-5 w-20"})]}),e.jsx(i.Skeleton,{className:"h-8 w-8 rounded-full"})]},n))})}function I({revision:s,isLatest:n,onRestore:t,onDelete:r,revisionNumber:l,compare:d,setCompare:u,pageId:m}){const{data:x}=c.useChaiUserInfo(s.currentEditor),a=(x==null?void 0:x.name)||"Unknown",p=!!d.find(h=>{var j;return n?(j=h==null?void 0:h.uid)==null?void 0:j.startsWith("live"):(h==null?void 0:h.uid)===s.uid}),D=d.length>=2&&!p;return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("p",{className:"flex items-center gap-1 text-xs leading-none",children:[e.jsx(b,{tag:n?"live":`#${l}`}),s.type==="published"?"Published":"Draft"," by ",e.jsx("span",{className:"text-xs font-bold",children:a})]})}),e.jsxs("div",{className:"flex items-center gap-x-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:s.type==="published"?e.jsx(b,{tag:"published"}):e.jsx(b,{tag:"draft"})}),e.jsx("div",{className:"flex items-center text-[10px] text-muted-foreground",children:e.jsx("span",{className:"leading-tight",children:S.format(s.createdAt,"MMM d, yyyy, h:mm a")})})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(c.PermissionChecker,{permissions:[c.PAGES_PERMISSIONS.RESTORE_REVISION,c.PAGES_PERMISSIONS.DELETE_REVISION],children:e.jsx(Y,{revision:s,onRestore:t,onDelete:r})})}),e.jsx(O,{checked:p,disabled:D,onChange:()=>{u(p?d.filter(h=>n?h.uid!==`live:${m}`:h.uid!==s.uid):[...d,{uid:n?`live:${m}`:s.uid,label:n?"live":`#${l}`,item:s}].sort((h,j)=>new Date(h.item.createdAt).getTime()-new Date(j.item.createdAt).getTime()))}})]})}function A({tab:s,onRemove:n}){return e.jsxs("span",{className:"flex items-center justify-between rounded border border-blue-100 p-1 font-medium",children:[e.jsx(b,{tag:s.label}),e.jsx("button",{className:"z-0 flex h-4 w-4 items-center justify-center rounded-full text-gray-400 hover:text-red-500",style:{lineHeight:1},onClick:()=>n(s.uid),"aria-label":"Remove selection",children:e.jsx(f.X,{className:"h-3 w-3"})})]})}function W({compare:s,setCompare:n,pageId:t}){const[r,l]=g.useState(!1),[d,u]=s;if(s.length===0)return null;const m=x=>n(s.filter(a=>a.uid!==x));return e.jsxs("div",{className:"mb-2 flex w-full max-w-md flex-col gap-1 rounded border bg-accent/60 p-2 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-x-2 text-xs",children:[e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"Compare"}),d&&e.jsx(A,{tab:d,onRemove:m}),e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"with"}),u?e.jsx(A,{tab:u,onRemove:m}):e.jsx("span",{className:"rounded border px-1 text-xs text-muted-foreground",children:"Choose another"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pb-0.5 pt-2",children:[e.jsx(N.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none text-gray-500",variant:"outline",onClick:()=>n([]),children:e.jsx("span",{children:" Clear"})}),e.jsxs(N.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none",variant:"default",onClick:()=>l(!0),disabled:s.length<2,children:[e.jsx(f.FileJson,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"pt-0.5",children:"Show JSON Diff"})]})]}),r&&(s==null?void 0:s.length)>1&&t&&e.jsx(g.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx("span",{className:"text-sm",children:"Loading diff viewer..."})}),children:e.jsx($,{open:r,onOpenChange:l,compare:s})})]})}function O({checked:s,disabled:n,onChange:t,label:r="Compare"}){return e.jsx("div",{className:"absolute bottom-2 right-2",children:e.jsxs("label",{className:`flex cursor-pointer items-center gap-x-1 text-[11px] ${n?"opacity-50":""}`,children:[e.jsx("input",{type:"checkbox",className:"h-3 w-3 cursor-pointer rounded focus:ring-0 focus:ring-offset-0",checked:s,disabled:n,onChange:t}),e.jsx("span",{className:"select-none leading-tight",children:r})]})})}function Y({revision:s,onRestore:n,onDelete:t}){return e.jsxs(i.DropdownMenu,{children:[e.jsx(i.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(N.Button,{variant:"ghost",size:"icon",className:"h-5 w-5",children:[e.jsx(f.MoreHorizontal,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More options"})]})}),e.jsxs(i.DropdownMenuContent,{align:"end",className:"text-xs",children:[e.jsx(c.PermissionChecker,{permission:c.PAGES_PERMISSIONS.RESTORE_REVISION,children:e.jsxs(i.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-sm",children:[e.jsx(f.Undo2,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Restore this version"})]})}),e.jsx(c.PermissionChecker,{permission:c.PAGES_PERMISSIONS.DELETE_REVISION,children:s.uid!=="current"&&e.jsxs(e.Fragment,{children:[e.jsx(i.DropdownMenuSeparator,{}),e.jsxs(i.DropdownMenuItem,{onClick:t,className:"cursor-pointer text-destructive",children:[e.jsx(f.Trash,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Delete this version"})]})]})})]})]})}function X({open:s,onOpenChange:n,revision:t,onRestore:r,isRestoring:l}){const{data:d}=c.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),u=(d==null?void 0:d.name)||"Unknown";return t?e.jsx(i.Dialog,{open:s,onOpenChange:m=>{l||n(m)},children:e.jsxs(i.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(i.DialogHeader,{children:[e.jsx(i.DialogTitle,{children:"Restore Revision"}),e.jsxs(i.DialogDescription,{children:["You are about to restore to revision ",t.uid.substring(0,8)," from"," ",S.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",u]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"How would you like to handle your current edits?"})}),e.jsxs(i.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(N.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>r(!1),disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Saving as draft..."]}):e.jsxs(e.Fragment,{children:[e.jsx(f.CloudOff,{className:"mr-2 h-4 w-4"}),"Save as draft"]})}),e.jsx(N.Button,{variant:"default",className:"sm:flex-1",onClick:()=>r(!0),disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Discarding current..."]}):e.jsxs(e.Fragment,{children:[e.jsx(f.Undo2,{className:"mr-2 h-4 w-4"}),"Discard current"]})})]})]})}):null}function Z({open:s,onOpenChange:n,revision:t,onDelete:r,isDeleting:l}){const{data:d}=c.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),u=(d==null?void 0:d.name)||"Unknown";return t?e.jsx(i.Dialog,{open:s,onOpenChange:m=>{l||n(m)},children:e.jsxs(i.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(i.DialogHeader,{children:[e.jsx(i.DialogTitle,{children:"Delete Revision"}),e.jsxs(i.DialogDescription,{children:["You are about to delete revision ",t.uid.substring(0,8)," from"," ",S.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",u]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"This action cannot be undone. Are you sure you want to proceed?"})}),e.jsxs(i.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(N.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>n(!1),disabled:l,children:"Cancel"}),e.jsx(N.Button,{variant:"destructive",className:"sm:flex-1",onClick:r,disabled:l,children:l?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Deleting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(f.Trash,{className:"mr-2 h-4 w-4"}),"Delete Revision"]})})]})]})}):null}function ee({isOpen:s}){var R;const[n,t]=w.useState([]),[r,l]=w.useState(null),[d,u]=w.useState(!1),[m,x]=w.useState(!1),{data:a}=c.usePrimaryPage(),{data:p,isFetching:D,error:h,refetch:j}=Q(a==null?void 0:a.id),{mutate:T,isPending:M}=z(),{mutate:k,isPending:F}=H(),_=y.useQueryClient(),{selectedLang:P,fallbackLang:q}=i.useLanguages(),U=P||q;g.useEffect(()=>{g.startTransition(()=>t([]))},[a==null?void 0:a.id]);const G=o=>{r&&k({revisionId:r.uid,discardCurrent:o,...r.uid==="current"&&(a==null?void 0:a.id)&&{pageId:a.id}},{onSuccess:()=>{u(!1),l(null),_.invalidateQueries({queryKey:[c.ACTIONS.GET_DRAFT_PAGE]})}})},C=o=>{l(o),u(!0)},E=o=>{l(o),x(!0)},V=()=>{r&&T(r.uid,{onSuccess:()=>{x(!1),l(null)}})};return g.useEffect(()=>{s&&j()},[s,j]),e.jsxs(e.Fragment,{children:[e.jsxs(i.SheetHeader,{children:[e.jsx(i.SheetTitle,{children:"Revision History"}),(a==null?void 0:a.createdAt)&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Page created on ",S.format(new Date(a.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),D?e.jsx(K,{}):h?e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Failed to load revisions. Please try again."}):e.jsxs("div",{className:"mt-2 flex h-full min-h-0 flex-1 flex-col space-y-2",children:[e.jsx(W,{lang:U,compare:n,setCompare:t,pageId:a==null?void 0:a.id}),e.jsx(J,{compare:n,setCompare:t}),(R=p==null?void 0:p.filter(o=>o.uid==="current"))==null?void 0:R.map((o,v)=>e.jsx(I,{pageId:a==null?void 0:a.id,revision:o,isLatest:!0,onRestore:()=>C(o),onDelete:()=>E(o),revisionNumber:v,compare:n,setCompare:t},o.uid)),e.jsx(i.ScrollArea,{className:"min-h-0 flex-1",children:e.jsx("div",{className:"space-y-2",children:[...p??[]].filter(o=>o.uid!=="current").sort((o,v)=>new Date(v.createdAt).getTime()-new Date(o.createdAt).getTime()).map((o,v)=>e.jsx(I,{pageId:a==null?void 0:a.id,revision:o,isLatest:o.uid==="current",onRestore:()=>C(o),onDelete:()=>E(o),revisionNumber:v+1,compare:n,setCompare:t},o.uid))})})]}),e.jsx(X,{open:d,onOpenChange:u,revision:r,onRestore:G,isRestoring:F}),e.jsx(Z,{open:m,onOpenChange:x,revision:r,onDelete:V,isDeleting:M})]})}exports.default=ee;
|
package/dist/pages.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-CzBSRTj0.cjs");exports.ChaiAiPanel=e.AiPanelContent;exports.ChaiJsonInput=e.SmartJsonInput;exports.ChaiWebsiteBuilder=e.ChaiWebsiteBuilder;exports.ImagePicker=e.ImagePicker;exports.LanguageSwitcher=e.LanguageSwitcher;exports.NestedPathSelector=e.NestedPathSelector;exports.PermissionChecker=e.PermissionChecker;exports.SupabaseRealtimeAdapter=e.SupabaseRealtimeAdapter;exports.createRealtimeAdapter=e.createRealtimeAdapter;exports.useActivePage=e.useCurrentActivePage;exports.useApiUrl=e.useApiUrl;exports.useBuilderFetch=e.useBuilderFetch;exports.useBuilderPageData=e.useBuilderPageData;exports.useChaiAuth=e.useChaiAuth;exports.useChaiPrimaryPage=e.usePrimaryPage;exports.useChaiUserInfo=e.useChaiUserInfo;exports.useClearAll=e.useClearAll;exports.useFallbackLang=e.useFallbackLang;exports.useFetch=e.useFetch;exports.useGotoPage=e.useGotoPage;exports.useLanguagePages=e.useLanguagePages;exports.usePageAllData=e.usePageAllData;exports.usePageTypes=e.usePageTypes;exports.useRealtimeAdapter=e.useRealtimeAdapter;exports.useReloadPage=e.useReloadPage;exports.useUpdateActivePageMetadata=e.useUpdateActivePageMetadata;exports.useUserPermissions=e.useCheckUserAccess;exports.useWebsitePages=e.useWebsitePrimaryPages;exports.useWebsiteSetting=e.useWebsiteSetting;
|
package/dist/pages.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a$ as s, aF as t, aU as i, aQ as u, aO as r, aP as g, aw as l, b5 as P, b4 as h, aV as b, aq as o, b3 as c, aL as d, b1 as n, av as A, ao as p, aW as m, i as C, ar as U, aX as k, j as F, aY as L, k as R, b0 as S, aZ as W, a_ as v, b2 as B, e as I, h as f } from "./index-
|
|
1
|
+
import { a$ as s, aF as t, aU as i, aQ as u, aO as r, aP as g, aw as l, b5 as P, b4 as h, aV as b, aq as o, b3 as c, aL as d, b1 as n, av as A, ao as p, aW as m, i as C, ar as U, aX as k, j as F, aY as L, k as R, b0 as S, aZ as W, a_ as v, b2 as B, e as I, h as f } from "./index-nzqILA37.js";
|
|
2
2
|
export {
|
|
3
3
|
s as ChaiAiPanel,
|
|
4
4
|
t as ChaiJsonInput,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsxs as n, jsx as t, Fragment as $ } from "react/jsx-runtime";
|
|
2
2
|
import { B as L } from "./register-chai-top-bar-D6GjnauV.js";
|
|
3
3
|
import { e as K, f as Q, g as J, o as V, q as W } from "./index-OuHV9Ann.js";
|
|
4
|
-
import { aq as X, ar as Y, A as I, aA as O, aB as Z, i as ee, k as te, ao as se, T as U, aC as le } from "./index-
|
|
5
|
-
import { LanguageSelector as ae } from "./page-manager-search-and-filter-
|
|
4
|
+
import { aq as X, ar as Y, A as I, aA as O, aB as Z, i as ee, k as te, ao as se, T as U, aC as le } from "./index-nzqILA37.js";
|
|
5
|
+
import { LanguageSelector as ae } from "./page-manager-search-and-filter-BwxrJZgv.js";
|
|
6
6
|
import { useQuery as ne } from "@tanstack/react-query";
|
|
7
7
|
import { find as B, filter as a, map as b, keys as re, get as F, includes as P, orderBy as N, isEmpty as oe, uniq as G, first as ce, concat as ie } from "lodash-es";
|
|
8
8
|
import { Lock as de, GlobeIcon as ue, File as he, Edit as me } from "lucide-react";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),q=require("./register-chai-top-bar-DyW9GPzV.cjs"),f=require("./index-DCJDQs1a.cjs"),r=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),q=require("./register-chai-top-bar-DyW9GPzV.cjs"),f=require("./index-DCJDQs1a.cjs"),r=require("./index-CzBSRTj0.cjs"),U=require("./page-manager-search-and-filter-BE7w_2hv.cjs"),F=require("@tanstack/react-query"),t=require("lodash-es"),b=require("lucide-react"),a=require("react"),M=()=>{const l=r.useApiUrl(),u=r.useFetch();return F.useQuery({queryKey:[r.ACTIONS.GET_CHANGES],queryFn:async()=>u(l,{action:r.ACTIONS.GET_CHANGES})})},G=({page:l,selectedPages:u,handleCheckboxChange:N,getPageType:y,hasSlug:h,currentOwnerId:c})=>{const x=r.useUserId(),{data:d}=r.useChaiUserInfo(c),o=c===x?null:d==null?void 0:d.name;return e.jsxs("tr",{className:"group relative border-b last:border-b-0 hover:bg-gray-50",children:[e.jsxs("td",{scope:"row",className:`flex items-center gap-x-1 whitespace-nowrap px-6 py-2 text-gray-900 dark:text-white ${o?"opacity-50":""}`,children:[o?e.jsx(b.Lock,{className:"h-4 w-4 fill-red-200 text-red-500"}):e.jsx("input",{checked:t.includes(u,l==null?void 0:l.id),onClick:p=>{p.stopPropagation(),N(l==null?void 0:l.id)},type:"checkbox",className:"cursor-pointer rounded focus:outline-none focus:ring-0"})," ",h(l.pageType)?e.jsx(b.File,{className:"h-4 w-4"}):e.jsx(b.GlobeIcon,{className:"h-4 w-4"}),e.jsx(r.Tooltip,{content:l.name,side:"top",showTooltip:l.name.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-medium text-black",children:l.name})}),l.slug&&e.jsx(r.Tooltip,{content:l.slug,side:"top",showTooltip:l.slug.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-mono text-xs text-muted-foreground",children:l.slug})})]}),e.jsx("td",{className:"px-2",children:y(l==null?void 0:l.pageType)}),e.jsx("td",{className:"px-4 text-right",children:t.first(l.changes)||""}),e.jsx(e.Fragment,{children:o&&e.jsxs("button",{className:"absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100",children:[e.jsx(b.Edit,{size:12,className:"stroke-[3]"})," ",e.jsx("span",{className:"font-medium",children:o})," is editing this page"]})})]},l==null?void 0:l.id)},O=({onClose:l=()=>{},isPending:u,publishPage:N})=>{const y=r.useUserId(),{pageToUser:h}=r.usePageToUser(),[c,x]=a.useState([]),d=r.useFallbackLang(),[o,p]=a.useState(d),{data:T,isFetching:C}=M(),{data:g}=r.usePageTypes(),k=a.useCallback(s=>{var n;return(n=t.find(g,{key:s}))==null?void 0:n.hasSlug},[g]),j=a.useMemo(()=>t.filter(g,s=>!k(s.key)).map(s=>s.key),[k,g]),P=t.uniq(t.map(T,"lang")).filter(Boolean),i=a.useMemo(()=>t.filter(T,s=>s.pageType==="theme"||s.pageType==="design_tokens"?!1:o===d?s.lang===o||s.lang==="":s.lang===o),[T,o,d]),w=a.useMemo(()=>t.filter(i,s=>!j.includes(s.pageType)),[i,j]),S=a.useMemo(()=>t.filter(i,s=>j.includes(s.pageType)),[i,j]);a.useEffect(()=>{const s=t.map(t.filter(i,{online:!0}),"id");a.startTransition(()=>x(s))},[i]),a.useEffect(()=>{const s=t.filter(t.keys(h),n=>t.get(h,[n,"userId"])!==y);a.startTransition(()=>x(n=>t.filter(n,m=>!t.includes(s,m))))},[h,y]);const v=c.length===(i==null?void 0:i.length),E=s=>{x(n=>t.includes(n,s)?t.filter(n,m=>m!==s):t.concat(n,s))},B=()=>{x(v?[]:t.map(i,"id"))},I=()=>{N({ids:t.uniq(c)},{onSuccess:()=>{l(),r.throwConfetti("CENTER_CENTER"),p(d)}})},A=s=>{if(s==="theme")return"Theme";const n=t.find(g,{key:s});return n?n==null?void 0:n.name:s},L=a.useMemo(()=>{const s=[{label:"Updated",top:"pt-2"},...t.orderBy(t.filter(w,{online:!0}),"pageType"),...t.orderBy(t.filter(S,{online:!0}),"pageType")].filter(m=>m.pageType!=="theme"&&m.pageType!=="design_tokens"),n=[{label:"Offline",top:"pt-6"},...t.orderBy(t.filter(w,{online:!1}),"pageType"),...t.orderBy(t.filter(S,{online:!1}),"pageType")];return[...s,...n]},[w,S]);return e.jsxs(f.DialogContent,{className:"flex max-h-[80%] max-w-4xl flex-col",children:[e.jsxs(f.DialogHeader,{children:[e.jsx(f.DialogTitle,{children:"Publish changes"}),e.jsx(f.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),P.length>0&&e.jsx("div",{className:"my-[2px] mt-0",children:e.jsx(U.LanguageSelector,{languages:[d,...P],selectedLanguage:o,setSelectedLanguage:p})}),e.jsx("div",{className:"no-scrollbar relative -mx-4 -mt-4 h-full max-h-full overflow-y-auto",children:C?e.jsxs("div",{className:"space-y-2 px-1",children:[e.jsx("div",{className:"mt-2 h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):e.jsxs("table",{className:"w-full text-left text-xs text-gray-500 dark:text-gray-400 rtl:text-right",children:[e.jsx("thead",{className:"sticky top-0 z-10 border-b bg-gray-50 text-gray-700 dark:bg-gray-700 dark:text-gray-400",children:e.jsxs("tr",{children:[e.jsxs("th",{scope:"col",className:"w-[1 50px] flex items-center gap-x-2 px-6 py-3",children:[e.jsx("input",{checked:v,onClick:s=>{s.stopPropagation(),B()},type:"checkbox",className:"mt-1 cursor-pointer rounded focus:outline-none focus:ring-0"}),"Name"]}),e.jsx("th",{scope:"col",className:"w-[150px] px-2 py-3",children:"Type"}),e.jsx("th",{scope:"col",className:"w-[150px] px-4 py-3 text-right",children:"Status"})]})}),e.jsx("tbody",{children:t.map(L,s=>s.label?e.jsx("tr",{children:e.jsxs("td",{colSpan:3,className:`relative px-6 py-2 text-xs font-medium text-gray-800 ${s.top}`,children:[e.jsx("div",{className:"absolute inset-0 left-6 flex items-center",children:e.jsx("div",{className:"order-gray-300 w-full"})}),e.jsx("div",{className:"relative flex justify-start",children:e.jsx("span",{className:"bg-gray-50 pr-2",children:s.label})})]})},"separator"):e.jsx(G,{page:s,selectedPages:c,handleCheckboxChange:E,getPageType:A,hasSlug:k,currentOwnerId:t.get(h,[(s==null?void 0:s.primaryPage)||(s==null?void 0:s.id),"userId"])}))})]})}),e.jsxs(f.DialogFooter,{className:"mt-10 flex items-center justify-center",children:[c.length>0&&e.jsxs("span",{className:"text-center text-sm text-muted-foreground",children:[c.length," Page",c.length!==1?"s":""," Selected"]}),e.jsx(q.Button,{disabled:u,variant:"outline",onClick:l,children:"Cancel"}),e.jsx(q.Button,{disabled:u||C||t.isEmpty(c),onClick:I,children:u?"Publishing...":"Publish Selected"})]})]})};exports.default=O;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as e, jsxs as i } from "react/jsx-runtime";
|
|
2
2
|
import { B as b, z as L } from "./register-chai-top-bar-D6GjnauV.js";
|
|
3
3
|
import { aF as ne, c as M, X as ie, Y as oe, P as le, aG as ce, ax as de, aH as ue, p as P } from "./index-OuHV9Ann.js";
|
|
4
|
-
import { aq as D, ar as G, A as _, ax as me } from "./index-
|
|
4
|
+
import { aq as D, ar as G, A as _, ax as me } from "./index-nzqILA37.js";
|
|
5
5
|
import { useQuery as K, useMutation as A, useQueryClient as pe } from "@tanstack/react-query";
|
|
6
6
|
import { useSetAtom as fe } from "jotai";
|
|
7
7
|
import { toast as N } from "sonner";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./register-chai-top-bar-DyW9GPzV.cjs"),x=require("./index-DCJDQs1a.cjs"),b=require("./index-BVwFJWDq.cjs"),C=require("@tanstack/react-query"),X=require("jotai"),j=require("sonner"),E=require("lucide-react"),i=require("react"),J=require("./image-compression-UaU7Bwqe.cjs"),R=require("lodash-es"),Z=s=>{const r=b.useApiUrl(),l=b.useFetch();return C.useMutation({mutationFn:async t=>l(r,{action:b.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{s?s(t):j.toast.success("Block saved successfully")},onError:t=>{console.error("Error saving block:",t),j.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},ee=s=>{const r=b.useApiUrl(),l=b.useFetch();return C.useQuery({staleTime:"static",queryKey:[b.ACTIONS.GET_LIBRARY_ITEM,s],enabled:!!s,queryFn:async()=>{if(!s)return null;try{return await l(r,{action:b.ACTIONS.GET_LIBRARY_ITEM,data:{id:s}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},te=s=>{const r=b.useApiUrl(),l=b.useFetch(),t=X.useSetAtom(x.libraryBlocksAtom);return C.useMutation({mutationFn:async c=>l(r,{action:b.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:c}}),onSuccess:()=>{t(c=>{const m={...c};return Object.keys(m).forEach(u=>{m[u]={loading:"idle",blocks:[],error:!1}}),m}),s?s():j.toast.success("Block deleted successfully")},onError:c=>{console.error("Error deleting block:",c),j.toast.error("Failed to delete block",{description:c instanceof Error?c.message:"Unknown error"})}})},se=({blockId:s,libBlockId:r,isOpen:l,onClose:t,blockName:c,trigger:m})=>{const[u,o]=i.useState(!1),d=x.useUpdateBlocksPropsRealtime(),y=te(()=>{d([s],{_libBlockId:void 0}),j.toast.success("Block deleted successfully"),o(!1),t()}),h=()=>{o(!0),y.mutate(r)},g=e.jsxs(p.Button,{type:"button",variant:"destructive",size:"sm",onClick:f=>f.preventDefault(),disabled:u,children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]});return e.jsxs(x.Popover,{open:l,onOpenChange:f=>!f&&t(),children:[e.jsx(x.PopoverTrigger,{asChild:!0,children:m||g}),e.jsx(x.PopoverContent,{className:"z-[9999] w-72 p-4",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',c,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(p.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:u,children:"Cancel"}),e.jsx(p.Button,{type:"button",variant:"destructive",size:"sm",onClick:h,disabled:u,children:u?"Deleting...":"Delete"})]})]})})]})},re=({blockId:s,libBlockId:r,blockName:l,size:t="sm",className:c="",close:m})=>{const[u,o]=i.useState(!1);return e.jsx(se,{blockId:s,libBlockId:r,isOpen:u,onClose:()=>{o(!1),m()},blockName:l,trigger:e.jsxs(p.Button,{type:"button",variant:"destructive",size:t,className:c,onClick:()=>o(!0),children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})})},ne=()=>{const s=b.useApiUrl(),r=b.useFetch(),l=C.useQueryClient(),{data:t=[],isLoading:c,error:m}=C.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await r(s,{action:"GET_LIBRARY_GROUPS"})||[]}catch(d){return console.error("Error fetching library groups:",d),[]}}}),{mutateAsync:u,isPending:o}=C.useMutation({mutationFn:async d=>{if(!d.trim())throw new Error("Group name is required");return r(s,{action:"CREATE_BLOCK_GROUP",data:{name:d}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),j.toast.success("Group created successfully")},onError:d=>{console.error("Error creating group:",d),j.toast.error("Failed to create group",{description:d instanceof Error?d.message:"Unknown error"})}});return{groups:t,isLoading:c,error:m,createGroup:u,isCreating:o}},ae=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),[c,m]=i.useState(""),u=i.useRef(null),{groups:o}=ne(),[d,y]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),h=i.useMemo(()=>[...o,...d.filter(n=>!o.some(B=>B.id===n.id))],[o,d]),g=()=>{const n=c.trim();if(!n)return;const B={id:n,name:n};y(w=>[...w,B]),r(B.id),m(""),t(!1)};i.useEffect(()=>{l&&u.current&&u.current.focus()},[l]);const f=n=>{n.key==="Enter"&&(n.preventDefault(),g())};return i.useEffect(()=>{s&&!h.some(n=>n.id===s)&&r("")},[s,h,r]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(p.Input,{ref:u,placeholder:"Enter new group name",value:c,onChange:n=>m(n.target.value),onKeyDown:f}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(p.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(p.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:s,onChange:n=>r(n.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(n=>e.jsx("option",{value:n.id,children:n.name},`lib-${n.id}`))}),d.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:d.filter(n=>!o.some(B=>B.id===n.id)).map(n=>e.jsx("option",{value:n.id,children:n.name},`local-${n.id}`))})]}),e.jsx(p.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(E.Plus,{className:"h-4 w-4"})})]})},oe=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),c=i.useRef(null),m=i.useCallback(async d=>{var h;const y=(h=d.target.files)==null?void 0:h[0];if(y)try{t(!0);let g=y;y.type.startsWith("image/")&&(g=await J.compressImageIfNeeded(y));const f=new FileReader;f.onloadend=()=>{r(f.result),t(!1)},f.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),j.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[r]),u=()=>{r(""),c.current&&(c.current.value="")},o=()=>{var d;(d=c.current)==null||d.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p.Input,{type:"file",ref:c,onChange:m,accept:"image/*",className:"hidden"}),e.jsx(p.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(E.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),s&&e.jsx(p.Button,{type:"button",variant:"outline",size:"icon",onClick:u,children:e.jsx(E.X,{className:"h-4 w-4"})})]}),s&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:s,alt:"Preview",className:"h-full w-full object-contain"})})]})},ie=s=>{const{blocks:r,close:l,blockId:t}=s,{getPartialBlocks:c}=x.usePartialBlocksStore(),m=r.find(a=>a._id===t),u=m==null?void 0:m._libBlockId,o=!!u,d=i.useMemo(()=>r.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[r]),y=i.useMemo(()=>{let a=[];for(const k of r)if(k._type==="PartialBlock"||k._type==="GlobalBlock"){let v=c(k.partialBlockId);k._parent&&(v==null?void 0:v.length)>0&&(v=v.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",k._parent),T))),a=[...a,...v]}else a.push(k);return a},[r,c]),[h,g]=i.useState(""),[f,n]=i.useState(""),[B,w]=i.useState(""),[S,_]=i.useState(""),[N,U]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=x.usePermissions(),Q=Y(b.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=x.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),j.toast.success("Block delinked from library"),l()},{data:I,isLoading:P,isError:G}=ee(u);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{I&&!P&&(g(I.name||""),n(I.group||""),w(I.description||""),_(I.preview||""),F(!1))},[I,P]),i.useEffect(()=>{const a=h.trim().length>=2,k=f.trim()!=="";M(a&&k)},[h,f]);const W=()=>{const a={};return h.trim()?h.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",f||(a.group="Group is required"),U(a),Object.keys(a).length===0},{resetLibrary:$}=x.useLibraryBlocks({id:""}),A=Z(a=>{o||D([t],{_libBlockId:a.id}),j.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const k=y.map(v=>(R.has(v,"_libBlockId")&&delete v._libBlockId,v));A.mutate({name:h.trim(),group:f,blocks:k,description:B.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:u}:{}})},L=A.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(p.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(p.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[d&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(E.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(p.Input,{id:"name",placeholder:"Enter block name",value:h,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ae,{value:f,onChange:n}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(p.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:B,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(oe,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(re,{blockId:t,libBlockId:u,blockName:h,className:"mr-auto",close:l}),e.jsx(p.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(p.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=ie;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./register-chai-top-bar-DyW9GPzV.cjs"),x=require("./index-DCJDQs1a.cjs"),b=require("./index-CzBSRTj0.cjs"),C=require("@tanstack/react-query"),X=require("jotai"),j=require("sonner"),E=require("lucide-react"),i=require("react"),J=require("./image-compression-UaU7Bwqe.cjs"),R=require("lodash-es"),Z=s=>{const r=b.useApiUrl(),l=b.useFetch();return C.useMutation({mutationFn:async t=>l(r,{action:b.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{s?s(t):j.toast.success("Block saved successfully")},onError:t=>{console.error("Error saving block:",t),j.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},ee=s=>{const r=b.useApiUrl(),l=b.useFetch();return C.useQuery({staleTime:"static",queryKey:[b.ACTIONS.GET_LIBRARY_ITEM,s],enabled:!!s,queryFn:async()=>{if(!s)return null;try{return await l(r,{action:b.ACTIONS.GET_LIBRARY_ITEM,data:{id:s}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},te=s=>{const r=b.useApiUrl(),l=b.useFetch(),t=X.useSetAtom(x.libraryBlocksAtom);return C.useMutation({mutationFn:async c=>l(r,{action:b.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:c}}),onSuccess:()=>{t(c=>{const m={...c};return Object.keys(m).forEach(u=>{m[u]={loading:"idle",blocks:[],error:!1}}),m}),s?s():j.toast.success("Block deleted successfully")},onError:c=>{console.error("Error deleting block:",c),j.toast.error("Failed to delete block",{description:c instanceof Error?c.message:"Unknown error"})}})},se=({blockId:s,libBlockId:r,isOpen:l,onClose:t,blockName:c,trigger:m})=>{const[u,o]=i.useState(!1),d=x.useUpdateBlocksPropsRealtime(),y=te(()=>{d([s],{_libBlockId:void 0}),j.toast.success("Block deleted successfully"),o(!1),t()}),h=()=>{o(!0),y.mutate(r)},g=e.jsxs(p.Button,{type:"button",variant:"destructive",size:"sm",onClick:f=>f.preventDefault(),disabled:u,children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]});return e.jsxs(x.Popover,{open:l,onOpenChange:f=>!f&&t(),children:[e.jsx(x.PopoverTrigger,{asChild:!0,children:m||g}),e.jsx(x.PopoverContent,{className:"z-[9999] w-72 p-4",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',c,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(p.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:u,children:"Cancel"}),e.jsx(p.Button,{type:"button",variant:"destructive",size:"sm",onClick:h,disabled:u,children:u?"Deleting...":"Delete"})]})]})})]})},re=({blockId:s,libBlockId:r,blockName:l,size:t="sm",className:c="",close:m})=>{const[u,o]=i.useState(!1);return e.jsx(se,{blockId:s,libBlockId:r,isOpen:u,onClose:()=>{o(!1),m()},blockName:l,trigger:e.jsxs(p.Button,{type:"button",variant:"destructive",size:t,className:c,onClick:()=>o(!0),children:[e.jsx(E.Trash2,{className:"mr-2 h-4 w-4"}),"Delete"]})})},ne=()=>{const s=b.useApiUrl(),r=b.useFetch(),l=C.useQueryClient(),{data:t=[],isLoading:c,error:m}=C.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await r(s,{action:"GET_LIBRARY_GROUPS"})||[]}catch(d){return console.error("Error fetching library groups:",d),[]}}}),{mutateAsync:u,isPending:o}=C.useMutation({mutationFn:async d=>{if(!d.trim())throw new Error("Group name is required");return r(s,{action:"CREATE_BLOCK_GROUP",data:{name:d}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),j.toast.success("Group created successfully")},onError:d=>{console.error("Error creating group:",d),j.toast.error("Failed to create group",{description:d instanceof Error?d.message:"Unknown error"})}});return{groups:t,isLoading:c,error:m,createGroup:u,isCreating:o}},ae=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),[c,m]=i.useState(""),u=i.useRef(null),{groups:o}=ne(),[d,y]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),h=i.useMemo(()=>[...o,...d.filter(n=>!o.some(B=>B.id===n.id))],[o,d]),g=()=>{const n=c.trim();if(!n)return;const B={id:n,name:n};y(w=>[...w,B]),r(B.id),m(""),t(!1)};i.useEffect(()=>{l&&u.current&&u.current.focus()},[l]);const f=n=>{n.key==="Enter"&&(n.preventDefault(),g())};return i.useEffect(()=>{s&&!h.some(n=>n.id===s)&&r("")},[s,h,r]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(p.Input,{ref:u,placeholder:"Enter new group name",value:c,onChange:n=>m(n.target.value),onKeyDown:f}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(p.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(p.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:s,onChange:n=>r(n.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(n=>e.jsx("option",{value:n.id,children:n.name},`lib-${n.id}`))}),d.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:d.filter(n=>!o.some(B=>B.id===n.id)).map(n=>e.jsx("option",{value:n.id,children:n.name},`local-${n.id}`))})]}),e.jsx(p.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(E.Plus,{className:"h-4 w-4"})})]})},oe=({value:s,onChange:r})=>{const[l,t]=i.useState(!1),c=i.useRef(null),m=i.useCallback(async d=>{var h;const y=(h=d.target.files)==null?void 0:h[0];if(y)try{t(!0);let g=y;y.type.startsWith("image/")&&(g=await J.compressImageIfNeeded(y));const f=new FileReader;f.onloadend=()=>{r(f.result),t(!1)},f.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),j.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[r]),u=()=>{r(""),c.current&&(c.current.value="")},o=()=>{var d;(d=c.current)==null||d.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(p.Input,{type:"file",ref:c,onChange:m,accept:"image/*",className:"hidden"}),e.jsx(p.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(E.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),s&&e.jsx(p.Button,{type:"button",variant:"outline",size:"icon",onClick:u,children:e.jsx(E.X,{className:"h-4 w-4"})})]}),s&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:s,alt:"Preview",className:"h-full w-full object-contain"})})]})},ie=s=>{const{blocks:r,close:l,blockId:t}=s,{getPartialBlocks:c}=x.usePartialBlocksStore(),m=r.find(a=>a._id===t),u=m==null?void 0:m._libBlockId,o=!!u,d=i.useMemo(()=>r.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[r]),y=i.useMemo(()=>{let a=[];for(const k of r)if(k._type==="PartialBlock"||k._type==="GlobalBlock"){let v=c(k.partialBlockId);k._parent&&(v==null?void 0:v.length)>0&&(v=v.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",k._parent),T))),a=[...a,...v]}else a.push(k);return a},[r,c]),[h,g]=i.useState(""),[f,n]=i.useState(""),[B,w]=i.useState(""),[S,_]=i.useState(""),[N,U]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=x.usePermissions(),Q=Y(b.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=x.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),j.toast.success("Block delinked from library"),l()},{data:I,isLoading:P,isError:G}=ee(u);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{I&&!P&&(g(I.name||""),n(I.group||""),w(I.description||""),_(I.preview||""),F(!1))},[I,P]),i.useEffect(()=>{const a=h.trim().length>=2,k=f.trim()!=="";M(a&&k)},[h,f]);const W=()=>{const a={};return h.trim()?h.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",f||(a.group="Group is required"),U(a),Object.keys(a).length===0},{resetLibrary:$}=x.useLibraryBlocks({id:""}),A=Z(a=>{o||D([t],{_libBlockId:a.id}),j.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const k=y.map(v=>(R.has(v,"_libBlockId")&&delete v._libBlockId,v));A.mutate({name:h.trim(),group:f,blocks:k,description:B.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:u}:{}})},L=A.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(p.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(p.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[d&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(E.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(p.Input,{id:"name",placeholder:"Enter block name",value:h,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ae,{value:f,onChange:n}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(p.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:B,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(x.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(oe,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(re,{blockId:t,libBlockId:u,blockName:h,className:"mr-auto",close:l}),e.jsx(p.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(p.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=ie;
|
|
@@ -14,7 +14,7 @@ import * as A from "@radix-ui/react-tooltip";
|
|
|
14
14
|
import { useControllableState as w } from "@radix-ui/react-use-controllable-state";
|
|
15
15
|
import * as x from "@radix-ui/react-collapsible";
|
|
16
16
|
import { motion as V } from "framer-motion";
|
|
17
|
-
import { L as h } from "./index-
|
|
17
|
+
import { L as h } from "./index-nzqILA37.js";
|
|
18
18
|
import { useTranslation as Y } from "react-i18next";
|
|
19
19
|
const Te = ({ className: e, ...t }) => /* @__PURE__ */ o(
|
|
20
20
|
R,
|