@storybook/react 7.0.0-alpha.2 → 7.0.0-alpha.20
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/chunk-X53CQCCB.mjs +1 -0
- package/dist/config.d.ts +24 -0
- package/dist/config.js +7 -0
- package/dist/config.mjs +7 -0
- package/dist/index.d.ts +173 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/types-9f8d440a.d.ts +17 -0
- package/package.json +39 -14
- package/preview.js +1 -1
- package/LICENSE +0 -21
- package/dist/cjs/config.js +0 -43
- package/dist/cjs/docs/config.js +0 -25
- package/dist/cjs/docs/extractArgTypes.js +0 -47
- package/dist/cjs/docs/extractProps.js +0 -57
- package/dist/cjs/docs/jsxDecorator.js +0 -210
- package/dist/cjs/docs/lib/captions.js +0 -18
- package/dist/cjs/docs/lib/componentTypes.js +0 -14
- package/dist/cjs/docs/lib/defaultValues/createDefaultValue.js +0 -86
- package/dist/cjs/docs/lib/defaultValues/createFromRawDefaultProp.js +0 -205
- package/dist/cjs/docs/lib/defaultValues/generateArray.js +0 -31
- package/dist/cjs/docs/lib/defaultValues/generateObject.js +0 -31
- package/dist/cjs/docs/lib/defaultValues/index.js +0 -31
- package/dist/cjs/docs/lib/defaultValues/prettyIdentifier.js +0 -36
- package/dist/cjs/docs/lib/generateCode.js +0 -74
- package/dist/cjs/docs/lib/index.js +0 -57
- package/dist/cjs/docs/lib/inspection/acornParser.js +0 -230
- package/dist/cjs/docs/lib/inspection/index.js +0 -31
- package/dist/cjs/docs/lib/inspection/inspectValue.js +0 -24
- package/dist/cjs/docs/lib/inspection/types.js +0 -19
- package/dist/cjs/docs/lib/isHtmlTag.js +0 -14
- package/dist/cjs/docs/propTypes/createType.js +0 -456
- package/dist/cjs/docs/propTypes/generateFuncSignature.js +0 -68
- package/dist/cjs/docs/propTypes/handleProp.js +0 -52
- package/dist/cjs/docs/propTypes/rawDefaultPropResolvers.js +0 -43
- package/dist/cjs/docs/propTypes/sortProps.js +0 -21
- package/dist/cjs/docs/react-argtypes.stories.js +0 -67
- package/dist/cjs/docs/typeScript/handleProp.js +0 -38
- package/dist/cjs/index.js +0 -98
- package/dist/cjs/preview/config.js +0 -19
- package/dist/cjs/preview/globals.js +0 -13
- package/dist/cjs/preview/index.js +0 -44
- package/dist/cjs/preview/render.js +0 -165
- package/dist/cjs/preview/types-6-0.js +0 -5
- package/dist/cjs/preview/types-6-3.js +0 -18
- package/dist/cjs/preview/types-7-0.js +0 -5
- package/dist/cjs/preview/types.js +0 -5
- package/dist/cjs/testing/index.js +0 -112
- package/dist/esm/config.js +0 -6
- package/dist/esm/docs/config.js +0 -12
- package/dist/esm/docs/extractArgTypes.js +0 -37
- package/dist/esm/docs/extractProps.js +0 -42
- package/dist/esm/docs/jsxDecorator.js +0 -170
- package/dist/esm/docs/lib/captions.js +0 -6
- package/dist/esm/docs/lib/componentTypes.js +0 -2
- package/dist/esm/docs/lib/defaultValues/createDefaultValue.js +0 -72
- package/dist/esm/docs/lib/defaultValues/createFromRawDefaultProp.js +0 -182
- package/dist/esm/docs/lib/defaultValues/generateArray.js +0 -21
- package/dist/esm/docs/lib/defaultValues/generateObject.js +0 -21
- package/dist/esm/docs/lib/defaultValues/index.js +0 -2
- package/dist/esm/docs/lib/defaultValues/prettyIdentifier.js +0 -24
- package/dist/esm/docs/lib/generateCode.js +0 -59
- package/dist/esm/docs/lib/index.js +0 -4
- package/dist/esm/docs/lib/inspection/acornParser.js +0 -211
- package/dist/esm/docs/lib/inspection/index.js +0 -2
- package/dist/esm/docs/lib/inspection/inspectValue.js +0 -15
- package/dist/esm/docs/lib/inspection/types.js +0 -12
- package/dist/esm/docs/lib/isHtmlTag.js +0 -4
- package/dist/esm/docs/propTypes/createType.js +0 -445
- package/dist/esm/docs/propTypes/generateFuncSignature.js +0 -57
- package/dist/esm/docs/propTypes/handleProp.js +0 -39
- package/dist/esm/docs/propTypes/rawDefaultPropResolvers.js +0 -31
- package/dist/esm/docs/propTypes/sortProps.js +0 -14
- package/dist/esm/docs/react-argtypes.stories.js +0 -54
- package/dist/esm/docs/typeScript/handleProp.js +0 -28
- package/dist/esm/index.js +0 -5
- package/dist/esm/preview/config.js +0 -1
- package/dist/esm/preview/globals.js +0 -8
- package/dist/esm/preview/index.js +0 -21
- package/dist/esm/preview/render.js +0 -141
- package/dist/esm/preview/types-6-0.js +0 -1
- package/dist/esm/preview/types-6-3.js +0 -10
- package/dist/esm/preview/types-7-0.js +0 -1
- package/dist/esm/preview/types.js +0 -1
- package/dist/esm/testing/index.js +0 -96
- package/dist/types/config.d.ts +0 -10
- package/dist/types/docs/config.d.ts +0 -10
- package/dist/types/docs/extractArgTypes.d.ts +0 -2
- package/dist/types/docs/extractProps.d.ts +0 -5
- package/dist/types/docs/jsxDecorator.d.ts +0 -23
- package/dist/types/docs/lib/captions.d.ts +0 -6
- package/dist/types/docs/lib/componentTypes.d.ts +0 -2
- package/dist/types/docs/lib/defaultValues/createDefaultValue.d.ts +0 -2
- package/dist/types/docs/lib/defaultValues/createFromRawDefaultProp.d.ts +0 -11
- package/dist/types/docs/lib/defaultValues/generateArray.d.ts +0 -3
- package/dist/types/docs/lib/defaultValues/generateObject.d.ts +0 -3
- package/dist/types/docs/lib/defaultValues/index.d.ts +0 -2
- package/dist/types/docs/lib/defaultValues/prettyIdentifier.d.ts +0 -4
- package/dist/types/docs/lib/generateCode.d.ts +0 -3
- package/dist/types/docs/lib/index.d.ts +0 -4
- package/dist/types/docs/lib/inspection/acornParser.d.ts +0 -7
- package/dist/types/docs/lib/inspection/index.d.ts +0 -2
- package/dist/types/docs/lib/inspection/inspectValue.d.ts +0 -2
- package/dist/types/docs/lib/inspection/types.d.ts +0 -50
- package/dist/types/docs/lib/isHtmlTag.d.ts +0 -1
- package/dist/types/docs/propTypes/createType.d.ts +0 -2
- package/dist/types/docs/propTypes/generateFuncSignature.d.ts +0 -4
- package/dist/types/docs/propTypes/handleProp.d.ts +0 -5
- package/dist/types/docs/propTypes/rawDefaultPropResolvers.d.ts +0 -1
- package/dist/types/docs/propTypes/sortProps.d.ts +0 -4
- package/dist/types/docs/react-argtypes.stories.d.ts +0 -1
- package/dist/types/docs/typeScript/handleProp.d.ts +0 -3
- package/dist/types/index.d.ts +0 -4
- package/dist/types/preview/config.d.ts +0 -1
- package/dist/types/preview/globals.d.ts +0 -1
- package/dist/types/preview/index.d.ts +0 -25
- package/dist/types/preview/render.d.ts +0 -5
- package/dist/types/preview/types-6-0.d.ts +0 -35
- package/dist/types/preview/types-6-3.d.ts +0 -40
- package/dist/types/preview/types-7-0.d.ts +0 -21
- package/dist/types/preview/types.d.ts +0 -16
- package/dist/types/testing/index.d.ts +0 -84
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.skipJsxRender = exports.renderJsx = exports.jsxDecorator = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _reactElementToJsxString = _interopRequireDefault(require("react-element-to-jsx-string"));
|
|
11
|
-
|
|
12
|
-
var _tsDedent = _interopRequireDefault(require("ts-dedent"));
|
|
13
|
-
|
|
14
|
-
var _utilDeprecate = _interopRequireDefault(require("util-deprecate"));
|
|
15
|
-
|
|
16
|
-
var _addons = require("@storybook/addons");
|
|
17
|
-
|
|
18
|
-
var _docsTools = require("@storybook/docs-tools");
|
|
19
|
-
|
|
20
|
-
var _clientLogger = require("@storybook/client-logger");
|
|
21
|
-
|
|
22
|
-
var _lib = require("./lib");
|
|
23
|
-
|
|
24
|
-
const _excluded = ["mdxType", "originalType", "children"];
|
|
25
|
-
|
|
26
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
27
|
-
|
|
28
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
29
|
-
|
|
30
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
|
-
|
|
32
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
33
|
-
|
|
34
|
-
/** Run the user supplied onBeforeRender function if it exists */
|
|
35
|
-
const applyBeforeRender = (domString, options) => {
|
|
36
|
-
if (typeof options.onBeforeRender !== 'function') {
|
|
37
|
-
return domString;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const deprecatedOnBeforeRender = (0, _utilDeprecate.default)(options.onBeforeRender, (0, _tsDedent.default)`
|
|
41
|
-
StoryFn.parameters.jsx.onBeforeRender was deprecated.
|
|
42
|
-
Prefer StoryFn.parameters.jsx.transformSource instead.
|
|
43
|
-
See https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-onbeforerender for details.
|
|
44
|
-
`);
|
|
45
|
-
return deprecatedOnBeforeRender(domString);
|
|
46
|
-
};
|
|
47
|
-
/** Run the user supplied transformSource function if it exists */
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const applyTransformSource = (domString, options, context) => {
|
|
51
|
-
if (typeof options.transformSource !== 'function') {
|
|
52
|
-
return domString;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
return options.transformSource(domString, context);
|
|
56
|
-
};
|
|
57
|
-
/** Apply the users parameters and render the jsx for a story */
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const renderJsx = (code, options) => {
|
|
61
|
-
if (typeof code === 'undefined') {
|
|
62
|
-
_clientLogger.logger.warn('Too many skip or undefined component');
|
|
63
|
-
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
let renderedJSX = code;
|
|
68
|
-
const Type = renderedJSX.type;
|
|
69
|
-
|
|
70
|
-
for (let i = 0; i < options.skip; i += 1) {
|
|
71
|
-
if (typeof renderedJSX === 'undefined') {
|
|
72
|
-
_clientLogger.logger.warn('Cannot skip undefined element');
|
|
73
|
-
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (_react.default.Children.count(renderedJSX) > 1) {
|
|
78
|
-
_clientLogger.logger.warn('Trying to skip an array of elements');
|
|
79
|
-
|
|
80
|
-
return null;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (typeof renderedJSX.props.children === 'undefined') {
|
|
84
|
-
_clientLogger.logger.warn('Not enough children to skip elements.');
|
|
85
|
-
|
|
86
|
-
if (typeof renderedJSX.type === 'function' && renderedJSX.type.name === '') {
|
|
87
|
-
renderedJSX = /*#__PURE__*/_react.default.createElement(Type, renderedJSX.props);
|
|
88
|
-
}
|
|
89
|
-
} else if (typeof renderedJSX.props.children === 'function') {
|
|
90
|
-
renderedJSX = renderedJSX.props.children();
|
|
91
|
-
} else {
|
|
92
|
-
renderedJSX = renderedJSX.props.children;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const displayNameDefaults = typeof options.displayName === 'string' ? {
|
|
97
|
-
showFunctions: true,
|
|
98
|
-
displayName: () => options.displayName
|
|
99
|
-
} : {
|
|
100
|
-
// To get exotic component names resolving properly
|
|
101
|
-
displayName: el => el.type.displayName || (0, _docsTools.getDocgenSection)(el.type, 'displayName') || (el.type.name !== '_default' ? el.type.name : null) || (typeof el.type === 'function' ? 'No Display Name' : null) || ((0, _lib.isForwardRef)(el.type) ? el.type.render.name : null) || ((0, _lib.isMemo)(el.type) ? el.type.type.name : null) || el.type
|
|
102
|
-
};
|
|
103
|
-
const filterDefaults = {
|
|
104
|
-
filterProps: (value, key) => value !== undefined
|
|
105
|
-
};
|
|
106
|
-
const opts = Object.assign({}, displayNameDefaults, filterDefaults, options);
|
|
107
|
-
|
|
108
|
-
const result = _react.default.Children.map(code, c => {
|
|
109
|
-
// @ts-ignore FIXME: workaround react-element-to-jsx-string
|
|
110
|
-
const child = typeof c === 'number' ? c.toString() : c;
|
|
111
|
-
let string = applyBeforeRender((0, _reactElementToJsxString.default)(child, opts), options);
|
|
112
|
-
|
|
113
|
-
if (string.indexOf('"') > -1) {
|
|
114
|
-
const matches = string.match(/\S+=\\"([^"]*)\\"/g);
|
|
115
|
-
|
|
116
|
-
if (matches) {
|
|
117
|
-
matches.forEach(match => {
|
|
118
|
-
string = string.replace(match, match.replace(/"/g, "'"));
|
|
119
|
-
});
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
return string;
|
|
124
|
-
}).join('\n');
|
|
125
|
-
|
|
126
|
-
return result.replace(/function\s+noRefCheck\(\)\s+\{\}/, '() => {}');
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
exports.renderJsx = renderJsx;
|
|
130
|
-
const defaultOpts = {
|
|
131
|
-
skip: 0,
|
|
132
|
-
showFunctions: false,
|
|
133
|
-
enableBeautify: true,
|
|
134
|
-
showDefaultProps: false
|
|
135
|
-
};
|
|
136
|
-
|
|
137
|
-
const skipJsxRender = context => {
|
|
138
|
-
var _context$parameters$d;
|
|
139
|
-
|
|
140
|
-
const sourceParams = context === null || context === void 0 ? void 0 : (_context$parameters$d = context.parameters.docs) === null || _context$parameters$d === void 0 ? void 0 : _context$parameters$d.source;
|
|
141
|
-
const isArgsStory = context === null || context === void 0 ? void 0 : context.parameters.__isArgsStory; // always render if the user forces it
|
|
142
|
-
|
|
143
|
-
if ((sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.type) === _docsTools.SourceType.DYNAMIC) {
|
|
144
|
-
return false;
|
|
145
|
-
} // never render if the user is forcing the block to render code, or
|
|
146
|
-
// if the user provides code, or if it's not an args story.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return !isArgsStory || (sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.code) || (sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.type) === _docsTools.SourceType.CODE;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
exports.skipJsxRender = skipJsxRender;
|
|
153
|
-
|
|
154
|
-
const isMdx = node => {
|
|
155
|
-
var _node$type, _node$props;
|
|
156
|
-
|
|
157
|
-
return ((_node$type = node.type) === null || _node$type === void 0 ? void 0 : _node$type.displayName) === 'MDXCreateElement' && !!((_node$props = node.props) !== null && _node$props !== void 0 && _node$props.mdxType);
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
const mdxToJsx = node => {
|
|
161
|
-
if (!isMdx(node)) return node;
|
|
162
|
-
|
|
163
|
-
const _node$props2 = node.props,
|
|
164
|
-
{
|
|
165
|
-
originalType,
|
|
166
|
-
children
|
|
167
|
-
} = _node$props2,
|
|
168
|
-
rest = _objectWithoutPropertiesLoose(_node$props2, _excluded);
|
|
169
|
-
|
|
170
|
-
let jsxChildren = [];
|
|
171
|
-
|
|
172
|
-
if (children) {
|
|
173
|
-
const array = Array.isArray(children) ? children : [children];
|
|
174
|
-
jsxChildren = array.map(mdxToJsx);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
return /*#__PURE__*/(0, _react.createElement)(originalType, rest, ...jsxChildren);
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
const jsxDecorator = (storyFn, context) => {
|
|
181
|
-
var _context$parameters$d2, _context$parameters$d3;
|
|
182
|
-
|
|
183
|
-
const channel = _addons.addons.getChannel();
|
|
184
|
-
|
|
185
|
-
const skip = skipJsxRender(context);
|
|
186
|
-
const story = storyFn();
|
|
187
|
-
let jsx = '';
|
|
188
|
-
(0, _addons.useEffect)(() => {
|
|
189
|
-
if (!skip) channel.emit(_docsTools.SNIPPET_RENDERED, (context || {}).id, jsx);
|
|
190
|
-
}); // We only need to render JSX if the source block is actually going to
|
|
191
|
-
// consume it. Otherwise it's just slowing us down.
|
|
192
|
-
|
|
193
|
-
if (skip) {
|
|
194
|
-
return story;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
const options = Object.assign({}, defaultOpts, (context === null || context === void 0 ? void 0 : context.parameters.jsx) || {}); // Exclude decorators from source code snippet by default
|
|
198
|
-
|
|
199
|
-
const storyJsx = context !== null && context !== void 0 && (_context$parameters$d2 = context.parameters.docs) !== null && _context$parameters$d2 !== void 0 && (_context$parameters$d3 = _context$parameters$d2.source) !== null && _context$parameters$d3 !== void 0 && _context$parameters$d3.excludeDecorators ? context.originalStoryFn(context.args, context) : story;
|
|
200
|
-
const sourceJsx = mdxToJsx(storyJsx);
|
|
201
|
-
const rendered = renderJsx(sourceJsx, options);
|
|
202
|
-
|
|
203
|
-
if (rendered) {
|
|
204
|
-
jsx = applyTransformSource(rendered, options, context);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
return story;
|
|
208
|
-
};
|
|
209
|
-
|
|
210
|
-
exports.jsxDecorator = jsxDecorator;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.OBJECT_CAPTION = exports.FUNCTION_CAPTION = exports.ELEMENT_CAPTION = exports.CUSTOM_CAPTION = exports.CLASS_CAPTION = exports.ARRAY_CAPTION = void 0;
|
|
7
|
-
const CUSTOM_CAPTION = 'custom';
|
|
8
|
-
exports.CUSTOM_CAPTION = CUSTOM_CAPTION;
|
|
9
|
-
const OBJECT_CAPTION = 'object';
|
|
10
|
-
exports.OBJECT_CAPTION = OBJECT_CAPTION;
|
|
11
|
-
const ARRAY_CAPTION = 'array';
|
|
12
|
-
exports.ARRAY_CAPTION = ARRAY_CAPTION;
|
|
13
|
-
const CLASS_CAPTION = 'class';
|
|
14
|
-
exports.CLASS_CAPTION = CLASS_CAPTION;
|
|
15
|
-
const FUNCTION_CAPTION = 'func';
|
|
16
|
-
exports.FUNCTION_CAPTION = FUNCTION_CAPTION;
|
|
17
|
-
const ELEMENT_CAPTION = 'element';
|
|
18
|
-
exports.ELEMENT_CAPTION = ELEMENT_CAPTION;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.isMemo = exports.isForwardRef = void 0;
|
|
7
|
-
|
|
8
|
-
const isMemo = component => component.$$typeof === Symbol.for('react.memo');
|
|
9
|
-
|
|
10
|
-
exports.isMemo = isMemo;
|
|
11
|
-
|
|
12
|
-
const isForwardRef = component => component.$$typeof === Symbol.for('react.forward_ref');
|
|
13
|
-
|
|
14
|
-
exports.isForwardRef = isForwardRef;
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createDefaultValue = createDefaultValue;
|
|
7
|
-
|
|
8
|
-
var _docsTools = require("@storybook/docs-tools");
|
|
9
|
-
|
|
10
|
-
var _captions = require("../captions");
|
|
11
|
-
|
|
12
|
-
var _inspection = require("../inspection");
|
|
13
|
-
|
|
14
|
-
var _isHtmlTag = require("../isHtmlTag");
|
|
15
|
-
|
|
16
|
-
var _generateCode = require("../generateCode");
|
|
17
|
-
|
|
18
|
-
var _generateObject = require("./generateObject");
|
|
19
|
-
|
|
20
|
-
var _generateArray = require("./generateArray");
|
|
21
|
-
|
|
22
|
-
var _prettyIdentifier = require("./prettyIdentifier");
|
|
23
|
-
|
|
24
|
-
function generateFunc({
|
|
25
|
-
inferredType,
|
|
26
|
-
ast
|
|
27
|
-
}) {
|
|
28
|
-
const {
|
|
29
|
-
identifier
|
|
30
|
-
} = inferredType;
|
|
31
|
-
|
|
32
|
-
if (identifier != null) {
|
|
33
|
-
return (0, _docsTools.createSummaryValue)((0, _prettyIdentifier.getPrettyIdentifier)(inferredType), (0, _generateCode.generateCode)(ast));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const prettyCaption = (0, _generateCode.generateCode)(ast, true);
|
|
37
|
-
return !(0, _docsTools.isTooLongForDefaultValueSummary)(prettyCaption) ? (0, _docsTools.createSummaryValue)(prettyCaption) : (0, _docsTools.createSummaryValue)(_captions.FUNCTION_CAPTION, (0, _generateCode.generateCode)(ast));
|
|
38
|
-
} // All elements are JSX elements.
|
|
39
|
-
// JSX elements are not supported by escodegen.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
function generateElement(defaultValue, inspectionResult) {
|
|
43
|
-
const {
|
|
44
|
-
inferredType
|
|
45
|
-
} = inspectionResult;
|
|
46
|
-
const {
|
|
47
|
-
identifier
|
|
48
|
-
} = inferredType;
|
|
49
|
-
|
|
50
|
-
if (identifier != null) {
|
|
51
|
-
if (!(0, _isHtmlTag.isHtmlTag)(identifier)) {
|
|
52
|
-
const prettyIdentifier = (0, _prettyIdentifier.getPrettyIdentifier)(inferredType);
|
|
53
|
-
return (0, _docsTools.createSummaryValue)(prettyIdentifier, defaultValue);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return !(0, _docsTools.isTooLongForDefaultValueSummary)(defaultValue) ? (0, _docsTools.createSummaryValue)(defaultValue) : (0, _docsTools.createSummaryValue)(_captions.ELEMENT_CAPTION, defaultValue);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function createDefaultValue(defaultValue) {
|
|
61
|
-
try {
|
|
62
|
-
const inspectionResult = (0, _inspection.inspectValue)(defaultValue);
|
|
63
|
-
|
|
64
|
-
switch (inspectionResult.inferredType.type) {
|
|
65
|
-
case _inspection.InspectionType.OBJECT:
|
|
66
|
-
return (0, _generateObject.generateObject)(inspectionResult);
|
|
67
|
-
|
|
68
|
-
case _inspection.InspectionType.FUNCTION:
|
|
69
|
-
return generateFunc(inspectionResult);
|
|
70
|
-
|
|
71
|
-
case _inspection.InspectionType.ELEMENT:
|
|
72
|
-
return generateElement(defaultValue, inspectionResult);
|
|
73
|
-
|
|
74
|
-
case _inspection.InspectionType.ARRAY:
|
|
75
|
-
return (0, _generateArray.generateArray)(inspectionResult);
|
|
76
|
-
|
|
77
|
-
default:
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
} catch (e) {
|
|
81
|
-
// eslint-disable-next-line no-console
|
|
82
|
-
console.error(e);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return null;
|
|
86
|
-
}
|
|
@@ -1,205 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createDefaultValueFromRawDefaultProp = createDefaultValueFromRawDefaultProp;
|
|
7
|
-
exports.createTypeResolvers = createTypeResolvers;
|
|
8
|
-
exports.extractFunctionName = extractFunctionName;
|
|
9
|
-
|
|
10
|
-
var _isPlainObject = _interopRequireDefault(require("lodash/isPlainObject"));
|
|
11
|
-
|
|
12
|
-
var _isFunction = _interopRequireDefault(require("lodash/isFunction"));
|
|
13
|
-
|
|
14
|
-
var _isString = _interopRequireDefault(require("lodash/isString"));
|
|
15
|
-
|
|
16
|
-
var _reactElementToJsxString = _interopRequireDefault(require("react-element-to-jsx-string"));
|
|
17
|
-
|
|
18
|
-
var _docsTools = require("@storybook/docs-tools");
|
|
19
|
-
|
|
20
|
-
var _inspection = require("../inspection");
|
|
21
|
-
|
|
22
|
-
var _generateObject = require("./generateObject");
|
|
23
|
-
|
|
24
|
-
var _generateArray = require("./generateArray");
|
|
25
|
-
|
|
26
|
-
var _prettyIdentifier = require("./prettyIdentifier");
|
|
27
|
-
|
|
28
|
-
var _captions = require("../captions");
|
|
29
|
-
|
|
30
|
-
var _isHtmlTag = require("../isHtmlTag");
|
|
31
|
-
|
|
32
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
33
|
-
|
|
34
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
35
|
-
// @ts-ignore
|
|
36
|
-
function isReactElement(element) {
|
|
37
|
-
return element.$$typeof != null;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function extractFunctionName(func, propName) {
|
|
41
|
-
const {
|
|
42
|
-
name
|
|
43
|
-
} = func; // Comparison with the prop name is to discard inferred function names.
|
|
44
|
-
|
|
45
|
-
if (name !== '' && name !== 'anonymous' && name !== propName) {
|
|
46
|
-
return name;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const stringResolver = rawDefaultProp => {
|
|
53
|
-
return (0, _docsTools.createSummaryValue)(JSON.stringify(rawDefaultProp));
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
function generateReactObject(rawDefaultProp) {
|
|
57
|
-
const {
|
|
58
|
-
type
|
|
59
|
-
} = rawDefaultProp;
|
|
60
|
-
const {
|
|
61
|
-
displayName
|
|
62
|
-
} = type;
|
|
63
|
-
const jsx = (0, _reactElementToJsxString.default)(rawDefaultProp, {});
|
|
64
|
-
|
|
65
|
-
if (displayName != null) {
|
|
66
|
-
const prettyIdentifier = (0, _prettyIdentifier.getPrettyElementIdentifier)(displayName);
|
|
67
|
-
return (0, _docsTools.createSummaryValue)(prettyIdentifier, jsx);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if ((0, _isString.default)(type)) {
|
|
71
|
-
// This is an HTML element.
|
|
72
|
-
if ((0, _isHtmlTag.isHtmlTag)(type)) {
|
|
73
|
-
const jsxCompact = (0, _reactElementToJsxString.default)(rawDefaultProp, {
|
|
74
|
-
tabStop: 0
|
|
75
|
-
});
|
|
76
|
-
const jsxSummary = jsxCompact.replace(/\r?\n|\r/g, '');
|
|
77
|
-
|
|
78
|
-
if (!(0, _docsTools.isTooLongForDefaultValueSummary)(jsxSummary)) {
|
|
79
|
-
return (0, _docsTools.createSummaryValue)(jsxSummary);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return (0, _docsTools.createSummaryValue)(_captions.ELEMENT_CAPTION, jsx);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const objectResolver = rawDefaultProp => {
|
|
88
|
-
if (isReactElement(rawDefaultProp) && rawDefaultProp.type != null) {
|
|
89
|
-
return generateReactObject(rawDefaultProp);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if ((0, _isPlainObject.default)(rawDefaultProp)) {
|
|
93
|
-
const inspectionResult = (0, _inspection.inspectValue)(JSON.stringify(rawDefaultProp));
|
|
94
|
-
return (0, _generateObject.generateObject)(inspectionResult);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (Array.isArray(rawDefaultProp)) {
|
|
98
|
-
const inspectionResult = (0, _inspection.inspectValue)(JSON.stringify(rawDefaultProp));
|
|
99
|
-
return (0, _generateArray.generateArray)(inspectionResult);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return (0, _docsTools.createSummaryValue)(_captions.OBJECT_CAPTION);
|
|
103
|
-
};
|
|
104
|
-
|
|
105
|
-
const functionResolver = (rawDefaultProp, propDef) => {
|
|
106
|
-
let isElement = false;
|
|
107
|
-
let inspectionResult; // Try to display the name of the component. The body of the component is omitted since the code has been transpiled.
|
|
108
|
-
|
|
109
|
-
if ((0, _isFunction.default)(rawDefaultProp.render)) {
|
|
110
|
-
isElement = true;
|
|
111
|
-
} else if (rawDefaultProp.prototype != null && (0, _isFunction.default)(rawDefaultProp.prototype.render)) {
|
|
112
|
-
isElement = true;
|
|
113
|
-
} else {
|
|
114
|
-
let innerElement;
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
inspectionResult = (0, _inspection.inspectValue)(rawDefaultProp.toString());
|
|
118
|
-
const {
|
|
119
|
-
hasParams,
|
|
120
|
-
params
|
|
121
|
-
} = inspectionResult.inferredType;
|
|
122
|
-
|
|
123
|
-
if (hasParams) {
|
|
124
|
-
// It might be a functional component accepting props.
|
|
125
|
-
if (params.length === 1 && params[0].type === 'ObjectPattern') {
|
|
126
|
-
innerElement = rawDefaultProp({});
|
|
127
|
-
}
|
|
128
|
-
} else {
|
|
129
|
-
innerElement = rawDefaultProp();
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (innerElement != null) {
|
|
133
|
-
if (isReactElement(innerElement)) {
|
|
134
|
-
isElement = true;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
} catch (e) {// do nothing.
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const funcName = extractFunctionName(rawDefaultProp, propDef.name);
|
|
142
|
-
|
|
143
|
-
if (funcName != null) {
|
|
144
|
-
if (isElement) {
|
|
145
|
-
return (0, _docsTools.createSummaryValue)((0, _prettyIdentifier.getPrettyElementIdentifier)(funcName));
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
if (inspectionResult != null) {
|
|
149
|
-
inspectionResult = (0, _inspection.inspectValue)(rawDefaultProp.toString());
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const {
|
|
153
|
-
hasParams
|
|
154
|
-
} = inspectionResult.inferredType;
|
|
155
|
-
return (0, _docsTools.createSummaryValue)((0, _prettyIdentifier.getPrettyFuncIdentifier)(funcName, hasParams));
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
return (0, _docsTools.createSummaryValue)(isElement ? _captions.ELEMENT_CAPTION : _captions.FUNCTION_CAPTION);
|
|
159
|
-
};
|
|
160
|
-
|
|
161
|
-
const defaultResolver = rawDefaultProp => {
|
|
162
|
-
return (0, _docsTools.createSummaryValue)(rawDefaultProp.toString());
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
const DEFAULT_TYPE_RESOLVERS = {
|
|
166
|
-
string: stringResolver,
|
|
167
|
-
object: objectResolver,
|
|
168
|
-
function: functionResolver,
|
|
169
|
-
default: defaultResolver
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
function createTypeResolvers(customResolvers = {}) {
|
|
173
|
-
return Object.assign({}, DEFAULT_TYPE_RESOLVERS, customResolvers);
|
|
174
|
-
} // When react-docgen cannot provide a defaultValue we take it from the raw defaultProp.
|
|
175
|
-
// It works fine for types that are not transpiled. For the types that are transpiled, we can only provide partial support.
|
|
176
|
-
// This means that:
|
|
177
|
-
// - The detail might not be available.
|
|
178
|
-
// - Identifiers might not be "prettified" for all the types.
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
function createDefaultValueFromRawDefaultProp(rawDefaultProp, propDef, typeResolvers = DEFAULT_TYPE_RESOLVERS) {
|
|
182
|
-
try {
|
|
183
|
-
// Keep the extra () otherwise it will fail for functions.
|
|
184
|
-
switch (typeof rawDefaultProp) {
|
|
185
|
-
case 'string':
|
|
186
|
-
return typeResolvers.string(rawDefaultProp, propDef);
|
|
187
|
-
|
|
188
|
-
case 'object':
|
|
189
|
-
return typeResolvers.object(rawDefaultProp, propDef);
|
|
190
|
-
|
|
191
|
-
case 'function':
|
|
192
|
-
{
|
|
193
|
-
return typeResolvers.function(rawDefaultProp, propDef);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
default:
|
|
197
|
-
return typeResolvers.default(rawDefaultProp, propDef);
|
|
198
|
-
}
|
|
199
|
-
} catch (e) {
|
|
200
|
-
// eslint-disable-next-line no-console
|
|
201
|
-
console.error(e);
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return null;
|
|
205
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.generateArray = generateArray;
|
|
7
|
-
|
|
8
|
-
var _docsTools = require("@storybook/docs-tools");
|
|
9
|
-
|
|
10
|
-
var _captions = require("../captions");
|
|
11
|
-
|
|
12
|
-
var _generateCode = require("../generateCode");
|
|
13
|
-
|
|
14
|
-
function generateArray({
|
|
15
|
-
inferredType,
|
|
16
|
-
ast
|
|
17
|
-
}) {
|
|
18
|
-
const {
|
|
19
|
-
depth
|
|
20
|
-
} = inferredType;
|
|
21
|
-
|
|
22
|
-
if (depth <= 2) {
|
|
23
|
-
const compactArray = (0, _generateCode.generateArrayCode)(ast, true);
|
|
24
|
-
|
|
25
|
-
if (!(0, _docsTools.isTooLongForDefaultValueSummary)(compactArray)) {
|
|
26
|
-
return (0, _docsTools.createSummaryValue)(compactArray);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return (0, _docsTools.createSummaryValue)(_captions.ARRAY_CAPTION, (0, _generateCode.generateArrayCode)(ast));
|
|
31
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.generateObject = generateObject;
|
|
7
|
-
|
|
8
|
-
var _docsTools = require("@storybook/docs-tools");
|
|
9
|
-
|
|
10
|
-
var _captions = require("../captions");
|
|
11
|
-
|
|
12
|
-
var _generateCode = require("../generateCode");
|
|
13
|
-
|
|
14
|
-
function generateObject({
|
|
15
|
-
inferredType,
|
|
16
|
-
ast
|
|
17
|
-
}) {
|
|
18
|
-
const {
|
|
19
|
-
depth
|
|
20
|
-
} = inferredType;
|
|
21
|
-
|
|
22
|
-
if (depth === 1) {
|
|
23
|
-
const compactObject = (0, _generateCode.generateObjectCode)(ast, true);
|
|
24
|
-
|
|
25
|
-
if (!(0, _docsTools.isTooLongForDefaultValueSummary)(compactObject)) {
|
|
26
|
-
return (0, _docsTools.createSummaryValue)(compactObject);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return (0, _docsTools.createSummaryValue)(_captions.OBJECT_CAPTION, (0, _generateCode.generateObjectCode)(ast));
|
|
31
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _createDefaultValue = require("./createDefaultValue");
|
|
8
|
-
|
|
9
|
-
Object.keys(_createDefaultValue).forEach(function (key) {
|
|
10
|
-
if (key === "default" || key === "__esModule") return;
|
|
11
|
-
if (key in exports && exports[key] === _createDefaultValue[key]) return;
|
|
12
|
-
Object.defineProperty(exports, key, {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _createDefaultValue[key];
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
var _createFromRawDefaultProp = require("./createFromRawDefaultProp");
|
|
21
|
-
|
|
22
|
-
Object.keys(_createFromRawDefaultProp).forEach(function (key) {
|
|
23
|
-
if (key === "default" || key === "__esModule") return;
|
|
24
|
-
if (key in exports && exports[key] === _createFromRawDefaultProp[key]) return;
|
|
25
|
-
Object.defineProperty(exports, key, {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () {
|
|
28
|
-
return _createFromRawDefaultProp[key];
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
});
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getPrettyElementIdentifier = getPrettyElementIdentifier;
|
|
7
|
-
exports.getPrettyFuncIdentifier = getPrettyFuncIdentifier;
|
|
8
|
-
exports.getPrettyIdentifier = getPrettyIdentifier;
|
|
9
|
-
|
|
10
|
-
var _inspection = require("../inspection");
|
|
11
|
-
|
|
12
|
-
function getPrettyFuncIdentifier(identifier, hasArguments) {
|
|
13
|
-
return hasArguments ? `${identifier}( ... )` : `${identifier}()`;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
function getPrettyElementIdentifier(identifier) {
|
|
17
|
-
return `<${identifier} />`;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function getPrettyIdentifier(inferredType) {
|
|
21
|
-
const {
|
|
22
|
-
type,
|
|
23
|
-
identifier
|
|
24
|
-
} = inferredType;
|
|
25
|
-
|
|
26
|
-
switch (type) {
|
|
27
|
-
case _inspection.InspectionType.FUNCTION:
|
|
28
|
-
return getPrettyFuncIdentifier(identifier, inferredType.hasParams);
|
|
29
|
-
|
|
30
|
-
case _inspection.InspectionType.ELEMENT:
|
|
31
|
-
return getPrettyElementIdentifier(identifier);
|
|
32
|
-
|
|
33
|
-
default:
|
|
34
|
-
return identifier;
|
|
35
|
-
}
|
|
36
|
-
}
|