@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.
Files changed (109) hide show
  1. package/README.md +12 -75
  2. package/angular/index.js +1 -1
  3. package/dist/cjs/DocsRenderer.js +54 -0
  4. package/dist/cjs/blocks.js +18 -0
  5. package/dist/cjs/index.js +13 -1
  6. package/dist/cjs/preset.js +35 -18
  7. package/dist/cjs/preview.js +6 -2
  8. package/dist/esm/DocsRenderer.js +35 -0
  9. package/dist/esm/blocks.js +1 -0
  10. package/dist/esm/index.js +2 -1
  11. package/dist/esm/preset.js +31 -11
  12. package/dist/esm/preview.js +6 -2
  13. package/dist/types/DocsRenderer.d.ts +8 -0
  14. package/dist/types/blocks.d.ts +1 -0
  15. package/dist/types/index.d.ts +1 -0
  16. package/dist/types/preset.d.ts +8 -2
  17. package/dist/types/preview.d.ts +1 -6
  18. package/jest-transform-mdx.js +4 -3
  19. package/package.json +25 -32
  20. package/web-components/README.md +1 -0
  21. package/LICENSE +0 -21
  22. package/blocks.d.ts +0 -2
  23. package/blocks.js +0 -14
  24. package/dist/cjs/blocks/Anchor.js +0 -23
  25. package/dist/cjs/blocks/ArgsTable.js +0 -329
  26. package/dist/cjs/blocks/Canvas.js +0 -109
  27. package/dist/cjs/blocks/Description.js +0 -126
  28. package/dist/cjs/blocks/DocsContainer.js +0 -127
  29. package/dist/cjs/blocks/DocsContext.js +0 -25
  30. package/dist/cjs/blocks/DocsPage.js +0 -30
  31. package/dist/cjs/blocks/DocsStory.js +0 -68
  32. package/dist/cjs/blocks/Heading.js +0 -31
  33. package/dist/cjs/blocks/Meta.js +0 -50
  34. package/dist/cjs/blocks/Preview.js +0 -23
  35. package/dist/cjs/blocks/Primary.js +0 -39
  36. package/dist/cjs/blocks/Props.js +0 -29
  37. package/dist/cjs/blocks/Source.js +0 -179
  38. package/dist/cjs/blocks/SourceContainer.js +0 -67
  39. package/dist/cjs/blocks/Stories.js +0 -51
  40. package/dist/cjs/blocks/Story.js +0 -143
  41. package/dist/cjs/blocks/Subheading.js +0 -31
  42. package/dist/cjs/blocks/Subtitle.js +0 -39
  43. package/dist/cjs/blocks/Title.js +0 -44
  44. package/dist/cjs/blocks/Wrapper.js +0 -20
  45. package/dist/cjs/blocks/enhanceSource.js +0 -92
  46. package/dist/cjs/blocks/index.js +0 -366
  47. package/dist/cjs/blocks/mdx.js +0 -234
  48. package/dist/cjs/blocks/types.js +0 -10
  49. package/dist/cjs/blocks/useStory.js +0 -37
  50. package/dist/cjs/blocks/utils.js +0 -40
  51. package/dist/cjs/manager.js +0 -20
  52. package/dist/esm/blocks/Anchor.js +0 -8
  53. package/dist/esm/blocks/ArgsTable.js +0 -292
  54. package/dist/esm/blocks/Canvas.js +0 -83
  55. package/dist/esm/blocks/Description.js +0 -107
  56. package/dist/esm/blocks/DocsContainer.js +0 -98
  57. package/dist/esm/blocks/DocsContext.js +0 -16
  58. package/dist/esm/blocks/DocsPage.js +0 -11
  59. package/dist/esm/blocks/DocsStory.js +0 -46
  60. package/dist/esm/blocks/Heading.js +0 -17
  61. package/dist/esm/blocks/Meta.js +0 -31
  62. package/dist/esm/blocks/Preview.js +0 -9
  63. package/dist/esm/blocks/Primary.js +0 -23
  64. package/dist/esm/blocks/Props.js +0 -14
  65. package/dist/esm/blocks/Source.js +0 -144
  66. package/dist/esm/blocks/SourceContainer.js +0 -44
  67. package/dist/esm/blocks/Stories.js +0 -30
  68. package/dist/esm/blocks/Story.js +0 -114
  69. package/dist/esm/blocks/Subheading.js +0 -17
  70. package/dist/esm/blocks/Subtitle.js +0 -23
  71. package/dist/esm/blocks/Title.js +0 -24
  72. package/dist/esm/blocks/Wrapper.js +0 -8
  73. package/dist/esm/blocks/enhanceSource.js +0 -87
  74. package/dist/esm/blocks/index.js +0 -24
  75. package/dist/esm/blocks/mdx.js +0 -203
  76. package/dist/esm/blocks/types.js +0 -2
  77. package/dist/esm/blocks/useStory.js +0 -27
  78. package/dist/esm/blocks/utils.js +0 -29
  79. package/dist/esm/manager.js +0 -16
  80. package/dist/types/blocks/Anchor.d.ts +0 -6
  81. package/dist/types/blocks/ArgsTable.d.ts +0 -33
  82. package/dist/types/blocks/Canvas.d.ts +0 -9
  83. package/dist/types/blocks/Description.d.ts +0 -20
  84. package/dist/types/blocks/DocsContainer.d.ts +0 -7
  85. package/dist/types/blocks/DocsContext.d.ts +0 -5
  86. package/dist/types/blocks/DocsPage.d.ts +0 -2
  87. package/dist/types/blocks/DocsStory.d.ts +0 -3
  88. package/dist/types/blocks/Heading.d.ts +0 -6
  89. package/dist/types/blocks/Meta.d.ts +0 -9
  90. package/dist/types/blocks/Preview.d.ts +0 -3
  91. package/dist/types/blocks/Primary.d.ts +0 -6
  92. package/dist/types/blocks/Props.d.ts +0 -3
  93. package/dist/types/blocks/Source.d.ts +0 -38
  94. package/dist/types/blocks/SourceContainer.d.ts +0 -14
  95. package/dist/types/blocks/Stories.d.ts +0 -7
  96. package/dist/types/blocks/Story.d.ts +0 -28
  97. package/dist/types/blocks/Subheading.d.ts +0 -3
  98. package/dist/types/blocks/Subtitle.d.ts +0 -6
  99. package/dist/types/blocks/Title.d.ts +0 -8
  100. package/dist/types/blocks/Wrapper.d.ts +0 -2
  101. package/dist/types/blocks/enhanceSource.d.ts +0 -3
  102. package/dist/types/blocks/index.d.ts +0 -24
  103. package/dist/types/blocks/mdx.d.ts +0 -20
  104. package/dist/types/blocks/types.d.ts +0 -13
  105. package/dist/types/blocks/useStory.d.ts +0 -5
  106. package/dist/types/blocks/utils.d.ts +0 -3
  107. package/dist/types/manager.d.ts +0 -1
  108. package/manager.js +0 -1
  109. package/register.js +0 -6
