@storybook/addon-docs 7.0.0-alpha.5 → 7.0.0-alpha.51
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 +14 -77
- package/angular/index.js +1 -1
- package/dist/DocsRenderer-MHI45CTG.mjs +1 -0
- package/dist/chunk-HKSD7XQF.mjs +1 -0
- package/dist/chunk-WMY67HY3.mjs +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/preset.d.ts +5 -0
- package/dist/preset.js +7 -0
- package/dist/preset.mjs +7 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +1 -0
- package/dist/preview.mjs +1 -0
- package/jest-transform-mdx.js +4 -3
- package/jest.config.js +7 -0
- package/package.json +65 -38
- package/preset.js +1 -1
- package/preview.js +1 -1
- package/web-components/README.md +1 -0
- package/LICENSE +0 -21
- package/blocks.d.ts +0 -2
- package/blocks.js +0 -14
- 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/index.js +0 -366
- 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/index.js +0 -18
- package/dist/cjs/manager.js +0 -20
- package/dist/cjs/preset.js +0 -162
- package/dist/cjs/preview.js +0 -18
- package/dist/cjs/shared.js +0 -22
- 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/index.js +0 -24
- 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/index.js +0 -1
- package/dist/esm/manager.js +0 -16
- package/dist/esm/preset.js +0 -132
- package/dist/esm/preview.js +0 -6
- package/dist/esm/shared.js +0 -11
- 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/index.d.ts +0 -24
- 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/index.d.ts +0 -1
- package/dist/types/manager.d.ts +0 -1
- package/dist/types/preset.d.ts +0 -12
- package/dist/types/preview.d.ts +0 -6
- package/dist/types/shared.d.ts +0 -24
- package/manager.js +0 -1
- package/mdx-compiler-plugin.js +0 -1
- package/register.js +0 -6
package/dist/cjs/manager.js
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _addons = require("@storybook/addons");
|
|
4
|
-
|
|
5
|
-
var _shared = require("./shared");
|
|
6
|
-
|
|
7
|
-
_addons.addons.register(_shared.ADDON_ID, () => {
|
|
8
|
-
_addons.addons.add(_shared.PANEL_ID, {
|
|
9
|
-
type: _addons.types.TAB,
|
|
10
|
-
title: 'Docs',
|
|
11
|
-
route: ({
|
|
12
|
-
storyId,
|
|
13
|
-
refId
|
|
14
|
-
}) => refId ? `/docs/${refId}_${storyId}` : `/docs/${storyId}`,
|
|
15
|
-
match: ({
|
|
16
|
-
viewMode
|
|
17
|
-
}) => viewMode === 'docs',
|
|
18
|
-
render: () => null
|
|
19
|
-
});
|
|
20
|
-
});
|
package/dist/cjs/preset.js
DELETED
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.storyIndexers = void 0;
|
|
7
|
-
exports.webpack = webpack;
|
|
8
|
-
|
|
9
|
-
var _fsExtra = _interopRequireDefault(require("fs-extra"));
|
|
10
|
-
|
|
11
|
-
var _remarkSlug = _interopRequireDefault(require("remark-slug"));
|
|
12
|
-
|
|
13
|
-
var _remarkExternalLinks = _interopRequireDefault(require("remark-external-links"));
|
|
14
|
-
|
|
15
|
-
var _global = _interopRequireDefault(require("global"));
|
|
16
|
-
|
|
17
|
-
var _nodeLogger = require("@storybook/node-logger");
|
|
18
|
-
|
|
19
|
-
var _csfTools = require("@storybook/csf-tools");
|
|
20
|
-
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
|
|
23
|
-
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); }
|
|
24
|
-
|
|
25
|
-
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; }
|
|
26
|
-
|
|
27
|
-
function createBabelOptions({
|
|
28
|
-
babelOptions,
|
|
29
|
-
mdxBabelOptions,
|
|
30
|
-
configureJSX
|
|
31
|
-
}) {
|
|
32
|
-
const babelPlugins = (mdxBabelOptions === null || mdxBabelOptions === void 0 ? void 0 : mdxBabelOptions.plugins) || (babelOptions === null || babelOptions === void 0 ? void 0 : babelOptions.plugins) || [];
|
|
33
|
-
const jsxPlugin = [require.resolve('@babel/plugin-transform-react-jsx'), {
|
|
34
|
-
pragma: 'React.createElement',
|
|
35
|
-
pragmaFrag: 'React.Fragment'
|
|
36
|
-
}];
|
|
37
|
-
const plugins = configureJSX ? [...babelPlugins, jsxPlugin] : babelPlugins;
|
|
38
|
-
return Object.assign({
|
|
39
|
-
// don't use the root babelrc by default (users can override this in mdxBabelOptions)
|
|
40
|
-
babelrc: false,
|
|
41
|
-
configFile: false
|
|
42
|
-
}, babelOptions, mdxBabelOptions, {
|
|
43
|
-
plugins
|
|
44
|
-
});
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async function webpack(webpackConfig = {}, options) {
|
|
48
|
-
var _global$FEATURES, _global$FEATURES2;
|
|
49
|
-
|
|
50
|
-
const resolvedBabelLoader = require.resolve('babel-loader');
|
|
51
|
-
|
|
52
|
-
const {
|
|
53
|
-
module = {}
|
|
54
|
-
} = webpackConfig; // it will reuse babel options that are already in use in storybook
|
|
55
|
-
// also, these babel options are chained with other presets.
|
|
56
|
-
|
|
57
|
-
const {
|
|
58
|
-
babelOptions,
|
|
59
|
-
mdxBabelOptions,
|
|
60
|
-
configureJSX = true,
|
|
61
|
-
sourceLoaderOptions = {
|
|
62
|
-
injectStoryParameters: true
|
|
63
|
-
},
|
|
64
|
-
transcludeMarkdown = false
|
|
65
|
-
} = options;
|
|
66
|
-
const mdxLoaderOptions = {
|
|
67
|
-
skipCsf: true,
|
|
68
|
-
remarkPlugins: [_remarkSlug.default, _remarkExternalLinks.default]
|
|
69
|
-
};
|
|
70
|
-
const mdxVersion = (_global$FEATURES = _global.default.FEATURES) !== null && _global$FEATURES !== void 0 && _global$FEATURES.previewMdx2 ? 'MDX2' : 'MDX1';
|
|
71
|
-
|
|
72
|
-
_nodeLogger.logger.info(`Addon-docs: using ${mdxVersion}`);
|
|
73
|
-
|
|
74
|
-
const mdxLoader = (_global$FEATURES2 = _global.default.FEATURES) !== null && _global$FEATURES2 !== void 0 && _global$FEATURES2.previewMdx2 ? require.resolve('@storybook/mdx2-csf/loader') : require.resolve('@storybook/mdx1-csf/loader'); // set `sourceLoaderOptions` to `null` to disable for manual configuration
|
|
75
|
-
|
|
76
|
-
const sourceLoader = sourceLoaderOptions ? [{
|
|
77
|
-
test: /\.(stories|story)\.[tj]sx?$/,
|
|
78
|
-
loader: require.resolve('@storybook/source-loader'),
|
|
79
|
-
options: Object.assign({}, sourceLoaderOptions, {
|
|
80
|
-
inspectLocalDependencies: true
|
|
81
|
-
}),
|
|
82
|
-
enforce: 'pre'
|
|
83
|
-
}] : [];
|
|
84
|
-
let rules = module.rules || [];
|
|
85
|
-
|
|
86
|
-
if (transcludeMarkdown) {
|
|
87
|
-
rules = [...rules.filter(rule => {
|
|
88
|
-
var _rule$test;
|
|
89
|
-
|
|
90
|
-
return ((_rule$test = rule.test) === null || _rule$test === void 0 ? void 0 : _rule$test.toString()) !== '/\\.md$/';
|
|
91
|
-
}), {
|
|
92
|
-
test: /\.md$/,
|
|
93
|
-
use: [{
|
|
94
|
-
loader: resolvedBabelLoader,
|
|
95
|
-
options: createBabelOptions({
|
|
96
|
-
babelOptions,
|
|
97
|
-
mdxBabelOptions,
|
|
98
|
-
configureJSX
|
|
99
|
-
})
|
|
100
|
-
}, {
|
|
101
|
-
loader: mdxLoader,
|
|
102
|
-
options: mdxLoaderOptions
|
|
103
|
-
}]
|
|
104
|
-
}];
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
const result = Object.assign({}, webpackConfig, {
|
|
108
|
-
module: Object.assign({}, module, {
|
|
109
|
-
rules: [...rules, {
|
|
110
|
-
test: /(stories|story)\.mdx$/,
|
|
111
|
-
use: [{
|
|
112
|
-
loader: resolvedBabelLoader,
|
|
113
|
-
options: createBabelOptions({
|
|
114
|
-
babelOptions,
|
|
115
|
-
mdxBabelOptions,
|
|
116
|
-
configureJSX
|
|
117
|
-
})
|
|
118
|
-
}, {
|
|
119
|
-
loader: mdxLoader
|
|
120
|
-
}]
|
|
121
|
-
}, {
|
|
122
|
-
test: /\.mdx$/,
|
|
123
|
-
exclude: /(stories|story)\.mdx$/,
|
|
124
|
-
use: [{
|
|
125
|
-
loader: resolvedBabelLoader,
|
|
126
|
-
options: createBabelOptions({
|
|
127
|
-
babelOptions,
|
|
128
|
-
mdxBabelOptions,
|
|
129
|
-
configureJSX
|
|
130
|
-
})
|
|
131
|
-
}, {
|
|
132
|
-
loader: mdxLoader,
|
|
133
|
-
options: mdxLoaderOptions
|
|
134
|
-
}]
|
|
135
|
-
}, ...sourceLoader]
|
|
136
|
-
})
|
|
137
|
-
});
|
|
138
|
-
return result;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const storyIndexers = async indexers => {
|
|
142
|
-
const mdxIndexer = async (fileName, opts) => {
|
|
143
|
-
var _global$FEATURES3;
|
|
144
|
-
|
|
145
|
-
let code = (await _fsExtra.default.readFile(fileName, 'utf-8')).toString(); // @ts-ignore
|
|
146
|
-
|
|
147
|
-
const {
|
|
148
|
-
compile
|
|
149
|
-
} = (_global$FEATURES3 = _global.default.FEATURES) !== null && _global$FEATURES3 !== void 0 && _global$FEATURES3.previewMdx2 ? await Promise.resolve().then(() => _interopRequireWildcard(require('@storybook/mdx2-csf'))) : await Promise.resolve().then(() => _interopRequireWildcard(require('@storybook/mdx1-csf')));
|
|
150
|
-
code = await compile(code, {});
|
|
151
|
-
return (0, _csfTools.loadCsf)(code, Object.assign({}, opts, {
|
|
152
|
-
fileName
|
|
153
|
-
})).parse();
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
return [{
|
|
157
|
-
test: /(stories|story)\.mdx$/,
|
|
158
|
-
indexer: mdxIndexer
|
|
159
|
-
}, ...(indexers || [])];
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
exports.storyIndexers = storyIndexers;
|
package/dist/cjs/preview.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.parameters = void 0;
|
|
7
|
-
|
|
8
|
-
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); }
|
|
9
|
-
|
|
10
|
-
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; }
|
|
11
|
-
|
|
12
|
-
const parameters = {
|
|
13
|
-
docs: {
|
|
14
|
-
getContainer: async () => (await Promise.resolve().then(() => _interopRequireWildcard(require('./blocks')))).DocsContainer,
|
|
15
|
-
getPage: async () => (await Promise.resolve().then(() => _interopRequireWildcard(require('./blocks')))).DocsPage
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
exports.parameters = parameters;
|
package/dist/cjs/shared.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.SourceType = exports.SNIPPET_RENDERED = exports.PARAM_KEY = exports.PANEL_ID = exports.ADDON_ID = void 0;
|
|
7
|
-
const ADDON_ID = 'storybook/docs';
|
|
8
|
-
exports.ADDON_ID = ADDON_ID;
|
|
9
|
-
const PANEL_ID = `${ADDON_ID}/panel`;
|
|
10
|
-
exports.PANEL_ID = PANEL_ID;
|
|
11
|
-
const PARAM_KEY = `docs`;
|
|
12
|
-
exports.PARAM_KEY = PARAM_KEY;
|
|
13
|
-
const SNIPPET_RENDERED = `${ADDON_ID}/snippet-rendered`;
|
|
14
|
-
exports.SNIPPET_RENDERED = SNIPPET_RENDERED;
|
|
15
|
-
let SourceType;
|
|
16
|
-
exports.SourceType = SourceType;
|
|
17
|
-
|
|
18
|
-
(function (SourceType) {
|
|
19
|
-
SourceType["AUTO"] = "auto";
|
|
20
|
-
SourceType["CODE"] = "code";
|
|
21
|
-
SourceType["DYNAMIC"] = "dynamic";
|
|
22
|
-
})(SourceType || (exports.SourceType = SourceType = {}));
|
|
@@ -1,292 +0,0 @@
|
|
|
1
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
2
|
-
|
|
3
|
-
import React, { useContext, useEffect, useState, useCallback } from 'react';
|
|
4
|
-
import mapValues from 'lodash/mapValues';
|
|
5
|
-
import { ArgsTable as PureArgsTable, ArgsTableError, TabbedArgsTable } from '@storybook/components';
|
|
6
|
-
import { addons } from '@storybook/addons';
|
|
7
|
-
import { filterArgTypes } from '@storybook/store';
|
|
8
|
-
import Events from '@storybook/core-events';
|
|
9
|
-
import { DocsContext } from './DocsContext';
|
|
10
|
-
import { CURRENT_SELECTION, PRIMARY_STORY } from './types';
|
|
11
|
-
import { getComponentName } from './utils';
|
|
12
|
-
import { lookupStoryId } from './Story';
|
|
13
|
-
import { useStory } from './useStory';
|
|
14
|
-
|
|
15
|
-
const getContext = (storyId, context) => {
|
|
16
|
-
const story = context.storyById(storyId);
|
|
17
|
-
|
|
18
|
-
if (!story) {
|
|
19
|
-
throw new Error(`Unknown story: ${storyId}`);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
return context.getStoryContext(story);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
const useArgs = (storyId, context) => {
|
|
26
|
-
const channel = addons.getChannel();
|
|
27
|
-
const storyContext = getContext(storyId, context);
|
|
28
|
-
const [args, setArgs] = useState(storyContext.args);
|
|
29
|
-
useEffect(() => {
|
|
30
|
-
const cb = changed => {
|
|
31
|
-
if (changed.storyId === storyId) {
|
|
32
|
-
setArgs(changed.args);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
channel.on(Events.STORY_ARGS_UPDATED, cb);
|
|
37
|
-
return () => channel.off(Events.STORY_ARGS_UPDATED, cb);
|
|
38
|
-
}, [storyId]);
|
|
39
|
-
const updateArgs = useCallback(updatedArgs => channel.emit(Events.UPDATE_STORY_ARGS, {
|
|
40
|
-
storyId,
|
|
41
|
-
updatedArgs
|
|
42
|
-
}), [storyId]);
|
|
43
|
-
const resetArgs = useCallback(argNames => channel.emit(Events.RESET_STORY_ARGS, {
|
|
44
|
-
storyId,
|
|
45
|
-
argNames
|
|
46
|
-
}), [storyId]);
|
|
47
|
-
return [args, updateArgs, resetArgs];
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
const useGlobals = (storyId, context) => {
|
|
51
|
-
const channel = addons.getChannel();
|
|
52
|
-
const storyContext = getContext(storyId, context);
|
|
53
|
-
const [globals, setGlobals] = useState(storyContext.globals);
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
const cb = changed => {
|
|
56
|
-
setGlobals(changed.globals);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
channel.on(Events.GLOBALS_UPDATED, cb);
|
|
60
|
-
return () => channel.off(Events.GLOBALS_UPDATED, cb);
|
|
61
|
-
}, []);
|
|
62
|
-
return [globals];
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
export const extractComponentArgTypes = (component, {
|
|
66
|
-
id,
|
|
67
|
-
storyById
|
|
68
|
-
}, include, exclude) => {
|
|
69
|
-
const {
|
|
70
|
-
parameters
|
|
71
|
-
} = storyById(id);
|
|
72
|
-
const {
|
|
73
|
-
extractArgTypes
|
|
74
|
-
} = parameters.docs || {};
|
|
75
|
-
|
|
76
|
-
if (!extractArgTypes) {
|
|
77
|
-
throw new Error(ArgsTableError.ARGS_UNSUPPORTED);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
let argTypes = extractArgTypes(component);
|
|
81
|
-
argTypes = filterArgTypes(argTypes, include, exclude);
|
|
82
|
-
return argTypes;
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
const isShortcut = value => {
|
|
86
|
-
return value && [CURRENT_SELECTION, PRIMARY_STORY].includes(value);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export const getComponent = (props = {}, {
|
|
90
|
-
id,
|
|
91
|
-
storyById
|
|
92
|
-
}) => {
|
|
93
|
-
const {
|
|
94
|
-
of
|
|
95
|
-
} = props;
|
|
96
|
-
const {
|
|
97
|
-
story
|
|
98
|
-
} = props;
|
|
99
|
-
const {
|
|
100
|
-
component
|
|
101
|
-
} = storyById(id);
|
|
102
|
-
|
|
103
|
-
if (isShortcut(of) || isShortcut(story)) {
|
|
104
|
-
return component || null;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
if (!of) {
|
|
108
|
-
throw new Error(ArgsTableError.NO_COMPONENT);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return of;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
const addComponentTabs = (tabs, components, context, include, exclude, sort) => Object.assign({}, tabs, mapValues(components, comp => ({
|
|
115
|
-
rows: extractComponentArgTypes(comp, context, include, exclude),
|
|
116
|
-
sort
|
|
117
|
-
})));
|
|
118
|
-
|
|
119
|
-
export const StoryTable = props => {
|
|
120
|
-
const context = useContext(DocsContext);
|
|
121
|
-
const {
|
|
122
|
-
id: currentId,
|
|
123
|
-
componentStories
|
|
124
|
-
} = context;
|
|
125
|
-
const {
|
|
126
|
-
story: storyName,
|
|
127
|
-
component,
|
|
128
|
-
subcomponents,
|
|
129
|
-
showComponent,
|
|
130
|
-
include,
|
|
131
|
-
exclude,
|
|
132
|
-
sort
|
|
133
|
-
} = props;
|
|
134
|
-
|
|
135
|
-
try {
|
|
136
|
-
let storyId;
|
|
137
|
-
|
|
138
|
-
switch (storyName) {
|
|
139
|
-
case CURRENT_SELECTION:
|
|
140
|
-
{
|
|
141
|
-
storyId = currentId;
|
|
142
|
-
break;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
case PRIMARY_STORY:
|
|
146
|
-
{
|
|
147
|
-
const primaryStory = componentStories()[0];
|
|
148
|
-
storyId = primaryStory.id;
|
|
149
|
-
break;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
default:
|
|
153
|
-
{
|
|
154
|
-
storyId = lookupStoryId(storyName, context);
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const story = useStory(storyId, context); // eslint-disable-next-line prefer-const
|
|
159
|
-
|
|
160
|
-
let [args, updateArgs, resetArgs] = useArgs(storyId, context);
|
|
161
|
-
const [globals] = useGlobals(storyId, context);
|
|
162
|
-
if (!story) return /*#__PURE__*/React.createElement(PureArgsTable, {
|
|
163
|
-
isLoading: true,
|
|
164
|
-
updateArgs: updateArgs,
|
|
165
|
-
resetArgs: resetArgs
|
|
166
|
-
});
|
|
167
|
-
const argTypes = filterArgTypes(story.argTypes, include, exclude);
|
|
168
|
-
const mainLabel = getComponentName(component) || 'Story';
|
|
169
|
-
let tabs = {
|
|
170
|
-
[mainLabel]: {
|
|
171
|
-
rows: argTypes,
|
|
172
|
-
args,
|
|
173
|
-
globals,
|
|
174
|
-
updateArgs,
|
|
175
|
-
resetArgs
|
|
176
|
-
}
|
|
177
|
-
}; // Use the dynamically generated component tabs if there are no controls
|
|
178
|
-
|
|
179
|
-
const storyHasArgsWithControls = argTypes && Object.values(argTypes).find(v => !!v?.control);
|
|
180
|
-
|
|
181
|
-
if (!storyHasArgsWithControls) {
|
|
182
|
-
updateArgs = null;
|
|
183
|
-
resetArgs = null;
|
|
184
|
-
tabs = {};
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
if (component && (!storyHasArgsWithControls || showComponent)) {
|
|
188
|
-
tabs = addComponentTabs(tabs, {
|
|
189
|
-
[mainLabel]: component
|
|
190
|
-
}, context, include, exclude);
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (subcomponents) {
|
|
194
|
-
if (Array.isArray(subcomponents)) {
|
|
195
|
-
throw new Error(`Unexpected subcomponents array. Expected an object whose keys are tab labels and whose values are components.`);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
tabs = addComponentTabs(tabs, subcomponents, context, include, exclude);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return /*#__PURE__*/React.createElement(TabbedArgsTable, {
|
|
202
|
-
tabs: tabs,
|
|
203
|
-
sort: sort
|
|
204
|
-
});
|
|
205
|
-
} catch (err) {
|
|
206
|
-
return /*#__PURE__*/React.createElement(PureArgsTable, {
|
|
207
|
-
error: err.message
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
export const ComponentsTable = props => {
|
|
212
|
-
const context = useContext(DocsContext);
|
|
213
|
-
const {
|
|
214
|
-
components,
|
|
215
|
-
include,
|
|
216
|
-
exclude,
|
|
217
|
-
sort
|
|
218
|
-
} = props;
|
|
219
|
-
const tabs = addComponentTabs({}, components, context, include, exclude);
|
|
220
|
-
return /*#__PURE__*/React.createElement(TabbedArgsTable, {
|
|
221
|
-
tabs: tabs,
|
|
222
|
-
sort: sort
|
|
223
|
-
});
|
|
224
|
-
};
|
|
225
|
-
export const ArgsTable = props => {
|
|
226
|
-
const context = useContext(DocsContext);
|
|
227
|
-
const {
|
|
228
|
-
id,
|
|
229
|
-
storyById
|
|
230
|
-
} = context;
|
|
231
|
-
const {
|
|
232
|
-
parameters: {
|
|
233
|
-
controls
|
|
234
|
-
},
|
|
235
|
-
subcomponents
|
|
236
|
-
} = storyById(id);
|
|
237
|
-
const {
|
|
238
|
-
include,
|
|
239
|
-
exclude,
|
|
240
|
-
components,
|
|
241
|
-
sort: sortProp
|
|
242
|
-
} = props;
|
|
243
|
-
const {
|
|
244
|
-
story: storyName
|
|
245
|
-
} = props;
|
|
246
|
-
const sort = sortProp || controls?.sort;
|
|
247
|
-
const main = getComponent(props, context);
|
|
248
|
-
|
|
249
|
-
if (storyName) {
|
|
250
|
-
return /*#__PURE__*/React.createElement(StoryTable, _extends({}, props, {
|
|
251
|
-
component: main,
|
|
252
|
-
subcomponents,
|
|
253
|
-
sort
|
|
254
|
-
}));
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
if (!components && !subcomponents) {
|
|
258
|
-
let mainProps;
|
|
259
|
-
|
|
260
|
-
try {
|
|
261
|
-
mainProps = {
|
|
262
|
-
rows: extractComponentArgTypes(main, context, include, exclude)
|
|
263
|
-
};
|
|
264
|
-
} catch (err) {
|
|
265
|
-
mainProps = {
|
|
266
|
-
error: err.message
|
|
267
|
-
};
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
return /*#__PURE__*/React.createElement(PureArgsTable, _extends({}, mainProps, {
|
|
271
|
-
sort: sort
|
|
272
|
-
}));
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (components) {
|
|
276
|
-
return /*#__PURE__*/React.createElement(ComponentsTable, _extends({}, props, {
|
|
277
|
-
components,
|
|
278
|
-
sort
|
|
279
|
-
}));
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
const mainLabel = getComponentName(main);
|
|
283
|
-
return /*#__PURE__*/React.createElement(ComponentsTable, _extends({}, props, {
|
|
284
|
-
components: Object.assign({
|
|
285
|
-
[mainLabel]: main
|
|
286
|
-
}, subcomponents),
|
|
287
|
-
sort: sort
|
|
288
|
-
}));
|
|
289
|
-
};
|
|
290
|
-
ArgsTable.defaultProps = {
|
|
291
|
-
of: CURRENT_SELECTION
|
|
292
|
-
};
|
|
@@ -1,83 +0,0 @@
|
|
|
1
|
-
const _excluded = ["withSource", "mdxSource", "children"];
|
|
2
|
-
|
|
3
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
4
|
-
|
|
5
|
-
import React, { useContext } from 'react';
|
|
6
|
-
import { MDXProvider } from '@mdx-js/react';
|
|
7
|
-
import { toId, storyNameFromExport } from '@storybook/csf';
|
|
8
|
-
import { resetComponents, Preview as PurePreview, PreviewSkeleton } from '@storybook/components';
|
|
9
|
-
import { DocsContext } from './DocsContext';
|
|
10
|
-
import { SourceContext } from './SourceContainer';
|
|
11
|
-
import { getSourceProps, SourceState } from './Source';
|
|
12
|
-
import { useStories } from './useStory';
|
|
13
|
-
import { CURRENT_SELECTION } from './types';
|
|
14
|
-
export { SourceState };
|
|
15
|
-
|
|
16
|
-
const getPreviewProps = (_ref, docsContext, sourceContext) => {
|
|
17
|
-
let {
|
|
18
|
-
withSource,
|
|
19
|
-
mdxSource,
|
|
20
|
-
children
|
|
21
|
-
} = _ref,
|
|
22
|
-
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
23
|
-
|
|
24
|
-
const {
|
|
25
|
-
mdxComponentAnnotations,
|
|
26
|
-
mdxStoryNameToKey
|
|
27
|
-
} = docsContext;
|
|
28
|
-
let sourceState = withSource;
|
|
29
|
-
let isLoading = false;
|
|
30
|
-
|
|
31
|
-
if (sourceState === SourceState.NONE) {
|
|
32
|
-
return {
|
|
33
|
-
isLoading,
|
|
34
|
-
previewProps: props
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (mdxSource) {
|
|
39
|
-
return {
|
|
40
|
-
isLoading,
|
|
41
|
-
previewProps: Object.assign({}, props, {
|
|
42
|
-
withSource: getSourceProps({
|
|
43
|
-
code: decodeURI(mdxSource)
|
|
44
|
-
}, docsContext, sourceContext)
|
|
45
|
-
})
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const childArray = Array.isArray(children) ? children : [children];
|
|
50
|
-
const storyChildren = childArray.filter(c => c.props && (c.props.id || c.props.name));
|
|
51
|
-
const targetIds = storyChildren.map(s => s.props.id || toId(mdxComponentAnnotations.id || mdxComponentAnnotations.title, storyNameFromExport(mdxStoryNameToKey[s.props.name])));
|
|
52
|
-
const sourceProps = getSourceProps({
|
|
53
|
-
ids: targetIds
|
|
54
|
-
}, docsContext, sourceContext);
|
|
55
|
-
if (!sourceState) sourceState = sourceProps.state;
|
|
56
|
-
const storyIds = targetIds.map(targetId => targetId === CURRENT_SELECTION ? docsContext.id : targetId);
|
|
57
|
-
const stories = useStories(storyIds, docsContext);
|
|
58
|
-
isLoading = stories.some(s => !s);
|
|
59
|
-
return {
|
|
60
|
-
isLoading,
|
|
61
|
-
previewProps: Object.assign({}, props, {
|
|
62
|
-
// pass through columns etc.
|
|
63
|
-
withSource: sourceProps,
|
|
64
|
-
isExpanded: sourceState === SourceState.OPEN
|
|
65
|
-
})
|
|
66
|
-
};
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const Canvas = props => {
|
|
70
|
-
const docsContext = useContext(DocsContext);
|
|
71
|
-
const sourceContext = useContext(SourceContext);
|
|
72
|
-
const {
|
|
73
|
-
isLoading,
|
|
74
|
-
previewProps
|
|
75
|
-
} = getPreviewProps(props, docsContext, sourceContext);
|
|
76
|
-
const {
|
|
77
|
-
children
|
|
78
|
-
} = props;
|
|
79
|
-
if (isLoading) return /*#__PURE__*/React.createElement(PreviewSkeleton, null);
|
|
80
|
-
return /*#__PURE__*/React.createElement(MDXProvider, {
|
|
81
|
-
components: resetComponents
|
|
82
|
-
}, /*#__PURE__*/React.createElement(PurePreview, previewProps, children));
|
|
83
|
-
};
|