@chaibuilder/pages 0.15.24 → 0.16.1

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 (84) hide show
  1. package/dist/{2AITGKQY-wLnL_T-W.cjs → 2AITGKQY-CD9A6oc6.cjs} +1 -1
  2. package/dist/{2AITGKQY-B6ojx8vV.js → 2AITGKQY-Z1XcJ6Q7.js} +2 -2
  3. package/dist/{NCMVHL6D-DGH2CRR6.cjs → NCMVHL6D-CkpM-3og.cjs} +1 -1
  4. package/dist/{NCMVHL6D-vsNnIwmV.js → NCMVHL6D-DoK0XoIo.js} +4 -4
  5. package/dist/{ZDWCUMSJ-3BnFdOH2.cjs → ZDWCUMSJ-D32swpGV.cjs} +1 -1
  6. package/dist/{ZDWCUMSJ-CoYx1TP5.js → ZDWCUMSJ-hGXNxbOK.js} +1 -1
  7. package/dist/{add-new-language-page-d0-cAxlt.js → add-new-language-page-BZPoqdX-.js} +2 -2
  8. package/dist/{add-new-language-page-VDZSKD95.cjs → add-new-language-page-D65TpIwK.cjs} +1 -1
  9. package/dist/{add-new-page-D4IkZL8h.cjs → add-new-page-CQ0aj4RJ.cjs} +1 -1
  10. package/dist/{add-new-page-Bcoxw6U5.js → add-new-page-DK25Y0zS.js} +1 -1
  11. package/dist/ai-panel-content-BSGJqnTM.cjs +1 -0
  12. package/dist/ai-panel-content-DYRZnMgV.js +52 -0
  13. package/dist/ai-panel-default-lang-BOZrL5Xe.cjs +1 -0
  14. package/dist/ai-panel-default-lang-DZUqC79y.js +173 -0
  15. package/dist/ai-panel-message-bubble-Bl-aUeU4.cjs +1 -0
  16. package/dist/ai-panel-message-bubble-DPAaAMAZ.js +38 -0
  17. package/dist/ai-panel-other-lang-CCyiE6ha.js +145 -0
  18. package/dist/ai-panel-other-lang-CNtlT5dM.cjs +1 -0
  19. package/dist/ai-panel-quick-prompts-DeS7L1f0.cjs +1 -0
  20. package/dist/ai-panel-quick-prompts-Ds0Ndz7g.js +46 -0
  21. package/dist/ai-prompt-input-Ch_PLEPN.js +133 -0
  22. package/dist/ai-prompt-input-Zg6lN1Lo.cjs +1 -0
  23. package/dist/ai-translation-prompt-BUFjo_om.cjs +1 -0
  24. package/dist/ai-translation-prompt-BiJ5B_an.js +28 -0
  25. package/dist/{delete-page-KS6p6b8f.js → delete-page-B95T2Prd.js} +1 -1
  26. package/dist/{delete-page-DeKAD4Ld.cjs → delete-page-BSop1jNg.cjs} +1 -1
  27. package/dist/{digital-asset-manager-Dfe9SS09.js → digital-asset-manager-BQNSwfKs.js} +1 -1
  28. package/dist/{digital-asset-manager-C9gYL2SF.cjs → digital-asset-manager-Bn58WzM6.cjs} +1 -1
  29. package/dist/{duplicate-page-CKr-HNs-.cjs → duplicate-page-BLxkSiug.cjs} +1 -1
  30. package/dist/{duplicate-page-vCgYnw4H.js → duplicate-page-CrzzObAj.js} +9 -9
  31. package/dist/{dynamic-page-selector-A4fqWqZZ.js → dynamic-page-selector-D6wQnNfH.js} +1 -1
  32. package/dist/{dynamic-page-selector-C7w3TOdK.cjs → dynamic-page-selector-D8UZ63LW.cjs} +1 -1
  33. package/dist/index-W0r4o5Ro.cjs +5 -0
  34. package/dist/{index-NSqs69Op.js → index-yhKyIbgs.js} +1035 -1031
  35. package/dist/index.cjs +1 -1
  36. package/dist/index.d.ts +5 -3
  37. package/dist/index.js +7 -7
  38. package/dist/{json-diff-viewer-7TGemUrn.js → json-diff-viewer-ISJS7lHK.js} +1 -1
  39. package/dist/{json-diff-viewer-nLLX6kJK.cjs → json-diff-viewer-ZeJ3Rp2y.cjs} +1 -1
  40. package/dist/{lang-panel-C6KxjKn_.js → lang-panel-Bj11IL7k.js} +33 -33
  41. package/dist/{lang-panel-dc9uBMtE.cjs → lang-panel-DqN_J3vz.cjs} +1 -1
  42. package/dist/{mark-as-template-CJ9SiEBl.cjs → mark-as-template-CcwAAdrd.cjs} +1 -1
  43. package/dist/{mark-as-template-CRUOQ_FZ.js → mark-as-template-CmCCMaQg.js} +1 -1
  44. package/dist/{no-language-page-content--8a37nsW.cjs → no-language-page-content-BXm1k1Aa.cjs} +1 -1
  45. package/dist/{no-language-page-content-ByHFQjkV.js → no-language-page-content-Cme-zo4R.js} +1 -1
  46. package/dist/{page-creator-CzUQicdh.cjs → page-creator-ByhjXyHP.cjs} +1 -1
  47. package/dist/{page-creator-J_CNgdj5.js → page-creator-Zbv4d4H8.js} +2 -2
  48. package/dist/{page-lock-request-BE9-Oego.cjs → page-lock-request-Cln-EE6Z.cjs} +1 -1
  49. package/dist/{page-lock-request-CD93n5pq.js → page-lock-request-DDQJb8IA.js} +10 -10
  50. package/dist/{page-locked-by-dialog-1Lm9dcT6.cjs → page-locked-by-dialog-BIXYITEu.cjs} +1 -1
  51. package/dist/{page-locked-by-dialog-noDLCQWF.js → page-locked-by-dialog-Csn56a3n.js} +1 -1
  52. package/dist/{page-manager-new-BoTBCqZF.cjs → page-manager-new-BJaTBpih.cjs} +1 -1
  53. package/dist/{page-manager-new-D-U4B9y9.js → page-manager-new-BrRxZDfT.js} +67 -67
  54. package/dist/{page-manager-search-and-filter-BJmETYq-.cjs → page-manager-search-and-filter-Bk3PUjha.cjs} +1 -1
  55. package/dist/{page-manager-search-and-filter-h-YzJVcH.js → page-manager-search-and-filter-_Hvk3bU3.js} +1 -1
  56. package/dist/{page-revisions-content-C7DXjFls.js → page-revisions-content-B6fRCBX_.js} +10 -10
  57. package/dist/{page-revisions-content-BNBb2qYh.cjs → page-revisions-content-C_Ha3tFu.cjs} +1 -1
  58. package/dist/prompt-helper-Csgu8Rfb.js +187 -0
  59. package/dist/prompt-helper-DgI1lgGV.cjs +51 -0
  60. package/dist/{publish-pages-content-DAKh_sSW.js → publish-pages-content-CFEIxKQD.js} +2 -2
  61. package/dist/{publish-pages-content-DsOVOiBD.cjs → publish-pages-content-DQDNxwHD.cjs} +1 -1
  62. package/dist/{save-to-lib-BR1Qhw3Q.cjs → save-to-lib-Bl22umTa.cjs} +1 -1
  63. package/dist/{save-to-lib-BPR_--qN.js → save-to-lib-YyYkF6c6.js} +1 -1
  64. package/dist/{seo-panel-C7XC-XRg.js → seo-panel-BZlMea1L.js} +1 -1
  65. package/dist/{seo-panel-CUqtdGoF.cjs → seo-panel-BhxikAkG.cjs} +1 -1
  66. package/dist/server.cjs +241 -1
  67. package/dist/server.d.ts +50 -6
  68. package/dist/server.js +10327 -290
  69. package/dist/{shared-json-ld-CDffP4G3.cjs → shared-json-ld-BfkH76U3.cjs} +1 -1
  70. package/dist/{shared-json-ld-0JD8sokD.js → shared-json-ld-E4Ckwlbr.js} +41 -41
  71. package/dist/{slug-input-BYH90lv1.cjs → slug-input--VmQG0S1.cjs} +1 -1
  72. package/dist/{slug-input-CvIDihGn.js → slug-input-CKKkqGj4.js} +1 -1
  73. package/dist/{theme-panel-footer-DPpLzCDu.js → theme-panel-footer-2ERfMsET.js} +1 -1
  74. package/dist/{theme-panel-footer-CUSfduTK.cjs → theme-panel-footer-CagxEZEO.cjs} +1 -1
  75. package/dist/{unmark-as-template-CjqRfFDL.js → unmark-as-template-BJ5CTNAe.js} +1 -1
  76. package/dist/{unmark-as-template-Bxw4t_Xi.cjs → unmark-as-template-CeWpo9wD.cjs} +1 -1
  77. package/dist/{unpublish-page-BjiB3d7l.cjs → unpublish-page-DmZSVxFj.cjs} +1 -1
  78. package/dist/{unpublish-page-CKKU1St1.js → unpublish-page-DvOWVBIf.js} +1 -1
  79. package/dist/{web-preview-D0OpieXz.js → web-preview-DTkIggV7.js} +1 -1
  80. package/dist/{web-preview-CNMYCWxW.cjs → web-preview-DlSKpPUZ.cjs} +1 -1
  81. package/package.json +3 -3
  82. package/dist/ai-panel-content-Cn3SA_Sr.cjs +0 -46
  83. package/dist/ai-panel-content-qmOJKjkE.js +0 -524
  84. package/dist/index-LfuCMBwI.cjs +0 -5
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),I=require("@tanstack/react-query"),c=require("./index-LfuCMBwI.cjs"),s=require("@chaibuilder/sdk/ui"),G=require("lodash-es"),f=require("lucide-react"),x=require("react"),E=require("sonner"),q=()=>{const t=c.useApiUrl(),d=c.useFetch();return I.useQuery({queryKey:[c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>d(t,{action:c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},U=({show:t,onClose:d,initialData:n})=>e.jsx(s.Dialog,{open:t,onOpenChange:()=>d(),children:t&&e.jsx(_,{show:t,onClose:d,initialData:n})}),_=({show:t,onClose:d,initialData:n})=>{const[r,p]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[N,C]=x.useState(!1),{data:g}=c.useCurrentPage(),{mutateAsync:A,isPending:j}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),v=I.useQueryClient();x.useEffect(()=>{p(n?{name:n.name,description:n.description,content:JSON.stringify(n.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),C(!1)},[t,n]);const i=async()=>{if(!r.name||!r.content){E.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){E.toast.error("Invalid JSON-LD content");return}const b={name:r.name,jsonld:l.parsed,addToExistingPages:N,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(b.primaryPage=n.primaryPageId);const w=await A(b);g!=null&&g.id&&(w!=null&&w.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:w.id,pageId:g.id,enabled:!0}),v.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,g.id]})),d()};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Add New Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[(n==null?void 0:n.languageCode)&&e.jsxs(s.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(f.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(s.AlertDescription,{className:"text-sm text-blue-800",children:["You are creating a ",e.jsx("span",{className:"font-semibold",children:n.languageCode})," language version of this schema. This will be linked to the default language schema."]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-name",children:"Schema Name"}),e.jsx(s.Input,{id:"new-name",value:r.name,onChange:l=>p({...r,name:l.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-description",children:"Description"}),e.jsx(s.Input,{id:"new-description",value:r.description||"",onChange:l=>p({...r,description:l.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"new-content",value:r.content||"{}",onChange:l=>p({...r,content:l}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!(n!=null&&n.primaryPageId)&&e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"add-to-all-existing",checked:N,onChange:l=>C(l.target.checked),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"add-to-all-existing",children:[e.jsx("div",{children:"Add to all existing pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"This schema will be added to all existing pages on your site"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"new-enabled",checked:r.enabledByDefaultForNewPages,onChange:l=>p({...r,enabledByDefaultForNewPages:l.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"new-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(s.Button,{disabled:j,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:j,type:"button",size:"sm",onClick:i,children:j?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Adding"]}):e.jsxs(e.Fragment,{children:["Add Schema",(n==null?void 0:n.languageCode)&&` (${n.languageCode})`]})})]})})]})]})},H=({id:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:()=>d(),children:t&&e.jsx(Q,{id:t,onClose:d})}),Q=({id:t,onClose:d})=>{const[n,r]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[p,N]=x.useState(!1),[C,g]=x.useState(!1),[A,j]=x.useState(!1),{data:u}=q(),{mutateAsync:v,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:b}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var m,D;if(t&&u){const y=u.find(P=>P.id===t);y&&(r({name:y.name,description:((m=y.metadata)==null?void 0:m.description)||"",content:JSON.stringify(y.jsonld,null,2),enabledByDefaultForNewPages:((D=y.metadata)==null?void 0:D.addToNewPages)||!1}),j(!!y.primaryPage))}},[t,u]);const w=async()=>{if(!n.name||!n.content){E.toast.error("Please enter a name and content");return}const m=c.parseJSONWithPlaceholders(n.content);if(!m.isValid){E.toast.error("Invalid JSON-LD content");return}const D={id:t,name:n.name,jsonld:m.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await v(D),d()},F=async()=>{try{await l(t)}finally{N(!1)}},T=async()=>{try{await b(t)}finally{g(!1)}};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Edit Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[!A&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-blue-900",children:"Manage Existing Pages"}),e.jsx("div",{className:"text-xs text-blue-700",children:"Add or remove this schema from all existing pages on your site"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>N(!0),children:"Add to all existing"}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>g(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(s.Input,{id:"edit-name",value:n.name,onChange:m=>r({...n,name:m.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-description",children:"Description"}),e.jsx(s.Input,{id:"edit-description",value:n.description||"",onChange:m=>r({...n,description:m.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"edit-content",value:n.content||"{}",onChange:m=>r({...n,content:m}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!A&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onChange:m=>r({...n,enabledByDefaultForNewPages:m.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"edit-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(s.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:i,type:"button",size:"sm",onClick:w,children:i?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:p,onOpenChange:N,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Add to All Existing Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will add the schema ",e.jsx("span",{className:"font-medium",children:n.name})," to all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:F,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:C,onOpenChange:g,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Remove from All Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will remove the schema ",e.jsx("span",{className:"font-medium",children:n.name})," from all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:T,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function V(){const[t,d]=x.useState(!1),[n,r]=x.useState(void 0),[p,N]=x.useState(null),[C,g]=x.useState(null),[A,j]=x.useState(null),{data:u,isLoading:v}=q(),{selectedLang:i}=M.useLanguages(),{data:l}=c.useCurrentPage(),{data:b}=c.useLanguagePages(),{mutateAsync:w}=c.useDeleteGlobalSchema(),{mutateAsync:F}=c.useTogglePageGlobalSchema(),T=x.useMemo(()=>b==null?void 0:b.find(a=>!a.primaryPage&&a.lang===""),[b]),m=x.useMemo(()=>(T==null?void 0:T.globalJsonLds)||[],[T]),D=x.useMemo(()=>u?G.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const h=i?G.find(u,S=>S.primaryPage===o.id&&S.lang===i):null;return{defaultSchema:o,languageVersion:h,displayItem:h||o,hasLanguageVersion:!!h}}):[],[u,i]),[y,P]=x.useState([]),L=y.length>0?y:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&P(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const z=async a=>{if(!(l!=null&&l.id))return;j(a);const o=L.includes(a),h=o?L.filter(S=>S!==a):[...L,a];P(h);try{await F({schemaId:a,pageId:l.id,enabled:!o})}catch{P(l.globalJsonLds)}finally{j(null)}},R=async a=>{j(a);try{await w(a)}finally{j(null)}};return e.jsxs("div",{className:"rounded border bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center justify-between pb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium",children:"Shared JSON-LD Templates"}),e.jsx("div",{className:"w-full text-xs text-gray-500",children:"Manage reusable JSON-LD schemas that can be applied across multiple pages"})]}),!i&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{type:"button",disabled:v,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:v?e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(f.Plus,{className:"h-4 w-4"})}),e.jsx(s.TooltipContent,{children:"Add new schema"})]})]}),e.jsxs(s.ScrollArea,{className:"max-h-96 overflow-y-auto",children:[e.jsxs("div",{className:"space-y-2",children:[(!u||(u==null?void 0:u.length)===0)&&!v&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),D.map(({defaultSchema:a,displayItem:o,hasLanguageVersion:h})=>{var k,B;const S=L.includes(o.id),O=m.includes(a.id),J=h&&i?O:S;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${A===o.id?"pointer-events-none":""}`,children:[A===o.id&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 flex items-center justify-center rounded-xl bg-white/80",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin text-primary"})}),e.jsx(s.CardHeader,{className:"p-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[(h||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:J,onChange:()=>z(a.id),disabled:!!(h&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),h&&i&&e.jsx(s.TooltipContent,{children:"Using the default language state"})]}),e.jsxs("div",{children:[e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-sm leading-none",children:[o.name,h&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),J&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((k=o==null?void 0:o.metadata)==null?void 0:k.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(B=o==null?void 0:o.metadata)==null?void 0:B.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"mx-2 h-6 w-px bg-border"}),e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>g(o.id),children:e.jsx(f.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(h||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>N(o.id),children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Edit schema"})]}),e.jsxs(s.AlertDialog,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.AlertDialogTrigger,{className:"flex h-5 w-5 items-center justify-center rounded-md text-red-500 hover:bg-red-100 hover:text-red-800",children:e.jsx(f.Trash,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Delete schema"})]}),e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Schema"}),e.jsxs(s.AlertDialogDescription,{children:["Are you sure you want to delete"," ",e.jsx("span",{className:"font-medium",children:o.name}),"? This action cannot be undone."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{type:"button",children:"Cancel"}),e.jsx(s.AlertDialogAction,{type:"button",onClick:()=>R(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!h&&i&&e.jsx(s.CardContent,{className:"px-2 pb-2",children:e.jsxs("div",{className:"flex w-full flex-col items-center justify-center rounded-lg border bg-gray-100 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"max-w-xl text-center text-xs text-gray-500",children:["Not available in '",i,"' language. Default language JSONLD will be used."]}),O&&e.jsx("span",{className:"rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700",children:"Enabled in default"})]}),e.jsx(s.Button,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>{r({name:a.name,description:a.description||"",jsonld:a.jsonld,languageCode:i,primaryPageId:a.id}),d(!0)},children:"Copy & Edit from default language"})]})})]},a.id)})]}),v&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(U,{show:t,onClose:()=>{d(!1),r(void 0)},initialData:n}),e.jsx(H,{id:p,onClose:()=>N(null)}),e.jsx(K,{schema:u==null?void 0:u.find(a=>a.id===C),onClose:()=>g(null)})]})}const K=({schema:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[t==null?void 0:t.name,(t==null?void 0:t.lang)&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",t.lang,")"]})]})}),e.jsxs("div",{className:"space-y-3",children:[(t==null?void 0:t.description)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Description"}),e.jsx("div",{className:"text-sm",children:t.description})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"JSON-LD Schema"}),e.jsx(s.Textarea,{value:JSON.stringify(t==null?void 0:t.jsonld,null,2),readOnly:!0,className:"font-mono text-xs",rows:15})]})]})]})});exports.default=V;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),I=require("@tanstack/react-query"),c=require("./index-W0r4o5Ro.cjs"),s=require("@chaibuilder/sdk/ui"),G=require("lodash-es"),f=require("lucide-react"),x=require("react"),E=require("sonner"),q=()=>{const t=c.useApiUrl(),d=c.useFetch();return I.useQuery({queryKey:[c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>d(t,{action:c.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},U=({show:t,onClose:d,initialData:n})=>e.jsx(s.Dialog,{open:t,onOpenChange:()=>d(),children:t&&e.jsx(_,{show:t,onClose:d,initialData:n})}),_=({show:t,onClose:d,initialData:n})=>{const[r,p]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[N,C]=x.useState(!1),{data:g}=c.useCurrentPage(),{mutateAsync:A,isPending:j}=c.useAddGlobalSchema(),{mutateAsync:u}=c.useTogglePageGlobalSchema(),v=I.useQueryClient();x.useEffect(()=>{p(n?{name:n.name,description:n.description,content:JSON.stringify(n.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),C(!1)},[t,n]);const i=async()=>{if(!r.name||!r.content){E.toast.error("Please enter a name and content");return}const l=c.parseJSONWithPlaceholders(r.content);if(!l.isValid){E.toast.error("Invalid JSON-LD content");return}const b={name:r.name,jsonld:l.parsed,addToExistingPages:N,addToNewPages:r.enabledByDefaultForNewPages,description:r.description};n!=null&&n.primaryPageId&&(b.primaryPage=n.primaryPageId);const w=await A(b);g!=null&&g.id&&(w!=null&&w.id)&&!(n!=null&&n.primaryPageId)&&(await u({schemaId:w.id,pageId:g.id,enabled:!0}),v.invalidateQueries({queryKey:[c.ACTIONS.GET_LANGUAGE_PAGES,g.id]})),d()};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Add New Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[(n==null?void 0:n.languageCode)&&e.jsxs(s.Alert,{className:"border-blue-200 bg-blue-50",children:[e.jsx(f.Info,{className:"h-4 w-4 text-blue-600"}),e.jsxs(s.AlertDescription,{className:"text-sm text-blue-800",children:["You are creating a ",e.jsx("span",{className:"font-semibold",children:n.languageCode})," language version of this schema. This will be linked to the default language schema."]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-name",children:"Schema Name"}),e.jsx(s.Input,{id:"new-name",value:r.name,onChange:l=>p({...r,name:l.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-description",children:"Description"}),e.jsx(s.Input,{id:"new-description",value:r.description||"",onChange:l=>p({...r,description:l.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"new-content",value:r.content||"{}",onChange:l=>p({...r,content:l}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!(n!=null&&n.primaryPageId)&&e.jsxs("div",{className:"flex flex-col gap-3 pt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"add-to-all-existing",checked:N,onChange:l=>C(l.target.checked),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"add-to-all-existing",children:[e.jsx("div",{children:"Add to all existing pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"This schema will be added to all existing pages on your site"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"new-enabled",checked:r.enabledByDefaultForNewPages,onChange:l=>p({...r,enabledByDefaultForNewPages:l.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"new-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(s.Button,{disabled:j,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:j,type:"button",size:"sm",onClick:i,children:j?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Adding"]}):e.jsxs(e.Fragment,{children:["Add Schema",(n==null?void 0:n.languageCode)&&` (${n.languageCode})`]})})]})})]})]})},H=({id:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:()=>d(),children:t&&e.jsx(Q,{id:t,onClose:d})}),Q=({id:t,onClose:d})=>{const[n,r]=x.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[p,N]=x.useState(!1),[C,g]=x.useState(!1),[A,j]=x.useState(!1),{data:u}=q(),{mutateAsync:v,isPending:i}=c.useUpdateGlobalSchema(),{mutateAsync:l}=c.useApplySchemaToAllPages(),{mutateAsync:b}=c.useRemoveSchemaFromAllPages();x.useEffect(()=>{var m,D;if(t&&u){const y=u.find(P=>P.id===t);y&&(r({name:y.name,description:((m=y.metadata)==null?void 0:m.description)||"",content:JSON.stringify(y.jsonld,null,2),enabledByDefaultForNewPages:((D=y.metadata)==null?void 0:D.addToNewPages)||!1}),j(!!y.primaryPage))}},[t,u]);const w=async()=>{if(!n.name||!n.content){E.toast.error("Please enter a name and content");return}const m=c.parseJSONWithPlaceholders(n.content);if(!m.isValid){E.toast.error("Invalid JSON-LD content");return}const D={id:t,name:n.name,jsonld:m.parsed,addToNewPages:n.enabledByDefaultForNewPages,description:n.description};await v(D),d()},F=async()=>{try{await l(t)}finally{N(!1)}},T=async()=>{try{await b(t)}finally{g(!1)}};return e.jsxs(s.DialogContent,{className:"flex max-w-xl flex-col overflow-y-auto",children:[e.jsx(s.DialogHeader,{children:e.jsx(s.DialogTitle,{children:"Edit Shared JSON-LD Schema"})}),e.jsxs("div",{className:"flex max-h-[75vh] flex-col space-y-2 overflow-y-auto",children:[!A&&e.jsxs("div",{className:"flex items-center justify-between rounded-lg border border-blue-300 bg-blue-500/10 p-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-blue-900",children:"Manage Existing Pages"}),e.jsx("div",{className:"text-xs text-blue-700",children:"Add or remove this schema from all existing pages on your site"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(s.Button,{size:"sm",className:"text-xs",variant:"outline",onClick:()=>N(!0),children:"Add to all existing"}),e.jsx(s.Button,{size:"sm",variant:"ghost",className:"text-xs",onClick:()=>g(!0),children:"Remove from all"})]})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(s.Input,{id:"edit-name",value:n.name,onChange:m=>r({...n,name:m.target.value}),placeholder:"e.g., Product Schema",className:"text-xs"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-description",children:"Description"}),e.jsx(s.Input,{id:"edit-description",value:n.description||"",onChange:m=>r({...n,description:m.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-content",children:"JSON-LD Content"}),e.jsx(c.SmartJsonInput,{id:"edit-content",value:n.content||"{}",onChange:m=>r({...n,content:m}),placeholder:"Enter JSON-LD markup...",rows:10})]}),!A&&e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx("input",{type:"checkbox",id:"edit-enabled",checked:n.enabledByDefaultForNewPages,onChange:m=>r({...n,enabledByDefaultForNewPages:m.target.checked}),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"}),e.jsxs(s.Label,{htmlFor:"edit-enabled",children:[e.jsx("div",{children:"Enabled by default for new pages"}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:"New pages will automatically include this schema"})]})]}),e.jsx("div",{className:"border-t pt-3",children:e.jsxs("div",{className:"flex items-center justify-end gap-2",children:[e.jsx(s.Button,{disabled:i,variant:"outline",type:"button",size:"sm",onClick:()=>d(),children:"Cancel"}),e.jsx(s.Button,{disabled:i,type:"button",size:"sm",onClick:w,children:i?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})})]}),e.jsx(s.AlertDialog,{open:p,onOpenChange:N,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Add to All Existing Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will add the schema ",e.jsx("span",{className:"font-medium",children:n.name})," to all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:F,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:C,onOpenChange:g,children:e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Remove from All Pages?"}),e.jsxs(s.AlertDialogDescription,{children:["This will remove the schema ",e.jsx("span",{className:"font-medium",children:n.name})," from all existing pages on your site. This action cannot be undone automatically."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{children:"Cancel"}),e.jsx(s.AlertDialogAction,{onClick:T,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function V(){const[t,d]=x.useState(!1),[n,r]=x.useState(void 0),[p,N]=x.useState(null),[C,g]=x.useState(null),[A,j]=x.useState(null),{data:u,isLoading:v}=q(),{selectedLang:i}=M.useLanguages(),{data:l}=c.useCurrentPage(),{data:b}=c.useLanguagePages(),{mutateAsync:w}=c.useDeleteGlobalSchema(),{mutateAsync:F}=c.useTogglePageGlobalSchema(),T=x.useMemo(()=>b==null?void 0:b.find(a=>!a.primaryPage&&a.lang===""),[b]),m=x.useMemo(()=>(T==null?void 0:T.globalJsonLds)||[],[T]),D=x.useMemo(()=>u?G.filter(u,o=>o.primaryPage===null&&o.lang==="").map(o=>{const h=i?G.find(u,S=>S.primaryPage===o.id&&S.lang===i):null;return{defaultSchema:o,languageVersion:h,displayItem:h||o,hasLanguageVersion:!!h}}):[],[u,i]),[y,P]=x.useState([]),L=y.length>0?y:(l==null?void 0:l.globalJsonLds)||[];x.useEffect(()=>{l!=null&&l.globalJsonLds&&P(l.globalJsonLds)},[l==null?void 0:l.globalJsonLds]);const z=async a=>{if(!(l!=null&&l.id))return;j(a);const o=L.includes(a),h=o?L.filter(S=>S!==a):[...L,a];P(h);try{await F({schemaId:a,pageId:l.id,enabled:!o})}catch{P(l.globalJsonLds)}finally{j(null)}},R=async a=>{j(a);try{await w(a)}finally{j(null)}};return e.jsxs("div",{className:"rounded border bg-muted p-2",children:[e.jsxs("div",{className:"flex items-center justify-between pb-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium",children:"Shared JSON-LD Templates"}),e.jsx("div",{className:"w-full text-xs text-gray-500",children:"Manage reusable JSON-LD schemas that can be applied across multiple pages"})]}),!i&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{type:"button",disabled:v,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),d(!0)},children:v?e.jsx(f.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(f.Plus,{className:"h-4 w-4"})}),e.jsx(s.TooltipContent,{children:"Add new schema"})]})]}),e.jsxs(s.ScrollArea,{className:"max-h-96 overflow-y-auto",children:[e.jsxs("div",{className:"space-y-2",children:[(!u||(u==null?void 0:u.length)===0)&&!v&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),D.map(({defaultSchema:a,displayItem:o,hasLanguageVersion:h})=>{var k,B;const S=L.includes(o.id),O=m.includes(a.id),J=h&&i?O:S;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${A===o.id?"pointer-events-none":""}`,children:[A===o.id&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 top-0 z-50 flex items-center justify-center rounded-xl bg-white/80",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin text-primary"})}),e.jsx(s.CardHeader,{className:"p-2",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[(h||!i)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("input",{type:"checkbox",checked:J,onChange:()=>z(a.id),disabled:!!(h&&i),className:"h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"})}),h&&i&&e.jsx(s.TooltipContent,{children:"Using the default language state"})]}),e.jsxs("div",{children:[e.jsxs(s.CardTitle,{className:"flex items-center gap-2 text-sm leading-none",children:[o.name,h&&i&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",i,")"]}),J&&e.jsx("span",{className:"sr-only text-xs font-normal text-muted-foreground",children:"Enabled"})]}),((k=o==null?void 0:o.metadata)==null?void 0:k.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(B=o==null?void 0:o.metadata)==null?void 0:B.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"mx-2 h-6 w-px bg-border"}),e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>g(o.id),children:e.jsx(f.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(h||!i)&&e.jsxs(e.Fragment,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.Button,{type:"button",variant:"ghost",size:"icon",className:"h-5 w-5 p-0",onClick:()=>N(o.id),children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Edit schema"})]}),e.jsxs(s.AlertDialog,{children:[e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx(s.AlertDialogTrigger,{className:"flex h-5 w-5 items-center justify-center rounded-md text-red-500 hover:bg-red-100 hover:text-red-800",children:e.jsx(f.Trash,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"Delete schema"})]}),e.jsxs(s.AlertDialogContent,{children:[e.jsxs(s.AlertDialogHeader,{children:[e.jsx(s.AlertDialogTitle,{children:"Delete Schema"}),e.jsxs(s.AlertDialogDescription,{children:["Are you sure you want to delete"," ",e.jsx("span",{className:"font-medium",children:o.name}),"? This action cannot be undone."]})]}),e.jsxs(s.AlertDialogFooter,{children:[e.jsx(s.AlertDialogCancel,{type:"button",children:"Cancel"}),e.jsx(s.AlertDialogAction,{type:"button",onClick:()=>R(o.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!h&&i&&e.jsx(s.CardContent,{className:"px-2 pb-2",children:e.jsxs("div",{className:"flex w-full flex-col items-center justify-center rounded-lg border bg-gray-100 py-3",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("div",{className:"max-w-xl text-center text-xs text-gray-500",children:["Not available in '",i,"' language. Default language JSONLD will be used."]}),O&&e.jsx("span",{className:"rounded-full bg-green-100 px-2 py-0.5 text-xs font-medium text-green-700",children:"Enabled in default"})]}),e.jsx(s.Button,{type:"button",size:"sm",variant:"outline",className:"mt-2",onClick:()=>{r({name:a.name,description:a.description||"",jsonld:a.jsonld,languageCode:i,primaryPageId:a.id}),d(!0)},children:"Copy & Edit from default language"})]})})]},a.id)})]}),v&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(f.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(U,{show:t,onClose:()=>{d(!1),r(void 0)},initialData:n}),e.jsx(H,{id:p,onClose:()=>N(null)}),e.jsx(K,{schema:u==null?void 0:u.find(a=>a.id===C),onClose:()=>g(null)})]})}const K=({schema:t,onClose:d})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:d,children:e.jsxs(s.DialogContent,{className:"max-w-2xl",children:[e.jsx(s.DialogHeader,{children:e.jsxs(s.DialogTitle,{className:"flex items-center gap-2",children:[t==null?void 0:t.name,(t==null?void 0:t.lang)&&e.jsxs("span",{className:"text-sm font-normal text-muted-foreground",children:["(",t.lang,")"]})]})}),e.jsxs("div",{className:"space-y-3",children:[(t==null?void 0:t.description)&&e.jsxs("div",{children:[e.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Description"}),e.jsx("div",{className:"text-sm",children:t.description})]}),e.jsxs("div",{children:[e.jsx("div",{className:"mb-2 text-xs font-medium text-muted-foreground",children:"JSON-LD Schema"}),e.jsx(s.Textarea,{value:JSON.stringify(t==null?void 0:t.jsonld,null,2),readOnly:!0,className:"font-mono text-xs",rows:15})]})]})]})});exports.default=V;
@@ -1,24 +1,24 @@
1
1
  import { jsx as e, jsxs as n, Fragment as j } from "react/jsx-runtime";
2
2
  import { useLanguages as me } from "@chaibuilder/sdk";
3
3
  import { useQuery as he, useQueryClient as ue } from "@tanstack/react-query";
4
- import { ak as ge, al as fe, A as U, ap as te, au as pe, av as se, aw as re, ax as de, ay as xe, az as Ne, aA as be, g as ye, aB as ve } from "./index-NSqs69Op.js";
4
+ import { am as ge, an as fe, A as U, ar as le, aw as pe, ax as se, ay as re, az as de, aA as xe, aB as Ne, aC as be, g as ye, aD as ve } from "./index-yhKyIbgs.js";
5
5
  import { Dialog as $, DialogContent as W, DialogHeader as Y, DialogTitle as X, Alert as we, AlertDescription as Ae, Label as y, Input as G, Button as v, AlertDialog as _, AlertDialogContent as R, AlertDialogHeader as M, AlertDialogTitle as q, AlertDialogDescription as H, AlertDialogFooter as Q, AlertDialogCancel as V, AlertDialogAction as K, Tooltip as E, TooltipTrigger as J, TooltipContent as O, ScrollArea as Ce, Card as Se, CardHeader as Pe, CardTitle as Te, AlertDialogTrigger as De, CardContent as Le, Textarea as Ee } from "@chaibuilder/sdk/ui";
6
6
  import { filter as Je, find as Oe } from "lodash-es";
7
7
  import { Info as Fe, Loader as F, Plus as ke, Eye as je, Edit as Ge, Trash as Be } from "lucide-react";
8
8
  import { useState as g, useEffect as Z, useMemo as z } from "react";
9
9
  import { toast as B } from "sonner";
10
10
  const oe = () => {
11
- const l = ge(), i = fe();
11
+ const t = ge(), i = fe();
12
12
  return he({
13
13
  queryKey: [U.GET_GLOBAL_JSONLD_ITEMS],
14
- queryFn: async () => i(l, { action: U.GET_GLOBAL_JSONLD_ITEMS })
14
+ queryFn: async () => i(t, { action: U.GET_GLOBAL_JSONLD_ITEMS })
15
15
  });
16
16
  }, Ie = ({
17
- show: l,
17
+ show: t,
18
18
  onClose: i,
19
19
  initialData: a
20
- }) => /* @__PURE__ */ e($, { open: l, onOpenChange: () => i(), children: l && /* @__PURE__ */ e(ze, { show: l, onClose: i, initialData: a }) }), ze = ({
21
- show: l,
20
+ }) => /* @__PURE__ */ e($, { open: t, onOpenChange: () => i(), children: t && /* @__PURE__ */ e(ze, { show: t, onClose: i, initialData: a }) }), ze = ({
21
+ show: t,
22
22
  onClose: i,
23
23
  initialData: a
24
24
  }) => {
@@ -27,7 +27,7 @@ const oe = () => {
27
27
  content: "",
28
28
  description: "",
29
29
  enabledByDefaultForNewPages: !1
30
- }), [x, P] = g(!1), { data: u } = te(), { mutateAsync: C, isPending: p } = pe(), { mutateAsync: c } = se(), w = ue();
30
+ }), [x, P] = g(!1), { data: u } = le(), { mutateAsync: C, isPending: p } = pe(), { mutateAsync: c } = se(), w = ue();
31
31
  Z(() => {
32
32
  f(a ? {
33
33
  name: a.name,
@@ -35,20 +35,20 @@ const oe = () => {
35
35
  content: JSON.stringify(a.jsonld, null, 2),
36
36
  enabledByDefaultForNewPages: !1
37
37
  } : { name: "", description: "", content: "", enabledByDefaultForNewPages: !1 }), P(!1);
38
- }, [l, a]);
38
+ }, [t, a]);
39
39
  const o = async () => {
40
40
  if (!d.name || !d.content) {
41
41
  B.error("Please enter a name and content");
42
42
  return;
43
43
  }
44
- const t = de(d.content);
45
- if (!t.isValid) {
44
+ const l = de(d.content);
45
+ if (!l.isValid) {
46
46
  B.error("Invalid JSON-LD content");
47
47
  return;
48
48
  }
49
49
  const N = {
50
50
  name: d.name,
51
- jsonld: t.parsed,
51
+ jsonld: l.parsed,
52
52
  addToExistingPages: x,
53
53
  addToNewPages: d.enabledByDefaultForNewPages,
54
54
  description: d.description
@@ -81,7 +81,7 @@ const oe = () => {
81
81
  {
82
82
  id: "new-name",
83
83
  value: d.name,
84
- onChange: (t) => f({ ...d, name: t.target.value }),
84
+ onChange: (l) => f({ ...d, name: l.target.value }),
85
85
  placeholder: "e.g., Product Schema",
86
86
  className: "text-xs"
87
87
  }
@@ -94,7 +94,7 @@ const oe = () => {
94
94
  {
95
95
  id: "new-description",
96
96
  value: d.description || "",
97
- onChange: (t) => f({ ...d, description: t.target.value }),
97
+ onChange: (l) => f({ ...d, description: l.target.value }),
98
98
  placeholder: "Brief description of this schema"
99
99
  }
100
100
  )
@@ -106,7 +106,7 @@ const oe = () => {
106
106
  {
107
107
  id: "new-content",
108
108
  value: d.content || "{}",
109
- onChange: (t) => f({ ...d, content: t }),
109
+ onChange: (l) => f({ ...d, content: l }),
110
110
  placeholder: "Enter JSON-LD markup...",
111
111
  rows: 10
112
112
  }
@@ -120,7 +120,7 @@ const oe = () => {
120
120
  type: "checkbox",
121
121
  id: "add-to-all-existing",
122
122
  checked: x,
123
- onChange: (t) => P(t.target.checked),
123
+ onChange: (l) => P(l.target.checked),
124
124
  className: "h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"
125
125
  }
126
126
  ),
@@ -136,7 +136,7 @@ const oe = () => {
136
136
  type: "checkbox",
137
137
  id: "new-enabled",
138
138
  checked: d.enabledByDefaultForNewPages,
139
- onChange: (t) => f({ ...d, enabledByDefaultForNewPages: t.target.checked }),
139
+ onChange: (l) => f({ ...d, enabledByDefaultForNewPages: l.target.checked }),
140
140
  className: "h-5 w-5 cursor-pointer rounded focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-1"
141
141
  }
142
142
  ),
@@ -158,17 +158,17 @@ const oe = () => {
158
158
  ] }) })
159
159
  ] })
160
160
  ] });
161
- }, Ue = ({ id: l, onClose: i }) => /* @__PURE__ */ e($, { open: !!l, onOpenChange: () => i(), children: l && /* @__PURE__ */ e(_e, { id: l, onClose: i }) }), _e = ({ id: l, onClose: i }) => {
161
+ }, Ue = ({ id: t, onClose: i }) => /* @__PURE__ */ e($, { open: !!t, onOpenChange: () => i(), children: t && /* @__PURE__ */ e(_e, { id: t, onClose: i }) }), _e = ({ id: t, onClose: i }) => {
162
162
  const [a, d] = g({
163
163
  name: "",
164
164
  content: "",
165
165
  description: "",
166
166
  enabledByDefaultForNewPages: !1
167
- }), [f, x] = g(!1), [P, u] = g(!1), [C, p] = g(!1), { data: c } = oe(), { mutateAsync: w, isPending: o } = xe(), { mutateAsync: t } = Ne(), { mutateAsync: N } = be();
167
+ }), [f, x] = g(!1), [P, u] = g(!1), [C, p] = g(!1), { data: c } = oe(), { mutateAsync: w, isPending: o } = xe(), { mutateAsync: l } = Ne(), { mutateAsync: N } = be();
168
168
  Z(() => {
169
169
  var m, D;
170
- if (l && c) {
171
- const b = c.find((L) => L.id === l);
170
+ if (t && c) {
171
+ const b = c.find((L) => L.id === t);
172
172
  b && (d({
173
173
  name: b.name,
174
174
  description: ((m = b.metadata) == null ? void 0 : m.description) || "",
@@ -176,7 +176,7 @@ const oe = () => {
176
176
  enabledByDefaultForNewPages: ((D = b.metadata) == null ? void 0 : D.addToNewPages) || !1
177
177
  }), p(!!b.primaryPage));
178
178
  }
179
- }, [l, c]);
179
+ }, [t, c]);
180
180
  const A = async () => {
181
181
  if (!a.name || !a.content) {
182
182
  B.error("Please enter a name and content");
@@ -188,7 +188,7 @@ const oe = () => {
188
188
  return;
189
189
  }
190
190
  const D = {
191
- id: l,
191
+ id: t,
192
192
  name: a.name,
193
193
  jsonld: m.parsed,
194
194
  addToNewPages: a.enabledByDefaultForNewPages,
@@ -197,13 +197,13 @@ const oe = () => {
197
197
  await w(D), i();
198
198
  }, I = async () => {
199
199
  try {
200
- await t(l);
200
+ await l(t);
201
201
  } finally {
202
202
  x(!1);
203
203
  }
204
204
  }, T = async () => {
205
205
  try {
206
- await N(l);
206
+ await N(t);
207
207
  } finally {
208
208
  u(!1);
209
209
  }
@@ -314,7 +314,7 @@ const oe = () => {
314
314
  ] });
315
315
  };
316
316
  function Xe() {
317
- const [l, i] = g(!1), [a, d] = g(void 0), [f, x] = g(null), [P, u] = g(null), [C, p] = g(null), { data: c, isLoading: w } = oe(), { selectedLang: o } = me(), { data: t } = te(), { data: N } = ye(), { mutateAsync: A } = ve(), { mutateAsync: I } = se(), T = z(() => N == null ? void 0 : N.find((s) => !s.primaryPage && s.lang === ""), [N]), m = z(() => (T == null ? void 0 : T.globalJsonLds) || [], [T]), D = z(() => c ? Je(c, (r) => r.primaryPage === null && r.lang === "").map((r) => {
317
+ const [t, i] = g(!1), [a, d] = g(void 0), [f, x] = g(null), [P, u] = g(null), [C, p] = g(null), { data: c, isLoading: w } = oe(), { selectedLang: o } = me(), { data: l } = le(), { data: N } = ye(), { mutateAsync: A } = ve(), { mutateAsync: I } = se(), T = z(() => N == null ? void 0 : N.find((s) => !s.primaryPage && s.lang === ""), [N]), m = z(() => (T == null ? void 0 : T.globalJsonLds) || [], [T]), D = z(() => c ? Je(c, (r) => r.primaryPage === null && r.lang === "").map((r) => {
318
318
  const h = o ? Oe(c, (S) => S.primaryPage === r.id && S.lang === o) : null;
319
319
  return {
320
320
  defaultSchema: r,
@@ -323,23 +323,23 @@ function Xe() {
323
323
  displayItem: h || r,
324
324
  hasLanguageVersion: !!h
325
325
  };
326
- }) : [], [c, o]), [b, L] = g([]), k = b.length > 0 ? b : (t == null ? void 0 : t.globalJsonLds) || [];
326
+ }) : [], [c, o]), [b, L] = g([]), k = b.length > 0 ? b : (l == null ? void 0 : l.globalJsonLds) || [];
327
327
  Z(() => {
328
- t != null && t.globalJsonLds && L(t.globalJsonLds);
329
- }, [t == null ? void 0 : t.globalJsonLds]);
328
+ l != null && l.globalJsonLds && L(l.globalJsonLds);
329
+ }, [l == null ? void 0 : l.globalJsonLds]);
330
330
  const ie = async (s) => {
331
- if (!(t != null && t.id)) return;
331
+ if (!(l != null && l.id)) return;
332
332
  p(s);
333
333
  const r = k.includes(s), h = r ? k.filter((S) => S !== s) : [...k, s];
334
334
  L(h);
335
335
  try {
336
336
  await I({
337
337
  schemaId: s,
338
- pageId: t.id,
338
+ pageId: l.id,
339
339
  enabled: !r
340
340
  });
341
341
  } catch {
342
- L(t.globalJsonLds);
342
+ L(l.globalJsonLds);
343
343
  } finally {
344
344
  p(null);
345
345
  }
@@ -377,7 +377,7 @@ function Xe() {
377
377
  /* @__PURE__ */ n("div", { className: "space-y-2", children: [
378
378
  (!c || (c == null ? void 0 : c.length) === 0) && !w && /* @__PURE__ */ e("div", { className: "flex items-center justify-center px-2 py-4 text-xs", children: "No shared JSON-LD found" }),
379
379
  D.map(({ defaultSchema: s, displayItem: r, hasLanguageVersion: h }) => {
380
- var ae, le;
380
+ var ae, te;
381
381
  const S = k.includes(r.id), ee = m.includes(s.id), ne = h && o ? ee : S;
382
382
  return /* @__PURE__ */ n(
383
383
  Se,
@@ -410,7 +410,7 @@ function Xe() {
410
410
  ] }),
411
411
  ne && /* @__PURE__ */ e("span", { className: "sr-only text-xs font-normal text-muted-foreground", children: "Enabled" })
412
412
  ] }),
413
- ((ae = r == null ? void 0 : r.metadata) == null ? void 0 : ae.description) && /* @__PURE__ */ e("p", { className: "mt-1 text-xs leading-none text-muted-foreground", children: (le = r == null ? void 0 : r.metadata) == null ? void 0 : le.description })
413
+ ((ae = r == null ? void 0 : r.metadata) == null ? void 0 : ae.description) && /* @__PURE__ */ e("p", { className: "mt-1 text-xs leading-none text-muted-foreground", children: (te = r == null ? void 0 : r.metadata) == null ? void 0 : te.description })
414
414
  ] })
415
415
  ] }),
416
416
  /* @__PURE__ */ n("div", { className: "flex items-center gap-2", children: [
@@ -516,7 +516,7 @@ function Xe() {
516
516
  /* @__PURE__ */ e(
517
517
  Ie,
518
518
  {
519
- show: l,
519
+ show: t,
520
520
  onClose: () => {
521
521
  i(!1), d(void 0);
522
522
  },
@@ -533,26 +533,26 @@ function Xe() {
533
533
  )
534
534
  ] });
535
535
  }
536
- const Re = ({ schema: l, onClose: i }) => /* @__PURE__ */ e($, { open: !!l, onOpenChange: i, children: /* @__PURE__ */ n(W, { className: "max-w-2xl", children: [
536
+ const Re = ({ schema: t, onClose: i }) => /* @__PURE__ */ e($, { open: !!t, onOpenChange: i, children: /* @__PURE__ */ n(W, { className: "max-w-2xl", children: [
537
537
  /* @__PURE__ */ e(Y, { children: /* @__PURE__ */ n(X, { className: "flex items-center gap-2", children: [
538
- l == null ? void 0 : l.name,
539
- (l == null ? void 0 : l.lang) && /* @__PURE__ */ n("span", { className: "text-sm font-normal text-muted-foreground", children: [
538
+ t == null ? void 0 : t.name,
539
+ (t == null ? void 0 : t.lang) && /* @__PURE__ */ n("span", { className: "text-sm font-normal text-muted-foreground", children: [
540
540
  "(",
541
- l.lang,
541
+ t.lang,
542
542
  ")"
543
543
  ] })
544
544
  ] }) }),
545
545
  /* @__PURE__ */ n("div", { className: "space-y-3", children: [
546
- (l == null ? void 0 : l.description) && /* @__PURE__ */ n("div", { children: [
546
+ (t == null ? void 0 : t.description) && /* @__PURE__ */ n("div", { children: [
547
547
  /* @__PURE__ */ e("div", { className: "text-xs font-medium text-muted-foreground", children: "Description" }),
548
- /* @__PURE__ */ e("div", { className: "text-sm", children: l.description })
548
+ /* @__PURE__ */ e("div", { className: "text-sm", children: t.description })
549
549
  ] }),
550
550
  /* @__PURE__ */ n("div", { children: [
551
551
  /* @__PURE__ */ e("div", { className: "mb-2 text-xs font-medium text-muted-foreground", children: "JSON-LD Schema" }),
552
552
  /* @__PURE__ */ e(
553
553
  Ee,
554
554
  {
555
- value: JSON.stringify(l == null ? void 0 : l.jsonld, null, 2),
555
+ value: JSON.stringify(t == null ? void 0 : t.jsonld, null, 2),
556
556
  readOnly: !0,
557
557
  className: "font-mono text-xs",
558
558
  rows: 15
@@ -1 +1 @@
1
- "use strict";const s=require("react/jsx-runtime"),u=require("./index-LfuCMBwI.cjs"),b=require("@chaibuilder/sdk/ui"),d=require("react"),j=e=>{if(!e)return{base:e,extension:null};const n=e.lastIndexOf(".");if(n<=0)return{base:e,extension:null};const t=e.substring(n);return{base:e.substring(0,n),extension:t}},x=e=>{if(!e)return e;const{base:n}=j(e);return n};function E(e,n){const t=(e||"").split("/").filter(Boolean);let r="",a=!0;if(n.slug==="/"){const i=t.pop()||"";if(u.LANGUAGES[i])a=!0;else{r=i;const l=t.pop()||"";a=!!u.LANGUAGES[l]}}else if(n.parent)t.length&&(r=t.pop()||"");else if(t.length){r=t.pop()||"";const i=t.pop()||"";a=!!u.LANGUAGES[i]}return{initSlug:r,prefix:a}}const v=e=>e&&x(e),C=(e,n)=>{const t=x(e||"");return!t||t==="/"?`/${n}`:`${t}/${n}`};function A({value:e,onChange:n,placeholder:t,parentSlug:r,onValidationChange:a,disabled:i=!1,fullSlug:l}){const[g,p]=d.useState(e),[o,f]=d.useState(null);d.useEffect(()=>{p(e)},[e]);const h=S=>{const c=S.target.value.replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),m=(c.match(/\./g)||[]).length,N=m<=1;m>1?f("Invalid slug. Only one dot (.) is allowed in the slug"):f(null),a&&a(N),p(c),n(c)};return s.jsxs("div",{children:[r&&s.jsx("div",{className:"mb-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Parent: ",s.jsx("span",{className:"font-mono text-gray-900",children:v(r)})]})}),s.jsxs("div",{className:"relative",children:[s.jsx(b.Input,{disabled:i,value:g,onChange:h,placeholder:t,className:o?"border-red-500":""}),o&&s.jsx("div",{className:"mt-1 text-xs text-red-500",children:o})]}),l&&l!=="undefined"&&s.jsx("div",{className:"mt-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Complete Slug: ",s.jsx("span",{className:"font-mono text-gray-900",children:l})]})})]})}exports.SlugInput=A;exports.combineParentChildSlugs=C;exports.parseSlugForEdit=E;exports.removeSlugExtension=x;
1
+ "use strict";const s=require("react/jsx-runtime"),u=require("./index-W0r4o5Ro.cjs"),b=require("@chaibuilder/sdk/ui"),d=require("react"),j=e=>{if(!e)return{base:e,extension:null};const n=e.lastIndexOf(".");if(n<=0)return{base:e,extension:null};const t=e.substring(n);return{base:e.substring(0,n),extension:t}},x=e=>{if(!e)return e;const{base:n}=j(e);return n};function E(e,n){const t=(e||"").split("/").filter(Boolean);let r="",a=!0;if(n.slug==="/"){const i=t.pop()||"";if(u.LANGUAGES[i])a=!0;else{r=i;const l=t.pop()||"";a=!!u.LANGUAGES[l]}}else if(n.parent)t.length&&(r=t.pop()||"");else if(t.length){r=t.pop()||"";const i=t.pop()||"";a=!!u.LANGUAGES[i]}return{initSlug:r,prefix:a}}const v=e=>e&&x(e),C=(e,n)=>{const t=x(e||"");return!t||t==="/"?`/${n}`:`${t}/${n}`};function A({value:e,onChange:n,placeholder:t,parentSlug:r,onValidationChange:a,disabled:i=!1,fullSlug:l}){const[g,p]=d.useState(e),[o,f]=d.useState(null);d.useEffect(()=>{p(e)},[e]);const h=S=>{const c=S.target.value.replace(/\//g,"").replace(/\s+/g,"-").replace(/[^a-zA-Z0-9-_.]/g,"-").replace(/-+/g,"-").replace(/^-+/,"").toLowerCase(),m=(c.match(/\./g)||[]).length,N=m<=1;m>1?f("Invalid slug. Only one dot (.) is allowed in the slug"):f(null),a&&a(N),p(c),n(c)};return s.jsxs("div",{children:[r&&s.jsx("div",{className:"mb-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Parent: ",s.jsx("span",{className:"font-mono text-gray-900",children:v(r)})]})}),s.jsxs("div",{className:"relative",children:[s.jsx(b.Input,{disabled:i,value:g,onChange:h,placeholder:t,className:o?"border-red-500":""}),o&&s.jsx("div",{className:"mt-1 text-xs text-red-500",children:o})]}),l&&l!=="undefined"&&s.jsx("div",{className:"mt-1 flex items-center",children:s.jsxs("span",{className:"text-xs text-gray-500",children:["Complete Slug: ",s.jsx("span",{className:"font-mono text-gray-900",children:l})]})})]})}exports.SlugInput=A;exports.combineParentChildSlugs=C;exports.parseSlugForEdit=E;exports.removeSlugExtension=x;
@@ -1,5 +1,5 @@
1
1
  import { jsxs as i, jsx as o } from "react/jsx-runtime";
2
- import { L as d } from "./index-NSqs69Op.js";
2
+ import { L as d } from "./index-yhKyIbgs.js";
3
3
  import { Input as v } from "@chaibuilder/sdk/ui";
4
4
  import { useState as x, useEffect as C } from "react";
5
5
  const y = (e) => {
@@ -1,5 +1,5 @@
1
1
  import { jsxs as c, jsx as a } from "react/jsx-runtime";
2
- import { u, a as d, t as h } from "./index-NSqs69Op.js";
2
+ import { u, a as d, t as h } from "./index-yhKyIbgs.js";
3
3
  import { useTheme as b, useTranslation as g } from "@chaibuilder/sdk";
4
4
  import { Button as o } from "@chaibuilder/sdk/ui";
5
5
  const x = () => {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-LfuCMBwI.cjs"),o=require("@chaibuilder/sdk"),r=require("@chaibuilder/sdk/ui"),h=()=>{const[t]=o.useTheme(),{mutate:c,isPending:i}=s.usePublishPages(),{mutateAsync:n,isPending:u}=s.useUpdateWebsiteSettings(),{t:a}=o.useTranslation(),l=()=>{n({settings:{theme:t}})},d=async()=>{await n({settings:{theme:t}}),c({ids:["THEME"]},{onSuccess:()=>{s.throwConfetti("BOTTOM_RIGHT")}})};return e.jsxs("div",{className:"flex items-center justify-center gap-x-3 border-t bg-white py-3",children:[e.jsx(r.Button,{size:"sm",variant:"outline",disabled:i||u,onClick:l,children:a("Save draft")}),e.jsx(r.Button,{size:"sm",disabled:i||u,onClick:d,children:a("Publish")})]})};exports.default=h;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-W0r4o5Ro.cjs"),o=require("@chaibuilder/sdk"),r=require("@chaibuilder/sdk/ui"),h=()=>{const[t]=o.useTheme(),{mutate:c,isPending:i}=s.usePublishPages(),{mutateAsync:n,isPending:u}=s.useUpdateWebsiteSettings(),{t:a}=o.useTranslation(),l=()=>{n({settings:{theme:t}})},d=async()=>{await n({settings:{theme:t}}),c({ids:["THEME"]},{onSuccess:()=>{s.throwConfetti("BOTTOM_RIGHT")}})};return e.jsxs("div",{className:"flex items-center justify-center gap-x-3 border-t bg-white py-3",children:[e.jsx(r.Button,{size:"sm",variant:"outline",disabled:i||u,onClick:l,children:a("Save draft")}),e.jsx(r.Button,{size:"sm",disabled:i||u,onClick:d,children:a("Publish")})]})};exports.default=h;
@@ -1,5 +1,5 @@
1
1
  import { jsx as e, jsxs as o } from "react/jsx-runtime";
2
- import { o as p } from "./index-NSqs69Op.js";
2
+ import { o as p } from "./index-yhKyIbgs.js";
3
3
  import { useTranslation as u } from "@chaibuilder/sdk";
4
4
  import { Dialog as d, DialogContent as g, DialogHeader as h, DialogTitle as f, DialogDescription as k, DialogFooter as D, Button as s } from "@chaibuilder/sdk/ui";
5
5
  import { useState as x } from "react";
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("./index-LfuCMBwI.cjs"),d=require("@chaibuilder/sdk"),t=require("@chaibuilder/sdk/ui"),m=require("react"),p=({page:i,onClose:n})=>{const{t:a}=d.useTranslation(),[r,s]=m.useState(!1),o=u.useUnmarkAsTemplate(),l=()=>{s(!0),o.mutate(i,{onSuccess:()=>{s(!1),n()},onError:()=>{s(!1)}})};return e.jsx(t.Dialog,{open:!0,onOpenChange:n,children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:a("Unmark as template")}),e.jsx(t.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:a("Are you sure you want to unmark this page as a template?")})]}),e.jsxs(t.DialogFooter,{className:r?"pointer-events-none opacity-75":"",children:[e.jsx(t.Button,{variant:"outline",onClick:c=>{c.stopPropagation(),n()},children:a("Cancel")}),e.jsx(t.Button,{variant:"default",disabled:r,onClick:l,children:a("Unmark as template")})]})]})})};exports.default=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),u=require("./index-W0r4o5Ro.cjs"),d=require("@chaibuilder/sdk"),t=require("@chaibuilder/sdk/ui"),m=require("react"),p=({page:i,onClose:n})=>{const{t:a}=d.useTranslation(),[r,s]=m.useState(!1),o=u.useUnmarkAsTemplate(),l=()=>{s(!0),o.mutate(i,{onSuccess:()=>{s(!1),n()},onError:()=>{s(!1)}})};return e.jsx(t.Dialog,{open:!0,onOpenChange:n,children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:a("Unmark as template")}),e.jsx(t.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:a("Are you sure you want to unmark this page as a template?")})]}),e.jsxs(t.DialogFooter,{className:r?"pointer-events-none opacity-75":"",children:[e.jsx(t.Button,{variant:"outline",onClick:c=>{c.stopPropagation(),n()},children:a("Cancel")}),e.jsx(t.Button,{variant:"default",disabled:r,onClick:l,children:a("Unmark as template")})]})]})})};exports.default=p;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),u=require("./index-LfuCMBwI.cjs"),c=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),d=({page:i,onClose:t})=>{const{t:e}=c.useTranslation(),{mutate:r,isPending:l}=u.useUnpublishPage(),o=async()=>{r(i,{onSuccess:t})};return n.jsx(s.Dialog,{open:!!i,onOpenChange:t,children:n.jsxs(s.DialogContent,{children:[n.jsxs(s.DialogHeader,{children:[n.jsx(s.DialogTitle,{children:e("Confirm action")}),n.jsxs(s.DialogDescription,{children:[e("Are you sure you want to unpublish")," ",n.jsx("b",{children:(i==null?void 0:i.name)??(i==null?void 0:i.slug)}),"?"]})]}),n.jsxs(s.DialogFooter,{children:[n.jsx(s.Button,{variant:"outline",onClick:t,children:e("Cancel")}),n.jsx(s.Button,{variant:"destructive",disabled:l,onClick:o,children:e(l?"Updating...":"Unpublish")})]})]})})};exports.default=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),u=require("./index-W0r4o5Ro.cjs"),c=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),d=({page:i,onClose:t})=>{const{t:e}=c.useTranslation(),{mutate:r,isPending:l}=u.useUnpublishPage(),o=async()=>{r(i,{onSuccess:t})};return n.jsx(s.Dialog,{open:!!i,onOpenChange:t,children:n.jsxs(s.DialogContent,{children:[n.jsxs(s.DialogHeader,{children:[n.jsx(s.DialogTitle,{children:e("Confirm action")}),n.jsxs(s.DialogDescription,{children:[e("Are you sure you want to unpublish")," ",n.jsx("b",{children:(i==null?void 0:i.name)??(i==null?void 0:i.slug)}),"?"]})]}),n.jsxs(s.DialogFooter,{children:[n.jsx(s.Button,{variant:"outline",onClick:t,children:e("Cancel")}),n.jsx(s.Button,{variant:"destructive",disabled:l,onClick:o,children:e(l?"Updating...":"Unpublish")})]})]})})};exports.default=d;
@@ -1,5 +1,5 @@
1
1
  import { jsx as o, jsxs as l } from "react/jsx-runtime";
2
- import { l as u } from "./index-NSqs69Op.js";
2
+ import { l as u } from "./index-yhKyIbgs.js";
3
3
  import { useTranslation as a } from "@chaibuilder/sdk";
4
4
  import { Dialog as h, DialogContent as d, DialogHeader as m, DialogTitle as b, DialogDescription as D, DialogFooter as f, Button as s } from "@chaibuilder/sdk/ui";
5
5
  const g = ({ page: n, onClose: t }) => {
@@ -4,7 +4,7 @@ import { Button as s } from "@chaibuilder/sdk/ui";
4
4
  import { useAtom as h } from "jotai";
5
5
  import { map as p } from "lodash-es";
6
6
  import { Smartphone as w, Tablet as f, Laptop as u, LaptopMinimal as x } from "lucide-react";
7
- import { p as v, T as _ } from "./index-NSqs69Op.js";
7
+ import { p as v, T as _ } from "./index-yhKyIbgs.js";
8
8
  const b = [
9
9
  {
10
10
  title: "mobile_xs_title",
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),a=require("@chaibuilder/sdk/ui"),h=require("jotai"),x=require("lodash-es"),n=require("lucide-react"),c=require("./index-LfuCMBwI.cjs"),m=[{title:"mobile_xs_title",content:"mobile_xs_content",icon:e.jsx(n.Smartphone,{className:"h-4 w-4"}),width:400},{title:"tablet_md_title",content:"tablet_md_content",icon:e.jsx(n.Tablet,{className:"h-4 w-4"}),width:800},{title:"desktop_xl_title",content:"desktop_xl_content",icon:e.jsx(n.Laptop,{className:"h-4 w-4"}),width:1200},{title:"large_desktop_2xl_title",content:"large_desktop_2xl_content",icon:e.jsx(n.LaptopMinimal,{className:"h-4 w-4"}),width:1600}],w=({currentWidth:t,width:s,icon:l,setIframeWidth:i})=>e.jsx(a.Button,{className:"px-3 py-3",onClick:()=>i(s),variant:s===t?"default":"ghost",children:l}),p=()=>{const[t,s]=o.useState(1200),l=r=>s(r),[i,d]=h.useAtom(c.previewUrlAtom);if(!i)return null;const u=()=>{d("")};return e.jsxs("div",{className:"absolute inset-0 z-[999999] flex h-screen w-screen flex-col overflow-hidden bg-gray-100",children:[e.jsxs("div",{className:"flex h-[50px] items-center justify-center border-b border-gray-200 px-4 shadow-sm",children:[e.jsx("div",{className:"flex items-center justify-center rounded-md border border-gray-300",children:x.map(m,r=>o.createElement(w,{...r,setIframeWidth:l,key:r.title,currentWidth:t}))})," ",e.jsx(c.Tooltip,{content:"Exit Preview",delayDuration:0,children:e.jsx(a.Button,{variant:"destructive",size:"sm",onClick:u,children:e.jsx("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M2 3C2 2.44772 2.44772 2 3 2H12C12.5523 2 13 2.44772 13 3V12C13 12.5523 12.5523 13 12 13H3C2.44772 13 2 12.5523 2 12V3ZM12 3H3V12H12V3Z",fill:"currentColor","fill-rule":"evenodd","clip-rule":"evenodd"})})})})]}),e.jsx("iframe",{style:{width:`${t}px`,transition:"width 0.3s ease-in-out"},className:"no-scrollbar mx-auto h-full overflow-y-auto border bg-white",src:i})]})};exports.default=p;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),o=require("react"),a=require("@chaibuilder/sdk/ui"),h=require("jotai"),x=require("lodash-es"),n=require("lucide-react"),c=require("./index-W0r4o5Ro.cjs"),m=[{title:"mobile_xs_title",content:"mobile_xs_content",icon:e.jsx(n.Smartphone,{className:"h-4 w-4"}),width:400},{title:"tablet_md_title",content:"tablet_md_content",icon:e.jsx(n.Tablet,{className:"h-4 w-4"}),width:800},{title:"desktop_xl_title",content:"desktop_xl_content",icon:e.jsx(n.Laptop,{className:"h-4 w-4"}),width:1200},{title:"large_desktop_2xl_title",content:"large_desktop_2xl_content",icon:e.jsx(n.LaptopMinimal,{className:"h-4 w-4"}),width:1600}],w=({currentWidth:t,width:s,icon:l,setIframeWidth:i})=>e.jsx(a.Button,{className:"px-3 py-3",onClick:()=>i(s),variant:s===t?"default":"ghost",children:l}),p=()=>{const[t,s]=o.useState(1200),l=r=>s(r),[i,d]=h.useAtom(c.previewUrlAtom);if(!i)return null;const u=()=>{d("")};return e.jsxs("div",{className:"absolute inset-0 z-[999999] flex h-screen w-screen flex-col overflow-hidden bg-gray-100",children:[e.jsxs("div",{className:"flex h-[50px] items-center justify-center border-b border-gray-200 px-4 shadow-sm",children:[e.jsx("div",{className:"flex items-center justify-center rounded-md border border-gray-300",children:x.map(m,r=>o.createElement(w,{...r,setIframeWidth:l,key:r.title,currentWidth:t}))})," ",e.jsx(c.Tooltip,{content:"Exit Preview",delayDuration:0,children:e.jsx(a.Button,{variant:"destructive",size:"sm",onClick:u,children:e.jsx("svg",{width:"15",height:"15",viewBox:"0 0 15 15",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:e.jsx("path",{d:"M2 3C2 2.44772 2.44772 2 3 2H12C12.5523 2 13 2.44772 13 3V12C13 12.5523 12.5523 13 12 13H3C2.44772 13 2 12.5523 2 12V3ZM12 3H3V12H12V3Z",fill:"currentColor","fill-rule":"evenodd","clip-rule":"evenodd"})})})})]}),e.jsx("iframe",{style:{width:`${t}px`,transition:"width 0.3s ease-in-out"},className:"no-scrollbar mx-auto h-full overflow-y-auto border bg-white",src:i})]})};exports.default=p;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "Suraj Air",
4
4
  "license": "Private",
5
5
  "homepage": "https://chaibuilder.com",
6
- "version": "0.15.24",
6
+ "version": "0.16.1",
7
7
  "type": "module",
8
8
  "files": [
9
9
  "dist"
@@ -58,7 +58,7 @@
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@chaibuilder/runtime": "2.2.0",
61
- "@chaibuilder/sdk": "3.0.27",
61
+ "@chaibuilder/sdk": "3.1.3",
62
62
  "@types/react": "*",
63
63
  "@types/react-dom": "*",
64
64
  "jotai": "2.14.0",
@@ -75,7 +75,7 @@
75
75
  },
76
76
  "dependencies": {
77
77
  "@chaibuilder/runtime": "2.2.0",
78
- "@chaibuilder/sdk": "3.0.27",
78
+ "@chaibuilder/sdk": "3.1.3",
79
79
  "@mhsdesign/jit-browser-tailwindcss": "^0.4.2",
80
80
  "@radix-ui/react-icons": "^1.3.2",
81
81
  "@supabase/supabase-js": "2.50.3",
@@ -1,46 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),S=require("@chaibuilder/sdk"),ee=require("@chaibuilder/sdk/ui"),E=require("lodash-es"),b=require("lucide-react"),p=require("react"),Q=require("sonner"),te=require("./index-LfuCMBwI.cjs"),K=["Box","Button","Heading","Paragraph","Text","Span","Link","Image","Video","Icon","List","ListItem","Row","Column","Form","Input","FormButton","Checkbox","Radio","Select","TextArea","Label","RichText","Divider","EmptyBox","LineBreak","Table","EmptySlot"];function se(s){if(!s)return"";let t=s.trim();return t=t.replace(/^```html\n?/i,""),t=t.replace(/^```\n?/,""),t=t.replace(/\n?```$/,""),t=t.trim(),t}function ne(s){if(!s)return"";const t=se(s);return t.length===0||!t.includes("<")||!t.includes(">")?"":t}const V=s=>{const t=document.getElementById("canvas-iframe");if(!t)return null;const n=t==null?void 0:t.contentDocument;if(!n)return null;const l=n.querySelector(`[data-block-id="${s}"]`);if(!l)return null;if(s==="canvas"){const r=n.createElement("div");return r.style.height="100vh",l.appendChild(r),r}return l},re=(s,t)=>{var v;const n=V(s);if(!n)return{position:0,currentHTML:""};n.style.opacity="0.9";const l=((v=n==null?void 0:n.parentNode)==null?void 0:v.childNodes)||[],r=Array.from(l).indexOf(n),h=n.outerHTML,u=new DOMParser().parseFromString(h,"text/html");return u.querySelectorAll("[data-block-id]").forEach(o=>{const w=o.getAttribute("data-block-id"),c=E.find(t,{_id:w}),C=c==null?void 0:c._type;if(K.includes(C)){const m=JSON.stringify(c);if(m!=null&&m.includes("{{")&&(m!=null&&m.includes("}}"))){const j=Object.keys(c).filter(k=>{const a=c[k],g=typeof a=="string"?a:JSON.stringify(a);return g.includes("{{")&&g.includes("}}")});j.length>0&&(o.setAttribute("data-binding-key",j[0]),o.innerHTML=E.get(c,j[0],""))}o.removeAttribute("data-block-type"),o.removeAttribute("data-style-prop"),o.removeAttribute("data-block-parent"),o.removeAttribute("data-style-id"),o.removeAttribute("data-block-id"),o.removeAttribute("data-block-index"),o.removeAttribute("data-highlighted")}else o.innerHTML=C}),{position:r,currentHTML:u.body.innerHTML}};function ae({userInput:s,language:t="en",currentHtml:n}){const l=te.LANGUAGES[t]||"English";return n&&n.trim().length>0?`
2
- MODE: EDIT
3
- CURRENT HTML:
4
- ${n}
5
-
6
- USER REQUEST: ${s}
7
-
8
- EDIT MODE INSTRUCTIONS:
9
- - Modify the existing HTML based on the user's request
10
- - IMPORTANT: If asked for updating content, do not change layout just update same HTML with updated content
11
- - CRITICAL: THINGS TO PREVENT
12
- - Preserve ALL data binding placeholders in format '{{dataBindingId}}' - never remove or modify these dynamic content markers
13
- - Preserve html tag with attributes data-block-type="PartialBlock" or data-block-type="CustomBlock" - never remove or modify these tag
14
- - Preserve the overall structure unless specifically asked to change it
15
- - Update content, styling, or layout as requested
16
- - Maintain responsive design and accessibility
17
- - Keep using shadcn/ui theme classes and Tailwind CSS
18
- - Ensure all chai-name attributes remain descriptive and accurate
19
- - Generate content in specified language: ${l}
20
- - Apply the same design principles from the system prompt
21
- - Make sure the edited HTML is clean and semantic`.trim():`
22
- USER REQUEST: ${s}
23
-
24
- CREATE MODE INSTRUCTIONS:
25
- - Generate complete HTML structure based on user request
26
- - Use creative, modern, and responsive design
27
- - Apply Tailwind CSS v3+ classes exclusively
28
- - Follow shadcn/ui design patterns and theming
29
- - Include proper accessibility attributes
30
- - Add chai-name attributes to all wrapper/container elements
31
- - Use semantic HTML structure
32
- - Generate contextually appropriate content in ${l}
33
- - Make each element unique and meaningful
34
- - Create realistic, professional content that fits the request
35
- - Avoid generic placeholder text
36
- - Use strategic image placement where appropriate
37
- - Ensure mobile-first responsive design
38
- - Apply proper hover and focus states
39
-
40
- DESIGN REQUIREMENTS:
41
- - Choose creative layout patterns that are visually striking
42
- - Apply modern spacing and typography
43
- - Use proper color contrast with shadcn/ui theme classes
44
- - Make it responsive across all device sizes
45
- - Include interactive elements with proper states
46
- - Ensure accessibility compliance`.trim()}const oe=[{label:"Navbar",prompt:"Create stunning, fully responsive navbar with"},{label:"Hero section",prompt:"Create visually compelling hero section with"},{label:"Features grid",prompt:"Create comprehensive features section with"},{label:"Contact form",prompt:"Create professional contact form with"},{label:"Testimonials",prompt:"Create engaging testimonials section with"},{label:"Pricing table",prompt:"Create modern pricing table with"},{label:"FAQ section",prompt:"Create informative FAQ section with"},{label:"Footer",prompt:"Create comprehensive footer section with"},{label:"Call to action",prompt:"Create compelling call to action section with"},{label:"Team section",prompt:"Create professional team section with"},{label:"Blog grid",prompt:"Create attractive blog grid section with"},{label:"Stats section",prompt:"Create impactful statistics section with"}],le=[{label:"Update styles",prompt:"Update styles"},{label:"Update content",prompt:"Update text content"},{label:"Update layout",prompt:"Update layout"},{label:"Improve content",prompt:"Improve text content grammar and spelling"},{label:"Make content longer",prompt:"Make text content longer"},{label:"Make content shorter",prompt:"Make text content shorter"},{label:"Fix grammar",prompt:"Fix grammar of the text content"}],ie=({onSelect:s,currentBlock:t,selectedImage:n})=>{const[l,r]=p.useState(!1),h=t?le:oe;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:()=>r(!l),className:S.mergeClasses("flex h-6 w-full cursor-pointer items-center justify-between gap-2 px-2",t?"bg-green-50/80 text-green-500 hover:bg-green-50":"text-primary hover:bg-primary/5"),children:[e.jsx("span",{className:"truncate whitespace-nowrap text-xs font-medium leading-none",children:n?"Image actions":t?"Edit : "+(t._name||t._type):"Quick Prompts"}),e.jsx(b.ChevronsUpDown,{className:"h-3 w-3"})]}),l&&e.jsx("div",{className:"max-h-60 w-full overflow-y-auto bg-white px-1 pb-1",children:h.map((y,u)=>e.jsx("div",{className:"flex cursor-pointer items-center gap-x-1 p-1 text-xs leading-none hover:text-blue-700",onClick:()=>{s(`${n||t?"Update":"Add New"} ${y.label}`,y.prompt),r(!1)},children:e.jsxs("span",{className:"truncate whitespace-nowrap",children:[t?null:e.jsx("span",{className:"font-thin text-muted-foreground",children:"Add New"})," ",y.label]})},u))})]})},ce=({message:s})=>{var t;return((t=s==null?void 0:s.content)==null?void 0:t.length)<100?e.jsx("div",{className:"relative z-50 mb-3 flex w-full flex-col gap-2 overflow-hidden",children:e.jsxs("div",{className:"flex w-max items-center justify-center gap-1 rounded-md p-1 px-2 text-xs font-medium text-blue-500",children:[e.jsx(b.Loader,{className:"h-3 w-3 animate-spin"})," Processing"]})}):e.jsx("div",{className:"relative z-50 mb-3 flex w-full flex-col gap-2 overflow-hidden",children:e.jsxs("div",{className:"flex w-max items-center justify-center gap-1 rounded-md p-1 px-2 text-xs font-medium text-blue-500",children:[e.jsx(b.Loader,{className:"h-3 w-3 animate-spin"})," Generating"]})})},de=({message:s,isUser:t,isLoading:n})=>t?e.jsx("div",{className:"relative mb-3 flex w-full justify-end overflow-hidden",children:e.jsx("div",{className:"flex max-w-[95%] flex-row-reverse rounded-lg rounded-br-sm bg-blue-500 px-2 py-1.5 text-xs text-white",children:s.userMessage})}):n?e.jsx(ce,{message:s}):e.jsx("div",{className:`relative mb-3 flex w-full overflow-hidden ${t?"justify-end":n?"max-h-48 min-h-24 justify-start":"max-h-16"}`,children:e.jsxs("div",{className:"flex w-max items-center justify-center gap-1 rounded-md p-1 px-2 text-xs font-medium text-green-500",children:[e.jsx(b.CheckCircle,{className:"h-3 w-3"})," Completed"]})}),ue=({input:s,setInput:t,onSend:n,onStop:l,isLoading:r,disabled:h,currentBlock:y})=>{const u=p.useRef(null),v=p.useRef(null),[o,w]=p.useState(null),c=a=>{a.key==="Enter"&&!a.shiftKey&&(a.preventDefault(),s.trim()&&!r&&(n(s==null?void 0:s.trim(),void 0,o||void 0),w(null)))},C=()=>{const a=u.current;a&&(a.style.height="auto",a.style.height=Math.min(a.scrollHeight,120)+"px")},m=a=>{var N;const g=(N=a.target.files)==null?void 0:N[0];if(g&&g.type.startsWith("image/")){const A=new FileReader;A.onload=P=>{var i,x;const H=(i=P.target)==null?void 0:i.result;w(H),t("Generate UI based on given image "),(x=u.current)==null||x.focus()},A.readAsDataURL(g)}a.target.value=""},j=()=>{var a;(a=v.current)==null||a.click()},k=()=>{n(s==null?void 0:s.trim(),void 0,o||void 0),w(null)};return p.useEffect(()=>{C()},[s]),e.jsxs("div",{children:[!o&&e.jsx("div",{className:`mx-auto flex w-full max-w-[95%] flex-col items-center overflow-hidden rounded-t-md border-x border-t border-gray-200 bg-gray-100 ${r?"pointer-events-none opacity-50":""}`,children:e.jsx(ie,{currentBlock:y,selectedImage:o,onSelect:(a,g)=>{var N;t(g+" "),(N=u.current)==null||N.focus()}})}),e.jsxs("div",{className:"rounded-lg border border-gray-200 bg-white",children:[o&&e.jsxs("div",{className:"relative flex w-max items-center justify-start gap-x-2 px-2 pt-2",children:[e.jsx("img",{src:o,alt:"Selected attachment",className:"max-h-16 max-w-full rounded-md border"}),e.jsx("button",{onClick:()=>w(null),className:"absolute -right-0 -top-0 flex items-center rounded-full bg-red-400 p-1 text-xs text-white hover:bg-red-500",title:"Remove image",children:e.jsx(b.X,{className:"h-2 w-2"})})]}),e.jsx("textarea",{ref:u,value:s,onChange:a=>t(a.target.value),onKeyDown:c,placeholder:"Ask me anything...",className:`max-h-[200px] min-h-[60px] w-full resize-none rounded-lg border-none px-3 py-2 text-sm outline-none ${r?"cursor-not-allowed opacity-50":""}`,rows:3,disabled:r}),e.jsxs("div",{className:"flex items-center justify-between p-2",children:[e.jsx("button",{disabled:r,onClick:j,className:`p-1.5 text-gray-400 hover:text-gray-500 ${r?"cursor-not-allowed opacity-50":""}`,title:"Attach Image",children:e.jsx(b.Paperclip,{size:16})}),e.jsx("input",{disabled:r,ref:v,type:"file",accept:"image/*",onChange:m,className:"hidden"}),r?e.jsx("button",{onClick:l,className:"z-50 rounded-md bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:"Stop generation",children:e.jsx(b.Square,{size:16})}):e.jsx("button",{onClick:k,disabled:!s.trim()||h,className:`rounded-md bg-blue-500 p-1.5 text-white transition-colors hover:bg-blue-600 ${!s.trim()||h?"cursor-not-allowed opacity-50":""}`,children:e.jsx(b.Send,{size:16})})]})]})]})},me=()=>{const[s,t]=p.useState(""),[n,l]=p.useState([]),[r,h]=p.useState(!1),[y,u]=p.useState(null),v=p.useRef(null),{addPredefinedBlock:o}=S.useAddBlock(),w=S.useRemoveBlocks(),c=S.useSelectedBlock(),[C,m]=p.useState(null),[j]=S.useBlocksStore(),{selectedLang:k,fallbackLang:a}=S.useLanguages(),g=k||a,N=()=>{var i;(i=v.current)==null||i.scrollIntoView({behavior:"smooth"})};p.useEffect(()=>{N()},[n,r]);const A=()=>{y&&(y.abort(),u(null)),h(!1),t(""),m(null),l(i=>{const x=i[i.length-1];return x&&x.role==="assistant"&&!x.content.trim()?i.slice(0,-1):i}),Q.toast.info("Generation stopped")},P=async(i,x,O)=>{var z;if(!i||r)return;const d=c;m(c);const{position:J,currentHTML:_}=re((c==null?void 0:c._id)||"",j);if(c&&!_){Q.toast.error("Something went wrong. Please try again.");return}const q={id:Date.now().toString(),role:"user",content:ae({userInput:x||i,language:g,currentHtml:c?_:""}),userMessage:i},F={id:Date.now().toString(),role:"assistant",content:""};l(T=>[...T,q,F]),h(!0);const $=new AbortController;u($);try{const T={messages:[...n,q].map(f=>({role:f.role,content:f.content}))};O&&(T.image=O);const I=await fetch("/chai/api/chat",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(T),signal:$.signal});if(!I.ok)throw new Error("Failed to get AI response");const R=(z=I.body)==null?void 0:z.getReader(),W=new TextDecoder;let L="";if(!R)throw new Error("Response body is not readable");const M=V(d?d==null?void 0:d._id:"canvas");for(;;){const{done:f,value:U}=await R.read();if(f){M&&!d&&M.remove();break}const D=W.decode(U,{stream:!0});L+=D,M&&(M.innerHTML=L,M.scrollIntoView({behavior:"smooth",block:"start"})),l(G=>G.map(B=>B.id===F.id?{...B,content:L}:B))}const X=ne(L),Y=S.getBlocksFromHTML(X),Z=E.map(Y,f=>{const U=E.get(f,"styles_attrs.data-block-type");if(U&&!K.includes(U)){const D=E.get(f,"styles_attrs.data-block-id");return{...E.find(j,{_id:D}),_parent:f==null?void 0:f._parent}}return f});d!=null&&d._id&&w([d==null?void 0:d._id]),o([...Z],d==null?void 0:d._parent,d?J:-1)}catch(T){if(T.name!=="AbortError"){const I={id:(Date.now()+1).toString(),role:"assistant",content:"Sorry, I encountered an error. Please try again."};l(R=>[...R,I])}}finally{t(""),h(!1),m(null),u(null)}},H=()=>{l([]),t(""),m(null),u(null),h(!1)};return e.jsxs(e.Fragment,{children:[r&&e.jsx("div",{className:"fixed inset-0 left-0 top-0 z-40 flex h-screen w-screen flex-col items-center justify-center bg-transparent"}),e.jsxs("div",{className:"flex h-full w-full flex-col bg-white",children:[e.jsxs("div",{className:"flex w-full items-center justify-between",children:[e.jsx("p",{className:"text-xs text-gray-500",children:"Your conversation will not be saved"}),(n==null?void 0:n.length)>0&&e.jsx(ee.Button,{variant:"outline",size:"icon",onClick:H,className:"h-6 w-6",children:e.jsx(b.Plus,{})})]}),e.jsxs("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:[n.length===0&&e.jsx("div",{className:"flex-1 space-y-3 overflow-y-auto py-4",children:e.jsxs("div",{className:"mx-auto mt-8 text-center text-gray-500",children:[e.jsx(b.Bot,{size:48,className:"mx-auto mb-4 text-gray-300"}),e.jsx("p",{className:"mx-auto max-w-[75%] text-sm",children:"Start a conversation with the AI assistant to generate and update your sections"})]})}),n.map((i,x)=>i.role!=="system"&&e.jsx(de,{message:i,isUser:i.role==="user",isLoading:i.role==="assistant"&&r&&x===n.length-1},x)),e.jsx("div",{ref:v})]}),e.jsx("div",{className:"border-gray-200 pb-2",children:e.jsx(ue,{input:s,setInput:t,onSend:P,onStop:A,isLoading:r,currentBlock:c||C,disabled:(s==null?void 0:s.length)===0})})]})]})};exports.default=me;