@chaibuilder/pages 0.16.14 → 0.16.15

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.
Files changed (94) hide show
  1. package/dist/{2AITGKQY-B7xwscsX.js → 2AITGKQY-2rt9M99C.js} +5 -5
  2. package/dist/{2AITGKQY-B9AnRLq_.cjs → 2AITGKQY-Cs6RBSPQ.cjs} +1 -1
  3. package/dist/{NCMVHL6D-CRMC-wXy.cjs → NCMVHL6D-CsC6nsSQ.cjs} +1 -1
  4. package/dist/{NCMVHL6D-B1mwht0Q.js → NCMVHL6D-vUfYKc6i.js} +4 -4
  5. package/dist/{ZDWCUMSJ-BqqPEOij.cjs → ZDWCUMSJ-B2OZjsr6.cjs} +1 -1
  6. package/dist/{ZDWCUMSJ-CxKNtXtp.js → ZDWCUMSJ-CzEWKlEU.js} +1 -1
  7. package/dist/active-in-another-tab-B0N5S-Bh.js +34 -0
  8. package/dist/active-in-another-tab-BK3cZf-x.cjs +1 -0
  9. package/dist/{add-new-language-page-D2a6GK-7.cjs → add-new-language-page-Dt1j-8Zg.cjs} +1 -1
  10. package/dist/{add-new-language-page-DD0qvJJs.js → add-new-language-page-YlqcCdlK.js} +20 -20
  11. package/dist/{add-new-page-01GDCaa4.cjs → add-new-page-DqhQUQBz.cjs} +1 -1
  12. package/dist/{add-new-page-CYtuChN1.js → add-new-page-aYomeid4.js} +1 -1
  13. package/dist/{ai-panel-content-DfdnvlS8.js → ai-panel-content-C6cH9rrC.js} +2 -2
  14. package/dist/{ai-panel-content-Ouz6pu_0.cjs → ai-panel-content-MOZmNIKP.cjs} +1 -1
  15. package/dist/{ai-panel-default-lang-Bi2fH1so.js → ai-panel-default-lang-BZHkFsox.js} +3 -3
  16. package/dist/{ai-panel-default-lang-N1pb8rzQ.cjs → ai-panel-default-lang-DOk_Q0IO.cjs} +2 -2
  17. package/dist/{ai-panel-other-lang-2JPRSyO1.js → ai-panel-other-lang-D2A46FTg.js} +3 -3
  18. package/dist/{ai-panel-other-lang-BysU1464.cjs → ai-panel-other-lang-qHrdvAMa.cjs} +1 -1
  19. package/dist/{ai-prompt-input-JeIqWZco.cjs → ai-prompt-input-BZSjjNJd.cjs} +1 -1
  20. package/dist/{ai-prompt-input-DadL_cng.js → ai-prompt-input-C6gDvvLQ.js} +2 -2
  21. package/dist/{ai-translation-prompt-CQb1L7NM.cjs → ai-translation-prompt-BqXo2CLp.cjs} +1 -1
  22. package/dist/{ai-translation-prompt-B0si-R0R.js → ai-translation-prompt-DTR0wbGt.js} +1 -1
  23. package/dist/continue-editing-in-this-client-C3T6Jzhi.cjs +1 -0
  24. package/dist/continue-editing-in-this-client-D2S1yCOM.js +24 -0
  25. package/dist/delete-page-BF1k60U2.js +70 -0
  26. package/dist/delete-page-x0DWKzsR.cjs +1 -0
  27. package/dist/{digital-asset-manager-B5FQGtGY.cjs → digital-asset-manager-BmlFt2T_.cjs} +1 -1
  28. package/dist/{digital-asset-manager-jfnmWRJj.js → digital-asset-manager-C8udwDBW.js} +1 -1
  29. package/dist/{duplicate-page-BNjfZ7Wd.cjs → duplicate-page-Dt_QZkTk.cjs} +1 -1
  30. package/dist/{duplicate-page-CERjaPIW.js → duplicate-page-u_6vUVo1.js} +13 -13
  31. package/dist/{dynamic-page-selector-Bpz_bvRu.cjs → dynamic-page-selector-Cgs_Y_Kl.cjs} +1 -1
  32. package/dist/{dynamic-page-selector-XEWV4iCf.js → dynamic-page-selector-DxBHmglP.js} +1 -1
  33. package/dist/index-BeWL6Sj6.cjs +5 -0
  34. package/dist/index-DI2Rwk5v.js +4820 -0
  35. package/dist/index.cjs +1 -1
  36. package/dist/index.d.ts +1 -34
  37. package/dist/index.js +21 -22
  38. package/dist/{json-diff-viewer-H-2DkGza.cjs → json-diff-viewer-D2g0Yab2.cjs} +1 -1
  39. package/dist/{json-diff-viewer-DyvKomxd.js → json-diff-viewer-QdUwk7yF.js} +6 -6
  40. package/dist/{lang-panel-BWP5A-FD.js → lang-panel-B8OD0GiA.js} +24 -24
  41. package/dist/{lang-panel-DcZ7u4em.cjs → lang-panel-M2Zb01lF.cjs} +1 -1
  42. package/dist/{mark-as-template-1oVraE1x.js → mark-as-template-CJ1mlxYT.js} +7 -7
  43. package/dist/{mark-as-template-B_FyVRRO.cjs → mark-as-template-DONU52b1.cjs} +1 -1
  44. package/dist/{no-language-page-content-JO4YYUx7.cjs → no-language-page-content-DD9Ok2Ku.cjs} +1 -1
  45. package/dist/{no-language-page-content-CEci_4j7.js → no-language-page-content-Dtm37LTJ.js} +1 -1
  46. package/dist/no-language-page-dialog-D3dvenZ7.cjs +1 -0
  47. package/dist/no-language-page-dialog-Dj_z2_hF.js +10 -0
  48. package/dist/{page-creator-DJJFl7px.js → page-creator-DIMFISo4.js} +52 -52
  49. package/dist/{page-creator-BGgoOA92.cjs → page-creator-DTC66ujU.cjs} +1 -1
  50. package/dist/page-lock-CI6BYvF_.cjs +1 -0
  51. package/dist/page-lock-DUlNr3os.js +30 -0
  52. package/dist/page-locked-dialog-BKwULMV7.js +133 -0
  53. package/dist/page-locked-dialog-DorIbva0.cjs +1 -0
  54. package/dist/page-manager-new-lNVrLOJp.cjs +1 -0
  55. package/dist/page-manager-new-znvqI9_L.js +354 -0
  56. package/dist/{page-manager-search-and-filter-DbUoW8Di.js → page-manager-search-and-filter-C-_w7N27.js} +1 -1
  57. package/dist/{page-manager-search-and-filter-Dgh8iyGp.cjs → page-manager-search-and-filter-pe0q0qnZ.cjs} +1 -1
  58. package/dist/{page-revisions-content-CwoXXE53.cjs → page-revisions-content-Caaj5TEI.cjs} +1 -1
  59. package/dist/{page-revisions-content-CxEJGxLY.js → page-revisions-content-CyLjyxNU.js} +19 -19
  60. package/dist/pages.css +1 -1
  61. package/dist/{publish-pages-content-CfAlmivf.js → publish-pages-content-Bih1W9C4.js} +88 -88
  62. package/dist/publish-pages-content-D5beVcQI.cjs +1 -0
  63. package/dist/{save-to-lib-BCaBfh0I.js → save-to-lib-BwpkJcT2.js} +1 -1
  64. package/dist/{save-to-lib-DpyJA0y1.cjs → save-to-lib-DPAERsi4.cjs} +1 -1
  65. package/dist/{selected-block-display-BmNhvYKu.js → selected-block-display-GXSf3y2s.js} +1 -1
  66. package/dist/{selected-block-display-CqnwyGRp.cjs → selected-block-display-s99Y91qI.cjs} +1 -1
  67. package/dist/{seo-panel-BH8fcGqr.js → seo-panel-BurZA566.js} +61 -61
  68. package/dist/{seo-panel-D-nKfsRJ.cjs → seo-panel-BxUfalVy.cjs} +1 -1
  69. package/dist/{shared-json-ld-m_OsVv8h.cjs → shared-json-ld-BYAdrPeC.cjs} +1 -1
  70. package/dist/{shared-json-ld-zTDoJzUv.js → shared-json-ld-DHWdJvQd.js} +39 -39
  71. package/dist/{slug-input-vzNtu37S.cjs → slug-input-CR2B1kDJ.cjs} +1 -1
  72. package/dist/{slug-input-CumDDlCk.js → slug-input-Z_ny7bgX.js} +1 -1
  73. package/dist/take-over-request-CnEpToCM.cjs +1 -0
  74. package/dist/take-over-request-DF2JsIes.js +63 -0
  75. package/dist/{theme-panel-footer-CdUmjB-e.js → theme-panel-footer-5mxFeEua.js} +4 -4
  76. package/dist/{theme-panel-footer-CKccBcd9.cjs → theme-panel-footer-C2CjHoBu.cjs} +1 -1
  77. package/dist/{unmark-as-template-BNFOsxIg.cjs → unmark-as-template-Dn90g1eh.cjs} +1 -1
  78. package/dist/{unmark-as-template-6ew-7bf8.js → unmark-as-template-JRRUYTOY.js} +1 -1
  79. package/dist/{unpublish-page-BZQpTpU3.cjs → unpublish-page-C3C_rTRd.cjs} +1 -1
  80. package/dist/{unpublish-page-BomE76Wg.js → unpublish-page-FZ8rbi7u.js} +9 -9
  81. package/dist/{web-preview-jo8lnpEx.js → web-preview-CGBKG162.js} +1 -1
  82. package/dist/{web-preview-C5QTX7bS.cjs → web-preview-NdxC92Fk.cjs} +1 -1
  83. package/package.json +3 -3
  84. package/dist/delete-page-C8Nt7IYF.cjs +0 -1
  85. package/dist/delete-page-_96Di9yN.js +0 -40
  86. package/dist/index-Pdb5tSRL.cjs +0 -5
  87. package/dist/index-e9WlBH0R.js +0 -4960
  88. package/dist/page-lock-request-BoYzkcyt.cjs +0 -1
  89. package/dist/page-lock-request-WzpcD2ZN.js +0 -75
  90. package/dist/page-locked-by-dialog-Djvjp2Hx.js +0 -68
  91. package/dist/page-locked-by-dialog-bvI27OZ6.cjs +0 -1
  92. package/dist/page-manager-new-CMfGorRQ.cjs +0 -1
  93. package/dist/page-manager-new-DmVX0qLk.js +0 -354
  94. package/dist/publish-pages-content-BRu7qwAo.cjs +0 -1
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-BeWL6Sj6.cjs"),C=require("@chaibuilder/sdk"),r=require("@chaibuilder/sdk/ui"),c=require("lucide-react"),o=require("react"),O=()=>{const m=s.useCurrentPageOwner(),f=s.useSendRealtimeEvent(),{setPageStatus:T}=s.usePageLockStatus(),{data:t,isFetching:j}=s.useChaiUserInfo((m==null?void 0:m.userId)||""),{pageLockMeta:d,setPageLockMeta:p}=s.usePageLockMeta(),{t:a}=C.useTranslation(),[u,i]=o.useState(""),[n,g]=o.useState({}),[N,v]=o.useState(!1),l=o.useRef(null);o.useEffect(()=>{d!=null&&d.type&&(l.current&&clearTimeout(l.current),g(d),p({}),i(""))},[d,p]);const k=()=>{u!==s.EVENT.TAKE_OVER_REQUEST&&(i(s.EVENT.TAKE_OVER_REQUEST),f(s.EVENT.TAKE_OVER_REQUEST),l.current=setTimeout(()=>i(""),2e4))},b=()=>{u!==s.EVENT.FORCE_TAKE_OVER_REQUEST&&(i(s.EVENT.FORCE_TAKE_OVER_REQUEST),f(s.EVENT.FORCE_TAKE_OVER_REQUEST),T(s.PAGE_STATUS.CHECKING),l.current=setTimeout(()=>i(""),2e4))},R=()=>{g({}),l.current&&clearTimeout(l.current),i("")},x=j?"Loading...":(t==null?void 0:t.name)||"Current editor",h=u===s.EVENT.TAKE_OVER_REQUEST,E=u===s.EVENT.FORCE_TAKE_OVER_REQUEST;return e.jsx(s.BlurContainer,{children:e.jsxs(r.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(r.CardHeader,{className:"space-y-1 border-b pb-3",children:e.jsxs(r.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:a("Page Locked for Editing")})]})}),e.jsxs(r.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:[t!=null&&t.avatar?e.jsx("img",{src:t.avatar,alt:t.name,className:"h-12 w-12 flex-shrink-0 rounded-full bg-black p-3 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}),(t==null?void 0:t.email)&&e.jsx("p",{className:"truncate text-sm leading-tight text-muted-foreground",children:t.email})]})]})]}),((n==null?void 0:n.type)===s.EVENT.TAKE_OVER_REJECTED||(n==null?void 0:n.type)===s.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:(t==null?void 0:t.name)||"The current editor"}),(n==null?void 0:n.type)===s.EVENT.TAKE_OVER_REJECTED?" rejected your take over request.":" forcefully took over this page."]})]}),e.jsx(r.Button,{size:"icon",variant:"ghost",onClick:R,className:"flex-shrink-0",children:e.jsx(c.X,{className:"h-4 w-4"})})]})})]}),e.jsx(r.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:a("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:a("Take Over Request:")}),e.jsx("p",{className:"mt-1 text-xs text-muted-foreground",children:a("Send a request to {{currentEditorName}} asking them to release the page. They can accept or decline your request.",{currentEditorName:x})})]}),e.jsxs(r.Button,{disabled:h,variant:"default",onClick:k,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:a("Request sent. If no response, try again or use force take over.")})]}),e.jsx(r.Accordion,{type:"single",collapsible:!0,className:"w-full",children:e.jsxs(r.AccordionItem,{value:"force-takeover",className:"rounded-md border border-destructive/40 bg-destructive/5",children:[e.jsx(r.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"}),a("Force Take Over")]}),e.jsx("p",{className:"pl-6 text-xs font-normal leading-tight text-muted-foreground",children:a("Immediately take control (use with caution)")})]})})}),e.jsx(r.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:N,onChange:y=>v(y.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:a("I understand this will immediately close the editor for {{currentEditorName}}. I am using this option with caution.",{currentEditorName:x})})]}),e.jsxs(r.Button,{disabled:!N||E,variant:"destructive",onClick:b,className:"w-full gap-2",children:[e.jsx(c.ShieldAlert,{className:"h-4 w-4"}),a(E?"Take over page...":"Force Take Over")]}),E&&e.jsx("p",{className:"text-xs text-muted-foreground",children:a("Attempting to forcefully take over this page. Please wait while we update the editing session.")})]})})]})})]})})]})})};exports.default=O;
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),x=require("./index-BeWL6Sj6.cjs"),G=require("./use-page-expand-manager-2KjeYfVS.cjs"),n=require("lodash-es"),$=require("@chaibuilder/sdk"),te=require("jotai"),v=require("lucide-react"),l=require("react"),J=(e,r)=>!e||!Array.isArray(e)?[]:n.isEmpty(r)?e:n.compact(n.filter(e,a=>{const t=n.toLower(r);return n.includes(n.toLower((a==null?void 0:a.name)||""),t)||n.includes(n.toLower((a==null?void 0:a.slug)||""),t)})),ne=(e,r)=>{const a=new Set,t=n.keyBy(e,"id");return r.forEach(c=>{let o=c;for(;o.parent&&t[o.parent];)a.add(o.parent),o=t[o.parent]}),Array.from(a).map(c=>t[c])},B=(e,r,a)=>n.isEmpty(r)?e:e.map(t=>{if(!a(t.pageType))return{...t,shouldExpandOnSearch:!0,children:t.children?B(t.children,r,a):[]};const c=t.children&&t.children.some(o=>n.includes(n.toLower(o.name||""),n.toLower(r))||n.includes(n.toLower(o.slug||""),n.toLower(r)));return{...t,shouldExpandOnSearch:c,children:t.children?B(t.children,r,a):[]}}),re=e=>{if(!e||!e.length)return[];const r={};e.forEach(t=>{r[t.id]={...t,children:[]}});const a=[];return Object.values(r).forEach(t=>{t.parent&&r[t.parent]?r[t.parent].children.push(t):a.push(t)}),a},K=e=>!e||!e.length?[]:[...e].sort((a,t)=>(a.name||"").localeCompare(t.name||"")).map(a=>({...a,children:a.children?K(a.children):[]})),ae=(e,r,a,t)=>{if(!e||!e.length)return[];let c=e;if(a!=="all"&&(c=n.compact(n.filter(e,{pageType:a}))),n.isEmpty(r))c=J(c,r);else{const m=J(c,r),d=ne(e,m);c=n.uniqBy([...m,...d],"id")}const o=K(re(c)),y=B(o,r,t),N=n.filter(y,m=>t(m.pageType)).sort((m,d)=>(m.name||"").localeCompare(d.name||"")),p=n.filter(y,m=>!t(m.pageType));let f=[];if(a==="all"){const m=n.keyBy(p,"pageType");f=Object.values(n.mapValues(m,(d,j)=>({...d,id:j,name:n.startCase(j),isPartialGroup:!0,children:y.filter(g=>g.pageType===j)})))}else f=p.sort((m,d)=>(m.name||"").localeCompare(d.name||""));return[...N,...f]},le=({page:e})=>{var t,c;const{isExpanded:r,toggleExpanded:a}=G.usePageExpandManager(e==null?void 0:e.id);return s.jsx("button",{onClick:o=>{o.stopPropagation(),a()},disabled:!((t=e==null?void 0:e.children)!=null&&t.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:s.jsx(v.ChevronRight,{size:12,className:`stroke-[4] transition-transform duration-200 ${r?"rotate-90":""}`})})},ie=({page:e,pageType:r})=>s.jsx("div",{className:"flex h-full items-center justify-center gap-x-1",children:e.dynamic?s.jsx(v.StarsIcon,{size:12,className:"text-yellow-400"}):r!=null&&r.icon?s.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?s.jsx(v.File,{size:12,className:"stroke-[1] text-slate-500"}):s.jsx(v.Hash,{size:12,className:"stroke-[1] text-slate-500"})}),oe=({isOnline:e})=>s.jsx("div",{className:`h-2 w-2 rounded-full ${e?"bg-green-300":"bg-gray-300"}`}),ce=({page:e,pageTypes:r,currentPage:a,onClickAction:t,languagePages:c,selectedLanguage:o,showUntranslatedPages:y})=>{const N=x.useUserId(),{pageToUser:p}=x.usePageToUser(),f=n.get(p,[e==null?void 0:e.id,"userId"]),{data:m}=x.useChaiUserInfo(f),d=m&&N!==f?m==null?void 0:m.name:null,j=x.useFallbackLang(),g=a===e.id,U=!!e.isTemplate,b=l.useMemo(()=>n.find(r,{key:e.pageType}),[r,e.pageType]);let h=n.get(c,e==null?void 0:e.id);h=n.get(h,"lang")===o?h:null;const E=o===j||!!h,L=(h==null?void 0:h.name)||(e==null?void 0:e.name)||"No name";let S=(h==null?void 0:h.slug)||(e==null?void 0:e.slug)||"";const C=S+(e!=null&&e.dynamic?`/${b==null?void 0:b.dynamicSlug}`:"")+(e!=null&&e.dynamicSlugCustom?`${e.dynamicSlugCustom}`:"");if(S.startsWith("/")&&!y){const u=S.split("/").pop();S=S.endsWith(u)&&e.dynamic?"":`/${u}`}const q=l.useMemo(()=>{const u="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]",T=`${g?"border-primary/30 bg-primary/5":"border-transparent hover:border-gray-200 hover:bg-gray-100"}`;return E?`${u} ${T} ${d?"opacity-60":""}`:`${u} bg-gray-100 opacity-50 group-hover:border-gray-200 border-transparent group-hover:bg-blue-100`},[E,g,d]);return s.jsxs("div",{className:"group relative",children:[s.jsxs("div",{onClick:()=>!e.isPartialGroup&&E&&t("select",e==null?void 0:e.id),className:q,children:[s.jsx(le,{page:e}),!e.isPartialGroup&&s.jsx(oe,{isOnline:h?h.online:e.online}),!e.isPartialGroup&&s.jsx(ie,{page:e,pageType:b}),s.jsx(x.Tooltip,{content:L,side:"top",showTooltip:L.length>35,children:s.jsx("span",{className:"max-w-[40%] truncate font-medium text-black",children:L})}),(S||e.dynamic)&&s.jsx(x.Tooltip,{content:C,side:"top",showTooltip:!0,children:s.jsxs("span",{className:"max-w-[40%] truncate font-mono text-xs text-muted-foreground",children:[S,e.dynamic&&(b==null?void 0:b.dynamicSlug)&&s.jsxs("span",{className:"text-xs text-gray-500",children:["/",b==null?void 0:b.dynamicSlug,e.dynamicSlugCustom]})]})}),U&&s.jsx(x.Tooltip,{content:"Template",side:"top",children:s.jsx("span",{className:"text-blue-500",children:s.jsx(v.NotepadText,{size:16})})}),!e.isPartialGroup&&E&&!d?s.jsx("div",{className:"duration absolute right-0.5 top-[3px]",children:s.jsx(x.PageActionsDropdown,{isLanguagePage:!!h,page:h||e,setDuplicatePage:u=>t("duplicate",u),setAddEditPage:u=>t("edit",h||u),setUnpublishPage:u=>t("unpublish",u),setDeletePage:u=>t("delete",h||u),setMarkAsTemplate:u=>t("markAsTemplate",u),setUnmarkAsTemplate:u=>t("unmarkAsTemplate",u),children:s.jsx("div",{className:"m-0 cursor-pointer rounded border border-transparent p-0.5 duration-100 hover:border-gray-400 hover:bg-white",children:s.jsx(v.MoreHorizontal,{className:"h-4 w-4",onClick:u=>u.stopPropagation()})})})}):d?s.jsx("span",{className:"duration absolute right-1.5 top-1/2 -translate-y-1/2 text-xs text-gray-500",children:s.jsx(v.Lock,{className:"h-3.5 w-3.5 fill-red-200 text-red-500"})}):null]}),s.jsx(s.Fragment,{children:d&&s.jsxs("button",{className:"absolute right-px top-1/2 flex h-6 -translate-y-1/2 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:[s.jsx(v.Edit,{size:12,className:"stroke-[3]"})," ",s.jsx("span",{className:"font-medium",children:d})," is editing this page"]})}),s.jsx(s.Fragment,{children:!E&&!e.isPartialGroup&&!d&&s.jsxs("button",{onClick:u=>{u.stopPropagation(),t("addLanguagePage",{language:o,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:[s.jsx(v.Plus,{size:12,className:"stroke-[3]"})," ",s.jsxs("span",{className:"text-[10px]",children:["Add ",n.get(x.LANGUAGES,o)," Page"]})]})})]})},X=({pages:e,tier:r,pageTypes:a,currentPage:t,onClickAction:c,languagePages:o,selectedLanguage:y,showUntranslatedPages:N})=>{const{expandedPages:p}=G.usePageExpandManager();return s.jsx("div",{className:"space-y-0.5",style:{paddingLeft:`${r*10}px`},children:e.map(f=>s.jsxs(s.Fragment,{children:[s.jsx(ce,{page:f,pageTypes:a,currentPage:t,onClickAction:c,languagePages:o,selectedLanguage:y,showUntranslatedPages:N}),f.children&&f.children.length>0&&(p==null?void 0:p.includes(f.id))&&s.jsx(X,{pages:f.children,tier:r+1,pageTypes:a,currentPage:t,onClickAction:c,languagePages:o,selectedLanguage:y,showUntranslatedPages:N})]},f.id))})},de=l.lazy(()=>Promise.resolve().then(()=>require("./page-manager-search-and-filter-pe0q0qnZ.cjs"))),ue=l.lazy(()=>Promise.resolve().then(()=>require("./add-new-page-DqhQUQBz.cjs"))),me=l.lazy(()=>Promise.resolve().then(()=>require("./delete-page-x0DWKzsR.cjs"))),he=l.lazy(()=>Promise.resolve().then(()=>require("./duplicate-page-Dt_QZkTk.cjs"))),xe=l.lazy(()=>Promise.resolve().then(()=>require("./mark-as-template-DONU52b1.cjs"))),fe=l.lazy(()=>Promise.resolve().then(()=>require("./unmark-as-template-Dn90g1eh.cjs"))),Pe=l.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-C3C_rTRd.cjs"))),ye=({close:e})=>{const{t:r}=$.useTranslation(),{languages:a,setSelectedLang:t}=$.useLanguages(),{data:c}=x.usePageTypes(),{data:o,isFetching:y}=x.useWebsitePages(),[N,p]=x.useSearchParams(),{updateForSelectedPage:f,expandPagesOnSearch:m}=G.usePageExpandManager(null),d=x.useFallbackLang(),j=N.get("page"),[g,U]=l.useState(""),[b,h]=l.useState(null),[E,L]=l.useState(null),[S,C]=l.useState(null),[q,u]=l.useState(null),[T,F]=l.useState(""),[O,R]=l.useState(null),[D,W]=l.useState(null),[k,Y]=l.useState(d),[Z,ee]=l.useState(!1),[,H]=te.useAtom(x.addNewLangAtom),M=Z&&k!==d,{data:A,isFetching:se}=x.useWebsiteLanguagePages(k),_=l.useCallback(P=>{var i;return(i=n.find(c,{key:P}))==null?void 0:i.hasSlug},[c]),w=l.useMemo(()=>o?M?n.filter(o,P=>!(A!=null&&A[P.id])):ae(o,g,T,_):[],[o,_,g,T,A,M]);l.useEffect(()=>{t(d)},[d,t]),l.useEffect(()=>{if(!n.isEmpty(T))return;const P=sessionStorage.getItem("pageTypeFilter")||"all";!n.isEmpty(c)&&P&&(n.find(c,{key:P})?F(P):F("all"))},[c,T]),l.useEffect(()=>{if(j&&!y&&!n.find(o,{id:j})){const i=n.find(o,{slug:"/"});if(i){const z=new URLSearchParams({page:i.id});x.navigateToPage(z,p)}else x.navigateToPage(new URLSearchParams({}),p,!0)}},[o,j,y,p]),l.useEffect(()=>{j&&!y&&!n.isEmpty(w)&&f(w,j)},[j,y,w,f]),l.useEffect(()=>{!n.isEmpty(g)&&!n.isEmpty(w)&&m(w)},[g,w,m]);const{setSelectedLang:I}=$.useLanguages(),Q=l.useCallback(P=>{const i=new URLSearchParams({page:P});k!==d?(i.set("lang",k),I(k)):I(""),x.navigateToPage(i,p),e()},[e,p,I,k,d]),V=(P,i)=>{var z;if(i)switch(P){case"add":L(i);break;case"select":Q(i);break;case"edit":k!==d?H({edit:!0,id:i==null?void 0:i.id,primaryPage:i==null?void 0:i.primaryPage}):L(i);break;case"delete":h(i);break;case"unpublish":C(i);break;case"markAsTemplate":u(i);break;case"unmarkAsTemplate":W(i);break;case"duplicate":R(i);break;case"addLanguagePage":H({edit:!1,primaryPage:((z=i==null?void 0:i.page)==null?void 0:z.id)||"",preselectedLang:(i==null?void 0:i.language)||k});break}};return s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"flex h-full flex-col justify-between",children:[s.jsx(l.Suspense,{children:s.jsx(de,{pages:w,search:g,setSearch:U,languages:[d,...a],selectedLanguage:k,setSelectedLanguage:Y,selectedPageType:T,setSelectedPageType:F,onAddPage:P=>V("add",P),showUntranslatedPages:M,setShowUntranslatedPages:ee})}),s.jsx("div",{className:"flex-1 overflow-y-auto px-4 pb-6 pt-2",children:y||se?s.jsx("div",{className:"space-y-2",children:n.map([...Array(15).keys()],P=>s.jsx("div",{className:"h-7 w-full animate-pulse rounded border border-gray-300 bg-gray-200"},P))}):n.isEmpty(w)?s.jsxs("div",{className:"flex h-[70vh] flex-col items-center justify-center gap-y-1 text-sm font-medium text-slate-500",children:[s.jsx(v.File,{className:"h-6 w-6 stroke-[1]"}),r("Empty List!"),s.jsx("span",{className:"font-light",children:r("Add new page to start")})]}):s.jsx(X,{tier:0,pages:w,pageTypes:c,currentPage:j||"",onClickAction:V,languagePages:A,selectedLanguage:k,showUntranslatedPages:M})})]}),E&&s.jsx(l.Suspense,{children:s.jsx(ue,{closePanel:e,editPage:Q,addEditPage:E,setAddEditPage:L})}),b&&s.jsx(l.Suspense,{children:s.jsx(me,{page:b,onClose:()=>h(null)})}),S&&s.jsx(l.Suspense,{children:s.jsx(Pe,{page:S,onClose:()=>C(null)})}),q&&s.jsx(l.Suspense,{children:s.jsx(xe,{page:q,onClose:()=>u(null)})}),D&&s.jsx(l.Suspense,{children:s.jsx(fe,{page:D,onClose:()=>W(null)})}),O&&s.jsx(l.Suspense,{children:s.jsx(he,{page:O,onClose:()=>R(null),closePanel:e})})]})};exports.default=ye;
@@ -0,0 +1,354 @@
1
+ import { jsxs as b, jsx as t, Fragment as D } from "react/jsx-runtime";
2
+ import { aA as be, aB as ye, ao as ge, k as ie, T as q, aK as ke, L as Ne, m as ve, g as we, c as Se, av as Ae, aL as Le, aM as K } from "./index-DI2Rwk5v.js";
3
+ import { u as J } from "./use-page-expand-manager-D6T75I11.js";
4
+ import { compact as ce, filter as z, isEmpty as w, uniqBy as Te, keyBy as de, mapValues as Ce, startCase as Ee, toLower as E, includes as R, get as O, find as $, map as Ue } from "lodash-es";
5
+ import { useTranslation as Ie, useLanguages as ae } from "@chaibuilder/sdk";
6
+ import { useAtom as Me } from "jotai";
7
+ import { NotepadText as $e, MoreHorizontal as ze, Lock as Be, Edit as Fe, Plus as je, ChevronRight as Ge, StarsIcon as Oe, Hash as De, File as ue } from "lucide-react";
8
+ import { useMemo as Q, lazy as U, useState as N, useCallback as le, useEffect as M, Suspense as C } from "react";
9
+ const oe = (e, n) => !e || !Array.isArray(e) ? [] : w(n) ? e : ce(
10
+ z(e, (r) => {
11
+ const s = E(n);
12
+ return R(E((r == null ? void 0 : r.name) || ""), s) || R(E((r == null ? void 0 : r.slug) || ""), s);
13
+ })
14
+ ), Re = (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
+ }, V = (e, n, r) => w(n) ? e : e.map((s) => {
22
+ if (!r(s.pageType))
23
+ return {
24
+ ...s,
25
+ shouldExpandOnSearch: !0,
26
+ children: s.children ? V(s.children, n, r) : []
27
+ };
28
+ const o = s.children && s.children.some(
29
+ (l) => R(E(l.name || ""), E(n)) || R(E(l.slug || ""), E(n))
30
+ );
31
+ return {
32
+ ...s,
33
+ shouldExpandOnSearch: o,
34
+ children: s.children ? V(s.children, n, r) : []
35
+ };
36
+ }), We = (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
+ })), He = (e, n, r, s) => {
52
+ if (!e || !e.length) return [];
53
+ let o = e;
54
+ if (r !== "all" && (o = ce(z(e, { pageType: r }))), w(n))
55
+ o = oe(o, n);
56
+ else {
57
+ const d = oe(o, n), i = Re(e, d);
58
+ o = Te([...d, ...i], "id");
59
+ }
60
+ const l = me(We(o)), f = V(l, n, s), S = z(f, (d) => s(d.pageType)).sort((d, i) => (d.name || "").localeCompare(i.name || "")), x = z(f, (d) => !s(d.pageType));
61
+ let m = [];
62
+ if (r === "all") {
63
+ const d = de(x, "pageType");
64
+ m = Object.values(
65
+ Ce(d, (i, P) => ({
66
+ ...i,
67
+ id: P,
68
+ name: Ee(P),
69
+ isPartialGroup: !0,
70
+ children: f.filter((y) => y.pageType === P)
71
+ }))
72
+ );
73
+ } else
74
+ m = x.sort((d, i) => (d.name || "").localeCompare(i.name || ""));
75
+ return [...S, ...m];
76
+ }, _e = ({ page: e }) => {
77
+ var s, o;
78
+ const { isExpanded: n, toggleExpanded: r } = J(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
+ Ge,
89
+ {
90
+ size: 12,
91
+ className: `stroke-[4] transition-transform duration-200 ${n ? "rotate-90" : ""}`
92
+ }
93
+ )
94
+ }
95
+ );
96
+ }, qe = ({ page: e, pageType: n }) => /* @__PURE__ */ t("div", { className: "flex h-full items-center justify-center gap-x-1", children: e.dynamic ? /* @__PURE__ */ t(Oe, { 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" }) }), Ke = ({ 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 S = be(), { pageToUser: x } = ye(), m = O(x, [e == null ? void 0 : e.id, "userId"]), { data: d } = ge(m), i = d && S !== m ? d == null ? void 0 : d.name : null, P = ie(), y = r === e.id, W = !!e.isTemplate, p = Q(() => $(n, { key: e.pageType }), [n, e.pageType]);
112
+ let u = O(o, e == null ? void 0 : e.id);
113
+ u = O(u, "lang") === l ? u : null;
114
+ const A = l === P || !!u, L = (u == null ? void 0 : u.name) || (e == null ? void 0 : e.name) || "No name";
115
+ let g = (u == null ? void 0 : u.slug) || (e == null ? void 0 : e.slug) || "";
116
+ const B = g + (e != null && e.dynamic ? `/${p == null ? void 0 : p.dynamicSlug}` : "") + (e != null && e.dynamicSlugCustom ? `${e.dynamicSlugCustom}` : "");
117
+ if (g.startsWith("/") && !f) {
118
+ const c = g.split("/").pop();
119
+ g = g.endsWith(c) && e.dynamic ? "" : `/${c}`;
120
+ }
121
+ const F = Q(() => {
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]", T = `${y ? "border-primary/30 bg-primary/5" : "border-transparent hover:border-gray-200 hover:bg-gray-100"}`;
123
+ return A ? `${c} ${T} ${i ? "opacity-60" : ""}` : `${c} bg-gray-100 opacity-50 group-hover:border-gray-200 border-transparent group-hover:bg-blue-100`;
124
+ }, [A, y, i]);
125
+ return /* @__PURE__ */ b("div", { className: "group relative", children: [
126
+ /* @__PURE__ */ b(
127
+ "div",
128
+ {
129
+ onClick: () => !e.isPartialGroup && A && s("select", e == null ? void 0 : e.id),
130
+ className: F,
131
+ children: [
132
+ /* @__PURE__ */ t(_e, { page: e }),
133
+ !e.isPartialGroup && /* @__PURE__ */ t(Ke, { isOnline: u ? u.online : e.online }),
134
+ !e.isPartialGroup && /* @__PURE__ */ t(qe, { page: e, pageType: p }),
135
+ /* @__PURE__ */ t(q, { content: L, side: "top", showTooltip: L.length > 35, children: /* @__PURE__ */ t("span", { className: "max-w-[40%] truncate font-medium text-black", children: L }) }),
136
+ (g || e.dynamic) && /* @__PURE__ */ t(q, { content: B, side: "top", showTooltip: !0, children: /* @__PURE__ */ b("span", { className: "max-w-[40%] truncate font-mono text-xs text-muted-foreground", children: [
137
+ g,
138
+ e.dynamic && (p == null ? void 0 : p.dynamicSlug) && /* @__PURE__ */ b("span", { className: "text-xs text-gray-500", children: [
139
+ "/",
140
+ p == null ? void 0 : p.dynamicSlug,
141
+ e.dynamicSlugCustom
142
+ ] })
143
+ ] }) }),
144
+ W && /* @__PURE__ */ t(q, { content: "Template", side: "top", children: /* @__PURE__ */ t("span", { className: "text-blue-500", children: /* @__PURE__ */ t($e, { size: 16 }) }) }),
145
+ !e.isPartialGroup && A && !i ? /* @__PURE__ */ t("div", { className: "duration absolute right-0.5 top-[3px]", children: /* @__PURE__ */ t(
146
+ ke,
147
+ {
148
+ isLanguagePage: !!u,
149
+ page: u || e,
150
+ setDuplicatePage: (c) => s("duplicate", c),
151
+ setAddEditPage: (c) => s("edit", u || c),
152
+ setUnpublishPage: (c) => s("unpublish", c),
153
+ setDeletePage: (c) => s("delete", u || 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
+ ) }) : i ? /* @__PURE__ */ t("span", { className: "duration absolute right-1.5 top-1/2 -translate-y-1/2 text-xs text-gray-500", children: /* @__PURE__ */ t(Be, { className: "h-3.5 w-3.5 fill-red-200 text-red-500" }) }) : null
159
+ ]
160
+ }
161
+ ),
162
+ /* @__PURE__ */ t(D, { children: i && /* @__PURE__ */ b("button", { className: "absolute right-px top-1/2 flex h-6 -translate-y-1/2 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(Fe, { size: 12, className: "stroke-[3]" }),
164
+ " ",
165
+ /* @__PURE__ */ t("span", { className: "font-medium", children: i }),
166
+ " is editing this page"
167
+ ] }) }),
168
+ /* @__PURE__ */ t(D, { children: !A && !e.isPartialGroup && !i && /* @__PURE__ */ b(
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(je, { size: 12, className: "stroke-[3]" }),
177
+ " ",
178
+ /* @__PURE__ */ b("span", { className: "text-[10px]", children: [
179
+ "Add ",
180
+ O(Ne, 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: S
196
+ }) => {
197
+ const { expandedPages: x } = J();
198
+ return /* @__PURE__ */ t("div", { className: "space-y-0.5", style: { paddingLeft: `${n * 10}px` }, children: e.map((m) => /* @__PURE__ */ b(D, { 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: S
209
+ }
210
+ ),
211
+ m.children && m.children.length > 0 && (x == null ? void 0 : x.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: S
222
+ }
223
+ )
224
+ ] }, m.id)) });
225
+ }, Ve = U(() => import("./page-manager-search-and-filter-C-_w7N27.js")), Je = U(() => import("./add-new-page-aYomeid4.js")), Xe = U(() => import("./delete-page-BF1k60U2.js")), Ye = U(() => import("./duplicate-page-u_6vUVo1.js")), Ze = U(() => import("./mark-as-template-CJ1mlxYT.js")), et = U(() => import("./unmark-as-template-JRRUYTOY.js")), tt = U(() => import("./unpublish-page-FZ8rbi7u.js")), dt = ({ close: e }) => {
226
+ const { t: n } = Ie(), { languages: r, setSelectedLang: s } = ae(), { data: o } = ve(), { data: l, isFetching: f } = we(), [S, x] = Se(), { updateForSelectedPage: m, expandPagesOnSearch: d } = J(null), i = ie(), P = S.get("page"), [y, W] = N(""), [p, u] = N(null), [A, L] = N(null), [g, B] = N(null), [F, c] = N(null), [T, H] = N(""), [X, Y] = N(null), [Z, ee] = N(null), [k, fe] = N(i), [xe, Pe] = N(!1), [, te] = Me(Ae), j = xe && k !== i, { data: I, isFetching: pe } = Le(k), se = le(
227
+ (h) => {
228
+ var a;
229
+ return (a = $(o, { key: h })) == null ? void 0 : a.hasSlug;
230
+ },
231
+ [o]
232
+ ), v = Q(() => l ? j ? z(l, (h) => !(I != null && I[h.id])) : He(l, y, T, se) : [], [l, se, y, T, I, j]);
233
+ M(() => {
234
+ s(i);
235
+ }, [i, s]), M(() => {
236
+ if (!w(T)) return;
237
+ const h = sessionStorage.getItem("pageTypeFilter") || "all";
238
+ !w(o) && h && ($(o, { key: h }) ? H(h) : H("all"));
239
+ }, [o, T]), M(() => {
240
+ if (P && !f && !$(l, { id: P })) {
241
+ const a = $(l, { slug: "/" });
242
+ if (a) {
243
+ const G = new URLSearchParams({ page: a.id });
244
+ K(G, x);
245
+ } else
246
+ K(new URLSearchParams({}), x, !0);
247
+ }
248
+ }, [l, P, f, x]), M(() => {
249
+ P && !f && !w(v) && m(v, P);
250
+ }, [P, f, v, m]), M(() => {
251
+ !w(y) && !w(v) && d(v);
252
+ }, [y, v, d]);
253
+ const { setSelectedLang: _ } = ae(), ne = le(
254
+ (h) => {
255
+ const a = new URLSearchParams({ page: h });
256
+ k !== i ? (a.set("lang", k), _(k)) : _(""), K(a, x), e();
257
+ },
258
+ [e, x, _, k, i]
259
+ ), re = (h, a) => {
260
+ var G;
261
+ if (a)
262
+ switch (h) {
263
+ case "add":
264
+ L(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
+ }) : L(a);
275
+ break;
276
+ case "delete":
277
+ u(a);
278
+ break;
279
+ case "unpublish":
280
+ B(a);
281
+ break;
282
+ case "markAsTemplate":
283
+ c(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: ((G = a == null ? void 0 : a.page) == null ? void 0 : G.id) || "",
295
+ preselectedLang: (a == null ? void 0 : a.language) || k
296
+ });
297
+ break;
298
+ }
299
+ };
300
+ return /* @__PURE__ */ b(D, { children: [
301
+ /* @__PURE__ */ b("div", { className: "flex h-full flex-col justify-between", children: [
302
+ /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(
303
+ Ve,
304
+ {
305
+ pages: v,
306
+ search: y,
307
+ setSearch: W,
308
+ languages: [i, ...r],
309
+ selectedLanguage: k,
310
+ setSelectedLanguage: fe,
311
+ selectedPageType: T,
312
+ setSelectedPageType: H,
313
+ onAddPage: (h) => re("add", h),
314
+ showUntranslatedPages: j,
315
+ setShowUntranslatedPages: Pe
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: Ue([...Array(15).keys()], (h) => /* @__PURE__ */ t("div", { className: "h-7 w-full animate-pulse rounded border border-gray-300 bg-gray-200" }, h)) }) : w(v) ? /* @__PURE__ */ b("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: P || "",
329
+ onClickAction: re,
330
+ languagePages: I,
331
+ selectedLanguage: k,
332
+ showUntranslatedPages: j
333
+ }
334
+ ) })
335
+ ] }),
336
+ A && /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(
337
+ Je,
338
+ {
339
+ closePanel: e,
340
+ editPage: ne,
341
+ addEditPage: A,
342
+ setAddEditPage: L
343
+ }
344
+ ) }),
345
+ p && /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(Xe, { page: p, onClose: () => u(null) }) }),
346
+ g && /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(tt, { page: g, onClose: () => B(null) }) }),
347
+ F && /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(Ze, { page: F, onClose: () => c(null) }) }),
348
+ Z && /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(et, { page: Z, onClose: () => ee(null) }) }),
349
+ X && /* @__PURE__ */ t(C, { children: /* @__PURE__ */ t(Ye, { page: X, onClose: () => Y(null), closePanel: e }) })
350
+ ] });
351
+ };
352
+ export {
353
+ dt as default
354
+ };
@@ -1,5 +1,5 @@
1
1
  import { jsx as e, jsxs as n, Fragment as k } from "react/jsx-runtime";
