@storybook/addon-docs 7.0.0-alpha.3 → 7.0.0-alpha.33

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 (104) hide show
  1. package/README.md +12 -13
  2. package/angular/index.js +1 -1
  3. package/blocks.js +1 -1
  4. package/dist/cjs/DocsRenderer.js +52 -0
  5. package/dist/cjs/blocks/index.js +4 -352
  6. package/dist/cjs/index.js +13 -1
  7. package/dist/cjs/preset.js +20 -5
  8. package/dist/cjs/preview.js +6 -2
  9. package/dist/esm/DocsRenderer.js +34 -0
  10. package/dist/esm/blocks/index.js +1 -24
  11. package/dist/esm/index.js +2 -1
  12. package/dist/esm/preset.js +15 -3
  13. package/dist/esm/preview.js +6 -2
  14. package/dist/types/DocsRenderer.d.ts +8 -0
  15. package/dist/types/blocks/index.d.ts +1 -24
  16. package/dist/types/index.d.ts +1 -0
  17. package/dist/types/preset.d.ts +8 -2
  18. package/dist/types/preview.d.ts +1 -6
  19. package/package.json +25 -24
  20. package/web-components/README.md +1 -0
  21. package/LICENSE +0 -21
  22. package/dist/cjs/blocks/Anchor.js +0 -23
  23. package/dist/cjs/blocks/ArgsTable.js +0 -329
  24. package/dist/cjs/blocks/Canvas.js +0 -109
  25. package/dist/cjs/blocks/Description.js +0 -126
  26. package/dist/cjs/blocks/DocsContainer.js +0 -127
  27. package/dist/cjs/blocks/DocsContext.js +0 -25
  28. package/dist/cjs/blocks/DocsPage.js +0 -30
  29. package/dist/cjs/blocks/DocsStory.js +0 -68
  30. package/dist/cjs/blocks/Heading.js +0 -31
  31. package/dist/cjs/blocks/Meta.js +0 -50
  32. package/dist/cjs/blocks/Preview.js +0 -23
  33. package/dist/cjs/blocks/Primary.js +0 -39
  34. package/dist/cjs/blocks/Props.js +0 -29
  35. package/dist/cjs/blocks/Source.js +0 -179
  36. package/dist/cjs/blocks/SourceContainer.js +0 -67
  37. package/dist/cjs/blocks/Stories.js +0 -51
  38. package/dist/cjs/blocks/Story.js +0 -143
  39. package/dist/cjs/blocks/Subheading.js +0 -31
  40. package/dist/cjs/blocks/Subtitle.js +0 -39
  41. package/dist/cjs/blocks/Title.js +0 -44
  42. package/dist/cjs/blocks/Wrapper.js +0 -20
  43. package/dist/cjs/blocks/enhanceSource.js +0 -92
  44. package/dist/cjs/blocks/mdx.js +0 -234
  45. package/dist/cjs/blocks/types.js +0 -10
  46. package/dist/cjs/blocks/useStory.js +0 -37
  47. package/dist/cjs/blocks/utils.js +0 -40
  48. package/dist/cjs/manager.js +0 -20
  49. package/dist/esm/blocks/Anchor.js +0 -8
  50. package/dist/esm/blocks/ArgsTable.js +0 -292
  51. package/dist/esm/blocks/Canvas.js +0 -83
  52. package/dist/esm/blocks/Description.js +0 -107
  53. package/dist/esm/blocks/DocsContainer.js +0 -98
  54. package/dist/esm/blocks/DocsContext.js +0 -16
  55. package/dist/esm/blocks/DocsPage.js +0 -11
  56. package/dist/esm/blocks/DocsStory.js +0 -46
  57. package/dist/esm/blocks/Heading.js +0 -17
  58. package/dist/esm/blocks/Meta.js +0 -31
  59. package/dist/esm/blocks/Preview.js +0 -9
  60. package/dist/esm/blocks/Primary.js +0 -23
  61. package/dist/esm/blocks/Props.js +0 -14
  62. package/dist/esm/blocks/Source.js +0 -144
  63. package/dist/esm/blocks/SourceContainer.js +0 -44
  64. package/dist/esm/blocks/Stories.js +0 -30
  65. package/dist/esm/blocks/Story.js +0 -114
  66. package/dist/esm/blocks/Subheading.js +0 -17
  67. package/dist/esm/blocks/Subtitle.js +0 -23
  68. package/dist/esm/blocks/Title.js +0 -24
  69. package/dist/esm/blocks/Wrapper.js +0 -8
  70. package/dist/esm/blocks/enhanceSource.js +0 -87
  71. package/dist/esm/blocks/mdx.js +0 -203
  72. package/dist/esm/blocks/types.js +0 -2
  73. package/dist/esm/blocks/useStory.js +0 -27
  74. package/dist/esm/blocks/utils.js +0 -29
  75. package/dist/esm/manager.js +0 -16
  76. package/dist/types/blocks/Anchor.d.ts +0 -6
  77. package/dist/types/blocks/ArgsTable.d.ts +0 -33
  78. package/dist/types/blocks/Canvas.d.ts +0 -9
  79. package/dist/types/blocks/Description.d.ts +0 -20
  80. package/dist/types/blocks/DocsContainer.d.ts +0 -7
  81. package/dist/types/blocks/DocsContext.d.ts +0 -5
  82. package/dist/types/blocks/DocsPage.d.ts +0 -2
  83. package/dist/types/blocks/DocsStory.d.ts +0 -3
  84. package/dist/types/blocks/Heading.d.ts +0 -6
  85. package/dist/types/blocks/Meta.d.ts +0 -9
  86. package/dist/types/blocks/Preview.d.ts +0 -3
  87. package/dist/types/blocks/Primary.d.ts +0 -6
  88. package/dist/types/blocks/Props.d.ts +0 -3
  89. package/dist/types/blocks/Source.d.ts +0 -38
  90. package/dist/types/blocks/SourceContainer.d.ts +0 -14
  91. package/dist/types/blocks/Stories.d.ts +0 -7
  92. package/dist/types/blocks/Story.d.ts +0 -28
  93. package/dist/types/blocks/Subheading.d.ts +0 -3
  94. package/dist/types/blocks/Subtitle.d.ts +0 -6
  95. package/dist/types/blocks/Title.d.ts +0 -8
  96. package/dist/types/blocks/Wrapper.d.ts +0 -2
  97. package/dist/types/blocks/enhanceSource.d.ts +0 -3
  98. package/dist/types/blocks/mdx.d.ts +0 -20
  99. package/dist/types/blocks/types.d.ts +0 -13
  100. package/dist/types/blocks/useStory.d.ts +0 -5
  101. package/dist/types/blocks/utils.d.ts +0 -3
  102. package/dist/types/manager.d.ts +0 -1
  103. package/manager.js +0 -1
  104. package/register.js +0 -6
