@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.
Files changed (59) hide show
  1. package/cjs/defaultProps/index.js +28 -9
  2. package/cjs/defaultProps/index.js.map +7 -0
  3. package/cjs/defaultProps/useMemoMergePropsWithDefault.js +44 -44
  4. package/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +7 -0
  5. package/cjs/getProps/index.js +37 -20
  6. package/cjs/getProps/index.js.map +7 -0
  7. package/cjs/index.js +30 -24
  8. package/cjs/index.js.map +7 -0
  9. package/cjs/tests/test.schema.js +67 -0
  10. package/cjs/tests/test.schema.js.map +7 -0
  11. package/cjs/validation/errorTemplates.js +44 -12
  12. package/cjs/validation/errorTemplates.js.map +7 -0
  13. package/cjs/validation/index.js +30 -15
  14. package/cjs/validation/index.js.map +7 -0
  15. package/cjs/validation/typescriptGuards.js +60 -31
  16. package/cjs/validation/typescriptGuards.js.map +7 -0
  17. package/cjs/validation/typescriptParsers.js +65 -34
  18. package/cjs/validation/typescriptParsers.js.map +7 -0
  19. package/cjs/validation/typescriptValidator.js +99 -135
  20. package/cjs/validation/typescriptValidator.js.map +7 -0
  21. package/cjs/validation/validator.js +43 -24
  22. package/cjs/validation/validator.js.map +7 -0
  23. package/esm/defaultProps/index.js +3 -1
  24. package/esm/defaultProps/index.js.map +7 -0
  25. package/esm/defaultProps/useMemoMergePropsWithDefault.js +14 -34
  26. package/esm/defaultProps/useMemoMergePropsWithDefault.js.map +7 -0
  27. package/esm/getProps/index.js +8 -15
  28. package/esm/getProps/index.js.map +7 -0
  29. package/esm/index.js +5 -7
  30. package/esm/index.js.map +7 -0
  31. package/esm/tests/test.schema.js +38 -0
  32. package/esm/tests/test.schema.js.map +7 -0
  33. package/esm/validation/errorTemplates.js +15 -7
  34. package/esm/validation/errorTemplates.js.map +7 -0
  35. package/esm/validation/index.js +5 -3
  36. package/esm/validation/index.js.map +7 -0
  37. package/esm/validation/typescriptGuards.js +31 -18
  38. package/esm/validation/typescriptGuards.js.map +7 -0
  39. package/esm/validation/typescriptParsers.js +36 -30
  40. package/esm/validation/typescriptParsers.js.map +7 -0
  41. package/esm/validation/typescriptValidator.js +57 -106
  42. package/esm/validation/typescriptValidator.js.map +7 -0
  43. package/esm/validation/validator.js +12 -18
  44. package/esm/validation/validator.js.map +7 -0
  45. package/package.json +1 -17
  46. package/types/index.d.ts +0 -1
  47. package/types/validation/typescriptValidator.d.ts +2 -2
  48. package/cjs/globalProps/constants.js +0 -15
  49. package/cjs/globalProps/globalAttributesPropTypes.js +0 -372
  50. package/cjs/globalProps/index.js +0 -11
  51. package/cjs/globalProps/useGetGlobalAttributes.js +0 -36
  52. package/esm/globalProps/constants.js +0 -11
  53. package/esm/globalProps/globalAttributesPropTypes.js +0 -368
  54. package/esm/globalProps/index.js +0 -2
  55. package/esm/globalProps/useGetGlobalAttributes.js +0 -32
  56. package/types/globalProps/constants.d.ts +0 -3
  57. package/types/globalProps/globalAttributesPropTypes.d.ts +0 -2169
  58. package/types/globalProps/index.d.ts +0 -2
  59. package/types/globalProps/useGetGlobalAttributes.d.ts +0 -5
@@ -1,45 +1,76 @@
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
-
9
- /* eslint-disable complexity */
10
- const typescriptObjectParser = format => {
11
- const keyValuePairs = []; // State of the algorithm
12
-
13
- let lastKey = '';
14
- let lastValue = '';
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) keyValuePairs.push([lastKey, lastValue]);
19
- lastKey = '';
20
- lastValue = '';
39
+ if (lastKey)
40
+ keyValuePairs.push([lastKey, lastValue]);
41
+ lastKey = "";
42
+ lastValue = "";
21
43
  shouldAppendToKey = true;
22
- }; // Complex -- but working -- logic
23
-
24
-
44
+ };
25
45
  let depth = 0;
