@storybook/addon-docs 7.0.0-alpha.4 → 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 +12 -75
- package/angular/index.js +1 -1
- package/dist/cjs/DocsRenderer.js +54 -0
- package/dist/cjs/blocks.js +18 -0
- package/dist/cjs/index.js +13 -1
- package/dist/cjs/preset.js +35 -18
- package/dist/cjs/preview.js +6 -2
- package/dist/esm/DocsRenderer.js +35 -0
- package/dist/esm/blocks.js +1 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/preset.js +31 -11
- package/dist/esm/preview.js +6 -2
- package/dist/types/DocsRenderer.d.ts +8 -0
- package/dist/types/blocks.d.ts +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/preset.d.ts +8 -2
- package/dist/types/preview.d.ts +1 -6
- package/jest-transform-mdx.js +4 -3
- package/package.json +25 -32
- package/web-components/README.md +1 -0
- package/LICENSE +0 -21
- package/blocks.d.ts +0 -2
- package/blocks.js +0 -14
- package/dist/cjs/blocks/Anchor.js +0 -23
- package/dist/cjs/blocks/ArgsTable.js +0 -329
- package/dist/cjs/blocks/Canvas.js +0 -109
- package/dist/cjs/blocks/Description.js +0 -126
- package/dist/cjs/blocks/DocsContainer.js +0 -127
- package/dist/cjs/blocks/DocsContext.js +0 -25
- package/dist/cjs/blocks/DocsPage.js +0 -30
- package/dist/cjs/blocks/DocsStory.js +0 -68
- package/dist/cjs/blocks/Heading.js +0 -31
- package/dist/cjs/blocks/Meta.js +0 -50
- package/dist/cjs/blocks/Preview.js +0 -23
- package/dist/cjs/blocks/Primary.js +0 -39
- package/dist/cjs/blocks/Props.js +0 -29
- package/dist/cjs/blocks/Source.js +0 -179
- package/dist/cjs/blocks/SourceContainer.js +0 -67
- package/dist/cjs/blocks/Stories.js +0 -51
- package/dist/cjs/blocks/Story.js +0 -143
- package/dist/cjs/blocks/Subheading.js +0 -31
- package/dist/cjs/blocks/Subtitle.js +0 -39
- package/dist/cjs/blocks/Title.js +0 -44
- package/dist/cjs/blocks/Wrapper.js +0 -20
- package/dist/cjs/blocks/enhanceSource.js +0 -92
- package/dist/cjs/blocks/index.js +0 -366
- package/dist/cjs/blocks/mdx.js +0 -234
- package/dist/cjs/blocks/types.js +0 -10
- package/dist/cjs/blocks/useStory.js +0 -37
- package/dist/cjs/blocks/utils.js +0 -40
- package/dist/cjs/manager.js +0 -20
- package/dist/esm/blocks/Anchor.js +0 -8
- package/dist/esm/blocks/ArgsTable.js +0 -292
- package/dist/esm/blocks/Canvas.js +0 -83
- package/dist/esm/blocks/Description.js +0 -107
- package/dist/esm/blocks/DocsContainer.js +0 -98
- package/dist/esm/blocks/DocsContext.js +0 -16
- package/dist/esm/blocks/DocsPage.js +0 -11
- package/dist/esm/blocks/DocsStory.js +0 -46
- package/dist/esm/blocks/Heading.js +0 -17
- package/dist/esm/blocks/Meta.js +0 -31
- package/dist/esm/blocks/Preview.js +0 -9
- package/dist/esm/blocks/Primary.js +0 -23
- package/dist/esm/blocks/Props.js +0 -14
- package/dist/esm/blocks/Source.js +0 -144
- package/dist/esm/blocks/SourceContainer.js +0 -44
- package/dist/esm/blocks/Stories.js +0 -30
- package/dist/esm/blocks/Story.js +0 -114
- package/dist/esm/blocks/Subheading.js +0 -17
- package/dist/esm/blocks/Subtitle.js +0 -23
- package/dist/esm/blocks/Title.js +0 -24
- package/dist/esm/blocks/Wrapper.js +0 -8
- package/dist/esm/blocks/enhanceSource.js +0 -87
- package/dist/esm/blocks/index.js +0 -24
- package/dist/esm/blocks/mdx.js +0 -203
- package/dist/esm/blocks/types.js +0 -2
- package/dist/esm/blocks/useStory.js +0 -27
- package/dist/esm/blocks/utils.js +0 -29
- package/dist/esm/manager.js +0 -16
- package/dist/types/blocks/Anchor.d.ts +0 -6
- package/dist/types/blocks/ArgsTable.d.ts +0 -33
- package/dist/types/blocks/Canvas.d.ts +0 -9
- package/dist/types/blocks/Description.d.ts +0 -20
- package/dist/types/blocks/DocsContainer.d.ts +0 -7
- package/dist/types/blocks/DocsContext.d.ts +0 -5
- package/dist/types/blocks/DocsPage.d.ts +0 -2
- package/dist/types/blocks/DocsStory.d.ts +0 -3
- package/dist/types/blocks/Heading.d.ts +0 -6
- package/dist/types/blocks/Meta.d.ts +0 -9
- package/dist/types/blocks/Preview.d.ts +0 -3
- package/dist/types/blocks/Primary.d.ts +0 -6
- package/dist/types/blocks/Props.d.ts +0 -3
- package/dist/types/blocks/Source.d.ts +0 -38
- package/dist/types/blocks/SourceContainer.d.ts +0 -14
- package/dist/types/blocks/Stories.d.ts +0 -7
- package/dist/types/blocks/Story.d.ts +0 -28
- package/dist/types/blocks/Subheading.d.ts +0 -3
- package/dist/types/blocks/Subtitle.d.ts +0 -6
- package/dist/types/blocks/Title.d.ts +0 -8
- package/dist/types/blocks/Wrapper.d.ts +0 -2
- package/dist/types/blocks/enhanceSource.d.ts +0 -3
- package/dist/types/blocks/index.d.ts +0 -24
- package/dist/types/blocks/mdx.d.ts +0 -20
- package/dist/types/blocks/types.d.ts +0 -13
- package/dist/types/blocks/useStory.d.ts +0 -5
- package/dist/types/blocks/utils.d.ts +0 -3
- package/dist/types/manager.d.ts +0 -1
- package/manager.js +0 -1
- package/register.js +0 -6
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
|
|
|
@@ -37,7 +36,7 @@ Click on the `Docs` tab to see it:
|
|
|
37
36
|
<img src="https://raw.githubusercontent.com/storybookjs/storybook/main/addons/docs/docs/media/docs-tab.png" width="100%" />
|
|
38
37
|
</center>
|
|
39
38
|
|
|
40
|
-
For more information on how it works, see the [`DocsPage` reference](https://github.com/storybookjs/storybook/
|
|
39
|
+
For more information on how it works, see the [`DocsPage` reference](https://github.com/storybookjs/storybook/blob/next/code/addons/docs/docs/docspage.md).
|
|
41
40
|
|
|
42
41
|
## MDX
|
|
43
42
|
|
|
@@ -73,7 +72,7 @@ And here's how that's rendered in Storybook:
|
|
|
73
72
|
<img src="https://raw.githubusercontent.com/storybookjs/storybook/main/addons/docs/docs/media/mdx-simple.png" width="100%" />
|
|
74
73
|
</center>
|
|
75
74
|
|
|
76
|
-
For more information on `MDX`, see the [`MDX` reference](https://github.com/storybookjs/storybook/
|
|
75
|
+
For more information on `MDX`, see the [`MDX` reference](https://github.com/storybookjs/storybook/blob/next/code/addons/docs/docs/mdx.md).
|
|
77
76
|
|
|
78
77
|
## Framework support
|
|
79
78
|
|
|
@@ -81,10 +80,9 @@ Storybook Docs supports all view layers that Storybook supports except for React
|
|
|
81
80
|
|
|
82
81
|
[Framework Support](https://storybook.js.org/docs/react/api/frameworks-feature-support)
|
|
83
82
|
|
|
84
|
-
|
|
85
83
|
**Note:** `#` = WIP support
|
|
86
84
|
|
|
87
|
-
Want to add enhanced features to your favorite framework? Check out this [dev guide](https://github.com/storybookjs/storybook/tree/next/addons/docs/docs/multiframework.md)
|
|
85
|
+
Want to add enhanced features to your favorite framework? Check out this [dev guide](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/multiframework.md)
|
|
88
86
|
|
|
89
87
|
## Installation
|
|
90
88
|
|
|
@@ -109,7 +107,7 @@ module.exports = {
|
|
|
109
107
|
};
|
|
110
108
|
```
|
|
111
109
|
|
|
112
|
-
If using in conjunction with the [storyshots add-on](https://github.com/storybookjs/storybook/blob/next/addons/storyshots/storyshots-core/README.md), you will need to
|
|
110
|
+
If using in conjunction with the [storyshots add-on](https://github.com/storybookjs/storybook/blob/next/code/addons/storyshots/storyshots-core/README.md), you will need to
|
|
113
111
|
configure Jest to transform MDX stories into something Storyshots can understand:
|
|
114
112
|
|
|
115
113
|
Add the following to your Jest configuration:
|
|
@@ -125,12 +123,12 @@ Add the following to your Jest configuration:
|
|
|
125
123
|
|
|
126
124
|
### Be sure to check framework specific installation needs
|
|
127
125
|
|
|
128
|
-
- [React](https://github.com/storybookjs/storybook/tree/next/addons/docs/react) (covered here)
|
|
129
|
-
- [Vue](https://github.com/storybookjs/storybook/tree/next/addons/docs/vue)
|
|
130
|
-
- [Angular](https://github.com/storybookjs/storybook/tree/next/addons/docs/angular)
|
|
131
|
-
- [Ember](https://github.com/storybookjs/storybook/tree/next/addons/docs/ember)
|
|
132
|
-
- [Web Components](https://github.com/storybookjs/storybook/tree/next/addons/docs/web-components)
|
|
133
|
-
- [Common setup (all other frameworks)](https://github.com/storybookjs/storybook/tree/next/addons/docs/common)
|
|
126
|
+
- [React](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/react) (covered here)
|
|
127
|
+
- [Vue](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/vue)
|
|
128
|
+
- [Angular](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/angular)
|
|
129
|
+
- [Ember](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/ember)
|
|
130
|
+
- [Web Components](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/web-components)
|
|
131
|
+
- [Common setup (all other frameworks)](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/common)
|
|
134
132
|
|
|
135
133
|
## Preset options
|
|
136
134
|
|
|
@@ -167,75 +165,14 @@ import Changelog from '../CHANGELOG.md';
|
|
|
167
165
|
<Changelog />
|
|
168
166
|
```
|
|
169
167
|
|
|
170
|
-
## Manual configuration
|
|
171
|
-
|
|
172
|
-
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):
|
|
173
|
-
|
|
174
|
-
```js
|
|
175
|
-
const createCompiler = require('@storybook/addon-docs/mdx-compiler-plugin');
|
|
176
|
-
|
|
177
|
-
module.exports = {
|
|
178
|
-
// 1. register the docs panel (as opposed to '@storybook/addon-docs' which
|
|
179
|
-
// will configure everything with a preset)
|
|
180
|
-
addons: ['@storybook/addon-docs/register'],
|
|
181
|
-
// 2. manually configure webpack, since you're not using the preset
|
|
182
|
-
webpackFinal: async (config) => {
|
|
183
|
-
config.module.rules.push({
|
|
184
|
-
// 2a. Load `.stories.mdx` / `.story.mdx` files as CSF and generate
|
|
185
|
-
// the docs page from the markdown
|
|
186
|
-
test: /\.(stories|story)\.mdx$/,
|
|
187
|
-
use: [
|
|
188
|
-
{
|
|
189
|
-
// Need to add babel-loader as dependency: `yarn add -D babel-loader`
|
|
190
|
-
loader: require.resolve('babel-loader'),
|
|
191
|
-
// may or may not need this line depending on your app's setup
|
|
192
|
-
options: {
|
|
193
|
-
plugins: ['@babel/plugin-transform-react-jsx'],
|
|
194
|
-
},
|
|
195
|
-
},
|
|
196
|
-
{
|
|
197
|
-
loader: '@mdx-js/loader',
|
|
198
|
-
options: {
|
|
199
|
-
compilers: [createCompiler({})],
|
|
200
|
-
},
|
|
201
|
-
},
|
|
202
|
-
],
|
|
203
|
-
});
|
|
204
|
-
// 2b. Run `source-loader` on story files to show their source code
|
|
205
|
-
// automatically in `DocsPage` or the `Source` doc block.
|
|
206
|
-
config.module.rules.push({
|
|
207
|
-
test: /\.(stories|story)\.[tj]sx?$/,
|
|
208
|
-
loader: require.resolve('@storybook/source-loader'),
|
|
209
|
-
exclude: [/node_modules/],
|
|
210
|
-
enforce: 'pre',
|
|
211
|
-
});
|
|
212
|
-
return config;
|
|
213
|
-
},
|
|
214
|
-
};
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
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:
|
|
218
|
-
|
|
219
|
-
```js
|
|
220
|
-
import { addParameters } from '@storybook/react';
|
|
221
|
-
import { DocsPage, DocsContainer } from '@storybook/addon-docs';
|
|
222
|
-
|
|
223
|
-
addParameters({
|
|
224
|
-
docs: {
|
|
225
|
-
container: DocsContainer,
|
|
226
|
-
page: DocsPage,
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
|
-
```
|
|
230
|
-
|
|
231
168
|
## TypeScript configuration
|
|
232
169
|
|
|
233
|
-
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/addons/docs/docs/props-tables.md).
|
|
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).
|
|
234
171
|
|
|
235
172
|
## More resources
|
|
236
173
|
|
|
237
174
|
Want to learn more? Here are some more articles on Storybook Docs:
|
|
238
175
|
|
|
239
|
-
- References: [DocsPage](https://github.com/storybookjs/storybook/tree/next/addons/docs/docs/docspage.md) / [MDX](https://github.com/storybookjs/storybook/tree/next/addons/docs/docs/mdx.md) / [FAQ](https://github.com/storybookjs/storybook/tree/next/addons/docs/docs/faq.md) / [Recipes](https://github.com/storybookjs/storybook/tree/next/addons/docs/docs/recipes.md) / [Theming](https://github.com/storybookjs/storybook/tree/next/addons/docs/docs/theming.md) / [Props](https://github.com/storybookjs/storybook/tree/next/addons/docs/docs/props-tables.md)
|
|
176
|
+
- References: [DocsPage](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/docspage.md) / [MDX](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/mdx.md) / [FAQ](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/faq.md) / [Recipes](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/recipes.md) / [Theming](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/theming.md) / [Props](https://github.com/storybookjs/storybook/tree/next/code/addons/docs/docs/props-tables.md)
|
|
240
177
|
- Announcements: [Vision](https://medium.com/storybookjs/storybook-docs-sneak-peak-5be78445094a) / [DocsPage](https://medium.com/storybookjs/storybook-docspage-e185bc3622bf) / [MDX](https://medium.com/storybookjs/rich-docs-with-storybook-mdx-61bc145ae7bc) / [Framework support](https://medium.com/storybookjs/storybook-docs-for-new-frameworks-b1f6090ee0ea)
|
|
241
178
|
- Example: [Storybook Design System](https://github.com/storybookjs/design-system)
|
package/angular/index.js
CHANGED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.defaultComponents = exports.DocsRenderer = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
11
|
+
|
|
12
|
+
var _components = require("@storybook/components");
|
|
13
|
+
|
|
14
|
+
var _blocks = require("@storybook/blocks");
|
|
15
|
+
|
|
16
|
+
var _react2 = require("@mdx-js/react");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
// TS doesn't like that we export a component with types that it doesn't know about (TS4203)
|
|
21
|
+
const defaultComponents = Object.assign({}, _components.components, {
|
|
22
|
+
code: _blocks.CodeOrSourceMdx,
|
|
23
|
+
a: _blocks.AnchorMdx
|
|
24
|
+
}, _blocks.HeadersMdx);
|
|
25
|
+
exports.defaultComponents = defaultComponents;
|
|
26
|
+
|
|
27
|
+
class DocsRenderer {
|
|
28
|
+
constructor() {
|
|
29
|
+
this.render = void 0;
|
|
30
|
+
this.unmount = void 0;
|
|
31
|
+
|
|
32
|
+
this.render = (context, docsParameter, element, callback) => {
|
|
33
|
+
// Use a random key to force the container to re-render each time we call `renderDocs`
|
|
34
|
+
// TODO: do we still need this? It was needed for angular (legacy) inline rendering:
|
|
35
|
+
// https://github.com/storybookjs/storybook/pull/16149
|
|
36
|
+
const components = Object.assign({}, defaultComponents, docsParameter === null || docsParameter === void 0 ? void 0 : docsParameter.components);
|
|
37
|
+
|
|
38
|
+
_reactDom.default.render( /*#__PURE__*/_react.default.createElement(_react2.MDXProvider, {
|
|
39
|
+
components: components
|
|
40
|
+
}, /*#__PURE__*/_react.default.createElement(_blocks.Docs, {
|
|
41
|
+
key: Math.random(),
|
|
42
|
+
context: context,
|
|
43
|
+
docsParameter: docsParameter
|
|
44
|
+
})), element, callback);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
this.unmount = element => {
|
|
48
|
+
_reactDom.default.unmountComponentAtNode(element);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
exports.DocsRenderer = DocsRenderer;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
|
|
7
|
+
var _blocks = require("@storybook/blocks");
|
|
8
|
+
|
|
9
|
+
Object.keys(_blocks).forEach(function (key) {
|
|
10
|
+
if (key === "default" || key === "__esModule") return;
|
|
11
|
+
if (key in exports && exports[key] === _blocks[key]) return;
|
|
12
|
+
Object.defineProperty(exports, key, {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _blocks[key];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
package/dist/cjs/index.js
CHANGED
|
@@ -3,11 +3,21 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
var _exportNames = {
|
|
7
|
+
DocsRenderer: true
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "DocsRenderer", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function () {
|
|
12
|
+
return _DocsRenderer.DocsRenderer;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
6
15
|
|
|
7
16
|
var _blocks = require("./blocks");
|
|
8
17
|
|
|
9
18
|
Object.keys(_blocks).forEach(function (key) {
|
|
10
19
|
if (key === "default" || key === "__esModule") return;
|
|
20
|
+
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
11
21
|
if (key in exports && exports[key] === _blocks[key]) return;
|
|
12
22
|
Object.defineProperty(exports, key, {
|
|
13
23
|
enumerable: true,
|
|
@@ -15,4 +25,6 @@ Object.keys(_blocks).forEach(function (key) {
|
|
|
15
25
|
return _blocks[key];
|
|
16
26
|
}
|
|
17
27
|
});
|
|
18
|
-
});
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
var _DocsRenderer = require("./DocsRenderer");
|
package/dist/cjs/preset.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.storyIndexers = void 0;
|
|
6
|
+
exports.storyIndexers = exports.docs = void 0;
|
|
7
7
|
exports.webpack = webpack;
|
|
8
8
|
|
|
9
9
|
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
@@ -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");
|
|
@@ -30,11 +28,20 @@ function createBabelOptions({
|
|
|
30
28
|
configureJSX
|
|
31
29
|
}) {
|
|
32
30
|
const babelPlugins = (mdxBabelOptions === null || mdxBabelOptions === void 0 ? void 0 : mdxBabelOptions.plugins) || (babelOptions === null || babelOptions === void 0 ? void 0 : babelOptions.plugins) || [];
|
|
31
|
+
const filteredBabelPlugins = babelPlugins.filter(p => {
|
|
32
|
+
const name = Array.isArray(p) ? p[0] : p;
|
|
33
|
+
|
|
34
|
+
if (typeof name === 'string') {
|
|
35
|
+
return !name.includes('plugin-transform-react-jsx');
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return true;
|
|
39
|
+
});
|
|
33
40
|
const jsxPlugin = [require.resolve('@babel/plugin-transform-react-jsx'), {
|
|
34
41
|
pragma: 'React.createElement',
|
|
35
42
|
pragmaFrag: 'React.Fragment'
|
|
36
43
|
}];
|
|
37
|
-
const plugins = configureJSX ? [...
|
|
44
|
+
const plugins = configureJSX ? [...filteredBabelPlugins, jsxPlugin] : babelPlugins;
|
|
38
45
|
return Object.assign({
|
|
39
46
|
// don't use the root babelrc by default (users can override this in mdxBabelOptions)
|
|
40
47
|
babelrc: false,
|
|
@@ -45,10 +52,7 @@ function createBabelOptions({
|
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
async function webpack(webpackConfig = {}, options) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const resolvedBabelLoader = require.resolve('babel-loader');
|
|
51
|
-
|
|
55
|
+
const resolvedBabelLoader = await options.presets.apply('babelLoaderRef');
|
|
52
56
|
const {
|
|
53
57
|
module = {}
|
|
54
58
|
} = webpackConfig; // it will reuse babel options that are already in use in storybook
|
|
@@ -64,14 +68,15 @@ async function webpack(webpackConfig = {}, options) {
|
|
|
64
68
|
transcludeMarkdown = false
|
|
65
69
|
} = options;
|
|
66
70
|
const mdxLoaderOptions = {
|
|
71
|
+
// whether to skip storybook files, useful for docs only mdx or md files
|
|
67
72
|
skipCsf: true,
|
|
68
73
|
remarkPlugins: [_remarkSlug.default, _remarkExternalLinks.default]
|
|
69
74
|
};
|
|
70
|
-
const mdxVersion = (_global$FEATURES = _global.default.FEATURES) !== null && _global$FEATURES !== void 0 && _global$FEATURES.previewMdx2 ? 'MDX2' : 'MDX1';
|
|
71
75
|
|
|
72
|
-
_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
|
|
73
79
|
|
|
74
|
-
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
|
|
75
80
|
|
|
76
81
|
const sourceLoader = sourceLoaderOptions ? [{
|
|
77
82
|
test: /\.(stories|story)\.[tj]sx?$/,
|
|
@@ -116,7 +121,10 @@ async function webpack(webpackConfig = {}, options) {
|
|
|
116
121
|
configureJSX
|
|
117
122
|
})
|
|
118
123
|
}, {
|
|
119
|
-
loader: mdxLoader
|
|
124
|
+
loader: mdxLoader,
|
|
125
|
+
options: Object.assign({}, mdxLoaderOptions, {
|
|
126
|
+
skipCsf: false
|
|
127
|
+
})
|
|
120
128
|
}]
|
|
121
129
|
}, {
|
|
122
130
|
test: /\.mdx$/,
|
|
@@ -140,13 +148,11 @@ async function webpack(webpackConfig = {}, options) {
|
|
|
140
148
|
|
|
141
149
|
const storyIndexers = async indexers => {
|
|
142
150
|
const mdxIndexer = async (fileName, opts) => {
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
let code = (await _fsExtra.default.readFile(fileName, 'utf-8')).toString(); // @ts-ignore
|
|
151
|
+
let code = (await _fsExtra.default.readFile(fileName, 'utf-8')).toString(); // @ts-expect-error (Converted from ts-ignore)
|
|
146
152
|
|
|
147
153
|
const {
|
|
148
154
|
compile
|
|
149
|
-
} =
|
|
155
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('@storybook/mdx2-csf')));
|
|
150
156
|
code = await compile(code, {});
|
|
151
157
|
return (0, _csfTools.loadCsf)(code, Object.assign({}, opts, {
|
|
152
158
|
fileName
|
|
@@ -155,8 +161,19 @@ const storyIndexers = async indexers => {
|
|
|
155
161
|
|
|
156
162
|
return [{
|
|
157
163
|
test: /(stories|story)\.mdx$/,
|
|
158
|
-
indexer: mdxIndexer
|
|
164
|
+
indexer: mdxIndexer,
|
|
165
|
+
addDocsTemplate: true
|
|
159
166
|
}, ...(indexers || [])];
|
|
160
167
|
};
|
|
161
168
|
|
|
162
|
-
exports.storyIndexers = storyIndexers;
|
|
169
|
+
exports.storyIndexers = storyIndexers;
|
|
170
|
+
|
|
171
|
+
const docs = docsOptions => {
|
|
172
|
+
return Object.assign({}, docsOptions, {
|
|
173
|
+
enabled: true,
|
|
174
|
+
defaultName: 'Docs',
|
|
175
|
+
docsPage: true
|
|
176
|
+
});
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
exports.docs = docs;
|
package/dist/cjs/preview.js
CHANGED
|
@@ -11,8 +11,12 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
11
11
|
|
|
12
12
|
const parameters = {
|
|
13
13
|
docs: {
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
renderer: async () => {
|
|
15
|
+
const {
|
|
16
|
+
DocsRenderer
|
|
17
|
+
} = await Promise.resolve().then(() => _interopRequireWildcard(require('./DocsRenderer')));
|
|
18
|
+
return new DocsRenderer();
|
|
19
|
+
}
|
|
16
20
|
}
|
|
17
21
|
};
|
|
18
22
|
exports.parameters = parameters;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import ReactDOM from 'react-dom';
|
|
3
|
+
import { components as htmlComponents } from '@storybook/components';
|
|
4
|
+
import { Docs, CodeOrSourceMdx, AnchorMdx, HeadersMdx } from '@storybook/blocks';
|
|
5
|
+
import { MDXProvider } from '@mdx-js/react'; // TS doesn't like that we export a component with types that it doesn't know about (TS4203)
|
|
6
|
+
|
|
7
|
+
export const defaultComponents = Object.assign({}, htmlComponents, {
|
|
8
|
+
code: CodeOrSourceMdx,
|
|
9
|
+
a: AnchorMdx
|
|
10
|
+
}, HeadersMdx);
|
|
11
|
+
export class DocsRenderer {
|
|
12
|
+
constructor() {
|
|
13
|
+
this.render = void 0;
|
|
14
|
+
this.unmount = void 0;
|
|
15
|
+
|
|
16
|
+
this.render = (context, docsParameter, element, callback) => {
|
|
17
|
+
// Use a random key to force the container to re-render each time we call `renderDocs`
|
|
18
|
+
// TODO: do we still need this? It was needed for angular (legacy) inline rendering:
|
|
19
|
+
// https://github.com/storybookjs/storybook/pull/16149
|
|
20
|
+
const components = Object.assign({}, defaultComponents, docsParameter?.components);
|
|
21
|
+
ReactDOM.render( /*#__PURE__*/React.createElement(MDXProvider, {
|
|
22
|
+
components: components
|
|
23
|
+
}, /*#__PURE__*/React.createElement(Docs, {
|
|
24
|
+
key: Math.random(),
|
|
25
|
+
context: context,
|
|
26
|
+
docsParameter: docsParameter
|
|
27
|
+
})), element, callback);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
this.unmount = element => {
|
|
31
|
+
ReactDOM.unmountComponentAtNode(element);
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@storybook/blocks';
|
package/dist/esm/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export * from './blocks';
|
|
1
|
+
export * from './blocks';
|
|
2
|
+
export { DocsRenderer } from './DocsRenderer';
|
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
|
|
@@ -13,11 +12,20 @@ function createBabelOptions({
|
|
|
13
12
|
configureJSX
|
|
14
13
|
}) {
|
|
15
14
|
const babelPlugins = mdxBabelOptions?.plugins || babelOptions?.plugins || [];
|
|
15
|
+
const filteredBabelPlugins = babelPlugins.filter(p => {
|
|
16
|
+
const name = Array.isArray(p) ? p[0] : p;
|
|
17
|
+
|
|
18
|
+
if (typeof name === 'string') {
|
|
19
|
+
return !name.includes('plugin-transform-react-jsx');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return true;
|
|
23
|
+
});
|
|
16
24
|
const jsxPlugin = [require.resolve('@babel/plugin-transform-react-jsx'), {
|
|
17
25
|
pragma: 'React.createElement',
|
|
18
26
|
pragmaFrag: 'React.Fragment'
|
|
19
27
|
}];
|
|
20
|
-
const plugins = configureJSX ? [...
|
|
28
|
+
const plugins = configureJSX ? [...filteredBabelPlugins, jsxPlugin] : babelPlugins;
|
|
21
29
|
return Object.assign({
|
|
22
30
|
// don't use the root babelrc by default (users can override this in mdxBabelOptions)
|
|
23
31
|
babelrc: false,
|
|
@@ -28,8 +36,7 @@ function createBabelOptions({
|
|
|
28
36
|
}
|
|
29
37
|
|
|
30
38
|
export async function webpack(webpackConfig = {}, options) {
|
|
31
|
-
const resolvedBabelLoader =
|
|
32
|
-
|
|
39
|
+
const resolvedBabelLoader = await options.presets.apply('babelLoaderRef');
|
|
33
40
|
const {
|
|
34
41
|
module = {}
|
|
35
42
|
} = webpackConfig; // it will reuse babel options that are already in use in storybook
|
|
@@ -45,12 +52,14 @@ export async function webpack(webpackConfig = {}, options) {
|
|
|
45
52
|
transcludeMarkdown = false
|
|
46
53
|
} = options;
|
|
47
54
|
const mdxLoaderOptions = {
|
|
55
|
+
// whether to skip storybook files, useful for docs only mdx or md files
|
|
48
56
|
skipCsf: true,
|
|
49
57
|
remarkPlugins: [remarkSlug, remarkExternalLinks]
|
|
50
58
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
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
|
+
|
|
54
63
|
|
|
55
64
|
const sourceLoader = sourceLoaderOptions ? [{
|
|
56
65
|
test: /\.(stories|story)\.[tj]sx?$/,
|
|
@@ -91,7 +100,10 @@ export async function webpack(webpackConfig = {}, options) {
|
|
|
91
100
|
configureJSX
|
|
92
101
|
})
|
|
93
102
|
}, {
|
|
94
|
-
loader: mdxLoader
|
|
103
|
+
loader: mdxLoader,
|
|
104
|
+
options: Object.assign({}, mdxLoaderOptions, {
|
|
105
|
+
skipCsf: false
|
|
106
|
+
})
|
|
95
107
|
}]
|
|
96
108
|
}, {
|
|
97
109
|
test: /\.mdx$/,
|
|
@@ -114,11 +126,11 @@ export async function webpack(webpackConfig = {}, options) {
|
|
|
114
126
|
}
|
|
115
127
|
export const storyIndexers = async indexers => {
|
|
116
128
|
const mdxIndexer = async (fileName, opts) => {
|
|
117
|
-
let code = (await fs.readFile(fileName, 'utf-8')).toString(); // @ts-ignore
|
|
129
|
+
let code = (await fs.readFile(fileName, 'utf-8')).toString(); // @ts-expect-error (Converted from ts-ignore)
|
|
118
130
|
|
|
119
131
|
const {
|
|
120
132
|
compile
|
|
121
|
-
} =
|
|
133
|
+
} = await import('@storybook/mdx2-csf');
|
|
122
134
|
code = await compile(code, {});
|
|
123
135
|
return loadCsf(code, Object.assign({}, opts, {
|
|
124
136
|
fileName
|
|
@@ -127,6 +139,14 @@ export const storyIndexers = async indexers => {
|
|
|
127
139
|
|
|
128
140
|
return [{
|
|
129
141
|
test: /(stories|story)\.mdx$/,
|
|
130
|
-
indexer: mdxIndexer
|
|
142
|
+
indexer: mdxIndexer,
|
|
143
|
+
addDocsTemplate: true
|
|
131
144
|
}, ...(indexers || [])];
|
|
145
|
+
};
|
|
146
|
+
export const docs = docsOptions => {
|
|
147
|
+
return Object.assign({}, docsOptions, {
|
|
148
|
+
enabled: true,
|
|
149
|
+
defaultName: 'Docs',
|
|
150
|
+
docsPage: true
|
|
151
|
+
});
|
|
132
152
|
};
|
package/dist/esm/preview.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export const parameters = {
|
|
2
2
|
docs: {
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
renderer: async () => {
|
|
4
|
+
const {
|
|
5
|
+
DocsRenderer
|
|
6
|
+
} = await import('./DocsRenderer');
|
|
7
|
+
return new DocsRenderer();
|
|
8
|
+
}
|
|
5
9
|
}
|
|
6
10
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AnyFramework } from '@storybook/csf';
|
|
2
|
+
import { DocsRenderFunction } from '@storybook/preview-web';
|
|
3
|
+
export declare const defaultComponents: Record<string, any>;
|
|
4
|
+
export declare class DocsRenderer<TFramework extends AnyFramework> {
|
|
5
|
+
render: DocsRenderFunction<TFramework>;
|
|
6
|
+
unmount: (element: HTMLElement) => void;
|
|
7
|
+
constructor();
|
|
8
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from '@storybook/blocks';
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/preset.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Options, StoryIndexer } from '@storybook/core-common';
|
|
1
|
+
import type { DocsOptions, Options, StoryIndexer } from '@storybook/core-common';
|
|
2
2
|
declare type BabelParams = {
|
|
3
3
|
babelOptions?: any;
|
|
4
4
|
mdxBabelOptions?: any;
|
|
@@ -8,5 +8,11 @@ export declare function webpack(webpackConfig: any, options: Options & BabelPara
|
|
|
8
8
|
sourceLoaderOptions: any;
|
|
9
9
|
transcludeMarkdown: boolean;
|
|
10
10
|
}): Promise<any>;
|
|
11
|
-
export declare const storyIndexers: (indexers
|
|
11
|
+
export declare const storyIndexers: (indexers: StoryIndexer[] | null) => Promise<StoryIndexer[]>;
|
|
12
|
+
export declare const docs: (docsOptions: DocsOptions) => {
|
|
13
|
+
enabled: boolean;
|
|
14
|
+
defaultName: string;
|
|
15
|
+
docsPage: boolean;
|
|
16
|
+
docsMode?: boolean;
|
|
17
|
+
};
|
|
12
18
|
export {};
|
package/dist/types/preview.d.ts
CHANGED
|
@@ -1,6 +1 @@
|
|
|
1
|
-
export declare const parameters:
|
|
2
|
-
docs: {
|
|
3
|
-
getContainer: () => Promise<import("react").FunctionComponent<import("./blocks").DocsContainerProps<import("@storybook/csf").AnyFramework>>>;
|
|
4
|
-
getPage: () => Promise<import("react").FC<{}>>;
|
|
5
|
-
};
|
|
6
|
-
};
|
|
1
|
+
export declare const parameters: any;
|
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);
|