annotate third_party/bun/node_modules/react-dom/cjs/react-dom-test-utils.development.js @ 22:947b81010aba

[Dowa & Seobeo] Updated so that Dowa hashmaps can use arena and not be broken. Split up web so taht it can handle different paths. Also fixes issues with hash collisions which was pain in the ass.
author June Park <parkjune1995@gmail.com>
date Tue, 07 Oct 2025 07:11:02 -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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
11 'use strict';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
13 if (process.env.NODE_ENV !== "production") {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
14 (function() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
15 'use strict';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
16
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
17 var React = require('react');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
18 var ReactDOM = require('react-dom');
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 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
21
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
22 // by calls to these methods by a Babel plugin.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
23 //
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
24 // In PROD (or in packages without access to React internals),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
25 // they are left as they are instead.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
26
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
27 function warn(format) {
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 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
31 args[_key - 1] = arguments[_key];
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 printWarning('warn', format, args);
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 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
38 function error(format) {
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 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
42 args[_key2 - 1] = arguments[_key2];
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 printWarning('error', format, args);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
46 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
47 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
48 }
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 function printWarning(level, format, args) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
51 // When changing this logic, you might want to also
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
52 // update consoleWithStackDev.www.js as well.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
53 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
54 var ReactDebugCurrentFrame = ReactSharedInternals.ReactDebugCurrentFrame;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
55 var stack = ReactDebugCurrentFrame.getStackAddendum();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
56
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
57 if (stack !== '') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
58 format += '%s';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
59 args = args.concat([stack]);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
60 } // eslint-disable-next-line react-internal/safe-string-coercion
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
61
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 var argsWithFormat = args.map(function (item) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
64 return String(item);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
65 }); // Careful: RN currently depends on this prefix
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 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
68 // breaks IE9: https://github.com/facebook/react/issues/13610
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
69 // eslint-disable-next-line react-internal/no-production-logging
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 Function.prototype.apply.call(console[level], console, argsWithFormat);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
72 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
73 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
74
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
75 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
76 * `ReactInstanceMap` maintains a mapping from a public facing stateful
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
77 * instance (key) and the internal representation (value). This allows public
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
78 * 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
79 * to internal methods.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
80 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
81 * 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
82 * If this becomes an actual Map, that will break.
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 function get(key) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
85 return key._reactInternals;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
88 var FunctionComponent = 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
89 var ClassComponent = 1;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
90
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
91 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
92
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
93 var HostComponent = 5;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
94 var HostText = 6;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
95
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
96 // 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
97 var NoFlags =
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 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
100
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
101 var Placement =
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
102 /* */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
103 2;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
104 var Hydrating =
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
105 /* */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
106 4096;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
107
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
108 var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
109 function getNearestMountedFiber(fiber) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
110 var node = fiber;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
111 var nearestMounted = fiber;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
112
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
113 if (!fiber.alternate) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
114 // 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
115 // 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
116 var nextNode = node;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
117
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
118 do {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
119 node = nextNode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
120
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
121 if ((node.flags & (Placement | Hydrating)) !== NoFlags) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
122 // 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
123 // 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
124 // if that one is still mounted.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
125 nearestMounted = node.return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
126 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
127
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
128 nextNode = node.return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
129 } while (nextNode);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
130 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
131 while (node.return) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
132 node = node.return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
133 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
134 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
135
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
136 if (node.tag === HostRoot) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
137 // 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
138 // renderContainerIntoSubtree.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
139 return nearestMounted;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
140 } // 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
141 // that has been unmounted.
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
144 return null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
145 }
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 function assertIsMounted(fiber) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
148 if (getNearestMountedFiber(fiber) !== fiber) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
149 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
150 }
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
153 function findCurrentFiberUsingSlowPath(fiber) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
154 var alternate = fiber.alternate;
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 (!alternate) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
157 // 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
158 var nearestMounted = getNearestMountedFiber(fiber);
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 === null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
161 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
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 if (nearestMounted !== fiber) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
165 return null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
166 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
167
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
168 return fiber;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
169 } // 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
170 // 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
171 // special cases and we'll deal with them.
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
174 var a = fiber;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
175 var b = alternate;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
176
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
177 while (true) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
178 var parentA = a.return;
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 if (parentA === null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
181 // We're at the root.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
182 break;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
183 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
184
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
185 var parentB = parentA.alternate;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
186
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
187 if (parentB === null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
188 // 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
189 // 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
190 // 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
191 // 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
192 var nextParent = parentA.return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
193
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
194 if (nextParent !== null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
195 a = b = nextParent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
196 continue;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
197 } // If there's no parent, we're at the root.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
198
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
199
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
200 break;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
201 } // 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
202 // 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
203 // 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
204
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
205
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
206 if (parentA.child === parentB.child) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
207 var child = parentA.child;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
208
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
209 while (child) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
210 if (child === a) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
211 // We've determined that A is the current branch.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
212 assertIsMounted(parentA);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
213 return fiber;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
214 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
215
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
216 if (child === b) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
217 // We've determined that B is the current branch.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
218 assertIsMounted(parentA);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
219 return alternate;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
220 }
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 child = child.sibling;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
223 } // 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
224 // 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
225
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
226
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
227 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
228 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
229
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
230 if (a.return !== b.return) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
231 // 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
232 // 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
233 // 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
234 // set of B.return.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
235 a = parentA;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
236 b = parentB;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
237 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
238 // 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
239 // 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
240 // which child belongs to which set.
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 // Search parent A's child set
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
243 var didFindChild = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
244 var _child = parentA.child;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
245
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
246 while (_child) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
247 if (_child === a) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
248 didFindChild = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
249 a = parentA;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
250 b = parentB;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
251 break;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
252 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
253
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
254 if (_child === b) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
255 didFindChild = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
256 b = parentA;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
257 a = parentB;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
258 break;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
261 _child = _child.sibling;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
262 }
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 if (!didFindChild) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
265 // Search parent B's child set
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
266 _child = parentB.child;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
267
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
268 while (_child) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
269 if (_child === a) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
270 didFindChild = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
271 a = parentB;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
272 b = parentA;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
273 break;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
274 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
275
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
276 if (_child === b) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
277 didFindChild = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
278 b = parentB;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
279 a = parentA;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
280 break;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
283 _child = _child.sibling;
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 if (!didFindChild) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
287 throw new Error('Child was not found in either parent set. This indicates a bug ' + 'in React related to the return pointer. Please file an issue.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
288 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
289 }
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
292 if (a.alternate !== b) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
293 throw new Error("Return fibers should always be each others' alternates. " + 'This error is likely caused by a bug in React. Please file an issue.');
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 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
296 // unmounted.
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.tag !== HostRoot) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
300 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
301 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
302
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
303 if (a.stateNode.current === a) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
304 // We've determined that A is the current branch.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
305 return fiber;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
306 } // Otherwise B has to be current branch.
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
309 return alternate;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
312 var assign = Object.assign;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
313
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
314 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
315 * `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
316 * `String.fromCharCode`. As such, only keys that correspond to printable
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
317 * 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
318 * 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
319 * 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
320 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
321 * @param {object} nativeEvent Native browser event.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
322 * @return {number} Normalized `charCode` property.
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 function getEventCharCode(nativeEvent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
325 var charCode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
326 var keyCode = nativeEvent.keyCode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
327
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
328 if ('charCode' in nativeEvent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
329 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
330
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
331 if (charCode === 0 && keyCode === 13) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
332 charCode = 13;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
333 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
334 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
335 // 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
336 charCode = keyCode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
337 } // 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
338 // report Enter as charCode 10 when ctrl is pressed.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
339
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
340
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
341 if (charCode === 10) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
342 charCode = 13;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
343 } // 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
344 // Must not discard the (non-)printable Enter-key.
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 if (charCode >= 32 || charCode === 13) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
348 return charCode;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
351 return 0;
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 functionThatReturnsTrue() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
355 return true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
356 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
357
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
358 function functionThatReturnsFalse() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
359 return false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
360 } // 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
361 // 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
362
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
363
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
364 function createSyntheticEvent(Interface) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
365 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
366 * 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
367 * top-level event delegation handler.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
368 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
369 * 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
370 * collection. The system should check `isPersistent` to determine whether the
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
371 * 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
372 * need a persisted event should invoke `persist`.
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 * 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
375 * 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
376 * DOM interface; custom application-specific events can also subclass this.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
377 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
378 function SyntheticBaseEvent(reactName, reactEventType, targetInst, nativeEvent, nativeEventTarget) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
379 this._reactName = reactName;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
380 this._targetInst = targetInst;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
381 this.type = reactEventType;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
382 this.nativeEvent = nativeEvent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
383 this.target = nativeEventTarget;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
384 this.currentTarget = null;
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 for (var _propName in Interface) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
387 if (!Interface.hasOwnProperty(_propName)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
388 continue;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
389 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
390
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
391 var normalize = Interface[_propName];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
392
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
393 if (normalize) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
394 this[_propName] = normalize(nativeEvent);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
395 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
396 this[_propName] = nativeEvent[_propName];
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 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
399
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
400 var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
401
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
402 if (defaultPrevented) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
403 this.isDefaultPrevented = functionThatReturnsTrue;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
404 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
405 this.isDefaultPrevented = functionThatReturnsFalse;
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 this.isPropagationStopped = functionThatReturnsFalse;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
409 return this;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
410 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
411
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
412 assign(SyntheticBaseEvent.prototype, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
413 preventDefault: function () {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
414 this.defaultPrevented = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
415 var event = this.nativeEvent;
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) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
418 return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
419 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
420
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
421 if (event.preventDefault) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
422 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
423 } else if (typeof event.returnValue !== 'unknown') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
424 event.returnValue = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
425 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
426
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
427 this.isDefaultPrevented = functionThatReturnsTrue;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
428 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
429 stopPropagation: function () {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
430 var event = this.nativeEvent;
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) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
433 return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
434 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
435
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
436 if (event.stopPropagation) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
437 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
438 } else if (typeof event.cancelBubble !== 'unknown') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
439 // The ChangeEventPlugin registers a "propertychange" event for
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
440 // IE. This event does not support bubbling or cancelling, and
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
441 // any references to cancelBubble throw "Member not found". A
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
442 // typeof check of "unknown" circumvents this issue (and is also
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
443 // IE specific).
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
444 event.cancelBubble = true;
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 this.isPropagationStopped = functionThatReturnsTrue;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
448 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
449
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 * 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
452 * 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
453 * won't be added back into the pool.
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 persist: function () {// Modern event system doesn't use pooling.
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
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 * 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
460 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
461 * @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
462 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
463 isPersistent: functionThatReturnsTrue
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
464 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
465 return SyntheticBaseEvent;
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 * @interface Event
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
469 * @see http://www.w3.org/TR/DOM-Level-3-Events/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
470 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
471
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
472
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
473 var EventInterface = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
474 eventPhase: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
475 bubbles: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
476 cancelable: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
477 timeStamp: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
478 return event.timeStamp || Date.now();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
479 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
480 defaultPrevented: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
481 isTrusted: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
482 };
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
483 var SyntheticEvent = createSyntheticEvent(EventInterface);
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 var UIEventInterface = assign({}, EventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
486 view: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
487 detail: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
488 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
489
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
490 var SyntheticUIEvent = createSyntheticEvent(UIEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
491 var lastMovementX;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
492 var lastMovementY;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
493 var lastMouseEvent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
494
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
495 function updateMouseMovementPolyfillState(event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
496 if (event !== lastMouseEvent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
497 if (lastMouseEvent && event.type === 'mousemove') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
498 lastMovementX = event.screenX - lastMouseEvent.screenX;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
499 lastMovementY = event.screenY - lastMouseEvent.screenY;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
500 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
501 lastMovementX = 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
502 lastMovementY = 0;
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 lastMouseEvent = event;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
506 }
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 * @interface MouseEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
510 * @see http://www.w3.org/TR/DOM-Level-3-Events/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
511 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
512
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
513
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
514 var MouseEventInterface = assign({}, UIEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
515 screenX: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
516 screenY: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
517 clientX: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
518 clientY: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
519 pageX: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
520 pageY: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
521 ctrlKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
522 shiftKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
523 altKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
524 metaKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
525 getModifierState: getEventModifierState,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
526 button: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
527 buttons: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
528 relatedTarget: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
529 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
530 return event.relatedTarget;
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 movementX: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
533 if ('movementX' in event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
534 return event.movementX;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
537 updateMouseMovementPolyfillState(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
538 return lastMovementX;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
539 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
540 movementY: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
541 if ('movementY' in event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
542 return event.movementY;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
543 } // Don't need to call updateMouseMovementPolyfillState() here
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
544 // because it's guaranteed to have already run when movementX
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
545 // was copied.
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 return lastMovementY;
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 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
551
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
552 var SyntheticMouseEvent = createSyntheticEvent(MouseEventInterface);
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 * @interface DragEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
555 * @see http://www.w3.org/TR/DOM-Level-3-Events/
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 DragEventInterface = assign({}, MouseEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
559 dataTransfer: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
560 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
561
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
562 var SyntheticDragEvent = createSyntheticEvent(DragEventInterface);
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 * @interface FocusEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
565 * @see http://www.w3.org/TR/DOM-Level-3-Events/
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 FocusEventInterface = assign({}, UIEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
569 relatedTarget: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
570 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
571
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
572 var SyntheticFocusEvent = createSyntheticEvent(FocusEventInterface);
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 * @interface Event
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
575 * @see http://www.w3.org/TR/css3-animations/#AnimationEvent-interface
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
576 * @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
577 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
578
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
579 var AnimationEventInterface = assign({}, EventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
580 animationName: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
581 elapsedTime: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
582 pseudoElement: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
583 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
584
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
585 var SyntheticAnimationEvent = createSyntheticEvent(AnimationEventInterface);
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 * @interface Event
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
588 * @see http://www.w3.org/TR/clipboard-apis/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
589 */
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 var ClipboardEventInterface = assign({}, EventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
592 clipboardData: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
593 return 'clipboardData' in event ? event.clipboardData : window.clipboardData;
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 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
596
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
597 var SyntheticClipboardEvent = createSyntheticEvent(ClipboardEventInterface);
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 * @interface Event
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
600 * @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
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 CompositionEventInterface = assign({}, EventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
604 data: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
605 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
606
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
607 var SyntheticCompositionEvent = createSyntheticEvent(CompositionEventInterface);
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 * Normalization of deprecated HTML5 `key` values
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
610 * @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
611 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
612
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
613 var normalizeKey = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
614 Esc: 'Escape',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
615 Spacebar: ' ',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
616 Left: 'ArrowLeft',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
617 Up: 'ArrowUp',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
618 Right: 'ArrowRight',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
619 Down: 'ArrowDown',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
620 Del: 'Delete',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
621 Win: 'OS',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
622 Menu: 'ContextMenu',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
623 Apps: 'ContextMenu',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
624 Scroll: 'ScrollLock',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
625 MozPrintableKey: 'Unidentified'
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
626 };
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 * Translation from legacy `keyCode` to HTML5 `key`
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
629 * 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
630 * @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
631 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
632
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
633 var translateToKey = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
634 '8': 'Backspace',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
635 '9': 'Tab',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
636 '12': 'Clear',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
637 '13': 'Enter',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
638 '16': 'Shift',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
639 '17': 'Control',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
640 '18': 'Alt',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
641 '19': 'Pause',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
642 '20': 'CapsLock',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
643 '27': 'Escape',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
644 '32': ' ',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
645 '33': 'PageUp',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
646 '34': 'PageDown',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
647 '35': 'End',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
648 '36': 'Home',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
649 '37': 'ArrowLeft',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
650 '38': 'ArrowUp',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
651 '39': 'ArrowRight',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
652 '40': 'ArrowDown',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
653 '45': 'Insert',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
654 '46': 'Delete',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
655 '112': 'F1',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
656 '113': 'F2',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
657 '114': 'F3',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
658 '115': 'F4',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
659 '116': 'F5',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
660 '117': 'F6',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
661 '118': 'F7',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
662 '119': 'F8',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
663 '120': 'F9',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
664 '121': 'F10',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
665 '122': 'F11',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
666 '123': 'F12',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
667 '144': 'NumLock',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
668 '145': 'ScrollLock',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
669 '224': 'Meta'
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 * @param {object} nativeEvent Native browser event.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
673 * @return {string} Normalized `key` property.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
674 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
675
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
676 function getEventKey(nativeEvent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
677 if (nativeEvent.key) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
678 // Normalize inconsistent values reported by browsers due to
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
679 // implementations of a working draft specification.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
680 // FireFox implements `key` but returns `MozPrintableKey` for all
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
681 // printable characters (normalized to `Unidentified`), ignore it.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
682 var key = normalizeKey[nativeEvent.key] || nativeEvent.key;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
683
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
684 if (key !== 'Unidentified') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
685 return key;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
686 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
687 } // 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
688
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 if (nativeEvent.type === 'keypress') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
691 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
692 // 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
693
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
694 return charCode === 13 ? 'Enter' : String.fromCharCode(charCode);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
695 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
696
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
697 if (nativeEvent.type === 'keydown' || nativeEvent.type === 'keyup') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
698 // While user keyboard layout determines the actual meaning of each
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
699 // `keyCode` value, almost all function keys have a universal value.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
700 return translateToKey[nativeEvent.keyCode] || 'Unidentified';
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
703 return '';
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 * 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
707 * @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
708 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
709
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
710
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
711 var modifierKeyToProp = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
712 Alt: 'altKey',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
713 Control: 'ctrlKey',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
714 Meta: 'metaKey',
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
715 Shift: 'shiftKey'
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
716 }; // 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
717 // 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
718 // 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
719
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
720 function modifierStateGetter(keyArg) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
721 var syntheticEvent = this;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
722 var nativeEvent = syntheticEvent.nativeEvent;
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 if (nativeEvent.getModifierState) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
725 return nativeEvent.getModifierState(keyArg);
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 var keyProp = modifierKeyToProp[keyArg];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
729 return keyProp ? !!nativeEvent[keyProp] : false;
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 function getEventModifierState(nativeEvent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
733 return modifierStateGetter;
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 * @interface KeyboardEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
737 * @see http://www.w3.org/TR/DOM-Level-3-Events/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
738 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
739
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
740
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
741 var KeyboardEventInterface = assign({}, UIEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
742 key: getEventKey,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
743 code: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
744 location: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
745 ctrlKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
746 shiftKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
747 altKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
748 metaKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
749 repeat: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
750 locale: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
751 getModifierState: getEventModifierState,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
752 // Legacy Interface
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
753 charCode: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
754 // `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
755 // the actual printable character.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
756 // 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
757 // implemented in any major browser. Only KeyPress has charCode.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
758 if (event.type === 'keypress') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
759 return getEventCharCode(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
760 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
761
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
762 return 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
763 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
764 keyCode: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
765 // `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
766 // physical keyboard key.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
767 // 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
768 // 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
769 // provides a surprisingly accurate mapping for US and European users.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
770 // 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
771 if (event.type === 'keydown' || event.type === 'keyup') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
772 return event.keyCode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
773 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
774
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
775 return 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
776 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
777 which: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
778 // `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
779 // type of the event.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
780 if (event.type === 'keypress') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
781 return getEventCharCode(event);
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 if (event.type === 'keydown' || event.type === 'keyup') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
785 return event.keyCode;
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 return 0;
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 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
791
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
792 var SyntheticKeyboardEvent = createSyntheticEvent(KeyboardEventInterface);
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 * @interface PointerEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
795 * @see http://www.w3.org/TR/pointerevents/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
796 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
797
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
798 var PointerEventInterface = assign({}, MouseEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
799 pointerId: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
800 width: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
801 height: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
802 pressure: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
803 tangentialPressure: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
804 tiltX: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
805 tiltY: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
806 twist: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
807 pointerType: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
808 isPrimary: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
809 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
810
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
811 var SyntheticPointerEvent = createSyntheticEvent(PointerEventInterface);
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 * @interface TouchEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
814 * @see http://www.w3.org/TR/touch-events/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
815 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
816
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
817 var TouchEventInterface = assign({}, UIEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
818 touches: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
819 targetTouches: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
820 changedTouches: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
821 altKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
822 metaKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
823 ctrlKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
824 shiftKey: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
825 getModifierState: getEventModifierState
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
826 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
827
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
828 var SyntheticTouchEvent = createSyntheticEvent(TouchEventInterface);
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 * @interface Event
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
831 * @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
832 * @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
833 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
834
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
835 var TransitionEventInterface = assign({}, EventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
836 propertyName: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
837 elapsedTime: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
838 pseudoElement: 0
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
839 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
840
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
841 var SyntheticTransitionEvent = createSyntheticEvent(TransitionEventInterface);
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 * @interface WheelEvent
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
844 * @see http://www.w3.org/TR/DOM-Level-3-Events/
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
845 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
846
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
847 var WheelEventInterface = assign({}, MouseEventInterface, {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
848 deltaX: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
849 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
850 'wheelDeltaX' in event ? -event.wheelDeltaX : 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
851 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
852 deltaY: function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
853 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
854 '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
855 'wheelDelta' in event ? -event.wheelDelta : 0;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
856 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
857 deltaZ: 0,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
858 // 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
859 // 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
860 // 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
861 // ~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
862 deltaMode: 0
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
865 var SyntheticWheelEvent = createSyntheticEvent(WheelEventInterface);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
866
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 * HTML nodeType values that represent the type of the node
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
869 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
870 var ELEMENT_NODE = 1;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
871
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
872 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
873 var funcArgs = Array.prototype.slice.call(arguments, 3);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
874
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
875 try {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
876 func.apply(context, funcArgs);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
877 } catch (error) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
878 this.onError(error);
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
882 var invokeGuardedCallbackImpl = invokeGuardedCallbackProd;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
883
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
884 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
885 // 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
886 // 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
887 // "Pause on exceptions" behavior. Because React wraps all user-provided
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
888 // functions in invokeGuardedCallback, and the production version of
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
889 // invokeGuardedCallback uses a try-catch, all user exceptions are treated
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
890 // 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
891 // 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
892 // 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
893 // the developer's perspective, the error is uncaught.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
894 //
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
895 // 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
896 // 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
897 // 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
898 // 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
899 // 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
900 // 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
901 // Effectively, this gives us try-catch behavior without actually using
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
902 // try-catch. Neat!
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
903 // 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
904 // DEV version of invokeGuardedCallback
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
905 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
906 var fakeNode = document.createElement('react');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
907
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
908 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
909 // 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
910 // when we call document.createEvent(). However this can cause confusing
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
911 // errors: https://github.com/facebook/create-react-app/issues/3482
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
912 // So we preemptively throw with a better message instead.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
913 if (typeof document === 'undefined' || document === null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
914 throw new Error('The `document` global was defined when React was initialized, but is not ' + 'defined anymore. This can happen in a test environment if a component ' + 'schedules an update from an asynchronous callback, but the test has already ' + 'finished running. To solve this, you can either unmount the component at ' + 'the end of your test (and ensure that any asynchronous operations get ' + 'canceled in `componentWillUnmount`), or you can change the test itself ' + 'to be asynchronous.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
915 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
916
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
917 var evt = document.createEvent('Event');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
918 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
919 // 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
920 // 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
921 // 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
922 // 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
923 // the error event at all.
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 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
926 // 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
927 // browsers that support it.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
928
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
929 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
930 // dispatching: https://github.com/facebook/react/issues/13688
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
931
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
932 var windowEventDescriptor = Object.getOwnPropertyDescriptor(window, 'event');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
933
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
934 function restoreAfterDispatch() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
935 // We immediately remove the callback from event listeners so that
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
936 // nested `invokeGuardedCallback` calls do not clash. Otherwise, a
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
937 // 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
938 // in the stack.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
939 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
940 // 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
941 // "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
942 // support window.event.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
943
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
944 if (typeof window.event !== 'undefined' && window.hasOwnProperty('event')) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
945 window.event = windowEvent;
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 } // 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
948 // dispatch our fake event using `dispatchEvent`. Inside the handler, we
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
949 // call the user-provided callback.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
950
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
951
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
952 var funcArgs = Array.prototype.slice.call(arguments, 3);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
953
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
954 function callCallback() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
955 didCall = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
956 restoreAfterDispatch();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
957 func.apply(context, funcArgs);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
958 didError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
959 } // 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
960 // 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
961 // 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
962 // 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
963 // 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
964 // 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
965 // 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
966 // 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
967 // 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
968 // 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
969 // ignore it because `didError` will be false, as described above.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
970
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
971
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
972 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
973
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
974 var didSetError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
975 var isCrossOriginError = false;
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 function handleWindowError(event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
978 error = event.error;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
979 didSetError = true;
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 (error === null && event.colno === 0 && event.lineno === 0) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
982 isCrossOriginError = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
983 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
984
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
985 if (event.defaultPrevented) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
986 // Some other error handler has prevented default.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
987 // Browsers silence the error report if this happens.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
988 // 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
989 if (error != null && typeof error === 'object') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
990 try {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
991 error._suppressLogging = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
992 } catch (inner) {// Ignore.
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 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
996 } // Create a fake event type.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
997
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
998
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
999 var evtType = "react-" + (name ? name : 'invokeguardedcallback'); // Attach our event handlers
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 window.addEventListener('error', handleWindowError);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1002 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
1003 // errors, it will trigger our global error handler.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1004
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1005 evt.initEvent(evtType, false, false);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1006 fakeNode.dispatchEvent(evt);
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 (windowEventDescriptor) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1009 Object.defineProperty(window, 'event', windowEventDescriptor);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1010 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1011
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1012 if (didCall && didError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1013 if (!didSetError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1014 // The callback errored, but the error event never fired.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1015 // eslint-disable-next-line react-internal/prod-error-codes
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1016 error = new Error('An error was thrown inside one of your components, but React ' + "doesn't know what it was. This is likely due to browser " + 'flakiness. React does its best to preserve the "Pause on ' + 'exceptions" behavior of the DevTools, which requires some ' + "DEV-mode only tricks. It's possible that these don't work in " + 'your browser. Try triggering the error in production mode, ' + 'or switching to a modern browser. If you suspect that this is ' + 'actually an issue with React, please file an issue.');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1017 } else if (isCrossOriginError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1018 // eslint-disable-next-line react-internal/prod-error-codes
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1019 error = new Error("A cross-origin error was thrown. React doesn't have access to " + 'the actual error object in development. ' + 'See https://reactjs.org/link/crossorigin-error for more information.');
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 this.onError(error);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1023 } // Remove our event listeners
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1024
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1025
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1026 window.removeEventListener('error', handleWindowError);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1027
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1028 if (!didCall) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1029 // Something went really wrong, and our event was not dispatched.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1030 // https://github.com/facebook/react/issues/16734
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1031 // https://github.com/facebook/react/issues/16585
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1032 // Fall back to the production implementation.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1033 restoreAfterDispatch();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1034 return invokeGuardedCallbackProd.apply(this, arguments);
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 };
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 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1039
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1040 var invokeGuardedCallbackImpl$1 = invokeGuardedCallbackImpl;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1041
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1042 var hasError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1043 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
1044
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1045 var hasRethrowError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1046 var rethrowError = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1047 var reporter = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1048 onError: function (error) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1049 hasError = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1050 caughtError = error;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1051 }
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 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1054 * 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
1055 * Returns an error if it throws, otherwise null.
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 * 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
1058 * 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
1059 * implementation in DEV mode.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1060 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1061 * @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
1062 * @param {Function} func The function to invoke
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1063 * @param {*} context The context to use when calling the function
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1064 * @param {...*} args Arguments for function
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1065 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1066
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1067 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
1068 hasError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1069 caughtError = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1070 invokeGuardedCallbackImpl$1.apply(reporter, arguments);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1071 }
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 * 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
1074 * 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
1075 * TODO: See if caughtError and rethrowError can be unified.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1076 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1077 * @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
1078 * @param {Function} func The function to invoke
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1079 * @param {*} context The context to use when calling the function
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1080 * @param {...*} args Arguments for function
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1083 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
1084 invokeGuardedCallback.apply(this, arguments);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1085
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1086 if (hasError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1087 var error = clearCaughtError();
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 if (!hasRethrowError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1090 hasRethrowError = true;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1091 rethrowError = error;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1092 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1093 }
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 * 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
1097 * 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
1098 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1099
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1100 function rethrowCaughtError() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1101 if (hasRethrowError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1102 var error = rethrowError;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1103 hasRethrowError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1104 rethrowError = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1105 throw error;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1106 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1107 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1108 function clearCaughtError() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1109 if (hasError) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1110 var error = caughtError;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1111 hasError = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1112 caughtError = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1113 return error;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1114 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1115 throw new Error('clearCaughtError was called but no error was captured. This error ' + 'is likely caused by a bug in React. Please file an issue.');
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 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1118
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1119 var isArrayImpl = Array.isArray; // eslint-disable-next-line no-redeclare
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 function isArray(a) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1122 return isArrayImpl(a);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1123 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1124
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1125 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
1126 var EventInternals = SecretInternals.Events;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1127 var getInstanceFromNode = EventInternals[0];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1128 var getNodeFromInstance = EventInternals[1];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1129 var getFiberCurrentPropsFromNode = EventInternals[2];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1130 var enqueueStateRestore = EventInternals[3];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1131 var restoreStateIfNeeded = EventInternals[4];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1132 var reactAct = React.unstable_act;
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 function Event(suffix) {}
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 var hasWarnedAboutDeprecatedMockComponent = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1137 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1138 * @class ReactTestUtils
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1139 */
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 function findAllInRenderedFiberTreeInternal(fiber, test) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1142 if (!fiber) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1143 return [];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1144 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1145
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1146 var currentParent = findCurrentFiberUsingSlowPath(fiber);
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 if (!currentParent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1149 return [];
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1152 var node = currentParent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1153 var ret = [];
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 while (true) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1156 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
1157 var publicInst = node.stateNode;
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 if (test(publicInst)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1160 ret.push(publicInst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1161 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1162 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1163
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1164 if (node.child) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1165 node.child.return = node;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1166 node = node.child;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1167 continue;
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 if (node === currentParent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1171 return ret;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1172 }
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 while (!node.sibling) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1175 if (!node.return || node.return === currentParent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1176 return ret;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1179 node = node.return;
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 node.sibling.return = node.return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1183 node = node.sibling;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1184 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1185 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1186
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1187 function validateClassInstance(inst, methodName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1188 if (!inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1189 // This is probably too relaxed but it's existing behavior.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1190 return;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1191 }
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 if (get(inst)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1194 // This is a public instance indeed.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1195 return;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1198 var received;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1199 var stringified = String(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1200
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1201 if (isArray(inst)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1202 received = 'an array';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1203 } else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1204 received = 'a DOM node';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1205 } else if (stringified === '[object Object]') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1206 received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1207 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1208 received = stringified;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1211 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
1212 }
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 * Utilities for making it easy to test React components.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1215 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1216 * See https://reactjs.org/docs/test-utils.html
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 * 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
1219 * utilities will suffice for testing purposes.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1220 * @lends ReactTestUtils
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
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 var didWarnAboutReactTestUtilsDeprecation = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1225
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1226 function renderIntoDocument(element) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1227 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1228 if (!didWarnAboutReactTestUtilsDeprecation) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1229 didWarnAboutReactTestUtilsDeprecation = true;
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 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
1232 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1233 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1234
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1235 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
1236 // 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
1237 // 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
1238 // (and probably rename it eventually) if no problems arise.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1239 // document.documentElement.appendChild(div);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1240
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1241 return ReactDOM.render(element, div);
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 isElement(element) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1245 return React.isValidElement(element);
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 isElementOfType(inst, convenienceConstructor) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1249 return React.isValidElement(inst) && inst.type === convenienceConstructor;
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 isDOMComponent(inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1253 return !!(inst && inst.nodeType === ELEMENT_NODE && 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 isDOMComponentElement(inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1257 return !!(inst && React.isValidElement(inst) && !!inst.tagName);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1258 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1259
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1260 function isCompositeComponent(inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1261 if (isDOMComponent(inst)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1262 // 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
1263 // this returns when we have DOM nodes as refs directly
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1264 return false;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1267 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
1268 }
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 function isCompositeComponentWithType(inst, type) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1271 if (!isCompositeComponent(inst)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1272 return false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1273 }
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 var internalInstance = get(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1276 var constructor = internalInstance.type;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1277 return constructor === type;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1280 function findAllInRenderedTree(inst, test) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1281 validateClassInstance(inst, 'findAllInRenderedTree');
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 if (!inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1284 return [];
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 var internalInstance = get(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1288 return findAllInRenderedFiberTreeInternal(internalInstance, test);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1289 }
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 * 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
1292 * components with the class name matching `className`.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1293 * @return {array} an array of all the matches.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1294 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1295
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1296
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1297 function scryRenderedDOMComponentsWithClass(root, classNames) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1298 validateClassInstance(root, 'scryRenderedDOMComponentsWithClass');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1299 return findAllInRenderedTree(root, function (inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1300 if (isDOMComponent(inst)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1301 var className = inst.className;
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 if (typeof className !== 'string') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1304 // SVG, probably.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1305 className = inst.getAttribute('class') || '';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1306 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1307
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1308 var classList = className.split(/\s+/);
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 if (!isArray(classNames)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1311 if (classNames === undefined) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1312 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
1313 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1314
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1315 classNames = classNames.split(/\s+/);
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 return classNames.every(function (name) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1319 return classList.indexOf(name) !== -1;
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 return false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1324 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1325 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1326 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1327 * Like scryRenderedDOMComponentsWithClass but expects there to be one result,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1328 * 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
1329 * number of matches besides one.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1330 * @return {!ReactDOMComponent} The one match.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1331 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1332
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 function findRenderedDOMComponentWithClass(root, className) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1335 validateClassInstance(root, 'findRenderedDOMComponentWithClass');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1336 var all = scryRenderedDOMComponentsWithClass(root, className);
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 if (all.length !== 1) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1339 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
1340 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1341
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1342 return all[0];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1343 }
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 * 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
1346 * components with the tag name matching `tagName`.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1347 * @return {array} an array of all the matches.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1348 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1349
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1350
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1351 function scryRenderedDOMComponentsWithTag(root, tagName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1352 validateClassInstance(root, 'scryRenderedDOMComponentsWithTag');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1353 return findAllInRenderedTree(root, function (inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1354 return isDOMComponent(inst) && inst.tagName.toUpperCase() === tagName.toUpperCase();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1355 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1356 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1357 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1358 * Like scryRenderedDOMComponentsWithTag but expects there to be one result,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1359 * 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
1360 * number of matches besides one.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1361 * @return {!ReactDOMComponent} The one match.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1362 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1363
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 function findRenderedDOMComponentWithTag(root, tagName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1366 validateClassInstance(root, 'findRenderedDOMComponentWithTag');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1367 var all = scryRenderedDOMComponentsWithTag(root, tagName);
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 if (all.length !== 1) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1370 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
1371 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1372
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1373 return all[0];
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 * Finds all instances of components with type equal to `componentType`.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1377 * @return {array} an array of all the matches.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1378 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1379
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1380
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1381 function scryRenderedComponentsWithType(root, componentType) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1382 validateClassInstance(root, 'scryRenderedComponentsWithType');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1383 return findAllInRenderedTree(root, function (inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1384 return isCompositeComponentWithType(inst, componentType);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1385 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1386 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1387 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1388 * Same as `scryRenderedComponentsWithType` but expects there to be one result
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1389 * 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
1390 * number of matches besides one.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1391 * @return {!ReactComponent} The one match.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1392 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1393
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 function findRenderedComponentWithType(root, componentType) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1396 validateClassInstance(root, 'findRenderedComponentWithType');
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1397 var all = scryRenderedComponentsWithType(root, componentType);
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 if (all.length !== 1) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1400 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
1401 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1402
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1403 return all[0];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1404 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1405 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1406 * 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
1407 * 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
1408 * 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
1409 * <div> containing any provided children.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1410 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1411 * @param {object} module the mock function object exported from a
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1412 * module that defines the component to be mocked
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1413 * @param {?string} mockTagName optional dummy root tag name to return
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1414 * from render method (overrides
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1415 * module.mockTagName if provided)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1416 * @return {object} the ReactTestUtils object (for chaining)
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1419
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1420 function mockComponent(module, mockTagName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1421 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1422 if (!hasWarnedAboutDeprecatedMockComponent) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1423 hasWarnedAboutDeprecatedMockComponent = true;
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 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
1426 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1427 }
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 mockTagName = mockTagName || module.mockTagName || 'div';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1430 module.prototype.render.mockImplementation(function () {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1431 return React.createElement(mockTagName, null, this.props.children);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1432 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1433 return this;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1434 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1435
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1436 function nativeTouchData(x, y) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1437 return {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1438 touches: [{
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1439 pageX: x,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1440 pageY: y
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1441 }]
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 } // Start of inline: the below functions were inlined from
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1444 // EventPropagator.js, as they deviated from ReactDOM's newer
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1445 // implementations.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1446
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1447 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1448 * Dispatch the event to the listener.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1449 * @param {SyntheticEvent} event SyntheticEvent to handle
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1450 * @param {function} listener Application-level callback
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1451 * @param {*} inst Internal component instance
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1452 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1453
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1454
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1455 function executeDispatch(event, listener, inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1456 var type = event.type || 'unknown-event';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1457 event.currentTarget = getNodeFromInstance(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1458 invokeGuardedCallbackAndCatchFirstError(type, listener, undefined, event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1459 event.currentTarget = null;
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 * Standard/simple iteration through an event's collected dispatches.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1463 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1464
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 function executeDispatchesInOrder(event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1467 var dispatchListeners = event._dispatchListeners;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1468 var dispatchInstances = event._dispatchInstances;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1469
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1470 if (isArray(dispatchListeners)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1471 for (var i = 0; i < dispatchListeners.length; i++) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1472 if (event.isPropagationStopped()) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1473 break;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1474 } // 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
1475
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1476
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1477 executeDispatch(event, dispatchListeners[i], dispatchInstances[i]);
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 } else if (dispatchListeners) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1480 executeDispatch(event, dispatchListeners, dispatchInstances);
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 event._dispatchListeners = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1484 event._dispatchInstances = null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1485 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1486 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1487 * 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
1488 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1489 * @param {?object} event Synthetic event to be dispatched.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1490 * @private
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1491 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1492
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 var executeDispatchesAndRelease = function (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1495 if (event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1496 executeDispatchesInOrder(event);
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 if (!event.isPersistent()) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1499 event.constructor.release(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1500 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1501 }
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 isInteractive(tag) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1505 return tag === 'button' || tag === 'input' || tag === 'select' || tag === 'textarea';
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1506 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1507
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1508 function getParent(inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1509 do {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1510 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
1511 // 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
1512 // 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
1513 // 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
1514 // do the portal feature.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1515 } while (inst && inst.tag !== HostComponent);
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 if (inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1518 return inst;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1521 return null;
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 * 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
1525 */
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1528 function traverseTwoPhase(inst, fn, arg) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1529 var path = [];
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 while (inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1532 path.push(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1533 inst = getParent(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1534 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1535
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1536 var i;
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 = path.length; i-- > 0;) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1539 fn(path[i], 'captured', 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 for (i = 0; i < path.length; i++) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1543 fn(path[i], 'bubbled', arg);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1544 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1545 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1546
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1547 function shouldPreventMouseEvent(name, type, props) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1548 switch (name) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1549 case 'onClick':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1550 case 'onClickCapture':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1551 case 'onDoubleClick':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1552 case 'onDoubleClickCapture':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1553 case 'onMouseDown':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1554 case 'onMouseDownCapture':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1555 case 'onMouseMove':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1556 case 'onMouseMoveCapture':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1557 case 'onMouseUp':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1558 case 'onMouseUpCapture':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1559 case 'onMouseEnter':
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1560 return !!(props.disabled && isInteractive(type));
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 default:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1563 return false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1564 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1565 }
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 * @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
1568 * @param {string} registrationName Name of listener (e.g. `onClick`).
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1569 * @return {?function} The stored callback.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1570 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1571
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1572
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1573 function getListener(inst, registrationName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1574 // TODO: shouldPreventMouseEvent is DOM-specific and definitely should not
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1575 // 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
1576 var stateNode = inst.stateNode;
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 if (!stateNode) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1579 // Work in progress (ex: onload events in incremental mode).
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1580 return null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1581 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1582
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1583 var props = getFiberCurrentPropsFromNode(stateNode);
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 if (!props) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1586 // Work in progress.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1587 return null;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1588 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1589
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1590 var listener = props[registrationName];
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 (shouldPreventMouseEvent(registrationName, inst.type, props)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1593 return null;
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 if (listener && typeof listener !== 'function') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1597 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
1598 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1599
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1600 return listener;
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1603 function listenerAtPhase(inst, event, propagationPhase) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1604 var registrationName = event._reactName;
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 if (propagationPhase === 'captured') {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1607 registrationName += 'Capture';
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1610 return getListener(inst, registrationName);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1611 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1612
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1613 function accumulateDispatches(inst, ignoredDirection, event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1614 if (inst && event && event._reactName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1615 var registrationName = event._reactName;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1616 var listener = getListener(inst, registrationName);
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 if (listener) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1619 if (event._dispatchListeners == null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1620 event._dispatchListeners = [];
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 if (event._dispatchInstances == null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1624 event._dispatchInstances = [];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1625 }
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 event._dispatchListeners.push(listener);
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 event._dispatchInstances.push(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1630 }
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 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1633
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1634 function accumulateDirectionalDispatches(inst, phase, event) {
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 if (!inst) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1637 error('Dispatching inst must not be null');
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 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1640
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1641 var listener = listenerAtPhase(inst, event, phase);
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 if (listener) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1644 if (event._dispatchListeners == null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1645 event._dispatchListeners = [];
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 if (event._dispatchInstances == null) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1649 event._dispatchInstances = [];
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1650 }
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 event._dispatchListeners.push(listener);
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 event._dispatchInstances.push(inst);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1655 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1656 }
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 function accumulateDirectDispatchesSingle(event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1659 if (event && event._reactName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1660 accumulateDispatches(event._targetInst, null, event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1661 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1662 }
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 function accumulateTwoPhaseDispatchesSingle(event) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1665 if (event && event._reactName) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1666 traverseTwoPhase(event._targetInst, accumulateDirectionalDispatches, event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1667 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1668 } // End of inline
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1671 var Simulate = {};
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1672 var directDispatchEventTypes = new Set(['mouseEnter', 'mouseLeave', 'pointerEnter', 'pointerLeave']);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1673 /**
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1674 * Exports:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1675 *
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1676 * - `Simulate.click(Element)`
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1677 * - `Simulate.mouseMove(Element)`
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1678 * - `Simulate.change(Element)`
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1679 * - ... (All keys from event plugin `eventTypes` objects)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1680 */
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1681
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1682 function makeSimulator(eventType) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1683 return function (domNode, eventData) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1684 if (React.isValidElement(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 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
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 if (isCompositeComponent(domNode)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1689 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
1690 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1691
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1692 var reactName = 'on' + eventType[0].toUpperCase() + eventType.slice(1);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1693 var fakeNativeEvent = new Event();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1694 fakeNativeEvent.target = domNode;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1695 fakeNativeEvent.type = eventType.toLowerCase();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1696 var targetInst = getInstanceFromNode(domNode);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1697 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
1698 // 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
1699
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1700 event.persist();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1701 assign(event, eventData);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1702
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1703 if (directDispatchEventTypes.has(eventType)) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1704 accumulateDirectDispatchesSingle(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1705 } else {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1706 accumulateTwoPhaseDispatchesSingle(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1707 }
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1708
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1709 ReactDOM.unstable_batchedUpdates(function () {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1710 // 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
1711 // do that since we're by-passing it here.
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1712 enqueueStateRestore(domNode);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1713 executeDispatchesAndRelease(event);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1714 rethrowCaughtError();
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 restoreStateIfNeeded();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1717 };
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1718 } // 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
1719
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1720
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1721 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
1722
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1723 function buildSimulators() {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1724 simulatedEventTypes.forEach(function (eventType) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1725 Simulate[eventType] = makeSimulator(eventType);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1726 });
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1727 }
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 buildSimulators();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1730 var didWarnAboutUsingAct = false;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1731 var act = function actWithWarning(callback) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1732 {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1733 if (!didWarnAboutUsingAct) {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1734 didWarnAboutUsingAct = true;
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 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
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
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1740 return reactAct(callback);
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1741 } ;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1742
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1743 exports.Simulate = Simulate;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1744 exports.act = act;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1745 exports.findAllInRenderedTree = findAllInRenderedTree;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1746 exports.findRenderedComponentWithType = findRenderedComponentWithType;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1747 exports.findRenderedDOMComponentWithClass = findRenderedDOMComponentWithClass;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1748 exports.findRenderedDOMComponentWithTag = findRenderedDOMComponentWithTag;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1749 exports.isCompositeComponent = isCompositeComponent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1750 exports.isCompositeComponentWithType = isCompositeComponentWithType;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1751 exports.isDOMComponent = isDOMComponent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1752 exports.isDOMComponentElement = isDOMComponentElement;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1753 exports.isElement = isElement;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1754 exports.isElementOfType = isElementOfType;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1755 exports.mockComponent = mockComponent;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1756 exports.nativeTouchData = nativeTouchData;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1757 exports.renderIntoDocument = renderIntoDocument;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1758 exports.scryRenderedComponentsWithType = scryRenderedComponentsWithType;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1759 exports.scryRenderedDOMComponentsWithClass = scryRenderedDOMComponentsWithClass;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1760 exports.scryRenderedDOMComponentsWithTag = scryRenderedDOMComponentsWithTag;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1761 exports.traverseTwoPhase = traverseTwoPhase;
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1762 })();
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
1763 }