@storybook/addon-docs 6.5.9 → 7.0.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (160) hide show
  1. package/blocks.d.ts +1 -1
  2. package/dist/cjs/blocks/Anchor.js +7 -10
  3. package/dist/cjs/blocks/ArgsTable.js +135 -206
  4. package/dist/cjs/blocks/Canvas.js +38 -73
  5. package/dist/cjs/blocks/Description.js +41 -68
  6. package/dist/cjs/blocks/DocsContainer.js +40 -68
  7. package/dist/cjs/blocks/DocsContext.js +1 -1
  8. package/dist/cjs/blocks/DocsPage.js +3 -5
  9. package/dist/cjs/blocks/DocsStory.js +18 -28
  10. package/dist/cjs/blocks/Heading.js +5 -9
  11. package/dist/cjs/blocks/Meta.js +11 -33
  12. package/dist/cjs/blocks/Preview.js +4 -10
  13. package/dist/cjs/blocks/Primary.js +12 -40
  14. package/dist/cjs/blocks/Props.js +4 -10
  15. package/dist/cjs/blocks/Source.js +62 -80
  16. package/dist/cjs/blocks/SourceContainer.js +19 -68
  17. package/dist/cjs/blocks/Stories.js +17 -48
  18. package/dist/cjs/blocks/Story.js +60 -180
  19. package/dist/cjs/blocks/Subheading.js +5 -9
  20. package/dist/cjs/blocks/Subtitle.js +15 -35
  21. package/dist/cjs/blocks/Title.js +12 -36
  22. package/dist/cjs/blocks/Wrapper.js +7 -8
  23. package/dist/cjs/blocks/enhanceSource.js +30 -67
  24. package/dist/cjs/blocks/index.js +28 -34
  25. package/dist/cjs/blocks/mdx.js +86 -97
  26. package/dist/cjs/blocks/types.js +2 -2
  27. package/dist/cjs/blocks/useStory.js +16 -87
  28. package/dist/cjs/blocks/utils.js +4 -25
  29. package/dist/cjs/index.js +1 -7
  30. package/dist/cjs/manager.js +9 -15
  31. package/dist/cjs/preset.js +129 -193
  32. package/dist/cjs/preview.js +5 -87
  33. package/dist/cjs/shared.js +5 -5
  34. package/dist/esm/blocks/Anchor.js +7 -10
  35. package/dist/esm/blocks/ArgsTable.js +133 -182
  36. package/dist/esm/blocks/Canvas.js +34 -46
  37. package/dist/esm/blocks/Description.js +39 -45
  38. package/dist/esm/blocks/DocsContainer.js +36 -44
  39. package/dist/esm/blocks/DocsContext.js +1 -1
  40. package/dist/esm/blocks/DocsPage.js +3 -5
  41. package/dist/esm/blocks/DocsStory.js +18 -27
  42. package/dist/esm/blocks/Heading.js +5 -7
  43. package/dist/esm/blocks/Meta.js +9 -13
  44. package/dist/esm/blocks/Preview.js +5 -10
  45. package/dist/esm/blocks/Primary.js +10 -16
  46. package/dist/esm/blocks/Props.js +5 -10
  47. package/dist/esm/blocks/Source.js +64 -70
  48. package/dist/esm/blocks/SourceContainer.js +17 -50
  49. package/dist/esm/blocks/Stories.js +15 -27
  50. package/dist/esm/blocks/Story.js +58 -151
  51. package/dist/esm/blocks/Subheading.js +5 -7
  52. package/dist/esm/blocks/Subtitle.js +12 -12
  53. package/dist/esm/blocks/Title.js +10 -11
  54. package/dist/esm/blocks/Wrapper.js +7 -8
  55. package/dist/esm/blocks/enhanceSource.js +32 -56
  56. package/dist/esm/blocks/mdx.js +85 -89
  57. package/dist/esm/blocks/types.js +2 -2
  58. package/dist/esm/blocks/useStory.js +16 -73
  59. package/dist/esm/blocks/utils.js +4 -18
  60. package/dist/esm/manager.js +9 -14
  61. package/dist/esm/preset.js +114 -179
  62. package/dist/esm/preview.js +3 -61
  63. package/dist/esm/shared.js +5 -5
  64. package/dist/{ts3.9 → types}/blocks/Anchor.d.ts +0 -0
  65. package/dist/{ts3.9 → types}/blocks/ArgsTable.d.ts +0 -0
  66. package/dist/{ts3.9 → types}/blocks/Canvas.d.ts +0 -0
  67. package/dist/{ts3.9 → types}/blocks/Description.d.ts +0 -0
  68. package/dist/{ts3.9 → types}/blocks/DocsContainer.d.ts +0 -0
  69. package/dist/{ts3.9 → types}/blocks/DocsContext.d.ts +0 -0
  70. package/dist/{ts3.9 → types}/blocks/DocsPage.d.ts +0 -0
  71. package/dist/{ts3.9 → types}/blocks/DocsStory.d.ts +0 -0
  72. package/dist/{ts3.9 → types}/blocks/Heading.d.ts +0 -0
  73. package/dist/{ts3.9 → types}/blocks/Meta.d.ts +0 -0
  74. package/dist/{ts3.9 → types}/blocks/Preview.d.ts +0 -0
  75. package/dist/{ts3.9 → types}/blocks/Primary.d.ts +0 -0
  76. package/dist/{ts3.9 → types}/blocks/Props.d.ts +0 -0
  77. package/dist/{ts3.9 → types}/blocks/Source.d.ts +0 -0
  78. package/dist/{ts3.9 → types}/blocks/SourceContainer.d.ts +0 -0
  79. package/dist/{ts3.9 → types}/blocks/Stories.d.ts +0 -0
  80. package/dist/{ts3.9 → types}/blocks/Story.d.ts +2 -2
  81. package/dist/{ts3.9 → types}/blocks/Subheading.d.ts +0 -0
  82. package/dist/{ts3.9 → types}/blocks/Subtitle.d.ts +0 -0
  83. package/dist/{ts3.9 → types}/blocks/Title.d.ts +0 -0
  84. package/dist/{ts3.9 → types}/blocks/Wrapper.d.ts +0 -0
  85. package/dist/{ts3.9 → types}/blocks/enhanceSource.d.ts +0 -0
  86. package/dist/{ts3.9 → types}/blocks/index.d.ts +0 -0
  87. package/dist/{ts3.9 → types}/blocks/mdx.d.ts +0 -0
  88. package/dist/{ts3.9 → types}/blocks/types.d.ts +0 -0
  89. package/dist/{ts3.9 → types}/blocks/useStory.d.ts +0 -0
  90. package/dist/{ts3.9 → types}/blocks/utils.d.ts +0 -0
  91. package/dist/{ts3.9 → types}/index.d.ts +0 -0
  92. package/dist/{ts3.9 → types}/manager.d.ts +0 -0
  93. package/dist/{ts3.9 → types}/preset.d.ts +2 -1
  94. package/dist/{ts3.9 → types}/preview.d.ts +0 -0
  95. package/dist/{ts3.9 → types}/shared.d.ts +0 -0
  96. package/package.json +17 -24
  97. package/dist/modern/blocks/Anchor.js +0 -8
  98. package/dist/modern/blocks/ArgsTable.js +0 -292
  99. package/dist/modern/blocks/Canvas.js +0 -83
  100. package/dist/modern/blocks/Description.js +0 -107
  101. package/dist/modern/blocks/DocsContainer.js +0 -98
  102. package/dist/modern/blocks/DocsContext.js +0 -16
  103. package/dist/modern/blocks/DocsPage.js +0 -11
  104. package/dist/modern/blocks/DocsStory.js +0 -48
  105. package/dist/modern/blocks/Heading.js +0 -17
  106. package/dist/modern/blocks/Meta.js +0 -31
  107. package/dist/modern/blocks/Preview.js +0 -9
  108. package/dist/modern/blocks/Primary.js +0 -23
  109. package/dist/modern/blocks/Props.js +0 -14
  110. package/dist/modern/blocks/Source.js +0 -154
  111. package/dist/modern/blocks/SourceContainer.js +0 -44
  112. package/dist/modern/blocks/Stories.js +0 -34
  113. package/dist/modern/blocks/Story.js +0 -168
  114. package/dist/modern/blocks/Subheading.js +0 -17
  115. package/dist/modern/blocks/Subtitle.js +0 -23
  116. package/dist/modern/blocks/Title.js +0 -24
  117. package/dist/modern/blocks/Wrapper.js +0 -8
  118. package/dist/modern/blocks/enhanceSource.js +0 -89
  119. package/dist/modern/blocks/index.js +0 -24
  120. package/dist/modern/blocks/mdx.js +0 -204
  121. package/dist/modern/blocks/types.js +0 -2
  122. package/dist/modern/blocks/useStory.js +0 -28
  123. package/dist/modern/blocks/utils.js +0 -29
  124. package/dist/modern/index.js +0 -1
  125. package/dist/modern/manager.js +0 -16
  126. package/dist/modern/preset.js +0 -130
  127. package/dist/modern/preview.js +0 -6
  128. package/dist/modern/shared.js +0 -11
  129. package/dist/ts3.4/blocks/Anchor.d.ts +0 -6
  130. package/dist/ts3.4/blocks/ArgsTable.d.ts +0 -33
  131. package/dist/ts3.4/blocks/Canvas.d.ts +0 -9
  132. package/dist/ts3.4/blocks/Description.d.ts +0 -20
  133. package/dist/ts3.4/blocks/DocsContainer.d.ts +0 -7
  134. package/dist/ts3.4/blocks/DocsContext.d.ts +0 -5
  135. package/dist/ts3.4/blocks/DocsPage.d.ts +0 -2
  136. package/dist/ts3.4/blocks/DocsStory.d.ts +0 -3
  137. package/dist/ts3.4/blocks/Heading.d.ts +0 -6
  138. package/dist/ts3.4/blocks/Meta.d.ts +0 -9
  139. package/dist/ts3.4/blocks/Preview.d.ts +0 -3
  140. package/dist/ts3.4/blocks/Primary.d.ts +0 -6
  141. package/dist/ts3.4/blocks/Props.d.ts +0 -3
  142. package/dist/ts3.4/blocks/Source.d.ts +0 -38
  143. package/dist/ts3.4/blocks/SourceContainer.d.ts +0 -14
  144. package/dist/ts3.4/blocks/Stories.d.ts +0 -7
  145. package/dist/ts3.4/blocks/Story.d.ts +0 -28
  146. package/dist/ts3.4/blocks/Subheading.d.ts +0 -3
  147. package/dist/ts3.4/blocks/Subtitle.d.ts +0 -6
  148. package/dist/ts3.4/blocks/Title.d.ts +0 -8
  149. package/dist/ts3.4/blocks/Wrapper.d.ts +0 -2
  150. package/dist/ts3.4/blocks/enhanceSource.d.ts +0 -3
  151. package/dist/ts3.4/blocks/index.d.ts +0 -24
  152. package/dist/ts3.4/blocks/mdx.d.ts +0 -20
  153. package/dist/ts3.4/blocks/types.d.ts +0 -13
  154. package/dist/ts3.4/blocks/useStory.d.ts +0 -5
  155. package/dist/ts3.4/blocks/utils.d.ts +0 -3
  156. package/dist/ts3.4/index.d.ts +0 -1
  157. package/dist/ts3.4/manager.d.ts +0 -1
  158. package/dist/ts3.4/preset.d.ts +0 -11
  159. package/dist/ts3.4/preview.d.ts +0 -6
  160. package/dist/ts3.4/shared.d.ts +0 -24
