@storybook/react 6.4.0-alpha.34 → 6.4.0-alpha.38

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.
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "render", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _render.render;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "renderToDOM", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _render.renderToDOM;
16
+ }
17
+ });
18
+ exports.parameters = void 0;
19
+
20
+ var _render = require("./render");
21
+
22
+ var parameters = {
23
+ framework: 'react'
24
+ };
25
+ exports.parameters = parameters;
@@ -7,27 +7,17 @@ exports.raw = exports.getStorybook = exports.forceReRender = exports.setAddon =
7
7
 
8
8
  require("core-js/modules/es.array.concat.js");
9
9
 
10
- var _react = _interopRequireDefault(require("react"));
11
-
12
10
  var _client = require("@storybook/core/client");
13
11
 
14
12
  require("./globals");
15
13
 
16
- var _render = _interopRequireDefault(require("./render"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
+ var _render = require("./render");
19
15
 
20
16
  /* eslint-disable prefer-destructuring */
21
17
  var framework = 'react';
22
-
23
- var globalRender = function globalRender(args, _ref) {
24
- var parameters = _ref.parameters;
25
- var Component = parameters.component;
26
- return /*#__PURE__*/_react.default.createElement(Component, args);
27
- };
28
-
29
- var api = (0, _client.start)(_render.default);
30
- api.clientApi.globalRender = globalRender;
18
+ var api = (0, _client.start)(_render.renderToDOM, {
19
+ render: _render.render
20
+ });
31
21
 
32
22
  var storiesOf = function storiesOf(kind, m) {
33
23
  return api.clientApi.storiesOf(kind, m).addParameters({
@@ -25,7 +25,8 @@ require("core-js/modules/es.symbol.iterator.js");
25
25
  Object.defineProperty(exports, "__esModule", {
26
26
  value: true
27
27
  });
28
- exports.default = renderMain;
28
+ exports.renderToDOM = renderToDOM;
29
+ exports.render = void 0;
29
30
 
30
31
  require("regenerator-runtime/runtime.js");
31
32
 
@@ -47,10 +48,6 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
47
48
 
48
49
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
49
50
 
50
- 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); } }
51
-
52
- 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); }); }; }
53
-
54
51
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
55
52
 
56
53
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -71,18 +68,52 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
71
68
 
72
69
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
73
70
 
74
- var document = _global.default.document,
75
- FRAMEWORK_OPTIONS = _global.default.FRAMEWORK_OPTIONS;
76
- var rootEl = document ? document.getElementById('root') : null;
71
+ 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); } }
72
+
73
+ 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); }); }; }
74
+
75
+ var FRAMEWORK_OPTIONS = _global.default.FRAMEWORK_OPTIONS;
77
76
 
