1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | 'use strict';
|
11 |
|
12 |
|
13 |
|
14 | if (process.env.NODE_ENV !== "production") {
|
15 | (function() {
|
16 | 'use strict';
|
17 |
|
18 | Object.defineProperty(exports, '__esModule', { value: true });
|
19 |
|
20 | var React = require('react');
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | var validateFormat = function () {};
|
34 |
|
35 | {
|
36 | validateFormat = function (format) {
|
37 | if (format === undefined) {
|
38 | throw new Error('invariant requires an error message argument');
|
39 | }
|
40 | };
|
41 | }
|
42 |
|
43 | function invariant(condition, format, a, b, c, d, e, f) {
|
44 | validateFormat(format);
|
45 |
|
46 | if (!condition) {
|
47 | var error = void 0;
|
48 | if (format === undefined) {
|
49 | error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
|
50 | } else {
|
51 | var args = [a, b, c, d, e, f];
|
52 | var argIndex = 0;
|
53 | error = new Error(format.replace(/%s/g, function () {
|
54 | return args[argIndex++];
|
55 | }));
|
56 | error.name = 'Invariant Violation';
|
57 | }
|
58 |
|
59 | error.framesToPop = 1;
|
60 | throw error;
|
61 | }
|
62 | }
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 | var warningWithoutStack = function () {};
|
75 |
|
76 | {
|
77 | warningWithoutStack = function (condition, format) {
|
78 | for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
79 | args[_key - 2] = arguments[_key];
|
80 | }
|
81 |
|
82 | if (format === undefined) {
|
83 | throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
|
84 | }
|
85 | if (args.length > 8) {
|
86 |
|
87 | throw new Error('warningWithoutStack() currently supports at most 8 arguments.');
|
88 | }
|
89 | if (condition) {
|
90 | return;
|
91 | }
|
92 | if (typeof console !== 'undefined') {
|
93 | var argsWithFormat = args.map(function (item) {
|
94 | return '' + item;
|
95 | });
|
96 | argsWithFormat.unshift('Warning: ' + format);
|
97 |
|
98 |
|
99 |
|
100 | Function.prototype.apply.call(console.error, console, argsWithFormat);
|
101 | }
|
102 | try {
|
103 |
|
104 |
|
105 |
|
106 | var argIndex = 0;
|
107 | var message = 'Warning: ' + format.replace(/%s/g, function () {
|
108 | return args[argIndex++];
|
109 | });
|
110 | throw new Error(message);
|
111 | } catch (x) {}
|
112 | };
|
113 | }
|
114 |
|
115 | var warningWithoutStack$1 = warningWithoutStack;
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 |
|
123 |
|
124 |
|
125 |
|
126 |
|
127 |
|
128 |
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 | function get(key) {
|
135 | return key._reactInternalFiber;
|
136 | }
|
137 |
|
138 | var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
139 |
|
140 |
|
141 |
|
142 |
|
143 | if (!ReactSharedInternals.hasOwnProperty('ReactCurrentDispatcher')) {
|
144 | ReactSharedInternals.ReactCurrentDispatcher = {
|
145 | current: null
|
146 | };
|
147 | }
|
148 |
|
149 |
|
150 |
|
151 | var hasSymbol = typeof Symbol === 'function' && Symbol.for;
|
152 |
|
153 |
|
154 | var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
|
155 | var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
|
156 | var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
|
157 | var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
|
158 | var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
|
159 | var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
|
160 |
|
161 | var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
|
162 | var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
|
163 | var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
|
164 | var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
|
165 | var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
|
166 |
|
167 | var Resolved = 1;
|
168 |
|
169 |
|
170 | function refineResolvedLazyComponent(lazyComponent) {
|
171 | return lazyComponent._status === Resolved ? lazyComponent._result : null;
|
172 | }
|
173 |
|
174 | function getWrappedName(outerType, innerType, wrapperName) {
|
175 | var functionName = innerType.displayName || innerType.name || '';
|
176 | return outerType.displayName || (functionName !== '' ? wrapperName + '(' + functionName + ')' : wrapperName);
|
177 | }
|
178 |
|
179 | function getComponentName(type) {
|
180 | if (type == null) {
|
181 |
|
182 | return null;
|
183 | }
|
184 | {
|
185 | if (typeof type.tag === 'number') {
|
186 | warningWithoutStack$1(false, 'Received an unexpected object in getComponentName(). ' + 'This is likely a bug in React. Please file an issue.');
|
187 | }
|
188 | }
|
189 | if (typeof type === 'function') {
|
190 | return type.displayName || type.name || null;
|
191 | }
|
192 | if (typeof type === 'string') {
|
193 | return type;
|
194 | }
|
195 | switch (type) {
|
196 | case REACT_CONCURRENT_MODE_TYPE:
|
197 | return 'ConcurrentMode';
|
198 | case REACT_FRAGMENT_TYPE:
|
199 | return 'Fragment';
|
200 | case REACT_PORTAL_TYPE:
|
201 | return 'Portal';
|
202 | case REACT_PROFILER_TYPE:
|
203 | return 'Profiler';
|
204 | case REACT_STRICT_MODE_TYPE:
|
205 | return 'StrictMode';
|
206 | case REACT_SUSPENSE_TYPE:
|
207 | return 'Suspense';
|
208 | }
|
209 | if (typeof type === 'object') {
|
210 | switch (type.$$typeof) {
|
211 | case REACT_CONTEXT_TYPE:
|
212 | return 'Context.Consumer';
|
213 | case REACT_PROVIDER_TYPE:
|
214 | return 'Context.Provider';
|
215 | case REACT_FORWARD_REF_TYPE:
|
216 | return getWrappedName(type, type.render, 'ForwardRef');
|
217 | case REACT_MEMO_TYPE:
|
218 | return getComponentName(type.type);
|
219 | case REACT_LAZY_TYPE:
|
220 | {
|
221 | var thenable = type;
|
222 | var resolvedThenable = refineResolvedLazyComponent(thenable);
|
223 | if (resolvedThenable) {
|
224 | return getComponentName(resolvedThenable);
|
225 | }
|
226 | }
|
227 | }
|
228 | }
|
229 | return null;
|
230 | }
|
231 |
|
232 | var ClassComponent = 1;
|
233 |
|
234 | var HostRoot = 3;
|
235 | var HostPortal = 4;
|
236 | var HostComponent = 5;
|
237 | var HostText = 6;
|
238 |
|
239 |
|
240 | var NoEffect = 0;
|
241 |
|
242 |
|
243 |
|
244 | var Placement = 2;
|
245 |
|
246 |
|
247 |
|
248 |
|
249 |
|
250 |
|
251 |
|
252 |
|
253 |
|
254 |
|
255 |
|
256 |
|
257 |
|
258 |
|
259 |
|
260 | var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
|
261 |
|
262 | var MOUNTING = 1;
|
263 | var MOUNTED = 2;
|
264 | var UNMOUNTED = 3;
|
265 |
|
266 | function isFiberMountedImpl(fiber) {
|
267 | var node = fiber;
|
268 | if (!fiber.alternate) {
|
269 |
|
270 |
|
271 | if ((node.effectTag & Placement) !== NoEffect) {
|
272 | return MOUNTING;
|
273 | }
|
274 | while (node.return) {
|
275 | node = node.return;
|
276 | if ((node.effectTag & Placement) !== NoEffect) {
|
277 | return MOUNTING;
|
278 | }
|
279 | }
|
280 | } else {
|
281 | while (node.return) {
|
282 | node = node.return;
|
283 | }
|
284 | }
|
285 | if (node.tag === HostRoot) {
|
286 |
|
287 |
|
288 | return MOUNTED;
|
289 | }
|
290 |
|
291 |
|
292 | return UNMOUNTED;
|
293 | }
|
294 |
|
295 | function isFiberMounted(fiber) {
|
296 | return isFiberMountedImpl(fiber) === MOUNTED;
|
297 | }
|
298 |
|
299 | function isMounted(component) {
|
300 | {
|
301 | var owner = ReactCurrentOwner.current;
|
302 | if (owner !== null && owner.tag === ClassComponent) {
|
303 | var ownerFiber = owner;
|
304 | var instance = ownerFiber.stateNode;
|
305 | !instance._warnedAboutRefsInRender ? warningWithoutStack$1(false, '%s is accessing isMounted inside its render() function. ' + 'render() should be a pure function of props and state. It should ' + 'never access something that requires stale data from the previous ' + 'render, such as refs. Move this logic to componentDidMount and ' + 'componentDidUpdate instead.', getComponentName(ownerFiber.type) || 'A component') : void 0;
|
306 | instance._warnedAboutRefsInRender = true;
|
307 | }
|
308 | }
|
309 |
|
310 | var fiber = get(component);
|
311 | if (!fiber) {
|
312 | return false;
|
313 | }
|
314 | return isFiberMountedImpl(fiber) === MOUNTED;
|
315 | }
|
316 |
|
317 | function assertIsMounted(fiber) {
|
318 | !(isFiberMountedImpl(fiber) === MOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
|
319 | }
|
320 |
|
321 | function findCurrentFiberUsingSlowPath(fiber) {
|
322 | var alternate = fiber.alternate;
|
323 | if (!alternate) {
|
324 |
|
325 | var state = isFiberMountedImpl(fiber);
|
326 | !(state !== UNMOUNTED) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
|
327 | if (state === MOUNTING) {
|
328 | return null;
|
329 | }
|
330 | return fiber;
|
331 | }
|
332 |
|
333 |
|
334 |
|
335 | var a = fiber;
|
336 | var b = alternate;
|
337 | while (true) {
|
338 | var parentA = a.return;
|
339 | var parentB = parentA ? parentA.alternate : null;
|
340 | if (!parentA || !parentB) {
|
341 |
|
342 | break;
|
343 | }
|
344 |
|
345 |
|
346 |
|
347 |
|
348 | if (parentA.child === parentB.child) {
|
349 | var child = parentA.child;
|
350 | while (child) {
|
351 | if (child === a) {
|
352 |
|
353 | assertIsMounted(parentA);
|
354 | return fiber;
|
355 | }
|
356 | if (child === b) {
|
357 |
|
358 | assertIsMounted(parentA);
|
359 | return alternate;
|
360 | }
|
361 | child = child.sibling;
|
362 | }
|
363 |
|
364 |
|
365 | invariant(false, 'Unable to find node on an unmounted component.');
|
366 | }
|
367 |
|
368 | if (a.return !== b.return) {
|
369 |
|
370 |
|
371 |
|
372 |
|
373 | a = parentA;
|
374 | b = parentB;
|
375 | } else {
|
376 |
|
377 |
|
378 |
|
379 |
|
380 |
|
381 | var didFindChild = false;
|
382 | var _child = parentA.child;
|
383 | while (_child) {
|
384 | if (_child === a) {
|
385 | didFindChild = true;
|
386 | a = parentA;
|
387 | b = parentB;
|
388 | break;
|
389 | }
|
390 | if (_child === b) {
|
391 | didFindChild = true;
|
392 | b = parentA;
|
393 | a = parentB;
|
394 | break;
|
395 | }
|
396 | _child = _child.sibling;
|
397 | }
|
398 | if (!didFindChild) {
|
399 |
|
400 | _child = parentB.child;
|
401 | while (_child) {
|
402 | if (_child === a) {
|
403 | didFindChild = true;
|
404 | a = parentB;
|
405 | b = parentA;
|
406 | break;
|
407 | }
|
408 | if (_child === b) {
|
409 | didFindChild = true;
|
410 | b = parentB;
|
411 | a = parentA;
|
412 | break;
|
413 | }
|
414 | _child = _child.sibling;
|
415 | }
|
416 | !didFindChild ? invariant(false, 'Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue.') : void 0;
|
417 | }
|
418 | }
|
419 |
|
420 | !(a.alternate === b) ? invariant(false, 'Return fibers should always be each others\' alternates. This error is likely caused by a bug in React. Please file an issue.') : void 0;
|
421 | }
|
422 |
|
423 |
|
424 | !(a.tag === HostRoot) ? invariant(false, 'Unable to find node on an unmounted component.') : void 0;
|
425 | if (a.stateNode.current === a) {
|
426 |
|
427 | return fiber;
|
428 | }
|
429 |
|
430 | return alternate;
|
431 | }
|
432 |
|
433 | function findCurrentHostFiber(parent) {
|
434 | var currentParent = findCurrentFiberUsingSlowPath(parent);
|
435 | if (!currentParent) {
|
436 | return null;
|
437 | }
|
438 |
|
439 |
|
440 | var node = currentParent;
|
441 | while (true) {
|
442 | if (node.tag === HostComponent || node.tag === HostText) {
|
443 | return node;
|
444 | } else if (node.child) {
|
445 | node.child.return = node;
|
446 | node = node.child;
|
447 | continue;
|
448 | }
|
449 | if (node === currentParent) {
|
450 | return null;
|
451 | }
|
452 | while (!node.sibling) {
|
453 | if (!node.return || node.return === currentParent) {
|
454 | return null;
|
455 | }
|
456 | node = node.return;
|
457 | }
|
458 | node.sibling.return = node.return;
|
459 | node = node.sibling;
|
460 | }
|
461 |
|
462 |
|
463 | return null;
|
464 | }
|
465 |
|
466 | function findCurrentHostFiberWithNoPortals(parent) {
|
467 | var currentParent = findCurrentFiberUsingSlowPath(parent);
|
468 | if (!currentParent) {
|
469 | return null;
|
470 | }
|
471 |
|
472 |
|
473 | var node = currentParent;
|
474 | while (true) {
|
475 | if (node.tag === HostComponent || node.tag === HostText) {
|
476 | return node;
|
477 | } else if (node.child && node.tag !== HostPortal) {
|
478 | node.child.return = node;
|
479 | node = node.child;
|
480 | continue;
|
481 | }
|
482 | if (node === currentParent) {
|
483 | return null;
|
484 | }
|
485 | while (!node.sibling) {
|
486 | if (!node.return || node.return === currentParent) {
|
487 | return null;
|
488 | }
|
489 | node = node.return;
|
490 | }
|
491 | node.sibling.return = node.return;
|
492 | node = node.sibling;
|
493 | }
|
494 |
|
495 |
|
496 | return null;
|
497 | }
|
498 |
|
499 | exports.isFiberMounted = isFiberMounted;
|
500 | exports.isMounted = isMounted;
|
501 | exports.findCurrentFiberUsingSlowPath = findCurrentFiberUsingSlowPath;
|
502 | exports.findCurrentHostFiber = findCurrentHostFiber;
|
503 | exports.findCurrentHostFiberWithNoPortals = findCurrentHostFiberWithNoPortals;
|
504 | })();
|
505 | }
|