@storybook/react 6.5.0-alpha.5 → 6.5.0-alpha.52
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/client/docs/config.js +29 -0
- package/dist/cjs/client/docs/extractArgTypes.js +54 -0
- package/dist/cjs/client/docs/extractProps.js +77 -0
- package/dist/cjs/client/docs/jsxDecorator.js +277 -0
- package/dist/cjs/client/docs/lib/captions.js +18 -0
- package/dist/cjs/client/docs/lib/componentTypes.js +24 -0
- package/dist/cjs/client/docs/lib/defaultValues/createDefaultValue.js +81 -0
- package/dist/cjs/client/docs/lib/defaultValues/createFromRawDefaultProp.js +225 -0
- package/dist/cjs/client/docs/lib/defaultValues/generateArray.js +29 -0
- package/dist/cjs/client/docs/lib/defaultValues/generateObject.js +29 -0
- package/dist/cjs/client/docs/lib/defaultValues/index.js +37 -0
- package/dist/cjs/client/docs/lib/defaultValues/prettyIdentifier.js +34 -0
- package/dist/cjs/client/docs/lib/generateCode.js +89 -0
- package/dist/cjs/client/docs/lib/index.js +63 -0
- package/dist/cjs/client/docs/lib/inspection/acornParser.js +254 -0
- package/dist/cjs/client/docs/lib/inspection/index.js +37 -0
- package/dist/cjs/client/docs/lib/inspection/inspectValue.js +26 -0
- package/dist/cjs/client/docs/lib/inspection/types.js +19 -0
- package/dist/cjs/client/docs/lib/isHtmlTag.js +18 -0
- package/dist/cjs/client/docs/propTypes/createType.js +469 -0
- package/dist/cjs/client/docs/propTypes/generateFuncSignature.js +78 -0
- package/dist/cjs/client/docs/propTypes/handleProp.js +54 -0
- package/dist/cjs/client/docs/propTypes/rawDefaultPropResolvers.js +47 -0
- package/dist/cjs/client/docs/propTypes/sortProps.js +37 -0
- package/dist/cjs/client/docs/react-argtypes.stories.js +129 -0
- package/dist/cjs/client/docs/typeScript/handleProp.js +38 -0
- package/dist/cjs/client/index.js +16 -14
- package/dist/cjs/client/preview/config.js +1 -1
- package/dist/cjs/client/preview/index.js +1 -1
- package/dist/cjs/client/preview/render.js +11 -11
- package/dist/cjs/client/preview/types-6-0.js +5 -1
- package/dist/cjs/client/preview/types-6-3.js +2 -0
- package/dist/cjs/client/preview/types-7-0.js +5 -1
- package/dist/cjs/client/preview/types.js +5 -1
- package/dist/cjs/demo/Welcome.js +7 -3
- package/dist/cjs/server/{framework-preset-react-docgen.js → framework-preset-react-docs.js} +21 -11
- package/dist/cjs/server/framework-preset-react.js +2 -2
- package/dist/cjs/server/preset.js +2 -2
- package/dist/esm/client/docs/config.js +16 -0
- package/dist/esm/client/docs/extractArgTypes.js +39 -0
- package/dist/esm/client/docs/extractProps.js +54 -0
- package/dist/esm/client/docs/jsxDecorator.js +218 -0
- package/dist/esm/client/docs/lib/captions.js +6 -0
- package/dist/esm/client/docs/lib/componentTypes.js +9 -0
- package/dist/esm/client/docs/lib/defaultValues/createDefaultValue.js +67 -0
- package/dist/esm/client/docs/lib/defaultValues/createFromRawDefaultProp.js +191 -0
- package/dist/esm/client/docs/lib/defaultValues/generateArray.js +19 -0
- package/dist/esm/client/docs/lib/defaultValues/generateObject.js +19 -0
- package/dist/esm/client/docs/lib/defaultValues/index.js +2 -0
- package/dist/esm/client/docs/lib/defaultValues/prettyIdentifier.js +22 -0
- package/dist/esm/client/docs/lib/generateCode.js +68 -0
- package/dist/esm/client/docs/lib/index.js +4 -0
- package/dist/esm/client/docs/lib/inspection/acornParser.js +213 -0
- package/dist/esm/client/docs/lib/inspection/index.js +2 -0
- package/dist/esm/client/docs/lib/inspection/inspectValue.js +16 -0
- package/dist/esm/client/docs/lib/inspection/types.js +12 -0
- package/dist/esm/client/docs/lib/isHtmlTag.js +6 -0
- package/dist/esm/client/docs/propTypes/createType.js +449 -0
- package/dist/esm/client/docs/propTypes/generateFuncSignature.js +62 -0
- package/dist/esm/client/docs/propTypes/handleProp.js +39 -0
- package/dist/esm/client/docs/propTypes/rawDefaultPropResolvers.js +32 -0
- package/dist/esm/client/docs/propTypes/sortProps.js +24 -0
- package/dist/esm/client/docs/react-argtypes.stories.js +97 -0
- package/dist/esm/client/docs/typeScript/handleProp.js +27 -0
- package/dist/esm/client/preview/render.js +6 -6
- package/dist/esm/client/preview/types-6-0.js +1 -0
- package/dist/esm/client/preview/types-6-3.js +3 -1
- package/dist/esm/client/preview/types-7-0.js +1 -0
- package/dist/esm/client/preview/types.js +1 -0
- package/dist/esm/demo/Welcome.js +7 -4
- package/dist/{modern/server/framework-preset-react-docgen.js → esm/server/framework-preset-react-docs.js} +15 -11
- package/dist/esm/server/framework-preset-react.js +2 -2
- package/dist/esm/server/preset.js +1 -1
- package/dist/modern/client/docs/config.js +14 -0
- package/dist/modern/client/docs/extractArgTypes.js +38 -0
- package/dist/modern/client/docs/extractProps.js +42 -0
- package/dist/modern/client/docs/jsxDecorator.js +177 -0
- package/dist/modern/client/docs/lib/captions.js +6 -0
- package/dist/modern/client/docs/lib/componentTypes.js +2 -0
- package/dist/modern/client/docs/lib/defaultValues/createDefaultValue.js +72 -0
- package/dist/modern/client/docs/lib/defaultValues/createFromRawDefaultProp.js +181 -0
- package/dist/modern/client/docs/lib/defaultValues/generateArray.js +21 -0
- package/dist/modern/client/docs/lib/defaultValues/generateObject.js +21 -0
- package/dist/modern/client/docs/lib/defaultValues/index.js +2 -0
- package/dist/modern/client/docs/lib/defaultValues/prettyIdentifier.js +24 -0
- package/dist/modern/client/docs/lib/generateCode.js +59 -0
- package/dist/modern/client/docs/lib/index.js +4 -0
- package/dist/modern/client/docs/lib/inspection/acornParser.js +211 -0
- package/dist/modern/client/docs/lib/inspection/index.js +2 -0
- package/dist/modern/client/docs/lib/inspection/inspectValue.js +15 -0
- package/dist/modern/client/docs/lib/inspection/types.js +12 -0
- package/dist/modern/client/docs/lib/isHtmlTag.js +4 -0
- package/dist/modern/client/docs/propTypes/createType.js +446 -0
- package/dist/modern/client/docs/propTypes/generateFuncSignature.js +57 -0
- package/dist/modern/client/docs/propTypes/handleProp.js +39 -0
- package/dist/modern/client/docs/propTypes/rawDefaultPropResolvers.js +31 -0
- package/dist/modern/client/docs/propTypes/sortProps.js +14 -0
- package/dist/modern/client/docs/react-argtypes.stories.js +54 -0
- package/dist/modern/client/docs/typeScript/handleProp.js +28 -0
- package/dist/modern/client/preview/types-6-0.js +1 -0
- package/dist/modern/client/preview/types-6-3.js +3 -1
- package/dist/modern/client/preview/types-7-0.js +1 -0
- package/dist/modern/client/preview/types.js +1 -0
- package/dist/modern/demo/Welcome.js +10 -6
- package/dist/{esm/server/framework-preset-react-docgen.js → modern/server/framework-preset-react-docs.js} +15 -11
- package/dist/modern/server/framework-preset-react.js +2 -2
- package/dist/modern/server/preset.js +1 -1
- package/dist/ts3.4/client/docs/config.d.ts +13 -0
- package/dist/ts3.4/client/docs/extractArgTypes.d.ts +2 -0
- package/dist/ts3.4/client/docs/extractProps.d.ts +5 -0
- package/dist/ts3.4/client/docs/jsxDecorator.d.ts +23 -0
- package/dist/ts3.4/client/docs/lib/captions.d.ts +6 -0
- package/dist/ts3.4/client/docs/lib/componentTypes.d.ts +2 -0
- package/dist/ts3.4/client/docs/lib/defaultValues/createDefaultValue.d.ts +2 -0
- package/dist/ts3.4/client/docs/lib/defaultValues/createFromRawDefaultProp.d.ts +11 -0
- package/dist/ts3.4/client/docs/lib/defaultValues/generateArray.d.ts +3 -0
- package/dist/ts3.4/client/docs/lib/defaultValues/generateObject.d.ts +3 -0
- package/dist/ts3.4/client/docs/lib/defaultValues/index.d.ts +2 -0
- package/dist/ts3.4/client/docs/lib/defaultValues/prettyIdentifier.d.ts +4 -0
- package/dist/ts3.4/client/docs/lib/generateCode.d.ts +3 -0
- package/dist/ts3.4/client/docs/lib/index.d.ts +4 -0
- package/dist/ts3.4/client/docs/lib/inspection/acornParser.d.ts +7 -0
- package/dist/ts3.4/client/docs/lib/inspection/index.d.ts +2 -0
- package/dist/ts3.4/client/docs/lib/inspection/inspectValue.d.ts +2 -0
- package/dist/ts3.4/client/docs/lib/inspection/types.d.ts +50 -0
- package/dist/ts3.4/client/docs/lib/isHtmlTag.d.ts +1 -0
- package/dist/ts3.4/client/docs/propTypes/createType.d.ts +2 -0
- package/dist/ts3.4/client/docs/propTypes/generateFuncSignature.d.ts +4 -0
- package/dist/ts3.4/client/docs/propTypes/handleProp.d.ts +5 -0
- package/dist/ts3.4/client/docs/propTypes/rawDefaultPropResolvers.d.ts +1 -0
- package/dist/ts3.4/client/docs/propTypes/sortProps.d.ts +4 -0
- package/dist/ts3.4/client/docs/react-argtypes.stories.d.ts +1 -0
- package/dist/ts3.4/client/docs/typeScript/handleProp.d.ts +3 -0
- package/dist/ts3.4/server/framework-preset-react-docs.d.ts +6 -0
- package/dist/ts3.4/server/framework-preset-react.d.ts +1 -46
- package/dist/ts3.9/client/docs/config.d.ts +13 -0
- package/dist/ts3.9/client/docs/extractArgTypes.d.ts +2 -0
- package/dist/ts3.9/client/docs/extractProps.d.ts +5 -0
- package/dist/ts3.9/client/docs/jsxDecorator.d.ts +23 -0
- package/dist/ts3.9/client/docs/lib/captions.d.ts +6 -0
- package/dist/ts3.9/client/docs/lib/componentTypes.d.ts +2 -0
- package/dist/ts3.9/client/docs/lib/defaultValues/createDefaultValue.d.ts +2 -0
- package/dist/ts3.9/client/docs/lib/defaultValues/createFromRawDefaultProp.d.ts +11 -0
- package/dist/ts3.9/client/docs/lib/defaultValues/generateArray.d.ts +3 -0
- package/dist/ts3.9/client/docs/lib/defaultValues/generateObject.d.ts +3 -0
- package/dist/ts3.9/client/docs/lib/defaultValues/index.d.ts +2 -0
- package/dist/ts3.9/client/docs/lib/defaultValues/prettyIdentifier.d.ts +4 -0
- package/dist/ts3.9/client/docs/lib/generateCode.d.ts +3 -0
- package/dist/ts3.9/client/docs/lib/index.d.ts +4 -0
- package/dist/ts3.9/client/docs/lib/inspection/acornParser.d.ts +7 -0
- package/dist/ts3.9/client/docs/lib/inspection/index.d.ts +2 -0
- package/dist/ts3.9/client/docs/lib/inspection/inspectValue.d.ts +2 -0
- package/dist/ts3.9/client/docs/lib/inspection/types.d.ts +50 -0
- package/dist/ts3.9/client/docs/lib/isHtmlTag.d.ts +1 -0
- package/dist/ts3.9/client/docs/propTypes/createType.d.ts +2 -0
- package/dist/ts3.9/client/docs/propTypes/generateFuncSignature.d.ts +4 -0
- package/dist/ts3.9/client/docs/propTypes/handleProp.d.ts +5 -0
- package/dist/ts3.9/client/docs/propTypes/rawDefaultPropResolvers.d.ts +1 -0
- package/dist/ts3.9/client/docs/propTypes/sortProps.d.ts +4 -0
- package/dist/ts3.9/client/docs/react-argtypes.stories.d.ts +1 -0
- package/dist/ts3.9/client/docs/typeScript/handleProp.d.ts +3 -0
- package/dist/ts3.9/client/preview/types-6-0.d.ts +3 -3
- package/dist/ts3.9/client/preview/types-7-0.d.ts +2 -2
- package/dist/ts3.9/server/framework-preset-cra.d.ts +1 -1
- package/dist/ts3.9/server/framework-preset-react-docs.d.ts +6 -0
- package/dist/ts3.9/server/framework-preset-react.d.ts +1 -46
- package/dist/ts3.9/server/options.d.ts +1 -1
- package/dist/ts3.9/server/preset.d.ts +1 -1
- package/package.json +36 -14
- package/types/index.ts +1 -1
- package/dist/cjs/typings.d.js +0 -1
- package/dist/esm/typings.d.js +0 -0
- package/dist/modern/typings.d.js +0 -0
- package/dist/ts3.4/server/framework-preset-react-docgen.d.ts +0 -5
- package/dist/ts3.9/server/framework-preset-react-docgen.d.ts +0 -5
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import "core-js/modules/es.array.map.js";
|
|
2
|
+
import "core-js/modules/es.array.concat.js";
|
|
3
|
+
import "core-js/modules/es.array.join.js";
|
|
4
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
5
|
+
import "core-js/modules/es.string.replace.js";
|
|
6
|
+
export function generateFuncSignature(params, returns) {
|
|
7
|
+
var hasParams = params != null;
|
|
8
|
+
var hasReturns = returns != null;
|
|
9
|
+
|
|
10
|
+
if (!hasParams && !hasReturns) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
var funcParts = [];
|
|
15
|
+
|
|
16
|
+
if (hasParams) {
|
|
17
|
+
var funcParams = params.map(function (x) {
|
|
18
|
+
var prettyName = x.getPrettyName();
|
|
19
|
+
var typeName = x.getTypeName();
|
|
20
|
+
|
|
21
|
+
if (typeName != null) {
|
|
22
|
+
return "".concat(prettyName, ": ").concat(typeName);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return prettyName;
|
|
26
|
+
});
|
|
27
|
+
funcParts.push("(".concat(funcParams.join(', '), ")"));
|
|
28
|
+
} else {
|
|
29
|
+
funcParts.push('()');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (hasReturns) {
|
|
33
|
+
funcParts.push("=> ".concat(returns.getTypeName()));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return funcParts.join(' ');
|
|
37
|
+
}
|
|
38
|
+
export function generateShortFuncSignature(params, returns) {
|
|
39
|
+
var hasParams = params != null;
|
|
40
|
+
var hasReturns = returns != null;
|
|
41
|
+
|
|
42
|
+
if (!hasParams && !hasReturns) {
|
|
43
|
+
return '';
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
var funcParts = [];
|
|
47
|
+
|
|
48
|
+
if (hasParams) {
|
|
49
|
+
funcParts.push('( ... )');
|
|
50
|
+
} else {
|
|
51
|
+
funcParts.push('()');
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (hasReturns) {
|
|
55
|
+
funcParts.push("=> ".concat(returns.getTypeName()));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return funcParts.join(' ');
|
|
59
|
+
}
|
|
60
|
+
export function toMultilineSignature(signature) {
|
|
61
|
+
return signature.replace(/,/g, ',\r\n');
|
|
62
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import "core-js/modules/es.array.map.js";
|
|
2
|
+
import "core-js/modules/es.function.name.js";
|
|
3
|
+
import { createType } from './createType';
|
|
4
|
+
import { createDefaultValue, createDefaultValueFromRawDefaultProp } from '../lib/defaultValues';
|
|
5
|
+
import { keepOriginalDefinitionOrder } from './sortProps';
|
|
6
|
+
import { rawDefaultPropTypeResolvers } from './rawDefaultPropResolvers';
|
|
7
|
+
export function enhancePropTypesProp(extractedProp, rawDefaultProp) {
|
|
8
|
+
var propDef = extractedProp.propDef;
|
|
9
|
+
var newtype = createType(extractedProp);
|
|
10
|
+
|
|
11
|
+
if (newtype != null) {
|
|
12
|
+
propDef.type = newtype;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
var defaultValue = extractedProp.docgenInfo.defaultValue;
|
|
16
|
+
|
|
17
|
+
if (defaultValue != null && defaultValue.value != null) {
|
|
18
|
+
var newDefaultValue = createDefaultValue(defaultValue.value);
|
|
19
|
+
|
|
20
|
+
if (newDefaultValue != null) {
|
|
21
|
+
propDef.defaultValue = newDefaultValue;
|
|
22
|
+
}
|
|
23
|
+
} else if (rawDefaultProp != null) {
|
|
24
|
+
var _newDefaultValue = createDefaultValueFromRawDefaultProp(rawDefaultProp, propDef, rawDefaultPropTypeResolvers);
|
|
25
|
+
|
|
26
|
+
if (_newDefaultValue != null) {
|
|
27
|
+
propDef.defaultValue = _newDefaultValue;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return propDef;
|
|
32
|
+
}
|
|
33
|
+
export function enhancePropTypesProps(extractedProps, component) {
|
|
34
|
+
var rawDefaultProps = component.defaultProps != null ? component.defaultProps : {};
|
|
35
|
+
var enhancedProps = extractedProps.map(function (x) {
|
|
36
|
+
return enhancePropTypesProp(x, rawDefaultProps[x.propDef.name]);
|
|
37
|
+
});
|
|
38
|
+
return keepOriginalDefinitionOrder(enhancedProps, component);
|
|
39
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import "core-js/modules/es.function.name.js";
|
|
2
|
+
import "core-js/modules/es.object.to-string.js";
|
|
3
|
+
import "core-js/modules/es.regexp.to-string.js";
|
|
4
|
+
import { createSummaryValue } from '@storybook/docs-tools';
|
|
5
|
+
import { extractFunctionName, createTypeResolvers } from '../lib/defaultValues';
|
|
6
|
+
import { FUNCTION_CAPTION, ELEMENT_CAPTION } from '../lib';
|
|
7
|
+
import { getPrettyElementIdentifier, getPrettyFuncIdentifier } from '../lib/defaultValues/prettyIdentifier';
|
|
8
|
+
import { inspectValue } from '../lib/inspection';
|
|
9
|
+
|
|
10
|
+
var funcResolver = function funcResolver(rawDefaultProp, _ref) {
|
|
11
|
+
var name = _ref.name,
|
|
12
|
+
type = _ref.type;
|
|
13
|
+
var isElement = type.summary === 'element' || type.summary === 'elementType';
|
|
14
|
+
var funcName = extractFunctionName(rawDefaultProp, name);
|
|
15
|
+
|
|
16
|
+
if (funcName != null) {
|
|
17
|
+
// Try to display the name of the component. The body of the component is omitted since the code has been transpiled.
|
|
18
|
+
if (isElement) {
|
|
19
|
+
return createSummaryValue(getPrettyElementIdentifier(funcName));
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
var _ref2 = inspectValue(rawDefaultProp.toString()).inferredType,
|
|
23
|
+
hasParams = _ref2.hasParams;
|
|
24
|
+
return createSummaryValue(getPrettyFuncIdentifier(funcName, hasParams));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return createSummaryValue(isElement ? ELEMENT_CAPTION : FUNCTION_CAPTION);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export var rawDefaultPropTypeResolvers = createTypeResolvers({
|
|
31
|
+
function: funcResolver
|
|
32
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import "core-js/modules/es.array.filter.js";
|
|
2
|
+
import "core-js/modules/es.object.to-string.js";
|
|
3
|
+
import "core-js/modules/es.array.map.js";
|
|
4
|
+
import "core-js/modules/es.object.keys.js";
|
|
5
|
+
import "core-js/modules/es.array.find.js";
|
|
6
|
+
import "core-js/modules/es.function.name.js";
|
|
7
|
+
// react-docgen doesn't returned the props in the order they were defined in the "propTypes" object of the component.
|
|
8
|
+
// This function re-order them by their original definition order.
|
|
9
|
+
export function keepOriginalDefinitionOrder(extractedProps, component) {
|
|
10
|
+
// eslint-disable-next-line react/forbid-foreign-prop-types
|
|
11
|
+
var propTypes = component.propTypes;
|
|
12
|
+
|
|
13
|
+
if (propTypes != null) {
|
|
14
|
+
return Object.keys(propTypes).map(function (x) {
|
|
15
|
+
return extractedProps.find(function (y) {
|
|
16
|
+
return y.name === x;
|
|
17
|
+
});
|
|
18
|
+
}).filter(function (x) {
|
|
19
|
+
return x;
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return extractedProps;
|
|
24
|
+
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import "core-js/modules/es.object.assign.js";
|
|
2
|
+
import "core-js/modules/es.array.map.js";
|
|
3
|
+
import "core-js/modules/es.object.entries.js";
|
|
4
|
+
import "core-js/modules/es.object.to-string.js";
|
|
5
|
+
import "core-js/modules/es.symbol.js";
|
|
6
|
+
import "core-js/modules/es.symbol.description.js";
|
|
7
|
+
import "core-js/modules/es.symbol.iterator.js";
|
|
8
|
+
import "core-js/modules/es.array.iterator.js";
|
|
9
|
+
import "core-js/modules/es.string.iterator.js";
|
|
10
|
+
import "core-js/modules/web.dom-collections.iterator.js";
|
|
11
|
+
import "core-js/modules/es.array.slice.js";
|
|
12
|
+
import "core-js/modules/es.function.name.js";
|
|
13
|
+
import "core-js/modules/es.array.from.js";
|
|
14
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
15
|
+
|
|
16
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
17
|
+
|
|
18
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
19
|
+
|
|
20
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
21
|
+
|
|
22
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
23
|
+
|
|
24
|
+
function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
|
25
|
+
|
|
26
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
27
|
+
|
|
28
|
+
import React, { useState } from 'react';
|
|
29
|
+
import mapValues from 'lodash/mapValues';
|
|
30
|
+
import { ArgsTable } from '@storybook/components';
|
|
31
|
+
import { inferControls } from '@storybook/store';
|
|
32
|
+
import { storiesOf } from '..';
|
|
33
|
+
import { extractArgTypes } from './extractArgTypes'; // FIXME
|
|
34
|
+
|
|
35
|
+
var argsTableProps = function argsTableProps(component) {
|
|
36
|
+
var argTypes = extractArgTypes(component);
|
|
37
|
+
var parameters = {
|
|
38
|
+
__isArgsStory: true
|
|
39
|
+
};
|
|
40
|
+
var rows = inferControls({
|
|
41
|
+
argTypes: argTypes,
|
|
42
|
+
parameters: parameters
|
|
43
|
+
});
|
|
44
|
+
return {
|
|
45
|
+
rows: rows
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
var ArgsStory = function ArgsStory(_ref) {
|
|
50
|
+
var component = _ref.component;
|
|
51
|
+
|
|
52
|
+
var _argsTableProps = argsTableProps(component),
|
|
53
|
+
rows = _argsTableProps.rows;
|
|
54
|
+
|
|
55
|
+
var initialArgs = mapValues(rows, function (argType) {
|
|
56
|
+
return argType.defaultValue;
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
var _useState = useState(initialArgs),
|
|
60
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
61
|
+
args = _useState2[0],
|
|
62
|
+
setArgs = _useState2[1];
|
|
63
|
+
|
|
64
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("p", null, /*#__PURE__*/React.createElement("b", null, "NOTE:"), " these stories are to help visualise the snapshot tests in", ' ', /*#__PURE__*/React.createElement("code", null, "./react-properties.test.js"), "."), /*#__PURE__*/React.createElement(ArgsTable, {
|
|
65
|
+
rows: rows,
|
|
66
|
+
args: args,
|
|
67
|
+
updateArgs: function updateArgs(val) {
|
|
68
|
+
return setArgs(Object.assign({}, args, val));
|
|
69
|
+
}
|
|
70
|
+
}), /*#__PURE__*/React.createElement("table", null, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("th", null, "arg name"), /*#__PURE__*/React.createElement("th", null, "argType"))), /*#__PURE__*/React.createElement("tbody", null, Object.entries(args).map(function (_ref2) {
|
|
71
|
+
var _ref3 = _slicedToArray(_ref2, 2),
|
|
72
|
+
key = _ref3[0],
|
|
73
|
+
val = _ref3[1];
|
|
74
|
+
|
|
75
|
+
return /*#__PURE__*/React.createElement("tr", {
|
|
76
|
+
key: key
|
|
77
|
+
}, /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("code", null, key)), /*#__PURE__*/React.createElement("td", null, /*#__PURE__*/React.createElement("pre", null, JSON.stringify(rows[key]))));
|
|
78
|
+
}))));
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
var issuesFixtures = ['js-class-component', 'js-function-component', 'js-function-component-inline-defaults', 'js-function-component-inline-defaults-no-propTypes', 'ts-function-component', 'ts-function-component-inline-defaults', '9399-js-proptypes-shape', '8663-js-styled-components', '9626-js-default-values', '9668-js-proptypes-no-jsdoc', '8143-ts-react-fc-generics', '8143-ts-imported-types', '8279-js-styled-docgen', '8140-js-prop-types-oneof', '9023-js-hoc', '8740-ts-multi-props', '9556-ts-react-default-exports', '9592-ts-styled-props', '9591-ts-import-types', '9721-ts-deprecated-jsdoc', '9827-ts-default-values', '9586-js-react-memo', '9575-ts-camel-case', '9493-ts-display-name', '8894-9511-ts-forward-ref', '9465-ts-type-props', '8428-js-static-prop-types', '9764-ts-extend-props', '9922-ts-component-props'];
|
|
82
|
+
var issuesStories = storiesOf('ArgTypes/Issues', module);
|
|
83
|
+
issuesFixtures.forEach(function (fixture) {
|
|
84
|
+
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
85
|
+
var _require = require("./__testfixtures__/".concat(fixture, "/input")),
|
|
86
|
+
component = _require.component;
|
|
87
|
+
|
|
88
|
+
issuesStories.add(fixture, function () {
|
|
89
|
+
return /*#__PURE__*/React.createElement(ArgsStory, {
|
|
90
|
+
component: component
|
|
91
|
+
});
|
|
92
|
+
}, {
|
|
93
|
+
chromatic: {
|
|
94
|
+
disable: true
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import "core-js/modules/es.array.map.js";
|
|
2
|
+
import { createDefaultValue, createDefaultValueFromRawDefaultProp } from '../lib/defaultValues';
|
|
3
|
+
export function enhanceTypeScriptProp(extractedProp, rawDefaultProp) {
|
|
4
|
+
var propDef = extractedProp.propDef;
|
|
5
|
+
var defaultValue = extractedProp.docgenInfo.defaultValue;
|
|
6
|
+
|
|
7
|
+
if (defaultValue != null && defaultValue.value != null) {
|
|
8
|
+
var newDefaultValue = createDefaultValue(defaultValue.value);
|
|
9
|
+
|
|
10
|
+
if (newDefaultValue != null) {
|
|
11
|
+
propDef.defaultValue = newDefaultValue;
|
|
12
|
+
}
|
|
13
|
+
} else if (rawDefaultProp != null) {
|
|
14
|
+
var _newDefaultValue = createDefaultValueFromRawDefaultProp(rawDefaultProp, propDef);
|
|
15
|
+
|
|
16
|
+
if (_newDefaultValue != null) {
|
|
17
|
+
propDef.defaultValue = _newDefaultValue;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return propDef;
|
|
22
|
+
}
|
|
23
|
+
export function enhanceTypeScriptProps(extractedProps) {
|
|
24
|
+
return extractedProps.map(function (prop) {
|
|
25
|
+
return enhanceTypeScriptProp(prop);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
2
|
|
|
3
3
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
4
4
|
|
|
5
5
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
6
6
|
|
|
7
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
7
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
8
8
|
|
|
9
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
9
|
+
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
10
10
|
|
|
11
11
|
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
12
12
|
|
|
13
13
|
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
14
14
|
|
|
15
|
-
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
|
15
|
+
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
|
16
16
|
|
|
17
17
|
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
18
18
|
|
|
@@ -21,16 +21,16 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
|
|
|
21
21
|
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
|
22
22
|
|
|
23
23
|
import "regenerator-runtime/runtime.js";
|
|
24
|
-
import "core-js/modules/es.promise.js";
|
|
25
24
|
import "core-js/modules/es.object.to-string.js";
|
|
25
|
+
import "core-js/modules/es.promise.js";
|
|
26
26
|
import "core-js/modules/es.array.concat.js";
|
|
27
27
|
import "core-js/modules/es.object.get-prototype-of.js";
|
|
28
28
|
import "core-js/modules/es.reflect.construct.js";
|
|
29
29
|
import "core-js/modules/es.symbol.js";
|
|
30
30
|
import "core-js/modules/es.symbol.description.js";
|
|
31
31
|
import "core-js/modules/es.symbol.iterator.js";
|
|
32
|
-
import "core-js/modules/es.string.iterator.js";
|
|
33
32
|
import "core-js/modules/es.array.iterator.js";
|
|
33
|
+
import "core-js/modules/es.string.iterator.js";
|
|
34
34
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
35
35
|
|
|
36
36
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/esm/demo/Welcome.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import "core-js/modules/es.object.assign.js";
|
|
2
1
|
import "core-js/modules/es.object.keys.js";
|
|
3
2
|
import "core-js/modules/es.symbol.js";
|
|
3
|
+
var _excluded = ["children"],
|
|
4
|
+
_excluded2 = ["children", "href", "target", "rel"],
|
|
5
|
+
_excluded3 = ["children", "onClick"];
|
|
6
|
+
import "core-js/modules/es.object.assign.js";
|
|
4
7
|
|
|
5
8
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
6
9
|
|
|
@@ -24,7 +27,7 @@ var Main = function Main(props) {
|
|
|
24
27
|
|
|
25
28
|
var Title = function Title(_ref) {
|
|
26
29
|
var children = _ref.children,
|
|
27
|
-
props = _objectWithoutProperties(_ref,
|
|
30
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
28
31
|
|
|
29
32
|
return /*#__PURE__*/React.createElement("h1", props, children);
|
|
30
33
|
};
|
|
@@ -56,7 +59,7 @@ var Link = function Link(_ref2) {
|
|
|
56
59
|
href = _ref2.href,
|
|
57
60
|
target = _ref2.target,
|
|
58
61
|
rel = _ref2.rel,
|
|
59
|
-
props = _objectWithoutProperties(_ref2,
|
|
62
|
+
props = _objectWithoutProperties(_ref2, _excluded2);
|
|
60
63
|
|
|
61
64
|
return /*#__PURE__*/React.createElement("a", _extends({
|
|
62
65
|
href: href
|
|
@@ -75,7 +78,7 @@ var Link = function Link(_ref2) {
|
|
|
75
78
|
var NavButton = function NavButton(_ref3) {
|
|
76
79
|
var children = _ref3.children,
|
|
77
80
|
onClick = _ref3.onClick,
|
|
78
|
-
props = _objectWithoutProperties(_ref3,
|
|
81
|
+
props = _objectWithoutProperties(_ref3, _excluded3);
|
|
79
82
|
|
|
80
83
|
return /*#__PURE__*/React.createElement("button", _extends({}, props, {
|
|
81
84
|
type: "button",
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
2
|
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
7
7
|
import "core-js/modules/es.promise.js";
|
|
8
|
+
import { findDistEsm } from '@storybook/core-common';
|
|
8
9
|
import ReactDocgenTypescriptPlugin from '@storybook/react-docgen-typescript-plugin';
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var typescriptOptions = await presets.apply('typescript', {});
|
|
10
|
+
import { hasDocsOrControls } from '@storybook/docs-tools';
|
|
11
|
+
export async function babel(config, options) {
|
|
12
|
+
if (!hasDocsOrControls(options)) return config;
|
|
13
|
+
var typescriptOptions = await options.presets.apply('typescript', {});
|
|
13
14
|
var reactDocgen = typescriptOptions.reactDocgen;
|
|
14
15
|
|
|
15
16
|
if (typeof reactDocgen !== 'string') {
|
|
@@ -25,10 +26,9 @@ export async function babel(config, {
|
|
|
25
26
|
}]
|
|
26
27
|
});
|
|
27
28
|
}
|
|
28
|
-
export async function webpackFinal(config, {
|
|
29
|
-
|
|
30
|
-
})
|
|
31
|
-
var typescriptOptions = await presets.apply('typescript', {});
|
|
29
|
+
export async function webpackFinal(config, options) {
|
|
30
|
+
if (!hasDocsOrControls(options)) return config;
|
|
31
|
+
var typescriptOptions = await options.presets.apply('typescript', {});
|
|
32
32
|
var reactDocgen = typescriptOptions.reactDocgen,
|
|
33
33
|
reactDocgenTypescriptOptions = typescriptOptions.reactDocgenTypescriptOptions;
|
|
34
34
|
|
|
@@ -42,4 +42,8 @@ export async function webpackFinal(config, {
|
|
|
42
42
|
savePropValueAsString: true
|
|
43
43
|
}))]
|
|
44
44
|
});
|
|
45
|
-
}
|
|
45
|
+
}
|
|
46
|
+
export var config = function (entry = [], options) {
|
|
47
|
+
if (!hasDocsOrControls(options)) return entry;
|
|
48
|
+
return [...entry, findDistEsm(__dirname, 'client/docs/config')];
|
|
49
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
1
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
2
2
|
|
|
3
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
4
|
|
|
5
5
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
6
6
|
|
|
@@ -2,4 +2,4 @@ import { findDistEsm } from '@storybook/core-common';
|
|
|
2
2
|
export var config = function (entries = []) {
|
|
3
3
|
return [...entries, findDistEsm(__dirname, 'client/preview/config')];
|
|
4
4
|
};
|
|
5
|
-
export var addons = [require.resolve('./framework-preset-react'), require.resolve('./framework-preset-cra'), require.resolve('./framework-preset-react-
|
|
5
|
+
export var addons = [require.resolve('./framework-preset-react'), require.resolve('./framework-preset-cra'), require.resolve('./framework-preset-react-docs')];
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { extractComponentDescription, enhanceArgTypes } from '@storybook/docs-tools';
|
|
2
|
+
import { extractArgTypes } from './extractArgTypes';
|
|
3
|
+
import { jsxDecorator } from './jsxDecorator';
|
|
4
|
+
export const parameters = {
|
|
5
|
+
docs: {
|
|
6
|
+
inlineStories: true,
|
|
7
|
+
// NOTE: that the result is a react element. Hooks support is provided by the outer code.
|
|
8
|
+
prepareForInline: storyFn => storyFn(),
|
|
9
|
+
extractArgTypes,
|
|
10
|
+
extractComponentDescription
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export const decorators = [jsxDecorator];
|
|
14
|
+
export const argTypesEnhancers = [enhanceArgTypes];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import "core-js/modules/es.array.reduce.js";
|
|
2
|
+
import { extractProps } from './extractProps';
|
|
3
|
+
export const extractArgTypes = component => {
|
|
4
|
+
if (component) {
|
|
5
|
+
const {
|
|
6
|
+
rows
|
|
7
|
+
} = extractProps(component);
|
|
8
|
+
|
|
9
|
+
if (rows) {
|
|
10
|
+
return rows.reduce((acc, row) => {
|
|
11
|
+
const {
|
|
12
|
+
name,
|
|
13
|
+
description,
|
|
14
|
+
type,
|
|
15
|
+
sbType,
|
|
16
|
+
defaultValue: defaultSummary,
|
|
17
|
+
jsDocTags,
|
|
18
|
+
required
|
|
19
|
+
} = row;
|
|
20
|
+
acc[name] = {
|
|
21
|
+
name,
|
|
22
|
+
description,
|
|
23
|
+
type: Object.assign({
|
|
24
|
+
required
|
|
25
|
+
}, sbType),
|
|
26
|
+
table: {
|
|
27
|
+
type,
|
|
28
|
+
jsDocTags,
|
|
29
|
+
defaultValue: defaultSummary
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return acc;
|
|
33
|
+
}, {});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import PropTypes from 'prop-types';
|
|
2
|
+
import { hasDocgen, extractComponentProps, TypeSystem } from '@storybook/docs-tools';
|
|
3
|
+
import { enhancePropTypesProps } from './propTypes/handleProp';
|
|
4
|
+
import { enhanceTypeScriptProps } from './typeScript/handleProp';
|
|
5
|
+
import { isMemo } from './lib'; // FIXME
|
|
6
|
+
|
|
7
|
+
const propTypesMap = new Map();
|
|
8
|
+
Object.keys(PropTypes).forEach(typeName => {
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
const type = PropTypes[typeName];
|
|
11
|
+
propTypesMap.set(type, typeName);
|
|
12
|
+
propTypesMap.set(type.isRequired, typeName);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
function getPropDefs(component, section) {
|
|
16
|
+
let processedComponent = component; // eslint-disable-next-line react/forbid-foreign-prop-types
|
|
17
|
+
|
|
18
|
+
if (!hasDocgen(component) && !component.propTypes && isMemo(component)) {
|
|
19
|
+
processedComponent = component.type;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const extractedProps = extractComponentProps(processedComponent, section);
|
|
23
|
+
|
|
24
|
+
if (extractedProps.length === 0) {
|
|
25
|
+
return [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
switch (extractedProps[0].typeSystem) {
|
|
29
|
+
case TypeSystem.JAVASCRIPT:
|
|
30
|
+
return enhancePropTypesProps(extractedProps, component);
|
|
31
|
+
|
|
32
|
+
case TypeSystem.TYPESCRIPT:
|
|
33
|
+
return enhanceTypeScriptProps(extractedProps);
|
|
34
|
+
|
|
35
|
+
default:
|
|
36
|
+
return extractedProps.map(x => x.propDef);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export const extractProps = component => ({
|
|
41
|
+
rows: getPropDefs(component, 'props')
|
|
42
|
+
});
|