@storybook/addon-docs 7.0.0-alpha.1 → 7.0.0-alpha.2
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/blocks/Anchor.js +7 -10
- package/dist/cjs/blocks/ArgsTable.js +134 -205
- package/dist/cjs/blocks/Canvas.js +38 -73
- package/dist/cjs/blocks/Description.js +41 -68
- package/dist/cjs/blocks/DocsContainer.js +40 -68
- package/dist/cjs/blocks/DocsContext.js +1 -1
- package/dist/cjs/blocks/DocsPage.js +3 -5
- package/dist/cjs/blocks/DocsStory.js +18 -28
- package/dist/cjs/blocks/Heading.js +5 -9
- package/dist/cjs/blocks/Meta.js +11 -33
- package/dist/cjs/blocks/Preview.js +4 -10
- package/dist/cjs/blocks/Primary.js +11 -39
- package/dist/cjs/blocks/Props.js +4 -10
- package/dist/cjs/blocks/Source.js +62 -80
- package/dist/cjs/blocks/SourceContainer.js +19 -68
- package/dist/cjs/blocks/Stories.js +16 -47
- package/dist/cjs/blocks/Story.js +60 -180
- package/dist/cjs/blocks/Subheading.js +5 -9
- package/dist/cjs/blocks/Subtitle.js +15 -35
- package/dist/cjs/blocks/Title.js +12 -36
- package/dist/cjs/blocks/Wrapper.js +7 -8
- package/dist/cjs/blocks/enhanceSource.js +30 -67
- package/dist/cjs/blocks/index.js +28 -34
- package/dist/cjs/blocks/mdx.js +85 -96
- package/dist/cjs/blocks/types.js +2 -2
- package/dist/cjs/blocks/useStory.js +16 -101
- package/dist/cjs/blocks/utils.js +4 -25
- package/dist/cjs/index.js +1 -7
- package/dist/cjs/manager.js +9 -15
- package/dist/cjs/preset.js +120 -288
- package/dist/cjs/preview.js +5 -103
- package/dist/cjs/shared.js +5 -5
- package/dist/esm/blocks/Story.js +21 -73
- package/dist/types/blocks/Story.d.ts +2 -2
- package/package.json +15 -14
package/dist/cjs/shared.js
CHANGED
|
@@ -4,15 +4,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.SourceType = exports.SNIPPET_RENDERED = exports.PARAM_KEY = exports.PANEL_ID = exports.ADDON_ID = void 0;
|
|
7
|
-
|
|
7
|
+
const ADDON_ID = 'storybook/docs';
|
|
8
8
|
exports.ADDON_ID = ADDON_ID;
|
|
9
|
-
|
|
9
|
+
const PANEL_ID = `${ADDON_ID}/panel`;
|
|
10
10
|
exports.PANEL_ID = PANEL_ID;
|
|
11
|
-
|
|
11
|
+
const PARAM_KEY = `docs`;
|
|
12
12
|
exports.PARAM_KEY = PARAM_KEY;
|
|
13
|
-
|
|
13
|
+
const SNIPPET_RENDERED = `${ADDON_ID}/snippet-rendered`;
|
|
14
14
|
exports.SNIPPET_RENDERED = SNIPPET_RENDERED;
|
|
15
|
-
|
|
15
|
+
let SourceType;
|
|
16
16
|
exports.SourceType = SourceType;
|
|
17
17
|
|
|
18
18
|
(function (SourceType) {
|
package/dist/esm/blocks/Story.js
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import React, { useContext, useRef, useEffect, useState } from 'react';
|
|
2
2
|
import { MDXProvider } from '@mdx-js/react';
|
|
3
|
-
import global from 'global';
|
|
4
3
|
import { resetComponents, Story as PureStory, StorySkeleton } from '@storybook/components';
|
|
5
4
|
import { toId, storyNameFromExport } from '@storybook/csf';
|
|
6
|
-
import { addons } from '@storybook/addons';
|
|
7
|
-
import Events from '@storybook/core-events';
|
|
8
5
|
import { CURRENT_SELECTION } from './types';
|
|
9
6
|
import { DocsContext } from './DocsContext';
|
|
10
7
|
import { useStory } from './useStory';
|
|
@@ -26,7 +23,7 @@ export const getStoryId = (props, context) => {
|
|
|
26
23
|
export const getStoryProps = ({
|
|
27
24
|
height,
|
|
28
25
|
inline
|
|
29
|
-
}, story
|
|
26
|
+
}, story) => {
|
|
30
27
|
const {
|
|
31
28
|
name: storyName,
|
|
32
29
|
parameters
|
|
@@ -42,51 +39,21 @@ export const getStoryProps = ({
|
|
|
42
39
|
|
|
43
40
|
const {
|
|
44
41
|
inlineStories = false,
|
|
45
|
-
iframeHeight = 100
|
|
46
|
-
prepareForInline
|
|
42
|
+
iframeHeight = 100
|
|
47
43
|
} = docs;
|
|
48
44
|
const storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
|
|
49
|
-
|
|
50
|
-
if (storyIsInline && !prepareForInline) {
|
|
51
|
-
throw new Error(`Story '${storyName}' is set to render inline, but no 'prepareForInline' function is implemented in your docs configuration!`);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const boundStoryFn = () => {
|
|
55
|
-
const storyResult = story.unboundStoryFn(Object.assign({}, context.getStoryContext(story), {
|
|
56
|
-
loaded: {},
|
|
57
|
-
abortSignal: undefined,
|
|
58
|
-
canvasElement: undefined
|
|
59
|
-
})); // We need to wait until the bound story function has actually been called before we
|
|
60
|
-
// consider the story rendered. Certain frameworks (i.e. angular) don't actually render
|
|
61
|
-
// the component in the very first react render cycle, and so we can't just wait until the
|
|
62
|
-
// `PureStory` component has been rendered to consider the underlying story "rendered".
|
|
63
|
-
|
|
64
|
-
onStoryFnCalled();
|
|
65
|
-
return storyResult;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
45
|
return Object.assign({
|
|
69
46
|
inline: storyIsInline,
|
|
70
47
|
id: story.id,
|
|
71
48
|
height: height || (storyIsInline ? undefined : iframeHeight),
|
|
72
49
|
title: storyName
|
|
73
50
|
}, storyIsInline && {
|
|
74
|
-
parameters
|
|
75
|
-
storyFn: () => prepareForInline(boundStoryFn, context.getStoryContext(story))
|
|
51
|
+
parameters
|
|
76
52
|
});
|
|
77
53
|
};
|
|
78
54
|
|
|
79
|
-
function makeGate() {
|
|
80
|
-
let open;
|
|
81
|
-
const gate = new Promise(r => {
|
|
82
|
-
open = r;
|
|
83
|
-
});
|
|
84
|
-
return [gate, open];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
55
|
const Story = props => {
|
|
88
56
|
const context = useContext(DocsContext);
|
|
89
|
-
const channel = addons.getChannel();
|
|
90
57
|
const storyRef = useRef();
|
|
91
58
|
const storyId = getStoryId(props, context);
|
|
92
59
|
const story = useStory(storyId, context);
|
|
@@ -102,54 +69,35 @@ const Story = props => {
|
|
|
102
69
|
|
|
103
70
|
return () => cleanup && cleanup();
|
|
104
71
|
}, [story]);
|
|
105
|
-
const [storyFnRan, onStoryFnRan] = makeGate();
|
|
106
|
-
const [rendered, onRendered] = makeGate();
|
|
107
|
-
useEffect(onRendered);
|
|
108
72
|
|
|
109
73
|
if (!story) {
|
|
110
74
|
return /*#__PURE__*/React.createElement(StorySkeleton, null);
|
|
111
75
|
}
|
|
112
76
|
|
|
113
|
-
const storyProps = getStoryProps(props, story
|
|
77
|
+
const storyProps = getStoryProps(props, story);
|
|
114
78
|
|
|
115
79
|
if (!storyProps) {
|
|
116
80
|
return null;
|
|
117
81
|
}
|
|
118
82
|
|
|
119
83
|
if (storyProps.inline) {
|
|
120
|
-
//
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
const {
|
|
139
|
-
height
|
|
140
|
-
} = storyProps;
|
|
141
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
142
|
-
id: storyBlockIdFromId(story.id)
|
|
143
|
-
}, /*#__PURE__*/React.createElement(MDXProvider, {
|
|
144
|
-
components: resetComponents
|
|
145
|
-
}, height ? /*#__PURE__*/React.createElement("style", null, `#story--${story.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`) : null, showLoader && /*#__PURE__*/React.createElement(StorySkeleton, null), /*#__PURE__*/React.createElement("div", {
|
|
146
|
-
ref: storyRef,
|
|
147
|
-
"data-name": story.name,
|
|
148
|
-
dangerouslySetInnerHTML: {
|
|
149
|
-
__html: htmlContents
|
|
150
|
-
}
|
|
151
|
-
})));
|
|
152
|
-
}
|
|
84
|
+
// We do this so React doesn't complain when we replace the span in a secondary render
|
|
85
|
+
const htmlContents = `<span></span>`; // FIXME: height/style/etc. lifted from PureStory
|
|
86
|
+
|
|
87
|
+
const {
|
|
88
|
+
height
|
|
89
|
+
} = storyProps;
|
|
90
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
91
|
+
id: storyBlockIdFromId(story.id)
|
|
92
|
+
}, /*#__PURE__*/React.createElement(MDXProvider, {
|
|
93
|
+
components: resetComponents
|
|
94
|
+
}, height ? /*#__PURE__*/React.createElement("style", null, `#story--${story.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`) : null, showLoader && /*#__PURE__*/React.createElement(StorySkeleton, null), /*#__PURE__*/React.createElement("div", {
|
|
95
|
+
ref: storyRef,
|
|
96
|
+
"data-name": story.name,
|
|
97
|
+
dangerouslySetInnerHTML: {
|
|
98
|
+
__html: htmlContents
|
|
99
|
+
}
|
|
100
|
+
})));
|
|
153
101
|
}
|
|
154
102
|
|
|
155
103
|
return /*#__PURE__*/React.createElement("div", {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FunctionComponent, ReactNode, ElementType, ComponentProps } from 'react';
|
|
2
2
|
import { Story as PureStory } from '@storybook/components';
|
|
3
3
|
import { StoryId, StoryAnnotations, AnyFramework } from '@storybook/csf';
|
|
4
|
-
import { Story as StoryType } from '@storybook/store';
|
|
4
|
+
import type { Story as StoryType } from '@storybook/store';
|
|
5
5
|
import { DocsContextProps } from './DocsContext';
|
|
6
6
|
export declare const storyBlockIdFromId: (storyId: string) => string;
|
|
7
7
|
declare type PureStoryProps = ComponentProps<typeof PureStory>;
|
|
@@ -23,6 +23,6 @@ declare type StoryImportProps = {
|
|
|
23
23
|
export declare type StoryProps = (StoryDefProps | StoryRefProps | StoryImportProps) & CommonProps;
|
|
24
24
|
export declare const lookupStoryId: (storyName: string, { mdxStoryNameToKey, mdxComponentAnnotations }: DocsContextProps) => string;
|
|
25
25
|
export declare const getStoryId: (props: StoryProps, context: DocsContextProps) => StoryId;
|
|
26
|
-
export declare const getStoryProps: <TFramework extends AnyFramework>({ height, inline }: StoryProps, story: StoryType<TFramework
|
|
26
|
+
export declare const getStoryProps: <TFramework extends AnyFramework>({ height, inline }: StoryProps, story: StoryType<TFramework>) => PureStoryProps;
|
|
27
27
|
declare const Story: FunctionComponent<StoryProps>;
|
|
28
28
|
export { Story };
|
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.2",
|
|
4
4
|
"description": "Document component usage and properties in Markdown",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"addon",
|
|
@@ -52,20 +52,21 @@
|
|
|
52
52
|
"@babel/preset-env": "^7.12.11",
|
|
53
53
|
"@jest/transform": "^26.6.2",
|
|
54
54
|
"@mdx-js/react": "^1.6.22",
|
|
55
|
-
"@storybook/addons": "7.0.0-alpha.
|
|
56
|
-
"@storybook/api": "7.0.0-alpha.
|
|
57
|
-
"@storybook/components": "7.0.0-alpha.
|
|
58
|
-
"@storybook/core-common": "7.0.0-alpha.
|
|
59
|
-
"@storybook/core-events": "7.0.0-alpha.
|
|
55
|
+
"@storybook/addons": "7.0.0-alpha.2",
|
|
56
|
+
"@storybook/api": "7.0.0-alpha.2",
|
|
57
|
+
"@storybook/components": "7.0.0-alpha.2",
|
|
58
|
+
"@storybook/core-common": "7.0.0-alpha.2",
|
|
59
|
+
"@storybook/core-events": "7.0.0-alpha.2",
|
|
60
60
|
"@storybook/csf": "0.0.2--canary.4566f4d.1",
|
|
61
|
-
"@storybook/
|
|
61
|
+
"@storybook/csf-tools": "7.0.0-alpha.2",
|
|
62
|
+
"@storybook/docs-tools": "7.0.0-alpha.2",
|
|
62
63
|
"@storybook/mdx1-csf": "^0.0.1",
|
|
63
|
-
"@storybook/node-logger": "7.0.0-alpha.
|
|
64
|
-
"@storybook/postinstall": "7.0.0-alpha.
|
|
65
|
-
"@storybook/preview-web": "7.0.0-alpha.
|
|
66
|
-
"@storybook/source-loader": "7.0.0-alpha.
|
|
67
|
-
"@storybook/store": "7.0.0-alpha.
|
|
68
|
-
"@storybook/theming": "7.0.0-alpha.
|
|
64
|
+
"@storybook/node-logger": "7.0.0-alpha.2",
|
|
65
|
+
"@storybook/postinstall": "7.0.0-alpha.2",
|
|
66
|
+
"@storybook/preview-web": "7.0.0-alpha.2",
|
|
67
|
+
"@storybook/source-loader": "7.0.0-alpha.2",
|
|
68
|
+
"@storybook/store": "7.0.0-alpha.2",
|
|
69
|
+
"@storybook/theming": "7.0.0-alpha.2",
|
|
69
70
|
"babel-loader": "^8.2.5",
|
|
70
71
|
"core-js": "^3.8.2",
|
|
71
72
|
"fast-deep-equal": "^3.1.3",
|
|
@@ -101,7 +102,7 @@
|
|
|
101
102
|
"publishConfig": {
|
|
102
103
|
"access": "public"
|
|
103
104
|
},
|
|
104
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "44920e2b6bd51981bac5124743c29fb9f5517e44",
|
|
105
106
|
"storybook": {
|
|
106
107
|
"displayName": "Docs",
|
|
107
108
|
"icon": "https://user-images.githubusercontent.com/263385/101991672-48355c80-3c7c-11eb-82d9-95fa12438f64.png",
|