1 | "use strict";
|
2 |
|
3 | require("core-js/modules/es.array.concat.js");
|
4 |
|
5 | require("core-js/modules/es.array.for-each.js");
|
6 |
|
7 | require("core-js/modules/es.object.assign.js");
|
8 |
|
9 | require("core-js/modules/es.object.get-prototype-of.js");
|
10 |
|
11 | require("core-js/modules/es.object.keys.js");
|
12 |
|
13 | require("core-js/modules/es.object.to-string.js");
|
14 |
|
15 | require("core-js/modules/es.regexp.to-string.js");
|
16 |
|
17 | require("core-js/modules/web.dom-collections.for-each.js");
|
18 |
|
19 | Object.defineProperty(exports, "__esModule", {
|
20 | value: true
|
21 | });
|
22 | exports.default = exports.addArgTypesEnhancer = exports.addLoader = exports.addParameters = exports.addDecorator = void 0;
|
23 |
|
24 | var _utilDeprecate = _interopRequireDefault(require("util-deprecate"));
|
25 |
|
26 | var _tsDedent = _interopRequireDefault(require("ts-dedent"));
|
27 |
|
28 | var _clientLogger = require("@storybook/client-logger");
|
29 |
|
30 | var _csf = require("@storybook/csf");
|
31 |
|
32 | var _hooks = require("./hooks");
|
33 |
|
34 | var _decorators = require("./decorators");
|
35 |
|
36 | var _templateObject, _templateObject2;
|
37 |
|
38 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
39 |
|
40 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
41 |
|
42 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
43 |
|
44 | 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); }
|
45 |
|
46 | function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
47 |
|
48 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
49 |
|
50 |
|
51 |
|
52 | var singleton;
|
53 | var addDecoratorDeprecationWarning = (0, _utilDeprecate.default)(function () {}, "`addDecorator` is deprecated, and will be removed in Storybook 7.0.\nInstead, use `export const decorators = [];` in your `preview.js`.\nRead more at https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-addparameters-and-adddecorator).");
|
54 |
|
55 | var addDecorator = function addDecorator(decorator) {
|
56 | var deprecationWarning = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
57 | if (!singleton) throw new Error("Singleton client API not yet initialized, cannot call addDecorator");
|
58 | if (deprecationWarning) addDecoratorDeprecationWarning();
|
59 | singleton.addDecorator(decorator);
|
60 | };
|
61 |
|
62 | exports.addDecorator = addDecorator;
|
63 | var addParametersDeprecationWarning = (0, _utilDeprecate.default)(function () {}, "`addParameters` is deprecated, and will be removed in Storybook 7.0.\nInstead, use `export const parameters = {};` in your `preview.js`.\nRead more at https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-addparameters-and-adddecorator).");
|
64 |
|
65 | var addParameters = function addParameters(parameters) {
|
66 | var deprecationWarning = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
67 | if (!singleton) throw new Error("Singleton client API not yet initialized, cannot call addParameters");
|
68 | if (deprecationWarning) addParametersDeprecationWarning();
|
69 | singleton.addParameters(parameters);
|
70 | };
|
71 |
|
72 | exports.addParameters = addParameters;
|
73 | var addLoaderDeprecationWarning = (0, _utilDeprecate.default)(function () {}, "`addLoader` is deprecated, and will be removed in Storybook 7.0.\nInstead, use `export const loaders = [];` in your `preview.js`.\nRead more at https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-addparameters-and-adddecorator).");
|
74 |
|
75 | var addLoader = function addLoader(loader) {
|
76 | var deprecationWarning = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
|
77 | if (!singleton) throw new Error("Singleton client API not yet initialized, cannot call addParameters");
|
78 | if (deprecationWarning) addLoaderDeprecationWarning();
|
79 | singleton.addLoader(loader);
|
80 | };
|
81 |
|
82 | exports.addLoader = addLoader;
|
83 |
|
84 | var addArgTypesEnhancer = function addArgTypesEnhancer(enhancer) {
|
85 | if (!singleton) throw new Error("Singleton client API not yet initialized, cannot call addArgTypesEnhancer");
|
86 | singleton.addArgTypesEnhancer(enhancer);
|
87 | };
|
88 |
|
89 | exports.addArgTypesEnhancer = addArgTypesEnhancer;
|
90 |
|
91 | var ClientApi =
|
92 | function ClientApi(_ref) {
|
93 | var _this = this;
|
94 |
|
95 | var storyStore = _ref.storyStore,
|
96 | _ref$decorateStory = _ref.decorateStory,
|
97 | decorateStory = _ref$decorateStory === void 0 ? _decorators.defaultDecorateStory : _ref$decorateStory,
|
98 | noStoryModuleAddMethodHotDispose = _ref.noStoryModuleAddMethodHotDispose;
|
99 |
|
100 | _classCallCheck(this, ClientApi);
|
101 |
|
102 | this._storyStore = void 0;
|
103 | this._addons = void 0;
|
104 | this._decorateStory = void 0;
|
105 | this._noStoryModuleAddMethodHotDispose = void 0;
|
106 | this.setAddon = (0, _utilDeprecate.default)(function (addon) {
|
107 | _this._addons = Object.assign({}, _this._addons, addon);
|
108 | }, (0, _tsDedent.default)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n `setAddon` is deprecated and will be removed in Storybook 7.0.\n\n https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-setaddon\n "], ["\n \\`setAddon\\` is deprecated and will be removed in Storybook 7.0.\n\n https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-setaddon\n "]))));
|
109 |
|
110 | this.addDecorator = function (decorator) {
|
111 | _this._storyStore.addGlobalMetadata({
|
112 | decorators: [decorator]
|
113 | });
|
114 | };
|
115 |
|
116 | this.clearDecorators = (0, _utilDeprecate.default)(function () {
|
117 | _this._storyStore.clearGlobalDecorators();
|
118 | }, (0, _tsDedent.default)(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n `clearDecorators` is deprecated and will be removed in Storybook 7.0.\n\n https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-cleardecorators\n "], ["\n \\`clearDecorators\\` is deprecated and will be removed in Storybook 7.0.\n\n https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-cleardecorators\n "]))));
|
119 |
|
120 | this.addParameters = function (parameters) {
|
121 | _this._storyStore.addGlobalMetadata({
|
122 | parameters: parameters
|
123 | });
|
124 | };
|
125 |
|
126 | this.addLoader = function (loader) {
|
127 | _this._storyStore.addGlobalMetadata({
|
128 | loaders: [loader]
|
129 | });
|
130 | };
|
131 |
|
132 | this.addArgTypesEnhancer = function (enhancer) {
|
133 | _this._storyStore.addArgTypesEnhancer(enhancer);
|
134 | };
|
135 |
|
136 | this.storiesOf = function (kind, m) {
|
137 | if (!kind && typeof kind !== 'string') {
|
138 | throw new Error('Invalid or missing kind provided for stories, should be a string');
|
139 | }
|
140 |
|
141 | if (!m) {
|
142 | _clientLogger.logger.warn("Missing 'module' parameter for story with a kind of '".concat(kind, "'. It will break your HMR"));
|
143 | }
|
144 |
|
145 | if (m) {
|
146 | var proto = Object.getPrototypeOf(m);
|
147 |
|
148 | if (proto.exports && proto.exports.default) {
|
149 |
|
150 | _clientLogger.logger.error("Illegal mix of CSF default export and storiesOf calls in a single file: ".concat(proto.i));
|
151 | }
|
152 | }
|
153 |
|
154 | if (m && m.hot && m.hot.dispose) {
|
155 | m.hot.dispose(function () {
|
156 | var _storyStore = _this._storyStore;
|
157 |
|
158 |
|
159 |
|
160 | _storyStore.removeStoryKind(kind, {
|
161 | allowUnsafe: true
|
162 | });
|
163 | });
|
164 | }
|
165 |
|
166 | var hasAdded = false;
|
167 | var api = {
|
168 | kind: kind.toString(),
|
169 | add: function add() {
|
170 | return api;
|
171 | },
|
172 | addDecorator: function addDecorator() {
|
173 | return api;
|
174 | },
|
175 | addLoader: function addLoader() {
|
176 | return api;
|
177 | },
|
178 | addParameters: function addParameters() {
|
179 | return api;
|
180 | }
|
181 | };
|
182 |
|
183 | Object.keys(_this._addons).forEach(function (name) {
|
184 | var addon = _this._addons[name];
|
185 |
|
186 | api[name] = function () {
|
187 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
188 | args[_key] = arguments[_key];
|
189 | }
|
190 |
|
191 | addon.apply(api, args);
|
192 | return api;
|
193 | };
|
194 | });
|
195 |
|
196 | api.add = function (storyName, storyFn) {
|
197 | var parameters = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
198 | hasAdded = true;
|
199 | var id = parameters.__id || (0, _csf.toId)(kind, storyName);
|
200 |
|
201 | if (typeof storyName !== 'string') {
|
202 | throw new Error("Invalid or missing storyName provided for a \"".concat(kind, "\" story."));
|
203 | }
|
204 |
|
205 | if (typeof storyFn !== 'function') {
|
206 | throw new Error("Cannot load story \"".concat(storyName, "\" in \"").concat(kind, "\" due to invalid format. Storybook expected a function but received ").concat(_typeof(storyFn), " instead."));
|
207 | }
|
208 |
|
209 | if (!_this._noStoryModuleAddMethodHotDispose && m && m.hot && m.hot.dispose) {
|
210 | m.hot.dispose(function () {
|
211 | var _storyStore = _this._storyStore;
|
212 |
|
213 | _storyStore.remove(id, {
|
214 | allowUnsafe: true
|
215 | });
|
216 | });
|
217 | }
|
218 |
|
219 | var fileName = m && m.id ? "".concat(m.id) : undefined;
|
220 |
|
221 | var decorators = parameters.decorators,
|
222 | loaders = parameters.loaders,
|
223 | storyParameters = _objectWithoutProperties(parameters, ["decorators", "loaders"]);
|
224 |
|
225 | _this._storyStore.addStory({
|
226 | id: id,
|
227 | kind: kind,
|
228 | name: storyName,
|
229 | storyFn: storyFn,
|
230 | parameters: Object.assign({
|
231 | fileName: fileName
|
232 | }, storyParameters),
|
233 | decorators: decorators,
|
234 | loaders: loaders
|
235 | }, {
|
236 | applyDecorators: (0, _hooks.applyHooks)(_this._decorateStory)
|
237 | });
|
238 |
|
239 | return api;
|
240 | };
|
241 |
|
242 | api.addDecorator = function (decorator) {
|
243 | if (hasAdded) throw new Error("You cannot add a decorator after the first story for a kind.\nRead more here: https://github.com/storybookjs/storybook/blob/master/MIGRATION.md#can-no-longer-add-decoratorsparameters-after-stories");
|
244 |
|
245 | _this._storyStore.addKindMetadata(kind, {
|
246 | decorators: [decorator]
|
247 | });
|
248 |
|
249 | return api;
|
250 | };
|
251 |
|
252 | api.addLoader = function (loader) {
|
253 | if (hasAdded) throw new Error("You cannot add a loader after the first story for a kind.");
|
254 |
|
255 | _this._storyStore.addKindMetadata(kind, {
|
256 | loaders: [loader]
|
257 | });
|
258 |
|
259 | return api;
|
260 | };
|
261 |
|
262 | api.addParameters = function (parameters) {
|
263 | if (hasAdded) throw new Error("You cannot add parameters after the first story for a kind.\nRead more here: https://github.com/storybookjs/storybook/blob/master/MIGRATION.md#can-no-longer-add-decoratorsparameters-after-stories");
|
264 |
|
265 | _this._storyStore.addKindMetadata(kind, {
|
266 | parameters: parameters
|
267 | });
|
268 |
|
269 | return api;
|
270 | };
|
271 |
|
272 | return api;
|
273 | };
|
274 |
|
275 | this.getStorybook = function () {
|
276 | return _this._storyStore.getStorybook();
|
277 | };
|
278 |
|
279 | this.raw = function () {
|
280 | return _this._storyStore.raw();
|
281 | };
|
282 |
|
283 | this.store = function () {
|
284 | return _this._storyStore;
|
285 | };
|
286 |
|
287 | this._storyStore = storyStore;
|
288 | this._addons = {};
|
289 | this._noStoryModuleAddMethodHotDispose = noStoryModuleAddMethodHotDispose || false;
|
290 | this._decorateStory = decorateStory;
|
291 | if (!storyStore) throw new Error('storyStore is required');
|
292 | singleton = this;
|
293 | };
|
294 |
|
295 | exports.default = ClientApi; |
\ | No newline at end of file |