@chaibuilder/sdk 4.0.0-beta.24 → 4.0.0-beta.25

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 (122) hide show
  1. package/dist/{2SSKDMRQ-DTcPSOGn.js → 2SSKDMRQ-Bk_4y8lw.js} +2 -2
  2. package/dist/{2SSKDMRQ-C6XmPkPR.cjs → 2SSKDMRQ-vWeQ_IyI.cjs} +1 -1
  3. package/dist/{AP7HFJJL-6aBLUYOi.cjs → AP7HFJJL-CMPLeI6t.cjs} +1 -1
  4. package/dist/{AP7HFJJL-CVazlaEj.js → AP7HFJJL-D_mI2XSw.js} +1 -1
  5. package/dist/{IconPicker-sbWeQ9M9.cjs → IconPicker-DB_PpKvH.cjs} +1 -1
  6. package/dist/{IconPicker-CcBoA1K0.js → IconPicker-jc6_JzXf.js} +1 -1
  7. package/dist/{WDYDFRGG-CwiYliX0.js → WDYDFRGG-B4H3RPcp.js} +2 -2
  8. package/dist/{WDYDFRGG-BtzyRDmj.cjs → WDYDFRGG-D7vzbPjk.cjs} +1 -1
  9. package/dist/{active-in-another-tab-B4O3FEEg.js → active-in-another-tab-CDhFxBU7.js} +2 -2
  10. package/dist/{active-in-another-tab-DRJY0QqU.cjs → active-in-another-tab-CMPHyyHE.cjs} +1 -1
  11. package/dist/{add-new-language-page-BfYL9jXF.js → add-new-language-page-BliZ46WW.js} +3 -3
  12. package/dist/{add-new-language-page-CKIRTFjr.cjs → add-new-language-page-IbMzbf4v.cjs} +1 -1
  13. package/dist/{add-new-page-dzN_CD2c.cjs → add-new-page-BJJqSKp0.cjs} +1 -1
  14. package/dist/{add-new-page-DVgxz4fs.js → add-new-page-DUCKfyWo.js} +2 -2
  15. package/dist/{ai-panel-content-Dyw4RHCV.cjs → ai-panel-content-DWOqjq3Z.cjs} +1 -1
  16. package/dist/{ai-panel-content-D5eFLI_B.js → ai-panel-content-GeQIaXy8.js} +3 -3
  17. package/dist/{ai-panel-default-lang-DEj9Qx2M.cjs → ai-panel-default-lang-DGNDrfam.cjs} +2 -2
  18. package/dist/{ai-panel-default-lang-Cj7meZBD.js → ai-panel-default-lang-VQsV6KB3.js} +3 -3
  19. package/dist/{ai-panel-other-lang-Da2XLEcm.cjs → ai-panel-other-lang-DvXF0Nn5.cjs} +1 -1
  20. package/dist/{ai-panel-other-lang-Cbi6HKzd.js → ai-panel-other-lang-SuC8jyfr.js} +3 -3
  21. package/dist/{ai-prompt-input-B6QoqT9B.js → ai-prompt-input-CB6iQAmE.js} +1 -1
  22. package/dist/{ai-prompt-input-DXS8gzex.cjs → ai-prompt-input-a8s-JrZb.cjs} +1 -1
  23. package/dist/{ai-translation-prompt-Dmq_Ahjf.js → ai-translation-prompt-CoNVDclG.js} +1 -1
  24. package/dist/{ai-translation-prompt-Uswft8iz.cjs → ai-translation-prompt-Qn1Sz4BI.cjs} +1 -1
  25. package/dist/change-password-modal-BtdsU0mm.cjs +1 -0
  26. package/dist/change-password-modal-CMEo8lEm.js +137 -0
  27. package/dist/{code-editor-wQWmwFKW.js → code-editor-CTMQr0aU.js} +1 -1
  28. package/dist/{code-editor-DbSBrsUA.cjs → code-editor-CjatfjZe.cjs} +1 -1
  29. package/dist/{continue-editing-in-this-client-Dkkzk8YZ.cjs → continue-editing-in-this-client-7swLl0kq.cjs} +1 -1
  30. package/dist/{continue-editing-in-this-client-BV0OrgEU.js → continue-editing-in-this-client-CNVJZvXQ.js} +2 -2
  31. package/dist/core.cjs +1 -1
  32. package/dist/core.js +1 -1
  33. package/dist/{css-import-modal-Co_YLkLB.js → css-import-modal-B3XY8Hzw.js} +1 -1
  34. package/dist/{css-import-modal-C3f5sphx.cjs → css-import-modal-D2RqE-V0.cjs} +1 -1
  35. package/dist/{delete-design-token-CJPAcsWp.js → delete-design-token-DEyYFVHU.js} +1 -1
  36. package/dist/{delete-design-token-zzNmNYLR.cjs → delete-design-token-Dd3b86G7.cjs} +1 -1
  37. package/dist/{delete-page-CQTjB7ZZ.js → delete-page-BSn5mRvk.js} +2 -2
  38. package/dist/{delete-page-6lInxYM_.cjs → delete-page-BfsmsTek.cjs} +1 -1
  39. package/dist/{design-token-usage-blwlGuEE.cjs → design-token-usage-BY8meqAt.cjs} +1 -1
  40. package/dist/{design-token-usage-BQY6eqzE.js → design-token-usage-f20BdlHE.js} +1 -1
  41. package/dist/{digital-asset-manager-cGUpTcu3.cjs → digital-asset-manager-Pi0YiB35.cjs} +1 -1
  42. package/dist/{digital-asset-manager-lPKoJ4FH.js → digital-asset-manager-iXt27NlP.js} +3 -3
  43. package/dist/{duplicate-page-Dmgqp93w.js → duplicate-page-BuVub6uY.js} +3 -3
  44. package/dist/{duplicate-page-rYeBMwHR.cjs → duplicate-page-g5hiQkrZ.cjs} +1 -1
  45. package/dist/{dynamic-page-selector-CVyA9Zp0.js → dynamic-page-selector-NZ-rKLo3.js} +2 -2
  46. package/dist/{dynamic-page-selector-zqGqpcww.cjs → dynamic-page-selector-z6UGEjk1.cjs} +1 -1
  47. package/dist/{get-chai-builder-theme-CfJkQYZc.js → get-chai-builder-theme-CHXhAcdV.js} +1 -1
  48. package/dist/{get-chai-builder-theme-Dm1z70lQ.cjs → get-chai-builder-theme-CMypjJk8.cjs} +1 -1
  49. package/dist/{image-editor-mVBb0VD_.js → image-editor--WT9183_.js} +1 -1
  50. package/dist/{image-editor-Cn1DgrNp.cjs → image-editor-C6cZZNbB.cjs} +1 -1
  51. package/dist/index-BGGNVIKx.cjs +5 -0
  52. package/dist/{index-EFWvSWoi.cjs → index-CfsIhbT2.cjs} +3 -3
  53. package/dist/{index-GfOB5KV1.js → index-ckjNCVor.js} +990 -978
  54. package/dist/{index-lm46VtIP.js → index-iRqgNs2O.js} +14 -10
  55. package/dist/{json-diff-viewer-D5yJoFh1.js → json-diff-viewer-DAQ-qSHk.js} +2 -2
  56. package/dist/{json-diff-viewer-BeSMdSd5.cjs → json-diff-viewer-DheqS084.cjs} +1 -1
  57. package/dist/{lang-panel-7qTejsLm.js → lang-panel-DRDPvY1i.js} +3 -3
  58. package/dist/{lang-panel-B-QUotOn.cjs → lang-panel-oLc-QyU4.cjs} +1 -1
  59. package/dist/{manage-design-tokens-TeWNZekH.cjs → manage-design-tokens-Hu25ejcC.cjs} +1 -1
  60. package/dist/{manage-design-tokens-DeH-yNJN.js → manage-design-tokens-rEzXQJRW.js} +2 -2
  61. package/dist/{mark-as-template-RkfNETRW.js → mark-as-template-BNbn5zQG.js} +2 -2
  62. package/dist/{mark-as-template-Co00KkhA.cjs → mark-as-template-DEThYoS6.cjs} +1 -1
  63. package/dist/{nested-path-selector-content-Dimjyy8J.js → nested-path-selector-content-BERhs6_L.js} +1 -1
  64. package/dist/{nested-path-selector-content-hBvmT_2A.cjs → nested-path-selector-content-Dz3-bNqT.cjs} +1 -1
  65. package/dist/{no-language-page-content-Bk3sTsdM.js → no-language-page-content-CPVIz5rC.js} +2 -2
  66. package/dist/{no-language-page-content-CLovr1bL.cjs → no-language-page-content-CrUkIrUJ.cjs} +1 -1
  67. package/dist/{no-language-page-dialog-C21Fq-UD.cjs → no-language-page-dialog-964r8feg.cjs} +1 -1
  68. package/dist/{no-language-page-dialog-Cx-YOrAd.js → no-language-page-dialog-DPDJ6gkQ.js} +2 -2
  69. package/dist/{page-creator-BBuYY84G.js → page-creator-CDcfL4al.js} +3 -3
  70. package/dist/{page-creator-BDmospqO.cjs → page-creator-kvymje2i.cjs} +1 -1
  71. package/dist/{page-lock-BrGWj326.js → page-lock-BpUGSiCT.js} +2 -2
  72. package/dist/{page-lock-DG5IvZaG.cjs → page-lock-gOE-Tt7g.cjs} +1 -1
  73. package/dist/{page-locked-dialog-DUktYJzU.js → page-locked-dialog-UQeYxWz1.js} +2 -2
  74. package/dist/{page-locked-dialog-DKnQpIMB.cjs → page-locked-dialog-aJFtoEzq.cjs} +1 -1
  75. package/dist/{page-manager-new-iYsDkUzG.cjs → page-manager-new-DBomYOFT.cjs} +1 -1
  76. package/dist/{page-manager-new-BfKYDWs7.js → page-manager-new-Dg02OZtc.js} +22 -22
  77. package/dist/{page-manager-search-and-filter-DVAGxnlw.js → page-manager-search-and-filter-CCTh5gkC.js} +2 -2
  78. package/dist/{page-manager-search-and-filter-CIspvIW2.cjs → page-manager-search-and-filter-pWHXOgMJ.cjs} +1 -1
  79. package/dist/{page-revisions-content-B84UtAxm.cjs → page-revisions-content-BDY8RXJW.cjs} +1 -1
  80. package/dist/{page-revisions-content-DB4mj_Cw.js → page-revisions-content-C6YjUAx9.js} +7 -7
  81. package/dist/pages.cjs +1 -1
  82. package/dist/pages.js +12 -12
  83. package/dist/{plugin-DVNaUexn.js → plugin-DH3BDqys.js} +7 -7
  84. package/dist/{plugin-BfC_qpW2.cjs → plugin-DO5QAuc1.cjs} +7 -7
  85. package/dist/{publish-pages-content-BRKsIr9W.js → publish-pages-content-8MQN9iLc.js} +17 -17
  86. package/dist/{publish-pages-content-ysv37LxZ.cjs → publish-pages-content-DjUd9oWi.cjs} +1 -1
  87. package/dist/render.cjs +1 -1
  88. package/dist/render.js +2 -2
  89. package/dist/{rte-widget-modal-Dj5BvA-1.js → rte-widget-modal-Bj7lxFEs.js} +1 -1
  90. package/dist/{rte-widget-modal-BS040t_9.cjs → rte-widget-modal-O31cHitM.cjs} +1 -1
  91. package/dist/{save-to-lib-D3kp0ovZ.js → save-to-lib-BMlowHNl.js} +2 -2
  92. package/dist/{save-to-lib-ClCCNy6W.cjs → save-to-lib-vxpiXsok.cjs} +1 -1
  93. package/dist/sdk.css +1 -1
  94. package/dist/{selected-block-display-BvRoOMt9.cjs → selected-block-display-BjhZTfSL.cjs} +1 -1
  95. package/dist/{selected-block-display-BtlTAkei.js → selected-block-display-BxHTDLna.js} +2 -2
  96. package/dist/{seo-panel-C_Cnwj1-.js → seo-panel-197ULlty.js} +2 -2
  97. package/dist/{seo-panel-CHGdB8_7.cjs → seo-panel-MrGhioya.cjs} +1 -1
  98. package/dist/{shared-json-ld-DA0wz-k3.cjs → shared-json-ld-6ovlKZ7L.cjs} +1 -1
  99. package/dist/{shared-json-ld-DPr0Douk.js → shared-json-ld-B2kfIim8.js} +24 -24
  100. package/dist/{slug-input-CqhlfgAe.js → slug-input-CSqTWSv8.js} +1 -1
  101. package/dist/{slug-input-DltqfQ3y.cjs → slug-input-CV-Dvosn.cjs} +1 -1
  102. package/dist/supabase-actions.cjs +1 -1
  103. package/dist/supabase-actions.d.ts +34 -0
  104. package/dist/supabase-actions.js +231 -192
  105. package/dist/{take-over-request-Bq7OF5Gp.cjs → take-over-request-BFZbLBOK.cjs} +1 -1
  106. package/dist/{take-over-request-ByUlm_HK.js → take-over-request-Ds_-1dOv.js} +2 -2
  107. package/dist/{theme-panel-footer-DG7Z5YjD.js → theme-panel-footer-C1f2KMBq.js} +2 -2
  108. package/dist/{theme-panel-footer-XYoM6sn5.cjs → theme-panel-footer-dHh8VGgj.cjs} +1 -1
  109. package/dist/{translation-warning-modal-DaBUipEY.js → translation-warning-modal-DPdVK3CD.js} +1 -1
  110. package/dist/{translation-warning-modal-DTxxfo0H.cjs → translation-warning-modal-HD8Mlj1e.cjs} +1 -1
  111. package/dist/{unmark-as-template-C9EXTj0X.cjs → unmark-as-template-D8wEsu9z.cjs} +1 -1
  112. package/dist/{unmark-as-template-BOFHOO0_.js → unmark-as-template-DLVNotM_.js} +2 -2
  113. package/dist/{unpublish-page-B5rev9W3.cjs → unpublish-page-Cl2R_dfN.cjs} +1 -1
  114. package/dist/{unpublish-page-KDM7kEEV.js → unpublish-page-ik9a66Rz.js} +2 -2
  115. package/dist/utils.cjs +1 -1
  116. package/dist/utils.js +1 -1
  117. package/dist/web-blocks.cjs +1 -1
  118. package/dist/web-blocks.js +23 -22
  119. package/dist/{web-preview-CvpevNzM.cjs → web-preview-CE39XTw0.cjs} +1 -1
  120. package/dist/{web-preview-BDgUTTr8.js → web-preview-ztlGD_Xm.js} +1 -1
  121. package/package.json +1 -1
  122. package/dist/index-B5qvHqN5.cjs +0 -5
