@chaibuilder/pages 0.16.18 → 0.16.19

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 (82) hide show
  1. package/dist/{2AITGKQY-DbBNqqNQ.cjs → 2AITGKQY-BH_4lP5P.cjs} +1 -1
  2. package/dist/{2AITGKQY-jev6nZ--.js → 2AITGKQY-BuWtti7-.js} +2 -2
  3. package/dist/{NCMVHL6D-BjH1Tg1s.cjs → NCMVHL6D-CfRPe-3L.cjs} +1 -1
  4. package/dist/{NCMVHL6D-BtVmDJZQ.js → NCMVHL6D-DbC9VYfW.js} +2 -2
  5. package/dist/{ZDWCUMSJ-Nezb42Bx.cjs → ZDWCUMSJ-BxhCnC2U.cjs} +1 -1
  6. package/dist/{ZDWCUMSJ-S9dikjgz.js → ZDWCUMSJ-CE0Md3aC.js} +1 -1
  7. package/dist/{active-in-another-tab-nD0Ct2zR.js → active-in-another-tab-C4o8FQXv.js} +1 -1
  8. package/dist/{active-in-another-tab-B2jwquvi.cjs → active-in-another-tab-SSCyhy2-.cjs} +1 -1
  9. package/dist/{add-new-language-page-BJk1ZO-t.js → add-new-language-page-BCu4Npk2.js} +2 -2
  10. package/dist/{add-new-language-page-B2CGLeBl.cjs → add-new-language-page-DUkVmwsT.cjs} +1 -1
  11. package/dist/{add-new-page-Y4l1kKgu.cjs → add-new-page-BDpRUueB.cjs} +1 -1
  12. package/dist/{add-new-page-DNMc1_m8.js → add-new-page-D1pc9kLA.js} +1 -1
  13. package/dist/{ai-panel-content-B2R5ac1Q.cjs → ai-panel-content-Bq3BC1Dm.cjs} +1 -1
  14. package/dist/{ai-panel-content-BZDagIjt.js → ai-panel-content-Dg6P7vk7.js} +2 -2
  15. package/dist/{ai-panel-default-lang-DFVRw2XO.js → ai-panel-default-lang-BxYd_6VF.js} +3 -3
  16. package/dist/{ai-panel-default-lang-DpRzlKuh.cjs → ai-panel-default-lang-C0X_Srso.cjs} +2 -2
  17. package/dist/{ai-panel-other-lang-mjWK495u.cjs → ai-panel-other-lang-BOu1wJ5J.cjs} +1 -1
  18. package/dist/{ai-panel-other-lang-CGiXHbUA.js → ai-panel-other-lang-CBAP_iX-.js} +3 -3
  19. package/dist/{ai-prompt-input-B6dhDx3f.js → ai-prompt-input-CiZCB6jc.js} +2 -2
  20. package/dist/{ai-prompt-input-B3799aqQ.cjs → ai-prompt-input-bqLGbsQ2.cjs} +1 -1
  21. package/dist/{ai-translation-prompt-C3SvF46x.cjs → ai-translation-prompt-Cas13J-r.cjs} +1 -1
  22. package/dist/{ai-translation-prompt-D5ndfcqu.js → ai-translation-prompt-D3XU5z3f.js} +1 -1
  23. package/dist/{continue-editing-in-this-client-BtPTGxtF.js → continue-editing-in-this-client-DIpi2ZSi.js} +1 -1
  24. package/dist/{continue-editing-in-this-client-ClnIhAB4.cjs → continue-editing-in-this-client-DbHzW_zt.cjs} +1 -1
  25. package/dist/{delete-page-CgbNmdX3.js → delete-page-CODOstkw.js} +1 -1
  26. package/dist/{delete-page-BWQiX4Qy.cjs → delete-page-DPHNAOC6.cjs} +1 -1
  27. package/dist/{digital-asset-manager-CHPG0akQ.cjs → digital-asset-manager-BllbsemN.cjs} +1 -1
  28. package/dist/{digital-asset-manager-D2DU2Arz.js → digital-asset-manager-BuYVjKfQ.js} +1 -1
  29. package/dist/{duplicate-page-D9YHfSTB.cjs → duplicate-page-Dc6_UBNZ.cjs} +1 -1
  30. package/dist/{duplicate-page-nhaRQq48.js → duplicate-page-DfH67AsW.js} +2 -2
  31. package/dist/{dynamic-page-selector-BpAx2T1D.js → dynamic-page-selector-C2UK6qGj.js} +1 -1
  32. package/dist/{dynamic-page-selector-BhFVhQXO.cjs → dynamic-page-selector-Dd8Orls1.cjs} +1 -1
  33. package/dist/index--Lu_Q_nO.cjs +5 -0
  34. package/dist/{index-tOCLaJS0.js → index-B_T6ZeA4.js} +106 -106
  35. package/dist/index.cjs +1 -1
  36. package/dist/index.js +1 -1
  37. package/dist/{json-diff-viewer-B7VUOCAk.cjs → json-diff-viewer-1IHmR_Nt.cjs} +1 -1
  38. package/dist/{json-diff-viewer-BHsCH0rV.js → json-diff-viewer-D8uyTokS.js} +1 -1
  39. package/dist/{lang-panel-CBDont1C.cjs → lang-panel-D-Pbw2bR.cjs} +1 -1
  40. package/dist/{lang-panel-Bf4bybUW.js → lang-panel-d7376A7w.js} +2 -2
  41. package/dist/{mark-as-template-mD5zJnTi.js → mark-as-template-Bx-MAB5M.js} +1 -1
  42. package/dist/{mark-as-template-ClVxTs7-.cjs → mark-as-template-DHFkkBvV.cjs} +1 -1
  43. package/dist/{no-language-page-content-BGqiBsuw.cjs → no-language-page-content-DkK7mBnG.cjs} +1 -1
  44. package/dist/{no-language-page-content-C91jYzRM.js → no-language-page-content-if-qlxZz.js} +1 -1
  45. package/dist/{no-language-page-dialog-DnN17tvI.cjs → no-language-page-dialog-49fBehZo.cjs} +1 -1
  46. package/dist/{no-language-page-dialog-CU_Y_GF8.js → no-language-page-dialog-CCLWQP1E.js} +2 -2
  47. package/dist/{page-creator-Dwn4aALC.js → page-creator-DRDoy3nM.js} +2 -2
  48. package/dist/{page-creator-BYEKqyKF.cjs → page-creator-DlJXKAhw.cjs} +1 -1
  49. package/dist/{page-lock-DAWrc3GC.cjs → page-lock-DOnPhjGp.cjs} +1 -1
  50. package/dist/{page-lock-DHoFXsEj.js → page-lock-pwxPivz-.js} +2 -2
  51. package/dist/{page-locked-dialog-QL8ZUQQd.js → page-locked-dialog-238NohyB.js} +1 -1
  52. package/dist/{page-locked-dialog-DMDIpR6r.cjs → page-locked-dialog-DKn93bBu.cjs} +1 -1
  53. package/dist/{page-manager-new-r1540okw.cjs → page-manager-new-Ch0UNJM1.cjs} +1 -1
  54. package/dist/{page-manager-new-1RGAp9KU.js → page-manager-new-hEQwUorR.js} +2 -2
  55. package/dist/{page-manager-search-and-filter-Dp1Z6uDu.cjs → page-manager-search-and-filter-4JatGyBT.cjs} +1 -1
  56. package/dist/{page-manager-search-and-filter-B9kZBAGe.js → page-manager-search-and-filter-B86rQEO4.js} +1 -1
  57. package/dist/{page-revisions-content-qrkR9Stz.cjs → page-revisions-content-ChOACVs4.cjs} +1 -1
  58. package/dist/{page-revisions-content-BLLa8Sar.js → page-revisions-content-V9S1rPUy.js} +2 -2
  59. package/dist/{publish-pages-content-DquiwxG5.cjs → publish-pages-content-CXKknMnI.cjs} +1 -1
  60. package/dist/{publish-pages-content-CML_ott4.js → publish-pages-content-GKnG7R5W.js} +2 -2
  61. package/dist/{save-to-lib-DZOs6H7V.js → save-to-lib-BO3WEr-u.js} +1 -1
  62. package/dist/{save-to-lib-BBZn9sEZ.cjs → save-to-lib-BderZ0Qz.cjs} +1 -1
  63. package/dist/{selected-block-display-qF0wXDpP.js → selected-block-display-DAe0XQgw.js} +1 -1
  64. package/dist/{selected-block-display-DWpFg5KU.cjs → selected-block-display-yB5bvo9w.cjs} +1 -1
  65. package/dist/{seo-panel-CmqA8v6p.cjs → seo-panel-C2WY1dTf.cjs} +1 -1
  66. package/dist/{seo-panel-DcTu-rLl.js → seo-panel-DuC3gQQy.js} +1 -1
  67. package/dist/{shared-json-ld-DZ2eZ35l.cjs → shared-json-ld-ChfktUpf.cjs} +1 -1
  68. package/dist/{shared-json-ld-Bs_lzQ6G.js → shared-json-ld-DMpCm3M4.js} +1 -1
  69. package/dist/{slug-input-Df9ug5YA.js → slug-input-CO6AGAQD.js} +1 -1
  70. package/dist/{slug-input-BvRnz9Xf.cjs → slug-input-CrjrFrxP.cjs} +1 -1
  71. package/dist/{take-over-request-BBmLlOro.js → take-over-request-Du7grW5x.js} +1 -1
  72. package/dist/{take-over-request-eUnq0CcU.cjs → take-over-request-mNydSSFX.cjs} +1 -1
  73. package/dist/{theme-panel-footer-BO6xk08X.js → theme-panel-footer-CSC6DpWO.js} +1 -1
  74. package/dist/{theme-panel-footer-CzntKXBS.cjs → theme-panel-footer-eZ1bbLzq.cjs} +1 -1
  75. package/dist/{unmark-as-template-BHbGyEJS.cjs → unmark-as-template-DzU6-XK7.cjs} +1 -1
  76. package/dist/{unmark-as-template-CSpTbvOz.js → unmark-as-template-dEb6wFT9.js} +1 -1
  77. package/dist/{unpublish-page-DTVEQJoy.js → unpublish-page-CxAB3-Cj.js} +1 -1
  78. package/dist/{unpublish-page-kHxAVlJS.cjs → unpublish-page-DGd2Kktq.cjs} +1 -1
  79. package/dist/{web-preview-CW4XBgip.cjs → web-preview-B6G0vdiq.cjs} +1 -1
  80. package/dist/{web-preview-SaTB5Pss.js → web-preview-yBF4EXzm.js} +1 -1
  81. package/package.json +1 -1
  82. package/dist/index-Nz9M0K-w.cjs +0 -5
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("./index-Nz9M0K-w.cjs"),N=require("@tanstack/react-query"),O=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),y=require("date-fns"),L=require("lodash-es"),p=require("lucide-react"),b=require("react");function Q(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const l=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(n,t,l.get?l:{enumerable:!0,get:()=>s[t]})}}return n.default=s,Object.freeze(n)}const v=Q(b);function z(s){const n=d.useApiUrl(),t=d.useFetch();return N.useQuery({queryKey:[d.ACTIONS.GET_PAGE_REVISIONS,s],queryFn:async()=>await t(n,{action:d.ACTIONS.GET_PAGE_REVISIONS,data:{pageId:s}}),enabled:!!s,refetchOnMount:!0})}const B=()=>{const s=d.useApiUrl(),n=d.useFetch(),t=N.useQueryClient();return N.useMutation({mutationFn:async l=>await n(s,{action:d.ACTIONS.DELETE_PAGE_REVISION,data:{revisionId:l}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},H=()=>{const s=d.useApiUrl(),n=d.useFetch(),t=N.useQueryClient();return N.useMutation({mutationFn:async({revisionId:l,discardCurrent:r})=>await n(s,{action:d.ACTIONS.RESTORE_PAGE_REVISION,data:{revisionId:l,discardCurrent:r}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},$=b.lazy(()=>Promise.resolve().then(()=>require("./json-diff-viewer-B7VUOCAk.cjs"))),g=({tag:s})=>s==="draft"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-amber-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Draft"})]}):s==="live"?e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-green-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Live"})]}):s==="published"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-green-500/10 px-1.5 py-0.5 text-xs text-green-600",children:[e.jsx(p.Rocket,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Published"})]}):s==="unsaved"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-red-500/10 px-1.5 py-0.5 text-xs text-red-600",children:[e.jsx(p.Save,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Unsaved changes"})]}):e.jsx("span",{className:"rounded bg-purple-500/10 px-1.5 py-0.5 font-mono text-xs font-bold text-purple-600",children:s});function J({compare:s,setCompare:n}){const{data:t}=d.useCurrentPage(),{saveState:l}=O.useSavePage(),[r]=d.usePageEditInfo();if(!t)return null;const c=!!s.find(u=>{var i;return(i=u==null?void 0:u.uid)==null?void 0:i.startsWith("draft:")}),x=s.length>=2&&!c,m=l==="UNSAVED";return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border bg-primary/5 p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-1 text-sm font-medium leading-none",children:[e.jsx(g,{tag:"draft"}),e.jsx("span",{className:"text-xs font-bold",children:"Currently editing"})]})}),e.jsx("div",{className:"flex items-center pl-2 text-[11px] text-muted-foreground",children:!L.isEmpty(r.lastSaved)&&e.jsxs("span",{children:["Last updated"," ",y.formatDistanceToNow(new Date(r.lastSaved),{addSuffix:!0})]})}),e.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:m?e.jsx(g,{tag:"unsaved"}):null})]}),e.jsx(A,{checked:c,disabled:x,onChange:()=>{n(c?s.filter(u=>u.uid!==`draft:${t==null?void 0:t.id}`):[...s,{uid:`draft:${t==null?void 0:t.id}`,label:"draft",item:{createdAt:Date.now()}}])}})]})}function K(){return e.jsx("div",{className:"mt-2 space-y-2",children:Array.from({length:5}).map((s,n)=>e.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(a.Skeleton,{className:"h-4 w-3/4"}),e.jsx(a.Skeleton,{className:"h-3 w-1/2"}),e.jsx(a.Skeleton,{className:"mt-1 h-5 w-20"})]}),e.jsx(a.Skeleton,{className:"h-8 w-8 rounded-full"})]},n))})}function I({revision:s,isLatest:n,onRestore:t,onDelete:l,revisionNumber:r,compare:c,setCompare:x,pageId:m}){const{data:u}=d.useChaiUserInfo(s.currentEditor),i=(u==null?void 0:u.name)||"Unknown",f=!!c.find(h=>{var j;return n?(j=h==null?void 0:h.uid)==null?void 0:j.startsWith("live"):(h==null?void 0:h.uid)===s.uid}),S=c.length>=2&&!f;return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("p",{className:"flex items-center gap-1 text-xs leading-none",children:[e.jsx(g,{tag:n?"live":`#${r}`}),s.type==="published"?"Published":"Draft"," by ",e.jsx("span",{className:"text-xs font-bold",children:i})]})}),e.jsxs("div",{className:"flex items-center gap-x-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:s.type==="published"?e.jsx(g,{tag:"published"}):e.jsx(g,{tag:"draft"})}),e.jsx("div",{className:"flex items-center text-[10px] text-muted-foreground",children:e.jsx("span",{className:"leading-tight",children:y.format(s.createdAt,"MMM d, h:mm a")})})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(d.PermissionChecker,{permissions:[d.PAGES_PERMISSIONS.RESTORE_REVISION,d.PAGES_PERMISSIONS.DELETE_REVISION],children:e.jsx(Y,{revision:s,onRestore:t,onDelete:l})})}),e.jsx(A,{checked:f,disabled:S,onChange:()=>{x(f?c.filter(h=>n?h.uid!==`live:${m}`:h.uid!==s.uid):[...c,{uid:n?`live:${m}`:s.uid,label:n?"live":`#${r}`,item:s}].sort((h,j)=>new Date(h.item.createdAt).getTime()-new Date(j.item.createdAt).getTime()))}})]})}function W({compare:s,setCompare:n,pageId:t}){const[l,r]=b.useState(!1),[c,x]=s;if(s.length===0)return null;const m=({tab:u})=>e.jsxs("span",{className:"flex items-center justify-between rounded border border-blue-100 p-1 font-medium",children:[e.jsx(g,{tag:u.label}),e.jsx("button",{className:"z-0 flex h-4 w-4 items-center justify-center rounded-full text-gray-400 hover:text-red-500",style:{lineHeight:1},onClick:()=>n(s.filter(i=>i.uid!==u.uid)),"aria-label":"Remove selection 1",children:e.jsx(p.X,{className:"h-3 w-3"})})]});return e.jsxs("div",{className:"mb-2 flex w-full max-w-md flex-col gap-1 rounded border bg-accent/60 p-2 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-x-2 text-xs",children:[e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"Compare"}),c&&e.jsx(m,{tab:c}),e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"with"}),x?e.jsx(m,{tab:x}):e.jsx("span",{className:"rounded border px-1 text-xs text-muted-foreground",children:"Choose another"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pb-0.5 pt-2",children:[e.jsx(a.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none text-gray-500",variant:"outline",onClick:()=>n([]),children:e.jsx("span",{children:" Clear"})}),e.jsxs(a.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none",variant:"default",onClick:()=>r(!0),disabled:s.length<2,children:[e.jsx(p.FileJson,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"pt-0.5",children:"Show JSON Diff"})]})]}),l&&(s==null?void 0:s.length)>1&&t&&e.jsx(b.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx("span",{className:"text-sm",children:"Loading diff viewer..."})}),children:e.jsx($,{open:l,onOpenChange:r,compare:s})})]})}function A({checked:s,disabled:n,onChange:t,label:l="Compare"}){return e.jsx("div",{className:"absolute bottom-2 right-2",children:e.jsxs("label",{className:`flex cursor-pointer items-center gap-x-1 text-[11px] ${n?"opacity-50":""}`,children:[e.jsx("input",{type:"checkbox",className:"h-3 w-3 cursor-pointer rounded focus:ring-0 focus:ring-offset-0",checked:s,disabled:n,onChange:t}),e.jsx("span",{className:"select-none leading-tight",children:l})]})})}function Y({revision:s,onRestore:n,onDelete:t}){return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",size:"icon",className:"h-5 w-5",children:[e.jsx(p.MoreHorizontal,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More options"})]})}),e.jsxs(a.DropdownMenuContent,{align:"end",className:"text-xs",children:[e.jsx(d.PermissionChecker,{permission:d.PAGES_PERMISSIONS.RESTORE_REVISION,children:e.jsxs(a.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-sm",children:[e.jsx(p.Undo2,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Restore this version"})]})}),e.jsx(d.PermissionChecker,{permission:d.PAGES_PERMISSIONS.DELETE_REVISION,children:s.uid!=="current"&&e.jsxs(e.Fragment,{children:[e.jsx(a.DropdownMenuSeparator,{}),e.jsxs(a.DropdownMenuItem,{onClick:t,className:"cursor-pointer text-destructive",children:[e.jsx(p.Trash,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Delete this version"})]})]})})]})]})}function X({open:s,onOpenChange:n,revision:t,onRestore:l,isRestoring:r}){const{data:c}=d.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),x=(c==null?void 0:c.name)||"Unknown";return t?e.jsx(a.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(a.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Restore Revision"}),e.jsxs(a.DialogDescription,{children:["You are about to restore to revision ",t.uid.substring(0,8)," from"," ",y.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",x]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"How would you like to handle your current edits?"})}),e.jsxs(a.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(a.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>l(!1),disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Saving as draft..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.CloudOff,{className:"mr-2 h-4 w-4"}),"Save as draft"]})}),e.jsx(a.Button,{variant:"default",className:"sm:flex-1",onClick:()=>l(!0),disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Discarding current..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Undo2,{className:"mr-2 h-4 w-4"}),"Discard current"]})})]})]})}):null}function Z({open:s,onOpenChange:n,revision:t,onDelete:l,isDeleting:r}){const{data:c}=d.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),x=(c==null?void 0:c.name)||"Unknown";return t?e.jsx(a.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(a.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Delete Revision"}),e.jsxs(a.DialogDescription,{children:["You are about to delete revision ",t.uid.substring(0,8)," from"," ",y.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",x]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"This action cannot be undone. Are you sure you want to proceed?"})}),e.jsxs(a.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(a.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>n(!1),disabled:r,children:"Cancel"}),e.jsx(a.Button,{variant:"destructive",className:"sm:flex-1",onClick:l,disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Deleting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Trash,{className:"mr-2 h-4 w-4"}),"Delete Revision"]})})]})]})}):null}function ee({isOpen:s}){var E,R;const[n,t]=v.useState([]),[l,r]=v.useState(null),[c,x]=v.useState(!1),[m,u]=v.useState(!1),{data:i}=d.useCurrentPage(),{data:f,isFetching:S,error:h,refetch:j}=z(i==null?void 0:i.id),{mutate:k,isPending:M}=B(),{mutate:T,isPending:F}=H(),_=N.useQueryClient(),{selectedLang:P,fallbackLang:q}=O.useLanguages(),U=P||q;b.useEffect(()=>t([]),[i==null?void 0:i.id]);const G=o=>{l&&T({revisionId:l.uid,discardCurrent:o},{onSuccess:()=>{x(!1),r(null),_.invalidateQueries({queryKey:[d.ACTIONS.GET_DRAFT_PAGE]})}})},D=o=>{r(o),x(!0)},C=o=>{r(o),u(!0)},V=()=>{l&&k(l.uid,{onSuccess:()=>{u(!1),r(null)}})};return b.useEffect(()=>{s&&j()},[s,j]),e.jsxs(e.Fragment,{children:[e.jsxs(a.SheetHeader,{children:[e.jsx(a.SheetTitle,{children:"Revision History"}),(i==null?void 0:i.createdAt)&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Page created on ",y.format(new Date(i.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),S?e.jsx(K,{}):h?e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Failed to load revisions. Please try again."}):e.jsxs("div",{className:"mt-2 flex h-full min-h-0 flex-1 flex-col space-y-2",children:[e.jsx(W,{lang:U,compare:n,setCompare:t,pageId:i==null?void 0:i.id}),e.jsx(J,{compare:n,setCompare:t}),(E=f==null?void 0:f.filter(o=>o.uid==="current"))==null?void 0:E.map((o,w)=>e.jsx(I,{pageId:i==null?void 0:i.id,revision:o,isLatest:!0,onRestore:()=>D(o),onDelete:()=>C(o),revisionNumber:w,compare:n,setCompare:t},o.uid)),e.jsx(a.ScrollArea,{className:"min-h-0 flex-1",children:e.jsx("div",{className:"space-y-2",children:(R=f==null?void 0:f.filter(o=>o.uid!=="current"))==null?void 0:R.map((o,w)=>e.jsx(I,{pageId:i==null?void 0:i.id,revision:o,isLatest:o.uid==="current",onRestore:()=>D(o),onDelete:()=>C(o),revisionNumber:w+1,compare:n,setCompare:t},o.uid))})})]}),e.jsx(X,{open:c,onOpenChange:x,revision:l,onRestore:G,isRestoring:F}),e.jsx(Z,{open:m,onOpenChange:u,revision:l,onDelete:V,isDeleting:M})]})}exports.default=ee;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),d=require("./index--Lu_Q_nO.cjs"),N=require("@tanstack/react-query"),O=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),y=require("date-fns"),L=require("lodash-es"),p=require("lucide-react"),b=require("react");function Q(s){const n=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(s){for(const t in s)if(t!=="default"){const l=Object.getOwnPropertyDescriptor(s,t);Object.defineProperty(n,t,l.get?l:{enumerable:!0,get:()=>s[t]})}}return n.default=s,Object.freeze(n)}const v=Q(b);function z(s){const n=d.useApiUrl(),t=d.useFetch();return N.useQuery({queryKey:[d.ACTIONS.GET_PAGE_REVISIONS,s],queryFn:async()=>await t(n,{action:d.ACTIONS.GET_PAGE_REVISIONS,data:{pageId:s}}),enabled:!!s,refetchOnMount:!0})}const B=()=>{const s=d.useApiUrl(),n=d.useFetch(),t=N.useQueryClient();return N.useMutation({mutationFn:async l=>await n(s,{action:d.ACTIONS.DELETE_PAGE_REVISION,data:{revisionId:l}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},H=()=>{const s=d.useApiUrl(),n=d.useFetch(),t=N.useQueryClient();return N.useMutation({mutationFn:async({revisionId:l,discardCurrent:r})=>await n(s,{action:d.ACTIONS.RESTORE_PAGE_REVISION,data:{revisionId:l,discardCurrent:r}}),onSuccess:()=>{t.invalidateQueries({queryKey:["revisions"]})}})},$=b.lazy(()=>Promise.resolve().then(()=>require("./json-diff-viewer-1IHmR_Nt.cjs"))),g=({tag:s})=>s==="draft"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-amber-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Draft"})]}):s==="live"?e.jsxs("span",{className:"flex items-center gap-1 rounded-full bg-primary/10 px-1.5 py-0.5 text-xs text-primary",children:[e.jsxs("span",{className:"relative flex h-2 w-2",children:[e.jsx("span",{className:"absolute inline-flex h-full w-full animate-ping rounded-full bg-green-400 opacity-75"}),e.jsx("span",{className:"relative inline-flex h-2 w-2 rounded-full bg-green-500"})]}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Live"})]}):s==="published"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-green-500/10 px-1.5 py-0.5 text-xs text-green-600",children:[e.jsx(p.Rocket,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Published"})]}):s==="unsaved"?e.jsxs("div",{className:"flex items-center gap-1 rounded-full bg-red-500/10 px-1.5 py-0.5 text-xs text-red-600",children:[e.jsx(p.Save,{className:"h-3 w-3"}),e.jsx("span",{className:"text-[11px] leading-tight",children:"Unsaved changes"})]}):e.jsx("span",{className:"rounded bg-purple-500/10 px-1.5 py-0.5 font-mono text-xs font-bold text-purple-600",children:s});function J({compare:s,setCompare:n}){const{data:t}=d.useCurrentPage(),{saveState:l}=O.useSavePage(),[r]=d.usePageEditInfo();if(!t)return null;const c=!!s.find(u=>{var i;return(i=u==null?void 0:u.uid)==null?void 0:i.startsWith("draft:")}),x=s.length>=2&&!c,m=l==="UNSAVED";return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border bg-primary/5 p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-1 text-sm font-medium leading-none",children:[e.jsx(g,{tag:"draft"}),e.jsx("span",{className:"text-xs font-bold",children:"Currently editing"})]})}),e.jsx("div",{className:"flex items-center pl-2 text-[11px] text-muted-foreground",children:!L.isEmpty(r.lastSaved)&&e.jsxs("span",{children:["Last updated"," ",y.formatDistanceToNow(new Date(r.lastSaved),{addSuffix:!0})]})}),e.jsx("div",{className:"flex items-center gap-2 pt-0.5",children:m?e.jsx(g,{tag:"unsaved"}):null})]}),e.jsx(A,{checked:c,disabled:x,onChange:()=>{n(c?s.filter(u=>u.uid!==`draft:${t==null?void 0:t.id}`):[...s,{uid:`draft:${t==null?void 0:t.id}`,label:"draft",item:{createdAt:Date.now()}}])}})]})}function K(){return e.jsx("div",{className:"mt-2 space-y-2",children:Array.from({length:5}).map((s,n)=>e.jsxs("div",{className:"flex items-start gap-3 rounded-md border p-2",children:[e.jsxs("div",{className:"flex-1 space-y-1",children:[e.jsx(a.Skeleton,{className:"h-4 w-3/4"}),e.jsx(a.Skeleton,{className:"h-3 w-1/2"}),e.jsx(a.Skeleton,{className:"mt-1 h-5 w-20"})]}),e.jsx(a.Skeleton,{className:"h-8 w-8 rounded-full"})]},n))})}function I({revision:s,isLatest:n,onRestore:t,onDelete:l,revisionNumber:r,compare:c,setCompare:x,pageId:m}){const{data:u}=d.useChaiUserInfo(s.currentEditor),i=(u==null?void 0:u.name)||"Unknown",f=!!c.find(h=>{var j;return n?(j=h==null?void 0:h.uid)==null?void 0:j.startsWith("live"):(h==null?void 0:h.uid)===s.uid}),S=c.length>=2&&!f;return e.jsxs("div",{className:"relative flex items-start gap-3 rounded-md border p-2 hover:bg-accent/50",children:[e.jsxs("div",{className:"flex-1 space-y-3",children:[e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("p",{className:"flex items-center gap-1 text-xs leading-none",children:[e.jsx(g,{tag:n?"live":`#${r}`}),s.type==="published"?"Published":"Draft"," by ",e.jsx("span",{className:"text-xs font-bold",children:i})]})}),e.jsxs("div",{className:"flex items-center gap-x-3",children:[e.jsx("div",{className:"flex items-center gap-2",children:s.type==="published"?e.jsx(g,{tag:"published"}):e.jsx(g,{tag:"draft"})}),e.jsx("div",{className:"flex items-center text-[10px] text-muted-foreground",children:e.jsx("span",{className:"leading-tight",children:y.format(s.createdAt,"MMM d, h:mm a")})})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(d.PermissionChecker,{permissions:[d.PAGES_PERMISSIONS.RESTORE_REVISION,d.PAGES_PERMISSIONS.DELETE_REVISION],children:e.jsx(Y,{revision:s,onRestore:t,onDelete:l})})}),e.jsx(A,{checked:f,disabled:S,onChange:()=>{x(f?c.filter(h=>n?h.uid!==`live:${m}`:h.uid!==s.uid):[...c,{uid:n?`live:${m}`:s.uid,label:n?"live":`#${r}`,item:s}].sort((h,j)=>new Date(h.item.createdAt).getTime()-new Date(j.item.createdAt).getTime()))}})]})}function W({compare:s,setCompare:n,pageId:t}){const[l,r]=b.useState(!1),[c,x]=s;if(s.length===0)return null;const m=({tab:u})=>e.jsxs("span",{className:"flex items-center justify-between rounded border border-blue-100 p-1 font-medium",children:[e.jsx(g,{tag:u.label}),e.jsx("button",{className:"z-0 flex h-4 w-4 items-center justify-center rounded-full text-gray-400 hover:text-red-500",style:{lineHeight:1},onClick:()=>n(s.filter(i=>i.uid!==u.uid)),"aria-label":"Remove selection 1",children:e.jsx(p.X,{className:"h-3 w-3"})})]});return e.jsxs("div",{className:"mb-2 flex w-full max-w-md flex-col gap-1 rounded border bg-accent/60 p-2 shadow-sm",children:[e.jsxs("div",{className:"flex items-center gap-x-2 text-xs",children:[e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"Compare"}),c&&e.jsx(m,{tab:c}),e.jsx("span",{className:"font-medium leading-tight text-gray-600",children:"with"}),x?e.jsx(m,{tab:x}):e.jsx("span",{className:"rounded border px-1 text-xs text-muted-foreground",children:"Choose another"})]}),e.jsxs("div",{className:"flex items-center justify-end gap-2 pb-0.5 pt-2",children:[e.jsx(a.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none text-gray-500",variant:"outline",onClick:()=>n([]),children:e.jsx("span",{children:" Clear"})}),e.jsxs(a.Button,{size:"sm",className:"h-6 gap-1 rounded px-2 text-xs leading-none",variant:"default",onClick:()=>r(!0),disabled:s.length<2,children:[e.jsx(p.FileJson,{className:"h-2.5 w-2.5"}),e.jsx("span",{className:"pt-0.5",children:"Show JSON Diff"})]})]}),l&&(s==null?void 0:s.length)>1&&t&&e.jsx(b.Suspense,{fallback:e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx("span",{className:"text-sm",children:"Loading diff viewer..."})}),children:e.jsx($,{open:l,onOpenChange:r,compare:s})})]})}function A({checked:s,disabled:n,onChange:t,label:l="Compare"}){return e.jsx("div",{className:"absolute bottom-2 right-2",children:e.jsxs("label",{className:`flex cursor-pointer items-center gap-x-1 text-[11px] ${n?"opacity-50":""}`,children:[e.jsx("input",{type:"checkbox",className:"h-3 w-3 cursor-pointer rounded focus:ring-0 focus:ring-offset-0",checked:s,disabled:n,onChange:t}),e.jsx("span",{className:"select-none leading-tight",children:l})]})})}function Y({revision:s,onRestore:n,onDelete:t}){return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",size:"icon",className:"h-5 w-5",children:[e.jsx(p.MoreHorizontal,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"More options"})]})}),e.jsxs(a.DropdownMenuContent,{align:"end",className:"text-xs",children:[e.jsx(d.PermissionChecker,{permission:d.PAGES_PERMISSIONS.RESTORE_REVISION,children:e.jsxs(a.DropdownMenuItem,{onClick:n,className:"cursor-pointer text-sm",children:[e.jsx(p.Undo2,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Restore this version"})]})}),e.jsx(d.PermissionChecker,{permission:d.PAGES_PERMISSIONS.DELETE_REVISION,children:s.uid!=="current"&&e.jsxs(e.Fragment,{children:[e.jsx(a.DropdownMenuSeparator,{}),e.jsxs(a.DropdownMenuItem,{onClick:t,className:"cursor-pointer text-destructive",children:[e.jsx(p.Trash,{className:"mr-2 h-4 w-4"}),e.jsx("span",{children:"Delete this version"})]})]})})]})]})}function X({open:s,onOpenChange:n,revision:t,onRestore:l,isRestoring:r}){const{data:c}=d.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),x=(c==null?void 0:c.name)||"Unknown";return t?e.jsx(a.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(a.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Restore Revision"}),e.jsxs(a.DialogDescription,{children:["You are about to restore to revision ",t.uid.substring(0,8)," from"," ",y.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",x]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"How would you like to handle your current edits?"})}),e.jsxs(a.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(a.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>l(!1),disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Saving as draft..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.CloudOff,{className:"mr-2 h-4 w-4"}),"Save as draft"]})}),e.jsx(a.Button,{variant:"default",className:"sm:flex-1",onClick:()=>l(!0),disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Discarding current..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Undo2,{className:"mr-2 h-4 w-4"}),"Discard current"]})})]})]})}):null}function Z({open:s,onOpenChange:n,revision:t,onDelete:l,isDeleting:r}){const{data:c}=d.useChaiUserInfo((t==null?void 0:t.currentEditor)||""),x=(c==null?void 0:c.name)||"Unknown";return t?e.jsx(a.Dialog,{open:s,onOpenChange:m=>{r||n(m)},children:e.jsxs(a.DialogContent,{className:"sm:max-w-md",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Delete Revision"}),e.jsxs(a.DialogDescription,{children:["You are about to delete revision ",t.uid.substring(0,8)," from"," ",y.format(t.createdAt,"MMM d, yyyy 'at' h:mm a")," by ",x]})]}),e.jsx("div",{className:"py-2",children:e.jsx("p",{className:"text-sm text-muted-foreground",children:"This action cannot be undone. Are you sure you want to proceed?"})}),e.jsxs(a.DialogFooter,{className:"flex flex-col gap-2 sm:flex-row",children:[e.jsx(a.Button,{variant:"outline",className:"sm:flex-1",onClick:()=>n(!1),disabled:r,children:"Cancel"}),e.jsx(a.Button,{variant:"destructive",className:"sm:flex-1",onClick:l,disabled:r,children:r?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mr-2 h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Deleting..."]}):e.jsxs(e.Fragment,{children:[e.jsx(p.Trash,{className:"mr-2 h-4 w-4"}),"Delete Revision"]})})]})]})}):null}function ee({isOpen:s}){var E,R;const[n,t]=v.useState([]),[l,r]=v.useState(null),[c,x]=v.useState(!1),[m,u]=v.useState(!1),{data:i}=d.useCurrentPage(),{data:f,isFetching:S,error:h,refetch:j}=z(i==null?void 0:i.id),{mutate:k,isPending:M}=B(),{mutate:T,isPending:F}=H(),_=N.useQueryClient(),{selectedLang:P,fallbackLang:q}=O.useLanguages(),U=P||q;b.useEffect(()=>t([]),[i==null?void 0:i.id]);const G=o=>{l&&T({revisionId:l.uid,discardCurrent:o},{onSuccess:()=>{x(!1),r(null),_.invalidateQueries({queryKey:[d.ACTIONS.GET_DRAFT_PAGE]})}})},D=o=>{r(o),x(!0)},C=o=>{r(o),u(!0)},V=()=>{l&&k(l.uid,{onSuccess:()=>{u(!1),r(null)}})};return b.useEffect(()=>{s&&j()},[s,j]),e.jsxs(e.Fragment,{children:[e.jsxs(a.SheetHeader,{children:[e.jsx(a.SheetTitle,{children:"Revision History"}),(i==null?void 0:i.createdAt)&&e.jsxs("p",{className:"mt-1 text-xs text-muted-foreground",children:["Page created on ",y.format(new Date(i.createdAt),"MMM d, yyyy 'at' h:mm a")]})]}),S?e.jsx(K,{}):h?e.jsx("div",{className:"p-4 text-center text-sm text-muted-foreground",children:"Failed to load revisions. Please try again."}):e.jsxs("div",{className:"mt-2 flex h-full min-h-0 flex-1 flex-col space-y-2",children:[e.jsx(W,{lang:U,compare:n,setCompare:t,pageId:i==null?void 0:i.id}),e.jsx(J,{compare:n,setCompare:t}),(E=f==null?void 0:f.filter(o=>o.uid==="current"))==null?void 0:E.map((o,w)=>e.jsx(I,{pageId:i==null?void 0:i.id,revision:o,isLatest:!0,onRestore:()=>D(o),onDelete:()=>C(o),revisionNumber:w,compare:n,setCompare:t},o.uid)),e.jsx(a.ScrollArea,{className:"min-h-0 flex-1",children:e.jsx("div",{className:"space-y-2",children:(R=f==null?void 0:f.filter(o=>o.uid!=="current"))==null?void 0:R.map((o,w)=>e.jsx(I,{pageId:i==null?void 0:i.id,revision:o,isLatest:o.uid==="current",onRestore:()=>D(o),onDelete:()=>C(o),revisionNumber:w+1,compare:n,setCompare:t},o.uid))})})]}),e.jsx(X,{open:c,onOpenChange:x,revision:l,onRestore:G,isRestoring:F}),e.jsx(Z,{open:m,onOpenChange:u,revision:l,onDelete:V,isDeleting:M})]})}exports.default=ee;
@@ -1,5 +1,5 @@
1
1
  import { jsxs as n, Fragment as p, jsx as e } from "react/jsx-runtime";
