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

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.
@@ -205,7 +205,7 @@ const StoryTable = props => {
205
205
  }
206
206
  }; // Use the dynamically generated component tabs if there are no controls
207
207
 
208
- const storyHasArgsWithControls = argTypes && Object.values(argTypes).find(v => !!(v !== null && v !== void 0 && v.control));
208
+ const storyHasArgsWithControls = argTypes && Object.values(argTypes).find(v => !!v?.control);
209
209
 
210
210
  if (!storyHasArgsWithControls) {
211
211
  updateArgs = null;
@@ -278,7 +278,7 @@ const ArgsTable = props => {
278
278
  const {
279
279
  story: storyName
280
280
  } = props;
281
- const sort = sortProp || (controls === null || controls === void 0 ? void 0 : controls.sort);
281
+ const sort = sortProp || controls?.sort;
282
282
  const main = getComponent(props, context);
283
283
 
284
284
  if (storyName) {
@@ -67,7 +67,7 @@ const getDescriptionProps = ({
67
67
  } = docs || {};
68
68
  const target = of === _types.CURRENT_SELECTION ? component : of; // override component description
69
69
 
70
- const componentDescriptionParameter = description === null || description === void 0 ? void 0 : description.component;
70
+ const componentDescriptionParameter = description?.component;
71
71
 
72
72
  if (componentDescriptionParameter) {
73
73
  return {
@@ -34,10 +34,8 @@ class DocsRenderer {
34
34
  exports.DocsRenderer = DocsRenderer;
35
35
 
36
36
  async function renderDocsAsync(docsContext, docsParameters, element) {
37
- var _docsParameters$getCo, _docsParameters$getPa;
38
-
39
- const Container = docsParameters.container || (await ((_docsParameters$getCo = docsParameters.getContainer) === null || _docsParameters$getCo === void 0 ? void 0 : _docsParameters$getCo.call(docsParameters))) || _DocsContainer.DocsContainer;
40
- const Page = docsParameters.page || (await ((_docsParameters$getPa = docsParameters.getPage) === null || _docsParameters$getPa === void 0 ? void 0 : _docsParameters$getPa.call(docsParameters))) || _DocsPage.DocsPage; // Use `title` as a key so that we force a re-render every time we switch components
37
+ const Container = docsParameters.container || (await docsParameters.getContainer?.()) || _DocsContainer.DocsContainer;
38
+ const Page = docsParameters.page || (await docsParameters.getPage?.()) || _DocsPage.DocsPage; // Use `title` as a key so that we force a re-render every time we switch components
41
39
 
42
40
  const docsElement = /*#__PURE__*/_react.default.createElement(Container, {
43
41
  key: docsContext.title,
@@ -42,9 +42,7 @@ const DocsStory = ({
42
42
  } = parameters;
43
43
 
44
44
  if (expanded && docs) {
45
- var _docs$description;
46
-
47
- description = (_docs$description = docs.description) === null || _docs$description === void 0 ? void 0 : _docs$description.story;
45
+ description = docs.description?.story;
48
46
 
49
47
  if (!description) {
50
48
  description = docs.storyDescription;
@@ -35,11 +35,7 @@ exports.SourceState = SourceState;
35
35
  })(SourceState || (exports.SourceState = SourceState = {}));
36
36
 
37
37
  const getSourceState = stories => {
38
- const states = stories.map(story => {
39
- var _story$parameters$doc, _story$parameters$doc2;
40
-
41
- return (_story$parameters$doc = story.parameters.docs) === null || _story$parameters$doc === void 0 ? void 0 : (_story$parameters$doc2 = _story$parameters$doc.source) === null || _story$parameters$doc2 === void 0 ? void 0 : _story$parameters$doc2.state;
42
- }).filter(Boolean);
38
+ const states = stories.map(story => story.parameters.docs?.source?.state).filter(Boolean);
43
39
  if (states.length === 0) return SourceState.CLOSED; // FIXME: handling multiple stories is a pain
44
40
 
45
41
  return states[0];
@@ -51,15 +47,13 @@ const getStorySource = (storyId, sourceContext) => {
51
47
  } = sourceContext; // source rendering is async so source is unavailable at the start of the render cycle,
52
48
  // so we fail gracefully here without warning
53
49
 
54
- return (sources === null || sources === void 0 ? void 0 : sources[storyId]) || {
50
+ return sources?.[storyId] || {
55
51
  code: '',
56
52
  format: false
57
53
  };
58
54
  };
59
55
 
60
56
  const getSnippet = (snippet, story) => {
61
- var _parameters$docs, _parameters$docs$sour, _parameters$docs2, _parameters$docs2$sou, _enhanced$docs, _enhanced$docs$source;
62
-
63
57
  if (!story) {
64
58
  return snippet;
65
59
  }
@@ -69,9 +63,9 @@ const getSnippet = (snippet, story) => {
69
63
  } = story; // eslint-disable-next-line no-underscore-dangle
70
64
 
71
65
  const isArgsStory = parameters.__isArgsStory;
72
- const type = ((_parameters$docs = parameters.docs) === null || _parameters$docs === void 0 ? void 0 : (_parameters$docs$sour = _parameters$docs.source) === null || _parameters$docs$sour === void 0 ? void 0 : _parameters$docs$sour.type) || _shared.SourceType.AUTO; // if user has hard-coded the snippet, that takes precedence
66
+ const type = parameters.docs?.source?.type || _shared.SourceType.AUTO; // if user has hard-coded the snippet, that takes precedence
73
67
 
74
- const userCode = (_parameters$docs2 = parameters.docs) === null || _parameters$docs2 === void 0 ? void 0 : (_parameters$docs2$sou = _parameters$docs2.source) === null || _parameters$docs2$sou === void 0 ? void 0 : _parameters$docs2$sou.code;
68
+ const userCode = parameters.docs?.source?.code;
75
69
 
76
70
  if (userCode !== undefined) {
77
71
  return userCode;
@@ -79,21 +73,17 @@ const getSnippet = (snippet, story) => {
79
73
 
80
74
 
81
75
  if (type === _shared.SourceType.DYNAMIC) {
82
- var _parameters$docs3, _parameters$docs3$tra;
83
-
84
- return ((_parameters$docs3 = parameters.docs) === null || _parameters$docs3 === void 0 ? void 0 : (_parameters$docs3$tra = _parameters$docs3.transformSource) === null || _parameters$docs3$tra === void 0 ? void 0 : _parameters$docs3$tra.call(_parameters$docs3, snippet, story)) || snippet;
76
+ return parameters.docs?.transformSource?.(snippet, story) || snippet;
85
77
  } // if this is an args story and there's a snippet
86
78
 
87
79
 
88
80
  if (type === _shared.SourceType.AUTO && snippet && isArgsStory) {
89
- var _parameters$docs4, _parameters$docs4$tra;
90
-
91
- return ((_parameters$docs4 = parameters.docs) === null || _parameters$docs4 === void 0 ? void 0 : (_parameters$docs4$tra = _parameters$docs4.transformSource) === null || _parameters$docs4$tra === void 0 ? void 0 : _parameters$docs4$tra.call(_parameters$docs4, snippet, story)) || snippet;
81
+ return parameters.docs?.transformSource?.(snippet, story) || snippet;
92
82
  } // otherwise, use the source code logic
93
83
 
94
84
 
95
85
  const enhanced = (0, _enhanceSource.enhanceSource)(story) || parameters;
96
- return (enhanced === null || enhanced === void 0 ? void 0 : (_enhanced$docs = enhanced.docs) === null || _enhanced$docs === void 0 ? void 0 : (_enhanced$docs$source = _enhanced$docs.source) === null || _enhanced$docs$source === void 0 ? void 0 : _enhanced$docs$source.code) || '';
86
+ return enhanced?.docs?.source?.code || '';
97
87
  };
98
88
 
99
89
  const getSourceProps = (props, docsContext, sourceContext) => {
@@ -27,11 +27,7 @@ const Stories = ({
27
27
  componentStories
28
28
  } = (0, _react.useContext)(_DocsContext.DocsContext);
29
29
  let stories = componentStories();
30
- stories = stories.filter(story => {
31
- var _story$parameters, _story$parameters$doc;
32
-
33
- return !((_story$parameters = story.parameters) !== null && _story$parameters !== void 0 && (_story$parameters$doc = _story$parameters.docs) !== null && _story$parameters$doc !== void 0 && _story$parameters$doc.disable);
34
- });
30
+ stories = stories.filter(story => !story.parameters?.docs?.disable);
35
31
  if (!includePrimary) stories = stories.slice(1);
36
32
 
37
33
  if (!stories || stories.length === 0) {
@@ -78,7 +78,7 @@ const getStoryProps = ({
78
78
  const storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
79
79
  return Object.assign({
80
80
  inline: storyIsInline,
81
- id: story === null || story === void 0 ? void 0 : story.id,
81
+ id: story?.id,
82
82
  height: height || (storyIsInline ? undefined : iframeHeight),
83
83
  title: storyName
84
84
  }, storyIsInline && {
@@ -28,7 +28,7 @@ const Subtitle = ({
28
28
  let text = children;
29
29
 
30
30
  if (!text) {
31
- text = parameters === null || parameters === void 0 ? void 0 : parameters.componentSubtitle;
31
+ text = parameters?.componentSubtitle;
32
32
  }
33
33
 
34
34
  return text ? /*#__PURE__*/_react.default.createElement(_components.Subtitle, {
@@ -60,8 +60,6 @@ const extract = (targetId, {
60
60
  };
61
61
 
62
62
  const enhanceSource = story => {
63
- var _docs$source;
64
-
65
63
  const {
66
64
  id,
67
65
  parameters
@@ -74,7 +72,7 @@ const enhanceSource = story => {
74
72
  transformSource
75
73
  } = docs; // no input or user has manually overridden the output
76
74
 
77
- if (!(storySource !== null && storySource !== void 0 && storySource.source) || (_docs$source = docs.source) !== null && _docs$source !== void 0 && _docs$source.code) {
75
+ if (!storySource?.source || docs.source?.code) {
78
76
  return null;
79
77
  }
80
78
 
@@ -29,7 +29,7 @@ function createBabelOptions({
29
29
  mdxBabelOptions,
30
30
  configureJSX
31
31
  }) {
32
- const babelPlugins = (mdxBabelOptions === null || mdxBabelOptions === void 0 ? void 0 : mdxBabelOptions.plugins) || (babelOptions === null || babelOptions === void 0 ? void 0 : babelOptions.plugins) || [];
32
+ const babelPlugins = mdxBabelOptions?.plugins || babelOptions?.plugins || [];
33
33
  const jsxPlugin = [require.resolve('@babel/plugin-transform-react-jsx'), {
34
34
  pragma: 'React.createElement',
35
35
  pragmaFrag: 'React.Fragment'
@@ -45,8 +45,6 @@ function createBabelOptions({
45
45
  }
46
46
 
47
47
  async function webpack(webpackConfig = {}, options) {
48
- var _global$FEATURES, _global$FEATURES2;
49
-
50
48
  const resolvedBabelLoader = require.resolve('babel-loader');
51
49
 
52
50
  const {
@@ -67,11 +65,11 @@ async function webpack(webpackConfig = {}, options) {
67
65
  skipCsf: true,
68
66
  remarkPlugins: [_remarkSlug.default, _remarkExternalLinks.default]
69
67
  };
70
- const mdxVersion = (_global$FEATURES = _global.default.FEATURES) !== null && _global$FEATURES !== void 0 && _global$FEATURES.previewMdx2 ? 'MDX2' : 'MDX1';
68
+ const mdxVersion = _global.default.FEATURES?.previewMdx2 ? 'MDX2' : 'MDX1';
71
69
 
72
70
  _nodeLogger.logger.info(`Addon-docs: using ${mdxVersion}`);
73
71
 
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
72
+ const mdxLoader = _global.default.FEATURES?.previewMdx2 ? require.resolve('@storybook/mdx2-csf/loader') : require.resolve('@storybook/mdx1-csf/loader'); // set `sourceLoaderOptions` to `null` to disable for manual configuration
75
73
 
76
74
  const sourceLoader = sourceLoaderOptions ? [{
77
75
  test: /\.(stories|story)\.[tj]sx?$/,
@@ -84,11 +82,7 @@ async function webpack(webpackConfig = {}, options) {
84
82
  let rules = module.rules || [];
85
83
 
86
84
  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
- }), {
85
+ rules = [...rules.filter(rule => rule.test?.toString() !== '/\\.md$/'), {
92
86
  test: /\.md$/,
93
87
  use: [{
94
88
  loader: resolvedBabelLoader,
@@ -140,13 +134,11 @@ async function webpack(webpackConfig = {}, options) {
140
134
 
141
135
  const storyIndexers = async indexers => {
142
136
  const mdxIndexer = async (fileName, opts) => {
143
- var _global$FEATURES3;
144
-
145
137
  let code = (await _fsExtra.default.readFile(fileName, 'utf-8')).toString(); // @ts-ignore
146
138
 
147
139
  const {
148
140
  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')));
141
+ } = _global.default.FEATURES?.previewMdx2 ? await Promise.resolve().then(() => _interopRequireWildcard(require('@storybook/mdx2-csf'))) : await Promise.resolve().then(() => _interopRequireWildcard(require('@storybook/mdx1-csf')));
150
142
  code = await compile(code, {});
151
143
  return (0, _csfTools.loadCsf)(code, Object.assign({}, opts, {
152
144
  fileName
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-docs",
3
- "version": "7.0.0-alpha.6",
3
+ "version": "7.0.0-alpha.7",
4
4
  "description": "Document component usage and properties in Markdown",
5
5
  "keywords": [
6
6
  "addon",
@@ -52,21 +52,21 @@
52
52
  "@babel/preset-env": "^7.12.11",
53
53
  "@jest/transform": "^26.6.2",
54
54
  "@mdx-js/react": "^1.6.22",
55
- "@storybook/addons": "7.0.0-alpha.6",
56
- "@storybook/api": "7.0.0-alpha.6",
57
- "@storybook/components": "7.0.0-alpha.6",
58
- "@storybook/core-common": "7.0.0-alpha.6",
59
- "@storybook/core-events": "7.0.0-alpha.6",
55
+ "@storybook/addons": "7.0.0-alpha.7",
56
+ "@storybook/api": "7.0.0-alpha.7",
57
+ "@storybook/components": "7.0.0-alpha.7",
58
+ "@storybook/core-common": "7.0.0-alpha.7",
59
+ "@storybook/core-events": "7.0.0-alpha.7",
60
60
  "@storybook/csf": "0.0.2--canary.4566f4d.1",
61
- "@storybook/csf-tools": "7.0.0-alpha.6",
62
- "@storybook/docs-tools": "7.0.0-alpha.6",
61
+ "@storybook/csf-tools": "7.0.0-alpha.7",
62
+ "@storybook/docs-tools": "7.0.0-alpha.7",
63
63
  "@storybook/mdx1-csf": "^0.0.1",
64
- "@storybook/node-logger": "7.0.0-alpha.6",
65
- "@storybook/postinstall": "7.0.0-alpha.6",
66
- "@storybook/preview-web": "7.0.0-alpha.6",
67
- "@storybook/source-loader": "7.0.0-alpha.6",
68
- "@storybook/store": "7.0.0-alpha.6",
69
- "@storybook/theming": "7.0.0-alpha.6",
64
+ "@storybook/node-logger": "7.0.0-alpha.7",
65
+ "@storybook/postinstall": "7.0.0-alpha.7",
66
+ "@storybook/preview-web": "7.0.0-alpha.7",
67
+ "@storybook/source-loader": "7.0.0-alpha.7",
68
+ "@storybook/store": "7.0.0-alpha.7",
69
+ "@storybook/theming": "7.0.0-alpha.7",
70
70
  "babel-loader": "^8.2.5",
71
71
  "core-js": "^3.8.2",
72
72
  "fast-deep-equal": "^3.1.3",
@@ -101,7 +101,7 @@
101
101
  "publishConfig": {
102
102
  "access": "public"
103
103
  },
104
- "gitHead": "a88dcca40ba169a373bad33dd76e9a4bd4f1f5ec",
104
+ "gitHead": "d334cabd251cd0ed8b845a87707dc84f007d4074",
105
105
  "storybook": {
106
106
  "displayName": "Docs",
107
107
  "icon": "https://user-images.githubusercontent.com/263385/101991672-48355c80-3c7c-11eb-82d9-95fa12438f64.png",