@dimah-s3/ui 1.5.10 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/dist/components/dimah-s3/list/object-list-breadcrumb.d.ts +7 -0
  2. package/dist/components/dimah-s3/list/object-list-breadcrumb.d.ts.map +1 -0
  3. package/dist/components/dimah-s3/list/object-list-menu.d.ts +65 -0
  4. package/dist/components/dimah-s3/list/object-list-menu.d.ts.map +1 -0
  5. package/dist/components/dimah-s3/list/object-list-rows.d.ts +32 -0
  6. package/dist/components/dimah-s3/list/object-list-rows.d.ts.map +1 -0
  7. package/dist/components/dimah-s3/list/object-list-selection-state.d.ts +38 -0
  8. package/dist/components/dimah-s3/list/object-list-selection-state.d.ts.map +1 -0
  9. package/dist/components/dimah-s3/list/object-list-selection.d.ts +36 -0
  10. package/dist/components/dimah-s3/list/object-list-selection.d.ts.map +1 -0
  11. package/dist/components/dimah-s3/list/object-list-states.d.ts +24 -0
  12. package/dist/components/dimah-s3/list/object-list-states.d.ts.map +1 -0
  13. package/dist/components/dimah-s3/list/object-list-upload.d.ts +14 -0
  14. package/dist/components/dimah-s3/list/object-list-upload.d.ts.map +1 -0
  15. package/dist/components/dimah-s3/list/object-list-usage.d.ts +7 -0
  16. package/dist/components/dimah-s3/list/object-list-usage.d.ts.map +1 -0
  17. package/dist/components/dimah-s3/list/object-list.d.ts +167 -0
  18. package/dist/components/dimah-s3/list/object-list.d.ts.map +1 -0
  19. package/dist/components/ui/breadcrumb.d.ts +11 -0
  20. package/dist/components/ui/breadcrumb.d.ts.map +1 -0
  21. package/dist/components/ui/checkbox.d.ts +4 -0
  22. package/dist/components/ui/checkbox.d.ts.map +1 -0
  23. package/dist/components/ui/dropdown-menu.d.ts +30 -0
  24. package/dist/components/ui/dropdown-menu.d.ts.map +1 -0
  25. package/dist/components/ui/empty.d.ts +13 -0
  26. package/dist/components/ui/empty.d.ts.map +1 -0
  27. package/dist/components/ui/item.d.ts +23 -0
  28. package/dist/components/ui/item.d.ts.map +1 -0
  29. package/dist/components/ui/separator.d.ts +4 -0
  30. package/dist/components/ui/separator.d.ts.map +1 -0
  31. package/dist/components/ui/skeleton.d.ts +4 -0
  32. package/dist/components/ui/skeleton.d.ts.map +1 -0
  33. package/dist/components/ui/spinner.d.ts +5 -0
  34. package/dist/components/ui/spinner.d.ts.map +1 -0
  35. package/dist/index.d.ts +2 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.js +1853 -9
  38. package/dist/index.js.map +1 -1
  39. package/dist/lib/file-type-icon.d.ts +14 -1
  40. package/dist/lib/file-type-icon.d.ts.map +1 -1
  41. package/dist/lib/format-expires-in.d.ts +3 -0
  42. package/dist/lib/format-expires-in.d.ts.map +1 -0
  43. package/package.json +12 -12
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, Loader2Icon } from 'lucide-react';
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 { formatFileSize, truncateFileName, fileNameFromKey } from '@dimah-s3/core';
9
+ import { formatFileSize, truncateFileName, fileNameFromKey, DELETE_BATCH_MAX_KEYS } from '@dimah-s3/core';
10
10
  import { useFormatDimahError, formatEta, isFetchDownload, formatAcceptLabels } from '@dimah-s3/react';
11
- import '@base-ui/react/merge-props';
12
- import '@base-ui/react/use-render';
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
- // Fill the media box so the glyph tracks Attachment size/orientation
486
- // (vertical media can grow well past the default icon rem sizes).
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" },
@@ -2173,7 +2201,1823 @@ function DeleteButton({
2173
2201
  resolveStatusSlot(statusSlot, statusNode)
2174
2202
  ] });
2175
2203
  }
