@chaibuilder/sdk 4.0.0-beta.8 → 4.0.0-beta.9

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 (139) hide show
  1. package/README.md +4 -5
  2. package/dist/{2SSKDMRQ-DewwiCoQ.js → 2SSKDMRQ-CdFBQR2o.js} +2 -2
  3. package/dist/{2SSKDMRQ-DHv4u_0i.cjs → 2SSKDMRQ-CuQ42ST6.cjs} +1 -1
  4. package/dist/{AP7HFJJL-cz754qhG.cjs → AP7HFJJL-DcnEb4BE.cjs} +1 -1
  5. package/dist/{AP7HFJJL-ComnZw7J.js → AP7HFJJL-bDlWX5Yx.js} +1 -1
  6. package/dist/{IconPicker-2H9IGKMS.js → IconPicker-CNwplOGy.js} +1 -1
  7. package/dist/{IconPicker-U0Z2dWeR.cjs → IconPicker-FpyYsxOf.cjs} +1 -1
  8. package/dist/STRINGS-BExFecZW.js +8 -0
  9. package/dist/STRINGS-FNnfjF5H.cjs +1 -0
  10. package/dist/{WDYDFRGG-BfRX3M58.cjs → WDYDFRGG-BxLmjulP.cjs} +1 -1
  11. package/dist/{WDYDFRGG-vy7nMYD4.js → WDYDFRGG-CWq7H6Qk.js} +2 -2
  12. package/dist/{actions-registery-CtQSSexG.cjs → actions-registery-BRgseJas.cjs} +16 -16
  13. package/dist/{actions-registery-DqrFhSMp.js → actions-registery-DRV8xywr.js} +180 -181
  14. package/dist/actions.cjs +1 -1
  15. package/dist/actions.d.ts +112 -51
  16. package/dist/actions.js +2 -2
  17. package/dist/{active-in-another-tab-5hn17Jeq.js → active-in-another-tab-C392ZWQc.js} +2 -2
  18. package/dist/{active-in-another-tab-ijahI5qu.cjs → active-in-another-tab-DEWOFgY5.cjs} +1 -1
  19. package/dist/{add-new-language-page-DmOyPy0u.js → add-new-language-page-BL2F_Cu7.js} +3 -3
  20. package/dist/{add-new-language-page-vmNKNx-e.cjs → add-new-language-page-DBWd0wDY.cjs} +1 -1
  21. package/dist/{add-new-page-XDuCkOyb.cjs → add-new-page-DYrQeKCi.cjs} +1 -1
  22. package/dist/{add-new-page-NHScAQn8.js → add-new-page-QVlyJhn9.js} +2 -2
  23. package/dist/{ai-panel-content-CHJ0JcQI.js → ai-panel-content-CCOluPtK.js} +3 -3
  24. package/dist/{ai-panel-content-BDqW16AW.cjs → ai-panel-content-DCZRBa6s.cjs} +1 -1
  25. package/dist/{ai-panel-default-lang-HeYWpbMu.cjs → ai-panel-default-lang-C3t0elrO.cjs} +2 -2
  26. package/dist/{ai-panel-default-lang-BIomgsN0.js → ai-panel-default-lang-Crz7QAxl.js} +4 -4
  27. package/dist/{ai-panel-other-lang-BMelEs3p.cjs → ai-panel-other-lang-BRkr4Te3.cjs} +1 -1
  28. package/dist/{ai-panel-other-lang-CbAgG-qX.js → ai-panel-other-lang-DIF8PYLh.js} +4 -4
  29. package/dist/{ai-prompt-input-BH8LOVT4.js → ai-prompt-input-D4dqy8L2.js} +1 -1
  30. package/dist/{ai-prompt-input-C_GG6nwq.cjs → ai-prompt-input-Ybgvrvd6.cjs} +1 -1
  31. package/dist/{ai-translation-prompt-CkHaFv5I.cjs → ai-translation-prompt-Ck12Bfl6.cjs} +1 -1
  32. package/dist/{ai-translation-prompt-DxsNw8YR.js → ai-translation-prompt-eZ4Sllva.js} +1 -1
  33. package/dist/{apply-binding-BvWfJCSZ.js → apply-binding-CLU6Xp4K.js} +77 -81
  34. package/dist/apply-binding-NvZX_rJe.cjs +1 -0
  35. package/dist/{code-editor-CGBAc-A6.js → code-editor-D45h29W1.js} +1 -1
  36. package/dist/{code-editor-GV8ibQ4h.cjs → code-editor-DH8eU4WL.cjs} +1 -1
  37. package/dist/{continue-editing-in-this-client-Da8ab_9d.js → continue-editing-in-this-client-BRrIvSrl.js} +2 -2
  38. package/dist/{continue-editing-in-this-client-DKHP0pq8.cjs → continue-editing-in-this-client-DgZ9Q18G.cjs} +1 -1
  39. package/dist/core-8lkXy4lC.cjs +1 -0
  40. package/dist/core-BvsZwF26.js +52 -0
  41. package/dist/core.cjs +1 -1
  42. package/dist/core.d.ts +147 -87
  43. package/dist/core.js +2 -2
  44. package/dist/{css-import-modal-CcZVLsF9.js → css-import-modal-BhLPzQH8.js} +1 -1
  45. package/dist/{css-import-modal-B4j26_cO.cjs → css-import-modal-C2-oVwFv.cjs} +1 -1
  46. package/dist/{delete-design-token-DzINIVtO.js → delete-design-token-D4Q5-Xql.js} +1 -1
  47. package/dist/{delete-design-token-3-WwqXMO.cjs → delete-design-token-DJSQluQ6.cjs} +1 -1
  48. package/dist/{delete-page-B7ODELqM.cjs → delete-page-BxbsKhY5.cjs} +1 -1
  49. package/dist/{delete-page-DwZDMwfI.js → delete-page-xHdZT-7c.js} +2 -2
  50. package/dist/{design-token-usage-DQf180Lg.js → design-token-usage-7wgmVSWI.js} +1 -1
  51. package/dist/{design-token-usage-Dy08kcIc.cjs → design-token-usage-KZ4pilLm.cjs} +1 -1
  52. package/dist/{digital-asset-manager-CDy9kHZO.js → digital-asset-manager-BmbVU7fX.js} +3 -3
  53. package/dist/{digital-asset-manager-C7subULa.cjs → digital-asset-manager-a1fqrQVH.cjs} +1 -1
  54. package/dist/{duplicate-page-DTnSztlr.js → duplicate-page-5uIno9Yh.js} +3 -3
  55. package/dist/{duplicate-page-CWQ9aMd9.cjs → duplicate-page-BBTxn_o1.cjs} +1 -1
  56. package/dist/{dynamic-page-selector-DJuxLcsM.cjs → dynamic-page-selector-C1ef0i2I.cjs} +1 -1
  57. package/dist/{dynamic-page-selector-DYW3ov_u.js → dynamic-page-selector-rhvhg7ol.js} +2 -2
  58. package/dist/{image-editor-DLeSST0K.js → image-editor-BXYZDa0s.js} +1 -1
  59. package/dist/{image-editor-C4H3AkZK.cjs → image-editor-rqUgAO8V.cjs} +1 -1
  60. package/dist/{index-D5d4QDq7.js → index-Be9lAaD7.js} +420 -422
  61. package/dist/index-BhqugjzS.cjs +160 -0
  62. package/dist/index-CNEEEgTV.cjs +5 -0
  63. package/dist/{index-BK0xWO1z.js → index-mjuSGlPU.js} +440 -447
  64. package/dist/{json-diff-viewer-g6SY62bl.cjs → json-diff-viewer-C9qmLiaq.cjs} +1 -1
  65. package/dist/{json-diff-viewer-BYHieVod.js → json-diff-viewer-aVwY7_hZ.js} +2 -2
  66. package/dist/{lang-panel-BG1GMn-1.js → lang-panel-BTWk23Mw.js} +3 -3
  67. package/dist/{lang-panel-Dm1eOO2J.cjs → lang-panel-Bo1ZWYfu.cjs} +1 -1
  68. package/dist/{manage-design-tokens-BdWQUHhw.js → manage-design-tokens-id8bylgO.js} +3 -3
  69. package/dist/manage-design-tokens-lUMCgjdS.cjs +1 -0
  70. package/dist/{mark-as-template-DUFnfVM3.cjs → mark-as-template-BYXBDXMv.cjs} +1 -1
  71. package/dist/{mark-as-template-D2XxagVO.js → mark-as-template-hv3WD852.js} +2 -2
  72. package/dist/{nested-path-selector-content-Wd6-Eql0.js → nested-path-selector-content-B8z90MFF.js} +1 -1
  73. package/dist/{nested-path-selector-content-CQOx2L9C.cjs → nested-path-selector-content-DgFFXcTD.cjs} +1 -1
  74. package/dist/{no-language-page-content-C11uF6hs.cjs → no-language-page-content-6Kk8UjFX.cjs} +1 -1
  75. package/dist/{no-language-page-content-BOv6TZIk.js → no-language-page-content-DMACzysm.js} +2 -2
  76. package/dist/{no-language-page-dialog-DIXyKRJq.js → no-language-page-dialog-D4n_XYUq.js} +2 -2
  77. package/dist/{no-language-page-dialog-CY5XhXsC.cjs → no-language-page-dialog-mBH-fthh.cjs} +1 -1
  78. package/dist/{page-creator-zSUFF4eT.cjs → page-creator-CGglYnYg.cjs} +1 -1
  79. package/dist/{page-creator-WX9lMrJY.js → page-creator-CgsOF0Eg.js} +3 -3
  80. package/dist/{page-lock-D9miLZjm.js → page-lock-CUCEBnJb.js} +2 -2
  81. package/dist/{page-lock-DGhR_url.cjs → page-lock-Hsi61Mk5.cjs} +1 -1
  82. package/dist/{page-locked-dialog-DTLnbfuP.cjs → page-locked-dialog-DSxbAMpt.cjs} +1 -1
  83. package/dist/{page-locked-dialog-CNCUCcvH.js → page-locked-dialog-bHvbFllT.js} +2 -2
  84. package/dist/{page-manager-new-Dd2c-Q_O.cjs → page-manager-new-CBfFl5rL.cjs} +1 -1
  85. package/dist/{page-manager-new-BFFOLh-l.js → page-manager-new-Cifc526h.js} +7 -7
  86. package/dist/{page-manager-search-and-filter-C1IWF_4d.js → page-manager-search-and-filter-CLJss6pV.js} +2 -2
  87. package/dist/{page-manager-search-and-filter-BKdQUJ2W.cjs → page-manager-search-and-filter-mEKl-UKh.cjs} +1 -1
  88. package/dist/{page-revisions-content-D0cflnj1.cjs → page-revisions-content-C95dQJyx.cjs} +1 -1
  89. package/dist/{page-revisions-content-DHapiLck.js → page-revisions-content-DvL4ya9g.js} +3 -3
  90. package/dist/pages.cjs +1 -1
  91. package/dist/pages.d.ts +146 -93
  92. package/dist/pages.js +1 -1
  93. package/dist/{publish-pages-content-BqLcnKry.cjs → publish-pages-content-B-6vSkql.cjs} +1 -1
  94. package/dist/{publish-pages-content-Bd2zJHtK.js → publish-pages-content-B8-IZW_U.js} +3 -3
  95. package/dist/render.cjs +1 -1
  96. package/dist/render.d.ts +12 -14
  97. package/dist/render.js +3 -3
  98. package/dist/{rte-widget-modal-RS8PMKOn.js → rte-widget-modal-1SbY5bcQ.js} +1 -1
  99. package/dist/{rte-widget-modal-DiB5BjH1.cjs → rte-widget-modal-CyKwtbOG.cjs} +1 -1
  100. package/dist/runtime.cjs +1 -1
  101. package/dist/runtime.d.ts +91 -77
  102. package/dist/runtime.js +57 -56
  103. package/dist/{save-to-lib--6ZXHEbC.js → save-to-lib-BKcBfjfi.js} +2 -2
  104. package/dist/{save-to-lib-BXJvaC1N.cjs → save-to-lib-BmPh_Vns.cjs} +1 -1
  105. package/dist/{selected-block-display-CUnCqXQw.js → selected-block-display-B3hHlcLA.js} +2 -2
  106. package/dist/{selected-block-display-BfpJda4h.cjs → selected-block-display-BCvTNcp2.cjs} +1 -1
  107. package/dist/{seo-panel-Bs-FcY1A.js → seo-panel-D3EyOYij.js} +2 -2
  108. package/dist/{seo-panel-CQITMfZ6.cjs → seo-panel-DVClgzX9.cjs} +1 -1
  109. package/dist/{shared-json-ld-DDXXi-Mj.cjs → shared-json-ld-BRgJTv0m.cjs} +1 -1
  110. package/dist/{shared-json-ld-7EujD341.js → shared-json-ld-DSPadwbY.js} +2 -2
  111. package/dist/{slug-input-CsVJAr7r.cjs → slug-input-B39SPBdP.cjs} +1 -1
  112. package/dist/{slug-input-DoEIq5rs.js → slug-input-C3UrwSkt.js} +1 -1
  113. package/dist/supabase-actions.cjs +1 -1
  114. package/dist/supabase-actions.js +1 -1
  115. package/dist/{take-over-request-C14kJ356.js → take-over-request-DfAlPvpE.js} +2 -2
  116. package/dist/{take-over-request-D5Oo3MPo.cjs → take-over-request-Tq9-gOCV.cjs} +1 -1
  117. package/dist/{theme-panel-footer-Dvknelm8.js → theme-panel-footer-DIy4baYU.js} +2 -2
  118. package/dist/{theme-panel-footer-Eeibz2JA.cjs → theme-panel-footer-DQzjVBBP.cjs} +1 -1
  119. package/dist/{translation-warning-modal-YlzP2XoO.js → translation-warning-modal-BHwLZZOw.js} +1 -1
  120. package/dist/{translation-warning-modal-CPzdHzqq.cjs → translation-warning-modal-Ckwt5Skc.cjs} +1 -1
  121. package/dist/types.cjs +1 -0
  122. package/dist/types.d.ts +598 -0
  123. package/dist/types.js +1 -0
  124. package/dist/{unmark-as-template-BGDwuCnv.cjs → unmark-as-template-BKA-sNZr.cjs} +1 -1
  125. package/dist/{unmark-as-template-CPJvQk7L.js → unmark-as-template-CbgifSbI.js} +2 -2
  126. package/dist/{unpublish-page-BMowW5wT.cjs → unpublish-page-BqzvOD76.cjs} +1 -1
  127. package/dist/{unpublish-page-DlFHLlmI.js → unpublish-page-DXQpAkvc.js} +2 -2
  128. package/dist/utils.d.ts +5 -5
  129. package/dist/web-blocks.cjs +1 -1
  130. package/dist/web-blocks.js +237 -237
  131. package/dist/{web-preview-BUnv3jIc.js → web-preview-DH7Yv-jg.js} +1 -1
  132. package/dist/{web-preview-D8GQHCjs.cjs → web-preview-DShy13AM.cjs} +1 -1
  133. package/package.json +6 -1
  134. package/dist/apply-binding-IsUf6UWJ.cjs +0 -1
  135. package/dist/core-Dr7QYemB.js +0 -56
  136. package/dist/core-Y0lXLwkq.cjs +0 -1
  137. package/dist/index-BRJCj7c_.cjs +0 -5
  138. package/dist/index-Bm8iS2OH.cjs +0 -160
  139. package/dist/manage-design-tokens-XWs_B6jo.cjs +0 -1
