@elliemae/ds-props-helpers 2.2.0-next.3 → 2.3.0-alpha.1
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 +28 -9
- package/cjs/defaultProps/index.js.map +7 -0
- package/cjs/defaultProps/useMemoMergePropsWithDefault.js +44 -44
- package/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +7 -0
- package/cjs/getProps/index.js +37 -20
- package/cjs/getProps/index.js.map +7 -0
- package/cjs/index.js +30 -24
- package/cjs/index.js.map +7 -0
- package/cjs/tests/test.schema.js +67 -0
- package/cjs/tests/test.schema.js.map +7 -0
- package/cjs/validation/errorTemplates.js +44 -12
- package/cjs/validation/errorTemplates.js.map +7 -0
- package/cjs/validation/index.js +30 -15
- package/cjs/validation/index.js.map +7 -0
- package/cjs/validation/typescriptGuards.js +60 -31
- package/cjs/validation/typescriptGuards.js.map +7 -0
- package/cjs/validation/typescriptParsers.js +65 -34
- package/cjs/validation/typescriptParsers.js.map +7 -0
- package/cjs/validation/typescriptValidator.js +99 -135
- package/cjs/validation/typescriptValidator.js.map +7 -0
- package/cjs/validation/validator.js +43 -24
- package/cjs/validation/validator.js.map +7 -0
- package/esm/defaultProps/index.js +3 -1
- package/esm/defaultProps/index.js.map +7 -0
- package/esm/defaultProps/useMemoMergePropsWithDefault.js +14 -34
- package/esm/defaultProps/useMemoMergePropsWithDefault.js.map +7 -0
- package/esm/getProps/index.js +8 -15
- package/esm/getProps/index.js.map +7 -0
- package/esm/index.js +5 -7
- package/esm/index.js.map +7 -0
- package/esm/tests/test.schema.js +38 -0
- package/esm/tests/test.schema.js.map +7 -0
- package/esm/validation/errorTemplates.js +15 -7
- package/esm/validation/errorTemplates.js.map +7 -0
- package/esm/validation/index.js +5 -3
- package/esm/validation/index.js.map +7 -0
- package/esm/validation/typescriptGuards.js +31 -18
- package/esm/validation/typescriptGuards.js.map +7 -0
- package/esm/validation/typescriptParsers.js +36 -30
- package/esm/validation/typescriptParsers.js.map +7 -0
- package/esm/validation/typescriptValidator.js +57 -106
- package/esm/validation/typescriptValidator.js.map +7 -0
- package/esm/validation/validator.js +12 -18
- package/esm/validation/validator.js.map +7 -0
- package/package.json +1 -17
- package/types/index.d.ts +0 -1
- package/types/validation/typescriptValidator.d.ts +2 -2
- 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/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/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
|
@@ -1,45 +1,76 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var typescriptParsers_exports = {};
|
|
29
|
+
__export(typescriptParsers_exports, {
|
|
30
|
+
typescriptObjectParser: () => typescriptObjectParser
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
const typescriptObjectParser = (format) => {
|
|
34
|
+
const keyValuePairs = [];
|
|
35
|
+
let lastKey = "";
|
|
36
|
+
let lastValue = "";
|
|
15
37
|
let shouldAppendToKey = true;
|
|
16
|
-
|
|
17
38
|
const pushPair = () => {
|
|
18
|
-
if (lastKey)
|
|
19
|
-
|
|
20
|
-
|
|
39
|
+
if (lastKey)
|
|
40
|
+
keyValuePairs.push([lastKey, lastValue]);
|
|
41
|
+
lastKey = "";
|
|
42
|
+
lastValue = "";
|
|
21
43
|
shouldAppendToKey = true;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
|
|
44
|
+
};
|
|
25
45
|
let depth = 0;
|
|
26
|
-
format.split(
|
|
27
|
-
if (char ===
|
|
46
|
+
format.split("").forEach((char) => {
|
|
47
|
+
if (char === "{") {
|
|
28
48
|
depth += 1;
|
|
29
|
-
if (depth > 1)
|
|
30
|
-
|
|
31
|
-
|
|
49
|
+
if (depth > 1)
|
|
50
|
+
lastValue += char;
|
|
51
|
+
} else if (char === "}") {
|
|
52
|
+
if (depth > 1)
|
|
53
|
+
lastValue += char;
|
|
32
54
|
depth -= 1;
|
|
33
|
-
if (depth === 1)
|
|
34
|
-
|
|
55
|
+
if (depth === 1)
|
|
56
|
+
pushPair();
|
|
57
|
+
} else if (char === ":") {
|
|
35
58
|
shouldAppendToKey = false;
|
|
36
|
-
if (depth > 1)
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
59
|
+
if (depth > 1)
|
|
60
|
+
lastValue += char;
|
|
61
|
+
} else if (char === ",") {
|
|
62
|
+
if (depth === 1)
|
|
63
|
+
pushPair();
|
|
64
|
+
else
|
|
65
|
+
lastValue += char;
|
|
66
|
+
} else if (char === " ") {
|
|
67
|
+
} else if (shouldAppendToKey)
|
|
68
|
+
lastKey += char;
|
|
69
|
+
else
|
|
70
|
+
lastValue += char;
|
|
40
71
|
});
|
|
41
72
|
pushPair();
|
|
42
73
|
return keyValuePairs;
|
|
43
74
|
};
|
|
44
|
-
|
|
45
|
-
|
|
75
|
+
module.exports = __toCommonJS(typescriptParsers_exports);
|
|
76
|
+
//# sourceMappingURL=typescriptParsers.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/validation/typescriptParsers.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable complexity */\nexport const typescriptObjectParser = (format: string): [string, string][] => {\n const keyValuePairs: [string, string][] = [];\n\n // State of the algorithm\n let lastKey = '';\n let lastValue = '';\n let shouldAppendToKey = true;\n\n const pushPair = () => {\n if (lastKey) keyValuePairs.push([lastKey, lastValue]);\n lastKey = '';\n lastValue = '';\n shouldAppendToKey = true;\n };\n\n // Complex -- but working -- logic\n let depth = 0;\n format.split('').forEach((char) => {\n if (char === '{') {\n depth += 1;\n if (depth > 1) lastValue += char;\n } else if (char === '}') {\n if (depth > 1) lastValue += char;\n depth -= 1;\n if (depth === 1) pushPair();\n } else if (char === ':') {\n shouldAppendToKey = false;\n if (depth > 1) lastValue += char;\n } else if (char === ',') {\n if (depth === 1) pushPair();\n else lastValue += char;\n } else if (char === ' ') {\n // Do nothing\n } else if (shouldAppendToKey) lastKey += char;\n else lastValue += char;\n });\n pushPair();\n\n return keyValuePairs;\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADChB,MAAM,yBAAyB,CAAC,WAAuC;AAC5E,QAAM,gBAAoC;AAG1C,MAAI,UAAU;AACd,MAAI,YAAY;AAChB,MAAI,oBAAoB;AAExB,QAAM,WAAW,MAAM;AACrB,QAAI;AAAS,oBAAc,KAAK,CAAC,SAAS;AAC1C,cAAU;AACV,gBAAY;AACZ,wBAAoB;AAAA;AAItB,MAAI,QAAQ;AACZ,SAAO,MAAM,IAAI,QAAQ,CAAC,SAAS;AACjC,QAAI,SAAS,KAAK;AAChB,eAAS;AACT,UAAI,QAAQ;AAAG,qBAAa;AAAA,eACnB,SAAS,KAAK;AACvB,UAAI,QAAQ;AAAG,qBAAa;AAC5B,eAAS;AACT,UAAI,UAAU;AAAG;AAAA,eACR,SAAS,KAAK;AACvB,0BAAoB;AACpB,UAAI,QAAQ;AAAG,qBAAa;AAAA,eACnB,SAAS,KAAK;AACvB,UAAI,UAAU;AAAG;AAAA;AACZ,qBAAa;AAAA,eACT,SAAS,KAAK;AAAA,eAEd;AAAmB,iBAAW;AAAA;AACpC,mBAAa;AAAA;AAEpB;AAEA,SAAO;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,207 +1,171 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var typescriptValidator_exports = {};
|
|
29
|
+
__export(typescriptValidator_exports, {
|
|
30
|
+
useValidateTypescriptPropTypes: () => useValidateTypescriptPropTypes,
|
|
31
|
+
validateTypescriptPropTypesImplementation: () => validateTypescriptPropTypesImplementation
|
|
32
|
+
});
|
|
33
|
+
var React = __toESM(require("react"));
|
|
34
|
+
var import_react_desc = require("react-desc");
|
|
35
|
+
var import_react = require("react");
|
|
36
|
+
var import_errorTemplates = require("./errorTemplates");
|
|
37
|
+
var import_typescriptGuards = require("./typescriptGuards");
|
|
38
|
+
var import_typescriptParsers = require("./typescriptParsers");
|
|
21
39
|
const validateUndefined = (schemaName, key, value, format) => {
|
|
22
|
-
if (value !==
|
|
23
|
-
|
|
40
|
+
if (value !== void 0 || value === "undefined") {
|
|
41
|
+
(0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
|
|
24
42
|
}
|
|
25
43
|
};
|
|
26
|
-
|
|
27
44
|
const validateNull = (schemaName, key, value, format) => {
|
|
28
|
-
if (value !== null || value ===
|
|
29
|
-
|
|
45
|
+
if (value !== null || value === "null") {
|
|
46
|
+
(0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
|
|
30
47
|
}
|
|
31
48
|
};
|
|
32
|
-
|
|
33
49
|
const validatePrimitiveType = (schemaName, key, value, format) => {
|
|
34
50
|
if (typeof value !== format) {
|
|
35
|
-
|
|
51
|
+
(0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
|
|
36
52
|
}
|
|
37
53
|
};
|
|
38
|
-
|
|
39
54
|
const validateString = (schemaName, key, value, format) => {
|
|
40
55
|
if (value !== format.slice(1, -1)) {
|
|
41
|
-
|
|
56
|
+
(0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
|
|
42
57
|
}
|
|
43
58
|
};
|
|
44
|
-
|
|
45
59
|
const validateArray = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
46
|
-
// Check that we have an array
|
|
47
60
|
if (!Array.isArray(value)) {
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
61
|
+
(0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
|
|
62
|
+
}
|
|
52
63
|
value.forEach((val, index) => {
|
|
53
|
-
|
|
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);
|
|
64
|
+
validateValueWithFormat(schemaName, `${key}[${index}]`, val, format.slice(0, -2), validationsMemo, nextValidationsMemo);
|
|
56
65
|
});
|
|
57
66
|
};
|
|
58
|
-
|
|
59
67
|
function isObjectType(value) {
|
|
60
|
-
return !(typeof value !==
|
|
68
|
+
return !(typeof value !== "object" || Array.isArray(value));
|
|
61
69
|
}
|
|
62
|
-
|
|
63
70
|
const validateObject = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
64
|
-
const valuesIsObject = isObjectType(value);
|
|
65
|
-
|
|
71
|
+
const valuesIsObject = isObjectType(value);
|
|
66
72
|
if (!valuesIsObject) {
|
|
67
|
-
|
|
73
|
+
(0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
|
|
68
74
|
return;
|
|
69
75
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const keyValuePairs =
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
keyValuePairs.forEach(_ref => {
|
|
77
|
-
let [objectKey, objectValue] = _ref;
|
|
78
|
-
const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;
|
|
79
|
-
|
|
76
|
+
if (format === "object")
|
|
77
|
+
return;
|
|
78
|
+
const keyValuePairs = (0, import_typescriptParsers.typescriptObjectParser)(format);
|
|
79
|
+
keyValuePairs.forEach(([objectKey, objectValue]) => {
|
|
80
|
+
const trueKey = objectKey.slice(-1) === "?" ? objectKey.slice(0, -1) : objectKey;
|
|
80
81
|
if (trueKey === objectKey && !(trueKey in value)) {
|
|
81
|
-
|
|
82
|
+
(0, import_errorTemplates.throwRequiredError)(schemaName, key);
|
|
82
83
|
}
|
|
83
|
-
|
|
84
84
|
if (trueKey in value) {
|
|
85
|
-
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
87
|
-
validateValueWithFormat(schemaName, "".concat(key, "[").concat(trueKey, "]"), value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
|
|
85
|
+
validateValueWithFormat(schemaName, `${key}[${trueKey}]`, value[trueKey], objectValue, validationsMemo, nextValidationsMemo);
|
|
88
86
|
}
|
|
89
87
|
});
|
|
90
88
|
};
|
|
91
|
-
|
|
92
89
|
const validateUnion = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
93
90
|
const possibilities = format.split(/\s?\|\s?/);
|
|
94
91
|
const errors = [];
|
|
95
|
-
possibilities.forEach(possibility => {
|
|
92
|
+
possibilities.forEach((possibility) => {
|
|
96
93
|
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
94
|
validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);
|
|
100
95
|
} catch (e) {
|
|
101
96
|
errors.push(e);
|
|
102
97
|
}
|
|
103
98
|
});
|
|
104
|
-
|
|
105
99
|
if (errors.length === possibilities.length) {
|
|
106
|
-
|
|
100
|
+
(0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
|
|
107
101
|
}
|
|
108
102
|
};
|
|
109
|
-
|
|
110
103
|
const validateFunction = (schemaName, key, value, format) => {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
104
|
+
if (typeof value !== "function") {
|
|
105
|
+
(0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
|
|
114
106
|
}
|
|
115
107
|
};
|
|
116
|
-
|
|
117
108
|
function isJSXElement(value) {
|
|
118
|
-
return value === null || typeof value ===
|
|
109
|
+
return value === null || typeof value === "object" && value !== null && "$$typeof" in value;
|
|
119
110
|
}
|
|
120
|
-
|
|
121
111
|
const validateJSXorNode = (schemaName, key, value, format) => {
|
|
122
112
|
const valueIsJSX = isJSXElement(value);
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
errorTemplates.throwTypeError(schemaName, key, value, format);
|
|
113
|
+
if (format === "JSX.Element" && !valueIsJSX) {
|
|
114
|
+
(0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
|
|
126
115
|
}
|
|
127
|
-
};
|
|
128
|
-
// Schema validator
|
|
129
|
-
// =============================================================================
|
|
130
|
-
|
|
131
|
-
|
|
116
|
+
};
|
|
132
117
|
const validateValueWithFormat = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {
|
|
133
118
|
nextValidationsMemo[value] = format;
|
|
134
|
-
|
|
135
119
|
if (value in validationsMemo) {
|
|
136
|
-
// We already validated this value on this format
|
|
137
120
|
return;
|
|
138
121
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
} else if (typescriptGuards.isUnion(format)) {
|
|
122
|
+
if ((0, import_typescriptGuards.isUndefined)(format)) {
|
|
123
|
+
validateUndefined(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
124
|
+
} else if ((0, import_typescriptGuards.isNull)(format)) {
|
|
125
|
+
validateNull(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
126
|
+
} else if ((0, import_typescriptGuards.isPrimitiveType)(format)) {
|
|
127
|
+
validatePrimitiveType(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
128
|
+
} else if ((0, import_typescriptGuards.isUnion)(format)) {
|
|
147
129
|
validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
148
|
-
} else if (
|
|
149
|
-
validateString(schemaName, key, value, format);
|
|
150
|
-
} else if (
|
|
130
|
+
} else if ((0, import_typescriptGuards.isString)(format)) {
|
|
131
|
+
validateString(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
132
|
+
} else if ((0, import_typescriptGuards.isArray)(format)) {
|
|
151
133
|
validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
152
|
-
} else if (
|
|
134
|
+
} else if ((0, import_typescriptGuards.isObject)(format)) {
|
|
153
135
|
validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
154
|
-
} else if (
|
|
155
|
-
validateFunction(schemaName, key, value, format);
|
|
156
|
-
} else if (
|
|
157
|
-
validateJSXorNode(schemaName, key, value, format);
|
|
158
|
-
} else if (
|
|
136
|
+
} else if ((0, import_typescriptGuards.isFunction)(format)) {
|
|
137
|
+
validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
138
|
+
} else if ((0, import_typescriptGuards.isJSXorNode)(format)) {
|
|
139
|
+
validateJSXorNode(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
140
|
+
} else if ((0, import_typescriptGuards.isSomethingWithParenthesis)(format)) {
|
|
159
141
|
validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);
|
|
160
142
|
}
|
|
161
143
|
};
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const {
|
|
167
|
-
properties,
|
|
168
|
-
name: schemaName
|
|
169
|
-
} = schema;
|
|
170
|
-
properties.forEach(property => {
|
|
171
|
-
const {
|
|
172
|
-
name,
|
|
173
|
-
format,
|
|
174
|
-
required
|
|
175
|
-
} = property;
|
|
176
|
-
|
|
144
|
+
const validateTypescriptPropTypesImplementation = (props, schema, validationsMemo = {}, nextValidationsMemo = {}) => {
|
|
145
|
+
const { properties, name: schemaName } = schema;
|
|
146
|
+
properties.forEach((property) => {
|
|
147
|
+
const { name, format, required } = property;
|
|
177
148
|
if (required && !(name in props)) {
|
|
178
|
-
|
|
149
|
+
(0, import_errorTemplates.throwRequiredError)(schema.name, name);
|
|
179
150
|
}
|
|
180
|
-
|
|
181
|
-
if (name in props && (props[name] !== undefined || required)) {
|
|
151
|
+
if (name in props && (props[name] !== void 0 || required)) {
|
|
182
152
|
validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);
|
|
183
153
|
}
|
|
184
154
|
});
|
|
185
|
-
};
|
|
186
|
-
|
|
155
|
+
};
|
|
187
156
|
const useValidateTypescriptPropTypes = (props, propTypes) => {
|
|
188
|
-
const [validationsMemo, setValidationsMemo] =
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return reactDesc.describe(Component);
|
|
195
|
-
}, []); // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
|
196
|
-
|
|
157
|
+
const [validationsMemo, setValidationsMemo] = (0, import_react.useState)({});
|
|
158
|
+
const ComponentWithSchema = (0, import_react.useMemo)(() => {
|
|
159
|
+
const Component = () => {
|
|
160
|
+
};
|
|
161
|
+
return (0, import_react_desc.describe)(Component);
|
|
162
|
+
}, []);
|
|
197
163
|
ComponentWithSchema.propTypes = propTypes;
|
|
198
|
-
|
|
164
|
+
(0, import_react.useMemo)(() => {
|
|
199
165
|
const nextValidationsMemo = {};
|
|
200
|
-
validateTypescriptPropTypesImplementation(props,
|
|
201
|
-
|
|
202
|
-
setValidationsMemo(nextValidationsMemo); // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
166
|
+
validateTypescriptPropTypesImplementation(props, ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
|
|
167
|
+
setValidationsMemo(nextValidationsMemo);
|
|
203
168
|
}, [props]);
|
|
204
169
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
exports.validateTypescriptPropTypesImplementation = validateTypescriptPropTypesImplementation;
|
|
170
|
+
module.exports = __toCommonJS(typescriptValidator_exports);
|
|
171
|
+
//# sourceMappingURL=typescriptValidator.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/validation/typescriptValidator.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable complexity */\n/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport { describe } from 'react-desc';\nimport React, { PropsWithChildren, useMemo, useState } from 'react';\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\nimport {\n isArray,\n isFunction,\n isJSXorNode,\n isObject,\n isPrimitiveType,\n isSomethingWithParenthesis,\n isString,\n isUnion,\n isUndefined,\n isNull,\n} from './typescriptGuards';\nimport { typescriptObjectParser } from './typescriptParsers';\n\ninterface TypescriptSchema {\n description: string;\n name: string;\n properties: { name: string; description: string; defaultValue?: unknown; format: string; required?: boolean }[];\n}\n\ntype ValidatorFn = (\n schemaName: string,\n key: string,\n value: unknown,\n format: string,\n validationsMemo: Record<symbol, string>,\n nextValidationsMemo: Record<symbol, string>,\n) => void;\n\n// =============================================================================\n// Atom Validators\n// =============================================================================\n\n// This functions will validate something from the data\n// and optionally recursively apply `validateValueWithFormat`\n// in smaller parts\n\nconst validateUndefined: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== undefined || value === 'undefined') {\n throwTypeError(schemaName, key, value, format);\n }\n};\nconst validateNull: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== null || value === 'null') {\n throwTypeError(schemaName, key, value, format);\n }\n};\nconst validatePrimitiveType: ValidatorFn = (schemaName, key, value, format) => {\n if (typeof value !== format) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateString: ValidatorFn = (schemaName, key, value, format) => {\n if (value !== format.slice(1, -1)) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateArray: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n // Check that we have an array\n if (!Array.isArray(value)) {\n throwTypeError(schemaName, key, value, format);\n }\n\n // Check that each element inside satisfies the format\n (value as unknown[]).forEach((val, index) => {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${index}]`,\n val,\n format.slice(0, -2),\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\nfunction isObjectType(value: unknown | Record<string, unknown>): value is Record<string, unknown> {\n return !(typeof value !== 'object' || Array.isArray(value));\n}\nconst validateObject: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const valuesIsObject = isObjectType(value);\n // Check that we have an object\n if (!valuesIsObject) {\n throwTypeError(schemaName, key, value, format);\n return;\n }\n\n if (format === 'object') return;\n\n const keyValuePairs = typescriptObjectParser(format);\n // Now we have the key - value pairs\n // Each key could either be required or not\n // Just recursively check the object\n\n keyValuePairs.forEach(([objectKey, objectValue]) => {\n const trueKey = objectKey.slice(-1) === '?' ? objectKey.slice(0, -1) : objectKey;\n\n if (trueKey === objectKey && !(trueKey in value)) {\n throwRequiredError(schemaName, key);\n }\n\n if (trueKey in value) {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(\n schemaName,\n `${key}[${trueKey}]`,\n value[trueKey],\n objectValue,\n validationsMemo,\n nextValidationsMemo,\n );\n }\n });\n};\n\nconst validateUnion: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n const possibilities = format.split(/\\s?\\|\\s?/);\n\n const errors = [];\n\n possibilities.forEach((possibility) => {\n try {\n // this is a recursive func, we need to invoke it before it's defined.\n // eslint-disable-next-line @typescript-eslint/no-use-before-define\n validateValueWithFormat(schemaName, key, value, possibility, validationsMemo, nextValidationsMemo);\n } catch (e) {\n errors.push(e);\n }\n });\n\n if (errors.length === possibilities.length) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nconst validateFunction: ValidatorFn = (schemaName, key, value, format) => {\n // Check that we have a function\n if (typeof value !== 'function') {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\nfunction isJSXElement(value: unknown | JSX.Element): value is JSX.Element {\n return value === null || (typeof value === 'object' && value !== null && '$$typeof' in value);\n}\nconst validateJSXorNode: ValidatorFn = (schemaName, key, value, format) => {\n const valueIsJSX = isJSXElement(value);\n if (format === 'JSX.Element' && !valueIsJSX) {\n throwTypeError(schemaName, key, value, format);\n }\n};\n\n// =============================================================================\n// Schema validator\n// =============================================================================\n\nconst validateValueWithFormat: ValidatorFn = (schemaName, key, value, format, validationsMemo, nextValidationsMemo) => {\n nextValidationsMemo[value as symbol] = format;\n\n if ((value as symbol) in validationsMemo) {\n // We already validated this value on this format\n return;\n }\n\n if (isUndefined(format)) {\n validateUndefined(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isNull(format)) {\n validateNull(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isPrimitiveType(format)) {\n validatePrimitiveType(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isUnion(format)) {\n validateUnion(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isString(format)) {\n validateString(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isArray(format)) {\n validateArray(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isObject(format)) {\n validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isFunction(format)) {\n validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isJSXorNode(format)) {\n validateJSXorNode(schemaName, key, value, format, validationsMemo, nextValidationsMemo);\n } else if (isSomethingWithParenthesis(format)) {\n validateValueWithFormat(schemaName, key, value, format.slice(1, -1), validationsMemo, nextValidationsMemo);\n }\n};\n\nexport const validateTypescriptPropTypesImplementation = (\n props: PropsWithChildren<Record<string, unknown>>,\n schema: TypescriptSchema,\n validationsMemo: Record<string, string> = {},\n nextValidationsMemo: Record<string, string> = {},\n): void => {\n const { properties, name: schemaName } = schema;\n\n properties.forEach((property) => {\n const { name, format, required } = property;\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (name in props && (props[name] !== undefined || required)) {\n validateValueWithFormat(schemaName, name, props[name], format, validationsMemo, nextValidationsMemo);\n }\n });\n};\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const useValidateTypescriptPropTypes = <T = Record<string, any>>(\n props: PropsWithChildren<T>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n propTypes: any,\n): void => {\n const [validationsMemo, setValidationsMemo] = useState({});\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\n const ComponentWithSchema = useMemo(() => {\n const Component = () => {};\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call\n return describe(Component);\n }, []);\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment\n ComponentWithSchema.propTypes = propTypes;\n\n useMemo(() => {\n const nextValidationsMemo = {};\n\n validateTypescriptPropTypesImplementation(\n props,\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call\n ComponentWithSchema.toTypescript(),\n validationsMemo,\n nextValidationsMemo,\n );\n\n setValidationsMemo(nextValidationsMemo);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props]);\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADGvB,wBAAyB;AACzB,mBAA4D;AAC5D,4BAAmD;AACnD,8BAWO;AACP,+BAAuC;AAyBv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AAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,36 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
var
|
|
9
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __reExport = (target, module2, copyDefault, desc) => {
|
|
13
|
+
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(module2))
|
|
15
|
+
if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
|
|
16
|
+
__defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return target;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (module2, isNodeMode) => {
|
|
21
|
+
return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
|
|
22
|
+
};
|
|
23
|
+
var __toCommonJS = /* @__PURE__ */ ((cache) => {
|
|
24
|
+
return (module2, temp) => {
|
|
25
|
+
return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
|
|
26
|
+
};
|
|
27
|
+
})(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
|
|
28
|
+
var validator_exports = {};
|
|
29
|
+
__export(validator_exports, {
|
|
30
|
+
useValidatePropTypes: () => useValidatePropTypes
|
|
31
|
+
});
|
|
32
|
+
var React = __toESM(require("react"));
|
|
33
|
+
var import_errorTemplates = require("./errorTemplates");
|
|
10
34
|
const useValidatePropTypes = (props, schema) => {
|
|
11
|
-
schema.properties.forEach(property => {
|
|
35
|
+
schema.properties.forEach((property) => {
|
|
12
36
|
const propertyName = property.name;
|
|
13
37
|
const currentProp = props[propertyName];
|
|
14
|
-
const currentPropTypeOf = typeof currentProp;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
let isValidReactElement = false; // this depends on react desc definition
|
|
19
|
-
|
|
38
|
+
const currentPropTypeOf = typeof currentProp;
|
|
39
|
+
const currentFormat = property.format;
|
|
40
|
+
let isValidReactElement = false;
|
|
20
41
|
if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {
|
|
21
|
-
|
|
42
|
+
(0, import_errorTemplates.throwRequiredError)(schema.name, property.name);
|
|
22
43
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (currentPropTypeOf === 'object' && Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') && (currentFormat.includes('node') || currentFormat.includes('element'))) {
|
|
44
|
+
if (currentPropTypeOf !== "undefined" && currentProp !== null) {
|
|
45
|
+
if (currentPropTypeOf === "object" && Object.prototype.hasOwnProperty.call(currentProp, "$$typeof") && (currentFormat.includes("node") || currentFormat.includes("element"))) {
|
|
26
46
|
isValidReactElement = true;
|
|
27
47
|
}
|
|
28
|
-
|
|
29
48
|
if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {
|
|
30
|
-
|
|
49
|
+
(0, import_errorTemplates.throwTypeError)(schema.name, propertyName, currentProp, currentFormat);
|
|
31
50
|
}
|
|
32
51
|
}
|
|
33
52
|
});
|
|
34
53
|
};
|
|
35
|
-
|
|
36
|
-
|
|
54
|
+
module.exports = __toCommonJS(validator_exports);
|
|
55
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/validation/validator.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable complexity */\n/* eslint-disable @typescript-eslint/explicit-module-boundary-types */\nimport { throwRequiredError, throwTypeError } from './errorTemplates';\n\nexport const useValidatePropTypes = (props: Record<string, unknown>, schema): void => {\n schema.properties.forEach((property) => {\n const propertyName = property.name;\n const currentProp = props[propertyName];\n const currentPropTypeOf = typeof currentProp;\n // eslint-disable-next-line max-len\n const currentFormat = property.format; // this is csv representing types e.g.: \"string\"/\"string,number\"/\"[object],string\"\n let isValidReactElement = false;\n // this depends on react desc definition\n if (property.required && !Object.prototype.hasOwnProperty.call(props, property.name)) {\n throwRequiredError(schema.name, property.name);\n }\n if (currentPropTypeOf !== 'undefined' && currentProp !== null) {\n if (\n currentPropTypeOf === 'object' &&\n Object.prototype.hasOwnProperty.call(currentProp, '$$typeof') &&\n (currentFormat.includes('node') || currentFormat.includes('element'))\n ) {\n isValidReactElement = true;\n }\n\n if (!currentFormat.includes(currentPropTypeOf) && !currentFormat.includes(currentProp) && !isValidReactElement) {\n throwTypeError(schema.name, propertyName, currentProp, currentFormat);\n }\n }\n });\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,4BAAmD;AAE5C,MAAM,uBAAuB,CAAC,OAAgC,WAAiB;AACpF,SAAO,WAAW,QAAQ,CAAC,aAAa;AACtC,UAAM,eAAe,SAAS;AAC9B,UAAM,cAAc,MAAM;AAC1B,UAAM,oBAAoB,OAAO;AAEjC,UAAM,gBAAgB,SAAS;AAC/B,QAAI,sBAAsB;AAE1B,QAAI,SAAS,YAAY,CAAC,OAAO,UAAU,eAAe,KAAK,OAAO,SAAS,OAAO;AACpF,oDAAmB,OAAO,MAAM,SAAS;AAAA;AAE3C,QAAI,sBAAsB,eAAe,gBAAgB,MAAM;AAC7D,UACE,sBAAsB,YACtB,OAAO,UAAU,eAAe,KAAK,aAAa,eACjD,eAAc,SAAS,WAAW,cAAc,SAAS,aAC1D;AACA,8BAAsB;AAAA;AAGxB,UAAI,CAAC,cAAc,SAAS,sBAAsB,CAAC,cAAc,SAAS,gBAAgB,CAAC,qBAAqB;AAC9G,kDAAe,OAAO,MAAM,cAAc,aAAa;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/defaultProps/index.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export * from './useMemoMergePropsWithDefault';\n"],
|
|
5
|
+
"mappings": "AAAA;ACAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,39 +1,19 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
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
|
-
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { useRef } from "react";
|
|
3
|
+
import deepequal from "fast-deep-equal/react";
|
|
15
4
|
const useMemoCompare = (next, compare) => {
|
|
16
|
-
// Ref for storing previous value
|
|
17
5
|
const previousRef = useRef(next);
|
|
18
|
-
const previous = previousRef.current;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
6
|
+
const previous = previousRef.current;
|
|
7
|
+
const isEqual = compare(previous, next);
|
|
8
|
+
if (!isEqual)
|
|
9
|
+
previousRef.current = next;
|
|
27
10
|
return isEqual ? previous : next;
|
|
28
|
-
};
|
|
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
|
-
|
|
11
|
+
};
|
|
12
|
+
const useMemoMergePropsWithDefault = (props, defaultProps, compare = deepequal) => {
|
|
13
|
+
const mergedProps = { ...defaultProps, ...props };
|
|
36
14
|
return useMemoCompare(mergedProps, compare);
|
|
37
15
|
};
|
|
38
|
-
|
|
39
|
-
|
|
16
|
+
export {
|
|
17
|
+
useMemoMergePropsWithDefault
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=useMemoMergePropsWithDefault.js.map
|