2204
+ function Spinner({
2205
+ className,
2206
+ ...props
2207
+ }) {
2208
+ return /* @__PURE__ */ jsx(
2209
+ Loader2Icon,
2210
+ {
2211
+ "data-slot": "spinner",
2212
+ role: "status",
2213
+ "aria-label": "Loading",
2214
+ className: cn("size-4 animate-spin", className),
2215
+ ...props
2216
+ }
2217
+ );
2218
+ }
2219
+ function Breadcrumb({ className, ...props }) {
2220
+ return /* @__PURE__ */ jsx(
2221
+ "nav",
2222
+ {
2223
+ "aria-label": "breadcrumb",
2224
+ "data-slot": "breadcrumb",
2225
+ className: cn(className),
2226
+ ...props
2227
+ }
2228
+ );
2229
+ }
2230
+ function BreadcrumbList({ className, ...props }) {
2231
+ return /* @__PURE__ */ jsx(
2232
+ "ol",
2233
+ {
2234
+ "data-slot": "breadcrumb-list",
2235
+ className: cn(
2236
+ "flex flex-wrap items-center gap-1.5 text-sm wrap-break-word text-muted-foreground",
2237
+ className
2238
+ ),
2239
+ ...props
2240
+ }
2241
+ );
2242
+ }
2243
+ function BreadcrumbItem({ className, ...props }) {
2244
+ return /* @__PURE__ */ jsx(
2245
+ "li",
2246
+ {
2247
+ "data-slot": "breadcrumb-item",
2248
+ className: cn("inline-flex items-center gap-1", className),
2249
+ ...props
2250
+ }
2251
+ );
2252
+ }
2253
+ function BreadcrumbLink({
2254
+ className,
2255
+ render,
2256
+ ...props
2257
+ }) {
2258
+ return useRender({
2259
+ defaultTagName: "a",
2260
+ props: mergeProps(
2261
+ {
2262
+ className: cn("transition-colors hover:text-foreground", className)
2263
+ },
2264
+ props
2265
+ ),
2266
+ render,
2267
+ state: {
2268
+ slot: "breadcrumb-link"
2269
+ }
2270
+ });
2271
+ }
2272
+ function BreadcrumbPage({ className, ...props }) {
2273
+ return /* @__PURE__ */ jsx(
2274
+ "span",
2275
+ {
2276
+ "data-slot": "breadcrumb-page",
2277
+ role: "link",
2278
+ "aria-disabled": "true",
2279
+ "aria-current": "page",
2280
+ className: cn("font-normal text-foreground", className),
2281
+ ...props
2282
+ }
2283
+ );
2284
+ }
2285
+ function BreadcrumbSeparator({
2286
+ children,
2287
+ className,
2288
+ ...props
2289
+ }) {
2290
+ return /* @__PURE__ */ jsx(
2291
+ "li",
2292
+ {
2293
+ "data-slot": "breadcrumb-separator",
2294
+ role: "presentation",
2295
+ "aria-hidden": "true",
2296
+ className: cn("[&>svg]:size-3.5", className),
2297
+ ...props,
2298
+ children: children ?? /* @__PURE__ */ jsx(ChevronRightIcon, { className: "rtl:rotate-180" })
2299
+ }
2300
+ );
2301
+ }
2302
+ function BreadcrumbEllipsis({
2303
+ className,
2304
+ ...props
2305
+ }) {
2306
+ return /* @__PURE__ */ jsxs(
2307
+ "span",
2308
+ {
2309
+ "data-slot": "breadcrumb-ellipsis",
2310
+ role: "presentation",
2311
+ "aria-hidden": "true",
2312
+ className: cn(
2313
+ "flex size-5 items-center justify-center [&>svg]:size-4",
2314
+ className
2315
+ ),
2316
+ ...props,
2317
+ children: [
2318
+ /* @__PURE__ */ jsx(MoreHorizontalIcon, {}),
2319
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "More" })
2320
+ ]
2321
+ }
2322
+ );
2323
+ }
2324
+ function DropdownMenu({ ...props }) {
2325
+ return /* @__PURE__ */ jsx(Menu.Root, { "data-slot": "dropdown-menu", ...props });
2326
+ }
2327
+ function DropdownMenuTrigger({ ...props }) {
2328
+ return /* @__PURE__ */ jsx(Menu.Trigger, { "data-slot": "dropdown-menu-trigger", ...props });
2329
+ }
2330
+ function DropdownMenuContent({
2331
+ align = "start",
2332
+ alignOffset = 0,
2333
+ side = "bottom",
2334
+ sideOffset = 4,
2335
+ className,
2336
+ ...props
2337
+ }) {
2338
+ return /* @__PURE__ */ jsx(Menu.Portal, { children: /* @__PURE__ */ jsx(
2339
+ Menu.Positioner,
2340
+ {
2341
+ className: "isolate z-50 outline-none",
2342
+ align,
2343
+ alignOffset,
2344
+ side,
2345
+ sideOffset,
2346
+ children: /* @__PURE__ */ jsx(
2347
+ Menu.Popup,
2348
+ {
2349
+ "data-slot": "dropdown-menu-content",
2350
+ className: cn(
2351
+ "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",
2352
+ className
2353
+ ),
2354
+ ...props
2355
+ }
2356
+ )
2357
+ }
2358
+ ) });
2359
+ }
2360
+ function DropdownMenuGroup({ ...props }) {
2361
+ return /* @__PURE__ */ jsx(Menu.Group, { "data-slot": "dropdown-menu-group", ...props });
2362
+ }
2363
+ function DropdownMenuItem({
2364
+ className,
2365
+ inset,
2366
+ variant = "default",
2367
+ ...props
2368
+ }) {
2369
+ return /* @__PURE__ */ jsx(
2370
+ Menu.Item,
2371
+ {
2372
+ "data-slot": "dropdown-menu-item",
2373
+ "data-inset": inset,
2374
+ "data-variant": variant,
2375
+ className: cn(
2376
+ "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",
2377
+ className
2378
+ ),
2379
+ ...props
2380
+ }
2381
+ );
2382
+ }
2383
+ function DropdownMenuSeparator({
2384
+ className,
2385
+ ...props
2386
+ }) {
2387
+ return /* @__PURE__ */ jsx(
2388
+ Menu.Separator,
2389
+ {
2390
+ "data-slot": "dropdown-menu-separator",
2391
+ className: cn("-mx-1 my-1 h-px bg-border", className),
2392
+ ...props
2393
+ }
2394
+ );
2395
+ }
2396
+ var VISIBLE_TRAIL = 2;
2397
+ function splitObjectListTrail(trail) {
2398
+ if (trail.length <= VISIBLE_TRAIL) {
2399
+ return { hidden: [], visible: trail };
2400
+ }
2401
+ return {
2402
+ hidden: trail.slice(0, -VISIBLE_TRAIL),
2403
+ visible: trail.slice(-VISIBLE_TRAIL)
2404
+ };
2405
+ }
2406
+ function ObjectListBreadcrumb({
2407
+ rootLabel,
2408
+ trail,
2409
+ navigate
2410
+ }) {
2411
+ const t = useTranslations();
2412
+ const atRoot = trail.length === 0;
2413
+ const { hidden, visible } = splitObjectListTrail(trail);
2414
+ return /* @__PURE__ */ jsx(Breadcrumb, { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsxs(BreadcrumbList, { className: "min-w-0 flex-nowrap", children: [
2415
+ /* @__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(
2416
+ BreadcrumbLink,
2417
+ {
2418
+ className: "max-w-40 truncate sm:max-w-56",
2419
+ render: /* @__PURE__ */ jsx("button", { type: "button" }),
2420
+ onClick: () => navigate([]),
2421
+ children: rootLabel
2422
+ }
2423
+ ) }),
2424
+ hidden.length > 0 ? /* @__PURE__ */ jsxs(Fragment$1, { children: [
2425
+ /* @__PURE__ */ jsx(BreadcrumbSeparator, {}),
2426
+ /* @__PURE__ */ jsx(BreadcrumbItem, { className: "shrink-0", children: /* @__PURE__ */ jsxs(DropdownMenu, { children: [
2427
+ /* @__PURE__ */ jsxs(DropdownMenuTrigger, { className: "flex items-center gap-1", children: [
2428
+ /* @__PURE__ */ jsx(BreadcrumbEllipsis, { className: "size-4" }),
2429
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: t("Earlier folders", { note: "object list" }) })
2430
+ ] }),
2431
+ /* @__PURE__ */ jsx(
2432
+ DropdownMenuContent,
2433
+ {
2434
+ align: "start",
2435
+ className: "max-w-64 min-w-48",
2436
+ children: /* @__PURE__ */ jsx(DropdownMenuGroup, { children: hidden.map((folder, index) => /* @__PURE__ */ jsx(
2437
+ DropdownMenuItem,
2438
+ {
2439
+ disabled: navigate == null,
2440
+ onClick: () => navigate?.(trail.slice(0, index + 1)),
2441
+ children: /* @__PURE__ */ jsx("span", { className: "truncate", children: folder.name })
2442
+ },
2443
+ folder.id
2444
+ )) })
2445
+ }
2446
+ )
2447
+ ] }) })
2448
+ ] }) : null,
2449
+ visible.map((folder, index) => {
2450
+ const trailIndex = hidden.length + index;
2451
+ const current = trailIndex === trail.length - 1;
2452
+ return /* @__PURE__ */ jsxs(Fragment$1, { children: [
2453
+ /* @__PURE__ */ jsx(BreadcrumbSeparator, {}),
2454
+ /* @__PURE__ */ jsx(BreadcrumbItem, { className: "min-w-0", children: current || navigate == null ? /* @__PURE__ */ jsx(BreadcrumbPage, { className: "max-w-40 truncate sm:max-w-56", children: folder.name }) : /* @__PURE__ */ jsx(
2455
+ BreadcrumbLink,
2456
+ {
2457
+ className: "max-w-40 truncate sm:max-w-56",
2458
+ render: /* @__PURE__ */ jsx("button", { type: "button" }),
2459
+ onClick: () => navigate(trail.slice(0, trailIndex + 1)),
2460
+ children: folder.name
2461
+ }
2462
+ ) })
2463
+ ] }, folder.id);
2464
+ })
2465
+ ] }) });
2466
+ }
2467
+ function Checkbox({ className, ...props }) {
2468
+ return /* @__PURE__ */ jsx(
2469
+ Checkbox$1.Root,
2470
+ {
2471
+ "data-slot": "checkbox",
2472
+ className: cn(
2473
+ "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",
2474
+ className
2475
+ ),
2476
+ ...props,
2477
+ children: /* @__PURE__ */ jsxs(
2478
+ Checkbox$1.Indicator,
2479
+ {
2480
+ "data-slot": "checkbox-indicator",
2481
+ className: "grid place-content-center text-current transition-none [&>svg]:size-3.5",
2482
+ children: [
2483
+ /* @__PURE__ */ jsx(CheckIcon, { className: "in-data-indeterminate:hidden" }),
2484
+ /* @__PURE__ */ jsx(MinusIcon, { className: "hidden in-data-indeterminate:block" })
2485
+ ]
2486
+ }
2487
+ )
2488
+ }
2489
+ );
2490
+ }
2491
+ var itemVariants = cva(
2492
+ "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",
2493
+ {
2494
+ variants: {
2495
+ variant: {
2496
+ default: "border-transparent",
2497
+ outline: "border-border",
2498
+ muted: "border-transparent bg-muted/50"
2499
+ },
2500
+ size: {
2501
+ default: "gap-2.5 px-3 py-2.5",
2502
+ sm: "gap-2.5 px-3 py-2.5",
2503
+ xs: "gap-2 px-2.5 py-2 in-data-[slot=dropdown-menu-content]:p-0"
2504
+ }
2505
+ },
2506
+ defaultVariants: {
2507
+ variant: "default",
2508
+ size: "default"
2509
+ }
2510
+ }
2511
+ );
2512
+ function Item({
2513
+ className,
2514
+ variant = "default",
2515
+ size = "default",
2516
+ render,
2517
+ ...props
2518
+ }) {
2519
+ return useRender({
2520
+ defaultTagName: "div",
2521
+ props: mergeProps(
2522
+ {
2523
+ className: cn(itemVariants({ variant, size, className }))
2524
+ },
2525
+ props
2526
+ ),
2527
+ render,
2528
+ state: {
2529
+ slot: "item",
2530
+ variant,
2531
+ size
2532
+ }
2533
+ });
2534
+ }
2535
+ cva(
2536
+ "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",
2537
+ {
2538
+ variants: {
2539
+ variant: {
2540
+ default: "bg-transparent",
2541
+ icon: "[&_svg:not([class*='size-'])]:size-4",
2542
+ 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"
2543
+ }
2544
+ },
2545
+ defaultVariants: {
2546
+ variant: "default"
2547
+ }
2548
+ }
2549
+ );
2550
+ function ItemContent({ className, ...props }) {
2551
+ return /* @__PURE__ */ jsx(
2552
+ "div",
2553
+ {
2554
+ "data-slot": "item-content",
2555
+ className: cn(
2556
+ "flex flex-1 flex-col gap-1 group-data-[size=xs]/item:gap-0 [&+[data-slot=item-content]]:flex-none",
2557
+ className
2558
+ ),
2559
+ ...props
2560
+ }
2561
+ );
2562
+ }
2563
+ function ItemTitle({ className, ...props }) {
2564
+ return /* @__PURE__ */ jsx(
2565
+ "div",
2566
+ {
2567
+ "data-slot": "item-title",
2568
+ className: cn(
2569
+ "line-clamp-1 flex w-fit items-center gap-2 text-sm leading-snug font-medium underline-offset-4",
2570
+ className
2571
+ ),
2572
+ ...props
2573
+ }
2574
+ );
2575
+ }
2576
+ function ItemDescription({ className, ...props }) {
2577
+ return /* @__PURE__ */ jsx(
2578
+ "p",
2579
+ {
2580
+ "data-slot": "item-description",
2581
+ className: cn(
2582
+ "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",
2583
+ className
2584
+ ),
2585
+ ...props
2586
+ }
2587
+ );
2588
+ }
2589
+ function SelectCheckbox({
2590
+ checked,
2591
+ indeterminate,
2592
+ label,
2593
+ onCheckedChange
2594
+ }) {
2595
+ const shiftRef = useRef(false);
2596
+ return /* @__PURE__ */ jsx(
2597
+ Checkbox,
2598
+ {
2599
+ checked,
2600
+ indeterminate,
2601
+ "aria-label": label,
2602
+ className: "after:-inset-x-2 after:-inset-y-3",
2603
+ onPointerDown: (event) => {
2604
+ shiftRef.current = event.shiftKey;
2605
+ },
2606
+ onKeyDown: (event) => {
2607
+ if (event.key === " " || event.key === "Enter") {
2608
+ shiftRef.current = event.shiftKey;
2609
+ }
2610
+ },
2611
+ onCheckedChange: (value) => {
2612
+ onCheckedChange(value, shiftRef.current);
2613
+ shiftRef.current = false;
2614
+ }
2615
+ }
2616
+ );
2617
+ }
2618
+ function ObjectListRows({
2619
+ items,
2620
+ folders,
2621
+ getKey,
2622
+ getLabel,
2623
+ getDescription,
2624
+ getFileName,
2625
+ getFileType,
2626
+ getPreviewUrl,
2627
+ renderItem,
2628
+ renderFolder,
2629
+ renderActions,
2630
+ renderMeta,
2631
+ onOpenItem,
2632
+ renderFolderActions,
2633
+ openFolder,
2634
+ filesSelectable,
2635
+ foldersSelectable,
2636
+ fileKeys,
2637
+ folderIds,
2638
+ selectRow
2639
+ }) {
2640
+ const t = useTranslations();
2641
+ return /* @__PURE__ */ jsxs("div", { role: "list", className: "flex min-w-0 flex-col", children: [
2642
+ folders.map(
2643
+ (folder) => renderFolder ? /* @__PURE__ */ jsx("div", { role: "listitem", "data-kind": "folder", children: renderFolder(folder) }, folder.id) : /* @__PURE__ */ jsx(
2644
+ ObjectListRow,
2645
+ {
2646
+ kind: "folder",
2647
+ title: folder.name,
2648
+ media: /* @__PURE__ */ jsx(FolderGlyph, {}),
2649
+ actions: renderFolderActions?.(folder),
2650
+ selected: folderIds.has(folder.id),
2651
+ selectable: foldersSelectable,
2652
+ selectLabel: t("Select {name}", {
2653
+ note: "object list selection",
2654
+ variables: { name: folder.name }
2655
+ }),
2656
+ onSelect: foldersSelectable ? (checked, shift) => selectRow("folder", folder.id, checked, shift) : void 0,
2657
+ onOpen: openFolder != null ? () => openFolder(folder) : void 0
2658
+ },
2659
+ folder.id
2660
+ )
2661
+ ),
2662
+ items.map((item) => {
2663
+ const key = getKey(item);
2664
+ if (renderItem) {
2665
+ return /* @__PURE__ */ jsx("div", { role: "listitem", "data-kind": "file", children: renderItem(item) }, key);
2666
+ }
2667
+ const fileName = getFileName?.(item) ?? getLabel(item);
2668
+ const previewUrl = getPreviewUrl?.(item);
2669
+ return /* @__PURE__ */ jsx(
2670
+ ObjectListRow,
2671
+ {
2672
+ kind: "file",
2673
+ title: getLabel(item),
2674
+ description: getDescription?.(item),
2675
+ media: previewUrl ? /* @__PURE__ */ jsx(
2676
+ "img",
2677
+ {
2678
+ src: previewUrl,
2679
+ alt: "",
2680
+ draggable: false,
2681
+ decoding: "async",
2682
+ className: "size-8 shrink-0 rounded-[4px] object-cover"
2683
+ }
2684
+ ) : /* @__PURE__ */ jsx(
2685
+ FileTypeGlyph,
2686
+ {
2687
+ layout: "icon",
2688
+ fileName,
2689
+ fileType: getFileType?.(item)
2690
+ }
2691
+ ),
2692
+ actions: renderActions?.(item),
2693
+ meta: renderMeta?.(item),
2694
+ selected: fileKeys.has(key),
2695
+ selectable: filesSelectable,
2696
+ selectLabel: t("Select {name}", {
2697
+ note: "object list selection",
2698
+ variables: { name: getLabel(item) }
2699
+ }),
2700
+ onOpen: onOpenItem != null ? () => onOpenItem(item) : void 0,
2701
+ onSelect: filesSelectable ? (checked, shift) => selectRow("file", key, checked, shift) : void 0
2702
+ },
2703
+ key
2704
+ );
2705
+ })
2706
+ ] });
2707
+ }
2708
+ var FILE_EXTENSION = /^\.[a-z0-9]{1,8}$/i;
2709
+ function splitFileName(name) {
2710
+ const dot = name.lastIndexOf(".");
2711
+ if (dot <= 0) return { stem: name, extension: "" };
2712
+ const extension = name.slice(dot);
2713
+ if (!FILE_EXTENSION.test(extension)) return { stem: name, extension: "" };
2714
+ return { stem: name.slice(0, dot), extension };
2715
+ }
2716
+ function FileNameLabel({ name }) {
2717
+ const { stem, extension } = splitFileName(name);
2718
+ return /* @__PURE__ */ jsxs("span", { dir: "auto", title: name, className: "flex max-w-full min-w-0", children: [
2719
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", children: stem }),
2720
+ extension ? /* @__PURE__ */ jsx("span", { className: "shrink-0", children: extension }) : null
2721
+ ] });
2722
+ }
2723
+ function ObjectListRow({
2724
+ kind,
2725
+ title,
2726
+ description,
2727
+ media,
2728
+ actions,
2729
+ meta,
2730
+ selected,
2731
+ selectable,
2732
+ selectLabel,
2733
+ onSelect,
2734
+ onOpen
2735
+ }) {
2736
+ const described = description != null && description !== false && description !== "";
2737
+ const showMeta = meta != null && meta !== false && meta !== "";
2738
+ 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)]";
2739
+ return /* @__PURE__ */ jsxs(
2740
+ "div",
2741
+ {
2742
+ role: "listitem",
2743
+ "data-slot": "object-list-row",
2744
+ "data-kind": kind,
2745
+ "data-selected": selected ? "" : void 0,
2746
+ className: cn(
2747
+ "grid min-h-11 min-w-0 items-center gap-2 overflow-hidden py-1 ps-1.5 pe-1 transition-colors duration-150",
2748
+ columns,
2749
+ selected ? "bg-dimah-s3-primary/10 hover:bg-dimah-s3-primary/15" : "hover:bg-dimah-s3-muted"
2750
+ ),
2751
+ children: [
2752
+ selectable && onSelect ? /* @__PURE__ */ jsx(
2753
+ SelectCheckbox,
2754
+ {
2755
+ checked: selected,
2756
+ label: selectLabel,
2757
+ onCheckedChange: onSelect
2758
+ }
2759
+ ) : null,
2760
+ /* @__PURE__ */ jsxs(
2761
+ Item,
2762
+ {
2763
+ size: "sm",
2764
+ className: cn(
2765
+ "w-full min-w-0 flex-nowrap overflow-hidden rounded-none bg-transparent p-0 hover:bg-transparent",
2766
+ onOpen && "cursor-pointer self-stretch text-start"
2767
+ ),
2768
+ render: onOpen ? /* @__PURE__ */ jsx("button", { type: "button" }) : void 0,
2769
+ onClick: onOpen,
2770
+ children: [
2771
+ /* @__PURE__ */ jsx("span", { className: "shrink-0", children: media }),
2772
+ /* @__PURE__ */ jsxs(
2773
+ ItemContent,
2774
+ {
2775
+ className: cn("min-w-0 gap-0 overflow-hidden", actions && "pe-2"),
2776
+ children: [
2777
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 items-center gap-2", children: [
2778
+ /* @__PURE__ */ jsx(ItemTitle, { className: "line-clamp-none block w-full min-w-0 overflow-hidden font-normal", children: /* @__PURE__ */ jsx(FileNameLabel, { name: title }) }),
2779
+ showMeta ? /* @__PURE__ */ jsx("div", { className: "shrink-0", children: meta }) : null
2780
+ ] }),
2781
+ described ? /* @__PURE__ */ jsx(ItemDescription, { className: "min-w-0 truncate text-xs leading-4 text-dimah-s3-muted-foreground", children: description }) : null
2782
+ ]
2783
+ }
2784
+ )
2785
+ ]
2786
+ }
2787
+ ),
2788
+ actions ? /* @__PURE__ */ jsx("div", { className: "shrink-0", children: actions }) : null
2789
+ ]
2790
+ }
2791
+ );
2792
+ }
2793
+ function useObjectListSelection({
2794
+ items,
2795
+ folders,
2796
+ filesSelectable,
2797
+ foldersSelectable,
2798
+ getKey,
2799
+ getLabel,
2800
+ getFileName,
2801
+ getObjectKey,
2802
+ resolveFolderKeys,
2803
+ onSelectionChange
2804
+ }) {
2805
+ const [fileKeys, setFileKeys] = useState(/* @__PURE__ */ new Set());
2806
+ const [folderIds, setFolderIds] = useState(/* @__PURE__ */ new Set());
2807
+ const anchorRef = useRef(null);
2808
+ const visibleFileKeys = useMemo(
2809
+ () => filesSelectable ? items.map((item) => getKey(item)) : [],
2810
+ [filesSelectable, getKey, items]
2811
+ );
2812
+ const visibleFolderIds = useMemo(
2813
+ () => foldersSelectable ? folders.map((folder) => folder.id) : [],
2814
+ [folders, foldersSelectable]
2815
+ );
2816
+ const selectedFileKeys = visibleFileKeys.filter((key) => fileKeys.has(key));
2817
+ const selectedFolderIds = visibleFolderIds.filter((id) => folderIds.has(id));
2818
+ const selectedFileKeySig = JSON.stringify(selectedFileKeys);
2819
+ const selectedFolderIdSig = JSON.stringify(selectedFolderIds);
2820
+ const onSelectionChangeRef = useRef(onSelectionChange);
2821
+ const getKeyRef = useRef(getKey);
2822
+ const rowsSelectable = filesSelectable || foldersSelectable;
2823
+ const selectedCount = selectedFileKeys.length + selectedFolderIds.length;
2824
+ const visibleCount = visibleFileKeys.length + visibleFolderIds.length;
2825
+ const selecting = rowsSelectable && selectedCount > 0;
2826
+ const snapshotRef = useRef({
2827
+ selecting: false,
2828
+ fileIds: [],
2829
+ folderIds: []
2830
+ });
2831
+ useEffect(() => {
2832
+ snapshotRef.current = {
2833
+ selecting,
2834
+ fileIds: visibleFileKeys,
2835
+ folderIds: visibleFolderIds
2836
+ };
2837
+ }, [selecting, visibleFileKeys, visibleFolderIds]);
2838
+ useEffect(() => {
2839
+ onSelectionChangeRef.current = onSelectionChange;
2840
+ getKeyRef.current = getKey;
2841
+ }, [getKey, onSelectionChange]);
2842
+ useEffect(() => {
2843
+ const notify = onSelectionChangeRef.current;
2844
+ if (!notify) return;
2845
+ const fileSet = new Set(JSON.parse(selectedFileKeySig));
2846
+ const folderSet = new Set(
2847
+ JSON.parse(selectedFolderIdSig)
2848
+ );
2849
+ notify({
2850
+ items: items.filter((item) => fileSet.has(getKeyRef.current(item))),
2851
+ folders: folders.filter((folder) => folderSet.has(folder.id))
2852
+ });
2853
+ }, [folders, items, selectedFileKeySig, selectedFolderIdSig]);
2854
+ const selectionRows = [];
2855
+ if (foldersSelectable) {
2856
+ for (const folder of folders) {
2857
+ selectionRows.push({ kind: "folder", id: folder.id });
2858
+ }
2859
+ }
2860
+ if (filesSelectable) {
2861
+ for (const item of items) {
2862
+ selectionRows.push({ kind: "file", id: getKey(item) });
2863
+ }
2864
+ }
2865
+ function toggleAll(checked) {
2866
+ anchorRef.current = null;
2867
+ setFileKeys(checked ? new Set(visibleFileKeys) : /* @__PURE__ */ new Set());
2868
+ setFolderIds(checked ? new Set(visibleFolderIds) : /* @__PURE__ */ new Set());
2869
+ }
2870
+ function clearSelection() {
2871
+ anchorRef.current = null;
2872
+ setFileKeys(/* @__PURE__ */ new Set());
2873
+ setFolderIds(/* @__PURE__ */ new Set());
2874
+ }
2875
+ function selectAt(index, checked, shift) {
2876
+ const row = selectionRows[index];
2877
+ if (!row) return;
2878
+ if (shift && anchorRef.current != null) {
2879
+ const start = Math.min(anchorRef.current, index);
2880
+ const end = Math.max(anchorRef.current, index);
2881
+ const files = new Set(fileKeys);
2882
+ const nextFolders = new Set(folderIds);
2883
+ for (let cursor = start; cursor <= end; cursor++) {
2884
+ const entry = selectionRows[cursor];
2885
+ if (!entry) continue;
2886
+ if (entry.kind === "file") files.add(entry.id);
2887
+ else nextFolders.add(entry.id);
2888
+ }
2889
+ setFileKeys(files);
2890
+ setFolderIds(nextFolders);
2891
+ return;
2892
+ }
2893
+ if (row.kind === "file") {
2894
+ setFileKeys((current) => replaceMember(current, row.id, checked));
2895
+ } else {
2896
+ setFolderIds((current) => replaceMember(current, row.id, checked));
2897
+ }
2898
+ anchorRef.current = index;
2899
+ }
2900
+ function selectRow(kind, id, checked, shift) {
2901
+ selectAt(
2902
+ selectionRows.findIndex((row) => row.kind === kind && row.id === id),
2903
+ checked,
2904
+ shift
2905
+ );
2906
+ }
2907
+ useEffect(() => {
2908
+ if (!rowsSelectable) return;
2909
+ function onKeyDown(event) {
2910
+ if (event.defaultPrevented) return;
2911
+ if (isFieldTarget(event.target) || isOverlayTarget(event.target)) return;
2912
+ const snapshot = snapshotRef.current;
2913
+ if (event.key === "Escape") {
2914
+ if (!snapshot.selecting) return;
2915
+ event.preventDefault();
2916
+ anchorRef.current = null;
2917
+ setFileKeys(/* @__PURE__ */ new Set());
2918
+ setFolderIds(/* @__PURE__ */ new Set());
2919
+ return;
2920
+ }
2921
+ if (event.code !== "KeyA") return;
2922
+ if (!(event.ctrlKey || event.metaKey) || event.altKey || event.shiftKey) {
2923
+ return;
2924
+ }
2925
+ if (!(event.target instanceof Element)) return;
2926
+ if (!event.target.closest("[data-slot=object-list]")) return;
2927
+ if (snapshot.fileIds.length + snapshot.folderIds.length === 0) return;
2928
+ event.preventDefault();
2929
+ anchorRef.current = null;
2930
+ setFileKeys(new Set(snapshot.fileIds));
2931
+ setFolderIds(new Set(snapshot.folderIds));
2932
+ }
2933
+ document.addEventListener("keydown", onKeyDown);
2934
+ return () => document.removeEventListener("keydown", onKeyDown);
2935
+ }, [rowsSelectable]);
2936
+ async function prepareSelection() {
2937
+ const entries = [];
2938
+ const seen = /* @__PURE__ */ new Set();
2939
+ function add(key, fileName) {
2940
+ if (seen.has(key)) return;
2941
+ seen.add(key);
2942
+ entries.push({ key, fileName });
2943
+ }
2944
+ const objectKeyOf = getObjectKey ?? getKey;
2945
+ for (const item of items) {
2946
+ if (!fileKeys.has(getKey(item))) continue;
2947
+ add(objectKeyOf(item), getFileName?.(item) ?? getLabel(item));
2948
+ }
2949
+ let skippedFolders = 0;
2950
+ for (const folder of folders) {
2951
+ if (!folderIds.has(folder.id)) continue;
2952
+ if (!resolveFolderKeys) {
2953
+ skippedFolders += 1;
2954
+ continue;
2955
+ }
2956
+ for (const key of await resolveFolderKeys(folder)) {
2957
+ add(key, fileNameFromKey(key));
2958
+ }
2959
+ }
2960
+ return { entries, skippedFolders };
2961
+ }
2962
+ return {
2963
+ fileKeys,
2964
+ folderIds,
2965
+ selectedCount,
2966
+ allSelected: visibleCount > 0 && selectedCount === visibleCount,
2967
+ selecting,
2968
+ rowsSelectable,
2969
+ toggleAll,
2970
+ clearSelection,
2971
+ selectRow,
2972
+ prepareSelection
2973
+ };
2974
+ }
2975
+ function isFieldTarget(target) {
2976
+ return target instanceof HTMLElement && (target.isContentEditable || target.tagName === "INPUT" || target.tagName === "TEXTAREA" || target.tagName === "SELECT");
2977
+ }
2978
+ function isOverlayTarget(target) {
2979
+ return target instanceof Element && Boolean(
2980
+ target.closest(
2981
+ "[role=dialog], [role=alertdialog], [role=menu], [data-slot=dropdown-menu-content], [data-slot=alert-dialog-content]"
2982
+ )
2983
+ );
2984
+ }
2985
+ function replaceMember(current, id, checked) {
2986
+ const next = new Set(current);
2987
+ if (checked) next.add(id);
2988
+ else next.delete(id);
2989
+ return next;
2990
+ }
2991
+ function ObjectListSelection({
2992
+ leading,
2993
+ selectedCount,
2994
+ onClear,
2995
+ prepare,
2996
+ removeMany,
2997
+ actions,
2998
+ onThisPage = false,
2999
+ onDeleted
3000
+ }) {
3001
+ const t = useTranslations();
3002
+ const [phase, setPhase] = useState(
3003
+ "idle"
3004
+ );
3005
+ const [planned, setPlanned] = useState(null);
3006
+ const [note, setNote] = useState(
3007
+ null
3008
+ );
3009
+ const visibleNote = note?.count === selectedCount ? note.text : null;
3010
+ const deletingRef = useRef(false);
3011
+ const mountedRef = useRef(true);
3012
+ const busy = phase === "prepare" || phase === "delete";
3013
+ useEffect(() => {
3014
+ mountedRef.current = true;
3015
+ return () => {
3016
+ mountedRef.current = false;
3017
+ };
3018
+ }, []);
3019
+ function showNote(text) {
3020
+ setNote(text === null ? null : { count: selectedCount, text });
3021
+ }
3022
+ function setPhaseIfMounted(next) {
3023
+ if (mountedRef.current) setPhase(next);
3024
+ }
3025
+ async function requestDelete() {
3026
+ if (!removeMany || busy) return;
3027
+ showNote(null);
3028
+ setPhase("prepare");
3029
+ try {
3030
+ const next = await prepare();
3031
+ if (!mountedRef.current) return;
3032
+ if (next.entries.length === 0) {
3033
+ showNote(
3034
+ next.skippedFolders > 0 ? t("Selected folders stay in the list.", {
3035
+ note: "object list selection"
3036
+ }) : t("Nothing to delete", { note: "object list selection" })
3037
+ );
3038
+ setPhase("idle");
3039
+ return;
3040
+ }
3041
+ setPlanned(next);
3042
+ setPhase("confirm");
3043
+ } catch {
3044
+ if (!mountedRef.current) return;
3045
+ showNote(
3046
+ t("Could not delete the selection", {
3047
+ note: "object list selection"
3048
+ })
3049
+ );
3050
+ setPhase("idle");
3051
+ }
3052
+ }
3053
+ async function confirmDelete() {
3054
+ const current = planned;
3055
+ if (!current || !removeMany || deletingRef.current) return;
3056
+ deletingRef.current = true;
3057
+ setPhase("delete");
3058
+ const deleted = [];
3059
+ const failed = [];
3060
+ try {
3061
+ const keys = current.entries.map((entry) => entry.key);
3062
+ for (let index = 0; index < keys.length; index += DELETE_BATCH_MAX_KEYS) {
3063
+ const chunk = keys.slice(index, index + DELETE_BATCH_MAX_KEYS);
3064
+ const result = await removeMany(chunk);
3065
+ deleted.push(...result.deleted);
3066
+ failed.push(...result.failed);
3067
+ }
3068
+ } finally {
3069
+ deletingRef.current = false;
3070
+ setPhaseIfMounted("idle");
3071
+ }
3072
+ if (deleted.length > 0) {
3073
+ toast.add({
3074
+ type: "success",
3075
+ title: t("Deleted {count} files", {
3076
+ note: "object list selection",
3077
+ variables: { count: String(deleted.length) }
3078
+ })
3079
+ });
3080
+ }
3081
+ if (failed.length > 0) {
3082
+ toast.add({
3083
+ type: "error",
3084
+ title: t("Could not delete {count} files", {
3085
+ note: "object list selection",
3086
+ variables: { count: String(failed.length) }
3087
+ })
3088
+ });
3089
+ }
3090
+ onDeleted?.({ deleted, failed });
3091
+ }
3092
+ if (selectedCount === 0) return null;
3093
+ const deleteLabel = t("Delete", { note: "button" });
3094
+ const clearLabel = t("Clear", { note: "object list selection" });
3095
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
3096
+ /* @__PURE__ */ jsxs("div", { className: "flex min-h-11 min-w-0 items-center gap-2 py-1.5 ps-1.5 pe-1", children: [
3097
+ leading,
3098
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 items-center justify-between gap-2", children: [
3099
+ /* @__PURE__ */ jsxs(
3100
+ "p",
3101
+ {
3102
+ "aria-live": "polite",
3103
+ className: "min-w-0 flex-1 truncate text-sm text-dimah-s3-foreground",
3104
+ children: [
3105
+ /* @__PURE__ */ jsx("span", { className: "font-medium tabular-nums", children: onThisPage ? t("{count} selected on this page", {
3106
+ note: "object list selection",
3107
+ variables: { count: String(selectedCount) }
3108
+ }) : t("{count} selected", {
3109
+ note: "object list selection",
3110
+ variables: { count: String(selectedCount) }
3111
+ }) }),
3112
+ visibleNote ? /* @__PURE__ */ jsx("span", { className: "ms-2 font-normal text-dimah-s3-muted-foreground", children: visibleNote }) : null
3113
+ ]
3114
+ }
3115
+ ),
3116
+ /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-1", children: [
3117
+ actions ? /* @__PURE__ */ jsx(
3118
+ "div",
3119
+ {
3120
+ className: cn(
3121
+ "flex items-center gap-1",
3122
+ busy && "pointer-events-none opacity-60"
3123
+ ),
3124
+ children: actions
3125
+ }
3126
+ ) : null,
3127
+ removeMany ? /* @__PURE__ */ jsxs(
3128
+ Button,
3129
+ {
3130
+ variant: "destructive",
3131
+ size: "sm",
3132
+ "aria-label": deleteLabel,
3133
+ disabled: busy,
3134
+ onClick: () => {
3135
+ void requestDelete();
3136
+ },
3137
+ children: [
3138
+ phase === "prepare" || phase === "delete" ? /* @__PURE__ */ jsx(Spinner, { "data-icon": "inline-start" }) : /* @__PURE__ */ jsx(Trash2Icon, { "data-icon": "inline-start" }),
3139
+ /* @__PURE__ */ jsx("span", { className: "max-sm:sr-only", children: deleteLabel })
3140
+ ]
3141
+ }
3142
+ ) : null,
3143
+ /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "sm", disabled: busy, onClick: onClear, children: clearLabel })
3144
+ ] })
3145
+ ] })
3146
+ ] }),
3147
+ /* @__PURE__ */ jsx(
3148
+ AlertDialog,
3149
+ {
3150
+ open: phase === "confirm" && planned != null,
3151
+ onOpenChange: (open) => {
3152
+ if (!open && !deletingRef.current) setPhase("idle");
3153
+ },
3154
+ children: /* @__PURE__ */ jsxs(AlertDialogContent, { children: [
3155
+ /* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
3156
+ /* @__PURE__ */ jsx(AlertDialogTitle, { children: t("Delete {count} files?", {
3157
+ note: "object list selection",
3158
+ variables: { count: String(planned?.entries.length ?? 0) }
3159
+ }) }),
3160
+ /* @__PURE__ */ jsxs(AlertDialogDescription, { children: [
3161
+ t("This action cannot be undone.", {
3162
+ note: "object list selection"
3163
+ }),
3164
+ planned && planned.skippedFolders > 0 ? ` ${t("Selected folders stay in the list.", { note: "object list selection" })}` : null
3165
+ ] })
3166
+ ] }),
3167
+ /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
3168
+ /* @__PURE__ */ jsx(AlertDialogCancel, { children: t("Cancel", { note: "dialog button" }) }),
3169
+ /* @__PURE__ */ jsx(
3170
+ AlertDialogAction,
3171
+ {
3172
+ variant: "destructive",
3173
+ onClick: () => {
3174
+ void confirmDelete();
3175
+ },
3176
+ children: t("Delete", { note: "dialog confirm" })
3177
+ }
3178
+ )
3179
+ ] })
3180
+ ] })
3181
+ }
3182
+ )
3183
+ ] });
3184
+ }
3185
+ function Empty({ className, ...props }) {
3186
+ return /* @__PURE__ */ jsx(
3187
+ "div",
3188
+ {
3189
+ "data-slot": "empty",
3190
+ className: cn(
3191
+ "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",
3192
+ className
3193
+ ),
3194
+ ...props
3195
+ }
3196
+ );
3197
+ }
3198
+ function EmptyHeader({ className, ...props }) {
3199
+ return /* @__PURE__ */ jsx(
3200
+ "div",
3201
+ {
3202
+ "data-slot": "empty-header",
3203
+ className: cn("flex max-w-sm flex-col items-center gap-2", className),
3204
+ ...props
3205
+ }
3206
+ );
3207
+ }
3208
+ var emptyMediaVariants = cva(
3209
+ "mb-2 flex shrink-0 items-center justify-center [&_svg]:pointer-events-none [&_svg]:shrink-0",
3210
+ {
3211
+ variants: {
3212
+ variant: {
3213
+ default: "bg-transparent",
3214
+ icon: "flex size-8 shrink-0 items-center justify-center rounded-lg bg-muted text-foreground [&_svg:not([class*='size-'])]:size-4"
3215
+ }
3216
+ },
3217
+ defaultVariants: {
3218
+ variant: "default"
3219
+ }
3220
+ }
3221
+ );
3222
+ function EmptyMedia({
3223
+ className,
3224
+ variant = "default",
3225
+ ...props
3226
+ }) {
3227
+ return /* @__PURE__ */ jsx(
3228
+ "div",
3229
+ {
3230
+ "data-slot": "empty-icon",
3231
+ "data-variant": variant,
3232
+ className: cn(emptyMediaVariants({ variant, className })),
3233
+ ...props
3234
+ }
3235
+ );
3236
+ }
3237
+ function EmptyTitle({ className, ...props }) {
3238
+ return /* @__PURE__ */ jsx(
3239
+ "div",
3240
+ {
3241
+ "data-slot": "empty-title",
3242
+ className: cn(
3243
+ "cn-font-heading text-sm font-medium tracking-tight",
3244
+ className
3245
+ ),
3246
+ ...props
3247
+ }
3248
+ );
3249
+ }
3250
+ function EmptyDescription({ className, ...props }) {
3251
+ return /* @__PURE__ */ jsx(
3252
+ "div",
3253
+ {
3254
+ "data-slot": "empty-description",
3255
+ className: cn(
3256
+ "text-sm/relaxed text-muted-foreground [&>a]:underline [&>a]:underline-offset-4 [&>a:hover]:text-primary",
3257
+ className
3258
+ ),
3259
+ ...props
3260
+ }
3261
+ );
3262
+ }
3263
+ function EmptyContent({ className, ...props }) {
3264
+ return /* @__PURE__ */ jsx(
3265
+ "div",
3266
+ {
3267
+ "data-slot": "empty-content",
3268
+ className: cn(
3269
+ "flex w-full max-w-sm min-w-0 flex-col items-center gap-2.5 text-sm text-balance",
3270
+ className
3271
+ ),
3272
+ ...props
3273
+ }
3274
+ );
3275
+ }
3276
+ function Skeleton({ className, ...props }) {
3277
+ return /* @__PURE__ */ jsx(
3278
+ "div",
3279
+ {
3280
+ "data-slot": "skeleton",
3281
+ className: cn("animate-pulse rounded-md bg-muted", className),
3282
+ ...props
3283
+ }
3284
+ );
3285
+ }
3286
+ function ObjectListEmpty({
3287
+ title,
3288
+ description
3289
+ }) {
3290
+ return /* @__PURE__ */ jsx(Empty, { className: "border-0", children: /* @__PURE__ */ jsxs(EmptyHeader, { children: [
3291
+ /* @__PURE__ */ jsx(FolderGlyph, { className: "mb-1 size-12" }),
3292
+ /* @__PURE__ */ jsx(EmptyTitle, { children: title }),
3293
+ /* @__PURE__ */ jsx(EmptyDescription, { children: description })
3294
+ ] }) });
3295
+ }
3296
+ function ObjectListError({
3297
+ message,
3298
+ onRetry
3299
+ }) {
3300
+ const t = useTranslations();
3301
+ return /* @__PURE__ */ jsxs(Empty, { className: "border-0", children: [
3302
+ /* @__PURE__ */ jsxs(EmptyHeader, { children: [
3303
+ /* @__PURE__ */ jsx(EmptyMedia, { variant: "icon", children: /* @__PURE__ */ jsx(AlertCircleIcon, {}) }),
3304
+ /* @__PURE__ */ jsx(EmptyTitle, { children: t("Could not load files", { note: "object list" }) }),
3305
+ message ? /* @__PURE__ */ jsx(EmptyDescription, { className: "[overflow-wrap:anywhere]", children: message }) : null
3306
+ ] }),
3307
+ onRetry ? /* @__PURE__ */ jsx(EmptyContent, { children: /* @__PURE__ */ jsx(ObjectListRetry, { onRetry }) }) : null
3308
+ ] });
3309
+ }
3310
+ function ObjectListErrorBanner({
3311
+ message,
3312
+ onRetry
3313
+ }) {
3314
+ return /* @__PURE__ */ jsxs(
3315
+ "div",
3316
+ {
3317
+ role: "alert",
3318
+ className: "flex items-center justify-between gap-3 border-t border-dimah-s3-border px-3 py-2",
3319
+ children: [
3320
+ /* @__PURE__ */ jsx("p", { className: "min-w-0 text-sm [overflow-wrap:anywhere] text-dimah-s3-destructive", children: message }),
3321
+ /* @__PURE__ */ jsx(ObjectListRetry, { onRetry })
3322
+ ]
3323
+ }
3324
+ );
3325
+ }
3326
+ function ObjectListRetry({
3327
+ onRetry
3328
+ }) {
3329
+ const t = useTranslations();
3330
+ if (!onRetry) return null;
3331
+ return /* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: () => void onRetry(), children: t("Retry", { note: "object list" }) });
3332
+ }
3333
+ function ObjectListSkeleton() {
3334
+ return /* @__PURE__ */ jsx("div", { className: "flex flex-col", children: ["a", "b", "c", "d"].map((key) => /* @__PURE__ */ jsxs(
3335
+ "div",
3336
+ {
3337
+ className: "flex min-h-11 items-center gap-2 py-1 ps-1.5 pe-1",
3338
+ children: [
3339
+ /* @__PURE__ */ jsx(Skeleton, { className: "size-8 rounded-sm" }),
3340
+ /* @__PURE__ */ jsxs("div", { className: "flex min-w-0 flex-1 flex-col gap-1", children: [
3341
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-3.5 w-40 max-w-full" }),
3342
+ /* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-16 max-w-full" })
3343
+ ] })
3344
+ ]
3345
+ },
3346
+ key
3347
+ )) });
3348
+ }
3349
+ function ObjectListContinue({
3350
+ active,
3351
+ pending,
3352
+ blocked,
3353
+ loadMore,
3354
+ root,
3355
+ ready
3356
+ }) {
3357
+ const t = useTranslations();
3358
+ const sentinelRef = useRef(null);
3359
+ const loadMoreRef = useRef(loadMore);
3360
+ useEffect(() => {
3361
+ loadMoreRef.current = loadMore;
3362
+ }, [loadMore]);
3363
+ useEffect(() => {
3364
+ const node = sentinelRef.current;
3365
+ if (!node || !ready || !active || pending || blocked) return;
3366
+ const observer = new IntersectionObserver(
3367
+ (entries) => {
3368
+ if (!entries.some((entry) => entry.isIntersecting)) return;
3369
+ void loadMoreRef.current?.();
3370
+ },
3371
+ { root, rootMargin: "48px" }
3372
+ );
3373
+ observer.observe(node);
3374
+ return () => observer.disconnect();
3375
+ }, [active, blocked, pending, ready, root]);
3376
+ if (!active && !pending) return null;
3377
+ return /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 flex-col", children: [
3378
+ pending ? /* @__PURE__ */ jsx("div", { className: "flex justify-center py-2", children: /* @__PURE__ */ jsx(Spinner, { "aria-label": t("Loading files", { note: "object list" }) }) }) : null,
3379
+ active ? /* @__PURE__ */ jsx("div", { ref: sentinelRef, "aria-hidden": true, className: "h-px w-full shrink-0" }) : null
3380
+ ] });
3381
+ }
3382
+ function useRefreshListAfterUpload(upload, refresh) {
3383
+ const tokenRef = useRef(null);
3384
+ const refreshRef = useRef(refresh);
3385
+ const successIds = upload?.files.filter((file) => file.status === "success").map((file) => file.id).join("\0") ?? "";
3386
+ const settled = upload != null && !upload.isPending && upload.phase !== "idle";
3387
+ useEffect(() => {
3388
+ refreshRef.current = refresh;
3389
+ }, [refresh]);
3390
+ useEffect(() => {
3391
+ if (!settled) {
3392
+ tokenRef.current = null;
3393
+ return;
3394
+ }
3395
+ if (!successIds) return;
3396
+ if (tokenRef.current === successIds) return;
3397
+ tokenRef.current = successIds;
3398
+ void refreshRef.current?.();
3399
+ }, [settled, successIds]);
3400
+ }
3401
+ function ObjectListUpload({ upload }) {
3402
+ const { statusNode } = useUploadUi(upload);
3403
+ if (upload.phase === "idle" || upload.phase === "success") return null;
3404
+ return /* @__PURE__ */ jsx("div", { className: "border-b border-dimah-s3-border px-3 py-2", children: statusNode });
3405
+ }
3406
+ function ObjectListDropOverlay({ upload }) {
3407
+ const t = useTranslations();
3408
+ const dropLabel = upload.isDragReject ? t("These files cannot be uploaded", { note: "object list" }) : t("Drop to upload into this folder", { note: "object list" });
3409
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
3410
+ upload.isDragActive ? /* @__PURE__ */ jsx(
3411
+ "div",
3412
+ {
3413
+ "aria-hidden": true,
3414
+ className: "pointer-events-none absolute inset-0 z-10 flex items-center justify-center bg-dimah-s3-card/80 p-6",
3415
+ children: /* @__PURE__ */ jsx(
3416
+ "p",
3417
+ {
3418
+ className: cn(
3419
+ "rounded-md border border-dashed px-3 py-2 text-sm",
3420
+ upload.isDragReject ? "border-dimah-s3-destructive text-dimah-s3-destructive" : "border-dimah-s3-primary text-dimah-s3-primary"
3421
+ ),
3422
+ children: dropLabel
3423
+ }
3424
+ )
3425
+ }
3426
+ ) : null,
3427
+ /* @__PURE__ */ jsx("div", { className: "sr-only", "aria-live": "polite", children: upload.isDragActive ? dropLabel : "" })
3428
+ ] });
3429
+ }
3430
+ function ObjectListUsageLine({
3431
+ usage,
3432
+ limits
3433
+ }) {
3434
+ const t = useTranslations();
3435
+ const byteCap = finiteCap(limits?.maxBytes);
3436
+ const fileCap = finiteCap(limits?.maxFiles);
3437
+ const bytesLabel = byteCap == null ? formatFileSize(usage.totalBytes) : t("{used} of {max}", {
3438
+ note: "object list usage",
3439
+ variables: {
3440
+ used: formatFileSize(usage.totalBytes),
3441
+ max: formatFileSize(byteCap)
3442
+ }
3443
+ });
3444
+ const filesLabel = fileCap == null ? usage.objectCount === 1 ? t("1 file", { note: "object list usage" }) : t("{count} files", {
3445
+ note: "object list usage",
3446
+ variables: { count: String(usage.objectCount) }
3447
+ }) : t("{count} of {max} files", {
3448
+ note: "object list usage",
3449
+ variables: {
3450
+ count: String(usage.objectCount),
3451
+ max: String(fileCap)
3452
+ }
3453
+ });
3454
+ const byteRatio = fillRatio(usage.totalBytes, byteCap);
3455
+ const fileRatio = fillRatio(usage.objectCount, fileCap);
3456
+ const tightest = tightestRatio(byteRatio, fileRatio);
3457
+ const over = tightest != null && tightest >= 1;
3458
+ const percent = tightest == null ? null : Math.min(100, Math.round(tightest * 100));
3459
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-1.5 border-b border-dimah-s3-border px-3 py-2", children: [
3460
+ /* @__PURE__ */ jsxs(
3461
+ "p",
3462
+ {
3463
+ className: cn(
3464
+ "text-xs tabular-nums",
3465
+ over ? "text-dimah-s3-destructive" : "text-dimah-s3-muted-foreground"
3466
+ ),
3467
+ children: [
3468
+ bytesLabel,
3469
+ /* @__PURE__ */ jsx("span", { "aria-hidden": true, children: " \xB7 " }),
3470
+ filesLabel
3471
+ ]
3472
+ }
3473
+ ),
3474
+ percent != null ? /* @__PURE__ */ jsx(
3475
+ "div",
3476
+ {
3477
+ className: "flex h-1 overflow-hidden rounded-full bg-dimah-s3-muted",
3478
+ "aria-hidden": true,
3479
+ children: /* @__PURE__ */ jsx(
3480
+ "div",
3481
+ {
3482
+ className: cn(
3483
+ "h-full",
3484
+ over ? "bg-dimah-s3-destructive" : "bg-dimah-s3-primary"
3485
+ ),
3486
+ style: { width: `${percent}%` }
3487
+ }
3488
+ )
3489
+ }
3490
+ ) : null
3491
+ ] });
3492
+ }
3493
+ function finiteCap(value) {
3494
+ if (value == null || !Number.isFinite(value) || value < 0) return null;
3495
+ return value;
3496
+ }
3497
+ function fillRatio(used, max) {
3498
+ if (max == null) return null;
3499
+ if (max === 0) return used > 0 ? 1 : 0;
3500
+ return used / max;
3501
+ }
3502
+ function tightestRatio(byteRatio, fileRatio) {
3503
+ if (byteRatio == null) return fileRatio;
3504
+ if (fileRatio == null) return byteRatio;
3505
+ return Math.max(byteRatio, fileRatio);
3506
+ }
3507
+ function ObjectList(props) {
3508
+ useRefreshListAfterUpload(props.upload, props.list.refresh);
3509
+ return /* @__PURE__ */ jsx(ObjectListFrame, { ...props }, props.list.parent ?? "");
3510
+ }
3511
+ function ObjectListFrame({
3512
+ list,
3513
+ getKey,
3514
+ getLabel,
3515
+ getDescription,
3516
+ getFileName,
3517
+ getFileType,
3518
+ getPreviewUrl,
3519
+ renderItem,
3520
+ renderFolder,
3521
+ renderActions,
3522
+ renderMeta,
3523
+ onOpenItem,
3524
+ renderFolderActions,
3525
+ header,
3526
+ rootLabel,
3527
+ breadcrumb = true,
3528
+ emptyTitle,
3529
+ emptyDescription,
3530
+ empty,
3531
+ className,
3532
+ height,
3533
+ maxHeight,
3534
+ selectable = false,
3535
+ getObjectKey,
3536
+ resolveFolderKeys,
3537
+ delete: remove,
3538
+ onSelectionChange,
3539
+ selectionActions,
3540
+ onDeleted,
3541
+ upload,
3542
+ usageLimits
3543
+ }) {
3544
+ const t = useTranslations();
3545
+ const formatError = useFormatDimahError();
3546
+ const folders = useMemo(() => list.folders ?? [], [list.folders]);
3547
+ const trail = list.trail ?? [];
3548
+ const isLoading = list.isLoading === true;
3549
+ const isRefreshing = list.isRefreshing === true;
3550
+ const label = rootLabel ?? t("Files", { note: "object list" });
3551
+ const errorMessage = list.error ? formatError(list.error) : null;
3552
+ const showRows = folders.length > 0 || list.items.length > 0;
3553
+ const showEmpty = !isLoading && !list.error && !showRows;
3554
+ const showInitialError = !isLoading && list.error != null && !showRows;
3555
+ const canSelect = selectable || remove != null || selectionActions != null || onSelectionChange != null;
3556
+ const filesSelectable = canSelect && renderItem == null;
3557
+ const foldersSelectable = canSelect && resolveFolderKeys != null && renderFolder == null;
3558
+ const selection = useObjectListSelection({
3559
+ items: list.items,
3560
+ folders,
3561
+ filesSelectable,
3562
+ foldersSelectable,
3563
+ getKey,
3564
+ getLabel,
3565
+ getFileName,
3566
+ getObjectKey,
3567
+ resolveFolderKeys,
3568
+ onSelectionChange
3569
+ });
3570
+ const [scroller, setScroller] = useState(null);
3571
+ const showHeader = breadcrumb || header != null || isRefreshing || selection.rowsSelectable && showRows;
3572
+ const pageLimited = list.hasMore === true;
3573
+ const busy = isLoading || isRefreshing || list.isLoadingMore === true;
3574
+ const frameHeight = cssLength(height);
3575
+ const frameMaxHeight = cssLength(maxHeight);
3576
+ const sized = frameHeight != null || frameMaxHeight != null;
3577
+ const frameStyle = sized ? {
3578
+ ...frameHeight != null ? { height: frameHeight } : {},
3579
+ ...frameMaxHeight != null ? { maxHeight: frameMaxHeight } : {}
3580
+ } : void 0;
3581
+ const frameClassName = cn(
3582
+ "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",
3583
+ sized && "min-h-0",
3584
+ upload?.isDragReject && "border-dimah-s3-destructive bg-dimah-s3-destructive/5",
3585
+ upload?.isDragAccept && "border-dimah-s3-primary bg-dimah-s3-primary/5",
3586
+ upload?.isDragActive && !upload.isDragAccept && !upload.isDragReject && "border-dimah-s3-primary/50",
3587
+ className
3588
+ );
3589
+ const frameProps = {
3590
+ "data-slot": "object-list",
3591
+ "aria-label": label,
3592
+ "aria-busy": busy || void 0,
3593
+ className: frameClassName
3594
+ };
3595
+ const selectAll = selection.rowsSelectable && showRows ? /* @__PURE__ */ jsx(
3596
+ SelectCheckbox,
3597
+ {
3598
+ checked: selection.allSelected,
3599
+ indeterminate: selection.selectedCount > 0 && !selection.allSelected,
3600
+ label: pageLimited ? t("Select this page", { note: "object list selection" }) : t("Select all", { note: "object list selection" }),
3601
+ onCheckedChange: (checked) => selection.toggleAll(checked)
3602
+ }
3603
+ ) : null;
3604
+ const sectionProps = {
3605
+ ...upload ? upload.getRootProps({
3606
+ ...frameProps,
3607
+ role: "region",
3608
+ tabIndex: void 0,
3609
+ "aria-disabled": void 0,
3610
+ onClick: (event) => {
3611
+ event.stopPropagation();
3612
+ }
3613
+ }) : frameProps,
3614
+ ...frameStyle ? { style: frameStyle } : {}
3615
+ };
3616
+ const emptyDescriptionText = emptyDescription ?? (upload ? t("Drop files here to add them to this folder.", {
3617
+ note: "object list"
3618
+ }) : t("Files and folders you add here will show up in this list.", {
3619
+ note: "object list"
3620
+ }));
3621
+ return /* @__PURE__ */ jsxs("section", { ...sectionProps, children: [
3622
+ /* @__PURE__ */ jsxs("div", { className: "shrink-0", children: [
3623
+ showHeader ? /* @__PURE__ */ jsx(
3624
+ "div",
3625
+ {
3626
+ className: cn(
3627
+ "border-b border-dimah-s3-border",
3628
+ selection.selecting && "bg-dimah-s3-primary/10"
3629
+ ),
3630
+ children: selection.selecting ? /* @__PURE__ */ jsx(
3631
+ ObjectListSelection,
3632
+ {
3633
+ leading: selectAll,
3634
+ selectedCount: selection.selectedCount,
3635
+ onClear: selection.clearSelection,
3636
+ prepare: selection.prepareSelection,
3637
+ removeMany: remove?.removeMany,
3638
+ actions: selectionActions,
3639
+ onThisPage: pageLimited,
3640
+ onDeleted: (result) => {
3641
+ selection.clearSelection();
3642
+ onDeleted?.(result);
3643
+ if (result.deleted.length > 0) void list.refresh?.();
3644
+ }
3645
+ }
3646
+ ) : /* @__PURE__ */ jsxs("div", { className: "flex min-h-11 min-w-0 items-center gap-2 py-1.5 ps-1.5 pe-1", children: [
3647
+ selectAll,
3648
+ breadcrumb ? /* @__PURE__ */ jsx(
3649
+ ObjectListBreadcrumb,
3650
+ {
3651
+ rootLabel: label,
3652
+ trail,
3653
+ navigate: list.navigate
3654
+ }
3655
+ ) : /* @__PURE__ */ jsx("div", { className: "min-w-0 flex-1" }),
3656
+ /* @__PURE__ */ jsxs("div", { className: "flex shrink-0 items-center gap-2", children: [
3657
+ isRefreshing ? /* @__PURE__ */ jsx(
3658
+ Spinner,
3659
+ {
3660
+ "aria-label": t("Loading files", { note: "object list" })
3661
+ }
3662
+ ) : null,
3663
+ header
3664
+ ] })
3665
+ ] })
3666
+ }
3667
+ ) : null,
3668
+ list.usage ? /* @__PURE__ */ jsx(ObjectListUsageLine, { usage: list.usage, limits: usageLimits }) : null,
3669
+ upload ? /* @__PURE__ */ jsx(ObjectListUpload, { upload }) : null
3670
+ ] }),
3671
+ /* @__PURE__ */ jsxs(
3672
+ "div",
3673
+ {
3674
+ ref: sized ? setScroller : void 0,
3675
+ className: sized ? cn(
3676
+ "flex min-h-0 flex-col overflow-y-auto overscroll-y-contain",
3677
+ frameHeight != null ? "flex-1" : "flex-auto"
3678
+ ) : void 0,
3679
+ children: [
3680
+ isLoading ? /* @__PURE__ */ jsx(ObjectListSkeleton, {}) : null,
3681
+ showInitialError ? /* @__PURE__ */ jsx(ObjectListError, { message: errorMessage, onRetry: list.refresh }) : null,
3682
+ showEmpty ? empty ?? /* @__PURE__ */ jsx(
3683
+ ObjectListEmpty,
3684
+ {
3685
+ title: emptyTitle ?? t("This folder is empty", { note: "object list" }),
3686
+ description: emptyDescriptionText
3687
+ }
3688
+ ) : null,
3689
+ showRows ? /* @__PURE__ */ jsx(
3690
+ ObjectListRows,
3691
+ {
3692
+ items: list.items,
3693
+ folders,
3694
+ getKey,
3695
+ getLabel,
3696
+ getDescription,
3697
+ getFileName,
3698
+ getFileType,
3699
+ getPreviewUrl,
3700
+ renderItem,
3701
+ renderFolder,
3702
+ renderActions,
3703
+ renderMeta,
3704
+ onOpenItem,
3705
+ renderFolderActions,
3706
+ openFolder: list.openFolder,
3707
+ filesSelectable,
3708
+ foldersSelectable,
3709
+ fileKeys: selection.fileKeys,
3710
+ folderIds: selection.folderIds,
3711
+ selectRow: selection.selectRow
3712
+ }
3713
+ ) : null,
3714
+ showRows && errorMessage ? /* @__PURE__ */ jsx(
3715
+ ObjectListErrorBanner,
3716
+ {
3717
+ message: errorMessage,
3718
+ onRetry: list.refresh
3719
+ }
3720
+ ) : null,
3721
+ /* @__PURE__ */ jsx(
3722
+ ObjectListContinue,
3723
+ {
3724
+ active: list.hasMore === true && list.loadMore != null,
3725
+ pending: list.isLoadingMore === true,
3726
+ blocked: list.error != null,
3727
+ loadMore: list.loadMore,
3728
+ root: sized ? scroller : null,
3729
+ ready: !sized || scroller != null
3730
+ }
3731
+ )
3732
+ ]
3733
+ }
3734
+ ),
3735
+ upload ? /* @__PURE__ */ jsx(ObjectListDropOverlay, { upload }) : null
3736
+ ] });
3737
+ }
3738
+ function cssLength(value) {
3739
+ if (typeof value === "number")
3740
+ return Number.isFinite(value) ? value : void 0;
3741
+ if (typeof value !== "string") return void 0;
3742
+ const trimmed = value.trim();
3743
+ return trimmed.length > 0 ? trimmed : void 0;
3744
+ }
3745
+ function durationParts(seconds) {
3746
+ const safe = Math.max(1, Math.round(seconds));
3747
+ if (safe >= 86400) {
3748
+ return { unit: "day", count: Math.max(1, Math.round(safe / 86400)) };
3749
+ }
3750
+ if (safe >= 3600) {
3751
+ return { unit: "hour", count: Math.max(1, Math.round(safe / 3600)) };
3752
+ }
3753
+ if (safe >= 60) {
3754
+ return { unit: "minute", count: Math.max(1, Math.round(safe / 60)) };
3755
+ }
3756
+ return { unit: "second", count: safe };
3757
+ }
3758
+ function useShareExpiryLabel() {
3759
+ const t = useTranslations();
3760
+ return (seconds) => {
3761
+ if (seconds <= 0) {
3762
+ return t("This link works while you can access this file.", {
3763
+ note: "object list menu"
3764
+ });
3765
+ }
3766
+ const { unit, count } = durationParts(seconds);
3767
+ const value = String(count);
3768
+ if (unit === "day") {
3769
+ return count === 1 ? t("Expires in 1 day", { note: "object list menu" }) : t("Expires in {count} days", {
3770
+ note: "object list menu",
3771
+ variables: { count: value }
3772
+ });
3773
+ }
3774
+ if (unit === "hour") {
3775
+ return count === 1 ? t("Expires in 1 hour", { note: "object list menu" }) : t("Expires in {count} hours", {
3776
+ note: "object list menu",
3777
+ variables: { count: value }
3778
+ });
3779
+ }
3780
+ if (unit === "minute") {
3781
+ return count === 1 ? t("Expires in 1 minute", { note: "object list menu" }) : t("Expires in {count} minutes", {
3782
+ note: "object list menu",
3783
+ variables: { count: value }
3784
+ });
3785
+ }
3786
+ return count === 1 ? t("Expires in 1 second", { note: "object list menu" }) : t("Expires in {count} seconds", {
3787
+ note: "object list menu",
3788
+ variables: { count: value }
3789
+ });
3790
+ };
3791
+ }
3792
+ function ObjectListMenu({
3793
+ objectKey,
3794
+ fileName,
3795
+ fileSize,
3796
+ download,
3797
+ share,
3798
+ expiresIn,
3799
+ delete: remove,
3800
+ onDeleted,
3801
+ actions
3802
+ }) {
3803
+ const t = useTranslations();
3804
+ const expiryLabel = useShareExpiryLabel();
3805
+ const linkSource = share ?? download;
3806
+ const [copying, setCopying] = useState(false);
3807
+ useRowDeleted(remove, objectKey, onDeleted);
3808
+ const downloadPending = download != null && download.isPending && download.objectKey === objectKey;
3809
+ const deleting = remove != null && remove.isDeleting;
3810
+ async function onCopyLink() {
3811
+ if (!linkSource || copying) return;
3812
+ setCopying(true);
3813
+ try {
3814
+ const result = await linkSource.presignMany([
3815
+ {
3816
+ key: objectKey,
3817
+ fileName,
3818
+ ...expiresIn != null ? { expiresIn } : {}
3819
+ }
3820
+ ]);
3821
+ const signed = result.signed[0];
3822
+ if (!signed) {
3823
+ toast.add({
3824
+ type: "error",
3825
+ title: t("Could not create link", { note: "object list menu" })
3826
+ });
3827
+ return;
3828
+ }
3829
+ try {
3830
+ await navigator.clipboard.writeText(signed.url);
3831
+ } catch {
3832
+ toast.add({
3833
+ type: "error",
3834
+ title: t("Could not copy link", { note: "object list menu" }),
3835
+ description: signed.url
3836
+ });
3837
+ return;
3838
+ }
3839
+ toast.add({
3840
+ type: "success",
3841
+ title: t("Link copied", { note: "object list menu" }),
3842
+ description: expiryLabel(signed.expiresIn)
3843
+ });
3844
+ } catch {
3845
+ toast.add({
3846
+ type: "error",
3847
+ title: t("Could not create link", { note: "object list menu" })
3848
+ });
3849
+ } finally {
3850
+ setCopying(false);
3851
+ }
3852
+ }
3853
+ const extra = actions ?? [];
3854
+ const showTransfer = download != null || linkSource != null;
3855
+ const showExtra = extra.length > 0;
3856
+ const showDelete = remove != null;
3857
+ if (!showTransfer && !showExtra && !showDelete) return null;
3858
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
3859
+ download ? /* @__PURE__ */ jsx(
3860
+ DownloadToasts,
3861
+ {
3862
+ download,
3863
+ objectKey,
3864
+ fileName
3865
+ }
3866
+ ) : null,
3867
+ /* @__PURE__ */ jsxs(DropdownMenu, { children: [
3868
+ /* @__PURE__ */ jsxs(DropdownMenuTrigger, { render: /* @__PURE__ */ jsx(Button, { variant: "ghost", size: "icon-sm" }), children: [
3869
+ /* @__PURE__ */ jsx(MoreHorizontalIcon, {}),
3870
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: t("File actions", { note: "object list menu" }) })
3871
+ ] }),
3872
+ /* @__PURE__ */ jsxs(DropdownMenuContent, { align: "end", className: "min-w-44", children: [
3873
+ showTransfer ? /* @__PURE__ */ jsxs(DropdownMenuGroup, { children: [
3874
+ download ? /* @__PURE__ */ jsxs(
3875
+ DropdownMenuItem,
3876
+ {
3877
+ disabled: downloadPending,
3878
+ onClick: () => void download.download(objectKey, fileName),
3879
+ children: [
3880
+ downloadPending ? /* @__PURE__ */ jsx(LoaderIcon, { className: "animate-spin" }) : /* @__PURE__ */ jsx(DownloadIcon, {}),
3881
+ t("Download", { note: "button" })
3882
+ ]
3883
+ }
3884
+ ) : null,
3885
+ linkSource ? /* @__PURE__ */ jsxs(
3886
+ DropdownMenuItem,
3887
+ {
3888
+ disabled: copying,
3889
+ onClick: () => void onCopyLink(),
3890
+ children: [
3891
+ copying ? /* @__PURE__ */ jsx(LoaderIcon, { className: "animate-spin" }) : /* @__PURE__ */ jsx(LinkIcon, {}),
3892
+ t("Copy link", { note: "object list menu" })
3893
+ ]
3894
+ }
3895
+ ) : null
3896
+ ] }) : null,
3897
+ showExtra && showTransfer ? /* @__PURE__ */ jsx(DropdownMenuSeparator, {}) : null,
3898
+ showExtra ? /* @__PURE__ */ jsx(DropdownMenuGroup, { children: extra.map((action, index) => /* @__PURE__ */ jsxs(
3899
+ DropdownMenuItem,
3900
+ {
3901
+ variant: action.destructive ? "destructive" : "default",
3902
+ disabled: action.disabled,
3903
+ onClick: () => {
3904
+ action.onClick();
3905
+ },
3906
+ children: [
3907
+ action.icon,
3908
+ action.label
3909
+ ]
3910
+ },
3911
+ `${action.label}-${index}`
3912
+ )) }) : null,
3913
+ showDelete && (showTransfer || showExtra) ? /* @__PURE__ */ jsx(DropdownMenuSeparator, {}) : null,
3914
+ remove ? /* @__PURE__ */ jsx(DropdownMenuGroup, { children: /* @__PURE__ */ jsxs(
3915
+ DropdownMenuItem,
3916
+ {
3917
+ variant: "destructive",
3918
+ disabled: deleting,
3919
+ onClick: () => remove.requestDelete(objectKey),
3920
+ children: [
3921
+ remove.isDeleting && remove.objectKey === objectKey ? /* @__PURE__ */ jsx(LoaderIcon, { className: "animate-spin" }) : /* @__PURE__ */ jsx(Trash2Icon, {}),
3922
+ t("Delete", { note: "button" })
3923
+ ]
3924
+ }
3925
+ ) }) : null
3926
+ ] })
3927
+ ] }),
3928
+ remove ? /* @__PURE__ */ jsx(
3929
+ DeleteConfirm,
3930
+ {
3931
+ remove,
3932
+ objectKey,
3933
+ fileName,
3934
+ fileSize
3935
+ }
3936
+ ) : null
3937
+ ] });
3938
+ }
3939
+ function DownloadToasts({
3940
+ download,
3941
+ objectKey,
3942
+ fileName
3943
+ }) {
3944
+ useDownloadToast(download, { objectKey, fileName });
3945
+ return null;
3946
+ }
3947
+ function DeleteConfirm({
3948
+ remove,
3949
+ objectKey,
3950
+ fileName,
3951
+ fileSize
3952
+ }) {
3953
+ const t = useTranslations();
3954
+ const displayName = fileName ?? fileNameFromKey(objectKey) ?? objectKey;
3955
+ const isThis = remove.objectKey === objectKey;
3956
+ useDeleteToast(remove, { objectKey, displayName });
3957
+ const fileLabel = fileSize != null ? `${truncateFileName(displayName)} (${formatFileSize(fileSize)})` : truncateFileName(displayName);
3958
+ return /* @__PURE__ */ jsx(
3959
+ AlertDialog,
3960
+ {
3961
+ open: remove.isConfirming && isThis,
3962
+ onOpenChange: (open) => {
3963
+ if (!open) remove.cancelDelete();
3964
+ },
3965
+ children: /* @__PURE__ */ jsxs(AlertDialogContent, { children: [
3966
+ /* @__PURE__ */ jsxs(AlertDialogHeader, { children: [
3967
+ /* @__PURE__ */ jsx(AlertDialogMedia, { children: /* @__PURE__ */ jsx(Trash2Icon, {}) }),
3968
+ /* @__PURE__ */ jsx(AlertDialogTitle, { children: t("Delete file?", { note: "dialog title" }) }),
3969
+ /* @__PURE__ */ jsx(
3970
+ AlertDialogDescription,
3971
+ {
3972
+ dir: "auto",
3973
+ className: "[overflow-wrap:anywhere]",
3974
+ children: t(
3975
+ 'Are you sure you want to delete "{name}"? This action cannot be undone.',
3976
+ {
3977
+ note: "dialog description",
3978
+ variables: { name: isolateLtr2(fileLabel) }
3979
+ }
3980
+ )
3981
+ }
3982
+ )
3983
+ ] }),
3984
+ /* @__PURE__ */ jsxs(AlertDialogFooter, { children: [
3985
+ /* @__PURE__ */ jsx(AlertDialogCancel, { children: t("Cancel", { note: "dialog button" }) }),
3986
+ /* @__PURE__ */ jsx(
3987
+ AlertDialogAction,
3988
+ {
3989
+ variant: "destructive",
3990
+ onClick: () => void remove.confirmDelete(),
3991
+ children: t("Delete", { note: "dialog confirm" })
3992
+ }
3993
+ )
3994
+ ] })
3995
+ ] })
3996
+ }
3997
+ );
3998
+ }
3999
+ function isolateLtr2(value) {
4000
+ return `\u2066${value}\u2069`;
4001
+ }
4002
+ function useRowDeleted(remove, objectKey, onDeleted) {
4003
+ const onDeletedRef = useRef(onDeleted);
4004
+ const notified = useRef(false);
4005
+ const phase = remove?.phase;
4006
+ const currentKey = remove?.objectKey;
4007
+ useEffect(() => {
4008
+ onDeletedRef.current = onDeleted;
4009
+ }, [onDeleted]);
4010
+ useEffect(() => {
4011
+ if (phase !== "success" || currentKey !== objectKey) {
4012
+ notified.current = false;
4013
+ return;
4014
+ }
4015
+ if (notified.current) return;
4016
+ notified.current = true;
4017
+ onDeletedRef.current?.();
4018
+ }, [currentKey, objectKey, phase]);
4019
+ }
2176
4020
 
2177
- export { DeleteButton, DownloadButton, FileAttachment, MultiUploadStatus, ProgressDownloadButton, StatusAttachment, Toaster, UploadButton, UploadDropzone, UploadFileStatus, UploadStatus, resolveStatusSlot, toast, useDeleteToast, useDeleteUi, useDownloadToast, useDownloadUi, useFileRejectToast, useUploadToast, useUploadUi };
4021
+ export { DeleteButton, DownloadButton, FileAttachment, MultiUploadStatus, ObjectList, ObjectListMenu, ProgressDownloadButton, StatusAttachment, Toaster, UploadButton, UploadDropzone, UploadFileStatus, UploadStatus, resolveStatusSlot, toast, useDeleteToast, useDeleteUi, useDownloadToast, useDownloadUi, useFileRejectToast, useUploadToast, useUploadUi };
2178
4022
  //# sourceMappingURL=index.js.map
2179
4023
  //# sourceMappingURL=index.js.map