use-tus 0.3.0 → 0.6.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.
Files changed (47) hide show
  1. package/README.md +90 -33
  2. package/dist/TusClientProvider/TusClientProvider.d.ts +6 -4
  3. package/dist/TusClientProvider/constants.d.ts +4 -0
  4. package/dist/TusClientProvider/index.d.ts +3 -2
  5. package/dist/{core → TusClientProvider/store}/contexts.d.ts +7 -7
  6. package/dist/{core → TusClientProvider/store}/tucClientActions.d.ts +49 -47
  7. package/dist/{core → TusClientProvider/store}/tusClientReducer.d.ts +18 -18
  8. package/dist/TusClientProvider/types.d.ts +2 -0
  9. package/dist/__stories__/Basic.stories.d.ts +5 -0
  10. package/dist/__stories__/CacheKey.stories.d.ts +5 -0
  11. package/dist/__stories__/DefaultOptions.stories.d.ts +5 -0
  12. package/dist/__stories__/components/BasicButton/BasicButton.d.ts +9 -0
  13. package/dist/__stories__/components/BasicButton/index.d.ts +1 -0
  14. package/dist/__stories__/components/LoadingCircle/LoadingCircle.d.ts +2 -0
  15. package/dist/__stories__/components/LoadingCircle/index.d.ts +1 -0
  16. package/dist/__stories__/components/ProgressBar/ProgressBar.d.ts +7 -0
  17. package/dist/__stories__/components/ProgressBar/index.d.ts +1 -0
  18. package/dist/__stories__/components/UploadIcon/UploadIcon.d.ts +2 -0
  19. package/dist/__stories__/components/UploadIcon/index.d.ts +1 -0
  20. package/dist/__stories__/constants.d.ts +1 -0
  21. package/dist/__tests__/TusClientProvider.test.d.ts +1 -0
  22. package/dist/__tests__/useTus.test.d.ts +1 -0
  23. package/dist/__tests__/useTusStore.test.d.ts +1 -0
  24. package/dist/__tests__/utils/getBlob.d.ts +1 -0
  25. package/dist/__tests__/utils/getDefaultOptions.d.ts +2 -0
  26. package/dist/__tests__/utils/mock.d.ts +6 -0
  27. package/dist/index.cjs.js +289 -1751
  28. package/dist/index.d.ts +3 -4
  29. package/dist/index.esm.js +280 -1719
  30. package/dist/index.js +345 -0
  31. package/dist/useTus/index.d.ts +3 -2
  32. package/dist/useTus/types.d.ts +14 -15
  33. package/dist/useTus/useTus.d.ts +2 -2
  34. package/dist/useTus/useTusStore.d.ts +2 -0
  35. package/dist/useTus/utils/createUpload.d.ts +3 -0
  36. package/dist/useTus/utils/startOrResumeUpload.d.ts +2 -0
  37. package/dist/useTus/utils/useAutoAbort.d.ts +2 -0
  38. package/dist/useTus/utils/useMergeTusOptions.d.ts +6 -0
  39. package/dist/useTusClient/index.d.ts +1 -0
  40. package/dist/useTusClient/useTusClient.d.ts +7 -0
  41. package/package.json +9 -9
  42. package/dist/TusClientProvider/TusController.d.ts +0 -4
  43. package/dist/core/constants.d.ts +0 -4
  44. package/dist/core/tusHandler.d.ts +0 -17
  45. package/dist/core/types.d.ts +0 -8
  46. package/dist/useTus/utils.d.ts +0 -16
  47. package/dist/utils/uid.d.ts +0 -1
package/dist/index.esm.js CHANGED
@@ -1,22 +1,5 @@
1
- import f, { useMemo, createContext, useContext, useState, useCallback, useEffect, useReducer } from 'react';
2
- import * as tus from 'tus-js-client';
3
- import { Upload } from 'tus-js-client';
4
-
5
- function _typeof(obj) {
6
- "@babel/helpers - typeof";
7
-
8
- if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
9
- _typeof = function (obj) {
10
- return typeof obj;
11
- };
12
- } else {
13
- _typeof = function (obj) {
14
- return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
15
- };
16
- }
17
-
18
- return _typeof(obj);
19
- }
1
+ import { useEffect, useMemo, useState, useCallback, createContext, useContext, useReducer, createElement } from 'react';
2
+ import { Upload, isSupported } from 'tus-js-client';
20
3
 
21
4
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
22
5
  try {
@@ -54,28 +37,6 @@ function _asyncToGenerator(fn) {
54
37
  };
55
38
  }
56
39
 
