victory-core 36.8.6 → 36.9.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/CHANGELOG.md +6 -0
- package/dist/victory-core.js +74 -2349
- package/dist/victory-core.min.js +1 -1
- package/es/victory-accessible-group/victory-accessible-group.d.ts +0 -9
- package/es/victory-accessible-group/victory-accessible-group.js +0 -9
- package/es/victory-animation/victory-animation.d.ts +0 -9
- package/es/victory-animation/victory-animation.js +0 -9
- package/es/victory-clip-container/victory-clip-container.d.ts +0 -30
- package/es/victory-clip-container/victory-clip-container.js +0 -31
- package/es/victory-container/victory-container.d.ts +0 -31
- package/es/victory-container/victory-container.js +0 -32
- package/es/victory-label/victory-label.js +1 -52
- package/es/victory-portal/portal.d.ts +0 -8
- package/es/victory-portal/portal.js +1 -10
- package/es/victory-portal/victory-portal.d.ts +0 -5
- package/es/victory-portal/victory-portal.js +0 -5
- package/es/victory-primitives/arc.d.ts +1 -32
- package/es/victory-primitives/arc.js +1 -13
- package/es/victory-primitives/background.d.ts +1 -32
- package/es/victory-primitives/background.js +1 -13
- package/es/victory-primitives/border.d.ts +1 -29
- package/es/victory-primitives/border.js +1 -10
- package/es/victory-primitives/line-segment.d.ts +1 -30
- package/es/victory-primitives/line-segment.js +1 -11
- package/es/victory-primitives/point.d.ts +1 -31
- package/es/victory-primitives/point.js +1 -12
- package/es/victory-primitives/whisker.d.ts +1 -38
- package/es/victory-primitives/whisker.js +1 -19
- package/es/victory-transition/victory-transition.d.ts +0 -6
- package/es/victory-transition/victory-transition.js +0 -6
- package/es/victory-util/common-props.d.ts +0 -5
- package/es/victory-util/common-props.js +1 -132
- package/es/victory-util/index.d.ts +0 -1
- package/es/victory-util/index.js +0 -2
- package/lib/victory-accessible-group/victory-accessible-group.d.ts +0 -9
- package/lib/victory-accessible-group/victory-accessible-group.js +0 -10
- package/lib/victory-animation/victory-animation.d.ts +0 -9
- package/lib/victory-animation/victory-animation.js +0 -10
- package/lib/victory-clip-container/victory-clip-container.d.ts +0 -30
- package/lib/victory-clip-container/victory-clip-container.js +0 -33
- package/lib/victory-container/victory-container.d.ts +0 -31
- package/lib/victory-container/victory-container.js +0 -34
- package/lib/victory-label/victory-label.js +1 -54
- package/lib/victory-portal/portal.d.ts +0 -8
- package/lib/victory-portal/portal.js +1 -16
- package/lib/victory-portal/victory-portal.d.ts +0 -5
- package/lib/victory-portal/victory-portal.js +0 -6
- package/lib/victory-primitives/arc.d.ts +1 -32
- package/lib/victory-primitives/arc.js +1 -15
- package/lib/victory-primitives/background.d.ts +1 -32
- package/lib/victory-primitives/background.js +1 -15
- package/lib/victory-primitives/border.d.ts +1 -29
- package/lib/victory-primitives/border.js +1 -12
- package/lib/victory-primitives/line-segment.d.ts +1 -30
- package/lib/victory-primitives/line-segment.js +1 -13
- package/lib/victory-primitives/point.d.ts +1 -31
- package/lib/victory-primitives/point.js +1 -14
- package/lib/victory-primitives/whisker.d.ts +1 -38
- package/lib/victory-primitives/whisker.js +1 -21
- package/lib/victory-transition/victory-transition.d.ts +0 -6
- package/lib/victory-transition/victory-transition.js +0 -7
- package/lib/victory-util/common-props.d.ts +0 -5
- package/lib/victory-util/common-props.js +1 -148
- package/lib/victory-util/index.d.ts +0 -1
- package/lib/victory-util/index.js +1 -6
- package/package.json +2 -3
- package/src/victory-accessible-group/victory-accessible-group.tsx +0 -12
- package/src/victory-animation/victory-animation.tsx +0 -51
- package/src/victory-clip-container/victory-clip-container.tsx +0 -34
- package/src/victory-container/victory-container.tsx +0 -35
- package/src/victory-label/victory-label.tsx +0 -83
- package/src/victory-portal/portal.tsx +0 -9
- package/src/victory-portal/victory-portal.tsx +0 -6
- package/src/victory-primitives/arc.tsx +1 -17
- package/src/victory-primitives/background.tsx +1 -17
- package/src/victory-primitives/border.tsx +1 -14
- package/src/victory-primitives/line-segment.tsx +1 -15
- package/src/victory-primitives/point.tsx +1 -29
- package/src/victory-primitives/whisker.tsx +1 -23
- package/src/victory-transition/victory-transition.tsx +0 -7
- package/src/victory-util/common-props.tsx +0 -218
- package/src/victory-util/index.ts +0 -1
- package/es/victory-util/prop-types.d.ts +0 -51
- package/es/victory-util/prop-types.js +0 -241
- package/lib/victory-util/prop-types.d.ts +0 -51
- package/lib/victory-util/prop-types.js +0 -269
- package/src/victory-util/prop-types.ts +0 -254
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import PropTypes from "prop-types";
|
|
2
|
-
import { D3Scale, ScaleName } from "../types/prop-types";
|
|
3
|
-
/**
|
|
4
|
-
* Return a new validator based on `propType` but which logs a `console.error`
|
|
5
|
-
* with `explanation` if used.
|
|
6
|
-
* @param {Function} propType The old, deprecated propType.
|
|
7
|
-
* @param {String} explanation The message to provide the user of the deprecated propType.
|
|
8
|
-
* @returns {Function} Validator which logs usage of this propType
|
|
9
|
-
*/
|
|
10
|
-
export declare function deprecated<T>(propType: PropTypes.Validator<T>, explanation: string): PropTypes.Validator<T>;
|
|
11
|
-
/**
|
|
12
|
-
* Return a new validator which returns true
|
|
13
|
-
* if and only if all validators passed as arguments return true.
|
|
14
|
-
* Like React.propTypes.oneOfType, except "all" instead of "any"
|
|
15
|
-
* @param {Array} validators Validation functions.
|
|
16
|
-
* @returns {Function} Combined validator function
|
|
17
|
-
*/
|
|
18
|
-
export declare function allOfType<T>(validators: Array<PropTypes.Validator<T>>): PropTypes.Requireable<T | undefined>;
|
|
19
|
-
/**
|
|
20
|
-
* Check that the value is a non-negative number.
|
|
21
|
-
*/
|
|
22
|
-
export declare const nonNegative: PropTypes.Requireable<number | undefined>;
|
|
23
|
-
/**
|
|
24
|
-
* Check that the value is an integer.
|
|
25
|
-
*/
|
|
26
|
-
export declare const integer: PropTypes.Requireable<number | undefined>;
|
|
27
|
-
/**
|
|
28
|
-
* Check that the value is greater than zero.
|
|
29
|
-
*/
|
|
30
|
-
export declare const greaterThanZero: PropTypes.Requireable<number | undefined>;
|
|
31
|
-
/**
|
|
32
|
-
* Check that the value is an Array of two unique values.
|
|
33
|
-
*/
|
|
34
|
-
export declare const domain: PropTypes.Requireable<[number, number] | undefined>;
|
|
35
|
-
/**
|
|
36
|
-
* Check that the value looks like a d3 `scale` function.
|
|
37
|
-
*/
|
|
38
|
-
export declare const scale: PropTypes.Requireable<ScaleName | D3Scale<any> | undefined>;
|
|
39
|
-
/**
|
|
40
|
-
* Check that an array contains items of the same type.
|
|
41
|
-
*/
|
|
42
|
-
export declare const homogeneousArray: PropTypes.Requireable<unknown[] | undefined>;
|
|
43
|
-
/**
|
|
44
|
-
* Check that array prop length matches props.data.length
|
|
45
|
-
*/
|
|
46
|
-
export declare const matchDataLength: PropTypes.Requireable<unknown[] | undefined>;
|
|
47
|
-
/**
|
|
48
|
-
* Check that the value is a regular expression
|
|
49
|
-
*/
|
|
50
|
-
export declare const regExp: PropTypes.Requireable<RegExp | undefined>;
|
|
51
|
-
//# sourceMappingURL=prop-types.d.ts.map
|
|
@@ -1,269 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.allOfType = allOfType;
|
|
7
|
-
exports.deprecated = deprecated;
|
|
8
|
-
exports.scale = exports.regExp = exports.nonNegative = exports.matchDataLength = exports.integer = exports.homogeneousArray = exports.greaterThanZero = exports.domain = void 0;
|
|
9
|
-
|
|
10
|
-
var _isRegExp2 = _interopRequireDefault(require("lodash/isRegExp"));
|
|
11
|
-
|
|
12
|
-
var _find2 = _interopRequireDefault(require("lodash/find"));
|
|
13
|
-
|
|
14
|
-
var Log = _interopRequireWildcard(require("./log"));
|
|
15
|
-
|
|
16
|
-
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
17
|
-
|
|
18
|
-
var Scale = _interopRequireWildcard(require("./scale"));
|
|
19
|
-
|
|
20
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
21
|
-
|
|
22
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
23
|
-
|
|
24
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
|
-
|
|
26
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Return a new validator based on `validator` but with the option to chain
|
|
30
|
-
* `isRequired` onto the validation. This is nearly identical to how React
|
|
31
|
-
* does it internally, but they don't expose their helper for us to use.
|
|
32
|
-
* @param {Function} validator Validation function.
|
|
33
|
-
* @returns {Function} Validator with `isRequired` option.
|
|
34
|
-
*/
|
|
35
|
-
var makeChainable = function (validator) {
|
|
36
|
-
var createChainable = function (isRequired) {
|
|
37
|
-
return function (props, propName, componentName) {
|
|
38
|
-
var value = props[propName];
|
|
39
|
-
|
|
40
|
-
if (value === undefined || value === null) {
|
|
41
|
-
if (isRequired) {
|
|
42
|
-
return new Error("Required `".concat(propName, "` was not specified in `").concat(componentName, "`."));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
for (var _len = arguments.length, rest = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
49
|
-
rest[_key - 3] = arguments[_key];
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return validator.apply(void 0, [props, propName, componentName].concat(rest));
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
var chainable = Object.assign(createChainable(false), {
|
|
57
|
-
isRequired: createChainable(true)
|
|
58
|
-
});
|
|
59
|
-
return chainable;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
var nullConstructor = function () {
|
|
63
|
-
return null;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
var undefinedConstructor = function () {
|
|
67
|
-
return undefined;
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* Get the constructor of `value`. If `value` is null or undefined, return the
|
|
71
|
-
* special singletons `nullConstructor` or `undefinedConstructor`, respectively.
|
|
72
|
-
* @param {*} value Instance to return the constructor of.
|
|
73
|
-
* @returns {Function} Constructor of `value`.
|
|
74
|
-
*/
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var getConstructor = function (value) {
|
|
78
|
-
if (value === undefined) {
|
|
79
|
-
return undefinedConstructor;
|
|
80
|
-
} else if (value === null) {
|
|
81
|
-
return nullConstructor;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return value.constructor;
|
|
85
|
-
};
|
|
86
|
-
/**
|
|
87
|
-
* Get the name of the constructor used to create `value`, using
|
|
88
|
-
* `Object.prototype.toString`. If the value is null or undefined, return
|
|
89
|
-
* "null" or "undefined", respectively.
|
|
90
|
-
* @param {*} value Instance to return the constructor name of.
|
|
91
|
-
* @returns {String} Name of the constructor.
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
var getConstructorName = function (value) {
|
|
96
|
-
if (value === undefined) {
|
|
97
|
-
return "undefined";
|
|
98
|
-
} else if (value === null) {
|
|
99
|
-
return "null";
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return Object.prototype.toString.call(value).slice(8, -1); // eslint-disable-line no-magic-numbers
|
|
103
|
-
};
|
|
104
|
-
/**
|
|
105
|
-
* Return a new validator based on `propType` but which logs a `console.error`
|
|
106
|
-
* with `explanation` if used.
|
|
107
|
-
* @param {Function} propType The old, deprecated propType.
|
|
108
|
-
* @param {String} explanation The message to provide the user of the deprecated propType.
|
|
109
|
-
* @returns {Function} Validator which logs usage of this propType
|
|
110
|
-
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
function deprecated(propType, explanation) {
|
|
114
|
-
return function (props, propName, componentName) {
|
|
115
|
-
var value = props[propName];
|
|
116
|
-
|
|
117
|
-
if (value !== null && value !== undefined) {
|
|
118
|
-
Log.warn("\"".concat(propName, "\" property of \"").concat(componentName, "\" has been deprecated ").concat(explanation));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
_propTypes.default.checkPropTypes(_defineProperty({}, propName, propType), props, propName, componentName);
|
|
122
|
-
|
|
123
|
-
return null;
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Return a new validator which returns true
|
|
128
|
-
* if and only if all validators passed as arguments return true.
|
|
129
|
-
* Like React.propTypes.oneOfType, except "all" instead of "any"
|
|
130
|
-
* @param {Array} validators Validation functions.
|
|
131
|
-
* @returns {Function} Combined validator function
|
|
132
|
-
*/
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
function allOfType(validators) {
|
|
136
|
-
return makeChainable(function (props, propName, componentName) {
|
|
137
|
-
for (var _len2 = arguments.length, rest = new Array(_len2 > 3 ? _len2 - 3 : 0), _key2 = 3; _key2 < _len2; _key2++) {
|
|
138
|
-
rest[_key2 - 3] = arguments[_key2];
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return validators.reduce(function (result, validator) {
|
|
142
|
-
return result || validator.apply(void 0, [props, propName, componentName].concat(rest));
|
|
143
|
-
}, null);
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Check that the value is a non-negative number.
|
|
148
|
-
*/
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
var nonNegative = makeChainable(function (props, propName, componentName) {
|
|
152
|
-
var value = props[propName];
|
|
153
|
-
|
|
154
|
-
if (typeof value !== "number" || value < 0) {
|
|
155
|
-
return new Error("`".concat(propName, "` in `").concat(componentName, "` must be a non-negative number."));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return null;
|
|
159
|
-
});
|
|
160
|
-
/**
|
|
161
|
-
* Check that the value is an integer.
|
|
162
|
-
*/
|
|
163
|
-
|
|
164
|
-
exports.nonNegative = nonNegative;
|
|
165
|
-
var integer = makeChainable(function (props, propName, componentName) {
|
|
166
|
-
var value = props[propName];
|
|
167
|
-
|
|
168
|
-
if (typeof value !== "number" || value % 1 !== 0) {
|
|
169
|
-
return new Error("`".concat(propName, "` in `").concat(componentName, "` must be an integer."));
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
return null;
|
|
173
|
-
});
|
|
174
|
-
/**
|
|
175
|
-
* Check that the value is greater than zero.
|
|
176
|
-
*/
|
|
177
|
-
|
|
178
|
-
exports.integer = integer;
|
|
179
|
-
var greaterThanZero = makeChainable(function (props, propName, componentName) {
|
|
180
|
-
var value = props[propName];
|
|
181
|
-
|
|
182
|
-
if (typeof value !== "number" || value <= 0) {
|
|
183
|
-
return new Error("`".concat(propName, "` in `").concat(componentName, "` must be a number greater than zero."));
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return null;
|
|
187
|
-
});
|
|
188
|
-
/**
|
|
189
|
-
* Check that the value is an Array of two unique values.
|
|
190
|
-
*/
|
|
191
|
-
|
|
192
|
-
exports.greaterThanZero = greaterThanZero;
|
|
193
|
-
var domain = makeChainable(function (props, propName, componentName) {
|
|
194
|
-
var value = props[propName];
|
|
195
|
-
|
|
196
|
-
if (!Array.isArray(value) || value.length !== 2 || value[1] === value[0]) {
|
|
197
|
-
return new Error("`".concat(propName, "` in `").concat(componentName, "` must be an array of two unique numeric values."));
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return null;
|
|
201
|
-
});
|
|
202
|
-
/**
|
|
203
|
-
* Check that the value looks like a d3 `scale` function.
|
|
204
|
-
*/
|
|
205
|
-
|
|
206
|
-
exports.domain = domain;
|
|
207
|
-
var scale = makeChainable(function (props, propName, componentName) {
|
|
208
|
-
var value = props[propName];
|
|
209
|
-
|
|
210
|
-
if (!Scale.validScale(value)) {
|
|
211
|
-
return new Error("`".concat(propName, "` in `").concat(componentName, "` must be a d3 scale."));
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
return null;
|
|
215
|
-
});
|
|
216
|
-
/**
|
|
217
|
-
* Check that an array contains items of the same type.
|
|
218
|
-
*/
|
|
219
|
-
|
|
220
|
-
exports.scale = scale;
|
|
221
|
-
var homogeneousArray = makeChainable(function (props, propName, componentName) {
|
|
222
|
-
var values = props[propName];
|
|
223
|
-
|
|
224
|
-
if (!Array.isArray(values)) {
|
|
225
|
-
return new Error("`".concat(propName, "` in `").concat(componentName, "` must be an array."));
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
if (values.length < 2) {
|
|
229
|
-
return null;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
var comparisonConstructor = getConstructor(values[0]);
|
|
233
|
-
var typeMismatchedValue = (0, _find2.default)(values, function (value) {
|
|
234
|
-
return comparisonConstructor !== getConstructor(value);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
if (typeMismatchedValue) {
|
|
238
|
-
var constructorName = getConstructorName(values[0]);
|
|
239
|
-
var otherConstructorName = getConstructorName(typeMismatchedValue);
|
|
240
|
-
return new Error("Expected `".concat(propName, "` in `").concat(componentName, "` to be a ") + "homogeneous array, but found types `".concat(constructorName, "` and ") + "`".concat(otherConstructorName, "`."));
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
return null;
|
|
244
|
-
});
|
|
245
|
-
/**
|
|
246
|
-
* Check that array prop length matches props.data.length
|
|
247
|
-
*/
|
|
248
|
-
|
|
249
|
-
exports.homogeneousArray = homogeneousArray;
|
|
250
|
-
var matchDataLength = makeChainable(function (props, propName) {
|
|
251
|
-
if (props[propName] && Array.isArray(props[propName]) && props[propName].length !== props.data.length) {
|
|
252
|
-
return new Error("Length of data and ".concat(propName, " arrays must match."));
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
return null;
|
|
256
|
-
});
|
|
257
|
-
/**
|
|
258
|
-
* Check that the value is a regular expression
|
|
259
|
-
*/
|
|
260
|
-
|
|
261
|
-
exports.matchDataLength = matchDataLength;
|
|
262
|
-
var regExp = makeChainable(function (props, propName, componentName) {
|
|
263
|
-
if (props[propName] && !(0, _isRegExp2.default)(props[propName])) {
|
|
264
|
-
return new Error("`".concat(propName, "` in `").concat(componentName, "` must be a regular expression."));
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
return null;
|
|
268
|
-
});
|
|
269
|
-
exports.regExp = regExp;
|
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
/* eslint no-magic-numbers: ["error", { "ignore": [-1, 0, 1, 2] }] */
|
|
2
|
-
/* eslint-disable max-params */
|
|
3
|
-
|
|
4
|
-
import { find, isRegExp } from "lodash";
|
|
5
|
-
import * as Log from "./log";
|
|
6
|
-
import PropTypes from "prop-types";
|
|
7
|
-
import * as Scale from "./scale";
|
|
8
|
-
import { D3Scale, ScaleName } from "../types/prop-types";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Return a new validator based on `validator` but with the option to chain
|
|
12
|
-
* `isRequired` onto the validation. This is nearly identical to how React
|
|
13
|
-
* does it internally, but they don't expose their helper for us to use.
|
|
14
|
-
* @param {Function} validator Validation function.
|
|
15
|
-
* @returns {Function} Validator with `isRequired` option.
|
|
16
|
-
*/
|
|
17
|
-
const makeChainable = function <T>(validator: PropTypes.Validator<T>) {
|
|
18
|
-
const createChainable =
|
|
19
|
-
(isRequired: boolean): PropTypes.Validator<T | undefined> =>
|
|
20
|
-
(props, propName, componentName, ...rest) => {
|
|
21
|
-
const value = props[propName];
|
|
22
|
-
if (value === undefined || value === null) {
|
|
23
|
-
if (isRequired) {
|
|
24
|
-
return new Error(
|
|
25
|
-
`Required \`${propName}\` was not specified in \`${componentName}\`.`,
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
return validator(props, propName, componentName, ...rest);
|
|
31
|
-
};
|
|
32
|
-
const chainable = Object.assign(createChainable(false), {
|
|
33
|
-
isRequired: createChainable(true),
|
|
34
|
-
});
|
|
35
|
-
return chainable as PropTypes.Requireable<T | undefined>;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
const nullConstructor = () => null;
|
|
39
|
-
const undefinedConstructor = () => undefined;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Get the constructor of `value`. If `value` is null or undefined, return the
|
|
43
|
-
* special singletons `nullConstructor` or `undefinedConstructor`, respectively.
|
|
44
|
-
* @param {*} value Instance to return the constructor of.
|
|
45
|
-
* @returns {Function} Constructor of `value`.
|
|
46
|
-
*/
|
|
47
|
-
const getConstructor = (value) => {
|
|
48
|
-
if (value === undefined) {
|
|
49
|
-
return undefinedConstructor;
|
|
50
|
-
} else if (value === null) {
|
|
51
|
-
return nullConstructor;
|
|
52
|
-
}
|
|
53
|
-
return value.constructor;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Get the name of the constructor used to create `value`, using
|
|
58
|
-
* `Object.prototype.toString`. If the value is null or undefined, return
|
|
59
|
-
* "null" or "undefined", respectively.
|
|
60
|
-
* @param {*} value Instance to return the constructor name of.
|
|
61
|
-
* @returns {String} Name of the constructor.
|
|
62
|
-
*/
|
|
63
|
-
const getConstructorName = (value) => {
|
|
64
|
-
if (value === undefined) {
|
|
65
|
-
return "undefined";
|
|
66
|
-
} else if (value === null) {
|
|
67
|
-
return "null";
|
|
68
|
-
}
|
|
69
|
-
return Object.prototype.toString.call(value).slice(8, -1); // eslint-disable-line no-magic-numbers
|
|
70
|
-
};
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Return a new validator based on `propType` but which logs a `console.error`
|
|
74
|
-
* with `explanation` if used.
|
|
75
|
-
* @param {Function} propType The old, deprecated propType.
|
|
76
|
-
* @param {String} explanation The message to provide the user of the deprecated propType.
|
|
77
|
-
* @returns {Function} Validator which logs usage of this propType
|
|
78
|
-
*/
|
|
79
|
-
export function deprecated<T>(
|
|
80
|
-
propType: PropTypes.Validator<T>,
|
|
81
|
-
explanation: string,
|
|
82
|
-
): PropTypes.Validator<T> {
|
|
83
|
-
return (props, propName, componentName) => {
|
|
84
|
-
const value = props[propName];
|
|
85
|
-
if (value !== null && value !== undefined) {
|
|
86
|
-
Log.warn(
|
|
87
|
-
`"${propName}" property of "${componentName}" has been deprecated ${explanation}`,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
PropTypes.checkPropTypes(
|
|
91
|
-
{ [propName]: propType },
|
|
92
|
-
props,
|
|
93
|
-
propName,
|
|
94
|
-
componentName,
|
|
95
|
-
);
|
|
96
|
-
return null;
|
|
97
|
-
};
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Return a new validator which returns true
|
|
102
|
-
* if and only if all validators passed as arguments return true.
|
|
103
|
-
* Like React.propTypes.oneOfType, except "all" instead of "any"
|
|
104
|
-
* @param {Array} validators Validation functions.
|
|
105
|
-
* @returns {Function} Combined validator function
|
|
106
|
-
*/
|
|
107
|
-
export function allOfType<T>(validators: Array<PropTypes.Validator<T>>) {
|
|
108
|
-
return makeChainable<T>((props, propName, componentName, ...rest) => {
|
|
109
|
-
return validators.reduce<null | Error>(
|
|
110
|
-
(result, validator) =>
|
|
111
|
-
result || validator(props, propName, componentName, ...rest),
|
|
112
|
-
null,
|
|
113
|
-
);
|
|
114
|
-
});
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
/**
|
|
118
|
-
* Check that the value is a non-negative number.
|
|
119
|
-
*/
|
|
120
|
-
export const nonNegative = makeChainable<number>(
|
|
121
|
-
(props, propName, componentName) => {
|
|
122
|
-
const value = props[propName];
|
|
123
|
-
if (typeof value !== "number" || value < 0) {
|
|
124
|
-
return new Error(
|
|
125
|
-
`\`${propName}\` in \`${componentName}\` must be a non-negative number.`,
|
|
126
|
-
);
|
|
127
|
-
}
|
|
128
|
-
return null;
|
|
129
|
-
},
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Check that the value is an integer.
|
|
134
|
-
*/
|
|
135
|
-
export const integer = makeChainable<number>(
|
|
136
|
-
(props, propName, componentName) => {
|
|
137
|
-
const value = props[propName];
|
|
138
|
-
if (typeof value !== "number" || value % 1 !== 0) {
|
|
139
|
-
return new Error(
|
|
140
|
-
`\`${propName}\` in \`${componentName}\` must be an integer.`,
|
|
141
|
-
);
|
|
142
|
-
}
|
|
143
|
-
return null;
|
|
144
|
-
},
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* Check that the value is greater than zero.
|
|
149
|
-
*/
|
|
150
|
-
export const greaterThanZero = makeChainable<number>(
|
|
151
|
-
(props, propName, componentName) => {
|
|
152
|
-
const value = props[propName];
|
|
153
|
-
if (typeof value !== "number" || value <= 0) {
|
|
154
|
-
return new Error(
|
|
155
|
-
`\`${propName}\` in \`${componentName}\` must be a number greater than zero.`,
|
|
156
|
-
);
|
|
157
|
-
}
|
|
158
|
-
return null;
|
|
159
|
-
},
|
|
160
|
-
);
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Check that the value is an Array of two unique values.
|
|
164
|
-
*/
|
|
165
|
-
export const domain = makeChainable<[number, number]>(
|
|
166
|
-
(props, propName, componentName) => {
|
|
167
|
-
const value = props[propName];
|
|
168
|
-
if (!Array.isArray(value) || value.length !== 2 || value[1] === value[0]) {
|
|
169
|
-
return new Error(
|
|
170
|
-
`\`${propName}\` in \`${componentName}\` must be an array of two unique numeric values.`,
|
|
171
|
-
);
|
|
172
|
-
}
|
|
173
|
-
return null;
|
|
174
|
-
},
|
|
175
|
-
);
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Check that the value looks like a d3 `scale` function.
|
|
179
|
-
*/
|
|
180
|
-
export const scale = makeChainable<ScaleName | D3Scale>(
|
|
181
|
-
(props, propName, componentName) => {
|
|
182
|
-
const value = props[propName];
|
|
183
|
-
if (!Scale.validScale(value)) {
|
|
184
|
-
return new Error(
|
|
185
|
-
`\`${propName}\` in \`${componentName}\` must be a d3 scale.`,
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
return null;
|
|
189
|
-
},
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Check that an array contains items of the same type.
|
|
194
|
-
*/
|
|
195
|
-
export const homogeneousArray = makeChainable<unknown[]>(
|
|
196
|
-
(props, propName, componentName) => {
|
|
197
|
-
const values = props[propName];
|
|
198
|
-
if (!Array.isArray(values)) {
|
|
199
|
-
return new Error(
|
|
200
|
-
`\`${propName}\` in \`${componentName}\` must be an array.`,
|
|
201
|
-
);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (values.length < 2) {
|
|
205
|
-
return null;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const comparisonConstructor = getConstructor(values[0]);
|
|
209
|
-
|
|
210
|
-
const typeMismatchedValue = find(values, (value) => {
|
|
211
|
-
return comparisonConstructor !== getConstructor(value);
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
if (typeMismatchedValue) {
|
|
215
|
-
const constructorName = getConstructorName(values[0]);
|
|
216
|
-
const otherConstructorName = getConstructorName(typeMismatchedValue);
|
|
217
|
-
|
|
218
|
-
return new Error(
|
|
219
|
-
`Expected \`${propName}\` in \`${componentName}\` to be a ` +
|
|
220
|
-
`homogeneous array, but found types \`${constructorName}\` and ` +
|
|
221
|
-
`\`${otherConstructorName}\`.`,
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
return null;
|
|
225
|
-
},
|
|
226
|
-
);
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Check that array prop length matches props.data.length
|
|
230
|
-
*/
|
|
231
|
-
export const matchDataLength = makeChainable<unknown[]>((props, propName) => {
|
|
232
|
-
if (
|
|
233
|
-
props[propName] &&
|
|
234
|
-
Array.isArray(props[propName]) &&
|
|
235
|
-
props[propName].length !== props.data.length
|
|
236
|
-
) {
|
|
237
|
-
return new Error(`Length of data and ${propName} arrays must match.`);
|
|
238
|
-
}
|
|
239
|
-
return null;
|
|
240
|
-
});
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Check that the value is a regular expression
|
|
244
|
-
*/
|
|
245
|
-
export const regExp = makeChainable<RegExp>(
|
|
246
|
-
(props, propName, componentName) => {
|
|
247
|
-
if (props[propName] && !isRegExp(props[propName])) {
|
|
248
|
-
return new Error(
|
|
249
|
-
`\`${propName}\` in \`${componentName}\` must be a regular expression.`,
|
|
250
|
-
);
|
|
251
|
-
}
|
|
252
|
-
return null;
|
|
253
|
-
},
|
|
254
|
-
);
|