@chaibuilder/pages 0.15.6 → 0.15.8

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 (63) hide show
  1. package/dist/{2AITGKQY-BnzAO102.cjs → 2AITGKQY-BGvx_OEz.cjs} +1 -1
  2. package/dist/{2AITGKQY-tXLat8E2.js → 2AITGKQY-CCad8XK8.js} +2 -2
  3. package/dist/{NCMVHL6D-DooF4Fqf.cjs → NCMVHL6D-C_u5lHQe.cjs} +1 -1
  4. package/dist/{NCMVHL6D-BwDANa-N.js → NCMVHL6D-Iv9ufIUy.js} +2 -2
  5. package/dist/{ZDWCUMSJ-DiH9kc7o.cjs → ZDWCUMSJ-BqZPKNlU.cjs} +1 -1
  6. package/dist/{ZDWCUMSJ-DWeYRRkj.js → ZDWCUMSJ-DT4dg62a.js} +1 -1
  7. package/dist/{add-new-language-page-DZhjVBBf.js → add-new-language-page-CfH8Ernl.js} +2 -2
  8. package/dist/{add-new-language-page-BCUrfgTy.cjs → add-new-language-page-DlQjzp--.cjs} +1 -1
  9. package/dist/{add-new-page-DWHANcUx.cjs → add-new-page-DH-nv7ae.cjs} +1 -1
  10. package/dist/{add-new-page-DYuuentN.js → add-new-page-DX1aQA56.js} +1 -1
  11. package/dist/{delete-page-1dSWwUBg.js → delete-page-DE-nabXs.js} +1 -1
  12. package/dist/{delete-page-m-Cuz7rG.cjs → delete-page-WPGzECyJ.cjs} +1 -1
  13. package/dist/{digital-asset-manager-By_JTIbb.cjs → digital-asset-manager-CGLE6VEW.cjs} +1 -1
  14. package/dist/{digital-asset-manager-BWZlrwFf.js → digital-asset-manager-DtWIJGhf.js} +1 -1
  15. package/dist/{duplicate-page-fUuBTAs7.js → duplicate-page-C1r3iBDY.js} +2 -2
  16. package/dist/{duplicate-page-Dzs8ya8l.cjs → duplicate-page-CByLwz0z.cjs} +1 -1
  17. package/dist/{dynamic-page-selector-X2qgdiNQ.js → dynamic-page-selector-Bk8_xgFx.js} +1 -1
  18. package/dist/{dynamic-page-selector-CwhL4z6F.cjs → dynamic-page-selector-GwGV0Q6Z.cjs} +1 -1
  19. package/dist/{index-0cMGDekp.cjs → index-BELYt0c9.cjs} +2 -2
  20. package/dist/{index-Bk8tPO5R.js → index-Djepisz3.js} +15 -15
  21. package/dist/index.cjs +1 -1
  22. package/dist/index.js +1 -1
  23. package/dist/{json-diff-viewer-Cfa9BjZ6.cjs → json-diff-viewer-BUhKwjf9.cjs} +1 -1
  24. package/dist/{json-diff-viewer-Cm84g19X.js → json-diff-viewer-zKpzQFxw.js} +1 -1
  25. package/dist/{lang-panel-CkSfJqr8.cjs → lang-panel-BYF6aLAt.cjs} +1 -1
  26. package/dist/{lang-panel-CaSKOJ8G.js → lang-panel-CtpuO-KH.js} +2 -2
  27. package/dist/{mark-as-template-CwsW86Zv.js → mark-as-template-0kikl0oL.js} +1 -1
  28. package/dist/{mark-as-template-Ci82hbOm.cjs → mark-as-template-wRAGJGtp.cjs} +1 -1
  29. package/dist/{no-language-page-content-DDz81nqg.js → no-language-page-content-B1M_x_U7.js} +1 -1
  30. package/dist/{no-language-page-content-CPt4aPy9.cjs → no-language-page-content-DX9WXKXs.cjs} +1 -1
  31. package/dist/{page-creator-Dr566_Yf.js → page-creator-BDJ6iDX9.js} +2 -2
  32. package/dist/{page-creator-Cd2LrG4u.cjs → page-creator-DuN5JD41.cjs} +1 -1
  33. package/dist/{page-lock-request-ECxkQMdS.js → page-lock-request-Bc_vwJhy.js} +1 -1
  34. package/dist/{page-lock-request-Bw_Wye1t.cjs → page-lock-request-PRQo0DDm.cjs} +1 -1
  35. package/dist/{page-locked-by-dialog-CnkVUpjt.js → page-locked-by-dialog-DiKNpVwH.js} +1 -1
  36. package/dist/{page-locked-by-dialog-AbutJT_V.cjs → page-locked-by-dialog-Dk0G2l7a.cjs} +1 -1
  37. package/dist/{page-manager-new-DkqNLZ5C.js → page-manager-new-CUHqC9Og.js} +2 -2
  38. package/dist/{page-manager-new-DLMvOata.cjs → page-manager-new-KBhn93Yd.cjs} +1 -1
  39. package/dist/{page-manager-search-and-filter-B98nz9xS.js → page-manager-search-and-filter-CJ4AK1_7.js} +1 -1
  40. package/dist/{page-manager-search-and-filter-CfEfWFeo.cjs → page-manager-search-and-filter-Ck5_TfNx.cjs} +1 -1
  41. package/dist/{page-revisions-content-D12GEp8C.cjs → page-revisions-content-Cw2cumYS.cjs} +1 -1
  42. package/dist/{page-revisions-content-CBQPYFZI.js → page-revisions-content-q1Ch2-IQ.js} +2 -2
  43. package/dist/{publish-pages-content-LNCr9tKv.cjs → publish-pages-content-B8Uuw29Q.cjs} +1 -1
  44. package/dist/{publish-pages-content-BF5yMo_L.js → publish-pages-content-DEHD8qkl.js} +2 -2
  45. package/dist/{save-to-lib-C1B6tWEF.cjs → save-to-lib-B83ZH4XX.cjs} +1 -1
  46. package/dist/{save-to-lib-SpilaoOL.js → save-to-lib-QEOpf_Bd.js} +1 -1
  47. package/dist/{seo-panel-sbYoo746.js → seo-panel-DEQfOfZs.js} +1 -1
  48. package/dist/{seo-panel-DkgkJUT6.cjs → seo-panel-DvDEatlO.cjs} +1 -1
  49. package/dist/server.cjs +1 -1
  50. package/dist/server.js +114 -112
  51. package/dist/{shared-json-ld-D_YyVPk3.js → shared-json-ld-Cyv9JitF.js} +35 -34
  52. package/dist/{shared-json-ld-CEUgLAev.cjs → shared-json-ld-D5F8RuF2.cjs} +1 -1
  53. package/dist/{slug-input-Cqj9EBju.cjs → slug-input-3vWL9FPC.cjs} +1 -1
  54. package/dist/{slug-input-Df-BG6xl.js → slug-input-D4e2anEs.js} +1 -1
  55. package/dist/{theme-panel-footer-Ca1UF5DA.cjs → theme-panel-footer-4dbLfEph.cjs} +1 -1
  56. package/dist/{theme-panel-footer-B6leVWSV.js → theme-panel-footer-D3Gub87c.js} +1 -1
  57. package/dist/{unmark-as-template-Cho9B4RN.js → unmark-as-template-BENGNo7g.js} +1 -1
  58. package/dist/{unmark-as-template-BOE-nKOb.cjs → unmark-as-template-Dkc7zLZr.cjs} +1 -1
  59. package/dist/{unpublish-page-BcxxZ8pr.cjs → unpublish-page-Cui0tgvd.cjs} +1 -1
  60. package/dist/{unpublish-page-Dr4qbwUx.js → unpublish-page-D5tWKVLY.js} +1 -1
  61. package/dist/{web-preview-Cq82TNaS.js → web-preview-CHNZZcqH.js} +1 -1
  62. package/dist/{web-preview-ued-fdxs.cjs → web-preview-CcPTcMio.cjs} +1 -1
  63. package/package.json +3 -3
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("./index-0cMGDekp.cjs"),N=require("./use-page-expand-manager-2KjeYfVS.cjs"),m=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),w=require("@tanstack/react-query"),r=require("lodash-es"),d=require("lucide-react"),C=require("react"),S=({selectedPageType:l,setSelectedPageType:i})=>{const{t:a}=m.useTranslation(),[n,o]=C.useState(""),{data:c}=j.usePageTypes(),h=t=>{if(!n)return!0;const x=n.toLowerCase(),p=g=>String(r.get(t,g,"")).toLowerCase().includes(x);return p("name")||p("key")},u=c.find(t=>t.key===l);return e.jsxs(s.Select,{onValueChange:i,value:l,children:[e.jsx(s.SelectTrigger,{className:`${l==="all"?"bg-gray-100/30 hover:bg-gray-100":"gap-x-1 border bg-gray-100/30 hover:bg-gray-100"} h-9 w-max min-w-[150px] overflow-hidden whitespace-nowrap rounded p-0 px-2 py-1 text-xs text-gray-600 shadow-none ring-0 focus:ring-0 [&>svg]:hidden`,children:e.jsxs("div",{className:"flex w-full items-center justify-between gap-x-1.5",children:[e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate whitespace-nowrap font-medium leading-tight",children:(u==null?void 0:u.name)||a("All")}),e.jsx(d.ListFilter,{className:`${l!=="all"?"fill-sky-50 text-sky-500":""} pointer-events-none h-4 w-4 text-muted-foreground hover:bg-blue-300`})]})}),e.jsxs(s.SelectContent,{children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white pb-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(d.Search,{strokeWidth:2,className:"absolute left-2 top-2.5 h-3.5 w-3.5 text-gray-400"}),e.jsx(s.Input,{placeholder:a("Search page types..."),className:"h-8 w-full rounded border pl-8 text-xs shadow-none",value:n,onChange:t=>o(t.target.value),onKeyDown:t=>t.stopPropagation()})]})}),e.jsx(s.SelectItem,{value:"all",children:a("All")}),!r.isEmpty(r.filter(c,t=>t.hasSlug&&h(t)))&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 border-t px-2 py-1.5 pt-2 text-xs font-semibold text-gray-500",children:a("Pages")}),r.map([...r.filter(c,t=>t.hasSlug&&h(t))].sort((t,x)=>r.get(t,"name","").localeCompare(r.get(x,"name",""))),t=>e.jsx(s.SelectItem,{value:r.get(t,"key"),children:r.get(t,"name")},r.get(t,"key")))]}),!r.isEmpty(r.filter(c,t=>!t.hasSlug&&h(t)))&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 border-t px-2 py-1.5 pt-2 text-xs font-semibold text-gray-500",children:a("Partials")}),r.map([...r.filter(c,t=>!t.hasSlug&&h(t))].sort((t,x)=>r.get(t,"name","").localeCompare(r.get(x,"name",""))),t=>e.jsx(s.SelectItem,{value:r.get(t,"key"),children:r.get(t,"name")},r.get(t,"key")))]}),r.isEmpty(r.filter(c,h))&&e.jsx("div",{className:"px-3 py-2 text-center text-sm text-gray-500",children:a("No matching page types found")})]})]})},k=({search:l,setSearch:i})=>{const{t:a}=m.useTranslation();return e.jsxs("div",{className:"relative flex h-9 flex-1 items-center gap-2 rounded-md border px-2.5",children:[e.jsx("label",{htmlFor:"page-search-input",className:"sr-only",children:a("Search Pages")}),e.jsx(d.Search,{className:`${l?"fill-sky-50 text-sky-500":""} pointer-events-none h-4 w-4 text-muted-foreground`,"aria-hidden":"true"}),e.jsx(s.Input,{id:"page-search-input",placeholder:a("Search pages"),value:l,onChange:n=>i(n.target.value),className:"border-none px-1.5 shadow-none outline-none ring-0 transition-none focus:outline-none focus:ring-0 focus-visible:ring-0",autoComplete:"off"})]})},T=({pages:l})=>{const{t:i}=m.useTranslation(),{expandAll:a,collapseAll:n,expandedPages:o}=N.usePageExpandManager(null);return e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"outline",size:"icon",onClick:()=>a(l),className:"rounded p-1 text-gray-500",children:e.jsx(d.ChevronsUpDown,{})})}),e.jsx(s.TooltipContent,{children:i("Expand All")})]}),e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{disabled:o.length===0,variant:"outline",size:"icon",onClick:()=>n(),className:"rounded p-1 text-gray-500",children:e.jsx(d.ChevronsDownUp,{})})}),e.jsx(s.TooltipContent,{children:i("Collapse All")})]})]})},y=({languages:l,selectedLanguage:i,setSelectedLanguage:a})=>{const n=j.useFallbackLang();return e.jsx("div",{className:"scrollbar-hide flex gap-1 overflow-x-auto pb-1",children:l.map(o=>e.jsxs(s.Button,{variant:i===o?"default":"outline",size:"sm",className:`h-6 flex-shrink-0 whitespace-nowrap rounded px-3 text-xs font-normal ${i===o?"bg-black text-white hover:bg-black":"text-gray-500"}`,onClick:()=>a(o.toLowerCase()),children:[o===n&&e.jsx(d.Star,{size:4,className:`p-0.5 ${i===n?"fill-white":"fill-black"}`}),j.LANGUAGES[o]||""]},o))})},v=()=>{const{t:l}=m.useTranslation(),i=w.useQueryClient();return e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{size:"sm",variant:"ghost",onClick:()=>i.invalidateQueries({queryKey:[j.ACTIONS.GET_WEBSITE_PAGES]}),className:"mt-1 h-6 w-6",children:e.jsx(d.RefreshCw,{})})}),e.jsx(s.TooltipContent,{side:"bottom",children:l("Refresh pages list")})]})},E=({pages:l,search:i,setSearch:a,languages:n,onAddPage:o,selectedLanguage:c,setSelectedLanguage:h,selectedPageType:u,setSelectedPageType:t,showUntranslatedPages:x,setShowUntranslatedPages:p})=>{const{t:g}=m.useTranslation(),f=n.length>1;return e.jsxs("div",{className:"space-y-3 border-b border-b-gray-200 px-4 pb-1",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(S,{selectedPageType:u,setSelectedPageType:t}),e.jsx(k,{search:i,setSearch:a}),e.jsx(T,{pages:l}),e.jsxs(s.Button,{variant:"default",onClick:o,className:"rounded px-3 font-normal",children:[e.jsx(d.Plus,{strokeWidth:2,className:"stroke-white stroke-[3]"}),e.jsx("span",{className:"font-normal text-white",children:g("Add Page")})]}),!f&&e.jsx(v,{})]}),f?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(y,{languages:n,selectedLanguage:c,setSelectedLanguage:b=>{h(b),p(x&&(n==null?void 0:n[0])!==c)}}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[(n==null?void 0:n[0])!==c&&e.jsxs(s.Tooltip,{children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{variant:"ghost",onClick:()=>p(!x),className:"h-6 rounded px-3 py-1 text-xs font-normal",children:x?e.jsx(d.FilterXIcon,{}):e.jsx(d.Filter,{})})}),e.jsx(s.TooltipContent,{side:"bottom",children:g("Toggle Untranslated Pages")})]}),e.jsx(v,{})]})]}):e.jsx("div",{className:"flex items-center justify-between gap-2"})]})};exports.LanguageSelector=y;exports.default=E;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),j=require("./index-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-0cMGDekp.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-Cfa9BjZ6.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,5 +1,5 @@
1
1
  import { jsxs as n, Fragment as p, jsx as e } from "react/jsx-runtime";
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-Bk8tPO5R.js";
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
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
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";
@@ -46,7 +46,7 @@ const Ae = () => {
46
46
  });
47
47
  }
48
48
  });
