@dimah-s3/ui 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +28 -0
  3. package/dist/components/delete/delete-button.d.ts +38 -0
  4. package/dist/components/delete/delete-button.d.ts.map +1 -0
  5. package/dist/components/download/download-button.d.ts +30 -0
  6. package/dist/components/download/download-button.d.ts.map +1 -0
  7. package/dist/components/download/progress-download-button.d.ts +39 -0
  8. package/dist/components/download/progress-download-button.d.ts.map +1 -0
  9. package/dist/components/ui/alert-dialog.d.ts +19 -0
  10. package/dist/components/ui/alert-dialog.d.ts.map +1 -0
  11. package/dist/components/ui/button.d.ts +9 -0
  12. package/dist/components/ui/button.d.ts.map +1 -0
  13. package/dist/components/ui/circle-progress.d.ts +6 -0
  14. package/dist/components/ui/circle-progress.d.ts.map +1 -0
  15. package/dist/components/ui/progress.d.ts +8 -0
  16. package/dist/components/ui/progress.d.ts.map +1 -0
  17. package/dist/components/ui/tooltip.d.ts +7 -0
  18. package/dist/components/ui/tooltip.d.ts.map +1 -0
  19. package/dist/components/upload/multi-upload-status.d.ts +9 -0
  20. package/dist/components/upload/multi-upload-status.d.ts.map +1 -0
  21. package/dist/components/upload/upload-button.d.ts +30 -0
  22. package/dist/components/upload/upload-button.d.ts.map +1 -0
  23. package/dist/components/upload/upload-dropzone.d.ts +22 -0
  24. package/dist/components/upload/upload-dropzone.d.ts.map +1 -0
  25. package/dist/components/upload/upload-status-block.d.ts +23 -0
  26. package/dist/components/upload/upload-status-block.d.ts.map +1 -0
  27. package/dist/components/upload/upload-status.d.ts +14 -0
  28. package/dist/components/upload/upload-status.d.ts.map +1 -0
  29. package/dist/hooks/use-delete-toast.d.ts +9 -0
  30. package/dist/hooks/use-delete-toast.d.ts.map +1 -0
  31. package/dist/hooks/use-download-toast.d.ts +14 -0
  32. package/dist/hooks/use-download-toast.d.ts.map +1 -0
  33. package/dist/hooks/use-upload-toast.d.ts +20 -0
  34. package/dist/hooks/use-upload-toast.d.ts.map +1 -0
  35. package/dist/index.d.ts +9 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +1306 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/lib/utils.d.ts +2 -0
  40. package/dist/lib/utils.d.ts.map +1 -0
  41. package/package.json +78 -0
  42. package/styles.css +7 -0
