1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | if (process.env.NODE_ENV !== "production") {
|
14 | (function() {
|
15 | 'use strict';
|
16 |
|
17 | var React = require('react');
|
18 | var ReactDOM = require('react-dom');
|
19 |
|
20 | var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | function warn(format) {
|
28 | {
|
29 | {
|
30 | for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
31 | args[_key - 1] = arguments[_key];
|
32 | }
|
33 |
|
34 | printWarning('warn', format, args);
|
35 | }
|
36 | }
|
37 | }
|
38 | function error(format) {
|
39 | {
|
40 | {
|
41 | for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
|
42 | args[_key2 - 1] = arguments[_key2];
|
43 | }
|
44 |
|
45 | printWarning('error', format, args);
|
46 | }
|
47 | }
|
48 | }
|
49 |
|
50 | function printWarning(level, format, args) {
|
51 |
|
52 |
|
53 | {
|
54 | var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
|
55 | var stack = ReactDebugCurrentFrame.getStackAddendum();
|
56 |
|
57 | if (stack !== '') {
|
58 | format += '%s';
|
59 | args = args.concat([stack]);
|
60 | }
|
61 |
|
62 |
|
63 | var argsWithFormat = args.map(function (item) {
|
64 | return String(item);
|
65 | });
|
66 |
|
67 | argsWithFormat.unshift('Warning: ' + format);
|
68 |
|
69 |
|
70 |
|
71 | Function.prototype.apply.call(console[level], console, argsWithFormat);
|
72 | }
|
73 | }
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 |
|
84 | function get(key) {
|
85 | return key._reactInternals;
|
86 | }
|
87 |
|
88 | var FunctionComponent = 0;
|
89 | var ClassComponent = 1;
|
90 |
|
91 | var HostRoot = 3;
|
92 |
|
93 | var HostComponent = 5;
|
94 | var HostText = 6;
|
95 |
|
96 |
|
97 | var NoFlags =
|
98 |
|
99 | 0;
|
100 |
|
101 | var Placement =
|
102 |
|
103 | 2;
|
104 | var Hydrating =
|
105 |
|
106 | 4096;
|
107 |
|
108 | var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
|
109 | function getNearestMountedFiber(fiber) {
|
110 | var node = fiber;
|
111 | var nearestMounted = fiber;
|
112 |
|
113 | if (!fiber.alternate) {
|
114 |
|
115 |
|
116 | var nextNode = node;
|
117 |
|
118 | do {
|
119 | node = nextNode;
|
120 |
|
121 | if ((node.flags & (Placement | Hydrating)) !== NoFlags) {
|
122 |
|
123 |
|
124 |
|
125 | nearestMounted = node.return;
|
126 | }
|
127 |
|
128 | nextNode = node.return;
|
129 | } while (nextNode);
|
130 | } else {
|
131 | while (node.return) {
|
132 | node = node.return;
|
133 | }
|
134 | }
|
135 |
|
136 | if (node.tag === HostRoot) {
|
137 |
|
138 |
|
139 | return nearestMounted;
|
140 | }
|
141 |
|
142 |
|
143 |
|
144 | return null;
|
145 | }
|
146 |
|
147 | function assertIsMounted(fiber) {
|
148 | if (getNearestMountedFiber(fiber) !== fiber) {
|
149 | throw new Error('Unable to find node on an unmounted component.');
|
150 | }
|
151 | }
|
152 |
|
153 | function findCurrentFiberUsingSlowPath(fiber) {
|
154 | var alternate = fiber.alternate;
|
155 |
|
156 | if (!alternate) {
|
157 |
|
158 | var nearestMounted = getNearestMountedFiber(fiber);
|
159 |
|
160 | if (nearestMounted === null) {
|
161 | throw new Error('Unable to find node on an unmounted component.');
|
162 | }
|
163 |
|
164 | if (nearestMounted !== fiber) {
|
165 | return null;
|
166 | }
|
167 |
|
168 | return fiber;
|
169 | }
|
170 |
|
171 |
|
172 |
|
173 |
|
174 | var a = fiber;
|
175 | var b = alternate;
|
176 |
|
177 | while (true) {
|
178 | var parentA = a.return;
|
179 |
|
180 | if (parentA === null) {
|
181 |
|
182 | break;
|
183 | }
|
184 |
|
185 | var parentB = parentA.alternate;
|
186 |
|
187 | if (parentB === null) {
|
188 |
|
189 |
|
190 |
|
191 |
|
192 | var nextParent = parentA.return;
|
193 |
|
194 | if (nextParent !== null) {
|
195 | a = b = nextParent;
|
196 | continue;
|
197 | }
|
198 |
|
199 |
|
200 | break;
|
201 | }
|
202 |
|
203 |
|
204 |
|
205 |
|
206 | if (parentA.child === parentB.child) {
|
207 | var child = parentA.child;
|
208 |
|
209 | while (child) {
|
210 | if (child === a) {
|
211 |
|
212 | assertIsMounted(parentA);
|
213 | return fiber;
|
214 | }
|
215 |
|
216 | if (child === b) {
|
217 |
|
218 | assertIsMounted(parentA);
|
219 | return alternate;
|
220 | }
|
221 |
|
222 | child = child.sibling;
|
223 | }
|
224 |
|
225 |
|
226 |
|
227 | throw new Error('Unable to find node on an unmounted component.');
|
228 | }
|
229 |
|
230 | if (a.return !== b.return) {
|
231 |
|
232 |
|
233 |
|
234 |
|
235 | a = parentA;
|
236 | b = parentB;
|
237 | } else {
|
238 |
|
239 |
|
240 |
|
241 |
|
242 |
|
243 | var didFindChild = false;
|
244 | var _child = parentA.child;
|
245 |
|
246 | while (_child) {
|
247 | if (_child === a) {
|
248 | didFindChild = true;
|
249 | a = parentA;
|
250 | b = parentB;
|
251 | break;
|
252 | }
|
253 |
|
254 | if (_child === b) {
|
255 | didFindChild = true;
|
256 | b = parentA;
|
257 | a = parentB;
|
258 | break;
|
259 | }
|
260 |
|
261 | _child = _child.sibling;
|
262 | }
|
263 |
|
264 | if (!didFindChild) {
|
265 |
|
266 | _child = parentB.child;
|
267 |
|
268 | while (_child) {
|
269 | if (_child === a) {
|
270 | didFindChild = true;
|
271 | a = parentB;
|
272 | b = parentA;
|
273 | break;
|
274 | }
|
275 |
|
276 | if (_child === b) {
|
277 | didFindChild = true;
|
278 | b = parentB;
|
279 | a = parentA;
|
280 | break;
|
281 | }
|
282 |
|
283 | _child = _child.sibling;
|
284 | }
|
285 |
|
286 | if (!didFindChild) {
|
287 | throw new Error('Child was not found in either parent set. This indicates a bug ' + 'in React related to the return pointer. Please file an issue.');
|
288 | }
|
289 | }
|
290 | }
|
291 |
|
292 | if (a.alternate !== b) {
|
293 | throw new Error("Return fibers should always be each others' alternates. " + 'This error is likely caused by a bug in React. Please file an issue.');
|
294 | }
|
295 | }
|
296 |
|
297 |
|
298 |
|
299 | if (a.tag !== HostRoot) {
|
300 | throw new Error('Unable to find node on an unmounted component.');
|
301 | }
|
302 |
|
303 | if (a.stateNode.current === a) {
|
304 |
|
305 | return fiber;
|
306 | }
|
307 |
|
308 |
|
309 | return alternate;
|
310 | }
|
311 |
|
312 | var assign = Object.assign;
|
313 |
|
314 |
|
315 |
|
316 |
|
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 | function getEventCharCode(nativeEvent) {
|
325 | var charCode;
|
326 | var keyCode = nativeEvent.keyCode;
|
327 |
|
328 | if ('charCode' in nativeEvent) {
|
329 | charCode = nativeEvent.charCode;
|
330 |
|
331 | if (charCode === 0 && keyCode === 13) {
|
332 | charCode = 13;
|
333 | }
|
334 | } else {
|
335 |
|
336 | charCode = keyCode;
|
337 | }
|
338 |
|
339 |
|
340 |
|
341 | if (charCode === 10) {
|
342 | charCode = 13;
|
343 | }
|
344 |
|
345 |
|
346 |
|
347 | if (charCode >= 32 || charCode === 13) {
|
348 | return charCode;
|
349 | }
|
350 |
|
351 | return 0;
|
352 | }
|
353 |
|
354 | function functionThatReturnsTrue() {
|
355 | return true;
|
356 | }
|
357 |
|
358 | function functionThatReturnsFalse() {
|
359 | return false;
|
360 | }
|
361 |
|
362 |
|
363 |
|
364 | function createSyntheticEvent(Interface) {
|
365 | |
366 |
|
367 |
|
368 |
|
369 |
|
370 |
|
371 |
|
372 |
|
373 |
|
374 |
|
375 |
|
376 |
|
377 |
|
378 | function SyntheticBaseEvent(reactName, reactEventType, targetInst, nativeEvent, nativeEventTarget) {
|
379 | this._reactName = reactName;
|
380 | this._targetInst = targetInst;
|
381 | this.type = reactEventType;
|
382 | this.nativeEvent = nativeEvent;
|
383 | this.target = nativeEventTarget;
|
384 | this.currentTarget = null;
|
385 |
|
386 | for (var _propName in Interface) {
|
387 | if (!Interface.hasOwnProperty(_propName)) {
|
388 | continue;
|
389 | }
|
390 |
|
391 | var normalize = Interface[_propName];
|
392 |
|
393 | if (normalize) {
|
394 | this[_propName] = normalize(nativeEvent);
|
395 | } else {
|
396 | this[_propName] = nativeEvent[_propName];
|
397 | }
|
398 | }
|
399 |
|
400 | var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
|
401 |
|
402 | if (defaultPrevented) {
|
403 | this.isDefaultPrevented = functionThatReturnsTrue;
|
404 | } else {
|
405 | this.isDefaultPrevented = functionThatReturnsFalse;
|
406 | }
|
407 |
|
408 | this.isPropagationStopped = functionThatReturnsFalse;
|
409 | return this;
|
410 | }
|
411 |
|
412 | assign(SyntheticBaseEvent.prototype, {
|
413 | preventDefault: function () {
|
414 | this.defaultPrevented = true;
|
415 | var event = this.nativeEvent;
|
416 |
|
417 | if (!event) {
|
418 | return;
|
419 | }
|
420 |
|
421 | if (event.preventDefault) {
|
422 | event.preventDefault();
|
423 | } else if (typeof event.returnValue !== 'unknown') {
|
424 | event.returnValue = false;
|
425 | }
|
426 |
|
427 | this.isDefaultPrevented = functionThatReturnsTrue;
|
428 | },
|
429 | stopPropagation: function () {
|
430 | var event = this.nativeEvent;
|
431 |
|
432 | if (!event) {
|
433 | return;
|
434 | }
|
435 |
|
436 | if (event.stopPropagation) {
|
437 | event.stopPropagation();
|
438 | } else if (typeof event.cancelBubble !== 'unknown') {
|
439 |
|
440 |
|
441 |
|
442 |
|
443 |
|
444 | event.cancelBubble = true;
|
445 | }
|
446 |
|
447 | this.isPropagationStopped = functionThatReturnsTrue;
|
448 | },
|
449 |
|
450 | |
451 |
|
452 |
|
453 |
|
454 |
|
455 | persist: function () {
|
456 | },
|
457 |
|
458 | |
459 |
|
460 |
|
461 |
|
462 |
|
463 | isPersistent: functionThatReturnsTrue
|
464 | });
|
465 | return SyntheticBaseEvent;
|
466 | }
|
467 |
|
468 |
|
469 |
|
470 |
|
471 |
|
472 |
|
473 | var EventInterface = {
|
474 | eventPhase: 0,
|
475 | bubbles: 0,
|
476 | cancelable: 0,
|
477 | timeStamp: function (event) {
|
478 | return event.timeStamp || Date.now();
|
479 | },
|
480 | defaultPrevented: 0,
|
481 | isTrusted: 0
|
482 | };
|
483 | var SyntheticEvent = createSyntheticEvent(EventInterface);
|
484 |
|
485 | var UIEventInterface = assign({}, EventInterface, {
|
486 | view: 0,
|
487 | detail: 0
|
488 | });
|
489 |
|
490 | var SyntheticUIEvent = createSyntheticEvent(UIEventInterface);
|
491 | var lastMovementX;
|
492 | var lastMovementY;
|
493 | var lastMouseEvent;
|
494 |
|
495 | function updateMouseMovementPolyfillState(event) {
|
496 | if (event !== lastMouseEvent) {
|
497 | if (lastMouseEvent && event.type === 'mousemove') {
|
498 | lastMovementX = event.screenX - lastMouseEvent.screenX;
|
499 | lastMovementY = event.screenY - lastMouseEvent.screenY;
|
500 | } else {
|
501 | lastMovementX = 0;
|
502 | lastMovementY = 0;
|
503 | }
|
504 |
|
505 | lastMouseEvent = event;
|
506 | }
|
507 | }
|
508 |
|
509 |
|
510 |
|
511 |
|
512 |
|
513 |
|
514 | var MouseEventInterface = assign({}, UIEventInterface, {
|
515 | screenX: 0,
|
516 | screenY: 0,
|
517 | clientX: 0,
|
518 | clientY: 0,
|
519 | pageX: 0,
|
520 | pageY: 0,
|
521 | ctrlKey: 0,
|
522 | shiftKey: 0,
|
523 | altKey: 0,
|
524 | metaKey: 0,
|
525 | getModifierState: getEventModifierState,
|
526 | button: 0,
|
527 | buttons: 0,
|
528 | relatedTarget: function (event) {
|
529 | if (event.relatedTarget === undefined) return event.fromElement === event.srcElement ? event.toElement : event.fromElement;
|
530 | return event.relatedTarget;
|
531 | },
|
532 | movementX: function (event) {
|
533 | if ('movementX' in event) {
|
534 | return event.movementX;
|
535 | }
|
536 |
|
537 | updateMouseMovementPolyfillState(event);
|
538 | return lastMovementX;
|
539 | },
|
540 | movementY: function (event) {
|
541 | if ('movementY' in event) {
|
542 | return event.movementY;
|
543 | }
|
544 |
|
545 |
|
546 |
|
547 |
|
548 | return lastMovementY;
|
549 | }
|
550 | });
|
551 |
|
552 | var SyntheticMouseEvent = createSyntheticEvent(MouseEventInterface);
|
553 |
|
554 |
|
555 |
|
556 |
|
557 |
|
558 | var DragEventInterface = assign({}, MouseEventInterface, {
|
559 | dataTransfer: 0
|
560 | });
|
561 |
|
562 | var SyntheticDragEvent = createSyntheticEvent(DragEventInterface);
|
563 |
|
564 |
|
565 |
|
566 |
|
567 |
|
568 | var FocusEventInterface = assign({}, UIEventInterface, {
|
569 | relatedTarget: 0
|
570 | });
|
571 |
|
572 | var SyntheticFocusEvent = createSyntheticEvent(FocusEventInterface);
|
573 |
|
574 |
|
575 |
|
576 |
|
577 |
|
578 |
|
579 | var AnimationEventInterface = assign({}, EventInterface, {
|
580 | animationName: 0,
|
581 | elapsedTime: 0,
|
582 | pseudoElement: 0
|
583 | });
|
584 |
|
585 | var SyntheticAnimationEvent = createSyntheticEvent(AnimationEventInterface);
|
586 |
|
587 |
|
588 |
|
589 |
|
590 |
|
591 | var ClipboardEventInterface = assign({}, EventInterface, {
|
592 | clipboardData: function (event) {
|
593 | return 'clipboardData' in event ? event.clipboardData : window.clipboardData;
|
594 | }
|
595 | });
|
596 |
|
597 | var SyntheticClipboardEvent = createSyntheticEvent(ClipboardEventInterface);
|
598 |
|
599 |
|
600 |
|
601 |
|
602 |
|
603 | var CompositionEventInterface = assign({}, EventInterface, {
|
604 | data: 0
|
605 | });
|
606 |
|
607 | var SyntheticCompositionEvent = createSyntheticEvent(CompositionEventInterface);
|
608 |
|
609 |
|
610 |
|
611 |
|
612 |
|
613 | var normalizeKey = {
|
614 | Esc: 'Escape',
|
615 | Spacebar: ' ',
|
616 | Left: 'ArrowLeft',
|
617 | Up: 'ArrowUp',
|
618 | Right: 'ArrowRight',
|
619 | Down: 'ArrowDown',
|
620 | Del: 'Delete',
|
621 | Win: 'OS',
|
622 | Menu: 'ContextMenu',
|
623 | Apps: 'ContextMenu',
|
624 | Scroll: 'ScrollLock',
|
625 | MozPrintableKey: 'Unidentified'
|
626 | };
|
627 |
|
628 |
|
629 |
|
630 |
|
631 |
|
632 |
|
633 | var translateToKey = {
|
634 | '8': 'Backspace',
|
635 | '9': 'Tab',
|
636 | '12': 'Clear',
|
637 | '13': 'Enter',
|
638 | '16': 'Shift',
|
639 | '17': 'Control',
|
640 | '18': 'Alt',
|
641 | '19': 'Pause',
|
642 | '20': 'CapsLock',
|
643 | '27': 'Escape',
|
644 | '32': ' ',
|
645 | '33': 'PageUp',
|
646 | '34': 'PageDown',
|
647 | '35': 'End',
|
648 | '36': 'Home',
|
649 | '37': 'ArrowLeft',
|
650 | '38': 'ArrowUp',
|
651 | '39': 'ArrowRight',
|
652 | '40': 'ArrowDown',
|
653 | '45': 'Insert',
|
654 | '46': 'Delete',
|
655 | '112': 'F1',
|
656 | '113': 'F2',
|
657 | '114': 'F3',
|
658 | '115': 'F4',
|
659 | '116': 'F5',
|
660 | '117': 'F6',
|
661 | '118': 'F7',
|
662 | '119': 'F8',
|
663 | '120': 'F9',
|
664 | '121': 'F10',
|
665 | '122': 'F11',
|
666 | '123': 'F12',
|
667 | '144': 'NumLock',
|
668 | '145': 'ScrollLock',
|
669 | '224': 'Meta'
|
670 | };
|
671 |
|
672 |
|
673 |
|
674 |
|
675 |
|
676 | function getEventKey(nativeEvent) {
|
677 | if (nativeEvent.key) {
|
678 |
|
679 |
|
680 |
|
681 |
|
682 | var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
|
683 |
|
684 | if (key !== 'Unidentified') {
|
685 | return key;
|
686 | }
|
687 | }
|
688 |
|
689 |
|
690 | if (nativeEvent.type === 'keypress') {
|
691 | var charCode = getEventCharCode(nativeEvent);
|
692 |
|
693 |
|
694 | return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
|
695 | }
|
696 |
|
697 | if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
|
698 |
|
699 |
|
700 | return translateToKey[nativeEvent.keyCode] || 'Unidentified';
|
701 | }
|
702 |
|
703 | return '';
|
704 | }
|
705 |
|
706 |
|
707 |
|
708 |
|
709 |
|
710 |
|
711 | var modifierKeyToProp = {
|
712 | Alt: 'altKey',
|
713 | Control: 'ctrlKey',
|
714 | Meta: 'metaKey',
|
715 | Shift: 'shiftKey'
|
716 | };
|
717 |
|
718 |
|
719 |
|
720 | function modifierStateGetter(keyArg) {
|
721 | var syntheticEvent = this;
|
722 | var nativeEvent = syntheticEvent.nativeEvent;
|
723 |
|
724 | if (nativeEvent.getModifierState) {
|
725 | return nativeEvent.getModifierState(keyArg);
|
726 | }
|
727 |
|
728 | var keyProp = modifierKeyToProp[keyArg];
|
729 | return keyProp ? !!nativeEvent[keyProp] : false;
|
730 | }
|
731 |
|
732 | function getEventModifierState(nativeEvent) {
|
733 | return modifierStateGetter;
|
734 | }
|
735 |
|
736 |
|
737 |
|
738 |
|
739 |
|
740 |
|
741 | var KeyboardEventInterface = assign({}, UIEventInterface, {
|
742 | key: getEventKey,
|
743 | code: 0,
|
744 | location: 0,
|
745 | ctrlKey: 0,
|
746 | shiftKey: 0,
|
747 | altKey: 0,
|
748 | metaKey: 0,
|
749 | repeat: 0,
|
750 | locale: 0,
|
751 | getModifierState: getEventModifierState,
|
752 |
|
753 | charCode: function (event) {
|
754 |
|
755 |
|
756 |
|
757 |
|
758 | if (event.type === 'keypress') {
|
759 | return getEventCharCode(event);
|
760 | }
|
761 |
|
762 | return 0;
|
763 | },
|
764 | keyCode: function (event) {
|
765 |
|
766 |
|
767 |
|
768 |
|
769 |
|
770 |
|
771 | if (event.type === 'keydown' || event.type === 'keyup') {
|
772 | return event.keyCode;
|
773 | }
|
774 |
|
775 | return 0;
|
776 | },
|
777 | which: function (event) {
|
778 |
|
779 |
|
780 | if (event.type === 'keypress') {
|
781 | return getEventCharCode(event);
|
782 | }
|
783 |
|
784 | if (event.type === 'keydown' || event.type === 'keyup') {
|
785 | return event.keyCode;
|
786 | }
|
787 |
|
788 | return 0;
|
789 | }
|
790 | });
|
791 |
|
792 | var SyntheticKeyboardEvent = createSyntheticEvent(KeyboardEventInterface);
|
793 |
|
794 |
|
795 |
|
796 |
|
797 |
|
798 | var PointerEventInterface = assign({}, MouseEventInterface, {
|
799 | pointerId: 0,
|
800 | width: 0,
|
801 | height: 0,
|
802 | pressure: 0,
|
803 | tangentialPressure: 0,
|
804 | tiltX: 0,
|
805 | tiltY: 0,
|
806 | twist: 0,
|
807 | pointerType: 0,
|
808 | isPrimary: 0
|
809 | });
|
810 |
|
811 | var SyntheticPointerEvent = createSyntheticEvent(PointerEventInterface);
|
812 |
|
813 |
|
814 |
|
815 |
|
816 |
|
817 | var TouchEventInterface = assign({}, UIEventInterface, {
|
818 | touches: 0,
|
819 | targetTouches: 0,
|
820 | changedTouches: 0,
|
821 | altKey: 0,
|
822 | metaKey: 0,
|
823 | ctrlKey: 0,
|
824 | shiftKey: 0,
|
825 | getModifierState: getEventModifierState
|
826 | });
|
827 |
|
828 | var SyntheticTouchEvent = createSyntheticEvent(TouchEventInterface);
|
829 |
|
830 |
|
831 |
|
832 |
|
833 |
|
834 |
|
835 | var TransitionEventInterface = assign({}, EventInterface, {
|
836 | propertyName: 0,
|
837 | elapsedTime: 0,
|
838 | pseudoElement: 0
|
839 | });
|
840 |
|
841 | var SyntheticTransitionEvent = createSyntheticEvent(TransitionEventInterface);
|
842 |
|
843 |
|
844 |
|
845 |
|
846 |
|
847 | var WheelEventInterface = assign({}, MouseEventInterface, {
|
848 | deltaX: function (event) {
|
849 | return 'deltaX' in event ? event.deltaX :
|
850 | 'wheelDeltaX' in event ? -event.wheelDeltaX : 0;
|
851 | },
|
852 | deltaY: function (event) {
|
853 | return 'deltaY' in event ? event.deltaY :
|
854 | 'wheelDeltaY' in event ? -event.wheelDeltaY :
|
855 | 'wheelDelta' in event ? -event.wheelDelta : 0;
|
856 | },
|
857 | deltaZ: 0,
|
858 |
|
859 |
|
860 |
|
861 |
|
862 | deltaMode: 0
|
863 | });
|
864 |
|
865 | var SyntheticWheelEvent = createSyntheticEvent(WheelEventInterface);
|
866 |
|
867 |
|
868 |
|
869 |
|
870 | var ELEMENT_NODE = 1;
|
871 |
|
872 | function invokeGuardedCallbackProd(name, func, context, a, b, c, d, e, f) {
|
873 | var funcArgs = Array.prototype.slice.call(arguments, 3);
|
874 |
|
875 | try {
|
876 | func.apply(context, funcArgs);
|
877 | } catch (error) {
|
878 | this.onError(error);
|
879 | }
|
880 | }
|
881 |
|
882 | var invokeGuardedCallbackImpl = invokeGuardedCallbackProd;
|
883 |
|
884 | {
|
885 |
|
886 |
|
887 |
|
888 |
|
889 |
|
890 |
|
891 |
|
892 |
|
893 |
|
894 |
|
895 |
|
896 |
|
897 |
|
898 |
|
899 |
|
900 |
|
901 |
|
902 |
|
903 |
|
904 |
|
905 | if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
|
906 | var fakeNode = document.createElement('react');
|
907 |
|
908 | invokeGuardedCallbackImpl = function invokeGuardedCallbackDev(name, func, context, a, b, c, d, e, f) {
|
909 |
|
910 |
|
911 |
|
912 |
|
913 | if (typeof document === 'undefined' || document === null) {
|
914 | throw new Error('The `document` global was defined when React was initialized, but is not ' + 'defined anymore. This can happen in a test environment if a component ' + 'schedules an update from an asynchronous callback, but the test has already ' + 'finished running. To solve this, you can either unmount the component at ' + 'the end of your test (and ensure that any asynchronous operations get ' + 'canceled in `componentWillUnmount`), or you can change the test itself ' + 'to be asynchronous.');
|
915 | }
|
916 |
|
917 | var evt = document.createEvent('Event');
|
918 | var didCall = false;
|
919 |
|
920 |
|
921 |
|
922 |
|
923 |
|
924 |
|
925 | var didError = true;
|
926 |
|
927 |
|
928 |
|
929 | var windowEvent = window.event;
|
930 |
|
931 |
|
932 | var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event');
|
933 |
|
934 | function restoreAfterDispatch() {
|
935 |
|
936 |
|
937 |
|
938 |
|
939 | fakeNode.removeEventListener(evtType, callCallback, false);
|
940 |
|
941 |
|
942 |
|
943 |
|
944 | if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
|
945 | window.event = windowEvent;
|
946 | }
|
947 | }
|
948 |
|
949 |
|
950 |
|
951 |
|
952 | var funcArgs = Array.prototype.slice.call(arguments, 3);
|
953 |
|
954 | function callCallback() {
|
955 | didCall = true;
|
956 | restoreAfterDispatch();
|
957 | func.apply(context, funcArgs);
|
958 | didError = false;
|
959 | }
|
960 |
|
961 |
|
962 |
|
963 |
|
964 |
|
965 |
|
966 |
|
967 |
|
968 |
|
969 |
|
970 |
|
971 |
|
972 | var error;
|
973 |
|
974 | var didSetError = false;
|
975 | var isCrossOriginError = false;
|
976 |
|
977 | function handleWindowError(event) {
|
978 | error = event.error;
|
979 | didSetError = true;
|
980 |
|
981 | if (error === null && event.colno === 0 && event.lineno === 0) {
|
982 | isCrossOriginError = true;
|
983 | }
|
984 |
|
985 | if (event.defaultPrevented) {
|
986 |
|
987 |
|
988 |
|
989 | if (error != null && typeof error === 'object') {
|
990 | try {
|
991 | error._suppressLogging = true;
|
992 | } catch (inner) {
|
993 | }
|
994 | }
|
995 | }
|
996 | }
|
997 |
|
998 |
|
999 | var evtType = "react-" + (name ? name : 'invokeguardedcallback');
|
1000 |
|
1001 | window.addEventListener('error', handleWindowError);
|
1002 | fakeNode.addEventListener(evtType, callCallback, false);
|
1003 |
|
1004 |
|
1005 | evt.initEvent(evtType, false, false);
|
1006 | fakeNode.dispatchEvent(evt);
|
1007 |
|
1008 | if (windowEventDescriptor) {
|
1009 | Object.defineProperty(window, 'event', windowEventDescriptor);
|
1010 | }
|
1011 |
|
1012 | if (didCall && didError) {
|
1013 | if (!didSetError) {
|
1014 |
|
1015 |
|
1016 | error = new Error('An error was thrown inside one of your components, but React ' + "doesn't know what it was. This is likely due to browser " + 'flakiness. React does its best to preserve the "Pause on ' + 'exceptions" behavior of the DevTools, which requires some ' + "DEV-mode only tricks. It's possible that these don't work in " + 'your browser. Try triggering the error in production mode, ' + 'or switching to a modern browser. If you suspect that this is ' + 'actually an issue with React, please file an issue.');
|
1017 | } else if (isCrossOriginError) {
|
1018 |
|
1019 | error = new Error("A cross-origin error was thrown. React doesn't have access to " + 'the actual error object in development. ' + 'See https://reactjs.org/link/crossorigin-error for more information.');
|
1020 | }
|
1021 |
|
1022 | this.onError(error);
|
1023 | }
|
1024 |
|
1025 |
|
1026 | window.removeEventListener('error', handleWindowError);
|
1027 |
|
1028 | if (!didCall) {
|
1029 |
|
1030 |
|
1031 |
|
1032 |
|
1033 | restoreAfterDispatch();
|
1034 | return invokeGuardedCallbackProd.apply(this, arguments);
|
1035 | }
|
1036 | };
|
1037 | }
|
1038 | }
|
1039 |
|
1040 | var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
|
1041 |
|
1042 | var hasError = false;
|
1043 | var caughtError = null;
|
1044 |
|
1045 | var hasRethrowError = false;
|
1046 | var rethrowError = null;
|
1047 | var reporter = {
|
1048 | onError: function (error) {
|
1049 | hasError = true;
|
1050 | caughtError = error;
|
1051 | }
|
1052 | };
|
1053 |
|
1054 |
|
1055 |
|
1056 |
|
1057 |
|
1058 |
|
1059 |
|
1060 |
|
1061 |
|
1062 |
|
1063 |
|
1064 |
|
1065 |
|
1066 |
|
1067 | function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
|
1068 | hasError = false;
|
1069 | caughtError = null;
|
1070 | invokeGuardedCallbackImpl$1.apply(reporter, arguments);
|
1071 | }
|
1072 |
|
1073 |
|
1074 |
|
1075 |
|
1076 |
|
1077 |
|
1078 |
|
1079 |
|
1080 |
|
1081 |
|
1082 |
|
1083 | function invokeGuardedCallbackAndCatchFirstError(name, func, context, a, b, c, d, e, f) {
|
1084 | invokeGuardedCallback.apply(this, arguments);
|
1085 |
|
1086 | if (hasError) {
|
1087 | var error = clearCaughtError();
|
1088 |
|
1089 | if (!hasRethrowError) {
|
1090 | hasRethrowError = true;
|
1091 | rethrowError = error;
|
1092 | }
|
1093 | }
|
1094 | }
|
1095 |
|
1096 |
|
1097 |
|
1098 |
|
1099 |
|
1100 | function rethrowCaughtError() {
|
1101 | if (hasRethrowError) {
|
1102 | var error = rethrowError;
|
1103 | hasRethrowError = false;
|
1104 | rethrowError = null;
|
1105 | throw error;
|
1106 | }
|
1107 | }
|
1108 | function clearCaughtError() {
|
1109 | if (hasError) {
|
1110 | var error = caughtError;
|
1111 | hasError = false;
|
1112 | caughtError = null;
|
1113 | return error;
|
1114 | } else {
|
1115 | throw new Error('clearCaughtError was called but no error was captured. This error ' + 'is likely caused by a bug in React. Please file an issue.');
|
1116 | }
|
1117 | }
|
1118 |
|
1119 | var isArrayImpl = Array.isArray;
|
1120 |
|
1121 | function isArray(a) {
|
1122 | return isArrayImpl(a);
|
1123 | }
|
1124 |
|
1125 | var SecretInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
1126 | var EventInternals = SecretInternals.Events;
|
1127 | var getInstanceFromNode = EventInternals[0];
|
1128 | var getNodeFromInstance = EventInternals[1];
|
1129 | var getFiberCurrentPropsFromNode = EventInternals[2];
|
1130 | var enqueueStateRestore = EventInternals[3];
|
1131 | var restoreStateIfNeeded = EventInternals[4];
|
1132 | var act = React.unstable_act;
|
1133 |
|
1134 | function Event(suffix) {}
|
1135 |
|
1136 | var hasWarnedAboutDeprecatedMockComponent = false;
|
1137 |
|
1138 |
|
1139 |
|
1140 |
|
1141 | function findAllInRenderedFiberTreeInternal(fiber, test) {
|
1142 | if (!fiber) {
|
1143 | return [];
|
1144 | }
|
1145 |
|
1146 | var currentParent = findCurrentFiberUsingSlowPath(fiber);
|
1147 |
|
1148 | if (!currentParent) {
|
1149 | return [];
|
1150 | }
|
1151 |
|
1152 | var node = currentParent;
|
1153 | var ret = [];
|
1154 |
|
1155 | while (true) {
|
1156 | if (node.tag === HostComponent || node.tag === HostText || node.tag === ClassComponent || node.tag === FunctionComponent) {
|
1157 | var publicInst = node.stateNode;
|
1158 |
|
1159 | if (test(publicInst)) {
|
1160 | ret.push(publicInst);
|
1161 | }
|
1162 | }
|
1163 |
|
1164 | if (node.child) {
|
1165 | node.child.return = node;
|
1166 | node = node.child;
|
1167 | continue;
|
1168 | }
|
1169 |
|
1170 | if (node === currentParent) {
|
1171 | return ret;
|
1172 | }
|
1173 |
|
1174 | while (!node.sibling) {
|
1175 | if (!node.return || node.return === currentParent) {
|
1176 | return ret;
|
1177 | }
|
1178 |
|
1179 | node = node.return;
|
1180 | }
|
1181 |
|
1182 | node.sibling.return = node.return;
|
1183 | node = node.sibling;
|
1184 | }
|
1185 | }
|
1186 |
|
1187 | function validateClassInstance(inst, methodName) {
|
1188 | if (!inst) {
|
1189 |
|
1190 | return;
|
1191 | }
|
1192 |
|
1193 | if (get(inst)) {
|
1194 |
|
1195 | return;
|
1196 | }
|
1197 |
|
1198 | var received;
|
1199 | var stringified = String(inst);
|
1200 |
|
1201 | if (isArray(inst)) {
|
1202 | received = 'an array';
|
1203 | } else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
|
1204 | received = 'a DOM node';
|
1205 | } else if (stringified === '[object Object]') {
|
1206 | received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
|
1207 | } else {
|
1208 | received = stringified;
|
1209 | }
|
1210 |
|
1211 | throw new Error(methodName + "(...): the first argument must be a React class instance. " + ("Instead received: " + received + "."));
|
1212 | }
|
1213 |
|
1214 |
|
1215 |
|
1216 |
|
1217 |
|
1218 |
|
1219 |
|
1220 |
|
1221 |
|
1222 |
|
1223 |
|
1224 | function renderIntoDocument(element) {
|
1225 | var div = document.createElement('div');
|
1226 |
|
1227 |
|
1228 |
|
1229 |
|
1230 |
|
1231 | return ReactDOM.render(element, div);
|
1232 | }
|
1233 |
|
1234 | function isElement(element) {
|
1235 | return React.isValidElement(element);
|
1236 | }
|
1237 |
|
1238 | function isElementOfType(inst, convenienceConstructor) {
|
1239 | return React.isValidElement(inst) && inst.type === convenienceConstructor;
|
1240 | }
|
1241 |
|
1242 | function isDOMComponent(inst) {
|
1243 | return !!(inst && inst.nodeType === ELEMENT_NODE && inst.tagName);
|
1244 | }
|
1245 |
|
1246 | function isDOMComponentElement(inst) {
|
1247 | return !!(inst && React.isValidElement(inst) && !!inst.tagName);
|
1248 | }
|
1249 |
|
1250 | function isCompositeComponent(inst) {
|
1251 | if (isDOMComponent(inst)) {
|
1252 |
|
1253 |
|
1254 | return false;
|
1255 | }
|
1256 |
|
1257 | return inst != null && typeof inst.render === 'function' && typeof inst.setState === 'function';
|
1258 | }
|
1259 |
|
1260 | function isCompositeComponentWithType(inst, type) {
|
1261 | if (!isCompositeComponent(inst)) {
|
1262 | return false;
|
1263 | }
|
1264 |
|
1265 | var internalInstance = get(inst);
|
1266 | var constructor = internalInstance.type;
|
1267 | return constructor === type;
|
1268 | }
|
1269 |
|
1270 | function findAllInRenderedTree(inst, test) {
|
1271 | validateClassInstance(inst, 'findAllInRenderedTree');
|
1272 |
|
1273 | if (!inst) {
|
1274 | return [];
|
1275 | }
|
1276 |
|
1277 | var internalInstance = get(inst);
|
1278 | return findAllInRenderedFiberTreeInternal(internalInstance, test);
|
1279 | }
|
1280 | /**
|
1281 | * Finds all instances of components in the rendered tree that are DOM
|
1282 | * components with the class name matching `className`.
|
1283 | * @return {array} an array of all the matches.
|
1284 | */
|
1285 |
|
1286 |
|
1287 | function scryRenderedDOMComponentsWithClass(root, classNames) {
|
1288 | validateClassInstance(root, 'scryRenderedDOMComponentsWithClass');
|
1289 | return findAllInRenderedTree(root, function (inst) {
|
1290 | if (isDOMComponent(inst)) {
|
1291 | var className = inst.className;
|
1292 |
|
1293 | if (typeof className !== 'string') {
|
1294 |
|
1295 | className = inst.getAttribute('class') || '';
|
1296 | }
|
1297 |
|
1298 | var classList = className.split(/\s+/);
|
1299 |
|
1300 | if (!isArray(classNames)) {
|
1301 | if (classNames === undefined) {
|
1302 | throw new Error('TestUtils.scryRenderedDOMComponentsWithClass expects a ' + 'className as a second argument.');
|
1303 | }
|
1304 |
|
1305 | classNames = classNames.split(/\s+/);
|
1306 | }
|
1307 |
|
1308 | return classNames.every(function (name) {
|
1309 | return classList.indexOf(name) !== -1;
|
1310 | });
|
1311 | }
|
1312 |
|
1313 | return false;
|
1314 | });
|
1315 | }
|
1316 |
|
1317 |
|
1318 |
|
1319 |
|
1320 |
|
1321 |
|
1322 |
|
1323 |
|
1324 | function findRenderedDOMComponentWithClass(root, className) {
|
1325 | validateClassInstance(root, 'findRenderedDOMComponentWithClass');
|
1326 | var all = scryRenderedDOMComponentsWithClass(root, className);
|
1327 |
|
1328 | if (all.length !== 1) {
|
1329 | throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for class:' + className);
|
1330 | }
|
1331 |
|
1332 | return all[0];
|
1333 | }
|
1334 |
|
1335 |
|
1336 |
|
1337 |
|
1338 |
|
1339 |
|
1340 |
|
1341 | function scryRenderedDOMComponentsWithTag(root, tagName) {
|
1342 | validateClassInstance(root, 'scryRenderedDOMComponentsWithTag');
|
1343 | return findAllInRenderedTree(root, function (inst) {
|
1344 | return isDOMComponent(inst) && inst.tagName.toUpperCase() === tagName.toUpperCase();
|
1345 | });
|
1346 | }
|
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 |
|
1352 |
|
1353 |
|
1354 |
|
1355 | function findRenderedDOMComponentWithTag(root, tagName) {
|
1356 | validateClassInstance(root, 'findRenderedDOMComponentWithTag');
|
1357 | var all = scryRenderedDOMComponentsWithTag(root, tagName);
|
1358 |
|
1359 | if (all.length !== 1) {
|
1360 | throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for tag:' + tagName);
|
1361 | }
|
1362 |
|
1363 | return all[0];
|
1364 | }
|
1365 |
|
1366 |
|
1367 |
|
1368 |
|
1369 |
|
1370 |
|
1371 | function scryRenderedComponentsWithType(root, componentType) {
|
1372 | validateClassInstance(root, 'scryRenderedComponentsWithType');
|
1373 | return findAllInRenderedTree(root, function (inst) {
|
1374 | return isCompositeComponentWithType(inst, componentType);
|
1375 | });
|
1376 | }
|
1377 |
|
1378 |
|
1379 |
|
1380 |
|
1381 |
|
1382 |
|
1383 |
|
1384 |
|
1385 | function findRenderedComponentWithType(root, componentType) {
|
1386 | validateClassInstance(root, 'findRenderedComponentWithType');
|
1387 | var all = scryRenderedComponentsWithType(root, componentType);
|
1388 |
|
1389 | if (all.length !== 1) {
|
1390 | throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for componentType:' + componentType);
|
1391 | }
|
1392 |
|
1393 | return all[0];
|
1394 | }
|
1395 |
|
1396 |
|
1397 |
|
1398 |
|
1399 |
|
1400 |
|
1401 |
|
1402 |
|
1403 |
|
1404 |
|
1405 |
|
1406 |
|
1407 |
|
1408 |
|
1409 |
|
1410 | function mockComponent(module, mockTagName) {
|
1411 | {
|
1412 | if (!hasWarnedAboutDeprecatedMockComponent) {
|
1413 | hasWarnedAboutDeprecatedMockComponent = true;
|
1414 |
|
1415 | warn('ReactTestUtils.mockComponent() is deprecated. ' + 'Use shallow rendering or jest.mock() instead.\n\n' + 'See https://reactjs.org/link/test-utils-mock-component for more information.');
|
1416 | }
|
1417 | }
|
1418 |
|
1419 | mockTagName = mockTagName || module.mockTagName || 'div';
|
1420 | module.prototype.render.mockImplementation(function () {
|
1421 | return React.createElement(mockTagName, null, this.props.children);
|
1422 | });
|
1423 | return this;
|
1424 | }
|
1425 |
|
1426 | function nativeTouchData(x, y) {
|
1427 | return {
|
1428 | touches: [{
|
1429 | pageX: x,
|
1430 | pageY: y
|
1431 | }]
|
1432 | };
|
1433 | }
|
1434 |
|
1435 |
|
1436 |
|
1437 |
|
1438 |
|
1439 |
|
1440 |
|
1441 |
|
1442 |
|
1443 |
|
1444 |
|
1445 | function executeDispatch(event, listener, inst) {
|
1446 | var type = event.type || 'unknown-event';
|
1447 | event.currentTarget = getNodeFromInstance(inst);
|
1448 | invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
|
1449 | event.currentTarget = null;
|
1450 | }
|
1451 |
|
1452 |
|
1453 |
|
1454 |
|
1455 |
|
1456 | function executeDispatchesInOrder(event) {
|
1457 | var dispatchListeners = event._dispatchListeners;
|
1458 | var dispatchInstances = event._dispatchInstances;
|
1459 |
|
1460 | if (isArray(dispatchListeners)) {
|
1461 | for (var i = 0; i < dispatchListeners.length; i++) {
|
1462 | if (event.isPropagationStopped()) {
|
1463 | break;
|
1464 | }
|
1465 |
|
1466 |
|
1467 | executeDispatch(event, dispatchListeners[i], dispatchInstances[i]);
|
1468 | }
|
1469 | } else if (dispatchListeners) {
|
1470 | executeDispatch(event, dispatchListeners, dispatchInstances);
|
1471 | }
|
1472 |
|
1473 | event._dispatchListeners = null;
|
1474 | event._dispatchInstances = null;
|
1475 | }
|
1476 |
|
1477 |
|
1478 |
|
1479 |
|
1480 |
|
1481 |
|
1482 |
|
1483 |
|
1484 | var executeDispatchesAndRelease = function (event) {
|
1485 | if (event) {
|
1486 | executeDispatchesInOrder(event);
|
1487 |
|
1488 | if (!event.isPersistent()) {
|
1489 | event.constructor.release(event);
|
1490 | }
|
1491 | }
|
1492 | };
|
1493 |
|
1494 | function isInteractive(tag) {
|
1495 | return tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea';
|
1496 | }
|
1497 |
|
1498 | function getParent(inst) {
|
1499 | do {
|
1500 | inst = inst.return;
|
1501 |
|
1502 |
|
1503 |
|
1504 |
|
1505 | } while (inst && inst.tag !== HostComponent);
|
1506 |
|
1507 | if (inst) {
|
1508 | return inst;
|
1509 | }
|
1510 |
|
1511 | return null;
|
1512 | }
|
1513 |
|
1514 |
|
1515 |
|
1516 |
|
1517 |
|
1518 | function traverseTwoPhase(inst, fn, arg) {
|
1519 | var path = [];
|
1520 |
|
1521 | while (inst) {
|
1522 | path.push(inst);
|
1523 | inst = getParent(inst);
|
1524 | }
|
1525 |
|
1526 | var i;
|
1527 |
|
1528 | for (i = path.length; i-- > 0;) {
|
1529 | fn(path[i], 'captured', arg);
|
1530 | }
|
1531 |
|
1532 | for (i = 0; i < path.length; i++) {
|
1533 | fn(path[i], 'bubbled', arg);
|
1534 | }
|
1535 | }
|
1536 |
|
1537 | function shouldPreventMouseEvent(name, type, props) {
|
1538 | switch (name) {
|
1539 | case 'onClick':
|
1540 | case 'onClickCapture':
|
1541 | case 'onDoubleClick':
|
1542 | case 'onDoubleClickCapture':
|
1543 | case 'onMouseDown':
|
1544 | case 'onMouseDownCapture':
|
1545 | case 'onMouseMove':
|
1546 | case 'onMouseMoveCapture':
|
1547 | case 'onMouseUp':
|
1548 | case 'onMouseUpCapture':
|
1549 | case 'onMouseEnter':
|
1550 | return !!(props.disabled && isInteractive(type));
|
1551 |
|
1552 | default:
|
1553 | return false;
|
1554 | }
|
1555 | }
|
1556 |
|
1557 |
|
1558 |
|
1559 |
|
1560 |
|
1561 |
|
1562 |
|
1563 | function getListener(inst, registrationName) {
|
1564 |
|
1565 |
|
1566 | var stateNode = inst.stateNode;
|
1567 |
|
1568 | if (!stateNode) {
|
1569 |
|
1570 | return null;
|
1571 | }
|
1572 |
|
1573 | var props = getFiberCurrentPropsFromNode(stateNode);
|
1574 |
|
1575 | if (!props) {
|
1576 |
|
1577 | return null;
|
1578 | }
|
1579 |
|
1580 | var listener = props[registrationName];
|
1581 |
|
1582 | if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
|
1583 | return null;
|
1584 | }
|
1585 |
|
1586 | if (listener && typeof listener !== 'function') {
|
1587 | throw new Error("Expected `" + registrationName + "` listener to be a function, instead got a value of `" + typeof listener + "` type.");
|
1588 | }
|
1589 |
|
1590 | return listener;
|
1591 | }
|
1592 |
|
1593 | function listenerAtPhase(inst, event, propagationPhase) {
|
1594 | var registrationName = event._reactName;
|
1595 |
|
1596 | if (propagationPhase === 'captured') {
|
1597 | registrationName += 'Capture';
|
1598 | }
|
1599 |
|
1600 | return getListener(inst, registrationName);
|
1601 | }
|
1602 |
|
1603 | function accumulateDispatches(inst, ignoredDirection, event) {
|
1604 | if (inst && event && event._reactName) {
|
1605 | var registrationName = event._reactName;
|
1606 | var listener = getListener(inst, registrationName);
|
1607 |
|
1608 | if (listener) {
|
1609 | if (event._dispatchListeners == null) {
|
1610 | event._dispatchListeners = [];
|
1611 | }
|
1612 |
|
1613 | if (event._dispatchInstances == null) {
|
1614 | event._dispatchInstances = [];
|
1615 | }
|
1616 |
|
1617 | event._dispatchListeners.push(listener);
|
1618 |
|
1619 | event._dispatchInstances.push(inst);
|
1620 | }
|
1621 | }
|
1622 | }
|
1623 |
|
1624 | function accumulateDirectionalDispatches(inst, phase, event) {
|
1625 | {
|
1626 | if (!inst) {
|
1627 | error('Dispatching inst must not be null');
|
1628 | }
|
1629 | }
|
1630 |
|
1631 | var listener = listenerAtPhase(inst, event, phase);
|
1632 |
|
1633 | if (listener) {
|
1634 | if (event._dispatchListeners == null) {
|
1635 | event._dispatchListeners = [];
|
1636 | }
|
1637 |
|
1638 | if (event._dispatchInstances == null) {
|
1639 | event._dispatchInstances = [];
|
1640 | }
|
1641 |
|
1642 | event._dispatchListeners.push(listener);
|
1643 |
|
1644 | event._dispatchInstances.push(inst);
|
1645 | }
|
1646 | }
|
1647 |
|
1648 | function accumulateDirectDispatchesSingle(event) {
|
1649 | if (event && event._reactName) {
|
1650 | accumulateDispatches(event._targetInst, null, event);
|
1651 | }
|
1652 | }
|
1653 |
|
1654 | function accumulateTwoPhaseDispatchesSingle(event) {
|
1655 | if (event && event._reactName) {
|
1656 | traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
|
1657 | }
|
1658 | }
|
1659 |
|
1660 |
|
1661 | var Simulate = {};
|
1662 | var directDispatchEventTypes = new Set(['mouseEnter', 'mouseLeave', 'pointerEnter', 'pointerLeave']);
|
1663 |
|
1664 |
|
1665 |
|
1666 |
|
1667 |
|
1668 |
|
1669 |
|
1670 |
|
1671 |
|
1672 | function makeSimulator(eventType) {
|
1673 | return function (domNode, eventData) {
|
1674 | if (React.isValidElement(domNode)) {
|
1675 | throw new Error('TestUtils.Simulate expected a DOM node as the first argument but received ' + 'a React element. Pass the DOM node you wish to simulate the event on instead. ' + 'Note that TestUtils.Simulate will not work if you are using shallow rendering.');
|
1676 | }
|
1677 |
|
1678 | if (isCompositeComponent(domNode)) {
|
1679 | throw new Error('TestUtils.Simulate expected a DOM node as the first argument but received ' + 'a component instance. Pass the DOM node you wish to simulate the event on instead.');
|
1680 | }
|
1681 |
|
1682 | var reactName = 'on' + eventType[0].toUpperCase() + eventType.slice(1);
|
1683 | var fakeNativeEvent = new Event();
|
1684 | fakeNativeEvent.target = domNode;
|
1685 | fakeNativeEvent.type = eventType.toLowerCase();
|
1686 | var targetInst = getInstanceFromNode(domNode);
|
1687 | var event = new SyntheticEvent(reactName, fakeNativeEvent.type, targetInst, fakeNativeEvent, domNode);
|
1688 |
|
1689 |
|
1690 | event.persist();
|
1691 | assign(event, eventData);
|
1692 |
|
1693 | if (directDispatchEventTypes.has(eventType)) {
|
1694 | accumulateDirectDispatchesSingle(event);
|
1695 | } else {
|
1696 | accumulateTwoPhaseDispatchesSingle(event);
|
1697 | }
|
1698 |
|
1699 | ReactDOM.unstable_batchedUpdates(function () {
|
1700 |
|
1701 |
|
1702 | enqueueStateRestore(domNode);
|
1703 | executeDispatchesAndRelease(event);
|
1704 | rethrowCaughtError();
|
1705 | });
|
1706 | restoreStateIfNeeded();
|
1707 | };
|
1708 | }
|
1709 |
|
1710 |
|
1711 | var simulatedEventTypes = ['blur', 'cancel', 'click', 'close', 'contextMenu', 'copy', 'cut', 'auxClick', 'doubleClick', 'dragEnd', 'dragStart', 'drop', 'focus', 'input', 'invalid', 'keyDown', 'keyPress', 'keyUp', 'mouseDown', 'mouseUp', 'paste', 'pause', 'play', 'pointerCancel', 'pointerDown', 'pointerUp', 'rateChange', 'reset', 'resize', 'seeked', 'submit', 'touchCancel', 'touchEnd', 'touchStart', 'volumeChange', 'drag', 'dragEnter', 'dragExit', 'dragLeave', 'dragOver', 'mouseMove', 'mouseOut', 'mouseOver', 'pointerMove', 'pointerOut', 'pointerOver', 'scroll', 'toggle', 'touchMove', 'wheel', 'abort', 'animationEnd', 'animationIteration', 'animationStart', 'canPlay', 'canPlayThrough', 'durationChange', 'emptied', 'encrypted', 'ended', 'error', 'gotPointerCapture', 'load', 'loadedData', 'loadedMetadata', 'loadStart', 'lostPointerCapture', 'playing', 'progress', 'seeking', 'stalled', 'suspend', 'timeUpdate', 'transitionEnd', 'waiting', 'mouseEnter', 'mouseLeave', 'pointerEnter', 'pointerLeave', 'change', 'select', 'beforeInput', 'compositionEnd', 'compositionStart', 'compositionUpdate'];
|
1712 |
|
1713 | function buildSimulators() {
|
1714 | simulatedEventTypes.forEach(function (eventType) {
|
1715 | Simulate[eventType] = makeSimulator(eventType);
|
1716 | });
|
1717 | }
|
1718 |
|
1719 | buildSimulators();
|
1720 |
|
1721 | exports.Simulate = Simulate;
|
1722 | exports.act = act;
|
1723 | exports.findAllInRenderedTree = findAllInRenderedTree;
|
1724 | exports.findRenderedComponentWithType = findRenderedComponentWithType;
|
1725 | exports.findRenderedDOMComponentWithClass = findRenderedDOMComponentWithClass;
|
1726 | exports.findRenderedDOMComponentWithTag = findRenderedDOMComponentWithTag;
|
1727 | exports.isCompositeComponent = isCompositeComponent;
|
1728 | exports.isCompositeComponentWithType = isCompositeComponentWithType;
|
1729 | exports.isDOMComponent = isDOMComponent;
|
1730 | exports.isDOMComponentElement = isDOMComponentElement;
|
1731 | exports.isElement = isElement;
|
1732 | exports.isElementOfType = isElementOfType;
|
1733 | exports.mockComponent = mockComponent;
|
1734 | exports.nativeTouchData = nativeTouchData;
|
1735 | exports.renderIntoDocument = renderIntoDocument;
|
1736 | exports.scryRenderedComponentsWithType = scryRenderedComponentsWithType;
|
1737 | exports.scryRenderedDOMComponentsWithClass = scryRenderedDOMComponentsWithClass;
|
1738 | exports.scryRenderedDOMComponentsWithTag = scryRenderedDOMComponentsWithTag;
|
1739 | exports.traverseTwoPhase = traverseTwoPhase;
|
1740 | })();
|
1741 | }
|