49
- }, ke = Se(() => import("./json-diff-viewer-Cm84g19X.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" })
@@ -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-CfEfWFeo.cjs"),r=require("./index-0cMGDekp.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,6 +1,6 @@
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-B98nz9xS.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-Bk8tPO5R.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";
@@ -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-0cMGDekp.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 { ak as L, al as G, A as _, ar as ie } from "./index-Bk8tPO5R.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";
@@ -1,5 +1,5 @@
1
1
  import { jsx as e, jsxs as s } from "react/jsx-runtime";
2
- import { g as ye, al as ve, ak as xe, A as Ne, L as Z, ap as we, aF as Se, aG as De, d as be, ar as Oe, aH as Le, aI as Ie, aJ as T, aK as Ce, aw as ee } from "./index-Bk8tPO5R.js";
2
+ import { g as ye, al as ve, ak as xe, A as Ne, L as Z, ap as we, aF as Se, aG as De, d as be, ar as Oe, aH as Le, aI as Ie, aJ as T, aK as Ce, aw as ee } from "./index-Djepisz3.js";
3
3
  import { useLanguages as z, useTranslation as ke, useSidebarActivePanel as Te, usePermissions as Ee } from "@chaibuilder/sdk";
4
4
  import { find as Fe, get as h, isEqual as te, isEmpty as je } from "lodash-es";
