@chaibuilder/pages 0.4.8-beta.1 → 0.4.8-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{B4MFY5CR-DyR5KduJ.cjs → B4MFY5CR-De2uSYsE.cjs} +1 -1
- package/dist/{B4MFY5CR-B6Ovh3Gq.js → B4MFY5CR-Y1TSYFEO.js} +1 -1
- package/dist/{HO4MOOFI-Dv82-fP1.js → HO4MOOFI-BYHU8reo.js} +2 -2
- package/dist/{HO4MOOFI-HjzuoPRe.cjs → HO4MOOFI-D_Wsaygd.cjs} +1 -1
- package/dist/{HUY7CZI3-Cx1xpXqQ.js → HUY7CZI3-Bu2JpU4v.js} +2 -2
- package/dist/{HUY7CZI3-bzxTWlyM.cjs → HUY7CZI3-DrOAHzjx.cjs} +1 -1
- package/dist/{digital-asset-manager-Dfg9MZry.js → digital-asset-manager-C8r5r7TV.js} +52 -46
- package/dist/digital-asset-manager-CBnrDmR9.cjs +1 -0
- package/dist/{index-C6iwM3hl.cjs → index-B9qohq82.cjs} +1 -1
- package/dist/{index-CqQe5PpG.js → index-C657rWjb.js} +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/digital-asset-manager-IFfwC5Xe.cjs +0 -1
|
@@ -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-C657rWjb.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-Y1TSYFEO.js";
|
|
2
|
+
import { g as d, c as f, a as e } from "./index-C657rWjb.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-De2uSYsE.cjs"),t=require("./index-B9qohq82.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-Y1TSYFEO.js";
|
|
2
|
+
import { g as v, c as C, a as e } from "./index-C657rWjb.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-De2uSYsE.cjs"),t=require("./index-B9qohq82.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;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { jsxs as a, Fragment as Q, jsx as e } from "react/jsx-runtime";
|
|
2
|
-
import X, { useState as
|
|
2
|
+
import X, { useState as w, useCallback as A, useMemo as oe, useRef as ce, Suspense as Y } from "react";
|
|
3
3
|
import { mergeClasses as $ } from "@chaibuilder/sdk";
|
|
4
4
|
import { Tabs as de, TabsList as ue, TabsTrigger as H, Button as f, TabsContent as V, Input as me, Card as he, CardContent as ge, Dialog as pe, DialogContent as fe, DialogHeader as ye, DialogTitle as ve, DialogDescription as xe, DialogFooter as Ne } from "@chaibuilder/sdk/ui";
|
|
5
|
-
import { debounce as Ae, find as
|
|
5
|
+
import { debounce as Ae, find as Se, merge as we } from "lodash-es";
|
|
6
6
|
import { Search as be, Film as Ce, ImageIcon as Ee, Edit as Te, Trash2 as De, Loader2 as W, Upload as Pe } from "lucide-react";
|
|
7
7
|
import { useDropzone as Ue } from "react-dropzone";
|
|
8
|
-
import { useQueryClient as R, useMutation as K, useQuery as
|
|
8
|
+
import { useQueryClient as R, useMutation as K, useQuery as Fe } from "@tanstack/react-query";
|
|
9
9
|
import { toast as b } from "sonner";
|
|
10
|
-
import { W as
|
|
11
|
-
const
|
|
12
|
-
const t =
|
|
10
|
+
import { W as F, X as z, Y as y, Z as k } from "./index-C657rWjb.js";
|
|
11
|
+
const ze = () => {
|
|
12
|
+
const t = F(), r = R(), o = z();
|
|
13
13
|
return K({
|
|
14
14
|
mutationFn: async ({
|
|
15
15
|
file: i,
|
|
@@ -21,15 +21,15 @@ const Fe = () => {
|
|
|
21
21
|
}),
|
|
22
22
|
onSuccess: () => {
|
|
23
23
|
r.invalidateQueries({
|
|
24
|
-
queryKey: [
|
|
24
|
+
queryKey: [k, y.GET_ASSETS]
|
|
25
25
|
}), b.success("Asset uploaded successfully");
|
|
26
26
|
},
|
|
27
27
|
onError: () => {
|
|
28
28
|
b.error("Failed to upload asset");
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
|
-
},
|
|
32
|
-
const t =
|
|
31
|
+
}, ke = () => {
|
|
32
|
+
const t = F(), r = R(), o = z();
|
|
33
33
|
return K({
|
|
34
34
|
mutationFn: async (i) => o(t, {
|
|
35
35
|
action: y.DELETE_ASSET,
|
|
@@ -37,15 +37,15 @@ const Fe = () => {
|
|
|
37
37
|
}),
|
|
38
38
|
onSuccess: () => {
|
|
39
39
|
r.invalidateQueries({
|
|
40
|
-
queryKey: [
|
|
40
|
+
queryKey: [k, y.GET_ASSETS]
|
|
41
41
|
}), b.success("Asset deleted successfully");
|
|
42
42
|
},
|
|
43
43
|
onError: () => {
|
|
44
44
|
b.error("Failed to delete asset");
|
|
45
45
|
}
|
|
46
46
|
});
|
|
47
|
-
},
|
|
48
|
-
const t =
|
|
47
|
+
}, Me = () => {
|
|
48
|
+
const t = F(), r = R(), o = z();
|
|
49
49
|
return K({
|
|
50
50
|
mutationFn: async (i) => o(t, {
|
|
51
51
|
action: y.UPDATE_ASSET,
|
|
@@ -53,17 +53,17 @@ const Fe = () => {
|
|
|
53
53
|
}),
|
|
54
54
|
onSuccess: () => {
|
|
55
55
|
r.invalidateQueries({
|
|
56
|
-
queryKey: [
|
|
56
|
+
queryKey: [k, y.GET_ASSETS]
|
|
57
57
|
}), b.success("Asset updated successfully");
|
|
58
58
|
},
|
|
59
59
|
onError: () => {
|
|
60
60
|
b.error("Failed to update asset");
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
|
-
},
|
|
64
|
-
const r =
|
|
65
|
-
return
|
|
66
|
-
queryKey: [
|
|
63
|
+
}, Ie = (t = {}) => {
|
|
64
|
+
const r = F(), o = z(), { search: i, page: d = 1, limit: u = 10 } = t;
|
|
65
|
+
return Fe({
|
|
66
|
+
queryKey: [k, y.GET_ASSETS, i, d, u],
|
|
67
67
|
queryFn: async () => await o(r, {
|
|
68
68
|
action: y.GET_ASSETS,
|
|
69
69
|
data: {
|
|
@@ -76,15 +76,15 @@ const Fe = () => {
|
|
|
76
76
|
});
|
|
77
77
|
};
|
|
78
78
|
function qe() {
|
|
79
|
-
const [r, o] =
|
|
79
|
+
const [r, o] = w([]), [i, d] = w({
|
|
80
80
|
query: "",
|
|
81
81
|
page: 1,
|
|
82
82
|
pageSize: 10
|
|
83
|
-
}), u = Ae(() => i.query, 300)(), { data: n, isLoading: C } =
|
|
83
|
+
}), u = Ae(() => i.query, 300)(), { data: n, isLoading: C } = Ie({
|
|
84
84
|
search: (u == null ? void 0 : u.toLowerCase().trim()) || "",
|
|
85
85
|
page: i.page,
|
|
86
86
|
limit: i.pageSize
|
|
87
|
-
}), v = n ? Math.ceil(n.total / n.pageSize) : 0, c = (n == null ? void 0 : n.page) || 1, g = c < v, m = c > 1, { mutate: E, isPending:
|
|
87
|
+
}), v = n ? Math.ceil(n.total / n.pageSize) : 0, c = (n == null ? void 0 : n.page) || 1, g = c < v, m = c > 1, { mutate: E, isPending: M } = Me(), { mutate: S, isPending: p } = ze(), { mutate: T, isPending: D } = ke(), x = A(
|
|
88
88
|
(h) => {
|
|
89
89
|
h >= 1 && h <= v && d((N) => ({
|
|
90
90
|
...N,
|
|
@@ -92,7 +92,7 @@ function qe() {
|
|
|
92
92
|
}));
|
|
93
93
|
},
|
|
94
94
|
[v]
|
|
95
|
-
),
|
|
95
|
+
), I = A(() => {
|
|
96
96
|
g && x(c + 1);
|
|
97
97
|
}, [c, g, x]), q = A(() => {
|
|
98
98
|
m && x(c - 1);
|
|
@@ -105,7 +105,7 @@ function qe() {
|
|
|
105
105
|
}));
|
|
106
106
|
}, []), P = A(
|
|
107
107
|
(h) => {
|
|
108
|
-
o((N) =>
|
|
108
|
+
o((N) => Se(N, { id: h.id }) ? [] : [h]);
|
|
109
109
|
},
|
|
110
110
|
[!1]
|
|
111
111
|
), _ = A(() => {
|
|
@@ -121,11 +121,11 @@ function qe() {
|
|
|
121
121
|
hasNextPage: g,
|
|
122
122
|
hasPreviousPage: m,
|
|
123
123
|
// Mutations
|
|
124
|
-
uploadAsset:
|
|
124
|
+
uploadAsset: S,
|
|
125
125
|
updateAsset: E,
|
|
126
126
|
deleteAsset: T,
|
|
127
127
|
goToPage: x,
|
|
128
|
-
nextPage:
|
|
128
|
+
nextPage: I,
|
|
129
129
|
previousPage: q,
|
|
130
130
|
updateSearchQuery: j,
|
|
131
131
|
clearSelectedAssets: _,
|
|
@@ -133,7 +133,7 @@ function qe() {
|
|
|
133
133
|
// Loading
|
|
134
134
|
isLoadingAssets: C,
|
|
135
135
|
isUploadingAsset: p,
|
|
136
|
-
isUpdatingAsset:
|
|
136
|
+
isUpdatingAsset: M,
|
|
137
137
|
isDeletingAsset: D
|
|
138
138
|
};
|
|
139
139
|
}
|
|
@@ -143,16 +143,16 @@ function Xe({
|
|
|
143
143
|
onSelect: r,
|
|
144
144
|
mode: o = "image"
|
|
145
145
|
}) {
|
|
146
|
-
const d = oe(() => [o], [o]), [u, n] =
|
|
146
|
+
const d = oe(() => [o], [o]), [u, n] = w("browse"), [C, v] = w(null), [c, g] = w(null), [m, E] = w({ show: !1, file: "" }), {
|
|
147
147
|
// Data
|
|
148
|
-
query:
|
|
149
|
-
assets:
|
|
148
|
+
query: M,
|
|
149
|
+
assets: S,
|
|
150
150
|
selectedAssets: p,
|
|
151
151
|
// Mutations
|
|
152
152
|
uploadAsset: T,
|
|
153
153
|
updateAsset: D,
|
|
154
154
|
deleteAsset: x,
|
|
155
|
-
updateSearchQuery:
|
|
155
|
+
updateSearchQuery: I,
|
|
156
156
|
clearSelectedAssets: q,
|
|
157
157
|
updateSelectedAssets: j,
|
|
158
158
|
// Loading
|
|
@@ -164,20 +164,26 @@ function Xe({
|
|
|
164
164
|
async (s) => new Promise((l, L) => {
|
|
165
165
|
const O = s[0], U = new FileReader();
|
|
166
166
|
U.readAsDataURL(O), U.onload = async () => {
|
|
167
|
-
const B = await T(
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
167
|
+
const B = await T(
|
|
168
|
+
{
|
|
169
|
+
file: U.result,
|
|
170
|
+
folderId: null,
|
|
171
|
+
name: O.name
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
onSuccess: () => {
|
|
175
|
+
n("browse");
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
);
|
|
179
|
+
l(B);
|
|
173
180
|
}, U.onerror = (B) => L(B);
|
|
174
181
|
}),
|
|
175
182
|
[T]
|
|
176
183
|
), { getRootProps: Z, getInputProps: J, isDragActive: ee } = Ue({
|
|
177
184
|
onDrop: G,
|
|
178
185
|
accept: {
|
|
179
|
-
"image/*": d.includes("image") ? [] : []
|
|
180
|
-
"video/*": d.includes("video") ? [] : []
|
|
186
|
+
"image/*": d.includes("image") ? [] : []
|
|
181
187
|
},
|
|
182
188
|
maxSize: 10 * 1024 * 1024
|
|
183
189
|
}), se = () => {
|
|
@@ -189,9 +195,9 @@ function Xe({
|
|
|
189
195
|
}, le = (s) => {
|
|
190
196
|
v(s);
|
|
191
197
|
}, ie = async (s, l) => {
|
|
192
|
-
await D(
|
|
198
|
+
await D(we(s, l)), t();
|
|
193
199
|
}, ne = (s) => {
|
|
194
|
-
|
|
200
|
+
I(s.target.value);
|
|
195
201
|
}, re = async (s, l) => {
|
|
196
202
|
try {
|
|
197
203
|
l ? await T({
|
|
@@ -250,13 +256,13 @@ function Xe({
|
|
|
250
256
|
me,
|
|
251
257
|
{
|
|
252
258
|
placeholder: "Search assets...",
|
|
253
|
-
value:
|
|
259
|
+
value: M,
|
|
254
260
|
onChange: ne,
|
|
255
261
|
className: "pl-8"
|
|
256
262
|
}
|
|
257
263
|
)
|
|
258
264
|
] }) }),
|
|
259
|
-
P &&
|
|
265
|
+
P && S.length === 0 ? /* @__PURE__ */ a("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: [
|
|
260
266
|
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
261
267
|
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
262
268
|
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
@@ -267,7 +273,7 @@ function Xe({
|
|
|
267
273
|
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
268
274
|
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" }),
|
|
269
275
|
/* @__PURE__ */ e("div", { className: "bg-gray-200 h-64 w-full animate-pulse rounded" })
|
|
270
|
-
] }) :
|
|
276
|
+
] }) : S.length === 0 ? /* @__PURE__ */ a("div", { className: "flex flex-col items-center justify-center text-center p-12 h-[380px]", children: [
|
|
271
277
|
/* @__PURE__ */ a("div", { className: "text-muted-foreground mb-2", children: [
|
|
272
278
|
/* @__PURE__ */ e("h3", { className: "text-gray-800 font-medium", children: "No assets to display" }),
|
|
273
279
|
/* @__PURE__ */ e("p", { className: "text-sm", children: "You haven't uploaded any assets yet. Start by uploading your first asset." })
|
|
@@ -279,7 +285,7 @@ function Xe({
|
|
|
279
285
|
ref: N,
|
|
280
286
|
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",
|
|
281
287
|
children: [
|
|
282
|
-
|
|
288
|
+
S.map((s) => /* @__PURE__ */ e(
|
|
283
289
|
he,
|
|
284
290
|
{
|
|
285
291
|
className: $(
|
|
@@ -294,7 +300,7 @@ function Xe({
|
|
|
294
300
|
{
|
|
295
301
|
src: s.thumbnailUrl || "/placeholder.svg",
|
|
296
302
|
alt: s.name,
|
|
297
|
-
className: "object-cover w-full h-full"
|
|
303
|
+
className: "object-cover w-full h-full min-h-[100px]"
|
|
298
304
|
}
|
|
299
305
|
) : /* @__PURE__ */ a("div", { className: "flex items-center justify-center h-full", children: [
|
|
300
306
|
/* @__PURE__ */ e(Ce, { className: "h-12 w-12 text-muted-foreground" }),
|
|
@@ -380,7 +386,7 @@ function Xe({
|
|
|
380
386
|
},
|
|
381
387
|
s.id
|
|
382
388
|
)),
|
|
383
|
-
P &&
|
|
389
|
+
P && S.length > 0 && /* @__PURE__ */ e("div", { className: "col-span-full flex justify-center py-4", children: /* @__PURE__ */ e(W, { className: "h-6 w-6 animate-spin text-muted-foreground" }) })
|
|
384
390
|
]
|
|
385
391
|
}
|
|
386
392
|
)
|
|
@@ -466,7 +472,7 @@ function Xe({
|
|
|
466
472
|
] });
|
|
467
473
|
}
|
|
468
474
|
function Le(t) {
|
|
469
|
-
return t < 1024 ? `${t.toFixed(2)} KB` : `${(t / 1024).toFixed(2)} MB`;
|
|
475
|
+
return t < 1024 ? `${t.toFixed(2)} B` : t < 1024 * 1024 ? `${(t / 1024).toFixed(2)} KB` : `${(t / (1024 * 1024)).toFixed(2)} MB`;
|
|
470
476
|
}
|
|
471
477
|
function Be(t) {
|
|
472
478
|
const r = new Date(t);
|
|
@@ -0,0 +1 @@
|
|
|
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"),M=require("lodash-es"),j=require("lucide-react"),X=require("react-dropzone"),A=require("@tanstack/react-query"),b=require("sonner"),a=require("./index-B9qohq82.cjs"),Z=()=>{const l=a.useAssetsApiUrl(),c=A.useQueryClient(),d=a.useFetch();return A.useMutation({mutationFn:async({file:r,folderId:m,name:h})=>d(l,{action:a.ACTIONS.UPLOAD_ASSET,data:{file:r,folderId:m,name:h}}),onSuccess:()=>{c.invalidateQueries({queryKey:[a.QUERY_KEY_BASE,a.ACTIONS.GET_ASSETS]}),b.toast.success("Asset uploaded successfully")},onError:()=>{b.toast.error("Failed to upload asset")}})},ee=()=>{const l=a.useAssetsApiUrl(),c=A.useQueryClient(),d=a.useFetch();return A.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]}),b.toast.success("Asset deleted successfully")},onError:()=>{b.toast.error("Failed to delete asset")}})},se=()=>{const l=a.useAssetsApiUrl(),c=A.useQueryClient(),d=a.useFetch();return A.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]}),b.toast.success("Asset updated successfully")},onError:()=>{b.toast.error("Failed to update asset")}})},te=(l={})=>{const c=a.useAssetsApiUrl(),d=a.useFetch(),{search:r,page:m=1,limit:h=10}=l;return A.useQuery({queryKey:[a.QUERY_KEY_BASE,a.ACTIONS.GET_ASSETS,r,m,h],queryFn:async()=>await d(c,{action:a.ACTIONS.GET_ASSETS,data:{search:r,page:m,limit:h}}),retry:1})};function ae(){const[c,d]=n.useState([]),[r,m]=n.useState({query:"",page:1,pageSize:10}),h=M.debounce(()=>r.query,300)(),{data:o,isLoading:w}=te({search:(h==null?void 0:h.toLowerCase().trim())||"",page:r.page,limit:r.pageSize}),y=o?Math.ceil(o.total/o.pageSize):0,u=(o==null?void 0:o.page)||1,p=u<y,g=u>1,{mutate:C,isPending:P}=se(),{mutate:N,isPending:f}=Z(),{mutate:E,isPending:T}=ee(),v=n.useCallback(x=>{x>=1&&x<=y&&m(S=>({...S,page:x}))},[y]),q=n.useCallback(()=>{p&&v(u+1)},[u,p,v]),F=n.useCallback(()=>{g&&v(u-1)},[u,g,v]),k=n.useCallback(x=>{m(S=>({...S,query:x,page:1}))},[]),D=n.useCallback(x=>{d(S=>M.find(S,{id:x.id})?[]:[x])},[!1]),I=n.useCallback(()=>{d([])},[]);return{query:(r==null?void 0:r.query)||"",selectedAssets:c,assets:(o==null?void 0:o.assets)||[],currentPage:u,totalPages:y,hasNextPage:p,hasPreviousPage:g,uploadAsset:N,updateAsset:C,deleteAsset:E,goToPage:v,nextPage:q,previousPage:F,updateSearchQuery:k,clearSelectedAssets:I,updateSelectedAssets:D,isLoadingAssets:w,isUploadingAsset:f,isUpdatingAsset:P,isDeletingAsset:T}}const le=n.lazy(()=>Promise.resolve().then(()=>require("./asset-metadata-editor-zw9u1BB9.cjs"))),ne=n.lazy(()=>Promise.resolve().then(()=>require("./image-editor-D8wu5UNM.cjs")));function ie({close:l,onSelect:c,mode:d="image"}){const m=n.useMemo(()=>[d],[d]),[h,o]=n.useState("browse"),[w,y]=n.useState(null),[u,p]=n.useState(null),[g,C]=n.useState({show:!1,file:""}),{query:P,assets:N,selectedAssets:f,uploadAsset:E,updateAsset:T,deleteAsset:v,updateSearchQuery:q,clearSelectedAssets:F,updateSelectedAssets:k,isLoadingAssets:D,isUploadingAsset:I,isUpdatingAsset:x}=ae(),S=n.useRef(null),_=n.useCallback(async s=>new Promise((i,z)=>{const Q=s[0],U=new FileReader;U.readAsDataURL(Q),U.onload=async()=>{const B=await E({file:U.result,folderId:null,name:Q.name},{onSuccess:()=>{o("browse")}});i(B)},U.onerror=B=>z(B)}),[E]),{getRootProps:O,getInputProps:R,isDragActive:K}=X.useDropzone({onDrop:_,accept:{"image/*":m.includes("image")?[]:[]},maxSize:10*1024*1024}),Y=()=>{c([f[0].url]),l()},G=async s=>{p(s)},$=async()=>{u&&(await v(u.id),p(null))},H=s=>{y(s)},V=async(s,i)=>{await T(M.merge(s,i)),l()},J=s=>{q(s.target.value)},W=async(s,i)=>{try{i?await E({file:s,folderId:null,name:g.name||""}):await T({id:g.id||"",file:s}),C({show:!1,file:""}),o("browse")}catch(z){console.error("Error saving edited image:",z)}};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:h,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:[f.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:f.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:P,onChange:J,className:"pl-8"})]})}),D&&N.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"})]}):N.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:S,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:[N.map(s=>e.jsx(t.Card,{className:L.mergeClasses("cursor-pointer overflow-hidden transition-all",f.some(i=>i.id===s.id)?"ring-2 ring-primary":"hover:ring-2 hover:ring-primary/20"),onClick:()=>k(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(),C({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"})})]}),f.some(i=>i.id===s.id)&&e.jsx("div",{className:"absolute top-2 left-2",children:e.jsx("input",{type:"checkbox",checked:f.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&&N.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()}),x||I?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: ",m.join(", ")]}),e.jsxs("p",{children:["Maximum file size: ",10,"MB"]})]})]})]})})]})]}),w&&e.jsx(n.Suspense,{fallback:e.jsx("div",{children:"Loading..."}),children:e.jsx(le,{asset:w,onSave:s=>V(w,s),onCancel:()=>{y(null)}})}),g.show&&e.jsx(n.Suspense,{fallback:e.jsx("div",{children:"Loading..."}),children:e.jsx(ne,{imageUrl:g.file,onSave:W,onClose:()=>C({show:!1,file:""}),defaultSavedImageName:g.name,isEditing:!!g.id})}),u&&e.jsx(t.Dialog,{open:!!u,onOpenChange:()=>p(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:()=>p(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;
|