@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.
Files changed (96) hide show
  1. package/dist/{2AITGKQY-D4uLyw6-.cjs → 2AITGKQY-BGvx_OEz.cjs} +1 -1
  2. package/dist/{2AITGKQY-DYwNjBFe.js → 2AITGKQY-CCad8XK8.js} +2 -2
  3. package/dist/{NCMVHL6D-C-L7-X3f.cjs → NCMVHL6D-C_u5lHQe.cjs} +1 -1
  4. package/dist/{NCMVHL6D-DVB60g_2.js → NCMVHL6D-Iv9ufIUy.js} +2 -2
  5. package/dist/{ZDWCUMSJ-BORULBXb.cjs → ZDWCUMSJ-BqZPKNlU.cjs} +1 -1
  6. package/dist/{ZDWCUMSJ-Dp6ML_tn.js → ZDWCUMSJ-DT4dg62a.js} +1 -1
  7. package/dist/add-new-language-page-CfH8Ernl.js +401 -0
  8. package/dist/add-new-language-page-DlQjzp--.cjs +1 -0
  9. package/dist/add-new-page-DH-nv7ae.cjs +1 -0
  10. package/dist/add-new-page-DX1aQA56.js +31 -0
  11. package/dist/delete-page-DE-nabXs.js +40 -0
  12. package/dist/delete-page-WPGzECyJ.cjs +1 -0
  13. package/dist/digital-asset-manager-CGLE6VEW.cjs +1 -0
  14. package/dist/digital-asset-manager-DtWIJGhf.js +913 -0
  15. package/dist/duplicate-page-C1r3iBDY.js +133 -0
  16. package/dist/duplicate-page-CByLwz0z.cjs +1 -0
  17. package/dist/{dynamic-page-selector-8g1-84iW.js → dynamic-page-selector-Bk8_xgFx.js} +1 -1
  18. package/dist/{dynamic-page-selector-Cz6zWaKo.cjs → dynamic-page-selector-GwGV0Q6Z.cjs} +1 -1
  19. package/dist/image-editor-CeSSNbFY.js +108 -0
  20. package/dist/image-editor-CnDnY97s.cjs +1 -0
  21. package/dist/index-BELYt0c9.cjs +5 -0
  22. package/dist/{index-zaGKeGBW.js → index-Djepisz3.js} +1168 -1219
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +10 -10
  25. package/dist/{json-diff-viewer-c3ft4c4A.cjs → json-diff-viewer-BUhKwjf9.cjs} +1 -1
  26. package/dist/{json-diff-viewer-BF0qFBif.js → json-diff-viewer-zKpzQFxw.js} +1 -1
  27. package/dist/lang-panel-BYF6aLAt.cjs +1 -0
  28. package/dist/lang-panel-CtpuO-KH.js +225 -0
  29. package/dist/mark-as-template-0kikl0oL.js +153 -0
  30. package/dist/mark-as-template-wRAGJGtp.cjs +1 -0
  31. package/dist/no-language-page-content-B1M_x_U7.js +42 -0
  32. package/dist/no-language-page-content-DX9WXKXs.cjs +1 -0
  33. package/dist/{page-creator-Crc5BzeB.js → page-creator-BDJ6iDX9.js} +2 -2
  34. package/dist/{page-creator-CsZpQ7Gy.cjs → page-creator-DuN5JD41.cjs} +1 -1
  35. package/dist/page-lock-request-Bc_vwJhy.js +75 -0
  36. package/dist/page-lock-request-PRQo0DDm.cjs +1 -0
  37. package/dist/page-locked-by-dialog-DiKNpVwH.js +68 -0
  38. package/dist/page-locked-by-dialog-Dk0G2l7a.cjs +1 -0
  39. package/dist/page-manager-new-CUHqC9Og.js +354 -0
  40. package/dist/page-manager-new-KBhn93Yd.cjs +1 -0
  41. package/dist/page-manager-search-and-filter-CJ4AK1_7.js +201 -0
  42. package/dist/page-manager-search-and-filter-Ck5_TfNx.cjs +1 -0
  43. package/dist/{page-revisions-content-dSFvGFEO.cjs → page-revisions-content-Cw2cumYS.cjs} +1 -1
  44. package/dist/{page-revisions-content-PRgwV04S.js → page-revisions-content-q1Ch2-IQ.js} +18 -18
  45. package/dist/{publish-pages-content-akIgltlm.cjs → publish-pages-content-B8Uuw29Q.cjs} +1 -1
  46. package/dist/{publish-pages-content-C24iBibw.js → publish-pages-content-DEHD8qkl.js} +6 -6
  47. package/dist/{save-to-lib-C3H1ZPb-.cjs → save-to-lib-B83ZH4XX.cjs} +1 -1
  48. package/dist/{save-to-lib-DSPvtFSd.js → save-to-lib-QEOpf_Bd.js} +1 -1
  49. package/dist/{seo-panel-rZ8s88c0.js → seo-panel-DEQfOfZs.js} +17 -17
  50. package/dist/{seo-panel-Ce6aTIyt.cjs → seo-panel-DvDEatlO.cjs} +1 -1
  51. package/dist/{shared-json-ld-DMYOwp6B.js → shared-json-ld-Cyv9JitF.js} +26 -25
  52. package/dist/{shared-json-ld-hCiviuBf.cjs → shared-json-ld-D5F8RuF2.cjs} +1 -1
  53. package/dist/{slug-input-BN8eQgxP.cjs → slug-input-3vWL9FPC.cjs} +1 -1
  54. package/dist/{slug-input-Dhzaobv6.js → slug-input-D4e2anEs.js} +1 -1
  55. package/dist/theme-panel-footer-4dbLfEph.cjs +1 -0
  56. package/dist/theme-panel-footer-D3Gub87c.js +25 -0
  57. package/dist/unmark-as-template-BENGNo7g.js +39 -0
  58. package/dist/unmark-as-template-Dkc7zLZr.cjs +1 -0
  59. package/dist/unpublish-page-Cui0tgvd.cjs +1 -0
  60. package/dist/unpublish-page-D5tWKVLY.js +27 -0
  61. package/dist/{web-preview-BEyjKFDL.js → web-preview-CHNZZcqH.js} +1 -1
  62. package/dist/{web-preview-TTKtpSUi.cjs → web-preview-CcPTcMio.cjs} +1 -1
  63. package/package.json +3 -3
  64. package/dist/add-new-language-page-D4VPifNs.cjs +0 -1
  65. package/dist/add-new-language-page-DENCjC_f.js +0 -390
  66. package/dist/add-new-page-BuK6We-q.cjs +0 -1
  67. package/dist/add-new-page-CD-9ppdS.js +0 -30
  68. package/dist/delete-page-B-TP6nJ7.cjs +0 -1
  69. package/dist/delete-page-CatRlDfx.js +0 -38
  70. package/dist/digital-asset-manager-DL2nAqUC.cjs +0 -1
  71. package/dist/digital-asset-manager-KakxBkBC.js +0 -917
  72. package/dist/duplicate-page-D4Oiy71Q.cjs +0 -1
  73. package/dist/duplicate-page-DEmh0df0.js +0 -120
  74. package/dist/image-editor-D9MPdtxC.js +0 -107
  75. package/dist/image-editor-Da6lrqkL.cjs +0 -1
  76. package/dist/index-Blg1T7nL.cjs +0 -5
  77. package/dist/lang-panel-D1FKTNui.js +0 -218
  78. package/dist/lang-panel-ExS97Zgk.cjs +0 -1
  79. package/dist/mark-as-template-CcnkROAU.cjs +0 -1
  80. package/dist/mark-as-template-v-I05xcZ.js +0 -146
  81. package/dist/no-language-page-content-Bm5CcsUo.js +0 -35
  82. package/dist/no-language-page-content-Ddz2hnYs.cjs +0 -1
  83. package/dist/page-lock-request-Dx6OrOwM.cjs +0 -1
  84. package/dist/page-lock-request-WKfG7Sd3.js +0 -64
  85. package/dist/page-locked-by-dialog-BvdAXZPw.cjs +0 -1
  86. package/dist/page-locked-by-dialog-jy3lYV3l.js +0 -63
  87. package/dist/page-manager-new-CNHlSwfe.js +0 -354
  88. package/dist/page-manager-new-CUlpwqpH.cjs +0 -1
  89. package/dist/page-manager-search-and-filter-CuAn82Db.js +0 -197
  90. package/dist/page-manager-search-and-filter-eFsGtm5W.cjs +0 -1
  91. package/dist/theme-panel-footer-0GrdOHO_.cjs +0 -1
  92. package/dist/theme-panel-footer-BzEy5bsg.js +0 -25
  93. package/dist/unmark-as-template-DXEs6foh.cjs +0 -1
  94. package/dist/unmark-as-template-Dsiyocm9.js +0 -38
  95. package/dist/unpublish-page-c1mqQEa_.cjs +0 -1
  96. package/dist/unpublish-page-yGyz2jiw.js +0 -26
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),x=require("./index-BELYt0c9.cjs"),G=require("./use-page-expand-manager-2KjeYfVS.cjs"),n=require("lodash-es"),B=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])},I=(e,r,a)=>n.isEmpty(r)?e:e.map(t=>{if(!a(t.pageType))return{...t,shouldExpandOnSearch:!0,children:t.children?I(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?I(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 h=J(c,r),d=ne(e,h);c=n.uniqBy([...h,...d],"id")}const o=K(re(c)),y=I(o,r,t),S=n.filter(y,h=>t(h.pageType)).sort((h,d)=>(h.name||"").localeCompare(d.name||"")),p=n.filter(y,h=>!t(h.pageType));let f=[];if(a==="all"){const h=n.keyBy(p,"pageType");f=Object.values(n.mapValues(h,(d,j)=>({...d,id:j,name:n.startCase(j),isPartialGroup:!0,children:y.filter(b=>b.pageType===j)})))}else f=p.sort((h,d)=>(h.name||"").localeCompare(d.name||""));return[...S,...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[S]=x.usePageUserMapping(),p=x.useFallbackLang(),f=a===e.id,h=!!e.isTemplate,d=l.useMemo(()=>n.find(r,{key:e.pageType}),[r,e.pageType]),j=S==null?void 0:S[e.id],{data:b}=x.useChaiUserInfo(j),w=b?b==null?void 0:b.name:null;let m=n.get(c,e==null?void 0:e.id);m=n.get(m,"lang")===o?m:null;const E=o===p||!!m,L=(m==null?void 0:m.name)||(e==null?void 0:e.name)||"No name";let g=(m==null?void 0:m.slug)||(e==null?void 0:e.slug)||"";const C=g+(e!=null&&e.dynamic?`/${d==null?void 0:d.dynamicSlug}`:"")+(e!=null&&e.dynamicSlugCustom?`${e.dynamicSlugCustom}`:"");if(g.startsWith("/")&&!y){const u=g.split("/").pop();g=g.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]",M=`${f?"border-primary/30 bg-primary/5":"border-transparent hover:border-gray-200 hover:bg-gray-100"}`;return E?`${u} ${M} ${w?"opacity-60":""}`:`${u} bg-gray-100 opacity-50 group-hover:border-gray-200 border-transparent group-hover:bg-blue-100`},[E,f,w]);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:m?m.online:e.online}),!e.isPartialGroup&&s.jsx(ie,{page:e,pageType:d}),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})}),(g||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:[g,e.dynamic&&(d==null?void 0:d.dynamicSlug)&&s.jsxs("span",{className:"text-xs text-gray-500",children:["/",d==null?void 0:d.dynamicSlug,e.dynamicSlugCustom]})]})}),h&&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&&!w?s.jsx("div",{className:"duration absolute right-0.5 top-[3px]",children:s.jsx(x.PageActionsDropdown,{isLanguagePage:!!m,page:m||e,setDuplicatePage:u=>t("duplicate",u),setAddEditPage:u=>t("edit",m||u),setUnpublishPage:u=>t("unpublish",u),setDeletePage:u=>t("delete",m||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()})})})}):w?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:w&&s.jsxs("button",{className:"absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100",children:[s.jsx(v.Edit,{size:12,className:"stroke-[3]"})," ",s.jsx("span",{className:"font-medium",children:w})," is editing this page"]})}),s.jsx(s.Fragment,{children:!E&&!e.isPartialGroup&&!w&&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:S})=>{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:S}),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:S})]},f.id))})},de=l.lazy(()=>Promise.resolve().then(()=>require("./page-manager-search-and-filter-Ck5_TfNx.cjs"))),ue=l.lazy(()=>Promise.resolve().then(()=>require("./add-new-page-DH-nv7ae.cjs"))),me=l.lazy(()=>Promise.resolve().then(()=>require("./delete-page-WPGzECyJ.cjs"))),he=l.lazy(()=>Promise.resolve().then(()=>require("./duplicate-page-CByLwz0z.cjs"))),xe=l.lazy(()=>Promise.resolve().then(()=>require("./mark-as-template-wRAGJGtp.cjs"))),fe=l.lazy(()=>Promise.resolve().then(()=>require("./unmark-as-template-Dkc7zLZr.cjs"))),Pe=l.lazy(()=>Promise.resolve().then(()=>require("./unpublish-page-Cui0tgvd.cjs"))),ye=({close:e})=>{const{t:r}=B.useTranslation(),{languages:a,setSelectedLang:t}=B.useLanguages(),{data:c}=x.usePageTypes(),{data:o,isFetching:y}=x.useWebsitePages(),[S,p]=x.useSearchParams(),{updateForSelectedPage:f,expandPagesOnSearch:h}=G.usePageExpandManager(null),d=x.useFallbackLang(),j=S.get("page"),[b,w]=l.useState(""),[m,E]=l.useState(null),[L,g]=l.useState(null),[C,q]=l.useState(null),[u,M]=l.useState(null),[T,U]=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),z=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]),N=l.useMemo(()=>o?z?n.filter(o,P=>!(A!=null&&A[P.id])):ae(o,b,T,_):[],[o,_,b,T,A,z]);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})?U(P):U("all"))},[c,T]),l.useEffect(()=>{if(j&&!y&&!n.find(o,{id:j})){const i=n.find(o,{slug:"/"});if(i){const F=new URLSearchParams({page:i.id});x.navigateToPage(F,p)}else x.navigateToPage(new URLSearchParams({}),p,!0)}},[o,j,y,p]),l.useEffect(()=>{j&&!y&&!n.isEmpty(N)&&f(N,j)},[j,y,N,f]),l.useEffect(()=>{!n.isEmpty(b)&&!n.isEmpty(N)&&h(N)},[b,N,h]);const{setSelectedLang:$}=B.useLanguages(),Q=l.useCallback(P=>{const i=new URLSearchParams({page:P});k!==d?(i.set("lang",k),$(k)):$(""),x.navigateToPage(i,p),e()},[e,p,$,k,d]),V=(P,i)=>{var F;if(i)switch(P){case"add":g(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}):g(i);break;case"delete":E(i);break;case"unpublish":q(i);break;case"markAsTemplate":M(i);break;case"unmarkAsTemplate":W(i);break;case"duplicate":R(i);break;case"addLanguagePage":H({edit:!1,primaryPage:((F=i==null?void 0:i.page)==null?void 0:F.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:N,search:b,setSearch:w,languages:[d,...a],selectedLanguage:k,setSelectedLanguage:Y,selectedPageType:T,setSelectedPageType:U,onAddPage:P=>V("add",P),showUntranslatedPages:z,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(N)?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:N,pageTypes:c,currentPage:j||"",onClickAction:V,languagePages:A,selectedLanguage:k,showUntranslatedPages:z})})]}),L&&s.jsx(l.Suspense,{children:s.jsx(ue,{closePanel:e,editPage:Q,addEditPage:L,setAddEditPage:g})}),m&&s.jsx(l.Suspense,{children:s.jsx(me,{page:m,onClose:()=>E(null)})}),C&&s.jsx(l.Suspense,{children:s.jsx(Pe,{page:C,onClose:()=>q(null)})}),u&&s.jsx(l.Suspense,{children:s.jsx(xe,{page:u,onClose:()=>M(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,201 @@
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-Djepisz3.js";
3
+ import { u as T } from "./use-page-expand-manager-D6T75I11.js";
4
+ import { useTranslation as f } from "@chaibuilder/sdk";
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";
6
+ import { useQueryClient as M } from "@tanstack/react-query";
7
+ import { isEmpty as w, filter as x, map as S, get as o } from "lodash-es";
8
+ import { Star as R, Plus as W, FilterXIcon as q, Filter as B, ListFilter as K, Search as P, ChevronsUpDown as Q, ChevronsDownUp as _, RefreshCw as O } from "lucide-react";
9
+ import { useState as U } from "react";
10
+ const V = ({ selectedPageType: a, setSelectedPageType: i }) => {
11
+ const { t: l } = f(), [r, s] = U(""), { data: c } = z(), h = (t) => {
12
+ if (!r) return !0;
13
+ const d = r.toLowerCase(), u = (v) => String(o(t, v, "")).toLowerCase().includes(d);
14
+ return u("name") || u("key");
15
+ }, p = c.find((t) => t.key === a);
16
+ return /* @__PURE__ */ n($, { onValueChange: i, value: a, children: [
17
+ /* @__PURE__ */ e(
18
+ G,
19
+ {
20
+ className: `${a === "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`,
21
+ children: /* @__PURE__ */ n("div", { className: "flex w-full items-center justify-between gap-x-1.5", children: [
22
+ /* @__PURE__ */ e("span", { className: "max-w-[150px] overflow-hidden truncate whitespace-nowrap font-medium leading-tight", children: (p == null ? void 0 : p.name) || l("All") }),
23
+ /* @__PURE__ */ e(
24
+ K,
25
+ {
26
+ className: `${a !== "all" ? "fill-sky-50 text-sky-500" : ""} pointer-events-none h-4 w-4 text-muted-foreground hover:bg-blue-300`
27
+ }
28
+ )
29
+ ] })
30
+ }
31
+ ),
32
+ /* @__PURE__ */ n(D, { children: [
33
+ /* @__PURE__ */ e("div", { className: "sticky top-0 z-10 bg-white pb-2", children: /* @__PURE__ */ n("div", { className: "relative", children: [
34
+ /* @__PURE__ */ e(P, { strokeWidth: 2, className: "absolute left-2 top-2.5 h-3.5 w-3.5 text-gray-400" }),
35
+ /* @__PURE__ */ e(
36
+ E,
37
+ {
38
+ placeholder: l("Search page types..."),
39
+ className: "h-8 w-full rounded border pl-8 text-xs shadow-none",
40
+ value: r,
41
+ onChange: (t) => s(t.target.value),
42
+ onKeyDown: (t) => t.stopPropagation()
43
+ }
44
+ )
45
+ ] }) }),
46
+ /* @__PURE__ */ e(N, { value: "all", children: l("All") }),
47
+ !w(x(c, (t) => t.hasSlug && h(t))) && /* @__PURE__ */ n(k, { children: [
48
+ /* @__PURE__ */ e("div", { className: "mt-2 border-t px-2 py-1.5 pt-2 text-xs font-semibold text-gray-500", children: l("Pages") }),
49
+ S(
50
+ [...x(c, (t) => t.hasSlug && h(t))].sort(
51
+ (t, d) => o(t, "name", "").localeCompare(o(d, "name", ""))
52
+ ),
53
+ (t) => /* @__PURE__ */ e(N, { value: o(t, "key"), children: o(t, "name") }, o(t, "key"))
54
+ )
55
+ ] }),
56
+ !w(x(c, (t) => !t.hasSlug && h(t))) && /* @__PURE__ */ n(k, { children: [
57
+ /* @__PURE__ */ e("div", { className: "mt-2 border-t px-2 py-1.5 pt-2 text-xs font-semibold text-gray-500", children: l("Partials") }),
58
+ S(
59
+ [...x(c, (t) => !t.hasSlug && h(t))].sort(
60
+ (t, d) => o(t, "name", "").localeCompare(o(d, "name", ""))
61
+ ),
62
+ (t) => /* @__PURE__ */ e(N, { value: o(t, "key"), children: o(t, "name") }, o(t, "key"))
63
+ )
64
+ ] }),
65
+ w(x(c, h)) && /* @__PURE__ */ e("div", { className: "px-3 py-2 text-center text-sm text-gray-500", children: l("No matching page types found") })
66
+ ] })
67
+ ] });
68
+ }, X = ({ search: a, setSearch: i }) => {
69
+ const { t: l } = f();
70
+ return /* @__PURE__ */ n("div", { className: "relative flex h-9 flex-1 items-center gap-2 rounded-md border px-2.5", children: [
71
+ /* @__PURE__ */ e("label", { htmlFor: "page-search-input", className: "sr-only", children: l("Search Pages") }),
72
+ /* @__PURE__ */ e(
73
+ P,
74
+ {
75
+ className: `${a ? "fill-sky-50 text-sky-500" : ""} pointer-events-none h-4 w-4 text-muted-foreground`,
76
+ "aria-hidden": "true"
77
+ }
78
+ ),
79
+ /* @__PURE__ */ e(
80
+ E,
81
+ {
82
+ id: "page-search-input",
83
+ placeholder: l("Search pages"),
84
+ value: a,
85
+ onChange: (r) => i(r.target.value),
86
+ className: "border-none px-1.5 shadow-none outline-none ring-0 transition-none focus:outline-none focus:ring-0 focus-visible:ring-0",
87
+ autoComplete: "off"
88
+ }
89
+ )
90
+ ] });
91
+ }, H = ({ pages: a }) => {
92
+ const { t: i } = f(), { expandAll: l, collapseAll: r, expandedPages: s } = T(null);
93
+ return /* @__PURE__ */ n("div", { className: "flex gap-1", children: [
94
+ /* @__PURE__ */ n(g, { children: [
95
+ /* @__PURE__ */ e(b, { asChild: !0, children: /* @__PURE__ */ e(m, { variant: "outline", size: "icon", onClick: () => l(a), className: "rounded p-1 text-gray-500", children: /* @__PURE__ */ e(Q, {}) }) }),
96
+ /* @__PURE__ */ e(y, { children: i("Expand All") })
97
+ ] }),
98
+ /* @__PURE__ */ n(g, { children: [
99
+ /* @__PURE__ */ e(b, { asChild: !0, children: /* @__PURE__ */ e(
100
+ m,
101
+ {
102
+ disabled: s.length === 0,
103
+ variant: "outline",
104
+ size: "icon",
105
+ onClick: () => r(),
106
+ className: "rounded p-1 text-gray-500",
107
+ children: /* @__PURE__ */ e(_, {})
108
+ }
109
+ ) }),
110
+ /* @__PURE__ */ e(y, { children: i("Collapse All") })
111
+ ] })
112
+ ] });
113
+ }, J = ({ languages: a, selectedLanguage: i, setSelectedLanguage: l }) => {
114
+ const r = F();
115
+ return /* @__PURE__ */ e("div", { className: "scrollbar-hide flex gap-1 overflow-x-auto pb-1", children: a.map((s) => /* @__PURE__ */ n(
116
+ m,
117
+ {
118
+ variant: i === s ? "default" : "outline",
119
+ size: "sm",
120
+ className: `h-6 flex-shrink-0 whitespace-nowrap rounded px-3 text-xs font-normal ${i === s ? "bg-black text-white hover:bg-black" : "text-gray-500"}`,
121
+ onClick: () => l(s.toLowerCase()),
122
+ children: [
123
+ s === r && /* @__PURE__ */ e(R, { size: 4, className: `p-0.5 ${i === r ? "fill-white" : "fill-black"}` }),
124
+ I[s] || ""
125
+ ]
126
+ },
127
+ s
128
+ )) });
129
+ }, A = () => {
130
+ const { t: a } = f(), i = M();
131
+ return /* @__PURE__ */ n(g, { children: [
132
+ /* @__PURE__ */ e(b, { asChild: !0, children: /* @__PURE__ */ e(
133
+ m,
134
+ {
135
+ size: "sm",
136
+ variant: "ghost",
137
+ onClick: () => i.invalidateQueries({ queryKey: [j.GET_WEBSITE_PAGES] }),
138
+ className: "mt-1 h-6 w-6",
139
+ children: /* @__PURE__ */ e(O, {})
140
+ }
141
+ ) }),
142
+ /* @__PURE__ */ e(y, { side: "bottom", children: a("Refresh pages list") })
143
+ ] });
144
+ }, se = ({
145
+ pages: a,
146
+ search: i,
147
+ setSearch: l,
148
+ languages: r,
149
+ onAddPage: s,
150
+ selectedLanguage: c,
151
+ setSelectedLanguage: h,
152
+ selectedPageType: p,
153
+ setSelectedPageType: t,
154
+ showUntranslatedPages: d,
155
+ setShowUntranslatedPages: u
156
+ }) => {
157
+ const { t: v } = f(), C = r.length > 1;
158
+ return /* @__PURE__ */ n("div", { className: "space-y-3 border-b border-b-gray-200 px-4 pb-1", children: [
159
+ /* @__PURE__ */ n("div", { className: "flex items-center gap-x-2", children: [
160
+ /* @__PURE__ */ e(V, { selectedPageType: p, setSelectedPageType: t }),
161
+ /* @__PURE__ */ e(X, { search: i, setSearch: l }),
162
+ /* @__PURE__ */ e(H, { pages: a }),
163
+ /* @__PURE__ */ n(m, { variant: "default", onClick: s, className: "rounded px-3 font-normal", children: [
164
+ /* @__PURE__ */ e(W, { strokeWidth: 2, className: "stroke-white stroke-[3]" }),
165
+ /* @__PURE__ */ e("span", { className: "font-normal text-white", children: v("Add Page") })
166
+ ] }),
167
+ !C && /* @__PURE__ */ e(A, {})
168
+ ] }),
169
+ C ? /* @__PURE__ */ n("div", { className: "flex items-center justify-between gap-2", children: [
170
+ /* @__PURE__ */ e(
171
+ J,
172
+ {
173
+ languages: r,
174
+ selectedLanguage: c,
175
+ setSelectedLanguage: (L) => {
176
+ h(L), u(d && (r == null ? void 0 : r[0]) !== c);
177
+ }
178
+ }
179
+ ),
180
+ /* @__PURE__ */ n("div", { className: "flex items-center gap-x-2", children: [
181
+ (r == null ? void 0 : r[0]) !== c && /* @__PURE__ */ n(g, { children: [
182
+ /* @__PURE__ */ e(b, { asChild: !0, children: /* @__PURE__ */ e(
183
+ m,
184
+ {
185
+ variant: "ghost",
186
+ onClick: () => u(!d),
187
+ className: "h-6 rounded px-3 py-1 text-xs font-normal",
188
+ children: d ? /* @__PURE__ */ e(q, {}) : /* @__PURE__ */ e(B, {})
189
+ }
190
+ ) }),
191
+ /* @__PURE__ */ e(y, { side: "bottom", children: v("Toggle Untranslated Pages") })
192
+ ] }),
193
+ /* @__PURE__ */ e(A, {})
194
+ ] })
195
+ ] }) : /* @__PURE__ */ e("div", { className: "flex items-center justify-between gap-2" })
196
+ ] });
197
+ };
198
+ export {
199
+ J as LanguageSelector,
200
+ se as default
201
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("./index-BELYt0c9.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-Blg1T7nL.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-c3ft4c4A.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-BELYt0c9.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-BUhKwjf9.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,8 +1,8 @@
1
1
  import { jsxs as n, Fragment as p, jsx as e } from "react/jsx-runtime";
2
- import { al as C, am as A, A as b, aq as j, at as le, aj as I, ar as R, as as w } from "./index-zaGKeGBW.js";
3
- import { useQuery as re, useQueryClient as O, useMutation as q } from "@tanstack/react-query";
2
+ import { ak as C, al as A, A as b, ap as q, as as le, ai as I, aq as R, ar as w } from "./index-Djepisz3.js";
3
+ import { useQuery as re, useQueryClient as k, useMutation as G } from "@tanstack/react-query";
4
4
  import { useLanguages as ie, useSavePage as de } from "@chaibuilder/sdk";
5
- import { SheetHeader as ce, SheetTitle as oe, ScrollArea as ue, Skeleton as y, Button as g, DropdownMenu as me, DropdownMenuTrigger as he, DropdownMenuContent as fe, DropdownMenuItem as U, DropdownMenuSeparator as pe, Dialog as G, DialogContent as L, DialogHeader as P, DialogTitle as $, DialogDescription as z, DialogFooter as H } from "@chaibuilder/sdk/ui";
5
+ import { SheetHeader as ce, SheetTitle as oe, ScrollArea as ue, Skeleton as y, Button as g, DropdownMenu as me, DropdownMenuTrigger as he, DropdownMenuContent as fe, DropdownMenuItem as U, DropdownMenuSeparator as pe, Dialog as j, DialogContent as L, DialogHeader as P, DialogTitle as $, DialogDescription as z, DialogFooter as H } from "@chaibuilder/sdk/ui";
6
6
  import { format as D, formatDistanceToNow as xe } from "date-fns";
7
7
  import { isEmpty as ge } from "lodash-es";
8
8
  import { FileJson as Ne, MoreHorizontal as be, Undo2 as J, Trash as Q, CloudOff as ye, Rocket as ve, Save as we, X as De } from "lucide-react";
@@ -21,8 +21,8 @@ function Ce(t) {
21
21
  });
22
22
  }
23
23
  const Ae = () => {
24
- const t = C(), s = A(), a = O();
25
- return q({
24
+ const t = C(), s = A(), a = k();
25
+ return G({
26
26
  mutationFn: async (i) => await s(t, {
27
27
  action: b.DELETE_PAGE_REVISION,
28
28
  data: { revisionId: i }
@@ -34,8 +34,8 @@ const Ae = () => {
34
34
  }
35
35
  });
36
36
  }, Ie = () => {
37
- const t = C(), s = A(), a = O();
38
- return q({
37
+ const t = C(), s = A(), a = k();
38
+ return G({
39
39
  mutationFn: async ({ revisionId: i, discardCurrent: l }) => await s(t, {
40
40
  action: b.RESTORE_PAGE_REVISION,
41
41
  data: { revisionId: i, discardCurrent: l }
@@ -46,7 +46,7 @@ const Ae = () => {
46
46
  });
47
47
  }
48
48
  });
49
- }, Oe = Se(() => import("./json-diff-viewer-BF0qFBif.js")), N = ({ tag: t }) => t === "draft" ? /* @__PURE__ */ n("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: [
49
+ }, ke = Se(() => import("./json-diff-viewer-zKpzQFxw.js")), N = ({ tag: t }) => t === "draft" ? /* @__PURE__ */ n("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: [
50
50
  /* @__PURE__ */ n("span", { className: "relative flex h-2 w-2", children: [
51
51
  /* @__PURE__ */ e("span", { className: "absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75" }),
52
52
  /* @__PURE__ */ e("span", { className: "relative inline-flex h-2 w-2 rounded-full bg-amber-500" })
@@ -65,8 +65,8 @@ const Ae = () => {
65
65
  /* @__PURE__ */ e(we, { className: "h-3 w-3" }),
66
66
  /* @__PURE__ */ e("span", { className: "text-[11px] leading-tight", children: "Unsaved changes" })
67
67
  ] }) : /* @__PURE__ */ e("span", { className: "rounded bg-purple-500/10 px-1.5 py-0.5 font-mono text-xs font-bold text-purple-600", children: t });
68
- function ke({ compare: t, setCompare: s }) {
69
- const { data: a } = j(), { saveState: i } = de(), [l] = le();
68
+ function Oe({ compare: t, setCompare: s }) {
69
+ const { data: a } = q(), { saveState: i } = de(), [l] = le();
70
70
  if (!a) return null;
71
71
  const d = !!t.find((o) => {
72
72
  var r;
@@ -214,7 +214,7 @@ function Te({ compare: t, setCompare: s, pageId: a }) {
214
214
  Re,
215
215
  {
216
216
  fallback: /* @__PURE__ */ e("div", { className: "flex items-center justify-center p-4", children: /* @__PURE__ */ e("span", { className: "text-sm", children: "Loading diff viewer..." }) }),
217
- children: /* @__PURE__ */ e(Oe, { open: i, onOpenChange: l, compare: t })
217
+ children: /* @__PURE__ */ e(ke, { open: i, onOpenChange: l, compare: t })
218
218
  }
219
219
  )
220
220
  ] });
@@ -264,7 +264,7 @@ function Ue({
264
264
  }) {
265
265
  const { data: d } = I((a == null ? void 0 : a.currentEditor) || ""), u = (d == null ? void 0 : d.name) || "Unknown";
266
266
  return a ? /* @__PURE__ */ e(
267
- G,
267
+ j,
268
268
  {
269
269
  open: t,
270
270
  onOpenChange: (m) => {
@@ -313,7 +313,7 @@ function Fe({
313
313
  }) {
314
314
  const { data: d } = I((a == null ? void 0 : a.currentEditor) || ""), u = (d == null ? void 0 : d.name) || "Unknown";
315
315
  return a ? /* @__PURE__ */ e(
316
- G,
316
+ j,
317
317
  {
318
318
  open: t,
319
319
  onOpenChange: (m) => {
@@ -349,7 +349,7 @@ function Fe({
349
349
  }
350
350
  function Je({ isOpen: t }) {
351
351
  var T, _;
352
- const [s, a] = v.useState([]), [i, l] = v.useState(null), [d, u] = v.useState(!1), [m, o] = v.useState(!1), { data: r } = j(), { data: f, isFetching: S, error: h, refetch: x } = Ce(r == null ? void 0 : r.id), { mutate: W, isPending: Y } = Ae(), { mutate: B, isPending: X } = Ie(), Z = O(), { selectedLang: ee, fallbackLang: te } = ie(), ne = ee || te;
352
+ const [s, a] = v.useState([]), [i, l] = v.useState(null), [d, u] = v.useState(!1), [m, o] = v.useState(!1), { data: r } = q(), { data: f, isFetching: S, error: h, refetch: x } = Ce(r == null ? void 0 : r.id), { mutate: W, isPending: Y } = Ae(), { mutate: B, isPending: X } = Ie(), Z = k(), { selectedLang: ee, fallbackLang: te } = ie(), ne = ee || te;
353
353
  F(() => a([]), [r == null ? void 0 : r.id]);
354
354
  const ae = (c) => {
355
355
  i && B(
@@ -362,7 +362,7 @@ function Je({ isOpen: t }) {
362
362
  }
363
363
  }
364
364
  );
365
- }, k = (c) => {
365
+ }, O = (c) => {
366
366
  l(c), u(!0);
367
367
  }, M = (c) => {
368
368
  l(c), o(!0);
@@ -389,14 +389,14 @@ function Je({ isOpen: t }) {
389
389
  ] }),
390
390
  S ? /* @__PURE__ */ e(Me, {}) : h ? /* @__PURE__ */ e("div", { className: "p-4 text-center text-sm text-muted-foreground", children: "Failed to load revisions. Please try again." }) : /* @__PURE__ */ n("div", { className: "mt-2 flex h-full min-h-0 flex-1 flex-col space-y-2", children: [
391
391
  /* @__PURE__ */ e(Te, { lang: ne, compare: s, setCompare: a, pageId: r == null ? void 0 : r.id }),
392
- /* @__PURE__ */ e(ke, { compare: s, setCompare: a }),
392
+ /* @__PURE__ */ e(Oe, { compare: s, setCompare: a }),
393
393
  (T = f == null ? void 0 : f.filter((c) => c.uid === "current")) == null ? void 0 : T.map((c, E) => /* @__PURE__ */ e(
394
394
  V,
395
395
  {
396
396
  pageId: r == null ? void 0 : r.id,
397
397
  revision: c,
398
398
  isLatest: !0,
399
- onRestore: () => k(c),
399
+ onRestore: () => O(c),
400
400
  onDelete: () => M(c),
401
401
  revisionNumber: E,
402
402
  compare: s,
@@ -410,7 +410,7 @@ function Je({ isOpen: t }) {
410
410
  pageId: r == null ? void 0 : r.id,
411
411
  revision: c,
412
412
  isLatest: c.uid === "current",
413
- onRestore: () => k(c),
413
+ onRestore: () => O(c),
414
414
  onDelete: () => M(c),
415
415
  revisionNumber: E + 1,
416
416
  compare: s,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),B=require("./page-manager-search-and-filter-eFsGtm5W.cjs"),r=require("./index-Blg1T7nL.cjs"),L=require("@tanstack/react-query"),h=require("@chaibuilder/sdk/ui"),t=require("lodash-es"),j=require("lucide-react"),i=require("react"),F=()=>{const l=r.useApiUrl(),u=r.useFetch();return L.useQuery({queryKey:[r.ACTIONS.GET_CHANGES],queryFn:async()=>u(l,{action:r.ACTIONS.GET_CHANGES})})},O=({page:l,selectedPages:u,handleCheckboxChange:b,getPageType:m,hasSlug:o,currentOwnerId:x})=>{const{data:d}=r.useChaiUserInfo(x),a=d==null?void 0:d.name;return e.jsxs("tr",{className:"group relative border-b last:border-b-0 hover:bg-gray-50",children:[e.jsxs("td",{scope:"row",className:`flex items-center gap-x-1 whitespace-nowrap px-6 py-2 text-gray-900 dark:text-white ${a?"opacity-50":""}`,children:[a?e.jsx(j.Lock,{className:"h-4 w-4 fill-red-200 text-red-500"}):e.jsx("input",{checked:t.includes(u,l==null?void 0:l.id),onClick:p=>{p.stopPropagation(),b(l==null?void 0:l.id)},type:"checkbox",className:"cursor-pointer rounded focus:outline-none focus:ring-0"})," ",o(l.pageType)?e.jsx(j.File,{className:"h-4 w-4"}):e.jsx(j.GlobeIcon,{className:"h-4 w-4"}),e.jsx(r.Tooltip,{content:l.name,side:"top",showTooltip:l.name.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-medium text-black",children:l.name})}),l.slug&&e.jsx(r.Tooltip,{content:l.slug,side:"top",showTooltip:l.slug.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-mono text-xs text-muted-foreground",children:l.slug})})]}),e.jsx("td",{className:"px-2",children:m(l==null?void 0:l.pageType)}),e.jsx("td",{className:"px-4 text-right",children:t.first(l.changes)||""}),e.jsx(e.Fragment,{children:a&&e.jsxs("button",{className:"absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100",children:[e.jsx(j.Edit,{size:12,className:"stroke-[3]"})," ",e.jsx("span",{className:"font-medium",children:a})," is editing this page"]})})]},l==null?void 0:l.id)},G=({onClose:l=()=>{},isPending:u,publishPage:b})=>{const[m]=r.usePageUserMapping(),[o,x]=i.useState([]),d=r.useFallbackLang(),[a,p]=i.useState(d),{data:N,isFetching:T}=F(),{data:g}=r.usePageTypes(),k=i.useCallback(s=>{var n;return(n=t.find(g,{key:s}))==null?void 0:n.hasSlug},[g]),y=i.useMemo(()=>t.filter(g,s=>!k(s.key)).map(s=>s.key),[k,g]),P=t.uniq(t.map(N,"lang")).filter(Boolean),c=i.useMemo(()=>t.filter(N,s=>s.pageType==="theme"?!1:a===d?s.lang===a||s.lang==="":s.lang===a),[N,a,d]),w=i.useMemo(()=>t.filter(c,s=>!y.includes(s.pageType)),[c,y]),S=i.useMemo(()=>t.filter(c,s=>y.includes(s.pageType)),[c,y]);i.useEffect(()=>{const s=t.map(t.filter(c,{online:!0}),"id");x(s)},[c]),i.useEffect(()=>{const s=Object.keys(m);x(n=>t.filter(n,f=>!t.includes(s,f)))},[m]);const C=o.length===(c==null?void 0:c.length),v=s=>{x(n=>t.includes(n,s)?t.filter(n,f=>f!==s):t.concat(n,s))},E=()=>{x(C?[]:t.map(c,"id"))},q=()=>{b({ids:t.uniq(o)},{onSuccess:()=>{l(),r.throwConfetti("CENTER_CENTER"),p(d)}})},M=s=>{if(s==="theme")return"Theme";const n=t.find(g,{key:s});return n?n==null?void 0:n.name:s},A=i.useMemo(()=>{const s=[{label:"Updated",top:"pt-2"},...t.orderBy(t.filter(w,{online:!0}),"pageType"),...t.orderBy(t.filter(S,{online:!0}),"pageType")].filter(f=>f.pageType!=="theme"),n=[{label:"Offline",top:"pt-6"},...t.orderBy(t.filter(w,{online:!1}),"pageType"),...t.orderBy(t.filter(S,{online:!1}),"pageType")];return[...s,...n]},[w,S]);return e.jsxs(h.DialogContent,{className:"flex max-h-[80%] max-w-4xl flex-col",children:[e.jsxs(h.DialogHeader,{children:[e.jsx(h.DialogTitle,{children:"Publish changes"}),e.jsx(h.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),P.length>0&&e.jsx("div",{className:"my-[2px] mt-0",children:e.jsx(B.LanguageSelector,{languages:[d,...P],selectedLanguage:a,setSelectedLanguage:p})}),e.jsx("div",{className:"no-scrollbar relative -mx-4 -mt-4 h-full max-h-full overflow-y-auto",children:T?e.jsxs("div",{className:"space-y-2 px-1",children:[e.jsx("div",{className:"mt-2 h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):e.jsxs("table",{className:"w-full text-left text-xs text-gray-500 dark:text-gray-400 rtl:text-right",children:[e.jsx("thead",{className:"sticky top-0 z-10 border-b bg-gray-50 text-gray-700 dark:bg-gray-700 dark:text-gray-400",children:e.jsxs("tr",{children:[e.jsxs("th",{scope:"col",className:"w-[1 50px] flex items-center gap-x-2 px-6 py-3",children:[e.jsx("input",{checked:C,onClick:s=>{s.stopPropagation(),E()},type:"checkbox",className:"mt-1 cursor-pointer rounded focus:outline-none focus:ring-0"}),"Name"]}),e.jsx("th",{scope:"col",className:"w-[150px] px-2 py-3",children:"Type"}),e.jsx("th",{scope:"col",className:"w-[150px] px-4 py-3 text-right",children:"Status"})]})}),e.jsx("tbody",{children:t.map(A,s=>s.label?e.jsx("tr",{children:e.jsxs("td",{colSpan:3,className:`relative px-6 py-2 text-xs font-medium text-gray-800 ${s.top}`,children:[e.jsx("div",{className:"absolute inset-0 left-6 flex items-center",children:e.jsx("div",{className:"order-gray-300 w-full"})}),e.jsx("div",{className:"relative flex justify-start",children:e.jsx("span",{className:"bg-gray-50 pr-2",children:s.label})})]})},"separator"):e.jsx(O,{page:s,selectedPages:o,handleCheckboxChange:v,getPageType:M,hasSlug:k,currentOwnerId:m[(s==null?void 0:s.primaryPage)||(s==null?void 0:s.id)]}))})]})}),e.jsxs(h.DialogFooter,{className:"mt-10 flex items-center justify-center",children:[o.length>0&&e.jsxs("span",{className:"text-center text-sm text-muted-foreground",children:[o.length," Page",o.length!==1?"s":""," Selected"]}),e.jsx(h.Button,{disabled:u,variant:"outline",onClick:l,children:"Cancel"}),e.jsx(h.Button,{disabled:u||T||t.isEmpty(o),onClick:q,children:u?"Publishing...":"Publish Selected"})]})]})};exports.default=G;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),B=require("./page-manager-search-and-filter-Ck5_TfNx.cjs"),r=require("./index-BELYt0c9.cjs"),L=require("@tanstack/react-query"),h=require("@chaibuilder/sdk/ui"),t=require("lodash-es"),j=require("lucide-react"),i=require("react"),F=()=>{const l=r.useApiUrl(),u=r.useFetch();return L.useQuery({queryKey:[r.ACTIONS.GET_CHANGES],queryFn:async()=>u(l,{action:r.ACTIONS.GET_CHANGES})})},O=({page:l,selectedPages:u,handleCheckboxChange:b,getPageType:m,hasSlug:o,currentOwnerId:x})=>{const{data:d}=r.useChaiUserInfo(x),a=d==null?void 0:d.name;return e.jsxs("tr",{className:"group relative border-b last:border-b-0 hover:bg-gray-50",children:[e.jsxs("td",{scope:"row",className:`flex items-center gap-x-1 whitespace-nowrap px-6 py-2 text-gray-900 dark:text-white ${a?"opacity-50":""}`,children:[a?e.jsx(j.Lock,{className:"h-4 w-4 fill-red-200 text-red-500"}):e.jsx("input",{checked:t.includes(u,l==null?void 0:l.id),onClick:p=>{p.stopPropagation(),b(l==null?void 0:l.id)},type:"checkbox",className:"cursor-pointer rounded focus:outline-none focus:ring-0"})," ",o(l.pageType)?e.jsx(j.File,{className:"h-4 w-4"}):e.jsx(j.GlobeIcon,{className:"h-4 w-4"}),e.jsx(r.Tooltip,{content:l.name,side:"top",showTooltip:l.name.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-medium text-black",children:l.name})}),l.slug&&e.jsx(r.Tooltip,{content:l.slug,side:"top",showTooltip:l.slug.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-mono text-xs text-muted-foreground",children:l.slug})})]}),e.jsx("td",{className:"px-2",children:m(l==null?void 0:l.pageType)}),e.jsx("td",{className:"px-4 text-right",children:t.first(l.changes)||""}),e.jsx(e.Fragment,{children:a&&e.jsxs("button",{className:"absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100",children:[e.jsx(j.Edit,{size:12,className:"stroke-[3]"})," ",e.jsx("span",{className:"font-medium",children:a})," is editing this page"]})})]},l==null?void 0:l.id)},G=({onClose:l=()=>{},isPending:u,publishPage:b})=>{const[m]=r.usePageUserMapping(),[o,x]=i.useState([]),d=r.useFallbackLang(),[a,p]=i.useState(d),{data:N,isFetching:T}=F(),{data:g}=r.usePageTypes(),k=i.useCallback(s=>{var n;return(n=t.find(g,{key:s}))==null?void 0:n.hasSlug},[g]),y=i.useMemo(()=>t.filter(g,s=>!k(s.key)).map(s=>s.key),[k,g]),P=t.uniq(t.map(N,"lang")).filter(Boolean),c=i.useMemo(()=>t.filter(N,s=>s.pageType==="theme"?!1:a===d?s.lang===a||s.lang==="":s.lang===a),[N,a,d]),w=i.useMemo(()=>t.filter(c,s=>!y.includes(s.pageType)),[c,y]),S=i.useMemo(()=>t.filter(c,s=>y.includes(s.pageType)),[c,y]);i.useEffect(()=>{const s=t.map(t.filter(c,{online:!0}),"id");x(s)},[c]),i.useEffect(()=>{const s=Object.keys(m);x(n=>t.filter(n,f=>!t.includes(s,f)))},[m]);const C=o.length===(c==null?void 0:c.length),v=s=>{x(n=>t.includes(n,s)?t.filter(n,f=>f!==s):t.concat(n,s))},E=()=>{x(C?[]:t.map(c,"id"))},q=()=>{b({ids:t.uniq(o)},{onSuccess:()=>{l(),r.throwConfetti("CENTER_CENTER"),p(d)}})},M=s=>{if(s==="theme")return"Theme";const n=t.find(g,{key:s});return n?n==null?void 0:n.name:s},A=i.useMemo(()=>{const s=[{label:"Updated",top:"pt-2"},...t.orderBy(t.filter(w,{online:!0}),"pageType"),...t.orderBy(t.filter(S,{online:!0}),"pageType")].filter(f=>f.pageType!=="theme"),n=[{label:"Offline",top:"pt-6"},...t.orderBy(t.filter(w,{online:!1}),"pageType"),...t.orderBy(t.filter(S,{online:!1}),"pageType")];return[...s,...n]},[w,S]);return e.jsxs(h.DialogContent,{className:"flex max-h-[80%] max-w-4xl flex-col",children:[e.jsxs(h.DialogHeader,{children:[e.jsx(h.DialogTitle,{children:"Publish changes"}),e.jsx(h.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),P.length>0&&e.jsx("div",{className:"my-[2px] mt-0",children:e.jsx(B.LanguageSelector,{languages:[d,...P],selectedLanguage:a,setSelectedLanguage:p})}),e.jsx("div",{className:"no-scrollbar relative -mx-4 -mt-4 h-full max-h-full overflow-y-auto",children:T?e.jsxs("div",{className:"space-y-2 px-1",children:[e.jsx("div",{className:"mt-2 h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):e.jsxs("table",{className:"w-full text-left text-xs text-gray-500 dark:text-gray-400 rtl:text-right",children:[e.jsx("thead",{className:"sticky top-0 z-10 border-b bg-gray-50 text-gray-700 dark:bg-gray-700 dark:text-gray-400",children:e.jsxs("tr",{children:[e.jsxs("th",{scope:"col",className:"w-[1 50px] flex items-center gap-x-2 px-6 py-3",children:[e.jsx("input",{checked:C,onClick:s=>{s.stopPropagation(),E()},type:"checkbox",className:"mt-1 cursor-pointer rounded focus:outline-none focus:ring-0"}),"Name"]}),e.jsx("th",{scope:"col",className:"w-[150px] px-2 py-3",children:"Type"}),e.jsx("th",{scope:"col",className:"w-[150px] px-4 py-3 text-right",children:"Status"})]})}),e.jsx("tbody",{children:t.map(A,s=>s.label?e.jsx("tr",{children:e.jsxs("td",{colSpan:3,className:`relative px-6 py-2 text-xs font-medium text-gray-800 ${s.top}`,children:[e.jsx("div",{className:"absolute inset-0 left-6 flex items-center",children:e.jsx("div",{className:"order-gray-300 w-full"})}),e.jsx("div",{className:"relative flex justify-start",children:e.jsx("span",{className:"bg-gray-50 pr-2",children:s.label})})]})},"separator"):e.jsx(O,{page:s,selectedPages:o,handleCheckboxChange:v,getPageType:M,hasSlug:k,currentOwnerId:m[(s==null?void 0:s.primaryPage)||(s==null?void 0:s.id)]}))})]})}),e.jsxs(h.DialogFooter,{className:"mt-10 flex items-center justify-center",children:[o.length>0&&e.jsxs("span",{className:"text-center text-sm text-muted-foreground",children:[o.length," Page",o.length!==1?"s":""," Selected"]}),e.jsx(h.Button,{disabled:u,variant:"outline",onClick:l,children:"Cancel"}),e.jsx(h.Button,{disabled:u||T||t.isEmpty(o),onClick:q,children:u?"Publishing...":"Publish Selected"})]})]})};exports.default=G;
@@ -1,11 +1,11 @@
1
1
  import { jsxs as n, jsx as t, Fragment as H } from "react/jsx-runtime";
2
- import { LanguageSelector as z } from "./page-manager-search-and-filter-CuAn82Db.js";
3
- import { al as R, am as _, A as L, au as $, f as K, h as Q, aj as J, T as A, t as V } from "./index-zaGKeGBW.js";
2
+ import { LanguageSelector as z } from "./page-manager-search-and-filter-CJ4AK1_7.js";
3
+ import { ak as R, al as _, A as L, at as $, f as K, h as Q, ai as J, T as A, t as V } from "./index-Djepisz3.js";
4
4
  import { useQuery as W } from "@tanstack/react-query";
5
5
  import { DialogContent as X, DialogHeader as Y, DialogTitle as Z, DialogDescription as ee, DialogFooter as te, Button as F } from "@chaibuilder/sdk/ui";
6
6
  import { find as G, filter as a, map as y, includes as P, orderBy as b, isEmpty as se, first as le, uniq as U, concat as ne } from "lodash-es";
7
7
  import { Lock as ae, GlobeIcon as re, File as ce, Edit as oe } from "lucide-react";
8
- import { useState as j, useCallback as ie, useMemo as g, useEffect as O } from "react";
8
+ import { useState as O, useCallback as ie, useMemo as g, useEffect as j } from "react";
9
9
  const de = () => {
10
10
  const s = R(), d = _();
11
11
  return W({
@@ -54,7 +54,7 @@ const de = () => {
54
54
  isPending: d,
55
55
  publishPage: N
56
56
  }) => {
57
- const [h] = $(), [o, u] = j([]), i = K(), [r, x] = j(i), { data: k, isFetching: C } = de(), { data: m } = Q(), w = ie((e) => {
57
+ const [h] = $(), [o, u] = O([]), i = K(), [r, x] = O(i), { data: k, isFetching: C } = de(), { data: m } = Q(), w = ie((e) => {
58
58
  var l;
59
59
  return (l = G(m, { key: e })) == null ? void 0 : l.hasSlug;
60
60
  }, [m]), f = g(
@@ -70,10 +70,10 @@ const de = () => {
70
70
  () => a(c, (e) => f.includes(e.pageType)),
71
71
  [c, f]
72
72
  );
73
- O(() => {
73
+ j(() => {
74
74
  const e = y(a(c, { online: !0 }), "id");
75
75
  u(e);
76
- }, [c]), O(() => {
76
+ }, [c]), j(() => {
77
77
  const e = Object.keys(h);
78
78
  u((l) => a(l, (p) => !P(e, p)));
79
79
  }, [h]);
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),I=require("@tanstack/react-query"),k=require("sonner"),x=require("./index-Blg1T7nL.cjs"),E=require("@chaibuilder/sdk"),c=require("@chaibuilder/sdk/ui"),C=require("lucide-react"),i=require("react"),X=require("./image-compression-DZ9WMmyn.cjs"),R=require("lodash-es"),J=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{n(t)},onError:t=>{console.error("Error saving block:",t),k.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},Z=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useQuery({staleTime:"static",queryKey:[x.ACTIONS.GET_LIBRARY_ITEM,n],enabled:!!n,queryFn:async()=>{if(!n)return null;try{return await l(s,{action:x.ACTIONS.GET_LIBRARY_ITEM,data:{id:n}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},ee=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:t}}),onSuccess:()=>{n()},onError:t=>{console.error("Error deleting block:",t),k.toast.error("Failed to delete block",{description:t instanceof Error?t.message:"Unknown error"})}})},te=({blockId:n,libBlockId:s,isOpen:l,onClose:t,blockName:m,trigger:f})=>{const[u,o]=i.useState(!1),d=E.useUpdateBlocksPropsRealtime(),b=ee(()=>{d([n],{_libBlockId:void 0}),k.toast.success("Block deleted successfully"),o(!1),t()}),p=()=>{o(!0),b.mutate(s)},g=e.jsxs(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:h=>h.preventDefault(),disabled:u,children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]});return e.jsxs(c.Popover,{open:l,onOpenChange:h=>!h&&t(),children:[e.jsx(c.PopoverTrigger,{asChild:!0,children:f||g}),e.jsx(c.PopoverContent,{className:"w-72 p-4 z-[9999]",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',m,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:u,children:"Cancel"}),e.jsx(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:p,disabled:u,children:u?"Deleting...":"Delete"})]})]})})]})},se=({blockId:n,libBlockId:s,blockName:l,size:t="sm",className:m="",close:f})=>{const[u,o]=i.useState(!1);return e.jsx(te,{blockId:n,libBlockId:s,isOpen:u,onClose:()=>{o(!1),f()},blockName:l,trigger:e.jsxs(c.Button,{type:"button",variant:"destructive",size:t,className:m,onClick:()=>o(!0),children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]})})},re=()=>{const n=x.useApiUrl(),s=x.useFetch(),l=I.useQueryClient(),{data:t=[],isLoading:m,error:f}=I.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await s(n,{action:"GET_LIBRARY_GROUPS"})||[]}catch(d){return console.error("Error fetching library groups:",d),[]}}}),{mutateAsync:u,isPending:o}=I.useMutation({mutationFn:async d=>{if(!d.trim())throw new Error("Group name is required");return s(n,{action:"CREATE_BLOCK_GROUP",data:{name:d}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),k.toast.success("Group created successfully")},onError:d=>{console.error("Error creating group:",d),k.toast.error("Failed to create group",{description:d instanceof Error?d.message:"Unknown error"})}});return{groups:t,isLoading:m,error:f,createGroup:u,isCreating:o}},ne=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),[m,f]=i.useState(""),u=i.useRef(null),{groups:o}=re(),[d,b]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),p=i.useMemo(()=>[...o,...d.filter(r=>!o.some(j=>j.id===r.id))],[o,d]),g=()=>{const r=m.trim();if(!r)return;const j={id:r,name:r};b(w=>[...w,j]),s(j.id),f(""),t(!1)};i.useEffect(()=>{l&&u.current&&u.current.focus()},[l]);const h=r=>{r.key==="Enter"&&(r.preventDefault(),g())};return i.useEffect(()=>{n&&!p.some(r=>r.id===n)&&s("")},[n,p,s]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Input,{ref:u,placeholder:"Enter new group name",value:m,onChange:r=>f(r.target.value),onKeyDown:h}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(c.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:n,onChange:r=>s(r.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(r=>e.jsx("option",{value:r.id,children:r.name},`lib-${r.id}`))}),d.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:d.filter(r=>!o.some(j=>j.id===r.id)).map(r=>e.jsx("option",{value:r.id,children:r.name},`local-${r.id}`))})]}),e.jsx(c.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(C.Plus,{className:"h-4 w-4"})})]})},ae=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),m=i.useRef(null),f=i.useCallback(async d=>{var p;const b=(p=d.target.files)==null?void 0:p[0];if(b)try{t(!0);let g=b;b.type.startsWith("image/")&&(g=await X.compressImageIfNeeded(b));const h=new FileReader;h.onloadend=()=>{s(h.result),t(!1)},h.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),k.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[s]),u=()=>{s(""),m.current&&(m.current.value="")},o=()=>{var d;(d=m.current)==null||d.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(c.Input,{type:"file",ref:m,onChange:f,accept:"image/*",className:"hidden"}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(C.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),n&&e.jsx(c.Button,{type:"button",variant:"outline",size:"icon",onClick:u,children:e.jsx(C.X,{className:"h-4 w-4"})})]}),n&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:n,alt:"Preview",className:"h-full w-full object-contain"})})]})},oe=n=>{const{blocks:s,close:l,blockId:t}=n,{getPartailBlocks:m}=E.usePartailBlocksStore(),f=s.find(a=>a._id===t),u=f==null?void 0:f._libBlockId,o=!!u,d=i.useMemo(()=>s.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[s]),b=i.useMemo(()=>{let a=[];for(const y of s)if(y._type==="PartialBlock"||y._type==="GlobalBlock"){let v=m(y.partialBlockId);y._parent&&(v==null?void 0:v.length)>0&&(v=v.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",y._parent),T))),a=[...a,...v]}else a.push(y);return a},[s,m]),[p,g]=i.useState(""),[h,r]=i.useState(""),[j,w]=i.useState(""),[S,_]=i.useState(""),[N,A]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=E.usePermissions(),Q=Y(x.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=E.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),k.toast.success("Block delinked from library"),l()},{data:B,isLoading:P,isError:G}=Z(u);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{B&&!P&&(g(B.name||""),r(B.group||""),w(B.description||""),_(B.preview||""),F(!1))},[B,P]),i.useEffect(()=>{const a=p.trim().length>=2,y=h.trim()!=="";M(a&&y)},[p,h]);const W=()=>{const a={};return p.trim()?p.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",h||(a.group="Group is required"),A(a),Object.keys(a).length===0},{resetLibrary:$}=E.useLibraryBlocks({id:""}),U=J(a=>{o||D([t],{_libBlockId:a.id}),k.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const y=b.map(v=>(R.has(v,"_libBlockId")&&delete v._libBlockId,v));U.mutate({name:p.trim(),group:h,blocks:y,description:j.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:u}:{}})},L=U.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(c.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[d&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(C.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(c.Input,{id:"name",placeholder:"Enter block name",value:p,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ne,{value:h,onChange:r}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(c.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:j,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(ae,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(se,{blockId:t,libBlockId:u,blockName:p,className:"mr-auto",close:l}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(c.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=oe;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),I=require("@tanstack/react-query"),k=require("sonner"),x=require("./index-BELYt0c9.cjs"),E=require("@chaibuilder/sdk"),c=require("@chaibuilder/sdk/ui"),C=require("lucide-react"),i=require("react"),X=require("./image-compression-DZ9WMmyn.cjs"),R=require("lodash-es"),J=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{n(t)},onError:t=>{console.error("Error saving block:",t),k.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},Z=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useQuery({staleTime:"static",queryKey:[x.ACTIONS.GET_LIBRARY_ITEM,n],enabled:!!n,queryFn:async()=>{if(!n)return null;try{return await l(s,{action:x.ACTIONS.GET_LIBRARY_ITEM,data:{id:n}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},ee=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:t}}),onSuccess:()=>{n()},onError:t=>{console.error("Error deleting block:",t),k.toast.error("Failed to delete block",{description:t instanceof Error?t.message:"Unknown error"})}})},te=({blockId:n,libBlockId:s,isOpen:l,onClose:t,blockName:m,trigger:f})=>{const[u,o]=i.useState(!1),d=E.useUpdateBlocksPropsRealtime(),b=ee(()=>{d([n],{_libBlockId:void 0}),k.toast.success("Block deleted successfully"),o(!1),t()}),p=()=>{o(!0),b.mutate(s)},g=e.jsxs(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:h=>h.preventDefault(),disabled:u,children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]});return e.jsxs(c.Popover,{open:l,onOpenChange:h=>!h&&t(),children:[e.jsx(c.PopoverTrigger,{asChild:!0,children:f||g}),e.jsx(c.PopoverContent,{className:"w-72 p-4 z-[9999]",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',m,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:u,children:"Cancel"}),e.jsx(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:p,disabled:u,children:u?"Deleting...":"Delete"})]})]})})]})},se=({blockId:n,libBlockId:s,blockName:l,size:t="sm",className:m="",close:f})=>{const[u,o]=i.useState(!1);return e.jsx(te,{blockId:n,libBlockId:s,isOpen:u,onClose:()=>{o(!1),f()},blockName:l,trigger:e.jsxs(c.Button,{type:"button",variant:"destructive",size:t,className:m,onClick:()=>o(!0),children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]})})},re=()=>{const n=x.useApiUrl(),s=x.useFetch(),l=I.useQueryClient(),{data:t=[],isLoading:m,error:f}=I.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await s(n,{action:"GET_LIBRARY_GROUPS"})||[]}catch(d){return console.error("Error fetching library groups:",d),[]}}}),{mutateAsync:u,isPending:o}=I.useMutation({mutationFn:async d=>{if(!d.trim())throw new Error("Group name is required");return s(n,{action:"CREATE_BLOCK_GROUP",data:{name:d}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),k.toast.success("Group created successfully")},onError:d=>{console.error("Error creating group:",d),k.toast.error("Failed to create group",{description:d instanceof Error?d.message:"Unknown error"})}});return{groups:t,isLoading:m,error:f,createGroup:u,isCreating:o}},ne=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),[m,f]=i.useState(""),u=i.useRef(null),{groups:o}=re(),[d,b]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),p=i.useMemo(()=>[...o,...d.filter(r=>!o.some(j=>j.id===r.id))],[o,d]),g=()=>{const r=m.trim();if(!r)return;const j={id:r,name:r};b(w=>[...w,j]),s(j.id),f(""),t(!1)};i.useEffect(()=>{l&&u.current&&u.current.focus()},[l]);const h=r=>{r.key==="Enter"&&(r.preventDefault(),g())};return i.useEffect(()=>{n&&!p.some(r=>r.id===n)&&s("")},[n,p,s]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Input,{ref:u,placeholder:"Enter new group name",value:m,onChange:r=>f(r.target.value),onKeyDown:h}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(c.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:n,onChange:r=>s(r.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(r=>e.jsx("option",{value:r.id,children:r.name},`lib-${r.id}`))}),d.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:d.filter(r=>!o.some(j=>j.id===r.id)).map(r=>e.jsx("option",{value:r.id,children:r.name},`local-${r.id}`))})]}),e.jsx(c.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(C.Plus,{className:"h-4 w-4"})})]})},ae=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),m=i.useRef(null),f=i.useCallback(async d=>{var p;const b=(p=d.target.files)==null?void 0:p[0];if(b)try{t(!0);let g=b;b.type.startsWith("image/")&&(g=await X.compressImageIfNeeded(b));const h=new FileReader;h.onloadend=()=>{s(h.result),t(!1)},h.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),k.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[s]),u=()=>{s(""),m.current&&(m.current.value="")},o=()=>{var d;(d=m.current)==null||d.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(c.Input,{type:"file",ref:m,onChange:f,accept:"image/*",className:"hidden"}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(C.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),n&&e.jsx(c.Button,{type:"button",variant:"outline",size:"icon",onClick:u,children:e.jsx(C.X,{className:"h-4 w-4"})})]}),n&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:n,alt:"Preview",className:"h-full w-full object-contain"})})]})},oe=n=>{const{blocks:s,close:l,blockId:t}=n,{getPartailBlocks:m}=E.usePartailBlocksStore(),f=s.find(a=>a._id===t),u=f==null?void 0:f._libBlockId,o=!!u,d=i.useMemo(()=>s.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[s]),b=i.useMemo(()=>{let a=[];for(const y of s)if(y._type==="PartialBlock"||y._type==="GlobalBlock"){let v=m(y.partialBlockId);y._parent&&(v==null?void 0:v.length)>0&&(v=v.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",y._parent),T))),a=[...a,...v]}else a.push(y);return a},[s,m]),[p,g]=i.useState(""),[h,r]=i.useState(""),[j,w]=i.useState(""),[S,_]=i.useState(""),[N,A]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=E.usePermissions(),Q=Y(x.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=E.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),k.toast.success("Block delinked from library"),l()},{data:B,isLoading:P,isError:G}=Z(u);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{B&&!P&&(g(B.name||""),r(B.group||""),w(B.description||""),_(B.preview||""),F(!1))},[B,P]),i.useEffect(()=>{const a=p.trim().length>=2,y=h.trim()!=="";M(a&&y)},[p,h]);const W=()=>{const a={};return p.trim()?p.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",h||(a.group="Group is required"),A(a),Object.keys(a).length===0},{resetLibrary:$}=E.useLibraryBlocks({id:""}),U=J(a=>{o||D([t],{_libBlockId:a.id}),k.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const y=b.map(v=>(R.has(v,"_libBlockId")&&delete v._libBlockId,v));U.mutate({name:p.trim(),group:h,blocks:y,description:j.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:u}:{}})},L=U.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(c.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[d&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(C.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(c.Input,{id:"name",placeholder:"Enter block name",value:p,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ne,{value:h,onChange:r}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(c.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:j,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(ae,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(se,{blockId:t,libBlockId:u,blockName:p,className:"mr-auto",close:l}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(c.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=oe;
@@ -1,7 +1,7 @@
1
1
  import { jsx as e, jsxs as i } from "react/jsx-runtime";
2
2
  import { useMutation as U, useQuery as z, useQueryClient as se } from "@tanstack/react-query";
3
3
  import { toast as B } from "sonner";
4
- import { al as L, am as G, A as _, as as ie } from "./index-zaGKeGBW.js";
4
+ import { ak as L, al as G, A as _, ar as ie } from "./index-Djepisz3.js";
5
5
  import { useUpdateBlocksPropsRealtime as K, usePartailBlocksStore as oe, usePermissions as le, useLibraryBlocks as ce } from "@chaibuilder/sdk";
6
6
  import { Button as b, Popover as de, PopoverTrigger as ue, PopoverContent as me, Input as D, Label as P } from "@chaibuilder/sdk/ui";
7
7
  import { Trash2 as Y, Plus as pe, ImageIcon as he, X as fe, AlertCircle as ge } from "lucide-react";