@storybook/addon-docs 6.5.9 → 7.0.0-alpha.2

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 (160) hide show
  1. package/blocks.d.ts +1 -1
  2. package/dist/cjs/blocks/Anchor.js +7 -10
  3. package/dist/cjs/blocks/ArgsTable.js +135 -206
  4. package/dist/cjs/blocks/Canvas.js +38 -73
  5. package/dist/cjs/blocks/Description.js +41 -68
  6. package/dist/cjs/blocks/DocsContainer.js +40 -68
  7. package/dist/cjs/blocks/DocsContext.js +1 -1
  8. package/dist/cjs/blocks/DocsPage.js +3 -5
  9. package/dist/cjs/blocks/DocsStory.js +18 -28
  10. package/dist/cjs/blocks/Heading.js +5 -9
  11. package/dist/cjs/blocks/Meta.js +11 -33
  12. package/dist/cjs/blocks/Preview.js +4 -10
  13. package/dist/cjs/blocks/Primary.js +12 -40
  14. package/dist/cjs/blocks/Props.js +4 -10
  15. package/dist/cjs/blocks/Source.js +62 -80
  16. package/dist/cjs/blocks/SourceContainer.js +19 -68
  17. package/dist/cjs/blocks/Stories.js +17 -48
  18. package/dist/cjs/blocks/Story.js +60 -180
  19. package/dist/cjs/blocks/Subheading.js +5 -9
  20. package/dist/cjs/blocks/Subtitle.js +15 -35
  21. package/dist/cjs/blocks/Title.js +12 -36
  22. package/dist/cjs/blocks/Wrapper.js +7 -8
  23. package/dist/cjs/blocks/enhanceSource.js +30 -67
  24. package/dist/cjs/blocks/index.js +28 -34
  25. package/dist/cjs/blocks/mdx.js +86 -97
  26. package/dist/cjs/blocks/types.js +2 -2
  27. package/dist/cjs/blocks/useStory.js +16 -87
  28. package/dist/cjs/blocks/utils.js +4 -25
  29. package/dist/cjs/index.js +1 -7
  30. package/dist/cjs/manager.js +9 -15
  31. package/dist/cjs/preset.js +129 -193
  32. package/dist/cjs/preview.js +5 -87
  33. package/dist/cjs/shared.js +5 -5
  34. package/dist/esm/blocks/Anchor.js +7 -10
  35. package/dist/esm/blocks/ArgsTable.js +133 -182
  36. package/dist/esm/blocks/Canvas.js +34 -46
  37. package/dist/esm/blocks/Description.js +39 -45
  38. package/dist/esm/blocks/DocsContainer.js +36 -44
  39. package/dist/esm/blocks/DocsContext.js +1 -1
  40. package/dist/esm/blocks/DocsPage.js +3 -5
  41. package/dist/esm/blocks/DocsStory.js +18 -27
  42. package/dist/esm/blocks/Heading.js +5 -7
  43. package/dist/esm/blocks/Meta.js +9 -13
  44. package/dist/esm/blocks/Preview.js +5 -10
  45. package/dist/esm/blocks/Primary.js +10 -16
  46. package/dist/esm/blocks/Props.js +5 -10
  47. package/dist/esm/blocks/Source.js +64 -70
  48. package/dist/esm/blocks/SourceContainer.js +17 -50
  49. package/dist/esm/blocks/Stories.js +15 -27
  50. package/dist/esm/blocks/Story.js +58 -151
  51. package/dist/esm/blocks/Subheading.js +5 -7
  52. package/dist/esm/blocks/Subtitle.js +12 -12
  53. package/dist/esm/blocks/Title.js +10 -11
  54. package/dist/esm/blocks/Wrapper.js +7 -8
  55. package/dist/esm/blocks/enhanceSource.js +32 -56
  56. package/dist/esm/blocks/mdx.js +85 -89
  57. package/dist/esm/blocks/types.js +2 -2
  58. package/dist/esm/blocks/useStory.js +16 -73
  59. package/dist/esm/blocks/utils.js +4 -18
  60. package/dist/esm/manager.js +9 -14
  61. package/dist/esm/preset.js +114 -179
  62. package/dist/esm/preview.js +3 -61
  63. package/dist/esm/shared.js +5 -5
  64. package/dist/{ts3.9 → types}/blocks/Anchor.d.ts +0 -0
  65. package/dist/{ts3.9 → types}/blocks/ArgsTable.d.ts +0 -0
  66. package/dist/{ts3.9 → types}/blocks/Canvas.d.ts +0 -0
  67. package/dist/{ts3.9 → types}/blocks/Description.d.ts +0 -0
  68. package/dist/{ts3.9 → types}/blocks/DocsContainer.d.ts +0 -0
  69. package/dist/{ts3.9 → types}/blocks/DocsContext.d.ts +0 -0
  70. package/dist/{ts3.9 → types}/blocks/DocsPage.d.ts +0 -0
  71. package/dist/{ts3.9 → types}/blocks/DocsStory.d.ts +0 -0
  72. package/dist/{ts3.9 → types}/blocks/Heading.d.ts +0 -0
  73. package/dist/{ts3.9 → types}/blocks/Meta.d.ts +0 -0
  74. package/dist/{ts3.9 → types}/blocks/Preview.d.ts +0 -0
  75. package/dist/{ts3.9 → types}/blocks/Primary.d.ts +0 -0
  76. package/dist/{ts3.9 → types}/blocks/Props.d.ts +0 -0
  77. package/dist/{ts3.9 → types}/blocks/Source.d.ts +0 -0
  78. package/dist/{ts3.9 → types}/blocks/SourceContainer.d.ts +0 -0
  79. package/dist/{ts3.9 → types}/blocks/Stories.d.ts +0 -0
  80. package/dist/{ts3.9 → types}/blocks/Story.d.ts +2 -2
  81. package/dist/{ts3.9 → types}/blocks/Subheading.d.ts +0 -0
  82. package/dist/{ts3.9 → types}/blocks/Subtitle.d.ts +0 -0
  83. package/dist/{ts3.9 → types}/blocks/Title.d.ts +0 -0
  84. package/dist/{ts3.9 → types}/blocks/Wrapper.d.ts +0 -0
  85. package/dist/{ts3.9 → types}/blocks/enhanceSource.d.ts +0 -0
  86. package/dist/{ts3.9 → types}/blocks/index.d.ts +0 -0
  87. package/dist/{ts3.9 → types}/blocks/mdx.d.ts +0 -0
  88. package/dist/{ts3.9 → types}/blocks/types.d.ts +0 -0
  89. package/dist/{ts3.9 → types}/blocks/useStory.d.ts +0 -0
  90. package/dist/{ts3.9 → types}/blocks/utils.d.ts +0 -0
  91. package/dist/{ts3.9 → types}/index.d.ts +0 -0
  92. package/dist/{ts3.9 → types}/manager.d.ts +0 -0
  93. package/dist/{ts3.9 → types}/preset.d.ts +2 -1
  94. package/dist/{ts3.9 → types}/preview.d.ts +0 -0
  95. package/dist/{ts3.9 → types}/shared.d.ts +0 -0
  96. package/package.json +17 -24
  97. package/dist/modern/blocks/Anchor.js +0 -8
  98. package/dist/modern/blocks/ArgsTable.js +0 -292
  99. package/dist/modern/blocks/Canvas.js +0 -83
  100. package/dist/modern/blocks/Description.js +0 -107
  101. package/dist/modern/blocks/DocsContainer.js +0 -98
  102. package/dist/modern/blocks/DocsContext.js +0 -16
  103. package/dist/modern/blocks/DocsPage.js +0 -11
  104. package/dist/modern/blocks/DocsStory.js +0 -48
  105. package/dist/modern/blocks/Heading.js +0 -17
  106. package/dist/modern/blocks/Meta.js +0 -31
  107. package/dist/modern/blocks/Preview.js +0 -9
  108. package/dist/modern/blocks/Primary.js +0 -23
  109. package/dist/modern/blocks/Props.js +0 -14
  110. package/dist/modern/blocks/Source.js +0 -154
  111. package/dist/modern/blocks/SourceContainer.js +0 -44
  112. package/dist/modern/blocks/Stories.js +0 -34
  113. package/dist/modern/blocks/Story.js +0 -168
  114. package/dist/modern/blocks/Subheading.js +0 -17
  115. package/dist/modern/blocks/Subtitle.js +0 -23
  116. package/dist/modern/blocks/Title.js +0 -24
  117. package/dist/modern/blocks/Wrapper.js +0 -8
  118. package/dist/modern/blocks/enhanceSource.js +0 -89
  119. package/dist/modern/blocks/index.js +0 -24
  120. package/dist/modern/blocks/mdx.js +0 -204
  121. package/dist/modern/blocks/types.js +0 -2
  122. package/dist/modern/blocks/useStory.js +0 -28
  123. package/dist/modern/blocks/utils.js +0 -29
  124. package/dist/modern/index.js +0 -1
  125. package/dist/modern/manager.js +0 -16
  126. package/dist/modern/preset.js +0 -130
  127. package/dist/modern/preview.js +0 -6
  128. package/dist/modern/shared.js +0 -11
  129. package/dist/ts3.4/blocks/Anchor.d.ts +0 -6
  130. package/dist/ts3.4/blocks/ArgsTable.d.ts +0 -33
  131. package/dist/ts3.4/blocks/Canvas.d.ts +0 -9
  132. package/dist/ts3.4/blocks/Description.d.ts +0 -20
  133. package/dist/ts3.4/blocks/DocsContainer.d.ts +0 -7
  134. package/dist/ts3.4/blocks/DocsContext.d.ts +0 -5
  135. package/dist/ts3.4/blocks/DocsPage.d.ts +0 -2
  136. package/dist/ts3.4/blocks/DocsStory.d.ts +0 -3
  137. package/dist/ts3.4/blocks/Heading.d.ts +0 -6
  138. package/dist/ts3.4/blocks/Meta.d.ts +0 -9
  139. package/dist/ts3.4/blocks/Preview.d.ts +0 -3
  140. package/dist/ts3.4/blocks/Primary.d.ts +0 -6
  141. package/dist/ts3.4/blocks/Props.d.ts +0 -3
  142. package/dist/ts3.4/blocks/Source.d.ts +0 -38
  143. package/dist/ts3.4/blocks/SourceContainer.d.ts +0 -14
  144. package/dist/ts3.4/blocks/Stories.d.ts +0 -7
  145. package/dist/ts3.4/blocks/Story.d.ts +0 -28
  146. package/dist/ts3.4/blocks/Subheading.d.ts +0 -3
  147. package/dist/ts3.4/blocks/Subtitle.d.ts +0 -6
  148. package/dist/ts3.4/blocks/Title.d.ts +0 -8
  149. package/dist/ts3.4/blocks/Wrapper.d.ts +0 -2
  150. package/dist/ts3.4/blocks/enhanceSource.d.ts +0 -3
  151. package/dist/ts3.4/blocks/index.d.ts +0 -24
  152. package/dist/ts3.4/blocks/mdx.d.ts +0 -20
  153. package/dist/ts3.4/blocks/types.d.ts +0 -13
  154. package/dist/ts3.4/blocks/useStory.d.ts +0 -5
  155. package/dist/ts3.4/blocks/utils.d.ts +0 -3
  156. package/dist/ts3.4/index.d.ts +0 -1
  157. package/dist/ts3.4/manager.d.ts +0 -1
  158. package/dist/ts3.4/preset.d.ts +0 -11
  159. package/dist/ts3.4/preview.d.ts +0 -6
  160. 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,196 +1,103 @@
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
- import global from 'global';
30
3
  import { resetComponents, Story as PureStory, StorySkeleton } from '@storybook/components';