2
- import { aq as C, ar as A, A as b, aw as q, az as le, ao as I, ax as R, ay as w } from "./index-tOCLaJS0.js";
2
+ import { aq as C, ar as A, A as b, aw as q, az as le, ao as I, ax as R, ay as w } from "./index-B_T6ZeA4.js";
3
3
  import { useQuery as re, useQueryClient as O, useMutation as G } from "@tanstack/react-query";
4
4
  import { useLanguages as ie, useSavePage as de } from "@chaibuilder/sdk";
5
5
  import { SheetHeader as ce, SheetTitle as oe, ScrollArea as ue, Skeleton as y, Button as g, DropdownMenu as me, DropdownMenuTrigger as he, DropdownMenuContent as fe, DropdownMenuItem as U, DropdownMenuSeparator as pe, Dialog as j, DialogContent as L, DialogHeader as z, DialogTitle as P, DialogDescription as $, DialogFooter as H } from "@chaibuilder/sdk/ui";
@@ -46,7 +46,7 @@ const Ae = () => {
46
46
  });
47
47
  }
48
48
  });
49
- }, Oe = Se(() => import("./json-diff-viewer-BHsCH0rV.js")), N = ({ tag: t }) => t === "draft" ? /* @__PURE__ */ n("div", { className: "flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600", children: [
49
+ }, Oe = Se(() => import("./json-diff-viewer-D8uyTokS.js")), N = ({ tag: t }) => t === "draft" ? /* @__PURE__ */ n("div", { className: "flex items-center gap-1 rounded-full bg-amber-500/10 px-1.5 py-0.5 text-xs text-amber-600", children: [
50
50
  /* @__PURE__ */ n("span", { className: "relative flex h-2 w-2", children: [
51
51
  /* @__PURE__ */ e("span", { className: "absolute inline-flex h-full w-full animate-ping rounded-full bg-amber-400 opacity-75" }),
52
52
  /* @__PURE__ */ e("span", { className: "relative inline-flex h-2 w-2 rounded-full bg-amber-500" })
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),L=require("./page-manager-search-and-filter-Dp1Z6uDu.cjs"),r=require("./index-Nz9M0K-w.cjs"),U=require("@tanstack/react-query"),h=require("@chaibuilder/sdk/ui"),t=require("lodash-es"),b=require("lucide-react"),i=require("react"),F=()=>{const l=r.useApiUrl(),d=r.useFetch();return U.useQuery({queryKey:[r.ACTIONS.GET_CHANGES],queryFn:async()=>d(l,{action:r.ACTIONS.GET_CHANGES})})},M=({page:l,selectedPages:d,handleCheckboxChange:N,getPageType:y,hasSlug:m,currentOwnerId:a})=>{const x=r.useUserId(),{data:u}=r.useChaiUserInfo(a),c=a===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 ${c?"opacity-50":""}`,children:[c?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"})," ",m(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:c&&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:c})," is editing this page"]})})]},l==null?void 0:l.id)},G=({onClose:l=()=>{},isPending:d,publishPage:N})=>{const y=r.useUserId(),{pageToUser:m}=r.usePageToUser(),[a,x]=i.useState([]),u=r.useFallbackLang(),[c,p]=i.useState(u),{data:k,isFetching:P}=F(),{data:g}=r.usePageTypes(),T=i.useCallback(s=>{var n;return(n=t.find(g,{key:s}))==null?void 0:n.hasSlug},[g]),j=i.useMemo(()=>t.filter(g,s=>!T(s.key)).map(s=>s.key),[T,g]),C=t.uniq(t.map(k,"lang")).filter(Boolean),o=i.useMemo(()=>t.filter(k,s=>s.pageType==="theme"?!1:c===u?s.lang===c||s.lang==="":s.lang===c),[k,c,u]),w=i.useMemo(()=>t.filter(o,s=>!j.includes(s.pageType)),[o,j]),S=i.useMemo(()=>t.filter(o,s=>j.includes(s.pageType)),[o,j]);i.useEffect(()=>{const s=t.map(t.filter(o,{online:!0}),"id");x(s)},[o]),i.useEffect(()=>{const s=t.filter(t.keys(m),n=>t.get(m,[n,"userId"])!==y);x(n=>t.filter(n,f=>!t.includes(s,f)))},[m,y]);const v=a.length===(o==null?void 0:o.length),E=s=>{x(n=>t.includes(n,s)?t.filter(n,f=>f!==s):t.concat(n,s))},q=()=>{x(v?[]:t.map(o,"id"))},I=()=>{N({ids:t.uniq(a)},{onSuccess:()=>{l(),r.throwConfetti("CENTER_CENTER"),p(u)}})},A=s=>{if(s==="theme")return"Theme";const n=t.find(g,{key:s});return n?n==null?void 0:n.name:s},B=i.useMemo(()=>{const s=[{label:"Updated",top:"pt-2"},...t.orderBy(t.filter(w,{online:!0}),"pageType"),...t.orderBy(t.filter(S,{online:!0}),"pageType")].filter(f=>f.pageType!=="theme"),n=[{label:"Offline",top:"pt-6"},...t.orderBy(t.filter(w,{online:!1}),"pageType"),...t.orderBy(t.filter(S,{online:!1}),"pageType")];return[...s,...n]},[w,S]);return e.jsxs(h.DialogContent,{className:"flex max-h-[80%] max-w-4xl flex-col",children:[e.jsxs(h.DialogHeader,{children:[e.jsx(h.DialogTitle,{children:"Publish changes"}),e.jsx(h.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),C.length>0&&e.jsx("div",{className:"my-[2px] mt-0",children:e.jsx(L.LanguageSelector,{languages:[u,...C],selectedLanguage:c,setSelectedLanguage:p})}),e.jsx("div",{className:"no-scrollbar relative -mx-4 -mt-4 h-full max-h-full overflow-y-auto",children:P?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(),q()},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(B,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(M,{page:s,selectedPages:a,handleCheckboxChange:E,getPageType:A,hasSlug:T,currentOwnerId:t.get(m,[(s==null?void 0:s.primaryPage)||(s==null?void 0:s.id),"userId"])}))})]})}),e.jsxs(h.DialogFooter,{className:"mt-10 flex items-center justify-center",children:[a.length>0&&e.jsxs("span",{className:"text-center text-sm text-muted-foreground",children:[a.length," Page",a.length!==1?"s":""," Selected"]}),e.jsx(h.Button,{disabled:d,variant:"outline",onClick:l,children:"Cancel"}),e.jsx(h.Button,{disabled:d||P||t.isEmpty(a),onClick:I,children:d?"Publishing...":"Publish Selected"})]})]})};exports.default=G;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),L=require("./page-manager-search-and-filter-4JatGyBT.cjs"),r=require("./index--Lu_Q_nO.cjs"),U=require("@tanstack/react-query"),h=require("@chaibuilder/sdk/ui"),t=require("lodash-es"),b=require("lucide-react"),i=require("react"),F=()=>{const l=r.useApiUrl(),d=r.useFetch();return U.useQuery({queryKey:[r.ACTIONS.GET_CHANGES],queryFn:async()=>d(l,{action:r.ACTIONS.GET_CHANGES})})},M=({page:l,selectedPages:d,handleCheckboxChange:N,getPageType:y,hasSlug:m,currentOwnerId:a})=>{const x=r.useUserId(),{data:u}=r.useChaiUserInfo(a),c=a===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 ${c?"opacity-50":""}`,children:[c?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"})," ",m(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:c&&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:c})," is editing this page"]})})]},l==null?void 0:l.id)},G=({onClose:l=()=>{},isPending:d,publishPage:N})=>{const y=r.useUserId(),{pageToUser:m}=r.usePageToUser(),[a,x]=i.useState([]),u=r.useFallbackLang(),[c,p]=i.useState(u),{data:k,isFetching:P}=F(),{data:g}=r.usePageTypes(),T=i.useCallback(s=>{var n;return(n=t.find(g,{key:s}))==null?void 0:n.hasSlug},[g]),j=i.useMemo(()=>t.filter(g,s=>!T(s.key)).map(s=>s.key),[T,g]),C=t.uniq(t.map(k,"lang")).filter(Boolean),o=i.useMemo(()=>t.filter(k,s=>s.pageType==="theme"?!1:c===u?s.lang===c||s.lang==="":s.lang===c),[k,c,u]),w=i.useMemo(()=>t.filter(o,s=>!j.includes(s.pageType)),[o,j]),S=i.useMemo(()=>t.filter(o,s=>j.includes(s.pageType)),[o,j]);i.useEffect(()=>{const s=t.map(t.filter(o,{online:!0}),"id");x(s)},[o]),i.useEffect(()=>{const s=t.filter(t.keys(m),n=>t.get(m,[n,"userId"])!==y);x(n=>t.filter(n,f=>!t.includes(s,f)))},[m,y]);const v=a.length===(o==null?void 0:o.length),E=s=>{x(n=>t.includes(n,s)?t.filter(n,f=>f!==s):t.concat(n,s))},q=()=>{x(v?[]:t.map(o,"id"))},I=()=>{N({ids:t.uniq(a)},{onSuccess:()=>{l(),r.throwConfetti("CENTER_CENTER"),p(u)}})},A=s=>{if(s==="theme")return"Theme";const n=t.find(g,{key:s});return n?n==null?void 0:n.name:s},B=i.useMemo(()=>{const s=[{label:"Updated",top:"pt-2"},...t.orderBy(t.filter(w,{online:!0}),"pageType"),...t.orderBy(t.filter(S,{online:!0}),"pageType")].filter(f=>f.pageType!=="theme"),n=[{label:"Offline",top:"pt-6"},...t.orderBy(t.filter(w,{online:!1}),"pageType"),...t.orderBy(t.filter(S,{online:!1}),"pageType")];return[...s,...n]},[w,S]);return e.jsxs(h.DialogContent,{className:"flex max-h-[80%] max-w-4xl flex-col",children:[e.jsxs(h.DialogHeader,{children:[e.jsx(h.DialogTitle,{children:"Publish changes"}),e.jsx(h.DialogDescription,{className:"text-xs",children:"Select the pages you want to publish. Click publish when you're done."})]}),C.length>0&&e.jsx("div",{className:"my-[2px] mt-0",children:e.jsx(L.LanguageSelector,{languages:[u,...C],selectedLanguage:c,setSelectedLanguage:p})}),e.jsx("div",{className:"no-scrollbar relative -mx-4 -mt-4 h-full max-h-full overflow-y-auto",children:P?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(),q()},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(B,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(M,{page:s,selectedPages:a,handleCheckboxChange:E,getPageType:A,hasSlug:T,currentOwnerId:t.get(m,[(s==null?void 0:s.primaryPage)||(s==null?void 0:s.id),"userId"])}))})]})}),e.jsxs(h.DialogFooter,{className:"mt-10 flex items-center justify-center",children:[a.length>0&&e.jsxs("span",{className:"text-center text-sm text-muted-foreground",children:[a.length," Page",a.length!==1?"s":""," Selected"]}),e.jsx(h.Button,{disabled:d,variant:"outline",onClick:l,children:"Cancel"}),e.jsx(h.Button,{disabled:d||P||t.isEmpty(a),onClick:I,children:d?"Publishing...":"Publish Selected"})]})]})};exports.default=G;
@@ -1,6 +1,6 @@
1
1
  import { jsxs as n, jsx as t, Fragment as _ } from "react/jsx-runtime";
2
- import { LanguageSelector as $ } from "./page-manager-search-and-filter-B9kZBAGe.js";
3
- import { aq as K, ar as Q, A as L, aA as q, aB as J, k as V, m as W, ao as X, T as I, t as Y } from "./index-tOCLaJS0.js";
2
+ import { LanguageSelector as $ } from "./page-manager-search-and-filter-B86rQEO4.js";
3
+ import { aq as K, ar as Q, A as L, aA as q, aB as J, k as V, m as W, ao as X, T as I, t as Y } from "./index-B_T6ZeA4.js";
4
4
  import { useQuery as Z } from "@tanstack/react-query";
5
5
  import { DialogContent as ee, DialogHeader as te, DialogTitle as se, DialogDescription as le, DialogFooter as ae, Button as U } from "@chaibuilder/sdk/ui";
6
6
  import { find as F, filter as a, map as b, keys as ne, get as G, includes as C, orderBy as N, isEmpty as re, first as oe, uniq as B, concat as ce } from "lodash-es";
@@ -1,7 +1,7 @@
1
1
  import { jsx as e, jsxs as i } from "react/jsx-runtime";
2
2
  import { useMutation as U, useQuery as z, useQueryClient as se } from "@tanstack/react-query";
3
3
  import { toast as B } from "sonner";
4
- import { aq as L, ar as G, A as _, ay as ie } from "./index-tOCLaJS0.js";
4
+ import { aq as L, ar as G, A as _, ay as ie } from "./index-B_T6ZeA4.js";
5
5
  import { useUpdateBlocksPropsRealtime as K, usePartailBlocksStore as oe, usePermissions as le, useLibraryBlocks as ce } from "@chaibuilder/sdk";
6
6
  import { Button as b, Popover as de, PopoverTrigger as ue, PopoverContent as me, Input as D, Label as P } from "@chaibuilder/sdk/ui";
7
7
  import { Trash2 as Y, Plus as pe, ImageIcon as he, X as fe, AlertCircle as ge } from "lucide-react";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),I=require("@tanstack/react-query"),k=require("sonner"),x=require("./index-Nz9M0K-w.cjs"),E=require("@chaibuilder/sdk"),c=require("@chaibuilder/sdk/ui"),C=require("lucide-react"),i=require("react"),X=require("./image-compression-DZ9WMmyn.cjs"),R=require("lodash-es"),J=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{n(t)},onError:t=>{console.error("Error saving block:",t),k.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},Z=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useQuery({staleTime:"static",queryKey:[x.ACTIONS.GET_LIBRARY_ITEM,n],enabled:!!n,queryFn:async()=>{if(!n)return null;try{return await l(s,{action:x.ACTIONS.GET_LIBRARY_ITEM,data:{id:n}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},ee=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:t}}),onSuccess:()=>{n()},onError:t=>{console.error("Error deleting block:",t),k.toast.error("Failed to delete block",{description:t instanceof Error?t.message:"Unknown error"})}})},te=({blockId:n,libBlockId:s,isOpen:l,onClose:t,blockName:m,trigger:f})=>{const[u,o]=i.useState(!1),d=E.useUpdateBlocksPropsRealtime(),b=ee(()=>{d([n],{_libBlockId:void 0}),k.toast.success("Block deleted successfully"),o(!1),t()}),p=()=>{o(!0),b.mutate(s)},g=e.jsxs(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:h=>h.preventDefault(),disabled:u,children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]});return e.jsxs(c.Popover,{open:l,onOpenChange:h=>!h&&t(),children:[e.jsx(c.PopoverTrigger,{asChild:!0,children:f||g}),e.jsx(c.PopoverContent,{className:"w-72 p-4 z-[9999]",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',m,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:u,children:"Cancel"}),e.jsx(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:p,disabled:u,children:u?"Deleting...":"Delete"})]})]})})]})},se=({blockId:n,libBlockId:s,blockName:l,size:t="sm",className:m="",close:f})=>{const[u,o]=i.useState(!1);return e.jsx(te,{blockId:n,libBlockId:s,isOpen:u,onClose:()=>{o(!1),f()},blockName:l,trigger:e.jsxs(c.Button,{type:"button",variant:"destructive",size:t,className:m,onClick:()=>o(!0),children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]})})},re=()=>{const n=x.useApiUrl(),s=x.useFetch(),l=I.useQueryClient(),{data:t=[],isLoading:m,error:f}=I.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await s(n,{action:"GET_LIBRARY_GROUPS"})||[]}catch(d){return console.error("Error fetching library groups:",d),[]}}}),{mutateAsync:u,isPending:o}=I.useMutation({mutationFn:async d=>{if(!d.trim())throw new Error("Group name is required");return s(n,{action:"CREATE_BLOCK_GROUP",data:{name:d}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),k.toast.success("Group created successfully")},onError:d=>{console.error("Error creating group:",d),k.toast.error("Failed to create group",{description:d instanceof Error?d.message:"Unknown error"})}});return{groups:t,isLoading:m,error:f,createGroup:u,isCreating:o}},ne=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),[m,f]=i.useState(""),u=i.useRef(null),{groups:o}=re(),[d,b]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),p=i.useMemo(()=>[...o,...d.filter(r=>!o.some(j=>j.id===r.id))],[o,d]),g=()=>{const r=m.trim();if(!r)return;const j={id:r,name:r};b(w=>[...w,j]),s(j.id),f(""),t(!1)};i.useEffect(()=>{l&&u.current&&u.current.focus()},[l]);const h=r=>{r.key==="Enter"&&(r.preventDefault(),g())};return i.useEffect(()=>{n&&!p.some(r=>r.id===n)&&s("")},[n,p,s]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Input,{ref:u,placeholder:"Enter new group name",value:m,onChange:r=>f(r.target.value),onKeyDown:h}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(c.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:n,onChange:r=>s(r.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(r=>e.jsx("option",{value:r.id,children:r.name},`lib-${r.id}`))}),d.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:d.filter(r=>!o.some(j=>j.id===r.id)).map(r=>e.jsx("option",{value:r.id,children:r.name},`local-${r.id}`))})]}),e.jsx(c.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(C.Plus,{className:"h-4 w-4"})})]})},ae=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),m=i.useRef(null),f=i.useCallback(async d=>{var p;const b=(p=d.target.files)==null?void 0:p[0];if(b)try{t(!0);let g=b;b.type.startsWith("image/")&&(g=await X.compressImageIfNeeded(b));const h=new FileReader;h.onloadend=()=>{s(h.result),t(!1)},h.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),k.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[s]),u=()=>{s(""),m.current&&(m.current.value="")},o=()=>{var d;(d=m.current)==null||d.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(c.Input,{type:"file",ref:m,onChange:f,accept:"image/*",className:"hidden"}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(C.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),n&&e.jsx(c.Button,{type:"button",variant:"outline",size:"icon",onClick:u,children:e.jsx(C.X,{className:"h-4 w-4"})})]}),n&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:n,alt:"Preview",className:"h-full w-full object-contain"})})]})},oe=n=>{const{blocks:s,close:l,blockId:t}=n,{getPartailBlocks:m}=E.usePartailBlocksStore(),f=s.find(a=>a._id===t),u=f==null?void 0:f._libBlockId,o=!!u,d=i.useMemo(()=>s.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[s]),b=i.useMemo(()=>{let a=[];for(const y of s)if(y._type==="PartialBlock"||y._type==="GlobalBlock"){let v=m(y.partialBlockId);y._parent&&(v==null?void 0:v.length)>0&&(v=v.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",y._parent),T))),a=[...a,...v]}else a.push(y);return a},[s,m]),[p,g]=i.useState(""),[h,r]=i.useState(""),[j,w]=i.useState(""),[S,_]=i.useState(""),[N,A]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=E.usePermissions(),Q=Y(x.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=E.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),k.toast.success("Block delinked from library"),l()},{data:B,isLoading:P,isError:G}=Z(u);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{B&&!P&&(g(B.name||""),r(B.group||""),w(B.description||""),_(B.preview||""),F(!1))},[B,P]),i.useEffect(()=>{const a=p.trim().length>=2,y=h.trim()!=="";M(a&&y)},[p,h]);const W=()=>{const a={};return p.trim()?p.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",h||(a.group="Group is required"),A(a),Object.keys(a).length===0},{resetLibrary:$}=E.useLibraryBlocks({id:""}),U=J(a=>{o||D([t],{_libBlockId:a.id}),k.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const y=b.map(v=>(R.has(v,"_libBlockId")&&delete v._libBlockId,v));U.mutate({name:p.trim(),group:h,blocks:y,description:j.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:u}:{}})},L=U.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(c.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[d&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(C.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(c.Input,{id:"name",placeholder:"Enter block name",value:p,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ne,{value:h,onChange:r}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(c.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:j,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(ae,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(se,{blockId:t,libBlockId:u,blockName:p,className:"mr-auto",close:l}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(c.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=oe;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),I=require("@tanstack/react-query"),k=require("sonner"),x=require("./index--Lu_Q_nO.cjs"),E=require("@chaibuilder/sdk"),c=require("@chaibuilder/sdk/ui"),C=require("lucide-react"),i=require("react"),X=require("./image-compression-DZ9WMmyn.cjs"),R=require("lodash-es"),J=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.UPSERT_LIBRARY_ITEM,data:t}),onSuccess:t=>{n(t)},onError:t=>{console.error("Error saving block:",t),k.toast.error("Failed to save block",{description:t instanceof Error?t.message:"Unknown error"})}})},Z=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useQuery({staleTime:"static",queryKey:[x.ACTIONS.GET_LIBRARY_ITEM,n],enabled:!!n,queryFn:async()=>{if(!n)return null;try{return await l(s,{action:x.ACTIONS.GET_LIBRARY_ITEM,data:{id:n}})}catch(t){throw console.error(t),new Error("The block could not be found on the server. It may have been deleted.")}},retry:!1})},ee=n=>{const s=x.useApiUrl(),l=x.useFetch();return I.useMutation({mutationFn:async t=>l(s,{action:x.ACTIONS.DELETE_LIBRARY_ITEM,data:{id:t}}),onSuccess:()=>{n()},onError:t=>{console.error("Error deleting block:",t),k.toast.error("Failed to delete block",{description:t instanceof Error?t.message:"Unknown error"})}})},te=({blockId:n,libBlockId:s,isOpen:l,onClose:t,blockName:m,trigger:f})=>{const[u,o]=i.useState(!1),d=E.useUpdateBlocksPropsRealtime(),b=ee(()=>{d([n],{_libBlockId:void 0}),k.toast.success("Block deleted successfully"),o(!1),t()}),p=()=>{o(!0),b.mutate(s)},g=e.jsxs(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:h=>h.preventDefault(),disabled:u,children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]});return e.jsxs(c.Popover,{open:l,onOpenChange:h=>!h&&t(),children:[e.jsx(c.PopoverTrigger,{asChild:!0,children:f||g}),e.jsx(c.PopoverContent,{className:"w-72 p-4 z-[9999]",sideOffset:5,align:"center",children:e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"font-medium",children:"Delete Block"}),e.jsxs("p",{className:"text-sm",children:["Are you sure you want to delete the block",e.jsxs("span",{className:"font-medium",children:[' "',m,'"']}),"?"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"This block will be permanently removed from the library. This action cannot be undone."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(c.Button,{type:"button",variant:"outline",size:"sm",onClick:t,disabled:u,children:"Cancel"}),e.jsx(c.Button,{type:"button",variant:"destructive",size:"sm",onClick:p,disabled:u,children:u?"Deleting...":"Delete"})]})]})})]})},se=({blockId:n,libBlockId:s,blockName:l,size:t="sm",className:m="",close:f})=>{const[u,o]=i.useState(!1);return e.jsx(te,{blockId:n,libBlockId:s,isOpen:u,onClose:()=>{o(!1),f()},blockName:l,trigger:e.jsxs(c.Button,{type:"button",variant:"destructive",size:t,className:m,onClick:()=>o(!0),children:[e.jsx(C.Trash2,{className:"h-4 w-4 mr-2"}),"Delete"]})})},re=()=>{const n=x.useApiUrl(),s=x.useFetch(),l=I.useQueryClient(),{data:t=[],isLoading:m,error:f}=I.useQuery({queryKey:["library-groups"],staleTime:"static",placeholderData:[],queryFn:async()=>{try{return await s(n,{action:"GET_LIBRARY_GROUPS"})||[]}catch(d){return console.error("Error fetching library groups:",d),[]}}}),{mutateAsync:u,isPending:o}=I.useMutation({mutationFn:async d=>{if(!d.trim())throw new Error("Group name is required");return s(n,{action:"CREATE_BLOCK_GROUP",data:{name:d}})},onSuccess:()=>{l.invalidateQueries({queryKey:["library-groups"]}),k.toast.success("Group created successfully")},onError:d=>{console.error("Error creating group:",d),k.toast.error("Failed to create group",{description:d instanceof Error?d.message:"Unknown error"})}});return{groups:t,isLoading:m,error:f,createGroup:u,isCreating:o}},ne=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),[m,f]=i.useState(""),u=i.useRef(null),{groups:o}=re(),[d,b]=i.useState([{id:"hero",name:"Hero"},{id:"feature",name:"Feature"},{id:"footer",name:"Footer"},{id:"content",name:"Content"},{id:"testimonial",name:"Testimonial"},{id:"pricing",name:"Pricing"},{id:"login",name:"Login"},{id:"logos",name:"Logos"},{id:"about",name:"About"},{id:"banner",name:"Banner"},{id:"blog",name:"Blog"},{id:"careers",name:"Careers"},{id:"casestudy",name:"Casestudy"},{id:"changelog",name:"Changelog"},{id:"compare",name:"Compare"},{id:"contact",name:"Contact"},{id:"cta",name:"Cta"},{id:"faq",name:"Faq"},{id:"gallery",name:"Gallery"},{id:"integration",name:"Integration"},{id:"list",name:"List"},{id:"navbar",name:"Navbar"},{id:"product",name:"Product"},{id:"signup",name:"Signup"},{id:"stats",name:"Stats"},{id:"team",name:"Team"},{id:"timeline",name:"Timeline"}]),p=i.useMemo(()=>[...o,...d.filter(r=>!o.some(j=>j.id===r.id))],[o,d]),g=()=>{const r=m.trim();if(!r)return;const j={id:r,name:r};b(w=>[...w,j]),s(j.id),f(""),t(!1)};i.useEffect(()=>{l&&u.current&&u.current.focus()},[l]);const h=r=>{r.key==="Enter"&&(r.preventDefault(),g())};return i.useEffect(()=>{n&&!p.some(r=>r.id===n)&&s("")},[n,p,s]),l?e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Input,{ref:u,placeholder:"Enter new group name",value:m,onChange:r=>f(r.target.value),onKeyDown:h}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(c.Button,{variant:"outline",size:"sm",onClick:()=>t(!1),children:"Cancel"}),e.jsx(c.Button,{size:"sm",onClick:g,children:"Create"})]})]}):e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("select",{className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",value:n,onChange:r=>s(r.target.value),children:[e.jsx("option",{value:"",children:"Select a group"}),o.length>0&&e.jsx("optgroup",{label:"Library Groups",children:o.map(r=>e.jsx("option",{value:r.id,children:r.name},`lib-${r.id}`))}),d.length>0&&e.jsx("optgroup",{label:"Predefined Groups",children:d.filter(r=>!o.some(j=>j.id===r.id)).map(r=>e.jsx("option",{value:r.id,children:r.name},`local-${r.id}`))})]}),e.jsx(c.Button,{type:"button",size:"icon",variant:"outline",onClick:()=>t(!0),children:e.jsx(C.Plus,{className:"h-4 w-4"})})]})},ae=({value:n,onChange:s})=>{const[l,t]=i.useState(!1),m=i.useRef(null),f=i.useCallback(async d=>{var p;const b=(p=d.target.files)==null?void 0:p[0];if(b)try{t(!0);let g=b;b.type.startsWith("image/")&&(g=await X.compressImageIfNeeded(b));const h=new FileReader;h.onloadend=()=>{s(h.result),t(!1)},h.readAsDataURL(g)}catch(g){console.error("Error reading file:",g),t(!1),k.toast.error("Failed to process image",{description:g instanceof Error?g.message:"Unknown error"})}},[s]),u=()=>{s(""),m.current&&(m.current.value="")},o=()=>{var d;(d=m.current)==null||d.click()};return e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(c.Input,{type:"file",ref:m,onChange:f,accept:"image/*",className:"hidden"}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:o,disabled:l,className:"w-full",children:l?e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"h-4 w-4 animate-spin rounded-full border-2 border-current border-t-transparent"}),"Uploading..."]}):e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(C.ImageIcon,{className:"h-4 w-4"}),"Select image"]})}),n&&e.jsx(c.Button,{type:"button",variant:"outline",size:"icon",onClick:u,children:e.jsx(C.X,{className:"h-4 w-4"})})]}),n&&e.jsx("div",{className:"aspect-video h-[200px] max-h-[200px] overflow-hidden rounded-md border",children:e.jsx("img",{src:n,alt:"Preview",className:"h-full w-full object-contain"})})]})},oe=n=>{const{blocks:s,close:l,blockId:t}=n,{getPartailBlocks:m}=E.usePartailBlocksStore(),f=s.find(a=>a._id===t),u=f==null?void 0:f._libBlockId,o=!!u,d=i.useMemo(()=>s.some(a=>a._type==="PartialBlock"||a._type==="GlobalBlock"),[s]),b=i.useMemo(()=>{let a=[];for(const y of s)if(y._type==="PartialBlock"||y._type==="GlobalBlock"){let v=m(y.partialBlockId);y._parent&&(v==null?void 0:v.length)>0&&(v=v.map(T=>(R.isEmpty(T._parent)&&R.set(T,"_parent",y._parent),T))),a=[...a,...v]}else a.push(y);return a},[s,m]),[p,g]=i.useState(""),[h,r]=i.useState(""),[j,w]=i.useState(""),[S,_]=i.useState(""),[N,A]=i.useState({}),[q,M]=i.useState(!1),[O,F]=i.useState(o),[z,K]=i.useState(!1),{hasPermission:Y}=E.usePermissions(),Q=Y(x.PAGES_PERMISSIONS.DELETE_LIBRARY_BLOCK),D=E.useUpdateBlocksPropsRealtime(),V=()=>{D([t],{_libBlockId:void 0}),k.toast.success("Block delinked from library"),l()},{data:B,isLoading:P,isError:G}=Z(u);i.useEffect(()=>{G&&o&&(K(!0),F(!1))},[G,o]),i.useEffect(()=>{B&&!P&&(g(B.name||""),r(B.group||""),w(B.description||""),_(B.preview||""),F(!1))},[B,P]),i.useEffect(()=>{const a=p.trim().length>=2,y=h.trim()!=="";M(a&&y)},[p,h]);const W=()=>{const a={};return p.trim()?p.length<2&&(a.name="Name must be at least 2 characters"):a.name="Name is required",h||(a.group="Group is required"),A(a),Object.keys(a).length===0},{resetLibrary:$}=E.useLibraryBlocks({id:""}),U=J(a=>{o||D([t],{_libBlockId:a.id}),k.toast.success(`Block ${o?"updated":"saved"} successfully`),$(a.library),l()}),H=async a=>{if(a.preventDefault(),!W())return;const y=b.map(v=>(R.has(v,"_libBlockId")&&delete v._libBlockId,v));U.mutate({name:p.trim(),group:h,blocks:y,description:j.trim(),...S&&S.startsWith("data:")?{previewImage:S}:{},...o?{id:u}:{}})},L=U.isPending;return O||P?e.jsx("div",{className:"flex items-center justify-center p-8",children:e.jsx("div",{className:"h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"})}):z?e.jsxs("div",{className:"space-y-4 p-6",children:[e.jsx("div",{className:"font-medium text-destructive",children:"Block Not Found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"This block could not be found on the server. It may have been deleted."}),e.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,children:"Cancel"}),e.jsx(c.Button,{onClick:V,variant:"destructive",children:"Delink Block"})]})]}):e.jsxs("div",{children:[d&&e.jsxs("div",{className:"mb-4 flex items-start gap-2 rounded-md border border-destructive/50 bg-destructive/10 p-3 text-destructive",children:[e.jsx(C.AlertCircle,{className:"mt-0.5 h-5 w-5 flex-shrink-0"}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:"Partial Blocks Detected"}),e.jsx("p",{className:"mt-1 text-xs",children:"This block contains one or more Partial Blocks. Partial blocks will be merged into the library block"})]})]}),e.jsxs("form",{onSubmit:H,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"name",className:N.name?"text-destructive":"",children:"Name"}),e.jsx(c.Input,{id:"name",placeholder:"Enter block name",value:p,onChange:a=>g(a.target.value),className:N.name?"border-destructive":""}),N.name&&e.jsx("p",{className:"text-xs text-destructive",children:N.name})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"group",className:N.group?"text-destructive":"",children:"Group"}),e.jsx(ne,{value:h,onChange:r}),N.group&&e.jsx("p",{className:"text-xs text-destructive",children:N.group})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"description",children:"Description (optional)"}),e.jsx(c.Input,{id:"description",placeholder:"Enter a brief description",className:"resize-none",value:j,onChange:a=>w(a.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(c.Label,{htmlFor:"previewImage",children:"Preview Image (optional)"}),e.jsx(ae,{value:S,onChange:_})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[o&&Q&&e.jsx(se,{blockId:t,libBlockId:u,blockName:p,className:"mr-auto",close:l}),e.jsx(c.Button,{type:"button",variant:"outline",onClick:l,disabled:L,children:"Cancel"}),e.jsx(c.Button,{type:"submit",disabled:L||!q,children:L?"Saving...":o?"Update Block":"Save Block"})]})]})]})};exports.default=oe;
@@ -13,7 +13,7 @@ import { Streamdown as A } from "streamdown";
13
13
  import * as b from "@radix-ui/react-collapsible";
14
14
  import { useControllableState as T } from "@radix-ui/react-use-controllable-state";
15
15
  import { motion as X } from "motion/react";
16
- import { L as h } from "./index-tOCLaJS0.js";
16
+ import { L as h } from "./index-B_T6ZeA4.js";
17
17
  import { useTranslation as q, useSelectedBlock as H } from "@chaibuilder/sdk";
18
18
  import { Button as W } from "@chaibuilder/sdk/ui";
19
19
  function a(...e) {
@@ -1,4 +1,4 @@
1
- "use strict";const o=require("react/jsx-runtime"),g=require("lucide-react"),i=require("react"),h=require("use-stick-to-bottom"),L=require("@radix-ui/react-slot"),T=require("class-variance-authority"),G=require("clsx"),I=require("tailwind-merge"),$=require("@radix-ui/react-separator"),F=require("@radix-ui/react-tooltip"),R=require("streamdown"),V=require("@radix-ui/react-collapsible"),w=require("@radix-ui/react-use-controllable-state"),Q=require("motion/react"),p=require("./index-Nz9M0K-w.cjs"),y=require("@chaibuilder/sdk"),K=require("@chaibuilder/sdk/ui");function f(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const b=f(i),E=f($),k=f(F),v=f(V);function a(...e){return I.twMerge(G.clsx(e))}const Y=T.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),N=b.forwardRef(({className:e,variant:t,size:s,asChild:n=!1,...r},l)=>{const c=n?L.Slot:"button";return o.jsx(c,{className:a(Y({variant:t,size:s,className:e})),ref:l,...r})});N.displayName="Button";const J=({className:e,...t})=>o.jsx(h.StickToBottom,{className:a("relative flex-1 overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...t}),X=({className:e,...t})=>o.jsx(h.StickToBottom.Content,{className:a("flex flex-col gap-8 p-4",e),...t}),H=({className:e,title:t="No messages yet",description:s="Start a conversation to see messages here",icon:n,children:r,...l})=>o.jsx("div",{className:a("flex size-full flex-col items-center justify-center gap-3 p-8 text-center",e),...l,children:r??o.jsxs(o.Fragment,{children:[n&&o.jsx("div",{className:"text-muted-foreground",children:n}),o.jsxs("div",{className:"space-y-1",children:[o.jsx("h3",{className:"font-medium text-sm",children:t}),s&&o.jsx("p",{className:"text-muted-foreground text-sm",children:s})]})]})}),W=({className:e,...t})=>{const{isAtBottom:s,scrollToBottom:n}=h.useStickToBottomContext(),r=i.useCallback(()=>{n()},[n]);return!s&&o.jsx(N,{className:a("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",e),onClick:r,size:"icon",type:"button",variant:"outline",...t,children:o.jsx(g.ArrowDownIcon,{className:"size-4"})})},Z=b.forwardRef(({className:e,orientation:t="horizontal",decorative:s=!0,...n},r)=>o.jsx(E.Root,{ref:r,decorative:s,orientation:t,className:a("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...n}));Z.displayName=E.Root.displayName;T.cva("flex w-fit items-stretch has-[>[data-slot=button-group]]:gap-2 [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1",{variants:{orientation:{horizontal:"[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",vertical:"flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none"}},defaultVariants:{orientation:"horizontal"}});const ee=b.forwardRef(({className:e,sideOffset:t=4,...s},n)=>o.jsx(k.Content,{ref:n,sideOffset:t,className:a("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",e),...s}));ee.displayName=k.Content.displayName;const te=({className:e,from:t,...s})=>o.jsx("div",{className:a("group flex w-full max-w-[80%] flex-col gap-2",t==="user"?"is-user ml-auto justify-end":"is-assistant",e),...s}),oe=({children:e,className:t,...s})=>o.jsx("div",{className:a("is-user:dark flex w-fit flex-col gap-2 overflow-hidden text-sm","group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground","group-[.is-assistant]:text-foreground",t),...s,children:e});i.createContext(null);const A=i.memo(({className:e,...t})=>o.jsx(R.Streamdown,{className:a("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",e),...t}),(e,t)=>e.children===t.children);A.displayName="MessageResponse";const se=v.Root,ne=v.CollapsibleTrigger,re=v.CollapsibleContent,ae=({children:e,as:t="p",className:s,duration:n=2,spread:r=2})=>{const l=Q.motion.create(t),c=i.useMemo(()=>((e==null?void 0:e.length)??0)*r,[e,r]);return o.jsx(l,{animate:{backgroundPosition:"0% center"},className:a("relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent","[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]",s),initial:{backgroundPosition:"100% center"},style:{"--spread":`${c}px`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},transition:{repeat:Number.POSITIVE_INFINITY,duration:n,ease:"linear"},children:e})},U=i.memo(ae),_=i.createContext(null),ie=()=>{const e=i.useContext(_);if(!e)throw new Error("Reasoning components must be used within Reasoning");return e},le=1e3,ce=1e3,z=i.memo(({className:e,isStreaming:t=!1,open:s,defaultOpen:n=!0,onOpenChange:r,duration:l,children:c,...q})=>{const[d,u]=w.useControllableState({prop:s,defaultProp:n,onChange:r}),[O,C]=w.useControllableState({prop:l,defaultProp:void 0}),[j,B]=i.useState(!1),[m,S]=i.useState(null);i.useEffect(()=>{t?m===null&&S(Date.now()):m!==null&&(C(Math.ceil((Date.now()-m)/ce)),S(null))},[t,m,C]),i.useEffect(()=>{if(n&&!t&&d&&!j){const x=setTimeout(()=>{u(!1),B(!0)},le);return()=>clearTimeout(x)}},[t,d,n,u,j]);const D=x=>{u(x)};return o.jsx(_.Provider,{value:{isStreaming:t,isOpen:d,setIsOpen:u,duration:O},children:o.jsx(se,{className:a("not-prose mb-4",e),onOpenChange:D,open:d,...q,children:c})})}),de=(e,t)=>e||t===0?o.jsx(U,{duration:1,children:"Thinking..."}):t===void 0?o.jsx("p",{children:"Thought for a few seconds"}):o.jsxs("p",{children:["Thought for ",t," seconds"]}),M=i.memo(({className:e,children:t,...s})=>{const{isStreaming:n,isOpen:r,duration:l}=ie();return o.jsx(ne,{className:a("flex w-full items-center gap-2 text-sm text-muted-foreground transition-colors hover:text-foreground",e),...s,children:t??o.jsxs(o.Fragment,{children:[o.jsx(g.BrainIcon,{className:"size-4"}),de(n,l),o.jsx(g.ChevronDownIcon,{className:a("size-4 transition-transform",r?"rotate-180":"rotate-0")})]})})}),P=i.memo(({className:e,children:t,...s})=>o.jsx(re,{className:a("mt-4 text-sm","text-muted-foreground outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2",e),...s,children:o.jsx(R.Streamdown,{...s,children:t})}));z.displayName="Reasoning";M.displayName="ReasoningTrigger";P.displayName="ReasoningContent";const ue=({className:e,content:t,isLoading:s=!1,...n})=>o.jsx("div",{className:a("is-assistant flex w-full max-w-[80%] flex-col gap-2",e),...n,children:o.jsx("div",{className:"flex w-fit flex-col gap-2 overflow-hidden text-sm",children:o.jsx("div",{className:"flex items-center gap-2 rounded-lg border border-muted-foreground/20 bg-muted/50 p-3",children:o.jsxs("div",{className:"flex flex-1 items-center gap-2",children:[s&&o.jsx(U,{duration:1.5,children:t}),!s&&o.jsx("div",{className:"text-xs text-muted-foreground",children:t})]})})})});function me({userInput:e,language:t="en",currentHtml:s}){const n=p.LANGUAGES[t]||"English";return s&&s.trim().length>0?`
1
+ "use strict";const o=require("react/jsx-runtime"),g=require("lucide-react"),i=require("react"),h=require("use-stick-to-bottom"),L=require("@radix-ui/react-slot"),T=require("class-variance-authority"),G=require("clsx"),I=require("tailwind-merge"),$=require("@radix-ui/react-separator"),F=require("@radix-ui/react-tooltip"),R=require("streamdown"),V=require("@radix-ui/react-collapsible"),w=require("@radix-ui/react-use-controllable-state"),Q=require("motion/react"),p=require("./index--Lu_Q_nO.cjs"),y=require("@chaibuilder/sdk"),K=require("@chaibuilder/sdk/ui");function f(e){const t=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(e){for(const s in e)if(s!=="default"){const n=Object.getOwnPropertyDescriptor(e,s);Object.defineProperty(t,s,n.get?n:{enumerable:!0,get:()=>e[s]})}}return t.default=e,Object.freeze(t)}const b=f(i),E=f($),k=f(F),v=f(V);function a(...e){return I.twMerge(G.clsx(e))}const Y=T.cva("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground hover:bg-destructive/90",outline:"border border-input bg-background hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-10 px-4 py-2",sm:"h-9 rounded-md px-3",lg:"h-11 rounded-md px-8",icon:"h-10 w-10"}},defaultVariants:{variant:"default",size:"default"}}),N=b.forwardRef(({className:e,variant:t,size:s,asChild:n=!1,...r},l)=>{const c=n?L.Slot:"button";return o.jsx(c,{className:a(Y({variant:t,size:s,className:e})),ref:l,...r})});N.displayName="Button";const J=({className:e,...t})=>o.jsx(h.StickToBottom,{className:a("relative flex-1 overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...t}),X=({className:e,...t})=>o.jsx(h.StickToBottom.Content,{className:a("flex flex-col gap-8 p-4",e),...t}),H=({className:e,title:t="No messages yet",description:s="Start a conversation to see messages here",icon:n,children:r,...l})=>o.jsx("div",{className:a("flex size-full flex-col items-center justify-center gap-3 p-8 text-center",e),...l,children:r??o.jsxs(o.Fragment,{children:[n&&o.jsx("div",{className:"text-muted-foreground",children:n}),o.jsxs("div",{className:"space-y-1",children:[o.jsx("h3",{className:"font-medium text-sm",children:t}),s&&o.jsx("p",{className:"text-muted-foreground text-sm",children:s})]})]})}),W=({className:e,...t})=>{const{isAtBottom:s,scrollToBottom:n}=h.useStickToBottomContext(),r=i.useCallback(()=>{n()},[n]);return!s&&o.jsx(N,{className:a("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",e),onClick:r,size:"icon",type:"button",variant:"outline",...t,children:o.jsx(g.ArrowDownIcon,{className:"size-4"})})},Z=b.forwardRef(({className:e,orientation:t="horizontal",decorative:s=!0,...n},r)=>o.jsx(E.Root,{ref:r,decorative:s,orientation:t,className:a("shrink-0 bg-border",t==="horizontal"?"h-[1px] w-full":"h-full w-[1px]",e),...n}));Z.displayName=E.Root.displayName;T.cva("flex w-fit items-stretch has-[>[data-slot=button-group]]:gap-2 [&>*]:focus-visible:relative [&>*]:focus-visible:z-10 has-[select[aria-hidden=true]:last-child]:[&>[data-slot=select-trigger]:last-of-type]:rounded-r-md [&>[data-slot=select-trigger]:not([class*='w-'])]:w-fit [&>input]:flex-1",{variants:{orientation:{horizontal:"[&>*:not(:first-child)]:rounded-l-none [&>*:not(:first-child)]:border-l-0 [&>*:not(:last-child)]:rounded-r-none",vertical:"flex-col [&>*:not(:first-child)]:rounded-t-none [&>*:not(:first-child)]:border-t-0 [&>*:not(:last-child)]:rounded-b-none"}},defaultVariants:{orientation:"horizontal"}});const ee=b.forwardRef(({className:e,sideOffset:t=4,...s},n)=>o.jsx(k.Content,{ref:n,sideOffset:t,className:a("z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md animate-in fade-in-0 zoom-in-95 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-tooltip-content-transform-origin]",e),...s}));ee.displayName=k.Content.displayName;const te=({className:e,from:t,...s})=>o.jsx("div",{className:a("group flex w-full max-w-[80%] flex-col gap-2",t==="user"?"is-user ml-auto justify-end":"is-assistant",e),...s}),oe=({children:e,className:t,...s})=>o.jsx("div",{className:a("is-user:dark flex w-fit flex-col gap-2 overflow-hidden text-sm","group-[.is-user]:ml-auto group-[.is-user]:rounded-lg group-[.is-user]:bg-secondary group-[.is-user]:px-4 group-[.is-user]:py-3 group-[.is-user]:text-foreground","group-[.is-assistant]:text-foreground",t),...s,children:e});i.createContext(null);const A=i.memo(({className:e,...t})=>o.jsx(R.Streamdown,{className:a("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",e),...t}),(e,t)=>e.children===t.children);A.displayName="MessageResponse";const se=v.Root,ne=v.CollapsibleTrigger,re=v.CollapsibleContent,ae=({children:e,as:t="p",className:s,duration:n=2,spread:r=2})=>{const l=Q.motion.create(t),c=i.useMemo(()=>((e==null?void 0:e.length)??0)*r,[e,r]);return o.jsx(l,{animate:{backgroundPosition:"0% center"},className:a("relative inline-block bg-[length:250%_100%,auto] bg-clip-text text-transparent","[--bg:linear-gradient(90deg,#0000_calc(50%-var(--spread)),var(--color-background),#0000_calc(50%+var(--spread)))] [background-repeat:no-repeat,padding-box]",s),initial:{backgroundPosition:"100% center"},style:{"--spread":`${c}px`,backgroundImage:"var(--bg), linear-gradient(var(--color-muted-foreground), var(--color-muted-foreground))"},transition:{repeat:Number.POSITIVE_INFINITY,duration:n,ease:"linear"},children:e})},U=i.memo(ae),_=i.createContext(null),ie=()=>{const e=i.useContext(_);if(!e)throw new Error("Reasoning components must be used within Reasoning");return e},le=1e3,ce=1e3,z=i.memo(({className:e,isStreaming:t=!1,open:s,defaultOpen:n=!0,onOpenChange:r,duration:l,children:c,...q})=>{const[d,u]=w.useControllableState({prop:s,defaultProp:n,onChange:r}),[O,C]=w.useControllableState({prop:l,defaultProp:void 0}),[j,B]=i.useState(!1),[m,S]=i.useState(null);i.useEffect(()=>{t?m===null&&S(Date.now()):m!==null&&(C(Math.ceil((Date.now()-m)/ce)),S(null))},[t,m,C]),i.useEffect(()=>{if(n&&!t&&d&&!j){const x=setTimeout(()=>{u(!1),B(!0)},le);return()=>clearTimeout(x)}},[t,d,n,u,j]);const D=x=>{u(x)};return o.jsx(_.Provider,{value:{isStreaming:t,isOpen:d,setIsOpen:u,duration:O},children:o.jsx(se,{className:a("not-prose mb-4",e),onOpenChange:D,open:d,...q,children:c})})}),de=(e,t)=>e||t===0?o.jsx(U,{duration:1,children:"Thinking..."}):t===void 0?o.jsx("p",{children:"Thought for a few seconds"}):o.jsxs("p",{children:["Thought for ",t," seconds"]}),M=i.memo(({className:e,children:t,...s})=>{const{isStreaming:n,isOpen:r,duration:l}=ie();return o.jsx(ne,{className:a("flex w-full items-center gap-2 text-sm text-muted-foreground transition-colors hover:text-foreground",e),...s,children:t??o.jsxs(o.Fragment,{children:[o.jsx(g.BrainIcon,{className:"size-4"}),de(n,l),o.jsx(g.ChevronDownIcon,{className:a("size-4 transition-transform",r?"rotate-180":"rotate-0")})]})})}),P=i.memo(({className:e,children:t,...s})=>o.jsx(re,{className:a("mt-4 text-sm","text-muted-foreground outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:slide-out-to-top-2 data-[state=open]:slide-in-from-top-2",e),...s,children:o.jsx(R.Streamdown,{...s,children:t})}));z.displayName="Reasoning";M.displayName="ReasoningTrigger";P.displayName="ReasoningContent";const ue=({className:e,content:t,isLoading:s=!1,...n})=>o.jsx("div",{className:a("is-assistant flex w-full max-w-[80%] flex-col gap-2",e),...n,children:o.jsx("div",{className:"flex w-fit flex-col gap-2 overflow-hidden text-sm",children:o.jsx("div",{className:"flex items-center gap-2 rounded-lg border border-muted-foreground/20 bg-muted/50 p-3",children:o.jsxs("div",{className:"flex flex-1 items-center gap-2",children:[s&&o.jsx(U,{duration:1.5,children:t}),!s&&o.jsx("div",{className:"text-xs text-muted-foreground",children:t})]})})})});function me({userInput:e,language:t="en",currentHtml:s}){const n=p.LANGUAGES[t]||"English";return s&&s.trim().length>0?`
2
2
  MODE: EDIT
3
3
  CURRENT HTML:
4
4
  ${s}
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-Nz9M0K-w.cjs"),P=require("@chaibuilder/sdk"),d=require("lodash-es"),v=require("react"),a=require("@chaibuilder/sdk/ui"),L=require("sonner"),ce=require("@tanstack/react-query"),K=require("lucide-react"),M=require("./get-seo-defaults-Cw7vFt-B.cjs"),de=()=>{const{selectedLang:t}=P.useLanguages(),{data:x,isFetching:u}=i.useLanguagePages();return{data:v.useMemo(()=>d.find(x,{lang:t||""})||{},[x,t]),isFetching:u}},ue=()=>{var p;const x=(p=document.getElementById("canvas-iframe").contentDocument)==null?void 0:p.body.innerHTML;if(!x)return null;const c=new DOMParser().parseFromString(x,"text/html");c.querySelectorAll("style, script, link, svg, [data-block-type='PartialBlock']").forEach(g=>g.remove()),c.querySelectorAll("*").forEach(g=>{Array.from(g.attributes).forEach(m=>g.removeAttribute(m.name))});const r=c.querySelectorAll("h1, h2, h3, h4, h5, h6, p");return Array.from(r).map(g=>`<${g.tagName.toLowerCase()}>${g.innerHTML}</${g.tagName.toLowerCase()}>`).join(" ").replace(/<p>Partial block. Double click to edit.<\/p>/,"")},F=({keyword:t,onComplete:x,field:u})=>{const c=i.useFetch(),r=i.useApiUrl(),{selectedLang:N,fallbackLang:p}=P.useLanguages(),{mutate:g,isPending:m}=ce.useMutation({mutationFn:async()=>{const D=ue();return await c(r,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:u,lang:N||p,pageContent:D,keyword:t}})},onSuccess:D=>{x({fieldValue:D.field})},onError:D=>{x({fieldValue:null,error:D.message})}});return e.jsx(a.Button,{disabled:m,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>g(),children:m?e.jsx(K.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(K.Wand2Icon,{className:"text-yellow-500"})})},ge=({isOpen:t,onClose:x,onSave:u,onDiscard:c,isSaving:r=!1,fromLanguage:N,toLanguage:p})=>{const g=i.LANGUAGES[N]||N,m=i.LANGUAGES[p]||p;return e.jsx(a.Dialog,{open:t,onOpenChange:x,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Unsaved SEO Changes"}),e.jsxs(a.DialogDescription,{children:['You have unsaved changes in the SEO for "',g,'" version. Do you want to save these changes before switching to "',m,'" version?']})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(a.Button,{variant:"outline",onClick:c,disabled:r,children:"Discard Changes"}),e.jsx(a.Button,{onClick:u,disabled:r,children:r?"Saving...":"Save & Switch"})]})]})})},me=t=>{if(!t)return!0;try{return JSON.parse(t),!0}catch{return!1}},he=(t,x)=>{const u=t.selectionStart||0,c=t.selectionEnd||0,r=t.value,N=r.substring(0,u),p=r.substring(c),g=`{{${x}}}`,m=N+""+g+p,D=u+0+g.length;return{value:m,newCursorPos:D}},Q=()=>{const{t}=P.useTranslation(),[,x]=P.useSidebarActivePanel(),{data:u}=i.useCurrentPage(),{data:c}=i.useBuilderPageData(),{data:r,isFetching:N}=de(),p=r==null?void 0:r.seo,g=v.useRef(null),[m,D]=v.useState("seo"),R=u==null?void 0:u.id,W=u==null?void 0:u.pageType,I=i.usePageType(W),{selectedLang:$,fallbackLang:X}=P.useLanguages(),h=$||X,[H,J]=v.useState(!1),[Z,_]=v.useState(!1),[ee,V]=v.useState(!1),[S,U]=v.useState(null),[n,w]=v.useState({keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"{}",metaOther:"{}",...p}),E=v.useRef({}),{mutate:se,isPending:q}=i.useUpdatePage(),f=q||H||Z,{hasPermission:te}=P.usePermissions(),o=te(i.PAGES_PERMISSIONS.EDIT_SEO),[ae]=i.usePagesProps(),ne=d.get(ae,"features.canResetSeoToDefault",!1),z=!$||n.jsonLD!=="{}";v.useEffect(()=>{if(!N&&p&&R){const s={keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",metaOther:"",...p};w(s),E.current[h]=s}},[N,p,h,R]),v.useEffect(()=>{const s=l=>{const{fromLang:b,toLang:A,switchHandler:y}=l.detail,G=E.current[h];(G?!d.isEqual(G,n):!1)?(U({fromLang:b,toLang:A,switchHandler:y}),V(!0)):y()};return window.addEventListener("seo-language-switch-check",s),()=>{window.removeEventListener("seo-language-switch-check",s)}},[R,n,h]);const oe=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,keyword:d.get(s,"seo.keyword",""),title:d.get(s,"seo.title",""),description:d.get(s,"seo.description",""),cononicalUrl:d.get(s,"seo.canonicalUrl",""),noIndex:d.get(s,"seo.noIndex",!1),noFollow:d.get(s,"seo.noFollow",!1),ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription","")};w(l),L.toast.success(t("SEO fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset SEO fields")),console.error("Reset SEO error:",s)}finally{J(!1)}},le=async()=>{if(!(!I||!h))try{_(!0);const s=M.getSeoDefaults(I,h),l={...n,jsonLD:d.get(s,"seo.jsonLD","")};w(l),L.toast.success(t("JSON-LD reset to default"))}catch(s){L.toast.error(t("Failed to reset JSON-LD")),console.error("Reset JSON-LD error:",s)}finally{_(!1)}},re=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription",""),ogImage:d.get(s,"seo.ogImage",""),ogImageId:d.get(s,"seo.ogImageId",""),metaOther:d.get(s,"seo.metaOther","{}")};w(l),L.toast.success(t("Meta Tag fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset Meta Tag fields")),console.error("Reset Meta Tag error:",s)}finally{J(!1)}},Y=async()=>{se({id:r==null?void 0:r.id,seo:n,primaryPage:R},{onSuccess:()=>{console.log("SEO & JSON-LD updated successfully",n),E.current[h]=n,L.toast.success("SEO & JSON-LD updated successfully")}})},O=(s,l)=>{const b=document.getElementById(l);if(b){const{value:A,newCursorPos:y}=he(b,s);g.current={id:l,position:y},b.tagName.toLowerCase()==="input"?(b.value=A,w(C=>({...C,[b.name]:A})),b.focus(),b.setSelectionRange(y,y),[0,10,50,100,200].forEach(C=>{setTimeout(()=>{const B=document.getElementById(l);B&&(B.focus(),B.setSelectionRange(y,y))},C)})):(w(T=>({...T,[b.name]:A})),requestAnimationFrame(()=>{const T=document.getElementById(l);T&&(T.focus(),T.setSelectionRange(y,y),setTimeout(()=>{const C=document.getElementById(l);C&&(C.focus(),C.setSelectionRange(y,y))},50))}))}},j=s=>{const l={...n,[s.target.name]:s.target.name==="noIndex"||s.target.name==="noFollow"?s.target.checked:s.target.value};w(l)},k=s=>l=>{d.isEmpty(l.fieldValue)||j({target:{name:s,value:typeof l.fieldValue=="string"?l.fieldValue.replace(/^"(.*)"$/,"$1"):l.fieldValue}}),l.error&&L.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to generate:"}),e.jsx("p",{children:l.error})]}))},ie=()=>{const s=d.get(u,"seo.jsonLD","{}");if((s==null?void 0:s.trim())==="{}"){L.toast.error("Default page JSON-LD is empty");return}j({target:{name:"jsonLD",value:s}})};return e.jsxs("div",{className:"relative flex h-full flex-col","data-panel-id":"seo",children:[!o&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center backdrop-blur-sm",children:e.jsx(a.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:e.jsx(a.AlertDescription,{children:t("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),e.jsxs("div",{className:"no-scrollbar flex-grow overflow-y-auto px-2 pb-20",children:[e.jsxs("div",{className:"mb-4 flex w-full items-center justify-between rounded-md bg-gray-100 px-2 py-1 text-left text-sm",children:[e.jsxs("span",{children:[e.jsx("div",{className:"font-medium",children:r==null?void 0:r.name}),e.jsx("span",{className:"font-mono text-xs leading-tight text-gray-500",children:r==null?void 0:r.slug})]}),e.jsx(i.LanguageSwitcher,{variant:"outline",showAdd:!1})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(a.Tabs,{value:m,onValueChange:D,className:"w-full",children:[e.jsxs(a.TabsList,{className:"mb-4 grid w-full grid-cols-3",children:[e.jsx(a.TabsTrigger,{value:"seo",children:t("SEO")}),e.jsx(a.TabsTrigger,{value:"opengraph",children:t("Meta Tags")}),e.jsx(a.TabsTrigger,{value:"jsonld",children:t("JSON-LD")})]}),e.jsx("div",{className:m==="seo"?"":"sr-only",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"keyword",children:t("Keyword")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"keyword")})]}),e.jsx(a.Input,{type:"text",id:"keyword",name:"keyword",value:n.keyword,onChange:j,disabled:f||!o,placeholder:t("Enter keyword"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("SEO Title")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("title"),field:"title"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"title")})]})]}),e.jsx(a.Input,{type:"text",id:"title",name:"title",value:n.title,onChange:j,disabled:f||!o,placeholder:t("Enter SEO title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"description",children:t("SEO Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("description"),field:"description"}),o&&e.jsx(i.NestedPathSelector,{data:c??{},onSelect:s=>O(s,"description")})]})]}),e.jsx(a.Textarea,{id:"description",name:"description",rows:5,value:n.description,onChange:j,disabled:f||!o,placeholder:t("Enter SEO description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("Canonical URL")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"canonicalUrl")})]}),e.jsx(a.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:n.canonicalUrl,onChange:j,disabled:f||!o,placeholder:t("Enter Canonical URL"),readOnly:!o})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:n.noIndex,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Index")})]}),e.jsx("p",{className:"mt-0 text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to index this page.")})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:n.noFollow,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Follow")})]}),e.jsx("p",{className:"text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to follow links on this page.")})]})]})}),e.jsx("div",{className:m==="opengraph"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"mb-4 font-semibold text-slate-700",children:t("Open Graph")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogTitle",children:t("OG Title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogTitle"),field:"ogTitle"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogTitle")})]})]}),e.jsx(a.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:n.ogTitle,onChange:j,disabled:f||!o,placeholder:t("Enter OG title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogDescription",children:t("OG Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogDescription"),field:"ogDescription"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogDescription")})]})]}),e.jsx(a.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:n.ogDescription,onChange:j,disabled:f||!o,placeholder:t("Enter OG description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogImage",children:t("OG Image")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>{w({...n,ogImage:`{{${s}}}`,ogImageId:""})}})]}),e.jsx(i.ImagePicker,{assetId:n.ogImageId,assetUrl:n.ogImage,onChange:s=>{w({...n,ogImage:s.url,ogImageId:s.id})},disabled:f||!o,placeholder:t("Select OG image"),className:"mb-2"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"metaOther",children:t("Meta Tags")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("metaOther"),field:"metaOther"})})]}),e.jsx(i.SmartJsonInput,{id:"metaOther",value:n.metaOther,onChange:s=>{j({target:{name:"metaOther",value:s}})},placeholder:t("Enter Meta Tags JSON"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:8,handleFieldInsert:O})]})]})]})})}),e.jsx("div",{className:m==="jsonld"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"jsonLD",children:t("JSON-LD")}),z&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("jsonLD"),field:"jsonLD"})})]}),e.jsx("div",{className:"hidden",children:JSON.stringify(c)}),e.jsx(i.SmartJsonInput,{id:"jsonLD",value:n.jsonLD,onChange:s=>{j({target:{name:"jsonLD",value:s}})},placeholder:t("Enter JSON-LD"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:12,handleFieldInsert:O,hasJsonLdForSelectedLang:z,copyJsonLDFromDefaultPage:ie})]})})})]})})]}),o&&e.jsxs("div",{className:"fixed bottom-0 left-0 right-0 flex w-full flex-shrink-0 items-center justify-between border-t bg-background p-4",children:[ne?e.jsx(a.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{m==="jsonld"?le():m==="opengraph"?re():oe()},disabled:f||!o||!I,children:t(H?"Resetting...":`Reset to ${m==="jsonld"?"Default JSON-LD":m==="opengraph"?"Default Open Graph":"Default SEO"}`)}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(a.Button,{onClick:Y,disabled:!me(n==null?void 0:n.jsonLD)||(E.current[h]?d.isEqual(E.current[h],n):!1)||f||!o,children:t(q?"Saving...":"Save")}),e.jsx(a.Button,{variant:"link",className:"text-gray-500 hover:text-gray-700",onClick:()=>x("outline"),children:t("Cancel")})]})]}),e.jsx(ge,{isOpen:ee,onClose:()=>{V(!1),U(null)},onSave:async()=>{S&&(await Y(),S.switchHandler(),V(!1),U(null))},onDiscard:()=>{if(S){const s=E.current[h];s&&w(s),S.switchHandler(),V(!1),U(null)}},isSaving:q,fromLanguage:(S==null?void 0:S.fromLang)||h,toLanguage:(S==null?void 0:S.toLang)||""})]})};Q.displayName="SeoPanel";exports.default=Q;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index--Lu_Q_nO.cjs"),P=require("@chaibuilder/sdk"),d=require("lodash-es"),v=require("react"),a=require("@chaibuilder/sdk/ui"),L=require("sonner"),ce=require("@tanstack/react-query"),K=require("lucide-react"),M=require("./get-seo-defaults-Cw7vFt-B.cjs"),de=()=>{const{selectedLang:t}=P.useLanguages(),{data:x,isFetching:u}=i.useLanguagePages();return{data:v.useMemo(()=>d.find(x,{lang:t||""})||{},[x,t]),isFetching:u}},ue=()=>{var p;const x=(p=document.getElementById("canvas-iframe").contentDocument)==null?void 0:p.body.innerHTML;if(!x)return null;const c=new DOMParser().parseFromString(x,"text/html");c.querySelectorAll("style, script, link, svg, [data-block-type='PartialBlock']").forEach(g=>g.remove()),c.querySelectorAll("*").forEach(g=>{Array.from(g.attributes).forEach(m=>g.removeAttribute(m.name))});const r=c.querySelectorAll("h1, h2, h3, h4, h5, h6, p");return Array.from(r).map(g=>`<${g.tagName.toLowerCase()}>${g.innerHTML}</${g.tagName.toLowerCase()}>`).join(" ").replace(/<p>Partial block. Double click to edit.<\/p>/,"")},F=({keyword:t,onComplete:x,field:u})=>{const c=i.useFetch(),r=i.useApiUrl(),{selectedLang:N,fallbackLang:p}=P.useLanguages(),{mutate:g,isPending:m}=ce.useMutation({mutationFn:async()=>{const D=ue();return await c(r,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:u,lang:N||p,pageContent:D,keyword:t}})},onSuccess:D=>{x({fieldValue:D.field})},onError:D=>{x({fieldValue:null,error:D.message})}});return e.jsx(a.Button,{disabled:m,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>g(),children:m?e.jsx(K.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(K.Wand2Icon,{className:"text-yellow-500"})})},ge=({isOpen:t,onClose:x,onSave:u,onDiscard:c,isSaving:r=!1,fromLanguage:N,toLanguage:p})=>{const g=i.LANGUAGES[N]||N,m=i.LANGUAGES[p]||p;return e.jsx(a.Dialog,{open:t,onOpenChange:x,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Unsaved SEO Changes"}),e.jsxs(a.DialogDescription,{children:['You have unsaved changes in the SEO for "',g,'" version. Do you want to save these changes before switching to "',m,'" version?']})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(a.Button,{variant:"outline",onClick:c,disabled:r,children:"Discard Changes"}),e.jsx(a.Button,{onClick:u,disabled:r,children:r?"Saving...":"Save & Switch"})]})]})})},me=t=>{if(!t)return!0;try{return JSON.parse(t),!0}catch{return!1}},he=(t,x)=>{const u=t.selectionStart||0,c=t.selectionEnd||0,r=t.value,N=r.substring(0,u),p=r.substring(c),g=`{{${x}}}`,m=N+""+g+p,D=u+0+g.length;return{value:m,newCursorPos:D}},Q=()=>{const{t}=P.useTranslation(),[,x]=P.useSidebarActivePanel(),{data:u}=i.useCurrentPage(),{data:c}=i.useBuilderPageData(),{data:r,isFetching:N}=de(),p=r==null?void 0:r.seo,g=v.useRef(null),[m,D]=v.useState("seo"),R=u==null?void 0:u.id,W=u==null?void 0:u.pageType,I=i.usePageType(W),{selectedLang:$,fallbackLang:X}=P.useLanguages(),h=$||X,[H,J]=v.useState(!1),[Z,_]=v.useState(!1),[ee,V]=v.useState(!1),[S,U]=v.useState(null),[n,w]=v.useState({keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"{}",metaOther:"{}",...p}),E=v.useRef({}),{mutate:se,isPending:q}=i.useUpdatePage(),f=q||H||Z,{hasPermission:te}=P.usePermissions(),o=te(i.PAGES_PERMISSIONS.EDIT_SEO),[ae]=i.usePagesProps(),ne=d.get(ae,"features.canResetSeoToDefault",!1),z=!$||n.jsonLD!=="{}";v.useEffect(()=>{if(!N&&p&&R){const s={keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",metaOther:"",...p};w(s),E.current[h]=s}},[N,p,h,R]),v.useEffect(()=>{const s=l=>{const{fromLang:b,toLang:A,switchHandler:y}=l.detail,G=E.current[h];(G?!d.isEqual(G,n):!1)?(U({fromLang:b,toLang:A,switchHandler:y}),V(!0)):y()};return window.addEventListener("seo-language-switch-check",s),()=>{window.removeEventListener("seo-language-switch-check",s)}},[R,n,h]);const oe=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,keyword:d.get(s,"seo.keyword",""),title:d.get(s,"seo.title",""),description:d.get(s,"seo.description",""),cononicalUrl:d.get(s,"seo.canonicalUrl",""),noIndex:d.get(s,"seo.noIndex",!1),noFollow:d.get(s,"seo.noFollow",!1),ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription","")};w(l),L.toast.success(t("SEO fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset SEO fields")),console.error("Reset SEO error:",s)}finally{J(!1)}},le=async()=>{if(!(!I||!h))try{_(!0);const s=M.getSeoDefaults(I,h),l={...n,jsonLD:d.get(s,"seo.jsonLD","")};w(l),L.toast.success(t("JSON-LD reset to default"))}catch(s){L.toast.error(t("Failed to reset JSON-LD")),console.error("Reset JSON-LD error:",s)}finally{_(!1)}},re=async()=>{if(!(!I||!h))try{J(!0);const s=M.getSeoDefaults(I,h),l={...n,ogTitle:d.get(s,"seo.ogTitle",""),ogDescription:d.get(s,"seo.ogDescription",""),ogImage:d.get(s,"seo.ogImage",""),ogImageId:d.get(s,"seo.ogImageId",""),metaOther:d.get(s,"seo.metaOther","{}")};w(l),L.toast.success(t("Meta Tag fields reset to defaults"))}catch(s){L.toast.error(t("Failed to reset Meta Tag fields")),console.error("Reset Meta Tag error:",s)}finally{J(!1)}},Y=async()=>{se({id:r==null?void 0:r.id,seo:n,primaryPage:R},{onSuccess:()=>{console.log("SEO & JSON-LD updated successfully",n),E.current[h]=n,L.toast.success("SEO & JSON-LD updated successfully")}})},O=(s,l)=>{const b=document.getElementById(l);if(b){const{value:A,newCursorPos:y}=he(b,s);g.current={id:l,position:y},b.tagName.toLowerCase()==="input"?(b.value=A,w(C=>({...C,[b.name]:A})),b.focus(),b.setSelectionRange(y,y),[0,10,50,100,200].forEach(C=>{setTimeout(()=>{const B=document.getElementById(l);B&&(B.focus(),B.setSelectionRange(y,y))},C)})):(w(T=>({...T,[b.name]:A})),requestAnimationFrame(()=>{const T=document.getElementById(l);T&&(T.focus(),T.setSelectionRange(y,y),setTimeout(()=>{const C=document.getElementById(l);C&&(C.focus(),C.setSelectionRange(y,y))},50))}))}},j=s=>{const l={...n,[s.target.name]:s.target.name==="noIndex"||s.target.name==="noFollow"?s.target.checked:s.target.value};w(l)},k=s=>l=>{d.isEmpty(l.fieldValue)||j({target:{name:s,value:typeof l.fieldValue=="string"?l.fieldValue.replace(/^"(.*)"$/,"$1"):l.fieldValue}}),l.error&&L.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to generate:"}),e.jsx("p",{children:l.error})]}))},ie=()=>{const s=d.get(u,"seo.jsonLD","{}");if((s==null?void 0:s.trim())==="{}"){L.toast.error("Default page JSON-LD is empty");return}j({target:{name:"jsonLD",value:s}})};return e.jsxs("div",{className:"relative flex h-full flex-col","data-panel-id":"seo",children:[!o&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center backdrop-blur-sm",children:e.jsx(a.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:e.jsx(a.AlertDescription,{children:t("You don't have permission to edit SEO settings. Contact your administrator for access.")})})}),e.jsxs("div",{className:"no-scrollbar flex-grow overflow-y-auto px-2 pb-20",children:[e.jsxs("div",{className:"mb-4 flex w-full items-center justify-between rounded-md bg-gray-100 px-2 py-1 text-left text-sm",children:[e.jsxs("span",{children:[e.jsx("div",{className:"font-medium",children:r==null?void 0:r.name}),e.jsx("span",{className:"font-mono text-xs leading-tight text-gray-500",children:r==null?void 0:r.slug})]}),e.jsx(i.LanguageSwitcher,{variant:"outline",showAdd:!1})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(a.Tabs,{value:m,onValueChange:D,className:"w-full",children:[e.jsxs(a.TabsList,{className:"mb-4 grid w-full grid-cols-3",children:[e.jsx(a.TabsTrigger,{value:"seo",children:t("SEO")}),e.jsx(a.TabsTrigger,{value:"opengraph",children:t("Meta Tags")}),e.jsx(a.TabsTrigger,{value:"jsonld",children:t("JSON-LD")})]}),e.jsx("div",{className:m==="seo"?"":"sr-only",children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"keyword",children:t("Keyword")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"keyword")})]}),e.jsx(a.Input,{type:"text",id:"keyword",name:"keyword",value:n.keyword,onChange:j,disabled:f||!o,placeholder:t("Enter keyword"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("SEO Title")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("title"),field:"title"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"title")})]})]}),e.jsx(a.Input,{type:"text",id:"title",name:"title",value:n.title,onChange:j,disabled:f||!o,placeholder:t("Enter SEO title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"description",children:t("SEO Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("description"),field:"description"}),o&&e.jsx(i.NestedPathSelector,{data:c??{},onSelect:s=>O(s,"description")})]})]}),e.jsx(a.Textarea,{id:"description",name:"description",rows:5,value:n.description,onChange:j,disabled:f||!o,placeholder:t("Enter SEO description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"title",children:t("Canonical URL")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"canonicalUrl")})]}),e.jsx(a.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:n.canonicalUrl,onChange:j,disabled:f||!o,placeholder:t("Enter Canonical URL"),readOnly:!o})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:n.noIndex,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Index")})]}),e.jsx("p",{className:"mt-0 text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to index this page.")})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(a.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:n.noFollow,onChange:j,disabled:f||!o,className:"h-4 w-4"}),e.jsx(a.Label,{className:"pb-1 text-xs",htmlFor:"noIndex",children:t("No Follow")})]}),e.jsx("p",{className:"text-[10px] font-light leading-4 text-gray-400",children:t("Check this if you don't want search engines to follow links on this page.")})]})]})}),e.jsx("div",{className:m==="opengraph"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx("h3",{className:"mb-4 font-semibold text-slate-700",children:t("Open Graph")}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogTitle",children:t("OG Title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogTitle"),field:"ogTitle"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogTitle")})]})]}),e.jsx(a.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:n.ogTitle,onChange:j,disabled:f||!o,placeholder:t("Enter OG title"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogDescription",children:t("OG Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(F,{keyword:n.keyword,onComplete:k("ogDescription"),field:"ogDescription"}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>O(s,"ogDescription")})]})]}),e.jsx(a.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:n.ogDescription,onChange:j,disabled:f||!o,placeholder:t("Enter OG description"),readOnly:!o})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"ogImage",children:t("OG Image")}),o&&e.jsx(i.NestedPathSelector,{dataType:"value",data:c??{},onSelect:s=>{w({...n,ogImage:`{{${s}}}`,ogImageId:""})}})]}),e.jsx(i.ImagePicker,{assetId:n.ogImageId,assetUrl:n.ogImage,onChange:s=>{w({...n,ogImage:s.url,ogImageId:s.id})},disabled:f||!o,placeholder:t("Select OG image"),className:"mb-2"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"metaOther",children:t("Meta Tags")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("metaOther"),field:"metaOther"})})]}),e.jsx(i.SmartJsonInput,{id:"metaOther",value:n.metaOther,onChange:s=>{j({target:{name:"metaOther",value:s}})},placeholder:t("Enter Meta Tags JSON"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:8,handleFieldInsert:O})]})]})]})})}),e.jsx("div",{className:m==="jsonld"?"":"sr-only",children:e.jsx("div",{className:"space-y-4",children:e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(a.Label,{className:"text-xs",htmlFor:"jsonLD",children:t("JSON-LD")}),z&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(F,{keyword:n.keyword,onComplete:k("jsonLD"),field:"jsonLD"})})]}),e.jsx("div",{className:"hidden",children:JSON.stringify(c)}),e.jsx(i.SmartJsonInput,{id:"jsonLD",value:n.jsonLD,onChange:s=>{j({target:{name:"jsonLD",value:s}})},placeholder:t("Enter JSON-LD"),disabled:f||!o,readOnly:!o,pageData:c||{},rows:12,handleFieldInsert:O,hasJsonLdForSelectedLang:z,copyJsonLDFromDefaultPage:ie})]})})})]})})]}),o&&e.jsxs("div",{className:"fixed bottom-0 left-0 right-0 flex w-full flex-shrink-0 items-center justify-between border-t bg-background p-4",children:[ne?e.jsx(a.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{m==="jsonld"?le():m==="opengraph"?re():oe()},disabled:f||!o||!I,children:t(H?"Resetting...":`Reset to ${m==="jsonld"?"Default JSON-LD":m==="opengraph"?"Default Open Graph":"Default SEO"}`)}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(a.Button,{onClick:Y,disabled:!me(n==null?void 0:n.jsonLD)||(E.current[h]?d.isEqual(E.current[h],n):!1)||f||!o,children:t(q?"Saving...":"Save")}),e.jsx(a.Button,{variant:"link",className:"text-gray-500 hover:text-gray-700",onClick:()=>x("outline"),children:t("Cancel")})]})]}),e.jsx(ge,{isOpen:ee,onClose:()=>{V(!1),U(null)},onSave:async()=>{S&&(await Y(),S.switchHandler(),V(!1),U(null))},onDiscard:()=>{if(S){const s=E.current[h];s&&w(s),S.switchHandler(),V(!1),U(null)}},isSaving:q,fromLanguage:(S==null?void 0:S.fromLang)||h,toLanguage:(S==null?void 0:S.toLang)||""})]})};Q.displayName="SeoPanel";exports.default=Q;
@@ -1,5 +1,5 @@
1
1
  import { jsx as e, jsxs as s } from "react/jsx-runtime";
