@chaibuilder/pages 0.4.9 → 0.4.10
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-C-y1qMcz.js → B4MFY5CR-BpnhFElu.js} +1 -1
- package/dist/{B4MFY5CR-CZIhZc_v.cjs → B4MFY5CR-CbOhoSHj.cjs} +1 -1
- package/dist/{HO4MOOFI-D1WZ0Hg3.js → HO4MOOFI-BaJU6Rmt.js} +2 -2
- package/dist/{HO4MOOFI-iH74XHta.cjs → HO4MOOFI-D-nc_Jzj.cjs} +1 -1
- package/dist/{HUY7CZI3-DABOTt0o.js → HUY7CZI3-C24G2dcQ.js} +2 -2
- package/dist/{HUY7CZI3-Bf9J-1mq.cjs → HUY7CZI3-CdUTm9km.cjs} +1 -1
- package/dist/digital-asset-manager-Dx_Fm4jg.cjs +1 -0
- package/dist/digital-asset-manager-k8g3Euye.js +496 -0
- package/dist/{index-B9yYtFHS.js → index-CYSpXUSz.js} +2628 -2544
- package/dist/index-Dg4tr4yA.cjs +2 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +12 -5
- package/dist/index.js +7 -6
- package/package.json +3 -3
- package/dist/digital-asset-manager-CI-fxUjE.cjs +0 -1
- package/dist/digital-asset-manager-ty2MhSyj.js +0 -493
- package/dist/index-D6MzyrPC.cjs +0 -2
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("react/jsx-runtime"),n=require("react"),L=require("@chaibuilder/sdk"),t=require("@chaibuilder/sdk/ui"),y=require("lodash-es"),j=require("lucide-react"),X=require("react-dropzone"),N=require("@tanstack/react-query"),w=require("sonner"),a=require("./index-D6MzyrPC.cjs"),Z=()=>{const l=a.useAssetsApiUrl(),c=N.useQueryClient(),d=a.useFetch();return N.useMutation({mutationFn:async({file:r,folderId:h,name:g})=>d(l,{action:a.ACTIONS.UPLOAD_ASSET,data:{file:r,folderId:h,name:g}}),onSuccess:()=>{c.invalidateQueries({queryKey:[a.QUERY_KEY_BASE,a.ACTIONS.GET_ASSETS]}),w.toast.success("Asset uploaded successfully")},onError:()=>{w.toast.error("Failed to upload asset")}})},ee=()=>{const l=a.useAssetsApiUrl(),c=N.useQueryClient(),d=a.useFetch();return N.useMutation({mutationFn:async r=>d(l,{action:a.ACTIONS.DELETE_ASSET,data:{id:r}}),onSuccess:()=>{c.invalidateQueries({queryKey:[a.QUERY_KEY_BASE,a.ACTIONS.GET_ASSETS]}),w.toast.success("Asset deleted successfully")},onError:()=>{w.toast.error("Failed to delete asset")}})},se=()=>{const l=a.useAssetsApiUrl(),c=N.useQueryClient(),d=a.useFetch();return N.useMutation({mutationFn:async r=>d(l,{action:a.ACTIONS.UPDATE_ASSET,data:r}),onSuccess:()=>{c.invalidateQueries({queryKey:[a.QUERY_KEY_BASE,a.ACTIONS.GET_ASSETS]}),w.toast.success("Asset updated successfully")},onError:()=>{w.toast.error("Failed to update asset")}})},te=(l={})=>{const c=a.useAssetsApiUrl(),d=a.useFetch(),{search:r,page:h=1,limit:g=10}=l;return N.useQuery({queryKey:[a.QUERY_KEY_BASE,a.ACTIONS.GET_ASSETS,r,h,g],queryFn:async()=>await d(c,{action:a.ACTIONS.GET_ASSETS,data:{search:r,page:h,limit:g}}),retry:1})};function ae(){const[c,d]=n.useState([]),[r,h]=n.useState({query:"",page:1,pageSize:10}),g=y.debounce(()=>r.query,300)(),{data:o,isLoading:C}=te({search:(g==null?void 0:g.toLowerCase().trim())||"",page:r.page,limit:r.pageSize}),v=o?Math.ceil(o.total/o.pageSize):0,u=(o==null?void 0:o.page)||1,f=u<v,x=u>1,{mutate:E,isPending:k}=se(),{mutate:b,isPending:m}=Z(),{mutate:T,isPending:U}=ee(),S=n.useCallback(p=>{p>=1&&p<=v&&h(A=>({...A,page:p}))},[v]),q=n.useCallback(()=>{f&&S(u+1)},[u,f,S]),F=n.useCallback(()=>{x&&S(u-1)},[u,x,S]),I=n.useCallback(p=>{h(A=>({...A,query:p,page:1}))},[]),D=n.useCallback(p=>{d(A=>y.find(A,{id:p.id})?[]:[p])},[!1]),z=n.useCallback(()=>{d([])},[]);return{query:(r==null?void 0:r.query)||"",selectedAssets:c,assets:(o==null?void 0:o.assets)||[],currentPage:u,totalPages:v,hasNextPage:f,hasPreviousPage:x,uploadAsset:b,updateAsset:E,deleteAsset:T,goToPage:S,nextPage:q,previousPage:F,updateSearchQuery:I,clearSelectedAssets:z,updateSelectedAssets:D,isLoadingAssets:C,isUploadingAsset:m,isUpdatingAsset:k,isDeletingAsset:U}}const le=n.lazy(()=>Promise.resolve().then(()=>require("./asset-metadata-editor-IRTgc3or.cjs"))),ne=n.lazy(()=>Promise.resolve().then(()=>require("./image-editor-DHmv5L8S.cjs")));function ie({close:l,onSelect:c,mode:d="image"}){const h=n.useMemo(()=>[d],[d]),[g,o]=n.useState("browse"),[C,v]=n.useState(null),[u,f]=n.useState(null),[x,E]=n.useState({show:!1,file:""}),{query:k,assets:b,selectedAssets:m,uploadAsset:T,updateAsset:U,deleteAsset:S,updateSearchQuery:q,clearSelectedAssets:F,updateSelectedAssets:I,isLoadingAssets:D,isUploadingAsset:z,isUpdatingAsset:p}=ae(),A=n.useRef(null),_=n.useCallback(async s=>new Promise((i,M)=>{const Q=s[0],P=new FileReader;P.readAsDataURL(Q),P.onload=async()=>{const B=await T({file:P.result,folderId:null,name:Q.name},{onSuccess:()=>{o("browse")}});i(B)},P.onerror=B=>M(B)}),[T]),{getRootProps:O,getInputProps:R,isDragActive:K}=X.useDropzone({onDrop:_,accept:{"image/*":h.includes("image")?[]:[]},maxSize:10*1024*1024}),Y=()=>{console.log("selectedAssets",m,y.pick(y.first(m),["url","width","height","description"])),m.length!==0&&(c(y.pick(y.first(m),["url","width","height","description"])),l())},G=async s=>{f(s)},$=async()=>{u&&(await S(u.id),f(null))},H=s=>{v(s)},V=async(s,i)=>{await U(y.merge(s,y.pick(i,["id","description"]))),l()},J=s=>{q(s.target.value)},W=async(s,i)=>{try{i?await T({file:s,folderId:null,name:x.name||""}):await U({id:x.id||"",file:s}),E({show:!1,file:""}),o("browse")}catch(M){console.error("Error saving edited image:",M)}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"min-w-[700px] min-h-[600px] w-[900px] max-w-[900px]",children:[e.jsx("h1",{className:"text-lg font-medium pb-4",children:"Digital Asset Manager"}),e.jsxs(t.Tabs,{value:g,onValueChange:s=>o(s),className:"flex-1 flex flex-col h-full",children:[e.jsxs("div",{className:"flex justify-between items-center mb-2",children:[e.jsxs(t.TabsList,{children:[e.jsx(t.TabsTrigger,{value:"browse",children:"Browse Assets"}),e.jsx(t.TabsTrigger,{value:"upload",children:"Upload"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[m.length>0&&e.jsx(e.Fragment,{children:e.jsx(t.Button,{variant:"outline",size:"sm",onClick:()=>F(),title:"Clear selection",children:"Clear"})}),e.jsx(t.Button,{size:"sm",onClick:Y,disabled:m.length===0,children:"Select Asset"})]})]}),e.jsxs(t.TabsContent,{value:"browse",className:"flex-1 flex flex-col",children:[e.jsx("div",{className:"flex items-center gap-2 mb-2",children:e.jsxs("div",{className:"relative w-full",children:[e.jsx(j.Search,{className:"absolute left-2 top-2.5 h-4 w-4 text-muted-foreground"}),e.jsx(t.Input,{placeholder:"Search assets...",value:k,onChange:J,className:"pl-8"})]})}),D&&b.length===0?e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 overflow-y-auto max-h-[550px] p-1",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"})]}):b.length===0?e.jsxs("div",{className:"flex flex-col items-center justify-center text-center p-12 h-[380px]",children:[e.jsxs("div",{className:"text-muted-foreground mb-2",children:[e.jsx("h3",{className:"text-gray-800 font-medium",children:"No assets to display"}),e.jsx("p",{className:"text-sm",children:"You haven't uploaded any assets yet. Start by uploading your first asset."})]}),e.jsx("div",{className:"flex gap-2 pt-4",children:e.jsx(t.Button,{size:"lg",onClick:()=>o("upload"),children:"Upload Assets"})})]}):e.jsxs("div",{ref:A,className:"grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 overflow-y-auto max-h-[550px] p-1",children:[b.map(s=>e.jsx(t.Card,{className:L.mergeClasses("cursor-pointer overflow-hidden transition-all",m.some(i=>i.id===s.id)?"ring-2 ring-primary":"hover:ring-2 hover:ring-primary/20"),onClick:()=>I(s),children:e.jsxs(t.CardContent,{className:"p-0 relative group",children:[e.jsxs("div",{className:"aspect-square relative overflow-hidden bg-muted",children:[s.type==="image"?e.jsx("img",{src:s.thumbnailUrl||"/placeholder.svg",alt:s.name,className:"object-cover w-full h-full min-h-[100px]"}):e.jsxs("div",{className:"flex items-center justify-center h-full",children:[e.jsx(j.Film,{className:"h-12 w-12 text-muted-foreground"}),s.thumbnailUrl&&e.jsx("img",{src:s.thumbnailUrl||"/placeholder.svg",alt:s.name,className:"absolute inset-0 object-cover w-full h-full"})]}),e.jsxs("div",{className:"absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2",children:[e.jsx(t.Button,{variant:"secondary",size:"icon",className:"h-8 w-8",onClick:i=>{i.stopPropagation(),H(s)},children:e.jsx(j.ImageIcon,{className:"h-4 w-4"})}),e.jsx(t.Button,{variant:"secondary",size:"icon",className:"h-8 w-8",onClick:i=>{i.stopPropagation(),E({id:s.id,show:!0,file:s.url,name:s.name})},children:e.jsx(j.Edit,{className:"h-4 w-4"})}),e.jsx(t.Button,{variant:"destructive",size:"icon",className:"h-8 w-8",onClick:i=>{i.stopPropagation(),G(s)},children:e.jsx(j.Trash2,{className:"h-4 w-4"})})]}),m.some(i=>i.id===s.id)&&e.jsx("div",{className:"absolute top-2 left-2",children:e.jsx("input",{type:"checkbox",checked:m.some(i=>i.id===s.id),readOnly:!0,className:"rounded-full"})})]}),e.jsxs("div",{className:"p-2",children:[e.jsx("div",{className:"text-sm font-medium truncate",title:s.name,children:s.name}),e.jsxs("div",{className:"text-xs text-muted-foreground flex items-center justify-between",children:[e.jsx("span",{children:re((s==null?void 0:s.size)||0)}),e.jsx("span",{children:oe(s.createdAt)})]})]})]})},s.id)),D&&b.length>0&&e.jsx("div",{className:"col-span-full flex justify-center py-4",children:e.jsx(j.Loader2,{className:"h-6 w-6 animate-spin text-muted-foreground"})})]})]}),e.jsx(t.TabsContent,{value:"upload",className:"flex-1 ",children:e.jsxs("div",{...O(),className:L.mergeClasses("border-2 border-dashed rounded-lg h-[380px] flex flex-col items-center justify-center text-center cursor-pointer hover:bg-gray-50",K?"border-primary bg-primary/5":"border-muted-foreground/20"),children:[e.jsx("input",{...R()}),p||z?e.jsxs("div",{className:"flex flex-col items-center",children:[e.jsx(j.Loader2,{className:"h-12 w-12 text-primary animate-spin mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-1",children:"Uploading files..."}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Please wait while your files are being processed."})]}):e.jsxs(e.Fragment,{children:[e.jsx(j.Upload,{className:"h-12 w-12 text-muted-foreground mb-4"}),e.jsx("h3",{className:"text-lg font-medium mb-1",children:"Drag & drop files here"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"or click to browse your files"}),e.jsxs("div",{className:"text-xs text-muted-foreground",children:[e.jsxs("p",{children:["Accepted file types: ",h.join(", ")]}),e.jsxs("p",{children:["Maximum file size: ",10,"MB"]})]})]})]})})]})]}),C&&e.jsx(n.Suspense,{fallback:e.jsx("div",{children:"Loading..."}),children:e.jsx(le,{asset:C,onSave:s=>V(C,s),onCancel:()=>{v(null)}})}),x.show&&e.jsx(n.Suspense,{fallback:e.jsx("div",{children:"Loading..."}),children:e.jsx(ne,{imageUrl:x.file,onSave:W,onClose:()=>E({show:!1,file:""}),defaultSavedImageName:x.name,isEditing:!!x.id})}),u&&e.jsx(t.Dialog,{open:!!u,onOpenChange:()=>f(null),children:e.jsxs(t.DialogContent,{children:[e.jsxs(t.DialogHeader,{children:[e.jsx(t.DialogTitle,{children:"Delete Asset"}),e.jsxs(t.DialogDescription,{children:['Are you sure you want to delete "',u.name,'"? This action cannot be undone.']})]}),e.jsxs(t.DialogFooter,{className:"gap-2 sm:gap-0",children:[e.jsx(t.Button,{variant:"outline",onClick:()=>f(null),children:"Cancel"}),e.jsx(t.Button,{variant:"destructive",onClick:$,children:"Delete"})]})]})})]})}function re(l){return l<1024?`${l.toFixed(2)} B`:l<1024*1024?`${(l/1024).toFixed(2)} KB`:`${(l/(1024*1024)).toFixed(2)} MB`}function oe(l){const c=new Date(l);return new Intl.DateTimeFormat("en-US",{month:"short",day:"numeric",year:"numeric"}).format(c)}exports.default=ie;
|
|
@@ -1,493 +0,0 @@
|
|
|
1
|
-
import { jsxs as t, Fragment as Q, jsx as e } from "react/jsx-runtime";
|
|
2
|
-
import J, { useState as S, useCallback as w, useMemo as de, useRef as ue, Suspense as $ } from "react";
|
|
3
|
-
import { mergeClasses as H } from "@chaibuilder/sdk";
|
|
4
|
-
import { Tabs as me, TabsList as he, TabsTrigger as V, Button as f, TabsContent as W, Input as ge, Card as pe, CardContent as fe, Dialog as ye, DialogContent as ve, DialogHeader as xe, DialogTitle as Ne, DialogDescription as we, DialogFooter as Ae } from "@chaibuilder/sdk/ui";
|
|
5
|
-
import { debounce as Se, find as be, pick as R, first as X, merge as Ce } from "lodash-es";
|
|
6
|
-
import { Search as Ee, Film as Te, ImageIcon as De, Edit as Pe, Trash2 as Ue, Loader2 as Z, Upload as Fe } from "lucide-react";
|
|
7
|
-
import { useDropzone as ze } from "react-dropzone";
|
|
8
|
-
import { useQueryClient as K, useMutation as G, useQuery as ke } from "@tanstack/react-query";
|
|
9
|
-
import { toast as b } from "sonner";
|
|
10
|
-
import { W as F, X as z, Y as y, Z as k } from "./index-B9yYtFHS.js";
|
|
11
|
-
const Me = () => {
|
|
12
|
-
const a = F(), r = K(), o = z();
|
|
13
|
-
return G({
|
|
14
|
-
mutationFn: async ({
|
|
15
|
-
file: i,
|
|
16
|
-
folderId: u,
|
|
17
|
-
name: m
|
|
18
|
-
}) => o(a, {
|
|
19
|
-
action: y.UPLOAD_ASSET,
|
|
20
|
-
data: { file: i, folderId: u, name: m }
|
|
21
|
-
}),
|
|
22
|
-
onSuccess: () => {
|
|
23
|
-
r.invalidateQueries({
|
|
24
|
-
queryKey: [k, y.GET_ASSETS]
|
|
25
|
-
}), b.success("Asset uploaded successfully");
|
|
26
|
-
},
|
|
27
|
-
onError: () => {
|
|
28
|
-
b.error("Failed to upload asset");
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
}, Ie = () => {
|
|
32
|
-
const a = F(), r = K(), o = z();
|
|
33
|
-
return G({
|
|
34
|
-
mutationFn: async (i) => o(a, {
|
|
35
|
-
action: y.DELETE_ASSET,
|
|
36
|
-
data: { id: i }
|
|
37
|
-
}),
|
|
38
|
-
onSuccess: () => {
|
|
39
|
-
r.invalidateQueries({
|
|
40
|
-
queryKey: [k, y.GET_ASSETS]
|
|
41
|
-
}), b.success("Asset deleted successfully");
|
|
42
|
-
},
|
|
43
|
-
onError: () => {
|
|
44
|
-
b.error("Failed to delete asset");
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
}, qe = () => {
|
|
48
|
-
const a = F(), r = K(), o = z();
|
|
49
|
-
return G({
|
|
50
|
-
mutationFn: async (i) => o(a, {
|
|
51
|
-
action: y.UPDATE_ASSET,
|
|
52
|
-
data: i
|
|
53
|
-
}),
|
|
54
|
-
onSuccess: () => {
|
|
55
|
-
r.invalidateQueries({
|
|
56
|
-
queryKey: [k, y.GET_ASSETS]
|
|
57
|
-
}), b.success("Asset updated successfully");
|
|
58
|
-
},
|
|
59
|
-
onError: () => {
|
|
60
|
-
b.error("Failed to update asset");
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
}, je = (a = {}) => {
|
|
64
|
-
const r = F(), o = z(), { search: i, page: u = 1, limit: m = 10 } = a;
|
|
65
|
-
return ke({
|
|
66
|
-
queryKey: [k, y.GET_ASSETS, i, u, m],
|
|
67
|
-
queryFn: async () => await o(r, {
|
|
68
|
-
action: y.GET_ASSETS,
|
|
69
|
-
data: {
|
|
70
|
-
search: i,
|
|
71
|
-
page: u,
|
|
72
|
-
limit: m
|
|
73
|
-
}
|
|
74
|
-
}),
|
|
75
|
-
retry: 1
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
function _e() {
|
|
79
|
-
const [r, o] = S([]), [i, u] = S({
|
|
80
|
-
query: "",
|
|
81
|
-
page: 1,
|
|
82
|
-
pageSize: 10
|
|
83
|
-
}), m = Se(() => i.query, 300)(), { data: n, isLoading: C } = je({
|
|
84
|
-
search: (m == null ? void 0 : m.toLowerCase().trim()) || "",
|
|
85
|
-
page: i.page,
|
|
86
|
-
limit: i.pageSize
|
|
87
|
-
}), v = n ? Math.ceil(n.total / n.pageSize) : 0, c = (n == null ? void 0 : n.page) || 1, p = c < v, h = c > 1, { mutate: E, isPending: M } = qe(), { mutate: A, isPending: d } = Me(), { mutate: T, isPending: D } = Ie(), x = w(
|
|
88
|
-
(g) => {
|
|
89
|
-
g >= 1 && g <= v && u((N) => ({
|
|
90
|
-
...N,
|
|
91
|
-
page: g
|
|
92
|
-
}));
|
|
93
|
-
},
|
|
94
|
-
[v]
|
|
95
|
-
), I = w(() => {
|
|
96
|
-
p && x(c + 1);
|
|
97
|
-
}, [c, p, x]), q = w(() => {
|
|
98
|
-
h && x(c - 1);
|
|
99
|
-
}, [c, h, x]), j = w((g) => {
|
|
100
|
-
u((N) => ({
|
|
101
|
-
...N,
|
|
102
|
-
query: g,
|
|
103
|
-
page: 1
|
|
104
|
-
// Reset to first page on new search
|
|
105
|
-
}));
|
|
106
|
-
}, []), P = w(
|
|
107
|
-
(g) => {
|
|
108
|
-
o((N) => be(N, { id: g.id }) ? [] : [g]);
|
|
109
|
-
},
|
|
110
|
-
[!1]
|
|
111
|
-
), _ = w(() => {
|
|
112
|
-
o([]);
|
|
113
|
-
}, []);
|
|
114
|
-
return {
|
|
115
|
-
// Data
|
|
116
|
-
query: (i == null ? void 0 : i.query) || "",
|
|
117
|
-
selectedAssets: r,
|
|
118
|
-
assets: (n == null ? void 0 : n.assets) || [],
|
|
119
|
-
currentPage: c,
|
|
120
|
-
totalPages: v,
|
|
121
|
-
hasNextPage: p,
|
|
122
|
-
hasPreviousPage: h,
|
|
123
|
-
// Mutations
|
|
124
|
-
uploadAsset: A,
|
|
125
|
-
updateAsset: E,
|
|
126
|
-
deleteAsset: T,
|
|
127
|
-
goToPage: x,
|
|
128
|
-
nextPage: I,
|
|
129
|
-
previousPage: q,
|
|
130
|
-
updateSearchQuery: j,
|
|
131
|
-
clearSelectedAssets: _,
|
|
132
|
-
updateSelectedAssets: P,
|
|
133
|
-
// Loading
|
|
134
|
-
isLoadingAssets: C,
|
|
135
|
-
isUploadingAsset: d,
|
|
136
|
-
isUpdatingAsset: M,
|
|
137
|
-
isDeletingAsset: D
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
const Le = J.lazy(() => import("./asset-metadata-editor-CyTBhS-V.js")), Be = J.lazy(() => import("./image-editor-By8RDHso.js"));
|
|
141
|
-
function Je({
|
|
142
|
-
close: a,
|
|
143
|
-
onSelect: r,
|
|
144
|
-
mode: o = "image"
|
|
145
|
-
}) {
|
|
146
|
-
const u = de(() => [o], [o]), [m, n] = S("browse"), [C, v] = S(null), [c, p] = S(null), [h, E] = S({ show: !1, file: "" }), {
|
|
147
|
-
// Data
|
|
148
|
-
query: M,
|
|
149
|
-
assets: A,
|
|
150
|
-
selectedAssets: d,
|
|
151
|
-
// Mutations
|
|
152
|
-
uploadAsset: T,
|
|
153
|
-
updateAsset: D,
|
|
154
|
-
deleteAsset: x,
|
|
155
|
-
updateSearchQuery: I,
|
|
156
|
-
clearSelectedAssets: q,
|
|
157
|
-
updateSelectedAssets: j,
|
|
158
|
-
// Loading
|
|
159
|
-
isLoadingAssets: P,
|
|
160
|
-
isUploadingAsset: _,
|
|
161
|
-
isUpdatingAsset: g
|
|
162
|
-
// isDeletingAsset,
|
|
163
|
-
} = _e(), N = ue(null), O = w(
|
|
164
|
-
async (s) => new Promise((l, L) => {
|
|
165
|
-
const Y = s[0], U = new FileReader();
|
|
166
|
-
U.readAsDataURL(Y), U.onload = async () => {
|
|
167
|
-
const B = await T(
|
|
168
|
-
{
|
|
169
|
-
file: U.result,
|
|
170
|
-
folderId: null,
|
|
171
|
-
name: Y.name
|
|
172
|
-
},
|
|
173
|
-
{
|
|
174
|
-
onSuccess: () => {
|
|
175
|
-
n("browse");
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
);
|
|
179
|
-
l(B);
|
|
180
|
-
}, U.onerror = (B) => L(B);
|
|
181
|
-
}),
|
|
182
|
-
[T]
|
|
183
|
-
), { getRootProps: ee, getInputProps: se, isDragActive: te } = ze({
|
|
184
|
-
onDrop: O,
|
|
185
|
-
accept: {
|
|
186
|
-
"image/*": u.includes("image") ? [] : []
|
|
187
|
-
},
|
|
188
|
-
maxSize: 10 * 1024 * 1024
|
|
189
|
-
}), ae = () => {
|
|
190
|
-
console.log(
|
|
191
|
-
"selectedAssets",
|
|
192
|
-
d,
|
|
193
|
-
R(X(d), ["url", "width", "height", "description"])
|
|
194
|
-
), d.length !== 0 && (r(
|
|
195
|
-
R(X(d), ["url", "width", "height", "description"])
|
|
196
|
-
), a());
|
|
197
|
-
}, le = async (s) => {
|
|
198
|
-
p(s);
|
|
199
|
-
}, ie = async () => {
|
|
200
|
-
c && (await x(c.id), p(null));
|
|
201
|
-
}, ne = (s) => {
|
|
202
|
-
v(s);
|
|
203
|
-
}, re = async (s, l) => {
|
|
204
|
-
await D(Ce(s, R(l, ["id", "description"]))), a();
|
|
205
|
-
}, oe = (s) => {
|
|
206
|
-
I(s.target.value);
|
|
207
|
-
}, ce = async (s, l) => {
|
|
208
|
-
try {
|
|
209
|
-
l ? await T({
|
|
210
|
-
file: s,
|
|
211
|
-
folderId: null,
|
|
212
|
-
name: h.name || ""
|
|
213
|
-
}) : await D({
|
|
214
|
-
id: h.id || "",
|
|
215
|
-
file: s
|
|
216
|
-
}), E({ show: !1, file: "" }), n("browse");
|
|
217
|
-
} catch (L) {
|
|
218
|
-
console.error("Error saving edited image:", L);
|
|
219
|
-
}
|
|
220
|
-
};
|
|
221
|
-
return /* @__PURE__ */ t(Q, { children: [
|
|
222
|
-
/* @__PURE__ */ t("div", { className: "min-w-[700px] min-h-[600px] w-[900px] max-w-[900px]", children: [
|
|
223
|
-
/* @__PURE__ */ e("h1", { className: "text-lg font-medium pb-4", children: "Digital Asset Manager" }),
|
|
224
|
-
/* @__PURE__ */ t(
|
|
225
|
-
me,
|
|
226
|
-
{
|
|
227
|
-
value: m,
|
|
228
|
-
onValueChange: (s) => n(s),
|
|
229
|
-
className: "flex-1 flex flex-col h-full",
|
|
230
|
-
children: [
|
|
231
|
-
/* @__PURE__ */ t("div", { className: "flex justify-between items-center mb-2", children: [
|
|
232
|
-
/* @__PURE__ */ t(he, { children: [
|
|
233
|
-
/* @__PURE__ */ e(V, { value: "browse", children: "Browse Assets" }),
|
|
234
|
-
/* @__PURE__ */ e(V, { value: "upload", children: "Upload" })
|
|
235
|
-
] }),
|
|
236
|
-
/* @__PURE__ */ t("div", { className: "flex items-center gap-2", children: [
|
|
237
|
-
d.length > 0 && /* @__PURE__ */ e(Q, { children: /* @__PURE__ */ e(
|
|
238
|
-
f,
|
|
239
|
-
{
|
|
240
|
-
variant: "outline",
|
|
241
|
-
size: "sm",
|
|
242
|
-
onClick: () => q(),
|
|
243
|
-
title: "Clear selection",
|
|
244
|
-
children: "Clear"
|
|
245
|
-
}
|
|
246
|
-
) }),
|
|
247
|
-
/* @__PURE__ */ e(
|
|
248
|
-
f,
|
|
249
|
-
{
|
|
250
|
-
size: "sm",
|
|
251
|
-
onClick: ae,
|
|
252
|
-
disabled: d.length === 0,
|
|
253
|
-
children: "Select Asset"
|
|
254
|
-
}
|
|
255
|
-
)
|
|
256
|
-
] })
|
|
257
|
-
] }),
|
|
258
|
-
/* @__PURE__ */ t(W, { value: "browse", className: "flex-1 flex flex-col", children: [
|
|
259
|
-
/* @__PURE__ */ e("div", { className: "flex items-center gap-2 mb-2", children: /* @__PURE__ */ t("div", { className: "relative w-full", children: [
|
|
260
|
-
/* @__PURE__ */ e(Ee, { className: "absolute left-2 top-2.5 h-4 w-4 text-muted-foreground" }),
|
|
261
|
-
/* @__PURE__ */ e(
|
|
262
|
-
ge,
|
|
263
|
-
{
|
|
264
|
-
placeholder: "Search assets...",
|
|
265
|
-
value: M,
|
|
266
|
-
onChange: oe,
|
|
267
|
-
className: "pl-8"
|
|
268
|
-
}
|
|
269
|
-
)
|
|
270
|
-
] }) }),
|
|
271
|
-
P && A.length === 0 ? /* @__PURE__ */ t("div", { className: "grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 overflow-y-auto max-h-[550px] p-1", children: [
|
|
272
|
-
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
273
|
-
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
274
|
-
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
275
|
-
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
276
|
-
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
277
|
-
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
278
|
-
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
279
|
-
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
280
|
-
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
281
|
-
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" })
|
|
282
|
-
] }) : A.length === 0 ? /* @__PURE__ */ t("div", { className: "flex flex-col items-center justify-center text-center p-12 h-[380px]", children: [
|
|
283
|
-
/* @__PURE__ */ t("div", { className: "text-muted-foreground mb-2", children: [
|
|
284
|
-
/* @__PURE__ */ e("h3", { className: "text-gray-800 font-medium", children: "No assets to display" }),
|
|
285
|
-
/* @__PURE__ */ e("p", { className: "text-sm", children: "You haven't uploaded any assets yet. Start by uploading your first asset." })
|
|
286
|
-
] }),
|
|
287
|
-
/* @__PURE__ */ e("div", { className: "flex gap-2 pt-4", children: /* @__PURE__ */ e(f, { size: "lg", onClick: () => n("upload"), children: "Upload Assets" }) })
|
|
288
|
-
] }) : /* @__PURE__ */ t(
|
|
289
|
-
"div",
|
|
290
|
-
{
|
|
291
|
-
ref: N,
|
|
292
|
-
className: "grid grid-cols-2 sm:grid-cols-3 md:grid-cols-4 lg:grid-cols-5 gap-2 overflow-y-auto max-h-[550px] p-1",
|
|
293
|
-
children: [
|
|
294
|
-
A.map((s) => /* @__PURE__ */ e(
|
|
295
|
-
pe,
|
|
296
|
-
{
|
|
297
|
-
className: H(
|
|
298
|
-
"cursor-pointer overflow-hidden transition-all",
|
|
299
|
-
d.some((l) => l.id === s.id) ? "ring-2 ring-primary" : "hover:ring-2 hover:ring-primary/20"
|
|
300
|
-
),
|
|
301
|
-
onClick: () => j(s),
|
|
302
|
-
children: /* @__PURE__ */ t(fe, { className: "p-0 relative group", children: [
|
|
303
|
-
/* @__PURE__ */ t("div", { className: "aspect-square relative overflow-hidden bg-muted", children: [
|
|
304
|
-
s.type === "image" ? /* @__PURE__ */ e(
|
|
305
|
-
"img",
|
|
306
|
-
{
|
|
307
|
-
src: s.thumbnailUrl || "/placeholder.svg",
|
|
308
|
-
alt: s.name,
|
|
309
|
-
className: "object-cover w-full h-full min-h-[100px]"
|
|
310
|
-
}
|
|
311
|
-
) : /* @__PURE__ */ t("div", { className: "flex items-center justify-center h-full", children: [
|
|
312
|
-
/* @__PURE__ */ e(Te, { className: "h-12 w-12 text-muted-foreground" }),
|
|
313
|
-
s.thumbnailUrl && /* @__PURE__ */ e(
|
|
314
|
-
"img",
|
|
315
|
-
{
|
|
316
|
-
src: s.thumbnailUrl || "/placeholder.svg",
|
|
317
|
-
alt: s.name,
|
|
318
|
-
className: "absolute inset-0 object-cover w-full h-full"
|
|
319
|
-
}
|
|
320
|
-
)
|
|
321
|
-
] }),
|
|
322
|
-
/* @__PURE__ */ t("div", { className: "absolute inset-0 bg-black/50 opacity-0 group-hover:opacity-100 transition-opacity flex items-center justify-center gap-2", children: [
|
|
323
|
-
/* @__PURE__ */ e(
|
|
324
|
-
f,
|
|
325
|
-
{
|
|
326
|
-
variant: "secondary",
|
|
327
|
-
size: "icon",
|
|
328
|
-
className: "h-8 w-8",
|
|
329
|
-
onClick: (l) => {
|
|
330
|
-
l.stopPropagation(), ne(s);
|
|
331
|
-
},
|
|
332
|
-
children: /* @__PURE__ */ e(De, { className: "h-4 w-4" })
|
|
333
|
-
}
|
|
334
|
-
),
|
|
335
|
-
/* @__PURE__ */ e(
|
|
336
|
-
f,
|
|
337
|
-
{
|
|
338
|
-
variant: "secondary",
|
|
339
|
-
size: "icon",
|
|
340
|
-
className: "h-8 w-8",
|
|
341
|
-
onClick: (l) => {
|
|
342
|
-
l.stopPropagation(), E({
|
|
343
|
-
id: s.id,
|
|
344
|
-
show: !0,
|
|
345
|
-
file: s.url,
|
|
346
|
-
name: s.name
|
|
347
|
-
});
|
|
348
|
-
},
|
|
349
|
-
children: /* @__PURE__ */ e(Pe, { className: "h-4 w-4" })
|
|
350
|
-
}
|
|
351
|
-
),
|
|
352
|
-
/* @__PURE__ */ e(
|
|
353
|
-
f,
|
|
354
|
-
{
|
|
355
|
-
variant: "destructive",
|
|
356
|
-
size: "icon",
|
|
357
|
-
className: "h-8 w-8",
|
|
358
|
-
onClick: (l) => {
|
|
359
|
-
l.stopPropagation(), le(s);
|
|
360
|
-
},
|
|
361
|
-
children: /* @__PURE__ */ e(Ue, { className: "h-4 w-4" })
|
|
362
|
-
}
|
|
363
|
-
)
|
|
364
|
-
] }),
|
|
365
|
-
d.some((l) => l.id === s.id) && /* @__PURE__ */ e("div", { className: "absolute top-2 left-2", children: /* @__PURE__ */ e(
|
|
366
|
-
"input",
|
|
367
|
-
{
|
|
368
|
-
type: "checkbox",
|
|
369
|
-
checked: d.some(
|
|
370
|
-
(l) => l.id === s.id
|
|
371
|
-
),
|
|
372
|
-
readOnly: !0,
|
|
373
|
-
className: "rounded-full"
|
|
374
|
-
}
|
|
375
|
-
) })
|
|
376
|
-
] }),
|
|
377
|
-
/* @__PURE__ */ t("div", { className: "p-2", children: [
|
|
378
|
-
/* @__PURE__ */ e(
|
|
379
|
-
"div",
|
|
380
|
-
{
|
|
381
|
-
className: "text-sm font-medium truncate",
|
|
382
|
-
title: s.name,
|
|
383
|
-
children: s.name
|
|
384
|
-
}
|
|
385
|
-
),
|
|
386
|
-
/* @__PURE__ */ t("div", { className: "text-xs text-muted-foreground flex items-center justify-between", children: [
|
|
387
|
-
/* @__PURE__ */ e("span", { children: Qe((s == null ? void 0 : s.size) || 0) }),
|
|
388
|
-
/* @__PURE__ */ e("span", { children: Re(s.createdAt) })
|
|
389
|
-
] })
|
|
390
|
-
] })
|
|
391
|
-
] })
|
|
392
|
-
},
|
|
393
|
-
s.id
|
|
394
|
-
)),
|
|
395
|
-
P && A.length > 0 && /* @__PURE__ */ e("div", { className: "col-span-full flex justify-center py-4", children: /* @__PURE__ */ e(Z, { className: "h-6 w-6 animate-spin text-muted-foreground" }) })
|
|
396
|
-
]
|
|
397
|
-
}
|
|
398
|
-
)
|
|
399
|
-
] }),
|
|
400
|
-
/* @__PURE__ */ e(W, { value: "upload", className: "flex-1 ", children: /* @__PURE__ */ t(
|
|
401
|
-
"div",
|
|
402
|
-
{
|
|
403
|
-
...ee(),
|
|
404
|
-
className: H(
|
|
405
|
-
"border-2 border-dashed rounded-lg h-[380px] flex flex-col items-center justify-center text-center cursor-pointer hover:bg-gray-50",
|
|
406
|
-
te ? "border-primary bg-primary/5" : "border-muted-foreground/20"
|
|
407
|
-
),
|
|
408
|
-
children: [
|
|
409
|
-
/* @__PURE__ */ e("input", { ...se() }),
|
|
410
|
-
g || _ ? /* @__PURE__ */ t("div", { className: "flex flex-col items-center", children: [
|
|
411
|
-
/* @__PURE__ */ e(Z, { className: "h-12 w-12 text-primary animate-spin mb-4" }),
|
|
412
|
-
/* @__PURE__ */ e("h3", { className: "text-lg font-medium mb-1", children: "Uploading files..." }),
|
|
413
|
-
/* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground", children: "Please wait while your files are being processed." })
|
|
414
|
-
] }) : /* @__PURE__ */ t(Q, { children: [
|
|
415
|
-
/* @__PURE__ */ e(Fe, { className: "h-12 w-12 text-muted-foreground mb-4" }),
|
|
416
|
-
/* @__PURE__ */ e("h3", { className: "text-lg font-medium mb-1", children: "Drag & drop files here" }),
|
|
417
|
-
/* @__PURE__ */ e("p", { className: "text-sm text-muted-foreground mb-4", children: "or click to browse your files" }),
|
|
418
|
-
/* @__PURE__ */ t("div", { className: "text-xs text-muted-foreground", children: [
|
|
419
|
-
/* @__PURE__ */ t("p", { children: [
|
|
420
|
-
"Accepted file types: ",
|
|
421
|
-
u.join(", ")
|
|
422
|
-
] }),
|
|
423
|
-
/* @__PURE__ */ t("p", { children: [
|
|
424
|
-
"Maximum file size: ",
|
|
425
|
-
10,
|
|
426
|
-
"MB"
|
|
427
|
-
] })
|
|
428
|
-
] })
|
|
429
|
-
] })
|
|
430
|
-
]
|
|
431
|
-
}
|
|
432
|
-
) })
|
|
433
|
-
]
|
|
434
|
-
}
|
|
435
|
-
)
|
|
436
|
-
] }),
|
|
437
|
-
C && /* @__PURE__ */ e($, { fallback: /* @__PURE__ */ e("div", { children: "Loading..." }), children: /* @__PURE__ */ e(
|
|
438
|
-
Le,
|
|
439
|
-
{
|
|
440
|
-
asset: C,
|
|
441
|
-
onSave: (s) => re(C, s),
|
|
442
|
-
onCancel: () => {
|
|
443
|
-
v(null);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
) }),
|
|
447
|
-
h.show && /* @__PURE__ */ e($, { fallback: /* @__PURE__ */ e("div", { children: "Loading..." }), children: /* @__PURE__ */ e(
|
|
448
|
-
Be,
|
|
449
|
-
{
|
|
450
|
-
imageUrl: h.file,
|
|
451
|
-
onSave: ce,
|
|
452
|
-
onClose: () => E({ show: !1, file: "" }),
|
|
453
|
-
defaultSavedImageName: h.name,
|
|
454
|
-
isEditing: !!h.id
|
|
455
|
-
}
|
|
456
|
-
) }),
|
|
457
|
-
c && /* @__PURE__ */ e(
|
|
458
|
-
ye,
|
|
459
|
-
{
|
|
460
|
-
open: !!c,
|
|
461
|
-
onOpenChange: () => p(null),
|
|
462
|
-
children: /* @__PURE__ */ t(ve, { children: [
|
|
463
|
-
/* @__PURE__ */ t(xe, { children: [
|
|
464
|
-
/* @__PURE__ */ e(Ne, { children: "Delete Asset" }),
|
|
465
|
-
/* @__PURE__ */ t(we, { children: [
|
|
466
|
-
'Are you sure you want to delete "',
|
|
467
|
-
c.name,
|
|
468
|
-
'"? This action cannot be undone.'
|
|
469
|
-
] })
|
|
470
|
-
] }),
|
|
471
|
-
/* @__PURE__ */ t(Ae, { className: "gap-2 sm:gap-0", children: [
|
|
472
|
-
/* @__PURE__ */ e(f, { variant: "outline", onClick: () => p(null), children: "Cancel" }),
|
|
473
|
-
/* @__PURE__ */ e(f, { variant: "destructive", onClick: ie, children: "Delete" })
|
|
474
|
-
] })
|
|
475
|
-
] })
|
|
476
|
-
}
|
|
477
|
-
)
|
|
478
|
-
] });
|
|
479
|
-
}
|
|
480
|
-
function Qe(a) {
|
|
481
|
-
return a < 1024 ? `${a.toFixed(2)} B` : a < 1024 * 1024 ? `${(a / 1024).toFixed(2)} KB` : `${(a / (1024 * 1024)).toFixed(2)} MB`;
|
|
482
|
-
}
|
|
483
|
-
function Re(a) {
|
|
484
|
-
const r = new Date(a);
|
|
485
|
-
return new Intl.DateTimeFormat("en-US", {
|
|
486
|
-
month: "short",
|
|
487
|
-
day: "numeric",
|
|
488
|
-
year: "numeric"
|
|
489
|
-
}).format(r);
|
|
490
|
-
}
|
|
491
|
-
export {
|
|
492
|
-
Je as default
|
|
493
|
-
};
|