@storybook/addon-docs 7.0.0-alpha.7 → 7.0.0-alpha.8

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 (94) hide show
  1. package/dist/cjs/blocks/index.js +4 -380
  2. package/dist/cjs/preview.js +1 -1
  3. package/dist/esm/blocks/index.js +1 -27
  4. package/dist/esm/preview.js +1 -1
  5. package/dist/types/blocks/index.d.ts +1 -26
  6. package/dist/types/preview.d.ts +1 -5
  7. package/package.json +16 -15
  8. package/dist/cjs/blocks/Anchor.js +0 -23
  9. package/dist/cjs/blocks/ArgsTable.js +0 -329
  10. package/dist/cjs/blocks/Canvas.js +0 -119
  11. package/dist/cjs/blocks/Description.js +0 -126
  12. package/dist/cjs/blocks/DocsContainer.js +0 -134
  13. package/dist/cjs/blocks/DocsContext.js +0 -25
  14. package/dist/cjs/blocks/DocsPage.js +0 -30
  15. package/dist/cjs/blocks/DocsRenderer.js +0 -48
  16. package/dist/cjs/blocks/DocsStory.js +0 -66
  17. package/dist/cjs/blocks/ExternalDocsContainer.js +0 -64
  18. package/dist/cjs/blocks/ExternalPreview.js +0 -99
  19. package/dist/cjs/blocks/Heading.js +0 -31
  20. package/dist/cjs/blocks/Meta.js +0 -64
  21. package/dist/cjs/blocks/Preview.js +0 -23
  22. package/dist/cjs/blocks/Primary.js +0 -39
  23. package/dist/cjs/blocks/Props.js +0 -29
  24. package/dist/cjs/blocks/Source.js +0 -175
  25. package/dist/cjs/blocks/SourceContainer.js +0 -67
  26. package/dist/cjs/blocks/Stories.js +0 -47
  27. package/dist/cjs/blocks/Story.js +0 -152
  28. package/dist/cjs/blocks/Subheading.js +0 -31
  29. package/dist/cjs/blocks/Subtitle.js +0 -39
  30. package/dist/cjs/blocks/Title.js +0 -44
  31. package/dist/cjs/blocks/Wrapper.js +0 -20
  32. package/dist/cjs/blocks/enhanceSource.js +0 -90
  33. package/dist/cjs/blocks/mdx.js +0 -234
  34. package/dist/cjs/blocks/types.js +0 -10
  35. package/dist/cjs/blocks/useStory.js +0 -44
  36. package/dist/cjs/blocks/utils.js +0 -40
  37. package/dist/esm/blocks/Anchor.js +0 -8
  38. package/dist/esm/blocks/ArgsTable.js +0 -292
  39. package/dist/esm/blocks/Canvas.js +0 -93
  40. package/dist/esm/blocks/Description.js +0 -107
  41. package/dist/esm/blocks/DocsContainer.js +0 -105
  42. package/dist/esm/blocks/DocsContext.js +0 -16
  43. package/dist/esm/blocks/DocsPage.js +0 -11
  44. package/dist/esm/blocks/DocsRenderer.js +0 -32
  45. package/dist/esm/blocks/DocsStory.js +0 -46
  46. package/dist/esm/blocks/ExternalDocsContainer.js +0 -48
  47. package/dist/esm/blocks/ExternalPreview.js +0 -89
  48. package/dist/esm/blocks/Heading.js +0 -17
  49. package/dist/esm/blocks/Meta.js +0 -45
  50. package/dist/esm/blocks/Preview.js +0 -9
  51. package/dist/esm/blocks/Primary.js +0 -23
  52. package/dist/esm/blocks/Props.js +0 -14
  53. package/dist/esm/blocks/Source.js +0 -150
  54. package/dist/esm/blocks/SourceContainer.js +0 -44
  55. package/dist/esm/blocks/Stories.js +0 -30
  56. package/dist/esm/blocks/Story.js +0 -123
  57. package/dist/esm/blocks/Subheading.js +0 -17
  58. package/dist/esm/blocks/Subtitle.js +0 -23
  59. package/dist/esm/blocks/Title.js +0 -24
  60. package/dist/esm/blocks/Wrapper.js +0 -8
  61. package/dist/esm/blocks/enhanceSource.js +0 -87
  62. package/dist/esm/blocks/mdx.js +0 -203
  63. package/dist/esm/blocks/types.js +0 -2
  64. package/dist/esm/blocks/useStory.js +0 -34
  65. package/dist/esm/blocks/utils.js +0 -29
  66. package/dist/types/blocks/Anchor.d.ts +0 -6
  67. package/dist/types/blocks/ArgsTable.d.ts +0 -33
  68. package/dist/types/blocks/Canvas.d.ts +0 -9
  69. package/dist/types/blocks/Description.d.ts +0 -20
  70. package/dist/types/blocks/DocsContainer.d.ts +0 -7
  71. package/dist/types/blocks/DocsContext.d.ts +0 -5
  72. package/dist/types/blocks/DocsPage.d.ts +0 -2
  73. package/dist/types/blocks/DocsRenderer.d.ts +0 -7
  74. package/dist/types/blocks/DocsStory.d.ts +0 -3
  75. package/dist/types/blocks/ExternalDocsContainer.d.ts +0 -4
  76. package/dist/types/blocks/ExternalPreview.d.ts +0 -19
  77. package/dist/types/blocks/Heading.d.ts +0 -6
  78. package/dist/types/blocks/Meta.d.ts +0 -12
  79. package/dist/types/blocks/Preview.d.ts +0 -3
  80. package/dist/types/blocks/Primary.d.ts +0 -6
  81. package/dist/types/blocks/Props.d.ts +0 -3
  82. package/dist/types/blocks/Source.d.ts +0 -38
  83. package/dist/types/blocks/SourceContainer.d.ts +0 -14
  84. package/dist/types/blocks/Stories.d.ts +0 -7
  85. package/dist/types/blocks/Story.d.ts +0 -30
  86. package/dist/types/blocks/Subheading.d.ts +0 -3
  87. package/dist/types/blocks/Subtitle.d.ts +0 -6
  88. package/dist/types/blocks/Title.d.ts +0 -8
  89. package/dist/types/blocks/Wrapper.d.ts +0 -2
  90. package/dist/types/blocks/enhanceSource.d.ts +0 -3
  91. package/dist/types/blocks/mdx.d.ts +0 -20
  92. package/dist/types/blocks/types.d.ts +0 -13
  93. package/dist/types/blocks/useStory.d.ts +0 -5
  94. package/dist/types/blocks/utils.d.ts +0 -3