78
- var render = function render(node, el) {
79
- return new Promise(function (resolve) {
80
- _reactDom.default.render(node, el, resolve);
81
- });
77
+ var render = function render(args, _ref) {
78
+ var id = _ref.id,
79
+ Component = _ref.component;
80
+
81
+ if (!Component) {
82
+ throw new Error("Unable to render story ".concat(id, " as the component annotation is missing from the default export"));
83
+ }
84
+
85
+ return /*#__PURE__*/_react.default.createElement(Component, args);
82
86
  };
83
87
 
84
- var ErrorBoundary = /*#__PURE__*/function (_Component) {
85
- _inherits(ErrorBoundary, _Component);
88
+ exports.render = render;
89
+
90
+ var renderElement = /*#__PURE__*/function () {
91
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(node, el) {
92
+ return regeneratorRuntime.wrap(function _callee$(_context) {
93
+ while (1) {
94
+ switch (_context.prev = _context.next) {
95
+ case 0:
96
+ return _context.abrupt("return", new Promise(function (resolve) {
97
+ _reactDom.default.render(node, el, function () {
98
+ return resolve(null);
99
+ });
100
+ }));
101
+
102
+ case 1:
103
+ case "end":
104
+ return _context.stop();
105
+ }
106
+ }
107
+ }, _callee);
108
+ }));
109
+
110
+ return function renderElement(_x, _x2) {
111
+ return _ref2.apply(this, arguments);
112
+ };
113
+ }();
114
+
115
+ var ErrorBoundary = /*#__PURE__*/function (_ReactComponent) {
116
+ _inherits(ErrorBoundary, _ReactComponent);
86
117
 
87
118
  var _super = _createSuper(ErrorBoundary);
88
119
 
@@ -140,43 +171,43 @@ var ErrorBoundary = /*#__PURE__*/function (_Component) {
140
171
 
141
172
  var Wrapper = FRAMEWORK_OPTIONS !== null && FRAMEWORK_OPTIONS !== void 0 && FRAMEWORK_OPTIONS.strictMode ? _react.StrictMode : _react.Fragment;
142
173
 
143
- function renderMain(_x) {
144
- return _renderMain.apply(this, arguments);
174
+ function renderToDOM(_x3, _x4) {
175
+ return _renderToDOM.apply(this, arguments);
145
176
  }
146
177
 
147
- function _renderMain() {
148
- _renderMain = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref) {
149
- var storyContext, unboundStoryFn, showMain, showException, forceRender, Story, content, element;
150
- return regeneratorRuntime.wrap(function _callee$(_context) {
178
+ function _renderToDOM() {
179
+ _renderToDOM = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(_ref3, domElement) {
180
+ var storyContext, unboundStoryFn, showMain, showException, forceRemount, Story, content, element;
181
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
151
182
  while (1) {
152
- switch (_context.prev = _context.next) {
183
+ switch (_context2.prev = _context2.next) {
153
184
  case 0:
154
- storyContext = _ref.storyContext, unboundStoryFn = _ref.unboundStoryFn, showMain = _ref.showMain, showException = _ref.showException, forceRender = _ref.forceRender;
185
+ storyContext = _ref3.storyContext, unboundStoryFn = _ref3.unboundStoryFn, showMain = _ref3.showMain, showException = _ref3.showException, forceRemount = _ref3.forceRemount;
155
186
  Story = unboundStoryFn;
156
187
  content = /*#__PURE__*/_react.default.createElement(ErrorBoundary, {
157
188
  showMain: showMain,
158
189
  showException: showException
159
190
  }, /*#__PURE__*/_react.default.createElement(Story, storyContext)); // For React 15, StrictMode & Fragment doesn't exists.
160
191
 
161
- element = Wrapper ? /*#__PURE__*/_react.default.createElement(Wrapper, null, content) : content; // We need to unmount the existing set of components in the DOM node.
192
+ element = Wrapper ? /*#__PURE__*/_react.default.createElement(Wrapper, null, content) : content; // In most cases, we need to unmount the existing set of components in the DOM node.
162
193
  // Otherwise, React may not recreate instances for every story run.
163
194
  // This could leads to issues like below:
164
195
  // https://github.com/storybookjs/react-storybook/issues/81
165
- // But forceRender means that it's the same story, so we want too keep the state in that case.
196
+ // (This is not the case when we change args or globals to the story however)
166
197
 
167
- if (!forceRender) {
168
- _reactDom.default.unmountComponentAtNode(rootEl);
198
+ if (forceRemount) {
199
+ _reactDom.default.unmountComponentAtNode(domElement);
169
200
  }
170
201
 
171
- _context.next = 7;
172
- return render(element, rootEl);
202
+ _context2.next = 7;
203
+ return renderElement(element, domElement);
173
204
 
174
205
  case 7:
175
206
  case "end":
176
- return _context.stop();
207
+ return _context2.stop();
177
208
  }
178
209
  }
179
- }, _callee);
210
+ }, _callee2);
180
211
  }));
181
- return _renderMain.apply(this, arguments);
212
+ return _renderToDOM.apply(this, arguments);
182
213
  }
@@ -0,0 +1,4 @@
1
+ export { render, renderToDOM } from './render';
2
+ export var parameters = {
3
+ framework: 'react'
4
+ };
@@ -1,20 +1,13 @@
1
1
  import "core-js/modules/es.array.concat.js";
2
2
 
3
3
  /* eslint-disable prefer-destructuring */
4
- import React from 'react';
5
4
  import { start } from '@storybook/core/client';
6
5
  import './globals';
7
- import render from './render';
6
+ import { renderToDOM, render } from './render';
8
7
  var framework = 'react';
9
-
10
- var globalRender = function globalRender(args, _ref) {
11
- var parameters = _ref.parameters;
12
- var Component = parameters.component;
13
- return /*#__PURE__*/React.createElement(Component, args);
14
- };
15
-
16
- var api = start(render);
17
- api.clientApi.globalRender = globalRender;
8
+ var api = start(renderToDOM, {
9
+ render: render
10
+ });
18
11
  export var storiesOf = function storiesOf(kind, m) {
19
12
  return api.clientApi.storiesOf(kind, m).addParameters({
20
13
  framework: framework
@@ -1,11 +1,5 @@
1
1
  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); }
2
2
 
3
- import "regenerator-runtime/runtime.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
-
9
3
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
4
 
11
5
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
@@ -26,6 +20,7 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
26
20
 
27
21
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
22
 
23
+ import "regenerator-runtime/runtime.js";
29
24
  import "core-js/modules/es.promise.js";
30
25
  import "core-js/modules/es.object.to-string.js";
31
26
  import "core-js/modules/es.array.concat.js";
@@ -37,21 +32,53 @@ import "core-js/modules/es.symbol.iterator.js";
37
32
  import "core-js/modules/es.string.iterator.js";
38
33
  import "core-js/modules/es.array.iterator.js";
39
34
  import "core-js/modules/web.dom-collections.iterator.js";
35
+
36
+ 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); } }
37
+
38
+ 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); }); }; }
39
+
40
40
  import global from 'global';
