@storybook/addon-docs 6.4.0-beta.3 → 6.4.0-beta.33

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 (61) 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 +8 -3
  8. package/dist/cjs/frameworks/angular/compodoc.js +3 -1
  9. package/dist/cjs/frameworks/angular/prepareForInline.js +52 -53
  10. package/dist/cjs/frameworks/angular/sourceDecorator.js +99 -23
  11. package/dist/cjs/frameworks/common/config.js +87 -3
  12. package/dist/cjs/frameworks/html/sourceDecorator.js +9 -2
  13. package/dist/cjs/frameworks/react/react-argtypes.stories.js +2 -2
  14. package/dist/cjs/frameworks/vue/extractArgTypes.js +106 -15
  15. package/dist/cjs/frameworks/vue/sourceDecorator.js +80 -33
  16. package/dist/cjs/frameworks/web-components/custom-elements.js +63 -25
  17. package/dist/esm/blocks/ArgsTable.js +3 -4
  18. package/dist/esm/blocks/Canvas.js +3 -2
  19. package/dist/esm/blocks/DocsStory.js +2 -1
  20. package/dist/esm/blocks/Source.js +1 -1
  21. package/dist/esm/blocks/Story.js +63 -27
  22. package/dist/esm/blocks/enhanceSource.js +7 -1
  23. package/dist/esm/blocks/useStory.js +8 -3
  24. package/dist/esm/frameworks/angular/compodoc.js +3 -1
  25. package/dist/esm/frameworks/angular/prepareForInline.js +46 -50
  26. package/dist/esm/frameworks/angular/sourceDecorator.js +72 -20
  27. package/dist/esm/frameworks/common/config.js +60 -3
  28. package/dist/esm/frameworks/html/sourceDecorator.js +9 -2
  29. package/dist/esm/frameworks/react/react-argtypes.stories.js +1 -1
  30. package/dist/esm/frameworks/vue/extractArgTypes.js +97 -14
  31. package/dist/esm/frameworks/vue/sourceDecorator.js +60 -23
  32. package/dist/esm/frameworks/web-components/custom-elements.js +60 -24
  33. package/dist/modern/blocks/ArgsTable.js +3 -5
  34. package/dist/modern/blocks/Canvas.js +3 -2
  35. package/dist/modern/blocks/DocsStory.js +2 -1
  36. package/dist/modern/blocks/Source.js +1 -1
  37. package/dist/modern/blocks/Story.js +37 -29
  38. package/dist/modern/blocks/enhanceSource.js +7 -1
  39. package/dist/modern/blocks/useStory.js +14 -3
  40. package/dist/modern/frameworks/angular/compodoc.js +3 -1
  41. package/dist/modern/frameworks/angular/prepareForInline.js +20 -15
  42. package/dist/modern/frameworks/angular/sourceDecorator.js +33 -20
  43. package/dist/modern/frameworks/common/config.js +2 -3
  44. package/dist/modern/frameworks/html/sourceDecorator.js +9 -2
  45. package/dist/modern/frameworks/react/react-argtypes.stories.js +1 -1
  46. package/dist/modern/frameworks/vue/extractArgTypes.js +64 -4
  47. package/dist/modern/frameworks/vue/sourceDecorator.js +14 -9
  48. package/dist/modern/frameworks/web-components/custom-elements.js +55 -23
  49. package/dist/ts3.4/blocks/Story.d.ts +1 -1
  50. package/dist/ts3.4/frameworks/angular/config.d.ts +1 -1
  51. package/dist/ts3.4/frameworks/angular/prepareForInline.d.ts +1 -1
  52. package/dist/ts3.4/frameworks/angular/sourceDecorator.d.ts +1 -1
  53. package/dist/ts3.4/frameworks/common/config.d.ts +2 -2
  54. package/dist/ts3.4/frameworks/web-components/custom-elements.d.ts +4 -3
  55. package/dist/ts3.9/blocks/Story.d.ts +1 -1
  56. package/dist/ts3.9/frameworks/angular/config.d.ts +1 -1
  57. package/dist/ts3.9/frameworks/angular/prepareForInline.d.ts +1 -1
  58. package/dist/ts3.9/frameworks/angular/sourceDecorator.d.ts +1 -1
  59. package/dist/ts3.9/frameworks/common/config.d.ts +2 -2
  60. package/dist/ts3.9/frameworks/web-components/custom-elements.d.ts +4 -3
  61. package/package.json +29 -30