2
- import { l as ye, ar as ve, aq as xe, A as Ne, L as Z, aw as we, aN as Se, aO as De, i as be, ay as Oe, aP as Le, aQ as Ce, aR as E, aS as Ie, aE as ee } from "./index-tOCLaJS0.js";
2
+ import { l as ye, ar as ve, aq as xe, A as Ne, L as Z, aw as we, aN as Se, aO as De, i as be, ay as Oe, aP as Le, aQ as Ce, aR as E, aS as Ie, aE as ee } from "./index-B_T6ZeA4.js";
3
3
  import { useLanguages as z, useTranslation as ke, useSidebarActivePanel as Ee, usePermissions as Te } from "@chaibuilder/sdk";
4
4
  import { find as Fe, get as h, isEqual as te, isEmpty as je } from "lodash-es";
5
5
  import { useMemo as Re, useRef as ae, useState as j, useEffect as se } from "react";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),I=require("@tanstack/react-query"),c=require("./index-Nz9M0K-w.cjs"),s=require("@chaibuilder/sdk/ui"),G=require("lodash-es"),f=require("lucide-react"),x=require("react"),E=require("sonner"),q=()=>{const t=c.useApiUrl(),d=c.useFetch();return I.useQuery({queryKey:[c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>d(t,{action:c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},U=({show:t,onClose:d,initialData:n})=>e.jsx(s.Dialog,{open:t,onOpenChange:()=>d(),children:t&&e.jsx(_,{show:t,onClose:d,initialData:n})}),_=({show:t,onClose:d,initialData:n})=>{const[r,p]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[N,C]=x.useState(!1),{data:g}=c.useCurrentPage(),{mutateAsync:A,isPending:j}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),v=I.useQueryClient();x.useEffect(()=>{p(n?{name:n.name,description:n.description,content:JSON.stringify(n.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),C(!1)},[t,n]);const i=async()=>{if(!r.name||!r.content){E.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){E.toast.error("Invalid JSON-LD content");return}const b={name:r.name,jsonld:l.parsed,addToExistingPages:N,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(b.primaryPage=n.primaryPageId);const w=await A(b);g!=null&&g.id&&(w!=null&&w.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:w.id,pageId:g.id,enabled:!0}),v.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,g.id]})),d()};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Add New Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[(n==null?void 0:n.languageCode)&&e.jsxs(s.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(f.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(s.AlertDescription,{className:"text-sm text-blue-800",children:["You are creating a ",e.jsx("span",{className:"font-semibold",children:n.languageCode})," language version of this schema. This will be linked to the default language schema."]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-name",children:"Schema Name"}),e.jsx(s.Input,{id:"new-name",value:r.name,onChange:l=>p({...r,name:l.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-description",children:"Description"}),e.jsx(s.Input,{id:"new-description",value:r.description||"",onChange:l=>p({...r,description:l.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"new-content",value:r.content||"{}",onChange:l=>p({...r,content:l}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!(n!=null&&n.primaryPageId)&&e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"add-to-all-existing",checked:N,onChange:l=>C(l.target.checked),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"add-to-all-existing",children:[e.jsx("div",{children:"Add to all existing pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"This schema will be added to all existing pages on your site"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"new-enabled",checked:r.enabledByDefaultForNewPages,onChange:l=>p({...r,enabledByDefaultForNewPages:l.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"new-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(s.Button,{disabled:j,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:j,type:"button",size:"sm",onClick:i,children:j?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Adding"]}):e.jsxs(e.Fragment,{children:["Add Schema",(n==null?void 0:n.languageCode)&&` (${n.languageCode})`]})})]})})]})]})},H=({id:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:()=>d(),children:t&&e.jsx(Q,{id:t,onClose:d})}),Q=({id:t,onClose:d})=>{const[n,r]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[p,N]=x.useState(!1),[C,g]=x.useState(!1),[A,j]=x.useState(!1),{data:u}=q(),{mutateAsync:v,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:b}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var m,D;if(t&&u){const y=u.find(P=>P.id===t);y&&(r({name:y.name,description:((m=y.metadata)==null?void 0:m.description)||"",content:JSON.stringify(y.jsonld,null,2),enabledByDefaultForNewPages:((D=y.metadata)==null?void 0:D.addToNewPages)||!1}),j(!!y.primaryPage))}},[t,u]);const w=async()=>{if(!n.name||!n.content){E.toast.error("Please enter a name and content");return}const m=c.parseJSONWithPlaceholders(n.content);if(!m.isValid){E.toast.error("Invalid JSON-LD content");return}const D={id:t,name:n.name,jsonld:m.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await v(D),d()},F=async()=>{try{await l(t)}finally{N(!1)}},T=async()=>{try{await b(t)}finally{g(!1)}};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Edit Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[!A&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-blue-900",children:"Manage Existing Pages"}),e.jsx("div",{className:"text-xs text-blue-700",children:"Add or remove this schema from all existing pages on your site"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>N(!0),children:"Add to all existing"}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>g(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(s.Input,{id:"edit-name",value:n.name,onChange:m=>r({...n,name:m.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-description",children:"Description"}),e.jsx(s.Input,{id:"edit-description",value:n.description||"",onChange:m=>r({...n,description:m.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"edit-content",value:n.content||"{}",onChange:m=>r({...n,content:m}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!A&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onChange:m=>r({...n,enabledByDefaultForNewPages:m.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"edit-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(s.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:i,type:"button",size:"sm",onClick:w,children:i?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:p,onOpenChange:N,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Add to All Existing Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will add the schema ",e.jsx("span",{className:"font-medium",children:n.name})," to all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:F,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:C,onOpenChange:g,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Remove from All Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will remove the schema ",e.jsx("span",{className:"font-medium",children:n.name})," from all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:T,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function V(){const[t,d]=x.useState(!1),[n,r]=x.useState(void 0),[p,N]=x.useState(null),[C,g]=x.useState(null),[A,j]=x.useState(null),{data:u,isLoading:v}=q(),{selectedLang:i}=M.useLanguages(),{data:l}=c.useCurrentPage(),{data:b}=c.useLanguagePages(),{mutateAsync:w}=c.useDeleteGlobalSchema(),{mutateAsync:F}=c.useTogglePageGlobalSchema(),T=x.useMemo(()=>b==null?void 0:b.find(a=>!a.primaryPage&&a.lang===""),[b]),m=x.useMemo(()=>(T==null?void 0:T.globalJsonLds)||[],[T]),D=x.useMemo(()=>u?G.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const h=i?G.find(u,S=>S.primaryPage===o.id&&S.lang===i):null;return{defaultSchema:o,languageVersion:h,displayItem:h||o,hasLanguageVersion:!!h}}):[],[u,i]),[y,P]=x.useState([]),L=y.length>0?y:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&P(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const z=async a=>{if(!(l!=null&&l.id))return;j(a);const o=L.includes(a),h=o?L.filter(S=>S!==a):[...L,a];P(h);try{await F({schemaId:a,pageId:l.id,enabled:!o})}catch{P(l.globalJsonLds)}finally{j(null)}},R=async a=>{j(a);try{await w(a)}finally{j(null)}};return e.jsxs("div",{className:"rounded border bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center justify-between pb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium",children:"Shared JSON-LD Templates"}),e.jsx("div",{className:"w-full text-xs text-gray-500",children:"Manage reusable JSON-LD schemas that can be applied across multiple pages"})]}),!i&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{type:"button",disabled:v,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:v?e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(f.Plus,{className:"h-4 w-4"})}),e.jsx(s.TooltipContent,{children:"Add new schema"})]})]}),e.jsxs(s.ScrollArea,{className:"max-h-96 overflow-y-auto",children:[e.jsxs("div",{className:"space-y-2",children:[(!u||(u==null?void 0:u.length)===0)&&!v&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),D.map(({defaultSchema:a,displayItem:o,hasLanguageVersion:h})=>{var k,B;const S=L.includes(o.id),O=m.includes(a.id),J=h&&i?O:S;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${A===o.id?"pointer-events-none":""}`,children:[A===o.id&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 flex items-center justify-center rounded-xl bg-white/80",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin text-primary"})}),e.jsx(s.CardHeader,{className:"p-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[(h||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:J,onChange:()=>z(a.id),disabled:!!(h&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),h&&i&&e.jsx(s.TooltipContent,{children:"Using the default language state"})]}),e.jsxs("div",{children:[e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-sm leading-none",children:[o.name,h&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),J&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((k=o==null?void 0:o.metadata)==null?void 0:k.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(B=o==null?void 0:o.metadata)==null?void 0:B.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"mx-2 h-6 w-px bg-border"}),e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>g(o.id),children:e.jsx(f.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(h||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>N(o.id),children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Edit schema"})]}),e.jsxs(s.AlertDialog,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.AlertDialogTrigger,{className:"flex h-5 w-5 items-center justify-center rounded-md text-red-500 hover:bg-red-100 hover:text-red-800",children:e.jsx(f.Trash,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Delete schema"})]}),e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Schema"}),e.jsxs(s.AlertDialogDescription,{children:["Are you sure you want to delete"," ",e.jsx("span",{className:"font-medium",children:o.name}),"? This action cannot be undone."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{type:"button",children:"Cancel"}),e.jsx(s.AlertDialogAction,{type:"button",onClick:()=>R(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!h&&i&&e.jsx(s.CardContent,{className:"px-2 pb-2",children:e.jsxs("div",{className:"flex w-full flex-col items-center justify-center rounded-lg border bg-gray-100 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"max-w-xl text-center text-xs text-gray-500",children:["Not available in '",i,"' language. Default language JSONLD will be used."]}),O&&e.jsx("span",{className:"rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700",children:"Enabled in default"})]}),e.jsx(s.Button,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>{r({name:a.name,description:a.description||"",jsonld:a.jsonld,languageCode:i,primaryPageId:a.id}),d(!0)},children:"Copy & Edit from default language"})]})})]},a.id)})]}),v&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(U,{show:t,onClose:()=>{d(!1),r(void 0)},initialData:n}),e.jsx(H,{id:p,onClose:()=>N(null)}),e.jsx(K,{schema:u==null?void 0:u.find(a=>a.id===C),onClose:()=>g(null)})]})}const K=({schema:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[t==null?void 0:t.name,(t==null?void 0:t.lang)&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",t.lang,")"]})]})}),e.jsxs("div",{className:"space-y-3",children:[(t==null?void 0:t.description)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Description"}),e.jsx("div",{className:"text-sm",children:t.description})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"JSON-LD Schema"}),e.jsx(s.Textarea,{value:JSON.stringify(t==null?void 0:t.jsonld,null,2),readOnly:!0,className:"font-mono text-xs",rows:15})]})]})]})});exports.default=V;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),I=require("@tanstack/react-query"),c=require("./index--Lu_Q_nO.cjs"),s=require("@chaibuilder/sdk/ui"),G=require("lodash-es"),f=require("lucide-react"),x=require("react"),E=require("sonner"),q=()=>{const t=c.useApiUrl(),d=c.useFetch();return I.useQuery({queryKey:[c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>d(t,{action:c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},U=({show:t,onClose:d,initialData:n})=>e.jsx(s.Dialog,{open:t,onOpenChange:()=>d(),children:t&&e.jsx(_,{show:t,onClose:d,initialData:n})}),_=({show:t,onClose:d,initialData:n})=>{const[r,p]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[N,C]=x.useState(!1),{data:g}=c.useCurrentPage(),{mutateAsync:A,isPending:j}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),v=I.useQueryClient();x.useEffect(()=>{p(n?{name:n.name,description:n.description,content:JSON.stringify(n.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),C(!1)},[t,n]);const i=async()=>{if(!r.name||!r.content){E.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){E.toast.error("Invalid JSON-LD content");return}const b={name:r.name,jsonld:l.parsed,addToExistingPages:N,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(b.primaryPage=n.primaryPageId);const w=await A(b);g!=null&&g.id&&(w!=null&&w.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:w.id,pageId:g.id,enabled:!0}),v.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,g.id]})),d()};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Add New Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[(n==null?void 0:n.languageCode)&&e.jsxs(s.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(f.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(s.AlertDescription,{className:"text-sm text-blue-800",children:["You are creating a ",e.jsx("span",{className:"font-semibold",children:n.languageCode})," language version of this schema. This will be linked to the default language schema."]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-name",children:"Schema Name"}),e.jsx(s.Input,{id:"new-name",value:r.name,onChange:l=>p({...r,name:l.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-description",children:"Description"}),e.jsx(s.Input,{id:"new-description",value:r.description||"",onChange:l=>p({...r,description:l.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"new-content",value:r.content||"{}",onChange:l=>p({...r,content:l}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!(n!=null&&n.primaryPageId)&&e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"add-to-all-existing",checked:N,onChange:l=>C(l.target.checked),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"add-to-all-existing",children:[e.jsx("div",{children:"Add to all existing pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"This schema will be added to all existing pages on your site"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"new-enabled",checked:r.enabledByDefaultForNewPages,onChange:l=>p({...r,enabledByDefaultForNewPages:l.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"new-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(s.Button,{disabled:j,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:j,type:"button",size:"sm",onClick:i,children:j?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Adding"]}):e.jsxs(e.Fragment,{children:["Add Schema",(n==null?void 0:n.languageCode)&&` (${n.languageCode})`]})})]})})]})]})},H=({id:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:()=>d(),children:t&&e.jsx(Q,{id:t,onClose:d})}),Q=({id:t,onClose:d})=>{const[n,r]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[p,N]=x.useState(!1),[C,g]=x.useState(!1),[A,j]=x.useState(!1),{data:u}=q(),{mutateAsync:v,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:b}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var m,D;if(t&&u){const y=u.find(P=>P.id===t);y&&(r({name:y.name,description:((m=y.metadata)==null?void 0:m.description)||"",content:JSON.stringify(y.jsonld,null,2),enabledByDefaultForNewPages:((D=y.metadata)==null?void 0:D.addToNewPages)||!1}),j(!!y.primaryPage))}},[t,u]);const w=async()=>{if(!n.name||!n.content){E.toast.error("Please enter a name and content");return}const m=c.parseJSONWithPlaceholders(n.content);if(!m.isValid){E.toast.error("Invalid JSON-LD content");return}const D={id:t,name:n.name,jsonld:m.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await v(D),d()},F=async()=>{try{await l(t)}finally{N(!1)}},T=async()=>{try{await b(t)}finally{g(!1)}};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Edit Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[!A&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-blue-900",children:"Manage Existing Pages"}),e.jsx("div",{className:"text-xs text-blue-700",children:"Add or remove this schema from all existing pages on your site"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>N(!0),children:"Add to all existing"}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>g(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(s.Input,{id:"edit-name",value:n.name,onChange:m=>r({...n,name:m.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-description",children:"Description"}),e.jsx(s.Input,{id:"edit-description",value:n.description||"",onChange:m=>r({...n,description:m.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"edit-content",value:n.content||"{}",onChange:m=>r({...n,content:m}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!A&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onChange:m=>r({...n,enabledByDefaultForNewPages:m.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"edit-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(s.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:i,type:"button",size:"sm",onClick:w,children:i?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:p,onOpenChange:N,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Add to All Existing Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will add the schema ",e.jsx("span",{className:"font-medium",children:n.name})," to all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:F,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:C,onOpenChange:g,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Remove from All Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will remove the schema ",e.jsx("span",{className:"font-medium",children:n.name})," from all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:T,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function V(){const[t,d]=x.useState(!1),[n,r]=x.useState(void 0),[p,N]=x.useState(null),[C,g]=x.useState(null),[A,j]=x.useState(null),{data:u,isLoading:v}=q(),{selectedLang:i}=M.useLanguages(),{data:l}=c.useCurrentPage(),{data:b}=c.useLanguagePages(),{mutateAsync:w}=c.useDeleteGlobalSchema(),{mutateAsync:F}=c.useTogglePageGlobalSchema(),T=x.useMemo(()=>b==null?void 0:b.find(a=>!a.primaryPage&&a.lang===""),[b]),m=x.useMemo(()=>(T==null?void 0:T.globalJsonLds)||[],[T]),D=x.useMemo(()=>u?G.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const h=i?G.find(u,S=>S.primaryPage===o.id&&S.lang===i):null;return{defaultSchema:o,languageVersion:h,displayItem:h||o,hasLanguageVersion:!!h}}):[],[u,i]),[y,P]=x.useState([]),L=y.length>0?y:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&P(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const z=async a=>{if(!(l!=null&&l.id))return;j(a);const o=L.includes(a),h=o?L.filter(S=>S!==a):[...L,a];P(h);try{await F({schemaId:a,pageId:l.id,enabled:!o})}catch{P(l.globalJsonLds)}finally{j(null)}},R=async a=>{j(a);try{await w(a)}finally{j(null)}};return e.jsxs("div",{className:"rounded border bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center justify-between pb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium",children:"Shared JSON-LD Templates"}),e.jsx("div",{className:"w-full text-xs text-gray-500",children:"Manage reusable JSON-LD schemas that can be applied across multiple pages"})]}),!i&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{type:"button",disabled:v,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:v?e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(f.Plus,{className:"h-4 w-4"})}),e.jsx(s.TooltipContent,{children:"Add new schema"})]})]}),e.jsxs(s.ScrollArea,{className:"max-h-96 overflow-y-auto",children:[e.jsxs("div",{className:"space-y-2",children:[(!u||(u==null?void 0:u.length)===0)&&!v&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),D.map(({defaultSchema:a,displayItem:o,hasLanguageVersion:h})=>{var k,B;const S=L.includes(o.id),O=m.includes(a.id),J=h&&i?O:S;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${A===o.id?"pointer-events-none":""}`,children:[A===o.id&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 flex items-center justify-center rounded-xl bg-white/80",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin text-primary"})}),e.jsx(s.CardHeader,{className:"p-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[(h||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:J,onChange:()=>z(a.id),disabled:!!(h&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),h&&i&&e.jsx(s.TooltipContent,{children:"Using the default language state"})]}),e.jsxs("div",{children:[e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-sm leading-none",children:[o.name,h&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),J&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((k=o==null?void 0:o.metadata)==null?void 0:k.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(B=o==null?void 0:o.metadata)==null?void 0:B.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"mx-2 h-6 w-px bg-border"}),e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>g(o.id),children:e.jsx(f.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(h||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>N(o.id),children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Edit schema"})]}),e.jsxs(s.AlertDialog,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.AlertDialogTrigger,{className:"flex h-5 w-5 items-center justify-center rounded-md text-red-500 hover:bg-red-100 hover:text-red-800",children:e.jsx(f.Trash,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Delete schema"})]}),e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Schema"}),e.jsxs(s.AlertDialogDescription,{children:["Are you sure you want to delete"," ",e.jsx("span",{className:"font-medium",children:o.name}),"? This action cannot be undone."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{type:"button",children:"Cancel"}),e.jsx(s.AlertDialogAction,{type:"button",onClick:()=>R(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!h&&i&&e.jsx(s.CardContent,{className:"px-2 pb-2",children:e.jsxs("div",{className:"flex w-full flex-col items-center justify-center rounded-lg border bg-gray-100 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"max-w-xl text-center text-xs text-gray-500",children:["Not available in '",i,"' language. Default language JSONLD will be used."]}),O&&e.jsx("span",{className:"rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700",children:"Enabled in default"})]}),e.jsx(s.Button,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>{r({name:a.name,description:a.description||"",jsonld:a.jsonld,languageCode:i,primaryPageId:a.id}),d(!0)},children:"Copy & Edit from default language"})]})})]},a.id)})]}),v&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(U,{show:t,onClose:()=>{d(!1),r(void 0)},initialData:n}),e.jsx(H,{id:p,onClose:()=>N(null)}),e.jsx(K,{schema:u==null?void 0:u.find(a=>a.id===C),onClose:()=>g(null)})]})}const K=({schema:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[t==null?void 0:t.name,(t==null?void 0:t.lang)&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",t.lang,")"]})]})}),e.jsxs("div",{className:"space-y-3",children:[(t==null?void 0:t.description)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Description"}),e.jsx("div",{className:"text-sm",children:t.description})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"JSON-LD Schema"}),e.jsx(s.Textarea,{value:JSON.stringify(t==null?void 0:t.jsonld,null,2),readOnly:!0,className:"font-mono text-xs",rows:15})]})]})]})});exports.default=V;
