@storybook/addon-docs 7.0.0-alpha.3 → 7.0.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -13
- package/blocks.js +1 -1
- package/dist/cjs/DocsRenderer.js +52 -0
- package/dist/cjs/blocks/index.js +4 -352
- package/dist/cjs/index.js +13 -1
- package/dist/cjs/preset.js +19 -4
- package/dist/cjs/preview.js +6 -2
- package/dist/esm/DocsRenderer.js +34 -0
- package/dist/esm/blocks/index.js +1 -24
- package/dist/esm/index.js +2 -1
- package/dist/esm/preset.js +14 -2
- package/dist/esm/preview.js +6 -2
- package/dist/types/DocsRenderer.d.ts +8 -0
- package/dist/types/blocks/index.d.ts +1 -24
- package/dist/types/index.d.ts +1 -0
- package/dist/types/preset.d.ts +8 -2
- package/dist/types/preview.d.ts +1 -6
- package/package.json +25 -24
- package/web-components/README.md +1 -0
- package/LICENSE +0 -21
- package/dist/cjs/blocks/Anchor.js +0 -23
- package/dist/cjs/blocks/ArgsTable.js +0 -329
- package/dist/cjs/blocks/Canvas.js +0 -109
- package/dist/cjs/blocks/Description.js +0 -126
- package/dist/cjs/blocks/DocsContainer.js +0 -127
- package/dist/cjs/blocks/DocsContext.js +0 -25
- package/dist/cjs/blocks/DocsPage.js +0 -30
- package/dist/cjs/blocks/DocsStory.js +0 -68
- package/dist/cjs/blocks/Heading.js +0 -31
- package/dist/cjs/blocks/Meta.js +0 -50
- package/dist/cjs/blocks/Preview.js +0 -23
- package/dist/cjs/blocks/Primary.js +0 -39
- package/dist/cjs/blocks/Props.js +0 -29
- package/dist/cjs/blocks/Source.js +0 -179
- package/dist/cjs/blocks/SourceContainer.js +0 -67
- package/dist/cjs/blocks/Stories.js +0 -51
- package/dist/cjs/blocks/Story.js +0 -143
- package/dist/cjs/blocks/Subheading.js +0 -31
- package/dist/cjs/blocks/Subtitle.js +0 -39
- package/dist/cjs/blocks/Title.js +0 -44
- package/dist/cjs/blocks/Wrapper.js +0 -20
- package/dist/cjs/blocks/enhanceSource.js +0 -92
- package/dist/cjs/blocks/mdx.js +0 -234
- package/dist/cjs/blocks/types.js +0 -10
- package/dist/cjs/blocks/useStory.js +0 -37
- package/dist/cjs/blocks/utils.js +0 -40
- package/dist/cjs/manager.js +0 -20
- package/dist/esm/blocks/Anchor.js +0 -8
- package/dist/esm/blocks/ArgsTable.js +0 -292
- package/dist/esm/blocks/Canvas.js +0 -83
- package/dist/esm/blocks/Description.js +0 -107
- package/dist/esm/blocks/DocsContainer.js +0 -98
- package/dist/esm/blocks/DocsContext.js +0 -16
- package/dist/esm/blocks/DocsPage.js +0 -11
- package/dist/esm/blocks/DocsStory.js +0 -46
- package/dist/esm/blocks/Heading.js +0 -17
- package/dist/esm/blocks/Meta.js +0 -31
- package/dist/esm/blocks/Preview.js +0 -9
- package/dist/esm/blocks/Primary.js +0 -23
- package/dist/esm/blocks/Props.js +0 -14
- package/dist/esm/blocks/Source.js +0 -144
- package/dist/esm/blocks/SourceContainer.js +0 -44
- package/dist/esm/blocks/Stories.js +0 -30
- package/dist/esm/blocks/Story.js +0 -114
- package/dist/esm/blocks/Subheading.js +0 -17
- package/dist/esm/blocks/Subtitle.js +0 -23
- package/dist/esm/blocks/Title.js +0 -24
- package/dist/esm/blocks/Wrapper.js +0 -8
- package/dist/esm/blocks/enhanceSource.js +0 -87
- package/dist/esm/blocks/mdx.js +0 -203
- package/dist/esm/blocks/types.js +0 -2
- package/dist/esm/blocks/useStory.js +0 -27
- package/dist/esm/blocks/utils.js +0 -29
- package/dist/esm/manager.js +0 -16
- package/dist/types/blocks/Anchor.d.ts +0 -6
- package/dist/types/blocks/ArgsTable.d.ts +0 -33
- package/dist/types/blocks/Canvas.d.ts +0 -9
- package/dist/types/blocks/Description.d.ts +0 -20
- package/dist/types/blocks/DocsContainer.d.ts +0 -7
- package/dist/types/blocks/DocsContext.d.ts +0 -5
- package/dist/types/blocks/DocsPage.d.ts +0 -2
- package/dist/types/blocks/DocsStory.d.ts +0 -3
- package/dist/types/blocks/Heading.d.ts +0 -6
- package/dist/types/blocks/Meta.d.ts +0 -9
- package/dist/types/blocks/Preview.d.ts +0 -3
- package/dist/types/blocks/Primary.d.ts +0 -6
- package/dist/types/blocks/Props.d.ts +0 -3
- package/dist/types/blocks/Source.d.ts +0 -38
- package/dist/types/blocks/SourceContainer.d.ts +0 -14
- package/dist/types/blocks/Stories.d.ts +0 -7
- package/dist/types/blocks/Story.d.ts +0 -28
- package/dist/types/blocks/Subheading.d.ts +0 -3
- package/dist/types/blocks/Subtitle.d.ts +0 -6
- package/dist/types/blocks/Title.d.ts +0 -8
- package/dist/types/blocks/Wrapper.d.ts +0 -2
- package/dist/types/blocks/enhanceSource.d.ts +0 -3
- package/dist/types/blocks/mdx.d.ts +0 -20
- package/dist/types/blocks/types.d.ts +0 -13
- package/dist/types/blocks/useStory.d.ts +0 -5
- package/dist/types/blocks/utils.d.ts +0 -3
- package/dist/types/manager.d.ts +0 -1
- package/manager.js +0 -1
- package/register.js +0 -6
package/dist/esm/preset.js
CHANGED
|
@@ -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$/,
|
|
@@ -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
|
};
|
package/dist/esm/preview.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export const parameters = {
|
|
2
2
|
docs: {
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
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';
|
package/dist/types/index.d.ts
CHANGED
package/dist/types/preset.d.ts
CHANGED
|
@@ -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
|
|
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 {};
|
package/dist/types/preview.d.ts
CHANGED
|
@@ -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
|
+
"version": "7.0.0-alpha.30",
|
|
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
|
-
"
|
|
48
|
+
"check": "tsc --noEmit",
|
|
49
|
+
"prepare": "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.
|
|
56
|
-
"@storybook/api": "7.0.0-alpha.
|
|
57
|
-
"@storybook/
|
|
58
|
-
"@storybook/
|
|
59
|
-
"@storybook/core-
|
|
60
|
-
"@storybook/
|
|
61
|
-
"@storybook/csf
|
|
62
|
-
"@storybook/
|
|
63
|
-
"@storybook/
|
|
64
|
-
"@storybook/
|
|
65
|
-
"@storybook/
|
|
66
|
-
"@storybook/
|
|
67
|
-
"@storybook/
|
|
68
|
-
"@storybook/
|
|
69
|
-
"@storybook/
|
|
56
|
+
"@storybook/addons": "7.0.0-alpha.30",
|
|
57
|
+
"@storybook/api": "7.0.0-alpha.30",
|
|
58
|
+
"@storybook/blocks": "7.0.0-alpha.30",
|
|
59
|
+
"@storybook/components": "7.0.0-alpha.30",
|
|
60
|
+
"@storybook/core-common": "7.0.0-alpha.30",
|
|
61
|
+
"@storybook/core-events": "7.0.0-alpha.30",
|
|
62
|
+
"@storybook/csf": "0.0.2--canary.0899bb7.0",
|
|
63
|
+
"@storybook/csf-tools": "7.0.0-alpha.30",
|
|
64
|
+
"@storybook/docs-tools": "7.0.0-alpha.30",
|
|
65
|
+
"@storybook/mdx1-csf": "0.0.5-canary.13.9ce928a.0",
|
|
66
|
+
"@storybook/node-logger": "7.0.0-alpha.30",
|
|
67
|
+
"@storybook/postinstall": "7.0.0-alpha.30",
|
|
68
|
+
"@storybook/preview-web": "7.0.0-alpha.30",
|
|
69
|
+
"@storybook/source-loader": "7.0.0-alpha.30",
|
|
70
|
+
"@storybook/store": "7.0.0-alpha.30",
|
|
71
|
+
"@storybook/theming": "7.0.0-alpha.30",
|
|
70
72
|
"babel-loader": "^8.2.5",
|
|
71
|
-
"
|
|
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": "
|
|
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": "
|
|
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": "
|
|
106
|
+
"gitHead": "aabf7b595cb13d8a86dca27ad3d6039205bd55d6",
|
|
106
107
|
"storybook": {
|
|
107
108
|
"displayName": "Docs",
|
|
108
109
|
"icon": "https://user-images.githubusercontent.com/263385/101991672-48355c80-3c7c-11eb-82d9-95fa12438f64.png",
|
package/web-components/README.md
CHANGED
|
@@ -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
|
-
};
|