@storybook/addon-docs 7.0.0-alpha.1 → 7.0.0-alpha.4

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.
@@ -4,15 +4,15 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.SourceType = exports.SNIPPET_RENDERED = exports.PARAM_KEY = exports.PANEL_ID = exports.ADDON_ID = void 0;
7
- var ADDON_ID = 'storybook/docs';
7
+ const ADDON_ID = 'storybook/docs';
8
8
  exports.ADDON_ID = ADDON_ID;
9
- var PANEL_ID = "".concat(ADDON_ID, "/panel");
9
+ const PANEL_ID = `${ADDON_ID}/panel`;
10
10
  exports.PANEL_ID = PANEL_ID;
11
- var PARAM_KEY = "docs";
11
+ const PARAM_KEY = `docs`;
12
12
  exports.PARAM_KEY = PARAM_KEY;
13
- var SNIPPET_RENDERED = "".concat(ADDON_ID, "/snippet-rendered");
13
+ const SNIPPET_RENDERED = `${ADDON_ID}/snippet-rendered`;
14
14
  exports.SNIPPET_RENDERED = SNIPPET_RENDERED;
15
- var SourceType;
15
+ let SourceType;
16
16
  exports.SourceType = SourceType;
17
17
 
18
18
  (function (SourceType) {
@@ -1,10 +1,7 @@
1
1
  import React, { useContext, useRef, useEffect, useState } from 'react';
2
2
  import { MDXProvider } from '@mdx-js/react';
3
- import global from 'global';
4
3
  import { resetComponents, Story as PureStory, StorySkeleton } from '@storybook/components';
5
4
  import { toId, storyNameFromExport } from '@storybook/csf';
6
- import { addons } from '@storybook/addons';
7
- import Events from '@storybook/core-events';
8
5
  import { CURRENT_SELECTION } from './types';
9
6
  import { DocsContext } from './DocsContext';
10
7
  import { useStory } from './useStory';
@@ -26,7 +23,7 @@ export const getStoryId = (props, context) => {
26
23
  export const getStoryProps = ({
27
24
  height,
28
25
  inline
29
- }, story, context, onStoryFnCalled) => {
26
+ }, story) => {
30
27
  const {
31
28
  name: storyName,
32
29
  parameters
@@ -42,51 +39,21 @@ export const getStoryProps = ({
42
39
 
43
40
  const {
44
41
  inlineStories = false,
45
- iframeHeight = 100,
46
- prepareForInline
42
+ iframeHeight = 100
47
43
  } = docs;
48
44
  const storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
49
-
50
- if (storyIsInline && !prepareForInline) {
51
- throw new Error(`Story '${storyName}' is set to render inline, but no 'prepareForInline' function is implemented in your docs configuration!`);
52
- }
53
-
54
- const boundStoryFn = () => {
55
- const storyResult = story.unboundStoryFn(Object.assign({}, context.getStoryContext(story), {
56
- loaded: {},
57
- abortSignal: undefined,
58
- canvasElement: undefined
59
- })); // We need to wait until the bound story function has actually been called before we
60
- // consider the story rendered. Certain frameworks (i.e. angular) don't actually render
61
- // the component in the very first react render cycle, and so we can't just wait until the
62
- // `PureStory` component has been rendered to consider the underlying story "rendered".
63
-
64
- onStoryFnCalled();
65
- return storyResult;
66
- };
67
-
68
45
  return Object.assign({
69
46
  inline: storyIsInline,
70
47
  id: story.id,
71
48
  height: height || (storyIsInline ? undefined : iframeHeight),
72
49
  title: storyName
73
50
  }, storyIsInline && {
74
- parameters,
75
- storyFn: () => prepareForInline(boundStoryFn, context.getStoryContext(story))
51
+ parameters
76
52
  });
77
53
  };
78
54
 
79
- function makeGate() {
80
- let open;
81
- const gate = new Promise(r => {
82
- open = r;
83
- });
84
- return [gate, open];
85
- }
86
-
87
55
  const Story = props => {
88
56
  const context = useContext(DocsContext);
89
- const channel = addons.getChannel();
90
57
  const storyRef = useRef();
91
58
  const storyId = getStoryId(props, context);
92
59
  const story = useStory(storyId, context);
@@ -102,54 +69,35 @@ const Story = props => {
102
69
 
103
70
  return () => cleanup && cleanup();
104
71
  }, [story]);
105
- const [storyFnRan, onStoryFnRan] = makeGate();
106
- const [rendered, onRendered] = makeGate();
107
- useEffect(onRendered);
108
72
 
109
73
  if (!story) {
110
74
  return /*#__PURE__*/React.createElement(StorySkeleton, null);
111
75
  }
112
76
 
113
- const storyProps = getStoryProps(props, story, context, onStoryFnRan);
77
+ const storyProps = getStoryProps(props, story);
114
78
 
115
79
  if (!storyProps) {
116
80
  return null;
117
81
  }
118
82
 
119
83
  if (storyProps.inline) {
120
- // If we are rendering a old-style inline Story via `PureStory` below, we want to emit
121
- // the `STORY_RENDERED` event when it renders. The modern mode below calls out to
122
- // `Preview.renderStoryToDom()` which itself emits the event.
123
- if (!global?.FEATURES?.modernInlineRender) {
124
- // We need to wait for two things before we can consider the story rendered:
125
- // (a) React's `useEffect` hook needs to fire. This is needed for React stories, as
126
- // decorators of the form `<A><B/></A>` will not actually execute `B` in the first
127
- // call to the story function.
128
- // (b) The story function needs to actually have been called.
129
- // Certain frameworks (i.e.angular) don't actually render the component in the very first
130
- // React render cycle, so we need to wait for the framework to actually do that
131
- Promise.all([storyFnRan, rendered]).then(() => {
132
- channel.emit(Events.STORY_RENDERED, storyId);
133
- });
134
- } else {
135
- // We do this so React doesn't complain when we replace the span in a secondary render
136
- const htmlContents = `<span></span>`; // FIXME: height/style/etc. lifted from PureStory
137
-
138
- const {
139
- height
140
- } = storyProps;
141
- return /*#__PURE__*/React.createElement("div", {
142
- id: storyBlockIdFromId(story.id)
143
- }, /*#__PURE__*/React.createElement(MDXProvider, {
144
- components: resetComponents
145
- }, height ? /*#__PURE__*/React.createElement("style", null, `#story--${story.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`) : null, showLoader && /*#__PURE__*/React.createElement(StorySkeleton, null), /*#__PURE__*/React.createElement("div", {
146
- ref: storyRef,
147
- "data-name": story.name,
148
- dangerouslySetInnerHTML: {
149
- __html: htmlContents
150
- }
151
- })));
152
- }
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
+ })));
153
101
  }
154
102
 
155
103
  return /*#__PURE__*/React.createElement("div", {
@@ -1,7 +1,7 @@
1
1
  import { FunctionComponent, ReactNode, ElementType, ComponentProps } from 'react';
2
2
  import { Story as PureStory } from '@storybook/components';
3
3
  import { StoryId, StoryAnnotations, AnyFramework } from '@storybook/csf';
4
- import { Story as StoryType } from '@storybook/store';
4
+ import type { Story as StoryType } from '@storybook/store';
5
5
  import { DocsContextProps } from './DocsContext';
6
6
  export declare const storyBlockIdFromId: (storyId: string) => string;
7
7
  declare type PureStoryProps = ComponentProps<typeof PureStory>;
@@ -23,6 +23,6 @@ declare type StoryImportProps = {
23
23
  export declare type StoryProps = (StoryDefProps | StoryRefProps | StoryImportProps) & CommonProps;
24
24
  export declare const lookupStoryId: (storyName: string, { mdxStoryNameToKey, mdxComponentAnnotations }: DocsContextProps) => string;
25
25
  export declare const getStoryId: (props: StoryProps, context: DocsContextProps) => StoryId;
26
- export declare const getStoryProps: <TFramework extends AnyFramework>({ height, inline }: StoryProps, story: StoryType<TFramework>, context: DocsContextProps<TFramework>, onStoryFnCalled: () => void) => PureStoryProps;
26
+ export declare const getStoryProps: <TFramework extends AnyFramework>({ height, inline }: StoryProps, story: StoryType<TFramework>) => PureStoryProps;
27
27
  declare const Story: FunctionComponent<StoryProps>;
28
28
  export { Story };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-docs",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-alpha.4",
4
4
  "description": "Document component usage and properties in Markdown",
5
5
  "keywords": [
6
6
  "addon",
@@ -52,26 +52,26 @@
52
52
  "@babel/preset-env": "^7.12.11",
53
53
  "@jest/transform": "^26.6.2",
54
54
  "@mdx-js/react": "^1.6.22",
55
- "@storybook/addons": "7.0.0-alpha.1",
56
- "@storybook/api": "7.0.0-alpha.1",
57
- "@storybook/components": "7.0.0-alpha.1",
58
- "@storybook/core-common": "7.0.0-alpha.1",
59
- "@storybook/core-events": "7.0.0-alpha.1",
55
+ "@storybook/addons": "7.0.0-alpha.4",
56
+ "@storybook/api": "7.0.0-alpha.4",
57
+ "@storybook/components": "7.0.0-alpha.4",
58
+ "@storybook/core-common": "7.0.0-alpha.4",
59
+ "@storybook/core-events": "7.0.0-alpha.4",
60
60
  "@storybook/csf": "0.0.2--canary.4566f4d.1",
61
- "@storybook/docs-tools": "7.0.0-alpha.1",
61
+ "@storybook/csf-tools": "7.0.0-alpha.4",
62
+ "@storybook/docs-tools": "7.0.0-alpha.4",
62
63
  "@storybook/mdx1-csf": "^0.0.1",
63
- "@storybook/node-logger": "7.0.0-alpha.1",
64
- "@storybook/postinstall": "7.0.0-alpha.1",
65
- "@storybook/preview-web": "7.0.0-alpha.1",
66
- "@storybook/source-loader": "7.0.0-alpha.1",
67
- "@storybook/store": "7.0.0-alpha.1",
68
- "@storybook/theming": "7.0.0-alpha.1",
64
+ "@storybook/node-logger": "7.0.0-alpha.4",
65
+ "@storybook/postinstall": "7.0.0-alpha.4",
66
+ "@storybook/preview-web": "7.0.0-alpha.4",
67
+ "@storybook/source-loader": "7.0.0-alpha.4",
68
+ "@storybook/store": "7.0.0-alpha.4",
69
+ "@storybook/theming": "7.0.0-alpha.4",
69
70
  "babel-loader": "^8.2.5",
70
71
  "core-js": "^3.8.2",
71
72
  "fast-deep-equal": "^3.1.3",
72
73
  "global": "^4.4.0",
73
74
  "lodash": "^4.17.21",
74
- "regenerator-runtime": "^0.13.7",
75
75
  "remark-external-links": "^8.0.0",
76
76
  "remark-slug": "^6.0.0",
77
77
  "ts-dedent": "^2.0.0",
@@ -101,7 +101,7 @@
101
101
  "publishConfig": {
102
102
  "access": "public"
103
103
  },
104
- "gitHead": "b90b85210f66da59656c2ef58b0910b156256bea",
104
+ "gitHead": "006ed54452dd7c37a8cbe91a84f5312182f7ca00",
105
105
  "storybook": {
106
106
  "displayName": "Docs",
107
107
  "icon": "https://user-images.githubusercontent.com/263385/101991672-48355c80-3c7c-11eb-82d9-95fa12438f64.png",