@dimah-s3/react 1.7.1 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -13
- package/dist/api.d.ts +24 -15
- package/dist/api.d.ts.map +1 -1
- package/dist/chunk-SPUUNLXI.js +824 -0
- package/dist/chunk-SPUUNLXI.js.map +1 -0
- package/dist/create-s3-client.d.ts +1 -1
- package/dist/create-s3-client.d.ts.map +1 -1
- package/dist/engine.d.ts +15 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +204 -512
- package/dist/engine.js.map +1 -1
- package/dist/helpers/format-accept-labels.d.ts +15 -2
- package/dist/helpers/format-accept-labels.d.ts.map +1 -1
- package/dist/helpers/format-date.d.ts +7 -0
- package/dist/helpers/format-date.d.ts.map +1 -0
- package/dist/helpers/format-dimah-error.d.ts +12 -2
- package/dist/helpers/format-dimah-error.d.ts.map +1 -1
- package/dist/helpers/format-file-size.d.ts +20 -0
- package/dist/helpers/format-file-size.d.ts.map +1 -0
- package/dist/helpers/format-speed.d.ts +1 -1
- package/dist/helpers/format-speed.d.ts.map +1 -1
- package/dist/helpers/format-upload-progress.d.ts +1 -1
- package/dist/helpers/format-upload-progress.d.ts.map +1 -1
- package/dist/helpers/index.d.ts +5 -8
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/load-route-catalog.d.ts +32 -8
- package/dist/helpers/load-route-catalog.d.ts.map +1 -1
- package/dist/helpers/throttled-speed.d.ts +2 -2
- package/dist/helpers/throttled-speed.d.ts.map +1 -1
- package/dist/helpers/to-timestamp.d.ts +5 -0
- package/dist/helpers/to-timestamp.d.ts.map +1 -0
- package/dist/helpers/truncate-file-name.d.ts +8 -0
- package/dist/helpers/truncate-file-name.d.ts.map +1 -0
- package/dist/helpers/use-format-accept-labels.d.ts +12 -0
- package/dist/helpers/use-format-accept-labels.d.ts.map +1 -0
- package/dist/helpers/use-format-eta.d.ts +14 -0
- package/dist/helpers/use-format-eta.d.ts.map +1 -0
- package/dist/helpers/use-format-speed.d.ts +12 -0
- package/dist/helpers/use-format-speed.d.ts.map +1 -0
- package/dist/hooks/use-delete.d.ts +6 -44
- package/dist/hooks/use-delete.d.ts.map +1 -1
- package/dist/hooks/use-download.d.ts +7 -117
- package/dist/hooks/use-download.d.ts.map +1 -1
- package/dist/hooks/use-fetch-download.d.ts +8 -0
- package/dist/hooks/use-fetch-download.d.ts.map +1 -0
- package/dist/hooks/use-file-intake.d.ts +43 -29
- package/dist/hooks/use-file-intake.d.ts.map +1 -1
- package/dist/hooks/use-file-upload.d.ts +38 -34
- package/dist/hooks/use-file-upload.d.ts.map +1 -1
- package/dist/hooks/use-object-list-selection.d.ts +78 -0
- package/dist/hooks/use-object-list-selection.d.ts.map +1 -0
- package/dist/hooks/use-object-list.d.ts +66 -16
- package/dist/hooks/use-object-list.d.ts.map +1 -1
- package/dist/hooks/use-object-url.d.ts +27 -10
- package/dist/hooks/use-object-url.d.ts.map +1 -1
- package/dist/hooks/use-route-upload-policy.d.ts +22 -14
- package/dist/hooks/use-route-upload-policy.d.ts.map +1 -1
- package/dist/hooks/use-upload.d.ts +72 -65
- package/dist/hooks/use-upload.d.ts.map +1 -1
- package/dist/index.d.ts +15 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2420 -2164
- package/dist/index.js.map +1 -1
- package/dist/internal/abortable.d.ts +9 -0
- package/dist/internal/abortable.d.ts.map +1 -0
- package/dist/internal/browser-download.d.ts +15 -0
- package/dist/internal/browser-download.d.ts.map +1 -0
- package/dist/internal/callbacks.d.ts +54 -0
- package/dist/internal/callbacks.d.ts.map +1 -0
- package/dist/internal/client-error.d.ts +15 -0
- package/dist/internal/client-error.d.ts.map +1 -0
- package/dist/internal/hooks.d.ts +27 -0
- package/dist/internal/hooks.d.ts.map +1 -0
- package/dist/internal/lru.d.ts +13 -0
- package/dist/internal/lru.d.ts.map +1 -0
- package/dist/internal/operations.d.ts +74 -0
- package/dist/internal/operations.d.ts.map +1 -0
- package/dist/internal/pool.d.ts +8 -0
- package/dist/internal/pool.d.ts.map +1 -0
- package/dist/list/entries.d.ts +14 -0
- package/dist/list/entries.d.ts.map +1 -0
- package/dist/list/memory-object-source.d.ts +60 -0
- package/dist/list/memory-object-source.d.ts.map +1 -0
- package/dist/list/types.d.ts +123 -11
- package/dist/list/types.d.ts.map +1 -1
- package/dist/s3-provider.d.ts +3 -2
- package/dist/s3-provider.d.ts.map +1 -1
- package/dist/store/local-storage-store.d.ts +5 -4
- package/dist/store/local-storage-store.d.ts.map +1 -1
- package/dist/store/memory-store.d.ts +3 -4
- package/dist/store/memory-store.d.ts.map +1 -1
- package/dist/translations/types.d.ts +105 -23
- package/dist/translations/types.d.ts.map +1 -1
- package/dist/types/delete.d.ts +98 -9
- package/dist/types/delete.d.ts.map +1 -1
- package/dist/types/download.d.ts +152 -23
- package/dist/types/download.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/operation.d.ts +38 -0
- package/dist/types/operation.d.ts.map +1 -0
- package/dist/types/upload-store.d.ts +30 -40
- package/dist/types/upload-store.d.ts.map +1 -1
- package/dist/types/upload.d.ts +177 -130
- package/dist/types/upload.d.ts.map +1 -1
- package/dist/upload/abort.d.ts +10 -0
- package/dist/upload/abort.d.ts.map +1 -0
- package/dist/upload/constants.d.ts +8 -3
- package/dist/upload/constants.d.ts.map +1 -1
- package/dist/upload/index.d.ts +3 -2
- package/dist/upload/index.d.ts.map +1 -1
- package/dist/upload/multipart.d.ts +14 -4
- package/dist/upload/multipart.d.ts.map +1 -1
- package/dist/upload/part-pool.d.ts +16 -0
- package/dist/upload/part-pool.d.ts.map +1 -0
- package/dist/upload/presigned-http.d.ts +5 -14
- package/dist/upload/presigned-http.d.ts.map +1 -1
- package/dist/upload/progress.d.ts +7 -0
- package/dist/upload/progress.d.ts.map +1 -0
- package/dist/upload/request.d.ts +9 -0
- package/dist/upload/request.d.ts.map +1 -0
- package/dist/upload/resume-key.d.ts +7 -3
- package/dist/upload/resume-key.d.ts.map +1 -1
- package/dist/upload/retry.d.ts +27 -2
- package/dist/upload/retry.d.ts.map +1 -1
- package/dist/upload/stored-upload.d.ts +7 -0
- package/dist/upload/stored-upload.d.ts.map +1 -0
- package/dist/upload/upload-file.d.ts +10 -11
- package/dist/upload/upload-file.d.ts.map +1 -1
- package/dist/upload/upload-part.d.ts +6 -3
- package/dist/upload/upload-part.d.ts.map +1 -1
- package/dist/upload/xhr-upload.d.ts +10 -2
- package/dist/upload/xhr-upload.d.ts.map +1 -1
- package/package.json +7 -8
- package/dist/helpers/format-eta.d.ts +0 -13
- package/dist/helpers/format-eta.d.ts.map +0 -1
- package/dist/helpers/format-validate-file-error.d.ts +0 -9
- package/dist/helpers/format-validate-file-error.d.ts.map +0 -1
- package/dist/hooks/index.d.ts +0 -7
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/internal-helpers.d.ts +0 -10
- package/dist/internal-helpers.d.ts.map +0 -1
- package/dist/store/use-immer-state.d.ts +0 -8
- package/dist/store/use-immer-state.d.ts.map +0 -1
- package/dist/types/error.d.ts +0 -27
- package/dist/types/error.d.ts.map +0 -1
- package/dist/upload/upload-files.d.ts +0 -26
- package/dist/upload/upload-files.d.ts.map +0 -1
|
@@ -1,118 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/** Named server route (`dimahS3({ routes })`). */
|
|
9
|
-
route: S3RouteName;
|
|
10
|
-
/** Content-Disposition for the GET. */
|
|
11
|
-
disposition?: "inline" | "attachment";
|
|
12
|
-
};
|
|
13
|
-
/** Options for {@link useDownload} in navigate mode (the default). */
|
|
14
|
-
export type UseNavigateDownloadOptions = SharedDownloadOptions & DownloadHooks & {
|
|
15
|
-
/**
|
|
16
|
-
* `"navigate"` (default) — presign then hand the URL to the browser.
|
|
17
|
-
* `"fetch"` — stream bytes in the browser for progress and cancel.
|
|
18
|
-
*/
|
|
19
|
-
mode?: "navigate";
|
|
20
|
-
};
|
|
21
|
-
/** Options for {@link useDownload} with `{ mode: "fetch" }`. */
|
|
22
|
-
export type UseFetchDownloadOptions = SharedDownloadOptions & FetchDownloadHooks & {
|
|
23
|
-
mode: "fetch";
|
|
24
|
-
};
|
|
25
|
-
export type UseDownloadOptions = UseNavigateDownloadOptions | UseFetchDownloadOptions;
|
|
26
|
-
export type UseNavigateDownloadState = {
|
|
27
|
-
/** Discriminant — omit `mode` or pass `"navigate"` on the hook. */
|
|
28
|
-
mode: "navigate";
|
|
29
|
-
/** Current download phase. */
|
|
30
|
-
phase: DownloadPhase;
|
|
31
|
-
/**
|
|
32
|
-
* Object this operation is targeting. Set when `download` / `presign`
|
|
33
|
-
* starts; kept through success/error/cancel until `reset()` or the next
|
|
34
|
-
* key. Lets a list of controls share one hook instance.
|
|
35
|
-
*/
|
|
36
|
-
objectKey: string | null;
|
|
37
|
-
/** Last error, or `null`. */
|
|
38
|
-
error: APIError | null;
|
|
39
|
-
/** Presigned URL — set after a successful presign, cleared on reset. */
|
|
40
|
-
url: string | null;
|
|
41
|
-
/** Validity window in seconds for the presigned URL. */
|
|
42
|
-
expiresIn: number | null;
|
|
43
|
-
};
|
|
44
|
-
export type UseNavigateDownloadReturn = UseNavigateDownloadState & {
|
|
45
|
-
/** `true` while the URL is being signed (`phase === "presigning"`). */
|
|
46
|
-
isPending: boolean;
|
|
47
|
-
/** Presign and trigger a native browser download. */
|
|
48
|
-
download: (key: string, downloadName?: string) => Promise<void>;
|
|
49
|
-
/**
|
|
50
|
-
* Fetch the presigned URL without triggering a browser download.
|
|
51
|
-
* `expiresIn` requests a shorter TTL. The server clamps it to the route cap.
|
|
52
|
-
*/
|
|
53
|
-
presign: (key: string, downloadName?: string, expiresIn?: number) => Promise<{
|
|
54
|
-
url: string;
|
|
55
|
-
expiresIn: number;
|
|
56
|
-
} | null>;
|
|
57
|
-
/**
|
|
58
|
-
* Presign many files without changing `phase` or `objectKey`.
|
|
59
|
-
* A shared single-file control therefore does not react to each key.
|
|
60
|
-
* `expiresIn` on an entry asks for a shorter TTL. The server clamps it.
|
|
61
|
-
* `beforeDownload` rejections and request errors are listed in `failed`.
|
|
62
|
-
* This does not hand the URLs to the browser.
|
|
63
|
-
*/
|
|
64
|
-
presignMany: (files: readonly {
|
|
65
|
-
key: string;
|
|
66
|
-
fileName?: string;
|
|
67
|
-
expiresIn?: number;
|
|
68
|
-
}[]) => Promise<{
|
|
69
|
-
signed: {
|
|
70
|
-
key: string;
|
|
71
|
-
url: string;
|
|
72
|
-
expiresIn: number;
|
|
73
|
-
}[];
|
|
74
|
-
failed: string[];
|
|
75
|
-
}>;
|
|
76
|
-
/** Reset state to `idle`. */
|
|
77
|
-
reset: () => void;
|
|
78
|
-
};
|
|
79
|
-
export type UseFetchDownloadState = {
|
|
80
|
-
/** Discriminant — pass `{ mode: "fetch" }` on the hook. */
|
|
81
|
-
mode: "fetch";
|
|
82
|
-
/** Current download phase. */
|
|
83
|
-
phase: FetchDownloadPhase;
|
|
84
|
-
/**
|
|
85
|
-
* Object this operation is targeting. Set when `download` starts; kept
|
|
86
|
-
* through success/error/cancel until `reset()` or the next key.
|
|
87
|
-
*/
|
|
88
|
-
objectKey: string | null;
|
|
89
|
-
/** Byte transfer progress. */
|
|
90
|
-
progress: UploadProgress;
|
|
91
|
-
/** Last error, or `null`. */
|
|
92
|
-
error: APIError | null;
|
|
93
|
-
/** Resolved download filename. */
|
|
94
|
-
fileName: string | null;
|
|
95
|
-
/** Total file size in bytes. */
|
|
96
|
-
fileSize: number | null;
|
|
97
|
-
};
|
|
98
|
-
export type UseFetchDownloadReturn = UseFetchDownloadState & {
|
|
99
|
-
/** `true` while bytes are transferring (`phase === "downloading"`). */
|
|
100
|
-
isDownloading: boolean;
|
|
101
|
-
/**
|
|
102
|
-
* `true` while the download is in-flight (`presigning` or `downloading`).
|
|
103
|
-
*/
|
|
104
|
-
isPending: boolean;
|
|
105
|
-
/** Presign, fetch bytes, and save via the browser. */
|
|
106
|
-
download: (key: string, downloadName?: string) => Promise<void>;
|
|
107
|
-
/** Abort the active download. */
|
|
108
|
-
cancel: () => void;
|
|
109
|
-
/** Reset state to `idle`. */
|
|
110
|
-
reset: () => void;
|
|
111
|
-
};
|
|
112
|
-
/** Return of {@link useDownload} — narrow with {@link isFetchDownload}. */
|
|
113
|
-
export type UseDownloadReturn = UseNavigateDownloadReturn | UseFetchDownloadReturn;
|
|
114
|
-
/** `true` when the hook was created with `{ mode: "fetch" }`. */
|
|
115
|
-
export declare function isFetchDownload(download: UseDownloadReturn): download is UseFetchDownloadReturn;
|
|
116
|
-
export declare function useDownload(options: UseNavigateDownloadOptions): UseNavigateDownloadReturn;
|
|
117
|
-
export declare function useDownload(options: UseFetchDownloadOptions): UseFetchDownloadReturn;
|
|
1
|
+
import type { UseDownloadOptions, UseDownloadReturn } from "../types/download.js";
|
|
2
|
+
/**
|
|
3
|
+
* Presigns objects and hands the URLs to the browser, which saves or opens
|
|
4
|
+
* them as the response's `Content-Disposition` says. Keys run in parallel,
|
|
5
|
+
* and each `download` call records an operation.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useDownload(options: UseDownloadOptions): UseDownloadReturn;
|
|
118
8
|
//# sourceMappingURL=use-download.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-download.d.ts","sourceRoot":"","sources":["../../src/hooks/use-download.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-download.d.ts","sourceRoot":"","sources":["../../src/hooks/use-download.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAMV,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,kBAAkB,CAAC;AAK1B;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAoJ1E"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UseFetchDownloadOptions, UseFetchDownloadReturn } from "../types/download.js";
|
|
2
|
+
/**
|
|
3
|
+
* Presigns objects, fetches their bytes with progress and saves them through
|
|
4
|
+
* the browser. Keys run in parallel, and each call records an operation that
|
|
5
|
+
* `cancel(key)` can abort.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useFetchDownload(options: UseFetchDownloadOptions): UseFetchDownloadReturn;
|
|
8
|
+
//# sourceMappingURL=use-fetch-download.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-fetch-download.d.ts","sourceRoot":"","sources":["../../src/hooks/use-fetch-download.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAIV,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,kBAAkB,CAAC;AAa1B;;;;GAIG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,uBAAuB,GAC/B,sBAAsB,CAqIxB"}
|
|
@@ -1,47 +1,61 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type HTMLAttributes } from "react";
|
|
2
|
+
import { type DropzoneInputProps, type DropzoneRootProps } from "react-dropzone";
|
|
3
|
+
import type { UploadCallOptions } from "../types/upload.js";
|
|
4
|
+
/** Call options, or a function that returns them when the files arrive. */
|
|
5
|
+
export type UploadCallInput = UploadCallOptions | (() => UploadCallOptions);
|
|
6
|
+
/**
|
|
7
|
+
* Props for a drop target that is not a dropzone, such as a folder row.
|
|
8
|
+
* While files are dragged over it, the element has a `data-drag-active`
|
|
9
|
+
* attribute.
|
|
10
|
+
*/
|
|
11
|
+
export type DropTargetProps = Pick<HTMLAttributes<HTMLElement>, "onDragEnter" | "onDragOver" | "onDragLeave" | "onDrop"> & {
|
|
12
|
+
"data-drag-active"?: boolean;
|
|
13
|
+
};
|
|
2
14
|
/** Options for {@link useFileIntake}. */
|
|
3
15
|
export type UseFileIntakeOptions = {
|
|
4
|
-
/** MIME types
|
|
5
|
-
accept?: string[];
|
|
6
|
-
/** Max
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/** Disable all intake interactions. */
|
|
16
|
+
/** HTML `accept` tokens: MIME types (`image/*`) and extensions (`.pdf`). */
|
|
17
|
+
accept?: readonly string[];
|
|
18
|
+
/** Max files per selection. More than one allows a multiple selection. */
|
|
19
|
+
maxFiles: number;
|
|
20
|
+
/**
|
|
21
|
+
* Disables every intake interaction: the root, drop targets and paste, and
|
|
22
|
+
* `open()` does nothing.
|
|
23
|
+
*/
|
|
13
24
|
disabled?: boolean;
|
|
14
|
-
/**
|
|
25
|
+
/** Disables click-to-open on the root. */
|
|
15
26
|
noClick?: boolean;
|
|
16
|
-
/**
|
|
27
|
+
/** Disables drag and drop on the root and on drop targets. */
|
|
17
28
|
noDrag?: boolean;
|
|
18
|
-
/**
|
|
29
|
+
/** Disables keyboard activation on the root. */
|
|
19
30
|
noKeyboard?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Gets every picked, dropped or pasted file, with the call options of the
|
|
33
|
+
* element that took them in. Files are not validated here.
|
|
34
|
+
*/
|
|
35
|
+
onFiles: (files: File[], call: UploadCallOptions | undefined) => void;
|
|
24
36
|
};
|
|
37
|
+
/** What {@link useFileIntake} returns. */
|
|
25
38
|
export type UseFileIntakeReturn = {
|
|
26
|
-
|
|
39
|
+
/** Spread on the dropzone root. `call` applies to its drops, pastes and picker. */
|
|
40
|
+
getRootProps: <T extends DropzoneRootProps>(props?: T, call?: UploadCallInput) => T;
|
|
41
|
+
/** Spread on a drop target. Adds drag and drop handlers only. */
|
|
42
|
+
getDropTargetProps: <T extends object = DropTargetProps>(props?: T & DropTargetProps, call?: UploadCallInput) => T & DropTargetProps;
|
|
43
|
+
/** Spread on a hidden `<input type="file">`. */
|
|
27
44
|
getInputProps: <T extends DropzoneInputProps>(props?: T) => T;
|
|
28
|
-
/**
|
|
29
|
-
open: () => void;
|
|
45
|
+
/** Opens the native file picker. `call` applies to the picked files. */
|
|
46
|
+
open: (call?: UploadCallOptions) => void;
|
|
30
47
|
isDragActive: boolean;
|
|
31
48
|
isDragAccept: boolean;
|
|
32
49
|
isDragReject: boolean;
|
|
33
|
-
/** Soft rejections from the last drop / selection. */
|
|
34
|
-
fileRejections: readonly FileRejection[];
|
|
35
50
|
};
|
|
36
51
|
/**
|
|
37
|
-
* Headless file intake powered by react-dropzone
|
|
38
|
-
*
|
|
39
|
-
* Dropzone owns picker / drag / size / count. Type matching uses
|
|
40
|
-
* {@link validateFile} (same HTML `accept` tokens as programmatic upload).
|
|
41
|
-
* The native input gets the HTML `accept` attribute directly.
|
|
52
|
+
* @internal Headless file intake powered by react-dropzone, behind `useUpload`.
|
|
42
53
|
*
|
|
43
|
-
*
|
|
54
|
+
* It only collects files and the call options of the element that took them
|
|
55
|
+
* in. `useUpload` validates them against the route policy, so a rejection
|
|
56
|
+
* always carries a catalog error code. The drag state still reflects
|
|
57
|
+
* `accept` and `maxFiles` while files are dragged.
|
|
44
58
|
*/
|
|
45
59
|
export declare function useFileIntake(options: UseFileIntakeOptions): UseFileIntakeReturn;
|
|
46
|
-
export type {
|
|
60
|
+
export type { DropzoneRootProps, DropzoneInputProps };
|
|
47
61
|
//# sourceMappingURL=use-file-intake.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-file-intake.d.ts","sourceRoot":"","sources":["../../src/hooks/use-file-intake.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-file-intake.d.ts","sourceRoot":"","sources":["../../src/hooks/use-file-intake.ts"],"names":[],"mappings":"AAEA,OAAO,EAKL,KAAK,cAAc,EAGpB,MAAM,OAAO,CAAC;AACf,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAEvB,MAAM,gBAAgB,CAAC;AAExB,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAExD,2EAA2E;AAC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D,wEAAwE;IACxE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,iBAAiB,KAAK,IAAI,CAAC;IACzC,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;CACvB,CAAC;AAwBF;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,oBAAoB,GAC5B,mBAAmB,CA0KrB;AAED,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -1,44 +1,48 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import {
|
|
3
|
-
import type {
|
|
4
|
-
/** @internal
|
|
5
|
-
export type UseFileUploadOptions =
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export type UseFileUploadState = {
|
|
1
|
+
import { type APIError } from "@dimah-s3/core";
|
|
2
|
+
import type { TransferProgress } from "../types/operation.js";
|
|
3
|
+
import type { FileRejection, UploadBatchResult, UploadCallOptions, UploadFileState, UploadPhase, UseUploadOptions } from "../types/upload.js";
|
|
4
|
+
/** @internal The queue part of `UseUploadOptions`, without the intake flags. */
|
|
5
|
+
export type UseFileUploadOptions = Omit<UseUploadOptions, "disabled" | "noDrag" | "noClick" | "noKeyboard">;
|
|
6
|
+
/** @internal What {@link useFileUpload} returns to `useUpload`. */
|
|
7
|
+
export type UseFileUploadReturn = {
|
|
8
|
+
/** Every file in the queue, in the order it was added. */
|
|
9
|
+
files: readonly UploadFileState[];
|
|
10
|
+
/** The first file, or `null`. */
|
|
11
|
+
file: UploadFileState | null;
|
|
12
|
+
/** `uploading` while a call is preparing or a file is in flight. */
|
|
14
13
|
phase: UploadPhase;
|
|
15
|
-
|
|
16
|
-
progress:
|
|
14
|
+
/** Bytes sent across every file in the queue. */
|
|
15
|
+
progress: TransferProgress;
|
|
16
|
+
/** The one failed file's error, or `PARTIAL_FAILURE` when several failed. */
|
|
17
17
|
error: APIError | null;
|
|
18
|
-
|
|
19
|
-
export type UseFileUploadReturn = UseFileUploadState & {
|
|
20
|
-
/** First file in the batch, or `null`. */
|
|
21
|
-
file: UploadFileState | null;
|
|
22
|
-
/** `true` while bytes are transferring (`phase === "uploading"`). */
|
|
23
|
-
isUploading: boolean;
|
|
24
|
-
/**
|
|
25
|
-
* `true` while the upload is in-flight (`validating`, `presigning`,
|
|
26
|
-
* `uploading`, or `finalizing`).
|
|
27
|
-
*/
|
|
18
|
+
/** `true` while `phase` is `uploading`. */
|
|
28
19
|
isPending: boolean;
|
|
29
|
-
/**
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Abort all in-flight uploads and clean up multipart / store resources.
|
|
33
|
-
*/
|
|
34
|
-
cancel: () => void;
|
|
20
|
+
/** Files the newest call rejected for their type, size or count. */
|
|
21
|
+
fileRejections: readonly FileRejection[];
|
|
35
22
|
/**
|
|
36
|
-
*
|
|
23
|
+
* Validates `files` against the route policy and uploads the valid ones.
|
|
24
|
+
* Rejected files go to `onFileReject` and never enter the queue. When no
|
|
25
|
+
* file is valid, the call ends there and runs only `onSettled`.
|
|
37
26
|
*/
|
|
27
|
+
upload: (files: readonly File[], call?: UploadCallOptions) => Promise<UploadBatchResult>;
|
|
28
|
+
/** Uploads the failed file `id` again, or every failed file. */
|
|
29
|
+
retry: (id?: string) => Promise<UploadBatchResult>;
|
|
30
|
+
/** Cancels one file by `id`, or every file and preparing call. */
|
|
31
|
+
cancel: (id?: string) => void;
|
|
32
|
+
/** Stops every file but keeps stored multipart uploads for resuming. */
|
|
38
33
|
detach: () => void;
|
|
39
|
-
/**
|
|
34
|
+
/** Removes settled files and rejections. Running files keep going. */
|
|
40
35
|
reset: () => void;
|
|
41
36
|
};
|
|
42
|
-
/**
|
|
37
|
+
/**
|
|
38
|
+
* @internal The upload queue behind `useUpload`.
|
|
39
|
+
*
|
|
40
|
+
* Every call loads the route catalog, validates its files, then runs
|
|
41
|
+
* `beforeUpload` and `onUploadStart` once. Valid files share one pool of
|
|
42
|
+
* `concurrentFiles` uploads across calls. Each file can be cancelled on its
|
|
43
|
+
* own. A cancelled or detached file leaves the queue and counts as `aborted`.
|
|
44
|
+
* A failed file can be retried in place. Unmounting detaches the files whose
|
|
45
|
+
* call had an `uploadStore`, so they can resume, and cancels the rest.
|
|
46
|
+
*/
|
|
43
47
|
export declare function useFileUpload(options: UseFileUploadOptions): UseFileUploadReturn;
|
|
44
48
|
//# sourceMappingURL=use-file-upload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-file-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-file-upload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-file-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-file-upload.ts"],"names":[],"mappings":"AAUA,OAAO,EAGL,KAAK,QAAQ,EAGd,MAAM,gBAAgB,CAAC;AAsBxB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EAEjB,eAAe,EACf,WAAW,EAGX,gBAAgB,EACjB,MAAM,gBAAgB,CAAC;AAUxB,gFAAgF;AAChF,MAAM,MAAM,oBAAoB,GAAG,IAAI,CACrC,gBAAgB,EAChB,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,YAAY,CACjD,CAAC;AAEF,mEAAmE;AACnE,MAAM,MAAM,mBAAmB,GAAG;IAChC,0DAA0D;IAC1D,KAAK,EAAE,SAAS,eAAe,EAAE,CAAC;IAClC,iCAAiC;IACjC,IAAI,EAAE,eAAe,GAAG,IAAI,CAAC;IAC7B,oEAAoE;IACpE,KAAK,EAAE,WAAW,CAAC;IACnB,iDAAiD;IACjD,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,6EAA6E;IAC7E,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;IACvB,2CAA2C;IAC3C,SAAS,EAAE,OAAO,CAAC;IACnB,oEAAoE;IACpE,cAAc,EAAE,SAAS,aAAa,EAAE,CAAC;IACzC;;;;OAIG;IACH,MAAM,EAAE,CACN,KAAK,EAAE,SAAS,IAAI,EAAE,EACtB,IAAI,CAAC,EAAE,iBAAiB,KACrB,OAAO,CAAC,iBAAiB,CAAC,CAAC;IAChC,gEAAgE;IAChE,KAAK,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,iBAAiB,CAAC,CAAC;IACnD,kEAAkE;IAClE,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,wEAAwE;IACxE,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,sEAAsE;IACtE,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,oBAAoB,GAC5B,mBAAmB,CAgCrB"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { ObjectListEntry, ObjectListFolder } from "../list/types.js";
|
|
2
|
+
export type ObjectListSelectionMode = "single" | "multiple";
|
|
3
|
+
/** Options for {@link useObjectListSelection}. */
|
|
4
|
+
export type UseObjectListSelectionOptions<TItem> = {
|
|
5
|
+
/** `single` keeps at most one entry. @default "multiple" */
|
|
6
|
+
mode?: ObjectListSelectionMode;
|
|
7
|
+
/**
|
|
8
|
+
* Which entries can be selected. Defaults to files only: a folder needs
|
|
9
|
+
* its object keys before a bulk action can act on it.
|
|
10
|
+
*/
|
|
11
|
+
isSelectable?: (entry: ObjectListEntry<TItem>) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Keep the selection when the folder changes. Entries that leave the
|
|
14
|
+
* loaded rows stay selected, as in a file picker that collects files from
|
|
15
|
+
* several folders. @default false
|
|
16
|
+
*/
|
|
17
|
+
persist?: boolean;
|
|
18
|
+
/** Called when the selected entries change, including when they clear. */
|
|
19
|
+
onSelectionChange?: (selected: readonly ObjectListEntry<TItem>[]) => void;
|
|
20
|
+
};
|
|
21
|
+
/** State and commands returned by {@link useObjectListSelection}. */
|
|
22
|
+
export type UseObjectListSelectionReturn<TItem> = {
|
|
23
|
+
mode: ObjectListSelectionMode;
|
|
24
|
+
persist: boolean;
|
|
25
|
+
/** Selected entries in the order they were selected. */
|
|
26
|
+
selected: readonly ObjectListEntry<TItem>[];
|
|
27
|
+
/** `entry.key` of each selected entry. */
|
|
28
|
+
selectedKeys: ReadonlySet<string>;
|
|
29
|
+
selectedItems: readonly TItem[];
|
|
30
|
+
selectedFolders: readonly ObjectListFolder[];
|
|
31
|
+
count: number;
|
|
32
|
+
/** At least one entry is selected. */
|
|
33
|
+
isSelecting: boolean;
|
|
34
|
+
/** Every selectable loaded entry is selected. */
|
|
35
|
+
allSelected: boolean;
|
|
36
|
+
/** Loaded entries that can be selected. */
|
|
37
|
+
selectableCount: number;
|
|
38
|
+
isSelected: (key: string) => boolean;
|
|
39
|
+
canSelect: (entry: ObjectListEntry<TItem>) => boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Flip one entry, or set it with `value`. `range` applies the same value
|
|
42
|
+
* to every selectable entry between the last toggled entry and this one.
|
|
43
|
+
*/
|
|
44
|
+
toggle: (key: string, options?: {
|
|
45
|
+
range?: boolean;
|
|
46
|
+
value?: boolean;
|
|
47
|
+
}) => void;
|
|
48
|
+
/** Add loaded entries. In `single` mode the last key wins. */
|
|
49
|
+
select: (keys: string | readonly string[]) => void;
|
|
50
|
+
deselect: (keys: string | readonly string[]) => void;
|
|
51
|
+
/** Select every selectable loaded entry. Ignored in `single` mode. */
|
|
52
|
+
selectAll: () => void;
|
|
53
|
+
clear: () => void;
|
|
54
|
+
};
|
|
55
|
+
/** The parts of a `useObjectList` return the selection reads. */
|
|
56
|
+
type SelectionSource<TItem> = {
|
|
57
|
+
entries: readonly ObjectListEntry<TItem>[];
|
|
58
|
+
parent: string | null;
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* Checkbox selection over the rows of a `useObjectList` return.
|
|
62
|
+
* Headless: render your own checkboxes, or pass it to `ObjectList` as
|
|
63
|
+
* `selection`.
|
|
64
|
+
*
|
|
65
|
+
* ```ts
|
|
66
|
+
* const list = useObjectList(source);
|
|
67
|
+
* const selection = useObjectListSelection(list);
|
|
68
|
+
*
|
|
69
|
+
* selection.toggle(entry.key, { range: event.shiftKey });
|
|
70
|
+
* selection.selectedItems; // the files to act on
|
|
71
|
+
* ```
|
|
72
|
+
*
|
|
73
|
+
* Without `persist`, the selection follows the loaded rows: it clears when
|
|
74
|
+
* the folder changes and drops entries a reload no longer returns.
|
|
75
|
+
*/
|
|
76
|
+
export declare function useObjectListSelection<TItem>(list: SelectionSource<TItem>, options?: UseObjectListSelectionOptions<TItem>): UseObjectListSelectionReturn<TItem>;
|
|
77
|
+
export {};
|
|
78
|
+
//# sourceMappingURL=use-object-list-selection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-object-list-selection.d.ts","sourceRoot":"","sources":["../../src/hooks/use-object-list-selection.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEtE,MAAM,MAAM,uBAAuB,GAAG,QAAQ,GAAG,UAAU,CAAC;AAE5D,kDAAkD;AAClD,MAAM,MAAM,6BAA6B,CAAC,KAAK,IAAI;IACjD,4DAA4D;IAC5D,IAAI,CAAC,EAAE,uBAAuB,CAAC;IAC/B;;;OAGG;IACH,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC;IAC1D;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,0EAA0E;IAC1E,iBAAiB,CAAC,EAAE,CAAC,QAAQ,EAAE,SAAS,eAAe,CAAC,KAAK,CAAC,EAAE,KAAK,IAAI,CAAC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E,CAAC;IAC3C,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACvB,CAAC;AAcF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAC1C,IAAI,EAAE,eAAe,CAAC,KAAK,CAAC,EAC5B,OAAO,GAAE,6BAA6B,CAAC,KAAK,CAAM,GACjD,4BAA4B,CAAC,KAAK,CAAC,CAgMrC"}
|
|
@@ -1,49 +1,99 @@
|
|
|
1
1
|
import type { APIError } from "@dimah-s3/core";
|
|
2
|
-
import type { ObjectListFolder, ObjectListUsage, UseObjectListOptions } from "../list/types.js";
|
|
3
|
-
|
|
2
|
+
import type { ObjectListEntry, ObjectListFile, ObjectListFolder, ObjectListSort, ObjectListStatus, ObjectListUsage, UseObjectListOptions } from "../list/types.js";
|
|
3
|
+
import type { UploadRequestOptions } from "../types/upload.js";
|
|
4
|
+
export type { ObjectListEntry, ObjectListFile, ObjectListFileEntry, ObjectListFolder, ObjectListFolderEntry, ObjectListPage, ObjectListQuery, ObjectListQueryInput, ObjectListSort, ObjectListSortDirection, ObjectListSource, ObjectListStatus, ObjectListUsage, UseObjectListOptions, } from "../list/types.js";
|
|
5
|
+
/** A value, or an updater from the current value. */
|
|
6
|
+
type Updater<T> = T | ((current: T) => T);
|
|
4
7
|
/** State and commands returned by {@link useObjectList}. */
|
|
5
8
|
export type UseObjectListReturn<TItem> = {
|
|
9
|
+
/** Folders, then files. Rows, tiles, and selection read this. */
|
|
10
|
+
entries: readonly ObjectListEntry<TItem>[];
|
|
6
11
|
items: readonly TItem[];
|
|
7
12
|
/** Child folders from the latest first page. */
|
|
8
13
|
folders: readonly ObjectListFolder[];
|
|
9
14
|
/** Path from the root, root excluded. */
|
|
10
15
|
trail: readonly ObjectListFolder[];
|
|
16
|
+
/** Open folder id. `null` is the root. */
|
|
11
17
|
parent: string | null;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
isLoading: boolean;
|
|
16
|
-
/** True while a later page is in flight. */
|
|
17
|
-
isLoadingMore: boolean;
|
|
18
|
-
/** True while the current folder is reloading and previous rows stay visible. */
|
|
19
|
-
isRefreshing: boolean;
|
|
18
|
+
sort: ObjectListSort | null;
|
|
19
|
+
/** Search text as typed. The query receives it trimmed. */
|
|
20
|
+
search: string;
|
|
20
21
|
/**
|
|
21
22
|
* Totals from the latest page that sent them. `null` when the source
|
|
22
23
|
* did not.
|
|
23
24
|
*/
|
|
24
25
|
usage: ObjectListUsage | null;
|
|
26
|
+
error: APIError | null;
|
|
27
|
+
status: ObjectListStatus;
|
|
28
|
+
/** True while the first page is in flight and there is nothing to show. */
|
|
29
|
+
isLoading: boolean;
|
|
30
|
+
/** True while a reload, sort, or search is in flight; rows stay visible. */
|
|
31
|
+
isRefreshing: boolean;
|
|
32
|
+
/** True while a later page is in flight. */
|
|
33
|
+
isLoadingMore: boolean;
|
|
25
34
|
hasMore: boolean;
|
|
35
|
+
nextCursor: string | null;
|
|
36
|
+
/** Load the next page. Ignored while another request is in flight. */
|
|
26
37
|
loadMore: () => Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Reload every page loaded so far, keeping the rows on screen until the
|
|
40
|
+
* new ones arrive.
|
|
41
|
+
*/
|
|
27
42
|
refresh: () => Promise<void>;
|
|
43
|
+
/** Repeat the request that failed: the next page, or a reload. */
|
|
44
|
+
retry: () => Promise<void>;
|
|
28
45
|
/** Open a child folder and load its first page. */
|
|
29
46
|
openFolder: (folder: ObjectListFolder) => void;
|
|
30
47
|
/** Replace the path. Pass `[]` for the root. */
|
|
31
48
|
navigate: (trail: readonly ObjectListFolder[]) => void;
|
|
49
|
+
/** Open the parent of the current folder. Does nothing at the root. */
|
|
50
|
+
goUp: () => void;
|
|
51
|
+
/** Change the order. Reloads the first page. */
|
|
52
|
+
setSort: (sort: ObjectListSort | null) => void;
|
|
53
|
+
/** Change the search text. Reloads the first page. Debounce it yourself. */
|
|
54
|
+
setSearch: (search: string) => void;
|
|
55
|
+
/**
|
|
56
|
+
* Edit the loaded files without a request, for example after a rename.
|
|
57
|
+
* The next reload replaces them.
|
|
58
|
+
*/
|
|
59
|
+
setItems: (items: Updater<readonly TItem[]>) => void;
|
|
60
|
+
/** Edit the loaded folders without a request. */
|
|
61
|
+
setFolders: (folders: Updater<readonly ObjectListFolder[]>) => void;
|
|
62
|
+
/** Drop loaded files by `getKey`. */
|
|
63
|
+
removeItems: (keys: readonly string[]) => void;
|
|
64
|
+
/** The `getKey` option. */
|
|
65
|
+
getKey: (item: TItem) => string;
|
|
66
|
+
/** The `getFile` option, or `{ name: getKey(item) }`. */
|
|
67
|
+
getFile: (item: TItem) => ObjectListFile;
|
|
68
|
+
/** The source's `uploadOptions`. Set when it supports drop-on-folder. */
|
|
69
|
+
uploadOptions: ((parent: string | null) => UploadRequestOptions) | undefined;
|
|
70
|
+
/**
|
|
71
|
+
* Creates an empty folder in the open folder and adds it to the loaded
|
|
72
|
+
* folders. Rejects with an `APIError`. Set when the source has
|
|
73
|
+
* `createFolder`.
|
|
74
|
+
*/
|
|
75
|
+
createFolder: ((name: string) => Promise<ObjectListFolder>) | undefined;
|
|
32
76
|
};
|
|
33
77
|
/**
|
|
34
78
|
* Page through a folder catalog without knowing the backend.
|
|
35
79
|
*
|
|
36
|
-
* Pass `query
|
|
37
|
-
*
|
|
38
|
-
*
|
|
80
|
+
* Pass a source: `query` loads one page for a folder, cursor, sort, and
|
|
81
|
+
* search; `getKey` and `getFile` read a row. `dbObjectSource` from
|
|
82
|
+
* `@dimah-s3/db/client` and `memoryObjectSource` are ready-made sources;
|
|
83
|
+
* a route handler is another. The hook never calls S3.
|
|
39
84
|
*
|
|
40
85
|
* ```ts
|
|
41
86
|
* const list = useObjectList({
|
|
42
|
-
* query: ({ parent, cursor, signal }) =>
|
|
43
|
-
* fetchFiles({ folderId: parent, cursor, signal }),
|
|
44
|
-
*
|
|
87
|
+
* query: ({ parent, cursor, sort, search, signal }) =>
|
|
88
|
+
* fetchFiles({ folderId: parent, cursor, sort, search, signal }),
|
|
89
|
+
* getKey: (file) => file.id,
|
|
90
|
+
* getFile: (file) => ({ name: file.name, objectKey: file.key, size: file.size }),
|
|
45
91
|
* });
|
|
46
92
|
* ```
|
|
93
|
+
*
|
|
94
|
+
* Changing the folder or `queryKey` clears the rows and shows the loading
|
|
95
|
+
* state. Changing the sort or search keeps the rows on screen until the new
|
|
96
|
+
* first page arrives.
|
|
47
97
|
*/
|
|
48
98
|
export declare function useObjectList<TItem>(options: UseObjectListOptions<TItem>): UseObjectListReturn<TItem>;
|
|
49
99
|
//# sourceMappingURL=use-object-list.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-object-list.d.ts","sourceRoot":"","sources":["../../src/hooks/use-object-list.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-object-list.d.ts","sourceRoot":"","sources":["../../src/hooks/use-object-list.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI/C,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,oBAAoB,EACrB,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE3D,YAAY,EACV,eAAe,EACf,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,qBAAqB,EACrB,cAAc,EACd,eAAe,EACf,oBAAoB,EACpB,cAAc,EACd,uBAAuB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AAItB,qDAAqD;AACrD,KAAK,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AAE1C,4DAA4D;AAC5D,MAA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EAAE,cAAc,GAAG,IAAI,KAAK,IAAI,CAAC;IAC/C,4EAA4E;IAC5E,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;IACpC;;;OAGG;IACH,QAAQ,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IACrD,iDAAiD;IACjD,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,SAAS,gBAAgB,EAAE,CAAC,KAAK,IAAI,CAAC;IACpE,qCAAqC;IACrC,WAAW,EAAE,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,KAAK,IAAI,CAAC;IAC/C,2BAA2B;IAC3B,MAAM,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,MAAM,CAAC;IAChC,yDAAyD;IACzD,OAAO,EAAE,CAAC,IAAI,EAAE,KAAK,KAAK,cAAc,CAAC;IACzC,yEAAyE;IACzE,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,KAAK,oBAAoB,CAAC,GAAG,SAAS,CAAC;IAC7E;;;;OAIG;IACH,YAAY,EAAE,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,gBAAgB,CAAC,CAAC,GAAG,SAAS,CAAC;CACzE,CAAC;AAgDF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,KAAK,EACjC,OAAO,EAAE,oBAAoB,CAAC,KAAK,CAAC,GACnC,mBAAmB,CAAC,KAAK,CAAC,CA0W5B"}
|
|
@@ -1,30 +1,47 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { APIError, ContentDispositionType, S3Api, S3RouteName } from "@dimah-s3/core";
|
|
2
2
|
export type UseObjectUrlOptions = {
|
|
3
3
|
/** S3Api. Optional when an `<S3Provider>` is present in the tree. */
|
|
4
4
|
api?: S3Api;
|
|
5
5
|
/** Named server route (`dimahS3({ routes })`). */
|
|
6
6
|
route: S3RouteName;
|
|
7
|
-
/** Stored object key. `null`
|
|
7
|
+
/** Stored object key. `null`, `undefined` or `""` clears the URL. */
|
|
8
8
|
objectKey?: string | null;
|
|
9
9
|
/** Content-Disposition for the GET. @default "inline" */
|
|
10
10
|
disposition?: ContentDispositionType;
|
|
11
|
-
/**
|
|
11
|
+
/** File name for Content-Disposition. */
|
|
12
12
|
fileName?: string;
|
|
13
|
+
/**
|
|
14
|
+
* Refresh this long before expiry. A URL that lives less than twice this
|
|
15
|
+
* long refreshes at half its lifetime instead.
|
|
16
|
+
* @default 60_000
|
|
17
|
+
*/
|
|
18
|
+
refreshBeforeMs?: number;
|
|
13
19
|
};
|
|
14
20
|
export type UseObjectUrlReturn = {
|
|
15
|
-
/**
|
|
21
|
+
/** The key this state belongs to, or `null` when there is no key. */
|
|
22
|
+
objectKey: string | null;
|
|
23
|
+
/** Presigned or proxy URL for `objectKey`. `null` until it is signed. */
|
|
16
24
|
url: string | null;
|
|
17
|
-
/**
|
|
18
|
-
|
|
25
|
+
/** When `url` stops working (ms since epoch). `null` for proxy URLs. */
|
|
26
|
+
expiresAt: number | null;
|
|
27
|
+
/** The last presign error for `objectKey`, or `null`. */
|
|
19
28
|
error: APIError | null;
|
|
29
|
+
/** `true` while a presign for `objectKey` is in flight. */
|
|
20
30
|
isLoading: boolean;
|
|
21
|
-
/**
|
|
31
|
+
/** Drops the cached URL and presigns again. */
|
|
22
32
|
refresh: () => void;
|
|
23
33
|
};
|
|
24
34
|
/**
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
35
|
+
* Presigns a GET URL for previews (`<img>`, `<video>`, links).
|
|
36
|
+
*
|
|
37
|
+
* URLs are cached per `S3Api`, so hooks showing the same object share one
|
|
38
|
+
* request. A URL is refreshed `refreshBeforeMs` before it expires; proxy URLs
|
|
39
|
+
* never expire and stay until `refresh()`. `url` is only ever the URL for the
|
|
40
|
+
* current `objectKey`: after the key changes it is `null` until the new URL
|
|
41
|
+
* is signed. A background refresh keeps the old URL until the new one lands.
|
|
42
|
+
* When it fails, the old URL stays with `error` set until it expires: a
|
|
43
|
+
* transient failure is retried with backoff until then, and the URL is
|
|
44
|
+
* cleared once it has expired.
|
|
28
45
|
*/
|
|
29
46
|
export declare function useObjectUrl(options: UseObjectUrlOptions): UseObjectUrlReturn;
|
|
30
47
|
//# sourceMappingURL=use-object-url.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-object-url.d.ts","sourceRoot":"","sources":["../../src/hooks/use-object-url.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"use-object-url.d.ts","sourceRoot":"","sources":["../../src/hooks/use-object-url.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,QAAQ,EACR,sBAAsB,EAEtB,KAAK,EACL,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAMxB,MAAM,MAAM,mBAAmB,GAAG;IAChC,qEAAqE;IACrE,GAAG,CAAC,EAAE,KAAK,CAAC;IACZ,kDAAkD;IAClD,KAAK,EAAE,WAAW,CAAC;IACnB,qEAAqE;IACrE,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,yDAAyD;IACzD,WAAW,CAAC,EAAE,sBAAsB,CAAC;IACrC,yCAAyC;IACzC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,qEAAqE;IACrE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,yEAAyE;IACzE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,wEAAwE;IACxE,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,yDAAyD;IACzD,KAAK,EAAE,QAAQ,GAAG,IAAI,CAAC;IACvB,2DAA2D;IAC3D,SAAS,EAAE,OAAO,CAAC;IACnB,+CAA+C;IAC/C,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB,CAAC;AAyGF;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,kBAAkB,CAoK7E"}
|