@elliemae/ds-props-helpers 2.0.0-next.8 → 2.0.0-rc.11
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/useMemoMergePropsWithDefault.js +9 -2
- package/cjs/getProps/index.js +11 -2
- package/cjs/validation/typescriptGuards.js +4 -0
- package/cjs/validation/typescriptParsers.js +4 -0
- package/cjs/validation/typescriptValidator.js +24 -6
- package/cjs/validation/validator.js +3 -1
- package/esm/defaultProps/useMemoMergePropsWithDefault.js +9 -2
- package/esm/getProps/index.js +11 -2
- package/esm/validation/typescriptGuards.js +4 -0
- package/esm/validation/typescriptParsers.js +4 -0
- package/esm/validation/typescriptValidator.js +24 -6
- package/esm/validation/validator.js +3 -1
- package/package.json +6 -3
- package/types/defaultProps/useMemoMergePropsWithDefault.d.ts +1 -1
- package/types/validation/typescriptValidator.d.ts +2 -2
|
@@ -2,6 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
8
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
9
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
5
10
|
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
6
11
|
var react = require('react');
|
|
7
12
|
var deepequal = require('fast-deep-equal/react');
|
|
@@ -18,7 +23,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
18
23
|
|
|
19
24
|
const useMemoCompare = (next, compare) => {
|
|
20
25
|
// Ref for storing previous value
|
|
21
|
-
const previousRef = react.useRef();
|
|
26
|
+
const previousRef = react.useRef(next);
|
|
22
27
|
const previous = previousRef.current; // Pass previous and next value to compare function
|
|
23
28
|
// to determine whether to consider them equal.
|
|
24
29
|
|
|
@@ -32,7 +37,9 @@ const useMemoCompare = (next, compare) => {
|
|
|
32
37
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
33
38
|
|
|
34
39
|
|
|
35
|
-
const useMemoMergePropsWithDefault = (props, defaultProps
|
|
40
|
+
const useMemoMergePropsWithDefault = function (props, defaultProps) {
|
|
41
|
+
let compare = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : deepequal__default["default"];
|
|
42
|
+
|
|
36
43
|
const mergedProps = _objectSpread(_objectSpread({}, defaultProps), props);
|
|
37
44
|
|
|
38
45
|
return useMemoCompare(mergedProps, compare);
|
package/cjs/getProps/index.js
CHANGED
|
@@ -2,10 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
5
8
|
require('core-js/modules/web.dom-collections.iterator.js');
|
|
6
9
|
|
|
7
|
-
const getAriaProps = props => Object.fromEntries(Object.entries(props).filter(
|
|
8
|
-
|
|
10
|
+
const getAriaProps = props => Object.fromEntries(Object.entries(props).filter(_ref => {
|
|
11
|
+
let [key] = _ref;
|
|
12
|
+
return key.includes('aria-');
|
|
13
|
+
}));
|
|
14
|
+
const getDataProps = props => Object.fromEntries(Object.entries(props).filter(_ref2 => {
|
|
15
|
+
let [key] = _ref2;
|
|
16
|
+
return key.includes('data-');
|
|
17
|
+
}));
|
|
9
18
|
|
|
10
19
|
exports.getAriaProps = getAriaProps;
|
|
11
20
|
exports.getDataProps = getDataProps;
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
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
|
+
|
|
5
9
|
const isPrimitiveType = format => ['string', 'number', 'boolean'].includes(format);
|
|
6
10
|
const isUndefined = format => format === '"undefined"';
|
|
7
11
|
const isUnion = format => {
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
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
|
+
|
|
5
9
|
/* eslint-disable complexity */
|
|
6
10
|
const typescriptObjectParser = format => {
|
|
7
11
|
const keyValuePairs = []; // State of the algorithm
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
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');
|
|
5
8
|
require('core-js/modules/web.dom-collections.iterator.js');
|
|
9
|
+
var reactDesc = require('react-desc');
|
|
6
10
|
var react = require('react');
|
|
7
11
|
var errorTemplates = require('./errorTemplates.js');
|
|
8
12
|
var typescriptGuards = require('./typescriptGuards.js');
|
|
@@ -55,7 +59,8 @@ const validateObject = (schemaName, key, value, format, validationsMemo, nextVal
|
|
|
55
59
|
// Each key could either be required or not
|
|
56
60
|
// Just recursively check the object
|
|
57
61
|
|
|
58
|
-
keyValuePairs.forEach(
|
|
62
|
+
keyValuePairs.forEach(_ref => {
|
|
63
|
+
let [objectKey, objectValue] = _ref;
|
|
59
64
|
const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
|
|
60
65
|
|
|
61
66
|
if (trueKey === objectKey && !(trueKey in value)) {
|
|
@@ -129,7 +134,9 @@ const validateValueWithFormat = (schemaName, key, value, format, validationsMemo
|
|
|
129
134
|
}
|
|
130
135
|
};
|
|
131
136
|
|
|
132
|
-
const validateTypescriptPropTypesImplementation = (props, schema
|
|
137
|
+
const validateTypescriptPropTypesImplementation = function (props, schema) {
|
|
138
|
+
let validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
139
|
+
let nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
133
140
|
const {
|
|
134
141
|
properties,
|
|
135
142
|
name: schemaName
|
|
@@ -149,12 +156,23 @@ const validateTypescriptPropTypesImplementation = (props, schema, validationsMem
|
|
|
149
156
|
validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
|
|
150
157
|
}
|
|
151
158
|
});
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
|
|
159
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
160
|
+
|
|
161
|
+
const useValidateTypescriptPropTypes = (props, propTypes) => {
|
|
162
|
+
const [validationsMemo, setValidationsMemo] = react.useState({}); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
163
|
+
|
|
164
|
+
const ComponentWithSchema = react.useMemo(() => {
|
|
165
|
+
const Component = () => {}; // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
return reactDesc.describe(Component);
|
|
169
|
+
}, []); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
170
|
+
|
|
171
|
+
ComponentWithSchema.propTypes = propTypes;
|
|
155
172
|
react.useMemo(() => {
|
|
156
173
|
const nextValidationsMemo = {};
|
|
157
|
-
validateTypescriptPropTypesImplementation(props,
|
|
174
|
+
validateTypescriptPropTypesImplementation(props, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
175
|
+
ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
|
|
158
176
|
setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
159
177
|
}, [props]);
|
|
160
178
|
};
|
|
@@ -2,9 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
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');
|
|
5
8
|
var errorTemplates = require('./errorTemplates.js');
|
|
6
9
|
|
|
7
|
-
/* eslint-disable complexity */
|
|
8
10
|
const useValidatePropTypes = (props, schema) => {
|
|
9
11
|
schema.properties.forEach(property => {
|
|
10
12
|
const propertyName = property.name;
|
|
@@ -1,3 +1,8 @@
|
|
|
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';
|
|
1
6
|
import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
|
|
2
7
|
import { useRef } from 'react';
|
|
3
8
|
import deepequal from 'fast-deep-equal/react';
|
|
@@ -9,7 +14,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
9
14
|
|
|
10
15
|
const useMemoCompare = (next, compare) => {
|
|
11
16
|
// Ref for storing previous value
|
|
12
|
-
const previousRef = useRef();
|
|
17
|
+
const previousRef = useRef(next);
|
|
13
18
|
const previous = previousRef.current; // Pass previous and next value to compare function
|
|
14
19
|
// to determine whether to consider them equal.
|
|
15
20
|
|
|
@@ -23,7 +28,9 @@ const useMemoCompare = (next, compare) => {
|
|
|
23
28
|
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
24
29
|
|
|
25
30
|
|
|
26
|
-
const useMemoMergePropsWithDefault = (props, defaultProps
|
|
31
|
+
const useMemoMergePropsWithDefault = function (props, defaultProps) {
|
|
32
|
+
let compare = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : deepequal;
|
|
33
|
+
|
|
27
34
|
const mergedProps = _objectSpread(_objectSpread({}, defaultProps), props);
|
|
28
35
|
|
|
29
36
|
return useMemoCompare(mergedProps, compare);
|
package/esm/getProps/index.js
CHANGED
|
@@ -1,6 +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';
|
|
1
4
|
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
2
5
|
|
|
3
|
-
const getAriaProps = props => Object.fromEntries(Object.entries(props).filter(
|
|
4
|
-
|
|
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
|
+
}));
|
|
5
14
|
|
|
6
15
|
export { getAriaProps, getDataProps };
|
|
@@ -1,3 +1,7 @@
|
|
|
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
|
+
|
|
1
5
|
const isPrimitiveType = format => ['string', 'number', 'boolean'].includes(format);
|
|
2
6
|
const isUndefined = format => format === '"undefined"';
|
|
3
7
|
const isUnion = format => {
|
|
@@ -1,3 +1,7 @@
|
|
|
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
|
+
|
|
1
5
|
/* eslint-disable complexity */
|
|
2
6
|
const typescriptObjectParser = format => {
|
|
3
7
|
const keyValuePairs = []; // State of the algorithm
|
|
@@ -1,4 +1,8 @@
|
|
|
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';
|
|
1
4
|
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
5
|
+
import { describe } from 'react-desc';
|
|
2
6
|
import { useState, useMemo } from 'react';
|
|
3
7
|
import { throwRequiredError, throwTypeError } from './errorTemplates.js';
|
|
4
8
|
import { isUndefined, isPrimitiveType, isUnion, isString, isArray, isObject, isFunction, isJSXorNode, isSomethingWithParenthesis } from './typescriptGuards.js';
|
|
@@ -51,7 +55,8 @@ const validateObject = (schemaName, key, value, format, validationsMemo, nextVal
|
|
|
51
55
|
// Each key could either be required or not
|
|
52
56
|
// Just recursively check the object
|
|
53
57
|
|
|
54
|
-
keyValuePairs.forEach(
|
|
58
|
+
keyValuePairs.forEach(_ref => {
|
|
59
|
+
let [objectKey, objectValue] = _ref;
|
|
55
60
|
const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
|
|
56
61
|
|
|
57
62
|
if (trueKey === objectKey && !(trueKey in value)) {
|
|
@@ -125,7 +130,9 @@ const validateValueWithFormat = (schemaName, key, value, format, validationsMemo
|
|
|
125
130
|
}
|
|
126
131
|
};
|
|
127
132
|
|
|
128
|
-
const validateTypescriptPropTypesImplementation = (props, schema
|
|
133
|
+
const validateTypescriptPropTypesImplementation = function (props, schema) {
|
|
134
|
+
let validationsMemo = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
135
|
+
let nextValidationsMemo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
129
136
|
const {
|
|
130
137
|
properties,
|
|
131
138
|
name: schemaName
|
|
@@ -145,12 +152,23 @@ const validateTypescriptPropTypesImplementation = (props, schema, validationsMem
|
|
|
145
152
|
validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
|
|
146
153
|
}
|
|
147
154
|
});
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
|
|
155
|
+
}; // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
156
|
+
|
|
157
|
+
const useValidateTypescriptPropTypes = (props, propTypes) => {
|
|
158
|
+
const [validationsMemo, setValidationsMemo] = useState({}); // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
159
|
+
|
|
160
|
+
const ComponentWithSchema = useMemo(() => {
|
|
161
|
+
const Component = () => {}; // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
return describe(Component);
|
|
165
|
+
}, []); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
166
|
+
|
|
167
|
+
ComponentWithSchema.propTypes = propTypes;
|
|
151
168
|
useMemo(() => {
|
|
152
169
|
const nextValidationsMemo = {};
|
|
153
|
-
validateTypescriptPropTypesImplementation(props,
|
|
170
|
+
validateTypescriptPropTypesImplementation(props, // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
|
|
171
|
+
ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
|
|
154
172
|
setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
155
173
|
}, [props]);
|
|
156
174
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
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';
|
|
1
4
|
import { throwRequiredError, throwTypeError } from './errorTemplates.js';
|
|
2
5
|
|
|
3
|
-
/* eslint-disable complexity */
|
|
4
6
|
const useValidatePropTypes = (props, schema) => {
|
|
5
7
|
schema.properties.forEach(property => {
|
|
6
8
|
const propertyName = property.name;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-props-helpers",
|
|
3
|
-
"version": "2.0.0-
|
|
3
|
+
"version": "2.0.0-rc.11",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Props Helpers",
|
|
6
6
|
"module": "./esm/index.js",
|
|
@@ -71,8 +71,11 @@
|
|
|
71
71
|
"build": "node ../../scripts/build/build.js"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"
|
|
75
|
-
"
|
|
74
|
+
"fast-deep-equal": "~3.1.3",
|
|
75
|
+
"react-desc": "^4.1.3"
|
|
76
|
+
},
|
|
77
|
+
"devDependencies": {
|
|
78
|
+
"@testing-library/jest-dom": "~5.15.0"
|
|
76
79
|
},
|
|
77
80
|
"peerDependencies": {
|
|
78
81
|
"react": "~17.0.2",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const useMemoMergePropsWithDefault: <T = Record<
|
|
1
|
+
export declare const useMemoMergePropsWithDefault: <T = Record<string, any>>(props: Partial<T>, defaultProps: Partial<T>, compare?: (a: any, b: any) => boolean) => T;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PropsWithChildren } from 'react';
|
|
1
|
+
import React, { PropsWithChildren } from 'react';
|
|
2
2
|
interface TypescriptSchema {
|
|
3
3
|
description: string;
|
|
4
4
|
name: string;
|
|
@@ -11,5 +11,5 @@ interface TypescriptSchema {
|
|
|
11
11
|
}[];
|
|
12
12
|
}
|
|
13
13
|
export declare const validateTypescriptPropTypesImplementation: (props: PropsWithChildren<Record<string, unknown>>, schema: TypescriptSchema, validationsMemo?: Record<string, string>, nextValidationsMemo?: Record<string, string>) => void;
|
|
14
|
-
export declare const useValidateTypescriptPropTypes: (props: PropsWithChildren<
|
|
14
|
+
export declare const useValidateTypescriptPropTypes: <T = Record<string, any>>(props: React.PropsWithChildren<T>, propTypes: any) => void;
|
|
15
15
|
export {};
|