57
- function _classCallCheck(instance, Constructor) {
58
- if (!(instance instanceof Constructor)) {
59
- throw new TypeError("Cannot call a class as a function");
60
- }
61
- }
62
-
63
- function _defineProperties(target, props) {
64
- for (var i = 0; i < props.length; i++) {
65
- var descriptor = props[i];
66
- descriptor.enumerable = descriptor.enumerable || false;
67
- descriptor.configurable = true;
68
- if ("value" in descriptor) descriptor.writable = true;
69
- Object.defineProperty(target, descriptor.key, descriptor);
70
- }
71
- }
72
-
73
- function _createClass(Constructor, protoProps, staticProps) {
74
- if (protoProps) _defineProperties(Constructor.prototype, protoProps);
75
- if (staticProps) _defineProperties(Constructor, staticProps);
76
- return Constructor;
77
- }
78
-
79
40
  function _defineProperty(obj, key, value) {
80
41
  if (key in obj) {
81
42
  Object.defineProperty(obj, key, {
@@ -181,17 +142,204 @@ function _nonIterableRest() {
181
142
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
182
143
  }
183
144
 
145
+ var createUpload = function createUpload(file, options, dispatchIsAborted) {
146
+ var upload = new Upload(file, options);
147
+ var originalStart = upload.start.bind(upload);
148
+ var originalAbort = upload.abort.bind(upload);
149
+
150
+ var start = function start() {
151
+ originalStart();
152
+ dispatchIsAborted(false);
153
+ };
154
+
155
+ var abort = function () {
156
+ var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
157
+ return regeneratorRuntime.wrap(function _callee$(_context) {
158
+ while (1) {
159
+ switch (_context.prev = _context.next) {
160
+ case 0:
161
+ originalAbort();
162
+ dispatchIsAborted(true);
163
+
164
+ case 2:
165
+ case "end":
166
+ return _context.stop();
167
+ }
168
+ }
169
+ }, _callee);
170
+ }));
171
+
172
+ return function abort() {
173
+ return _ref.apply(this, arguments);
174
+ };
175
+ }();
176
+
177
+ upload.start = start;
178
+ upload.abort = abort;
179
+ return upload;
180
+ };
181
+
182
+ var startOrResumeUpload = function startOrResumeUpload(upload) {
183
+ upload.findPreviousUploads().then(function (previousUploads) {
184
+ if (previousUploads.length) {
185
+ upload.resumeFromPreviousUpload(previousUploads[0]);
186
+ }
187
+
188
+ upload.start();
189
+ });
190
+ };
191
+
192
+ var useAutoAbort = function useAutoAbort(upload, autoAbort) {
193
+ useEffect(function () {
194
+ var abortUploading = function () {
195
+ var _ref = _asyncToGenerator(regeneratorRuntime.mark(function _callee() {
196
+ return regeneratorRuntime.wrap(function _callee$(_context) {
197
+ while (1) {
198
+ switch (_context.prev = _context.next) {
199
+ case 0:
200
+ if (upload) {
201
+ _context.next = 2;
202
+ break;
203
+ }
204
+
205
+ return _context.abrupt("return");
206
+
207
+ case 2:
208
+ _context.next = 4;
209
+ return upload.abort();
210
+
211
+ case 4:
212
+ case "end":
213
+ return _context.stop();
214
+ }
215
+ }
216
+ }, _callee);
217
+ }));
218
+
219
+ return function abortUploading() {
220
+ return _ref.apply(this, arguments);
221
+ };
222
+ }();
223
+
224
+ return function () {
225
+ if (!autoAbort) {
226
+ return;
227
+ }
228
+
229
+ abortUploading();
230
+ };
231
+ }, [autoAbort, upload]);
232
+ };
233
+
234
+ var defaultUseTusOptionsValue = Object.freeze({
235
+ autoAbort: true,
236
+ autoStart: false
237
+ });
238
+ var useMergeTusOptions = function useMergeTusOptions(options) {
239
+ return useMemo(function () {
240
+ return _objectSpread2(_objectSpread2({}, defaultUseTusOptionsValue), options || {});
241
+ }, [options]);
242
+ };
243
+
244
+ var initialUseTusState = Object.freeze({
245
+ upload: undefined,
246
+ isSuccess: false,
247
+ isAborted: false,
248
+ error: undefined
249
+ });
250
+ var useTus = function useTus(baseOption) {
251
+ var _useMergeTusOptions = useMergeTusOptions(baseOption),
252
+ autoAbort = _useMergeTusOptions.autoAbort,
253
+ autoStart = _useMergeTusOptions.autoStart,
254
+ uploadOptions = _useMergeTusOptions.uploadOptions;
255
+
256
+ var _useState = useState(initialUseTusState),
257
+ _useState2 = _slicedToArray(_useState, 2),
258
+ tusState = _useState2[0],
259
+ setTusState = _useState2[1];
260
+
261
+ var updateTusState = useCallback(function (newOptions) {
262
+ setTusState(function (tus) {
263
+ return _objectSpread2(_objectSpread2({}, tus), newOptions);
264
+ });
265
+ }, []);
266
+ var setUpload = useCallback(function (file) {
267
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
268
+
269
+ var targetOptions = _objectSpread2(_objectSpread2({}, uploadOptions), options);
270
+
271
+ var onSuccess = function onSuccess() {
272
+ var _targetOptions$onSucc;
273
+
274
+ updateTusState({
275
+ isSuccess: true
276
+ });
277
+ targetOptions === null || targetOptions === void 0 ? void 0 : (_targetOptions$onSucc = targetOptions.onSuccess) === null || _targetOptions$onSucc === void 0 ? void 0 : _targetOptions$onSucc.call(targetOptions);
278
+ };
279
+
280
+ var onError = function onError(error) {
281
+ var _targetOptions$onErro;
282
+
283
+ updateTusState({
284
+ error: error
285
+ });
286
+ targetOptions === null || targetOptions === void 0 ? void 0 : (_targetOptions$onErro = targetOptions.onError) === null || _targetOptions$onErro === void 0 ? void 0 : _targetOptions$onErro.call(targetOptions, error);
287
+ };
288
+
289
+ var mergedUploadOptions = _objectSpread2(_objectSpread2({}, targetOptions), {}, {
290
+ onSuccess: onSuccess,
291
+ onError: onError
292
+ });
293
+
294
+ var dispatchIsAborted = function dispatchIsAborted(isAborted) {
295
+ updateTusState({
296
+ isAborted: isAborted
297
+ });
298
+ };
299
+
300
+ var upload = createUpload(file, mergedUploadOptions, dispatchIsAborted);
301
+
302
+ if (autoStart) {
303
+ startOrResumeUpload(upload);
304
+ }
305
+
306
+ updateTusState({
307
+ upload: upload
308
+ });
309
+ }, [autoStart, updateTusState, uploadOptions]);
310
+ var remove = useCallback(function () {
311
+ var _tusState$upload;
312
+
313
+ tusState === null || tusState === void 0 ? void 0 : (_tusState$upload = tusState.upload) === null || _tusState$upload === void 0 ? void 0 : _tusState$upload.abort();
314
+ setTusState(initialUseTusState);
315
+ }, [tusState === null || tusState === void 0 ? void 0 : tusState.upload]);
316
+ var tusResult = useMemo(function () {
317
+ var _tusState$isSuccess, _tusState$isAborted;
318
+
319
+ return {
320
+ upload: tusState === null || tusState === void 0 ? void 0 : tusState.upload,
321
+ isSuccess: (_tusState$isSuccess = tusState === null || tusState === void 0 ? void 0 : tusState.isSuccess) !== null && _tusState$isSuccess !== void 0 ? _tusState$isSuccess : false,
322
+ error: tusState === null || tusState === void 0 ? void 0 : tusState.error,
323
+ isAborted: (_tusState$isAborted = tusState === null || tusState === void 0 ? void 0 : tusState.isAborted) !== null && _tusState$isAborted !== void 0 ? _tusState$isAborted : false,
324
+ setUpload: setUpload,
325
+ remove: remove
326
+ };
327
+ }, [tusState, setUpload, remove]);
328
+ useAutoAbort(tusResult.upload, autoAbort !== null && autoAbort !== void 0 ? autoAbort : false);
329
+ return tusResult;
330
+ };
331
+
184
332
  var ERROR_MESSAGES = {
185
- tusClientHasNotFounded: 'No TusClient set, use TusClientProvider to set one',
186
- tusIsNotSupported: 'This browser does not support uploads. Please use a modern browser instead.'
333
+ tusClientHasNotFounded: "No TusClient set, use TusClientProvider to set one",
334
+ tusIsNotSupported: "This browser does not support uploads. Please use a modern browser instead."
187
335
  };
188
336
 
189
- var TusClientStateContext = /*#__PURE__*/createContext(undefined);
190
- var TusClientDispatchContext = /*#__PURE__*/createContext(undefined);
337
+ var TusClientStateContext = createContext(undefined);
338
+ var TusClientDispatchContext = createContext(undefined);
191
339
  var useTusClientState = function useTusClientState() {
192
340
  var tusClientState = useContext(TusClientStateContext);
193
341
 
194
- if (!tusClientState && process.env.NODE_ENV !== 'production') {
342
+ if (!tusClientState && process.env.NODE_ENV !== "production") {
195
343
  throw new Error(ERROR_MESSAGES.tusClientHasNotFounded);
196
344
  }
197
345
 
@@ -202,7 +350,7 @@ var useTusClientState = function useTusClientState() {
202
350
  var useTusClientDispatch = function useTusClientDispatch() {
203
351
  var tusClientDispatch = useContext(TusClientDispatchContext);
204
352
 
205
- if (!tusClientDispatch && process.env.NODE_ENV !== 'production') {
353
+ if (!tusClientDispatch && process.env.NODE_ENV !== "production") {
206
354
  throw new Error(ERROR_MESSAGES.tusClientHasNotFounded);
207
355
  }
208
356
 
@@ -213,7 +361,7 @@ var useTusClientDispatch = function useTusClientDispatch() {
213
361
 
214
362
  var insertUploadInstance = function insertUploadInstance(cacheKey, upload) {
215
363
  return {
216
- type: 'INSERT_UPLOAD_INSTANCE',
364
+ type: "INSERT_UPLOAD_INSTANCE",
217
365
  payload: {
218
366
  cacheKey: cacheKey,
219
367
  uploadState: {
@@ -226,7 +374,7 @@ var insertUploadInstance = function insertUploadInstance(cacheKey, upload) {
226
374
  };
227
375
  var updateSuccessUpload = function updateSuccessUpload(cacheKey) {
228
376
  return {
229
- type: 'UPDATE_SUCCESS_UPLOAD',
377
+ type: "UPDATE_SUCCESS_UPLOAD",
230
378
  payload: {
231
379
  cacheKey: cacheKey
232
380
  }
@@ -234,7 +382,7 @@ var updateSuccessUpload = function updateSuccessUpload(cacheKey) {
234
382
  };
235
383
  var updateErrorUpload = function updateErrorUpload(cacheKey, error) {
236
384
  return {
237
- type: 'UPDATE_ERROR_UPLOAD',
385
+ type: "UPDATE_ERROR_UPLOAD",
238
386
  payload: {
239
387
  cacheKey: cacheKey,
240
388
  error: error
@@ -243,7 +391,7 @@ var updateErrorUpload = function updateErrorUpload(cacheKey, error) {
243
391
  };
244
392
  var updateIsAbortedUpload = function updateIsAbortedUpload(cacheKey, isAborted) {
245
393
  return {
246
- type: 'UPDATE_IS_ABORTED_UPLOAD',
394
+ type: "UPDATE_IS_ABORTED_UPLOAD",
247
395
  payload: {
248
396
  cacheKey: cacheKey,
249
397
  isAborted: isAborted
@@ -252,202 +400,75 @@ var updateIsAbortedUpload = function updateIsAbortedUpload(cacheKey, isAborted)
252
400
  };
253
401
  var removeUploadInstance = function removeUploadInstance(cacheKey) {
254
402
  return {
255
- type: 'REMOVE_UPLOAD_INSTANCE',
403
+ type: "REMOVE_UPLOAD_INSTANCE",
256
404
  payload: {
257
405
  cacheKey: cacheKey
258
406
  }
259
407
  };
260
408
  };
261
- var updateTusHandlerOptions = function updateTusHandlerOptions(payload) {
409
+ var updateDefaultOptions = function updateDefaultOptions(defaultOptions) {
262
410
  return {
263
- type: 'UPDATE_TUS_HANDLER_OPTIONS',
264
- payload: payload
265
- };
266
- };
267
-
268
- var createOptionHandler = function createOptionHandler(handlers, _ref) {
269
- var dispatch = _ref.dispatch,
270
- internalDispatch = _ref.internalDispatch,
271
- cacheKey = _ref.cacheKey;
272
-
273
- var onSuccess = function onSuccess() {
274
- if (cacheKey) {
275
- dispatch(updateSuccessUpload(cacheKey));
276
- }
277
-
278
- if (!cacheKey) {
279
- internalDispatch(function (internalTusState) {
280
- return _objectSpread2(_objectSpread2({}, internalTusState), {}, {
281
- isSuccess: true
282
- });
283
- });
284
- }
285
-
286
- if (handlers.onSuccess) {
287
- handlers.onSuccess();
288
- }
289
- };
290
-
291
- var onError = function onError(err) {
292
- if (cacheKey) {
293
- dispatch(updateErrorUpload(cacheKey, err));
294
- }
295
-
296
- if (!cacheKey) {
297
- internalDispatch(function (internalTusState) {
298
- return _objectSpread2(_objectSpread2({}, internalTusState), {}, {
299
- error: err
300
- });
301
- });
302
- }
303
-
304
- if (handlers.onError) {
305
- handlers.onError(err);
411
+ type: "UPDATE_DEFAULT_OPTIONS",
412
+ payload: {
413
+ defaultOptions: defaultOptions
306
414
  }
307
415
  };
308
-
309
- return {
310
- onSuccess: onSuccess,
311
- onError: onError
312
- };
313
- };
314
- var startOrResumeUpload = function startOrResumeUpload(upload) {
315
- upload.findPreviousUploads().then(function (previousUploads) {
316
- if (previousUploads.length) {
317
- upload.resumeFromPreviousUpload(previousUploads[0]);
318
- }
319
-
320
- upload.start();
321
- });
322
416
  };
323
- var createUpload = function createUpload(file, options, _ref2) {
324
- var dispatch = _ref2.dispatch,
325
- internalDispatch = _ref2.internalDispatch,
326
- cacheKey = _ref2.cacheKey;
327
- var upload = new Upload(file, options);
328
- var originalStart = upload.start.bind(upload);
329
- var originalAbort = upload.abort.bind(upload);
330
417
 
331
- var dispatchIsAborted = function dispatchIsAborted(isAborted) {
332
- if (cacheKey) {
333
- dispatch(updateIsAbortedUpload(cacheKey, isAborted));
334
- return;
335
- }
418
+ var useTusStore = function useTusStore(cacheKey, baseOption) {
419
+ var _useMergeTusOptions = useMergeTusOptions(baseOption),
420
+ autoAbort = _useMergeTusOptions.autoAbort,
421
+ autoStart = _useMergeTusOptions.autoStart,
422
+ uploadOptions = _useMergeTusOptions.uploadOptions;
336
423
 
337
- internalDispatch(function (internalTusState) {
338
- return _objectSpread2(_objectSpread2({}, internalTusState), {}, {
339
- isAborted: isAborted
340
- });
341
- });
342
- };
424
+ var _useTusClientState = useTusClientState(),
425
+ defaultOptions = _useTusClientState.defaultOptions,
426
+ uploads = _useTusClientState.uploads;
343
427
 
344
- var start = function start() {
345
- originalStart();
346
- dispatchIsAborted(false);
347
- };
428
+ var tusClientDispatch = useTusClientDispatch();
429
+ var setUpload = useCallback(function (file) {
430
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
348
431
 
349
- var abort = /*#__PURE__*/function () {
350
- var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
351
- return regeneratorRuntime.wrap(function _callee$(_context) {
352
- while (1) {
353
- switch (_context.prev = _context.next) {
354
- case 0:
355
- originalAbort();
356
- dispatchIsAborted(true);
432
+ var targetOptions = _objectSpread2(_objectSpread2(_objectSpread2({}, defaultOptions === null || defaultOptions === void 0 ? void 0 : defaultOptions(file)), uploadOptions), options);
357
433
 
358
- case 2:
359
- case "end":
360
- return _context.stop();
361
- }
362
- }
363
- }, _callee);
364
- }));
434
+ var onSuccess = function onSuccess() {
435
+ var _targetOptions$onSucc;
365
436
 
366
- return function abort() {
367
- return _ref3.apply(this, arguments);
437
+ tusClientDispatch(updateSuccessUpload(cacheKey));
438
+ targetOptions === null || targetOptions === void 0 ? void 0 : (_targetOptions$onSucc = targetOptions.onSuccess) === null || _targetOptions$onSucc === void 0 ? void 0 : _targetOptions$onSucc.call(targetOptions);
368
439
  };
369
- }();
370
-
371
- upload.start = start;
372
- upload.abort = abort;
373
- return upload;
374
- };
375
-
376
- var defaultUseTusOptionsValue = Object.freeze({
377
- cacheKey: undefined,
378
- autoAbort: true,
379
- autoStart: false
380
- });
381
- var initialUseTusState = Object.freeze({
382
- upload: undefined,
383
- isSuccess: false,
384
- isAborted: false,
385
- error: undefined
386
- });
387
- var useTus = function useTus(useTusOptions) {
388
- var _defaultUseTusOptions = _objectSpread2(_objectSpread2({}, defaultUseTusOptionsValue), useTusOptions || {}),
389
- cacheKey = _defaultUseTusOptions.cacheKey,
390
- autoAbort = _defaultUseTusOptions.autoAbort,
391
- autoStart = _defaultUseTusOptions.autoStart;
392
440
 
393
- var _useState = useState(initialUseTusState),
394
- _useState2 = _slicedToArray(_useState, 2),
395
- internalTusState = _useState2[0],
396
- setInternalTusState = _useState2[1];
441
+ var onError = function onError(error) {
442
+ var _targetOptions$onErro;
397
443
 
398
- var tusClientState = useTusClientState();
399
- var tusClientDispatch = useTusClientDispatch();
400
- var tus = tusClientState.tusHandler.getTus;
401
- var setUpload = useCallback(function (file) {
402
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
403
- var dispatcher = {
404
- cacheKey: cacheKey,
405
- dispatch: tusClientDispatch,
406
- internalDispatch: setInternalTusState
444
+ tusClientDispatch(updateErrorUpload(cacheKey, error));
445
+ targetOptions === null || targetOptions === void 0 ? void 0 : (_targetOptions$onErro = targetOptions.onError) === null || _targetOptions$onErro === void 0 ? void 0 : _targetOptions$onErro.call(targetOptions, error);
407
446
  };
408
447
 
409
- var targetOptions = _objectSpread2(_objectSpread2({}, tus.defaultOptions(file)), options);
410
-
411
- var _createOptionHandler = createOptionHandler({
412
- onError: targetOptions.onError,
413
- onSuccess: targetOptions.onSuccess
414
- }, dispatcher),
415
- onSuccess = _createOptionHandler.onSuccess,
416
- onError = _createOptionHandler.onError;
417
-
418
- var uploadOptions = _objectSpread2(_objectSpread2({}, targetOptions), {}, {
448
+ var mergedUploadOptions = _objectSpread2(_objectSpread2({}, targetOptions), {}, {
419
449
  onSuccess: onSuccess,
420
450
  onError: onError
421
451
  });
422
452
 
423
- var upload = createUpload(file, uploadOptions, dispatcher);
453
+ var dispatchIsAborted = function dispatchIsAborted(isAborted) {
454
+ tusClientDispatch(updateIsAbortedUpload(cacheKey, isAborted));
455
+ };
456
+
457
+ var upload = createUpload(file, mergedUploadOptions, dispatchIsAborted);
424
458
 
425
459
  if (autoStart) {
426
460
  startOrResumeUpload(upload);
427
461
  }
428
462
 
429
- if (cacheKey) {
430
- tusClientDispatch(insertUploadInstance(cacheKey, upload));
431
- return;
432
- }
433
-
434
- setInternalTusState(_objectSpread2(_objectSpread2({}, initialUseTusState), {}, {
435
- upload: upload
436
- }));
437
- }, [tusClientDispatch, cacheKey, tus, autoStart]);
463
+ tusClientDispatch(insertUploadInstance(cacheKey, upload));
464
+ }, [autoStart, cacheKey, defaultOptions, tusClientDispatch, uploadOptions]);
438
465
  var targetTusState = useMemo(function () {
439
- return cacheKey ? tusClientState.uploads[cacheKey] : internalTusState;
440
- }, [cacheKey, tusClientState, internalTusState]);
466
+ return uploads[cacheKey];
467
+ }, [cacheKey, uploads]);
441
468
  var remove = useCallback(function () {
442
469
  var _targetTusState$uploa;
443
470
 
444
471
  targetTusState === null || targetTusState === void 0 ? void 0 : (_targetTusState$uploa = targetTusState.upload) === null || _targetTusState$uploa === void 0 ? void 0 : _targetTusState$uploa.abort();
445
-
446
- if (!cacheKey) {
447
- setInternalTusState(initialUseTusState);
448
- return;
449
- }
450
-
451
472
  tusClientDispatch(removeUploadInstance(cacheKey));
452
473
  }, [targetTusState, tusClientDispatch, cacheKey]);
453
474
  var tusResult = useMemo(function () {
@@ -461,1518 +482,90 @@ var useTus = function useTus(useTusOptions) {
461
482
  setUpload: setUpload,
462
483
  remove: remove
463
484
  };
464
- }, [targetTusState, setUpload, remove]); // For autoAbort option
465
-
466
- useEffect(function () {
467
- var abortUploading = /*#__PURE__*/function () {
468
- var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
469
- return regeneratorRuntime.wrap(function _callee$(_context) {
470
- while (1) {
471
- switch (_context.prev = _context.next) {
472
- case 0:
473
- if (tusResult.upload) {
474
- _context.next = 2;
475
- break;
476
- }
477
-
478
- return _context.abrupt("return");
479
-
480
- case 2:
481
- _context.next = 4;
482
- return tusResult.upload.abort();
483
-
484
- case 4:
485
- case "end":
486
- return _context.stop();
487
- }
488
- }
489
- }, _callee);
490
- }));
491
-
492
- return function abortUploading() {
493
- return _ref.apply(this, arguments);
494
- };
495
- }();
496
-
497
- return function () {
498
- if (!autoAbort) {
499
- return;
500
- }
501
-
502
- abortUploading();
503
- };
504
- }, [autoAbort, tusResult.upload]);
505
- return tusResult;
506
- };
507
-
508
- function createCommonjsModule(fn) {
509
- var module = { exports: {} };
510
- return fn(module, module.exports), module.exports;
511
- }
512
-
513
- /*
514
- object-assign
515
- (c) Sindre Sorhus
516
- @license MIT
517
- */
518
- /* eslint-disable no-unused-vars */
519
-
520
- var getOwnPropertySymbols = Object.getOwnPropertySymbols;
521
- var hasOwnProperty = Object.prototype.hasOwnProperty;
522
- var propIsEnumerable = Object.prototype.propertyIsEnumerable;
523
-
524
- function toObject(val) {
525
- if (val === null || val === undefined) {
526
- throw new TypeError('Object.assign cannot be called with null or undefined');
527
- }
528
-
529
- return Object(val);
530
- }
531
-
532
- function shouldUseNative() {
533
- try {
534
- if (!Object.assign) {
535
- return false;
536
- } // Detect buggy property enumeration order in older V8 versions.
537
- // https://bugs.chromium.org/p/v8/issues/detail?id=4118
538
-
539
-
540
- var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
541
-
542
- test1[5] = 'de';
543
-
544
- if (Object.getOwnPropertyNames(test1)[0] === '5') {
545
- return false;
546
- } // https://bugs.chromium.org/p/v8/issues/detail?id=3056
547
-
548
-
549
- var test2 = {};
550
-
551
- for (var i = 0; i < 10; i++) {
552
- test2['_' + String.fromCharCode(i)] = i;
553
- }
554
-
555
- var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
556
- return test2[n];
557
- });
558
-
559
- if (order2.join('') !== '0123456789') {
560
- return false;
561
- } // https://bugs.chromium.org/p/v8/issues/detail?id=3056
562
-
563
-
564
- var test3 = {};
565
- 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
566
- test3[letter] = letter;
567
- });
568
-
569
- if (Object.keys(Object.assign({}, test3)).join('') !== 'abcdefghijklmnopqrst') {
570
- return false;
571
- }
572
-
573
- return true;
574
- } catch (err) {
575
- // We don't expect any of the above to throw, but better to be safe.
576
- return false;
577
- }
578
- }
579
-
580
- var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
581
- var from;
582
- var to = toObject(target);
583
- var symbols;
584
-
585
- for (var s = 1; s < arguments.length; s++) {
586
- from = Object(arguments[s]);
587
-
588
- for (var key in from) {
589
- if (hasOwnProperty.call(from, key)) {
590
- to[key] = from[key];
591
- }
592
- }
593
-
594
- if (getOwnPropertySymbols) {
595
- symbols = getOwnPropertySymbols(from);
596
-
597
- for (var i = 0; i < symbols.length; i++) {
598
- if (propIsEnumerable.call(from, symbols[i])) {
599
- to[symbols[i]] = from[symbols[i]];
600
- }
601
- }
602
- }
603
- }
604
-
605
- return to;
606
- };
607
-
608
- /** @license React v17.0.2
609
- * react-jsx-runtime.production.min.js
610
- *
611
- * Copyright (c) Facebook, Inc. and its affiliates.
612
- *
613
- * This source code is licensed under the MIT license found in the
614
- * LICENSE file in the root directory of this source tree.
615
- */
616
- var reactJsxRuntime_production_min = createCommonjsModule(function (module, exports) {
617
-
618
- var g = 60103;
619
- exports.Fragment = 60107;
620
-
621
- if ("function" === typeof Symbol && Symbol["for"]) {
622
- var h = Symbol["for"];
623
- g = h("react.element");
624
- exports.Fragment = h("react.fragment");
625
- }
626
-
627
- var m = f.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,
628
- n = Object.prototype.hasOwnProperty,
629
- p = {
630
- key: !0,
631
- ref: !0,
632
- __self: !0,
633
- __source: !0
634
- };
635
-
636
- function q(c, a, k) {
637
- var b,
638
- d = {},
639
- e = null,
640
- l = null;
641
- void 0 !== k && (e = "" + k);
642
- void 0 !== a.key && (e = "" + a.key);
643
- void 0 !== a.ref && (l = a.ref);
644
-
645
- for (b in a) {
646
- n.call(a, b) && !p.hasOwnProperty(b) && (d[b] = a[b]);
647
- }
648
-
649
- if (c && c.defaultProps) for (b in a = c.defaultProps, a) {
650
- void 0 === d[b] && (d[b] = a[b]);
651
- }
652
- return {
653
- $$typeof: g,
654
- type: c,
655
- key: e,
656
- ref: l,
657
- props: d,
658
- _owner: m.current
659
- };
660
- }
661
-
662
- exports.jsx = q;
663
- exports.jsxs = q;
664
- });
665
-
666
- var reactJsxRuntime_development = createCommonjsModule(function (module, exports) {
667
-
668
- if (process.env.NODE_ENV !== "production") {
669
- (function () {
670
-
671
- var React = f;
672
- var _assign = objectAssign; // ATTENTION
673
- // When adding new symbols to this file,
674
- // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols'
675
- // The Symbol used to tag the ReactElement-like types. If there is no native Symbol
676
- // nor polyfill, then a plain number is used for performance.
677
-
678
- var REACT_ELEMENT_TYPE = 0xeac7;
679
- var REACT_PORTAL_TYPE = 0xeaca;
680
- exports.Fragment = 0xeacb;
681
- var REACT_STRICT_MODE_TYPE = 0xeacc;
682
- var REACT_PROFILER_TYPE = 0xead2;
683
- var REACT_PROVIDER_TYPE = 0xeacd;
684
- var REACT_CONTEXT_TYPE = 0xeace;
685
- var REACT_FORWARD_REF_TYPE = 0xead0;
686
- var REACT_SUSPENSE_TYPE = 0xead1;
687
- var REACT_SUSPENSE_LIST_TYPE = 0xead8;
688
- var REACT_MEMO_TYPE = 0xead3;
689
- var REACT_LAZY_TYPE = 0xead4;
690
- var REACT_BLOCK_TYPE = 0xead9;
691
- var REACT_SERVER_BLOCK_TYPE = 0xeada;
692
- var REACT_FUNDAMENTAL_TYPE = 0xead5;
693
- var REACT_DEBUG_TRACING_MODE_TYPE = 0xeae1;
694
- var REACT_LEGACY_HIDDEN_TYPE = 0xeae3;
695
-
696
- if (typeof Symbol === 'function' && Symbol["for"]) {
697
- var symbolFor = Symbol["for"];
698
- REACT_ELEMENT_TYPE = symbolFor('react.element');
699
- REACT_PORTAL_TYPE = symbolFor('react.portal');
700
- exports.Fragment = symbolFor('react.fragment');
701
- REACT_STRICT_MODE_TYPE = symbolFor('react.strict_mode');
702
- REACT_PROFILER_TYPE = symbolFor('react.profiler');
703
- REACT_PROVIDER_TYPE = symbolFor('react.provider');
704
- REACT_CONTEXT_TYPE = symbolFor('react.context');
705
- REACT_FORWARD_REF_TYPE = symbolFor('react.forward_ref');
706
- REACT_SUSPENSE_TYPE = symbolFor('react.suspense');
707
- REACT_SUSPENSE_LIST_TYPE = symbolFor('react.suspense_list');
708
- REACT_MEMO_TYPE = symbolFor('react.memo');
709
- REACT_LAZY_TYPE = symbolFor('react.lazy');
710
- REACT_BLOCK_TYPE = symbolFor('react.block');
711
- REACT_SERVER_BLOCK_TYPE = symbolFor('react.server.block');
712
- REACT_FUNDAMENTAL_TYPE = symbolFor('react.fundamental');
713
- symbolFor('react.scope');
714
- symbolFor('react.opaque.id');
715
- REACT_DEBUG_TRACING_MODE_TYPE = symbolFor('react.debug_trace_mode');
716
- symbolFor('react.offscreen');
717
- REACT_LEGACY_HIDDEN_TYPE = symbolFor('react.legacy_hidden');
718
- }
719
-
720
- var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
721
- var FAUX_ITERATOR_SYMBOL = '@@iterator';
722
-
723
- function getIteratorFn(maybeIterable) {
724
- if (maybeIterable === null || _typeof(maybeIterable) !== 'object') {
725
- return null;
726
- }
727
-
728
- var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
729
-
730
- if (typeof maybeIterator === 'function') {
731
- return maybeIterator;
732
- }
733
-
734
- return null;
735
- }
736
-
737
- var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
738
-
739
- function error(format) {
740
- {
741
- for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
742
- args[_key2 - 1] = arguments[_key2];
743
- }
744
-
745
- printWarning('error', format, args);
746
- }
747
- }
748
-
749
- function printWarning(level, format, args) {
750
- // When changing this logic, you might want to also
751
- // update consoleWithStackDev.www.js as well.
752
- {
753
- var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
754
- var stack = ReactDebugCurrentFrame.getStackAddendum();
755
-
756
- if (stack !== '') {
757
- format += '%s';
758
- args = args.concat([stack]);
759
- }
760
-
761
- var argsWithFormat = args.map(function (item) {
762
- return '' + item;
763
- }); // Careful: RN currently depends on this prefix
764
-
765
- argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
766
- // breaks IE9: https://github.com/facebook/react/issues/13610
767
- // eslint-disable-next-line react-internal/no-production-logging
768
-
769
- Function.prototype.apply.call(console[level], console, argsWithFormat);
770
- }
771
- } // Filter certain DOM attributes (e.g. src, href) if their values are empty strings.
772
-
773
-
774
- var enableScopeAPI = false; // Experimental Create Event Handle API.
775
-
776
- function isValidElementType(type) {
777
- if (typeof type === 'string' || typeof type === 'function') {
778
- return true;
779
- } // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill).
780
-
781
-
782
- if (type === exports.Fragment || type === REACT_PROFILER_TYPE || type === REACT_DEBUG_TRACING_MODE_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_TYPE || type === REACT_LEGACY_HIDDEN_TYPE || enableScopeAPI) {
783
- return true;
784
- }
785
-
786
- if (_typeof(type) === 'object' && type !== null) {
787
- if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_BLOCK_TYPE || type[0] === REACT_SERVER_BLOCK_TYPE) {
788
- return true;
789
- }
790
- }
791
-
792
- return false;
793
- }
794
-
795
- function getWrappedName(outerType, innerType, wrapperName) {
796
- var functionName = innerType.displayName || innerType.name || '';
797
- return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName);
798
- }
799
-
800
- function getContextName(type) {
801
- return type.displayName || 'Context';
802
- }
803
-
804
- function getComponentName(type) {
805
- if (type == null) {
806
- // Host root, text node or just invalid type.
807
- return null;
808
- }
809
-
810
- {
811
- if (typeof type.tag === 'number') {
812
- error('Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
813
- }
814
- }
815
-
816
- if (typeof type === 'function') {
817
- return type.displayName || type.name || null;
818
- }
819
-
820
- if (typeof type === 'string') {
821
- return type;
822
- }
823
-
824
- switch (type) {
825
- case exports.Fragment:
826
- return 'Fragment';
827
-
828
- case REACT_PORTAL_TYPE:
829
- return 'Portal';
830
-
831
- case REACT_PROFILER_TYPE:
832
- return 'Profiler';
833
-
834
- case REACT_STRICT_MODE_TYPE:
835
- return 'StrictMode';
836
-
837
- case REACT_SUSPENSE_TYPE:
838
- return 'Suspense';
839
-
840
- case REACT_SUSPENSE_LIST_TYPE:
841
- return 'SuspenseList';
842
- }
843
-
844
- if (_typeof(type) === 'object') {
845
- switch (type.$$typeof) {
846
- case REACT_CONTEXT_TYPE:
847
- var context = type;
848
- return getContextName(context) + '.Consumer';
849
-
850
- case REACT_PROVIDER_TYPE:
851
- var provider = type;
852
- return getContextName(provider._context) + '.Provider';
853
-
854
- case REACT_FORWARD_REF_TYPE:
855
- return getWrappedName(type, type.render, 'ForwardRef');
856
-
857
- case REACT_MEMO_TYPE:
858
- return getComponentName(type.type);
859
-
860
- case REACT_BLOCK_TYPE:
861
- return getComponentName(type._render);
862
-
863
- case REACT_LAZY_TYPE:
864
- {
865
- var lazyComponent = type;
866
- var payload = lazyComponent._payload;
867
- var init = lazyComponent._init;
868
-
869
- try {
870
- return getComponentName(init(payload));
871
- } catch (x) {
872
- return null;
873
- }
874
- }
875
- }
876
- }
877
-
878
- return null;
879
- } // Helpers to patch console.logs to avoid logging during side-effect free
880
- // replaying on render function. This currently only patches the object
881
- // lazily which won't cover if the log function was extracted eagerly.
882
- // We could also eagerly patch the method.
883
-
884
-
885
- var disabledDepth = 0;
886
- var prevLog;
887
- var prevInfo;
888
- var prevWarn;
889
- var prevError;
890
- var prevGroup;
891
- var prevGroupCollapsed;
892
- var prevGroupEnd;
893
-
894
- function disabledLog() {}
895
-
896
- disabledLog.__reactDisabledLog = true;
897
-
898
- function disableLogs() {
899
- {
900
- if (disabledDepth === 0) {
901
- /* eslint-disable react-internal/no-production-logging */
902
- prevLog = console.log;
903
- prevInfo = console.info;
904
- prevWarn = console.warn;
905
- prevError = console.error;
906
- prevGroup = console.group;
907
- prevGroupCollapsed = console.groupCollapsed;
908
- prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099
909
-
910
- var props = {
911
- configurable: true,
912
- enumerable: true,
913
- value: disabledLog,
914
- writable: true
915
- }; // $FlowFixMe Flow thinks console is immutable.
916
-
917
- Object.defineProperties(console, {
918
- info: props,
919
- log: props,
920
- warn: props,
921
- error: props,
922
- group: props,
923
- groupCollapsed: props,
924
- groupEnd: props
925
- });
926
- /* eslint-enable react-internal/no-production-logging */
927
- }
928
-
929
- disabledDepth++;
930
- }
931
- }
932
-
933
- function reenableLogs() {
934
- {
935
- disabledDepth--;
936
-
937
- if (disabledDepth === 0) {
938
- /* eslint-disable react-internal/no-production-logging */
939
- var props = {
940
- configurable: true,
941
- enumerable: true,
942
- writable: true
943
- }; // $FlowFixMe Flow thinks console is immutable.
944
-
945
- Object.defineProperties(console, {
946
- log: _assign({}, props, {
947
- value: prevLog
948
- }),
949
- info: _assign({}, props, {
950
- value: prevInfo
951
- }),
952
- warn: _assign({}, props, {
953
- value: prevWarn
954
- }),
955
- error: _assign({}, props, {
956
- value: prevError
957
- }),
958
- group: _assign({}, props, {
959
- value: prevGroup
960
- }),
961
- groupCollapsed: _assign({}, props, {
962
- value: prevGroupCollapsed
963
- }),
964
- groupEnd: _assign({}, props, {
965
- value: prevGroupEnd
966
- })
967
- });
968
- /* eslint-enable react-internal/no-production-logging */
969
- }
970
-
971
- if (disabledDepth < 0) {
972
- error('disabledDepth fell below zero. ' + 'This is a bug in React. Please file an issue.');
973
- }
974
- }
975
- }
976
-
977
- var ReactCurrentDispatcher = ReactSharedInternals.ReactCurrentDispatcher;
978
- var prefix;
979
-
980
- function describeBuiltInComponentFrame(name, source, ownerFn) {
981
- {
982
- if (prefix === undefined) {
983
- // Extract the VM specific prefix used by each line.
984
- try {
985
- throw Error();
986
- } catch (x) {
987
- var match = x.stack.trim().match(/\n( *(at )?)/);
988
- prefix = match && match[1] || '';
989
- }
990
- } // We use the prefix to ensure our stacks line up with native stack frames.
991
-
992
-
993
- return '\n' + prefix + name;
994
- }
995
- }
996
-
997
- var reentry = false;
998
- var componentFrameCache;
999
- {
1000
- var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map;
1001
- componentFrameCache = new PossiblyWeakMap();
1002
- }
1003
-
1004
- function describeNativeComponentFrame(fn, construct) {
1005
- // If something asked for a stack inside a fake render, it should get ignored.
1006
- if (!fn || reentry) {
1007
- return '';
1008
- }
1009
-
1010
- {
1011
- var frame = componentFrameCache.get(fn);
1012
-
1013
- if (frame !== undefined) {
1014
- return frame;
1015
- }
1016
- }
1017
- var control;
1018
- reentry = true;
1019
- var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe It does accept undefined.
1020
-
1021
- Error.prepareStackTrace = undefined;
1022
- var previousDispatcher;
1023
- {
1024
- previousDispatcher = ReactCurrentDispatcher.current; // Set the dispatcher in DEV because this might be call in the render function
1025
- // for warnings.
1026
-
1027
- ReactCurrentDispatcher.current = null;
1028
- disableLogs();
1029
- }
1030
-
1031
- try {
1032
- // This should throw.
1033
- if (construct) {
1034
- // Something should be setting the props in the constructor.
1035
- var Fake = function Fake() {
1036
- throw Error();
1037
- }; // $FlowFixMe
1038
-
1039
-
1040
- Object.defineProperty(Fake.prototype, 'props', {
1041
- set: function set() {
1042
- // We use a throwing setter instead of frozen or non-writable props
1043
- // because that won't throw in a non-strict mode function.
1044
- throw Error();
1045
- }
1046
- });
1047
-
1048
- if ((typeof Reflect === "undefined" ? "undefined" : _typeof(Reflect)) === 'object' && Reflect.construct) {
1049
- // We construct a different control for this case to include any extra
1050
- // frames added by the construct call.
1051
- try {
1052
- Reflect.construct(Fake, []);
1053
- } catch (x) {
1054
- control = x;
1055
- }
1056
-
1057
- Reflect.construct(fn, [], Fake);
1058
- } else {
1059
- try {
1060
- Fake.call();
1061
- } catch (x) {
1062
- control = x;
1063
- }
1064
-
1065
- fn.call(Fake.prototype);
1066
- }
1067
- } else {
1068
- try {
1069
- throw Error();
1070
- } catch (x) {
1071
- control = x;
1072
- }
1073
-
1074
- fn();
1075
- }
1076
- } catch (sample) {
1077
- // This is inlined manually because closure doesn't do it for us.
1078
- if (sample && control && typeof sample.stack === 'string') {
1079
- // This extracts the first frame from the sample that isn't also in the control.
1080
- // Skipping one frame that we assume is the frame that calls the two.
1081
- var sampleLines = sample.stack.split('\n');
1082
- var controlLines = control.stack.split('\n');
1083
- var s = sampleLines.length - 1;
1084
- var c = controlLines.length - 1;
1085
-
1086
- while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) {
1087
- // We expect at least one stack frame to be shared.
1088
- // Typically this will be the root most one. However, stack frames may be
1089
- // cut off due to maximum stack limits. In this case, one maybe cut off
1090
- // earlier than the other. We assume that the sample is longer or the same
1091
- // and there for cut off earlier. So we should find the root most frame in
1092
- // the sample somewhere in the control.
1093
- c--;
1094
- }
1095
-
1096
- for (; s >= 1 && c >= 0; s--, c--) {
1097
- // Next we find the first one that isn't the same which should be the
1098
- // frame that called our sample function and the control.
1099
- if (sampleLines[s] !== controlLines[c]) {
1100
- // In V8, the first line is describing the message but other VMs don't.
1101
- // If we're about to return the first line, and the control is also on the same
1102
- // line, that's a pretty good indicator that our sample threw at same line as
1103
- // the control. I.e. before we entered the sample frame. So we ignore this result.
1104
- // This can happen if you passed a class to function component, or non-function.
1105
- if (s !== 1 || c !== 1) {
1106
- do {
1107
- s--;
1108
- c--; // We may still have similar intermediate frames from the construct call.
1109
- // The next one that isn't the same should be our match though.
1110
-
1111
- if (c < 0 || sampleLines[s] !== controlLines[c]) {
1112
- // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier.
1113
- var _frame = '\n' + sampleLines[s].replace(' at new ', ' at ');
1114
-
1115
- {
1116
- if (typeof fn === 'function') {
1117
- componentFrameCache.set(fn, _frame);
1118
- }
1119
- } // Return the line we found.
1120
-
1121
- return _frame;
1122
- }
1123
- } while (s >= 1 && c >= 0);
1124
- }
1125
-
1126
- break;
1127
- }
1128
- }
1129
- }
1130
- } finally {
1131
- reentry = false;
1132
- {
1133
- ReactCurrentDispatcher.current = previousDispatcher;
1134
- reenableLogs();
1135
- }
1136
- Error.prepareStackTrace = previousPrepareStackTrace;
1137
- } // Fallback to just using the name if we couldn't make it throw.
1138
-
1139
-
1140
- var name = fn ? fn.displayName || fn.name : '';
1141
- var syntheticFrame = name ? describeBuiltInComponentFrame(name) : '';
1142
- {
1143
- if (typeof fn === 'function') {
1144
- componentFrameCache.set(fn, syntheticFrame);
1145
- }
1146
- }
1147
- return syntheticFrame;
1148
- }
1149
-
1150
- function describeFunctionComponentFrame(fn, source, ownerFn) {
1151
- {
1152
- return describeNativeComponentFrame(fn, false);
1153
- }
1154
- }
1155
-
1156
- function shouldConstruct(Component) {
1157
- var prototype = Component.prototype;
1158
- return !!(prototype && prototype.isReactComponent);
1159
- }
1160
-
1161
- function describeUnknownElementTypeFrameInDEV(type, source, ownerFn) {
1162
- if (type == null) {
1163
- return '';
1164
- }
1165
-
1166
- if (typeof type === 'function') {
1167
- {
1168
- return describeNativeComponentFrame(type, shouldConstruct(type));
1169
- }
1170
- }
1171
-
1172
- if (typeof type === 'string') {
1173
- return describeBuiltInComponentFrame(type);
1174
- }
1175
-
1176
- switch (type) {
1177
- case REACT_SUSPENSE_TYPE:
1178
- return describeBuiltInComponentFrame('Suspense');
1179
-
1180
- case REACT_SUSPENSE_LIST_TYPE:
1181
- return describeBuiltInComponentFrame('SuspenseList');
1182
- }
1183
-
1184
- if (_typeof(type) === 'object') {
1185
- switch (type.$$typeof) {
1186
- case REACT_FORWARD_REF_TYPE:
1187
- return describeFunctionComponentFrame(type.render);
1188
-
1189
- case REACT_MEMO_TYPE:
1190
- // Memo may contain any component type so we recursively resolve it.
1191
- return describeUnknownElementTypeFrameInDEV(type.type, source, ownerFn);
1192
-
1193
- case REACT_BLOCK_TYPE:
1194
- return describeFunctionComponentFrame(type._render);
1195
-
1196
- case REACT_LAZY_TYPE:
1197
- {
1198
- var lazyComponent = type;
1199
- var payload = lazyComponent._payload;
1200
- var init = lazyComponent._init;
1201
-
1202
- try {
1203
- // Lazy may contain any component type so we recursively resolve it.
1204
- return describeUnknownElementTypeFrameInDEV(init(payload), source, ownerFn);
1205
- } catch (x) {}
1206
- }
1207
- }
1208
- }
1209
-
1210
- return '';
1211
- }
1212
-
1213
- var loggedTypeFailures = {};
1214
- var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
1215
-
1216
- function setCurrentlyValidatingElement(element) {
1217
- {
1218
- if (element) {
1219
- var owner = element._owner;
1220
- var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
1221
- ReactDebugCurrentFrame.setExtraStackFrame(stack);
1222
- } else {
1223
- ReactDebugCurrentFrame.setExtraStackFrame(null);
1224
- }
1225
- }
1226
- }
1227
-
1228
- function checkPropTypes(typeSpecs, values, location, componentName, element) {
1229
- {
1230
- // $FlowFixMe This is okay but Flow doesn't know it.
1231
- var has = Function.call.bind(Object.prototype.hasOwnProperty);
1232
-
1233
- for (var typeSpecName in typeSpecs) {
1234
- if (has(typeSpecs, typeSpecName)) {
1235
- var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to
1236
- // fail the render phase where it didn't fail before. So we log it.
1237
- // After these have been cleaned up, we'll let them throw.
1238
-
1239
- try {
1240
- // This is intentionally an invariant that gets caught. It's the same
1241
- // behavior as without this statement except with a better message.
1242
- if (typeof typeSpecs[typeSpecName] !== 'function') {
1243
- var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + _typeof(typeSpecs[typeSpecName]) + '`.' + 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.');
1244
- err.name = 'Invariant Violation';
1245
- throw err;
1246
- }
1247
-
1248
- error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED');
1249
- } catch (ex) {
1250
- error$1 = ex;
1251
- }
1252
-
1253
- if (error$1 && !(error$1 instanceof Error)) {
1254
- setCurrentlyValidatingElement(element);
1255
- error('%s: type specification of %s' + ' `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, _typeof(error$1));
1256
- setCurrentlyValidatingElement(null);
1257
- }
1258
-
1259
- if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) {
1260
- // Only monitor this failure once because there tends to be a lot of the
1261
- // same error.
1262
- loggedTypeFailures[error$1.message] = true;
1263
- setCurrentlyValidatingElement(element);
1264
- error('Failed %s type: %s', location, error$1.message);
1265
- setCurrentlyValidatingElement(null);
1266
- }
1267
- }
1268
- }
1269
- }
1270
- }
1271
-
1272
- var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
1273
- var hasOwnProperty = Object.prototype.hasOwnProperty;
1274
- var RESERVED_PROPS = {
1275
- key: true,
1276
- ref: true,
1277
- __self: true,
1278
- __source: true
1279
- };
1280
- var specialPropKeyWarningShown;
1281
- var specialPropRefWarningShown;
1282
- var didWarnAboutStringRefs;
1283
- {
1284
- didWarnAboutStringRefs = {};
1285
- }
1286
-
1287
- function hasValidRef(config) {
1288
- {
1289
- if (hasOwnProperty.call(config, 'ref')) {
1290
- var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
1291
-
1292
- if (getter && getter.isReactWarning) {
1293
- return false;
1294
- }
1295
- }
1296
- }
1297
- return config.ref !== undefined;
1298
- }
1299
-
1300
- function hasValidKey(config) {
1301
- {
1302
- if (hasOwnProperty.call(config, 'key')) {
1303
- var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
1304
-
1305
- if (getter && getter.isReactWarning) {
1306
- return false;
1307
- }
1308
- }
1309
- }
1310
- return config.key !== undefined;
1311
- }
1312
-
1313
- function warnIfStringRefCannotBeAutoConverted(config, self) {
1314
- {
1315
- if (typeof config.ref === 'string' && ReactCurrentOwner.current && self && ReactCurrentOwner.current.stateNode !== self) {
1316
- var componentName = getComponentName(ReactCurrentOwner.current.type);
1317
-
1318
- if (!didWarnAboutStringRefs[componentName]) {
1319
- error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-string-ref', getComponentName(ReactCurrentOwner.current.type), config.ref);
1320
- didWarnAboutStringRefs[componentName] = true;
1321
- }
1322
- }
1323
- }
1324
- }
1325
-
1326
- function defineKeyPropWarningGetter(props, displayName) {
1327
- {
1328
- var warnAboutAccessingKey = function warnAboutAccessingKey() {
1329
- if (!specialPropKeyWarningShown) {
1330
- specialPropKeyWarningShown = true;
1331
- error('%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
1332
- }
1333
- };
1334
-
1335
- warnAboutAccessingKey.isReactWarning = true;
1336
- Object.defineProperty(props, 'key', {
1337
- get: warnAboutAccessingKey,
1338
- configurable: true
1339
- });
1340
- }
1341
- }
1342
-
1343
- function defineRefPropWarningGetter(props, displayName) {
1344
- {
1345
- var warnAboutAccessingRef = function warnAboutAccessingRef() {
1346
- if (!specialPropRefWarningShown) {
1347
- specialPropRefWarningShown = true;
1348
- error('%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName);
1349
- }
1350
- };
1351
-
1352
- warnAboutAccessingRef.isReactWarning = true;
1353
- Object.defineProperty(props, 'ref', {
1354
- get: warnAboutAccessingRef,
1355
- configurable: true
1356
- });
1357
- }
1358
- }
1359
- /**
1360
- * Factory method to create a new React element. This no longer adheres to
1361
- * the class pattern, so do not use new to call it. Also, instanceof check
1362
- * will not work. Instead test $$typeof field against Symbol.for('react.element') to check
1363
- * if something is a React Element.
1364
- *
1365
- * @param {*} type
1366
- * @param {*} props
1367
- * @param {*} key
1368
- * @param {string|object} ref
1369
- * @param {*} owner
1370
- * @param {*} self A *temporary* helper to detect places where `this` is
1371
- * different from the `owner` when React.createElement is called, so that we
1372
- * can warn. We want to get rid of owner and replace string `ref`s with arrow
1373
- * functions, and as long as `this` and owner are the same, there will be no
1374
- * change in behavior.
1375
- * @param {*} source An annotation object (added by a transpiler or otherwise)
1376
- * indicating filename, line number, and/or other information.
1377
- * @internal
1378
- */
1379
-
1380
-
1381
- var ReactElement = function ReactElement(type, key, ref, self, source, owner, props) {
1382
- var element = {
1383
- // This tag allows us to uniquely identify this as a React Element
1384
- $$typeof: REACT_ELEMENT_TYPE,
1385
- // Built-in properties that belong on the element
1386
- type: type,
1387
- key: key,
1388
- ref: ref,
1389
- props: props,
1390
- // Record the component responsible for creating this element.
1391
- _owner: owner
1392
- };
1393
- {
1394
- // The validation flag is currently mutative. We put it on
1395
- // an external backing store so that we can freeze the whole object.
1396
- // This can be replaced with a WeakMap once they are implemented in
1397
- // commonly used development environments.
1398
- element._store = {}; // To make comparing ReactElements easier for testing purposes, we make
1399
- // the validation flag non-enumerable (where possible, which should
1400
- // include every environment we run tests in), so the test framework
1401
- // ignores it.
1402
-
1403
- Object.defineProperty(element._store, 'validated', {
1404
- configurable: false,
1405
- enumerable: false,
1406
- writable: true,
1407
- value: false
1408
- }); // self and source are DEV only properties.
1409
-
1410
- Object.defineProperty(element, '_self', {
1411
- configurable: false,
1412
- enumerable: false,
1413
- writable: false,
1414
- value: self
1415
- }); // Two elements created in two different places should be considered
1416
- // equal for testing purposes and therefore we hide it from enumeration.
1417
-
1418
- Object.defineProperty(element, '_source', {
1419
- configurable: false,
1420
- enumerable: false,
1421
- writable: false,
1422
- value: source
1423
- });
1424
-
1425
- if (Object.freeze) {
1426
- Object.freeze(element.props);
1427
- Object.freeze(element);
1428
- }
1429
- }
1430
- return element;
1431
- };
1432
- /**
1433
- * https://github.com/reactjs/rfcs/pull/107
1434
- * @param {*} type
1435
- * @param {object} props
1436
- * @param {string} key
1437
- */
1438
-
1439
-
1440
- function jsxDEV(type, config, maybeKey, source, self) {
1441
- {
1442
- var propName; // Reserved names are extracted
1443
-
1444
- var props = {};
1445
- var key = null;
1446
- var ref = null; // Currently, key can be spread in as a prop. This causes a potential
1447
- // issue if key is also explicitly declared (ie. <div {...props} key="Hi" />
1448
- // or <div key="Hi" {...props} /> ). We want to deprecate key spread,
1449
- // but as an intermediary step, we will use jsxDEV for everything except
1450
- // <div {...props} key="Hi" />, because we aren't currently able to tell if
1451
- // key is explicitly declared to be undefined or not.
1452
-
1453
- if (maybeKey !== undefined) {
1454
- key = '' + maybeKey;
1455
- }
1456
-
1457
- if (hasValidKey(config)) {
1458
- key = '' + config.key;
1459
- }
1460
-
1461
- if (hasValidRef(config)) {
1462
- ref = config.ref;
1463
- warnIfStringRefCannotBeAutoConverted(config, self);
1464
- } // Remaining properties are added to a new props object
1465
-
1466
-
1467
- for (propName in config) {
1468
- if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
1469
- props[propName] = config[propName];
1470
- }
1471
- } // Resolve default props
1472
-
1473
-
1474
- if (type && type.defaultProps) {
1475
- var defaultProps = type.defaultProps;
1476
-
1477
- for (propName in defaultProps) {
1478
- if (props[propName] === undefined) {
1479
- props[propName] = defaultProps[propName];
1480
- }
1481
- }
1482
- }
1483
-
1484
- if (key || ref) {
1485
- var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
1486
-
1487
- if (key) {
1488
- defineKeyPropWarningGetter(props, displayName);
1489
- }
1490
-
1491
- if (ref) {
1492
- defineRefPropWarningGetter(props, displayName);
1493
- }
1494
- }
1495
-
1496
- return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
1497
- }
1498
- }
1499
-
1500
- var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
1501
- var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame;
1502
-
1503
- function setCurrentlyValidatingElement$1(element) {
1504
- {
1505
- if (element) {
1506
- var owner = element._owner;
1507
- var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null);
1508
- ReactDebugCurrentFrame$1.setExtraStackFrame(stack);
1509
- } else {
1510
- ReactDebugCurrentFrame$1.setExtraStackFrame(null);
1511
- }
1512
- }
1513
- }
1514
-
1515
- var propTypesMisspellWarningShown;
1516
- {
1517
- propTypesMisspellWarningShown = false;
1518
- }
1519
- /**
1520
- * Verifies the object is a ReactElement.
1521
- * See https://reactjs.org/docs/react-api.html#isvalidelement
1522
- * @param {?object} object
1523
- * @return {boolean} True if `object` is a ReactElement.
1524
- * @final
1525
- */
1526
-
1527
- function isValidElement(object) {
1528
- {
1529
- return _typeof(object) === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
1530
- }
1531
- }
1532
-
1533
- function getDeclarationErrorAddendum() {
1534
- {
1535
- if (ReactCurrentOwner$1.current) {
1536
- var name = getComponentName(ReactCurrentOwner$1.current.type);
1537
-
1538
- if (name) {
1539
- return '\n\nCheck the render method of `' + name + '`.';
1540
- }
1541
- }
1542
-
1543
- return '';
1544
- }
1545
- }
1546
-
1547
- function getSourceInfoErrorAddendum(source) {
1548
- {
1549
- if (source !== undefined) {
1550
- var fileName = source.fileName.replace(/^.*[\\\/]/, '');
1551
- var lineNumber = source.lineNumber;
1552
- return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.';
1553
- }
1554
-
1555
- return '';
1556
- }
1557
- }
1558
- /**
1559
- * Warn if there's no key explicitly set on dynamic arrays of children or
1560
- * object keys are not valid. This allows us to keep track of children between
1561
- * updates.
1562
- */
1563
-
1564
-
1565
- var ownerHasKeyUseWarning = {};
1566
-
1567
- function getCurrentComponentErrorInfo(parentType) {
1568
- {
1569
- var info = getDeclarationErrorAddendum();
1570
-
1571
- if (!info) {
1572
- var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
1573
-
1574
- if (parentName) {
1575
- info = "\n\nCheck the top-level render call using <" + parentName + ">.";
1576
- }
1577
- }
1578
-
1579
- return info;
1580
- }
1581
- }
1582
- /**
1583
- * Warn if the element doesn't have an explicit key assigned to it.
1584
- * This element is in an array. The array could grow and shrink or be
1585
- * reordered. All children that haven't already been validated are required to
1586
- * have a "key" property assigned to it. Error statuses are cached so a warning
1587
- * will only be shown once.
1588
- *
1589
- * @internal
1590
- * @param {ReactElement} element Element that requires a key.
1591
- * @param {*} parentType element's parent's type.
1592
- */
1593
-
1594
-
1595
- function validateExplicitKey(element, parentType) {
1596
- {
1597
- if (!element._store || element._store.validated || element.key != null) {
1598
- return;
1599
- }
1600
-
1601
- element._store.validated = true;
1602
- var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
1603
-
1604
- if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
1605
- return;
1606
- }
1607
-
1608
- ownerHasKeyUseWarning[currentComponentErrorInfo] = true; // Usually the current owner is the offender, but if it accepts children as a
1609
- // property, it may be the creator of the child that's responsible for
1610
- // assigning it a key.
1611
-
1612
- var childOwner = '';
1613
-
1614
- if (element && element._owner && element._owner !== ReactCurrentOwner$1.current) {
1615
- // Give the component that originally created this child.
1616
- childOwner = " It was passed a child from " + getComponentName(element._owner.type) + ".";
1617
- }
1618
-
1619
- setCurrentlyValidatingElement$1(element);
1620
- error('Each child in a list should have a unique "key" prop.' + '%s%s See https://reactjs.org/link/warning-keys for more information.', currentComponentErrorInfo, childOwner);
1621
- setCurrentlyValidatingElement$1(null);
1622
- }
1623
- }
1624
- /**
1625
- * Ensure that every element either is passed in a static location, in an
1626
- * array with an explicit keys property defined, or in an object literal
1627
- * with valid key property.
1628
- *
1629
- * @internal
1630
- * @param {ReactNode} node Statically passed child of any type.
1631
- * @param {*} parentType node's parent's type.
1632
- */
1633
-
1634
-
1635
- function validateChildKeys(node, parentType) {
1636
- {
1637
- if (_typeof(node) !== 'object') {
1638
- return;
1639
- }
1640
-
1641
- if (Array.isArray(node)) {
1642
- for (var i = 0; i < node.length; i++) {
1643
- var child = node[i];
1644
-
1645
- if (isValidElement(child)) {
1646
- validateExplicitKey(child, parentType);
1647
- }
1648
- }
1649
- } else if (isValidElement(node)) {
1650
- // This element was passed in a valid location.
1651
- if (node._store) {
1652
- node._store.validated = true;
1653
- }
1654
- } else if (node) {
1655
- var iteratorFn = getIteratorFn(node);
1656
-
1657
- if (typeof iteratorFn === 'function') {
1658
- // Entry iterators used to provide implicit keys,
1659
- // but now we print a separate warning for them later.
1660
- if (iteratorFn !== node.entries) {
1661
- var iterator = iteratorFn.call(node);
1662
- var step;
1663
-
1664
- while (!(step = iterator.next()).done) {
1665
- if (isValidElement(step.value)) {
1666
- validateExplicitKey(step.value, parentType);
1667
- }
1668
- }
1669
- }
1670
- }
1671
- }
1672
- }
1673
- }
1674
- /**
1675
- * Given an element, validate that its props follow the propTypes definition,
1676
- * provided by the type.
1677
- *
1678
- * @param {ReactElement} element
1679
- */
1680
-
1681
-
1682
- function validatePropTypes(element) {
1683
- {
1684
- var type = element.type;
1685
-
1686
- if (type === null || type === undefined || typeof type === 'string') {
1687
- return;
1688
- }
1689
-
1690
- var propTypes;
1691
-
1692
- if (typeof type === 'function') {
1693
- propTypes = type.propTypes;
1694
- } else if (_typeof(type) === 'object' && (type.$$typeof === REACT_FORWARD_REF_TYPE || // Note: Memo only checks outer props here.
1695
- // Inner props are checked in the reconciler.
1696
- type.$$typeof === REACT_MEMO_TYPE)) {
1697
- propTypes = type.propTypes;
1698
- } else {
1699
- return;
1700
- }
1701
-
1702
- if (propTypes) {
1703
- // Intentionally inside to avoid triggering lazy initializers:
1704
- var name = getComponentName(type);
1705
- checkPropTypes(propTypes, element.props, 'prop', name, element);
1706
- } else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) {
1707
- propTypesMisspellWarningShown = true; // Intentionally inside to avoid triggering lazy initializers:
1708
-
1709
- var _name = getComponentName(type);
1710
-
1711
- error('Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', _name || 'Unknown');
1712
- }
1713
-
1714
- if (typeof type.getDefaultProps === 'function' && !type.getDefaultProps.isReactClassApproved) {
1715
- error('getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.');
1716
- }
1717
- }
1718
- }
1719
- /**
1720
- * Given a fragment, validate that it can only be provided with fragment props
1721
- * @param {ReactElement} fragment
1722
- */
1723
-
1724
-
1725
- function validateFragmentProps(fragment) {
1726
- {
1727
- var keys = Object.keys(fragment.props);
1728
-
1729
- for (var i = 0; i < keys.length; i++) {
1730
- var key = keys[i];
1731
-
1732
- if (key !== 'children' && key !== 'key') {
1733
- setCurrentlyValidatingElement$1(fragment);
1734
- error('Invalid prop `%s` supplied to `React.Fragment`. ' + 'React.Fragment can only have `key` and `children` props.', key);
1735
- setCurrentlyValidatingElement$1(null);
1736
- break;
1737
- }
1738
- }
1739
-
1740
- if (fragment.ref !== null) {
1741
- setCurrentlyValidatingElement$1(fragment);
1742
- error('Invalid attribute `ref` supplied to `React.Fragment`.');
1743
- setCurrentlyValidatingElement$1(null);
1744
- }
1745
- }
1746
- }
1747
-
1748
- function jsxWithValidation(type, props, key, isStaticChildren, source, self) {
1749
- {
1750
- var validType = isValidElementType(type); // We warn in this case but don't throw. We expect the element creation to
1751
- // succeed and there will likely be errors in render.
1752
-
1753
- if (!validType) {
1754
- var info = '';
1755
-
1756
- if (type === undefined || _typeof(type) === 'object' && type !== null && Object.keys(type).length === 0) {
1757
- info += ' You likely forgot to export your component from the file ' + "it's defined in, or you might have mixed up default and named imports.";
1758
- }
1759
-
1760
- var sourceInfo = getSourceInfoErrorAddendum(source);
1761
-
1762
- if (sourceInfo) {
1763
- info += sourceInfo;
1764
- } else {
1765
- info += getDeclarationErrorAddendum();
1766
- }
1767
-
1768
- var typeString;
1769
-
1770
- if (type === null) {
1771
- typeString = 'null';
1772
- } else if (Array.isArray(type)) {
1773
- typeString = 'array';
1774
- } else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
1775
- typeString = "<" + (getComponentName(type.type) || 'Unknown') + " />";
1776
- info = ' Did you accidentally export a JSX literal instead of a component?';
1777
- } else {
1778
- typeString = _typeof(type);
1779
- }
1780
-
1781
- error('React.jsx: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', typeString, info);
1782
- }
1783
-
1784
- var element = jsxDEV(type, props, key, source, self); // The result can be nullish if a mock or a custom function is used.
1785
- // TODO: Drop this when these are no longer allowed as the type argument.
1786
-
1787
- if (element == null) {
1788
- return element;
1789
- } // Skip key warning if the type isn't valid since our key validation logic
1790
- // doesn't expect a non-string/function type and can throw confusing errors.
1791
- // We don't want exception behavior to differ between dev and prod.
1792
- // (Rendering will throw with a helpful message and as soon as the type is
1793
- // fixed, the key warnings will appear.)
1794
-
1795
-
1796
- if (validType) {
1797
- var children = props.children;
1798
-
1799
- if (children !== undefined) {
1800
- if (isStaticChildren) {
1801
- if (Array.isArray(children)) {
1802
- for (var i = 0; i < children.length; i++) {
1803
- validateChildKeys(children[i], type);
1804
- }
1805
-
1806
- if (Object.freeze) {
1807
- Object.freeze(children);
1808
- }
1809
- } else {
1810
- error('React.jsx: Static children should always be an array. ' + 'You are likely explicitly calling React.jsxs or React.jsxDEV. ' + 'Use the Babel transform instead.');
1811
- }
1812
- } else {
1813
- validateChildKeys(children, type);
1814
- }
1815
- }
1816
- }
1817
-
1818
- if (type === exports.Fragment) {
1819
- validateFragmentProps(element);
1820
- } else {
1821
- validatePropTypes(element);
1822
- }
1823
-
1824
- return element;
1825
- }
1826
- } // These two functions exist to still get child warnings in dev
1827
- // even with the prod transform. This means that jsxDEV is purely
1828
- // opt-in behavior for better messages but that we won't stop
1829
- // giving you warnings if you use production apis.
1830
-
1831
-
1832
- function jsxWithValidationStatic(type, props, key) {
1833
- {
1834
- return jsxWithValidation(type, props, key, true);
1835
- }
1836
- }
1837
-
1838
- function jsxWithValidationDynamic(type, props, key) {
1839
- {
1840
- return jsxWithValidation(type, props, key, false);
1841
- }
1842
- }
1843
-
1844
- var jsx = jsxWithValidationDynamic; // we may want to special case jsxs internally to take advantage of static children.
1845
- // for now we can ship identical prod functions
1846
-
1847
- var jsxs = jsxWithValidationStatic;
1848
- exports.jsx = jsx;
1849
- exports.jsxs = jsxs;
1850
- })();
1851
- }
1852
- });
1853
-
1854
- var jsxRuntime = createCommonjsModule(function (module) {
1855
-
1856
- if (process.env.NODE_ENV === 'production') {
1857
- module.exports = reactJsxRuntime_production_min;
1858
- } else {
1859
- module.exports = reactJsxRuntime_development;
1860
- }
1861
- });
1862
-
1863
- var initialDefaultOptions = function initialDefaultOptions() {
1864
- return tus.defaultOptions;
1865
- };
1866
- var TusHandler = /*#__PURE__*/function () {
1867
- function TusHandler(tusConfigs) {
1868
- _classCallCheck(this, TusHandler);
1869
-
1870
- var _ref = tusConfigs || {},
1871
- _ref$canStoreURLs = _ref.canStoreURLs,
1872
- canStoreURLs = _ref$canStoreURLs === void 0 ? tus.canStoreURLs : _ref$canStoreURLs,
1873
- _ref$defaultOptions = _ref.defaultOptions,
1874
- defaultOptions = _ref$defaultOptions === void 0 ? initialDefaultOptions : _ref$defaultOptions;
1875
-
1876
- this.tus = _objectSpread2(_objectSpread2({}, tus), {}, {
1877
- canStoreURLs: canStoreURLs,
1878
- defaultOptions: defaultOptions
1879
- });
1880
- }
1881
-
1882
- _createClass(TusHandler, [{
1883
- key: "getTus",
1884
- get: function get() {
1885
- return this.tus;
1886
- }
1887
- }]);
1888
-
1889
- return TusHandler;
1890
- }();
485
+ }, [targetTusState, setUpload, remove]);
486
+ useAutoAbort(tusResult.upload, autoAbort !== null && autoAbort !== void 0 ? autoAbort : false);
487
+ return tusResult;
488
+ };
1891
489
 
1892
490
  var tusClientReducer = function tusClientReducer(state, actions) {
1893
491
  switch (actions.type) {
1894
- case 'INSERT_UPLOAD_INSTANCE':
492
+ case "INSERT_UPLOAD_INSTANCE":
1895
493
  {
1896
494
  var _actions$payload = actions.payload,
1897
- cacheKey = _actions$payload.cacheKey,
495
+ _cacheKey = _actions$payload.cacheKey,
1898
496
  uploadState = _actions$payload.uploadState;
1899
497
  return _objectSpread2(_objectSpread2({}, state), {}, {
1900
- uploads: _objectSpread2(_objectSpread2({}, state.uploads), {}, _defineProperty({}, cacheKey, uploadState))
498
+ uploads: _objectSpread2(_objectSpread2({}, state.uploads), {}, _defineProperty({}, _cacheKey, uploadState))
1901
499
  });
1902
500
  }
1903
501
 
1904
- case 'UPDATE_SUCCESS_UPLOAD':
502
+ case "UPDATE_SUCCESS_UPLOAD":
1905
503
  {
1906
- var _cacheKey = actions.payload.cacheKey;
1907
- var target = state.uploads[_cacheKey];
504
+ var _cacheKey2 = actions.payload.cacheKey;
505
+ var target = state.uploads[_cacheKey2];
1908
506
 
1909
507
  if (!target) {
1910
508
  return state;
1911
509
  }
1912
510
 
1913
511
  return _objectSpread2(_objectSpread2({}, state), {}, {
1914
- uploads: _objectSpread2(_objectSpread2({}, state.uploads), {}, _defineProperty({}, _cacheKey, _objectSpread2(_objectSpread2({}, target || {}), {}, {
512
+ uploads: _objectSpread2(_objectSpread2({}, state.uploads), {}, _defineProperty({}, _cacheKey2, _objectSpread2(_objectSpread2({}, target || {}), {}, {
1915
513
  isSuccess: true
1916
514
  })))
1917
515
  });
1918
516
  }
1919
517
 
1920
- case 'UPDATE_ERROR_UPLOAD':
518
+ case "UPDATE_ERROR_UPLOAD":
1921
519
  {
1922
520
  var _actions$payload2 = actions.payload,
1923
- _cacheKey2 = _actions$payload2.cacheKey,
521
+ _cacheKey3 = _actions$payload2.cacheKey,
1924
522
  error = _actions$payload2.error;
1925
- var _target = state.uploads[_cacheKey2];
523
+ var _target = state.uploads[_cacheKey3];
1926
524
 
1927
525
  if (!_target) {
1928
526
  return state;
1929
527
  }
1930
528
 
1931
529
  return _objectSpread2(_objectSpread2({}, state), {}, {
1932
- uploads: _objectSpread2(_objectSpread2({}, state.uploads), {}, _defineProperty({}, _cacheKey2, _objectSpread2(_objectSpread2({}, _target), {}, {
530
+ uploads: _objectSpread2(_objectSpread2({}, state.uploads), {}, _defineProperty({}, _cacheKey3, _objectSpread2(_objectSpread2({}, _target), {}, {
1933
531
  error: error
1934
532
  })))
1935
533
  });
1936
534
  }
1937
535
 
1938
- case 'UPDATE_IS_ABORTED_UPLOAD':
536
+ case "UPDATE_IS_ABORTED_UPLOAD":
1939
537
  {
1940
538
  var _actions$payload3 = actions.payload,
1941
- _cacheKey3 = _actions$payload3.cacheKey,
539
+ _cacheKey4 = _actions$payload3.cacheKey,
1942
540
  isAborted = _actions$payload3.isAborted;
1943
- var _target2 = state.uploads[_cacheKey3];
541
+ var _target2 = state.uploads[_cacheKey4];
1944
542
 
1945
543
  if (!_target2) {
1946
544
  return state;
1947
545
  }
1948
546
 
1949
547
  return _objectSpread2(_objectSpread2({}, state), {}, {
1950
- uploads: _objectSpread2(_objectSpread2({}, state.uploads), {}, _defineProperty({}, _cacheKey3, _objectSpread2(_objectSpread2({}, _target2), {}, {
548
+ uploads: _objectSpread2(_objectSpread2({}, state.uploads), {}, _defineProperty({}, _cacheKey4, _objectSpread2(_objectSpread2({}, _target2), {}, {
1951
549
  isAborted: isAborted
1952
550
  })))
1953
551
  });
1954
552
  }
1955
553
 
1956
- case 'REMOVE_UPLOAD_INSTANCE':
554
+ case "REMOVE_UPLOAD_INSTANCE":
1957
555
  {
1958
- var _cacheKey4 = actions.payload.cacheKey;
556
+ var _cacheKey5 = actions.payload.cacheKey;
1959
557
  var newUploads = state.uploads;
1960
- delete newUploads[_cacheKey4];
558
+ delete newUploads[_cacheKey5];
1961
559
  return _objectSpread2(_objectSpread2({}, state), {}, {
1962
560
  uploads: newUploads
1963
561
  });
1964
562
  }
1965
563
 
1966
- case 'UPDATE_TUS_HANDLER_OPTIONS':
564
+ case "UPDATE_DEFAULT_OPTIONS":
1967
565
  {
1968
- var _actions$payload4 = actions.payload,
1969
- canStoreURLs = _actions$payload4.canStoreURLs,
1970
- defaultOptions = _actions$payload4.defaultOptions;
566
+ var defaultOptions = actions.payload.defaultOptions;
1971
567
  return _objectSpread2(_objectSpread2({}, state), {}, {
1972
- tusHandler: new TusHandler({
1973
- canStoreURLs: canStoreURLs,
1974
- defaultOptions: defaultOptions
1975
- })
568
+ defaultOptions: defaultOptions
1976
569
  });
1977
570
  }
1978
571
 
@@ -1982,72 +575,40 @@ var tusClientReducer = function tusClientReducer(state, actions) {
1982
575
  };
1983
576
  var tusClientInitialState = {
1984
577
  uploads: {},
1985
- tusHandler: new TusHandler()
578
+ defaultOptions: undefined
1986
579
  };
1987
580
 
1988
- var TusController = function TusController(_ref) {
1989
- var canStoreURLs = _ref.canStoreURLs,
1990
- _ref$defaultOptions = _ref.defaultOptions,
1991
- defaultOptions = _ref$defaultOptions === void 0 ? initialDefaultOptions : _ref$defaultOptions,
581
+ var TusClientProvider = function TusClientProvider(_ref) {
582
+ var defaultOptions = _ref.defaultOptions,
1992
583
  children = _ref.children;
1993
584
 
1994
- var _useTusClientState = useTusClientState(),
1995
- tusHandler = _useTusClientState.tusHandler;
585
+ var _useReducer = useReducer(tusClientReducer, _objectSpread2(_objectSpread2({}, tusClientInitialState), {}, {
586
+ defaultOptions: defaultOptions
587
+ })),
588
+ _useReducer2 = _slicedToArray(_useReducer, 2),
589
+ tusClientState = _useReducer2[0],
590
+ tusClientDispatch = _useReducer2[1];
1996
591
 
1997
- var tus = tusHandler.getTus;
1998
- var tusClientDispatch = useTusClientDispatch();
1999
592
  useEffect(function () {
2000
- if (tusHandler.getTus.isSupported || process.env.NODE_ENV === 'production') {
593
+ if (isSupported || process.env.NODE_ENV === "production") {
2001
594
  return;
2002
- } // eslint-disable-next-line no-console
2003
-
595
+ }
2004
596
 
2005
597
  console.error(ERROR_MESSAGES.tusIsNotSupported);
2006
- }, [tusHandler.getTus.isSupported]);
598
+ }, []);
2007
599
  useEffect(function () {
2008
- if (tus.defaultOptions === defaultOptions && tus.canStoreURLs === canStoreURLs) {
600
+ if (tusClientState.defaultOptions === defaultOptions) {
2009
601
  return;
2010
602
  }
2011
603
 
2012
- tusClientDispatch(updateTusHandlerOptions({
2013
- canStoreURLs: canStoreURLs,
2014
- defaultOptions: defaultOptions
2015
- }));
2016
- }, [tusClientDispatch, canStoreURLs, defaultOptions, tus.canStoreURLs, tus.defaultOptions]);
2017
- return jsxRuntime.jsx(jsxRuntime.Fragment, {
2018
- children: children
2019
- }, void 0);
2020
- };
2021
-
2022
- var TusClientProvider = function TusClientProvider(_ref) {
2023
- var canStoreURLs = _ref.canStoreURLs,
2024
- defaultOptions = _ref.defaultOptions,
2025
- children = _ref.children;
2026
-
2027
- var _useReducer = useReducer(tusClientReducer, _objectSpread2(_objectSpread2({}, tusClientInitialState), {}, {
2028
- tusHandler: new TusHandler({
2029
- canStoreURLs: canStoreURLs,
2030
- defaultOptions: defaultOptions
2031
- })
2032
- })),
2033
- _useReducer2 = _slicedToArray(_useReducer, 2),
2034
- tusClientState = _useReducer2[0],
2035
- tusClientDispatch = _useReducer2[1];
2036
-
2037
- return jsxRuntime.jsx(TusClientStateContext.Provider, Object.assign({
604
+ tusClientDispatch(updateDefaultOptions(defaultOptions));
605
+ }, [defaultOptions, tusClientState.defaultOptions]);
606
+ var tusClientDispatchContextProviderElement = createElement(TusClientDispatchContext.Provider, {
607
+ value: tusClientDispatch
608
+ }, children);
609
+ return createElement(TusClientStateContext.Provider, {
2038
610
  value: tusClientState
2039
- }, {
2040
- children: jsxRuntime.jsx(TusClientDispatchContext.Provider, Object.assign({
2041
- value: tusClientDispatch
2042
- }, {
2043
- children: jsxRuntime.jsx(TusController, Object.assign({
2044
- canStoreURLs: canStoreURLs,
2045
- defaultOptions: defaultOptions
2046
- }, {
2047
- children: children
2048
- }), void 0)
2049
- }), void 0)
2050
- }), void 0);
611
+ }, tusClientDispatchContextProviderElement);
2051
612
  };
2052
613
 
2053
- export { TusClientProvider, useTus };
614
+ export { TusClientProvider, useTus, useTusStore };