@elliemae/ds-props-helpers 3.0.0-next.2 → 3.0.0-next.3
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/dist/cjs/defaultProps/index.js +28 -0
- package/dist/cjs/defaultProps/index.js.map +7 -0
- package/dist/cjs/defaultProps/useMemoMergePropsWithDefault.js +62 -0
- package/dist/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +7 -0
- package/dist/cjs/getProps/index.js +37 -0
- package/dist/cjs/getProps/index.js.map +7 -0
- package/dist/cjs/globalProps/constants.js +397 -0
- package/dist/cjs/globalProps/constants.js.map +7 -0
- package/dist/cjs/globalProps/globalAttributesPropTypes.js +398 -0
- package/dist/cjs/globalProps/globalAttributesPropTypes.js.map +7 -0
- package/dist/cjs/globalProps/index.js +29 -0
- package/dist/cjs/globalProps/index.js.map +7 -0
- package/dist/cjs/globalProps/useGetGlobalAttributes.js +56 -0
- package/dist/cjs/globalProps/useGetGlobalAttributes.js.map +7 -0
- package/dist/cjs/index.js +34 -0
- package/dist/cjs/index.js.map +7 -0
- package/dist/cjs/propTypes/PropTypes.js +149 -0
- package/dist/cjs/propTypes/PropTypes.js.map +7 -0
- package/dist/cjs/propTypes/customPropTypes.js +38 -0
- package/dist/cjs/propTypes/customPropTypes.js.map +7 -0
- package/dist/cjs/propTypes/describe.js +81 -0
- package/dist/cjs/propTypes/describe.js.map +7 -0
- package/dist/cjs/propTypes/describeConversions.js +96 -0
- package/dist/cjs/propTypes/describeConversions.js.map +7 -0
- package/dist/cjs/propTypes/describeGuards.js +49 -0
- package/dist/cjs/propTypes/describeGuards.js.map +7 -0
- package/dist/cjs/propTypes/index.js +37 -0
- package/dist/cjs/propTypes/index.js.map +7 -0
- package/dist/cjs/propTypes/toTypescript.js +154 -0
- package/dist/cjs/propTypes/toTypescript.js.map +7 -0
- package/dist/cjs/propTypes/types.js +27 -0
- package/dist/cjs/propTypes/types.js.map +7 -0
- package/dist/cjs/tests/globalProps/TestComponent.js +54 -0
- package/dist/cjs/tests/globalProps/TestComponent.js.map +7 -0
- package/dist/cjs/tests/validation/test.schema.js +67 -0
- package/dist/cjs/tests/validation/test.schema.js.map +7 -0
- package/dist/cjs/tests/xstyledProps/TestComponent.js +60 -0
- package/dist/cjs/tests/xstyledProps/TestComponent.js.map +7 -0
- package/dist/cjs/useDeprecateComponent/index.js +40 -0
- package/dist/cjs/useDeprecateComponent/index.js.map +7 -0
- package/dist/cjs/validation/errorTemplates.js +48 -0
- package/dist/cjs/validation/errorTemplates.js.map +7 -0
- package/dist/cjs/validation/index.js +30 -0
- package/dist/cjs/validation/index.js.map +7 -0
- package/dist/cjs/validation/typescriptGuards.js +65 -0
- package/dist/cjs/validation/typescriptGuards.js.map +7 -0
- package/dist/cjs/validation/typescriptParsers.js +76 -0
- package/dist/cjs/validation/typescriptParsers.js.map +7 -0
- package/dist/cjs/validation/typescriptValidator.js +171 -0
- package/dist/cjs/validation/typescriptValidator.js.map +7 -0
- package/dist/cjs/validation/validator.js +55 -0
- package/dist/cjs/validation/validator.js.map +7 -0
- package/dist/cjs/xstyledProps/constants.js +88 -0
- package/dist/cjs/xstyledProps/constants.js.map +7 -0
- package/dist/cjs/xstyledProps/index.js +29 -0
- package/dist/cjs/xstyledProps/index.js.map +7 -0
- package/dist/cjs/xstyledProps/useGetXstyledProps.js +48 -0
- package/dist/cjs/xstyledProps/useGetXstyledProps.js.map +7 -0
- package/dist/cjs/xstyledProps/xstyledPropTypes.js +92 -0
- package/dist/cjs/xstyledProps/xstyledPropTypes.js.map +7 -0
- package/dist/esm/defaultProps/index.js +3 -0
- package/dist/esm/defaultProps/index.js.map +7 -0
- package/dist/esm/defaultProps/useMemoMergePropsWithDefault.js +35 -0
- package/dist/esm/defaultProps/useMemoMergePropsWithDefault.js.map +7 -0
- package/dist/esm/getProps/index.js +8 -0
- package/dist/esm/getProps/index.js.map +7 -0
- package/dist/esm/globalProps/constants.js +368 -0
- package/dist/esm/globalProps/constants.js.map +7 -0
- package/dist/esm/globalProps/globalAttributesPropTypes.js +369 -0
- package/dist/esm/globalProps/globalAttributesPropTypes.js.map +7 -0
- package/dist/esm/globalProps/index.js +4 -0
- package/dist/esm/globalProps/index.js.map +7 -0
- package/dist/esm/globalProps/useGetGlobalAttributes.js +27 -0
- package/dist/esm/globalProps/useGetGlobalAttributes.js.map +7 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/index.js.map +7 -0
- package/dist/esm/propTypes/PropTypes.js +122 -0
- package/dist/esm/propTypes/PropTypes.js.map +7 -0
- package/dist/esm/propTypes/customPropTypes.js +9 -0
- package/dist/esm/propTypes/customPropTypes.js.map +7 -0
- package/dist/esm/propTypes/describe.js +52 -0
- package/dist/esm/propTypes/describe.js.map +7 -0
- package/dist/esm/propTypes/describeConversions.js +76 -0
- package/dist/esm/propTypes/describeConversions.js.map +7 -0
- package/dist/esm/propTypes/describeGuards.js +20 -0
- package/dist/esm/propTypes/describeGuards.js.map +7 -0
- package/dist/esm/propTypes/index.js +8 -0
- package/dist/esm/propTypes/index.js.map +7 -0
- package/dist/esm/propTypes/toTypescript.js +127 -0
- package/dist/esm/propTypes/toTypescript.js.map +7 -0
- package/dist/esm/propTypes/types.js +2 -0
- package/dist/esm/propTypes/types.js.map +7 -0
- package/dist/esm/tests/globalProps/TestComponent.js +27 -0
- package/dist/esm/tests/globalProps/TestComponent.js.map +7 -0
- package/dist/esm/tests/validation/test.schema.js +38 -0
- package/dist/esm/tests/validation/test.schema.js.map +7 -0
- package/dist/esm/tests/xstyledProps/TestComponent.js +33 -0
- package/dist/esm/tests/xstyledProps/TestComponent.js.map +7 -0
- package/dist/esm/useDeprecateComponent/index.js +11 -0
- package/dist/esm/useDeprecateComponent/index.js.map +7 -0
- package/dist/esm/validation/errorTemplates.js +19 -0
- package/dist/esm/validation/errorTemplates.js.map +7 -0
- package/dist/esm/validation/index.js +5 -0
- package/dist/esm/validation/index.js.map +7 -0
- package/dist/esm/validation/typescriptGuards.js +36 -0
- package/dist/esm/validation/typescriptGuards.js.map +7 -0
- package/dist/esm/validation/typescriptParsers.js +47 -0
- package/dist/esm/validation/typescriptParsers.js.map +7 -0
- package/dist/esm/validation/typescriptValidator.js +153 -0
- package/dist/esm/validation/typescriptValidator.js.map +7 -0
- package/dist/esm/validation/validator.js +26 -0
- package/dist/esm/validation/validator.js.map +7 -0
- package/dist/esm/xstyledProps/constants.js +59 -0
- package/dist/esm/xstyledProps/constants.js.map +7 -0
- package/dist/esm/xstyledProps/index.js +4 -0
- package/dist/esm/xstyledProps/index.js.map +7 -0
- package/dist/esm/xstyledProps/useGetXstyledProps.js +19 -0
- package/dist/esm/xstyledProps/useGetXstyledProps.js.map +7 -0
- package/dist/esm/xstyledProps/xstyledPropTypes.js +63 -0
- package/dist/esm/xstyledProps/xstyledPropTypes.js.map +7 -0
- package/package.json +91 -45
- package/cjs/defaultProps/index.js +0 -9
- package/cjs/defaultProps/useMemoMergePropsWithDefault.js +0 -48
- package/cjs/getProps/index.js +0 -20
- package/cjs/globalProps/constants.js +0 -15
- package/cjs/globalProps/globalAttributesPropTypes.js +0 -372
- package/cjs/globalProps/index.js +0 -11
- package/cjs/globalProps/useGetGlobalAttributes.js +0 -36
- package/cjs/index.js +0 -24
- package/cjs/validation/errorTemplates.js +0 -16
- package/cjs/validation/index.js +0 -15
- package/cjs/validation/typescriptGuards.js +0 -36
- package/cjs/validation/typescriptParsers.js +0 -45
- package/cjs/validation/typescriptValidator.js +0 -207
- package/cjs/validation/validator.js +0 -36
- package/esm/defaultProps/index.js +0 -1
- package/esm/defaultProps/useMemoMergePropsWithDefault.js +0 -39
- package/esm/getProps/index.js +0 -15
- package/esm/globalProps/constants.js +0 -11
- package/esm/globalProps/globalAttributesPropTypes.js +0 -368
- package/esm/globalProps/index.js +0 -2
- package/esm/globalProps/useGetGlobalAttributes.js +0 -32
- package/esm/index.js +0 -7
- package/esm/validation/errorTemplates.js +0 -11
- package/esm/validation/index.js +0 -3
- package/esm/validation/typescriptGuards.js +0 -23
- package/esm/validation/typescriptParsers.js +0 -41
- package/esm/validation/typescriptValidator.js +0 -202
- package/esm/validation/validator.js +0 -32
- package/types/defaultProps/index.d.ts +0 -1
- package/types/defaultProps/useMemoMergePropsWithDefault.d.ts +0 -1
- package/types/getProps/index.d.ts +0 -2
- package/types/globalProps/constants.d.ts +0 -3
- package/types/globalProps/globalAttributesPropTypes.d.ts +0 -2169
- package/types/globalProps/index.d.ts +0 -2
- package/types/globalProps/useGetGlobalAttributes.d.ts +0 -5
- package/types/index.d.ts +0 -4
- package/types/tests/any.validation.test.d.ts +0 -1
- package/types/tests/array.validation.test.d.ts +0 -1
- package/types/tests/boolean.validation.test.d.ts +0 -1
- package/types/tests/function.validation.test.d.ts +0 -1
- package/types/tests/number.validation.test.d.ts +0 -1
- package/types/tests/object.validation.test.d.ts +0 -1
- package/types/tests/schema.validation.test.d.ts +0 -1
- package/types/tests/string.validation.test.d.ts +0 -1
- package/types/tests/test.schema.d.ts +0 -1
- package/types/tests/union.validation.test.d.ts +0 -1
- package/types/validation/errorTemplates.d.ts +0 -2
- package/types/validation/index.d.ts +0 -3
- package/types/validation/typescriptGuards.d.ts +0 -12
- package/types/validation/typescriptParsers.d.ts +0 -1
- package/types/validation/typescriptValidator.d.ts +0 -15
- package/types/validation/validator.d.ts +0 -1
|
@@ -1,207 +0,0 @@
|
|
|
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 reactDesc = require('react-desc');
|
|
10
|
-
var react = require('react');
|
|
11
|
-
var errorTemplates = require('./errorTemplates.js');
|
|
12
|
-
var typescriptGuards = require('./typescriptGuards.js');
|
|
13
|
-
var typescriptParsers = require('./typescriptParsers.js');
|
|
14
|
-
|
|
15
|
-
// =============================================================================
|
|
16
|
-
// Atom Validators
|
|
17
|
-
// =============================================================================
|
|
18
|
-
// This functions will validate something from the data
|
|
19
|
-
// and optionally recursively apply `validateValueWithFormat`
|
|
20
|
-
// in smaller parts
|
|
21
|
-
const validateUndefined = (schemaName, key, value, format) => {
|
|
22
|
-
if (value !== undefined || value === 'undefined') {
|
|
23
|
-
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
const validateNull = (schemaName, key, value, format) => {
|
|
28
|
-
if (value !== null || value === 'null') {
|
|
29
|
-
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const validatePrimitiveType = (schemaName, key, value, format) => {
|
|
34
|
-
if (typeof value !== format) {
|
|
35
|
-
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
36
|
-
}
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const validateString = (schemaName, key, value, format) => {
|
|
40
|
-
if (value !== format.slice(1, -1)) {
|
|
41
|
-
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const validateArray = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
46
|
-
// Check that we have an array
|
|
47
|
-
if (!Array.isArray(value)) {
|
|
48
|
-
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
49
|
-
} // Check that each element inside satisfies the format
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
value.forEach((val, index) => {
|
|
53
|
-
// this is a recursive func, we need to invoke it before it's defined.
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
55
|
-
validateValueWithFormat(schemaName, "".concat(key, "[").concat(index, "]"), val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
function isObjectType(value) {
|
|
60
|
-
return !(typeof value !== 'object' || Array.isArray(value));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
const validateObject = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
64
|
-
const valuesIsObject = isObjectType(value); // Check that we have an object
|
|
65
|
-
|
|
66
|
-
if (!valuesIsObject) {
|
|
67
|
-
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
if (format === 'object') return;
|
|
72
|
-
const keyValuePairs = typescriptParsers.typescriptObjectParser(format); // Now we have the key - value pairs
|
|
73
|
-
// Each key could either be required or not
|
|
74
|
-
// Just recursively check the object
|
|
75
|
-
|
|
76
|
-
keyValuePairs.forEach(_ref => {
|
|
77
|
-
let [objectKey, objectValue] = _ref;
|
|
78
|
-
const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
|
|
79
|
-
|
|
80
|
-
if (trueKey === objectKey && !(trueKey in value)) {
|
|
81
|
-
errorTemplates.throwRequiredError(schemaName, key);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (trueKey in value) {
|
|
85
|
-
// this is a recursive func, we need to invoke it before it's defined.
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
87
|
-
validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const validateUnion = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
93
|
-
const possibilities = format.split(/\s?\|\s?/);
|
|
94
|
-
const errors = [];
|
|
95
|
-
possibilities.forEach(possibility => {
|
|
96
|
-
try {
|
|
97
|
-
// this is a recursive func, we need to invoke it before it's defined.
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
99
|
-
validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);
|
|
100
|
-
} catch (e) {
|
|
101
|
-
errors.push(e);
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
if (errors.length === possibilities.length) {
|
|
106
|
-
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
const validateFunction = (schemaName, key, value, format) => {
|
|
111
|
-
// Check that we have a function
|
|
112
|
-
if (typeof value !== 'function') {
|
|
113
|
-
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
function isJSXElement(value) {
|
|
118
|
-
return value === null || typeof value === 'object' && value !== null && '$$typeof' in value;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const validateJSXorNode = (schemaName, key, value, format) => {
|
|
122
|
-
const valueIsJSX = isJSXElement(value);
|
|
123
|
-
|
|
124
|
-
if (format === 'JSX.Element' && !valueIsJSX) {
|
|
125
|
-
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
126
|
-
}
|
|
127
|
-
}; // =============================================================================
|
|
128
|
-
// Schema validator
|
|
129
|
-
// =============================================================================
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
const validateValueWithFormat = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
133
|
-
nextValidationsMemo[value] = format;
|
|
134
|
-
|
|
135
|
-
if (value in validationsMemo) {
|
|
136
|
-
// We already validated this value on this format
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (typescriptGuards.isUndefined(format)) {
|
|
141
|
-
validateUndefined(schemaName, key, value, format);
|
|
142
|
-
} else if (typescriptGuards.isNull(format)) {
|
|
143
|
-
validateNull(schemaName, key, value, format);
|
|
144
|
-
} else if (typescriptGuards.isPrimitiveType(format)) {
|
|
145
|
-
validatePrimitiveType(schemaName, key, value, format);
|
|
146
|
-
} else if (typescriptGuards.isUnion(format)) {
|
|
147
|
-
validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
148
|
-
} else if (typescriptGuards.isString(format)) {
|
|
149
|
-
validateString(schemaName, key, value, format);
|
|
150
|
-
} else if (typescriptGuards.isArray(format)) {
|
|
151
|
-
validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
152
|
-
} else if (typescriptGuards.isObject(format)) {
|
|
153
|
-
validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
154
|
-
} else if (typescriptGuards.isFunction(format)) {
|
|
155
|
-
validateFunction(schemaName, key, value, format);
|
|
156
|
-
} else if (typescriptGuards.isJSXorNode(format)) {
|
|
157
|
-
validateJSXorNode(schemaName, key, value, format);
|
|
158
|
-
} else if (typescriptGuards.isSomethingWithParenthesis(format)) {
|
|
159
|
-
validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);
|
|
160
|
-
}
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
const validateTypescriptPropTypesImplementation = function (props, schema) {
|
|
164
|
-
let validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
165
|
-
let nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
166
|
-
const {
|
|
167
|
-
properties,
|
|
168
|
-
name: schemaName
|
|
169
|
-
} = schema;
|
|
170
|
-
properties.forEach(property => {
|
|
171
|
-
const {
|
|
172
|
-
name,
|
|
173
|
-
format,
|
|
174
|
-
required
|
|
175
|
-
} = property;
|
|
176
|
-
|
|
177
|
-
if (required && !(name in props)) {
|
|
178
|
-
errorTemplates.throwRequiredError(schema.name, name);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (name in props && (props[name] !== undefined || required)) {
|
|
182
|
-
validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
186
|
-
|
|
187
|
-
const useValidateTypescriptPropTypes = (props, propTypes) => {
|
|
188
|
-
const [validationsMemo, setValidationsMemo] = react.useState({}); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
189
|
-
|
|
190
|
-
const ComponentWithSchema = react.useMemo(() => {
|
|
191
|
-
const Component = () => {}; // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return reactDesc.describe(Component);
|
|
195
|
-
}, []); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
196
|
-
|
|
197
|
-
ComponentWithSchema.propTypes = propTypes;
|
|
198
|
-
react.useMemo(() => {
|
|
199
|
-
const nextValidationsMemo = {};
|
|
200
|
-
validateTypescriptPropTypesImplementation(props, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
201
|
-
ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
|
|
202
|
-
setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
203
|
-
}, [props]);
|
|
204
|
-
};
|
|
205
|
-
|
|
206
|
-
exports.useValidateTypescriptPropTypes = useValidateTypescriptPropTypes;
|
|
207
|
-
exports.validateTypescriptPropTypesImplementation = validateTypescriptPropTypesImplementation;
|
|
@@ -1,36 +0,0 @@
|
|
|
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;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { useMemoMergePropsWithDefault } from './useMemoMergePropsWithDefault.js';
|
|
@@ -1,39 +0,0 @@
|
|
|
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 };
|
package/esm/getProps/index.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
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 };
|
|
@@ -1,11 +0,0 @@
|
|
|
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 };
|