use-tus 0.8.2 → 0.8.4
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 +123 -198
- package/dist/__stories__/Basic.stories.d.ts +1 -2
- package/dist/__stories__/CacheKey.stories.d.ts +1 -2
- package/dist/__stories__/DefaultOptions.stories.d.ts +1 -2
- package/dist/__tests__/utils/mock.d.ts +0 -1
- package/dist/utils/core/createUpload.d.ts +1 -1
- package/dist/utils/options/mergeUseTusOptions.d.ts +1 -1
- package/package.json +21 -19
package/README.md
CHANGED
|
@@ -13,29 +13,25 @@
|
|
|
13
13
|
</p>
|
|
14
14
|
|
|
15
15
|
## Features
|
|
16
|
-
- Resumable file uploads
|
|
16
|
+
- Resumable file uploads in React.
|
|
17
|
+
- Improved file upload management within the React component lifecycle.
|
|
17
18
|
- Lightweight and simple interface hooks.
|
|
18
|
-
-
|
|
19
|
+
- Manage [Upload](https://github.com/tus/tus-js-client/blob/master/docs/api.md#tusuploadfile-options) instances via context.
|
|
19
20
|
- TypeScript support.
|
|
20
21
|
|
|
21
22
|
## Demo
|
|
22
|
-
|
|
23
|
+
Try out the [use-tus demo](https://kqito.github.io/use-tus/?path=/story/usetus--basic).
|
|
23
24
|
|
|
24
25
|
|
|
25
26
|
## Installation
|
|
26
|
-
|
|
27
|
-
```sh
|
|
28
|
-
npm install use-tus tus-js-client
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
or
|
|
27
|
+
Install the package using your package manager of choice.
|
|
32
28
|
|
|
33
29
|
```sh
|
|
34
|
-
|
|
30
|
+
npm install use-tus tus-js-client
|
|
35
31
|
```
|
|
36
32
|
|
|
37
33
|
## Usage
|
|
38
|
-
|
|
34
|
+
Below is an example of how to use `useTus`.
|
|
39
35
|
|
|
40
36
|
```tsx
|
|
41
37
|
import { useTus } from 'use-tus'
|
|
@@ -44,38 +40,26 @@ const Uploader = () => {
|
|
|
44
40
|
const { upload, setUpload, isSuccess, error, remove } = useTus();
|
|
45
41
|
|
|
46
42
|
const handleSetUpload = useCallback((event: ChangeEvent<HTMLInputElement>) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
[setUpload]
|
|
62
|
-
);
|
|
43
|
+
const file = event.target.files.item(0);
|
|
44
|
+
if (!file) return;
|
|
45
|
+
|
|
46
|
+
setUpload(file, {
|
|
47
|
+
endpoint: 'https://tusd.tusdemo.net/files/',
|
|
48
|
+
metadata: {
|
|
49
|
+
filename: file.name,
|
|
50
|
+
filetype: file.type,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
}, [setUpload]);
|
|
63
54
|
|
|
64
55
|
const handleStart = useCallback(() => {
|
|
65
|
-
if (
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// Start to upload the file.
|
|
70
|
-
upload.start();
|
|
56
|
+
if (upload) upload.start();
|
|
71
57
|
}, [upload]);
|
|
72
58
|
|
|
73
59
|
return (
|
|
74
60
|
<div>
|
|
75
61
|
<input type="file" onChange={handleSetUpload} />
|
|
76
|
-
<button type="button" onClick={handleStart}>
|
|
77
|
-
Upload
|
|
78
|
-
</button>
|
|
62
|
+
<button type="button" onClick={handleStart}>Upload</button>
|
|
79
63
|
</div>
|
|
80
64
|
);
|
|
81
65
|
};
|
|
@@ -104,49 +88,45 @@ const { upload, setUpload, isSuccess, isAborted, isUploading, error, remove } =
|
|
|
104
88
|
- `Upload` (type: `Upload | undefined`) (default: undefined)
|
|
105
89
|
- Option to specify customized own Upload class with this hooks.
|
|
106
90
|
|
|
107
|
-
####
|
|
108
|
-
This option extends the UploadOptions provided by `tus-js-client`,
|
|
109
|
-
|
|
110
|
-
For detail type information of `UploadOptions`, please see [here](https://github.com/tus/tus-js-client/blob/master/lib/index.d.ts#L22).
|
|
91
|
+
#### `uploadOptions`
|
|
92
|
+
This option extends the `UploadOptions` provided by `tus-js-client`, allowing every callback to receive the upload instance as the final argument. For detailed type information on `UploadOptions`, see [here](https://github.com/tus/tus-js-client/blob/master/lib/index.d.ts#L22).
|
|
111
93
|
|
|
112
|
-
|
|
94
|
+
Example:
|
|
113
95
|
|
|
114
96
|
```ts
|
|
115
|
-
|
|
97
|
+
setUpload(file, {
|
|
116
98
|
onSuccess: (upload) => {
|
|
117
99
|
console.log(upload.url)
|
|
118
100
|
},
|
|
119
101
|
onError: (error, upload) => {
|
|
120
102
|
console.log(error)
|
|
121
|
-
|
|
122
103
|
setTimeout(() => {
|
|
123
104
|
upload.start()
|
|
124
105
|
}, 1000)
|
|
125
106
|
}
|
|
126
|
-
})
|
|
107
|
+
});
|
|
127
108
|
```
|
|
128
109
|
|
|
129
|
-
|
|
110
|
+
|
|
111
|
+
#### Returns
|
|
130
112
|
- `upload` (type: `tus.Upload | undefined`)
|
|
131
|
-
-
|
|
132
|
-
-
|
|
133
|
-
- For detail usage, please see [here](https://github.com/tus/tus-js-client#example)
|
|
113
|
+
- Used for resumable file uploads. Undefined unless `setUpload` is called.
|
|
114
|
+
- For detailed usage, see [here](https://github.com/tus/tus-js-client#example).
|
|
134
115
|
|
|
135
116
|
- `setUpload` (type: `(file: tus.Upload['file'], options?: TusHooksUploadFnOptions) => void`)
|
|
136
|
-
- Function to create an `Upload`.
|
|
137
|
-
- The property specified in `uploadOptions` will be overwritten if property of `options` are speicified.
|
|
117
|
+
- Function to create an `Upload`. `uploadOptions` properties are overwritten if `options` is specified.
|
|
138
118
|
|
|
139
119
|
- `isSuccess` (type: `boolean`)
|
|
140
|
-
-
|
|
120
|
+
- Indicates if the upload was successful.
|
|
141
121
|
|
|
142
122
|
- `isAborted` (type: `boolean`)
|
|
143
|
-
-
|
|
123
|
+
- Indicates if the upload was aborted.
|
|
144
124
|
|
|
145
125
|
- `isUploading` (type: `boolean`)
|
|
146
|
-
- Indicates if an
|
|
126
|
+
- Indicates if an upload is in progress.
|
|
147
127
|
|
|
148
128
|
- `error` (type: `Error | undefined`)
|
|
149
|
-
- Error when upload fails.
|
|
129
|
+
- Error when the upload fails.
|
|
150
130
|
|
|
151
131
|
- `remove` (type: `() => void`)
|
|
152
132
|
- Function to reset states.
|
|
@@ -154,61 +134,52 @@ setUplaod(file, {
|
|
|
154
134
|
### `useTusStore` hooks
|
|
155
135
|
|
|
156
136
|
```tsx
|
|
157
|
-
const { upload, setUpload, isSuccess, isAborted, isUploading, error, remove } = useTusStore(cacheKey, { autoAbort, autoStart, uploadOptions, Upload
|
|
137
|
+
const { upload, setUpload, isSuccess, isAborted, isUploading, error, remove } = useTusStore(cacheKey, { autoAbort, autoStart, uploadOptions, Upload });
|
|
158
138
|
```
|
|
159
139
|
|
|
160
|
-
`useTusStore`
|
|
140
|
+
`useTusStore` creates an object for resumable file uploads and stores it in a context. This is useful for handling uploads across components or pages.
|
|
161
141
|
|
|
162
|
-
|
|
142
|
+
> [!NOTE]
|
|
143
|
+
> `useTusStore` requires `TusClientProvider` as a parent or higher element.
|
|
163
144
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
### Arguments
|
|
145
|
+
#### Arguments
|
|
167
146
|
- `cacheKey` (type: `string`)
|
|
168
|
-
-
|
|
147
|
+
- Key associated with the `Upload` object created by `setUpload`.
|
|
169
148
|
|
|
170
|
-
- `autoAbort` (type: `boolean | undefined
|
|
171
|
-
-
|
|
149
|
+
- `autoAbort` (type: `boolean | undefined`, default: `true`)
|
|
150
|
+
- Automatically abort uploads when `useTusStore` is unmounted.
|
|
172
151
|
|
|
173
|
-
- `autoStart` (type: `boolean | undefined
|
|
174
|
-
-
|
|
152
|
+
- `autoStart` (type: `boolean | undefined`, default: `false`)
|
|
153
|
+
- Automatically start the upload after calling the `setUpload` function.
|
|
175
154
|
|
|
176
|
-
- `uploadOptions` (type: `TusHooksUploadFnOptions | undefined
|
|
177
|
-
-
|
|
178
|
-
- For detail type information of `TusHooksUploadFnOptions`, please see [here](https://github.com/tus/tus-js-client/blob/master/lib/index.d.ts#L22).
|
|
155
|
+
- `uploadOptions` (type: `TusHooksUploadFnOptions | undefined`, default: `undefined`)
|
|
156
|
+
- Set options to be used by the upload object generated by this hook.
|
|
179
157
|
|
|
180
|
-
- `Upload` (type: `Upload | undefined
|
|
181
|
-
-
|
|
158
|
+
- `Upload` (type: `Upload | undefined`, default: `undefined`)
|
|
159
|
+
- Specify a customized `Upload` class with this hook.
|
|
182
160
|
|
|
183
|
-
|
|
161
|
+
#### Returns
|
|
184
162
|
- `upload` (type: `tus.Upload | undefined`)
|
|
185
|
-
-
|
|
186
|
-
-
|
|
163
|
+
- Used for resumable file uploads. Undefined unless `setUpload` is called.
|
|
164
|
+
- Corresponds to the `Upload` associated with `cacheKey` in `TusClientProvider`.
|
|
187
165
|
|
|
188
|
-
|
|
189
|
-
- `
|
|
190
|
-
- Object to be used when performing Resumable file upload.
|
|
191
|
-
- This value of the `Upload` associated with the cacheKey in the TusClientProvider. If not present, undefined.
|
|
192
|
-
- For detail usage, please see [here](https://github.com/tus/tus-js-client#example)
|
|
193
|
-
|
|
194
|
-
- `setUpload` (type: `(file: tus.Upload['file'], options?: tus.Upload['options']) => void`)
|
|
195
|
-
- Function to create an `Upload`.
|
|
196
|
-
- The property specified in `uploadOptions` will be overwritten if property of `options` are speicified.
|
|
166
|
+
- `setUpload` (type: `(file: tus.Upload['file'], options?: TusHooksUploadFnOptions) => void`)
|
|
167
|
+
- Function to create an `Upload`. `uploadOptions` properties are overwritten if `options` is specified.
|
|
197
168
|
|
|
198
169
|
- `isSuccess` (type: `boolean`)
|
|
199
|
-
-
|
|
170
|
+
- Indicates if the upload was successful.
|
|
200
171
|
|
|
201
172
|
- `isAborted` (type: `boolean`)
|
|
202
|
-
-
|
|
173
|
+
- Indicates if the upload was aborted.
|
|
203
174
|
|
|
204
175
|
- `isUploading` (type: `boolean`)
|
|
205
|
-
- Indicates if an
|
|
176
|
+
- Indicates if an upload is in progress.
|
|
206
177
|
|
|
207
178
|
- `error` (type: `Error | undefined`)
|
|
208
|
-
- Error when upload fails.
|
|
179
|
+
- Error when the upload fails.
|
|
209
180
|
|
|
210
181
|
- `remove` (type: `() => void`)
|
|
211
|
-
- Function to delete the `Upload` associated with cacheKey
|
|
182
|
+
- Function to delete the `Upload` associated with `cacheKey`.
|
|
212
183
|
|
|
213
184
|
### `TusClientProvider`
|
|
214
185
|
|
|
@@ -220,34 +191,35 @@ This hooks is useful when you want to handle uploads across pages or components.
|
|
|
220
191
|
)
|
|
221
192
|
```
|
|
222
193
|
|
|
223
|
-
`TusClientProvider`
|
|
194
|
+
`TusClientProvider` stores `Upload` objects created with `useTusStore`.
|
|
224
195
|
|
|
225
|
-
|
|
196
|
+
#### Props
|
|
226
197
|
- `defaultOptions` (type: `(file: tus.Upload['file']) => TusHooksUploadFnOptions | undefined`)
|
|
227
|
-
-
|
|
198
|
+
- Default options object used when creating new uploads. For more details, see [here](https://github.com/tus/tus-js-client/blob/master/docs/api.md#tusdefaultoptions).
|
|
228
199
|
|
|
229
200
|
### `useTusClient`
|
|
230
201
|
|
|
231
202
|
```tsx
|
|
232
203
|
const { state, removeUpload, reset } = useTusClient();
|
|
233
204
|
```
|
|
234
|
-
`useTusClient` is a hooks that can be used to retrieve and reset the state of a `TusClientProvider`.
|
|
235
205
|
|
|
236
|
-
|
|
206
|
+
`useTusClient` retrieves and resets the state of `TusClientProvider`.
|
|
207
|
+
|
|
208
|
+
#### Returns
|
|
237
209
|
- `state` (type: `{ [cacheKey: string]: UploadState | undefined }`)
|
|
238
|
-
- Upload information associated with cacheKey
|
|
210
|
+
- Upload information associated with `cacheKey`.
|
|
239
211
|
|
|
240
212
|
- `removeUpload` (type: `(cacheKey: string) => void`)
|
|
241
|
-
- Remove the upload instance associated with
|
|
213
|
+
- Remove the upload instance associated with `cacheKey`.
|
|
242
214
|
|
|
243
215
|
- `reset` (type: `() => void`)
|
|
244
|
-
- Initialize the value of TusClientProvider
|
|
216
|
+
- Initialize the value of `TusClientProvider`.
|
|
245
217
|
|
|
246
218
|
## Examples
|
|
247
|
-
|
|
219
|
+
Here are some examples of how to use `use-tus`.
|
|
248
220
|
|
|
249
221
|
### Uploading a file
|
|
250
|
-
|
|
222
|
+
Use `setUpload` and `upload.start` functions to perform resumable file uploads.
|
|
251
223
|
|
|
252
224
|
```tsx
|
|
253
225
|
import { useTus } from 'use-tus'
|
|
@@ -256,44 +228,33 @@ const Uploader = () => {
|
|
|
256
228
|
const { upload, setUpload } = useTus();
|
|
257
229
|
|
|
258
230
|
const handleSetUpload = useCallback((event: ChangeEvent<HTMLInputElement>) => {
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
},
|
|
271
|
-
});
|
|
272
|
-
},
|
|
273
|
-
[setUpload]
|
|
274
|
-
);
|
|
231
|
+
const file = event.target.files.item(0);
|
|
232
|
+
if (!file) return;
|
|
233
|
+
|
|
234
|
+
setUpload(file, {
|
|
235
|
+
endpoint: 'https://tusd.tusdemo.net/files/',
|
|
236
|
+
metadata: {
|
|
237
|
+
filename: file.name,
|
|
238
|
+
filetype: file.type,
|
|
239
|
+
},
|
|
240
|
+
});
|
|
241
|
+
}, [setUpload]);
|
|
275
242
|
|
|
276
243
|
const handleStart = useCallback(() => {
|
|
277
|
-
if (
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
// Start upload the file.
|
|
282
|
-
upload.start();
|
|
244
|
+
if (upload) upload.start();
|
|
283
245
|
}, [upload]);
|
|
284
246
|
|
|
285
247
|
return (
|
|
286
248
|
<div>
|
|
287
249
|
<input type="file" onChange={handleSetUpload} />
|
|
288
|
-
<button type="button" onClick={handleStart}>
|
|
289
|
-
Upload
|
|
290
|
-
</button>
|
|
250
|
+
<button type="button" onClick={handleStart}>Upload</button>
|
|
291
251
|
</div>
|
|
292
252
|
);
|
|
293
253
|
};
|
|
294
254
|
```
|
|
295
255
|
|
|
296
|
-
|
|
256
|
+
> [!TIP]
|
|
257
|
+
> You can also set `autoStart` to automatically start uploading files after `setUpload` is called.
|
|
297
258
|
|
|
298
259
|
```tsx
|
|
299
260
|
import { useTus } from 'use-tus'
|
|
@@ -302,30 +263,26 @@ const Uploader = () => {
|
|
|
302
263
|
const { upload, setUpload } = useTus({ autoStart: true });
|
|
303
264
|
|
|
304
265
|
const handleSetUpload = useCallback((event: ChangeEvent<HTMLInputElement>) => {
|
|
305
|
-
|
|
266
|
+
const file = event.target.files.item(0);
|
|
267
|
+
if (!file) return;
|
|
268
|
+
|
|
269
|
+
setUpload(file, {
|
|
270
|
+
endpoint: 'https://tusd.tusdemo.net/files/',
|
|
271
|
+
metadata: {
|
|
272
|
+
filename: file.name,
|
|
273
|
+
filetype: file.type,
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
}, [setUpload]);
|
|
306
277
|
|
|
307
|
-
if (!file) {
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
setUpload(file, {
|
|
312
|
-
endpoint: 'https://tusd.tusdemo.net/files/',
|
|
313
|
-
metadata: {
|
|
314
|
-
filename: file.name,
|
|
315
|
-
filetype: file.type,
|
|
316
|
-
},
|
|
317
|
-
});
|
|
318
|
-
},
|
|
319
|
-
[setUpload]
|
|
320
|
-
);
|
|
321
278
|
return (
|
|
322
279
|
<input type="file" onChange={handleSetUpload} />
|
|
323
280
|
);
|
|
324
281
|
};
|
|
325
282
|
```
|
|
326
283
|
|
|
327
|
-
### Aborting a
|
|
328
|
-
|
|
284
|
+
### Aborting a File Upload
|
|
285
|
+
Use the `upload.abort` function to abort an upload.
|
|
329
286
|
|
|
330
287
|
```tsx
|
|
331
288
|
import { useTus } from 'use-tus'
|
|
@@ -334,54 +291,33 @@ const Aborter = () => {
|
|
|
334
291
|
const { upload } = useTus();
|
|
335
292
|
|
|
336
293
|
const handleAbort = useCallback(() => {
|
|
337
|
-
if (
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
upload.abort();
|
|
294
|
+
if (upload) upload.abort();
|
|
342
295
|
}, [upload]);
|
|
343
296
|
|
|
344
297
|
return (
|
|
345
298
|
<div>
|
|
346
|
-
<button type="button" onClick={handleAbort}>
|
|
347
|
-
Abort
|
|
348
|
-
</button>
|
|
299
|
+
<button type="button" onClick={handleAbort}>Abort</button>
|
|
349
300
|
</div>
|
|
350
301
|
);
|
|
351
302
|
};
|
|
352
303
|
```
|
|
353
304
|
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
```tsx
|
|
357
|
-
import { useTus } from 'use-tus'
|
|
358
|
-
|
|
359
|
-
const Uploader = () => {
|
|
360
|
-
const { upload, setUpload } = useTus({ autoAbort: true });
|
|
361
|
-
|
|
362
|
-
// omitted...
|
|
363
|
-
};
|
|
364
|
-
```
|
|
365
|
-
|
|
366
|
-
## Default options of upload
|
|
367
|
-
You can specify default options in the `defaultOptions` props of the `TusClientProvider`.
|
|
305
|
+
### Default Options for Upload
|
|
306
|
+
Specify default options in `defaultOptions` props of the `TusClientProvider`.
|
|
368
307
|
|
|
369
308
|
```tsx
|
|
370
309
|
import { useTusStore, DefaultOptions, TusClientProvider } from 'use-tus'
|
|
371
310
|
|
|
372
|
-
const defaultOptions: DefaultOptions = (
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
endpoint: 'https://tusd.tusdemo.net/files/',
|
|
377
|
-
metadata: file
|
|
311
|
+
const defaultOptions: DefaultOptions = (file) => ({
|
|
312
|
+
endpoint: 'https://tusd.tusdemo.net/files/',
|
|
313
|
+
metadata:
|
|
314
|
+
file instanceof File
|
|
378
315
|
? {
|
|
379
316
|
filename: file.name,
|
|
380
317
|
filetype: file.type,
|
|
381
318
|
}
|
|
382
319
|
: undefined,
|
|
383
|
-
|
|
384
|
-
};
|
|
320
|
+
});
|
|
385
321
|
|
|
386
322
|
const App = () => (
|
|
387
323
|
<TusClientProvider defaultOptions={defaultOptions}>
|
|
@@ -393,45 +329,34 @@ const Uploader = () => {
|
|
|
393
329
|
const { setUpload } = useTusStore('cacheKey', { autoStart: true });
|
|
394
330
|
|
|
395
331
|
const handleSetUpload = useCallback((event: ChangeEvent<HTMLInputElement>) => {
|
|
396
|
-
|
|
332
|
+
const file = event.target.files.item(0);
|
|
333
|
+
if (!file) return;
|
|
397
334
|
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
// You no longer need to specify the options associated with upload.
|
|
403
|
-
// If specified, it will override defaultOptions.
|
|
404
|
-
setUpload(file);
|
|
405
|
-
},
|
|
406
|
-
[setUpload]
|
|
407
|
-
);
|
|
335
|
+
// Uploads the selected file using default options.
|
|
336
|
+
// Overrides if options are provided to setUpload.
|
|
337
|
+
setUpload(file);
|
|
338
|
+
}, [setUpload]);
|
|
408
339
|
|
|
409
|
-
return
|
|
410
|
-
<div>
|
|
411
|
-
<input type="file" onChange={handleSetUpload} />
|
|
412
|
-
</div>
|
|
413
|
-
);
|
|
340
|
+
return <input type="file" onChange={handleSetUpload} />;
|
|
414
341
|
};
|
|
415
342
|
```
|
|
416
343
|
|
|
417
|
-
### Specify
|
|
418
|
-
|
|
344
|
+
### Specify Upload Key
|
|
345
|
+
Specify `cacheKey` to associate uploads across components/pages.
|
|
419
346
|
|
|
420
347
|
```tsx
|
|
421
|
-
|
|
422
|
-
// Create upload accosiated with 'upload-thumbnail' key
|
|
423
|
-
const { setUpload } = useTusStore('upload-thumbnail')
|
|
348
|
+
import { useTusStore } from 'use-tus'
|
|
424
349
|
|
|
425
|
-
|
|
426
|
-
}
|
|
350
|
+
const SelectFileComponent = (file: File) => {
|
|
351
|
+
const { setUpload } = useTusStore('upload-thumbnail');
|
|
352
|
+
setUpload(file);
|
|
353
|
+
};
|
|
427
354
|
|
|
428
355
|
const UploadFileComponent = () => {
|
|
429
|
-
const { upload } = useTusStore('upload-thumbnail')
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
356
|
+
const { upload } = useTusStore('upload-thumbnail');
|
|
357
|
+
if (upload) upload.start();
|
|
358
|
+
};
|
|
433
359
|
```
|
|
434
360
|
|
|
435
|
-
|
|
436
361
|
## License
|
|
437
362
|
[MIT © kqito](./LICENSE)
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/// <reference types="jest" />
|
|
2
1
|
import type { Upload } from "tus-js-client";
|
|
3
2
|
export declare const createUploadMock: (start: jest.Mock, abort: jest.Mock) => typeof Upload;
|
|
4
3
|
export declare const createConsoleErrorMock: () => jest.SpyInstance<void, [message?: any, ...optionalParams: any[]], any>;
|
|
@@ -12,5 +12,5 @@ export type CreateUploadParams = {
|
|
|
12
12
|
export declare const createUpload: ({ Upload, file, uploadOptions, uploadFnOptions, onChange, onStart, onAbort, }: CreateUploadParams) => {
|
|
13
13
|
upload: UploadType;
|
|
14
14
|
originalStart: () => void;
|
|
15
|
-
originalAbort: (shouldTerminate?: boolean
|
|
15
|
+
originalAbort: (shouldTerminate?: boolean) => Promise<void>;
|
|
16
16
|
};
|
|
@@ -3,6 +3,6 @@ import { TusHooksOptions } from "../../types";
|
|
|
3
3
|
export declare const mergeUseTusOptions: (options: TusHooksOptions) => {
|
|
4
4
|
autoAbort: boolean;
|
|
5
5
|
autoStart: boolean;
|
|
6
|
-
uploadOptions: import("../../types").TusHooksUploadOptions
|
|
6
|
+
uploadOptions: import("../../types").TusHooksUploadOptions;
|
|
7
7
|
Upload: typeof Upload;
|
|
8
8
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-tus",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.4",
|
|
4
4
|
"description": "React hooks for resumable file uploads using tus-js-client",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"build": "npm-run-all -s type clean build:rollup",
|
|
10
|
+
"build:rollup": "cross-env NODE_ENV=production rollup -c",
|
|
11
|
+
"test": "cross-env NODE_ENV=TEST jest",
|
|
12
|
+
"type": "tsc --noEmit",
|
|
13
|
+
"format": "npm-run-all -s format:*",
|
|
14
|
+
"format:fix": "prettier --write './**/*.{ts,tsx,js,jsx,json}'",
|
|
15
|
+
"format:lint": "eslint ./ --ext .ts,.tsx",
|
|
16
|
+
"clean": "rimraf ./dist",
|
|
17
|
+
"prepublishOnly": "npm run build",
|
|
18
|
+
"prepare": "husky install",
|
|
19
|
+
"storybook": "storybook dev -p 6006",
|
|
20
|
+
"storybook:build": "storybook build",
|
|
21
|
+
"storybook:static": "gh-pages -d storybook-static",
|
|
22
|
+
"storybook:deploy": "npm-run-all -s storybook:build storybook:static"
|
|
23
|
+
},
|
|
8
24
|
"keywords": [
|
|
9
25
|
"react",
|
|
10
26
|
"react-hooks",
|
|
@@ -73,27 +89,13 @@
|
|
|
73
89
|
"storybook": "^7.5.1",
|
|
74
90
|
"tailwindcss": "npm:@tailwindcss/postcss7-compat",
|
|
75
91
|
"ts-jest": "^29.1.1",
|
|
76
|
-
"tus-js-client": "
|
|
92
|
+
"tus-js-client": "4.0.0",
|
|
77
93
|
"typescript": "^5.2.2",
|
|
78
94
|
"vite": "^4.5.0"
|
|
79
95
|
},
|
|
80
96
|
"peerDependencies": {
|
|
81
97
|
"react": ">=16.8",
|
|
82
|
-
"tus-js-client": ">=2.2.0"
|
|
98
|
+
"tus-js-client": ">=2.2.0 <4.2.0"
|
|
83
99
|
},
|
|
84
|
-
"packageManager": "pnpm@
|
|
85
|
-
|
|
86
|
-
"build": "npm-run-all -s type clean build:rollup",
|
|
87
|
-
"build:rollup": "cross-env NODE_ENV=production rollup -c",
|
|
88
|
-
"test": "cross-env NODE_ENV=TEST jest",
|
|
89
|
-
"type": "tsc --noEmit",
|
|
90
|
-
"format": "npm-run-all -s format:*",
|
|
91
|
-
"format:fix": "prettier --write './**/*.{ts,tsx,js,jsx,json}'",
|
|
92
|
-
"format:lint": "eslint ./ --ext .ts,.tsx",
|
|
93
|
-
"clean": "rimraf ./dist",
|
|
94
|
-
"storybook": "storybook dev -p 6006",
|
|
95
|
-
"storybook:build": "storybook build",
|
|
96
|
-
"storybook:static": "gh-pages -d storybook-static",
|
|
97
|
-
"storybook:deploy": "npm-run-all -s storybook:build storybook:static"
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
+
"packageManager": "pnpm@10.33.0+sha512.10568bb4a6afb58c9eb3630da90cc9516417abebd3fabbe6739f0ae795728da1491e9db5a544c76ad8eb7570f5c4bb3d6c637b2cb41bfdcdb47fa823c8649319"
|
|
101
|
+
}
|