@elliemae/ds-props-helpers 2.3.0-alpha.6 → 2.3.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/defaultProps/index.js +9 -0
- package/cjs/defaultProps/useMemoMergePropsWithDefault.js +48 -0
- package/cjs/getProps/index.js +20 -0
- package/cjs/globalProps/constants.js +15 -0
- package/cjs/globalProps/globalAttributesPropTypes.js +382 -0
- package/cjs/globalProps/index.js +11 -0
- package/cjs/globalProps/useGetGlobalAttributes.js +36 -0
- package/cjs/index.js +28 -0
- package/cjs/propTypes/PropTypes.js +130 -0
- package/cjs/propTypes/customPropTypes.js +21 -0
- package/cjs/propTypes/describe.js +64 -0
- package/cjs/propTypes/describeConversions.js +104 -0
- package/cjs/propTypes/describeGuards.js +21 -0
- package/cjs/propTypes/index.js +11 -0
- package/cjs/propTypes/toTypescript.js +160 -0
- package/cjs/propTypes/types.js +2 -0
- package/cjs/validation/errorTemplates.js +16 -0
- package/cjs/validation/index.js +15 -0
- package/cjs/validation/typescriptGuards.js +36 -0
- package/cjs/validation/typescriptParsers.js +45 -0
- package/cjs/validation/typescriptValidator.js +208 -0
- package/cjs/validation/validator.js +36 -0
- package/esm/defaultProps/index.js +1 -0
- package/esm/defaultProps/useMemoMergePropsWithDefault.js +39 -0
- package/esm/getProps/index.js +15 -0
- package/esm/globalProps/constants.js +11 -0
- package/{dist/esm → esm}/globalProps/globalAttributesPropTypes.js +67 -58
- package/esm/globalProps/index.js +2 -0
- package/esm/globalProps/useGetGlobalAttributes.js +32 -0
- package/esm/index.js +9 -0
- package/esm/propTypes/PropTypes.js +124 -0
- package/esm/propTypes/customPropTypes.js +17 -0
- package/esm/propTypes/describe.js +62 -0
- package/esm/propTypes/describeConversions.js +96 -0
- package/esm/propTypes/describeGuards.js +10 -0
- package/esm/propTypes/index.js +2 -0
- package/esm/propTypes/toTypescript.js +154 -0
- package/esm/propTypes/types.js +1 -0
- package/esm/validation/errorTemplates.js +11 -0
- package/esm/validation/index.js +3 -0
- package/esm/validation/typescriptGuards.js +23 -0
- package/esm/validation/typescriptParsers.js +41 -0
- package/esm/validation/typescriptValidator.js +203 -0
- package/esm/validation/validator.js +32 -0
- package/package.json +63 -65
- package/types/defaultProps/index.d.ts +1 -0
- package/types/defaultProps/useMemoMergePropsWithDefault.d.ts +1 -0
- package/types/getProps/index.d.ts +2 -0
- package/types/globalProps/constants.d.ts +3 -0
- package/types/globalProps/globalAttributesPropTypes.d.ts +363 -0
- package/types/globalProps/index.d.ts +2 -0
- package/types/globalProps/useGetGlobalAttributes.d.ts +5 -0
- package/types/index.d.ts +5 -0
- package/types/propTypes/PropTypes.d.ts +3 -0
- package/types/propTypes/customPropTypes.d.ts +2 -0
- package/types/propTypes/describe.d.ts +3 -0
- package/types/propTypes/describeConversions.d.ts +3 -0
- package/types/propTypes/describeGuards.d.ts +9 -0
- package/types/propTypes/index.d.ts +3 -0
- package/types/propTypes/toTypescript.d.ts +3 -0
- package/types/propTypes/types.d.ts +96 -0
- package/types/tests/globalProps/TestComponent.d.ts +1 -0
- package/types/tests/globalProps/globalAttributes.test.d.ts +1 -0
- package/types/tests/validation/any.validation.test.d.ts +1 -0
- package/types/tests/validation/array.validation.test.d.ts +1 -0
- package/types/tests/validation/boolean.validation.test.d.ts +1 -0
- package/types/tests/validation/function.validation.test.d.ts +1 -0
- package/types/tests/validation/number.validation.test.d.ts +1 -0
- package/types/tests/validation/object.validation.test.d.ts +1 -0
- package/types/tests/validation/schema.validation.test.d.ts +1 -0
- package/types/tests/validation/string.validation.test.d.ts +1 -0
- package/types/tests/validation/test.schema.d.ts +1 -0
- package/types/tests/validation/union.validation.test.d.ts +1 -0
- package/types/validation/errorTemplates.d.ts +2 -0
- package/types/validation/index.d.ts +3 -0
- package/types/validation/typescriptGuards.d.ts +12 -0
- package/types/validation/typescriptParsers.d.ts +1 -0
- package/types/validation/typescriptValidator.d.ts +15 -0
- package/types/validation/validator.d.ts +1 -0
- package/dist/cjs/defaultProps/index.js +0 -28
- package/dist/cjs/defaultProps/index.js.map +0 -7
- package/dist/cjs/defaultProps/useMemoMergePropsWithDefault.js +0 -48
- package/dist/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +0 -7
- package/dist/cjs/getProps/index.js +0 -37
- package/dist/cjs/getProps/index.js.map +0 -7
- package/dist/cjs/globalProps/constants.js +0 -398
- package/dist/cjs/globalProps/constants.js.map +0 -7
- package/dist/cjs/globalProps/globalAttributesPropTypes.js +0 -398
- package/dist/cjs/globalProps/globalAttributesPropTypes.js.map +0 -7
- package/dist/cjs/globalProps/index.js +0 -29
- package/dist/cjs/globalProps/index.js.map +0 -7
- package/dist/cjs/globalProps/useGetGlobalAttributes.js +0 -56
- package/dist/cjs/globalProps/useGetGlobalAttributes.js.map +0 -7
- package/dist/cjs/index.js +0 -32
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/propTypes/PropTypes.js +0 -136
- package/dist/cjs/propTypes/PropTypes.js.map +0 -7
- package/dist/cjs/propTypes/customPropTypes.js +0 -38
- package/dist/cjs/propTypes/customPropTypes.js.map +0 -7
- package/dist/cjs/propTypes/describe.js +0 -81
- package/dist/cjs/propTypes/describe.js.map +0 -7
- package/dist/cjs/propTypes/describeConversions.js +0 -96
- package/dist/cjs/propTypes/describeConversions.js.map +0 -7
- package/dist/cjs/propTypes/describeGuards.js +0 -49
- package/dist/cjs/propTypes/describeGuards.js.map +0 -7
- package/dist/cjs/propTypes/index.js +0 -37
- package/dist/cjs/propTypes/index.js.map +0 -7
- package/dist/cjs/propTypes/toTypescript.js +0 -139
- package/dist/cjs/propTypes/toTypescript.js.map +0 -7
- package/dist/cjs/propTypes/types.js +0 -27
- package/dist/cjs/propTypes/types.js.map +0 -7
- package/dist/cjs/tests/globalProps/TestComponent.js +0 -42
- package/dist/cjs/tests/globalProps/TestComponent.js.map +0 -7
- package/dist/cjs/tests/validation/test.schema.js +0 -67
- package/dist/cjs/tests/validation/test.schema.js.map +0 -7
- package/dist/cjs/validation/errorTemplates.js +0 -48
- package/dist/cjs/validation/errorTemplates.js.map +0 -7
- package/dist/cjs/validation/index.js +0 -30
- package/dist/cjs/validation/index.js.map +0 -7
- package/dist/cjs/validation/typescriptGuards.js +0 -65
- package/dist/cjs/validation/typescriptGuards.js.map +0 -7
- package/dist/cjs/validation/typescriptParsers.js +0 -76
- package/dist/cjs/validation/typescriptParsers.js.map +0 -7
- package/dist/cjs/validation/typescriptValidator.js +0 -171
- package/dist/cjs/validation/typescriptValidator.js.map +0 -7
- package/dist/cjs/validation/validator.js +0 -55
- package/dist/cjs/validation/validator.js.map +0 -7
- package/dist/esm/defaultProps/index.js +0 -3
- package/dist/esm/defaultProps/index.js.map +0 -7
- package/dist/esm/defaultProps/useMemoMergePropsWithDefault.js +0 -19
- package/dist/esm/defaultProps/useMemoMergePropsWithDefault.js.map +0 -7
- package/dist/esm/getProps/index.js +0 -8
- package/dist/esm/getProps/index.js.map +0 -7
- package/dist/esm/globalProps/constants.js +0 -369
- package/dist/esm/globalProps/constants.js.map +0 -7
- package/dist/esm/globalProps/globalAttributesPropTypes.js.map +0 -7
- package/dist/esm/globalProps/index.js +0 -4
- package/dist/esm/globalProps/index.js.map +0 -7
- package/dist/esm/globalProps/useGetGlobalAttributes.js +0 -27
- package/dist/esm/globalProps/useGetGlobalAttributes.js.map +0 -7
- package/dist/esm/index.js +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/propTypes/PropTypes.js +0 -107
- package/dist/esm/propTypes/PropTypes.js.map +0 -7
- package/dist/esm/propTypes/customPropTypes.js +0 -9
- package/dist/esm/propTypes/customPropTypes.js.map +0 -7
- package/dist/esm/propTypes/describe.js +0 -52
- package/dist/esm/propTypes/describe.js.map +0 -7
- package/dist/esm/propTypes/describeConversions.js +0 -76
- package/dist/esm/propTypes/describeConversions.js.map +0 -7
- package/dist/esm/propTypes/describeGuards.js +0 -20
- package/dist/esm/propTypes/describeGuards.js.map +0 -7
- package/dist/esm/propTypes/index.js +0 -8
- package/dist/esm/propTypes/index.js.map +0 -7
- package/dist/esm/propTypes/toTypescript.js +0 -110
- package/dist/esm/propTypes/toTypescript.js.map +0 -7
- package/dist/esm/propTypes/types.js +0 -2
- package/dist/esm/propTypes/types.js.map +0 -7
- package/dist/esm/tests/globalProps/TestComponent.js +0 -13
- package/dist/esm/tests/globalProps/TestComponent.js.map +0 -7
- package/dist/esm/tests/validation/test.schema.js +0 -38
- package/dist/esm/tests/validation/test.schema.js.map +0 -7
- package/dist/esm/validation/errorTemplates.js +0 -19
- package/dist/esm/validation/errorTemplates.js.map +0 -7
- package/dist/esm/validation/index.js +0 -5
- package/dist/esm/validation/index.js.map +0 -7
- package/dist/esm/validation/typescriptGuards.js +0 -36
- package/dist/esm/validation/typescriptGuards.js.map +0 -7
- package/dist/esm/validation/typescriptParsers.js +0 -47
- package/dist/esm/validation/typescriptParsers.js.map +0 -7
- package/dist/esm/validation/typescriptValidator.js +0 -153
- package/dist/esm/validation/typescriptValidator.js.map +0 -7
- package/dist/esm/validation/validator.js +0 -26
- package/dist/esm/validation/validator.js.map +0 -7
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
9
|
+
var react = require('react');
|
|
10
|
+
require('../propTypes/PropTypes.js');
|
|
11
|
+
var describe = require('../propTypes/describe.js');
|
|
12
|
+
var errorTemplates = require('./errorTemplates.js');
|
|
13
|
+
var typescriptGuards = require('./typescriptGuards.js');
|
|
14
|
+
var typescriptParsers = require('./typescriptParsers.js');
|
|
15
|
+
|
|
16
|
+
// =============================================================================
|
|
17
|
+
// Atom Validators
|
|
18
|
+
// =============================================================================
|
|
19
|
+
// This functions will validate something from the data
|
|
20
|
+
// and optionally recursively apply `validateValueWithFormat`
|
|
21
|
+
// in smaller parts
|
|
22
|
+
const validateUndefined = (schemaName, key, value, format) => {
|
|
23
|
+
if (value !== undefined || value === 'undefined') {
|
|
24
|
+
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const validateNull = (schemaName, key, value, format) => {
|
|
29
|
+
if (value !== null || value === 'null') {
|
|
30
|
+
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const validatePrimitiveType = (schemaName, key, value, format) => {
|
|
35
|
+
if (typeof value !== format) {
|
|
36
|
+
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const validateString = (schemaName, key, value, format) => {
|
|
41
|
+
if (value !== format.slice(1, -1)) {
|
|
42
|
+
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const validateArray = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
47
|
+
// Check that we have an array
|
|
48
|
+
if (!Array.isArray(value)) {
|
|
49
|
+
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
50
|
+
} // Check that each element inside satisfies the format
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
value.forEach((val, index) => {
|
|
54
|
+
// this is a recursive func, we need to invoke it before it's defined.
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
56
|
+
validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function isObjectType(value) {
|
|
61
|
+
return !(typeof value !== 'object' || Array.isArray(value));
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const validateObject = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
65
|
+
const valuesIsObject = isObjectType(value); // Check that we have an object
|
|
66
|
+
|
|
67
|
+
if (!valuesIsObject) {
|
|
68
|
+
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (format === 'object') return;
|
|
73
|
+
const keyValuePairs = typescriptParsers.typescriptObjectParser(format); // Now we have the key - value pairs
|
|
74
|
+
// Each key could either be required or not
|
|
75
|
+
// Just recursively check the object
|
|
76
|
+
|
|
77
|
+
keyValuePairs.forEach(_ref => {
|
|
78
|
+
let [objectKey, objectValue] = _ref;
|
|
79
|
+
const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
|
|
80
|
+
|
|
81
|
+
if (trueKey === objectKey && !(trueKey in value)) {
|
|
82
|
+
errorTemplates.throwRequiredError(schemaName, key);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (trueKey in value) {
|
|
86
|
+
// this is a recursive func, we need to invoke it before it's defined.
|
|
87
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
88
|
+
validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const validateUnion = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
94
|
+
const possibilities = format.split(/\s?\|\s?/);
|
|
95
|
+
const errors = [];
|
|
96
|
+
possibilities.forEach(possibility => {
|
|
97
|
+
try {
|
|
98
|
+
// this is a recursive func, we need to invoke it before it's defined.
|
|
99
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
100
|
+
validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);
|
|
101
|
+
} catch (e) {
|
|
102
|
+
errors.push(e);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (errors.length === possibilities.length) {
|
|
107
|
+
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const validateFunction = (schemaName, key, value, format) => {
|
|
112
|
+
// Check that we have a function
|
|
113
|
+
if (typeof value !== 'function') {
|
|
114
|
+
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
function isJSXElement(value) {
|
|
119
|
+
return value === null || typeof value === 'object' && value !== null && '$$typeof' in value;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
const validateJSXorNode = (schemaName, key, value, format) => {
|
|
123
|
+
const valueIsJSX = isJSXElement(value);
|
|
124
|
+
|
|
125
|
+
if (format === 'JSX.Element' && !valueIsJSX) {
|
|
126
|
+
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
127
|
+
}
|
|
128
|
+
}; // =============================================================================
|
|
129
|
+
// Schema validator
|
|
130
|
+
// =============================================================================
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
const validateValueWithFormat = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
134
|
+
nextValidationsMemo[value] = format;
|
|
135
|
+
|
|
136
|
+
if (value in validationsMemo) {
|
|
137
|
+
// We already validated this value on this format
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (typescriptGuards.isUndefined(format)) {
|
|
142
|
+
validateUndefined(schemaName, key, value, format);
|
|
143
|
+
} else if (typescriptGuards.isNull(format)) {
|
|
144
|
+
validateNull(schemaName, key, value, format);
|
|
145
|
+
} else if (typescriptGuards.isPrimitiveType(format)) {
|
|
146
|
+
validatePrimitiveType(schemaName, key, value, format);
|
|
147
|
+
} else if (typescriptGuards.isUnion(format)) {
|
|
148
|
+
validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
149
|
+
} else if (typescriptGuards.isString(format)) {
|
|
150
|
+
validateString(schemaName, key, value, format);
|
|
151
|
+
} else if (typescriptGuards.isArray(format)) {
|
|
152
|
+
validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
153
|
+
} else if (typescriptGuards.isObject(format)) {
|
|
154
|
+
validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
155
|
+
} else if (typescriptGuards.isFunction(format)) {
|
|
156
|
+
validateFunction(schemaName, key, value, format);
|
|
157
|
+
} else if (typescriptGuards.isJSXorNode(format)) {
|
|
158
|
+
validateJSXorNode(schemaName, key, value, format);
|
|
159
|
+
} else if (typescriptGuards.isSomethingWithParenthesis(format)) {
|
|
160
|
+
validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
const validateTypescriptPropTypesImplementation = function (props, schema) {
|
|
165
|
+
let validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
166
|
+
let nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
167
|
+
const {
|
|
168
|
+
properties,
|
|
169
|
+
name: schemaName
|
|
170
|
+
} = schema;
|
|
171
|
+
properties.forEach(property => {
|
|
172
|
+
const {
|
|
173
|
+
name,
|
|
174
|
+
format,
|
|
175
|
+
required
|
|
176
|
+
} = property;
|
|
177
|
+
|
|
178
|
+
if (required && !(name in props)) {
|
|
179
|
+
errorTemplates.throwRequiredError(schema.name, name);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (name in props && (props[name] !== undefined || required)) {
|
|
183
|
+
validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
187
|
+
|
|
188
|
+
const useValidateTypescriptPropTypes = (props, propTypes) => {
|
|
189
|
+
const [validationsMemo, setValidationsMemo] = react.useState({}); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
190
|
+
|
|
191
|
+
const ComponentWithSchema = react.useMemo(() => {
|
|
192
|
+
const Component = () => {}; // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
return describe(Component);
|
|
196
|
+
}, []); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
197
|
+
|
|
198
|
+
ComponentWithSchema.propTypes = propTypes;
|
|
199
|
+
react.useMemo(() => {
|
|
200
|
+
const nextValidationsMemo = {};
|
|
201
|
+
validateTypescriptPropTypesImplementation(props, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
202
|
+
ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
|
|
203
|
+
setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
204
|
+
}, [props]);
|
|
205
|
+
};
|
|
206
|
+
|
|
207
|
+
exports.useValidateTypescriptPropTypes = useValidateTypescriptPropTypes;
|
|
208
|
+
exports.validateTypescriptPropTypesImplementation = validateTypescriptPropTypesImplementation;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
var errorTemplates = require('./errorTemplates.js');
|
|
9
|
+
|
|
10
|
+
const useValidatePropTypes = (props, schema) => {
|
|
11
|
+
schema.properties.forEach(property => {
|
|
12
|
+
const propertyName = property.name;
|
|
13
|
+
const currentProp = props[propertyName];
|
|
14
|
+
const currentPropTypeOf = typeof currentProp; // eslint-disable-next-line max-len
|
|
15
|
+
|
|
16
|
+
const currentFormat = property.format; // this is csv representing types e.g.: "string"/"string,number"/"[object],string"
|
|
17
|
+
|
|
18
|
+
let isValidReactElement = false; // this depends on react desc definition
|
|
19
|
+
|
|
20
|
+
if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {
|
|
21
|
+
errorTemplates.throwRequiredError(schema.name, property.name);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (currentPropTypeOf !== 'undefined' && currentProp !== null) {
|
|
25
|
+
if (currentPropTypeOf === 'object' && Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') && (currentFormat.includes('node') || currentFormat.includes('element'))) {
|
|
26
|
+
isValidReactElement = true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {
|
|
30
|
+
errorTemplates.throwTypeError(schema.name, propertyName, currentProp, currentFormat);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
exports.useValidatePropTypes = useValidatePropTypes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { useMemoMergePropsWithDefault } from './useMemoMergePropsWithDefault.js';
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
6
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
7
|
+
import { useRef } from 'react';
|
|
8
|
+
import deepequal from 'fast-deep-equal/react';
|
|
9
|
+
|
|
10
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
11
|
+
|
|
12
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
13
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
14
|
+
|
|
15
|
+
const useMemoCompare = (next, compare) => {
|
|
16
|
+
// Ref for storing previous value
|
|
17
|
+
const previousRef = useRef(next);
|
|
18
|
+
const previous = previousRef.current; // Pass previous and next value to compare function
|
|
19
|
+
// to determine whether to consider them equal.
|
|
20
|
+
|
|
21
|
+
const isEqual = compare(previous, next); // If not equal update previousRef to next value.
|
|
22
|
+
// We only update if not equal so that this hook continues to return
|
|
23
|
+
// the same old value if compare keeps returning true.
|
|
24
|
+
|
|
25
|
+
if (!isEqual) previousRef.current = next; // Finally, if equal then return the previous value
|
|
26
|
+
|
|
27
|
+
return isEqual ? previous : next;
|
|
28
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
const useMemoMergePropsWithDefault = function (props, defaultProps) {
|
|
32
|
+
let compare = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : deepequal;
|
|
33
|
+
|
|
34
|
+
const mergedProps = _objectSpread(_objectSpread({}, defaultProps), props);
|
|
35
|
+
|
|
36
|
+
return useMemoCompare(mergedProps, compare);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { useMemoMergePropsWithDefault };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
4
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
5
|
+
|
|
6
|
+
const getAriaProps = props => Object.fromEntries(Object.entries(props).filter(_ref => {
|
|
7
|
+
let [key] = _ref;
|
|
8
|
+
return key.includes('aria-');
|
|
9
|
+
}));
|
|
10
|
+
const getDataProps = props => Object.fromEntries(Object.entries(props).filter(_ref2 => {
|
|
11
|
+
let [key] = _ref2;
|
|
12
|
+
return key.includes('data-');
|
|
13
|
+
}));
|
|
14
|
+
|
|
15
|
+
export { getAriaProps, getDataProps };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.map.js';
|
|
3
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
4
|
+
|
|
5
|
+
/* eslint-disable max-lines */
|
|
6
|
+
const ariaAttributes = ['aria-activedescendant', 'aria-atomic', 'aria-autocomplete', 'aria-busy', 'aria-checked', 'aria-colcount', 'aria-colindex', 'aria-colspan', 'aria-controls', 'aria-current', 'aria-describedby', 'aria-details', 'aria-disabled', 'aria-dropeffect', 'aria-errormessage', 'aria-expanded', 'aria-flowto', 'aria-grabbed', 'aria-haspopup', 'aria-hidden', 'aria-invalid', 'aria-keyshortcuts', 'aria-label', 'aria-labelledby', 'aria-level', 'aria-live', 'aria-modal', 'aria-multiline', 'aria-multiselectable', 'aria-orientation', 'aria-owns', 'aria-placeholder', 'aria-posinset', 'aria-pressed', 'aria-readonly', 'aria-relevant', 'aria-required', 'aria-roledescription', 'aria-rowcount', 'aria-rowindex', 'aria-rowspan', 'aria-selected', 'aria-setsize', 'aria-sort', 'aria-valuemax', 'aria-valuemin', 'aria-valuenow', 'aria-valuetext'];
|
|
7
|
+
const domAttributes = ['onCopy', 'onCopyCapture', 'onCut', 'onCutCapture', 'onPaste', 'onPasteCapture', 'onCompositionEnd', 'onCompositionEndCapture', 'onCompositionStart', 'onCompositionStartCapture', 'onCompositionUpdate', 'onCompositionUpdateCapture', 'onFocus', 'onFocusCapture', 'onBlur', 'onBlurCapture', 'onChange', 'onChangeCapture', 'onBeforeInput', 'onBeforeInputCapture', 'onInput', 'onInputCapture', 'onReset', 'onResetCapture', 'onSubmit', 'onSubmitCapture', 'onInvalid', 'onInvalidCapture', 'onLoad', 'onLoadCapture', 'onError', 'onErrorCapture', 'onKeyDown', 'onKeyDownCapture', 'onKeyPress', 'onKeyPressCapture', 'onKeyUp', 'onKeyUpCapture', 'onAbort', 'onAbortCapture', 'onCanPlay', 'onCanPlayCapture', 'onCanPlayThrough', 'onCanPlayThroughCapture', 'onDurationChange', 'onDurationChangeCapture', 'onEmptied', 'onEmptiedCapture', 'onEncrypted', 'onEncryptedCapture', 'onEnded', 'onEndedCapture', 'onLoadedData', 'onLoadedDataCapture', 'onLoadedMetadata', 'onLoadedMetadataCapture', 'onLoadStart', 'onLoadStartCapture', 'onPause', 'onPauseCapture', 'onPlay', 'onPlayCapture', 'onPlaying', 'onPlayingCapture', 'onProgress', 'onProgressCapture', 'onRateChange', 'onRateChangeCapture', 'onSeeked', 'onSeekedCapture', 'onSeeking', 'onSeekingCapture', 'onStalled', 'onStalledCapture', 'onSuspend', 'onSuspendCapture', 'onTimeUpdate', 'onTimeUpdateCapture', 'onVolumeChange', 'onVolumeChangeCapture', 'onWaiting', 'onWaitingCapture', 'onAuxClick', 'onAuxClickCapture', 'onClick', 'onClickCapture', 'onContextMenu', 'onContextMenuCapture', 'onDoubleClick', 'onDoubleClickCapture', 'onDrag', 'onDragCapture', 'onDragEnd', 'onDragEndCapture', 'onDragEnter', 'onDragEnterCapture', 'onDragExit', 'onDragExitCapture', 'onDragLeave', 'onDragLeaveCapture', 'onDragOver', 'onDragOverCapture', 'onDragStart', 'onDragStartCapture', 'onDrop', 'onDropCapture', 'onMouseDown', 'onMouseDownCapture', 'onMouseEnter', 'onMouseLeave', 'onMouseMove', 'onMouseMoveCapture', 'onMouseOut', 'onMouseOutCapture', 'onMouseOver', 'onMouseOverCapture', 'onMouseUp', 'onMouseUpCapture', 'onSelect', 'onSelectCapture', 'onTouchCancel', 'onTouchCancelCapture', 'onTouchEnd', 'onTouchEndCapture', 'onTouchMove', 'onTouchMoveCapture', 'onTouchStart', 'onTouchStartCapture', 'onPointerDown', 'onPointerDownCapture', 'onPointerMove', 'onPointerMoveCapture', 'onPointerUp', 'onPointerUpCapture', 'onPointerCancel', 'onPointerCancelCapture', 'onPointerEnter', 'onPointerEnterCapture', 'onPointerLeave', 'onPointerLeaveCapture', 'onPointerOver', 'onPointerOverCapture', 'onPointerOut', 'onPointerOutCapture', 'onGotPointerCapture', 'onGotPointerCaptureCapture', 'onLostPointerCapture', 'onLostPointerCaptureCapture', 'onScroll', 'onScrollCapture', 'onWheel', 'onWheelCapture', 'onAnimationStart', 'onAnimationStartCapture', 'onAnimationEnd', 'onAnimationEndCapture', 'onAnimationIteration', 'onAnimationIterationCapture', 'onTransitionEnd', 'onTransitionEndCapture'];
|
|
8
|
+
const htmlAttributes = ['about', 'accept', 'acceptCharset', 'accessKey', 'action', 'allowFullScreen', 'allowTransparency', 'alt', 'as', 'async', 'autoCapitalize', 'autoComplete', 'autoCorrect', 'autoFocus', 'autoPlay', 'autoSave', 'capture', 'cellPadding', 'cellSpacing', 'challenge', 'charSet', 'checked', 'cite', 'classID', 'className', 'color', 'cols', 'colSpan', 'content', 'contentEditable', 'contextMenu', 'controls', 'coords', 'crossOrigin', 'data', 'datatype', 'dateTime', 'default', 'defaultChecked', 'defaultValue', 'defer', 'dir', 'disabled', 'download', 'draggable', 'encType', 'form', 'formAction', 'formEncType', 'formMethod', 'formNoValidate', 'formTarget', 'frameBorder', 'headers', 'height', 'hidden', 'high', 'href', 'hrefLang', 'htmlFor', 'httpEquiv', 'id', 'inlist', 'inputMode', 'integrity', 'is', 'itemID', 'itemProp', 'itemRef', 'itemScope', 'itemType', 'keyParams', 'keyType', 'kind', 'label', 'lang', 'list', 'loop', 'low', 'manifest', 'marginHeight', 'marginWidth', 'max', 'maxLength', 'media', 'mediaGroup', 'method', 'min', 'minLength', 'multiple', 'muted', 'name', 'nonce', 'noValidate', 'open', 'optimum', 'pattern', 'placeholder', 'playsInline', 'poster', 'prefix', 'preload', 'property', 'radioGroup', 'readOnly', 'rel', 'required', 'resource', 'results', 'reversed', 'role', 'rows', 'rowSpan', 'sandbox', 'scope', 'scoped', 'scrolling', 'seamless', 'security', 'selected', 'shape', 'size', 'sizes', 'slot', 'span', 'spellCheck', 'src', 'srcDoc', 'srcLang', 'srcSet', 'start', 'step', 'style', 'summary', 'suppressContentEditableWarning', 'suppressHydrationWarning', 'tabIndex', 'target', 'title', 'translate', 'type', 'typeof', 'unselectable', 'useMap', 'value', 'vocab', 'width', 'wmode', 'wrap'];
|
|
9
|
+
const globalAttributes = Object.fromEntries([...ariaAttributes, ...domAttributes, ...htmlAttributes].map(entry => [entry, true]));
|
|
10
|
+
|
|
11
|
+
export { globalAttributes };
|
|
@@ -1,10 +1,21 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import PropTypes from '../propTypes/PropTypes.js';
|
|
2
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
4
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
6
|
+
import 'core-js/modules/esnext.async-iterator.map.js';
|
|
7
|
+
import 'core-js/modules/esnext.iterator.map.js';
|
|
8
|
+
import 'prop-types';
|
|
9
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
10
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
11
|
+
import '@babel/runtime/helpers/esm/defineProperty';
|
|
12
|
+
|
|
13
|
+
/* eslint-disable max-lines */
|
|
3
14
|
const globalAttributesPropTypes = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
15
|
+
'aria-*': PropTypes.any.description('Aria related properties').global(),
|
|
16
|
+
'on-*': PropTypes.func.description('Any supported React event').global(),
|
|
17
|
+
'data-*': PropTypes.any.description('Any data property to attach to the root container').global(),
|
|
18
|
+
'all HTML attributes': PropTypes.any.description('HTML attributes such as id, className, autoComplete, href and so on').global(),
|
|
8
19
|
about: PropTypes.any.hidden(),
|
|
9
20
|
accept: PropTypes.any.hidden(),
|
|
10
21
|
acceptCharset: PropTypes.any.hidden(),
|
|
@@ -13,54 +24,54 @@ const globalAttributesPropTypes = {
|
|
|
13
24
|
allowFullScreen: PropTypes.any.hidden(),
|
|
14
25
|
allowTransparency: PropTypes.any.hidden(),
|
|
15
26
|
alt: PropTypes.any.hidden(),
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
27
|
+
'aria-activedescendant': PropTypes.any.hidden(),
|
|
28
|
+
'aria-atomic': PropTypes.any.hidden(),
|
|
29
|
+
'aria-autocomplete': PropTypes.any.hidden(),
|
|
30
|
+
'aria-busy': PropTypes.any.hidden(),
|
|
31
|
+
'aria-checked': PropTypes.any.hidden(),
|
|
32
|
+
'aria-colcount': PropTypes.any.hidden(),
|
|
33
|
+
'aria-colindex': PropTypes.any.hidden(),
|
|
34
|
+
'aria-colspan': PropTypes.any.hidden(),
|
|
35
|
+
'aria-controls': PropTypes.any.hidden(),
|
|
36
|
+
'aria-current': PropTypes.any.hidden(),
|
|
37
|
+
'aria-describedby': PropTypes.any.hidden(),
|
|
38
|
+
'aria-details': PropTypes.any.hidden(),
|
|
39
|
+
'aria-disabled': PropTypes.any.hidden(),
|
|
40
|
+
'aria-dropeffect': PropTypes.any.hidden(),
|
|
41
|
+
'aria-errormessage': PropTypes.any.hidden(),
|
|
42
|
+
'aria-expanded': PropTypes.any.hidden(),
|
|
43
|
+
'aria-flowto': PropTypes.any.hidden(),
|
|
44
|
+
'aria-grabbed': PropTypes.any.hidden(),
|
|
45
|
+
'aria-haspopup': PropTypes.any.hidden(),
|
|
46
|
+
'aria-hidden': PropTypes.any.hidden(),
|
|
47
|
+
'aria-invalid': PropTypes.any.hidden(),
|
|
48
|
+
'aria-keyshortcuts': PropTypes.any.hidden(),
|
|
49
|
+
'aria-label': PropTypes.any.hidden(),
|
|
50
|
+
'aria-labelledby': PropTypes.any.hidden(),
|
|
51
|
+
'aria-level': PropTypes.any.hidden(),
|
|
52
|
+
'aria-live': PropTypes.any.hidden(),
|
|
53
|
+
'aria-modal': PropTypes.any.hidden(),
|
|
54
|
+
'aria-multiline': PropTypes.any.hidden(),
|
|
55
|
+
'aria-multiselectable': PropTypes.any.hidden(),
|
|
56
|
+
'aria-orientation': PropTypes.any.hidden(),
|
|
57
|
+
'aria-owns': PropTypes.any.hidden(),
|
|
58
|
+
'aria-placeholder': PropTypes.any.hidden(),
|
|
59
|
+
'aria-posinset': PropTypes.any.hidden(),
|
|
60
|
+
'aria-pressed': PropTypes.any.hidden(),
|
|
61
|
+
'aria-readonly': PropTypes.any.hidden(),
|
|
62
|
+
'aria-relevant': PropTypes.any.hidden(),
|
|
63
|
+
'aria-required': PropTypes.any.hidden(),
|
|
64
|
+
'aria-roledescription': PropTypes.any.hidden(),
|
|
65
|
+
'aria-rowcount': PropTypes.any.hidden(),
|
|
66
|
+
'aria-rowindex': PropTypes.any.hidden(),
|
|
67
|
+
'aria-rowspan': PropTypes.any.hidden(),
|
|
68
|
+
'aria-selected': PropTypes.any.hidden(),
|
|
69
|
+
'aria-setsize': PropTypes.any.hidden(),
|
|
70
|
+
'aria-sort': PropTypes.any.hidden(),
|
|
71
|
+
'aria-valuemax': PropTypes.any.hidden(),
|
|
72
|
+
'aria-valuemin': PropTypes.any.hidden(),
|
|
73
|
+
'aria-valuenow': PropTypes.any.hidden(),
|
|
74
|
+
'aria-valuetext': PropTypes.any.hidden(),
|
|
64
75
|
as: PropTypes.any.hidden(),
|
|
65
76
|
async: PropTypes.any.hidden(),
|
|
66
77
|
autoCapitalize: PropTypes.any.hidden(),
|
|
@@ -363,7 +374,5 @@ const globalAttributesPropTypes = {
|
|
|
363
374
|
wmode: PropTypes.any.hidden(),
|
|
364
375
|
wrap: PropTypes.any.hidden()
|
|
365
376
|
};
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
};
|
|
369
|
-
//# sourceMappingURL=globalAttributesPropTypes.js.map
|
|
377
|
+
|
|
378
|
+
export { globalAttributesPropTypes };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
4
|
+
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
import { globalAttributes } from './constants.js';
|
|
7
|
+
|
|
8
|
+
const useGetGlobalAttributes = (props, overrides) => {
|
|
9
|
+
const componentGlobalAttributes = useMemo(() => {
|
|
10
|
+
const globalAttributesObject = {};
|
|
11
|
+
Object.entries(props).forEach(_ref => {
|
|
12
|
+
let [key, value] = _ref;
|
|
13
|
+
|
|
14
|
+
if (key in globalAttributes || key.startsWith('data-')) {
|
|
15
|
+
if (overrides && key in overrides && typeof value === 'function' && typeof overrides[key] === 'function') {
|
|
16
|
+
const newFunc = function () {
|
|
17
|
+
value(...arguments);
|
|
18
|
+
overrides[key](...arguments);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
globalAttributesObject[key] = newFunc;
|
|
22
|
+
} else {
|
|
23
|
+
globalAttributesObject[key] = value;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return globalAttributesObject;
|
|
28
|
+
}, [props, overrides]);
|
|
29
|
+
return componentGlobalAttributes;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export { useGetGlobalAttributes };
|
package/esm/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { useMemoMergePropsWithDefault } from './defaultProps/useMemoMergePropsWithDefault.js';
|
|
2
|
+
export { useValidatePropTypes } from './validation/validator.js';
|
|
3
|
+
export { throwRequiredError, throwTypeError } from './validation/errorTemplates.js';
|
|
4
|
+
export { useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation } from './validation/typescriptValidator.js';
|
|
5
|
+
export { getAriaProps, getDataProps } from './getProps/index.js';
|
|
6
|
+
export { useGetGlobalAttributes } from './globalProps/useGetGlobalAttributes.js';
|
|
7
|
+
export { globalAttributesPropTypes } from './globalProps/globalAttributesPropTypes.js';
|
|
8
|
+
export { default as PropTypes } from './propTypes/PropTypes.js';
|
|
9
|
+
export { default as describe } from './propTypes/describe.js';
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import 'core-js/modules/esnext.async-iterator.filter.js';
|
|
2
|
+
import 'core-js/modules/esnext.iterator.filter.js';
|
|
3
|
+
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
4
|
+
import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
5
|
+
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
6
|
+
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
7
|
+
|
|
8
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
9
|
+
|
|
10
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
11
|
+
|
|
12
|
+
const addPropTypeDocumentationField = fieldName => function addFieldToReactDesc(value) {
|
|
13
|
+
if (!this.reactDesc) {
|
|
14
|
+
this.reactDesc = {};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
let realValue = value;
|
|
18
|
+
if (fieldName === 'global' || fieldName === 'hidden') realValue = true;
|
|
19
|
+
this.reactDesc[fieldName] = realValue;
|
|
20
|
+
return this;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const documentedPropType = {
|
|
24
|
+
defaultValue: addPropTypeDocumentationField('defaultValue'),
|
|
25
|
+
description: addPropTypeDocumentationField('description'),
|
|
26
|
+
deprecated: addPropTypeDocumentationField('deprecated'),
|
|
27
|
+
format: addPropTypeDocumentationField('format'),
|
|
28
|
+
global: addPropTypeDocumentationField('global'),
|
|
29
|
+
hidden: addPropTypeDocumentationField('hidden')
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const createPropType = type => {
|
|
33
|
+
const propTypeObj = _objectSpread({
|
|
34
|
+
type
|
|
35
|
+
}, documentedPropType);
|
|
36
|
+
|
|
37
|
+
Object.defineProperty(propTypeObj, 'isRequired', {
|
|
38
|
+
get: function getRequired() {
|
|
39
|
+
if (!this.reactDesc) {
|
|
40
|
+
this.reactDesc = {};
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
this.reactDesc.required = true;
|
|
44
|
+
return this;
|
|
45
|
+
},
|
|
46
|
+
enumerable: true,
|
|
47
|
+
configurable: true
|
|
48
|
+
});
|
|
49
|
+
return propTypeObj;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const createPropTypeWithArgs = type => args => {
|
|
53
|
+
const propTypeObj = _objectSpread({
|
|
54
|
+
args,
|
|
55
|
+
type
|
|
56
|
+
}, documentedPropType);
|
|
57
|
+
|
|
58
|
+
Object.defineProperty(propTypeObj, 'isRequired', {
|
|
59
|
+
get: function getRequired() {
|
|
60
|
+
if (!this.reactDesc) {
|
|
61
|
+
this.reactDesc = {};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
this.reactDesc.required = true;
|
|
65
|
+
return this;
|
|
66
|
+
},
|
|
67
|
+
enumerable: true,
|
|
68
|
+
configurable: true
|
|
69
|
+
});
|
|
70
|
+
return propTypeObj;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const PropTypes = {
|
|
74
|
+
custom: callback => {
|
|
75
|
+
const target = callback.bind(null);
|
|
76
|
+
target.type = 'func';
|
|
77
|
+
Object.keys(documentedPropType).forEach(fieldName => {
|
|
78
|
+
const fieldNameCasted = fieldName; // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
79
|
+
|
|
80
|
+
target[fieldNameCasted] = documentedPropType[fieldNameCasted];
|
|
81
|
+
});
|
|
82
|
+
return target;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
function definePropType(type) {
|
|
87
|
+
Object.defineProperty(PropTypes, type, {
|
|
88
|
+
get: function getPropType() {
|
|
89
|
+
return createPropType(type);
|
|
90
|
+
},
|
|
91
|
+
enumerable: true,
|
|
92
|
+
configurable: true
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function definePropTypeWithArgs(type) {
|
|
97
|
+
Object.defineProperty(PropTypes, type, {
|
|
98
|
+
get: function getPropType() {
|
|
99
|
+
return createPropTypeWithArgs(type);
|
|
100
|
+
},
|
|
101
|
+
enumerable: true,
|
|
102
|
+
configurable: true
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
definePropType('any');
|
|
107
|
+
definePropType('array');
|
|
108
|
+
definePropType('bool');
|
|
109
|
+
definePropType('element');
|
|
110
|
+
definePropType('func');
|
|
111
|
+
definePropType('node');
|
|
112
|
+
definePropType('number');
|
|
113
|
+
definePropType('object');
|
|
114
|
+
definePropType('symbol');
|
|
115
|
+
definePropType('string');
|
|
116
|
+
definePropTypeWithArgs('arrayOf');
|
|
117
|
+
definePropTypeWithArgs('instanceOf');
|
|
118
|
+
definePropTypeWithArgs('objectOf');
|
|
119
|
+
definePropTypeWithArgs('oneOfType');
|
|
120
|
+
definePropTypeWithArgs('oneOf');
|
|
121
|
+
definePropTypeWithArgs('shape');
|
|
122
|
+
definePropTypeWithArgs('tuple');
|
|
123
|
+
|
|
124
|
+
export { PropTypes as default };
|