@@ -1,36 +1,4 @@
1
- function _extends() { _extends = Object.assign || 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
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
-
5
- import "core-js/modules/es.array.includes.js";
6
- import "core-js/modules/es.string.includes.js";
7
- import "core-js/modules/es.object.assign.js";
8
- import "core-js/modules/es.array.sort.js";
9
- import "core-js/modules/es.array.find.js";
10
- import "core-js/modules/es.object.to-string.js";
11
- import "core-js/modules/es.object.values.js";
12
- import "core-js/modules/es.symbol.js";
13
- import "core-js/modules/es.symbol.description.js";
14
- import "core-js/modules/es.symbol.iterator.js";
15
- import "core-js/modules/es.array.iterator.js";
16
- import "core-js/modules/es.string.iterator.js";
17
- import "core-js/modules/web.dom-collections.iterator.js";
18
- import "core-js/modules/es.array.slice.js";
19
- import "core-js/modules/es.function.name.js";
20
- import "core-js/modules/es.array.from.js";
21
- import "core-js/modules/es.regexp.exec.js";
22
-
23
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
24
-
25
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
26
-
27
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
28
-
29
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
30
-
31
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
32
-
33
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
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); }
34
2
 
35
3
  import React, { useContext, useEffect, useState, useCallback } from 'react';
