@dimah-s3/react 2.0.0-beta.4 → 2.0.0-beta.6

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 (48) hide show
  1. package/dist/{chunk-SPUUNLXI.js → chunk-VJIUZK62.js} +49 -3
  2. package/dist/chunk-VJIUZK62.js.map +1 -0
  3. package/dist/engine.d.ts +3 -3
  4. package/dist/engine.d.ts.map +1 -1
  5. package/dist/engine.js +3 -15
  6. package/dist/engine.js.map +1 -1
  7. package/dist/helpers/{format-dimah-error.d.ts → format-error.d.ts} +3 -3
  8. package/dist/helpers/format-error.d.ts.map +1 -0
  9. package/dist/helpers/index.d.ts +1 -1
  10. package/dist/helpers/index.d.ts.map +1 -1
  11. package/dist/helpers/use-format-speed.d.ts +2 -1
  12. package/dist/helpers/use-format-speed.d.ts.map +1 -1
  13. package/dist/hooks/use-download.d.ts.map +1 -1
  14. package/dist/hooks/use-fetch-download.d.ts.map +1 -1
  15. package/dist/hooks/use-file-upload.d.ts +7 -3
  16. package/dist/hooks/use-file-upload.d.ts.map +1 -1
  17. package/dist/hooks/use-object-list-selection.d.ts.map +1 -1
  18. package/dist/hooks/use-object-list.d.ts +3 -3
  19. package/dist/hooks/use-object-list.d.ts.map +1 -1
  20. package/dist/hooks/use-upload-limit.d.ts +19 -0
  21. package/dist/hooks/use-upload-limit.d.ts.map +1 -0
  22. package/dist/hooks/use-upload.d.ts +9 -7
  23. package/dist/hooks/use-upload.d.ts.map +1 -1
  24. package/dist/index.d.ts +2 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +170 -64
  27. package/dist/index.js.map +1 -1
  28. package/dist/internal/upload-limits.d.ts +27 -0
  29. package/dist/internal/upload-limits.d.ts.map +1 -0
  30. package/dist/list/entries.d.ts +13 -0
  31. package/dist/list/entries.d.ts.map +1 -1
  32. package/dist/list/types.d.ts +2 -2
  33. package/dist/list/types.d.ts.map +1 -1
  34. package/dist/translations/types.d.ts +2 -1
  35. package/dist/translations/types.d.ts.map +1 -1
  36. package/dist/types/delete.d.ts +6 -3
  37. package/dist/types/delete.d.ts.map +1 -1
  38. package/dist/types/download.d.ts +9 -18
  39. package/dist/types/download.d.ts.map +1 -1
  40. package/dist/types/upload.d.ts +21 -0
  41. package/dist/types/upload.d.ts.map +1 -1
  42. package/package.json +4 -4
  43. package/dist/chunk-SPUUNLXI.js.map +0 -1
  44. package/dist/helpers/format-dimah-error.d.ts.map +0 -1
  45. package/dist/helpers/format-speed.d.ts +0 -10
  46. package/dist/helpers/format-speed.d.ts.map +0 -1
  47. package/dist/helpers/format-upload-progress.d.ts +0 -20
  48. package/dist/helpers/format-upload-progress.d.ts.map +0 -1