@@ -1,4 +1,4 @@
1
- "use strict";const o=require("react/jsx-runtime"),r=require("./register-chai-top-bar-DWTuRU53.cjs"),m=require("lucide-react"),i=require("react"),p=require("use-stick-to-bottom"),T=require("streamdown");require("@radix-ui/react-slot");const P=require("class-variance-authority"),_=require("./index-EFWvSWoi.cjs");require("clsx");require("tailwind-merge");const z=require("@radix-ui/react-tooltip"),j=require("@radix-ui/react-use-controllable-state"),B=require("@radix-ui/react-collapsible"),D=require("framer-motion"),f=require("./index-B5qvHqN5.cjs"),I=require("react-i18next");function h(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 L=h(i),S=h(z),b=h(B),G=({className:e,...t})=>o.jsx(p.StickToBottom,{className:r.cn("relative flex-1 overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...t}),$=({className:e,...t})=>o.jsx(p.StickToBottom.Content,{className:r.cn("flex flex-col gap-8 p-4",e),...t}),F=({className:e,title:t="No messages yet",description:s="Start a conversation to see messages here",icon:n,children:a,...l})=>o.jsx("div",{className:r.cn("flex size-full flex-col items-center justify-center gap-3 p-8 text-center",e),...l,children:a??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:"text-sm font-medium",children:t}),s&&o.jsx("p",{className:"text-sm text-muted-foreground",children:s})]})]})}),Q=({className:e,...t})=>{const{isAtBottom:s,scrollToBottom:n}=p.useStickToBottomContext(),a=i.useCallback(()=>{n()},[n]);return!s&&o.jsx(r.Button,{className:r.cn("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",e),onClick:a,size:"icon",type:"button",variant:"outline",...t,children:o.jsx(m.ArrowDownIcon,{className:"size-4"})})};P.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 V=L.forwardRef(({className:e,sideOffset:t=4,...s},n)=>o.jsx(S.Content,{ref:n,sideOffset:t,className:r.cn("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}));V.displayName=S.Content.displayName;const K=({className:e,from:t,...s})=>o.jsx("div",{className:r.cn("group flex w-full max-w-[80%] flex-col gap-2",t==="user"?"is-user ml-auto justify-end":"is-assistant",e),...s}),Y=({children:e,className:t,...s})=>o.jsx("div",{className:r.cn("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 w=i.memo(({className:e,...t})=>o.jsx(T.Streamdown,{className:r.cn("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",e),...t}),(e,t)=>e.children===t.children);w.displayName="MessageResponse";const J=b.Root,X=b.CollapsibleTrigger,H=b.CollapsibleContent,W=({children:e,as:t="p",className:s,duration:n=2,spread:a=2})=>{const l=D.motion.create(t),g=i.useMemo(()=>((e==null?void 0:e.length)??0)*a,[e,a]);return o.jsx(l,{animate:{backgroundPosition:"0% center"},className:r.cn("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":`${g}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})},E=i.memo(W),R=i.createContext(null),Z=()=>{const e=i.useContext(R);if(!e)throw new Error("Reasoning components must be used within Reasoning");return e},ee=1e3,te=1e3,y=i.memo(({className:e,isStreaming:t=!1,open:s,defaultOpen:n=!0,onOpenChange:a,duration:l,children:g,...U})=>{const[c,d]=j.useControllableState({prop:s,defaultProp:n,onChange:a}),[M,v]=j.useControllableState({prop:l,defaultProp:void 0}),[N,q]=i.useState(!1),[u,C]=i.useState(null);i.useEffect(()=>{t?u===null&&C(Date.now()):u!==null&&(v(Math.ceil((Date.now()-u)/te)),C(null))},[t,u,v]),i.useEffect(()=>{if(n&&!t&&c&&!N){const x=setTimeout(()=>{d(!1),q(!0)},ee);return()=>clearTimeout(x)}},[t,c,n,d,N]);const O=x=>{d(x)};return o.jsx(R.Provider,{value:{isStreaming:t,isOpen:c,setIsOpen:d,duration:M},children:o.jsx(J,{className:r.cn("not-prose mb-4",e),onOpenChange:O,open:c,...U,children:g})})}),oe=(e,t)=>e||t===0?o.jsx(E,{duration:1,children:"Thinking..."}):t===void 0?o.jsx("p",{children:"Thought for a few seconds"}):o.jsxs("p",{children:["Thought for ",t," seconds"]}),A=i.memo(({className:e,children:t,...s})=>{const{isStreaming:n,isOpen:a,duration:l}=Z();return o.jsx(X,{className:r.cn("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(m.BrainIcon,{className:"size-4"}),oe(n,l),o.jsx(m.ChevronDownIcon,{className:r.cn("size-4 transition-transform",a?"rotate-180":"rotate-0")})]})})}),k=i.memo(({className:e,children:t,...s})=>o.jsx(H,{className:r.cn("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(T.Streamdown,{...s,children:t})}));y.displayName="Reasoning";A.displayName="ReasoningTrigger";k.displayName="ReasoningContent";const se=({className:e,content:t,isLoading:s=!1,...n})=>o.jsx("div",{className:r.cn("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(E,{duration:1.5,children:t}),!s&&o.jsx("div",{className:"text-xs text-muted-foreground",children:t})]})})})});function ne({userInput:e,language:t="en",currentHtml:s}){const n=f.LANGUAGES[t]||"English";return s&&s.trim().length>0?`
1
+ "use strict";const o=require("react/jsx-runtime"),r=require("./register-chai-top-bar-DWTuRU53.cjs"),m=require("lucide-react"),i=require("react"),p=require("use-stick-to-bottom"),T=require("streamdown");require("@radix-ui/react-slot");const P=require("class-variance-authority"),_=require("./index-CfsIhbT2.cjs");require("clsx");require("tailwind-merge");const z=require("@radix-ui/react-tooltip"),j=require("@radix-ui/react-use-controllable-state"),B=require("@radix-ui/react-collapsible"),D=require("framer-motion"),f=require("./index-BGGNVIKx.cjs"),I=require("react-i18next");function h(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 L=h(i),S=h(z),b=h(B),G=({className:e,...t})=>o.jsx(p.StickToBottom,{className:r.cn("relative flex-1 overflow-y-hidden",e),initial:"smooth",resize:"smooth",role:"log",...t}),$=({className:e,...t})=>o.jsx(p.StickToBottom.Content,{className:r.cn("flex flex-col gap-8 p-4",e),...t}),F=({className:e,title:t="No messages yet",description:s="Start a conversation to see messages here",icon:n,children:a,...l})=>o.jsx("div",{className:r.cn("flex size-full flex-col items-center justify-center gap-3 p-8 text-center",e),...l,children:a??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:"text-sm font-medium",children:t}),s&&o.jsx("p",{className:"text-sm text-muted-foreground",children:s})]})]})}),Q=({className:e,...t})=>{const{isAtBottom:s,scrollToBottom:n}=p.useStickToBottomContext(),a=i.useCallback(()=>{n()},[n]);return!s&&o.jsx(r.Button,{className:r.cn("absolute bottom-4 left-[50%] translate-x-[-50%] rounded-full",e),onClick:a,size:"icon",type:"button",variant:"outline",...t,children:o.jsx(m.ArrowDownIcon,{className:"size-4"})})};P.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 V=L.forwardRef(({className:e,sideOffset:t=4,...s},n)=>o.jsx(S.Content,{ref:n,sideOffset:t,className:r.cn("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}));V.displayName=S.Content.displayName;const K=({className:e,from:t,...s})=>o.jsx("div",{className:r.cn("group flex w-full max-w-[80%] flex-col gap-2",t==="user"?"is-user ml-auto justify-end":"is-assistant",e),...s}),Y=({children:e,className:t,...s})=>o.jsx("div",{className:r.cn("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 w=i.memo(({className:e,...t})=>o.jsx(T.Streamdown,{className:r.cn("size-full [&>*:first-child]:mt-0 [&>*:last-child]:mb-0",e),...t}),(e,t)=>e.children===t.children);w.displayName="MessageResponse";const J=b.Root,X=b.CollapsibleTrigger,H=b.CollapsibleContent,W=({children:e,as:t="p",className:s,duration:n=2,spread:a=2})=>{const l=D.motion.create(t),g=i.useMemo(()=>((e==null?void 0:e.length)??0)*a,[e,a]);return o.jsx(l,{animate:{backgroundPosition:"0% center"},className:r.cn("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":`${g}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})},E=i.memo(W),R=i.createContext(null),Z=()=>{const e=i.useContext(R);if(!e)throw new Error("Reasoning components must be used within Reasoning");return e},ee=1e3,te=1e3,y=i.memo(({className:e,isStreaming:t=!1,open:s,defaultOpen:n=!0,onOpenChange:a,duration:l,children:g,...U})=>{const[c,d]=j.useControllableState({prop:s,defaultProp:n,onChange:a}),[M,v]=j.useControllableState({prop:l,defaultProp:void 0}),[N,q]=i.useState(!1),[u,C]=i.useState(null);i.useEffect(()=>{t?u===null&&C(Date.now()):u!==null&&(v(Math.ceil((Date.now()-u)/te)),C(null))},[t,u,v]),i.useEffect(()=>{if(n&&!t&&c&&!N){const x=setTimeout(()=>{d(!1),q(!0)},ee);return()=>clearTimeout(x)}},[t,c,n,d,N]);const O=x=>{d(x)};return o.jsx(R.Provider,{value:{isStreaming:t,isOpen:c,setIsOpen:d,duration:M},children:o.jsx(J,{className:r.cn("not-prose mb-4",e),onOpenChange:O,open:c,...U,children:g})})}),oe=(e,t)=>e||t===0?o.jsx(E,{duration:1,children:"Thinking..."}):t===void 0?o.jsx("p",{children:"Thought for a few seconds"}):o.jsxs("p",{children:["Thought for ",t," seconds"]}),A=i.memo(({className:e,children:t,...s})=>{const{isStreaming:n,isOpen:a,duration:l}=Z();return o.jsx(X,{className:r.cn("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(m.BrainIcon,{className:"size-4"}),oe(n,l),o.jsx(m.ChevronDownIcon,{className:r.cn("size-4 transition-transform",a?"rotate-180":"rotate-0")})]})})}),k=i.memo(({className:e,children:t,...s})=>o.jsx(H,{className:r.cn("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(T.Streamdown,{...s,children:t})}));y.displayName="Reasoning";A.displayName="ReasoningTrigger";k.displayName="ReasoningContent";const se=({className:e,content:t,isLoading:s=!1,...n})=>o.jsx("div",{className:r.cn("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(E,{duration:1.5,children:t}),!s&&o.jsx("div",{className:"text-xs text-muted-foreground",children:t})]})})})});function ne({userInput:e,language:t="en",currentHtml:s}){const n=f.LANGUAGES[t]||"English";return s&&s.trim().length>0?`
2
2
  MODE: EDIT
3
3
  CURRENT HTML:
4
4
  ${s}
@@ -7,14 +7,14 @@ import { StickToBottom as R, useStickToBottomContext as Q } from "use-stick-to-b
7
7
  import { Streamdown as y } from "streamdown";
8
8
  import "@radix-ui/react-slot";
9
9
  import { cva as F } from "class-variance-authority";
10
- import { ao as K } from "./index-lm46VtIP.js";
10
+ import { ao as K } from "./index-iRqgNs2O.js";
11
11
  import "clsx";
12
12
  import "tailwind-merge";
13
13
  import * as A from "@radix-ui/react-tooltip";
14
14
  import { useControllableState as w } from "@radix-ui/react-use-controllable-state";
15
15
  import * as x from "@radix-ui/react-collapsible";
16
16
  import { motion as V } from "framer-motion";
17
- import { L as h } from "./index-GfOB5KV1.js";
17
+ import { L as h } from "./index-ckjNCVor.js";
18
18
  import { useTranslation as Y } from "react-i18next";
19
19
  const Te = ({ className: e, ...t }) => /* @__PURE__ */ o(
20
20
  R,
@@ -1,6 +1,6 @@
1
1
  import { jsx as t, jsxs as o } from "react/jsx-runtime";
2
- import { l as ve, as as xe, ar as Ne, A as we, L as ee, aw as Se, aK as De, aL as Oe, i as be, ay as je, aM as Le, aN as Ie, aO as T, aP as Ee, aE as te } from "./index-GfOB5KV1.js";
3
- import { d as z, D as ke, e as Te, f as Ce, g as Fe, p as Je, o as Ae, ai as Pe, as as Re, at as qe, au as $, q as S, T as se } from "./index-lm46VtIP.js";
2
+ import { l as ve, as as xe, ar as Ne, A as we, L as ee, aw as Se, aL as De, aM as Oe, i as be, ay as je, aN as Le, aO as Ie, aP as T, aQ as Ee, aF as te } from "./index-ckjNCVor.js";
3
+ import { d as z, D as ke, e as Te, f as Ce, g as Fe, p as Je, o as Ae, ai as Pe, as as Re, at as qe, au as $, q as S, T as se } from "./index-iRqgNs2O.js";
4
4
  import { find as Be, get as g, isEqual as ne, isEmpty as Ue } from "lodash-es";
5
5
  import { useMemo as _e, useRef as ae, useState as J, useEffect as oe } from "react";
6
6
  import { B as R, D as Ve, F as Ge, z as A } from "./register-chai-top-bar-CX_JkRJn.js";
@@ -1,2 +1,2 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-B5qvHqN5.cjs"),r=require("./index-EFWvSWoi.cjs"),u=require("lodash-es"),w=require("react"),f=require("./register-chai-top-bar-DWTuRU53.cjs"),ie=require("react-i18next"),O=require("sonner"),de=require("@tanstack/react-query"),K=require("lucide-react"),G=require("./get-seo-defaults-Cw7vFt-B.cjs"),ue=()=>{const{selectedLang:t}=r.useLanguages(),{data:p,isFetching:n}=i.useLanguagePages();return{data:w.useMemo(()=>u.find(p,{lang:t||""})||{},[p,t]),isFetching:n}},pe=()=>{var x;const p=(x=document.getElementById("canvas-iframe").contentDocument)==null?void 0:x.body.innerHTML;if(!p)return null;const d=new DOMParser().parseFromString(p,"text/html");d.querySelectorAll("style, script, link, svg, [data-block-type='PartialBlock']").forEach(h=>h.remove()),d.querySelectorAll("*").forEach(h=>{Array.from(h.attributes).forEach(g=>h.removeAttribute(g.name))});const l=d.querySelectorAll("h1, h2, h3, h4, h5, h6, p");return Array.from(l).map(h=>`<${h.tagName.toLowerCase()}>${h.innerHTML}</${h.tagName.toLowerCase()}>`).join(" ").replace(/<p>Partial block. Double click to edit.<\/p>/,"")},R=({keyword:t,onComplete:p,field:n})=>{const d=i.useFetch(),l=i.useApiUrl(),{selectedLang:N,fallbackLang:x}=r.useLanguages(),{mutate:h,isPending:g}=de.useMutation({mutationFn:async()=>{const I=pe();return await d(l,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:n,lang:N||x,pageContent:I,keyword:t}})},onSuccess:I=>{p({fieldValue:I.field})},onError:I=>{p({fieldValue:null,error:I.message})}});return e.jsx(f.Button,{disabled:g,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>h(),children:g?e.jsx(K.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(K.Wand2Icon,{className:"text-yellow-500"})})},he=(t,p)=>{if(!t)return{success:!1,error:"Empty response from AI"};try{let n=t;if(typeof n=="string"&&(/^".*"$/.test(n)&&(n=n.replace(/^"(.*)"$/,"$1"),n=n.replace(/\\\\/g,"___DOUBLE_BACKSLASH___").replace(/\\n/g,`
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),i=require("./index-BGGNVIKx.cjs"),r=require("./index-CfsIhbT2.cjs"),u=require("lodash-es"),w=require("react"),f=require("./register-chai-top-bar-DWTuRU53.cjs"),ie=require("react-i18next"),O=require("sonner"),de=require("@tanstack/react-query"),K=require("lucide-react"),G=require("./get-seo-defaults-Cw7vFt-B.cjs"),ue=()=>{const{selectedLang:t}=r.useLanguages(),{data:p,isFetching:n}=i.useLanguagePages();return{data:w.useMemo(()=>u.find(p,{lang:t||""})||{},[p,t]),isFetching:n}},pe=()=>{var x;const p=(x=document.getElementById("canvas-iframe").contentDocument)==null?void 0:x.body.innerHTML;if(!p)return null;const d=new DOMParser().parseFromString(p,"text/html");d.querySelectorAll("style, script, link, svg, [data-block-type='PartialBlock']").forEach(h=>h.remove()),d.querySelectorAll("*").forEach(h=>{Array.from(h.attributes).forEach(g=>h.removeAttribute(g.name))});const l=d.querySelectorAll("h1, h2, h3, h4, h5, h6, p");return Array.from(l).map(h=>`<${h.tagName.toLowerCase()}>${h.innerHTML}</${h.tagName.toLowerCase()}>`).join(" ").replace(/<p>Partial block. Double click to edit.<\/p>/,"")},R=({keyword:t,onComplete:p,field:n})=>{const d=i.useFetch(),l=i.useApiUrl(),{selectedLang:N,fallbackLang:x}=r.useLanguages(),{mutate:h,isPending:g}=de.useMutation({mutationFn:async()=>{const I=pe();return await d(l,{action:i.ACTIONS.GENERATE_SEO_FIELD,data:{pageContext:"",dynamic:!1,field:n,lang:N||x,pageContent:I,keyword:t}})},onSuccess:I=>{p({fieldValue:I.field})},onError:I=>{p({fieldValue:null,error:I.message})}});return e.jsx(f.Button,{disabled:g,type:"button",className:"h-5 w-5",variant:"ghost",size:"sm",onClick:()=>h(),children:g?e.jsx(K.Loader,{className:"h-3 w-3 animate-spin text-yellow-500"}):e.jsx(K.Wand2Icon,{className:"text-yellow-500"})})},he=(t,p)=>{if(!t)return{success:!1,error:"Empty response from AI"};try{let n=t;if(typeof n=="string"&&(/^".*"$/.test(n)&&(n=n.replace(/^"(.*)"$/,"$1"),n=n.replace(/\\\\/g,"___DOUBLE_BACKSLASH___").replace(/\\n/g,`
2
2
  `).replace(/\\"/g,'"').replace(/___DOUBLE_BACKSLASH___/g,"\\")),p==="jsonLD"||p==="metaOther")){n.includes("```")&&(n=n.replace(/^```json\s*/i,"").replace(/^```\s*/,"").replace(/\s*```$/m,"")),n=n.trim();try{JSON.parse(n)}catch{return{success:!1,error:"The AI response is not valid JSON. Please try again or edit manually."}}}return{success:!0,value:n}}catch(n){return{success:!1,error:n instanceof Error?n.message:"Unknown error occurred"}}},ge=({isOpen:t,onClose:p,onSave:n,onDiscard:d,isSaving:l=!1,fromLanguage:N,toLanguage:x})=>{const h=i.LANGUAGES[N]||N,g=i.LANGUAGES[x]||x;return e.jsx(r.Dialog,{open:t,onOpenChange:p,children:e.jsxs(r.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Unsaved SEO Changes"}),e.jsxs(r.DialogDescription,{children:['You have unsaved changes in the SEO for "',h,'" version. Do you want to save these changes before switching to "',g,'" version?']})]}),e.jsxs("div",{className:"flex justify-end gap-3 pt-4",children:[e.jsx(f.Button,{variant:"outline",onClick:d,disabled:l,children:"Discard Changes"}),e.jsx(f.Button,{onClick:n,disabled:l,children:l?"Saving...":"Save & Switch"})]})]})})},me=t=>{if(!t)return!0;try{return JSON.parse(t),!0}catch{return!1}},xe=(t,p)=>{const n=t.selectionStart||0,d=t.selectionEnd||0,l=t.value,N=l.substring(0,n),x=l.substring(d),h=`{{${p}}}`,g=N+""+h+x,I=n+0+h.length;return{value:g,newCursorPos:I}},Q=()=>{const{t}=ie.useTranslation(),[,p]=r.useSidebarActivePanel(),{data:n}=i.useChaiCurrentPage(),{data:d}=i.useBuilderPageData(),{data:l,isFetching:N}=ue(),x=l==null?void 0:l.seo,h=w.useRef(null),[g,I]=w.useState("seo"),F=n==null?void 0:n.id,Y=n==null?void 0:n.pageType,E=i.usePageType(Y),{selectedLang:M,fallbackLang:X}=r.useLanguages(),m=M||X,[H,P]=w.useState(!1),[Z,$]=w.useState(!1),[ee,q]=w.useState(!1),[b,B]=w.useState(null),[o,D]=w.useState({keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"{}",metaOther:"{}",...x}),A=w.useRef({}),{mutate:se,isPending:U}=i.useUpdatePage(),y=U||H||Z,{hasPermission:te}=r.usePermissions(),a=te(i.PAGES_PERMISSIONS.EDIT_SEO),[ne]=i.usePagesProps(),oe=u.get(ne,"features.canResetSeoToDefault",!1),W=!M||o.jsonLD!=="{}";w.useEffect(()=>{if(!N&&x&&F){const s={keyword:"",title:"",description:"",cononicalUrl:"",noIndex:!1,noFollow:"",ogTitle:"",ogDescription:"",ogImage:"",ogImageId:"",searchTitle:"",searchDescription:"",jsonLD:"",metaOther:"",...x};D(s),A.current[m]=s}},[N,x,m,F]),w.useEffect(()=>{const s=c=>{const{fromLang:j,toLang:J,switchHandler:v}=c.detail,_=A.current[m];(_?!u.isEqual(_,o):!1)?(B({fromLang:j,toLang:J,switchHandler:v}),q(!0)):v()};return window.addEventListener("seo-language-switch-check",s),()=>{window.removeEventListener("seo-language-switch-check",s)}},[F,o,m]);const ae=async()=>{if(!(!E||!m))try{P(!0);const s=G.getSeoDefaults(E,m),c={...o,keyword:u.get(s,"seo.keyword",""),title:u.get(s,"seo.title",""),description:u.get(s,"seo.description",""),cononicalUrl:u.get(s,"seo.canonicalUrl",""),noIndex:u.get(s,"seo.noIndex",!1),noFollow:u.get(s,"seo.noFollow",!1),ogTitle:u.get(s,"seo.ogTitle",""),ogDescription:u.get(s,"seo.ogDescription","")};D(c),O.toast.success(t("SEO fields reset to defaults"))}catch(s){O.toast.error(t("Failed to reset SEO fields")),console.error("Reset SEO error:",s)}finally{P(!1)}},re=async()=>{if(!(!E||!m))try{$(!0);const s=G.getSeoDefaults(E,m),c={...o,jsonLD:u.get(s,"seo.jsonLD","")};D(c),O.toast.success(t("JSON-LD reset to default"))}catch(s){O.toast.error(t("Failed to reset JSON-LD")),console.error("Reset JSON-LD error:",s)}finally{$(!1)}},le=async()=>{if(!(!E||!m))try{P(!0);const s=G.getSeoDefaults(E,m),c={...o,ogTitle:u.get(s,"seo.ogTitle",""),ogDescription:u.get(s,"seo.ogDescription",""),ogImage:u.get(s,"seo.ogImage",""),ogImageId:u.get(s,"seo.ogImageId",""),metaOther:u.get(s,"seo.metaOther","{}")};D(c),O.toast.success(t("Meta Tag fields reset to defaults"))}catch(s){O.toast.error(t("Failed to reset Meta Tag fields")),console.error("Reset Meta Tag error:",s)}finally{P(!1)}},z=async()=>{se({id:l==null?void 0:l.id,seo:o,primaryPage:F},{onSuccess:()=>{console.log("SEO & JSON-LD updated successfully",o),A.current[m]=o,O.toast.success("SEO & JSON-LD updated successfully")}})},L=(s,c)=>{const j=document.getElementById(c);if(j){const{value:J,newCursorPos:v}=xe(j,s);h.current={id:c,position:v},j.tagName.toLowerCase()==="input"?(j.value=J,D(k=>({...k,[j.name]:J})),j.focus(),j.setSelectionRange(v,v),[0,10,50,100,200].forEach(k=>{setTimeout(()=>{const V=document.getElementById(c);V&&(V.focus(),V.setSelectionRange(v,v))},k)})):(D(T=>({...T,[j.name]:J})),requestAnimationFrame(()=>{const T=document.getElementById(c);T&&(T.focus(),T.setSelectionRange(v,v),setTimeout(()=>{const k=document.getElementById(c);k&&(k.focus(),k.setSelectionRange(v,v))},50))}))}},S=s=>{const c={...o,[s.target.name]:s.target.name==="noIndex"||s.target.name==="noFollow"?s.target.checked:s.target.value};D(c)},C=s=>c=>{if(!u.isEmpty(c.fieldValue)){const j=he(c.fieldValue,s);j.success?S({target:{name:s,value:j.value}}):O.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to process AI response:"}),e.jsx("p",{children:j.error})]}))}c.error&&O.toast.error(e.jsxs("div",{children:[e.jsx("h2",{children:"Failed to generate:"}),e.jsx("p",{children:c.error})]}))},ce=()=>{const s=u.get(n,"seo.jsonLD","{}");if((s==null?void 0:s.trim())==="{}"){O.toast.error("Default page JSON-LD is empty");return}S({target:{name:"jsonLD",value:s}})};return e.jsxs("div",{className:"relative flex h-full flex-col","data-panel-id":"seo",children:[!a&&e.jsx("div",{className:"absolute inset-0 z-10 flex items-center justify-center backdrop-blur-sm",children:e.jsx(f.Alert,{variant:"default",className:"w-[80%] max-w-md text-xs",children:e.jsx(f.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:l==null?void 0:l.name}),e.jsx("span",{className:"font-mono text-xs leading-tight text-gray-500",children:l==null?void 0:l.slug})]}),e.jsx(i.LanguageSwitcher,{variant:"outline",showAdd:!1})]}),e.jsx("form",{className:"space-y-8",children:e.jsxs(r.Tabs,{value:g,onValueChange:I,className:"w-full",children:[e.jsxs(r.TabsList,{className:"mb-4 grid w-full grid-cols-3",children:[e.jsx(r.TabsTrigger,{value:"seo",children:t("SEO")}),e.jsx(r.TabsTrigger,{value:"opengraph",children:t("Meta Tags")}),e.jsx(r.TabsTrigger,{value:"jsonld",children:t("JSON-LD")})]}),e.jsx("div",{className:g==="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(r.Label,{className:"text-xs",htmlFor:"keyword",children:t("Keyword")}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"keyword")})]}),e.jsx(f.Input,{type:"text",id:"keyword",name:"keyword",value:o.keyword,onChange:S,disabled:y||!a,placeholder:t("Enter keyword"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"title",children:t("SEO Title")}),e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(R,{keyword:o.keyword,onComplete:C("title"),field:"title"}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"title")})]})]}),e.jsx(f.Input,{type:"text",id:"title",name:"title",value:o.title,onChange:S,disabled:y||!a,placeholder:t("Enter SEO title"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"description",children:t("SEO Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{keyword:o.keyword,onComplete:C("description"),field:"description"}),a&&e.jsx(i.NestedPathSelector,{data:d??{},onSelect:s=>L(s,"description")})]})]}),e.jsx(r.Textarea,{id:"description",name:"description",rows:5,value:o.description,onChange:S,disabled:y||!a,placeholder:t("Enter SEO description"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"title",children:t("Canonical URL")}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"canonicalUrl")})]}),e.jsx(f.Input,{type:"text",id:"canonicalUrl",name:"canonicalUrl",value:o.canonicalUrl,onChange:S,disabled:y||!a,placeholder:t("Enter Canonical URL"),readOnly:!a})]}),e.jsxs("div",{className:"",children:[e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx(f.Input,{type:"checkbox",id:"noIndex",name:"noIndex",checked:o.noIndex,onChange:S,disabled:y||!a,className:"h-4 w-4"}),e.jsx(r.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(f.Input,{type:"checkbox",id:"noFollow",name:"noFollow",checked:o.noFollow,onChange:S,disabled:y||!a,className:"h-4 w-4"}),e.jsx(r.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:g==="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(r.Label,{className:"text-xs",htmlFor:"ogTitle",children:t("OG Title")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{keyword:o.keyword,onComplete:C("ogTitle"),field:"ogTitle"}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"ogTitle")})]})]}),e.jsx(f.Input,{type:"text",id:"ogTitle",name:"ogTitle",value:o.ogTitle,onChange:S,disabled:y||!a,placeholder:t("Enter OG title"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"ogDescription",children:t("OG Description")}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(R,{keyword:o.keyword,onComplete:C("ogDescription"),field:"ogDescription"}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>L(s,"ogDescription")})]})]}),e.jsx(r.Textarea,{id:"ogDescription",name:"ogDescription",rows:5,value:o.ogDescription,onChange:S,disabled:y||!a,placeholder:t("Enter OG description"),readOnly:!a})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(r.Label,{className:"text-xs",htmlFor:"ogImage",children:t("OG Image")}),a&&e.jsx(i.NestedPathSelector,{dataType:"value",data:d??{},onSelect:s=>{D({...o,ogImage:`{{${s}}}`,ogImageId:""})}})]}),e.jsx(i.ImagePicker,{assetId:o.ogImageId,assetUrl:o.ogImage,onChange:s=>{D({...o,ogImage:s.url,ogImageId:s.id})},disabled:y||!a,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(r.Label,{className:"text-xs",htmlFor:"metaOther",children:t("Meta Tags")}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(R,{keyword:o.keyword,onComplete:C("metaOther"),field:"metaOther"})})]}),e.jsx(i.SmartJsonInput,{id:"metaOther",value:o.metaOther,onChange:s=>{S({target:{name:"metaOther",value:s}})},placeholder:t("Enter Meta Tags JSON"),disabled:y||!a,readOnly:!a,pageData:d||{},rows:8,handleFieldInsert:L})]})]})]})})}),e.jsx("div",{className:g==="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(r.Label,{className:"text-xs",htmlFor:"jsonLD",children:t("JSON-LD")}),W&&e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(R,{keyword:o.keyword,onComplete:C("jsonLD"),field:"jsonLD"})})]}),e.jsx("div",{className:"hidden",children:JSON.stringify(d)}),e.jsx(i.SmartJsonInput,{id:"jsonLD",value:o.jsonLD,onChange:s=>{S({target:{name:"jsonLD",value:s}})},placeholder:t("Enter JSON-LD"),disabled:y||!a,readOnly:!a,pageData:d||{},rows:12,handleFieldInsert:L,hasJsonLdForSelectedLang:W,copyJsonLDFromDefaultPage:ce})]})})})]})})]}),a&&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:[oe?e.jsx(f.Button,{type:"button",variant:"ghost",size:"sm",onClick:()=>{g==="jsonld"?re():g==="opengraph"?le():ae()},disabled:y||!a||!E,children:t(H?"Resetting...":`Reset to ${g==="jsonld"?"Default JSON-LD":g==="opengraph"?"Default Open Graph":"Default SEO"}`)}):e.jsx("div",{}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx(f.Button,{onClick:z,disabled:!me(o==null?void 0:o.jsonLD)||(A.current[m]?u.isEqual(A.current[m],o):!1)||y||!a,children:t(U?"Saving...":"Save")}),e.jsx(f.Button,{variant:"link",className:"text-gray-500 hover:text-gray-700",onClick:()=>p("outline"),children:t("Cancel")})]})]}),e.jsx(ge,{isOpen:ee,onClose:()=>{q(!1),B(null)},onSave:async()=>{b&&(await z(),b.switchHandler(),q(!1),B(null))},onDiscard:()=>{if(b){const s=A.current[m];s&&D(s),b.switchHandler(),q(!1),B(null)}},isSaving:U,fromLanguage:(b==null?void 0:b.fromLang)||m,toLanguage:(b==null?void 0:b.toLang)||""})]})};Q.displayName="SeoPanel";exports.default=Q;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-EFWvSWoi.cjs"),m=require("./register-chai-top-bar-DWTuRU53.cjs"),c=require("./index-B5qvHqN5.cjs"),q=require("@tanstack/react-query"),I=require("lodash-es"),N=require("lucide-react"),x=require("react"),F=require("sonner"),z=()=>{const t=c.useApiUrl(),d=c.useFetch();return q.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,j]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[b,C]=x.useState(!1),{data:p}=c.useChaiCurrentPage(),{mutateAsync:S,isPending:f}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),w=q.useQueryClient();x.useEffect(()=>{j(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){F.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){F.toast.error("Invalid JSON-LD content");return}const y={name:r.name,jsonld:l.parsed,addToExistingPages:b,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(y.primaryPage=n.primaryPageId);const A=await S(y);p!=null&&p.id&&(A!=null&&A.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:A.id,pageId:p.id,enabled:!0}),w.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,p.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(m.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(N.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(m.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(m.Input,{id:"new-name",value:r.name,onChange:l=>j({...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(m.Input,{id:"new-description",value:r.description||"",onChange:l=>j({...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=>j({...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:b,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=>j({...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(m.Button,{disabled:f,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(m.Button,{disabled:f,type:"button",size:"sm",onClick:i,children:f?e.jsxs(e.Fragment,{children:[e.jsx(N.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}),[j,b]=x.useState(!1),[C,p]=x.useState(!1),[S,f]=x.useState(!1),{data:u}=z(),{mutateAsync:w,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:y}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var h,D;if(t&&u){const v=u.find(L=>L.id===t);v&&(r({name:v.name,description:((h=v.metadata)==null?void 0:h.description)||"",content:JSON.stringify(v.jsonld,null,2),enabledByDefaultForNewPages:((D=v.metadata)==null?void 0:D.addToNewPages)||!1}),f(!!v.primaryPage))}},[t,u]);const A=async()=>{if(!n.name||!n.content){F.toast.error("Please enter a name and content");return}const h=c.parseJSONWithPlaceholders(n.content);if(!h.isValid){F.toast.error("Invalid JSON-LD content");return}const D={id:t,name:n.name,jsonld:h.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await w(D),d()},O=async()=>{try{await l(t)}finally{b(!1)}},T=async()=>{try{await y(t)}finally{p(!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:[!S&&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(m.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>b(!0),children:"Add to all existing"}),e.jsx(m.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>p(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(m.Input,{id:"edit-name",value:n.name,onChange:h=>r({...n,name:h.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(m.Input,{id:"edit-description",value:n.description||"",onChange:h=>r({...n,description:h.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:h=>r({...n,content:h}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!S&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onChange:h=>r({...n,enabledByDefaultForNewPages:h.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(m.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(m.Button,{disabled:i,type:"button",size:"sm",onClick:A,children:i?e.jsxs(e.Fragment,{children:[e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:j,onOpenChange:b,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:O,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:C,onOpenChange:p,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),[j,b]=x.useState(null),[C,p]=x.useState(null),[S,f]=x.useState(null),{data:u,isLoading:w}=z(),{selectedLang:i}=s.useLanguages(),{data:l}=c.useChaiCurrentPage(),{data:y}=c.useLanguagePages(),{mutateAsync:A}=c.useDeleteGlobalSchema(),{mutateAsync:O}=c.useTogglePageGlobalSchema(),T=x.useMemo(()=>y==null?void 0:y.find(a=>!a.primaryPage&&a.lang===""),[y]),h=x.useMemo(()=>(T==null?void 0:T.globalJsonLds)||[],[T]),D=x.useMemo(()=>u?I.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const g=i?I.find(u,P=>P.primaryPage===o.id&&P.lang===i):null;return{defaultSchema:o,languageVersion:g,displayItem:g||o,hasLanguageVersion:!!g}}):[],[u,i]),[v,L]=x.useState([]),E=v.length>0?v:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&L(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const R=async a=>{if(!(l!=null&&l.id))return;f(a);const o=E.includes(a),g=o?E.filter(P=>P!==a):[...E,a];L(g);try{await O({schemaId:a,pageId:l.id,enabled:!o})}catch{L(l.globalJsonLds)}finally{f(null)}},M=async a=>{f(a);try{await A(a)}finally{f(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:w,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:w?e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(N.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)&&!w&&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:g})=>{var B,G;const P=E.includes(o.id),J=h.includes(a.id),k=g&&i?J:P;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${S===o.id?"pointer-events-none":""}`,children:[S===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(N.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:[(g||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:k,onChange:()=>R(a.id),disabled:!!(g&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),g&&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,g&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),k&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((B=o==null?void 0:o.metadata)==null?void 0:B.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(G=o==null?void 0:o.metadata)==null?void 0:G.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(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>p(o.id),children:e.jsx(N.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(g||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>b(o.id),children:e.jsx(N.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(N.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:()=>M(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!g&&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."]}),J&&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(m.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)})]}),w&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(N.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:j,onClose:()=>b(null)}),e.jsx(K,{schema:u==null?void 0:u.find(a=>a.id===C),onClose:()=>p(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"),s=require("./index-CfsIhbT2.cjs"),m=require("./register-chai-top-bar-DWTuRU53.cjs"),c=require("./index-BGGNVIKx.cjs"),q=require("@tanstack/react-query"),I=require("lodash-es"),N=require("lucide-react"),x=require("react"),F=require("sonner"),z=()=>{const t=c.useApiUrl(),d=c.useFetch();return q.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,j]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[b,C]=x.useState(!1),{data:p}=c.useChaiCurrentPage(),{mutateAsync:S,isPending:f}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),w=q.useQueryClient();x.useEffect(()=>{j(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){F.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){F.toast.error("Invalid JSON-LD content");return}const y={name:r.name,jsonld:l.parsed,addToExistingPages:b,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(y.primaryPage=n.primaryPageId);const A=await S(y);p!=null&&p.id&&(A!=null&&A.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:A.id,pageId:p.id,enabled:!0}),w.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,p.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(m.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(N.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(m.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(m.Input,{id:"new-name",value:r.name,onChange:l=>j({...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(m.Input,{id:"new-description",value:r.description||"",onChange:l=>j({...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=>j({...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:b,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=>j({...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(m.Button,{disabled:f,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(m.Button,{disabled:f,type:"button",size:"sm",onClick:i,children:f?e.jsxs(e.Fragment,{children:[e.jsx(N.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}),[j,b]=x.useState(!1),[C,p]=x.useState(!1),[S,f]=x.useState(!1),{data:u}=z(),{mutateAsync:w,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:y}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var h,D;if(t&&u){const v=u.find(L=>L.id===t);v&&(r({name:v.name,description:((h=v.metadata)==null?void 0:h.description)||"",content:JSON.stringify(v.jsonld,null,2),enabledByDefaultForNewPages:((D=v.metadata)==null?void 0:D.addToNewPages)||!1}),f(!!v.primaryPage))}},[t,u]);const A=async()=>{if(!n.name||!n.content){F.toast.error("Please enter a name and content");return}const h=c.parseJSONWithPlaceholders(n.content);if(!h.isValid){F.toast.error("Invalid JSON-LD content");return}const D={id:t,name:n.name,jsonld:h.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await w(D),d()},O=async()=>{try{await l(t)}finally{b(!1)}},T=async()=>{try{await y(t)}finally{p(!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:[!S&&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(m.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>b(!0),children:"Add to all existing"}),e.jsx(m.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>p(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(m.Input,{id:"edit-name",value:n.name,onChange:h=>r({...n,name:h.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(m.Input,{id:"edit-description",value:n.description||"",onChange:h=>r({...n,description:h.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:h=>r({...n,content:h}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!S&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onChange:h=>r({...n,enabledByDefaultForNewPages:h.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(m.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(m.Button,{disabled:i,type:"button",size:"sm",onClick:A,children:i?e.jsxs(e.Fragment,{children:[e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:j,onOpenChange:b,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:O,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:C,onOpenChange:p,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),[j,b]=x.useState(null),[C,p]=x.useState(null),[S,f]=x.useState(null),{data:u,isLoading:w}=z(),{selectedLang:i}=s.useLanguages(),{data:l}=c.useChaiCurrentPage(),{data:y}=c.useLanguagePages(),{mutateAsync:A}=c.useDeleteGlobalSchema(),{mutateAsync:O}=c.useTogglePageGlobalSchema(),T=x.useMemo(()=>y==null?void 0:y.find(a=>!a.primaryPage&&a.lang===""),[y]),h=x.useMemo(()=>(T==null?void 0:T.globalJsonLds)||[],[T]),D=x.useMemo(()=>u?I.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const g=i?I.find(u,P=>P.primaryPage===o.id&&P.lang===i):null;return{defaultSchema:o,languageVersion:g,displayItem:g||o,hasLanguageVersion:!!g}}):[],[u,i]),[v,L]=x.useState([]),E=v.length>0?v:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&L(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const R=async a=>{if(!(l!=null&&l.id))return;f(a);const o=E.includes(a),g=o?E.filter(P=>P!==a):[...E,a];L(g);try{await O({schemaId:a,pageId:l.id,enabled:!o})}catch{L(l.globalJsonLds)}finally{f(null)}},M=async a=>{f(a);try{await A(a)}finally{f(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:w,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:w?e.jsx(N.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(N.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)&&!w&&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:g})=>{var B,G;const P=E.includes(o.id),J=h.includes(a.id),k=g&&i?J:P;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${S===o.id?"pointer-events-none":""}`,children:[S===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(N.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:[(g||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:k,onChange:()=>R(a.id),disabled:!!(g&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),g&&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,g&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),k&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((B=o==null?void 0:o.metadata)==null?void 0:B.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(G=o==null?void 0:o.metadata)==null?void 0:G.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(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>p(o.id),children:e.jsx(N.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(g||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(m.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>b(o.id),children:e.jsx(N.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(N.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:()=>M(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!g&&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."]}),J&&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(m.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)})]}),w&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(N.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:j,onClose:()=>b(null)}),e.jsx(K,{schema:u==null?void 0:u.find(a=>a.id===C),onClose:()=>p(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
- import { D as W, e as $, f as X, g as Y, q as y, F as U, H as _, I as R, J as M, K as q, M as H, O as Q, Q as V, d as me, x as L, y as F, z as J, a3 as he, U as ue, V as ge, W as fe, G as pe, X as xe, T as Ne } from "./index-lm46VtIP.js";
2
+ import { D as W, e as $, f as X, g as Y, q as y, F as U, H as _, I as R, J as M, K as q, M as H, O as K, Q, d as me, x as L, y as F, z as J, a3 as he, U as ue, V as ge, W as fe, G as pe, X as xe, T as Ne } from "./index-iRqgNs2O.js";
3
3
  import { D as be, F as ye, z as j, B as v } from "./register-chai-top-bar-CX_JkRJn.js";
4
- import { ar as ve, as as we, A as K, aw as te, aC as Ce, aD as se, aE as re, aF as de, aG as Ae, aH as Se, aI as Pe, l as Te, aJ as De } from "./index-GfOB5KV1.js";
4
+ import { ar as ve, as as we, A as V, aw as te, aD as Ae, aE as se, aF as re, aG as de, aH as Ce, aI as Se, aJ as Pe, l as Te, aK as De } from "./index-ckjNCVor.js";
5
5
  import { useQuery as Ee, useQueryClient as Le } from "@tanstack/react-query";
6
6
  import { filter as Fe, find as Je } 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";
@@ -10,8 +10,8 @@ import { toast as B } from "sonner";
10
10
  const oe = () => {
11
11
  const l = ve(), i = we();
12
12
  return Ee({
13
- queryKey: [K.GET_GLOBAL_JSONLD_ITEMS],
14
- queryFn: async () => i(l, { action: K.GET_GLOBAL_JSONLD_ITEMS })
13
+ queryKey: [V.GET_GLOBAL_JSONLD_ITEMS],
14
+ queryFn: async () => i(l, { action: V.GET_GLOBAL_JSONLD_ITEMS })
15
15
  });
16
16
  }, Ie = ({
17
17
  show: l,
@@ -27,7 +27,7 @@ const oe = () => {
27
27
  content: "",
28
28
  description: "",
29
29
  enabledByDefaultForNewPages: !1
30
- }), [x, S] = g(!1), { data: u } = te(), { mutateAsync: A, isPending: p } = Ce(), { mutateAsync: c } = se(), w = Le();
30
+ }), [x, S] = g(!1), { data: u } = te(), { mutateAsync: C, isPending: p } = Ae(), { mutateAsync: c } = se(), w = Le();
31
31
  Z(() => {
32
32
  f(a ? {
33
33
  name: a.name,
@@ -54,13 +54,13 @@ const oe = () => {
54
54
  description: d.description
55
55
  };
56
56
  a != null && a.primaryPageId && (N.primaryPage = a.primaryPageId);
57
- const C = await A(N);
58
- u != null && u.id && (C != null && C.id) && !(a != null && a.primaryPageId) && (await c({
59
- schemaId: C.id,
57
+ const A = await C(N);
58
+ u != null && u.id && (A != null && A.id) && !(a != null && a.primaryPageId) && (await c({
59
+ schemaId: A.id,
60
60
  pageId: u.id,
61
61
  enabled: !0
62
62
  }), w.invalidateQueries({
63
- queryKey: [K.GET_LANGUAGE_PAGES, u.id]
63
+ queryKey: [V.GET_LANGUAGE_PAGES, u.id]
64
64
  })), i();
65
65
  };
66
66
  return /* @__PURE__ */ n($, { className: "flex max-w-xl flex-col overflow-y-auto", children: [
@@ -164,7 +164,7 @@ const oe = () => {
164
164
  content: "",
165
165
  description: "",
166
166
  enabledByDefaultForNewPages: !1
167
- }), [f, x] = g(!1), [S, u] = g(!1), [A, p] = g(!1), { data: c } = oe(), { mutateAsync: w, isPending: o } = Ae(), { mutateAsync: t } = Se(), { mutateAsync: N } = Pe();
167
+ }), [f, x] = g(!1), [S, u] = g(!1), [C, p] = g(!1), { data: c } = oe(), { mutateAsync: w, isPending: o } = Ce(), { mutateAsync: t } = Se(), { mutateAsync: N } = Pe();
168
168
  Z(() => {
169
169
  var m, T;
170
170
  if (l && c) {
@@ -177,7 +177,7 @@ const oe = () => {
177
177
  }), p(!!b.primaryPage));
178
178
  }
179
179
  }, [l, c]);
180
- const C = async () => {
180
+ const A = async () => {
181
181
  if (!a.name || !a.content) {
182
182
  B.error("Please enter a name and content");
183
183
  return;
@@ -211,7 +211,7 @@ const oe = () => {
211
211
  return /* @__PURE__ */ n($, { className: "flex max-w-xl flex-col overflow-y-auto", children: [
212
212
  /* @__PURE__ */ e(X, { children: /* @__PURE__ */ e(Y, { children: "Edit Shared JSON-LD Schema" }) }),
213
213
  /* @__PURE__ */ n("div", { className: "flex max-h-[75vh] flex-col space-y-2 overflow-y-auto", children: [
214
- !A && /* @__PURE__ */ n("div", { className: "flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2", children: [
214
+ !C && /* @__PURE__ */ n("div", { className: "flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2", children: [
215
215
  /* @__PURE__ */ n("div", { children: [
216
216
  /* @__PURE__ */ e("div", { className: "text-sm font-medium text-blue-900", children: "Manage Existing Pages" }),
217
217
  /* @__PURE__ */ e("div", { className: "text-xs text-blue-700", children: "Add or remove this schema from all existing pages on your site" })
@@ -259,7 +259,7 @@ const oe = () => {
259
259
  }
260
260
  )
261
261
  ] }),
262
- !A && /* @__PURE__ */ n("div", { className: "flex items-center space-x-2", children: [
262
+ !C && /* @__PURE__ */ n("div", { className: "flex items-center space-x-2", children: [
263
263
  /* @__PURE__ */ e(
264
264
  "input",
265
265
  {
@@ -277,7 +277,7 @@ const oe = () => {
277
277
  ] }),
278
278
  /* @__PURE__ */ e("div", { className: "border-t pt-3", children: /* @__PURE__ */ n("div", { className: "flex items-center justify-end gap-2", children: [
279
279
  /* @__PURE__ */ e(v, { disabled: o, variant: "outline", type: "button", size: "sm", onClick: () => i(), children: "Cancel" }),
280
- /* @__PURE__ */ e(v, { disabled: o, type: "button", size: "sm", onClick: C, children: o ? /* @__PURE__ */ n(G, { children: [
280
+ /* @__PURE__ */ e(v, { disabled: o, type: "button", size: "sm", onClick: A, children: o ? /* @__PURE__ */ n(G, { children: [
281
281
  /* @__PURE__ */ e(O, { className: "h-4 w-4 animate-spin" }),
282
282
  " Updating"
283
283
  ] }) : "Update Schema" })
@@ -293,8 +293,8 @@ const oe = () => {
293
293
  ] })
294
294
  ] }),
295
295
  /* @__PURE__ */ n(H, { children: [
296
- /* @__PURE__ */ e(Q, { children: "Cancel" }),
297
- /* @__PURE__ */ e(V, { onClick: I, children: "Add to All" })
296
+ /* @__PURE__ */ e(K, { children: "Cancel" }),
297
+ /* @__PURE__ */ e(Q, { onClick: I, children: "Add to All" })
298
298
  ] })
299
299
  ] }) }),
300
300
  /* @__PURE__ */ e(U, { open: S, onOpenChange: u, children: /* @__PURE__ */ n(_, { children: [
@@ -307,14 +307,14 @@ const oe = () => {
307
307
  ] })
308
308
  ] }),
309
309
  /* @__PURE__ */ n(H, { children: [
310
- /* @__PURE__ */ e(Q, { children: "Cancel" }),
311
- /* @__PURE__ */ e(V, { onClick: P, className: "bg-red-500 hover:bg-red-600", children: "Remove from All" })
310
+ /* @__PURE__ */ e(K, { children: "Cancel" }),
311
+ /* @__PURE__ */ e(Q, { onClick: P, className: "bg-red-500 hover:bg-red-600", children: "Remove from All" })
312
312
  ] })
313
313
  ] }) })
314
314
  ] });
315
315
  };
316
316
  function Ye() {
317
- const [l, i] = g(!1), [a, d] = g(void 0), [f, x] = g(null), [S, u] = g(null), [A, p] = g(null), { data: c, isLoading: w } = oe(), { selectedLang: o } = me(), { data: t } = te(), { data: N } = Te(), { mutateAsync: C } = De(), { mutateAsync: I } = se(), P = z(() => N == null ? void 0 : N.find((s) => !s.primaryPage && s.lang === ""), [N]), m = z(() => (P == null ? void 0 : P.globalJsonLds) || [], [P]), T = z(() => c ? Fe(c, (r) => r.primaryPage === null && r.lang === "").map((r) => {
317
+ const [l, i] = g(!1), [a, d] = g(void 0), [f, x] = g(null), [S, u] = g(null), [C, p] = g(null), { data: c, isLoading: w } = oe(), { selectedLang: o } = me(), { data: t } = te(), { data: N } = Te(), { mutateAsync: A } = De(), { mutateAsync: I } = se(), P = z(() => N == null ? void 0 : N.find((s) => !s.primaryPage && s.lang === ""), [N]), m = z(() => (P == null ? void 0 : P.globalJsonLds) || [], [P]), T = z(() => c ? Fe(c, (r) => r.primaryPage === null && r.lang === "").map((r) => {
318
318
  const h = o ? Je(c, (D) => D.primaryPage === r.id && D.lang === o) : null;
319
319
  return {
320
320
  defaultSchema: r,
@@ -346,7 +346,7 @@ function Ye() {
346
346
  }, ce = async (s) => {
347
347
  p(s);
348
348
  try {
349
- await C(s);
349
+ await A(s);
350
350
  } finally {
351
351
  p(null);
352
352
  }
@@ -382,9 +382,9 @@ function Ye() {
382
382
  return /* @__PURE__ */ n(
383
383
  ue,
384
384
  {
385
- className: `relative border-gray-300 p-0 shadow-none transition-all ${A === r.id ? "pointer-events-none" : ""}`,
385
+ className: `relative border-gray-300 p-0 shadow-none transition-all ${C === r.id ? "pointer-events-none" : ""}`,
386
386
  children: [
387
- A === r.id && /* @__PURE__ */ e("div", { className: "absolute bottom-0 left-0 right-0 top-0 z-50 flex items-center justify-center rounded-xl bg-white/80", children: /* @__PURE__ */ e(O, { className: "h-5 w-5 animate-spin text-primary" }) }),
387
+ C === r.id && /* @__PURE__ */ e("div", { className: "absolute bottom-0 left-0 right-0 top-0 z-50 flex items-center justify-center rounded-xl bg-white/80", children: /* @__PURE__ */ e(O, { className: "h-5 w-5 animate-spin text-primary" }) }),
388
388
  /* @__PURE__ */ e(ge, { className: "p-2", children: /* @__PURE__ */ n("div", { className: "flex items-center justify-between", children: [
389
389
  /* @__PURE__ */ n("div", { className: "flex items-center gap-3", children: [
390
390
  (h || !o) && /* @__PURE__ */ n(L, { delayDuration: 0, children: [
@@ -460,9 +460,9 @@ function Ye() {
460
460
  ] })
461
461
  ] }),
462
462
  /* @__PURE__ */ n(H, { children: [
463
- /* @__PURE__ */ e(Q, { type: "button", children: "Cancel" }),
463
+ /* @__PURE__ */ e(K, { type: "button", children: "Cancel" }),
464
464
  /* @__PURE__ */ e(
465
- V,
465
+ Q,
466
466
  {
467
467
  type: "button",
468
468
  onClick: () => ce(r.id),
@@ -1,6 +1,6 @@
1
1
  import { jsxs as i, jsx as o } from "react/jsx-runtime";
2
2
  import { z as v } from "./register-chai-top-bar-CX_JkRJn.js";
3
- import { L as d } from "./index-lm46VtIP.js";
3
+ import { L as d } from "./index-iRqgNs2O.js";
4
4
  import { useState as x, useEffect as C } from "react";
5
5
  const y = (e) => {
6
6
  if (!e) return { base: e, extension: null };
@@ -1 +1 @@
1
- "use strict";const s=require("react/jsx-runtime"),b=require("./register-chai-top-bar-DWTuRU53.cjs"),u=require("./index-EFWvSWoi.cjs"),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 o=t.pop()||"";a=!!u.LANGUAGES[o]}}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:o}){const[g,p]=d.useState(e),[l,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:l?"border-red-500":""}),l&&s.jsx("div",{className:"mt-1 text-xs text-red-500",children:l})]}),o&&o!=="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:o})]})})]})}exports.SlugInput=A;exports.combineParentChildSlugs=C;exports.parseSlugForEdit=E;exports.removeSlugExtension=x;
1
+ "use strict";const s=require("react/jsx-runtime"),b=require("./register-chai-top-bar-DWTuRU53.cjs"),u=require("./index-CfsIhbT2.cjs"),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 o=t.pop()||"";a=!!u.LANGUAGES[o]}}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:o}){const[g,p]=d.useState(e),[l,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:l?"border-red-500":""}),l&&s.jsx("div",{className:"mt-1 text-xs text-red-500",children:l})]}),o&&o!=="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:o})]})})]})}exports.SlugInput=A;exports.combineParentChildSlugs=C;exports.parseSlugForEdit=E;exports.removeSlugExtension=x;
@@ -1 +1 @@
1
- "use strict";var O=Object.defineProperty;var D=(l,r,e)=>r in l?O(l,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):l[r]=e;var y=(l,r,e)=>D(l,typeof r!="symbol"?r+"":r,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./actions-registery-DFKvH08w.cjs"),f=require("lodash-es"),b=require("sharp"),c=require("zod");class A{constructor(r,e,t){this.appId=r,this.userId=e,this.supabase=t}appendUpdatedAtToUrl(r,e){if(f.isEmpty(r))return"";const t=new URL(r),o=new Date(e).getTime();return t.searchParams.set("t",o.toString()),`${t.origin}${t.pathname}${t.search}${t.hash}`}getBufferFromBase64(r){try{const e=r.split(",")[1]||r;return Buffer.from(e,"base64")}catch{throw new Error("Invalid base64 string format")}}async uploadImageFile(r,e,t,o){try{const s=this.getBufferFromBase64(r),n=await b(s).metadata(),i=["jpeg","jpg","png","webp","gif","svg","tiff"];if(!n.format||!i.includes(n.format.toLowerCase()))throw new Error(`Invalid image format: ${n.format||"unknown"}`);const u=o?await b(s).webp({quality:100}).resize({width:Math.min(n.width||2e3,2e3)}).toBuffer():await b(s).webp({quality:100}).toBuffer();let a=u;if(o&&u.length>120*1024){const _=Math.floor(90*(122880/u.length));a=await b(s).webp({quality:_}).resize({width:Math.min(n.width||2e3,2e3)}).toBuffer()}const d=await b(a).metadata(),g=await b(s).webp({quality:70}).resize({width:300}).toBuffer(),p=t.split("."),m=p.length>1?p.slice(0,-1).join("."):t,w=`${f.kebabCase(m)}.webp`,z=`${w}_thumbnail.webp`,T=this.appId,I=e?`${T}/${e}`:T,S=h.getChaiAction("UPLOAD_TO_STORAGE");if(!S)throw new Error("UPLOAD_TO_STORAGE action not found");S.setContext({appId:this.appId,userId:this.userId});const U=await S.execute({file:a.toString("base64"),fileName:w,contentType:"image/webp",folder:I});if(U.error)throw new Error(U.error);const E=await S.execute({file:g.toString("base64"),fileName:z,contentType:"image/webp",folder:I});if(E.error)throw new Error(E.error);return{url:U.data.url,thumbnailUrl:E.data.url,size:d.size||a.length,width:d.width||0,height:d.height||0,mimeType:"image/webp"}}catch(s){return console.error("Upload image error:",s),{error:s instanceof Error?s.message:"Unknown error"}}}async uploadSvgFile(r,e,t){try{const o=this.getBufferFromBase64(r);let s,n;try{const w=await b(o).metadata();s=w.width,n=w.height}catch{}const i=t.split("."),u=i.length>1?i.slice(0,-1).join("."):t,a=`${f.kebabCase(u)}.svg`,d=this.appId,g=e?`${d}/${e}`:d,p=h.getChaiAction("UPLOAD_TO_STORAGE");if(!p)throw new Error("UPLOAD_TO_STORAGE action not found");p.setContext({appId:this.appId,userId:this.userId});const m=await p.execute({file:o.toString("base64"),fileName:a,contentType:"image/svg+xml",folder:g});if(m.error)throw new Error(m.error);return{url:m.data.url,thumbnailUrl:m.data.url,size:o.length,width:s,height:n,mimeType:"image/svg+xml"}}catch(o){return console.error("SVG upload error:",o),{error:o instanceof Error?o.message:"Unknown error"}}}async upload({file:r,folderId:e,name:t,optimize:o=!0}){var s;try{const i=t.toLowerCase().endsWith(".svg")||r.includes("data:image/svg+xml")?await this.uploadSvgFile(r,e,t):await this.uploadImageFile(r,e,t,o??!0);if("error"in i)return i;const u={name:t,app:this.appId,url:i.url,thumbnailUrl:i.thumbnailUrl,size:(s=i.size)==null?void 0:s.toString(),width:i.width,height:i.height,format:i.mimeType.split("/")[1],folderId:e,type:i.mimeType.startsWith("image/")?"image":"file",createdBy:this.userId,updatedAt:new Date().toISOString()},{data:a,error:d}=await this.supabase.from("app_assets").insert(u).select("*").single();if(d)throw new Error(`Failed to store asset in database: ${d.message}`);return{id:a.id,name:a.name,type:a.type,url:this.appendUpdatedAtToUrl(a.url,a.updatedAt),size:a.size,thumbnailUrl:this.appendUpdatedAtToUrl(a.thumbnailUrl||"",a.updatedAt),width:a.width,height:a.height,format:a.format,folderId:a.folderId,createdBy:a.createdBy||"",createdAt:a.createdAt,updatedAt:a.updatedAt}}catch(n){return{error:n instanceof Error?n.message:"Unknown error occurred"}}}async getAsset({id:r}){try{const{data:e,error:t}=await this.supabase.from("app_assets").select("*").eq("id",r).eq("app",this.appId).single();if(t)throw new Error(`Failed to fetch asset: ${t.message}`);return f.set(e,"url",this.appendUpdatedAtToUrl(e.url,e.updatedAt)),f.set(e,"thumbnailUrl",this.appendUpdatedAtToUrl(e.thumbnailUrl||"",e.updatedAt)),e}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async getAssets({search:r="",page:e=1,limit:t=20}={}){try{const o=(e-1)*t;let s=this.supabase.from("app_assets").select("*",{count:"exact"}).eq("app",this.appId).order("updatedAt",{ascending:!1});r&&(s=s.or(`name.ilike.%${r}%,description.ilike.%${r}%`));const{data:n,error:i,count:u}=await s.range(o,o+t-1);if(i)throw new Error(i.message);return{assets:n.map(d=>(f.set(d,"url",this.appendUpdatedAtToUrl(d.url,d.updatedAt)),f.set(d,"thsupabaseumbnailUrl",this.appendUpdatedAtToUrl(d.thumbnailUrl||"",d.updatedAt)),d)),total:u||0,page:e,pageSize:t}}catch(o){throw console.error("Error fetching assets:",o),o}}async deleteAsset({id:r}){try{const{data:e,error:t}=await this.supabase.from("app_assets").select("*").eq("id",r).eq("app",this.appId).single();if(t)throw new Error(`Failed to fetch asset: ${t.message}`);if(e.url)try{const n=new URL(e.url).pathname.split("/"),i=n.indexOf("dam-assets");if(i!==-1){const u=n.slice(i+1).join("/"),a=h.getChaiAction("DELETE_FROM_STORAGE");if(a&&(a.setContext({appId:this.appId,userId:this.userId}),await a.execute({key:u})),e.thumbnailUrl&&e.thumbnailUrl!==e.url){const g=new URL(e.thumbnailUrl).pathname.split("/"),p=g.indexOf("dam-assets");if(p!==-1){const m=g.slice(p+1).join("/");a&&await a.execute({key:m})}}}}catch(s){console.warn("Failed to delete from storage, continuing with database deletion:",s)}const{error:o}=await this.supabase.from("app_assets").delete().eq("id",r);if(o)throw new Error(`Failed to delete asset: ${o.message}`);return{success:!0}}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async updateAsset({id:r,file:e,description:t}){var o,s;try{const{data:n,error:i}=await this.supabase.from("app_assets").select("*").eq("id",r).single();if(i)throw new Error(`Failed to fetch asset: ${i.message}`);const u={};if(t!==void 0&&(u.description=t,u.updatedAt=new Date().toISOString()),e){const p=((o=n.format)==null?void 0:o.toLowerCase())==="svg"||e.includes("data:image/svg+xml")?await this.uploadSvgFile(e,n.folderId,n.name):await this.uploadImageFile(e,n.folderId,n.name,!0);if("error"in p)return p;u.url=p.url,u.thumbnailUrl=p.thumbnailUrl,u.size=(s=p.size)==null?void 0:s.toString(),u.width=p.width,u.height=p.height,u.format=p.mimeType.split("/")[1],u.updatedAt=new Date().toISOString()}const{data:a,error:d}=await this.supabase.from("app_assets").update(u).eq("id",r).select().single();if(d)throw new Error(`Failed to update asset: ${d.message}`);return f.set(a,"url",this.appendUpdatedAtToUrl(a.url,a.updatedAt)),f.set(a,"thumbnailUrl",this.appendUpdatedAtToUrl(a.thumbnailUrl||"",a.updatedAt)),a}catch(n){return{error:n instanceof Error?n.message:"Unknown error occurred"}}}}const C=c.z.object({name:c.z.string(),file:c.z.string(),folderId:c.z.string().optional().nullable(),optimize:c.z.boolean().optional()});class F extends h.ChaiBaseAction{constructor(r){super(),this.supabase=r}getValidationSchema(){return C}async execute(r){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:t}=this.context;if(!t)return{error:"User ID is required",status:401};const s=await new A(e,t,this.supabase).upload(r);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPLOAD_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const B=c.z.object({id:c.z.string()});class v extends h.ChaiBaseAction{constructor(r){super(),this.supabase=r}getValidationSchema(){return B}async execute(r){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:t}=this.context;if(!t)return{error:"User ID is required",status:401};const s=await new A(e,t,this.supabase).getAsset(r);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const $=c.z.object({search:c.z.string().optional(),page:c.z.number().optional(),limit:c.z.number().optional()});class q extends h.ChaiBaseAction{constructor(r){super(),this.supabase=r}getValidationSchema(){return $}async execute(r){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:t}=this.context;if(!t)return{error:"User ID is required",status:401};const s=await new A(e,t,this.supabase).getAssets(r);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSETS error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const G=c.z.object({id:c.z.string()});class j extends h.ChaiBaseAction{constructor(r){super(),this.supabase=r}getValidationSchema(){return G}async execute(r){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:t}=this.context;if(!t)return{error:"User ID is required",status:401};const s=await new A(e,t,this.supabase).deleteAsset(r);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("DELETE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const L=c.z.object({id:c.z.string(),file:c.z.string().optional(),description:c.z.string().optional()});class P extends h.ChaiBaseAction{constructor(r){super(),this.supabase=r}getValidationSchema(){return L}async execute(r){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:t}=this.context;if(!t)return{error:"User ID is required",status:401};const s=await new A(e,t,this.supabase).updateAsset(r);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPDATE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const R=c.z.object({userId:c.z.string()});class M extends h.ChaiBaseAction{constructor(r){super(),this.supabase=r}getValidationSchema(){return R}async execute(r){var e,t,o,s,n,i;try{const{userId:u}=r,{data:a,error:d}=await this.supabase.auth.admin.getUserById(u);return d?{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}:{data:{id:((e=a.user)==null?void 0:e.id)||"unknown",email:((t=a.user)==null?void 0:t.email)||"unknown@chaibuilder.com",name:((s=(o=a.user)==null?void 0:o.user_metadata)==null?void 0:s.name)||"Unknown",avatar:((i=(n=a.user)==null?void 0:n.user_metadata)==null?void 0:i.avatar_url)||""},status:200}}catch{return{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}}}}const N=c.z.object({key:c.z.string()});class x extends h.ChaiBaseAction{constructor(e){super();y(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return N}async execute(e){try{const{key:t}=e,{error:o}=await this.supabase.storage.from(this.bucketName).remove([t]);return o?{error:`Failed to delete from Supabase Storage: ${o.message}`,status:500}:{data:{success:!0},status:200}}catch(t){return console.error("DELETE_FROM_STORAGE error:",t),{error:t instanceof Error?t.message:"Unknown error",status:500}}}}const V=c.z.object({file:c.z.string(),fileName:c.z.string(),contentType:c.z.string().optional(),folder:c.z.string().optional(),metadata:c.z.record(c.z.string(),c.z.any()).optional()});class k extends h.ChaiBaseAction{constructor(e){super();y(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return V}async execute(e){try{if(!this.context)return{error:"Context not set",status:400};const{appId:t}=this.context,{file:o,fileName:s,contentType:n,folder:i,metadata:u}=e;let a;if(typeof o=="string"){const w=o.split(",")[1]||o;a=Buffer.from(w,"base64")}else a=o;const d=i?`${i}/${s}`:`${t}/${s}`,{data:g,error:p}=await this.supabase.storage.from(this.bucketName).upload(d,a,{contentType:n||"application/octet-stream",upsert:!0,...u&&{metadata:u}});if(p)return{error:`Failed to upload to Supabase Storage: ${p.message}`,status:500};const{data:{publicUrl:m}}=this.supabase.storage.from(this.bucketName).getPublicUrl(d);return{data:{url:m,key:g.path,size:a.length,metadata:u},status:200}}catch(t){return console.error("UPLOAD_TO_STORAGE error:",t),{error:t instanceof Error?t.message:"Unknown error",status:500}}}}const W=l=>({GET_CHAI_USER:new M(l)}),H=l=>({UPLOAD_ASSET:new F(l),GET_ASSET:new v(l),GET_ASSETS:new q(l),DELETE_ASSET:new j(l),UPDATE_ASSET:new P(l),UPLOAD_TO_STORAGE:new k(l),DELETE_FROM_STORAGE:new x(l)});exports.DeleteFromStorageAction=x;exports.SupabaseAuthActions=W;exports.SupabaseStorageActions=H;exports.UploadToStorageAction=k;
1
+ "use strict";var D=Object.defineProperty;var O=(u,t,e)=>t in u?D(u,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):u[t]=e;var y=(u,t,e)=>O(u,typeof t!="symbol"?t+"":t,e);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("./actions-registery-DFKvH08w.cjs"),w=require("lodash-es"),b=require("sharp"),i=require("zod");class A{constructor(t,e,r){this.appId=t,this.userId=e,this.supabase=r}appendUpdatedAtToUrl(t,e){if(w.isEmpty(t))return"";const r=new URL(t),o=new Date(e).getTime();return r.searchParams.set("t",o.toString()),`${r.origin}${r.pathname}${r.search}${r.hash}`}getBufferFromBase64(t){try{const e=t.split(",")[1]||t;return Buffer.from(e,"base64")}catch{throw new Error("Invalid base64 string format")}}async uploadImageFile(t,e,r,o){try{const s=this.getBufferFromBase64(t),n=await b(s).metadata(),c=["jpeg","jpg","png","webp","gif","svg","tiff"];if(!n.format||!c.includes(n.format.toLowerCase()))throw new Error(`Invalid image format: ${n.format||"unknown"}`);const d=o?await b(s).webp({quality:100}).resize({width:Math.min(n.width||2e3,2e3)}).toBuffer():await b(s).webp({quality:100}).toBuffer();let a=d;if(o&&d.length>120*1024){const _=Math.floor(90*(122880/d.length));a=await b(s).webp({quality:_}).resize({width:Math.min(n.width||2e3,2e3)}).toBuffer()}const l=await b(a).metadata(),g=await b(s).webp({quality:70}).resize({width:300}).toBuffer(),p=r.split("."),m=p.length>1?p.slice(0,-1).join("."):r,f=`${w.kebabCase(m)}.webp`,k=`${f}_thumbnail.webp`,T=this.appId,I=e?`${T}/${e}`:T,S=h.getChaiAction("UPLOAD_TO_STORAGE");if(!S)throw new Error("UPLOAD_TO_STORAGE action not found");S.setContext({appId:this.appId,userId:this.userId});const U=await S.execute({file:a.toString("base64"),fileName:f,contentType:"image/webp",folder:I});if(U.error)throw new Error(U.error);const E=await S.execute({file:g.toString("base64"),fileName:k,contentType:"image/webp",folder:I});if(E.error)throw new Error(E.error);return{url:U.data.url,thumbnailUrl:E.data.url,size:l.size||a.length,width:l.width||0,height:l.height||0,mimeType:"image/webp"}}catch(s){return console.error("Upload image error:",s),{error:s instanceof Error?s.message:"Unknown error"}}}async uploadSvgFile(t,e,r){try{const o=this.getBufferFromBase64(t);let s,n;try{const f=await b(o).metadata();s=f.width,n=f.height}catch{}const c=r.split("."),d=c.length>1?c.slice(0,-1).join("."):r,a=`${w.kebabCase(d)}.svg`,l=this.appId,g=e?`${l}/${e}`:l,p=h.getChaiAction("UPLOAD_TO_STORAGE");if(!p)throw new Error("UPLOAD_TO_STORAGE action not found");p.setContext({appId:this.appId,userId:this.userId});const m=await p.execute({file:o.toString("base64"),fileName:a,contentType:"image/svg+xml",folder:g});if(m.error)throw new Error(m.error);return{url:m.data.url,thumbnailUrl:m.data.url,size:o.length,width:s,height:n,mimeType:"image/svg+xml"}}catch(o){return console.error("SVG upload error:",o),{error:o instanceof Error?o.message:"Unknown error"}}}async upload({file:t,folderId:e,name:r,optimize:o=!0}){var s;try{const c=r.toLowerCase().endsWith(".svg")||t.includes("data:image/svg+xml")?await this.uploadSvgFile(t,e,r):await this.uploadImageFile(t,e,r,o??!0);if("error"in c)return c;const d={name:r,app:this.appId,url:c.url,thumbnailUrl:c.thumbnailUrl,size:(s=c.size)==null?void 0:s.toString(),width:c.width,height:c.height,format:c.mimeType.split("/")[1],folderId:e,type:c.mimeType.startsWith("image/")?"image":"file",createdBy:this.userId,updatedAt:new Date().toISOString()},{data:a,error:l}=await this.supabase.from("app_assets").insert(d).select("*").single();if(l)throw new Error(`Failed to store asset in database: ${l.message}`);return{id:a.id,name:a.name,type:a.type,url:this.appendUpdatedAtToUrl(a.url,a.updatedAt),size:a.size,thumbnailUrl:this.appendUpdatedAtToUrl(a.thumbnailUrl||"",a.updatedAt),width:a.width,height:a.height,format:a.format,folderId:a.folderId,createdBy:a.createdBy||"",createdAt:a.createdAt,updatedAt:a.updatedAt}}catch(n){return{error:n instanceof Error?n.message:"Unknown error occurred"}}}async getAsset({id:t}){try{const{data:e,error:r}=await this.supabase.from("app_assets").select("*").eq("id",t).eq("app",this.appId).single();if(r)throw new Error(`Failed to fetch asset: ${r.message}`);return w.set(e,"url",this.appendUpdatedAtToUrl(e.url,e.updatedAt)),w.set(e,"thumbnailUrl",this.appendUpdatedAtToUrl(e.thumbnailUrl||"",e.updatedAt)),e}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async getAssets({search:t="",page:e=1,limit:r=20}={}){try{const o=(e-1)*r;let s=this.supabase.from("app_assets").select("*",{count:"exact"}).eq("app",this.appId).order("updatedAt",{ascending:!1});t&&(s=s.or(`name.ilike.%${t}%,description.ilike.%${t}%`));const{data:n,error:c,count:d}=await s.range(o,o+r-1);if(c)throw new Error(c.message);return{assets:n.map(l=>(w.set(l,"url",this.appendUpdatedAtToUrl(l.url,l.updatedAt)),w.set(l,"thsupabaseumbnailUrl",this.appendUpdatedAtToUrl(l.thumbnailUrl||"",l.updatedAt)),l)),total:d||0,page:e,pageSize:r}}catch(o){throw console.error("Error fetching assets:",o),o}}async deleteAsset({id:t}){try{const{data:e,error:r}=await this.supabase.from("app_assets").select("*").eq("id",t).eq("app",this.appId).single();if(r)throw new Error(`Failed to fetch asset: ${r.message}`);if(e.url)try{const n=new URL(e.url).pathname.split("/"),c=n.indexOf("dam-assets");if(c!==-1){const d=n.slice(c+1).join("/"),a=h.getChaiAction("DELETE_FROM_STORAGE");if(a&&(a.setContext({appId:this.appId,userId:this.userId}),await a.execute({key:d})),e.thumbnailUrl&&e.thumbnailUrl!==e.url){const g=new URL(e.thumbnailUrl).pathname.split("/"),p=g.indexOf("dam-assets");if(p!==-1){const m=g.slice(p+1).join("/");a&&await a.execute({key:m})}}}}catch(s){console.warn("Failed to delete from storage, continuing with database deletion:",s)}const{error:o}=await this.supabase.from("app_assets").delete().eq("id",t);if(o)throw new Error(`Failed to delete asset: ${o.message}`);return{success:!0}}catch(e){return{error:e instanceof Error?e.message:"Unknown error occurred"}}}async updateAsset({id:t,file:e,description:r}){var o,s;try{const{data:n,error:c}=await this.supabase.from("app_assets").select("*").eq("id",t).single();if(c)throw new Error(`Failed to fetch asset: ${c.message}`);const d={};if(r!==void 0&&(d.description=r,d.updatedAt=new Date().toISOString()),e){const p=((o=n.format)==null?void 0:o.toLowerCase())==="svg"||e.includes("data:image/svg+xml")?await this.uploadSvgFile(e,n.folderId,n.name):await this.uploadImageFile(e,n.folderId,n.name,!0);if("error"in p)return p;d.url=p.url,d.thumbnailUrl=p.thumbnailUrl,d.size=(s=p.size)==null?void 0:s.toString(),d.width=p.width,d.height=p.height,d.format=p.mimeType.split("/")[1],d.updatedAt=new Date().toISOString()}const{data:a,error:l}=await this.supabase.from("app_assets").update(d).eq("id",t).select().single();if(l)throw new Error(`Failed to update asset: ${l.message}`);return w.set(a,"url",this.appendUpdatedAtToUrl(a.url,a.updatedAt)),w.set(a,"thumbnailUrl",this.appendUpdatedAtToUrl(a.thumbnailUrl||"",a.updatedAt)),a}catch(n){return{error:n instanceof Error?n.message:"Unknown error occurred"}}}}const C=i.z.object({name:i.z.string(),file:i.z.string(),folderId:i.z.string().optional().nullable(),optimize:i.z.boolean().optional()});class P extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return C}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new A(e,r,this.supabase).upload(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPLOAD_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const F=i.z.object({id:i.z.string()});class B extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return F}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new A(e,r,this.supabase).getAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const v=i.z.object({search:i.z.string().optional(),page:i.z.number().optional(),limit:i.z.number().optional()});class $ extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return v}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new A(e,r,this.supabase).getAssets(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("GET_ASSETS error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const q=i.z.object({id:i.z.string()});class G extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return q}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new A(e,r,this.supabase).deleteAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("DELETE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const L=i.z.object({id:i.z.string(),file:i.z.string().optional(),description:i.z.string().optional()});class j extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return L}async execute(t){try{if(!this.context)return{error:"Context not set",status:400};const{appId:e,userId:r}=this.context;if(!r)return{error:"User ID is required",status:401};const s=await new A(e,r,this.supabase).updateAsset(t);return"error"in s?{error:s.error,status:400}:s}catch(e){return console.error("UPDATE_ASSET error:",e),{error:e instanceof Error?e.message:"Unknown error",status:500}}}}const R=i.z.object({userId:i.z.string()});class N extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return R}async execute(t){var e,r,o,s,n,c;try{const{userId:d}=t,{data:a,error:l}=await this.supabase.auth.admin.getUserById(d);return l?{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}:{data:{id:((e=a.user)==null?void 0:e.id)||"unknown",email:((r=a.user)==null?void 0:r.email)||"unknown@chaibuilder.com",name:((s=(o=a.user)==null?void 0:o.user_metadata)==null?void 0:s.name)||"Unknown",avatar:((c=(n=a.user)==null?void 0:n.user_metadata)==null?void 0:c.avatar_url)||""},status:200}}catch{return{data:{id:"unknown",email:"unknown@chaibuilder.com",name:"Unknown",avatar:""},status:200}}}}const M=i.z.object({email:i.z.string().email(),oldPassword:i.z.string().min(1,"Old password is required"),newPassword:i.z.string().min(8,"New password must be at least 8 characters"),confirmPassword:i.z.string().min(1,"Confirm password is required")}).refine(u=>u.newPassword===u.confirmPassword,{message:"Confirm password does not match",path:["confirmPassword"]});class V extends h.ChaiBaseAction{constructor(t){super(),this.supabase=t}getValidationSchema(){return M}async execute(t){try{const{email:e,oldPassword:r,newPassword:o}=t,{error:s}=await this.supabase.auth.signInWithPassword({email:e,password:r});if(s)throw new h.ActionError("Current password is incorrect","INVALID_PASSWORD",400);const{error:n}=await this.supabase.auth.updateUser({password:o});if(n)throw new h.ActionError(n.message||"Failed to update password","UPDATE_FAILED",400);return{data:{message:"Password changed successfully"},status:200}}catch(e){throw e}}}const W=i.z.object({key:i.z.string()});class x extends h.ChaiBaseAction{constructor(e){super();y(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return W}async execute(e){try{const{key:r}=e,{error:o}=await this.supabase.storage.from(this.bucketName).remove([r]);return o?{error:`Failed to delete from Supabase Storage: ${o.message}`,status:500}:{data:{success:!0},status:200}}catch(r){return console.error("DELETE_FROM_STORAGE error:",r),{error:r instanceof Error?r.message:"Unknown error",status:500}}}}const H=i.z.object({file:i.z.string(),fileName:i.z.string(),contentType:i.z.string().optional(),folder:i.z.string().optional(),metadata:i.z.record(i.z.string(),i.z.any()).optional()});class z extends h.ChaiBaseAction{constructor(e){super();y(this,"bucketName","dam-assets");this.supabase=e}getValidationSchema(){return H}async execute(e){try{if(!this.context)return{error:"Context not set",status:400};const{appId:r}=this.context,{file:o,fileName:s,contentType:n,folder:c,metadata:d}=e;let a;if(typeof o=="string"){const f=o.split(",")[1]||o;a=Buffer.from(f,"base64")}else a=o;const l=c?`${c}/${s}`:`${r}/${s}`,{data:g,error:p}=await this.supabase.storage.from(this.bucketName).upload(l,a,{contentType:n||"application/octet-stream",upsert:!0,...d&&{metadata:d}});if(p)return{error:`Failed to upload to Supabase Storage: ${p.message}`,status:500};const{data:{publicUrl:m}}=this.supabase.storage.from(this.bucketName).getPublicUrl(l);return{data:{url:m,key:g.path,size:a.length,metadata:d},status:200}}catch(r){return console.error("UPLOAD_TO_STORAGE error:",r),{error:r instanceof Error?r.message:"Unknown error",status:500}}}}const K=u=>({GET_CHAI_USER:new N(u),CHANGE_PASSWORD:new V(u)}),Q=u=>({UPLOAD_ASSET:new P(u),GET_ASSET:new B(u),GET_ASSETS:new $(u),DELETE_ASSET:new G(u),UPDATE_ASSET:new j(u),UPLOAD_TO_STORAGE:new z(u),DELETE_FROM_STORAGE:new x(u)});exports.DeleteFromStorageAction=x;exports.SupabaseAuthActions=K;exports.SupabaseStorageActions=Q;exports.UploadToStorageAction=z;
@@ -74,6 +74,39 @@ declare interface ChaiUser {
74
74
  avatar: string;
75
75
  }
76
76
 
77
+ /**
78
+ * CHANGE_PASSWORD Action
79
+ * Changes user password using Supabase Auth
80
+ */
81
+ declare class ChangePasswordAction extends ChaiBaseAction<ChangePasswordInput> {
82
+ private supabase;
83
+ constructor(supabase: SupabaseClient);
84
+ protected getValidationSchema(): z.ZodObject<{
85
+ email: z.ZodString;
86
+ oldPassword: z.ZodString;
87
+ newPassword: z.ZodString;
88
+ confirmPassword: z.ZodString;
89
+ }, z.core.$strip>;
90
+ execute(data: ChangePasswordInput): Promise<{
91
+ data: {
92
+ message: string;
93
+ };
94
+ status: number;
95
+ } | {
96
+ error: string;
97
+ status: number;
98
+ }>;
99
+ }
100
+
101
+ declare type ChangePasswordInput = z.infer<typeof ChangePasswordSchema>;
102
+
103
+ declare const ChangePasswordSchema: z.ZodObject<{
104
+ email: z.ZodString;
105
+ oldPassword: z.ZodString;
106
+ newPassword: z.ZodString;
107
+ confirmPassword: z.ZodString;
108
+ }, z.core.$strip>;
109
+
77
110
  declare class DeleteAssetAction extends ChaiBaseAction<DeleteAssetInput> {
78
111
  private supabase;
79
112
  constructor(supabase: SupabaseClient);
@@ -193,6 +226,7 @@ declare const GetChaiUserSchema: z.ZodObject<{
193
226
 
194
227
  export declare const SupabaseAuthActions: (supabase: SupabaseClient) => {
195
228
  GET_CHAI_USER: GetChaiUserAction;
229
+ CHANGE_PASSWORD: ChangePasswordAction;
196
230
  };
197
231
 
198
232
  export declare const SupabaseStorageActions: (supabase: SupabaseClient) => {