UNPKG

102 kBJavaScriptView Raw
1/** @license React v16.8.2
2 * react.development.js
3 *
4 * Copyright (c) Facebook, Inc. and its affiliates.
5 *
6 * This source code is licensed under the MIT license found in the
7 * LICENSE file in the root directory of this source tree.
8 */
9
10'use strict';
11
12(function (global, factory) {
13 typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
14 typeof define === 'function' && define.amd ? define(factory) :
15 (global.React = factory());
16}(this, (function () { 'use strict';
17
18// TODO: this is special because it gets imported during build.
19
20var ReactVersion = '16.8.2';
21
22// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
23// nor polyfill, then a plain number is used for performance.
24var hasSymbol = typeof Symbol === 'function' && Symbol.for;
25
26var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
27var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
28var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
29var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
30var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
31var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
32var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
33
34var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
35var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
36var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
37var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
38var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
39
40var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
41var FAUX_ITERATOR_SYMBOL = '@@iterator';
42
43function getIteratorFn(maybeIterable) {
44 if (maybeIterable === null || typeof maybeIterable !== 'object') {
45 return null;
46 }
47 var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
48 if (typeof maybeIterator === 'function') {
49 return maybeIterator;
50 }
51 return null;
52}
53
54/*
55object-assign
56(c) Sindre Sorhus
57@license MIT
58*/
59
60
61/* eslint-disable no-unused-vars */
62var getOwnPropertySymbols = Object.getOwnPropertySymbols;
63var hasOwnProperty = Object.prototype.hasOwnProperty;
64var propIsEnumerable = Object.prototype.propertyIsEnumerable;
65
66function toObject(val) {
67 if (val === null || val === undefined) {
68 throw new TypeError('Object.assign cannot be called with null or undefined');
69 }
70
71 return Object(val);
72}
73
74function shouldUseNative() {
75 try {
76 if (!Object.assign) {
77 return false;
78 }
79
80 // Detect buggy property enumeration order in older V8 versions.
81
82 // https://bugs.chromium.org/p/v8/issues/detail?id=4118
83 var test1 = new String('abc'); // eslint-disable-line no-new-wrappers
84 test1[5] = 'de';
85 if (Object.getOwnPropertyNames(test1)[0] === '5') {
86 return false;
87 }
88
89 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
90 var test2 = {};
91 for (var i = 0; i < 10; i++) {
92 test2['_' + String.fromCharCode(i)] = i;
93 }
94 var order2 = Object.getOwnPropertyNames(test2).map(function (n) {
95 return test2[n];
96 });
97 if (order2.join('') !== '0123456789') {
98 return false;
99 }
100
101 // https://bugs.chromium.org/p/v8/issues/detail?id=3056
102 var test3 = {};
103 'abcdefghijklmnopqrst'.split('').forEach(function (letter) {
104 test3[letter] = letter;
105 });
106 if (Object.keys(Object.assign({}, test3)).join('') !==
107 'abcdefghijklmnopqrst') {
108 return false;
109 }
110
111 return true;
112 } catch (err) {
113 // We don't expect any of the above to throw, but better to be safe.
114 return false;
115 }
116}
117
118var objectAssign = shouldUseNative() ? Object.assign : function (target, source) {
119 var from;
120 var to = toObject(target);
121 var symbols;
122
123 for (var s = 1; s < arguments.length; s++) {
124 from = Object(arguments[s]);
125
126 for (var key in from) {
127 if (hasOwnProperty.call(from, key)) {
128 to[key] = from[key];
129 }
130 }
131
132 if (getOwnPropertySymbols) {
133 symbols = getOwnPropertySymbols(from);
134 for (var i = 0; i < symbols.length; i++) {
135 if (propIsEnumerable.call(from, symbols[i])) {
136 to[symbols[i]] = from[symbols[i]];
137 }
138 }
139 }
140 }
141
142 return to;
143};
144
145/**
146 * Use invariant() to assert state which your program assumes to be true.
147 *
148 * Provide sprintf-style format (only %s is supported) and arguments
149 * to provide information about what broke and what you were
150 * expecting.
151 *
152 * The invariant message will be stripped in production, but the invariant
153 * will remain to ensure logic does not differ in production.
154 */
155
156var validateFormat = function () {};
157
158{
159 validateFormat = function (format) {
160 if (format === undefined) {
161 throw new Error('invariant requires an error message argument');
162 }
163 };
164}
165
166function invariant(condition, format, a, b, c, d, e, f) {
167 validateFormat(format);
168
169 if (!condition) {
170 var error = void 0;
171 if (format === undefined) {
172 error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
173 } else {
174 var args = [a, b, c, d, e, f];
175 var argIndex = 0;
176 error = new Error(format.replace(/%s/g, function () {
177 return args[argIndex++];
178 }));
179 error.name = 'Invariant Violation';
180 }
181
182 error.framesToPop = 1; // we don't care about invariant's own frame
183 throw error;
184 }
185}
186
187// Relying on the `invariant()` implementation lets us
188// preserve the format and params in the www builds.
189
190/**
191 * Forked from fbjs/warning:
192 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
193 *
194 * Only change is we use console.warn instead of console.error,
195 * and do nothing when 'console' is not supported.
196 * This really simplifies the code.
197 * ---
198 * Similar to invariant but only logs a warning if the condition is not met.
199 * This can be used to log issues in development environments in critical
200 * paths. Removing the logging code for production environments will keep the
201 * same logic and follow the same code paths.
202 */
203
204var lowPriorityWarning = function () {};
205
206{
207 var printWarning = function (format) {
208 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
209 args[_key - 1] = arguments[_key];
210 }
211
212 var argIndex = 0;
213 var message = 'Warning: ' + format.replace(/%s/g, function () {
214 return args[argIndex++];
215 });
216 if (typeof console !== 'undefined') {
217 console.warn(message);
218 }
219 try {
220 // --- Welcome to debugging React ---
221 // This error was thrown as a convenience so that you can use this stack
222 // to find the callsite that caused this warning to fire.
223 throw new Error(message);
224 } catch (x) {}
225 };
226
227 lowPriorityWarning = function (condition, format) {
228 if (format === undefined) {
229 throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
230 }
231 if (!condition) {
232 for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
233 args[_key2 - 2] = arguments[_key2];
234 }
235
236 printWarning.apply(undefined, [format].concat(args));
237 }
238 };
239}
240
241var lowPriorityWarning$1 = lowPriorityWarning;
242
243/**
244 * Similar to invariant but only logs a warning if the condition is not met.
245 * This can be used to log issues in development environments in critical
246 * paths. Removing the logging code for production environments will keep the
247 * same logic and follow the same code paths.
248 */
249
250var warningWithoutStack = function () {};
251
252{
253 warningWithoutStack = function (condition, format) {
254 for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
255 args[_key - 2] = arguments[_key];
256 }
257
258 if (format === undefined) {
259 throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
260 }
261 if (args.length > 8) {
262 // Check before the condition to catch violations early.
263 throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
264 }
265 if (condition) {
266 return;
267 }
268 if (typeof console !== 'undefined') {
269 var argsWithFormat = args.map(function (item) {
270 return '' + item;
271 });
272 argsWithFormat.unshift('Warning: ' + format);
273
274 // We intentionally don't use spread (or .apply) directly because it
275 // breaks IE9: https://github.com/facebook/react/issues/13610
276 Function.prototype.apply.call(console.error, console, argsWithFormat);
277 }
278 try {
279 // --- Welcome to debugging React ---
280 // This error was thrown as a convenience so that you can use this stack
281 // to find the callsite that caused this warning to fire.
282 var argIndex = 0;
283 var message = 'Warning: ' + format.replace(/%s/g, function () {
284 return args[argIndex++];
285 });
286 throw new Error(message);
287 } catch (x) {}
288 };
289}
290
291var warningWithoutStack$1 = warningWithoutStack;
292
293var didWarnStateUpdateForUnmountedComponent = {};
294
295function warnNoop(publicInstance, callerName) {
296 {
297 var _constructor = publicInstance.constructor;
298 var componentName = _constructor && (_constructor.displayName || _constructor.name) || 'ReactClass';
299 var warningKey = componentName + '.' + callerName;
300 if (didWarnStateUpdateForUnmountedComponent[warningKey]) {
301 return;
302 }
303 warningWithoutStack$1(false, "Can't call %s on a component that is not yet mounted. " + 'This is a no-op, but it might indicate a bug in your application. ' + 'Instead, assign to `this.state` directly or define a `state = {};` ' + 'class property with the desired state in the %s component.', callerName, componentName);
304 didWarnStateUpdateForUnmountedComponent[warningKey] = true;
305 }
306}
307
308/**
309 * This is the abstract API for an update queue.
310 */
311var ReactNoopUpdateQueue = {
312 /**
313 * Checks whether or not this composite component is mounted.
314 * @param {ReactClass} publicInstance The instance we want to test.
315 * @return {boolean} True if mounted, false otherwise.
316 * @protected
317 * @final
318 */
319 isMounted: function (publicInstance) {
320 return false;
321 },
322
323 /**
324 * Forces an update. This should only be invoked when it is known with
325 * certainty that we are **not** in a DOM transaction.
326 *
327 * You may want to call this when you know that some deeper aspect of the
328 * component's state has changed but `setState` was not called.
329 *
330 * This will not invoke `shouldComponentUpdate`, but it will invoke
331 * `componentWillUpdate` and `componentDidUpdate`.
332 *
333 * @param {ReactClass} publicInstance The instance that should rerender.
334 * @param {?function} callback Called after component is updated.
335 * @param {?string} callerName name of the calling function in the public API.
336 * @internal
337 */
338 enqueueForceUpdate: function (publicInstance, callback, callerName) {
339 warnNoop(publicInstance, 'forceUpdate');
340 },
341
342 /**
343 * Replaces all of the state. Always use this or `setState` to mutate state.
344 * You should treat `this.state` as immutable.
345 *
346 * There is no guarantee that `this.state` will be immediately updated, so
347 * accessing `this.state` after calling this method may return the old value.
348 *
349 * @param {ReactClass} publicInstance The instance that should rerender.
350 * @param {object} completeState Next state.
351 * @param {?function} callback Called after component is updated.
352 * @param {?string} callerName name of the calling function in the public API.
353 * @internal
354 */
355 enqueueReplaceState: function (publicInstance, completeState, callback, callerName) {
356 warnNoop(publicInstance, 'replaceState');
357 },
358
359 /**
360 * Sets a subset of the state. This only exists because _pendingState is
361 * internal. This provides a merging strategy that is not available to deep
362 * properties which is confusing. TODO: Expose pendingState or don't use it
363 * during the merge.
364 *
365 * @param {ReactClass} publicInstance The instance that should rerender.
366 * @param {object} partialState Next partial state to be merged with state.
367 * @param {?function} callback Called after component is updated.
368 * @param {?string} Name of the calling function in the public API.
369 * @internal
370 */
371 enqueueSetState: function (publicInstance, partialState, callback, callerName) {
372 warnNoop(publicInstance, 'setState');
373 }
374};
375
376var emptyObject = {};
377{
378 Object.freeze(emptyObject);
379}
380
381/**
382 * Base class helpers for the updating state of a component.
383 */
384function Component(props, context, updater) {
385 this.props = props;
386 this.context = context;
387 // If a component has string refs, we will assign a different object later.
388 this.refs = emptyObject;
389 // We initialize the default updater but the real one gets injected by the
390 // renderer.
391 this.updater = updater || ReactNoopUpdateQueue;
392}
393
394Component.prototype.isReactComponent = {};
395
396/**
397 * Sets a subset of the state. Always use this to mutate
398 * state. You should treat `this.state` as immutable.
399 *
400 * There is no guarantee that `this.state` will be immediately updated, so
401 * accessing `this.state` after calling this method may return the old value.
402 *
403 * There is no guarantee that calls to `setState` will run synchronously,
404 * as they may eventually be batched together. You can provide an optional
405 * callback that will be executed when the call to setState is actually
406 * completed.
407 *
408 * When a function is provided to setState, it will be called at some point in
409 * the future (not synchronously). It will be called with the up to date
410 * component arguments (state, props, context). These values can be different
411 * from this.* because your function may be called after receiveProps but before
412 * shouldComponentUpdate, and this new state, props, and context will not yet be
413 * assigned to this.
414 *
415 * @param {object|function} partialState Next partial state or function to
416 * produce next partial state to be merged with current state.
417 * @param {?function} callback Called after state is updated.
418 * @final
419 * @protected
420 */
421Component.prototype.setState = function (partialState, callback) {
422 !(typeof partialState === 'object' || typeof partialState === 'function' || partialState == null) ? invariant(false, 'setState(...): takes an object of state variables to update or a function which returns an object of state variables.') : void 0;
423 this.updater.enqueueSetState(this, partialState, callback, 'setState');
424};
425
426/**
427 * Forces an update. This should only be invoked when it is known with
428 * certainty that we are **not** in a DOM transaction.
429 *
430 * You may want to call this when you know that some deeper aspect of the
431 * component's state has changed but `setState` was not called.
432 *
433 * This will not invoke `shouldComponentUpdate`, but it will invoke
434 * `componentWillUpdate` and `componentDidUpdate`.
435 *
436 * @param {?function} callback Called after update is complete.
437 * @final
438 * @protected
439 */
440Component.prototype.forceUpdate = function (callback) {
441 this.updater.enqueueForceUpdate(this, callback, 'forceUpdate');
442};
443
444/**
445 * Deprecated APIs. These APIs used to exist on classic React classes but since
446 * we would like to deprecate them, we're not going to move them over to this
447 * modern base class. Instead, we define a getter that warns if it's accessed.
448 */
449{
450 var deprecatedAPIs = {
451 isMounted: ['isMounted', 'Instead, make sure to clean up subscriptions and pending requests in ' + 'componentWillUnmount to prevent memory leaks.'],
452 replaceState: ['replaceState', 'Refactor your code to use setState instead (see ' + 'https://github.com/facebook/react/issues/3236).']
453 };
454 var defineDeprecationWarning = function (methodName, info) {
455 Object.defineProperty(Component.prototype, methodName, {
456 get: function () {
457 lowPriorityWarning$1(false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]);
458 return undefined;
459 }
460 });
461 };
462 for (var fnName in deprecatedAPIs) {
463 if (deprecatedAPIs.hasOwnProperty(fnName)) {
464 defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
465 }
466 }
467}
468
469function ComponentDummy() {}
470ComponentDummy.prototype = Component.prototype;
471
472/**
473 * Convenience component with default shallow equality check for sCU.
474 */
475function PureComponent(props, context, updater) {
476 this.props = props;
477 this.context = context;
478 // If a component has string refs, we will assign a different object later.
479 this.refs = emptyObject;
480 this.updater = updater || ReactNoopUpdateQueue;
481}
482
483var pureComponentPrototype = PureComponent.prototype = new ComponentDummy();
484pureComponentPrototype.constructor = PureComponent;
485// Avoid an extra prototype jump for these methods.
486objectAssign(pureComponentPrototype, Component.prototype);
487pureComponentPrototype.isPureReactComponent = true;
488
489// an immutable object with a single mutable value
490function createRef() {
491 var refObject = {
492 current: null
493 };
494 {
495 Object.seal(refObject);
496 }
497 return refObject;
498}
499
500var enableSchedulerDebugging = false;
501
502/* eslint-disable no-var */
503
504// TODO: Use symbols?
505var ImmediatePriority = 1;
506var UserBlockingPriority = 2;
507var NormalPriority = 3;
508var LowPriority = 4;
509var IdlePriority = 5;
510
511// Max 31 bit integer. The max integer size in V8 for 32-bit systems.
512// Math.pow(2, 30) - 1
513// 0b111111111111111111111111111111
514var maxSigned31BitInt = 1073741823;
515
516// Times out immediately
517var IMMEDIATE_PRIORITY_TIMEOUT = -1;
518// Eventually times out
519var USER_BLOCKING_PRIORITY = 250;
520var NORMAL_PRIORITY_TIMEOUT = 5000;
521var LOW_PRIORITY_TIMEOUT = 10000;
522// Never times out
523var IDLE_PRIORITY = maxSigned31BitInt;
524
525// Callbacks are stored as a circular, doubly linked list.
526var firstCallbackNode = null;
527
528var currentDidTimeout = false;
529// Pausing the scheduler is useful for debugging.
530var isSchedulerPaused = false;
531
532var currentPriorityLevel = NormalPriority;
533var currentEventStartTime = -1;
534var currentExpirationTime = -1;
535
536// This is set when a callback is being executed, to prevent re-entrancy.
537var isExecutingCallback = false;
538
539var isHostCallbackScheduled = false;
540
541var hasNativePerformanceNow = typeof performance === 'object' && typeof performance.now === 'function';
542
543function ensureHostCallbackIsScheduled() {
544 if (isExecutingCallback) {
545 // Don't schedule work yet; wait until the next time we yield.
546 return;
547 }
548 // Schedule the host callback using the earliest expiration in the list.
549 var expirationTime = firstCallbackNode.expirationTime;
550 if (!isHostCallbackScheduled) {
551 isHostCallbackScheduled = true;
552 } else {
553 // Cancel the existing host callback.
554 cancelHostCallback();
555 }
556 requestHostCallback(flushWork, expirationTime);
557}
558
559function flushFirstCallback() {
560 var flushedNode = firstCallbackNode;
561
562 // Remove the node from the list before calling the callback. That way the
563 // list is in a consistent state even if the callback throws.
564 var next = firstCallbackNode.next;
565 if (firstCallbackNode === next) {
566 // This is the last callback in the list.
567 firstCallbackNode = null;
568 next = null;
569 } else {
570 var lastCallbackNode = firstCallbackNode.previous;
571 firstCallbackNode = lastCallbackNode.next = next;
572 next.previous = lastCallbackNode;
573 }
574
575 flushedNode.next = flushedNode.previous = null;
576
577 // Now it's safe to call the callback.
578 var callback = flushedNode.callback;
579 var expirationTime = flushedNode.expirationTime;
580 var priorityLevel = flushedNode.priorityLevel;
581 var previousPriorityLevel = currentPriorityLevel;
582 var previousExpirationTime = currentExpirationTime;
583 currentPriorityLevel = priorityLevel;
584 currentExpirationTime = expirationTime;
585 var continuationCallback;
586 try {
587 continuationCallback = callback();
588 } finally {
589 currentPriorityLevel = previousPriorityLevel;
590 currentExpirationTime = previousExpirationTime;
591 }
592
593 // A callback may return a continuation. The continuation should be scheduled
594 // with the same priority and expiration as the just-finished callback.
595 if (typeof continuationCallback === 'function') {
596 var continuationNode = {
597 callback: continuationCallback,
598 priorityLevel: priorityLevel,
599 expirationTime: expirationTime,
600 next: null,
601 previous: null
602 };
603
604 // Insert the new callback into the list, sorted by its expiration. This is
605 // almost the same as the code in `scheduleCallback`, except the callback
606 // is inserted into the list *before* callbacks of equal expiration instead
607 // of after.
608 if (firstCallbackNode === null) {
609 // This is the first callback in the list.
610 firstCallbackNode = continuationNode.next = continuationNode.previous = continuationNode;
611 } else {
612 var nextAfterContinuation = null;
613 var node = firstCallbackNode;
614 do {
615 if (node.expirationTime >= expirationTime) {
616 // This callback expires at or after the continuation. We will insert
617 // the continuation *before* this callback.
618 nextAfterContinuation = node;
619 break;
620 }
621 node = node.next;
622 } while (node !== firstCallbackNode);
623
624 if (nextAfterContinuation === null) {
625 // No equal or lower priority callback was found, which means the new
626 // callback is the lowest priority callback in the list.
627 nextAfterContinuation = firstCallbackNode;
628 } else if (nextAfterContinuation === firstCallbackNode) {
629 // The new callback is the highest priority callback in the list.
630 firstCallbackNode = continuationNode;
631 ensureHostCallbackIsScheduled();
632 }
633
634 var previous = nextAfterContinuation.previous;
635 previous.next = nextAfterContinuation.previous = continuationNode;
636 continuationNode.next = nextAfterContinuation;
637 continuationNode.previous = previous;
638 }
639 }
640}
641
642function flushImmediateWork() {
643 if (
644 // Confirm we've exited the outer most event handler
645 currentEventStartTime === -1 && firstCallbackNode !== null && firstCallbackNode.priorityLevel === ImmediatePriority) {
646 isExecutingCallback = true;
647 try {
648 do {
649 flushFirstCallback();
650 } while (
651 // Keep flushing until there are no more immediate callbacks
652 firstCallbackNode !== null && firstCallbackNode.priorityLevel === ImmediatePriority);
653 } finally {
654 isExecutingCallback = false;
655 if (firstCallbackNode !== null) {
656 // There's still work remaining. Request another callback.
657 ensureHostCallbackIsScheduled();
658 } else {
659 isHostCallbackScheduled = false;
660 }
661 }
662 }
663}
664
665function flushWork(didTimeout) {
666 // Exit right away if we're currently paused
667
668 if (enableSchedulerDebugging && isSchedulerPaused) {
669 return;
670 }
671
672 isExecutingCallback = true;
673 var previousDidTimeout = currentDidTimeout;
674 currentDidTimeout = didTimeout;
675 try {
676 if (didTimeout) {
677 // Flush all the expired callbacks without yielding.
678 while (firstCallbackNode !== null && !(enableSchedulerDebugging && isSchedulerPaused)) {
679 // TODO Wrap in feature flag
680 // Read the current time. Flush all the callbacks that expire at or
681 // earlier than that time. Then read the current time again and repeat.
682 // This optimizes for as few performance.now calls as possible.
683 var currentTime = getCurrentTime();
684 if (firstCallbackNode.expirationTime <= currentTime) {
685 do {
686 flushFirstCallback();
687 } while (firstCallbackNode !== null && firstCallbackNode.expirationTime <= currentTime && !(enableSchedulerDebugging && isSchedulerPaused));
688 continue;
689 }
690 break;
691 }
692 } else {
693 // Keep flushing callbacks until we run out of time in the frame.
694 if (firstCallbackNode !== null) {
695 do {
696 if (enableSchedulerDebugging && isSchedulerPaused) {
697 break;
698 }
699 flushFirstCallback();
700 } while (firstCallbackNode !== null && !shouldYieldToHost());
701 }
702 }
703 } finally {
704 isExecutingCallback = false;
705 currentDidTimeout = previousDidTimeout;
706 if (firstCallbackNode !== null) {
707 // There's still work remaining. Request another callback.
708 ensureHostCallbackIsScheduled();
709 } else {
710 isHostCallbackScheduled = false;
711 }
712 // Before exiting, flush all the immediate work that was scheduled.
713 flushImmediateWork();
714 }
715}
716
717function unstable_runWithPriority(priorityLevel, eventHandler) {
718 switch (priorityLevel) {
719 case ImmediatePriority:
720 case UserBlockingPriority:
721 case NormalPriority:
722 case LowPriority:
723 case IdlePriority:
724 break;
725 default:
726 priorityLevel = NormalPriority;
727 }
728
729 var previousPriorityLevel = currentPriorityLevel;
730 var previousEventStartTime = currentEventStartTime;
731 currentPriorityLevel = priorityLevel;
732 currentEventStartTime = getCurrentTime();
733
734 try {
735 return eventHandler();
736 } finally {
737 currentPriorityLevel = previousPriorityLevel;
738 currentEventStartTime = previousEventStartTime;
739
740 // Before exiting, flush all the immediate work that was scheduled.
741 flushImmediateWork();
742 }
743}
744
745function unstable_next(eventHandler) {
746 var priorityLevel = void 0;
747 switch (currentPriorityLevel) {
748 case ImmediatePriority:
749 case UserBlockingPriority:
750 case NormalPriority:
751 // Shift down to normal priority
752 priorityLevel = NormalPriority;
753 break;
754 default:
755 // Anything lower than normal priority should remain at the current level.
756 priorityLevel = currentPriorityLevel;
757 break;
758 }
759
760 var previousPriorityLevel = currentPriorityLevel;
761 var previousEventStartTime = currentEventStartTime;
762 currentPriorityLevel = priorityLevel;
763 currentEventStartTime = getCurrentTime();
764
765 try {
766 return eventHandler();
767 } finally {
768 currentPriorityLevel = previousPriorityLevel;
769 currentEventStartTime = previousEventStartTime;
770
771 // Before exiting, flush all the immediate work that was scheduled.
772 flushImmediateWork();
773 }
774}
775
776function unstable_wrapCallback(callback) {
777 var parentPriorityLevel = currentPriorityLevel;
778 return function () {
779 // This is a fork of runWithPriority, inlined for performance.
780 var previousPriorityLevel = currentPriorityLevel;
781 var previousEventStartTime = currentEventStartTime;
782 currentPriorityLevel = parentPriorityLevel;
783 currentEventStartTime = getCurrentTime();
784
785 try {
786 return callback.apply(this, arguments);
787 } finally {
788 currentPriorityLevel = previousPriorityLevel;
789 currentEventStartTime = previousEventStartTime;
790 flushImmediateWork();
791 }
792 };
793}
794
795function unstable_scheduleCallback(callback, deprecated_options) {
796 var startTime = currentEventStartTime !== -1 ? currentEventStartTime : getCurrentTime();
797
798 var expirationTime;
799 if (typeof deprecated_options === 'object' && deprecated_options !== null && typeof deprecated_options.timeout === 'number') {
800 // FIXME: Remove this branch once we lift expiration times out of React.
801 expirationTime = startTime + deprecated_options.timeout;
802 } else {
803 switch (currentPriorityLevel) {
804 case ImmediatePriority:
805 expirationTime = startTime + IMMEDIATE_PRIORITY_TIMEOUT;
806 break;
807 case UserBlockingPriority:
808 expirationTime = startTime + USER_BLOCKING_PRIORITY;
809 break;
810 case IdlePriority:
811 expirationTime = startTime + IDLE_PRIORITY;
812 break;
813 case LowPriority:
814 expirationTime = startTime + LOW_PRIORITY_TIMEOUT;
815 break;
816 case NormalPriority:
817 default:
818 expirationTime = startTime + NORMAL_PRIORITY_TIMEOUT;
819 }
820 }
821
822 var newNode = {
823 callback: callback,
824 priorityLevel: currentPriorityLevel,
825 expirationTime: expirationTime,
826 next: null,
827 previous: null
828 };
829
830 // Insert the new callback into the list, ordered first by expiration, then
831 // by insertion. So the new callback is inserted any other callback with
832 // equal expiration.
833 if (firstCallbackNode === null) {
834 // This is the first callback in the list.
835 firstCallbackNode = newNode.next = newNode.previous = newNode;
836 ensureHostCallbackIsScheduled();
837 } else {
838 var next = null;
839 var node = firstCallbackNode;
840 do {
841 if (node.expirationTime > expirationTime) {
842 // The new callback expires before this one.
843 next = node;
844 break;
845 }
846 node = node.next;
847 } while (node !== firstCallbackNode);
848
849 if (next === null) {
850 // No callback with a later expiration was found, which means the new
851 // callback has the latest expiration in the list.
852 next = firstCallbackNode;
853 } else if (next === firstCallbackNode) {
854 // The new callback has the earliest expiration in the entire list.
855 firstCallbackNode = newNode;
856 ensureHostCallbackIsScheduled();
857 }
858
859 var previous = next.previous;
860 previous.next = next.previous = newNode;
861 newNode.next = next;
862 newNode.previous = previous;
863 }
864
865 return newNode;
866}
867
868function unstable_pauseExecution() {
869 isSchedulerPaused = true;
870}
871
872function unstable_continueExecution() {
873 isSchedulerPaused = false;
874 if (firstCallbackNode !== null) {
875 ensureHostCallbackIsScheduled();
876 }
877}
878
879function unstable_getFirstCallbackNode() {
880 return firstCallbackNode;
881}
882
883function unstable_cancelCallback(callbackNode) {
884 var next = callbackNode.next;
885 if (next === null) {
886 // Already cancelled.
887 return;
888 }
889
890 if (next === callbackNode) {
891 // This is the only scheduled callback. Clear the list.
892 firstCallbackNode = null;
893 } else {
894 // Remove the callback from its position in the list.
895 if (callbackNode === firstCallbackNode) {
896 firstCallbackNode = next;
897 }
898 var previous = callbackNode.previous;
899 previous.next = next;
900 next.previous = previous;
901 }
902
903 callbackNode.next = callbackNode.previous = null;
904}
905
906function unstable_getCurrentPriorityLevel() {
907 return currentPriorityLevel;
908}
909
910function unstable_shouldYield() {
911 return !currentDidTimeout && (firstCallbackNode !== null && firstCallbackNode.expirationTime < currentExpirationTime || shouldYieldToHost());
912}
913
914// The remaining code is essentially a polyfill for requestIdleCallback. It
915// works by scheduling a requestAnimationFrame, storing the time for the start
916// of the frame, then scheduling a postMessage which gets scheduled after paint.
917// Within the postMessage handler do as much work as possible until time + frame
918// rate. By separating the idle call into a separate event tick we ensure that
919// layout, paint and other browser work is counted against the available time.
920// The frame rate is dynamically adjusted.
921
922// We capture a local reference to any global, in case it gets polyfilled after
923// this module is initially evaluated. We want to be using a
924// consistent implementation.
925var localDate = Date;
926
927// This initialization code may run even on server environments if a component
928// just imports ReactDOM (e.g. for findDOMNode). Some environments might not
929// have setTimeout or clearTimeout. However, we always expect them to be defined
930// on the client. https://github.com/facebook/react/pull/13088
931var localSetTimeout = typeof setTimeout === 'function' ? setTimeout : undefined;
932var localClearTimeout = typeof clearTimeout === 'function' ? clearTimeout : undefined;
933
934// We don't expect either of these to necessarily be defined, but we will error
935// later if they are missing on the client.
936var localRequestAnimationFrame = typeof requestAnimationFrame === 'function' ? requestAnimationFrame : undefined;
937var localCancelAnimationFrame = typeof cancelAnimationFrame === 'function' ? cancelAnimationFrame : undefined;
938
939var getCurrentTime;
940
941// requestAnimationFrame does not run when the tab is in the background. If
942// we're backgrounded we prefer for that work to happen so that the page
943// continues to load in the background. So we also schedule a 'setTimeout' as
944// a fallback.
945// TODO: Need a better heuristic for backgrounded work.
946var ANIMATION_FRAME_TIMEOUT = 100;
947var rAFID;
948var rAFTimeoutID;
949var requestAnimationFrameWithTimeout = function (callback) {
950 // schedule rAF and also a setTimeout
951 rAFID = localRequestAnimationFrame(function (timestamp) {
952 // cancel the setTimeout
953 localClearTimeout(rAFTimeoutID);
954 callback(timestamp);
955 });
956 rAFTimeoutID = localSetTimeout(function () {
957 // cancel the requestAnimationFrame
958 localCancelAnimationFrame(rAFID);
959 callback(getCurrentTime());
960 }, ANIMATION_FRAME_TIMEOUT);
961};
962
963if (hasNativePerformanceNow) {
964 var Performance = performance;
965 getCurrentTime = function () {
966 return Performance.now();
967 };
968} else {
969 getCurrentTime = function () {
970 return localDate.now();
971 };
972}
973
974var requestHostCallback;
975var cancelHostCallback;
976var shouldYieldToHost;
977
978var globalValue = null;
979if (typeof window !== 'undefined') {
980 globalValue = window;
981} else if (typeof global !== 'undefined') {
982 globalValue = global;
983}
984
985if (globalValue && globalValue._schedMock) {
986 // Dynamic injection, only for testing purposes.
987 var globalImpl = globalValue._schedMock;
988 requestHostCallback = globalImpl[0];
989 cancelHostCallback = globalImpl[1];
990 shouldYieldToHost = globalImpl[2];
991 getCurrentTime = globalImpl[3];
992} else if (
993// If Scheduler runs in a non-DOM environment, it falls back to a naive
994// implementation using setTimeout.
995typeof window === 'undefined' ||
996// Check if MessageChannel is supported, too.
997typeof MessageChannel !== 'function') {
998 // If this accidentally gets imported in a non-browser environment, e.g. JavaScriptCore,
999 // fallback to a naive implementation.
1000 var _callback = null;
1001 var _flushCallback = function (didTimeout) {
1002 if (_callback !== null) {
1003 try {
1004 _callback(didTimeout);
1005 } finally {
1006 _callback = null;
1007 }
1008 }
1009 };
1010 requestHostCallback = function (cb, ms) {
1011 if (_callback !== null) {
1012 // Protect against re-entrancy.
1013 setTimeout(requestHostCallback, 0, cb);
1014 } else {
1015 _callback = cb;
1016 setTimeout(_flushCallback, 0, false);
1017 }
1018 };
1019 cancelHostCallback = function () {
1020 _callback = null;
1021 };
1022 shouldYieldToHost = function () {
1023 return false;
1024 };
1025} else {
1026 if (typeof console !== 'undefined') {
1027 // TODO: Remove fb.me link
1028 if (typeof localRequestAnimationFrame !== 'function') {
1029 console.error("This browser doesn't support requestAnimationFrame. " + 'Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills');
1030 }
1031 if (typeof localCancelAnimationFrame !== 'function') {
1032 console.error("This browser doesn't support cancelAnimationFrame. " + 'Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills');
1033 }
1034 }
1035
1036 var scheduledHostCallback = null;
1037 var isMessageEventScheduled = false;
1038 var timeoutTime = -1;
1039
1040 var isAnimationFrameScheduled = false;
1041
1042 var isFlushingHostCallback = false;
1043
1044 var frameDeadline = 0;
1045 // We start out assuming that we run at 30fps but then the heuristic tracking
1046 // will adjust this value to a faster fps if we get more frequent animation
1047 // frames.
1048 var previousFrameTime = 33;
1049 var activeFrameTime = 33;
1050
1051 shouldYieldToHost = function () {
1052 return frameDeadline <= getCurrentTime();
1053 };
1054
1055 // We use the postMessage trick to defer idle work until after the repaint.
1056 var channel = new MessageChannel();
1057 var port = channel.port2;
1058 channel.port1.onmessage = function (event) {
1059 isMessageEventScheduled = false;
1060
1061 var prevScheduledCallback = scheduledHostCallback;
1062 var prevTimeoutTime = timeoutTime;
1063 scheduledHostCallback = null;
1064 timeoutTime = -1;
1065
1066 var currentTime = getCurrentTime();
1067
1068 var didTimeout = false;
1069 if (frameDeadline - currentTime <= 0) {
1070 // There's no time left in this idle period. Check if the callback has
1071 // a timeout and whether it's been exceeded.
1072 if (prevTimeoutTime !== -1 && prevTimeoutTime <= currentTime) {
1073 // Exceeded the timeout. Invoke the callback even though there's no
1074 // time left.
1075 didTimeout = true;
1076 } else {
1077 // No timeout.
1078 if (!isAnimationFrameScheduled) {
1079 // Schedule another animation callback so we retry later.
1080 isAnimationFrameScheduled = true;
1081 requestAnimationFrameWithTimeout(animationTick);
1082 }
1083 // Exit without invoking the callback.
1084 scheduledHostCallback = prevScheduledCallback;
1085 timeoutTime = prevTimeoutTime;
1086 return;
1087 }
1088 }
1089
1090 if (prevScheduledCallback !== null) {
1091 isFlushingHostCallback = true;
1092 try {
1093 prevScheduledCallback(didTimeout);
1094 } finally {
1095 isFlushingHostCallback = false;
1096 }
1097 }
1098 };
1099
1100 var animationTick = function (rafTime) {
1101 if (scheduledHostCallback !== null) {
1102 // Eagerly schedule the next animation callback at the beginning of the
1103 // frame. If the scheduler queue is not empty at the end of the frame, it
1104 // will continue flushing inside that callback. If the queue *is* empty,
1105 // then it will exit immediately. Posting the callback at the start of the
1106 // frame ensures it's fired within the earliest possible frame. If we
1107 // waited until the end of the frame to post the callback, we risk the
1108 // browser skipping a frame and not firing the callback until the frame
1109 // after that.
1110 requestAnimationFrameWithTimeout(animationTick);
1111 } else {
1112 // No pending work. Exit.
1113 isAnimationFrameScheduled = false;
1114 return;
1115 }
1116
1117 var nextFrameTime = rafTime - frameDeadline + activeFrameTime;
1118 if (nextFrameTime < activeFrameTime && previousFrameTime < activeFrameTime) {
1119 if (nextFrameTime < 8) {
1120 // Defensive coding. We don't support higher frame rates than 120hz.
1121 // If the calculated frame time gets lower than 8, it is probably a bug.
1122 nextFrameTime = 8;
1123 }
1124 // If one frame goes long, then the next one can be short to catch up.
1125 // If two frames are short in a row, then that's an indication that we
1126 // actually have a higher frame rate than what we're currently optimizing.
1127 // We adjust our heuristic dynamically accordingly. For example, if we're
1128 // running on 120hz display or 90hz VR display.
1129 // Take the max of the two in case one of them was an anomaly due to
1130 // missed frame deadlines.
1131 activeFrameTime = nextFrameTime < previousFrameTime ? previousFrameTime : nextFrameTime;
1132 } else {
1133 previousFrameTime = nextFrameTime;
1134 }
1135 frameDeadline = rafTime + activeFrameTime;
1136 if (!isMessageEventScheduled) {
1137 isMessageEventScheduled = true;
1138 port.postMessage(undefined);
1139 }
1140 };
1141
1142 requestHostCallback = function (callback, absoluteTimeout) {
1143 scheduledHostCallback = callback;
1144 timeoutTime = absoluteTimeout;
1145 if (isFlushingHostCallback || absoluteTimeout < 0) {
1146 // Don't wait for the next frame. Continue working ASAP, in a new event.
1147 port.postMessage(undefined);
1148 } else if (!isAnimationFrameScheduled) {
1149 // If rAF didn't already schedule one, we need to schedule a frame.
1150 // TODO: If this rAF doesn't materialize because the browser throttles, we
1151 // might want to still have setTimeout trigger rIC as a backup to ensure
1152 // that we keep performing work.
1153 isAnimationFrameScheduled = true;
1154 requestAnimationFrameWithTimeout(animationTick);
1155 }
1156 };
1157
1158 cancelHostCallback = function () {
1159 scheduledHostCallback = null;
1160 isMessageEventScheduled = false;
1161 timeoutTime = -1;
1162 };
1163}
1164
1165// Helps identify side effects in begin-phase lifecycle hooks and setState reducers:
1166
1167
1168// In some cases, StrictMode should also double-render lifecycles.
1169// This can be confusing for tests though,
1170// And it can be bad for performance in production.
1171// This feature flag can be used to control the behavior:
1172
1173
1174// To preserve the "Pause on caught exceptions" behavior of the debugger, we
1175// replay the begin phase of a failed component inside invokeGuardedCallback.
1176
1177
1178// Warn about deprecated, async-unsafe lifecycles; relates to RFC #6:
1179
1180
1181// Gather advanced timing metrics for Profiler subtrees.
1182
1183
1184// Trace which interactions trigger each commit.
1185var enableSchedulerTracing = true;
1186
1187// Only used in www builds.
1188 // TODO: true? Here it might just be false.
1189
1190// Only used in www builds.
1191
1192
1193// Only used in www builds.
1194
1195
1196// React Fire: prevent the value and checked attributes from syncing
1197// with their related DOM properties
1198
1199
1200// These APIs will no longer be "unstable" in the upcoming 16.7 release,
1201// Control this behavior with a flag to support 16.6 minor releases in the meanwhile.
1202var enableStableConcurrentModeAPIs = false;
1203
1204var DEFAULT_THREAD_ID = 0;
1205
1206// Counters used to generate unique IDs.
1207var interactionIDCounter = 0;
1208var threadIDCounter = 0;
1209
1210// Set of currently traced interactions.
1211// Interactions "stack"–
1212// Meaning that newly traced interactions are appended to the previously active set.
1213// When an interaction goes out of scope, the previous set (if any) is restored.
1214var interactionsRef = null;
1215
1216// Listener(s) to notify when interactions begin and end.
1217var subscriberRef = null;
1218
1219if (enableSchedulerTracing) {
1220 interactionsRef = {
1221 current: new Set()
1222 };
1223 subscriberRef = {
1224 current: null
1225 };
1226}
1227
1228function unstable_clear(callback) {
1229 if (!enableSchedulerTracing) {
1230 return callback();
1231 }
1232
1233 var prevInteractions = interactionsRef.current;
1234 interactionsRef.current = new Set();
1235
1236 try {
1237 return callback();
1238 } finally {
1239 interactionsRef.current = prevInteractions;
1240 }
1241}
1242
1243function unstable_getCurrent() {
1244 if (!enableSchedulerTracing) {
1245 return null;
1246 } else {
1247 return interactionsRef.current;
1248 }
1249}
1250
1251function unstable_getThreadID() {
1252 return ++threadIDCounter;
1253}
1254
1255function unstable_trace(name, timestamp, callback) {
1256 var threadID = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_THREAD_ID;
1257
1258 if (!enableSchedulerTracing) {
1259 return callback();
1260 }
1261
1262 var interaction = {
1263 __count: 1,
1264 id: interactionIDCounter++,
1265 name: name,
1266 timestamp: timestamp
1267 };
1268
1269 var prevInteractions = interactionsRef.current;
1270
1271 // Traced interactions should stack/accumulate.
1272 // To do that, clone the current interactions.
1273 // The previous set will be restored upon completion.
1274 var interactions = new Set(prevInteractions);
1275 interactions.add(interaction);
1276 interactionsRef.current = interactions;
1277
1278 var subscriber = subscriberRef.current;
1279 var returnValue = void 0;
1280
1281 try {
1282 if (subscriber !== null) {
1283 subscriber.onInteractionTraced(interaction);
1284 }
1285 } finally {
1286 try {
1287 if (subscriber !== null) {
1288 subscriber.onWorkStarted(interactions, threadID);
1289 }
1290 } finally {
1291 try {
1292 returnValue = callback();
1293 } finally {
1294 interactionsRef.current = prevInteractions;
1295
1296 try {
1297 if (subscriber !== null) {
1298 subscriber.onWorkStopped(interactions, threadID);
1299 }
1300 } finally {
1301 interaction.__count--;
1302
1303 // If no async work was scheduled for this interaction,
1304 // Notify subscribers that it's completed.
1305 if (subscriber !== null && interaction.__count === 0) {
1306 subscriber.onInteractionScheduledWorkCompleted(interaction);
1307 }
1308 }
1309 }
1310 }
1311 }
1312
1313 return returnValue;
1314}
1315
1316function unstable_wrap(callback) {
1317 var threadID = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_THREAD_ID;
1318
1319 if (!enableSchedulerTracing) {
1320 return callback;
1321 }
1322
1323 var wrappedInteractions = interactionsRef.current;
1324
1325 var subscriber = subscriberRef.current;
1326 if (subscriber !== null) {
1327 subscriber.onWorkScheduled(wrappedInteractions, threadID);
1328 }
1329
1330 // Update the pending async work count for the current interactions.
1331 // Update after calling subscribers in case of error.
1332 wrappedInteractions.forEach(function (interaction) {
1333 interaction.__count++;
1334 });
1335
1336 var hasRun = false;
1337
1338 function wrapped() {
1339 var prevInteractions = interactionsRef.current;
1340 interactionsRef.current = wrappedInteractions;
1341
1342 subscriber = subscriberRef.current;
1343
1344 try {
1345 var returnValue = void 0;
1346
1347 try {
1348 if (subscriber !== null) {
1349 subscriber.onWorkStarted(wrappedInteractions, threadID);
1350 }
1351 } finally {
1352 try {
1353 returnValue = callback.apply(undefined, arguments);
1354 } finally {
1355 interactionsRef.current = prevInteractions;
1356
1357 if (subscriber !== null) {
1358 subscriber.onWorkStopped(wrappedInteractions, threadID);
1359 }
1360 }
1361 }
1362
1363 return returnValue;
1364 } finally {
1365 if (!hasRun) {
1366 // We only expect a wrapped function to be executed once,
1367 // But in the event that it's executed more than once–
1368 // Only decrement the outstanding interaction counts once.
1369 hasRun = true;
1370
1371 // Update pending async counts for all wrapped interactions.
1372 // If this was the last scheduled async work for any of them,
1373 // Mark them as completed.
1374 wrappedInteractions.forEach(function (interaction) {
1375 interaction.__count--;
1376
1377 if (subscriber !== null && interaction.__count === 0) {
1378 subscriber.onInteractionScheduledWorkCompleted(interaction);
1379 }
1380 });
1381 }
1382 }
1383 }
1384
1385 wrapped.cancel = function cancel() {
1386 subscriber = subscriberRef.current;
1387
1388 try {
1389 if (subscriber !== null) {
1390 subscriber.onWorkCanceled(wrappedInteractions, threadID);
1391 }
1392 } finally {
1393 // Update pending async counts for all wrapped interactions.
1394 // If this was the last scheduled async work for any of them,
1395 // Mark them as completed.
1396 wrappedInteractions.forEach(function (interaction) {
1397 interaction.__count--;
1398
1399 if (subscriber && interaction.__count === 0) {
1400 subscriber.onInteractionScheduledWorkCompleted(interaction);
1401 }
1402 });
1403 }
1404 };
1405
1406 return wrapped;
1407}
1408
1409var subscribers = null;
1410if (enableSchedulerTracing) {
1411 subscribers = new Set();
1412}
1413
1414function unstable_subscribe(subscriber) {
1415 if (enableSchedulerTracing) {
1416 subscribers.add(subscriber);
1417
1418 if (subscribers.size === 1) {
1419 subscriberRef.current = {
1420 onInteractionScheduledWorkCompleted: onInteractionScheduledWorkCompleted,
1421 onInteractionTraced: onInteractionTraced,
1422 onWorkCanceled: onWorkCanceled,
1423 onWorkScheduled: onWorkScheduled,
1424 onWorkStarted: onWorkStarted,
1425 onWorkStopped: onWorkStopped
1426 };
1427 }
1428 }
1429}
1430
1431function unstable_unsubscribe(subscriber) {
1432 if (enableSchedulerTracing) {
1433 subscribers.delete(subscriber);
1434
1435 if (subscribers.size === 0) {
1436 subscriberRef.current = null;
1437 }
1438 }
1439}
1440
1441function onInteractionTraced(interaction) {
1442 var didCatchError = false;
1443 var caughtError = null;
1444
1445 subscribers.forEach(function (subscriber) {
1446 try {
1447 subscriber.onInteractionTraced(interaction);
1448 } catch (error) {
1449 if (!didCatchError) {
1450 didCatchError = true;
1451 caughtError = error;
1452 }
1453 }
1454 });
1455
1456 if (didCatchError) {
1457 throw caughtError;
1458 }
1459}
1460
1461function onInteractionScheduledWorkCompleted(interaction) {
1462 var didCatchError = false;
1463 var caughtError = null;
1464
1465 subscribers.forEach(function (subscriber) {
1466 try {
1467 subscriber.onInteractionScheduledWorkCompleted(interaction);
1468 } catch (error) {
1469 if (!didCatchError) {
1470 didCatchError = true;
1471 caughtError = error;
1472 }
1473 }
1474 });
1475
1476 if (didCatchError) {
1477 throw caughtError;
1478 }
1479}
1480
1481function onWorkScheduled(interactions, threadID) {
1482 var didCatchError = false;
1483 var caughtError = null;
1484
1485 subscribers.forEach(function (subscriber) {
1486 try {
1487 subscriber.onWorkScheduled(interactions, threadID);
1488 } catch (error) {
1489 if (!didCatchError) {
1490 didCatchError = true;
1491 caughtError = error;
1492 }
1493 }
1494 });
1495
1496 if (didCatchError) {
1497 throw caughtError;
1498 }
1499}
1500
1501function onWorkStarted(interactions, threadID) {
1502 var didCatchError = false;
1503 var caughtError = null;
1504
1505 subscribers.forEach(function (subscriber) {
1506 try {
1507 subscriber.onWorkStarted(interactions, threadID);
1508 } catch (error) {
1509 if (!didCatchError) {
1510 didCatchError = true;
1511 caughtError = error;
1512 }
1513 }
1514 });
1515
1516 if (didCatchError) {
1517 throw caughtError;
1518 }
1519}
1520
1521function onWorkStopped(interactions, threadID) {
1522 var didCatchError = false;
1523 var caughtError = null;
1524
1525 subscribers.forEach(function (subscriber) {
1526 try {
1527 subscriber.onWorkStopped(interactions, threadID);
1528 } catch (error) {
1529 if (!didCatchError) {
1530 didCatchError = true;
1531 caughtError = error;
1532 }
1533 }
1534 });
1535
1536 if (didCatchError) {
1537 throw caughtError;
1538 }
1539}
1540
1541function onWorkCanceled(interactions, threadID) {
1542 var didCatchError = false;
1543 var caughtError = null;
1544
1545 subscribers.forEach(function (subscriber) {
1546 try {
1547 subscriber.onWorkCanceled(interactions, threadID);
1548 } catch (error) {
1549 if (!didCatchError) {
1550 didCatchError = true;
1551 caughtError = error;
1552 }
1553 }
1554 });
1555
1556 if (didCatchError) {
1557 throw caughtError;
1558 }
1559}
1560
1561/**
1562 * Keeps track of the current dispatcher.
1563 */
1564var ReactCurrentDispatcher = {
1565 /**
1566 * @internal
1567 * @type {ReactComponent}
1568 */
1569 current: null
1570};
1571
1572/**
1573 * Keeps track of the current owner.
1574 *
1575 * The current owner is the component who should own any components that are
1576 * currently being constructed.
1577 */
1578var ReactCurrentOwner = {
1579 /**
1580 * @internal
1581 * @type {ReactComponent}
1582 */
1583 current: null
1584};
1585
1586var BEFORE_SLASH_RE = /^(.*)[\\\/]/;
1587
1588var describeComponentFrame = function (name, source, ownerName) {
1589 var sourceInfo = '';
1590 if (source) {
1591 var path = source.fileName;
1592 var fileName = path.replace(BEFORE_SLASH_RE, '');
1593 {
1594 // In DEV, include code for a common special case:
1595 // prefer "folder/index.js" instead of just "index.js".
1596 if (/^index\./.test(fileName)) {
1597 var match = path.match(BEFORE_SLASH_RE);
1598 if (match) {
1599 var pathBeforeSlash = match[1];
1600 if (pathBeforeSlash) {
1601 var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, '');
1602 fileName = folderName + '/' + fileName;
1603 }
1604 }
1605 }
1606 }
1607 sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')';
1608 } else if (ownerName) {
1609 sourceInfo = ' (created by ' + ownerName + ')';
1610 }
1611 return '\n in ' + (name || 'Unknown') + sourceInfo;
1612};
1613
1614var Resolved = 1;
1615
1616
1617function refineResolvedLazyComponent(lazyComponent) {
1618 return lazyComponent._status === Resolved ? lazyComponent._result : null;
1619}
1620
1621function getWrappedName(outerType, innerType, wrapperName) {
1622 var functionName = innerType.displayName || innerType.name || '';
1623 return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
1624}
1625
1626function getComponentName(type) {
1627 if (type == null) {
1628 // Host root, text node or just invalid type.
1629 return null;
1630 }
1631 {
1632 if (typeof type.tag === 'number') {
1633 warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
1634 }
1635 }
1636 if (typeof type === 'function') {
1637 return type.displayName || type.name || null;
1638 }
1639 if (typeof type === 'string') {
1640 return type;
1641 }
1642 switch (type) {
1643 case REACT_CONCURRENT_MODE_TYPE:
1644 return 'ConcurrentMode';
1645 case REACT_FRAGMENT_TYPE:
1646 return 'Fragment';
1647 case REACT_PORTAL_TYPE:
1648 return 'Portal';
1649 case REACT_PROFILER_TYPE:
1650 return 'Profiler';
1651 case REACT_STRICT_MODE_TYPE:
1652 return 'StrictMode';
1653 case REACT_SUSPENSE_TYPE:
1654 return 'Suspense';
1655 }
1656 if (typeof type === 'object') {
1657 switch (type.$$typeof) {
1658 case REACT_CONTEXT_TYPE:
1659 return 'Context.Consumer';
1660 case REACT_PROVIDER_TYPE:
1661 return 'Context.Provider';
1662 case REACT_FORWARD_REF_TYPE:
1663 return getWrappedName(type, type.render, 'ForwardRef');
1664 case REACT_MEMO_TYPE:
1665 return getComponentName(type.type);
1666 case REACT_LAZY_TYPE:
1667 {
1668 var thenable = type;
1669 var resolvedThenable = refineResolvedLazyComponent(thenable);
1670 if (resolvedThenable) {
1671 return getComponentName(resolvedThenable);
1672 }
1673 }
1674 }
1675 }
1676 return null;
1677}
1678
1679var ReactDebugCurrentFrame = {};
1680
1681var currentlyValidatingElement = null;
1682
1683function setCurrentlyValidatingElement(element) {
1684 {
1685 currentlyValidatingElement = element;
1686 }
1687}
1688
1689{
1690 // Stack implementation injected by the current renderer.
1691 ReactDebugCurrentFrame.getCurrentStack = null;
1692
1693 ReactDebugCurrentFrame.getStackAddendum = function () {
1694 var stack = '';
1695
1696 // Add an extra top frame while an element is being validated
1697 if (currentlyValidatingElement) {
1698 var name = getComponentName(currentlyValidatingElement.type);
1699 var owner = currentlyValidatingElement._owner;
1700 stack += describeComponentFrame(name, currentlyValidatingElement._source, owner && getComponentName(owner.type));
1701 }
1702
1703 // Delegate to the injected renderer-specific implementation
1704 var impl = ReactDebugCurrentFrame.getCurrentStack;
1705 if (impl) {
1706 stack += impl() || '';
1707 }
1708
1709 return stack;
1710 };
1711}
1712
1713var ReactSharedInternals = {
1714 ReactCurrentDispatcher: ReactCurrentDispatcher,
1715 ReactCurrentOwner: ReactCurrentOwner,
1716 // Used by renderers to avoid bundling object-assign twice in UMD bundles:
1717 assign: objectAssign
1718};
1719
1720{
1721 // Re-export the schedule API(s) for UMD bundles.
1722 // This avoids introducing a dependency on a new UMD global in a minor update,
1723 // Since that would be a breaking change (e.g. for all existing CodeSandboxes).
1724 // This re-export is only required for UMD bundles;
1725 // CJS bundles use the shared NPM package.
1726 objectAssign(ReactSharedInternals, {
1727 Scheduler: {
1728 unstable_cancelCallback: unstable_cancelCallback,
1729 unstable_shouldYield: unstable_shouldYield,
1730 unstable_now: getCurrentTime,
1731 unstable_scheduleCallback: unstable_scheduleCallback,
1732 unstable_runWithPriority: unstable_runWithPriority,
1733 unstable_next: unstable_next,
1734 unstable_wrapCallback: unstable_wrapCallback,
1735 unstable_getFirstCallbackNode: unstable_getFirstCallbackNode,
1736 unstable_pauseExecution: unstable_pauseExecution,
1737 unstable_continueExecution: unstable_continueExecution,
1738 unstable_getCurrentPriorityLevel: unstable_getCurrentPriorityLevel
1739 },
1740 SchedulerTracing: {
1741 __interactionsRef: interactionsRef,
1742 __subscriberRef: subscriberRef,
1743 unstable_clear: unstable_clear,
1744 unstable_getCurrent: unstable_getCurrent,
1745 unstable_getThreadID: unstable_getThreadID,
1746 unstable_subscribe: unstable_subscribe,
1747 unstable_trace: unstable_trace,
1748 unstable_unsubscribe: unstable_unsubscribe,
1749 unstable_wrap: unstable_wrap
1750 }
1751 });
1752}
1753
1754{
1755 objectAssign(ReactSharedInternals, {
1756 // These should not be included in production.
1757 ReactDebugCurrentFrame: ReactDebugCurrentFrame,
1758 // Shim for React DOM 16.0.0 which still destructured (but not used) this.
1759 // TODO: remove in React 17.0.
1760 ReactComponentTreeHook: {}
1761 });
1762}
1763
1764/**
1765 * Similar to invariant but only logs a warning if the condition is not met.
1766 * This can be used to log issues in development environments in critical
1767 * paths. Removing the logging code for production environments will keep the
1768 * same logic and follow the same code paths.
1769 */
1770
1771var warning = warningWithoutStack$1;
1772
1773{
1774 warning = function (condition, format) {
1775 if (condition) {
1776 return;
1777 }
1778 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
1779 var stack = ReactDebugCurrentFrame.getStackAddendum();
1780 // eslint-disable-next-line react-internal/warning-and-invariant-args
1781
1782 for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
1783 args[_key - 2] = arguments[_key];
1784 }
1785
1786 warningWithoutStack$1.apply(undefined, [false, format + '%s'].concat(args, [stack]));
1787 };
1788}
1789
1790var warning$1 = warning;
1791
1792var hasOwnProperty$1 = Object.prototype.hasOwnProperty;
1793
1794var RESERVED_PROPS = {
1795 key: true,
1796 ref: true,
1797 __self: true,
1798 __source: true
1799};
1800
1801var specialPropKeyWarningShown = void 0;
1802var specialPropRefWarningShown = void 0;
1803
1804function hasValidRef(config) {
1805 {
1806 if (hasOwnProperty$1.call(config, 'ref')) {
1807 var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
1808 if (getter && getter.isReactWarning) {
1809 return false;
1810 }
1811 }
1812 }
1813 return config.ref !== undefined;
1814}
1815
1816function hasValidKey(config) {
1817 {
1818 if (hasOwnProperty$1.call(config, 'key')) {
1819 var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
1820 if (getter && getter.isReactWarning) {
1821 return false;
1822 }
1823 }
1824 }
1825 return config.key !== undefined;
1826}
1827
1828function defineKeyPropWarningGetter(props, displayName) {
1829 var warnAboutAccessingKey = function () {
1830 if (!specialPropKeyWarningShown) {
1831 specialPropKeyWarningShown = true;
1832 warningWithoutStack$1(false, '%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://fb.me/react-special-props)', displayName);
1833 }
1834 };
1835 warnAboutAccessingKey.isReactWarning = true;
1836 Object.defineProperty(props, 'key', {
1837 get: warnAboutAccessingKey,
1838 configurable: true
1839 });
1840}
1841
1842function defineRefPropWarningGetter(props, displayName) {
1843 var warnAboutAccessingRef = function () {
1844 if (!specialPropRefWarningShown) {
1845 specialPropRefWarningShown = true;
1846 warningWithoutStack$1(false, '%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://fb.me/react-special-props)', displayName);
1847 }
1848 };
1849 warnAboutAccessingRef.isReactWarning = true;
1850 Object.defineProperty(props, 'ref', {
1851 get: warnAboutAccessingRef,
1852 configurable: true
1853 });
1854}
1855
1856/**
1857 * Factory method to create a new React element. This no longer adheres to
1858 * the class pattern, so do not use new to call it. Also, no instanceof check
1859 * will work. Instead test $$typeof field against Symbol.for('react.element') to check
1860 * if something is a React Element.
1861 *
1862 * @param {*} type
1863 * @param {*} key
1864 * @param {string|object} ref
1865 * @param {*} self A *temporary* helper to detect places where `this` is
1866 * different from the `owner` when React.createElement is called, so that we
1867 * can warn. We want to get rid of owner and replace string `ref`s with arrow
1868 * functions, and as long as `this` and owner are the same, there will be no
1869 * change in behavior.
1870 * @param {*} source An annotation object (added by a transpiler or otherwise)
1871 * indicating filename, line number, and/or other information.
1872 * @param {*} owner
1873 * @param {*} props
1874 * @internal
1875 */
1876var ReactElement = function (type, key, ref, self, source, owner, props) {
1877 var element = {
1878 // This tag allows us to uniquely identify this as a React Element
1879 $$typeof: REACT_ELEMENT_TYPE,
1880
1881 // Built-in properties that belong on the element
1882 type: type,
1883 key: key,
1884 ref: ref,
1885 props: props,
1886
1887 // Record the component responsible for creating this element.
1888 _owner: owner
1889 };
1890
1891 {
1892 // The validation flag is currently mutative. We put it on
1893 // an external backing store so that we can freeze the whole object.
1894 // This can be replaced with a WeakMap once they are implemented in
1895 // commonly used development environments.
1896 element._store = {};
1897
1898 // To make comparing ReactElements easier for testing purposes, we make
1899 // the validation flag non-enumerable (where possible, which should
1900 // include every environment we run tests in), so the test framework
1901 // ignores it.
1902 Object.defineProperty(element._store, 'validated', {
1903 configurable: false,
1904 enumerable: false,
1905 writable: true,
1906 value: false
1907 });
1908 // self and source are DEV only properties.
1909 Object.defineProperty(element, '_self', {
1910 configurable: false,
1911 enumerable: false,
1912 writable: false,
1913 value: self
1914 });
1915 // Two elements created in two different places should be considered
1916 // equal for testing purposes and therefore we hide it from enumeration.
1917 Object.defineProperty(element, '_source', {
1918 configurable: false,
1919 enumerable: false,
1920 writable: false,
1921 value: source
1922 });
1923 if (Object.freeze) {
1924 Object.freeze(element.props);
1925 Object.freeze(element);
1926 }
1927 }
1928
1929 return element;
1930};
1931
1932/**
1933 * Create and return a new ReactElement of the given type.
1934 * See https://reactjs.org/docs/react-api.html#createelement
1935 */
1936function createElement(type, config, children) {
1937 var propName = void 0;
1938
1939 // Reserved names are extracted
1940 var props = {};
1941
1942 var key = null;
1943 var ref = null;
1944 var self = null;
1945 var source = null;
1946
1947 if (config != null) {
1948 if (hasValidRef(config)) {
1949 ref = config.ref;
1950 }
1951 if (hasValidKey(config)) {
1952 key = '' + config.key;
1953 }
1954
1955 self = config.__self === undefined ? null : config.__self;
1956 source = config.__source === undefined ? null : config.__source;
1957 // Remaining properties are added to a new props object
1958 for (propName in config) {
1959 if (hasOwnProperty$1.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
1960 props[propName] = config[propName];
1961 }
1962 }
1963 }
1964
1965 // Children can be more than one argument, and those are transferred onto
1966 // the newly allocated props object.
1967 var childrenLength = arguments.length - 2;
1968 if (childrenLength === 1) {
1969 props.children = children;
1970 } else if (childrenLength > 1) {
1971 var childArray = Array(childrenLength);
1972 for (var i = 0; i < childrenLength; i++) {
1973 childArray[i] = arguments[i + 2];
1974 }
1975 {
1976 if (Object.freeze) {
1977 Object.freeze(childArray);
1978 }
1979 }
1980 props.children = childArray;
1981 }
1982
1983 // Resolve default props
1984 if (type && type.defaultProps) {
1985 var defaultProps = type.defaultProps;
1986 for (propName in defaultProps) {
1987 if (props[propName] === undefined) {
1988 props[propName] = defaultProps[propName];
1989 }
1990 }
1991 }
1992 {
1993 if (key || ref) {
1994 var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
1995 if (key) {
1996 defineKeyPropWarningGetter(props, displayName);
1997 }
1998 if (ref) {
1999 defineRefPropWarningGetter(props, displayName);
2000 }
2001 }
2002 }
2003 return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
2004}
2005
2006/**
2007 * Return a function that produces ReactElements of a given type.
2008 * See https://reactjs.org/docs/react-api.html#createfactory
2009 */
2010
2011
2012function cloneAndReplaceKey(oldElement, newKey) {
2013 var newElement = ReactElement(oldElement.type, newKey, oldElement.ref, oldElement._self, oldElement._source, oldElement._owner, oldElement.props);
2014
2015 return newElement;
2016}
2017
2018/**
2019 * Clone and return a new ReactElement using element as the starting point.
2020 * See https://reactjs.org/docs/react-api.html#cloneelement
2021 */
2022function cloneElement(element, config, children) {
2023 !!(element === null || element === undefined) ? invariant(false, 'React.cloneElement(...): The argument must be a React element, but you passed %s.', element) : void 0;
2024
2025 var propName = void 0;
2026
2027 // Original props are copied
2028 var props = objectAssign({}, element.props);
2029
2030 // Reserved names are extracted
2031 var key = element.key;
2032 var ref = element.ref;
2033 // Self is preserved since the owner is preserved.
2034 var self = element._self;
2035 // Source is preserved since cloneElement is unlikely to be targeted by a
2036 // transpiler, and the original source is probably a better indicator of the
2037 // true owner.
2038 var source = element._source;
2039
2040 // Owner will be preserved, unless ref is overridden
2041 var owner = element._owner;
2042
2043 if (config != null) {
2044 if (hasValidRef(config)) {
2045 // Silently steal the ref from the parent.
2046 ref = config.ref;
2047 owner = ReactCurrentOwner.current;
2048 }
2049 if (hasValidKey(config)) {
2050 key = '' + config.key;
2051 }
2052
2053 // Remaining properties override existing props
2054 var defaultProps = void 0;
2055 if (element.type && element.type.defaultProps) {
2056 defaultProps = element.type.defaultProps;
2057 }
2058 for (propName in config) {
2059 if (hasOwnProperty$1.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
2060 if (config[propName] === undefined && defaultProps !== undefined) {
2061 // Resolve default props
2062 props[propName] = defaultProps[propName];
2063 } else {
2064 props[propName] = config[propName];
2065 }
2066 }
2067 }
2068 }
2069
2070 // Children can be more than one argument, and those are transferred onto
2071 // the newly allocated props object.
2072 var childrenLength = arguments.length - 2;
2073 if (childrenLength === 1) {
2074 props.children = children;
2075 } else if (childrenLength > 1) {
2076 var childArray = Array(childrenLength);
2077 for (var i = 0; i < childrenLength; i++) {
2078 childArray[i] = arguments[i + 2];
2079 }
2080 props.children = childArray;
2081 }
2082
2083 return ReactElement(element.type, key, ref, self, source, owner, props);
2084}
2085
2086/**
2087 * Verifies the object is a ReactElement.
2088 * See https://reactjs.org/docs/react-api.html#isvalidelement
2089 * @param {?object} object
2090 * @return {boolean} True if `object` is a ReactElement.
2091 * @final
2092 */
2093function isValidElement(object) {
2094 return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
2095}
2096
2097var SEPARATOR = '.';
2098var SUBSEPARATOR = ':';
2099
2100/**
2101 * Escape and wrap key so it is safe to use as a reactid
2102 *
2103 * @param {string} key to be escaped.
2104 * @return {string} the escaped key.
2105 */
2106function escape(key) {
2107 var escapeRegex = /[=:]/g;
2108 var escaperLookup = {
2109 '=': '=0',
2110 ':': '=2'
2111 };
2112 var escapedString = ('' + key).replace(escapeRegex, function (match) {
2113 return escaperLookup[match];
2114 });
2115
2116 return '$' + escapedString;
2117}
2118
2119/**
2120 * TODO: Test that a single child and an array with one item have the same key
2121 * pattern.
2122 */
2123
2124var didWarnAboutMaps = false;
2125
2126var userProvidedKeyEscapeRegex = /\/+/g;
2127function escapeUserProvidedKey(text) {
2128 return ('' + text).replace(userProvidedKeyEscapeRegex, '$&/');
2129}
2130
2131var POOL_SIZE = 10;
2132var traverseContextPool = [];
2133function getPooledTraverseContext(mapResult, keyPrefix, mapFunction, mapContext) {
2134 if (traverseContextPool.length) {
2135 var traverseContext = traverseContextPool.pop();
2136 traverseContext.result = mapResult;
2137 traverseContext.keyPrefix = keyPrefix;
2138 traverseContext.func = mapFunction;
2139 traverseContext.context = mapContext;
2140 traverseContext.count = 0;
2141 return traverseContext;
2142 } else {
2143 return {
2144 result: mapResult,
2145 keyPrefix: keyPrefix,
2146 func: mapFunction,
2147 context: mapContext,
2148 count: 0
2149 };
2150 }
2151}
2152
2153function releaseTraverseContext(traverseContext) {
2154 traverseContext.result = null;
2155 traverseContext.keyPrefix = null;
2156 traverseContext.func = null;
2157 traverseContext.context = null;
2158 traverseContext.count = 0;
2159 if (traverseContextPool.length < POOL_SIZE) {
2160 traverseContextPool.push(traverseContext);
2161 }
2162}
2163
2164/**
2165 * @param {?*} children Children tree container.
2166 * @param {!string} nameSoFar Name of the key path so far.
2167 * @param {!function} callback Callback to invoke with each child found.
2168 * @param {?*} traverseContext Used to pass information throughout the traversal
2169 * process.
2170 * @return {!number} The number of children in this subtree.
2171 */
2172function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) {
2173 var type = typeof children;
2174
2175 if (type === 'undefined' || type === 'boolean') {
2176 // All of the above are perceived as null.
2177 children = null;
2178 }
2179
2180 var invokeCallback = false;
2181
2182 if (children === null) {
2183 invokeCallback = true;
2184 } else {
2185 switch (type) {
2186 case 'string':
2187 case 'number':
2188 invokeCallback = true;
2189 break;
2190 case 'object':
2191 switch (children.$$typeof) {
2192 case REACT_ELEMENT_TYPE:
2193 case REACT_PORTAL_TYPE:
2194 invokeCallback = true;
2195 }
2196 }
2197 }
2198
2199 if (invokeCallback) {
2200 callback(traverseContext, children,
2201 // If it's the only child, treat the name as if it was wrapped in an array
2202 // so that it's consistent if the number of children grows.
2203 nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar);
2204 return 1;
2205 }
2206
2207 var child = void 0;
2208 var nextName = void 0;
2209 var subtreeCount = 0; // Count of children found in the current subtree.
2210 var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
2211
2212 if (Array.isArray(children)) {
2213 for (var i = 0; i < children.length; i++) {
2214 child = children[i];
2215 nextName = nextNamePrefix + getComponentKey(child, i);
2216 subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
2217 }
2218 } else {
2219 var iteratorFn = getIteratorFn(children);
2220 if (typeof iteratorFn === 'function') {
2221 {
2222 // Warn about using Maps as children
2223 if (iteratorFn === children.entries) {
2224 !didWarnAboutMaps ? warning$1(false, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.') : void 0;
2225 didWarnAboutMaps = true;
2226 }
2227 }
2228
2229 var iterator = iteratorFn.call(children);
2230 var step = void 0;
2231 var ii = 0;
2232 while (!(step = iterator.next()).done) {
2233 child = step.value;
2234 nextName = nextNamePrefix + getComponentKey(child, ii++);
2235 subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
2236 }
2237 } else if (type === 'object') {
2238 var addendum = '';
2239 {
2240 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + ReactDebugCurrentFrame.getStackAddendum();
2241 }
2242 var childrenString = '' + children;
2243 invariant(false, 'Objects are not valid as a React child (found: %s).%s', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum);
2244 }
2245 }
2246
2247 return subtreeCount;
2248}
2249
2250/**
2251 * Traverses children that are typically specified as `props.children`, but
2252 * might also be specified through attributes:
2253 *
2254 * - `traverseAllChildren(this.props.children, ...)`
2255 * - `traverseAllChildren(this.props.leftPanelChildren, ...)`
2256 *
2257 * The `traverseContext` is an optional argument that is passed through the
2258 * entire traversal. It can be used to store accumulations or anything else that
2259 * the callback might find relevant.
2260 *
2261 * @param {?*} children Children tree object.
2262 * @param {!function} callback To invoke upon traversing each child.
2263 * @param {?*} traverseContext Context for traversal.
2264 * @return {!number} The number of children in this subtree.
2265 */
2266function traverseAllChildren(children, callback, traverseContext) {
2267 if (children == null) {
2268 return 0;
2269 }
2270
2271 return traverseAllChildrenImpl(children, '', callback, traverseContext);
2272}
2273
2274/**
2275 * Generate a key string that identifies a component within a set.
2276 *
2277 * @param {*} component A component that could contain a manual key.
2278 * @param {number} index Index that is used if a manual key is not provided.
2279 * @return {string}
2280 */
2281function getComponentKey(component, index) {
2282 // Do some typechecking here since we call this blindly. We want to ensure
2283 // that we don't block potential future ES APIs.
2284 if (typeof component === 'object' && component !== null && component.key != null) {
2285 // Explicit key
2286 return escape(component.key);
2287 }
2288 // Implicit key determined by the index in the set
2289 return index.toString(36);
2290}
2291
2292function forEachSingleChild(bookKeeping, child, name) {
2293 var func = bookKeeping.func,
2294 context = bookKeeping.context;
2295
2296 func.call(context, child, bookKeeping.count++);
2297}
2298
2299/**
2300 * Iterates through children that are typically specified as `props.children`.
2301 *
2302 * See https://reactjs.org/docs/react-api.html#reactchildrenforeach
2303 *
2304 * The provided forEachFunc(child, index) will be called for each
2305 * leaf child.
2306 *
2307 * @param {?*} children Children tree container.
2308 * @param {function(*, int)} forEachFunc
2309 * @param {*} forEachContext Context for forEachContext.
2310 */
2311function forEachChildren(children, forEachFunc, forEachContext) {
2312 if (children == null) {
2313 return children;
2314 }
2315 var traverseContext = getPooledTraverseContext(null, null, forEachFunc, forEachContext);
2316 traverseAllChildren(children, forEachSingleChild, traverseContext);
2317 releaseTraverseContext(traverseContext);
2318}
2319
2320function mapSingleChildIntoContext(bookKeeping, child, childKey) {
2321 var result = bookKeeping.result,
2322 keyPrefix = bookKeeping.keyPrefix,
2323 func = bookKeeping.func,
2324 context = bookKeeping.context;
2325
2326
2327 var mappedChild = func.call(context, child, bookKeeping.count++);
2328 if (Array.isArray(mappedChild)) {
2329 mapIntoWithKeyPrefixInternal(mappedChild, result, childKey, function (c) {
2330 return c;
2331 });
2332 } else if (mappedChild != null) {
2333 if (isValidElement(mappedChild)) {
2334 mappedChild = cloneAndReplaceKey(mappedChild,
2335 // Keep both the (mapped) and old keys if they differ, just as
2336 // traverseAllChildren used to do for objects as children
2337 keyPrefix + (mappedChild.key && (!child || child.key !== mappedChild.key) ? escapeUserProvidedKey(mappedChild.key) + '/' : '') + childKey);
2338 }
2339 result.push(mappedChild);
2340 }
2341}
2342
2343function mapIntoWithKeyPrefixInternal(children, array, prefix, func, context) {
2344 var escapedPrefix = '';
2345 if (prefix != null) {
2346 escapedPrefix = escapeUserProvidedKey(prefix) + '/';
2347 }
2348 var traverseContext = getPooledTraverseContext(array, escapedPrefix, func, context);
2349 traverseAllChildren(children, mapSingleChildIntoContext, traverseContext);
2350 releaseTraverseContext(traverseContext);
2351}
2352
2353/**
2354 * Maps children that are typically specified as `props.children`.
2355 *
2356 * See https://reactjs.org/docs/react-api.html#reactchildrenmap
2357 *
2358 * The provided mapFunction(child, key, index) will be called for each
2359 * leaf child.
2360 *
2361 * @param {?*} children Children tree container.
2362 * @param {function(*, int)} func The map function.
2363 * @param {*} context Context for mapFunction.
2364 * @return {object} Object containing the ordered map of results.
2365 */
2366function mapChildren(children, func, context) {
2367 if (children == null) {
2368 return children;
2369 }
2370 var result = [];
2371 mapIntoWithKeyPrefixInternal(children, result, null, func, context);
2372 return result;
2373}
2374
2375/**
2376 * Count the number of children that are typically specified as
2377 * `props.children`.
2378 *
2379 * See https://reactjs.org/docs/react-api.html#reactchildrencount
2380 *
2381 * @param {?*} children Children tree container.
2382 * @return {number} The number of children.
2383 */
2384function countChildren(children) {
2385 return traverseAllChildren(children, function () {
2386 return null;
2387 }, null);
2388}
2389
2390/**
2391 * Flatten a children object (typically specified as `props.children`) and
2392 * return an array with appropriately re-keyed children.
2393 *
2394 * See https://reactjs.org/docs/react-api.html#reactchildrentoarray
2395 */
2396function toArray(children) {
2397 var result = [];
2398 mapIntoWithKeyPrefixInternal(children, result, null, function (child) {
2399 return child;
2400 });
2401 return result;
2402}
2403
2404/**
2405 * Returns the first child in a collection of children and verifies that there
2406 * is only one child in the collection.
2407 *
2408 * See https://reactjs.org/docs/react-api.html#reactchildrenonly
2409 *
2410 * The current implementation of this function assumes that a single child gets
2411 * passed without a wrapper, but the purpose of this helper function is to
2412 * abstract away the particular structure of children.
2413 *
2414 * @param {?object} children Child collection structure.
2415 * @return {ReactElement} The first and only `ReactElement` contained in the
2416 * structure.
2417 */
2418function onlyChild(children) {
2419 !isValidElement(children) ? invariant(false, 'React.Children.only expected to receive a single React element child.') : void 0;
2420 return children;
2421}
2422
2423function createContext(defaultValue, calculateChangedBits) {
2424 if (calculateChangedBits === undefined) {
2425 calculateChangedBits = null;
2426 } else {
2427 {
2428 !(calculateChangedBits === null || typeof calculateChangedBits === 'function') ? warningWithoutStack$1(false, 'createContext: Expected the optional second argument to be a ' + 'function. Instead received: %s', calculateChangedBits) : void 0;
2429 }
2430 }
2431
2432 var context = {
2433 $$typeof: REACT_CONTEXT_TYPE,
2434 _calculateChangedBits: calculateChangedBits,
2435 // As a workaround to support multiple concurrent renderers, we categorize
2436 // some renderers as primary and others as secondary. We only expect
2437 // there to be two concurrent renderers at most: React Native (primary) and
2438 // Fabric (secondary); React DOM (primary) and React ART (secondary).
2439 // Secondary renderers store their context values on separate fields.
2440 _currentValue: defaultValue,
2441 _currentValue2: defaultValue,
2442 // Used to track how many concurrent renderers this context currently
2443 // supports within in a single renderer. Such as parallel server rendering.
2444 _threadCount: 0,
2445 // These are circular
2446 Provider: null,
2447 Consumer: null
2448 };
2449
2450 context.Provider = {
2451 $$typeof: REACT_PROVIDER_TYPE,
2452 _context: context
2453 };
2454
2455 var hasWarnedAboutUsingNestedContextConsumers = false;
2456 var hasWarnedAboutUsingConsumerProvider = false;
2457
2458 {
2459 // A separate object, but proxies back to the original context object for
2460 // backwards compatibility. It has a different $$typeof, so we can properly
2461 // warn for the incorrect usage of Context as a Consumer.
2462 var Consumer = {
2463 $$typeof: REACT_CONTEXT_TYPE,
2464 _context: context,
2465 _calculateChangedBits: context._calculateChangedBits
2466 };
2467 // $FlowFixMe: Flow complains about not setting a value, which is intentional here
2468 Object.defineProperties(Consumer, {
2469 Provider: {
2470 get: function () {
2471 if (!hasWarnedAboutUsingConsumerProvider) {
2472 hasWarnedAboutUsingConsumerProvider = true;
2473 warning$1(false, 'Rendering <Context.Consumer.Provider> is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Provider> instead?');
2474 }
2475 return context.Provider;
2476 },
2477 set: function (_Provider) {
2478 context.Provider = _Provider;
2479 }
2480 },
2481 _currentValue: {
2482 get: function () {
2483 return context._currentValue;
2484 },
2485 set: function (_currentValue) {
2486 context._currentValue = _currentValue;
2487 }
2488 },
2489 _currentValue2: {
2490 get: function () {
2491 return context._currentValue2;
2492 },
2493 set: function (_currentValue2) {
2494 context._currentValue2 = _currentValue2;
2495 }
2496 },
2497 _threadCount: {
2498 get: function () {
2499 return context._threadCount;
2500 },
2501 set: function (_threadCount) {
2502 context._threadCount = _threadCount;
2503 }
2504 },
2505 Consumer: {
2506 get: function () {
2507 if (!hasWarnedAboutUsingNestedContextConsumers) {
2508 hasWarnedAboutUsingNestedContextConsumers = true;
2509 warning$1(false, 'Rendering <Context.Consumer.Consumer> is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Consumer> instead?');
2510 }
2511 return context.Consumer;
2512 }
2513 }
2514 });
2515 // $FlowFixMe: Flow complains about missing properties because it doesn't understand defineProperty
2516 context.Consumer = Consumer;
2517 }
2518
2519 {
2520 context._currentRenderer = null;
2521 context._currentRenderer2 = null;
2522 }
2523
2524 return context;
2525}
2526
2527function lazy(ctor) {
2528 var lazyType = {
2529 $$typeof: REACT_LAZY_TYPE,
2530 _ctor: ctor,
2531 // React uses these fields to store the result.
2532 _status: -1,
2533 _result: null
2534 };
2535
2536 {
2537 // In production, this would just set it on the object.
2538 var defaultProps = void 0;
2539 var propTypes = void 0;
2540 Object.defineProperties(lazyType, {
2541 defaultProps: {
2542 configurable: true,
2543 get: function () {
2544 return defaultProps;
2545 },
2546 set: function (newDefaultProps) {
2547 warning$1(false, 'React.lazy(...): It is not supported to assign `defaultProps` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.');
2548 defaultProps = newDefaultProps;
2549 // Match production behavior more closely:
2550 Object.defineProperty(lazyType, 'defaultProps', {
2551 enumerable: true
2552 });
2553 }
2554 },
2555 propTypes: {
2556 configurable: true,
2557 get: function () {
2558 return propTypes;
2559 },
2560 set: function (newPropTypes) {
2561 warning$1(false, 'React.lazy(...): It is not supported to assign `propTypes` to ' + 'a lazy component import. Either specify them where the component ' + 'is defined, or create a wrapping component around it.');
2562 propTypes = newPropTypes;
2563 // Match production behavior more closely:
2564 Object.defineProperty(lazyType, 'propTypes', {
2565 enumerable: true
2566 });
2567 }
2568 }
2569 });
2570 }
2571
2572 return lazyType;
2573}
2574
2575function forwardRef(render) {
2576 {
2577 if (render != null && render.$$typeof === REACT_MEMO_TYPE) {
2578 warningWithoutStack$1(false, 'forwardRef requires a render function but received a `memo` ' + 'component. Instead of forwardRef(memo(...)), use ' + 'memo(forwardRef(...)).');
2579 } else if (typeof render !== 'function') {
2580 warningWithoutStack$1(false, 'forwardRef requires a render function but was given %s.', render === null ? 'null' : typeof render);
2581 } else {
2582 !(
2583 // Do not warn for 0 arguments because it could be due to usage of the 'arguments' object
2584 render.length === 0 || render.length === 2) ? warningWithoutStack$1(false, 'forwardRef render functions accept exactly two parameters: props and ref. %s', render.length === 1 ? 'Did you forget to use the ref parameter?' : 'Any additional parameter will be undefined.') : void 0;
2585 }
2586
2587 if (render != null) {
2588 !(render.defaultProps == null && render.propTypes == null) ? warningWithoutStack$1(false, 'forwardRef render functions do not support propTypes or defaultProps. ' + 'Did you accidentally pass a React component?') : void 0;
2589 }
2590 }
2591
2592 return {
2593 $$typeof: REACT_FORWARD_REF_TYPE,
2594 render: render
2595 };
2596}
2597
2598function isValidElementType(type) {
2599 return typeof type === 'string' || typeof type === 'function' ||
2600 // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
2601 type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || typeof type === 'object' && type !== null && (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);
2602}
2603
2604function memo(type, compare) {
2605 {
2606 if (!isValidElementType(type)) {
2607 warningWithoutStack$1(false, 'memo: The first argument must be a component. Instead ' + 'received: %s', type === null ? 'null' : typeof type);
2608 }
2609 }
2610 return {
2611 $$typeof: REACT_MEMO_TYPE,
2612 type: type,
2613 compare: compare === undefined ? null : compare
2614 };
2615}
2616
2617function resolveDispatcher() {
2618 var dispatcher = ReactCurrentDispatcher.current;
2619 !(dispatcher !== null) ? invariant(false, 'Hooks can only be called inside the body of a function component. (https://fb.me/react-invalid-hook-call)') : void 0;
2620 return dispatcher;
2621}
2622
2623function useContext(Context, unstable_observedBits) {
2624 var dispatcher = resolveDispatcher();
2625 {
2626 !(unstable_observedBits === undefined) ? warning$1(false, 'useContext() second argument is reserved for future ' + 'use in React. Passing it is not supported. ' + 'You passed: %s.%s', unstable_observedBits, typeof unstable_observedBits === 'number' && Array.isArray(arguments[2]) ? '\n\nDid you call array.map(useContext)? ' + 'Calling Hooks inside a loop is not supported. ' + 'Learn more at https://fb.me/rules-of-hooks' : '') : void 0;
2627
2628 // TODO: add a more generic warning for invalid values.
2629 if (Context._context !== undefined) {
2630 var realContext = Context._context;
2631 // Don't deduplicate because this legitimately causes bugs
2632 // and nobody should be using this in existing code.
2633 if (realContext.Consumer === Context) {
2634 warning$1(false, 'Calling useContext(Context.Consumer) is not supported, may cause bugs, and will be ' + 'removed in a future major release. Did you mean to call useContext(Context) instead?');
2635 } else if (realContext.Provider === Context) {
2636 warning$1(false, 'Calling useContext(Context.Provider) is not supported. ' + 'Did you mean to call useContext(Context) instead?');
2637 }
2638 }
2639 }
2640 return dispatcher.useContext(Context, unstable_observedBits);
2641}
2642
2643function useState(initialState) {
2644 var dispatcher = resolveDispatcher();
2645 return dispatcher.useState(initialState);
2646}
2647
2648function useReducer(reducer, initialArg, init) {
2649 var dispatcher = resolveDispatcher();
2650 return dispatcher.useReducer(reducer, initialArg, init);
2651}
2652
2653function useRef(initialValue) {
2654 var dispatcher = resolveDispatcher();
2655 return dispatcher.useRef(initialValue);
2656}
2657
2658function useEffect(create, inputs) {
2659 var dispatcher = resolveDispatcher();
2660 return dispatcher.useEffect(create, inputs);
2661}
2662
2663function useLayoutEffect(create, inputs) {
2664 var dispatcher = resolveDispatcher();
2665 return dispatcher.useLayoutEffect(create, inputs);
2666}
2667
2668function useCallback(callback, inputs) {
2669 var dispatcher = resolveDispatcher();
2670 return dispatcher.useCallback(callback, inputs);
2671}
2672
2673function useMemo(create, inputs) {
2674 var dispatcher = resolveDispatcher();
2675 return dispatcher.useMemo(create, inputs);
2676}
2677
2678function useImperativeHandle(ref, create, inputs) {
2679 var dispatcher = resolveDispatcher();
2680 return dispatcher.useImperativeHandle(ref, create, inputs);
2681}
2682
2683function useDebugValue(value, formatterFn) {
2684 {
2685 var dispatcher = resolveDispatcher();
2686 return dispatcher.useDebugValue(value, formatterFn);
2687 }
2688}
2689
2690/**
2691 * Copyright (c) 2013-present, Facebook, Inc.
2692 *
2693 * This source code is licensed under the MIT license found in the
2694 * LICENSE file in the root directory of this source tree.
2695 */
2696
2697
2698
2699var ReactPropTypesSecret$1 = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED';
2700
2701var ReactPropTypesSecret_1 = ReactPropTypesSecret$1;
2702
2703/**
2704 * Copyright (c) 2013-present, Facebook, Inc.
2705 *
2706 * This source code is licensed under the MIT license found in the
2707 * LICENSE file in the root directory of this source tree.
2708 */
2709
2710
2711
2712var printWarning$1 = function() {};
2713
2714{
2715 var ReactPropTypesSecret = ReactPropTypesSecret_1;
2716 var loggedTypeFailures = {};
2717
2718 printWarning$1 = function(text) {
2719 var message = 'Warning: ' + text;
2720 if (typeof console !== 'undefined') {
2721 console.error(message);
2722 }
2723 try {
2724 // --- Welcome to debugging React ---
2725 // This error was thrown as a convenience so that you can use this stack
2726 // to find the callsite that caused this warning to fire.
2727 throw new Error(message);
2728 } catch (x) {}
2729 };
2730}
2731
2732/**
2733 * Assert that the values match with the type specs.
2734 * Error messages are memorized and will only be shown once.
2735 *
2736 * @param {object} typeSpecs Map of name to a ReactPropType
2737 * @param {object} values Runtime values that need to be type-checked
2738 * @param {string} location e.g. "prop", "context", "child context"
2739 * @param {string} componentName Name of the component for error messages.
2740 * @param {?Function} getStack Returns the component stack.
2741 * @private
2742 */
2743function checkPropTypes(typeSpecs, values, location, componentName, getStack) {
2744 {
2745 for (var typeSpecName in typeSpecs) {
2746 if (typeSpecs.hasOwnProperty(typeSpecName)) {
2747 var error;
2748 // Prop type validation may throw. In case they do, we don't want to
2749 // fail the render phase where it didn't fail before. So we log it.
2750 // After these have been cleaned up, we'll let them throw.
2751 try {
2752 // This is intentionally an invariant that gets caught. It's the same
2753 // behavior as without this statement except with a better message.
2754 if (typeof typeSpecs[typeSpecName] !== 'function') {
2755 var err = Error(
2756 (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' +
2757 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.'
2758 );
2759 err.name = 'Invariant Violation';
2760 throw err;
2761 }
2762 error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret);
2763 } catch (ex) {
2764 error = ex;
2765 }
2766 if (error && !(error instanceof Error)) {
2767 printWarning$1(
2768 (componentName || 'React class') + ': type specification of ' +
2769 location + ' `' + typeSpecName + '` is invalid; the type checker ' +
2770 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' +
2771 'You may have forgotten to pass an argument to the type checker ' +
2772 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' +
2773 'shape all require an argument).'
2774 );
2775
2776 }
2777 if (error instanceof Error && !(error.message in loggedTypeFailures)) {
2778 // Only monitor this failure once because there tends to be a lot of the
2779 // same error.
2780 loggedTypeFailures[error.message] = true;
2781
2782 var stack = getStack ? getStack() : '';
2783
2784 printWarning$1(
2785 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '')
2786 );
2787 }
2788 }
2789 }
2790 }
2791}
2792
2793var checkPropTypes_1 = checkPropTypes;
2794
2795/**
2796 * ReactElementValidator provides a wrapper around a element factory
2797 * which validates the props passed to the element. This is intended to be
2798 * used only in DEV and could be replaced by a static type checker for languages
2799 * that support it.
2800 */
2801
2802var propTypesMisspellWarningShown = void 0;
2803
2804{
2805 propTypesMisspellWarningShown = false;
2806}
2807
2808function getDeclarationErrorAddendum() {
2809 if (ReactCurrentOwner.current) {
2810 var name = getComponentName(ReactCurrentOwner.current.type);
2811 if (name) {
2812 return '\n\nCheck the render method of `' + name + '`.';
2813 }
2814 }
2815 return '';
2816}
2817
2818function getSourceInfoErrorAddendum(elementProps) {
2819 if (elementProps !== null && elementProps !== undefined && elementProps.__source !== undefined) {
2820 var source = elementProps.__source;
2821 var fileName = source.fileName.replace(/^.*[\\\/]/, '');
2822 var lineNumber = source.lineNumber;
2823 return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.';
2824 }
2825 return '';
2826}
2827
2828/**
2829 * Warn if there's no key explicitly set on dynamic arrays of children or
2830 * object keys are not valid. This allows us to keep track of children between
2831 * updates.
2832 */
2833var ownerHasKeyUseWarning = {};
2834
2835function getCurrentComponentErrorInfo(parentType) {
2836 var info = getDeclarationErrorAddendum();
2837
2838 if (!info) {
2839 var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
2840 if (parentName) {
2841 info = '\n\nCheck the top-level render call using <' + parentName + '>.';
2842 }
2843 }
2844 return info;
2845}
2846
2847/**
2848 * Warn if the element doesn't have an explicit key assigned to it.
2849 * This element is in an array. The array could grow and shrink or be
2850 * reordered. All children that haven't already been validated are required to
2851 * have a "key" property assigned to it. Error statuses are cached so a warning
2852 * will only be shown once.
2853 *
2854 * @internal
2855 * @param {ReactElement} element Element that requires a key.
2856 * @param {*} parentType element's parent's type.
2857 */
2858function validateExplicitKey(element, parentType) {
2859 if (!element._store || element._store.validated || element.key != null) {
2860 return;
2861 }
2862 element._store.validated = true;
2863
2864 var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
2865 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
2866 return;
2867 }
2868 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
2869
2870 // Usually the current owner is the offender, but if it accepts children as a
2871 // property, it may be the creator of the child that's responsible for
2872 // assigning it a key.
2873 var childOwner = '';
2874 if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
2875 // Give the component that originally created this child.
2876 childOwner = ' It was passed a child from ' + getComponentName(element._owner.type) + '.';
2877 }
2878
2879 setCurrentlyValidatingElement(element);
2880 {
2881 warning$1(false, 'Each child in a list should have a unique "key" prop.' + '%s%s See https://fb.me/react-warning-keys for more information.', currentComponentErrorInfo, childOwner);
2882 }
2883 setCurrentlyValidatingElement(null);
2884}
2885
2886/**
2887 * Ensure that every element either is passed in a static location, in an
2888 * array with an explicit keys property defined, or in an object literal
2889 * with valid key property.
2890 *
2891 * @internal
2892 * @param {ReactNode} node Statically passed child of any type.
2893 * @param {*} parentType node's parent's type.
2894 */
2895function validateChildKeys(node, parentType) {
2896 if (typeof node !== 'object') {
2897 return;
2898 }
2899 if (Array.isArray(node)) {
2900 for (var i = 0; i < node.length; i++) {
2901 var child = node[i];
2902 if (isValidElement(child)) {
2903 validateExplicitKey(child, parentType);
2904 }
2905 }
2906 } else if (isValidElement(node)) {
2907 // This element was passed in a valid location.
2908 if (node._store) {
2909 node._store.validated = true;
2910 }
2911 } else if (node) {
2912 var iteratorFn = getIteratorFn(node);
2913 if (typeof iteratorFn === 'function') {
2914 // Entry iterators used to provide implicit keys,
2915 // but now we print a separate warning for them later.
2916 if (iteratorFn !== node.entries) {
2917 var iterator = iteratorFn.call(node);
2918 var step = void 0;
2919 while (!(step = iterator.next()).done) {
2920 if (isValidElement(step.value)) {
2921 validateExplicitKey(step.value, parentType);
2922 }
2923 }
2924 }
2925 }
2926 }
2927}
2928
2929/**
2930 * Given an element, validate that its props follow the propTypes definition,
2931 * provided by the type.
2932 *
2933 * @param {ReactElement} element
2934 */
2935function validatePropTypes(element) {
2936 var type = element.type;
2937 if (type === null || type === undefined || typeof type === 'string') {
2938 return;
2939 }
2940 var name = getComponentName(type);
2941 var propTypes = void 0;
2942 if (typeof type === 'function') {
2943 propTypes = type.propTypes;
2944 } else if (typeof type === 'object' && (type.$$typeof === REACT_FORWARD_REF_TYPE ||
2945 // Note: Memo only checks outer props here.
2946 // Inner props are checked in the reconciler.
2947 type.$$typeof === REACT_MEMO_TYPE)) {
2948 propTypes = type.propTypes;
2949 } else {
2950 return;
2951 }
2952 if (propTypes) {
2953 setCurrentlyValidatingElement(element);
2954 checkPropTypes_1(propTypes, element.props, 'prop', name, ReactDebugCurrentFrame.getStackAddendum);
2955 setCurrentlyValidatingElement(null);
2956 } else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) {
2957 propTypesMisspellWarningShown = true;
2958 warningWithoutStack$1(false, 'Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', name || 'Unknown');
2959 }
2960 if (typeof type.getDefaultProps === 'function') {
2961 !type.getDefaultProps.isReactClassApproved ? warningWithoutStack$1(false, 'getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.') : void 0;
2962 }
2963}
2964
2965/**
2966 * Given a fragment, validate that it can only be provided with fragment props
2967 * @param {ReactElement} fragment
2968 */
2969function validateFragmentProps(fragment) {
2970 setCurrentlyValidatingElement(fragment);
2971
2972 var keys = Object.keys(fragment.props);
2973 for (var i = 0; i < keys.length; i++) {
2974 var key = keys[i];
2975 if (key !== 'children' && key !== 'key') {
2976 warning$1(false, 'Invalid prop `%s` supplied to `React.Fragment`. ' + 'React.Fragment can only have `key` and `children` props.', key);
2977 break;
2978 }
2979 }
2980
2981 if (fragment.ref !== null) {
2982 warning$1(false, 'Invalid attribute `ref` supplied to `React.Fragment`.');
2983 }
2984
2985 setCurrentlyValidatingElement(null);
2986}
2987
2988function createElementWithValidation(type, props, children) {
2989 var validType = isValidElementType(type);
2990
2991 // We warn in this case but don't throw. We expect the element creation to
2992 // succeed and there will likely be errors in render.
2993 if (!validType) {
2994 var info = '';
2995 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
2996 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.";
2997 }
2998
2999 var sourceInfo = getSourceInfoErrorAddendum(props);
3000 if (sourceInfo) {
3001 info += sourceInfo;
3002 } else {
3003 info += getDeclarationErrorAddendum();
3004 }
3005
3006 var typeString = void 0;
3007 if (type === null) {
3008 typeString = 'null';
3009 } else if (Array.isArray(type)) {
3010 typeString = 'array';
3011 } else if (type !== undefined && type.$$typeof === REACT_ELEMENT_TYPE) {
3012 typeString = '<' + (getComponentName(type.type) || 'Unknown') + ' />';
3013 info = ' Did you accidentally export a JSX literal instead of a component?';
3014 } else {
3015 typeString = typeof type;
3016 }
3017
3018 warning$1(false, 'React.createElement: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', typeString, info);
3019 }
3020
3021 var element = createElement.apply(this, arguments);
3022
3023 // The result can be nullish if a mock or a custom function is used.
3024 // TODO: Drop this when these are no longer allowed as the type argument.
3025 if (element == null) {
3026 return element;
3027 }
3028
3029 // Skip key warning if the type isn't valid since our key validation logic
3030 // doesn't expect a non-string/function type and can throw confusing errors.
3031 // We don't want exception behavior to differ between dev and prod.
3032 // (Rendering will throw with a helpful message and as soon as the type is
3033 // fixed, the key warnings will appear.)
3034 if (validType) {
3035 for (var i = 2; i < arguments.length; i++) {
3036 validateChildKeys(arguments[i], type);
3037 }
3038 }
3039
3040 if (type === REACT_FRAGMENT_TYPE) {
3041 validateFragmentProps(element);
3042 } else {
3043 validatePropTypes(element);
3044 }
3045
3046 return element;
3047}
3048
3049function createFactoryWithValidation(type) {
3050 var validatedFactory = createElementWithValidation.bind(null, type);
3051 validatedFactory.type = type;
3052 // Legacy hook: remove it
3053 {
3054 Object.defineProperty(validatedFactory, 'type', {
3055 enumerable: false,
3056 get: function () {
3057 lowPriorityWarning$1(false, 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.');
3058 Object.defineProperty(this, 'type', {
3059 value: type
3060 });
3061 return type;
3062 }
3063 });
3064 }
3065
3066 return validatedFactory;
3067}
3068
3069function cloneElementWithValidation(element, props, children) {
3070 var newElement = cloneElement.apply(this, arguments);
3071 for (var i = 2; i < arguments.length; i++) {
3072 validateChildKeys(arguments[i], newElement.type);
3073 }
3074 validatePropTypes(newElement);
3075 return newElement;
3076}
3077
3078var React = {
3079 Children: {
3080 map: mapChildren,
3081 forEach: forEachChildren,
3082 count: countChildren,
3083 toArray: toArray,
3084 only: onlyChild
3085 },
3086
3087 createRef: createRef,
3088 Component: Component,
3089 PureComponent: PureComponent,
3090
3091 createContext: createContext,
3092 forwardRef: forwardRef,
3093 lazy: lazy,
3094 memo: memo,
3095
3096 useCallback: useCallback,
3097 useContext: useContext,
3098 useEffect: useEffect,
3099 useImperativeHandle: useImperativeHandle,
3100 useDebugValue: useDebugValue,
3101 useLayoutEffect: useLayoutEffect,
3102 useMemo: useMemo,
3103 useReducer: useReducer,
3104 useRef: useRef,
3105 useState: useState,
3106
3107 Fragment: REACT_FRAGMENT_TYPE,
3108 StrictMode: REACT_STRICT_MODE_TYPE,
3109 Suspense: REACT_SUSPENSE_TYPE,
3110
3111 createElement: createElementWithValidation,
3112 cloneElement: cloneElementWithValidation,
3113 createFactory: createFactoryWithValidation,
3114 isValidElement: isValidElement,
3115
3116 version: ReactVersion,
3117
3118 unstable_ConcurrentMode: REACT_CONCURRENT_MODE_TYPE,
3119 unstable_Profiler: REACT_PROFILER_TYPE,
3120
3121 __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: ReactSharedInternals
3122};
3123
3124// Note: some APIs are added with feature flags.
3125// Make sure that stable builds for open source
3126// don't modify the React object to avoid deopts.
3127// Also let's not expose their names in stable builds.
3128
3129if (enableStableConcurrentModeAPIs) {
3130 React.ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
3131 React.Profiler = REACT_PROFILER_TYPE;
3132 React.unstable_ConcurrentMode = undefined;
3133 React.unstable_Profiler = undefined;
3134}
3135
3136
3137
3138var React$2 = Object.freeze({
3139 default: React
3140});
3141
3142var React$3 = ( React$2 && React ) || React$2;
3143
3144// TODO: decide on the top-level export form.
3145// This is hacky but makes it work with both Rollup and Jest.
3146var react = React$3.default || React$3;
3147
3148return react;
3149
3150})));