41
- import React, { Component, StrictMode, Fragment } from 'react';
41
+ import React, { Component as ReactComponent, StrictMode, Fragment } from 'react';
42
42
  import ReactDOM from 'react-dom';
43
- var document = global.document,
44
- FRAMEWORK_OPTIONS = global.FRAMEWORK_OPTIONS;
45
- var rootEl = document ? document.getElementById('root') : null;
46
-
47
- var render = function render(node, el) {
48
- return new Promise(function (resolve) {
49
- ReactDOM.render(node, el, resolve);
50
- });
43
+ var FRAMEWORK_OPTIONS = global.FRAMEWORK_OPTIONS;
44
+ export var render = function render(args, _ref) {
45
+ var id = _ref.id,
46
+ Component = _ref.component;
47
+
48
+ if (!Component) {
49
+ throw new Error("Unable to render story ".concat(id, " as the component annotation is missing from the default export"));
50
+ }
51
+
52
+ return /*#__PURE__*/React.createElement(Component, args);
51
53
  };
52
54
 
53
- var ErrorBoundary = /*#__PURE__*/function (_Component) {
54
- _inherits(ErrorBoundary, _Component);
55
+ var renderElement = /*#__PURE__*/function () {
56
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(node, el) {
57
+ return regeneratorRuntime.wrap(function _callee$(_context) {
58
+ while (1) {
59
+ switch (_context.prev = _context.next) {
60
+ case 0:
61
+ return _context.abrupt("return", new Promise(function (resolve) {
62
+ ReactDOM.render(node, el, function () {
63
+ return resolve(null);
64
+ });
65
+ }));
66
+
67
+ case 1:
68
+ case "end":
69
+ return _context.stop();
70
+ }
71
+ }
72
+ }, _callee);
73
+ }));
74
+
75
+ return function renderElement(_x, _x2) {
76
+ return _ref2.apply(this, arguments);
77
+ };
78
+ }();
79
+
80
+ var ErrorBoundary = /*#__PURE__*/function (_ReactComponent) {
81
+ _inherits(ErrorBoundary, _ReactComponent);
55
82
 
56
83
  var _super = _createSuper(ErrorBoundary);
57
84
 
@@ -105,46 +132,46 @@ var ErrorBoundary = /*#__PURE__*/function (_Component) {
105
132
  }]);
106
133
 
107
134
  return ErrorBoundary;
108
- }(Component);
135
+ }(ReactComponent);
109
136
 
110
137
  var Wrapper = FRAMEWORK_OPTIONS !== null && FRAMEWORK_OPTIONS !== void 0 && FRAMEWORK_OPTIONS.strictMode ? StrictMode : Fragment;
