@storybook/addon-docs 7.0.0-alpha.39 → 7.0.0-alpha.40
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/README.md +0 -62
- package/dist/cjs/DocsRenderer.js +3 -1
- package/dist/cjs/preset.js +4 -10
- package/dist/esm/DocsRenderer.js +2 -1
- package/dist/esm/preset.js +5 -5
- package/jest-transform-mdx.js +4 -3
- package/package.json +18 -23
package/README.md
CHANGED
|
@@ -23,7 +23,6 @@ Read on to learn more:
|
|
|
23
23
|
- [Installation](#installation)
|
|
24
24
|
- [Be sure to check framework specific installation needs](#be-sure-to-check-framework-specific-installation-needs)
|
|
25
25
|
- [Preset options](#preset-options)
|
|
26
|
-
- [Manual configuration](#manual-configuration)
|
|
27
26
|
- [TypeScript configuration](#typescript-configuration)
|
|
28
27
|
- [More resources](#more-resources)
|
|
29
28
|
|
|
@@ -166,67 +165,6 @@ import Changelog from '../CHANGELOG.md';
|
|
|
166
165
|
<Changelog />
|
|
167
166
|
```
|
|
168
167
|
|
|
169
|
-
## Manual configuration
|
|
170
|
-
|
|
171
|
-
We recommend using the preset, which should work out of the box. If you don't want to use the preset, and prefer to configure "the long way" add the following configuration to `.storybook/main.js` (see comments inline for explanation):
|
|
172
|
-
|
|
173
|
-
```js
|
|
174
|
-
const createCompiler = require('@storybook/addon-docs/mdx-compiler-plugin');
|
|
175
|
-
|
|
176
|
-
module.exports = {
|
|
177
|
-
// 1. register the docs panel (as opposed to '@storybook/addon-docs' which
|
|
178
|
-
// will configure everything with a preset)
|
|
179
|
-
addons: ['@storybook/addon-docs/register'],
|
|
180
|
-
// 2. manually configure webpack, since you're not using the preset
|
|
181
|
-
webpackFinal: async (config) => {
|
|
182
|
-
config.module.rules.push({
|
|
183
|
-
// 2a. Load `.stories.mdx` / `.story.mdx` files as CSF and generate
|
|
184
|
-
// the docs page from the markdown
|
|
185
|
-
test: /\.(stories|story)\.mdx$/,
|
|
186
|
-
use: [
|
|
187
|
-
{
|
|
188
|
-
// Need to add babel-loader as dependency: `yarn add -D babel-loader`
|
|
189
|
-
loader: require.resolve('babel-loader'),
|
|
190
|
-
// may or may not need this line depending on your app's setup
|
|
191
|
-
options: {
|
|
192
|
-
plugins: ['@babel/plugin-transform-react-jsx'],
|
|
193
|
-
},
|
|
194
|
-
},
|
|
195
|
-
{
|
|
196
|
-
loader: '@mdx-js/loader',
|
|
197
|
-
options: {
|
|
198
|
-
compilers: [createCompiler({})],
|
|
199
|
-
},
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
});
|
|
203
|
-
// 2b. Run `source-loader` on story files to show their source code
|
|
204
|
-
// automatically in `DocsPage` or the `Source` doc block.
|
|
205
|
-
config.module.rules.push({
|
|
206
|
-
test: /\.(stories|story)\.[tj]sx?$/,
|
|
207
|
-
loader: require.resolve('@storybook/source-loader'),
|
|
208
|
-
exclude: [/node_modules/],
|
|
209
|
-
enforce: 'pre',
|
|
210
|
-
});
|
|
211
|
-
return config;
|
|
212
|
-
},
|
|
213
|
-
};
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
You'll also need to set up the docs parameter in `.storybook/preview.js`. This includes the `DocsPage` for rendering the page, a container, and various configuration options, such as `extractComponentDescription` for manually extracting a component description:
|
|
217
|
-
|
|
218
|
-
```js
|
|
219
|
-
import { addParameters } from '@storybook/react';
|
|
220
|
-
import { DocsPage, DocsContainer } from '@storybook/addon-docs';
|
|
221
|
-
|
|
222
|
-
addParameters({
|
|
223
|
-
docs: {
|
|
224
|
-
container: DocsContainer,
|
|
225
|
-
page: DocsPage,
|
|
226
|
-
},
|
|
227
|
-
});
|
|
228
|
-
```
|
|
229
|
-
|
|
230
168
|
## TypeScript configuration
|
|
231
169
|
|
|
232
170
|
As of SB6 [TypeScript is zero-config](https://storybook.js.org/docs/react/configure/typescript) and should work with SB Docs out of the box. For advanced configuration options, refer to the [Props documentation](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/props-tables.md).
|
package/dist/cjs/DocsRenderer.js
CHANGED
|
@@ -33,8 +33,10 @@ class DocsRenderer {
|
|
|
33
33
|
// Use a random key to force the container to re-render each time we call `renderDocs`
|
|
34
34
|
// TODO: do we still need this? It was needed for angular (legacy) inline rendering:
|
|
35
35
|
// https://github.com/storybookjs/storybook/pull/16149
|
|
36
|
+
const components = Object.assign({}, defaultComponents, docsParameter === null || docsParameter === void 0 ? void 0 : docsParameter.components);
|
|
37
|
+
|
|
36
38
|
_reactDom.default.render( /*#__PURE__*/_react.default.createElement(_react2.MDXProvider, {
|
|
37
|
-
components:
|
|
39
|
+
components: components
|
|
38
40
|
}, /*#__PURE__*/_react.default.createElement(_blocks.Docs, {
|
|
39
41
|
key: Math.random(),
|
|
40
42
|
context: context,
|
package/dist/cjs/preset.js
CHANGED
|
@@ -12,8 +12,6 @@ var _remarkSlug = _interopRequireDefault(require("remark-slug"));
|
|
|
12
12
|
|
|
13
13
|
var _remarkExternalLinks = _interopRequireDefault(require("remark-external-links"));
|
|
14
14
|
|
|
15
|
-
var _global = _interopRequireDefault(require("global"));
|
|
16
|
-
|
|
17
15
|
var _nodeLogger = require("@storybook/node-logger");
|
|
18
16
|
|
|
19
17
|
var _csfTools = require("@storybook/csf-tools");
|
|
@@ -54,8 +52,6 @@ function createBabelOptions({
|
|
|
54
52
|
}
|
|
55
53
|
|
|
56
54
|
async function webpack(webpackConfig = {}, options) {
|
|
57
|
-
var _global$FEATURES, _global$FEATURES2;
|
|
58
|
-
|
|
59
55
|
const resolvedBabelLoader = await options.presets.apply('babelLoaderRef');
|
|
60
56
|
const {
|
|
61
57
|
module = {}
|
|
@@ -76,11 +72,11 @@ async function webpack(webpackConfig = {}, options) {
|
|
|
76
72
|
skipCsf: true,
|
|
77
73
|
remarkPlugins: [_remarkSlug.default, _remarkExternalLinks.default]
|
|
78
74
|
};
|
|
79
|
-
const mdxVersion = (_global$FEATURES = _global.default.FEATURES) !== null && _global$FEATURES !== void 0 && _global$FEATURES.previewMdx2 ? 'MDX2' : 'MDX1';
|
|
80
75
|
|
|
81
|
-
_nodeLogger.logger.info(`Addon-docs: using
|
|
76
|
+
_nodeLogger.logger.info(`Addon-docs: using MDX2`);
|
|
77
|
+
|
|
78
|
+
const mdxLoader = require.resolve('@storybook/mdx2-csf/loader'); // set `sourceLoaderOptions` to `null` to disable for manual configuration
|
|
82
79
|
|
|
83
|
-
const mdxLoader = (_global$FEATURES2 = _global.default.FEATURES) !== null && _global$FEATURES2 !== void 0 && _global$FEATURES2.previewMdx2 ? require.resolve('@storybook/mdx2-csf/loader') : require.resolve('@storybook/mdx1-csf/loader'); // set `sourceLoaderOptions` to `null` to disable for manual configuration
|
|
84
80
|
|
|
85
81
|
const sourceLoader = sourceLoaderOptions ? [{
|
|
86
82
|
test: /\.(stories|story)\.[tj]sx?$/,
|
|
@@ -152,13 +148,11 @@ async function webpack(webpackConfig = {}, options) {
|
|
|
152
148
|
|
|
153
149
|
const storyIndexers = async indexers => {
|
|
154
150
|
const mdxIndexer = async (fileName, opts) => {
|
|
155
|
-
var _global$FEATURES3;
|
|
156
|
-
|
|
157
151
|
let code = (await _fsExtra.default.readFile(fileName, 'utf-8')).toString(); // @ts-expect-error (Converted from ts-ignore)
|
|
158
152
|
|
|
159
153
|
const {
|
|
160
154
|
compile
|
|
161
|
-
} =
|
|
155
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@storybook/mdx2-csf')));
|
|
162
156
|
code = await compile(code, {});
|
|
163
157
|
return (0, _csfTools.loadCsf)(code, Object.assign({}, opts, {
|
|
164
158
|
fileName
|
package/dist/esm/DocsRenderer.js
CHANGED
|
@@ -17,8 +17,9 @@ export class DocsRenderer {
|
|
|
17
17
|
// Use a random key to force the container to re-render each time we call `renderDocs`
|
|
18
18
|
// TODO: do we still need this? It was needed for angular (legacy) inline rendering:
|
|
19
19
|
// https://github.com/storybookjs/storybook/pull/16149
|
|
20
|
+
const components = Object.assign({}, defaultComponents, docsParameter?.components);
|
|
20
21
|
ReactDOM.render( /*#__PURE__*/React.createElement(MDXProvider, {
|
|
21
|
-
components:
|
|
22
|
+
components: components
|
|
22
23
|
}, /*#__PURE__*/React.createElement(Docs, {
|
|
23
24
|
key: Math.random(),
|
|
24
25
|
context: context,
|
package/dist/esm/preset.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import fs from 'fs-extra';
|
|
2
2
|
import remarkSlug from 'remark-slug';
|
|
3
3
|
import remarkExternalLinks from 'remark-external-links';
|
|
4
|
-
import global from 'global';
|
|
5
4
|
import { logger } from '@storybook/node-logger';
|
|
6
5
|
import { loadCsf } from '@storybook/csf-tools'; // for frameworks that are not working with react, we need to configure
|
|
7
6
|
// the jsx to transpile mdx, for now there will be a flag for that
|
|
@@ -57,9 +56,10 @@ export async function webpack(webpackConfig = {}, options) {
|
|
|
57
56
|
skipCsf: true,
|
|
58
57
|
remarkPlugins: [remarkSlug, remarkExternalLinks]
|
|
59
58
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const mdxLoader =
|
|
59
|
+
logger.info(`Addon-docs: using MDX2`);
|
|
60
|
+
|
|
61
|
+
const mdxLoader = require.resolve('@storybook/mdx2-csf/loader'); // set `sourceLoaderOptions` to `null` to disable for manual configuration
|
|
62
|
+
|
|
63
63
|
|
|
64
64
|
const sourceLoader = sourceLoaderOptions ? [{
|
|
65
65
|
test: /\.(stories|story)\.[tj]sx?$/,
|
|
@@ -130,7 +130,7 @@ export const storyIndexers = async indexers => {
|
|
|
130
130
|
|
|
131
131
|
const {
|
|
132
132
|
compile
|
|
133
|
-
} =
|
|
133
|
+
} = await import('@storybook/mdx2-csf');
|
|
134
134
|
code = await compile(code, {});
|
|
135
135
|
return loadCsf(code, Object.assign({}, opts, {
|
|
136
136
|
fileName
|
package/jest-transform-mdx.js
CHANGED
|
@@ -2,15 +2,16 @@ const path = require('path');
|
|
|
2
2
|
const { ScriptTransformer } = require('@jest/transform');
|
|
3
3
|
const { dedent } = require('ts-dedent');
|
|
4
4
|
|
|
5
|
-
const {
|
|
5
|
+
const { compileAsync } = require('@storybook/mdx2-csf');
|
|
6
6
|
|
|
7
7
|
module.exports = {
|
|
8
|
-
|
|
8
|
+
async processAsync(src, filename, config, { instrument }) {
|
|
9
|
+
const code = await compileAsync(src, { skipCsf: false });
|
|
9
10
|
const result = dedent`
|
|
10
11
|
/* @jsx mdx */
|
|
11
12
|
import React from 'react'
|
|
12
13
|
import { mdx } from '@mdx-js/react'
|
|
13
|
-
${
|
|
14
|
+
${code}
|
|
14
15
|
`;
|
|
15
16
|
|
|
16
17
|
const extension = path.extname(filename);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/addon-docs",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.40",
|
|
4
4
|
"description": "Document component usage and properties in Markdown",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"addon",
|
|
@@ -51,23 +51,23 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@babel/plugin-transform-react-jsx": "^7.12.12",
|
|
53
53
|
"@jest/transform": "^26.6.2",
|
|
54
|
-
"@mdx-js/react": "^1.
|
|
55
|
-
"@storybook/addons": "7.0.0-alpha.
|
|
56
|
-
"@storybook/api": "7.0.0-alpha.
|
|
57
|
-
"@storybook/blocks": "7.0.0-alpha.
|
|
58
|
-
"@storybook/components": "7.0.0-alpha.
|
|
59
|
-
"@storybook/core-common": "7.0.0-alpha.
|
|
60
|
-
"@storybook/core-events": "7.0.0-alpha.
|
|
54
|
+
"@mdx-js/react": "^2.1.5",
|
|
55
|
+
"@storybook/addons": "7.0.0-alpha.40",
|
|
56
|
+
"@storybook/api": "7.0.0-alpha.40",
|
|
57
|
+
"@storybook/blocks": "7.0.0-alpha.40",
|
|
58
|
+
"@storybook/components": "7.0.0-alpha.40",
|
|
59
|
+
"@storybook/core-common": "7.0.0-alpha.40",
|
|
60
|
+
"@storybook/core-events": "7.0.0-alpha.40",
|
|
61
61
|
"@storybook/csf": "0.0.2--canary.49.258942b.0",
|
|
62
|
-
"@storybook/csf-tools": "7.0.0-alpha.
|
|
63
|
-
"@storybook/docs-tools": "7.0.0-alpha.
|
|
64
|
-
"@storybook/
|
|
65
|
-
"@storybook/node-logger": "7.0.0-alpha.
|
|
66
|
-
"@storybook/postinstall": "7.0.0-alpha.
|
|
67
|
-
"@storybook/preview-web": "7.0.0-alpha.
|
|
68
|
-
"@storybook/source-loader": "7.0.0-alpha.
|
|
69
|
-
"@storybook/store": "7.0.0-alpha.
|
|
70
|
-
"@storybook/theming": "7.0.0-alpha.
|
|
62
|
+
"@storybook/csf-tools": "7.0.0-alpha.40",
|
|
63
|
+
"@storybook/docs-tools": "7.0.0-alpha.40",
|
|
64
|
+
"@storybook/mdx2-csf": "0.1.0-next.0",
|
|
65
|
+
"@storybook/node-logger": "7.0.0-alpha.40",
|
|
66
|
+
"@storybook/postinstall": "7.0.0-alpha.40",
|
|
67
|
+
"@storybook/preview-web": "7.0.0-alpha.40",
|
|
68
|
+
"@storybook/source-loader": "7.0.0-alpha.40",
|
|
69
|
+
"@storybook/store": "7.0.0-alpha.40",
|
|
70
|
+
"@storybook/theming": "7.0.0-alpha.40",
|
|
71
71
|
"dequal": "^2.0.2",
|
|
72
72
|
"fs-extra": "^9.0.1",
|
|
73
73
|
"global": "^4.4.0",
|
|
@@ -77,18 +77,13 @@
|
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"@babel/core": "^7.12.10",
|
|
80
|
-
"@storybook/mdx2-csf": "0.0.4-canary.14.04ffbe8.0",
|
|
81
80
|
"typescript": "~4.6.3"
|
|
82
81
|
},
|
|
83
82
|
"peerDependencies": {
|
|
84
|
-
"@storybook/mdx2-csf": "0.0.4-canary.14.04ffbe8.0",
|
|
85
83
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
86
84
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
87
85
|
},
|
|
88
86
|
"peerDependenciesMeta": {
|
|
89
|
-
"@storybook/mdx2-csf": {
|
|
90
|
-
"optional": true
|
|
91
|
-
},
|
|
92
87
|
"react": {
|
|
93
88
|
"optional": true
|
|
94
89
|
},
|
|
@@ -99,7 +94,7 @@
|
|
|
99
94
|
"publishConfig": {
|
|
100
95
|
"access": "public"
|
|
101
96
|
},
|
|
102
|
-
"gitHead": "
|
|
97
|
+
"gitHead": "8f6d8629f1ad7e776c39e2c7621f4a0d538aa93c",
|
|
103
98
|
"storybook": {
|
|
104
99
|
"displayName": "Docs",
|
|
105
100
|
"icon": "https://user-images.githubusercontent.com/263385/101991672-48355c80-3c7c-11eb-82d9-95fa12438f64.png",
|