@dimah-s3/ui 1.5.11 → 1.7.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.
- package/dist/components/dimah-s3/attachment/file-attachment.d.ts.map +1 -1
- package/dist/components/dimah-s3/delete/delete-button.d.ts +1 -1
- package/dist/components/dimah-s3/delete/delete-button.d.ts.map +1 -1
- package/dist/components/dimah-s3/download/progress-download-button.d.ts +1 -1
- package/dist/components/dimah-s3/download/progress-download-button.d.ts.map +1 -1
- package/dist/components/dimah-s3/list/object-list-breadcrumb.d.ts +7 -0
- package/dist/components/dimah-s3/list/object-list-breadcrumb.d.ts.map +1 -0
- package/dist/components/dimah-s3/list/object-list-menu.d.ts +65 -0
- package/dist/components/dimah-s3/list/object-list-menu.d.ts.map +1 -0
- package/dist/components/dimah-s3/list/object-list-rows.d.ts +32 -0
- package/dist/components/dimah-s3/list/object-list-rows.d.ts.map +1 -0
- package/dist/components/dimah-s3/list/object-list-selection-state.d.ts +38 -0
- package/dist/components/dimah-s3/list/object-list-selection-state.d.ts.map +1 -0
- package/dist/components/dimah-s3/list/object-list-selection.d.ts +36 -0
- package/dist/components/dimah-s3/list/object-list-selection.d.ts.map +1 -0
- package/dist/components/dimah-s3/list/object-list-states.d.ts +24 -0
- package/dist/components/dimah-s3/list/object-list-states.d.ts.map +1 -0
- package/dist/components/dimah-s3/list/object-list-upload.d.ts +14 -0
- package/dist/components/dimah-s3/list/object-list-upload.d.ts.map +1 -0
- package/dist/components/dimah-s3/list/object-list-usage.d.ts +7 -0
- package/dist/components/dimah-s3/list/object-list-usage.d.ts.map +1 -0
- package/dist/components/dimah-s3/list/object-list.d.ts +169 -0
- package/dist/components/dimah-s3/list/object-list.d.ts.map +1 -0
- package/dist/components/dimah-s3/upload/multi-upload-status.d.ts.map +1 -1
- package/dist/components/dimah-s3/upload/upload-dropzone.d.ts.map +1 -1
- package/dist/components/dimah-s3/upload/upload-status.d.ts.map +1 -1
- package/dist/components/ui/breadcrumb.d.ts +11 -0
- package/dist/components/ui/breadcrumb.d.ts.map +1 -0
- package/dist/components/ui/checkbox.d.ts +4 -0
- package/dist/components/ui/checkbox.d.ts.map +1 -0
- package/dist/components/ui/dropdown-menu.d.ts +30 -0
- package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
- package/dist/components/ui/empty.d.ts +13 -0
- package/dist/components/ui/empty.d.ts.map +1 -0
- package/dist/components/ui/item.d.ts +23 -0
- package/dist/components/ui/item.d.ts.map +1 -0
- package/dist/components/ui/separator.d.ts +4 -0
- package/dist/components/ui/separator.d.ts.map +1 -0
- package/dist/components/ui/skeleton.d.ts +4 -0
- package/dist/components/ui/skeleton.d.ts.map +1 -0
- package/dist/components/ui/spinner.d.ts +5 -0
- package/dist/components/ui/spinner.d.ts.map +1 -0
- package/dist/hooks/use-delete-ui.d.ts.map +1 -1
- package/dist/hooks/use-download-toast.d.ts.map +1 -1
- package/dist/hooks/use-file-reject-toast.d.ts +1 -1
- package/dist/hooks/use-file-reject-toast.d.ts.map +1 -1
- package/dist/hooks/use-upload-toast.d.ts.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1953 -88
- package/dist/index.js.map +1 -1
- package/dist/lib/file-type-icon.d.ts +14 -1
- package/dist/lib/file-type-icon.d.ts.map +1 -1
- package/dist/lib/format-expires-in.d.ts +3 -0
- package/dist/lib/format-expires-in.d.ts.map +1 -0
- package/dist/lib/isolate-text.d.ts +7 -0
- package/dist/lib/isolate-text.d.ts.map +1 -0
- package/package.json +10 -10
package/dist/index.js
CHANGED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { AlertCircleIcon, PauseIcon, XIcon, CloudUpload, LoaderIcon, DownloadIcon, Trash2Icon, CheckCircleIcon, LoaderCircleIcon, CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon
|
|
2
|
+
import { AlertCircleIcon, PauseIcon, XIcon, CloudUpload, LoaderIcon, DownloadIcon, Trash2Icon, MoreHorizontalIcon, LinkIcon, CheckCircleIcon, LoaderCircleIcon, Loader2Icon, CheckIcon, MinusIcon, ChevronRightIcon, CircleCheckIcon, InfoIcon, TriangleAlertIcon, OctagonXIcon } from 'lucide-react';
|
|
3
3
|
import { useTranslations } from '@fuma-translate/react';
|
|
4
4
|
import { cn } from 'cn';
|
|
5
5
|
import { Button as Button$1 } from '@base-ui/react/button';
|
|
6
6
|
import { cva } from 'class-variance-authority';
|
|
7
7
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
8
8
|
import { Tooltip as Tooltip$1 } from '@base-ui/react/tooltip';
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import '@base-ui/react/merge-props';
|
|
12
|
-
import '@base-ui/react/use-render';
|
|
9
|
+
import { useFormatDimahError, useFormatFileSize, useFormatNumber, formatEta, isFetchDownload, formatAcceptLabels } from '@dimah-s3/react';
|
|
10
|
+
import { truncateFileName, fileNameFromKey, DELETE_BATCH_MAX_KEYS } from '@dimah-s3/core';
|
|
11
|
+
import { mergeProps } from '@base-ui/react/merge-props';
|
|
12
|
+
import { useRender } from '@base-ui/react/use-render';
|
|
13
13
|
import { FileIcon, defaultStyles } from 'react-file-icon';
|
|
14
14
|
import { Progress as Progress$1 } from '@base-ui/react/progress';
|
|
15
|
-
import { useRef, useLayoutEffect, useEffect } from 'react';
|
|
15
|
+
import { useRef, useLayoutEffect, useEffect, useMemo, useState, Fragment as Fragment$1 } from 'react';
|
|
16
16
|
import { Toast as Toast$1 } from '@base-ui/react/toast';
|
|
17
17
|
import { AlertDialog as AlertDialog$1 } from '@base-ui/react/alert-dialog';
|
|
18
|
+
import { Menu } from '@base-ui/react/menu';
|
|
19
|
+
import { Checkbox as Checkbox$1 } from '@base-ui/react/checkbox';
|
|
18
20
|
|
|
19
21
|
// src/components/dimah-s3/upload/upload-button.tsx
|
|
20
22
|
var buttonVariants = cva(
|
|
@@ -473,6 +475,7 @@ function stylesFor(ext) {
|
|
|
473
475
|
function FileTypeGlyph({
|
|
474
476
|
fileName,
|
|
475
477
|
fileType,
|
|
478
|
+
layout = "fill",
|
|
476
479
|
className
|
|
477
480
|
}) {
|
|
478
481
|
const ext = resolveFileTypeExtension(fileName, fileType);
|
|
@@ -482,9 +485,8 @@ function FileTypeGlyph({
|
|
|
482
485
|
"span",
|
|
483
486
|
{
|
|
484
487
|
className: cn(
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
"flex size-full items-center justify-center [&_svg]:size-[min(76%,8rem)]!",
|
|
488
|
+
"flex shrink-0 items-center justify-center",
|
|
489
|
+
layout === "fill" ? "size-full [&_svg]:size-[min(76%,8rem)]!" : "size-8 [&_svg]:size-7!",
|
|
488
490
|
className
|
|
489
491
|
),
|
|
490
492
|
"aria-hidden": true,
|
|
@@ -492,6 +494,32 @@ function FileTypeGlyph({
|
|
|
492
494
|
}
|
|
493
495
|
);
|
|
494
496
|
}
|
|
497
|
+
function FolderGlyph({ className }) {
|
|
498
|
+
return /* @__PURE__ */ jsxs(
|
|
499
|
+
"svg",
|
|
500
|
+
{
|
|
501
|
+
viewBox: "0 0 32 32",
|
|
502
|
+
className: cn("size-8 shrink-0", className),
|
|
503
|
+
"aria-hidden": true,
|
|
504
|
+
children: [
|
|
505
|
+
/* @__PURE__ */ jsx(
|
|
506
|
+
"path",
|
|
507
|
+
{
|
|
508
|
+
fill: "#E2AE1A",
|
|
509
|
+
d: "M4 9.2A2.2 2.2 0 0 1 6.2 7h5.1c.5 0 .9.2 1.2.5l1.3 1.4c.2.2.4.3.7.3h9.3A2.2 2.2 0 0 1 26 11.4V13H4V9.2Z"
|
|
510
|
+
}
|
|
511
|
+
),
|
|
512
|
+
/* @__PURE__ */ jsx(
|
|
513
|
+
"path",
|
|
514
|
+
{
|
|
515
|
+
fill: "#F6C445",
|
|
516
|
+
d: "M4 12.2h24v11.3A2.5 2.5 0 0 1 25.5 26h-19A2.5 2.5 0 0 1 4 23.5V12.2Z"
|
|
517
|
+
}
|
|
518
|
+
)
|
|
519
|
+
]
|
|
520
|
+
}
|
|
521
|
+
);
|
|
522
|
+
}
|
|
495
523
|
var PROGRESS_BY_SIZE = {
|
|
496
524
|
default: { size: 20, strokeWidth: 2.5, className: "size-5" },
|
|
497
525
|
sm: { size: 16, strokeWidth: 2, className: "size-4" },
|
|
@@ -515,6 +543,8 @@ function FileAttachment({
|
|
|
515
543
|
}) {
|
|
516
544
|
const t = useTranslations();
|
|
517
545
|
const formatError = useFormatDimahError();
|
|
546
|
+
const formatFileSize = useFormatFileSize();
|
|
547
|
+
const formatNumber = useFormatNumber();
|
|
518
548
|
const errorText = error == null ? null : typeof error === "string" ? error : formatError(error);
|
|
519
549
|
const progress = PROGRESS_BY_SIZE[size];
|
|
520
550
|
const resolvedDescription = description ?? (state === "error" ? errorText ?? t("Upload failed", { note: "status" }) : fileSize != null ? formatFileSize(fileSize) : null);
|
|
@@ -531,7 +561,7 @@ function FileAttachment({
|
|
|
531
561
|
className: progress.className,
|
|
532
562
|
label: state === "uploading" ? t("{percent}%", {
|
|
533
563
|
note: "progress",
|
|
534
|
-
variables: { percent:
|
|
564
|
+
variables: { percent: formatNumber(Math.round(percent)) }
|
|
535
565
|
}) : void 0
|
|
536
566
|
}
|
|
537
567
|
) }) : state === "error" ? /* @__PURE__ */ jsx("div", { className: "absolute inset-0 flex items-center justify-center bg-dimah-s3-destructive/20 text-dimah-s3-destructive", children: /* @__PURE__ */ jsx(AlertCircleIcon, {}) }) : null;
|
|
@@ -711,6 +741,7 @@ function MultiUploadStatus({
|
|
|
711
741
|
}) {
|
|
712
742
|
const t = useTranslations();
|
|
713
743
|
const formatError = useFormatDimahError();
|
|
744
|
+
const formatNumber = useFormatNumber();
|
|
714
745
|
const { phase, files, progress, error } = upload;
|
|
715
746
|
const onCancel = upload.cancel;
|
|
716
747
|
const onPause = upload.resumable ? upload.detach : void 0;
|
|
@@ -729,10 +760,10 @@ function MultiUploadStatus({
|
|
|
729
760
|
t("{done}/{total} files", {
|
|
730
761
|
note: "upload progress",
|
|
731
762
|
variables: {
|
|
732
|
-
done:
|
|
763
|
+
done: formatNumber(
|
|
733
764
|
files.filter((f) => f.status === "success").length
|
|
734
765
|
),
|
|
735
|
-
total:
|
|
766
|
+
total: formatNumber(files.length)
|
|
736
767
|
}
|
|
737
768
|
}),
|
|
738
769
|
eta ? /* @__PURE__ */ jsxs("span", { className: "font-normal text-dimah-s3-muted-foreground", children: [
|
|
@@ -779,7 +810,7 @@ function MultiUploadStatus({
|
|
|
779
810
|
state: "done",
|
|
780
811
|
title: t("All {count} file(s) uploaded", {
|
|
781
812
|
note: "status",
|
|
782
|
-
variables: { count:
|
|
813
|
+
variables: { count: formatNumber(files.length) }
|
|
783
814
|
}),
|
|
784
815
|
onDismiss: upload.reset,
|
|
785
816
|
...layout
|
|
@@ -866,6 +897,7 @@ function UploadFileStatus({
|
|
|
866
897
|
}) {
|
|
867
898
|
const t = useTranslations();
|
|
868
899
|
const formatError = useFormatDimahError();
|
|
900
|
+
const formatFileSize = useFormatFileSize();
|
|
869
901
|
const errorText = error ? formatError(error) : null;
|
|
870
902
|
const layout = { size, orientation, className };
|
|
871
903
|
const progress = file?.progress;
|
|
@@ -1165,19 +1197,14 @@ function Toaster({
|
|
|
1165
1197
|
}
|
|
1166
1198
|
Toast$1.createToastManager;
|
|
1167
1199
|
Toast$1.useToastManager;
|
|
1168
|
-
function
|
|
1169
|
-
return /* @__PURE__ */ jsx("
|
|
1170
|
-
}
|
|
1171
|
-
function progressNode(loaded, total) {
|
|
1172
|
-
return /* @__PURE__ */ jsxs("span", { dir: "ltr", className: "inline-block whitespace-nowrap tabular-nums", children: [
|
|
1173
|
-
formatFileSize(loaded),
|
|
1174
|
-
" / ",
|
|
1175
|
-
formatFileSize(total)
|
|
1176
|
-
] });
|
|
1200
|
+
function numbersNode(text) {
|
|
1201
|
+
return /* @__PURE__ */ jsx("bdi", { className: "inline-block whitespace-nowrap tabular-nums", children: text });
|
|
1177
1202
|
}
|
|
1178
1203
|
function useUploadToast(upload, enabled) {
|
|
1179
1204
|
const t = useTranslations();
|
|
1180
1205
|
const formatError = useFormatDimahError();
|
|
1206
|
+
const formatFileSize = useFormatFileSize();
|
|
1207
|
+
const formatNumber = useFormatNumber();
|
|
1181
1208
|
const toastIdRef = useRef(null);
|
|
1182
1209
|
const prevPhaseRef = useRef(upload.phase);
|
|
1183
1210
|
const cancelRef = useRef(upload.cancel);
|
|
@@ -1202,15 +1229,15 @@ function useUploadToast(upload, enabled) {
|
|
|
1202
1229
|
type: "success",
|
|
1203
1230
|
title: t("{count} file(s) uploaded", {
|
|
1204
1231
|
note: "toast",
|
|
1205
|
-
variables: { count:
|
|
1232
|
+
variables: { count: formatNumber(files.length) }
|
|
1206
1233
|
}),
|
|
1207
|
-
description:
|
|
1234
|
+
description: numbersNode(formatFileSize(total))
|
|
1208
1235
|
});
|
|
1209
1236
|
} else if (file) {
|
|
1210
1237
|
toast.add({
|
|
1211
1238
|
type: "success",
|
|
1212
1239
|
title: t("Upload complete", { note: "toast" }),
|
|
1213
|
-
description:
|
|
1240
|
+
description: numbersNode(formatFileSize(file.size))
|
|
1214
1241
|
});
|
|
1215
1242
|
}
|
|
1216
1243
|
toastIdRef.current = null;
|
|
@@ -1223,31 +1250,35 @@ function useUploadToast(upload, enabled) {
|
|
|
1223
1250
|
toast.add({
|
|
1224
1251
|
type: "error",
|
|
1225
1252
|
title: t("Upload finished with errors", { note: "toast" }),
|
|
1226
|
-
description: /* @__PURE__ */ jsx(
|
|
1227
|
-
"
|
|
1228
|
-
{
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
children: t("{succeeded} succeeded, {failed} failed", {
|
|
1232
|
-
note: "toast",
|
|
1233
|
-
variables: {
|
|
1234
|
-
succeeded: String(succeeded),
|
|
1235
|
-
failed: String(failed)
|
|
1236
|
-
}
|
|
1237
|
-
})
|
|
1253
|
+
description: /* @__PURE__ */ jsx("span", { className: "tabular-nums", children: t("{succeeded} succeeded, {failed} failed", {
|
|
1254
|
+
note: "toast",
|
|
1255
|
+
variables: {
|
|
1256
|
+
succeeded: formatNumber(succeeded),
|
|
1257
|
+
failed: formatNumber(failed)
|
|
1238
1258
|
}
|
|
1239
|
-
)
|
|
1259
|
+
}) })
|
|
1240
1260
|
});
|
|
1241
1261
|
} else {
|
|
1242
1262
|
toast.add({
|
|
1243
1263
|
type: "error",
|
|
1244
1264
|
title: t("Upload failed", { note: "toast" }),
|
|
1245
|
-
description: /* @__PURE__ */ jsx("span", {
|
|
1265
|
+
description: /* @__PURE__ */ jsx("span", { className: "block [overflow-wrap:anywhere]", children: error ? formatError(error) : file?.error ? formatError(file.error) : t("Unknown error", { note: "fallback" }) })
|
|
1246
1266
|
});
|
|
1247
1267
|
}
|
|
1248
1268
|
toastIdRef.current = null;
|
|
1249
1269
|
}
|
|
1250
|
-
}, [
|
|
1270
|
+
}, [
|
|
1271
|
+
enabled,
|
|
1272
|
+
phase,
|
|
1273
|
+
file,
|
|
1274
|
+
files,
|
|
1275
|
+
progress,
|
|
1276
|
+
error,
|
|
1277
|
+
t,
|
|
1278
|
+
formatError,
|
|
1279
|
+
formatFileSize,
|
|
1280
|
+
formatNumber
|
|
1281
|
+
]);
|
|
1251
1282
|
useEffect(() => {
|
|
1252
1283
|
if (!enabled || phase !== "uploading") return;
|
|
1253
1284
|
const isMulti = files.length > 1;
|
|
@@ -1258,11 +1289,15 @@ function useUploadToast(upload, enabled) {
|
|
|
1258
1289
|
title: t("Uploading {done}/{total}", {
|
|
1259
1290
|
note: "toast",
|
|
1260
1291
|
variables: {
|
|
1261
|
-
done:
|
|
1262
|
-
|
|
1292
|
+
done: formatNumber(
|
|
1293
|
+
files.filter((f) => f.status === "success").length
|
|
1294
|
+
),
|
|
1295
|
+
total: formatNumber(files.length)
|
|
1263
1296
|
}
|
|
1264
1297
|
}),
|
|
1265
|
-
description:
|
|
1298
|
+
description: numbersNode(
|
|
1299
|
+
`${formatFileSize(progress.loaded)} / ${formatFileSize(progress.total)}`
|
|
1300
|
+
),
|
|
1266
1301
|
actionProps: {
|
|
1267
1302
|
children: t("Cancel", { note: "toast action" }),
|
|
1268
1303
|
onClick: () => cancelRef.current()
|
|
@@ -1271,7 +1306,9 @@ function useUploadToast(upload, enabled) {
|
|
|
1271
1306
|
type: "loading",
|
|
1272
1307
|
timeout: 0,
|
|
1273
1308
|
title: t("Uploading", { note: "toast" }),
|
|
1274
|
-
description:
|
|
1309
|
+
description: numbersNode(
|
|
1310
|
+
`${formatFileSize(singleProgress.loaded)} / ${formatFileSize(file.size)}`
|
|
1311
|
+
),
|
|
1275
1312
|
actionProps: {
|
|
1276
1313
|
children: t("Cancel", { note: "toast action" }),
|
|
1277
1314
|
onClick: () => cancelRef.current()
|
|
@@ -1283,24 +1320,29 @@ function useUploadToast(upload, enabled) {
|
|
|
1283
1320
|
} else {
|
|
1284
1321
|
toastIdRef.current = toast.add(payload);
|
|
1285
1322
|
}
|
|
1286
|
-
}, [enabled, phase, file, files, progress, t]);
|
|
1323
|
+
}, [enabled, phase, file, files, progress, t, formatFileSize, formatNumber]);
|
|
1287
1324
|
}
|
|
1288
|
-
function rejectionSummary(rejections, t) {
|
|
1325
|
+
function rejectionSummary(rejections, t, formatNumber) {
|
|
1289
1326
|
const first = rejections[0];
|
|
1290
1327
|
if (!first) {
|
|
1291
1328
|
return t("Some files were rejected", { note: "toast" });
|
|
1292
1329
|
}
|
|
1293
1330
|
const detail = first.errors[0]?.message ?? t("File type or size not allowed", { note: "toast" });
|
|
1294
1331
|
if (rejections.length === 1) {
|
|
1295
|
-
return
|
|
1332
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1333
|
+
/* @__PURE__ */ jsx("bdi", { children: first.file.name }),
|
|
1334
|
+
": ",
|
|
1335
|
+
detail
|
|
1336
|
+
] });
|
|
1296
1337
|
}
|
|
1297
1338
|
return t("{count} files were rejected", {
|
|
1298
1339
|
note: "toast",
|
|
1299
|
-
variables: { count:
|
|
1340
|
+
variables: { count: formatNumber(rejections.length) }
|
|
1300
1341
|
});
|
|
1301
1342
|
}
|
|
1302
1343
|
function useFileRejectToast(fileRejections, enabled) {
|
|
1303
1344
|
const t = useTranslations();
|
|
1345
|
+
const formatNumber = useFormatNumber();
|
|
1304
1346
|
const prevRef = useRef([]);
|
|
1305
1347
|
useEffect(() => {
|
|
1306
1348
|
if (!enabled) return;
|
|
@@ -1313,9 +1355,9 @@ function useFileRejectToast(fileRejections, enabled) {
|
|
|
1313
1355
|
toast.add({
|
|
1314
1356
|
type: "error",
|
|
1315
1357
|
title: t("File not accepted", { note: "toast" }),
|
|
1316
|
-
description: /* @__PURE__ */ jsx("span", {
|
|
1358
|
+
description: /* @__PURE__ */ jsx("span", { className: "block [overflow-wrap:anywhere]", children: rejectionSummary(fileRejections, t, formatNumber) })
|
|
1317
1359
|
});
|
|
1318
|
-
}, [enabled, fileRejections, t]);
|
|
1360
|
+
}, [enabled, fileRejections, t, formatNumber]);
|
|
1319
1361
|
}
|
|
1320
1362
|
function useUploadUi(upload, {
|
|
1321
1363
|
toast: enableToast = true,
|
|
@@ -1405,7 +1447,7 @@ function ButtonShell({
|
|
|
1405
1447
|
status
|
|
1406
1448
|
] });
|
|
1407
1449
|
}
|
|
1408
|
-
function dropzoneHints(policy, t) {
|
|
1450
|
+
function dropzoneHints(policy, t, format) {
|
|
1409
1451
|
const acceptLabels = formatAcceptLabels(policy.accept);
|
|
1410
1452
|
const maxFiles = policy.maxFiles;
|
|
1411
1453
|
const limitParts = [];
|
|
@@ -1413,12 +1455,12 @@ function dropzoneHints(policy, t) {
|
|
|
1413
1455
|
limitParts.push(
|
|
1414
1456
|
t("You can upload {count} files", {
|
|
1415
1457
|
note: "dropzone hint",
|
|
1416
|
-
variables: { count:
|
|
1458
|
+
variables: { count: format.number(maxFiles) }
|
|
1417
1459
|
})
|
|
1418
1460
|
);
|
|
1419
1461
|
}
|
|
1420
1462
|
if (policy.maxFileSize != null) {
|
|
1421
|
-
const size =
|
|
1463
|
+
const size = format.fileSize(policy.maxFileSize);
|
|
1422
1464
|
limitParts.push(
|
|
1423
1465
|
maxFiles > 1 ? t("Each up to {size}", {
|
|
1424
1466
|
note: "dropzone hint",
|
|
@@ -1451,7 +1493,12 @@ function UploadDropzone({
|
|
|
1451
1493
|
const isDisabled = Boolean(disabled) || upload.isPending;
|
|
1452
1494
|
const hasCustomChrome = children != null;
|
|
1453
1495
|
const dropzoneLabel = label ?? t("Drag and drop files here", { note: "dropzone" });
|
|
1454
|
-
const
|
|
1496
|
+
const formatFileSize = useFormatFileSize();
|
|
1497
|
+
const formatNumber = useFormatNumber();
|
|
1498
|
+
const { limitsLine, acceptLine } = dropzoneHints(upload.policy, t, {
|
|
1499
|
+
fileSize: formatFileSize,
|
|
1500
|
+
number: formatNumber
|
|
1501
|
+
});
|
|
1455
1502
|
const { statusNode } = useUploadUi(upload, {
|
|
1456
1503
|
toast: enableToast,
|
|
1457
1504
|
attachmentSize,
|
|
@@ -1509,6 +1556,7 @@ function UploadDropzone({
|
|
|
1509
1556
|
}
|
|
1510
1557
|
function useDownloadToast(download, { enabled = true, objectKey, fileName, fileSize }) {
|
|
1511
1558
|
const t = useTranslations();
|
|
1559
|
+
const formatFileSize = useFormatFileSize();
|
|
1512
1560
|
const formatDimahError = useFormatDimahError();
|
|
1513
1561
|
const displayName = fileName ?? fileNameFromKey(objectKey) ?? objectKey;
|
|
1514
1562
|
const toastIdRef = useRef(null);
|
|
@@ -1531,7 +1579,7 @@ function useDownloadToast(download, { enabled = true, objectKey, fileName, fileS
|
|
|
1531
1579
|
const prev = prevPhaseRef.current;
|
|
1532
1580
|
prevPhaseRef.current = phase;
|
|
1533
1581
|
if (!enabled || activeKey !== objectKey) return;
|
|
1534
|
-
const errorNode = (value) => /* @__PURE__ */ jsx("span", {
|
|
1582
|
+
const errorNode = (value) => /* @__PURE__ */ jsx("span", { className: "block [overflow-wrap:anywhere]", children: formatDimahError(value) });
|
|
1535
1583
|
const closeLoading = () => {
|
|
1536
1584
|
if (toastIdRef.current) {
|
|
1537
1585
|
toast.close(toastIdRef.current);
|
|
@@ -1545,7 +1593,7 @@ function useDownloadToast(download, { enabled = true, objectKey, fileName, fileS
|
|
|
1545
1593
|
type: "loading",
|
|
1546
1594
|
timeout: 0,
|
|
1547
1595
|
title: t("Downloading", { note: "toast" }),
|
|
1548
|
-
description: /* @__PURE__ */ jsx("
|
|
1596
|
+
description: /* @__PURE__ */ jsx("bdi", { children: truncateFileName(displayName) }),
|
|
1549
1597
|
actionProps: {
|
|
1550
1598
|
children: t("Cancel", { note: "toast action" }),
|
|
1551
1599
|
onClick: () => cancelRef.current?.()
|
|
@@ -1565,14 +1613,7 @@ function useDownloadToast(download, { enabled = true, objectKey, fileName, fileS
|
|
|
1565
1613
|
" ",
|
|
1566
1614
|
"\xB7",
|
|
1567
1615
|
" ",
|
|
1568
|
-
/* @__PURE__ */ jsx(
|
|
1569
|
-
"span",
|
|
1570
|
-
{
|
|
1571
|
-
dir: "ltr",
|
|
1572
|
-
className: "inline-block whitespace-nowrap tabular-nums",
|
|
1573
|
-
children: formatFileSize(fileSize)
|
|
1574
|
-
}
|
|
1575
|
-
)
|
|
1616
|
+
/* @__PURE__ */ jsx("bdi", { className: "inline-block whitespace-nowrap tabular-nums", children: formatFileSize(fileSize) })
|
|
1576
1617
|
] }) : null
|
|
1577
1618
|
] })
|
|
1578
1619
|
});
|
|
@@ -1592,7 +1633,7 @@ function useDownloadToast(download, { enabled = true, objectKey, fileName, fileS
|
|
|
1592
1633
|
toast.add({
|
|
1593
1634
|
type: "info",
|
|
1594
1635
|
title: t("Download cancelled", { note: "toast" }),
|
|
1595
|
-
description: /* @__PURE__ */ jsx("
|
|
1636
|
+
description: /* @__PURE__ */ jsx("bdi", { children: truncateFileName(displayName) })
|
|
1596
1637
|
});
|
|
1597
1638
|
}
|
|
1598
1639
|
return;
|
|
@@ -1623,7 +1664,8 @@ function useDownloadToast(download, { enabled = true, objectKey, fileName, fileS
|
|
|
1623
1664
|
activeKey,
|
|
1624
1665
|
objectKey,
|
|
1625
1666
|
t,
|
|
1626
|
-
formatDimahError
|
|
1667
|
+
formatDimahError,
|
|
1668
|
+
formatFileSize
|
|
1627
1669
|
]);
|
|
1628
1670
|
useEffect(() => {
|
|
1629
1671
|
if (!enabled || activeKey !== objectKey || phase !== "downloading" || !progress) {
|
|
@@ -1634,16 +1676,13 @@ function useDownloadToast(download, { enabled = true, objectKey, fileName, fileS
|
|
|
1634
1676
|
type: "loading",
|
|
1635
1677
|
timeout: 0,
|
|
1636
1678
|
title: t("Downloading", { note: "toast" }),
|
|
1637
|
-
description: /* @__PURE__ */
|
|
1638
|
-
formatFileSize(progress.loaded),
|
|
1639
|
-
progress.total > 0 ? ` / ${formatFileSize(progress.total)}` : null
|
|
1640
|
-
] }),
|
|
1679
|
+
description: /* @__PURE__ */ jsx("bdi", { className: "inline-block whitespace-nowrap tabular-nums", children: progress.total > 0 ? `${formatFileSize(progress.loaded)} / ${formatFileSize(progress.total)}` : formatFileSize(progress.loaded) }),
|
|
1641
1680
|
actionProps: {
|
|
1642
1681
|
children: t("Cancel", { note: "toast action" }),
|
|
1643
1682
|
onClick: () => cancelRef.current?.()
|
|
1644
1683
|
}
|
|
1645
1684
|
});
|
|
1646
|
-
}, [enabled, phase, progress, t, activeKey, objectKey]);
|
|
1685
|
+
}, [enabled, phase, progress, t, activeKey, objectKey, formatFileSize]);
|
|
1647
1686
|
}
|
|
1648
1687
|
function useDownloadUi(download, {
|
|
1649
1688
|
toast: enableToast = true,
|
|
@@ -1770,6 +1809,7 @@ function ProgressDownloadButton({
|
|
|
1770
1809
|
attachmentOrientation
|
|
1771
1810
|
}) {
|
|
1772
1811
|
const t = useTranslations();
|
|
1812
|
+
const formatFileSize = useFormatFileSize();
|
|
1773
1813
|
const isThis = download.objectKey === objectKey;
|
|
1774
1814
|
const isPendingThis = download.isPending && isThis;
|
|
1775
1815
|
const { statusNode } = useDownloadUi(download, {
|
|
@@ -2001,14 +2041,14 @@ function useDeleteToast(del, { enabled = true, objectKey, displayName }) {
|
|
|
2001
2041
|
toast.add({
|
|
2002
2042
|
type: "success",
|
|
2003
2043
|
title: t("File deleted", { note: "toast" }),
|
|
2004
|
-
description: /* @__PURE__ */ jsx("
|
|
2044
|
+
description: /* @__PURE__ */ jsx("bdi", { children: truncateFileName(displayName) })
|
|
2005
2045
|
});
|
|
2006
2046
|
}
|
|
2007
2047
|
if (del.phase === "error") {
|
|
2008
2048
|
toast.add({
|
|
2009
2049
|
type: "error",
|
|
2010
2050
|
title: t("Delete failed", { note: "toast" }),
|
|
2011
|
-
description: /* @__PURE__ */ jsx("span", {
|
|
2051
|
+
description: /* @__PURE__ */ jsx("span", { className: "block [overflow-wrap:anywhere]", children: formatDimahError(del.error) })
|
|
2012
2052
|
});
|
|
2013
2053
|
}
|
|
2014
2054
|
}, [
|
|
@@ -2022,6 +2062,11 @@ function useDeleteToast(del, { enabled = true, objectKey, displayName }) {
|
|
|
2022
2062
|
formatDimahError
|
|
2023
2063
|
]);
|
|
2024
2064
|
}
|
|
2065
|
+
|
|
2066
|
+
// src/lib/isolate-text.ts
|
|
2067
|
+
function isolateText(value) {
|
|
2068
|
+
return `\u2068${value}\u2069`;
|
|
2069
|
+
}
|
|
2025
2070
|
function useDeleteUi(del, {
|
|
2026
2071
|
toast: enableToast = true,
|
|
2027
2072
|
objectKey,
|
|
@@ -2042,7 +2087,7 @@ function useDeleteUi(del, {
|
|
|
2042
2087
|
state: "done",
|
|
2043
2088
|
title: t('"{name}" deleted', {
|
|
2044
2089
|
note: "status",
|
|
2045
|
-
variables: { name: truncateFileName(displayName) }
|
|
2090
|
+
variables: { name: isolateText(truncateFileName(displayName)) }
|
|
2046
2091
|
}),
|
|
2047
2092
|
onDismiss: del.reset,
|
|
2048
2093
|
size: attachmentSize,
|
|
@@ -2061,9 +2106,6 @@ function useDeleteUi(del, {
|
|
|
2061
2106
|
) : null;
|
|
2062
2107
|
return { statusNode };
|
|
2063
2108
|
}
|
|
2064
|
-
function isolateLtr(value) {
|
|
2065
|
-
return `\u2066${value}\u2069`;
|
|
2066
|
-
}
|
|
2067
2109
|
function DeleteButton({
|
|
2068
2110
|
delete: del,
|
|
2069
2111
|
objectKey,
|
|
@@ -2085,6 +2127,7 @@ function DeleteButton({
|
|
|
2085
2127
|
attachmentOrientation
|
|
2086
2128
|
}) {
|
|
2087
2129
|
const t = useTranslations();
|
|
2130
|
+
const formatFileSize = useFormatFileSize();
|
|
2088
2131
|
const displayName = fileName ?? fileNameFromKey(objectKey) ?? objectKey;
|
|
2089
2132
|
const isThis = del.objectKey === objectKey;
|
|
2090
2133
|
const isDeletingThis = del.isDeleting && isThis;
|
|
@@ -2100,12 +2143,13 @@ function DeleteButton({
|
|
|
2100
2143
|
isDeletingThis ? /* @__PURE__ */ jsx(LoaderIcon, { className: "animate-spin", "data-icon": "inline-start" }) : /* @__PURE__ */ jsx(Trash2Icon, { "data-icon": "inline-start" }),
|
|
2101
2144
|
label ?? t("Delete", { note: "button" })
|
|
2102
2145
|
] });
|
|
2103
|
-
const
|
|
2146
|
+
const name = isolateText(truncateFileName(displayName));
|
|
2147
|
+
const fileLabel = fileSize != null ? `${name} (${isolateText(formatFileSize(fileSize))})` : name;
|
|
2104
2148
|
const description = confirmDescription ?? t(
|
|
2105
2149
|
'Are you sure you want to delete "{name}"? This action cannot be undone.',
|
|
2106
2150
|
{
|
|
2107
2151
|
note: "dialog description",
|
|
2108
|
-
variables: { name:
|
|
2152
|
+
variables: { name: fileLabel }
|
|
2109
2153
|
}
|
|
2110
2154
|
);
|
|
2111
2155
|
return /* @__PURE__ */ jsxs("div", { className: cn("inline-flex flex-col gap-2", className), children: [
|
|
@@ -2146,14 +2190,7 @@ function DeleteButton({
|
|
|
2146
2190
|
/* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
|
|
2147
2191
|
/* @__PURE__ */ jsx(AlertDialogMedia, { children: /* @__PURE__ */ jsx(Trash2Icon, {}) }),
|
|
2148
2192
|
/* @__PURE__ */ jsx(AlertDialogTitle, { children: confirmTitle ?? t("Delete file?", { note: "dialog title" }) }),
|
|
2149
|
-
/* @__PURE__ */ jsx(
|
|
2150
|
-
AlertDialogDescription,
|
|
2151
|
-
{
|
|
2152
|
-
dir: "auto",
|
|
2153
|
-
className: "[overflow-wrap:anywhere]",
|
|
2154
|
-
children: description
|
|
2155
|
-
}
|
|
2156
|
-
)
|
|
2193
|
+
/* @__PURE__ */ jsx(AlertDialogDescription, { className: "[overflow-wrap:anywhere]", children: description })
|
|
2157
2194
|
] }),
|
|
2158
2195
|
/* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
|
|
2159
2196
|
/* @__PURE__ */ jsx(AlertDialogCancel, { children: t("Cancel", { note: "dialog button" }) }),
|
|
@@ -2173,7 +2210,1835 @@ function DeleteButton({
|
|
|
2173
2210
|
resolveStatusSlot(statusSlot, statusNode)
|
|
2174
2211
|
] });
|
|
2175
2212
|
}
|
|
2213
|
+
function Spinner({
|
|
2214
|
+
className,
|
|
2215
|
+
...props
|
|
2216
|
+
}) {
|
|
2217
|
+
return /* @__PURE__ */ jsx(
|
|
2218
|
+
Loader2Icon,
|
|
2219
|
+
{
|
|
2220
|
+
"data-slot": "spinner",
|
|
2221
|
+
role: "status",
|
|
2222
|
+
"aria-label": "Loading",
|
|
2223
|
+
className: cn("size-4 animate-spin", className),
|
|
2224
|
+
...props
|
|
2225
|
+
}
|
|
2226
|
+
);
|
|
2227
|
+
}
|
|
2228
|
+
function Breadcrumb({ className, ...props }) {
|
|
2229
|
+
return /* @__PURE__ */ jsx(
|
|
2230
|
+
"nav",
|
|
2231
|
+
{
|
|
2232
|
+
"aria-label": "breadcrumb",
|
|
2233
|
+
"data-slot": "breadcrumb",
|
|
2234
|
+
className: cn(className),
|
|
2235
|
+
...props
|
|
2236
|
+
}
|
|
2237
|
+
);
|
|
2238
|
+
}
|
|
2239
|
+
function BreadcrumbList({ className, ...props }) {
|
|
2240
|
+
return /* @__PURE__ */ jsx(
|
|
2241
|
+
"ol",
|
|
2242
|
+
{
|
|
2243
|
+
"data-slot": "breadcrumb-list",
|
|
2244
|
+
className: cn(
|
|
2245
|
+
"flex flex-wrap items-center gap-1.5 text-sm wrap-break-word text-muted-foreground",
|
|
2246
|
+
className
|
|
2247
|
+
),
|
|
2248
|
+
...props
|
|
2249
|
+
}
|
|
2250
|
+
);
|
|
2251
|
+
}
|
|
2252
|
+
function BreadcrumbItem({ className, ...props }) {
|
|
2253
|
+
return /* @__PURE__ */ jsx(
|
|
2254
|
+
"li",
|
|
2255
|
+
{
|
|
2256
|
+
"data-slot": "breadcrumb-item",
|
|
2257
|
+
className: cn("inline-flex items-center gap-1", className),
|
|
2258
|
+
...props
|
|
2259
|
+
}
|
|
2260
|
+
);
|
|
2261
|
+
}
|
|
2262
|
+
function BreadcrumbLink({
|
|
2263
|
+
className,
|
|
2264
|
+
render,
|
|
2265
|
+
...props
|
|
2266
|
+
}) {
|
|
2267
|
+
return useRender({
|
|
2268
|
+
defaultTagName: "a",
|
|
2269
|
+
props: mergeProps(
|
|
2270
|
+
{
|
|
2271
|
+
className: cn("transition-colors hover:text-foreground", className)
|
|
2272
|
+
},
|
|
2273
|
+
props
|
|
2274
|
+
),
|
|
2275
|
+
render,
|
|
2276
|
+
state: {
|
|
2277
|
+
slot: "breadcrumb-link"
|
|
2278
|
+
}
|
|
2279
|
+
});
|
|
2280
|
+
}
|
|
2281
|
+
function BreadcrumbPage({ className, ...props }) {
|
|
2282
|
+
return /* @__PURE__ */ jsx(
|
|
2283
|
+
"span",
|
|
2284
|
+
{
|
|
2285
|
+
"data-slot": "breadcrumb-page",
|
|
2286
|
+
role: "link",
|
|
2287
|
+
"aria-disabled": "true",
|
|
2288
|
+
"aria-current": "page",
|
|
2289
|
+
className: cn("font-normal text-foreground", className),
|
|
2290
|
+
...props
|
|
2291
|
+
}
|
|
2292
|
+
);
|
|
2293
|
+
}
|
|
2294
|
+
function BreadcrumbSeparator({
|
|
2295
|
+
children,
|
|
2296
|
+
className,
|
|
2297
|
+
...props
|
|
2298
|
+
}) {
|
|
2299
|
+
return /* @__PURE__ */ jsx(
|
|
2300
|
+
"li",
|
|
2301
|
+
{
|
|
2302
|
+
"data-slot": "breadcrumb-separator",
|
|
2303
|
+
role: "presentation",
|
|
2304
|
+
"aria-hidden": "true",
|
|
2305
|
+
className: cn("[&>svg]:size-3.5", className),
|
|
2306
|
+
...props,
|
|
2307
|
+
children: children ?? /* @__PURE__ */ jsx(ChevronRightIcon, { className: "rtl:rotate-180" })
|
|
2308
|
+
}
|
|
2309
|
+
);
|
|
2310
|
+
}
|
|
2311
|
+
function BreadcrumbEllipsis({
|
|
2312
|
+
className,
|
|
2313
|
+
...props
|
|
2314
|
+
}) {
|
|
2315
|
+
return /* @__PURE__ */ jsxs(
|
|
2316
|
+
"span",
|
|
2317
|
+
{
|
|
2318
|
+
"data-slot": "breadcrumb-ellipsis",
|
|
2319
|
+
role: "presentation",
|
|
2320
|
+
"aria-hidden": "true",
|
|
2321
|
+
className: cn(
|
|
2322
|
+
"flex size-5 items-center justify-center [&>svg]:size-4",
|
|
2323
|
+
className
|
|
2324
|
+
),
|
|
2325
|
+
...props,
|
|
2326
|
+
children: [
|
|
2327
|
+
/* @__PURE__ */ jsx(MoreHorizontalIcon, {}),
|
|
2328
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: "More" })
|
|
2329
|
+
]
|
|
2330
|
+
}
|
|
2331
|
+
);
|
|
2332
|
+
}
|
|
2333
|
+
function DropdownMenu({ ...props }) {
|
|
2334
|
+
return /* @__PURE__ */ jsx(Menu.Root, { "data-slot": "dropdown-menu", ...props });
|
|
2335
|
+
}
|
|
2336
|
+
function DropdownMenuTrigger({ ...props }) {
|
|
2337
|
+
return /* @__PURE__ */ jsx(Menu.Trigger, { "data-slot": "dropdown-menu-trigger", ...props });
|
|
2338
|
+
}
|
|
2339
|
+
function DropdownMenuContent({
|
|
2340
|
+
align = "start",
|
|
2341
|
+
alignOffset = 0,
|
|
2342
|
+
side = "bottom",
|
|
2343
|
+
sideOffset = 4,
|
|
2344
|
+
className,
|
|
2345
|
+
...props
|
|
2346
|
+
}) {
|
|
2347
|
+
return /* @__PURE__ */ jsx(Menu.Portal, { children: /* @__PURE__ */ jsx(
|
|
2348
|
+
Menu.Positioner,
|
|
2349
|
+
{
|
|
2350
|
+
className: "isolate z-50 outline-none",
|
|
2351
|
+
align,
|
|
2352
|
+
alignOffset,
|
|
2353
|
+
side,
|
|
2354
|
+
sideOffset,
|
|
2355
|
+
children: /* @__PURE__ */ jsx(
|
|
2356
|
+
Menu.Popup,
|
|
2357
|
+
{
|
|
2358
|
+
"data-slot": "dropdown-menu-content",
|
|
2359
|
+
className: cn(
|
|
2360
|
+
"cn-menu-target cn-menu-translucent z-50 max-h-(--available-height) w-(--anchor-width) min-w-32 origin-(--transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 outline-none data-[side=bottom]:slide-in-from-top-2 data-[side=inline-end]:slide-in-from-left-2 data-[side=inline-start]:slide-in-from-right-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-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:overflow-hidden data-closed:fade-out-0 data-closed:zoom-out-95",
|
|
2361
|
+
className
|
|
2362
|
+
),
|
|
2363
|
+
...props
|
|
2364
|
+
}
|
|
2365
|
+
)
|
|
2366
|
+
}
|
|
2367
|
+
) });
|
|
2368
|
+
}
|
|
2369
|
+
function DropdownMenuGroup({ ...props }) {
|
|
2370
|
+
return /* @__PURE__ */ jsx(Menu.Group, { "data-slot": "dropdown-menu-group", ...props });
|
|
2371
|
+
}
|
|
2372
|
+
function DropdownMenuItem({
|
|
2373
|
+
className,
|
|
2374
|
+
inset,
|
|
2375
|
+
variant = "default",
|
|
2376
|
+
...props
|
|
2377
|
+
}) {
|
|
2378
|
+
return /* @__PURE__ */ jsx(
|
|
2379
|
+
Menu.Item,
|
|
2380
|
+
{
|
|
2381
|
+
"data-slot": "dropdown-menu-item",
|
|
2382
|
+
"data-inset": inset,
|
|
2383
|
+
"data-variant": variant,
|
|
2384
|
+
className: cn(
|
|
2385
|
+
"group/dropdown-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:ps-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive",
|
|
2386
|
+
className
|
|
2387
|
+
),
|
|
2388
|
+
...props
|
|
2389
|
+
}
|
|
2390
|
+
);
|
|
2391
|
+
}
|
|
2392
|
+
function DropdownMenuSeparator({
|
|
2393
|
+
className,
|
|
2394
|
+
...props
|
|
2395
|
+
}) {
|
|
2396
|
+
return /* @__PURE__ */ jsx(
|
|
2397
|
+
Menu.Separator,
|
|
2398
|
+
{
|
|
2399
|
+
"data-slot": "dropdown-menu-separator",
|
|
2400
|
+
className: cn("-mx-1 my-1 h-px bg-border", className),
|
|
2401
|
+
...props
|
|
2402
|
+
}
|
|
2403
|
+
);
|
|
2404
|
+
}
|
|
2405
|
+
var VISIBLE_TRAIL = 2;
|
|
2406
|
+
function splitObjectListTrail(trail) {
|
|
2407
|
+
if (trail.length <= VISIBLE_TRAIL) {
|
|
2408
|
+
return { hidden: [], visible: trail };
|
|
2409
|
+
}
|
|
2410
|
+
return {
|
|
2411
|
+
hidden: trail.slice(0, -VISIBLE_TRAIL),
|
|
2412
|
+
visible: trail.slice(-VISIBLE_TRAIL)
|
|
2413
|
+
};
|
|
2414
|
+
}
|
|
2415
|
+
function ObjectListBreadcrumb({
|
|
2416
|
+
rootLabel,
|
|
2417
|
+
trail,
|
|
2418
|
+
navigate
|
|
2419
|
+
}) {
|
|
2420
|
+
const t = useTranslations();
|
|
2421
|
+
const atRoot = trail.length === 0;
|
|
2422
|
+
const { hidden, visible } = splitObjectListTrail(trail);
|
|
2423
|
+
return /* @__PURE__ */ jsx(Breadcrumb, { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsxs(BreadcrumbList, { className: "min-w-0 flex-nowrap", children: [
|
|
2424
|
+
/* @__PURE__ */ jsx(BreadcrumbItem, { className: "min-w-0", children: atRoot || navigate == null ? /* @__PURE__ */ jsx(BreadcrumbPage, { className: "max-w-40 truncate sm:max-w-56", children: rootLabel }) : /* @__PURE__ */ jsx(
|
|
2425
|
+
BreadcrumbLink,
|
|
2426
|
+
{
|
|
2427
|
+
className: "max-w-40 truncate sm:max-w-56",
|
|
2428
|
+
render: /* @__PURE__ */ jsx("button", { type: "button" }),
|
|
2429
|
+
onClick: () => navigate([]),
|
|
2430
|
+
children: rootLabel
|
|
2431
|
+
}
|
|
2432
|
+
) }),
|
|
2433
|
+
hidden.length > 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
2434
|
+
/* @__PURE__ */ jsx(BreadcrumbSeparator, {}),
|
|
2435
|
+
/* @__PURE__ */ jsx(BreadcrumbItem, { className: "shrink-0", children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
2436
|
+
/* @__PURE__ */ jsxs(DropdownMenuTrigger, { className: "flex items-center gap-1", children: [
|
|
2437
|
+
/* @__PURE__ */ jsx(BreadcrumbEllipsis, { className: "size-4" }),
|
|
2438
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: t("Earlier folders", { note: "object list" }) })
|
|
2439
|
+
] }),
|
|
2440
|
+
/* @__PURE__ */ jsx(
|
|
2441
|
+
DropdownMenuContent,
|
|
2442
|
+
{
|
|
2443
|
+
align: "start",
|
|
2444
|
+
className: "max-w-64 min-w-48",
|
|
2445
|
+
children: /* @__PURE__ */ jsx(DropdownMenuGroup, { children: hidden.map((folder, index) => /* @__PURE__ */ jsx(
|
|
2446
|
+
DropdownMenuItem,
|
|
2447
|
+
{
|
|
2448
|
+
disabled: navigate == null,
|
|
2449
|
+
onClick: () => navigate?.(trail.slice(0, index + 1)),
|
|
2450
|
+
children: /* @__PURE__ */ jsx("span", { className: "truncate", children: /* @__PURE__ */ jsx("bdi", { children: folder.name }) })
|
|
2451
|
+
},
|
|
2452
|
+
folder.id
|
|
2453
|
+
)) })
|
|
2454
|
+
}
|
|
2455
|
+
)
|
|
2456
|
+
] }) })
|
|
2457
|
+
] }) : null,
|
|
2458
|
+
visible.map((folder, index) => {
|
|
2459
|
+
const trailIndex = hidden.length + index;
|
|
2460
|
+
const current = trailIndex === trail.length - 1;
|
|
2461
|
+
return /* @__PURE__ */ jsxs(Fragment$1, { children: [
|
|
2462
|
+
/* @__PURE__ */ jsx(BreadcrumbSeparator, {}),
|
|
2463
|
+
/* @__PURE__ */ jsx(BreadcrumbItem, { className: "min-w-0", children: current || navigate == null ? /* @__PURE__ */ jsx(BreadcrumbPage, { className: "max-w-40 truncate sm:max-w-56", children: /* @__PURE__ */ jsx("bdi", { children: folder.name }) }) : /* @__PURE__ */ jsx(
|
|
2464
|
+
BreadcrumbLink,
|
|
2465
|
+
{
|
|
2466
|
+
className: "max-w-40 truncate sm:max-w-56",
|
|
2467
|
+
render: /* @__PURE__ */ jsx("button", { type: "button" }),
|
|
2468
|
+
onClick: () => navigate(trail.slice(0, trailIndex + 1)),
|
|
2469
|
+
children: /* @__PURE__ */ jsx("bdi", { children: folder.name })
|
|
2470
|
+
}
|
|
2471
|
+
) })
|
|
2472
|
+
] }, folder.id);
|
|
2473
|
+
})
|
|
2474
|
+
] }) });
|
|
2475
|
+
}
|
|
2476
|
+
function Checkbox({ className, ...props }) {
|
|
2477
|
+
return /* @__PURE__ */ jsx(
|
|
2478
|
+
Checkbox$1.Root,
|
|
2479
|
+
{
|
|
2480
|
+
"data-slot": "checkbox",
|
|
2481
|
+
className: cn(
|
|
2482
|
+
"peer relative flex size-4 shrink-0 items-center justify-center rounded-[4px] border border-input transition-colors outline-none group-has-disabled/field:opacity-50 group-has-[:focus-visible]/field-label:ring-0 group-has-[:focus-visible]/field-label:not-data-checked:border-input after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground group-has-[:focus-visible]/field-label:data-checked:border-primary dark:data-checked:bg-primary",
|
|
2483
|
+
className
|
|
2484
|
+
),
|
|
2485
|
+
...props,
|
|
2486
|
+
children: /* @__PURE__ */ jsxs(
|
|
2487
|
+
Checkbox$1.Indicator,
|
|
2488
|
+
{
|
|
2489
|
+
"data-slot": "checkbox-indicator",
|
|
2490
|
+
className: "grid place-content-center text-current transition-none [&>svg]:size-3.5",
|
|
2491
|
+
children: [
|
|
2492
|
+
/* @__PURE__ */ jsx(CheckIcon, { className: "in-data-indeterminate:hidden" }),
|
|
2493
|
+
/* @__PURE__ */ jsx(MinusIcon, { className: "hidden in-data-indeterminate:block" })
|
|
2494
|
+
]
|
|
2495
|
+
}
|
|
2496
|
+
)
|
|
2497
|
+
}
|
|
2498
|
+
);
|
|
2499
|
+
}
|
|
2500
|
+
var itemVariants = cva(
|
|
2501
|
+
"group/item flex w-full flex-wrap items-center rounded-lg border text-sm transition-colors duration-100 outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 [a]:transition-colors [a]:hover:bg-muted",
|
|
2502
|
+
{
|
|
2503
|
+
variants: {
|
|
2504
|
+
variant: {
|
|
2505
|
+
default: "border-transparent",
|
|
2506
|
+
outline: "border-border",
|
|
2507
|
+
muted: "border-transparent bg-muted/50"
|
|
2508
|
+
},
|
|
2509
|
+
size: {
|
|
2510
|
+
default: "gap-2.5 px-3 py-2.5",
|
|
2511
|
+
sm: "gap-2.5 px-3 py-2.5",
|
|
2512
|
+
xs: "gap-2 px-2.5 py-2 in-data-[slot=dropdown-menu-content]:p-0"
|
|
2513
|
+
}
|
|
2514
|
+
},
|
|
2515
|
+
defaultVariants: {
|
|
2516
|
+
variant: "default",
|
|
2517
|
+
size: "default"
|
|
2518
|
+
}
|
|
2519
|
+
}
|
|
2520
|
+
);
|
|
2521
|
+
function Item({
|
|
2522
|
+
className,
|
|
2523
|
+
variant = "default",
|
|
2524
|
+
size = "default",
|
|
2525
|
+
render,
|
|
2526
|
+
...props
|
|
2527
|
+
}) {
|
|
2528
|
+
return useRender({
|
|
2529
|
+
defaultTagName: "div",
|
|
2530
|
+
props: mergeProps(
|
|
2531
|
+
{
|
|
2532
|
+
className: cn(itemVariants({ variant, size, className }))
|
|
2533
|
+
},
|
|
2534
|
+
props
|
|
2535
|
+
),
|
|
2536
|
+
render,
|
|
2537
|
+
state: {
|
|
2538
|
+
slot: "item",
|
|
2539
|
+
variant,
|
|
2540
|
+
size
|
|
2541
|
+
}
|
|
2542
|
+
});
|
|
2543
|
+
}
|
|
2544
|
+
cva(
|
|
2545
|
+
"flex shrink-0 items-center justify-center gap-2 group-has-data-[slot=item-description]/item:translate-y-0.5 group-has-data-[slot=item-description]/item:self-start [&_svg]:pointer-events-none",
|
|
2546
|
+
{
|
|
2547
|
+
variants: {
|
|
2548
|
+
variant: {
|
|
2549
|
+
default: "bg-transparent",
|
|
2550
|
+
icon: "[&_svg:not([class*='size-'])]:size-4",
|
|
2551
|
+
image: "size-10 overflow-hidden rounded-sm group-data-[size=sm]/item:size-8 group-data-[size=xs]/item:size-6 [&_img]:size-full [&_img]:object-cover"
|
|
2552
|
+
}
|
|
2553
|
+
},
|
|
2554
|
+
defaultVariants: {
|
|
2555
|
+
variant: "default"
|
|
2556
|
+
}
|
|
2557
|
+
}
|
|
2558
|
+
);
|
|
2559
|
+
function ItemContent({ className, ...props }) {
|
|
2560
|
+
return /* @__PURE__ */ jsx(
|
|
2561
|
+
"div",
|
|
2562
|
+
{
|
|
2563
|
+
"data-slot": "item-content",
|
|
2564
|
+
className: cn(
|
|
2565
|
+
"flex flex-1 flex-col gap-1 group-data-[size=xs]/item:gap-0 [&+[data-slot=item-content]]:flex-none",
|
|
2566
|
+
className
|
|
2567
|
+
),
|
|
2568
|
+
...props
|
|
2569
|
+
}
|
|
2570
|
+
);
|
|
2571
|
+
}
|
|
2572
|
+
function ItemTitle({ className, ...props }) {
|
|
2573
|
+
return /* @__PURE__ */ jsx(
|
|
2574
|
+
"div",
|
|
2575
|
+
{
|
|
2576
|
+
"data-slot": "item-title",
|
|
2577
|
+
className: cn(
|
|
2578
|
+
"line-clamp-1 flex w-fit items-center gap-2 text-sm leading-snug font-medium underline-offset-4",
|
|
2579
|
+
className
|
|
2580
|
+
),
|
|
2581
|
+
...props
|
|
2582
|
+
}
|
|
2583
|
+
);
|
|
2584
|
+
}
|
|
2585
|
+
function ItemDescription({ className, ...props }) {
|
|
2586
|
+
return /* @__PURE__ */ jsx(
|
|
2587
|
+
"p",
|
|
2588
|
+
{
|
|
2589
|
+
"data-slot": "item-description",
|
|
2590
|
+
className: cn(
|
|
2591
|
+
"line-clamp-2 text-start text-sm leading-normal font-normal text-muted-foreground group-data-[size=xs]/item:text-xs [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary",
|
|
2592
|
+
className
|
|
2593
|
+
),
|
|
2594
|
+
...props
|
|
2595
|
+
}
|
|
2596
|
+
);
|
|
2597
|
+
}
|
|
2598
|
+
function SelectCheckbox({
|
|
2599
|
+
checked,
|
|
2600
|
+
indeterminate,
|
|
2601
|
+
label,
|
|
2602
|
+
onCheckedChange
|
|
2603
|
+
}) {
|
|
2604
|
+
const shiftRef = useRef(false);
|
|
2605
|
+
return /* @__PURE__ */ jsx(
|
|
2606
|
+
Checkbox,
|
|
2607
|
+
{
|
|
2608
|
+
checked,
|
|
2609
|
+
indeterminate,
|
|
2610
|
+
"aria-label": label,
|
|
2611
|
+
className: "after:-inset-x-2 after:-inset-y-3",
|
|
2612
|
+
onPointerDown: (event) => {
|
|
2613
|
+
shiftRef.current = event.shiftKey;
|
|
2614
|
+
},
|
|
2615
|
+
onKeyDown: (event) => {
|
|
2616
|
+
if (event.key === " " || event.key === "Enter") {
|
|
2617
|
+
shiftRef.current = event.shiftKey;
|
|
2618
|
+
}
|
|
2619
|
+
},
|
|
2620
|
+
onCheckedChange: (value) => {
|
|
2621
|
+
onCheckedChange(value, shiftRef.current);
|
|
2622
|
+
shiftRef.current = false;
|
|
2623
|
+
}
|
|
2624
|
+
}
|
|
2625
|
+
);
|
|
2626
|
+
}
|
|
2627
|
+
function ObjectListRows({
|
|
2628
|
+
items,
|
|
2629
|
+
folders,
|
|
2630
|
+
getKey,
|
|
2631
|
+
getLabel,
|
|
2632
|
+
getDescription,
|
|
2633
|
+
getFileName,
|
|
2634
|
+
getFileType,
|
|
2635
|
+
getPreviewUrl,
|
|
2636
|
+
renderItem,
|
|
2637
|
+
renderFolder,
|
|
2638
|
+
renderActions,
|
|
2639
|
+
renderMeta,
|
|
2640
|
+
onOpenItem,
|
|
2641
|
+
renderFolderActions,
|
|
2642
|
+
openFolder,
|
|
2643
|
+
filesSelectable,
|
|
2644
|
+
foldersSelectable,
|
|
2645
|
+
fileKeys,
|
|
2646
|
+
folderIds,
|
|
2647
|
+
selectRow
|
|
2648
|
+
}) {
|
|
2649
|
+
const t = useTranslations();
|
|
2650
|
+
return /* @__PURE__ */ jsxs("div", { role: "list", className: "flex min-w-0 flex-col", children: [
|
|
2651
|
+
folders.map(
|
|
2652
|
+
(folder) => renderFolder ? /* @__PURE__ */ jsx("div", { role: "listitem", "data-kind": "folder", children: renderFolder(folder) }, folder.id) : /* @__PURE__ */ jsx(
|
|
2653
|
+
ObjectListRow,
|
|
2654
|
+
{
|
|
2655
|
+
kind: "folder",
|
|
2656
|
+
title: folder.name,
|
|
2657
|
+
media: /* @__PURE__ */ jsx(FolderGlyph, {}),
|
|
2658
|
+
actions: renderFolderActions?.(folder),
|
|
2659
|
+
selected: folderIds.has(folder.id),
|
|
2660
|
+
selectable: foldersSelectable,
|
|
2661
|
+
selectLabel: t("Select {name}", {
|
|
2662
|
+
note: "object list selection",
|
|
2663
|
+
variables: { name: folder.name }
|
|
2664
|
+
}),
|
|
2665
|
+
onSelect: foldersSelectable ? (checked, shift) => selectRow("folder", folder.id, checked, shift) : void 0,
|
|
2666
|
+
onOpen: openFolder != null ? () => openFolder(folder) : void 0
|
|
2667
|
+
},
|
|
2668
|
+
folder.id
|
|
2669
|
+
)
|
|
2670
|
+
),
|
|
2671
|
+
items.map((item) => {
|
|
2672
|
+
const key = getKey(item);
|
|
2673
|
+
if (renderItem) {
|
|
2674
|
+
return /* @__PURE__ */ jsx("div", { role: "listitem", "data-kind": "file", children: renderItem(item) }, key);
|
|
2675
|
+
}
|
|
2676
|
+
const fileName = getFileName?.(item) ?? getLabel(item);
|
|
2677
|
+
const previewUrl = getPreviewUrl?.(item);
|
|
2678
|
+
return /* @__PURE__ */ jsx(
|
|
2679
|
+
ObjectListRow,
|
|
2680
|
+
{
|
|
2681
|
+
kind: "file",
|
|
2682
|
+
title: getLabel(item),
|
|
2683
|
+
description: getDescription?.(item),
|
|
2684
|
+
media: previewUrl ? /* @__PURE__ */ jsx(
|
|
2685
|
+
"img",
|
|
2686
|
+
{
|
|
2687
|
+
src: previewUrl,
|
|
2688
|
+
alt: "",
|
|
2689
|
+
draggable: false,
|
|
2690
|
+
decoding: "async",
|
|
2691
|
+
className: "size-8 shrink-0 rounded-[4px] object-cover"
|
|
2692
|
+
}
|
|
2693
|
+
) : /* @__PURE__ */ jsx(
|
|
2694
|
+
FileTypeGlyph,
|
|
2695
|
+
{
|
|
2696
|
+
layout: "icon",
|
|
2697
|
+
fileName,
|
|
2698
|
+
fileType: getFileType?.(item)
|
|
2699
|
+
}
|
|
2700
|
+
),
|
|
2701
|
+
actions: renderActions?.(item),
|
|
2702
|
+
meta: renderMeta?.(item),
|
|
2703
|
+
selected: fileKeys.has(key),
|
|
2704
|
+
selectable: filesSelectable,
|
|
2705
|
+
selectLabel: t("Select {name}", {
|
|
2706
|
+
note: "object list selection",
|
|
2707
|
+
variables: { name: getLabel(item) }
|
|
2708
|
+
}),
|
|
2709
|
+
onOpen: onOpenItem != null ? () => onOpenItem(item) : void 0,
|
|
2710
|
+
onSelect: filesSelectable ? (checked, shift) => selectRow("file", key, checked, shift) : void 0
|
|
2711
|
+
},
|
|
2712
|
+
key
|
|
2713
|
+
);
|
|
2714
|
+
})
|
|
2715
|
+
] });
|
|
2716
|
+
}
|
|
2717
|
+
var FILE_EXTENSION = /^\.[a-z0-9]{1,8}$/i;
|
|
2718
|
+
function splitFileName(name) {
|
|
2719
|
+
const dot = name.lastIndexOf(".");
|
|
2720
|
+
if (dot <= 0) return { stem: name, extension: "" };
|
|
2721
|
+
const extension = name.slice(dot);
|
|
2722
|
+
if (!FILE_EXTENSION.test(extension)) return { stem: name, extension: "" };
|
|
2723
|
+
return { stem: name.slice(0, dot), extension };
|
|
2724
|
+
}
|
|
2725
|
+
function NameLabel({ name, kind }) {
|
|
2726
|
+
const { stem, extension } = kind === "file" ? splitFileName(name) : { stem: name, extension: "" };
|
|
2727
|
+
return /* @__PURE__ */ jsxs(
|
|
2728
|
+
"span",
|
|
2729
|
+
{
|
|
2730
|
+
dir: "auto",
|
|
2731
|
+
title: name,
|
|
2732
|
+
className: "inline-flex max-w-full min-w-0 align-top",
|
|
2733
|
+
children: [
|
|
2734
|
+
/* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", children: stem }),
|
|
2735
|
+
extension ? /* @__PURE__ */ jsx("span", { className: "shrink-0", children: extension }) : null
|
|
2736
|
+
]
|
|
2737
|
+
}
|
|
2738
|
+
);
|
|
2739
|
+
}
|
|
2740
|
+
function ObjectListRow({
|
|
2741
|
+
kind,
|
|
2742
|
+
title,
|
|
2743
|
+
description,
|
|
2744
|
+
media,
|
|
2745
|
+
actions,
|
|
2746
|
+
meta,
|
|
2747
|
+
selected,
|
|
2748
|
+
selectable,
|
|
2749
|
+
selectLabel,
|
|
2750
|
+
onSelect,
|
|
2751
|
+
onOpen
|
|
2752
|
+
}) {
|
|
2753
|
+
const described = description != null && description !== false && description !== "";
|
|
2754
|
+
const showMeta = meta != null && meta !== false && meta !== "";
|
|
2755
|
+
const columns = selectable ? actions ? "grid-cols-[auto_minmax(0,1fr)_auto]" : "grid-cols-[auto_minmax(0,1fr)]" : actions ? "grid-cols-[minmax(0,1fr)_auto]" : "grid-cols-[minmax(0,1fr)]";
|
|
2756
|
+
return /* @__PURE__ */ jsxs(
|
|
2757
|
+
"div",
|
|
2758
|
+
{
|
|
2759
|
+
role: "listitem",
|
|
2760
|
+
"data-slot": "object-list-row",
|
|
2761
|
+
"data-kind": kind,
|
|
2762
|
+
"data-selected": selected ? "" : void 0,
|
|
2763
|
+
className: cn(
|
|
2764
|
+
"grid min-h-11 min-w-0 items-center gap-2 overflow-hidden py-1 ps-1.5 pe-1 transition-colors duration-150",
|
|
2765
|
+
columns,
|
|
2766
|
+
selected ? "bg-dimah-s3-primary/10 hover:bg-dimah-s3-primary/15" : "hover:bg-dimah-s3-muted"
|
|
2767
|
+
),
|
|
2768
|
+
children: [
|
|
2769
|
+
selectable && onSelect ? /* @__PURE__ */ jsx(
|
|
2770
|
+
SelectCheckbox,
|
|
2771
|
+
{
|
|
2772
|
+
checked: selected,
|
|
2773
|
+
label: selectLabel,
|
|
2774
|
+
onCheckedChange: onSelect
|
|
2775
|
+
}
|
|
2776
|
+
) : null,
|
|
2777
|
+
/* @__PURE__ */ jsxs(
|
|
2778
|
+
Item,
|
|
2779
|
+
{
|
|
2780
|
+
size: "sm",
|
|
2781
|
+
className: cn(
|
|
2782
|
+
"w-full min-w-0 flex-nowrap overflow-hidden rounded-none bg-transparent p-0 hover:bg-transparent",
|
|
2783
|
+
onOpen && "cursor-pointer self-stretch text-start"
|
|
2784
|
+
),
|
|
2785
|
+
render: onOpen ? /* @__PURE__ */ jsx("button", { type: "button" }) : void 0,
|
|
2786
|
+
onClick: onOpen,
|
|
2787
|
+
children: [
|
|
2788
|
+
/* @__PURE__ */ jsx("span", { className: "shrink-0", children: media }),
|
|
2789
|
+
/* @__PURE__ */ jsxs(
|
|
2790
|
+
ItemContent,
|
|
2791
|
+
{
|
|
2792
|
+
className: cn("min-w-0 gap-0 overflow-hidden", actions && "pe-2"),
|
|
2793
|
+
children: [
|
|
2794
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [
|
|
2795
|
+
/* @__PURE__ */ jsx(ItemTitle, { className: "line-clamp-none block w-full min-w-0 overflow-hidden font-normal", children: /* @__PURE__ */ jsx(NameLabel, { name: title, kind }) }),
|
|
2796
|
+
showMeta ? /* @__PURE__ */ jsx("div", { className: "shrink-0", children: meta }) : null
|
|
2797
|
+
] }),
|
|
2798
|
+
described ? /* @__PURE__ */ jsx(ItemDescription, { className: "min-w-0 truncate text-xs leading-4 text-dimah-s3-muted-foreground", children: description }) : null
|
|
2799
|
+
]
|
|
2800
|
+
}
|
|
2801
|
+
)
|
|
2802
|
+
]
|
|
2803
|
+
}
|
|
2804
|
+
),
|
|
2805
|
+
actions ? /* @__PURE__ */ jsx("div", { className: "shrink-0", children: actions }) : null
|
|
2806
|
+
]
|
|
2807
|
+
}
|
|
2808
|
+
);
|
|
2809
|
+
}
|
|
2810
|
+
function useObjectListSelection({
|
|
2811
|
+
items,
|
|
2812
|
+
folders,
|
|
2813
|
+
filesSelectable,
|
|
2814
|
+
foldersSelectable,
|
|
2815
|
+
getKey,
|
|
2816
|
+
getLabel,
|
|
2817
|
+
getFileName,
|
|
2818
|
+
getObjectKey,
|
|
2819
|
+
resolveFolderKeys,
|
|
2820
|
+
onSelectionChange
|
|
2821
|
+
}) {
|
|
2822
|
+
const [fileKeys, setFileKeys] = useState(/* @__PURE__ */ new Set());
|
|
2823
|
+
const [folderIds, setFolderIds] = useState(/* @__PURE__ */ new Set());
|
|
2824
|
+
const anchorRef = useRef(null);
|
|
2825
|
+
const visibleFileKeys = useMemo(
|
|
2826
|
+
() => filesSelectable ? items.map((item) => getKey(item)) : [],
|
|
2827
|
+
[filesSelectable, getKey, items]
|
|
2828
|
+
);
|
|
2829
|
+
const visibleFolderIds = useMemo(
|
|
2830
|
+
() => foldersSelectable ? folders.map((folder) => folder.id) : [],
|
|
2831
|
+
[folders, foldersSelectable]
|
|
2832
|
+
);
|
|
2833
|
+
const selectedFileKeys = visibleFileKeys.filter((key) => fileKeys.has(key));
|
|
2834
|
+
const selectedFolderIds = visibleFolderIds.filter((id) => folderIds.has(id));
|
|
2835
|
+
const selectedFileKeySig = JSON.stringify(selectedFileKeys);
|
|
2836
|
+
const selectedFolderIdSig = JSON.stringify(selectedFolderIds);
|
|
2837
|
+
const onSelectionChangeRef = useRef(onSelectionChange);
|
|
2838
|
+
const getKeyRef = useRef(getKey);
|
|
2839
|
+
const rowsRef = useRef({ items, folders });
|
|
2840
|
+
const rowsSelectable = filesSelectable || foldersSelectable;
|
|
2841
|
+
const selectedCount = selectedFileKeys.length + selectedFolderIds.length;
|
|
2842
|
+
const visibleCount = visibleFileKeys.length + visibleFolderIds.length;
|
|
2843
|
+
const selecting = rowsSelectable && selectedCount > 0;
|
|
2844
|
+
const snapshotRef = useRef({
|
|
2845
|
+
selecting: false,
|
|
2846
|
+
fileIds: [],
|
|
2847
|
+
folderIds: []
|
|
2848
|
+
});
|
|
2849
|
+
useEffect(() => {
|
|
2850
|
+
snapshotRef.current = {
|
|
2851
|
+
selecting,
|
|
2852
|
+
fileIds: visibleFileKeys,
|
|
2853
|
+
folderIds: visibleFolderIds
|
|
2854
|
+
};
|
|
2855
|
+
}, [selecting, visibleFileKeys, visibleFolderIds]);
|
|
2856
|
+
useEffect(() => {
|
|
2857
|
+
onSelectionChangeRef.current = onSelectionChange;
|
|
2858
|
+
getKeyRef.current = getKey;
|
|
2859
|
+
rowsRef.current = { items, folders };
|
|
2860
|
+
}, [folders, getKey, items, onSelectionChange]);
|
|
2861
|
+
useEffect(() => {
|
|
2862
|
+
const notify = onSelectionChangeRef.current;
|
|
2863
|
+
if (!notify) return;
|
|
2864
|
+
const fileSet = new Set(JSON.parse(selectedFileKeySig));
|
|
2865
|
+
const folderSet = new Set(
|
|
2866
|
+
JSON.parse(selectedFolderIdSig)
|
|
2867
|
+
);
|
|
2868
|
+
const rows = rowsRef.current;
|
|
2869
|
+
notify({
|
|
2870
|
+
items: rows.items.filter((item) => fileSet.has(getKeyRef.current(item))),
|
|
2871
|
+
folders: rows.folders.filter((folder) => folderSet.has(folder.id))
|
|
2872
|
+
});
|
|
2873
|
+
}, [selectedFileKeySig, selectedFolderIdSig]);
|
|
2874
|
+
const selectionRows = [];
|
|
2875
|
+
if (foldersSelectable) {
|
|
2876
|
+
for (const folder of folders) {
|
|
2877
|
+
selectionRows.push({ kind: "folder", id: folder.id });
|
|
2878
|
+
}
|
|
2879
|
+
}
|
|
2880
|
+
if (filesSelectable) {
|
|
2881
|
+
for (const item of items) {
|
|
2882
|
+
selectionRows.push({ kind: "file", id: getKey(item) });
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2885
|
+
function toggleAll(checked) {
|
|
2886
|
+
anchorRef.current = null;
|
|
2887
|
+
setFileKeys(checked ? new Set(visibleFileKeys) : /* @__PURE__ */ new Set());
|
|
2888
|
+
setFolderIds(checked ? new Set(visibleFolderIds) : /* @__PURE__ */ new Set());
|
|
2889
|
+
}
|
|
2890
|
+
function clearSelection() {
|
|
2891
|
+
anchorRef.current = null;
|
|
2892
|
+
setFileKeys(/* @__PURE__ */ new Set());
|
|
2893
|
+
setFolderIds(/* @__PURE__ */ new Set());
|
|
2894
|
+
}
|
|
2895
|
+
function selectAt(index, checked, shift) {
|
|
2896
|
+
const row = selectionRows[index];
|
|
2897
|
+
if (!row) return;
|
|
2898
|
+
if (shift && anchorRef.current != null) {
|
|
2899
|
+
const start = Math.min(anchorRef.current, index);
|
|
2900
|
+
const end = Math.max(anchorRef.current, index);
|
|
2901
|
+
const files = new Set(fileKeys);
|
|
2902
|
+
const nextFolders = new Set(folderIds);
|
|
2903
|
+
for (let cursor = start; cursor <= end; cursor++) {
|
|
2904
|
+
const entry = selectionRows[cursor];
|
|
2905
|
+
if (!entry) continue;
|
|
2906
|
+
if (entry.kind === "file") files.add(entry.id);
|
|
2907
|
+
else nextFolders.add(entry.id);
|
|
2908
|
+
}
|
|
2909
|
+
setFileKeys(files);
|
|
2910
|
+
setFolderIds(nextFolders);
|
|
2911
|
+
return;
|
|
2912
|
+
}
|
|
2913
|
+
if (row.kind === "file") {
|
|
2914
|
+
setFileKeys((current) => replaceMember(current, row.id, checked));
|
|
2915
|
+
} else {
|
|
2916
|
+
setFolderIds((current) => replaceMember(current, row.id, checked));
|
|
2917
|
+
}
|
|
2918
|
+
anchorRef.current = index;
|
|
2919
|
+
}
|
|
2920
|
+
function selectRow(kind, id, checked, shift) {
|
|
2921
|
+
selectAt(
|
|
2922
|
+
selectionRows.findIndex((row) => row.kind === kind && row.id === id),
|
|
2923
|
+
checked,
|
|
2924
|
+
shift
|
|
2925
|
+
);
|
|
2926
|
+
}
|
|
2927
|
+
useEffect(() => {
|
|
2928
|
+
if (!rowsSelectable) return;
|
|
2929
|
+
function onKeyDown(event) {
|
|
2930
|
+
if (event.defaultPrevented) return;
|
|
2931
|
+
if (isFieldTarget(event.target) || isOverlayTarget(event.target)) return;
|
|
2932
|
+
const snapshot = snapshotRef.current;
|
|
2933
|
+
if (event.key === "Escape") {
|
|
2934
|
+
if (!snapshot.selecting) return;
|
|
2935
|
+
event.preventDefault();
|
|
2936
|
+
anchorRef.current = null;
|
|
2937
|
+
setFileKeys(/* @__PURE__ */ new Set());
|
|
2938
|
+
setFolderIds(/* @__PURE__ */ new Set());
|
|
2939
|
+
return;
|
|
2940
|
+
}
|
|
2941
|
+
if (event.code !== "KeyA") return;
|
|
2942
|
+
if (!(event.ctrlKey || event.metaKey) || event.altKey || event.shiftKey) {
|
|
2943
|
+
return;
|
|
2944
|
+
}
|
|
2945
|
+
if (!(event.target instanceof Element)) return;
|
|
2946
|
+
if (!event.target.closest("[data-slot=object-list]")) return;
|
|
2947
|
+
if (snapshot.fileIds.length + snapshot.folderIds.length === 0) return;
|
|
2948
|
+
event.preventDefault();
|
|
2949
|
+
anchorRef.current = null;
|
|
2950
|
+
setFileKeys(new Set(snapshot.fileIds));
|
|
2951
|
+
setFolderIds(new Set(snapshot.folderIds));
|
|
2952
|
+
}
|
|
2953
|
+
document.addEventListener("keydown", onKeyDown);
|
|
2954
|
+
return () => document.removeEventListener("keydown", onKeyDown);
|
|
2955
|
+
}, [rowsSelectable]);
|
|
2956
|
+
async function prepareSelection() {
|
|
2957
|
+
const entries = [];
|
|
2958
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2959
|
+
function add(key, fileName) {
|
|
2960
|
+
if (seen.has(key)) return;
|
|
2961
|
+
seen.add(key);
|
|
2962
|
+
entries.push({ key, fileName });
|
|
2963
|
+
}
|
|
2964
|
+
const objectKeyOf = getObjectKey ?? getKey;
|
|
2965
|
+
for (const item of items) {
|
|
2966
|
+
if (!fileKeys.has(getKey(item))) continue;
|
|
2967
|
+
add(objectKeyOf(item), getFileName?.(item) ?? getLabel(item));
|
|
2968
|
+
}
|
|
2969
|
+
let skippedFolders = 0;
|
|
2970
|
+
for (const folder of folders) {
|
|
2971
|
+
if (!folderIds.has(folder.id)) continue;
|
|
2972
|
+
if (!resolveFolderKeys) {
|
|
2973
|
+
skippedFolders += 1;
|
|
2974
|
+
continue;
|
|
2975
|
+
}
|
|
2976
|
+
for (const key of await resolveFolderKeys(folder)) {
|
|
2977
|
+
add(key, fileNameFromKey(key));
|
|
2978
|
+
}
|
|
2979
|
+
}
|
|
2980
|
+
return { entries, skippedFolders };
|
|
2981
|
+
}
|
|
2982
|
+
return {
|
|
2983
|
+
fileKeys,
|
|
2984
|
+
folderIds,
|
|
2985
|
+
selectedCount,
|
|
2986
|
+
allSelected: visibleCount > 0 && selectedCount === visibleCount,
|
|
2987
|
+
selecting,
|
|
2988
|
+
rowsSelectable,
|
|
2989
|
+
toggleAll,
|
|
2990
|
+
clearSelection,
|
|
2991
|
+
selectRow,
|
|
2992
|
+
prepareSelection
|
|
2993
|
+
};
|
|
2994
|
+
}
|
|
2995
|
+
function isFieldTarget(target) {
|
|
2996
|
+
return target instanceof HTMLElement && (target.isContentEditable || target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.tagName === "SELECT");
|
|
2997
|
+
}
|
|
2998
|
+
function isOverlayTarget(target) {
|
|
2999
|
+
return target instanceof Element && Boolean(
|
|
3000
|
+
target.closest(
|
|
3001
|
+
"[role=dialog], [role=alertdialog], [role=menu], [data-slot=dropdown-menu-content], [data-slot=alert-dialog-content]"
|
|
3002
|
+
)
|
|
3003
|
+
);
|
|
3004
|
+
}
|
|
3005
|
+
function replaceMember(current, id, checked) {
|
|
3006
|
+
const next = new Set(current);
|
|
3007
|
+
if (checked) next.add(id);
|
|
3008
|
+
else next.delete(id);
|
|
3009
|
+
return next;
|
|
3010
|
+
}
|
|
3011
|
+
function ObjectListSelection({
|
|
3012
|
+
leading,
|
|
3013
|
+
selectedCount,
|
|
3014
|
+
onClear,
|
|
3015
|
+
prepare,
|
|
3016
|
+
removeMany,
|
|
3017
|
+
actions,
|
|
3018
|
+
onThisPage = false,
|
|
3019
|
+
onDeleted
|
|
3020
|
+
}) {
|
|
3021
|
+
const t = useTranslations();
|
|
3022
|
+
const formatNumber = useFormatNumber();
|
|
3023
|
+
const [phase, setPhase] = useState(
|
|
3024
|
+
"idle"
|
|
3025
|
+
);
|
|
3026
|
+
const [planned, setPlanned] = useState(null);
|
|
3027
|
+
const [note, setNote] = useState(
|
|
3028
|
+
null
|
|
3029
|
+
);
|
|
3030
|
+
const visibleNote = note?.count === selectedCount ? note.text : null;
|
|
3031
|
+
const deletingRef = useRef(false);
|
|
3032
|
+
const mountedRef = useRef(true);
|
|
3033
|
+
const busy = phase === "prepare" || phase === "delete";
|
|
3034
|
+
useEffect(() => {
|
|
3035
|
+
mountedRef.current = true;
|
|
3036
|
+
return () => {
|
|
3037
|
+
mountedRef.current = false;
|
|
3038
|
+
};
|
|
3039
|
+
}, []);
|
|
3040
|
+
function showNote(text) {
|
|
3041
|
+
setNote(text === null ? null : { count: selectedCount, text });
|
|
3042
|
+
}
|
|
3043
|
+
function setPhaseIfMounted(next) {
|
|
3044
|
+
if (mountedRef.current) setPhase(next);
|
|
3045
|
+
}
|
|
3046
|
+
async function requestDelete() {
|
|
3047
|
+
if (!removeMany || busy) return;
|
|
3048
|
+
showNote(null);
|
|
3049
|
+
setPhase("prepare");
|
|
3050
|
+
try {
|
|
3051
|
+
const next = await prepare();
|
|
3052
|
+
if (!mountedRef.current) return;
|
|
3053
|
+
if (next.entries.length === 0) {
|
|
3054
|
+
showNote(
|
|
3055
|
+
next.skippedFolders > 0 ? t("Selected folders stay in the list.", {
|
|
3056
|
+
note: "object list selection"
|
|
3057
|
+
}) : t("Nothing to delete", { note: "object list selection" })
|
|
3058
|
+
);
|
|
3059
|
+
setPhase("idle");
|
|
3060
|
+
return;
|
|
3061
|
+
}
|
|
3062
|
+
setPlanned(next);
|
|
3063
|
+
setPhase("confirm");
|
|
3064
|
+
} catch {
|
|
3065
|
+
if (!mountedRef.current) return;
|
|
3066
|
+
showNote(
|
|
3067
|
+
t("Could not delete the selection", {
|
|
3068
|
+
note: "object list selection"
|
|
3069
|
+
})
|
|
3070
|
+
);
|
|
3071
|
+
setPhase("idle");
|
|
3072
|
+
}
|
|
3073
|
+
}
|
|
3074
|
+
async function confirmDelete() {
|
|
3075
|
+
const current = planned;
|
|
3076
|
+
if (!current || !removeMany || deletingRef.current) return;
|
|
3077
|
+
deletingRef.current = true;
|
|
3078
|
+
setPhase("delete");
|
|
3079
|
+
const deleted = [];
|
|
3080
|
+
const failed = [];
|
|
3081
|
+
try {
|
|
3082
|
+
const keys = current.entries.map((entry) => entry.key);
|
|
3083
|
+
for (let index = 0; index < keys.length; index += DELETE_BATCH_MAX_KEYS) {
|
|
3084
|
+
const chunk = keys.slice(index, index + DELETE_BATCH_MAX_KEYS);
|
|
3085
|
+
const result = await removeMany(chunk);
|
|
3086
|
+
deleted.push(...result.deleted);
|
|
3087
|
+
failed.push(...result.failed);
|
|
3088
|
+
}
|
|
3089
|
+
} finally {
|
|
3090
|
+
deletingRef.current = false;
|
|
3091
|
+
setPhaseIfMounted("idle");
|
|
3092
|
+
}
|
|
3093
|
+
if (deleted.length > 0) {
|
|
3094
|
+
toast.add({
|
|
3095
|
+
type: "success",
|
|
3096
|
+
title: t("Deleted {count} files", {
|
|
3097
|
+
note: "object list selection",
|
|
3098
|
+
variables: { count: formatNumber(deleted.length) }
|
|
3099
|
+
})
|
|
3100
|
+
});
|
|
3101
|
+
}
|
|
3102
|
+
if (failed.length > 0) {
|
|
3103
|
+
toast.add({
|
|
3104
|
+
type: "error",
|
|
3105
|
+
title: t("Could not delete {count} files", {
|
|
3106
|
+
note: "object list selection",
|
|
3107
|
+
variables: { count: formatNumber(failed.length) }
|
|
3108
|
+
})
|
|
3109
|
+
});
|
|
3110
|
+
}
|
|
3111
|
+
onDeleted?.({ deleted, failed });
|
|
3112
|
+
}
|
|
3113
|
+
if (selectedCount === 0) return null;
|
|
3114
|
+
const deleteLabel = t("Delete", { note: "button" });
|
|
3115
|
+
const clearLabel = t("Clear", { note: "object list selection" });
|
|
3116
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3117
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-h-11 min-w-0 items-center gap-2 py-1.5 ps-1.5 pe-1", children: [
|
|
3118
|
+
leading,
|
|
3119
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 items-center justify-between gap-2", children: [
|
|
3120
|
+
/* @__PURE__ */ jsxs(
|
|
3121
|
+
"p",
|
|
3122
|
+
{
|
|
3123
|
+
"aria-live": "polite",
|
|
3124
|
+
className: "min-w-0 flex-1 truncate text-sm text-dimah-s3-foreground",
|
|
3125
|
+
children: [
|
|
3126
|
+
/* @__PURE__ */ jsx("span", { className: "font-medium tabular-nums", children: onThisPage ? t("{count} selected on this page", {
|
|
3127
|
+
note: "object list selection",
|
|
3128
|
+
variables: { count: formatNumber(selectedCount) }
|
|
3129
|
+
}) : t("{count} selected", {
|
|
3130
|
+
note: "object list selection",
|
|
3131
|
+
variables: { count: formatNumber(selectedCount) }
|
|
3132
|
+
}) }),
|
|
3133
|
+
visibleNote ? /* @__PURE__ */ jsx("span", { className: "ms-2 font-normal text-dimah-s3-muted-foreground", children: visibleNote }) : null
|
|
3134
|
+
]
|
|
3135
|
+
}
|
|
3136
|
+
),
|
|
3137
|
+
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [
|
|
3138
|
+
actions ? /* @__PURE__ */ jsx(
|
|
3139
|
+
"div",
|
|
3140
|
+
{
|
|
3141
|
+
className: cn(
|
|
3142
|
+
"flex items-center gap-1",
|
|
3143
|
+
busy && "pointer-events-none opacity-60"
|
|
3144
|
+
),
|
|
3145
|
+
children: actions
|
|
3146
|
+
}
|
|
3147
|
+
) : null,
|
|
3148
|
+
removeMany ? /* @__PURE__ */ jsxs(
|
|
3149
|
+
Button,
|
|
3150
|
+
{
|
|
3151
|
+
variant: "destructive",
|
|
3152
|
+
size: "sm",
|
|
3153
|
+
"aria-label": deleteLabel,
|
|
3154
|
+
disabled: busy,
|
|
3155
|
+
onClick: () => {
|
|
3156
|
+
void requestDelete();
|
|
3157
|
+
},
|
|
3158
|
+
children: [
|
|
3159
|
+
phase === "prepare" || phase === "delete" ? /* @__PURE__ */ jsx(Spinner, { "data-icon": "inline-start" }) : /* @__PURE__ */ jsx(Trash2Icon, { "data-icon": "inline-start" }),
|
|
3160
|
+
/* @__PURE__ */ jsx("span", { className: "max-sm:sr-only", children: deleteLabel })
|
|
3161
|
+
]
|
|
3162
|
+
}
|
|
3163
|
+
) : null,
|
|
3164
|
+
/* @__PURE__ */ jsx(Button, { variant: "ghost", size: "sm", disabled: busy, onClick: onClear, children: clearLabel })
|
|
3165
|
+
] })
|
|
3166
|
+
] })
|
|
3167
|
+
] }),
|
|
3168
|
+
/* @__PURE__ */ jsx(
|
|
3169
|
+
AlertDialog,
|
|
3170
|
+
{
|
|
3171
|
+
open: phase === "confirm" && planned != null,
|
|
3172
|
+
onOpenChange: (open) => {
|
|
3173
|
+
if (!open && !deletingRef.current) setPhase("idle");
|
|
3174
|
+
},
|
|
3175
|
+
children: /* @__PURE__ */ jsxs(AlertDialogContent, { children: [
|
|
3176
|
+
/* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
|
|
3177
|
+
/* @__PURE__ */ jsx(AlertDialogTitle, { children: t("Delete {count} files?", {
|
|
3178
|
+
note: "object list selection",
|
|
3179
|
+
variables: {
|
|
3180
|
+
count: formatNumber(planned?.entries.length ?? 0)
|
|
3181
|
+
}
|
|
3182
|
+
}) }),
|
|
3183
|
+
/* @__PURE__ */ jsxs(AlertDialogDescription, { children: [
|
|
3184
|
+
t("This action cannot be undone.", {
|
|
3185
|
+
note: "object list selection"
|
|
3186
|
+
}),
|
|
3187
|
+
planned && planned.skippedFolders > 0 ? ` ${t("Selected folders stay in the list.", { note: "object list selection" })}` : null
|
|
3188
|
+
] })
|
|
3189
|
+
] }),
|
|
3190
|
+
/* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
|
|
3191
|
+
/* @__PURE__ */ jsx(AlertDialogCancel, { children: t("Cancel", { note: "dialog button" }) }),
|
|
3192
|
+
/* @__PURE__ */ jsx(
|
|
3193
|
+
AlertDialogAction,
|
|
3194
|
+
{
|
|
3195
|
+
variant: "destructive",
|
|
3196
|
+
onClick: () => {
|
|
3197
|
+
void confirmDelete();
|
|
3198
|
+
},
|
|
3199
|
+
children: t("Delete", { note: "dialog confirm" })
|
|
3200
|
+
}
|
|
3201
|
+
)
|
|
3202
|
+
] })
|
|
3203
|
+
] })
|
|
3204
|
+
}
|
|
3205
|
+
)
|
|
3206
|
+
] });
|
|
3207
|
+
}
|
|
3208
|
+
function Empty({ className, ...props }) {
|
|
3209
|
+
return /* @__PURE__ */ jsx(
|
|
3210
|
+
"div",
|
|
3211
|
+
{
|
|
3212
|
+
"data-slot": "empty",
|
|
3213
|
+
className: cn(
|
|
3214
|
+
"flex w-full min-w-0 flex-1 flex-col items-center justify-center gap-4 rounded-xl border-dashed p-6 text-center text-balance",
|
|
3215
|
+
className
|
|
3216
|
+
),
|
|
3217
|
+
...props
|
|
3218
|
+
}
|
|
3219
|
+
);
|
|
3220
|
+
}
|
|
3221
|
+
function EmptyHeader({ className, ...props }) {
|
|
3222
|
+
return /* @__PURE__ */ jsx(
|
|
3223
|
+
"div",
|
|
3224
|
+
{
|
|
3225
|
+
"data-slot": "empty-header",
|
|
3226
|
+
className: cn("flex max-w-sm flex-col items-center gap-2", className),
|
|
3227
|
+
...props
|
|
3228
|
+
}
|
|
3229
|
+
);
|
|
3230
|
+
}
|
|
3231
|
+
var emptyMediaVariants = cva(
|
|
3232
|
+
"mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
|
|
3233
|
+
{
|
|
3234
|
+
variants: {
|
|
3235
|
+
variant: {
|
|
3236
|
+
default: "bg-transparent",
|
|
3237
|
+
icon: "flex size-8 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground [&_svg:not([class*='size-'])]:size-4"
|
|
3238
|
+
}
|
|
3239
|
+
},
|
|
3240
|
+
defaultVariants: {
|
|
3241
|
+
variant: "default"
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3244
|
+
);
|
|
3245
|
+
function EmptyMedia({
|
|
3246
|
+
className,
|
|
3247
|
+
variant = "default",
|
|
3248
|
+
...props
|
|
3249
|
+
}) {
|
|
3250
|
+
return /* @__PURE__ */ jsx(
|
|
3251
|
+
"div",
|
|
3252
|
+
{
|
|
3253
|
+
"data-slot": "empty-icon",
|
|
3254
|
+
"data-variant": variant,
|
|
3255
|
+
className: cn(emptyMediaVariants({ variant, className })),
|
|
3256
|
+
...props
|
|
3257
|
+
}
|
|
3258
|
+
);
|
|
3259
|
+
}
|
|
3260
|
+
function EmptyTitle({ className, ...props }) {
|
|
3261
|
+
return /* @__PURE__ */ jsx(
|
|
3262
|
+
"div",
|
|
3263
|
+
{
|
|
3264
|
+
"data-slot": "empty-title",
|
|
3265
|
+
className: cn(
|
|
3266
|
+
"cn-font-heading text-sm font-medium tracking-tight",
|
|
3267
|
+
className
|
|
3268
|
+
),
|
|
3269
|
+
...props
|
|
3270
|
+
}
|
|
3271
|
+
);
|
|
3272
|
+
}
|
|
3273
|
+
function EmptyDescription({ className, ...props }) {
|
|
3274
|
+
return /* @__PURE__ */ jsx(
|
|
3275
|
+
"div",
|
|
3276
|
+
{
|
|
3277
|
+
"data-slot": "empty-description",
|
|
3278
|
+
className: cn(
|
|
3279
|
+
"text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary",
|
|
3280
|
+
className
|
|
3281
|
+
),
|
|
3282
|
+
...props
|
|
3283
|
+
}
|
|
3284
|
+
);
|
|
3285
|
+
}
|
|
3286
|
+
function EmptyContent({ className, ...props }) {
|
|
3287
|
+
return /* @__PURE__ */ jsx(
|
|
3288
|
+
"div",
|
|
3289
|
+
{
|
|
3290
|
+
"data-slot": "empty-content",
|
|
3291
|
+
className: cn(
|
|
3292
|
+
"flex w-full max-w-sm min-w-0 flex-col items-center gap-2.5 text-sm text-balance",
|
|
3293
|
+
className
|
|
3294
|
+
),
|
|
3295
|
+
...props
|
|
3296
|
+
}
|
|
3297
|
+
);
|
|
3298
|
+
}
|
|
3299
|
+
function Skeleton({ className, ...props }) {
|
|
3300
|
+
return /* @__PURE__ */ jsx(
|
|
3301
|
+
"div",
|
|
3302
|
+
{
|
|
3303
|
+
"data-slot": "skeleton",
|
|
3304
|
+
className: cn("animate-pulse rounded-md bg-muted", className),
|
|
3305
|
+
...props
|
|
3306
|
+
}
|
|
3307
|
+
);
|
|
3308
|
+
}
|
|
3309
|
+
function ObjectListEmpty({
|
|
3310
|
+
title,
|
|
3311
|
+
description
|
|
3312
|
+
}) {
|
|
3313
|
+
return /* @__PURE__ */ jsx(Empty, { className: "border-0", children: /* @__PURE__ */ jsxs(EmptyHeader, { children: [
|
|
3314
|
+
/* @__PURE__ */ jsx(FolderGlyph, { className: "mb-1 size-12" }),
|
|
3315
|
+
/* @__PURE__ */ jsx(EmptyTitle, { children: title }),
|
|
3316
|
+
/* @__PURE__ */ jsx(EmptyDescription, { children: description })
|
|
3317
|
+
] }) });
|
|
3318
|
+
}
|
|
3319
|
+
function ObjectListError({
|
|
3320
|
+
message,
|
|
3321
|
+
onRetry
|
|
3322
|
+
}) {
|
|
3323
|
+
const t = useTranslations();
|
|
3324
|
+
return /* @__PURE__ */ jsxs(Empty, { className: "border-0", children: [
|
|
3325
|
+
/* @__PURE__ */ jsxs(EmptyHeader, { children: [
|
|
3326
|
+
/* @__PURE__ */ jsx(EmptyMedia, { variant: "icon", children: /* @__PURE__ */ jsx(AlertCircleIcon, {}) }),
|
|
3327
|
+
/* @__PURE__ */ jsx(EmptyTitle, { children: t("Could not load files", { note: "object list" }) }),
|
|
3328
|
+
message ? /* @__PURE__ */ jsx(EmptyDescription, { className: "[overflow-wrap:anywhere]", children: message }) : null
|
|
3329
|
+
] }),
|
|
3330
|
+
onRetry ? /* @__PURE__ */ jsx(EmptyContent, { children: /* @__PURE__ */ jsx(ObjectListRetry, { onRetry }) }) : null
|
|
3331
|
+
] });
|
|
3332
|
+
}
|
|
3333
|
+
function ObjectListErrorBanner({
|
|
3334
|
+
message,
|
|
3335
|
+
onRetry
|
|
3336
|
+
}) {
|
|
3337
|
+
return /* @__PURE__ */ jsxs(
|
|
3338
|
+
"div",
|
|
3339
|
+
{
|
|
3340
|
+
role: "alert",
|
|
3341
|
+
className: "flex items-center justify-between gap-3 border-t border-dimah-s3-border px-3 py-2",
|
|
3342
|
+
children: [
|
|
3343
|
+
/* @__PURE__ */ jsx("p", { className: "min-w-0 text-sm [overflow-wrap:anywhere] text-dimah-s3-destructive", children: message }),
|
|
3344
|
+
/* @__PURE__ */ jsx(ObjectListRetry, { onRetry })
|
|
3345
|
+
]
|
|
3346
|
+
}
|
|
3347
|
+
);
|
|
3348
|
+
}
|
|
3349
|
+
function ObjectListRetry({
|
|
3350
|
+
onRetry
|
|
3351
|
+
}) {
|
|
3352
|
+
const t = useTranslations();
|
|
3353
|
+
if (!onRetry) return null;
|
|
3354
|
+
return /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void onRetry(), children: t("Retry", { note: "object list" }) });
|
|
3355
|
+
}
|
|
3356
|
+
function ObjectListSkeleton() {
|
|
3357
|
+
return /* @__PURE__ */ jsx("div", { className: "flex flex-col", children: ["a", "b", "c", "d"].map((key) => /* @__PURE__ */ jsxs(
|
|
3358
|
+
"div",
|
|
3359
|
+
{
|
|
3360
|
+
className: "flex min-h-11 items-center gap-2 py-1 ps-1.5 pe-1",
|
|
3361
|
+
children: [
|
|
3362
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "size-8 rounded-sm" }),
|
|
3363
|
+
/* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
|
|
3364
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-3.5 w-40 max-w-full" }),
|
|
3365
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-16 max-w-full" })
|
|
3366
|
+
] })
|
|
3367
|
+
]
|
|
3368
|
+
},
|
|
3369
|
+
key
|
|
3370
|
+
)) });
|
|
3371
|
+
}
|
|
3372
|
+
function ObjectListContinue({
|
|
3373
|
+
active,
|
|
3374
|
+
pending,
|
|
3375
|
+
blocked,
|
|
3376
|
+
loadMore,
|
|
3377
|
+
root,
|
|
3378
|
+
ready
|
|
3379
|
+
}) {
|
|
3380
|
+
const t = useTranslations();
|
|
3381
|
+
const sentinelRef = useRef(null);
|
|
3382
|
+
const loadMoreRef = useRef(loadMore);
|
|
3383
|
+
useEffect(() => {
|
|
3384
|
+
loadMoreRef.current = loadMore;
|
|
3385
|
+
}, [loadMore]);
|
|
3386
|
+
useEffect(() => {
|
|
3387
|
+
const node = sentinelRef.current;
|
|
3388
|
+
if (!node || !ready || !active || pending || blocked) return;
|
|
3389
|
+
const observer = new IntersectionObserver(
|
|
3390
|
+
(entries) => {
|
|
3391
|
+
if (!entries.some((entry) => entry.isIntersecting)) return;
|
|
3392
|
+
void loadMoreRef.current?.();
|
|
3393
|
+
},
|
|
3394
|
+
{ root, rootMargin: "48px" }
|
|
3395
|
+
);
|
|
3396
|
+
observer.observe(node);
|
|
3397
|
+
return () => observer.disconnect();
|
|
3398
|
+
}, [active, blocked, pending, ready, root]);
|
|
3399
|
+
if (!active && !pending) return null;
|
|
3400
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 flex-col", children: [
|
|
3401
|
+
pending ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-2", children: /* @__PURE__ */ jsx(Spinner, { "aria-label": t("Loading files", { note: "object list" }) }) }) : null,
|
|
3402
|
+
active ? /* @__PURE__ */ jsx("div", { ref: sentinelRef, "aria-hidden": true, className: "h-px w-full shrink-0" }) : null
|
|
3403
|
+
] });
|
|
3404
|
+
}
|
|
3405
|
+
function useRefreshListAfterUpload(upload, refresh) {
|
|
3406
|
+
const tokenRef = useRef(null);
|
|
3407
|
+
const refreshRef = useRef(refresh);
|
|
3408
|
+
const successIds = upload?.files.filter((file) => file.status === "success").map((file) => file.id).join("\0") ?? "";
|
|
3409
|
+
const settled = upload != null && !upload.isPending && upload.phase !== "idle";
|
|
3410
|
+
useEffect(() => {
|
|
3411
|
+
refreshRef.current = refresh;
|
|
3412
|
+
}, [refresh]);
|
|
3413
|
+
useEffect(() => {
|
|
3414
|
+
if (!settled) {
|
|
3415
|
+
tokenRef.current = null;
|
|
3416
|
+
return;
|
|
3417
|
+
}
|
|
3418
|
+
if (!successIds) return;
|
|
3419
|
+
if (tokenRef.current === successIds) return;
|
|
3420
|
+
tokenRef.current = successIds;
|
|
3421
|
+
void refreshRef.current?.();
|
|
3422
|
+
}, [settled, successIds]);
|
|
3423
|
+
}
|
|
3424
|
+
function ObjectListUpload({ upload }) {
|
|
3425
|
+
const { statusNode } = useUploadUi(upload);
|
|
3426
|
+
if (upload.phase === "idle" || upload.phase === "success") return null;
|
|
3427
|
+
return /* @__PURE__ */ jsx("div", { className: "border-b border-dimah-s3-border px-3 py-2", children: statusNode });
|
|
3428
|
+
}
|
|
3429
|
+
function ObjectListDropOverlay({ upload }) {
|
|
3430
|
+
const t = useTranslations();
|
|
3431
|
+
const dropLabel = upload.isDragReject ? t("These files cannot be uploaded", { note: "object list" }) : t("Drop to upload into this folder", { note: "object list" });
|
|
3432
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3433
|
+
upload.isDragActive ? /* @__PURE__ */ jsx(
|
|
3434
|
+
"div",
|
|
3435
|
+
{
|
|
3436
|
+
"aria-hidden": true,
|
|
3437
|
+
className: "pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-dimah-s3-card/80 p-6",
|
|
3438
|
+
children: /* @__PURE__ */ jsx(
|
|
3439
|
+
"p",
|
|
3440
|
+
{
|
|
3441
|
+
className: cn(
|
|
3442
|
+
"rounded-md border border-dashed px-3 py-2 text-sm",
|
|
3443
|
+
upload.isDragReject ? "border-dimah-s3-destructive text-dimah-s3-destructive" : "border-dimah-s3-primary text-dimah-s3-primary"
|
|
3444
|
+
),
|
|
3445
|
+
children: dropLabel
|
|
3446
|
+
}
|
|
3447
|
+
)
|
|
3448
|
+
}
|
|
3449
|
+
) : null,
|
|
3450
|
+
/* @__PURE__ */ jsx("div", { className: "sr-only", "aria-live": "polite", children: upload.isDragActive ? dropLabel : "" })
|
|
3451
|
+
] });
|
|
3452
|
+
}
|
|
3453
|
+
function ObjectListUsageLine({
|
|
3454
|
+
usage,
|
|
3455
|
+
limits
|
|
3456
|
+
}) {
|
|
3457
|
+
const t = useTranslations();
|
|
3458
|
+
const formatFileSize = useFormatFileSize();
|
|
3459
|
+
const formatNumber = useFormatNumber();
|
|
3460
|
+
const byteCap = finiteCap(limits?.maxBytes);
|
|
3461
|
+
const fileCap = finiteCap(limits?.maxFiles);
|
|
3462
|
+
const bytesLabel = byteCap == null ? formatFileSize(usage.totalBytes) : t("{used} of {max}", {
|
|
3463
|
+
note: "object list usage",
|
|
3464
|
+
variables: {
|
|
3465
|
+
used: formatFileSize(usage.totalBytes),
|
|
3466
|
+
max: formatFileSize(byteCap)
|
|
3467
|
+
}
|
|
3468
|
+
});
|
|
3469
|
+
const filesLabel = fileCap == null ? usage.objectCount === 1 ? t("1 file", { note: "object list usage" }) : t("{count} files", {
|
|
3470
|
+
note: "object list usage",
|
|
3471
|
+
variables: { count: formatNumber(usage.objectCount) }
|
|
3472
|
+
}) : t("{count} of {max} files", {
|
|
3473
|
+
note: "object list usage",
|
|
3474
|
+
variables: {
|
|
3475
|
+
count: formatNumber(usage.objectCount),
|
|
3476
|
+
max: formatNumber(fileCap)
|
|
3477
|
+
}
|
|
3478
|
+
});
|
|
3479
|
+
const byteRatio = fillRatio(usage.totalBytes, byteCap);
|
|
3480
|
+
const fileRatio = fillRatio(usage.objectCount, fileCap);
|
|
3481
|
+
const tightest = tightestRatio(byteRatio, fileRatio);
|
|
3482
|
+
const over = tightest != null && tightest >= 1;
|
|
3483
|
+
const percent = tightest == null ? null : Math.min(100, Math.round(tightest * 100));
|
|
3484
|
+
return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 border-b border-dimah-s3-border px-3 py-2", children: [
|
|
3485
|
+
/* @__PURE__ */ jsxs(
|
|
3486
|
+
"p",
|
|
3487
|
+
{
|
|
3488
|
+
className: cn(
|
|
3489
|
+
"text-xs tabular-nums",
|
|
3490
|
+
over ? "text-dimah-s3-destructive" : "text-dimah-s3-muted-foreground"
|
|
3491
|
+
),
|
|
3492
|
+
children: [
|
|
3493
|
+
bytesLabel,
|
|
3494
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": true, children: " \xB7 " }),
|
|
3495
|
+
filesLabel
|
|
3496
|
+
]
|
|
3497
|
+
}
|
|
3498
|
+
),
|
|
3499
|
+
percent != null ? /* @__PURE__ */ jsx(
|
|
3500
|
+
"div",
|
|
3501
|
+
{
|
|
3502
|
+
className: "flex h-1 overflow-hidden rounded-full bg-dimah-s3-muted",
|
|
3503
|
+
"aria-hidden": true,
|
|
3504
|
+
children: /* @__PURE__ */ jsx(
|
|
3505
|
+
"div",
|
|
3506
|
+
{
|
|
3507
|
+
className: cn(
|
|
3508
|
+
"h-full",
|
|
3509
|
+
over ? "bg-dimah-s3-destructive" : "bg-dimah-s3-primary"
|
|
3510
|
+
),
|
|
3511
|
+
style: { width: `${percent}%` }
|
|
3512
|
+
}
|
|
3513
|
+
)
|
|
3514
|
+
}
|
|
3515
|
+
) : null
|
|
3516
|
+
] });
|
|
3517
|
+
}
|
|
3518
|
+
function finiteCap(value) {
|
|
3519
|
+
if (value == null || !Number.isFinite(value) || value < 0) return null;
|
|
3520
|
+
return value;
|
|
3521
|
+
}
|
|
3522
|
+
function fillRatio(used, max) {
|
|
3523
|
+
if (max == null) return null;
|
|
3524
|
+
if (max === 0) return used > 0 ? 1 : 0;
|
|
3525
|
+
return used / max;
|
|
3526
|
+
}
|
|
3527
|
+
function tightestRatio(byteRatio, fileRatio) {
|
|
3528
|
+
if (byteRatio == null) return fileRatio;
|
|
3529
|
+
if (fileRatio == null) return byteRatio;
|
|
3530
|
+
return Math.max(byteRatio, fileRatio);
|
|
3531
|
+
}
|
|
3532
|
+
function ObjectList(props) {
|
|
3533
|
+
useRefreshListAfterUpload(props.upload, props.list.refresh);
|
|
3534
|
+
return /* @__PURE__ */ jsx(ObjectListFrame, { ...props }, props.list.parent ?? "");
|
|
3535
|
+
}
|
|
3536
|
+
function ObjectListFrame({
|
|
3537
|
+
list,
|
|
3538
|
+
getKey,
|
|
3539
|
+
getLabel,
|
|
3540
|
+
getDescription,
|
|
3541
|
+
getFileName,
|
|
3542
|
+
getFileType,
|
|
3543
|
+
getPreviewUrl,
|
|
3544
|
+
renderItem,
|
|
3545
|
+
renderFolder,
|
|
3546
|
+
renderActions,
|
|
3547
|
+
renderMeta,
|
|
3548
|
+
onOpenItem,
|
|
3549
|
+
renderFolderActions,
|
|
3550
|
+
header,
|
|
3551
|
+
rootLabel,
|
|
3552
|
+
breadcrumb = true,
|
|
3553
|
+
emptyTitle,
|
|
3554
|
+
emptyDescription,
|
|
3555
|
+
empty,
|
|
3556
|
+
className,
|
|
3557
|
+
height,
|
|
3558
|
+
maxHeight,
|
|
3559
|
+
selectable = false,
|
|
3560
|
+
getObjectKey,
|
|
3561
|
+
resolveFolderKeys,
|
|
3562
|
+
delete: remove,
|
|
3563
|
+
onSelectionChange,
|
|
3564
|
+
selectionActions,
|
|
3565
|
+
onDeleted,
|
|
3566
|
+
upload,
|
|
3567
|
+
usageLimits
|
|
3568
|
+
}) {
|
|
3569
|
+
const t = useTranslations();
|
|
3570
|
+
const formatError = useFormatDimahError();
|
|
3571
|
+
const folders = useMemo(() => list.folders ?? [], [list.folders]);
|
|
3572
|
+
const trail = list.trail ?? [];
|
|
3573
|
+
const isLoading = list.isLoading === true;
|
|
3574
|
+
const isRefreshing = list.isRefreshing === true;
|
|
3575
|
+
const label = rootLabel ?? t("Files", { note: "object list" });
|
|
3576
|
+
const errorMessage = list.error ? formatError(list.error) : null;
|
|
3577
|
+
const showRows = folders.length > 0 || list.items.length > 0;
|
|
3578
|
+
const showEmpty = !isLoading && !list.error && !showRows;
|
|
3579
|
+
const showInitialError = !isLoading && list.error != null && !showRows;
|
|
3580
|
+
const canSelect = selectable || remove != null || selectionActions != null || onSelectionChange != null;
|
|
3581
|
+
const filesSelectable = canSelect && renderItem == null;
|
|
3582
|
+
const foldersSelectable = canSelect && resolveFolderKeys != null && renderFolder == null;
|
|
3583
|
+
const selection = useObjectListSelection({
|
|
3584
|
+
items: list.items,
|
|
3585
|
+
folders,
|
|
3586
|
+
filesSelectable,
|
|
3587
|
+
foldersSelectable,
|
|
3588
|
+
getKey,
|
|
3589
|
+
getLabel,
|
|
3590
|
+
getFileName,
|
|
3591
|
+
getObjectKey,
|
|
3592
|
+
resolveFolderKeys,
|
|
3593
|
+
onSelectionChange
|
|
3594
|
+
});
|
|
3595
|
+
const [scroller, setScroller] = useState(null);
|
|
3596
|
+
const showHeader = breadcrumb || header != null || isRefreshing || selection.rowsSelectable && showRows;
|
|
3597
|
+
const pageLimited = list.hasMore === true;
|
|
3598
|
+
const busy = isLoading || isRefreshing || list.isLoadingMore === true;
|
|
3599
|
+
const frameHeight = cssLength(height);
|
|
3600
|
+
const frameMaxHeight = cssLength(maxHeight);
|
|
3601
|
+
const sized = frameHeight != null || frameMaxHeight != null;
|
|
3602
|
+
const frameStyle = sized ? {
|
|
3603
|
+
...frameHeight != null ? { height: frameHeight } : {},
|
|
3604
|
+
...frameMaxHeight != null ? { maxHeight: frameMaxHeight } : {}
|
|
3605
|
+
} : void 0;
|
|
3606
|
+
const frameClassName = cn(
|
|
3607
|
+
"relative flex w-full min-w-0 flex-col overflow-hidden rounded-xl border border-dimah-s3-border bg-dimah-s3-card text-dimah-s3-card-foreground transition-colors",
|
|
3608
|
+
sized && "min-h-0",
|
|
3609
|
+
upload?.isDragReject && "border-dimah-s3-destructive bg-dimah-s3-destructive/5",
|
|
3610
|
+
upload?.isDragAccept && "border-dimah-s3-primary bg-dimah-s3-primary/5",
|
|
3611
|
+
upload?.isDragActive && !upload.isDragAccept && !upload.isDragReject && "border-dimah-s3-primary/50",
|
|
3612
|
+
className
|
|
3613
|
+
);
|
|
3614
|
+
const frameProps = {
|
|
3615
|
+
"data-slot": "object-list",
|
|
3616
|
+
"aria-label": label,
|
|
3617
|
+
"aria-busy": busy || void 0,
|
|
3618
|
+
className: frameClassName
|
|
3619
|
+
};
|
|
3620
|
+
const selectAll = selection.rowsSelectable && showRows ? /* @__PURE__ */ jsx(
|
|
3621
|
+
SelectCheckbox,
|
|
3622
|
+
{
|
|
3623
|
+
checked: selection.allSelected,
|
|
3624
|
+
indeterminate: selection.selectedCount > 0 && !selection.allSelected,
|
|
3625
|
+
label: pageLimited ? t("Select this page", { note: "object list selection" }) : t("Select all", { note: "object list selection" }),
|
|
3626
|
+
onCheckedChange: (checked) => selection.toggleAll(checked)
|
|
3627
|
+
}
|
|
3628
|
+
) : null;
|
|
3629
|
+
const sectionProps = {
|
|
3630
|
+
...upload ? upload.getRootProps({
|
|
3631
|
+
...frameProps,
|
|
3632
|
+
role: "region",
|
|
3633
|
+
tabIndex: void 0,
|
|
3634
|
+
"aria-disabled": void 0,
|
|
3635
|
+
onClick: (event) => {
|
|
3636
|
+
event.stopPropagation();
|
|
3637
|
+
}
|
|
3638
|
+
}) : frameProps,
|
|
3639
|
+
...frameStyle ? { style: frameStyle } : {}
|
|
3640
|
+
};
|
|
3641
|
+
const emptyDescriptionText = emptyDescription ?? (upload ? t("Drop files here to add them to this folder.", {
|
|
3642
|
+
note: "object list"
|
|
3643
|
+
}) : t("Files and folders you add here will show up in this list.", {
|
|
3644
|
+
note: "object list"
|
|
3645
|
+
}));
|
|
3646
|
+
return /* @__PURE__ */ jsxs("section", { ...sectionProps, children: [
|
|
3647
|
+
/* @__PURE__ */ jsxs("div", { className: "shrink-0", children: [
|
|
3648
|
+
showHeader ? /* @__PURE__ */ jsx(
|
|
3649
|
+
"div",
|
|
3650
|
+
{
|
|
3651
|
+
className: cn(
|
|
3652
|
+
"border-b border-dimah-s3-border",
|
|
3653
|
+
selection.selecting && "bg-dimah-s3-primary/10"
|
|
3654
|
+
),
|
|
3655
|
+
children: selection.selecting ? /* @__PURE__ */ jsx(
|
|
3656
|
+
ObjectListSelection,
|
|
3657
|
+
{
|
|
3658
|
+
leading: selectAll,
|
|
3659
|
+
selectedCount: selection.selectedCount,
|
|
3660
|
+
onClear: selection.clearSelection,
|
|
3661
|
+
prepare: selection.prepareSelection,
|
|
3662
|
+
removeMany: remove?.removeMany,
|
|
3663
|
+
actions: selectionActions,
|
|
3664
|
+
onThisPage: pageLimited,
|
|
3665
|
+
onDeleted: (result) => {
|
|
3666
|
+
selection.clearSelection();
|
|
3667
|
+
onDeleted?.(result);
|
|
3668
|
+
if (result.deleted.length > 0) void list.refresh?.();
|
|
3669
|
+
}
|
|
3670
|
+
}
|
|
3671
|
+
) : /* @__PURE__ */ jsxs("div", { className: "flex min-h-11 min-w-0 items-center gap-2 py-1.5 ps-1.5 pe-1", children: [
|
|
3672
|
+
selectAll,
|
|
3673
|
+
breadcrumb ? /* @__PURE__ */ jsx(
|
|
3674
|
+
ObjectListBreadcrumb,
|
|
3675
|
+
{
|
|
3676
|
+
rootLabel: label,
|
|
3677
|
+
trail,
|
|
3678
|
+
navigate: list.navigate
|
|
3679
|
+
}
|
|
3680
|
+
) : /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1" }),
|
|
3681
|
+
/* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-2", children: [
|
|
3682
|
+
isRefreshing ? /* @__PURE__ */ jsx(
|
|
3683
|
+
Spinner,
|
|
3684
|
+
{
|
|
3685
|
+
"aria-label": t("Loading files", { note: "object list" })
|
|
3686
|
+
}
|
|
3687
|
+
) : null,
|
|
3688
|
+
header
|
|
3689
|
+
] })
|
|
3690
|
+
] })
|
|
3691
|
+
}
|
|
3692
|
+
) : null,
|
|
3693
|
+
list.usage ? /* @__PURE__ */ jsx(ObjectListUsageLine, { usage: list.usage, limits: usageLimits }) : null,
|
|
3694
|
+
upload ? /* @__PURE__ */ jsx(ObjectListUpload, { upload }) : null
|
|
3695
|
+
] }),
|
|
3696
|
+
/* @__PURE__ */ jsxs(
|
|
3697
|
+
"div",
|
|
3698
|
+
{
|
|
3699
|
+
ref: sized ? setScroller : void 0,
|
|
3700
|
+
className: sized ? cn(
|
|
3701
|
+
"flex min-h-0 flex-col overflow-y-auto overscroll-y-contain",
|
|
3702
|
+
frameHeight != null ? "flex-1" : "flex-auto"
|
|
3703
|
+
) : void 0,
|
|
3704
|
+
children: [
|
|
3705
|
+
isLoading ? /* @__PURE__ */ jsx(ObjectListSkeleton, {}) : null,
|
|
3706
|
+
showInitialError ? /* @__PURE__ */ jsx(ObjectListError, { message: errorMessage, onRetry: list.refresh }) : null,
|
|
3707
|
+
showEmpty ? empty ?? /* @__PURE__ */ jsx(
|
|
3708
|
+
ObjectListEmpty,
|
|
3709
|
+
{
|
|
3710
|
+
title: emptyTitle ?? t("This folder is empty", { note: "object list" }),
|
|
3711
|
+
description: emptyDescriptionText
|
|
3712
|
+
}
|
|
3713
|
+
) : null,
|
|
3714
|
+
showRows ? /* @__PURE__ */ jsx(
|
|
3715
|
+
ObjectListRows,
|
|
3716
|
+
{
|
|
3717
|
+
items: list.items,
|
|
3718
|
+
folders,
|
|
3719
|
+
getKey,
|
|
3720
|
+
getLabel,
|
|
3721
|
+
getDescription,
|
|
3722
|
+
getFileName,
|
|
3723
|
+
getFileType,
|
|
3724
|
+
getPreviewUrl,
|
|
3725
|
+
renderItem,
|
|
3726
|
+
renderFolder,
|
|
3727
|
+
renderActions,
|
|
3728
|
+
renderMeta,
|
|
3729
|
+
onOpenItem,
|
|
3730
|
+
renderFolderActions,
|
|
3731
|
+
openFolder: list.openFolder,
|
|
3732
|
+
filesSelectable,
|
|
3733
|
+
foldersSelectable,
|
|
3734
|
+
fileKeys: selection.fileKeys,
|
|
3735
|
+
folderIds: selection.folderIds,
|
|
3736
|
+
selectRow: selection.selectRow
|
|
3737
|
+
}
|
|
3738
|
+
) : null,
|
|
3739
|
+
showRows && errorMessage ? /* @__PURE__ */ jsx(
|
|
3740
|
+
ObjectListErrorBanner,
|
|
3741
|
+
{
|
|
3742
|
+
message: errorMessage,
|
|
3743
|
+
onRetry: list.refresh
|
|
3744
|
+
}
|
|
3745
|
+
) : null,
|
|
3746
|
+
/* @__PURE__ */ jsx(
|
|
3747
|
+
ObjectListContinue,
|
|
3748
|
+
{
|
|
3749
|
+
active: list.hasMore === true && list.loadMore != null,
|
|
3750
|
+
pending: list.isLoadingMore === true,
|
|
3751
|
+
blocked: list.error != null,
|
|
3752
|
+
loadMore: list.loadMore,
|
|
3753
|
+
root: sized ? scroller : null,
|
|
3754
|
+
ready: !sized || scroller != null
|
|
3755
|
+
}
|
|
3756
|
+
)
|
|
3757
|
+
]
|
|
3758
|
+
}
|
|
3759
|
+
),
|
|
3760
|
+
upload ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3761
|
+
/* @__PURE__ */ jsx("input", { ...upload.getInputProps() }),
|
|
3762
|
+
/* @__PURE__ */ jsx(ObjectListDropOverlay, { upload })
|
|
3763
|
+
] }) : null
|
|
3764
|
+
] });
|
|
3765
|
+
}
|
|
3766
|
+
function cssLength(value) {
|
|
3767
|
+
if (typeof value === "number")
|
|
3768
|
+
return Number.isFinite(value) ? value : void 0;
|
|
3769
|
+
if (typeof value !== "string") return void 0;
|
|
3770
|
+
const trimmed = value.trim();
|
|
3771
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
3772
|
+
}
|
|
3773
|
+
function durationParts(seconds) {
|
|
3774
|
+
const safe = Math.max(1, Math.round(seconds));
|
|
3775
|
+
if (safe >= 86400) {
|
|
3776
|
+
return { unit: "day", count: Math.max(1, Math.round(safe / 86400)) };
|
|
3777
|
+
}
|
|
3778
|
+
if (safe >= 3600) {
|
|
3779
|
+
return { unit: "hour", count: Math.max(1, Math.round(safe / 3600)) };
|
|
3780
|
+
}
|
|
3781
|
+
if (safe >= 60) {
|
|
3782
|
+
return { unit: "minute", count: Math.max(1, Math.round(safe / 60)) };
|
|
3783
|
+
}
|
|
3784
|
+
return { unit: "second", count: safe };
|
|
3785
|
+
}
|
|
3786
|
+
function useShareExpiryLabel() {
|
|
3787
|
+
const t = useTranslations();
|
|
3788
|
+
const formatNumber = useFormatNumber();
|
|
3789
|
+
return (seconds) => {
|
|
3790
|
+
if (seconds <= 0) {
|
|
3791
|
+
return t("This link works while you can access this file.", {
|
|
3792
|
+
note: "object list menu"
|
|
3793
|
+
});
|
|
3794
|
+
}
|
|
3795
|
+
const { unit, count } = durationParts(seconds);
|
|
3796
|
+
const value = formatNumber(count);
|
|
3797
|
+
if (unit === "day") {
|
|
3798
|
+
return count === 1 ? t("Expires in 1 day", { note: "object list menu" }) : t("Expires in {count} days", {
|
|
3799
|
+
note: "object list menu",
|
|
3800
|
+
variables: { count: value }
|
|
3801
|
+
});
|
|
3802
|
+
}
|
|
3803
|
+
if (unit === "hour") {
|
|
3804
|
+
return count === 1 ? t("Expires in 1 hour", { note: "object list menu" }) : t("Expires in {count} hours", {
|
|
3805
|
+
note: "object list menu",
|
|
3806
|
+
variables: { count: value }
|
|
3807
|
+
});
|
|
3808
|
+
}
|
|
3809
|
+
if (unit === "minute") {
|
|
3810
|
+
return count === 1 ? t("Expires in 1 minute", { note: "object list menu" }) : t("Expires in {count} minutes", {
|
|
3811
|
+
note: "object list menu",
|
|
3812
|
+
variables: { count: value }
|
|
3813
|
+
});
|
|
3814
|
+
}
|
|
3815
|
+
return count === 1 ? t("Expires in 1 second", { note: "object list menu" }) : t("Expires in {count} seconds", {
|
|
3816
|
+
note: "object list menu",
|
|
3817
|
+
variables: { count: value }
|
|
3818
|
+
});
|
|
3819
|
+
};
|
|
3820
|
+
}
|
|
3821
|
+
function ObjectListMenu({
|
|
3822
|
+
objectKey,
|
|
3823
|
+
fileName,
|
|
3824
|
+
fileSize,
|
|
3825
|
+
download,
|
|
3826
|
+
share,
|
|
3827
|
+
expiresIn,
|
|
3828
|
+
delete: remove,
|
|
3829
|
+
onDeleted,
|
|
3830
|
+
actions
|
|
3831
|
+
}) {
|
|
3832
|
+
const t = useTranslations();
|
|
3833
|
+
const expiryLabel = useShareExpiryLabel();
|
|
3834
|
+
const linkSource = share ?? download;
|
|
3835
|
+
const [copying, setCopying] = useState(false);
|
|
3836
|
+
useRowDeleted(remove, objectKey, onDeleted);
|
|
3837
|
+
const downloadPending = download != null && download.isPending && download.objectKey === objectKey;
|
|
3838
|
+
const deleting = remove != null && remove.isDeleting;
|
|
3839
|
+
async function onCopyLink() {
|
|
3840
|
+
if (!linkSource || copying) return;
|
|
3841
|
+
setCopying(true);
|
|
3842
|
+
try {
|
|
3843
|
+
const result = await linkSource.presignMany([
|
|
3844
|
+
{
|
|
3845
|
+
key: objectKey,
|
|
3846
|
+
fileName,
|
|
3847
|
+
...expiresIn != null ? { expiresIn } : {}
|
|
3848
|
+
}
|
|
3849
|
+
]);
|
|
3850
|
+
const signed = result.signed[0];
|
|
3851
|
+
if (!signed) {
|
|
3852
|
+
toast.add({
|
|
3853
|
+
type: "error",
|
|
3854
|
+
title: t("Could not create link", { note: "object list menu" })
|
|
3855
|
+
});
|
|
3856
|
+
return;
|
|
3857
|
+
}
|
|
3858
|
+
try {
|
|
3859
|
+
await navigator.clipboard.writeText(signed.url);
|
|
3860
|
+
} catch {
|
|
3861
|
+
toast.add({
|
|
3862
|
+
type: "error",
|
|
3863
|
+
title: t("Could not copy link", { note: "object list menu" }),
|
|
3864
|
+
description: signed.url
|
|
3865
|
+
});
|
|
3866
|
+
return;
|
|
3867
|
+
}
|
|
3868
|
+
toast.add({
|
|
3869
|
+
type: "success",
|
|
3870
|
+
title: t("Link copied", { note: "object list menu" }),
|
|
3871
|
+
description: expiryLabel(signed.expiresIn)
|
|
3872
|
+
});
|
|
3873
|
+
} catch {
|
|
3874
|
+
toast.add({
|
|
3875
|
+
type: "error",
|
|
3876
|
+
title: t("Could not create link", { note: "object list menu" })
|
|
3877
|
+
});
|
|
3878
|
+
} finally {
|
|
3879
|
+
setCopying(false);
|
|
3880
|
+
}
|
|
3881
|
+
}
|
|
3882
|
+
const extra = actions ?? [];
|
|
3883
|
+
const showTransfer = download != null || linkSource != null;
|
|
3884
|
+
const showExtra = extra.length > 0;
|
|
3885
|
+
const showDelete = remove != null;
|
|
3886
|
+
if (!showTransfer && !showExtra && !showDelete) return null;
|
|
3887
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
3888
|
+
download ? /* @__PURE__ */ jsx(
|
|
3889
|
+
DownloadToasts,
|
|
3890
|
+
{
|
|
3891
|
+
download,
|
|
3892
|
+
objectKey,
|
|
3893
|
+
fileName
|
|
3894
|
+
}
|
|
3895
|
+
) : null,
|
|
3896
|
+
/* @__PURE__ */ jsxs(DropdownMenu, { children: [
|
|
3897
|
+
/* @__PURE__ */ jsxs(DropdownMenuTrigger, { render: /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon-sm" }), children: [
|
|
3898
|
+
/* @__PURE__ */ jsx(MoreHorizontalIcon, {}),
|
|
3899
|
+
/* @__PURE__ */ jsx("span", { className: "sr-only", children: t("File actions", { note: "object list menu" }) })
|
|
3900
|
+
] }),
|
|
3901
|
+
/* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "min-w-44", children: [
|
|
3902
|
+
showTransfer ? /* @__PURE__ */ jsxs(DropdownMenuGroup, { children: [
|
|
3903
|
+
download ? /* @__PURE__ */ jsxs(
|
|
3904
|
+
DropdownMenuItem,
|
|
3905
|
+
{
|
|
3906
|
+
disabled: downloadPending,
|
|
3907
|
+
onClick: () => void download.download(objectKey, fileName),
|
|
3908
|
+
children: [
|
|
3909
|
+
downloadPending ? /* @__PURE__ */ jsx(LoaderIcon, { className: "animate-spin" }) : /* @__PURE__ */ jsx(DownloadIcon, {}),
|
|
3910
|
+
t("Download", { note: "button" })
|
|
3911
|
+
]
|
|
3912
|
+
}
|
|
3913
|
+
) : null,
|
|
3914
|
+
linkSource ? /* @__PURE__ */ jsxs(
|
|
3915
|
+
DropdownMenuItem,
|
|
3916
|
+
{
|
|
3917
|
+
disabled: copying,
|
|
3918
|
+
onClick: () => void onCopyLink(),
|
|
3919
|
+
children: [
|
|
3920
|
+
copying ? /* @__PURE__ */ jsx(LoaderIcon, { className: "animate-spin" }) : /* @__PURE__ */ jsx(LinkIcon, {}),
|
|
3921
|
+
t("Copy link", { note: "object list menu" })
|
|
3922
|
+
]
|
|
3923
|
+
}
|
|
3924
|
+
) : null
|
|
3925
|
+
] }) : null,
|
|
3926
|
+
showExtra && showTransfer ? /* @__PURE__ */ jsx(DropdownMenuSeparator, {}) : null,
|
|
3927
|
+
showExtra ? /* @__PURE__ */ jsx(DropdownMenuGroup, { children: extra.map((action, index) => /* @__PURE__ */ jsxs(
|
|
3928
|
+
DropdownMenuItem,
|
|
3929
|
+
{
|
|
3930
|
+
variant: action.destructive ? "destructive" : "default",
|
|
3931
|
+
disabled: action.disabled,
|
|
3932
|
+
onClick: () => {
|
|
3933
|
+
action.onClick();
|
|
3934
|
+
},
|
|
3935
|
+
children: [
|
|
3936
|
+
action.icon,
|
|
3937
|
+
action.label
|
|
3938
|
+
]
|
|
3939
|
+
},
|
|
3940
|
+
`${action.label}-${index}`
|
|
3941
|
+
)) }) : null,
|
|
3942
|
+
showDelete && (showTransfer || showExtra) ? /* @__PURE__ */ jsx(DropdownMenuSeparator, {}) : null,
|
|
3943
|
+
remove ? /* @__PURE__ */ jsx(DropdownMenuGroup, { children: /* @__PURE__ */ jsxs(
|
|
3944
|
+
DropdownMenuItem,
|
|
3945
|
+
{
|
|
3946
|
+
variant: "destructive",
|
|
3947
|
+
disabled: deleting,
|
|
3948
|
+
onClick: () => remove.requestDelete(objectKey),
|
|
3949
|
+
children: [
|
|
3950
|
+
remove.isDeleting && remove.objectKey === objectKey ? /* @__PURE__ */ jsx(LoaderIcon, { className: "animate-spin" }) : /* @__PURE__ */ jsx(Trash2Icon, {}),
|
|
3951
|
+
t("Delete", { note: "button" })
|
|
3952
|
+
]
|
|
3953
|
+
}
|
|
3954
|
+
) }) : null
|
|
3955
|
+
] })
|
|
3956
|
+
] }),
|
|
3957
|
+
remove ? /* @__PURE__ */ jsx(
|
|
3958
|
+
DeleteConfirm,
|
|
3959
|
+
{
|
|
3960
|
+
remove,
|
|
3961
|
+
objectKey,
|
|
3962
|
+
fileName,
|
|
3963
|
+
fileSize
|
|
3964
|
+
}
|
|
3965
|
+
) : null
|
|
3966
|
+
] });
|
|
3967
|
+
}
|
|
3968
|
+
function DownloadToasts({
|
|
3969
|
+
download,
|
|
3970
|
+
objectKey,
|
|
3971
|
+
fileName
|
|
3972
|
+
}) {
|
|
3973
|
+
useDownloadToast(download, { objectKey, fileName });
|
|
3974
|
+
return null;
|
|
3975
|
+
}
|
|
3976
|
+
function DeleteConfirm({
|
|
3977
|
+
remove,
|
|
3978
|
+
objectKey,
|
|
3979
|
+
fileName,
|
|
3980
|
+
fileSize
|
|
3981
|
+
}) {
|
|
3982
|
+
const t = useTranslations();
|
|
3983
|
+
const formatFileSize = useFormatFileSize();
|
|
3984
|
+
const displayName = fileName ?? fileNameFromKey(objectKey) ?? objectKey;
|
|
3985
|
+
const isThis = remove.objectKey === objectKey;
|
|
3986
|
+
useDeleteToast(remove, { objectKey, displayName });
|
|
3987
|
+
const name = isolateText(truncateFileName(displayName));
|
|
3988
|
+
const fileLabel = fileSize != null ? `${name} (${isolateText(formatFileSize(fileSize))})` : name;
|
|
3989
|
+
return /* @__PURE__ */ jsx(
|
|
3990
|
+
AlertDialog,
|
|
3991
|
+
{
|
|
3992
|
+
open: remove.isConfirming && isThis,
|
|
3993
|
+
onOpenChange: (open) => {
|
|
3994
|
+
if (!open) remove.cancelDelete();
|
|
3995
|
+
},
|
|
3996
|
+
children: /* @__PURE__ */ jsxs(AlertDialogContent, { children: [
|
|
3997
|
+
/* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
|
|
3998
|
+
/* @__PURE__ */ jsx(AlertDialogMedia, { children: /* @__PURE__ */ jsx(Trash2Icon, {}) }),
|
|
3999
|
+
/* @__PURE__ */ jsx(AlertDialogTitle, { children: t("Delete file?", { note: "dialog title" }) }),
|
|
4000
|
+
/* @__PURE__ */ jsx(AlertDialogDescription, { className: "[overflow-wrap:anywhere]", children: t(
|
|
4001
|
+
'Are you sure you want to delete "{name}"? This action cannot be undone.',
|
|
4002
|
+
{
|
|
4003
|
+
note: "dialog description",
|
|
4004
|
+
variables: { name: fileLabel }
|
|
4005
|
+
}
|
|
4006
|
+
) })
|
|
4007
|
+
] }),
|
|
4008
|
+
/* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
|
|
4009
|
+
/* @__PURE__ */ jsx(AlertDialogCancel, { children: t("Cancel", { note: "dialog button" }) }),
|
|
4010
|
+
/* @__PURE__ */ jsx(
|
|
4011
|
+
AlertDialogAction,
|
|
4012
|
+
{
|
|
4013
|
+
variant: "destructive",
|
|
4014
|
+
onClick: () => void remove.confirmDelete(),
|
|
4015
|
+
children: t("Delete", { note: "dialog confirm" })
|
|
4016
|
+
}
|
|
4017
|
+
)
|
|
4018
|
+
] })
|
|
4019
|
+
] })
|
|
4020
|
+
}
|
|
4021
|
+
);
|
|
4022
|
+
}
|
|
4023
|
+
function useRowDeleted(remove, objectKey, onDeleted) {
|
|
4024
|
+
const onDeletedRef = useRef(onDeleted);
|
|
4025
|
+
const notified = useRef(false);
|
|
4026
|
+
const phase = remove?.phase;
|
|
4027
|
+
const currentKey = remove?.objectKey;
|
|
4028
|
+
useEffect(() => {
|
|
4029
|
+
onDeletedRef.current = onDeleted;
|
|
4030
|
+
}, [onDeleted]);
|
|
4031
|
+
useEffect(() => {
|
|
4032
|
+
if (phase !== "success" || currentKey !== objectKey) {
|
|
4033
|
+
notified.current = false;
|
|
4034
|
+
return;
|
|
4035
|
+
}
|
|
4036
|
+
if (notified.current) return;
|
|
4037
|
+
notified.current = true;
|
|
4038
|
+
onDeletedRef.current?.();
|
|
4039
|
+
}, [currentKey, objectKey, phase]);
|
|
4040
|
+
}
|
|
2176
4041
|
|
|
2177
|
-
export { DeleteButton, DownloadButton, FileAttachment, MultiUploadStatus, ProgressDownloadButton, StatusAttachment, Toaster, UploadButton, UploadDropzone, UploadFileStatus, UploadStatus, resolveStatusSlot, toast, useDeleteToast, useDeleteUi, useDownloadToast, useDownloadUi, useFileRejectToast, useUploadToast, useUploadUi };
|
|
4042
|
+
export { DeleteButton, DownloadButton, FileAttachment, MultiUploadStatus, ObjectList, ObjectListMenu, ProgressDownloadButton, StatusAttachment, Toaster, UploadButton, UploadDropzone, UploadFileStatus, UploadStatus, resolveStatusSlot, toast, useDeleteToast, useDeleteUi, useDownloadToast, useDownloadUi, useFileRejectToast, useUploadToast, useUploadUi };
|
|
2178
4043
|
//# sourceMappingURL=index.js.map
|
|
2179
4044
|
//# sourceMappingURL=index.js.map
|