5
5
  import { useMemo as Re, useRef as ae, useState as j, useEffect as se } from "react";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-0cMGDekp.cjs"),P=require("@chaibuilder/sdk"),d=require("lodash-es"),v=require("react"),a=require("@chaibuilder/sdk/ui"),L=require("sonner"),ce=require("@tanstack/react-query"),K=require("lucide-react"),M=require("./get-seo-defaults-Cw7vFt-B.cjs"),de=()=>{const{selectedLang:t}=P.useLanguages(),{data:x,isFetching:u}=i.useLanguagePages();return{data:v.useMemo(()=>d.find(x,{lang:t||""})||{},[x,t]),isFetching:u}},ue=()=>{var p;const x=(p=document.getElementById("canvas-iframe").contentDocument)==null?void 0:p.body.innerHTML;if(!x)return null;const c=new DOMParser().parseFromString(x,"text/html");c.querySelectorAll("style, script, link, svg, [data-block-type='PartialBlock']").forEach(g=>g.remove()),c.querySelectorAll("*").forEach(g=>{Array.from(g.attributes).forEach(m=>g.removeAttribute(m.name))});const r=c.querySelectorAll("h1, h2, h3, h4, h5, h6, p");return Array.from(r).map(g=>`<${g.tagName.toLowerCase()}>${g.innerHTML}</${g.tagName.toLowerCase()}>`).join(" ").replace(/<p>Partial block. Double click to edit.<\/p>/,"")},F=({keyword:t,onComplete:x,field:u})=>{const c=i.useFetch(),r=i.useApiUrl(),{selectedLang:N,fallbackLang:p}=P.useLanguages(),{mutate:g,isPending:m}=ce.useMutation({mutationFn:async()=>{const D=ue();return await c(r,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:u,lang:N||p,pageContent:D,keyword:t}})},onSuccess:D=>{x({fieldValue:D.field})},onError:D=>{x({fieldValue:null,error:D.message})}});return e.jsx(a.Button,{disabled:m,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>g(),children:m?e.jsx(K.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(K.Wand2Icon,{className:"text-yellow-500"})})},ge=({isOpen:t,onClose:x,onSave:u,onDiscard:c,isSaving:r=!1,fromLanguage:N,toLanguage:p})=>{const g=i.LANGUAGES[N]||N,m=i.LANGUAGES[p]||p;return e.jsx(a.Dialog,{open:t,onOpenChange:x,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Unsaved SEO Changes"}),e.jsxs(a.DialogDescription,{children:['You have unsaved changes in the SEO for "',g,'" version. Do you want to save these changes before switching to "',m,'" version?']})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(a.Button,{variant:"outline",onClick:c,disabled:r,children:"Discard Changes"}),e.jsx(a.Button,{onClick:u,disabled:r,children:r?"Saving...":"Save & Switch"})]})]})})},me=t=>{if(!t)return!0;try{return JSON.parse(t),!0}catch{return!1}},he=(t,x)=>{const u=t.selectionStart||0,c=t.selectionEnd||0,r=t.value,N=r.substring(0,u),p=r.substring(c),g=`{{${x}}}`,m=N+""+g+p,D=u+0+g.length;return{value:m,newCursorPos:D}},Q=()=>{const{t}=P.useTranslation(),[,x]=P.useSidebarActivePanel(),{data:u}=i.useCurrentPage(),{data:c}=i.useBuilderPageData(),{data:r,isFetching:N}=de(),p=r==null?void 0:r.seo,g=v.useRef(null),[m,D]=v.useState("seo"),R=u==null?void 0:u.id,W=u==null?void 0:u.pageType,I=i.usePageType(W),{selectedLang:$,fallbackLang:X}=P.useLanguages(),h=$||X,[H,J]=v.useState(!1),[Z,_]=v.useState(!1),[ee,V]=v.useState(!1),[S,U]=v.useState(null),[n,w]=v.useState({keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"{}",metaOther:"{}",...p}),E=v.useRef({}),{mutate:se,isPending:q}=i.useUpdatePage(),f=q||H||Z,{hasPermission:te}=P.usePermissions(),o=te(i.PAGES_PERMISSIONS.EDIT_SEO),[ae]=i.usePagesProps(),ne=d.get(ae,"features.canResetSeoToDefault",!1),z=!$||n.jsonLD!=="{}";v.useEffect(()=>{if(!N&&p&&R){const s={keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",metaOther:"",...p};w(s),E.current[h]=s}},[N,p,h,R]),v.useEffect(()=>{const s=l=>{const{fromLang:b,toLang:A,switchHandler:y}=l.detail,G=E.current[h];(G?!d.isEqual(G,n):!1)?(U({fromLang:b,toLang:A,switchHandler:y}),V(!0)):y()};return window.addEventListener("seo-language-switch-check",s),()=>{window.removeEventListener("seo-language-switch-check",s)}},[R,n,h]);const oe=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,keyword:d.get(s,"seo.keyword",""),title:d.get(s,"seo.title",""),description:d.get(s,"seo.description",""),cononicalUrl:d.get(s,"seo.canonicalUrl",""),noIndex:d.get(s,"seo.noIndex",!1),noFollow:d.get(s,"seo.noFollow",!1),ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription","")};w(l),L.toast.success(t("SEO fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset SEO fields")),console.error("Reset SEO error:",s)}finally{J(!1)}},le=async()=>{if(!(!I||!h))try{_(!0);const s=M.getSeoDefaults(I,h),l={...n,jsonLD:d.get(s,"seo.jsonLD","")};w(l),L.toast.success(t("JSON-LD reset to default"))}catch(s){L.toast.error(t("Failed to reset JSON-LD")),console.error("Reset JSON-LD error:",s)}finally{_(!1)}},re=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription",""),ogImage:d.get(s,"seo.ogImage",""),ogImageId:d.get(s,"seo.ogImageId",""),metaOther:d.get(s,"seo.metaOther","{}")};w(l),L.toast.success(t("Meta Tag fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset Meta Tag fields")),console.error("Reset Meta Tag error:",s)}finally{J(!1)}},Y=async()=>{se({id:r==null?void 0:r.id,seo:n,primaryPage:R},{onSuccess:()=>{console.log("SEO & JSON-LD updated successfully",n),E.current[h]=n,L.toast.success("SEO & JSON-LD updated successfully")}})},O=(s,l)=>{const b=document.getElementById(l);if(b){const{value:A,newCursorPos:y}=he(b,s);g.current={id:l,position:y},b.tagName.toLowerCase()==="input"?(b.value=A,w(C=>({...C,[b.name]:A})),b.focus(),b.setSelectionRange(y,y),[0,10,50,100,200].forEach(C=>{setTimeout(()=>{const B=document.getElementById(l);B&&(B.focus(),B.setSelectionRange(y,y))},C)})):(w(T=>({...T,[b.name]:A})),requestAnimationFrame(()=>{const T=document.getElementById(l);T&&(T.focus(),T.setSelectionRange(y,y),setTimeout(()=>{const C=document.getElementById(l);C&&(C.focus(),C.setSelectionRange(y,y))},50))}))}},j=s=>{const l={...n,[s.target.name]:s.target.name==="noIndex"||s.target.name==="noFollow"?s.target.checked:s.target.value};w(l)},k=s=>l=>{d.isEmpty(l.fieldValue)||j({target:{name:s,value:typeof l.fieldValue=="string"?l.fieldValue.replace(/^"(.*)"$/,"$1"):l.fieldValue}}),l.error&&L.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to generate:"}),e.jsx("p",{children:l.error})]}))},ie=()=>{const s=d.get(u,"seo.jsonLD","{}");if((s==null?void 0:s.trim())==="{}"){L.toast.error("Default page JSON-LD is empty");return}j({target:{name:"jsonLD",value:s}})};return e.jsxs("div",{className:"relative flex h-full flex-col","data-panel-id":"seo",children:[!o&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center backdrop-blur-sm",children:e.jsx(a.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:e.jsx(a.AlertDescription,{children:t("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),e.jsxs("div",{className:"no-scrollbar flex-grow overflow-y-auto px-2 pb-20",children:[e.jsxs("div",{className:"mb-4 flex w-full items-center justify-between rounded-md bg-gray-100 px-2 py-1 text-left text-sm",children:[e.jsxs("span",{children:[e.jsx("div",{className:"font-medium",children:r==null?void 0:r.name}),e.jsx("span",{className:"font-mono text-xs leading-tight text-gray-500",children:r==null?void 0:r.slug})]}),e.jsx(i.LanguageSwitcher,{variant:"outline",showAdd:!1})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(a.Tabs,{value:m,onValueChange:D,className:"w-full",children:[e.jsxs(a.TabsList,{className:"mb-4 grid w-full grid-cols-3",children:[e.jsx(a.TabsTrigger,{value:"seo",children:t("SEO")}),e.jsx(a.TabsTrigger,{value:"opengraph",children:t("Meta Tags")}),e.jsx(a.TabsTrigger,{value:"jsonld",children:t("JSON-LD")})]}),e.jsx("div",{className:m==="seo"?"":"sr-only",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"keyword",children:t("Keyword")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"keyword")})]}),e.jsx(a.Input,{type:"text",id:"keyword",name:"keyword",value:n.keyword,onChange:j,disabled:f||!o,placeholder:t("Enter keyword"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("SEO Title")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("title"),field:"title"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"title")})]})]}),e.jsx(a.Input,{type:"text",id:"title",name:"title",value:n.title,onChange:j,disabled:f||!o,placeholder:t("Enter SEO title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"description",children:t("SEO Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("description"),field:"description"}),o&&e.jsx(i.NestedPathSelector,{data:c??{},onSelect:s=>O(s,"description")})]})]}),e.jsx(a.Textarea,{id:"description",name:"description",rows:5,value:n.description,onChange:j,disabled:f||!o,placeholder:t("Enter SEO description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("Canonical URL")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"canonicalUrl")})]}),e.jsx(a.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:n.canonicalUrl,onChange:j,disabled:f||!o,placeholder:t("Enter Canonical URL"),readOnly:!o})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:n.noIndex,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Index")})]}),e.jsx("p",{className:"mt-0 text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to index this page.")})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:n.noFollow,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Follow")})]}),e.jsx("p",{className:"text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to follow links on this page.")})]})]})}),e.jsx("div",{className:m==="opengraph"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"mb-4 font-semibold text-slate-700",children:t("Open Graph")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogTitle",children:t("OG Title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogTitle"),field:"ogTitle"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogTitle")})]})]}),e.jsx(a.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:n.ogTitle,onChange:j,disabled:f||!o,placeholder:t("Enter OG title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogDescription",children:t("OG Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogDescription"),field:"ogDescription"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogDescription")})]})]}),e.jsx(a.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:n.ogDescription,onChange:j,disabled:f||!o,placeholder:t("Enter OG description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogImage",children:t("OG Image")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>{w({...n,ogImage:`{{${s}}}`,ogImageId:""})}})]}),e.jsx(i.ImagePicker,{assetId:n.ogImageId,assetUrl:n.ogImage,onChange:s=>{w({...n,ogImage:s.url,ogImageId:s.id})},disabled:f||!o,placeholder:t("Select OG image"),className:"mb-2"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"metaOther",children:t("Meta Tags")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("metaOther"),field:"metaOther"})})]}),e.jsx(i.SmartJsonInput,{id:"metaOther",value:n.metaOther,onChange:s=>{j({target:{name:"metaOther",value:s}})},placeholder:t("Enter Meta Tags JSON"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:8,handleFieldInsert:O})]})]})]})})}),e.jsx("div",{className:m==="jsonld"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"jsonLD",children:t("JSON-LD")}),z&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("jsonLD"),field:"jsonLD"})})]}),e.jsx("div",{className:"hidden",children:JSON.stringify(c)}),e.jsx(i.SmartJsonInput,{id:"jsonLD",value:n.jsonLD,onChange:s=>{j({target:{name:"jsonLD",value:s}})},placeholder:t("Enter JSON-LD"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:12,handleFieldInsert:O,hasJsonLdForSelectedLang:z,copyJsonLDFromDefaultPage:ie})]})})})]})})]}),o&&e.jsxs("div",{className:"fixed bottom-0 left-0 right-0 flex w-full flex-shrink-0 items-center justify-between border-t bg-background p-4",children:[ne?e.jsx(a.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{m==="jsonld"?le():m==="opengraph"?re():oe()},disabled:f||!o||!I,children:t(H?"Resetting...":`Reset to ${m==="jsonld"?"Default JSON-LD":m==="opengraph"?"Default Open Graph":"Default SEO"}`)}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(a.Button,{onClick:Y,disabled:!me(n==null?void 0:n.jsonLD)||(E.current[h]?d.isEqual(E.current[h],n):!1)||f||!o,children:t(q?"Saving...":"Save")}),e.jsx(a.Button,{variant:"link",className:"text-gray-500 hover:text-gray-700",onClick:()=>x("outline"),children:t("Cancel")})]})]}),e.jsx(ge,{isOpen:ee,onClose:()=>{V(!1),U(null)},onSave:async()=>{S&&(await Y(),S.switchHandler(),V(!1),U(null))},onDiscard:()=>{if(S){const s=E.current[h];s&&w(s),S.switchHandler(),V(!1),U(null)}},isSaving:q,fromLanguage:(S==null?void 0:S.fromLang)||h,toLanguage:(S==null?void 0:S.toLang)||""})]})};Q.displayName="SeoPanel";exports.default=Q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-BELYt0c9.cjs"),P=require("@chaibuilder/sdk"),d=require("lodash-es"),v=require("react"),a=require("@chaibuilder/sdk/ui"),L=require("sonner"),ce=require("@tanstack/react-query"),K=require("lucide-react"),M=require("./get-seo-defaults-Cw7vFt-B.cjs"),de=()=>{const{selectedLang:t}=P.useLanguages(),{data:x,isFetching:u}=i.useLanguagePages();return{data:v.useMemo(()=>d.find(x,{lang:t||""})||{},[x,t]),isFetching:u}},ue=()=>{var p;const x=(p=document.getElementById("canvas-iframe").contentDocument)==null?void 0:p.body.innerHTML;if(!x)return null;const c=new DOMParser().parseFromString(x,"text/html");c.querySelectorAll("style, script, link, svg, [data-block-type='PartialBlock']").forEach(g=>g.remove()),c.querySelectorAll("*").forEach(g=>{Array.from(g.attributes).forEach(m=>g.removeAttribute(m.name))});const r=c.querySelectorAll("h1, h2, h3, h4, h5, h6, p");return Array.from(r).map(g=>`<${g.tagName.toLowerCase()}>${g.innerHTML}</${g.tagName.toLowerCase()}>`).join(" ").replace(/<p>Partial block. Double click to edit.<\/p>/,"")},F=({keyword:t,onComplete:x,field:u})=>{const c=i.useFetch(),r=i.useApiUrl(),{selectedLang:N,fallbackLang:p}=P.useLanguages(),{mutate:g,isPending:m}=ce.useMutation({mutationFn:async()=>{const D=ue();return await c(r,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:u,lang:N||p,pageContent:D,keyword:t}})},onSuccess:D=>{x({fieldValue:D.field})},onError:D=>{x({fieldValue:null,error:D.message})}});return e.jsx(a.Button,{disabled:m,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>g(),children:m?e.jsx(K.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(K.Wand2Icon,{className:"text-yellow-500"})})},ge=({isOpen:t,onClose:x,onSave:u,onDiscard:c,isSaving:r=!1,fromLanguage:N,toLanguage:p})=>{const g=i.LANGUAGES[N]||N,m=i.LANGUAGES[p]||p;return e.jsx(a.Dialog,{open:t,onOpenChange:x,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Unsaved SEO Changes"}),e.jsxs(a.DialogDescription,{children:['You have unsaved changes in the SEO for "',g,'" version. Do you want to save these changes before switching to "',m,'" version?']})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(a.Button,{variant:"outline",onClick:c,disabled:r,children:"Discard Changes"}),e.jsx(a.Button,{onClick:u,disabled:r,children:r?"Saving...":"Save & Switch"})]})]})})},me=t=>{if(!t)return!0;try{return JSON.parse(t),!0}catch{return!1}},he=(t,x)=>{const u=t.selectionStart||0,c=t.selectionEnd||0,r=t.value,N=r.substring(0,u),p=r.substring(c),g=`{{${x}}}`,m=N+""+g+p,D=u+0+g.length;return{value:m,newCursorPos:D}},Q=()=>{const{t}=P.useTranslation(),[,x]=P.useSidebarActivePanel(),{data:u}=i.useCurrentPage(),{data:c}=i.useBuilderPageData(),{data:r,isFetching:N}=de(),p=r==null?void 0:r.seo,g=v.useRef(null),[m,D]=v.useState("seo"),R=u==null?void 0:u.id,W=u==null?void 0:u.pageType,I=i.usePageType(W),{selectedLang:$,fallbackLang:X}=P.useLanguages(),h=$||X,[H,J]=v.useState(!1),[Z,_]=v.useState(!1),[ee,V]=v.useState(!1),[S,U]=v.useState(null),[n,w]=v.useState({keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"{}",metaOther:"{}",...p}),E=v.useRef({}),{mutate:se,isPending:q}=i.useUpdatePage(),f=q||H||Z,{hasPermission:te}=P.usePermissions(),o=te(i.PAGES_PERMISSIONS.EDIT_SEO),[ae]=i.usePagesProps(),ne=d.get(ae,"features.canResetSeoToDefault",!1),z=!$||n.jsonLD!=="{}";v.useEffect(()=>{if(!N&&p&&R){const s={keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",metaOther:"",...p};w(s),E.current[h]=s}},[N,p,h,R]),v.useEffect(()=>{const s=l=>{const{fromLang:b,toLang:A,switchHandler:y}=l.detail,G=E.current[h];(G?!d.isEqual(G,n):!1)?(U({fromLang:b,toLang:A,switchHandler:y}),V(!0)):y()};return window.addEventListener("seo-language-switch-check",s),()=>{window.removeEventListener("seo-language-switch-check",s)}},[R,n,h]);const oe=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,keyword:d.get(s,"seo.keyword",""),title:d.get(s,"seo.title",""),description:d.get(s,"seo.description",""),cononicalUrl:d.get(s,"seo.canonicalUrl",""),noIndex:d.get(s,"seo.noIndex",!1),noFollow:d.get(s,"seo.noFollow",!1),ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription","")};w(l),L.toast.success(t("SEO fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset SEO fields")),console.error("Reset SEO error:",s)}finally{J(!1)}},le=async()=>{if(!(!I||!h))try{_(!0);const s=M.getSeoDefaults(I,h),l={...n,jsonLD:d.get(s,"seo.jsonLD","")};w(l),L.toast.success(t("JSON-LD reset to default"))}catch(s){L.toast.error(t("Failed to reset JSON-LD")),console.error("Reset JSON-LD error:",s)}finally{_(!1)}},re=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription",""),ogImage:d.get(s,"seo.ogImage",""),ogImageId:d.get(s,"seo.ogImageId",""),metaOther:d.get(s,"seo.metaOther","{}")};w(l),L.toast.success(t("Meta Tag fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset Meta Tag fields")),console.error("Reset Meta Tag error:",s)}finally{J(!1)}},Y=async()=>{se({id:r==null?void 0:r.id,seo:n,primaryPage:R},{onSuccess:()=>{console.log("SEO & JSON-LD updated successfully",n),E.current[h]=n,L.toast.success("SEO & JSON-LD updated successfully")}})},O=(s,l)=>{const b=document.getElementById(l);if(b){const{value:A,newCursorPos:y}=he(b,s);g.current={id:l,position:y},b.tagName.toLowerCase()==="input"?(b.value=A,w(C=>({...C,[b.name]:A})),b.focus(),b.setSelectionRange(y,y),[0,10,50,100,200].forEach(C=>{setTimeout(()=>{const B=document.getElementById(l);B&&(B.focus(),B.setSelectionRange(y,y))},C)})):(w(T=>({...T,[b.name]:A})),requestAnimationFrame(()=>{const T=document.getElementById(l);T&&(T.focus(),T.setSelectionRange(y,y),setTimeout(()=>{const C=document.getElementById(l);C&&(C.focus(),C.setSelectionRange(y,y))},50))}))}},j=s=>{const l={...n,[s.target.name]:s.target.name==="noIndex"||s.target.name==="noFollow"?s.target.checked:s.target.value};w(l)},k=s=>l=>{d.isEmpty(l.fieldValue)||j({target:{name:s,value:typeof l.fieldValue=="string"?l.fieldValue.replace(/^"(.*)"$/,"$1"):l.fieldValue}}),l.error&&L.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to generate:"}),e.jsx("p",{children:l.error})]}))},ie=()=>{const s=d.get(u,"seo.jsonLD","{}");if((s==null?void 0:s.trim())==="{}"){L.toast.error("Default page JSON-LD is empty");return}j({target:{name:"jsonLD",value:s}})};return e.jsxs("div",{className:"relative flex h-full flex-col","data-panel-id":"seo",children:[!o&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center backdrop-blur-sm",children:e.jsx(a.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:e.jsx(a.AlertDescription,{children:t("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),e.jsxs("div",{className:"no-scrollbar flex-grow overflow-y-auto px-2 pb-20",children:[e.jsxs("div",{className:"mb-4 flex w-full items-center justify-between rounded-md bg-gray-100 px-2 py-1 text-left text-sm",children:[e.jsxs("span",{children:[e.jsx("div",{className:"font-medium",children:r==null?void 0:r.name}),e.jsx("span",{className:"font-mono text-xs leading-tight text-gray-500",children:r==null?void 0:r.slug})]}),e.jsx(i.LanguageSwitcher,{variant:"outline",showAdd:!1})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(a.Tabs,{value:m,onValueChange:D,className:"w-full",children:[e.jsxs(a.TabsList,{className:"mb-4 grid w-full grid-cols-3",children:[e.jsx(a.TabsTrigger,{value:"seo",children:t("SEO")}),e.jsx(a.TabsTrigger,{value:"opengraph",children:t("Meta Tags")}),e.jsx(a.TabsTrigger,{value:"jsonld",children:t("JSON-LD")})]}),e.jsx("div",{className:m==="seo"?"":"sr-only",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"keyword",children:t("Keyword")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"keyword")})]}),e.jsx(a.Input,{type:"text",id:"keyword",name:"keyword",value:n.keyword,onChange:j,disabled:f||!o,placeholder:t("Enter keyword"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("SEO Title")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("title"),field:"title"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"title")})]})]}),e.jsx(a.Input,{type:"text",id:"title",name:"title",value:n.title,onChange:j,disabled:f||!o,placeholder:t("Enter SEO title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"description",children:t("SEO Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("description"),field:"description"}),o&&e.jsx(i.NestedPathSelector,{data:c??{},onSelect:s=>O(s,"description")})]})]}),e.jsx(a.Textarea,{id:"description",name:"description",rows:5,value:n.description,onChange:j,disabled:f||!o,placeholder:t("Enter SEO description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("Canonical URL")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"canonicalUrl")})]}),e.jsx(a.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:n.canonicalUrl,onChange:j,disabled:f||!o,placeholder:t("Enter Canonical URL"),readOnly:!o})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:n.noIndex,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Index")})]}),e.jsx("p",{className:"mt-0 text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to index this page.")})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:n.noFollow,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Follow")})]}),e.jsx("p",{className:"text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to follow links on this page.")})]})]})}),e.jsx("div",{className:m==="opengraph"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"mb-4 font-semibold text-slate-700",children:t("Open Graph")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogTitle",children:t("OG Title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogTitle"),field:"ogTitle"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogTitle")})]})]}),e.jsx(a.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:n.ogTitle,onChange:j,disabled:f||!o,placeholder:t("Enter OG title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogDescription",children:t("OG Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogDescription"),field:"ogDescription"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogDescription")})]})]}),e.jsx(a.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:n.ogDescription,onChange:j,disabled:f||!o,placeholder:t("Enter OG description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogImage",children:t("OG Image")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>{w({...n,ogImage:`{{${s}}}`,ogImageId:""})}})]}),e.jsx(i.ImagePicker,{assetId:n.ogImageId,assetUrl:n.ogImage,onChange:s=>{w({...n,ogImage:s.url,ogImageId:s.id})},disabled:f||!o,placeholder:t("Select OG image"),className:"mb-2"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"metaOther",children:t("Meta Tags")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("metaOther"),field:"metaOther"})})]}),e.jsx(i.SmartJsonInput,{id:"metaOther",value:n.metaOther,onChange:s=>{j({target:{name:"metaOther",value:s}})},placeholder:t("Enter Meta Tags JSON"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:8,handleFieldInsert:O})]})]})]})})}),e.jsx("div",{className:m==="jsonld"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"jsonLD",children:t("JSON-LD")}),z&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("jsonLD"),field:"jsonLD"})})]}),e.jsx("div",{className:"hidden",children:JSON.stringify(c)}),e.jsx(i.SmartJsonInput,{id:"jsonLD",value:n.jsonLD,onChange:s=>{j({target:{name:"jsonLD",value:s}})},placeholder:t("Enter JSON-LD"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:12,handleFieldInsert:O,hasJsonLdForSelectedLang:z,copyJsonLDFromDefaultPage:ie})]})})})]})})]}),o&&e.jsxs("div",{className:"fixed bottom-0 left-0 right-0 flex w-full flex-shrink-0 items-center justify-between border-t bg-background p-4",children:[ne?e.jsx(a.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{m==="jsonld"?le():m==="opengraph"?re():oe()},disabled:f||!o||!I,children:t(H?"Resetting...":`Reset to ${m==="jsonld"?"Default JSON-LD":m==="opengraph"?"Default Open Graph":"Default SEO"}`)}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(a.Button,{onClick:Y,disabled:!me(n==null?void 0:n.jsonLD)||(E.current[h]?d.isEqual(E.current[h],n):!1)||f||!o,children:t(q?"Saving...":"Save")}),e.jsx(a.Button,{variant:"link",className:"text-gray-500 hover:text-gray-700",onClick:()=>x("outline"),children:t("Cancel")})]})]}),e.jsx(ge,{isOpen:ee,onClose:()=>{V(!1),U(null)},onSave:async()=>{S&&(await Y(),S.switchHandler(),V(!1),U(null))},onDiscard:()=>{if(S){const s=E.current[h];s&&w(s),S.switchHandler(),V(!1),U(null)}},isSaving:q,fromLanguage:(S==null?void 0:S.fromLang)||h,toLanguage:(S==null?void 0:S.toLang)||""})]})};Q.displayName="SeoPanel";exports.default=Q;