@@ -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];
@@ -57,7 +62,7 @@ export function useStories(storyIds, context) {
57
62
  case 2:
58
63
  story = _context.sent;
59
64
  setStories(function (current) {
60
- return Object.assign({}, current, _defineProperty({}, storyId, story));
65
+ return current[storyId] === story ? current : Object.assign({}, current, _defineProperty({}, storyId, story));
61
66
  });
62
67
 
63
68
  case 4:
@@ -72,7 +77,7 @@ export function useStories(storyIds, context) {
72
77
  return _ref.apply(this, arguments);
73
78
  };
74
79
  }()));
75
- }, storyIds);
80
+ });
76
81
  return storyIds.map(function (storyId) {
77
82
  return storiesById[storyId];
78
83
  });
@@ -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;
@@ -18,62 +18,58 @@ var limit = pLimit(1);
18
18
 
19
19
  export var prepareForInline = function prepareForInline(storyFn, _ref) {
20
20
  var id = _ref.id,
21
- parameters = _ref.parameters;
22
- return /*#__PURE__*/React.createElement('div', {
23
- ref: function () {
24
- var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(node) {
25
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
26
- while (1) {
27
- switch (_context2.prev = _context2.next) {
28
- case 0:
29
- if (node) {
30
- _context2.next = 2;
31
- break;
32
- }
21
+ parameters = _ref.parameters,
22
+ component = _ref.component;
23
+ var el = React.useRef();
24
+ React.useEffect(function () {
25
+ _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
26
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
27
+ while (1) {
28
+ switch (_context2.prev = _context2.next) {
29
+ case 0:
30
+ limit( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
31
+ var renderer;
32
+ return regeneratorRuntime.wrap(function _callee$(_context) {
33
+ while (1) {
34
+ switch (_context.prev = _context.next) {
35
+ case 0:
36
+ _context.next = 2;
37
+ return rendererFactory.getRendererInstance("".concat(id, "-").concat(nanoid(10)).toLowerCase(), el.current);
33
38
 
34
- return _context2.abrupt("return", null);
39
+ case 2:
40
+ renderer = _context.sent;
35
41
 
36
- case 2:
37
- return _context2.abrupt("return", limit( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
38
- var renderer;
39
- return regeneratorRuntime.wrap(function _callee$(_context) {
40
- while (1) {
41
- switch (_context.prev = _context.next) {
42
- case 0:
43
- _context.next = 2;
44
- return rendererFactory.getRendererInstance("".concat(id, "-").concat(nanoid(10)), node);
42
+ if (!renderer) {
43
+ _context.next = 6;
44
+ break;
45
+ }
45
46
 
46
- case 2:
47
- renderer = _context.sent;
48
- _context.next = 5;
49
- return renderer.render({
50
- forced: false,
51
- parameters: parameters,
52
- storyFnAngular: storyFn(),
53
- targetDOMNode: node
54
- });
47
+ _context.next = 6;
48
+ return renderer.render({
49
+ forced: false,
50
+ component: component,
51
+ parameters: parameters,
52
+ storyFnAngular: storyFn(),
53
+ targetDOMNode: el.current
54
+ });
55
55
 
56
- case 5:
57
- case "end":
58
- return _context.stop();
59
- }
56
+ case 6:
57
+ case "end":
58
+ return _context.stop();
60
59
  }
61
- }, _callee);
62
- }))));
60
+ }
61
+ }, _callee);
62
+ })));
63
63
 
64
- case 3:
65
- case "end":
66
- return _context2.stop();
67
- }
64
+ case 1:
65
+ case "end":
66
+ return _context2.stop();
68
67
  }
69
- }, _callee2);
70
- }));
71
-
72
- function ref(_x) {
73
- return _ref2.apply(this, arguments);
74
- }
75
-
76
- return ref;
77
- }()
68
+ }
69
+ }, _callee2);
70
+ }))();
71
+ });
72
+ return /*#__PURE__*/React.createElement('div', {
73
+ ref: el
78
74
  });
79
75
  };
@@ -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) {