react 15.6.2 → 16.0.0-alpha.2
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 +3772 -4326
- package/dist/react-with-addons.min.js +12 -6
- package/dist/react.js +2798 -3167
- package/dist/react.min.js +12 -5
- package/lib/KeyEscapeUtils.js +5 -3
- package/lib/PooledClass.js +5 -3
- package/lib/React.js +11 -46
- package/lib/ReactAddonsDOMDependencies.js +5 -3
- package/lib/ReactAddonsDOMDependenciesUMDShim.js +5 -3
- package/lib/ReactBaseClasses.js +9 -13
- package/lib/ReactCSSTransitionGroup.js +9 -9
- package/lib/ReactCSSTransitionGroupChild.js +118 -134
- package/lib/ReactChildren.js +9 -7
- package/lib/ReactClass.js +704 -0
- 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 +15 -14
- package/lib/ReactFragment.js +5 -3
- package/lib/ReactNoopUpdateQueue.js +16 -17
- package/lib/ReactPropTypeLocationNames.js +5 -3
- package/lib/ReactPropTypeLocations.js +5 -3
- package/lib/ReactPropTypes.js +460 -7
- package/lib/ReactPropTypesSecret.js +5 -3
- 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 +21 -7
- package/lib/deprecated.js +8 -6
- package/lib/flattenChildren.js +5 -3
- package/lib/getComponentName.js +35 -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 +20 -29
- package/lib/update.js +5 -3
- package/package.json +4 -5
- package/lib/LinkedStateMixin.js +0 -32
- package/lib/ReactComponentTreeDevtool.js +0 -12
- package/lib/ReactLink.js +0 -47
- package/lib/createClass.js +0 -20
- package/lib/getNextDebugIDUMDShim.js +0 -15
- package/lib/lowPriorityWarning.js +0 -62
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
|
|
|
@@ -13,7 +15,7 @@ var warning = require('fbjs/lib/warning');
|
|
|
13
15
|
function warnNoop(publicInstance, callerName) {
|
|
14
16
|
if (process.env.NODE_ENV !== 'production') {
|
|
15
17
|
var constructor = publicInstance.constructor;
|
|
16
|
-
process.env.NODE_ENV !== 'production' ? warning(false, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted component. ' + 'This is a no-op
|
|
18
|
+
process.env.NODE_ENV !== 'production' ? warning(false, '%s(...): Can only update a mounted or mounting component. ' + 'This usually means you called %s() on an unmounted component. ' + 'This is a no-op.\n\nPlease check the code for the %s component.', callerName, callerName, constructor && (constructor.displayName || constructor.name) || 'ReactClass') : void 0;
|
|
17
19
|
}
|
|
18
20
|
}
|
|
19
21
|
|
|
@@ -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,469 @@
|
|
|
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');
|
|
17
|
+
var ReactPropTypesSecret = require('./ReactPropTypesSecret');
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
var emptyFunction = require('fbjs/lib/emptyFunction');
|
|
20
|
+
var getIteratorFn = require('./getIteratorFn');
|
|
21
|
+
var invariant = require('fbjs/lib/invariant');
|
|
22
|
+
var warning = require('fbjs/lib/warning');
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Collection of methods that allow declaration and validation of props that are
|
|
26
|
+
* supplied to React components. Example usage:
|
|
27
|
+
*
|
|
28
|
+
* var Props = require('ReactPropTypes');
|
|
29
|
+
* var MyArticle = React.createClass({
|
|
30
|
+
* propTypes: {
|
|
31
|
+
* // An optional string prop named "description".
|
|
32
|
+
* description: Props.string,
|
|
33
|
+
*
|
|
34
|
+
* // A required enum prop named "category".
|
|
35
|
+
* category: Props.oneOf(['News','Photos']).isRequired,
|
|
36
|
+
*
|
|
37
|
+
* // A prop named "dialog" that requires an instance of Dialog.
|
|
38
|
+
* dialog: Props.instanceOf(Dialog).isRequired
|
|
39
|
+
* },
|
|
40
|
+
* render: function() { ... }
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* A more formal specification of how these methods are used:
|
|
44
|
+
*
|
|
45
|
+
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
|
|
46
|
+
* decl := ReactPropTypes.{type}(.isRequired)?
|
|
47
|
+
*
|
|
48
|
+
* Each and every declaration produces a function with the same signature. This
|
|
49
|
+
* allows the creation of custom validation functions. For example:
|
|
50
|
+
*
|
|
51
|
+
* var MyLink = React.createClass({
|
|
52
|
+
* propTypes: {
|
|
53
|
+
* // An optional string or URI prop named "href".
|
|
54
|
+
* href: function(props, propName, componentName) {
|
|
55
|
+
* var propValue = props[propName];
|
|
56
|
+
* if (propValue != null && typeof propValue !== 'string' &&
|
|
57
|
+
* !(propValue instanceof URI)) {
|
|
58
|
+
* return new Error(
|
|
59
|
+
* 'Expected a string or an URI for ' + propName + ' in ' +
|
|
60
|
+
* componentName
|
|
61
|
+
* );
|
|
62
|
+
* }
|
|
63
|
+
* }
|
|
64
|
+
* },
|
|
65
|
+
* render: function() {...}
|
|
66
|
+
* });
|
|
67
|
+
*
|
|
68
|
+
* @internal
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
var ANONYMOUS = '<<anonymous>>';
|
|
72
|
+
|
|
73
|
+
var ReactPropTypes;
|
|
74
|
+
|
|
75
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
76
|
+
// Keep in sync with production version below
|
|
77
|
+
ReactPropTypes = {
|
|
78
|
+
array: createPrimitiveTypeChecker('array'),
|
|
79
|
+
bool: createPrimitiveTypeChecker('boolean'),
|
|
80
|
+
func: createPrimitiveTypeChecker('function'),
|
|
81
|
+
number: createPrimitiveTypeChecker('number'),
|
|
82
|
+
object: createPrimitiveTypeChecker('object'),
|
|
83
|
+
string: createPrimitiveTypeChecker('string'),
|
|
84
|
+
symbol: createPrimitiveTypeChecker('symbol'),
|
|
85
|
+
|
|
86
|
+
any: createAnyTypeChecker(),
|
|
87
|
+
arrayOf: createArrayOfTypeChecker,
|
|
88
|
+
element: createElementTypeChecker(),
|
|
89
|
+
instanceOf: createInstanceTypeChecker,
|
|
90
|
+
node: createNodeChecker(),
|
|
91
|
+
objectOf: createObjectOfTypeChecker,
|
|
92
|
+
oneOf: createEnumTypeChecker,
|
|
93
|
+
oneOfType: createUnionTypeChecker,
|
|
94
|
+
shape: createShapeTypeChecker
|
|
95
|
+
};
|
|
96
|
+
} else {
|
|
97
|
+
var productionTypeChecker = function () {
|
|
98
|
+
invariant(false, 'React.PropTypes type checking code is stripped in production.');
|
|
99
|
+
};
|
|
100
|
+
productionTypeChecker.isRequired = productionTypeChecker;
|
|
101
|
+
var getProductionTypeChecker = function () {
|
|
102
|
+
return productionTypeChecker;
|
|
103
|
+
};
|
|
104
|
+
// Keep in sync with development version above
|
|
105
|
+
ReactPropTypes = {
|
|
106
|
+
array: productionTypeChecker,
|
|
107
|
+
bool: productionTypeChecker,
|
|
108
|
+
func: productionTypeChecker,
|
|
109
|
+
number: productionTypeChecker,
|
|
110
|
+
object: productionTypeChecker,
|
|
111
|
+
string: productionTypeChecker,
|
|
112
|
+
symbol: productionTypeChecker,
|
|
113
|
+
|
|
114
|
+
any: productionTypeChecker,
|
|
115
|
+
arrayOf: getProductionTypeChecker,
|
|
116
|
+
element: productionTypeChecker,
|
|
117
|
+
instanceOf: getProductionTypeChecker,
|
|
118
|
+
node: productionTypeChecker,
|
|
119
|
+
objectOf: getProductionTypeChecker,
|
|
120
|
+
oneOf: getProductionTypeChecker,
|
|
121
|
+
oneOfType: getProductionTypeChecker,
|
|
122
|
+
shape: getProductionTypeChecker
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* inlined Object.is polyfill to avoid requiring consumers ship their own
|
|
128
|
+
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
|
|
129
|
+
*/
|
|
130
|
+
/*eslint-disable no-self-compare*/
|
|
131
|
+
function is(x, y) {
|
|
132
|
+
// SameValue algorithm
|
|
133
|
+
if (x === y) {
|
|
134
|
+
// Steps 1-5, 7-10
|
|
135
|
+
// Steps 6.b-6.e: +0 != -0
|
|
136
|
+
return x !== 0 || 1 / x === 1 / y;
|
|
137
|
+
} else {
|
|
138
|
+
// Step 6.a: NaN == NaN
|
|
139
|
+
return x !== x && y !== y;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
/*eslint-enable no-self-compare*/
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* We use an Error-like object for backward compatibility as people may call
|
|
146
|
+
* PropTypes directly and inspect their output. However, we don't use real
|
|
147
|
+
* Errors anymore. We don't inspect their stack anyway, and creating them
|
|
148
|
+
* is prohibitively expensive if they are created too often, such as what
|
|
149
|
+
* happens in oneOfType() for any type before the one that matched.
|
|
150
|
+
*/
|
|
151
|
+
function PropTypeError(message) {
|
|
152
|
+
this.message = message;
|
|
153
|
+
this.stack = '';
|
|
154
|
+
}
|
|
155
|
+
// Make `instanceof Error` still work for returned errors.
|
|
156
|
+
PropTypeError.prototype = Error.prototype;
|
|
157
|
+
|
|
158
|
+
function createChainableTypeChecker(validate) {
|
|
159
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
160
|
+
var manualPropTypeCallCache = {};
|
|
161
|
+
}
|
|
162
|
+
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
|
|
163
|
+
componentName = componentName || ANONYMOUS;
|
|
164
|
+
propFullName = propFullName || propName;
|
|
165
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
166
|
+
if (secret !== ReactPropTypesSecret && typeof console !== 'undefined') {
|
|
167
|
+
var cacheKey = componentName + ':' + propName;
|
|
168
|
+
if (!manualPropTypeCallCache[cacheKey]) {
|
|
169
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'You are manually calling a React.PropTypes validation ' + 'function for the `%s` prop on `%s`. This is deprecated ' + 'and will not work in production with the next major version. ' + 'You may be seeing this warning due to a third-party PropTypes ' + 'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.', propFullName, componentName) : void 0;
|
|
170
|
+
manualPropTypeCallCache[cacheKey] = true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
if (props[propName] == null) {
|
|
175
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
176
|
+
if (isRequired) {
|
|
177
|
+
if (props[propName] === null) {
|
|
178
|
+
return new PropTypeError('The ' + locationName + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
|
|
179
|
+
}
|
|
180
|
+
return new PropTypeError('The ' + locationName + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
|
|
181
|
+
}
|
|
182
|
+
return null;
|
|
183
|
+
} else {
|
|
184
|
+
return validate(props, propName, componentName, location, propFullName);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
var chainedCheckType = checkType.bind(null, false);
|
|
189
|
+
chainedCheckType.isRequired = checkType.bind(null, true);
|
|
190
|
+
|
|
191
|
+
return chainedCheckType;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function createPrimitiveTypeChecker(expectedType) {
|
|
195
|
+
function validate(props, propName, componentName, location, propFullName, secret) {
|
|
196
|
+
var propValue = props[propName];
|
|
197
|
+
var propType = getPropType(propValue);
|
|
198
|
+
if (propType !== expectedType) {
|
|
199
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
200
|
+
// `propValue` being instance of, say, date/regexp, pass the 'object'
|
|
201
|
+
// check, but we can offer a more precise error message here rather than
|
|
202
|
+
// 'of type `object`'.
|
|
203
|
+
var preciseType = getPreciseType(propValue);
|
|
204
|
+
|
|
205
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
return createChainableTypeChecker(validate);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function createAnyTypeChecker() {
|
|
213
|
+
return createChainableTypeChecker(emptyFunction.thatReturnsNull);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function createArrayOfTypeChecker(typeChecker) {
|
|
217
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
218
|
+
if (typeof typeChecker !== 'function') {
|
|
219
|
+
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
|
|
220
|
+
}
|
|
221
|
+
var propValue = props[propName];
|
|
222
|
+
if (!Array.isArray(propValue)) {
|
|
223
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
224
|
+
var propType = getPropType(propValue);
|
|
225
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
|
|
226
|
+
}
|
|
227
|
+
for (var i = 0; i < propValue.length; i++) {
|
|
228
|
+
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
|
|
229
|
+
if (error instanceof Error) {
|
|
230
|
+
return error;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
return createChainableTypeChecker(validate);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
function createElementTypeChecker() {
|
|
239
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
240
|
+
var propValue = props[propName];
|
|
241
|
+
if (!ReactElement.isValidElement(propValue)) {
|
|
242
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
243
|
+
var propType = getPropType(propValue);
|
|
244
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected a single ReactElement.'));
|
|
245
|
+
}
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
return createChainableTypeChecker(validate);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function createInstanceTypeChecker(expectedClass) {
|
|
252
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
253
|
+
if (!(props[propName] instanceof expectedClass)) {
|
|
254
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
255
|
+
var expectedClassName = expectedClass.name || ANONYMOUS;
|
|
256
|
+
var actualClassName = getClassName(props[propName]);
|
|
257
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + actualClassName + '` supplied to `' + componentName + '`, expected ') + ('instance of `' + expectedClassName + '`.'));
|
|
258
|
+
}
|
|
259
|
+
return null;
|
|
260
|
+
}
|
|
261
|
+
return createChainableTypeChecker(validate);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function createEnumTypeChecker(expectedValues) {
|
|
265
|
+
if (!Array.isArray(expectedValues)) {
|
|
266
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOf, expected an instance of array.') : void 0;
|
|
267
|
+
return emptyFunction.thatReturnsNull;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
271
|
+
var propValue = props[propName];
|
|
272
|
+
for (var i = 0; i < expectedValues.length; i++) {
|
|
273
|
+
if (is(propValue, expectedValues[i])) {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
279
|
+
var valuesString = JSON.stringify(expectedValues);
|
|
280
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of value `' + propValue + '` ' + ('supplied to `' + componentName + '`, expected one of ' + valuesString + '.'));
|
|
281
|
+
}
|
|
282
|
+
return createChainableTypeChecker(validate);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
function createObjectOfTypeChecker(typeChecker) {
|
|
286
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
287
|
+
if (typeof typeChecker !== 'function') {
|
|
288
|
+
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside objectOf.');
|
|
289
|
+
}
|
|
290
|
+
var propValue = props[propName];
|
|
291
|
+
var propType = getPropType(propValue);
|
|
292
|
+
if (propType !== 'object') {
|
|
293
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
294
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an object.'));
|
|
295
|
+
}
|
|
296
|
+
for (var key in propValue) {
|
|
297
|
+
if (propValue.hasOwnProperty(key)) {
|
|
298
|
+
var error = typeChecker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
|
299
|
+
if (error instanceof Error) {
|
|
300
|
+
return error;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
return createChainableTypeChecker(validate);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
function createUnionTypeChecker(arrayOfTypeCheckers) {
|
|
310
|
+
if (!Array.isArray(arrayOfTypeCheckers)) {
|
|
311
|
+
process.env.NODE_ENV !== 'production' ? warning(false, 'Invalid argument supplied to oneOfType, expected an instance of array.') : void 0;
|
|
312
|
+
return emptyFunction.thatReturnsNull;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
316
|
+
for (var i = 0; i < arrayOfTypeCheckers.length; i++) {
|
|
317
|
+
var checker = arrayOfTypeCheckers[i];
|
|
318
|
+
if (checker(props, propName, componentName, location, propFullName, ReactPropTypesSecret) == null) {
|
|
319
|
+
return null;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
324
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`.'));
|
|
325
|
+
}
|
|
326
|
+
return createChainableTypeChecker(validate);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function createNodeChecker() {
|
|
330
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
331
|
+
if (!isNode(props[propName])) {
|
|
332
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
333
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` supplied to ' + ('`' + componentName + '`, expected a ReactNode.'));
|
|
334
|
+
}
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
return createChainableTypeChecker(validate);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function createShapeTypeChecker(shapeTypes) {
|
|
341
|
+
function validate(props, propName, componentName, location, propFullName) {
|
|
342
|
+
var propValue = props[propName];
|
|
343
|
+
var propType = getPropType(propValue);
|
|
344
|
+
if (propType !== 'object') {
|
|
345
|
+
var locationName = ReactPropTypeLocationNames[location];
|
|
346
|
+
return new PropTypeError('Invalid ' + locationName + ' `' + propFullName + '` of type `' + propType + '` ' + ('supplied to `' + componentName + '`, expected `object`.'));
|
|
347
|
+
}
|
|
348
|
+
for (var key in shapeTypes) {
|
|
349
|
+
var checker = shapeTypes[key];
|
|
350
|
+
if (!checker) {
|
|
351
|
+
continue;
|
|
352
|
+
}
|
|
353
|
+
var error = checker(propValue, key, componentName, location, propFullName + '.' + key, ReactPropTypesSecret);
|
|
354
|
+
if (error) {
|
|
355
|
+
return error;
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
return null;
|
|
359
|
+
}
|
|
360
|
+
return createChainableTypeChecker(validate);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function isNode(propValue) {
|
|
364
|
+
switch (typeof propValue) {
|
|
365
|
+
case 'number':
|
|
366
|
+
case 'string':
|
|
367
|
+
case 'undefined':
|
|
368
|
+
return true;
|
|
369
|
+
case 'boolean':
|
|
370
|
+
return !propValue;
|
|
371
|
+
case 'object':
|
|
372
|
+
if (Array.isArray(propValue)) {
|
|
373
|
+
return propValue.every(isNode);
|
|
374
|
+
}
|
|
375
|
+
if (propValue === null || ReactElement.isValidElement(propValue)) {
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
var iteratorFn = getIteratorFn(propValue);
|
|
380
|
+
if (iteratorFn) {
|
|
381
|
+
var iterator = iteratorFn.call(propValue);
|
|
382
|
+
var step;
|
|
383
|
+
if (iteratorFn !== propValue.entries) {
|
|
384
|
+
while (!(step = iterator.next()).done) {
|
|
385
|
+
if (!isNode(step.value)) {
|
|
386
|
+
return false;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
} else {
|
|
390
|
+
// Iterator will provide entry [k,v] tuples rather than values.
|
|
391
|
+
while (!(step = iterator.next()).done) {
|
|
392
|
+
var entry = step.value;
|
|
393
|
+
if (entry) {
|
|
394
|
+
if (!isNode(entry[1])) {
|
|
395
|
+
return false;
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
} else {
|
|
401
|
+
return false;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
return true;
|
|
405
|
+
default:
|
|
406
|
+
return false;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
function isSymbol(propType, propValue) {
|
|
411
|
+
// Native Symbol.
|
|
412
|
+
if (propType === 'symbol') {
|
|
413
|
+
return true;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
// 19.4.3.5 Symbol.prototype[@@toStringTag] === 'Symbol'
|
|
417
|
+
if (propValue['@@toStringTag'] === 'Symbol') {
|
|
418
|
+
return true;
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
// Fallback for non-spec compliant Symbols which are polyfilled.
|
|
422
|
+
if (typeof Symbol === 'function' && propValue instanceof Symbol) {
|
|
423
|
+
return true;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Equivalent of `typeof` but with special handling for array and regexp.
|
|
430
|
+
function getPropType(propValue) {
|
|
431
|
+
var propType = typeof propValue;
|
|
432
|
+
if (Array.isArray(propValue)) {
|
|
433
|
+
return 'array';
|
|
434
|
+
}
|
|
435
|
+
if (propValue instanceof RegExp) {
|
|
436
|
+
// Old webkits (at least until Android 4.0) return 'function' rather than
|
|
437
|
+
// 'object' for typeof a RegExp. We'll normalize this here so that /bla/
|
|
438
|
+
// passes PropTypes.object.
|
|
439
|
+
return 'object';
|
|
440
|
+
}
|
|
441
|
+
if (isSymbol(propType, propValue)) {
|
|
442
|
+
return 'symbol';
|
|
443
|
+
}
|
|
444
|
+
return propType;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// This handles more types than `getPropType`. Only used for error messages.
|
|
448
|
+
// See `createPrimitiveTypeChecker`.
|
|
449
|
+
function getPreciseType(propValue) {
|
|
450
|
+
var propType = getPropType(propValue);
|
|
451
|
+
if (propType === 'object') {
|
|
452
|
+
if (propValue instanceof Date) {
|
|
453
|
+
return 'date';
|
|
454
|
+
} else if (propValue instanceof RegExp) {
|
|
455
|
+
return 'regexp';
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return propType;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
// Returns class name of the object, if any.
|
|
462
|
+
function getClassName(propValue) {
|
|
463
|
+
if (!propValue.constructor || !propValue.constructor.name) {
|
|
464
|
+
return ANONYMOUS;
|
|
465
|
+
}
|
|
466
|
+
return propValue.constructor.name;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
module.exports = ReactPropTypes;
|