react-dom 16.1.2 → 16.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/react-dom-server.browser.development.js +68 -51
- package/cjs/react-dom-server.browser.production.min.js +20 -19
- package/cjs/react-dom-server.node.development.js +69 -52
- package/cjs/react-dom-server.node.production.min.js +22 -21
- package/cjs/react-dom-test-utils.development.js +8 -1
- package/cjs/react-dom-test-utils.production.min.js +2 -1
- package/cjs/react-dom-unstable-native-dependencies.development.js +3 -1
- package/cjs/react-dom-unstable-native-dependencies.production.min.js +2 -1
- package/cjs/react-dom.development.js +297 -303
- package/cjs/react-dom.production.min.js +209 -207
- package/package.json +1 -1
- package/umd/react-dom-server.browser.development.js +120 -105
- package/umd/react-dom-server.browser.production.min.js +26 -27
- package/umd/react-dom-test-utils.development.js +1247 -0
- package/umd/react-dom-test-utils.production.min.js +29 -0
- package/umd/react-dom-unstable-native-dependencies.development.js +16 -16
- package/umd/react-dom-unstable-native-dependencies.production.min.js +1 -1
- package/umd/react-dom.development.js +511 -519
- package/umd/react-dom.production.min.js +182 -182
|
@@ -0,0 +1,1247 @@
|
|
|
1
|
+
/** @license React v16.2.0
|
|
2
|
+
* react-dom-test-utils.development.js
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
|
5
|
+
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
(function (global, factory) {
|
|
13
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('react'), require('react-dom')) :
|
|
14
|
+
typeof define === 'function' && define.amd ? define(['react', 'react-dom'], factory) :
|
|
15
|
+
(global.ReactTestUtils = factory(global.React,global.ReactDOM));
|
|
16
|
+
}(this, (function (React,ReactDOM) { 'use strict';
|
|
17
|
+
|
|
18
|
+
var ReactInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
19
|
+
|
|
20
|
+
var _assign = ReactInternals.assign;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* WARNING: DO NOT manually require this module.
|
|
24
|
+
* This is a replacement for `invariant(...)` used by the error code system
|
|
25
|
+
* and will _only_ be required by the corresponding babel pass.
|
|
26
|
+
* It always throws.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
|
31
|
+
*
|
|
32
|
+
* This source code is licensed under the MIT license found in the
|
|
33
|
+
* LICENSE file in the root directory of this source tree.
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Use invariant() to assert state which your program assumes to be true.
|
|
41
|
+
*
|
|
42
|
+
* Provide sprintf-style format (only %s is supported) and arguments
|
|
43
|
+
* to provide information about what broke and what you were
|
|
44
|
+
* expecting.
|
|
45
|
+
*
|
|
46
|
+
* The invariant message will be stripped in production, but the invariant
|
|
47
|
+
* will remain to ensure logic does not differ in production.
|
|
48
|
+
*/
|
|
49
|
+
|
|
50
|
+
var validateFormat = function validateFormat(format) {};
|
|
51
|
+
|
|
52
|
+
{
|
|
53
|
+
validateFormat = function validateFormat(format) {
|
|
54
|
+
if (format === undefined) {
|
|
55
|
+
throw new Error('invariant requires an error message argument');
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
function invariant(condition, format, a, b, c, d, e, f) {
|
|
61
|
+
validateFormat(format);
|
|
62
|
+
|
|
63
|
+
if (!condition) {
|
|
64
|
+
var error;
|
|
65
|
+
if (format === undefined) {
|
|
66
|
+
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
|
|
67
|
+
} else {
|
|
68
|
+
var args = [a, b, c, d, e, f];
|
|
69
|
+
var argIndex = 0;
|
|
70
|
+
error = new Error(format.replace(/%s/g, function () {
|
|
71
|
+
return args[argIndex++];
|
|
72
|
+
}));
|
|
73
|
+
error.name = 'Invariant Violation';
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
error.framesToPop = 1; // we don't care about invariant's own frame
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
var invariant_1 = invariant;
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
|
85
|
+
*
|
|
86
|
+
* This source code is licensed under the MIT license found in the
|
|
87
|
+
* LICENSE file in the root directory of this source tree.
|
|
88
|
+
*
|
|
89
|
+
*
|
|
90
|
+
*/
|
|
91
|
+
|
|
92
|
+
function makeEmptyFunction(arg) {
|
|
93
|
+
return function () {
|
|
94
|
+
return arg;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* This function accepts and discards inputs; it has no side effects. This is
|
|
100
|
+
* primarily useful idiomatically for overridable function endpoints which
|
|
101
|
+
* always need to be callable, since JS lacks a null-call idiom ala Cocoa.
|
|
102
|
+
*/
|
|
103
|
+
var emptyFunction = function emptyFunction() {};
|
|
104
|
+
|
|
105
|
+
emptyFunction.thatReturns = makeEmptyFunction;
|
|
106
|
+
emptyFunction.thatReturnsFalse = makeEmptyFunction(false);
|
|
107
|
+
emptyFunction.thatReturnsTrue = makeEmptyFunction(true);
|
|
108
|
+
emptyFunction.thatReturnsNull = makeEmptyFunction(null);
|
|
109
|
+
emptyFunction.thatReturnsThis = function () {
|
|
110
|
+
return this;
|
|
111
|
+
};
|
|
112
|
+
emptyFunction.thatReturnsArgument = function (arg) {
|
|
113
|
+
return arg;
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
var emptyFunction_1 = emptyFunction;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Copyright (c) 2014-present, Facebook, Inc.
|
|
120
|
+
*
|
|
121
|
+
* This source code is licensed under the MIT license found in the
|
|
122
|
+
* LICENSE file in the root directory of this source tree.
|
|
123
|
+
*
|
|
124
|
+
*/
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Similar to invariant but only logs a warning if the condition is not met.
|
|
132
|
+
* This can be used to log issues in development environments in critical
|
|
133
|
+
* paths. Removing the logging code for production environments will keep the
|
|
134
|
+
* same logic and follow the same code paths.
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
var warning = emptyFunction_1;
|
|
138
|
+
|
|
139
|
+
{
|
|
140
|
+
var printWarning = function printWarning(format) {
|
|
141
|
+
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
142
|
+
args[_key - 1] = arguments[_key];
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
var argIndex = 0;
|
|
146
|
+
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
|
147
|
+
return args[argIndex++];
|
|
148
|
+
});
|
|
149
|
+
if (typeof console !== 'undefined') {
|
|
150
|
+
console.error(message);
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
// --- Welcome to debugging React ---
|
|
154
|
+
// This error was thrown as a convenience so that you can use this stack
|
|
155
|
+
// to find the callsite that caused this warning to fire.
|
|
156
|
+
throw new Error(message);
|
|
157
|
+
} catch (x) {}
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
warning = function warning(condition, format) {
|
|
161
|
+
if (format === undefined) {
|
|
162
|
+
throw new Error('`warning(condition, format, ...args)` requires a warning ' + 'message argument');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (format.indexOf('Failed Composite propType: ') === 0) {
|
|
166
|
+
return; // Ignore CompositeComponent proptype check.
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
if (!condition) {
|
|
170
|
+
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
171
|
+
args[_key2 - 2] = arguments[_key2];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
printWarning.apply(undefined, [format].concat(args));
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
var warning_1 = warning;
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* `ReactInstanceMap` maintains a mapping from a public facing stateful
|
|
183
|
+
* instance (key) and the internal representation (value). This allows public
|
|
184
|
+
* methods to accept the user facing instance as an argument and map them back
|
|
185
|
+
* to internal methods.
|
|
186
|
+
*
|
|
187
|
+
* Note that this module is currently shared and assumed to be stateless.
|
|
188
|
+
* If this becomes an actual Map, that will break.
|
|
189
|
+
*/
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* This API should be called `delete` but we'd have to make sure to always
|
|
193
|
+
* transform these to strings for IE support. When this transform is fully
|
|
194
|
+
* supported we can rename it.
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
function get(key) {
|
|
199
|
+
return key._reactInternalFiber;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
var ReactInternals$1 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
203
|
+
|
|
204
|
+
var ReactCurrentOwner = ReactInternals$1.ReactCurrentOwner;
|
|
205
|
+
var ReactDebugCurrentFrame = ReactInternals$1.ReactDebugCurrentFrame;
|
|
206
|
+
|
|
207
|
+
// Before we know whether it is functional or class
|
|
208
|
+
var FunctionalComponent = 1;
|
|
209
|
+
var ClassComponent = 2;
|
|
210
|
+
var HostRoot = 3; // Root of a host tree. Could be nested inside another node.
|
|
211
|
+
// A subtree. Could be an entry point to a different renderer.
|
|
212
|
+
var HostComponent = 5;
|
|
213
|
+
var HostText = 6;
|
|
214
|
+
|
|
215
|
+
// Don't change these two values:
|
|
216
|
+
var NoEffect = 0; // 0b00000000
|
|
217
|
+
// 0b00000001
|
|
218
|
+
|
|
219
|
+
// You can change the rest (and add more).
|
|
220
|
+
var Placement = 2; // 0b00000010
|
|
221
|
+
// 0b00000100
|
|
222
|
+
// 0b00000110
|
|
223
|
+
// 0b00001000
|
|
224
|
+
// 0b00010000
|
|
225
|
+
// 0b00100000
|
|
226
|
+
// 0b01000000
|
|
227
|
+
// 0b10000000
|
|
228
|
+
|
|
229
|
+
var MOUNTING = 1;
|
|
230
|
+
var MOUNTED = 2;
|
|
231
|
+
var UNMOUNTED = 3;
|
|
232
|
+
|
|
233
|
+
function isFiberMountedImpl(fiber) {
|
|
234
|
+
var node = fiber;
|
|
235
|
+
if (!fiber.alternate) {
|
|
236
|
+
// If there is no alternate, this might be a new tree that isn't inserted
|
|
237
|
+
// yet. If it is, then it will have a pending insertion effect on it.
|
|
238
|
+
if ((node.effectTag & Placement) !== NoEffect) {
|
|
239
|
+
return MOUNTING;
|
|
240
|
+
}
|
|
241
|
+
while (node['return']) {
|
|
242
|
+
node = node['return'];
|
|
243
|
+
if ((node.effectTag & Placement) !== NoEffect) {
|
|
244
|
+
return MOUNTING;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
while (node['return']) {
|
|
249
|
+
node = node['return'];
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
if (node.tag === HostRoot) {
|
|
253
|
+
// TODO: Check if this was a nested HostRoot when used with
|
|
254
|
+
// renderContainerIntoSubtree.
|
|
255
|
+
return MOUNTED;
|
|
256
|
+
}
|
|
257
|
+
// If we didn't hit the root, that means that we're in an disconnected tree
|
|
258
|
+
// that has been unmounted.
|
|
259
|
+
return UNMOUNTED;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
function assertIsMounted(fiber) {
|
|
267
|
+
!(isFiberMountedImpl(fiber) === MOUNTED) ? invariant_1(false, 'Unable to find node on an unmounted component.') : void 0;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function findCurrentFiberUsingSlowPath(fiber) {
|
|
271
|
+
var alternate = fiber.alternate;
|
|
272
|
+
if (!alternate) {
|
|
273
|
+
// If there is no alternate, then we only need to check if it is mounted.
|
|
274
|
+
var state = isFiberMountedImpl(fiber);
|
|
275
|
+
!(state !== UNMOUNTED) ? invariant_1(false, 'Unable to find node on an unmounted component.') : void 0;
|
|
276
|
+
if (state === MOUNTING) {
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
return fiber;
|
|
280
|
+
}
|
|
281
|
+
// If we have two possible branches, we'll walk backwards up to the root
|
|
282
|
+
// to see what path the root points to. On the way we may hit one of the
|
|
283
|
+
// special cases and we'll deal with them.
|
|
284
|
+
var a = fiber;
|
|
285
|
+
var b = alternate;
|
|
286
|
+
while (true) {
|
|
287
|
+
var parentA = a['return'];
|
|
288
|
+
var parentB = parentA ? parentA.alternate : null;
|
|
289
|
+
if (!parentA || !parentB) {
|
|
290
|
+
// We're at the root.
|
|
291
|
+
break;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// If both copies of the parent fiber point to the same child, we can
|
|
295
|
+
// assume that the child is current. This happens when we bailout on low
|
|
296
|
+
// priority: the bailed out fiber's child reuses the current child.
|
|
297
|
+
if (parentA.child === parentB.child) {
|
|
298
|
+
var child = parentA.child;
|
|
299
|
+
while (child) {
|
|
300
|
+
if (child === a) {
|
|
301
|
+
// We've determined that A is the current branch.
|
|
302
|
+
assertIsMounted(parentA);
|
|
303
|
+
return fiber;
|
|
304
|
+
}
|
|
305
|
+
if (child === b) {
|
|
306
|
+
// We've determined that B is the current branch.
|
|
307
|
+
assertIsMounted(parentA);
|
|
308
|
+
return alternate;
|
|
309
|
+
}
|
|
310
|
+
child = child.sibling;
|
|
311
|
+
}
|
|
312
|
+
// We should never have an alternate for any mounting node. So the only
|
|
313
|
+
// way this could possibly happen is if this was unmounted, if at all.
|
|
314
|
+
invariant_1(false, 'Unable to find node on an unmounted component.');
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
if (a['return'] !== b['return']) {
|
|
318
|
+
// The return pointer of A and the return pointer of B point to different
|
|
319
|
+
// fibers. We assume that return pointers never criss-cross, so A must
|
|
320
|
+
// belong to the child set of A.return, and B must belong to the child
|
|
321
|
+
// set of B.return.
|
|
322
|
+
a = parentA;
|
|
323
|
+
b = parentB;
|
|
324
|
+
} else {
|
|
325
|
+
// The return pointers point to the same fiber. We'll have to use the
|
|
326
|
+
// default, slow path: scan the child sets of each parent alternate to see
|
|
327
|
+
// which child belongs to which set.
|
|
328
|
+
//
|
|
329
|
+
// Search parent A's child set
|
|
330
|
+
var didFindChild = false;
|
|
331
|
+
var _child = parentA.child;
|
|
332
|
+
while (_child) {
|
|
333
|
+
if (_child === a) {
|
|
334
|
+
didFindChild = true;
|
|
335
|
+
a = parentA;
|
|
336
|
+
b = parentB;
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
if (_child === b) {
|
|
340
|
+
didFindChild = true;
|
|
341
|
+
b = parentA;
|
|
342
|
+
a = parentB;
|
|
343
|
+
break;
|
|
344
|
+
}
|
|
345
|
+
_child = _child.sibling;
|
|
346
|
+
}
|
|
347
|
+
if (!didFindChild) {
|
|
348
|
+
// Search parent B's child set
|
|
349
|
+
_child = parentB.child;
|
|
350
|
+
while (_child) {
|
|
351
|
+
if (_child === a) {
|
|
352
|
+
didFindChild = true;
|
|
353
|
+
a = parentB;
|
|
354
|
+
b = parentA;
|
|
355
|
+
break;
|
|
356
|
+
}
|
|
357
|
+
if (_child === b) {
|
|
358
|
+
didFindChild = true;
|
|
359
|
+
b = parentB;
|
|
360
|
+
a = parentA;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
_child = _child.sibling;
|
|
364
|
+
}
|
|
365
|
+
!didFindChild ? invariant_1(false, 'Child was not found in either parent set. This indicates a bug in React related to the return pointer. Please file an issue.') : void 0;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
!(a.alternate === b) ? invariant_1(false, 'Return fibers should always be each others\' alternates. This error is likely caused by a bug in React. Please file an issue.') : void 0;
|
|
370
|
+
}
|
|
371
|
+
// If the root is not a host container, we're in a disconnected tree. I.e.
|
|
372
|
+
// unmounted.
|
|
373
|
+
!(a.tag === HostRoot) ? invariant_1(false, 'Unable to find node on an unmounted component.') : void 0;
|
|
374
|
+
if (a.stateNode.current === a) {
|
|
375
|
+
// We've determined that A is the current branch.
|
|
376
|
+
return fiber;
|
|
377
|
+
}
|
|
378
|
+
// Otherwise B has to be current branch.
|
|
379
|
+
return alternate;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/* eslint valid-typeof: 0 */
|
|
383
|
+
|
|
384
|
+
var didWarnForAddedNewProperty = false;
|
|
385
|
+
var isProxySupported = typeof Proxy === 'function';
|
|
386
|
+
var EVENT_POOL_SIZE = 10;
|
|
387
|
+
|
|
388
|
+
var shouldBeReleasedProperties = ['dispatchConfig', '_targetInst', 'nativeEvent', 'isDefaultPrevented', 'isPropagationStopped', '_dispatchListeners', '_dispatchInstances'];
|
|
389
|
+
|
|
390
|
+
/**
|
|
391
|
+
* @interface Event
|
|
392
|
+
* @see http://www.w3.org/TR/DOM-Level-3-Events/
|
|
393
|
+
*/
|
|
394
|
+
var EventInterface = {
|
|
395
|
+
type: null,
|
|
396
|
+
target: null,
|
|
397
|
+
// currentTarget is set when dispatching; no use in copying it here
|
|
398
|
+
currentTarget: emptyFunction_1.thatReturnsNull,
|
|
399
|
+
eventPhase: null,
|
|
400
|
+
bubbles: null,
|
|
401
|
+
cancelable: null,
|
|
402
|
+
timeStamp: function (event) {
|
|
403
|
+
return event.timeStamp || Date.now();
|
|
404
|
+
},
|
|
405
|
+
defaultPrevented: null,
|
|
406
|
+
isTrusted: null
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Synthetic events are dispatched by event plugins, typically in response to a
|
|
411
|
+
* top-level event delegation handler.
|
|
412
|
+
*
|
|
413
|
+
* These systems should generally use pooling to reduce the frequency of garbage
|
|
414
|
+
* collection. The system should check `isPersistent` to determine whether the
|
|
415
|
+
* event should be released into the pool after being dispatched. Users that
|
|
416
|
+
* need a persisted event should invoke `persist`.
|
|
417
|
+
*
|
|
418
|
+
* Synthetic events (and subclasses) implement the DOM Level 3 Events API by
|
|
419
|
+
* normalizing browser quirks. Subclasses do not necessarily have to implement a
|
|
420
|
+
* DOM interface; custom application-specific events can also subclass this.
|
|
421
|
+
*
|
|
422
|
+
* @param {object} dispatchConfig Configuration used to dispatch this event.
|
|
423
|
+
* @param {*} targetInst Marker identifying the event target.
|
|
424
|
+
* @param {object} nativeEvent Native browser event.
|
|
425
|
+
* @param {DOMEventTarget} nativeEventTarget Target node.
|
|
426
|
+
*/
|
|
427
|
+
function SyntheticEvent(dispatchConfig, targetInst, nativeEvent, nativeEventTarget) {
|
|
428
|
+
{
|
|
429
|
+
// these have a getter/setter for warnings
|
|
430
|
+
delete this.nativeEvent;
|
|
431
|
+
delete this.preventDefault;
|
|
432
|
+
delete this.stopPropagation;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
this.dispatchConfig = dispatchConfig;
|
|
436
|
+
this._targetInst = targetInst;
|
|
437
|
+
this.nativeEvent = nativeEvent;
|
|
438
|
+
|
|
439
|
+
var Interface = this.constructor.Interface;
|
|
440
|
+
for (var propName in Interface) {
|
|
441
|
+
if (!Interface.hasOwnProperty(propName)) {
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
{
|
|
445
|
+
delete this[propName]; // this has a getter/setter for warnings
|
|
446
|
+
}
|
|
447
|
+
var normalize = Interface[propName];
|
|
448
|
+
if (normalize) {
|
|
449
|
+
this[propName] = normalize(nativeEvent);
|
|
450
|
+
} else {
|
|
451
|
+
if (propName === 'target') {
|
|
452
|
+
this.target = nativeEventTarget;
|
|
453
|
+
} else {
|
|
454
|
+
this[propName] = nativeEvent[propName];
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
|
|
460
|
+
if (defaultPrevented) {
|
|
461
|
+
this.isDefaultPrevented = emptyFunction_1.thatReturnsTrue;
|
|
462
|
+
} else {
|
|
463
|
+
this.isDefaultPrevented = emptyFunction_1.thatReturnsFalse;
|
|
464
|
+
}
|
|
465
|
+
this.isPropagationStopped = emptyFunction_1.thatReturnsFalse;
|
|
466
|
+
return this;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
_assign(SyntheticEvent.prototype, {
|
|
470
|
+
preventDefault: function () {
|
|
471
|
+
this.defaultPrevented = true;
|
|
472
|
+
var event = this.nativeEvent;
|
|
473
|
+
if (!event) {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
if (event.preventDefault) {
|
|
478
|
+
event.preventDefault();
|
|
479
|
+
} else if (typeof event.returnValue !== 'unknown') {
|
|
480
|
+
event.returnValue = false;
|
|
481
|
+
}
|
|
482
|
+
this.isDefaultPrevented = emptyFunction_1.thatReturnsTrue;
|
|
483
|
+
},
|
|
484
|
+
|
|
485
|
+
stopPropagation: function () {
|
|
486
|
+
var event = this.nativeEvent;
|
|
487
|
+
if (!event) {
|
|
488
|
+
return;
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
if (event.stopPropagation) {
|
|
492
|
+
event.stopPropagation();
|
|
493
|
+
} else if (typeof event.cancelBubble !== 'unknown') {
|
|
494
|
+
// The ChangeEventPlugin registers a "propertychange" event for
|
|
495
|
+
// IE. This event does not support bubbling or cancelling, and
|
|
496
|
+
// any references to cancelBubble throw "Member not found". A
|
|
497
|
+
// typeof check of "unknown" circumvents this issue (and is also
|
|
498
|
+
// IE specific).
|
|
499
|
+
event.cancelBubble = true;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
this.isPropagationStopped = emptyFunction_1.thatReturnsTrue;
|
|
503
|
+
},
|
|
504
|
+
|
|
505
|
+
/**
|
|
506
|
+
* We release all dispatched `SyntheticEvent`s after each event loop, adding
|
|
507
|
+
* them back into the pool. This allows a way to hold onto a reference that
|
|
508
|
+
* won't be added back into the pool.
|
|
509
|
+
*/
|
|
510
|
+
persist: function () {
|
|
511
|
+
this.isPersistent = emptyFunction_1.thatReturnsTrue;
|
|
512
|
+
},
|
|
513
|
+
|
|
514
|
+
/**
|
|
515
|
+
* Checks if this event should be released back into the pool.
|
|
516
|
+
*
|
|
517
|
+
* @return {boolean} True if this should not be released, false otherwise.
|
|
518
|
+
*/
|
|
519
|
+
isPersistent: emptyFunction_1.thatReturnsFalse,
|
|
520
|
+
|
|
521
|
+
/**
|
|
522
|
+
* `PooledClass` looks for `destructor` on each instance it releases.
|
|
523
|
+
*/
|
|
524
|
+
destructor: function () {
|
|
525
|
+
var Interface = this.constructor.Interface;
|
|
526
|
+
for (var propName in Interface) {
|
|
527
|
+
{
|
|
528
|
+
Object.defineProperty(this, propName, getPooledWarningPropertyDefinition(propName, Interface[propName]));
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
for (var i = 0; i < shouldBeReleasedProperties.length; i++) {
|
|
532
|
+
this[shouldBeReleasedProperties[i]] = null;
|
|
533
|
+
}
|
|
534
|
+
{
|
|
535
|
+
Object.defineProperty(this, 'nativeEvent', getPooledWarningPropertyDefinition('nativeEvent', null));
|
|
536
|
+
Object.defineProperty(this, 'preventDefault', getPooledWarningPropertyDefinition('preventDefault', emptyFunction_1));
|
|
537
|
+
Object.defineProperty(this, 'stopPropagation', getPooledWarningPropertyDefinition('stopPropagation', emptyFunction_1));
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
SyntheticEvent.Interface = EventInterface;
|
|
543
|
+
|
|
544
|
+
/**
|
|
545
|
+
* Helper to reduce boilerplate when creating subclasses.
|
|
546
|
+
*
|
|
547
|
+
* @param {function} Class
|
|
548
|
+
* @param {?object} Interface
|
|
549
|
+
*/
|
|
550
|
+
SyntheticEvent.augmentClass = function (Class, Interface) {
|
|
551
|
+
var Super = this;
|
|
552
|
+
|
|
553
|
+
var E = function () {};
|
|
554
|
+
E.prototype = Super.prototype;
|
|
555
|
+
var prototype = new E();
|
|
556
|
+
|
|
557
|
+
_assign(prototype, Class.prototype);
|
|
558
|
+
Class.prototype = prototype;
|
|
559
|
+
Class.prototype.constructor = Class;
|
|
560
|
+
|
|
561
|
+
Class.Interface = _assign({}, Super.Interface, Interface);
|
|
562
|
+
Class.augmentClass = Super.augmentClass;
|
|
563
|
+
addEventPoolingTo(Class);
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
/** Proxying after everything set on SyntheticEvent
|
|
567
|
+
* to resolve Proxy issue on some WebKit browsers
|
|
568
|
+
* in which some Event properties are set to undefined (GH#10010)
|
|
569
|
+
*/
|
|
570
|
+
{
|
|
571
|
+
if (isProxySupported) {
|
|
572
|
+
/*eslint-disable no-func-assign */
|
|
573
|
+
SyntheticEvent = new Proxy(SyntheticEvent, {
|
|
574
|
+
construct: function (target, args) {
|
|
575
|
+
return this.apply(target, Object.create(target.prototype), args);
|
|
576
|
+
},
|
|
577
|
+
apply: function (constructor, that, args) {
|
|
578
|
+
return new Proxy(constructor.apply(that, args), {
|
|
579
|
+
set: function (target, prop, value) {
|
|
580
|
+
if (prop !== 'isPersistent' && !target.constructor.Interface.hasOwnProperty(prop) && shouldBeReleasedProperties.indexOf(prop) === -1) {
|
|
581
|
+
warning_1(didWarnForAddedNewProperty || target.isPersistent(), "This synthetic event is reused for performance reasons. If you're " + "seeing this, you're adding a new property in the synthetic event object. " + 'The property is never released. See ' + 'https://fb.me/react-event-pooling for more information.');
|
|
582
|
+
didWarnForAddedNewProperty = true;
|
|
583
|
+
}
|
|
584
|
+
target[prop] = value;
|
|
585
|
+
return true;
|
|
586
|
+
}
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
/*eslint-enable no-func-assign */
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
addEventPoolingTo(SyntheticEvent);
|
|
595
|
+
|
|
596
|
+
/**
|
|
597
|
+
* Helper to nullify syntheticEvent instance properties when destructing
|
|
598
|
+
*
|
|
599
|
+
* @param {String} propName
|
|
600
|
+
* @param {?object} getVal
|
|
601
|
+
* @return {object} defineProperty object
|
|
602
|
+
*/
|
|
603
|
+
function getPooledWarningPropertyDefinition(propName, getVal) {
|
|
604
|
+
var isFunction = typeof getVal === 'function';
|
|
605
|
+
return {
|
|
606
|
+
configurable: true,
|
|
607
|
+
set: set,
|
|
608
|
+
get: get
|
|
609
|
+
};
|
|
610
|
+
|
|
611
|
+
function set(val) {
|
|
612
|
+
var action = isFunction ? 'setting the method' : 'setting the property';
|
|
613
|
+
warn(action, 'This is effectively a no-op');
|
|
614
|
+
return val;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
function get() {
|
|
618
|
+
var action = isFunction ? 'accessing the method' : 'accessing the property';
|
|
619
|
+
var result = isFunction ? 'This is a no-op function' : 'This is set to null';
|
|
620
|
+
warn(action, result);
|
|
621
|
+
return getVal;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
function warn(action, result) {
|
|
625
|
+
var warningCondition = false;
|
|
626
|
+
warning_1(warningCondition, "This synthetic event is reused for performance reasons. If you're seeing this, " + "you're %s `%s` on a released/nullified synthetic event. %s. " + 'If you must keep the original synthetic event around, use event.persist(). ' + 'See https://fb.me/react-event-pooling for more information.', action, propName, result);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) {
|
|
631
|
+
var EventConstructor = this;
|
|
632
|
+
if (EventConstructor.eventPool.length) {
|
|
633
|
+
var instance = EventConstructor.eventPool.pop();
|
|
634
|
+
EventConstructor.call(instance, dispatchConfig, targetInst, nativeEvent, nativeInst);
|
|
635
|
+
return instance;
|
|
636
|
+
}
|
|
637
|
+
return new EventConstructor(dispatchConfig, targetInst, nativeEvent, nativeInst);
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function releasePooledEvent(event) {
|
|
641
|
+
var EventConstructor = this;
|
|
642
|
+
!(event instanceof EventConstructor) ? invariant_1(false, 'Trying to release an event instance into a pool of a different type.') : void 0;
|
|
643
|
+
event.destructor();
|
|
644
|
+
if (EventConstructor.eventPool.length < EVENT_POOL_SIZE) {
|
|
645
|
+
EventConstructor.eventPool.push(event);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
|
|
649
|
+
function addEventPoolingTo(EventConstructor) {
|
|
650
|
+
EventConstructor.eventPool = [];
|
|
651
|
+
EventConstructor.getPooled = getPooledEvent;
|
|
652
|
+
EventConstructor.release = releasePooledEvent;
|
|
653
|
+
}
|
|
654
|
+
|
|
655
|
+
var SyntheticEvent$1 = SyntheticEvent;
|
|
656
|
+
|
|
657
|
+
/**
|
|
658
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
|
659
|
+
*
|
|
660
|
+
* This source code is licensed under the MIT license found in the
|
|
661
|
+
* LICENSE file in the root directory of this source tree.
|
|
662
|
+
*
|
|
663
|
+
*/
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* Simple, lightweight module assisting with the detection and context of
|
|
671
|
+
* Worker. Helps avoid circular dependencies and allows code to reason about
|
|
672
|
+
* whether or not they are in a Worker, even if they never include the main
|
|
673
|
+
* `ReactWorker` dependency.
|
|
674
|
+
*/
|
|
675
|
+
var ExecutionEnvironment = {
|
|
676
|
+
|
|
677
|
+
canUseDOM: canUseDOM,
|
|
678
|
+
|
|
679
|
+
canUseWorkers: typeof Worker !== 'undefined',
|
|
680
|
+
|
|
681
|
+
canUseEventListeners: canUseDOM && !!(window.addEventListener || window.attachEvent),
|
|
682
|
+
|
|
683
|
+
canUseViewport: canUseDOM && !!window.screen,
|
|
684
|
+
|
|
685
|
+
isInWorker: !canUseDOM // For now, this is true - might change in the future.
|
|
686
|
+
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
var ExecutionEnvironment_1 = ExecutionEnvironment;
|
|
690
|
+
|
|
691
|
+
/**
|
|
692
|
+
* Generate a mapping of standard vendor prefixes using the defined style property and event name.
|
|
693
|
+
*
|
|
694
|
+
* @param {string} styleProp
|
|
695
|
+
* @param {string} eventName
|
|
696
|
+
* @returns {object}
|
|
697
|
+
*/
|
|
698
|
+
function makePrefixMap(styleProp, eventName) {
|
|
699
|
+
var prefixes = {};
|
|
700
|
+
|
|
701
|
+
prefixes[styleProp.toLowerCase()] = eventName.toLowerCase();
|
|
702
|
+
prefixes['Webkit' + styleProp] = 'webkit' + eventName;
|
|
703
|
+
prefixes['Moz' + styleProp] = 'moz' + eventName;
|
|
704
|
+
prefixes['ms' + styleProp] = 'MS' + eventName;
|
|
705
|
+
prefixes['O' + styleProp] = 'o' + eventName.toLowerCase();
|
|
706
|
+
|
|
707
|
+
return prefixes;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
/**
|
|
711
|
+
* A list of event names to a configurable list of vendor prefixes.
|
|
712
|
+
*/
|
|
713
|
+
var vendorPrefixes = {
|
|
714
|
+
animationend: makePrefixMap('Animation', 'AnimationEnd'),
|
|
715
|
+
animationiteration: makePrefixMap('Animation', 'AnimationIteration'),
|
|
716
|
+
animationstart: makePrefixMap('Animation', 'AnimationStart'),
|
|
717
|
+
transitionend: makePrefixMap('Transition', 'TransitionEnd')
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
/**
|
|
721
|
+
* Event names that have already been detected and prefixed (if applicable).
|
|
722
|
+
*/
|
|
723
|
+
var prefixedEventNames = {};
|
|
724
|
+
|
|
725
|
+
/**
|
|
726
|
+
* Element to check for prefixes on.
|
|
727
|
+
*/
|
|
728
|
+
var style = {};
|
|
729
|
+
|
|
730
|
+
/**
|
|
731
|
+
* Bootstrap if a DOM exists.
|
|
732
|
+
*/
|
|
733
|
+
if (ExecutionEnvironment_1.canUseDOM) {
|
|
734
|
+
style = document.createElement('div').style;
|
|
735
|
+
|
|
736
|
+
// On some platforms, in particular some releases of Android 4.x,
|
|
737
|
+
// the un-prefixed "animation" and "transition" properties are defined on the
|
|
738
|
+
// style object but the events that fire will still be prefixed, so we need
|
|
739
|
+
// to check if the un-prefixed events are usable, and if not remove them from the map.
|
|
740
|
+
if (!('AnimationEvent' in window)) {
|
|
741
|
+
delete vendorPrefixes.animationend.animation;
|
|
742
|
+
delete vendorPrefixes.animationiteration.animation;
|
|
743
|
+
delete vendorPrefixes.animationstart.animation;
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
// Same as above
|
|
747
|
+
if (!('TransitionEvent' in window)) {
|
|
748
|
+
delete vendorPrefixes.transitionend.transition;
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
/**
|
|
753
|
+
* Attempts to determine the correct vendor prefixed event name.
|
|
754
|
+
*
|
|
755
|
+
* @param {string} eventName
|
|
756
|
+
* @returns {string}
|
|
757
|
+
*/
|
|
758
|
+
function getVendorPrefixedEventName(eventName) {
|
|
759
|
+
if (prefixedEventNames[eventName]) {
|
|
760
|
+
return prefixedEventNames[eventName];
|
|
761
|
+
} else if (!vendorPrefixes[eventName]) {
|
|
762
|
+
return eventName;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
var prefixMap = vendorPrefixes[eventName];
|
|
766
|
+
|
|
767
|
+
for (var styleProp in prefixMap) {
|
|
768
|
+
if (prefixMap.hasOwnProperty(styleProp) && styleProp in style) {
|
|
769
|
+
return prefixedEventNames[eventName] = prefixMap[styleProp];
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
|
|
773
|
+
return '';
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
/**
|
|
777
|
+
* Types of raw signals from the browser caught at the top level.
|
|
778
|
+
*
|
|
779
|
+
* For events like 'submit' which don't consistently bubble (which we
|
|
780
|
+
* trap at a lower node than `document`), binding at `document` would
|
|
781
|
+
* cause duplicate events so we don't include them here.
|
|
782
|
+
*/
|
|
783
|
+
var topLevelTypes$1 = {
|
|
784
|
+
topAbort: 'abort',
|
|
785
|
+
topAnimationEnd: getVendorPrefixedEventName('animationend') || 'animationend',
|
|
786
|
+
topAnimationIteration: getVendorPrefixedEventName('animationiteration') || 'animationiteration',
|
|
787
|
+
topAnimationStart: getVendorPrefixedEventName('animationstart') || 'animationstart',
|
|
788
|
+
topBlur: 'blur',
|
|
789
|
+
topCancel: 'cancel',
|
|
790
|
+
topCanPlay: 'canplay',
|
|
791
|
+
topCanPlayThrough: 'canplaythrough',
|
|
792
|
+
topChange: 'change',
|
|
793
|
+
topClick: 'click',
|
|
794
|
+
topClose: 'close',
|
|
795
|
+
topCompositionEnd: 'compositionend',
|
|
796
|
+
topCompositionStart: 'compositionstart',
|
|
797
|
+
topCompositionUpdate: 'compositionupdate',
|
|
798
|
+
topContextMenu: 'contextmenu',
|
|
799
|
+
topCopy: 'copy',
|
|
800
|
+
topCut: 'cut',
|
|
801
|
+
topDoubleClick: 'dblclick',
|
|
802
|
+
topDrag: 'drag',
|
|
803
|
+
topDragEnd: 'dragend',
|
|
804
|
+
topDragEnter: 'dragenter',
|
|
805
|
+
topDragExit: 'dragexit',
|
|
806
|
+
topDragLeave: 'dragleave',
|
|
807
|
+
topDragOver: 'dragover',
|
|
808
|
+
topDragStart: 'dragstart',
|
|
809
|
+
topDrop: 'drop',
|
|
810
|
+
topDurationChange: 'durationchange',
|
|
811
|
+
topEmptied: 'emptied',
|
|
812
|
+
topEncrypted: 'encrypted',
|
|
813
|
+
topEnded: 'ended',
|
|
814
|
+
topError: 'error',
|
|
815
|
+
topFocus: 'focus',
|
|
816
|
+
topInput: 'input',
|
|
817
|
+
topKeyDown: 'keydown',
|
|
818
|
+
topKeyPress: 'keypress',
|
|
819
|
+
topKeyUp: 'keyup',
|
|
820
|
+
topLoadedData: 'loadeddata',
|
|
821
|
+
topLoad: 'load',
|
|
822
|
+
topLoadedMetadata: 'loadedmetadata',
|
|
823
|
+
topLoadStart: 'loadstart',
|
|
824
|
+
topMouseDown: 'mousedown',
|
|
825
|
+
topMouseMove: 'mousemove',
|
|
826
|
+
topMouseOut: 'mouseout',
|
|
827
|
+
topMouseOver: 'mouseover',
|
|
828
|
+
topMouseUp: 'mouseup',
|
|
829
|
+
topPaste: 'paste',
|
|
830
|
+
topPause: 'pause',
|
|
831
|
+
topPlay: 'play',
|
|
832
|
+
topPlaying: 'playing',
|
|
833
|
+
topProgress: 'progress',
|
|
834
|
+
topRateChange: 'ratechange',
|
|
835
|
+
topScroll: 'scroll',
|
|
836
|
+
topSeeked: 'seeked',
|
|
837
|
+
topSeeking: 'seeking',
|
|
838
|
+
topSelectionChange: 'selectionchange',
|
|
839
|
+
topStalled: 'stalled',
|
|
840
|
+
topSuspend: 'suspend',
|
|
841
|
+
topTextInput: 'textInput',
|
|
842
|
+
topTimeUpdate: 'timeupdate',
|
|
843
|
+
topToggle: 'toggle',
|
|
844
|
+
topTouchCancel: 'touchcancel',
|
|
845
|
+
topTouchEnd: 'touchend',
|
|
846
|
+
topTouchMove: 'touchmove',
|
|
847
|
+
topTouchStart: 'touchstart',
|
|
848
|
+
topTransitionEnd: getVendorPrefixedEventName('transitionend') || 'transitionend',
|
|
849
|
+
topVolumeChange: 'volumechange',
|
|
850
|
+
topWaiting: 'waiting',
|
|
851
|
+
topWheel: 'wheel'
|
|
852
|
+
};
|
|
853
|
+
|
|
854
|
+
var BrowserEventConstants = {
|
|
855
|
+
topLevelTypes: topLevelTypes$1
|
|
856
|
+
};
|
|
857
|
+
|
|
858
|
+
var findDOMNode = ReactDOM.findDOMNode;
|
|
859
|
+
var _ReactDOM$__SECRET_IN = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
860
|
+
var EventPluginHub = _ReactDOM$__SECRET_IN.EventPluginHub;
|
|
861
|
+
var EventPluginRegistry = _ReactDOM$__SECRET_IN.EventPluginRegistry;
|
|
862
|
+
var EventPropagators = _ReactDOM$__SECRET_IN.EventPropagators;
|
|
863
|
+
var ReactControlledComponent = _ReactDOM$__SECRET_IN.ReactControlledComponent;
|
|
864
|
+
var ReactDOMComponentTree = _ReactDOM$__SECRET_IN.ReactDOMComponentTree;
|
|
865
|
+
var ReactDOMEventListener = _ReactDOM$__SECRET_IN.ReactDOMEventListener;
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
var topLevelTypes = BrowserEventConstants.topLevelTypes;
|
|
869
|
+
|
|
870
|
+
function Event(suffix) {}
|
|
871
|
+
|
|
872
|
+
/**
|
|
873
|
+
* @class ReactTestUtils
|
|
874
|
+
*/
|
|
875
|
+
|
|
876
|
+
function findAllInRenderedFiberTreeInternal(fiber, test) {
|
|
877
|
+
if (!fiber) {
|
|
878
|
+
return [];
|
|
879
|
+
}
|
|
880
|
+
var currentParent = findCurrentFiberUsingSlowPath(fiber);
|
|
881
|
+
if (!currentParent) {
|
|
882
|
+
return [];
|
|
883
|
+
}
|
|
884
|
+
var node = currentParent;
|
|
885
|
+
var ret = [];
|
|
886
|
+
while (true) {
|
|
887
|
+
if (node.tag === HostComponent || node.tag === HostText || node.tag === ClassComponent || node.tag === FunctionalComponent) {
|
|
888
|
+
var publicInst = node.stateNode;
|
|
889
|
+
if (test(publicInst)) {
|
|
890
|
+
ret.push(publicInst);
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
if (node.child) {
|
|
894
|
+
node.child['return'] = node;
|
|
895
|
+
node = node.child;
|
|
896
|
+
continue;
|
|
897
|
+
}
|
|
898
|
+
if (node === currentParent) {
|
|
899
|
+
return ret;
|
|
900
|
+
}
|
|
901
|
+
while (!node.sibling) {
|
|
902
|
+
if (!node['return'] || node['return'] === currentParent) {
|
|
903
|
+
return ret;
|
|
904
|
+
}
|
|
905
|
+
node = node['return'];
|
|
906
|
+
}
|
|
907
|
+
node.sibling['return'] = node['return'];
|
|
908
|
+
node = node.sibling;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/**
|
|
913
|
+
* Utilities for making it easy to test React components.
|
|
914
|
+
*
|
|
915
|
+
* See https://reactjs.org/docs/test-utils.html
|
|
916
|
+
*
|
|
917
|
+
* Todo: Support the entire DOM.scry query syntax. For now, these simple
|
|
918
|
+
* utilities will suffice for testing purposes.
|
|
919
|
+
* @lends ReactTestUtils
|
|
920
|
+
*/
|
|
921
|
+
var ReactTestUtils = {
|
|
922
|
+
renderIntoDocument: function (element) {
|
|
923
|
+
var div = document.createElement('div');
|
|
924
|
+
// None of our tests actually require attaching the container to the
|
|
925
|
+
// DOM, and doing so creates a mess that we rely on test isolation to
|
|
926
|
+
// clean up, so we're going to stop honoring the name of this method
|
|
927
|
+
// (and probably rename it eventually) if no problems arise.
|
|
928
|
+
// document.documentElement.appendChild(div);
|
|
929
|
+
return ReactDOM.render(element, div);
|
|
930
|
+
},
|
|
931
|
+
|
|
932
|
+
isElement: function (element) {
|
|
933
|
+
return React.isValidElement(element);
|
|
934
|
+
},
|
|
935
|
+
|
|
936
|
+
isElementOfType: function (inst, convenienceConstructor) {
|
|
937
|
+
return React.isValidElement(inst) && inst.type === convenienceConstructor;
|
|
938
|
+
},
|
|
939
|
+
|
|
940
|
+
isDOMComponent: function (inst) {
|
|
941
|
+
return !!(inst && inst.nodeType === 1 && inst.tagName);
|
|
942
|
+
},
|
|
943
|
+
|
|
944
|
+
isDOMComponentElement: function (inst) {
|
|
945
|
+
return !!(inst && React.isValidElement(inst) && !!inst.tagName);
|
|
946
|
+
},
|
|
947
|
+
|
|
948
|
+
isCompositeComponent: function (inst) {
|
|
949
|
+
if (ReactTestUtils.isDOMComponent(inst)) {
|
|
950
|
+
// Accessing inst.setState warns; just return false as that'll be what
|
|
951
|
+
// this returns when we have DOM nodes as refs directly
|
|
952
|
+
return false;
|
|
953
|
+
}
|
|
954
|
+
return inst != null && typeof inst.render === 'function' && typeof inst.setState === 'function';
|
|
955
|
+
},
|
|
956
|
+
|
|
957
|
+
isCompositeComponentWithType: function (inst, type) {
|
|
958
|
+
if (!ReactTestUtils.isCompositeComponent(inst)) {
|
|
959
|
+
return false;
|
|
960
|
+
}
|
|
961
|
+
var internalInstance = get(inst);
|
|
962
|
+
var constructor = internalInstance.type;
|
|
963
|
+
return constructor === type;
|
|
964
|
+
},
|
|
965
|
+
|
|
966
|
+
findAllInRenderedTree: function (inst, test) {
|
|
967
|
+
if (!inst) {
|
|
968
|
+
return [];
|
|
969
|
+
}
|
|
970
|
+
!ReactTestUtils.isCompositeComponent(inst) ? invariant_1(false, 'findAllInRenderedTree(...): instance must be a composite component') : void 0;
|
|
971
|
+
var internalInstance = get(inst);
|
|
972
|
+
return findAllInRenderedFiberTreeInternal(internalInstance, test);
|
|
973
|
+
},
|
|
974
|
+
|
|
975
|
+
/**
|
|
976
|
+
* Finds all instance of components in the rendered tree that are DOM
|
|
977
|
+
* components with the class name matching `className`.
|
|
978
|
+
* @return {array} an array of all the matches.
|
|
979
|
+
*/
|
|
980
|
+
scryRenderedDOMComponentsWithClass: function (root, classNames) {
|
|
981
|
+
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
982
|
+
if (ReactTestUtils.isDOMComponent(inst)) {
|
|
983
|
+
var className = inst.className;
|
|
984
|
+
if (typeof className !== 'string') {
|
|
985
|
+
// SVG, probably.
|
|
986
|
+
className = inst.getAttribute('class') || '';
|
|
987
|
+
}
|
|
988
|
+
var classList = className.split(/\s+/);
|
|
989
|
+
|
|
990
|
+
if (!Array.isArray(classNames)) {
|
|
991
|
+
!(classNames !== undefined) ? invariant_1(false, 'TestUtils.scryRenderedDOMComponentsWithClass expects a className as a second argument.') : void 0;
|
|
992
|
+
classNames = classNames.split(/\s+/);
|
|
993
|
+
}
|
|
994
|
+
return classNames.every(function (name) {
|
|
995
|
+
return classList.indexOf(name) !== -1;
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
return false;
|
|
999
|
+
});
|
|
1000
|
+
},
|
|
1001
|
+
|
|
1002
|
+
/**
|
|
1003
|
+
* Like scryRenderedDOMComponentsWithClass but expects there to be one result,
|
|
1004
|
+
* and returns that one result, or throws exception if there is any other
|
|
1005
|
+
* number of matches besides one.
|
|
1006
|
+
* @return {!ReactDOMComponent} The one match.
|
|
1007
|
+
*/
|
|
1008
|
+
findRenderedDOMComponentWithClass: function (root, className) {
|
|
1009
|
+
var all = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
|
|
1010
|
+
if (all.length !== 1) {
|
|
1011
|
+
throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for class:' + className);
|
|
1012
|
+
}
|
|
1013
|
+
return all[0];
|
|
1014
|
+
},
|
|
1015
|
+
|
|
1016
|
+
/**
|
|
1017
|
+
* Finds all instance of components in the rendered tree that are DOM
|
|
1018
|
+
* components with the tag name matching `tagName`.
|
|
1019
|
+
* @return {array} an array of all the matches.
|
|
1020
|
+
*/
|
|
1021
|
+
scryRenderedDOMComponentsWithTag: function (root, tagName) {
|
|
1022
|
+
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
1023
|
+
return ReactTestUtils.isDOMComponent(inst) && inst.tagName.toUpperCase() === tagName.toUpperCase();
|
|
1024
|
+
});
|
|
1025
|
+
},
|
|
1026
|
+
|
|
1027
|
+
/**
|
|
1028
|
+
* Like scryRenderedDOMComponentsWithTag but expects there to be one result,
|
|
1029
|
+
* and returns that one result, or throws exception if there is any other
|
|
1030
|
+
* number of matches besides one.
|
|
1031
|
+
* @return {!ReactDOMComponent} The one match.
|
|
1032
|
+
*/
|
|
1033
|
+
findRenderedDOMComponentWithTag: function (root, tagName) {
|
|
1034
|
+
var all = ReactTestUtils.scryRenderedDOMComponentsWithTag(root, tagName);
|
|
1035
|
+
if (all.length !== 1) {
|
|
1036
|
+
throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for tag:' + tagName);
|
|
1037
|
+
}
|
|
1038
|
+
return all[0];
|
|
1039
|
+
},
|
|
1040
|
+
|
|
1041
|
+
/**
|
|
1042
|
+
* Finds all instances of components with type equal to `componentType`.
|
|
1043
|
+
* @return {array} an array of all the matches.
|
|
1044
|
+
*/
|
|
1045
|
+
scryRenderedComponentsWithType: function (root, componentType) {
|
|
1046
|
+
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
1047
|
+
return ReactTestUtils.isCompositeComponentWithType(inst, componentType);
|
|
1048
|
+
});
|
|
1049
|
+
},
|
|
1050
|
+
|
|
1051
|
+
/**
|
|
1052
|
+
* Same as `scryRenderedComponentsWithType` but expects there to be one result
|
|
1053
|
+
* and returns that one result, or throws exception if there is any other
|
|
1054
|
+
* number of matches besides one.
|
|
1055
|
+
* @return {!ReactComponent} The one match.
|
|
1056
|
+
*/
|
|
1057
|
+
findRenderedComponentWithType: function (root, componentType) {
|
|
1058
|
+
var all = ReactTestUtils.scryRenderedComponentsWithType(root, componentType);
|
|
1059
|
+
if (all.length !== 1) {
|
|
1060
|
+
throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for componentType:' + componentType);
|
|
1061
|
+
}
|
|
1062
|
+
return all[0];
|
|
1063
|
+
},
|
|
1064
|
+
|
|
1065
|
+
/**
|
|
1066
|
+
* Pass a mocked component module to this method to augment it with
|
|
1067
|
+
* useful methods that allow it to be used as a dummy React component.
|
|
1068
|
+
* Instead of rendering as usual, the component will become a simple
|
|
1069
|
+
* <div> containing any provided children.
|
|
1070
|
+
*
|
|
1071
|
+
* @param {object} module the mock function object exported from a
|
|
1072
|
+
* module that defines the component to be mocked
|
|
1073
|
+
* @param {?string} mockTagName optional dummy root tag name to return
|
|
1074
|
+
* from render method (overrides
|
|
1075
|
+
* module.mockTagName if provided)
|
|
1076
|
+
* @return {object} the ReactTestUtils object (for chaining)
|
|
1077
|
+
*/
|
|
1078
|
+
mockComponent: function (module, mockTagName) {
|
|
1079
|
+
mockTagName = mockTagName || module.mockTagName || 'div';
|
|
1080
|
+
|
|
1081
|
+
module.prototype.render.mockImplementation(function () {
|
|
1082
|
+
return React.createElement(mockTagName, null, this.props.children);
|
|
1083
|
+
});
|
|
1084
|
+
|
|
1085
|
+
return this;
|
|
1086
|
+
},
|
|
1087
|
+
|
|
1088
|
+
/**
|
|
1089
|
+
* Simulates a top level event being dispatched from a raw event that occurred
|
|
1090
|
+
* on an `Element` node.
|
|
1091
|
+
* @param {Object} topLevelType A type from `BrowserEventConstants.topLevelTypes`
|
|
1092
|
+
* @param {!Element} node The dom to simulate an event occurring on.
|
|
1093
|
+
* @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
|
|
1094
|
+
*/
|
|
1095
|
+
simulateNativeEventOnNode: function (topLevelType, node, fakeNativeEvent) {
|
|
1096
|
+
fakeNativeEvent.target = node;
|
|
1097
|
+
ReactDOMEventListener.dispatchEvent(topLevelType, fakeNativeEvent);
|
|
1098
|
+
},
|
|
1099
|
+
|
|
1100
|
+
/**
|
|
1101
|
+
* Simulates a top level event being dispatched from a raw event that occurred
|
|
1102
|
+
* on the `ReactDOMComponent` `comp`.
|
|
1103
|
+
* @param {Object} topLevelType A type from `BrowserEventConstants.topLevelTypes`.
|
|
1104
|
+
* @param {!ReactDOMComponent} comp
|
|
1105
|
+
* @param {?Event} fakeNativeEvent Fake native event to use in SyntheticEvent.
|
|
1106
|
+
*/
|
|
1107
|
+
simulateNativeEventOnDOMComponent: function (topLevelType, comp, fakeNativeEvent) {
|
|
1108
|
+
ReactTestUtils.simulateNativeEventOnNode(topLevelType, findDOMNode(comp), fakeNativeEvent);
|
|
1109
|
+
},
|
|
1110
|
+
|
|
1111
|
+
nativeTouchData: function (x, y) {
|
|
1112
|
+
return {
|
|
1113
|
+
touches: [{ pageX: x, pageY: y }]
|
|
1114
|
+
};
|
|
1115
|
+
},
|
|
1116
|
+
|
|
1117
|
+
Simulate: null,
|
|
1118
|
+
SimulateNative: {}
|
|
1119
|
+
};
|
|
1120
|
+
|
|
1121
|
+
/**
|
|
1122
|
+
* Exports:
|
|
1123
|
+
*
|
|
1124
|
+
* - `ReactTestUtils.Simulate.click(Element)`
|
|
1125
|
+
* - `ReactTestUtils.Simulate.mouseMove(Element)`
|
|
1126
|
+
* - `ReactTestUtils.Simulate.change(Element)`
|
|
1127
|
+
* - ... (All keys from event plugin `eventTypes` objects)
|
|
1128
|
+
*/
|
|
1129
|
+
function makeSimulator(eventType) {
|
|
1130
|
+
return function (domNode, eventData) {
|
|
1131
|
+
!!React.isValidElement(domNode) ? invariant_1(false, '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.') : void 0;
|
|
1132
|
+
!!ReactTestUtils.isCompositeComponent(domNode) ? invariant_1(false, '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.') : void 0;
|
|
1133
|
+
|
|
1134
|
+
var dispatchConfig = EventPluginRegistry.eventNameDispatchConfigs[eventType];
|
|
1135
|
+
|
|
1136
|
+
var fakeNativeEvent = new Event();
|
|
1137
|
+
fakeNativeEvent.target = domNode;
|
|
1138
|
+
fakeNativeEvent.type = eventType.toLowerCase();
|
|
1139
|
+
|
|
1140
|
+
// We don't use SyntheticEvent.getPooled in order to not have to worry about
|
|
1141
|
+
// properly destroying any properties assigned from `eventData` upon release
|
|
1142
|
+
var targetInst = ReactDOMComponentTree.getInstanceFromNode(domNode);
|
|
1143
|
+
var event = new SyntheticEvent$1(dispatchConfig, targetInst, fakeNativeEvent, domNode);
|
|
1144
|
+
|
|
1145
|
+
// Since we aren't using pooling, always persist the event. This will make
|
|
1146
|
+
// sure it's marked and won't warn when setting additional properties.
|
|
1147
|
+
event.persist();
|
|
1148
|
+
_assign(event, eventData);
|
|
1149
|
+
|
|
1150
|
+
if (dispatchConfig.phasedRegistrationNames) {
|
|
1151
|
+
EventPropagators.accumulateTwoPhaseDispatches(event);
|
|
1152
|
+
} else {
|
|
1153
|
+
EventPropagators.accumulateDirectDispatches(event);
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
ReactDOM.unstable_batchedUpdates(function () {
|
|
1157
|
+
// Normally extractEvent enqueues a state restore, but we'll just always
|
|
1158
|
+
// do that since we we're by-passing it here.
|
|
1159
|
+
ReactControlledComponent.enqueueStateRestore(domNode);
|
|
1160
|
+
|
|
1161
|
+
EventPluginHub.enqueueEvents(event);
|
|
1162
|
+
EventPluginHub.processEventQueue(true);
|
|
1163
|
+
});
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
|
|
1167
|
+
function buildSimulators() {
|
|
1168
|
+
ReactTestUtils.Simulate = {};
|
|
1169
|
+
|
|
1170
|
+
var eventType;
|
|
1171
|
+
for (eventType in EventPluginRegistry.eventNameDispatchConfigs) {
|
|
1172
|
+
/**
|
|
1173
|
+
* @param {!Element|ReactDOMComponent} domComponentOrNode
|
|
1174
|
+
* @param {?object} eventData Fake event data to use in SyntheticEvent.
|
|
1175
|
+
*/
|
|
1176
|
+
ReactTestUtils.Simulate[eventType] = makeSimulator(eventType);
|
|
1177
|
+
}
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
// Rebuild ReactTestUtils.Simulate whenever event plugins are injected
|
|
1181
|
+
var oldInjectEventPluginOrder = EventPluginHub.injection.injectEventPluginOrder;
|
|
1182
|
+
EventPluginHub.injection.injectEventPluginOrder = function () {
|
|
1183
|
+
oldInjectEventPluginOrder.apply(this, arguments);
|
|
1184
|
+
buildSimulators();
|
|
1185
|
+
};
|
|
1186
|
+
var oldInjectEventPlugins = EventPluginHub.injection.injectEventPluginsByName;
|
|
1187
|
+
EventPluginHub.injection.injectEventPluginsByName = function () {
|
|
1188
|
+
oldInjectEventPlugins.apply(this, arguments);
|
|
1189
|
+
buildSimulators();
|
|
1190
|
+
};
|
|
1191
|
+
|
|
1192
|
+
buildSimulators();
|
|
1193
|
+
|
|
1194
|
+
/**
|
|
1195
|
+
* Exports:
|
|
1196
|
+
*
|
|
1197
|
+
* - `ReactTestUtils.SimulateNative.click(Element/ReactDOMComponent)`
|
|
1198
|
+
* - `ReactTestUtils.SimulateNative.mouseMove(Element/ReactDOMComponent)`
|
|
1199
|
+
* - `ReactTestUtils.SimulateNative.mouseIn/ReactDOMComponent)`
|
|
1200
|
+
* - `ReactTestUtils.SimulateNative.mouseOut(Element/ReactDOMComponent)`
|
|
1201
|
+
* - ... (All keys from `BrowserEventConstants.topLevelTypes`)
|
|
1202
|
+
*
|
|
1203
|
+
* Note: Top level event types are a subset of the entire set of handler types
|
|
1204
|
+
* (which include a broader set of "synthetic" events). For example, onDragDone
|
|
1205
|
+
* is a synthetic event. Except when testing an event plugin or React's event
|
|
1206
|
+
* handling code specifically, you probably want to use ReactTestUtils.Simulate
|
|
1207
|
+
* to dispatch synthetic events.
|
|
1208
|
+
*/
|
|
1209
|
+
|
|
1210
|
+
function makeNativeSimulator(eventType) {
|
|
1211
|
+
return function (domComponentOrNode, nativeEventData) {
|
|
1212
|
+
var fakeNativeEvent = new Event(eventType);
|
|
1213
|
+
_assign(fakeNativeEvent, nativeEventData);
|
|
1214
|
+
if (ReactTestUtils.isDOMComponent(domComponentOrNode)) {
|
|
1215
|
+
ReactTestUtils.simulateNativeEventOnDOMComponent(eventType, domComponentOrNode, fakeNativeEvent);
|
|
1216
|
+
} else if (domComponentOrNode.tagName) {
|
|
1217
|
+
// Will allow on actual dom nodes.
|
|
1218
|
+
ReactTestUtils.simulateNativeEventOnNode(eventType, domComponentOrNode, fakeNativeEvent);
|
|
1219
|
+
}
|
|
1220
|
+
};
|
|
1221
|
+
}
|
|
1222
|
+
|
|
1223
|
+
Object.keys(topLevelTypes).forEach(function (eventType) {
|
|
1224
|
+
// Event type is stored as 'topClick' - we transform that to 'click'
|
|
1225
|
+
var convenienceName = eventType.indexOf('top') === 0 ? eventType.charAt(3).toLowerCase() + eventType.substr(4) : eventType;
|
|
1226
|
+
/**
|
|
1227
|
+
* @param {!Element|ReactDOMComponent} domComponentOrNode
|
|
1228
|
+
* @param {?Event} nativeEventData Fake native event to use in SyntheticEvent.
|
|
1229
|
+
*/
|
|
1230
|
+
ReactTestUtils.SimulateNative[convenienceName] = makeNativeSimulator(eventType);
|
|
1231
|
+
});
|
|
1232
|
+
|
|
1233
|
+
|
|
1234
|
+
|
|
1235
|
+
var ReactTestUtils$2 = Object.freeze({
|
|
1236
|
+
default: ReactTestUtils
|
|
1237
|
+
});
|
|
1238
|
+
|
|
1239
|
+
var ReactTestUtils$3 = ( ReactTestUtils$2 && ReactTestUtils ) || ReactTestUtils$2;
|
|
1240
|
+
|
|
1241
|
+
// TODO: decide on the top-level export form.
|
|
1242
|
+
// This is hacky but makes it work with both Rollup and Jest.
|
|
1243
|
+
var testUtils = ReactTestUtils$3['default'] ? ReactTestUtils$3['default'] : ReactTestUtils$3;
|
|
1244
|
+
|
|
1245
|
+
return testUtils;
|
|
1246
|
+
|
|
1247
|
+
})));
|