@@ -0,0 +1,19 @@
1
+ import type { UploadLimit } from "../types/upload.js";
2
+ import type { UseUploadReturn } from "./use-upload";
3
+ /**
4
+ * Caps the files `upload` takes in at `limit` while the calling component
5
+ * is mounted. `UploadField` uses it for its `maxFiles`.
6
+ *
7
+ * The hook enforces it on every call, wherever it comes from:
8
+ * `handleFiles`, `open`, drops, pastes and `retry`. A call holds its slots
9
+ * from the moment it starts, so two quick calls never take the same ones,
10
+ * and the hook rejects the files past the limit with `TOO_MANY_FILES`. A
11
+ * retry takes only the failed files that fit, in queue order, and leaves
12
+ * the rest as they failed. With several limits on one hook, the strictest
13
+ * wins. `null` sets none.
14
+ *
15
+ * Returns the files that still fit, counting calls still preparing, or
16
+ * `null` without a limit.
17
+ */
18
+ export declare function useUploadLimit(upload: Pick<UseUploadReturn, "instanceId" | "files">, limit: UploadLimit | null): number | null;
19
+ //# sourceMappingURL=use-upload-limit.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-upload-limit.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload-limit.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAEpD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,IAAI,CAAC,eAAe,EAAE,YAAY,GAAG,OAAO,CAAC,EACrD,KAAK,EAAE,WAAW,GAAG,IAAI,GACxB,MAAM,GAAG,IAAI,CAqBf"}
@@ -48,13 +48,15 @@ export type UseUploadReturn = {
48
48
  /** Opens the native file picker. `call` applies to the picked files. */
49
49
  open: (call?: UploadCallOptions) => void;
50
50
  /**
51
- * Uploads the failed file `id` again, or every failed file. Each file goes
52
- * with the options of the call it came from: it is validated again, and
53
- * `beforeUpload` and `onUploadStart` run again. It keeps its place and
54
- * `id` in the queue, and a retry never replaces the queue. Resolves like
55
- * `handleFiles`; with nothing to retry, at once and without callbacks.
51
+ * Uploads the failed files `ids` (one id or several) again, or every
52
+ * failed file. Files that came from one call go again as one call, with
53
+ * that call's options: they are validated again, and `beforeUpload` and
54
+ * `onUploadStart` run once for them. Each keeps its place and `id` in the
55
+ * queue, and a retry never replaces the queue. Under a `useUploadLimit`,
56
+ * only the failed files that fit go again. Resolves like `handleFiles`;
57
+ * with nothing to retry, at once and without callbacks.
56
58
  */
57
- retry: (id?: string) => Promise<UploadBatchResult>;
59
+ retry: (ids?: string | readonly string[]) => Promise<UploadBatchResult>;
58
60
  /** Cancels one file by `id`, or every file. */
59
61
  cancel: (id?: string) => void;
60
62
  /** Stops every file but keeps stored multipart uploads for resuming. */
@@ -89,7 +91,7 @@ export type UseUploadReturn = {
89
91
  *
90
92
  * Every call validates its files against the route policy from the catalog
91
93
  * and rejects the invalid ones with catalog error codes, so
92
- * `useFormatDimahError` can show them. Valid files upload `concurrentFiles`
94
+ * `useFormatError` can show them. Valid files upload `concurrentFiles`
93
95
  * at a time, and each one can be cancelled with `cancel(id)`. A call's
94
96
  * `uploadOptions` merge over the hook's: call fields win, and `metadata`
95
97
  * merges key by key.
@@ -1 +1 @@
1
- {"version":3,"file":"use-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload.ts"],"names":[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;;;;;;;;;GASG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAyEpE"}
package/dist/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export { createS3Client, type ReactS3Client } from "./create-s3-client";
3
3
  /** Generated key map. Use it with `satisfies Partial<Translations>`. */
4
4
  export type { Translations } from "./translations";
5
5
  export { useUpload, type DropTargetProps, type DropzoneInputProps, type DropzoneRootProps, type UploadPolicy, type UseUploadReturn, } from "./hooks/use-upload";
6
+ export { useUploadLimit } from "./hooks/use-upload-limit";
6
7
  export { useDownload } from "./hooks/use-download";
7
8
  export { useFetchDownload } from "./hooks/use-fetch-download";
8
9
  export { useDelete } from "./hooks/use-delete";
@@ -10,7 +11,7 @@ export { useObjectUrl, type UseObjectUrlOptions, type UseObjectUrlReturn, } from
10
11
  export { useRouteUploadPolicy, type CatalogLoadStatus, type UseRouteUploadPolicyOptions, type UseRouteUploadPolicyReturn, } from "./hooks/use-route-upload-policy";
11
12
  export { useObjectList, type UseObjectListReturn, } from "./hooks/use-object-list";
12
13
  export { useObjectListSelection, type ObjectListSelectionMode, type UseObjectListSelectionOptions, type UseObjectListSelectionReturn, } from "./hooks/use-object-list-selection";
13
- export { useFormatAcceptLabels, useFormatDate, useFormatDimahError, useFormatEta, useFormatFileSize, useFormatNumber, useFormatSpeed, type DateInput, } from "./helpers";
14
+ export { useFormatAcceptLabels, useFormatDate, useFormatError, useFormatEta, useFormatFileSize, useFormatNumber, useFormatSpeed, type DateInput, } from "./helpers";
14
15
  export type * from "./types";
15
16
  export type * from "./list/types";
16
17
  export type { RouteUploadPolicy, RouteUploadPolicyOptions, } from "./helpers/load-route-catalog";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,KAAK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MAAM,6BAA6B,CAAC;AAC7E,YAAY,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC"}
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use client";
2
- import { requireApi, loadRouteCatalog, toClientError, mergeRouteUploadPolicy, resolveRouteUploadPolicy, DEFAULT_MAX_FILES, runBeforeCallback, mapWithConcurrency, abortable, reportOperationOutcome, transferProgress, runStartCallback, notify, runAfterCallback, createObjectListEntries, formatAcceptLabels, formatFileSize, isRawAPIError, toTimestamp, uploadAbortReason, DEFAULT_CONCURRENT_FILES, mergeUploadRequest, resolveUploadRequest, hookFailed, uploadFile } from './chunk-SPUUNLXI.js';
3
- import { createContext, useContext, useState, useEffect, useCallback, useId, useRef, useMemo, useSyncExternalStore, useLayoutEffect } from 'react';
2
+ import { requireApi, loadRouteCatalog, toClientError, mergeRouteUploadPolicy, resolveRouteUploadPolicy, DEFAULT_MAX_FILES, runBeforeCallback, abortable, reportOperationOutcome, transferProgress, runStartCallback, notify, runAfterCallback, reuseObjectListEntries, formatAcceptLabels, formatFileSize, isRawAPIError, toTimestamp, uploadAbortReason, DEFAULT_CONCURRENT_FILES, mergeUploadRequest, resolveUploadRequest, hookFailed, uploadFile } from './chunk-VJIUZK62.js';
3
+ import { createContext, useContext, useState, useEffect, useCallback, useId, useLayoutEffect, useSyncExternalStore, useRef, useMemo } from 'react';
4
4
  import { TranslationProvider, useTranslations } from '@fuma-translate/react';
5
5
  import { jsx } from 'react/jsx-runtime';
6
6
  import { createS3Client as createS3Client$1, parseFileName, fileNameFromKey, s3Error, DELETE_MANY_MAX_KEYS, APIError, normalizeObjectKey, isAPIError, S3_ERROR_CODES, validateFile } from '@dimah-s3/core';
@@ -250,10 +250,85 @@ function createThrottledSpeedUpdater(tracker, intervalMs = 500) {
250
250
  };
251
251
  }
252
252
 
253
+ // src/internal/upload-limits.ts
254
+ var intakes = /* @__PURE__ */ new Map();
255
+ function intakeFor(instanceId) {
256
+ let intake = intakes.get(instanceId);
257
+ if (!intake) {
258
+ intake = { limits: /* @__PURE__ */ new Set(), reserved: 0, listeners: /* @__PURE__ */ new Set() };
259
+ intakes.set(instanceId, intake);
260
+ }
261
+ return intake;
262
+ }
263
+ function prune(instanceId, intake) {
264
+ if (intake.limits.size === 0 && intake.reserved === 0 && intake.listeners.size === 0 && intakes.get(instanceId) === intake) {
265
+ intakes.delete(instanceId);
266
+ }
267
+ }
268
+ function addUploadLimit(instanceId, ref) {
269
+ const intake = intakeFor(instanceId);
270
+ intake.limits.add(ref);
271
+ return () => {
272
+ intake.limits.delete(ref);
273
+ prune(instanceId, intake);
274
+ };
275
+ }
276
+ function reserveUploadSlots(instanceId, count) {
277
+ if (count <= 0) return () => {
278
+ };
279
+ const intake = intakeFor(instanceId);
280
+ intake.reserved += count;
281
+ notify2(intake);
282
+ let released = false;
283
+ return () => {
284
+ if (released) return;
285
+ released = true;
286
+ intake.reserved -= count;
287
+ notify2(intake);
288
+ prune(instanceId, intake);
289
+ };
290
+ }
291
+ function reservedUploadSlots(instanceId) {
292
+ return intakes.get(instanceId)?.reserved ?? 0;
293
+ }
294
+ function subscribeUploadSlots(instanceId, listener) {
295
+ const intake = intakeFor(instanceId);
296
+ intake.listeners.add(listener);
297
+ return () => {
298
+ intake.listeners.delete(listener);
299
+ prune(instanceId, intake);
300
+ };
301
+ }
302
+ function notify2(intake) {
303
+ for (const listener of intake.listeners) listener();
304
+ }
305
+ function freeUploadSlots(instanceId, files) {
306
+ const intake = intakes.get(instanceId);
307
+ let free = Number.POSITIVE_INFINITY;
308
+ if (!intake) return free;
309
+ for (const { current } of intake.limits) {
310
+ if (current) {
311
+ free = Math.min(free, uploadSlotsLeft(current, files, intake.reserved));
312
+ }
313
+ }
314
+ return free;
315
+ }
316
+ function uploadSlotsLeft(limit, files, reserved) {
317
+ let taken = reserved;
318
+ for (const entry of files) {
319
+ if (entry.phase === "error") continue;
320
+ if (entry.phase === "success" && limit.counted?.has(entry.id)) continue;
321
+ taken += 1;
322
+ }
323
+ return Math.max(0, limit.available - taken);
324
+ }
325
+
253
326
  // src/hooks/use-file-upload.ts
254
- function useFileUpload(options) {
327
+ function useFileUpload(options, instanceId) {
255
328
  const contextApi = useContext(S3Context);
256
- const [queue] = useState(() => createUploadQueue(options, contextApi));
329
+ const [queue] = useState(
330
+ () => createUploadQueue(options, contextApi, instanceId)
331
+ );
257
332
  const snapshot = useSyncExternalStore(
258
333
  queue.subscribe,
259
334
  queue.getSnapshot,
@@ -288,7 +363,7 @@ var ACTIVE_PHASES = /* @__PURE__ */ new Set([
288
363
  "uploading",
289
364
  "finalizing"
290
365
  ]);
291
- function createUploadQueue(initialOptions, initialContextApi) {
366
+ function createUploadQueue(initialOptions, initialContextApi, instanceId) {
292
367
  const listeners = /* @__PURE__ */ new Set();
293
368
  const tasks = /* @__PURE__ */ new Map();
294
369
  const waiting = [];
@@ -448,7 +523,7 @@ function createUploadQueue(initialOptions, initialContextApi) {
448
523
  return { status: "error", file, error: toClientError(error) };
449
524
  }
450
525
  }
451
- async function prepare(api, files, options, call, signal) {
526
+ async function prepare(api, files, maxFiles, options, signal) {
452
527
  let pending = files;
453
528
  try {
454
529
  let catalog;
@@ -467,10 +542,6 @@ function createUploadQueue(initialOptions, initialContextApi) {
467
542
  multipart: options.multipart
468
543
  }
469
544
  );
470
- const maxFiles = Math.min(
471
- options.maxFiles ?? DEFAULT_MAX_FILES,
472
- call.maxFiles ?? Number.POSITIVE_INFINITY
473
- );
474
545
  const accepted = [];
475
546
  const rejected = [];
476
547
  for (const file of files) {
@@ -510,7 +581,7 @@ function createUploadQueue(initialOptions, initialContextApi) {
510
581
  }
511
582
  }
512
583
  function enqueue(entries, call, options, replace) {
513
- if (replace && !options.queue) {
584
+ if (replace && !queues(call, options)) {
514
585
  for (const task of tasks.values()) {
515
586
  abortTask(task, uploadAbortReason("cancel"));
516
587
  }
@@ -522,10 +593,11 @@ function createUploadQueue(initialOptions, initialContextApi) {
522
593
  function upload(input, call = {}) {
523
594
  return startCall([...input], call, []);
524
595
  }
525
- function retry(id) {
596
+ function retry(ids) {
597
+ const wanted = ids === void 0 ? null : new Set(typeof ids === "string" ? [ids] : ids);
526
598
  const failed = snapshot.files.filter(
527
- (entry) => entry.phase === "error" && (id === void 0 || entry.id === id)
528
- );
599
+ (entry) => entry.phase === "error" && (wanted?.has(entry.id) ?? true)
600
+ ).slice(0, freeUploadSlots(instanceId, snapshot.files));
529
601
  if (failed.length === 0) return Promise.resolve(batchResult([]));
530
602
  const calls = Map.groupBy(
531
603
  failed,
@@ -546,7 +618,7 @@ function createUploadQueue(initialOptions, initialContextApi) {
546
618
  const api = requireApi(options.api ?? latest.contextApi, "useUpload");
547
619
  if (files.length === 0) return settle(batchResult([]));
548
620
  const controller = new AbortController();
549
- if (!options.queue && retried.length === 0) {
621
+ if (!queues(call, options) && retried.length === 0) {
550
622
  const reason = uploadAbortReason("cancel");
551
623
  for (const pending of preparingCalls) pending.abort(reason);
552
624
  }
@@ -557,10 +629,26 @@ function createUploadQueue(initialOptions, initialContextApi) {
557
629
  );
558
630
  preparingCalls.add(controller);
559
631
  commit({ preparing: snapshot.preparing + 1 });
632
+ const maxFiles = Math.min(
633
+ options.maxFiles ?? DEFAULT_MAX_FILES,
634
+ call.maxFiles ?? Number.POSITIVE_INFINITY,
635
+ retried.length === 0 ? freeUploadSlots(instanceId, snapshot.files) : Number.POSITIVE_INFINITY
636
+ );
637
+ const release = reserveUploadSlots(
638
+ instanceId,
639
+ retried.length === 0 ? Math.min(files.length, maxFiles) : 0
640
+ );
560
641
  let prepared;
561
642
  try {
562
- prepared = await prepare(api, files, options, call, controller.signal);
643
+ prepared = await prepare(
644
+ api,
645
+ files,
646
+ maxFiles,
647
+ options,
648
+ controller.signal
649
+ );
563
650
  } finally {
651
+ release();
564
652
  preparingCalls.delete(controller);
565
653
  for (const id of previous.keys()) retrying.delete(id);
566
654
  commit({ preparing: snapshot.preparing - 1 });
@@ -747,6 +835,9 @@ function createUploadQueue(initialOptions, initialContextApi) {
747
835
  dispose
748
836
  };
749
837
  }
838
+ function queues(call, options) {
839
+ return call.queue ?? options.queue ?? false;
840
+ }
750
841
  function createEntry(file) {
751
842
  return {
752
843
  id: crypto.randomUUID(),
@@ -1082,7 +1173,7 @@ function useUpload(options) {
1082
1173
  maxFileSize: options.maxFileSize,
1083
1174
  multipart: options.multipart
1084
1175
  });
1085
- const engine = useFileUpload(options);
1176
+ const engine = useFileUpload(options, instanceId);
1086
1177
  const { upload, retry: retryFiles } = engine;
1087
1178
  const catalogStatusRef = useLiveRef(routePolicy.status);
1088
1179
  const handleFiles = useCallback(
@@ -1093,9 +1184,9 @@ function useUpload(options) {
1093
1184
  [catalogStatusRef, reloadCatalog, upload]
1094
1185
  );
1095
1186
  const retry = useCallback(
1096
- (id) => {
1187
+ (ids) => {
1097
1188
  if (catalogStatusRef.current === "error") reloadCatalog();
1098
- return retryFiles(id);
1189
+ return retryFiles(ids);
1099
1190
  },
1100
1191
  [catalogStatusRef, reloadCatalog, retryFiles]
1101
1192
  );
@@ -1141,6 +1232,24 @@ function toFileArray(files) {
1141
1232
  if (files instanceof File) return [files];
1142
1233
  return Array.from(files);
1143
1234
  }
1235
+ function useUploadLimit(upload, limit) {
1236
+ const { instanceId, files } = upload;
1237
+ const [ref] = useState(() => ({ current: limit }));
1238
+ useLayoutEffect(() => {
1239
+ ref.current = limit;
1240
+ });
1241
+ useLayoutEffect(() => addUploadLimit(instanceId, ref), [instanceId, ref]);
1242
+ const subscribe = useCallback(
1243
+ (listener) => subscribeUploadSlots(instanceId, listener),
1244
+ [instanceId]
1245
+ );
1246
+ const reserved = useSyncExternalStore(
1247
+ subscribe,
1248
+ () => reservedUploadSlots(instanceId),
1249
+ () => 0
1250
+ );
1251
+ return limit ? uploadSlotsLeft(limit, files, reserved) : null;
1252
+ }
1144
1253
  var REVOKE_DELAY_MS = 3e4;
1145
1254
  function startBrowserDownload(url) {
1146
1255
  clickLink(url);
@@ -1191,7 +1300,6 @@ function clickLink(href, fileName) {
1191
1300
  }
1192
1301
 
1193
1302
  // src/hooks/use-download.ts
1194
- var PRESIGN_MANY_CONCURRENCY = 4;
1195
1303
  function useDownload(options) {
1196
1304
  const instanceId = useId();
1197
1305
  const contextApi = useContext(S3Context);
@@ -1235,27 +1343,6 @@ function useDownload(options) {
1235
1343
  },
1236
1344
  [optionsRef, resolveApi, sign]
1237
1345
  );
1238
- const presignMany = useCallback(
1239
- async (files) => {
1240
- const outcomes = await mapWithConcurrency(
1241
- files,
1242
- PRESIGN_MANY_CONCURRENCY,
1243
- ({ key, ...request }) => presign2(key, request)
1244
- );
1245
- const result = { signed: [], failed: [], blocked: [] };
1246
- for (const outcome of outcomes) {
1247
- if (outcome.status === "success") {
1248
- result.signed.push(outcome.data);
1249
- } else if (outcome.status === "error") {
1250
- result.failed.push({ key: outcome.key, error: outcome.error });
1251
- } else {
1252
- result.blocked.push(outcome.key);
1253
- }
1254
- }
1255
- return result;
1256
- },
1257
- [presign2]
1258
- );
1259
1346
  const navigate = useCallback(
1260
1347
  async (call, fileName) => {
1261
1348
  const { key, signal } = call;
@@ -1312,7 +1399,6 @@ function useDownload(options) {
1312
1399
  isPending: pendingKeys.length > 0,
1313
1400
  download,
1314
1401
  presign: presign2,
1315
- presignMany,
1316
1402
  cancel,
1317
1403
  reset
1318
1404
  };
@@ -1926,6 +2012,12 @@ function useObjectList(options) {
1926
2012
  () => options.defaultSearch ?? "",
1927
2013
  options.onSearchChange
1928
2014
  );
2015
+ const searchParentRef = useRef(parent);
2016
+ useLayoutEffect(() => {
2017
+ if (searchParentRef.current === parent) return;
2018
+ searchParentRef.current = parent;
2019
+ setSearchValue("");
2020
+ }, [parent, setSearchValue]);
1929
2021
  const queryKey = JSON.stringify(options.queryKey ?? []);
1930
2022
  const trimmedSearch = search.trim();
1931
2023
  const request = useMemo(() => {
@@ -2152,9 +2244,11 @@ function useObjectList(options) {
2152
2244
  }
2153
2245
  } : draft
2154
2246
  );
2247
+ const now = requestRef.current;
2248
+ if (now.scope === scope && namesNeedReload(now)) await run("refresh");
2155
2249
  return folder;
2156
2250
  },
2157
- [optionsRef, requestRef, update]
2251
+ [optionsRef, requestRef, run, update]
2158
2252
  );
2159
2253
  const settleRename = useCallback(
2160
2254
  async (scope, replaced) => {
@@ -2246,14 +2340,6 @@ function useObjectList(options) {
2246
2340
  },
2247
2341
  [optionsRef, requestRef, settleRename, trailRef, update]
2248
2342
  );
2249
- const setSort = useCallback(
2250
- (next) => setSortValue(next),
2251
- [setSortValue]
2252
- );
2253
- const setSearch = useCallback(
2254
- (next) => setSearchValue(next),
2255
- [setSearchValue]
2256
- );
2257
2343
  const { getKey, getFile: readFile } = options;
2258
2344
  const getFile = useMemo(
2259
2345
  () => readFile ?? ((item) => ({ name: getKey(item) })),
@@ -2273,10 +2359,7 @@ function useObjectList(options) {
2273
2359
  pending,
2274
2360
  failure
2275
2361
  });
2276
- const entries = useMemo(
2277
- () => createObjectListEntries(folders, items, getKey, getFile),
2278
- [folders, getFile, getKey, items]
2279
- );
2362
+ const entries = useReusedEntries(folders, items, getKey, getFile);
2280
2363
  const nextCursor = fresh ? snapshot.nextCursor : null;
2281
2364
  return {
2282
2365
  entries,
@@ -2300,8 +2383,8 @@ function useObjectList(options) {
2300
2383
  openFolder,
2301
2384
  navigate,
2302
2385
  goUp,
2303
- setSort,
2304
- setSearch,
2386
+ setSort: setSortValue,
2387
+ setSearch: setSearchValue,
2305
2388
  setItems,
2306
2389
  setFolders,
2307
2390
  removeItems,
@@ -2313,6 +2396,15 @@ function useObjectList(options) {
2313
2396
  renameFolder: options.renameFolder ? renameFolder : void 0
2314
2397
  };
2315
2398
  }
2399
+ function useReusedEntries(folders, items, getKey, getFile) {
2400
+ const [cache, setCache] = useState(
2401
+ () => reuseObjectListEntries(null, folders, items, getKey, getFile)
2402
+ );
2403
+ if (cache.folders === folders && cache.items === items) return cache.entries;
2404
+ const next = reuseObjectListEntries(cache, folders, items, getKey, getFile);
2405
+ setCache(next);
2406
+ return next.entries;
2407
+ }
2316
2408
  function readStatus({
2317
2409
  enabled,
2318
2410
  fresh,
@@ -2360,15 +2452,23 @@ function useObjectListSelection(list, options = {}) {
2360
2452
  selected: /* @__PURE__ */ new Map(),
2361
2453
  anchor: null
2362
2454
  }));
2455
+ const loaded = useMemo(
2456
+ () => new Map(list.entries.map((entry) => [entry.key, entry])),
2457
+ [list.entries]
2458
+ );
2363
2459
  let state = stored;
2364
2460
  if (stored.scope !== scope) {
2365
2461
  state = { scope, selected: /* @__PURE__ */ new Map(), anchor: null };
2366
2462
  setStored(state);
2463
+ } else if (!persist && hasMissing(stored.selected, loaded)) {
2464
+ state = {
2465
+ ...stored,
2466
+ selected: new Map(
2467
+ [...stored.selected].filter(([key]) => loaded.has(key))
2468
+ )
2469
+ };
2470
+ setStored(state);
2367
2471
  }
2368
- const loaded = useMemo(
2369
- () => new Map(list.entries.map((entry) => [entry.key, entry])),
2370
- [list.entries]
2371
- );
2372
2472
  const selectable = useMemo(
2373
2473
  () => list.entries.filter((entry) => canSelect(entry)),
2374
2474
  [canSelect, list.entries]
@@ -2521,6 +2621,12 @@ function useObjectListSelection(list, options = {}) {
2521
2621
  clear
2522
2622
  };
2523
2623
  }
2624
+ function hasMissing(selected, loaded) {
2625
+ for (const key of selected.keys()) {
2626
+ if (!loaded.has(key)) return true;
2627
+ }
2628
+ return false;
2629
+ }
2524
2630
  function toKeys(keys) {
2525
2631
  return typeof keys === "string" ? [keys] : keys;
2526
2632
  }
@@ -2581,8 +2687,8 @@ function numberFormat(locale) {
2581
2687
  return format;
2582
2688
  }
2583
2689
 
2584
- // src/helpers/format-dimah-error.tsx
2585
- function useFormatDimahError() {
2690
+ // src/helpers/format-error.tsx
2691
+ function useFormatError() {
2586
2692
  const t = useTranslations();
2587
2693
  const formatFileSize2 = useFormatFileSize();
2588
2694
  const formatNumber = useFormatNumber();
@@ -2822,6 +2928,6 @@ function dateFormat(locale, options = DEFAULT_DATE_OPTIONS) {
2822
2928
  return format;
2823
2929
  }
2824
2930
 
2825
- export { S3Provider, createS3Client, useApi, useDelete, useDownload, useFetchDownload, useFormatAcceptLabels, useFormatDate, useFormatDimahError, useFormatEta, useFormatFileSize, useFormatNumber, useFormatSpeed, useObjectList, useObjectListSelection, useObjectUrl, useRouteUploadPolicy, useUpload };
2931
+ export { S3Provider, createS3Client, useApi, useDelete, useDownload, useFetchDownload, useFormatAcceptLabels, useFormatDate, useFormatError, useFormatEta, useFormatFileSize, useFormatNumber, useFormatSpeed, useObjectList, useObjectListSelection, useObjectUrl, useRouteUploadPolicy, useUpload, useUploadLimit };
2826
2932
  //# sourceMappingURL=index.js.map
2827
2933
  //# sourceMappingURL=index.js.map