@dimah-s3/react 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/engine.js +6 -0
- package/dist/engine.js.map +1 -1
- package/dist/hooks/index.d.ts +3 -5
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/use-delete.d.ts +12 -2
- package/dist/hooks/use-delete.d.ts.map +1 -1
- package/dist/hooks/use-download.d.ts +27 -2
- package/dist/hooks/use-download.d.ts.map +1 -1
- package/dist/hooks/use-file-intake.d.ts +1 -1
- package/dist/hooks/use-file-upload.d.ts +13 -48
- package/dist/hooks/use-file-upload.d.ts.map +1 -1
- package/dist/hooks/use-upload.d.ts +37 -16
- package/dist/hooks/use-upload.d.ts.map +1 -1
- package/dist/index.d.ts +3 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +167 -421
- package/dist/index.js.map +1 -1
- package/dist/store/memory-store.d.ts +1 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/upload.d.ts +40 -19
- package/dist/types/upload.d.ts.map +1 -1
- package/dist/upload/constants.d.ts +2 -0
- package/dist/upload/constants.d.ts.map +1 -1
- package/dist/upload/upload-files.d.ts +4 -2
- package/dist/upload/upload-files.d.ts.map +1 -1
- package/package.json +2 -2
- package/dist/hooks/use-multi-file-upload.d.ts +0 -44
- package/dist/hooks/use-multi-file-upload.d.ts.map +0 -1
- package/dist/hooks/use-multi-upload.d.ts +0 -63
- package/dist/hooks/use-multi-upload.d.ts.map +0 -1
- package/dist/types/multi-upload.d.ts +0 -26
- package/dist/types/multi-upload.d.ts.map +0 -1
|
@@ -8,7 +8,7 @@ import type { UploadStore } from "../types/upload-store";
|
|
|
8
8
|
* @example
|
|
9
9
|
* ```ts
|
|
10
10
|
* const store = createMemoryStore();
|
|
11
|
-
*
|
|
11
|
+
* useUpload({ api, route: "uploads", uploadStore: store });
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
14
|
export declare function createMemoryStore(): UploadStore;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAC/B,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
|
package/dist/types/upload.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { S3RouteName, UploadPresignResponse } from "@dimah-s3/core";
|
|
1
|
+
import type { DimahS3Error, S3RouteName, UploadPresignResponse } from "@dimah-s3/core";
|
|
2
2
|
import type { UploadStore } from "./upload-store";
|
|
3
3
|
/** Result returned after a successful upload. */
|
|
4
4
|
export type UploadResult = {
|
|
@@ -25,6 +25,8 @@ export type UploadProgress = {
|
|
|
25
25
|
speed?: number;
|
|
26
26
|
};
|
|
27
27
|
export type UploadPhase = "idle" | "validating" | "presigning" | "uploading" | "finalizing" | "success" | "error";
|
|
28
|
+
/** Per-file status inside a batch (`pending` before bytes start). */
|
|
29
|
+
export type UploadFileStatus = "pending" | "uploading" | "success" | "error";
|
|
28
30
|
/** Display metadata for a file in upload UI (no raw `File`). */
|
|
29
31
|
export type UploadFileInfo = {
|
|
30
32
|
/** Display file name. */
|
|
@@ -39,6 +41,16 @@ export type UploadFileInfo = {
|
|
|
39
41
|
*/
|
|
40
42
|
previewUrl: string | null;
|
|
41
43
|
};
|
|
44
|
+
/** Per-file state in `useUpload` (`files[]`; `file` is `files[0]`). */
|
|
45
|
+
export type UploadFileState = UploadFileInfo & {
|
|
46
|
+
/** Unique ID for this file in the batch. */
|
|
47
|
+
id: string;
|
|
48
|
+
status: UploadFileStatus;
|
|
49
|
+
progress: UploadProgress;
|
|
50
|
+
error: DimahS3Error | null;
|
|
51
|
+
/** Set after this file succeeds. */
|
|
52
|
+
result: UploadResult | null;
|
|
53
|
+
};
|
|
42
54
|
/** Per-upload options passed to the presign API. */
|
|
43
55
|
export type UploadRequestOptions = {
|
|
44
56
|
/**
|
|
@@ -59,24 +71,34 @@ export type UploadRequestOptions = {
|
|
|
59
71
|
*/
|
|
60
72
|
checksum?: string;
|
|
61
73
|
};
|
|
62
|
-
/**
|
|
74
|
+
/**
|
|
75
|
+
* Lifecycle hooks for `useUpload`.
|
|
76
|
+
* Callbacks that receive `File[]` / `UploadResult[]` always use arrays
|
|
77
|
+
* (a single file is `[file]` / `[result]`).
|
|
78
|
+
*/
|
|
63
79
|
export type UploadHooks = {
|
|
64
80
|
/** Runs before the upload starts. Return `false` to block it. */
|
|
65
|
-
beforeUpload?: (
|
|
81
|
+
beforeUpload?: (files: File[]) => Promise<boolean> | boolean;
|
|
66
82
|
/** Fires after validation passes and the upload begins. */
|
|
67
|
-
onUploadStart?: (
|
|
68
|
-
/** Fires continuously
|
|
69
|
-
onProgress?: (
|
|
83
|
+
onUploadStart?: (files: File[]) => void;
|
|
84
|
+
/** Fires continuously with aggregate progress across the batch. */
|
|
85
|
+
onProgress?: (progress: UploadProgress) => void;
|
|
86
|
+
/** Fires continuously for one file while its bytes are transferred. */
|
|
87
|
+
onFileProgress?: (file: File, progress: UploadProgress) => void;
|
|
70
88
|
/** Fires after each part is successfully uploaded to S3 (multipart only). */
|
|
71
89
|
onPartUpload?: (file: File, partNumber: number, totalParts: number) => void;
|
|
72
90
|
/** Fires once after `CreateMultipartUpload` succeeds (multipart only). */
|
|
73
91
|
onMultipartInit?: (file: File, uploadId: string) => void;
|
|
74
|
-
/** Fires when the
|
|
75
|
-
|
|
76
|
-
/** Fires when
|
|
77
|
-
|
|
92
|
+
/** Fires when one file in the batch finishes successfully. */
|
|
93
|
+
onFileSuccess?: (file: File, result: UploadResult) => void;
|
|
94
|
+
/** Fires when one file in the batch fails. */
|
|
95
|
+
onFileError?: (file: File, error: DimahS3Error) => void;
|
|
96
|
+
/** Fires when every file in the batch succeeds. */
|
|
97
|
+
onSuccess?: (results: UploadResult[]) => Promise<void> | void;
|
|
98
|
+
/** Fires when the batch fails (validation, block, or one or more file errors). */
|
|
99
|
+
onError?: (error: unknown, phase: UploadPhase) => void;
|
|
78
100
|
/** Fires when the upload is cancelled via `cancel()`. */
|
|
79
|
-
onCancel?: (
|
|
101
|
+
onCancel?: () => void;
|
|
80
102
|
};
|
|
81
103
|
/**
|
|
82
104
|
* Replaces PUT/POST to `presign.url`. Use for in-memory backends or when
|
|
@@ -100,7 +122,7 @@ export type RetryConfig = {
|
|
|
100
122
|
/** Base delay in ms for exponential backoff. @default 1000 */
|
|
101
123
|
baseDelay?: number;
|
|
102
124
|
};
|
|
103
|
-
/** Engine configuration for `
|
|
125
|
+
/** Engine configuration for `useUpload`. */
|
|
104
126
|
export type FileUploadConfig = {
|
|
105
127
|
/**
|
|
106
128
|
* Named server route (`dimahS3({ routes })`). Required — the server
|
|
@@ -124,6 +146,10 @@ export type FileUploadConfig = {
|
|
|
124
146
|
* route `maxFileSize`. Omitted values are filled from `api.catalog()`.
|
|
125
147
|
*/
|
|
126
148
|
maxFileSize?: number;
|
|
149
|
+
/**
|
|
150
|
+
* Max number of files per selection. @default 1
|
|
151
|
+
*/
|
|
152
|
+
maxFiles?: number;
|
|
127
153
|
/**
|
|
128
154
|
* Compute and send a SHA-256 checksum on presign. Filled from
|
|
129
155
|
* `api.catalog()` when the route sets `upload.checksum`.
|
|
@@ -131,6 +157,8 @@ export type FileUploadConfig = {
|
|
|
131
157
|
checksum?: boolean;
|
|
132
158
|
/** Number of parts uploaded concurrently (multipart). */
|
|
133
159
|
concurrentParts?: number;
|
|
160
|
+
/** Number of files uploaded concurrently when `maxFiles` is greater than 1. */
|
|
161
|
+
concurrentFiles?: number;
|
|
134
162
|
/** Retry configuration for failed network requests. */
|
|
135
163
|
retry?: RetryConfig;
|
|
136
164
|
/**
|
|
@@ -142,11 +170,4 @@ export type FileUploadConfig = {
|
|
|
142
170
|
*/
|
|
143
171
|
uploadStore?: UploadStore | false;
|
|
144
172
|
};
|
|
145
|
-
/** Extra engine configuration for multi-file uploads. */
|
|
146
|
-
export type MultiFileUploadConfig = FileUploadConfig & {
|
|
147
|
-
/** Max number of files in a batch. */
|
|
148
|
-
maxFiles?: number;
|
|
149
|
-
/** Number of files uploaded concurrently. */
|
|
150
|
-
concurrentFiles?: number;
|
|
151
|
-
};
|
|
152
173
|
//# sourceMappingURL=upload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/types/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../../src/types/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,qBAAqB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElD,iDAAiD;AACjD,MAAM,MAAM,YAAY,GAAG;IACzB,qBAAqB;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,2BAA2B;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0DAA0D;IAC1D,aAAa,EAAE,MAAM,CAAC;IACtB,iCAAiC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,4DAA4D;AAC5D,MAAM,MAAM,cAAc,GAAG;IAC3B,gCAAgC;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,+BAA+B;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,mCAA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KAAK,IAAI,CAAC;IAChD,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB,KACE,OAAO,CAAC,IAAI,CAAC,CAAC;AAEnB;;;GAGG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,CAAC;AAEF,uDAAuD;AACvD,MAAM,MAAM,WAAW,GAAG;IACxB,+DAA+D;IAC/D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,8DAA8D;IAC9D,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,4CAA4C;AAC5C,MAAM,MAAM,gBAAgB,GAAG;IAC7B;;;OAGG;IACH,KAAK,EAAE,WAAW,CAAC;IACnB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,yDAAyD;IACzD,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,+EAA+E;IAC/E,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,uDAAuD;IACvD,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB;;;;;;OAMG;IACH,WAAW,CAAC,EAAE,WAAW,GAAG,KAAK,CAAC;CACnC,CAAC"}
|
|
@@ -4,4 +4,6 @@ export declare const MAX_RETRIES = 3;
|
|
|
4
4
|
export declare const RETRY_BASE_DELAY = 1000;
|
|
5
5
|
export declare const DEFAULT_CONCURRENT_PARTS = 2;
|
|
6
6
|
export declare const DEFAULT_CONCURRENT_FILES = 2;
|
|
7
|
+
/** Default max files per selection — one file. */
|
|
8
|
+
export declare const DEFAULT_MAX_FILES = 1;
|
|
7
9
|
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/upload/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,QAAmB,CAAC;AAC5D,eAAO,MAAM,iBAAiB,QAAkB,CAAC;AACjD,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,gBAAgB,OAAQ,CAAC;AACtC,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,wBAAwB,IAAI,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/upload/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,2BAA2B,QAAmB,CAAC;AAC5D,eAAO,MAAM,iBAAiB,QAAkB,CAAC;AACjD,eAAO,MAAM,WAAW,IAAI,CAAC;AAC7B,eAAO,MAAM,gBAAgB,OAAQ,CAAC;AACtC,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAC1C,kDAAkD;AAClD,eAAO,MAAM,iBAAiB,IAAI,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { FileUploadConfig, UploadPhase, UploadProgress, UploadResult, UploadRequestOptions } from "../types";
|
|
2
2
|
import type { DimahS3Error, S3Api } from "@dimah-s3/core";
|
|
3
3
|
export type FileItemStatus = "pending" | "uploading" | "success" | "error";
|
|
4
4
|
export type FileItem = {
|
|
@@ -16,9 +16,11 @@ export type MultiUploadCallbacks = {
|
|
|
16
16
|
onTotalProgress?: (progress: UploadProgress) => void;
|
|
17
17
|
/** Called once after multipart init for a file (id → uploadId, server key). */
|
|
18
18
|
onMultipartInit?: (id: string, uploadId: string, key: string) => void;
|
|
19
|
+
onFilePhaseChange?: (id: string, phase: Extract<UploadPhase, "presigning" | "uploading" | "finalizing">) => void;
|
|
20
|
+
onPartUpload?: (id: string, partNumber: number, totalParts: number) => void;
|
|
19
21
|
};
|
|
20
22
|
export declare function uploadFiles(api: S3Api, items: Array<{
|
|
21
23
|
id: string;
|
|
22
24
|
file: File;
|
|
23
|
-
}>, config:
|
|
25
|
+
}>, config: FileUploadConfig, callbacks?: MultiUploadCallbacks, signal?: AbortSignal, getRequestOptions?: (file: File) => UploadRequestOptions): Promise<FileItem[]>;
|
|
24
26
|
//# sourceMappingURL=upload-files.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upload-files.d.ts","sourceRoot":"","sources":["../../src/upload/upload-files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,
|
|
1
|
+
{"version":3,"file":"upload-files.d.ts","sourceRoot":"","sources":["../../src/upload/upload-files.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,YAAY,EACZ,oBAAoB,EACrB,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAK1D,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAE3E,MAAM,MAAM,QAAQ,GAAG;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,IAAI,CAAC;IACX,MAAM,EAAE,cAAc,CAAC;IACvB,QAAQ,EAAE,cAAc,CAAC;IACzB,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,cAAc,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;IAChE,aAAa,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,KAAK,IAAI,CAAC;IAC3D,WAAW,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IACxD,eAAe,CAAC,EAAE,CAAC,QAAQ,EAAE,cAAc,KAAK,IAAI,CAAC;IACrD,+EAA+E;IAC/E,eAAe,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACtE,iBAAiB,CAAC,EAAE,CAClB,EAAE,EAAE,MAAM,EACV,KAAK,EAAE,OAAO,CAAC,WAAW,EAAE,YAAY,GAAG,WAAW,GAAG,YAAY,CAAC,KACnE,IAAI,CAAC;IACV,YAAY,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CAC7E,CAAC;AAEF,wBAAsB,WAAW,CAC/B,GAAG,EAAE,KAAK,EACV,KAAK,EAAE,KAAK,CAAC;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,EACxC,MAAM,EAAE,gBAAgB,EACxB,SAAS,GAAE,oBAAyB,EACpC,MAAM,CAAC,EAAE,WAAW,EACpB,iBAAiB,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,oBAAoB,GACvD,OAAO,CAAC,QAAQ,EAAE,CAAC,CAiFrB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dimah-s3/react",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Headless React hooks for presigned S3 file uploads, downloads, and deletes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"s3",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"dist"
|
|
45
45
|
],
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@dimah-s3/core": "1.
|
|
47
|
+
"@dimah-s3/core": "1.2.0",
|
|
48
48
|
"@fuma-translate/react": "^1.0.2",
|
|
49
49
|
"immer": "^11.1.18",
|
|
50
50
|
"react-dropzone": "^20.1.1"
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { S3Api } from "@dimah-s3/core";
|
|
2
|
-
import { DimahS3Error } from "@dimah-s3/core";
|
|
3
|
-
import type { MultiFileUploadConfig, UploadProgress, UploadRequestOptions, MultiUploadPhase, MultiUploadFileState, MultiUploadHooks } from "../types";
|
|
4
|
-
/** Options for {@link useMultiFileUpload}. */
|
|
5
|
-
export type UseMultiFileUploadOptions = MultiFileUploadConfig & MultiUploadHooks & {
|
|
6
|
-
/** S3Api. Optional when an `<S3Provider>` is present in the tree. */
|
|
7
|
-
api?: S3Api;
|
|
8
|
-
/** Static request options applied to all files. */
|
|
9
|
-
uploadOptions?: UploadRequestOptions;
|
|
10
|
-
/** Per-file request options (overrides `uploadOptions`). */
|
|
11
|
-
getUploadOptions?: (file: File) => UploadRequestOptions;
|
|
12
|
-
};
|
|
13
|
-
export type UseMultiFileUploadState = {
|
|
14
|
-
/** Current batch upload phase. */
|
|
15
|
-
phase: MultiUploadPhase;
|
|
16
|
-
/** Per-file upload states. */
|
|
17
|
-
files: MultiUploadFileState[];
|
|
18
|
-
/** Aggregated progress across all files. */
|
|
19
|
-
totalProgress: UploadProgress;
|
|
20
|
-
/** Batch-level error, or `null`. */
|
|
21
|
-
error: DimahS3Error | null;
|
|
22
|
-
};
|
|
23
|
-
export type UseMultiFileUploadReturn = UseMultiFileUploadState & {
|
|
24
|
-
/** `true` while bytes are transferring (`phase === "uploading"`). */
|
|
25
|
-
isUploading: boolean;
|
|
26
|
-
/** `true` while the batch is in-flight (`validating` or `uploading`). */
|
|
27
|
-
isPending: boolean;
|
|
28
|
-
/** Upload multiple files. The server generates each object key. */
|
|
29
|
-
upload: (files: File[]) => Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* Abort all in-flight uploads and clean up multipart / store resources
|
|
32
|
-
* (same semantics as {@link useFileUpload}'s `cancel`).
|
|
33
|
-
*/
|
|
34
|
-
cancel: () => void;
|
|
35
|
-
/**
|
|
36
|
-
* Stop uploads but preserve multipart store entries for resume
|
|
37
|
-
* (same semantics as {@link useFileUpload}'s `detach`).
|
|
38
|
-
*/
|
|
39
|
-
detach: () => void;
|
|
40
|
-
/** Reset state to `idle`. */
|
|
41
|
-
reset: () => void;
|
|
42
|
-
};
|
|
43
|
-
export declare function useMultiFileUpload(options: UseMultiFileUploadOptions): UseMultiFileUploadReturn;
|
|
44
|
-
//# sourceMappingURL=use-multi-file-upload.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-multi-file-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-multi-file-upload.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAgB,MAAM,gBAAgB,CAAC;AAW5D,OAAO,KAAK,EACV,qBAAqB,EACrB,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AAMjB,8CAA8C;AAC9C,MAAM,MAAM,yBAAyB,GAAG,qBAAqB,GAC3D,gBAAgB,GAAG;IACjB,qEAAqE;IACrE,GAAG,CAAC,EAAE,KAAK,CAAC;IACZ,mDAAmD;IACnD,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,4DAA4D;IAC5D,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,oBAAoB,CAAC;CACzD,CAAC;AAEJ,MAAM,MAAM,uBAAuB,GAAG;IACpC,kCAAkC;IAClC,KAAK,EAAE,gBAAgB,CAAC;IACxB,8BAA8B;IAC9B,KAAK,EAAE,oBAAoB,EAAE,CAAC;IAC9B,4CAA4C;IAC5C,aAAa,EAAE,cAAc,CAAC;IAC9B,oCAAoC;IACpC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,uBAAuB,GAAG;IAC/D,qEAAqE;IACrE,WAAW,EAAE,OAAO,CAAC;IACrB,yEAAyE;IACzE,SAAS,EAAE,OAAO,CAAC;IACnB,mEAAmE;IACnE,MAAM,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzC;;;OAGG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB;;;OAGG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AA0BF,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,yBAAyB,GACjC,wBAAwB,CA+Y1B"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import type { DimahS3Error } from "@dimah-s3/core";
|
|
2
|
-
import type { UploadProgress, MultiUploadFileState, MultiUploadPhase } from "../types";
|
|
3
|
-
import { type UseMultiFileUploadOptions } from "./use-multi-file-upload";
|
|
4
|
-
import { type DropzoneInputProps, type DropzoneRootProps, type FileRejection } from "./use-file-intake";
|
|
5
|
-
export type { DropzoneInputProps, DropzoneRootProps, FileRejection };
|
|
6
|
-
/** Options for {@link useMultiUpload}. */
|
|
7
|
-
export type UseMultiUploadOptions = UseMultiFileUploadOptions & {
|
|
8
|
-
/** Disable all intake interactions. */
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
/**
|
|
11
|
-
* Disable drag interactions on the root (button-style UIs).
|
|
12
|
-
* @default false
|
|
13
|
-
*/
|
|
14
|
-
noDrag?: boolean;
|
|
15
|
-
/**
|
|
16
|
-
* Disable click-to-open on the root (when opening via `open()` on a button).
|
|
17
|
-
* @default false
|
|
18
|
-
*/
|
|
19
|
-
noClick?: boolean;
|
|
20
|
-
/**
|
|
21
|
-
* Disable keyboard activation on the root.
|
|
22
|
-
* @default false
|
|
23
|
-
*/
|
|
24
|
-
noKeyboard?: boolean;
|
|
25
|
-
/** Called when dropzone soft-rejects files (type/size/count). */
|
|
26
|
-
onFileReject?: (rejections: readonly FileRejection[]) => void;
|
|
27
|
-
};
|
|
28
|
-
export type UseMultiUploadReturn = {
|
|
29
|
-
/** Current batch upload phase. */
|
|
30
|
-
phase: MultiUploadPhase;
|
|
31
|
-
/** Per-file upload states. */
|
|
32
|
-
files: MultiUploadFileState[];
|
|
33
|
-
/** Aggregated progress across all files. */
|
|
34
|
-
totalProgress: UploadProgress;
|
|
35
|
-
/** Batch-level error, or `null`. */
|
|
36
|
-
error: DimahS3Error | null;
|
|
37
|
-
/** `true` while bytes are transferring (`phase === "uploading"`). */
|
|
38
|
-
isUploading: boolean;
|
|
39
|
-
/** `true` while the batch is in-flight (`validating` or `uploading`). */
|
|
40
|
-
isPending: boolean;
|
|
41
|
-
/** Handle files programmatically (bypasses dropzone). */
|
|
42
|
-
handleFiles: (files: FileList | File[] | null) => void;
|
|
43
|
-
/** Open the native file picker. */
|
|
44
|
-
open: () => void;
|
|
45
|
-
/** Abort all in-flight uploads. */
|
|
46
|
-
cancel: () => void;
|
|
47
|
-
/** Preserve multipart store entries for resume. */
|
|
48
|
-
detach: () => void;
|
|
49
|
-
/** Reset state to `idle`. */
|
|
50
|
-
reset: () => void;
|
|
51
|
-
/** Spread on the dropzone / clickable root element. */
|
|
52
|
-
getRootProps: <T extends DropzoneRootProps>(props?: T) => T;
|
|
53
|
-
/** Spread on a hidden `<input type="file">`. */
|
|
54
|
-
getInputProps: <T extends DropzoneInputProps>(props?: T) => T;
|
|
55
|
-
/** `true` while a drag is over the root. */
|
|
56
|
-
isDragActive: boolean;
|
|
57
|
-
isDragAccept: boolean;
|
|
58
|
-
isDragReject: boolean;
|
|
59
|
-
/** Soft rejections from the last drop / selection. */
|
|
60
|
-
fileRejections: readonly FileRejection[];
|
|
61
|
-
};
|
|
62
|
-
export declare function useMultiUpload(options: UseMultiUploadOptions): UseMultiUploadReturn;
|
|
63
|
-
//# sourceMappingURL=use-multi-upload.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"use-multi-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-multi-upload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,SAAS,CAAC;AACjB,OAAO,EAEL,KAAK,yBAAyB,EAC/B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,mBAAmB,CAAC;AAG3B,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,aAAa,EAAE,CAAC;AAErE,0CAA0C;AAC1C,MAAM,MAAM,qBAAqB,GAAG,yBAAyB,GAAG;IAC9D,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;OAGG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,iEAAiE;IACjE,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,SAAS,aAAa,EAAE,KAAK,IAAI,CAAC;CAC/D,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,kCAAkC;IAClC,KAAK,EAAE,gBAAgB,CAAC;IACxB,8BAA8B;IAC9B,KAAK,EAAE,oBAAoB,EAAE,CAAC;IAC9B,4CAA4C;IAC5C,aAAa,EAAE,cAAc,CAAC;IAC9B,oCAAoC;IACpC,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IAC3B,qEAAqE;IACrE,WAAW,EAAE,OAAO,CAAC;IACrB,yEAAyE;IACzE,SAAS,EAAE,OAAO,CAAC;IACnB,yDAAyD;IACzD,WAAW,EAAE,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,EAAE,GAAG,IAAI,KAAK,IAAI,CAAC;IACvD,mCAAmC;IACnC,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,mCAAmC;IACnC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,mDAAmD;IACnD,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,uDAAuD;IACvD,YAAY,EAAE,CAAC,CAAC,SAAS,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC5D,gDAAgD;IAChD,aAAa,EAAE,CAAC,CAAC,SAAS,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC9D,4CAA4C;IAC5C,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,OAAO,CAAC;IACtB,sDAAsD;IACtD,cAAc,EAAE,SAAS,aAAa,EAAE,CAAC;CAC1C,CAAC;AAEF,wBAAgB,cAAc,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,oBAAoB,CAsDtB"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { DimahS3Error } from "@dimah-s3/core";
|
|
2
|
-
import type { UploadFileInfo, UploadProgress, UploadResult } from "./upload";
|
|
3
|
-
export type MultiUploadPhase = "idle" | "validating" | "uploading" | "success" | "error";
|
|
4
|
-
/** Per-file state in a multi-upload batch. */
|
|
5
|
-
export type MultiUploadFileState = UploadFileInfo & {
|
|
6
|
-
/** Unique ID for this file in the batch. */
|
|
7
|
-
id: string;
|
|
8
|
-
status: "pending" | "uploading" | "success" | "error";
|
|
9
|
-
progress: UploadProgress;
|
|
10
|
-
error: DimahS3Error | null;
|
|
11
|
-
/** Set after this file succeeds. */
|
|
12
|
-
result: UploadResult | null;
|
|
13
|
-
};
|
|
14
|
-
/** Lifecycle hooks for multi-file upload. */
|
|
15
|
-
export type MultiUploadHooks = {
|
|
16
|
-
beforeUpload?: (files: File[]) => Promise<boolean> | boolean;
|
|
17
|
-
onUploadStart?: (files: File[]) => void;
|
|
18
|
-
onFileProgress?: (file: File, progress: UploadProgress) => void;
|
|
19
|
-
onFileSuccess?: (file: File, result: UploadResult) => void;
|
|
20
|
-
onFileError?: (file: File, error: DimahS3Error) => void;
|
|
21
|
-
onProgress?: (progress: UploadProgress) => void;
|
|
22
|
-
onSuccess?: (results: UploadResult[]) => Promise<void> | void;
|
|
23
|
-
onError?: (error: unknown) => void;
|
|
24
|
-
onCancel?: () => void;
|
|
25
|
-
};
|
|
26
|
-
//# sourceMappingURL=multi-upload.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"multi-upload.d.ts","sourceRoot":"","sources":["../../src/types/multi-upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAE7E,MAAM,MAAM,gBAAgB,GAC1B,MAAM,GAAG,YAAY,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;AAE5D,8CAA8C;AAC9C,MAAM,MAAM,oBAAoB,GAAG,cAAc,GAAG;IAClD,4CAA4C;IAC5C,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,SAAS,GAAG,WAAW,GAAG,SAAS,GAAG,OAAO,CAAC;IACtD,QAAQ,EAAE,cAAc,CAAC;IACzB,KAAK,EAAE,YAAY,GAAG,IAAI,CAAC;IAC3B,oCAAoC;IACpC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;CAC7B,CAAC;AAEF,6CAA6C;AAC7C,MAAM,MAAM,gBAAgB,GAAG;IAC7B,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,OAAO,CAAC,O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