@storybook/addon-docs 7.0.0-alpha.1 → 7.0.0-alpha.10
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/index.js +5 -359
- package/dist/cjs/index.js +1 -7
- package/dist/cjs/manager.js +9 -15
- package/dist/cjs/preset.js +114 -290
- package/dist/cjs/preview.js +9 -103
- package/dist/cjs/shared.js +5 -5
- package/dist/esm/blocks/index.js +1 -24
- package/dist/esm/preview.js +6 -2
- package/dist/types/blocks/index.d.ts +1 -24
- package/dist/types/preview.d.ts +1 -6
- package/package.json +16 -15
- package/dist/cjs/blocks/Anchor.js +0 -26
- package/dist/cjs/blocks/ArgsTable.js +0 -400
- package/dist/cjs/blocks/Canvas.js +0 -144
- package/dist/cjs/blocks/Description.js +0 -153
- package/dist/cjs/blocks/DocsContainer.js +0 -155
- package/dist/cjs/blocks/DocsContext.js +0 -25
- package/dist/cjs/blocks/DocsPage.js +0 -32
- package/dist/cjs/blocks/DocsStory.js +0 -78
- package/dist/cjs/blocks/Heading.js +0 -35
- package/dist/cjs/blocks/Meta.js +0 -72
- package/dist/cjs/blocks/Preview.js +0 -29
- package/dist/cjs/blocks/Primary.js +0 -67
- package/dist/cjs/blocks/Props.js +0 -35
- package/dist/cjs/blocks/Source.js +0 -197
- package/dist/cjs/blocks/SourceContainer.js +0 -116
- package/dist/cjs/blocks/Stories.js +0 -82
- package/dist/cjs/blocks/Story.js +0 -263
- package/dist/cjs/blocks/Subheading.js +0 -35
- package/dist/cjs/blocks/Subtitle.js +0 -59
- package/dist/cjs/blocks/Title.js +0 -68
- package/dist/cjs/blocks/Wrapper.js +0 -21
- package/dist/cjs/blocks/enhanceSource.js +0 -129
- package/dist/cjs/blocks/mdx.js +0 -245
- package/dist/cjs/blocks/types.js +0 -10
- package/dist/cjs/blocks/useStory.js +0 -122
- package/dist/cjs/blocks/utils.js +0 -61
- 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 -166
- 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/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/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/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
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import deprecate from 'util-deprecate';
|
|
3
|
-
import dedent from 'ts-dedent';
|
|
4
|
-
import { Canvas } from './Canvas';
|
|
5
|
-
export const Preview = deprecate(props => /*#__PURE__*/React.createElement(Canvas, props), dedent`
|
|
6
|
-
Preview doc block has been renamed to Canvas.
|
|
7
|
-
|
|
8
|
-
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#previewprops-renamed
|
|
9
|
-
`);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
-
|
|
3
|
-
import React, { useContext } from 'react';
|
|
4
|
-
import { DocsContext } from './DocsContext';
|
|
5
|
-
import { DocsStory } from './DocsStory';
|
|
6
|
-
export const Primary = ({
|
|
7
|
-
name
|
|
8
|
-
}) => {
|
|
9
|
-
const {
|
|
10
|
-
componentStories: getComponentStories
|
|
11
|
-
} = useContext(DocsContext);
|
|
12
|
-
const componentStories = getComponentStories();
|
|
13
|
-
let story;
|
|
14
|
-
|
|
15
|
-
if (componentStories) {
|
|
16
|
-
story = name ? componentStories.find(s => s.name === name) : componentStories[0];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return story ? /*#__PURE__*/React.createElement(DocsStory, _extends({}, story, {
|
|
20
|
-
expanded: false,
|
|
21
|
-
withToolbar: true
|
|
22
|
-
})) : null;
|
|
23
|
-
};
|
package/dist/esm/blocks/Props.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import deprecate from 'util-deprecate';
|
|
3
|
-
import dedent from 'ts-dedent';
|
|
4
|
-
import { ArgsTable } from './ArgsTable';
|
|
5
|
-
import { CURRENT_SELECTION } from './types';
|
|
6
|
-
export const Props = deprecate(props => /*#__PURE__*/React.createElement(ArgsTable, props), dedent`
|
|
7
|
-
Props doc block has been renamed to ArgsTable.
|
|
8
|
-
|
|
9
|
-
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#previewprops-renamed
|
|
10
|
-
`); // @ts-ignore
|
|
11
|
-
|
|
12
|
-
Props.defaultProps = {
|
|
13
|
-
of: CURRENT_SELECTION
|
|
14
|
-
};
|
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import { Source as PureSource, SourceError } from '@storybook/components';
|
|
3
|
-
import { DocsContext } from './DocsContext';
|
|
4
|
-
import { SourceContext } from './SourceContainer';
|
|
5
|
-
import { CURRENT_SELECTION } from './types';
|
|
6
|
-
import { SourceType } from '../shared';
|
|
7
|
-
import { enhanceSource } from './enhanceSource';
|
|
8
|
-
import { useStories } from './useStory';
|
|
9
|
-
export let SourceState;
|
|
10
|
-
|
|
11
|
-
(function (SourceState) {
|
|
12
|
-
SourceState["OPEN"] = "open";
|
|
13
|
-
SourceState["CLOSED"] = "closed";
|
|
14
|
-
SourceState["NONE"] = "none";
|
|
15
|
-
})(SourceState || (SourceState = {}));
|
|
16
|
-
|
|
17
|
-
const getSourceState = stories => {
|
|
18
|
-
const states = stories.map(story => story.parameters.docs?.source?.state).filter(Boolean);
|
|
19
|
-
if (states.length === 0) return SourceState.CLOSED; // FIXME: handling multiple stories is a pain
|
|
20
|
-
|
|
21
|
-
return states[0];
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const getStorySource = (storyId, sourceContext) => {
|
|
25
|
-
const {
|
|
26
|
-
sources
|
|
27
|
-
} = sourceContext; // source rendering is async so source is unavailable at the start of the render cycle,
|
|
28
|
-
// so we fail gracefully here without warning
|
|
29
|
-
|
|
30
|
-
return sources?.[storyId] || {
|
|
31
|
-
code: '',
|
|
32
|
-
format: false
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const getSnippet = (snippet, story) => {
|
|
37
|
-
if (!story) {
|
|
38
|
-
return snippet;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const {
|
|
42
|
-
parameters
|
|
43
|
-
} = story; // eslint-disable-next-line no-underscore-dangle
|
|
44
|
-
|
|
45
|
-
const isArgsStory = parameters.__isArgsStory;
|
|
46
|
-
const type = parameters.docs?.source?.type || SourceType.AUTO; // if user has hard-coded the snippet, that takes precedence
|
|
47
|
-
|
|
48
|
-
const userCode = parameters.docs?.source?.code;
|
|
49
|
-
|
|
50
|
-
if (userCode !== undefined) {
|
|
51
|
-
return userCode;
|
|
52
|
-
} // if user has explicitly set this as dynamic, use snippet
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (type === SourceType.DYNAMIC) {
|
|
56
|
-
return parameters.docs?.transformSource?.(snippet, story) || snippet;
|
|
57
|
-
} // if this is an args story and there's a snippet
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (type === SourceType.AUTO && snippet && isArgsStory) {
|
|
61
|
-
return parameters.docs?.transformSource?.(snippet, story) || snippet;
|
|
62
|
-
} // otherwise, use the source code logic
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
const enhanced = enhanceSource(story) || parameters;
|
|
66
|
-
return enhanced?.docs?.source?.code || '';
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const getSourceProps = (props, docsContext, sourceContext) => {
|
|
70
|
-
const {
|
|
71
|
-
id: currentId,
|
|
72
|
-
storyById
|
|
73
|
-
} = docsContext;
|
|
74
|
-
const {
|
|
75
|
-
parameters
|
|
76
|
-
} = storyById(currentId);
|
|
77
|
-
const codeProps = props;
|
|
78
|
-
const singleProps = props;
|
|
79
|
-
const multiProps = props;
|
|
80
|
-
let source = codeProps.code; // prefer user-specified code
|
|
81
|
-
|
|
82
|
-
let {
|
|
83
|
-
format
|
|
84
|
-
} = codeProps; // prefer user-specified code
|
|
85
|
-
|
|
86
|
-
const targetIds = multiProps.ids || [singleProps.id || currentId];
|
|
87
|
-
const storyIds = targetIds.map(targetId => targetId === CURRENT_SELECTION ? currentId : targetId);
|
|
88
|
-
const stories = useStories(storyIds, docsContext);
|
|
89
|
-
|
|
90
|
-
if (!stories.every(Boolean)) {
|
|
91
|
-
return {
|
|
92
|
-
error: SourceError.SOURCE_UNAVAILABLE,
|
|
93
|
-
state: SourceState.NONE
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
if (!source) {
|
|
98
|
-
// just take the format from the first story, given how they're all concatinated together...
|
|
99
|
-
// TODO: we should consider sending an event with all the sources separately, instead of concatenating them here
|
|
100
|
-
({
|
|
101
|
-
format
|
|
102
|
-
} = getStorySource(storyIds[0], sourceContext));
|
|
103
|
-
source = storyIds.map((storyId, idx) => {
|
|
104
|
-
const {
|
|
105
|
-
code: storySource
|
|
106
|
-
} = getStorySource(storyId, sourceContext);
|
|
107
|
-
const storyObj = stories[idx];
|
|
108
|
-
return getSnippet(storySource, storyObj);
|
|
109
|
-
}).join('\n\n');
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const state = getSourceState(stories);
|
|
113
|
-
const {
|
|
114
|
-
docs: docsParameters = {}
|
|
115
|
-
} = parameters;
|
|
116
|
-
const {
|
|
117
|
-
source: sourceParameters = {}
|
|
118
|
-
} = docsParameters;
|
|
119
|
-
const {
|
|
120
|
-
language: docsLanguage = null
|
|
121
|
-
} = sourceParameters;
|
|
122
|
-
return source ? {
|
|
123
|
-
code: source,
|
|
124
|
-
state,
|
|
125
|
-
format,
|
|
126
|
-
language: props.language || docsLanguage || 'jsx',
|
|
127
|
-
dark: props.dark || false
|
|
128
|
-
} : {
|
|
129
|
-
error: SourceError.SOURCE_UNAVAILABLE,
|
|
130
|
-
state
|
|
131
|
-
};
|
|
132
|
-
};
|
|
133
|
-
/**
|
|
134
|
-
* Story source doc block renders source code if provided,
|
|
135
|
-
* or the source for a story if `storyId` is provided, or
|
|
136
|
-
* the source for the current story if nothing is provided.
|
|
137
|
-
*/
|
|
138
|
-
|
|
139
|
-
export const Source = props => {
|
|
140
|
-
const sourceContext = useContext(SourceContext);
|
|
141
|
-
const docsContext = useContext(DocsContext);
|
|
142
|
-
const sourceProps = getSourceProps(props, docsContext, sourceContext);
|
|
143
|
-
return /*#__PURE__*/React.createElement(PureSource, sourceProps);
|
|
144
|
-
};
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useEffect, useState } from 'react';
|
|
2
|
-
import deepEqual from 'fast-deep-equal';
|
|
3
|
-
import { addons } from '@storybook/addons';
|
|
4
|
-
import { SNIPPET_RENDERED } from '../shared';
|
|
5
|
-
export const SourceContext = /*#__PURE__*/createContext({
|
|
6
|
-
sources: {}
|
|
7
|
-
});
|
|
8
|
-
export const SourceContainer = ({
|
|
9
|
-
children
|
|
10
|
-
}) => {
|
|
11
|
-
const [sources, setSources] = useState({});
|
|
12
|
-
const channel = addons.getChannel();
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
const handleSnippetRendered = (id, newSource, format = false) => {
|
|
15
|
-
// optimization: if the source is the same, ignore the incoming event
|
|
16
|
-
if (sources[id] && sources[id].code === newSource) {
|
|
17
|
-
return;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
setSources(current => {
|
|
21
|
-
const newSources = Object.assign({}, current, {
|
|
22
|
-
[id]: {
|
|
23
|
-
code: newSource,
|
|
24
|
-
format
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
if (!deepEqual(current, newSources)) {
|
|
29
|
-
return newSources;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return current;
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
channel.on(SNIPPET_RENDERED, handleSnippetRendered);
|
|
37
|
-
return () => channel.off(SNIPPET_RENDERED, handleSnippetRendered);
|
|
38
|
-
}, []);
|
|
39
|
-
return /*#__PURE__*/React.createElement(SourceContext.Provider, {
|
|
40
|
-
value: {
|
|
41
|
-
sources
|
|
42
|
-
}
|
|
43
|
-
}, children);
|
|
44
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
-
|
|
3
|
-
import React, { useContext } from 'react';
|
|
4
|
-
import { DocsContext } from './DocsContext';
|
|
5
|
-
import { DocsStory } from './DocsStory';
|
|
6
|
-
import { Heading } from './Heading';
|
|
7
|
-
export const Stories = ({
|
|
8
|
-
title,
|
|
9
|
-
includePrimary = false
|
|
10
|
-
}) => {
|
|
11
|
-
const {
|
|
12
|
-
componentStories
|
|
13
|
-
} = useContext(DocsContext);
|
|
14
|
-
let stories = componentStories();
|
|
15
|
-
stories = stories.filter(story => !story.parameters?.docs?.disable);
|
|
16
|
-
if (!includePrimary) stories = stories.slice(1);
|
|
17
|
-
|
|
18
|
-
if (!stories || stories.length === 0) {
|
|
19
|
-
return null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Heading, null, title), stories.map(story => story && /*#__PURE__*/React.createElement(DocsStory, _extends({
|
|
23
|
-
key: story.id
|
|
24
|
-
}, story, {
|
|
25
|
-
expanded: true
|
|
26
|
-
}))));
|
|
27
|
-
};
|
|
28
|
-
Stories.defaultProps = {
|
|
29
|
-
title: 'Stories'
|
|
30
|
-
};
|
package/dist/esm/blocks/Story.js
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
import React, { useContext, useRef, useEffect, useState } from 'react';
|
|
2
|
-
import { MDXProvider } from '@mdx-js/react';
|
|
3
|
-
import global from 'global';
|
|
4
|
-
import { resetComponents, Story as PureStory, StorySkeleton } from '@storybook/components';
|
|
5
|
-
import { toId, storyNameFromExport } from '@storybook/csf';
|
|
6
|
-
import { addons } from '@storybook/addons';
|
|
7
|
-
import Events from '@storybook/core-events';
|
|
8
|
-
import { CURRENT_SELECTION } from './types';
|
|
9
|
-
import { DocsContext } from './DocsContext';
|
|
10
|
-
import { useStory } from './useStory';
|
|
11
|
-
export const storyBlockIdFromId = storyId => `story--${storyId}`;
|
|
12
|
-
export const lookupStoryId = (storyName, {
|
|
13
|
-
mdxStoryNameToKey,
|
|
14
|
-
mdxComponentAnnotations
|
|
15
|
-
}) => toId(mdxComponentAnnotations.id || mdxComponentAnnotations.title, storyNameFromExport(mdxStoryNameToKey[storyName]));
|
|
16
|
-
export const getStoryId = (props, context) => {
|
|
17
|
-
const {
|
|
18
|
-
id
|
|
19
|
-
} = props;
|
|
20
|
-
const {
|
|
21
|
-
name
|
|
22
|
-
} = props;
|
|
23
|
-
const inputId = id === CURRENT_SELECTION ? context.id : id;
|
|
24
|
-
return inputId || lookupStoryId(name, context);
|
|
25
|
-
};
|
|
26
|
-
export const getStoryProps = ({
|
|
27
|
-
height,
|
|
28
|
-
inline
|
|
29
|
-
}, story, context, onStoryFnCalled) => {
|
|
30
|
-
const {
|
|
31
|
-
name: storyName,
|
|
32
|
-
parameters
|
|
33
|
-
} = story;
|
|
34
|
-
const {
|
|
35
|
-
docs = {}
|
|
36
|
-
} = parameters;
|
|
37
|
-
|
|
38
|
-
if (docs.disable) {
|
|
39
|
-
return null;
|
|
40
|
-
} // prefer block props, then story parameters defined by the framework-specific settings and optionally overridden by users
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
const {
|
|
44
|
-
inlineStories = false,
|
|
45
|
-
iframeHeight = 100,
|
|
46
|
-
prepareForInline
|
|
47
|
-
} = docs;
|
|
48
|
-
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
|
-
return Object.assign({
|
|
69
|
-
inline: storyIsInline,
|
|
70
|
-
id: story.id,
|
|
71
|
-
height: height || (storyIsInline ? undefined : iframeHeight),
|
|
72
|
-
title: storyName
|
|
73
|
-
}, storyIsInline && {
|
|
74
|
-
parameters,
|
|
75
|
-
storyFn: () => prepareForInline(boundStoryFn, context.getStoryContext(story))
|
|
76
|
-
});
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
function makeGate() {
|
|
80
|
-
let open;
|
|
81
|
-
const gate = new Promise(r => {
|
|
82
|
-
open = r;
|
|
83
|
-
});
|
|
84
|
-
return [gate, open];
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const Story = props => {
|
|
88
|
-
const context = useContext(DocsContext);
|
|
89
|
-
const channel = addons.getChannel();
|
|
90
|
-
const storyRef = useRef();
|
|
91
|
-
const storyId = getStoryId(props, context);
|
|
92
|
-
const story = useStory(storyId, context);
|
|
93
|
-
const [showLoader, setShowLoader] = useState(true);
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
let cleanup;
|
|
96
|
-
|
|
97
|
-
if (story && storyRef.current) {
|
|
98
|
-
const element = storyRef.current;
|
|
99
|
-
cleanup = context.renderStoryToElement(story, element);
|
|
100
|
-
setShowLoader(false);
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return () => cleanup && cleanup();
|
|
104
|
-
}, [story]);
|
|
105
|
-
const [storyFnRan, onStoryFnRan] = makeGate();
|
|
106
|
-
const [rendered, onRendered] = makeGate();
|
|
107
|
-
useEffect(onRendered);
|
|
108
|
-
|
|
109
|
-
if (!story) {
|
|
110
|
-
return /*#__PURE__*/React.createElement(StorySkeleton, null);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
const storyProps = getStoryProps(props, story, context, onStoryFnRan);
|
|
114
|
-
|
|
115
|
-
if (!storyProps) {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
if (storyProps.inline) {
|
|
120
|
-
// If we are rendering a old-style inline Story via `PureStory` below, we want to emit
|
|
121
|
-
// the `STORY_RENDERED` event when it renders. The modern mode below calls out to
|
|
122
|
-
// `Preview.renderStoryToDom()` which itself emits the event.
|
|
123
|
-
if (!global?.FEATURES?.modernInlineRender) {
|
|
124
|
-
// We need to wait for two things before we can consider the story rendered:
|
|
125
|
-
// (a) React's `useEffect` hook needs to fire. This is needed for React stories, as
|
|
126
|
-
// decorators of the form `<A><B/></A>` will not actually execute `B` in the first
|
|
127
|
-
// call to the story function.
|
|
128
|
-
// (b) The story function needs to actually have been called.
|
|
129
|
-
// Certain frameworks (i.e.angular) don't actually render the component in the very first
|
|
130
|
-
// React render cycle, so we need to wait for the framework to actually do that
|
|
131
|
-
Promise.all([storyFnRan, rendered]).then(() => {
|
|
132
|
-
channel.emit(Events.STORY_RENDERED, storyId);
|
|
133
|
-
});
|
|
134
|
-
} else {
|
|
135
|
-
// We do this so React doesn't complain when we replace the span in a secondary render
|
|
136
|
-
const htmlContents = `<span></span>`; // FIXME: height/style/etc. lifted from PureStory
|
|
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
|
-
}
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
156
|
-
id: storyBlockIdFromId(story.id)
|
|
157
|
-
}, /*#__PURE__*/React.createElement(MDXProvider, {
|
|
158
|
-
components: resetComponents
|
|
159
|
-
}, /*#__PURE__*/React.createElement(PureStory, storyProps)));
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
Story.defaultProps = {
|
|
163
|
-
children: null,
|
|
164
|
-
name: null
|
|
165
|
-
};
|
|
166
|
-
export { Story };
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { H3 } from '@storybook/components';
|
|
3
|
-
import { HeaderMdx } from './mdx';
|
|
4
|
-
export const Subheading = ({
|
|
5
|
-
children,
|
|
6
|
-
disableAnchor
|
|
7
|
-
}) => {
|
|
8
|
-
if (disableAnchor || typeof children !== 'string') {
|
|
9
|
-
return /*#__PURE__*/React.createElement(H3, null, children);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const tagID = children.toLowerCase().replace(/[^a-z0-9]/gi, '-');
|
|
13
|
-
return /*#__PURE__*/React.createElement(HeaderMdx, {
|
|
14
|
-
as: "h3",
|
|
15
|
-
id: tagID
|
|
16
|
-
}, children);
|
|
17
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import { Subtitle as PureSubtitle } from '@storybook/components';
|
|
3
|
-
import { DocsContext } from './DocsContext';
|
|
4
|
-
export const Subtitle = ({
|
|
5
|
-
children
|
|
6
|
-
}) => {
|
|
7
|
-
const {
|
|
8
|
-
id,
|
|
9
|
-
storyById
|
|
10
|
-
} = useContext(DocsContext);
|
|
11
|
-
const {
|
|
12
|
-
parameters
|
|
13
|
-
} = storyById(id);
|
|
14
|
-
let text = children;
|
|
15
|
-
|
|
16
|
-
if (!text) {
|
|
17
|
-
text = parameters?.componentSubtitle;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return text ? /*#__PURE__*/React.createElement(PureSubtitle, {
|
|
21
|
-
className: "sbdocs-subtitle"
|
|
22
|
-
}, text) : null;
|
|
23
|
-
};
|
package/dist/esm/blocks/Title.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import { Title as PureTitle } from '@storybook/components';
|
|
3
|
-
import { DocsContext } from './DocsContext';
|
|
4
|
-
const STORY_KIND_PATH_SEPARATOR = /\s*\/\s*/;
|
|
5
|
-
export const extractTitle = ({
|
|
6
|
-
title
|
|
7
|
-
}) => {
|
|
8
|
-
const groups = title.trim().split(STORY_KIND_PATH_SEPARATOR);
|
|
9
|
-
return groups && groups[groups.length - 1] || title;
|
|
10
|
-
};
|
|
11
|
-
export const Title = ({
|
|
12
|
-
children
|
|
13
|
-
}) => {
|
|
14
|
-
const context = useContext(DocsContext);
|
|
15
|
-
let text = children;
|
|
16
|
-
|
|
17
|
-
if (!text) {
|
|
18
|
-
text = extractTitle(context);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
return text ? /*#__PURE__*/React.createElement(PureTitle, {
|
|
22
|
-
className: "sbdocs-title"
|
|
23
|
-
}, text) : null;
|
|
24
|
-
};
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
import { combineParameters } from '@storybook/store'; // ============================================================
|
|
2
|
-
// START @storybook/source-loader/extract-source
|
|
3
|
-
//
|
|
4
|
-
// This code duplicated because tree-shaking isn't working.
|
|
5
|
-
// It's not DRY, but source-loader is on the chopping block for
|
|
6
|
-
// the next version of addon-docs, so it's not the worst sin.
|
|
7
|
-
// ============================================================
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* given a location, extract the text from the full source
|
|
11
|
-
*/
|
|
12
|
-
function extractSource(location, lines) {
|
|
13
|
-
const {
|
|
14
|
-
startBody: start,
|
|
15
|
-
endBody: end
|
|
16
|
-
} = location;
|
|
17
|
-
|
|
18
|
-
if (start.line === end.line && lines[start.line - 1] !== undefined) {
|
|
19
|
-
return lines[start.line - 1].substring(start.col, end.col);
|
|
20
|
-
} // NOTE: storysource locations are 1-based not 0-based!
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
const startLine = lines[start.line - 1];
|
|
24
|
-
const endLine = lines[end.line - 1];
|
|
25
|
-
|
|
26
|
-
if (startLine === undefined || endLine === undefined) {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return [startLine.substring(start.col), ...lines.slice(start.line, end.line - 1), endLine.substring(0, end.col)].join('\n');
|
|
31
|
-
} // ============================================================
|
|
32
|
-
// END @storybook/source-loader/extract-source
|
|
33
|
-
// ============================================================
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* Replaces full story id name like: story-kind--story-name -> story-name
|
|
38
|
-
* @param id
|
|
39
|
-
*/
|
|
40
|
-
const storyIdToSanitizedStoryName = id => id.replace(/^.*?--/, '');
|
|
41
|
-
|
|
42
|
-
const extract = (targetId, {
|
|
43
|
-
source,
|
|
44
|
-
locationsMap
|
|
45
|
-
}) => {
|
|
46
|
-
if (!locationsMap) {
|
|
47
|
-
return source;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const sanitizedStoryName = storyIdToSanitizedStoryName(targetId);
|
|
51
|
-
const location = locationsMap[sanitizedStoryName];
|
|
52
|
-
|
|
53
|
-
if (!location) {
|
|
54
|
-
return source;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
const lines = source.split('\n');
|
|
58
|
-
return extractSource(location, lines);
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
export const enhanceSource = story => {
|
|
62
|
-
const {
|
|
63
|
-
id,
|
|
64
|
-
parameters
|
|
65
|
-
} = story;
|
|
66
|
-
const {
|
|
67
|
-
storySource,
|
|
68
|
-
docs = {}
|
|
69
|
-
} = parameters;
|
|
70
|
-
const {
|
|
71
|
-
transformSource
|
|
72
|
-
} = docs; // no input or user has manually overridden the output
|
|
73
|
-
|
|
74
|
-
if (!storySource?.source || docs.source?.code) {
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const input = extract(id, storySource);
|
|
79
|
-
const code = transformSource ? transformSource(input, story) : input;
|
|
80
|
-
return {
|
|
81
|
-
docs: combineParameters(docs, {
|
|
82
|
-
source: {
|
|
83
|
-
code
|
|
84
|
-
}
|
|
85
|
-
})
|
|
86
|
-
};
|
|
87
|
-
};
|