@@ -1,234 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.assertIsFn = exports.HeadersMdx = exports.HeaderMdx = exports.CodeOrSourceMdx = exports.AnchorMdx = exports.AddContext = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- var _addons = require("@storybook/addons");
11
-
12
- var _coreEvents = require("@storybook/core-events");
13
-
14
- var _components = require("@storybook/components");
15
-
16
- var _global = _interopRequireDefault(require("global"));
17
-
18
- var _theming = require("@storybook/theming");
19
-
20
- var _DocsContext = require("./DocsContext");
21
-
22
- const _excluded = ["children"],
23
- _excluded2 = ["className", "children"],
24
- _excluded3 = ["href", "target", "children"],
25
- _excluded4 = ["as", "id", "children"],
26
- _excluded5 = ["as", "id", "children"];
27
-
28
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
-
30
- 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); }
31
-
32
- 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; }
33
-
34
- const {
35
- document
36
- } = _global.default; // Hacky utility for asserting identifiers in MDX Story elements
37
-
38
- const assertIsFn = val => {
39
- if (typeof val !== 'function') {
40
- throw new Error(`Expected story function, got: ${val}`);
41
- }
42
-
43
- return val;
44
- }; // Hacky utility for adding mdxStoryToId to the default context
45
-
46
-
47
- exports.assertIsFn = assertIsFn;
48
-
49
- const AddContext = props => {
50
- const {
51
- children
52
- } = props,
53
- rest = _objectWithoutPropertiesLoose(props, _excluded);
54
-
55
- const parentContext = _react.default.useContext(_DocsContext.DocsContext);
56
-
57
- return /*#__PURE__*/_react.default.createElement(_DocsContext.DocsContext.Provider, {
58
- value: Object.assign({}, parentContext, rest)
59
- }, children);
60
- };
61
-
62
- exports.AddContext = AddContext;
63
-
64
- const CodeOrSourceMdx = _ref => {
65
- let {
66
- className,
67
- children
68
- } = _ref,
69
- rest = _objectWithoutPropertiesLoose(_ref, _excluded2);
70
-
71
- // markdown-to-jsx does not add className to inline code
72
- if (typeof className !== 'string' && (typeof children !== 'string' || !children.match(/[\n\r]/g))) {
73
- return /*#__PURE__*/_react.default.createElement(_components.Code, null, children);
74
- } // className: "lang-jsx"
75
-
76
-
77
- const language = className && className.split('-');
78
- return /*#__PURE__*/_react.default.createElement(_components.Source, _extends({
79
- language: language && language[1] || 'plaintext',
80
- format: false,
81
- code: children
82
- }, rest));
83
- };
84
-
85
- exports.CodeOrSourceMdx = CodeOrSourceMdx;
86
-
87
- function navigate(url) {
88
- _addons.addons.getChannel().emit(_coreEvents.NAVIGATE_URL, url);
89
- } // @ts-ignore
90
-
91
-
92
- const A = _components.components.a;
93
-
94
- const AnchorInPage = ({
95
- hash,
96
- children
97
- }) => /*#__PURE__*/_react.default.createElement(A, {
98
- href: hash,
99
- target: "_self",
100
- onClick: event => {
101
- const id = hash.substring(1);
102
- const element = document.getElementById(id);
103
-
104
- if (element) {
105
- navigate(hash);
106
- }
107
- }
108
- }, children);
109
-
110
- const AnchorMdx = props => {
111
- const {
112
- href,
113
- target,
114
- children
115
- } = props,
116
- rest = _objectWithoutPropertiesLoose(props, _excluded3);
117
-
118
- if (href) {
119
- // Enable scrolling for in-page anchors.
120
- if (href.startsWith('#')) {
121
- return /*#__PURE__*/_react.default.createElement(AnchorInPage, {
122
- hash: href
123
- }, children);
124
- } // Links to other pages of SB should use the base URL of the top level iframe instead of the base URL of the preview iframe.
125
-
126
-
127
- if (target !== '_blank' && !href.startsWith('https://')) {
128
- return /*#__PURE__*/_react.default.createElement(A, _extends({
129
- href: href,
130
- onClick: event => {
131
- event.preventDefault(); // use the A element's href, which has been modified for
132
- // local paths without a `?path=` query param prefix
133
-
134
- navigate(event.currentTarget.getAttribute('href'));
135
- },
136
- target: target
137
- }, rest), children);
138
- }
139
- } // External URL dont need any modification.
140
-
141
-
142
- return /*#__PURE__*/_react.default.createElement(A, props);
143
- };
144
-
145
- exports.AnchorMdx = AnchorMdx;
146
- const SUPPORTED_MDX_HEADERS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
147
- const OcticonHeaders = SUPPORTED_MDX_HEADERS.reduce((acc, headerType) => Object.assign({}, acc, {
148
- // @ts-ignore
149
- [headerType]: (0, _theming.styled)(_components.components[headerType])({
150
- '& svg': {
151
- visibility: 'hidden'
152
- },
153
- '&:hover svg': {
154
- visibility: 'visible'
155
- }
156
- })
157
- }), {});
158
-
159
- const OcticonAnchor = _theming.styled.a(() => ({
160
- float: 'left',
161
- paddingRight: '4px',
162
- marginLeft: '-20px',
163
- // Allow the theme's text color to override the default link color.
164
- color: 'inherit'
165
- }));
166
-
167
- const HeaderWithOcticonAnchor = _ref2 => {
168
- let {
169
- as,
170
- id,
171
- children
172
- } = _ref2,
173
- rest = _objectWithoutPropertiesLoose(_ref2, _excluded4);
174
-
175
- // @ts-ignore
176
- const OcticonHeader = OcticonHeaders[as];
177
- const hash = `#${id}`;
178
- return /*#__PURE__*/_react.default.createElement(OcticonHeader, _extends({
179
- id: id
180
- }, rest), /*#__PURE__*/_react.default.createElement(OcticonAnchor, {
181
- "aria-hidden": "true",
182
- href: hash,
183
- tabIndex: -1,
184
- target: "_self",
185
- onClick: event => {
186
- const element = document.getElementById(id);
187
-
188
- if (element) {
189
- navigate(hash);
190
- }
191
- }
192
- }, /*#__PURE__*/_react.default.createElement("svg", {
193
- viewBox: "0 0 16 16",
194
- version: "1.1",
195
- width: "16",
196
- height: "16",
197
- "aria-hidden": "true",
198
- fill: "currentColor"
199
- }, /*#__PURE__*/_react.default.createElement("path", {
200
- fillRule: "evenodd",
201
- d: "M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"
202
- }))), children);
203
- };
204
-
205
- const HeaderMdx = props => {
206
- const {
207
- as,
208
- id,
209
- children
210
- } = props,
211
- rest = _objectWithoutPropertiesLoose(props, _excluded5); // An id should have been added on every header by the "remark-slug" plugin.
212
-
213
-
214
- if (id) {
215
- return /*#__PURE__*/_react.default.createElement(HeaderWithOcticonAnchor, _extends({
216
- as: as,
217
- id: id
218
- }, rest), children);
219
- } // @ts-ignore
220
-
221
-
222
- const Header = _components.components[as]; // Make sure it still work if "remark-slug" plugin is not present.
223
-
224
- return /*#__PURE__*/_react.default.createElement(Header, props);
225
- };
226
-
227
- exports.HeaderMdx = HeaderMdx;
228
- const HeadersMdx = SUPPORTED_MDX_HEADERS.reduce((acc, headerType) => Object.assign({}, acc, {
229
- // @ts-ignore
230
- [headerType]: props => /*#__PURE__*/_react.default.createElement(HeaderMdx, _extends({
231
- as: headerType
232
- }, props))
233
- }), {});
234
- exports.HeadersMdx = HeadersMdx;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.PRIMARY_STORY = exports.CURRENT_SELECTION = void 0;
7
- const CURRENT_SELECTION = '.';
8
- exports.CURRENT_SELECTION = CURRENT_SELECTION;
9
- const PRIMARY_STORY = '^';
10
- exports.PRIMARY_STORY = PRIMARY_STORY;
@@ -1,44 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useStories = useStories;
7
- exports.useStory = useStory;
8
-
9
- var _react = require("react");
10
-
11
- function useStory(storyId, context) {
12
- const stories = useStories([storyId], context);
13
- return stories && stories[0];
14
- }
15
-
16
- function useStories(storyIds, context) {
17
- // Legacy docs pages can reference any story by id. Those stories will need to be
18
- // asyncronously loaded; we use the state for this
19
- const [storiesById, setStories] = (0, _react.useState)({});
20
- (0, _react.useEffect)(() => {
21
- Promise.all(storyIds.map(async storyId => {
22
- // loadStory will be called every single time useStory is called
23
- // because useEffect does not use storyIds as an input. This is because
24
- // HMR can change the story even when the storyId hasn't changed. However, it
25
- // will be a no-op once the story has loaded. Furthermore, the `story` will
26
- // have an exact equality when the story hasn't changed, so it won't trigger
27
- // any unnecessary re-renders
28
- const story = await context.loadStory(storyId);
29
- setStories(current => current[storyId] === story ? current : Object.assign({}, current, {
30
- [storyId]: story
31
- }));
32
- }));
33
- });
34
- return storyIds.map(storyId => {
35
- if (storiesById[storyId]) return storiesById[storyId];
36
-
37
- try {
38
- // If we are allowed to load this story id synchonously, this will work
39
- return context.storyById(storyId);
40
- } catch (err) {
41
- return null;
42
- }
43
- });
44
- }
@@ -1,40 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getComponentName = void 0;
7
- exports.scrollToElement = scrollToElement;
8
-
9
- /* eslint-disable no-underscore-dangle */
10
- const titleCase = str => str.split('-').map(part => part.charAt(0).toUpperCase() + part.slice(1)).join('');
11
-
12
- const getComponentName = component => {
13
- if (!component) {
14
- return undefined;
15
- }
16
-
17
- if (typeof component === 'string') {
18
- if (component.includes('-')) {
19
- return titleCase(component);
20
- }
21
-
22
- return component;
23
- }
24
-
25
- if (component.__docgenInfo && component.__docgenInfo.displayName) {
26
- return component.__docgenInfo.displayName;
27
- }
28
-
29
- return component.name;
30
- };
31
-
32
- exports.getComponentName = getComponentName;
33
-
34
- function scrollToElement(element, block = 'start') {
35
- element.scrollIntoView({
36
- behavior: 'smooth',
37
- block,
38
- inline: 'nearest'
39
- });
40
- }
@@ -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
- };