@dimah-s3/react 1.7.1 → 2.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -13
- package/dist/api.d.ts +24 -15
- package/dist/api.d.ts.map +1 -1
- package/dist/chunk-SPUUNLXI.js +824 -0
- package/dist/chunk-SPUUNLXI.js.map +1 -0
- package/dist/create-s3-client.d.ts +1 -1
- package/dist/create-s3-client.d.ts.map +1 -1
- package/dist/engine.d.ts +15 -1
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +204 -512
- package/dist/engine.js.map +1 -1
- package/dist/helpers/format-accept-labels.d.ts +15 -2
- package/dist/helpers/format-accept-labels.d.ts.map +1 -1
- package/dist/helpers/format-date.d.ts +7 -0
- package/dist/helpers/format-date.d.ts.map +1 -0
- package/dist/helpers/format-dimah-error.d.ts +12 -2
- package/dist/helpers/format-dimah-error.d.ts.map +1 -1
- package/dist/helpers/format-file-size.d.ts +20 -0
- package/dist/helpers/format-file-size.d.ts.map +1 -0
- package/dist/helpers/format-speed.d.ts +1 -1
- package/dist/helpers/format-speed.d.ts.map +1 -1
- package/dist/helpers/format-upload-progress.d.ts +1 -1
- package/dist/helpers/format-upload-progress.d.ts.map +1 -1
- package/dist/helpers/index.d.ts +5 -8
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/load-route-catalog.d.ts +32 -8
- package/dist/helpers/load-route-catalog.d.ts.map +1 -1
- package/dist/helpers/throttled-speed.d.ts +2 -2
- package/dist/helpers/throttled-speed.d.ts.map +1 -1
- package/dist/helpers/to-timestamp.d.ts +5 -0
- package/dist/helpers/to-timestamp.d.ts.map +1 -0
- package/dist/helpers/truncate-file-name.d.ts +8 -0
- package/dist/helpers/truncate-file-name.d.ts.map +1 -0
- package/dist/helpers/use-format-accept-labels.d.ts +12 -0
- package/dist/helpers/use-format-accept-labels.d.ts.map +1 -0
- package/dist/helpers/use-format-eta.d.ts +14 -0
- package/dist/helpers/use-format-eta.d.ts.map +1 -0
- package/dist/helpers/use-format-speed.d.ts +12 -0
- package/dist/helpers/use-format-speed.d.ts.map +1 -0
- package/dist/hooks/use-delete.d.ts +6 -44
- package/dist/hooks/use-delete.d.ts.map +1 -1
- package/dist/hooks/use-download.d.ts +7 -117
- package/dist/hooks/use-download.d.ts.map +1 -1
- package/dist/hooks/use-fetch-download.d.ts +8 -0
- package/dist/hooks/use-fetch-download.d.ts.map +1 -0
- package/dist/hooks/use-file-intake.d.ts +43 -29
- package/dist/hooks/use-file-intake.d.ts.map +1 -1
- package/dist/hooks/use-file-upload.d.ts +38 -34
- package/dist/hooks/use-file-upload.d.ts.map +1 -1
- package/dist/hooks/use-object-list-selection.d.ts +78 -0
- package/dist/hooks/use-object-list-selection.d.ts.map +1 -0
- package/dist/hooks/use-object-list.d.ts +66 -16
- package/dist/hooks/use-object-list.d.ts.map +1 -1
- package/dist/hooks/use-object-url.d.ts +27 -10
- package/dist/hooks/use-object-url.d.ts.map +1 -1
- package/dist/hooks/use-route-upload-policy.d.ts +22 -14
- package/dist/hooks/use-route-upload-policy.d.ts.map +1 -1
- package/dist/hooks/use-upload.d.ts +72 -65
- package/dist/hooks/use-upload.d.ts.map +1 -1
- package/dist/index.d.ts +15 -19
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2420 -2164
- package/dist/index.js.map +1 -1
- package/dist/internal/abortable.d.ts +9 -0
- package/dist/internal/abortable.d.ts.map +1 -0
- package/dist/internal/browser-download.d.ts +15 -0
- package/dist/internal/browser-download.d.ts.map +1 -0
- package/dist/internal/callbacks.d.ts +54 -0
- package/dist/internal/callbacks.d.ts.map +1 -0
- package/dist/internal/client-error.d.ts +15 -0
- package/dist/internal/client-error.d.ts.map +1 -0
- package/dist/internal/hooks.d.ts +27 -0
- package/dist/internal/hooks.d.ts.map +1 -0
- package/dist/internal/lru.d.ts +13 -0
- package/dist/internal/lru.d.ts.map +1 -0
- package/dist/internal/operations.d.ts +74 -0
- package/dist/internal/operations.d.ts.map +1 -0
- package/dist/internal/pool.d.ts +8 -0
- package/dist/internal/pool.d.ts.map +1 -0
- package/dist/list/entries.d.ts +14 -0
- package/dist/list/entries.d.ts.map +1 -0
- package/dist/list/memory-object-source.d.ts +60 -0
- package/dist/list/memory-object-source.d.ts.map +1 -0
- package/dist/list/types.d.ts +123 -11
- package/dist/list/types.d.ts.map +1 -1
- package/dist/s3-provider.d.ts +3 -2
- package/dist/s3-provider.d.ts.map +1 -1
- package/dist/store/local-storage-store.d.ts +5 -4
- package/dist/store/local-storage-store.d.ts.map +1 -1
- package/dist/store/memory-store.d.ts +3 -4
- package/dist/store/memory-store.d.ts.map +1 -1
- package/dist/translations/types.d.ts +105 -23
- package/dist/translations/types.d.ts.map +1 -1
- package/dist/types/delete.d.ts +98 -9
- package/dist/types/delete.d.ts.map +1 -1
- package/dist/types/download.d.ts +152 -23
- package/dist/types/download.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/operation.d.ts +38 -0
- package/dist/types/operation.d.ts.map +1 -0
- package/dist/types/upload-store.d.ts +30 -40
- package/dist/types/upload-store.d.ts.map +1 -1
- package/dist/types/upload.d.ts +177 -130
- package/dist/types/upload.d.ts.map +1 -1
- package/dist/upload/abort.d.ts +10 -0
- package/dist/upload/abort.d.ts.map +1 -0
- package/dist/upload/constants.d.ts +8 -3
- package/dist/upload/constants.d.ts.map +1 -1
- package/dist/upload/index.d.ts +3 -2
- package/dist/upload/index.d.ts.map +1 -1
- package/dist/upload/multipart.d.ts +14 -4
- package/dist/upload/multipart.d.ts.map +1 -1
- package/dist/upload/part-pool.d.ts +16 -0
- package/dist/upload/part-pool.d.ts.map +1 -0
- package/dist/upload/presigned-http.d.ts +5 -14
- package/dist/upload/presigned-http.d.ts.map +1 -1
- package/dist/upload/progress.d.ts +7 -0
- package/dist/upload/progress.d.ts.map +1 -0
- package/dist/upload/request.d.ts +9 -0
- package/dist/upload/request.d.ts.map +1 -0
- package/dist/upload/resume-key.d.ts +7 -3
- package/dist/upload/resume-key.d.ts.map +1 -1
- package/dist/upload/retry.d.ts +27 -2
- package/dist/upload/retry.d.ts.map +1 -1
- package/dist/upload/stored-upload.d.ts +7 -0
- package/dist/upload/stored-upload.d.ts.map +1 -0
- package/dist/upload/upload-file.d.ts +10 -11
- package/dist/upload/upload-file.d.ts.map +1 -1
- package/dist/upload/upload-part.d.ts +6 -3
- package/dist/upload/upload-part.d.ts.map +1 -1
- package/dist/upload/xhr-upload.d.ts +10 -2
- package/dist/upload/xhr-upload.d.ts.map +1 -1
- package/package.json +7 -8
- package/dist/helpers/format-eta.d.ts +0 -13
- package/dist/helpers/format-eta.d.ts.map +0 -1
- package/dist/helpers/format-validate-file-error.d.ts +0 -9
- package/dist/helpers/format-validate-file-error.d.ts.map +0 -1
- package/dist/hooks/index.d.ts +0 -7
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/internal-helpers.d.ts +0 -10
- package/dist/internal-helpers.d.ts.map +0 -1
- package/dist/store/use-immer-state.d.ts +0 -8
- package/dist/store/use-immer-state.d.ts.map +0 -1
- package/dist/types/error.d.ts +0 -27
- package/dist/types/error.d.ts.map +0 -1
- package/dist/upload/upload-files.d.ts +0 -26
- package/dist/upload/upload-files.d.ts.map +0 -1
package/README.md
CHANGED
|
@@ -1,35 +1,75 @@
|
|
|
1
1
|
# @dimah-s3/react
|
|
2
2
|
|
|
3
|
+
**2.0 beta.** Install with `@beta`. `@latest` stays on 1.x, and betas can include breaking changes until 2.0.0.
|
|
4
|
+
|
|
3
5
|
Headless React hooks for S3 upload, download, and delete flows.
|
|
4
6
|
|
|
5
|
-
Full documentation: [s3.dimah.dev/docs/react](https://s3.dimah.dev/docs/react) ·
|
|
6
|
-
[llms.txt](https://s3.dimah.dev/llms.txt)
|
|
7
|
+
Full documentation: [v2.s3.dimah.dev/docs/react](https://v2.s3.dimah.dev/docs/react) ·
|
|
8
|
+
[llms.txt](https://v2.s3.dimah.dev/llms.txt)
|
|
7
9
|
|
|
8
10
|
## Install
|
|
9
11
|
|
|
10
12
|
```bash
|
|
11
|
-
pnpm add @dimah-s3/react
|
|
13
|
+
pnpm add @dimah-s3/react@beta @dimah-s3/core@beta @fuma-translate/react
|
|
12
14
|
```
|
|
13
15
|
|
|
16
|
+
Requires React 19.2.
|
|
17
|
+
|
|
14
18
|
## Minimal setup
|
|
15
19
|
|
|
20
|
+
Create the client once, in a client module:
|
|
21
|
+
|
|
16
22
|
```tsx
|
|
17
|
-
|
|
23
|
+
"use client";
|
|
24
|
+
|
|
25
|
+
import { createS3Client } from "@dimah-s3/react";
|
|
18
26
|
|
|
19
27
|
export const s3Client = createS3Client();
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
Wrap your app in `<s3Client.Provider>`. Then call a hook with a route name.
|
|
31
|
+
The server builds the object key:
|
|
20
32
|
|
|
21
|
-
|
|
22
|
-
|
|
33
|
+
```tsx
|
|
34
|
+
"use client";
|
|
35
|
+
|
|
36
|
+
import { useUpload } from "@dimah-s3/react";
|
|
37
|
+
|
|
38
|
+
export function AvatarPicker() {
|
|
39
|
+
const upload = useUpload({ route: "avatar", accept: ["image/*"] });
|
|
23
40
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
41
|
+
return (
|
|
42
|
+
<>
|
|
43
|
+
<input {...upload.getInputProps()} />
|
|
44
|
+
<button
|
|
45
|
+
type="button"
|
|
46
|
+
disabled={upload.isPending}
|
|
47
|
+
onClick={() => upload.open()}
|
|
48
|
+
>
|
|
49
|
+
{upload.isPending
|
|
50
|
+
? `Uploading ${upload.progress.percent}%`
|
|
51
|
+
: "Upload avatar"}
|
|
52
|
+
</button>
|
|
53
|
+
{upload.error ? <p role="alert">{upload.error.message}</p> : null}
|
|
54
|
+
</>
|
|
55
|
+
);
|
|
56
|
+
}
|
|
31
57
|
```
|
|
32
58
|
|
|
59
|
+
## Entries
|
|
60
|
+
|
|
61
|
+
- `@dimah-s3/react`: the hooks (`useUpload`, `useDownload`,
|
|
62
|
+
`useFetchDownload`, `useDelete`, `useObjectUrl`, `useObjectList`, …),
|
|
63
|
+
`S3Provider`, `createS3Client`, and the types. It is a `"use client"`
|
|
64
|
+
module.
|
|
65
|
+
- `@dimah-s3/react/engine`: plain functions with no React import, such as
|
|
66
|
+
`uploadFile`, `memoryObjectSource`, `defineApi`, `loadRouteCatalog`, and
|
|
67
|
+
`createLocalStorageStore`. Shared and server modules can import it.
|
|
68
|
+
- `APIError`, `S3_ERROR_CODES`, and the other protocol helpers come from
|
|
69
|
+
`@dimah-s3/core`.
|
|
70
|
+
|
|
71
|
+
For prebuilt components, see [`@dimah-s3/ui`](https://v2.s3.dimah.dev/docs/react/ui).
|
|
72
|
+
|
|
33
73
|
## License
|
|
34
74
|
|
|
35
75
|
MIT
|
package/dist/api.d.ts
CHANGED
|
@@ -1,29 +1,38 @@
|
|
|
1
|
+
import type { S3Api } from "@dimah-s3/core";
|
|
2
|
+
import type { S3ApiUploadTransport } from "./types/upload";
|
|
1
3
|
/**
|
|
2
|
-
* Type helper for a custom dimah-s3
|
|
4
|
+
* Type helper for a custom dimah-s3 API.
|
|
3
5
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
6
|
+
* Implement each `S3Api` method to call your own backend endpoint, tRPC
|
|
7
|
+
* mutation, GraphQL query, or anything else. Each method takes
|
|
8
|
+
* `(payload, options)`; forward `options.signal` so cancels reach the
|
|
9
|
+
* request. Add `uploadTransport` to replace the byte transfer. The object is
|
|
10
|
+
* returned as-is; `defineApi` only checks the type.
|
|
7
11
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
12
|
+
* With the default dimah-s3 route layout, use `createS3Client` from
|
|
13
|
+
* `@dimah-s3/react` (or `@dimah-s3/core` without React bindings) instead.
|
|
10
14
|
*
|
|
11
15
|
* @example
|
|
12
16
|
* ```ts
|
|
13
|
-
* import { defineApi } from "@dimah-s3/react";
|
|
17
|
+
* import { defineApi } from "@dimah-s3/react/engine";
|
|
14
18
|
*
|
|
15
19
|
* export const api = defineApi({
|
|
16
|
-
* async upload(payload) {
|
|
17
|
-
*
|
|
18
|
-
*
|
|
20
|
+
* async upload(payload, options) {
|
|
21
|
+
* const res = await fetch("/api/storage/presign", {
|
|
22
|
+
* method: "POST",
|
|
23
|
+
* body: JSON.stringify(payload),
|
|
24
|
+
* signal: options?.signal,
|
|
25
|
+
* });
|
|
26
|
+
* return res.json();
|
|
19
27
|
* },
|
|
20
|
-
* async confirm(payload) { ... },
|
|
21
|
-
* async download(payload) { ... },
|
|
22
|
-
* async
|
|
28
|
+
* async confirm(payload, options) { ... },
|
|
29
|
+
* async download(payload, options) { ... },
|
|
30
|
+
* async catalog(options) { ... },
|
|
31
|
+
* async delete(payload, options) { ... },
|
|
32
|
+
* async deleteMany(payload, options) { ... },
|
|
23
33
|
* multipart: { init, signPart, listParts, complete, abort },
|
|
24
34
|
* });
|
|
25
35
|
* ```
|
|
26
36
|
*/
|
|
27
|
-
|
|
28
|
-
export declare function defineApi(input: S3Api): S3Api;
|
|
37
|
+
export declare function defineApi<TApi extends S3Api & S3ApiUploadTransport>(api: TApi): TApi;
|
|
29
38
|
//# sourceMappingURL=api.d.ts.map
|
package/dist/api.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,SAAS,CAAC,IAAI,SAAS,KAAK,GAAG,oBAAoB,EACjE,GAAG,EAAE,IAAI,GACR,IAAI,CAEN"}
|