@storybook/addon-docs 6.5.7-alpha.0 → 7.0.0-alpha.1

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 (135) hide show
  1. package/blocks.d.ts +1 -1
  2. package/dist/cjs/blocks/ArgsTable.js +1 -1
  3. package/dist/cjs/blocks/Primary.js +1 -1
  4. package/dist/cjs/blocks/Stories.js +1 -1
  5. package/dist/cjs/blocks/mdx.js +1 -1
  6. package/dist/cjs/blocks/useStory.js +18 -4
  7. package/dist/cjs/preset.js +137 -33
  8. package/dist/cjs/preview.js +22 -6
  9. package/dist/esm/blocks/Anchor.js +7 -10
  10. package/dist/esm/blocks/ArgsTable.js +133 -182
  11. package/dist/esm/blocks/Canvas.js +34 -46
  12. package/dist/esm/blocks/Description.js +39 -45
  13. package/dist/esm/blocks/DocsContainer.js +36 -44
  14. package/dist/esm/blocks/DocsContext.js +1 -1
  15. package/dist/esm/blocks/DocsPage.js +3 -5
  16. package/dist/esm/blocks/DocsStory.js +18 -27
  17. package/dist/esm/blocks/Heading.js +5 -7
  18. package/dist/esm/blocks/Meta.js +9 -13
  19. package/dist/esm/blocks/Preview.js +5 -10
  20. package/dist/esm/blocks/Primary.js +10 -16
  21. package/dist/esm/blocks/Props.js +5 -10
  22. package/dist/esm/blocks/Source.js +64 -70
  23. package/dist/esm/blocks/SourceContainer.js +17 -50
  24. package/dist/esm/blocks/Stories.js +15 -27
  25. package/dist/esm/blocks/Story.js +58 -99
  26. package/dist/esm/blocks/Subheading.js +5 -7
  27. package/dist/esm/blocks/Subtitle.js +12 -12
  28. package/dist/esm/blocks/Title.js +10 -11
  29. package/dist/esm/blocks/Wrapper.js +7 -8
  30. package/dist/esm/blocks/enhanceSource.js +32 -56
  31. package/dist/esm/blocks/mdx.js +85 -89
  32. package/dist/esm/blocks/types.js +2 -2
  33. package/dist/esm/blocks/useStory.js +16 -73
  34. package/dist/esm/blocks/utils.js +4 -18
  35. package/dist/esm/manager.js +9 -14
  36. package/dist/esm/preset.js +114 -179
  37. package/dist/esm/preview.js +3 -61
  38. package/dist/esm/shared.js +5 -5
  39. package/dist/{ts3.9 → types}/blocks/Anchor.d.ts +0 -0
  40. package/dist/{ts3.9 → types}/blocks/ArgsTable.d.ts +0 -0
  41. package/dist/{ts3.9 → types}/blocks/Canvas.d.ts +0 -0
  42. package/dist/{ts3.9 → types}/blocks/Description.d.ts +0 -0
  43. package/dist/{ts3.9 → types}/blocks/DocsContainer.d.ts +0 -0
  44. package/dist/{ts3.9 → types}/blocks/DocsContext.d.ts +0 -0
  45. package/dist/{ts3.9 → types}/blocks/DocsPage.d.ts +0 -0
  46. package/dist/{ts3.9 → types}/blocks/DocsStory.d.ts +0 -0
  47. package/dist/{ts3.9 → types}/blocks/Heading.d.ts +0 -0
  48. package/dist/{ts3.9 → types}/blocks/Meta.d.ts +0 -0
  49. package/dist/{ts3.9 → types}/blocks/Preview.d.ts +0 -0
  50. package/dist/{ts3.9 → types}/blocks/Primary.d.ts +0 -0
  51. package/dist/{ts3.9 → types}/blocks/Props.d.ts +0 -0
  52. package/dist/{ts3.9 → types}/blocks/Source.d.ts +0 -0
  53. package/dist/{ts3.9 → types}/blocks/SourceContainer.d.ts +0 -0
  54. package/dist/{ts3.9 → types}/blocks/Stories.d.ts +0 -0
  55. package/dist/{ts3.9 → types}/blocks/Story.d.ts +0 -0
  56. package/dist/{ts3.9 → types}/blocks/Subheading.d.ts +0 -0
  57. package/dist/{ts3.9 → types}/blocks/Subtitle.d.ts +0 -0
  58. package/dist/{ts3.9 → types}/blocks/Title.d.ts +0 -0
  59. package/dist/{ts3.9 → types}/blocks/Wrapper.d.ts +0 -0
  60. package/dist/{ts3.9 → types}/blocks/enhanceSource.d.ts +0 -0
  61. package/dist/{ts3.9 → types}/blocks/index.d.ts +0 -0
  62. package/dist/{ts3.9 → types}/blocks/mdx.d.ts +0 -0
  63. package/dist/{ts3.9 → types}/blocks/types.d.ts +0 -0
  64. package/dist/{ts3.9 → types}/blocks/useStory.d.ts +0 -0
  65. package/dist/{ts3.9 → types}/blocks/utils.d.ts +0 -0
  66. package/dist/{ts3.9 → types}/index.d.ts +0 -0
  67. package/dist/{ts3.9 → types}/manager.d.ts +0 -0
  68. package/dist/{ts3.9 → types}/preset.d.ts +2 -1
  69. package/dist/{ts3.9 → types}/preview.d.ts +0 -0
  70. package/dist/{ts3.9 → types}/shared.d.ts +0 -0
  71. package/package.json +16 -24
  72. package/dist/modern/blocks/Anchor.js +0 -8
  73. package/dist/modern/blocks/ArgsTable.js +0 -292
  74. package/dist/modern/blocks/Canvas.js +0 -83
  75. package/dist/modern/blocks/Description.js +0 -107
  76. package/dist/modern/blocks/DocsContainer.js +0 -98
  77. package/dist/modern/blocks/DocsContext.js +0 -16
  78. package/dist/modern/blocks/DocsPage.js +0 -11
  79. package/dist/modern/blocks/DocsStory.js +0 -48
  80. package/dist/modern/blocks/Heading.js +0 -17
  81. package/dist/modern/blocks/Meta.js +0 -31
  82. package/dist/modern/blocks/Preview.js +0 -9
  83. package/dist/modern/blocks/Primary.js +0 -23
  84. package/dist/modern/blocks/Props.js +0 -14
  85. package/dist/modern/blocks/Source.js +0 -154
  86. package/dist/modern/blocks/SourceContainer.js +0 -44
  87. package/dist/modern/blocks/Stories.js +0 -34
  88. package/dist/modern/blocks/Story.js +0 -168
  89. package/dist/modern/blocks/Subheading.js +0 -17
  90. package/dist/modern/blocks/Subtitle.js +0 -23
  91. package/dist/modern/blocks/Title.js +0 -24
  92. package/dist/modern/blocks/Wrapper.js +0 -8
  93. package/dist/modern/blocks/enhanceSource.js +0 -89
  94. package/dist/modern/blocks/index.js +0 -24
  95. package/dist/modern/blocks/mdx.js +0 -204
  96. package/dist/modern/blocks/types.js +0 -2
  97. package/dist/modern/blocks/useStory.js +0 -28
  98. package/dist/modern/blocks/utils.js +0 -29
  99. package/dist/modern/index.js +0 -1
  100. package/dist/modern/manager.js +0 -16
  101. package/dist/modern/preset.js +0 -130
  102. package/dist/modern/preview.js +0 -6
  103. package/dist/modern/shared.js +0 -11
  104. package/dist/ts3.4/blocks/Anchor.d.ts +0 -6
  105. package/dist/ts3.4/blocks/ArgsTable.d.ts +0 -33
  106. package/dist/ts3.4/blocks/Canvas.d.ts +0 -9
  107. package/dist/ts3.4/blocks/Description.d.ts +0 -20
  108. package/dist/ts3.4/blocks/DocsContainer.d.ts +0 -7
  109. package/dist/ts3.4/blocks/DocsContext.d.ts +0 -5
  110. package/dist/ts3.4/blocks/DocsPage.d.ts +0 -2
  111. package/dist/ts3.4/blocks/DocsStory.d.ts +0 -3
  112. package/dist/ts3.4/blocks/Heading.d.ts +0 -6
  113. package/dist/ts3.4/blocks/Meta.d.ts +0 -9
  114. package/dist/ts3.4/blocks/Preview.d.ts +0 -3
  115. package/dist/ts3.4/blocks/Primary.d.ts +0 -6
  116. package/dist/ts3.4/blocks/Props.d.ts +0 -3
  117. package/dist/ts3.4/blocks/Source.d.ts +0 -38
  118. package/dist/ts3.4/blocks/SourceContainer.d.ts +0 -14
  119. package/dist/ts3.4/blocks/Stories.d.ts +0 -7
  120. package/dist/ts3.4/blocks/Story.d.ts +0 -28
  121. package/dist/ts3.4/blocks/Subheading.d.ts +0 -3
  122. package/dist/ts3.4/blocks/Subtitle.d.ts +0 -6
  123. package/dist/ts3.4/blocks/Title.d.ts +0 -8
  124. package/dist/ts3.4/blocks/Wrapper.d.ts +0 -2
  125. package/dist/ts3.4/blocks/enhanceSource.d.ts +0 -3
  126. package/dist/ts3.4/blocks/index.d.ts +0 -24
  127. package/dist/ts3.4/blocks/mdx.d.ts +0 -20
  128. package/dist/ts3.4/blocks/types.d.ts +0 -13
  129. package/dist/ts3.4/blocks/useStory.d.ts +0 -5
  130. package/dist/ts3.4/blocks/utils.d.ts +0 -3
  131. package/dist/ts3.4/index.d.ts +0 -1
  132. package/dist/ts3.4/manager.d.ts +0 -1
  133. package/dist/ts3.4/preset.d.ts +0 -11
  134. package/dist/ts3.4/preview.d.ts +0 -6
  135. package/dist/ts3.4/shared.d.ts +0 -24
