@storybook/addon-docs 6.4.0-beta.6 → 6.4.0-rc.0

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 (46) hide show
  1. package/dist/cjs/blocks/ArgsTable.js +3 -4
  2. package/dist/cjs/blocks/Canvas.js +2 -1
  3. package/dist/cjs/blocks/DocsStory.js +2 -1
  4. package/dist/cjs/blocks/Source.js +1 -1
  5. package/dist/cjs/blocks/Story.js +65 -30
  6. package/dist/cjs/blocks/enhanceSource.js +2 -2
  7. package/dist/cjs/blocks/useStory.js +6 -1
  8. package/dist/cjs/frameworks/angular/compodoc.js +3 -1
  9. package/dist/cjs/frameworks/angular/sourceDecorator.js +99 -23
  10. package/dist/cjs/frameworks/common/config.js +87 -3
  11. package/dist/cjs/frameworks/html/sourceDecorator.js +9 -2
  12. package/dist/cjs/frameworks/react/react-argtypes.stories.js +2 -2
  13. package/dist/cjs/frameworks/vue/sourceDecorator.js +80 -33
  14. package/dist/esm/blocks/ArgsTable.js +3 -4
  15. package/dist/esm/blocks/Canvas.js +3 -2
  16. package/dist/esm/blocks/DocsStory.js +2 -1
  17. package/dist/esm/blocks/Source.js +1 -1
  18. package/dist/esm/blocks/Story.js +63 -27
  19. package/dist/esm/blocks/enhanceSource.js +7 -1
  20. package/dist/esm/blocks/useStory.js +6 -1
  21. package/dist/esm/frameworks/angular/compodoc.js +3 -1
  22. package/dist/esm/frameworks/angular/sourceDecorator.js +72 -20
  23. package/dist/esm/frameworks/common/config.js +60 -3
  24. package/dist/esm/frameworks/html/sourceDecorator.js +9 -2
  25. package/dist/esm/frameworks/react/react-argtypes.stories.js +1 -1
  26. package/dist/esm/frameworks/vue/sourceDecorator.js +60 -23
  27. package/dist/modern/blocks/ArgsTable.js +3 -5
  28. package/dist/modern/blocks/Canvas.js +3 -2
  29. package/dist/modern/blocks/DocsStory.js +2 -1
  30. package/dist/modern/blocks/Source.js +1 -1
  31. package/dist/modern/blocks/Story.js +37 -29
  32. package/dist/modern/blocks/enhanceSource.js +7 -1
  33. package/dist/modern/blocks/useStory.js +6 -1
  34. package/dist/modern/frameworks/angular/compodoc.js +3 -1
  35. package/dist/modern/frameworks/angular/sourceDecorator.js +33 -20
  36. package/dist/modern/frameworks/common/config.js +2 -3
  37. package/dist/modern/frameworks/html/sourceDecorator.js +9 -2
  38. package/dist/modern/frameworks/react/react-argtypes.stories.js +1 -1
  39. package/dist/modern/frameworks/vue/sourceDecorator.js +14 -9
  40. package/dist/ts3.4/blocks/Story.d.ts +1 -1
  41. package/dist/ts3.4/frameworks/angular/sourceDecorator.d.ts +1 -1
  42. package/dist/ts3.4/frameworks/common/config.d.ts +2 -2
  43. package/dist/ts3.9/blocks/Story.d.ts +1 -1
  44. package/dist/ts3.9/frameworks/angular/sourceDecorator.d.ts +1 -1
  45. package/dist/ts3.9/frameworks/common/config.d.ts +2 -2
  46. package/package.json +29 -30
@@ -1,12 +1,6 @@
1
1
  "use strict";
2
2
 
3
- require("core-js/modules/es.symbol.js");
4
-
5
- require("core-js/modules/es.symbol.description.js");
6
-
7
- require("core-js/modules/es.object.to-string.js");
8
-
9
- require("core-js/modules/es.symbol.iterator.js");
3
+ require("core-js/modules/es.weak-map.js");
10
4
 
11
5
  require("core-js/modules/es.string.iterator.js");
