changeset 19 | 3d72ae0968f4 |
parent 18 | be944660c56a |
child 21 | 48c4eec2b7e6 |
18:be944660c56a | 19:3d72ae0968f4 |
---|---|
1 /** @license React v16.13.1 |
1 /** @license React v17.0.2 |
2 * react.development.js |
2 * react.development.js |
3 * |
3 * |
4 * Copyright (c) Facebook, Inc. and its affiliates. |
4 * Copyright (c) Facebook, Inc. and its affiliates. |
5 * |
5 * |
6 * This source code is licensed under the MIT license found in the |
6 * This source code is licensed under the MIT license found in the |
7 * LICENSE file in the root directory of this source tree. |
7 * LICENSE file in the root directory of this source tree. |
8 */ |
8 */ |
9 |
|
10 'use strict'; |
|
11 |
|
12 (function (global, factory) { |
9 (function (global, factory) { |
13 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : |
10 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : |
14 typeof define === 'function' && define.amd ? define(['exports'], factory) : |
11 typeof define === 'function' && define.amd ? define(['exports'], factory) : |
15 (global = global || self, factory(global.React = {})); |
12 (global = global || self, factory(global.React = {})); |
16 }(this, (function (exports) { 'use strict'; |
13 }(this, (function (exports) { 'use strict'; |
17 |
14 |
18 var ReactVersion = '16.13.1'; |
15 // TODO: this is special because it gets imported during build. |
19 |
16 var ReactVersion = '17.0.2'; |
17 |
|
18 // ATTENTION |
|
19 // When adding new symbols to this file, |
|
20 // Please consider also adding to 'react-devtools-shared/src/backend/ReactSymbols' |
|
20 // The Symbol used to tag the ReactElement-like types. If there is no native Symbol |
21 // The Symbol used to tag the ReactElement-like types. If there is no native Symbol |
21 // nor polyfill, then a plain number is used for performance. |
22 // nor polyfill, then a plain number is used for performance. |
22 var hasSymbol = typeof Symbol === 'function' && Symbol.for; |
23 var REACT_ELEMENT_TYPE = 0xeac7; |
23 var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7; |
24 var REACT_PORTAL_TYPE = 0xeaca; |
24 var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca; |
25 exports.Fragment = 0xeacb; |
25 var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb; |
26 exports.StrictMode = 0xeacc; |
26 var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc; |
27 exports.Profiler = 0xead2; |
27 var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2; |
28 var REACT_PROVIDER_TYPE = 0xeacd; |
28 var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd; |
29 var REACT_CONTEXT_TYPE = 0xeace; |
29 var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace; // TODO: We don't use AsyncMode or ConcurrentMode anymore. They were temporary |
30 var REACT_FORWARD_REF_TYPE = 0xead0; |
30 var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf; |
31 exports.Suspense = 0xead1; |
31 var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0; |
32 var REACT_SUSPENSE_LIST_TYPE = 0xead8; |
32 var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1; |
33 var REACT_MEMO_TYPE = 0xead3; |
33 var REACT_SUSPENSE_LIST_TYPE = hasSymbol ? Symbol.for('react.suspense_list') : 0xead8; |
34 var REACT_LAZY_TYPE = 0xead4; |
34 var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3; |
35 var REACT_BLOCK_TYPE = 0xead9; |
35 var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4; |
36 var REACT_SERVER_BLOCK_TYPE = 0xeada; |
36 var REACT_BLOCK_TYPE = hasSymbol ? Symbol.for('react.block') : 0xead9; |
37 var REACT_FUNDAMENTAL_TYPE = 0xead5; |
37 var REACT_FUNDAMENTAL_TYPE = hasSymbol ? Symbol.for('react.fundamental') : 0xead5; |
38 var REACT_SCOPE_TYPE = 0xead7; |
38 var REACT_RESPONDER_TYPE = hasSymbol ? Symbol.for('react.responder') : 0xead6; |
39 var REACT_OPAQUE_ID_TYPE = 0xeae0; |
39 var REACT_SCOPE_TYPE = hasSymbol ? Symbol.for('react.scope') : 0xead7; |
40 var REACT_DEBUG_TRACING_MODE_TYPE = 0xeae1; |
41 var REACT_OFFSCREEN_TYPE = 0xeae2; |
|
42 var REACT_LEGACY_HIDDEN_TYPE = 0xeae3; |
|
43 |
|
44 if (typeof Symbol === 'function' && Symbol.for) { |
|
45 var symbolFor = Symbol.for; |
|
46 REACT_ELEMENT_TYPE = symbolFor('react.element'); |
|
47 REACT_PORTAL_TYPE = symbolFor('react.portal'); |
|
48 exports.Fragment = symbolFor('react.fragment'); |
|
49 exports.StrictMode = symbolFor('react.strict_mode'); |
|
50 exports.Profiler = symbolFor('react.profiler'); |
|
51 REACT_PROVIDER_TYPE = symbolFor('react.provider'); |
|
52 REACT_CONTEXT_TYPE = symbolFor('react.context'); |
|
53 REACT_FORWARD_REF_TYPE = symbolFor('react.forward_ref'); |
|
54 exports.Suspense = symbolFor('react.suspense'); |
|
55 REACT_SUSPENSE_LIST_TYPE = symbolFor('react.suspense_list'); |
|
56 REACT_MEMO_TYPE = symbolFor('react.memo'); |
|
57 REACT_LAZY_TYPE = symbolFor('react.lazy'); |
|
58 REACT_BLOCK_TYPE = symbolFor('react.block'); |
|
59 REACT_SERVER_BLOCK_TYPE = symbolFor('react.server.block'); |
|
60 REACT_FUNDAMENTAL_TYPE = symbolFor('react.fundamental'); |
|
61 REACT_SCOPE_TYPE = symbolFor('react.scope'); |
|
62 REACT_OPAQUE_ID_TYPE = symbolFor('react.opaque.id'); |
|
63 REACT_DEBUG_TRACING_MODE_TYPE = symbolFor('react.debug_trace_mode'); |
|
64 REACT_OFFSCREEN_TYPE = symbolFor('react.offscreen'); |
|
65 REACT_LEGACY_HIDDEN_TYPE = symbolFor('react.legacy_hidden'); |
|
66 } |
|
67 |
|
40 var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; |
68 var MAYBE_ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator; |
41 var FAUX_ITERATOR_SYMBOL = '@@iterator'; |
69 var FAUX_ITERATOR_SYMBOL = '@@iterator'; |
42 function getIteratorFn(maybeIterable) { |
70 function getIteratorFn(maybeIterable) { |
43 if (maybeIterable === null || typeof maybeIterable !== 'object') { |
71 if (maybeIterable === null || typeof maybeIterable !== 'object') { |
44 return null; |
72 return null; |
51 } |
79 } |
52 |
80 |
53 return null; |
81 return null; |
54 } |
82 } |
55 |
83 |
56 /* |
|
57 object-assign |
|
58 (c) Sindre Sorhus |
|
59 @license MIT |
|
60 */ |
|
61 /* eslint-disable no-unused-vars */ |
|
62 var getOwnPropertySymbols = Object.getOwnPropertySymbols; |
|
63 var hasOwnProperty = Object.prototype.hasOwnProperty; |
84 var hasOwnProperty = Object.prototype.hasOwnProperty; |
64 var propIsEnumerable = Object.prototype.propertyIsEnumerable; |
85 |
65 |
86 var _assign = function (to, from) { |
66 function toObject(val) { |
87 for (var key in from) { |
67 if (val === null || val === undefined) { |
88 if (hasOwnProperty.call(from, key)) { |
68 throw new TypeError('Object.assign cannot be called with null or undefined'); |
89 to[key] = from[key]; |
69 } |
90 } |
70 |
91 } |
71 return Object(val); |
92 }; |
72 } |
93 |
73 |
94 var assign = Object.assign || function (target, sources) { |
74 function shouldUseNative() { |
95 if (target == null) { |
75 try { |
96 throw new TypeError('Object.assign target cannot be null or undefined'); |
76 if (!Object.assign) { |
97 } |
77 return false; |
98 |
78 } |
99 var to = Object(target); |
79 |
100 |
80 // Detect buggy property enumeration order in older V8 versions. |
101 for (var nextIndex = 1; nextIndex < arguments.length; nextIndex++) { |
81 |
102 var nextSource = arguments[nextIndex]; |
82 // https://bugs.chromium.org/p/v8/issues/detail?id=4118 |
103 |
83 var test1 = new String('abc'); // eslint-disable-line no-new-wrappers |
104 if (nextSource != null) { |
84 test1[5] = 'de'; |
105 _assign(to, Object(nextSource)); |
85 if (Object.getOwnPropertyNames(test1)[0] === '5') { |
106 } |
86 return false; |
107 } |
87 } |
108 |
88 |
109 return to; |
89 // https://bugs.chromium.org/p/v8/issues/detail?id=3056 |
|
90 var test2 = {}; |
|
91 for (var i = 0; i < 10; i++) { |
|
92 test2['_' + String.fromCharCode(i)] = i; |
|
93 } |
|
94 var order2 = Object.getOwnPropertyNames(test2).map(function (n) { |
|
95 return test2[n]; |
|
96 }); |
|
97 if (order2.join('') !== '0123456789') { |
|
98 return false; |
|
99 } |
|
100 |
|
101 // https://bugs.chromium.org/p/v8/issues/detail?id=3056 |
|
102 var test3 = {}; |
|
103 'abcdefghijklmnopqrst'.split('').forEach(function (letter) { |
|
104 test3[letter] = letter; |
|
105 }); |
|
106 if (Object.keys(Object.assign({}, test3)).join('') !== |
|
107 'abcdefghijklmnopqrst') { |
|
108 return false; |
|
109 } |
|
110 |
|
111 return true; |
|
112 } catch (err) { |
|
113 // We don't expect any of the above to throw, but better to be safe. |
|
114 return false; |
|
115 } |
|
116 } |
|
117 |
|
118 var objectAssign = shouldUseNative() ? Object.assign : function (target, source) { |
|
119 var from; |
|
120 var to = toObject(target); |
|
121 var symbols; |
|
122 |
|
123 for (var s = 1; s < arguments.length; s++) { |
|
124 from = Object(arguments[s]); |
|
125 |
|
126 for (var key in from) { |
|
127 if (hasOwnProperty.call(from, key)) { |
|
128 to[key] = from[key]; |
|
129 } |
|
130 } |
|
131 |
|
132 if (getOwnPropertySymbols) { |
|
133 symbols = getOwnPropertySymbols(from); |
|
134 for (var i = 0; i < symbols.length; i++) { |
|
135 if (propIsEnumerable.call(from, symbols[i])) { |
|
136 to[symbols[i]] = from[symbols[i]]; |
|
137 } |
|
138 } |
|
139 } |
|
140 } |
|
141 |
|
142 return to; |
|
143 }; |
110 }; |
144 |
111 |
145 /** |
112 /** |
146 * Keeps track of the current dispatcher. |
113 * Keeps track of the current dispatcher. |
147 */ |
114 */ |
156 /** |
123 /** |
157 * Keeps track of the current batch's configuration such as how long an update |
124 * Keeps track of the current batch's configuration such as how long an update |
158 * should suspend for if it needs to. |
125 * should suspend for if it needs to. |
159 */ |
126 */ |
160 var ReactCurrentBatchConfig = { |
127 var ReactCurrentBatchConfig = { |
161 suspense: null |
128 transition: 0 |
162 }; |
129 }; |
163 |
130 |
164 /** |
131 /** |
165 * Keeps track of the current owner. |
132 * Keeps track of the current owner. |
166 * |
133 * |
173 * @type {ReactComponent} |
140 * @type {ReactComponent} |
174 */ |
141 */ |
175 current: null |
142 current: null |
176 }; |
143 }; |
177 |
144 |
178 var BEFORE_SLASH_RE = /^(.*)[\\\/]/; |
145 var ReactDebugCurrentFrame = {}; |
179 function describeComponentFrame (name, source, ownerName) { |
146 var currentExtraStackFrame = null; |
180 var sourceInfo = ''; |
147 function setExtraStackFrame(stack) { |
181 |
148 { |
182 if (source) { |
149 currentExtraStackFrame = stack; |
183 var path = source.fileName; |
150 } |
184 var fileName = path.replace(BEFORE_SLASH_RE, ''); |
151 } |
185 |
152 |
153 { |
|
154 ReactDebugCurrentFrame.setExtraStackFrame = function (stack) { |
|
186 { |
155 { |
187 // In DEV, include code for a common special case: |
156 currentExtraStackFrame = stack; |
188 // prefer "folder/index.js" instead of just "index.js". |
157 } |
189 if (/^index\./.test(fileName)) { |
158 }; // Stack implementation injected by the current renderer. |
190 var match = path.match(BEFORE_SLASH_RE); |
159 |
191 |
160 |
192 if (match) { |
|
193 var pathBeforeSlash = match[1]; |
|
194 |
|
195 if (pathBeforeSlash) { |
|
196 var folderName = pathBeforeSlash.replace(BEFORE_SLASH_RE, ''); |
|
197 fileName = folderName + '/' + fileName; |
|
198 } |
|
199 } |
|
200 } |
|
201 } |
|
202 |
|
203 sourceInfo = ' (at ' + fileName + ':' + source.lineNumber + ')'; |
|
204 } else if (ownerName) { |
|
205 sourceInfo = ' (created by ' + ownerName + ')'; |
|
206 } |
|
207 |
|
208 return '\n in ' + (name || 'Unknown') + sourceInfo; |
|
209 } |
|
210 |
|
211 var Resolved = 1; |
|
212 function refineResolvedLazyComponent(lazyComponent) { |
|
213 return lazyComponent._status === Resolved ? lazyComponent._result : null; |
|
214 } |
|
215 |
|
216 function getWrappedName(outerType, innerType, wrapperName) { |
|
217 var functionName = innerType.displayName || innerType.name || ''; |
|
218 return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName); |
|
219 } |
|
220 |
|
221 function getComponentName(type) { |
|
222 if (type == null) { |
|
223 // Host root, text node or just invalid type. |
|
224 return null; |
|
225 } |
|
226 |
|
227 { |
|
228 if (typeof type.tag === 'number') { |
|
229 error('Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.'); |
|
230 } |
|
231 } |
|
232 |
|
233 if (typeof type === 'function') { |
|
234 return type.displayName || type.name || null; |
|
235 } |
|
236 |
|
237 if (typeof type === 'string') { |
|
238 return type; |
|
239 } |
|
240 |
|
241 switch (type) { |
|
242 case REACT_FRAGMENT_TYPE: |
|
243 return 'Fragment'; |
|
244 |
|
245 case REACT_PORTAL_TYPE: |
|
246 return 'Portal'; |
|
247 |
|
248 case REACT_PROFILER_TYPE: |
|
249 return "Profiler"; |
|
250 |
|
251 case REACT_STRICT_MODE_TYPE: |
|
252 return 'StrictMode'; |
|
253 |
|
254 case REACT_SUSPENSE_TYPE: |
|
255 return 'Suspense'; |
|
256 |
|
257 case REACT_SUSPENSE_LIST_TYPE: |
|
258 return 'SuspenseList'; |
|
259 } |
|
260 |
|
261 if (typeof type === 'object') { |
|
262 switch (type.$$typeof) { |
|
263 case REACT_CONTEXT_TYPE: |
|
264 return 'Context.Consumer'; |
|
265 |
|
266 case REACT_PROVIDER_TYPE: |
|
267 return 'Context.Provider'; |
|
268 |
|
269 case REACT_FORWARD_REF_TYPE: |
|
270 return getWrappedName(type, type.render, 'ForwardRef'); |
|
271 |
|
272 case REACT_MEMO_TYPE: |
|
273 return getComponentName(type.type); |
|
274 |
|
275 case REACT_BLOCK_TYPE: |
|
276 return getComponentName(type.render); |
|
277 |
|
278 case REACT_LAZY_TYPE: |
|
279 { |
|
280 var thenable = type; |
|
281 var resolvedThenable = refineResolvedLazyComponent(thenable); |
|
282 |
|
283 if (resolvedThenable) { |
|
284 return getComponentName(resolvedThenable); |
|
285 } |
|
286 |
|
287 break; |
|
288 } |
|
289 } |
|
290 } |
|
291 |
|
292 return null; |
|
293 } |
|
294 |
|
295 var ReactDebugCurrentFrame = {}; |
|
296 var currentlyValidatingElement = null; |
|
297 function setCurrentlyValidatingElement(element) { |
|
298 { |
|
299 currentlyValidatingElement = element; |
|
300 } |
|
301 } |
|
302 |
|
303 { |
|
304 // Stack implementation injected by the current renderer. |
|
305 ReactDebugCurrentFrame.getCurrentStack = null; |
161 ReactDebugCurrentFrame.getCurrentStack = null; |
306 |
162 |
307 ReactDebugCurrentFrame.getStackAddendum = function () { |
163 ReactDebugCurrentFrame.getStackAddendum = function () { |
308 var stack = ''; // Add an extra top frame while an element is being validated |
164 var stack = ''; // Add an extra top frame while an element is being validated |
309 |
165 |
310 if (currentlyValidatingElement) { |
166 if (currentExtraStackFrame) { |
311 var name = getComponentName(currentlyValidatingElement.type); |
167 stack += currentExtraStackFrame; |
312 var owner = currentlyValidatingElement._owner; |
|
313 stack += describeComponentFrame(name, currentlyValidatingElement._source, owner && getComponentName(owner.type)); |
|
314 } // Delegate to the injected renderer-specific implementation |
168 } // Delegate to the injected renderer-specific implementation |
315 |
169 |
316 |
170 |
317 var impl = ReactDebugCurrentFrame.getCurrentStack; |
171 var impl = ReactDebugCurrentFrame.getCurrentStack; |
318 |
172 |
335 ReactCurrentDispatcher: ReactCurrentDispatcher, |
189 ReactCurrentDispatcher: ReactCurrentDispatcher, |
336 ReactCurrentBatchConfig: ReactCurrentBatchConfig, |
190 ReactCurrentBatchConfig: ReactCurrentBatchConfig, |
337 ReactCurrentOwner: ReactCurrentOwner, |
191 ReactCurrentOwner: ReactCurrentOwner, |
338 IsSomeRendererActing: IsSomeRendererActing, |
192 IsSomeRendererActing: IsSomeRendererActing, |
339 // Used by renderers to avoid bundling object-assign twice in UMD bundles: |
193 // Used by renderers to avoid bundling object-assign twice in UMD bundles: |
340 assign: objectAssign |
194 assign: assign |
341 }; |
195 }; |
342 |
196 |
343 { |
197 { |
344 objectAssign(ReactSharedInternals, { |
198 ReactSharedInternals.ReactDebugCurrentFrame = ReactDebugCurrentFrame; |
345 // These should not be included in production. |
|
346 ReactDebugCurrentFrame: ReactDebugCurrentFrame, |
|
347 // Shim for React DOM 16.0.0 which still destructured (but not used) this. |
|
348 // TODO: remove in React 17.0. |
|
349 ReactComponentTreeHook: {} |
|
350 }); |
|
351 } |
199 } |
352 |
200 |
353 // by calls to these methods by a Babel plugin. |
201 // by calls to these methods by a Babel plugin. |
354 // |
202 // |
355 // In PROD (or in packages without access to React internals), |
203 // In PROD (or in packages without access to React internals), |
376 |
224 |
377 function printWarning(level, format, args) { |
225 function printWarning(level, format, args) { |
378 // When changing this logic, you might want to also |
226 // When changing this logic, you might want to also |
379 // update consoleWithStackDev.www.js as well. |
227 // update consoleWithStackDev.www.js as well. |
380 { |
228 { |
381 var hasExistingStack = args.length > 0 && typeof args[args.length - 1] === 'string' && args[args.length - 1].indexOf('\n in') === 0; |
229 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; |
382 |
230 var stack = ReactDebugCurrentFrame.getStackAddendum(); |
383 if (!hasExistingStack) { |
231 |
384 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame; |
232 if (stack !== '') { |
385 var stack = ReactDebugCurrentFrame.getStackAddendum(); |
233 format += '%s'; |
386 |
234 args = args.concat([stack]); |
387 if (stack !== '') { |
|
388 format += '%s'; |
|
389 args = args.concat([stack]); |
|
390 } |
|
391 } |
235 } |
392 |
236 |
393 var argsWithFormat = args.map(function (item) { |
237 var argsWithFormat = args.map(function (item) { |
394 return '' + item; |
238 return '' + item; |
395 }); // Careful: RN currently depends on this prefix |
239 }); // Careful: RN currently depends on this prefix |
397 argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it |
241 argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it |
398 // breaks IE9: https://github.com/facebook/react/issues/13610 |
242 // breaks IE9: https://github.com/facebook/react/issues/13610 |
399 // eslint-disable-next-line react-internal/no-production-logging |
243 // eslint-disable-next-line react-internal/no-production-logging |
400 |
244 |
401 Function.prototype.apply.call(console[level], console, argsWithFormat); |
245 Function.prototype.apply.call(console[level], console, argsWithFormat); |
402 |
|
403 try { |
|
404 // --- Welcome to debugging React --- |
|
405 // This error was thrown as a convenience so that you can use this stack |
|
406 // to find the callsite that caused this warning to fire. |
|
407 var argIndex = 0; |
|
408 var message = 'Warning: ' + format.replace(/%s/g, function () { |
|
409 return args[argIndex++]; |
|
410 }); |
|
411 throw new Error(message); |
|
412 } catch (x) {} |
|
413 } |
246 } |
414 } |
247 } |
415 |
248 |
416 var didWarnStateUpdateForUnmountedComponent = {}; |
249 var didWarnStateUpdateForUnmountedComponent = {}; |
417 |
250 |
621 } |
454 } |
622 |
455 |
623 var pureComponentPrototype = PureComponent.prototype = new ComponentDummy(); |
456 var pureComponentPrototype = PureComponent.prototype = new ComponentDummy(); |
624 pureComponentPrototype.constructor = PureComponent; // Avoid an extra prototype jump for these methods. |
457 pureComponentPrototype.constructor = PureComponent; // Avoid an extra prototype jump for these methods. |
625 |
458 |
626 objectAssign(pureComponentPrototype, Component.prototype); |
459 assign(pureComponentPrototype, Component.prototype); |
627 |
460 |
628 pureComponentPrototype.isPureReactComponent = true; |
461 pureComponentPrototype.isPureReactComponent = true; |
629 |
462 |
630 // an immutable object with a single mutable value |
463 // an immutable object with a single mutable value |
631 function createRef() { |
464 function createRef() { |
636 { |
469 { |
637 Object.seal(refObject); |
470 Object.seal(refObject); |
638 } |
471 } |
639 |
472 |
640 return refObject; |
473 return refObject; |
474 } |
|
475 |
|
476 function getWrappedName(outerType, innerType, wrapperName) { |
|
477 var functionName = innerType.displayName || innerType.name || ''; |
|
478 return outerType.displayName || (functionName !== '' ? wrapperName + "(" + functionName + ")" : wrapperName); |
|
479 } |
|
480 |
|
481 function getContextName(type) { |
|
482 return type.displayName || 'Context'; |
|
483 } |
|
484 |
|
485 function getComponentName(type) { |
|
486 if (type == null) { |
|
487 // Host root, text node or just invalid type. |
|
488 return null; |
|
489 } |
|
490 |
|
491 { |
|
492 if (typeof type.tag === 'number') { |
|
493 error('Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.'); |
|
494 } |
|
495 } |
|
496 |
|
497 if (typeof type === 'function') { |
|
498 return type.displayName || type.name || null; |
|
499 } |
|
500 |
|
501 if (typeof type === 'string') { |
|
502 return type; |
|
503 } |
|
504 |
|
505 switch (type) { |
|
506 case exports.Fragment: |
|
507 return 'Fragment'; |
|
508 |
|
509 case REACT_PORTAL_TYPE: |
|
510 return 'Portal'; |
|
511 |
|
512 case exports.Profiler: |
|
513 return 'Profiler'; |
|
514 |
|
515 case exports.StrictMode: |
|
516 return 'StrictMode'; |
|
517 |
|
518 case exports.Suspense: |
|
519 return 'Suspense'; |
|
520 |
|
521 case REACT_SUSPENSE_LIST_TYPE: |
|
522 return 'SuspenseList'; |
|
523 } |
|
524 |
|
525 if (typeof type === 'object') { |
|
526 switch (type.$$typeof) { |
|
527 case REACT_CONTEXT_TYPE: |
|
528 var context = type; |
|
529 return getContextName(context) + '.Consumer'; |
|
530 |
|
531 case REACT_PROVIDER_TYPE: |
|
532 var provider = type; |
|
533 return getContextName(provider._context) + '.Provider'; |
|
534 |
|
535 case REACT_FORWARD_REF_TYPE: |
|
536 return getWrappedName(type, type.render, 'ForwardRef'); |
|
537 |
|
538 case REACT_MEMO_TYPE: |
|
539 return getComponentName(type.type); |
|
540 |
|
541 case REACT_BLOCK_TYPE: |
|
542 return getComponentName(type._render); |
|
543 |
|
544 case REACT_LAZY_TYPE: |
|
545 { |
|
546 var lazyComponent = type; |
|
547 var payload = lazyComponent._payload; |
|
548 var init = lazyComponent._init; |
|
549 |
|
550 try { |
|
551 return getComponentName(init(payload)); |
|
552 } catch (x) { |
|
553 return null; |
|
554 } |
|
555 } |
|
556 } |
|
557 } |
|
558 |
|
559 return null; |
|
641 } |
560 } |
642 |
561 |
643 var hasOwnProperty$1 = Object.prototype.hasOwnProperty; |
562 var hasOwnProperty$1 = Object.prototype.hasOwnProperty; |
644 var RESERVED_PROPS = { |
563 var RESERVED_PROPS = { |
645 key: true, |
564 key: true, |
685 var warnAboutAccessingKey = function () { |
604 var warnAboutAccessingKey = function () { |
686 { |
605 { |
687 if (!specialPropKeyWarningShown) { |
606 if (!specialPropKeyWarningShown) { |
688 specialPropKeyWarningShown = true; |
607 specialPropKeyWarningShown = true; |
689 |
608 |
690 error('%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', displayName); |
609 error('%s: `key` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName); |
691 } |
610 } |
692 } |
611 } |
693 }; |
612 }; |
694 |
613 |
695 warnAboutAccessingKey.isReactWarning = true; |
614 warnAboutAccessingKey.isReactWarning = true; |
703 var warnAboutAccessingRef = function () { |
622 var warnAboutAccessingRef = function () { |
704 { |
623 { |
705 if (!specialPropRefWarningShown) { |
624 if (!specialPropRefWarningShown) { |
706 specialPropRefWarningShown = true; |
625 specialPropRefWarningShown = true; |
707 |
626 |
708 error('%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://fb.me/react-special-props)', displayName); |
627 error('%s: `ref` is not a prop. Trying to access it will result ' + 'in `undefined` being returned. If you need to access the same ' + 'value within the child component, you should pass it as a different ' + 'prop. (https://reactjs.org/link/special-props)', displayName); |
709 } |
628 } |
710 } |
629 } |
711 }; |
630 }; |
712 |
631 |
713 warnAboutAccessingRef.isReactWarning = true; |
632 warnAboutAccessingRef.isReactWarning = true; |
721 { |
640 { |
722 if (typeof config.ref === 'string' && ReactCurrentOwner.current && config.__self && ReactCurrentOwner.current.stateNode !== config.__self) { |
641 if (typeof config.ref === 'string' && ReactCurrentOwner.current && config.__self && ReactCurrentOwner.current.stateNode !== config.__self) { |
723 var componentName = getComponentName(ReactCurrentOwner.current.type); |
642 var componentName = getComponentName(ReactCurrentOwner.current.type); |
724 |
643 |
725 if (!didWarnAboutStringRefs[componentName]) { |
644 if (!didWarnAboutStringRefs[componentName]) { |
726 error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://fb.me/react-strict-mode-string-ref', getComponentName(ReactCurrentOwner.current.type), config.ref); |
645 error('Component "%s" contains the string ref "%s". ' + 'Support for string refs will be removed in a future major release. ' + 'This case cannot be automatically converted to an arrow function. ' + 'We ask you to manually fix this case by using useRef() or createRef() instead. ' + 'Learn more about using refs safely here: ' + 'https://reactjs.org/link/strict-mode-string-ref', componentName, config.ref); |
727 |
646 |
728 didWarnAboutStringRefs[componentName] = true; |
647 didWarnAboutStringRefs[componentName] = true; |
729 } |
648 } |
730 } |
649 } |
731 } |
650 } |
907 } |
826 } |
908 } |
827 } |
909 |
828 |
910 var propName; // Original props are copied |
829 var propName; // Original props are copied |
911 |
830 |
912 var props = objectAssign({}, element.props); // Reserved names are extracted |
831 var props = assign({}, element.props); // Reserved names are extracted |
913 |
832 |
914 |
833 |
915 var key = element.key; |
834 var key = element.key; |
916 var ref = element.ref; // Self is preserved since the owner is preserved. |
835 var ref = element.ref; // Self is preserved since the owner is preserved. |
917 |
836 |
996 var escapeRegex = /[=:]/g; |
915 var escapeRegex = /[=:]/g; |
997 var escaperLookup = { |
916 var escaperLookup = { |
998 '=': '=0', |
917 '=': '=0', |
999 ':': '=2' |
918 ':': '=2' |
1000 }; |
919 }; |
1001 var escapedString = ('' + key).replace(escapeRegex, function (match) { |
920 var escapedString = key.replace(escapeRegex, function (match) { |
1002 return escaperLookup[match]; |
921 return escaperLookup[match]; |
1003 }); |
922 }); |
1004 return '$' + escapedString; |
923 return '$' + escapedString; |
1005 } |
924 } |
1006 /** |
925 /** |
1011 |
930 |
1012 var didWarnAboutMaps = false; |
931 var didWarnAboutMaps = false; |
1013 var userProvidedKeyEscapeRegex = /\/+/g; |
932 var userProvidedKeyEscapeRegex = /\/+/g; |
1014 |
933 |
1015 function escapeUserProvidedKey(text) { |
934 function escapeUserProvidedKey(text) { |
1016 return ('' + text).replace(userProvidedKeyEscapeRegex, '$&/'); |
935 return text.replace(userProvidedKeyEscapeRegex, '$&/'); |
1017 } |
|
1018 |
|
1019 var POOL_SIZE = 10; |
|
1020 var traverseContextPool = []; |
|
1021 |
|
1022 function getPooledTraverseContext(mapResult, keyPrefix, mapFunction, mapContext) { |
|
1023 if (traverseContextPool.length) { |
|
1024 var traverseContext = traverseContextPool.pop(); |
|
1025 traverseContext.result = mapResult; |
|
1026 traverseContext.keyPrefix = keyPrefix; |
|
1027 traverseContext.func = mapFunction; |
|
1028 traverseContext.context = mapContext; |
|
1029 traverseContext.count = 0; |
|
1030 return traverseContext; |
|
1031 } else { |
|
1032 return { |
|
1033 result: mapResult, |
|
1034 keyPrefix: keyPrefix, |
|
1035 func: mapFunction, |
|
1036 context: mapContext, |
|
1037 count: 0 |
|
1038 }; |
|
1039 } |
|
1040 } |
|
1041 |
|
1042 function releaseTraverseContext(traverseContext) { |
|
1043 traverseContext.result = null; |
|
1044 traverseContext.keyPrefix = null; |
|
1045 traverseContext.func = null; |
|
1046 traverseContext.context = null; |
|
1047 traverseContext.count = 0; |
|
1048 |
|
1049 if (traverseContextPool.length < POOL_SIZE) { |
|
1050 traverseContextPool.push(traverseContext); |
|
1051 } |
|
1052 } |
936 } |
1053 /** |
937 /** |
1054 * @param {?*} children Children tree container. |
938 * Generate a key string that identifies a element within a set. |
1055 * @param {!string} nameSoFar Name of the key path so far. |
939 * |
1056 * @param {!function} callback Callback to invoke with each child found. |
940 * @param {*} element A element that could contain a manual key. |
1057 * @param {?*} traverseContext Used to pass information throughout the traversal |
941 * @param {number} index Index that is used if a manual key is not provided. |
1058 * process. |
942 * @return {string} |
1059 * @return {!number} The number of children in this subtree. |
|
1060 */ |
943 */ |
1061 |
944 |
1062 |
945 |
1063 function traverseAllChildrenImpl(children, nameSoFar, callback, traverseContext) { |
946 function getElementKey(element, index) { |
947 // Do some typechecking here since we call this blindly. We want to ensure |
|
948 // that we don't block potential future ES APIs. |
|
949 if (typeof element === 'object' && element !== null && element.key != null) { |
|
950 // Explicit key |
|
951 return escape('' + element.key); |
|
952 } // Implicit key determined by the index in the set |
|
953 |
|
954 |
|
955 return index.toString(36); |
|
956 } |
|
957 |
|
958 function mapIntoArray(children, array, escapedPrefix, nameSoFar, callback) { |
|
1064 var type = typeof children; |
959 var type = typeof children; |
1065 |
960 |
1066 if (type === 'undefined' || type === 'boolean') { |
961 if (type === 'undefined' || type === 'boolean') { |
1067 // All of the above are perceived as null. |
962 // All of the above are perceived as null. |
1068 children = null; |
963 children = null; |
1088 |
983 |
1089 } |
984 } |
1090 } |
985 } |
1091 |
986 |
1092 if (invokeCallback) { |
987 if (invokeCallback) { |
1093 callback(traverseContext, children, // If it's the only child, treat the name as if it was wrapped in an array |
988 var _child = children; |
1094 // so that it's consistent if the number of children grows. |
989 var mappedChild = callback(_child); // If it's the only child, treat the name as if it was wrapped in an array |
1095 nameSoFar === '' ? SEPARATOR + getComponentKey(children, 0) : nameSoFar); |
990 // so that it's consistent if the number of children grows: |
991 |
|
992 var childKey = nameSoFar === '' ? SEPARATOR + getElementKey(_child, 0) : nameSoFar; |
|
993 |
|
994 if (Array.isArray(mappedChild)) { |
|
995 var escapedChildKey = ''; |
|
996 |
|
997 if (childKey != null) { |
|
998 escapedChildKey = escapeUserProvidedKey(childKey) + '/'; |
|
999 } |
|
1000 |
|
1001 mapIntoArray(mappedChild, array, escapedChildKey, '', function (c) { |
|
1002 return c; |
|
1003 }); |
|
1004 } else if (mappedChild != null) { |
|
1005 if (isValidElement(mappedChild)) { |
|
1006 mappedChild = cloneAndReplaceKey(mappedChild, // Keep both the (mapped) and old keys if they differ, just as |
|
1007 // traverseAllChildren used to do for objects as children |
|
1008 escapedPrefix + ( // $FlowFixMe Flow incorrectly thinks React.Portal doesn't have a key |
|
1009 mappedChild.key && (!_child || _child.key !== mappedChild.key) ? // $FlowFixMe Flow incorrectly thinks existing element's key can be a number |
|
1010 escapeUserProvidedKey('' + mappedChild.key) + '/' : '') + childKey); |
|
1011 } |
|
1012 |
|
1013 array.push(mappedChild); |
|
1014 } |
|
1015 |
|
1096 return 1; |
1016 return 1; |
1097 } |
1017 } |
1098 |
1018 |
1099 var child; |
1019 var child; |
1100 var nextName; |
1020 var nextName; |
1103 var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR; |
1023 var nextNamePrefix = nameSoFar === '' ? SEPARATOR : nameSoFar + SUBSEPARATOR; |
1104 |
1024 |
1105 if (Array.isArray(children)) { |
1025 if (Array.isArray(children)) { |
1106 for (var i = 0; i < children.length; i++) { |
1026 for (var i = 0; i < children.length; i++) { |
1107 child = children[i]; |
1027 child = children[i]; |
1108 nextName = nextNamePrefix + getComponentKey(child, i); |
1028 nextName = nextNamePrefix + getElementKey(child, i); |
1109 subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext); |
1029 subtreeCount += mapIntoArray(child, array, escapedPrefix, nextName, callback); |
1110 } |
1030 } |
1111 } else { |
1031 } else { |
1112 var iteratorFn = getIteratorFn(children); |
1032 var iteratorFn = getIteratorFn(children); |
1113 |
1033 |
1114 if (typeof iteratorFn === 'function') { |
1034 if (typeof iteratorFn === 'function') { |
1035 var iterableChildren = children; |
|
1115 |
1036 |
1116 { |
1037 { |
1117 // Warn about using Maps as children |
1038 // Warn about using Maps as children |
1118 if (iteratorFn === children.entries) { |
1039 if (iteratorFn === iterableChildren.entries) { |
1119 if (!didWarnAboutMaps) { |
1040 if (!didWarnAboutMaps) { |
1120 warn('Using Maps as children is deprecated and will be removed in ' + 'a future major release. Consider converting children to ' + 'an array of keyed ReactElements instead.'); |
1041 warn('Using Maps as children is not supported. ' + 'Use an array of keyed ReactElements instead.'); |
1121 } |
1042 } |
1122 |
1043 |
1123 didWarnAboutMaps = true; |
1044 didWarnAboutMaps = true; |
1124 } |
1045 } |
1125 } |
1046 } |
1126 |
1047 |
1127 var iterator = iteratorFn.call(children); |
1048 var iterator = iteratorFn.call(iterableChildren); |
1128 var step; |
1049 var step; |
1129 var ii = 0; |
1050 var ii = 0; |
1130 |
1051 |
1131 while (!(step = iterator.next()).done) { |
1052 while (!(step = iterator.next()).done) { |
1132 child = step.value; |
1053 child = step.value; |
1133 nextName = nextNamePrefix + getComponentKey(child, ii++); |
1054 nextName = nextNamePrefix + getElementKey(child, ii++); |
1134 subtreeCount += traverseAllChildrenImpl(child, nextName, callback, traverseContext); |
1055 subtreeCount += mapIntoArray(child, array, escapedPrefix, nextName, callback); |
1135 } |
1056 } |
1136 } else if (type === 'object') { |
1057 } else if (type === 'object') { |
1137 var addendum = ''; |
|
1138 |
|
1139 { |
|
1140 addendum = ' If you meant to render a collection of children, use an array ' + 'instead.' + ReactDebugCurrentFrame.getStackAddendum(); |
|
1141 } |
|
1142 |
|
1143 var childrenString = '' + children; |
1058 var childrenString = '' + children; |
1144 |
1059 |
1145 { |
1060 { |
1146 { |
1061 { |
1147 throw Error( "Objects are not valid as a React child (found: " + (childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString) + ")." + addendum ); |
1062 throw Error( "Objects are not valid as a React child (found: " + (childrenString === '[object Object]' ? 'object with keys {' + Object.keys(children).join(', ') + '}' : childrenString) + "). If you meant to render a collection of children, use an array instead." ); |
1148 } |
1063 } |
1149 } |
1064 } |
1150 } |
1065 } |
1151 } |
1066 } |
1152 |
1067 |
1153 return subtreeCount; |
1068 return subtreeCount; |
1154 } |
1069 } |
1070 |
|
1155 /** |
1071 /** |
1156 * Traverses children that are typically specified as `props.children`, but |
1072 * Maps children that are typically specified as `props.children`. |
1157 * might also be specified through attributes: |
|
1158 * |
1073 * |
1159 * - `traverseAllChildren(this.props.children, ...)` |
1074 * See https://reactjs.org/docs/react-api.html#reactchildrenmap |
1160 * - `traverseAllChildren(this.props.leftPanelChildren, ...)` |
|
1161 * |
1075 * |
1162 * The `traverseContext` is an optional argument that is passed through the |
1076 * The provided mapFunction(child, index) will be called for each |
1163 * entire traversal. It can be used to store accumulations or anything else that |
1077 * leaf child. |
1164 * the callback might find relevant. |
|
1165 * |
1078 * |
1166 * @param {?*} children Children tree object. |
1079 * @param {?*} children Children tree container. |
1167 * @param {!function} callback To invoke upon traversing each child. |
1080 * @param {function(*, int)} func The map function. |
1168 * @param {?*} traverseContext Context for traversal. |
1081 * @param {*} context Context for mapFunction. |
1169 * @return {!number} The number of children in this subtree. |
1082 * @return {object} Object containing the ordered map of results. |
1170 */ |
1083 */ |
1171 |
1084 function mapChildren(children, func, context) { |
1172 |
|
1173 function traverseAllChildren(children, callback, traverseContext) { |
|
1174 if (children == null) { |
1085 if (children == null) { |
1175 return 0; |
1086 return children; |
1176 } |
1087 } |
1177 |
1088 |
1178 return traverseAllChildrenImpl(children, '', callback, traverseContext); |
1089 var result = []; |
1090 var count = 0; |
|
1091 mapIntoArray(children, result, '', '', function (child) { |
|
1092 return func.call(context, child, count++); |
|
1093 }); |
|
1094 return result; |
|
1179 } |
1095 } |
1180 /** |
1096 /** |
1181 * Generate a key string that identifies a component within a set. |
1097 * Count the number of children that are typically specified as |
1098 * `props.children`. |
|
1182 * |
1099 * |
1183 * @param {*} component A component that could contain a manual key. |
1100 * See https://reactjs.org/docs/react-api.html#reactchildrencount |
1184 * @param {number} index Index that is used if a manual key is not provided. |
1101 * |
1185 * @return {string} |
1102 * @param {?*} children Children tree container. |
1103 * @return {number} The number of children. |
|
1186 */ |
1104 */ |
1187 |
1105 |
1188 |
1106 |
1189 function getComponentKey(component, index) { |
1107 function countChildren(children) { |
1190 // Do some typechecking here since we call this blindly. We want to ensure |
1108 var n = 0; |
1191 // that we don't block potential future ES APIs. |
1109 mapChildren(children, function () { |
1192 if (typeof component === 'object' && component !== null && component.key != null) { |
1110 n++; // Don't return anything |
1193 // Explicit key |
1111 }); |
1194 return escape(component.key); |
1112 return n; |
1195 } // Implicit key determined by the index in the set |
1113 } |
1196 |
1114 |
1197 |
|
1198 return index.toString(36); |
|
1199 } |
|
1200 |
|
1201 function forEachSingleChild(bookKeeping, child, name) { |
|
1202 var func = bookKeeping.func, |
|
1203 context = bookKeeping.context; |
|
1204 func.call(context, child, bookKeeping.count++); |
|
1205 } |
|
1206 /** |
1115 /** |
1207 * Iterates through children that are typically specified as `props.children`. |
1116 * Iterates through children that are typically specified as `props.children`. |
1208 * |
1117 * |
1209 * See https://reactjs.org/docs/react-api.html#reactchildrenforeach |
1118 * See https://reactjs.org/docs/react-api.html#reactchildrenforeach |
1210 * |
1119 * |
1213 * |
1122 * |
1214 * @param {?*} children Children tree container. |
1123 * @param {?*} children Children tree container. |
1215 * @param {function(*, int)} forEachFunc |
1124 * @param {function(*, int)} forEachFunc |
1216 * @param {*} forEachContext Context for forEachContext. |
1125 * @param {*} forEachContext Context for forEachContext. |
1217 */ |
1126 */ |
1218 |
|
1219 |
|
1220 function forEachChildren(children, forEachFunc, forEachContext) { |
1127 function forEachChildren(children, forEachFunc, forEachContext) { |
1221 if (children == null) { |
1128 mapChildren(children, function () { |
1222 return children; |
1129 forEachFunc.apply(this, arguments); // Don't return anything. |
1223 } |
1130 }, forEachContext); |
1224 |
|
1225 var traverseContext = getPooledTraverseContext(null, null, forEachFunc, forEachContext); |
|
1226 traverseAllChildren(children, forEachSingleChild, traverseContext); |
|
1227 releaseTraverseContext(traverseContext); |
|
1228 } |
|
1229 |
|
1230 function mapSingleChildIntoContext(bookKeeping, child, childKey) { |
|
1231 var result = bookKeeping.result, |
|
1232 keyPrefix = bookKeeping.keyPrefix, |
|
1233 func = bookKeeping.func, |
|
1234 context = bookKeeping.context; |
|
1235 var mappedChild = func.call(context, child, bookKeeping.count++); |
|
1236 |
|
1237 if (Array.isArray(mappedChild)) { |
|
1238 mapIntoWithKeyPrefixInternal(mappedChild, result, childKey, function (c) { |
|
1239 return c; |
|
1240 }); |
|
1241 } else if (mappedChild != null) { |
|
1242 if (isValidElement(mappedChild)) { |
|
1243 mappedChild = cloneAndReplaceKey(mappedChild, // Keep both the (mapped) and old keys if they differ, just as |
|
1244 // traverseAllChildren used to do for objects as children |
|
1245 keyPrefix + (mappedChild.key && (!child || child.key !== mappedChild.key) ? escapeUserProvidedKey(mappedChild.key) + '/' : '') + childKey); |
|
1246 } |
|
1247 |
|
1248 result.push(mappedChild); |
|
1249 } |
|
1250 } |
|
1251 |
|
1252 function mapIntoWithKeyPrefixInternal(children, array, prefix, func, context) { |
|
1253 var escapedPrefix = ''; |
|
1254 |
|
1255 if (prefix != null) { |
|
1256 escapedPrefix = escapeUserProvidedKey(prefix) + '/'; |
|
1257 } |
|
1258 |
|
1259 var traverseContext = getPooledTraverseContext(array, escapedPrefix, func, context); |
|
1260 traverseAllChildren(children, mapSingleChildIntoContext, traverseContext); |
|
1261 releaseTraverseContext(traverseContext); |
|
1262 } |
|
1263 /** |
|
1264 * Maps children that are typically specified as `props.children`. |
|
1265 * |
|
1266 * See https://reactjs.org/docs/react-api.html#reactchildrenmap |
|
1267 * |
|
1268 * The provided mapFunction(child, key, index) will be called for each |
|
1269 * leaf child. |
|
1270 * |
|
1271 * @param {?*} children Children tree container. |
|
1272 * @param {function(*, int)} func The map function. |
|
1273 * @param {*} context Context for mapFunction. |
|
1274 * @return {object} Object containing the ordered map of results. |
|
1275 */ |
|
1276 |
|
1277 |
|
1278 function mapChildren(children, func, context) { |
|
1279 if (children == null) { |
|
1280 return children; |
|
1281 } |
|
1282 |
|
1283 var result = []; |
|
1284 mapIntoWithKeyPrefixInternal(children, result, null, func, context); |
|
1285 return result; |
|
1286 } |
|
1287 /** |
|
1288 * Count the number of children that are typically specified as |
|
1289 * `props.children`. |
|
1290 * |
|
1291 * See https://reactjs.org/docs/react-api.html#reactchildrencount |
|
1292 * |
|
1293 * @param {?*} children Children tree container. |
|
1294 * @return {number} The number of children. |
|
1295 */ |
|
1296 |
|
1297 |
|
1298 function countChildren(children) { |
|
1299 return traverseAllChildren(children, function () { |
|
1300 return null; |
|
1301 }, null); |
|
1302 } |
1131 } |
1303 /** |
1132 /** |
1304 * Flatten a children object (typically specified as `props.children`) and |
1133 * Flatten a children object (typically specified as `props.children`) and |
1305 * return an array with appropriately re-keyed children. |
1134 * return an array with appropriately re-keyed children. |
1306 * |
1135 * |
1307 * See https://reactjs.org/docs/react-api.html#reactchildrentoarray |
1136 * See https://reactjs.org/docs/react-api.html#reactchildrentoarray |
1308 */ |
1137 */ |
1309 |
1138 |
1310 |
1139 |
1311 function toArray(children) { |
1140 function toArray(children) { |
1312 var result = []; |
1141 return mapChildren(children, function (child) { |
1313 mapIntoWithKeyPrefixInternal(children, result, null, function (child) { |
|
1314 return child; |
1142 return child; |
1315 }); |
1143 }) || []; |
1316 return result; |
|
1317 } |
1144 } |
1318 /** |
1145 /** |
1319 * Returns the first child in a collection of children and verifies that there |
1146 * Returns the first child in a collection of children and verifies that there |
1320 * is only one child in the collection. |
1147 * is only one child in the collection. |
1321 * |
1148 * |
1373 $$typeof: REACT_PROVIDER_TYPE, |
1200 $$typeof: REACT_PROVIDER_TYPE, |
1374 _context: context |
1201 _context: context |
1375 }; |
1202 }; |
1376 var hasWarnedAboutUsingNestedContextConsumers = false; |
1203 var hasWarnedAboutUsingNestedContextConsumers = false; |
1377 var hasWarnedAboutUsingConsumerProvider = false; |
1204 var hasWarnedAboutUsingConsumerProvider = false; |
1205 var hasWarnedAboutDisplayNameOnConsumer = false; |
|
1378 |
1206 |
1379 { |
1207 { |
1380 // A separate object, but proxies back to the original context object for |
1208 // A separate object, but proxies back to the original context object for |
1381 // backwards compatibility. It has a different $$typeof, so we can properly |
1209 // backwards compatibility. It has a different $$typeof, so we can properly |
1382 // warn for the incorrect usage of Context as a Consumer. |
1210 // warn for the incorrect usage of Context as a Consumer. |
1433 error('Rendering <Context.Consumer.Consumer> is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Consumer> instead?'); |
1261 error('Rendering <Context.Consumer.Consumer> is not supported and will be removed in ' + 'a future major release. Did you mean to render <Context.Consumer> instead?'); |
1434 } |
1262 } |
1435 |
1263 |
1436 return context.Consumer; |
1264 return context.Consumer; |
1437 } |
1265 } |
1266 }, |
|
1267 displayName: { |
|
1268 get: function () { |
|
1269 return context.displayName; |
|
1270 }, |
|
1271 set: function (displayName) { |
|
1272 if (!hasWarnedAboutDisplayNameOnConsumer) { |
|
1273 warn('Setting `displayName` on Context.Consumer has no effect. ' + "You should set it directly on the context with Context.displayName = '%s'.", displayName); |
|
1274 |
|
1275 hasWarnedAboutDisplayNameOnConsumer = true; |
|
1276 } |
|
1277 } |
|
1438 } |
1278 } |
1439 }); // $FlowFixMe: Flow complains about missing properties because it doesn't understand defineProperty |
1279 }); // $FlowFixMe: Flow complains about missing properties because it doesn't understand defineProperty |
1440 |
1280 |
1441 context.Consumer = Consumer; |
1281 context.Consumer = Consumer; |
1442 } |
1282 } |
1447 } |
1287 } |
1448 |
1288 |
1449 return context; |
1289 return context; |
1450 } |
1290 } |
1451 |
1291 |
1292 var Uninitialized = -1; |
|
1293 var Pending = 0; |
|
1294 var Resolved = 1; |
|
1295 var Rejected = 2; |
|
1296 |
|
1297 function lazyInitializer(payload) { |
|
1298 if (payload._status === Uninitialized) { |
|
1299 var ctor = payload._result; |
|
1300 var thenable = ctor(); // Transition to the next state. |
|
1301 |
|
1302 var pending = payload; |
|
1303 pending._status = Pending; |
|
1304 pending._result = thenable; |
|
1305 thenable.then(function (moduleObject) { |
|
1306 if (payload._status === Pending) { |
|
1307 var defaultExport = moduleObject.default; |
|
1308 |
|
1309 { |
|
1310 if (defaultExport === undefined) { |
|
1311 error('lazy: Expected the result of a dynamic import() call. ' + 'Instead received: %s\n\nYour code should look like: \n ' + // Break up imports to avoid accidentally parsing them as dependencies. |
|
1312 'const MyComponent = lazy(() => imp' + "ort('./MyComponent'))", moduleObject); |
|
1313 } |
|
1314 } // Transition to the next state. |
|
1315 |
|
1316 |
|
1317 var resolved = payload; |
|
1318 resolved._status = Resolved; |
|
1319 resolved._result = defaultExport; |
|
1320 } |
|
1321 }, function (error) { |
|
1322 if (payload._status === Pending) { |
|
1323 // Transition to the next state. |
|
1324 var rejected = payload; |
|
1325 rejected._status = Rejected; |
|
1326 rejected._result = error; |
|
1327 } |
|
1328 }); |
|
1329 } |
|
1330 |
|
1331 if (payload._status === Resolved) { |
|
1332 return payload._result; |
|
1333 } else { |
|
1334 throw payload._result; |
|
1335 } |
|
1336 } |
|
1337 |
|
1452 function lazy(ctor) { |
1338 function lazy(ctor) { |
1339 var payload = { |
|
1340 // We use these fields to store the result. |
|
1341 _status: -1, |
|
1342 _result: ctor |
|
1343 }; |
|
1453 var lazyType = { |
1344 var lazyType = { |
1454 $$typeof: REACT_LAZY_TYPE, |
1345 $$typeof: REACT_LAZY_TYPE, |
1455 _ctor: ctor, |
1346 _payload: payload, |
1456 // React uses these fields to store the result. |
1347 _init: lazyInitializer |
1457 _status: -1, |
|
1458 _result: null |
|
1459 }; |
1348 }; |
1460 |
1349 |
1461 { |
1350 { |
1462 // In production, this would just set it on the object. |
1351 // In production, this would just set it on the object. |
1463 var defaultProps; |
1352 var defaultProps; |
1464 var propTypes; |
1353 var propTypes; // $FlowFixMe |
1354 |
|
1465 Object.defineProperties(lazyType, { |
1355 Object.defineProperties(lazyType, { |
1466 defaultProps: { |
1356 defaultProps: { |
1467 configurable: true, |
1357 configurable: true, |
1468 get: function () { |
1358 get: function () { |
1469 return defaultProps; |
1359 return defaultProps; |
1470 }, |
1360 }, |
1471 set: function (newDefaultProps) { |
1361 set: function (newDefaultProps) { |
1472 error('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.'); |
1362 error('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.'); |
1473 |
1363 |
1474 defaultProps = newDefaultProps; // Match production behavior more closely: |
1364 defaultProps = newDefaultProps; // Match production behavior more closely: |
1365 // $FlowFixMe |
|
1475 |
1366 |
1476 Object.defineProperty(lazyType, 'defaultProps', { |
1367 Object.defineProperty(lazyType, 'defaultProps', { |
1477 enumerable: true |
1368 enumerable: true |
1478 }); |
1369 }); |
1479 } |
1370 } |
1485 }, |
1376 }, |
1486 set: function (newPropTypes) { |
1377 set: function (newPropTypes) { |
1487 error('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.'); |
1378 error('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.'); |
1488 |
1379 |
1489 propTypes = newPropTypes; // Match production behavior more closely: |
1380 propTypes = newPropTypes; // Match production behavior more closely: |
1381 // $FlowFixMe |
|
1490 |
1382 |
1491 Object.defineProperty(lazyType, 'propTypes', { |
1383 Object.defineProperty(lazyType, 'propTypes', { |
1492 enumerable: true |
1384 enumerable: true |
1493 }); |
1385 }); |
1494 } |
1386 } |
1516 error('forwardRef render functions do not support propTypes or defaultProps. ' + 'Did you accidentally pass a React component?'); |
1408 error('forwardRef render functions do not support propTypes or defaultProps. ' + 'Did you accidentally pass a React component?'); |
1517 } |
1409 } |
1518 } |
1410 } |
1519 } |
1411 } |
1520 |
1412 |
1521 return { |
1413 var elementType = { |
1522 $$typeof: REACT_FORWARD_REF_TYPE, |
1414 $$typeof: REACT_FORWARD_REF_TYPE, |
1523 render: render |
1415 render: render |
1524 }; |
1416 }; |
1525 } |
1417 |
1418 { |
|
1419 var ownName; |
|
1420 Object.defineProperty(elementType, 'displayName', { |
|
1421 enumerable: false, |
|
1422 configurable: true, |
|
1423 get: function () { |
|
1424 return ownName; |
|
1425 }, |
|
1426 set: function (name) { |
|
1427 ownName = name; |
|
1428 |
|
1429 if (render.displayName == null) { |
|
1430 render.displayName = name; |
|
1431 } |
|
1432 } |
|
1433 }); |
|
1434 } |
|
1435 |
|
1436 return elementType; |
|
1437 } |
|
1438 |
|
1439 // Filter certain DOM attributes (e.g. src, href) if their values are empty strings. |
|
1440 |
|
1441 var enableScopeAPI = false; // Experimental Create Event Handle API. |
|
1526 |
1442 |
1527 function isValidElementType(type) { |
1443 function isValidElementType(type) { |
1528 return typeof type === 'string' || typeof type === 'function' || // Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill. |
1444 if (typeof type === 'string' || typeof type === 'function') { |
1529 type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || type === REACT_SUSPENSE_LIST_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_FUNDAMENTAL_TYPE || type.$$typeof === REACT_RESPONDER_TYPE || type.$$typeof === REACT_SCOPE_TYPE || type.$$typeof === REACT_BLOCK_TYPE); |
1445 return true; |
1446 } // Note: typeof might be other than 'symbol' or 'number' (e.g. if it's a polyfill). |
|
1447 |
|
1448 |
|
1449 if (type === exports.Fragment || type === exports.Profiler || type === REACT_DEBUG_TRACING_MODE_TYPE || type === exports.StrictMode || type === exports.Suspense || type === REACT_SUSPENSE_LIST_TYPE || type === REACT_LEGACY_HIDDEN_TYPE || enableScopeAPI ) { |
|
1450 return true; |
|
1451 } |
|
1452 |
|
1453 if (typeof type === 'object' && type !== null) { |
|
1454 if (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE || type.$$typeof === REACT_FUNDAMENTAL_TYPE || type.$$typeof === REACT_BLOCK_TYPE || type[0] === REACT_SERVER_BLOCK_TYPE) { |
|
1455 return true; |
|
1456 } |
|
1457 } |
|
1458 |
|
1459 return false; |
|
1530 } |
1460 } |
1531 |
1461 |
1532 function memo(type, compare) { |
1462 function memo(type, compare) { |
1533 { |
1463 { |
1534 if (!isValidElementType(type)) { |
1464 if (!isValidElementType(type)) { |
1535 error('memo: The first argument must be a component. Instead ' + 'received: %s', type === null ? 'null' : typeof type); |
1465 error('memo: The first argument must be a component. Instead ' + 'received: %s', type === null ? 'null' : typeof type); |
1536 } |
1466 } |
1537 } |
1467 } |
1538 |
1468 |
1539 return { |
1469 var elementType = { |
1540 $$typeof: REACT_MEMO_TYPE, |
1470 $$typeof: REACT_MEMO_TYPE, |
1541 type: type, |
1471 type: type, |
1542 compare: compare === undefined ? null : compare |
1472 compare: compare === undefined ? null : compare |
1543 }; |
1473 }; |
1474 |
|
1475 { |
|
1476 var ownName; |
|
1477 Object.defineProperty(elementType, 'displayName', { |
|
1478 enumerable: false, |
|
1479 configurable: true, |
|
1480 get: function () { |
|
1481 return ownName; |
|
1482 }, |
|
1483 set: function (name) { |
|
1484 ownName = name; |
|
1485 |
|
1486 if (type.displayName == null) { |
|
1487 type.displayName = name; |
|
1488 } |
|
1489 } |
|
1490 }); |
|
1491 } |
|
1492 |
|
1493 return elementType; |
|
1544 } |
1494 } |
1545 |
1495 |
1546 function resolveDispatcher() { |
1496 function resolveDispatcher() { |
1547 var dispatcher = ReactCurrentDispatcher.current; |
1497 var dispatcher = ReactCurrentDispatcher.current; |
1548 |
1498 |
1549 if (!(dispatcher !== null)) { |
1499 if (!(dispatcher !== null)) { |
1550 { |
1500 { |
1551 throw Error( "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." ); |
1501 throw Error( "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://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem." ); |
1552 } |
1502 } |
1553 } |
1503 } |
1554 |
1504 |
1555 return dispatcher; |
1505 return dispatcher; |
1556 } |
1506 } |
1558 function useContext(Context, unstable_observedBits) { |
1508 function useContext(Context, unstable_observedBits) { |
1559 var dispatcher = resolveDispatcher(); |
1509 var dispatcher = resolveDispatcher(); |
1560 |
1510 |
1561 { |
1511 { |
1562 if (unstable_observedBits !== undefined) { |
1512 if (unstable_observedBits !== undefined) { |
1563 error('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' : ''); |
1513 error('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://reactjs.org/link/rules-of-hooks' : ''); |
1564 } // TODO: add a more generic warning for invalid values. |
1514 } // TODO: add a more generic warning for invalid values. |
1565 |
1515 |
1566 |
1516 |
1567 if (Context._context !== undefined) { |
1517 if (Context._context !== undefined) { |
1568 var realContext = Context._context; // Don't deduplicate because this legitimately causes bugs |
1518 var realContext = Context._context; // Don't deduplicate because this legitimately causes bugs |
1615 var dispatcher = resolveDispatcher(); |
1565 var dispatcher = resolveDispatcher(); |
1616 return dispatcher.useDebugValue(value, formatterFn); |
1566 return dispatcher.useDebugValue(value, formatterFn); |
1617 } |
1567 } |
1618 } |
1568 } |
1619 |
1569 |
1620 /** |
1570 // Helpers to patch console.logs to avoid logging during side-effect free |
1621 * Copyright (c) 2013-present, Facebook, Inc. |
1571 // replaying on render function. This currently only patches the object |
1622 * |
1572 // lazily which won't cover if the log function was extracted eagerly. |
1623 * This source code is licensed under the MIT license found in the |
1573 // We could also eagerly patch the method. |
1624 * LICENSE file in the root directory of this source tree. |
1574 var disabledDepth = 0; |
1625 */ |
1575 var prevLog; |
1626 |
1576 var prevInfo; |
1627 var ReactPropTypesSecret = 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'; |
1577 var prevWarn; |
1628 |
1578 var prevError; |
1629 var ReactPropTypesSecret_1 = ReactPropTypesSecret; |
1579 var prevGroup; |
1630 |
1580 var prevGroupCollapsed; |
1631 var printWarning$1 = function() {}; |
1581 var prevGroupEnd; |
1582 |
|
1583 function disabledLog() {} |
|
1584 |
|
1585 disabledLog.__reactDisabledLog = true; |
|
1586 function disableLogs() { |
|
1587 { |
|
1588 if (disabledDepth === 0) { |
|
1589 /* eslint-disable react-internal/no-production-logging */ |
|
1590 prevLog = console.log; |
|
1591 prevInfo = console.info; |
|
1592 prevWarn = console.warn; |
|
1593 prevError = console.error; |
|
1594 prevGroup = console.group; |
|
1595 prevGroupCollapsed = console.groupCollapsed; |
|
1596 prevGroupEnd = console.groupEnd; // https://github.com/facebook/react/issues/19099 |
|
1597 |
|
1598 var props = { |
|
1599 configurable: true, |
|
1600 enumerable: true, |
|
1601 value: disabledLog, |
|
1602 writable: true |
|
1603 }; // $FlowFixMe Flow thinks console is immutable. |
|
1604 |
|
1605 Object.defineProperties(console, { |
|
1606 info: props, |
|
1607 log: props, |
|
1608 warn: props, |
|
1609 error: props, |
|
1610 group: props, |
|
1611 groupCollapsed: props, |
|
1612 groupEnd: props |
|
1613 }); |
|
1614 /* eslint-enable react-internal/no-production-logging */ |
|
1615 } |
|
1616 |
|
1617 disabledDepth++; |
|
1618 } |
|
1619 } |
|
1620 function reenableLogs() { |
|
1621 { |
|
1622 disabledDepth--; |
|
1623 |
|
1624 if (disabledDepth === 0) { |
|
1625 /* eslint-disable react-internal/no-production-logging */ |
|
1626 var props = { |
|
1627 configurable: true, |
|
1628 enumerable: true, |
|
1629 writable: true |
|
1630 }; // $FlowFixMe Flow thinks console is immutable. |
|
1631 |
|
1632 Object.defineProperties(console, { |
|
1633 log: assign({}, props, { |
|
1634 value: prevLog |
|
1635 }), |
|
1636 info: assign({}, props, { |
|
1637 value: prevInfo |
|
1638 }), |
|
1639 warn: assign({}, props, { |
|
1640 value: prevWarn |
|
1641 }), |
|
1642 error: assign({}, props, { |
|
1643 value: prevError |
|
1644 }), |
|
1645 group: assign({}, props, { |
|
1646 value: prevGroup |
|
1647 }), |
|
1648 groupCollapsed: assign({}, props, { |
|
1649 value: prevGroupCollapsed |
|
1650 }), |
|
1651 groupEnd: assign({}, props, { |
|
1652 value: prevGroupEnd |
|
1653 }) |
|
1654 }); |
|
1655 /* eslint-enable react-internal/no-production-logging */ |
|
1656 } |
|
1657 |
|
1658 if (disabledDepth < 0) { |
|
1659 error('disabledDepth fell below zero. ' + 'This is a bug in React. Please file an issue.'); |
|
1660 } |
|
1661 } |
|
1662 } |
|
1663 |
|
1664 var ReactCurrentDispatcher$1 = ReactSharedInternals.ReactCurrentDispatcher; |
|
1665 var prefix; |
|
1666 function describeBuiltInComponentFrame(name, source, ownerFn) { |
|
1667 { |
|
1668 if (prefix === undefined) { |
|
1669 // Extract the VM specific prefix used by each line. |
|
1670 try { |
|
1671 throw Error(); |
|
1672 } catch (x) { |
|
1673 var match = x.stack.trim().match(/\n( *(at )?)/); |
|
1674 prefix = match && match[1] || ''; |
|
1675 } |
|
1676 } // We use the prefix to ensure our stacks line up with native stack frames. |
|
1677 |
|
1678 |
|
1679 return '\n' + prefix + name; |
|
1680 } |
|
1681 } |
|
1682 var reentry = false; |
|
1683 var componentFrameCache; |
|
1632 |
1684 |
1633 { |
1685 { |
1634 var ReactPropTypesSecret$1 = ReactPropTypesSecret_1; |
1686 var PossiblyWeakMap = typeof WeakMap === 'function' ? WeakMap : Map; |
1635 var loggedTypeFailures = {}; |
1687 componentFrameCache = new PossiblyWeakMap(); |
1636 var has = Function.call.bind(Object.prototype.hasOwnProperty); |
1688 } |
1637 |
1689 |
1638 printWarning$1 = function(text) { |
1690 function describeNativeComponentFrame(fn, construct) { |
1639 var message = 'Warning: ' + text; |
1691 // If something asked for a stack inside a fake render, it should get ignored. |
1640 if (typeof console !== 'undefined') { |
1692 if (!fn || reentry) { |
1641 console.error(message); |
1693 return ''; |
1642 } |
1694 } |
1643 try { |
1695 |
1644 // --- Welcome to debugging React --- |
1696 { |
1645 // This error was thrown as a convenience so that you can use this stack |
1697 var frame = componentFrameCache.get(fn); |
1646 // to find the callsite that caused this warning to fire. |
1698 |
1647 throw new Error(message); |
1699 if (frame !== undefined) { |
1648 } catch (x) {} |
1700 return frame; |
1649 }; |
1701 } |
1650 } |
1702 } |
1651 |
1703 |
1652 /** |
1704 var control; |
1653 * Assert that the values match with the type specs. |
1705 reentry = true; |
1654 * Error messages are memorized and will only be shown once. |
1706 var previousPrepareStackTrace = Error.prepareStackTrace; // $FlowFixMe It does accept undefined. |
1655 * |
1707 |
1656 * @param {object} typeSpecs Map of name to a ReactPropType |
1708 Error.prepareStackTrace = undefined; |
1657 * @param {object} values Runtime values that need to be type-checked |
1709 var previousDispatcher; |
1658 * @param {string} location e.g. "prop", "context", "child context" |
1710 |
1659 * @param {string} componentName Name of the component for error messages. |
1711 { |
1660 * @param {?Function} getStack Returns the component stack. |
1712 previousDispatcher = ReactCurrentDispatcher$1.current; // Set the dispatcher in DEV because this might be call in the render function |
1661 * @private |
1713 // for warnings. |
1662 */ |
1714 |
1663 function checkPropTypes(typeSpecs, values, location, componentName, getStack) { |
1715 ReactCurrentDispatcher$1.current = null; |
1664 { |
1716 disableLogs(); |
1717 } |
|
1718 |
|
1719 try { |
|
1720 // This should throw. |
|
1721 if (construct) { |
|
1722 // Something should be setting the props in the constructor. |
|
1723 var Fake = function () { |
|
1724 throw Error(); |
|
1725 }; // $FlowFixMe |
|
1726 |
|
1727 |
|
1728 Object.defineProperty(Fake.prototype, 'props', { |
|
1729 set: function () { |
|
1730 // We use a throwing setter instead of frozen or non-writable props |
|
1731 // because that won't throw in a non-strict mode function. |
|
1732 throw Error(); |
|
1733 } |
|
1734 }); |
|
1735 |
|
1736 if (typeof Reflect === 'object' && Reflect.construct) { |
|
1737 // We construct a different control for this case to include any extra |
|
1738 // frames added by the construct call. |
|
1739 try { |
|
1740 Reflect.construct(Fake, []); |
|
1741 } catch (x) { |
|
1742 control = x; |
|
1743 } |
|
1744 |
|
1745 Reflect.construct(fn, [], Fake); |
|
1746 } else { |
|
1747 try { |
|
1748 Fake.call(); |
|
1749 } catch (x) { |
|
1750 control = x; |
|
1751 } |
|
1752 |
|
1753 fn.call(Fake.prototype); |
|
1754 } |
|
1755 } else { |
|
1756 try { |
|
1757 throw Error(); |
|
1758 } catch (x) { |
|
1759 control = x; |
|
1760 } |
|
1761 |
|
1762 fn(); |
|
1763 } |
|
1764 } catch (sample) { |
|
1765 // This is inlined manually because closure doesn't do it for us. |
|
1766 if (sample && control && typeof sample.stack === 'string') { |
|
1767 // This extracts the first frame from the sample that isn't also in the control. |
|
1768 // Skipping one frame that we assume is the frame that calls the two. |
|
1769 var sampleLines = sample.stack.split('\n'); |
|
1770 var controlLines = control.stack.split('\n'); |
|
1771 var s = sampleLines.length - 1; |
|
1772 var c = controlLines.length - 1; |
|
1773 |
|
1774 while (s >= 1 && c >= 0 && sampleLines[s] !== controlLines[c]) { |
|
1775 // We expect at least one stack frame to be shared. |
|
1776 // Typically this will be the root most one. However, stack frames may be |
|
1777 // cut off due to maximum stack limits. In this case, one maybe cut off |
|
1778 // earlier than the other. We assume that the sample is longer or the same |
|
1779 // and there for cut off earlier. So we should find the root most frame in |
|
1780 // the sample somewhere in the control. |
|
1781 c--; |
|
1782 } |
|
1783 |
|
1784 for (; s >= 1 && c >= 0; s--, c--) { |
|
1785 // Next we find the first one that isn't the same which should be the |
|
1786 // frame that called our sample function and the control. |
|
1787 if (sampleLines[s] !== controlLines[c]) { |
|
1788 // In V8, the first line is describing the message but other VMs don't. |
|
1789 // If we're about to return the first line, and the control is also on the same |
|
1790 // line, that's a pretty good indicator that our sample threw at same line as |
|
1791 // the control. I.e. before we entered the sample frame. So we ignore this result. |
|
1792 // This can happen if you passed a class to function component, or non-function. |
|
1793 if (s !== 1 || c !== 1) { |
|
1794 do { |
|
1795 s--; |
|
1796 c--; // We may still have similar intermediate frames from the construct call. |
|
1797 // The next one that isn't the same should be our match though. |
|
1798 |
|
1799 if (c < 0 || sampleLines[s] !== controlLines[c]) { |
|
1800 // V8 adds a "new" prefix for native classes. Let's remove it to make it prettier. |
|
1801 var _frame = '\n' + sampleLines[s].replace(' at new ', ' at '); |
|
1802 |
|
1803 { |
|
1804 if (typeof fn === 'function') { |
|
1805 componentFrameCache.set(fn, _frame); |
|
1806 } |
|
1807 } // Return the line we found. |
|
1808 |
|
1809 |
|
1810 return _frame; |
|
1811 } |
|
1812 } while (s >= 1 && c >= 0); |
|
1813 } |
|
1814 |
|
1815 break; |
|
1816 } |
|
1817 } |
|
1818 } |
|
1819 } finally { |
|
1820 reentry = false; |
|
1821 |
|
1822 { |
|
1823 ReactCurrentDispatcher$1.current = previousDispatcher; |
|
1824 reenableLogs(); |
|
1825 } |
|
1826 |
|
1827 Error.prepareStackTrace = previousPrepareStackTrace; |
|
1828 } // Fallback to just using the name if we couldn't make it throw. |
|
1829 |
|
1830 |
|
1831 var name = fn ? fn.displayName || fn.name : ''; |
|
1832 var syntheticFrame = name ? describeBuiltInComponentFrame(name) : ''; |
|
1833 |
|
1834 { |
|
1835 if (typeof fn === 'function') { |
|
1836 componentFrameCache.set(fn, syntheticFrame); |
|
1837 } |
|
1838 } |
|
1839 |
|
1840 return syntheticFrame; |
|
1841 } |
|
1842 function describeFunctionComponentFrame(fn, source, ownerFn) { |
|
1843 { |
|
1844 return describeNativeComponentFrame(fn, false); |
|
1845 } |
|
1846 } |
|
1847 |
|
1848 function shouldConstruct(Component) { |
|
1849 var prototype = Component.prototype; |
|
1850 return !!(prototype && prototype.isReactComponent); |
|
1851 } |
|
1852 |
|
1853 function describeUnknownElementTypeFrameInDEV(type, source, ownerFn) { |
|
1854 |
|
1855 if (type == null) { |
|
1856 return ''; |
|
1857 } |
|
1858 |
|
1859 if (typeof type === 'function') { |
|
1860 { |
|
1861 return describeNativeComponentFrame(type, shouldConstruct(type)); |
|
1862 } |
|
1863 } |
|
1864 |
|
1865 if (typeof type === 'string') { |
|
1866 return describeBuiltInComponentFrame(type); |
|
1867 } |
|
1868 |
|
1869 switch (type) { |
|
1870 case exports.Suspense: |
|
1871 return describeBuiltInComponentFrame('Suspense'); |
|
1872 |
|
1873 case REACT_SUSPENSE_LIST_TYPE: |
|
1874 return describeBuiltInComponentFrame('SuspenseList'); |
|
1875 } |
|
1876 |
|
1877 if (typeof type === 'object') { |
|
1878 switch (type.$$typeof) { |
|
1879 case REACT_FORWARD_REF_TYPE: |
|
1880 return describeFunctionComponentFrame(type.render); |
|
1881 |
|
1882 case REACT_MEMO_TYPE: |
|
1883 // Memo may contain any component type so we recursively resolve it. |
|
1884 return describeUnknownElementTypeFrameInDEV(type.type, source, ownerFn); |
|
1885 |
|
1886 case REACT_BLOCK_TYPE: |
|
1887 return describeFunctionComponentFrame(type._render); |
|
1888 |
|
1889 case REACT_LAZY_TYPE: |
|
1890 { |
|
1891 var lazyComponent = type; |
|
1892 var payload = lazyComponent._payload; |
|
1893 var init = lazyComponent._init; |
|
1894 |
|
1895 try { |
|
1896 // Lazy may contain any component type so we recursively resolve it. |
|
1897 return describeUnknownElementTypeFrameInDEV(init(payload), source, ownerFn); |
|
1898 } catch (x) {} |
|
1899 } |
|
1900 } |
|
1901 } |
|
1902 |
|
1903 return ''; |
|
1904 } |
|
1905 |
|
1906 var loggedTypeFailures = {}; |
|
1907 var ReactDebugCurrentFrame$1 = ReactSharedInternals.ReactDebugCurrentFrame; |
|
1908 |
|
1909 function setCurrentlyValidatingElement(element) { |
|
1910 { |
|
1911 if (element) { |
|
1912 var owner = element._owner; |
|
1913 var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null); |
|
1914 ReactDebugCurrentFrame$1.setExtraStackFrame(stack); |
|
1915 } else { |
|
1916 ReactDebugCurrentFrame$1.setExtraStackFrame(null); |
|
1917 } |
|
1918 } |
|
1919 } |
|
1920 |
|
1921 function checkPropTypes(typeSpecs, values, location, componentName, element) { |
|
1922 { |
|
1923 // $FlowFixMe This is okay but Flow doesn't know it. |
|
1924 var has = Function.call.bind(Object.prototype.hasOwnProperty); |
|
1925 |
|
1665 for (var typeSpecName in typeSpecs) { |
1926 for (var typeSpecName in typeSpecs) { |
1666 if (has(typeSpecs, typeSpecName)) { |
1927 if (has(typeSpecs, typeSpecName)) { |
1667 var error; |
1928 var error$1 = void 0; // Prop type validation may throw. In case they do, we don't want to |
1668 // Prop type validation may throw. In case they do, we don't want to |
|
1669 // fail the render phase where it didn't fail before. So we log it. |
1929 // fail the render phase where it didn't fail before. So we log it. |
1670 // After these have been cleaned up, we'll let them throw. |
1930 // After these have been cleaned up, we'll let them throw. |
1931 |
|
1671 try { |
1932 try { |
1672 // This is intentionally an invariant that gets caught. It's the same |
1933 // This is intentionally an invariant that gets caught. It's the same |
1673 // behavior as without this statement except with a better message. |
1934 // behavior as without this statement except with a better message. |
1674 if (typeof typeSpecs[typeSpecName] !== 'function') { |
1935 if (typeof typeSpecs[typeSpecName] !== 'function') { |
1675 var err = Error( |
1936 var err = Error((componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' + 'This often happens because of typos such as `PropTypes.function` instead of `PropTypes.func`.'); |
1676 (componentName || 'React class') + ': ' + location + ' type `' + typeSpecName + '` is invalid; ' + |
|
1677 'it must be a function, usually from the `prop-types` package, but received `' + typeof typeSpecs[typeSpecName] + '`.' |
|
1678 ); |
|
1679 err.name = 'Invariant Violation'; |
1937 err.name = 'Invariant Violation'; |
1680 throw err; |
1938 throw err; |
1681 } |
1939 } |
1682 error = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, ReactPropTypesSecret$1); |
1940 |
1941 error$1 = typeSpecs[typeSpecName](values, typeSpecName, componentName, location, null, 'SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED'); |
|
1683 } catch (ex) { |
1942 } catch (ex) { |
1684 error = ex; |
1943 error$1 = ex; |
1685 } |
1944 } |
1686 if (error && !(error instanceof Error)) { |
1945 |
1687 printWarning$1( |
1946 if (error$1 && !(error$1 instanceof Error)) { |
1688 (componentName || 'React class') + ': type specification of ' + |
1947 setCurrentlyValidatingElement(element); |
1689 location + ' `' + typeSpecName + '` is invalid; the type checker ' + |
1948 |
1690 'function must return `null` or an `Error` but returned a ' + typeof error + '. ' + |
1949 error('%s: type specification of %s' + ' `%s` is invalid; the type checker ' + 'function must return `null` or an `Error` but returned a %s. ' + 'You may have forgotten to pass an argument to the type checker ' + 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + 'shape all require an argument).', componentName || 'React class', location, typeSpecName, typeof error$1); |
1691 'You may have forgotten to pass an argument to the type checker ' + |
1950 |
1692 'creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and ' + |
1951 setCurrentlyValidatingElement(null); |
1693 'shape all require an argument).' |
|
1694 ); |
|
1695 } |
1952 } |
1696 if (error instanceof Error && !(error.message in loggedTypeFailures)) { |
1953 |
1954 if (error$1 instanceof Error && !(error$1.message in loggedTypeFailures)) { |
|
1697 // Only monitor this failure once because there tends to be a lot of the |
1955 // Only monitor this failure once because there tends to be a lot of the |
1698 // same error. |
1956 // same error. |
1699 loggedTypeFailures[error.message] = true; |
1957 loggedTypeFailures[error$1.message] = true; |
1700 |
1958 setCurrentlyValidatingElement(element); |
1701 var stack = getStack ? getStack() : ''; |
1959 |
1702 |
1960 error('Failed %s type: %s', location, error$1.message); |
1703 printWarning$1( |
1961 |
1704 'Failed ' + location + ' type: ' + error.message + (stack != null ? stack : '') |
1962 setCurrentlyValidatingElement(null); |
1705 ); |
|
1706 } |
1963 } |
1707 } |
1964 } |
1708 } |
1965 } |
1709 } |
1966 } |
1710 } |
1967 } |
1711 |
1968 |
1712 /** |
1969 function setCurrentlyValidatingElement$1(element) { |
1713 * Resets warning cache when testing. |
1970 { |
1714 * |
1971 if (element) { |
1715 * @private |
1972 var owner = element._owner; |
1716 */ |
1973 var stack = describeUnknownElementTypeFrameInDEV(element.type, element._source, owner ? owner.type : null); |
1717 checkPropTypes.resetWarningCache = function() { |
1974 setExtraStackFrame(stack); |
1718 { |
1975 } else { |
1719 loggedTypeFailures = {}; |
1976 setExtraStackFrame(null); |
1720 } |
1977 } |
1721 }; |
1978 } |
1722 |
1979 } |
1723 var checkPropTypes_1 = checkPropTypes; |
|
1724 |
1980 |
1725 var propTypesMisspellWarningShown; |
1981 var propTypesMisspellWarningShown; |
1726 |
1982 |
1727 { |
1983 { |
1728 propTypesMisspellWarningShown = false; |
1984 propTypesMisspellWarningShown = false; |
1813 if (element && element._owner && element._owner !== ReactCurrentOwner.current) { |
2069 if (element && element._owner && element._owner !== ReactCurrentOwner.current) { |
1814 // Give the component that originally created this child. |
2070 // Give the component that originally created this child. |
1815 childOwner = " It was passed a child from " + getComponentName(element._owner.type) + "."; |
2071 childOwner = " It was passed a child from " + getComponentName(element._owner.type) + "."; |
1816 } |
2072 } |
1817 |
2073 |
1818 setCurrentlyValidatingElement(element); |
2074 { |
1819 |
2075 setCurrentlyValidatingElement$1(element); |
1820 { |
2076 |
1821 error('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); |
2077 error('Each child in a list should have a unique "key" prop.' + '%s%s See https://reactjs.org/link/warning-keys for more information.', currentComponentErrorInfo, childOwner); |
1822 } |
2078 |
1823 |
2079 setCurrentlyValidatingElement$1(null); |
1824 setCurrentlyValidatingElement(null); |
2080 } |
1825 } |
2081 } |
1826 /** |
2082 /** |
1827 * Ensure that every element either is passed in a static location, in an |
2083 * Ensure that every element either is passed in a static location, in an |
1828 * array with an explicit keys property defined, or in an object literal |
2084 * array with an explicit keys property defined, or in an object literal |
1829 * with valid key property. |
2085 * with valid key property. |
1885 |
2141 |
1886 if (type === null || type === undefined || typeof type === 'string') { |
2142 if (type === null || type === undefined || typeof type === 'string') { |
1887 return; |
2143 return; |
1888 } |
2144 } |
1889 |
2145 |
1890 var name = getComponentName(type); |
|
1891 var propTypes; |
2146 var propTypes; |
1892 |
2147 |
1893 if (typeof type === 'function') { |
2148 if (typeof type === 'function') { |
1894 propTypes = type.propTypes; |
2149 propTypes = type.propTypes; |
1895 } else if (typeof type === 'object' && (type.$$typeof === REACT_FORWARD_REF_TYPE || // Note: Memo only checks outer props here. |
2150 } else if (typeof type === 'object' && (type.$$typeof === REACT_FORWARD_REF_TYPE || // Note: Memo only checks outer props here. |
1899 } else { |
2154 } else { |
1900 return; |
2155 return; |
1901 } |
2156 } |
1902 |
2157 |
1903 if (propTypes) { |
2158 if (propTypes) { |
1904 setCurrentlyValidatingElement(element); |
2159 // Intentionally inside to avoid triggering lazy initializers: |
1905 checkPropTypes_1(propTypes, element.props, 'prop', name, ReactDebugCurrentFrame.getStackAddendum); |
2160 var name = getComponentName(type); |
1906 setCurrentlyValidatingElement(null); |
2161 checkPropTypes(propTypes, element.props, 'prop', name, element); |
1907 } else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) { |
2162 } else if (type.PropTypes !== undefined && !propTypesMisspellWarningShown) { |
1908 propTypesMisspellWarningShown = true; |
2163 propTypesMisspellWarningShown = true; // Intentionally inside to avoid triggering lazy initializers: |
1909 |
2164 |
1910 error('Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', name || 'Unknown'); |
2165 var _name = getComponentName(type); |
2166 |
|
2167 error('Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?', _name || 'Unknown'); |
|
1911 } |
2168 } |
1912 |
2169 |
1913 if (typeof type.getDefaultProps === 'function' && !type.getDefaultProps.isReactClassApproved) { |
2170 if (typeof type.getDefaultProps === 'function' && !type.getDefaultProps.isReactClassApproved) { |
1914 error('getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.'); |
2171 error('getDefaultProps is only used on classic React.createClass ' + 'definitions. Use a static property named `defaultProps` instead.'); |
1915 } |
2172 } |
1921 */ |
2178 */ |
1922 |
2179 |
1923 |
2180 |
1924 function validateFragmentProps(fragment) { |
2181 function validateFragmentProps(fragment) { |
1925 { |
2182 { |
1926 setCurrentlyValidatingElement(fragment); |
|
1927 var keys = Object.keys(fragment.props); |
2183 var keys = Object.keys(fragment.props); |
1928 |
2184 |
1929 for (var i = 0; i < keys.length; i++) { |
2185 for (var i = 0; i < keys.length; i++) { |
1930 var key = keys[i]; |
2186 var key = keys[i]; |
1931 |
2187 |
1932 if (key !== 'children' && key !== 'key') { |
2188 if (key !== 'children' && key !== 'key') { |
2189 setCurrentlyValidatingElement$1(fragment); |
|
2190 |
|
1933 error('Invalid prop `%s` supplied to `React.Fragment`. ' + 'React.Fragment can only have `key` and `children` props.', key); |
2191 error('Invalid prop `%s` supplied to `React.Fragment`. ' + 'React.Fragment can only have `key` and `children` props.', key); |
1934 |
2192 |
2193 setCurrentlyValidatingElement$1(null); |
|
1935 break; |
2194 break; |
1936 } |
2195 } |
1937 } |
2196 } |
1938 |
2197 |
1939 if (fragment.ref !== null) { |
2198 if (fragment.ref !== null) { |
2199 setCurrentlyValidatingElement$1(fragment); |
|
2200 |
|
1940 error('Invalid attribute `ref` supplied to `React.Fragment`.'); |
2201 error('Invalid attribute `ref` supplied to `React.Fragment`.'); |
1941 } |
2202 |
1942 |
2203 setCurrentlyValidatingElement$1(null); |
1943 setCurrentlyValidatingElement(null); |
2204 } |
1944 } |
2205 } |
1945 } |
2206 } |
1946 function createElementWithValidation(type, props, children) { |
2207 function createElementWithValidation(type, props, children) { |
1947 var validType = isValidElementType(type); // We warn in this case but don't throw. We expect the element creation to |
2208 var validType = isValidElementType(type); // We warn in this case but don't throw. We expect the element creation to |
1948 // succeed and there will likely be errors in render. |
2209 // succeed and there will likely be errors in render. |
1996 for (var i = 2; i < arguments.length; i++) { |
2257 for (var i = 2; i < arguments.length; i++) { |
1997 validateChildKeys(arguments[i], type); |
2258 validateChildKeys(arguments[i], type); |
1998 } |
2259 } |
1999 } |
2260 } |
2000 |
2261 |
2001 if (type === REACT_FRAGMENT_TYPE) { |
2262 if (type === exports.Fragment) { |
2002 validateFragmentProps(element); |
2263 validateFragmentProps(element); |
2003 } else { |
2264 } else { |
2004 validatePropTypes(element); |
2265 validatePropTypes(element); |
2005 } |
2266 } |
2006 |
2267 |
2044 validatePropTypes(newElement); |
2305 validatePropTypes(newElement); |
2045 return newElement; |
2306 return newElement; |
2046 } |
2307 } |
2047 |
2308 |
2048 var enableSchedulerDebugging = false; |
2309 var enableSchedulerDebugging = false; |
2049 var enableProfiling = true; |
2310 var enableProfiling = false; |
2050 |
2311 |
2051 var requestHostCallback; |
2312 var requestHostCallback; |
2052 var requestHostTimeout; |
2313 var requestHostTimeout; |
2053 var cancelHostTimeout; |
2314 var cancelHostTimeout; |
2054 var shouldYieldToHost; |
2315 var shouldYieldToHost; |
2055 var requestPaint; |
2316 var requestPaint; |
2056 var getCurrentTime; |
2317 var getCurrentTime; |
2057 var forceFrameRate; |
2318 var forceFrameRate; |
2319 var hasPerformanceNow = typeof performance === 'object' && typeof performance.now === 'function'; |
|
2320 |
|
2321 if (hasPerformanceNow) { |
|
2322 var localPerformance = performance; |
|
2323 |
|
2324 getCurrentTime = function () { |
|
2325 return localPerformance.now(); |
|
2326 }; |
|
2327 } else { |
|
2328 var localDate = Date; |
|
2329 var initialTime = localDate.now(); |
|
2330 |
|
2331 getCurrentTime = function () { |
|
2332 return localDate.now() - initialTime; |
|
2333 }; |
|
2334 } |
|
2058 |
2335 |
2059 if ( // If Scheduler runs in a non-DOM environment, it falls back to a naive |
2336 if ( // If Scheduler runs in a non-DOM environment, it falls back to a naive |
2060 // implementation using setTimeout. |
2337 // implementation using setTimeout. |
2061 typeof window === 'undefined' || // Check if MessageChannel is supported, too. |
2338 typeof window === 'undefined' || // Check if MessageChannel is supported, too. |
2062 typeof MessageChannel !== 'function') { |
2339 typeof MessageChannel !== 'function') { |
2079 throw e; |
2356 throw e; |
2080 } |
2357 } |
2081 } |
2358 } |
2082 }; |
2359 }; |
2083 |
2360 |
2084 var initialTime = Date.now(); |
|
2085 |
|
2086 getCurrentTime = function () { |
|
2087 return Date.now() - initialTime; |
|
2088 }; |
|
2089 |
|
2090 requestHostCallback = function (cb) { |
2361 requestHostCallback = function (cb) { |
2091 if (_callback !== null) { |
2362 if (_callback !== null) { |
2092 // Protect against re-entrancy. |
2363 // Protect against re-entrancy. |
2093 setTimeout(requestHostCallback, 0, cb); |
2364 setTimeout(requestHostCallback, 0, cb); |
2094 } else { |
2365 } else { |
2110 }; |
2381 }; |
2111 |
2382 |
2112 requestPaint = forceFrameRate = function () {}; |
2383 requestPaint = forceFrameRate = function () {}; |
2113 } else { |
2384 } else { |
2114 // Capture local references to native APIs, in case a polyfill overrides them. |
2385 // Capture local references to native APIs, in case a polyfill overrides them. |
2115 var performance = window.performance; |
|
2116 var _Date = window.Date; |
|
2117 var _setTimeout = window.setTimeout; |
2386 var _setTimeout = window.setTimeout; |
2118 var _clearTimeout = window.clearTimeout; |
2387 var _clearTimeout = window.clearTimeout; |
2119 |
2388 |
2120 if (typeof console !== 'undefined') { |
2389 if (typeof console !== 'undefined') { |
2121 // TODO: Scheduler no longer requires these methods to be polyfilled. But |
2390 // TODO: Scheduler no longer requires these methods to be polyfilled. But |
2122 // maybe we want to continue warning if they don't exist, to preserve the |
2391 // maybe we want to continue warning if they don't exist, to preserve the |
2123 // option to rely on it in the future? |
2392 // option to rely on it in the future? |
2124 var requestAnimationFrame = window.requestAnimationFrame; |
2393 var requestAnimationFrame = window.requestAnimationFrame; |
2125 var cancelAnimationFrame = window.cancelAnimationFrame; // TODO: Remove fb.me link |
2394 var cancelAnimationFrame = window.cancelAnimationFrame; |
2126 |
2395 |
2127 if (typeof requestAnimationFrame !== 'function') { |
2396 if (typeof requestAnimationFrame !== 'function') { |
2128 // Using console['error'] to evade Babel and ESLint |
2397 // Using console['error'] to evade Babel and ESLint |
2129 console['error']("This browser doesn't support requestAnimationFrame. " + 'Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills'); |
2398 console['error']("This browser doesn't support requestAnimationFrame. " + 'Make sure that you load a ' + 'polyfill in older browsers. https://reactjs.org/link/react-polyfills'); |
2130 } |
2399 } |
2131 |
2400 |
2132 if (typeof cancelAnimationFrame !== 'function') { |
2401 if (typeof cancelAnimationFrame !== 'function') { |
2133 // Using console['error'] to evade Babel and ESLint |
2402 // Using console['error'] to evade Babel and ESLint |
2134 console['error']("This browser doesn't support cancelAnimationFrame. " + 'Make sure that you load a ' + 'polyfill in older browsers. https://fb.me/react-polyfills'); |
2403 console['error']("This browser doesn't support cancelAnimationFrame. " + 'Make sure that you load a ' + 'polyfill in older browsers. https://reactjs.org/link/react-polyfills'); |
2135 } |
2404 } |
2136 } |
|
2137 |
|
2138 if (typeof performance === 'object' && typeof performance.now === 'function') { |
|
2139 getCurrentTime = function () { |
|
2140 return performance.now(); |
|
2141 }; |
|
2142 } else { |
|
2143 var _initialTime = _Date.now(); |
|
2144 |
|
2145 getCurrentTime = function () { |
|
2146 return _Date.now() - _initialTime; |
|
2147 }; |
|
2148 } |
2405 } |
2149 |
2406 |
2150 var isMessageLoopRunning = false; |
2407 var isMessageLoopRunning = false; |
2151 var scheduledHostCallback = null; |
2408 var scheduledHostCallback = null; |
2152 var taskTimeoutID = -1; // Scheduler periodically yields in case there is other work on the main |
2409 var taskTimeoutID = -1; // Scheduler periodically yields in case there is other work on the main |
2169 } |
2426 } |
2170 |
2427 |
2171 forceFrameRate = function (fps) { |
2428 forceFrameRate = function (fps) { |
2172 if (fps < 0 || fps > 125) { |
2429 if (fps < 0 || fps > 125) { |
2173 // Using console['error'] to evade Babel and ESLint |
2430 // Using console['error'] to evade Babel and ESLint |
2174 console['error']('forceFrameRate takes a positive int between 0 and 125, ' + 'forcing framerates higher than 125 fps is not unsupported'); |
2431 console['error']('forceFrameRate takes a positive int between 0 and 125, ' + 'forcing frame rates higher than 125 fps is not supported'); |
2175 return; |
2432 return; |
2176 } |
2433 } |
2177 |
2434 |
2178 if (fps > 0) { |
2435 if (fps > 0) { |
2179 yieldInterval = Math.floor(1000 / fps); |
2436 yieldInterval = Math.floor(1000 / fps); |
2321 var diff = a.sortIndex - b.sortIndex; |
2578 var diff = a.sortIndex - b.sortIndex; |
2322 return diff !== 0 ? diff : a.id - b.id; |
2579 return diff !== 0 ? diff : a.id - b.id; |
2323 } |
2580 } |
2324 |
2581 |
2325 // TODO: Use symbols? |
2582 // TODO: Use symbols? |
2326 var NoPriority = 0; |
|
2327 var ImmediatePriority = 1; |
2583 var ImmediatePriority = 1; |
2328 var UserBlockingPriority = 2; |
2584 var UserBlockingPriority = 2; |
2329 var NormalPriority = 3; |
2585 var NormalPriority = 3; |
2330 var LowPriority = 4; |
2586 var LowPriority = 4; |
2331 var IdlePriority = 5; |
2587 var IdlePriority = 5; |
2332 |
2588 |
2333 var runIdCounter = 0; |
|
2334 var mainThreadIdCounter = 0; |
|
2335 var profilingStateSize = 4; |
|
2336 var sharedProfilingBuffer = // $FlowFixMe Flow doesn't know about SharedArrayBuffer |
|
2337 typeof SharedArrayBuffer === 'function' ? new SharedArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : // $FlowFixMe Flow doesn't know about ArrayBuffer |
|
2338 typeof ArrayBuffer === 'function' ? new ArrayBuffer(profilingStateSize * Int32Array.BYTES_PER_ELEMENT) : null // Don't crash the init path on IE9 |
|
2339 ; |
|
2340 var profilingState = sharedProfilingBuffer !== null ? new Int32Array(sharedProfilingBuffer) : []; // We can't read this but it helps save bytes for null checks |
|
2341 |
|
2342 var PRIORITY = 0; |
|
2343 var CURRENT_TASK_ID = 1; |
|
2344 var CURRENT_RUN_ID = 2; |
|
2345 var QUEUE_SIZE = 3; |
|
2346 |
|
2347 { |
|
2348 profilingState[PRIORITY] = NoPriority; // This is maintained with a counter, because the size of the priority queue |
|
2349 // array might include canceled tasks. |
|
2350 |
|
2351 profilingState[QUEUE_SIZE] = 0; |
|
2352 profilingState[CURRENT_TASK_ID] = 0; |
|
2353 } // Bytes per element is 4 |
|
2354 |
|
2355 |
|
2356 var INITIAL_EVENT_LOG_SIZE = 131072; |
|
2357 var MAX_EVENT_LOG_SIZE = 524288; // Equivalent to 2 megabytes |
|
2358 |
|
2359 var eventLogSize = 0; |
|
2360 var eventLogBuffer = null; |
|
2361 var eventLog = null; |
|
2362 var eventLogIndex = 0; |
|
2363 var TaskStartEvent = 1; |
|
2364 var TaskCompleteEvent = 2; |
|
2365 var TaskErrorEvent = 3; |
|
2366 var TaskCancelEvent = 4; |
|
2367 var TaskRunEvent = 5; |
|
2368 var TaskYieldEvent = 6; |
|
2369 var SchedulerSuspendEvent = 7; |
|
2370 var SchedulerResumeEvent = 8; |
|
2371 |
|
2372 function logEvent(entries) { |
|
2373 if (eventLog !== null) { |
|
2374 var offset = eventLogIndex; |
|
2375 eventLogIndex += entries.length; |
|
2376 |
|
2377 if (eventLogIndex + 1 > eventLogSize) { |
|
2378 eventLogSize *= 2; |
|
2379 |
|
2380 if (eventLogSize > MAX_EVENT_LOG_SIZE) { |
|
2381 // Using console['error'] to evade Babel and ESLint |
|
2382 console['error']("Scheduler Profiling: Event log exceeded maximum size. Don't " + 'forget to call `stopLoggingProfilingEvents()`.'); |
|
2383 stopLoggingProfilingEvents(); |
|
2384 return; |
|
2385 } |
|
2386 |
|
2387 var newEventLog = new Int32Array(eventLogSize * 4); |
|
2388 newEventLog.set(eventLog); |
|
2389 eventLogBuffer = newEventLog.buffer; |
|
2390 eventLog = newEventLog; |
|
2391 } |
|
2392 |
|
2393 eventLog.set(entries, offset); |
|
2394 } |
|
2395 } |
|
2396 |
|
2397 function startLoggingProfilingEvents() { |
|
2398 eventLogSize = INITIAL_EVENT_LOG_SIZE; |
|
2399 eventLogBuffer = new ArrayBuffer(eventLogSize * 4); |
|
2400 eventLog = new Int32Array(eventLogBuffer); |
|
2401 eventLogIndex = 0; |
|
2402 } |
|
2403 function stopLoggingProfilingEvents() { |
|
2404 var buffer = eventLogBuffer; |
|
2405 eventLogSize = 0; |
|
2406 eventLogBuffer = null; |
|
2407 eventLog = null; |
|
2408 eventLogIndex = 0; |
|
2409 return buffer; |
|
2410 } |
|
2411 function markTaskStart(task, ms) { |
|
2412 { |
|
2413 profilingState[QUEUE_SIZE]++; |
|
2414 |
|
2415 if (eventLog !== null) { |
|
2416 // performance.now returns a float, representing milliseconds. When the |
|
2417 // event is logged, it's coerced to an int. Convert to microseconds to |
|
2418 // maintain extra degrees of precision. |
|
2419 logEvent([TaskStartEvent, ms * 1000, task.id, task.priorityLevel]); |
|
2420 } |
|
2421 } |
|
2422 } |
|
2423 function markTaskCompleted(task, ms) { |
|
2424 { |
|
2425 profilingState[PRIORITY] = NoPriority; |
|
2426 profilingState[CURRENT_TASK_ID] = 0; |
|
2427 profilingState[QUEUE_SIZE]--; |
|
2428 |
|
2429 if (eventLog !== null) { |
|
2430 logEvent([TaskCompleteEvent, ms * 1000, task.id]); |
|
2431 } |
|
2432 } |
|
2433 } |
|
2434 function markTaskCanceled(task, ms) { |
|
2435 { |
|
2436 profilingState[QUEUE_SIZE]--; |
|
2437 |
|
2438 if (eventLog !== null) { |
|
2439 logEvent([TaskCancelEvent, ms * 1000, task.id]); |
|
2440 } |
|
2441 } |
|
2442 } |
|
2443 function markTaskErrored(task, ms) { |
2589 function markTaskErrored(task, ms) { |
2444 { |
|
2445 profilingState[PRIORITY] = NoPriority; |
|
2446 profilingState[CURRENT_TASK_ID] = 0; |
|
2447 profilingState[QUEUE_SIZE]--; |
|
2448 |
|
2449 if (eventLog !== null) { |
|
2450 logEvent([TaskErrorEvent, ms * 1000, task.id]); |
|
2451 } |
|
2452 } |
|
2453 } |
|
2454 function markTaskRun(task, ms) { |
|
2455 { |
|
2456 runIdCounter++; |
|
2457 profilingState[PRIORITY] = task.priorityLevel; |
|
2458 profilingState[CURRENT_TASK_ID] = task.id; |
|
2459 profilingState[CURRENT_RUN_ID] = runIdCounter; |
|
2460 |
|
2461 if (eventLog !== null) { |
|
2462 logEvent([TaskRunEvent, ms * 1000, task.id, runIdCounter]); |
|
2463 } |
|
2464 } |
|
2465 } |
|
2466 function markTaskYield(task, ms) { |
|
2467 { |
|
2468 profilingState[PRIORITY] = NoPriority; |
|
2469 profilingState[CURRENT_TASK_ID] = 0; |
|
2470 profilingState[CURRENT_RUN_ID] = 0; |
|
2471 |
|
2472 if (eventLog !== null) { |
|
2473 logEvent([TaskYieldEvent, ms * 1000, task.id, runIdCounter]); |
|
2474 } |
|
2475 } |
|
2476 } |
|
2477 function markSchedulerSuspended(ms) { |
|
2478 { |
|
2479 mainThreadIdCounter++; |
|
2480 |
|
2481 if (eventLog !== null) { |
|
2482 logEvent([SchedulerSuspendEvent, ms * 1000, mainThreadIdCounter]); |
|
2483 } |
|
2484 } |
|
2485 } |
|
2486 function markSchedulerUnsuspended(ms) { |
|
2487 { |
|
2488 if (eventLog !== null) { |
|
2489 logEvent([SchedulerResumeEvent, ms * 1000, mainThreadIdCounter]); |
|
2490 } |
|
2491 } |
|
2492 } |
2590 } |
2493 |
2591 |
2494 /* eslint-disable no-var */ |
2592 /* eslint-disable no-var */ |
2495 // Math.pow(2, 30) - 1 |
2593 // Math.pow(2, 30) - 1 |
2496 // 0b111111111111111111111111111111 |
2594 // 0b111111111111111111111111111111 |
2497 |
2595 |
2498 var maxSigned31BitInt = 1073741823; // Times out immediately |
2596 var maxSigned31BitInt = 1073741823; // Times out immediately |
2499 |
2597 |
2500 var IMMEDIATE_PRIORITY_TIMEOUT = -1; // Eventually times out |
2598 var IMMEDIATE_PRIORITY_TIMEOUT = -1; // Eventually times out |
2501 |
2599 |
2502 var USER_BLOCKING_PRIORITY = 250; |
2600 var USER_BLOCKING_PRIORITY_TIMEOUT = 250; |
2503 var NORMAL_PRIORITY_TIMEOUT = 5000; |
2601 var NORMAL_PRIORITY_TIMEOUT = 5000; |
2504 var LOW_PRIORITY_TIMEOUT = 10000; // Never times out |
2602 var LOW_PRIORITY_TIMEOUT = 10000; // Never times out |
2505 |
2603 |
2506 var IDLE_PRIORITY = maxSigned31BitInt; // Tasks are stored on a min heap |
2604 var IDLE_PRIORITY_TIMEOUT = maxSigned31BitInt; // Tasks are stored on a min heap |
2507 |
2605 |
2508 var taskQueue = []; |
2606 var taskQueue = []; |
2509 var timerQueue = []; // Incrementing id counter. Used to maintain insertion order. |
2607 var timerQueue = []; // Incrementing id counter. Used to maintain insertion order. |
2510 |
2608 |
2511 var taskIdCounter = 1; // Pausing the scheduler is useful for debugging. |
2609 var taskIdCounter = 1; // Pausing the scheduler is useful for debugging. |
2527 } else if (timer.startTime <= currentTime) { |
2625 } else if (timer.startTime <= currentTime) { |
2528 // Timer fired. Transfer to the task queue. |
2626 // Timer fired. Transfer to the task queue. |
2529 pop(timerQueue); |
2627 pop(timerQueue); |
2530 timer.sortIndex = timer.expirationTime; |
2628 timer.sortIndex = timer.expirationTime; |
2531 push(taskQueue, timer); |
2629 push(taskQueue, timer); |
2532 |
|
2533 { |
|
2534 markTaskStart(timer, currentTime); |
|
2535 timer.isQueued = true; |
|
2536 } |
|
2537 } else { |
2630 } else { |
2538 // Remaining timers are pending. |
2631 // Remaining timers are pending. |
2539 return; |
2632 return; |
2540 } |
2633 } |
2541 |
2634 |
2560 } |
2653 } |
2561 } |
2654 } |
2562 } |
2655 } |
2563 |
2656 |
2564 function flushWork(hasTimeRemaining, initialTime) { |
2657 function flushWork(hasTimeRemaining, initialTime) { |
2565 { |
|
2566 markSchedulerUnsuspended(initialTime); |
|
2567 } // We'll need a host callback the next time work is scheduled. |
|
2568 |
2658 |
2569 |
2659 |
2570 isHostCallbackScheduled = false; |
2660 isHostCallbackScheduled = false; |
2571 |
2661 |
2572 if (isHostTimeoutScheduled) { |
2662 if (isHostTimeoutScheduled) { |
2590 } |
2680 } |
2591 |
2681 |
2592 throw error; |
2682 throw error; |
2593 } |
2683 } |
2594 } else { |
2684 } else { |
2595 // No catch in prod codepath. |
2685 // No catch in prod code path. |
2596 return workLoop(hasTimeRemaining, initialTime); |
2686 return workLoop(hasTimeRemaining, initialTime); |
2597 } |
2687 } |
2598 } finally { |
2688 } finally { |
2599 currentTask = null; |
2689 currentTask = null; |
2600 currentPriorityLevel = previousPriorityLevel; |
2690 currentPriorityLevel = previousPriorityLevel; |
2601 isPerformingWork = false; |
2691 isPerformingWork = false; |
2602 |
|
2603 { |
|
2604 var _currentTime = getCurrentTime(); |
|
2605 |
|
2606 markSchedulerSuspended(_currentTime); |
|
2607 } |
|
2608 } |
2692 } |
2609 } |
2693 } |
2610 |
2694 |
2611 function workLoop(hasTimeRemaining, initialTime) { |
2695 function workLoop(hasTimeRemaining, initialTime) { |
2612 var currentTime = initialTime; |
2696 var currentTime = initialTime; |
2619 break; |
2703 break; |
2620 } |
2704 } |
2621 |
2705 |
2622 var callback = currentTask.callback; |
2706 var callback = currentTask.callback; |
2623 |
2707 |
2624 if (callback !== null) { |
2708 if (typeof callback === 'function') { |
2625 currentTask.callback = null; |
2709 currentTask.callback = null; |
2626 currentPriorityLevel = currentTask.priorityLevel; |
2710 currentPriorityLevel = currentTask.priorityLevel; |
2627 var didUserCallbackTimeout = currentTask.expirationTime <= currentTime; |
2711 var didUserCallbackTimeout = currentTask.expirationTime <= currentTime; |
2628 markTaskRun(currentTask, currentTime); |
2712 |
2629 var continuationCallback = callback(didUserCallbackTimeout); |
2713 var continuationCallback = callback(didUserCallbackTimeout); |
2630 currentTime = getCurrentTime(); |
2714 currentTime = getCurrentTime(); |
2631 |
2715 |
2632 if (typeof continuationCallback === 'function') { |
2716 if (typeof continuationCallback === 'function') { |
2633 currentTask.callback = continuationCallback; |
2717 currentTask.callback = continuationCallback; |
2634 markTaskYield(currentTask, currentTime); |
|
2635 } else { |
2718 } else { |
2636 { |
|
2637 markTaskCompleted(currentTask, currentTime); |
|
2638 currentTask.isQueued = false; |
|
2639 } |
|
2640 |
2719 |
2641 if (currentTask === peek(taskQueue)) { |
2720 if (currentTask === peek(taskQueue)) { |
2642 pop(taskQueue); |
2721 pop(taskQueue); |
2643 } |
2722 } |
2644 } |
2723 } |
2728 currentPriorityLevel = previousPriorityLevel; |
2807 currentPriorityLevel = previousPriorityLevel; |
2729 } |
2808 } |
2730 }; |
2809 }; |
2731 } |
2810 } |
2732 |
2811 |
2733 function timeoutForPriorityLevel(priorityLevel) { |
|
2734 switch (priorityLevel) { |
|
2735 case ImmediatePriority: |
|
2736 return IMMEDIATE_PRIORITY_TIMEOUT; |
|
2737 |
|
2738 case UserBlockingPriority: |
|
2739 return USER_BLOCKING_PRIORITY; |
|
2740 |
|
2741 case IdlePriority: |
|
2742 return IDLE_PRIORITY; |
|
2743 |
|
2744 case LowPriority: |
|
2745 return LOW_PRIORITY_TIMEOUT; |
|
2746 |
|
2747 case NormalPriority: |
|
2748 default: |
|
2749 return NORMAL_PRIORITY_TIMEOUT; |
|
2750 } |
|
2751 } |
|
2752 |
|
2753 function unstable_scheduleCallback(priorityLevel, callback, options) { |
2812 function unstable_scheduleCallback(priorityLevel, callback, options) { |
2754 var currentTime = getCurrentTime(); |
2813 var currentTime = getCurrentTime(); |
2755 var startTime; |
2814 var startTime; |
2756 var timeout; |
|
2757 |
2815 |
2758 if (typeof options === 'object' && options !== null) { |
2816 if (typeof options === 'object' && options !== null) { |
2759 var delay = options.delay; |
2817 var delay = options.delay; |
2760 |
2818 |
2761 if (typeof delay === 'number' && delay > 0) { |
2819 if (typeof delay === 'number' && delay > 0) { |
2762 startTime = currentTime + delay; |
2820 startTime = currentTime + delay; |
2763 } else { |
2821 } else { |
2764 startTime = currentTime; |
2822 startTime = currentTime; |
2765 } |
2823 } |
2766 |
|
2767 timeout = typeof options.timeout === 'number' ? options.timeout : timeoutForPriorityLevel(priorityLevel); |
|
2768 } else { |
2824 } else { |
2769 timeout = timeoutForPriorityLevel(priorityLevel); |
|
2770 startTime = currentTime; |
2825 startTime = currentTime; |
2826 } |
|
2827 |
|
2828 var timeout; |
|
2829 |
|
2830 switch (priorityLevel) { |
|
2831 case ImmediatePriority: |
|
2832 timeout = IMMEDIATE_PRIORITY_TIMEOUT; |
|
2833 break; |
|
2834 |
|
2835 case UserBlockingPriority: |
|
2836 timeout = USER_BLOCKING_PRIORITY_TIMEOUT; |
|
2837 break; |
|
2838 |
|
2839 case IdlePriority: |
|
2840 timeout = IDLE_PRIORITY_TIMEOUT; |
|
2841 break; |
|
2842 |
|
2843 case LowPriority: |
|
2844 timeout = LOW_PRIORITY_TIMEOUT; |
|
2845 break; |
|
2846 |
|
2847 case NormalPriority: |
|
2848 default: |
|
2849 timeout = NORMAL_PRIORITY_TIMEOUT; |
|
2850 break; |
|
2771 } |
2851 } |
2772 |
2852 |
2773 var expirationTime = startTime + timeout; |
2853 var expirationTime = startTime + timeout; |
2774 var newTask = { |
2854 var newTask = { |
2775 id: taskIdCounter++, |
2855 id: taskIdCounter++, |
2778 startTime: startTime, |
2858 startTime: startTime, |
2779 expirationTime: expirationTime, |
2859 expirationTime: expirationTime, |
2780 sortIndex: -1 |
2860 sortIndex: -1 |
2781 }; |
2861 }; |
2782 |
2862 |
2783 { |
|
2784 newTask.isQueued = false; |
|
2785 } |
|
2786 |
|
2787 if (startTime > currentTime) { |
2863 if (startTime > currentTime) { |
2788 // This is a delayed task. |
2864 // This is a delayed task. |
2789 newTask.sortIndex = startTime; |
2865 newTask.sortIndex = startTime; |
2790 push(timerQueue, newTask); |
2866 push(timerQueue, newTask); |
2791 |
2867 |
2802 requestHostTimeout(handleTimeout, startTime - currentTime); |
2878 requestHostTimeout(handleTimeout, startTime - currentTime); |
2803 } |
2879 } |
2804 } else { |
2880 } else { |
2805 newTask.sortIndex = expirationTime; |
2881 newTask.sortIndex = expirationTime; |
2806 push(taskQueue, newTask); |
2882 push(taskQueue, newTask); |
2807 |
|
2808 { |
|
2809 markTaskStart(newTask, currentTime); |
|
2810 newTask.isQueued = true; |
|
2811 } // Schedule a host callback, if needed. If we're already performing work, |
|
2812 // wait until the next time we yield. |
2883 // wait until the next time we yield. |
2813 |
2884 |
2814 |
2885 |
2815 if (!isHostCallbackScheduled && !isPerformingWork) { |
2886 if (!isHostCallbackScheduled && !isPerformingWork) { |
2816 isHostCallbackScheduled = true; |
2887 isHostCallbackScheduled = true; |
2835 function unstable_getFirstCallbackNode() { |
2906 function unstable_getFirstCallbackNode() { |
2836 return peek(taskQueue); |
2907 return peek(taskQueue); |
2837 } |
2908 } |
2838 |
2909 |
2839 function unstable_cancelCallback(task) { |
2910 function unstable_cancelCallback(task) { |
2840 { |
|
2841 if (task.isQueued) { |
|
2842 var currentTime = getCurrentTime(); |
|
2843 markTaskCanceled(task, currentTime); |
|
2844 task.isQueued = false; |
|
2845 } |
|
2846 } // Null out the callback to indicate the task has been canceled. (Can't |
|
2847 // remove from the queue because you can't remove arbitrary nodes from an |
2911 // remove from the queue because you can't remove arbitrary nodes from an |
2848 // array based heap, only the first one.) |
2912 // array based heap, only the first one.) |
2849 |
2913 |
2850 |
2914 |
2851 task.callback = null; |
2915 task.callback = null; |
2853 |
2917 |
2854 function unstable_getCurrentPriorityLevel() { |
2918 function unstable_getCurrentPriorityLevel() { |
2855 return currentPriorityLevel; |
2919 return currentPriorityLevel; |
2856 } |
2920 } |
2857 |
2921 |
2858 function unstable_shouldYield() { |
|
2859 var currentTime = getCurrentTime(); |
|
2860 advanceTimers(currentTime); |
|
2861 var firstTask = peek(taskQueue); |
|
2862 return firstTask !== currentTask && currentTask !== null && firstTask !== null && firstTask.callback !== null && firstTask.startTime <= currentTime && firstTask.expirationTime < currentTask.expirationTime || shouldYieldToHost(); |
|
2863 } |
|
2864 |
|
2865 var unstable_requestPaint = requestPaint; |
2922 var unstable_requestPaint = requestPaint; |
2866 var unstable_Profiling = { |
2923 var unstable_Profiling = null; |
2867 startLoggingProfilingEvents: startLoggingProfilingEvents, |
|
2868 stopLoggingProfilingEvents: stopLoggingProfilingEvents, |
|
2869 sharedProfilingBuffer: sharedProfilingBuffer |
|
2870 } ; |
|
2871 |
2924 |
2872 |
2925 |
2873 |
2926 |
2874 var Scheduler = /*#__PURE__*/Object.freeze({ |
2927 var Scheduler = /*#__PURE__*/Object.freeze({ |
2875 __proto__: null, |
2928 __proto__: null, |
2882 unstable_next: unstable_next, |
2935 unstable_next: unstable_next, |
2883 unstable_scheduleCallback: unstable_scheduleCallback, |
2936 unstable_scheduleCallback: unstable_scheduleCallback, |
2884 unstable_cancelCallback: unstable_cancelCallback, |
2937 unstable_cancelCallback: unstable_cancelCallback, |
2885 unstable_wrapCallback: unstable_wrapCallback, |
2938 unstable_wrapCallback: unstable_wrapCallback, |
2886 unstable_getCurrentPriorityLevel: unstable_getCurrentPriorityLevel, |
2939 unstable_getCurrentPriorityLevel: unstable_getCurrentPriorityLevel, |
2887 unstable_shouldYield: unstable_shouldYield, |
2940 get unstable_shouldYield () { return shouldYieldToHost; }, |
2888 unstable_requestPaint: unstable_requestPaint, |
2941 unstable_requestPaint: unstable_requestPaint, |
2889 unstable_continueExecution: unstable_continueExecution, |
2942 unstable_continueExecution: unstable_continueExecution, |
2890 unstable_pauseExecution: unstable_pauseExecution, |
2943 unstable_pauseExecution: unstable_pauseExecution, |
2891 unstable_getFirstCallbackNode: unstable_getFirstCallbackNode, |
2944 unstable_getFirstCallbackNode: unstable_getFirstCallbackNode, |
2892 get unstable_now () { return getCurrentTime; }, |
2945 get unstable_now () { return getCurrentTime; }, |
3234 |
3287 |
3235 var ReactSharedInternals$1 = { |
3288 var ReactSharedInternals$1 = { |
3236 ReactCurrentDispatcher: ReactCurrentDispatcher, |
3289 ReactCurrentDispatcher: ReactCurrentDispatcher, |
3237 ReactCurrentOwner: ReactCurrentOwner, |
3290 ReactCurrentOwner: ReactCurrentOwner, |
3238 IsSomeRendererActing: IsSomeRendererActing, |
3291 IsSomeRendererActing: IsSomeRendererActing, |
3292 ReactCurrentBatchConfig: ReactCurrentBatchConfig, |
|
3239 // Used by renderers to avoid bundling object-assign twice in UMD bundles: |
3293 // Used by renderers to avoid bundling object-assign twice in UMD bundles: |
3240 assign: objectAssign |
3294 assign: assign, |
3241 }; |
3295 // Re-export the schedule API(s) for UMD bundles. |
3242 |
3296 // This avoids introducing a dependency on a new UMD global in a minor update, |
3243 { |
3297 // Since that would be a breaking change (e.g. for all existing CodeSandboxes). |
3244 objectAssign(ReactSharedInternals$1, { |
3298 // This re-export is only required for UMD bundles; |
3245 // These should not be included in production. |
3299 // CJS bundles use the shared NPM package. |
3246 ReactDebugCurrentFrame: ReactDebugCurrentFrame, |
|
3247 // Shim for React DOM 16.0.0 which still destructured (but not used) this. |
|
3248 // TODO: remove in React 17.0. |
|
3249 ReactComponentTreeHook: {} |
|
3250 }); |
|
3251 } // Re-export the schedule API(s) for UMD bundles. |
|
3252 // This avoids introducing a dependency on a new UMD global in a minor update, |
|
3253 // Since that would be a breaking change (e.g. for all existing CodeSandboxes). |
|
3254 // This re-export is only required for UMD bundles; |
|
3255 // CJS bundles use the shared NPM package. |
|
3256 |
|
3257 |
|
3258 objectAssign(ReactSharedInternals$1, { |
|
3259 Scheduler: Scheduler, |
3300 Scheduler: Scheduler, |
3260 SchedulerTracing: SchedulerTracing |
3301 SchedulerTracing: SchedulerTracing |
3261 }); |
3302 }; |
3303 |
|
3304 { |
|
3305 ReactSharedInternals$1.ReactDebugCurrentFrame = ReactDebugCurrentFrame; |
|
3306 } |
|
3262 |
3307 |
3263 { |
3308 { |
3264 |
3309 |
3265 try { |
3310 try { |
3266 var frozenObject = Object.freeze({}); |
3311 var frozenObject = Object.freeze({}); |
3267 var testMap = new Map([[frozenObject, null]]); |
3312 /* eslint-disable no-new */ |
3268 var testSet = new Set([frozenObject]); // This is necessary for Rollup to not consider these unused. |
3313 |
3269 // https://github.com/rollup/rollup/issues/1771 |
3314 new Map([[frozenObject, null]]); |
3270 // TODO: we can remove these if Rollup fixes the bug. |
3315 new Set([frozenObject]); |
3271 |
3316 /* eslint-enable no-new */ |
3272 testMap.set(0, 0); |
|
3273 testSet.add(0); |
|
3274 } catch (e) { |
3317 } catch (e) { |
3275 } |
3318 } |
3276 } |
3319 } |
3277 |
3320 |
3278 var createElement$1 = createElementWithValidation ; |
3321 var createElement$1 = createElementWithValidation ; |
3286 only: onlyChild |
3329 only: onlyChild |
3287 }; |
3330 }; |
3288 |
3331 |
3289 exports.Children = Children; |
3332 exports.Children = Children; |
3290 exports.Component = Component; |
3333 exports.Component = Component; |
3291 exports.Fragment = REACT_FRAGMENT_TYPE; |
|
3292 exports.Profiler = REACT_PROFILER_TYPE; |
|
3293 exports.PureComponent = PureComponent; |
3334 exports.PureComponent = PureComponent; |
3294 exports.StrictMode = REACT_STRICT_MODE_TYPE; |
|
3295 exports.Suspense = REACT_SUSPENSE_TYPE; |
|
3296 exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = ReactSharedInternals$1; |
3335 exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED = ReactSharedInternals$1; |
3297 exports.cloneElement = cloneElement$1; |
3336 exports.cloneElement = cloneElement$1; |
3298 exports.createContext = createContext; |
3337 exports.createContext = createContext; |
3299 exports.createElement = createElement$1; |
3338 exports.createElement = createElement$1; |
3300 exports.createFactory = createFactory; |
3339 exports.createFactory = createFactory; |