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