@@ -1,8 +0,0 @@
1
- import React from 'react';
2
- export const anchorBlockIdFromId = storyId => `anchor--${storyId}`;
3
- export const Anchor = ({
4
- storyId,
5
- children
6
- }) => /*#__PURE__*/React.createElement("div", {
7
- id: anchorBlockIdFromId(storyId)
8
- }, children);
@@ -1,292 +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, useEffect, useState, useCallback } from 'react';
4
- import mapValues from 'lodash/mapValues';
5
- import { ArgsTable as PureArgsTable, ArgsTableError, TabbedArgsTable } from '@storybook/components';
6
- import { addons } from '@storybook/addons';
7
- import { filterArgTypes } from '@storybook/store';
8
- import Events from '@storybook/core-events';
9
- import { DocsContext } from './DocsContext';
10
- import { CURRENT_SELECTION, PRIMARY_STORY } from './types';
11
- import { getComponentName } from './utils';
12
- import { lookupStoryId } from './Story';
13
- import { useStory } from './useStory';
14
-
15
- const getContext = (storyId, context) => {
16
- const story = context.storyById(storyId);
17
-
18
- if (!story) {
19
- throw new Error(`Unknown story: ${storyId}`);
20
- }
21
-
22
- return context.getStoryContext(story);
23
- };
24
-
25
- const useArgs = (storyId, context) => {
26
- const channel = addons.getChannel();
27
- const storyContext = getContext(storyId, context);
28
- const [args, setArgs] = useState(storyContext.args);
29
- useEffect(() => {
30
- const cb = changed => {
31
- if (changed.storyId === storyId) {
32
- setArgs(changed.args);
33
- }
34
- };
35
-
36
- channel.on(Events.STORY_ARGS_UPDATED, cb);
37
- return () => channel.off(Events.STORY_ARGS_UPDATED, cb);
38
- }, [storyId]);
39
- const updateArgs = useCallback(updatedArgs => channel.emit(Events.UPDATE_STORY_ARGS, {
40
- storyId,
41
- updatedArgs
42
- }), [storyId]);
43
- const resetArgs = useCallback(argNames => channel.emit(Events.RESET_STORY_ARGS, {
44
- storyId,
45
- argNames
46
- }), [storyId]);
47
- return [args, updateArgs, resetArgs];
48
- };
49
-
50
- const useGlobals = (storyId, context) => {
51
- const channel = addons.getChannel();
52
- const storyContext = getContext(storyId, context);
53
- const [globals, setGlobals] = useState(storyContext.globals);
54
- useEffect(() => {
55
- const cb = changed => {
56
- setGlobals(changed.globals);
57
- };
58
-
59
- channel.on(Events.GLOBALS_UPDATED, cb);
60
- return () => channel.off(Events.GLOBALS_UPDATED, cb);
61
- }, []);
62
- return [globals];
63
- };
64
-
65
- export const extractComponentArgTypes = (component, {
66
- id,
67
- storyById
68
- }, include, exclude) => {
69
- const {
70
- parameters
71
- } = storyById(id);
72
- const {
73
- extractArgTypes
74
- } = parameters.docs || {};
75
-
76
- if (!extractArgTypes) {
77
- throw new Error(ArgsTableError.ARGS_UNSUPPORTED);
78
- }
79
-
80
- let argTypes = extractArgTypes(component);
81
- argTypes = filterArgTypes(argTypes, include, exclude);
82
- return argTypes;
83
- };
84
-
85
- const isShortcut = value => {
86
- return value && [CURRENT_SELECTION, PRIMARY_STORY].includes(value);
87
- };
88
-
89
- export const getComponent = (props = {}, {
90
- id,
91
- storyById
92
- }) => {
93
- const {
94
- of
95
- } = props;
96
- const {
97
- story
98
- } = props;
99
- const {
100
- component
101
- } = storyById(id);
102
-
103
- if (isShortcut(of) || isShortcut(story)) {
104
- return component || null;
105
- }
106
-
107
- if (!of) {
108
- throw new Error(ArgsTableError.NO_COMPONENT);
109
- }
110
-
111
- return of;
112
- };
113
-
114
- const addComponentTabs = (tabs, components, context, include, exclude, sort) => Object.assign({}, tabs, mapValues(components, comp => ({
115
- rows: extractComponentArgTypes(comp, context, include, exclude),
116
- sort
117
- })));
118
-
119
- export const StoryTable = props => {
120
- const context = useContext(DocsContext);
121
- const {
122
- id: currentId,
123
- componentStories
124
- } = context;
125
- const {
126
- story: storyName,
127
- component,
128
- subcomponents,
129
- showComponent,
130
- include,
131
- exclude,
132
- sort
133
- } = props;
134
-
135
- try {
136
- let storyId;
137
-
138
- switch (storyName) {
139
- case CURRENT_SELECTION:
140
- {
141
- storyId = currentId;
142
- break;
143
- }
144
-
145
- case PRIMARY_STORY:
146
- {
147
- const primaryStory = componentStories()[0];
148
- storyId = primaryStory.id;
149
- break;
150
- }
151
-
152
- default:
153
- {
154
- storyId = lookupStoryId(storyName, context);
155
- }
156
- }
157
-
158
- const story = useStory(storyId, context); // eslint-disable-next-line prefer-const
159
-
160
- let [args, updateArgs, resetArgs] = useArgs(storyId, context);
161
- const [globals] = useGlobals(storyId, context);
162
- if (!story) return /*#__PURE__*/React.createElement(PureArgsTable, {
163
- isLoading: true,
164
- updateArgs: updateArgs,
165
- resetArgs: resetArgs
166
- });
167
- const argTypes = filterArgTypes(story.argTypes, include, exclude);
168
- const mainLabel = getComponentName(component) || 'Story';
169
- let tabs = {
170
- [mainLabel]: {
171
- rows: argTypes,
172
- args,
173
- globals,
174
- updateArgs,
175
- resetArgs
176
- }
177
- }; // Use the dynamically generated component tabs if there are no controls
178
-
179
- const storyHasArgsWithControls = argTypes && Object.values(argTypes).find(v => !!v?.control);
180
-
181
- if (!storyHasArgsWithControls) {
182
- updateArgs = null;
183
- resetArgs = null;
184
- tabs = {};
185
- }
186
-
187
- if (component && (!storyHasArgsWithControls || showComponent)) {
188
- tabs = addComponentTabs(tabs, {
189
- [mainLabel]: component
190
- }, context, include, exclude);
191
- }
192
-
193
- if (subcomponents) {
194
- if (Array.isArray(subcomponents)) {
195
- throw new Error(`Unexpected subcomponents array. Expected an object whose keys are tab labels and whose values are components.`);
196
- }
197
-
198
- tabs = addComponentTabs(tabs, subcomponents, context, include, exclude);
199
- }
200
-
201
- return /*#__PURE__*/React.createElement(TabbedArgsTable, {
202
- tabs: tabs,
203
- sort: sort
204
- });
205
- } catch (err) {
206
- return /*#__PURE__*/React.createElement(PureArgsTable, {
207
- error: err.message
208
- });
209
- }
210
- };
211
- export const ComponentsTable = props => {
212
- const context = useContext(DocsContext);
213
- const {
214
- components,
215
- include,
216
- exclude,
217
- sort
218
- } = props;
219
- const tabs = addComponentTabs({}, components, context, include, exclude);
220
- return /*#__PURE__*/React.createElement(TabbedArgsTable, {
221
- tabs: tabs,
222
- sort: sort
223
- });
224
- };
225
- export const ArgsTable = props => {
226
- const context = useContext(DocsContext);
227
- const {
228
- id,
229
- storyById
230
- } = context;
231
- const {
232
- parameters: {
233
- controls
234
- },
235
- subcomponents
236
- } = storyById(id);
237
- const {
238
- include,
239
- exclude,
240
- components,
241
- sort: sortProp
242
- } = props;
243
- const {
244
- story: storyName
245
- } = props;
246
- const sort = sortProp || controls?.sort;
247
- const main = getComponent(props, context);
248
-
249
- if (storyName) {
250
- return /*#__PURE__*/React.createElement(StoryTable, _extends({}, props, {
251
- component: main,
252
- subcomponents,
253
- sort
254
- }));
255
- }
256
-
257
- if (!components && !subcomponents) {
258
- let mainProps;
259
-
260
- try {
261
- mainProps = {
262
- rows: extractComponentArgTypes(main, context, include, exclude)
263
- };
264
- } catch (err) {
265
- mainProps = {
266
- error: err.message
267
- };
268
- }
269
-
270
- return /*#__PURE__*/React.createElement(PureArgsTable, _extends({}, mainProps, {
271
- sort: sort
272
- }));
273
- }
274
-
275
- if (components) {
276
- return /*#__PURE__*/React.createElement(ComponentsTable, _extends({}, props, {
277
- components,
278
- sort
279
- }));
280
- }
281
-
282
- const mainLabel = getComponentName(main);
283
- return /*#__PURE__*/React.createElement(ComponentsTable, _extends({}, props, {
284
- components: Object.assign({
285
- [mainLabel]: main
286
- }, subcomponents),
287
- sort: sort
288
- }));
289
- };
290
- ArgsTable.defaultProps = {
291
- of: CURRENT_SELECTION
292
- };
@@ -1,83 +0,0 @@
1
- const _excluded = ["withSource", "mdxSource", "children"];
2
-
3
- function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
4
-
5
- import React, { useContext } from 'react';
6
- import { MDXProvider } from '@mdx-js/react';
7
- import { toId, storyNameFromExport } from '@storybook/csf';
8
- import { resetComponents, Preview as PurePreview, PreviewSkeleton } from '@storybook/components';
9
- import { DocsContext } from './DocsContext';
10
- import { SourceContext } from './SourceContainer';
11
- import { getSourceProps, SourceState } from './Source';
12
- import { useStories } from './useStory';
13
- import { CURRENT_SELECTION } from './types';
14
- export { SourceState };
15
-
16
- const getPreviewProps = (_ref, docsContext, sourceContext) => {
17
- let {
18
- withSource,
19
- mdxSource,
20
- children
21
- } = _ref,
22
- props = _objectWithoutPropertiesLoose(_ref, _excluded);
23
-
24
- const {
25
- mdxComponentAnnotations,
26
- mdxStoryNameToKey
27
- } = docsContext;
28
- let sourceState = withSource;
29
- let isLoading = false;
30
-
31
- if (sourceState === SourceState.NONE) {
32
- return {
33
- isLoading,
34
- previewProps: props
35
- };
36
- }
37
-
38
- if (mdxSource) {
39
- return {
40
- isLoading,
41
- previewProps: Object.assign({}, props, {
42
- withSource: getSourceProps({
43
- code: decodeURI(mdxSource)
44
- }, docsContext, sourceContext)
45
- })
46
- };
47
- }
48
-
49
- const childArray = Array.isArray(children) ? children : [children];
50
- const storyChildren = childArray.filter(c => c.props && (c.props.id || c.props.name));
51
- const targetIds = storyChildren.map(s => s.props.id || toId(mdxComponentAnnotations.id || mdxComponentAnnotations.title, storyNameFromExport(mdxStoryNameToKey[s.props.name])));
52
- const sourceProps = getSourceProps({
53
- ids: targetIds
54
- }, docsContext, sourceContext);
55
- if (!sourceState) sourceState = sourceProps.state;
56
- const storyIds = targetIds.map(targetId => targetId === CURRENT_SELECTION ? docsContext.id : targetId);
57
- const stories = useStories(storyIds, docsContext);
58
- isLoading = stories.some(s => !s);
59
- return {
60
- isLoading,
61
- previewProps: Object.assign({}, props, {
62
- // pass through columns etc.
63
- withSource: sourceProps,
64
- isExpanded: sourceState === SourceState.OPEN
65
- })
66
- };
67
- };
68
-
69
- export const Canvas = props => {
70
- const docsContext = useContext(DocsContext);
71
- const sourceContext = useContext(SourceContext);
72
- const {
73
- isLoading,
74
- previewProps
75
- } = getPreviewProps(props, docsContext, sourceContext);
76
- const {
77
- children
78
- } = props;
79
- if (isLoading) return /*#__PURE__*/React.createElement(PreviewSkeleton, null);
80
- return /*#__PURE__*/React.createElement(MDXProvider, {
81
- components: resetComponents
82
- }, /*#__PURE__*/React.createElement(PurePreview, previewProps, children));
83
- };
@@ -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,98 +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
- storyById
34
- } = context;
35
- const {
36
- parameters: {
37
- options = {},
38
- docs = {}
39
- }
40
- } = storyById(storyId);
41
- let themeVars = docs.theme;
42
-
43
- if (!themeVars && options.theme) {
44
- warnOptionsTheme();
45
- themeVars = options.theme;
46
- }
47
-
48
- const theme = ensureTheme(themeVars);
49
- const allComponents = Object.assign({}, defaultComponents, docs.components);
50
- useEffect(() => {
51
- let url;
52
-
53
- try {
54
- url = new URL(globalWindow.parent.location);
55
- } catch (err) {
56
- return;
57
- }
58
-
59
- if (url.hash) {
60
- const element = document.getElementById(url.hash.substring(1));
61
-
62
- if (element) {
63
- // Introducing a delay to ensure scrolling works when it's a full refresh.
64
- setTimeout(() => {
65
- scrollToElement(element);
66
- }, 200);
67
- }
68
- } else {
69
- const element = document.getElementById(anchorBlockIdFromId(storyId)) || document.getElementById(storyBlockIdFromId(storyId));
70
-
71
- if (element) {
72
- const allStories = element.parentElement.querySelectorAll('[id|="anchor-"]');
73
- let scrollTarget = element;
74
-
75
- if (allStories && allStories[0] === element) {
76
- // Include content above first story
77
- scrollTarget = document.getElementById('docs-root');
78
- } // Introducing a delay to ensure scrolling works when it's a full refresh.
79
-
80
-
81
- setTimeout(() => {
82
- scrollToElement(scrollTarget, 'start');
83
- }, 200);
84
- }
85
- }
86
- }, [storyId]);
87
- return /*#__PURE__*/React.createElement(DocsContext.Provider, {
88
- value: context
89
- }, /*#__PURE__*/React.createElement(SourceContainer, null, /*#__PURE__*/React.createElement(ThemeProvider, {
90
- theme: theme
91
- }, /*#__PURE__*/React.createElement(MDXProvider, {
92
- components: allComponents
93
- }, /*#__PURE__*/React.createElement(DocsWrapper, {
94
- className: "sbdocs sbdocs-wrapper"
95
- }, /*#__PURE__*/React.createElement(DocsContent, {
96
- className: "sbdocs sbdocs-content"
97
- }, children))))));
98
- };
@@ -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({});
13
- globalWindow.__DOCS_CONTEXT__.displayName = 'DocsContext';
14
- }
15
-
16
- export const DocsContext = globalWindow ? globalWindow.__DOCS_CONTEXT__ : /*#__PURE__*/createContext({});
@@ -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,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,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
- };