@@ -1,7 +1,7 @@
1
1
  import { jsx as e, jsxs as n, Fragment as G } from "react/jsx-runtime";
2
2
  import { useLanguages as me } from "@chaibuilder/sdk";
3
3
  import { useQuery as he, useQueryClient as ue } from "@tanstack/react-query";
4
- import { aq as ge, ar as fe, A as U, aw as te, aC as pe, aD as se, aE as re, aF as de, aG as xe, aH as Ne, aI as be, l as ye, aJ as ve } from "./index-tOCLaJS0.js";
4
+ import { aq as ge, ar as fe, A as U, aw as te, aC as pe, aD as se, aE as re, aF as de, aG as xe, aH as Ne, aI as be, l as ye, aJ as ve } from "./index-B_T6ZeA4.js";
5
5
  import { Dialog as $, DialogContent as W, DialogHeader as Y, DialogTitle as X, Alert as we, AlertDescription as Ae, Label as y, Input as j, Button as v, AlertDialog as _, AlertDialogContent as R, AlertDialogHeader as q, AlertDialogTitle as M, AlertDialogDescription as H, AlertDialogFooter as Q, AlertDialogCancel as V, AlertDialogAction as K, Tooltip as L, TooltipTrigger as J, TooltipContent as F, ScrollArea as Ce, Card as Se, CardHeader as Pe, CardTitle as Te, AlertDialogTrigger as De, CardContent as Ee, Textarea as Le } from "@chaibuilder/sdk/ui";
