@chaibuilder/pages 0.15.0 → 0.15.2

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 (70) hide show
  1. package/dist/{2AITGKQY-CpxlNmec.cjs → 2AITGKQY-C2afI3G9.cjs} +1 -1
  2. package/dist/{2AITGKQY-gEvxLMa5.js → 2AITGKQY-CpTgZa1B.js} +2 -2
  3. package/dist/{NCMVHL6D-sV6MElOb.cjs → NCMVHL6D-BdBKMEGN.cjs} +1 -1
  4. package/dist/{NCMVHL6D-DpycZ17L.js → NCMVHL6D-fVqsZOVq.js} +2 -2
  5. package/dist/{ZDWCUMSJ-BbzwbqTE.js → ZDWCUMSJ-CTb4F48A.js} +1 -1
  6. package/dist/{ZDWCUMSJ-BPT9OZay.cjs → ZDWCUMSJ-DHGlUoWR.cjs} +1 -1
  7. package/dist/{add-new-language-page-B4_z4O8a.cjs → add-new-language-page-CY2hL7A-.cjs} +1 -1
  8. package/dist/{add-new-language-page-C8LIaHl6.js → add-new-language-page-DY0789ha.js} +2 -2
  9. package/dist/{add-new-page-JY6dRnC4.js → add-new-page-C6fGkJF9.js} +1 -1
  10. package/dist/{add-new-page-CQRr6Z8g.cjs → add-new-page-DnVeU4g6.cjs} +1 -1
  11. package/dist/{delete-page-z88W-Ikh.cjs → delete-page-DZi2DCAb.cjs} +1 -1
  12. package/dist/{delete-page-Dfa2vyQB.js → delete-page-hLDHKzbl.js} +1 -1
  13. package/dist/digital-asset-manager-Cj5r9niq.cjs +1 -0
  14. package/dist/digital-asset-manager-CpoNKOFK.js +1001 -0
  15. package/dist/{duplicate-page-Welcro7Y.cjs → duplicate-page-CTH0REkv.cjs} +1 -1
  16. package/dist/{duplicate-page-B0urG1pP.js → duplicate-page-sdO4hRfo.js} +14 -14
  17. package/dist/{dynamic-page-selector-CyhZ0SRO.js → dynamic-page-selector-EfxbLRp-.js} +1 -1
  18. package/dist/{dynamic-page-selector-Dn_j_r-h.cjs → dynamic-page-selector-Ki3lEtRJ.cjs} +1 -1
  19. package/dist/image-editor-CRJ0cNde.cjs +1 -0
  20. package/dist/image-editor-DR1FYokM.js +111 -0
  21. package/dist/{index-BSEA_u0X.js → index-CdUDr4JM.js} +1446 -1368
  22. package/dist/index-vjYir4bk.cjs +5 -0
  23. package/dist/index.cjs +1 -1
  24. package/dist/index.js +10 -10
  25. package/dist/{json-diff-viewer-DVlb4YWD.js → json-diff-viewer-BQSgrzoZ.js} +1 -1
  26. package/dist/{json-diff-viewer-BIJ4iNWb.cjs → json-diff-viewer-DthVeQzc.cjs} +1 -1
  27. package/dist/{lang-panel-D0IN38gF.js → lang-panel-DJGvZmRK.js} +29 -29
  28. package/dist/{lang-panel-l6Teik-4.cjs → lang-panel-DTDqVZGv.cjs} +1 -1
  29. package/dist/{mark-as-template-DBPJ1gIK.cjs → mark-as-template-BNbkAkrD.cjs} +1 -1
  30. package/dist/{mark-as-template-B22EANHN.js → mark-as-template-C3669ENB.js} +1 -1
  31. package/dist/{no-language-page-content-DNNu8wd0.js → no-language-page-content-DMdFjwWT.js} +1 -1
  32. package/dist/{no-language-page-content-BUHXqSKG.cjs → no-language-page-content-DY-A9YbI.cjs} +1 -1
  33. package/dist/{page-creator-BPgx7zdJ.js → page-creator-B_X6PI1J.js} +2 -2
  34. package/dist/{page-creator-DbN3Nvq6.cjs → page-creator-BcoyQ5mT.cjs} +1 -1
  35. package/dist/{page-lock-request-BFkpw5VN.cjs → page-lock-request-Cl0GyiJp.cjs} +1 -1
  36. package/dist/{page-lock-request-Br9S1AsA.js → page-lock-request-DJVlDGsX.js} +10 -10
  37. package/dist/{page-locked-by-dialog-2h8cv1tO.cjs → page-locked-by-dialog-CZvpeWVu.cjs} +1 -1
  38. package/dist/{page-locked-by-dialog-DyLcMu33.js → page-locked-by-dialog-DY_jVajL.js} +1 -1
  39. package/dist/{page-manager-new-B2oBm4pU.js → page-manager-new-BKr1R3Yu.js} +37 -37
  40. package/dist/{page-manager-new-CAj6WV-C.cjs → page-manager-new-v2nHss3Q.cjs} +1 -1
  41. package/dist/{page-manager-search-and-filter-CWMXLTqE.cjs → page-manager-search-and-filter-CibEmd6Z.cjs} +1 -1
  42. package/dist/{page-manager-search-and-filter-WQYVXUAt.js → page-manager-search-and-filter-DLrJ5bRM.js} +1 -1
  43. package/dist/{page-revisions-content-AMH8AxBU.cjs → page-revisions-content-Bv1b1HsS.cjs} +1 -1
  44. package/dist/{page-revisions-content-DM-ngq3R.js → page-revisions-content-C4hAdUVX.js} +17 -17
  45. package/dist/{publish-pages-content-Dast4sG6.js → publish-pages-content-B-8X8FzF.js} +2 -2
  46. package/dist/{publish-pages-content-Dkv0Lok8.cjs → publish-pages-content-Krawy2bg.cjs} +1 -1
  47. package/dist/{save-to-lib-B5k0MVbW.js → save-to-lib-BV_uNHn3.js} +12 -12
  48. package/dist/{save-to-lib-DWtmtrUj.cjs → save-to-lib-CiX1h4Po.cjs} +1 -1
  49. package/dist/{seo-panel-D75jQH_j.js → seo-panel-BHqhAOiz.js} +34 -34
  50. package/dist/{seo-panel-dBvEEfi9.cjs → seo-panel-CpjeH5Yl.cjs} +1 -1
  51. package/dist/shared-json-ld-BfkvfAZY.js +650 -0
  52. package/dist/shared-json-ld-C-fV8erH.cjs +1 -0
  53. package/dist/{slug-input-BEegJ8bv.js → slug-input-Dz9A1ksl.js} +1 -1
  54. package/dist/{slug-input-BITq28nI.cjs → slug-input-ssMiXYTG.cjs} +1 -1
  55. package/dist/{theme-panel-footer-zLXS6SHh.js → theme-panel-footer-DZSU9bNX.js} +1 -1
  56. package/dist/{theme-panel-footer-DcASH9l1.cjs → theme-panel-footer-Rmw520a9.cjs} +1 -1
  57. package/dist/{unmark-as-template-DXFRY_pc.js → unmark-as-template-D8o31xMH.js} +1 -1
  58. package/dist/{unmark-as-template-ChmjL4-w.cjs → unmark-as-template-D_Td5Aeb.cjs} +1 -1
  59. package/dist/{unpublish-page-BxN0deJK.cjs → unpublish-page-Bca-dVic.cjs} +1 -1
  60. package/dist/{unpublish-page-DMteaCpR.js → unpublish-page-D9XisIu8.js} +1 -1
  61. package/dist/{web-preview-DM11qhOe.cjs → web-preview-BddtAY2w.cjs} +1 -1
  62. package/dist/{web-preview-BDTdFQ2h.js → web-preview-Dn1aCs5v.js} +1 -1
  63. package/package.json +1 -1
  64. package/dist/digital-asset-manager-Zh-mlMF5.cjs +0 -1
  65. package/dist/digital-asset-manager-hqMwBWhb.js +0 -976
  66. package/dist/image-editor-BWLJT1mr.cjs +0 -1
  67. package/dist/image-editor-CzFST20j.js +0 -104
  68. package/dist/index-MlpQJHWW.cjs +0 -5
  69. package/dist/shared-json-ld-BvWyXBz_.cjs +0 -1
  70. package/dist/shared-json-ld-ZtwsYt9H.js +0 -337
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),q=require("@tanstack/react-query"),u=require("./index-vjYir4bk.cjs"),s=require("@chaibuilder/sdk/ui"),I=require("lodash-es"),p=require("lucide-react"),o=require("react"),F=require("sonner"),z=()=>{const t=u.useApiUrl(),h=u.useFetch();return q.useQuery({queryKey:[u.ACTIONS.GET_GLOBAL_JSONLD_ITEMS],queryFn:async()=>h(t,{action:u.ACTIONS.GET_GLOBAL_JSONLD_ITEMS})})},U=({show:t,onClose:h,initialData:n})=>e.jsx(s.Dialog,{open:t,onOpenChange:()=>h(),children:t&&e.jsx(_,{show:t,onClose:h,initialData:n})}),_=({show:t,onClose:h,initialData:n})=>{const[S,N]=o.useState("edit"),[v,i]=o.useState(""),[l,b]=o.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[w,g]=o.useState(!1),{data:j}=u.useCurrentPage(),{mutateAsync:m,isPending:c}=u.useAddGlobalSchema(),{mutateAsync:y}=u.useTogglePageGlobalSchema(),O=q.useQueryClient();o.useEffect(()=>{N("edit"),b(n?{name:n.name,description:n.description,content:JSON.stringify(n.jsonld,null,2),enabledByDefaultForNewPages:!1}:{name:"",description:"",content:"",enabledByDefaultForNewPages:!1}),g(!1)},[t,n]),o.useEffect(()=>{const d=u.parseJSONWithPlaceholders(l.content);i(d.isValid?JSON.stringify(d.parsed,null,2):"")},[l.content]);const T=async()=>{if(!l.name||!l.content){F.toast.error("Please enter a name and content");return}const d=u.parseJSONWithPlaceholders(l.content);if(!d.isValid){F.toast.error("Invalid JSON-LD content");return}const P={name:l.name,jsonld:d.parsed,addToExistingPages:w,addToNewPages:l.enabledByDefaultForNewPages,description:l.description};n!=null&&n.primaryPageId&&(P.primaryPage=n.primaryPageId);const C=await m(P);j!=null&&j.id&&(C!=null&&C.id)&&!(n!=null&&n.primaryPageId)&&(await y({schemaId:C.id,pageId:j.id,enabled:!0}),O.invalidateQueries({queryKey:[u.ACTIONS.GET_LANGUAGE_PAGES,j.id]})),h()};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(p.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:l.name,onChange:d=>b({...l,name:d.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:l.description||"",onChange:d=>b({...l,description:d.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"new-content",children:"JSON-LD Content"}),e.jsxs(s.Tabs,{value:S,onValueChange:N,className:"w-full",children:[e.jsxs("div",{className:"mb-2 flex w-full items-center justify-between",children:[e.jsxs(s.TabsList,{className:"w-max",children:[e.jsxs(s.TabsTrigger,{value:"edit",className:"flex items-center gap-1",children:[e.jsx(p.Code,{className:"h-4 w-4"}),e.jsx("span",{children:"Edit"})]}),e.jsxs(s.TabsTrigger,{value:"preview",className:"flex items-center gap-1",disabled:!v,children:[e.jsx(p.Eye,{className:"h-4 w-4"}),e.jsx("span",{children:"Preview"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:S==="edit"&&e.jsx(s.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>b({...l,content:v}),disabled:!v,children:"Format"})})]}),e.jsxs(s.TabsContent,{value:"edit",children:[e.jsx(s.Textarea,{id:"new-content",value:l.content||"{}",onChange:d=>b({...l,content:d.target.value}),className:"font-mono text-sm",placeholder:"Enter JSON-LD markup...",rows:10}),!v&&l.content?e.jsx("p",{className:"pt-px text-xs text-red-500",children:"Invalid JSON-LD"}):e.jsx("p",{})]}),e.jsx(s.TabsContent,{value:"preview",children:e.jsx(s.Textarea,{id:"new-content",value:v||"{}",className:"bg-muted font-mono text-sm",placeholder:"{}",rows:10,readOnly:!0})})]})]}),!(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(s.Switch,{id:"add-to-all-existing",checked:w,onCheckedChange:d=>g(d)}),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(s.Switch,{id:"new-enabled",checked:l.enabledByDefaultForNewPages,onCheckedChange:d=>b({...l,enabledByDefaultForNewPages:d})}),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.jsxs("div",{className:"flex items-center justify-between pt-2",children:[e.jsx("div",{}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(s.Button,{disabled:c,variant:"outline",type:"button",size:"sm",onClick:()=>h(),children:"Cancel"}),e.jsx(s.Button,{disabled:c||!v,type:"button",size:"sm",onClick:T,children:c?e.jsxs(e.Fragment,{children:[e.jsx(p.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:h})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:()=>h(),children:t&&e.jsx(V,{id:t,onClose:h})}),V=({id:t,onClose:h})=>{const[n,S]=o.useState("edit"),[N,v]=o.useState(""),[i,l]=o.useState({name:"",content:"",description:"",enabledByDefaultForNewPages:!1}),[b,w]=o.useState(!1),[g,j]=o.useState(!1),[m,c]=o.useState(!1),{data:y}=z(),{mutateAsync:O,isPending:T}=u.useUpdateGlobalSchema(),{mutateAsync:d}=u.useApplySchemaToAllPages(),{mutateAsync:P}=u.useRemoveSchemaFromAllPages();o.useEffect(()=>{var x,L;if(S("edit"),t&&y){const A=y.find(a=>a.id===t);A&&(l({name:A.name,description:((x=A.metadata)==null?void 0:x.description)||"",content:JSON.stringify(A.jsonld,null,2),enabledByDefaultForNewPages:((L=A.metadata)==null?void 0:L.addToNewPages)||!1}),c(!!A.primaryPage))}},[t,y]),o.useEffect(()=>{const x=u.parseJSONWithPlaceholders(i.content);v(x.isValid?JSON.stringify(x.parsed,null,2):"")},[i.content]);const C=async()=>{if(!i.name||!i.content){F.toast.error("Please enter a name and content");return}const x=u.parseJSONWithPlaceholders(i.content);if(!x.isValid){F.toast.error("Invalid JSON-LD content");return}const L={id:t,name:i.name,jsonld:x.parsed,addToNewPages:i.enabledByDefaultForNewPages,description:i.description};await O(L),h()},J=async()=>{try{await d(t)}finally{w(!1)}},E=async()=>{try{await P(t)}finally{j(!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:[e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-name",children:"Schema Name"}),e.jsx(s.Input,{id:"edit-name",value:i.name,onChange:x=>l({...i,name:x.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:i.description||"",onChange:x=>l({...i,description:x.target.value}),placeholder:"Brief description of this schema"})]}),e.jsxs("div",{children:[e.jsx(s.Label,{htmlFor:"edit-content",children:"JSON-LD Content"}),e.jsxs(s.Tabs,{value:n,onValueChange:S,className:"w-full",children:[e.jsxs("div",{className:"mb-2 flex w-full items-center justify-between",children:[e.jsxs(s.TabsList,{className:"w-max",children:[e.jsxs(s.TabsTrigger,{value:"edit",className:"flex items-center gap-1",children:[e.jsx(p.Code,{className:"h-4 w-4"}),e.jsx("span",{children:"Edit"})]}),e.jsxs(s.TabsTrigger,{value:"preview",className:"flex items-center gap-1",disabled:!N,children:[e.jsx(p.Eye,{className:"h-4 w-4"}),e.jsx("span",{children:"Preview"})]})]}),e.jsx("div",{className:"flex items-center gap-2",children:n==="edit"&&e.jsx(s.Button,{type:"button",variant:"outline",size:"sm",onClick:()=>l({...i,content:N}),disabled:!N,children:"Format"})})]}),e.jsxs(s.TabsContent,{value:"edit",children:[e.jsx(s.Textarea,{id:"edit-content",value:i.content||"{}",onChange:x=>l({...i,content:x.target.value}),className:"font-mono text-sm",placeholder:"Enter JSON-LD markup...",rows:10}),!N&&i.content?e.jsx("p",{className:"pt-px text-xs text-red-500",children:"Invalid JSON-LD"}):e.jsx("p",{})]}),e.jsx(s.TabsContent,{value:"preview",children:e.jsx(s.Textarea,{id:"edit-content-preview",value:N||"{}",className:"bg-muted font-mono text-sm",placeholder:"{}",rows:10,readOnly:!0})})]})]}),!m&&e.jsxs(e.Fragment,{children:[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",variant:"outline",onClick:()=>w(!0),children:"Add to all existing"}),e.jsx(s.Button,{size:"sm",variant:"ghost",onClick:()=>j(!0),children:"Remove from all"})]})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(s.Switch,{id:"edit-enabled",checked:i.enabledByDefaultForNewPages,onCheckedChange:x=>l({...i,enabledByDefaultForNewPages:x})}),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.jsxs("div",{className:`flex items-center justify-between ${m?"pt-2":""}`,children:[m&&e.jsx("div",{}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(s.Button,{disabled:T,variant:"outline",type:"button",size:"sm",onClick:()=>h(),children:"Cancel"}),e.jsx(s.Button,{disabled:T||!N,type:"button",size:"sm",onClick:C,children:T?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader,{className:"h-4 w-4 animate-spin"})," Updating"]}):"Update Schema"})]})]})]}),e.jsx(s.AlertDialog,{open:b,onOpenChange:w,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:i.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:J,children:"Add to All"})]})]})}),e.jsx(s.AlertDialog,{open:g,onOpenChange:j,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:i.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:E,className:"bg-red-500 hover:bg-red-600",children:"Remove from All"})]})]})})]})};function Q(){const[t,h]=o.useState(!1),[n,S]=o.useState(void 0),[N,v]=o.useState(null),[i,l]=o.useState(null),[b,w]=o.useState(null),{data:g,isLoading:j}=z(),{selectedLang:m}=M.useLanguages(),{data:c}=u.useCurrentPage(),{data:y}=u.useLanguagePages(),{mutateAsync:O}=u.useDeleteGlobalSchema(),{mutateAsync:T}=u.useTogglePageGlobalSchema(),d=o.useMemo(()=>y==null?void 0:y.find(a=>!a.primaryPage&&a.lang===""),[y]),P=o.useMemo(()=>(d==null?void 0:d.globalJsonLds)||[],[d]),C=o.useMemo(()=>g?I.filter(g,r=>r.primaryPage===null&&r.lang==="").map(r=>{const f=m?I.find(g,D=>D.primaryPage===r.id&&D.lang===m):null;return{defaultSchema:r,languageVersion:f,displayItem:f||r,hasLanguageVersion:!!f}}):[],[g,m]),[J,E]=o.useState([]),x=J.length>0?J:(c==null?void 0:c.globalJsonLds)||[];o.useEffect(()=>{c!=null&&c.globalJsonLds&&E(c.globalJsonLds)},[c==null?void 0:c.globalJsonLds]);const L=async a=>{if(!(c!=null&&c.id))return;w(a);const r=x.includes(a),f=r?x.filter(D=>D!==a):[...x,a];E(f);try{await T({schemaId:a,pageId:c.id,enabled:!r})}catch{E(c.globalJsonLds)}finally{w(null)}},A=async a=>{w(a);try{await O(a)}finally{w(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"})]}),!m&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{type:"button",disabled:j,className:"rounded-full bg-primary p-1 text-primary-foreground hover:bg-primary/80",onClick:a=>{a.stopPropagation(),h(!0)},children:j?e.jsx(p.Loader,{className:"h-4 w-4 animate-spin"}):e.jsx(p.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:[(!g||(g==null?void 0:g.length)===0)&&!j&&e.jsx("div",{className:"flex items-center justify-center px-2 py-4 text-xs",children:"No shared JSON-LD found"}),C.map(({defaultSchema:a,displayItem:r,hasLanguageVersion:f})=>{var B,G;const D=x.includes(r.id),k=P.includes(a.id),R=f&&m?k:D;return e.jsxs(s.Card,{className:`relative border-gray-300 p-0 shadow-none transition-all ${b===r.id?"pointer-events-none":""}`,children:[b===r.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(p.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:[(f||!m)&&e.jsxs(s.Tooltip,{delayDuration:0,children:[e.jsx(s.TooltipTrigger,{asChild:!0,children:e.jsx("div",{children:e.jsx(s.Switch,{checked:R,onCheckedChange:()=>L(a.id),disabled:!!(f&&m)})})}),f&&m&&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:[r.name,f&&m&&e.jsxs("span",{className:"text-xs font-normal text-muted-foreground",children:["(",m,")"]})]}),((B=r==null?void 0:r.metadata)==null?void 0:B.description)&&e.jsx("p",{className:"mt-1 text-xs leading-none text-muted-foreground",children:(G=r==null?void 0:r.metadata)==null?void 0:G.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",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:()=>l(r.id),children:e.jsx(p.Eye,{className:"h-4 w-4"})})}),e.jsx(s.TooltipContent,{children:"View schema"})]}),(f||!m)&&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:()=>v(r.id),children:e.jsx(p.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(p.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:r.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:()=>A(r.id),className:"bg-red-500 text-white hover:bg-red-600",children:"Delete"})]})]})]})]})]})]})}),!f&&m&&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 '",m,"' language. Default language JSONLD will be used."]}),k&&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:()=>{S({name:a.name,description:a.description||"",jsonld:a.jsonld,languageCode:m,primaryPageId:a.id}),h(!0)},children:"Copy & Edit from default language"})]})})]},a.id)})]}),j&&e.jsx("div",{className:"flex items-center justify-center p-4",children:e.jsx(p.Loader,{className:"h-5 w-5 animate-spin"})})]}),e.jsx(U,{show:t,onClose:()=>{h(!1),S(void 0)},initialData:n}),e.jsx(H,{id:N,onClose:()=>v(null)}),e.jsx(W,{schema:g==null?void 0:g.find(a=>a.id===i),onClose:()=>l(null)})]})}const W=({schema:t,onClose:h})=>e.jsx(s.Dialog,{open:!!t,onOpenChange:h,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=Q;
@@ -1,5 +1,5 @@
1
1
  import { jsxs as i, jsx as o } from "react/jsx-runtime";
