@dimah-s3/react 0.1.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/LICENSE +21 -0
- package/README.md +31 -0
- package/dist/api.d.ts +29 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/create-s3-client.d.ts +34 -0
- package/dist/create-s3-client.d.ts.map +1 -0
- package/dist/helpers/format-accept-labels.d.ts +3 -0
- package/dist/helpers/format-accept-labels.d.ts.map +1 -0
- package/dist/helpers/format-dimah-error.d.ts +8 -0
- package/dist/helpers/format-dimah-error.d.ts.map +1 -0
- package/dist/helpers/format-dimah-error.test.d.ts +2 -0
- package/dist/helpers/format-dimah-error.test.d.ts.map +1 -0
- package/dist/helpers/format-eta.d.ts +13 -0
- package/dist/helpers/format-eta.d.ts.map +1 -0
- package/dist/helpers/format-speed.d.ts +9 -0
- package/dist/helpers/format-speed.d.ts.map +1 -0
- package/dist/helpers/format-upload-progress.d.ts +18 -0
- package/dist/helpers/format-upload-progress.d.ts.map +1 -0
- package/dist/helpers/format-validate-file-error.d.ts +9 -0
- package/dist/helpers/format-validate-file-error.d.ts.map +1 -0
- package/dist/helpers/helpers.test.d.ts +2 -0
- package/dist/helpers/helpers.test.d.ts.map +1 -0
- package/dist/helpers/index.d.ts +9 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/speed-tracker.d.ts +18 -0
- package/dist/helpers/speed-tracker.d.ts.map +1 -0
- package/dist/helpers/throttled-speed.d.ts +8 -0
- package/dist/helpers/throttled-speed.d.ts.map +1 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/use-delete.d.ts +29 -0
- package/dist/hooks/use-delete.d.ts.map +1 -0
- package/dist/hooks/use-download.d.ts +33 -0
- package/dist/hooks/use-download.d.ts.map +1 -0
- package/dist/hooks/use-fetch-download.d.ts +33 -0
- package/dist/hooks/use-fetch-download.d.ts.map +1 -0
- package/dist/hooks/use-multi-upload-controls.d.ts +45 -0
- package/dist/hooks/use-multi-upload-controls.d.ts.map +1 -0
- package/dist/hooks/use-multi-upload.d.ts +39 -0
- package/dist/hooks/use-multi-upload.d.ts.map +1 -0
- package/dist/hooks/use-upload-controls.d.ts +54 -0
- package/dist/hooks/use-upload-controls.d.ts.map +1 -0
- package/dist/hooks/use-upload.d.ts +83 -0
- package/dist/hooks/use-upload.d.ts.map +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1558 -0
- package/dist/index.js.map +1 -0
- package/dist/internal-helpers.d.ts +10 -0
- package/dist/internal-helpers.d.ts.map +1 -0
- package/dist/s3-provider.d.ts +50 -0
- package/dist/s3-provider.d.ts.map +1 -0
- package/dist/store/index.d.ts +4 -0
- package/dist/store/index.d.ts.map +1 -0
- package/dist/store/local-storage-store.d.ts +10 -0
- package/dist/store/local-storage-store.d.ts.map +1 -0
- package/dist/store/memory-store.d.ts +15 -0
- package/dist/store/memory-store.d.ts.map +1 -0
- package/dist/translations/index.d.ts +2 -0
- package/dist/translations/index.d.ts.map +1 -0
- package/dist/translations/types.d.ts +61 -0
- package/dist/translations/types.d.ts.map +1 -0
- package/dist/types/delete.d.ts +11 -0
- package/dist/types/delete.d.ts.map +1 -0
- package/dist/types/download.d.ts +26 -0
- package/dist/types/download.d.ts.map +1 -0
- package/dist/types/error.d.ts +24 -0
- package/dist/types/error.d.ts.map +1 -0
- package/dist/types/index.d.ts +7 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/multi-upload.d.ts +27 -0
- package/dist/types/multi-upload.d.ts.map +1 -0
- package/dist/types/upload-store.d.ts +55 -0
- package/dist/types/upload-store.d.ts.map +1 -0
- package/dist/types/upload.d.ts +102 -0
- package/dist/types/upload.d.ts.map +1 -0
- package/dist/upload/constants.d.ts +7 -0
- package/dist/upload/constants.d.ts.map +1 -0
- package/dist/upload/index.d.ts +3 -0
- package/dist/upload/index.d.ts.map +1 -0
- package/dist/upload/multipart.d.ts +5 -0
- package/dist/upload/multipart.d.ts.map +1 -0
- package/dist/upload/presigned-http.d.ts +17 -0
- package/dist/upload/presigned-http.d.ts.map +1 -0
- package/dist/upload/retry.d.ts +3 -0
- package/dist/upload/retry.d.ts.map +1 -0
- package/dist/upload/upload-file.d.ts +13 -0
- package/dist/upload/upload-file.d.ts.map +1 -0
- package/dist/upload/upload-files.d.ts +26 -0
- package/dist/upload/upload-files.d.ts.map +1 -0
- package/dist/upload/upload-part.d.ts +4 -0
- package/dist/upload/upload-part.d.ts.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hamidreza
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# @dimah-s3/react
|
|
2
|
+
|
|
3
|
+
Headless React hooks for S3 upload, download, and delete flows.
|
|
4
|
+
|
|
5
|
+
Full documentation: [dimah-s3-docs.vercel.app](https://dimah-s3-docs.vercel.app/docs/react)
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add @dimah-s3/react
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Minimal setup
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { createS3Client, useUploadControls } from "@dimah-s3/react";
|
|
17
|
+
|
|
18
|
+
export const { api, S3Provider, useApi } = createS3Client();
|
|
19
|
+
|
|
20
|
+
// App root
|
|
21
|
+
<S3Provider>{children}</S3Provider>;
|
|
22
|
+
|
|
23
|
+
// In a component
|
|
24
|
+
const { openFilePicker, inputProps } = useUploadControls({
|
|
25
|
+
objectKey: (file) => `uploads/${file.name}`,
|
|
26
|
+
});
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## License
|
|
30
|
+
|
|
31
|
+
MIT
|
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type helper for a custom dimah-s3 presign API.
|
|
3
|
+
*
|
|
4
|
+
* Accepts an `S3Api` object — implement each method to call your own backend
|
|
5
|
+
* endpoint, tRPC mutation, GraphQL query, or anything else. The object is
|
|
6
|
+
* returned as-is; `defineApi` just enforces the type contract.
|
|
7
|
+
*
|
|
8
|
+
* If you are using the default dimah-s3 route layout, use `createS3Client`
|
|
9
|
+
* from `@dimah-s3/react` (or `@dimah-s3/core` without React bindings).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { defineApi } from "@dimah-s3/react";
|
|
14
|
+
*
|
|
15
|
+
* export const api = defineApi({
|
|
16
|
+
* async upload(payload) {
|
|
17
|
+
* return fetch("/api/storage/presign", { method: "POST", body: JSON.stringify(payload) })
|
|
18
|
+
* .then(r => r.json());
|
|
19
|
+
* },
|
|
20
|
+
* async confirm(payload) { ... },
|
|
21
|
+
* async download(key, options) { ... },
|
|
22
|
+
* async delete(key) { ... },
|
|
23
|
+
* multipart: { init, signPart, listParts, complete, abort },
|
|
24
|
+
* });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
import type { S3Api } from "@dimah-s3/core";
|
|
28
|
+
export declare function defineApi(input: S3Api): S3Api;
|
|
29
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAE5C,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAE7C"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type CreateS3ClientOptions, type S3Api, type S3ClientPlugin, type ClientPluginMethodsMap } from "@dimah-s3/core";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { type S3ProviderProps } from "./s3-provider";
|
|
4
|
+
type BoundProviderProps = Omit<S3ProviderProps, "api"> & {
|
|
5
|
+
children: ReactNode;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Create a typed S3 browser client — Better Auth–style one-shot setup.
|
|
9
|
+
*
|
|
10
|
+
* Returns the `api` singleton plus a bound `S3Provider` / `useApi` so plugin
|
|
11
|
+
* methods stay typed without generics on every call.
|
|
12
|
+
*
|
|
13
|
+
* ```ts
|
|
14
|
+
* import { createS3Client } from "@dimah-s3/react";
|
|
15
|
+
* import { dbClient } from "@dimah-s3/db/client";
|
|
16
|
+
*
|
|
17
|
+
* export const { api, S3Provider, useApi } = createS3Client({
|
|
18
|
+
* basePath: "/api/s3",
|
|
19
|
+
* plugins: [dbClient()],
|
|
20
|
+
* });
|
|
21
|
+
*
|
|
22
|
+
* await api.db.listObjects();
|
|
23
|
+
*
|
|
24
|
+
* const api = useApi(); // includes .db
|
|
25
|
+
* <S3Provider>{children}</S3Provider>
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function createS3Client<const P extends readonly S3ClientPlugin[] = []>(options?: CreateS3ClientOptions<P>): {
|
|
29
|
+
api: S3Api & ClientPluginMethodsMap<P>;
|
|
30
|
+
S3Provider: (props: BoundProviderProps) => import("react").JSX.Element;
|
|
31
|
+
useApi: () => S3Api & ClientPluginMethodsMap<P>;
|
|
32
|
+
};
|
|
33
|
+
export type { CreateS3ClientOptions };
|
|
34
|
+
//# sourceMappingURL=create-s3-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-s3-client.d.ts","sourceRoot":"","sources":["../src/create-s3-client.tsx"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,qBAAqB,EAC1B,KAAK,KAAK,EACV,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC5B,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,EAGL,KAAK,eAAe,EACrB,MAAM,eAAe,CAAC;AAEvB,KAAK,kBAAkB,GAAG,IAAI,CAAC,eAAe,EAAE,KAAK,CAAC,GAAG;IACvD,QAAQ,EAAE,SAAS,CAAC;CACrB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,cAAc,CAAC,KAAK,CAAC,CAAC,SAAS,SAAS,cAAc,EAAE,GAAG,EAAE,EAC3E,OAAO,CAAC,EAAE,qBAAqB,CAAC,CAAC,CAAC;;wBAMP,kBAAkB;;EAS9C;AAED,YAAY,EAAE,qBAAqB,EAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-accept-labels.d.ts","sourceRoot":"","sources":["../../src/helpers/format-accept-labels.ts"],"names":[],"mappings":"AAaA,4FAA4F;AAC5F,wBAAgB,kBAAkB,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAe9D"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localized {@link DimahS3Error} → string.
|
|
3
|
+
*
|
|
4
|
+
* `t("…")` call sites are nested under `useTranslations()` so fuma-translate
|
|
5
|
+
* can extract keys (it cannot see `t` passed into a plain helper).
|
|
6
|
+
*/
|
|
7
|
+
export declare function useFormatDimahError(): (err: unknown) => string;
|
|
8
|
+
//# sourceMappingURL=format-dimah-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-dimah-error.d.ts","sourceRoot":"","sources":["../../src/helpers/format-dimah-error.tsx"],"names":[],"mappings":"AAeA;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,CAAC,GAAG,EAAE,OAAO,KAAK,MAAM,CAsD9D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-dimah-error.test.d.ts","sourceRoot":"","sources":["../../src/helpers/format-dimah-error.test.tsx"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats an estimated remaining time given the remaining bytes and current speed.
|
|
3
|
+
*
|
|
4
|
+
* Returns `null` when speed is 0 or nothing remains (not yet calculable).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* formatEta(4_400_000, 450_000) // → "9s"
|
|
8
|
+
* formatEta(4_400_000, 75_000) // → "58s"
|
|
9
|
+
* formatEta(90_000_000, 1_500_000) // → "1m"
|
|
10
|
+
* formatEta(5_400_000_000, 500_000) // → "3h"
|
|
11
|
+
*/
|
|
12
|
+
export declare function formatEta(remainingBytes: number, bytesPerSecond: number): string | null;
|
|
13
|
+
//# sourceMappingURL=format-eta.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-eta.d.ts","sourceRoot":"","sources":["../../src/helpers/format-eta.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CACvB,cAAc,EAAE,MAAM,EACtB,cAAc,EAAE,MAAM,GACrB,MAAM,GAAG,IAAI,CAYf"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats a transfer speed (bytes/second) as a human-readable string.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* formatSpeed(1_200_000) // → "1.2 MB/s"
|
|
6
|
+
* formatSpeed(512) // → "512 B/s"
|
|
7
|
+
*/
|
|
8
|
+
export declare function formatSpeed(bytesPerSecond: number): string;
|
|
9
|
+
//# sourceMappingURL=format-speed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-speed.d.ts","sourceRoot":"","sources":["../../src/helpers/format-speed.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,cAAc,EAAE,MAAM,GAAG,MAAM,CAE1D"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Formats upload progress as a human-readable transfer string.
|
|
3
|
+
*
|
|
4
|
+
* @param loaded Bytes transferred so far.
|
|
5
|
+
* @param total Total bytes to transfer (0 means unknown).
|
|
6
|
+
* @param percent Transfer percentage (0–100).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```ts
|
|
10
|
+
* formatUploadProgress(1_200_000, 5_600_000, 21)
|
|
11
|
+
* // → "1.2 MB / 5.6 MB (21%)"
|
|
12
|
+
*
|
|
13
|
+
* formatUploadProgress(1_200_000, 0, 0)
|
|
14
|
+
* // → "1.2 MB"
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
export declare function formatUploadProgress(loaded: number, total: number, percent: number): string;
|
|
18
|
+
//# sourceMappingURL=format-upload-progress.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-upload-progress.d.ts","sourceRoot":"","sources":["../../src/helpers/format-upload-progress.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,MAAM,GACd,MAAM,CAIR"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ValidateFileError } from "@dimah-s3/core";
|
|
2
|
+
/**
|
|
3
|
+
* Localized {@link ValidateFileError} → string.
|
|
4
|
+
*
|
|
5
|
+
* `t("…")` call sites are nested under `useTranslations()` so fuma-translate
|
|
6
|
+
* can extract keys.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useFormatValidateFileError(): (error: ValidateFileError) => string;
|
|
9
|
+
//# sourceMappingURL=format-validate-file-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format-validate-file-error.d.ts","sourceRoot":"","sources":["../../src/helpers/format-validate-file-error.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGxD;;;;;GAKG;AACH,wBAAgB,0BAA0B,IAAI,CAC5C,KAAK,EAAE,iBAAiB,KACrB,MAAM,CAwBV"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.test.d.ts","sourceRoot":"","sources":["../../src/helpers/helpers.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { formatAcceptLabels } from "./format-accept-labels";
|
|
2
|
+
export { formatUploadProgress } from "./format-upload-progress";
|
|
3
|
+
export { formatSpeed } from "./format-speed";
|
|
4
|
+
export { formatEta } from "./format-eta";
|
|
5
|
+
export { useFormatValidateFileError } from "./format-validate-file-error";
|
|
6
|
+
export { useFormatDimahError } from "./format-dimah-error";
|
|
7
|
+
export { createSpeedTracker, type SpeedTracker } from "./speed-tracker";
|
|
8
|
+
export { createThrottledSpeedUpdater } from "./throttled-speed";
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a sliding-window transfer speed calculator.
|
|
3
|
+
*
|
|
4
|
+
* Tracks bytes transferred over a rolling time window to produce a smooth,
|
|
5
|
+
* instantaneous speed reading in bytes/second.
|
|
6
|
+
*
|
|
7
|
+
* @param windowMs Rolling window duration in milliseconds. @default 3000
|
|
8
|
+
*/
|
|
9
|
+
export declare function createSpeedTracker(windowMs?: number): {
|
|
10
|
+
/**
|
|
11
|
+
* Record the latest cumulative `loaded` byte count.
|
|
12
|
+
* Returns the current speed in bytes/second (0 until at least 2 samples exist).
|
|
13
|
+
*/
|
|
14
|
+
update(loaded: number): number;
|
|
15
|
+
reset(): void;
|
|
16
|
+
};
|
|
17
|
+
export type SpeedTracker = ReturnType<typeof createSpeedTracker>;
|
|
18
|
+
//# sourceMappingURL=speed-tracker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"speed-tracker.d.ts","sourceRoot":"","sources":["../../src/helpers/speed-tracker.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,SAAO;IAI9C;;;OAGG;IACH,MAAM,SAAS,MAAM,GAAG,MAAM;IAoB9B,KAAK;EAIR;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,kBAAkB,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { UploadProgress } from "../types";
|
|
2
|
+
import type { SpeedTracker } from "./speed-tracker";
|
|
3
|
+
/** Throttle speed samples so UI updates stay readable. */
|
|
4
|
+
export declare function createThrottledSpeedUpdater(tracker: SpeedTracker, intervalMs?: number): {
|
|
5
|
+
reset(): void;
|
|
6
|
+
apply(progress: UploadProgress): UploadProgress;
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=throttled-speed.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"throttled-speed.d.ts","sourceRoot":"","sources":["../../src/helpers/throttled-speed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD,0DAA0D;AAC1D,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,YAAY,EACrB,UAAU,SAAM;IAMd,KAAK;IAKL,KAAK,WAAW,cAAc,GAAG,cAAc;EAUlD"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { useUpload, type UseUploadOptions, type UseUploadState, type UseUploadReturn, } from "./use-upload";
|
|
2
|
+
export { useMultiUpload, type UseMultiUploadOptions, type UseMultiUploadState, type UseMultiUploadReturn, } from "./use-multi-upload";
|
|
3
|
+
export { useUploadControls, type UseUploadControlsOptions, type UseUploadControlsReturn, } from "./use-upload-controls";
|
|
4
|
+
export { useMultiUploadControls, type UseMultiUploadControlsOptions, type UseMultiUploadControlsReturn, } from "./use-multi-upload-controls";
|
|
5
|
+
export { useDownload, type DownloadPhase, type DownloadHooks, type UseDownloadOptions, type UseDownloadState, type UseDownloadReturn, } from "./use-download";
|
|
6
|
+
export { useFetchDownload, type FetchDownloadPhase, type FetchDownloadProgress, type FetchDownloadHooks, type UseFetchDownloadOptions, type UseFetchDownloadState, type UseFetchDownloadReturn, } from "./use-fetch-download";
|
|
7
|
+
export { useDelete, type UseDeleteOptions, type UseDeleteState, type UseDeleteReturn, } from "./use-delete";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,cAAc,EACd,KAAK,qBAAqB,EAC1B,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,GAC1B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,iBAAiB,EACjB,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,GAC7B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,sBAAsB,EACtB,KAAK,6BAA6B,EAClC,KAAK,4BAA4B,GAClC,MAAM,6BAA6B,CAAC;AACrC,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"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { S3Api } from "@dimah-s3/core";
|
|
2
|
+
import type { DeletePhase, DeleteHooks } from "../types";
|
|
3
|
+
/** Options for {@link useDelete}. */
|
|
4
|
+
export type UseDeleteOptions = DeleteHooks & {
|
|
5
|
+
/** S3Api. Optional when an `<S3Provider>` is present in the tree. */
|
|
6
|
+
api?: S3Api;
|
|
7
|
+
/** Target bucket (overrides server default). */
|
|
8
|
+
bucket?: string;
|
|
9
|
+
};
|
|
10
|
+
export type UseDeleteState = {
|
|
11
|
+
/** Current delete phase. */
|
|
12
|
+
phase: DeletePhase;
|
|
13
|
+
/** Error message, or `null`. */
|
|
14
|
+
error: string | null;
|
|
15
|
+
};
|
|
16
|
+
export type UseDeleteReturn = UseDeleteState & {
|
|
17
|
+
/** Key awaiting confirmation, or `null`. */
|
|
18
|
+
pendingKey: string | null;
|
|
19
|
+
/** Move to the `confirming` phase for the given key. */
|
|
20
|
+
requestDelete: (key: string) => void;
|
|
21
|
+
/** Send the delete request for the pending key. */
|
|
22
|
+
confirmDelete: () => Promise<void>;
|
|
23
|
+
/** Cancel confirmation and return to `idle`. */
|
|
24
|
+
cancelDelete: () => void;
|
|
25
|
+
/** Reset state to `idle`. */
|
|
26
|
+
reset: () => void;
|
|
27
|
+
};
|
|
28
|
+
export declare function useDelete(options: UseDeleteOptions): UseDeleteReturn;
|
|
29
|
+
//# sourceMappingURL=use-delete.d.ts.map
|
|
@@ -0,0 +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;AAGzD,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,CAsEpE"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { S3Api } from "@dimah-s3/core";
|
|
2
|
+
export type { DownloadPhase, DownloadHooks } from "../types/download";
|
|
3
|
+
import type { DownloadPhase, DownloadHooks } from "../types/download";
|
|
4
|
+
/** Options for {@link useDownload}. */
|
|
5
|
+
export type UseDownloadOptions = DownloadHooks & {
|
|
6
|
+
/** S3Api. Optional when an `<S3Provider>` is present in the tree. */
|
|
7
|
+
api?: S3Api;
|
|
8
|
+
/** Target bucket (overrides server default). */
|
|
9
|
+
bucket?: string;
|
|
10
|
+
};
|
|
11
|
+
export type UseDownloadState = {
|
|
12
|
+
/** Current download phase. */
|
|
13
|
+
phase: DownloadPhase;
|
|
14
|
+
/** Error message, or `null`. */
|
|
15
|
+
error: string | null;
|
|
16
|
+
/** Presigned URL — set after a successful presign, cleared on reset. */
|
|
17
|
+
url: string | null;
|
|
18
|
+
/** Validity window in seconds for the presigned URL. */
|
|
19
|
+
expiresIn: number | null;
|
|
20
|
+
};
|
|
21
|
+
export type UseDownloadReturn = UseDownloadState & {
|
|
22
|
+
/** Presign and trigger a native browser download. */
|
|
23
|
+
download: (key: string, downloadName?: string) => Promise<void>;
|
|
24
|
+
/** Fetch the presigned URL without triggering a browser download. */
|
|
25
|
+
presign: (key: string, downloadName?: string) => Promise<{
|
|
26
|
+
url: string;
|
|
27
|
+
expiresIn: number;
|
|
28
|
+
} | null>;
|
|
29
|
+
/** Reset state to `idle`. */
|
|
30
|
+
reset: () => void;
|
|
31
|
+
};
|
|
32
|
+
export declare function useDownload(options: UseDownloadOptions): UseDownloadReturn;
|
|
33
|
+
//# sourceMappingURL=use-download.d.ts.map
|
|
@@ -0,0 +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;AAI5C,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,CA0E1E"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { S3Api } from "@dimah-s3/core";
|
|
2
|
+
import type { FetchDownloadPhase, FetchDownloadHooks } from "../types/download";
|
|
3
|
+
import type { UploadProgress } from "../types/upload";
|
|
4
|
+
export type { FetchDownloadPhase, FetchDownloadProgress, FetchDownloadHooks, } from "../types/download";
|
|
5
|
+
/** Options for {@link useFetchDownload}. */
|
|
6
|
+
export type UseFetchDownloadOptions = FetchDownloadHooks & {
|
|
7
|
+
/** S3Api. Optional when an `<S3Provider>` is present in the tree. */
|
|
8
|
+
api?: S3Api;
|
|
9
|
+
/** Target bucket (overrides server default). */
|
|
10
|
+
bucket?: string;
|
|
11
|
+
};
|
|
12
|
+
export type UseFetchDownloadState = {
|
|
13
|
+
/** Current download phase. */
|
|
14
|
+
phase: FetchDownloadPhase;
|
|
15
|
+
/** Byte transfer progress. */
|
|
16
|
+
progress: UploadProgress;
|
|
17
|
+
/** Error message, or `null`. */
|
|
18
|
+
error: string | null;
|
|
19
|
+
/** Resolved download filename. */
|
|
20
|
+
fileName: string | null;
|
|
21
|
+
/** Total file size in bytes. */
|
|
22
|
+
fileSize: number | null;
|
|
23
|
+
};
|
|
24
|
+
export type UseFetchDownloadReturn = UseFetchDownloadState & {
|
|
25
|
+
/** Presign, fetch bytes, and save via the browser. */
|
|
26
|
+
download: (key: string, downloadName?: string) => Promise<void>;
|
|
27
|
+
/** Abort the active download. */
|
|
28
|
+
cancel: () => void;
|
|
29
|
+
/** Reset state to `idle`. */
|
|
30
|
+
reset: () => void;
|
|
31
|
+
};
|
|
32
|
+
export declare function useFetchDownload(options: UseFetchDownloadOptions): UseFetchDownloadReturn;
|
|
33
|
+
//# 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":"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;AAGtD,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,CA4IxB"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { UploadProgress, MultiUploadFileState, MultiUploadPhase } from "../types";
|
|
2
|
+
import { type UseMultiUploadOptions } from "./use-multi-upload";
|
|
3
|
+
/** Options for {@link useMultiUploadControls}. */
|
|
4
|
+
export type UseMultiUploadControlsOptions = UseMultiUploadOptions & {
|
|
5
|
+
/** S3 object key, or a function that derives it from each file. */
|
|
6
|
+
objectKey: string | ((file: File) => string);
|
|
7
|
+
};
|
|
8
|
+
export type UseMultiUploadControlsReturn = {
|
|
9
|
+
/** Current batch upload phase. */
|
|
10
|
+
phase: MultiUploadPhase;
|
|
11
|
+
/** Per-file upload states. */
|
|
12
|
+
files: MultiUploadFileState[];
|
|
13
|
+
/** Aggregated progress across all files. */
|
|
14
|
+
totalProgress: UploadProgress;
|
|
15
|
+
/** Batch-level error message, or `null`. */
|
|
16
|
+
error: string | null;
|
|
17
|
+
/** `true` while uploading. */
|
|
18
|
+
isUploading: boolean;
|
|
19
|
+
/** Handle files from drag-and-drop or a file input. */
|
|
20
|
+
handleFiles: (files: FileList | null) => void;
|
|
21
|
+
/** Open the hidden file picker. */
|
|
22
|
+
openFilePicker: () => void;
|
|
23
|
+
/** Abort all in-flight uploads. */
|
|
24
|
+
cancel: () => void;
|
|
25
|
+
/** Preserve multipart store entries for resume. */
|
|
26
|
+
detach: () => void;
|
|
27
|
+
/** Reset state to `idle`. */
|
|
28
|
+
reset: () => void;
|
|
29
|
+
/** Spread on a hidden `<input>` element. */
|
|
30
|
+
inputProps: {
|
|
31
|
+
ref: React.RefObject<HTMLInputElement | null>;
|
|
32
|
+
type: "file";
|
|
33
|
+
multiple: true;
|
|
34
|
+
accept?: string;
|
|
35
|
+
hidden: true;
|
|
36
|
+
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
37
|
+
};
|
|
38
|
+
/** Spread on a container to enable drag-and-drop. */
|
|
39
|
+
dropHandlers: {
|
|
40
|
+
onDragOver: (e: React.DragEvent) => void;
|
|
41
|
+
onDrop: (e: React.DragEvent) => void;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
export declare function useMultiUploadControls(options: UseMultiUploadControlsOptions): UseMultiUploadControlsReturn;
|
|
45
|
+
//# sourceMappingURL=use-multi-upload-controls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-multi-upload-controls.d.ts","sourceRoot":"","sources":["../../src/hooks/use-multi-upload-controls.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAkB,KAAK,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAEhF,kDAAkD;AAClD,MAAM,MAAM,6BAA6B,GAAG,qBAAqB,GAAG;IAClE,mEAAmE;IACnE,SAAS,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,KAAK,MAAM,CAAC,CAAC;CAC9C,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,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,uDAAuD;IACvD,WAAW,EAAE,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,KAAK,IAAI,CAAC;IAC9C,mCAAmC;IACnC,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,mCAAmC;IACnC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,mDAAmD;IACnD,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,6BAA6B;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,4CAA4C;IAC5C,UAAU,EAAE;QACV,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;QAC9C,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,EAAE,IAAI,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,IAAI,CAAC;QACb,QAAQ,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;KAC5D,CAAC;IACF,qDAAqD;IACrD,YAAY,EAAE;QACZ,UAAU,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC;QACzC,MAAM,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC;KACtC,CAAC;CACH,CAAC;AAEF,wBAAgB,sBAAsB,CACpC,OAAO,EAAE,6BAA6B,GACrC,4BAA4B,CAgD9B"}
|
|
@@ -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 useMultiUpload}. */
|
|
4
|
+
export type UseMultiUploadOptions = 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 UseMultiUploadState = {
|
|
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 UseMultiUploadReturn = UseMultiUploadState & {
|
|
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 useUpload}'s `cancel`).
|
|
28
|
+
*/
|
|
29
|
+
cancel: () => void;
|
|
30
|
+
/**
|
|
31
|
+
* Stop uploads but preserve multipart store entries for resume
|
|
32
|
+
* (same semantics as {@link useUpload}'s `detach`).
|
|
33
|
+
*/
|
|
34
|
+
detach: () => void;
|
|
35
|
+
/** Reset state to `idle`. */
|
|
36
|
+
reset: () => void;
|
|
37
|
+
};
|
|
38
|
+
export declare function useMultiUpload(options: UseMultiUploadOptions): UseMultiUploadReturn;
|
|
39
|
+
//# sourceMappingURL=use-multi-upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-multi-upload.d.ts","sourceRoot":"","sources":["../../src/hooks/use-multi-upload.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAO5C,OAAO,KAAK,EACV,YAAY,EACZ,cAAc,EACd,oBAAoB,EACpB,gBAAgB,EAChB,oBAAoB,EACpB,gBAAgB,EACjB,MAAM,UAAU,CAAC;AAGlB,0CAA0C;AAC1C,MAAM,MAAM,qBAAqB,GAAG,YAAY,GAC9C,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,mBAAmB,GAAG;IAChC,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,oBAAoB,GAAG,mBAAmB,GAAG;IACvD,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,cAAc,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,oBAAoB,CA+RtB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { UploadPhase, UploadProgress, UploadRequestOptions } from "../types";
|
|
2
|
+
import { type UseUploadOptions } from "./use-upload";
|
|
3
|
+
/** Options for {@link useUploadControls}. */
|
|
4
|
+
export type UseUploadControlsOptions = UseUploadOptions & {
|
|
5
|
+
/** S3 object key, or a function that derives it from the file. */
|
|
6
|
+
objectKey: string | ((file: File) => string);
|
|
7
|
+
/** Static request options applied to the upload. */
|
|
8
|
+
uploadOptions?: UploadRequestOptions;
|
|
9
|
+
/** Per-upload request options override. */
|
|
10
|
+
getUploadOptions?: (file: File) => UploadRequestOptions;
|
|
11
|
+
};
|
|
12
|
+
export type UseUploadControlsReturn = {
|
|
13
|
+
/** Current upload phase. */
|
|
14
|
+
phase: UploadPhase;
|
|
15
|
+
/** Info about the selected file. */
|
|
16
|
+
fileInfo: {
|
|
17
|
+
name: string;
|
|
18
|
+
size: number;
|
|
19
|
+
} | null;
|
|
20
|
+
/** Byte transfer progress. */
|
|
21
|
+
progress: UploadProgress;
|
|
22
|
+
/** Error message, or `null`. */
|
|
23
|
+
error: string | null;
|
|
24
|
+
/** `true` while uploading. */
|
|
25
|
+
isUploading: boolean;
|
|
26
|
+
/** Handle files from drag-and-drop or a file input. */
|
|
27
|
+
handleFiles: (files: FileList | null) => void;
|
|
28
|
+
/** Open the hidden file picker. */
|
|
29
|
+
openFilePicker: () => void;
|
|
30
|
+
/** Abort and reset to idle. */
|
|
31
|
+
cancel: () => void;
|
|
32
|
+
/**
|
|
33
|
+
* Soft-stop: preserves S3 parts and store entry so a future `upload()` can
|
|
34
|
+
* resume. For non-resumable uploads, identical to `cancel()`.
|
|
35
|
+
* See `UseUploadReturn.detach` for full semantics.
|
|
36
|
+
*/
|
|
37
|
+
detach: () => void;
|
|
38
|
+
reset: () => void;
|
|
39
|
+
/** Spread on a hidden `<input>` element. */
|
|
40
|
+
inputProps: {
|
|
41
|
+
ref: React.RefObject<HTMLInputElement | null>;
|
|
42
|
+
type: "file";
|
|
43
|
+
accept?: string;
|
|
44
|
+
hidden: true;
|
|
45
|
+
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
|
|
46
|
+
};
|
|
47
|
+
/** Spread on a container to enable drag-and-drop. */
|
|
48
|
+
dropHandlers: {
|
|
49
|
+
onDragOver: (e: React.DragEvent) => void;
|
|
50
|
+
onDrop: (e: React.DragEvent) => void;
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export declare function useUploadControls(options: UseUploadControlsOptions): UseUploadControlsReturn;
|
|
54
|
+
//# sourceMappingURL=use-upload-controls.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-upload-controls.d.ts","sourceRoot":"","sources":["../../src/hooks/use-upload-controls.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,oBAAoB,EACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAa,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAEhE,6CAA6C;AAC7C,MAAM,MAAM,wBAAwB,GAAG,gBAAgB,GAAG;IACxD,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;CACzD,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,4BAA4B;IAC5B,KAAK,EAAE,WAAW,CAAC;IACnB,oCAAoC;IACpC,QAAQ,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;IAChD,8BAA8B;IAC9B,QAAQ,EAAE,cAAc,CAAC;IACzB,gCAAgC;IAChC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,8BAA8B;IAC9B,WAAW,EAAE,OAAO,CAAC;IACrB,uDAAuD;IACvD,WAAW,EAAE,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,KAAK,IAAI,CAAC;IAC9C,mCAAmC;IACnC,cAAc,EAAE,MAAM,IAAI,CAAC;IAC3B,+BAA+B;IAC/B,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB;;;;OAIG;IACH,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB,4CAA4C;IAC5C,UAAU,EAAE;QACV,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;QAC9C,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,IAAI,CAAC;QACb,QAAQ,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;KAC5D,CAAC;IACF,qDAAqD;IACrD,YAAY,EAAE;QACZ,UAAU,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC;QACzC,MAAM,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS,KAAK,IAAI,CAAC;KACtC,CAAC;CACH,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,wBAAwB,GAChC,uBAAuB,CA2DzB"}
|