6
6
  import { filter as Je, find as Fe } from "lodash-es";
7
7
  import { Info as Oe, Loader as O, Plus as ke, Eye as Ge, Edit as je, Trash as Be } from "lucide-react";
@@ -1,5 +1,5 @@
1
1
  import { jsxs as i, jsx as o } from "react/jsx-runtime";
2
- import { L as d } from "./index-tOCLaJS0.js";
2
+ import { L as d } from "./index-B_T6ZeA4.js";
3
3
  import { Input as v } from "@chaibuilder/sdk/ui";
4
4
  import { useState as x, useEffect as C } from "react";
5
5
  const y = (e) => {
@@ -1 +1 @@
1
- "use strict";const s=require("react/jsx-runtime"),u=require("./index-Nz9M0K-w.cjs"),b=require("@chaibuilder/sdk/ui"),d=require("react"),j=e=>{if(!e)return{base:e,extension:null};const n=e.lastIndexOf(".");if(n<=0)return{base:e,extension:null};const t=e.substring(n);return{base:e.substring(0,n),extension:t}},x=e=>{if(!e)return e;const{base:n}=j(e);return n};function E(e,n){const t=(e||"").split("/").filter(Boolean);let r="",a=!0;if(n.slug==="/"){const i=t.pop()||"";if(u.LANGUAGES[i])a=!0;else{r=i;const l=t.pop()||"";a=!!u.LANGUAGES[l]}}else if(n.parent)t.length&&(r=t.pop()||"");else if(t.length){r=t.pop()||"";const i=t.pop()||"";a=!!u.LANGUAGES[i]}return{initSlug:r,prefix:a}}const v=e=>e&&x(e),C=(e,n)=>{const t=x(e||"");return!t||t==="/"?`/${n}`:`${t}/${n}`};function A({value:e,onChange:n,placeholder:t,parentSlug:r,onValidationChange:a,disabled:i=!1,fullSlug:l}){const[g,p]=d.useState(e),[o,f]=d.useState(null);d.useEffect(()=>{p(e)},[e]);const h=S=>{const c=S.target.value.replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),m=(c.match(/\./g)||[]).length,N=m<=1;m>1?f("Invalid slug. Only one dot (.) is allowed in the slug"):f(null),a&&a(N),p(c),n(c)};return s.jsxs("div",{children:[r&&s.jsx("div",{className:"mb-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Parent: ",s.jsx("span",{className:"font-mono text-gray-900",children:v(r)})]})}),s.jsxs("div",{className:"relative",children:[s.jsx(b.Input,{disabled:i,value:g,onChange:h,placeholder:t,className:o?"border-red-500":""}),o&&s.jsx("div",{className:"mt-1 text-xs text-red-500",children:o})]}),l&&l!=="undefined"&&s.jsx("div",{className:"mt-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Complete Slug: ",s.jsx("span",{className:"font-mono text-gray-900",children:l})]})})]})}exports.SlugInput=A;exports.combineParentChildSlugs=C;exports.parseSlugForEdit=E;exports.removeSlugExtension=x;
1
+ "use strict";const s=require("react/jsx-runtime"),u=require("./index--Lu_Q_nO.cjs"),b=require("@chaibuilder/sdk/ui"),d=require("react"),j=e=>{if(!e)return{base:e,extension:null};const n=e.lastIndexOf(".");if(n<=0)return{base:e,extension:null};const t=e.substring(n);return{base:e.substring(0,n),extension:t}},x=e=>{if(!e)return e;const{base:n}=j(e);return n};function E(e,n){const t=(e||"").split("/").filter(Boolean);let r="",a=!0;if(n.slug==="/"){const i=t.pop()||"";if(u.LANGUAGES[i])a=!0;else{r=i;const l=t.pop()||"";a=!!u.LANGUAGES[l]}}else if(n.parent)t.length&&(r=t.pop()||"");else if(t.length){r=t.pop()||"";const i=t.pop()||"";a=!!u.LANGUAGES[i]}return{initSlug:r,prefix:a}}const v=e=>e&&x(e),C=(e,n)=>{const t=x(e||"");return!t||t==="/"?`/${n}`:`${t}/${n}`};function A({value:e,onChange:n,placeholder:t,parentSlug:r,onValidationChange:a,disabled:i=!1,fullSlug:l}){const[g,p]=d.useState(e),[o,f]=d.useState(null);d.useEffect(()=>{p(e)},[e]);const h=S=>{const c=S.target.value.replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),m=(c.match(/\./g)||[]).length,N=m<=1;m>1?f("Invalid slug. Only one dot (.) is allowed in the slug"):f(null),a&&a(N),p(c),n(c)};return s.jsxs("div",{children:[r&&s.jsx("div",{className:"mb-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Parent: ",s.jsx("span",{className:"font-mono text-gray-900",children:v(r)})]})}),s.jsxs("div",{className:"relative",children:[s.jsx(b.Input,{disabled:i,value:g,onChange:h,placeholder:t,className:o?"border-red-500":""}),o&&s.jsx("div",{className:"mt-1 text-xs text-red-500",children:o})]}),l&&l!=="undefined"&&s.jsx("div",{className:"mt-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Complete Slug: ",s.jsx("span",{className:"font-mono text-gray-900",children:l})]})})]})}exports.SlugInput=A;exports.combineParentChildSlugs=C;exports.parseSlugForEdit=E;exports.removeSlugExtension=x;
@@ -1,5 +1,5 @@
1
1
  import { jsx as t, jsxs as a } from "react/jsx-runtime";