26
- format.split('').forEach(char => {
27
- if (char === '{') {
46
+ format.split("").forEach((char) => {
47
+ if (char === "{") {
28
48
  depth += 1;
29
- if (depth > 1) lastValue += char;
30
- } else if (char === '}') {
31
- if (depth > 1) lastValue += char;
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) pushPair();
34
- } else if (char === ':') {
55
+ if (depth === 1)
56
+ pushPair();
57
+ } else if (char === ":") {
35
58
  shouldAppendToKey = false;
36
- if (depth > 1) lastValue += char;
37
- } else if (char === ',') {
38
- if (depth === 1) pushPair();else lastValue += char;
39
- } else if (char === ' ') ; else if (shouldAppendToKey) lastKey += char;else lastValue += char;
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
- exports.typescriptObjectParser = typescriptObjectParser;
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
- '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
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 !== undefined || value === 'undefined') {
23
- errorTemplates.throwTypeError(schemaName, key, value, format);
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 === 'null') {
29
- errorTemplates.throwTypeError(schemaName, key, value, format);
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
- errorTemplates.throwTypeError(schemaName, key, value, format);
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
- errorTemplates.throwTypeError(schemaName, key, value, format);
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
- errorTemplates.throwTypeError(schemaName, key, value, format);
49
- } // Check that each element inside satisfies the format
50
-
51
-
61
+ (0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
62
+ }
52
63
  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);
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 !== 'object' || Array.isArray(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); // Check that we have an object
65
-
71
+ const valuesIsObject = isObjectType(value);
66
72
  if (!valuesIsObject) {
67
- errorTemplates.throwTypeError(schemaName, key, value, format);
73
+ (0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
68
74
  return;
69
75
  }
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
-
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
- errorTemplates.throwRequiredError(schemaName, key);
82
+ (0, import_errorTemplates.throwRequiredError)(schemaName, key);
82
83
  }
83
-
84
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);
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
- errorTemplates.throwTypeError(schemaName, key, value, format);
100
+ (0, import_errorTemplates.throwTypeError)(schemaName, key, value, format);
107
101
  }
108
102
  };
109
-
110
103
  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);
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 === 'object' && value !== null && '$$typeof' in 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
- if (format === 'JSX.Element' && !valueIsJSX) {
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
- 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)) {
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 (typescriptGuards.isString(format)) {
149
- validateString(schemaName, key, value, format);
150
- } else if (typescriptGuards.isArray(format)) {
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 (typescriptGuards.isObject(format)) {
134
+ } else if ((0, import_typescriptGuards.isObject)(format)) {
153
135
  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)) {
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 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
-
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
- errorTemplates.throwRequiredError(schema.name, name);
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
- }; // eslint-disable-next-line @typescript-eslint/no-explicit-any
186
-
155
+ };
187
156
  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
-
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
- react.useMemo(() => {
164
+ (0, import_react.useMemo)(() => {
199
165
  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
166
+ validateTypescriptPropTypesImplementation(props, ComponentWithSchema.toTypescript(), validationsMemo, nextValidationsMemo);
167
+ setValidationsMemo(nextValidationsMemo);
203
168
  }, [props]);
204
169
  };
205
-
206
- exports.useValidateTypescriptPropTypes = useValidateTypescriptPropTypes;
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": "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",
6
+ "names": []
7
+ }
@@ -1,36 +1,55 @@
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
-
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; // 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
-
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
- errorTemplates.throwRequiredError(schema.name, property.name);
42
+ (0, import_errorTemplates.throwRequiredError)(schema.name, property.name);
22
43
  }
23
-
24
- if (currentPropTypeOf !== 'undefined' && currentProp !== null) {
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
- errorTemplates.throwTypeError(schema.name, propertyName, currentProp, currentFormat);
49
+ (0, import_errorTemplates.throwTypeError)(schema.name, propertyName, currentProp, currentFormat);
31
50
  }
32
51
  }
33
52
  });
34
53
  };
35
-
36
- exports.useValidatePropTypes = useValidatePropTypes;
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
+ }
@@ -1 +1,3 @@
1
- export { useMemoMergePropsWithDefault } from './useMemoMergePropsWithDefault.js';
1
+ import * as React from "react";
2
+ export * from "./useMemoMergePropsWithDefault";
3
+ //# sourceMappingURL=index.js.map
@@ -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 '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
-
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; // 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
-
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
- }; // 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
-
11
+ };
12
+ const useMemoMergePropsWithDefault = (props, defaultProps, compare = deepequal) => {
13
+ const mergedProps = { ...defaultProps, ...props };
36
14
  return useMemoCompare(mergedProps, compare);
37
15
  };
38
-
39
- export { useMemoMergePropsWithDefault };
16
+ export {
17
+ useMemoMergePropsWithDefault
18
+ };
19
+ //# sourceMappingURL=useMemoMergePropsWithDefault.js.map