@elliemae/ds-props-helpers 3.70.0-next.9 → 3.70.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/contractProps/getContractProps.js +47 -0
- package/dist/cjs/contractProps/getContractProps.js.map +7 -0
- package/dist/cjs/contractProps/index.js +36 -0
- package/dist/cjs/contractProps/index.js.map +7 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/index.js.map +2 -2
- package/dist/cjs/package.json +1 -4
- package/dist/cjs/propTypes/PropTypes.js +1 -0
- package/dist/cjs/propTypes/PropTypes.js.map +2 -2
- package/dist/cjs/propTypes/toTypescript.js +5 -1
- package/dist/cjs/propTypes/toTypescript.js.map +2 -2
- package/dist/cjs/useOwnerProps/index.js +1 -1
- package/dist/cjs/useOwnerProps/index.js.map +2 -2
- package/dist/cjs/validation/typescriptGuards.js +2 -0
- package/dist/cjs/validation/typescriptGuards.js.map +2 -2
- package/dist/cjs/validation/typescriptValidator.js +2 -0
- package/dist/cjs/validation/typescriptValidator.js.map +2 -2
- package/dist/cjs/xstyledProps/useGetXstyledProps.js.map +2 -2
- package/dist/esm/contractProps/getContractProps.js +17 -0
- package/dist/esm/contractProps/getContractProps.js.map +7 -0
- package/dist/esm/contractProps/index.js +6 -0
- package/dist/esm/contractProps/index.js.map +7 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/package.json +1 -4
- package/dist/esm/propTypes/PropTypes.js +1 -0
- package/dist/esm/propTypes/PropTypes.js.map +2 -2
- package/dist/esm/propTypes/toTypescript.js +5 -1
- package/dist/esm/propTypes/toTypescript.js.map +2 -2
- package/dist/esm/useOwnerProps/index.js +2 -2
- package/dist/esm/useOwnerProps/index.js.map +2 -2
- package/dist/esm/validation/typescriptGuards.js +2 -0
- package/dist/esm/validation/typescriptGuards.js.map +2 -2
- package/dist/esm/validation/typescriptValidator.js +3 -0
- package/dist/esm/validation/typescriptValidator.js.map +2 -2
- package/dist/esm/xstyledProps/useGetXstyledProps.js.map +2 -2
- package/dist/types/contractProps/getContractProps.d.ts +52 -0
- package/dist/types/contractProps/index.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/validation/typescriptGuards.d.ts +1 -0
- package/package.json +7 -7
- package/dist/types/tests/globalProps/TestComponent.d.ts +0 -1
- package/dist/types/tests/globalProps/globalAttributes.test.d.ts +0 -1
- package/dist/types/tests/propsPerDataTestId/getPropsPerDatatestIdPropTypes.test.d.ts +0 -1
- package/dist/types/tests/propsPerDataTestId/getPropsPerDatatestid.test.d.ts +0 -1
- package/dist/types/tests/validation/any.validation.test.d.ts +0 -1
- package/dist/types/tests/validation/array.validation.test.d.ts +0 -1
- package/dist/types/tests/validation/boolean.validation.test.d.ts +0 -1
- package/dist/types/tests/validation/function.validation.test.d.ts +0 -1
- package/dist/types/tests/validation/isRequiredIf.validation.test.d.ts +0 -1
- package/dist/types/tests/validation/number.validation.test.d.ts +0 -1
- package/dist/types/tests/validation/object.validation.test.d.ts +0 -1
- package/dist/types/tests/validation/objectOf.validation.test.d.ts +0 -1
- package/dist/types/tests/validation/schema.validation.test.d.ts +0 -1
- package/dist/types/tests/validation/shapeWithObjectOf.validation.test.d.ts +0 -1
- package/dist/types/tests/validation/shapeWithObjectOfAndSignature.validation.test.d.ts +0 -1
- package/dist/types/tests/validation/string.validation.test.d.ts +0 -1
- package/dist/types/tests/validation/test.schema.d.ts +0 -1
- package/dist/types/tests/validation/union.validation.test.d.ts +0 -1
- package/dist/types/tests/xstyledProps/TestComponent.d.ts +0 -1
- package/dist/types/tests/xstyledProps/xstyledProps.test.d.ts +0 -1
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var getContractProps_exports = {};
|
|
30
|
+
__export(getContractProps_exports, {
|
|
31
|
+
getContractProps: () => getContractProps
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(getContractProps_exports);
|
|
34
|
+
var React = __toESM(require("react"));
|
|
35
|
+
const DOCUMENTATION_ONLY_SCHEMA_KEYS = /* @__PURE__ */ new Set(["aria-*", "on-*", "data-*", "all HTML attributes"]);
|
|
36
|
+
const getContractProps = (props, contractShape) => {
|
|
37
|
+
const declaredKeys = new Set(Object.keys(contractShape).filter((key) => !DOCUMENTATION_ONLY_SCHEMA_KEYS.has(key)));
|
|
38
|
+
const contractProps = {};
|
|
39
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
40
|
+
if (value === void 0) return;
|
|
41
|
+
if (DOCUMENTATION_ONLY_SCHEMA_KEYS.has(key)) return;
|
|
42
|
+
if (!declaredKeys.has(key) && !key.startsWith("data-")) return;
|
|
43
|
+
contractProps[key] = value;
|
|
44
|
+
});
|
|
45
|
+
return contractProps;
|
|
46
|
+
};
|
|
47
|
+
//# sourceMappingURL=getContractProps.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/contractProps/getContractProps.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * Documentation-only entries that live in `globalAttributesPropTypes` (and therefore in every\n * component schema that spreads it). They exist so the Storybook props table can show \"you may pass\n * any aria-* / data-* / on-* / HTML attribute\" in a single row \u2014 they are NOT prop names a consumer\n * can ever pass, so they must never be treated as part of the runtime key set.\n */\nconst DOCUMENTATION_ONLY_SCHEMA_KEYS = new Set(['aria-*', 'on-*', 'data-*', 'all HTML attributes']);\n\n/**\n * Filters an arbitrary object down to the props a component's contract declares.\n *\n * This is the engine behind each package's own curated passthrough utility (e.g. ds-app-picker's\n * `getDSAppPickerContractProps`). Packages are expected to expose a bound utility rather than their\n * schema: the schema stays an internal implementation detail, so the two can drift later without\n * expanding anyone's public API.\n *\n * Three behaviours worth knowing, because callers depend on them:\n *\n * 1. **Documentation-only wildcard keys are ignored.** See `DOCUMENTATION_ONLY_SCHEMA_KEYS`.\n * 2. **`data-*` is honoured by prefix**, matching `getGlobalAttributes` \u2014 arbitrary data attributes\n * are a supported consumer surface even though no schema can enumerate them. Note the house\n * behaviour deliberately does not extend the same courtesy to `aria-*` or `on*`: those are\n * matched against the schema's explicit list, so a typo fails loudly instead of reaching the DOM.\n * 3. **`undefined` is dropped, `null` is forwarded.** These two are not interchangeable, and the rule\n * follows React rather than being invented here:\n *\n * - React's own default resolution (`resolveDefaultProps`) applies a `defaultProps` entry only when\n * the incoming prop is `undefined`; a `null` is respected as an explicitly supplied value. This\n * is the same rule as JS destructuring defaults and ES6 default parameters \u2014 a language-level\n * standard, not a React invention. So `undefined` means \"I am not defining this, you decide\" and\n * `null` means \"I am defining it, as nothing\".\n * - Everywhere React *consumes* a value rather than defaulting it \u2014 DOM attributes, children, event\n * handlers \u2014 it collapses the two and treats both as absent. The distinction is load-bearing\n * only at a default-resolution boundary.\n *\n * A contract passthrough is exactly such a boundary: the result is spread *after* a wrapper's own\n * defaults, so dropping `undefined` is what stops an unset key from erasing a working default,\n * while forwarding `null` is what lets a consumer deliberately override one. This matters more\n * here than in plain React, because Dimsum's `useMemoMergePropsWithDefault` is a plain\n * `{...defaults, ...props}` spread \u2014 it does NOT skip `undefined` the way `resolveDefaultProps`\n * does, so an `undefined` that reaches it clobbers the component's default too.\n *\n * What happens to a forwarded `null` afterwards is the receiving component's business, not this\n * function's. Dimsum components are strictly typed: `validateTypescriptPropTypesImplementation`\n * validates any value that is not `undefined`, and a prop declared as a function does not admit\n * `null` \u2014 so passing `null` there raises a prop-type error, correctly. A prop only accepts `null`\n * if its own declared type says so and its code carries the matching null guards. Where a consumer\n * wants to state \"do nothing\", the type-honouring way to say it is an explicit no-op \u2014 `() => {}`\n * for a handler, `() => null` for a component \u2014 which is unambiguous in a way that `null` is not.\n * This function stays out of that decision: forwarding the value and letting the owning contract\n * judge it is the correct division of concerns at this abstraction level.\n *\n * @param props - the object to filter; anything the contract does not declare is discarded\n * @param contractShape - any object whose KEYS name the contract's props. Only `Object.keys` is read,\n * so it is deliberately not narrowed to `DSPropTypesSchema`\n *\n * a PropTypes schema is usually fine and there is a code dedicated to discarding the global attributes to make the schema compatible for faster internal transition/implementation.\n * @returns a new object containing only the declared, defined props\n */\nexport const getContractProps = <ContractProps>(props: object, contractShape: object): Partial<ContractProps> => {\n const declaredKeys = new Set(Object.keys(contractShape).filter((key) => !DOCUMENTATION_ONLY_SCHEMA_KEYS.has(key)));\n\n // `props` is typed as `object` rather than `Record<string, unknown>` so callers can pass their own\n // declared prop interfaces without a cast at every call site. The casts live here instead.\n const contractProps: Record<string, unknown> = {};\n\n Object.entries(props as Record<string, unknown>).forEach(([key, value]) => {\n if (value === undefined) return;\n // Order matters: 'data-*' is itself prefixed with 'data-', so the documentation-only check has\n // to win over the prefix rule below or the pseudo-key would readmit itself.\n if (DOCUMENTATION_ONLY_SCHEMA_KEYS.has(key)) return;\n if (!declaredKeys.has(key) && !key.startsWith('data-')) return;\n contractProps[key] = value;\n });\n\n return contractProps as Partial<ContractProps>;\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADMvB,MAAM,iCAAiC,oBAAI,IAAI,CAAC,UAAU,QAAQ,UAAU,qBAAqB,CAAC;AAqD3F,MAAM,mBAAmB,CAAgB,OAAe,kBAAkD;AAC/G,QAAM,eAAe,IAAI,IAAI,OAAO,KAAK,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,+BAA+B,IAAI,GAAG,CAAC,CAAC;AAIjH,QAAM,gBAAyC,CAAC;AAEhD,SAAO,QAAQ,KAAgC,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACzE,QAAI,UAAU,OAAW;AAGzB,QAAI,+BAA+B,IAAI,GAAG,EAAG;AAC7C,QAAI,CAAC,aAAa,IAAI,GAAG,KAAK,CAAC,IAAI,WAAW,OAAO,EAAG;AACxD,kBAAc,GAAG,IAAI;AAAA,EACvB,CAAC;AAED,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var contractProps_exports = {};
|
|
30
|
+
__export(contractProps_exports, {
|
|
31
|
+
getContractProps: () => import_getContractProps.getContractProps
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(contractProps_exports);
|
|
34
|
+
var React = __toESM(require("react"));
|
|
35
|
+
var import_getContractProps = require("./getContractProps.js");
|
|
36
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/contractProps/index.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
+
"sourcesContent": ["export { getContractProps } from './getContractProps.js';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,8BAAiC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/cjs/index.js
CHANGED
|
@@ -31,6 +31,7 @@ __export(index_exports, {
|
|
|
31
31
|
PropTypes: () => import_propTypes.PropTypes,
|
|
32
32
|
describe: () => import_propTypes.describe,
|
|
33
33
|
getAriaProps: () => import_getProps.getAriaProps,
|
|
34
|
+
getContractProps: () => import_contractProps.getContractProps,
|
|
34
35
|
getDataProps: () => import_getProps.getDataProps,
|
|
35
36
|
getGlobalAttributes: () => import_globalProps.getGlobalAttributes,
|
|
36
37
|
getPropsPerDatatestIdPropTypes: () => import_propsPerDataTestId.getPropsPerDatatestIdPropTypes,
|
|
@@ -58,6 +59,7 @@ var import_propTypes = require("./propTypes/index.js");
|
|
|
58
59
|
var import_validation = require("./validation/index.js");
|
|
59
60
|
var import_xstyledProps = require("./xstyledProps/index.js");
|
|
60
61
|
var import_useDeprecateComponent = require("./useDeprecateComponent/index.js");
|
|
62
|
+
var import_contractProps = require("./contractProps/index.js");
|
|
61
63
|
var import_propsPerDataTestId = require("./propsPerDataTestId/index.js");
|
|
62
64
|
var import_propsPerSlot = require("./propsPerSlot/index.js");
|
|
63
65
|
var import_useOwnerProps = require("./useOwnerProps/index.js");
|
package/dist/cjs/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/index.ts", "../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["export { useMemoMergePropsWithDefault } from './defaultProps/index.js';\nexport { getAriaProps, getDataProps } from './getProps/index.js';\nexport {\n getGlobalAttributes,\n useGetGlobalAttributes,\n globalAttributesPropTypes,\n type GlobalAttributesT,\n} from './globalProps/index.js';\nexport { describe, PropTypes, type DSPropTypesSchema } from './propTypes/index.js';\nexport type { ValidationMap } from 'prop-types';\nexport {\n throwTypeError,\n throwRequiredError,\n useValidateTypescriptPropTypes,\n validateTypescriptPropTypesImplementation,\n} from './validation/index.js';\nexport { type XstyledProps, useGetXstyledProps, xstyledPropTypes, getXstyledProps } from './xstyledProps/index.js';\nexport { useDeprecateComponent } from './useDeprecateComponent/index.js';\n\nexport { getPropsPerDatatestid, getPropsPerDatatestIdPropTypes } from './propsPerDataTestId/index.js';\nexport { getPropsPerSlotPropTypes } from './propsPerSlot/index.js';\nexport { useOwnerProps } from './useOwnerProps/index.js';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,0BAA6C;AAC7C,sBAA2C;AAC3C,yBAKO;AACP,uBAA4D;AAE5D,wBAKO;AACP,0BAAyF;AACzF,mCAAsC;AAEtC,gCAAsE;AACtE,0BAAyC;AACzC,2BAA8B;",
|
|
4
|
+
"sourcesContent": ["export { useMemoMergePropsWithDefault } from './defaultProps/index.js';\nexport { getAriaProps, getDataProps } from './getProps/index.js';\nexport {\n getGlobalAttributes,\n useGetGlobalAttributes,\n globalAttributesPropTypes,\n type GlobalAttributesT,\n} from './globalProps/index.js';\nexport { describe, PropTypes, type DSPropTypesSchema } from './propTypes/index.js';\nexport type { ValidationMap } from 'prop-types';\nexport {\n throwTypeError,\n throwRequiredError,\n useValidateTypescriptPropTypes,\n validateTypescriptPropTypesImplementation,\n} from './validation/index.js';\nexport { type XstyledProps, useGetXstyledProps, xstyledPropTypes, getXstyledProps } from './xstyledProps/index.js';\nexport { useDeprecateComponent } from './useDeprecateComponent/index.js';\n\nexport { getContractProps } from './contractProps/index.js';\nexport { getPropsPerDatatestid, getPropsPerDatatestIdPropTypes } from './propsPerDataTestId/index.js';\nexport { getPropsPerSlotPropTypes } from './propsPerSlot/index.js';\nexport { useOwnerProps } from './useOwnerProps/index.js';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,0BAA6C;AAC7C,sBAA2C;AAC3C,yBAKO;AACP,uBAA4D;AAE5D,wBAKO;AACP,0BAAyF;AACzF,mCAAsC;AAEtC,2BAAiC;AACjC,gCAAsE;AACtE,0BAAyC;AACzC,2BAA8B;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/cjs/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/propTypes/PropTypes.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import type { PropTypesTypes, DocumentedPropType, ReactDescObjT, PropTypesObj } from './types.js';\n\nconst addPropTypeDocumentationField = <T extends keyof ReactDescObjT>(fieldName: T) =>\n function addFieldToReactDesc(this: DocumentedPropType, value: ReactDescObjT[T]): DocumentedPropType {\n if (!this.reactDesc) {\n this.reactDesc = {};\n }\n let realValue = value;\n if (\n fieldName === 'global' ||\n fieldName === 'dataTestId' ||\n fieldName === 'hidden' ||\n fieldName === 'xstyled' ||\n fieldName === 'omitValidation'\n )\n realValue = true;\n\n this.reactDesc[fieldName] = realValue;\n return this;\n };\n\nconst documentedPropType: Omit<DocumentedPropType, 'type' | 'isRequired' | 'reactDesc'> = {\n defaultValue: addPropTypeDocumentationField('defaultValue'),\n description: addPropTypeDocumentationField('description'),\n deprecated: addPropTypeDocumentationField('deprecated'),\n format: addPropTypeDocumentationField('format'),\n signature: addPropTypeDocumentationField('signature'),\n global: addPropTypeDocumentationField('global'),\n omitValidation: addPropTypeDocumentationField('omitValidation'),\n hidden: addPropTypeDocumentationField('hidden'),\n dataTestId: addPropTypeDocumentationField('dataTestId'),\n xstyled: addPropTypeDocumentationField('xstyled'),\n isRequiredIf: addPropTypeDocumentationField('isRequiredIf'),\n};\n\nconst createPropType = (type: PropTypesTypes) => {\n const propTypeObj = {\n type,\n ...documentedPropType,\n };\n Object.defineProperty(propTypeObj, 'isRequired', {\n get: function getRequired(this: DocumentedPropType) {\n if (!this.reactDesc) {\n this.reactDesc = {};\n }\n this.reactDesc.required = true;\n return this;\n },\n enumerable: true,\n configurable: true,\n });\n\n return propTypeObj;\n};\n\nconst createPropTypeWithArgs = (type: PropTypesTypes) => (args: unknown) => {\n const propTypeObj = {\n args,\n type,\n ...documentedPropType,\n };\n Object.defineProperty(propTypeObj, 'isRequired', {\n get: function getRequired(this: DocumentedPropType) {\n if (!this.reactDesc) {\n this.reactDesc = {};\n }\n this.reactDesc.required = true;\n return this;\n },\n enumerable: true,\n configurable: true,\n });\n return propTypeObj;\n};\n\nconst PropTypes = {\n custom: (callback: CallableFunction) => {\n const target = callback.bind(null) as CallableFunction & DocumentedPropType;\n target.type = 'func';\n Object.keys(documentedPropType).forEach((fieldName) => {\n const fieldNameCasted = fieldName as keyof DocumentedPropType;\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (target[fieldNameCasted] as unknown) = documentedPropType[fieldNameCasted] as unknown;\n });\n return target;\n },\n} as unknown as PropTypesObj;\n\nfunction definePropType(type: PropTypesTypes) {\n Object.defineProperty(PropTypes, type, {\n get: function getPropType() {\n return createPropType(type);\n },\n enumerable: true,\n configurable: true,\n });\n}\n\nfunction definePropTypeWithArgs(type: PropTypesTypes) {\n Object.defineProperty(PropTypes, type, {\n get: function getPropType() {\n return createPropTypeWithArgs(type);\n },\n enumerable: true,\n configurable: true,\n });\n}\n\ndefinePropType('any');\ndefinePropType('array');\ndefinePropType('bool');\ndefinePropType('element');\ndefinePropType('func');\ndefinePropType('node');\ndefinePropType('number');\ndefinePropType('object');\ndefinePropType('symbol');\ndefinePropType('string');\n\ndefinePropTypeWithArgs('arrayOf');\ndefinePropTypeWithArgs('instanceOf');\ndefinePropTypeWithArgs('objectOf');\ndefinePropTypeWithArgs('oneOfType');\ndefinePropTypeWithArgs('oneOf');\ndefinePropTypeWithArgs('shape');\ndefinePropTypeWithArgs('tuple');\n\nexport default PropTypes;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,MAAM,gCAAgC,CAAgC,cACpE,SAAS,oBAA8C,OAA6C;AAClG,MAAI,CAAC,KAAK,WAAW;AACnB,SAAK,YAAY,CAAC;AAAA,EACpB;AACA,MAAI,YAAY;AAChB,MACE,cAAc,YACd,cAAc,gBACd,cAAc,YACd,cAAc,aACd,cAAc;AAEd,gBAAY;AAEd,OAAK,UAAU,SAAS,IAAI;AAC5B,SAAO;AACT;AAEF,MAAM,qBAAoF;AAAA,EACxF,cAAc,8BAA8B,cAAc;AAAA,EAC1D,aAAa,8BAA8B,aAAa;AAAA,EACxD,YAAY,8BAA8B,YAAY;AAAA,EACtD,QAAQ,8BAA8B,QAAQ;AAAA,EAC9C,WAAW,8BAA8B,WAAW;AAAA,EACpD,QAAQ,8BAA8B,QAAQ;AAAA,EAC9C,gBAAgB,8BAA8B,gBAAgB;AAAA,EAC9D,QAAQ,8BAA8B,QAAQ;AAAA,EAC9C,YAAY,8BAA8B,YAAY;AAAA,EACtD,SAAS,8BAA8B,SAA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,WAAW,MAAM;AAAA,IACrC,KAAK,SAAS,cAAc;AAC1B,aAAO,uBAAuB,IAAI;AAAA,IACpC;AAAA,IACA,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB,CAAC;AACH;AAEA,eAAe,KAAK;AACpB,eAAe,OAAO;AACtB,eAAe,MAAM;AACrB,eAAe,SAAS;AACxB,eAAe,MAAM;AACrB,eAAe,MAAM;AACrB,eAAe,QAAQ;AACvB,eAAe,QAAQ;AACvB,eAAe,QAAQ;AACvB,eAAe,QAAQ;AAEvB,uBAAuB,SAAS;AAChC,uBAAuB,YAAY;AACnC,uBAAuB,UAAU;AACjC,uBAAuB,WAAW;AAClC,uBAAuB,OAAO;AAC9B,uBAAuB,OAAO;AAC9B,uBAAuB,OAAO;AAE9B,IAAO,oBAAQ;",
|
|
4
|
+
"sourcesContent": ["import type { PropTypesTypes, DocumentedPropType, ReactDescObjT, PropTypesObj } from './types.js';\n\nconst addPropTypeDocumentationField = <T extends keyof ReactDescObjT>(fieldName: T) =>\n function addFieldToReactDesc(this: DocumentedPropType, value: ReactDescObjT[T]): DocumentedPropType {\n if (!this.reactDesc) {\n this.reactDesc = {};\n }\n let realValue = value;\n if (\n fieldName === 'global' ||\n fieldName === 'dataTestId' ||\n fieldName === 'hidden' ||\n fieldName === 'xstyled' ||\n fieldName === 'omitValidation'\n )\n realValue = true;\n\n this.reactDesc[fieldName] = realValue;\n return this;\n };\n\nconst documentedPropType: Omit<DocumentedPropType, 'type' | 'isRequired' | 'reactDesc'> = {\n defaultValue: addPropTypeDocumentationField('defaultValue'),\n description: addPropTypeDocumentationField('description'),\n deprecated: addPropTypeDocumentationField('deprecated'),\n format: addPropTypeDocumentationField('format'),\n signature: addPropTypeDocumentationField('signature'),\n global: addPropTypeDocumentationField('global'),\n omitValidation: addPropTypeDocumentationField('omitValidation'),\n hidden: addPropTypeDocumentationField('hidden'),\n dataTestId: addPropTypeDocumentationField('dataTestId'),\n xstyled: addPropTypeDocumentationField('xstyled'),\n isRequiredIf: addPropTypeDocumentationField('isRequiredIf'),\n};\n\nconst createPropType = (type: PropTypesTypes) => {\n const propTypeObj = {\n type,\n ...documentedPropType,\n };\n Object.defineProperty(propTypeObj, 'isRequired', {\n get: function getRequired(this: DocumentedPropType) {\n if (!this.reactDesc) {\n this.reactDesc = {};\n }\n this.reactDesc.required = true;\n return this;\n },\n enumerable: true,\n configurable: true,\n });\n\n return propTypeObj;\n};\n\nconst createPropTypeWithArgs = (type: PropTypesTypes) => (args: unknown) => {\n const propTypeObj = {\n args,\n type,\n ...documentedPropType,\n };\n Object.defineProperty(propTypeObj, 'isRequired', {\n get: function getRequired(this: DocumentedPropType) {\n if (!this.reactDesc) {\n this.reactDesc = {};\n }\n this.reactDesc.required = true;\n return this;\n },\n enumerable: true,\n configurable: true,\n });\n return propTypeObj;\n};\n\nconst PropTypes = {\n custom: (callback: CallableFunction) => {\n const target = callback.bind(null) as CallableFunction & DocumentedPropType;\n target.type = 'func';\n Object.keys(documentedPropType).forEach((fieldName) => {\n const fieldNameCasted = fieldName as keyof DocumentedPropType;\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (target[fieldNameCasted] as unknown) = documentedPropType[fieldNameCasted] as unknown;\n });\n return target;\n },\n} as unknown as PropTypesObj;\n\nfunction definePropType(type: PropTypesTypes) {\n Object.defineProperty(PropTypes, type, {\n get: function getPropType() {\n return createPropType(type);\n },\n enumerable: true,\n configurable: true,\n });\n}\n\nfunction definePropTypeWithArgs(type: PropTypesTypes) {\n Object.defineProperty(PropTypes, type, {\n get: function getPropType() {\n return createPropTypeWithArgs(type);\n },\n enumerable: true,\n configurable: true,\n });\n}\n\ndefinePropType('any');\ndefinePropType('array');\ndefinePropType('bool');\ndefinePropType('element');\ndefinePropType('elementType');\ndefinePropType('func');\ndefinePropType('node');\ndefinePropType('number');\ndefinePropType('object');\ndefinePropType('symbol');\ndefinePropType('string');\n\ndefinePropTypeWithArgs('arrayOf');\ndefinePropTypeWithArgs('instanceOf');\ndefinePropTypeWithArgs('objectOf');\ndefinePropTypeWithArgs('oneOfType');\ndefinePropTypeWithArgs('oneOf');\ndefinePropTypeWithArgs('shape');\ndefinePropTypeWithArgs('tuple');\n\nexport default PropTypes;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEvB,MAAM,gCAAgC,CAAgC,cACpE,SAAS,oBAA8C,OAA6C;AAClG,MAAI,CAAC,KAAK,WAAW;AACnB,SAAK,YAAY,CAAC;AAAA,EACpB;AACA,MAAI,YAAY;AAChB,MACE,cAAc,YACd,cAAc,gBACd,cAAc,YACd,cAAc,aACd,cAAc;AAEd,gBAAY;AAEd,OAAK,UAAU,SAAS,IAAI;AAC5B,SAAO;AACT;AAEF,MAAM,qBAAoF;AAAA,EACxF,cAAc,8BAA8B,cAAc;AAAA,EAC1D,aAAa,8BAA8B,aAAa;AAAA,EACxD,YAAY,8BAA8B,YAAY;AAAA,EACtD,QAAQ,8BAA8B,QAAQ;AAAA,EAC9C,WAAW,8BAA8B,WAAW;AAAA,EACpD,QAAQ,8BAA8B,QAAQ;AAAA,EAC9C,gBAAgB,8BAA8B,gBAAgB;AAAA,EAC9D,QAAQ,8BAA8B,QAAQ;AAAA,EAC9C,YAAY,8BAA8B,YAAY;AAAA,EACtD,SAAS,8BAA8B,SAAS;AAAA,EAChD,cAAc,8BAA8B,cAAc;AAC5D;AAEA,MAAM,iBAAiB,CAAC,SAAyB;AAC/C,QAAM,cAAc;AAAA,IAClB;AAAA,IACA,GAAG;AAAA,EACL;AACA,SAAO,eAAe,aAAa,cAAc;AAAA,IAC/C,KAAK,SAAS,cAAsC;AAClD,UAAI,CAAC,KAAK,WAAW;AACnB,aAAK,YAAY,CAAC;AAAA,MACpB;AACA,WAAK,UAAU,WAAW;AAC1B,aAAO;AAAA,IACT;AAAA,IACA,YAAY;AAAA,IACZ,cAAc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;AAEvB,uBAAuB,SAAS;AAChC,uBAAuB,YAAY;AACnC,uBAAuB,UAAU;AACjC,uBAAuB,WAAW;AAClC,uBAAuB,OAAO;AAC9B,uBAAuB,OAAO;AAC9B,uBAAuB,OAAO;AAE9B,IAAO,oBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -45,7 +45,8 @@ const shapeFormat = (shape) => {
|
|
|
45
45
|
} else {
|
|
46
46
|
valueFormat = propTypeFormat(value);
|
|
47
47
|
}
|
|
48
|
-
|
|
48
|
+
const deprecatedMarker = value.reactDesc?.deprecated ? `/** @deprecated v${value.reactDesc.deprecated.version} */ ` : "";
|
|
49
|
+
return `${deprecatedMarker}${key}${value.reactDesc && value.reactDesc.required ? "" : "?"}: ${valueFormat}`;
|
|
49
50
|
});
|
|
50
51
|
return `{${props.join(",")}}`;
|
|
51
52
|
};
|
|
@@ -80,6 +81,9 @@ const propTypeFormat = (propType, joinWith = "") => {
|
|
|
80
81
|
case "element":
|
|
81
82
|
result = "JSX.Element";
|
|
82
83
|
break;
|
|
84
|
+
case "elementType":
|
|
85
|
+
result = "React.ComponentType<Record<string,unknown>>";
|
|
86
|
+
break;
|
|
83
87
|
case "instanceOf":
|
|
84
88
|
result = "any";
|
|
85
89
|
break;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/propTypes/toTypescript.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable @typescript-eslint/restrict-template-expressions */\n/* eslint-disable @typescript-eslint/no-use-before-define */\n/* eslint-disable complexity */\n/* eslint-disable react/forbid-foreign-prop-types */\nimport type React from 'react';\nimport type { ComponentDocumentation, Hook, ReactDescT, TypescriptDocumentation } from './types.js';\nimport { isReactDesc } from './describeGuards.js';\n\nconst arrayFormat = (array: ReactDescT[]) => array.map((propType) => propTypeFormat(propType));\n\nconst shapeFormat = (shape: Record<string, ReactDescT>) => {\n const props = Object.keys(shape).map((key) => {\n const value = shape[key];\n let valueFormat;\n if (\n value.type &&\n (value.type === 'arrayOf' || value.type === 'oneOfType' || value.type === 'oneOf') &&\n Array.isArray(value.args)\n ) {\n valueFormat = `${propTypeFormat(value)}`;\n } else if (value.type === 'shape') {\n valueFormat = `${propTypeFormat(value)}`;\n } else {\n valueFormat = propTypeFormat(value);\n }\n return `${key}${value.reactDesc && value.reactDesc.required ? '' : '?'}: ${valueFormat}`;\n });\n return `{${props.join(',')}}`;\n};\n\nconst propTypeFormat = (propType: ReactDescT | ReactDescT[], joinWith = ''): string => {\n let result;\n if (Array.isArray(propType)) {\n result = arrayFormat(propType).join(joinWith);\n } else if (typeof propType !== 'function' && propType.type) {\n switch (propType.type) {\n case 'array':\n result = 'any[]';\n break;\n case 'arrayOf':\n if ((propType.args as ReactDescT).type === 'oneOfType') {\n result = `(${propTypeFormat(propType.args as ReactDescT, ' | ')})[]`;\n } else {\n result = `${propTypeFormat(propType.args as ReactDescT, '\\n')}[]`;\n }\n break;\n case 'tuple':\n result = `[${propTypeFormat(propType.args as ReactDescT, ', ')}]`;\n break;\n case 'bool':\n result = 'boolean';\n break;\n case 'func':\n result = propType?.reactDesc?.signature ?? '((...args: any[]) => any)';\n break;\n case 'node':\n result = 'React.ReactNode';\n break;\n case 'element':\n result = 'JSX.Element';\n break;\n case 'instanceOf':\n result = 'any';\n break;\n case 'symbol':\n result = 'any';\n break;\n case 'objectOf':\n result = `{ [key: string]: ${propTypeFormat(propType.args as ReactDescT)} }`;\n break;\n case 'oneOf':\n result = (propType.args as unknown[]).map((a) => `\"${a}\"`).join(' | ');\n break;\n case 'oneOfType':\n result = `${propTypeFormat(propType.args as ReactDescT[], ' | ')}`;\n break;\n case 'shape':\n result = `${shapeFormat(propType.args as Record<string, ReactDescT>)}`;\n break;\n default:\n result = `${propType.type}`;\n break;\n }\n } else {\n result = 'any';\n }\n return result;\n};\n\nconst propTypeAsTypescript = (propType: ReactDescT, propName: string) => {\n const documentation = {\n ...propType.reactDesc,\n name: propName,\n };\n\n documentation.format = propTypeFormat(propType);\n\n return documentation;\n};\n\nexport default function descToTypescript<C, R>(\n component: React.ComponentType<C> | Hook<C, R>,\n reactDesc: ComponentDocumentation,\n) {\n if (!component) {\n throw new Error('react-desc: component is required');\n }\n\n const documentation: Partial<TypescriptDocumentation> = {\n name: component.displayName || component.name,\n ...reactDesc,\n };\n if (reactDesc) {\n delete documentation.propTypes;\n\n if (reactDesc.propTypes) {\n const propTypes: TypescriptDocumentation['properties'] = [];\n Object.keys(reactDesc.propTypes).forEach((propName) => {\n const propType = reactDesc.propTypes[propName];\n if (propType.type === 'shape') {\n propType.reactDesc.group = {};\n\n Object.keys(propType.args as Record<string, ReactDescT>).forEach((prop) => {\n if (!propType.reactDesc.group) return;\n propType.reactDesc.group[prop] = propTypeAsTypescript(\n (propType.args as Record<string, ReactDescT>)[prop],\n prop,\n );\n });\n }\n propTypes.push(propTypeAsTypescript(propType, propName));\n });\n if (propTypes.length > 0) {\n documentation.properties = propTypes;\n }\n }\n if (reactDesc.returnType) {\n if (isReactDesc(reactDesc.returnType)) {\n documentation.returns = propTypeAsTypescript(reactDesc.returnType, 'returns');\n } else {\n documentation.returns = Object.entries(reactDesc.returnType).map(([propName, propType]) =>\n propTypeAsTypescript(propType, propName),\n );\n }\n }\n }\n return documentation as TypescriptDocumentation;\n}\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADMvB,4BAA4B;AAE5B,MAAM,cAAc,CAAC,UAAwB,MAAM,IAAI,CAAC,aAAa,eAAe,QAAQ,CAAC;AAE7F,MAAM,cAAc,CAAC,UAAsC;AACzD,QAAM,QAAQ,OAAO,KAAK,KAAK,EAAE,IAAI,CAAC,QAAQ;AAC5C,UAAM,QAAQ,MAAM,GAAG;AACvB,QAAI;AACJ,QACE,MAAM,SACL,MAAM,SAAS,aAAa,MAAM,SAAS,eAAe,MAAM,SAAS,YAC1E,MAAM,QAAQ,MAAM,IAAI,GACxB;AACA,oBAAc,GAAG,eAAe,KAAK,CAAC;AAAA,IACxC,WAAW,MAAM,SAAS,SAAS;AACjC,oBAAc,GAAG,eAAe,KAAK,CAAC;AAAA,IACxC,OAAO;AACL,oBAAc,eAAe,KAAK;AAAA,IACpC;AACA,WAAO,GAAG,GAAG,GAAG,MAAM,aAAa,MAAM,UAAU,WAAW,KAAK,GAAG,KAAK,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable @typescript-eslint/restrict-template-expressions */\n/* eslint-disable @typescript-eslint/no-use-before-define */\n/* eslint-disable complexity */\n/* eslint-disable react/forbid-foreign-prop-types */\nimport type React from 'react';\nimport type { ComponentDocumentation, Hook, ReactDescT, TypescriptDocumentation } from './types.js';\nimport { isReactDesc } from './describeGuards.js';\n\nconst arrayFormat = (array: ReactDescT[]) => array.map((propType) => propTypeFormat(propType));\n\nconst shapeFormat = (shape: Record<string, ReactDescT>) => {\n const props = Object.keys(shape).map((key) => {\n const value = shape[key];\n let valueFormat;\n if (\n value.type &&\n (value.type === 'arrayOf' || value.type === 'oneOfType' || value.type === 'oneOf') &&\n Array.isArray(value.args)\n ) {\n valueFormat = `${propTypeFormat(value)}`;\n } else if (value.type === 'shape') {\n valueFormat = `${propTypeFormat(value)}`;\n } else {\n valueFormat = propTypeFormat(value);\n }\n const deprecatedMarker = value.reactDesc?.deprecated\n ? `/** @deprecated v${value.reactDesc.deprecated.version} */ `\n : '';\n return `${deprecatedMarker}${key}${value.reactDesc && value.reactDesc.required ? '' : '?'}: ${valueFormat}`;\n });\n return `{${props.join(',')}}`;\n};\n\nconst propTypeFormat = (propType: ReactDescT | ReactDescT[], joinWith = ''): string => {\n let result;\n if (Array.isArray(propType)) {\n result = arrayFormat(propType).join(joinWith);\n } else if (typeof propType !== 'function' && propType.type) {\n switch (propType.type) {\n case 'array':\n result = 'any[]';\n break;\n case 'arrayOf':\n if ((propType.args as ReactDescT).type === 'oneOfType') {\n result = `(${propTypeFormat(propType.args as ReactDescT, ' | ')})[]`;\n } else {\n result = `${propTypeFormat(propType.args as ReactDescT, '\\n')}[]`;\n }\n break;\n case 'tuple':\n result = `[${propTypeFormat(propType.args as ReactDescT, ', ')}]`;\n break;\n case 'bool':\n result = 'boolean';\n break;\n case 'func':\n result = propType?.reactDesc?.signature ?? '((...args: any[]) => any)';\n break;\n case 'node':\n result = 'React.ReactNode';\n break;\n case 'element':\n result = 'JSX.Element';\n break;\n case 'elementType':\n result = 'React.ComponentType<Record<string,unknown>>';\n break;\n case 'instanceOf':\n result = 'any';\n break;\n case 'symbol':\n result = 'any';\n break;\n case 'objectOf':\n result = `{ [key: string]: ${propTypeFormat(propType.args as ReactDescT)} }`;\n break;\n case 'oneOf':\n result = (propType.args as unknown[]).map((a) => `\"${a}\"`).join(' | ');\n break;\n case 'oneOfType':\n result = `${propTypeFormat(propType.args as ReactDescT[], ' | ')}`;\n break;\n case 'shape':\n result = `${shapeFormat(propType.args as Record<string, ReactDescT>)}`;\n break;\n default:\n result = `${propType.type}`;\n break;\n }\n } else {\n result = 'any';\n }\n return result;\n};\n\nconst propTypeAsTypescript = (propType: ReactDescT, propName: string) => {\n const documentation = {\n ...propType.reactDesc,\n name: propName,\n };\n\n documentation.format = propTypeFormat(propType);\n\n return documentation;\n};\n\nexport default function descToTypescript<C, R>(\n component: React.ComponentType<C> | Hook<C, R>,\n reactDesc: ComponentDocumentation,\n) {\n if (!component) {\n throw new Error('react-desc: component is required');\n }\n\n const documentation: Partial<TypescriptDocumentation> = {\n name: component.displayName || component.name,\n ...reactDesc,\n };\n if (reactDesc) {\n delete documentation.propTypes;\n\n if (reactDesc.propTypes) {\n const propTypes: TypescriptDocumentation['properties'] = [];\n Object.keys(reactDesc.propTypes).forEach((propName) => {\n const propType = reactDesc.propTypes[propName];\n if (propType.type === 'shape') {\n propType.reactDesc.group = {};\n\n Object.keys(propType.args as Record<string, ReactDescT>).forEach((prop) => {\n if (!propType.reactDesc.group) return;\n propType.reactDesc.group[prop] = propTypeAsTypescript(\n (propType.args as Record<string, ReactDescT>)[prop],\n prop,\n );\n });\n }\n propTypes.push(propTypeAsTypescript(propType, propName));\n });\n if (propTypes.length > 0) {\n documentation.properties = propTypes;\n }\n }\n if (reactDesc.returnType) {\n if (isReactDesc(reactDesc.returnType)) {\n documentation.returns = propTypeAsTypescript(reactDesc.returnType, 'returns');\n } else {\n documentation.returns = Object.entries(reactDesc.returnType).map(([propName, propType]) =>\n propTypeAsTypescript(propType, propName),\n );\n }\n }\n }\n return documentation as TypescriptDocumentation;\n}\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADMvB,4BAA4B;AAE5B,MAAM,cAAc,CAAC,UAAwB,MAAM,IAAI,CAAC,aAAa,eAAe,QAAQ,CAAC;AAE7F,MAAM,cAAc,CAAC,UAAsC;AACzD,QAAM,QAAQ,OAAO,KAAK,KAAK,EAAE,IAAI,CAAC,QAAQ;AAC5C,UAAM,QAAQ,MAAM,GAAG;AACvB,QAAI;AACJ,QACE,MAAM,SACL,MAAM,SAAS,aAAa,MAAM,SAAS,eAAe,MAAM,SAAS,YAC1E,MAAM,QAAQ,MAAM,IAAI,GACxB;AACA,oBAAc,GAAG,eAAe,KAAK,CAAC;AAAA,IACxC,WAAW,MAAM,SAAS,SAAS;AACjC,oBAAc,GAAG,eAAe,KAAK,CAAC;AAAA,IACxC,OAAO;AACL,oBAAc,eAAe,KAAK;AAAA,IACpC;AACA,UAAM,mBAAmB,MAAM,WAAW,aACtC,oBAAoB,MAAM,UAAU,WAAW,OAAO,SACtD;AACJ,WAAO,GAAG,gBAAgB,GAAG,GAAG,GAAG,MAAM,aAAa,MAAM,UAAU,WAAW,KAAK,GAAG,KAAK,WAAW;AAA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,IACF;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -36,6 +36,6 @@ var import_react = require("react");
|
|
|
36
36
|
const useOwnerProps = (props, args) => {
|
|
37
37
|
const getOwnerProps = (0, import_react.useCallback)(() => props, [props]);
|
|
38
38
|
const getOwnerPropsArguments = (0, import_react.useCallback)(() => args ?? {}, [args]);
|
|
39
|
-
return { getOwnerProps, getOwnerPropsArguments };
|
|
39
|
+
return (0, import_react.useMemo)(() => ({ getOwnerProps, getOwnerPropsArguments }), [getOwnerProps, getOwnerPropsArguments]);
|
|
40
40
|
};
|
|
41
41
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/useOwnerProps/index.tsx", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import { useCallback } from 'react';\n\nexport const useOwnerProps = <P, A extends object = Record<string, never>>(props: P, args?: A) => {\n const getOwnerProps = useCallback(() => props, [props]);\n const getOwnerPropsArguments = useCallback(() => args ?? {}, [args]);\n return { getOwnerProps, getOwnerPropsArguments };\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,
|
|
4
|
+
"sourcesContent": ["import { useCallback, useMemo } from 'react';\n\nexport const useOwnerProps = <P, A extends object = Record<string, never>>(props: P, args?: A) => {\n const getOwnerProps = useCallback(() => props, [props]);\n const getOwnerPropsArguments = useCallback(() => args ?? {}, [args]);\n return useMemo(() => ({ getOwnerProps, getOwnerPropsArguments }), [getOwnerProps, getOwnerPropsArguments]);\n};\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAqC;AAE9B,MAAM,gBAAgB,CAA8C,OAAU,SAAa;AAChG,QAAM,oBAAgB,0BAAY,MAAM,OAAO,CAAC,KAAK,CAAC;AACtD,QAAM,6BAAyB,0BAAY,MAAM,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;AACnE,aAAO,sBAAQ,OAAO,EAAE,eAAe,uBAAuB,IAAI,CAAC,eAAe,sBAAsB,CAAC;AAC3G;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -35,6 +35,7 @@ __export(typescriptGuards_exports, {
|
|
|
35
35
|
isObject: () => isObject,
|
|
36
36
|
isObjectOf: () => isObjectOf,
|
|
37
37
|
isPrimitiveType: () => isPrimitiveType,
|
|
38
|
+
isReactComponentType: () => isReactComponentType,
|
|
38
39
|
isSomethingWithParenthesis: () => isSomethingWithParenthesis,
|
|
39
40
|
isString: () => isString,
|
|
40
41
|
isUndefined: () => isUndefined,
|
|
@@ -75,5 +76,6 @@ const isFunction = (format) => {
|
|
|
75
76
|
return arrowOccursAtDepth1;
|
|
76
77
|
};
|
|
77
78
|
const isJSXorNode = (format) => !isUnion(format) && ["React.ReactNode", "JSX.Element"].includes(format);
|
|
79
|
+
const isReactComponentType = (format) => !isUnion(format) && format === "React.ComponentType<Record<string,unknown>>";
|
|
78
80
|
const isSomethingWithParenthesis = (format) => !isUnion(format) && format[0] === "(" && format.slice(-1) === ")";
|
|
79
81
|
//# sourceMappingURL=typescriptGuards.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/validation/typescriptGuards.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["type GuardFn = (format: string) => boolean;\n\nexport const isPrimitiveType: GuardFn = (format) => ['string', 'number', 'boolean'].includes(format);\nexport const isUndefined: GuardFn = (format) => format === '\"undefined\"';\nexport const isNull: GuardFn = (format) => format === '\"null\"';\nexport const isUnion: GuardFn = (format) => {\n let depth = 0;\n let satisfies = false;\n format.split('').forEach((char) => {\n if (['{', '('].includes(char)) depth += 1;\n else if (['}', ')'].includes(char)) depth -= 1;\n else if (char === '|' && depth === 0) satisfies = true;\n });\n return satisfies;\n};\n\nexport const isString: GuardFn = (format) => !isUnion(format) && format[0] === '\"' && format.slice(-1) === '\"';\n\nexport const isArray: GuardFn = (format) => !isUnion(format) && format.slice(-2) === '[]';\n\nexport const isObjectOf: GuardFn = (format) =>\n format !== 'object' && !isUnion(format) && format.startsWith('{ [key: string]: ');\n\nexport const isObject: GuardFn = (format) =>\n format === 'object' || (!isUnion(format) && format[0] === '{' && format.slice(-1) === '}');\n\nexport const isFunction: GuardFn = (format) => {\n // It's isn't an union\n if (isUnion(format)) return false;\n // Has to start with (( and end with )\n if (!format.startsWith('((') && format.slice(-1) !== ')') return false;\n\n // The arrow MUST occur at depth 1 (when couting parenthesis)\n // Otherwise the only possibility is that we have \"something with parenthesis\" (look down below)\n let depth = 0;\n let arrowOccursAtDepth1 = false;\n for (let i = 0; i < format.length; i += 1) {\n const char = format[i];\n if (['{', '('].includes(char)) depth += 1;\n else if (['}', ')'].includes(char)) depth -= 1;\n else if (i < format.length - 1 && format.slice(i, i + 2) === '=>') {\n arrowOccursAtDepth1 = arrowOccursAtDepth1 || depth === 1;\n }\n }\n return arrowOccursAtDepth1;\n};\n\nexport const isJSXorNode: GuardFn = (format) => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);\n\nexport const isSomethingWithParenthesis: GuardFn = (format) =>\n !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEhB,MAAM,kBAA2B,CAAC,WAAW,CAAC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ACpC,IAAI,OAAO,SAAS,KAAK,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM,MAAM;AACjE,4BAAsB,uBAAuB,UAAU;AAAA,IACzD;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,cAAuB,CAAC,WAAW,CAAC,QAAQ,MAAM,KAAK,CAAC,mBAAmB,aAAa,EAAE,SAAS,MAAM;AAE/G,MAAM,6BAAsC,CAAC,WAClD,CAAC,QAAQ,MAAM,KAAK,OAAO,CAAC,MAAM,OAAO,OAAO,MAAM,EAAE,MAAM;",
|
|
4
|
+
"sourcesContent": ["type GuardFn = (format: string) => boolean;\n\nexport const isPrimitiveType: GuardFn = (format) => ['string', 'number', 'boolean'].includes(format);\nexport const isUndefined: GuardFn = (format) => format === '\"undefined\"';\nexport const isNull: GuardFn = (format) => format === '\"null\"';\nexport const isUnion: GuardFn = (format) => {\n let depth = 0;\n let satisfies = false;\n format.split('').forEach((char) => {\n if (['{', '('].includes(char)) depth += 1;\n else if (['}', ')'].includes(char)) depth -= 1;\n else if (char === '|' && depth === 0) satisfies = true;\n });\n return satisfies;\n};\n\nexport const isString: GuardFn = (format) => !isUnion(format) && format[0] === '\"' && format.slice(-1) === '\"';\n\nexport const isArray: GuardFn = (format) => !isUnion(format) && format.slice(-2) === '[]';\n\nexport const isObjectOf: GuardFn = (format) =>\n format !== 'object' && !isUnion(format) && format.startsWith('{ [key: string]: ');\n\nexport const isObject: GuardFn = (format) =>\n format === 'object' || (!isUnion(format) && format[0] === '{' && format.slice(-1) === '}');\n\nexport const isFunction: GuardFn = (format) => {\n // It's isn't an union\n if (isUnion(format)) return false;\n // Has to start with (( and end with )\n if (!format.startsWith('((') && format.slice(-1) !== ')') return false;\n\n // The arrow MUST occur at depth 1 (when couting parenthesis)\n // Otherwise the only possibility is that we have \"something with parenthesis\" (look down below)\n let depth = 0;\n let arrowOccursAtDepth1 = false;\n for (let i = 0; i < format.length; i += 1) {\n const char = format[i];\n if (['{', '('].includes(char)) depth += 1;\n else if (['}', ')'].includes(char)) depth -= 1;\n else if (i < format.length - 1 && format.slice(i, i + 2) === '=>') {\n arrowOccursAtDepth1 = arrowOccursAtDepth1 || depth === 1;\n }\n }\n return arrowOccursAtDepth1;\n};\n\nexport const isJSXorNode: GuardFn = (format) => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);\n\nexport const isReactComponentType: GuardFn = (format) =>\n !isUnion(format) && format === 'React.ComponentType<Record<string,unknown>>';\n\nexport const isSomethingWithParenthesis: GuardFn = (format) =>\n !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADEhB,MAAM,kBAA2B,CAAC,WAAW,CAAC,UAAU,UAAU,SAAS,EAAE,SAAS,MAAM;AAC5F,MAAM,cAAuB,CAAC,WAAW,WAAW;AACpD,MAAM,SAAkB,CAAC,WAAW,WAAW;AAC/C,MAAM,UAAmB,CAAC,WAAW;AAC1C,MAAI,QAAQ;AACZ,MAAI,YAAY;AAChB,SAAO,MAAM,EAAE,EAAE,QAAQ,CAAC,SAAS;AACjC,QAAI,CAAC,KAAK,GAAG,EAAE,SAAS,IAAI,EAAG,UAAS;AAAA,aAC/B,CAAC,KAAK,GAAG,EAAE,SAAS,IAAI,EAAG,UAAS;AAAA,aACpC,SAAS,OAAO,UAAU,EAAG,aAAY;AAAA,EACpD,CAAC;AACD,SAAO;AACT;AAEO,MAAM,WAAoB,CAAC,WAAW,CAAC,QAAQ,MAAM,KAAK,OAAO,CAAC,MAAM,OAAO,OAAO,MAAM,EAAE,MAAM;AAEpG,MAAM,UAAmB,CAAC,WAAW,CAAC,QAAQ,MAAM,KAAK,OAAO,MAAM,EAAE,MAAM;AAE9E,MAAM,aAAsB,CAAC,WAClC,WAAW,YAAY,CAAC,QAAQ,MAAM,KAAK,OAAO,WAAW,mBAAmB;AAE3E,MAAM,WAAoB,CAAC,WAChC,WAAW,YAAa,CAAC,QAAQ,MAAM,KAAK,OAAO,CAAC,MAAM,OAAO,OAAO,MAAM,EAAE,MAAM;AAEjF,MAAM,aAAsB,CAAC,WAAW;AAE7C,MAAI,QAAQ,MAAM,EAAG,QAAO;AAE5B,MAAI,CAAC,OAAO,WAAW,IAAI,KAAK,OAAO,MAAM,EAAE,MAAM,IAAK,QAAO;AAIjE,MAAI,QAAQ;AACZ,MAAI,sBAAsB;AAC1B,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;AACzC,UAAM,OAAO,OAAO,CAAC;AACrB,QAAI,CAAC,KAAK,GAAG,EAAE,SAAS,IAAI,EAAG,UAAS;AAAA,aAC/B,CAAC,KAAK,GAAG,EAAE,SAAS,IAAI,EAAG,UAAS;AAAA,aACpC,IAAI,OAAO,SAAS,KAAK,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM,MAAM;AACjE,4BAAsB,uBAAuB,UAAU;AAAA,IACzD;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,cAAuB,CAAC,WAAW,CAAC,QAAQ,MAAM,KAAK,CAAC,mBAAmB,aAAa,EAAE,SAAS,MAAM;AAE/G,MAAM,uBAAgC,CAAC,WAC5C,CAAC,QAAQ,MAAM,KAAK,WAAW;AAE1B,MAAM,6BAAsC,CAAC,WAClD,CAAC,QAAQ,MAAM,KAAK,OAAO,CAAC,MAAM,OAAO,OAAO,MAAM,EAAE,MAAM;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -170,6 +170,8 @@ const validateValueWithFormat = (schemaName, key, value, format, validationsMemo
|
|
|
170
170
|
validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
171
171
|
} else if ((0, import_typescriptGuards.isFunction)(format)) {
|
|
172
172
|
validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
173
|
+
} else if ((0, import_typescriptGuards.isReactComponentType)(format)) {
|
|
174
|
+
validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
173
175
|
} else if ((0, import_typescriptGuards.isJSXorNode)(format)) {
|
|
174
176
|
validateJSXorNode(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
175
177
|
} else if ((0, import_typescriptGuards.isSomethingWithParenthesis)(format)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 type { PropsWithChildren, WeakValidationMap } from 'react';\nimport { useMemo, useRef } from 'react';\nimport type { TypescriptDocumentation } from '../propTypes/types.js';\nimport { describe } from '../propTypes/index.js';\nimport { throwRequiredError, throwTypeError } from './errorTemplates.js';\nimport {\n isArray,\n isFunction,\n isJSXorNode,\n isObject,\n isPrimitiveType,\n isSomethingWithParenthesis,\n isString,\n isUnion,\n isUndefined,\n isNull,\n isObjectOf,\n} from './typescriptGuards.js';\nimport { typescriptObjectParser } from './typescriptParsers.js';\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): value is Record<string, unknown> {\n return !(typeof value !== 'object' || Array.isArray(value));\n}\n\nconst validateObjectOf: 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 const valuesFormat = format.slice('{ [key: string]: '.length, -2);\n\n Object.keys(value).forEach((objectKey) => {\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}[${objectKey}]`,\n value[objectKey],\n valuesFormat,\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\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, trueKey);\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): 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 (isObjectOf(format)) {\n validateObjectOf(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: TypescriptDocumentation,\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, isRequiredIf, omitValidation } = property;\n\n const requiredConditionally = isRequiredIf && isRequiredIf(props);\n\n if (omitValidation) {\n return;\n }\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (requiredConditionally && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n const shouldValidateProperty = props[name] !== undefined || required || requiredConditionally;\n\n if (name in props && format && shouldValidateProperty) {\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 propTypes: WeakValidationMap<unknown>,\n componentDisplayName: string,\n): void => {\n if (!componentDisplayName) {\n throw new Error('Provide display name for the component to use for validation');\n }\n\n const validationsMemo = useRef<Record<string, string>>({});\n\n const typescriptSchema = useMemo(() => {\n const Component = () => {};\n\n const DescribedComponent = describe(Component);\n DescribedComponent.propTypes = propTypes;\n DescribedComponent.displayName = componentDisplayName;\n return DescribedComponent.toTypescript();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [propTypes]);\n\n useMemo(() => {\n const nextValidationsMemo = {};\n\n validateTypescriptPropTypesImplementation(props, typescriptSchema, validationsMemo.current, nextValidationsMemo);\n validationsMemo.current = nextValidationsMemo;\n return 'WE DONT NEED RETURN just the memo';\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;AAAA;ACAA,YAAuB;ADIvB,mBAAgC;AAEhC,uBAAyB;AACzB,4BAAmD;AACnD,
|
|
4
|
+
"sourcesContent": ["/* eslint-disable complexity */\n/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport type { PropsWithChildren, WeakValidationMap } from 'react';\nimport { useMemo, useRef } from 'react';\nimport type { TypescriptDocumentation } from '../propTypes/types.js';\nimport { describe } from '../propTypes/index.js';\nimport { throwRequiredError, throwTypeError } from './errorTemplates.js';\nimport {\n isArray,\n isFunction,\n isJSXorNode,\n isObject,\n isReactComponentType,\n isPrimitiveType,\n isSomethingWithParenthesis,\n isString,\n isUnion,\n isUndefined,\n isNull,\n isObjectOf,\n} from './typescriptGuards.js';\nimport { typescriptObjectParser } from './typescriptParsers.js';\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): value is Record<string, unknown> {\n return !(typeof value !== 'object' || Array.isArray(value));\n}\n\nconst validateObjectOf: 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 const valuesFormat = format.slice('{ [key: string]: '.length, -2);\n\n Object.keys(value).forEach((objectKey) => {\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}[${objectKey}]`,\n value[objectKey],\n valuesFormat,\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\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, trueKey);\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): 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 (isObjectOf(format)) {\n validateObjectOf(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 (isReactComponentType(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: TypescriptDocumentation,\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, isRequiredIf, omitValidation } = property;\n\n const requiredConditionally = isRequiredIf && isRequiredIf(props);\n\n if (omitValidation) {\n return;\n }\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (requiredConditionally && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n const shouldValidateProperty = props[name] !== undefined || required || requiredConditionally;\n\n if (name in props && format && shouldValidateProperty) {\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 propTypes: WeakValidationMap<unknown>,\n componentDisplayName: string,\n): void => {\n if (!componentDisplayName) {\n throw new Error('Provide display name for the component to use for validation');\n }\n\n const validationsMemo = useRef<Record<string, string>>({});\n\n const typescriptSchema = useMemo(() => {\n const Component = () => {};\n\n const DescribedComponent = describe(Component);\n DescribedComponent.propTypes = propTypes;\n DescribedComponent.displayName = componentDisplayName;\n return DescribedComponent.toTypescript();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [propTypes]);\n\n useMemo(() => {\n const nextValidationsMemo = {};\n\n validateTypescriptPropTypesImplementation(props, typescriptSchema, validationsMemo.current, nextValidationsMemo);\n validationsMemo.current = nextValidationsMemo;\n return 'WE DONT NEED RETURN just the memo';\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;AAAA;ACAA,YAAuB;ADIvB,mBAAgC;AAEhC,uBAAyB;AACzB,4BAAmD;AACnD,8BAaO;AACP,+BAAuC;AAmBvC,MAAM,oBAAiC,CAAC,YAAY,KAAK,OAAO,WAAW;AACzE,MAAI,UAAU,UAAa,UAAU,aAAa;AAChD,8CAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AACA,MAAM,eAA4B,CAAC,YAAY,KAAK,OAAO,WAAW;AACpE,MAAI,UAAU,QAAQ,UAAU,QAAQ;AACtC,8CAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AACA,MAAM,wBAAqC,CAAC,YAAY,KAAK,OAAO,WAAW;AAC7E,MAAI,OAAO,UAAU,QAAQ;AAC3B,8CAAe,Y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BAAgB,SAAS,mBAAmB;AAC/G,oBAAgB,UAAU;AAC1B,WAAO;AAAA,EAET,GAAG,CAAC,KAAK,CAAC;AACZ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/xstyledProps/useGetXstyledProps.tsx", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import { useMemo } from 'react';\nimport type {\n SizingProps,\n SpaceProps,\n LayoutProps,\n BoxShadowProps,\n BorderProps,\n BackgroundProps,\n FontWeightProps,\n TextAlignProps,\n} from '@elliemae/ds-system';\nimport { xstyledKeys } from './constants.js';\n\nexport interface XstyledProps\n extends
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAwB;AAWxB,uBAA4B;
|
|
4
|
+
"sourcesContent": ["import { useMemo } from 'react';\nimport type {\n SizingProps,\n SpaceProps,\n LayoutProps,\n BoxShadowProps,\n BorderProps,\n BackgroundProps,\n FontWeightProps,\n TextAlignProps,\n} from '@elliemae/ds-system';\nimport { xstyledKeys } from './constants.js';\n\nexport interface XstyledProps\n extends\n SpaceProps,\n SizingProps,\n LayoutProps,\n BoxShadowProps,\n BorderProps,\n BackgroundProps,\n FontWeightProps,\n TextAlignProps {}\n\ntype PropsWithXstyled<T> = T & XstyledProps;\n\nexport const getXstyledProps = <T,>(props: PropsWithXstyled<T>): XstyledProps => {\n const xstyledPropsObject: Record<string, unknown> = {};\n Object.entries(props).forEach(([key, value]) => {\n if (key in xstyledKeys) {\n xstyledPropsObject[key] = value;\n }\n });\n return xstyledPropsObject;\n};\n\nexport const useGetXstyledProps = <T,>(props: PropsWithXstyled<T>): XstyledProps =>\n useMemo(() => getXstyledProps(props), [props]);\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAwB;AAWxB,uBAA4B;AAerB,MAAM,kBAAkB,CAAK,UAA6C;AAC/E,QAAM,qBAA8C,CAAC;AACrD,SAAO,QAAQ,KAAK,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAC9C,QAAI,OAAO,8BAAa;AACtB,yBAAmB,GAAG,IAAI;AAAA,IAC5B;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAEO,MAAM,qBAAqB,CAAK,cACrC,sBAAQ,MAAM,gBAAgB,KAAK,GAAG,CAAC,KAAK,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
const DOCUMENTATION_ONLY_SCHEMA_KEYS = /* @__PURE__ */ new Set(["aria-*", "on-*", "data-*", "all HTML attributes"]);
|
|
3
|
+
const getContractProps = (props, contractShape) => {
|
|
4
|
+
const declaredKeys = new Set(Object.keys(contractShape).filter((key) => !DOCUMENTATION_ONLY_SCHEMA_KEYS.has(key)));
|
|
5
|
+
const contractProps = {};
|
|
6
|
+
Object.entries(props).forEach(([key, value]) => {
|
|
7
|
+
if (value === void 0) return;
|
|
8
|
+
if (DOCUMENTATION_ONLY_SCHEMA_KEYS.has(key)) return;
|
|
9
|
+
if (!declaredKeys.has(key) && !key.startsWith("data-")) return;
|
|
10
|
+
contractProps[key] = value;
|
|
11
|
+
});
|
|
12
|
+
return contractProps;
|
|
13
|
+
};
|
|
14
|
+
export {
|
|
15
|
+
getContractProps
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=getContractProps.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/contractProps/getContractProps.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/**\n * Documentation-only entries that live in `globalAttributesPropTypes` (and therefore in every\n * component schema that spreads it). They exist so the Storybook props table can show \"you may pass\n * any aria-* / data-* / on-* / HTML attribute\" in a single row \u2014 they are NOT prop names a consumer\n * can ever pass, so they must never be treated as part of the runtime key set.\n */\nconst DOCUMENTATION_ONLY_SCHEMA_KEYS = new Set(['aria-*', 'on-*', 'data-*', 'all HTML attributes']);\n\n/**\n * Filters an arbitrary object down to the props a component's contract declares.\n *\n * This is the engine behind each package's own curated passthrough utility (e.g. ds-app-picker's\n * `getDSAppPickerContractProps`). Packages are expected to expose a bound utility rather than their\n * schema: the schema stays an internal implementation detail, so the two can drift later without\n * expanding anyone's public API.\n *\n * Three behaviours worth knowing, because callers depend on them:\n *\n * 1. **Documentation-only wildcard keys are ignored.** See `DOCUMENTATION_ONLY_SCHEMA_KEYS`.\n * 2. **`data-*` is honoured by prefix**, matching `getGlobalAttributes` \u2014 arbitrary data attributes\n * are a supported consumer surface even though no schema can enumerate them. Note the house\n * behaviour deliberately does not extend the same courtesy to `aria-*` or `on*`: those are\n * matched against the schema's explicit list, so a typo fails loudly instead of reaching the DOM.\n * 3. **`undefined` is dropped, `null` is forwarded.** These two are not interchangeable, and the rule\n * follows React rather than being invented here:\n *\n * - React's own default resolution (`resolveDefaultProps`) applies a `defaultProps` entry only when\n * the incoming prop is `undefined`; a `null` is respected as an explicitly supplied value. This\n * is the same rule as JS destructuring defaults and ES6 default parameters \u2014 a language-level\n * standard, not a React invention. So `undefined` means \"I am not defining this, you decide\" and\n * `null` means \"I am defining it, as nothing\".\n * - Everywhere React *consumes* a value rather than defaulting it \u2014 DOM attributes, children, event\n * handlers \u2014 it collapses the two and treats both as absent. The distinction is load-bearing\n * only at a default-resolution boundary.\n *\n * A contract passthrough is exactly such a boundary: the result is spread *after* a wrapper's own\n * defaults, so dropping `undefined` is what stops an unset key from erasing a working default,\n * while forwarding `null` is what lets a consumer deliberately override one. This matters more\n * here than in plain React, because Dimsum's `useMemoMergePropsWithDefault` is a plain\n * `{...defaults, ...props}` spread \u2014 it does NOT skip `undefined` the way `resolveDefaultProps`\n * does, so an `undefined` that reaches it clobbers the component's default too.\n *\n * What happens to a forwarded `null` afterwards is the receiving component's business, not this\n * function's. Dimsum components are strictly typed: `validateTypescriptPropTypesImplementation`\n * validates any value that is not `undefined`, and a prop declared as a function does not admit\n * `null` \u2014 so passing `null` there raises a prop-type error, correctly. A prop only accepts `null`\n * if its own declared type says so and its code carries the matching null guards. Where a consumer\n * wants to state \"do nothing\", the type-honouring way to say it is an explicit no-op \u2014 `() => {}`\n * for a handler, `() => null` for a component \u2014 which is unambiguous in a way that `null` is not.\n * This function stays out of that decision: forwarding the value and letting the owning contract\n * judge it is the correct division of concerns at this abstraction level.\n *\n * @param props - the object to filter; anything the contract does not declare is discarded\n * @param contractShape - any object whose KEYS name the contract's props. Only `Object.keys` is read,\n * so it is deliberately not narrowed to `DSPropTypesSchema`\n *\n * a PropTypes schema is usually fine and there is a code dedicated to discarding the global attributes to make the schema compatible for faster internal transition/implementation.\n * @returns a new object containing only the declared, defined props\n */\nexport const getContractProps = <ContractProps>(props: object, contractShape: object): Partial<ContractProps> => {\n const declaredKeys = new Set(Object.keys(contractShape).filter((key) => !DOCUMENTATION_ONLY_SCHEMA_KEYS.has(key)));\n\n // `props` is typed as `object` rather than `Record<string, unknown>` so callers can pass their own\n // declared prop interfaces without a cast at every call site. The casts live here instead.\n const contractProps: Record<string, unknown> = {};\n\n Object.entries(props as Record<string, unknown>).forEach(([key, value]) => {\n if (value === undefined) return;\n // Order matters: 'data-*' is itself prefixed with 'data-', so the documentation-only check has\n // to win over the prefix rule below or the pseudo-key would readmit itself.\n if (DOCUMENTATION_ONLY_SCHEMA_KEYS.has(key)) return;\n if (!declaredKeys.has(key) && !key.startsWith('data-')) return;\n contractProps[key] = value;\n });\n\n return contractProps as Partial<ContractProps>;\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACMvB,MAAM,iCAAiC,oBAAI,IAAI,CAAC,UAAU,QAAQ,UAAU,qBAAqB,CAAC;AAqD3F,MAAM,mBAAmB,CAAgB,OAAe,kBAAkD;AAC/G,QAAM,eAAe,IAAI,IAAI,OAAO,KAAK,aAAa,EAAE,OAAO,CAAC,QAAQ,CAAC,+BAA+B,IAAI,GAAG,CAAC,CAAC;AAIjH,QAAM,gBAAyC,CAAC;AAEhD,SAAO,QAAQ,KAAgC,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AACzE,QAAI,UAAU,OAAW;AAGzB,QAAI,+BAA+B,IAAI,GAAG,EAAG;AAC7C,QAAI,CAAC,aAAa,IAAI,GAAG,KAAK,CAAC,IAAI,WAAW,OAAO,EAAG;AACxD,kBAAc,GAAG,IAAI;AAAA,EACvB,CAAC;AAED,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/contractProps/index.ts"],
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { getContractProps } from './getContractProps.js';\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,wBAAwB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/esm/index.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
} from "./validation/index.js";
|
|
16
16
|
import { useGetXstyledProps, xstyledPropTypes, getXstyledProps } from "./xstyledProps/index.js";
|
|
17
17
|
import { useDeprecateComponent } from "./useDeprecateComponent/index.js";
|
|
18
|
+
import { getContractProps } from "./contractProps/index.js";
|
|
18
19
|
import { getPropsPerDatatestid, getPropsPerDatatestIdPropTypes } from "./propsPerDataTestId/index.js";
|
|
19
20
|
import { getPropsPerSlotPropTypes } from "./propsPerSlot/index.js";
|
|
20
21
|
import { useOwnerProps } from "./useOwnerProps/index.js";
|
|
@@ -22,6 +23,7 @@ export {
|
|
|
22
23
|
PropTypes,
|
|
23
24
|
describe,
|
|
24
25
|
getAriaProps,
|
|
26
|
+
getContractProps,
|
|
25
27
|
getDataProps,
|
|
26
28
|
getGlobalAttributes,
|
|
27
29
|
getPropsPerDatatestIdPropTypes,
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { useMemoMergePropsWithDefault } from './defaultProps/index.js';\nexport { getAriaProps, getDataProps } from './getProps/index.js';\nexport {\n getGlobalAttributes,\n useGetGlobalAttributes,\n globalAttributesPropTypes,\n type GlobalAttributesT,\n} from './globalProps/index.js';\nexport { describe, PropTypes, type DSPropTypesSchema } from './propTypes/index.js';\nexport type { ValidationMap } from 'prop-types';\nexport {\n throwTypeError,\n throwRequiredError,\n useValidateTypescriptPropTypes,\n validateTypescriptPropTypesImplementation,\n} from './validation/index.js';\nexport { type XstyledProps, useGetXstyledProps, xstyledPropTypes, getXstyledProps } from './xstyledProps/index.js';\nexport { useDeprecateComponent } from './useDeprecateComponent/index.js';\n\nexport { getPropsPerDatatestid, getPropsPerDatatestIdPropTypes } from './propsPerDataTestId/index.js';\nexport { getPropsPerSlotPropTypes } from './propsPerSlot/index.js';\nexport { useOwnerProps } from './useOwnerProps/index.js';\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,oCAAoC;AAC7C,SAAS,cAAc,oBAAoB;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,UAAU,iBAAyC;AAE5D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAA4B,oBAAoB,kBAAkB,uBAAuB;AACzF,SAAS,6BAA6B;AAEtC,SAAS,uBAAuB,sCAAsC;AACtE,SAAS,gCAAgC;AACzC,SAAS,qBAAqB;",
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { useMemoMergePropsWithDefault } from './defaultProps/index.js';\nexport { getAriaProps, getDataProps } from './getProps/index.js';\nexport {\n getGlobalAttributes,\n useGetGlobalAttributes,\n globalAttributesPropTypes,\n type GlobalAttributesT,\n} from './globalProps/index.js';\nexport { describe, PropTypes, type DSPropTypesSchema } from './propTypes/index.js';\nexport type { ValidationMap } from 'prop-types';\nexport {\n throwTypeError,\n throwRequiredError,\n useValidateTypescriptPropTypes,\n validateTypescriptPropTypesImplementation,\n} from './validation/index.js';\nexport { type XstyledProps, useGetXstyledProps, xstyledPropTypes, getXstyledProps } from './xstyledProps/index.js';\nexport { useDeprecateComponent } from './useDeprecateComponent/index.js';\n\nexport { getContractProps } from './contractProps/index.js';\nexport { getPropsPerDatatestid, getPropsPerDatatestIdPropTypes } from './propsPerDataTestId/index.js';\nexport { getPropsPerSlotPropTypes } from './propsPerSlot/index.js';\nexport { useOwnerProps } from './useOwnerProps/index.js';\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,oCAAoC;AAC7C,SAAS,cAAc,oBAAoB;AAC3C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AACP,SAAS,UAAU,iBAAyC;AAE5D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAA4B,oBAAoB,kBAAkB,uBAAuB;AACzF,SAAS,6BAA6B;AAEtC,SAAS,wBAAwB;AACjC,SAAS,uBAAuB,sCAAsC;AACtE,SAAS,gCAAgC;AACzC,SAAS,qBAAqB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/esm/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/propTypes/PropTypes.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type { PropTypesTypes, DocumentedPropType, ReactDescObjT, PropTypesObj } from './types.js';\n\nconst addPropTypeDocumentationField = <T extends keyof ReactDescObjT>(fieldName: T) =>\n function addFieldToReactDesc(this: DocumentedPropType, value: ReactDescObjT[T]): DocumentedPropType {\n if (!this.reactDesc) {\n this.reactDesc = {};\n }\n let realValue = value;\n if (\n fieldName === 'global' ||\n fieldName === 'dataTestId' ||\n fieldName === 'hidden' ||\n fieldName === 'xstyled' ||\n fieldName === 'omitValidation'\n )\n realValue = true;\n\n this.reactDesc[fieldName] = realValue;\n return this;\n };\n\nconst documentedPropType: Omit<DocumentedPropType, 'type' | 'isRequired' | 'reactDesc'> = {\n defaultValue: addPropTypeDocumentationField('defaultValue'),\n description: addPropTypeDocumentationField('description'),\n deprecated: addPropTypeDocumentationField('deprecated'),\n format: addPropTypeDocumentationField('format'),\n signature: addPropTypeDocumentationField('signature'),\n global: addPropTypeDocumentationField('global'),\n omitValidation: addPropTypeDocumentationField('omitValidation'),\n hidden: addPropTypeDocumentationField('hidden'),\n dataTestId: addPropTypeDocumentationField('dataTestId'),\n xstyled: addPropTypeDocumentationField('xstyled'),\n isRequiredIf: addPropTypeDocumentationField('isRequiredIf'),\n};\n\nconst createPropType = (type: PropTypesTypes) => {\n const propTypeObj = {\n type,\n ...documentedPropType,\n };\n Object.defineProperty(propTypeObj, 'isRequired', {\n get: function getRequired(this: DocumentedPropType) {\n if (!this.reactDesc) {\n this.reactDesc = {};\n }\n this.reactDesc.required = true;\n return this;\n },\n enumerable: true,\n configurable: true,\n });\n\n return propTypeObj;\n};\n\nconst createPropTypeWithArgs = (type: PropTypesTypes) => (args: unknown) => {\n const propTypeObj = {\n args,\n type,\n ...documentedPropType,\n };\n Object.defineProperty(propTypeObj, 'isRequired', {\n get: function getRequired(this: DocumentedPropType) {\n if (!this.reactDesc) {\n this.reactDesc = {};\n }\n this.reactDesc.required = true;\n return this;\n },\n enumerable: true,\n configurable: true,\n });\n return propTypeObj;\n};\n\nconst PropTypes = {\n custom: (callback: CallableFunction) => {\n const target = callback.bind(null) as CallableFunction & DocumentedPropType;\n target.type = 'func';\n Object.keys(documentedPropType).forEach((fieldName) => {\n const fieldNameCasted = fieldName as keyof DocumentedPropType;\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (target[fieldNameCasted] as unknown) = documentedPropType[fieldNameCasted] as unknown;\n });\n return target;\n },\n} as unknown as PropTypesObj;\n\nfunction definePropType(type: PropTypesTypes) {\n Object.defineProperty(PropTypes, type, {\n get: function getPropType() {\n return createPropType(type);\n },\n enumerable: true,\n configurable: true,\n });\n}\n\nfunction definePropTypeWithArgs(type: PropTypesTypes) {\n Object.defineProperty(PropTypes, type, {\n get: function getPropType() {\n return createPropTypeWithArgs(type);\n },\n enumerable: true,\n configurable: true,\n });\n}\n\ndefinePropType('any');\ndefinePropType('array');\ndefinePropType('bool');\ndefinePropType('element');\ndefinePropType('func');\ndefinePropType('node');\ndefinePropType('number');\ndefinePropType('object');\ndefinePropType('symbol');\ndefinePropType('string');\n\ndefinePropTypeWithArgs('arrayOf');\ndefinePropTypeWithArgs('instanceOf');\ndefinePropTypeWithArgs('objectOf');\ndefinePropTypeWithArgs('oneOfType');\ndefinePropTypeWithArgs('oneOf');\ndefinePropTypeWithArgs('shape');\ndefinePropTypeWithArgs('tuple');\n\nexport default PropTypes;\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACEvB,MAAM,gCAAgC,CAAgC,cACpE,SAAS,oBAA8C,OAA6C;AAClG,MAAI,CAAC,KAAK,WAAW;AACnB,SAAK,YAAY,CAAC;AAAA,EACpB;AACA,MAAI,YAAY;AAChB,MACE,cAAc,YACd,cAAc,gBACd,cAAc,YACd,cAAc,aACd,cAAc;AAEd,gBAAY;AAEd,OAAK,UAAU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O;AACd,WAAO,KAAK,kBAAkB,EAAE,QAAQ,CAAC,cAAc;AACrD,YAAM,kBAAkB;AAExB,MAAC,OAAO,eAAe,IAAgB,mBAAmB,eAAe;AAAA,IAC3E,CAAC;AACD,WAAO;AAAA,EACT;AACF;AAEA,SAAS,eAAe,MAAsB;AAC5C,SAAO,eAAe,WAAW,MAAM;AAAA,IACrC,KAAK,SAAS,cAAc;AAC1B,aAAO,eAAe,IAAI;AAAA,IAC5B;AAAA,IACA,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB,CAAC;AACH;AAEA,SAAS,uBAAuB,MAAsB;AACpD,SAAO,eAAe,WAAW,MAAM;AAAA,IACrC,KAAK,SAAS,cAAc;AAC1B,aAAO,uBAAuB,IAAI;AAAA,IACpC;AAAA,IACA,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB,CAAC;AACH;AAEA,eAAe,KAAK;AACpB,eAAe,OAAO;AACtB,eAAe,MAAM;AACrB,eAAe,SAAS;AACxB,eAAe,MAAM;AACrB,eAAe,MAAM;AACrB,eAAe,QAAQ;AACvB,eAAe,QAAQ;AACvB,eAAe,QAAQ;AACvB,eAAe,QAAQ;AAEvB,uBAAuB,SAAS;AAChC,uBAAuB,YAAY;AACnC,uBAAuB,UAAU;AACjC,uBAAuB,WAAW;AAClC,uBAAuB,OAAO;AAC9B,uBAAuB,OAAO;AAC9B,uBAAuB,OAAO;AAE9B,IAAO,oBAAQ;",
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type { PropTypesTypes, DocumentedPropType, ReactDescObjT, PropTypesObj } from './types.js';\n\nconst addPropTypeDocumentationField = <T extends keyof ReactDescObjT>(fieldName: T) =>\n function addFieldToReactDesc(this: DocumentedPropType, value: ReactDescObjT[T]): DocumentedPropType {\n if (!this.reactDesc) {\n this.reactDesc = {};\n }\n let realValue = value;\n if (\n fieldName === 'global' ||\n fieldName === 'dataTestId' ||\n fieldName === 'hidden' ||\n fieldName === 'xstyled' ||\n fieldName === 'omitValidation'\n )\n realValue = true;\n\n this.reactDesc[fieldName] = realValue;\n return this;\n };\n\nconst documentedPropType: Omit<DocumentedPropType, 'type' | 'isRequired' | 'reactDesc'> = {\n defaultValue: addPropTypeDocumentationField('defaultValue'),\n description: addPropTypeDocumentationField('description'),\n deprecated: addPropTypeDocumentationField('deprecated'),\n format: addPropTypeDocumentationField('format'),\n signature: addPropTypeDocumentationField('signature'),\n global: addPropTypeDocumentationField('global'),\n omitValidation: addPropTypeDocumentationField('omitValidation'),\n hidden: addPropTypeDocumentationField('hidden'),\n dataTestId: addPropTypeDocumentationField('dataTestId'),\n xstyled: addPropTypeDocumentationField('xstyled'),\n isRequiredIf: addPropTypeDocumentationField('isRequiredIf'),\n};\n\nconst createPropType = (type: PropTypesTypes) => {\n const propTypeObj = {\n type,\n ...documentedPropType,\n };\n Object.defineProperty(propTypeObj, 'isRequired', {\n get: function getRequired(this: DocumentedPropType) {\n if (!this.reactDesc) {\n this.reactDesc = {};\n }\n this.reactDesc.required = true;\n return this;\n },\n enumerable: true,\n configurable: true,\n });\n\n return propTypeObj;\n};\n\nconst createPropTypeWithArgs = (type: PropTypesTypes) => (args: unknown) => {\n const propTypeObj = {\n args,\n type,\n ...documentedPropType,\n };\n Object.defineProperty(propTypeObj, 'isRequired', {\n get: function getRequired(this: DocumentedPropType) {\n if (!this.reactDesc) {\n this.reactDesc = {};\n }\n this.reactDesc.required = true;\n return this;\n },\n enumerable: true,\n configurable: true,\n });\n return propTypeObj;\n};\n\nconst PropTypes = {\n custom: (callback: CallableFunction) => {\n const target = callback.bind(null) as CallableFunction & DocumentedPropType;\n target.type = 'func';\n Object.keys(documentedPropType).forEach((fieldName) => {\n const fieldNameCasted = fieldName as keyof DocumentedPropType;\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n (target[fieldNameCasted] as unknown) = documentedPropType[fieldNameCasted] as unknown;\n });\n return target;\n },\n} as unknown as PropTypesObj;\n\nfunction definePropType(type: PropTypesTypes) {\n Object.defineProperty(PropTypes, type, {\n get: function getPropType() {\n return createPropType(type);\n },\n enumerable: true,\n configurable: true,\n });\n}\n\nfunction definePropTypeWithArgs(type: PropTypesTypes) {\n Object.defineProperty(PropTypes, type, {\n get: function getPropType() {\n return createPropTypeWithArgs(type);\n },\n enumerable: true,\n configurable: true,\n });\n}\n\ndefinePropType('any');\ndefinePropType('array');\ndefinePropType('bool');\ndefinePropType('element');\ndefinePropType('elementType');\ndefinePropType('func');\ndefinePropType('node');\ndefinePropType('number');\ndefinePropType('object');\ndefinePropType('symbol');\ndefinePropType('string');\n\ndefinePropTypeWithArgs('arrayOf');\ndefinePropTypeWithArgs('instanceOf');\ndefinePropTypeWithArgs('objectOf');\ndefinePropTypeWithArgs('oneOfType');\ndefinePropTypeWithArgs('oneOf');\ndefinePropTypeWithArgs('shape');\ndefinePropTypeWithArgs('tuple');\n\nexport default PropTypes;\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACEvB,MAAM,gCAAgC,CAAgC,cACpE,SAAS,oBAA8C,OAA6C;AAClG,MAAI,CAAC,KAAK,WAAW;AACnB,SAAK,YAAY,CAAC;AAAA,EACpB;AACA,MAAI,YAAY;AAChB,MACE,cAAc,YACd,cAAc,gBACd,cAAc,YACd,cAAc,aACd,cAAc;AAEd,gBAAY;AAEd,OAAK,UAAU,SAAS,IAAI;AAC5B,SAAO;AACT;AAEF,MAAM,qBAAoF;AAAA,EACxF,cAAc,8BAA8B,cAAc;AAAA,EAC1D,aAAa,8BAA8B,aAAa;AAAA,EACxD,YAAY,8BAA8B,YAAY;AAAA,EACtD,QAAQ,8BAA8B,QAAQ;AAAA,EAC9C,WAAW,8BAA8B,WAAW;AAAA,EACpD,QAAQ,8BAA8B,QAAQ;AAAA,EAC9C,gBAAgB,8BAA8B,gBAAgB;AAAA,EAC9D,QAAQ,8BAA8B,QAAQ;AAAA,EAC9C,YAAY,8BAA8B,YAAY;AAAA,EACtD,SAAS,8BAA8B,SAAS;AAAA,E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AM;AAAA,IACrC,KAAK,SAAS,cAAc;AAC1B,aAAO,uBAAuB,IAAI;AAAA,IACpC;AAAA,IACA,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB,CAAC;AACH;AAEA,eAAe,KAAK;AACpB,eAAe,OAAO;AACtB,eAAe,MAAM;AACrB,eAAe,SAAS;AACxB,eAAe,aAAa;AAC5B,eAAe,MAAM;AACrB,eAAe,MAAM;AACrB,eAAe,QAAQ;AACvB,eAAe,QAAQ;AACvB,eAAe,QAAQ;AACvB,eAAe,QAAQ;AAEvB,uBAAuB,SAAS;AAChC,uBAAuB,YAAY;AACnC,uBAAuB,UAAU;AACjC,uBAAuB,WAAW;AAClC,uBAAuB,OAAO;AAC9B,uBAAuB,OAAO;AAC9B,uBAAuB,OAAO;AAE9B,IAAO,oBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -12,7 +12,8 @@ const shapeFormat = (shape) => {
|
|
|
12
12
|
} else {
|
|
13
13
|
valueFormat = propTypeFormat(value);
|
|
14
14
|
}
|
|
15
|
-
|
|
15
|
+
const deprecatedMarker = value.reactDesc?.deprecated ? `/** @deprecated v${value.reactDesc.deprecated.version} */ ` : "";
|
|
16
|
+
return `${deprecatedMarker}${key}${value.reactDesc && value.reactDesc.required ? "" : "?"}: ${valueFormat}`;
|
|
16
17
|
});
|
|
17
18
|
return `{${props.join(",")}}`;
|
|
18
19
|
};
|
|
@@ -47,6 +48,9 @@ const propTypeFormat = (propType, joinWith = "") => {
|
|
|
47
48
|
case "element":
|
|
48
49
|
result = "JSX.Element";
|
|
49
50
|
break;
|
|
51
|
+
case "elementType":
|
|
52
|
+
result = "React.ComponentType<Record<string,unknown>>";
|
|
53
|
+
break;
|
|
50
54
|
case "instanceOf":
|
|
51
55
|
result = "any";
|
|
52
56
|
break;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/propTypes/toTypescript.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/restrict-template-expressions */\n/* eslint-disable @typescript-eslint/no-use-before-define */\n/* eslint-disable complexity */\n/* eslint-disable react/forbid-foreign-prop-types */\nimport type React from 'react';\nimport type { ComponentDocumentation, Hook, ReactDescT, TypescriptDocumentation } from './types.js';\nimport { isReactDesc } from './describeGuards.js';\n\nconst arrayFormat = (array: ReactDescT[]) => array.map((propType) => propTypeFormat(propType));\n\nconst shapeFormat = (shape: Record<string, ReactDescT>) => {\n const props = Object.keys(shape).map((key) => {\n const value = shape[key];\n let valueFormat;\n if (\n value.type &&\n (value.type === 'arrayOf' || value.type === 'oneOfType' || value.type === 'oneOf') &&\n Array.isArray(value.args)\n ) {\n valueFormat = `${propTypeFormat(value)}`;\n } else if (value.type === 'shape') {\n valueFormat = `${propTypeFormat(value)}`;\n } else {\n valueFormat = propTypeFormat(value);\n }\n return `${key}${value.reactDesc && value.reactDesc.required ? '' : '?'}: ${valueFormat}`;\n });\n return `{${props.join(',')}}`;\n};\n\nconst propTypeFormat = (propType: ReactDescT | ReactDescT[], joinWith = ''): string => {\n let result;\n if (Array.isArray(propType)) {\n result = arrayFormat(propType).join(joinWith);\n } else if (typeof propType !== 'function' && propType.type) {\n switch (propType.type) {\n case 'array':\n result = 'any[]';\n break;\n case 'arrayOf':\n if ((propType.args as ReactDescT).type === 'oneOfType') {\n result = `(${propTypeFormat(propType.args as ReactDescT, ' | ')})[]`;\n } else {\n result = `${propTypeFormat(propType.args as ReactDescT, '\\n')}[]`;\n }\n break;\n case 'tuple':\n result = `[${propTypeFormat(propType.args as ReactDescT, ', ')}]`;\n break;\n case 'bool':\n result = 'boolean';\n break;\n case 'func':\n result = propType?.reactDesc?.signature ?? '((...args: any[]) => any)';\n break;\n case 'node':\n result = 'React.ReactNode';\n break;\n case 'element':\n result = 'JSX.Element';\n break;\n case 'instanceOf':\n result = 'any';\n break;\n case 'symbol':\n result = 'any';\n break;\n case 'objectOf':\n result = `{ [key: string]: ${propTypeFormat(propType.args as ReactDescT)} }`;\n break;\n case 'oneOf':\n result = (propType.args as unknown[]).map((a) => `\"${a}\"`).join(' | ');\n break;\n case 'oneOfType':\n result = `${propTypeFormat(propType.args as ReactDescT[], ' | ')}`;\n break;\n case 'shape':\n result = `${shapeFormat(propType.args as Record<string, ReactDescT>)}`;\n break;\n default:\n result = `${propType.type}`;\n break;\n }\n } else {\n result = 'any';\n }\n return result;\n};\n\nconst propTypeAsTypescript = (propType: ReactDescT, propName: string) => {\n const documentation = {\n ...propType.reactDesc,\n name: propName,\n };\n\n documentation.format = propTypeFormat(propType);\n\n return documentation;\n};\n\nexport default function descToTypescript<C, R>(\n component: React.ComponentType<C> | Hook<C, R>,\n reactDesc: ComponentDocumentation,\n) {\n if (!component) {\n throw new Error('react-desc: component is required');\n }\n\n const documentation: Partial<TypescriptDocumentation> = {\n name: component.displayName || component.name,\n ...reactDesc,\n };\n if (reactDesc) {\n delete documentation.propTypes;\n\n if (reactDesc.propTypes) {\n const propTypes: TypescriptDocumentation['properties'] = [];\n Object.keys(reactDesc.propTypes).forEach((propName) => {\n const propType = reactDesc.propTypes[propName];\n if (propType.type === 'shape') {\n propType.reactDesc.group = {};\n\n Object.keys(propType.args as Record<string, ReactDescT>).forEach((prop) => {\n if (!propType.reactDesc.group) return;\n propType.reactDesc.group[prop] = propTypeAsTypescript(\n (propType.args as Record<string, ReactDescT>)[prop],\n prop,\n );\n });\n }\n propTypes.push(propTypeAsTypescript(propType, propName));\n });\n if (propTypes.length > 0) {\n documentation.properties = propTypes;\n }\n }\n if (reactDesc.returnType) {\n if (isReactDesc(reactDesc.returnType)) {\n documentation.returns = propTypeAsTypescript(reactDesc.returnType, 'returns');\n } else {\n documentation.returns = Object.entries(reactDesc.returnType).map(([propName, propType]) =>\n propTypeAsTypescript(propType, propName),\n );\n }\n }\n }\n return documentation as TypescriptDocumentation;\n}\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACMvB,SAAS,mBAAmB;AAE5B,MAAM,cAAc,CAAC,UAAwB,MAAM,IAAI,CAAC,aAAa,eAAe,QAAQ,CAAC;AAE7F,MAAM,cAAc,CAAC,UAAsC;AACzD,QAAM,QAAQ,OAAO,KAAK,KAAK,EAAE,IAAI,CAAC,QAAQ;AAC5C,UAAM,QAAQ,MAAM,GAAG;AACvB,QAAI;AACJ,QACE,MAAM,SACL,MAAM,SAAS,aAAa,MAAM,SAAS,eAAe,MAAM,SAAS,YAC1E,MAAM,QAAQ,MAAM,IAAI,GACxB;AACA,oBAAc,GAAG,eAAe,KAAK,CAAC;AAAA,IACxC,WAAW,MAAM,SAAS,SAAS;AACjC,oBAAc,GAAG,eAAe,KAAK,CAAC;AAAA,IACxC,OAAO;AACL,oBAAc,eAAe,KAAK;AAAA,IACpC;AACA,WAAO,GAAG,GAAG,GAAG,MAAM,aAAa,MAAM,UAAU,WAAW,KAAK,GAAG,KAAK,WAAW;AAAA,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/restrict-template-expressions */\n/* eslint-disable @typescript-eslint/no-use-before-define */\n/* eslint-disable complexity */\n/* eslint-disable react/forbid-foreign-prop-types */\nimport type React from 'react';\nimport type { ComponentDocumentation, Hook, ReactDescT, TypescriptDocumentation } from './types.js';\nimport { isReactDesc } from './describeGuards.js';\n\nconst arrayFormat = (array: ReactDescT[]) => array.map((propType) => propTypeFormat(propType));\n\nconst shapeFormat = (shape: Record<string, ReactDescT>) => {\n const props = Object.keys(shape).map((key) => {\n const value = shape[key];\n let valueFormat;\n if (\n value.type &&\n (value.type === 'arrayOf' || value.type === 'oneOfType' || value.type === 'oneOf') &&\n Array.isArray(value.args)\n ) {\n valueFormat = `${propTypeFormat(value)}`;\n } else if (value.type === 'shape') {\n valueFormat = `${propTypeFormat(value)}`;\n } else {\n valueFormat = propTypeFormat(value);\n }\n const deprecatedMarker = value.reactDesc?.deprecated\n ? `/** @deprecated v${value.reactDesc.deprecated.version} */ `\n : '';\n return `${deprecatedMarker}${key}${value.reactDesc && value.reactDesc.required ? '' : '?'}: ${valueFormat}`;\n });\n return `{${props.join(',')}}`;\n};\n\nconst propTypeFormat = (propType: ReactDescT | ReactDescT[], joinWith = ''): string => {\n let result;\n if (Array.isArray(propType)) {\n result = arrayFormat(propType).join(joinWith);\n } else if (typeof propType !== 'function' && propType.type) {\n switch (propType.type) {\n case 'array':\n result = 'any[]';\n break;\n case 'arrayOf':\n if ((propType.args as ReactDescT).type === 'oneOfType') {\n result = `(${propTypeFormat(propType.args as ReactDescT, ' | ')})[]`;\n } else {\n result = `${propTypeFormat(propType.args as ReactDescT, '\\n')}[]`;\n }\n break;\n case 'tuple':\n result = `[${propTypeFormat(propType.args as ReactDescT, ', ')}]`;\n break;\n case 'bool':\n result = 'boolean';\n break;\n case 'func':\n result = propType?.reactDesc?.signature ?? '((...args: any[]) => any)';\n break;\n case 'node':\n result = 'React.ReactNode';\n break;\n case 'element':\n result = 'JSX.Element';\n break;\n case 'elementType':\n result = 'React.ComponentType<Record<string,unknown>>';\n break;\n case 'instanceOf':\n result = 'any';\n break;\n case 'symbol':\n result = 'any';\n break;\n case 'objectOf':\n result = `{ [key: string]: ${propTypeFormat(propType.args as ReactDescT)} }`;\n break;\n case 'oneOf':\n result = (propType.args as unknown[]).map((a) => `\"${a}\"`).join(' | ');\n break;\n case 'oneOfType':\n result = `${propTypeFormat(propType.args as ReactDescT[], ' | ')}`;\n break;\n case 'shape':\n result = `${shapeFormat(propType.args as Record<string, ReactDescT>)}`;\n break;\n default:\n result = `${propType.type}`;\n break;\n }\n } else {\n result = 'any';\n }\n return result;\n};\n\nconst propTypeAsTypescript = (propType: ReactDescT, propName: string) => {\n const documentation = {\n ...propType.reactDesc,\n name: propName,\n };\n\n documentation.format = propTypeFormat(propType);\n\n return documentation;\n};\n\nexport default function descToTypescript<C, R>(\n component: React.ComponentType<C> | Hook<C, R>,\n reactDesc: ComponentDocumentation,\n) {\n if (!component) {\n throw new Error('react-desc: component is required');\n }\n\n const documentation: Partial<TypescriptDocumentation> = {\n name: component.displayName || component.name,\n ...reactDesc,\n };\n if (reactDesc) {\n delete documentation.propTypes;\n\n if (reactDesc.propTypes) {\n const propTypes: TypescriptDocumentation['properties'] = [];\n Object.keys(reactDesc.propTypes).forEach((propName) => {\n const propType = reactDesc.propTypes[propName];\n if (propType.type === 'shape') {\n propType.reactDesc.group = {};\n\n Object.keys(propType.args as Record<string, ReactDescT>).forEach((prop) => {\n if (!propType.reactDesc.group) return;\n propType.reactDesc.group[prop] = propTypeAsTypescript(\n (propType.args as Record<string, ReactDescT>)[prop],\n prop,\n );\n });\n }\n propTypes.push(propTypeAsTypescript(propType, propName));\n });\n if (propTypes.length > 0) {\n documentation.properties = propTypes;\n }\n }\n if (reactDesc.returnType) {\n if (isReactDesc(reactDesc.returnType)) {\n documentation.returns = propTypeAsTypescript(reactDesc.returnType, 'returns');\n } else {\n documentation.returns = Object.entries(reactDesc.returnType).map(([propName, propType]) =>\n propTypeAsTypescript(propType, propName),\n );\n }\n }\n }\n return documentation as TypescriptDocumentation;\n}\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACMvB,SAAS,mBAAmB;AAE5B,MAAM,cAAc,CAAC,UAAwB,MAAM,IAAI,CAAC,aAAa,eAAe,QAAQ,CAAC;AAE7F,MAAM,cAAc,CAAC,UAAsC;AACzD,QAAM,QAAQ,OAAO,KAAK,KAAK,EAAE,IAAI,CAAC,QAAQ;AAC5C,UAAM,QAAQ,MAAM,GAAG;AACvB,QAAI;AACJ,QACE,MAAM,SACL,MAAM,SAAS,aAAa,MAAM,SAAS,eAAe,MAAM,SAAS,YAC1E,MAAM,QAAQ,MAAM,IAAI,GACxB;AACA,oBAAc,GAAG,eAAe,KAAK,CAAC;AAAA,IACxC,WAAW,MAAM,SAAS,SAAS;AACjC,oBAAc,GAAG,eAAe,KAAK,CAAC;AAAA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,UAAU,UAAU,GAAG;AACrC,sBAAc,UAAU,qBAAqB,UAAU,YAAY,SAAS;AAAA,MAC9E,OAAO;AACL,sBAAc,UAAU,OAAO,QAAQ,UAAU,UAAU,EAAE;AAAA,UAAI,CAAC,CAAC,UAAU,QAAQ,MACnF,qBAAqB,UAAU,QAAQ;AAAA,QACzC;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
-
import { useCallback } from "react";
|
|
2
|
+
import { useCallback, useMemo } from "react";
|
|
3
3
|
const useOwnerProps = (props, args) => {
|
|
4
4
|
const getOwnerProps = useCallback(() => props, [props]);
|
|
5
5
|
const getOwnerPropsArguments = useCallback(() => args ?? {}, [args]);
|
|
6
|
-
return { getOwnerProps, getOwnerPropsArguments };
|
|
6
|
+
return useMemo(() => ({ getOwnerProps, getOwnerPropsArguments }), [getOwnerProps, getOwnerPropsArguments]);
|
|
7
7
|
};
|
|
8
8
|
export {
|
|
9
9
|
useOwnerProps
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/useOwnerProps/index.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useCallback } from 'react';\n\nexport const useOwnerProps = <P, A extends object = Record<string, never>>(props: P, args?: A) => {\n const getOwnerProps = useCallback(() => props, [props]);\n const getOwnerPropsArguments = useCallback(() => args ?? {}, [args]);\n return { getOwnerProps, getOwnerPropsArguments };\n};\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useCallback, useMemo } from 'react';\n\nexport const useOwnerProps = <P, A extends object = Record<string, never>>(props: P, args?: A) => {\n const getOwnerProps = useCallback(() => props, [props]);\n const getOwnerPropsArguments = useCallback(() => args ?? {}, [args]);\n return useMemo(() => ({ getOwnerProps, getOwnerPropsArguments }), [getOwnerProps, getOwnerPropsArguments]);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,aAAa,eAAe;AAE9B,MAAM,gBAAgB,CAA8C,OAAU,SAAa;AAChG,QAAM,gBAAgB,YAAY,MAAM,OAAO,CAAC,KAAK,CAAC;AACtD,QAAM,yBAAyB,YAAY,MAAM,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;AACnE,SAAO,QAAQ,OAAO,EAAE,eAAe,uBAAuB,IAAI,CAAC,eAAe,sBAAsB,CAAC;AAC3G;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -32,6 +32,7 @@ const isFunction = (format) => {
|
|
|
32
32
|
return arrowOccursAtDepth1;
|
|
33
33
|
};
|
|
34
34
|
const isJSXorNode = (format) => !isUnion(format) && ["React.ReactNode", "JSX.Element"].includes(format);
|
|
35
|
+
const isReactComponentType = (format) => !isUnion(format) && format === "React.ComponentType<Record<string,unknown>>";
|
|
35
36
|
const isSomethingWithParenthesis = (format) => !isUnion(format) && format[0] === "(" && format.slice(-1) === ")";
|
|
36
37
|
export {
|
|
37
38
|
isArray,
|
|
@@ -41,6 +42,7 @@ export {
|
|
|
41
42
|
isObject,
|
|
42
43
|
isObjectOf,
|
|
43
44
|
isPrimitiveType,
|
|
45
|
+
isReactComponentType,
|
|
44
46
|
isSomethingWithParenthesis,
|
|
45
47
|
isString,
|
|
46
48
|
isUndefined,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/validation/typescriptGuards.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "type GuardFn = (format: string) => boolean;\n\nexport const isPrimitiveType: GuardFn = (format) => ['string', 'number', 'boolean'].includes(format);\nexport const isUndefined: GuardFn = (format) => format === '\"undefined\"';\nexport const isNull: GuardFn = (format) => format === '\"null\"';\nexport const isUnion: GuardFn = (format) => {\n let depth = 0;\n let satisfies = false;\n format.split('').forEach((char) => {\n if (['{', '('].includes(char)) depth += 1;\n else if (['}', ')'].includes(char)) depth -= 1;\n else if (char === '|' && depth === 0) satisfies = true;\n });\n return satisfies;\n};\n\nexport const isString: GuardFn = (format) => !isUnion(format) && format[0] === '\"' && format.slice(-1) === '\"';\n\nexport const isArray: GuardFn = (format) => !isUnion(format) && format.slice(-2) === '[]';\n\nexport const isObjectOf: GuardFn = (format) =>\n format !== 'object' && !isUnion(format) && format.startsWith('{ [key: string]: ');\n\nexport const isObject: GuardFn = (format) =>\n format === 'object' || (!isUnion(format) && format[0] === '{' && format.slice(-1) === '}');\n\nexport const isFunction: GuardFn = (format) => {\n // It's isn't an union\n if (isUnion(format)) return false;\n // Has to start with (( and end with )\n if (!format.startsWith('((') && format.slice(-1) !== ')') return false;\n\n // The arrow MUST occur at depth 1 (when couting parenthesis)\n // Otherwise the only possibility is that we have \"something with parenthesis\" (look down below)\n let depth = 0;\n let arrowOccursAtDepth1 = false;\n for (let i = 0; i < format.length; i += 1) {\n const char = format[i];\n if (['{', '('].includes(char)) depth += 1;\n else if (['}', ')'].includes(char)) depth -= 1;\n else if (i < format.length - 1 && format.slice(i, i + 2) === '=>') {\n arrowOccursAtDepth1 = arrowOccursAtDepth1 || depth === 1;\n }\n }\n return arrowOccursAtDepth1;\n};\n\nexport const isJSXorNode: GuardFn = (format) => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);\n\nexport const isSomethingWithParenthesis: GuardFn = (format) =>\n !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACEhB,MAAM,kBAA2B,CAAC,WAAW,CAAC,UAAU,UAAU,SAAS,EAAE,SAAS,MAAM;AAC5F,MAAM,c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,CAAC,MAAM,MAAM;AACjE,4BAAsB,uBAAuB,UAAU;AAAA,IACzD;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,cAAuB,CAAC,WAAW,CAAC,QAAQ,MAAM,KAAK,CAAC,mBAAmB,aAAa,EAAE,SAAS,MAAM;AAE/G,MAAM,6BAAsC,CAAC,WAClD,CAAC,QAAQ,MAAM,KAAK,OAAO,CAAC,MAAM,OAAO,OAAO,MAAM,EAAE,MAAM;",
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "type GuardFn = (format: string) => boolean;\n\nexport const isPrimitiveType: GuardFn = (format) => ['string', 'number', 'boolean'].includes(format);\nexport const isUndefined: GuardFn = (format) => format === '\"undefined\"';\nexport const isNull: GuardFn = (format) => format === '\"null\"';\nexport const isUnion: GuardFn = (format) => {\n let depth = 0;\n let satisfies = false;\n format.split('').forEach((char) => {\n if (['{', '('].includes(char)) depth += 1;\n else if (['}', ')'].includes(char)) depth -= 1;\n else if (char === '|' && depth === 0) satisfies = true;\n });\n return satisfies;\n};\n\nexport const isString: GuardFn = (format) => !isUnion(format) && format[0] === '\"' && format.slice(-1) === '\"';\n\nexport const isArray: GuardFn = (format) => !isUnion(format) && format.slice(-2) === '[]';\n\nexport const isObjectOf: GuardFn = (format) =>\n format !== 'object' && !isUnion(format) && format.startsWith('{ [key: string]: ');\n\nexport const isObject: GuardFn = (format) =>\n format === 'object' || (!isUnion(format) && format[0] === '{' && format.slice(-1) === '}');\n\nexport const isFunction: GuardFn = (format) => {\n // It's isn't an union\n if (isUnion(format)) return false;\n // Has to start with (( and end with )\n if (!format.startsWith('((') && format.slice(-1) !== ')') return false;\n\n // The arrow MUST occur at depth 1 (when couting parenthesis)\n // Otherwise the only possibility is that we have \"something with parenthesis\" (look down below)\n let depth = 0;\n let arrowOccursAtDepth1 = false;\n for (let i = 0; i < format.length; i += 1) {\n const char = format[i];\n if (['{', '('].includes(char)) depth += 1;\n else if (['}', ')'].includes(char)) depth -= 1;\n else if (i < format.length - 1 && format.slice(i, i + 2) === '=>') {\n arrowOccursAtDepth1 = arrowOccursAtDepth1 || depth === 1;\n }\n }\n return arrowOccursAtDepth1;\n};\n\nexport const isJSXorNode: GuardFn = (format) => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);\n\nexport const isReactComponentType: GuardFn = (format) =>\n !isUnion(format) && format === 'React.ComponentType<Record<string,unknown>>';\n\nexport const isSomethingWithParenthesis: GuardFn = (format) =>\n !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACEhB,MAAM,kBAA2B,CAAC,WAAW,CAAC,UAAU,UAAU,SAAS,EAAE,SAAS,MAAM;AAC5F,MAAM,cAAuB,CAAC,WAAW,WAAW;AACpD,MAAM,SAAkB,CAAC,WAAW,WAAW;AAC/C,MAAM,UAAmB,CAAC,WAAW;AAC1C,MAAI,QAAQ;AACZ,MAAI,YAAY;AAChB,SAAO,MAAM,EAAE,EAAE,QAAQ,CAAC,SAAS;AACjC,QAAI,CAAC,KAAK,GAAG,EAAE,SAAS,IAAI,EAAG,UAAS;AAAA,aAC/B,CAAC,KAAK,GAAG,EAAE,SAAS,IAAI,EAAG,UAAS;AAAA,aACpC,SAAS,OAAO,UAAU,EAAG,aAAY;AAAA,EACpD,CAAC;AACD,SAAO;AACT;AAEO,MAAM,WAAoB,CAAC,WAAW,CAAC,QAAQ,MAAM,KAAK,OAAO,CAAC,MAAM,OAAO,OAAO,MAAM,EAAE,MAAM;AAEpG,MAAM,UAAmB,CAAC,WAAW,CAAC,QAAQ,MAAM,KAAK,OAAO,MAAM,EAAE,MAAM;AAE9E,MAAM,aAAsB,CAAC,WAClC,WAAW,YAAY,CAAC,QAAQ,MAAM,KAAK,OAAO,WAAW,mBAAmB;AAE3E,MAAM,WAAoB,CAAC,WAChC,WAAW,YAAa,CAAC,QAAQ,MAAM,KAAK,OAAO,CAAC,MAAM,OAAO,OAAO,MAAM,EAAE,MAAM;AAEjF,MAAM,aAAsB,CAAC,WAAW;AAE7C,MAAI,QAAQ,MAAM,EAAG,QAAO;AAE5B,MAAI,CAAC,OAAO,WAAW,IAAI,KAAK,OAAO,MAAM,EAAE,MAAM,IAAK,QAAO;AAIjE,MAAI,QAAQ;AACZ,MAAI,sBAAsB;AAC1B,WAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK,GAAG;AACzC,UAAM,OAAO,OAAO,CAAC;AACrB,QAAI,CAAC,KAAK,GAAG,EAAE,SAAS,IAAI,EAAG,UAAS;AAAA,aAC/B,CAAC,KAAK,GAAG,EAAE,SAAS,IAAI,EAAG,UAAS;AAAA,aACpC,IAAI,OAAO,SAAS,KAAK,OAAO,MAAM,GAAG,IAAI,CAAC,MAAM,MAAM;AACjE,4BAAsB,uBAAuB,UAAU;AAAA,IACzD;AAAA,EACF;AACA,SAAO;AACT;AAEO,MAAM,cAAuB,CAAC,WAAW,CAAC,QAAQ,MAAM,KAAK,CAAC,mBAAmB,aAAa,EAAE,SAAS,MAAM;AAE/G,MAAM,uBAAgC,CAAC,WAC5C,CAAC,QAAQ,MAAM,KAAK,WAAW;AAE1B,MAAM,6BAAsC,CAAC,WAClD,CAAC,QAAQ,MAAM,KAAK,OAAO,CAAC,MAAM,OAAO,OAAO,MAAM,EAAE,MAAM;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
isFunction,
|
|
8
8
|
isJSXorNode,
|
|
9
9
|
isObject,
|
|
10
|
+
isReactComponentType,
|
|
10
11
|
isPrimitiveType,
|
|
11
12
|
isSomethingWithParenthesis,
|
|
12
13
|
isString,
|
|
@@ -148,6 +149,8 @@ const validateValueWithFormat = (schemaName, key, value, format, validationsMemo
|
|
|
148
149
|
validateObject(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
149
150
|
} else if (isFunction(format)) {
|
|
150
151
|
validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
152
|
+
} else if (isReactComponentType(format)) {
|
|
153
|
+
validateFunction(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
151
154
|
} else if (isJSXorNode(format)) {
|
|
152
155
|
validateJSXorNode(schemaName, key, value, format, validationsMemo, nextValidationsMemo);
|
|
153
156
|
} else if (isSomethingWithParenthesis(format)) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/validation/typescriptValidator.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\n/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport type { PropsWithChildren, WeakValidationMap } from 'react';\nimport { useMemo, useRef } from 'react';\nimport type { TypescriptDocumentation } from '../propTypes/types.js';\nimport { describe } from '../propTypes/index.js';\nimport { throwRequiredError, throwTypeError } from './errorTemplates.js';\nimport {\n isArray,\n isFunction,\n isJSXorNode,\n isObject,\n isPrimitiveType,\n isSomethingWithParenthesis,\n isString,\n isUnion,\n isUndefined,\n isNull,\n isObjectOf,\n} from './typescriptGuards.js';\nimport { typescriptObjectParser } from './typescriptParsers.js';\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): value is Record<string, unknown> {\n return !(typeof value !== 'object' || Array.isArray(value));\n}\n\nconst validateObjectOf: 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 const valuesFormat = format.slice('{ [key: string]: '.length, -2);\n\n Object.keys(value).forEach((objectKey) => {\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}[${objectKey}]`,\n value[objectKey],\n valuesFormat,\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\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, trueKey);\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): 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 (isObjectOf(format)) {\n validateObjectOf(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: TypescriptDocumentation,\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, isRequiredIf, omitValidation } = property;\n\n const requiredConditionally = isRequiredIf && isRequiredIf(props);\n\n if (omitValidation) {\n return;\n }\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (requiredConditionally && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n const shouldValidateProperty = props[name] !== undefined || required || requiredConditionally;\n\n if (name in props && format && shouldValidateProperty) {\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 propTypes: WeakValidationMap<unknown>,\n componentDisplayName: string,\n): void => {\n if (!componentDisplayName) {\n throw new Error('Provide display name for the component to use for validation');\n }\n\n const validationsMemo = useRef<Record<string, string>>({});\n\n const typescriptSchema = useMemo(() => {\n const Component = () => {};\n\n const DescribedComponent = describe(Component);\n DescribedComponent.propTypes = propTypes;\n DescribedComponent.displayName = componentDisplayName;\n return DescribedComponent.toTypescript();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [propTypes]);\n\n useMemo(() => {\n const nextValidationsMemo = {};\n\n validateTypescriptPropTypesImplementation(props, typescriptSchema, validationsMemo.current, nextValidationsMemo);\n validationsMemo.current = nextValidationsMemo;\n return 'WE DONT NEED RETURN just the memo';\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props]);\n};\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,SAAS,cAAc;AAEhC,SAAS,gBAAgB;AACzB,SAAS,oBAAoB,sBAAsB;AACnD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,8BAA8B;AAmBvC,MAAM,oBAAiC,CAAC,YAAY,KAAK,OAAO,WAAW;AACzE,MAAI,UAAU,UAAa,UAAU,aAAa;AAChD,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AACA,MAAM,eAA4B,CAAC,YAAY,KAAK,OAAO,WAAW;AACpE,MAAI,UAAU,QAAQ,UAAU,QAAQ;AACtC,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AACA,MAAM,wBAAqC,CAAC,YAAY,KAAK,OAAO,WAAW;AAC7E,MAAI,OAAO,UAAU,QAAQ;AAC3B,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AAEA,MAAM,iBAA8B,CAAC,YAAY,KAAK,OAAO,WAAW;AACtE,MAAI,UAAU,OAAO,MAAM,GAAG,EAAE,GAAG;AACjC,mBAAe,YAAY,KAAK,OAAO,MAAM;AAAA,EAC/C;AACF;AAEA,MAAM,gBAA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,UAAU,cAAc,eAAe,IAAI;AAEjE,UAAM,wBAAwB,gBAAgB,aAAa,KAAK;AAEhE,QAAI,gBAAgB;AAClB;AAAA,IACF;AAEA,QAAI,YAAY,EAAE,QAAQ,QAAQ;AAChC,yBAAmB,OAAO,MAAM,IAAI;AAAA,IACtC;AAEA,QAAI,yBAAyB,EAAE,QAAQ,QAAQ;AAC7C,yBAAmB,OAAO,MAAM,IAAI;AAAA,IACtC;AAEA,UAAM,yBAAyB,MAAM,IAAI,MAAM,UAAa,YAAY;AAExE,QAAI,QAAQ,SAAS,UAAU,wBAAwB;AACrD,8BAAwB,YAAY,MAAM,MAAM,IAAI,GAAG,QAAQ,iBAAiB,mBAAmB;AAAA,IACrG;AAAA,EACF,CAAC;AACH;AAGO,MAAM,iCAAiC,CAC5C,OACA,WACA,yBACS;AACT,MAAI,CAAC,sBAAsB;AACzB,UAAM,IAAI,MAAM,8DAA8D;AAAA,EAChF;AAEA,QAAM,kBAAkB,OAA+B,CAAC,CAAC;AAEzD,QAAM,mBAAmB,QAAQ,MAAM;AACrC,UAAM,YAAY,MAAM;AAAA,IAAC;AAEzB,UAAM,qBAAqB,SAAS,SAAS;AAC7C,uBAAmB,YAAY;AAC/B,uBAAmB,cAAc;AACjC,WAAO,mBAAmB,aAAa;AAAA,EAEzC,GAAG,CAAC,SAAS,CAAC;AAEd,UAAQ,MAAM;AACZ,UAAM,sBAAsB,CAAC;AAE7B,8CAA0C,OAAO,kBAAkB,gBAAgB,SAAS,mBAAmB;AAC/G,oBAAgB,UAAU;AAC1B,WAAO;AAAA,EAET,GAAG,CAAC,KAAK,CAAC;AACZ;",
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable complexity */\n/* eslint-disable max-lines */\n/* eslint-disable max-params */\nimport type { PropsWithChildren, WeakValidationMap } from 'react';\nimport { useMemo, useRef } from 'react';\nimport type { TypescriptDocumentation } from '../propTypes/types.js';\nimport { describe } from '../propTypes/index.js';\nimport { throwRequiredError, throwTypeError } from './errorTemplates.js';\nimport {\n isArray,\n isFunction,\n isJSXorNode,\n isObject,\n isReactComponentType,\n isPrimitiveType,\n isSomethingWithParenthesis,\n isString,\n isUnion,\n isUndefined,\n isNull,\n isObjectOf,\n} from './typescriptGuards.js';\nimport { typescriptObjectParser } from './typescriptParsers.js';\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): value is Record<string, unknown> {\n return !(typeof value !== 'object' || Array.isArray(value));\n}\n\nconst validateObjectOf: 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 const valuesFormat = format.slice('{ [key: string]: '.length, -2);\n\n Object.keys(value).forEach((objectKey) => {\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}[${objectKey}]`,\n value[objectKey],\n valuesFormat,\n validationsMemo,\n nextValidationsMemo,\n );\n });\n};\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, trueKey);\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): 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 (isObjectOf(format)) {\n validateObjectOf(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 (isReactComponentType(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: TypescriptDocumentation,\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, isRequiredIf, omitValidation } = property;\n\n const requiredConditionally = isRequiredIf && isRequiredIf(props);\n\n if (omitValidation) {\n return;\n }\n\n if (required && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n if (requiredConditionally && !(name in props)) {\n throwRequiredError(schema.name, name);\n }\n\n const shouldValidateProperty = props[name] !== undefined || required || requiredConditionally;\n\n if (name in props && format && shouldValidateProperty) {\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 propTypes: WeakValidationMap<unknown>,\n componentDisplayName: string,\n): void => {\n if (!componentDisplayName) {\n throw new Error('Provide display name for the component to use for validation');\n }\n\n const validationsMemo = useRef<Record<string, string>>({});\n\n const typescriptSchema = useMemo(() => {\n const Component = () => {};\n\n const DescribedComponent = describe(Component);\n DescribedComponent.propTypes = propTypes;\n DescribedComponent.displayName = componentDisplayName;\n return DescribedComponent.toTypescript();\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [propTypes]);\n\n useMemo(() => {\n const nextValidationsMemo = {};\n\n validateTypescriptPropTypesImplementation(props, typescriptSchema, validationsMemo.current, nextValidationsMemo);\n validationsMemo.current = nextValidationsMemo;\n return 'WE DONT NEED RETURN just the memo';\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [props]);\n};\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACIvB,SAAS,SAAS,cAAc;AAEhC,SAAS,gBAAgB;AACzB,SAAS,oBAAoB,sBAAsB;AACnD;AAAA,EACE;AAA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M,IAAI,GAAG,QAAQ,iBAAiB,mBAAmB;AAAA,IACrG;AAAA,EACF,CAAC;AACH;AAGO,MAAM,iCAAiC,CAC5C,OACA,WACA,yBACS;AACT,MAAI,CAAC,sBAAsB;AACzB,UAAM,IAAI,MAAM,8DAA8D;AAAA,EAChF;AAEA,QAAM,kBAAkB,OAA+B,CAAC,CAAC;AAEzD,QAAM,mBAAmB,QAAQ,MAAM;AACrC,UAAM,YAAY,MAAM;AAAA,IAAC;AAEzB,UAAM,qBAAqB,SAAS,SAAS;AAC7C,uBAAmB,YAAY;AAC/B,uBAAmB,cAAc;AACjC,WAAO,mBAAmB,aAAa;AAAA,EAEzC,GAAG,CAAC,SAAS,CAAC;AAEd,UAAQ,MAAM;AACZ,UAAM,sBAAsB,CAAC;AAE7B,8CAA0C,OAAO,kBAAkB,gBAAgB,SAAS,mBAAmB;AAC/G,oBAAgB,UAAU;AAC1B,WAAO;AAAA,EAET,GAAG,CAAC,KAAK,CAAC;AACZ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/xstyledProps/useGetXstyledProps.tsx"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useMemo } from 'react';\nimport type {\n SizingProps,\n SpaceProps,\n LayoutProps,\n BoxShadowProps,\n BorderProps,\n BackgroundProps,\n FontWeightProps,\n TextAlignProps,\n} from '@elliemae/ds-system';\nimport { xstyledKeys } from './constants.js';\n\nexport interface XstyledProps\n extends
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,eAAe;AAWxB,SAAS,mBAAmB;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useMemo } from 'react';\nimport type {\n SizingProps,\n SpaceProps,\n LayoutProps,\n BoxShadowProps,\n BorderProps,\n BackgroundProps,\n FontWeightProps,\n TextAlignProps,\n} from '@elliemae/ds-system';\nimport { xstyledKeys } from './constants.js';\n\nexport interface XstyledProps\n extends\n SpaceProps,\n SizingProps,\n LayoutProps,\n BoxShadowProps,\n BorderProps,\n BackgroundProps,\n FontWeightProps,\n TextAlignProps {}\n\ntype PropsWithXstyled<T> = T & XstyledProps;\n\nexport const getXstyledProps = <T,>(props: PropsWithXstyled<T>): XstyledProps => {\n const xstyledPropsObject: Record<string, unknown> = {};\n Object.entries(props).forEach(([key, value]) => {\n if (key in xstyledKeys) {\n xstyledPropsObject[key] = value;\n }\n });\n return xstyledPropsObject;\n};\n\nexport const useGetXstyledProps = <T,>(props: PropsWithXstyled<T>): XstyledProps =>\n useMemo(() => getXstyledProps(props), [props]);\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,eAAe;AAWxB,SAAS,mBAAmB;AAerB,MAAM,kBAAkB,CAAK,UAA6C;AAC/E,QAAM,qBAA8C,CAAC;AACrD,SAAO,QAAQ,KAAK,EAAE,QAAQ,CAAC,CAAC,KAAK,KAAK,MAAM;AAC9C,QAAI,OAAO,aAAa;AACtB,yBAAmB,GAAG,IAAI;AAAA,IAC5B;AAAA,EACF,CAAC;AACD,SAAO;AACT;AAEO,MAAM,qBAAqB,CAAK,UACrC,QAAQ,MAAM,gBAAgB,KAAK,GAAG,CAAC,KAAK,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Filters an arbitrary object down to the props a component's contract declares.
|
|
3
|
+
*
|
|
4
|
+
* This is the engine behind each package's own curated passthrough utility (e.g. ds-app-picker's
|
|
5
|
+
* `getDSAppPickerContractProps`). Packages are expected to expose a bound utility rather than their
|
|
6
|
+
* schema: the schema stays an internal implementation detail, so the two can drift later without
|
|
7
|
+
* expanding anyone's public API.
|
|
8
|
+
*
|
|
9
|
+
* Three behaviours worth knowing, because callers depend on them:
|
|
10
|
+
*
|
|
11
|
+
* 1. **Documentation-only wildcard keys are ignored.** See `DOCUMENTATION_ONLY_SCHEMA_KEYS`.
|
|
12
|
+
* 2. **`data-*` is honoured by prefix**, matching `getGlobalAttributes` — arbitrary data attributes
|
|
13
|
+
* are a supported consumer surface even though no schema can enumerate them. Note the house
|
|
14
|
+
* behaviour deliberately does not extend the same courtesy to `aria-*` or `on*`: those are
|
|
15
|
+
* matched against the schema's explicit list, so a typo fails loudly instead of reaching the DOM.
|
|
16
|
+
* 3. **`undefined` is dropped, `null` is forwarded.** These two are not interchangeable, and the rule
|
|
17
|
+
* follows React rather than being invented here:
|
|
18
|
+
*
|
|
19
|
+
* - React's own default resolution (`resolveDefaultProps`) applies a `defaultProps` entry only when
|
|
20
|
+
* the incoming prop is `undefined`; a `null` is respected as an explicitly supplied value. This
|
|
21
|
+
* is the same rule as JS destructuring defaults and ES6 default parameters — a language-level
|
|
22
|
+
* standard, not a React invention. So `undefined` means "I am not defining this, you decide" and
|
|
23
|
+
* `null` means "I am defining it, as nothing".
|
|
24
|
+
* - Everywhere React *consumes* a value rather than defaulting it — DOM attributes, children, event
|
|
25
|
+
* handlers — it collapses the two and treats both as absent. The distinction is load-bearing
|
|
26
|
+
* only at a default-resolution boundary.
|
|
27
|
+
*
|
|
28
|
+
* A contract passthrough is exactly such a boundary: the result is spread *after* a wrapper's own
|
|
29
|
+
* defaults, so dropping `undefined` is what stops an unset key from erasing a working default,
|
|
30
|
+
* while forwarding `null` is what lets a consumer deliberately override one. This matters more
|
|
31
|
+
* here than in plain React, because Dimsum's `useMemoMergePropsWithDefault` is a plain
|
|
32
|
+
* `{...defaults, ...props}` spread — it does NOT skip `undefined` the way `resolveDefaultProps`
|
|
33
|
+
* does, so an `undefined` that reaches it clobbers the component's default too.
|
|
34
|
+
*
|
|
35
|
+
* What happens to a forwarded `null` afterwards is the receiving component's business, not this
|
|
36
|
+
* function's. Dimsum components are strictly typed: `validateTypescriptPropTypesImplementation`
|
|
37
|
+
* validates any value that is not `undefined`, and a prop declared as a function does not admit
|
|
38
|
+
* `null` — so passing `null` there raises a prop-type error, correctly. A prop only accepts `null`
|
|
39
|
+
* if its own declared type says so and its code carries the matching null guards. Where a consumer
|
|
40
|
+
* wants to state "do nothing", the type-honouring way to say it is an explicit no-op — `() => {}`
|
|
41
|
+
* for a handler, `() => null` for a component — which is unambiguous in a way that `null` is not.
|
|
42
|
+
* This function stays out of that decision: forwarding the value and letting the owning contract
|
|
43
|
+
* judge it is the correct division of concerns at this abstraction level.
|
|
44
|
+
*
|
|
45
|
+
* @param props - the object to filter; anything the contract does not declare is discarded
|
|
46
|
+
* @param contractShape - any object whose KEYS name the contract's props. Only `Object.keys` is read,
|
|
47
|
+
* so it is deliberately not narrowed to `DSPropTypesSchema`
|
|
48
|
+
*
|
|
49
|
+
* a PropTypes schema is usually fine and there is a code dedicated to discarding the global attributes to make the schema compatible for faster internal transition/implementation.
|
|
50
|
+
* @returns a new object containing only the declared, defined props
|
|
51
|
+
*/
|
|
52
|
+
export declare const getContractProps: <ContractProps>(props: object, contractShape: object) => Partial<ContractProps>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { getContractProps } from './getContractProps.js';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export type { ValidationMap } from 'prop-types';
|
|
|
6
6
|
export { throwTypeError, throwRequiredError, useValidateTypescriptPropTypes, validateTypescriptPropTypesImplementation, } from './validation/index.js';
|
|
7
7
|
export { type XstyledProps, useGetXstyledProps, xstyledPropTypes, getXstyledProps } from './xstyledProps/index.js';
|
|
8
8
|
export { useDeprecateComponent } from './useDeprecateComponent/index.js';
|
|
9
|
+
export { getContractProps } from './contractProps/index.js';
|
|
9
10
|
export { getPropsPerDatatestid, getPropsPerDatatestIdPropTypes } from './propsPerDataTestId/index.js';
|
|
10
11
|
export { getPropsPerSlotPropTypes } from './propsPerSlot/index.js';
|
|
11
12
|
export { useOwnerProps } from './useOwnerProps/index.js';
|
|
@@ -9,5 +9,6 @@ export declare const isObjectOf: GuardFn;
|
|
|
9
9
|
export declare const isObject: GuardFn;
|
|
10
10
|
export declare const isFunction: GuardFn;
|
|
11
11
|
export declare const isJSXorNode: GuardFn;
|
|
12
|
+
export declare const isReactComponentType: GuardFn;
|
|
12
13
|
export declare const isSomethingWithParenthesis: GuardFn;
|
|
13
14
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-props-helpers",
|
|
3
|
-
"version": "3.70.0-
|
|
3
|
+
"version": "3.70.0-rc.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Props Helpers",
|
|
6
6
|
"files": [
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
"sideEffects": [],
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "https://
|
|
22
|
+
"url": "https://github.com/intcx/PLATFORM-UI.dimsum.git"
|
|
23
23
|
},
|
|
24
24
|
"engines": {
|
|
25
25
|
"pnpm": ">=9",
|
|
@@ -35,15 +35,15 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"fast-deep-equal": "~3.1.3",
|
|
37
37
|
"prop-types": "~15.8.1",
|
|
38
|
-
"@elliemae/ds-system": "3.70.0-
|
|
39
|
-
"@elliemae/ds-typescript-helpers": "3.70.0-
|
|
38
|
+
"@elliemae/ds-system": "3.70.0-rc.0",
|
|
39
|
+
"@elliemae/ds-typescript-helpers": "3.70.0-rc.0"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"jest": "^30.0.0",
|
|
43
|
-
"@elliemae/ds-monorepo-devops": "3.70.0-
|
|
43
|
+
"@elliemae/ds-monorepo-devops": "3.70.0-rc.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"lodash-es": "^4.
|
|
46
|
+
"lodash-es": "^4.18.1",
|
|
47
47
|
"react": "^18.3.1",
|
|
48
48
|
"react-dom": "^18.3.1"
|
|
49
49
|
},
|
|
@@ -60,4 +60,4 @@
|
|
|
60
60
|
"build": "cross-env NODE_ENV=production node ../../../scripts/build/build.mjs",
|
|
61
61
|
"checkDeps": "npx -yes ../../util/ds-codemods check-missing-packages --projectFolderPath=\"./\" --ignorePackagesGlobPattern=\"\" --ignoreFilesGlobPattern=\"**/test-ables/*,**/tests/*\""
|
|
62
62
|
}
|
|
63
|
-
}
|
|
63
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function TestComponent(props: any): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const TypescriptSchema: import("../../propTypes/types.js").TypescriptDocumentation;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export function TestComponent(props: any): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|