@@ -45,6 +45,7 @@ export async function webpack(webpackConfig = {}, options) {
45
45
  transcludeMarkdown = false
46
46
  } = options;
47
47
  const mdxLoaderOptions = {
48
+ // whether to skip storybook files, useful for docs only mdx or md files
48
49
  skipCsf: true,
49
50
  remarkPlugins: [remarkSlug, remarkExternalLinks]
50
51
  };
@@ -91,7 +92,10 @@ export async function webpack(webpackConfig = {}, options) {
91
92
  configureJSX
92
93
  })
93
94
  }, {
94
- loader: mdxLoader
95
+ loader: mdxLoader,
96
+ options: Object.assign({}, mdxLoaderOptions, {
97
+ skipCsf: false
98
+ })
95
99
  }]
96
100
  }, {
97
101
  test: /\.mdx$/,
@@ -114,7 +118,7 @@ export async function webpack(webpackConfig = {}, options) {
114
118
  }
115
119
  export const storyIndexers = async indexers => {
116
120
  const mdxIndexer = async (fileName, opts) => {
117
- let code = (await fs.readFile(fileName, 'utf-8')).toString(); // @ts-ignore
121
+ let code = (await fs.readFile(fileName, 'utf-8')).toString(); // @ts-expect-error (Converted from ts-ignore)
118
122
 
119
123
  const {
120
124
  compile
@@ -127,6 +131,14 @@ export const storyIndexers = async indexers => {
127
131
 
128
132
  return [{
129
133
  test: /(stories|story)\.mdx$/,
130
- indexer: mdxIndexer
134
+ indexer: mdxIndexer,
135
+ addDocsTemplate: true
131
136
  }, ...(indexers || [])];
137
+ };
138
+ export const docs = docsOptions => {
139
+ return Object.assign({}, docsOptions, {
140
+ enabled: true,
141
+ defaultName: 'Docs',
142
+ docsPage: true
143
+ });
132
144
  };
@@ -1,6 +1,10 @@
1
1
  export const parameters = {
2
2
  docs: {
3
- getContainer: async () => (await import('./blocks')).DocsContainer,
4
- getPage: async () => (await import('./blocks')).DocsPage
3
+ renderer: async () => {
4
+ const {
5
+ DocsRenderer
6
+ } = await import('./DocsRenderer');
7
+ return new DocsRenderer();
8
+ }
5
9
  }
6
10
  };
@@ -0,0 +1,8 @@
1
+ import { AnyFramework } from '@storybook/csf';
2
+ import { DocsRenderFunction } from '@storybook/preview-web';
3
+ export declare const defaultComponents: Record<string, any>;
4
+ export declare class DocsRenderer<TFramework extends AnyFramework> {
5
+ render: DocsRenderFunction<TFramework>;
6
+ unmount: (element: HTMLElement) => void;
7
+ constructor();
8
+ }
@@ -1,24 +1 @@
1
- export { ColorPalette, ColorItem, IconGallery, IconItem, Typeset } from '@storybook/components';
2
- export * from './Anchor';
3
- export * from './ArgsTable';
4
- export * from './Canvas';
5
- export * from './Description';
6
- export * from './DocsContext';
7
- export * from './DocsPage';
8
- export * from './DocsContainer';
9
- export * from './DocsStory';
10
- export * from './Heading';
11
- export * from './Meta';
12
- export * from './Preview';
13
- export * from './Primary';
14
- export * from './Props';
15
- export * from './Source';
16
- export * from './SourceContainer';
17
- export * from './Stories';
18
- export * from './Story';
19
- export * from './Subheading';
20
- export * from './Subtitle';
21
- export * from './Title';
22
- export * from './Wrapper';
23
- export * from './types';
24
- export * from './mdx';
1
+ export * from '@storybook/blocks';
@@ -1 +1,2 @@
1
1
  export * from './blocks';
2
+ export { DocsRenderer } from './DocsRenderer';
@@ -1,4 +1,4 @@
1
- import type { Options, StoryIndexer } from '@storybook/core-common';
1
+ import type { DocsOptions, Options, StoryIndexer } from '@storybook/core-common';
2
2
  declare type BabelParams = {
3
3
  babelOptions?: any;
4
4
  mdxBabelOptions?: any;
@@ -8,5 +8,11 @@ export declare function webpack(webpackConfig: any, options: Options & BabelPara
8
8
  sourceLoaderOptions: any;
9
9
  transcludeMarkdown: boolean;
10
10
  }): Promise<any>;
11
- export declare const storyIndexers: (indexers?: StoryIndexer[]) => Promise<StoryIndexer[]>;
11
+ export declare const storyIndexers: (indexers: StoryIndexer[] | null) => Promise<StoryIndexer[]>;
12
+ export declare const docs: (docsOptions: DocsOptions) => {
13
+ enabled: boolean;
14
+ defaultName: string;
15
+ docsPage: boolean;
16
+ docsMode?: boolean;
17
+ };
12
18
  export {};
@@ -1,6 +1 @@
1
- export declare const parameters: {
2
- docs: {
3
- getContainer: () => Promise<import("react").FunctionComponent<import("./blocks").DocsContainerProps<import("@storybook/csf").AnyFramework>>>;
4
- getPage: () => Promise<import("react").FC<{}>>;
5
- };
6
- };
1
+ export declare const parameters: any;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-docs",
3
- "version": "7.0.0-alpha.3",
3
+ "version": "7.0.0-alpha.33",
4
4
  "description": "Document component usage and properties in Markdown",
5
5
  "keywords": [
6
6
  "addon",
@@ -45,34 +45,34 @@
45
45
  "!__testfixtures__"
46
46
  ],
47
47
  "scripts": {
48
- "prepare": "node ../../scripts/prepare.js"
48
+ "check": "tsc --noEmit",
49
+ "prep": "node ../../../scripts/prepare.js"
49
50
  },
50
51
  "dependencies": {
51
52
  "@babel/plugin-transform-react-jsx": "^7.12.12",
52
53
  "@babel/preset-env": "^7.12.11",
53
54
  "@jest/transform": "^26.6.2",
54
55
  "@mdx-js/react": "^1.6.22",
55
- "@storybook/addons": "7.0.0-alpha.3",
56
- "@storybook/api": "7.0.0-alpha.3",
57
- "@storybook/components": "7.0.0-alpha.3",
58
- "@storybook/core-common": "7.0.0-alpha.3",
59
- "@storybook/core-events": "7.0.0-alpha.3",
60
- "@storybook/csf": "0.0.2--canary.4566f4d.1",
61
- "@storybook/csf-tools": "7.0.0-alpha.3",
62
- "@storybook/docs-tools": "7.0.0-alpha.3",
63
- "@storybook/mdx1-csf": "^0.0.1",
64
- "@storybook/node-logger": "7.0.0-alpha.3",
65
- "@storybook/postinstall": "7.0.0-alpha.3",
66
- "@storybook/preview-web": "7.0.0-alpha.3",
67
- "@storybook/source-loader": "7.0.0-alpha.3",
68
- "@storybook/store": "7.0.0-alpha.3",
69
- "@storybook/theming": "7.0.0-alpha.3",
56
+ "@storybook/addons": "7.0.0-alpha.33",
57
+ "@storybook/api": "7.0.0-alpha.33",
58
+ "@storybook/blocks": "7.0.0-alpha.33",
59
+ "@storybook/components": "7.0.0-alpha.33",
60
+ "@storybook/core-common": "7.0.0-alpha.33",
61
+ "@storybook/core-events": "7.0.0-alpha.33",
62
+ "@storybook/csf": "0.0.2--canary.0899bb7.0",
63
+ "@storybook/csf-tools": "7.0.0-alpha.33",
64
+ "@storybook/docs-tools": "7.0.0-alpha.33",
65
+ "@storybook/mdx1-csf": "0.0.5-canary.13.9ce928a.0",
66
+ "@storybook/node-logger": "7.0.0-alpha.33",
67
+ "@storybook/postinstall": "7.0.0-alpha.33",
68
+ "@storybook/preview-web": "7.0.0-alpha.33",
69
+ "@storybook/source-loader": "7.0.0-alpha.33",
70
+ "@storybook/store": "7.0.0-alpha.33",
71
+ "@storybook/theming": "7.0.0-alpha.33",
70
72
  "babel-loader": "^8.2.5",
71
- "core-js": "^3.8.2",
72
- "fast-deep-equal": "^3.1.3",
73
+ "dequal": "^2.0.2",
73
74
  "global": "^4.4.0",
74
75
  "lodash": "^4.17.21",
75
- "regenerator-runtime": "^0.13.7",
76
76
  "remark-external-links": "^8.0.0",
77
77
  "remark-slug": "^6.0.0",
78
78
  "ts-dedent": "^2.0.0",
@@ -80,11 +80,12 @@
80
80
  },
81
81
  "devDependencies": {
82
82
  "@babel/core": "^7.12.10",
83
- "@storybook/mdx2-csf": "^0.0.3",
84
- "@types/util-deprecate": "^1.0.0"
83
+ "@storybook/mdx2-csf": "0.0.4-canary.14.04ffbe8.0",
84
+ "@types/util-deprecate": "^1.0.0",
85
+ "typescript": "~4.6.3"
85
86
  },
86
87
  "peerDependencies": {
87
- "@storybook/mdx2-csf": "^0.0.3",
88
+ "@storybook/mdx2-csf": "0.0.4-canary.14.04ffbe8.0",
88
89
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
89
90
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
90
91
  },
@@ -102,7 +103,7 @@
102
103
  "publishConfig": {
103
104
  "access": "public"
104
105
  },
105
- "gitHead": "629b056190993bcee6445471b8cb27208eb401a9",
106
+ "gitHead": "5da5b0fabd04cc5cd5771e8242a960f05d03234a",
106
107
  "storybook": {
107
108
  "displayName": "Docs",
108
109
  "icon": "https://user-images.githubusercontent.com/263385/101991672-48355c80-3c7c-11eb-82d9-95fa12438f64.png",
@@ -39,6 +39,7 @@ Known analyzers that output `custom-elements.json` v1.0.0:
39
39
  - Supports Vanilla, LitElement, FASTElement, Stencil, Catalyst, Atomico
40
40
 
41
41
  Known analyzers that output older versions of `custom-elements.json`:
42
+
42
43
  - [web-component-analyzer](https://github.com/runem/web-component-analyzer)
43
44
  - Supports LitElement, Polymer, Vanilla, (Stencil)
44
45
  - [stenciljs](https://stenciljs.com/)
package/LICENSE DELETED
@@ -1,21 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2017 Kadira Inc. <hello@kadira.io>
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in
13
- all copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
- THE SOFTWARE.
@@ -1,23 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.anchorBlockIdFromId = exports.Anchor = void 0;
7
-
8
- var _react = _interopRequireDefault(require("react"));
9
-
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
-
12
- const anchorBlockIdFromId = storyId => `anchor--${storyId}`;
13
-
14
- exports.anchorBlockIdFromId = anchorBlockIdFromId;
15
-
16
- const Anchor = ({
17
- storyId,
18
- children
19
- }) => /*#__PURE__*/_react.default.createElement("div", {
20
- id: anchorBlockIdFromId(storyId)
21
- }, children);
22
-
23
- exports.Anchor = Anchor;
@@ -1,329 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getComponent = exports.extractComponentArgTypes = exports.StoryTable = exports.ComponentsTable = exports.ArgsTable = void 0;
7
-
8
- var _react = _interopRequireWildcard(require("react"));
9
-
10
- var _mapValues = _interopRequireDefault(require("lodash/mapValues"));
11
-
12
- var _components = require("@storybook/components");
13
-
14
- var _addons = require("@storybook/addons");
15
-
16
- var _store = require("@storybook/store");
17
-
18
- var _coreEvents = _interopRequireDefault(require("@storybook/core-events"));
19
-
20
- var _DocsContext = require("./DocsContext");
21
-
22
- var _types = require("./types");
23
-
24
- var _utils = require("./utils");
25
-
26
- var _Story = require("./Story");
27
-
28
- var _useStory = require("./useStory");
29
-
30
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
-
32
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
33
-
34
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
35
-
36
- 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); }
37
-
38
- const getContext = (storyId, context) => {
39
- const story = context.storyById(storyId);
40
-
41
- if (!story) {
42
- throw new Error(`Unknown story: ${storyId}`);
43
- }
44
-
45
- return context.getStoryContext(story);
46
- };
47
-
48
- const useArgs = (storyId, context) => {
49
- const channel = _addons.addons.getChannel();
50
-
51
- const storyContext = getContext(storyId, context);
52
- const [args, setArgs] = (0, _react.useState)(storyContext.args);
53
- (0, _react.useEffect)(() => {
54
- const cb = changed => {
55
- if (changed.storyId === storyId) {
56
- setArgs(changed.args);
57
- }
58
- };
59
-
60
- channel.on(_coreEvents.default.STORY_ARGS_UPDATED, cb);
61
- return () => channel.off(_coreEvents.default.STORY_ARGS_UPDATED, cb);
62
- }, [storyId]);
63
- const updateArgs = (0, _react.useCallback)(updatedArgs => channel.emit(_coreEvents.default.UPDATE_STORY_ARGS, {
64
- storyId,
65
- updatedArgs
66
- }), [storyId]);
67
- const resetArgs = (0, _react.useCallback)(argNames => channel.emit(_coreEvents.default.RESET_STORY_ARGS, {
68
- storyId,
69
- argNames
70
- }), [storyId]);
71
- return [args, updateArgs, resetArgs];
72
- };
73
-
74
- const useGlobals = (storyId, context) => {
75
- const channel = _addons.addons.getChannel();
76
-
77
- const storyContext = getContext(storyId, context);
78
- const [globals, setGlobals] = (0, _react.useState)(storyContext.globals);
79
- (0, _react.useEffect)(() => {
80
- const cb = changed => {
81
- setGlobals(changed.globals);
82
- };
83
-
84
- channel.on(_coreEvents.default.GLOBALS_UPDATED, cb);
85
- return () => channel.off(_coreEvents.default.GLOBALS_UPDATED, cb);
86
- }, []);
87
- return [globals];
88
- };
89
-
90
- const extractComponentArgTypes = (component, {
91
- id,
92
- storyById
93
- }, include, exclude) => {
94
- const {
95
- parameters
96
- } = storyById(id);
97
- const {
98
- extractArgTypes
99
- } = parameters.docs || {};
100
-
101
- if (!extractArgTypes) {
102
- throw new Error(_components.ArgsTableError.ARGS_UNSUPPORTED);
103
- }
104
-
105
- let argTypes = extractArgTypes(component);
106
- argTypes = (0, _store.filterArgTypes)(argTypes, include, exclude);
107
- return argTypes;
108
- };
109
-
110
- exports.extractComponentArgTypes = extractComponentArgTypes;
111
-
112
- const isShortcut = value => {
113
- return value && [_types.CURRENT_SELECTION, _types.PRIMARY_STORY].includes(value);
114
- };
115
-
116
- const getComponent = (props = {}, {
117
- id,
118
- storyById
119
- }) => {
120
- const {
121
- of
122
- } = props;
123
- const {
124
- story
125
- } = props;
126
- const {
127
- component
128
- } = storyById(id);
129
-
130
- if (isShortcut(of) || isShortcut(story)) {
131
- return component || null;
132
- }
133
-
134
- if (!of) {
135
- throw new Error(_components.ArgsTableError.NO_COMPONENT);
136
- }
137
-
138
- return of;
139
- };
140
-
141
- exports.getComponent = getComponent;
142
-
143
- const addComponentTabs = (tabs, components, context, include, exclude, sort) => Object.assign({}, tabs, (0, _mapValues.default)(components, comp => ({
144
- rows: extractComponentArgTypes(comp, context, include, exclude),
145
- sort
146
- })));
147
-
148
- const StoryTable = props => {
149
- const context = (0, _react.useContext)(_DocsContext.DocsContext);
150
- const {
151
- id: currentId,
152
- componentStories
153
- } = context;
154
- const {
155
- story: storyName,
156
- component,
157
- subcomponents,
158
- showComponent,
159
- include,
160
- exclude,
161
- sort
162
- } = props;
163
-
164
- try {
165
- let storyId;
166
-
167
- switch (storyName) {
168
- case _types.CURRENT_SELECTION:
169
- {
170
- storyId = currentId;
171
- break;
172
- }
173
-
174
- case _types.PRIMARY_STORY:
175
- {
176
- const primaryStory = componentStories()[0];
177
- storyId = primaryStory.id;
178
- break;
179
- }
180
-
181
- default:
182
- {
183
- storyId = (0, _Story.lookupStoryId)(storyName, context);
184
- }
185
- }
186
-
187
- const story = (0, _useStory.useStory)(storyId, context); // eslint-disable-next-line prefer-const
188
-
189
- let [args, updateArgs, resetArgs] = useArgs(storyId, context);
190
- const [globals] = useGlobals(storyId, context);
191
- if (!story) return /*#__PURE__*/_react.default.createElement(_components.ArgsTable, {
192
- isLoading: true,
193
- updateArgs: updateArgs,
194
- resetArgs: resetArgs
195
- });
196
- const argTypes = (0, _store.filterArgTypes)(story.argTypes, include, exclude);
197
- const mainLabel = (0, _utils.getComponentName)(component) || 'Story';
198
- let tabs = {
199
- [mainLabel]: {
200
- rows: argTypes,
201
- args,
202
- globals,
203
- updateArgs,
204
- resetArgs
205
- }
206
- }; // Use the dynamically generated component tabs if there are no controls
207
-
208
- const storyHasArgsWithControls = argTypes && Object.values(argTypes).find(v => !!(v !== null && v !== void 0 && v.control));
209
-
210
- if (!storyHasArgsWithControls) {
211
- updateArgs = null;
212
- resetArgs = null;
213
- tabs = {};
214
- }
215
-
216
- if (component && (!storyHasArgsWithControls || showComponent)) {
217
- tabs = addComponentTabs(tabs, {
218
- [mainLabel]: component
219
- }, context, include, exclude);
220
- }
221
-
222
- if (subcomponents) {
223
- if (Array.isArray(subcomponents)) {
224
- throw new Error(`Unexpected subcomponents array. Expected an object whose keys are tab labels and whose values are components.`);
225
- }
226
-
227
- tabs = addComponentTabs(tabs, subcomponents, context, include, exclude);
228
- }
229
-
230
- return /*#__PURE__*/_react.default.createElement(_components.TabbedArgsTable, {
231
- tabs: tabs,
232
- sort: sort
233
- });
234
- } catch (err) {
235
- return /*#__PURE__*/_react.default.createElement(_components.ArgsTable, {
236
- error: err.message
237
- });
238
- }
239
- };
240
-
241
- exports.StoryTable = StoryTable;
242
-
243
- const ComponentsTable = props => {
244
- const context = (0, _react.useContext)(_DocsContext.DocsContext);
245
- const {
246
- components,
247
- include,
248
- exclude,
249
- sort
250
- } = props;
251
- const tabs = addComponentTabs({}, components, context, include, exclude);
252
- return /*#__PURE__*/_react.default.createElement(_components.TabbedArgsTable, {
253
- tabs: tabs,
254
- sort: sort
255
- });
256
- };
257
-
258
- exports.ComponentsTable = ComponentsTable;
259
-
260
- const ArgsTable = props => {
261
- const context = (0, _react.useContext)(_DocsContext.DocsContext);
262
- const {
263
- id,
264
- storyById
265
- } = context;
266
- const {
267
- parameters: {
268
- controls
269
- },
270
- subcomponents
271
- } = storyById(id);
272
- const {
273
- include,
274
- exclude,
275
- components,
276
- sort: sortProp
277
- } = props;
278
- const {
279
- story: storyName
280
- } = props;
281
- const sort = sortProp || (controls === null || controls === void 0 ? void 0 : controls.sort);
282
- const main = getComponent(props, context);
283
-
284
- if (storyName) {
285
- return /*#__PURE__*/_react.default.createElement(StoryTable, _extends({}, props, {
286
- component: main,
287
- subcomponents,
288
- sort
289
- }));
290
- }
291
-
292
- if (!components && !subcomponents) {
293
- let mainProps;
294
-
295
- try {
296
- mainProps = {
297
- rows: extractComponentArgTypes(main, context, include, exclude)
298
- };
299
- } catch (err) {
300
- mainProps = {
301
- error: err.message
302
- };
303
- }
304
-
305
- return /*#__PURE__*/_react.default.createElement(_components.ArgsTable, _extends({}, mainProps, {
306
- sort: sort
307
- }));
308
- }
309
-
310
- if (components) {
311
- return /*#__PURE__*/_react.default.createElement(ComponentsTable, _extends({}, props, {
312
- components,
313
- sort
314
- }));
315
- }
316
-
317
- const mainLabel = (0, _utils.getComponentName)(main);
318
- return /*#__PURE__*/_react.default.createElement(ComponentsTable, _extends({}, props, {
319
- components: Object.assign({
320
- [mainLabel]: main
321
- }, subcomponents),
322
- sort: sort
323
- }));
324
- };
325
-
326
- exports.ArgsTable = ArgsTable;
327
- ArgsTable.defaultProps = {
328
- of: _types.CURRENT_SELECTION
329
- };