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