2
- import { an as N, b as C, a as b, ao as v, B as E, E as d, P as m } from "./index-tOCLaJS0.js";
2
+ import { an as N, b as C, a as b, ao as v, B as E, E as d, P as m } from "./index-B_T6ZeA4.js";
3
3
  import { useSavePage as T, useTranslation as w } from "@chaibuilder/sdk";
4
4
  import { Card as I, CardHeader as k, CardTitle as y, CardContent as R, CardFooter as S, Button as u } from "@chaibuilder/sdk/ui";
5
5
  import { AlertCircle as A, UserIcon as P, Check as _, X as q } from "lucide-react";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index-Nz9M0K-w.cjs"),m=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),l=require("lucide-react"),j=require("react"),p=()=>{const i=t.useSendRealtimeEvent(),{pageLockMeta:r}=t.usePageLockMeta(),{setPageStatus:d}=t.usePageLockStatus(),{savePageAsync:x}=m.useSavePage(),h=r==null?void 0:r.requestingUserId,{data:s,isFetching:g}=t.useChaiUserInfo(h||""),o=g?"Fetching user...":(s==null?void 0:s.name)||"Current editor",[u,c]=j.useState(!1),N=async()=>{c(!0),await x(),i(t.EVENT.CONTINUE_EDITING_IN_THIS_CLIENT,r),d(t.PAGE_STATUS.CHECKING),setTimeout(()=>c(!1),2e3)},f=()=>{c(!0),i(t.EVENT.TAKE_OVER_REJECTED,r),d(t.PAGE_STATUS.EDITING),setTimeout(()=>c(!1),2e3)},{t:n}=m.useTranslation();return e.jsx(t.BlurContainer,{children:e.jsxs(a.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(a.CardHeader,{className:"space-y-1",children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2 text-xl",children:[e.jsx(l.AlertCircle,{className:"h-8 w-8 rounded-md bg-amber-500/20 p-1.5 text-amber-500"}),n("Take Over Requested")]})}),e.jsxs(a.CardContent,{className:"space-y-4",children:[e.jsxs("div",{className:"relative rounded-md border border-green-500 px-2 pb-2 pt-4",children:[e.jsx("div",{className:"absolute -top-2.5 left-3 w-max rounded-full bg-green-500 px-3 py-1 text-xs font-medium leading-3 text-white",children:"Requested by"}),e.jsxs("div",{className:"flex items-center space-x-4 p-1",children:[s!=null&&s.avatar?e.jsx("img",{src:s.avatar,alt:s.name,className:"h-12 w-12 flex-shrink-0 rounded-full bg-black p-3 text-white"}):e.jsx(l.UserIcon,{className:"h-12 w-12 flex-shrink-0 rounded-full bg-black p-3 text-white"}),e.jsxs("div",{className:"flex-1 space-y-0",children:[e.jsx("div",{className:"truncate font-medium leading-tight text-black",children:o}),(s==null?void 0:s.email)&&e.jsx("p",{className:"truncate text-sm leading-tight text-muted-foreground",children:s.email})]})]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-gray-700",children:o})," ",n("has requested to")," ",e.jsx("span",{className:"font-medium text-gray-500",children:"take over"})," ",n("editing this page."),"."," ",n("Do you want to allow them to continue?")]})]}),e.jsxs(a.CardFooter,{className:"flex gap-2",children:[e.jsxs(a.Button,{disabled:u,variant:"default",onClick:N,className:"flex-1 gap-2",children:[e.jsx(l.Check,{className:"h-4 w-4"}),n("Accept")]}),e.jsxs(a.Button,{disabled:u,variant:"outline",onClick:f,className:"flex-1 gap-2",children:[e.jsx(l.X,{className:"h-4 w-4"}),n("Reject")]})]})]})})};exports.default=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),t=require("./index--Lu_Q_nO.cjs"),m=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),l=require("lucide-react"),j=require("react"),p=()=>{const i=t.useSendRealtimeEvent(),{pageLockMeta:r}=t.usePageLockMeta(),{setPageStatus:d}=t.usePageLockStatus(),{savePageAsync:x}=m.useSavePage(),h=r==null?void 0:r.requestingUserId,{data:s,isFetching:g}=t.useChaiUserInfo(h||""),o=g?"Fetching user...":(s==null?void 0:s.name)||"Current editor",[u,c]=j.useState(!1),N=async()=>{c(!0),await x(),i(t.EVENT.CONTINUE_EDITING_IN_THIS_CLIENT,r),d(t.PAGE_STATUS.CHECKING),setTimeout(()=>c(!1),2e3)},f=()=>{c(!0),i(t.EVENT.TAKE_OVER_REJECTED,r),d(t.PAGE_STATUS.EDITING),setTimeout(()=>c(!1),2e3)},{t:n}=m.useTranslation();return e.jsx(t.BlurContainer,{children:e.jsxs(a.Card,{className:"mx-auto w-full max-w-md",children:[e.jsx(a.CardHeader,{className:"space-y-1",children:e.jsxs(a.CardTitle,{className:"flex items-center gap-2 text-xl",children:[e.jsx(l.AlertCircle,{className:"h-8 w-8 rounded-md bg-amber-500/20 p-1.5 text-amber-500"}),n("Take Over Requested")]})}),e.jsxs(a.CardContent,{className:"space-y-4",children:[e.jsxs("div",{className:"relative rounded-md border border-green-500 px-2 pb-2 pt-4",children:[e.jsx("div",{className:"absolute -top-2.5 left-3 w-max rounded-full bg-green-500 px-3 py-1 text-xs font-medium leading-3 text-white",children:"Requested by"}),e.jsxs("div",{className:"flex items-center space-x-4 p-1",children:[s!=null&&s.avatar?e.jsx("img",{src:s.avatar,alt:s.name,className:"h-12 w-12 flex-shrink-0 rounded-full bg-black p-3 text-white"}):e.jsx(l.UserIcon,{className:"h-12 w-12 flex-shrink-0 rounded-full bg-black p-3 text-white"}),e.jsxs("div",{className:"flex-1 space-y-0",children:[e.jsx("div",{className:"truncate font-medium leading-tight text-black",children:o}),(s==null?void 0:s.email)&&e.jsx("p",{className:"truncate text-sm leading-tight text-muted-foreground",children:s.email})]})]})]}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-gray-700",children:o})," ",n("has requested to")," ",e.jsx("span",{className:"font-medium text-gray-500",children:"take over"})," ",n("editing this page."),"."," ",n("Do you want to allow them to continue?")]})]}),e.jsxs(a.CardFooter,{className:"flex gap-2",children:[e.jsxs(a.Button,{disabled:u,variant:"default",onClick:N,className:"flex-1 gap-2",children:[e.jsx(l.Check,{className:"h-4 w-4"}),n("Accept")]}),e.jsxs(a.Button,{disabled:u,variant:"outline",onClick:f,className:"flex-1 gap-2",children:[e.jsx(l.X,{className:"h-4 w-4"}),n("Reject")]})]})]})})};exports.default=p;
