@elliemae/ds-props-helpers 2.0.0-rc.3 → 2.0.0-rc.7
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 +1 -1
- package/cjs/validation/typescriptValidator.js +16 -4
- package/esm/defaultProps/useMemoMergePropsWithDefault.js +1 -1
- package/esm/validation/typescriptValidator.js +16 -4
- package/package.json +1 -1
- package/types/defaultProps/useMemoMergePropsWithDefault.d.ts +1 -1
- package/types/validation/typescriptValidator.d.ts +2 -2
|
@@ -23,7 +23,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
23
23
|
|
|
24
24
|
const useMemoCompare = (next, compare) => {
|
|
25
25
|
// Ref for storing previous value
|
|
26
|
-
const previousRef = react.useRef();
|
|
26
|
+
const previousRef = react.useRef(next);
|
|
27
27
|
const previous = previousRef.current; // Pass previous and next value to compare function
|
|
28
28
|
// to determine whether to consider them equal.
|
|
29
29
|
|
|
@@ -6,6 +6,7 @@ require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
|
6
6
|
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
7
|
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
8
|
require('core-js/modules/web.dom-collections.iterator.js');
|
|
9
|
+
var reactDesc = require('react-desc');
|
|
9
10
|
var react = require('react');
|
|
10
11
|
var errorTemplates = require('./errorTemplates.js');
|
|
11
12
|
var typescriptGuards = require('./typescriptGuards.js');
|
|
@@ -155,12 +156,23 @@ const validateTypescriptPropTypesImplementation = function (props, schema) {
|
|
|
155
156
|
validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
|
|
156
157
|
}
|
|
157
158
|
});
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
|
|
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;
|
|
161
172
|
react.useMemo(() => {
|
|
162
173
|
const nextValidationsMemo = {};
|
|
163
|
-
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);
|
|
164
176
|
setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
165
177
|
}, [props]);
|
|
166
178
|
};
|
|
@@ -14,7 +14,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
14
14
|
|
|
15
15
|
const useMemoCompare = (next, compare) => {
|
|
16
16
|
// Ref for storing previous value
|
|
17
|
-
const previousRef = useRef();
|
|
17
|
+
const previousRef = useRef(next);
|
|
18
18
|
const previous = previousRef.current; // Pass previous and next value to compare function
|
|
19
19
|
// to determine whether to consider them equal.
|
|
20
20
|
|
|
@@ -2,6 +2,7 @@ import 'core-js/modules/esnext.async-iterator.for-each.js';
|
|
|
2
2
|
import 'core-js/modules/esnext.iterator.constructor.js';
|
|
3
3
|
import 'core-js/modules/esnext.iterator.for-each.js';
|
|
4
4
|
import 'core-js/modules/web.dom-collections.iterator.js';
|
|
5
|
+
import { describe } from 'react-desc';
|
|
5
6
|
import { useState, useMemo } from 'react';
|
|
6
7
|
import { throwRequiredError, throwTypeError } from './errorTemplates.js';
|
|
7
8
|
import { isUndefined, isPrimitiveType, isUnion, isString, isArray, isObject, isFunction, isJSXorNode, isSomethingWithParenthesis } from './typescriptGuards.js';
|
|
@@ -151,12 +152,23 @@ const validateTypescriptPropTypesImplementation = function (props, schema) {
|
|
|
151
152
|
validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
|
|
152
153
|
}
|
|
153
154
|
});
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
|
|
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;
|
|
157
168
|
useMemo(() => {
|
|
158
169
|
const nextValidationsMemo = {};
|
|
159
|
-
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);
|
|
160
172
|
setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
161
173
|
}, [props]);
|
|
162
174
|
};
|
package/package.json
CHANGED
|
@@ -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: <T = Record<
|
|
14
|
+
export declare const useValidateTypescriptPropTypes: <T = Record<string, any>>(props: React.PropsWithChildren<T>, propTypes: any) => void;
|
|
15
15
|
export {};
|