react 15.7.0 → 16.0.0-alpha
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/LICENSE +26 -16
- package/PATENTS +33 -0
- package/README.md +7 -0
- package/dist/react-with-addons.js +3831 -4404
- package/dist/react-with-addons.min.js +7 -6
- package/dist/react.js +2929 -3319
- package/dist/react.min.js +7 -5
- package/lib/KeyEscapeUtils.js +5 -3
- package/lib/PooledClass.js +5 -3
- package/lib/React.js +20 -61
- package/lib/ReactAddonsDOMDependencies.js +5 -3
- package/lib/ReactAddonsDOMDependenciesUMDShim.js +5 -3
- package/lib/ReactCSSTransitionGroup.js +9 -9
- package/lib/ReactCSSTransitionGroupChild.js +118 -134
- package/lib/ReactChildren.js +9 -7
- package/lib/ReactClass.js +703 -0
- package/lib/{ReactBaseClasses.js → ReactComponent.js} +11 -40
- package/lib/ReactComponentTreeHook.js +63 -58
- package/lib/ReactComponentTreeHookUMDShim.js +5 -3
- package/lib/ReactComponentWithPureRenderMixin.js +5 -3
- package/lib/ReactCurrentOwner.js +7 -3
- package/lib/ReactCurrentOwnerUMDShim.js +5 -3
- package/lib/ReactDOMFactories.js +6 -3
- package/lib/ReactElement.js +9 -7
- package/lib/ReactElementSymbol.js +5 -3
- package/lib/ReactElementType.js +5 -3
- package/lib/ReactElementValidator.js +13 -12
- package/lib/ReactFragment.js +5 -3
- package/lib/ReactNoopUpdateQueue.js +15 -16
- package/lib/ReactPropTypeLocationNames.js +5 -3
- package/lib/ReactPropTypeLocations.js +5 -3
- package/lib/ReactPropTypes.js +447 -7
- package/lib/ReactPureComponent.js +41 -0
- package/lib/ReactStateSetters.js +5 -3
- package/lib/ReactTransitionChildMapping.js +5 -3
- package/lib/ReactTransitionEvents.js +5 -3
- package/lib/ReactTransitionGroup.js +8 -12
- package/lib/ReactTypeOfWork.js +26 -0
- package/lib/ReactUMDEntry.js +8 -7
- package/lib/ReactUMDShim.js +5 -3
- package/lib/ReactVersion.js +6 -4
- package/lib/ReactWithAddons.js +5 -5
- package/lib/ReactWithAddonsUMDEntry.js +8 -7
- package/lib/canDefineProperty.js +5 -3
- package/lib/checkReactTypeSpec.js +22 -9
- package/lib/deprecated.js +8 -6
- package/lib/flattenChildren.js +5 -3
- package/lib/getComponentName.js +37 -0
- package/lib/getIteratorFn.js +5 -3
- package/lib/getNextDebugID.js +5 -3
- package/lib/onlyChild.js +6 -4
- package/lib/reactProdInvariant.js +4 -2
- package/lib/shallowCompare.js +5 -3
- package/lib/sliceChildren.js +5 -3
- package/lib/traverseAllChildren.js +6 -4
- package/lib/update.js +5 -3
- package/package.json +24 -35
- package/cjs/react-jsx-dev-runtime.development.js +0 -866
- package/cjs/react-jsx-dev-runtime.production.min.js +0 -9
- package/cjs/react-jsx-runtime.development.js +0 -888
- package/cjs/react-jsx-runtime.production.min.js +0 -10
- package/jsx-dev-runtime.js +0 -7
- package/jsx-runtime.js +0 -7
- package/lib/LinkedStateMixin.js +0 -32
- package/lib/ReactComponentTreeDevtool.js +0 -12
- package/lib/ReactLink.js +0 -47
- package/lib/ReactPropTypesSecret.js +0 -14
- package/lib/createClass.js +0 -20
- package/lib/getNextDebugIDUMDShim.js +0 -15
- package/lib/lowPriorityWarning.js +0 -62
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2014-present, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
3
4
|
*
|
|
4
|
-
* This source code is licensed under the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
6
8
|
*
|
|
7
9
|
*/
|
|
8
10
|
|
|
@@ -22,13 +24,13 @@ var ReactElement = require('./ReactElement');
|
|
|
22
24
|
var checkReactTypeSpec = require('./checkReactTypeSpec');
|
|
23
25
|
|
|
24
26
|
var canDefineProperty = require('./canDefineProperty');
|
|
27
|
+
var getComponentName = require('./getComponentName');
|
|
25
28
|
var getIteratorFn = require('./getIteratorFn');
|
|
26
29
|
var warning = require('fbjs/lib/warning');
|
|
27
|
-
var lowPriorityWarning = require('./lowPriorityWarning');
|
|
28
30
|
|
|
29
31
|
function getDeclarationErrorAddendum() {
|
|
30
32
|
if (ReactCurrentOwner.current) {
|
|
31
|
-
var name = ReactCurrentOwner.current
|
|
33
|
+
var name = getComponentName(ReactCurrentOwner.current);
|
|
32
34
|
if (name) {
|
|
33
35
|
return ' Check the render method of `' + name + '`.';
|
|
34
36
|
}
|
|
@@ -96,7 +98,7 @@ function validateExplicitKey(element, parentType) {
|
|
|
96
98
|
var childOwner = '';
|
|
97
99
|
if (element && element._owner && element._owner !== ReactCurrentOwner.current) {
|
|
98
100
|
// Give the component that originally created this child.
|
|
99
|
-
childOwner = ' It was passed a child from ' + element._owner
|
|
101
|
+
childOwner = ' It was passed a child from ' + getComponentName(element._owner) + '.';
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
process.env.NODE_ENV !== 'production' ? warning(false, 'Each child in an array or iterator should have a unique "key" prop.' + '%s%s See https://fb.me/react-warning-keys for more information.%s', currentComponentErrorInfo, childOwner, ReactComponentTreeHook.getCurrentStackAddendum(element)) : void 0;
|
|
@@ -165,15 +167,16 @@ function validatePropTypes(element) {
|
|
|
165
167
|
}
|
|
166
168
|
|
|
167
169
|
var ReactElementValidator = {
|
|
170
|
+
|
|
168
171
|
createElement: function (type, props, children) {
|
|
169
|
-
var validType = typeof type === 'string' || typeof type === 'function';
|
|
172
|
+
var validType = typeof type === 'string' || typeof type === 'function' || type !== null && typeof type === 'object' && typeof type.tag === 'number';
|
|
170
173
|
// We warn in this case but don't throw. We expect the element creation to
|
|
171
174
|
// succeed and there will likely be errors in render.
|
|
172
175
|
if (!validType) {
|
|
173
176
|
if (typeof type !== 'function' && typeof type !== 'string') {
|
|
174
177
|
var info = '';
|
|
175
178
|
if (type === undefined || typeof type === 'object' && type !== null && Object.keys(type).length === 0) {
|
|
176
|
-
info += ' You likely forgot to export your component from the file ' +
|
|
179
|
+
info += ' You likely forgot to export your component from the file ' + 'it\'s defined in.';
|
|
177
180
|
}
|
|
178
181
|
|
|
179
182
|
var sourceInfo = getSourceInfoErrorAddendum(props);
|
|
@@ -185,10 +188,7 @@ var ReactElementValidator = {
|
|
|
185
188
|
|
|
186
189
|
info += ReactComponentTreeHook.getCurrentStackAddendum();
|
|
187
190
|
|
|
188
|
-
var currentSource = props !== null && props !== undefined && props.__source !== undefined ? props.__source : null;
|
|
189
|
-
ReactComponentTreeHook.pushNonStandardWarningStack(true, currentSource);
|
|
190
191
|
process.env.NODE_ENV !== 'production' ? warning(false, 'React.createElement: type is invalid -- expected a string (for ' + 'built-in components) or a class/function (for composite ' + 'components) but got: %s.%s', type == null ? type : typeof type, info) : void 0;
|
|
191
|
-
ReactComponentTreeHook.popNonStandardWarningStack();
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
|
|
@@ -226,7 +226,7 @@ var ReactElementValidator = {
|
|
|
226
226
|
Object.defineProperty(validatedFactory, 'type', {
|
|
227
227
|
enumerable: false,
|
|
228
228
|
get: function () {
|
|
229
|
-
|
|
229
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'Factory.type is deprecated. Access the class directly ' + 'before passing it to createFactory.') : void 0;
|
|
230
230
|
Object.defineProperty(this, 'type', {
|
|
231
231
|
value: type
|
|
232
232
|
});
|
|
@@ -247,6 +247,7 @@ var ReactElementValidator = {
|
|
|
247
247
|
validatePropTypes(newElement);
|
|
248
248
|
return newElement;
|
|
249
249
|
}
|
|
250
|
+
|
|
250
251
|
};
|
|
251
252
|
|
|
252
253
|
module.exports = ReactElementValidator;
|
package/lib/ReactFragment.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2015-present, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
3
4
|
*
|
|
4
|
-
* This source code is licensed under the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
6
8
|
*
|
|
7
9
|
*/
|
|
8
10
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2015-present, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
3
4
|
*
|
|
4
|
-
* This source code is licensed under the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
6
8
|
*
|
|
7
9
|
*/
|
|
8
10
|
|
|
@@ -21,6 +23,7 @@ function warnNoop(publicInstance, callerName) {
|
|
|
21
23
|
* This is the abstract API for an update queue.
|
|
22
24
|
*/
|
|
23
25
|
var ReactNoopUpdateQueue = {
|
|
26
|
+
|
|
24
27
|
/**
|
|
25
28
|
* Checks whether or not this composite component is mounted.
|
|
26
29
|
* @param {ReactClass} publicInstance The instance we want to test.
|
|
@@ -32,16 +35,6 @@ var ReactNoopUpdateQueue = {
|
|
|
32
35
|
return false;
|
|
33
36
|
},
|
|
34
37
|
|
|
35
|
-
/**
|
|
36
|
-
* Enqueue a callback that will be executed after all the pending updates
|
|
37
|
-
* have processed.
|
|
38
|
-
*
|
|
39
|
-
* @param {ReactClass} publicInstance The instance to use as `this` context.
|
|
40
|
-
* @param {?function} callback Called after state is updated.
|
|
41
|
-
* @internal
|
|
42
|
-
*/
|
|
43
|
-
enqueueCallback: function (publicInstance, callback) {},
|
|
44
|
-
|
|
45
38
|
/**
|
|
46
39
|
* Forces an update. This should only be invoked when it is known with
|
|
47
40
|
* certainty that we are **not** in a DOM transaction.
|
|
@@ -53,9 +46,11 @@ var ReactNoopUpdateQueue = {
|
|
|
53
46
|
* `componentWillUpdate` and `componentDidUpdate`.
|
|
54
47
|
*
|
|
55
48
|
* @param {ReactClass} publicInstance The instance that should rerender.
|
|
49
|
+
* @param {?function} callback Called after component is updated.
|
|
50
|
+
* @param {?string} Name of the calling function in the public API.
|
|
56
51
|
* @internal
|
|
57
52
|
*/
|
|
58
|
-
enqueueForceUpdate: function (publicInstance) {
|
|
53
|
+
enqueueForceUpdate: function (publicInstance, callback, callerName) {
|
|
59
54
|
warnNoop(publicInstance, 'forceUpdate');
|
|
60
55
|
},
|
|
61
56
|
|
|
@@ -68,9 +63,11 @@ var ReactNoopUpdateQueue = {
|
|
|
68
63
|
*
|
|
69
64
|
* @param {ReactClass} publicInstance The instance that should rerender.
|
|
70
65
|
* @param {object} completeState Next state.
|
|
66
|
+
* @param {?function} callback Called after component is updated.
|
|
67
|
+
* @param {?string} Name of the calling function in the public API.
|
|
71
68
|
* @internal
|
|
72
69
|
*/
|
|
73
|
-
enqueueReplaceState: function (publicInstance, completeState) {
|
|
70
|
+
enqueueReplaceState: function (publicInstance, completeState, callback, callerName) {
|
|
74
71
|
warnNoop(publicInstance, 'replaceState');
|
|
75
72
|
},
|
|
76
73
|
|
|
@@ -82,9 +79,11 @@ var ReactNoopUpdateQueue = {
|
|
|
82
79
|
*
|
|
83
80
|
* @param {ReactClass} publicInstance The instance that should rerender.
|
|
84
81
|
* @param {object} partialState Next partial state to be merged with state.
|
|
82
|
+
* @param {?function} callback Called after component is updated.
|
|
83
|
+
* @param {?string} Name of the calling function in the public API.
|
|
85
84
|
* @internal
|
|
86
85
|
*/
|
|
87
|
-
enqueueSetState: function (publicInstance, partialState) {
|
|
86
|
+
enqueueSetState: function (publicInstance, partialState, callback, callerName) {
|
|
88
87
|
warnNoop(publicInstance, 'setState');
|
|
89
88
|
}
|
|
90
89
|
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2013-present, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
3
4
|
*
|
|
4
|
-
* This source code is licensed under the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
6
8
|
*
|
|
7
9
|
*
|
|
8
10
|
*/
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2013-present, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
3
4
|
*
|
|
4
|
-
* This source code is licensed under the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
6
8
|
*
|
|
7
9
|
*
|
|
8
10
|
*/
|
package/lib/ReactPropTypes.js
CHANGED
|
@@ -1,16 +1,456 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright
|
|
2
|
+
* Copyright 2013-present, Facebook, Inc.
|
|
3
|
+
* All rights reserved.
|
|
3
4
|
*
|
|
4
|
-
* This source code is licensed under the
|
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
|
5
|
+
* This source code is licensed under the BSD-style license found in the
|
|
6
|
+
* LICENSE file in the root directory of this source tree. An additional grant
|
|
7
|
+
* of patent rights can be found in the PATENTS file in the same directory.
|
|
6
8
|
*
|
|
7
9
|
*/
|
|
8
10
|
|
|
9
11
|
'use strict';
|
|
10
12
|
|
|
11
|
-
var
|
|
12
|
-
isValidElement = _require.isValidElement;
|
|
13
|
+
var _prodInvariant = require('./reactProdInvariant');
|
|
13
14
|
|
|
14
|
-
var
|
|
15
|
+
var ReactElement = require('./ReactElement');
|
|
16
|
+
var ReactPropTypeLocationNames = require('./ReactPropTypeLocationNames');
|
|
15
17
|
|
|
16
|
-
|
|
18
|
+
var emptyFunction = require('fbjs/lib/emptyFunction');
|
|
19
|
+
var getIteratorFn = require('./getIteratorFn');
|
|
20
|
+
var invariant = require('fbjs/lib/invariant');
|
|
21
|
+
var warning = require('fbjs/lib/warning');
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Collection of methods that allow declaration and validation of props that are
|
|
25
|
+
* supplied to React components. Example usage:
|
|
26
|
+
*
|
|
27
|
+
* var Props = require('ReactPropTypes');
|
|
28
|
+
* var MyArticle = React.createClass({
|
|
29
|
+
* propTypes: {
|
|
30
|
+
* // An optional string prop named "description".
|
|
31
|
+
* description: Props.string,
|
|
32
|
+
*
|
|
33
|
+
* // A required enum prop named "category".
|
|
34
|
+
* category: Props.oneOf(['News','Photos']).isRequired,
|
|
35
|
+
*
|
|
36
|
+
* // A prop named "dialog" that requires an instance of Dialog.
|
|
37
|
+
* dialog: Props.instanceOf(Dialog).isRequired
|
|
38
|
+
* },
|
|
39
|
+
* render: function() { ... }
|
|
40
|
+
* });
|
|
41
|
+
*
|
|
42
|
+
* A more formal specification of how these methods are used:
|
|
43
|
+
*
|
|
44
|
+
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
|
|
45
|
+
* decl := ReactPropTypes.{type}(.isRequired)?
|
|
46
|
+
*
|
|
47
|
+
* Each and every declaration produces a function with the same signature. This
|
|
48
|
+
* allows the creation of custom validation functions. For example:
|
|
49
|
+
*
|
|
50
|
+
* var MyLink = React.createClass({
|
|
51
|
+
* propTypes: {
|
|
52
|
+
* // An optional string or URI prop named "href".
|
|
53
|
+
* href: function(props, propName, componentName) {
|
|
54
|
+
* var propValue = props[propName];
|
|
55
|
+
* if (propValue != null && typeof propValue !== 'string' &&
|
|
56
|
+
* !(propValue instanceof URI)) {
|
|
57
|
+
* return new Error(
|
|
58
|
+
* 'Expected a string or an URI for ' + propName + ' in ' +
|
|
59
|
+
* componentName
|
|
60
|
+
* );
|
|
61
|
+
* }
|
|
62
|
+
* }
|
|
63
|
+
* },
|
|
64
|
+
* render: function() {...}
|
|
65
|
+
* });
|
|
66
|
+
*
|
|
67
|
+
* @internal
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
var ANONYMOUS = '<<anonymous>>';
|
|
71
|
+
|
|
72
|
+
var ReactPropTypes;
|
|
73
|
+
|
|
74
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
75
|
+
// Keep in sync with production version below
|
|
76
|
+
ReactPropTypes = {
|
|
77
|
+
array: createPrimitiveTypeChecker('array'),
|
|
78
|
+
bool: createPrimitiveTypeChecker('boolean'),
|
|
79
|
+
func: createPrimitiveTypeChecker('function'),
|
|
80
|
+
number: createPrimitiveTypeChecker('number'),
|
|
81
|
+
object: createPrimitiveTypeChecker('object'),
|
|
82
|
+
string: createPrimitiveTypeChecker('string'),
|
|
83
|
+
symbol: createPrimitiveTypeChecker('symbol'),
|
|
84
|
+
|
|
85
|
+
any: createAnyTypeChecker(),
|
|
86
|
+
arrayOf: createArrayOfTypeChecker,
|
|
87
|
+
element: createElementTypeChecker(),
|
|
88
|
+
instanceOf: createInstanceTypeChecker,
|
|
89
|
+
node: createNodeChecker(),
|
|
90
|
+
objectOf: createObjectOfTypeChecker,
|
|
91
|
+
oneOf: createEnumTypeChecker,
|
|
92
|
+
oneOfType: createUnionTypeChecker,
|
|
93
|
+
shape: createShapeTypeChecker
|
|
94
|
+
};
|
|
95
|
+
} else {
|
|
96
|
+
var productionTypeChecker = function () {
|
|
97
|
+
invariant(false, 'React.PropTypes type checking code is stripped in production.');
|
|
98
|
+
};
|
|
99
|
+
productionTypeChecker.isRequired = productionTypeChecker;
|
|
100
|
+
var getProductionTypeChecker = function () {
|
|
101
|
+
return productionTypeChecker;
|
|
102
|
+
};
|
|
103
|
+
// Keep in sync with development version above
|
|
104
|
+
ReactPropTypes = {
|
|
105
|
+
array: productionTypeChecker,
|
|
106
|
+
bool: productionTypeChecker,
|
|
107
|
+
func: productionTypeChecker,
|
|
108
|
+
number: productionTypeChecker,
|
|
109
|
+
object: productionTypeChecker,
|
|
110
|
+
string: productionTypeChecker,
|
|
111
|
+
symbol: productionTypeChecker,
|
|
112
|
+
|
|
113
|
+
any: productionTypeChecker,
|
|
114
|
+
arrayOf: getProductionTypeChecker,
|
|
115
|
+
element: productionTypeChecker,
|
|
116
|
+
instanceOf: getProductionTypeChecker,
|
|
117
|
+
node: productionTypeChecker,
|
|
118
|
+
objectOf: getProductionTypeChecker,
|
|
119
|
+
oneOf: getProductionTypeChecker,
|
|
120
|
+
oneOfType: getProductionTypeChecker,
|
|
121
|
+
shape: getProductionTypeChecker
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
127
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
128
|
+
*/
|
|
129
|
+
/*eslint-disable no-self-compare*/
|
|
130
|
+
function is(x, y) {
|
|
131
|
+
// SameValue algorithm
|
|
132
|
+
if (x === y) {
|
|
133
|
+
// Steps 1-5, 7-10
|
|
134
|
+
// Steps 6.b-6.e: +0 != -0
|
|
135
|
+
return x !== 0 || 1 / x === 1 / y;
|
|
136
|
+
} else {
|
|
137
|
+
// Step 6.a: NaN == NaN
|
|
138
|
+
return x !== x && y !== y;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/*eslint-enable no-self-compare*/
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* We use an Error-like object for backward compatibility as people may call
|
|
145
|
+
* PropTypes directly and inspect their output. However we don't use real
|
|
146
|
+
* Errors anymore. We don't inspect their stack anyway, and creating them
|
|
147
|
+
* is prohibitively expensive if they are created too often, such as what
|
|
148
|
+
* happens in oneOfType() for any type before the one that matched.
|
|
149
|
+
*/
|
|
150
|
+
function PropTypeError(message) {
|
|
151
|
+
this.message = message;
|
|
152
|
+
this.stack = '';
|
|
153
|
+
}
|
|
154
|
+
// Make `instanceof Error` still work for returned errors.
|
|
155
|
+
PropTypeError.prototype = Error.prototype;
|
|
156
|
+
|
|
157
|
+
function createChainableTypeChecker(validate) {
|
|
158
|
+
function checkType(isRequired, props, propName, componentName, location, propFullName) {
|
|
159
|
+
componentName = componentName || ANONYMOUS;
|
|
160
|
+
propFullName = propFullName || propName;
|
|
161
|
+
if (props[propName] == null) {
|
|
162
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
163
|
+
if (isRequired) {
|
|
164
|
+
if (props[propName] === null) {
|
|
165
|
+
return new PropTypeError('The ' + locationName + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
|
|
166
|
+
}
|
|
167
|
+
return new PropTypeError('The ' + locationName + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
|
|
168
|
+
}
|
|
169
|
+
return null;
|
|
170
|
+
} else {
|
|
171
|
+
return validate(props, propName, componentName, location, propFullName);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
var chainedCheckType = checkType.bind(null, false);
|
|
176
|
+
chainedCheckType.isRequired = checkType.bind(null, true);
|
|
177
|
+
|
|
178
|
+
return chainedCheckType;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function createPrimitiveTypeChecker(expectedType) {
|
|
182
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
183
|
+
var propValue = props[propName];
|
|
184
|
+
var propType = getPropType(propValue);
|
|
185
|
+
if (propType !== expectedType) {
|
|
186
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
187
|
+
// `propValue` being instance of, say, date/regexp, pass the 'object'
|
|
188
|
+
// check, but we can offer a more precise error message here rather than
|
|
189
|
+
// 'of type `object`'.
|
|
190
|
+
var preciseType = getPreciseType(propValue);
|
|
191
|
+
|
|
192
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
|
|
193
|
+
}
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
return createChainableTypeChecker(validate);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
function createAnyTypeChecker() {
|
|
200
|
+
return createChainableTypeChecker(emptyFunction.thatReturns(null));
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function createArrayOfTypeChecker(typeChecker) {
|
|
204
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
205
|
+
if (typeof typeChecker !== 'function') {
|
|
206
|
+
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
|
|
207
|
+
}
|
|
208
|
+
var propValue = props[propName];
|
|
209
|
+
if (!Array.isArray(propValue)) {
|
|
210
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
211
|
+
var propType = getPropType(propValue);
|
|
212
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
|
213
|
+
}
|
|
214
|
+
for (var i = 0; i < propValue.length; i++) {
|
|
215
|
+
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']');
|
|
216
|
+
if (error instanceof Error) {
|
|
217
|
+
return error;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
return createChainableTypeChecker(validate);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function createElementTypeChecker() {
|
|
226
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
227
|
+
var propValue = props[propName];
|
|
228
|
+
if (!ReactElement.isValidElement(propValue)) {
|
|
229
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
230
|
+
var propType = getPropType(propValue);
|
|
231
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
|
232
|
+
}
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
return createChainableTypeChecker(validate);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function createInstanceTypeChecker(expectedClass) {
|
|
239
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
240
|
+
if (!(props[propName] instanceof expectedClass)) {
|
|
241
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
242
|
+
var expectedClassName = expectedClass.name || ANONYMOUS;
|
|
243
|
+
var actualClassName = getClassName(props[propName]);
|
|
244
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
|
245
|
+
}
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
return createChainableTypeChecker(validate);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function createEnumTypeChecker(expectedValues) {
|
|
252
|
+
if (!Array.isArray(expectedValues)) {
|
|
253
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0;
|
|
254
|
+
return emptyFunction.thatReturnsNull;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
258
|
+
var propValue = props[propName];
|
|
259
|
+
for (var i = 0; i < expectedValues.length; i++) {
|
|
260
|
+
if (is(propValue, expectedValues[i])) {
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
266
|
+
var valuesString = JSON.stringify(expectedValues);
|
|
267
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
|
268
|
+
}
|
|
269
|
+
return createChainableTypeChecker(validate);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
function createObjectOfTypeChecker(typeChecker) {
|
|
273
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
274
|
+
if (typeof typeChecker !== 'function') {
|
|
275
|
+
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
|
276
|
+
}
|
|
277
|
+
var propValue = props[propName];
|
|
278
|
+
var propType = getPropType(propValue);
|
|
279
|
+
if (propType !== 'object') {
|
|
280
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
281
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
|
282
|
+
}
|
|
283
|
+
for (var key in propValue) {
|
|
284
|
+
if (propValue.hasOwnProperty(key)) {
|
|
285
|
+
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key);
|
|
286
|
+
if (error instanceof Error) {
|
|
287
|
+
return error;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
return createChainableTypeChecker(validate);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
297
|
+
if (!Array.isArray(arrayOfTypeCheckers)) {
|
|
298
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
|
|
299
|
+
return emptyFunction.thatReturnsNull;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
303
|
+
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
304
|
+
var checker = arrayOfTypeCheckers[i];
|
|
305
|
+
if (checker(props, propName, componentName, location, propFullName) == null) {
|
|
306
|
+
return null;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
311
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
|
|
312
|
+
}
|
|
313
|
+
return createChainableTypeChecker(validate);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function createNodeChecker() {
|
|
317
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
318
|
+
if (!isNode(props[propName])) {
|
|
319
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
320
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
return createChainableTypeChecker(validate);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
function createShapeTypeChecker(shapeTypes) {
|
|
328
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
329
|
+
var propValue = props[propName];
|
|
330
|
+
var propType = getPropType(propValue);
|
|
331
|
+
if (propType !== 'object') {
|
|
332
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
333
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
334
|
+
}
|
|
335
|
+
for (var key in shapeTypes) {
|
|
336
|
+
var checker = shapeTypes[key];
|
|
337
|
+
if (!checker) {
|
|
338
|
+
continue;
|
|
339
|
+
}
|
|
340
|
+
var error = checker(propValue, key, componentName, location, propFullName + '.' + key);
|
|
341
|
+
if (error) {
|
|
342
|
+
return error;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
return null;
|
|
346
|
+
}
|
|
347
|
+
return createChainableTypeChecker(validate);
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
function isNode(propValue) {
|
|
351
|
+
switch (typeof propValue) {
|
|
352
|
+
case 'number':
|
|
353
|
+
case 'string':
|
|
354
|
+
case 'undefined':
|
|
355
|
+
return true;
|
|
356
|
+
case 'boolean':
|
|
357
|
+
return !propValue;
|
|
358
|
+
case 'object':
|
|
359
|
+
if (Array.isArray(propValue)) {
|
|
360
|
+
return propValue.every(isNode);
|
|
361
|
+
}
|
|
362
|
+
if (propValue === null || ReactElement.isValidElement(propValue)) {
|
|
363
|
+
return true;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
var iteratorFn = getIteratorFn(propValue);
|
|
367
|
+
if (iteratorFn) {
|
|
368
|
+
var iterator = iteratorFn.call(propValue);
|
|
369
|
+
var step;
|
|
370
|
+
if (iteratorFn !== propValue.entries) {
|
|
371
|
+
while (!(step = iterator.next()).done) {
|
|
372
|
+
if (!isNode(step.value)) {
|
|
373
|
+
return false;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
} else {
|
|
377
|
+
// Iterator will provide entry [k,v] tuples rather than values.
|
|
378
|
+
while (!(step = iterator.next()).done) {
|
|
379
|
+
var entry = step.value;
|
|
380
|
+
if (entry) {
|
|
381
|
+
if (!isNode(entry[1])) {
|
|
382
|
+
return false;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
} else {
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
return true;
|
|
392
|
+
default:
|
|
393
|
+
return false;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function isSymbol(propType, propValue) {
|
|
398
|
+
// Native Symbol.
|
|
399
|
+
if (propType === 'symbol') {
|
|
400
|
+
return true;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
|
|
404
|
+
if (propValue['@@toStringTag'] === 'Symbol') {
|
|
405
|
+
return true;
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// Fallback for non-spec compliant Symbols which are polyfilled.
|
|
409
|
+
if (typeof Symbol === 'function' && propValue instanceof Symbol) {
|
|
410
|
+
return true;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
return false;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// Equivalent of `typeof` but with special handling for array and regexp.
|
|
417
|
+
function getPropType(propValue) {
|
|
418
|
+
var propType = typeof propValue;
|
|
419
|
+
if (Array.isArray(propValue)) {
|
|
420
|
+
return 'array';
|
|
421
|
+
}
|
|
422
|
+
if (propValue instanceof RegExp) {
|
|
423
|
+
// Old webkits (at least until Android 4.0) return 'function' rather than
|
|
424
|
+
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/
|
|
425
|
+
// passes PropTypes.object.
|
|
426
|
+
return 'object';
|
|
427
|
+
}
|
|
428
|
+
if (isSymbol(propType, propValue)) {
|
|
429
|
+
return 'symbol';
|
|
430
|
+
}
|
|
431
|
+
return propType;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
// This handles more types than `getPropType`. Only used for error messages.
|
|
435
|
+
// See `createPrimitiveTypeChecker`.
|
|
436
|
+
function getPreciseType(propValue) {
|
|
437
|
+
var propType = getPropType(propValue);
|
|
438
|
+
if (propType === 'object') {
|
|
439
|
+
if (propValue instanceof Date) {
|
|
440
|
+
return 'date';
|
|
441
|
+
} else if (propValue instanceof RegExp) {
|
|
442
|
+
return 'regexp';
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
return propType;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
// Returns class name of the object, if any.
|
|
449
|
+
function getClassName(propValue) {
|
|
450
|
+
if (!propValue.constructor || !propValue.constructor.name) {
|
|
451
|
+
return ANONYMOUS;
|
|
452
|
+
}
|
|
453
|
+
return propValue.constructor.name;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
module.exports = ReactPropTypes;
|