@@ -1,5 +1,5 @@
1
1
  import { jsxs as c, jsx as a } from "react/jsx-runtime";
2
- import { e as d, f as h, t as u } from "./index-tOCLaJS0.js";
2
+ import { e as d, f as h, t as u } from "./index-B_T6ZeA4.js";
3
3
  import { useTheme as b, useTranslation as f } from "@chaibuilder/sdk";
4
4
  import { Button as o } from "@chaibuilder/sdk/ui";
5
5
  const x = () => {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-Nz9M0K-w.cjs"),o=require("@chaibuilder/sdk"),r=require("@chaibuilder/sdk/ui"),h=()=>{const[t]=o.useTheme(),{mutate:c,isPending:i}=s.usePublishPages(),{mutateAsync:n,isPending:u}=s.useUpdateWebsiteSettings(),{t:a}=o.useTranslation(),l=()=>{n({settings:{theme:t}})},d=async()=>{await n({settings:{theme:t}}),c({ids:["THEME"]},{onSuccess:()=>{s.throwConfetti("BOTTOM_RIGHT")}})};return e.jsxs("div",{className:"flex items-center justify-center gap-x-3 border-t bg-white py-3",children:[e.jsx(r.Button,{size:"sm",variant:"outline",disabled:i||u,onClick:l,children:a("Save draft")}),e.jsx(r.Button,{size:"sm",disabled:i||u,onClick:d,children:a("Publish")})]})};exports.default=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index--Lu_Q_nO.cjs"),o=require("@chaibuilder/sdk"),r=require("@chaibuilder/sdk/ui"),h=()=>{const[t]=o.useTheme(),{mutate:c,isPending:i}=s.usePublishPages(),{mutateAsync:n,isPending:u}=s.useUpdateWebsiteSettings(),{t:a}=o.useTranslation(),l=()=>{n({settings:{theme:t}})},d=async()=>{await n({settings:{theme:t}}),c({ids:["THEME"]},{onSuccess:()=>{s.throwConfetti("BOTTOM_RIGHT")}})};return e.jsxs("div",{className:"flex items-center justify-center gap-x-3 border-t bg-white py-3",children:[e.jsx(r.Button,{size:"sm",variant:"outline",disabled:i||u,onClick:l,children:a("Save draft")}),e.jsx(r.Button,{size:"sm",disabled:i||u,onClick:d,children:a("Publish")})]})};exports.default=h;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("./index-Nz9M0K-w.cjs"),d=require("@chaibuilder/sdk"),t=require("@chaibuilder/sdk/ui"),m=require("react"),p=({page:i,onClose:n})=>{const{t:a}=d.useTranslation(),[r,s]=m.useState(!1),o=u.useUnmarkAsTemplate(),l=()=>{s(!0),o.mutate(i,{onSuccess:()=>{s(!1),n()},onError:()=>{s(!1)}})};return e.jsx(t.Dialog,{open:!0,onOpenChange:n,children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:a("Unmark as template")}),e.jsx(t.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:a("Are you sure you want to unmark this page as a template?")})]}),e.jsxs(t.DialogFooter,{className:r?"pointer-events-none opacity-75":"",children:[e.jsx(t.Button,{variant:"outline",onClick:c=>{c.stopPropagation(),n()},children:a("Cancel")}),e.jsx(t.Button,{variant:"default",disabled:r,onClick:l,children:a("Unmark as template")})]})]})})};exports.default=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("./index--Lu_Q_nO.cjs"),d=require("@chaibuilder/sdk"),t=require("@chaibuilder/sdk/ui"),m=require("react"),p=({page:i,onClose:n})=>{const{t:a}=d.useTranslation(),[r,s]=m.useState(!1),o=u.useUnmarkAsTemplate(),l=()=>{s(!0),o.mutate(i,{onSuccess:()=>{s(!1),n()},onError:()=>{s(!1)}})};return e.jsx(t.Dialog,{open:!0,onOpenChange:n,children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:a("Unmark as template")}),e.jsx(t.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:a("Are you sure you want to unmark this page as a template?")})]}),e.jsxs(t.DialogFooter,{className:r?"pointer-events-none opacity-75":"",children:[e.jsx(t.Button,{variant:"outline",onClick:c=>{c.stopPropagation(),n()},children:a("Cancel")}),e.jsx(t.Button,{variant:"default",disabled:r,onClick:l,children:a("Unmark as template")})]})]})})};exports.default=p;