2
- import { L as d } from "./index-BSEA_u0X.js";
2
+ import { L as d } from "./index-CdUDr4JM.js";
3
3
  import { Input as v } from "@chaibuilder/sdk/ui";
4
4
  import { useState as x, useEffect as C } from "react";
5
5
  const y = (e) => {
@@ -1 +1 @@
1
- "use strict";const s=require("react/jsx-runtime"),u=require("./index-MlpQJHWW.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-vjYir4bk.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 h, jsx as n } from "react/jsx-runtime";
2
- import { u as l, a as m, t as r } from "./index-BSEA_u0X.js";
2
+ import { u as l, a as m, t as r } from "./index-CdUDr4JM.js";
3
3
  import { useTheme as d } from "@chaibuilder/sdk";
4
4
  import { Button as a } from "@chaibuilder/sdk/ui";
5
5
  const P = () => {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-MlpQJHWW.cjs"),d=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),l=()=>{const[t]=d.useTheme(),{mutate:o,isPending:i}=s.usePublishPages(),{mutateAsync:n,isPending:u}=s.useUpdateWebsiteSettings(),r=()=>{n({settings:{theme:t}})},c=async()=>{await n({settings:{theme:t}}),o({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(a.Button,{size:"sm",variant:"outline",disabled:i||u,onClick:r,children:"Save draft"}),e.jsx(a.Button,{size:"sm",disabled:i||u,onClick:c,children:"Publish"})]})};exports.default=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),s=require("./index-vjYir4bk.cjs"),d=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),l=()=>{const[t]=d.useTheme(),{mutate:o,isPending:i}=s.usePublishPages(),{mutateAsync:n,isPending:u}=s.useUpdateWebsiteSettings(),r=()=>{n({settings:{theme:t}})},c=async()=>{await n({settings:{theme:t}}),o({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(a.Button,{size:"sm",variant:"outline",disabled:i||u,onClick:r,children:"Save draft"}),e.jsx(a.Button,{size:"sm",disabled:i||u,onClick:c,children:"Publish"})]})};exports.default=l;
@@ -1,5 +1,5 @@
1
1
  import { jsx as e, jsxs as n } from "react/jsx-runtime";
2
- import { o as c } from "./index-BSEA_u0X.js";
2
+ import { o as c } from "./index-CdUDr4JM.js";
3
3
  import { Dialog as m, DialogContent as p, DialogHeader as d, DialogTitle as u, DialogDescription as h, DialogFooter as g, Button as r } from "@chaibuilder/sdk/ui";
4
4
  import { useState as f } from "react";
5
5
  const T = ({ page: i, onClose: a }) => {
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("./index-MlpQJHWW.cjs"),t=require("@chaibuilder/sdk/ui"),u=require("react"),d=({page:i,onClose:a})=>{const[s,n]=u.useState(!1),r=c.useUnmarkAsTemplate(),o=()=>{n(!0),r.mutate(i,{onSuccess:()=>{n(!1),a()},onError:()=>{n(!1)}})};return e.jsx(t.Dialog,{open:!0,onOpenChange:a,children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Unmark as template"}),e.jsx(t.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:"Are you sure you want to unmark this page as a template?"})]}),e.jsxs(t.DialogFooter,{className:s?"pointer-events-none opacity-75":"",children:[e.jsx(t.Button,{variant:"outline",onClick:l=>{l.stopPropagation(),a()},children:"Cancel"}),e.jsx(t.Button,{variant:"default",disabled:s,onClick:o,children:"Unmark as template"})]})]})})};exports.default=d;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),c=require("./index-vjYir4bk.cjs"),t=require("@chaibuilder/sdk/ui"),u=require("react"),d=({page:i,onClose:a})=>{const[s,n]=u.useState(!1),r=c.useUnmarkAsTemplate(),o=()=>{n(!0),r.mutate(i,{onSuccess:()=>{n(!1),a()},onError:()=>{n(!1)}})};return e.jsx(t.Dialog,{open:!0,onOpenChange:a,children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Unmark as template"}),e.jsx(t.DialogDescription,{className:"space-y-1 py-4 text-xs text-slate-500",children:"Are you sure you want to unmark this page as a template?"})]}),e.jsxs(t.DialogFooter,{className:s?"pointer-events-none opacity-75":"",children:[e.jsx(t.Button,{variant:"outline",onClick:l=>{l.stopPropagation(),a()},children:"Cancel"}),e.jsx(t.Button,{variant:"default",disabled:s,onClick:o,children:"Unmark as template"})]})]})})};exports.default=d;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),s=require("./index-MlpQJHWW.cjs"),e=require("@chaibuilder/sdk/ui"),o=({page:i,onClose:t})=>{const{mutate:r,isPending:l}=s.useUnpublishPage(),c=async()=>{r(i,{onSuccess:t})};return n.jsx(e.Dialog,{open:!!i,onOpenChange:t,children:n.jsxs(e.DialogContent,{children:[n.jsxs(e.DialogHeader,{children:[n.jsx(e.DialogTitle,{children:"Confirm action"}),n.jsxs(e.DialogDescription,{children:[s.CONTENT.UNPUBLISH_MSG," ",n.jsx("b",{children:(i==null?void 0:i.name)??(i==null?void 0:i.slug)}),"?"]})]}),n.jsxs(e.DialogFooter,{children:[n.jsx(e.Button,{variant:"outline",onClick:t,children:"Cancel"}),n.jsx(e.Button,{variant:"destructive",disabled:l,onClick:c,children:l?s.CONTENT.UPDATING:s.CONTENT.UNPUBLISH})]})]})})};exports.default=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),s=require("./index-vjYir4bk.cjs"),e=require("@chaibuilder/sdk/ui"),o=({page:i,onClose:t})=>{const{mutate:r,isPending:l}=s.useUnpublishPage(),c=async()=>{r(i,{onSuccess:t})};return n.jsx(e.Dialog,{open:!!i,onOpenChange:t,children:n.jsxs(e.DialogContent,{children:[n.jsxs(e.DialogHeader,{children:[n.jsx(e.DialogTitle,{children:"Confirm action"}),n.jsxs(e.DialogDescription,{children:[s.CONTENT.UNPUBLISH_MSG," ",n.jsx("b",{children:(i==null?void 0:i.name)??(i==null?void 0:i.slug)}),"?"]})]}),n.jsxs(e.DialogFooter,{children:[n.jsx(e.Button,{variant:"outline",onClick:t,children:"Cancel"}),n.jsx(e.Button,{variant:"destructive",disabled:l,onClick:c,children:l?s.CONTENT.UPDATING:s.CONTENT.UNPUBLISH})]})]})})};exports.default=o;
@@ -1,5 +1,5 @@
1
1
  import { jsx as n, jsxs as l } from "react/jsx-runtime";