31
4
  import { toId, storyNameFromExport } from '@storybook/csf';
32
- import { addons } from '@storybook/addons';
33
- import Events from '@storybook/core-events';
34
5
  import { CURRENT_SELECTION } from './types';
35
6
  import { DocsContext } from './DocsContext';
36
7
  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;
8
+ export const storyBlockIdFromId = storyId => `story--${storyId}`;
9
+ export const lookupStoryId = (storyName, {
10
+ mdxStoryNameToKey,
11
+ mdxComponentAnnotations
12
+ }) => toId(mdxComponentAnnotations.id || mdxComponentAnnotations.title, storyNameFromExport(mdxStoryNameToKey[storyName]));
13
+ export const getStoryId = (props, context) => {
14
+ const {
15
+ id
16
+ } = props;
17
+ const {
18
+ name
19
+ } = props;
20
+ const inputId = id === CURRENT_SELECTION ? context.id : id;
51
21
  return inputId || lookupStoryId(name, context);
52
22
  };
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;
23
+ export const getStoryProps = ({
24
+ height,
25
+ inline
26
+ }, story) => {
27
+ const {
28
+ name: storyName,
29
+ parameters
30
+ } = story;
31
+ const {
32
+ docs = {}
33
+ } = parameters;
60
34
 
61
35
  if (docs.disable) {
62
36
  return null;
63
37
  } // prefer block props, then story parameters defined by the framework-specific settings and optionally overridden by users
64
38
 
65
39
 
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;
72
-
73
- 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!"));
75
- }
76
-
77
- var boundStoryFn = function boundStoryFn() {
78
- var storyResult = story.unboundStoryFn(Object.assign({}, context.getStoryContext(story), {
79
- loaded: {},
80
- abortSignal: undefined,
81
- canvasElement: undefined
82
- })); // We need to wait until the bound story function has actually been called before we
83
- // consider the story rendered. Certain frameworks (i.e. angular) don't actually render
84
- // the component in the very first react render cycle, and so we can't just wait until the
85
- // `PureStory` component has been rendered to consider the underlying story "rendered".
86
-
87
- onStoryFnCalled();
88
- return storyResult;
89
- };
90
-
40
+ const {
41
+ inlineStories = false,
42
+ iframeHeight = 100
43
+ } = docs;
44
+ const storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
91
45
  return Object.assign({
92
46
  inline: storyIsInline,
93
47
  id: story.id,
94
48
  height: height || (storyIsInline ? undefined : iframeHeight),
95
49
  title: storyName
96
50
  }, storyIsInline && {
97
- parameters: parameters,
98
- storyFn: function storyFn() {
99
- return prepareForInline(boundStoryFn, context.getStoryContext(story));
100
- }
51
+ parameters
101
52
  });
