UNPKG

47 kBJavaScriptView Raw
1/** @license React v16.3.2
2 * react.development.js
3 *
4 * Copyright (c) 2013-present, Facebook, Inc.
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
13
14if (process.env.NODE_ENV !== "production") {
15 (function() {
16'use strict';
17
18var _assign = require('object-assign');
19var invariant = require('fbjs/lib/invariant');
20var emptyObject = require('fbjs/lib/emptyObject');
21var warning = require('fbjs/lib/warning');
22var emptyFunction = require('fbjs/lib/emptyFunction');
23var checkPropTypes = require('prop-types/checkPropTypes');
24
25// TODO: this is special because it gets imported during build.
26
27var ReactVersion = '16.3.2';
28
29// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
30// nor polyfill, then a plain number is used for performance.
31var hasSymbol = typeof Symbol === 'function' && Symbol['for'];
32
33var REACT_ELEMENT_TYPE = hasSymbol ? Symbol['for']('react.element') : 0xeac7;
34var REACT_CALL_TYPE = hasSymbol ? Symbol['for']('react.call') : 0xeac8;
35var REACT_RETURN_TYPE = hasSymbol ? Symbol['for']('react.return') : 0xeac9;
36var REACT_PORTAL_TYPE = hasSymbol ? Symbol['for']('react.portal') : 0xeaca;
37var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol['for']('react.fragment') : 0xeacb;
38var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol['for']('react.strict_mode') : 0xeacc;
39var REACT_PROVIDER_TYPE = hasSymbol ? Symbol['for']('react.provider') : 0xeacd;
40var REACT_CONTEXT_TYPE = hasSymbol ? Symbol['for']('react.context') : 0xeace;
41var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol['for']('react.async_mode') : 0xeacf;
42var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol['for']('react.forward_ref') : 0xead0;
43
44var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
45var FAUX_ITERATOR_SYMBOL = '@@iterator';
46
47function getIteratorFn(maybeIterable) {
48 if (maybeIterable === null || typeof maybeIterable === 'undefined') {
49 return null;
50 }
51 var maybeIterator = MAYBE_ITERATOR_SYMBOL && maybeIterable[MAYBE_ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL];
52 if (typeof maybeIterator === 'function') {
53 return maybeIterator;
54 }
55 return null;
56}
57
58// Relying on the `invariant()` implementation lets us
59// have preserve the format and params in the www builds.
60
61/**
62 * Forked from fbjs/warning:
63 * https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
64 *
65 * Only change is we use console.warn instead of console.error,
66 * and do nothing when 'console' is not supported.
67 * This really simplifies the code.
68 * ---
69 * Similar to invariant but only logs a warning if the condition is not met.
70 * This can be used to log issues in development environments in critical
71 * paths. Removing the logging code for production environments will keep the
72 * same logic and follow the same code paths.
73 */
74
75var lowPriorityWarning = function () {};
76
77{
78 var printWarning = function (format) {
79 for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
80 args[_key - 1] = arguments[_key];
81 }
82
83 var argIndex = 0;
84 var message = 'Warning: ' + format.replace(/%s/g, function () {
85 return args[argIndex++];
86 });
87 if (typeof console !== 'undefined') {
88 console.warn(message);
89 }
90 try {
91 // --- Welcome to debugging React ---
92 // This error was thrown as a convenience so that you can use this stack
93 // to find the callsite that caused this warning to fire.
94 throw new Error(message);
95 } catch (x) {}
96 };
97
98 lowPriorityWarning = function (condition, format) {
99 if (format === undefined) {
100 throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
101 }
102 if (!condition) {
103 for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
104 args[_key2 - 2] = arguments[_key2];
105 }
106
107 printWarning.apply(undefined, [format].concat(args));
108 }
109 };
110}
111
112var lowPriorityWarning$1 = lowPriorityWarning;
113
114var didWarnStateUpdateForUnmountedComponent = {};
115
116function warnNoop(publicInstance, callerName) {
117 {
118 var _constructor = publicInstance.constructor;
119 var componentName = _constructor && (_constructor.displayName || _constructor.name) || 'ReactClass';
120 var warningKey = componentName + '.' + callerName;
121 if (didWarnStateUpdateForUnmountedComponent[warningKey]) {
122 return;
123 }
124 warning(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);
125 didWarnStateUpdateForUnmountedComponent[warningKey] = true;
126 }
127}
128
129/**
130 * This is the abstract API for an update queue.
131 */
132var ReactNoopUpdateQueue = {
133 /**
134 * Checks whether or not this composite component is mounted.
135 * @param {ReactClass} publicInstance The instance we want to test.
136 * @return {boolean} True if mounted, false otherwise.
137 * @protected
138 * @final
139 */
140 isMounted: function (publicInstance) {
141 return false;
142 },
143
144 /**
145 * Forces an update. This should only be invoked when it is known with
146 * certainty that we are **not** in a DOM transaction.
147 *
148 * You may want to call this when you know that some deeper aspect of the
149 * component's state has changed but `setState` was not called.
150 *
151 * This will not invoke `shouldComponentUpdate`, but it will invoke
152 * `componentWillUpdate` and `componentDidUpdate`.
153 *
154 * @param {ReactClass} publicInstance The instance that should rerender.
155 * @param {?function} callback Called after component is updated.
156 * @param {?string} callerName name of the calling function in the public API.
157 * @internal
158 */
159 enqueueForceUpdate: function (publicInstance, callback, callerName) {
160 warnNoop(publicInstance, 'forceUpdate');
161 },
162
163 /**
164 * Replaces all of the state. Always use this or `setState` to mutate state.
165 * You should treat `this.state` as immutable.
166 *
167 * There is no guarantee that `this.state` will be immediately updated, so
168 * accessing `this.state` after calling this method may return the old value.
169 *
170 * @param {ReactClass} publicInstance The instance that should rerender.
171 * @param {object} completeState Next state.
172 * @param {?function} callback Called after component is updated.
173 * @param {?string} callerName name of the calling function in the public API.
174 * @internal
175 */
176 enqueueReplaceState: function (publicInstance, completeState, callback, callerName) {
177 warnNoop(publicInstance, 'replaceState');
178 },
179
180 /**
181 * Sets a subset of the state. This only exists because _pendingState is
182 * internal. This provides a merging strategy that is not available to deep
183 * properties which is confusing. TODO: Expose pendingState or don't use it
184 * during the merge.
185 *
186 * @param {ReactClass} publicInstance The instance that should rerender.
187 * @param {object} partialState Next partial state to be merged with state.
188 * @param {?function} callback Called after component is updated.
189 * @param {?string} Name of the calling function in the public API.
190 * @internal
191 */
192 enqueueSetState: function (publicInstance, partialState, callback, callerName) {
193 warnNoop(publicInstance, 'setState');
194 }
195};
196
197/**
198 * Base class helpers for the updating state of a component.
199 */
200function Component(props, context, updater) {
201 this.props = props;
202 this.context = context;
203 this.refs = emptyObject;
204 // We initialize the default updater but the real one gets injected by the
205 // renderer.
206 this.updater = updater || ReactNoopUpdateQueue;
207}
208
209Component.prototype.isReactComponent = {};
210
211/**
212 * Sets a subset of the state. Always use this to mutate
213 * state. You should treat `this.state` as immutable.
214 *
215 * There is no guarantee that `this.state` will be immediately updated, so
216 * accessing `this.state` after calling this method may return the old value.
217 *
218 * There is no guarantee that calls to `setState` will run synchronously,
219 * as they may eventually be batched together. You can provide an optional
220 * callback that will be executed when the call to setState is actually
221 * completed.
222 *
223 * When a function is provided to setState, it will be called at some point in
224 * the future (not synchronously). It will be called with the up to date
225 * component arguments (state, props, context). These values can be different
226 * from this.* because your function may be called after receiveProps but before
227 * shouldComponentUpdate, and this new state, props, and context will not yet be
228 * assigned to this.
229 *
230 * @param {object|function} partialState Next partial state or function to
231 * produce next partial state to be merged with current state.
232 * @param {?function} callback Called after state is updated.
233 * @final
234 * @protected
235 */
236Component.prototype.setState = function (partialState, callback) {
237 !(typeof partialState === 'object' || typeof partialState === 'function' || partialState == null) ? invariant(false, 'setState(...): takes an object of state variables to update or a function which returns an object of state variables.') : void 0;
238 this.updater.enqueueSetState(this, partialState, callback, 'setState');
239};
240
241/**
242 * Forces an update. This should only be invoked when it is known with
243 * certainty that we are **not** in a DOM transaction.
244 *
245 * You may want to call this when you know that some deeper aspect of the
246 * component's state has changed but `setState` was not called.
247 *
248 * This will not invoke `shouldComponentUpdate`, but it will invoke
249 * `componentWillUpdate` and `componentDidUpdate`.
250 *
251 * @param {?function} callback Called after update is complete.
252 * @final
253 * @protected
254 */
255Component.prototype.forceUpdate = function (callback) {
256 this.updater.enqueueForceUpdate(this, callback, 'forceUpdate');
257};
258
259/**
260 * Deprecated APIs. These APIs used to exist on classic React classes but since
261 * we would like to deprecate them, we're not going to move them over to this
262 * modern base class. Instead, we define a getter that warns if it's accessed.
263 */
264{
265 var deprecatedAPIs = {
266 isMounted: ['isMounted', 'Instead, make sure to clean up subscriptions and pending requests in ' + 'componentWillUnmount to prevent memory leaks.'],
267 replaceState: ['replaceState', 'Refactor your code to use setState instead (see ' + 'https://github.com/facebook/react/issues/3236).']
268 };
269 var defineDeprecationWarning = function (methodName, info) {
270 Object.defineProperty(Component.prototype, methodName, {
271 get: function () {
272 lowPriorityWarning$1(false, '%s(...) is deprecated in plain JavaScript React classes. %s', info[0], info[1]);
273 return undefined;
274 }
275 });
276 };
277 for (var fnName in deprecatedAPIs) {
278 if (deprecatedAPIs.hasOwnProperty(fnName)) {
279 defineDeprecationWarning(fnName, deprecatedAPIs[fnName]);
280 }
281 }
282}
283
284function ComponentDummy() {}
285ComponentDummy.prototype = Component.prototype;
286
287/**
288 * Convenience component with default shallow equality check for sCU.
289 */
290function PureComponent(props, context, updater) {
291 this.props = props;
292 this.context = context;
293 this.refs = emptyObject;
294 this.updater = updater || ReactNoopUpdateQueue;
295}
296
297var pureComponentPrototype = PureComponent.prototype = new ComponentDummy();
298pureComponentPrototype.constructor = PureComponent;
299// Avoid an extra prototype jump for these methods.
300_assign(pureComponentPrototype, Component.prototype);
301pureComponentPrototype.isPureReactComponent = true;
302
303// an immutable object with a single mutable value
304function createRef() {
305 var refObject = {
306 current: null
307 };
308 {
309 Object.seal(refObject);
310 }
311 return refObject;
312}
313
314/**
315 * Keeps track of the current owner.
316 *
317 * The current owner is the component who should own any components that are
318 * currently being constructed.
319 */
320var ReactCurrentOwner = {
321 /**
322 * @internal
323 * @type {ReactComponent}
324 */
325 current: null
326};
327
328var hasOwnProperty = Object.prototype.hasOwnProperty;
329
330var RESERVED_PROPS = {
331 key: true,
332 ref: true,
333 __self: true,
334 __source: true
335};
336
337var specialPropKeyWarningShown = void 0;
338var specialPropRefWarningShown = void 0;
339
340function hasValidRef(config) {
341 {
342 if (hasOwnProperty.call(config, 'ref')) {
343 var getter = Object.getOwnPropertyDescriptor(config, 'ref').get;
344 if (getter && getter.isReactWarning) {
345 return false;
346 }
347 }
348 }
349 return config.ref !== undefined;
350}
351
352function hasValidKey(config) {
353 {
354 if (hasOwnProperty.call(config, 'key')) {
355 var getter = Object.getOwnPropertyDescriptor(config, 'key').get;
356 if (getter && getter.isReactWarning) {
357 return false;
358 }
359 }
360 }
361 return config.key !== undefined;
362}
363
364function defineKeyPropWarningGetter(props, displayName) {
365 var warnAboutAccessingKey = function () {
366 if (!specialPropKeyWarningShown) {
367 specialPropKeyWarningShown = true;
368 warning(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);
369 }
370 };
371 warnAboutAccessingKey.isReactWarning = true;
372 Object.defineProperty(props, 'key', {
373 get: warnAboutAccessingKey,
374 configurable: true
375 });
376}
377
378function defineRefPropWarningGetter(props, displayName) {
379 var warnAboutAccessingRef = function () {
380 if (!specialPropRefWarningShown) {
381 specialPropRefWarningShown = true;
382 warning(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);
383 }
384 };
385 warnAboutAccessingRef.isReactWarning = true;
386 Object.defineProperty(props, 'ref', {
387 get: warnAboutAccessingRef,
388 configurable: true
389 });
390}
391
392/**
393 * Factory method to create a new React element. This no longer adheres to
394 * the class pattern, so do not use new to call it. Also, no instanceof check
395 * will work. Instead test $$typeof field against Symbol.for('react.element') to check
396 * if something is a React Element.
397 *
398 * @param {*} type
399 * @param {*} key
400 * @param {string|object} ref
401 * @param {*} self A *temporary* helper to detect places where `this` is
402 * different from the `owner` when React.createElement is called, so that we
403 * can warn. We want to get rid of owner and replace string `ref`s with arrow
404 * functions, and as long as `this` and owner are the same, there will be no
405 * change in behavior.
406 * @param {*} source An annotation object (added by a transpiler or otherwise)
407 * indicating filename, line number, and/or other information.
408 * @param {*} owner
409 * @param {*} props
410 * @internal
411 */
412var ReactElement = function (type, key, ref, self, source, owner, props) {
413 var element = {
414 // This tag allows us to uniquely identify this as a React Element
415 $$typeof: REACT_ELEMENT_TYPE,
416
417 // Built-in properties that belong on the element
418 type: type,
419 key: key,
420 ref: ref,
421 props: props,
422
423 // Record the component responsible for creating this element.
424 _owner: owner
425 };
426
427 {
428 // The validation flag is currently mutative. We put it on
429 // an external backing store so that we can freeze the whole object.
430 // This can be replaced with a WeakMap once they are implemented in
431 // commonly used development environments.
432 element._store = {};
433
434 // To make comparing ReactElements easier for testing purposes, we make
435 // the validation flag non-enumerable (where possible, which should
436 // include every environment we run tests in), so the test framework
437 // ignores it.
438 Object.defineProperty(element._store, 'validated', {
439 configurable: false,
440 enumerable: false,
441 writable: true,
442 value: false
443 });
444 // self and source are DEV only properties.
445 Object.defineProperty(element, '_self', {
446 configurable: false,
447 enumerable: false,
448 writable: false,
449 value: self
450 });
451 // Two elements created in two different places should be considered
452 // equal for testing purposes and therefore we hide it from enumeration.
453 Object.defineProperty(element, '_source', {
454 configurable: false,
455 enumerable: false,
456 writable: false,
457 value: source
458 });
459 if (Object.freeze) {
460 Object.freeze(element.props);
461 Object.freeze(element);
462 }
463 }
464
465 return element;
466};
467
468/**
469 * Create and return a new ReactElement of the given type.
470 * See https://reactjs.org/docs/react-api.html#createelement
471 */
472function createElement(type, config, children) {
473 var propName = void 0;
474
475 // Reserved names are extracted
476 var props = {};
477
478 var key = null;
479 var ref = null;
480 var self = null;
481 var source = null;
482
483 if (config != null) {
484 if (hasValidRef(config)) {
485 ref = config.ref;
486 }
487 if (hasValidKey(config)) {
488 key = '' + config.key;
489 }
490
491 self = config.__self === undefined ? null : config.__self;
492 source = config.__source === undefined ? null : config.__source;
493 // Remaining properties are added to a new props object
494 for (propName in config) {
495 if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
496 props[propName] = config[propName];
497 }
498 }
499 }
500
501 // Children can be more than one argument, and those are transferred onto
502 // the newly allocated props object.
503 var childrenLength = arguments.length - 2;
504 if (childrenLength === 1) {
505 props.children = children;
506 } else if (childrenLength > 1) {
507 var childArray = Array(childrenLength);
508 for (var i = 0; i < childrenLength; i++) {
509 childArray[i] = arguments[i + 2];
510 }
511 {
512 if (Object.freeze) {
513 Object.freeze(childArray);
514 }
515 }
516 props.children = childArray;
517 }
518
519 // Resolve default props
520 if (type && type.defaultProps) {
521 var defaultProps = type.defaultProps;
522 for (propName in defaultProps) {
523 if (props[propName] === undefined) {
524 props[propName] = defaultProps[propName];
525 }
526 }
527 }
528 {
529 if (key || ref) {
530 if (typeof props.$$typeof === 'undefined' || props.$$typeof !== REACT_ELEMENT_TYPE) {
531 var displayName = typeof type === 'function' ? type.displayName || type.name || 'Unknown' : type;
532 if (key) {
533 defineKeyPropWarningGetter(props, displayName);
534 }
535 if (ref) {
536 defineRefPropWarningGetter(props, displayName);
537 }
538 }
539 }
540 }
541 return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
542}
543
544/**
545 * Return a function that produces ReactElements of a given type.
546 * See https://reactjs.org/docs/react-api.html#createfactory
547 */
548
549
550function cloneAndReplaceKey(oldElement, newKey) {
551 var newElement = ReactElement(oldElement.type, newKey, oldElement.ref, oldElement._self, oldElement._source, oldElement._owner, oldElement.props);
552
553 return newElement;
554}
555
556/**
557 * Clone and return a new ReactElement using element as the starting point.
558 * See https://reactjs.org/docs/react-api.html#cloneelement
559 */
560function cloneElement(element, config, children) {
561 !!(element === null || element === undefined) ? invariant(false, 'React.cloneElement(...): The argument must be a React element, but you passed %s.', element) : void 0;
562
563 var propName = void 0;
564
565 // Original props are copied
566 var props = _assign({}, element.props);
567
568 // Reserved names are extracted
569 var key = element.key;
570 var ref = element.ref;
571 // Self is preserved since the owner is preserved.
572 var self = element._self;
573 // Source is preserved since cloneElement is unlikely to be targeted by a
574 // transpiler, and the original source is probably a better indicator of the
575 // true owner.
576 var source = element._source;
577
578 // Owner will be preserved, unless ref is overridden
579 var owner = element._owner;
580
581 if (config != null) {
582 if (hasValidRef(config)) {
583 // Silently steal the ref from the parent.
584 ref = config.ref;
585 owner = ReactCurrentOwner.current;
586 }
587 if (hasValidKey(config)) {
588 key = '' + config.key;
589 }
590
591 // Remaining properties override existing props
592 var defaultProps = void 0;
593 if (element.type && element.type.defaultProps) {
594 defaultProps = element.type.defaultProps;
595 }
596 for (propName in config) {
597 if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
598 if (config[propName] === undefined && defaultProps !== undefined) {
599 // Resolve default props
600 props[propName] = defaultProps[propName];
601 } else {
602 props[propName] = config[propName];
603 }
604 }
605 }
606 }
607
608 // Children can be more than one argument, and those are transferred onto
609 // the newly allocated props object.
610 var childrenLength = arguments.length - 2;
611 if (childrenLength === 1) {
612 props.children = children;
613 } else if (childrenLength > 1) {
614 var childArray = Array(childrenLength);
615 for (var i = 0; i < childrenLength; i++) {
616 childArray[i] = arguments[i + 2];
617 }
618 props.children = childArray;
619 }
620
621 return ReactElement(element.type, key, ref, self, source, owner, props);
622}
623
624/**
625 * Verifies the object is a ReactElement.
626 * See https://reactjs.org/docs/react-api.html#isvalidelement
627 * @param {?object} object
628 * @return {boolean} True if `object` is a valid component.
629 * @final
630 */
631function isValidElement(object) {
632 return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
633}
634
635var ReactDebugCurrentFrame = {};
636
637{
638 // Component that is being worked on
639 ReactDebugCurrentFrame.getCurrentStack = null;
640
641 ReactDebugCurrentFrame.getStackAddendum = function () {
642 var impl = ReactDebugCurrentFrame.getCurrentStack;
643 if (impl) {
644 return impl();
645 }
646 return null;
647 };
648}
649
650var SEPARATOR = '.';
651var SUBSEPARATOR = ':';
652
653/**
654 * Escape and wrap key so it is safe to use as a reactid
655 *
656 * @param {string} key to be escaped.
657 * @return {string} the escaped key.
658 */
659function escape(key) {
660 var escapeRegex = /[=:]/g;
661 var escaperLookup = {
662 '=': '=0',
663 ':': '=2'
664 };
665 var escapedString = ('' + key).replace(escapeRegex, function (match) {
666 return escaperLookup[match];
667 });
668
669 return '$' + escapedString;
670}
671
672/**
673 * TODO: Test that a single child and an array with one item have the same key
674 * pattern.
675 */
676
677var didWarnAboutMaps = false;
678
679var userProvidedKeyEscapeRegex = /\/+/g;
680function escapeUserProvidedKey(text) {
681 return ('' + text).replace(userProvidedKeyEscapeRegex, '$&/');
682}
683
684var POOL_SIZE = 10;
685var traverseContextPool = [];
686function getPooledTraverseContext(mapResult, keyPrefix, mapFunction, mapContext) {
687 if (traverseContextPool.length) {
688 var traverseContext = traverseContextPool.pop();
689 traverseContext.result = mapResult;
690 traverseContext.keyPrefix = keyPrefix;
691 traverseContext.func = mapFunction;
692 traverseContext.context = mapContext;
693 traverseContext.count = 0;
694 return traverseContext;
695 } else {
696 return {
697 result: mapResult,
698 keyPrefix: keyPrefix,
699 func: mapFunction,
700 context: mapContext,
701 count: 0
702 };
703 }
704}
705
706function releaseTraverseContext(traverseContext) {
707 traverseContext.result = null;
708 traverseContext.keyPrefix = null;
709 traverseContext.func = null;
710 traverseContext.context = null;
711 traverseContext.count = 0;
712 if (traverseContextPool.length < POOL_SIZE) {
713 traverseContextPool.push(traverseContext);
714 }
715}
716
717/**
718 * @param {?*} children Children tree container.
719 * @param {!string} nameSoFar Name of the key path so far.
720 * @param {!function} callback Callback to invoke with each child found.
721 * @param {?*} traverseContext Used to pass information throughout the traversal
722 * process.
723 * @return {!number} The number of children in this subtree.
724 */
725function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) {
726 var type = typeof children;
727
728 if (type === 'undefined' || type === 'boolean') {
729 // All of the above are perceived as null.
730 children = null;
731 }
732
733 var invokeCallback = false;
734
735 if (children === null) {
736 invokeCallback = true;
737 } else {
738 switch (type) {
739 case 'string':
740 case 'number':
741 invokeCallback = true;
742 break;
743 case 'object':
744 switch (children.$$typeof) {
745 case REACT_ELEMENT_TYPE:
746 case REACT_PORTAL_TYPE:
747 invokeCallback = true;
748 }
749 }
750 }
751
752 if (invokeCallback) {
753 callback(traverseContext, children,
754 // If it's the only child, treat the name as if it was wrapped in an array
755 // so that it's consistent if the number of children grows.
756 nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar);
757 return 1;
758 }
759
760 var child = void 0;
761 var nextName = void 0;
762 var subtreeCount = 0; // Count of children found in the current subtree.
763 var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR;
764
765 if (Array.isArray(children)) {
766 for (var i = 0; i < children.length; i++) {
767 child = children[i];
768 nextName = nextNamePrefix + getComponentKey(child, i);
769 subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
770 }
771 } else {
772 var iteratorFn = getIteratorFn(children);
773 if (typeof iteratorFn === 'function') {
774 {
775 // Warn about using Maps as children
776 if (iteratorFn === children.entries) {
777 !didWarnAboutMaps ? warning(false, 'Using Maps as children is unsupported and will likely yield ' + 'unexpected results. Convert it to a sequence/iterable of keyed ' + 'ReactElements instead.%s', ReactDebugCurrentFrame.getStackAddendum()) : void 0;
778 didWarnAboutMaps = true;
779 }
780 }
781
782 var iterator = iteratorFn.call(children);
783 var step = void 0;
784 var ii = 0;
785 while (!(step = iterator.next()).done) {
786 child = step.value;
787 nextName = nextNamePrefix + getComponentKey(child, ii++);
788 subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext);
789 }
790 } else if (type === 'object') {
791 var addendum = '';
792 {
793 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + ReactDebugCurrentFrame.getStackAddendum();
794 }
795 var childrenString = '' + children;
796 invariant(false, 'Objects are not valid as a React child (found: %s).%s', childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString, addendum);
797 }
798 }
799
800 return subtreeCount;
801}
802
803/**
804 * Traverses children that are typically specified as `props.children`, but
805 * might also be specified through attributes:
806 *
807 * - `traverseAllChildren(this.props.children, ...)`
808 * - `traverseAllChildren(this.props.leftPanelChildren, ...)`
809 *
810 * The `traverseContext` is an optional argument that is passed through the
811 * entire traversal. It can be used to store accumulations or anything else that
812 * the callback might find relevant.
813 *
814 * @param {?*} children Children tree object.
815 * @param {!function} callback To invoke upon traversing each child.
816 * @param {?*} traverseContext Context for traversal.
817 * @return {!number} The number of children in this subtree.
818 */
819function traverseAllChildren(children, callback, traverseContext) {
820 if (children == null) {
821 return 0;
822 }
823
824 return traverseAllChildrenImpl(children, '', callback, traverseContext);
825}
826
827/**
828 * Generate a key string that identifies a component within a set.
829 *
830 * @param {*} component A component that could contain a manual key.
831 * @param {number} index Index that is used if a manual key is not provided.
832 * @return {string}
833 */
834function getComponentKey(component, index) {
835 // Do some typechecking here since we call this blindly. We want to ensure
836 // that we don't block potential future ES APIs.
837 if (typeof component === 'object' && component !== null && component.key != null) {
838 // Explicit key
839 return escape(component.key);
840 }
841 // Implicit key determined by the index in the set
842 return index.toString(36);
843}
844
845function forEachSingleChild(bookKeeping, child, name) {
846 var func = bookKeeping.func,
847 context = bookKeeping.context;
848
849 func.call(context, child, bookKeeping.count++);
850}
851
852/**
853 * Iterates through children that are typically specified as `props.children`.
854 *
855 * See https://reactjs.org/docs/react-api.html#react.children.foreach
856 *
857 * The provided forEachFunc(child, index) will be called for each
858 * leaf child.
859 *
860 * @param {?*} children Children tree container.
861 * @param {function(*, int)} forEachFunc
862 * @param {*} forEachContext Context for forEachContext.
863 */
864function forEachChildren(children, forEachFunc, forEachContext) {
865 if (children == null) {
866 return children;
867 }
868 var traverseContext = getPooledTraverseContext(null, null, forEachFunc, forEachContext);
869 traverseAllChildren(children, forEachSingleChild, traverseContext);
870 releaseTraverseContext(traverseContext);
871}
872
873function mapSingleChildIntoContext(bookKeeping, child, childKey) {
874 var result = bookKeeping.result,
875 keyPrefix = bookKeeping.keyPrefix,
876 func = bookKeeping.func,
877 context = bookKeeping.context;
878
879
880 var mappedChild = func.call(context, child, bookKeeping.count++);
881 if (Array.isArray(mappedChild)) {
882 mapIntoWithKeyPrefixInternal(mappedChild, result, childKey, emptyFunction.thatReturnsArgument);
883 } else if (mappedChild != null) {
884 if (isValidElement(mappedChild)) {
885 mappedChild = cloneAndReplaceKey(mappedChild,
886 // Keep both the (mapped) and old keys if they differ, just as
887 // traverseAllChildren used to do for objects as children
888 keyPrefix + (mappedChild.key && (!child || child.key !== mappedChild.key) ? escapeUserProvidedKey(mappedChild.key) + '/' : '') + childKey);
889 }
890 result.push(mappedChild);
891 }
892}
893
894function mapIntoWithKeyPrefixInternal(children, array, prefix, func, context) {
895 var escapedPrefix = '';
896 if (prefix != null) {
897 escapedPrefix = escapeUserProvidedKey(prefix) + '/';
898 }
899 var traverseContext = getPooledTraverseContext(array, escapedPrefix, func, context);
900 traverseAllChildren(children, mapSingleChildIntoContext, traverseContext);
901 releaseTraverseContext(traverseContext);
902}
903
904/**
905 * Maps children that are typically specified as `props.children`.
906 *
907 * See https://reactjs.org/docs/react-api.html#react.children.map
908 *
909 * The provided mapFunction(child, key, index) will be called for each
910 * leaf child.
911 *
912 * @param {?*} children Children tree container.
913 * @param {function(*, int)} func The map function.
914 * @param {*} context Context for mapFunction.
915 * @return {object} Object containing the ordered map of results.
916 */
917function mapChildren(children, func, context) {
918 if (children == null) {
919 return children;
920 }
921 var result = [];
922 mapIntoWithKeyPrefixInternal(children, result, null, func, context);
923 return result;
924}
925
926/**
927 * Count the number of children that are typically specified as
928 * `props.children`.
929 *
930 * See https://reactjs.org/docs/react-api.html#react.children.count
931 *
932 * @param {?*} children Children tree container.
933 * @return {number} The number of children.
934 */
935function countChildren(children, context) {
936 return traverseAllChildren(children, emptyFunction.thatReturnsNull, null);
937}
938
939/**
940 * Flatten a children object (typically specified as `props.children`) and
941 * return an array with appropriately re-keyed children.
942 *
943 * See https://reactjs.org/docs/react-api.html#react.children.toarray
944 */
945function toArray(children) {
946 var result = [];
947 mapIntoWithKeyPrefixInternal(children, result, null, emptyFunction.thatReturnsArgument);
948 return result;
949}
950
951/**
952 * Returns the first child in a collection of children and verifies that there
953 * is only one child in the collection.
954 *
955 * See https://reactjs.org/docs/react-api.html#react.children.only
956 *
957 * The current implementation of this function assumes that a single child gets
958 * passed without a wrapper, but the purpose of this helper function is to
959 * abstract away the particular structure of children.
960 *
961 * @param {?object} children Child collection structure.
962 * @return {ReactElement} The first and only `ReactElement` contained in the
963 * structure.
964 */
965function onlyChild(children) {
966 !isValidElement(children) ? invariant(false, 'React.Children.only expected to receive a single React element child.') : void 0;
967 return children;
968}
969
970function createContext(defaultValue, calculateChangedBits) {
971 if (calculateChangedBits === undefined) {
972 calculateChangedBits = null;
973 } else {
974 {
975 !(calculateChangedBits === null || typeof calculateChangedBits === 'function') ? warning(false, 'createContext: Expected the optional second argument to be a ' + 'function. Instead received: %s', calculateChangedBits) : void 0;
976 }
977 }
978
979 var context = {
980 $$typeof: REACT_CONTEXT_TYPE,
981 _calculateChangedBits: calculateChangedBits,
982 _defaultValue: defaultValue,
983 _currentValue: defaultValue,
984 _changedBits: 0,
985 // These are circular
986 Provider: null,
987 Consumer: null
988 };
989
990 context.Provider = {
991 $$typeof: REACT_PROVIDER_TYPE,
992 _context: context
993 };
994 context.Consumer = context;
995
996 {
997 context._currentRenderer = null;
998 }
999
1000 return context;
1001}
1002
1003function forwardRef(render) {
1004 {
1005 !(typeof render === 'function') ? warning(false, 'forwardRef requires a render function but was given %s.', render === null ? 'null' : typeof render) : void 0;
1006 }
1007
1008 return {
1009 $$typeof: REACT_FORWARD_REF_TYPE,
1010 render: render
1011 };
1012}
1013
1014var describeComponentFrame = function (name, source, ownerName) {
1015 return '\n in ' + (name || 'Unknown') + (source ? ' (at ' + source.fileName.replace(/^.*[\\\/]/, '') + ':' + source.lineNumber + ')' : ownerName ? ' (created by ' + ownerName + ')' : '');
1016};
1017
1018function isValidElementType(type) {
1019 return typeof type === 'string' || typeof type === 'function' ||
1020 // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
1021 type === REACT_FRAGMENT_TYPE || type === REACT_ASYNC_MODE_TYPE || type === REACT_STRICT_MODE_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE);
1022}
1023
1024function getComponentName(fiber) {
1025 var type = fiber.type;
1026
1027 if (typeof type === 'function') {
1028 return type.displayName || type.name;
1029 }
1030 if (typeof type === 'string') {
1031 return type;
1032 }
1033 switch (type) {
1034 case REACT_FRAGMENT_TYPE:
1035 return 'ReactFragment';
1036 case REACT_PORTAL_TYPE:
1037 return 'ReactPortal';
1038 case REACT_CALL_TYPE:
1039 return 'ReactCall';
1040 case REACT_RETURN_TYPE:
1041 return 'ReactReturn';
1042 }
1043 if (typeof type === 'object' && type !== null) {
1044 switch (type.$$typeof) {
1045 case REACT_FORWARD_REF_TYPE:
1046 var functionName = type.render.displayName || type.render.name || '';
1047 return functionName !== '' ? 'ForwardRef(' + functionName + ')' : 'ForwardRef';
1048 }
1049 }
1050 return null;
1051}
1052
1053/**
1054 * ReactElementValidator provides a wrapper around a element factory
1055 * which validates the props passed to the element. This is intended to be
1056 * used only in DEV and could be replaced by a static type checker for languages
1057 * that support it.
1058 */
1059
1060var currentlyValidatingElement = void 0;
1061var propTypesMisspellWarningShown = void 0;
1062
1063var getDisplayName = function () {};
1064var getStackAddendum = function () {};
1065
1066{
1067 currentlyValidatingElement = null;
1068
1069 propTypesMisspellWarningShown = false;
1070
1071 getDisplayName = function (element) {
1072 if (element == null) {
1073 return '#empty';
1074 } else if (typeof element === 'string' || typeof element === 'number') {
1075 return '#text';
1076 } else if (typeof element.type === 'string') {
1077 return element.type;
1078 } else if (element.type === REACT_FRAGMENT_TYPE) {
1079 return 'React.Fragment';
1080 } else {
1081 return element.type.displayName || element.type.name || 'Unknown';
1082 }
1083 };
1084
1085 getStackAddendum = function () {
1086 var stack = '';
1087 if (currentlyValidatingElement) {
1088 var name = getDisplayName(currentlyValidatingElement);
1089 var owner = currentlyValidatingElement._owner;
1090 stack += describeComponentFrame(name, currentlyValidatingElement._source, owner && getComponentName(owner));
1091 }
1092 stack += ReactDebugCurrentFrame.getStackAddendum() || '';
1093 return stack;
1094 };
1095}
1096
1097function getDeclarationErrorAddendum() {
1098 if (ReactCurrentOwner.current) {
1099 var name = getComponentName(ReactCurrentOwner.current);
1100 if (name) {
1101 return '\n\nCheck the render method of `' + name + '`.';
1102 }
1103 }
1104 return '';
1105}
1106
1107function getSourceInfoErrorAddendum(elementProps) {
1108 if (elementProps !== null && elementProps !== undefined && elementProps.__source !== undefined) {
1109 var source = elementProps.__source;
1110 var fileName = source.fileName.replace(/^.*[\\\/]/, '');
1111 var lineNumber = source.lineNumber;
1112 return '\n\nCheck your code at ' + fileName + ':' + lineNumber + '.';
1113 }
1114 return '';
1115}
1116
1117/**
1118 * Warn if there's no key explicitly set on dynamic arrays of children or
1119 * object keys are not valid. This allows us to keep track of children between
1120 * updates.
1121 */
1122var ownerHasKeyUseWarning = {};
1123
1124function getCurrentComponentErrorInfo(parentType) {
1125 var info = getDeclarationErrorAddendum();
1126
1127 if (!info) {
1128 var parentName = typeof parentType === 'string' ? parentType : parentType.displayName || parentType.name;
1129 if (parentName) {
1130 info = '\n\nCheck the top-level render call using <' + parentName + '>.';
1131 }
1132 }
1133 return info;
1134}
1135
1136/**
1137 * Warn if the element doesn't have an explicit key assigned to it.
1138 * This element is in an array. The array could grow and shrink or be
1139 * reordered. All children that haven't already been validated are required to
1140 * have a "key" property assigned to it. Error statuses are cached so a warning
1141 * will only be shown once.
1142 *
1143 * @internal
1144 * @param {ReactElement} element Element that requires a key.
1145 * @param {*} parentType element's parent's type.
1146 */
1147function validateExplicitKey(element, parentType) {
1148 if (!element._store || element._store.validated || element.key != null) {
1149 return;
1150 }
1151 element._store.validated = true;
1152
1153 var currentComponentErrorInfo = getCurrentComponentErrorInfo(parentType);
1154 if (ownerHasKeyUseWarning[currentComponentErrorInfo]) {
1155 return;
1156 }
1157 ownerHasKeyUseWarning[currentComponentErrorInfo] = true;
1158
1159 // Usually the current owner is the offender, but if it accepts children as a
1160 // property, it may be the creator of the child that's responsible for
1161 // assigning it a key.
1162 var childOwner = '';
1163 if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
1164 // Give the component that originally created this child.
1165 childOwner = ' It was passed a child from ' + getComponentName(element._owner) + '.';
1166 }
1167
1168 currentlyValidatingElement = element;
1169 {
1170 warning(false, 'Each child in an array or iterator should have a unique "key" prop.' + '%s%s See https://fb.me/react-warning-keys for more information.%s', currentComponentErrorInfo, childOwner, getStackAddendum());
1171 }
1172 currentlyValidatingElement = null;
1173}
1174
1175/**
1176 * Ensure that every element either is passed in a static location, in an
1177 * array with an explicit keys property defined, or in an object literal
1178 * with valid key property.
1179 *
1180 * @internal
1181 * @param {ReactNode} node Statically passed child of any type.
1182 * @param {*} parentType node's parent's type.
1183 */
1184function validateChildKeys(node, parentType) {
1185 if (typeof node !== 'object') {
1186 return;
1187 }
1188 if (Array.isArray(node)) {
1189 for (var i = 0; i < node.length; i++) {
1190 var child = node[i];
1191 if (isValidElement(child)) {
1192 validateExplicitKey(child, parentType);
1193 }
1194 }
1195 } else if (isValidElement(node)) {
1196 // This element was passed in a valid location.
1197 if (node._store) {
1198 node._store.validated = true;
1199 }
1200 } else if (node) {
1201 var iteratorFn = getIteratorFn(node);
1202 if (typeof iteratorFn === 'function') {
1203 // Entry iterators used to provide implicit keys,
1204 // but now we print a separate warning for them later.
1205 if (iteratorFn !== node.entries) {
1206 var iterator = iteratorFn.call(node);
1207 var step = void 0;
1208 while (!(step = iterator.next()).done) {
1209 if (isValidElement(step.value)) {
1210 validateExplicitKey(step.value, parentType);
1211 }
1212 }
1213 }
1214 }
1215 }
1216}
1217
1218/**
1219 * Given an element, validate that its props follow the propTypes definition,
1220 * provided by the type.
1221 *
1222 * @param {ReactElement} element
1223 */
1224function validatePropTypes(element) {
1225 var componentClass = element.type;
1226 if (typeof componentClass !== 'function') {
1227 return;
1228 }
1229 var name = componentClass.displayName || componentClass.name;
1230 var propTypes = componentClass.propTypes;
1231 if (propTypes) {
1232 currentlyValidatingElement = element;
1233 checkPropTypes(propTypes, element.props, 'prop', name, getStackAddendum);
1234 currentlyValidatingElement = null;
1235 } else if (componentClass.PropTypes !== undefined && !propTypesMisspellWarningShown) {
1236 propTypesMisspellWarningShown = true;
1237 warning(false, 'Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', name || 'Unknown');
1238 }
1239 if (typeof componentClass.getDefaultProps === 'function') {
1240 !componentClass.getDefaultProps.isReactClassApproved ? warning(false, 'getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.') : void 0;
1241 }
1242}
1243
1244/**
1245 * Given a fragment, validate that it can only be provided with fragment props
1246 * @param {ReactElement} fragment
1247 */
1248function validateFragmentProps(fragment) {
1249 currentlyValidatingElement = fragment;
1250
1251 var keys = Object.keys(fragment.props);
1252 for (var i = 0; i < keys.length; i++) {
1253 var key = keys[i];
1254 if (key !== 'children' && key !== 'key') {
1255 warning(false, 'Invalid prop `%s` supplied to `React.Fragment`. ' + 'React.Fragment can only have `key` and `children` props.%s', key, getStackAddendum());
1256 break;
1257 }
1258 }
1259
1260 if (fragment.ref !== null) {
1261 warning(false, 'Invalid attribute `ref` supplied to `React.Fragment`.%s', getStackAddendum());
1262 }
1263
1264 currentlyValidatingElement = null;
1265}
1266
1267function createElementWithValidation(type, props, children) {
1268 var validType = isValidElementType(type);
1269
1270 // We warn in this case but don't throw. We expect the element creation to
1271 // succeed and there will likely be errors in render.
1272 if (!validType) {
1273 var info = '';
1274 if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
1275 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.";
1276 }
1277
1278 var sourceInfo = getSourceInfoErrorAddendum(props);
1279 if (sourceInfo) {
1280 info += sourceInfo;
1281 } else {
1282 info += getDeclarationErrorAddendum();
1283 }
1284
1285 info += getStackAddendum() || '';
1286
1287 var typeString = void 0;
1288 if (type === null) {
1289 typeString = 'null';
1290 } else if (Array.isArray(type)) {
1291 typeString = 'array';
1292 } else {
1293 typeString = typeof type;
1294 }
1295
1296 warning(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);
1297 }
1298
1299 var element = createElement.apply(this, arguments);
1300
1301 // The result can be nullish if a mock or a custom function is used.
1302 // TODO: Drop this when these are no longer allowed as the type argument.
1303 if (element == null) {
1304 return element;
1305 }
1306
1307 // Skip key warning if the type isn't valid since our key validation logic
1308 // doesn't expect a non-string/function type and can throw confusing errors.
1309 // We don't want exception behavior to differ between dev and prod.
1310 // (Rendering will throw with a helpful message and as soon as the type is
1311 // fixed, the key warnings will appear.)
1312 if (validType) {
1313 for (var i = 2; i < arguments.length; i++) {
1314 validateChildKeys(arguments[i], type);
1315 }
1316 }
1317
1318 if (type === REACT_FRAGMENT_TYPE) {
1319 validateFragmentProps(element);
1320 } else {
1321 validatePropTypes(element);
1322 }
1323
1324 return element;
1325}
1326
1327function createFactoryWithValidation(type) {
1328 var validatedFactory = createElementWithValidation.bind(null, type);
1329 validatedFactory.type = type;
1330 // Legacy hook: remove it
1331 {
1332 Object.defineProperty(validatedFactory, 'type', {
1333 enumerable: false,
1334 get: function () {
1335 lowPriorityWarning$1(false, 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.');
1336 Object.defineProperty(this, 'type', {
1337 value: type
1338 });
1339 return type;
1340 }
1341 });
1342 }
1343
1344 return validatedFactory;
1345}
1346
1347function cloneElementWithValidation(element, props, children) {
1348 var newElement = cloneElement.apply(this, arguments);
1349 for (var i = 2; i < arguments.length; i++) {
1350 validateChildKeys(arguments[i], newElement.type);
1351 }
1352 validatePropTypes(newElement);
1353 return newElement;
1354}
1355
1356var React = {
1357 Children: {
1358 map: mapChildren,
1359 forEach: forEachChildren,
1360 count: countChildren,
1361 toArray: toArray,
1362 only: onlyChild
1363 },
1364
1365 createRef: createRef,
1366 Component: Component,
1367 PureComponent: PureComponent,
1368
1369 createContext: createContext,
1370 forwardRef: forwardRef,
1371
1372 Fragment: REACT_FRAGMENT_TYPE,
1373 StrictMode: REACT_STRICT_MODE_TYPE,
1374 unstable_AsyncMode: REACT_ASYNC_MODE_TYPE,
1375
1376 createElement: createElementWithValidation,
1377 cloneElement: cloneElementWithValidation,
1378 createFactory: createFactoryWithValidation,
1379 isValidElement: isValidElement,
1380
1381 version: ReactVersion,
1382
1383 __SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
1384 ReactCurrentOwner: ReactCurrentOwner,
1385 // Used by renderers to avoid bundling object-assign twice in UMD bundles:
1386 assign: _assign
1387 }
1388};
1389
1390{
1391 _assign(React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED, {
1392 // These should not be included in production.
1393 ReactDebugCurrentFrame: ReactDebugCurrentFrame,
1394 // Shim for React DOM 16.0.0 which still destructured (but not used) this.
1395 // TODO: remove in React 17.0.
1396 ReactComponentTreeHook: {}
1397 });
1398}
1399
1400
1401
1402var React$2 = Object.freeze({
1403 default: React
1404});
1405
1406var React$3 = ( React$2 && React ) || React$2;
1407
1408// TODO: decide on the top-level export form.
1409// This is hacky but makes it work with both Rollup and Jest.
1410var react = React$3['default'] ? React$3['default'] : React$3;
1411
1412module.exports = react;
1413 })();
1414}