@dimah-s3/react 0.6.3 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -2
- package/dist/helpers/file-preview.d.ts +5 -0
- package/dist/helpers/file-preview.d.ts.map +1 -0
- package/dist/helpers/index.d.ts +2 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/to-dropzone-accept.d.ts +16 -0
- package/dist/helpers/to-dropzone-accept.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +5 -4
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/use-delete.d.ts.map +1 -1
- package/dist/hooks/use-download.d.ts.map +1 -1
- package/dist/hooks/use-fetch-download.d.ts.map +1 -1
- package/dist/hooks/use-file-intake.d.ts +46 -0
- package/dist/hooks/use-file-intake.d.ts.map +1 -0
- package/dist/hooks/use-file-upload.d.ts +76 -0
- package/dist/hooks/use-file-upload.d.ts.map +1 -0
- package/dist/hooks/use-multi-file-upload.d.ts +39 -0
- package/dist/hooks/use-multi-file-upload.d.ts.map +1 -0
- package/dist/hooks/use-multi-upload.d.ts +44 -22
- package/dist/hooks/use-multi-upload.d.ts.map +1 -1
- package/dist/hooks/use-upload.d.ts +51 -67
- package/dist/hooks/use-upload.d.ts.map +1 -1
- package/dist/index.d.ts +6 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +503 -247
- package/dist/index.js.map +1 -1
- package/dist/store/create-hook-store.d.ts +48 -0
- package/dist/store/create-hook-store.d.ts.map +1 -0
- package/dist/store/memory-store.d.ts +1 -1
- package/dist/translations/types.d.ts +1 -5
- package/dist/translations/types.d.ts.map +1 -1
- package/dist/types/multi-upload.d.ts +7 -0
- package/dist/types/multi-upload.d.ts.map +1 -1
- package/dist/types/upload.d.ts +15 -1
- package/dist/types/upload.d.ts.map +1 -1
- package/package.json +8 -5
- package/dist/hooks/use-multi-upload-controls.d.ts +0 -45
- package/dist/hooks/use-multi-upload-controls.d.ts.map +0 -1
- package/dist/hooks/use-upload-controls.d.ts +0 -54
- package/dist/hooks/use-upload-controls.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ pnpm add @dimah-s3/react
|
|
|
13
13
|
## Minimal setup
|
|
14
14
|
|
|
15
15
|
```tsx
|
|
16
|
-
import { createS3Client,
|
|
16
|
+
import { createS3Client, useUpload } from "@dimah-s3/react";
|
|
17
17
|
|
|
18
18
|
export const { api, S3Provider, useApi } = createS3Client();
|
|
19
19
|
|
|
@@ -21,8 +21,11 @@ export const { api, S3Provider, useApi } = createS3Client();
|
|
|
21
21
|
<S3Provider>{children}</S3Provider>;
|
|
22
22
|
|
|
23
23
|
// In a component
|
|
24
|
-
const {
|
|
24
|
+
const { open, getInputProps } = useUpload({
|
|
25
25
|
objectKey: (file) => `uploads/${file.name}`,
|
|
26
|
+
noDrag: true,
|
|
27
|
+
noClick: true,
|
|
28
|
+
noKeyboard: true,
|
|
26
29
|
});
|
|
27
30
|
```
|
|
28
31
|
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Create an object URL for image files; returns `null` for non-images. */
|
|
2
|
+
export declare function createImagePreviewUrl(file: File): string | null;
|
|
3
|
+
/** Revoke an object URL created by {@link createImagePreviewUrl}. */
|
|
4
|
+
export declare function revokePreviewUrl(url: string | null | undefined): void;
|
|
5
|
+
//# sourceMappingURL=file-preview.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"file-preview.d.ts","sourceRoot":"","sources":["../../src/helpers/file-preview.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM,GAAG,IAAI,CAG/D;AAED,qEAAqE;AACrE,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,IAAI,CAGrE"}
|
package/dist/helpers/index.d.ts
CHANGED
|
@@ -6,4 +6,6 @@ export { useFormatValidateFileError } from "./format-validate-file-error";
|
|
|
6
6
|
export { useFormatDimahError } from "./format-dimah-error";
|
|
7
7
|
export { createSpeedTracker, type SpeedTracker } from "./speed-tracker";
|
|
8
8
|
export { createThrottledSpeedUpdater } from "./throttled-speed";
|
|
9
|
+
export { createImagePreviewUrl, revokePreviewUrl } from "./file-preview";
|
|
10
|
+
export { toDropzoneAccept } from "./to-dropzone-accept";
|
|
9
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,KAAK,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,2BAA2B,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACzE,OAAO,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Accept } from "react-dropzone";
|
|
2
|
+
/**
|
|
3
|
+
* Convert dimah-s3 `accept: string[]` into react-dropzone's `Accept` map.
|
|
4
|
+
*
|
|
5
|
+
* - MIME types / wildcards (`image/*`, `application/pdf`) become keys.
|
|
6
|
+
* - Bare extensions (`.png`, `pdf`) are grouped under a catch-all MIME key
|
|
7
|
+
* (`"*" + "/*"`) so dropzone can still match by filename extension.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* toDropzoneAccept(["image/*", ".pdf"])
|
|
12
|
+
* // → { "image/*": [], "*\/\*": [".pdf"] } (catch-all MIME key)
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare function toDropzoneAccept(accept: string[] | undefined): Accept | undefined;
|
|
16
|
+
//# sourceMappingURL=to-dropzone-accept.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"to-dropzone-accept.d.ts","sourceRoot":"","sources":["../../src/helpers/to-dropzone-accept.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,GAC3B,MAAM,GAAG,SAAS,CAuBpB"}
|
package/dist/hooks/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export {
|
|
4
|
-
export {
|
|
1
|
+
export { useFileUpload, type UseFileUploadOptions, type UseFileUploadState, type UseFileUploadReturn, } from "./use-file-upload";
|
|
2
|
+
export { useMultiFileUpload, type UseMultiFileUploadOptions, type UseMultiFileUploadState, type UseMultiFileUploadReturn, } from "./use-multi-file-upload";
|
|
3
|
+
export { useUpload, type UseUploadOptions, type UseUploadReturn, } from "./use-upload";
|
|
4
|
+
export { useMultiUpload, type UseMultiUploadOptions, type UseMultiUploadReturn, } from "./use-multi-upload";
|
|
5
|
+
export { useFileIntake, type UseFileIntakeOptions, type UseFileIntakeReturn, type FileRejection, type DropzoneRootProps, type DropzoneInputProps, } from "./use-file-intake";
|
|
5
6
|
export { useDownload, type DownloadPhase, type DownloadHooks, type UseDownloadOptions, type UseDownloadState, type UseDownloadReturn, } from "./use-download";
|
|
6
7
|
export { useFetchDownload, type FetchDownloadPhase, type FetchDownloadProgress, type FetchDownloadHooks, type UseFetchDownloadOptions, type UseFetchDownloadState, type UseFetchDownloadReturn, } from "./use-fetch-download";
|
|
7
8
|
export { useDelete, type UseDeleteOptions, type UseDeleteState, type UseDeleteReturn, } from "./use-delete";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,GAC9B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACvB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,gBAAgB,EAChB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,GAC5B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,cAAc,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-delete.d.ts","sourceRoot":"","sources":["../../src/hooks/use-delete.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"use-delete.d.ts","sourceRoot":"","sources":["../../src/hooks/use-delete.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,OAAO,KAAK,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AASzD,qCAAqC;AACrC,MAAM,MAAM,gBAAgB,GAAG,WAAW,GAAG;IAC3C,qEAAqE;IACrE,GAAG,CAAC,EAAE,KAAK,CAAC;IACZ,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,4BAA4B;IAC5B,KAAK,EAAE,WAAW,CAAC;IACnB,gCAAgC;IAChC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG,cAAc,GAAG;IAC7C,4CAA4C;IAC5C,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,wDAAwD;IACxD,aAAa,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,mDAAmD;IACnD,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACnC,gDAAgD;IAChD,YAAY,EAAE,MAAM,IAAI,CAAC;IACzB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAcF,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CA4FpE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-download.d.ts","sourceRoot":"","sources":["../../src/hooks/use-download.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-download.d.ts","sourceRoot":"","sources":["../../src/hooks/use-download.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAU5C,YAAY,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEtE,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAEtE,uCAAuC;AACvC,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG;IAC/C,qEAAqE;IACrE,GAAG,CAAC,EAAE,KAAK,CAAC;IACZ,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,8BAA8B;IAC9B,KAAK,EAAE,aAAa,CAAC;IACrB,gCAAgC;IAChC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,wEAAwE;IACxE,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACnB,wDAAwD;IACxD,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,GAAG;IACjD,qDAAqD;IACrD,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,qEAAqE;IACrE,OAAO,EAAE,CACP,GAAG,EAAE,MAAM,EACX,YAAY,CAAC,EAAE,MAAM,KAClB,OAAO,CAAC;QAAE,GAAG,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC,CAAC;IACxD,6BAA6B;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AASF,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAmF1E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-fetch-download.d.ts","sourceRoot":"","sources":["../../src/hooks/use-fetch-download.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAK5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-fetch-download.d.ts","sourceRoot":"","sources":["../../src/hooks/use-fetch-download.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAK5C,OAAO,KAAK,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAStD,YAAY,EACV,kBAAkB,EAClB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,mBAAmB,CAAC;AAE3B,4CAA4C;AAC5C,MAAM,MAAM,uBAAuB,GAAG,kBAAkB,GAAG;IACzD,qEAAqE;IACrE,GAAG,CAAC,EAAE,KAAK,CAAC;IACZ,gDAAgD;IAChD,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,8BAA8B;IAC9B,KAAK,EAAE,kBAAkB,CAAC;IAC1B,8BAA8B;IAC9B,QAAQ,EAAE,cAAc,CAAC;IACzB,gCAAgC;IAChC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,kCAAkC;IAClC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,gCAAgC;IAChC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG,qBAAqB,GAAG;IAC3D,sDAAsD;IACtD,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAChE,iCAAiC;IACjC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAYF,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,uBAAuB,GAC/B,sBAAsB,CA2JxB"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { type DropzoneInputProps, type DropzoneRootProps, type FileRejection } from "react-dropzone";
|
|
2
|
+
/** Options for {@link useFileIntake}. */
|
|
3
|
+
export type UseFileIntakeOptions = {
|
|
4
|
+
/** MIME types / extensions (dimah-s3 `accept` shape). */
|
|
5
|
+
accept?: string[];
|
|
6
|
+
/** Max file size in bytes (soft check at intake). */
|
|
7
|
+
maxFileSize?: number;
|
|
8
|
+
/** Max number of files (multi mode). */
|
|
9
|
+
maxFiles?: number;
|
|
10
|
+
/** Allow multiple files. @default false */
|
|
11
|
+
multiple?: boolean;
|
|
12
|
+
/** Disable all intake interactions. */
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
/** Disable click-to-open on the root. Useful for button-driven UIs. */
|
|
15
|
+
noClick?: boolean;
|
|
16
|
+
/** Disable drag-and-drop. */
|
|
17
|
+
noDrag?: boolean;
|
|
18
|
+
/** Disable keyboard activation on the root. */
|
|
19
|
+
noKeyboard?: boolean;
|
|
20
|
+
/** Called with accepted files from drop / picker / paste. */
|
|
21
|
+
onAccept: (files: File[]) => void;
|
|
22
|
+
/** Called when dropzone soft-rejects files. */
|
|
23
|
+
onReject?: (rejections: readonly FileRejection[]) => void;
|
|
24
|
+
};
|
|
25
|
+
export type UseFileIntakeReturn = {
|
|
26
|
+
getRootProps: <T extends DropzoneRootProps>(props?: T) => T;
|
|
27
|
+
getInputProps: <T extends DropzoneInputProps>(props?: T) => T;
|
|
28
|
+
/** Open the native file picker. */
|
|
29
|
+
open: () => void;
|
|
30
|
+
isDragActive: boolean;
|
|
31
|
+
isDragAccept: boolean;
|
|
32
|
+
isDragReject: boolean;
|
|
33
|
+
/** Soft rejections from the last drop / selection. */
|
|
34
|
+
fileRejections: readonly FileRejection[];
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Headless file intake powered by react-dropzone.
|
|
38
|
+
*
|
|
39
|
+
* Soft-validates `accept` / size / count at the dropzone layer; authoritative
|
|
40
|
+
* validation still runs inside `useFileUpload` / `useMultiFileUpload` via `validateFile`.
|
|
41
|
+
*
|
|
42
|
+
* @internal — prefer {@link useUpload} / {@link useMultiUpload}.
|
|
43
|
+
*/
|
|
44
|
+
export declare function useFileIntake(options: UseFileIntakeOptions): UseFileIntakeReturn;
|
|
45
|
+
export type { FileRejection, DropzoneRootProps, DropzoneInputProps };
|
|
46
|
+
//# sourceMappingURL=use-file-intake.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-file-intake.d.ts","sourceRoot":"","sources":["../../src/hooks/use-file-intake.ts"],"names":[],"mappings":"AAGA,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,gBAAgB,CAAC;AAIxB,yCAAyC;AACzC,MAAM,MAAM,oBAAoB,GAAG;IACjC,yDAAyD;IACzD,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,qDAAqD;IACrD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,wCAAwC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,2CAA2C;IAC3C,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uCAAuC;IACvC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,uEAAuE;IACvE,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,6BAA6B;IAC7B,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,+CAA+C;IAC/C,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,6DAA6D;IAC7D,QAAQ,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,KAAK,IAAI,CAAC;IAClC,+CAA+C;IAC/C,QAAQ,CAAC,EAAE,CAAC,UAAU,EAAE,SAAS,aAAa,EAAE,KAAK,IAAI,CAAC;CAC3D,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,EAAE,CAAC,CAAC,SAAS,iBAAiB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC5D,aAAa,EAAE,CAAC,CAAC,SAAS,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC;IAC9D,mCAAmC;IACnC,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,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;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,oBAAoB,GAC5B,mBAAmB,CA+CrB;AAED,YAAY,EAAE,aAAa,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,CAAC"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { S3Api } from "@dimah-s3/core";
|
|
2
|
+
import type { UploadConfig, UploadHooks, UploadPhase, UploadProgress, UploadResult, UploadRequestOptions } from "../types";
|
|
3
|
+
/** Options for {@link useFileUpload}. */
|
|
4
|
+
export type UseFileUploadOptions = UploadConfig & UploadHooks & {
|
|
5
|
+
/** S3Api. Optional when an `<S3Provider>` is present in the tree. */
|
|
6
|
+
api?: S3Api;
|
|
7
|
+
};
|
|
8
|
+
export type UseFileUploadState = {
|
|
9
|
+
/** Current upload phase. */
|
|
10
|
+
phase: UploadPhase;
|
|
11
|
+
/** Byte transfer progress. */
|
|
12
|
+
progress: UploadProgress;
|
|
13
|
+
/** Error message, or `null`. */
|
|
14
|
+
error: string | null;
|
|
15
|
+
/** Result after success, or `null`. */
|
|
16
|
+
result: UploadResult | null;
|
|
17
|
+
/** Name of the file being uploaded. */
|
|
18
|
+
fileName: string | null;
|
|
19
|
+
/** Size of the file being uploaded in bytes. */
|
|
20
|
+
fileSize: number | null;
|
|
21
|
+
/** MIME type of the file being uploaded. */
|
|
22
|
+
fileType: string | null;
|
|
23
|
+
/**
|
|
24
|
+
* Image thumbnail object URL, or `null`.
|
|
25
|
+
* Kept through success; revoked when state returns to idle.
|
|
26
|
+
*/
|
|
27
|
+
previewUrl: string | null;
|
|
28
|
+
};
|
|
29
|
+
export type UseFileUploadReturn = UseFileUploadState & {
|
|
30
|
+
/**
|
|
31
|
+
* Start an upload.
|
|
32
|
+
*
|
|
33
|
+
* Safe to call again after `success`, `error`, or `cancel` — state is reset
|
|
34
|
+
* automatically before the new upload begins.
|
|
35
|
+
*
|
|
36
|
+
* If `uploadStore` is configured and a previous upload for the same
|
|
37
|
+
* `objectKey` was interrupted (e.g. via `detach()`), the engine will find
|
|
38
|
+
* the stored `uploadId`, call `listParts`, and resume from the last completed
|
|
39
|
+
* part rather than starting a new multipart upload.
|
|
40
|
+
*/
|
|
41
|
+
upload: (file: File, objectKey: string, requestOptions?: UploadRequestOptions) => Promise<void>;
|
|
42
|
+
/**
|
|
43
|
+
* Abort the upload and fully clean up all resources.
|
|
44
|
+
*
|
|
45
|
+
* - Stops the in-flight network request immediately.
|
|
46
|
+
* - For multipart uploads: calls `AbortMultipartUpload` on S3 so incomplete
|
|
47
|
+
* parts are freed right away (instead of waiting for the bucket lifecycle
|
|
48
|
+
* policy to expire them).
|
|
49
|
+
* - Removes the `uploadStore` entry if one was provided.
|
|
50
|
+
* - Resets state to `idle`.
|
|
51
|
+
*
|
|
52
|
+
* Use this for a "Cancel" button that the user explicitly clicks to abandon
|
|
53
|
+
* the upload entirely.
|
|
54
|
+
*/
|
|
55
|
+
cancel: () => void;
|
|
56
|
+
/**
|
|
57
|
+
* Soft-stop: preserves S3 parts and store entry so a future `upload()` can
|
|
58
|
+
* resume. For non-resumable uploads, identical to `cancel()`.
|
|
59
|
+
* See `UseFileUploadReturn.detach` for full semantics.
|
|
60
|
+
*/
|
|
61
|
+
detach: () => void;
|
|
62
|
+
/**
|
|
63
|
+
* Reset UI state to `idle` without touching any S3 or store resources.
|
|
64
|
+
*
|
|
65
|
+
* - Stops the in-flight network request if one is active.
|
|
66
|
+
* - Does **not** call `AbortMultipartUpload`.
|
|
67
|
+
* - Does **not** modify `uploadStore`.
|
|
68
|
+
* - Does **not** fire `onCancel`.
|
|
69
|
+
*
|
|
70
|
+
* Use this to clear an error or success state from the UI, or when you
|
|
71
|
+
* handle cleanup yourself outside this hook.
|
|
72
|
+
*/
|
|
73
|
+
reset: () => void;
|
|
74
|
+
};
|
|
75
|
+
export declare function useFileUpload(options: UseFileUploadOptions): UseFileUploadReturn;
|
|
76
|
+
//# sourceMappingURL=use-file-upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-file-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-file-upload.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAiB5C,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,WAAW,EACX,cAAc,EACd,YAAY,EACZ,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAGlB,yCAAyC;AACzC,MAAM,MAAM,oBAAoB,GAAG,YAAY,GAC7C,WAAW,GAAG;IACZ,qEAAqE;IACrE,GAAG,CAAC,EAAE,KAAK,CAAC;CACb,CAAC;AAEJ,MAAM,MAAM,kBAAkB,GAAG;IAC/B,4BAA4B;IAC5B,KAAK,EAAE,WAAW,CAAC;IACnB,8BAA8B;IAC9B,QAAQ,EAAE,cAAc,CAAC;IACzB,gCAAgC;IAChC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,uCAAuC;IACvC,MAAM,EAAE,YAAY,GAAG,IAAI,CAAC;IAC5B,uCAAuC;IACvC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,gDAAgD;IAChD,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,4CAA4C;IAC5C,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;;OAGG;IACH,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG,kBAAkB,GAAG;IACrD;;;;;;;;;;OAUG;IACH,MAAM,EAAE,CACN,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,MAAM,EACjB,cAAc,CAAC,EAAE,oBAAoB,KAClC,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB;;;;;;;;;;;;OAYG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB;;;;OAIG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB;;;;;;;;;;OAUG;IACH,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAyBF,wBAAgB,aAAa,CAC3B,OAAO,EAAE,oBAAoB,GAC5B,mBAAmB,CA+NrB"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { S3Api } from "@dimah-s3/core";
|
|
2
|
+
import type { UploadConfig, UploadProgress, UploadRequestOptions, MultiUploadPhase, MultiUploadFileState, MultiUploadHooks } from "../types";
|
|
3
|
+
/** Options for {@link useMultiFileUpload}. */
|
|
4
|
+
export type UseMultiFileUploadOptions = UploadConfig & MultiUploadHooks & {
|
|
5
|
+
/** S3Api. Optional when an `<S3Provider>` is present in the tree. */
|
|
6
|
+
api?: S3Api;
|
|
7
|
+
/** Static request options applied to all files. */
|
|
8
|
+
uploadOptions?: UploadRequestOptions;
|
|
9
|
+
/** Per-file request options (overrides `uploadOptions`). */
|
|
10
|
+
getUploadOptions?: (file: File) => UploadRequestOptions;
|
|
11
|
+
};
|
|
12
|
+
export type UseMultiFileUploadState = {
|
|
13
|
+
/** Current batch upload phase. */
|
|
14
|
+
phase: MultiUploadPhase;
|
|
15
|
+
/** Per-file upload states. */
|
|
16
|
+
files: MultiUploadFileState[];
|
|
17
|
+
/** Aggregated progress across all files. */
|
|
18
|
+
totalProgress: UploadProgress;
|
|
19
|
+
/** Batch-level error message, or `null`. */
|
|
20
|
+
error: string | null;
|
|
21
|
+
};
|
|
22
|
+
export type UseMultiFileUploadReturn = UseMultiFileUploadState & {
|
|
23
|
+
/** Upload multiple files. */
|
|
24
|
+
upload: (files: File[], resolveKey: (file: File) => string) => Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Abort all in-flight uploads and clean up multipart / store resources
|
|
27
|
+
* (same semantics as {@link useFileUpload}'s `cancel`).
|
|
28
|
+
*/
|
|
29
|
+
cancel: () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Stop uploads but preserve multipart store entries for resume
|
|
32
|
+
* (same semantics as {@link useFileUpload}'s `detach`).
|
|
33
|
+
*/
|
|
34
|
+
detach: () => void;
|
|
35
|
+
/** Reset state to `idle`. */
|
|
36
|
+
reset: () => void;
|
|
37
|
+
};
|
|
38
|
+
export declare function useMultiFileUpload(options: UseMultiFileUploadOptions): UseMultiFileUploadReturn;
|
|
39
|
+
//# sourceMappingURL=use-multi-file-upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
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;AAiB5C,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAGlB,8CAA8C;AAC9C,MAAM,MAAM,yBAAyB,GAAG,YAAY,GAClD,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,4CAA4C;IAC5C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG,uBAAuB,GAAG;IAC/D,6BAA6B;IAC7B,MAAM,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAC7E;;;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;AAsBF,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,yBAAyB,GACjC,wBAAwB,CA4U1B"}
|
|
@@ -1,15 +1,31 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
1
|
+
import type { UploadProgress, MultiUploadFileState, MultiUploadPhase } from "../types";
|
|
2
|
+
import { type UseMultiFileUploadOptions } from "./use-multi-file-upload";
|
|
3
|
+
import { type DropzoneInputProps, type DropzoneRootProps, type FileRejection } from "./use-file-intake";
|
|
3
4
|
/** Options for {@link useMultiUpload}. */
|
|
4
|
-
export type UseMultiUploadOptions =
|
|
5
|
-
/**
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
|
|
5
|
+
export type UseMultiUploadOptions = UseMultiFileUploadOptions & {
|
|
6
|
+
/** S3 object key, or a function that derives it from each file. */
|
|
7
|
+
objectKey: string | ((file: File) => string);
|
|
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;
|
|
11
27
|
};
|
|
12
|
-
export type
|
|
28
|
+
export type UseMultiUploadReturn = {
|
|
13
29
|
/** Current batch upload phase. */
|
|
14
30
|
phase: MultiUploadPhase;
|
|
15
31
|
/** Per-file upload states. */
|
|
@@ -18,22 +34,28 @@ export type UseMultiUploadState = {
|
|
|
18
34
|
totalProgress: UploadProgress;
|
|
19
35
|
/** Batch-level error message, or `null`. */
|
|
20
36
|
error: string | null;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
*/
|
|
37
|
+
/** `true` while uploading. */
|
|
38
|
+
isUploading: boolean;
|
|
39
|
+
/** Handle files programmatically (bypasses dropzone). */
|
|
40
|
+
handleFiles: (files: FileList | File[] | null) => void;
|
|
41
|
+
/** Open the native file picker. */
|
|
42
|
+
open: () => void;
|
|
43
|
+
/** Abort all in-flight uploads. */
|
|
29
44
|
cancel: () => void;
|
|
30
|
-
/**
|
|
31
|
-
* Stop uploads but preserve multipart store entries for resume
|
|
32
|
-
* (same semantics as {@link useUpload}'s `detach`).
|
|
33
|
-
*/
|
|
45
|
+
/** Preserve multipart store entries for resume. */
|
|
34
46
|
detach: () => void;
|
|
35
47
|
/** Reset state to `idle`. */
|
|
36
48
|
reset: () => void;
|
|
49
|
+
/** Spread on the dropzone / clickable root element. */
|
|
50
|
+
getRootProps: <T extends DropzoneRootProps>(props?: T) => T;
|
|
51
|
+
/** Spread on a hidden `<input type="file">`. */
|
|
52
|
+
getInputProps: <T extends DropzoneInputProps>(props?: T) => T;
|
|
53
|
+
/** `true` while a drag is over the root. */
|
|
54
|
+
isDragActive: boolean;
|
|
55
|
+
isDragAccept: boolean;
|
|
56
|
+
isDragReject: boolean;
|
|
57
|
+
/** Soft rejections from the last drop / selection. */
|
|
58
|
+
fileRejections: readonly FileRejection[];
|
|
37
59
|
};
|
|
38
60
|
export declare function useMultiUpload(options: UseMultiUploadOptions): UseMultiUploadReturn;
|
|
39
61
|
//# sourceMappingURL=use-multi-upload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-multi-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-multi-upload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-multi-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-multi-upload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAEL,KAAK,yBAAyB,EAC/B,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,mBAAmB,CAAC;AAE3B,0CAA0C;AAC1C,MAAM,MAAM,qBAAqB,GAAG,yBAAyB,GAAG;IAC9D,mEAAmE;IACnE,SAAS,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC;IAC7C,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,4CAA4C;IAC5C,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,8BAA8B;IAC9B,WAAW,EAAE,OAAO,CAAC;IACrB,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,CAwDtB"}
|
|
@@ -1,83 +1,67 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import
|
|
1
|
+
import type { UploadFileInfo, UploadPhase, UploadProgress, UploadRequestOptions } from "../types";
|
|
2
|
+
import { type UseFileUploadOptions } from "./use-file-upload";
|
|
3
|
+
import { type DropzoneInputProps, type DropzoneRootProps, type FileRejection } from "./use-file-intake";
|
|
3
4
|
/** Options for {@link useUpload}. */
|
|
4
|
-
export type UseUploadOptions =
|
|
5
|
-
/**
|
|
6
|
-
|
|
5
|
+
export type UseUploadOptions = UseFileUploadOptions & {
|
|
6
|
+
/** S3 object key, or a function that derives it from the file. */
|
|
7
|
+
objectKey: string | ((file: File) => string);
|
|
8
|
+
/** Static request options applied to the upload. */
|
|
9
|
+
uploadOptions?: UploadRequestOptions;
|
|
10
|
+
/** Per-upload request options override. */
|
|
11
|
+
getUploadOptions?: (file: File) => UploadRequestOptions;
|
|
12
|
+
/** Disable all intake interactions. */
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Disable drag interactions on the root (button-style UIs).
|
|
16
|
+
* @default false
|
|
17
|
+
*/
|
|
18
|
+
noDrag?: boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Disable click-to-open on the root (when opening via `open()` on a button).
|
|
21
|
+
* @default false
|
|
22
|
+
*/
|
|
23
|
+
noClick?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Disable keyboard activation on the root.
|
|
26
|
+
* @default false
|
|
27
|
+
*/
|
|
28
|
+
noKeyboard?: boolean;
|
|
29
|
+
/** Called when dropzone soft-rejects files (type/size). */
|
|
30
|
+
onFileReject?: (rejections: readonly FileRejection[]) => void;
|
|
7
31
|
};
|
|
8
|
-
export type
|
|
32
|
+
export type UseUploadReturn = {
|
|
9
33
|
/** Current upload phase. */
|
|
10
34
|
phase: UploadPhase;
|
|
35
|
+
/** Info about the selected file. */
|
|
36
|
+
fileInfo: UploadFileInfo | null;
|
|
11
37
|
/** Byte transfer progress. */
|
|
12
38
|
progress: UploadProgress;
|
|
13
39
|
/** Error message, or `null`. */
|
|
14
40
|
error: string | null;
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export type UseUploadReturn = UseUploadState & {
|
|
23
|
-
/**
|
|
24
|
-
* Start an upload.
|
|
25
|
-
*
|
|
26
|
-
* Safe to call again after `success`, `error`, or `cancel` — state is reset
|
|
27
|
-
* automatically before the new upload begins.
|
|
28
|
-
*
|
|
29
|
-
* If `uploadStore` is configured and a previous upload for the same
|
|
30
|
-
* `objectKey` was interrupted (e.g. via `detach()`), the engine will find
|
|
31
|
-
* the stored `uploadId`, call `listParts`, and resume from the last completed
|
|
32
|
-
* part rather than starting a new multipart upload.
|
|
33
|
-
*/
|
|
34
|
-
upload: (file: File, objectKey: string, requestOptions?: UploadRequestOptions) => Promise<void>;
|
|
35
|
-
/**
|
|
36
|
-
* Abort the upload and fully clean up all resources.
|
|
37
|
-
*
|
|
38
|
-
* - Stops the in-flight network request immediately.
|
|
39
|
-
* - For multipart uploads: calls `AbortMultipartUpload` on S3 so incomplete
|
|
40
|
-
* parts are freed right away (instead of waiting for the bucket lifecycle
|
|
41
|
-
* policy to expire them).
|
|
42
|
-
* - Removes the `uploadStore` entry if one was provided.
|
|
43
|
-
* - Resets state to `idle`.
|
|
44
|
-
*
|
|
45
|
-
* Use this for a "Cancel" button that the user explicitly clicks to abandon
|
|
46
|
-
* the upload entirely.
|
|
47
|
-
*/
|
|
41
|
+
/** `true` while uploading. */
|
|
42
|
+
isUploading: boolean;
|
|
43
|
+
/** Handle files programmatically (bypasses dropzone). */
|
|
44
|
+
handleFiles: (files: FileList | File[] | null) => void;
|
|
45
|
+
/** Open the native file picker. */
|
|
46
|
+
open: () => void;
|
|
47
|
+
/** Abort and reset to idle. */
|
|
48
48
|
cancel: () => void;
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
* Compared to `cancel()`:
|
|
54
|
-
* - Does **not** call `AbortMultipartUpload` (parts stay on S3).
|
|
55
|
-
* - Does **not** remove the `uploadStore` entry.
|
|
56
|
-
* - Does **not** fire the `onCancel` callback.
|
|
57
|
-
*
|
|
58
|
-
* The next call to `upload(sameFile, sameKey)` will detect the stored
|
|
59
|
-
* `uploadId`, verify the existing parts via `listParts`, and continue
|
|
60
|
-
* uploading from where it stopped.
|
|
61
|
-
*
|
|
62
|
-
* For **simple uploads** or multipart **without** `uploadStore`, this is
|
|
63
|
-
* identical to `cancel()` — there is no S3 state worth preserving.
|
|
64
|
-
*
|
|
65
|
-
* Intended for custom UIs that want to offer a "save for later / resume"
|
|
66
|
-
* workflow.
|
|
50
|
+
* Soft-stop: preserves S3 parts and store entry so a future `upload()` can
|
|
51
|
+
* resume. For non-resumable uploads, identical to `cancel()`.
|
|
67
52
|
*/
|
|
68
53
|
detach: () => void;
|
|
69
|
-
/**
|
|
70
|
-
* Reset UI state to `idle` without touching any S3 or store resources.
|
|
71
|
-
*
|
|
72
|
-
* - Stops the in-flight network request if one is active.
|
|
73
|
-
* - Does **not** call `AbortMultipartUpload`.
|
|
74
|
-
* - Does **not** modify `uploadStore`.
|
|
75
|
-
* - Does **not** fire `onCancel`.
|
|
76
|
-
*
|
|
77
|
-
* Use this to clear an error or success state from the UI, or when you
|
|
78
|
-
* handle cleanup yourself outside this hook.
|
|
79
|
-
*/
|
|
80
54
|
reset: () => void;
|
|
55
|
+
/** Spread on the dropzone / clickable root element. */
|
|
56
|
+
getRootProps: <T extends DropzoneRootProps>(props?: T) => T;
|
|
57
|
+
/** Spread on a hidden `<input type="file">`. */
|
|
58
|
+
getInputProps: <T extends DropzoneInputProps>(props?: T) => T;
|
|
59
|
+
/** `true` while a drag is over the root. */
|
|
60
|
+
isDragActive: boolean;
|
|
61
|
+
isDragAccept: boolean;
|
|
62
|
+
isDragReject: boolean;
|
|
63
|
+
/** Soft rejections from the last drop / selection. */
|
|
64
|
+
fileRejections: readonly FileRejection[];
|
|
81
65
|
};
|
|
82
66
|
export declare function useUpload(options: UseUploadOptions): UseUploadReturn;
|
|
83
67
|
//# sourceMappingURL=use-upload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,cAAc,EACd,WAAW,EACX,cAAc,EACd,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAiB,KAAK,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,mBAAmB,CAAC;AAE3B,qCAAqC;AACrC,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG;IACpD,kEAAkE;IAClE,SAAS,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC;IAC7C,oDAAoD;IACpD,aAAa,CAAC,EAAE,oBAAoB,CAAC;IACrC,2CAA2C;IAC3C,gBAAgB,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,oBAAoB,CAAC;IACxD,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,2DAA2D;IAC3D,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,SAAS,aAAa,EAAE,KAAK,IAAI,CAAC;CAC/D,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,4BAA4B;IAC5B,KAAK,EAAE,WAAW,CAAC;IACnB,oCAAoC;IACpC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAC;IAChC,8BAA8B;IAC9B,QAAQ,EAAE,cAAc,CAAC;IACzB,gCAAgC;IAChC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,8BAA8B;IAC9B,WAAW,EAAE,OAAO,CAAC;IACrB,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,+BAA+B;IAC/B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB;;;OAGG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,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,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,eAAe,CAuEpE"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,11 +6,12 @@ export { S3Provider, useApi, S3Context, type S3ProviderProps, } from "./s3-provi
|
|
|
6
6
|
export type { Translations } from "./translations";
|
|
7
7
|
export { createLocalStorageStore, createMemoryStore } from "./store";
|
|
8
8
|
export { uploadFile, uploadFiles, type UploadEngineCallbacks, type FileItem, type FileItemStatus, type MultiUploadCallbacks, } from "./upload";
|
|
9
|
-
export { formatAcceptLabels, formatUploadProgress, formatSpeed, formatEta, useFormatDimahError, useFormatValidateFileError, createSpeedTracker, type SpeedTracker, } from "./helpers";
|
|
10
|
-
export {
|
|
11
|
-
export {
|
|
12
|
-
export {
|
|
13
|
-
export {
|
|
9
|
+
export { formatAcceptLabels, formatUploadProgress, formatSpeed, formatEta, useFormatDimahError, useFormatValidateFileError, createSpeedTracker, createImagePreviewUrl, revokePreviewUrl, toDropzoneAccept, type SpeedTracker, } from "./helpers";
|
|
10
|
+
export { useFileUpload, type UseFileUploadOptions, type UseFileUploadState, type UseFileUploadReturn, } from "./hooks/use-file-upload";
|
|
11
|
+
export { useMultiFileUpload, type UseMultiFileUploadOptions, type UseMultiFileUploadState, type UseMultiFileUploadReturn, } from "./hooks/use-multi-file-upload";
|
|
12
|
+
export { useUpload, type UseUploadOptions, type UseUploadReturn, } from "./hooks/use-upload";
|
|
13
|
+
export { useMultiUpload, type UseMultiUploadOptions, type UseMultiUploadReturn, } from "./hooks/use-multi-upload";
|
|
14
|
+
export { useFileIntake, type UseFileIntakeOptions, type UseFileIntakeReturn, type FileRejection, type DropzoneRootProps, type DropzoneInputProps, } from "./hooks/use-file-intake";
|
|
14
15
|
export { useDownload, type DownloadPhase, type DownloadHooks, type UseDownloadOptions, type UseDownloadState, type UseDownloadReturn, } from "./hooks/use-download";
|
|
15
16
|
export { useFetchDownload, type FetchDownloadPhase, type FetchDownloadProgress, type FetchDownloadHooks, type UseFetchDownloadOptions, type UseFetchDownloadState, type UseFetchDownloadReturn, } from "./hooks/use-fetch-download";
|
|
16
17
|
export { useDelete, type UseDeleteOptions, type UseDeleteState, type UseDeleteReturn, } from "./hooks/use-delete";
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EACL,UAAU,EACV,MAAM,EACN,SAAS,EACT,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AAGvB,sEAAsE;AACtE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGrE,OAAO,EACL,UAAU,EACV,WAAW,EACX,KAAK,qBAAqB,EAC1B,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,SAAS,EACT,mBAAmB,EACnB,0BAA0B,EAC1B,kBAAkB,EAClB,KAAK,YAAY,GAClB,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,SAAS,CAAC;AAGxB,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAChF,OAAO,EACL,UAAU,EACV,MAAM,EACN,SAAS,EACT,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AAGvB,sEAAsE;AACtE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAGnD,OAAO,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAGrE,OAAO,EACL,UAAU,EACV,WAAW,EACX,KAAK,qBAAqB,EAC1B,KAAK,QAAQ,EACb,KAAK,cAAc,EACnB,KAAK,oBAAoB,GAC1B,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,WAAW,EACX,SAAS,EACT,mBAAmB,EACnB,0BAA0B,EAC1B,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,YAAY,GAClB,MAAM,WAAW,CAAC;AAGnB,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,GACzB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,kBAAkB,EAClB,KAAK,yBAAyB,EAC9B,KAAK,uBAAuB,EAC5B,KAAK,wBAAwB,GAC9B,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACL,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,oBAAoB,GAC1B,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,aAAa,EACb,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,iBAAiB,EACtB,KAAK,kBAAkB,GACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,WAAW,EACX,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,GACvB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EACL,gBAAgB,EAChB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,GAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,oBAAoB,CAAC"}
|