102
53
  };
103
54
 
104
- function makeGate() {
105
- var open;
106
- var gate = new Promise(function (r) {
107
- open = r;
108
- });
109
- return [gate, open];
110
- }
111
-
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;
55
+ const Story = props => {
56
+ const context = useContext(DocsContext);
57
+ const storyRef = useRef();
58
+ const storyId = getStoryId(props, context);
59
+ const story = useStory(storyId, context);
60
+ const [showLoader, setShowLoader] = useState(true);
61
+ useEffect(() => {
62
+ let cleanup;
126
63
 
127
64
  if (story && storyRef.current) {
128
- var element = storyRef.current;
65
+ const element = storyRef.current;
129
66
  cleanup = context.renderStoryToElement(story, element);
130
67
  setShowLoader(false);
131
68
  }
132
69
 
133
- return function () {
134
- return cleanup && cleanup();
135
- };
70
+ return () => cleanup && cleanup();
136
71
  }, [story]);
137
72
 
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
-
148
- useEffect(onRendered);
149
-
150
73
  if (!story) {
151
74
  return /*#__PURE__*/React.createElement(StorySkeleton, null);
152
75
  }
153
76
 
154
- var storyProps = getStoryProps(props, story, context, onStoryFnRan);
77
+ const storyProps = getStoryProps(props, story);
155
78
 
156
79
  if (!storyProps) {
157
80
  return null;
158
81
  }
159
82
 
160
83
  if (storyProps.inline) {
161
- var _global$FEATURES;
162
-
163
- // If we are rendering a old-style inline Story via `PureStory` below, we want to emit
164
- // the `STORY_RENDERED` event when it renders. The modern mode below calls out to
165
- // `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)) {
167
- // We need to wait for two things before we can consider the story rendered:
168
- // (a) React's `useEffect` hook needs to fire. This is needed for React stories, as
169
- // decorators of the form `<A><B/></A>` will not actually execute `B` in the first
170
- // call to the story function.
171
- // (b) The story function needs to actually have been called.
172
- // Certain frameworks (i.e.angular) don't actually render the component in the very first
173
- // React render cycle, so we need to wait for the framework to actually do that
174
- Promise.all([storyFnRan, rendered]).then(function () {
175
- channel.emit(Events.STORY_RENDERED, storyId);
176
- });
177
- } else {
178
- // 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
180
-
181
- var height = storyProps.height;
182
- return /*#__PURE__*/React.createElement("div", {
183
- id: storyBlockIdFromId(story.id)
184
- }, /*#__PURE__*/React.createElement(MDXProvider, {
185
- 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", {
187
- ref: storyRef,
188
- "data-name": story.name,
189
- dangerouslySetInnerHTML: {
190
- __html: htmlContents
191
- }
192
- })));
193
- }
84
+ // We do this so React doesn't complain when we replace the span in a secondary render
85
+ const htmlContents = `<span></span>`; // FIXME: height/style/etc. lifted from PureStory
86
+
87
+ const {
88
+ height
89
+ } = storyProps;
90
+ return /*#__PURE__*/React.createElement("div", {
91
+ id: storyBlockIdFromId(story.id)
92
+ }, /*#__PURE__*/React.createElement(MDXProvider, {
93
+ components: resetComponents
94
+ }, 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", {
95
+ ref: storyRef,
96
+ "data-name": story.name,
97
+ dangerouslySetInnerHTML: {
98
+ __html: htmlContents
99
+ }
100
+ })));
194
101
  }
195
102
 
196
103
  return /*#__PURE__*/React.createElement("div", {
@@ -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