@storybook/addon-docs 7.0.0-alpha.6 → 7.0.0-alpha.61
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 +14 -77
- package/angular/index.js +1 -1
- package/dist/DocsRenderer-FLOC7YSC.mjs +1 -0
- package/dist/chunk-HXSBEJGO.mjs +1 -0
- package/dist/chunk-MA2MUXQN.mjs +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/preset.d.ts +5 -0
- package/dist/preset.js +7 -0
- package/dist/preset.mjs +7 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +1 -0
- package/dist/preview.mjs +1 -0
- package/dist/shims/mdx-react-shim.d.ts +1 -0
- package/dist/shims/mdx-react-shim.js +1 -0
- package/dist/shims/mdx-react-shim.mjs +1 -0
- package/jest-transform-mdx.js +4 -3
- package/jest.config.js +7 -0
- package/package.json +80 -46
- package/preset.js +1 -1
- package/preview.js +2 -1
- 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 -119
- package/dist/cjs/blocks/Description.js +0 -126
- package/dist/cjs/blocks/DocsContainer.js +0 -134
- package/dist/cjs/blocks/DocsContext.js +0 -25
- package/dist/cjs/blocks/DocsPage.js +0 -30
- package/dist/cjs/blocks/DocsRenderer.js +0 -50
- package/dist/cjs/blocks/DocsStory.js +0 -68
- package/dist/cjs/blocks/ExternalDocsContainer.js +0 -64
- package/dist/cjs/blocks/ExternalPreview.js +0 -99
- package/dist/cjs/blocks/Heading.js +0 -31
- package/dist/cjs/blocks/Meta.js +0 -64
- 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 -185
- package/dist/cjs/blocks/SourceContainer.js +0 -67
- package/dist/cjs/blocks/Stories.js +0 -51
- package/dist/cjs/blocks/Story.js +0 -152
- 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 -394
- package/dist/cjs/blocks/mdx.js +0 -234
- package/dist/cjs/blocks/types.js +0 -10
- package/dist/cjs/blocks/useStory.js +0 -44
- package/dist/cjs/blocks/utils.js +0 -40
- package/dist/cjs/index.js +0 -18
- package/dist/cjs/manager.js +0 -20
- package/dist/cjs/preset.js +0 -162
- package/dist/cjs/preview.js +0 -22
- package/dist/cjs/shared.js +0 -22
- package/dist/esm/blocks/Anchor.js +0 -8
- package/dist/esm/blocks/ArgsTable.js +0 -292
- package/dist/esm/blocks/Canvas.js +0 -93
- package/dist/esm/blocks/Description.js +0 -107
- package/dist/esm/blocks/DocsContainer.js +0 -105
- package/dist/esm/blocks/DocsContext.js +0 -16
- package/dist/esm/blocks/DocsPage.js +0 -11
- package/dist/esm/blocks/DocsRenderer.js +0 -32
- package/dist/esm/blocks/DocsStory.js +0 -46
- package/dist/esm/blocks/ExternalDocsContainer.js +0 -48
- package/dist/esm/blocks/ExternalPreview.js +0 -89
- package/dist/esm/blocks/Heading.js +0 -17
- package/dist/esm/blocks/Meta.js +0 -45
- 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 -150
- package/dist/esm/blocks/SourceContainer.js +0 -44
- package/dist/esm/blocks/Stories.js +0 -30
- package/dist/esm/blocks/Story.js +0 -123
- 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 -27
- package/dist/esm/blocks/mdx.js +0 -203
- package/dist/esm/blocks/types.js +0 -2
- package/dist/esm/blocks/useStory.js +0 -34
- package/dist/esm/blocks/utils.js +0 -29
- package/dist/esm/index.js +0 -1
- package/dist/esm/manager.js +0 -16
- package/dist/esm/preset.js +0 -132
- package/dist/esm/preview.js +0 -10
- package/dist/esm/shared.js +0 -11
- 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/DocsRenderer.d.ts +0 -7
- package/dist/types/blocks/DocsStory.d.ts +0 -3
- package/dist/types/blocks/ExternalDocsContainer.d.ts +0 -4
- package/dist/types/blocks/ExternalPreview.d.ts +0 -19
- package/dist/types/blocks/Heading.d.ts +0 -6
- package/dist/types/blocks/Meta.d.ts +0 -12
- 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 -30
- 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 -26
- 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/index.d.ts +0 -1
- package/dist/types/manager.d.ts +0 -1
- package/dist/types/preset.d.ts +0 -12
- package/dist/types/preview.d.ts +0 -5
- package/dist/types/shared.d.ts +0 -24
- package/manager.js +0 -1
- package/mdx-compiler-plugin.js +0 -1
- package/register.js +0 -6
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import { Description } from '@storybook/components';
|
|
3
|
-
import { str } from '@storybook/docs-tools';
|
|
4
|
-
import { DocsContext } from './DocsContext';
|
|
5
|
-
import { CURRENT_SELECTION } from './types';
|
|
6
|
-
export let DescriptionType;
|
|
7
|
-
|
|
8
|
-
(function (DescriptionType) {
|
|
9
|
-
DescriptionType["INFO"] = "info";
|
|
10
|
-
DescriptionType["NOTES"] = "notes";
|
|
11
|
-
DescriptionType["DOCGEN"] = "docgen";
|
|
12
|
-
DescriptionType["LEGACY_5_2"] = "legacy-5.2";
|
|
13
|
-
DescriptionType["AUTO"] = "auto";
|
|
14
|
-
})(DescriptionType || (DescriptionType = {}));
|
|
15
|
-
|
|
16
|
-
const getNotes = notes => notes && (typeof notes === 'string' ? notes : str(notes.markdown) || str(notes.text));
|
|
17
|
-
|
|
18
|
-
const getInfo = info => info && (typeof info === 'string' ? info : str(info.text));
|
|
19
|
-
|
|
20
|
-
const noDescription = component => null;
|
|
21
|
-
|
|
22
|
-
export const getDescriptionProps = ({
|
|
23
|
-
of,
|
|
24
|
-
type,
|
|
25
|
-
markdown,
|
|
26
|
-
children
|
|
27
|
-
}, {
|
|
28
|
-
id,
|
|
29
|
-
storyById
|
|
30
|
-
}) => {
|
|
31
|
-
const {
|
|
32
|
-
component,
|
|
33
|
-
parameters
|
|
34
|
-
} = storyById(id);
|
|
35
|
-
|
|
36
|
-
if (children || markdown) {
|
|
37
|
-
return {
|
|
38
|
-
markdown: children || markdown
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const {
|
|
43
|
-
notes,
|
|
44
|
-
info,
|
|
45
|
-
docs
|
|
46
|
-
} = parameters;
|
|
47
|
-
const {
|
|
48
|
-
extractComponentDescription = noDescription,
|
|
49
|
-
description
|
|
50
|
-
} = docs || {};
|
|
51
|
-
const target = of === CURRENT_SELECTION ? component : of; // override component description
|
|
52
|
-
|
|
53
|
-
const componentDescriptionParameter = description?.component;
|
|
54
|
-
|
|
55
|
-
if (componentDescriptionParameter) {
|
|
56
|
-
return {
|
|
57
|
-
markdown: componentDescriptionParameter
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
switch (type) {
|
|
62
|
-
case DescriptionType.INFO:
|
|
63
|
-
return {
|
|
64
|
-
markdown: getInfo(info)
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
case DescriptionType.NOTES:
|
|
68
|
-
return {
|
|
69
|
-
markdown: getNotes(notes)
|
|
70
|
-
};
|
|
71
|
-
// FIXME: remove in 6.0
|
|
72
|
-
|
|
73
|
-
case DescriptionType.LEGACY_5_2:
|
|
74
|
-
return {
|
|
75
|
-
markdown: `
|
|
76
|
-
${getNotes(notes) || getInfo(info) || ''}
|
|
77
|
-
|
|
78
|
-
${extractComponentDescription(target) || ''}
|
|
79
|
-
`.trim()
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
case DescriptionType.DOCGEN:
|
|
83
|
-
case DescriptionType.AUTO:
|
|
84
|
-
default:
|
|
85
|
-
return {
|
|
86
|
-
markdown: extractComponentDescription(target, Object.assign({
|
|
87
|
-
component
|
|
88
|
-
}, parameters))
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const DescriptionContainer = props => {
|
|
94
|
-
const context = useContext(DocsContext);
|
|
95
|
-
const {
|
|
96
|
-
markdown
|
|
97
|
-
} = getDescriptionProps(props, context);
|
|
98
|
-
return markdown ? /*#__PURE__*/React.createElement(Description, {
|
|
99
|
-
markdown: markdown
|
|
100
|
-
}) : null;
|
|
101
|
-
}; // since we are in the docs blocks, assume default description if for primary component story
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
DescriptionContainer.defaultProps = {
|
|
105
|
-
of: '.'
|
|
106
|
-
};
|
|
107
|
-
export { DescriptionContainer as Description };
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import React, { useEffect } from 'react';
|
|
2
|
-
import global from 'global';
|
|
3
|
-
import deprecate from 'util-deprecate';
|
|
4
|
-
import dedent from 'ts-dedent';
|
|
5
|
-
import { MDXProvider } from '@mdx-js/react';
|
|
6
|
-
import { ThemeProvider, ensure as ensureTheme } from '@storybook/theming';
|
|
7
|
-
import { DocsWrapper, DocsContent, components as htmlComponents } from '@storybook/components';
|
|
8
|
-
import { DocsContext } from './DocsContext';
|
|
9
|
-
import { anchorBlockIdFromId } from './Anchor';
|
|
10
|
-
import { storyBlockIdFromId } from './Story';
|
|
11
|
-
import { SourceContainer } from './SourceContainer';
|
|
12
|
-
import { CodeOrSourceMdx, AnchorMdx, HeadersMdx } from './mdx';
|
|
13
|
-
import { scrollToElement } from './utils';
|
|
14
|
-
const {
|
|
15
|
-
document,
|
|
16
|
-
window: globalWindow
|
|
17
|
-
} = global;
|
|
18
|
-
const defaultComponents = Object.assign({}, htmlComponents, {
|
|
19
|
-
code: CodeOrSourceMdx,
|
|
20
|
-
a: AnchorMdx
|
|
21
|
-
}, HeadersMdx);
|
|
22
|
-
const warnOptionsTheme = deprecate(() => {}, dedent`
|
|
23
|
-
Deprecated parameter: options.theme => docs.theme
|
|
24
|
-
|
|
25
|
-
https://github.com/storybookjs/storybook/blob/next/addons/docs/docs/theming.md#storybook-theming
|
|
26
|
-
`);
|
|
27
|
-
export const DocsContainer = ({
|
|
28
|
-
context,
|
|
29
|
-
children
|
|
30
|
-
}) => {
|
|
31
|
-
const {
|
|
32
|
-
id: storyId,
|
|
33
|
-
type,
|
|
34
|
-
storyById
|
|
35
|
-
} = context;
|
|
36
|
-
const allComponents = Object.assign({}, defaultComponents);
|
|
37
|
-
let theme = ensureTheme(null);
|
|
38
|
-
|
|
39
|
-
if (type === 'legacy') {
|
|
40
|
-
const {
|
|
41
|
-
parameters: {
|
|
42
|
-
options = {},
|
|
43
|
-
docs = {}
|
|
44
|
-
}
|
|
45
|
-
} = storyById(storyId);
|
|
46
|
-
let themeVars = docs.theme;
|
|
47
|
-
|
|
48
|
-
if (!themeVars && options.theme) {
|
|
49
|
-
warnOptionsTheme();
|
|
50
|
-
themeVars = options.theme;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
theme = ensureTheme(themeVars);
|
|
54
|
-
Object.assign(allComponents, docs.components);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
useEffect(() => {
|
|
58
|
-
let url;
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
url = new URL(globalWindow.parent.location);
|
|
62
|
-
} catch (err) {
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (url.hash) {
|
|
67
|
-
const element = document.getElementById(url.hash.substring(1));
|
|
68
|
-
|
|
69
|
-
if (element) {
|
|
70
|
-
// Introducing a delay to ensure scrolling works when it's a full refresh.
|
|
71
|
-
setTimeout(() => {
|
|
72
|
-
scrollToElement(element);
|
|
73
|
-
}, 200);
|
|
74
|
-
}
|
|
75
|
-
} else {
|
|
76
|
-
const element = document.getElementById(anchorBlockIdFromId(storyId)) || document.getElementById(storyBlockIdFromId(storyId));
|
|
77
|
-
|
|
78
|
-
if (element) {
|
|
79
|
-
const allStories = element.parentElement.querySelectorAll('[id|="anchor-"]');
|
|
80
|
-
let scrollTarget = element;
|
|
81
|
-
|
|
82
|
-
if (allStories && allStories[0] === element) {
|
|
83
|
-
// Include content above first story
|
|
84
|
-
scrollTarget = document.getElementById('docs-root');
|
|
85
|
-
} // Introducing a delay to ensure scrolling works when it's a full refresh.
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
setTimeout(() => {
|
|
89
|
-
scrollToElement(scrollTarget, 'start');
|
|
90
|
-
}, 200);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}, [storyId]);
|
|
94
|
-
return /*#__PURE__*/React.createElement(DocsContext.Provider, {
|
|
95
|
-
value: context
|
|
96
|
-
}, /*#__PURE__*/React.createElement(SourceContainer, null, /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
97
|
-
theme: theme
|
|
98
|
-
}, /*#__PURE__*/React.createElement(MDXProvider, {
|
|
99
|
-
components: allComponents
|
|
100
|
-
}, /*#__PURE__*/React.createElement(DocsWrapper, {
|
|
101
|
-
className: "sbdocs sbdocs-wrapper"
|
|
102
|
-
}, /*#__PURE__*/React.createElement(DocsContent, {
|
|
103
|
-
className: "sbdocs sbdocs-content"
|
|
104
|
-
}, children))))));
|
|
105
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { createContext } from 'react';
|
|
2
|
-
import { window as globalWindow } from 'global';
|
|
3
|
-
|
|
4
|
-
// We add DocsContext to window. The reason is that in case DocsContext.ts is
|
|
5
|
-
// imported multiple times (maybe once directly, and another time from a minified bundle)
|
|
6
|
-
// we will have multiple DocsContext definitions - leading to lost context in
|
|
7
|
-
// the React component tree.
|
|
8
|
-
// This was specifically a problem with the Vite builder.
|
|
9
|
-
|
|
10
|
-
/* eslint-disable no-underscore-dangle */
|
|
11
|
-
if (globalWindow && globalWindow.__DOCS_CONTEXT__ === undefined) {
|
|
12
|
-
globalWindow.__DOCS_CONTEXT__ = /*#__PURE__*/createContext(null);
|
|
13
|
-
globalWindow.__DOCS_CONTEXT__.displayName = 'DocsContext';
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const DocsContext = globalWindow ? globalWindow.__DOCS_CONTEXT__ : /*#__PURE__*/createContext(null);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { Title } from './Title';
|
|
3
|
-
import { Subtitle } from './Subtitle';
|
|
4
|
-
import { Description } from './Description';
|
|
5
|
-
import { Primary } from './Primary';
|
|
6
|
-
import { PRIMARY_STORY } from './types';
|
|
7
|
-
import { ArgsTable } from './ArgsTable';
|
|
8
|
-
import { Stories } from './Stories';
|
|
9
|
-
export const DocsPage = () => /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Title, null), /*#__PURE__*/React.createElement(Subtitle, null), /*#__PURE__*/React.createElement(Description, null), /*#__PURE__*/React.createElement(Primary, null), /*#__PURE__*/React.createElement(ArgsTable, {
|
|
10
|
-
story: PRIMARY_STORY
|
|
11
|
-
}), /*#__PURE__*/React.createElement(Stories, null));
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import ReactDOM from 'react-dom';
|
|
3
|
-
import { DocsContainer } from './DocsContainer';
|
|
4
|
-
import { DocsPage } from './DocsPage';
|
|
5
|
-
export class DocsRenderer {
|
|
6
|
-
constructor() {
|
|
7
|
-
this.render = void 0;
|
|
8
|
-
this.unmount = void 0;
|
|
9
|
-
|
|
10
|
-
this.render = (docsContext, docsParameters, element, callback) => {
|
|
11
|
-
renderDocsAsync(docsContext, docsParameters, element).then(callback);
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
this.unmount = element => {
|
|
15
|
-
ReactDOM.unmountComponentAtNode(element);
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
async function renderDocsAsync(docsContext, docsParameters, element) {
|
|
22
|
-
const Container = docsParameters.container || (await docsParameters.getContainer?.()) || DocsContainer;
|
|
23
|
-
const Page = docsParameters.page || (await docsParameters.getPage?.()) || DocsPage; // Use `title` as a key so that we force a re-render every time we switch components
|
|
24
|
-
|
|
25
|
-
const docsElement = /*#__PURE__*/React.createElement(Container, {
|
|
26
|
-
key: docsContext.title,
|
|
27
|
-
context: docsContext
|
|
28
|
-
}, /*#__PURE__*/React.createElement(Page, null));
|
|
29
|
-
await new Promise(resolve => {
|
|
30
|
-
ReactDOM.render(docsElement, element, resolve);
|
|
31
|
-
});
|
|
32
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import deprecate from 'util-deprecate';
|
|
3
|
-
import dedent from 'ts-dedent';
|
|
4
|
-
import { Subheading } from './Subheading';
|
|
5
|
-
import { Anchor } from './Anchor';
|
|
6
|
-
import { Description } from './Description';
|
|
7
|
-
import { Story } from './Story';
|
|
8
|
-
import { Canvas } from './Canvas';
|
|
9
|
-
const warnStoryDescription = deprecate(() => {}, dedent`
|
|
10
|
-
Deprecated parameter: docs.storyDescription => docs.description.story
|
|
11
|
-
|
|
12
|
-
https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#docs-description-parameter
|
|
13
|
-
`);
|
|
14
|
-
export const DocsStory = ({
|
|
15
|
-
id,
|
|
16
|
-
name,
|
|
17
|
-
expanded = true,
|
|
18
|
-
withToolbar = false,
|
|
19
|
-
parameters = {}
|
|
20
|
-
}) => {
|
|
21
|
-
let description;
|
|
22
|
-
const {
|
|
23
|
-
docs
|
|
24
|
-
} = parameters;
|
|
25
|
-
|
|
26
|
-
if (expanded && docs) {
|
|
27
|
-
description = docs.description?.story;
|
|
28
|
-
|
|
29
|
-
if (!description) {
|
|
30
|
-
description = docs.storyDescription;
|
|
31
|
-
if (description) warnStoryDescription();
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const subheading = expanded && name;
|
|
36
|
-
return /*#__PURE__*/React.createElement(Anchor, {
|
|
37
|
-
storyId: id
|
|
38
|
-
}, subheading && /*#__PURE__*/React.createElement(Subheading, null, subheading), description && /*#__PURE__*/React.createElement(Description, {
|
|
39
|
-
markdown: description
|
|
40
|
-
}), /*#__PURE__*/React.createElement(Canvas, {
|
|
41
|
-
withToolbar: withToolbar
|
|
42
|
-
}, /*#__PURE__*/React.createElement(Story, {
|
|
43
|
-
id: id,
|
|
44
|
-
parameters: parameters
|
|
45
|
-
})));
|
|
46
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { ThemeProvider, themes, ensure } from '@storybook/theming';
|
|
3
|
-
import { DocsContext } from './DocsContext';
|
|
4
|
-
import { ExternalPreview } from './ExternalPreview';
|
|
5
|
-
let preview;
|
|
6
|
-
export const ExternalDocsContainer = ({
|
|
7
|
-
projectAnnotations,
|
|
8
|
-
children
|
|
9
|
-
}) => {
|
|
10
|
-
if (!preview) preview = new ExternalPreview(projectAnnotations);
|
|
11
|
-
let pageMeta;
|
|
12
|
-
|
|
13
|
-
const setMeta = m => {
|
|
14
|
-
pageMeta = m;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const docsContext = {
|
|
18
|
-
type: 'external',
|
|
19
|
-
id: 'external-docs',
|
|
20
|
-
title: 'External',
|
|
21
|
-
name: 'Docs',
|
|
22
|
-
storyIdByModuleExport: (storyExport, metaExport) => {
|
|
23
|
-
return preview.storyIdByModuleExport(storyExport, metaExport || pageMeta);
|
|
24
|
-
},
|
|
25
|
-
storyById: id => {
|
|
26
|
-
return preview.storyById(id);
|
|
27
|
-
},
|
|
28
|
-
getStoryContext: () => {
|
|
29
|
-
throw new Error('not implemented');
|
|
30
|
-
},
|
|
31
|
-
componentStories: () => {
|
|
32
|
-
// TODO: could implement in a very similar way to in DocsRender. (TODO: How to share code?)
|
|
33
|
-
throw new Error('not implemented');
|
|
34
|
-
},
|
|
35
|
-
loadStory: async id => {
|
|
36
|
-
return preview.storyById(id);
|
|
37
|
-
},
|
|
38
|
-
renderStoryToElement: (story, element) => {
|
|
39
|
-
return preview.renderStoryToElement(story, element);
|
|
40
|
-
},
|
|
41
|
-
setMeta
|
|
42
|
-
};
|
|
43
|
-
return /*#__PURE__*/React.createElement(DocsContext.Provider, {
|
|
44
|
-
value: docsContext
|
|
45
|
-
}, /*#__PURE__*/React.createElement(ThemeProvider, {
|
|
46
|
-
theme: ensure(themes.normal)
|
|
47
|
-
}, children));
|
|
48
|
-
};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Preview } from '@storybook/preview-web';
|
|
2
|
-
import { toId } from '@storybook/csf';
|
|
3
|
-
|
|
4
|
-
class ConstantMap {
|
|
5
|
-
// eslint-disable-next-line no-useless-constructor
|
|
6
|
-
constructor(prefix) {
|
|
7
|
-
this.prefix = prefix;
|
|
8
|
-
this.entries = new Map();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
get(key) {
|
|
12
|
-
if (!this.entries.has(key)) {
|
|
13
|
-
this.entries.set(key, `${this.prefix}${this.entries.size}`);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
return this.entries.get(key);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class ExternalPreview extends Preview {
|
|
22
|
-
constructor(projectAnnotations) {
|
|
23
|
-
super();
|
|
24
|
-
this.projectAnnotations = projectAnnotations;
|
|
25
|
-
this.initialized = false;
|
|
26
|
-
this.importPaths = new ConstantMap('./importPath/');
|
|
27
|
-
this.titles = new ConstantMap('title-');
|
|
28
|
-
this.storyIds = new Map();
|
|
29
|
-
this.storyIndex = {
|
|
30
|
-
v: 4,
|
|
31
|
-
entries: {}
|
|
32
|
-
};
|
|
33
|
-
this.moduleExportsByImportPath = {};
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
storyIdByModuleExport(storyExport, meta) {
|
|
37
|
-
if (!this.storyIds.has(storyExport)) this.addStoryFromExports(storyExport, meta);
|
|
38
|
-
return this.storyIds.get(storyExport);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
addStoryFromExports(storyExport, meta) {
|
|
42
|
-
const importPath = this.importPaths.get(meta);
|
|
43
|
-
this.moduleExportsByImportPath[importPath] = meta;
|
|
44
|
-
const title = meta.default.title || this.titles.get(meta);
|
|
45
|
-
const exportEntry = Object.entries(meta).find(([_, moduleExport]) => moduleExport === storyExport);
|
|
46
|
-
if (!exportEntry) throw new Error(`Didn't find \`of\` used in Story block in the provided CSF exports`);
|
|
47
|
-
const storyId = toId(title, exportEntry[0]);
|
|
48
|
-
this.storyIds.set(storyExport, storyId);
|
|
49
|
-
this.storyIndex.entries[storyId] = {
|
|
50
|
-
id: storyId,
|
|
51
|
-
importPath,
|
|
52
|
-
title,
|
|
53
|
-
name: 'Name',
|
|
54
|
-
type: 'story'
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
if (!this.initialized) {
|
|
58
|
-
this.initialized = true;
|
|
59
|
-
return this.initialize({
|
|
60
|
-
getStoryIndex: () => this.storyIndex,
|
|
61
|
-
importFn: path => {
|
|
62
|
-
return Promise.resolve(this.moduleExportsByImportPath[path]);
|
|
63
|
-
},
|
|
64
|
-
getProjectAnnotations: () => this.projectAnnotations
|
|
65
|
-
});
|
|
66
|
-
} // else
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
return this.onStoriesChanged({
|
|
70
|
-
storyIndex: this.storyIndex
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
storyById(storyId) {
|
|
75
|
-
const entry = this.storyIndex.entries[storyId];
|
|
76
|
-
if (!entry) throw new Error(`Unknown storyId ${storyId}`);
|
|
77
|
-
const {
|
|
78
|
-
importPath,
|
|
79
|
-
title
|
|
80
|
-
} = entry;
|
|
81
|
-
const moduleExports = this.moduleExportsByImportPath[importPath];
|
|
82
|
-
const csfFile = this.storyStore.processCSFFileWithCache(moduleExports, importPath, title);
|
|
83
|
-
return this.storyStore.storyFromCSFFile({
|
|
84
|
-
storyId,
|
|
85
|
-
csfFile
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { H2 } from '@storybook/components';
|
|
3
|
-
import { HeaderMdx } from './mdx';
|
|
4
|
-
export const Heading = ({
|
|
5
|
-
children,
|
|
6
|
-
disableAnchor
|
|
7
|
-
}) => {
|
|
8
|
-
if (disableAnchor || typeof children !== 'string') {
|
|
9
|
-
return /*#__PURE__*/React.createElement(H2, null, children);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const tagID = children.toLowerCase().replace(/[^a-z0-9]/gi, '-');
|
|
13
|
-
return /*#__PURE__*/React.createElement(HeaderMdx, {
|
|
14
|
-
as: "h2",
|
|
15
|
-
id: tagID
|
|
16
|
-
}, children);
|
|
17
|
-
};
|
package/dist/esm/blocks/Meta.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import React, { useContext } from 'react';
|
|
2
|
-
import global from 'global';
|
|
3
|
-
import { Anchor } from './Anchor';
|
|
4
|
-
import { DocsContext } from './DocsContext';
|
|
5
|
-
const {
|
|
6
|
-
document
|
|
7
|
-
} = global;
|
|
8
|
-
|
|
9
|
-
function getFirstStoryId(docsContext) {
|
|
10
|
-
const stories = docsContext.componentStories();
|
|
11
|
-
return stories.length > 0 ? stories[0].id : null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function renderAnchor() {
|
|
15
|
-
const context = useContext(DocsContext);
|
|
16
|
-
|
|
17
|
-
if (context.type !== 'legacy') {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const anchorId = getFirstStoryId(context) || context.id;
|
|
22
|
-
return /*#__PURE__*/React.createElement(Anchor, {
|
|
23
|
-
storyId: anchorId
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* This component is used to declare component metadata in docs
|
|
28
|
-
* and gets transformed into a default export underneath the hood.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
export const Meta = ({
|
|
33
|
-
of
|
|
34
|
-
}) => {
|
|
35
|
-
let isDocs = true;
|
|
36
|
-
|
|
37
|
-
if (document) {
|
|
38
|
-
const params = new URL(document.location).searchParams;
|
|
39
|
-
isDocs = params.get('viewMode') === 'docs';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const context = useContext(DocsContext);
|
|
43
|
-
if (of) context.setMeta(of);
|
|
44
|
-
return isDocs ? renderAnchor() : null;
|
|
45
|
-
};
|
|
@@ -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
|
-
};
|