@@ -1,7 +1,3 @@
1
- import "core-js/modules/es.array.filter.js";
2
- import "core-js/modules/es.object.to-string.js";
3
- import "core-js/modules/es.array.map.js";
4
- import "core-js/modules/es.array.join.js";
5
1
  import React, { useContext } from 'react';
6
2
  import { Source as PureSource, SourceError } from '@storybook/components';
7
3
  import { DocsContext } from './DocsContext';
@@ -10,7 +6,7 @@ import { CURRENT_SELECTION } from './types';
10
6
  import { SourceType } from '../shared';
11
7
  import { enhanceSource } from './enhanceSource';
12
8
  import { useStories } from './useStory';
13
- export var SourceState;
9
+ export let SourceState;
14
10
 
15
11
  (function (SourceState) {
16
12
  SourceState["OPEN"] = "open";
@@ -18,40 +14,38 @@ export var SourceState;
18
14
  SourceState["NONE"] = "none";
19
15
  })(SourceState || (SourceState = {}));
20
16
 
21
- var getSourceState = function getSourceState(stories) {
22
- var states = stories.map(function (story) {
23
- var _story$parameters$doc, _story$parameters$doc2;
24
-
25
- 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;
26
- }).filter(Boolean);
17
+ const getSourceState = stories => {
18
+ const states = stories.map(story => story.parameters.docs?.source?.state).filter(Boolean);
27
19
  if (states.length === 0) return SourceState.CLOSED; // FIXME: handling multiple stories is a pain
28
20
 
29
21
  return states[0];
30
22
  };
31
23
 
32
- var getStorySource = function getStorySource(storyId, sourceContext) {
33
- var sources = sourceContext.sources; // source rendering is async so source is unavailable at the start of the render cycle,
24
+ const getStorySource = (storyId, sourceContext) => {
25
+ const {
26
+ sources
27
+ } = sourceContext; // source rendering is async so source is unavailable at the start of the render cycle,
34
28
  // so we fail gracefully here without warning
35
29
 
36
- return (sources === null || sources === void 0 ? void 0 : sources[storyId]) || {
30
+ return sources?.[storyId] || {
37
31
  code: '',
38
32
  format: false
39
33
  };
40
34
  };
41
35
 
42
- var getSnippet = function getSnippet(snippet, story) {
43
- var _parameters$docs, _parameters$docs$sour, _parameters$docs2, _parameters$docs2$sou, _enhanced$docs, _enhanced$docs$source;
44
-
36
+ const getSnippet = (snippet, story) => {
45
37
  if (!story) {
46
38
  return snippet;
47
39
  }
48
40
 
49
- var parameters = story.parameters; // eslint-disable-next-line no-underscore-dangle
41
+ const {
42
+ parameters
43
+ } = story; // eslint-disable-next-line no-underscore-dangle
50
44
 
51
- var isArgsStory = parameters.__isArgsStory;
52
- var 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) || SourceType.AUTO; // if user has hard-coded the snippet, that takes precedence
45
+ const isArgsStory = parameters.__isArgsStory;
46
+ const type = parameters.docs?.source?.type || SourceType.AUTO; // if user has hard-coded the snippet, that takes precedence
53
47
 
54
- var 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;
48
+ const userCode = parameters.docs?.source?.code;
55
49
 
56
50
  if (userCode !== undefined) {
57
51
  return userCode;
@@ -59,42 +53,39 @@ var getSnippet = function getSnippet(snippet, story) {
59
53
 
60
54
 
61
55
  if (type === SourceType.DYNAMIC) {
62
- var _parameters$docs3, _parameters$docs3$tra;
63
-
64
- 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;
56
+ return parameters.docs?.transformSource?.(snippet, story) || snippet;
65
57
  } // if this is an args story and there's a snippet
66
58
 
67
59
 
68
60
  if (type === SourceType.AUTO && snippet && isArgsStory) {
69
- var _parameters$docs4, _parameters$docs4$tra;
70
-
71
- 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;
61
+ return parameters.docs?.transformSource?.(snippet, story) || snippet;
72
62
  } // otherwise, use the source code logic
73
63
 
74
64
 
75
- var enhanced = enhanceSource(story) || parameters;
76
- 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) || '';
65
+ const enhanced = enhanceSource(story) || parameters;
66
+ return enhanced?.docs?.source?.code || '';
77
67
  };
78
68
 
79
- export var getSourceProps = function getSourceProps(props, docsContext, sourceContext) {
80
- var currentId = docsContext.id,
81
- storyById = docsContext.storyById;
82
-
83
- var _storyById = storyById(currentId),
84
- parameters = _storyById.parameters;
85
-
86
- var codeProps = props;
87
- var singleProps = props;
88
- var multiProps = props;
89
- var source = codeProps.code; // prefer user-specified code
90
-
91
- var format = codeProps.format; // prefer user-specified code
92
-
93
- var targetIds = multiProps.ids || [singleProps.id || currentId];
94
- var storyIds = targetIds.map(function (targetId) {
95
- return targetId === CURRENT_SELECTION ? currentId : targetId;
96
- });
97
- var stories = useStories(storyIds, docsContext);
69
+ export const getSourceProps = (props, docsContext, sourceContext) => {
70
+ const {
71
+ id: currentId,
72
+ storyById
73
+ } = docsContext;
74
+ const {
75
+ parameters
76
+ } = storyById(currentId);
77
+ const codeProps = props;
78
+ const singleProps = props;
79
+ const multiProps = props;
80
+ let source = codeProps.code; // prefer user-specified code
81
+
82
+ let {
83
+ format
84
+ } = codeProps; // prefer user-specified code
85
+
86
+ const targetIds = multiProps.ids || [singleProps.id || currentId];
87
+ const storyIds = targetIds.map(targetId => targetId === CURRENT_SELECTION ? currentId : targetId);
88
+ const stories = useStories(storyIds, docsContext);
98
89
 
99
90
  if (!stories.every(Boolean)) {
100
91
  return {
@@ -106,34 +97,37 @@ export var getSourceProps = function getSourceProps(props, docsContext, sourceCo
106
97
  if (!source) {
107
98
  // just take the format from the first story, given how they're all concatinated together...
108
99
  // TODO: we should consider sending an event with all the sources separately, instead of concatenating them here
109
- var _getStorySource = getStorySource(storyIds[0], sourceContext);
110
-
111
- format = _getStorySource.format;
112
- source = storyIds.map(function (storyId, idx) {
113
- var _getStorySource2 = getStorySource(storyId, sourceContext),
114
- storySource = _getStorySource2.code;
115
-
116
- var storyObj = stories[idx];
100
+ ({
101
+ format
102
+ } = getStorySource(storyIds[0], sourceContext));
103
+ source = storyIds.map((storyId, idx) => {
104
+ const {
105
+ code: storySource
106
+ } = getStorySource(storyId, sourceContext);
107
+ const storyObj = stories[idx];
117
108
  return getSnippet(storySource, storyObj);
118
109
  }).join('\n\n');
119
110
  }
120
111
 
121
- var state = getSourceState(stories);
122
- var _parameters$docs5 = parameters.docs,
123
- docsParameters = _parameters$docs5 === void 0 ? {} : _parameters$docs5;
124
- var _docsParameters$sourc = docsParameters.source,
125
- sourceParameters = _docsParameters$sourc === void 0 ? {} : _docsParameters$sourc;
126
- var _sourceParameters$lan = sourceParameters.language,
127
- docsLanguage = _sourceParameters$lan === void 0 ? null : _sourceParameters$lan;
112
+ const state = getSourceState(stories);
113
+ const {
114
+ docs: docsParameters = {}
115
+ } = parameters;
116
+ const {
117
+ source: sourceParameters = {}
118
+ } = docsParameters;
119
+ const {
120
+ language: docsLanguage = null
121
+ } = sourceParameters;
128
122
  return source ? {
129
123
  code: source,
130
- state: state,
131
- format: format,
124
+ state,
125
+ format,
132
126
  language: props.language || docsLanguage || 'jsx',
133
127
  dark: props.dark || false
134
128
  } : {
135
129
  error: SourceError.SOURCE_UNAVAILABLE,
136
- state: state
130
+ state
137
131
  };
138
132
  };
139
133
  /**
@@ -142,9 +136,9 @@ export var getSourceProps = function getSourceProps(props, docsContext, sourceCo
142
136
  * the source for the current story if nothing is provided.
143
137
  */
144
138
 
145
- export var Source = function Source(props) {
146
- var sourceContext = useContext(SourceContext);
147
- var docsContext = useContext(DocsContext);
148
- var sourceProps = getSourceProps(props, docsContext, sourceContext);
139
+ export const Source = props => {
140
+ const sourceContext = useContext(SourceContext);
141
+ const docsContext = useContext(DocsContext);
142
+ const sourceProps = getSourceProps(props, docsContext, sourceContext);
149
143
  return /*#__PURE__*/React.createElement(PureSource, sourceProps);
150
144
  };
@@ -1,60 +1,29 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
3
- import "core-js/modules/es.object.assign.js";
4
- import "core-js/modules/es.symbol.js";
5
- import "core-js/modules/es.symbol.description.js";
6
- import "core-js/modules/es.object.to-string.js";
7
- import "core-js/modules/es.symbol.iterator.js";
8
- import "core-js/modules/es.array.iterator.js";
9
- import "core-js/modules/es.string.iterator.js";
10
- import "core-js/modules/web.dom-collections.iterator.js";
11
- import "core-js/modules/es.array.slice.js";
12
- import "core-js/modules/es.function.name.js";
13
- import "core-js/modules/es.array.from.js";
14
- import "core-js/modules/es.regexp.exec.js";
15
-
16
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
17
-
18
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
19
-
20
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
21
-
22
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
23
-
24
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
25
-
26
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
27
-
28
1
  import React, { createContext, useEffect, useState } from 'react';
29
2
  import deepEqual from 'fast-deep-equal';
30
3
  import { addons } from '@storybook/addons';
31
4
  import { SNIPPET_RENDERED } from '../shared';
32
- export var SourceContext = /*#__PURE__*/createContext({
5
+ export const SourceContext = /*#__PURE__*/createContext({
33
6
  sources: {}
34
7
  });
35
- export var SourceContainer = function SourceContainer(_ref) {
36
- var children = _ref.children;
37
-
38
- var _useState = useState({}),
39
- _useState2 = _slicedToArray(_useState, 2),
40
- sources = _useState2[0],
41
- setSources = _useState2[1];
42
-
43
- var channel = addons.getChannel();
44
- useEffect(function () {
45
- var handleSnippetRendered = function handleSnippetRendered(id, newSource) {
46
- var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
47
-
8
+ export const SourceContainer = ({
9
+ children
10
+ }) => {
11
+ const [sources, setSources] = useState({});
12
+ const channel = addons.getChannel();
13
+ useEffect(() => {
14
+ const handleSnippetRendered = (id, newSource, format = false) => {
48
15
  // optimization: if the source is the same, ignore the incoming event
49
16
  if (sources[id] && sources[id].code === newSource) {
50
17
  return;
51
18
  }
52
19
 
53
- setSources(function (current) {
54
- var newSources = Object.assign({}, current, _defineProperty({}, id, {
55
- code: newSource,
56
- format: format
57
- }));
20
+ setSources(current => {
21
+ const newSources = Object.assign({}, current, {
22
+ [id]: {
23
+ code: newSource,
24
+ format
25
+ }
26
+ });
58
27
 
59
28
  if (!deepEqual(current, newSources)) {
60
29
  return newSources;
@@ -65,13 +34,11 @@ export var SourceContainer = function SourceContainer(_ref) {
65
34
  };
66
35
 
67
36
  channel.on(SNIPPET_RENDERED, handleSnippetRendered);
68
- return function () {
69
- return channel.off(SNIPPET_RENDERED, handleSnippetRendered);
70
- };
37
+ return () => channel.off(SNIPPET_RENDERED, handleSnippetRendered);
71
38
  }, []);
72
39
  return /*#__PURE__*/React.createElement(SourceContext.Provider, {
73
40
  value: {
74
- sources: sources
41
+ sources
75
42
  }
76
43
  }, children);
77
44
  };
@@ -1,41 +1,29 @@
1
- function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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
2
 
3
- import "core-js/modules/es.array.filter.js";
4
- import "core-js/modules/es.object.to-string.js";
5
- import "core-js/modules/es.array.slice.js";
6
- import "core-js/modules/es.array.map.js";
7
- import "core-js/modules/es.object.assign.js";
8
3
  import React, { useContext } from 'react';
9
4
  import { DocsContext } from './DocsContext';
10
5
  import { DocsStory } from './DocsStory';
11
6
  import { Heading } from './Heading';
12
- export var Stories = function Stories(_ref) {
13
- var title = _ref.title,
14
- _ref$includePrimary = _ref.includePrimary,
15
- includePrimary = _ref$includePrimary === void 0 ? false : _ref$includePrimary;
16
-
17
- var _useContext = useContext(DocsContext),
18
- componentStories = _useContext.componentStories;
19
-
20
- var stories = componentStories();
21
- stories = stories.filter(function (story) {
22
- var _story$parameters, _story$parameters$doc;
23
-
24
- 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);
25
- });
7
+ export const Stories = ({
8
+ title,
9
+ includePrimary = false
10
+ }) => {
11
+ const {
12
+ componentStories
13
+ } = useContext(DocsContext);
14
+ let stories = componentStories();
15
+ stories = stories.filter(story => !story.parameters?.docs?.disable);
26
16
  if (!includePrimary) stories = stories.slice(1);
27
17
 
28
18
  if (!stories || stories.length === 0) {
29
19
  return null;
30
20
  }
31
21
 
32
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Heading, null, title), stories.map(function (story) {
33
- return story && /*#__PURE__*/React.createElement(DocsStory, _extends({
34
- key: story.id
35
- }, story, {
36
- expanded: true
37
- }));
38
- }));
22
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Heading, null, title), stories.map(story => story && /*#__PURE__*/React.createElement(DocsStory, _extends({
23
+ key: story.id
24
+ }, story, {
25
+ expanded: true
26
+ }))));
39
27
  };
40
28
  Stories.defaultProps = {
41
29
  title: 'Stories'
@@ -1,29 +1,3 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
-
3
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
-
5
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
-
7
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
8
-
9
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
10
-
11
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
-
13
- import "core-js/modules/es.function.name.js";
14
- import "core-js/modules/es.object.assign.js";
15
- import "core-js/modules/es.object.to-string.js";
16
- import "core-js/modules/es.promise.js";
17
- import "core-js/modules/es.array.iterator.js";
18
- import "core-js/modules/es.string.iterator.js";
19
- import "core-js/modules/web.dom-collections.iterator.js";
20
- import "core-js/modules/es.array.concat.js";
21
- import "core-js/modules/es.symbol.js";
22
- import "core-js/modules/es.symbol.description.js";
23
- import "core-js/modules/es.symbol.iterator.js";
24
- import "core-js/modules/es.array.slice.js";
25
- import "core-js/modules/es.array.from.js";
26
- import "core-js/modules/es.regexp.exec.js";
27
1
  import React, { useContext, useRef, useEffect, useState } from 'react';
28
2
  import { MDXProvider } from '@mdx-js/react';
29
3
  import global from 'global';
@@ -34,48 +8,51 @@ import Events from '@storybook/core-events';
34
8
  import { CURRENT_SELECTION } from './types';
35
9
  import { DocsContext } from './DocsContext';
36
10
  import { useStory } from './useStory';
37
- export var storyBlockIdFromId = function storyBlockIdFromId(storyId) {
38
- return "story--".concat(storyId);
39
- };
40
- export var lookupStoryId = function lookupStoryId(storyName, _ref) {
41
- var mdxStoryNameToKey = _ref.mdxStoryNameToKey,
42
- mdxComponentAnnotations = _ref.mdxComponentAnnotations;
43
- return toId(mdxComponentAnnotations.id || mdxComponentAnnotations.title, storyNameFromExport(mdxStoryNameToKey[storyName]));
44
- };
45
- export var getStoryId = function getStoryId(props, context) {
46
- var _ref2 = props,
47
- id = _ref2.id;
48
- var _ref3 = props,
49
- name = _ref3.name;
50
- var inputId = id === CURRENT_SELECTION ? context.id : id;
11
+ export const storyBlockIdFromId = storyId => `story--${storyId}`;
12
+ export const lookupStoryId = (storyName, {
13
+ mdxStoryNameToKey,
14
+ mdxComponentAnnotations
15
+ }) => toId(mdxComponentAnnotations.id || mdxComponentAnnotations.title, storyNameFromExport(mdxStoryNameToKey[storyName]));
16
+ export const getStoryId = (props, context) => {
17
+ const {
18
+ id
19
+ } = props;
20
+ const {
21
+ name
22
+ } = props;
23
+ const inputId = id === CURRENT_SELECTION ? context.id : id;
51
24
  return inputId || lookupStoryId(name, context);
52
25
  };
53
- export var getStoryProps = function getStoryProps(_ref4, story, context, onStoryFnCalled) {
54
- var height = _ref4.height,
55
- inline = _ref4.inline;
56
- var storyName = story.name,
57
- parameters = story.parameters;
58
- var _parameters$docs = parameters.docs,
59
- docs = _parameters$docs === void 0 ? {} : _parameters$docs;
26
+ export const getStoryProps = ({
27
+ height,
28
+ inline
29
+ }, story, context, onStoryFnCalled) => {
30
+ const {
31
+ name: storyName,
32
+ parameters
33
+ } = story;
34
+ const {
35
+ docs = {}
36
+ } = parameters;
60
37
 
61
38
  if (docs.disable) {
62
39
  return null;
63
40
  } // prefer block props, then story parameters defined by the framework-specific settings and optionally overridden by users
64
41
 
65
42
 
66
- var _docs$inlineStories = docs.inlineStories,
67
- inlineStories = _docs$inlineStories === void 0 ? false : _docs$inlineStories,
68
- _docs$iframeHeight = docs.iframeHeight,
69
- iframeHeight = _docs$iframeHeight === void 0 ? 100 : _docs$iframeHeight,
70
- prepareForInline = docs.prepareForInline;
71
- var storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
43
+ const {
44
+ inlineStories = false,
45
+ iframeHeight = 100,
46
+ prepareForInline
47
+ } = docs;
48
+ const storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
72
49
 
73
50
  if (storyIsInline && !prepareForInline) {
74
- throw new Error("Story '".concat(storyName, "' is set to render inline, but no 'prepareForInline' function is implemented in your docs configuration!"));
51
+ throw new Error(`Story '${storyName}' is set to render inline, but no 'prepareForInline' function is implemented in your docs configuration!`);
75
52
  }
76
53
 
77
- var boundStoryFn = function boundStoryFn() {
78
- var storyResult = story.unboundStoryFn(Object.assign({}, context.getStoryContext(story), {
54
+ const boundStoryFn = () => {
55
+ const storyResult = story.unboundStoryFn(Object.assign({}, context.getStoryContext(story), {
79
56
  loaded: {},
80
57
  abortSignal: undefined,
81
58
  canvasElement: undefined
@@ -94,76 +71,56 @@ export var getStoryProps = function getStoryProps(_ref4, story, context, onStory
94
71
  height: height || (storyIsInline ? undefined : iframeHeight),
95
72
  title: storyName
96
73
  }, storyIsInline && {
97
- parameters: parameters,
98
- storyFn: function storyFn() {
99
- return prepareForInline(boundStoryFn, context.getStoryContext(story));
100
- }
74
+ parameters,
75
+ storyFn: () => prepareForInline(boundStoryFn, context.getStoryContext(story))
101
76
  });
102
77
  };
103
78
 
104
79
  function makeGate() {
105
- var open;
106
- var gate = new Promise(function (r) {
80
+ let open;
81
+ const gate = new Promise(r => {
107
82
  open = r;
108
83
  });
109
84
  return [gate, open];
110
85
  }
111
86
 
112
- var Story = function Story(props) {
113
- var context = useContext(DocsContext);
114
- var channel = addons.getChannel();
115
- var storyRef = useRef();
116
- var storyId = getStoryId(props, context);
117
- var story = useStory(storyId, context);
118
-
119
- var _useState = useState(true),
120
- _useState2 = _slicedToArray(_useState, 2),
121
- showLoader = _useState2[0],
122
- setShowLoader = _useState2[1];
123
-
124
- useEffect(function () {
125
- var cleanup;
87
+ const Story = props => {
88
+ const context = useContext(DocsContext);
89
+ const channel = addons.getChannel();
90
+ const storyRef = useRef();
91
+ const storyId = getStoryId(props, context);
92
+ const story = useStory(storyId, context);
93
+ const [showLoader, setShowLoader] = useState(true);
94
+ useEffect(() => {
95
+ let cleanup;
126
96
 
127
97
  if (story && storyRef.current) {
128
- var element = storyRef.current;
98
+ const element = storyRef.current;
129
99
  cleanup = context.renderStoryToElement(story, element);
130
100
  setShowLoader(false);
131
101
  }
132
102
 
133
- return function () {
134
- return cleanup && cleanup();
135
- };
103
+ return () => cleanup && cleanup();
136
104
  }, [story]);
137
-
138
- var _makeGate = makeGate(),
139
- _makeGate2 = _slicedToArray(_makeGate, 2),
140
- storyFnRan = _makeGate2[0],
141
- onStoryFnRan = _makeGate2[1];
142
-
143
- var _makeGate3 = makeGate(),
144
- _makeGate4 = _slicedToArray(_makeGate3, 2),
145
- rendered = _makeGate4[0],
146
- onRendered = _makeGate4[1];
147
-
105
+ const [storyFnRan, onStoryFnRan] = makeGate();
106
+ const [rendered, onRendered] = makeGate();
148
107
  useEffect(onRendered);
149
108
 
150
109
  if (!story) {
151
110
  return /*#__PURE__*/React.createElement(StorySkeleton, null);
152
111
  }
153
112
 
154
- var storyProps = getStoryProps(props, story, context, onStoryFnRan);
113
+ const storyProps = getStoryProps(props, story, context, onStoryFnRan);
155
114
 
156
115
  if (!storyProps) {
157
116
  return null;
158
117
  }
159
118
 
160
119
  if (storyProps.inline) {
161
- var _global$FEATURES;
162
-
163
120
  // If we are rendering a old-style inline Story via `PureStory` below, we want to emit
164
121
  // the `STORY_RENDERED` event when it renders. The modern mode below calls out to
165
122
  // `Preview.renderStoryToDom()` which itself emits the event.
166
- if (!(global !== null && global !== void 0 && (_global$FEATURES = global.FEATURES) !== null && _global$FEATURES !== void 0 && _global$FEATURES.modernInlineRender)) {
123
+ if (!global?.FEATURES?.modernInlineRender) {
167
124
  // We need to wait for two things before we can consider the story rendered:
168
125
  // (a) React's `useEffect` hook needs to fire. This is needed for React stories, as
169
126
  // decorators of the form `<A><B/></A>` will not actually execute `B` in the first
@@ -171,19 +128,21 @@ var Story = function Story(props) {
171
128
  // (b) The story function needs to actually have been called.
172
129
  // Certain frameworks (i.e.angular) don't actually render the component in the very first
173
130
  // React render cycle, so we need to wait for the framework to actually do that
174
- Promise.all([storyFnRan, rendered]).then(function () {
131
+ Promise.all([storyFnRan, rendered]).then(() => {
175
132
  channel.emit(Events.STORY_RENDERED, storyId);
176
133
  });
177
134
  } else {
178
135
  // We do this so React doesn't complain when we replace the span in a secondary render
179
- var htmlContents = "<span></span>"; // FIXME: height/style/etc. lifted from PureStory
136
+ const htmlContents = `<span></span>`; // FIXME: height/style/etc. lifted from PureStory
180
137
 
181
- var height = storyProps.height;
138
+ const {
139
+ height
140
+ } = storyProps;
182
141
  return /*#__PURE__*/React.createElement("div", {
183
142
  id: storyBlockIdFromId(story.id)
184
143
  }, /*#__PURE__*/React.createElement(MDXProvider, {
185
144
  components: resetComponents
186
- }, height ? /*#__PURE__*/React.createElement("style", null, "#story--".concat(story.id, " { min-height: ").concat(height, "; transform: translateZ(0); overflow: auto }")) : null, showLoader && /*#__PURE__*/React.createElement(StorySkeleton, null), /*#__PURE__*/React.createElement("div", {
145
+ }, height ? /*#__PURE__*/React.createElement("style", null, `#story--${story.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`) : null, showLoader && /*#__PURE__*/React.createElement(StorySkeleton, null), /*#__PURE__*/React.createElement("div", {
187
146
  ref: storyRef,
188
147
  "data-name": story.name,
189
148
  dangerouslySetInnerHTML: {
@@ -1,17 +1,15 @@
1
- import "core-js/modules/es.regexp.exec.js";
2
- import "core-js/modules/es.string.replace.js";
3
1
  import React from 'react';
4
2
  import { H3 } from '@storybook/components';
5
3
  import { HeaderMdx } from './mdx';
6
- export var Subheading = function Subheading(_ref) {
7
- var children = _ref.children,
8
- disableAnchor = _ref.disableAnchor;
9
-
4
+ export const Subheading = ({
5
+ children,
6
+ disableAnchor
7
+ }) => {
10
8
  if (disableAnchor || typeof children !== 'string') {
11
9
  return /*#__PURE__*/React.createElement(H3, null, children);
12
10
  }
13
11
 
14
- var tagID = children.toLowerCase().replace(/[^a-z0-9]/gi, '-');
12
+ const tagID = children.toLowerCase().replace(/[^a-z0-9]/gi, '-');
15
13
  return /*#__PURE__*/React.createElement(HeaderMdx, {
16
14
  as: "h3",
17
15
  id: tagID
@@ -1,20 +1,20 @@
1
1
  import React, { useContext } from 'react';
2
2
  import { Subtitle as PureSubtitle } from '@storybook/components';
3
3
  import { DocsContext } from './DocsContext';
4
- export var Subtitle = function Subtitle(_ref) {
5
- var children = _ref.children;
6
-
7
- var _useContext = useContext(DocsContext),
8
- id = _useContext.id,
9
- storyById = _useContext.storyById;
10
-
11
- var _storyById = storyById(id),
12
- parameters = _storyById.parameters;
13
-
14
- var text = children;
4
+ export const Subtitle = ({
5
+ children
6
+ }) => {
7
+ const {
8
+ id,
9
+ storyById
10
+ } = useContext(DocsContext);
11
+ const {
12
+ parameters
13
+ } = storyById(id);
14
+ let text = children;
15
15
 
16
16
  if (!text) {
17
- text = parameters === null || parameters === void 0 ? void 0 : parameters.componentSubtitle;
17
+ text = parameters?.componentSubtitle;
18
18
  }
19
19
 
20
20
  return text ? /*#__PURE__*/React.createElement(PureSubtitle, {