@elliemae/ds-props-helpers 3.27.0-next.1 → 3.27.0-next.12
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/propTypes/describe.js +22 -2
- package/dist/cjs/propTypes/describe.js.map +2 -2
- package/dist/cjs/propTypes/describeGuards.js +2 -0
- package/dist/cjs/propTypes/describeGuards.js.map +2 -2
- package/dist/cjs/propTypes/toTypescript.js +10 -0
- package/dist/cjs/propTypes/toTypescript.js.map +2 -2
- package/dist/cjs/propTypes/types.js.map +1 -1
- package/dist/esm/propTypes/describe.js +22 -2
- package/dist/esm/propTypes/describe.js.map +2 -2
- package/dist/esm/propTypes/describeGuards.js +2 -0
- package/dist/esm/propTypes/describeGuards.js.map +2 -2
- package/dist/esm/propTypes/toTypescript.js +10 -0
- package/dist/esm/propTypes/toTypescript.js.map +2 -2
- package/dist/types/propTypes/describeGuards.d.ts +1 -0
- package/dist/types/propTypes/types.d.ts +27 -1
- package/package.json +3 -3
|
@@ -34,6 +34,7 @@ module.exports = __toCommonJS(describe_exports);
|
|
|
34
34
|
var React = __toESM(require("react"));
|
|
35
35
|
var import_describeConversions = require("./describeConversions.js");
|
|
36
36
|
var import_toTypescript = __toESM(require("./toTypescript.js"));
|
|
37
|
+
var import_describeGuards = require("./describeGuards.js");
|
|
37
38
|
function describe(ComponentInstance) {
|
|
38
39
|
if (!ComponentInstance) {
|
|
39
40
|
throw new Error("react-desc: component is required");
|
|
@@ -64,9 +65,8 @@ function describe(ComponentInstance) {
|
|
|
64
65
|
}
|
|
65
66
|
Object.keys(value).forEach((name) => {
|
|
66
67
|
const propType = value[name];
|
|
67
|
-
let realPropType;
|
|
68
68
|
documentation.propTypes[name] = propType;
|
|
69
|
-
realPropType = (0, import_describeConversions.convertPropType)(propType);
|
|
69
|
+
const realPropType = (0, import_describeConversions.convertPropType)(propType);
|
|
70
70
|
DocumentedComponent.propTypesValue[name] = realPropType;
|
|
71
71
|
return propType;
|
|
72
72
|
});
|
|
@@ -74,6 +74,26 @@ function describe(ComponentInstance) {
|
|
|
74
74
|
enumerable: true,
|
|
75
75
|
configurable: true
|
|
76
76
|
});
|
|
77
|
+
Object.defineProperty(DocumentedComponent, "returnType", {
|
|
78
|
+
get: () => DocumentedComponent.returnTypeValue,
|
|
79
|
+
set: (value) => {
|
|
80
|
+
if ((0, import_describeGuards.isReactDesc)(value)) {
|
|
81
|
+
DocumentedComponent.returnTypeValue = (0, import_describeConversions.convertPropType)(value);
|
|
82
|
+
documentation.returnType = value;
|
|
83
|
+
} else {
|
|
84
|
+
DocumentedComponent.returnTypeValue = {};
|
|
85
|
+
Object.keys(value).forEach((name) => {
|
|
86
|
+
const propType = value[name];
|
|
87
|
+
documentation.returnType = { ...documentation.returnType ?? {}, [name]: propType };
|
|
88
|
+
const realPropType = (0, import_describeConversions.convertPropType)(propType);
|
|
89
|
+
DocumentedComponent.returnTypeValue = { ...DocumentedComponent.returnTypeValue, [name]: realPropType };
|
|
90
|
+
return propType;
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
enumerable: true,
|
|
95
|
+
configurable: true
|
|
96
|
+
});
|
|
77
97
|
return DocumentedComponent;
|
|
78
98
|
}
|
|
79
99
|
//# sourceMappingURL=describe.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/propTypes/describe.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable react/forbid-foreign-prop-types */\nimport type { Requireable, Validator } from 'prop-types';\nimport type React from 'react';\nimport { convertPropType } from './describeConversions.js';\nimport descToTypescript from './toTypescript.js';\nimport type { ReactDescT, Hook, ComponentDocumentation, DocumentedReactComponent } from './types.js';\n\nexport default function describe<C, R>(ComponentInstance: React.ComponentType<C> | Hook<C, R>) {\n if (!ComponentInstance) {\n throw new Error('react-desc: component is required');\n }\n\n const documentation: ComponentDocumentation = {\n propTypes: {},\n };\n\n const DocumentedComponent = ComponentInstance as DocumentedReactComponent<C>;\n\n const addDocumentationProp = <T extends keyof ComponentDocumentation>(propName: T) => {\n const func = (value: ComponentDocumentation[T]): DocumentedReactComponent<C> => {\n documentation[propName] = value;\n return DocumentedComponent;\n };\n return func;\n };\n\n DocumentedComponent.availableAt = addDocumentationProp('availableAt');\n DocumentedComponent.description = addDocumentationProp('description');\n DocumentedComponent.details = addDocumentationProp('details');\n DocumentedComponent.deprecated = addDocumentationProp('deprecated');\n DocumentedComponent.usage = addDocumentationProp('usage');\n DocumentedComponent.intrinsicElement = addDocumentationProp('intrinsicElement');\n\n DocumentedComponent.toTypescript = () => descToTypescript(ComponentInstance, documentation);\n\n Object.defineProperty(DocumentedComponent, 'propTypes', {\n get: () => DocumentedComponent.propTypesValue,\n set: (value: Record<string, ReactDescT>) => {\n if (!DocumentedComponent.propTypesValue) {\n DocumentedComponent.propTypesValue = {};\n }\n\n Object.keys(value).forEach((name) => {\n const propType: ReactDescT = value[name];\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADGvB,iCAAgC;AAChC,0BAA6B;
|
|
4
|
+
"sourcesContent": ["/* eslint-disable react/forbid-foreign-prop-types */\nimport type { Requireable, Validator } from 'prop-types';\nimport type React from 'react';\nimport { convertPropType } from './describeConversions.js';\nimport descToTypescript from './toTypescript.js';\nimport type { ReactDescT, Hook, ComponentDocumentation, DocumentedReactComponent } from './types.js';\nimport { isReactDesc } from './describeGuards.js';\n\nexport default function describe<C, R>(ComponentInstance: React.ComponentType<C> | Hook<C, R>) {\n if (!ComponentInstance) {\n throw new Error('react-desc: component is required');\n }\n\n const documentation: ComponentDocumentation = {\n propTypes: {},\n };\n\n const DocumentedComponent = ComponentInstance as DocumentedReactComponent<C>;\n\n const addDocumentationProp = <T extends keyof ComponentDocumentation>(propName: T) => {\n const func = (value: ComponentDocumentation[T]): DocumentedReactComponent<C> => {\n documentation[propName] = value;\n return DocumentedComponent;\n };\n return func;\n };\n\n DocumentedComponent.availableAt = addDocumentationProp('availableAt');\n DocumentedComponent.description = addDocumentationProp('description');\n DocumentedComponent.details = addDocumentationProp('details');\n DocumentedComponent.deprecated = addDocumentationProp('deprecated');\n DocumentedComponent.usage = addDocumentationProp('usage');\n DocumentedComponent.intrinsicElement = addDocumentationProp('intrinsicElement');\n\n DocumentedComponent.toTypescript = () => descToTypescript(ComponentInstance, documentation);\n\n Object.defineProperty(DocumentedComponent, 'propTypes', {\n get: () => DocumentedComponent.propTypesValue,\n set: (value: Record<string, ReactDescT>) => {\n if (!DocumentedComponent.propTypesValue) {\n DocumentedComponent.propTypesValue = {};\n }\n\n Object.keys(value).forEach((name) => {\n const propType: ReactDescT = value[name];\n documentation.propTypes[name] = propType;\n const realPropType: Requireable<unknown> | Validator<unknown> = convertPropType(propType);\n // We don't need to rely on the isRequired from prop-types package\n // So no need to invoke (realPropType).isRequired if our own proptype is required\n // Validation will handle that case for us\n DocumentedComponent.propTypesValue[name] = realPropType as Validator<unknown>;\n return propType;\n });\n },\n enumerable: true,\n configurable: true,\n });\n\n Object.defineProperty(DocumentedComponent, 'returnType', {\n get: () => DocumentedComponent.returnTypeValue,\n set: (value: ReactDescT | Record<string, ReactDescT>) => {\n if (isReactDesc(value)) {\n DocumentedComponent.returnTypeValue = convertPropType(value);\n documentation.returnType = value;\n } else {\n DocumentedComponent.returnTypeValue = {};\n Object.keys(value).forEach((name) => {\n const propType: ReactDescT = value[name];\n documentation.returnType = { ...(documentation.returnType ?? {}), [name]: propType };\n const realPropType: Requireable<unknown> | Validator<unknown> = convertPropType(propType);\n DocumentedComponent.returnTypeValue = { ...DocumentedComponent.returnTypeValue, [name]: realPropType };\n return propType;\n });\n }\n },\n enumerable: true,\n configurable: true,\n });\n\n return DocumentedComponent;\n}\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mapp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;AAAA,IAC/B,KAAK,CAAC,UAAmD;AACvD,cAAI,mCAAY,KAAK,GAAG;AACtB,4BAAoB,sBAAkB,4CAAgB,KAAK;AAC3D,sBAAc,aAAa;AAAA,MAC7B,OAAO;AACL,4BAAoB,kBAAkB,CAAC;AACvC,eAAO,KAAK,KAAK,EAAE,QAAQ,CAAC,SAAS;AACnC,gBAAM,WAAuB,MAAM,IAAI;AACvC,wBAAc,aAAa,EAAE,GAAI,cAAc,cAAc,CAAC,GAAI,CAAC,IAAI,GAAG,SAAS;AACnF,gBAAM,mBAA0D,4CAAgB,QAAQ;AACxF,8BAAoB,kBAAkB,EAAE,GAAG,oBAAoB,iBAAiB,CAAC,IAAI,GAAG,aAAa;AACrG,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB,CAAC;AAED,SAAO;AACT;",
|
|
6
6
|
"names": ["descToTypescript"]
|
|
7
7
|
}
|
|
@@ -35,6 +35,7 @@ __export(describeGuards_exports, {
|
|
|
35
35
|
isObjectOf: () => isObjectOf,
|
|
36
36
|
isOneOf: () => isOneOf,
|
|
37
37
|
isOneOfType: () => isOneOfType,
|
|
38
|
+
isReactDesc: () => isReactDesc,
|
|
38
39
|
isShape: () => isShape
|
|
39
40
|
});
|
|
40
41
|
module.exports = __toCommonJS(describeGuards_exports);
|
|
@@ -47,4 +48,5 @@ const isInstanceOf = (propType, realPropType) => propType.type === "instanceOf";
|
|
|
47
48
|
const isOneOf = (propType, realPropType) => propType.type === "oneOf";
|
|
48
49
|
const isObjectOf = (propType, realPropType) => propType.type === "objectOf";
|
|
49
50
|
const isExact = (propType, realPropType) => propType.type === "exact";
|
|
51
|
+
const isReactDesc = (reactDesc) => reactDesc && typeof reactDesc === "object" && "reactDesc" in reactDesc;
|
|
50
52
|
//# sourceMappingURL=describeGuards.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/propTypes/describeGuards.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["import type {\n AllPropTypes,\n ArrayOfT,\n ExactT,\n InstanceOfT,\n ObjectOfT,\n OneOfT,\n OneOfTypeT,\n ParametizedPropTypes,\n ReactDescT,\n ShapeT,\n} from './types.js';\n\nexport const hasArguments = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ParametizedPropTypes =>\n !!propType.args;\n\nexport const isOneOfType = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is OneOfTypeT =>\n propType.type === 'oneOfType';\n\nexport const isArrayOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ArrayOfT =>\n propType.type === 'arrayOf';\n\nexport const isShape = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ShapeT =>\n propType.type === 'shape';\n\nexport const isInstanceOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is InstanceOfT =>\n propType.type === 'instanceOf';\n\nexport const isOneOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is OneOfT =>\n propType.type === 'oneOf';\n\nexport const isObjectOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ObjectOfT =>\n propType.type === 'objectOf';\n\nexport const isExact = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ExactT =>\n propType.type === 'exact';\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADahB,MAAM,eAAe,CAAC,UAAsB,iBACjD,CAAC,CAAC,SAAS;AAEN,MAAM,cAAc,CAAC,UAAsB,iBAChD,SAAS,SAAS;AAEb,MAAM,YAAY,CAAC,UAAsB,iBAC9C,SAAS,SAAS;AAEb,MAAM,UAAU,CAAC,UAAsB,iBAC5C,SAAS,SAAS;AAEb,MAAM,eAAe,CAAC,UAAsB,iBACjD,SAAS,SAAS;AAEb,MAAM,UAAU,CAAC,UAAsB,iBAC5C,SAAS,SAAS;AAEb,MAAM,aAAa,CAAC,UAAsB,iBAC/C,SAAS,SAAS;AAEb,MAAM,UAAU,CAAC,UAAsB,iBAC5C,SAAS,SAAS;",
|
|
4
|
+
"sourcesContent": ["import type {\n AllPropTypes,\n ArrayOfT,\n ExactT,\n InstanceOfT,\n ObjectOfT,\n OneOfT,\n OneOfTypeT,\n ParametizedPropTypes,\n ReactDescT,\n ShapeT,\n} from './types.js';\n\nexport const hasArguments = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ParametizedPropTypes =>\n !!propType.args;\n\nexport const isOneOfType = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is OneOfTypeT =>\n propType.type === 'oneOfType';\n\nexport const isArrayOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ArrayOfT =>\n propType.type === 'arrayOf';\n\nexport const isShape = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ShapeT =>\n propType.type === 'shape';\n\nexport const isInstanceOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is InstanceOfT =>\n propType.type === 'instanceOf';\n\nexport const isOneOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is OneOfT =>\n propType.type === 'oneOf';\n\nexport const isObjectOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ObjectOfT =>\n propType.type === 'objectOf';\n\nexport const isExact = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ExactT =>\n propType.type === 'exact';\n\nexport const isReactDesc = (reactDesc: object): reactDesc is ReactDescT =>\n reactDesc && typeof reactDesc === 'object' && 'reactDesc' in reactDesc;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADahB,MAAM,eAAe,CAAC,UAAsB,iBACjD,CAAC,CAAC,SAAS;AAEN,MAAM,cAAc,CAAC,UAAsB,iBAChD,SAAS,SAAS;AAEb,MAAM,YAAY,CAAC,UAAsB,iBAC9C,SAAS,SAAS;AAEb,MAAM,UAAU,CAAC,UAAsB,iBAC5C,SAAS,SAAS;AAEb,MAAM,eAAe,CAAC,UAAsB,iBACjD,SAAS,SAAS;AAEb,MAAM,UAAU,CAAC,UAAsB,iBAC5C,SAAS,SAAS;AAEb,MAAM,aAAa,CAAC,UAAsB,iBAC/C,SAAS,SAAS;AAEb,MAAM,UAAU,CAAC,UAAsB,iBAC5C,SAAS,SAAS;AAEb,MAAM,cAAc,CAAC,cAC1B,aAAa,OAAO,cAAc,YAAY,eAAe;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -32,6 +32,7 @@ __export(toTypescript_exports, {
|
|
|
32
32
|
});
|
|
33
33
|
module.exports = __toCommonJS(toTypescript_exports);
|
|
34
34
|
var React = __toESM(require("react"));
|
|
35
|
+
var import_describeGuards = require("./describeGuards.js");
|
|
35
36
|
const arrayFormat = (array) => array.map((propType) => propTypeFormat(propType));
|
|
36
37
|
const shapeFormat = (shape) => {
|
|
37
38
|
const props = Object.keys(shape).map((key) => {
|
|
@@ -145,6 +146,15 @@ function descToTypescript(component, reactDesc) {
|
|
|
145
146
|
documentation.properties = propTypes;
|
|
146
147
|
}
|
|
147
148
|
}
|
|
149
|
+
if (reactDesc.returnType) {
|
|
150
|
+
if ((0, import_describeGuards.isReactDesc)(reactDesc.returnType)) {
|
|
151
|
+
documentation.returns = propTypeAsTypescript(reactDesc.returnType, "returns");
|
|
152
|
+
} else {
|
|
153
|
+
documentation.returns = Object.entries(reactDesc.returnType).map(
|
|
154
|
+
([propName, propType]) => propTypeAsTypescript(propType, propName)
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
148
158
|
}
|
|
149
159
|
return documentation;
|
|
150
160
|
}
|
|
@@ -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';\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 }\n return documentation as TypescriptDocumentation;\n}\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;
|
|
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": ";;;;;;;;;;;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,UAAU;AAAO;AAC/B,qBAAS,UAAU,MAAM,IAAI,IAAI;AAAA,cAC9B,SAAS,KAAoC,IAAI;AAAA,cAClD;AAAA,YACF;AAAA,UACF,CAAC;AAAA,QACH;AACA,kBAAU,KAAK,qBAAqB,UAAU,QAAQ,CAAC;AAAA,MACzD,CAAC;AACD,UAAI,UAAU,SAAS,GAAG;AACxB,sBAAc,aAAa;AAAA,MAC7B;AAAA,IACF;AACA,QAAI,UAAU,YAAY;AACxB,cAAI,mCAAY,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,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/propTypes/types.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
|
|
4
|
-
"sourcesContent": ["
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-lines */\nimport type {\n any,\n array,\n bool,\n func,\n number,\n object,\n string,\n node,\n element,\n symbol,\n elementType,\n instanceOf,\n oneOf,\n oneOfType,\n arrayOf,\n objectOf,\n shape,\n exact,\n Validator,\n ValidationMap,\n} from 'prop-types';\nimport type React from 'react';\n\nexport interface ReactDescObjT {\n [key: string]: unknown;\n required?: boolean;\n deprecated?: Record<string, string>;\n description?: string;\n defaultValue?: unknown;\n format?: string;\n signature?: string;\n warned?: boolean;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n isRequiredIf?: (props: any) => boolean;\n group?: Record<string, unknown>;\n}\n\nexport type InstanceOfT = typeof instanceOf;\nexport type OneOfT = typeof oneOf;\nexport type ObjectOfT = typeof objectOf;\nexport type ExactT = typeof exact;\nexport type OneOfTypeT = typeof oneOfType;\nexport type ArrayOfT = typeof arrayOf;\nexport type ShapeT = typeof shape;\nexport type AnyT = typeof any;\nexport type ArrayT = typeof array;\nexport type BoolT = typeof bool;\nexport type FuncT = typeof func;\nexport type NumberT = typeof number;\nexport type ObjectT = typeof object;\nexport type StringT = typeof string;\nexport type NodeT = typeof node;\nexport type ElementT = typeof element;\nexport type SymbolT = typeof symbol;\nexport type ElementTypeT = typeof elementType;\n\nexport type ParametizedPropTypes = InstanceOfT | OneOfT | ObjectOfT | ExactT | OneOfTypeT | ArrayOfT | ShapeT;\n\nexport type AllPropTypes =\n | AnyT\n | ArrayT\n | BoolT\n | FuncT\n | NumberT\n | ObjectT\n | StringT\n | NodeT\n | ElementT\n | SymbolT\n | ElementTypeT\n | ParametizedPropTypes;\n\nexport type PropTypesTypes =\n | 'any'\n | 'array'\n | 'bool'\n | 'func'\n | 'number'\n | 'object'\n | 'string'\n | 'node'\n | 'element'\n | 'symbol'\n | 'elementType'\n | 'instanceOf'\n | 'oneOf'\n | 'oneOfType'\n | 'arrayOf'\n | 'objectOf'\n | 'shape'\n | 'exact'\n | 'tuple';\n\nexport interface ReactDescT {\n [key: string]: unknown;\n type: PropTypesTypes;\n defaultValue: (this: ReactDescT, dfault: unknown) => ReactDescT;\n deprecated: (this: ReactDescT, info: Record<string, string>) => ReactDescT;\n description: (this: ReactDescT, descr: string) => ReactDescT;\n format: (this: ReactDescT, format: string) => ReactDescT;\n signature: (this: ReactDescT, format: string) => ReactDescT;\n hidden: (this: ReactDescT) => ReactDescT;\n dataTestId: (this: ReactDescT) => ReactDescT;\n global: (this: ReactDescT) => ReactDescT;\n xstyled: (this: ReactDescT) => ReactDescT;\n omitValidation: (this: ReactDescT) => ReactDescT;\n isRequired: ReactDescT;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n isRequiredIf: (this: ReactDescT, isRequiredIf: (props: any) => boolean) => ReactDescT;\n reactDesc: ReactDescObjT;\n args?:\n | ReactDescT\n | ReactDescT[]\n | Record<string, ReactDescT>\n | unknown[]\n | Parameters<InstanceOfT>[0]\n | Parameters<OneOfT>[0]\n | Parameters<ObjectOfT>[0]\n | Parameters<ExactT>[0];\n}\n\nexport interface ComponentDocumentation {\n propTypes: Record<string, ReactDescT>;\n returnType?: ReactDescT | Record<string, ReactDescT>;\n availableAt?: unknown;\n description?: string;\n details?: unknown;\n deprecated?: unknown;\n usage?: unknown;\n intrinsicElement?: unknown;\n toTypescript?: unknown;\n}\n\nexport interface TypescriptDocumentation extends Partial<ComponentDocumentation> {\n name: string;\n description: string;\n properties: {\n name: string;\n required?: boolean | undefined;\n deprecated?: Record<string, string> | undefined;\n description?: string;\n format?: string;\n signature?: string;\n warned?: boolean;\n defaultValue?: unknown;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n isRequiredIf?: (props: any) => boolean;\n omitValidation?: boolean;\n }[];\n returns?:\n | {\n name: string;\n required?: boolean | undefined;\n deprecated?: Record<string, string> | undefined;\n description?: string;\n format?: string;\n signature?: string;\n warned?: boolean;\n defaultValue?: unknown;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n isRequiredIf?: (props: any) => boolean;\n omitValidation?: boolean;\n }\n | {\n name: string;\n required?: boolean | undefined;\n deprecated?: Record<string, string> | undefined;\n description?: string;\n format?: string;\n signature?: string;\n warned?: boolean;\n defaultValue?: unknown;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n isRequiredIf?: (props: any) => boolean;\n omitValidation?: boolean;\n }[];\n}\n\nexport type DocumentedReactComponent<T> = React.ComponentType<T> & {\n availableAt: unknown;\n description: (descr: string) => DocumentedReactComponent<T>;\n details: unknown;\n deprecated: unknown;\n usage: unknown;\n intrinsicElement: unknown;\n toTypescript: () => TypescriptDocumentation;\n propTypesValue: ValidationMap<Record<string, unknown>>;\n returnType: ReactDescT | Record<string, ReactDescT>;\n returnTypeValue: Validator<unknown> | ValidationMap<Record<string, unknown>>;\n};\n\nexport type Hook<T = unknown, S = unknown> = ((props: T) => S) & { displayName?: string; name?: string };\n\nexport type DocumentedPropType = ReactDescT;\n\nexport type PropTypesObj = {\n any: DocumentedPropType;\n array: DocumentedPropType;\n bool: DocumentedPropType;\n func: DocumentedPropType;\n number: DocumentedPropType;\n object: DocumentedPropType;\n string: DocumentedPropType;\n node: DocumentedPropType;\n element: DocumentedPropType;\n symbol: DocumentedPropType;\n elementType: DocumentedPropType;\n instanceOf: (cls: unknown) => DocumentedPropType;\n oneOf: (arr: unknown[]) => DocumentedPropType;\n oneOfType: (arr: DocumentedPropType[]) => DocumentedPropType;\n arrayOf: (smth: DocumentedPropType) => DocumentedPropType;\n objectOf: (smth: DocumentedPropType) => DocumentedPropType;\n shape: (obj: Record<string, DocumentedPropType>) => DocumentedPropType;\n exact: (obj: Record<string, DocumentedPropType>) => DocumentedPropType;\n tuple: (arr: DocumentedPropType[]) => DocumentedPropType;\n};\n\nexport type DSPropTypesSchema<T> = Required<{ [key in keyof T]: ReactDescT }>;\n", "import * as React from 'react';\nexport { React };\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;ACAA,YAAuB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { convertPropType } from "./describeConversions.js";
|
|
3
3
|
import descToTypescript from "./toTypescript.js";
|
|
4
|
+
import { isReactDesc } from "./describeGuards.js";
|
|
4
5
|
function describe(ComponentInstance) {
|
|
5
6
|
if (!ComponentInstance) {
|
|
6
7
|
throw new Error("react-desc: component is required");
|
|
@@ -31,9 +32,8 @@ function describe(ComponentInstance) {
|
|
|
31
32
|
}
|
|
32
33
|
Object.keys(value).forEach((name) => {
|
|
33
34
|
const propType = value[name];
|
|
34
|
-
let realPropType;
|
|
35
35
|
documentation.propTypes[name] = propType;
|
|
36
|
-
realPropType = convertPropType(propType);
|
|
36
|
+
const realPropType = convertPropType(propType);
|
|
37
37
|
DocumentedComponent.propTypesValue[name] = realPropType;
|
|
38
38
|
return propType;
|
|
39
39
|
});
|
|
@@ -41,6 +41,26 @@ function describe(ComponentInstance) {
|
|
|
41
41
|
enumerable: true,
|
|
42
42
|
configurable: true
|
|
43
43
|
});
|
|
44
|
+
Object.defineProperty(DocumentedComponent, "returnType", {
|
|
45
|
+
get: () => DocumentedComponent.returnTypeValue,
|
|
46
|
+
set: (value) => {
|
|
47
|
+
if (isReactDesc(value)) {
|
|
48
|
+
DocumentedComponent.returnTypeValue = convertPropType(value);
|
|
49
|
+
documentation.returnType = value;
|
|
50
|
+
} else {
|
|
51
|
+
DocumentedComponent.returnTypeValue = {};
|
|
52
|
+
Object.keys(value).forEach((name) => {
|
|
53
|
+
const propType = value[name];
|
|
54
|
+
documentation.returnType = { ...documentation.returnType ?? {}, [name]: propType };
|
|
55
|
+
const realPropType = convertPropType(propType);
|
|
56
|
+
DocumentedComponent.returnTypeValue = { ...DocumentedComponent.returnTypeValue, [name]: realPropType };
|
|
57
|
+
return propType;
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
enumerable: true,
|
|
62
|
+
configurable: true
|
|
63
|
+
});
|
|
44
64
|
return DocumentedComponent;
|
|
45
65
|
}
|
|
46
66
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/propTypes/describe.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable react/forbid-foreign-prop-types */\nimport type { Requireable, Validator } from 'prop-types';\nimport type React from 'react';\nimport { convertPropType } from './describeConversions.js';\nimport descToTypescript from './toTypescript.js';\nimport type { ReactDescT, Hook, ComponentDocumentation, DocumentedReactComponent } from './types.js';\n\nexport default function describe<C, R>(ComponentInstance: React.ComponentType<C> | Hook<C, R>) {\n if (!ComponentInstance) {\n throw new Error('react-desc: component is required');\n }\n\n const documentation: ComponentDocumentation = {\n propTypes: {},\n };\n\n const DocumentedComponent = ComponentInstance as DocumentedReactComponent<C>;\n\n const addDocumentationProp = <T extends keyof ComponentDocumentation>(propName: T) => {\n const func = (value: ComponentDocumentation[T]): DocumentedReactComponent<C> => {\n documentation[propName] = value;\n return DocumentedComponent;\n };\n return func;\n };\n\n DocumentedComponent.availableAt = addDocumentationProp('availableAt');\n DocumentedComponent.description = addDocumentationProp('description');\n DocumentedComponent.details = addDocumentationProp('details');\n DocumentedComponent.deprecated = addDocumentationProp('deprecated');\n DocumentedComponent.usage = addDocumentationProp('usage');\n DocumentedComponent.intrinsicElement = addDocumentationProp('intrinsicElement');\n\n DocumentedComponent.toTypescript = () => descToTypescript(ComponentInstance, documentation);\n\n Object.defineProperty(DocumentedComponent, 'propTypes', {\n get: () => DocumentedComponent.propTypesValue,\n set: (value: Record<string, ReactDescT>) => {\n if (!DocumentedComponent.propTypesValue) {\n DocumentedComponent.propTypesValue = {};\n }\n\n Object.keys(value).forEach((name) => {\n const propType: ReactDescT = value[name];\n
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACGvB,SAAS,uBAAuB;AAChC,OAAO,sBAAsB;
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable react/forbid-foreign-prop-types */\nimport type { Requireable, Validator } from 'prop-types';\nimport type React from 'react';\nimport { convertPropType } from './describeConversions.js';\nimport descToTypescript from './toTypescript.js';\nimport type { ReactDescT, Hook, ComponentDocumentation, DocumentedReactComponent } from './types.js';\nimport { isReactDesc } from './describeGuards.js';\n\nexport default function describe<C, R>(ComponentInstance: React.ComponentType<C> | Hook<C, R>) {\n if (!ComponentInstance) {\n throw new Error('react-desc: component is required');\n }\n\n const documentation: ComponentDocumentation = {\n propTypes: {},\n };\n\n const DocumentedComponent = ComponentInstance as DocumentedReactComponent<C>;\n\n const addDocumentationProp = <T extends keyof ComponentDocumentation>(propName: T) => {\n const func = (value: ComponentDocumentation[T]): DocumentedReactComponent<C> => {\n documentation[propName] = value;\n return DocumentedComponent;\n };\n return func;\n };\n\n DocumentedComponent.availableAt = addDocumentationProp('availableAt');\n DocumentedComponent.description = addDocumentationProp('description');\n DocumentedComponent.details = addDocumentationProp('details');\n DocumentedComponent.deprecated = addDocumentationProp('deprecated');\n DocumentedComponent.usage = addDocumentationProp('usage');\n DocumentedComponent.intrinsicElement = addDocumentationProp('intrinsicElement');\n\n DocumentedComponent.toTypescript = () => descToTypescript(ComponentInstance, documentation);\n\n Object.defineProperty(DocumentedComponent, 'propTypes', {\n get: () => DocumentedComponent.propTypesValue,\n set: (value: Record<string, ReactDescT>) => {\n if (!DocumentedComponent.propTypesValue) {\n DocumentedComponent.propTypesValue = {};\n }\n\n Object.keys(value).forEach((name) => {\n const propType: ReactDescT = value[name];\n documentation.propTypes[name] = propType;\n const realPropType: Requireable<unknown> | Validator<unknown> = convertPropType(propType);\n // We don't need to rely on the isRequired from prop-types package\n // So no need to invoke (realPropType).isRequired if our own proptype is required\n // Validation will handle that case for us\n DocumentedComponent.propTypesValue[name] = realPropType as Validator<unknown>;\n return propType;\n });\n },\n enumerable: true,\n configurable: true,\n });\n\n Object.defineProperty(DocumentedComponent, 'returnType', {\n get: () => DocumentedComponent.returnTypeValue,\n set: (value: ReactDescT | Record<string, ReactDescT>) => {\n if (isReactDesc(value)) {\n DocumentedComponent.returnTypeValue = convertPropType(value);\n documentation.returnType = value;\n } else {\n DocumentedComponent.returnTypeValue = {};\n Object.keys(value).forEach((name) => {\n const propType: ReactDescT = value[name];\n documentation.returnType = { ...(documentation.returnType ?? {}), [name]: propType };\n const realPropType: Requireable<unknown> | Validator<unknown> = convertPropType(propType);\n DocumentedComponent.returnTypeValue = { ...DocumentedComponent.returnTypeValue, [name]: realPropType };\n return propType;\n });\n }\n },\n enumerable: true,\n configurable: true,\n });\n\n return DocumentedComponent;\n}\n"],
|
|
5
|
+
"mappings": "AA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K,GAAG;AACtB,4BAAoB,kBAAkB,gBAAgB,KAAK;AAC3D,sBAAc,aAAa;AAAA,MAC7B,OAAO;AACL,4BAAoB,kBAAkB,CAAC;AACvC,eAAO,KAAK,KAAK,EAAE,QAAQ,CAAC,SAAS;AACnC,gBAAM,WAAuB,MAAM,IAAI;AACvC,wBAAc,aAAa,EAAE,GAAI,cAAc,cAAc,CAAC,GAAI,CAAC,IAAI,GAAG,SAAS;AACnF,gBAAM,eAA0D,gBAAgB,QAAQ;AACxF,8BAAoB,kBAAkB,EAAE,GAAG,oBAAoB,iBAAiB,CAAC,IAAI,GAAG,aAAa;AACrG,iBAAO;AAAA,QACT,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,YAAY;AAAA,IACZ,cAAc;AAAA,EAChB,CAAC;AAED,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,6 +7,7 @@ const isInstanceOf = (propType, realPropType) => propType.type === "instanceOf";
|
|
|
7
7
|
const isOneOf = (propType, realPropType) => propType.type === "oneOf";
|
|
8
8
|
const isObjectOf = (propType, realPropType) => propType.type === "objectOf";
|
|
9
9
|
const isExact = (propType, realPropType) => propType.type === "exact";
|
|
10
|
+
const isReactDesc = (reactDesc) => reactDesc && typeof reactDesc === "object" && "reactDesc" in reactDesc;
|
|
10
11
|
export {
|
|
11
12
|
hasArguments,
|
|
12
13
|
isArrayOf,
|
|
@@ -15,6 +16,7 @@ export {
|
|
|
15
16
|
isObjectOf,
|
|
16
17
|
isOneOf,
|
|
17
18
|
isOneOfType,
|
|
19
|
+
isReactDesc,
|
|
18
20
|
isShape
|
|
19
21
|
};
|
|
20
22
|
//# sourceMappingURL=describeGuards.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/propTypes/describeGuards.ts"],
|
|
4
|
-
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type {\n AllPropTypes,\n ArrayOfT,\n ExactT,\n InstanceOfT,\n ObjectOfT,\n OneOfT,\n OneOfTypeT,\n ParametizedPropTypes,\n ReactDescT,\n ShapeT,\n} from './types.js';\n\nexport const hasArguments = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ParametizedPropTypes =>\n !!propType.args;\n\nexport const isOneOfType = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is OneOfTypeT =>\n propType.type === 'oneOfType';\n\nexport const isArrayOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ArrayOfT =>\n propType.type === 'arrayOf';\n\nexport const isShape = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ShapeT =>\n propType.type === 'shape';\n\nexport const isInstanceOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is InstanceOfT =>\n propType.type === 'instanceOf';\n\nexport const isOneOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is OneOfT =>\n propType.type === 'oneOf';\n\nexport const isObjectOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ObjectOfT =>\n propType.type === 'objectOf';\n\nexport const isExact = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ExactT =>\n propType.type === 'exact';\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;ACahB,MAAM,eAAe,CAAC,UAAsB,iBACjD,CAAC,CAAC,SAAS;AAEN,MAAM,cAAc,CAAC,UAAsB,iBAChD,SAAS,SAAS;AAEb,MAAM,YAAY,CAAC,UAAsB,iBAC9C,SAAS,SAAS;AAEb,MAAM,UAAU,CAAC,UAAsB,iBAC5C,SAAS,SAAS;AAEb,MAAM,eAAe,CAAC,UAAsB,iBACjD,SAAS,SAAS;AAEb,MAAM,UAAU,CAAC,UAAsB,iBAC5C,SAAS,SAAS;AAEb,MAAM,aAAa,CAAC,UAAsB,iBAC/C,SAAS,SAAS;AAEb,MAAM,UAAU,CAAC,UAAsB,iBAC5C,SAAS,SAAS;",
|
|
4
|
+
"sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import type {\n AllPropTypes,\n ArrayOfT,\n ExactT,\n InstanceOfT,\n ObjectOfT,\n OneOfT,\n OneOfTypeT,\n ParametizedPropTypes,\n ReactDescT,\n ShapeT,\n} from './types.js';\n\nexport const hasArguments = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ParametizedPropTypes =>\n !!propType.args;\n\nexport const isOneOfType = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is OneOfTypeT =>\n propType.type === 'oneOfType';\n\nexport const isArrayOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ArrayOfT =>\n propType.type === 'arrayOf';\n\nexport const isShape = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ShapeT =>\n propType.type === 'shape';\n\nexport const isInstanceOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is InstanceOfT =>\n propType.type === 'instanceOf';\n\nexport const isOneOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is OneOfT =>\n propType.type === 'oneOf';\n\nexport const isObjectOf = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ObjectOfT =>\n propType.type === 'objectOf';\n\nexport const isExact = (propType: ReactDescT, realPropType: AllPropTypes): realPropType is ExactT =>\n propType.type === 'exact';\n\nexport const isReactDesc = (reactDesc: object): reactDesc is ReactDescT =>\n reactDesc && typeof reactDesc === 'object' && 'reactDesc' in reactDesc;\n"],
|
|
5
|
+
"mappings": "AAAA,YAAY,WAAW;ACahB,MAAM,eAAe,CAAC,UAAsB,iBACjD,CAAC,CAAC,SAAS;AAEN,MAAM,cAAc,CAAC,UAAsB,iBAChD,SAAS,SAAS;AAEb,MAAM,YAAY,CAAC,UAAsB,iBAC9C,SAAS,SAAS;AAEb,MAAM,UAAU,CAAC,UAAsB,iBAC5C,SAAS,SAAS;AAEb,MAAM,eAAe,CAAC,UAAsB,iBACjD,SAAS,SAAS;AAEb,MAAM,UAAU,CAAC,UAAsB,iBAC5C,SAAS,SAAS;AAEb,MAAM,aAAa,CAAC,UAAsB,iBAC/C,SAAS,SAAS;AAEb,MAAM,UAAU,CAAC,UAAsB,iBAC5C,SAAS,SAAS;AAEb,MAAM,cAAc,CAAC,cAC1B,aAAa,OAAO,cAAc,YAAY,eAAe;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { isReactDesc } from "./describeGuards.js";
|
|
2
3
|
const arrayFormat = (array) => array.map((propType) => propTypeFormat(propType));
|
|
3
4
|
const shapeFormat = (shape) => {
|
|
4
5
|
const props = Object.keys(shape).map((key) => {
|
|
@@ -112,6 +113,15 @@ function descToTypescript(component, reactDesc) {
|
|
|
112
113
|
documentation.properties = propTypes;
|
|
113
114
|
}
|
|
114
115
|
}
|
|
116
|
+
if (reactDesc.returnType) {
|
|
117
|
+
if (isReactDesc(reactDesc.returnType)) {
|
|
118
|
+
documentation.returns = propTypeAsTypescript(reactDesc.returnType, "returns");
|
|
119
|
+
} else {
|
|
120
|
+
documentation.returns = Object.entries(reactDesc.returnType).map(
|
|
121
|
+
([propName, propType]) => propTypeAsTypescript(propType, propName)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
115
125
|
}
|
|
116
126
|
return documentation;
|
|
117
127
|
}
|
|
@@ -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';\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 }\n return documentation as TypescriptDocumentation;\n}\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,WAAW;
|
|
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;AAAA,IACvC,WAAW,MAAM,SAAS,SAAS;AACjC,oBAAc,GAAG,eAAe,KAAK;AAAA,IACvC,OAAO;AACL,o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A,MACF;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -7,3 +7,4 @@ export declare const isInstanceOf: (propType: ReactDescT, realPropType: AllPropT
|
|
|
7
7
|
export declare const isOneOf: (propType: ReactDescT, realPropType: AllPropTypes) => realPropType is typeof import("prop-types").oneOf;
|
|
8
8
|
export declare const isObjectOf: (propType: ReactDescT, realPropType: AllPropTypes) => realPropType is typeof import("prop-types").objectOf;
|
|
9
9
|
export declare const isExact: (propType: ReactDescT, realPropType: AllPropTypes) => realPropType is typeof import("prop-types").exact;
|
|
10
|
+
export declare const isReactDesc: (reactDesc: object) => reactDesc is ReactDescT;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { any, array, bool, func, number, object, string, node, element, symbol, elementType, instanceOf, oneOf, oneOfType, arrayOf, objectOf, shape, exact, ValidationMap } from 'prop-types';
|
|
1
|
+
import type { any, array, bool, func, number, object, string, node, element, symbol, elementType, instanceOf, oneOf, oneOfType, arrayOf, objectOf, shape, exact, Validator, ValidationMap } from 'prop-types';
|
|
2
2
|
import type React from 'react';
|
|
3
3
|
export interface ReactDescObjT {
|
|
4
4
|
[key: string]: unknown;
|
|
@@ -53,6 +53,7 @@ export interface ReactDescT {
|
|
|
53
53
|
}
|
|
54
54
|
export interface ComponentDocumentation {
|
|
55
55
|
propTypes: Record<string, ReactDescT>;
|
|
56
|
+
returnType?: ReactDescT | Record<string, ReactDescT>;
|
|
56
57
|
availableAt?: unknown;
|
|
57
58
|
description?: string;
|
|
58
59
|
details?: unknown;
|
|
@@ -76,6 +77,29 @@ export interface TypescriptDocumentation extends Partial<ComponentDocumentation>
|
|
|
76
77
|
isRequiredIf?: (props: any) => boolean;
|
|
77
78
|
omitValidation?: boolean;
|
|
78
79
|
}[];
|
|
80
|
+
returns?: {
|
|
81
|
+
name: string;
|
|
82
|
+
required?: boolean | undefined;
|
|
83
|
+
deprecated?: Record<string, string> | undefined;
|
|
84
|
+
description?: string;
|
|
85
|
+
format?: string;
|
|
86
|
+
signature?: string;
|
|
87
|
+
warned?: boolean;
|
|
88
|
+
defaultValue?: unknown;
|
|
89
|
+
isRequiredIf?: (props: any) => boolean;
|
|
90
|
+
omitValidation?: boolean;
|
|
91
|
+
} | {
|
|
92
|
+
name: string;
|
|
93
|
+
required?: boolean | undefined;
|
|
94
|
+
deprecated?: Record<string, string> | undefined;
|
|
95
|
+
description?: string;
|
|
96
|
+
format?: string;
|
|
97
|
+
signature?: string;
|
|
98
|
+
warned?: boolean;
|
|
99
|
+
defaultValue?: unknown;
|
|
100
|
+
isRequiredIf?: (props: any) => boolean;
|
|
101
|
+
omitValidation?: boolean;
|
|
102
|
+
}[];
|
|
79
103
|
}
|
|
80
104
|
export type DocumentedReactComponent<T> = React.ComponentType<T> & {
|
|
81
105
|
availableAt: unknown;
|
|
@@ -86,6 +110,8 @@ export type DocumentedReactComponent<T> = React.ComponentType<T> & {
|
|
|
86
110
|
intrinsicElement: unknown;
|
|
87
111
|
toTypescript: () => TypescriptDocumentation;
|
|
88
112
|
propTypesValue: ValidationMap<Record<string, unknown>>;
|
|
113
|
+
returnType: ReactDescT | Record<string, ReactDescT>;
|
|
114
|
+
returnTypeValue: Validator<unknown> | ValidationMap<Record<string, unknown>>;
|
|
89
115
|
};
|
|
90
116
|
export type Hook<T = unknown, S = unknown> = ((props: T) => S) & {
|
|
91
117
|
displayName?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@elliemae/ds-props-helpers",
|
|
3
|
-
"version": "3.27.0-next.
|
|
3
|
+
"version": "3.27.0-next.12",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "ICE MT - Dimsum - Props Helpers",
|
|
6
6
|
"files": [
|
|
@@ -34,11 +34,11 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"fast-deep-equal": "~3.1.3",
|
|
36
36
|
"prop-types": "~15.8.1",
|
|
37
|
-
"@elliemae/ds-system": "3.27.0-next.
|
|
37
|
+
"@elliemae/ds-system": "3.27.0-next.12"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@elliemae/pui-cli": "~9.0.0-next.31",
|
|
41
|
-
"@elliemae/ds-monorepo-devops": "3.27.0-next.
|
|
41
|
+
"@elliemae/ds-monorepo-devops": "3.27.0-next.12"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"lodash": "^4.17.21",
|