2
- import { l as d, C as r } from "./index-BSEA_u0X.js";
2
+ import { l as d, C as r } from "./index-CdUDr4JM.js";
3
3
  import { Dialog as h, DialogContent as a, DialogHeader as u, DialogTitle as m, DialogDescription as U, DialogFooter as D, Button as e } from "@chaibuilder/sdk/ui";
4
4
  const f = ({ page: i, onClose: o }) => {
5
5
  const { mutate: s, isPending: t } = d(), c = async () => {
@@ -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-MlpQJHWW.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-vjYir4bk.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;
@@ -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-BSEA_u0X.js";
7
+ import { p as v, T as _ } from "./index-CdUDr4JM.js";
8
8
  const b = [
9
9
  {
10
10
  title: "mobile_xs_title",
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.0",
6
+ "version": "0.15.2",
7
7
  "type": "module",
8
8
  "files": [
9
9
  "dist"
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),X=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),L=require("lodash-es"),p=require("lucide-react"),d=require("react"),he=require("react-dropzone"),A=require("sonner"),Z=require("./image-compression-DZ9WMmyn.cjs"),k=require("@tanstack/react-query"),j=require("./index-MlpQJHWW.cjs"),xe=d.createContext(null),K={didCatch:!1,error:null};class fe extends d.Component{constructor(r){super(r),this.resetErrorBoundary=this.resetErrorBoundary.bind(this),this.state=K}static getDerivedStateFromError(r){return{didCatch:!0,error:r}}resetErrorBoundary(){const{error:r}=this.state;if(r!==null){for(var o,s,c=arguments.length,i=new Array(c),u=0;u<c;u++)i[u]=arguments[u];(o=(s=this.props).onReset)===null||o===void 0||o.call(s,{args:i,reason:"imperative-api"}),this.setState(K)}}componentDidCatch(r,o){var s,c;(s=(c=this.props).onError)===null||s===void 0||s.call(c,r,o)}componentDidUpdate(r,o){const{didCatch:s}=this.state,{resetKeys:c}=this.props;if(s&&o.error!==null&&pe(r.resetKeys,c)){var i,u;(i=(u=this.props).onReset)===null||i===void 0||i.call(u,{next:c,prev:r.resetKeys,reason:"keys"}),this.setState(K)}}render(){const{children:r,fallbackRender:o,FallbackComponent:s,fallback:c}=this.props,{didCatch:i,error:u}=this.state;let v=r;if(i){const N={error:u,resetErrorBoundary:this.resetErrorBoundary};if(typeof o=="function")v=o(N);else if(s)v=d.createElement(s,N);else if(c!==void 0)v=c;else throw u}return d.createElement(xe.Provider,{value:{didCatch:i,error:u,resetErrorBoundary:this.resetErrorBoundary}},v)}}function pe(){let n=arguments.length>0&&arguments[0]!==void 0?arguments[0]:[],r=arguments.length>1&&arguments[1]!==void 0?arguments[1]:[];return n.length!==r.length||n.some((o,s)=>!Object.is(o,r[s]))}const ge=()=>{const n=j.useAssetsApiUrl(),r=k.useQueryClient(),o=j.useFetch();return k.useMutation({mutationFn:async s=>{const c=s.map(async u=>o(n,{action:j.ACTIONS.UPLOAD_ASSET,data:u}));return await Promise.all(c)},onSuccess:s=>{var c;if(s!=null&&s.some(i=>i.error))throw new Error(((c=s==null?void 0:s.find(i=>i.error))==null?void 0:c.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[j.ACTIONS.GET_ASSETS]});const i=s==null?void 0:s.length;A.toast.success(`${i===1?"Asset":i+" Assets"} uploaded successfully`)}},onError:()=>{A.toast.error("Failed to upload asset")}})},je=()=>{const n=j.useAssetsApiUrl(),r=k.useQueryClient(),o=j.useFetch();return k.useMutation({mutationFn:async s=>o(n,{action:j.ACTIONS.DELETE_ASSET,data:{id:s}}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);r.invalidateQueries({queryKey:[j.ACTIONS.GET_ASSETS]}),A.toast.success("Asset deleted successfully")},onError:()=>{A.toast.error("Failed to delete asset")}})},ve=()=>{const n=j.useAssetsApiUrl(),r=k.useQueryClient(),o=j.useFetch();return k.useMutation({mutationFn:async s=>o(n,{action:j.ACTIONS.UPDATE_ASSET,data:s}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);r.invalidateQueries({queryKey:[j.ACTIONS.GET_ASSETS]}),A.toast.success("Asset updated successfully")},onError:()=>{A.toast.error("Failed to update asset")}})};function ye({currentPage:n,totalPages:r,onPageChange:o,pageRangeDisplayed:s=3,showPageInput:c=!0,className:i=""}){const[u,v]=d.useState(String(n)),N=d.useMemo(()=>{const l=Math.floor(s/2);let m=Math.max(1,n-l),x=Math.min(r,n+l);x-m+1<s&&(m===1?x=Math.min(r,m+s-1):x===r&&(m=Math.max(1,x-s+1)));const y=[];m>1&&(y.push(1),m>2&&y.push("..."));for(let b=m;b<=x;b++)y.push(b);return x<r&&(x<r-1&&y.push("..."),y.push(r)),y},[n,r,s]),g=l=>{l!==n&&l>=1&&l<=r&&(o(l),v(String(l)))},w=()=>{n>1&&g(n-1)},S=()=>{n<r&&g(n+1)},C=()=>{const l=Number(u);!isNaN(l)&&l>=1&&l<=r&&g(l)},f=l=>{l.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${i}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:w,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(p.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((l,m)=>{if(l==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const x=l,y=x===n;return e.jsx(a.Button,{variant:y?"default":"outline",size:"sm",onClick:()=>g(x),className:y?"border-blue-600 bg-blue-600 px-3 py-1 text-sm text-white":"border px-3 py-1 text-sm hover:bg-gray-50 hover:text-black",children:x},x)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:S,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(p.ChevronRight,{className:" h-4 w-4"})]})]}),c&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-muted-foreground",children:"Go to"}),e.jsx(a.Input,{type:"number",min:1,max:r,value:u,onChange:l=>{const m=l.target.value.replace(/[^\d]/g,"");v(m)},onKeyDown:f,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:u===""||Number(u)<1||Number(u)>r,children:"Go"})]})]})}const Ne=(n={})=>{const r=j.useAssetsApiUrl(),o=j.useFetch(),{search:s,page:c=1,limit:i=30}=n;return k.useQuery({queryKey:[j.ACTIONS.GET_ASSETS,s,c,i],queryFn:async()=>{const u=await o(r,{action:j.ACTIONS.GET_ASSETS,data:{search:s,page:c,limit:i}});return u.page=c,u.limit=i,u},staleTime:1/0,retry:1})},be=n=>{const r=j.useAssetsApiUrl(),o=j.useFetch();return k.useQuery({queryKey:[j.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await o(r,{action:j.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function we(n){const r=isNaN(n)?0:typeof n=="number"?n:parseInt(n);return r?r<1024?`${r.toFixed(2)} B`:r<1024*1024?`${(r/1024).toFixed(2)} KB`:`${(r/(1024*1024)).toFixed(2)} MB`:"0 B"}function V(n){if(!n)return"N/A";const r=new Date(n);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(r)}function H(n,r){let o=n,s=r==null?void 0:r.description;return(!s||typeof s!="string")&&(s=""),(!o||typeof o!="string")&&(o=""),o!==s}const Ce=({assetId:n,onBack:r,onEdit:o,onSave:s,isSaving:c})=>{var S,C,f;const{data:i,isLoading:u,isError:v}=be(n||""),[N,g]=d.useState(""),w=async(l,m)=>{try{await navigator.clipboard.writeText(l),A.toast.success(`${m} copied to clipboard`)}catch(x){A.toast.error(`Failed to copy ${m}`,{description:x==null?void 0:x.message})}};return d.useEffect(()=>{i!=null&&i.description&&g(i.description)},[i]),u?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(p.Loader,{className:"h-8 w-8 animate-spin"})}):v||!(i!=null&&i.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(p.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:"No Asset Found"}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:v?"There was an error loading the asset. Please try again later.":"The asset you're looking for doesn't exist or has been removed."}),e.jsxs("div",{className:"flex justify-center gap-4",children:[e.jsx(a.Button,{variant:"outline",onClick:r,children:"Back to Assets"}),v&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:"Try Again"})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:r,disabled:c,children:[e.jsx(p.ChevronLeft,{className:"h-4 w-4"}),"Back to Assets"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:c,children:"Cancel"}),e.jsxs(a.Button,{variant:"outline",onClick:()=>w(i.url,"Asset URL"),disabled:c,children:[e.jsx(p.Copy,{className:"h-4 w-4 mr-2"}),"Copy URL"]}),e.jsxs(a.Button,{variant:"default",onClick:()=>o(i),disabled:c,children:[e.jsx(p.Pencil,{className:"h-4 w-4"}),"Edit Image"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:`${i.url}?v=${((S=i.metadata)==null?void 0:S.updatedAt)||i.createdAt}`,alt:i.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(a.Label,{className:"w-full text-center",children:"Details"}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:"File Name",value:i.name},{label:"Type",value:i.type,capitalize:!0},{label:"Format",value:((C=i.metadata)==null?void 0:C.format)||i.type,capitalize:!0},{label:"Size",value:we(i.size)},{label:"Dimensions",value:`${i.width||0} × ${i.height||0}`},{label:"Created",value:V(i.createdAt)},{label:"Updated",value:V(((f=i.metadata)==null?void 0:f.updatedAt)||i.createdAt)},{label:"URL",value:i.url,copyable:!0}].map(l=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(a.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:l.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(l.capitalize?" capitalize":""),children:l.value}),l.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>w(l.value,l.label),children:e.jsx(p.Link,{className:"h-3 w-3"})})]})]},l.label))})]}),i.usedOn&&i.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:"Used On"}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:i.usedOn.map((l,m)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:l.name}),e.jsxs("div",{className:"text-gray-500",children:["(",l.slug,")"]})]},m))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(a.Label,{className:"w-full text-center",children:"Description"}),e.jsx(a.Textarea,{id:"description",value:N,placeholder:"Enter a description for the asset",onChange:l=>g(l.target.value),rows:3,disabled:c,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>s(N),disabled:c||!H(N,i),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${c||!H(N,i)?"opacity-50 cursor-not-allowed":""}`,children:c?e.jsxs(e.Fragment,{children:[e.jsx(p.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):"Save"})})]})]})]})]})},Ae=d.lazy(()=>Promise.resolve().then(()=>require("./image-editor-BWLJT1mr.cjs"))),Se=25*1024*1024,Te=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:o,isUploadingAsset:s,onUploaded:c})=>{const[i,u]=d.useState(()=>{const f=localStorage.getItem("chai_optimize_images");return f!==null?f==="true":!0});d.useEffect(()=>{localStorage.setItem("chai_optimize_images",i.toString())},[i]);const v=n||s,N=d.useCallback(async f=>{try{const l=f;if(!l.every(b=>b.type.startsWith("image/")))return A.toast.error("Invalid file type. Please upload a valid file."),Promise.reject(new Error("Invalid file type"));const m=l.map(async b=>{let z=b;return b.type.startsWith("image/")&&(z=await Z.compressImageIfNeeded(b)),new Promise((M,D)=>{const F=new FileReader;F.readAsDataURL(z),F.onload=async()=>{M({file:F.result,folderId:void 0,name:b.name,optimize:i})},F.onerror=()=>D(null)})}),x=await Promise.all(m),y=await o(x);return(y==null?void 0:y.length)===1&&c(y[0]),y}catch(l){return Promise.reject(l)}},[o,i,c]),g=f=>{const l=[];let m=0;return f.forEach(x=>{x.size>Se?m++:l.push(x)}),m>0&&A.toast.error(`${m===1&&f.length===1?"File":m+(m===1?" file":" files")} exceed the maximum size limit of 10MB.`),L.isEmpty(l)?[]:N(l)},{getRootProps:w,getInputProps:S,isDragActive:C}=he.useDropzone({onDrop:g,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||s,multiple:!0});return e.jsx("div",{className:`flex h-[60px] w-full flex-col items-center justify-center rounded-lg border-2 border-dashed border-slate-300 p-0 py-2 hover:border-black/50 ${v?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...w(),className:X.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",v?"items-start":"items-center",C?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...S()}),v?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"flex items-center justify-center gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(p.Loader,{className:"h-4 w-4 animate-spin text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:n?"Updating file...":"Uploading file..."}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:["Please wait while we ",n?"update":"upload"," your file..."]})]})]})}):e.jsxs("div",{className:"flex w-full items-center justify-between px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"flex items-center justify-between gap-2 leading-tight",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full border border-indigo-500 bg-indigo-100 p-2",children:e.jsx(p.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:["Drop your file here or"," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:"browse"})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:["Accepted file types: ",e.jsx("span",{className:"capitalize text-indigo-400",children:r.join(", ")})]})})]})]})}),e.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:["Optimization:"," ",e.jsx("span",{className:i?"text-indigo-600":"text-gray-400",children:i?"On":"Off"})]}),e.jsx(a.Switch,{checked:i,onCheckedChange:f=>{u(f)},onClick:f=>{f.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`flex cursor-help items-center text-amber-500 ${i?"invisible":""}`,children:e.jsx(p.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsxs("p",{className:"text-xs text-white",children:["Warning: Unoptimized images may affect ",e.jsx("br",{})," performance and page load times"]})})]})})]})]})]})})};function Ee({close:n,onSelect:r,mode:o="image",assetId:s}){const u=d.useMemo(()=>[o],[o]),[v,N]=d.useState(null),[g,w]=d.useState(null),[S,C]=d.useState(null),[f,l]=d.useState({show:!1,file:""}),[m,x]=d.useState(!1),[y,b]=d.useState(s?"details":"grid"),[z,M]=d.useState(""),[D,F]=d.useState(""),[q,P]=d.useState(1),[Q]=d.useState(30),[T,$]=d.useState([]);d.useEffect(()=>{s&&(N(s),b("details"))},[s]),d.useEffect(()=>{const t=setTimeout(()=>{M(D),P(1)},300);return()=>clearTimeout(t)},[D]);const{data:B,isLoading:O,refetch:J}=Ne({search:z.toLowerCase().trim(),page:q,limit:Q}),I=(B==null?void 0:B.assets)||[],Y=(B==null?void 0:B.total)||0,E=Math.ceil(Y/Q);d.useEffect(()=>{O||E<=0||P(t=>t>E?E:t<1?1:t)},[O,E]);const ee=(I==null?void 0:I.length)>0,{mutate:te}=je(),{mutateAsync:G,isPending:se}=ge(),{mutate:R,isPending:ie}=ve(),W=d.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,E));h!==q&&P(h)},[E,q]),re=t=>{F(t.target.value)},ae=d.useCallback(t=>{$(h=>L.find(h,{id:t.id})?[]:[t])},[!1]),le=d.useCallback(()=>{$([])},[]),_=t=>{(t==null?void 0:t.length)!==0&&(r(L.pick(L.first(t||T),["id","url","width","height","description"])),n())},ne=async t=>{w(t)},oe=async()=>{g&&(C(g==null?void 0:g.id),await te(g.id,{onSuccess:()=>{C(null),w(null)},onError:()=>{C(null)}}),w(null))},ce=t=>{N(t.id),b("details")},de=async(t,h)=>{try{const U=localStorage.getItem("chai_optimize_images")!=="false";h?(await G([{file:t,folderId:void 0,name:f.name||"",optimize:U}]),l({show:!1,file:""})):(await R({id:f.id||"",file:t}),l({show:!1,file:""}))}catch(U){console.error("Error saving edited image:",U)}},ue=d.useCallback(t=>{$([t])},[]),me=d.useCallback(t=>{W(t)},[W]);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex h-[80vh] max-h-[1232px] w-[80vw] max-w-[1232px] flex-col space-y-4",children:[e.jsx("h1",{className:"text-lg font-medium",children:"Digital Asset Manager"}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Te,{maxFileSize:10,allowedTypes:u,uploadAssets:G,isUpdatingAsset:ie,isUploadingAsset:se,onUploaded:ue}),e.jsxs("div",{className:"relative flex flex-1 flex-col gap-y-3 overflow-hidden rounded-lg border p-2",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2",children:[e.jsx(p.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${D.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:"Search assets...",onChange:re,value:D,className:"pl-8"})]}),e.jsxs("div",{className:"flex items-center gap-x-2",children:[T.length>0?e.jsx("div",{className:"flex items-center justify-between",children:e.jsxs("div",{className:"flex items-center gap-2",children:[T.length>0&&e.jsx(e.Fragment,{children:e.jsx(a.Button,{variant:"outline",size:"sm",onClick:()=>le(),title:"Clear selection",children:"Clear"})}),e.jsx(a.Button,{size:"sm",onClick:()=>_(T),disabled:T.length===0,children:"Select Asset"})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>J(),children:e.jsx(p.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:O?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"}),e.jsx("div",{className:"h-64 w-full animate-pulse rounded bg-gray-200"})]}):!O&&!ee?e.jsxs("div",{className:"flex h-full flex-col items-center justify-center rounded-lg border",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(p.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:"No assets found"}),e.jsx("div",{className:"text-sm text-muted-foreground",children:z.length>0?"No assets found for your search: "+z:"Start uploading assets to get started"}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:I==null?void 0:I.map(t=>e.jsxs("div",{className:X.mergeClasses("group relative flex max-h-[180px] max-w-[180px] cursor-pointer flex-col justify-between overflow-hidden rounded-lg border-2 transition-all",T.some(h=>h.id===t.id)?"border-blue-500":"hover:border-black/90",S&&(g==null?void 0:g.id)===t.id?"pointer-events-none opacity-50":"",S===t.id?"pointer-events-none opacity-50":""),onClick:()=>ae(t),onDoubleClick:()=>_([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[S===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(p.Loader,{className:"h-8 w-8 animate-spin text-white"})}):null,t.type==="image"?e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:`h-full min-h-[80px] w-full object-contain ${T.some(h=>h.id===t.id)?"":"group-hover:blur group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex h-full items-center justify-center",children:[e.jsx(p.Film,{className:"h-12 w-12 text-muted-foreground"}),t.thumbnailUrl&&e.jsx("img",{src:`${t.thumbnailUrl||"/placeholder.svg"}?v=${(t==null?void 0:t.updatedAt)||t.createdAt}`,alt:t.name,className:"absolute inset-0 h-full w-full object-cover"})]})]}),e.jsxs("div",{className:"flex items-end justify-between border-t-[1px] border-black/10 bg-white px-2 py-1",children:[e.jsx("div",{className:"truncate text-xs leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"flex items-center justify-between whitespace-nowrap text-[9px] font-light text-muted-foreground",children:e.jsx("span",{children:Z.formatFileSize((t==null?void 0:t.size)||0)})})]}),!T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute inset-0 flex items-center justify-center opacity-0 transition-opacity group-hover:opacity-100",children:e.jsxs("div",{className:"grid grid-cols-4 gap-2 p-2",children:[e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ce(t)},children:e.jsx(p.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:"View Details"})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),navigator.clipboard.writeText(t.url),A.toast.success("Asset URL copied to clipboard")},children:e.jsx(p.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:"Copy URL"})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),l({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(p.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:"Edit Image"})})]})}),e.jsx(a.TooltipProvider,{children:e.jsxs(a.Tooltip,{children:[e.jsx(a.TooltipTrigger,{asChild:!0,children:e.jsx(a.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:h=>{h.stopPropagation(),ne(t)},children:e.jsx(p.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:"Delete Asset"})})]})})]})}),T.some(h=>h.id===t.id)&&e.jsx("div",{className:"absolute right-1 top-1 h-max rounded-full border border-white bg-blue-500 p-1",children:e.jsx(p.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),E>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(fe,{fallback:e.jsx("div",{className:"text-red-500",children:"Error loading pagination"}),children:e.jsx(ye,{currentPage:q,totalPages:E,onPageChange:me,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(Ce,{assetId:v||s||"",onBack:()=>{b("grid"),N(null)},onEdit:t=>{l({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(v){x(!0);try{const h=I.find(U=>U.id===v);h&&await R(L.merge(h,{description:t}))}finally{x(!1)}}},isSaving:m})]}),f.show&&e.jsx(d.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(p.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ae,{imageUrl:f.file,onSave:de,onClose:()=>l({show:!1,file:""}),defaultSavedImageName:f.name,isEditing:!!f.id})}),g&&e.jsx(a.Dialog,{open:!!g,onOpenChange:()=>w(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:"Delete Asset"}),e.jsxs(a.DialogDescription,{children:['Are you sure you want to delete "',g.name,'"? This action cannot be undone.']})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>w(null),children:"Cancel"}),e.jsx(a.Button,{variant:"destructive",onClick:oe,children:"Delete"})]})]})})]})}exports.default=Ee;