annotate third_party/bun/node_modules/react-dom/umd/react-dom-test-utils.development.js @ 14:0570ada19343

misc file removal.
author June Park <parkjune1995@gmail.com>
date Thu, 02 Oct 2025 14:41:06 -0700
parents de54585a40f1
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
2 * @license React
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
3 * react-dom-test-utils.development.js
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
4 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
5 * Copyright (c) Facebook, Inc. and its affiliates.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
6 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
7 * This source code is licensed under the MIT license found in the
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
8 * LICENSE file in the root directory of this source tree.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
9 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
10 (function (global, factory) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
11 typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('react-dom')) :
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
12 typeof define === 'function' && define.amd ? define(['exports', 'react', 'react-dom'], factory) :
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
13 (global = global || self, factory(global.ReactTestUtils = {}, global.React, global.ReactDOM));
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
14 }(this, (function (exports, React, ReactDOM) { 'use strict';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
15
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
16 var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
17
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
18 // by calls to these methods by a Babel plugin.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
19 //
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
20 // In PROD (or in packages without access to React internals),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
21 // they are left as they are instead.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
22
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
23 function warn(format) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
24 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
25 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
26 for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
27 args[_key - 1] = arguments[_key];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
28 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
29
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
30 printWarning('warn', format, args);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
31 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
32 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
33 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
34 function error(format) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
35 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
36 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
37 for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
38 args[_key2 - 1] = arguments[_key2];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
39 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
40
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
41 printWarning('error', format, args);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
42 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
43 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
44 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
45
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
46 function printWarning(level, format, args) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
47 // When changing this logic, you might want to also
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
48 // update consoleWithStackDev.www.js as well.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
49 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
50 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
51 var stack = ReactDebugCurrentFrame.getStackAddendum();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
52
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
53 if (stack !== '') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
54 format += '%s';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
55 args = args.concat([stack]);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
56 } // eslint-disable-next-line react-internal/safe-string-coercion
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
57
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
58
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
59 var argsWithFormat = args.map(function (item) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
60 return String(item);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
61 }); // Careful: RN currently depends on this prefix
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
62
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
63 argsWithFormat.unshift('Warning: ' + format); // We intentionally don't use spread (or .apply) directly because it
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
64 // breaks IE9: https://github.com/facebook/react/issues/13610
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
65 // eslint-disable-next-line react-internal/no-production-logging
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
66
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
67 Function.prototype.apply.call(console[level], console, argsWithFormat);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
68 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
69 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
70
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
71 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
72 * `ReactInstanceMap` maintains a mapping from a public facing stateful
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
73 * instance (key) and the internal representation (value). This allows public
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
74 * methods to accept the user facing instance as an argument and map them back
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
75 * to internal methods.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
76 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
77 * Note that this module is currently shared and assumed to be stateless.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
78 * If this becomes an actual Map, that will break.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
79 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
80 function get(key) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
81 return key._reactInternals;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
82 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
83
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
84 var FunctionComponent = 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
85 var ClassComponent = 1;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
86
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
87 var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
88
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
89 var HostComponent = 5;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
90 var HostText = 6;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
91
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
92 // Don't change these two values. They're used by React Dev Tools.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
93 var NoFlags =
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
94 /* */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
95 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
96
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
97 var Placement =
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
98 /* */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
99 2;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
100 var Hydrating =
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
101 /* */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
102 4096;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
103
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
104 var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
105 function getNearestMountedFiber(fiber) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
106 var node = fiber;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
107 var nearestMounted = fiber;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
108
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
109 if (!fiber.alternate) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
110 // If there is no alternate, this might be a new tree that isn't inserted
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
111 // yet. If it is, then it will have a pending insertion effect on it.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
112 var nextNode = node;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
113
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
114 do {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
115 node = nextNode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
116
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
117 if ((node.flags & (Placement | Hydrating)) !== NoFlags) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
118 // This is an insertion or in-progress hydration. The nearest possible
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
119 // mounted fiber is the parent but we need to continue to figure out
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
120 // if that one is still mounted.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
121 nearestMounted = node.return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
122 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
123
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
124 nextNode = node.return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
125 } while (nextNode);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
126 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
127 while (node.return) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
128 node = node.return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
129 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
130 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
131
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
132 if (node.tag === HostRoot) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
133 // TODO: Check if this was a nested HostRoot when used with
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
134 // renderContainerIntoSubtree.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
135 return nearestMounted;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
136 } // If we didn't hit the root, that means that we're in an disconnected tree
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
137 // that has been unmounted.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
138
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
139
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
140 return null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
141 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
142
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
143 function assertIsMounted(fiber) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
144 if (getNearestMountedFiber(fiber) !== fiber) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
145 throw new Error('Unable to find node on an unmounted component.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
146 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
147 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
148
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
149 function findCurrentFiberUsingSlowPath(fiber) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
150 var alternate = fiber.alternate;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
151
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
152 if (!alternate) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
153 // If there is no alternate, then we only need to check if it is mounted.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
154 var nearestMounted = getNearestMountedFiber(fiber);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
155
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
156 if (nearestMounted === null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
157 throw new Error('Unable to find node on an unmounted component.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
158 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
159
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
160 if (nearestMounted !== fiber) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
161 return null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
162 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
163
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
164 return fiber;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
165 } // If we have two possible branches, we'll walk backwards up to the root
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
166 // to see what path the root points to. On the way we may hit one of the
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
167 // special cases and we'll deal with them.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
168
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
169
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
170 var a = fiber;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
171 var b = alternate;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
172
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
173 while (true) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
174 var parentA = a.return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
175
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
176 if (parentA === null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
177 // We're at the root.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
178 break;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
179 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
180
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
181 var parentB = parentA.alternate;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
182
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
183 if (parentB === null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
184 // There is no alternate. This is an unusual case. Currently, it only
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
185 // happens when a Suspense component is hidden. An extra fragment fiber
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
186 // is inserted in between the Suspense fiber and its children. Skip
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
187 // over this extra fragment fiber and proceed to the next parent.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
188 var nextParent = parentA.return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
189
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
190 if (nextParent !== null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
191 a = b = nextParent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
192 continue;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
193 } // If there's no parent, we're at the root.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
194
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
195
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
196 break;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
197 } // If both copies of the parent fiber point to the same child, we can
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
198 // assume that the child is current. This happens when we bailout on low
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
199 // priority: the bailed out fiber's child reuses the current child.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
200
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
201
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
202 if (parentA.child === parentB.child) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
203 var child = parentA.child;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
204
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
205 while (child) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
206 if (child === a) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
207 // We've determined that A is the current branch.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
208 assertIsMounted(parentA);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
209 return fiber;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
210 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
211
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
212 if (child === b) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
213 // We've determined that B is the current branch.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
214 assertIsMounted(parentA);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
215 return alternate;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
216 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
217
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
218 child = child.sibling;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
219 } // We should never have an alternate for any mounting node. So the only
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
220 // way this could possibly happen is if this was unmounted, if at all.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
221
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
222
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
223 throw new Error('Unable to find node on an unmounted component.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
224 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
225
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
226 if (a.return !== b.return) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
227 // The return pointer of A and the return pointer of B point to different
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
228 // fibers. We assume that return pointers never criss-cross, so A must
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
229 // belong to the child set of A.return, and B must belong to the child
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
230 // set of B.return.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
231 a = parentA;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
232 b = parentB;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
233 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
234 // The return pointers point to the same fiber. We'll have to use the
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
235 // default, slow path: scan the child sets of each parent alternate to see
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
236 // which child belongs to which set.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
237 //
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
238 // Search parent A's child set
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
239 var didFindChild = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
240 var _child = parentA.child;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
241
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
242 while (_child) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
243 if (_child === a) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
244 didFindChild = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
245 a = parentA;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
246 b = parentB;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
247 break;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
248 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
249
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
250 if (_child === b) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
251 didFindChild = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
252 b = parentA;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
253 a = parentB;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
254 break;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
255 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
256
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
257 _child = _child.sibling;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
258 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
259
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
260 if (!didFindChild) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
261 // Search parent B's child set
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
262 _child = parentB.child;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
263
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
264 while (_child) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
265 if (_child === a) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
266 didFindChild = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
267 a = parentB;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
268 b = parentA;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
269 break;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
270 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
271
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
272 if (_child === b) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
273 didFindChild = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
274 b = parentB;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
275 a = parentA;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
276 break;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
277 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
278
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
279 _child = _child.sibling;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
280 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
281
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
282 if (!didFindChild) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
283 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.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
284 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
285 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
286 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
287
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
288 if (a.alternate !== b) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
289 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.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
290 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
291 } // If the root is not a host container, we're in a disconnected tree. I.e.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
292 // unmounted.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
293
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
294
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
295 if (a.tag !== HostRoot) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
296 throw new Error('Unable to find node on an unmounted component.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
297 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
298
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
299 if (a.stateNode.current === a) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
300 // We've determined that A is the current branch.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
301 return fiber;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
302 } // Otherwise B has to be current branch.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
303
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
304
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
305 return alternate;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
306 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
307
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
308 var assign = Object.assign;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
309
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
310 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
311 * `charCode` represents the actual "character code" and is safe to use with
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
312 * `String.fromCharCode`. As such, only keys that correspond to printable
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
313 * characters produce a valid `charCode`, the only exception to this is Enter.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
314 * The Tab-key is considered non-printable and does not have a `charCode`,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
315 * presumably because it does not produce a tab-character in browsers.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
316 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
317 * @param {object} nativeEvent Native browser event.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
318 * @return {number} Normalized `charCode` property.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
319 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
320 function getEventCharCode(nativeEvent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
321 var charCode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
322 var keyCode = nativeEvent.keyCode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
323
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
324 if ('charCode' in nativeEvent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
325 charCode = nativeEvent.charCode; // FF does not set `charCode` for the Enter-key, check against `keyCode`.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
326
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
327 if (charCode === 0 && keyCode === 13) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
328 charCode = 13;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
329 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
330 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
331 // IE8 does not implement `charCode`, but `keyCode` has the correct value.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
332 charCode = keyCode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
333 } // IE and Edge (on Windows) and Chrome / Safari (on Windows and Linux)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
334 // report Enter as charCode 10 when ctrl is pressed.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
335
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
336
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
337 if (charCode === 10) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
338 charCode = 13;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
339 } // Some non-printable keys are reported in `charCode`/`keyCode`, discard them.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
340 // Must not discard the (non-)printable Enter-key.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
341
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
342
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
343 if (charCode >= 32 || charCode === 13) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
344 return charCode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
345 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
346
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
347 return 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
348 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
349
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
350 function functionThatReturnsTrue() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
351 return true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
352 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
353
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
354 function functionThatReturnsFalse() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
355 return false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
356 } // This is intentionally a factory so that we have different returned constructors.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
357 // If we had a single constructor, it would be megamorphic and engines would deopt.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
358
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
359
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
360 function createSyntheticEvent(Interface) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
361 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
362 * Synthetic events are dispatched by event plugins, typically in response to a
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
363 * top-level event delegation handler.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
364 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
365 * These systems should generally use pooling to reduce the frequency of garbage
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
366 * collection. The system should check `isPersistent` to determine whether the
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
367 * event should be released into the pool after being dispatched. Users that
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
368 * need a persisted event should invoke `persist`.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
369 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
370 * Synthetic events (and subclasses) implement the DOM Level 3 Events API by
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
371 * normalizing browser quirks. Subclasses do not necessarily have to implement a
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
372 * DOM interface; custom application-specific events can also subclass this.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
373 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
374 function SyntheticBaseEvent(reactName, reactEventType, targetInst, nativeEvent, nativeEventTarget) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
375 this._reactName = reactName;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
376 this._targetInst = targetInst;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
377 this.type = reactEventType;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
378 this.nativeEvent = nativeEvent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
379 this.target = nativeEventTarget;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
380 this.currentTarget = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
381
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
382 for (var _propName in Interface) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
383 if (!Interface.hasOwnProperty(_propName)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
384 continue;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
385 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
386
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
387 var normalize = Interface[_propName];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
388
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
389 if (normalize) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
390 this[_propName] = normalize(nativeEvent);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
391 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
392 this[_propName] = nativeEvent[_propName];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
393 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
394 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
395
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
396 var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
397
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
398 if (defaultPrevented) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
399 this.isDefaultPrevented = functionThatReturnsTrue;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
400 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
401 this.isDefaultPrevented = functionThatReturnsFalse;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
402 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
403
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
404 this.isPropagationStopped = functionThatReturnsFalse;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
405 return this;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
406 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
407
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
408 assign(SyntheticBaseEvent.prototype, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
409 preventDefault: function () {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
410 this.defaultPrevented = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
411 var event = this.nativeEvent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
412
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
413 if (!event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
414 return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
415 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
416
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
417 if (event.preventDefault) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
418 event.preventDefault(); // $FlowFixMe - flow is not aware of `unknown` in IE
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
419 } else if (typeof event.returnValue !== 'unknown') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
420 event.returnValue = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
421 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
422
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
423 this.isDefaultPrevented = functionThatReturnsTrue;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
424 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
425 stopPropagation: function () {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
426 var event = this.nativeEvent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
427
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
428 if (!event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
429 return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
430 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
431
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
432 if (event.stopPropagation) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
433 event.stopPropagation(); // $FlowFixMe - flow is not aware of `unknown` in IE
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
434 } else if (typeof event.cancelBubble !== 'unknown') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
435 // The ChangeEventPlugin registers a "propertychange" event for
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
436 // IE. This event does not support bubbling or cancelling, and
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
437 // any references to cancelBubble throw "Member not found". A
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
438 // typeof check of "unknown" circumvents this issue (and is also
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
439 // IE specific).
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
440 event.cancelBubble = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
441 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
442
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
443 this.isPropagationStopped = functionThatReturnsTrue;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
444 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
445
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
446 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
447 * We release all dispatched `SyntheticEvent`s after each event loop, adding
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
448 * them back into the pool. This allows a way to hold onto a reference that
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
449 * won't be added back into the pool.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
450 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
451 persist: function () {// Modern event system doesn't use pooling.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
452 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
453
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
454 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
455 * Checks if this event should be released back into the pool.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
456 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
457 * @return {boolean} True if this should not be released, false otherwise.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
458 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
459 isPersistent: functionThatReturnsTrue
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
460 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
461 return SyntheticBaseEvent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
462 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
463 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
464 * @interface Event
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
465 * @see http://www.w3.org/TR/DOM-Level-3-Events/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
466 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
467
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
468
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
469 var EventInterface = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
470 eventPhase: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
471 bubbles: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
472 cancelable: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
473 timeStamp: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
474 return event.timeStamp || Date.now();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
475 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
476 defaultPrevented: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
477 isTrusted: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
478 };
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
479 var SyntheticEvent = createSyntheticEvent(EventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
480
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
481 var UIEventInterface = assign({}, EventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
482 view: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
483 detail: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
484 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
485
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
486 var SyntheticUIEvent = createSyntheticEvent(UIEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
487 var lastMovementX;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
488 var lastMovementY;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
489 var lastMouseEvent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
490
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
491 function updateMouseMovementPolyfillState(event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
492 if (event !== lastMouseEvent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
493 if (lastMouseEvent && event.type === 'mousemove') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
494 lastMovementX = event.screenX - lastMouseEvent.screenX;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
495 lastMovementY = event.screenY - lastMouseEvent.screenY;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
496 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
497 lastMovementX = 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
498 lastMovementY = 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
499 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
500
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
501 lastMouseEvent = event;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
502 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
503 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
504 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
505 * @interface MouseEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
506 * @see http://www.w3.org/TR/DOM-Level-3-Events/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
507 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
508
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
509
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
510 var MouseEventInterface = assign({}, UIEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
511 screenX: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
512 screenY: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
513 clientX: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
514 clientY: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
515 pageX: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
516 pageY: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
517 ctrlKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
518 shiftKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
519 altKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
520 metaKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
521 getModifierState: getEventModifierState,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
522 button: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
523 buttons: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
524 relatedTarget: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
525 if (event.relatedTarget === undefined) return event.fromElement === event.srcElement ? event.toElement : event.fromElement;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
526 return event.relatedTarget;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
527 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
528 movementX: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
529 if ('movementX' in event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
530 return event.movementX;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
531 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
532
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
533 updateMouseMovementPolyfillState(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
534 return lastMovementX;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
535 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
536 movementY: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
537 if ('movementY' in event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
538 return event.movementY;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
539 } // Don't need to call updateMouseMovementPolyfillState() here
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
540 // because it's guaranteed to have already run when movementX
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
541 // was copied.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
542
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
543
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
544 return lastMovementY;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
545 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
546 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
547
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
548 var SyntheticMouseEvent = createSyntheticEvent(MouseEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
549 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
550 * @interface DragEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
551 * @see http://www.w3.org/TR/DOM-Level-3-Events/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
552 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
553
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
554 var DragEventInterface = assign({}, MouseEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
555 dataTransfer: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
556 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
557
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
558 var SyntheticDragEvent = createSyntheticEvent(DragEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
559 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
560 * @interface FocusEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
561 * @see http://www.w3.org/TR/DOM-Level-3-Events/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
562 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
563
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
564 var FocusEventInterface = assign({}, UIEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
565 relatedTarget: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
566 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
567
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
568 var SyntheticFocusEvent = createSyntheticEvent(FocusEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
569 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
570 * @interface Event
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
571 * @see http://www.w3.org/TR/css3-animations/#AnimationEvent-interface
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
572 * @see https://developer.mozilla.org/en-US/docs/Web/API/AnimationEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
573 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
574
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
575 var AnimationEventInterface = assign({}, EventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
576 animationName: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
577 elapsedTime: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
578 pseudoElement: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
579 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
580
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
581 var SyntheticAnimationEvent = createSyntheticEvent(AnimationEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
582 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
583 * @interface Event
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
584 * @see http://www.w3.org/TR/clipboard-apis/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
585 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
586
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
587 var ClipboardEventInterface = assign({}, EventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
588 clipboardData: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
589 return 'clipboardData' in event ? event.clipboardData : window.clipboardData;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
590 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
591 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
592
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
593 var SyntheticClipboardEvent = createSyntheticEvent(ClipboardEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
594 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
595 * @interface Event
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
596 * @see http://www.w3.org/TR/DOM-Level-3-Events/#events-compositionevents
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
597 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
598
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
599 var CompositionEventInterface = assign({}, EventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
600 data: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
601 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
602
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
603 var SyntheticCompositionEvent = createSyntheticEvent(CompositionEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
604 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
605 * Normalization of deprecated HTML5 `key` values
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
606 * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
607 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
608
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
609 var normalizeKey = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
610 Esc: 'Escape',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
611 Spacebar: ' ',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
612 Left: 'ArrowLeft',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
613 Up: 'ArrowUp',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
614 Right: 'ArrowRight',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
615 Down: 'ArrowDown',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
616 Del: 'Delete',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
617 Win: 'OS',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
618 Menu: 'ContextMenu',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
619 Apps: 'ContextMenu',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
620 Scroll: 'ScrollLock',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
621 MozPrintableKey: 'Unidentified'
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
622 };
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
623 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
624 * Translation from legacy `keyCode` to HTML5 `key`
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
625 * Only special keys supported, all others depend on keyboard layout or browser
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
626 * @see https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent#Key_names
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
627 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
628
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
629 var translateToKey = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
630 '8': 'Backspace',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
631 '9': 'Tab',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
632 '12': 'Clear',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
633 '13': 'Enter',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
634 '16': 'Shift',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
635 '17': 'Control',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
636 '18': 'Alt',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
637 '19': 'Pause',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
638 '20': 'CapsLock',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
639 '27': 'Escape',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
640 '32': ' ',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
641 '33': 'PageUp',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
642 '34': 'PageDown',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
643 '35': 'End',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
644 '36': 'Home',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
645 '37': 'ArrowLeft',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
646 '38': 'ArrowUp',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
647 '39': 'ArrowRight',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
648 '40': 'ArrowDown',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
649 '45': 'Insert',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
650 '46': 'Delete',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
651 '112': 'F1',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
652 '113': 'F2',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
653 '114': 'F3',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
654 '115': 'F4',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
655 '116': 'F5',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
656 '117': 'F6',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
657 '118': 'F7',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
658 '119': 'F8',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
659 '120': 'F9',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
660 '121': 'F10',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
661 '122': 'F11',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
662 '123': 'F12',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
663 '144': 'NumLock',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
664 '145': 'ScrollLock',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
665 '224': 'Meta'
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
666 };
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
667 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
668 * @param {object} nativeEvent Native browser event.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
669 * @return {string} Normalized `key` property.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
670 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
671
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
672 function getEventKey(nativeEvent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
673 if (nativeEvent.key) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
674 // Normalize inconsistent values reported by browsers due to
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
675 // implementations of a working draft specification.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
676 // FireFox implements `key` but returns `MozPrintableKey` for all
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
677 // printable characters (normalized to `Unidentified`), ignore it.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
678 var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
679
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
680 if (key !== 'Unidentified') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
681 return key;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
682 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
683 } // Browser does not implement `key`, polyfill as much of it as we can.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
684
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
685
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
686 if (nativeEvent.type === 'keypress') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
687 var charCode = getEventCharCode(nativeEvent); // The enter-key is technically both printable and non-printable and can
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
688 // thus be captured by `keypress`, no other non-printable key should.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
689
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
690 return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
691 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
692
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
693 if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
694 // While user keyboard layout determines the actual meaning of each
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
695 // `keyCode` value, almost all function keys have a universal value.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
696 return translateToKey[nativeEvent.keyCode] || 'Unidentified';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
697 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
698
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
699 return '';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
700 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
701 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
702 * Translation from modifier key to the associated property in the event.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
703 * @see http://www.w3.org/TR/DOM-Level-3-Events/#keys-Modifiers
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
704 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
705
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
706
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
707 var modifierKeyToProp = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
708 Alt: 'altKey',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
709 Control: 'ctrlKey',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
710 Meta: 'metaKey',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
711 Shift: 'shiftKey'
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
712 }; // Older browsers (Safari <= 10, iOS Safari <= 10.2) do not support
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
713 // getModifierState. If getModifierState is not supported, we map it to a set of
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
714 // modifier keys exposed by the event. In this case, Lock-keys are not supported.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
715
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
716 function modifierStateGetter(keyArg) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
717 var syntheticEvent = this;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
718 var nativeEvent = syntheticEvent.nativeEvent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
719
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
720 if (nativeEvent.getModifierState) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
721 return nativeEvent.getModifierState(keyArg);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
722 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
723
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
724 var keyProp = modifierKeyToProp[keyArg];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
725 return keyProp ? !!nativeEvent[keyProp] : false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
726 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
727
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
728 function getEventModifierState(nativeEvent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
729 return modifierStateGetter;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
730 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
731 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
732 * @interface KeyboardEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
733 * @see http://www.w3.org/TR/DOM-Level-3-Events/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
734 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
735
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
736
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
737 var KeyboardEventInterface = assign({}, UIEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
738 key: getEventKey,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
739 code: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
740 location: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
741 ctrlKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
742 shiftKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
743 altKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
744 metaKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
745 repeat: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
746 locale: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
747 getModifierState: getEventModifierState,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
748 // Legacy Interface
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
749 charCode: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
750 // `charCode` is the result of a KeyPress event and represents the value of
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
751 // the actual printable character.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
752 // KeyPress is deprecated, but its replacement is not yet final and not
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
753 // implemented in any major browser. Only KeyPress has charCode.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
754 if (event.type === 'keypress') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
755 return getEventCharCode(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
756 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
757
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
758 return 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
759 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
760 keyCode: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
761 // `keyCode` is the result of a KeyDown/Up event and represents the value of
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
762 // physical keyboard key.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
763 // The actual meaning of the value depends on the users' keyboard layout
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
764 // which cannot be detected. Assuming that it is a US keyboard layout
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
765 // provides a surprisingly accurate mapping for US and European users.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
766 // Due to this, it is left to the user to implement at this time.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
767 if (event.type === 'keydown' || event.type === 'keyup') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
768 return event.keyCode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
769 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
770
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
771 return 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
772 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
773 which: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
774 // `which` is an alias for either `keyCode` or `charCode` depending on the
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
775 // type of the event.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
776 if (event.type === 'keypress') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
777 return getEventCharCode(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
778 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
779
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
780 if (event.type === 'keydown' || event.type === 'keyup') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
781 return event.keyCode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
782 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
783
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
784 return 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
785 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
786 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
787
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
788 var SyntheticKeyboardEvent = createSyntheticEvent(KeyboardEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
789 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
790 * @interface PointerEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
791 * @see http://www.w3.org/TR/pointerevents/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
792 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
793
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
794 var PointerEventInterface = assign({}, MouseEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
795 pointerId: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
796 width: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
797 height: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
798 pressure: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
799 tangentialPressure: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
800 tiltX: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
801 tiltY: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
802 twist: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
803 pointerType: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
804 isPrimary: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
805 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
806
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
807 var SyntheticPointerEvent = createSyntheticEvent(PointerEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
808 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
809 * @interface TouchEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
810 * @see http://www.w3.org/TR/touch-events/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
811 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
812
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
813 var TouchEventInterface = assign({}, UIEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
814 touches: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
815 targetTouches: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
816 changedTouches: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
817 altKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
818 metaKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
819 ctrlKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
820 shiftKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
821 getModifierState: getEventModifierState
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
822 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
823
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
824 var SyntheticTouchEvent = createSyntheticEvent(TouchEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
825 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
826 * @interface Event
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
827 * @see http://www.w3.org/TR/2009/WD-css3-transitions-20090320/#transition-events-
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
828 * @see https://developer.mozilla.org/en-US/docs/Web/API/TransitionEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
829 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
830
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
831 var TransitionEventInterface = assign({}, EventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
832 propertyName: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
833 elapsedTime: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
834 pseudoElement: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
835 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
836
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
837 var SyntheticTransitionEvent = createSyntheticEvent(TransitionEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
838 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
839 * @interface WheelEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
840 * @see http://www.w3.org/TR/DOM-Level-3-Events/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
841 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
842
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
843 var WheelEventInterface = assign({}, MouseEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
844 deltaX: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
845 return 'deltaX' in event ? event.deltaX : // Fallback to `wheelDeltaX` for Webkit and normalize (right is positive).
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
846 'wheelDeltaX' in event ? -event.wheelDeltaX : 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
847 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
848 deltaY: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
849 return 'deltaY' in event ? event.deltaY : // Fallback to `wheelDeltaY` for Webkit and normalize (down is positive).
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
850 'wheelDeltaY' in event ? -event.wheelDeltaY : // Fallback to `wheelDelta` for IE<9 and normalize (down is positive).
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
851 'wheelDelta' in event ? -event.wheelDelta : 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
852 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
853 deltaZ: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
854 // Browsers without "deltaMode" is reporting in raw wheel delta where one
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
855 // notch on the scroll is always +/- 120, roughly equivalent to pixels.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
856 // A good approximation of DOM_DELTA_LINE (1) is 5% of viewport size or
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
857 // ~40 pixels, for DOM_DELTA_SCREEN (2) it is 87.5% of viewport size.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
858 deltaMode: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
859 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
860
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
861 var SyntheticWheelEvent = createSyntheticEvent(WheelEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
862
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
863 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
864 * HTML nodeType values that represent the type of the node
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
865 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
866 var ELEMENT_NODE = 1;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
867
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
868 function invokeGuardedCallbackProd(name, func, context, a, b, c, d, e, f) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
869 var funcArgs = Array.prototype.slice.call(arguments, 3);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
870
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
871 try {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
872 func.apply(context, funcArgs);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
873 } catch (error) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
874 this.onError(error);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
875 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
876 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
877
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
878 var invokeGuardedCallbackImpl = invokeGuardedCallbackProd;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
879
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
880 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
881 // In DEV mode, we swap out invokeGuardedCallback for a special version
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
882 // that plays more nicely with the browser's DevTools. The idea is to preserve
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
883 // "Pause on exceptions" behavior. Because React wraps all user-provided
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
884 // functions in invokeGuardedCallback, and the production version of
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
885 // invokeGuardedCallback uses a try-catch, all user exceptions are treated
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
886 // like caught exceptions, and the DevTools won't pause unless the developer
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
887 // takes the extra step of enabling pause on caught exceptions. This is
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
888 // unintuitive, though, because even though React has caught the error, from
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
889 // the developer's perspective, the error is uncaught.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
890 //
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
891 // To preserve the expected "Pause on exceptions" behavior, we don't use a
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
892 // try-catch in DEV. Instead, we synchronously dispatch a fake event to a fake
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
893 // DOM node, and call the user-provided callback from inside an event handler
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
894 // for that fake event. If the callback throws, the error is "captured" using
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
895 // a global event handler. But because the error happens in a different
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
896 // event loop context, it does not interrupt the normal program flow.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
897 // Effectively, this gives us try-catch behavior without actually using
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
898 // try-catch. Neat!
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
899 // Check that the browser supports the APIs we need to implement our special
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
900 // DEV version of invokeGuardedCallback
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
901 if (typeof window !== 'undefined' && typeof window.dispatchEvent === 'function' && typeof document !== 'undefined' && typeof document.createEvent === 'function') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
902 var fakeNode = document.createElement('react');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
903
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
904 invokeGuardedCallbackImpl = function invokeGuardedCallbackDev(name, func, context, a, b, c, d, e, f) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
905 // If document doesn't exist we know for sure we will crash in this method
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
906 // when we call document.createEvent(). However this can cause confusing
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
907 // errors: https://github.com/facebook/create-react-app/issues/3482
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
908 // So we preemptively throw with a better message instead.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
909 if (typeof document === 'undefined' || document === null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
910 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.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
911 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
912
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
913 var evt = document.createEvent('Event');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
914 var didCall = false; // Keeps track of whether the user-provided callback threw an error. We
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
915 // set this to true at the beginning, then set it to false right after
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
916 // calling the function. If the function errors, `didError` will never be
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
917 // set to false. This strategy works even if the browser is flaky and
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
918 // fails to call our global error handler, because it doesn't rely on
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
919 // the error event at all.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
920
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
921 var didError = true; // Keeps track of the value of window.event so that we can reset it
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
922 // during the callback to let user code access window.event in the
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
923 // browsers that support it.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
924
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
925 var windowEvent = window.event; // Keeps track of the descriptor of window.event to restore it after event
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
926 // dispatching: https://github.com/facebook/react/issues/13688
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
927
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
928 var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
929
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
930 function restoreAfterDispatch() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
931 // We immediately remove the callback from event listeners so that
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
932 // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
933 // nested call would trigger the fake event handlers of any call higher
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
934 // in the stack.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
935 fakeNode.removeEventListener(evtType, callCallback, false); // We check for window.hasOwnProperty('event') to prevent the
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
936 // window.event assignment in both IE <= 10 as they throw an error
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
937 // "Member not found" in strict mode, and in Firefox which does not
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
938 // support window.event.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
939
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
940 if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
941 window.event = windowEvent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
942 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
943 } // Create an event handler for our fake event. We will synchronously
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
944 // dispatch our fake event using `dispatchEvent`. Inside the handler, we
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
945 // call the user-provided callback.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
946
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
947
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
948 var funcArgs = Array.prototype.slice.call(arguments, 3);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
949
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
950 function callCallback() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
951 didCall = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
952 restoreAfterDispatch();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
953 func.apply(context, funcArgs);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
954 didError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
955 } // Create a global error event handler. We use this to capture the value
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
956 // that was thrown. It's possible that this error handler will fire more
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
957 // than once; for example, if non-React code also calls `dispatchEvent`
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
958 // and a handler for that event throws. We should be resilient to most of
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
959 // those cases. Even if our error event handler fires more than once, the
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
960 // last error event is always used. If the callback actually does error,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
961 // we know that the last error event is the correct one, because it's not
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
962 // possible for anything else to have happened in between our callback
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
963 // erroring and the code that follows the `dispatchEvent` call below. If
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
964 // the callback doesn't error, but the error event was fired, we know to
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
965 // ignore it because `didError` will be false, as described above.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
966
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
967
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
968 var error; // Use this to track whether the error event is ever called.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
969
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
970 var didSetError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
971 var isCrossOriginError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
972
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
973 function handleWindowError(event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
974 error = event.error;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
975 didSetError = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
976
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
977 if (error === null && event.colno === 0 && event.lineno === 0) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
978 isCrossOriginError = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
979 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
980
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
981 if (event.defaultPrevented) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
982 // Some other error handler has prevented default.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
983 // Browsers silence the error report if this happens.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
984 // We'll remember this to later decide whether to log it or not.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
985 if (error != null && typeof error === 'object') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
986 try {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
987 error._suppressLogging = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
988 } catch (inner) {// Ignore.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
989 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
990 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
991 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
992 } // Create a fake event type.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
993
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
994
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
995 var evtType = "react-" + (name ? name : 'invokeguardedcallback'); // Attach our event handlers
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
996
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
997 window.addEventListener('error', handleWindowError);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
998 fakeNode.addEventListener(evtType, callCallback, false); // Synchronously dispatch our fake event. If the user-provided function
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
999 // errors, it will trigger our global error handler.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1000
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1001 evt.initEvent(evtType, false, false);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1002 fakeNode.dispatchEvent(evt);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1003
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1004 if (windowEventDescriptor) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1005 Object.defineProperty(window, 'event', windowEventDescriptor);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1006 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1007
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1008 if (didCall && didError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1009 if (!didSetError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1010 // The callback errored, but the error event never fired.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1011 // eslint-disable-next-line react-internal/prod-error-codes
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1012 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.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1013 } else if (isCrossOriginError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1014 // eslint-disable-next-line react-internal/prod-error-codes
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1015 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.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1016 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1017
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1018 this.onError(error);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1019 } // Remove our event listeners
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1020
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1021
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1022 window.removeEventListener('error', handleWindowError);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1023
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1024 if (!didCall) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1025 // Something went really wrong, and our event was not dispatched.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1026 // https://github.com/facebook/react/issues/16734
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1027 // https://github.com/facebook/react/issues/16585
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1028 // Fall back to the production implementation.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1029 restoreAfterDispatch();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1030 return invokeGuardedCallbackProd.apply(this, arguments);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1031 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1032 };
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1033 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1034 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1035
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1036 var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1037
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1038 var hasError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1039 var caughtError = null; // Used by event system to capture/rethrow the first error.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1040
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1041 var hasRethrowError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1042 var rethrowError = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1043 var reporter = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1044 onError: function (error) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1045 hasError = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1046 caughtError = error;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1047 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1048 };
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1049 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1050 * Call a function while guarding against errors that happens within it.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1051 * Returns an error if it throws, otherwise null.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1052 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1053 * In production, this is implemented using a try-catch. The reason we don't
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1054 * use a try-catch directly is so that we can swap out a different
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1055 * implementation in DEV mode.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1056 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1057 * @param {String} name of the guard to use for logging or debugging
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1058 * @param {Function} func The function to invoke
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1059 * @param {*} context The context to use when calling the function
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1060 * @param {...*} args Arguments for function
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1061 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1062
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1063 function invokeGuardedCallback(name, func, context, a, b, c, d, e, f) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1064 hasError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1065 caughtError = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1066 invokeGuardedCallbackImpl$1.apply(reporter, arguments);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1067 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1068 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1069 * Same as invokeGuardedCallback, but instead of returning an error, it stores
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1070 * it in a global so it can be rethrown by `rethrowCaughtError` later.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1071 * TODO: See if caughtError and rethrowError can be unified.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1072 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1073 * @param {String} name of the guard to use for logging or debugging
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1074 * @param {Function} func The function to invoke
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1075 * @param {*} context The context to use when calling the function
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1076 * @param {...*} args Arguments for function
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1077 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1078
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1079 function invokeGuardedCallbackAndCatchFirstError(name, func, context, a, b, c, d, e, f) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1080 invokeGuardedCallback.apply(this, arguments);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1081
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1082 if (hasError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1083 var error = clearCaughtError();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1084
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1085 if (!hasRethrowError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1086 hasRethrowError = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1087 rethrowError = error;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1088 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1089 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1090 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1091 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1092 * During execution of guarded functions we will capture the first error which
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1093 * we will rethrow to be handled by the top level error handler.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1094 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1095
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1096 function rethrowCaughtError() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1097 if (hasRethrowError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1098 var error = rethrowError;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1099 hasRethrowError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1100 rethrowError = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1101 throw error;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1102 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1103 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1104 function clearCaughtError() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1105 if (hasError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1106 var error = caughtError;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1107 hasError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1108 caughtError = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1109 return error;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1110 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1111 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.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1112 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1113 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1114
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1115 var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1116
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1117 function isArray(a) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1118 return isArrayImpl(a);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1119 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1120
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1121 var SecretInternals = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1122 var EventInternals = SecretInternals.Events;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1123 var getInstanceFromNode = EventInternals[0];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1124 var getNodeFromInstance = EventInternals[1];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1125 var getFiberCurrentPropsFromNode = EventInternals[2];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1126 var enqueueStateRestore = EventInternals[3];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1127 var restoreStateIfNeeded = EventInternals[4];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1128 var reactAct = React.unstable_act;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1129
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1130 function Event(suffix) {}
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1131
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1132 var hasWarnedAboutDeprecatedMockComponent = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1133 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1134 * @class ReactTestUtils
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1135 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1136
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1137 function findAllInRenderedFiberTreeInternal(fiber, test) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1138 if (!fiber) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1139 return [];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1140 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1141
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1142 var currentParent = findCurrentFiberUsingSlowPath(fiber);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1143
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1144 if (!currentParent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1145 return [];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1146 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1147
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1148 var node = currentParent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1149 var ret = [];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1150
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1151 while (true) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1152 if (node.tag === HostComponent || node.tag === HostText || node.tag === ClassComponent || node.tag === FunctionComponent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1153 var publicInst = node.stateNode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1154
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1155 if (test(publicInst)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1156 ret.push(publicInst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1157 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1158 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1159
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1160 if (node.child) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1161 node.child.return = node;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1162 node = node.child;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1163 continue;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1164 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1165
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1166 if (node === currentParent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1167 return ret;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1168 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1169
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1170 while (!node.sibling) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1171 if (!node.return || node.return === currentParent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1172 return ret;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1173 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1174
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1175 node = node.return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1176 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1177
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1178 node.sibling.return = node.return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1179 node = node.sibling;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1180 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1181 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1182
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1183 function validateClassInstance(inst, methodName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1184 if (!inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1185 // This is probably too relaxed but it's existing behavior.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1186 return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1187 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1188
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1189 if (get(inst)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1190 // This is a public instance indeed.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1191 return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1192 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1193
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1194 var received;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1195 var stringified = String(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1196
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1197 if (isArray(inst)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1198 received = 'an array';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1199 } else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1200 received = 'a DOM node';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1201 } else if (stringified === '[object Object]') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1202 received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1203 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1204 received = stringified;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1205 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1206
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1207 throw new Error(methodName + "(...): the first argument must be a React class instance. " + ("Instead received: " + received + "."));
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1208 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1209 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1210 * Utilities for making it easy to test React components.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1211 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1212 * See https://reactjs.org/docs/test-utils.html
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1213 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1214 * Todo: Support the entire DOM.scry query syntax. For now, these simple
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1215 * utilities will suffice for testing purposes.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1216 * @lends ReactTestUtils
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1217 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1218
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1219
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1220 var didWarnAboutReactTestUtilsDeprecation = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1221
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1222 function renderIntoDocument(element) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1223 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1224 if (!didWarnAboutReactTestUtilsDeprecation) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1225 didWarnAboutReactTestUtilsDeprecation = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1226
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1227 error('ReactDOMTestUtils is deprecated and will be removed in a future ' + 'major release, because it exposes internal implementation details ' + 'that are highly likely to change between releases. Upgrade to a ' + 'modern testing library, such as @testing-library/react. See ' + 'https://react.dev/warnings/react-dom-test-utils for more info.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1228 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1229 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1230
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1231 var div = document.createElement('div'); // None of our tests actually require attaching the container to the
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1232 // DOM, and doing so creates a mess that we rely on test isolation to
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1233 // clean up, so we're going to stop honoring the name of this method
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1234 // (and probably rename it eventually) if no problems arise.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1235 // document.documentElement.appendChild(div);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1236
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1237 return ReactDOM.render(element, div);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1238 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1239
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1240 function isElement(element) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1241 return React.isValidElement(element);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1242 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1243
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1244 function isElementOfType(inst, convenienceConstructor) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1245 return React.isValidElement(inst) && inst.type === convenienceConstructor;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1246 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1247
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1248 function isDOMComponent(inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1249 return !!(inst && inst.nodeType === ELEMENT_NODE && inst.tagName);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1250 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1251
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1252 function isDOMComponentElement(inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1253 return !!(inst && React.isValidElement(inst) && !!inst.tagName);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1254 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1255
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1256 function isCompositeComponent(inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1257 if (isDOMComponent(inst)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1258 // Accessing inst.setState warns; just return false as that'll be what
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1259 // this returns when we have DOM nodes as refs directly
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1260 return false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1261 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1262
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1263 return inst != null && typeof inst.render === 'function' && typeof inst.setState === 'function';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1264 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1265
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1266 function isCompositeComponentWithType(inst, type) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1267 if (!isCompositeComponent(inst)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1268 return false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1269 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1270
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1271 var internalInstance = get(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1272 var constructor = internalInstance.type;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1273 return constructor === type;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1274 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1275
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1276 function findAllInRenderedTree(inst, test) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1277 validateClassInstance(inst, 'findAllInRenderedTree');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1278
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1279 if (!inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1280 return [];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1281 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1282
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1283 var internalInstance = get(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1284 return findAllInRenderedFiberTreeInternal(internalInstance, test);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1285 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1286 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1287 * Finds all instances of components in the rendered tree that are DOM
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1288 * components with the class name matching `className`.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1289 * @return {array} an array of all the matches.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1290 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1291
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1292
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1293 function scryRenderedDOMComponentsWithClass(root, classNames) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1294 validateClassInstance(root, 'scryRenderedDOMComponentsWithClass');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1295 return findAllInRenderedTree(root, function (inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1296 if (isDOMComponent(inst)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1297 var className = inst.className;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1298
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1299 if (typeof className !== 'string') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1300 // SVG, probably.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1301 className = inst.getAttribute('class') || '';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1302 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1303
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1304 var classList = className.split(/\s+/);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1305
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1306 if (!isArray(classNames)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1307 if (classNames === undefined) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1308 throw new Error('TestUtils.scryRenderedDOMComponentsWithClass expects a ' + 'className as a second argument.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1309 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1310
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1311 classNames = classNames.split(/\s+/);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1312 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1313
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1314 return classNames.every(function (name) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1315 return classList.indexOf(name) !== -1;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1316 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1317 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1318
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1319 return false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1320 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1321 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1322 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1323 * Like scryRenderedDOMComponentsWithClass but expects there to be one result,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1324 * and returns that one result, or throws exception if there is any other
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1325 * number of matches besides one.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1326 * @return {!ReactDOMComponent} The one match.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1327 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1328
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1329
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1330 function findRenderedDOMComponentWithClass(root, className) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1331 validateClassInstance(root, 'findRenderedDOMComponentWithClass');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1332 var all = scryRenderedDOMComponentsWithClass(root, className);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1333
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1334 if (all.length !== 1) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1335 throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for class:' + className);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1336 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1337
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1338 return all[0];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1339 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1340 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1341 * Finds all instances of components in the rendered tree that are DOM
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1342 * components with the tag name matching `tagName`.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1343 * @return {array} an array of all the matches.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1344 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1345
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1346
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1347 function scryRenderedDOMComponentsWithTag(root, tagName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1348 validateClassInstance(root, 'scryRenderedDOMComponentsWithTag');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1349 return findAllInRenderedTree(root, function (inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1350 return isDOMComponent(inst) && inst.tagName.toUpperCase() === tagName.toUpperCase();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1351 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1352 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1353 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1354 * Like scryRenderedDOMComponentsWithTag but expects there to be one result,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1355 * and returns that one result, or throws exception if there is any other
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1356 * number of matches besides one.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1357 * @return {!ReactDOMComponent} The one match.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1358 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1359
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1360
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1361 function findRenderedDOMComponentWithTag(root, tagName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1362 validateClassInstance(root, 'findRenderedDOMComponentWithTag');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1363 var all = scryRenderedDOMComponentsWithTag(root, tagName);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1364
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1365 if (all.length !== 1) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1366 throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for tag:' + tagName);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1367 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1368
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1369 return all[0];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1370 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1371 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1372 * Finds all instances of components with type equal to `componentType`.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1373 * @return {array} an array of all the matches.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1374 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1375
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1376
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1377 function scryRenderedComponentsWithType(root, componentType) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1378 validateClassInstance(root, 'scryRenderedComponentsWithType');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1379 return findAllInRenderedTree(root, function (inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1380 return isCompositeComponentWithType(inst, componentType);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1381 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1382 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1383 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1384 * Same as `scryRenderedComponentsWithType` but expects there to be one result
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1385 * and returns that one result, or throws exception if there is any other
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1386 * number of matches besides one.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1387 * @return {!ReactComponent} The one match.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1388 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1389
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1390
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1391 function findRenderedComponentWithType(root, componentType) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1392 validateClassInstance(root, 'findRenderedComponentWithType');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1393 var all = scryRenderedComponentsWithType(root, componentType);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1394
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1395 if (all.length !== 1) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1396 throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for componentType:' + componentType);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1397 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1398
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1399 return all[0];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1400 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1401 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1402 * Pass a mocked component module to this method to augment it with
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1403 * useful methods that allow it to be used as a dummy React component.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1404 * Instead of rendering as usual, the component will become a simple
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1405 * <div> containing any provided children.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1406 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1407 * @param {object} module the mock function object exported from a
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1408 * module that defines the component to be mocked
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1409 * @param {?string} mockTagName optional dummy root tag name to return
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1410 * from render method (overrides
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1411 * module.mockTagName if provided)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1412 * @return {object} the ReactTestUtils object (for chaining)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1413 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1414
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1415
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1416 function mockComponent(module, mockTagName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1417 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1418 if (!hasWarnedAboutDeprecatedMockComponent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1419 hasWarnedAboutDeprecatedMockComponent = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1420
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1421 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.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1422 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1423 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1424
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1425 mockTagName = mockTagName || module.mockTagName || 'div';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1426 module.prototype.render.mockImplementation(function () {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1427 return React.createElement(mockTagName, null, this.props.children);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1428 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1429 return this;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1430 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1431
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1432 function nativeTouchData(x, y) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1433 return {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1434 touches: [{
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1435 pageX: x,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1436 pageY: y
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1437 }]
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1438 };
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1439 } // Start of inline: the below functions were inlined from
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1440 // EventPropagator.js, as they deviated from ReactDOM's newer
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1441 // implementations.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1442
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1443 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1444 * Dispatch the event to the listener.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1445 * @param {SyntheticEvent} event SyntheticEvent to handle
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1446 * @param {function} listener Application-level callback
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1447 * @param {*} inst Internal component instance
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1448 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1449
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1450
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1451 function executeDispatch(event, listener, inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1452 var type = event.type || 'unknown-event';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1453 event.currentTarget = getNodeFromInstance(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1454 invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1455 event.currentTarget = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1456 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1457 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1458 * Standard/simple iteration through an event's collected dispatches.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1459 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1460
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1461
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1462 function executeDispatchesInOrder(event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1463 var dispatchListeners = event._dispatchListeners;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1464 var dispatchInstances = event._dispatchInstances;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1465
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1466 if (isArray(dispatchListeners)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1467 for (var i = 0; i < dispatchListeners.length; i++) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1468 if (event.isPropagationStopped()) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1469 break;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1470 } // Listeners and Instances are two parallel arrays that are always in sync.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1471
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1472
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1473 executeDispatch(event, dispatchListeners[i], dispatchInstances[i]);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1474 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1475 } else if (dispatchListeners) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1476 executeDispatch(event, dispatchListeners, dispatchInstances);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1477 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1478
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1479 event._dispatchListeners = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1480 event._dispatchInstances = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1481 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1482 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1483 * Dispatches an event and releases it back into the pool, unless persistent.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1484 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1485 * @param {?object} event Synthetic event to be dispatched.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1486 * @private
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1487 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1488
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1489
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1490 var executeDispatchesAndRelease = function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1491 if (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1492 executeDispatchesInOrder(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1493
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1494 if (!event.isPersistent()) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1495 event.constructor.release(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1496 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1497 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1498 };
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1499
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1500 function isInteractive(tag) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1501 return tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1502 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1503
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1504 function getParent(inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1505 do {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1506 inst = inst.return; // TODO: If this is a HostRoot we might want to bail out.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1507 // That is depending on if we want nested subtrees (layers) to bubble
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1508 // events to their parent. We could also go through parentNode on the
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1509 // host node but that wouldn't work for React Native and doesn't let us
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1510 // do the portal feature.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1511 } while (inst && inst.tag !== HostComponent);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1512
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1513 if (inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1514 return inst;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1515 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1516
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1517 return null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1518 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1519 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1520 * Simulates the traversal of a two-phase, capture/bubble event dispatch.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1521 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1522
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1523
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1524 function traverseTwoPhase(inst, fn, arg) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1525 var path = [];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1526
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1527 while (inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1528 path.push(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1529 inst = getParent(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1530 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1531
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1532 var i;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1533
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1534 for (i = path.length; i-- > 0;) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1535 fn(path[i], 'captured', arg);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1536 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1537
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1538 for (i = 0; i < path.length; i++) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1539 fn(path[i], 'bubbled', arg);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1540 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1541 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1542
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1543 function shouldPreventMouseEvent(name, type, props) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1544 switch (name) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1545 case 'onClick':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1546 case 'onClickCapture':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1547 case 'onDoubleClick':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1548 case 'onDoubleClickCapture':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1549 case 'onMouseDown':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1550 case 'onMouseDownCapture':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1551 case 'onMouseMove':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1552 case 'onMouseMoveCapture':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1553 case 'onMouseUp':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1554 case 'onMouseUpCapture':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1555 case 'onMouseEnter':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1556 return !!(props.disabled && isInteractive(type));
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1557
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1558 default:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1559 return false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1560 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1561 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1562 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1563 * @param {object} inst The instance, which is the source of events.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1564 * @param {string} registrationName Name of listener (e.g. `onClick`).
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1565 * @return {?function} The stored callback.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1566 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1567
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1568
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1569 function getListener(inst, registrationName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1570 // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1571 // live here; needs to be moved to a better place soon
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1572 var stateNode = inst.stateNode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1573
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1574 if (!stateNode) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1575 // Work in progress (ex: onload events in incremental mode).
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1576 return null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1577 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1578
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1579 var props = getFiberCurrentPropsFromNode(stateNode);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1580
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1581 if (!props) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1582 // Work in progress.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1583 return null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1584 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1585
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1586 var listener = props[registrationName];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1587
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1588 if (shouldPreventMouseEvent(registrationName, inst.type, props)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1589 return null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1590 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1591
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1592 if (listener && typeof listener !== 'function') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1593 throw new Error("Expected `" + registrationName + "` listener to be a function, instead got a value of `" + typeof listener + "` type.");
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1594 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1595
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1596 return listener;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1597 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1598
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1599 function listenerAtPhase(inst, event, propagationPhase) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1600 var registrationName = event._reactName;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1601
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1602 if (propagationPhase === 'captured') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1603 registrationName += 'Capture';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1604 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1605
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1606 return getListener(inst, registrationName);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1607 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1608
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1609 function accumulateDispatches(inst, ignoredDirection, event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1610 if (inst && event && event._reactName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1611 var registrationName = event._reactName;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1612 var listener = getListener(inst, registrationName);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1613
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1614 if (listener) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1615 if (event._dispatchListeners == null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1616 event._dispatchListeners = [];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1617 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1618
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1619 if (event._dispatchInstances == null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1620 event._dispatchInstances = [];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1621 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1622
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1623 event._dispatchListeners.push(listener);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1624
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1625 event._dispatchInstances.push(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1626 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1627 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1628 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1629
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1630 function accumulateDirectionalDispatches(inst, phase, event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1631 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1632 if (!inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1633 error('Dispatching inst must not be null');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1634 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1635 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1636
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1637 var listener = listenerAtPhase(inst, event, phase);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1638
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1639 if (listener) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1640 if (event._dispatchListeners == null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1641 event._dispatchListeners = [];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1642 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1643
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1644 if (event._dispatchInstances == null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1645 event._dispatchInstances = [];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1646 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1647
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1648 event._dispatchListeners.push(listener);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1649
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1650 event._dispatchInstances.push(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1651 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1652 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1653
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1654 function accumulateDirectDispatchesSingle(event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1655 if (event && event._reactName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1656 accumulateDispatches(event._targetInst, null, event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1657 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1658 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1659
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1660 function accumulateTwoPhaseDispatchesSingle(event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1661 if (event && event._reactName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1662 traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1663 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1664 } // End of inline
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1665
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1666
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1667 var Simulate = {};
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1668 var directDispatchEventTypes = new Set(['mouseEnter', 'mouseLeave', 'pointerEnter', 'pointerLeave']);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1669 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1670 * Exports:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1671 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1672 * - `Simulate.click(Element)`
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1673 * - `Simulate.mouseMove(Element)`
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1674 * - `Simulate.change(Element)`
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1675 * - ... (All keys from event plugin `eventTypes` objects)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1676 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1677
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1678 function makeSimulator(eventType) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1679 return function (domNode, eventData) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1680 if (React.isValidElement(domNode)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1681 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.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1682 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1683
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1684 if (isCompositeComponent(domNode)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1685 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.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1686 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1687
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1688 var reactName = 'on' + eventType[0].toUpperCase() + eventType.slice(1);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1689 var fakeNativeEvent = new Event();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1690 fakeNativeEvent.target = domNode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1691 fakeNativeEvent.type = eventType.toLowerCase();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1692 var targetInst = getInstanceFromNode(domNode);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1693 var event = new SyntheticEvent(reactName, fakeNativeEvent.type, targetInst, fakeNativeEvent, domNode); // Since we aren't using pooling, always persist the event. This will make
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1694 // sure it's marked and won't warn when setting additional properties.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1695
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1696 event.persist();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1697 assign(event, eventData);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1698
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1699 if (directDispatchEventTypes.has(eventType)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1700 accumulateDirectDispatchesSingle(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1701 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1702 accumulateTwoPhaseDispatchesSingle(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1703 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1704
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1705 ReactDOM.unstable_batchedUpdates(function () {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1706 // Normally extractEvent enqueues a state restore, but we'll just always
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1707 // do that since we're by-passing it here.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1708 enqueueStateRestore(domNode);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1709 executeDispatchesAndRelease(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1710 rethrowCaughtError();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1711 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1712 restoreStateIfNeeded();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1713 };
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1714 } // A one-time snapshot with no plans to update. We'll probably want to deprecate Simulate API.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1715
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1716
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1717 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'];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1718
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1719 function buildSimulators() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1720 simulatedEventTypes.forEach(function (eventType) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1721 Simulate[eventType] = makeSimulator(eventType);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1722 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1723 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1724
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1725 buildSimulators();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1726 var didWarnAboutUsingAct = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1727 var act = function actWithWarning(callback) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1728 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1729 if (!didWarnAboutUsingAct) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1730 didWarnAboutUsingAct = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1731
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1732 error('`ReactDOMTestUtils.act` is deprecated in favor of `React.act`. ' + 'Import `act` from `react` instead of `react-dom/test-utils`. ' + 'See https://react.dev/warnings/react-dom-test-utils for more info.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1733 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1734 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1735
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1736 return reactAct(callback);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1737 } ;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1738
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1739 exports.Simulate = Simulate;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1740 exports.act = act;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1741 exports.findAllInRenderedTree = findAllInRenderedTree;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1742 exports.findRenderedComponentWithType = findRenderedComponentWithType;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1743 exports.findRenderedDOMComponentWithClass = findRenderedDOMComponentWithClass;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1744 exports.findRenderedDOMComponentWithTag = findRenderedDOMComponentWithTag;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1745 exports.isCompositeComponent = isCompositeComponent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1746 exports.isCompositeComponentWithType = isCompositeComponentWithType;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1747 exports.isDOMComponent = isDOMComponent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1748 exports.isDOMComponentElement = isDOMComponentElement;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1749 exports.isElement = isElement;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1750 exports.isElementOfType = isElementOfType;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1751 exports.mockComponent = mockComponent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1752 exports.nativeTouchData = nativeTouchData;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1753 exports.renderIntoDocument = renderIntoDocument;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1754 exports.scryRenderedComponentsWithType = scryRenderedComponentsWithType;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1755 exports.scryRenderedDOMComponentsWithClass = scryRenderedDOMComponentsWithClass;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1756 exports.scryRenderedDOMComponentsWithTag = scryRenderedDOMComponentsWithTag;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1757 exports.traverseTwoPhase = traverseTwoPhase;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1758
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1759 })));