package/dist/server.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";var I=Object.defineProperty;var O=(i,a,t)=>a in i?I(i,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[a]=t;var C=(i,a,t)=>O(i,typeof a!="symbol"?a+"":a,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("lodash-es"),B=require("@chaibuilder/runtime");let G=async i=>({...i});const M=i=>{G=i},y=async i=>{try{return await G(i)}catch(a){return console.error(a),{}}},p={},T=()=>Object.values(p),g=i=>p[i],v=(i,a)=>{p[i]={key:i,...a,hasSlug:!0}},U=(i,a)=>{p[i]={key:i,...a,hasSlug:!1}},P={};function N(i,a){c.has(P,i)&&console.warn(`Collection ${i} already registered`),P[i]={...a,id:i}}const b=()=>Object.values(P),_=i=>c.get(P,i);class R{constructor(a){this.backend=a}async upload({file:a,folderId:t,name:s},e){var o,l;return await((l=(o=this.backend).handleAssetsAction)==null?void 0:l.call(o,{action:"UPLOAD_ASSET",data:{name:s,file:a,folderId:t}},e))}async getAsset({id:a},t){var s,e;return(e=(s=this.backend).handleAssetsAction)==null?void 0:e.call(s,{action:"GET_ASSET",data:{id:a}},t)}async getAssets(a,t){var s,e;return(e=(s=this.backend).handleAssetsAction)==null?void 0:e.call(s,{action:"GET_ASSETS",data:a},t)}async deleteAsset({id:a},t){var s,e;return(e=(s=this.backend).handleAssetsAction)==null?void 0:e.call(s,{action:"DELETE_ASSET",data:{id:a}},t)}async updateAsset({id:a,file:t,description:s},e){var r,o;return(o=(r=this.backend).handleAssetsAction)==null?void 0:o.call(r,{action:"UPDATE_ASSET",data:{id:a,file:t,description:s}},e)}}class L{constructor(a){this.backend=a}async refreshToken(a){var s,e;const t=await((e=(s=this.backend).handleUsersAction)==null?void 0:e.call(s,{action:"REFRESH_TOKEN",data:a}));return t.error?{error:t.error}:t}async login({email:a,password:t}){var e,r;const s=await((r=(e=this.backend).handleUsersAction)==null?void 0:r.call(e,{action:"LOGIN",data:{email:a,password:t}}));return s.error?{error:s.error}:s}async logout(){var a,t;await((t=(a=this.backend).handleUsersAction)==null?void 0:t.call(a,{action:"LOGOUT"}))}async isUserActive(a){var s,e;return(await((e=(s=this.backend).handleUsersAction)==null?void 0:e.call(s,{action:"CHECK_USER_STATUS"},a))).success}async getUserRoleAndPermissions(a){var s,e;return await((e=(s=this.backend).handleUsersAction)==null?void 0:e.call(s,{action:"GET_ROLE_AND_PERMISSIONS"},a))}async getUserInfo(a,t){var e,r;return await((r=(e=this.backend).handleUsersAction)==null?void 0:r.call(e,{action:"GET_CHAI_USER",data:t},a))}}class H{constructor(a,t,s){C(this,"fallbackLang","");C(this,"draftMode",!1);this.backend=a,this.chaiUsers=t,this.chaiAssets=s,this._registerDefaultPageTypes(),this.chaiUsers=t??new L(this.backend),this.chaiAssets=s??new R(this.backend)}_registerDefaultPageTypes(){v("page",{name:"Static Page",icon:'<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M5 8V20H19V8H5ZM5 6H19V4H5V6ZM20 22H4C3.44772 22 3 21.5523 3 21V3C3 2.44772 3.44772 2 4 2H20C20.5523 2 21 2.44772 21 3V21C21 21.5523 20.5523 22 20 22ZM7 10H11V14H7V10ZM7 16H17V18H7V16ZM13 11H17V13H13V11Z"></path></svg>'}),U("global",{name:"Global Block",helpText:"A global block can be reused in multiple pages.",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-hash-icon lucide-hash"><line x1="4" x2="20" y1="9" y2="9"/><line x1="4" x2="20" y1="15" y2="15"/><line x1="10" x2="8" y1="3" y2="21"/><line x1="16" x2="14" y1="3" y2="21"/></svg>'})}setFallbackLang(a){if(c.isEmpty(a))throw new Error("Fallback language cannot be empty");this.fallbackLang=a}getFallbackLang(){return this.fallbackLang}setDraftMode(a){this.draftMode=a}isDraftMode(){return this.draftMode}async handle(a,t){var e,r,o,l,f,S,E,m,d,w,h;switch(a.action){case"UPLOAD_ASSET":return(e=this.chaiAssets)==null?void 0:e.upload({file:a.data.file,name:a.data.name,folderId:a.data.folderId??null,optimize:a.data.optimize??!0},t);case"GET_ASSET":return(r=this.chaiAssets)==null?void 0:r.getAsset(a.data,t);case"GET_ASSETS":return(o=this.chaiAssets)==null?void 0:o.getAssets(a.data,t);case"DELETE_ASSET":return(l=this.chaiAssets)==null?void 0:l.deleteAsset(a.data,t);case"UPDATE_ASSET":return(f=this.chaiAssets)==null?void 0:f.updateAsset(a.data,t);case"REFRESH_TOKEN":return(S=this.chaiUsers)==null?void 0:S.refreshToken(a.data);case"LOGIN":return(E=this.chaiUsers)==null?void 0:E.login(a.data);case"LOGOUT":return(m=this.chaiUsers)==null?void 0:m.logout();case"CHECK_USER_STATUS":return(d=this.chaiUsers)==null?void 0:d.isUserActive(t);case"GET_ROLE_AND_PERMISSIONS":return(w=this.chaiUsers)==null?void 0:w.getUserRoleAndPermissions(t);case"GET_CHAI_USER":return(h=this.chaiUsers)==null?void 0:h.getUserInfo(t,a.data)}if(a.action==="GET_BUILDER_PAGE_DATA"){const n=await y({lang:a.data.lang,draft:!0,inBuilder:!0}),u=g(a.data.pageType);return u?{...u.dataProvider?await u.dataProvider({lang:a.data.lang,draft:!0,inBuilder:!0,pageProps:a.data.pageProps??{}}):{},global:n}:{global:n}}if(a.action==="GET_PAGE_TYPES")return Promise.all(T().map(async n=>({key:n.key,helpText:n.helpText??"",icon:n.icon??"",dynamicSegments:n.dynamicSegments??"",dynamicSlug:n.dynamicSlug??"",hasSlug:n.hasSlug??!0,name:typeof n.name=="function"?await n.name():n.name,...c.isFunction(n.defaultTrackingInfo)?{trackingDefault:n.defaultTrackingInfo()}:{},...c.isFunction(n.defaultSeo)?{defaultSeo:n.defaultSeo()}:{},...c.isFunction(n.defaultJSONLD)?{defaultJSONLD:n.defaultJSONLD()}:{}})));if(a.action==="SEARCH_PAGE_TYPE_ITEMS"){const n=g(a.data.pageType);return n?n.search?await n.search(a.data.query):this.backend.handleAction(a,t):{error:"Page type not found"}}if(a.action==="GET_DYNAMIC_PAGES"){const n=g(a.data.pageType);return n?n.getDynamicPages?await n.getDynamicPages(a.data):[]:{error:"Page type not found"}}if(a.action==="GET_COLLECTIONS")return b().map(n=>c.omit(n,"fetch"));if(a.action==="GET_BLOCK_ASYNC_PROPS"){const n=a.data.block,u=n._type;if(u==="Repeater"&&(n!=null&&n.repeaterItems.includes("{{#"))){const A=n.repeaterItems.replace("{{#","").replace("}}",""),k=_(A);return k?await(k==null?void 0:k.fetch({block:n,pageProps:a.data.pageProps,lang:a.data.lang,draft:!0,inBuilder:!0}))??[]:[]}else{const A=B.getRegisteredChaiBlock(u);return!A||!c.isFunction(A.dataProvider)?{}:await A.dataProvider({block:n,pageProps:a.data.pageProps,lang:a.data.lang,draft:!0,inBuilder:!0})??{}}}const s=await this.backend.handleAction(a,t);return this.emit(a.action,s),s}emit(a,t){var r,o,l;if(!["CREATE_PAGE","UPDATE_PAGE","DELETE_PAGE"].includes(a))return;const s=c.get(t,"page");if(!s)return;const e=g(s.pageType);if(e)switch(a){case"CREATE_PAGE":return(r=e.onCreate)==null?void 0:r.call(e,s);case"UPDATE_PAGE":return(o=e.onUpdate)==null?void 0:o.call(e,s);case"DELETE_PAGE":return(l=e.onDelete)==null?void 0:l.call(e,s)}}async resolvePageLink(a,t){if(!c.startsWith(a,"pageType:"))return a;const s=a.split(":")[1],e=a.split(":")[2],r=g(s);return r?await this.resolveLink(r.key,e,t):a}async resolveLink(a,t,s){const e=g(a);if(!e)return"/not-found";const r=this.isDraftMode();return e.resolveLink?await e.resolveLink(t,r,s):await this.backend.handleAction({action:"GET_LINK",data:{pageType:a,id:t,draft:r,lang:s===this.getFallbackLang()?"":s}})}async getPageBySlug(a){const t=this.isDraftMode(),s={};return T().forEach(e=>{c.has(e,"dynamicSegments")&&e.dynamicSegments&&(s[e.key]=e.dynamicSegments)}),await this.backend.handleAction({action:"GET_PAGE_META",data:{slug:a,draft:t,dynamicSegments:s}})}async getFullPage(a){const t=this.isDraftMode();return await this.backend.handleAction({action:"GET_PAGE",data:{id:a,draft:t,mergePartials:!0}})}async getRevisionPage({id:a,type:t,lang:s}){const e=this.getFallbackLang()===s?"":s;return await this.backend.handleAction({action:"GET_REVISION_PAGE",data:{id:a,type:t,...e?{lang:e}:{}}})}async getSiteSettings(){const a=this.isDraftMode();return await this.backend.handleAction({action:"GET_WEBSITE_SETTINGS",data:{draft:a}})}async getPageData({blocks:a,pageType:t,pageProps:s,lang:e}){var m;const r=this.isDraftMode(),o=g(t),l=a.filter(d=>d._type==="Repeater"&&(d==null?void 0:d.repeaterItems.includes("{{#")));let f={};if(l.length>0){const d=l.map(h=>({collectionId:h.repeaterItems.replace("{{#","").replace("}}",""),block:h}));f=(await Promise.all(d.map(async({collectionId:h,block:n})=>{const u=_(h);try{const A=await(u==null?void 0:u.fetch({lang:e,draft:r,inBuilder:!1,pageProps:s,block:n}));return Promise.resolve({[`#${h}/${n._id}`]:c.get(A,"items",[])??[]})}catch{return Promise.resolve({[`#${h}/${n._id}`]:[]})}}))).reduce((h,n)=>({...h,...n}),{})}const[S,E]=await Promise.all([this.getGlobalData(e),((m=o==null?void 0:o.dataProvider)==null?void 0:m.call(o,{lang:e,draft:r,inBuilder:!1,pageProps:s}))||Promise.resolve({})]);return o?{...E,global:S,...f}:{global:S,...f}}async getGlobalData(a){return await y({lang:a,draft:this.isDraftMode(),inBuilder:!1})}async request(a){return await this.backend.handleAction(a)}}class K{constructor(a="",t=D){this.apiKey=a,this.apiUrl=t}async handleUsersAction(a,t){const s=await fetch(`${this.apiUrl}/v1/api/users`,{method:"POST",body:JSON.stringify(a),headers:{"x-chai-api-key":this.apiKey,"x-chai-auth-token":t}}),e=await s.json();return c.has(e,"error")?{...e,status:s.status}:e}async handleAction(a,t){const s=await fetch(`${this.apiUrl}/v1/api/chai`,{method:"POST",body:JSON.stringify(a),headers:{"x-chai-api-key":this.apiKey,"x-chai-auth-token":t}}),e=await s.json();return c.has(e,"error")?{...e,status:s.status}:e}async handleAssetsAction(a,t){return await(await fetch(`${this.apiUrl}/v1/api/assets`,{method:"POST",body:JSON.stringify(a),headers:{"x-chai-api-key":this.apiKey,"x-chai-auth-token":t}})).json()}}const x={ab:"Abkhazian",aa:"Afar",af:"Afrikaans",ak:"Akan",sq:"Albanian",am:"Amharic",ar:"Arabic",an:"Aragonese",hy:"Armenian",as:"Assamese",av:"Avaric",ae:"Avestan",ay:"Aymara",az:"Azerbaijani",bm:"Bambara",ba:"Bashkir",eu:"Basque",be:"Belarusian",bn:"Bengali",bh:"Bihari",bi:"Bislama",bs:"Bosnian",br:"Breton",bg:"Bulgarian",my:"Burmese",ca:"Catalan",ch:"Chamorro",ce:"Chechen",ny:"Chichewa",zh:"Chinese","zh-Hans":"Chinese (Simplified)","zh-Hant":"Chinese (Traditional)",cv:"Chuvash",kw:"Cornish",co:"Corsican",cr:"Cree",hr:"Croatian",cs:"Czech",da:"Danish",dv:"Maldivian",nl:"Dutch",dz:"Dzongkha",en:"English",eo:"Esperanto",et:"Estonian",ee:"Ewe",fo:"Faroese",fj:"Fijian",fi:"Finnish",fr:"French",ff:"Fula, Pular",gl:"Galician",gd:"Gaelic (Scottish)",gv:"Manx",ka:"Georgian",de:"German",el:"Greek",kl:"Kalaallisut",gn:"Guarani",gu:"Gujarati",ht:"Haitian Creole",ha:"Hausa",he:"Hebrew",hz:"Herero",hi:"Hindi",ho:"Hiri Motu",hu:"Hungarian",is:"Icelandic",io:"Ido",ig:"Igbo",id:"Indonesian",ia:"Interlingua",ie:"Interlingue",iu:"Inuktitut",ik:"Inupiak",ga:"Irish",it:"Italian",ja:"Japanese",jv:"Javanese",kn:"Kannada",kr:"Kanuri",ks:"Kashmiri",kk:"Kazakh",km:"Khmer",ki:"Kikuyu",rw:"Kinyarwanda",rn:"Kirundi",ky:"Kyrgyz",kv:"Komi",kg:"Kongo",ko:"Korean",ku:"Kurdish",kj:"Kwanyama",lo:"Lao",la:"Latin",lv:"Latvian",li:"Limburgish",ln:"Lingala",lt:"Lithuanian",lu:"Luga-Katanga",lg:"Luganda, Ganda",lb:"Luxembourgish",mk:"Macedonian",mg:"Malagasy",ms:"Malay",ml:"Malayalam",mt:"Maltese",mi:"Maori",mr:"Marathi",mh:"Marshallese",mo:"Moldavian",mn:"Mongolian",na:"Nauru",nv:"Navajo",ng:"Ndonga",nd:"Northern Ndebele",ne:"Nepali",no:"Norwegian",nb:"Norwegian bokmål",nn:"Norwegian nynorsk",ii:"Sichuan Yi",oc:"Occitan",oj:"Ojibwe",cu:"Old Church Slavonic",or:"Oriya",om:"Oromo",os:"Ossetian",pi:"Pāli",ps:"Pashto, Pushto",fa:"Persian (Farsi)",pl:"Polish",pt:"Portuguese",pa:"Punjabi (Eastern)",qu:"Quechua",rm:"Romansh",ro:"Romanian",ru:"Russian",se:"Sami",sm:"Samoan",sg:"Sango",sa:"Sanskrit",sr:"Serbian",sh:"Serbo-Croatian",st:"Sesotho",tn:"Setswana",sn:"Shona",sd:"Sindhi",si:"Sinhalese",ss:"Swati",sk:"Slovak",sl:"Slovenian",so:"Somali",nr:"Southern Ndebele",es:"Spanish",su:"Sundanese",sw:"Swahili (Kiswahili)",sv:"Swedish",tl:"Tagalog",ty:"Tahitian",tg:"Tajik",ta:"Tamil",tt:"Tatar",te:"Telugu",th:"Thai",bo:"Tibetan",ti:"Tigrinya",to:"Tonga",ts:"Tsonga",tr:"Turkish",tk:"Turkmen",tw:"Twi",ug:"Uyghur",uk:"Ukrainian",ur:"Urdu",uz:"Uzbek",ve:"Venda",vi:"Vietnamese",vo:"Volapük",wa:"Wallon",cy:"Welsh",wo:"Wolof",fy:"Western Frisian",xh:"Xhosa",yi:"Yiddish",yo:"Yoruba",za:"Zhuang, Chuang",zu:"Zulu"},D="https://api.chaibuilder.com";exports.API_URL=D;exports.ChaiBuilderPages=H;exports.ChaiBuilderPagesBackend=K;exports.ChaiBuilderPagesUserManagement=L;exports.LANGUAGES=x;exports.getChaiCollection=_;exports.getChaiCollections=b;exports.getChaiPageType=g;exports.getChaiPageTypes=T;exports.registerChaiCollection=N;exports.registerChaiGlobalDataProvider=M;exports.registerChaiPageType=v;exports.registerChaiPartialType=U;
1
+ "use strict";var I=Object.defineProperty;var O=(i,a,t)=>a in i?I(i,a,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[a]=t;var C=(i,a,t)=>O(i,typeof a!="symbol"?a+"":a,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("lodash-es"),B=require("@chaibuilder/runtime");let G=async i=>({...i});const M=i=>{G=i},y=async i=>{try{return await G(i)}catch(a){return console.error(a),{}}},p={},T=()=>Object.values(p),A=i=>p[i],v=(i,a)=>{p[i]={key:i,...a,hasSlug:!0}},U=(i,a)=>{p[i]={key:i,...a,hasSlug:!1}},P={};function N(i,a){c.has(P,i)&&console.warn(`Collection ${i} already registered`),P[i]={...a,id:i}}const L=()=>Object.values(P),_=i=>c.get(P,i);class R{constructor(a){this.backend=a}async upload({file:a,folderId:t,name:s},e){var o,h;return await((h=(o=this.backend).handleAssetsAction)==null?void 0:h.call(o,{action:"UPLOAD_ASSET",data:{name:s,file:a,folderId:t}},e))}async getAsset({id:a},t){var s,e;return(e=(s=this.backend).handleAssetsAction)==null?void 0:e.call(s,{action:"GET_ASSET",data:{id:a}},t)}async getAssets(a,t){var s,e;return(e=(s=this.backend).handleAssetsAction)==null?void 0:e.call(s,{action:"GET_ASSETS",data:a},t)}async deleteAsset({id:a},t){var s,e;return(e=(s=this.backend).handleAssetsAction)==null?void 0:e.call(s,{action:"DELETE_ASSET",data:{id:a}},t)}async updateAsset({id:a,file:t,description:s},e){var r,o;return(o=(r=this.backend).handleAssetsAction)==null?void 0:o.call(r,{action:"UPDATE_ASSET",data:{id:a,file:t,description:s}},e)}}class b{constructor(a){this.backend=a}async refreshToken(a){var s,e;const t=await((e=(s=this.backend).handleUsersAction)==null?void 0:e.call(s,{action:"REFRESH_TOKEN",data:a}));return t.error?{error:t.error}:t}async login({email:a,password:t}){var e,r;const s=await((r=(e=this.backend).handleUsersAction)==null?void 0:r.call(e,{action:"LOGIN",data:{email:a,password:t}}));return s.error?{error:s.error}:s}async logout(){var a,t;await((t=(a=this.backend).handleUsersAction)==null?void 0:t.call(a,{action:"LOGOUT"}))}async isUserActive(a){var s,e;return(await((e=(s=this.backend).handleUsersAction)==null?void 0:e.call(s,{action:"CHECK_USER_STATUS"},a))).success}async getUserRoleAndPermissions(a){var s,e;return await((e=(s=this.backend).handleUsersAction)==null?void 0:e.call(s,{action:"GET_ROLE_AND_PERMISSIONS"},a))}async getUserInfo(a,t){var e,r;return await((r=(e=this.backend).handleUsersAction)==null?void 0:r.call(e,{action:"GET_CHAI_USER",data:t},a))}}class H{constructor(a,t,s){C(this,"fallbackLang","");C(this,"draftMode",!1);this.backend=a,this.chaiUsers=t,this.chaiAssets=s,this._registerDefaultPageTypes(),this.chaiUsers=t??new b(this.backend),this.chaiAssets=s??new R(this.backend)}_registerDefaultPageTypes(){v("page",{name:"Static Page",icon:'<svg stroke="currentColor" fill="currentColor" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path d="M5 8V20H19V8H5ZM5 6H19V4H5V6ZM20 22H4C3.44772 22 3 21.5523 3 21V3C3 2.44772 3.44772 2 4 2H20C20.5523 2 21 2.44772 21 3V21C21 21.5523 20.5523 22 20 22ZM7 10H11V14H7V10ZM7 16H17V18H7V16ZM13 11H17V13H13V11Z"></path></svg>'}),U("global",{name:"Global Block",helpText:"A global block can be reused in multiple pages.",icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-hash-icon lucide-hash"><line x1="4" x2="20" y1="9" y2="9"/><line x1="4" x2="20" y1="15" y2="15"/><line x1="10" x2="8" y1="3" y2="21"/><line x1="16" x2="14" y1="3" y2="21"/></svg>'})}setFallbackLang(a){if(c.isEmpty(a))throw new Error("Fallback language cannot be empty");this.fallbackLang=a}getFallbackLang(){return this.fallbackLang}setDraftMode(a){this.draftMode=a}isDraftMode(){return this.draftMode}async handle(a,t){var e,r,o,h,f,m,E,S,d,w,l;switch(a.action){case"UPLOAD_ASSET":return(e=this.chaiAssets)==null?void 0:e.upload({file:a.data.file,name:a.data.name,folderId:a.data.folderId??null,optimize:a.data.optimize??!0},t);case"GET_ASSET":return(r=this.chaiAssets)==null?void 0:r.getAsset(a.data,t);case"GET_ASSETS":return(o=this.chaiAssets)==null?void 0:o.getAssets(a.data,t);case"DELETE_ASSET":return(h=this.chaiAssets)==null?void 0:h.deleteAsset(a.data,t);case"UPDATE_ASSET":return(f=this.chaiAssets)==null?void 0:f.updateAsset(a.data,t);case"REFRESH_TOKEN":return(m=this.chaiUsers)==null?void 0:m.refreshToken(a.data);case"LOGIN":return(E=this.chaiUsers)==null?void 0:E.login(a.data);case"LOGOUT":return(S=this.chaiUsers)==null?void 0:S.logout();case"CHECK_USER_STATUS":return(d=this.chaiUsers)==null?void 0:d.isUserActive(t);case"GET_ROLE_AND_PERMISSIONS":return(w=this.chaiUsers)==null?void 0:w.getUserRoleAndPermissions(t);case"GET_CHAI_USER":return(l=this.chaiUsers)==null?void 0:l.getUserInfo(t,a.data)}if(a.action==="GET_BUILDER_PAGE_DATA"){const n=await y({lang:a.data.lang,draft:!0,inBuilder:!0}),u=A(a.data.pageType);return u?{...u.dataProvider?await u.dataProvider({lang:a.data.lang,draft:!0,inBuilder:!0,pageProps:a.data.pageProps??{}}):{},global:n}:{global:n}}if(a.action==="GET_PAGE_TYPES")return Promise.all(T().map(async n=>({key:n.key,helpText:n.helpText??"",icon:n.icon??"",dynamicSegments:n.dynamicSegments??"",dynamicSlug:n.dynamicSlug??"",hasSlug:n.hasSlug??!0,name:typeof n.name=="function"?await n.name():n.name,...c.isFunction(n.defaultTrackingInfo)?{trackingDefault:n.defaultTrackingInfo()}:{},...c.isFunction(n.defaultSeo)?{defaultSeo:n.defaultSeo()}:{},...c.isFunction(n.defaultJSONLD)?{defaultJSONLD:n.defaultJSONLD()}:{}})));if(a.action==="SEARCH_PAGE_TYPE_ITEMS"){const n=A(a.data.pageType);return n?n.search?await n.search(a.data.query):this.backend.handleAction(a,t):{error:"Page type not found"}}if(a.action==="GET_DYNAMIC_PAGES"){const n=A(a.data.pageType);return n?n.getDynamicPages?await n.getDynamicPages(a.data):[]:{error:"Page type not found"}}if(a.action==="GET_COLLECTIONS")return L().map(n=>c.omit(n,"fetch"));if(a.action==="GET_BLOCK_ASYNC_PROPS"){const n=a.data.block,u=n._type;if(u==="Repeater"&&(n!=null&&n.repeaterItems.includes("{{#"))){const g=n.repeaterItems.replace("{{#","").replace("}}",""),k=_(g);return k?await(k==null?void 0:k.fetch({block:n,pageProps:a.data.pageProps,lang:a.data.lang,draft:!0,inBuilder:!0}))??[]:[]}else{const g=B.getRegisteredChaiBlock(u);return!g||!c.isFunction(g.dataProvider)?{}:await g.dataProvider({block:n,pageProps:a.data.pageProps,lang:a.data.lang,draft:!0,inBuilder:!0})??{}}}const s=await this.backend.handleAction(a,t);return this.emit(a.action,s),s}emit(a,t){var r,o,h;if(!["CREATE_PAGE","UPDATE_PAGE","DELETE_PAGE"].includes(a))return;const s=c.get(t,"page");if(!s)return;const e=A(s.pageType);if(e)switch(a){case"CREATE_PAGE":return(r=e.onCreate)==null?void 0:r.call(e,s);case"UPDATE_PAGE":return(o=e.onUpdate)==null?void 0:o.call(e,s);case"DELETE_PAGE":return(h=e.onDelete)==null?void 0:h.call(e,s)}}async resolvePageLink(a,t){if(!c.startsWith(a,"pageType:"))return a;const s=a.split(":")[1],e=a.split(":")[2],r=A(s);return r?await this.resolveLink(r.key,e,t):a}async resolveLink(a,t,s){const e=A(a);if(!e)return"/not-found";const r=this.isDraftMode();return e.resolveLink?await e.resolveLink(t,r,s):await this.backend.handleAction({action:"GET_LINK",data:{pageType:a,id:t,draft:r,lang:s===this.getFallbackLang()?"":s}})}async getPageBySlug(a){const t=this.isDraftMode(),s={};return T().forEach(e=>{c.has(e,"dynamicSegments")&&e.dynamicSegments&&(s[e.key]=e.dynamicSegments)}),await this.backend.handleAction({action:"GET_PAGE_META",data:{slug:a,draft:t,dynamicSegments:s}})}async getFullPage(a){const t=this.isDraftMode();return await this.backend.handleAction({action:"GET_PAGE",data:{id:a,draft:t,mergePartials:!0}})}async getRevisionPage({id:a,type:t,lang:s}){const e=this.getFallbackLang()===s?"":s;return await this.backend.handleAction({action:"GET_REVISION_PAGE",data:{id:a,type:t,...e?{lang:e}:{}}})}async getSiteSettings(){const a=this.isDraftMode();return await this.backend.handleAction({action:"GET_WEBSITE_SETTINGS",data:{draft:a}})}async getPageData({blocks:a,pageType:t,pageProps:s,lang:e}){var S;const r=this.isDraftMode(),o=A(t),h=a.filter(d=>d._type==="Repeater"&&(d==null?void 0:d.repeaterItems.includes("{{#")));let f={};if(h.length>0){const d=h.map(l=>({collectionId:l.repeaterItems.replace("{{#","").replace("}}",""),block:l}));f=(await Promise.all(d.map(async({collectionId:l,block:n})=>{const u=_(l);try{const g=await(u==null?void 0:u.fetch({lang:e,draft:r,inBuilder:!1,pageProps:s,block:n}));return Promise.resolve({[`#${l}/${n._id}`]:c.get(g,"items",[])??[],[`#${l}/${n._id}/totalItems`]:c.get(g,"totalItems",-1)??-1})}catch{return Promise.resolve({[`#${l}/${n._id}`]:[],[`#${l}/${n._id}/totalItems`]:-1})}}))).reduce((l,n)=>({...l,...n}),{})}const[m,E]=await Promise.all([this.getGlobalData(e),((S=o==null?void 0:o.dataProvider)==null?void 0:S.call(o,{lang:e,draft:r,inBuilder:!1,pageProps:s}))||Promise.resolve({})]);return o?{...E,global:m,...f}:{global:m,...f}}async getGlobalData(a){return await y({lang:a,draft:this.isDraftMode(),inBuilder:!1})}async request(a){return await this.backend.handleAction(a)}}class K{constructor(a="",t=D){this.apiKey=a,this.apiUrl=t}async handleUsersAction(a,t){const s=await fetch(`${this.apiUrl}/v1/api/users`,{method:"POST",body:JSON.stringify(a),headers:{"x-chai-api-key":this.apiKey,"x-chai-auth-token":t}}),e=await s.json();return c.has(e,"error")?{...e,status:s.status}:e}async handleAction(a,t){const s=await fetch(`${this.apiUrl}/v1/api/chai`,{method:"POST",body:JSON.stringify(a),headers:{"x-chai-api-key":this.apiKey,"x-chai-auth-token":t}}),e=await s.json();return c.has(e,"error")?{...e,status:s.status}:e}async handleAssetsAction(a,t){return await(await fetch(`${this.apiUrl}/v1/api/assets`,{method:"POST",body:JSON.stringify(a),headers:{"x-chai-api-key":this.apiKey,"x-chai-auth-token":t}})).json()}}const x={ab:"Abkhazian",aa:"Afar",af:"Afrikaans",ak:"Akan",sq:"Albanian",am:"Amharic",ar:"Arabic",an:"Aragonese",hy:"Armenian",as:"Assamese",av:"Avaric",ae:"Avestan",ay:"Aymara",az:"Azerbaijani",bm:"Bambara",ba:"Bashkir",eu:"Basque",be:"Belarusian",bn:"Bengali",bh:"Bihari",bi:"Bislama",bs:"Bosnian",br:"Breton",bg:"Bulgarian",my:"Burmese",ca:"Catalan",ch:"Chamorro",ce:"Chechen",ny:"Chichewa",zh:"Chinese","zh-Hans":"Chinese (Simplified)","zh-Hant":"Chinese (Traditional)",cv:"Chuvash",kw:"Cornish",co:"Corsican",cr:"Cree",hr:"Croatian",cs:"Czech",da:"Danish",dv:"Maldivian",nl:"Dutch",dz:"Dzongkha",en:"English",eo:"Esperanto",et:"Estonian",ee:"Ewe",fo:"Faroese",fj:"Fijian",fi:"Finnish",fr:"French",ff:"Fula, Pular",gl:"Galician",gd:"Gaelic (Scottish)",gv:"Manx",ka:"Georgian",de:"German",el:"Greek",kl:"Kalaallisut",gn:"Guarani",gu:"Gujarati",ht:"Haitian Creole",ha:"Hausa",he:"Hebrew",hz:"Herero",hi:"Hindi",ho:"Hiri Motu",hu:"Hungarian",is:"Icelandic",io:"Ido",ig:"Igbo",id:"Indonesian",ia:"Interlingua",ie:"Interlingue",iu:"Inuktitut",ik:"Inupiak",ga:"Irish",it:"Italian",ja:"Japanese",jv:"Javanese",kn:"Kannada",kr:"Kanuri",ks:"Kashmiri",kk:"Kazakh",km:"Khmer",ki:"Kikuyu",rw:"Kinyarwanda",rn:"Kirundi",ky:"Kyrgyz",kv:"Komi",kg:"Kongo",ko:"Korean",ku:"Kurdish",kj:"Kwanyama",lo:"Lao",la:"Latin",lv:"Latvian",li:"Limburgish",ln:"Lingala",lt:"Lithuanian",lu:"Luga-Katanga",lg:"Luganda, Ganda",lb:"Luxembourgish",mk:"Macedonian",mg:"Malagasy",ms:"Malay",ml:"Malayalam",mt:"Maltese",mi:"Maori",mr:"Marathi",mh:"Marshallese",mo:"Moldavian",mn:"Mongolian",na:"Nauru",nv:"Navajo",ng:"Ndonga",nd:"Northern Ndebele",ne:"Nepali",no:"Norwegian",nb:"Norwegian bokmål",nn:"Norwegian nynorsk",ii:"Sichuan Yi",oc:"Occitan",oj:"Ojibwe",cu:"Old Church Slavonic",or:"Oriya",om:"Oromo",os:"Ossetian",pi:"Pāli",ps:"Pashto, Pushto",fa:"Persian (Farsi)",pl:"Polish",pt:"Portuguese",pa:"Punjabi (Eastern)",qu:"Quechua",rm:"Romansh",ro:"Romanian",ru:"Russian",se:"Sami",sm:"Samoan",sg:"Sango",sa:"Sanskrit",sr:"Serbian",sh:"Serbo-Croatian",st:"Sesotho",tn:"Setswana",sn:"Shona",sd:"Sindhi",si:"Sinhalese",ss:"Swati",sk:"Slovak",sl:"Slovenian",so:"Somali",nr:"Southern Ndebele",es:"Spanish",su:"Sundanese",sw:"Swahili (Kiswahili)",sv:"Swedish",tl:"Tagalog",ty:"Tahitian",tg:"Tajik",ta:"Tamil",tt:"Tatar",te:"Telugu",th:"Thai",bo:"Tibetan",ti:"Tigrinya",to:"Tonga",ts:"Tsonga",tr:"Turkish",tk:"Turkmen",tw:"Twi",ug:"Uyghur",uk:"Ukrainian",ur:"Urdu",uz:"Uzbek",ve:"Venda",vi:"Vietnamese",vo:"Volapük",wa:"Wallon",cy:"Welsh",wo:"Wolof",fy:"Western Frisian",xh:"Xhosa",yi:"Yiddish",yo:"Yoruba",za:"Zhuang, Chuang",zu:"Zulu"},D="https://api.chaibuilder.com";exports.API_URL=D;exports.ChaiBuilderPages=H;exports.ChaiBuilderPagesBackend=K;exports.ChaiBuilderPagesUserManagement=b;exports.LANGUAGES=x;exports.getChaiCollection=_;exports.getChaiCollections=L;exports.getChaiPageType=A;exports.getChaiPageTypes=T;exports.registerChaiCollection=N;exports.registerChaiGlobalDataProvider=M;exports.registerChaiPageType=v;exports.registerChaiPartialType=U;