36
4
  import mapValues from 'lodash/mapValues';
@@ -44,111 +12,93 @@ import { getComponentName } from './utils';
44
12
  import { lookupStoryId } from './Story';
45
13
  import { useStory } from './useStory';
46
14
 
47
- var getContext = function getContext(storyId, context) {
48
- var story = context.storyById(storyId);
15
+ const getContext = (storyId, context) => {
16
+ const story = context.storyById(storyId);
49
17
 
50
18
  if (!story) {
51
- throw new Error("Unknown story: ".concat(storyId));
19
+ throw new Error(`Unknown story: ${storyId}`);
52
20
  }
53
21
 
54
22
  return context.getStoryContext(story);
55
23
  };
56
24
 
57
- var useArgs = function useArgs(storyId, context) {
58
- var channel = addons.getChannel();
59
- var storyContext = getContext(storyId, context);
60
-
61
- var _useState = useState(storyContext.args),
62
- _useState2 = _slicedToArray(_useState, 2),
63
- args = _useState2[0],
64
- setArgs = _useState2[1];
65
-
66
- useEffect(function () {
67
- var cb = function cb(changed) {
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 => {
68
31
  if (changed.storyId === storyId) {
69
32
  setArgs(changed.args);
70
33
  }
71
34
  };
72
35
 
73
36
  channel.on(Events.STORY_ARGS_UPDATED, cb);
74
- return function () {
75
- return channel.off(Events.STORY_ARGS_UPDATED, cb);
76
- };
77
- }, [storyId]);
78
- var updateArgs = useCallback(function (updatedArgs) {
79
- return channel.emit(Events.UPDATE_STORY_ARGS, {
80
- storyId: storyId,
81
- updatedArgs: updatedArgs
82
- });
83
- }, [storyId]);
84
- var resetArgs = useCallback(function (argNames) {
85
- return channel.emit(Events.RESET_STORY_ARGS, {
86
- storyId: storyId,
87
- argNames: argNames
88
- });
37
+ return () => channel.off(Events.STORY_ARGS_UPDATED, cb);
89
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]);
90
47
  return [args, updateArgs, resetArgs];
91
48
  };
92
49
 
93
- var useGlobals = function useGlobals(storyId, context) {
94
- var channel = addons.getChannel();
95
- var storyContext = getContext(storyId, context);
96
-
97
- var _useState3 = useState(storyContext.globals),
98
- _useState4 = _slicedToArray(_useState3, 2),
99
- globals = _useState4[0],
100
- setGlobals = _useState4[1];
101
-
102
- useEffect(function () {
103
- var cb = function cb(changed) {
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 => {
104
56
  setGlobals(changed.globals);
105
57
  };
106
58
 
107
59
  channel.on(Events.GLOBALS_UPDATED, cb);
108
- return function () {
109
- return channel.off(Events.GLOBALS_UPDATED, cb);
110
- };
60
+ return () => channel.off(Events.GLOBALS_UPDATED, cb);
111
61
  }, []);
112
62
  return [globals];
113
63
  };
114
64
 
115
- export var extractComponentArgTypes = function extractComponentArgTypes(component, _ref, include, exclude) {
116
- var id = _ref.id,
117
- storyById = _ref.storyById;
118
-
119
- var _storyById = storyById(id),
120
- parameters = _storyById.parameters;
121
-
122
- var _ref2 = parameters.docs || {},
123
- extractArgTypes = _ref2.extractArgTypes;
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 || {};
124
75
 
125
76
  if (!extractArgTypes) {
126
77
  throw new Error(ArgsTableError.ARGS_UNSUPPORTED);
127
78
  }
128
79
 
129
- var argTypes = extractArgTypes(component);
80
+ let argTypes = extractArgTypes(component);
130
81
  argTypes = filterArgTypes(argTypes, include, exclude);
131
82
  return argTypes;
132
83
  };
133
84
 
134
- var isShortcut = function isShortcut(value) {
85
+ const isShortcut = value => {
135
86
  return value && [CURRENT_SELECTION, PRIMARY_STORY].includes(value);
136
87
  };
137
88
 
138
- export var getComponent = function getComponent() {
139
- var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
140
-
141
- var _ref3 = arguments.length > 1 ? arguments[1] : undefined,
142
- id = _ref3.id,
143
- storyById = _ref3.storyById;
144
-
145
- var _ref4 = props,
146
- of = _ref4.of;
147
- var _ref5 = props,
148
- story = _ref5.story;
149
-
150
- var _storyById2 = storyById(id),
151
- component = _storyById2.component;
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);
152
102
 
153
103
  if (isShortcut(of) || isShortcut(story)) {
154
104
  return component || null;
@@ -161,29 +111,29 @@ export var getComponent = function getComponent() {
161
111
  return of;
162
112
  };
163
113
 
164
- var addComponentTabs = function addComponentTabs(tabs, components, context, include, exclude, sort) {
165
- return Object.assign({}, tabs, mapValues(components, function (comp) {
166
- return {
167
- rows: extractComponentArgTypes(comp, context, include, exclude),
168
- sort: sort
169
- };
170
- }));
171
- };
172
-
173
- export var StoryTable = function StoryTable(props) {
174
- var context = useContext(DocsContext);
175
- var currentId = context.id,
176
- componentStories = context.componentStories;
177
- var storyName = props.story,
178
- component = props.component,
179
- subcomponents = props.subcomponents,
180
- showComponent = props.showComponent,
181
- include = props.include,
182
- exclude = props.exclude,
183
- sort = props.sort;
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;
184
134
 
185
135
  try {
186
- var storyId;
136
+ let storyId;
187
137
 
188
138
  switch (storyName) {
189
139
  case CURRENT_SELECTION:
@@ -194,7 +144,7 @@ export var StoryTable = function StoryTable(props) {
194
144
 
195
145
  case PRIMARY_STORY:
196
146
  {
197
- var primaryStory = componentStories()[0];
147
+ const primaryStory = componentStories()[0];
198
148
  storyId = primaryStory.id;
199
149
  break;
200
150
  }
@@ -205,38 +155,28 @@ export var StoryTable = function StoryTable(props) {
205
155
  }
206
156
  }
207
157
 
208
- var story = useStory(storyId, context); // eslint-disable-next-line prefer-const
209
-
210
- var _useArgs = useArgs(storyId, context),
211
- _useArgs2 = _slicedToArray(_useArgs, 3),
212
- args = _useArgs2[0],
213
- updateArgs = _useArgs2[1],
214
- resetArgs = _useArgs2[2];
215
-
216
- var _useGlobals = useGlobals(storyId, context),
217
- _useGlobals2 = _slicedToArray(_useGlobals, 1),
218
- globals = _useGlobals2[0];
158
+ const story = useStory(storyId, context); // eslint-disable-next-line prefer-const
219
159
 
160
+ let [args, updateArgs, resetArgs] = useArgs(storyId, context);
161
+ const [globals] = useGlobals(storyId, context);
220
162
  if (!story) return /*#__PURE__*/React.createElement(PureArgsTable, {
221
163
  isLoading: true,
222
164
  updateArgs: updateArgs,
223
165
  resetArgs: resetArgs
224
166
  });
225
- var argTypes = filterArgTypes(story.argTypes, include, exclude);
226
- var mainLabel = getComponentName(component) || 'Story';
227
-
228
- var tabs = _defineProperty({}, mainLabel, {
229
- rows: argTypes,
230
- args: args,
231
- globals: globals,
232
- updateArgs: updateArgs,
233
- resetArgs: resetArgs
234
- }); // Use the dynamically generated component tabs if there are no controls
235
-
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
236
178
 
237
- var storyHasArgsWithControls = argTypes && Object.values(argTypes).find(function (v) {
238
- return !!(v !== null && v !== void 0 && v.control);
239
- });
179
+ const storyHasArgsWithControls = argTypes && Object.values(argTypes).find(v => !!v?.control);
240
180
 
241
181
  if (!storyHasArgsWithControls) {
242
182
  updateArgs = null;
@@ -245,12 +185,14 @@ export var StoryTable = function StoryTable(props) {
245
185
  }
246
186
 
247
187
  if (component && (!storyHasArgsWithControls || showComponent)) {
248
- tabs = addComponentTabs(tabs, _defineProperty({}, mainLabel, component), context, include, exclude);
188
+ tabs = addComponentTabs(tabs, {
189
+ [mainLabel]: component
190
+ }, context, include, exclude);
249
191
  }
250
192
 
251
193
  if (subcomponents) {
252
194
  if (Array.isArray(subcomponents)) {
253
- throw new Error("Unexpected subcomponents array. Expected an object whose keys are tab labels and whose values are components.");
195
+ throw new Error(`Unexpected subcomponents array. Expected an object whose keys are tab labels and whose values are components.`);
254
196
  }
255
197
 
256
198
  tabs = addComponentTabs(tabs, subcomponents, context, include, exclude);
@@ -266,47 +208,54 @@ export var StoryTable = function StoryTable(props) {
266
208
  });
267
209
  }
268
210
  };
269
- export var ComponentsTable = function ComponentsTable(props) {
270
- var context = useContext(DocsContext);
271
- var components = props.components,
272
- include = props.include,
273
- exclude = props.exclude,
274
- sort = props.sort;
275
- var tabs = addComponentTabs({}, components, context, include, exclude);
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);
276
220
  return /*#__PURE__*/React.createElement(TabbedArgsTable, {
277
221
  tabs: tabs,
278
222
  sort: sort
279
223
  });
280
224
  };
281
- export var ArgsTable = function ArgsTable(props) {
282
- var context = useContext(DocsContext);
283
- var id = context.id,
284
- storyById = context.storyById;
285
-
286
- var _storyById3 = storyById(id),
287
- controls = _storyById3.parameters.controls,
288
- subcomponents = _storyById3.subcomponents;
289
-
290
- var _ref6 = props,
291
- include = _ref6.include,
292
- exclude = _ref6.exclude,
293
- components = _ref6.components,
294
- sortProp = _ref6.sort;
295
- var _ref7 = props,
296
- storyName = _ref7.story;
297
- var sort = sortProp || (controls === null || controls === void 0 ? void 0 : controls.sort);
298
- var main = getComponent(props, context);
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);
299
248
 
300
249
  if (storyName) {
301
250
  return /*#__PURE__*/React.createElement(StoryTable, _extends({}, props, {
302
251
  component: main,
303
- subcomponents: subcomponents,
304
- sort: sort
252
+ subcomponents,
253
+ sort
305
254
  }));
306
255
  }
307
256
 
308
257
  if (!components && !subcomponents) {
309
- var mainProps;
258
+ let mainProps;
310
259
 
311
260
  try {
312
261
  mainProps = {
@@ -325,14 +274,16 @@ export var ArgsTable = function ArgsTable(props) {
325
274
 
326
275
  if (components) {
327
276
  return /*#__PURE__*/React.createElement(ComponentsTable, _extends({}, props, {
328
- components: components,
329
- sort: sort
277
+ components,
278
+ sort
330
279
  }));
331
280
  }
332
281
 
333
- var mainLabel = getComponentName(main);
282
+ const mainLabel = getComponentName(main);
334
283
  return /*#__PURE__*/React.createElement(ComponentsTable, _extends({}, props, {
335
- components: Object.assign(_defineProperty({}, mainLabel, main), subcomponents),
284
+ components: Object.assign({
285
+ [mainLabel]: main
286
+ }, subcomponents),
336
287
  sort: sort
337
288
  }));
338
289
  };
@@ -1,13 +1,4 @@
1
- import "core-js/modules/es.object.keys.js";
2
- import "core-js/modules/es.symbol.js";
3
- var _excluded = ["withSource", "mdxSource", "children"];
4
- import "core-js/modules/es.object.assign.js";
5
- import "core-js/modules/es.array.filter.js";
6
- import "core-js/modules/es.object.to-string.js";
7
- import "core-js/modules/es.function.name.js";
8
- import "core-js/modules/es.array.map.js";
9
-
10
- function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
1
+ const _excluded = ["withSource", "mdxSource", "children"];
11
2
 
12
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; }
13
4
 
@@ -22,27 +13,31 @@ import { useStories } from './useStory';
22
13
  import { CURRENT_SELECTION } from './types';
23
14
  export { SourceState };
24
15
 
25
- var getPreviewProps = function getPreviewProps(_ref, docsContext, sourceContext) {
26
- var withSource = _ref.withSource,
27
- mdxSource = _ref.mdxSource,
28
- children = _ref.children,
29
- props = _objectWithoutProperties(_ref, _excluded);
16
+ const getPreviewProps = (_ref, docsContext, sourceContext) => {
17
+ let {
18
+ withSource,
19
+ mdxSource,
20
+ children
21
+ } = _ref,
22
+ props = _objectWithoutPropertiesLoose(_ref, _excluded);
30
23
 
31
- var mdxComponentAnnotations = docsContext.mdxComponentAnnotations,
32
- mdxStoryNameToKey = docsContext.mdxStoryNameToKey;
33
- var sourceState = withSource;
34
- var isLoading = false;
24
+ const {
25
+ mdxComponentAnnotations,
26
+ mdxStoryNameToKey
27
+ } = docsContext;
28
+ let sourceState = withSource;
29
+ let isLoading = false;
35
30
 
36
31
  if (sourceState === SourceState.NONE) {
37
32
  return {
38
- isLoading: isLoading,
33
+ isLoading,
39
34
  previewProps: props
40
35
  };
41
36
  }
42
37
 
43
38
  if (mdxSource) {
44
39
  return {
45
- isLoading: isLoading,
40
+ isLoading,
46
41
  previewProps: Object.assign({}, props, {
47
42
  withSource: getSourceProps({
48
43
  code: decodeURI(mdxSource)
@@ -51,26 +46,18 @@ var getPreviewProps = function getPreviewProps(_ref, docsContext, sourceContext)
51
46
  };
52
47
  }
53
48
 
54
- var childArray = Array.isArray(children) ? children : [children];
55
- var storyChildren = childArray.filter(function (c) {
56
- return c.props && (c.props.id || c.props.name);
57
- });
58
- var targetIds = storyChildren.map(function (s) {
59
- return s.props.id || toId(mdxComponentAnnotations.id || mdxComponentAnnotations.title, storyNameFromExport(mdxStoryNameToKey[s.props.name]));
60
- });
61
- var sourceProps = getSourceProps({
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({
62
53
  ids: targetIds
63
54
  }, docsContext, sourceContext);
64
55
  if (!sourceState) sourceState = sourceProps.state;
65
- var storyIds = targetIds.map(function (targetId) {
66
- return targetId === CURRENT_SELECTION ? docsContext.id : targetId;
67
- });
68
- var stories = useStories(storyIds, docsContext);
69
- isLoading = stories.some(function (s) {
70
- return !s;
71
- });
56
+ const storyIds = targetIds.map(targetId => targetId === CURRENT_SELECTION ? docsContext.id : targetId);
57
+ const stories = useStories(storyIds, docsContext);
58
+ isLoading = stories.some(s => !s);
72
59
  return {
73
- isLoading: isLoading,
60
+ isLoading,
74
61
  previewProps: Object.assign({}, props, {
75
62
  // pass through columns etc.
76
63
  withSource: sourceProps,
@@ -79,15 +66,16 @@ var getPreviewProps = function getPreviewProps(_ref, docsContext, sourceContext)
79
66
  };
80
67
  };
81
68
 
82
- export var Canvas = function Canvas(props) {
83
- var docsContext = useContext(DocsContext);
84
- var sourceContext = useContext(SourceContext);
85
-
86
- var _getPreviewProps = getPreviewProps(props, docsContext, sourceContext),
87
- isLoading = _getPreviewProps.isLoading,
88
- previewProps = _getPreviewProps.previewProps;
89
-
90
- var children = props.children;
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;
91
79
  if (isLoading) return /*#__PURE__*/React.createElement(PreviewSkeleton, null);
92
80
  return /*#__PURE__*/React.createElement(MDXProvider, {
93
81
  components: resetComponents