react-dom 16.4.2 → 16.5.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/README.md +1 -1
- package/cjs/react-dom-server.browser.development.js +474 -181
- package/cjs/react-dom-server.browser.production.min.js +33 -31
- package/cjs/react-dom-server.node.development.js +474 -181
- package/cjs/react-dom-server.node.production.min.js +36 -34
- package/cjs/react-dom-test-utils.development.js +260 -102
- package/cjs/react-dom-test-utils.production.min.js +23 -23
- package/cjs/react-dom-unstable-native-dependencies.development.js +180 -82
- package/cjs/react-dom-unstable-native-dependencies.production.min.js +28 -27
- package/cjs/react-dom.development.js +3431 -2774
- package/cjs/react-dom.production.min.js +224 -228
- package/cjs/react-dom.profiling.min.js +233 -230
- package/package.json +4 -3
- package/profiling.js +38 -0
- package/umd/react-dom-server.browser.development.js +449 -447
- package/umd/react-dom-server.browser.production.min.js +29 -30
- package/umd/react-dom-test-utils.development.js +201 -225
- package/umd/react-dom-test-utils.production.min.js +21 -21
- package/umd/react-dom-unstable-native-dependencies.development.js +112 -163
- package/umd/react-dom-unstable-native-dependencies.production.min.js +23 -23
- package/umd/react-dom.development.js +3419 -3217
- package/umd/react-dom.production.min.js +184 -188
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/** @license React v16.
|
|
1
|
+
/** @license React v16.5.0
|
|
2
2
|
* react-dom-test-utils.development.js
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
@@ -16,15 +16,97 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
16
16
|
'use strict';
|
|
17
17
|
|
|
18
18
|
var _assign = require('object-assign');
|
|
19
|
-
var invariant = require('fbjs/lib/invariant');
|
|
20
19
|
var React = require('react');
|
|
21
20
|
var ReactDOM = require('react-dom');
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Use invariant() to assert state which your program assumes to be true.
|
|
24
|
+
*
|
|
25
|
+
* Provide sprintf-style format (only %s is supported) and arguments
|
|
26
|
+
* to provide information about what broke and what you were
|
|
27
|
+
* expecting.
|
|
28
|
+
*
|
|
29
|
+
* The invariant message will be stripped in production, but the invariant
|
|
30
|
+
* will remain to ensure logic does not differ in production.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
var validateFormat = function () {};
|
|
34
|
+
|
|
35
|
+
{
|
|
36
|
+
validateFormat = function (format) {
|
|
37
|
+
if (format === undefined) {
|
|
38
|
+
throw new Error('invariant requires an error message argument');
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function invariant(condition, format, a, b, c, d, e, f) {
|
|
44
|
+
validateFormat(format);
|
|
45
|
+
|
|
46
|
+
if (!condition) {
|
|
47
|
+
var error = void 0;
|
|
48
|
+
if (format === undefined) {
|
|
49
|
+
error = new Error('Minified exception occurred; use the non-minified dev environment ' + 'for the full error message and additional helpful warnings.');
|
|
50
|
+
} else {
|
|
51
|
+
var args = [a, b, c, d, e, f];
|
|
52
|
+
var argIndex = 0;
|
|
53
|
+
error = new Error(format.replace(/%s/g, function () {
|
|
54
|
+
return args[argIndex++];
|
|
55
|
+
}));
|
|
56
|
+
error.name = 'Invariant Violation';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
error.framesToPop = 1; // we don't care about invariant's own frame
|
|
60
|
+
throw error;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
25
63
|
|
|
26
64
|
// Relying on the `invariant()` implementation lets us
|
|
27
|
-
//
|
|
65
|
+
// preserve the format and params in the www builds.
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Similar to invariant but only logs a warning if the condition is not met.
|
|
69
|
+
* This can be used to log issues in development environments in critical
|
|
70
|
+
* paths. Removing the logging code for production environments will keep the
|
|
71
|
+
* same logic and follow the same code paths.
|
|
72
|
+
*/
|
|
73
|
+
|
|
74
|
+
var warningWithoutStack = function () {};
|
|
75
|
+
|
|
76
|
+
{
|
|
77
|
+
warningWithoutStack = function (condition, format) {
|
|
78
|
+
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
79
|
+
args[_key - 2] = arguments[_key];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (format === undefined) {
|
|
83
|
+
throw new Error('`warningWithoutStack(condition, format, ...args)` requires a warning ' + 'message argument');
|
|
84
|
+
}
|
|
85
|
+
if (condition) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (typeof console !== 'undefined') {
|
|
89
|
+
var _console;
|
|
90
|
+
|
|
91
|
+
var stringArgs = args.map(function (item) {
|
|
92
|
+
return '' + item;
|
|
93
|
+
});
|
|
94
|
+
(_console = console).error.apply(_console, ['Warning: ' + format].concat(stringArgs));
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
// --- Welcome to debugging React ---
|
|
98
|
+
// This error was thrown as a convenience so that you can use this stack
|
|
99
|
+
// to find the callsite that caused this warning to fire.
|
|
100
|
+
var argIndex = 0;
|
|
101
|
+
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
|
102
|
+
return args[argIndex++];
|
|
103
|
+
});
|
|
104
|
+
throw new Error(message);
|
|
105
|
+
} catch (x) {}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
var warningWithoutStack$1 = warningWithoutStack;
|
|
28
110
|
|
|
29
111
|
/**
|
|
30
112
|
* `ReactInstanceMap` maintains a mapping from a public facing stateful
|
|
@@ -47,21 +129,20 @@ function get(key) {
|
|
|
47
129
|
return key._reactInternalFiber;
|
|
48
130
|
}
|
|
49
131
|
|
|
50
|
-
var
|
|
51
|
-
|
|
52
|
-
var ReactCurrentOwner = ReactInternals.ReactCurrentOwner;
|
|
53
|
-
var ReactDebugCurrentFrame = ReactInternals.ReactDebugCurrentFrame;
|
|
132
|
+
var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
|
|
54
133
|
|
|
55
134
|
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
|
|
56
135
|
// nor polyfill, then a plain number is used for performance.
|
|
57
136
|
|
|
58
|
-
|
|
59
|
-
var
|
|
137
|
+
var FunctionalComponent = 0;
|
|
138
|
+
var FunctionalComponentLazy = 1;
|
|
60
139
|
var ClassComponent = 2;
|
|
61
|
-
var
|
|
140
|
+
var ClassComponentLazy = 3;
|
|
141
|
+
// Before we know whether it is functional or class
|
|
142
|
+
var HostRoot = 5; // Root of a host tree. Could be nested inside another node.
|
|
62
143
|
// A subtree. Could be an entry point to a different renderer.
|
|
63
|
-
var HostComponent =
|
|
64
|
-
var HostText =
|
|
144
|
+
var HostComponent = 7;
|
|
145
|
+
var HostText = 8;
|
|
65
146
|
|
|
66
147
|
// Don't change these two values. They're used by React Dev Tools.
|
|
67
148
|
var NoEffect = /* */0;
|
|
@@ -78,8 +159,13 @@ var Placement = /* */2;
|
|
|
78
159
|
|
|
79
160
|
|
|
80
161
|
|
|
162
|
+
// Update & Callback & Ref & Snapshot
|
|
163
|
+
|
|
164
|
+
|
|
81
165
|
// Union of all host effects
|
|
82
166
|
|
|
167
|
+
var ReactCurrentOwner = ReactSharedInternals.ReactCurrentOwner;
|
|
168
|
+
|
|
83
169
|
var MOUNTING = 1;
|
|
84
170
|
var MOUNTED = 2;
|
|
85
171
|
var UNMOUNTED = 3;
|
|
@@ -235,11 +321,8 @@ function findCurrentFiberUsingSlowPath(fiber) {
|
|
|
235
321
|
|
|
236
322
|
/* eslint valid-typeof: 0 */
|
|
237
323
|
|
|
238
|
-
var didWarnForAddedNewProperty = false;
|
|
239
324
|
var EVENT_POOL_SIZE = 10;
|
|
240
325
|
|
|
241
|
-
var shouldBeReleasedProperties = ['dispatchConfig', '_targetInst', 'nativeEvent', 'isDefaultPrevented', 'isPropagationStopped', '_dispatchListeners', '_dispatchInstances'];
|
|
242
|
-
|
|
243
326
|
/**
|
|
244
327
|
* @interface Event
|
|
245
328
|
* @see http://www.w3.org/TR/DOM-Level-3-Events/
|
|
@@ -248,7 +331,9 @@ var EventInterface = {
|
|
|
248
331
|
type: null,
|
|
249
332
|
target: null,
|
|
250
333
|
// currentTarget is set when dispatching; no use in copying it here
|
|
251
|
-
currentTarget:
|
|
334
|
+
currentTarget: function () {
|
|
335
|
+
return null;
|
|
336
|
+
},
|
|
252
337
|
eventPhase: null,
|
|
253
338
|
bubbles: null,
|
|
254
339
|
cancelable: null,
|
|
@@ -259,6 +344,14 @@ var EventInterface = {
|
|
|
259
344
|
isTrusted: null
|
|
260
345
|
};
|
|
261
346
|
|
|
347
|
+
function functionThatReturnsTrue() {
|
|
348
|
+
return true;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
function functionThatReturnsFalse() {
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
354
|
+
|
|
262
355
|
/**
|
|
263
356
|
* Synthetic events are dispatched by event plugins, typically in response to a
|
|
264
357
|
* top-level event delegation handler.
|
|
@@ -283,6 +376,8 @@ function SyntheticEvent(dispatchConfig, targetInst, nativeEvent, nativeEventTarg
|
|
|
283
376
|
delete this.nativeEvent;
|
|
284
377
|
delete this.preventDefault;
|
|
285
378
|
delete this.stopPropagation;
|
|
379
|
+
delete this.isDefaultPrevented;
|
|
380
|
+
delete this.isPropagationStopped;
|
|
286
381
|
}
|
|
287
382
|
|
|
288
383
|
this.dispatchConfig = dispatchConfig;
|
|
@@ -311,11 +406,11 @@ function SyntheticEvent(dispatchConfig, targetInst, nativeEvent, nativeEventTarg
|
|
|
311
406
|
|
|
312
407
|
var defaultPrevented = nativeEvent.defaultPrevented != null ? nativeEvent.defaultPrevented : nativeEvent.returnValue === false;
|
|
313
408
|
if (defaultPrevented) {
|
|
314
|
-
this.isDefaultPrevented =
|
|
409
|
+
this.isDefaultPrevented = functionThatReturnsTrue;
|
|
315
410
|
} else {
|
|
316
|
-
this.isDefaultPrevented =
|
|
411
|
+
this.isDefaultPrevented = functionThatReturnsFalse;
|
|
317
412
|
}
|
|
318
|
-
this.isPropagationStopped =
|
|
413
|
+
this.isPropagationStopped = functionThatReturnsFalse;
|
|
319
414
|
return this;
|
|
320
415
|
}
|
|
321
416
|
|
|
@@ -332,7 +427,7 @@ _assign(SyntheticEvent.prototype, {
|
|
|
332
427
|
} else if (typeof event.returnValue !== 'unknown') {
|
|
333
428
|
event.returnValue = false;
|
|
334
429
|
}
|
|
335
|
-
this.isDefaultPrevented =
|
|
430
|
+
this.isDefaultPrevented = functionThatReturnsTrue;
|
|
336
431
|
},
|
|
337
432
|
|
|
338
433
|
stopPropagation: function () {
|
|
@@ -352,7 +447,7 @@ _assign(SyntheticEvent.prototype, {
|
|
|
352
447
|
event.cancelBubble = true;
|
|
353
448
|
}
|
|
354
449
|
|
|
355
|
-
this.isPropagationStopped =
|
|
450
|
+
this.isPropagationStopped = functionThatReturnsTrue;
|
|
356
451
|
},
|
|
357
452
|
|
|
358
453
|
/**
|
|
@@ -361,7 +456,7 @@ _assign(SyntheticEvent.prototype, {
|
|
|
361
456
|
* won't be added back into the pool.
|
|
362
457
|
*/
|
|
363
458
|
persist: function () {
|
|
364
|
-
this.isPersistent =
|
|
459
|
+
this.isPersistent = functionThatReturnsTrue;
|
|
365
460
|
},
|
|
366
461
|
|
|
367
462
|
/**
|
|
@@ -369,7 +464,7 @@ _assign(SyntheticEvent.prototype, {
|
|
|
369
464
|
*
|
|
370
465
|
* @return {boolean} True if this should not be released, false otherwise.
|
|
371
466
|
*/
|
|
372
|
-
isPersistent:
|
|
467
|
+
isPersistent: functionThatReturnsFalse,
|
|
373
468
|
|
|
374
469
|
/**
|
|
375
470
|
* `PooledClass` looks for `destructor` on each instance it releases.
|
|
@@ -381,13 +476,19 @@ _assign(SyntheticEvent.prototype, {
|
|
|
381
476
|
Object.defineProperty(this, propName, getPooledWarningPropertyDefinition(propName, Interface[propName]));
|
|
382
477
|
}
|
|
383
478
|
}
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
479
|
+
this.dispatchConfig = null;
|
|
480
|
+
this._targetInst = null;
|
|
481
|
+
this.nativeEvent = null;
|
|
482
|
+
this.isDefaultPrevented = functionThatReturnsFalse;
|
|
483
|
+
this.isPropagationStopped = functionThatReturnsFalse;
|
|
484
|
+
this._dispatchListeners = null;
|
|
485
|
+
this._dispatchInstances = null;
|
|
387
486
|
{
|
|
388
487
|
Object.defineProperty(this, 'nativeEvent', getPooledWarningPropertyDefinition('nativeEvent', null));
|
|
389
|
-
Object.defineProperty(this, '
|
|
390
|
-
Object.defineProperty(this, '
|
|
488
|
+
Object.defineProperty(this, 'isDefaultPrevented', getPooledWarningPropertyDefinition('isDefaultPrevented', functionThatReturnsFalse));
|
|
489
|
+
Object.defineProperty(this, 'isPropagationStopped', getPooledWarningPropertyDefinition('isPropagationStopped', functionThatReturnsFalse));
|
|
490
|
+
Object.defineProperty(this, 'preventDefault', getPooledWarningPropertyDefinition('preventDefault', function () {}));
|
|
491
|
+
Object.defineProperty(this, 'stopPropagation', getPooledWarningPropertyDefinition('stopPropagation', function () {}));
|
|
391
492
|
}
|
|
392
493
|
}
|
|
393
494
|
});
|
|
@@ -418,38 +519,6 @@ SyntheticEvent.extend = function (Interface) {
|
|
|
418
519
|
return Class;
|
|
419
520
|
};
|
|
420
521
|
|
|
421
|
-
/** Proxying after everything set on SyntheticEvent
|
|
422
|
-
* to resolve Proxy issue on some WebKit browsers
|
|
423
|
-
* in which some Event properties are set to undefined (GH#10010)
|
|
424
|
-
*/
|
|
425
|
-
{
|
|
426
|
-
var isProxySupported = typeof Proxy === 'function' &&
|
|
427
|
-
// https://github.com/facebook/react/issues/12011
|
|
428
|
-
!Object.isSealed(new Proxy({}, {}));
|
|
429
|
-
|
|
430
|
-
if (isProxySupported) {
|
|
431
|
-
/*eslint-disable no-func-assign */
|
|
432
|
-
SyntheticEvent = new Proxy(SyntheticEvent, {
|
|
433
|
-
construct: function (target, args) {
|
|
434
|
-
return this.apply(target, Object.create(target.prototype), args);
|
|
435
|
-
},
|
|
436
|
-
apply: function (constructor, that, args) {
|
|
437
|
-
return new Proxy(constructor.apply(that, args), {
|
|
438
|
-
set: function (target, prop, value) {
|
|
439
|
-
if (prop !== 'isPersistent' && !target.constructor.Interface.hasOwnProperty(prop) && shouldBeReleasedProperties.indexOf(prop) === -1) {
|
|
440
|
-
!(didWarnForAddedNewProperty || target.isPersistent()) ? warning(false, "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.') : void 0;
|
|
441
|
-
didWarnForAddedNewProperty = true;
|
|
442
|
-
}
|
|
443
|
-
target[prop] = value;
|
|
444
|
-
return true;
|
|
445
|
-
}
|
|
446
|
-
});
|
|
447
|
-
}
|
|
448
|
-
});
|
|
449
|
-
/*eslint-enable no-func-assign */
|
|
450
|
-
}
|
|
451
|
-
}
|
|
452
|
-
|
|
453
522
|
addEventPoolingTo(SyntheticEvent);
|
|
454
523
|
|
|
455
524
|
/**
|
|
@@ -482,7 +551,7 @@ function getPooledWarningPropertyDefinition(propName, getVal) {
|
|
|
482
551
|
|
|
483
552
|
function warn(action, result) {
|
|
484
553
|
var warningCondition = false;
|
|
485
|
-
!warningCondition ?
|
|
554
|
+
!warningCondition ? warningWithoutStack$1(false, "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) : void 0;
|
|
486
555
|
}
|
|
487
556
|
}
|
|
488
557
|
|
|
@@ -498,7 +567,7 @@ function getPooledEvent(dispatchConfig, targetInst, nativeEvent, nativeInst) {
|
|
|
498
567
|
|
|
499
568
|
function releasePooledEvent(event) {
|
|
500
569
|
var EventConstructor = this;
|
|
501
|
-
!(event instanceof EventConstructor) ? invariant(false, 'Trying to release an event instance
|
|
570
|
+
!(event instanceof EventConstructor) ? invariant(false, 'Trying to release an event instance into a pool of a different type.') : void 0;
|
|
502
571
|
event.destructor();
|
|
503
572
|
if (EventConstructor.eventPool.length < EVENT_POOL_SIZE) {
|
|
504
573
|
EventConstructor.eventPool.push(event);
|
|
@@ -511,7 +580,64 @@ function addEventPoolingTo(EventConstructor) {
|
|
|
511
580
|
EventConstructor.release = releasePooledEvent;
|
|
512
581
|
}
|
|
513
582
|
|
|
514
|
-
|
|
583
|
+
/**
|
|
584
|
+
* Forked from fbjs/warning:
|
|
585
|
+
* https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
|
|
586
|
+
*
|
|
587
|
+
* Only change is we use console.warn instead of console.error,
|
|
588
|
+
* and do nothing when 'console' is not supported.
|
|
589
|
+
* This really simplifies the code.
|
|
590
|
+
* ---
|
|
591
|
+
* Similar to invariant but only logs a warning if the condition is not met.
|
|
592
|
+
* This can be used to log issues in development environments in critical
|
|
593
|
+
* paths. Removing the logging code for production environments will keep the
|
|
594
|
+
* same logic and follow the same code paths.
|
|
595
|
+
*/
|
|
596
|
+
|
|
597
|
+
var lowPriorityWarning = function () {};
|
|
598
|
+
|
|
599
|
+
{
|
|
600
|
+
var printWarning = function (format) {
|
|
601
|
+
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
602
|
+
args[_key - 1] = arguments[_key];
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
var argIndex = 0;
|
|
606
|
+
var message = 'Warning: ' + format.replace(/%s/g, function () {
|
|
607
|
+
return args[argIndex++];
|
|
608
|
+
});
|
|
609
|
+
if (typeof console !== 'undefined') {
|
|
610
|
+
console.warn(message);
|
|
611
|
+
}
|
|
612
|
+
try {
|
|
613
|
+
// --- Welcome to debugging React ---
|
|
614
|
+
// This error was thrown as a convenience so that you can use this stack
|
|
615
|
+
// to find the callsite that caused this warning to fire.
|
|
616
|
+
throw new Error(message);
|
|
617
|
+
} catch (x) {}
|
|
618
|
+
};
|
|
619
|
+
|
|
620
|
+
lowPriorityWarning = function (condition, format) {
|
|
621
|
+
if (format === undefined) {
|
|
622
|
+
throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
|
|
623
|
+
}
|
|
624
|
+
if (!condition) {
|
|
625
|
+
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
|
|
626
|
+
args[_key2 - 2] = arguments[_key2];
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
printWarning.apply(undefined, [format].concat(args));
|
|
630
|
+
}
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
var lowPriorityWarning$1 = lowPriorityWarning;
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* HTML nodeType values that represent the type of the node
|
|
638
|
+
*/
|
|
639
|
+
|
|
640
|
+
var ELEMENT_NODE = 1;
|
|
515
641
|
|
|
516
642
|
// Do not uses the below two methods directly!
|
|
517
643
|
// Instead use constants exported from DOMTopLevelEventTypes in ReactDOM.
|
|
@@ -521,6 +647,8 @@ function unsafeCastStringToDOMTopLevelType(topLevelType) {
|
|
|
521
647
|
return topLevelType;
|
|
522
648
|
}
|
|
523
649
|
|
|
650
|
+
var canUseDOM = !!(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
651
|
+
|
|
524
652
|
/**
|
|
525
653
|
* Generate a mapping of standard vendor prefixes using the defined style property and event name.
|
|
526
654
|
*
|
|
@@ -534,8 +662,6 @@ function makePrefixMap(styleProp, eventName) {
|
|
|
534
662
|
prefixes[styleProp.toLowerCase()] = eventName.toLowerCase();
|
|
535
663
|
prefixes['Webkit' + styleProp] = 'webkit' + eventName;
|
|
536
664
|
prefixes['Moz' + styleProp] = 'moz' + eventName;
|
|
537
|
-
prefixes['ms' + styleProp] = 'MS' + eventName;
|
|
538
|
-
prefixes['O' + styleProp] = 'o' + eventName.toLowerCase();
|
|
539
665
|
|
|
540
666
|
return prefixes;
|
|
541
667
|
}
|
|
@@ -563,7 +689,7 @@ var style = {};
|
|
|
563
689
|
/**
|
|
564
690
|
* Bootstrap if a DOM exists.
|
|
565
691
|
*/
|
|
566
|
-
if (
|
|
692
|
+
if (canUseDOM) {
|
|
567
693
|
style = document.createElement('div').style;
|
|
568
694
|
|
|
569
695
|
// On some platforms, in particular some releases of Android 4.x,
|
|
@@ -631,6 +757,7 @@ var TOP_CONTEXT_MENU = unsafeCastStringToDOMTopLevelType('contextmenu');
|
|
|
631
757
|
var TOP_COPY = unsafeCastStringToDOMTopLevelType('copy');
|
|
632
758
|
var TOP_CUT = unsafeCastStringToDOMTopLevelType('cut');
|
|
633
759
|
var TOP_DOUBLE_CLICK = unsafeCastStringToDOMTopLevelType('dblclick');
|
|
760
|
+
|
|
634
761
|
var TOP_DRAG = unsafeCastStringToDOMTopLevelType('drag');
|
|
635
762
|
var TOP_DRAG_END = unsafeCastStringToDOMTopLevelType('dragend');
|
|
636
763
|
var TOP_DRAG_ENTER = unsafeCastStringToDOMTopLevelType('dragenter');
|
|
@@ -700,17 +827,26 @@ var TOP_WHEEL = unsafeCastStringToDOMTopLevelType('wheel');
|
|
|
700
827
|
// unless they're explicitly whitelisted in `ReactBrowserEventEmitter.listenTo`.
|
|
701
828
|
|
|
702
829
|
var findDOMNode = ReactDOM.findDOMNode;
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
var
|
|
707
|
-
var
|
|
708
|
-
var
|
|
709
|
-
var
|
|
830
|
+
// Keep in sync with ReactDOMUnstableNativeDependencies.js
|
|
831
|
+
// and ReactDOM.js:
|
|
832
|
+
|
|
833
|
+
var _ReactDOM$__SECRET_IN = ReactDOM.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Events;
|
|
834
|
+
var getInstanceFromNode = _ReactDOM$__SECRET_IN[0];
|
|
835
|
+
var getNodeFromInstance = _ReactDOM$__SECRET_IN[1];
|
|
836
|
+
var getFiberCurrentPropsFromNode = _ReactDOM$__SECRET_IN[2];
|
|
837
|
+
var eventNameDispatchConfigs = _ReactDOM$__SECRET_IN[3];
|
|
838
|
+
var accumulateTwoPhaseDispatches = _ReactDOM$__SECRET_IN[4];
|
|
839
|
+
var accumulateDirectDispatches = _ReactDOM$__SECRET_IN[5];
|
|
840
|
+
var enqueueStateRestore = _ReactDOM$__SECRET_IN[6];
|
|
841
|
+
var restoreStateIfNeeded = _ReactDOM$__SECRET_IN[7];
|
|
842
|
+
var dispatchEvent = _ReactDOM$__SECRET_IN[8];
|
|
843
|
+
var runEventsInBatch = _ReactDOM$__SECRET_IN[9];
|
|
710
844
|
|
|
711
845
|
|
|
712
846
|
function Event(suffix) {}
|
|
713
847
|
|
|
848
|
+
var hasWarnedAboutDeprecatedMockComponent = false;
|
|
849
|
+
|
|
714
850
|
/**
|
|
715
851
|
* @class ReactTestUtils
|
|
716
852
|
*/
|
|
@@ -724,7 +860,7 @@ function Event(suffix) {}
|
|
|
724
860
|
*/
|
|
725
861
|
function simulateNativeEventOnNode(topLevelType, node, fakeNativeEvent) {
|
|
726
862
|
fakeNativeEvent.target = node;
|
|
727
|
-
|
|
863
|
+
dispatchEvent(topLevelType, fakeNativeEvent);
|
|
728
864
|
}
|
|
729
865
|
|
|
730
866
|
/**
|
|
@@ -749,7 +885,7 @@ function findAllInRenderedFiberTreeInternal(fiber, test) {
|
|
|
749
885
|
var node = currentParent;
|
|
750
886
|
var ret = [];
|
|
751
887
|
while (true) {
|
|
752
|
-
if (node.tag === HostComponent || node.tag === HostText || node.tag === ClassComponent || node.tag === FunctionalComponent) {
|
|
888
|
+
if (node.tag === HostComponent || node.tag === HostText || node.tag === ClassComponent || node.tag === ClassComponentLazy || node.tag === FunctionalComponent || node.tag === FunctionalComponentLazy) {
|
|
753
889
|
var publicInst = node.stateNode;
|
|
754
890
|
if (test(publicInst)) {
|
|
755
891
|
ret.push(publicInst);
|
|
@@ -774,6 +910,29 @@ function findAllInRenderedFiberTreeInternal(fiber, test) {
|
|
|
774
910
|
}
|
|
775
911
|
}
|
|
776
912
|
|
|
913
|
+
function validateClassInstance(inst, methodName) {
|
|
914
|
+
if (!inst) {
|
|
915
|
+
// This is probably too relaxed but it's existing behavior.
|
|
916
|
+
return;
|
|
917
|
+
}
|
|
918
|
+
if (get(inst)) {
|
|
919
|
+
// This is a public instance indeed.
|
|
920
|
+
return;
|
|
921
|
+
}
|
|
922
|
+
var received = void 0;
|
|
923
|
+
var stringified = '' + inst;
|
|
924
|
+
if (Array.isArray(inst)) {
|
|
925
|
+
received = 'an array';
|
|
926
|
+
} else if (inst && inst.nodeType === ELEMENT_NODE && inst.tagName) {
|
|
927
|
+
received = 'a DOM node';
|
|
928
|
+
} else if (stringified === '[object Object]') {
|
|
929
|
+
received = 'object with keys {' + Object.keys(inst).join(', ') + '}';
|
|
930
|
+
} else {
|
|
931
|
+
received = stringified;
|
|
932
|
+
}
|
|
933
|
+
invariant(false, '%s(...): the first argument must be a React class instance. Instead received: %s.', methodName, received);
|
|
934
|
+
}
|
|
935
|
+
|
|
777
936
|
/**
|
|
778
937
|
* Utilities for making it easy to test React components.
|
|
779
938
|
*
|
|
@@ -803,7 +962,7 @@ var ReactTestUtils = {
|
|
|
803
962
|
},
|
|
804
963
|
|
|
805
964
|
isDOMComponent: function (inst) {
|
|
806
|
-
return !!(inst && inst.nodeType ===
|
|
965
|
+
return !!(inst && inst.nodeType === ELEMENT_NODE && inst.tagName);
|
|
807
966
|
},
|
|
808
967
|
|
|
809
968
|
isDOMComponentElement: function (inst) {
|
|
@@ -829,10 +988,10 @@ var ReactTestUtils = {
|
|
|
829
988
|
},
|
|
830
989
|
|
|
831
990
|
findAllInRenderedTree: function (inst, test) {
|
|
991
|
+
validateClassInstance(inst, 'findAllInRenderedTree');
|
|
832
992
|
if (!inst) {
|
|
833
993
|
return [];
|
|
834
994
|
}
|
|
835
|
-
!ReactTestUtils.isCompositeComponent(inst) ? invariant(false, 'findAllInRenderedTree(...): instance must be a composite component') : void 0;
|
|
836
995
|
var internalInstance = get(inst);
|
|
837
996
|
return findAllInRenderedFiberTreeInternal(internalInstance, test);
|
|
838
997
|
},
|
|
@@ -843,6 +1002,7 @@ var ReactTestUtils = {
|
|
|
843
1002
|
* @return {array} an array of all the matches.
|
|
844
1003
|
*/
|
|
845
1004
|
scryRenderedDOMComponentsWithClass: function (root, classNames) {
|
|
1005
|
+
validateClassInstance(root, 'scryRenderedDOMComponentsWithClass');
|
|
846
1006
|
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
847
1007
|
if (ReactTestUtils.isDOMComponent(inst)) {
|
|
848
1008
|
var className = inst.className;
|
|
@@ -871,6 +1031,7 @@ var ReactTestUtils = {
|
|
|
871
1031
|
* @return {!ReactDOMComponent} The one match.
|
|
872
1032
|
*/
|
|
873
1033
|
findRenderedDOMComponentWithClass: function (root, className) {
|
|
1034
|
+
validateClassInstance(root, 'findRenderedDOMComponentWithClass');
|
|
874
1035
|
var all = ReactTestUtils.scryRenderedDOMComponentsWithClass(root, className);
|
|
875
1036
|
if (all.length !== 1) {
|
|
876
1037
|
throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for class:' + className);
|
|
@@ -884,6 +1045,7 @@ var ReactTestUtils = {
|
|
|
884
1045
|
* @return {array} an array of all the matches.
|
|
885
1046
|
*/
|
|
886
1047
|
scryRenderedDOMComponentsWithTag: function (root, tagName) {
|
|
1048
|
+
validateClassInstance(root, 'scryRenderedDOMComponentsWithTag');
|
|
887
1049
|
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
888
1050
|
return ReactTestUtils.isDOMComponent(inst) && inst.tagName.toUpperCase() === tagName.toUpperCase();
|
|
889
1051
|
});
|
|
@@ -896,6 +1058,7 @@ var ReactTestUtils = {
|
|
|
896
1058
|
* @return {!ReactDOMComponent} The one match.
|
|
897
1059
|
*/
|
|
898
1060
|
findRenderedDOMComponentWithTag: function (root, tagName) {
|
|
1061
|
+
validateClassInstance(root, 'findRenderedDOMComponentWithTag');
|
|
899
1062
|
var all = ReactTestUtils.scryRenderedDOMComponentsWithTag(root, tagName);
|
|
900
1063
|
if (all.length !== 1) {
|
|
901
1064
|
throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for tag:' + tagName);
|
|
@@ -908,6 +1071,7 @@ var ReactTestUtils = {
|
|
|
908
1071
|
* @return {array} an array of all the matches.
|
|
909
1072
|
*/
|
|
910
1073
|
scryRenderedComponentsWithType: function (root, componentType) {
|
|
1074
|
+
validateClassInstance(root, 'scryRenderedComponentsWithType');
|
|
911
1075
|
return ReactTestUtils.findAllInRenderedTree(root, function (inst) {
|
|
912
1076
|
return ReactTestUtils.isCompositeComponentWithType(inst, componentType);
|
|
913
1077
|
});
|
|
@@ -920,6 +1084,7 @@ var ReactTestUtils = {
|
|
|
920
1084
|
* @return {!ReactComponent} The one match.
|
|
921
1085
|
*/
|
|
922
1086
|
findRenderedComponentWithType: function (root, componentType) {
|
|
1087
|
+
validateClassInstance(root, 'findRenderedComponentWithType');
|
|
923
1088
|
var all = ReactTestUtils.scryRenderedComponentsWithType(root, componentType);
|
|
924
1089
|
if (all.length !== 1) {
|
|
925
1090
|
throw new Error('Did not find exactly one match (found: ' + all.length + ') ' + 'for componentType:' + componentType);
|
|
@@ -941,6 +1106,11 @@ var ReactTestUtils = {
|
|
|
941
1106
|
* @return {object} the ReactTestUtils object (for chaining)
|
|
942
1107
|
*/
|
|
943
1108
|
mockComponent: function (module, mockTagName) {
|
|
1109
|
+
if (!hasWarnedAboutDeprecatedMockComponent) {
|
|
1110
|
+
hasWarnedAboutDeprecatedMockComponent = true;
|
|
1111
|
+
lowPriorityWarning$1(false, 'ReactTestUtils.mockComponent() is deprecated. ' + 'Use shallow rendering or jest.mock() instead.\n\n' + 'See https://fb.me/test-utils-mock-component for more information.');
|
|
1112
|
+
}
|
|
1113
|
+
|
|
944
1114
|
mockTagName = mockTagName || module.mockTagName || 'div';
|
|
945
1115
|
|
|
946
1116
|
module.prototype.render.mockImplementation(function () {
|
|
@@ -973,7 +1143,7 @@ function makeSimulator(eventType) {
|
|
|
973
1143
|
!!React.isValidElement(domNode) ? invariant(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;
|
|
974
1144
|
!!ReactTestUtils.isCompositeComponent(domNode) ? invariant(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;
|
|
975
1145
|
|
|
976
|
-
var dispatchConfig =
|
|
1146
|
+
var dispatchConfig = eventNameDispatchConfigs[eventType];
|
|
977
1147
|
|
|
978
1148
|
var fakeNativeEvent = new Event();
|
|
979
1149
|
fakeNativeEvent.target = domNode;
|
|
@@ -981,8 +1151,8 @@ function makeSimulator(eventType) {
|
|
|
981
1151
|
|
|
982
1152
|
// We don't use SyntheticEvent.getPooled in order to not have to worry about
|
|
983
1153
|
// properly destroying any properties assigned from `eventData` upon release
|
|
984
|
-
var targetInst =
|
|
985
|
-
var event = new SyntheticEvent
|
|
1154
|
+
var targetInst = getInstanceFromNode(domNode);
|
|
1155
|
+
var event = new SyntheticEvent(dispatchConfig, targetInst, fakeNativeEvent, domNode);
|
|
986
1156
|
|
|
987
1157
|
// Since we aren't using pooling, always persist the event. This will make
|
|
988
1158
|
// sure it's marked and won't warn when setting additional properties.
|
|
@@ -990,18 +1160,18 @@ function makeSimulator(eventType) {
|
|
|
990
1160
|
_assign(event, eventData);
|
|
991
1161
|
|
|
992
1162
|
if (dispatchConfig.phasedRegistrationNames) {
|
|
993
|
-
|
|
1163
|
+
accumulateTwoPhaseDispatches(event);
|
|
994
1164
|
} else {
|
|
995
|
-
|
|
1165
|
+
accumulateDirectDispatches(event);
|
|
996
1166
|
}
|
|
997
1167
|
|
|
998
1168
|
ReactDOM.unstable_batchedUpdates(function () {
|
|
999
1169
|
// Normally extractEvent enqueues a state restore, but we'll just always
|
|
1000
1170
|
// do that since we we're by-passing it here.
|
|
1001
|
-
|
|
1002
|
-
|
|
1171
|
+
enqueueStateRestore(domNode);
|
|
1172
|
+
runEventsInBatch(event, true);
|
|
1003
1173
|
});
|
|
1004
|
-
|
|
1174
|
+
restoreStateIfNeeded();
|
|
1005
1175
|
};
|
|
1006
1176
|
}
|
|
1007
1177
|
|
|
@@ -1009,7 +1179,7 @@ function buildSimulators() {
|
|
|
1009
1179
|
ReactTestUtils.Simulate = {};
|
|
1010
1180
|
|
|
1011
1181
|
var eventType = void 0;
|
|
1012
|
-
for (eventType in
|
|
1182
|
+
for (eventType in eventNameDispatchConfigs) {
|
|
1013
1183
|
/**
|
|
1014
1184
|
* @param {!Element|ReactDOMComponent} domComponentOrNode
|
|
1015
1185
|
* @param {?object} eventData Fake event data to use in SyntheticEvent.
|
|
@@ -1018,18 +1188,6 @@ function buildSimulators() {
|
|
|
1018
1188
|
}
|
|
1019
1189
|
}
|
|
1020
1190
|
|
|
1021
|
-
// Rebuild ReactTestUtils.Simulate whenever event plugins are injected
|
|
1022
|
-
var oldInjectEventPluginOrder = EventPluginHub.injection.injectEventPluginOrder;
|
|
1023
|
-
EventPluginHub.injection.injectEventPluginOrder = function () {
|
|
1024
|
-
oldInjectEventPluginOrder.apply(this, arguments);
|
|
1025
|
-
buildSimulators();
|
|
1026
|
-
};
|
|
1027
|
-
var oldInjectEventPlugins = EventPluginHub.injection.injectEventPluginsByName;
|
|
1028
|
-
EventPluginHub.injection.injectEventPluginsByName = function () {
|
|
1029
|
-
oldInjectEventPlugins.apply(this, arguments);
|
|
1030
|
-
buildSimulators();
|
|
1031
|
-
};
|
|
1032
|
-
|
|
1033
1191
|
buildSimulators();
|
|
1034
1192
|
|
|
1035
1193
|
/**
|
|
@@ -1082,7 +1240,7 @@ var ReactTestUtils$3 = ( ReactTestUtils$2 && ReactTestUtils ) || ReactTestUtils$
|
|
|
1082
1240
|
|
|
1083
1241
|
// TODO: decide on the top-level export form.
|
|
1084
1242
|
// This is hacky but makes it work with both Rollup and Jest.
|
|
1085
|
-
var testUtils = ReactTestUtils$3.default
|
|
1243
|
+
var testUtils = ReactTestUtils$3.default || ReactTestUtils$3;
|
|
1086
1244
|
|
|
1087
1245
|
module.exports = testUtils;
|
|
1088
1246
|
})();
|