@@ -1,7 +1,7 @@
1
1
  import { jsx as e, jsxs as a, Fragment as k } from "react/jsx-runtime";
2
2
  import { B as m, z as E } from "./register-chai-top-bar-CX_JkRJn.js";
3
- import { w as g, x as b, y, S as L, z as F, A as I, B as w } from "./index-BK0xWO1z.js";
4
- import { k as j, L as T, m as $, A as B } from "./index-D5d4QDq7.js";
3
+ import { w as g, x as b, y, S as L, z as F, A as I, B as w } from "./index-mjuSGlPU.js";
4
+ import { k as j, L as T, m as $, A as B } from "./index-Be9lAaD7.js";
5
5
  import { u as G } from "./use-page-expand-manager-Cf4MUEJw.js";
6
6
  import { useQueryClient as D } from "@tanstack/react-query";
7
7
  import { isEmpty as N, filter as x, map as S, get as o } from "lodash-es";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),h=require("./register-chai-top-bar-DWTuRU53.cjs"),n=require("./index-Bm8iS2OH.cjs"),f=require("./index-BRJCj7c_.cjs"),w=require("./use-page-expand-manager-B6XTvk0E.cjs"),C=require("@tanstack/react-query"),s=require("lodash-es"),d=require("lucide-react"),S=require("react"),g=require("react-i18next"),k=({selectedPageType:l,setSelectedPageType:i})=>{const{t:a}=g.useTranslation(),[r,o]=S.useState(""),{data:c}=f.usePageTypes(),u=t=>{if(!r)return!0;const x=r.toLowerCase(),m=j=>String(s.get(t,j,"")).toLowerCase().includes(x);return m("name")||m("key")},p=c.find(t=>t.key===l);return e.jsxs(n.Select,{onValueChange:i,value:l,children:[e.jsx(n.SelectTrigger,{className:`${l==="all"?"bg-gray-100/30 hover:bg-gray-100":"gap-x-1 border bg-gray-100/30 hover:bg-gray-100"} h-9 w-max min-w-[150px] overflow-hidden whitespace-nowrap rounded p-0 px-2 py-1 text-xs text-gray-600 shadow-none ring-0 focus:ring-0 [&>svg]:hidden`,children:e.jsxs("div",{className:"flex w-full items-center justify-between gap-x-1.5",children:[e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate whitespace-nowrap font-medium leading-tight",children:(p==null?void 0:p.name)||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(n.SelectContent,{children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white pb-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(d.Search,{strokeWidth:2,className:"absolute left-2 top-2.5 h-3.5 w-3.5 text-gray-400"}),e.jsx(h.Input,{placeholder:a("Search page types..."),className:"h-8 w-full rounded border pl-8 text-xs shadow-none",value:r,onChange:t=>o(t.target.value),onKeyDown:t=>t.stopPropagation()})]})}),e.jsx(n.SelectItem,{value:"all",children:a("All")}),!s.isEmpty(s.filter(c,t=>t.hasSlug&&u(t)))&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 border-t px-2 py-1.5 pt-2 text-xs font-semibold text-gray-500",children:a("Pages")}),s.map([...s.filter(c,t=>t.hasSlug&&u(t))].sort((t,x)=>s.get(t,"name","").localeCompare(s.get(x,"name",""))),t=>e.jsx(n.SelectItem,{value:s.get(t,"key"),children:s.get(t,"name")},s.get(t,"key")))]}),!s.isEmpty(s.filter(c,t=>!t.hasSlug&&u(t)))&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 border-t px-2 py-1.5 pt-2 text-xs font-semibold text-gray-500",children:a("Partials")}),s.map([...s.filter(c,t=>!t.hasSlug&&u(t))].sort((t,x)=>s.get(t,"name","").localeCompare(s.get(x,"name",""))),t=>e.jsx(n.SelectItem,{value:s.get(t,"key"),children:s.get(t,"name")},s.get(t,"key")))]}),s.isEmpty(s.filter(c,u))&&e.jsx("div",{className:"px-3 py-2 text-center text-sm text-gray-500",children:a("No matching page types found")})]})]})},T=({search:l,setSearch:i})=>{const{t:a}=g.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(h.Input,{id:"page-search-input",placeholder:a("Search pages"),value:l,onChange:r=>i(r.target.value),className:"border-none px-1.5 shadow-none outline-none ring-0 transition-none focus:outline-none focus:ring-0 focus-visible:ring-0",autoComplete:"off"})]})},E=({pages:l})=>{const{t:i}=g.useTranslation(),{expandAll:a,collapseAll:r,expandedPages:o}=w.usePageExpandManager(null);return e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(n.Tooltip,{children:[e.jsx(n.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{variant:"outline",size:"icon",onClick:()=>a(l),className:"rounded p-1 text-gray-500",children:e.jsx(d.ChevronsUpDown,{})})}),e.jsx(n.TooltipContent,{children:i("Expand All")})]}),e.jsxs(n.Tooltip,{children:[e.jsx(n.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{disabled:o.length===0,variant:"outline",size:"icon",onClick:()=>r(),className:"rounded p-1 text-gray-500",children:e.jsx(d.ChevronsDownUp,{})})}),e.jsx(n.TooltipContent,{children:i("Collapse All")})]})]})},b=({languages:l,selectedLanguage:i,setSelectedLanguage:a})=>{const r=f.useFallbackLang();return e.jsx("div",{className:"scrollbar-hide flex gap-1 overflow-x-auto pb-1",children:l.map(o=>e.jsxs(h.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===r&&e.jsx(d.Star,{size:4,className:`p-0.5 ${i===r?"fill-white":"fill-black"}`}),f.LANGUAGES[o]||""]},o))})},y=()=>{const{t:l}=g.useTranslation(),i=C.useQueryClient();return e.jsxs(n.Tooltip,{children:[e.jsx(n.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{size:"sm",variant:"ghost",onClick:()=>i.invalidateQueries({queryKey:[f.ACTIONS.GET_WEBSITE_PAGES]}),className:"mt-1 h-6 w-6",children:e.jsx(d.RefreshCw,{})})}),e.jsx(n.TooltipContent,{side:"bottom",children:l("Refresh pages list")})]})},q=({pages:l,search:i,setSearch:a,languages:r,onAddPage:o,selectedLanguage:c,setSelectedLanguage:u,selectedPageType:p,setSelectedPageType:t,showUntranslatedPages:x,setShowUntranslatedPages:m})=>{const{t:j}=g.useTranslation(),v=r.length>1;return e.jsxs("div",{className:"space-y-3 border-b border-b-gray-200 px-4 pb-1",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(k,{selectedPageType:p,setSelectedPageType:t}),e.jsx(T,{search:i,setSearch:a}),e.jsx(E,{pages:l}),e.jsxs(h.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:j("Add Page")})]}),!v&&e.jsx(y,{})]}),v?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(b,{languages:r,selectedLanguage:c,setSelectedLanguage:N=>{u(N),m(x&&(r==null?void 0:r[0])!==c)}}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[(r==null?void 0:r[0])!==c&&e.jsxs(n.Tooltip,{children:[e.jsx(n.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{variant:"ghost",onClick:()=>m(!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(n.TooltipContent,{side:"bottom",children:j("Toggle Untranslated Pages")})]}),e.jsx(y,{})]})]}):e.jsx("div",{className:"flex items-center justify-between gap-2"})]})};exports.LanguageSelector=b;exports.default=q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),h=require("./register-chai-top-bar-DWTuRU53.cjs"),n=require("./index-BhqugjzS.cjs"),f=require("./index-CNEEEgTV.cjs"),w=require("./use-page-expand-manager-B6XTvk0E.cjs"),C=require("@tanstack/react-query"),s=require("lodash-es"),d=require("lucide-react"),S=require("react"),g=require("react-i18next"),k=({selectedPageType:l,setSelectedPageType:i})=>{const{t:a}=g.useTranslation(),[r,o]=S.useState(""),{data:c}=f.usePageTypes(),u=t=>{if(!r)return!0;const x=r.toLowerCase(),m=j=>String(s.get(t,j,"")).toLowerCase().includes(x);return m("name")||m("key")},p=c.find(t=>t.key===l);return e.jsxs(n.Select,{onValueChange:i,value:l,children:[e.jsx(n.SelectTrigger,{className:`${l==="all"?"bg-gray-100/30 hover:bg-gray-100":"gap-x-1 border bg-gray-100/30 hover:bg-gray-100"} h-9 w-max min-w-[150px] overflow-hidden whitespace-nowrap rounded p-0 px-2 py-1 text-xs text-gray-600 shadow-none ring-0 focus:ring-0 [&>svg]:hidden`,children:e.jsxs("div",{className:"flex w-full items-center justify-between gap-x-1.5",children:[e.jsx("span",{className:"max-w-[150px] overflow-hidden truncate whitespace-nowrap font-medium leading-tight",children:(p==null?void 0:p.name)||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(n.SelectContent,{children:[e.jsx("div",{className:"sticky top-0 z-10 bg-white pb-2",children:e.jsxs("div",{className:"relative",children:[e.jsx(d.Search,{strokeWidth:2,className:"absolute left-2 top-2.5 h-3.5 w-3.5 text-gray-400"}),e.jsx(h.Input,{placeholder:a("Search page types..."),className:"h-8 w-full rounded border pl-8 text-xs shadow-none",value:r,onChange:t=>o(t.target.value),onKeyDown:t=>t.stopPropagation()})]})}),e.jsx(n.SelectItem,{value:"all",children:a("All")}),!s.isEmpty(s.filter(c,t=>t.hasSlug&&u(t)))&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 border-t px-2 py-1.5 pt-2 text-xs font-semibold text-gray-500",children:a("Pages")}),s.map([...s.filter(c,t=>t.hasSlug&&u(t))].sort((t,x)=>s.get(t,"name","").localeCompare(s.get(x,"name",""))),t=>e.jsx(n.SelectItem,{value:s.get(t,"key"),children:s.get(t,"name")},s.get(t,"key")))]}),!s.isEmpty(s.filter(c,t=>!t.hasSlug&&u(t)))&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"mt-2 border-t px-2 py-1.5 pt-2 text-xs font-semibold text-gray-500",children:a("Partials")}),s.map([...s.filter(c,t=>!t.hasSlug&&u(t))].sort((t,x)=>s.get(t,"name","").localeCompare(s.get(x,"name",""))),t=>e.jsx(n.SelectItem,{value:s.get(t,"key"),children:s.get(t,"name")},s.get(t,"key")))]}),s.isEmpty(s.filter(c,u))&&e.jsx("div",{className:"px-3 py-2 text-center text-sm text-gray-500",children:a("No matching page types found")})]})]})},T=({search:l,setSearch:i})=>{const{t:a}=g.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(h.Input,{id:"page-search-input",placeholder:a("Search pages"),value:l,onChange:r=>i(r.target.value),className:"border-none px-1.5 shadow-none outline-none ring-0 transition-none focus:outline-none focus:ring-0 focus-visible:ring-0",autoComplete:"off"})]})},E=({pages:l})=>{const{t:i}=g.useTranslation(),{expandAll:a,collapseAll:r,expandedPages:o}=w.usePageExpandManager(null);return e.jsxs("div",{className:"flex gap-1",children:[e.jsxs(n.Tooltip,{children:[e.jsx(n.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{variant:"outline",size:"icon",onClick:()=>a(l),className:"rounded p-1 text-gray-500",children:e.jsx(d.ChevronsUpDown,{})})}),e.jsx(n.TooltipContent,{children:i("Expand All")})]}),e.jsxs(n.Tooltip,{children:[e.jsx(n.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{disabled:o.length===0,variant:"outline",size:"icon",onClick:()=>r(),className:"rounded p-1 text-gray-500",children:e.jsx(d.ChevronsDownUp,{})})}),e.jsx(n.TooltipContent,{children:i("Collapse All")})]})]})},b=({languages:l,selectedLanguage:i,setSelectedLanguage:a})=>{const r=f.useFallbackLang();return e.jsx("div",{className:"scrollbar-hide flex gap-1 overflow-x-auto pb-1",children:l.map(o=>e.jsxs(h.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===r&&e.jsx(d.Star,{size:4,className:`p-0.5 ${i===r?"fill-white":"fill-black"}`}),f.LANGUAGES[o]||""]},o))})},y=()=>{const{t:l}=g.useTranslation(),i=C.useQueryClient();return e.jsxs(n.Tooltip,{children:[e.jsx(n.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{size:"sm",variant:"ghost",onClick:()=>i.invalidateQueries({queryKey:[f.ACTIONS.GET_WEBSITE_PAGES]}),className:"mt-1 h-6 w-6",children:e.jsx(d.RefreshCw,{})})}),e.jsx(n.TooltipContent,{side:"bottom",children:l("Refresh pages list")})]})},q=({pages:l,search:i,setSearch:a,languages:r,onAddPage:o,selectedLanguage:c,setSelectedLanguage:u,selectedPageType:p,setSelectedPageType:t,showUntranslatedPages:x,setShowUntranslatedPages:m})=>{const{t:j}=g.useTranslation(),v=r.length>1;return e.jsxs("div",{className:"space-y-3 border-b border-b-gray-200 px-4 pb-1",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(k,{selectedPageType:p,setSelectedPageType:t}),e.jsx(T,{search:i,setSearch:a}),e.jsx(E,{pages:l}),e.jsxs(h.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:j("Add Page")})]}),!v&&e.jsx(y,{})]}),v?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[e.jsx(b,{languages:r,selectedLanguage:c,setSelectedLanguage:N=>{u(N),m(x&&(r==null?void 0:r[0])!==c)}}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[(r==null?void 0:r[0])!==c&&e.jsxs(n.Tooltip,{children:[e.jsx(n.TooltipTrigger,{asChild:!0,children:e.jsx(h.Button,{variant:"ghost",onClick:()=>m(!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(n.TooltipContent,{side:"bottom",children:j("Toggle Untranslated Pages")})]}),e.jsx(y,{})]})]}):e.jsx("div",{className:"flex items-center justify-between gap-2"})]})};exports.LanguageSelector=b;exports.default=q;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),N=require("./register-chai-top-bar-DWTuRU53.cjs"),i=require("./index-Bm8iS2OH.cjs"),c=require("./index-BRJCj7c_.cjs"),y=require("@tanstack/react-query"),v=require("date-fns"),B=require("lodash-es"),p=require("lucide-react"),g=require("react");function L(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const 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 S=L(g);function Q(s){const n=c.useApiUrl(),t=c.useFetch();return y.useQuery({queryKey:[c.ACTIONS.GET_PAGE_REVISIONS,s],queryFn:async()=>await t(n,{action:c.ACTIONS.GET_PAGE_REVISIONS,data:{pageId:s}}),enabled:!!s,refetchOnMount:!0})}const z=()=>{const s=c.useApiUrl(),n=c.useFetch(),t=y.useQueryClient();return y.useMutation({mutationFn:async l=>await n(s,{action:c.ACTIONS.DELETE_PAGE_REVISION,data:{revisionId:l}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},H=()=>{const s=c.useApiUrl(),n=c.useFetch(),t=y.useQueryClient();return y.useMutation({mutationFn:async({revisionId:l,discardCurrent:r,pageId:d})=>await n(s,{action:c.ACTIONS.RESTORE_PAGE_REVISION,data:{revisionId:l,discardCurrent:r,...d&&{pageId:d}}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},$=g.lazy(()=>Promise.resolve().then(()=>require("./json-diff-viewer-g6SY62bl.cjs"))),b=({tag:s})=>s==="draft"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-amber-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Draft"})]}):s==="live"?e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-green-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Live"})]}):s==="published"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-green-500/10 px-1.5 py-0.5 text-xs text-green-600",children:[e.jsx(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}=c.useChaiCurrentPage(),{saveState:l}=i.useSavePage(),[r]=c.usePageEditInfo();if(!t)return null;const d=!!s.find(x=>{var a;return(a=x==null?void 0:x.uid)==null?void 0:a.startsWith("draft:")}),u=s.length>=2&&!d,m=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(b,{tag:"draft"}),e.jsx("span",{className:"text-xs font-bold",children:"Currently editing"})]})}),e.jsx("div",{className:"flex items-center pl-2 text-[11px] text-muted-foreground",children:!B.isEmpty(r.lastSaved)&&e.jsxs("span",{children:["Last updated"," ",v.formatDistanceToNow(new Date(r.lastSaved),{addSuffix:!0})]})}),e.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:m?e.jsx(b,{tag:"unsaved"}):null})]}),e.jsx(A,{checked:d,disabled:u,onChange:()=>{n(d?s.filter(x=>x.uid!==`draft:${t==null?void 0:t.id}`):[...s,{uid:`draft:${t==null?void 0:t.id}`,label:"draft",item:{createdAt:Date.now()}}])}})]})}function K(){return e.jsx("div",{className:"mt-2 space-y-2",children:Array.from({length:5}).map((s,n)=>e.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(i.Skeleton,{className:"h-4 w-3/4"}),e.jsx(i.Skeleton,{className:"h-3 w-1/2"}),e.jsx(i.Skeleton,{className:"mt-1 h-5 w-20"})]}),e.jsx(i.Skeleton,{className:"h-8 w-8 rounded-full"})]},n))})}function O({revision:s,isLatest:n,onRestore:t,onDelete:l,revisionNumber:r,compare:d,setCompare:u,pageId:m}){const{data:x}=c.useChaiUserInfo(s.currentEditor),a=(x==null?void 0:x.name)||"Unknown",f=!!d.find(h=>{var j;return n?(j=h==null?void 0:h.uid)==null?void 0:j.startsWith("live"):(h==null?void 0:h.uid)===s.uid}),w=d.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(b,{tag:n?"live":`#${r}`}),s.type==="published"?"Published":"Draft"," by ",e.jsx("span",{className:"text-xs font-bold",children:a})]})}),e.jsxs("div",{className:"flex items-center gap-x-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:s.type==="published"?e.jsx(b,{tag:"published"}):e.jsx(b,{tag:"draft"})}),e.jsx("div",{className:"flex items-center text-[10px] text-muted-foreground",children:e.jsx("span",{className:"leading-tight",children:v.format(s.createdAt,"MMM d, h:mm a")})})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(c.PermissionChecker,{permissions:[c.PAGES_PERMISSIONS.RESTORE_REVISION,c.PAGES_PERMISSIONS.DELETE_REVISION],children:e.jsx(Y,{revision:s,onRestore:t,onDelete:l})})}),e.jsx(A,{checked:f,disabled:w,onChange:()=>{u(f?d.filter(h=>n?h.uid!==`live:${m}`:h.uid!==s.uid):[...d,{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]=g.useState(!1),[d,u]=s;if(s.length===0)return null;const m=({tab:x})=>e.jsxs("span",{className:"flex items-center justify-between rounded border border-blue-100 p-1 font-medium",children:[e.jsx(b,{tag:x.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(a=>a.uid!==x.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"}),d&&e.jsx(m,{tab:d}),e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"with"}),u?e.jsx(m,{tab:u}):e.jsx("span",{className:"rounded border px-1 text-xs text-muted-foreground",children:"Choose another"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pb-0.5 pt-2",children:[e.jsx(N.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none text-gray-500",variant:"outline",onClick:()=>n([]),children:e.jsx("span",{children:" Clear"})}),e.jsxs(N.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none",variant:"default",onClick:()=>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(g.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx("span",{className:"text-sm",children:"Loading diff viewer..."})}),children:e.jsx($,{open: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(i.DropdownMenu,{children:[e.jsx(i.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(N.Button,{variant:"ghost",size:"icon",className:"h-5 w-5",children:[e.jsx(p.MoreHorizontal,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More options"})]})}),e.jsxs(i.DropdownMenuContent,{align:"end",className:"text-xs",children:[e.jsx(c.PermissionChecker,{permission:c.PAGES_PERMISSIONS.RESTORE_REVISION,children:e.jsxs(i.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-sm",children:[e.jsx(p.Undo2,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Restore this version"})]})}),e.jsx(c.PermissionChecker,{permission:c.PAGES_PERMISSIONS.DELETE_REVISION,children:s.uid!=="current"&&e.jsxs(e.Fragment,{children:[e.jsx(i.DropdownMenuSeparator,{}),e.jsxs(i.DropdownMenuItem,{onClick:t,className:"cursor-pointer text-destructive",children:[e.jsx(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:d}=c.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),u=(d==null?void 0:d.name)||"Unknown";return t?e.jsx(i.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(i.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(i.DialogHeader,{children:[e.jsx(i.DialogTitle,{children:"Restore Revision"}),e.jsxs(i.DialogDescription,{children:["You are about to restore to revision ",t.uid.substring(0,8)," from"," ",v.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",u]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"How would you like to handle your current edits?"})}),e.jsxs(i.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(N.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>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(N.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:d}=c.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),u=(d==null?void 0:d.name)||"Unknown";return t?e.jsx(i.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(i.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(i.DialogHeader,{children:[e.jsx(i.DialogTitle,{children:"Delete Revision"}),e.jsxs(i.DialogDescription,{children:["You are about to delete revision ",t.uid.substring(0,8)," from"," ",v.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",u]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"This action cannot be undone. Are you sure you want to proceed?"})}),e.jsxs(i.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(N.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>n(!1),disabled:r,children:"Cancel"}),e.jsx(N.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 R,I;const[n,t]=S.useState([]),[l,r]=S.useState(null),[d,u]=S.useState(!1),[m,x]=S.useState(!1),{data:a}=c.useChaiCurrentPage(),{data:f,isFetching:w,error:h,refetch:j}=Q(a==null?void 0:a.id),{mutate:T,isPending:M}=z(),{mutate:k,isPending:F}=H(),_=y.useQueryClient(),{selectedLang:q,fallbackLang:P}=i.useLanguages(),U=q||P;g.useEffect(()=>{g.startTransition(()=>t([]))},[a==null?void 0:a.id]);const G=o=>{l&&k({revisionId:l.uid,discardCurrent:o,...l.uid==="current"&&(a==null?void 0:a.id)&&{pageId:a.id}},{onSuccess:()=>{u(!1),r(null),_.invalidateQueries({queryKey:[c.ACTIONS.GET_DRAFT_PAGE]})}})},C=o=>{r(o),u(!0)},E=o=>{r(o),x(!0)},V=()=>{l&&T(l.uid,{onSuccess:()=>{x(!1),r(null)}})};return g.useEffect(()=>{s&&j()},[s,j]),e.jsxs(e.Fragment,{children:[e.jsxs(i.SheetHeader,{children:[e.jsx(i.SheetTitle,{children:"Revision History"}),(a==null?void 0:a.createdAt)&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Page created on ",v.format(new Date(a.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),w?e.jsx(K,{}):h?e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Failed to load revisions. Please try again."}):e.jsxs("div",{className:"mt-2 flex h-full min-h-0 flex-1 flex-col space-y-2",children:[e.jsx(W,{lang:U,compare:n,setCompare:t,pageId:a==null?void 0:a.id}),e.jsx(J,{compare:n,setCompare:t}),(R=f==null?void 0:f.filter(o=>o.uid==="current"))==null?void 0:R.map((o,D)=>e.jsx(O,{pageId:a==null?void 0:a.id,revision:o,isLatest:!0,onRestore:()=>C(o),onDelete:()=>E(o),revisionNumber:D,compare:n,setCompare:t},o.uid)),e.jsx(i.ScrollArea,{className:"min-h-0 flex-1",children:e.jsx("div",{className:"space-y-2",children:(I=f==null?void 0:f.filter(o=>o.uid!=="current"))==null?void 0:I.map((o,D)=>e.jsx(O,{pageId:a==null?void 0:a.id,revision:o,isLatest:o.uid==="current",onRestore:()=>C(o),onDelete:()=>E(o),revisionNumber:D+1,compare:n,setCompare:t},o.uid))})})]}),e.jsx(X,{open:d,onOpenChange:u,revision:l,onRestore:G,isRestoring:F}),e.jsx(Z,{open:m,onOpenChange:x,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"),N=require("./register-chai-top-bar-DWTuRU53.cjs"),i=require("./index-BhqugjzS.cjs"),c=require("./index-CNEEEgTV.cjs"),y=require("@tanstack/react-query"),v=require("date-fns"),B=require("lodash-es"),p=require("lucide-react"),g=require("react");function L(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const 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 S=L(g);function Q(s){const n=c.useApiUrl(),t=c.useFetch();return y.useQuery({queryKey:[c.ACTIONS.GET_PAGE_REVISIONS,s],queryFn:async()=>await t(n,{action:c.ACTIONS.GET_PAGE_REVISIONS,data:{pageId:s}}),enabled:!!s,refetchOnMount:!0})}const z=()=>{const s=c.useApiUrl(),n=c.useFetch(),t=y.useQueryClient();return y.useMutation({mutationFn:async l=>await n(s,{action:c.ACTIONS.DELETE_PAGE_REVISION,data:{revisionId:l}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},H=()=>{const s=c.useApiUrl(),n=c.useFetch(),t=y.useQueryClient();return y.useMutation({mutationFn:async({revisionId:l,discardCurrent:r,pageId:d})=>await n(s,{action:c.ACTIONS.RESTORE_PAGE_REVISION,data:{revisionId:l,discardCurrent:r,...d&&{pageId:d}}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},$=g.lazy(()=>Promise.resolve().then(()=>require("./json-diff-viewer-C9qmLiaq.cjs"))),b=({tag:s})=>s==="draft"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-amber-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Draft"})]}):s==="live"?e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-green-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Live"})]}):s==="published"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-green-500/10 px-1.5 py-0.5 text-xs text-green-600",children:[e.jsx(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}=c.useChaiCurrentPage(),{saveState:l}=i.useSavePage(),[r]=c.usePageEditInfo();if(!t)return null;const d=!!s.find(x=>{var a;return(a=x==null?void 0:x.uid)==null?void 0:a.startsWith("draft:")}),u=s.length>=2&&!d,m=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(b,{tag:"draft"}),e.jsx("span",{className:"text-xs font-bold",children:"Currently editing"})]})}),e.jsx("div",{className:"flex items-center pl-2 text-[11px] text-muted-foreground",children:!B.isEmpty(r.lastSaved)&&e.jsxs("span",{children:["Last updated"," ",v.formatDistanceToNow(new Date(r.lastSaved),{addSuffix:!0})]})}),e.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:m?e.jsx(b,{tag:"unsaved"}):null})]}),e.jsx(A,{checked:d,disabled:u,onChange:()=>{n(d?s.filter(x=>x.uid!==`draft:${t==null?void 0:t.id}`):[...s,{uid:`draft:${t==null?void 0:t.id}`,label:"draft",item:{createdAt:Date.now()}}])}})]})}function K(){return e.jsx("div",{className:"mt-2 space-y-2",children:Array.from({length:5}).map((s,n)=>e.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(i.Skeleton,{className:"h-4 w-3/4"}),e.jsx(i.Skeleton,{className:"h-3 w-1/2"}),e.jsx(i.Skeleton,{className:"mt-1 h-5 w-20"})]}),e.jsx(i.Skeleton,{className:"h-8 w-8 rounded-full"})]},n))})}function O({revision:s,isLatest:n,onRestore:t,onDelete:l,revisionNumber:r,compare:d,setCompare:u,pageId:m}){const{data:x}=c.useChaiUserInfo(s.currentEditor),a=(x==null?void 0:x.name)||"Unknown",f=!!d.find(h=>{var j;return n?(j=h==null?void 0:h.uid)==null?void 0:j.startsWith("live"):(h==null?void 0:h.uid)===s.uid}),w=d.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(b,{tag:n?"live":`#${r}`}),s.type==="published"?"Published":"Draft"," by ",e.jsx("span",{className:"text-xs font-bold",children:a})]})}),e.jsxs("div",{className:"flex items-center gap-x-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:s.type==="published"?e.jsx(b,{tag:"published"}):e.jsx(b,{tag:"draft"})}),e.jsx("div",{className:"flex items-center text-[10px] text-muted-foreground",children:e.jsx("span",{className:"leading-tight",children:v.format(s.createdAt,"MMM d, h:mm a")})})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(c.PermissionChecker,{permissions:[c.PAGES_PERMISSIONS.RESTORE_REVISION,c.PAGES_PERMISSIONS.DELETE_REVISION],children:e.jsx(Y,{revision:s,onRestore:t,onDelete:l})})}),e.jsx(A,{checked:f,disabled:w,onChange:()=>{u(f?d.filter(h=>n?h.uid!==`live:${m}`:h.uid!==s.uid):[...d,{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]=g.useState(!1),[d,u]=s;if(s.length===0)return null;const m=({tab:x})=>e.jsxs("span",{className:"flex items-center justify-between rounded border border-blue-100 p-1 font-medium",children:[e.jsx(b,{tag:x.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(a=>a.uid!==x.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"}),d&&e.jsx(m,{tab:d}),e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"with"}),u?e.jsx(m,{tab:u}):e.jsx("span",{className:"rounded border px-1 text-xs text-muted-foreground",children:"Choose another"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pb-0.5 pt-2",children:[e.jsx(N.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none text-gray-500",variant:"outline",onClick:()=>n([]),children:e.jsx("span",{children:" Clear"})}),e.jsxs(N.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none",variant:"default",onClick:()=>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(g.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx("span",{className:"text-sm",children:"Loading diff viewer..."})}),children:e.jsx($,{open: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(i.DropdownMenu,{children:[e.jsx(i.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(N.Button,{variant:"ghost",size:"icon",className:"h-5 w-5",children:[e.jsx(p.MoreHorizontal,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More options"})]})}),e.jsxs(i.DropdownMenuContent,{align:"end",className:"text-xs",children:[e.jsx(c.PermissionChecker,{permission:c.PAGES_PERMISSIONS.RESTORE_REVISION,children:e.jsxs(i.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-sm",children:[e.jsx(p.Undo2,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Restore this version"})]})}),e.jsx(c.PermissionChecker,{permission:c.PAGES_PERMISSIONS.DELETE_REVISION,children:s.uid!=="current"&&e.jsxs(e.Fragment,{children:[e.jsx(i.DropdownMenuSeparator,{}),e.jsxs(i.DropdownMenuItem,{onClick:t,className:"cursor-pointer text-destructive",children:[e.jsx(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:d}=c.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),u=(d==null?void 0:d.name)||"Unknown";return t?e.jsx(i.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(i.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(i.DialogHeader,{children:[e.jsx(i.DialogTitle,{children:"Restore Revision"}),e.jsxs(i.DialogDescription,{children:["You are about to restore to revision ",t.uid.substring(0,8)," from"," ",v.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",u]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"How would you like to handle your current edits?"})}),e.jsxs(i.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(N.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>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(N.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:d}=c.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),u=(d==null?void 0:d.name)||"Unknown";return t?e.jsx(i.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(i.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(i.DialogHeader,{children:[e.jsx(i.DialogTitle,{children:"Delete Revision"}),e.jsxs(i.DialogDescription,{children:["You are about to delete revision ",t.uid.substring(0,8)," from"," ",v.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",u]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"This action cannot be undone. Are you sure you want to proceed?"})}),e.jsxs(i.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(N.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>n(!1),disabled:r,children:"Cancel"}),e.jsx(N.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 R,I;const[n,t]=S.useState([]),[l,r]=S.useState(null),[d,u]=S.useState(!1),[m,x]=S.useState(!1),{data:a}=c.useChaiCurrentPage(),{data:f,isFetching:w,error:h,refetch:j}=Q(a==null?void 0:a.id),{mutate:T,isPending:M}=z(),{mutate:k,isPending:F}=H(),_=y.useQueryClient(),{selectedLang:q,fallbackLang:P}=i.useLanguages(),U=q||P;g.useEffect(()=>{g.startTransition(()=>t([]))},[a==null?void 0:a.id]);const G=o=>{l&&k({revisionId:l.uid,discardCurrent:o,...l.uid==="current"&&(a==null?void 0:a.id)&&{pageId:a.id}},{onSuccess:()=>{u(!1),r(null),_.invalidateQueries({queryKey:[c.ACTIONS.GET_DRAFT_PAGE]})}})},C=o=>{r(o),u(!0)},E=o=>{r(o),x(!0)},V=()=>{l&&T(l.uid,{onSuccess:()=>{x(!1),r(null)}})};return g.useEffect(()=>{s&&j()},[s,j]),e.jsxs(e.Fragment,{children:[e.jsxs(i.SheetHeader,{children:[e.jsx(i.SheetTitle,{children:"Revision History"}),(a==null?void 0:a.createdAt)&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Page created on ",v.format(new Date(a.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),w?e.jsx(K,{}):h?e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Failed to load revisions. Please try again."}):e.jsxs("div",{className:"mt-2 flex h-full min-h-0 flex-1 flex-col space-y-2",children:[e.jsx(W,{lang:U,compare:n,setCompare:t,pageId:a==null?void 0:a.id}),e.jsx(J,{compare:n,setCompare:t}),(R=f==null?void 0:f.filter(o=>o.uid==="current"))==null?void 0:R.map((o,D)=>e.jsx(O,{pageId:a==null?void 0:a.id,revision:o,isLatest:!0,onRestore:()=>C(o),onDelete:()=>E(o),revisionNumber:D,compare:n,setCompare:t},o.uid)),e.jsx(i.ScrollArea,{className:"min-h-0 flex-1",children:e.jsx("div",{className:"space-y-2",children:(I=f==null?void 0:f.filter(o=>o.uid!=="current"))==null?void 0:I.map((o,D)=>e.jsx(O,{pageId:a==null?void 0:a.id,revision:o,isLatest:o.uid==="current",onRestore:()=>C(o),onDelete:()=>E(o),revisionNumber:D+1,compare:n,setCompare:t},o.uid))})})]}),e.jsx(X,{open:d,onOpenChange:u,revision:l,onRestore:G,isRestoring:F}),e.jsx(Z,{open:m,onOpenChange:x,revision:l,onDelete:V,isDeleting:M})]})}exports.default=ee;
@@ -1,7 +1,7 @@
1
1
  import { jsxs as a, Fragment as p, jsx as e } from "react/jsx-runtime";
2
2
  import { B as g } from "./register-chai-top-bar-CX_JkRJn.js";
3
- import { n as le, a9 as re, aa as ie, a2 as de, ab as y, Q as ce, D as q, d as G, e as j, f as L, p as z, q as $, r as oe, s as ue, t as me, v as U, ac as he } from "./index-BK0xWO1z.js";
4
- import { ar as R, as as A, A as b, aw as H, az as fe, ap as I, ax as C, ay as w } from "./index-D5d4QDq7.js";
3
+ import { n as le, a9 as re, aa as ie, a2 as de, ab as y, Q as ce, D as q, d as G, e as j, f as L, p as z, q as $, r as oe, s as ue, t as me, v as U, ac as he } from "./index-mjuSGlPU.js";
4
+ import { ar as R, as as A, A as b, aw as H, az as fe, ap as I, ax as C, ay as w } from "./index-Be9lAaD7.js";
5
5
  import { useQuery as pe, useQueryClient as O, useMutation as Q } from "@tanstack/react-query";
6
6
  import { format as D, formatDistanceToNow as xe } from "date-fns";
7
7
  import { isEmpty as ge } from "lodash-es";
@@ -50,7 +50,7 @@ const Ie = () => {
50
50
  });
51
51
  }
52
52
  });
53
- }, ke = Re(() => import("./json-diff-viewer-BYHieVod.js")), N = ({ tag: t }) => t === "draft" ? /* @__PURE__ */ a("div", { className: "flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600", children: [
53
+ }, ke = Re(() => import("./json-diff-viewer-aVwY7_hZ.js")), N = ({ tag: t }) => t === "draft" ? /* @__PURE__ */ a("div", { className: "flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600", children: [
54
54
  /* @__PURE__ */ a("span", { className: "relative flex h-2 w-2", children: [
55
55
  /* @__PURE__ */ e("span", { className: "absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75" }),
56
56
  /* @__PURE__ */ e("span", { className: "relative inline-flex h-2 w-2 rounded-full bg-amber-500" })
package/dist/pages.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-BRJCj7c_.cjs");exports.ChaiJsonInput=e.SmartJsonInput;exports.ChaiWebsiteBuilder=e.ChaiWebsiteBuilder;exports.ImagePicker=e.ImagePicker;exports.LanguageSwitcher=e.LanguageSwitcher;exports.NestedPathSelector=e.NestedPathSelector;exports.PermissionChecker=e.PermissionChecker;exports.useActivePage=e.useActivePage;exports.useApiUrl=e.useApiUrl;exports.useBuilderFetch=e.useBuilderFetch;exports.useBuilderPageData=e.useBuilderPageData;exports.useChaiAuth=e.useChaiAuth;exports.useChaiCurrentPage=e.useChaiCurrentPage;exports.useChaiUserInfo=e.useChaiUserInfo;exports.useClearAll=e.useClearAll;exports.useFallbackLang=e.useFallbackLang;exports.useFetch=e.useFetch;exports.useGotoPage=e.useGotoPage;exports.useLanguagePages=e.useLanguagePages;exports.usePageTypes=e.usePageTypes;exports.useReloadPage=e.useReloadPage;exports.useUpdateActivePageMetadata=e.useUpdateActivePageMetadata;exports.useUserPermissions=e.useUserRoleAndPermissions;exports.useWebsitePages=e.useWebsitePages;exports.useWebsiteSetting=e.useWebsiteSetting;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./index-CNEEEgTV.cjs");exports.ChaiJsonInput=e.SmartJsonInput;exports.ChaiWebsiteBuilder=e.ChaiWebsiteBuilder;exports.ImagePicker=e.ImagePicker;exports.LanguageSwitcher=e.LanguageSwitcher;exports.NestedPathSelector=e.NestedPathSelector;exports.PermissionChecker=e.PermissionChecker;exports.useActivePage=e.useActivePage;exports.useApiUrl=e.useApiUrl;exports.useBuilderFetch=e.useBuilderFetch;exports.useBuilderPageData=e.useBuilderPageData;exports.useChaiAuth=e.useChaiAuth;exports.useChaiCurrentPage=e.useChaiCurrentPage;exports.useChaiUserInfo=e.useChaiUserInfo;exports.useClearAll=e.useClearAll;exports.useFallbackLang=e.useFallbackLang;exports.useFetch=e.useFetch;exports.useGotoPage=e.useGotoPage;exports.useLanguagePages=e.useLanguagePages;exports.usePageTypes=e.usePageTypes;exports.useReloadPage=e.useReloadPage;exports.useUpdateActivePageMetadata=e.useUpdateActivePageMetadata;exports.useUserPermissions=e.useUserRoleAndPermissions;exports.useWebsitePages=e.useWebsitePages;exports.useWebsiteSetting=e.useWebsiteSetting;
package/dist/pages.d.ts CHANGED
@@ -4,7 +4,7 @@ import { ReactNode } from 'react';
4
4
  import { UseMutationResult } from '@tanstack/react-query';
5
5
  import { UseQueryResult } from '@tanstack/react-query';
6
6
 
7
- declare type AskAiResponse = {
7
+ declare type ChaiAskAiResponse = {
8
8
  blocks?: Array<{
9
9
  _id: string;
10
10
  } & Partial<ChaiBlock>>;
@@ -12,18 +12,6 @@ declare type AskAiResponse = {
12
12
  error?: any;
13
13
  };
14
14
 
15
- declare type BlocksWithDesignTokens = Record<string, string>;
16
-
17
- declare type BorderRadiusValue = false | string;
18
-
19
- declare type Breakpoint = {
20
- title: string;
21
- content: string;
22
- breakpoint: "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | string;
23
- icon: default_2.ReactNode | Element;
24
- width: number;
25
- };
26
-
27
15
  declare type ChaiBlock<T = Record<string, any>> = {
28
16
  _id: string;
29
17
  _name?: string;
@@ -33,6 +21,16 @@ declare type ChaiBlock<T = Record<string, any>> = {
33
21
  partialBlockId?: string;
34
22
  } & T;
35
23
 
24
+ declare type ChaiBlocksWithDesignTokens = Record<string, string>;
25
+
26
+ declare type ChaiBreakpoint = {
27
+ title: string;
28
+ content: string;
29
+ breakpoint: "xs" | "sm" | "md" | "lg" | "xl" | "2xl" | string;
30
+ icon: default_2.ReactNode | Element;
31
+ width: number;
32
+ };
33
+
36
34
  declare interface ChaiBuilderEditorProps {
37
35
  children?: default_2.ReactNode;
38
36
  /**
@@ -45,13 +43,7 @@ declare interface ChaiBuilderEditorProps {
45
43
  /**
46
44
  * User
47
45
  */
48
- user?: {
49
- id: string;
50
- name: string;
51
- email: string;
52
- avatar?: string;
53
- role?: string;
54
- };
46
+ user?: ChaiUserInfo;
55
47
  /**
56
48
  * Permissions
57
49
  */
@@ -67,19 +59,15 @@ declare interface ChaiBuilderEditorProps {
67
59
  /**
68
60
  * Theme presets
69
61
  */
70
- themePresets?: Record<string, Partial<ChaiThemeValues>>[];
71
- /**
72
- * Theme options
73
- */
74
- themeOptions?: (defaultThemeOptions: ChaiBuilderThemeOptions) => ChaiBuilderThemeOptions;
62
+ themePresets?: Record<string, Partial<ChaiTheme>>[];
75
63
  /**
76
64
  * Theme
77
65
  */
78
- theme?: Partial<ChaiThemeValues>;
66
+ theme?: ChaiTheme;
79
67
  /**
80
68
  * Builder theme
81
69
  */
82
- builderTheme?: ChaiThemeValues;
70
+ builderTheme?: ChaiTheme;
83
71
  /**
84
72
  * Theme panel component
85
73
  * TODO: Move to registerChaiThemePanelComponent()
@@ -118,7 +106,7 @@ declare interface ChaiBuilderEditorProps {
118
106
  /**
119
107
  * Breakpoints
120
108
  */
121
- breakpoints?: Breakpoint[];
109
+ breakpoints?: ChaiBreakpoint[];
122
110
  /**
123
111
  * Loading state
124
112
  */
@@ -130,7 +118,7 @@ declare interface ChaiBuilderEditorProps {
130
118
  /**
131
119
  * Ask AI callback
132
120
  */
133
- askAiCallBack?: (type: "styles" | "content", prompt: string, blocks: ChaiBlock[], lang: string) => Promise<AskAiResponse>;
121
+ askAiCallBack?: (type: "styles" | "content", prompt: string, blocks: ChaiBlock[], lang: string) => Promise<ChaiAskAiResponse>;
134
122
  /**
135
123
  * Get partial blocks
136
124
  * @returns {Record<string, { type: string; name: string; description?: string }>}
@@ -152,7 +140,7 @@ declare interface ChaiBuilderEditorProps {
152
140
  * onSave callback function
153
141
  * @param saveData
154
142
  */
155
- onSave?: ({ blocks, theme, autoSave }: SavePageData) => Promise<boolean | Error>;
143
+ onSave?: ({ blocks, theme, autoSave }: ChaiSavePageData) => Promise<boolean | Error>;
156
144
  /**
157
145
  * onSaveStateChange callback function
158
146
  * @param syncStatus
@@ -170,15 +158,15 @@ declare interface ChaiBuilderEditorProps {
170
158
  /**
171
159
  * Languages
172
160
  */
173
- languages?: Array<string>;
161
+ languages?: string[];
174
162
  /**
175
163
  * Page Types props
176
164
  */
177
- pageTypes?: PageType[];
165
+ pageTypes?: ChaiPageType[];
178
166
  /**
179
167
  * Search page type items
180
168
  */
181
- searchPageTypeItems?: (pageTypeKey: string, query: string) => Promise<PageTypeItem[] | Error>;
169
+ searchPageTypeItems?: (pageTypeKey: string, query: string) => Promise<Pick<ChaiPage_2, "id" | "slug" | "name">[] | Error>;
182
170
  /**
183
171
  * Collections
184
172
  */
@@ -208,23 +196,14 @@ declare interface ChaiBuilderEditorProps {
208
196
  designTokens?: boolean;
209
197
  };
210
198
  structureRules?: StructureRule[];
211
- designTokens?: DesignTokens;
212
- siteWideUsage?: SiteWideUsage;
199
+ designTokens?: ChaiDesignTokens;
200
+ siteWideUsage?: ChaiSiteWideUsageData;
213
201
  /**
214
202
  * Screen to small message component
215
203
  */
216
204
  smallScreenComponent?: ReactComponentType;
217
205
  }
218
206
 
219
- declare type ChaiBuilderThemeOptions = {
220
- fontFamily: false | Record<VariableKey, string>;
221
- borderRadius: BorderRadiusValue;
222
- colors: false | {
223
- group: string;
224
- items: Record<VariableKey, [HSLColor, HSLColor]>;
225
- }[];
226
- };
227
-
228
207
  declare type ChaiCollectoin = {
229
208
  id: string;
230
209
  name: string;
@@ -233,9 +212,122 @@ declare type ChaiCollectoin = {
233
212
  sorts?: SortOptions[];
234
213
  };
235
214
 
215
+ declare interface ChaiDesignTokens {
216
+ [uniqueId: string]: {
217
+ name: string;
218
+ value: string;
219
+ };
220
+ }
221
+
236
222
  export declare const ChaiJsonInput: React.FC<SmartJsonInputProps>;
237
223
 
238
- declare type ChaiThemeValues = {
224
+ declare type ChaiPage = {
225
+ id: string;
226
+ slug: string;
227
+ lang: string;
228
+ name: string;
229
+ pageType: string;
230
+ blocks: ChaiBlock[];
231
+ createdAt: string;
232
+ lastSaved: string;
233
+ dynamic: boolean;
234
+ online: boolean;
235
+ seo: ChaiPageSeo;
236
+ app: string;
237
+ primaryPage?: string | null;
238
+ currentEditor?: string | null;
239
+ changes: object[];
240
+ parent?: string | null;
241
+ libRefId?: string | null;
242
+ dynamicSlugCustom?: string | null;
243
+ metadata?: object;
244
+ jsonld?: object;
245
+ globalJsonLds?: string[];
246
+ links?: string;
247
+ partialBlocks?: string;
248
+ designTokens?: ChaiDesignTokens;
249
+ };
250
+
251
+ declare interface ChaiPage_2 {
252
+ id: string;
253
+ name: string;
254
+ slug: string;
255
+ pageType: string;
256
+ parent: string | null;
257
+ children?: ChaiPage_2[];
258
+ isTemplate?: boolean;
259
+ dynamic?: boolean;
260
+ [key: string]: any;
261
+ }
262
+
263
+ declare type ChaiPageProps<T = Record<string, any>> = {
264
+ slug: string;
265
+ searchParams?: Record<string, string>;
266
+ } & T;
267
+
268
+ declare type ChaiPageSeo = {
269
+ title?: string;
270
+ description?: string;
271
+ ogTitle?: string;
272
+ ogDescription?: string;
273
+ ogImage?: string;
274
+ canonicalUrl?: string;
275
+ noIndex?: boolean;
276
+ noFollow?: boolean;
277
+ jsonLD?: string;
278
+ };
279
+
280
+ declare type ChaiPageType = {
281
+ key: string;
282
+ helpText?: string;
283
+ icon?: string;
284
+ hasSlug?: boolean;
285
+ name: string | (() => Promise<string>);
286
+ dynamicSegments?: string;
287
+ dynamicSlug?: string;
288
+ getDynamicPages?: ({ query, uuid, }: {
289
+ query?: string;
290
+ uuid?: string;
291
+ }) => Promise<Pick<ChaiPage, "id" | "name" | "slug" | "primaryPage">[]>;
292
+ search?: (query: string) => Promise<Pick<ChaiPage, "id" | "name" | "slug">[] | Error>;
293
+ resolveLink?: (id: string, draft?: boolean, lang?: string) => Promise<string>;
294
+ onCreate?: (data: Partial<ChaiPage> & {
295
+ id: string;
296
+ }) => Promise<void>;
297
+ onUpdate?: (data: Partial<ChaiPage> & {
298
+ id: string;
299
+ }) => Promise<void>;
300
+ onDelete?: (data: Pick<ChaiPage, "id">) => Promise<void>;
301
+ dataProvider?: (args: {
302
+ lang: string;
303
+ draft: boolean;
304
+ inBuilder: boolean;
305
+ pageProps: ChaiPageProps;
306
+ }) => Promise<Record<string, any>>;
307
+ defaultSeo?: () => Record<string, any>;
308
+ defaultJSONLD?: () => Record<string, any>;
309
+ defaultMetaTags?: () => Record<string, string>;
310
+ };
311
+
312
+ declare type ChaiSavePageData = {
313
+ autoSave: boolean;
314
+ blocks: ChaiBlock[];
315
+ theme?: ChaiTheme;
316
+ needTranslations?: boolean;
317
+ designTokens: ChaiDesignTokens;
318
+ };
319
+
320
+ declare interface ChaiSiteWideUsageData {
321
+ [pageId: string]: {
322
+ name: string;
323
+ isPartial: boolean;
324
+ partialBlocks: string[];
325
+ links: string[];
326
+ designTokens: ChaiBlocksWithDesignTokens;
327
+ };
328
+ }
329
+
330
+ declare type ChaiTheme = {
239
331
  fontFamily: {
240
332
  heading: string;
241
333
  body: string;
@@ -261,10 +353,16 @@ declare type ChaiThemeValues = {
261
353
  "card-foreground": [HexColor, HexColor];
262
354
  popover: [HexColor, HexColor];
263
355
  "popover-foreground": [HexColor, HexColor];
264
- [key: string]: [HexColor, HexColor];
265
356
  };
266
357
  };
267
358
 
359
+ declare type ChaiUserInfo = {
360
+ id: string;
361
+ email: string;
362
+ name: string;
363
+ avatar?: string;
364
+ };
365
+
268
366
  export declare const ChaiWebsiteBuilder: (props: ChaiWebsiteBuilderProps) => JSX.Element;
269
367
 
270
368
  declare type ChaiWebsiteBuilderProps = {
@@ -287,22 +385,8 @@ declare type ChaiWebsiteSetting = {
287
385
  appKey: string;
288
386
  fallbackLang: string;
289
387
  languages: string[];
290
- theme: Record<"fontFamily" | "borderRadius" | "colors", any>;
291
- designTokens: DesignTokens_2;
292
- };
293
-
294
- declare interface DesignTokens {
295
- [uniqueId: string]: {
296
- name: string;
297
- value: string;
298
- };
299
- }
300
-
301
- declare type DesignTokens_2 = {
302
- [token: string]: {
303
- value: string;
304
- name: string;
305
- };
388
+ theme: ChaiTheme;
389
+ designTokens: ChaiDesignTokens;
306
390
  };
307
391
 
308
392
  declare type FilterOptions = {
@@ -352,17 +436,6 @@ declare type NestedPathSelectorProps = {
352
436
  disabled?: boolean;
353
437
  };
354
438
 
355
- declare type PageType = {
356
- key: string;
357
- name: string;
358
- };
359
-
360
- declare type PageTypeItem = {
361
- id: string;
362
- name: string;
363
- slug?: string;
364
- };
365
-
366
439
  export declare const PermissionChecker: ({ permission, permissions, children, fallback, }: {
367
440
  permission?: string;
368
441
  permissions?: string[];
@@ -372,24 +445,6 @@ export declare const PermissionChecker: ({ permission, permissions, children, fa
372
445
 
373
446
  declare type ReactComponentType = default_2.ComponentType<any>;
374
447
 
375
- declare type SavePageData = {
376
- autoSave: boolean;
377
- blocks: ChaiBlock[];
378
- theme?: ChaiThemeValues;
379
- needTranslations?: boolean;
380
- designTokens: DesignTokens;
381
- };
382
-
383
- declare interface SiteWideUsage {
384
- [pageId: string]: {
385
- name: string;
386
- isPartial: boolean;
387
- partialBlocks: string[];
388
- links: string[];
389
- designTokens: BlocksWithDesignTokens;
390
- };
391
- }
392
-
393
448
  declare interface SmartJsonInputProps {
394
449
  value: string;
395
450
  onChange: (value: string) => void;
@@ -487,6 +542,4 @@ export declare const useWebsitePages: () => UseQueryResult<any, Error>;
487
542
 
488
543
  export declare const useWebsiteSetting: () => UseQueryResult<ChaiWebsiteSetting, Error>;
489
544
 
490
- declare type VariableKey = string;
491
-
492
545
  export { }
package/dist/pages.js CHANGED
@@ -1,4 +1,4 @@
1
- import { aE as s, aT as u, aP as t, aN as i, aO as r, ax as g, aU as P, ar as l, v as h, aK as n, aZ as o, aw as c, ap as C, aV as d, k as p, as as m, aW as A, l as U, m as b, aX as k, aY as W, a_ as v, g as B, j as F } from "./index-D5d4QDq7.js";
1
+ import { aE as s, aT as u, aP as t, aN as i, aO as r, ax as g, aU as P, ar as l, v as h, aK as n, aZ as o, aw as c, ap as C, aV as d, k as p, as as m, aW as A, l as U, m as b, aX as k, aY as W, a_ as v, g as B, j as F } from "./index-Be9lAaD7.js";
2
2
  export {
3
3
  s as ChaiJsonInput,
4
4
  u as ChaiWebsiteBuilder,
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),q=require("./register-chai-top-bar-DWTuRU53.cjs"),f=require("./index-Bm8iS2OH.cjs"),r=require("./index-BRJCj7c_.cjs"),U=require("./page-manager-search-and-filter-BKdQUJ2W.cjs"),F=require("@tanstack/react-query"),t=require("lodash-es"),b=require("lucide-react"),a=require("react"),M=()=>{const l=r.useApiUrl(),d=r.useFetch();return F.useQuery({queryKey:[r.ACTIONS.GET_CHANGES],queryFn:async()=>d(l,{action:r.ACTIONS.GET_CHANGES})})},G=({page:l,selectedPages:d,handleCheckboxChange:N,getPageType:y,hasSlug:h,currentOwnerId:c})=>{const x=r.useUserId(),{data:u}=r.useChaiUserInfo(c),o=c===x?null:u==null?void 0:u.name;return e.jsxs("tr",{className:"group relative border-b last:border-b-0 hover:bg-gray-50",children:[e.jsxs("td",{scope:"row",className:`flex items-center gap-x-1 whitespace-nowrap px-6 py-2 text-gray-900 dark:text-white ${o?"opacity-50":""}`,children:[o?e.jsx(b.Lock,{className:"h-4 w-4 fill-red-200 text-red-500"}):e.jsx("input",{checked:t.includes(d,l==null?void 0:l.id),onClick:p=>{p.stopPropagation(),N(l==null?void 0:l.id)},type:"checkbox",className:"cursor-pointer rounded focus:outline-none focus:ring-0"})," ",h(l.pageType)?e.jsx(b.File,{className:"h-4 w-4"}):e.jsx(b.GlobeIcon,{className:"h-4 w-4"}),e.jsx(r.Tooltip,{content:l.name,side:"top",showTooltip:l.name.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-medium text-black",children:l.name})}),l.slug&&e.jsx(r.Tooltip,{content:l.slug,side:"top",showTooltip:l.slug.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-mono text-xs text-muted-foreground",children:l.slug})})]}),e.jsx("td",{className:"px-2",children:y(l==null?void 0:l.pageType)}),e.jsx("td",{className:"px-4 text-right",children:t.first(l.changes)||""}),e.jsx(e.Fragment,{children:o&&e.jsxs("button",{className:"absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100",children:[e.jsx(b.Edit,{size:12,className:"stroke-[3]"})," ",e.jsx("span",{className:"font-medium",children:o})," is editing this page"]})})]},l==null?void 0:l.id)},O=({onClose:l=()=>{},isPending:d,publishPage:N})=>{const y=r.useUserId(),{pageToUser:h}=r.usePageToUser(),[c,x]=a.useState([]),u=r.useFallbackLang(),[o,p]=a.useState(u),{data:T,isFetching:C}=M(),{data:m}=r.usePageTypes(),k=a.useCallback(s=>{var n;return(n=t.find(m,{key:s}))==null?void 0:n.hasSlug},[m]),j=a.useMemo(()=>t.filter(m,s=>!k(s.key)).map(s=>s.key),[k,m]),P=t.uniq(t.map(T,"lang")).filter(Boolean),i=a.useMemo(()=>t.filter(T,s=>s.pageType==="theme"?!1:o===u?s.lang===o||s.lang==="":s.lang===o),[T,o,u]),w=a.useMemo(()=>t.filter(i,s=>!j.includes(s.pageType)),[i,j]),S=a.useMemo(()=>t.filter(i,s=>j.includes(s.pageType)),[i,j]);a.useEffect(()=>{const s=t.map(t.filter(i,{online:!0}),"id");a.startTransition(()=>x(s))},[i]),a.useEffect(()=>{const s=t.filter(t.keys(h),n=>t.get(h,[n,"userId"])!==y);a.startTransition(()=>x(n=>t.filter(n,g=>!t.includes(s,g))))},[h,y]);const v=c.length===(i==null?void 0:i.length),E=s=>{x(n=>t.includes(n,s)?t.filter(n,g=>g!==s):t.concat(n,s))},B=()=>{x(v?[]:t.map(i,"id"))},I=()=>{N({ids:t.uniq(c)},{onSuccess:()=>{l(),r.throwConfetti("CENTER_CENTER"),p(u)}})},A=s=>{if(s==="theme")return"Theme";const n=t.find(m,{key:s});return n?n==null?void 0:n.name:s},L=a.useMemo(()=>{const s=[{label:"Updated",top:"pt-2"},...t.orderBy(t.filter(w,{online:!0}),"pageType"),...t.orderBy(t.filter(S,{online:!0}),"pageType")].filter(g=>g.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(f.DialogContent,{className:"flex max-h-[80%] max-w-4xl flex-col",children:[e.jsxs(f.DialogHeader,{children:[e.jsx(f.DialogTitle,{children:"Publish changes"}),e.jsx(f.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),P.length>0&&e.jsx("div",{className:"my-[2px] mt-0",children:e.jsx(U.LanguageSelector,{languages:[u,...P],selectedLanguage:o,setSelectedLanguage:p})}),e.jsx("div",{className:"no-scrollbar relative -mx-4 -mt-4 h-full max-h-full overflow-y-auto",children:C?e.jsxs("div",{className:"space-y-2 px-1",children:[e.jsx("div",{className:"mt-2 h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):e.jsxs("table",{className:"w-full text-left text-xs text-gray-500 dark:text-gray-400 rtl:text-right",children:[e.jsx("thead",{className:"sticky top-0 z-10 border-b bg-gray-50 text-gray-700 dark:bg-gray-700 dark:text-gray-400",children:e.jsxs("tr",{children:[e.jsxs("th",{scope:"col",className:"w-[1 50px] flex items-center gap-x-2 px-6 py-3",children:[e.jsx("input",{checked:v,onClick:s=>{s.stopPropagation(),B()},type:"checkbox",className:"mt-1 cursor-pointer rounded focus:outline-none focus:ring-0"}),"Name"]}),e.jsx("th",{scope:"col",className:"w-[150px] px-2 py-3",children:"Type"}),e.jsx("th",{scope:"col",className:"w-[150px] px-4 py-3 text-right",children:"Status"})]})}),e.jsx("tbody",{children:t.map(L,s=>s.label?e.jsx("tr",{children:e.jsxs("td",{colSpan:3,className:`relative px-6 py-2 text-xs font-medium text-gray-800 ${s.top}`,children:[e.jsx("div",{className:"absolute inset-0 left-6 flex items-center",children:e.jsx("div",{className:"order-gray-300 w-full"})}),e.jsx("div",{className:"relative flex justify-start",children:e.jsx("span",{className:"bg-gray-50 pr-2",children:s.label})})]})},"separator"):e.jsx(G,{page:s,selectedPages:c,handleCheckboxChange:E,getPageType:A,hasSlug:k,currentOwnerId:t.get(h,[(s==null?void 0:s.primaryPage)||(s==null?void 0:s.id),"userId"])}))})]})}),e.jsxs(f.DialogFooter,{className:"mt-10 flex items-center justify-center",children:[c.length>0&&e.jsxs("span",{className:"text-center text-sm text-muted-foreground",children:[c.length," Page",c.length!==1?"s":""," Selected"]}),e.jsx(q.Button,{disabled:d,variant:"outline",onClick:l,children:"Cancel"}),e.jsx(q.Button,{disabled:d||C||t.isEmpty(c),onClick:I,children:d?"Publishing...":"Publish Selected"})]})]})};exports.default=O;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),q=require("./register-chai-top-bar-DWTuRU53.cjs"),f=require("./index-BhqugjzS.cjs"),r=require("./index-CNEEEgTV.cjs"),U=require("./page-manager-search-and-filter-mEKl-UKh.cjs"),F=require("@tanstack/react-query"),t=require("lodash-es"),b=require("lucide-react"),a=require("react"),M=()=>{const l=r.useApiUrl(),d=r.useFetch();return F.useQuery({queryKey:[r.ACTIONS.GET_CHANGES],queryFn:async()=>d(l,{action:r.ACTIONS.GET_CHANGES})})},G=({page:l,selectedPages:d,handleCheckboxChange:N,getPageType:y,hasSlug:h,currentOwnerId:c})=>{const x=r.useUserId(),{data:u}=r.useChaiUserInfo(c),o=c===x?null:u==null?void 0:u.name;return e.jsxs("tr",{className:"group relative border-b last:border-b-0 hover:bg-gray-50",children:[e.jsxs("td",{scope:"row",className:`flex items-center gap-x-1 whitespace-nowrap px-6 py-2 text-gray-900 dark:text-white ${o?"opacity-50":""}`,children:[o?e.jsx(b.Lock,{className:"h-4 w-4 fill-red-200 text-red-500"}):e.jsx("input",{checked:t.includes(d,l==null?void 0:l.id),onClick:p=>{p.stopPropagation(),N(l==null?void 0:l.id)},type:"checkbox",className:"cursor-pointer rounded focus:outline-none focus:ring-0"})," ",h(l.pageType)?e.jsx(b.File,{className:"h-4 w-4"}):e.jsx(b.GlobeIcon,{className:"h-4 w-4"}),e.jsx(r.Tooltip,{content:l.name,side:"top",showTooltip:l.name.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-medium text-black",children:l.name})}),l.slug&&e.jsx(r.Tooltip,{content:l.slug,side:"top",showTooltip:l.slug.length>25,children:e.jsx("span",{className:"max-w-[200px] truncate font-mono text-xs text-muted-foreground",children:l.slug})})]}),e.jsx("td",{className:"px-2",children:y(l==null?void 0:l.pageType)}),e.jsx("td",{className:"px-4 text-right",children:t.first(l.changes)||""}),e.jsx(e.Fragment,{children:o&&e.jsxs("button",{className:"absolute right-0 top-0 flex h-full items-center gap-x-1 rounded bg-red-50 px-2 py-0.5 text-xs font-light text-red-500 opacity-0 group-hover:opacity-100",children:[e.jsx(b.Edit,{size:12,className:"stroke-[3]"})," ",e.jsx("span",{className:"font-medium",children:o})," is editing this page"]})})]},l==null?void 0:l.id)},O=({onClose:l=()=>{},isPending:d,publishPage:N})=>{const y=r.useUserId(),{pageToUser:h}=r.usePageToUser(),[c,x]=a.useState([]),u=r.useFallbackLang(),[o,p]=a.useState(u),{data:T,isFetching:C}=M(),{data:m}=r.usePageTypes(),k=a.useCallback(s=>{var n;return(n=t.find(m,{key:s}))==null?void 0:n.hasSlug},[m]),j=a.useMemo(()=>t.filter(m,s=>!k(s.key)).map(s=>s.key),[k,m]),P=t.uniq(t.map(T,"lang")).filter(Boolean),i=a.useMemo(()=>t.filter(T,s=>s.pageType==="theme"?!1:o===u?s.lang===o||s.lang==="":s.lang===o),[T,o,u]),w=a.useMemo(()=>t.filter(i,s=>!j.includes(s.pageType)),[i,j]),S=a.useMemo(()=>t.filter(i,s=>j.includes(s.pageType)),[i,j]);a.useEffect(()=>{const s=t.map(t.filter(i,{online:!0}),"id");a.startTransition(()=>x(s))},[i]),a.useEffect(()=>{const s=t.filter(t.keys(h),n=>t.get(h,[n,"userId"])!==y);a.startTransition(()=>x(n=>t.filter(n,g=>!t.includes(s,g))))},[h,y]);const v=c.length===(i==null?void 0:i.length),E=s=>{x(n=>t.includes(n,s)?t.filter(n,g=>g!==s):t.concat(n,s))},B=()=>{x(v?[]:t.map(i,"id"))},I=()=>{N({ids:t.uniq(c)},{onSuccess:()=>{l(),r.throwConfetti("CENTER_CENTER"),p(u)}})},A=s=>{if(s==="theme")return"Theme";const n=t.find(m,{key:s});return n?n==null?void 0:n.name:s},L=a.useMemo(()=>{const s=[{label:"Updated",top:"pt-2"},...t.orderBy(t.filter(w,{online:!0}),"pageType"),...t.orderBy(t.filter(S,{online:!0}),"pageType")].filter(g=>g.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(f.DialogContent,{className:"flex max-h-[80%] max-w-4xl flex-col",children:[e.jsxs(f.DialogHeader,{children:[e.jsx(f.DialogTitle,{children:"Publish changes"}),e.jsx(f.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),P.length>0&&e.jsx("div",{className:"my-[2px] mt-0",children:e.jsx(U.LanguageSelector,{languages:[u,...P],selectedLanguage:o,setSelectedLanguage:p})}),e.jsx("div",{className:"no-scrollbar relative -mx-4 -mt-4 h-full max-h-full overflow-y-auto",children:C?e.jsxs("div",{className:"space-y-2 px-1",children:[e.jsx("div",{className:"mt-2 h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-6 w-full animate-pulse rounded bg-gray-200"})]}):e.jsxs("table",{className:"w-full text-left text-xs text-gray-500 dark:text-gray-400 rtl:text-right",children:[e.jsx("thead",{className:"sticky top-0 z-10 border-b bg-gray-50 text-gray-700 dark:bg-gray-700 dark:text-gray-400",children:e.jsxs("tr",{children:[e.jsxs("th",{scope:"col",className:"w-[1 50px] flex items-center gap-x-2 px-6 py-3",children:[e.jsx("input",{checked:v,onClick:s=>{s.stopPropagation(),B()},type:"checkbox",className:"mt-1 cursor-pointer rounded focus:outline-none focus:ring-0"}),"Name"]}),e.jsx("th",{scope:"col",className:"w-[150px] px-2 py-3",children:"Type"}),e.jsx("th",{scope:"col",className:"w-[150px] px-4 py-3 text-right",children:"Status"})]})}),e.jsx("tbody",{children:t.map(L,s=>s.label?e.jsx("tr",{children:e.jsxs("td",{colSpan:3,className:`relative px-6 py-2 text-xs font-medium text-gray-800 ${s.top}`,children:[e.jsx("div",{className:"absolute inset-0 left-6 flex items-center",children:e.jsx("div",{className:"order-gray-300 w-full"})}),e.jsx("div",{className:"relative flex justify-start",children:e.jsx("span",{className:"bg-gray-50 pr-2",children:s.label})})]})},"separator"):e.jsx(G,{page:s,selectedPages:c,handleCheckboxChange:E,getPageType:A,hasSlug:k,currentOwnerId:t.get(h,[(s==null?void 0:s.primaryPage)||(s==null?void 0:s.id),"userId"])}))})]})}),e.jsxs(f.DialogFooter,{className:"mt-10 flex items-center justify-center",children:[c.length>0&&e.jsxs("span",{className:"text-center text-sm text-muted-foreground",children:[c.length," Page",c.length!==1?"s":""," Selected"]}),e.jsx(q.Button,{disabled:d,variant:"outline",onClick:l,children:"Cancel"}),e.jsx(q.Button,{disabled:d||C||t.isEmpty(c),onClick:I,children:d?"Publishing...":"Publish Selected"})]})]})};exports.default=O;
@@ -1,8 +1,8 @@
1
1
  import { jsxs as n, jsx as t, Fragment as $ } from "react/jsx-runtime";
2
2
  import { B as L } from "./register-chai-top-bar-CX_JkRJn.js";
3
- import { d as K, e as Q, f as J, p as V, q as W } from "./index-BK0xWO1z.js";
4
- import { ar as X, as as Y, A as I, aA as O, aB as Z, k as ee, m as te, ap as se, T as U, t as le } from "./index-D5d4QDq7.js";
5
- import { LanguageSelector as ae } from "./page-manager-search-and-filter-C1IWF_4d.js";
3
+ import { d as K, e as Q, f as J, p as V, q as W } from "./index-mjuSGlPU.js";
4
+ import { ar as X, as as Y, A as I, aA as O, aB as Z, k as ee, m as te, ap as se, T as U, t as le } from "./index-Be9lAaD7.js";
5
+ import { LanguageSelector as ae } from "./page-manager-search-and-filter-CLJss6pV.js";
6
6
  import { useQuery as ne } from "@tanstack/react-query";
7
7
  import { find as B, filter as a, map as b, keys as re, get as F, includes as C, orderBy as N, isEmpty as oe, uniq as G, first as ce, concat as ie } from "lodash-es";
8
8
  import { Lock as de, GlobeIcon as ue, File as me, Edit as he } from "lucide-react";
package/dist/render.cjs CHANGED
@@ -1,3 +1,3 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./plugin-BGlQf0iy.cjs"),d=require("./apply-binding-IsUf6UWJ.cjs"),m=require("react/jsx-runtime"),t=require("lodash-es"),g=require("react"),b=require("./core-Y0lXLwkq.cjs"),F=require("@mhsdesign/jit-browser-tailwindcss"),j=require("@tailwindcss/aspect-ratio"),q=require("@tailwindcss/container-queries"),K=require("@tailwindcss/forms"),M=require("@tailwindcss/typography"),L=require("./get-chai-builder-theme-BApShjRz.cjs");async function O(e){const a={pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:!1},n=await e.dataProvider(a);return t.has(n,"$metadata")&&t.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,n.$metadata),e.children({...t.omit(n,"$metadata")})}const N=()=>m.jsx("div",{}),H=e=>{const{block:a,lang:n,fallbackLang:s,children:i,externalData:l,blocks:o,draft:r,pageProps:c,dataProviderMetadataCallback:f}=e,u=b.getRegisteredChaiBlock(a._type),p=t.get(u,"component",null),_=t.get(e.repeaterData,"index",-1),k=t.get(e.repeaterData,"dataKey",""),w=n===s?"":n??"",y=d.applyBindingToBlockProps(d.applyLanguage(a,w,u),l??{},{index:_,key:k}),h=d.getBlockTagAttributes(a,!1),I=D(o,a._id,d.getBlockRuntimeProps(a._type)),T=t.has(u,"dataProvider")&&t.isFunction(u.dataProvider),B={...y,...h,...I},P={blockProps:{},inBuilder:!1,lang:n||s||"en",draft:r??!1,pageData:l??{},...B},v=t.get(B,"_show",!0);if(t.isNull(p)||!v)return null;if(T){const S=t.get(u,"suspenseFallback",N);return m.jsx(g.Suspense,{fallback:g.createElement(S),children:m.jsx(O,{lang:n??"",pageProps:c,block:B,dataProvider:u.dataProvider,...f?{dataProviderMetadataCallback:f}:{},draft:r??!1,children:$=>g.createElement(p,{...P,...$,children:i({_id:a._id,_type:a._type,...t.isArray(y.repeaterItems)?{repeaterItems:d.applyLimit(y.repeaterItems,a),$repeaterItemsKey:y.$repeaterItemsKey,repeaterTotalItems:y.repeaterTotalItems??-1}:{}})})})})}return m.jsx(g.Suspense,{children:g.createElement(p,{...P,children:i({_id:a._id,_type:a._type,...t.isArray(y.repeaterItems)?{repeaterItems:d.applyLimit(y.repeaterItems,a),$repeaterItemsKey:y.$repeaterItemsKey,repeaterTotalItems:y.repeaterTotalItems??-1}:{}})})})},x=e=>{const{blocks:a,parent:n,repeaterData:s,type:i}=e;let l=t.uniqBy(t.filter(a,r=>t.has(r,"_id")&&(t.isEmpty(n)?!r._parent:r._parent===n)),"_id");const o=r=>t.filter(a,c=>c._parent===r).length>0;return(i==="Heading"||i==="Paragraph"||i==="Link"||i==="Span")&&(l=d.adjustSpacingInContentBlocks(l)),t.map(l,r=>r?g.createElement(H,{...e,key:r._id,block:r},({_id:c,_type:f,repeaterItems:u,$repeaterItemsKey:p})=>f==="Repeater"?t.isArray(u)&&u.map((_,k)=>g.createElement(x,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}-${k}`,repeaterData:{index:k,dataKey:p}})):o(c)?g.createElement(x,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}`,repeaterData:s,type:r._type}):null):null)},D=(e,a,n)=>t.isEmpty(n)?{}:Object.entries(n).reduce((s,[i,l])=>{const o=[];let r=t.find(e,{_id:a});for(;r;)o.push(r),r=t.find(e,{_id:r._parent});const c=t.find(o,{_type:l.block});return c&&(s[i]=t.get(c,t.get(l,"prop"),null)),s},{});function J(e){if(t.isEmpty(e.lang)&&!t.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");if(t.isEmpty(e.blocks))return null;const a=e.lang??"en",n=e.fallbackLang??a;return m.jsx(x,{...e,lang:a,fallbackLang:n})}async function V(e){const a=await e.dataProvider;return t.has(a,"$metadata")&&t.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,a.$metadata),e.children({...t.omit(a,"$metadata")})}const W=()=>m.jsx("div",{}),U=async e=>{const{block:a,lang:n,fallbackLang:s,children:i,externalData:l,blocks:o,draft:r,pageProps:c,dataProviderMetadataCallback:f,dataProviders:u}=e,p=b.getRegisteredChaiBlock(a._type),_=t.get(p,"component",null),k=t.get(e.repeaterData,"index",-1),w=t.get(e.repeaterData,"dataKey",""),y=n===s?"":n??"en",h=d.applyBindingToBlockProps(d.applyLanguage(a,y,p),l??{},{index:k,key:w}),I=d.getBlockTagAttributes(a,!1),T=D(o,a._id,d.getBlockRuntimeProps(a._type)),B=t.has(p,"dataProvider")&&t.isFunction(p.dataProvider),P={...h,...I,...T},v={blockProps:{},inBuilder:!1,lang:n||s||"en",draft:r??!1,pageData:l??{},...P},S=t.get(P,"_show",!0);if(t.isNull(_)||!S)return null;if(B){const $=t.get(u,a._id,Promise.resolve({})),R=t.get(p,"suspenseFallback",W);return m.jsx(g.Suspense,{fallback:g.createElement(R),children:m.jsx(V,{lang:n??"",pageProps:c,block:P,dataProvider:$,...f?{dataProviderMetadataCallback:f}:{},draft:r??!1,children:A=>g.createElement(_,{...v,...A,children:i({_id:a._id,_type:a._type,...t.isArray(h.repeaterItems)?{repeaterItems:d.applyLimit(h.repeaterItems,a),$repeaterItemsKey:h.$repeaterItemsKey,repeaterTotalItems:h.repeaterTotalItems??-1}:{}})})})})}return g.createElement(_,{...v,children:i({_id:a._id,_type:a._type,...t.isArray(h.repeaterItems)?{repeaterItems:d.applyLimit(h.repeaterItems,a),$repeaterItemsKey:h.$repeaterItemsKey,repeaterTotalItems:h.repeaterTotalItems??-1}:{}})})},C=async e=>{const{blocks:a,parent:n,repeaterData:s,type:i}=e;let l=t.uniqBy(t.filter(a,r=>t.has(r,"_id")&&(t.isEmpty(n)?!r._parent:r._parent===n)),"_id");const o=r=>t.filter(a,c=>c._parent===r).length>0;return(i==="Heading"||i==="Paragraph"||i==="Link")&&(l=d.adjustSpacingInContentBlocks(l)),t.map(l,r=>r?g.createElement(U,{...e,dataProviders:e.dataProviders,key:r._id,block:r},({_id:c,_type:f,repeaterItems:u,$repeaterItemsKey:p})=>f==="Repeater"?t.isArray(u)&&u.map((_,k)=>g.createElement(C,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}-${k}`,repeaterData:{index:k,dataKey:p}})):o(c)?g.createElement(C,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}`,repeaterData:s,type:r._type}):null):null)};async function G(e){if(t.isEmpty(e.lang)&&!t.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");if(t.isEmpty(e.blocks))return null;const a=e.lang??"en",n=e.fallbackLang??a;if(e.dataProviders)return m.jsx(C,{...e,lang:a,fallbackLang:n,dataProviders:e.dataProviders});const i=e.blocks.filter(l=>{const o=b.getRegisteredChaiBlock(l._type);return!!(t.has(o,"dataProvider")&&t.isFunction(o.dataProvider))}).reduce((l,o)=>{const r=b.getRegisteredChaiBlock(o._type);if(!r||!r.dataProvider)return l;const c={pageProps:e.pageProps,block:o,lang:e.lang,draft:e.draft,inBuilder:!1};return l[o._id]=r.dataProvider(c),l},{});return m.jsx(C,{...e,lang:a,fallbackLang:n,dataProviders:i})}function Q(e,a){const n=e.filter(s=>s._type==="GlobalBlock"||s._type==="PartialBlock");for(let s=0;s<n.length;s++){const i=n[s],l=t.get(i,"partialBlockId",t.get(i,"globalBlock",""));if(l==="")continue;let o=t.cloneDeep(t.get(a,l,[]));i._parent&&(o==null?void 0:o.length)>0&&(o=o.map(c=>(t.isEmpty(c._parent)&&(c._parent=i._parent),c)));const r=e.indexOf(i);e.splice(r,1,...o)}return e}const z=e=>{if(!e)return[];try{return JSON.parse(X(e)).filter(n=>!n._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function X(e){const a=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(a,n=>{const s=decodeURIComponent(n),i=s.indexOf("public");return i!==-1?s.substring(i+6):s})}async function Y(e,a=[],n=!1){return await F.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:{...L.getChaiBuilderTheme(),keyframes:{"accordion-down":{from:{height:"0"},to:{height:"var(--radix-accordion-content-height)"}},"accordion-up":{from:{height:"var(--radix-accordion-content-height)"},to:{height:"0"}}},animation:{"accordion-down":"accordion-down 0.2s ease-out","accordion-up":"accordion-up 0.2s ease-out"}}},plugins:[K,M,j,q,L.chaiBuilderPlugin],corePlugins:{preflight:n}}}).generateStylesFromContent(` ${n?"@tailwind base;":""}
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const E=require("./plugin-BGlQf0iy.cjs"),d=require("./apply-binding-NvZX_rJe.cjs"),m=require("react/jsx-runtime"),t=require("lodash-es"),g=require("react"),b=require("./core-8lkXy4lC.cjs"),F=require("@mhsdesign/jit-browser-tailwindcss"),j=require("@tailwindcss/aspect-ratio"),q=require("@tailwindcss/container-queries"),K=require("@tailwindcss/forms"),M=require("@tailwindcss/typography"),L=require("./get-chai-builder-theme-BApShjRz.cjs");async function O(e){const a={pageProps:e.pageProps,block:e.block,lang:e.lang,draft:e.draft,inBuilder:!1},n=await e.dataProvider(a);return t.has(n,"$metadata")&&t.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,n.$metadata),e.children({...t.omit(n,"$metadata")})}const N=()=>m.jsx("div",{}),H=e=>{const{block:a,lang:n,fallbackLang:s,children:i,externalData:l,blocks:o,draft:r,pageProps:c,dataProviderMetadataCallback:f}=e,u=b.getRegisteredChaiBlock(a._type),p=t.get(u,"component",null),_=t.get(e.repeaterData,"index",-1),k=t.get(e.repeaterData,"dataKey",""),w=n===s?"":n??"",y=d.applyBindingToBlockProps(d.applyLanguage(a,w,u),l??{},{index:_,key:k}),h=d.getBlockTagAttributes(a,!1),I=D(o,a._id,d.getBlockRuntimeProps(a._type)),T=t.has(u,"dataProvider")&&t.isFunction(u.dataProvider),B={...y,...h,...I},P={blockProps:{},inBuilder:!1,lang:n||s||"en",draft:r??!1,pageData:l??{},...B},v=t.get(B,"_show",!0);if(t.isNull(p)||!v)return null;if(T){const S=t.get(u,"suspenseFallback",N);return m.jsx(g.Suspense,{fallback:g.createElement(S),children:m.jsx(O,{lang:n??"",pageProps:c,block:B,dataProvider:u.dataProvider,...f?{dataProviderMetadataCallback:f}:{},draft:r??!1,children:$=>g.createElement(p,{...P,...$,children:i({_id:a._id,_type:a._type,...t.isArray(y.repeaterItems)?{repeaterItems:d.applyLimit(y.repeaterItems,a),$repeaterItemsKey:y.$repeaterItemsKey,repeaterTotalItems:y.repeaterTotalItems??-1}:{}})})})})}return m.jsx(g.Suspense,{children:g.createElement(p,{...P,children:i({_id:a._id,_type:a._type,...t.isArray(y.repeaterItems)?{repeaterItems:d.applyLimit(y.repeaterItems,a),$repeaterItemsKey:y.$repeaterItemsKey,repeaterTotalItems:y.repeaterTotalItems??-1}:{}})})})},x=e=>{const{blocks:a,parent:n,repeaterData:s,type:i}=e;let l=t.uniqBy(t.filter(a,r=>t.has(r,"_id")&&(t.isEmpty(n)?!r._parent:r._parent===n)),"_id");const o=r=>t.filter(a,c=>c._parent===r).length>0;return(i==="Heading"||i==="Paragraph"||i==="Link"||i==="Span")&&(l=d.adjustSpacingInContentBlocks(l)),t.map(l,r=>r?g.createElement(H,{...e,key:r._id,block:r},({_id:c,_type:f,repeaterItems:u,$repeaterItemsKey:p})=>f==="Repeater"?t.isArray(u)&&u.map((_,k)=>g.createElement(x,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}-${k}`,repeaterData:{index:k,dataKey:p}})):o(c)?g.createElement(x,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}`,repeaterData:s,type:r._type}):null):null)},D=(e,a,n)=>t.isEmpty(n)?{}:Object.entries(n).reduce((s,[i,l])=>{const o=[];let r=t.find(e,{_id:a});for(;r;)o.push(r),r=t.find(e,{_id:r._parent});const c=t.find(o,{_type:l.block});return c&&(s[i]=t.get(c,t.get(l,"prop"),null)),s},{});function J(e){if(t.isEmpty(e.lang)&&!t.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");if(t.isEmpty(e.blocks))return null;const a=e.lang??"en",n=e.fallbackLang??a;return m.jsx(x,{...e,lang:a,fallbackLang:n})}async function V(e){const a=await e.dataProvider;return t.has(a,"$metadata")&&t.isFunction(e.dataProviderMetadataCallback)&&e.dataProviderMetadataCallback(e.block,a.$metadata),e.children({...t.omit(a,"$metadata")})}const W=()=>m.jsx("div",{}),U=async e=>{const{block:a,lang:n,fallbackLang:s,children:i,externalData:l,blocks:o,draft:r,pageProps:c,dataProviderMetadataCallback:f,dataProviders:u}=e,p=b.getRegisteredChaiBlock(a._type),_=t.get(p,"component",null),k=t.get(e.repeaterData,"index",-1),w=t.get(e.repeaterData,"dataKey",""),y=n===s?"":n??"en",h=d.applyBindingToBlockProps(d.applyLanguage(a,y,p),l??{},{index:k,key:w}),I=d.getBlockTagAttributes(a,!1),T=D(o,a._id,d.getBlockRuntimeProps(a._type)),B=t.has(p,"dataProvider")&&t.isFunction(p.dataProvider),P={...h,...I,...T},v={blockProps:{},inBuilder:!1,lang:n||s||"en",draft:r??!1,pageData:l??{},...P},S=t.get(P,"_show",!0);if(t.isNull(_)||!S)return null;if(B){const $=t.get(u,a._id,Promise.resolve({})),R=t.get(p,"suspenseFallback",W);return m.jsx(g.Suspense,{fallback:g.createElement(R),children:m.jsx(V,{lang:n??"",pageProps:c,block:P,dataProvider:$,...f?{dataProviderMetadataCallback:f}:{},draft:r??!1,children:A=>g.createElement(_,{...v,...A,children:i({_id:a._id,_type:a._type,...t.isArray(h.repeaterItems)?{repeaterItems:d.applyLimit(h.repeaterItems,a),$repeaterItemsKey:h.$repeaterItemsKey,repeaterTotalItems:h.repeaterTotalItems??-1}:{}})})})})}return g.createElement(_,{...v,children:i({_id:a._id,_type:a._type,...t.isArray(h.repeaterItems)?{repeaterItems:d.applyLimit(h.repeaterItems,a),$repeaterItemsKey:h.$repeaterItemsKey,repeaterTotalItems:h.repeaterTotalItems??-1}:{}})})},C=async e=>{const{blocks:a,parent:n,repeaterData:s,type:i}=e;let l=t.uniqBy(t.filter(a,r=>t.has(r,"_id")&&(t.isEmpty(n)?!r._parent:r._parent===n)),"_id");const o=r=>t.filter(a,c=>c._parent===r).length>0;return(i==="Heading"||i==="Paragraph"||i==="Link")&&(l=d.adjustSpacingInContentBlocks(l)),t.map(l,r=>r?g.createElement(U,{...e,dataProviders:e.dataProviders,key:r._id,block:r},({_id:c,_type:f,repeaterItems:u,$repeaterItemsKey:p})=>f==="Repeater"?t.isArray(u)&&u.map((_,k)=>g.createElement(C,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}-${k}`,repeaterData:{index:k,dataKey:p}})):o(c)?g.createElement(C,{...e,parent:r._id,key:`${t.get(r,"_parent","root")}-${r._id}`,repeaterData:s,type:r._type}):null):null)};async function G(e){if(t.isEmpty(e.lang)&&!t.isEmpty(e.fallbackLang))throw new Error("lang prop is required when fallbackLang is provided");if(t.isEmpty(e.blocks))return null;const a=e.lang??"en",n=e.fallbackLang??a;if(e.dataProviders)return m.jsx(C,{...e,lang:a,fallbackLang:n,dataProviders:e.dataProviders});const i=e.blocks.filter(l=>{const o=b.getRegisteredChaiBlock(l._type);return!!(t.has(o,"dataProvider")&&t.isFunction(o.dataProvider))}).reduce((l,o)=>{const r=b.getRegisteredChaiBlock(o._type);if(!r||!r.dataProvider)return l;const c={pageProps:e.pageProps,block:o,lang:e.lang,draft:e.draft,inBuilder:!1};return l[o._id]=r.dataProvider(c),l},{});return m.jsx(C,{...e,lang:a,fallbackLang:n,dataProviders:i})}function Q(e,a){const n=e.filter(s=>s._type==="GlobalBlock"||s._type==="PartialBlock");for(let s=0;s<n.length;s++){const i=n[s],l=t.get(i,"partialBlockId",t.get(i,"globalBlock",""));if(l==="")continue;let o=t.cloneDeep(t.get(a,l,[]));i._parent&&(o==null?void 0:o.length)>0&&(o=o.map(c=>(t.isEmpty(c._parent)&&(c._parent=i._parent),c)));const r=e.indexOf(i);e.splice(r,1,...o)}return e}const z=e=>{if(!e)return[];try{return JSON.parse(X(e)).filter(n=>!n._type.startsWith("@chai"))}catch{return[{_type:"Paragraph",_id:"error",content:"Invalid JSON. Please check the JSON string."}]}};function X(e){const a=/(asset:\/\/|https:\/\/asset\.localhost\/)(?:localhost\/)?[^"']+/g;return e.replace(a,n=>{const s=decodeURIComponent(n),i=s.indexOf("public");return i!==-1?s.substring(i+6):s})}async function Y(e,a=[],n=!1){return await F.createTailwindcss({tailwindConfig:{darkMode:"class",safelist:a,theme:{extend:{...L.getChaiBuilderTheme(),keyframes:{"accordion-down":{from:{height:"0"},to:{height:"var(--radix-accordion-content-height)"}},"accordion-up":{from:{height:"var(--radix-accordion-content-height)"},to:{height:"0"}}},animation:{"accordion-down":"accordion-down 0.2s ease-out","accordion-up":"accordion-up 0.2s ease-out"}}},plugins:[K,M,j,q,L.chaiBuilderPlugin],corePlugins:{preflight:n}}}).generateStylesFromContent(` ${n?"@tailwind base;":""}
2
2
  @tailwind components;
3
3
  @tailwind utilities;`,e)}const Z=(e,a)=>{const n=JSON.stringify(e).replace(/#styles:([^"]*)/g,(s,i)=>`#styles:${i.replace(/,/g," ")}`.replace(/#styles:/g,""));return Y([n],[],a)},ee=async(e,a=!1)=>await Z(e,a);exports.getChaiThemeCssVariables=E.getChaiThemeCssVariables;exports.getThemeFontsCSSImport=E.getThemeFontsCSSImport;exports.getThemeFontsLinkMarkup=E.getThemeFontsLinkMarkup;exports.applyChaiDataBinding=d.applyChaiDataBinding;exports.applyDesignTokens=d.applyDesignTokens;exports.convertHTMLToChaiBlocks=d.getBlocksFromHTML;exports.AsyncRenderChaiBlocks=G;exports.RenderChaiBlocks=J;exports.convertToBlocks=z;exports.getMergedPartialBlocks=Q;exports.getStylesForBlocks=ee;