use-tus 0.2.5 → 0.5.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 +201 -14
- package/dist/TusClientProvider/TusClientProvider.d.ts +4 -4
- package/dist/TusClientProvider/TusController.d.ts +4 -4
- package/dist/TusClientProvider/index.d.ts +2 -2
- package/dist/__stories__/Basic.stories.d.ts +5 -0
- package/dist/__stories__/CacheKey.stories.d.ts +5 -0
- package/dist/__stories__/DefaultOptions.stories.d.ts +5 -0
- package/dist/__stories__/components/BasicButton/BasicButton.d.ts +9 -0
- package/dist/__stories__/components/BasicButton/index.d.ts +1 -0
- package/dist/__stories__/components/LoadingCircle/LoadingCircle.d.ts +2 -0
- package/dist/__stories__/components/LoadingCircle/index.d.ts +1 -0
- package/dist/__stories__/components/ProgressBar/ProgressBar.d.ts +7 -0
- package/dist/__stories__/components/ProgressBar/index.d.ts +1 -0
- package/dist/__stories__/components/UploadIcon/UploadIcon.d.ts +2 -0
- package/dist/__stories__/components/UploadIcon/index.d.ts +1 -0
- package/dist/__stories__/constants.d.ts +1 -0
- package/dist/__tests__/TusClientProvider.test.d.ts +1 -0
- package/dist/__tests__/useTus.test.d.ts +1 -0
- package/dist/__tests__/utils/getBlob.d.ts +1 -0
- package/dist/__tests__/utils/mock.d.ts +5 -0
- package/dist/core/constants.d.ts +4 -4
- package/dist/core/contexts.d.ts +7 -7
- package/dist/core/tucClientActions.d.ts +50 -47
- package/dist/core/tusClientReducer.d.ts +18 -18
- package/dist/core/tusHandler.d.ts +17 -11
- package/dist/core/types.d.ts +8 -8
- package/dist/index.cjs.js +64 -1432
- package/dist/index.d.ts +4 -3
- package/dist/index.esm.js +51 -1416
- package/dist/index.js +385 -0
- package/dist/useTus/index.d.ts +2 -2
- package/dist/useTus/types.d.ts +15 -15
- package/dist/useTus/useTus.d.ts +2 -2
- package/dist/useTus/utils.d.ts +16 -16
- package/dist/useTusClient/index.d.ts +1 -0
- package/dist/useTusClient/useTusClient.d.ts +7 -0
- package/dist/utils/uid.d.ts +1 -1
- package/package.json +7 -7
package/dist/index.js
ADDED
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { createContext, useMemo, useContext, useState, useCallback, useEffect, createElement, Fragment, useReducer } from 'react';
|
|
2
|
+
import * as tus from 'tus-js-client';
|
|
3
|
+
import { Upload } from 'tus-js-client';
|
|
4
|
+
|
|
5
|
+
const ERROR_MESSAGES = {
|
|
6
|
+
tusClientHasNotFounded: 'No TusClient set, use TusClientProvider to set one',
|
|
7
|
+
tusIsNotSupported: 'This browser does not support uploads. Please use a modern browser instead.',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const TusClientStateContext = createContext(undefined);
|
|
11
|
+
const TusClientDispatchContext = createContext(undefined);
|
|
12
|
+
const useTusClientState = () => {
|
|
13
|
+
const tusClientState = useContext(TusClientStateContext);
|
|
14
|
+
if (!tusClientState && process.env.NODE_ENV !== 'production') {
|
|
15
|
+
throw new Error(ERROR_MESSAGES.tusClientHasNotFounded);
|
|
16
|
+
}
|
|
17
|
+
return useMemo(() => tusClientState, [tusClientState]);
|
|
18
|
+
};
|
|
19
|
+
const useTusClientDispatch = () => {
|
|
20
|
+
const tusClientDispatch = useContext(TusClientDispatchContext);
|
|
21
|
+
if (!tusClientDispatch && process.env.NODE_ENV !== 'production') {
|
|
22
|
+
throw new Error(ERROR_MESSAGES.tusClientHasNotFounded);
|
|
23
|
+
}
|
|
24
|
+
return useMemo(() => tusClientDispatch, [
|
|
25
|
+
tusClientDispatch,
|
|
26
|
+
]);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const insertUploadInstance = (cacheKey, upload) => ({
|
|
30
|
+
type: 'INSERT_UPLOAD_INSTANCE',
|
|
31
|
+
payload: {
|
|
32
|
+
cacheKey,
|
|
33
|
+
uploadState: {
|
|
34
|
+
upload,
|
|
35
|
+
isSuccess: false,
|
|
36
|
+
isAborted: false,
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
});
|
|
40
|
+
const updateSuccessUpload = (cacheKey) => ({
|
|
41
|
+
type: 'UPDATE_SUCCESS_UPLOAD',
|
|
42
|
+
payload: {
|
|
43
|
+
cacheKey,
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
const updateErrorUpload = (cacheKey, error) => ({
|
|
47
|
+
type: 'UPDATE_ERROR_UPLOAD',
|
|
48
|
+
payload: {
|
|
49
|
+
cacheKey,
|
|
50
|
+
error,
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
const updateIsAbortedUpload = (cacheKey, isAborted) => ({
|
|
54
|
+
type: 'UPDATE_IS_ABORTED_UPLOAD',
|
|
55
|
+
payload: {
|
|
56
|
+
cacheKey,
|
|
57
|
+
isAborted,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
const removeUploadInstance = (cacheKey) => ({
|
|
61
|
+
type: 'REMOVE_UPLOAD_INSTANCE',
|
|
62
|
+
payload: {
|
|
63
|
+
cacheKey,
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
const updateTusHandlerOptions = (payload) => ({
|
|
67
|
+
type: 'UPDATE_TUS_HANDLER_OPTIONS',
|
|
68
|
+
payload,
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const createOptionHandler = (handlers, { dispatch, internalDispatch, cacheKey }) => {
|
|
72
|
+
const onSuccess = () => {
|
|
73
|
+
if (cacheKey) {
|
|
74
|
+
dispatch(updateSuccessUpload(cacheKey));
|
|
75
|
+
}
|
|
76
|
+
if (!cacheKey) {
|
|
77
|
+
internalDispatch((internalTusState) => ({
|
|
78
|
+
...internalTusState,
|
|
79
|
+
isSuccess: true,
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
if (handlers.onSuccess) {
|
|
83
|
+
handlers.onSuccess();
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const onError = (err) => {
|
|
87
|
+
if (cacheKey) {
|
|
88
|
+
dispatch(updateErrorUpload(cacheKey, err));
|
|
89
|
+
}
|
|
90
|
+
if (!cacheKey) {
|
|
91
|
+
internalDispatch((internalTusState) => ({
|
|
92
|
+
...internalTusState,
|
|
93
|
+
error: err,
|
|
94
|
+
}));
|
|
95
|
+
}
|
|
96
|
+
if (handlers.onError) {
|
|
97
|
+
handlers.onError(err);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return {
|
|
101
|
+
onSuccess,
|
|
102
|
+
onError,
|
|
103
|
+
};
|
|
104
|
+
};
|
|
105
|
+
const startOrResumeUpload = (upload) => {
|
|
106
|
+
upload.findPreviousUploads().then((previousUploads) => {
|
|
107
|
+
if (previousUploads.length) {
|
|
108
|
+
upload.resumeFromPreviousUpload(previousUploads[0]);
|
|
109
|
+
}
|
|
110
|
+
upload.start();
|
|
111
|
+
});
|
|
112
|
+
};
|
|
113
|
+
const createUpload = (file, options, { dispatch, internalDispatch, cacheKey }) => {
|
|
114
|
+
const upload = new Upload(file, options);
|
|
115
|
+
const originalStart = upload.start.bind(upload);
|
|
116
|
+
const originalAbort = upload.abort.bind(upload);
|
|
117
|
+
const dispatchIsAborted = (isAborted) => {
|
|
118
|
+
if (cacheKey) {
|
|
119
|
+
dispatch(updateIsAbortedUpload(cacheKey, isAborted));
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
internalDispatch((internalTusState) => ({
|
|
123
|
+
...internalTusState,
|
|
124
|
+
isAborted,
|
|
125
|
+
}));
|
|
126
|
+
};
|
|
127
|
+
const start = () => {
|
|
128
|
+
originalStart();
|
|
129
|
+
dispatchIsAborted(false);
|
|
130
|
+
};
|
|
131
|
+
const abort = async () => {
|
|
132
|
+
originalAbort();
|
|
133
|
+
dispatchIsAborted(true);
|
|
134
|
+
};
|
|
135
|
+
upload.start = start;
|
|
136
|
+
upload.abort = abort;
|
|
137
|
+
return upload;
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
const defaultUseTusOptionsValue = Object.freeze({
|
|
141
|
+
cacheKey: undefined,
|
|
142
|
+
autoAbort: true,
|
|
143
|
+
autoStart: false,
|
|
144
|
+
});
|
|
145
|
+
const initialUseTusState = Object.freeze({
|
|
146
|
+
upload: undefined,
|
|
147
|
+
isSuccess: false,
|
|
148
|
+
isAborted: false,
|
|
149
|
+
error: undefined,
|
|
150
|
+
});
|
|
151
|
+
const useTus = (useTusOptions) => {
|
|
152
|
+
const { cacheKey, autoAbort, autoStart } = {
|
|
153
|
+
...defaultUseTusOptionsValue,
|
|
154
|
+
...(useTusOptions || {}),
|
|
155
|
+
};
|
|
156
|
+
const [internalTusState, setInternalTusState] = useState(initialUseTusState);
|
|
157
|
+
const tusClientState = useTusClientState();
|
|
158
|
+
const tusClientDispatch = useTusClientDispatch();
|
|
159
|
+
const tus = tusClientState.tusHandler.getTus;
|
|
160
|
+
const setUpload = useCallback((file, options = {}) => {
|
|
161
|
+
const dispatcher = {
|
|
162
|
+
cacheKey,
|
|
163
|
+
dispatch: tusClientDispatch,
|
|
164
|
+
internalDispatch: setInternalTusState,
|
|
165
|
+
};
|
|
166
|
+
const targetOptions = {
|
|
167
|
+
...tus.defaultOptions(file),
|
|
168
|
+
...options,
|
|
169
|
+
};
|
|
170
|
+
const { onSuccess, onError } = createOptionHandler({
|
|
171
|
+
onError: targetOptions.onError,
|
|
172
|
+
onSuccess: targetOptions.onSuccess,
|
|
173
|
+
}, dispatcher);
|
|
174
|
+
const uploadOptions = {
|
|
175
|
+
...targetOptions,
|
|
176
|
+
onSuccess,
|
|
177
|
+
onError,
|
|
178
|
+
};
|
|
179
|
+
const upload = createUpload(file, uploadOptions, dispatcher);
|
|
180
|
+
if (autoStart) {
|
|
181
|
+
startOrResumeUpload(upload);
|
|
182
|
+
}
|
|
183
|
+
if (cacheKey) {
|
|
184
|
+
tusClientDispatch(insertUploadInstance(cacheKey, upload));
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
setInternalTusState({
|
|
188
|
+
...initialUseTusState,
|
|
189
|
+
upload,
|
|
190
|
+
});
|
|
191
|
+
}, [tusClientDispatch, cacheKey, tus, autoStart]);
|
|
192
|
+
const targetTusState = useMemo(() => (cacheKey ? tusClientState.uploads[cacheKey] : internalTusState), [cacheKey, tusClientState, internalTusState]);
|
|
193
|
+
const remove = useCallback(() => {
|
|
194
|
+
targetTusState?.upload?.abort();
|
|
195
|
+
if (!cacheKey) {
|
|
196
|
+
setInternalTusState(initialUseTusState);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
tusClientDispatch(removeUploadInstance(cacheKey));
|
|
200
|
+
}, [targetTusState, tusClientDispatch, cacheKey]);
|
|
201
|
+
const tusResult = useMemo(() => ({
|
|
202
|
+
upload: targetTusState?.upload,
|
|
203
|
+
isSuccess: targetTusState?.isSuccess ?? false,
|
|
204
|
+
error: targetTusState?.error,
|
|
205
|
+
isAborted: targetTusState?.isAborted ?? false,
|
|
206
|
+
setUpload,
|
|
207
|
+
remove,
|
|
208
|
+
}), [targetTusState, setUpload, remove]);
|
|
209
|
+
// For autoAbort option
|
|
210
|
+
useEffect(() => {
|
|
211
|
+
const abortUploading = async () => {
|
|
212
|
+
if (!tusResult.upload) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
await tusResult.upload.abort();
|
|
216
|
+
};
|
|
217
|
+
return () => {
|
|
218
|
+
if (!autoAbort) {
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
abortUploading();
|
|
222
|
+
};
|
|
223
|
+
}, [autoAbort, tusResult.upload]);
|
|
224
|
+
return tusResult;
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
const initialDefaultOptions = () => tus.defaultOptions;
|
|
228
|
+
class TusHandler {
|
|
229
|
+
constructor(tusConfigs) {
|
|
230
|
+
const { canStoreURLs = tus.canStoreURLs, defaultOptions = initialDefaultOptions, } = tusConfigs || {};
|
|
231
|
+
this.tus = {
|
|
232
|
+
...tus,
|
|
233
|
+
canStoreURLs,
|
|
234
|
+
defaultOptions,
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
get getTus() {
|
|
238
|
+
return this.tus;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const tusClientReducer = (state, actions) => {
|
|
243
|
+
switch (actions.type) {
|
|
244
|
+
case 'INSERT_UPLOAD_INSTANCE': {
|
|
245
|
+
const { cacheKey, uploadState } = actions.payload;
|
|
246
|
+
return {
|
|
247
|
+
...state,
|
|
248
|
+
uploads: {
|
|
249
|
+
...state.uploads,
|
|
250
|
+
[cacheKey]: uploadState,
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
case 'UPDATE_SUCCESS_UPLOAD': {
|
|
255
|
+
const { cacheKey } = actions.payload;
|
|
256
|
+
const target = state.uploads[cacheKey];
|
|
257
|
+
if (!target) {
|
|
258
|
+
return state;
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
...state,
|
|
262
|
+
uploads: {
|
|
263
|
+
...state.uploads,
|
|
264
|
+
[cacheKey]: {
|
|
265
|
+
...(target || {}),
|
|
266
|
+
isSuccess: true,
|
|
267
|
+
},
|
|
268
|
+
},
|
|
269
|
+
};
|
|
270
|
+
}
|
|
271
|
+
case 'UPDATE_ERROR_UPLOAD': {
|
|
272
|
+
const { cacheKey, error } = actions.payload;
|
|
273
|
+
const target = state.uploads[cacheKey];
|
|
274
|
+
if (!target) {
|
|
275
|
+
return state;
|
|
276
|
+
}
|
|
277
|
+
return {
|
|
278
|
+
...state,
|
|
279
|
+
uploads: {
|
|
280
|
+
...state.uploads,
|
|
281
|
+
[cacheKey]: {
|
|
282
|
+
...target,
|
|
283
|
+
error,
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
case 'UPDATE_IS_ABORTED_UPLOAD': {
|
|
289
|
+
const { cacheKey, isAborted } = actions.payload;
|
|
290
|
+
const target = state.uploads[cacheKey];
|
|
291
|
+
if (!target) {
|
|
292
|
+
return state;
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
...state,
|
|
296
|
+
uploads: {
|
|
297
|
+
...state.uploads,
|
|
298
|
+
[cacheKey]: {
|
|
299
|
+
...target,
|
|
300
|
+
isAborted,
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
case 'REMOVE_UPLOAD_INSTANCE': {
|
|
306
|
+
const { cacheKey } = actions.payload;
|
|
307
|
+
const newUploads = state.uploads;
|
|
308
|
+
delete newUploads[cacheKey];
|
|
309
|
+
return {
|
|
310
|
+
...state,
|
|
311
|
+
uploads: newUploads,
|
|
312
|
+
};
|
|
313
|
+
}
|
|
314
|
+
case 'RESET_CLIENT': {
|
|
315
|
+
return {
|
|
316
|
+
tusHandler: new TusHandler(),
|
|
317
|
+
uploads: {},
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
case 'UPDATE_TUS_HANDLER_OPTIONS': {
|
|
321
|
+
const { canStoreURLs, defaultOptions } = actions.payload;
|
|
322
|
+
return {
|
|
323
|
+
...state,
|
|
324
|
+
tusHandler: new TusHandler({
|
|
325
|
+
canStoreURLs,
|
|
326
|
+
defaultOptions,
|
|
327
|
+
}),
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
default:
|
|
331
|
+
return state;
|
|
332
|
+
}
|
|
333
|
+
};
|
|
334
|
+
const tusClientInitialState = {
|
|
335
|
+
uploads: {},
|
|
336
|
+
tusHandler: new TusHandler(),
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
const TusController = ({ canStoreURLs, defaultOptions = initialDefaultOptions, children, }) => {
|
|
340
|
+
const { tusHandler } = useTusClientState();
|
|
341
|
+
const tus = tusHandler.getTus;
|
|
342
|
+
const tusClientDispatch = useTusClientDispatch();
|
|
343
|
+
useEffect(() => {
|
|
344
|
+
if (tusHandler.getTus.isSupported ||
|
|
345
|
+
process.env.NODE_ENV === 'production') {
|
|
346
|
+
return;
|
|
347
|
+
}
|
|
348
|
+
// eslint-disable-next-line no-console
|
|
349
|
+
console.error(ERROR_MESSAGES.tusIsNotSupported);
|
|
350
|
+
}, [tusHandler.getTus.isSupported]);
|
|
351
|
+
useEffect(() => {
|
|
352
|
+
if (tus.defaultOptions === defaultOptions &&
|
|
353
|
+
tus.canStoreURLs === canStoreURLs) {
|
|
354
|
+
return;
|
|
355
|
+
}
|
|
356
|
+
tusClientDispatch(updateTusHandlerOptions({ canStoreURLs, defaultOptions }));
|
|
357
|
+
}, [
|
|
358
|
+
tusClientDispatch,
|
|
359
|
+
canStoreURLs,
|
|
360
|
+
defaultOptions,
|
|
361
|
+
tus.canStoreURLs,
|
|
362
|
+
tus.defaultOptions,
|
|
363
|
+
]);
|
|
364
|
+
return createElement(Fragment, {}, children);
|
|
365
|
+
};
|
|
366
|
+
|
|
367
|
+
const TusClientProvider = ({ canStoreURLs, defaultOptions, children, }) => {
|
|
368
|
+
const [tusClientState, tusClientDispatch] = useReducer(tusClientReducer, {
|
|
369
|
+
...tusClientInitialState,
|
|
370
|
+
tusHandler: new TusHandler({
|
|
371
|
+
canStoreURLs,
|
|
372
|
+
defaultOptions,
|
|
373
|
+
}),
|
|
374
|
+
});
|
|
375
|
+
const tusControllerElement = createElement(TusController, {
|
|
376
|
+
canStoreURLs,
|
|
377
|
+
defaultOptions,
|
|
378
|
+
}, children);
|
|
379
|
+
const tusClientDispatchContextProviderElement = createElement(TusClientDispatchContext.Provider, { value: tusClientDispatch }, tusControllerElement);
|
|
380
|
+
return createElement(TusClientStateContext.Provider, {
|
|
381
|
+
value: tusClientState,
|
|
382
|
+
}, tusClientDispatchContextProviderElement);
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
export { TusClientProvider, useTus };
|
package/dist/useTus/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { useTus } from './useTus';
|
|
2
|
-
export type { UseTusResult, UseTusOptions } from './types';
|
|
1
|
+
export { useTus } from './useTus';
|
|
2
|
+
export type { UseTusResult, UseTusOptions } from './types';
|
package/dist/useTus/types.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type { Upload } from 'tus-js-client';
|
|
2
|
-
export declare type UseTusOptions = {
|
|
3
|
-
cacheKey?: string;
|
|
4
|
-
autoAbort?: boolean;
|
|
5
|
-
autoStart?: boolean;
|
|
6
|
-
};
|
|
7
|
-
export declare type UseTusResult = {
|
|
8
|
-
upload?: Upload;
|
|
9
|
-
setUpload: (file: Upload['file'], options?: Upload['options']) => void;
|
|
10
|
-
remove: () => void;
|
|
11
|
-
isSuccess: boolean;
|
|
12
|
-
isAborted: boolean;
|
|
13
|
-
error?: Error;
|
|
14
|
-
};
|
|
15
|
-
export declare type UseTusState = Pick<UseTusResult, 'upload' | 'isSuccess' | 'error' | 'isAborted'>;
|
|
1
|
+
import type { Upload } from 'tus-js-client';
|
|
2
|
+
export declare type UseTusOptions = {
|
|
3
|
+
cacheKey?: string;
|
|
4
|
+
autoAbort?: boolean;
|
|
5
|
+
autoStart?: boolean;
|
|
6
|
+
};
|
|
7
|
+
export declare type UseTusResult = {
|
|
8
|
+
upload?: Upload;
|
|
9
|
+
setUpload: (file: Upload['file'], options?: Upload['options']) => void;
|
|
10
|
+
remove: () => void;
|
|
11
|
+
isSuccess: boolean;
|
|
12
|
+
isAborted: boolean;
|
|
13
|
+
error?: Error;
|
|
14
|
+
};
|
|
15
|
+
export declare type UseTusState = Pick<UseTusResult, 'upload' | 'isSuccess' | 'error' | 'isAborted'>;
|
package/dist/useTus/useTus.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { UseTusOptions, UseTusResult } from './types';
|
|
2
|
-
export declare const useTus: (useTusOptions?: UseTusOptions | undefined) => UseTusResult;
|
|
1
|
+
import { UseTusOptions, UseTusResult } from './types';
|
|
2
|
+
export declare const useTus: (useTusOptions?: UseTusOptions | undefined) => UseTusResult;
|
package/dist/useTus/utils.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { SetStateAction } from 'react';
|
|
2
|
-
import { Upload } from 'tus-js-client';
|
|
3
|
-
import { TusClientActions } from '../core/tucClientActions';
|
|
4
|
-
import { UseTusOptions, UseTusState } from './types';
|
|
5
|
-
export declare type Dispatcher = {
|
|
6
|
-
dispatch: (value: TusClientActions) => void;
|
|
7
|
-
internalDispatch: (value: SetStateAction<UseTusState>) => void;
|
|
8
|
-
cacheKey: UseTusOptions['cacheKey'];
|
|
9
|
-
};
|
|
10
|
-
declare type OptionHandler = Pick<Upload['options'], 'onError' | 'onSuccess'>;
|
|
11
|
-
declare type CreateUpload = (file: Upload['file'], options: Upload['options'], dispatcher: Dispatcher) => Upload;
|
|
12
|
-
declare type CreateOptionHandler = (handlers: OptionHandler, dispatcher: Dispatcher) => OptionHandler;
|
|
13
|
-
export declare const createOptionHandler: CreateOptionHandler;
|
|
14
|
-
export declare const startOrResumeUpload: (upload: Upload) => void;
|
|
15
|
-
export declare const createUpload: CreateUpload;
|
|
16
|
-
export {};
|
|
1
|
+
import { SetStateAction } from 'react';
|
|
2
|
+
import { Upload } from 'tus-js-client';
|
|
3
|
+
import { TusClientActions } from '../core/tucClientActions';
|
|
4
|
+
import { UseTusOptions, UseTusState } from './types';
|
|
5
|
+
export declare type Dispatcher = {
|
|
6
|
+
dispatch: (value: TusClientActions) => void;
|
|
7
|
+
internalDispatch: (value: SetStateAction<UseTusState>) => void;
|
|
8
|
+
cacheKey: UseTusOptions['cacheKey'];
|
|
9
|
+
};
|
|
10
|
+
declare type OptionHandler = Pick<Upload['options'], 'onError' | 'onSuccess'>;
|
|
11
|
+
declare type CreateUpload = (file: Upload['file'], options: Upload['options'], dispatcher: Dispatcher) => Upload;
|
|
12
|
+
declare type CreateOptionHandler = (handlers: OptionHandler, dispatcher: Dispatcher) => OptionHandler;
|
|
13
|
+
export declare const createOptionHandler: CreateOptionHandler;
|
|
14
|
+
export declare const startOrResumeUpload: (upload: Upload) => void;
|
|
15
|
+
export declare const createUpload: CreateUpload;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useTusClient } from './useTusClient';
|
package/dist/utils/uid.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const createUid: () => string;
|
|
1
|
+
export declare const createUid: () => string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "use-tus",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
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",
|
|
@@ -53,6 +53,7 @@
|
|
|
53
53
|
"@rollup/plugin-babel": "^5.3.0",
|
|
54
54
|
"@rollup/plugin-commonjs": "^18.0.0",
|
|
55
55
|
"@rollup/plugin-node-resolve": "^11.2.1",
|
|
56
|
+
"@rollup/plugin-typescript": "^8.3.0",
|
|
56
57
|
"@storybook/addon-actions": "^6.2.9",
|
|
57
58
|
"@storybook/addon-essentials": "^6.2.9",
|
|
58
59
|
"@storybook/addon-links": "^6.2.9",
|
|
@@ -90,15 +91,14 @@
|
|
|
90
91
|
"react-dom": "^17.0.2",
|
|
91
92
|
"rimraf": "^3.0.2",
|
|
92
93
|
"rollup": "^2.44.0",
|
|
93
|
-
"rollup-plugin-typescript2": "^0.30.0",
|
|
94
94
|
"tailwindcss": "npm:@tailwindcss/postcss7-compat",
|
|
95
95
|
"ts-jest": "^26.5.4",
|
|
96
|
-
"typescript": "^4.2.3"
|
|
96
|
+
"typescript": "^4.2.3",
|
|
97
|
+
"tus-js-client": "^2.2.0"
|
|
97
98
|
},
|
|
98
99
|
"peerDependencies": {
|
|
99
|
-
"react": "^16.8.0 || ^17.0.0"
|
|
100
|
-
},
|
|
101
|
-
"dependencies": {
|
|
100
|
+
"react": "^16.8.0 || ^17.0.0",
|
|
102
101
|
"tus-js-client": "^2.2.0"
|
|
103
|
-
}
|
|
102
|
+
},
|
|
103
|
+
"dependencies": {}
|
|
104
104
|
}
|