package/dist/index.js ADDED
@@ -0,0 +1,1306 @@
1
+ import { PauseIcon, XIcon, CheckCircleIcon, AlertCircleIcon, CloudUpload, LoaderIcon, DownloadIcon, Trash2Icon, CheckCircle2Icon } from 'lucide-react';
2
+ import { useTranslations } from '@fuma-translate/react';
3
+ import { formatEta, useUploadControls, useMultiUploadControls, formatAcceptLabels, useDownload, useFetchDownload, useDelete, useFormatDimahError } from '@dimah-s3/react';
4
+ import { cn } from 'cnfast';
5
+ import { Button as Button$1 } from '@base-ui/react/button';
6
+ import { cva } from 'class-variance-authority';
7
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
8
+ import { Tooltip as Tooltip$1 } from '@base-ui/react/tooltip';
9
+ import { truncateFileName, formatFileSize } from '@dimah-s3/core';
10
+ import { Progress as Progress$1 } from '@base-ui/react/progress';
11
+ import { useState, useRef, useLayoutEffect, useEffect } from 'react';
12
+ import { toast } from 'sonner';
13
+ import { AlertDialog as AlertDialog$1 } from '@base-ui/react/alert-dialog';
14
+
15
+ var buttonVariants = cva(
16
+ "group/button inline-flex shrink-0 items-center justify-center rounded-md border border-transparent bg-clip-padding text-xs/relaxed font-medium whitespace-nowrap transition-all outline-none select-none focus-visible:border-ring focus-visible:ring-2 focus-visible:ring-ring/30 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-2 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
17
+ {
18
+ variants: {
19
+ variant: {
20
+ default: "bg-primary text-primary-foreground hover:bg-primary/80",
21
+ outline: "border-border hover:bg-input/50 hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:bg-input/30",
22
+ secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground",
23
+ ghost: "hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:hover:bg-muted/50",
24
+ destructive: "bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40",
25
+ link: "text-primary underline-offset-4 hover:underline"
26
+ },
27
+ size: {
28
+ default: "h-7 gap-1 px-2 text-xs/relaxed has-data-[icon=inline-end]:pe-1.5 has-data-[icon=inline-start]:ps-1.5 [&_svg:not([class*='size-'])]:size-3.5",
29
+ xs: "h-5 gap-1 rounded-sm px-2 text-[0.625rem] has-data-[icon=inline-end]:pe-1.5 has-data-[icon=inline-start]:ps-1.5 [&_svg:not([class*='size-'])]:size-2.5",
30
+ sm: "h-6 gap-1 px-2 text-xs/relaxed has-data-[icon=inline-end]:pe-1.5 has-data-[icon=inline-start]:ps-1.5 [&_svg:not([class*='size-'])]:size-3",
31
+ lg: "h-8 gap-1 px-2.5 text-xs/relaxed has-data-[icon=inline-end]:pe-2 has-data-[icon=inline-start]:ps-2 [&_svg:not([class*='size-'])]:size-4",
32
+ icon: "size-7 [&_svg:not([class*='size-'])]:size-3.5",
33
+ "icon-xs": "size-5 rounded-sm [&_svg:not([class*='size-'])]:size-2.5",
34
+ "icon-sm": "size-6 [&_svg:not([class*='size-'])]:size-3",
35
+ "icon-lg": "size-8 [&_svg:not([class*='size-'])]:size-4"
36
+ }
37
+ },
38
+ defaultVariants: {
39
+ variant: "default",
40
+ size: "default"
41
+ }
42
+ }
43
+ );
44
+ function Button({
45
+ className,
46
+ variant = "default",
47
+ size = "default",
48
+ ...props
49
+ }) {
50
+ return /* @__PURE__ */ jsx(
51
+ Button$1,
52
+ {
53
+ "data-slot": "button",
54
+ className: cn(buttonVariants({ variant, size, className })),
55
+ ...props
56
+ }
57
+ );
58
+ }
59
+ function Tooltip({ ...props }) {
60
+ return /* @__PURE__ */ jsx(Tooltip$1.Root, { "data-slot": "tooltip", ...props });
61
+ }
62
+ function TooltipTrigger({ ...props }) {
63
+ return /* @__PURE__ */ jsx(Tooltip$1.Trigger, { "data-slot": "tooltip-trigger", ...props });
64
+ }
65
+ function TooltipContent({
66
+ className,
67
+ side = "top",
68
+ sideOffset = 4,
69
+ align = "center",
70
+ alignOffset = 0,
71
+ children,
72
+ ...props
73
+ }) {
74
+ return /* @__PURE__ */ jsx(Tooltip$1.Portal, { children: /* @__PURE__ */ jsx(
75
+ Tooltip$1.Positioner,
76
+ {
77
+ align,
78
+ alignOffset,
79
+ side,
80
+ sideOffset,
81
+ className: "isolate z-50",
82
+ children: /* @__PURE__ */ jsxs(
83
+ Tooltip$1.Popup,
84
+ {
85
+ "data-slot": "tooltip-content",
86
+ className: cn(
87
+ "z-50 inline-flex w-fit max-w-xs origin-(--transform-origin) items-center gap-1.5 rounded-md bg-foreground px-3 py-1.5 text-xs text-background has-data-[slot=kbd]:pe-1.5 data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-start-2 data-[side=inline-start]:slide-in-from-end-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 **:data-[slot=kbd]:relative **:data-[slot=kbd]:isolate **:data-[slot=kbd]:z-50 **:data-[slot=kbd]:rounded-sm data-[state=delayed-open]:animate-in data-[state=delayed-open]:fade-in-0 data-[state=delayed-open]:zoom-in-95 data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
88
+ className
89
+ ),
90
+ ...props,
91
+ children: [
92
+ children,
93
+ /* @__PURE__ */ jsx(Tooltip$1.Arrow, { className: "z-50 size-2.5 translate-y-[calc(-50%-2px)] rotate-45 rounded-[2px] bg-foreground fill-foreground data-[side=bottom]:top-1 data-[side=inline-end]:top-1/2! data-[side=inline-end]:-start-1 data-[side=inline-end]:-translate-y-1/2 data-[side=inline-start]:top-1/2! data-[side=inline-start]:-end-1 data-[side=inline-start]:-translate-y-1/2 data-[side=left]:top-1/2! data-[side=left]:-right-1 data-[side=left]:-translate-y-1/2 data-[side=right]:top-1/2! data-[side=right]:-left-1 data-[side=right]:-translate-y-1/2 data-[side=top]:-bottom-2.5" })
94
+ ]
95
+ }
96
+ )
97
+ }
98
+ ) });
99
+ }
100
+ function CircleProgress({
101
+ percent,
102
+ size = 20,
103
+ strokeWidth = 2.5
104
+ }) {
105
+ const r = (size - strokeWidth) / 2;
106
+ const c = 2 * Math.PI * r;
107
+ const offset = c - percent / 100 * c;
108
+ return /* @__PURE__ */ jsxs("svg", { width: size, height: size, className: "shrink-0 -rotate-90", children: [
109
+ /* @__PURE__ */ jsx(
110
+ "circle",
111
+ {
112
+ cx: size / 2,
113
+ cy: size / 2,
114
+ r,
115
+ fill: "none",
116
+ stroke: "currentColor",
117
+ strokeWidth,
118
+ className: "text-muted-foreground/20"
119
+ }
120
+ ),
121
+ /* @__PURE__ */ jsx(
122
+ "circle",
123
+ {
124
+ cx: size / 2,
125
+ cy: size / 2,
126
+ r,
127
+ fill: "none",
128
+ stroke: "currentColor",
129
+ strokeWidth,
130
+ strokeDasharray: c,
131
+ strokeDashoffset: offset,
132
+ strokeLinecap: "round",
133
+ className: "text-primary transition-[stroke-dashoffset] duration-200"
134
+ }
135
+ )
136
+ ] });
137
+ }
138
+ function UploadStatus({
139
+ phase,
140
+ progress,
141
+ error,
142
+ fileInfo,
143
+ onCancel,
144
+ onPause
145
+ }) {
146
+ const t = useTranslations();
147
+ if (phase === "idle") return null;
148
+ if (phase === "uploading" && fileInfo) {
149
+ const eta = progress.speed && progress.total ? formatEta(progress.total - progress.loaded, progress.speed) : null;
150
+ return /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-2 text-xs", children: [
151
+ /* @__PURE__ */ jsx(CircleProgress, { percent: progress.percent, size: 14, strokeWidth: 2 }),
152
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 items-center gap-1.5", children: [
153
+ /* @__PURE__ */ jsx("span", { className: "truncate max-w-[30ch]", children: truncateFileName(fileInfo.name) }),
154
+ eta ? /* @__PURE__ */ jsxs("span", { className: "shrink-0 text-muted-foreground", children: [
155
+ "\xB7 ",
156
+ eta
157
+ ] }) : null
158
+ ] }),
159
+ /* @__PURE__ */ jsx("span", { className: "ms-auto shrink-0 whitespace-nowrap tabular-nums text-muted-foreground", children: formatFileSize(fileInfo.size) }),
160
+ onPause ? /* @__PURE__ */ jsx(
161
+ Button,
162
+ {
163
+ variant: "ghost",
164
+ size: "icon",
165
+ className: "size-6 shrink-0",
166
+ "aria-label": t("Pause", { note: "upload control" }),
167
+ onClick: (e) => {
168
+ e.stopPropagation();
169
+ onPause();
170
+ },
171
+ children: /* @__PURE__ */ jsx(PauseIcon, { className: "size-3.5" })
172
+ }
173
+ ) : null,
174
+ /* @__PURE__ */ jsx(
175
+ Button,
176
+ {
177
+ variant: "ghost",
178
+ size: "icon",
179
+ className: "size-6 shrink-0",
180
+ "aria-label": t("Cancel", { note: "upload control" }),
181
+ onClick: (e) => {
182
+ e.stopPropagation();
183
+ onCancel?.();
184
+ },
185
+ children: /* @__PURE__ */ jsx(XIcon, { className: "size-3.5" })
186
+ }
187
+ )
188
+ ] });
189
+ }
190
+ if (phase === "success" && fileInfo) {
191
+ return /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-1.5 text-xs", children: [
192
+ /* @__PURE__ */ jsx(CheckCircleIcon, { className: "size-3.5 shrink-0 text-green-600" }),
193
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate max-w-[30ch]", children: truncateFileName(fileInfo.name) }),
194
+ /* @__PURE__ */ jsx("span", { className: "ms-auto shrink-0 text-muted-foreground", children: formatFileSize(fileInfo.size) })
195
+ ] });
196
+ }
197
+ if (phase === "error") {
198
+ return /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-start gap-1.5 text-xs", children: [
199
+ /* @__PURE__ */ jsx(AlertCircleIcon, { className: "mt-0.5 size-3.5 shrink-0 text-destructive" }),
200
+ /* @__PURE__ */ jsx("p", { className: "min-w-0 [overflow-wrap:anywhere] text-destructive", children: error ?? t("Upload failed", { note: "status" }) })
201
+ ] });
202
+ }
203
+ if (phase === "validating" || phase === "presigning") {
204
+ return /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t("Preparing\u2026", { note: "upload status" }) });
205
+ }
206
+ return null;
207
+ }
208
+ function Progress({
209
+ className,
210
+ children,
211
+ value,
212
+ ...props
213
+ }) {
214
+ return /* @__PURE__ */ jsxs(
215
+ Progress$1.Root,
216
+ {
217
+ value,
218
+ "data-slot": "progress",
219
+ className: cn("flex flex-wrap gap-3", className),
220
+ ...props,
221
+ children: [
222
+ children,
223
+ /* @__PURE__ */ jsx(ProgressTrack, { children: /* @__PURE__ */ jsx(ProgressIndicator, {}) })
224
+ ]
225
+ }
226
+ );
227
+ }
228
+ function ProgressTrack({ className, ...props }) {
229
+ return /* @__PURE__ */ jsx(
230
+ Progress$1.Track,
231
+ {
232
+ className: cn(
233
+ "relative flex h-1 w-full items-center overflow-x-hidden rounded-md bg-muted",
234
+ className
235
+ ),
236
+ "data-slot": "progress-track",
237
+ ...props
238
+ }
239
+ );
240
+ }
241
+ function ProgressIndicator({
242
+ className,
243
+ ...props
244
+ }) {
245
+ return /* @__PURE__ */ jsx(
246
+ Progress$1.Indicator,
247
+ {
248
+ "data-slot": "progress-indicator",
249
+ className: cn("h-full bg-primary transition-all", className),
250
+ ...props
251
+ }
252
+ );
253
+ }
254
+ function ProgressLabel({ className, ...props }) {
255
+ return /* @__PURE__ */ jsx(
256
+ Progress$1.Label,
257
+ {
258
+ className: cn("text-xs/relaxed font-medium", className),
259
+ "data-slot": "progress-label",
260
+ ...props
261
+ }
262
+ );
263
+ }
264
+ function ProgressValue({ className, ...props }) {
265
+ return /* @__PURE__ */ jsx(
266
+ Progress$1.Value,
267
+ {
268
+ className: cn(
269
+ "ms-auto text-xs/relaxed text-muted-foreground tabular-nums",
270
+ className
271
+ ),
272
+ "data-slot": "progress-value",
273
+ ...props
274
+ }
275
+ );
276
+ }
277
+ function MultiUploadStatus({
278
+ phase,
279
+ files,
280
+ totalProgress,
281
+ error,
282
+ onCancel
283
+ }) {
284
+ const t = useTranslations();
285
+ if (phase === "idle") return null;
286
+ if (phase === "uploading") {
287
+ const eta = totalProgress.speed && totalProgress.total ? formatEta(
288
+ totalProgress.total - totalProgress.loaded,
289
+ totalProgress.speed
290
+ ) : null;
291
+ return /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-2", children: [
292
+ /* @__PURE__ */ jsxs("div", { className: "flex w-full items-center gap-1.5", children: [
293
+ /* @__PURE__ */ jsxs(Progress, { value: totalProgress.percent, className: "flex-1", children: [
294
+ /* @__PURE__ */ jsxs(ProgressLabel, { children: [
295
+ t("{done}/{total} files", {
296
+ note: "upload progress",
297
+ variables: {
298
+ done: String(
299
+ files.filter((f) => f.status === "success").length
300
+ ),
301
+ total: String(files.length)
302
+ }
303
+ }),
304
+ eta ? /* @__PURE__ */ jsxs("span", { className: "font-normal text-muted-foreground", children: [
305
+ " ",
306
+ "\xB7 ",
307
+ eta
308
+ ] }) : null
309
+ ] }),
310
+ /* @__PURE__ */ jsx(ProgressValue, {})
311
+ ] }),
312
+ /* @__PURE__ */ jsx(
313
+ Button,
314
+ {
315
+ variant: "ghost",
316
+ size: "icon",
317
+ className: "size-7 shrink-0",
318
+ "aria-label": t("Cancel", { note: "upload control" }),
319
+ onClick: (e) => {
320
+ e.stopPropagation();
321
+ onCancel?.();
322
+ },
323
+ children: /* @__PURE__ */ jsx(XIcon, { className: "size-4" })
324
+ }
325
+ )
326
+ ] }),
327
+ /* @__PURE__ */ jsx(FileList, { files })
328
+ ] });
329
+ }
330
+ if (phase === "success") {
331
+ return /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-1", children: [
332
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-green-600", children: t("All {count} file(s) uploaded", {
333
+ note: "status",
334
+ variables: { count: String(files.length) }
335
+ }) }),
336
+ /* @__PURE__ */ jsx(FileList, { files })
337
+ ] });
338
+ }
339
+ if (phase === "error") {
340
+ return /* @__PURE__ */ jsxs("div", { className: "flex w-full flex-col gap-1", children: [
341
+ /* @__PURE__ */ jsx("span", { className: "text-xs text-destructive", children: error ?? t("Upload failed", { note: "status" }) }),
342
+ files.length > 0 && /* @__PURE__ */ jsx(FileList, { files })
343
+ ] });
344
+ }
345
+ if (phase === "validating") {
346
+ return /* @__PURE__ */ jsx("span", { className: "text-xs text-muted-foreground", children: t("Validating\u2026", { note: "upload status" }) });
347
+ }
348
+ return null;
349
+ }
350
+ function FileList({ files }) {
351
+ return /* @__PURE__ */ jsx("ul", { className: "flex flex-col gap-1", children: files.map((f) => /* @__PURE__ */ jsxs("li", { className: "flex flex-col gap-0.5 text-xs", children: [
352
+ /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-1.5", children: [
353
+ f.status === "success" && /* @__PURE__ */ jsx(CheckCircleIcon, { className: "size-3.5 shrink-0 text-green-600" }),
354
+ f.status === "error" && /* @__PURE__ */ jsx(AlertCircleIcon, { className: "size-3.5 shrink-0 text-destructive" }),
355
+ (f.status === "pending" || f.status === "uploading") && /* @__PURE__ */ jsx(
356
+ CircleProgress,
357
+ {
358
+ percent: f.status === "uploading" ? f.progress.percent : 0,
359
+ size: 14,
360
+ strokeWidth: 2
361
+ }
362
+ ),
363
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 shrink", children: truncateFileName(f.fileName) }),
364
+ /* @__PURE__ */ jsx("span", { className: "shrink-0 text-muted-foreground", children: formatFileSize(f.fileSize) })
365
+ ] }),
366
+ f.status === "error" && f.error && /* @__PURE__ */ jsx("span", { className: "truncate [overflow-wrap:anywhere] ps-5 text-destructive", children: f.error })
367
+ ] }, f.id)) });
368
+ }
369
+ function UploadStatusBlock(props) {
370
+ if (props.mode === "multi" && props.files.length === 1) {
371
+ const f = props.files[0];
372
+ return /* @__PURE__ */ jsx(
373
+ UploadStatus,
374
+ {
375
+ phase: props.phase,
376
+ progress: f.progress,
377
+ error: f.error ?? props.error,
378
+ fileInfo: { name: f.fileName, size: f.fileSize },
379
+ onCancel: props.onCancel,
380
+ onPause: props.onPause
381
+ }
382
+ );
383
+ }
384
+ if (props.mode === "multi") {
385
+ return /* @__PURE__ */ jsx(
386
+ MultiUploadStatus,
387
+ {
388
+ phase: props.phase,
389
+ files: props.files,
390
+ totalProgress: props.totalProgress,
391
+ error: props.error,
392
+ onCancel: props.onCancel
393
+ }
394
+ );
395
+ }
396
+ return /* @__PURE__ */ jsx(
397
+ UploadStatus,
398
+ {
399
+ phase: props.phase,
400
+ progress: props.progress,
401
+ error: props.error,
402
+ fileInfo: props.fileInfo,
403
+ onCancel: props.onCancel,
404
+ onPause: props.onPause
405
+ }
406
+ );
407
+ }
408
+ function sizeNode(size) {
409
+ return /* @__PURE__ */ jsx("span", { dir: "ltr", className: "inline-block whitespace-nowrap tabular-nums", children: formatFileSize(size) });
410
+ }
411
+ function progressNode(loaded, total) {
412
+ return /* @__PURE__ */ jsxs("span", { dir: "ltr", className: "inline-block whitespace-nowrap tabular-nums", children: [
413
+ formatFileSize(loaded),
414
+ " / ",
415
+ formatFileSize(total)
416
+ ] });
417
+ }
418
+ function useUploadToast(ctrl, enabled) {
419
+ const t = useTranslations();
420
+ const toastIdRef = useRef(null);
421
+ const prevPhaseRef = useRef(ctrl.phase);
422
+ const cancelRef = useRef(ctrl.cancel);
423
+ useLayoutEffect(() => {
424
+ cancelRef.current = ctrl.cancel;
425
+ });
426
+ const { mode, phase, fileInfo, progress, files, totalProgress, error } = ctrl;
427
+ useEffect(() => {
428
+ if (prevPhaseRef.current === phase) return;
429
+ prevPhaseRef.current = phase;
430
+ if (!enabled) return;
431
+ const fileList = files ?? [];
432
+ const isMulti = mode === "multi" && fileList.length > 1;
433
+ const file = fileInfo ?? (fileList.length === 1 ? { name: fileList[0].fileName, size: fileList[0].fileSize } : null);
434
+ const total = totalProgress?.total ?? 0;
435
+ if (phase === "idle" && toastIdRef.current) {
436
+ toast.dismiss(toastIdRef.current);
437
+ toastIdRef.current = null;
438
+ }
439
+ if (phase === "success") {
440
+ if (toastIdRef.current) toast.dismiss(toastIdRef.current);
441
+ if (isMulti) {
442
+ toast.success(
443
+ t("{count} file(s) uploaded", {
444
+ note: "toast",
445
+ variables: { count: String(fileList.length) }
446
+ }),
447
+ {
448
+ description: sizeNode(total)
449
+ }
450
+ );
451
+ } else if (file) {
452
+ toast.success(t("Upload complete", { note: "toast" }), {
453
+ description: sizeNode(file.size)
454
+ });
455
+ }
456
+ toastIdRef.current = null;
457
+ }
458
+ if (phase === "error") {
459
+ if (toastIdRef.current) toast.dismiss(toastIdRef.current);
460
+ if (isMulti && fileList.length > 0) {
461
+ const succeeded = fileList.filter((f) => f.status === "success").length;
462
+ const failed = fileList.filter((f) => f.status === "error").length;
463
+ toast.error(t("Upload finished with errors", { note: "toast" }), {
464
+ description: /* @__PURE__ */ jsx(
465
+ "span",
466
+ {
467
+ dir: "ltr",
468
+ className: "inline-block whitespace-nowrap tabular-nums",
469
+ children: t("{succeeded} succeeded, {failed} failed", {
470
+ note: "toast",
471
+ variables: {
472
+ succeeded: String(succeeded),
473
+ failed: String(failed)
474
+ }
475
+ })
476
+ }
477
+ )
478
+ });
479
+ } else {
480
+ toast.error(t("Upload failed", { note: "toast" }), {
481
+ description: /* @__PURE__ */ jsx("span", { dir: "auto", className: "block [overflow-wrap:anywhere]", children: error ?? fileList[0]?.error ?? t("Unknown error", { note: "fallback" }) })
482
+ });
483
+ }
484
+ toastIdRef.current = null;
485
+ }
486
+ }, [enabled, phase, mode, fileInfo, files, totalProgress, error, t]);
487
+ useEffect(() => {
488
+ if (!enabled || phase !== "uploading") return;
489
+ const fileList = files ?? [];
490
+ const isMulti = mode === "multi" && fileList.length > 1;
491
+ const file = fileInfo ?? (fileList.length === 1 ? { name: fileList[0].fileName, size: fileList[0].fileSize } : null);
492
+ const total = totalProgress ?? { loaded: 0, total: 0};
493
+ const singleProgress = progress ?? (fileList.length === 1 ? fileList[0].progress : { loaded: 0});
494
+ const id = toastIdRef.current ?? `upload-${Date.now()}`;
495
+ toastIdRef.current = id;
496
+ if (isMulti) {
497
+ const done = fileList.filter((f) => f.status === "success").length;
498
+ toast.loading(
499
+ t("Uploading {done}/{total}", {
500
+ note: "toast",
501
+ variables: { done: String(done), total: String(fileList.length) }
502
+ }),
503
+ {
504
+ id,
505
+ description: progressNode(total.loaded, total.total),
506
+ cancel: {
507
+ label: t("Cancel", { note: "toast action" }),
508
+ onClick: () => cancelRef.current()
509
+ }
510
+ }
511
+ );
512
+ } else if (file) {
513
+ toast.loading(t("Uploading", { note: "toast" }), {
514
+ id,
515
+ description: progressNode(singleProgress.loaded, file.size),
516
+ cancel: {
517
+ label: t("Cancel", { note: "toast action" }),
518
+ onClick: () => cancelRef.current()
519
+ }
520
+ });
521
+ }
522
+ }, [enabled, phase, mode, fileInfo, files, progress, totalProgress, t]);
523
+ }
524
+ var EMPTY_PROGRESS = { loaded: 0, total: 0, percent: 0 };
525
+ var EMPTY_FILES = [];
526
+ function UploadButton({
527
+ className,
528
+ label,
529
+ children,
530
+ disabled,
531
+ tooltipText,
532
+ toast: enableToast = true,
533
+ showStatus = true,
534
+ multiple,
535
+ variant = "default",
536
+ size = "default",
537
+ buttonClassName,
538
+ ...options
539
+ }) {
540
+ const t = useTranslations();
541
+ const isMulti = multiple === true || (options.maxFiles ?? 1) > 1;
542
+ const single = useUploadControls(options);
543
+ const multi = useMultiUploadControls(
544
+ options
545
+ );
546
+ const canPause = options.uploadStore != null && options.uploadStore !== false;
547
+ const ctrl = isMulti ? {
548
+ mode: "multi",
549
+ phase: multi.phase,
550
+ files: multi.files,
551
+ totalProgress: multi.totalProgress,
552
+ error: multi.error,
553
+ cancel: multi.cancel
554
+ } : {
555
+ mode: "single",
556
+ phase: single.phase,
557
+ fileInfo: single.fileInfo,
558
+ progress: single.progress,
559
+ error: single.error,
560
+ cancel: single.cancel
561
+ };
562
+ const isDisabled = disabled || (isMulti ? multi.isUploading : single.isUploading);
563
+ useUploadToast(ctrl, enableToast);
564
+ const status = showStatus ? isMulti ? /* @__PURE__ */ jsx(
565
+ UploadStatusBlock,
566
+ {
567
+ mode: "multi",
568
+ phase: multi.phase,
569
+ files: multi.files ?? EMPTY_FILES,
570
+ totalProgress: multi.totalProgress ?? EMPTY_PROGRESS,
571
+ error: multi.error,
572
+ onCancel: multi.cancel,
573
+ onPause: canPause ? multi.detach : void 0
574
+ }
575
+ ) : /* @__PURE__ */ jsx(
576
+ UploadStatusBlock,
577
+ {
578
+ mode: "single",
579
+ phase: single.phase,
580
+ progress: single.progress,
581
+ error: single.error,
582
+ fileInfo: single.fileInfo,
583
+ onCancel: single.cancel,
584
+ onPause: canPause ? single.detach : void 0
585
+ }
586
+ ) : null;
587
+ const openFilePicker = isMulti ? multi.openFilePicker : single.openFilePicker;
588
+ const inputProps = isMulti ? multi.inputProps : single.inputProps;
589
+ const buttonLabel = label ?? (isMulti ? t("Upload files", { note: "button" }) : t("Upload file", { note: "button" }));
590
+ const buttonContent = children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
591
+ /* @__PURE__ */ jsx(CloudUpload, { "data-icon": "inline-start" }),
592
+ buttonLabel
593
+ ] });
594
+ const button = /* @__PURE__ */ jsx(
595
+ Button,
596
+ {
597
+ variant,
598
+ size,
599
+ className: buttonClassName,
600
+ disabled: isDisabled,
601
+ onClick: openFilePicker,
602
+ children: buttonContent
603
+ }
604
+ );
605
+ return /* @__PURE__ */ jsxs("div", { className: cn("inline-flex flex-col gap-2", className), children: [
606
+ /* @__PURE__ */ jsxs("div", { className: "inline-flex items-center gap-2", children: [
607
+ /* @__PURE__ */ jsx("input", { ...inputProps }),
608
+ tooltipText ? /* @__PURE__ */ jsxs(Tooltip, { children: [
609
+ /* @__PURE__ */ jsx(TooltipTrigger, { render: button }),
610
+ /* @__PURE__ */ jsx(TooltipContent, { children: tooltipText })
611
+ ] }) : button
612
+ ] }),
613
+ status
614
+ ] });
615
+ }
616
+ var EMPTY_PROGRESS2 = { loaded: 0, total: 0, percent: 0 };
617
+ var EMPTY_FILES2 = [];
618
+ function UploadDropzone({
619
+ className,
620
+ label,
621
+ children,
622
+ disabled,
623
+ toast: enableToast = true,
624
+ showStatus = true,
625
+ multiple,
626
+ ...options
627
+ }) {
628
+ const t = useTranslations();
629
+ const isMulti = multiple === true || (options.maxFiles ?? 1) > 1;
630
+ const single = useUploadControls(options);
631
+ const multi = useMultiUploadControls(
632
+ options
633
+ );
634
+ const canPause = options.uploadStore != null && options.uploadStore !== false;
635
+ const ctrl = isMulti ? {
636
+ mode: "multi",
637
+ phase: multi.phase,
638
+ files: multi.files,
639
+ totalProgress: multi.totalProgress,
640
+ error: multi.error,
641
+ cancel: multi.cancel
642
+ } : {
643
+ mode: "single",
644
+ phase: single.phase,
645
+ fileInfo: single.fileInfo,
646
+ progress: single.progress,
647
+ error: single.error,
648
+ cancel: single.cancel
649
+ };
650
+ const [isDragOver, setIsDragOver] = useState(false);
651
+ const isDisabled = disabled || (isMulti ? multi.isUploading : single.isUploading);
652
+ const openFilePicker = isMulti ? multi.openFilePicker : single.openFilePicker;
653
+ const dropHandlers = isMulti ? multi.dropHandlers : single.dropHandlers;
654
+ const inputProps = isMulti ? multi.inputProps : single.inputProps;
655
+ useUploadToast(ctrl, enableToast);
656
+ const acceptLabels = formatAcceptLabels(options.accept);
657
+ const maxFiles = options.maxFiles;
658
+ const limitParts = [];
659
+ if (maxFiles != null && maxFiles > 0) {
660
+ limitParts.push(
661
+ maxFiles === 1 ? t("You can upload a file", { note: "dropzone hint" }) : t("You can upload {count} files", {
662
+ note: "dropzone hint",
663
+ variables: { count: String(maxFiles) }
664
+ })
665
+ );
666
+ }
667
+ if (options.maxFileSize != null) {
668
+ const size = formatFileSize(options.maxFileSize);
669
+ limitParts.push(
670
+ maxFiles != null && maxFiles > 1 ? t("Each up to {size}", {
671
+ note: "dropzone hint",
672
+ variables: { size }
673
+ }) : t("Up to {size}", {
674
+ note: "dropzone hint",
675
+ variables: { size }
676
+ })
677
+ );
678
+ }
679
+ const limitsLine = limitParts.length > 0 ? `${limitParts.join(". ")}.` : null;
680
+ const acceptLine = acceptLabels.length > 0 ? t("Accepted {types}.", {
681
+ note: "dropzone hint",
682
+ variables: { types: acceptLabels.join(", ") }
683
+ }) : null;
684
+ const hasCustomContent = children != null;
685
+ const dropzoneLabel = label ?? t("Drag and drop files here", { note: "dropzone" });
686
+ const status = showStatus ? isMulti ? /* @__PURE__ */ jsx(
687
+ UploadStatusBlock,
688
+ {
689
+ mode: "multi",
690
+ phase: multi.phase,
691
+ files: multi.files ?? EMPTY_FILES2,
692
+ totalProgress: multi.totalProgress ?? EMPTY_PROGRESS2,
693
+ error: multi.error,
694
+ onCancel: multi.cancel,
695
+ onPause: canPause ? multi.detach : void 0
696
+ }
697
+ ) : /* @__PURE__ */ jsx(
698
+ UploadStatusBlock,
699
+ {
700
+ mode: "single",
701
+ phase: single.phase,
702
+ progress: single.progress,
703
+ error: single.error,
704
+ fileInfo: single.fileInfo,
705
+ onCancel: single.cancel,
706
+ onPause: canPause ? single.detach : void 0
707
+ }
708
+ ) : null;
709
+ const onKeyDown = (e) => {
710
+ if (isDisabled) return;
711
+ if (e.key === "Enter" || e.key === " ") {
712
+ e.preventDefault();
713
+ openFilePicker();
714
+ }
715
+ };
716
+ return /* @__PURE__ */ jsxs(
717
+ "div",
718
+ {
719
+ role: "button",
720
+ tabIndex: isDisabled ? -1 : 0,
721
+ "aria-disabled": isDisabled || void 0,
722
+ "aria-label": dropzoneLabel,
723
+ className: cn(
724
+ "rounded-lg border-2 border-dashed transition-colors",
725
+ hasCustomContent ? "flex items-stretch justify-stretch p-0" : "flex flex-col items-center justify-center gap-3 p-6 text-center",
726
+ isDisabled ? "cursor-not-allowed border-muted-foreground/25" : "cursor-pointer border-muted-foreground/25 hover:border-primary/50",
727
+ !isDisabled && isDragOver && "border-primary/50",
728
+ className
729
+ ),
730
+ onClick: isDisabled ? void 0 : openFilePicker,
731
+ onKeyDown,
732
+ ...isDisabled ? {} : {
733
+ ...dropHandlers,
734
+ onDragEnter: (e) => {
735
+ if (e.dataTransfer.types.includes("Files")) setIsDragOver(true);
736
+ },
737
+ onDragLeave: (e) => {
738
+ if (!e.currentTarget.contains(e.relatedTarget)) {
739
+ setIsDragOver(false);
740
+ }
741
+ },
742
+ onDrop: (e) => {
743
+ setIsDragOver(false);
744
+ dropHandlers.onDrop(e);
745
+ }
746
+ },
747
+ children: [
748
+ /* @__PURE__ */ jsx("input", { ...inputProps }),
749
+ hasCustomContent ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
750
+ /* @__PURE__ */ jsx(
751
+ CloudUpload,
752
+ {
753
+ className: cn("size-6", isDisabled && "opacity-50"),
754
+ strokeWidth: 1.5
755
+ }
756
+ ),
757
+ /* @__PURE__ */ jsxs(
758
+ "div",
759
+ {
760
+ className: cn("flex flex-col gap-1", isDisabled && "opacity-50"),
761
+ children: [
762
+ /* @__PURE__ */ jsx("p", { className: "text-sm font-medium", children: dropzoneLabel }),
763
+ limitsLine && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: limitsLine }),
764
+ acceptLine && /* @__PURE__ */ jsx("p", { className: "text-xs text-muted-foreground", children: acceptLine })
765
+ ]
766
+ }
767
+ ),
768
+ status && /* @__PURE__ */ jsx("div", { className: "w-full text-start", children: status })
769
+ ] })
770
+ ]
771
+ }
772
+ );
773
+ }
774
+ function useDownloadToast({
775
+ enabled = true,
776
+ objectKey,
777
+ fileName,
778
+ fileSize
779
+ }) {
780
+ const t = useTranslations();
781
+ const formatDimahError = useFormatDimahError();
782
+ const displayName = fileName ?? objectKey.split("/").pop() ?? objectKey;
783
+ const errorNode = (error) => /* @__PURE__ */ jsx("span", { dir: "auto", className: "block [overflow-wrap:anywhere]", children: formatDimahError(error) });
784
+ const onInitiated = () => {
785
+ if (enabled) toast.success(t("Download started", { note: "toast" }));
786
+ };
787
+ const onSuccess = (_key, actualFileName) => {
788
+ if (!enabled) return;
789
+ toast.dismiss(`dl-${objectKey}`);
790
+ toast.success(t("Download complete", { note: "toast" }), {
791
+ description: /* @__PURE__ */ jsxs("span", { className: "block", children: [
792
+ /* @__PURE__ */ jsx("bdi", { children: truncateFileName(actualFileName) }),
793
+ fileSize != null ? /* @__PURE__ */ jsxs(Fragment, { children: [
794
+ " ",
795
+ "\xB7",
796
+ " ",
797
+ /* @__PURE__ */ jsx(
798
+ "span",
799
+ {
800
+ dir: "ltr",
801
+ className: "inline-block whitespace-nowrap tabular-nums",
802
+ children: formatFileSize(fileSize)
803
+ }
804
+ )
805
+ ] }) : null
806
+ ] })
807
+ });
808
+ };
809
+ const onError = (_key, error) => {
810
+ if (!enabled) return;
811
+ toast.dismiss(`dl-${objectKey}`);
812
+ toast.error(t("Download failed", { note: "toast" }), {
813
+ description: errorNode(error)
814
+ });
815
+ };
816
+ const onErrorWithPhase = (_key, error, _phase) => {
817
+ if (!enabled) return;
818
+ toast.dismiss(`dl-${objectKey}`);
819
+ toast.error(t("Download failed", { note: "toast" }), {
820
+ description: errorNode(error)
821
+ });
822
+ };
823
+ const onCancel = (_key) => {
824
+ if (!enabled) return;
825
+ toast.dismiss(`dl-${objectKey}`);
826
+ toast.info(t("Download cancelled", { note: "toast" }), {
827
+ description: /* @__PURE__ */ jsx("span", { dir: "auto", children: truncateFileName(displayName) })
828
+ });
829
+ };
830
+ return { onInitiated, onSuccess, onError, onErrorWithPhase, onCancel };
831
+ }
832
+ function DownloadButton({
833
+ api,
834
+ objectKey,
835
+ fileName,
836
+ label,
837
+ children,
838
+ className,
839
+ disabled,
840
+ toast: enableToast = true,
841
+ showStatus = true,
842
+ variant = "outline",
843
+ size = "default",
844
+ buttonClassName
845
+ }) {
846
+ const t = useTranslations();
847
+ const toastHandlers = useDownloadToast({
848
+ enabled: enableToast,
849
+ objectKey,
850
+ fileName
851
+ });
852
+ const dl = useDownload({
853
+ api,
854
+ onInitiated: () => {
855
+ toastHandlers.onInitiated();
856
+ },
857
+ onError: (key, error) => {
858
+ toastHandlers.onError(key, error);
859
+ }
860
+ });
861
+ const isPending = dl.phase === "presigning";
862
+ const buttonContent = children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
863
+ isPending ? /* @__PURE__ */ jsx(LoaderIcon, { className: "animate-spin", "data-icon": "inline-start" }) : /* @__PURE__ */ jsx(DownloadIcon, { "data-icon": "inline-start" }),
864
+ label ?? t("Download", { note: "button" })
865
+ ] });
866
+ return /* @__PURE__ */ jsxs("div", { className: cn("inline-flex flex-col gap-1.5", className), children: [
867
+ /* @__PURE__ */ jsx(
868
+ Button,
869
+ {
870
+ variant,
871
+ size,
872
+ className: buttonClassName,
873
+ disabled: disabled || isPending,
874
+ onClick: () => dl.download(objectKey, fileName),
875
+ children: buttonContent
876
+ }
877
+ ),
878
+ showStatus && dl.phase === "error" && /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-start gap-1.5 text-xs", children: [
879
+ /* @__PURE__ */ jsx(AlertCircleIcon, { className: "mt-0.5 size-3.5 shrink-0 text-destructive" }),
880
+ /* @__PURE__ */ jsx("p", { className: "min-w-0 [overflow-wrap:anywhere] text-destructive", children: dl.error ?? t("Download failed", { note: "status" }) })
881
+ ] })
882
+ ] });
883
+ }
884
+ function ProgressDownloadButton({
885
+ api,
886
+ objectKey,
887
+ fileName,
888
+ fileSize,
889
+ bucket,
890
+ label,
891
+ children,
892
+ className,
893
+ fillClassName,
894
+ disabled,
895
+ tooltipText,
896
+ cancelTooltipText,
897
+ toast: enableToast = true,
898
+ showStatus = true,
899
+ variant = "outline",
900
+ size = "default",
901
+ buttonClassName,
902
+ beforeDownload,
903
+ onDownloadStart,
904
+ onProgress,
905
+ onSuccess,
906
+ onError,
907
+ onCancel
908
+ }) {
909
+ const t = useTranslations();
910
+ const toastHandlers = useDownloadToast({
911
+ enabled: enableToast,
912
+ objectKey,
913
+ fileName,
914
+ fileSize
915
+ });
916
+ const dl = useFetchDownload({
917
+ api,
918
+ bucket,
919
+ beforeDownload,
920
+ onDownloadStart,
921
+ onProgress,
922
+ onSuccess: (key, actualFileName) => {
923
+ toastHandlers.onSuccess(key, actualFileName);
924
+ onSuccess?.(key, actualFileName);
925
+ },
926
+ onError: (key, error, phase) => {
927
+ toastHandlers.onErrorWithPhase(key, error, phase);
928
+ onError?.(key, error, phase);
929
+ },
930
+ onCancel: (key) => {
931
+ toastHandlers.onCancel(key);
932
+ onCancel?.(key);
933
+ }
934
+ });
935
+ const isDownloading = dl.phase === "downloading" || dl.phase === "presigning";
936
+ const handleClick = () => {
937
+ if (isDownloading) {
938
+ dl.cancel();
939
+ return;
940
+ }
941
+ dl.download(objectKey, fileName);
942
+ };
943
+ const computedPercentFromFileSize = fileSize && fileSize > 0 ? Math.min(100, Math.round(dl.progress.loaded / fileSize * 100)) : null;
944
+ const fillPercent = dl.phase === "presigning" ? 12 : dl.progress.total > 0 ? dl.progress.percent : computedPercentFromFileSize;
945
+ const isIndeterminateFill = isDownloading && fillPercent == null && dl.phase === "downloading";
946
+ const buttonContent = children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
947
+ !isDownloading && /* @__PURE__ */ jsx(DownloadIcon, { "data-icon": "inline-start" }),
948
+ isDownloading ? formatFileSize(dl.progress.loaded) : label ?? t("Download", { note: "button" })
949
+ ] });
950
+ return /* @__PURE__ */ jsxs("div", { className: cn("inline-flex flex-col items-center gap-1.5", className), children: [
951
+ /* @__PURE__ */ jsxs(Tooltip, { children: [
952
+ /* @__PURE__ */ jsxs(
953
+ TooltipTrigger,
954
+ {
955
+ render: /* @__PURE__ */ jsx(
956
+ Button,
957
+ {
958
+ variant,
959
+ size,
960
+ disabled,
961
+ className: cn(
962
+ "relative min-w-24 overflow-hidden",
963
+ buttonClassName
964
+ ),
965
+ onClick: handleClick
966
+ }
967
+ ),
968
+ children: [
969
+ isDownloading && /* @__PURE__ */ jsx(
970
+ "span",
971
+ {
972
+ className: cn(
973
+ "absolute inset-y-0 start-0 bg-primary/15",
974
+ fillPercent != null ? "transition-[width] duration-200" : "w-full animate-pulse",
975
+ fillClassName
976
+ ),
977
+ style: fillPercent != null ? { width: `${fillPercent}%` } : void 0,
978
+ "aria-hidden": isIndeterminateFill
979
+ }
980
+ ),
981
+ /* @__PURE__ */ jsx("span", { className: "relative z-10 flex w-full items-center justify-center gap-1", children: buttonContent })
982
+ ]
983
+ }
984
+ ),
985
+ /* @__PURE__ */ jsx(TooltipContent, { children: isDownloading ? cancelTooltipText ?? t("Cancel download", { note: "tooltip" }) : tooltipText ?? t("Download file", { note: "tooltip" }) })
986
+ ] }),
987
+ showStatus && dl.phase === "error" && /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-start gap-1.5 text-xs", children: [
988
+ /* @__PURE__ */ jsx(AlertCircleIcon, { className: "mt-0.5 size-3.5 shrink-0 text-destructive" }),
989
+ /* @__PURE__ */ jsx("p", { className: "min-w-0 [overflow-wrap:anywhere] text-destructive", children: dl.error ?? t("Download failed", { note: "status" }) })
990
+ ] })
991
+ ] });
992
+ }
993
+ function AlertDialog({ ...props }) {
994
+ return /* @__PURE__ */ jsx(AlertDialog$1.Root, { "data-slot": "alert-dialog", ...props });
995
+ }
996
+ function AlertDialogTrigger({ ...props }) {
997
+ return /* @__PURE__ */ jsx(AlertDialog$1.Trigger, { "data-slot": "alert-dialog-trigger", ...props });
998
+ }
999
+ function AlertDialogPortal({ ...props }) {
1000
+ return /* @__PURE__ */ jsx(AlertDialog$1.Portal, { "data-slot": "alert-dialog-portal", ...props });
1001
+ }
1002
+ function AlertDialogOverlay({
1003
+ className,
1004
+ ...props
1005
+ }) {
1006
+ return /* @__PURE__ */ jsx(
1007
+ AlertDialog$1.Backdrop,
1008
+ {
1009
+ "data-slot": "alert-dialog-overlay",
1010
+ className: cn(
1011
+ "fixed inset-0 isolate z-50 bg-black/80 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
1012
+ className
1013
+ ),
1014
+ ...props
1015
+ }
1016
+ );
1017
+ }
1018
+ function AlertDialogContent({
1019
+ className,
1020
+ size = "default",
1021
+ ...props
1022
+ }) {
1023
+ return /* @__PURE__ */ jsxs(AlertDialogPortal, { children: [
1024
+ /* @__PURE__ */ jsx(AlertDialogOverlay, {}),
1025
+ /* @__PURE__ */ jsx(
1026
+ AlertDialog$1.Popup,
1027
+ {
1028
+ "data-slot": "alert-dialog-content",
1029
+ "data-size": size,
1030
+ className: cn(
1031
+ "group/alert-dialog-content fixed top-1/2 start-1/2 z-50 grid w-full -translate-x-1/2 rtl:translate-x-1/2 -translate-y-1/2 gap-3 rounded-xl bg-popover p-4 text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-64 data-[size=default]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
1032
+ className
1033
+ ),
1034
+ ...props
1035
+ }
1036
+ )
1037
+ ] });
1038
+ }
1039
+ function AlertDialogHeader({
1040
+ className,
1041
+ ...props
1042
+ }) {
1043
+ return /* @__PURE__ */ jsx(
1044
+ "div",
1045
+ {
1046
+ "data-slot": "alert-dialog-header",
1047
+ className: cn(
1048
+ "grid grid-rows-[auto_1fr] place-items-center gap-1 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-start sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]",
1049
+ className
1050
+ ),
1051
+ ...props
1052
+ }
1053
+ );
1054
+ }
1055
+ function AlertDialogFooter({
1056
+ className,
1057
+ ...props
1058
+ }) {
1059
+ return /* @__PURE__ */ jsx(
1060
+ "div",
1061
+ {
1062
+ "data-slot": "alert-dialog-footer",
1063
+ className: cn(
1064
+ "flex flex-col-reverse gap-2 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end",
1065
+ className
1066
+ ),
1067
+ ...props
1068
+ }
1069
+ );
1070
+ }
1071
+ function AlertDialogMedia({
1072
+ className,
1073
+ ...props
1074
+ }) {
1075
+ return /* @__PURE__ */ jsx(
1076
+ "div",
1077
+ {
1078
+ "data-slot": "alert-dialog-media",
1079
+ className: cn(
1080
+ "mb-2 inline-flex size-8 items-center justify-center rounded-md bg-muted sm:group-data-[size=default]/alert-dialog-content:row-span-2 *:[svg:not([class*='size-'])]:size-4",
1081
+ className
1082
+ ),
1083
+ ...props
1084
+ }
1085
+ );
1086
+ }
1087
+ function AlertDialogTitle({
1088
+ className,
1089
+ ...props
1090
+ }) {
1091
+ return /* @__PURE__ */ jsx(
1092
+ AlertDialog$1.Title,
1093
+ {
1094
+ "data-slot": "alert-dialog-title",
1095
+ className: cn(
1096
+ "font-heading text-sm font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2",
1097
+ className
1098
+ ),
1099
+ ...props
1100
+ }
1101
+ );
1102
+ }
1103
+ function AlertDialogDescription({
1104
+ className,
1105
+ ...props
1106
+ }) {
1107
+ return /* @__PURE__ */ jsx(
1108
+ AlertDialog$1.Description,
1109
+ {
1110
+ "data-slot": "alert-dialog-description",
1111
+ className: cn(
1112
+ "text-xs/relaxed text-balance text-muted-foreground md:text-pretty *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
1113
+ className
1114
+ ),
1115
+ ...props
1116
+ }
1117
+ );
1118
+ }
1119
+ function AlertDialogAction({
1120
+ className,
1121
+ ...props
1122
+ }) {
1123
+ return /* @__PURE__ */ jsx(
1124
+ Button,
1125
+ {
1126
+ "data-slot": "alert-dialog-action",
1127
+ className: cn(className),
1128
+ ...props
1129
+ }
1130
+ );
1131
+ }
1132
+ function AlertDialogCancel({
1133
+ className,
1134
+ variant = "outline",
1135
+ size = "default",
1136
+ ...props
1137
+ }) {
1138
+ return /* @__PURE__ */ jsx(
1139
+ AlertDialog$1.Close,
1140
+ {
1141
+ "data-slot": "alert-dialog-cancel",
1142
+ className: cn(className),
1143
+ render: /* @__PURE__ */ jsx(Button, { variant, size }),
1144
+ ...props
1145
+ }
1146
+ );
1147
+ }
1148
+ function useDeleteToast({
1149
+ enabled = true,
1150
+ displayName
1151
+ }) {
1152
+ const t = useTranslations();
1153
+ const formatDimahError = useFormatDimahError();
1154
+ const onSuccess = (_key) => {
1155
+ if (!enabled) return;
1156
+ toast.success(t("File deleted", { note: "toast" }), {
1157
+ description: /* @__PURE__ */ jsx("span", { dir: "auto", children: truncateFileName(displayName) })
1158
+ });
1159
+ };
1160
+ const onError = (_key, error) => {
1161
+ if (!enabled) return;
1162
+ toast.error(t("Delete failed", { note: "toast" }), {
1163
+ description: /* @__PURE__ */ jsx("span", { dir: "auto", className: "block [overflow-wrap:anywhere]", children: formatDimahError(error) })
1164
+ });
1165
+ };
1166
+ return { onSuccess, onError };
1167
+ }
1168
+ function isolateLtr(value) {
1169
+ return `\u2066${value}\u2069`;
1170
+ }
1171
+ function DeleteButton({
1172
+ api,
1173
+ objectKey,
1174
+ fileName,
1175
+ fileSize,
1176
+ bucket,
1177
+ label,
1178
+ children,
1179
+ className,
1180
+ disabled,
1181
+ tooltipText,
1182
+ toast: enableToast = true,
1183
+ showStatus = true,
1184
+ confirmTitle,
1185
+ confirmDescription,
1186
+ variant = "destructive",
1187
+ size = "default",
1188
+ buttonClassName,
1189
+ beforeDelete,
1190
+ onDeleteStart,
1191
+ onSuccess,
1192
+ onError
1193
+ }) {
1194
+ const t = useTranslations();
1195
+ const displayName = fileName ?? objectKey.split("/").pop() ?? objectKey;
1196
+ const toastHandlers = useDeleteToast({
1197
+ enabled: enableToast,
1198
+ displayName
1199
+ });
1200
+ const del = useDelete({
1201
+ api,
1202
+ bucket,
1203
+ beforeDelete,
1204
+ onDeleteStart,
1205
+ onSuccess: (key) => {
1206
+ toastHandlers.onSuccess(key);
1207
+ onSuccess?.(key);
1208
+ },
1209
+ onError: (key, error, phase) => {
1210
+ toastHandlers.onError(key, error);
1211
+ onError?.(key, error, phase);
1212
+ }
1213
+ });
1214
+ const isDeleting = del.phase === "deleting";
1215
+ const isDisabled = disabled || isDeleting;
1216
+ const buttonContent = children ?? /* @__PURE__ */ jsxs(Fragment, { children: [
1217
+ isDeleting ? /* @__PURE__ */ jsx(LoaderIcon, { className: "animate-spin", "data-icon": "inline-start" }) : /* @__PURE__ */ jsx(Trash2Icon, { "data-icon": "inline-start" }),
1218
+ label ?? t("Delete", { note: "button" })
1219
+ ] });
1220
+ const fileLabel = fileSize != null ? `${truncateFileName(displayName)} (${formatFileSize(fileSize)})` : truncateFileName(displayName);
1221
+ const description = confirmDescription ?? t(
1222
+ 'Are you sure you want to delete "{name}"? This action cannot be undone.',
1223
+ {
1224
+ note: "dialog description",
1225
+ variables: { name: isolateLtr(fileLabel) }
1226
+ }
1227
+ );
1228
+ return /* @__PURE__ */ jsxs("div", { className: cn("inline-flex flex-col gap-1.5", className), children: [
1229
+ /* @__PURE__ */ jsx("div", { className: "inline-flex items-center gap-2", children: /* @__PURE__ */ jsxs(
1230
+ AlertDialog,
1231
+ {
1232
+ open: del.phase === "confirming",
1233
+ onOpenChange: (open) => {
1234
+ if (!open) del.cancelDelete();
1235
+ },
1236
+ children: [
1237
+ /* @__PURE__ */ jsxs(Tooltip, { children: [
1238
+ /* @__PURE__ */ jsx(
1239
+ TooltipTrigger,
1240
+ {
1241
+ render: /* @__PURE__ */ jsx(
1242
+ AlertDialogTrigger,
1243
+ {
1244
+ disabled: isDisabled,
1245
+ onClick: () => del.requestDelete(objectKey),
1246
+ render: /* @__PURE__ */ jsx(
1247
+ Button,
1248
+ {
1249
+ variant,
1250
+ size,
1251
+ className: buttonClassName,
1252
+ disabled: isDisabled
1253
+ }
1254
+ )
1255
+ }
1256
+ ),
1257
+ children: buttonContent
1258
+ }
1259
+ ),
1260
+ /* @__PURE__ */ jsx(TooltipContent, { children: tooltipText ?? t("Delete file", { note: "tooltip" }) })
1261
+ ] }),
1262
+ /* @__PURE__ */ jsxs(AlertDialogContent, { children: [
1263
+ /* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
1264
+ /* @__PURE__ */ jsx(AlertDialogMedia, { children: /* @__PURE__ */ jsx(Trash2Icon, {}) }),
1265
+ /* @__PURE__ */ jsx(AlertDialogTitle, { children: confirmTitle ?? t("Delete file?", { note: "dialog title" }) }),
1266
+ /* @__PURE__ */ jsx(
1267
+ AlertDialogDescription,
1268
+ {
1269
+ dir: "auto",
1270
+ className: "[overflow-wrap:anywhere]",
1271
+ children: description
1272
+ }
1273
+ )
1274
+ ] }),
1275
+ /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
1276
+ /* @__PURE__ */ jsx(AlertDialogCancel, { children: t("Cancel", { note: "dialog button" }) }),
1277
+ /* @__PURE__ */ jsx(
1278
+ AlertDialogAction,
1279
+ {
1280
+ variant: "destructive",
1281
+ onClick: () => del.confirmDelete(),
1282
+ children: t("Delete", { note: "dialog confirm" })
1283
+ }
1284
+ )
1285
+ ] })
1286
+ ] })
1287
+ ]
1288
+ }
1289
+ ) }),
1290
+ showStatus && del.phase === "success" && /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-1.5 text-xs", children: [
1291
+ /* @__PURE__ */ jsx(CheckCircle2Icon, { className: "size-3.5 shrink-0 text-green-600" }),
1292
+ /* @__PURE__ */ jsx("p", { className: "min-w-0 [overflow-wrap:anywhere] text-green-600", children: t('"{name}" deleted', {
1293
+ note: "status",
1294
+ variables: { name: truncateFileName(displayName) }
1295
+ }) })
1296
+ ] }),
1297
+ showStatus && del.phase === "error" && /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-start gap-1.5 text-xs", children: [
1298
+ /* @__PURE__ */ jsx(AlertCircleIcon, { className: "mt-0.5 size-3.5 shrink-0 text-destructive" }),
1299
+ /* @__PURE__ */ jsx("p", { className: "min-w-0 [overflow-wrap:anywhere] text-destructive", children: del.error ?? t("Delete failed", { note: "status" }) })
1300
+ ] })
1301
+ ] });
1302
+ }
1303
+
1304
+ export { DeleteButton, DownloadButton, MultiUploadStatus, ProgressDownloadButton, UploadButton, UploadDropzone, UploadStatus, UploadStatusBlock };
1305
+ //# sourceMappingURL=index.js.map
1306
+ //# sourceMappingURL=index.js.map