@chaibuilder/pages 0.16.13 → 0.16.14
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.
- package/dist/{2AITGKQY-D1mM4eEh.js → 2AITGKQY-B7xwscsX.js} +2 -2
- package/dist/{2AITGKQY-AK2WgbeT.cjs → 2AITGKQY-B9AnRLq_.cjs} +1 -1
- package/dist/{NCMVHL6D-BeRsWdGV.js → NCMVHL6D-B1mwht0Q.js} +4 -4
- package/dist/{NCMVHL6D-DItDf9IY.cjs → NCMVHL6D-CRMC-wXy.cjs} +1 -1
- package/dist/{ZDWCUMSJ-COSBY-at.cjs → ZDWCUMSJ-BqqPEOij.cjs} +1 -1
- package/dist/{ZDWCUMSJ-D6caRaY7.js → ZDWCUMSJ-CxKNtXtp.js} +1 -1
- package/dist/{add-new-language-page-CQcFi0Tp.cjs → add-new-language-page-D2a6GK-7.cjs} +1 -1
- package/dist/{add-new-language-page-nnaUe-qk.js → add-new-language-page-DD0qvJJs.js} +2 -2
- package/dist/{add-new-page-DxObnvo_.cjs → add-new-page-01GDCaa4.cjs} +1 -1
- package/dist/{add-new-page-Ba1fq6LH.js → add-new-page-CYtuChN1.js} +1 -1
- package/dist/ai-panel-content-DfdnvlS8.js +123 -0
- package/dist/ai-panel-content-Ouz6pu_0.cjs +1 -0
- package/dist/ai-panel-default-lang-Bi2fH1so.js +317 -0
- package/dist/ai-panel-default-lang-N1pb8rzQ.cjs +3 -0
- package/dist/{ai-panel-other-lang-B4euTuod.js → ai-panel-other-lang-2JPRSyO1.js} +10 -9
- package/dist/ai-panel-other-lang-BysU1464.cjs +1 -0
- package/dist/ai-prompt-input-DadL_cng.js +1071 -0
- package/dist/ai-prompt-input-JeIqWZco.cjs +1 -0
- package/dist/{ai-translation-prompt-CVuPbgXw.js → ai-translation-prompt-B0si-R0R.js} +1 -1
- package/dist/{ai-translation-prompt-Ip7w2_Ey.cjs → ai-translation-prompt-CQb1L7NM.cjs} +1 -1
- package/dist/{delete-page-CbY8q5M3.cjs → delete-page-C8Nt7IYF.cjs} +1 -1
- package/dist/{delete-page-SX9X35nA.js → delete-page-_96Di9yN.js} +1 -1
- package/dist/{digital-asset-manager-CIMo79Di.cjs → digital-asset-manager-B5FQGtGY.cjs} +1 -1
- package/dist/{digital-asset-manager-SAFNO_mx.js → digital-asset-manager-jfnmWRJj.js} +1 -1
- package/dist/{duplicate-page-CXK2HcxD.cjs → duplicate-page-BNjfZ7Wd.cjs} +1 -1
- package/dist/{duplicate-page-5SwLvmkX.js → duplicate-page-CERjaPIW.js} +9 -9
- package/dist/{dynamic-page-selector-Crd3y4Hk.cjs → dynamic-page-selector-Bpz_bvRu.cjs} +1 -1
- package/dist/{dynamic-page-selector-DfcuTqRN.js → dynamic-page-selector-XEWV4iCf.js} +1 -1
- package/dist/{index-Bz7smSC0.cjs → index-Pdb5tSRL.cjs} +2 -2
- package/dist/{index-EnM7J19_.js → index-e9WlBH0R.js} +70 -70
- package/dist/index.cjs +1 -1
- package/dist/index.js +4 -4
- package/dist/{json-diff-viewer-CDwpbuag.js → json-diff-viewer-DyvKomxd.js} +1 -1
- package/dist/{json-diff-viewer-D34kDA_c.cjs → json-diff-viewer-H-2DkGza.cjs} +1 -1
- package/dist/{lang-panel-CUIeO5bb.js → lang-panel-BWP5A-FD.js} +2 -2
- package/dist/{lang-panel-CaFrYllL.cjs → lang-panel-DcZ7u4em.cjs} +1 -1
- package/dist/{mark-as-template-D0dLQaIB.js → mark-as-template-1oVraE1x.js} +1 -1
- package/dist/{mark-as-template-v182tmN6.cjs → mark-as-template-B_FyVRRO.cjs} +1 -1
- package/dist/{no-language-page-content-ByRFD_qA.js → no-language-page-content-CEci_4j7.js} +1 -1
- package/dist/{no-language-page-content-Bk4fEx_p.cjs → no-language-page-content-JO4YYUx7.cjs} +1 -1
- package/dist/{page-creator-BnvaGZVI.cjs → page-creator-BGgoOA92.cjs} +1 -1
- package/dist/{page-creator-Bh0IUGR3.js → page-creator-DJJFl7px.js} +2 -2
- package/dist/{page-lock-request-C2b1kqyA.cjs → page-lock-request-BoYzkcyt.cjs} +1 -1
- package/dist/{page-lock-request-CaNqxfD6.js → page-lock-request-WzpcD2ZN.js} +6 -6
- package/dist/{page-locked-by-dialog--WLDdkw9.js → page-locked-by-dialog-Djvjp2Hx.js} +1 -1
- package/dist/{page-locked-by-dialog-90ElC8aG.cjs → page-locked-by-dialog-bvI27OZ6.cjs} +1 -1
- package/dist/{page-manager-new-SNRQn7Az.cjs → page-manager-new-CMfGorRQ.cjs} +1 -1
- package/dist/{page-manager-new-Bo4-zwfW.js → page-manager-new-DmVX0qLk.js} +14 -14
- package/dist/{page-manager-search-and-filter-BETHSa3y.js → page-manager-search-and-filter-DbUoW8Di.js} +1 -1
- package/dist/{page-manager-search-and-filter-hyUIHOD_.cjs → page-manager-search-and-filter-Dgh8iyGp.cjs} +1 -1
- package/dist/{page-revisions-content-BCMjvZRZ.cjs → page-revisions-content-CwoXXE53.cjs} +1 -1
- package/dist/{page-revisions-content-VWthKL7O.js → page-revisions-content-CxEJGxLY.js} +18 -18
- package/dist/pages.css +1 -1
- package/dist/{publish-pages-content-CaBwfekc.cjs → publish-pages-content-BRu7qwAo.cjs} +1 -1
- package/dist/{publish-pages-content-6N7aEcM1.js → publish-pages-content-CfAlmivf.js} +6 -6
- package/dist/{save-to-lib-YYBxY7MV.js → save-to-lib-BCaBfh0I.js} +1 -1
- package/dist/{save-to-lib-CtGpDkC6.cjs → save-to-lib-DpyJA0y1.cjs} +1 -1
- package/dist/{selected-block-display-DdW-DWF1.js → selected-block-display-BmNhvYKu.js} +1 -1
- package/dist/{selected-block-display-BEbuJn0l.cjs → selected-block-display-CqnwyGRp.cjs} +1 -1
- package/dist/{seo-panel-CqJDhbj-.js → seo-panel-BH8fcGqr.js} +1 -1
- package/dist/{seo-panel-B9P7fXjo.cjs → seo-panel-D-nKfsRJ.cjs} +1 -1
- package/dist/server.cjs +1 -1
- package/dist/server.js +39 -39
- package/dist/{shared-json-ld-CyxmC9y5.cjs → shared-json-ld-m_OsVv8h.cjs} +1 -1
- package/dist/{shared-json-ld-DxEPILj_.js → shared-json-ld-zTDoJzUv.js} +1 -1
- package/dist/{slug-input-j5z5ZQn9.js → slug-input-CumDDlCk.js} +1 -1
- package/dist/{slug-input-RNiSrU3p.cjs → slug-input-vzNtu37S.cjs} +1 -1
- package/dist/{theme-panel-footer-CCsiDIVl.cjs → theme-panel-footer-CKccBcd9.cjs} +1 -1
- package/dist/{theme-panel-footer-DD2yalfG.js → theme-panel-footer-CdUmjB-e.js} +1 -1
- package/dist/{unmark-as-template-B2hKhAHn.js → unmark-as-template-6ew-7bf8.js} +1 -1
- package/dist/{unmark-as-template-DXjLbqOM.cjs → unmark-as-template-BNFOsxIg.cjs} +1 -1
- package/dist/{unpublish-page-BdJScWMX.cjs → unpublish-page-BZQpTpU3.cjs} +1 -1
- package/dist/{unpublish-page-BvB1PGSz.js → unpublish-page-BomE76Wg.js} +1 -1
- package/dist/{web-preview-BI4jd0O7.cjs → web-preview-C5QTX7bS.cjs} +1 -1
- package/dist/{web-preview-CwVpkcwU.js → web-preview-jo8lnpEx.js} +1 -1
- package/package.json +1 -1
- package/dist/ai-panel-content-B2AgBWqo.cjs +0 -1
- package/dist/ai-panel-content-M1UnzG_f.js +0 -54
- package/dist/ai-panel-default-lang-CHOFEwmV.js +0 -313
- package/dist/ai-panel-default-lang-sy6vkQJh.cjs +0 -3
- package/dist/ai-panel-other-lang-BwjSDD3L.cjs +0 -1
- package/dist/ai-prompt-input-B_NRADBT.js +0 -988
- package/dist/ai-prompt-input-DcyVXcLG.cjs +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),r=require("./selected-block-display-CqnwyGRp.cjs"),d=require("react"),R=require("cmdk"),b=require("lucide-react"),ye=require("@radix-ui/react-dialog"),Ne=require("@radix-ui/react-dropdown-menu"),we=require("@radix-ui/react-hover-card"),J=require("class-variance-authority"),Se=require("@radix-ui/react-select"),Ie=require("@chaibuilder/sdk"),U=require("./ai-panel-content-Ouz6pu_0.cjs");function q(t){const s=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(t){for(const a in t)if(a!=="default"){const n=Object.getOwnPropertyDescriptor(t,a);Object.defineProperty(s,a,n.get?n:{enumerable:!0,get:()=>t[a]})}}return s.default=t,Object.freeze(s)}const p=q(d),z=q(ye),w=q(Ne),G=q(we),I=q(Se),Ce=z.Root,ke=z.Trigger,Re=z.Portal,Q=p.forwardRef(({className:t,...s},a)=>e.jsx(z.Overlay,{ref:a,className:r.cn("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",t),...s}));Q.displayName=z.Overlay.displayName;const Z=p.forwardRef(({className:t,children:s,...a},n)=>e.jsxs(Re,{children:[e.jsx(Q,{}),e.jsxs(z.Content,{ref:n,className:r.cn("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",t),...a,children:[s,e.jsxs(z.Close,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[e.jsx(b.X,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Close"})]})]})]}));Z.displayName=z.Content.displayName;const ee=p.forwardRef(({className:t,...s},a)=>e.jsx(z.Title,{ref:a,className:r.cn("text-lg font-semibold leading-none tracking-tight",t),...s}));ee.displayName=z.Title.displayName;const De=p.forwardRef(({className:t,...s},a)=>e.jsx(z.Description,{ref:a,className:r.cn("text-sm text-muted-foreground",t),...s}));De.displayName=z.Description.displayName;const te=p.forwardRef(({className:t,...s},a)=>e.jsx(R.Command,{ref:a,className:r.cn("flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",t),...s}));te.displayName=R.Command.displayName;const se=p.forwardRef(({className:t,...s},a)=>e.jsxs("div",{className:"flex items-center border-b px-3","cmdk-input-wrapper":"",children:[e.jsx(b.Search,{className:"mr-2 h-4 w-4 shrink-0 opacity-50"}),e.jsx(R.Command.Input,{ref:a,className:r.cn("flex h-11 w-full rounded-md bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",t),...s})]}));se.displayName=R.Command.Input.displayName;const ae=p.forwardRef(({className:t,...s},a)=>e.jsx(R.Command.List,{ref:a,className:r.cn("max-h-[300px] overflow-y-auto overflow-x-hidden",t),...s}));ae.displayName=R.Command.List.displayName;const ze=p.forwardRef((t,s)=>e.jsx(R.Command.Empty,{ref:s,className:"py-6 text-center text-sm",...t}));ze.displayName=R.Command.Empty.displayName;const ne=p.forwardRef(({className:t,...s},a)=>e.jsx(R.Command.Group,{ref:a,className:r.cn("overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",t),...s}));ne.displayName=R.Command.Group.displayName;const Pe=p.forwardRef(({className:t,...s},a)=>e.jsx(R.Command.Separator,{ref:a,className:r.cn("-mx-1 h-px bg-border",t),...s}));Pe.displayName=R.Command.Separator.displayName;const oe=p.forwardRef(({className:t,...s},a)=>e.jsx(R.Command.Item,{ref:a,className:r.cn("relative flex cursor-default gap-2 select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none data-[disabled=true]:pointer-events-none data-[selected='true']:bg-accent data-[selected=true]:text-accent-foreground data-[disabled=true]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",t),...s}));oe.displayName=R.Command.Item.displayName;const Te=w.Root,Le=w.Trigger,Ae=p.forwardRef(({className:t,inset:s,children:a,...n},l)=>e.jsxs(w.SubTrigger,{ref:l,className:r.cn("flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",s&&"pl-8",t),...n,children:[a,e.jsx(b.ChevronRight,{className:"ml-auto"})]}));Ae.displayName=w.SubTrigger.displayName;const Me=p.forwardRef(({className:t,...s},a)=>e.jsx(w.SubContent,{ref:a,className:r.cn("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]",t),...s}));Me.displayName=w.SubContent.displayName;const re=p.forwardRef(({className:t,sideOffset:s=4,...a},n)=>e.jsx(w.Portal,{children:e.jsx(w.Content,{ref:n,sideOffset:s,className:r.cn("z-50 max-h-[var(--radix-dropdown-menu-content-available-height)] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-dropdown-menu-content-transform-origin]",t),...a})}));re.displayName=w.Content.displayName;const ie=p.forwardRef(({className:t,inset:s,...a},n)=>e.jsx(w.Item,{ref:n,className:r.cn("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",s&&"pl-8",t),...a}));ie.displayName=w.Item.displayName;const _e=p.forwardRef(({className:t,children:s,checked:a,...n},l)=>e.jsxs(w.CheckboxItem,{ref:l,className:r.cn("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),checked:a,...n,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(w.ItemIndicator,{children:e.jsx(b.Check,{className:"h-4 w-4"})})}),s]}));_e.displayName=w.CheckboxItem.displayName;const Oe=p.forwardRef(({className:t,children:s,...a},n)=>e.jsxs(w.RadioItem,{ref:n,className:r.cn("relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...a,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(w.ItemIndicator,{children:e.jsx(b.Circle,{className:"h-2 w-2 fill-current"})})}),s]}));Oe.displayName=w.RadioItem.displayName;const Ue=p.forwardRef(({className:t,inset:s,...a},n)=>e.jsx(w.Label,{ref:n,className:r.cn("px-2 py-1.5 text-sm font-semibold",s&&"pl-8",t),...a}));Ue.displayName=w.Label.displayName;const qe=p.forwardRef(({className:t,...s},a)=>e.jsx(w.Separator,{ref:a,className:r.cn("-mx-1 my-1 h-px bg-muted",t),...s}));qe.displayName=w.Separator.displayName;const Be=G.Root,Ee=G.Trigger,le=p.forwardRef(({className:t,align:s="center",sideOffset:a=4,...n},l)=>e.jsx(G.Content,{ref:l,align:s,sideOffset:a,className:r.cn("z-50 w-64 rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-hover-card-content-transform-origin]",t),...n}));le.displayName=G.Content.displayName;const Fe=p.forwardRef(({className:t,type:s,...a},n)=>e.jsx("input",{type:s,className:r.cn("flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:n,...a}));Fe.displayName="Input";const ce=p.forwardRef(({className:t,...s},a)=>e.jsx("textarea",{className:r.cn("flex min-h-[80px] w-full rounded-md border border-input bg-background px-3 py-2 text-base ring-offset-background placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",t),ref:a,...s}));ce.displayName="Textarea";function Ge({className:t,...s}){return e.jsx("div",{"data-slot":"input-group",role:"group",className:r.cn("group/input-group border-input dark:bg-input/30 shadow-xs relative flex w-full items-center rounded-md border outline-none transition-[color,box-shadow]","h-9 has-[>textarea]:h-auto","has-[>[data-align=inline-start]]:[&>input]:pl-2","has-[>[data-align=inline-end]]:[&>input]:pr-2","has-[>[data-align=block-start]]:h-auto has-[>[data-align=block-start]]:flex-col has-[>[data-align=block-start]]:[&>input]:pb-3","has-[>[data-align=block-end]]:h-auto has-[>[data-align=block-end]]:flex-col has-[>[data-align=block-end]]:[&>input]:pt-3","has-[[data-slot=input-group-control]:focus-visible]:ring-ring has-[[data-slot=input-group-control]:focus-visible]:ring-1","has-[[data-slot][aria-invalid=true]]:ring-destructive/20 has-[[data-slot][aria-invalid=true]]:border-destructive dark:has-[[data-slot][aria-invalid=true]]:ring-destructive/40",t),...s})}const Ve=J.cva("text-muted-foreground flex h-auto cursor-text select-none items-center justify-center gap-2 py-1.5 text-sm font-medium group-data-[disabled=true]/input-group:opacity-50 [&>kbd]:rounded-[calc(var(--radius)-5px)] [&>svg:not([class*='size-'])]:size-4",{variants:{align:{"inline-start":"order-first pl-3 has-[>button]:ml-[-0.45rem] has-[>kbd]:ml-[-0.35rem]","inline-end":"order-last pr-3 has-[>button]:mr-[-0.4rem] has-[>kbd]:mr-[-0.35rem]","block-start":"[.border-b]:pb-3 order-first w-full justify-start px-3 pt-3 group-has-[>input]/input-group:pt-2.5","block-end":"[.border-t]:pt-3 order-last w-full justify-start px-3 pb-3 group-has-[>input]/input-group:pb-2.5"}},defaultVariants:{align:"inline-start"}});function de({className:t,align:s="inline-start",...a}){return e.jsx("div",{role:"group","data-slot":"input-group-addon","data-align":s,className:r.cn(Ve({align:s}),t),onClick:n=>{var l,g;n.target.closest("button")||(g=(l=n.currentTarget.parentElement)==null?void 0:l.querySelector("input"))==null||g.focus()},...a})}const He=J.cva("flex items-center gap-2 text-sm shadow-none",{variants:{size:{xs:"h-6 gap-1 rounded-[calc(var(--radius)-5px)] px-2 has-[>svg]:px-2 [&>svg:not([class*='size-'])]:size-3.5",sm:"h-8 gap-1.5 rounded-md px-2.5 has-[>svg]:px-2.5","icon-xs":"size-6 rounded-[calc(var(--radius)-5px)] p-0 has-[>svg]:p-0","icon-sm":"size-8 p-0 has-[>svg]:p-0"}},defaultVariants:{size:"xs"}});function ue({className:t,type:s="button",variant:a="ghost",size:n="xs",...l}){return e.jsx(r.Button,{type:s,"data-size":n,variant:a,className:r.cn(He({size:n}),t),...l})}function We({className:t,...s}){return e.jsx(ce,{"data-slot":"input-group-control",className:r.cn("flex-1 resize-none rounded-none border-0 bg-transparent py-3 shadow-none focus-visible:ring-0 dark:bg-transparent",t),...s})}const Ke=p.forwardRef(({className:t,children:s,...a},n)=>e.jsxs(I.Trigger,{ref:n,className:r.cn("flex h-10 w-full items-center justify-between rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background data-[placeholder]:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1",t),...a,children:[s,e.jsx(I.Icon,{asChild:!0,children:e.jsx(b.ChevronDown,{className:"h-4 w-4 opacity-50"})})]}));Ke.displayName=I.Trigger.displayName;const me=p.forwardRef(({className:t,...s},a)=>e.jsx(I.ScrollUpButton,{ref:a,className:r.cn("flex cursor-default items-center justify-center py-1",t),...s,children:e.jsx(b.ChevronUp,{className:"h-4 w-4"})}));me.displayName=I.ScrollUpButton.displayName;const pe=p.forwardRef(({className:t,...s},a)=>e.jsx(I.ScrollDownButton,{ref:a,className:r.cn("flex cursor-default items-center justify-center py-1",t),...s,children:e.jsx(b.ChevronDown,{className:"h-4 w-4"})}));pe.displayName=I.ScrollDownButton.displayName;const Xe=p.forwardRef(({className:t,children:s,position:a="popper",...n},l)=>e.jsx(I.Portal,{children:e.jsxs(I.Content,{ref:l,className:r.cn("relative z-50 max-h-[--radix-select-content-available-height] min-w-[8rem] overflow-y-auto overflow-x-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 origin-[--radix-select-content-transform-origin]",a==="popper"&&"data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1",t),position:a,...n,children:[e.jsx(me,{}),e.jsx(I.Viewport,{className:r.cn("p-1",a==="popper"&&"h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]"),children:s}),e.jsx(pe,{})]})}));Xe.displayName=I.Content.displayName;const Ye=p.forwardRef(({className:t,...s},a)=>e.jsx(I.Label,{ref:a,className:r.cn("py-1.5 pl-8 pr-2 text-sm font-semibold",t),...s}));Ye.displayName=I.Label.displayName;const $e=p.forwardRef(({className:t,children:s,...a},n)=>e.jsxs(I.Item,{ref:n,className:r.cn("relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none focus:bg-accent focus:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",t),...a,children:[e.jsx("span",{className:"absolute left-2 flex h-3.5 w-3.5 items-center justify-center",children:e.jsx(I.ItemIndicator,{children:e.jsx(b.Check,{className:"h-4 w-4"})})}),e.jsx(I.ItemText,{children:s})]}));$e.displayName=I.Item.displayName;const Je=p.forwardRef(({className:t,...s},a)=>e.jsx(I.Separator,{ref:a,className:r.cn("-mx-1 my-1 h-px bg-muted",t),...s}));Je.displayName=I.Separator.displayName;const Qe="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Ze=(t=21)=>{let s="",a=crypto.getRandomValues(new Uint8Array(t|=0));for(;t--;)s+=Qe[a[t]&63];return s};const et=d.createContext(null),tt=d.createContext(null),fe=()=>d.useContext(et),st=()=>d.useContext(tt),xe=d.createContext(null),V=()=>{const t=st(),s=d.useContext(xe),a=t??s;if(!a)throw new Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return a};function at({data:t,className:s,...a}){var v;const n=V(),l=t.filename||"",u=((v=t.mediaType)!=null&&v.startsWith("image/")&&t.url?"image":"file")==="image",y=l||(u?"Image":"Attachment");return e.jsxs(gt,{children:[e.jsx(Ee,{asChild:!0,children:e.jsxs("div",{className:r.cn("group relative flex h-8 cursor-default select-none items-center gap-1.5 rounded-md border border-border px-1.5 text-sm font-medium transition-all hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",s),...a,children:[e.jsxs("div",{className:"relative size-5 shrink-0",children:[e.jsx("div",{className:"absolute inset-0 flex size-5 items-center justify-center overflow-hidden rounded bg-background transition-opacity group-hover:opacity-0",children:u?e.jsx("img",{alt:l||"attachment",className:"size-5 object-cover",height:20,src:t.url,width:20}):e.jsx("div",{className:"flex size-5 items-center justify-center text-muted-foreground",children:e.jsx(b.PaperclipIcon,{className:"size-3"})})}),e.jsxs(r.Button,{"aria-label":"Remove attachment",className:"absolute inset-0 size-5 cursor-pointer rounded p-0 opacity-0 transition-opacity group-hover:pointer-events-auto group-hover:opacity-100 [&>svg]:size-2.5",onClick:k=>{k.stopPropagation(),n.remove(t.id)},type:"button",variant:"ghost",children:[e.jsx(b.XIcon,{}),e.jsx("span",{className:"sr-only",children:"Remove"})]})]}),e.jsx("span",{className:"flex-1 truncate",children:y})]},t.id)}),e.jsx(ht,{className:"w-auto p-2",children:e.jsxs("div",{className:"w-auto space-y-3",children:[u&&e.jsx("div",{className:"flex max-h-96 w-96 items-center justify-center overflow-hidden rounded-md border",children:e.jsx("img",{alt:l||"attachment preview",className:"max-h-full max-w-full object-contain",height:384,src:t.url,width:448})}),e.jsx("div",{className:"flex items-center gap-2.5",children:e.jsxs("div",{className:"min-w-0 flex-1 space-y-1 px-0.5",children:[e.jsx("h4",{className:"truncate text-sm font-semibold leading-none",children:l||(u?"Image":"Attachment")}),t.mediaType&&e.jsx("p",{className:"truncate font-mono text-xs text-muted-foreground",children:t.mediaType})]})})]})})]})}function nt({children:t,className:s,...a}){const n=V();return n.files.length?e.jsx("div",{className:r.cn("flex flex-wrap items-center gap-2 p-3",s),...a,children:n.files.map(l=>e.jsx(d.Fragment,{children:t(l)},l.id))}):null}const ot=({label:t="Add photos or files",...s})=>{const a=V();return e.jsxs(ie,{...s,onSelect:n=>{n.preventDefault(),a.openFileDialog()},children:[e.jsx(b.ImageIcon,{className:"mr-2 size-4"})," ",t]})},rt=({className:t,accept:s,multiple:a,globalDrop:n,syncHiddenInput:l,maxFiles:g,maxFileSize:u,onError:y,onSubmit:v,children:k,...T})=>{const o=fe(),c=!!o,m=d.useRef(null),P=d.useRef(null),C=d.useRef(null);d.useEffect(()=>{var N;const i=(N=P.current)==null?void 0:N.closest("form");i instanceof HTMLFormElement&&(C.current=i)},[]);const[D,A]=d.useState([]),j=c?o.attachments.files:D,M=d.useCallback(()=>{var i;(i=m.current)==null||i.click()},[]),B=d.useCallback(i=>!s||s.trim()===""?!0:s.includes("image/*")?i.type.startsWith("image/"):!0,[s]),E=d.useCallback(i=>{const N=Array.from(i),h=N.filter(S=>B(S));if(N.length&&h.length===0){y==null||y({code:"accept",message:"No files match the accepted types."});return}const x=S=>u?S.size<=u:!0,f=h.filter(x);if(h.length>0&&f.length===0){y==null||y({code:"max_file_size",message:"All files exceed the maximum size."});return}A(S=>{const _=typeof g=="number"?Math.max(0,g-S.length):void 0,je=typeof _=="number"?f.slice(0,_):f;typeof _=="number"&&f.length>_&&(y==null||y({code:"max_files",message:"Too many files. Some were not added."}));const Y=[];for(const H of je)Y.push({id:Ze(),type:"file",url:URL.createObjectURL(H),mediaType:H.type,filename:H.name});return S.concat(Y)})},[B,g,u,y]),L=c?i=>o.attachments.add(i):E,O=c?i=>o.attachments.remove(i):i=>A(N=>{const h=N.find(x=>x.id===i);return h!=null&&h.url&&URL.revokeObjectURL(h.url),N.filter(x=>x.id!==i)}),F=c?()=>o.attachments.clear():()=>A(i=>{for(const N of i)N.url&&URL.revokeObjectURL(N.url);return[]}),K=c?()=>o.attachments.openFileDialog():M;d.useEffect(()=>{c&&o.__registerFileInput(m,()=>{var i;return(i=m.current)==null?void 0:i.click()})},[c,o]),d.useEffect(()=>{l&&m.current&&j.length===0&&(m.current.value="")},[j,l]),d.useEffect(()=>{const i=C.current;if(!i)return;const N=x=>{var f,S;(S=(f=x.dataTransfer)==null?void 0:f.types)!=null&&S.includes("Files")&&x.preventDefault()},h=x=>{var f,S,_;(S=(f=x.dataTransfer)==null?void 0:f.types)!=null&&S.includes("Files")&&x.preventDefault(),(_=x.dataTransfer)!=null&&_.files&&x.dataTransfer.files.length>0&&L(x.dataTransfer.files)};return i.addEventListener("dragover",N),i.addEventListener("drop",h),()=>{i.removeEventListener("dragover",N),i.removeEventListener("drop",h)}},[L]),d.useEffect(()=>{if(!n)return;const i=h=>{var x,f;(f=(x=h.dataTransfer)==null?void 0:x.types)!=null&&f.includes("Files")&&h.preventDefault()},N=h=>{var x,f,S;(f=(x=h.dataTransfer)==null?void 0:x.types)!=null&&f.includes("Files")&&h.preventDefault(),(S=h.dataTransfer)!=null&&S.files&&h.dataTransfer.files.length>0&&L(h.dataTransfer.files)};return document.addEventListener("dragover",i),document.addEventListener("drop",N),()=>{document.removeEventListener("dragover",i),document.removeEventListener("drop",N)}},[L,n]),d.useEffect(()=>()=>{if(!c)for(const i of j)i.url&&URL.revokeObjectURL(i.url)},[c,j]);const ge=i=>{i.currentTarget.files&&L(i.currentTarget.files)},he=async i=>{const h=await(await fetch(i)).blob();return new Promise((x,f)=>{const S=new FileReader;S.onloadend=()=>x(S.result),S.onerror=f,S.readAsDataURL(h)})},be=d.useMemo(()=>({files:j.map(i=>({...i,id:i.id})),add:L,remove:O,clear:F,openFileDialog:K,fileInputRef:m}),[j,L,O,F,K]),ve=i=>{i.preventDefault();const N=i.currentTarget,h=c?o.textInput.value:new FormData(N).get("message")||"";c||N.reset(),Promise.all(j.map(async({id:x,...f})=>f.url&&f.url.startsWith("blob:")?{...f,url:await he(f.url)}:f)).then(x=>{try{const f=v({text:h,files:x},i);f instanceof Promise?f.then(()=>{F(),c&&o.textInput.clear()}).catch(()=>{}):(F(),c&&o.textInput.clear())}catch{}})},X=e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:"hidden",ref:P}),e.jsx("input",{accept:s,"aria-label":"Upload files",className:"hidden",multiple:a,onChange:ge,ref:m,title:"Upload files",type:"file"}),e.jsx("form",{className:r.cn("w-full",t),onSubmit:ve,...T,children:e.jsx(Ge,{className:"overflow-hidden",children:k})})]});return c?X:e.jsx(xe.Provider,{value:be,children:X})},it=({onChange:t,className:s,placeholder:a="What would you like to know?",...n})=>{const l=fe(),g=V(),[u,y]=d.useState(!1),v=o=>{if(o.key==="Enter"){if(u||o.nativeEvent.isComposing||o.shiftKey)return;o.preventDefault();const c=o.currentTarget.form,m=c==null?void 0:c.querySelector('button[type="submit"]');if(m!=null&&m.disabled)return;c==null||c.requestSubmit()}if(o.key==="Backspace"&&o.currentTarget.value===""&&g.files.length>0){o.preventDefault();const c=g.files.at(-1);c&&g.remove(c.id)}},k=o=>{var P;const c=(P=o.clipboardData)==null?void 0:P.items;if(!c)return;const m=[];for(const C of c)if(C.kind==="file"){const D=C.getAsFile();D&&m.push(D)}m.length>0&&(o.preventDefault(),g.add(m))},T=l?{value:l.textInput.value,onChange:o=>{l.textInput.setInput(o.currentTarget.value),t==null||t(o)}}:{onChange:t};return e.jsx(We,{className:r.cn("field-sizing-content max-h-48 min-h-16",s),name:"message",onCompositionEnd:()=>y(!1),onCompositionStart:()=>y(!0),onKeyDown:v,onPaste:k,placeholder:a,...n,...T})},lt=({className:t,...s})=>e.jsx(de,{align:"block-end",className:r.cn("order-first flex-wrap gap-1",t),...s}),ct=({className:t,...s})=>e.jsx(de,{align:"block-end",className:r.cn("justify-between gap-1",t),...s}),dt=({className:t,...s})=>e.jsx("div",{className:r.cn("flex items-center gap-1",t),...s}),W=({variant:t="ghost",className:s,size:a,...n})=>{const l=a??(d.Children.count(n.children)>1?"sm":"icon-sm");return e.jsx(ue,{className:r.cn(s),size:l,type:"button",variant:t,...n})},ut=t=>e.jsx(Te,{...t}),mt=({className:t,children:s,...a})=>e.jsx(Le,{asChild:!0,children:e.jsx(W,{className:t,...a,children:s??e.jsx(b.PlusIcon,{className:"size-4"})})}),pt=({className:t,...s})=>e.jsx(re,{align:"start",className:r.cn(t),...s}),ft=({className:t,variant:s="default",size:a="icon-sm",status:n,children:l,...g})=>{let u=e.jsx(b.CornerDownLeftIcon,{className:"size-4"});return n==="submitted"?u=e.jsx(b.Loader2Icon,{className:"size-4 animate-spin"}):n==="streaming"?u=e.jsx(b.SquareIcon,{className:"size-4"}):n==="error"&&(u=e.jsx(b.XIcon,{className:"size-4"})),e.jsx(ue,{"aria-label":"Submit",className:r.cn(t),size:a,type:"submit",variant:s,...g,children:l??u})},xt=({className:t,textareaRef:s,onTranscriptionChange:a,...n})=>{const[l,g]=d.useState(!1),[u,y]=d.useState(null),v=d.useRef(null);d.useEffect(()=>{if(typeof window<"u"&&("SpeechRecognition"in window||"webkitSpeechRecognition"in window)){const T=window.SpeechRecognition||window.webkitSpeechRecognition,o=new T;o.continuous=!0,o.interimResults=!0,o.lang="en-US",o.onstart=()=>{g(!0)},o.onend=()=>{g(!1)},o.onresult=c=>{var P;let m="";for(let C=c.resultIndex;C<c.results.length;C++){const D=c.results[C];D.isFinal&&(m+=((P=D[0])==null?void 0:P.transcript)??"")}if(m&&(s!=null&&s.current)){const C=s.current,D=C.value,A=D+(D?" ":"")+m;C.value=A,C.dispatchEvent(new Event("input",{bubbles:!0})),a==null||a(A)}},o.onerror=c=>{console.error("Speech recognition error:",c.error),g(!1)},v.current=o,y(o)}return()=>{v.current&&v.current.stop()}},[s,a]);const k=d.useCallback(()=>{u&&(l?u.stop():u.start())},[u,l]);return e.jsx(W,{className:r.cn("relative transition-all duration-200",l&&"animate-pulse bg-accent text-accent-foreground",t),disabled:!u,onClick:k,...n,children:e.jsx(b.MicIcon,{className:"size-4"})})},gt=({openDelay:t=0,closeDelay:s=0,...a})=>e.jsx(Be,{closeDelay:s,openDelay:t,...a}),ht=({align:t="start",...s})=>e.jsx(le,{align:t,...s}),bt=t=>e.jsx(Ce,{...t}),vt=t=>e.jsx(ke,{...t}),jt=({className:t,children:s,title:a="Model Selector",...n})=>e.jsxs(Z,{className:r.cn("p-0",t),...n,children:[e.jsx(ee,{className:"sr-only",children:a}),e.jsx(te,{className:"**:data-[slot=command-input-wrapper]:h-auto",children:s})]}),yt=({className:t,...s})=>e.jsx(se,{className:r.cn("h-auto py-3.5",t),...s}),Nt=t=>e.jsx(ae,{...t}),wt=t=>e.jsx(ne,{...t}),St=t=>e.jsx(oe,{...t}),It=({provider:t,className:s,...a})=>e.jsx("img",{...a,alt:`${t} logo`,className:r.cn("size-3 dark:invert",s),height:12,src:`https://models.dev/logos/${t}.svg`,width:12}),Ct=({className:t,...s})=>e.jsx("span",{className:r.cn("flex-1 truncate text-left",t),...s}),kt=({selectedModel:t,onModelChange:s,disabled:a=!1})=>{const[n,l]=d.useState(!1),[g,u]=d.useState(""),y=U.getModelById(t)||U.getDefaultModel(),k=U.AI_MODELS.filter(o=>o.name.toLowerCase().includes(g.toLowerCase())||o.provider.toLowerCase().includes(g.toLowerCase())).reduce((o,c)=>(o[c.provider]||(o[c.provider]=[]),o[c.provider].push(c),o),{}),T=o=>{s(o),l(!1),u("")};return e.jsxs(bt,{open:n,onOpenChange:l,children:[e.jsx(vt,{asChild:!0,children:e.jsxs(r.Button,{variant:"outline",size:"sm",disabled:a,className:"h-8 gap-1 px-2 text-xs",children:[e.jsx(b.Cpu,{size:14}),e.jsx("span",{className:"max-w-20 truncate",children:y.name})]})}),e.jsxs(jt,{className:"w-96 p-0",children:[e.jsx(yt,{placeholder:"Search models...",value:g,onValueChange:u}),e.jsx(Nt,{children:Object.entries(k).map(([o,c])=>e.jsx(wt,{heading:o.charAt(0).toUpperCase()+o.slice(1),children:c.map(m=>e.jsxs(St,{value:m.id,onSelect:()=>T(m.id),className:"flex cursor-pointer items-center gap-2 p-2",children:[e.jsx(It,{provider:m.provider}),e.jsxs("div",{className:"flex flex-1 flex-col",children:[e.jsx(Ct,{children:m.name}),e.jsx("span",{className:"text-xs text-muted-foreground",children:m.description})]}),t===m.id&&e.jsx("div",{className:"h-2 w-2 rounded-full bg-blue-500"})]},m.id))},o))})]})]})},$="chai-ai-selected-model",Rt=({input:t,setInput:s,onSend:a,onStop:n,isLoading:l,disabled:g,selectedLang:u,selectedModel:y=U.getDefaultModel().id,onModelChange:v})=>{const{t:k}=Ie.useTranslation(),[T,o]=d.useState(y),[c,m]=d.useState(null),P=d.useRef(null),[C,D]=d.useState(!1);d.useEffect(()=>{if(!u){const j=localStorage.getItem($);if(j)o(j),v==null||v(j);else{const M=U.getDefaultModel().id;o(M),v==null||v(M)}}},[u,v]);const A=j=>{var E;const M=j.files.find(L=>{var O;return(O=L.mediaType)==null?void 0:O.startsWith("image/")}),B=(M==null?void 0:M.url)||c;a((E=j.text)==null?void 0:E.trim(),void 0,B,T),m(null)};return e.jsx("div",{className:"relative",children:e.jsx("div",{className:"border-gray-20 rounded-lg border",children:e.jsxs(rt,{onSubmit:A,accept:"image/*",className:"flex h-auto w-full flex-col",children:[e.jsx(lt,{className:"p-0",children:e.jsx(nt,{className:"pb-0",children:j=>e.jsx(at,{className:"text-xs",data:j})})}),e.jsx(it,{ref:P,value:t,onChange:j=>s(j.target.value),placeholder:k(u?"Ask to update content":"Ask me anything..."),disabled:l,className:"max-h-[200px] min-h-[60px] w-full",rows:3}),e.jsxs(ct,{children:[u?e.jsx("div",{}):e.jsxs(dt,{children:[e.jsxs(ut,{children:[e.jsx(mt,{disabled:l,children:e.jsx(b.Paperclip,{size:16})}),e.jsx(pt,{children:e.jsx(ot,{})})]}),e.jsx(xt,{textareaRef:P,onTranscriptionChange:s,disabled:l}),e.jsx(kt,{selectedModel:T,onModelChange:j=>{o(j),v==null||v(j),localStorage.setItem($,j)},disabled:l}),e.jsxs(W,{className:"hidden",size:"sm",onClick:()=>D(!C),variant:C?"default":"ghost",children:[e.jsx(b.GlobeIcon,{size:16}),e.jsx("span",{children:"Search"})]})]}),l?e.jsxs("button",{onClick:n,className:"z-50 flex items-center gap-x-1 rounded-md bg-red-500 p-1.5 text-white transition-colors hover:bg-red-600",title:k("Stop generation"),children:[e.jsx(b.Square,{size:16})," ",e.jsx("span",{className:"text-xs",children:k("Stop")})]}):e.jsx(ft,{disabled:!t.trim()||g,children:e.jsx(b.Send,{size:16})})]})]})})})};exports.default=Rt;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as t, jsxs as l } from "react/jsx-runtime";
|
|
2
|
-
import { L as r } from "./index-
|
|
2
|
+
import { L as r } from "./index-e9WlBH0R.js";
|
|
3
3
|
import { useTranslation as i } from "@chaibuilder/sdk";
|
|
4
4
|
import { Button as c } from "@chaibuilder/sdk/ui";
|
|
5
5
|
import { ArrowRight as m } from "lucide-react";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),a=require("./index-Pdb5tSRL.cjs"),c=require("@chaibuilder/sdk"),r=require("@chaibuilder/sdk/ui"),o=require("lucide-react"),x=({selectedLang:s,isLoading:n,selectedBlock:l,onClick:i})=>{const{t}=c.useTranslation();return e.jsx("div",{className:"flex flex-col gap-2",children:e.jsx("div",{className:`flex flex-col gap-2 ${n?"pointer-events-none opacity-50":""}`,children:l?e.jsx(r.Button,{variant:"outline",className:"h-auto",onClick:()=>i("TRANSLATE"),children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("p",{className:"text-left text-xs font-thin",children:t("Quick Action:")}),e.jsxs("span",{className:"flex items-center gap-x-2 text-sm font-medium",children:[t("Translate Content")," ",t("to")," ",a.LANGUAGES[s]," ",e.jsx(o.ArrowRight,{className:"h-4 w-4"})]})]})}):null})})};exports.default=x;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("react/jsx-runtime"),r=require("./index-Pdb5tSRL.cjs"),c=require("@chaibuilder/sdk"),s=require("@chaibuilder/sdk/ui"),y=require("lodash-es");function S({page:e,onClose:l}){const{t}=c.useTranslation(),[,d]=r.useSearchParams(),{mutate:u,isPending:a}=r.useDeletePage(),{data:o}=r.usePageTypes(),{setSelectedLang:h,fallbackLang:m}=c.useLanguages(),[,x]=c.useSidebarActivePanel(),P=()=>{a||u(e,{onSuccess:()=>{e!=null&&e.primaryPage?(window.history.replaceState({},"",`/?page=${e.primaryPage}`),d(new URLSearchParams({page:e.primaryPage}))):(window.history.replaceState({},"","/"),d(new URLSearchParams)),window.dispatchEvent(new PopStateEvent("popstate")),h(m),x("outline"),l()}})},i=o==null?void 0:o.find(D=>D.key===(e==null?void 0:e.pageType));return n.jsx(s.Dialog,{open:!!e,onOpenChange:l,children:n.jsxs(s.DialogContent,{children:[n.jsxs(s.DialogHeader,{children:[n.jsx(s.DialogTitle,{children:t("Confirm Deletion")}),n.jsxs(s.DialogDescription,{className:"py-4 text-slate-500",children:[n.jsxs("div",{children:[t("Are you sure you want to remove")," ",n.jsx("b",{children:(e==null?void 0:e.name)??(e==null?void 0:e.slug)})," ",i!=null&&i.hasSlug?(i==null?void 0:i.name)+"?":`${t("page?")} ${e!=null&&e.primaryPage?"":t("This will also delete all associated language pages.")}`]}),e.lang&&n.jsxs("div",{className:"py-2 text-sm",children:[t("Language"),": ",n.jsx("span",{className:"font-medium text-gray-500",children:y.get(r.LANGUAGES,e.lang,e.lang)})]})]})]}),n.jsxs(s.DialogFooter,{children:[n.jsx(s.Button,{variant:"outline",onClick:l,children:t("Cancel")}),n.jsx(s.Button,{variant:"destructive",disabled:a,onClick:P,children:t(a?"Deleting...":"Delete")})]})]})})}exports.default=S;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as i, jsxs as r } from "react/jsx-runtime";
|
|
2
|
-
import { i as f, m as w, h as y, L as S } from "./index-
|
|
2
|
+
import { i as f, m as w, h as y, L as S } from "./index-e9WlBH0R.js";
|
|
3
3
|
import { useTranslation as v, useLanguages as L, useSidebarActivePanel as x } from "@chaibuilder/sdk";
|
|
4
4
|
import { Dialog as A, DialogContent as k, DialogHeader as C, DialogTitle as N, DialogDescription as g, DialogFooter as E, Button as c } from "@chaibuilder/sdk/ui";
|
|
5
5
|
import { get as U } from "lodash-es";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),F=require("lodash-es"),f=require("lucide-react"),u=require("react"),fe=require("react-dropzone"),g=require("./index-Bz7smSC0.cjs"),w=require("sonner"),Y=require("./image-compression-DZ9WMmyn.cjs"),z=require("@tanstack/react-query"),pe=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>{const o=i.map(async l=>x(n,{action:g.ACTIONS.UPLOAD_ASSET,data:l}));return await Promise.all(o)},onSuccess:i=>{var o;if(i!=null&&i.some(s=>s.error))throw new Error(((o=i==null?void 0:i.find(s=>s.error))==null?void 0:o.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]});const s=i==null?void 0:i.length;w.toast.success(`${s===1?"Asset":s+" Assets"} uploaded successfully`)}},onError:()=>{w.toast.error("Failed to upload asset")}})},ge=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.DELETE_ASSET,data:{id:i}}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),w.toast.success("Asset deleted successfully")},onError:()=>{w.toast.error("Failed to delete asset")}})},je=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.UPDATE_ASSET,data:i}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),i!=null&&i.id&&r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSET,i.id]}),w.toast.success("Asset updated successfully")},onError:()=>{w.toast.error("Failed to update asset")}})};function ve({currentPage:n,totalPages:r,onPageChange:x,pageRangeDisplayed:i=3,showPageInput:o=!0,className:s=""}){const[l,E]=u.useState(String(n)),N=u.useMemo(()=>{const c=Math.floor(i/2);let m=Math.max(1,n-c),d=Math.min(r,n+c);d-m+1<i&&(m===1?d=Math.min(r,m+i-1):d===r&&(m=Math.max(1,d-i+1)));const p=[];m>1&&(p.push(1),m>2&&p.push("..."));for(let y=m;y<=d;y++)p.push(y);return d<r&&(d<r-1&&p.push("..."),p.push(r)),p},[n,r,i]),v=c=>{c!==n&&c>=1&&c<=r&&(x(c),E(String(c)))},j=()=>{n>1&&v(n-1)},b=()=>{n<r&&v(n+1)},C=()=>{const c=Number(l);!isNaN(c)&&c>=1&&c<=r&&v(c)},A=c=>{c.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${s}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:j,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(f.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((c,m)=>{if(c==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const d=c,p=d===n;return e.jsx(a.Button,{variant:p?"default":"outline",size:"sm",onClick:()=>v(d),className:p?"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:d},d)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:b,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(f.ChevronRight,{className:" h-4 w-4"})]})]}),o&&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:l,onChange:c=>{const m=c.target.value.replace(/[^\d]/g,"");E(m)},onKeyDown:A,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:l===""||Number(l)<1||Number(l)>r,children:"Go"})]})]})}const ye=(n={})=>{const r=g.useAssetsApiUrl(),x=g.useFetch(),{search:i,page:o=1,limit:s=30}=n;return z.useQuery({queryKey:[g.ACTIONS.GET_ASSETS,i,o,s],queryFn:async()=>{const l=await x(r,{action:g.ACTIONS.GET_ASSETS,data:{search:i,page:o,limit:s}});return l.page=o,l.limit=s,l},staleTime:1/0,retry:1})},Ne=n=>{const r=g.useAssetsApiUrl(),x=g.useFetch();return z.useQuery({queryKey:[g.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await x(r,{action:g.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function be(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 Z(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 J(n,r){let x=n,i=r==null?void 0:r.description;return(!i||typeof i!="string")&&(i=""),(!x||typeof x!="string")&&(x=""),x!==i}const we=({assetId:n,onBack:r,onEdit:x,onSave:i,isSaving:o})=>{var c,m;const{t:s}=M.useTranslation(),{data:l,isLoading:E,isError:N}=Ne(n||""),[v,j]=u.useState(""),[b,C]=u.useState(!1);u.useEffect(()=>{const d=new Image;return d.src=(l==null?void 0:l.url)||"",d.onload=()=>C(!0),()=>{d.onload=null}},[l]);const A=async(d,p)=>{try{await navigator.clipboard.writeText(d),w.toast.success(s("{{type}} copied to clipboard",{type:p}))}catch(y){w.toast.error(s("Failed to copy {{type}}",{type:p}),{description:y==null?void 0:y.message})}};return u.useEffect(()=>{l!=null&&l.description&&j(l.description)},[l]),E||!b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}):N||!(l!=null&&l.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(f.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:s("No Asset Found")}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:s(N?"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:s("Back to Assets")}),N&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:s("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:o,children:[e.jsx(f.ChevronLeft,{className:"h-4 w-4"}),s("Back to Assets")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:o,children:s("Cancel")}),e.jsxs(a.Button,{variant:"outline",onClick:()=>A(l.url,s("Asset URL")),disabled:o,children:[e.jsx(f.Copy,{className:"h-4 w-4 mr-2"}),s("Copy URL")]}),e.jsxs(a.Button,{variant:"default",onClick:()=>x(l),disabled:o,children:[e.jsx(f.Pencil,{className:"h-4 w-4"}),s("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:l.url,alt:l.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:s("Details")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:s("File Name"),value:l.name},{label:s("Type"),value:l.type,capitalize:!0},{label:s("Format"),value:((c=l.metadata)==null?void 0:c.format)||l.type,capitalize:!0},{label:s("Size"),value:be(l.size)},{label:s("Dimensions"),value:`${l.width||0} × ${l.height||0}`},{label:s("Created"),value:Z(l.createdAt)},{label:s("Updated"),value:Z(((m=l.metadata)==null?void 0:m.updatedAt)||(l==null?void 0:l.updatedAt)||l.createdAt)},{label:s("URL"),value:l.url,copyable:!0}].map(d=>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:d.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(d.capitalize?" capitalize":""),children:d.value}),d.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>A(d.value,d.label),children:e.jsx(f.Link,{className:"h-3 w-3"})})]})]},d.label))})]}),l.usedOn&&l.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:s("Used On")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:l.usedOn.map((d,p)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:d.name}),e.jsxs("div",{className:"text-gray-500",children:["(",d.slug,")"]})]},p))})]}),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:s("Description")}),e.jsx(a.Textarea,{id:"description",value:v,placeholder:s("Enter a description for the asset"),onChange:d=>j(d.target.value),rows:3,disabled:o,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:()=>i(v),disabled:o||!J(v,l),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${o||!J(v,l)?"opacity-50 cursor-not-allowed":""}`,children:o?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),s("Saving...")]}):s("Save")})})]})]})]})]})},Ce=u.lazy(()=>Promise.resolve().then(()=>require("./image-editor-CnDnY97s.cjs"))),Ae=25*1024*1024,Se=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:x,isUploadingAsset:i,onUploaded:o})=>{const{t:s}=M.useTranslation(),[l,E]=u.useState(()=>{const c=localStorage.getItem("chai_optimize_images");return c!==null?c==="true":!0});u.useEffect(()=>{localStorage.setItem("chai_optimize_images",l.toString())},[l]);const N=n||i,v=u.useCallback(async c=>{try{const m=c;if(!m.every(S=>S.type.startsWith("image/")))return w.toast.error(s("Invalid file type. Please upload a valid file.")),Promise.reject(new Error("Invalid file type"));const d=m.map(async S=>{let U=S;return S.type.startsWith("image/")&&(U=await Y.compressImageIfNeeded(S)),new Promise((_,B)=>{const L=new FileReader;L.readAsDataURL(U),L.onload=async()=>{_({file:L.result,folderId:void 0,name:S.name,optimize:l})},L.onerror=()=>B(null)})}),p=await Promise.all(d),y=await x(p);return(y==null?void 0:y.length)===1&&o(y[0]),y}catch(m){return Promise.reject(m)}},[x,l,o,s]),j=c=>{const m=[];let d=0;return c.forEach(p=>{p.size>Ae?d++:m.push(p)}),d>0&&w.toast.error(`${d===1&&c.length===1?s("File"):d+s(d===1?" file":" files")} ${s("exceed the maximum size limit of 10MB.")}`),F.isEmpty(m)?[]:v(m)},{getRootProps:b,getInputProps:C,isDragActive:A}=fe.useDropzone({onDrop:j,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||i,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 ${N?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...b(),className:M.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",N?"items-start":"items-center",A?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...C()}),N?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(f.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:s(n?"Updating file...":"Uploading file...")}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:[s("Please wait while we")," ",s(n?"update":"upload")," ",s("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(f.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:[s("Drop your file here or")," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:s("browse")})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:[s("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:[s("Optimization:")," "," ",e.jsx("span",{className:l?"text-indigo-600":"text-gray-400",children:s(l?"On":"Off")})]}),e.jsx(a.Switch,{checked:l,onCheckedChange:c=>{E(c)},onClick:c=>{c.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 ${l?"invisible":""}`,children:e.jsx(f.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsx("p",{className:"text-xs text-white",children:s("Warning: Unoptimized images may affect performance and page load times")})})]})})]})]})]})})};function Te({close:n,onSelect:r,mode:x="image",assetId:i}){const{t:o}=M.useTranslation(),s=!1,l=10,E=u.useMemo(()=>[x],[x]),[N,v]=u.useState(null),[j,b]=u.useState(null),[C,A]=u.useState(null),[c,m]=u.useState({show:!1,file:""}),[d,p]=u.useState(!1),[y,S]=u.useState(i?"details":"grid"),[U,_]=u.useState(""),[B,L]=u.useState(""),[P,Q]=u.useState(1),[R]=u.useState(30),[T,G]=u.useState([]);u.useEffect(()=>{i&&(v(i),S("details"))},[i]),u.useEffect(()=>{const t=setTimeout(()=>{_(B),Q(1)},300);return()=>clearTimeout(t)},[B]);const{data:q,isLoading:$,refetch:ee}=ye({search:U.toLowerCase().trim(),page:P,limit:R}),D=(q==null?void 0:q.assets)||[],te=(q==null?void 0:q.total)||0,I=Math.ceil(te/R);u.useEffect(()=>{$||I<=0||Q(t=>t>I?I:t<1?1:t)},[$,I]);const se=(D==null?void 0:D.length)>0,{mutate:ie}=ge(),{mutateAsync:K,isPending:le}=pe(),{mutateAsync:W,isPending:ae}=je(),V=u.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,I));h!==P&&Q(h)},[I,P]),re=t=>{L(t.target.value)},ne=u.useCallback(t=>{G(h=>F.find(h,{id:t.id})?[]:[t])},[s]),oe=u.useCallback(()=>{G([])},[]),H=t=>{(t==null?void 0:t.length)!==0&&(r(F.pick(F.first(t||T),["id","url","width","height","description"])),n())},ce=async t=>{b(t)},de=async()=>{j&&(A(j==null?void 0:j.id),await ie(j.id,{onSuccess:()=>{A(null),b(null)},onError:()=>{A(null)}}),b(null))},ue=t=>{v(t.id),S("details")},me=async(t,h)=>{try{const O=localStorage.getItem("chai_optimize_images")!=="false";if(h){const k=await K([{file:t,folderId:void 0,name:c.name||"",optimize:O}]);if((k==null?void 0:k.length)>0){const X=k[0];r({...F.pick(X,["id","width","height","description"]),url:X.url})}}else{const k=await W({id:c.id||"",file:t});k&&r({...F.pick(k,["id","width","height","description"]),url:k.url})}m({show:!1,file:""}),n()}catch(O){console.error(o("Error saving edited image:"),O)}},he=u.useCallback(t=>{G([t])},[]),xe=u.useCallback(t=>{V(t)},[V]);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:o("Digital Asset Manager")}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Se,{maxFileSize:l,allowedTypes:E,uploadAssets:K,isUpdatingAsset:ae,isUploadingAsset:le,onUploaded:he}),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(f.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${B.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:o("Search assets..."),onChange:re,value:B,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:()=>oe(),title:o("Clear selection"),children:o("Clear")})}),e.jsx(a.Button,{size:"sm",onClick:()=>H(T),disabled:T.length===0,children:o("Select Asset")})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>ee(),children:e.jsx(f.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:$?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"})]}):!$&&!se?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(f.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:o("No assets found")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:U.length>0?o("No assets found for your search: {{query}}",{query:U}):o("Start uploading assets to get started")}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:D==null?void 0:D.map(t=>e.jsxs("div",{className:M.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",C&&(j==null?void 0:j.id)===t.id?"pointer-events-none opacity-50":"",C===t.id?"pointer-events-none opacity-50":""),onClick:()=>ne(t),onDoubleClick:()=>H([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[C===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(f.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(f.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:Y.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(),ue(t)},children:e.jsx(f.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("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),w.toast.success(o("Asset URL copied to clipboard"))},children:e.jsx(f.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("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(),m({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("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(),ce(t)},children:e.jsx(f.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("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(f.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),I>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(g.ErrorBoundary,{fallback:e.jsx("div",{className:"text-red-500",children:o("Error loading pagination")}),children:e.jsx(ve,{currentPage:P,totalPages:I,onPageChange:xe,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(we,{assetId:N||i||"",onBack:()=>{S("grid"),v(null)},onEdit:t=>{m({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(N){p(!0);try{const h=D.find(O=>O.id===N);h&&await W(F.merge(h,{description:t}))}finally{p(!1)}}},isSaving:d})]}),c.show&&e.jsx(u.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ce,{imageUrl:c.file,onSave:me,onClose:()=>m({show:!1,file:""}),defaultSavedImageName:c.name,isEditing:!!c.id})}),j&&e.jsx(a.Dialog,{open:!!j,onOpenChange:()=>b(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:o("Delete Asset")}),e.jsx(a.DialogDescription,{children:o('Are you sure you want to delete "{{name}}"? This action cannot be undone.',{name:j.name})})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>b(null),children:o("Cancel")}),e.jsx(a.Button,{variant:"destructive",onClick:de,children:o("Delete")})]})]})})]})}exports.default=Te;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),M=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),F=require("lodash-es"),f=require("lucide-react"),u=require("react"),fe=require("react-dropzone"),g=require("./index-Pdb5tSRL.cjs"),w=require("sonner"),Y=require("./image-compression-DZ9WMmyn.cjs"),z=require("@tanstack/react-query"),pe=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>{const o=i.map(async l=>x(n,{action:g.ACTIONS.UPLOAD_ASSET,data:l}));return await Promise.all(o)},onSuccess:i=>{var o;if(i!=null&&i.some(s=>s.error))throw new Error(((o=i==null?void 0:i.find(s=>s.error))==null?void 0:o.error)||"Failed to upload asset");{r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]});const s=i==null?void 0:i.length;w.toast.success(`${s===1?"Asset":s+" Assets"} uploaded successfully`)}},onError:()=>{w.toast.error("Failed to upload asset")}})},ge=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.DELETE_ASSET,data:{id:i}}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),w.toast.success("Asset deleted successfully")},onError:()=>{w.toast.error("Failed to delete asset")}})},je=()=>{const n=g.useAssetsApiUrl(),r=z.useQueryClient(),x=g.useFetch();return z.useMutation({mutationFn:async i=>x(n,{action:g.ACTIONS.UPDATE_ASSET,data:i}),onSuccess:i=>{if(i!=null&&i.error)throw new Error(i==null?void 0:i.error);r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSETS]}),i!=null&&i.id&&r.invalidateQueries({queryKey:[g.ACTIONS.GET_ASSET,i.id]}),w.toast.success("Asset updated successfully")},onError:()=>{w.toast.error("Failed to update asset")}})};function ve({currentPage:n,totalPages:r,onPageChange:x,pageRangeDisplayed:i=3,showPageInput:o=!0,className:s=""}){const[l,E]=u.useState(String(n)),N=u.useMemo(()=>{const c=Math.floor(i/2);let m=Math.max(1,n-c),d=Math.min(r,n+c);d-m+1<i&&(m===1?d=Math.min(r,m+i-1):d===r&&(m=Math.max(1,d-i+1)));const p=[];m>1&&(p.push(1),m>2&&p.push("..."));for(let y=m;y<=d;y++)p.push(y);return d<r&&(d<r-1&&p.push("..."),p.push(r)),p},[n,r,i]),v=c=>{c!==n&&c>=1&&c<=r&&(x(c),E(String(c)))},j=()=>{n>1&&v(n-1)},b=()=>{n<r&&v(n+1)},C=()=>{const c=Number(l);!isNaN(c)&&c>=1&&c<=r&&v(c)},A=c=>{c.key==="Enter"&&C()};return r<=1?null:e.jsxs("div",{className:`flex flex-wrap items-center justify-center gap-3 ${s}`,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:j,disabled:n===1,className:"px-2 py-1 text-sm hover:bg-gray-50",children:[e.jsx(f.ChevronLeft,{className:" h-4 w-4"}),"Previous"]}),e.jsx("div",{className:"flex items-center gap-2",children:N.map((c,m)=>{if(c==="...")return e.jsx("span",{className:"px-2 text-muted-foreground",children:"..."},`ellipsis-${m}`);const d=c,p=d===n;return e.jsx(a.Button,{variant:p?"default":"outline",size:"sm",onClick:()=>v(d),className:p?"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:d},d)})}),e.jsxs(a.Button,{variant:"outline",size:"sm",onClick:b,disabled:n===r,className:"px-2 py-1 text-sm hover:bg-gray-50",children:["Next",e.jsx(f.ChevronRight,{className:" h-4 w-4"})]})]}),o&&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:l,onChange:c=>{const m=c.target.value.replace(/[^\d]/g,"");E(m)},onKeyDown:A,className:"h-8 w-16 px-2 py-1"}),e.jsx(a.Button,{variant:"outline",size:"sm",onClick:C,disabled:l===""||Number(l)<1||Number(l)>r,children:"Go"})]})]})}const ye=(n={})=>{const r=g.useAssetsApiUrl(),x=g.useFetch(),{search:i,page:o=1,limit:s=30}=n;return z.useQuery({queryKey:[g.ACTIONS.GET_ASSETS,i,o,s],queryFn:async()=>{const l=await x(r,{action:g.ACTIONS.GET_ASSETS,data:{search:i,page:o,limit:s}});return l.page=o,l.limit=s,l},staleTime:1/0,retry:1})},Ne=n=>{const r=g.useAssetsApiUrl(),x=g.useFetch();return z.useQuery({queryKey:[g.ACTIONS.GET_ASSET,n],queryFn:async()=>n?await x(r,{action:g.ACTIONS.GET_ASSET,data:{id:n}}):null,staleTime:1/0,retry:1})};function be(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 Z(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 J(n,r){let x=n,i=r==null?void 0:r.description;return(!i||typeof i!="string")&&(i=""),(!x||typeof x!="string")&&(x=""),x!==i}const we=({assetId:n,onBack:r,onEdit:x,onSave:i,isSaving:o})=>{var c,m;const{t:s}=M.useTranslation(),{data:l,isLoading:E,isError:N}=Ne(n||""),[v,j]=u.useState(""),[b,C]=u.useState(!1);u.useEffect(()=>{const d=new Image;return d.src=(l==null?void 0:l.url)||"",d.onload=()=>C(!0),()=>{d.onload=null}},[l]);const A=async(d,p)=>{try{await navigator.clipboard.writeText(d),w.toast.success(s("{{type}} copied to clipboard",{type:p}))}catch(y){w.toast.error(s("Failed to copy {{type}}",{type:p}),{description:y==null?void 0:y.message})}};return u.useEffect(()=>{l!=null&&l.description&&j(l.description)},[l]),E||!b?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}):N||!(l!=null&&l.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(f.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:s("No Asset Found")}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:s(N?"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:s("Back to Assets")}),N&&e.jsx(a.Button,{variant:"default",onClick:()=>window.location.reload(),children:s("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:o,children:[e.jsx(f.ChevronLeft,{className:"h-4 w-4"}),s("Back to Assets")]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(a.Button,{variant:"outline",onClick:r,disabled:o,children:s("Cancel")}),e.jsxs(a.Button,{variant:"outline",onClick:()=>A(l.url,s("Asset URL")),disabled:o,children:[e.jsx(f.Copy,{className:"h-4 w-4 mr-2"}),s("Copy URL")]}),e.jsxs(a.Button,{variant:"default",onClick:()=>x(l),disabled:o,children:[e.jsx(f.Pencil,{className:"h-4 w-4"}),s("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:l.url,alt:l.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:s("Details")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:s("File Name"),value:l.name},{label:s("Type"),value:l.type,capitalize:!0},{label:s("Format"),value:((c=l.metadata)==null?void 0:c.format)||l.type,capitalize:!0},{label:s("Size"),value:be(l.size)},{label:s("Dimensions"),value:`${l.width||0} × ${l.height||0}`},{label:s("Created"),value:Z(l.createdAt)},{label:s("Updated"),value:Z(((m=l.metadata)==null?void 0:m.updatedAt)||(l==null?void 0:l.updatedAt)||l.createdAt)},{label:s("URL"),value:l.url,copyable:!0}].map(d=>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:d.label}),":",e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+(d.capitalize?" capitalize":""),children:d.value}),d.copyable&&e.jsx(a.Button,{variant:"ghost",size:"icon",className:"h-6 w-6",onClick:()=>A(d.value,d.label),children:e.jsx(f.Link,{className:"h-3 w-3"})})]})]},d.label))})]}),l.usedOn&&l.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(a.Label,{children:s("Used On")}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:l.usedOn.map((d,p)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:d.name}),e.jsxs("div",{className:"text-gray-500",children:["(",d.slug,")"]})]},p))})]}),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:s("Description")}),e.jsx(a.Textarea,{id:"description",value:v,placeholder:s("Enter a description for the asset"),onChange:d=>j(d.target.value),rows:3,disabled:o,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:()=>i(v),disabled:o||!J(v,l),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${o||!J(v,l)?"opacity-50 cursor-not-allowed":""}`,children:o?e.jsxs(e.Fragment,{children:[e.jsx(f.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),s("Saving...")]}):s("Save")})})]})]})]})]})},Ce=u.lazy(()=>Promise.resolve().then(()=>require("./image-editor-CnDnY97s.cjs"))),Ae=25*1024*1024,Se=({isUpdatingAsset:n,allowedTypes:r,uploadAssets:x,isUploadingAsset:i,onUploaded:o})=>{const{t:s}=M.useTranslation(),[l,E]=u.useState(()=>{const c=localStorage.getItem("chai_optimize_images");return c!==null?c==="true":!0});u.useEffect(()=>{localStorage.setItem("chai_optimize_images",l.toString())},[l]);const N=n||i,v=u.useCallback(async c=>{try{const m=c;if(!m.every(S=>S.type.startsWith("image/")))return w.toast.error(s("Invalid file type. Please upload a valid file.")),Promise.reject(new Error("Invalid file type"));const d=m.map(async S=>{let U=S;return S.type.startsWith("image/")&&(U=await Y.compressImageIfNeeded(S)),new Promise((_,B)=>{const L=new FileReader;L.readAsDataURL(U),L.onload=async()=>{_({file:L.result,folderId:void 0,name:S.name,optimize:l})},L.onerror=()=>B(null)})}),p=await Promise.all(d),y=await x(p);return(y==null?void 0:y.length)===1&&o(y[0]),y}catch(m){return Promise.reject(m)}},[x,l,o,s]),j=c=>{const m=[];let d=0;return c.forEach(p=>{p.size>Ae?d++:m.push(p)}),d>0&&w.toast.error(`${d===1&&c.length===1?s("File"):d+s(d===1?" file":" files")} ${s("exceed the maximum size limit of 10MB.")}`),F.isEmpty(m)?[]:v(m)},{getRootProps:b,getInputProps:C,isDragActive:A}=fe.useDropzone({onDrop:j,accept:{"image/*":r.includes("image")?[]:[]},disabled:n||i,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 ${N?"pointer-events-none bg-gray-100 opacity-90":"bg-gray-100 hover:border-black/50 hover:bg-gray-100"}`,children:e.jsxs("div",{...b(),className:M.mergeClasses("flex h-max w-full cursor-pointer flex-col justify-center rounded-lg text-center",N?"items-start":"items-center",A?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...C()}),N?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(f.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:s(n?"Updating file...":"Uploading file...")}),e.jsxs("div",{className:"text-xs font-light text-muted-foreground",children:[s("Please wait while we")," ",s(n?"update":"upload")," ",s("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(f.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:[s("Drop your file here or")," ",e.jsx("span",{className:"cursor-pointer text-indigo-500 hover:underline",children:s("browse")})]}),e.jsx("div",{className:"text-xs font-light text-muted-foreground",children:e.jsxs("span",{className:"",children:[s("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:[s("Optimization:")," "," ",e.jsx("span",{className:l?"text-indigo-600":"text-gray-400",children:s(l?"On":"Off")})]}),e.jsx(a.Switch,{checked:l,onCheckedChange:c=>{E(c)},onClick:c=>{c.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 ${l?"invisible":""}`,children:e.jsx(f.AlertTriangle,{className:"mr-1 h-4 w-4"})})}),e.jsx(a.TooltipContent,{side:"top",children:e.jsx("p",{className:"text-xs text-white",children:s("Warning: Unoptimized images may affect performance and page load times")})})]})})]})]})]})})};function Te({close:n,onSelect:r,mode:x="image",assetId:i}){const{t:o}=M.useTranslation(),s=!1,l=10,E=u.useMemo(()=>[x],[x]),[N,v]=u.useState(null),[j,b]=u.useState(null),[C,A]=u.useState(null),[c,m]=u.useState({show:!1,file:""}),[d,p]=u.useState(!1),[y,S]=u.useState(i?"details":"grid"),[U,_]=u.useState(""),[B,L]=u.useState(""),[P,Q]=u.useState(1),[R]=u.useState(30),[T,G]=u.useState([]);u.useEffect(()=>{i&&(v(i),S("details"))},[i]),u.useEffect(()=>{const t=setTimeout(()=>{_(B),Q(1)},300);return()=>clearTimeout(t)},[B]);const{data:q,isLoading:$,refetch:ee}=ye({search:U.toLowerCase().trim(),page:P,limit:R}),D=(q==null?void 0:q.assets)||[],te=(q==null?void 0:q.total)||0,I=Math.ceil(te/R);u.useEffect(()=>{$||I<=0||Q(t=>t>I?I:t<1?1:t)},[$,I]);const se=(D==null?void 0:D.length)>0,{mutate:ie}=ge(),{mutateAsync:K,isPending:le}=pe(),{mutateAsync:W,isPending:ae}=je(),V=u.useCallback(t=>{const h=Math.min(Math.max(1,t),Math.max(1,I));h!==P&&Q(h)},[I,P]),re=t=>{L(t.target.value)},ne=u.useCallback(t=>{G(h=>F.find(h,{id:t.id})?[]:[t])},[s]),oe=u.useCallback(()=>{G([])},[]),H=t=>{(t==null?void 0:t.length)!==0&&(r(F.pick(F.first(t||T),["id","url","width","height","description"])),n())},ce=async t=>{b(t)},de=async()=>{j&&(A(j==null?void 0:j.id),await ie(j.id,{onSuccess:()=>{A(null),b(null)},onError:()=>{A(null)}}),b(null))},ue=t=>{v(t.id),S("details")},me=async(t,h)=>{try{const O=localStorage.getItem("chai_optimize_images")!=="false";if(h){const k=await K([{file:t,folderId:void 0,name:c.name||"",optimize:O}]);if((k==null?void 0:k.length)>0){const X=k[0];r({...F.pick(X,["id","width","height","description"]),url:X.url})}}else{const k=await W({id:c.id||"",file:t});k&&r({...F.pick(k,["id","width","height","description"]),url:k.url})}m({show:!1,file:""}),n()}catch(O){console.error(o("Error saving edited image:"),O)}},he=u.useCallback(t=>{G([t])},[]),xe=u.useCallback(t=>{V(t)},[V]);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:o("Digital Asset Manager")}),y==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(Se,{maxFileSize:l,allowedTypes:E,uploadAssets:K,isUpdatingAsset:ae,isUploadingAsset:le,onUploaded:he}),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(f.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${B.length>0?"text-indigo-800":""}`}),e.jsx(a.Input,{placeholder:o("Search assets..."),onChange:re,value:B,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:()=>oe(),title:o("Clear selection"),children:o("Clear")})}),e.jsx(a.Button,{size:"sm",onClick:()=>H(T),disabled:T.length===0,children:o("Select Asset")})]})}):null,e.jsx(a.Button,{variant:"ghost",size:"icon",onClick:()=>ee(),children:e.jsx(f.RefreshCwIcon,{className:"h-4 w-4"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:$?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"})]}):!$&&!se?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(f.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-lg text-muted-foreground",children:o("No assets found")}),e.jsx("div",{className:"text-sm text-muted-foreground",children:U.length>0?o("No assets found for your search: {{query}}",{query:U}):o("Start uploading assets to get started")}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:D==null?void 0:D.map(t=>e.jsxs("div",{className:M.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",C&&(j==null?void 0:j.id)===t.id?"pointer-events-none opacity-50":"",C===t.id?"pointer-events-none opacity-50":""),onClick:()=>ne(t),onDoubleClick:()=>H([t]),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[C===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(f.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(f.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:Y.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(),ue(t)},children:e.jsx(f.ImageIcon,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("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),w.toast.success(o("Asset URL copied to clipboard"))},children:e.jsx(f.Copy,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("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(),m({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(f.Edit,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("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(),ce(t)},children:e.jsx(f.Trash2,{className:"h-4 w-4"})})}),e.jsx(a.TooltipContent,{children:e.jsx("p",{children:o("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(f.Check,{className:"h-3 w-3 text-white",strokeWidth:5})})]},t.id))})}),I>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 border-t bg-white p-4",children:e.jsx(g.ErrorBoundary,{fallback:e.jsx("div",{className:"text-red-500",children:o("Error loading pagination")}),children:e.jsx(ve,{currentPage:P,totalPages:I,onPageChange:xe,pageRangeDisplayed:3,showPageInput:!0})})})]})]}):e.jsx(we,{assetId:N||i||"",onBack:()=>{S("grid"),v(null)},onEdit:t=>{m({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(N){p(!0);try{const h=D.find(O=>O.id===N);h&&await W(F.merge(h,{description:t}))}finally{p(!1)}}},isSaving:d})]}),c.show&&e.jsx(u.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(f.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ce,{imageUrl:c.file,onSave:me,onClose:()=>m({show:!1,file:""}),defaultSavedImageName:c.name,isEditing:!!c.id})}),j&&e.jsx(a.Dialog,{open:!!j,onOpenChange:()=>b(null),children:e.jsxs(a.DialogContent,{children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:o("Delete Asset")}),e.jsx(a.DialogDescription,{children:o('Are you sure you want to delete "{{name}}"? This action cannot be undone.',{name:j.name})})]}),e.jsxs(a.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(a.Button,{variant:"outline",onClick:()=>b(null),children:o("Cancel")}),e.jsx(a.Button,{variant:"destructive",onClick:de,children:o("Delete")})]})]})})]})}exports.default=Te;
|
|
@@ -5,7 +5,7 @@ import { find as Ge, merge as Oe, pick as Y, first as Be, isEmpty as Ke } from "
|
|
|
5
5
|
import { ChevronLeft as he, ChevronRight as Qe, Loader as B, AlertCircle as Re, Copy as fe, Pencil as We, Link as Ve, Search as He, RefreshCwIcon as Xe, Archive as Ze, Film as Je, ImageIcon as Ye, Edit as et, Trash2 as tt, Check as it, Upload as lt, AlertTriangle as at } from "lucide-react";
|
|
6
6
|
import pe, { useState as y, useMemo as ge, useEffect as O, useCallback as M, Suspense as rt } from "react";
|
|
7
7
|
import { useDropzone as nt } from "react-dropzone";
|
|
8
|
-
import { aM as K,
|
|
8
|
+
import { aM as K, al as Q, A as b, aN as st } from "./index-e9WlBH0R.js";
|
|
9
9
|
import { toast as A } from "sonner";
|
|
10
10
|
import { f as ct, c as ot } from "./image-compression-DsZ1oqpb.js";
|
|
11
11
|
import { useQueryClient as te, useMutation as ie, useQuery as xe } from "@tanstack/react-query";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),p=require("./index-Pdb5tSRL.cjs"),N=require("@tanstack/react-query"),v=require("sonner"),E=require("@chaibuilder/sdk"),a=require("@chaibuilder/sdk/ui"),P=require("lodash-es"),C=require("lucide-react"),g=require("react"),A=require("./slug-input-vzNtu37S.cjs"),T=()=>{const t=p.useApiUrl(),u=N.useQueryClient(),h=p.useFetch();return N.useMutation({mutationFn:async({pageId:s,name:x,slug:r})=>{const o={pageId:s,name:x};return r&&(o.slug=r),await h(t,{action:"DUPLICATE_PAGE",data:o})},onSuccess:()=>{u.invalidateQueries({queryKey:[p.ACTIONS.GET_WEBSITE_PAGES]}),v.toast.success("Page duplicated successfully")},onError:s=>{v.toast.error("Failed to duplicate page",{description:s.message||"An error occurred while duplicating the page"})}})},w=({page:t,onClose:u,closePanel:h=()=>{}})=>{const{t:s}=E.useTranslation(),{mutate:x,isPending:r}=T(),[o,i]=g.useState(null),[d,D]=g.useState(`${t.name} (Copy)`),b=p.useChangePage(),n=P.isEmpty(t.slug),[m,I]=g.useState(n?"":`${t.slug.split("/").pop()}-copy`),f=n?"":P.initial(t.slug.split("/")).join("/"),[y,j]=g.useState(!1),q=l=>{if(l.preventDefault(),!d.trim()){i(s("Name is required"));return}if(!n&&!m.trim()){i(s("Slug is required"));return}i(null),j(!0);const S={pageId:t.id,name:d};n||(S.slug=`${f}/${m}`),x(S,{onSuccess:c=>{j(!1),u(),b(c.id,h)},onError:c=>{j(!1),c.code==="SLUG_EXISTS"?i(s("A page with this slug already exists. Please choose a different slug.")):c.code==="INVALID_SLUG"?i(s("The slug format is invalid. Please use only lowercase letters, numbers, and hyphens.")):c.code==="PERMISSION_DENIED"?i(s("You don't have permission to duplicate this page.")):i(c.message||s("Failed to duplicate page. Please try again later."))}})};return e.jsx(a.Dialog,{open:!!t,onOpenChange:u,children:e.jsxs(a.DialogContent,{className:"sm:max-w-[425px]",children:[e.jsxs(a.DialogHeader,{children:[e.jsx(a.DialogTitle,{children:s("Duplicate Page")}),e.jsx(a.DialogDescription,{children:s("Create a copy of the page with a new name and slug")})]}),e.jsxs("div",{className:"mb-4 rounded-md bg-gray-50 p-3",children:[e.jsxs("h3",{className:"mb-1 text-sm font-medium",children:[s("Duplicating:"),":"]}),e.jsxs("div",{className:"flex flex-col gap-1 text-sm text-gray-700",children:[e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Name"),":"]})," ",t.name]}),!n&&e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Slug"),":"]})," ",t.slug]}),e.jsxs("div",{children:[e.jsxs("span",{className:"font-medium",children:[s("Type"),":"]})," ",t.pageType]})]})]}),e.jsxs("form",{onSubmit:q,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"name",className:"text-sm",children:s("Name")}),e.jsx(a.Input,{id:"name",value:d,onChange:l=>D(l.target.value),required:!0})]}),!n&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(a.Label,{htmlFor:"slug",className:"text-sm",children:s("Slug")}),e.jsx(A.SlugInput,{value:m,onChange:l=>I(l),parentSlug:f,onValidationChange:l=>{i(l?null:s("Invalid slug"))}})]}),o&&e.jsxs(a.Alert,{variant:"destructive",className:"py-2",children:[e.jsx(C.AlertCircle,{className:"h-4 w-4"}),e.jsx("span",{className:"text-sm",children:o})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(a.Button,{type:"button",variant:"outline",onClick:u,disabled:r,children:s("Cancel")}),e.jsx(a.Button,{type:"submit",disabled:!d.trim()||!n&&!m.trim()||r||y,children:s(r||y?"Duplicating...":"Duplicate")})]})]})]})})};exports.default=w;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { jsx as t, jsxs as a } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
2
|
+
import { ak as C, al as A, A as T, am as w } from "./index-e9WlBH0R.js";
|
|
3
3
|
import { useQueryClient as F, useMutation as _ } from "@tanstack/react-query";
|
|
4
4
|
import { toast as v } from "sonner";
|
|
5
5
|
import { useTranslation as q } from "@chaibuilder/sdk";
|
|
6
|
-
import { Dialog as G, DialogContent as L, DialogHeader as U, DialogTitle as j, DialogDescription as $, Label as D, Input as O, Alert as
|
|
7
|
-
import { isEmpty as
|
|
8
|
-
import { AlertCircle as
|
|
6
|
+
import { Dialog as G, DialogContent as L, DialogHeader as U, DialogTitle as j, DialogDescription as $, Label as D, Input as O, Alert as k, Button as P } from "@chaibuilder/sdk/ui";
|
|
7
|
+
import { isEmpty as B, initial as M } from "lodash-es";
|
|
8
|
+
import { AlertCircle as Q } from "lucide-react";
|
|
9
9
|
import { useState as p } from "react";
|
|
10
|
-
import { S as
|
|
10
|
+
import { S as V } from "./slug-input-CumDDlCk.js";
|
|
11
11
|
const H = () => {
|
|
12
12
|
const s = C(), o = F(), g = A();
|
|
13
13
|
return _({
|
|
@@ -38,7 +38,7 @@ const H = () => {
|
|
|
38
38
|
closePanel: g = () => {
|
|
39
39
|
}
|
|
40
40
|
}) => {
|
|
41
|
-
const { t: e } = q(), { mutate: h, isPending: r } = H(), [u, i] = p(null), [m, x] = p(`${s.name} (Copy)`), I = w(), l =
|
|
41
|
+
const { t: e } = q(), { mutate: h, isPending: r } = H(), [u, i] = p(null), [m, x] = p(`${s.name} (Copy)`), I = w(), l = B(s.slug), [d, E] = p(l ? "" : `${s.slug.split("/").pop()}-copy`), y = l ? "" : M(s.slug.split("/")).join("/"), [N, f] = p(!1), b = (n) => {
|
|
42
42
|
if (n.preventDefault(), !m.trim()) {
|
|
43
43
|
i(e("Name is required"));
|
|
44
44
|
return;
|
|
@@ -106,7 +106,7 @@ const H = () => {
|
|
|
106
106
|
!l && /* @__PURE__ */ a("div", { className: "space-y-2", children: [
|
|
107
107
|
/* @__PURE__ */ t(D, { htmlFor: "slug", className: "text-sm", children: e("Slug") }),
|
|
108
108
|
/* @__PURE__ */ t(
|
|
109
|
-
|
|
109
|
+
V,
|
|
110
110
|
{
|
|
111
111
|
value: d,
|
|
112
112
|
onChange: (n) => E(n),
|
|
@@ -117,8 +117,8 @@ const H = () => {
|
|
|
117
117
|
}
|
|
118
118
|
)
|
|
119
119
|
] }),
|
|
120
|
-
u && /* @__PURE__ */ a(
|
|
121
|
-
/* @__PURE__ */ t(
|
|
120
|
+
u && /* @__PURE__ */ a(k, { variant: "destructive", className: "py-2", children: [
|
|
121
|
+
/* @__PURE__ */ t(Q, { className: "h-4 w-4" }),
|
|
122
122
|
/* @__PURE__ */ t("span", { className: "text-sm", children: u })
|
|
123
123
|
] }),
|
|
124
124
|
/* @__PURE__ */ a("div", { className: "flex justify-end gap-2", children: [
|
|
@@ -1 +1 @@
|
|
|
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"),h=require("lodash-es"),p=require("lucide-react"),d=require("react"),g=require("./index-
|
|
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"),h=require("lodash-es"),p=require("lucide-react"),d=require("react"),g=require("./index-Pdb5tSRL.cjs"),f=({isDefaultLang:r,searchQuery:l,setSearchQuery:c})=>e.jsx(a.Input,{type:"text",autoFocus:!0,value:r?l:"",onChange:t=>c(t.target.value),placeholder:r?"Search pages...":"To search select default language",disabled:!r,onKeyDown:t=>t.stopPropagation()}),m=({dynamicPage:r,setDynamicPage:l,searchQuery:c,setSearchQuery:t,dynamicPages:n})=>{const{selectedLang:o,fallbackLang:i}=x.useLanguages(),u=(o==null?void 0:o.length)===0;return e.jsxs(a.DropdownMenu,{children:[e.jsx(a.DropdownMenuTrigger,{asChild:!0,children:e.jsxs(a.Button,{variant:"ghost",className:"w-max focus:outline-none focus:ring-0 border-[0px] rounded-md py-1 text-sm h-max border border-gray-200 hover:bg-gray-100 pl-4",children:[r?h.get(r,"name"):"Select Page",e.jsx(p.ChevronDown,{className:"ml-2 h-4 w-4"})]})}),e.jsxs(a.DropdownMenuContent,{className:"w-96 divide-y shadow-xl p-0 max-h-[75vh]",children:[e.jsx("div",{className:"p-1.5 bg-gray-50/30",children:e.jsx(f,{isDefaultLang:u,searchQuery:c,setSearchQuery:t})}),(n==null?void 0:n.length)===0?e.jsx("div",{className:"h-24 text-xs flex items-center justify-center",children:"No pages found"}):n==null?void 0:n.map(s=>e.jsx(a.DropdownMenuItem,{onClick:()=>l(s),disabled:u?i!==s.lang:o!==s.lang,className:`flex flex-col justify-start cursor-pointer overflow-x-auto whitespace-nowrap no-scrollbar ${s.id===(r==null?void 0:r.id)?"bg-blue-50":"hover:bg-gray-50"}`,children:e.jsx("div",{className:"w-full text-xs whitespace-nowrap px-2 py-[2px]",children:e.jsxs("div",{className:"flex items-center gap-x-2",children:[e.jsx("span",{className:"font-medium",children:s.name}),e.jsx("span",{className:"font-mono font-medium text-gray-500 text-xs rounded-full px-2 py-[1px] border border-gray-300 truncate",children:s.slug})]})})},s.id))]})]})},j=()=>{const{dynamicPage:r,dynamicPages:l,allLangPages:c,selectedLang:t,searchQuery:n,updateDynamicPage:o,updateSearchQuery:i,onChangeLanguage:u}=g.useDynamicPageSelector(),s=d.useRef(void 0);return d.useEffect(()=>{s.current!==t&&r&&(u(),s.current=t)},[t,l]),e.jsx("div",{className:"relative",children:e.jsx(m,{dynamicPage:r,setDynamicPage:o,searchQuery:n,setSearchQuery:i,dynamicPages:c})})};exports.default=j;
|
|
@@ -4,7 +4,7 @@ import { DropdownMenu as h, DropdownMenuTrigger as p, Button as m, DropdownMenuC
|
|
|
4
4
|
import { get as v } from "lodash-es";
|
|
5
5
|
import { ChevronDown as w } from "lucide-react";
|
|
6
6
|
import { useRef as b, useEffect as N } from "react";
|
|
7
|
-
import { k as y } from "./index-
|
|
7
|
+
import { k as y } from "./index-e9WlBH0R.js";
|
|
8
8
|
const D = ({
|
|
9
9
|
isDefaultLang: e,
|
|
10
10
|
searchQuery: l,
|