12
6
 
@@ -14,6 +8,14 @@ require("core-js/modules/es.array.iterator.js");
14
8
 
15
9
  require("core-js/modules/web.dom-collections.iterator.js");
16
10
 
11
+ require("core-js/modules/es.object.get-own-property-descriptor.js");
12
+
13
+ require("core-js/modules/es.symbol.js");
14
+
15
+ require("core-js/modules/es.symbol.description.js");
16
+
17
+ require("core-js/modules/es.symbol.iterator.js");
18
+
17
19
  require("core-js/modules/es.array.from.js");
18
20
 
19
21
  require("core-js/modules/es.array.slice.js");
@@ -26,6 +28,12 @@ Object.defineProperty(exports, "__esModule", {
26
28
  exports.vnodeToString = vnodeToString;
27
29
  exports.sourceDecorator = exports.skipSourceRender = void 0;
28
30
 
31
+ require("regenerator-runtime/runtime.js");
32
+
33
+ require("core-js/modules/es.promise.js");
34
+
35
+ require("core-js/modules/es.object.to-string.js");
36
+
29
37
  require("core-js/modules/es.array.join.js");
30
38
 
31
39
  require("core-js/modules/es.array.filter.js");
@@ -52,14 +60,8 @@ var _addons = require("@storybook/addons");
52
60
 
53
61
  var _clientLogger = require("@storybook/client-logger");
54
62
 
55
- var _standalone = _interopRequireDefault(require("prettier/standalone"));
56
-
57
- var _parserHtml = _interopRequireDefault(require("prettier/parser-html"));
58
-
59
63
  var _shared = require("../../shared");
60
64
 
61
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
62
-
63
65
  function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
64
66
 
65
67
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
@@ -82,6 +84,14 @@ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToAr
82
84
 
83
85
  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; }
84
86
 
87
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
88
+
89
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (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; }
90
+
91
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
92
+
93
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
94
+
85
95
  var skipSourceRender = function skipSourceRender(context) {
86
96
  var _context$parameters$d;
87
97
 
@@ -125,13 +135,50 @@ var sourceDecorator = function sourceDecorator(storyFn, context) {
125
135
  try {
126
136
  var storyNode = lookupStoryInstance(this, storyComponent);
127
137
  var code = vnodeToString(storyNode._vnode);
128
- channel.emit(_shared.SNIPPET_RENDERED, (context || {}).id, _standalone.default.format("<template>".concat(code, "</template>"), {
129
- parser: 'vue',
130
- plugins: [_parserHtml.default],
131
- // Because the parsed vnode missing spaces right before/after the surround tag,
132
- // we always get weird wrapped code without this option.
133
- htmlWhitespaceSensitivity: 'ignore'
134
- }));
138
+
139
+ var emitFormattedTemplate = /*#__PURE__*/function () {
140
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
141
+ var prettier, prettierHtml;
142
+ return regeneratorRuntime.wrap(function _callee$(_context) {
143
+ while (1) {
144
+ switch (_context.prev = _context.next) {
145
+ case 0:
146
+ _context.next = 2;
147
+ return Promise.resolve().then(function () {
148
+ return _interopRequireWildcard(require('prettier/standalone'));
149
+ });
150
+
151
+ case 2:
152
+ prettier = _context.sent;
153
+ _context.next = 5;
154
+ return Promise.resolve().then(function () {
155
+ return _interopRequireWildcard(require('prettier/parser-html'));
156
+ });
157
+
158
+ case 5:
159
+ prettierHtml = _context.sent;
160
+ channel.emit(_shared.SNIPPET_RENDERED, (context || {}).id, prettier.format("<template>".concat(code, "</template>"), {
161
+ parser: 'vue',
162
+ plugins: [prettierHtml],
163
+ // Because the parsed vnode missing spaces right before/after the surround tag,
164
+ // we always get weird wrapped code without this option.
165
+ htmlWhitespaceSensitivity: 'ignore'
166
+ }));
167
+
168
+ case 7:
169
+ case "end":
170
+ return _context.stop();
171
+ }
172
+ }
173
+ }, _callee);
174
+ }));
175
+
176
+ return function emitFormattedTemplate() {
177
+ return _ref.apply(this, arguments);
178
+ };
179
+ }();
180
+
181
+ emitFormattedTemplate();
135
182
  } catch (e) {
136
183
  _clientLogger.logger.warn("Failed to generate dynamic story source: ".concat(e));
137
184
  }
