@chaibuilder/pages 0.5.2 → 0.5.3
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/{B4MFY5CR-Dejj9XNi.cjs → B4MFY5CR--lNS1XOZ.cjs} +1 -1
- package/dist/{B4MFY5CR-CxaAsbN9.js → B4MFY5CR-SntV1tRS.js} +1 -1
- package/dist/{HO4MOOFI-DyGZciGV.js → HO4MOOFI-BqUF7yRt.js} +2 -2
- package/dist/{HO4MOOFI-aeWm2iw3.cjs → HO4MOOFI-Dtsz_siU.cjs} +1 -1
- package/dist/{HUY7CZI3-BKHbLpsl.js → HUY7CZI3-BQnbnmHI.js} +2 -2
- package/dist/{HUY7CZI3-CLInB0IP.cjs → HUY7CZI3-D_CODqZw.cjs} +1 -1
- package/dist/{digital-asset-manager-DJEJxRa5.js → digital-asset-manager-Biz2tg8j.js} +1 -1
- package/dist/{digital-asset-manager-GB5X0F5T.cjs → digital-asset-manager-_BA_7qEh.cjs} +1 -1
- package/dist/index-B0BuMI6F.cjs +2 -0
- package/dist/{index-TNPTcXFM.js → index-cpLk6vnM.js} +1001 -995
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/index-BV5BWsTF.cjs +0 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
var ps = Object.defineProperty;
|
|
2
2
|
var xs = (e, t, n) => t in e ? ps(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
3
|
var qe = (e, t, n) => xs(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
-
import { s as Vn, m as Gn, b as R, d as rr, e as U, a as m, f as W, h as oe, S as B, c as D, i as we, u as $e, j as V, k as A, l as Ne, o as ut, P as zo, n as j, D as ws, t as q, p as Ft, q as ln, r as k, v as F, w as $s, x as Rt, y as Cs, z as Ss, A as wn, F as ks, B as Es, C as Ds, E as Kt, G as Ms, H as As, I as Fs, J as or, K as Kr, L as Ts, M as qt, $ as Ro, N as Br, O as Is, Q as Ps, R as zn, T as Ls, U as Os, V as qs } from "./index-
|
|
4
|
+
import { s as Vn, m as Gn, b as R, d as rr, e as U, a as m, f as W, h as oe, S as B, c as D, i as we, u as $e, j as V, k as A, l as Ne, o as ut, P as zo, n as j, D as ws, t as q, p as Ft, q as ln, r as k, v as F, w as $s, x as Rt, y as Cs, z as Ss, A as wn, F as ks, B as Es, C as Ds, E as Kt, G as Ms, H as As, I as Fs, J as or, K as Kr, L as Ts, M as qt, $ as Ro, N as Br, O as Is, Q as Ps, R as zn, T as Ls, U as Os, V as qs } from "./index-cpLk6vnM.js";
|
|
5
5
|
var _s = (e) => e != null, zs = (e) => e.filter(_s);
|
|
6
6
|
function Rs(e) {
|
|
7
7
|
return (...t) => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c, T as l, P as m, a as u, D as v, Q as i } from "./B4MFY5CR-
|
|
2
|
-
import { g as d, c as f, a as e } from "./index-
|
|
1
|
+
import { c, T as l, P as m, a as u, D as v, Q as i } from "./B4MFY5CR-SntV1tRS.js";
|
|
2
|
+
import { g as d, c as f, a as e } from "./index-cpLk6vnM.js";
|
|
3
3
|
var p = (a) => {
|
|
4
4
|
const [r, t] = c({
|
|
5
5
|
prefix: "TanstackQueryDevtools"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./B4MFY5CR
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./B4MFY5CR--lNS1XOZ.cjs"),t=require("./index-B0BuMI6F.cjs");var s=c=>{const[r,o]=e.createLocalStorage({prefix:"TanstackQueryDevtools"}),l=t.getPreferredColorScheme(),a=t.createMemo(()=>{const n=r.theme_preference||e.THEME_PREFERENCE;return n!=="system"?n:l()});return t.createComponent(e.QueryDevtoolsContext.Provider,{value:c,get children(){return t.createComponent(e.PiPProvider,{localStore:r,setLocalStore:o,get children(){return t.createComponent(e.ThemeContext.Provider,{value:a,get children(){return t.createComponent(e.Devtools,{localStore:r,setLocalStore:o})}})}})}})},u=s;exports.default=u;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { c as s, T as c, P as u, a as i, b as m, C as P, Q as d } from "./B4MFY5CR-
|
|
2
|
-
import { g as v, c as C, a as e } from "./index-
|
|
1
|
+
import { c as s, T as c, P as u, a as i, b as m, C as P, Q as d } from "./B4MFY5CR-SntV1tRS.js";
|
|
2
|
+
import { g as v, c as C, a as e } from "./index-cpLk6vnM.js";
|
|
3
3
|
var h = (t) => {
|
|
4
4
|
const [r, o] = s({
|
|
5
5
|
prefix: "TanstackQueryDevtools"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./B4MFY5CR
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./B4MFY5CR--lNS1XOZ.cjs"),t=require("./index-B0BuMI6F.cjs");var u=o=>{const[r,n]=e.createLocalStorage({prefix:"TanstackQueryDevtools"}),c=t.getPreferredColorScheme(),a=t.createMemo(()=>{const l=r.theme_preference||e.THEME_PREFERENCE;return l!=="system"?l:c()});return t.createComponent(e.QueryDevtoolsContext.Provider,{value:o,get children(){return t.createComponent(e.PiPProvider,{disabled:!0,localStore:r,setLocalStore:n,get children(){return t.createComponent(e.ThemeContext.Provider,{value:a,get children(){return t.createComponent(e.ParentPanel,{get children(){return t.createComponent(e.ContentView,{localStore:r,setLocalStore:n,get onClose(){return o.onClose},showPanelViewOnly:!0})}})}})}})}})},i=u;exports.default=i;
|
|
@@ -7,7 +7,7 @@ import { Loader as F, AlertCircle as Me, ChevronLeft as Oe, Pencil as Ke, Search
|
|
|
7
7
|
import { useDropzone as Je } from "react-dropzone";
|
|
8
8
|
import { useQueryClient as R, useMutation as W, useQuery as le } from "@tanstack/react-query";
|
|
9
9
|
import { toast as j } from "sonner";
|
|
10
|
-
import { W as U, X as $, Y as y, Z as _ } from "./index-
|
|
10
|
+
import { W as U, X as $, Y as y, Z as _ } from "./index-cpLk6vnM.js";
|
|
11
11
|
const et = () => {
|
|
12
12
|
const n = U(), r = R(), s = $();
|
|
13
13
|
return W({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("react"),V=require("@chaibuilder/sdk"),r=require("@chaibuilder/sdk/ui"),B=require("lodash-es"),x=require("lucide-react"),me=require("react-dropzone"),C=require("@tanstack/react-query"),z=require("sonner"),c=require("./index-BV5BWsTF.cjs"),xe=()=>{const l=c.useAssetsApiUrl(),a=C.useQueryClient(),o=c.useFetch();return C.useMutation({mutationFn:async({file:s,folderId:m,name:i,optimize:g=!0})=>o(l,{action:c.ACTIONS.UPLOAD_ASSET,data:{file:s,folderId:m,name:i,optimize:g}}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);a.invalidateQueries({queryKey:[c.QUERY_KEY_BASE,c.ACTIONS.GET_ASSETS]}),z.toast.success("Asset uploaded successfully")},onError:()=>{z.toast.error("Failed to upload asset")}})},he=()=>{const l=c.useAssetsApiUrl(),a=C.useQueryClient(),o=c.useFetch();return C.useMutation({mutationFn:async s=>o(l,{action:c.ACTIONS.DELETE_ASSET,data:{id:s}}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);a.invalidateQueries({queryKey:[c.QUERY_KEY_BASE,c.ACTIONS.GET_ASSETS]}),z.toast.success("Asset deleted successfully")},onError:()=>{z.toast.error("Failed to delete asset")}})},fe=()=>{const l=c.useAssetsApiUrl(),a=C.useQueryClient(),o=c.useFetch();return C.useMutation({mutationFn:async s=>o(l,{action:c.ACTIONS.UPDATE_ASSET,data:s}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);a.invalidateQueries({queryKey:[c.QUERY_KEY_BASE,c.ACTIONS.GET_ASSETS]}),z.toast.success("Asset updated successfully")},onError:()=>{z.toast.error("Failed to update asset")}})},ge=(l={})=>{const a=c.useAssetsApiUrl(),o=c.useFetch(),{search:s,page:m=1,limit:i=30}=l;return C.useQuery({queryKey:[c.QUERY_KEY_BASE,c.ACTIONS.GET_ASSETS,s,m,i],queryFn:async()=>{const g=await o(a,{action:c.ACTIONS.GET_ASSETS,data:{search:s,page:m,limit:i}});return g.page=m,g.limit=i,g},staleTime:1e3*60*5,retry:1})},pe=l=>{const a=c.useAssetsApiUrl(),o=c.useFetch();return C.useQuery({queryKey:[c.QUERY_KEY_BASE,c.ACTIONS.GET_ASSET,l],queryFn:async()=>l?await o(a,{action:c.ACTIONS.GET_ASSET,data:{id:l}}):null,staleTime:1e3*60*5,retry:1})};function je(l){const a=isNaN(l)?0:typeof l=="number"?l:parseInt(l);return a?a<1024?`${a.toFixed(2)} B`:a<1024*1024?`${(a/1024).toFixed(2)} KB`:`${(a/(1024*1024)).toFixed(2)} MB`:"0 B"}function Y(l){if(!l)return"N/A";const a=new Date(l);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(a)}function G(l,a){let o=l,s=a==null?void 0:a.description;return(!s||typeof s!="string")&&(s=""),(!o||typeof o!="string")&&(o=""),o!==s}const ve=({assetId:l,onBack:a,onEdit:o,onSave:s,isSaving:m})=>{var N,S,f;const{data:i,isLoading:g,isError:p}=pe(l||""),[v,h]=n.useState("");return n.useEffect(()=>{i!=null&&i.description&&h(i.description)},[i]),g?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(x.Loader,{className:"h-8 w-8 animate-spin"})}):p||!(i!=null&&i.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(x.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:"No Asset Found"}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:p?"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(r.Button,{variant:"outline",onClick:a,children:"Back to Assets"}),p&&e.jsx(r.Button,{variant:"default",onClick:()=>window.location.reload(),children:"Try Again"})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(r.Button,{variant:"outline",size:"sm",onClick:a,disabled:m,children:[e.jsx(x.ChevronLeft,{className:"h-4 w-4"}),"Back to Assets"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(r.Button,{variant:"outline",onClick:a,disabled:m,children:"Cancel"}),e.jsxs(r.Button,{variant:"default",onClick:()=>o(i),disabled:m,children:[e.jsx(x.Pencil,{className:"h-4 w-4"}),"Edit Image"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:`${i.url}?v=${((N=i.metadata)==null?void 0:N.updatedAt)||i.createdAt}`,alt:i.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(r.Label,{className:"w-full text-center",children:"Details"}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:"File Name",value:i.name},{label:"Type",value:i.type,capitalize:!0},{label:"Format",value:((S=i.metadata)==null?void 0:S.format)||i.type,capitalize:!0},{label:"Size",value:je(i.size)},{label:"Dimensions",value:`${i.width||0} × ${i.height||0}`},{label:"Created",value:Y(i.createdAt)},{label:"Updated",value:Y(((f=i.metadata)==null?void 0:f.updatedAt)||i.createdAt)}].map(u=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(r.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:u.label}),":",e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+u.capitalize?" capitalize":"",children:u.value})]},u.label))})]}),i.usedOn&&i.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(r.Label,{children:"Used On"}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:i.usedOn.map((u,y)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:u.name}),e.jsxs("div",{className:"text-gray-500",children:["(",u.slug,")"]})]},y))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(r.Label,{className:"w-full text-center",children:"Description"}),e.jsx(r.Textarea,{id:"description",value:v,placeholder:"Enter a description for the asset",onChange:u=>h(u.target.value),rows:3,disabled:m,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>s(v),disabled:m||!G(v,i),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${m||!G(v,i)?"opacity-50 cursor-not-allowed":""}`,children:m?e.jsxs(e.Fragment,{children:[e.jsx(x.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):"Save"})})]})]})]})]})},Ne=n.lazy(()=>Promise.resolve().then(()=>require("./image-editor-BWLJT1mr.cjs")));function ye(l){const a=isNaN(l)?0:typeof l=="number"?l:parseInt(l);return a?a<1024?`${a.toFixed(2)} B`:a<1024*1024?`${(a/1024).toFixed(2)} KB`:`${(a/(1024*1024)).toFixed(2)} MB`:"0 B"}const be=({isUpdatingAsset:l,allowedTypes:a,maxFileSize:o,uploadAsset:s,isUploadingAsset:m})=>{const[i,g]=n.useState(()=>{const f=localStorage.getItem("chai_optimize_images");return f!==null?f==="true":!0});n.useEffect(()=>{localStorage.setItem("chai_optimize_images",i.toString())},[i]);const p=l||m,v=n.useCallback(async f=>new Promise((u,y)=>{const F=f[0],E=new FileReader;E.readAsDataURL(F),E.onload=async()=>{const D=await s({file:E.result,folderId:void 0,name:F.name,optimize:i});u(D)},E.onerror=D=>y(D)}),[s,i]),{getRootProps:h,getInputProps:N,isDragActive:S}=me.useDropzone({onDrop:v,accept:{"image/*":a.includes("image")?[]:[]},maxSize:o*1024*1024,disabled:l||m});return e.jsx("div",{className:`flex flex-col items-center justify-center w-full border-2 hover:border-black/50 border-dashed p-0 rounded-lg border-slate-300 py-2 h-[60px] ${p?"opacity-90 bg-gray-100 pointer-events-none":"hover:border-black/50 bg-gray-100 hover:bg-gray-100"}`,children:e.jsxs("div",{...h(),className:V.mergeClasses("rounded-lg text-center cursor-pointer w-full h-max flex flex-col justify-center",p?"items-start":"items-center",S?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...N()}),p?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"leading-tight flex items-center justify-center gap-2",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(x.Loader,{className:"h-4 w-4 text-indigo-500 animate-spin"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:l?"Updating file...":"Uploading file..."}),e.jsxs("div",{className:"text-xs text-muted-foreground font-light",children:["Please wait while we ",l?"update":"upload"," ","your file..."]})]})]})}):e.jsxs("div",{className:"flex items-center justify-between w-full px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"leading-tight flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2 border border-indigo-500",children:e.jsx(x.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:["Drop your file here or"," ",e.jsx("span",{className:"text-indigo-500 cursor-pointer hover:underline",children:"browse"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground font-light",children:[e.jsxs("span",{className:"",children:["Accepted file types:"," ",e.jsx("span",{className:"capitalize text-indigo-400",children:a.join(", ")})," & "]}),e.jsxs("span",{children:["Max file size:"," ",e.jsxs("span",{className:"capitalize text-indigo-400",children:[o," MB"]})]})]})]})]})}),e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:["Optimization:"," ",e.jsx("span",{className:i?"text-indigo-600":"text-gray-400",children:i?"On":"Off"})]}),e.jsx(r.Switch,{checked:i,onCheckedChange:f=>{g(f)},onClick:f=>{f.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(r.TooltipProvider,{children:e.jsxs(r.Tooltip,{children:[e.jsx(r.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`text-amber-500 flex items-center cursor-help ${i?"invisible":""}`,children:e.jsx(x.AlertTriangle,{className:"h-4 w-4 mr-1"})})}),e.jsx(r.TooltipContent,{side:"top",children:e.jsxs("p",{className:"text-white text-xs",children:["Warning: Unoptimized images may affect ",e.jsx("br",{})," performance and page load times"]})})]})})]})]})]})})};function we({close:l,onSelect:a,mode:o="image",assetId:s}){const g=n.useMemo(()=>[o],[o]),[p,v]=n.useState(null),[h,N]=n.useState(null),[S,f]=n.useState(null),[u,y]=n.useState({show:!1,file:""}),[F,E]=n.useState(!1),[D,U]=n.useState(s?"details":"grid"),[q,W]=n.useState(""),[P,H]=n.useState(""),[b,$]=n.useState(1),[L]=n.useState(30),[w,Q]=n.useState([]);n.useEffect(()=>{s&&(v(s),U("details"))},[s]),n.useEffect(()=>{const t=setTimeout(()=>{W(P),$(1)},300);return()=>clearTimeout(t)},[P]);const{data:k,isLoading:M}=ge({search:q.toLowerCase().trim(),page:b,limit:L}),T=(k==null?void 0:k.assets)||[],J=(k==null?void 0:k.total)||0,A=Math.ceil(J/L),O=b<A,_=b>1,X=(T==null?void 0:T.length)>0,{mutate:Z}=he(),{mutate:K,isPending:ee}=xe(),{mutate:R,isPending:te}=fe(),I=n.useCallback(t=>{t>=1&&t<=A&&$(t)},[A]),se=n.useCallback(()=>{O&&I(b+1)},[b,O,I]),ie=n.useCallback(()=>{_&&I(b-1)},[b,_,I]),ae=t=>{H(t.target.value)},le=n.useCallback(t=>{Q(d=>B.find(d,{id:t.id})?[]:[t])},[!1]),re=n.useCallback(()=>{Q([])},[]),ne=()=>{w.length!==0&&(a(B.pick(B.first(w),["id","url","width","height","description"])),l())},ce=async t=>{N(t)},oe=async()=>{h&&(f(h==null?void 0:h.id),await Z(h.id,{onSuccess:()=>{f(null),N(null)},onError:()=>{f(null)}}),N(null))},de=t=>{v(t.id),U("details")},ue=async(t,d)=>{try{const j=localStorage.getItem("chai_optimize_images")!=="false";d?(await K({file:t,folderId:void 0,name:u.name||"",optimize:j}),y({show:!1,file:""})):(await R({id:u.id||"",file:t}),y({show:!1,file:""}))}catch(j){console.error("Error saving edited image:",j)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"max-w-[1232px] max-h-[1232px] w-[80vw] h-[80vh] space-y-4 flex flex-col",children:[e.jsx("h1",{className:"text-lg font-medium",children:"Digital Asset Manager"}),D==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(be,{maxFileSize:10,allowedTypes:g,uploadAsset:K,isUpdatingAsset:te,isUploadingAsset:ee}),e.jsxs("div",{className:"border p-2 rounded-lg flex-1 flex flex-col gap-y-3 overflow-hidden relative",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2 ",children:[e.jsx(x.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${P.length>0?"text-indigo-800":""}`}),e.jsx(r.Input,{placeholder:"Search assets...",onChange:ae,value:P,className:"pl-8"})]}),w.length>0?e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs("div",{className:"flex items-center gap-2",children:[w.length>0&&e.jsx(e.Fragment,{children:e.jsx(r.Button,{variant:"outline",size:"sm",onClick:()=>re(),title:"Clear selection",children:"Clear"})}),e.jsx(r.Button,{size:"sm",onClick:ne,disabled:w.length===0,children:"Select Asset"})]})}):null]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:M?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"})]}):!M&&!X?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full border rounded-lg",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(x.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-muted-foreground text-lg",children:"No assets found"}),e.jsx("div",{className:"text-muted-foreground text-sm",children:q.length>0?"No assets found for your search: "+q:"Start uploading assets to get started"}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:T==null?void 0:T.map(t=>e.jsxs("div",{className:V.mergeClasses("relative cursor-pointer overflow-hidden transition-all rounded-lg border-2 group max-w-[180px] max-h-[180px] flex flex-col justify-between",w.some(d=>d.id===t.id)?"border-blue-500":"hover:border-black/90",S&&(h==null?void 0:h.id)===t.id?"opacity-50 pointer-events-none":"",S===t.id?"opacity-50 pointer-events-none":""),onClick:()=>le(t),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[S===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(x.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:`object-contain w-full h-full min-h-[80px] ${w.some(d=>d.id===t.id)?"":"group-hover:blur-sm group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex items-center justify-center h-full",children:[e.jsx(x.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 object-cover w-full h-full"})]})]}),e.jsxs("div",{className:"py-1 px-2 flex items-end justify-between bg-white border-t-[1px] border-black/10",children:[e.jsx("div",{className:"text-xs truncate leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"text-[9px] whitespace-nowrap font-light text-muted-foreground flex items-center justify-between",children:e.jsx("span",{children:ye((t==null?void 0:t.size)||0)})})]}),!w.some(d=>d.id===t.id)&&e.jsxs("div",{className:"absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2",children:[e.jsx(r.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:d=>{d.stopPropagation(),de(t)},children:e.jsx(x.ImageIcon,{className:"h-4 w-4"})}),e.jsx(r.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:d=>{d.stopPropagation(),y({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(x.Edit,{className:"h-4 w-4"})}),e.jsx(r.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:d=>{d.stopPropagation(),ce(t)},children:e.jsx(x.Trash2,{className:"h-4 w-4"})})]}),w.some(d=>d.id===t.id)&&e.jsx("div",{className:"absolute top-1 right-1 border border-white h-max rounded-full bg-blue-500 p-1",children:e.jsx(x.Check,{className:"w-3 h-3 text-white",strokeWidth:5})})]},t.id))})}),A>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-white border-t p-4",children:e.jsxs("div",{className:"flex items-center justify-center space-x-2",children:[e.jsx(r.Button,{variant:"outline",size:"sm",onClick:ie,disabled:!_,children:"Previous"}),Array.from({length:Math.min(5,A)},(t,d)=>{const j=d+1;return e.jsx(r.Button,{variant:b===j?"default":"outline",size:"sm",onClick:()=>I(j),children:j},j)}),A>5&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-muted-foreground",children:"..."}),e.jsx(r.Button,{variant:b===A?"default":"outline",size:"sm",onClick:()=>I(A),children:A})]}),e.jsx(r.Button,{variant:"outline",size:"sm",onClick:se,disabled:!O,children:"Next"})]})})]})]}):e.jsx(ve,{assetId:p||s||"",onBack:()=>{U("grid"),v(null)},onEdit:t=>{y({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(p){E(!0);try{const d=T.find(j=>j.id===p);d&&await R(B.merge(d,{description:t}))}finally{E(!1)}}},isSaving:F})]}),u.show&&e.jsx(n.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(x.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ne,{imageUrl:u.file,onSave:ue,onClose:()=>y({show:!1,file:""}),defaultSavedImageName:u.name,isEditing:!!u.id})}),h&&e.jsx(r.Dialog,{open:!!h,onOpenChange:()=>N(null),children:e.jsxs(r.DialogContent,{children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Delete Asset"}),e.jsxs(r.DialogDescription,{children:['Are you sure you want to delete "',h.name,'"? This action cannot be undone.']})]}),e.jsxs(r.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(r.Button,{variant:"outline",onClick:()=>N(null),children:"Cancel"}),e.jsx(r.Button,{variant:"destructive",onClick:oe,children:"Delete"})]})]})})]})}exports.default=we;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("react"),V=require("@chaibuilder/sdk"),r=require("@chaibuilder/sdk/ui"),B=require("lodash-es"),x=require("lucide-react"),me=require("react-dropzone"),C=require("@tanstack/react-query"),z=require("sonner"),c=require("./index-B0BuMI6F.cjs"),xe=()=>{const l=c.useAssetsApiUrl(),a=C.useQueryClient(),o=c.useFetch();return C.useMutation({mutationFn:async({file:s,folderId:m,name:i,optimize:g=!0})=>o(l,{action:c.ACTIONS.UPLOAD_ASSET,data:{file:s,folderId:m,name:i,optimize:g}}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);a.invalidateQueries({queryKey:[c.QUERY_KEY_BASE,c.ACTIONS.GET_ASSETS]}),z.toast.success("Asset uploaded successfully")},onError:()=>{z.toast.error("Failed to upload asset")}})},he=()=>{const l=c.useAssetsApiUrl(),a=C.useQueryClient(),o=c.useFetch();return C.useMutation({mutationFn:async s=>o(l,{action:c.ACTIONS.DELETE_ASSET,data:{id:s}}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);a.invalidateQueries({queryKey:[c.QUERY_KEY_BASE,c.ACTIONS.GET_ASSETS]}),z.toast.success("Asset deleted successfully")},onError:()=>{z.toast.error("Failed to delete asset")}})},fe=()=>{const l=c.useAssetsApiUrl(),a=C.useQueryClient(),o=c.useFetch();return C.useMutation({mutationFn:async s=>o(l,{action:c.ACTIONS.UPDATE_ASSET,data:s}),onSuccess:s=>{if(s!=null&&s.error)throw new Error(s==null?void 0:s.error);a.invalidateQueries({queryKey:[c.QUERY_KEY_BASE,c.ACTIONS.GET_ASSETS]}),z.toast.success("Asset updated successfully")},onError:()=>{z.toast.error("Failed to update asset")}})},ge=(l={})=>{const a=c.useAssetsApiUrl(),o=c.useFetch(),{search:s,page:m=1,limit:i=30}=l;return C.useQuery({queryKey:[c.QUERY_KEY_BASE,c.ACTIONS.GET_ASSETS,s,m,i],queryFn:async()=>{const g=await o(a,{action:c.ACTIONS.GET_ASSETS,data:{search:s,page:m,limit:i}});return g.page=m,g.limit=i,g},staleTime:1e3*60*5,retry:1})},pe=l=>{const a=c.useAssetsApiUrl(),o=c.useFetch();return C.useQuery({queryKey:[c.QUERY_KEY_BASE,c.ACTIONS.GET_ASSET,l],queryFn:async()=>l?await o(a,{action:c.ACTIONS.GET_ASSET,data:{id:l}}):null,staleTime:1e3*60*5,retry:1})};function je(l){const a=isNaN(l)?0:typeof l=="number"?l:parseInt(l);return a?a<1024?`${a.toFixed(2)} B`:a<1024*1024?`${(a/1024).toFixed(2)} KB`:`${(a/(1024*1024)).toFixed(2)} MB`:"0 B"}function Y(l){if(!l)return"N/A";const a=new Date(l);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric",hour:"2-digit",minute:"2-digit"}).format(a)}function G(l,a){let o=l,s=a==null?void 0:a.description;return(!s||typeof s!="string")&&(s=""),(!o||typeof o!="string")&&(o=""),o!==s}const ve=({assetId:l,onBack:a,onEdit:o,onSave:s,isSaving:m})=>{var N,S,f;const{data:i,isLoading:g,isError:p}=pe(l||""),[v,h]=n.useState("");return n.useEffect(()=>{i!=null&&i.description&&h(i.description)},[i]),g?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsx(x.Loader,{className:"h-8 w-8 animate-spin"})}):p||!(i!=null&&i.id)?e.jsx("div",{className:"flex-1 flex items-center justify-center",children:e.jsxs("div",{className:"text-center max-w-md mx-auto p-6",children:[e.jsx("div",{className:"flex justify-center mb-4",children:e.jsx(x.AlertCircle,{className:"h-12 w-12 text-gray-400"})}),e.jsx("h3",{className:"text-lg font-medium text-gray-900 mb-2",children:"No Asset Found"}),e.jsx("p",{className:"text-sm text-gray-500 mb-6",children:p?"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(r.Button,{variant:"outline",onClick:a,children:"Back to Assets"}),p&&e.jsx(r.Button,{variant:"default",onClick:()=>window.location.reload(),children:"Try Again"})]})]})}):e.jsxs("div",{className:"flex-1 flex flex-col gap-y-4 overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs(r.Button,{variant:"outline",size:"sm",onClick:a,disabled:m,children:[e.jsx(x.ChevronLeft,{className:"h-4 w-4"}),"Back to Assets"]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(r.Button,{variant:"outline",onClick:a,disabled:m,children:"Cancel"}),e.jsxs(r.Button,{variant:"default",onClick:()=>o(i),disabled:m,children:[e.jsx(x.Pencil,{className:"h-4 w-4"}),"Edit Image"]})]})]}),e.jsxs("div",{className:"grid grid-cols-2 items-start gap-6 flex-1 overflow-hidden",children:[e.jsx("div",{className:"relative h-[calc(80vh-200px)] w-full flex items-start justify-center",children:e.jsx("img",{src:`${i.url}?v=${((N=i.metadata)==null?void 0:N.updatedAt)||i.createdAt}`,alt:i.name,className:"w-full h-full object-contain rounded-lg max-h-max max-w-max"})}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100",children:[e.jsx(r.Label,{className:"w-full text-center",children:"Details"}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2 bg-white",children:[{label:"File Name",value:i.name},{label:"Type",value:i.type,capitalize:!0},{label:"Format",value:((S=i.metadata)==null?void 0:S.format)||i.type,capitalize:!0},{label:"Size",value:je(i.size)},{label:"Dimensions",value:`${i.width||0} × ${i.height||0}`},{label:"Created",value:Y(i.createdAt)},{label:"Updated",value:Y(((f=i.metadata)==null?void 0:f.updatedAt)||i.createdAt)}].map(u=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(r.Label,{className:"w-max text-left px-2 w-1/4 font-normal text-gray-700",children:u.label}),":",e.jsx("div",{className:"w-max text-left font-medium text-gray-900"+u.capitalize?" capitalize":"",children:u.value})]},u.label))})]}),i.usedOn&&i.usedOn.length>0&&e.jsxs("div",{className:"grid gap-3",children:[e.jsx(r.Label,{children:"Used On"}),e.jsx("div",{className:"grid grid-cols-1 gap-2 text-sm border rounded-md p-2",children:i.usedOn.map((u,y)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-max text-left font-medium text-gray-900",children:u.name}),e.jsxs("div",{className:"text-gray-500",children:["(",u.slug,")"]})]},y))})]}),e.jsxs("div",{className:"grid gap-3 border rounded-md pt-2 bg-gray-100 relative",children:[e.jsx(r.Label,{className:"w-full text-center",children:"Description"}),e.jsx(r.Textarea,{id:"description",value:v,placeholder:"Enter a description for the asset",onChange:u=>h(u.target.value),rows:3,disabled:m,className:"hover:border-black/40 bg-white"}),e.jsx("div",{className:"flex justify-end items-start absolute top-1.5 right-2",children:e.jsx("button",{type:"button",onClick:()=>s(v),disabled:m||!G(v,i),className:`py-0 bg-blue-500 text-white px-3 py-0.5 rounded-md text-sm ${m||!G(v,i)?"opacity-50 cursor-not-allowed":""}`,children:m?e.jsxs(e.Fragment,{children:[e.jsx(x.Loader,{className:"h-4 w-4 mr-2 animate-spin"}),"Saving..."]}):"Save"})})]})]})]})]})},Ne=n.lazy(()=>Promise.resolve().then(()=>require("./image-editor-BWLJT1mr.cjs")));function ye(l){const a=isNaN(l)?0:typeof l=="number"?l:parseInt(l);return a?a<1024?`${a.toFixed(2)} B`:a<1024*1024?`${(a/1024).toFixed(2)} KB`:`${(a/(1024*1024)).toFixed(2)} MB`:"0 B"}const be=({isUpdatingAsset:l,allowedTypes:a,maxFileSize:o,uploadAsset:s,isUploadingAsset:m})=>{const[i,g]=n.useState(()=>{const f=localStorage.getItem("chai_optimize_images");return f!==null?f==="true":!0});n.useEffect(()=>{localStorage.setItem("chai_optimize_images",i.toString())},[i]);const p=l||m,v=n.useCallback(async f=>new Promise((u,y)=>{const F=f[0],E=new FileReader;E.readAsDataURL(F),E.onload=async()=>{const D=await s({file:E.result,folderId:void 0,name:F.name,optimize:i});u(D)},E.onerror=D=>y(D)}),[s,i]),{getRootProps:h,getInputProps:N,isDragActive:S}=me.useDropzone({onDrop:v,accept:{"image/*":a.includes("image")?[]:[]},maxSize:o*1024*1024,disabled:l||m});return e.jsx("div",{className:`flex flex-col items-center justify-center w-full border-2 hover:border-black/50 border-dashed p-0 rounded-lg border-slate-300 py-2 h-[60px] ${p?"opacity-90 bg-gray-100 pointer-events-none":"hover:border-black/50 bg-gray-100 hover:bg-gray-100"}`,children:e.jsxs("div",{...h(),className:V.mergeClasses("rounded-lg text-center cursor-pointer w-full h-max flex flex-col justify-center",p?"items-start":"items-center",S?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...N()}),p?e.jsx("div",{className:"flex flex-col items-center px-6",children:e.jsxs("div",{className:"leading-tight flex items-center justify-center gap-2",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2",children:e.jsx(x.Loader,{className:"h-4 w-4 text-indigo-500 animate-spin"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("div",{className:"font-medium",children:l?"Updating file...":"Uploading file..."}),e.jsxs("div",{className:"text-xs text-muted-foreground font-light",children:["Please wait while we ",l?"update":"upload"," ","your file..."]})]})]})}):e.jsxs("div",{className:"flex items-center justify-between w-full px-6",children:[e.jsx("div",{className:"flex flex-col items-center",children:e.jsxs("div",{className:"leading-tight flex items-center justify-between gap-2",children:[e.jsx("div",{className:"flex items-center justify-center rounded-full bg-indigo-100 p-2 border border-indigo-500",children:e.jsx(x.Upload,{className:"h-4 w-4 text-indigo-500"})}),e.jsxs("div",{className:"text-left",children:[e.jsxs("div",{className:"font-medium",children:["Drop your file here or"," ",e.jsx("span",{className:"text-indigo-500 cursor-pointer hover:underline",children:"browse"})]}),e.jsxs("div",{className:"text-xs text-muted-foreground font-light",children:[e.jsxs("span",{className:"",children:["Accepted file types:"," ",e.jsx("span",{className:"capitalize text-indigo-400",children:a.join(", ")})," & "]}),e.jsxs("span",{children:["Max file size:"," ",e.jsxs("span",{className:"capitalize text-indigo-400",children:[o," MB"]})]})]})]})]})}),e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center gap-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("span",{className:"text-xs",children:["Optimization:"," ",e.jsx("span",{className:i?"text-indigo-600":"text-gray-400",children:i?"On":"Off"})]}),e.jsx(r.Switch,{checked:i,onCheckedChange:f=>{g(f)},onClick:f=>{f.stopPropagation()},className:"data-[state=checked]:bg-indigo-500"})]}),e.jsx(r.TooltipProvider,{children:e.jsxs(r.Tooltip,{children:[e.jsx(r.TooltipTrigger,{asChild:!0,children:e.jsx("span",{className:`text-amber-500 flex items-center cursor-help ${i?"invisible":""}`,children:e.jsx(x.AlertTriangle,{className:"h-4 w-4 mr-1"})})}),e.jsx(r.TooltipContent,{side:"top",children:e.jsxs("p",{className:"text-white text-xs",children:["Warning: Unoptimized images may affect ",e.jsx("br",{})," performance and page load times"]})})]})})]})]})]})})};function we({close:l,onSelect:a,mode:o="image",assetId:s}){const g=n.useMemo(()=>[o],[o]),[p,v]=n.useState(null),[h,N]=n.useState(null),[S,f]=n.useState(null),[u,y]=n.useState({show:!1,file:""}),[F,E]=n.useState(!1),[D,U]=n.useState(s?"details":"grid"),[q,W]=n.useState(""),[P,H]=n.useState(""),[b,$]=n.useState(1),[L]=n.useState(30),[w,Q]=n.useState([]);n.useEffect(()=>{s&&(v(s),U("details"))},[s]),n.useEffect(()=>{const t=setTimeout(()=>{W(P),$(1)},300);return()=>clearTimeout(t)},[P]);const{data:k,isLoading:M}=ge({search:q.toLowerCase().trim(),page:b,limit:L}),T=(k==null?void 0:k.assets)||[],J=(k==null?void 0:k.total)||0,A=Math.ceil(J/L),O=b<A,_=b>1,X=(T==null?void 0:T.length)>0,{mutate:Z}=he(),{mutate:K,isPending:ee}=xe(),{mutate:R,isPending:te}=fe(),I=n.useCallback(t=>{t>=1&&t<=A&&$(t)},[A]),se=n.useCallback(()=>{O&&I(b+1)},[b,O,I]),ie=n.useCallback(()=>{_&&I(b-1)},[b,_,I]),ae=t=>{H(t.target.value)},le=n.useCallback(t=>{Q(d=>B.find(d,{id:t.id})?[]:[t])},[!1]),re=n.useCallback(()=>{Q([])},[]),ne=()=>{w.length!==0&&(a(B.pick(B.first(w),["id","url","width","height","description"])),l())},ce=async t=>{N(t)},oe=async()=>{h&&(f(h==null?void 0:h.id),await Z(h.id,{onSuccess:()=>{f(null),N(null)},onError:()=>{f(null)}}),N(null))},de=t=>{v(t.id),U("details")},ue=async(t,d)=>{try{const j=localStorage.getItem("chai_optimize_images")!=="false";d?(await K({file:t,folderId:void 0,name:u.name||"",optimize:j}),y({show:!1,file:""})):(await R({id:u.id||"",file:t}),y({show:!1,file:""}))}catch(j){console.error("Error saving edited image:",j)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"max-w-[1232px] max-h-[1232px] w-[80vw] h-[80vh] space-y-4 flex flex-col",children:[e.jsx("h1",{className:"text-lg font-medium",children:"Digital Asset Manager"}),D==="grid"?e.jsxs(e.Fragment,{children:[e.jsx(be,{maxFileSize:10,allowedTypes:g,uploadAsset:K,isUpdatingAsset:te,isUploadingAsset:ee}),e.jsxs("div",{className:"border p-2 rounded-lg flex-1 flex flex-col gap-y-3 overflow-hidden relative",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"relative w-1/2 ",children:[e.jsx(x.Search,{strokeWidth:3,className:`absolute left-2 top-2.5 h-4 w-4 text-muted-foreground ${P.length>0?"text-indigo-800":""}`}),e.jsx(r.Input,{placeholder:"Search assets...",onChange:ae,value:P,className:"pl-8"})]}),w.length>0?e.jsx("div",{className:"flex justify-between items-center",children:e.jsxs("div",{className:"flex items-center gap-2",children:[w.length>0&&e.jsx(e.Fragment,{children:e.jsx(r.Button,{variant:"outline",size:"sm",onClick:()=>re(),title:"Clear selection",children:"Clear"})}),e.jsx(r.Button,{size:"sm",onClick:ne,disabled:w.length===0,children:"Select Asset"})]})}):null]}),e.jsx("div",{className:"flex-1 overflow-y-auto pb-[66px]",children:M?e.jsxs("div",{className:"columns-1 gap-3 space-y-3 sm:columns-3 md:columns-5",children:[e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"}),e.jsx("div",{className:"bg-gray-200 h-64 w-full animate-pulse rounded"})]}):!M&&!X?e.jsxs("div",{className:"flex flex-col items-center justify-center h-full border rounded-lg",children:[e.jsx("div",{className:"text-muted-foreground",children:e.jsx(x.Archive,{className:"h-9 w-9 text-indigo-500"})}),e.jsx("div",{className:"text-muted-foreground text-lg",children:"No assets found"}),e.jsx("div",{className:"text-muted-foreground text-sm",children:q.length>0?"No assets found for your search: "+q:"Start uploading assets to get started"}),e.jsx("br",{})]}):e.jsx("div",{className:"flex flex-wrap gap-3 p-1",children:T==null?void 0:T.map(t=>e.jsxs("div",{className:V.mergeClasses("relative cursor-pointer overflow-hidden transition-all rounded-lg border-2 group max-w-[180px] max-h-[180px] flex flex-col justify-between",w.some(d=>d.id===t.id)?"border-blue-500":"hover:border-black/90",S&&(h==null?void 0:h.id)===t.id?"opacity-50 pointer-events-none":"",S===t.id?"opacity-50 pointer-events-none":""),onClick:()=>le(t),children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden",children:[S===t.id?e.jsx("div",{className:"absolute inset-0 flex items-center justify-center bg-black/50",children:e.jsx(x.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:`object-contain w-full h-full min-h-[80px] ${w.some(d=>d.id===t.id)?"":"group-hover:blur-sm group-hover:contrast-50"}`}):e.jsxs("div",{className:"flex items-center justify-center h-full",children:[e.jsx(x.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 object-cover w-full h-full"})]})]}),e.jsxs("div",{className:"py-1 px-2 flex items-end justify-between bg-white border-t-[1px] border-black/10",children:[e.jsx("div",{className:"text-xs truncate leading-tight",title:t.name,children:t.name}),e.jsx("div",{className:"text-[9px] whitespace-nowrap font-light text-muted-foreground flex items-center justify-between",children:e.jsx("span",{children:ye((t==null?void 0:t.size)||0)})})]}),!w.some(d=>d.id===t.id)&&e.jsxs("div",{className:"absolute inset-0 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2",children:[e.jsx(r.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:d=>{d.stopPropagation(),de(t)},children:e.jsx(x.ImageIcon,{className:"h-4 w-4"})}),e.jsx(r.Button,{variant:"secondary",size:"icon",className:"h-8 w-8 rounded-full",onClick:d=>{d.stopPropagation(),y({id:t.id,show:!0,file:t.url,name:t.name})},children:e.jsx(x.Edit,{className:"h-4 w-4"})}),e.jsx(r.Button,{variant:"destructive",size:"icon",className:"h-8 w-8 rounded-full",onClick:d=>{d.stopPropagation(),ce(t)},children:e.jsx(x.Trash2,{className:"h-4 w-4"})})]}),w.some(d=>d.id===t.id)&&e.jsx("div",{className:"absolute top-1 right-1 border border-white h-max rounded-full bg-blue-500 p-1",children:e.jsx(x.Check,{className:"w-3 h-3 text-white",strokeWidth:5})})]},t.id))})}),A>1&&e.jsx("div",{className:"absolute bottom-0 left-0 right-0 bg-white border-t p-4",children:e.jsxs("div",{className:"flex items-center justify-center space-x-2",children:[e.jsx(r.Button,{variant:"outline",size:"sm",onClick:ie,disabled:!_,children:"Previous"}),Array.from({length:Math.min(5,A)},(t,d)=>{const j=d+1;return e.jsx(r.Button,{variant:b===j?"default":"outline",size:"sm",onClick:()=>I(j),children:j},j)}),A>5&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-muted-foreground",children:"..."}),e.jsx(r.Button,{variant:b===A?"default":"outline",size:"sm",onClick:()=>I(A),children:A})]}),e.jsx(r.Button,{variant:"outline",size:"sm",onClick:se,disabled:!O,children:"Next"})]})})]})]}):e.jsx(ve,{assetId:p||s||"",onBack:()=>{U("grid"),v(null)},onEdit:t=>{y({id:t.id,show:!0,file:t.url,name:t.name})},onSave:async t=>{if(p){E(!0);try{const d=T.find(j=>j.id===p);d&&await R(B.merge(d,{description:t}))}finally{E(!1)}}},isSaving:F})]}),u.show&&e.jsx(n.Suspense,{fallback:e.jsx("div",{className:"absolute inset-0 flex items-center justify-center",children:e.jsx(x.Loader,{className:"h-8 w-8 animate-spin"})}),children:e.jsx(Ne,{imageUrl:u.file,onSave:ue,onClose:()=>y({show:!1,file:""}),defaultSavedImageName:u.name,isEditing:!!u.id})}),h&&e.jsx(r.Dialog,{open:!!h,onOpenChange:()=>N(null),children:e.jsxs(r.DialogContent,{children:[e.jsxs(r.DialogHeader,{children:[e.jsx(r.DialogTitle,{children:"Delete Asset"}),e.jsxs(r.DialogDescription,{children:['Are you sure you want to delete "',h.name,'"? This action cannot be undone.']})]}),e.jsxs(r.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(r.Button,{variant:"outline",onClick:()=>N(null),children:"Cancel"}),e.jsx(r.Button,{variant:"destructive",onClick:oe,children:"Delete"})]})]})})]})}exports.default=we;
|