@storybook/addon-docs 6.4.0-alpha.35 → 6.4.0-alpha.39

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.
@@ -131,7 +131,7 @@ var getSourceProps = function getSourceProps(props, docsContext, sourceContext)
131
131
  var targetIds = multiProps.ids || [targetId];
132
132
  var stories = (0, _useStory.useStories)(targetIds, docsContext);
133
133
 
134
- if (!stories) {
134
+ if (!stories.every(Boolean)) {
135
135
  return {
136
136
  error: _components.SourceError.SOURCE_UNAVAILABLE,
137
137
  state: SourceState.NONE
@@ -79,11 +79,15 @@ var SourceContainer = function SourceContainer(_ref) {
79
79
  (0, _react.useEffect)(function () {
80
80
  var handleSnippetRendered = function handleSnippetRendered(id, newItem) {
81
81
  if (newItem !== sources[id]) {
82
- var newSources = Object.assign({}, sources, _defineProperty({}, id, newItem));
82
+ setSources(function (current) {
83
+ var newSources = Object.assign({}, current, _defineProperty({}, id, newItem));
83
84
 
84
- if (!(0, _fastDeepEqual.default)(sources, newSources)) {
85
- setSources(newSources);
86
- }
85
+ if (!(0, _fastDeepEqual.default)(current, newSources)) {
86
+ return newSources;
87
+ }
88
+
89
+ return current;
90
+ });
87
91
  }
88
92
  };
89
93
 
@@ -124,6 +124,8 @@ var getStoryProps = function getStoryProps(_ref4, story, context) {
124
124
  exports.getStoryProps = getStoryProps;
125
125
 
126
126
  var Story = function Story(props) {
127
+ var _global$FEATURES;
128
+
127
129
  var context = (0, _react.useContext)(_DocsContext.DocsContext);
128
130
  var ref = (0, _react.useRef)();
129
131
  var story = (0, _useStory.useStory)(getStoryId(props, context), context); // Ensure we wait until this story is properly rendered in the docs context.
@@ -178,7 +180,7 @@ var Story = function Story(props) {
178
180
  return null;
179
181
  }
180
182
 
181
- if (_global.default !== null && _global.default !== void 0 && _global.default.FEATURES.modernInlineRender) {
183
+ if (_global.default !== null && _global.default !== void 0 && (_global$FEATURES = _global.default.FEATURES) !== null && _global$FEATURES !== void 0 && _global$FEATURES.modernInlineRender) {
182
184
  // We do this so React doesn't complain when we replace the span in a secondary render
183
185
  var htmlContents = "<span data-is-loading-indicator=\"true\">loading story...</span>"; // FIXME: height/style/etc. lifted from PureStory
184
186
 
@@ -18,6 +18,8 @@ Object.defineProperty(exports, "__esModule", {
18
18
  exports.useStory = useStory;
19
19
  exports.useStories = useStories;
20
20
 
21
+ require("regenerator-runtime/runtime.js");
22
+
21
23
  require("core-js/modules/es.promise.js");
22
24
 
23
25
  require("core-js/modules/es.object.to-string.js");
@@ -30,8 +32,16 @@ require("core-js/modules/web.dom-collections.iterator.js");
30
32
 
31
33
  require("core-js/modules/es.array.map.js");
32
34
 
35
+ require("core-js/modules/es.object.assign.js");
36
+
33
37
  var _react = require("react");
34
38
 
39
+ 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; }
40
+
41
+ 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); } }
42
+
43
+ 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); }); }; }
44
+
35
45
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
36
46
 
37
47
  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."); }
@@ -50,19 +60,42 @@ function useStory(storyId, context) {
50
60
  }
51
61
 
52
62
  function useStories(storyIds, context) {
53
- var _useState = (0, _react.useState)(null),
63
+ var _useState = (0, _react.useState)({}),
54
64
  _useState2 = _slicedToArray(_useState, 2),
55
- stories = _useState2[0],
65
+ storiesById = _useState2[0],
56
66
  setStories = _useState2[1];
57
67
 
58
68
  (0, _react.useEffect)(function () {
59
- Promise.all(storyIds.map(function (storyId) {
60
- return context.loadStory(storyId);
61
- })).then(function (loadedStories) {
62
- if (!stories) {
63
- setStories(loadedStories);
64
- }
65
- });
69
+ Promise.all(storyIds.map( /*#__PURE__*/function () {
70
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(storyId) {
71
+ var story;
72
+ return regeneratorRuntime.wrap(function _callee$(_context) {
73
+ while (1) {
74
+ switch (_context.prev = _context.next) {
75
+ case 0:
76
+ _context.next = 2;
77
+ return context.loadStory(storyId);
78
+
79
+ case 2:
80
+ story = _context.sent;
81
+ setStories(function (current) {
82
+ return Object.assign({}, current, _defineProperty({}, storyId, story));
83
+ });
84
+
85
+ case 4:
86
+ case "end":
87
+ return _context.stop();
88
+ }
89
+ }
90
+ }, _callee);
91
+ }));
92
+
93
+ return function (_x) {
94
+ return _ref.apply(this, arguments);
95
+ };
96
+ }()));
97
+ }, storyIds);
98
+ return storyIds.map(function (storyId) {
99
+ return storiesById[storyId];
66
100
  });
67
- return stories;
68
101
  }
@@ -88,7 +88,7 @@ export var getSourceProps = function getSourceProps(props, docsContext, sourceCo
88
88
  var targetIds = multiProps.ids || [targetId];
89
89
  var stories = useStories(targetIds, docsContext);
90
90
 
91
- if (!stories) {
91
+ if (!stories.every(Boolean)) {
92
92
  return {
93
93
  error: SourceError.SOURCE_UNAVAILABLE,
94
94
  state: SourceState.NONE
@@ -43,11 +43,15 @@ export var SourceContainer = function SourceContainer(_ref) {
43
43
  useEffect(function () {
44
44
  var handleSnippetRendered = function handleSnippetRendered(id, newItem) {
45
45
  if (newItem !== sources[id]) {
46
- var newSources = Object.assign({}, sources, _defineProperty({}, id, newItem));
46
+ setSources(function (current) {
47
+ var newSources = Object.assign({}, current, _defineProperty({}, id, newItem));
47
48
 
48
- if (!deepEqual(sources, newSources)) {
49
- setSources(newSources);
50
- }
49
+ if (!deepEqual(current, newSources)) {
50
+ return newSources;
51
+ }
52
+
53
+ return current;
54
+ });
51
55
  }
52
56
  };
53
57
 
@@ -69,6 +69,8 @@ export var getStoryProps = function getStoryProps(_ref4, story, context) {
69
69
  };
70
70
 
71
71
  var Story = function Story(props) {
72
+ var _global$FEATURES;
73
+
72
74
  var context = useContext(DocsContext);
73
75
  var ref = useRef();
74
76
  var story = useStory(getStoryId(props, context), context); // Ensure we wait until this story is properly rendered in the docs context.
@@ -123,7 +125,7 @@ var Story = function Story(props) {
123
125
  return null;
124
126
  }
125
127
 
126
- if (global !== null && global !== void 0 && global.FEATURES.modernInlineRender) {
128
+ if (global !== null && global !== void 0 && (_global$FEATURES = global.FEATURES) !== null && _global$FEATURES !== void 0 && _global$FEATURES.modernInlineRender) {
127
129
  // We do this so React doesn't complain when we replace the span in a secondary render
128
130
  var htmlContents = "<span data-is-loading-indicator=\"true\">loading story...</span>"; // FIXME: height/style/etc. lifted from PureStory
129
131
 
@@ -1,9 +1,18 @@
1
+ import "regenerator-runtime/runtime.js";
2
+
3
+ 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; }
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 "core-js/modules/es.promise.js";
2
10
  import "core-js/modules/es.object.to-string.js";
3
11
  import "core-js/modules/es.string.iterator.js";
4
12
  import "core-js/modules/es.array.iterator.js";
5
13
  import "core-js/modules/web.dom-collections.iterator.js";
6
14
  import "core-js/modules/es.array.map.js";
15
+ import "core-js/modules/es.object.assign.js";
7
16
  import "core-js/modules/es.symbol.js";
8
17
  import "core-js/modules/es.symbol.description.js";
9
18
  import "core-js/modules/es.symbol.iterator.js";
@@ -29,19 +38,42 @@ export function useStory(storyId, context) {
29
38
  return stories && stories[0];
30
39
  }
31
40
  export function useStories(storyIds, context) {
32
- var _useState = useState(null),
41
+ var _useState = useState({}),
33
42
  _useState2 = _slicedToArray(_useState, 2),
34
- stories = _useState2[0],
43
+ storiesById = _useState2[0],
35
44
  setStories = _useState2[1];
36
45
 
37
46
  useEffect(function () {
38
- Promise.all(storyIds.map(function (storyId) {
39
- return context.loadStory(storyId);
40
- })).then(function (loadedStories) {
41
- if (!stories) {
42
- setStories(loadedStories);
43
- }
44
- });
47
+ Promise.all(storyIds.map( /*#__PURE__*/function () {
48
+ var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(storyId) {
49
+ var story;
50
+ return regeneratorRuntime.wrap(function _callee$(_context) {
51
+ while (1) {
52
+ switch (_context.prev = _context.next) {
53
+ case 0:
54
+ _context.next = 2;
55
+ return context.loadStory(storyId);
56
+
57
+ case 2:
58
+ story = _context.sent;
59
+ setStories(function (current) {
60
+ return Object.assign({}, current, _defineProperty({}, storyId, story));
61
+ });
62
+
63
+ case 4:
64
+ case "end":
65
+ return _context.stop();
66
+ }
67
+ }
68
+ }, _callee);
69
+ }));
70
+
71
+ return function (_x) {
72
+ return _ref.apply(this, arguments);
73
+ };
74
+ }()));
75
+ }, storyIds);
76
+ return storyIds.map(function (storyId) {
77
+ return storiesById[storyId];
45
78
  });
46
- return stories;
47
79
  }
@@ -90,7 +90,7 @@ export const getSourceProps = (props, docsContext, sourceContext) => {
90
90
  const targetIds = multiProps.ids || [targetId];
91
91
  const stories = useStories(targetIds, docsContext);
92
92
 
93
- if (!stories) {
93
+ if (!stories.every(Boolean)) {
94
94
  return {
95
95
  error: SourceError.SOURCE_UNAVAILABLE,
96
96
  state: SourceState.NONE
@@ -13,13 +13,17 @@ export const SourceContainer = ({
13
13
  useEffect(() => {
14
14
  const handleSnippetRendered = (id, newItem) => {
15
15
  if (newItem !== sources[id]) {
16
- const newSources = Object.assign({}, sources, {
17
- [id]: newItem
18
- });
16
+ setSources(current => {
17
+ const newSources = Object.assign({}, current, {
18
+ [id]: newItem
19
+ });
20
+
21
+ if (!deepEqual(current, newSources)) {
22
+ return newSources;
23
+ }
19
24
 
20
- if (!deepEqual(sources, newSources)) {
21
- setSources(newSources);
22
- }
25
+ return current;
26
+ });
23
27
  }
24
28
  };
25
29
 
@@ -65,6 +65,8 @@ export const getStoryProps = ({
65
65
  };
66
66
 
67
67
  const Story = props => {
68
+ var _global$FEATURES;
69
+
68
70
  const context = useContext(DocsContext);
69
71
  const ref = useRef();
70
72
  const story = useStory(getStoryId(props, context), context); // Ensure we wait until this story is properly rendered in the docs context.
@@ -121,7 +123,7 @@ const Story = props => {
121
123
  return null;
122
124
  }
123
125
 
124
- if (global !== null && global !== void 0 && global.FEATURES.modernInlineRender) {
126
+ if (global !== null && global !== void 0 && (_global$FEATURES = global.FEATURES) !== null && _global$FEATURES !== void 0 && _global$FEATURES.modernInlineRender) {
125
127
  // We do this so React doesn't complain when we replace the span in a secondary render
126
128
  const htmlContents = `<span data-is-loading-indicator="true">loading story...</span>`; // FIXME: height/style/etc. lifted from PureStory
127
129
 
@@ -4,13 +4,14 @@ export function useStory(storyId, context) {
4
4
  return stories && stories[0];
5
5
  }
6
6
  export function useStories(storyIds, context) {
7
- const [stories, setStories] = useState(null);
7
+ const [storiesById, setStories] = useState({});
8
8
  useEffect(() => {
9
- Promise.all(storyIds.map(storyId => context.loadStory(storyId))).then(loadedStories => {
10
- if (!stories) {
11
- setStories(loadedStories);
12
- }
13
- });
14
- });
15
- return stories;
9
+ Promise.all(storyIds.map(async storyId => {
10
+ const story = await context.loadStory(storyId);
11
+ setStories(current => Object.assign({}, current, {
12
+ [storyId]: story
13
+ }));
14
+ }));
15
+ }, storyIds);
16
+ return storyIds.map(storyId => storiesById[storyId]);
16
17
  }
@@ -1,5 +1,5 @@
1
1
  import { StoryId, AnyFramework } from '@storybook/csf';
2
2
  import { Story } from '@storybook/store';
3
3
  import { DocsContextProps } from './DocsContext';
4
- export declare function useStory<TFramework extends AnyFramework>(storyId: StoryId, context: DocsContextProps<TFramework>): Story<TFramework> | void;
5
- export declare function useStories<TFramework extends AnyFramework>(storyIds: StoryId[], context: DocsContextProps<TFramework>): Story<TFramework>[] | void;
4
+ export declare function useStory<TFramework extends AnyFramework = AnyFramework>(storyId: StoryId, context: DocsContextProps<TFramework>): Story<TFramework> | void;
5
+ export declare function useStories<TFramework extends AnyFramework = AnyFramework>(storyIds: StoryId[], context: DocsContextProps<TFramework>): (Story<TFramework> | void)[];
@@ -1,5 +1,5 @@
1
1
  import { StoryId, AnyFramework } from '@storybook/csf';
2
2
  import { Story } from '@storybook/store';
3
3
  import { DocsContextProps } from './DocsContext';
4
- export declare function useStory<TFramework extends AnyFramework>(storyId: StoryId, context: DocsContextProps<TFramework>): Story<TFramework> | void;
5
- export declare function useStories<TFramework extends AnyFramework>(storyIds: StoryId[], context: DocsContextProps<TFramework>): Story<TFramework>[] | void;
4
+ export declare function useStory<TFramework extends AnyFramework = AnyFramework>(storyId: StoryId, context: DocsContextProps<TFramework>): Story<TFramework> | void;
5
+ export declare function useStories<TFramework extends AnyFramework = AnyFramework>(storyIds: StoryId[], context: DocsContextProps<TFramework>): (Story<TFramework> | void)[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-docs",
3
- "version": "6.4.0-alpha.35",
3
+ "version": "6.4.0-alpha.39",
4
4
  "description": "Document component usage and properties in Markdown",
5
5
  "keywords": [
6
6
  "addon",
@@ -63,22 +63,22 @@
63
63
  "@mdx-js/loader": "^1.6.22",
64
64
  "@mdx-js/mdx": "^1.6.22",
65
65
  "@mdx-js/react": "^1.6.22",
66
- "@storybook/addons": "6.4.0-alpha.35",
67
- "@storybook/api": "6.4.0-alpha.35",
68
- "@storybook/builder-webpack4": "6.4.0-alpha.35",
69
- "@storybook/client-api": "6.4.0-alpha.35",
70
- "@storybook/client-logger": "6.4.0-alpha.35",
71
- "@storybook/components": "6.4.0-alpha.35",
72
- "@storybook/core": "6.4.0-alpha.35",
73
- "@storybook/core-events": "6.4.0-alpha.35",
66
+ "@storybook/addons": "6.4.0-alpha.39",
67
+ "@storybook/api": "6.4.0-alpha.39",
68
+ "@storybook/builder-webpack4": "6.4.0-alpha.39",
69
+ "@storybook/client-api": "6.4.0-alpha.39",
70
+ "@storybook/client-logger": "6.4.0-alpha.39",
71
+ "@storybook/components": "6.4.0-alpha.39",
72
+ "@storybook/core": "6.4.0-alpha.39",
73
+ "@storybook/core-events": "6.4.0-alpha.39",
74
74
  "@storybook/csf": "0.0.2--canary.68887a1.0",
75
- "@storybook/csf-tools": "6.4.0-alpha.35",
76
- "@storybook/node-logger": "6.4.0-alpha.35",
77
- "@storybook/postinstall": "6.4.0-alpha.35",
78
- "@storybook/preview-web": "6.4.0-alpha.35",
79
- "@storybook/source-loader": "6.4.0-alpha.35",
80
- "@storybook/store": "6.4.0-alpha.35",
81
- "@storybook/theming": "6.4.0-alpha.35",
75
+ "@storybook/csf-tools": "6.4.0-alpha.39",
76
+ "@storybook/node-logger": "6.4.0-alpha.39",
77
+ "@storybook/postinstall": "6.4.0-alpha.39",
78
+ "@storybook/preview-web": "6.4.0-alpha.39",
79
+ "@storybook/source-loader": "6.4.0-alpha.39",
80
+ "@storybook/store": "6.4.0-alpha.39",
81
+ "@storybook/theming": "6.4.0-alpha.39",
82
82
  "acorn": "^7.4.1",
83
83
  "acorn-jsx": "^5.3.1",
84
84
  "acorn-walk": "^7.2.0",
@@ -107,11 +107,11 @@
107
107
  "@babel/core": "^7.12.10",
108
108
  "@emotion/core": "^10.1.1",
109
109
  "@emotion/styled": "^10.0.27",
110
- "@storybook/angular": "6.4.0-alpha.35",
111
- "@storybook/html": "6.4.0-alpha.35",
112
- "@storybook/react": "6.4.0-alpha.35",
113
- "@storybook/vue": "6.4.0-alpha.35",
114
- "@storybook/web-components": "6.4.0-alpha.35",
110
+ "@storybook/angular": "6.4.0-alpha.39",
111
+ "@storybook/html": "6.4.0-alpha.39",
112
+ "@storybook/react": "6.4.0-alpha.39",
113
+ "@storybook/vue": "6.4.0-alpha.39",
114
+ "@storybook/web-components": "6.4.0-alpha.39",
115
115
  "@types/cross-spawn": "^6.0.2",
116
116
  "@types/doctrine": "^0.0.3",
117
117
  "@types/enzyme": "^3.10.8",
@@ -141,12 +141,12 @@
141
141
  "zone.js": "^0.11.3"
142
142
  },
143
143
  "peerDependencies": {
144
- "@storybook/angular": "6.4.0-alpha.35",
145
- "@storybook/html": "6.4.0-alpha.35",
146
- "@storybook/react": "6.4.0-alpha.35",
147
- "@storybook/vue": "6.4.0-alpha.35",
148
- "@storybook/vue3": "6.4.0-alpha.35",
149
- "@storybook/web-components": "6.4.0-alpha.35",
144
+ "@storybook/angular": "6.4.0-alpha.39",
145
+ "@storybook/html": "6.4.0-alpha.39",
146
+ "@storybook/react": "6.4.0-alpha.39",
147
+ "@storybook/vue": "6.4.0-alpha.39",
148
+ "@storybook/vue3": "6.4.0-alpha.39",
149
+ "@storybook/web-components": "6.4.0-alpha.39",
150
150
  "lit": "^2.0.0-rc.1",
151
151
  "lit-html": "^1.4.1 || ^2.0.0-rc.3",
152
152
  "react": "^16.8.0 || ^17.0.0",
@@ -203,7 +203,7 @@
203
203
  "publishConfig": {
204
204
  "access": "public"
205
205
  },
206
- "gitHead": "8f65635eb105c8ef3e6ffea3c9cf6668ad34705e",
206
+ "gitHead": "b1d5f20b2fb6c52f06a85cba6e644629d9bd2e15",
207
207
  "sbmodern": "dist/modern/index.js",
208
208
  "storybook": {
209
209
  "displayName": "Docs",