@@ -145,17 +192,17 @@ exports.sourceDecorator = sourceDecorator;
145
192
  function vnodeToString(vnode) {
146
193
  var _vnode$data, _vnode$componentOptio, _vnode$data2;
147
194
 
148
- var attrString = [].concat(_toConsumableArray((_vnode$data = vnode.data) !== null && _vnode$data !== void 0 && _vnode$data.slot ? [['slot', vnode.data.slot]] : []), [['class', stringifyClassAttribute(vnode)]], _toConsumableArray((_vnode$componentOptio = vnode.componentOptions) !== null && _vnode$componentOptio !== void 0 && _vnode$componentOptio.propsData ? Object.entries(vnode.componentOptions.propsData) : []), _toConsumableArray((_vnode$data2 = vnode.data) !== null && _vnode$data2 !== void 0 && _vnode$data2.attrs ? Object.entries(vnode.data.attrs) : [])).filter(function (_ref, index, list) {
149
- var _ref2 = _slicedToArray(_ref, 1),
150
- name = _ref2[0];
195
+ var attrString = [].concat(_toConsumableArray((_vnode$data = vnode.data) !== null && _vnode$data !== void 0 && _vnode$data.slot ? [['slot', vnode.data.slot]] : []), [['class', stringifyClassAttribute(vnode)]], _toConsumableArray((_vnode$componentOptio = vnode.componentOptions) !== null && _vnode$componentOptio !== void 0 && _vnode$componentOptio.propsData ? Object.entries(vnode.componentOptions.propsData) : []), _toConsumableArray((_vnode$data2 = vnode.data) !== null && _vnode$data2 !== void 0 && _vnode$data2.attrs ? Object.entries(vnode.data.attrs) : [])).filter(function (_ref2, index, list) {
196
+ var _ref3 = _slicedToArray(_ref2, 1),
197
+ name = _ref3[0];
151
198
 
152
199
  return list.findIndex(function (item) {
153
200
  return item[0] === name;
154
201
  }) === index;
155
- }).map(function (_ref3) {
156
- var _ref4 = _slicedToArray(_ref3, 2),
157
- name = _ref4[0],
158
- value = _ref4[1];
202
+ }).map(function (_ref4) {
203
+ var _ref5 = _slicedToArray(_ref4, 2),
204
+ name = _ref5[0],
205
+ value = _ref5[1];
159
206
 
160
207
  return stringifyAttr(name, value);
161
208
  }).filter(Boolean).join(' ');
@@ -222,14 +269,14 @@ function normalizeClassBinding(binding) {
222
269
  }
223
270
 
224
271
  if (_typeof(binding) === 'object') {
225
- return Object.entries(binding).filter(function (_ref5) {
226
- var _ref6 = _slicedToArray(_ref5, 2),
227
- active = _ref6[1];
272
+ return Object.entries(binding).filter(function (_ref6) {
273
+ var _ref7 = _slicedToArray(_ref6, 2),
274
+ active = _ref7[1];
228
275
 
229
276
  return !!active;
230
- }).map(function (_ref7) {
231
- var _ref8 = _slicedToArray(_ref7, 1),
232
- className = _ref8[0];
277
+ }).map(function (_ref8) {
278
+ var _ref9 = _slicedToArray(_ref8, 1),
279
+ className = _ref9[0];
233
280
 
234
281
  return className;
235
282
  });
@@ -185,10 +185,9 @@ export var StoryTable = function StoryTable(props) {
185
185
  updateArgs = _useArgs2[1],
186
186
  resetArgs = _useArgs2[2];
187
187
 
188
- if (!story) {
189
- return /*#__PURE__*/React.createElement("div", null, "Loading...");
190
- }
191
-
188
+ if (!story) return /*#__PURE__*/React.createElement(PureArgsTable, {
189
+ isLoading: true
190
+ });
192
191
  var argTypes = filterArgTypes(story.argTypes, include, exclude);
193
192
  var mainLabel = getComponentName(component) || 'Story';
194
193
 
@@ -12,7 +12,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
12
12
  import React, { useContext } from 'react';
13
13
  import { MDXProvider } from '@mdx-js/react';
14
14
  import { toId, storyNameFromExport } from '@storybook/csf';
15
- import { resetComponents, Preview as PurePreview } from '@storybook/components';
15
+ import { resetComponents, Preview as PurePreview, PreviewSkeleton } from '@storybook/components';
16
16
  import { DocsContext } from './DocsContext';
17
17
  import { SourceContext } from './SourceContainer';
18
18
  import { getSourceProps, SourceState } from './Source';
@@ -82,7 +82,8 @@ export var Canvas = function Canvas(props) {
82
82
  previewProps = _getPreviewProps.previewProps;
83
83
 
84
84
  var children = props.children;
85
- return isLoading ? null : /*#__PURE__*/React.createElement(MDXProvider, {
85
+ if (isLoading) return /*#__PURE__*/React.createElement(PreviewSkeleton, null);
86
+ return /*#__PURE__*/React.createElement(MDXProvider, {
86
87
  components: resetComponents
87
88
  }, /*#__PURE__*/React.createElement(PurePreview, previewProps, children));
88
89
  };
@@ -49,6 +49,7 @@ export var DocsStory = function DocsStory(_ref) {
49
49
  }), /*#__PURE__*/React.createElement(Canvas, {
50
50
  withToolbar: withToolbar
51
51
  }, /*#__PURE__*/React.createElement(Story, {
52
- id: id
52
+ id: id,
53
+ parameters: parameters
53
54
  })));
54
55
  };
@@ -49,7 +49,7 @@ var getSnippet = function getSnippet(snippet, story) {
49
49
 
50
50
  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;
51
51
 
52
- if (userCode) {
52
+ if (userCode !== undefined) {
53
53
  return userCode;
54
54
  } // if user has explicitly set this as dynamic, use snippet
55
55
 
@@ -1,11 +1,34 @@
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) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_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
+
1
13
  import "core-js/modules/es.function.name.js";
2
14
  import "core-js/modules/es.object.assign.js";
3
15
  import "core-js/modules/es.array.concat.js";
4
- import React, { useContext, useRef, useEffect, useMemo } from 'react';
16
+ import "core-js/modules/es.symbol.js";
17
+ import "core-js/modules/es.symbol.description.js";
18
+ import "core-js/modules/es.object.to-string.js";
19
+ import "core-js/modules/es.symbol.iterator.js";
20
+ import "core-js/modules/es.string.iterator.js";
21
+ import "core-js/modules/es.array.iterator.js";
22
+ import "core-js/modules/web.dom-collections.iterator.js";
23
+ import "core-js/modules/es.array.slice.js";
24
+ import "core-js/modules/es.array.from.js";
25
+ import React, { useContext, useRef, useEffect, useState } from 'react';
5
26
  import { MDXProvider } from '@mdx-js/react';
6
- import { resetComponents, Story as PureStory } from '@storybook/components';
7
- import { toId, storyNameFromExport } from '@storybook/csf';
8
27
  import global from 'global';
28
+ import { resetComponents, Story as PureStory, StorySkeleton } from '@storybook/components';
29
+ import { toId, storyNameFromExport } from '@storybook/csf';
30
+ import { addons } from '@storybook/addons';
31
+ import Events from '@storybook/core-events';
9
32
  import { CURRENT_SELECTION } from './types';
10
33
  import { DocsContext } from './DocsContext';
11
34
  import { useStory } from './useStory';
@@ -25,7 +48,7 @@ export var getStoryId = function getStoryId(props, context) {
25
48
  var inputId = id === CURRENT_SELECTION ? context.id : id;
26
49
  return inputId || lookupStoryId(name, context);
27
50
  };
28
- export var getStoryProps = function getStoryProps(_ref4, story, context) {
51
+ export var getStoryProps = function getStoryProps(_ref4, story, context, onStoryFnCalled) {
29
52
  var height = _ref4.height,
30
53
  inline = _ref4.inline;
31
54
  var storyName = story.name,
@@ -50,9 +73,17 @@ export var getStoryProps = function getStoryProps(_ref4, story, context) {
50
73
  }
51
74
 
52
75
  var boundStoryFn = function boundStoryFn() {
53
- return story.unboundStoryFn(Object.assign({}, context.getStoryContext(story), {
54
- loaded: {}
55
- }));
76
+ var storyResult = story.unboundStoryFn(Object.assign({}, context.getStoryContext(story), {
77
+ loaded: {},
78
+ abortSignal: undefined,
79
+ canvasElement: undefined
80
+ })); // We need to wait until the bound story function has actually been called before we
81
+ // consider the story rendered. Certain frameworks (i.e. angular) don't actually render
82
+ // the component in the very first react render cycle, and so we can't just wait until the
83
+ // `PureStory` component has been rendered to consider the underlying story "rendered".
84
+
85
+ onStoryFnCalled();
86
+ return storyResult;
56
87
  };
57
88
 
58
89
  return Object.assign({
@@ -63,7 +94,7 @@ export var getStoryProps = function getStoryProps(_ref4, story, context) {
63
94
  }, storyIsInline && {
64
95
  parameters: parameters,
65
96
  storyFn: function storyFn() {
66
- return prepareForInline(boundStoryFn, story);
97
+ return prepareForInline(boundStoryFn, context.getStoryContext(story));
67
98
  }
68
99
  });
69
100
  };
@@ -72,21 +103,20 @@ var Story = function Story(props) {
72
103
  var _global$FEATURES;
73
104
 
74
105
  var context = useContext(DocsContext);
75
- var ref = useRef();
76
- var story = useStory(getStoryId(props, context), context); // Ensure we wait until this story is properly rendered in the docs context.
77
- // The purpose of this is to ensure that that the `DOCS_RENDERED` event isn't emitted
78
- // until all stories on the page have rendered.
79
-
80
- var storyId = context.id,
81
- registerRenderingStory = context.registerRenderingStory;
82
- var storyRendered = useMemo(registerRenderingStory, [storyId]);
83
- useEffect(function () {
84
- if (story) storyRendered();
85
- }, [story]);
106
+ var channel = addons.getChannel();
107
+ var storyRef = useRef();
108
+ var storyId = getStoryId(props, context);
109
+ var story = useStory(storyId, context);
110
+
111
+ var _useState = useState(true),
112
+ _useState2 = _slicedToArray(_useState, 2),
113
+ showLoader = _useState2[0],
114
+ setShowLoader = _useState2[1];
115
+
86
116
  useEffect(function () {
87
117
  var cleanup;
88
118
 
89
- if (story && ref.current) {
119
+ if (story && storyRef.current) {
90
120
  var componentId = story.componentId,
91
121
  id = story.id,
92
122
  title = story.title,
@@ -106,8 +136,9 @@ var Story = function Story(props) {
106
136
  cleanup = context.renderStoryToElement({
107
137
  story: story,
108
138
  renderContext: renderContext,
109
- element: ref.current
139
+ element: storyRef.current
110
140
  });
141
+ setShowLoader(false);
111
142
  }
112
143
 
113
144
  return function () {
@@ -116,10 +147,15 @@ var Story = function Story(props) {
116
147
  }, [story]);
117
148
 
118
149
  if (!story) {
119
- return /*#__PURE__*/React.createElement("div", null, "Loading...");
120
- }
150
+ return /*#__PURE__*/React.createElement(StorySkeleton, null);
151
+ } // If we are rendering a old-style inline Story via `PureStory` below, we want to emit
152
+ // the `STORY_RENDERED` event when it renders. The modern mode below calls out to
153
+ // `Preview.renderStoryToDom()` which itself emits the event.
154
+
121
155
 
122
- var storyProps = getStoryProps(props, story, context);
156
+ var storyProps = getStoryProps(props, story, context, function () {
157
+ return channel.emit(Events.STORY_RENDERED, storyId);
158
+ });
123
159
 
124
160
  if (!storyProps) {
125
161
  return null;
@@ -127,15 +163,15 @@ var Story = function Story(props) {
127
163
 
128
164
  if (global !== null && global !== void 0 && (_global$FEATURES = global.FEATURES) !== null && _global$FEATURES !== void 0 && _global$FEATURES.modernInlineRender) {
129
165
  // We do this so React doesn't complain when we replace the span in a secondary render
130
- var htmlContents = "<span data-is-loading-indicator=\"true\">loading story...</span>"; // FIXME: height/style/etc. lifted from PureStory
166
+ var htmlContents = "<span></span>"; // FIXME: height/style/etc. lifted from PureStory
131
167
 
132
168
  var height = storyProps.height;
133
169
  return /*#__PURE__*/React.createElement("div", {
134
170
  id: storyBlockIdFromId(story.id)
135
171
  }, /*#__PURE__*/React.createElement(MDXProvider, {
136
172
  components: resetComponents
137
- }, height ? /*#__PURE__*/React.createElement("style", null, "#story--".concat(story.id, " { min-height: ").concat(height, "; transform: translateZ(0); overflow: auto }")) : null, /*#__PURE__*/React.createElement("div", {
138
- ref: ref,
173
+ }, 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", {
174
+ ref: storyRef,
139
175
  "data-name": story.name,
140
176
  dangerouslySetInnerHTML: {
141
177
  __html: htmlContents
@@ -25,7 +25,13 @@ import "core-js/modules/es.array.iterator.js";
25
25
  import "core-js/modules/web.dom-collections.iterator.js";
26
26
  import "core-js/modules/es.array.from.js";
27
27
  import "core-js/modules/es.function.name.js";
28
- import { combineParameters } from '@storybook/client-api';
28
+ import { combineParameters } from '@storybook/store'; // ============================================================
29
+ // START @storybook/source-loader/extract-source
30
+ //
31
+ // This code duplicated because tree-shaking isn't working.
32
+ // It's not DRY, but source-loader is on the chopping block for
33
+ // the next version of addon-docs, so it's not the worst sin.
34
+ // ============================================================
29
35
 
30
36
  /**
31
37
  * given a location, extract the text from the full source
@@ -38,7 +38,12 @@ export function useStory(storyId, context) {
38
38
  return stories && stories[0];
39
39
  }
40
40
  export function useStories(storyIds, context) {
41
- var _useState = useState({}),
41
+ var initialStoriesById = context.componentStories().reduce(function (acc, story) {
42
+ acc[story.id] = story;
43
+ return acc;
44
+ }, {});
45
+
46
+ var _useState = useState(initialStoriesById),
42
47
  _useState2 = _slicedToArray(_useState, 2),
43
48
  storiesById = _useState2[0],
44
49
  setStories = _useState2[1];
@@ -274,8 +274,10 @@ var extractDefaultValue = function extractDefaultValue(property) {
274
274
  };
275
275
 
276
276
  var resolveTypealias = function resolveTypealias(compodocType) {
277
+ var _compodocJson$miscell, _compodocJson$miscell2;
278
+
277
279
  var compodocJson = getCompodocJson();
278
- var typeAlias = compodocJson === null || compodocJson === void 0 ? void 0 : compodocJson.miscellaneous.typealiases.find(function (x) {
280
+ var typeAlias = compodocJson === null || compodocJson === void 0 ? void 0 : (_compodocJson$miscell = compodocJson.miscellaneous) === null || _compodocJson$miscell === void 0 ? void 0 : (_compodocJson$miscell2 = _compodocJson$miscell.typealiases) === null || _compodocJson$miscell2 === void 0 ? void 0 : _compodocJson$miscell2.find(function (x) {
279
281
  return x.name === compodocType;
280
282
  });
281
283
  return typeAlias ? resolveTypealias(typeAlias.rawtype) : compodocType;
@@ -1,7 +1,13 @@
1
+ import "regenerator-runtime/runtime.js";
2
+ import "core-js/modules/es.promise.js";
3
+ import "core-js/modules/es.object.to-string.js";
4
+
5
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
+
7
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
8
+
1
9
  import { addons, useEffect } from '@storybook/addons';
2
10
  import { computesTemplateSourceFromComponent } from '@storybook/angular/renderer';
3
- import prettierHtml from 'prettier/parser-html';
4
- import prettier from 'prettier/standalone';
5
11
  import { SNIPPET_RENDERED, SourceType } from '../../shared';
6
12
  export var skipSourceRender = function skipSourceRender(context) {
7
13
  var _context$parameters$d;
@@ -16,16 +22,58 @@ export var skipSourceRender = function skipSourceRender(context) {
16
22
 
17
23
  return (sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.code) || (sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.type) === SourceType.CODE;
18
24
  };
25
+ var prettyUpInternal;
19
26
 
20
- var prettyUp = function prettyUp(source) {
21
- return prettier.format(source, {
22
- parser: 'angular',
23
- plugins: [prettierHtml],
24
- htmlWhitespaceSensitivity: 'ignore'
25
- });
26
- };
27
+ var makePrettyUp = /*#__PURE__*/function () {
28
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
29
+ var prettierHtml, prettier;
30
+ return regeneratorRuntime.wrap(function _callee$(_context) {
31
+ while (1) {
32
+ switch (_context.prev = _context.next) {
33
+ case 0:
34
+ if (!prettyUpInternal) {
35
+ _context.next = 2;
36
+ break;
37
+ }
38
+
39
+ return _context.abrupt("return", prettyUpInternal);
40
+
41
+ case 2:
42
+ _context.next = 4;
43
+ return import('prettier/parser-html');
44
+
45
+ case 4:
46
+ prettierHtml = _context.sent;
47
+ _context.next = 7;
48
+ return import('prettier/standalone');
49
+
50
+ case 7:
51
+ prettier = _context.sent;
52
+
53
+ prettyUpInternal = function prettyUpInternal(source) {
54
+ return prettier.format(source, {
55
+ parser: 'angular',
56
+ plugins: [prettierHtml],
57
+ htmlWhitespaceSensitivity: 'ignore'
58
+ });
59
+ };
60
+
61
+ return _context.abrupt("return", prettyUpInternal);
62
+
63
+ case 10:
64
+ case "end":
65
+ return _context.stop();
66
+ }
67
+ }
68
+ }, _callee);
69
+ }));
70
+
71
+ return function makePrettyUp() {
72
+ return _ref.apply(this, arguments);
73
+ };
74
+ }();
27
75
  /**
28
- * Svelte source decorator.
76
+ * Angular source decorator.
29
77
  * @param storyFn Fn
30
78
  * @param context StoryContext
31
79
  */
@@ -45,20 +93,24 @@ export var sourceDecorator = function sourceDecorator(storyFn, context) {
45
93
  var component = context.component,
46
94
  argTypes = context.argTypes;
47
95
  var toEmit;
96
+ var prettyUpPromise = makePrettyUp();
48
97
  useEffect(function () {
49
- if (toEmit) channel.emit(SNIPPET_RENDERED, context.id, prettyUp(template));
98
+ prettyUpPromise.then(function (prettyUp) {
99
+ if (toEmit) channel.emit(SNIPPET_RENDERED, context.id, prettyUp(toEmit));
100
+ });
50
101
  });
102
+ prettyUpPromise.then(function (prettyUp) {
103
+ if (component && !userDefinedTemplate) {
104
+ var _source = computesTemplateSourceFromComponent(component, props, argTypes); // We might have a story with a Directive or Service defined as the component
105
+ // In these cases there might exist a template, even if we aren't able to create source from component
51
106
 
52
- if (component && !userDefinedTemplate) {
53
- var source = computesTemplateSourceFromComponent(component, props, argTypes); // We might have a story with a Directive or Service defined as the component
54
- // In these cases there might exist a template, even if we aren't able to create source from component
55
107
 
56
- if (source || template) {
57
- toEmit = prettyUp(source || template);
108
+ if (_source || template) {
109
+ toEmit = prettyUp(_source || template);
110
+ }
111
+ } else if (template) {
112
+ toEmit = prettyUp(template);
58
113
  }
59
- } else if (template) {
60
- toEmit = prettyUp(template);
61
- }
62
-
114
+ });
63
115
  return story;
64
116
  };
@@ -1,10 +1,67 @@
1
- import { DocsContainer, DocsPage } from '../../blocks';
1
+ import "regenerator-runtime/runtime.js";
2
+ import "core-js/modules/es.promise.js";
3
+ import "core-js/modules/es.object.to-string.js";
4
+
5
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
+
7
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
8
+
2
9
  import { enhanceArgTypes } from './enhanceArgTypes';
3
10
  export var parameters = {
4
11
  docs: {
5
12
  inlineStories: false,
6
- container: DocsContainer,
7
- page: DocsPage,
13
+ getContainer: function () {
14
+ var _getContainer = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
15
+ return regeneratorRuntime.wrap(function _callee$(_context) {
16
+ while (1) {
17
+ switch (_context.prev = _context.next) {
18
+ case 0:
19
+ _context.next = 2;
20
+ return import('../../blocks');
21
+
22
+ case 2:
23
+ return _context.abrupt("return", _context.sent.DocsContainer);
24
+
25
+ case 3:
26
+ case "end":
27
+ return _context.stop();
28
+ }
29
+ }
30
+ }, _callee);
31
+ }));
32
+
33
+ function getContainer() {
34
+ return _getContainer.apply(this, arguments);
35
+ }
36
+
37
+ return getContainer;
38
+ }(),
39
+ getPage: function () {
40
+ var _getPage = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
41
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
42
+ while (1) {
43
+ switch (_context2.prev = _context2.next) {
44
+ case 0:
45
+ _context2.next = 2;
46
+ return import('../../blocks');
47
+
48
+ case 2:
49
+ return _context2.abrupt("return", _context2.sent.DocsPage);
50
+
51
+ case 3:
52
+ case "end":
53
+ return _context2.stop();
54
+ }
55
+ }
56
+ }, _callee2);
57
+ }));
58
+
59
+ function getPage() {
60
+ return _getPage.apply(this, arguments);
61
+ }
62
+
63
+ return getPage;
64
+ }(),
8
65
  iframeHeight: 100
9
66
  }
10
67
  };
@@ -38,8 +38,15 @@ export function sourceDecorator(storyFn, context) {
38
38
  var story = context !== null && context !== void 0 && (_context$parameters$d3 = context.parameters.docs) !== null && _context$parameters$d3 !== void 0 && (_context$parameters$d4 = _context$parameters$d3.source) !== null && _context$parameters$d4 !== void 0 && _context$parameters$d4.excludeDecorators ? context.originalStoryFn(context.args, context) : storyFn();
39
39
  var source;
40
40
 
41
- if (typeof story === 'string' && !skipSourceRender(context)) {
42
- source = applyTransformSource(story, context);
41
+ if (!skipSourceRender(context)) {
42
+ if (typeof story === 'string') {
43
+ source = story;
44
+ } // eslint-disable-next-line no-undef
45
+ else if (story instanceof Element) {
46
+ source = story.outerHTML;
47
+ }
48
+
49
+ if (source) source = applyTransformSource(source, context);
43
50
  }
44
51
 
45
52
  useEffect(function () {
@@ -28,7 +28,7 @@ import React, { useState } from 'react';
28
28
  import mapValues from 'lodash/mapValues';
29
29
  import { storiesOf } from '@storybook/react';
30
30
  import { ArgsTable } from '@storybook/components';
31
- import { inferControls } from '@storybook/client-api';
31
+ import { inferControls } from '@storybook/store';
32
32
  import { extractArgTypes } from './extractArgTypes';
33
33
 
34
34
  var argsTableProps = function argsTableProps(component) {