2
- import { f as F, L as I, h as z, A as j } from "./index-e9WlBH0R.js";
2
+ import { k as F, L as I, m as z, A as j } from "./index-DI2Rwk5v.js";
3
3
  import { u as T } from "./use-page-expand-manager-D6T75I11.js";
4
4
  import { useTranslation as f } from "@chaibuilder/sdk";
5
5
  import { Button as m, Tooltip as g, TooltipTrigger as b, TooltipContent as y, Select as $, SelectTrigger as G, SelectContent as D, Input as E, SelectItem as N } from "@chaibuilder/sdk/ui";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("./index-Pdb5tSRL.cjs"),N=require("./use-page-expand-manager-2KjeYfVS.cjs"),m=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),w=require("@tanstack/react-query"),r=require("lodash-es"),d=require("lucide-react"),C=require("react"),S=({selectedPageType:l,setSelectedPageType:i})=>{const{t:a}=m.useTranslation(),[n,o]=C.useState(""),{data:c}=j.usePageTypes(),h=t=>{if(!n)return!0;const x=n.toLowerCase(),p=g=>String(r.get(t,g,"")).toLowerCase().includes(x);return p("name")||p("key")},u=c.find(t=>t.key===l);return e.jsxs(s.Select,{onValueChange:i,value:l,children:[e.jsx(s.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:(u==null?void 0:u.name)||a("All")}),e.jsx(d.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(s.SelectContent,{children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white pb-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(d.Search,{strokeWidth:2,className:"absolute left-2 top-2.5 h-3.5 w-3.5 text-gray-400"}),e.jsx(s.Input,{placeholder:a("Search page types..."),className:"h-8 w-full rounded border pl-8 text-xs shadow-none",value:n,onChange:t=>o(t.target.value),onKeyDown:t=>t.stopPropagation()})]})}),e.jsx(s.SelectItem,{value:"all",children:a("All")}),!r.isEmpty(r.filter(c,t=>t.hasSlug&&h(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:a("Pages")}),r.map([...r.filter(c,t=>t.hasSlug&&h(t))].sort((t,x)=>r.get(t,"name","").localeCompare(r.get(x,"name",""))),t=>e.jsx(s.SelectItem,{value:r.get(t,"key"),children:r.get(t,"name")},r.get(t,"key")))]}),!r.isEmpty(r.filter(c,t=>!t.hasSlug&&h(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:a("Partials")}),r.map([...r.filter(c,t=>!t.hasSlug&&h(t))].sort((t,x)=>r.get(t,"name","").localeCompare(r.get(x,"name",""))),t=>e.jsx(s.SelectItem,{value:r.get(t,"key"),children:r.get(t,"name")},r.get(t,"key")))]}),r.isEmpty(r.filter(c,h))&&e.jsx("div",{className:"px-3 py-2 text-center text-sm text-gray-500",children:a("No matching page types found")})]})]})},k=({search:l,setSearch:i})=>{const{t:a}=m.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:a("Search Pages")}),e.jsx(d.Search,{className:`${l?"fill-sky-50 text-sky-500":""} pointer-events-none h-4 w-4 text-muted-foreground`,"aria-hidden":"true"}),e.jsx(s.Input,{id:"page-search-input",placeholder:a("Search pages"),value:l,onChange:n=>i(n.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"})]})},T=({pages:l})=>{const{t:i}=m.useTranslation(),{expandAll:a,collapseAll:n,expandedPages:o}=N.usePageExpandManager(null);return e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"outline",size:"icon",onClick:()=>a(l),className:"rounded p-1 text-gray-500",children:e.jsx(d.ChevronsUpDown,{})})}),e.jsx(s.TooltipContent,{children:i("Expand All")})]}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{disabled:o.length===0,variant:"outline",size:"icon",onClick:()=>n(),className:"rounded p-1 text-gray-500",children:e.jsx(d.ChevronsDownUp,{})})}),e.jsx(s.TooltipContent,{children:i("Collapse All")})]})]})},y=({languages:l,selectedLanguage:i,setSelectedLanguage:a})=>{const n=j.useFallbackLang();return e.jsx("div",{className:"scrollbar-hide flex gap-1 overflow-x-auto pb-1",children:l.map(o=>e.jsxs(s.Button,{variant:i===o?"default":"outline",size:"sm",className:`h-6 flex-shrink-0 whitespace-nowrap rounded px-3 text-xs font-normal ${i===o?"bg-black text-white hover:bg-black":"text-gray-500"}`,onClick:()=>a(o.toLowerCase()),children:[o===n&&e.jsx(d.Star,{size:4,className:`p-0.5 ${i===n?"fill-white":"fill-black"}`}),j.LANGUAGES[o]||""]},o))})},v=()=>{const{t:l}=m.useTranslation(),i=w.useQueryClient();return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",onClick:()=>i.invalidateQueries({queryKey:[j.ACTIONS.GET_WEBSITE_PAGES]}),className:"mt-1 h-6 w-6",children:e.jsx(d.RefreshCw,{})})}),e.jsx(s.TooltipContent,{side:"bottom",children:l("Refresh pages list")})]})},E=({pages:l,search:i,setSearch:a,languages:n,onAddPage:o,selectedLanguage:c,setSelectedLanguage:h,selectedPageType:u,setSelectedPageType:t,showUntranslatedPages:x,setShowUntranslatedPages:p})=>{const{t:g}=m.useTranslation(),f=n.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(S,{selectedPageType:u,setSelectedPageType:t}),e.jsx(k,{search:i,setSearch:a}),e.jsx(T,{pages:l}),e.jsxs(s.Button,{variant:"default",onClick:o,className:"rounded px-3 font-normal",children:[e.jsx(d.Plus,{strokeWidth:2,className:"stroke-white stroke-[3]"}),e.jsx("span",{className:"font-normal text-white",children:g("Add Page")})]}),!f&&e.jsx(v,{})]}),f?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(y,{languages:n,selectedLanguage:c,setSelectedLanguage:b=>{h(b),p(x&&(n==null?void 0:n[0])!==c)}}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[(n==null?void 0:n[0])!==c&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",onClick:()=>p(!x),className:"h-6 rounded px-3 py-1 text-xs font-normal",children:x?e.jsx(d.FilterXIcon,{}):e.jsx(d.Filter,{})})}),e.jsx(s.TooltipContent,{side:"bottom",children:g("Toggle Untranslated Pages")})]}),e.jsx(v,{})]})]}):e.jsx("div",{className:"flex items-center justify-between gap-2"})]})};exports.LanguageSelector=y;exports.default=E;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("./index-BeWL6Sj6.cjs"),N=require("./use-page-expand-manager-2KjeYfVS.cjs"),m=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),w=require("@tanstack/react-query"),r=require("lodash-es"),d=require("lucide-react"),C=require("react"),S=({selectedPageType:l,setSelectedPageType:i})=>{const{t:a}=m.useTranslation(),[n,o]=C.useState(""),{data:c}=j.usePageTypes(),h=t=>{if(!n)return!0;const x=n.toLowerCase(),p=g=>String(r.get(t,g,"")).toLowerCase().includes(x);return p("name")||p("key")},u=c.find(t=>t.key===l);return e.jsxs(s.Select,{onValueChange:i,value:l,children:[e.jsx(s.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:(u==null?void 0:u.name)||a("All")}),e.jsx(d.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(s.SelectContent,{children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white pb-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(d.Search,{strokeWidth:2,className:"absolute left-2 top-2.5 h-3.5 w-3.5 text-gray-400"}),e.jsx(s.Input,{placeholder:a("Search page types..."),className:"h-8 w-full rounded border pl-8 text-xs shadow-none",value:n,onChange:t=>o(t.target.value),onKeyDown:t=>t.stopPropagation()})]})}),e.jsx(s.SelectItem,{value:"all",children:a("All")}),!r.isEmpty(r.filter(c,t=>t.hasSlug&&h(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:a("Pages")}),r.map([...r.filter(c,t=>t.hasSlug&&h(t))].sort((t,x)=>r.get(t,"name","").localeCompare(r.get(x,"name",""))),t=>e.jsx(s.SelectItem,{value:r.get(t,"key"),children:r.get(t,"name")},r.get(t,"key")))]}),!r.isEmpty(r.filter(c,t=>!t.hasSlug&&h(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:a("Partials")}),r.map([...r.filter(c,t=>!t.hasSlug&&h(t))].sort((t,x)=>r.get(t,"name","").localeCompare(r.get(x,"name",""))),t=>e.jsx(s.SelectItem,{value:r.get(t,"key"),children:r.get(t,"name")},r.get(t,"key")))]}),r.isEmpty(r.filter(c,h))&&e.jsx("div",{className:"px-3 py-2 text-center text-sm text-gray-500",children:a("No matching page types found")})]})]})},k=({search:l,setSearch:i})=>{const{t:a}=m.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:a("Search Pages")}),e.jsx(d.Search,{className:`${l?"fill-sky-50 text-sky-500":""} pointer-events-none h-4 w-4 text-muted-foreground`,"aria-hidden":"true"}),e.jsx(s.Input,{id:"page-search-input",placeholder:a("Search pages"),value:l,onChange:n=>i(n.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"})]})},T=({pages:l})=>{const{t:i}=m.useTranslation(),{expandAll:a,collapseAll:n,expandedPages:o}=N.usePageExpandManager(null);return e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"outline",size:"icon",onClick:()=>a(l),className:"rounded p-1 text-gray-500",children:e.jsx(d.ChevronsUpDown,{})})}),e.jsx(s.TooltipContent,{children:i("Expand All")})]}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{disabled:o.length===0,variant:"outline",size:"icon",onClick:()=>n(),className:"rounded p-1 text-gray-500",children:e.jsx(d.ChevronsDownUp,{})})}),e.jsx(s.TooltipContent,{children:i("Collapse All")})]})]})},y=({languages:l,selectedLanguage:i,setSelectedLanguage:a})=>{const n=j.useFallbackLang();return e.jsx("div",{className:"scrollbar-hide flex gap-1 overflow-x-auto pb-1",children:l.map(o=>e.jsxs(s.Button,{variant:i===o?"default":"outline",size:"sm",className:`h-6 flex-shrink-0 whitespace-nowrap rounded px-3 text-xs font-normal ${i===o?"bg-black text-white hover:bg-black":"text-gray-500"}`,onClick:()=>a(o.toLowerCase()),children:[o===n&&e.jsx(d.Star,{size:4,className:`p-0.5 ${i===n?"fill-white":"fill-black"}`}),j.LANGUAGES[o]||""]},o))})},v=()=>{const{t:l}=m.useTranslation(),i=w.useQueryClient();return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",onClick:()=>i.invalidateQueries({queryKey:[j.ACTIONS.GET_WEBSITE_PAGES]}),className:"mt-1 h-6 w-6",children:e.jsx(d.RefreshCw,{})})}),e.jsx(s.TooltipContent,{side:"bottom",children:l("Refresh pages list")})]})},E=({pages:l,search:i,setSearch:a,languages:n,onAddPage:o,selectedLanguage:c,setSelectedLanguage:h,selectedPageType:u,setSelectedPageType:t,showUntranslatedPages:x,setShowUntranslatedPages:p})=>{const{t:g}=m.useTranslation(),f=n.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(S,{selectedPageType:u,setSelectedPageType:t}),e.jsx(k,{search:i,setSearch:a}),e.jsx(T,{pages:l}),e.jsxs(s.Button,{variant:"default",onClick:o,className:"rounded px-3 font-normal",children:[e.jsx(d.Plus,{strokeWidth:2,className:"stroke-white stroke-[3]"}),e.jsx("span",{className:"font-normal text-white",children:g("Add Page")})]}),!f&&e.jsx(v,{})]}),f?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(y,{languages:n,selectedLanguage:c,setSelectedLanguage:b=>{h(b),p(x&&(n==null?void 0:n[0])!==c)}}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[(n==null?void 0:n[0])!==c&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",onClick:()=>p(!x),className:"h-6 rounded px-3 py-1 text-xs font-normal",children:x?e.jsx(d.FilterXIcon,{}):e.jsx(d.Filter,{})})}),e.jsx(s.TooltipContent,{side:"bottom",children:g("Toggle Untranslated Pages")})]}),e.jsx(v,{})]})]}):e.jsx("div",{className:"flex items-center justify-between gap-2"})]})};exports.LanguageSelector=y;exports.default=E;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("./index-Pdb5tSRL.cjs"),N=require("@tanstack/react-query"),O=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),y=require("date-fns"),L=require("lodash-es"),p=require("lucide-react"),b=require("react");function Q(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const l=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(n,t,l.get?l:{enumerable:!0,get:()=>s[t]})}}return n.default=s,Object.freeze(n)}const v=Q(b);function z(s){const n=d.useApiUrl(),t=d.useFetch();return N.useQuery({queryKey:[d.ACTIONS.GET_PAGE_REVISIONS,s],queryFn:async()=>await t(n,{action:d.ACTIONS.GET_PAGE_REVISIONS,data:{pageId:s}}),enabled:!!s,refetchOnMount:!0})}const B=()=>{const s=d.useApiUrl(),n=d.useFetch(),t=N.useQueryClient();return N.useMutation({mutationFn:async l=>await n(s,{action:d.ACTIONS.DELETE_PAGE_REVISION,data:{revisionId:l}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},H=()=>{const s=d.useApiUrl(),n=d.useFetch(),t=N.useQueryClient();return N.useMutation({mutationFn:async({revisionId:l,discardCurrent:r})=>await n(s,{action:d.ACTIONS.RESTORE_PAGE_REVISION,data:{revisionId:l,discardCurrent:r}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},$=b.lazy(()=>Promise.resolve().then(()=>require("./json-diff-viewer-H-2DkGza.cjs"))),g=({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(p.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(p.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}=d.useCurrentPage(),{saveState:l}=O.useSavePage(),[r]=d.usePageEditInfo();if(!t)return null;const c=!!s.find(u=>{var i;return(i=u==null?void 0:u.uid)==null?void 0:i.startsWith("draft:")}),x=s.length>=2&&!c,m=l==="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(g,{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:!L.isEmpty(r.lastSaved)&&e.jsxs("span",{children:["Last updated"," ",y.formatDistanceToNow(new Date(r.lastSaved),{addSuffix:!0})]})}),e.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:m?e.jsx(g,{tag:"unsaved"}):null})]}),e.jsx(A,{checked:c,disabled:x,onChange:()=>{n(c?s.filter(u=>u.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(a.Skeleton,{className:"h-4 w-3/4"}),e.jsx(a.Skeleton,{className:"h-3 w-1/2"}),e.jsx(a.Skeleton,{className:"mt-1 h-5 w-20"})]}),e.jsx(a.Skeleton,{className:"h-8 w-8 rounded-full"})]},n))})}function I({revision:s,isLatest:n,onRestore:t,onDelete:l,revisionNumber:r,compare:c,setCompare:x,pageId:m}){const{data:u}=d.useChaiUserInfo(s.currentEditor),i=(u==null?void 0:u.name)||"Unknown",f=!!c.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}),S=c.length>=2&&!f;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(g,{tag:n?"live":`#${r}`}),s.type==="published"?"Published":"Draft"," by ",e.jsx("span",{className:"text-xs font-bold",children:i})]})}),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(g,{tag:"published"}):e.jsx(g,{tag:"draft"})}),e.jsx("div",{className:"flex items-center text-[10px] text-muted-foreground",children:e.jsx("span",{className:"leading-tight",children:y.format(s.createdAt,"MMM d, h:mm a")})})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(d.PermissionChecker,{permissions:[d.PAGES_PERMISSIONS.RESTORE_REVISION,d.PAGES_PERMISSIONS.DELETE_REVISION],children:e.jsx(Y,{revision:s,onRestore:t,onDelete:l})})}),e.jsx(A,{checked:f,disabled:S,onChange:()=>{x(f?c.filter(h=>n?h.uid!==`live:${m}`:h.uid!==s.uid):[...c,{uid:n?`live:${m}`:s.uid,label:n?"live":`#${r}`,item:s}].sort((h,j)=>new Date(h.item.createdAt).getTime()-new Date(j.item.createdAt).getTime()))}})]})}function W({compare:s,setCompare:n,pageId:t}){const[l,r]=b.useState(!1),[c,x]=s;if(s.length===0)return null;const m=({tab:u})=>e.jsxs("span",{className:"flex items-center justify-between rounded border border-blue-100 p-1 font-medium",children:[e.jsx(g,{tag:u.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.filter(i=>i.uid!==u.uid)),"aria-label":"Remove selection 1",children:e.jsx(p.X,{className:"h-3 w-3"})})]});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"}),c&&e.jsx(m,{tab:c}),e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"with"}),x?e.jsx(m,{tab:x}):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(a.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(a.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none",variant:"default",onClick:()=>r(!0),disabled:s.length<2,children:[e.jsx(p.FileJson,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"pt-0.5",children:"Show JSON Diff"})]})]}),l&&(s==null?void 0:s.length)>1&&t&&e.jsx(b.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:l,onOpenChange:r,compare:s})})]})}function A({checked:s,disabled:n,onChange:t,label:l="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:l})]})})}function Y({revision:s,onRestore:n,onDelete:t}){return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",size:"icon",className:"h-5 w-5",children:[e.jsx(p.MoreHorizontal,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More options"})]})}),e.jsxs(a.DropdownMenuContent,{align:"end",className:"text-xs",children:[e.jsx(d.PermissionChecker,{permission:d.PAGES_PERMISSIONS.RESTORE_REVISION,children:e.jsxs(a.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-sm",children:[e.jsx(p.Undo2,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Restore this version"})]})}),e.jsx(d.PermissionChecker,{permission:d.PAGES_PERMISSIONS.DELETE_REVISION,children:s.uid!=="current"&&e.jsxs(e.Fragment,{children:[e.jsx(a.DropdownMenuSeparator,{}),e.jsxs(a.DropdownMenuItem,{onClick:t,className:"cursor-pointer text-destructive",children:[e.jsx(p.Trash,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Delete this version"})]})]})})]})]})}function X({open:s,onOpenChange:n,revision:t,onRestore:l,isRestoring:r}){const{data:c}=d.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),x=(c==null?void 0:c.name)||"Unknown";return t?e.jsx(a.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(a.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Restore Revision"}),e.jsxs(a.DialogDescription,{children:["You are about to restore to revision ",t.uid.substring(0,8)," from"," ",y.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",x]})]}),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(a.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(a.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>l(!1),disabled:r,children:r?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(p.CloudOff,{className:"mr-2 h-4 w-4"}),"Save as draft"]})}),e.jsx(a.Button,{variant:"default",className:"sm:flex-1",onClick:()=>l(!0),disabled:r,children:r?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(p.Undo2,{className:"mr-2 h-4 w-4"}),"Discard current"]})})]})]})}):null}function Z({open:s,onOpenChange:n,revision:t,onDelete:l,isDeleting:r}){const{data:c}=d.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),x=(c==null?void 0:c.name)||"Unknown";return t?e.jsx(a.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(a.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Delete Revision"}),e.jsxs(a.DialogDescription,{children:["You are about to delete revision ",t.uid.substring(0,8)," from"," ",y.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",x]})]}),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(a.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(a.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>n(!1),disabled:r,children:"Cancel"}),e.jsx(a.Button,{variant:"destructive",className:"sm:flex-1",onClick:l,disabled:r,children:r?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(p.Trash,{className:"mr-2 h-4 w-4"}),"Delete Revision"]})})]})]})}):null}function ee({isOpen:s}){var E,R;const[n,t]=v.useState([]),[l,r]=v.useState(null),[c,x]=v.useState(!1),[m,u]=v.useState(!1),{data:i}=d.useCurrentPage(),{data:f,isFetching:S,error:h,refetch:j}=z(i==null?void 0:i.id),{mutate:k,isPending:M}=B(),{mutate:T,isPending:F}=H(),_=N.useQueryClient(),{selectedLang:P,fallbackLang:q}=O.useLanguages(),U=P||q;b.useEffect(()=>t([]),[i==null?void 0:i.id]);const G=o=>{l&&T({revisionId:l.uid,discardCurrent:o},{onSuccess:()=>{x(!1),r(null),_.invalidateQueries({queryKey:[d.ACTIONS.GET_DRAFT_PAGE]})}})},D=o=>{r(o),x(!0)},C=o=>{r(o),u(!0)},V=()=>{l&&k(l.uid,{onSuccess:()=>{u(!1),r(null)}})};return b.useEffect(()=>{s&&j()},[s,j]),e.jsxs(e.Fragment,{children:[e.jsxs(a.SheetHeader,{children:[e.jsx(a.SheetTitle,{children:"Revision History"}),(i==null?void 0:i.createdAt)&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Page created on ",y.format(new Date(i.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),S?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:i==null?void 0:i.id}),e.jsx(J,{compare:n,setCompare:t}),(E=f==null?void 0:f.filter(o=>o.uid==="current"))==null?void 0:E.map((o,w)=>e.jsx(I,{pageId:i==null?void 0:i.id,revision:o,isLatest:!0,onRestore:()=>D(o),onDelete:()=>C(o),revisionNumber:w,compare:n,setCompare:t},o.uid)),e.jsx(a.ScrollArea,{className:"min-h-0 flex-1",children:e.jsx("div",{className:"space-y-2",children:(R=f==null?void 0:f.filter(o=>o.uid!=="current"))==null?void 0:R.map((o,w)=>e.jsx(I,{pageId:i==null?void 0:i.id,revision:o,isLatest:o.uid==="current",onRestore:()=>D(o),onDelete:()=>C(o),revisionNumber:w+1,compare:n,setCompare:t},o.uid))})})]}),e.jsx(X,{open:c,onOpenChange:x,revision:l,onRestore:G,isRestoring:F}),e.jsx(Z,{open:m,onOpenChange:u,revision:l,onDelete:V,isDeleting:M})]})}exports.default=ee;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("./index-BeWL6Sj6.cjs"),N=require("@tanstack/react-query"),O=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),y=require("date-fns"),L=require("lodash-es"),p=require("lucide-react"),b=require("react");function Q(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const l=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(n,t,l.get?l:{enumerable:!0,get:()=>s[t]})}}return n.default=s,Object.freeze(n)}const v=Q(b);function z(s){const n=d.useApiUrl(),t=d.useFetch();return N.useQuery({queryKey:[d.ACTIONS.GET_PAGE_REVISIONS,s],queryFn:async()=>await t(n,{action:d.ACTIONS.GET_PAGE_REVISIONS,data:{pageId:s}}),enabled:!!s,refetchOnMount:!0})}const B=()=>{const s=d.useApiUrl(),n=d.useFetch(),t=N.useQueryClient();return N.useMutation({mutationFn:async l=>await n(s,{action:d.ACTIONS.DELETE_PAGE_REVISION,data:{revisionId:l}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},H=()=>{const s=d.useApiUrl(),n=d.useFetch(),t=N.useQueryClient();return N.useMutation({mutationFn:async({revisionId:l,discardCurrent:r})=>await n(s,{action:d.ACTIONS.RESTORE_PAGE_REVISION,data:{revisionId:l,discardCurrent:r}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},$=b.lazy(()=>Promise.resolve().then(()=>require("./json-diff-viewer-D2g0Yab2.cjs"))),g=({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(p.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(p.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}=d.useCurrentPage(),{saveState:l}=O.useSavePage(),[r]=d.usePageEditInfo();if(!t)return null;const c=!!s.find(u=>{var i;return(i=u==null?void 0:u.uid)==null?void 0:i.startsWith("draft:")}),x=s.length>=2&&!c,m=l==="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(g,{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:!L.isEmpty(r.lastSaved)&&e.jsxs("span",{children:["Last updated"," ",y.formatDistanceToNow(new Date(r.lastSaved),{addSuffix:!0})]})}),e.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:m?e.jsx(g,{tag:"unsaved"}):null})]}),e.jsx(A,{checked:c,disabled:x,onChange:()=>{n(c?s.filter(u=>u.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(a.Skeleton,{className:"h-4 w-3/4"}),e.jsx(a.Skeleton,{className:"h-3 w-1/2"}),e.jsx(a.Skeleton,{className:"mt-1 h-5 w-20"})]}),e.jsx(a.Skeleton,{className:"h-8 w-8 rounded-full"})]},n))})}function I({revision:s,isLatest:n,onRestore:t,onDelete:l,revisionNumber:r,compare:c,setCompare:x,pageId:m}){const{data:u}=d.useChaiUserInfo(s.currentEditor),i=(u==null?void 0:u.name)||"Unknown",f=!!c.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}),S=c.length>=2&&!f;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(g,{tag:n?"live":`#${r}`}),s.type==="published"?"Published":"Draft"," by ",e.jsx("span",{className:"text-xs font-bold",children:i})]})}),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(g,{tag:"published"}):e.jsx(g,{tag:"draft"})}),e.jsx("div",{className:"flex items-center text-[10px] text-muted-foreground",children:e.jsx("span",{className:"leading-tight",children:y.format(s.createdAt,"MMM d, h:mm a")})})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(d.PermissionChecker,{permissions:[d.PAGES_PERMISSIONS.RESTORE_REVISION,d.PAGES_PERMISSIONS.DELETE_REVISION],children:e.jsx(Y,{revision:s,onRestore:t,onDelete:l})})}),e.jsx(A,{checked:f,disabled:S,onChange:()=>{x(f?c.filter(h=>n?h.uid!==`live:${m}`:h.uid!==s.uid):[...c,{uid:n?`live:${m}`:s.uid,label:n?"live":`#${r}`,item:s}].sort((h,j)=>new Date(h.item.createdAt).getTime()-new Date(j.item.createdAt).getTime()))}})]})}function W({compare:s,setCompare:n,pageId:t}){const[l,r]=b.useState(!1),[c,x]=s;if(s.length===0)return null;const m=({tab:u})=>e.jsxs("span",{className:"flex items-center justify-between rounded border border-blue-100 p-1 font-medium",children:[e.jsx(g,{tag:u.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.filter(i=>i.uid!==u.uid)),"aria-label":"Remove selection 1",children:e.jsx(p.X,{className:"h-3 w-3"})})]});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"}),c&&e.jsx(m,{tab:c}),e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"with"}),x?e.jsx(m,{tab:x}):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(a.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(a.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none",variant:"default",onClick:()=>r(!0),disabled:s.length<2,children:[e.jsx(p.FileJson,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"pt-0.5",children:"Show JSON Diff"})]})]}),l&&(s==null?void 0:s.length)>1&&t&&e.jsx(b.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:l,onOpenChange:r,compare:s})})]})}function A({checked:s,disabled:n,onChange:t,label:l="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:l})]})})}function Y({revision:s,onRestore:n,onDelete:t}){return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",size:"icon",className:"h-5 w-5",children:[e.jsx(p.MoreHorizontal,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More options"})]})}),e.jsxs(a.DropdownMenuContent,{align:"end",className:"text-xs",children:[e.jsx(d.PermissionChecker,{permission:d.PAGES_PERMISSIONS.RESTORE_REVISION,children:e.jsxs(a.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-sm",children:[e.jsx(p.Undo2,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Restore this version"})]})}),e.jsx(d.PermissionChecker,{permission:d.PAGES_PERMISSIONS.DELETE_REVISION,children:s.uid!=="current"&&e.jsxs(e.Fragment,{children:[e.jsx(a.DropdownMenuSeparator,{}),e.jsxs(a.DropdownMenuItem,{onClick:t,className:"cursor-pointer text-destructive",children:[e.jsx(p.Trash,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Delete this version"})]})]})})]})]})}function X({open:s,onOpenChange:n,revision:t,onRestore:l,isRestoring:r}){const{data:c}=d.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),x=(c==null?void 0:c.name)||"Unknown";return t?e.jsx(a.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(a.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Restore Revision"}),e.jsxs(a.DialogDescription,{children:["You are about to restore to revision ",t.uid.substring(0,8)," from"," ",y.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",x]})]}),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(a.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(a.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>l(!1),disabled:r,children:r?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(p.CloudOff,{className:"mr-2 h-4 w-4"}),"Save as draft"]})}),e.jsx(a.Button,{variant:"default",className:"sm:flex-1",onClick:()=>l(!0),disabled:r,children:r?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(p.Undo2,{className:"mr-2 h-4 w-4"}),"Discard current"]})})]})]})}):null}function Z({open:s,onOpenChange:n,revision:t,onDelete:l,isDeleting:r}){const{data:c}=d.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),x=(c==null?void 0:c.name)||"Unknown";return t?e.jsx(a.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(a.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Delete Revision"}),e.jsxs(a.DialogDescription,{children:["You are about to delete revision ",t.uid.substring(0,8)," from"," ",y.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",x]})]}),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(a.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(a.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>n(!1),disabled:r,children:"Cancel"}),e.jsx(a.Button,{variant:"destructive",className:"sm:flex-1",onClick:l,disabled:r,children:r?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(p.Trash,{className:"mr-2 h-4 w-4"}),"Delete Revision"]})})]})]})}):null}function ee({isOpen:s}){var E,R;const[n,t]=v.useState([]),[l,r]=v.useState(null),[c,x]=v.useState(!1),[m,u]=v.useState(!1),{data:i}=d.useCurrentPage(),{data:f,isFetching:S,error:h,refetch:j}=z(i==null?void 0:i.id),{mutate:k,isPending:M}=B(),{mutate:T,isPending:F}=H(),_=N.useQueryClient(),{selectedLang:P,fallbackLang:q}=O.useLanguages(),U=P||q;b.useEffect(()=>t([]),[i==null?void 0:i.id]);const G=o=>{l&&T({revisionId:l.uid,discardCurrent:o},{onSuccess:()=>{x(!1),r(null),_.invalidateQueries({queryKey:[d.ACTIONS.GET_DRAFT_PAGE]})}})},D=o=>{r(o),x(!0)},C=o=>{r(o),u(!0)},V=()=>{l&&k(l.uid,{onSuccess:()=>{u(!1),r(null)}})};return b.useEffect(()=>{s&&j()},[s,j]),e.jsxs(e.Fragment,{children:[e.jsxs(a.SheetHeader,{children:[e.jsx(a.SheetTitle,{children:"Revision History"}),(i==null?void 0:i.createdAt)&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Page created on ",y.format(new Date(i.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),S?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:i==null?void 0:i.id}),e.jsx(J,{compare:n,setCompare:t}),(E=f==null?void 0:f.filter(o=>o.uid==="current"))==null?void 0:E.map((o,w)=>e.jsx(I,{pageId:i==null?void 0:i.id,revision:o,isLatest:!0,onRestore:()=>D(o),onDelete:()=>C(o),revisionNumber:w,compare:n,setCompare:t},o.uid)),e.jsx(a.ScrollArea,{className:"min-h-0 flex-1",children:e.jsx("div",{className:"space-y-2",children:(R=f==null?void 0:f.filter(o=>o.uid!=="current"))==null?void 0:R.map((o,w)=>e.jsx(I,{pageId:i==null?void 0:i.id,revision:o,isLatest:o.uid==="current",onRestore:()=>D(o),onDelete:()=>C(o),revisionNumber:w+1,compare:n,setCompare:t},o.uid))})})]}),e.jsx(X,{open:c,onOpenChange:x,revision:l,onRestore:G,isRestoring:F}),e.jsx(Z,{open:m,onOpenChange:u,revision:l,onDelete:V,isDeleting:M})]})}exports.default=ee;