UNPKG

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