@chaibuilder/pages 0.15.5 → 0.15.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{2AITGKQY-D4uLyw6-.cjs → 2AITGKQY-BGvx_OEz.cjs} +1 -1
- package/dist/{2AITGKQY-DYwNjBFe.js → 2AITGKQY-CCad8XK8.js} +2 -2
- package/dist/{NCMVHL6D-C-L7-X3f.cjs → NCMVHL6D-C_u5lHQe.cjs} +1 -1
- package/dist/{NCMVHL6D-DVB60g_2.js → NCMVHL6D-Iv9ufIUy.js} +2 -2
- package/dist/{ZDWCUMSJ-BORULBXb.cjs → ZDWCUMSJ-BqZPKNlU.cjs} +1 -1
- package/dist/{ZDWCUMSJ-Dp6ML_tn.js → ZDWCUMSJ-DT4dg62a.js} +1 -1
- package/dist/add-new-language-page-CfH8Ernl.js +401 -0
- package/dist/add-new-language-page-DlQjzp--.cjs +1 -0
- package/dist/add-new-page-DH-nv7ae.cjs +1 -0
- package/dist/add-new-page-DX1aQA56.js +31 -0
- package/dist/delete-page-DE-nabXs.js +40 -0
- package/dist/delete-page-WPGzECyJ.cjs +1 -0
- package/dist/digital-asset-manager-CGLE6VEW.cjs +1 -0
- package/dist/digital-asset-manager-DtWIJGhf.js +913 -0
- package/dist/duplicate-page-C1r3iBDY.js +133 -0
- package/dist/duplicate-page-CByLwz0z.cjs +1 -0
- package/dist/{dynamic-page-selector-8g1-84iW.js → dynamic-page-selector-Bk8_xgFx.js} +1 -1
- package/dist/{dynamic-page-selector-Cz6zWaKo.cjs → dynamic-page-selector-GwGV0Q6Z.cjs} +1 -1
- package/dist/image-editor-CeSSNbFY.js +108 -0
- package/dist/image-editor-CnDnY97s.cjs +1 -0
- package/dist/index-BELYt0c9.cjs +5 -0
- package/dist/{index-zaGKeGBW.js → index-Djepisz3.js} +1168 -1219
- package/dist/index.cjs +1 -1
- package/dist/index.js +10 -10
- package/dist/{json-diff-viewer-c3ft4c4A.cjs → json-diff-viewer-BUhKwjf9.cjs} +1 -1
- package/dist/{json-diff-viewer-BF0qFBif.js → json-diff-viewer-zKpzQFxw.js} +1 -1
- package/dist/lang-panel-BYF6aLAt.cjs +1 -0
- package/dist/lang-panel-CtpuO-KH.js +225 -0
- package/dist/mark-as-template-0kikl0oL.js +153 -0
- package/dist/mark-as-template-wRAGJGtp.cjs +1 -0
- package/dist/no-language-page-content-B1M_x_U7.js +42 -0
- package/dist/no-language-page-content-DX9WXKXs.cjs +1 -0
- package/dist/{page-creator-Crc5BzeB.js → page-creator-BDJ6iDX9.js} +2 -2
- package/dist/{page-creator-CsZpQ7Gy.cjs → page-creator-DuN5JD41.cjs} +1 -1
- package/dist/page-lock-request-Bc_vwJhy.js +75 -0
- package/dist/page-lock-request-PRQo0DDm.cjs +1 -0
- package/dist/page-locked-by-dialog-DiKNpVwH.js +68 -0
- package/dist/page-locked-by-dialog-Dk0G2l7a.cjs +1 -0
- package/dist/page-manager-new-CUHqC9Og.js +354 -0
- package/dist/page-manager-new-KBhn93Yd.cjs +1 -0
- package/dist/page-manager-search-and-filter-CJ4AK1_7.js +201 -0
- package/dist/page-manager-search-and-filter-Ck5_TfNx.cjs +1 -0
- package/dist/{page-revisions-content-dSFvGFEO.cjs → page-revisions-content-Cw2cumYS.cjs} +1 -1
- package/dist/{page-revisions-content-PRgwV04S.js → page-revisions-content-q1Ch2-IQ.js} +18 -18
- package/dist/{publish-pages-content-akIgltlm.cjs → publish-pages-content-B8Uuw29Q.cjs} +1 -1
- package/dist/{publish-pages-content-C24iBibw.js → publish-pages-content-DEHD8qkl.js} +6 -6
- package/dist/{save-to-lib-C3H1ZPb-.cjs → save-to-lib-B83ZH4XX.cjs} +1 -1
- package/dist/{save-to-lib-DSPvtFSd.js → save-to-lib-QEOpf_Bd.js} +1 -1
- package/dist/{seo-panel-rZ8s88c0.js → seo-panel-DEQfOfZs.js} +17 -17
- package/dist/{seo-panel-Ce6aTIyt.cjs → seo-panel-DvDEatlO.cjs} +1 -1
- package/dist/{shared-json-ld-DMYOwp6B.js → shared-json-ld-Cyv9JitF.js} +26 -25
- package/dist/{shared-json-ld-hCiviuBf.cjs → shared-json-ld-D5F8RuF2.cjs} +1 -1
- package/dist/{slug-input-BN8eQgxP.cjs → slug-input-3vWL9FPC.cjs} +1 -1
- package/dist/{slug-input-Dhzaobv6.js → slug-input-D4e2anEs.js} +1 -1
- package/dist/theme-panel-footer-4dbLfEph.cjs +1 -0
- package/dist/theme-panel-footer-D3Gub87c.js +25 -0
- package/dist/unmark-as-template-BENGNo7g.js +39 -0
- package/dist/unmark-as-template-Dkc7zLZr.cjs +1 -0
- package/dist/unpublish-page-Cui0tgvd.cjs +1 -0
- package/dist/unpublish-page-D5tWKVLY.js +27 -0
- package/dist/{web-preview-BEyjKFDL.js → web-preview-CHNZZcqH.js} +1 -1
- package/dist/{web-preview-TTKtpSUi.cjs → web-preview-CcPTcMio.cjs} +1 -1
- package/package.json +3 -3
- package/dist/add-new-language-page-D4VPifNs.cjs +0 -1
- package/dist/add-new-language-page-DENCjC_f.js +0 -390
- package/dist/add-new-page-BuK6We-q.cjs +0 -1
- package/dist/add-new-page-CD-9ppdS.js +0 -30
- package/dist/delete-page-B-TP6nJ7.cjs +0 -1
- package/dist/delete-page-CatRlDfx.js +0 -38
- package/dist/digital-asset-manager-DL2nAqUC.cjs +0 -1
- package/dist/digital-asset-manager-KakxBkBC.js +0 -917
- package/dist/duplicate-page-D4Oiy71Q.cjs +0 -1
- package/dist/duplicate-page-DEmh0df0.js +0 -120
- package/dist/image-editor-D9MPdtxC.js +0 -107
- package/dist/image-editor-Da6lrqkL.cjs +0 -1
- package/dist/index-Blg1T7nL.cjs +0 -5
- package/dist/lang-panel-D1FKTNui.js +0 -218
- package/dist/lang-panel-ExS97Zgk.cjs +0 -1
- package/dist/mark-as-template-CcnkROAU.cjs +0 -1
- package/dist/mark-as-template-v-I05xcZ.js +0 -146
- package/dist/no-language-page-content-Bm5CcsUo.js +0 -35
- package/dist/no-language-page-content-Ddz2hnYs.cjs +0 -1
- package/dist/page-lock-request-Dx6OrOwM.cjs +0 -1
- package/dist/page-lock-request-WKfG7Sd3.js +0 -64
- package/dist/page-locked-by-dialog-BvdAXZPw.cjs +0 -1
- package/dist/page-locked-by-dialog-jy3lYV3l.js +0 -63
- package/dist/page-manager-new-CNHlSwfe.js +0 -354
- package/dist/page-manager-new-CUlpwqpH.cjs +0 -1
- package/dist/page-manager-search-and-filter-CuAn82Db.js +0 -197
- package/dist/page-manager-search-and-filter-eFsGtm5W.cjs +0 -1
- package/dist/theme-panel-footer-0GrdOHO_.cjs +0 -1
- package/dist/theme-panel-footer-BzEy5bsg.js +0 -25
- package/dist/unmark-as-template-DXEs6foh.cjs +0 -1
- package/dist/unmark-as-template-Dsiyocm9.js +0 -38
- package/dist/unpublish-page-c1mqQEa_.cjs +0 -1
- package/dist/unpublish-page-yGyz2jiw.js +0 -26
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("@chaibuilder/sdk/ui"),i=require("react"),$=require("./slug-input-BN8eQgxP.cjs"),Y=require("@chaibuilder/sdk"),b=require("lodash-es"),C=require("lucide-react"),w=require("./index-Blg1T7nL.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:o}){const[f,m]=i.useState(null),h=i.useRef(null),[g,L]=i.useState(p+t);i.useEffect(()=>{L(p+t)},[t,p]);const B=v=>{const S=v.target.value;if(!S.startsWith(p)){const O=S.replace(p,""),R=p+O;L(R),c(O);return}const l=S.substring(p.length).replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),a=(l.match(/\./g)||[]).length,x=a<=1;a>1?m("Invalid slug. Only one dot (.) is allowed in the slug"):m(null),o&&o(x);const y=p+l;L(y),c(l)},N=()=>{if(h.current){const v=h.current;setTimeout(()=>{const S=p.length;v.setSelectionRange(S,S)},0)}},W=v=>{const S=v.currentTarget;(S.selectionStart||0)<=p.length&&setTimeout(()=>{const l=p.length;S.setSelectionRange(l,l)},0)};return e.jsx("div",{children:e.jsxs("div",{className:"relative",children:[e.jsxs("p",{className:"text-gray-500 text-xs mb-2",children:[`${p}`," is a dynamic segment of slug"]}),e.jsx(n.Input,{ref:h,value:g,onChange:B,onFocus:N,onClick:W,placeholder:j,className:f?"border-red-500":""}),f&&e.jsx("div",{className:"text-red-500 text-xs mt-1",children:f})]})})}const X=({children:t,onWheel:c,...j})=>{const p=o=>{try{o.preventDefault();const f=o.currentTarget;f.scrollTop+=o.deltaY}catch{o.preventDefault()}c&&c(o)};return e.jsx(n.CommandList,{...j,onWheel:p,children:t})},te=(...t)=>t.filter(Boolean).join(" ");function $e({pages:t,selectedParentId:c,onChange:j,className:p,id:o="parentPage",currentPage:f}){const[m,h]=i.useState(!1),[g,L]=i.useState(""),B=Y.useChaiFeatureFlag("enable-add-page-dropdown");B||(p="w-full rounded-md border border-gray-300 px-3 py-2");const N=i.useMemo(()=>!t||t.length===0?[]:t.filter(x=>!b.isEmpty(x.slug)).filter(x=>x.slug!=="/").sort((x,y)=>x.slug.localeCompare(y.slug)),[t]),W=i.useMemo(()=>{if(!g.trim())return N;const a=g.toLowerCase();return N.filter(x=>x.name.toLowerCase().includes(a)||x.slug.toLowerCase().includes(a))},[N,g]),v=a=>Math.max(0,(a.match(/\//g)||[]).length-1),S=a=>" ".repeat(a),d=a=>{if(a==="/")return"/";const x=a.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 a=N.find(x=>x.id===c);return a?`${a.name} (${d(a.slug)})`:"None"};return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:o,className:"text-sm",children:"Parent"}),B?e.jsxs(n.Popover,{open:m,onOpenChange:h,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{id:o,variant:"outline",role:"combobox",className:te("w-full justify-between",p),"data-testid":"parent-page-selector",children:[l(),e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.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(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search pages...",className:"h-8 pl-8 text-xs",value:g,onChange:a=>L(a.target.value)})]})})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No pages found."}),e.jsxs(n.CommandGroup,{children:[e.jsxs(n.CommandItem,{value:"none",onSelect:()=>{j(""),h(!1),L("")},className:"flex cursor-pointer items-center justify-between",children:[e.jsx("span",{children:"None"}),e.jsx(C.Check,{className:te("mr-2 h-4 w-4",c?"opacity-0":"opacity-100")})]}),W.map(a=>{const x=S(v(a.slug)),y=d(a.slug),O=e.jsxs("span",{className:"flex items-center text-sm",children:[x,a.name,e.jsxs("span",{className:"text-xs text-gray-500",children:[" (",y,")"]})]});return e.jsxs(n.CommandItem,{value:a.id,onSelect:()=>{j(a.id),h(!1),L("")},className:"flex cursor-pointer items-center justify-between whitespace-pre-wrap",children:[e.jsx("span",{children:O}),e.jsx(C.Check,{className:te("mr-2 h-4 w-4 shrink-0",c===a.id?"opacity-100":"opacity-0")})]},a.id)})]})]})]})})]}):e.jsxs("select",{id:o,value:c||"none",onChange:a=>j(a.target.value),className:p,"data-testid":"parent-page-selector",children:[e.jsx("option",{value:"none",children:"None"}),N.map(a=>{const x=v(a.slug),y=x>0?S(x):"",O=d(a.slug);return(f==null?void 0:f.id)===a.id||a.slug.startsWith(f==null?void 0:f.slug)?null:e.jsxs("option",{value:a.id,children:[y,a.name," (",O,")"]},a.id)})]})]})}const ze=(...t)=>t.filter(Boolean).join(" "),_e=({templates:t,selectedTemplateId:c,onSelectTemplate:j,isLoading:p=!1})=>{const[o,f]=i.useState(""),[m,h]=i.useState(!1),[g,L]=i.useState(""),B=Y.useChaiFeatureFlag("enable-add-page-dropdown");if(i.useEffect(()=>{if(c){const d=t.find(l=>l.id===c);f((d==null?void 0:d.preview)||"")}else 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 N={};t.forEach(d=>{const l=d.libraryName;N[l]||(N[l]=[]),N[l].push(d)});const W=Object.entries(N).reduce((d,[l,a])=>{const x=a.filter(y=>y.name.toLowerCase().includes(g.toLowerCase())||l.toLowerCase().includes(g.toLowerCase()));return x.length>0&&(d[l]=x),d},{}),v=t.find(d=>d.id===c),S=v?b.startCase(v.name):"No Template";return e.jsxs("div",{className:"space-y-4",children:[B?e.jsxs(n.Popover,{open:m,onOpenChange:h,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",className:"w-full justify-between",children:[S,e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.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(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search templates...",className:"h-8 pl-8 text-xs",value:g,onChange:d=>L(d.target.value)})]})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No templates found."}),Object.entries(W).map(([d,l])=>e.jsx(n.CommandGroup,{heading:d,children:l.map(a=>e.jsxs(n.CommandItem,{value:a.id,onSelect:()=>{j(a.id),h(!1),L("")},className:"flex cursor-pointer items-center justify-between",children:[b.startCase(a.name),e.jsx(C.Check,{className:ze("mr-2 h-4 w-4",c===a.id?"opacity-100":"opacity-0")})]},a.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(N).map(([d,l])=>e.jsx("optgroup",{label:d,children:l.map(a=>e.jsx("option",{value:a.id,children:b.startCase(a.name)},a.id))},d))]}),o&&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:o,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"})]})]})},Ve=()=>{const t=w.useApiUrl(),c=w.useFetch();return je.useQuery({queryKey:[w.ACTIONS.GET_LIBRARIES],staleTime:"static",queryFn:async()=>await c(t,{action:w.ACTIONS.GET_LIBRARIES})||[]})},Qe=t=>{const c=w.useApiUrl(),j=w.useFetch();return je.useQuery({queryKey:[w.ACTIONS.GET_TEMPLATES_BY_TYPE,t],staleTime:"static",enabled:!!t,queryFn:async()=>{const p=await j(c,{action:w.ACTIONS.GET_TEMPLATES_BY_TYPE,data:{pageType:t}});return(t?b.filter(p,{pageType:t}):p)||[]}})},Ye=t=>{const{data:c=[],isLoading:j}=Qe(t),{data:p=[],isLoading:o}=Ve(),f=i.useMemo(()=>j||o?[]:c.map(h=>{const g=b.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,o]),m=i.useMemo(()=>b.groupBy(f,"libraryName"),[f]);return{data:f,groupedData:m,isLoading:j||o}},U=(...t)=>t.filter(Boolean).join(" ");function He({addEditPage:t,close:c,closePanel:j}){var xe,ge;const{data:p}=w.usePageTypes(),o=i.useMemo(()=>p??[],[p]),f=w.useChangePage(),m=!!(t!=null&&t.id),{data:h}=w.useWebsitePages(),{mutate:g,isPending:L}=w.useCreatePage(),{mutate:B,isPending:N}=w.useUpdatePage(),[W,v]=i.useState(null),[S,d]=i.useState(!0),[l,a]=i.useState((t==null?void 0:t.pageType)??"page"),{hasPermission:x}=Y.usePermissions(),y=x(w.PAGES_PERMISSIONS.CHANGE_PAGE_TYPE),[O,R]=i.useState(!1),[ye,ve]=i.useState(""),{selectedLang:Se,fallbackLang:Ce}=Y.useLanguages(),ne=Se||Ce,[z,H]=i.useState(""),[ae,V]=i.useState(!1),le=i.useMemo(()=>{const s=o.find(u=>u.key===l);return(s==null?void 0:s.hasSlug)===!1},[l,o]),[T,Ne]=i.useState((t==null?void 0:t.parent)??""),[G,re]=i.useState((t==null?void 0:t.name)??""),[I,oe]=i.useState((t==null?void 0:t.dynamic)??!1),[F,Q]=i.useState(I?"":((t==null?void 0:t.slug)??"").split("/").pop()||""),[ie,ce]=i.useState((t==null?void 0:t.dynamicSlugCustom)??""),[ue,be]=i.useState(!0),[we,P]=i.useState(!1),[E,ke]=i.useState(""),{data:me,isLoading:Le}=Ye(l),_=L||N,he=Y.useChaiFeatureFlag("enable-add-page-dropdown"),ee=i.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=i.useMemo(()=>!m||!(t!=null&&t.id)||!h?!1:h.some(s=>s.parent===t.id),[m,t==null?void 0:t.id,h]),r=o.find(s=>s.key===l),M=s=>{if(m&&l!==s){ve(s),R(!0),H(""),V(!1);return}a(s),H(""),V(!1)},pe=()=>{a(ye),R(!1),oe(!1)},Ie=s=>{oe(s),s?Q(""):ce("")},Fe=s=>{if(Ne(s),s&&s!=="none"){const u=h==null?void 0:h.find(k=>k.id===s),q=(u==null?void 0:u.slug)||"";if(F.startsWith(q)){const k=F.slice(q.length).replace(/^\/+/,"");Q(k)}else Q(F.replace(/^\/+/,""))}else Q(F?`${F}`:"")},qe=s=>{ke(s)},Ae=()=>G.trim()?I&&!b.isEmpty(F)?(v("Slug must be empty when using dynamic slug"),!1):I&&!ue?(v("Dynamic slug is invalid"),!1):!0:(J.toast.error("Name is required"),!1),Be=()=>{const s={pageType:r==null?void 0:r.key,name:G,slug:"",hasSlug:!1};m?B({id:t==null?void 0:t.id,name:G},{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()&&!I)return v("Child page slug is required"),!1;const q=$.removeSlugExtension(u),k=$.combineParentChildSlugs(q,s);return Object.keys(w.LANGUAGES).some(Z=>k===`/${Z}`||(k==null?void 0:k.startsWith(`/${Z}/`)))?(v("Slugs cannot start with a language code for primary page"),!1):!0},We=(s,u)=>{const q=$.removeSlugExtension(u),k=$.combineParentChildSlugs(q,s),D={pageType:l,name:G,slug:k.replace(/\/$/,""),parent:T,dynamic:I,hasSlug:!0,template:E||void 0,tracking:{},seo:{},jsonLD:{}};if(I&&(D.dynamicSlugCustom=ie),m){const A=b.pick(D,["pageType","parent","name","slug","dynamic","dynamicSlugCustom"]);B({id:t==null?void 0:t.id,...A},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}})}else{const A=b.find(o,{key:l});A!=null&&A.trackingDefault&&(D.tracking=A.trackingDefault);const{seo:Z,jsonLD:Ge}=fe.getSeoDefaults(A,ne);b.set(D,"seo",Z),b.set(D,"jsonLD",Ge),g(D,{onSuccess:Me=>{c(),f(Me.page.id,j)}})}},Re=()=>{const s={pageType:l,name:G,slug:F===""?"/":`/${F.replace(/\/$/,"")}`,template:E||void 0,parent:null,tracking:{}};if(m)B({id:t==null?void 0:t.id,...s},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}});else{const u=b.find(o,{key:l});u!=null&&u.trackingDefault&&(s.tracking=u.trackingDefault);const{seo:q,jsonLD:k}=fe.getSeoDefaults(u,ne);b.set(s,"seo",q),b.set(s,"jsonLD",k),g(s,{onSuccess:D=>{var A;(A=D==null?void 0:D.page)!=null&&A.id&&f(D.page.id,j),c()}})}},de=s=>{if(s.preventDefault(),v(null),!!Ae()){if(!(r!=null&&r.hasSlug)){Be();return}if(T&&T!=="none"){const u=h==null?void 0:h.find(k=>k.id===T),q=(u==null?void 0:u.slug)||"";if(!Oe(F,q))return;We(F,q)}else Re()}},{pagesType:se,partialsType:K}=i.useMemo(()=>{const s=u=>z?u.name.toLowerCase().includes(z.toLowerCase())||u.key.toLowerCase().includes(z.toLowerCase()):!0;return{pagesType:o.filter(u=>u.hasSlug!==!1&&s(u)),partialsType:o.filter(u=>u.hasSlug===!1&&s(u))}},[o,z]);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(n.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(n.Popover,{open:ae,onOpenChange:V,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:U("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.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(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:z,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No page type found."}),m?le?e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsx(n.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("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(n.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}),K.length>0&&e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("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=>M(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:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsx("optgroup",{label:"Pages",children:o.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:o.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}),e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})]})}),O&&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(n.Button,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),e.jsx(n.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(n.Label,{className:"mb-1 block text-sm",children:"Template"}),e.jsx(_e,{templates:me,selectedTemplateId:E,onSelectTemplate:qe,isLoading:Le})]}),e.jsx($e,{pages:h,selectedParentId:T,onChange:Fe,currentPage:t}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(n.Input,{id:"name",value:G,onChange:s=>re(s.target.value),required:!0,"aria-required":"true",placeholder:"Enter page name"})]}),(r==null?void 0:r.dynamicSegments)&&T&&T!=="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:I,onChange:s=>Ie(s.target.checked),className:"rounded border-gray-300"}),e.jsx(n.Label,{htmlFor:"useDynamicSlug",className:"text-sm",children:"Use Dynamic Slug"})]}),I&&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)||!I)&&e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),e.jsx($.SlugInput,{value:F,onChange:s=>{var u;Q(s),m&&s!==(((u=t==null?void 0:t.slug)==null?void 0:u.split("/").pop())||"")?P(!!(Te||De)):P(!1)},placeholder:T&&T!=="none"?"Enter page slug":l==="page"?"Leave empty for home page":"Required - e.g. your-slug",parentSlug:T&&T!=="none"?(ge=h==null?void 0:h.find(s=>s.id===T))==null?void 0:ge.slug:void 0,onValidationChange:d}),W&&e.jsx("p",{className:"text-xs text-red-500",children:W}),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(n.Button,{disabled:_||!S&&(!(r!=null&&r.dynamicSegments)||!I)||I&&!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(n.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(n.Popover,{open:ae,onOpenChange:V,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:U("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.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(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:z,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"max-h-[200px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No page type found."}),e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>{M(s.key),V(!1)},className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("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=>M(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:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})}),O&&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(n.Button,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),e.jsx(n.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:(xe=o.find(s=>s.key===l))==null?void 0:xe.helpText})]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(n.Input,{id:"name",value:G,onChange:s=>re(s.target.value),required:!0,"aria-required":"true"})]}),e.jsx(n.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
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("@chaibuilder/sdk/ui"),i=require("react"),$=require("./slug-input-3vWL9FPC.cjs"),Y=require("@chaibuilder/sdk"),b=require("lodash-es"),C=require("lucide-react"),w=require("./index-BELYt0c9.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:o}){const[f,m]=i.useState(null),h=i.useRef(null),[g,L]=i.useState(p+t);i.useEffect(()=>{L(p+t)},[t,p]);const B=v=>{const S=v.target.value;if(!S.startsWith(p)){const O=S.replace(p,""),R=p+O;L(R),c(O);return}const l=S.substring(p.length).replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),a=(l.match(/\./g)||[]).length,x=a<=1;a>1?m("Invalid slug. Only one dot (.) is allowed in the slug"):m(null),o&&o(x);const y=p+l;L(y),c(l)},N=()=>{if(h.current){const v=h.current;setTimeout(()=>{const S=p.length;v.setSelectionRange(S,S)},0)}},W=v=>{const S=v.currentTarget;(S.selectionStart||0)<=p.length&&setTimeout(()=>{const l=p.length;S.setSelectionRange(l,l)},0)};return e.jsx("div",{children:e.jsxs("div",{className:"relative",children:[e.jsxs("p",{className:"text-gray-500 text-xs mb-2",children:[`${p}`," is a dynamic segment of slug"]}),e.jsx(n.Input,{ref:h,value:g,onChange:B,onFocus:N,onClick:W,placeholder:j,className:f?"border-red-500":""}),f&&e.jsx("div",{className:"text-red-500 text-xs mt-1",children:f})]})})}const X=({children:t,onWheel:c,...j})=>{const p=o=>{try{o.preventDefault();const f=o.currentTarget;f.scrollTop+=o.deltaY}catch{o.preventDefault()}c&&c(o)};return e.jsx(n.CommandList,{...j,onWheel:p,children:t})},te=(...t)=>t.filter(Boolean).join(" ");function $e({pages:t,selectedParentId:c,onChange:j,className:p,id:o="parentPage",currentPage:f}){const[m,h]=i.useState(!1),[g,L]=i.useState(""),B=Y.useChaiFeatureFlag("enable-add-page-dropdown");B||(p="w-full rounded-md border border-gray-300 px-3 py-2");const N=i.useMemo(()=>!t||t.length===0?[]:t.filter(x=>!b.isEmpty(x.slug)).filter(x=>x.slug!=="/").sort((x,y)=>x.slug.localeCompare(y.slug)),[t]),W=i.useMemo(()=>{if(!g.trim())return N;const a=g.toLowerCase();return N.filter(x=>x.name.toLowerCase().includes(a)||x.slug.toLowerCase().includes(a))},[N,g]),v=a=>Math.max(0,(a.match(/\//g)||[]).length-1),S=a=>" ".repeat(a),d=a=>{if(a==="/")return"/";const x=a.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 a=N.find(x=>x.id===c);return a?`${a.name} (${d(a.slug)})`:"None"};return e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:o,className:"text-sm",children:"Parent"}),B?e.jsxs(n.Popover,{open:m,onOpenChange:h,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{id:o,variant:"outline",role:"combobox",className:te("w-full justify-between",p),"data-testid":"parent-page-selector",children:[l(),e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.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(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search pages...",className:"h-8 pl-8 text-xs",value:g,onChange:a=>L(a.target.value)})]})})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No pages found."}),e.jsxs(n.CommandGroup,{children:[e.jsxs(n.CommandItem,{value:"none",onSelect:()=>{j(""),h(!1),L("")},className:"flex cursor-pointer items-center justify-between",children:[e.jsx("span",{children:"None"}),e.jsx(C.Check,{className:te("mr-2 h-4 w-4",c?"opacity-0":"opacity-100")})]}),W.map(a=>{const x=S(v(a.slug)),y=d(a.slug),O=e.jsxs("span",{className:"flex items-center text-sm",children:[x,a.name,e.jsxs("span",{className:"text-xs text-gray-500",children:[" (",y,")"]})]});return e.jsxs(n.CommandItem,{value:a.id,onSelect:()=>{j(a.id),h(!1),L("")},className:"flex cursor-pointer items-center justify-between whitespace-pre-wrap",children:[e.jsx("span",{children:O}),e.jsx(C.Check,{className:te("mr-2 h-4 w-4 shrink-0",c===a.id?"opacity-100":"opacity-0")})]},a.id)})]})]})]})})]}):e.jsxs("select",{id:o,value:c||"none",onChange:a=>j(a.target.value),className:p,"data-testid":"parent-page-selector",children:[e.jsx("option",{value:"none",children:"None"}),N.map(a=>{const x=v(a.slug),y=x>0?S(x):"",O=d(a.slug);return(f==null?void 0:f.id)===a.id||a.slug.startsWith(f==null?void 0:f.slug)?null:e.jsxs("option",{value:a.id,children:[y,a.name," (",O,")"]},a.id)})]})]})}const ze=(...t)=>t.filter(Boolean).join(" "),_e=({templates:t,selectedTemplateId:c,onSelectTemplate:j,isLoading:p=!1})=>{const[o,f]=i.useState(""),[m,h]=i.useState(!1),[g,L]=i.useState(""),B=Y.useChaiFeatureFlag("enable-add-page-dropdown");if(i.useEffect(()=>{if(c){const d=t.find(l=>l.id===c);f((d==null?void 0:d.preview)||"")}else 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 N={};t.forEach(d=>{const l=d.libraryName;N[l]||(N[l]=[]),N[l].push(d)});const W=Object.entries(N).reduce((d,[l,a])=>{const x=a.filter(y=>y.name.toLowerCase().includes(g.toLowerCase())||l.toLowerCase().includes(g.toLowerCase()));return x.length>0&&(d[l]=x),d},{}),v=t.find(d=>d.id===c),S=v?b.startCase(v.name):"No Template";return e.jsxs("div",{className:"space-y-4",children:[B?e.jsxs(n.Popover,{open:m,onOpenChange:h,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",className:"w-full justify-between",children:[S,e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.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(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search templates...",className:"h-8 pl-8 text-xs",value:g,onChange:d=>L(d.target.value)})]})}),e.jsxs(X,{className:"max-h-[300px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No templates found."}),Object.entries(W).map(([d,l])=>e.jsx(n.CommandGroup,{heading:d,children:l.map(a=>e.jsxs(n.CommandItem,{value:a.id,onSelect:()=>{j(a.id),h(!1),L("")},className:"flex cursor-pointer items-center justify-between",children:[b.startCase(a.name),e.jsx(C.Check,{className:ze("mr-2 h-4 w-4",c===a.id?"opacity-100":"opacity-0")})]},a.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(N).map(([d,l])=>e.jsx("optgroup",{label:d,children:l.map(a=>e.jsx("option",{value:a.id,children:b.startCase(a.name)},a.id))},d))]}),o&&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:o,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"})]})]})},Ve=()=>{const t=w.useApiUrl(),c=w.useFetch();return je.useQuery({queryKey:[w.ACTIONS.GET_LIBRARIES],staleTime:"static",queryFn:async()=>await c(t,{action:w.ACTIONS.GET_LIBRARIES})||[]})},Qe=t=>{const c=w.useApiUrl(),j=w.useFetch();return je.useQuery({queryKey:[w.ACTIONS.GET_TEMPLATES_BY_TYPE,t],staleTime:"static",enabled:!!t,queryFn:async()=>{const p=await j(c,{action:w.ACTIONS.GET_TEMPLATES_BY_TYPE,data:{pageType:t}});return(t?b.filter(p,{pageType:t}):p)||[]}})},Ye=t=>{const{data:c=[],isLoading:j}=Qe(t),{data:p=[],isLoading:o}=Ve(),f=i.useMemo(()=>j||o?[]:c.map(h=>{const g=b.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,o]),m=i.useMemo(()=>b.groupBy(f,"libraryName"),[f]);return{data:f,groupedData:m,isLoading:j||o}},U=(...t)=>t.filter(Boolean).join(" ");function He({addEditPage:t,close:c,closePanel:j}){var xe,ge;const{data:p}=w.usePageTypes(),o=i.useMemo(()=>p??[],[p]),f=w.useChangePage(),m=!!(t!=null&&t.id),{data:h}=w.useWebsitePages(),{mutate:g,isPending:L}=w.useCreatePage(),{mutate:B,isPending:N}=w.useUpdatePage(),[W,v]=i.useState(null),[S,d]=i.useState(!0),[l,a]=i.useState((t==null?void 0:t.pageType)??"page"),{hasPermission:x}=Y.usePermissions(),y=x(w.PAGES_PERMISSIONS.CHANGE_PAGE_TYPE),[O,R]=i.useState(!1),[ye,ve]=i.useState(""),{selectedLang:Se,fallbackLang:Ce}=Y.useLanguages(),ne=Se||Ce,[z,H]=i.useState(""),[ae,V]=i.useState(!1),le=i.useMemo(()=>{const s=o.find(u=>u.key===l);return(s==null?void 0:s.hasSlug)===!1},[l,o]),[T,Ne]=i.useState((t==null?void 0:t.parent)??""),[G,re]=i.useState((t==null?void 0:t.name)??""),[I,oe]=i.useState((t==null?void 0:t.dynamic)??!1),[F,Q]=i.useState(I?"":((t==null?void 0:t.slug)??"").split("/").pop()||""),[ie,ce]=i.useState((t==null?void 0:t.dynamicSlugCustom)??""),[ue,be]=i.useState(!0),[we,P]=i.useState(!1),[E,ke]=i.useState(""),{data:me,isLoading:Le}=Ye(l),_=L||N,he=Y.useChaiFeatureFlag("enable-add-page-dropdown"),ee=i.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=i.useMemo(()=>!m||!(t!=null&&t.id)||!h?!1:h.some(s=>s.parent===t.id),[m,t==null?void 0:t.id,h]),r=o.find(s=>s.key===l),M=s=>{if(m&&l!==s){ve(s),R(!0),H(""),V(!1);return}a(s),H(""),V(!1)},pe=()=>{a(ye),R(!1),oe(!1)},Ie=s=>{oe(s),s?Q(""):ce("")},Fe=s=>{if(Ne(s),s&&s!=="none"){const u=h==null?void 0:h.find(k=>k.id===s),q=(u==null?void 0:u.slug)||"";if(F.startsWith(q)){const k=F.slice(q.length).replace(/^\/+/,"");Q(k)}else Q(F.replace(/^\/+/,""))}else Q(F?`${F}`:"")},qe=s=>{ke(s)},Ae=()=>G.trim()?I&&!b.isEmpty(F)?(v("Slug must be empty when using dynamic slug"),!1):I&&!ue?(v("Dynamic slug is invalid"),!1):!0:(J.toast.error("Name is required"),!1),Be=()=>{const s={pageType:r==null?void 0:r.key,name:G,slug:"",hasSlug:!1};m?B({id:t==null?void 0:t.id,name:G},{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()&&!I)return v("Child page slug is required"),!1;const q=$.removeSlugExtension(u),k=$.combineParentChildSlugs(q,s);return Object.keys(w.LANGUAGES).some(Z=>k===`/${Z}`||(k==null?void 0:k.startsWith(`/${Z}/`)))?(v("Slugs cannot start with a language code for primary page"),!1):!0},We=(s,u)=>{const q=$.removeSlugExtension(u),k=$.combineParentChildSlugs(q,s),D={pageType:l,name:G,slug:k.replace(/\/$/,""),parent:T,dynamic:I,hasSlug:!0,template:E||void 0,tracking:{},seo:{},jsonLD:{}};if(I&&(D.dynamicSlugCustom=ie),m){const A=b.pick(D,["pageType","parent","name","slug","dynamic","dynamicSlugCustom"]);B({id:t==null?void 0:t.id,...A},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}})}else{const A=b.find(o,{key:l});A!=null&&A.trackingDefault&&(D.tracking=A.trackingDefault);const{seo:Z,jsonLD:Ge}=fe.getSeoDefaults(A,ne);b.set(D,"seo",Z),b.set(D,"jsonLD",Ge),g(D,{onSuccess:Me=>{c(),f(Me.page.id,j)}})}},Re=()=>{const s={pageType:l,name:G,slug:F===""?"/":`/${F.replace(/\/$/,"")}`,template:E||void 0,parent:null,tracking:{}};if(m)B({id:t==null?void 0:t.id,...s},{onSuccess:()=>{J.toast.success("Page updated successfully"),c()}});else{const u=b.find(o,{key:l});u!=null&&u.trackingDefault&&(s.tracking=u.trackingDefault);const{seo:q,jsonLD:k}=fe.getSeoDefaults(u,ne);b.set(s,"seo",q),b.set(s,"jsonLD",k),g(s,{onSuccess:D=>{var A;(A=D==null?void 0:D.page)!=null&&A.id&&f(D.page.id,j),c()}})}},de=s=>{if(s.preventDefault(),v(null),!!Ae()){if(!(r!=null&&r.hasSlug)){Be();return}if(T&&T!=="none"){const u=h==null?void 0:h.find(k=>k.id===T),q=(u==null?void 0:u.slug)||"";if(!Oe(F,q))return;We(F,q)}else Re()}},{pagesType:se,partialsType:K}=i.useMemo(()=>{const s=u=>z?u.name.toLowerCase().includes(z.toLowerCase())||u.key.toLowerCase().includes(z.toLowerCase()):!0;return{pagesType:o.filter(u=>u.hasSlug!==!1&&s(u)),partialsType:o.filter(u=>u.hasSlug===!1&&s(u))}},[o,z]);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(n.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(n.Popover,{open:ae,onOpenChange:V,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:U("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.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(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:z,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No page type found."}),m?le?e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}):e.jsx(n.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("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(n.CommandGroup,{heading:"Pages",children:se.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("mr-2 h-4 w-4",l===s.key?"opacity-100":"opacity-0")})]},s.key))}),K.length>0&&e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>M(s.key),className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("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=>M(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:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}):e.jsx("optgroup",{label:"Pages",children:o.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:o.filter(s=>s.hasSlug!==!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))}),e.jsx("optgroup",{label:"Partials",children:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})]})}),O&&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(n.Button,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),e.jsx(n.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(n.Label,{className:"mb-1 block text-sm",children:"Template"}),e.jsx(_e,{templates:me,selectedTemplateId:E,onSelectTemplate:qe,isLoading:Le})]}),e.jsx($e,{pages:h,selectedParentId:T,onChange:Fe,currentPage:t}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(n.Input,{id:"name",value:G,onChange:s=>re(s.target.value),required:!0,"aria-required":"true",placeholder:"Enter page name"})]}),(r==null?void 0:r.dynamicSegments)&&T&&T!=="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:I,onChange:s=>Ie(s.target.checked),className:"rounded border-gray-300"}),e.jsx(n.Label,{htmlFor:"useDynamicSlug",className:"text-sm",children:"Use Dynamic Slug"})]}),I&&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)||!I)&&e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"slug",className:"text-sm",children:"Slug"}),e.jsx($.SlugInput,{value:F,onChange:s=>{var u;Q(s),m&&s!==(((u=t==null?void 0:t.slug)==null?void 0:u.split("/").pop())||"")?P(!!(Te||De)):P(!1)},placeholder:T&&T!=="none"?"Enter page slug":l==="page"?"Leave empty for home page":"Required - e.g. your-slug",parentSlug:T&&T!=="none"?(ge=h==null?void 0:h.find(s=>s.id===T))==null?void 0:ge.slug:void 0,onValidationChange:d}),W&&e.jsx("p",{className:"text-xs text-red-500",children:W}),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(n.Button,{disabled:_||!S&&(!(r!=null&&r.dynamicSegments)||!I)||I&&!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(n.Label,{htmlFor:"pageType",className:"text-sm",children:"Type"}),he?e.jsxs(n.Popover,{open:ae,onOpenChange:V,children:[e.jsx(n.PopoverTrigger,{asChild:!0,children:e.jsxs(n.Button,{variant:"outline",role:"combobox",disabled:m&&!y,className:U("w-full justify-between",m&&!y?"cursor-not-allowed text-gray-500":""),children:[(r==null?void 0:r.name)||"Select page type",e.jsx(C.ChevronDown,{className:"ml-2 h-4 w-4 shrink-0 opacity-50"})]})}),e.jsx(n.PopoverContent,{className:"w-[var(--radix-popover-trigger-width)] p-0",align:"start",children:e.jsxs(n.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(C.Search,{strokeWidth:2,className:"absolute left-2 top-2 h-4 w-4 text-gray-400"}),e.jsx(n.Input,{placeholder:"Search page types...",className:"h-8 pl-8 text-xs",value:z,onChange:s=>H(s.target.value)})]})}),e.jsxs(X,{className:"max-h-[200px] overflow-y-auto",children:[e.jsx(n.CommandEmpty,{children:"No page type found."}),e.jsx(n.CommandGroup,{heading:"Partials",children:K.map(s=>e.jsxs(n.CommandItem,{value:s.key,onSelect:()=>{M(s.key),V(!1)},className:"flex cursor-pointer items-center justify-between",children:[s.name,e.jsx(C.Check,{className:U("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=>M(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:o.filter(s=>s.hasSlug===!1).map(s=>e.jsx("option",{value:s.key,children:s.name},s.key))})}),O&&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(n.Button,{variant:"outline",size:"sm",onClick:()=>R(!1),children:"Cancel"}),e.jsx(n.Button,{variant:"default",size:"sm",onClick:pe,children:"Confirm"})]})]}),e.jsx("p",{className:"text-xs text-gray-500",children:(xe=o.find(s=>s.key===l))==null?void 0:xe.helpText})]}),e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n.Label,{htmlFor:"name",className:"text-sm",children:"Name"}),e.jsx(n.Input,{id:"name",value:G,onChange:s=>re(s.target.value),required:!0,"aria-required":"true"})]}),e.jsx(n.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;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { jsx as e, jsxs as r, Fragment as o } from "react/jsx-runtime";
|
|
2
|
+
import { ai as w, aj as T, B as m } from "./index-Djepisz3.js";
|
|
3
|
+
import { useTranslation as x } from "@chaibuilder/sdk";
|
|
4
|
+
import { Card as b, CardHeader as v, CardTitle as y, CardContent as B, CardFooter as q, Button as u } from "@chaibuilder/sdk/ui";
|
|
5
|
+
import { Loader as f, TableIcon as _, CheckCircle as j, Target as A, Edit as g, Check as I, X as O } from "lucide-react";
|
|
6
|
+
import { useState as E, useEffect as R } from "react";
|
|
7
|
+
const k = ({ userId: c }) => {
|
|
8
|
+
const { data: n } = w(c);
|
|
9
|
+
return (n == null ? void 0 : n.name) || "Unknown";
|
|
10
|
+
}, X = ({
|
|
11
|
+
isChecking: c,
|
|
12
|
+
lockingStatus: n,
|
|
13
|
+
onContinue: p
|
|
14
|
+
}) => {
|
|
15
|
+
const { t } = x(), [d, h] = E(!1), i = n === "page_is_active_in_other_tab", s = (n == null ? void 0 : n.length) > 0, { pageLock: a, acceptTakeOver: l, rejectTakeOver: C } = T(), N = () => {
|
|
16
|
+
h(!0), s || i ? p() : l(), setTimeout(() => {
|
|
17
|
+
h(!1);
|
|
18
|
+
}, 3e3);
|
|
19
|
+
};
|
|
20
|
+
return R(() => {
|
|
21
|
+
(a == null ? void 0 : a.requestedBy) === "ANOTHER_TAB" && l();
|
|
22
|
+
}, [a, l]), (a == null ? void 0 : a.requestedBy) === "ANOTHER_TAB" ? null : c ? /* @__PURE__ */ e(m, { children: /* @__PURE__ */ e(f, { className: "h-5 w-5 animate-spin text-primary" }) }) : /* @__PURE__ */ e(m, { children: /* @__PURE__ */ r(b, { className: "mx-auto w-full max-w-md", children: [
|
|
23
|
+
/* @__PURE__ */ e(v, { className: "space-y-1", children: /* @__PURE__ */ r(y, { className: "flex items-center gap-2 text-xl font-medium", children: [
|
|
24
|
+
d ? /* @__PURE__ */ e(f, { className: "h-6 w-6 animate-spin text-gray-500" }) : i ? /* @__PURE__ */ e(_, { className: "h-6 w-6 text-green-500" }) : s ? /* @__PURE__ */ e(j, { className: "h-6 w-6 text-green-500" }) : /* @__PURE__ */ e(A, { className: "h-6 w-6 text-green-500" }),
|
|
25
|
+
t(i ? "Page is active in other tab" : s ? "You can edit the page now." : "Page take over request")
|
|
26
|
+
] }) }),
|
|
27
|
+
/* @__PURE__ */ e(B, { className: "grid gap-4", children: /* @__PURE__ */ e("div", { children: i ? /* @__PURE__ */ r("p", { children: [
|
|
28
|
+
t("You are already editing this page in another tab. To continue editing here, click on"),
|
|
29
|
+
' "',
|
|
30
|
+
t("Continue editing here"),
|
|
31
|
+
'".'
|
|
32
|
+
] }) : s ? /* @__PURE__ */ e("p", { children: t("This page is released by other user you can continue editing now.") }) : /* @__PURE__ */ r("p", { children: [
|
|
33
|
+
/* @__PURE__ */ r("b", { children: [
|
|
34
|
+
" ",
|
|
35
|
+
/* @__PURE__ */ e(k, { userId: a == null ? void 0 : a.requestedBy })
|
|
36
|
+
] }),
|
|
37
|
+
" ",
|
|
38
|
+
t("has requested to take over this page."),
|
|
39
|
+
/* @__PURE__ */ e("br", {}),
|
|
40
|
+
" ",
|
|
41
|
+
t("If you accept, your unsaved changes will be saved.")
|
|
42
|
+
] }) }) }),
|
|
43
|
+
/* @__PURE__ */ r(q, { className: "flex items-center justify-end gap-2", children: [
|
|
44
|
+
/* @__PURE__ */ e(
|
|
45
|
+
u,
|
|
46
|
+
{
|
|
47
|
+
disabled: d,
|
|
48
|
+
onClick: N,
|
|
49
|
+
className: s ? "" : "bg-green-500 hover:bg-green-600",
|
|
50
|
+
children: i ? /* @__PURE__ */ r(o, { children: [
|
|
51
|
+
/* @__PURE__ */ e(g, { className: "h-5 w-5" }),
|
|
52
|
+
" ",
|
|
53
|
+
t("Continue editing here")
|
|
54
|
+
] }) : s ? /* @__PURE__ */ r(o, { children: [
|
|
55
|
+
/* @__PURE__ */ e(g, { className: "h-5 w-5" }),
|
|
56
|
+
" ",
|
|
57
|
+
t("Continue to edit")
|
|
58
|
+
] }) : /* @__PURE__ */ r(o, { children: [
|
|
59
|
+
/* @__PURE__ */ e(I, { className: "h-5 w-5" }),
|
|
60
|
+
" ",
|
|
61
|
+
t("Accept")
|
|
62
|
+
] })
|
|
63
|
+
}
|
|
64
|
+
),
|
|
65
|
+
!s && /* @__PURE__ */ r(u, { variant: "outline", onClick: C, children: [
|
|
66
|
+
/* @__PURE__ */ e(O, { className: "h-5 w-5" }),
|
|
67
|
+
" ",
|
|
68
|
+
t("Reject")
|
|
69
|
+
] })
|
|
70
|
+
] })
|
|
71
|
+
] }) });
|
|
72
|
+
};
|
|
73
|
+
export {
|
|
74
|
+
X as default
|
|
75
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),l=require("./index-BELYt0c9.cjs"),C=require("@chaibuilder/sdk"),i=require("@chaibuilder/sdk/ui"),n=require("lucide-react"),x=require("react"),N=({userId:d})=>{const{data:r}=l.useChaiUserInfo(d);return(r==null?void 0:r.name)||"Unknown"},f=({isChecking:d,lockingStatus:r,onContinue:j})=>{const{t:s}=C.useTranslation(),[u,h]=x.useState(!1),c=r==="page_is_active_in_other_tab",a=(r==null?void 0:r.length)>0,{pageLock:t,acceptTakeOver:o,rejectTakeOver:m}=l.usePageLockRequestTakeOver(),g=()=>{h(!0),a||c?j():o(),setTimeout(()=>{h(!1)},3e3)};return x.useEffect(()=>{(t==null?void 0:t.requestedBy)==="ANOTHER_TAB"&&o()},[t,o]),(t==null?void 0:t.requestedBy)==="ANOTHER_TAB"?null:d?e.jsx(l.BlurContainer,{children:e.jsx(n.Loader,{className:"h-5 w-5 animate-spin text-primary"})}):e.jsx(l.BlurContainer,{children:e.jsxs(i.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(i.CardHeader,{className:"space-y-1",children:e.jsxs(i.CardTitle,{className:"flex items-center gap-2 text-xl font-medium",children:[u?e.jsx(n.Loader,{className:"h-6 w-6 animate-spin text-gray-500"}):c?e.jsx(n.TableIcon,{className:"h-6 w-6 text-green-500"}):a?e.jsx(n.CheckCircle,{className:"h-6 w-6 text-green-500"}):e.jsx(n.Target,{className:"h-6 w-6 text-green-500"}),s(c?"Page is active in other tab":a?"You can edit the page now.":"Page take over request")]})}),e.jsx(i.CardContent,{className:"grid gap-4",children:e.jsx("div",{children:c?e.jsxs("p",{children:[s("You are already editing this page in another tab. To continue editing here, click on"),' "',s("Continue editing here"),'".']}):a?e.jsx("p",{children:s("This page is released by other user you can continue editing now.")}):e.jsxs("p",{children:[e.jsxs("b",{children:[" ",e.jsx(N,{userId:t==null?void 0:t.requestedBy})]})," ",s("has requested to take over this page."),e.jsx("br",{})," ",s("If you accept, your unsaved changes will be saved.")]})})}),e.jsxs(i.CardFooter,{className:"flex items-center justify-end gap-2",children:[e.jsx(i.Button,{disabled:u,onClick:g,className:a?"":"bg-green-500 hover:bg-green-600",children:c?e.jsxs(e.Fragment,{children:[e.jsx(n.Edit,{className:"h-5 w-5"})," ",s("Continue editing here")]}):a?e.jsxs(e.Fragment,{children:[e.jsx(n.Edit,{className:"h-5 w-5"})," ",s("Continue to edit")]}):e.jsxs(e.Fragment,{children:[e.jsx(n.Check,{className:"h-5 w-5"})," ",s("Accept")]})}),!a&&e.jsxs(i.Button,{variant:"outline",onClick:m,children:[e.jsx(n.X,{className:"h-5 w-5"})," ",s("Reject")]})]})]})})};exports.default=f;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { jsx as e, jsxs as r } from "react/jsx-runtime";
|
|
2
|
+
import { useTranslation as f } from "@chaibuilder/sdk";
|
|
3
|
+
import { Card as x, CardHeader as h, CardTitle as N, CardContent as g, Skeleton as d, CardFooter as b, Button as w } from "@chaibuilder/sdk/ui";
|
|
4
|
+
import { formatDistanceToNow as k } from "date-fns";
|
|
5
|
+
import { LockKeyhole as y, UserIcon as v, Info as C, KeyIcon as T } from "lucide-react";
|
|
6
|
+
import { useState as B } from "react";
|
|
7
|
+
import { B as D } from "./index-Djepisz3.js";
|
|
8
|
+
function O({
|
|
9
|
+
avatar: l,
|
|
10
|
+
name: s,
|
|
11
|
+
email: o,
|
|
12
|
+
lastSaved: i,
|
|
13
|
+
onTakeOver: u,
|
|
14
|
+
isRequestRejected: n,
|
|
15
|
+
isFetchingUserInfo: a
|
|
16
|
+
}) {
|
|
17
|
+
const { t } = f(), [c, m] = B(!1), p = () => {
|
|
18
|
+
m(!0), setTimeout(() => {
|
|
19
|
+
m(!1);
|
|
20
|
+
}, 15e3), u();
|
|
21
|
+
};
|
|
22
|
+
return /* @__PURE__ */ e(D, { children: /* @__PURE__ */ r(x, { className: "mx-auto w-full max-w-md", children: [
|
|
23
|
+
/* @__PURE__ */ e(h, { className: "space-y-1", children: /* @__PURE__ */ r(N, { className: "flex items-center gap-2 text-xl", children: [
|
|
24
|
+
/* @__PURE__ */ e(y, { className: "h-8 w-8 rounded-md bg-sky-500/20 p-1.5 text-sky-500" }),
|
|
25
|
+
t("Page is locked for editing")
|
|
26
|
+
] }) }),
|
|
27
|
+
/* @__PURE__ */ e(g, { className: "w-md grid w-full pt-2", children: /* @__PURE__ */ r("div", { children: [
|
|
28
|
+
/* @__PURE__ */ r("div", { className: "relative mx-auto flex w-96 items-center space-x-4 rounded-md border border-green-500 px-2 pb-2 pt-4", children: [
|
|
29
|
+
/* @__PURE__ */ e("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: t("Locked By") }),
|
|
30
|
+
l && !a ? /* @__PURE__ */ e("img", { src: l, alt: s, className: "h-14 w-14 rounded-full border border-gray-300" }) : /* @__PURE__ */ e(v, { className: "h-14 w-14 flex-shrink-0 rounded-full bg-gradient-to-br from-purple-400 to-pink-500 p-2 text-white" }),
|
|
31
|
+
/* @__PURE__ */ r("div", { className: a ? "space-y-1.5" : "space-y-0", children: [
|
|
32
|
+
a ? /* @__PURE__ */ e(d, { className: "h-4 w-40 rounded" }) : /* @__PURE__ */ e("span", { className: "truncate font-medium text-black", children: s }),
|
|
33
|
+
o && !a ? /* @__PURE__ */ e("p", { className: "truncate text-sm text-muted-foreground", children: o }) : /* @__PURE__ */ e(d, { className: "h-4 w-60 rounded" }),
|
|
34
|
+
i && !a ? /* @__PURE__ */ r("p", { className: "text-sm text-muted-foreground", children: [
|
|
35
|
+
t("Last saved"),
|
|
36
|
+
":",
|
|
37
|
+
" ",
|
|
38
|
+
k(new Date(i), {
|
|
39
|
+
addSuffix: !0
|
|
40
|
+
})
|
|
41
|
+
] }) : /* @__PURE__ */ e(d, { className: "h-4 w-40 rounded" })
|
|
42
|
+
] })
|
|
43
|
+
] }),
|
|
44
|
+
/* @__PURE__ */ e("div", { className: "mt-4 text-sm", children: /* @__PURE__ */ r("p", { className: "py-4 text-center text-gray-600", children: [
|
|
45
|
+
t("This page is currently being edited by"),
|
|
46
|
+
" ",
|
|
47
|
+
/* @__PURE__ */ e("span", { className: "font-bold", children: s }),
|
|
48
|
+
".",
|
|
49
|
+
/* @__PURE__ */ e("br", {}),
|
|
50
|
+
/* @__PURE__ */ e("br", {}),
|
|
51
|
+
" ",
|
|
52
|
+
t("You can either wait until they finish editing or request to take over the page.")
|
|
53
|
+
] }) }),
|
|
54
|
+
n && /* @__PURE__ */ r("div", { className: "mt-4 flex w-full items-center justify-center gap-x-2 rounded border border-red-500 bg-red-50 p-2 text-center font-medium text-red-500", children: [
|
|
55
|
+
/* @__PURE__ */ e(C, { className: "h-5 w-5" }),
|
|
56
|
+
" ",
|
|
57
|
+
t("Page take over request is rejected")
|
|
58
|
+
] })
|
|
59
|
+
] }) }),
|
|
60
|
+
/* @__PURE__ */ e(b, { children: /* @__PURE__ */ r(w, { disabled: c, onClick: p, className: "w-full", variant: "destructive", children: [
|
|
61
|
+
/* @__PURE__ */ e(T, { className: "h-5 w-5" }),
|
|
62
|
+
t(c ? "Page take is requested." : n ? "Request take over again" : "Request take over")
|
|
63
|
+
] }) })
|
|
64
|
+
] }) });
|
|
65
|
+
}
|
|
66
|
+
export {
|
|
67
|
+
O as default
|
|
68
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),h=require("@chaibuilder/sdk"),t=require("@chaibuilder/sdk/ui"),j=require("date-fns"),a=require("lucide-react"),p=require("react"),f=require("./index-BELYt0c9.cjs");function g({avatar:l,name:d,email:n,lastSaved:c,onTakeOver:x,isRequestRejected:i,isFetchingUserInfo:r}){const{t:s}=h.useTranslation(),[o,u]=p.useState(!1),m=()=>{u(!0),setTimeout(()=>{u(!1)},15e3),x()};return e.jsx(f.BlurContainer,{children:e.jsxs(t.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(t.CardHeader,{className:"space-y-1",children:e.jsxs(t.CardTitle,{className:"flex items-center gap-2 text-xl",children:[e.jsx(a.LockKeyhole,{className:"h-8 w-8 rounded-md bg-sky-500/20 p-1.5 text-sky-500"}),s("Page is locked for editing")]})}),e.jsx(t.CardContent,{className:"w-md grid w-full pt-2",children:e.jsxs("div",{children:[e.jsxs("div",{className:"relative mx-auto flex w-96 items-center space-x-4 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:s("Locked By")}),l&&!r?e.jsx("img",{src:l,alt:d,className:"h-14 w-14 rounded-full border border-gray-300"}):e.jsx(a.UserIcon,{className:"h-14 w-14 flex-shrink-0 rounded-full bg-gradient-to-br from-purple-400 to-pink-500 p-2 text-white"}),e.jsxs("div",{className:r?"space-y-1.5":"space-y-0",children:[r?e.jsx(t.Skeleton,{className:"h-4 w-40 rounded"}):e.jsx("span",{className:"truncate font-medium text-black",children:d}),n&&!r?e.jsx("p",{className:"truncate text-sm text-muted-foreground",children:n}):e.jsx(t.Skeleton,{className:"h-4 w-60 rounded"}),c&&!r?e.jsxs("p",{className:"text-sm text-muted-foreground",children:[s("Last saved"),":"," ",j.formatDistanceToNow(new Date(c),{addSuffix:!0})]}):e.jsx(t.Skeleton,{className:"h-4 w-40 rounded"})]})]}),e.jsx("div",{className:"mt-4 text-sm",children:e.jsxs("p",{className:"py-4 text-center text-gray-600",children:[s("This page is currently being edited by")," ",e.jsx("span",{className:"font-bold",children:d}),".",e.jsx("br",{}),e.jsx("br",{})," ",s("You can either wait until they finish editing or request to take over the page.")]})}),i&&e.jsxs("div",{className:"mt-4 flex w-full items-center justify-center gap-x-2 rounded border border-red-500 bg-red-50 p-2 text-center font-medium text-red-500",children:[e.jsx(a.Info,{className:"h-5 w-5"})," ",s("Page take over request is rejected")]})]})}),e.jsx(t.CardFooter,{children:e.jsxs(t.Button,{disabled:o,onClick:m,className:"w-full",variant:"destructive",children:[e.jsx(a.KeyIcon,{className:"h-5 w-5"}),s(o?"Page take is requested.":i?"Request take over again":"Request take over")]})})]})})}exports.default=g;
|
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { jsxs as y, jsx as t, Fragment as O } from "react/jsx-runtime";
|
|
2
|
+
import { at as be, f as ie, ai as ye, T as _, aC as ge, L as ke, h as Ne, b as we, i as ve, ao as Se, aD as Ae, aE as q } from "./index-Djepisz3.js";
|
|
3
|
+
import { u as K } from "./use-page-expand-manager-D6T75I11.js";
|
|
4
|
+
import { compact as ce, filter as F, isEmpty as S, uniqBy as Le, keyBy as de, mapValues as Te, startCase as Ce, toLower as T, includes as R, find as z, get as Q, map as Ee } from "lodash-es";
|
|
5
|
+
import { useTranslation as Ue, useLanguages as ae } from "@chaibuilder/sdk";
|
|
6
|
+
import { useAtom as $e } from "jotai";
|
|
7
|
+
import { NotepadText as Me, MoreHorizontal as ze, Lock as Fe, Edit as je, Plus as Be, ChevronRight as Ie, StarsIcon as Ge, Hash as De, File as ue } from "lucide-react";
|
|
8
|
+
import { useMemo as V, lazy as C, useState as N, useCallback as le, useEffect as M, Suspense as L } from "react";
|
|
9
|
+
const oe = (e, n) => !e || !Array.isArray(e) ? [] : S(n) ? e : ce(
|
|
10
|
+
F(e, (r) => {
|
|
11
|
+
const s = T(n);
|
|
12
|
+
return R(T((r == null ? void 0 : r.name) || ""), s) || R(T((r == null ? void 0 : r.slug) || ""), s);
|
|
13
|
+
})
|
|
14
|
+
), Oe = (e, n) => {
|
|
15
|
+
const r = /* @__PURE__ */ new Set(), s = de(e, "id");
|
|
16
|
+
return n.forEach((o) => {
|
|
17
|
+
let l = o;
|
|
18
|
+
for (; l.parent && s[l.parent]; )
|
|
19
|
+
r.add(l.parent), l = s[l.parent];
|
|
20
|
+
}), Array.from(r).map((o) => s[o]);
|
|
21
|
+
}, J = (e, n, r) => S(n) ? e : e.map((s) => {
|
|
22
|
+
if (!r(s.pageType))
|
|
23
|
+
return {
|
|
24
|
+
...s,
|
|
25
|
+
shouldExpandOnSearch: !0,
|
|
26
|
+
children: s.children ? J(s.children, n, r) : []
|
|
27
|
+
};
|
|
28
|
+
const o = s.children && s.children.some(
|
|
29
|
+
(l) => R(T(l.name || ""), T(n)) || R(T(l.slug || ""), T(n))
|
|
30
|
+
);
|
|
31
|
+
return {
|
|
32
|
+
...s,
|
|
33
|
+
shouldExpandOnSearch: o,
|
|
34
|
+
children: s.children ? J(s.children, n, r) : []
|
|
35
|
+
};
|
|
36
|
+
}), Re = (e) => {
|
|
37
|
+
if (!e || !e.length) return [];
|
|
38
|
+
const n = {};
|
|
39
|
+
e.forEach((s) => {
|
|
40
|
+
n[s.id] = { ...s, children: [] };
|
|
41
|
+
});
|
|
42
|
+
const r = [];
|
|
43
|
+
return Object.values(n).forEach((s) => {
|
|
44
|
+
s.parent && n[s.parent] ? n[s.parent].children.push(s) : r.push(s);
|
|
45
|
+
}), r;
|
|
46
|
+
}, me = (e) => !e || !e.length ? [] : [...e].sort(
|
|
47
|
+
(r, s) => (r.name || "").localeCompare(s.name || "")
|
|
48
|
+
).map((r) => ({
|
|
49
|
+
...r,
|
|
50
|
+
children: r.children ? me(r.children) : []
|
|
51
|
+
})), We = (e, n, r, s) => {
|
|
52
|
+
if (!e || !e.length) return [];
|
|
53
|
+
let o = e;
|
|
54
|
+
if (r !== "all" && (o = ce(F(e, { pageType: r }))), S(n))
|
|
55
|
+
o = oe(o, n);
|
|
56
|
+
else {
|
|
57
|
+
const u = oe(o, n), i = Oe(e, u);
|
|
58
|
+
o = Le([...u, ...i], "id");
|
|
59
|
+
}
|
|
60
|
+
const l = me(Re(o)), f = J(l, n, s), g = F(f, (u) => s(u.pageType)).sort((u, i) => (u.name || "").localeCompare(i.name || "")), P = F(f, (u) => !s(u.pageType));
|
|
61
|
+
let m = [];
|
|
62
|
+
if (r === "all") {
|
|
63
|
+
const u = de(P, "pageType");
|
|
64
|
+
m = Object.values(
|
|
65
|
+
Te(u, (i, x) => ({
|
|
66
|
+
...i,
|
|
67
|
+
id: x,
|
|
68
|
+
name: Ce(x),
|
|
69
|
+
isPartialGroup: !0,
|
|
70
|
+
children: f.filter((p) => p.pageType === x)
|
|
71
|
+
}))
|
|
72
|
+
);
|
|
73
|
+
} else
|
|
74
|
+
m = P.sort((u, i) => (u.name || "").localeCompare(i.name || ""));
|
|
75
|
+
return [...g, ...m];
|
|
76
|
+
}, He = ({ page: e }) => {
|
|
77
|
+
var s, o;
|
|
78
|
+
const { isExpanded: n, toggleExpanded: r } = K(e == null ? void 0 : e.id);
|
|
79
|
+
return /* @__PURE__ */ t(
|
|
80
|
+
"button",
|
|
81
|
+
{
|
|
82
|
+
onClick: (l) => {
|
|
83
|
+
l.stopPropagation(), r();
|
|
84
|
+
},
|
|
85
|
+
disabled: !((s = e == null ? void 0 : e.children) != null && s.length),
|
|
86
|
+
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 ${(o = e == null ? void 0 : e.children) != null && o.length ? "hover:text-blue-400" : "opacity-0"}`,
|
|
87
|
+
children: /* @__PURE__ */ t(
|
|
88
|
+
Ie,
|
|
89
|
+
{
|
|
90
|
+
size: 12,
|
|
91
|
+
className: `stroke-[4] transition-transform duration-200 ${n ? "rotate-90" : ""}`
|
|
92
|
+
}
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
);
|
|
96
|
+
}, _e = ({ page: e, pageType: n }) => /* @__PURE__ */ t("div", { className: "flex h-full items-center justify-center gap-x-1", children: e.dynamic ? /* @__PURE__ */ t(Ge, { size: 12, className: "text-yellow-400" }) : n != null && n.icon ? /* @__PURE__ */ t(
|
|
97
|
+
"div",
|
|
98
|
+
{
|
|
99
|
+
className: "flex h-4 max-h-4 w-4 max-w-4 items-center justify-center stroke-[1] text-slate-500",
|
|
100
|
+
dangerouslySetInnerHTML: { __html: n.icon }
|
|
101
|
+
}
|
|
102
|
+
) : n != null && n.hasSlug ? /* @__PURE__ */ t(ue, { size: 12, className: "stroke-[1] text-slate-500" }) : /* @__PURE__ */ t(De, { size: 12, className: "stroke-[1] text-slate-500" }) }), qe = ({ isOnline: e }) => /* @__PURE__ */ t("div", { className: `h-2 w-2 rounded-full ${e ? "bg-green-300" : "bg-gray-300"}` }), Qe = ({
|
|
103
|
+
page: e,
|
|
104
|
+
pageTypes: n,
|
|
105
|
+
currentPage: r,
|
|
106
|
+
onClickAction: s,
|
|
107
|
+
languagePages: o,
|
|
108
|
+
selectedLanguage: l,
|
|
109
|
+
showUntranslatedPages: f
|
|
110
|
+
}) => {
|
|
111
|
+
const [g] = be(), P = ie(), m = r === e.id, u = !!e.isTemplate, i = V(() => z(n, { key: e.pageType }), [n, e.pageType]), x = g == null ? void 0 : g[e.id], { data: p } = ye(x), w = p ? p == null ? void 0 : p.name : null;
|
|
112
|
+
let d = Q(o, e == null ? void 0 : e.id);
|
|
113
|
+
d = Q(d, "lang") === l ? d : null;
|
|
114
|
+
const A = l === P || !!d, E = (d == null ? void 0 : d.name) || (e == null ? void 0 : e.name) || "No name";
|
|
115
|
+
let b = (d == null ? void 0 : d.slug) || (e == null ? void 0 : e.slug) || "";
|
|
116
|
+
const j = b + (e != null && e.dynamic ? `/${i == null ? void 0 : i.dynamicSlug}` : "") + (e != null && e.dynamicSlugCustom ? `${e.dynamicSlugCustom}` : "");
|
|
117
|
+
if (b.startsWith("/") && !f) {
|
|
118
|
+
const c = b.split("/").pop();
|
|
119
|
+
b = b.endsWith(c) && e.dynamic ? "" : `/${c}`;
|
|
120
|
+
}
|
|
121
|
+
const B = V(() => {
|
|
122
|
+
const c = "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]", I = `${m ? "border-primary/30 bg-primary/5" : "border-transparent hover:border-gray-200 hover:bg-gray-100"}`;
|
|
123
|
+
return A ? `${c} ${I} ${w ? "opacity-60" : ""}` : `${c} bg-gray-100 opacity-50 group-hover:border-gray-200 border-transparent group-hover:bg-blue-100`;
|
|
124
|
+
}, [A, m, w]);
|
|
125
|
+
return /* @__PURE__ */ y("div", { className: "group relative", children: [
|
|
126
|
+
/* @__PURE__ */ y(
|
|
127
|
+
"div",
|
|
128
|
+
{
|
|
129
|
+
onClick: () => !e.isPartialGroup && A && s("select", e == null ? void 0 : e.id),
|
|
130
|
+
className: B,
|
|
131
|
+
children: [
|
|
132
|
+
/* @__PURE__ */ t(He, { page: e }),
|
|
133
|
+
!e.isPartialGroup && /* @__PURE__ */ t(qe, { isOnline: d ? d.online : e.online }),
|
|
134
|
+
!e.isPartialGroup && /* @__PURE__ */ t(_e, { page: e, pageType: i }),
|
|
135
|
+
/* @__PURE__ */ t(_, { content: E, side: "top", showTooltip: E.length > 35, children: /* @__PURE__ */ t("span", { className: "max-w-[40%] truncate font-medium text-black", children: E }) }),
|
|
136
|
+
(b || e.dynamic) && /* @__PURE__ */ t(_, { content: j, side: "top", showTooltip: !0, children: /* @__PURE__ */ y("span", { className: "max-w-[40%] truncate font-mono text-xs text-muted-foreground", children: [
|
|
137
|
+
b,
|
|
138
|
+
e.dynamic && (i == null ? void 0 : i.dynamicSlug) && /* @__PURE__ */ y("span", { className: "text-xs text-gray-500", children: [
|
|
139
|
+
"/",
|
|
140
|
+
i == null ? void 0 : i.dynamicSlug,
|
|
141
|
+
e.dynamicSlugCustom
|
|
142
|
+
] })
|
|
143
|
+
] }) }),
|
|
144
|
+
u && /* @__PURE__ */ t(_, { content: "Template", side: "top", children: /* @__PURE__ */ t("span", { className: "text-blue-500", children: /* @__PURE__ */ t(Me, { size: 16 }) }) }),
|
|
145
|
+
!e.isPartialGroup && A && !w ? /* @__PURE__ */ t("div", { className: "duration absolute right-0.5 top-[3px]", children: /* @__PURE__ */ t(
|
|
146
|
+
ge,
|
|
147
|
+
{
|
|
148
|
+
isLanguagePage: !!d,
|
|
149
|
+
page: d || e,
|
|
150
|
+
setDuplicatePage: (c) => s("duplicate", c),
|
|
151
|
+
setAddEditPage: (c) => s("edit", d || c),
|
|
152
|
+
setUnpublishPage: (c) => s("unpublish", c),
|
|
153
|
+
setDeletePage: (c) => s("delete", d || c),
|
|
154
|
+
setMarkAsTemplate: (c) => s("markAsTemplate", c),
|
|
155
|
+
setUnmarkAsTemplate: (c) => s("unmarkAsTemplate", c),
|
|
156
|
+
children: /* @__PURE__ */ t("div", { className: "m-0 cursor-pointer rounded border border-transparent p-0.5 duration-100 hover:border-gray-400 hover:bg-white", children: /* @__PURE__ */ t(ze, { className: "h-4 w-4", onClick: (c) => c.stopPropagation() }) })
|
|
157
|
+
}
|
|
158
|
+
) }) : w ? /* @__PURE__ */ t("span", { className: "duration absolute right-1.5 top-1/2 -translate-y-1/2 text-xs text-gray-500", children: /* @__PURE__ */ t(Fe, { className: "h-3.5 w-3.5 fill-red-200 text-red-500" }) }) : null
|
|
159
|
+
]
|
|
160
|
+
}
|
|
161
|
+
),
|
|
162
|
+
/* @__PURE__ */ t(O, { children: w && /* @__PURE__ */ y("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: [
|
|
163
|
+
/* @__PURE__ */ t(je, { size: 12, className: "stroke-[3]" }),
|
|
164
|
+
" ",
|
|
165
|
+
/* @__PURE__ */ t("span", { className: "font-medium", children: w }),
|
|
166
|
+
" is editing this page"
|
|
167
|
+
] }) }),
|
|
168
|
+
/* @__PURE__ */ t(O, { children: !A && !e.isPartialGroup && !w && /* @__PURE__ */ y(
|
|
169
|
+
"button",
|
|
170
|
+
{
|
|
171
|
+
onClick: (c) => {
|
|
172
|
+
c.stopPropagation(), s("addLanguagePage", { language: l, page: e });
|
|
173
|
+
},
|
|
174
|
+
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",
|
|
175
|
+
children: [
|
|
176
|
+
/* @__PURE__ */ t(Be, { size: 12, className: "stroke-[3]" }),
|
|
177
|
+
" ",
|
|
178
|
+
/* @__PURE__ */ y("span", { className: "text-[10px]", children: [
|
|
179
|
+
"Add ",
|
|
180
|
+
Q(ke, l),
|
|
181
|
+
" Page"
|
|
182
|
+
] })
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
) })
|
|
186
|
+
] });
|
|
187
|
+
}, he = ({
|
|
188
|
+
pages: e,
|
|
189
|
+
tier: n,
|
|
190
|
+
pageTypes: r,
|
|
191
|
+
currentPage: s,
|
|
192
|
+
onClickAction: o,
|
|
193
|
+
languagePages: l,
|
|
194
|
+
selectedLanguage: f,
|
|
195
|
+
showUntranslatedPages: g
|
|
196
|
+
}) => {
|
|
197
|
+
const { expandedPages: P } = K();
|
|
198
|
+
return /* @__PURE__ */ t("div", { className: "space-y-0.5", style: { paddingLeft: `${n * 10}px` }, children: e.map((m) => /* @__PURE__ */ y(O, { children: [
|
|
199
|
+
/* @__PURE__ */ t(
|
|
200
|
+
Qe,
|
|
201
|
+
{
|
|
202
|
+
page: m,
|
|
203
|
+
pageTypes: r,
|
|
204
|
+
currentPage: s,
|
|
205
|
+
onClickAction: o,
|
|
206
|
+
languagePages: l,
|
|
207
|
+
selectedLanguage: f,
|
|
208
|
+
showUntranslatedPages: g
|
|
209
|
+
}
|
|
210
|
+
),
|
|
211
|
+
m.children && m.children.length > 0 && (P == null ? void 0 : P.includes(m.id)) && /* @__PURE__ */ t(
|
|
212
|
+
he,
|
|
213
|
+
{
|
|
214
|
+
pages: m.children,
|
|
215
|
+
tier: n + 1,
|
|
216
|
+
pageTypes: r,
|
|
217
|
+
currentPage: s,
|
|
218
|
+
onClickAction: o,
|
|
219
|
+
languagePages: l,
|
|
220
|
+
selectedLanguage: f,
|
|
221
|
+
showUntranslatedPages: g
|
|
222
|
+
}
|
|
223
|
+
)
|
|
224
|
+
] }, m.id)) });
|
|
225
|
+
}, Ve = C(() => import("./page-manager-search-and-filter-CJ4AK1_7.js")), Je = C(() => import("./add-new-page-DX1aQA56.js")), Ke = C(() => import("./delete-page-DE-nabXs.js")), Xe = C(() => import("./duplicate-page-C1r3iBDY.js")), Ye = C(() => import("./mark-as-template-0kikl0oL.js")), Ze = C(() => import("./unmark-as-template-BENGNo7g.js")), et = C(() => import("./unpublish-page-D5tWKVLY.js")), ct = ({ close: e }) => {
|
|
226
|
+
const { t: n } = Ue(), { languages: r, setSelectedLang: s } = ae(), { data: o } = Ne(), { data: l, isFetching: f } = we(), [g, P] = ve(), { updateForSelectedPage: m, expandPagesOnSearch: u } = K(null), i = ie(), x = g.get("page"), [p, w] = N(""), [d, A] = N(null), [E, b] = N(null), [j, B] = N(null), [c, I] = N(null), [U, W] = N(""), [X, Y] = N(null), [Z, ee] = N(null), [k, fe] = N(i), [Pe, xe] = N(!1), [, te] = $e(Se), G = Pe && k !== i, { data: $, isFetching: pe } = Ae(k), se = le(
|
|
227
|
+
(h) => {
|
|
228
|
+
var a;
|
|
229
|
+
return (a = z(o, { key: h })) == null ? void 0 : a.hasSlug;
|
|
230
|
+
},
|
|
231
|
+
[o]
|
|
232
|
+
), v = V(() => l ? G ? F(l, (h) => !($ != null && $[h.id])) : We(l, p, U, se) : [], [l, se, p, U, $, G]);
|
|
233
|
+
M(() => {
|
|
234
|
+
s(i);
|
|
235
|
+
}, [i, s]), M(() => {
|
|
236
|
+
if (!S(U)) return;
|
|
237
|
+
const h = sessionStorage.getItem("pageTypeFilter") || "all";
|
|
238
|
+
!S(o) && h && (z(o, { key: h }) ? W(h) : W("all"));
|
|
239
|
+
}, [o, U]), M(() => {
|
|
240
|
+
if (x && !f && !z(l, { id: x })) {
|
|
241
|
+
const a = z(l, { slug: "/" });
|
|
242
|
+
if (a) {
|
|
243
|
+
const D = new URLSearchParams({ page: a.id });
|
|
244
|
+
q(D, P);
|
|
245
|
+
} else
|
|
246
|
+
q(new URLSearchParams({}), P, !0);
|
|
247
|
+
}
|
|
248
|
+
}, [l, x, f, P]), M(() => {
|
|
249
|
+
x && !f && !S(v) && m(v, x);
|
|
250
|
+
}, [x, f, v, m]), M(() => {
|
|
251
|
+
!S(p) && !S(v) && u(v);
|
|
252
|
+
}, [p, v, u]);
|
|
253
|
+
const { setSelectedLang: H } = ae(), ne = le(
|
|
254
|
+
(h) => {
|
|
255
|
+
const a = new URLSearchParams({ page: h });
|
|
256
|
+
k !== i ? (a.set("lang", k), H(k)) : H(""), q(a, P), e();
|
|
257
|
+
},
|
|
258
|
+
[e, P, H, k, i]
|
|
259
|
+
), re = (h, a) => {
|
|
260
|
+
var D;
|
|
261
|
+
if (a)
|
|
262
|
+
switch (h) {
|
|
263
|
+
case "add":
|
|
264
|
+
b(a);
|
|
265
|
+
break;
|
|
266
|
+
case "select":
|
|
267
|
+
ne(a);
|
|
268
|
+
break;
|
|
269
|
+
case "edit":
|
|
270
|
+
k !== i ? te({
|
|
271
|
+
edit: !0,
|
|
272
|
+
id: a == null ? void 0 : a.id,
|
|
273
|
+
primaryPage: a == null ? void 0 : a.primaryPage
|
|
274
|
+
}) : b(a);
|
|
275
|
+
break;
|
|
276
|
+
case "delete":
|
|
277
|
+
A(a);
|
|
278
|
+
break;
|
|
279
|
+
case "unpublish":
|
|
280
|
+
B(a);
|
|
281
|
+
break;
|
|
282
|
+
case "markAsTemplate":
|
|
283
|
+
I(a);
|
|
284
|
+
break;
|
|
285
|
+
case "unmarkAsTemplate":
|
|
286
|
+
ee(a);
|
|
287
|
+
break;
|
|
288
|
+
case "duplicate":
|
|
289
|
+
Y(a);
|
|
290
|
+
break;
|
|
291
|
+
case "addLanguagePage":
|
|
292
|
+
te({
|
|
293
|
+
edit: !1,
|
|
294
|
+
primaryPage: ((D = a == null ? void 0 : a.page) == null ? void 0 : D.id) || "",
|
|
295
|
+
preselectedLang: (a == null ? void 0 : a.language) || k
|
|
296
|
+
});
|
|
297
|
+
break;
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
return /* @__PURE__ */ y(O, { children: [
|
|
301
|
+
/* @__PURE__ */ y("div", { className: "flex h-full flex-col justify-between", children: [
|
|
302
|
+
/* @__PURE__ */ t(L, { children: /* @__PURE__ */ t(
|
|
303
|
+
Ve,
|
|
304
|
+
{
|
|
305
|
+
pages: v,
|
|
306
|
+
search: p,
|
|
307
|
+
setSearch: w,
|
|
308
|
+
languages: [i, ...r],
|
|
309
|
+
selectedLanguage: k,
|
|
310
|
+
setSelectedLanguage: fe,
|
|
311
|
+
selectedPageType: U,
|
|
312
|
+
setSelectedPageType: W,
|
|
313
|
+
onAddPage: (h) => re("add", h),
|
|
314
|
+
showUntranslatedPages: G,
|
|
315
|
+
setShowUntranslatedPages: xe
|
|
316
|
+
}
|
|
317
|
+
) }),
|
|
318
|
+
/* @__PURE__ */ t("div", { className: "flex-1 overflow-y-auto px-4 pb-6 pt-2", children: f || pe ? /* @__PURE__ */ t("div", { className: "space-y-2", children: Ee([...Array(15).keys()], (h) => /* @__PURE__ */ t("div", { className: "h-7 w-full animate-pulse rounded border border-gray-300 bg-gray-200" }, h)) }) : S(v) ? /* @__PURE__ */ y("div", { className: "flex h-[70vh] flex-col items-center justify-center gap-y-1 text-sm font-medium text-slate-500", children: [
|
|
319
|
+
/* @__PURE__ */ t(ue, { className: "h-6 w-6 stroke-[1]" }),
|
|
320
|
+
n("Empty List!"),
|
|
321
|
+
/* @__PURE__ */ t("span", { className: "font-light", children: n("Add new page to start") })
|
|
322
|
+
] }) : /* @__PURE__ */ t(
|
|
323
|
+
he,
|
|
324
|
+
{
|
|
325
|
+
tier: 0,
|
|
326
|
+
pages: v,
|
|
327
|
+
pageTypes: o,
|
|
328
|
+
currentPage: x || "",
|
|
329
|
+
onClickAction: re,
|
|
330
|
+
languagePages: $,
|
|
331
|
+
selectedLanguage: k,
|
|
332
|
+
showUntranslatedPages: G
|
|
333
|
+
}
|
|
334
|
+
) })
|
|
335
|
+
] }),
|
|
336
|
+
E && /* @__PURE__ */ t(L, { children: /* @__PURE__ */ t(
|
|
337
|
+
Je,
|
|
338
|
+
{
|
|
339
|
+
closePanel: e,
|
|
340
|
+
editPage: ne,
|
|
341
|
+
addEditPage: E,
|
|
342
|
+
setAddEditPage: b
|
|
343
|
+
}
|
|
344
|
+
) }),
|
|
345
|
+
d && /* @__PURE__ */ t(L, { children: /* @__PURE__ */ t(Ke, { page: d, onClose: () => A(null) }) }),
|
|
346
|
+
j && /* @__PURE__ */ t(L, { children: /* @__PURE__ */ t(et, { page: j, onClose: () => B(null) }) }),
|
|
347
|
+
c && /* @__PURE__ */ t(L, { children: /* @__PURE__ */ t(Ye, { page: c, onClose: () => I(null) }) }),
|
|
348
|
+
Z && /* @__PURE__ */ t(L, { children: /* @__PURE__ */ t(Ze, { page: Z, onClose: () => ee(null) }) }),
|
|
349
|
+
X && /* @__PURE__ */ t(L, { children: /* @__PURE__ */ t(Xe, { page: X, onClose: () => Y(null), closePanel: e }) })
|
|
350
|
+
] });
|
|
351
|
+
};
|
|
352
|
+
export {
|
|
353
|
+
ct as default
|
|
354
|
+
};
|