111
- export default function renderMain(_x) {
112
- return _renderMain.apply(this, arguments);
138
+ export function renderToDOM(_x3, _x4) {
139
+ return _renderToDOM.apply(this, arguments);
113
140
  }
114
141
 
115
- function _renderMain() {
116
- _renderMain = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(_ref) {
117
- var storyContext, unboundStoryFn, showMain, showException, forceRender, Story, content, element;
118
- return regeneratorRuntime.wrap(function _callee$(_context) {
142
+ function _renderToDOM() {
143
+ _renderToDOM = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(_ref3, domElement) {
144
+ var storyContext, unboundStoryFn, showMain, showException, forceRemount, Story, content, element;
145
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
119
146
  while (1) {
120
- switch (_context.prev = _context.next) {
147
+ switch (_context2.prev = _context2.next) {
121
148
  case 0:
122
- storyContext = _ref.storyContext, unboundStoryFn = _ref.unboundStoryFn, showMain = _ref.showMain, showException = _ref.showException, forceRender = _ref.forceRender;
149
+ storyContext = _ref3.storyContext, unboundStoryFn = _ref3.unboundStoryFn, showMain = _ref3.showMain, showException = _ref3.showException, forceRemount = _ref3.forceRemount;
123
150
  Story = unboundStoryFn;
124
151
  content = /*#__PURE__*/React.createElement(ErrorBoundary, {
125
152
  showMain: showMain,
126
153
  showException: showException
127
154
  }, /*#__PURE__*/React.createElement(Story, storyContext)); // For React 15, StrictMode & Fragment doesn't exists.
128
155
 
129
- element = Wrapper ? /*#__PURE__*/React.createElement(Wrapper, null, content) : content; // We need to unmount the existing set of components in the DOM node.
156
+ element = Wrapper ? /*#__PURE__*/React.createElement(Wrapper, null, content) : content; // In most cases, we need to unmount the existing set of components in the DOM node.
130
157
  // Otherwise, React may not recreate instances for every story run.
131
158
  // This could leads to issues like below:
132
159
  // https://github.com/storybookjs/react-storybook/issues/81
133
- // But forceRender means that it's the same story, so we want too keep the state in that case.
160
+ // (This is not the case when we change args or globals to the story however)
134
161
 
135
- if (!forceRender) {
136
- ReactDOM.unmountComponentAtNode(rootEl);
162
+ if (forceRemount) {
163
+ ReactDOM.unmountComponentAtNode(domElement);
137
164
  }
138
165
 
139
- _context.next = 7;
140
- return render(element, rootEl);
166
+ _context2.next = 7;
167
+ return renderElement(element, domElement);
141
168
 
142
169
  case 7:
143
170
  case "end":
144
- return _context.stop();
171
+ return _context2.stop();
145
172
  }
146
173
  }
147
- }, _callee);
174
+ }, _callee2);
148
175
  }));
149
- return _renderMain.apply(this, arguments);
176
+ return _renderToDOM.apply(this, arguments);
150
177
  }
@@ -0,0 +1,4 @@
1
+ export { render, renderToDOM } from './render';
2
+ export const parameters = {
3
+ framework: 'react'
4
+ };
@@ -1,19 +1,11 @@
1
1
  /* eslint-disable prefer-destructuring */
2
- import React from 'react';
3
2
  import { start } from '@storybook/core/client';
4
3
  import './globals';
5
- import render from './render';
4
+ import { renderToDOM, render } from './render';
6
5
  const framework = 'react';
7
-
8
- const globalRender = (args, {
9
- parameters
10
- }) => {
11
- const Component = parameters.component;
12
- return /*#__PURE__*/React.createElement(Component, args);
13
- };
14
-
15
- const api = start(render);
16
- api.clientApi.globalRender = globalRender;
6
+ const api = start(renderToDOM, {
7
+ render
8
+ });
17
9
  export const storiesOf = (kind, m) => {
18
10
  return api.clientApi.storiesOf(kind, m).addParameters({
19
11
  framework
@@ -1,17 +1,25 @@
1
1
  import global from 'global';
2
- import React, { Component, StrictMode, Fragment } from 'react';
2
+ import React, { Component as ReactComponent, StrictMode, Fragment } from 'react';
3
3
  import ReactDOM from 'react-dom';
4
4
  const {
5
- document,
6
5
  FRAMEWORK_OPTIONS
7
6
  } = global;
8
- const rootEl = document ? document.getElementById('root') : null;
7
+ export const render = (args, {
8
+ id,
9
+ component: Component
10
+ }) => {
11
+ if (!Component) {
12
+ throw new Error(`Unable to render story ${id} as the component annotation is missing from the default export`);
13
+ }
14
+
15
+ return /*#__PURE__*/React.createElement(Component, args);
16
+ };
9
17
 
10
- const render = (node, el) => new Promise(resolve => {
11
- ReactDOM.render(node, el, resolve);
18
+ const renderElement = async (node, el) => new Promise(resolve => {
19
+ ReactDOM.render(node, el, () => resolve(null));
12
20
  });
13
21
 
14
- class ErrorBoundary extends Component {
22
+ class ErrorBoundary extends ReactComponent {
15
23
  constructor(...args) {
16
24
  super(...args);
17
25
  this.state = {
@@ -59,28 +67,28 @@ class ErrorBoundary extends Component {
59
67
  }
60
68
 
61
69
  const Wrapper = FRAMEWORK_OPTIONS !== null && FRAMEWORK_OPTIONS !== void 0 && FRAMEWORK_OPTIONS.strictMode ? StrictMode : Fragment;
62
- export default async function renderMain({
70
+ export async function renderToDOM({
63
71
  storyContext,
64
72
  unboundStoryFn,
65
73
  showMain,
66
74
  showException,
67
- forceRender
68
- }) {
75
+ forceRemount
76
+ }, domElement) {
69
77
  const Story = unboundStoryFn;
70
78
  const content = /*#__PURE__*/React.createElement(ErrorBoundary, {
71
79
  showMain: showMain,
72
80
  showException: showException
73
81
  }, /*#__PURE__*/React.createElement(Story, storyContext)); // For React 15, StrictMode & Fragment doesn't exists.
74
82
 
75
- const element = Wrapper ? /*#__PURE__*/React.createElement(Wrapper, null, content) : content; // We need to unmount the existing set of components in the DOM node.
83
+ const element = Wrapper ? /*#__PURE__*/React.createElement(Wrapper, null, content) : content; // In most cases, we need to unmount the existing set of components in the DOM node.
76
84
  // Otherwise, React may not recreate instances for every story run.
77
85
  // This could leads to issues like below:
78
86
  // https://github.com/storybookjs/react-storybook/issues/81
79
- // But forceRender means that it's the same story, so we want too keep the state in that case.
87
+ // (This is not the case when we change args or globals to the story however)
80
88
 
81
- if (!forceRender) {
82
- ReactDOM.unmountComponentAtNode(rootEl);
89
+ if (forceRemount) {
90
+ ReactDOM.unmountComponentAtNode(domElement);
83
91
  }
84
92
 
85
- await render(element, rootEl);
93
+ await renderElement(element, domElement);
86
94
  }
@@ -0,0 +1,4 @@
1
+ export { render, renderToDOM } from './render';
2
+ export declare const parameters: {
3
+ framework: string;
4
+ };
@@ -2,8 +2,9 @@
2
2
  /// <reference types="node" />
3
3
  import { ClientStoryApi, Loadable } from '@storybook/addons';
4
4
  import './globals';
5
- import { IStorybookSection, StoryFnReactReturnType } from './types';
6
- interface ClientApi extends ClientStoryApi<StoryFnReactReturnType> {
5
+ import { IStorybookSection } from './types';
6
+ import { ReactFramework } from './types-6-0';
7
+ interface ClientApi extends ClientStoryApi<ReactFramework['storyResult']> {
7
8
  setAddon(addon: any): void;
8
9
  configure(loader: Loadable, module: NodeModule): void;
9
10
  getStorybook(): IStorybookSection[];
@@ -1,2 +1,5 @@
1
- import { RenderContext } from './types';
2
- export default function renderMain({ storyContext, unboundStoryFn, showMain, showException, forceRender, }: RenderContext): Promise<void>;
1
+ import { RenderContext } from '@storybook/store';
2
+ import { ArgsStoryFn } from '@storybook/csf';
3
+ import { ReactFramework } from './types-6-0';
4
+ export declare const render: ArgsStoryFn<ReactFramework>;
5
+ export declare function renderToDOM({ storyContext, unboundStoryFn, showMain, showException, forceRemount, }: RenderContext<ReactFramework>, domElement: HTMLElement): Promise<void>;
@@ -1,18 +1,20 @@
1
1
  import { ComponentType } from 'react';
2
- import { Args as DefaultArgs, Annotations, BaseMeta, BaseStory } from '@storybook/addons';
2
+ import { Args, ComponentAnnotations, StoryAnnotationsOrFn } from '@storybook/csf';
3
3
  import { StoryFnReactReturnType } from './types';
4
- export { Args, ArgTypes, Parameters, StoryContext } from '@storybook/addons';
5
- declare type ReactComponent = ComponentType<any>;
6
- declare type ReactReturnType = StoryFnReactReturnType;
4
+ export { Args, ArgTypes, Parameters, StoryContext } from '@storybook/csf';
5
+ export declare type ReactFramework = {
6
+ component: ComponentType<any>;
7
+ storyResult: StoryFnReactReturnType;
8
+ };
7
9
  /**
8
10
  * Metadata to configure the stories for a component.
9
11
  *
10
12
  * @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
11
13
  */
12
- export declare type Meta<Args = DefaultArgs> = BaseMeta<ReactComponent> & Annotations<Args, ReactReturnType>;
14
+ export declare type Meta<TArgs = Args> = ComponentAnnotations<ReactFramework, TArgs>;
13
15
  /**
14
16
  * Story function that represents a component example.
15
17
  *
16
18
  * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
17
19
  */
18
- export declare type Story<Args = DefaultArgs> = BaseStory<Args, ReactReturnType> & Annotations<Args, ReactReturnType>;
20
+ export declare type Story<TArgs = Args> = StoryAnnotationsOrFn<ReactFramework, TArgs>;
@@ -1,6 +1,6 @@
1
1
  import { ReactElement } from 'react';
2
- export { RenderContext } from '@storybook/client-api';
3
- export { StoryContext } from '@storybook/addons';
2
+ export { RenderContext } from '@storybook/store';
3
+ export { StoryContext } from '@storybook/csf';
4
4
  export interface ShowErrorArgs {
5
5
  title: string;
6
6
  description: string;
@@ -8,7 +8,7 @@ export interface ShowErrorArgs {
8
8
  export declare type StoryFnReactReturnType = ReactElement<unknown>;
9
9
  export interface IStorybookStory {
10
10
  name: string;
11
- render: () => any;
11
+ render: (context: any) => any;
12
12
  }
13
13
  export interface IStorybookSection {
14
14
  kind: string;
@@ -0,0 +1,4 @@
1
+ export { render, renderToDOM } from './render';
2
+ export declare const parameters: {
3
+ framework: string;
4
+ };
@@ -2,8 +2,9 @@
2
2
  /// <reference types="node" />
3
3
  import { ClientStoryApi, Loadable } from '@storybook/addons';
4
4
  import './globals';
5
- import { IStorybookSection, StoryFnReactReturnType } from './types';
6
- interface ClientApi extends ClientStoryApi<StoryFnReactReturnType> {
5
+ import { IStorybookSection } from './types';
6
+ import { ReactFramework } from './types-6-0';
7
+ interface ClientApi extends ClientStoryApi<ReactFramework['storyResult']> {
7
8
  setAddon(addon: any): void;
8
9
  configure(loader: Loadable, module: NodeModule): void;
9
10
  getStorybook(): IStorybookSection[];
@@ -1,2 +1,5 @@
1
- import { RenderContext } from './types';
2
- export default function renderMain({ storyContext, unboundStoryFn, showMain, showException, forceRender, }: RenderContext): Promise<void>;
1
+ import { RenderContext } from '@storybook/store';
2
+ import { ArgsStoryFn } from '@storybook/csf';
3
+ import { ReactFramework } from './types-6-0';
4
+ export declare const render: ArgsStoryFn<ReactFramework>;
5
+ export declare function renderToDOM({ storyContext, unboundStoryFn, showMain, showException, forceRemount, }: RenderContext<ReactFramework>, domElement: HTMLElement): Promise<void>;
@@ -1,18 +1,20 @@
1
1
  import { ComponentType } from 'react';
2
- import { Args as DefaultArgs, Annotations, BaseMeta, BaseStory } from '@storybook/addons';
2
+ import { Args, ComponentAnnotations, StoryAnnotationsOrFn } from '@storybook/csf';
3
3
  import { StoryFnReactReturnType } from './types';
4
- export type { Args, ArgTypes, Parameters, StoryContext } from '@storybook/addons';
5
- declare type ReactComponent = ComponentType<any>;
6
- declare type ReactReturnType = StoryFnReactReturnType;
4
+ export type { Args, ArgTypes, Parameters, StoryContext } from '@storybook/csf';
5
+ export declare type ReactFramework = {
6
+ component: ComponentType<any>;
7
+ storyResult: StoryFnReactReturnType;
8
+ };
7
9
  /**
8
10
  * Metadata to configure the stories for a component.
9
11
  *
10
12
  * @see [Default export](https://storybook.js.org/docs/formats/component-story-format/#default-export)
11
13
  */
12
- export declare type Meta<Args = DefaultArgs> = BaseMeta<ReactComponent> & Annotations<Args, ReactReturnType>;
14
+ export declare type Meta<TArgs = Args> = ComponentAnnotations<ReactFramework, TArgs>;
13
15
  /**
14
16
  * Story function that represents a component example.
15
17
  *
16
18
  * @see [Named Story exports](https://storybook.js.org/docs/formats/component-story-format/#named-story-exports)
17
19
  */
18
- export declare type Story<Args = DefaultArgs> = BaseStory<Args, ReactReturnType> & Annotations<Args, ReactReturnType>;
20
+ export declare type Story<TArgs = Args> = StoryAnnotationsOrFn<ReactFramework, TArgs>;
@@ -1,6 +1,6 @@
1
1
  import { ReactElement } from 'react';
2
- export type { RenderContext } from '@storybook/client-api';
3
- export type { StoryContext } from '@storybook/addons';
2
+ export type { RenderContext } from '@storybook/store';
3
+ export type { StoryContext } from '@storybook/csf';
4
4
  export interface ShowErrorArgs {
5
5
  title: string;
6
6
  description: string;
@@ -8,7 +8,7 @@ export interface ShowErrorArgs {
8
8
  export declare type StoryFnReactReturnType = ReactElement<unknown>;
9
9
  export interface IStorybookStory {
10
10
  name: string;
11
- render: () => any;
11
+ render: (context: any) => any;
12
12
  }
13
13
  export interface IStorybookSection {
14
14
  kind: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/react",
3
- "version": "6.4.0-alpha.34",
3
+ "version": "6.4.0-alpha.38",
4
4
  "description": "Storybook for React: Develop React Component in isolation with Hot Reloading.",
5
5
  "keywords": [
6
6
  "storybook"
@@ -49,12 +49,14 @@
49
49
  "@babel/preset-flow": "^7.12.1",
50
50
  "@babel/preset-react": "^7.12.10",
51
51
  "@pmmmwh/react-refresh-webpack-plugin": "^0.5.0-rc.2",
52
- "@storybook/addons": "6.4.0-alpha.34",
53
- "@storybook/core": "6.4.0-alpha.34",
54
- "@storybook/core-common": "6.4.0-alpha.34",
55
- "@storybook/node-logger": "6.4.0-alpha.34",
52
+ "@storybook/addons": "6.4.0-alpha.38",
53
+ "@storybook/core": "6.4.0-alpha.38",
54
+ "@storybook/core-common": "6.4.0-alpha.38",
55
+ "@storybook/csf": "0.0.2--canary.68887a1.0",
56
+ "@storybook/node-logger": "6.4.0-alpha.38",
56
57
  "@storybook/react-docgen-typescript-plugin": "1.0.2-canary.253f8c1.0",
57
58
  "@storybook/semver": "^7.3.2",
59
+ "@storybook/store": "6.4.0-alpha.38",
58
60
  "@types/webpack-env": "^1.16.0",
59
61
  "babel-plugin-add-react-displayname": "^0.0.5",
60
62
  "babel-plugin-named-asset-import": "^0.3.1",
@@ -71,7 +73,7 @@
71
73
  "webpack": "4"
72
74
  },
73
75
  "devDependencies": {
74
- "@storybook/client-api": "6.4.0-alpha.34",
76
+ "@storybook/client-api": "6.4.0-alpha.38",
75
77
  "@types/node": "^14.14.20",
76
78
  "@types/prompts": "^2.0.9"
77
79
  },
@@ -94,6 +96,6 @@
94
96
  "publishConfig": {
95
97
  "access": "public"
96
98
  },
97
- "gitHead": "ccd25210cd159e42110b700b0562e951bb9b3a57",
99
+ "gitHead": "14b9d19e7e9e3de84729ce0c7989efa372c6987c",
98
100
  "sbmodern": "dist/modern/client/index.js"
99
101
  }
package/preset.js ADDED
@@ -0,0 +1,7 @@
1
+ function config(entry = []) {
2
+ return [...entry, require.resolve('./dist/esm/client/preview/config')];
3
+ }
4
+
5
+ module.exports = {
6
+ config,
7
+ };