1 | import "core-js/modules/es.symbol.js";
|
2 | import "core-js/modules/es.symbol.description.js";
|
3 | import "core-js/modules/es.symbol.iterator.js";
|
4 | import "core-js/modules/es.array.iterator.js";
|
5 | import "core-js/modules/es.string.iterator.js";
|
6 | import "core-js/modules/web.dom-collections.iterator.js";
|
7 | import "core-js/modules/es.array.slice.js";
|
8 | import "core-js/modules/es.array.from.js";
|
9 | import "core-js/modules/es.object.freeze.js";
|
10 | var _excluded = ["default", "__namedExportsOrder"];
|
11 |
|
12 | var _templateObject;
|
13 |
|
14 | 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; }
|
15 |
|
16 | 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; }
|
17 |
|
18 | function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
19 |
|
20 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
21 |
|
22 | 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."); }
|
23 |
|
24 | 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); }
|
25 |
|
26 | 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; }
|
27 |
|
28 | function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_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; }
|
29 |
|
30 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
31 |
|
32 | import "core-js/modules/es.object.keys.js";
|
33 | import "core-js/modules/es.object.entries.js";
|
34 | import "core-js/modules/es.array.map.js";
|
35 | import "core-js/modules/es.object.to-string.js";
|
36 | import "core-js/modules/web.dom-collections.for-each.js";
|
37 | import "core-js/modules/es.object.assign.js";
|
38 | import "core-js/modules/es.regexp.constructor.js";
|
39 | import "core-js/modules/es.regexp.exec.js";
|
40 | import "core-js/modules/es.regexp.to-string.js";
|
41 | import "core-js/modules/es.array.concat.js";
|
42 | import "core-js/modules/es.array.filter.js";
|
43 | import "core-js/modules/es.function.name.js";
|
44 |
|
45 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
46 |
|
47 | 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); } }
|
48 |
|
49 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
50 |
|
51 | import global from 'global';
|
52 | import dedent from 'ts-dedent';
|
53 | import { SynchronousPromise } from 'synchronous-promise';
|
54 | import { toId, isExportStory, storyNameFromExport } from '@storybook/csf';
|
55 | import { userOrAutoTitle, sortStoriesV6 } from '@storybook/store';
|
56 | import { logger } from '@storybook/client-logger';
|
57 | export var StoryStoreFacade = function () {
|
58 | function StoryStoreFacade() {
|
59 | _classCallCheck(this, StoryStoreFacade);
|
60 |
|
61 | this.projectAnnotations = void 0;
|
62 | this.stories = void 0;
|
63 | this.csfExports = void 0;
|
64 | this.projectAnnotations = {
|
65 | loaders: [],
|
66 | decorators: [],
|
67 | parameters: {},
|
68 | argsEnhancers: [],
|
69 | argTypesEnhancers: [],
|
70 | args: {},
|
71 | argTypes: {}
|
72 | };
|
73 | this.stories = {};
|
74 | this.csfExports = {};
|
75 | }
|
76 |
|
77 |
|
78 |
|
79 | _createClass(StoryStoreFacade, [{
|
80 | key: "importFn",
|
81 | value: function importFn(path) {
|
82 | var _this = this;
|
83 |
|
84 | return SynchronousPromise.resolve().then(function () {
|
85 | var moduleExports = _this.csfExports[path];
|
86 | if (!moduleExports) throw new Error("Unknown path: ".concat(path));
|
87 | return moduleExports;
|
88 | });
|
89 | }
|
90 | }, {
|
91 | key: "getStoryIndex",
|
92 | value: function getStoryIndex(store) {
|
93 | var _this$projectAnnotati,
|
94 | _this$projectAnnotati2,
|
95 | _this2 = this;
|
96 |
|
97 | var fileNameOrder = Object.keys(this.csfExports);
|
98 | var storySortParameter = (_this$projectAnnotati = this.projectAnnotations.parameters) === null || _this$projectAnnotati === void 0 ? void 0 : (_this$projectAnnotati2 = _this$projectAnnotati.options) === null || _this$projectAnnotati2 === void 0 ? void 0 : _this$projectAnnotati2.storySort;
|
99 | var storyEntries = Object.entries(this.stories);
|
100 |
|
101 | var sortableV6 = storyEntries.map(function (_ref) {
|
102 | var _ref2 = _slicedToArray(_ref, 2),
|
103 | storyId = _ref2[0],
|
104 | importPath = _ref2[1].importPath;
|
105 |
|
106 | var exports = _this2.csfExports[importPath];
|
107 | var csfFile = store.processCSFFileWithCache(exports, importPath, exports.default.title);
|
108 | return [storyId, store.storyFromCSFFile({
|
109 | storyId: storyId,
|
110 | csfFile: csfFile
|
111 | }), csfFile.meta.parameters, _this2.projectAnnotations.parameters];
|
112 | });
|
113 |
|
114 | var sortedV7;
|
115 |
|
116 | try {
|
117 | sortedV7 = sortStoriesV6(sortableV6, storySortParameter, fileNameOrder);
|
118 | } catch (err) {
|
119 | if (typeof storySortParameter === 'function') {
|
120 | throw new Error(dedent(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n Error sorting stories with sort parameter ", ":\n\n > ", "\n \n Are you using a V7-style sort function in V6 compatibility mode?\n \n More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#v7-style-story-sort\n "])), storySortParameter, err.message));
|
121 | }
|
122 |
|
123 | throw err;
|
124 | }
|
125 |
|
126 | var stories = sortedV7.reduce(function (acc, s) {
|
127 |
|
128 |
|
129 |
|
130 |
|
131 | acc[s.id] = _this2.stories[s.id];
|
132 | return acc;
|
133 | }, {});
|
134 | return {
|
135 | v: 3,
|
136 | stories: stories
|
137 | };
|
138 | }
|
139 | }, {
|
140 | key: "clearFilenameExports",
|
141 | value: function clearFilenameExports(fileName) {
|
142 | var _this3 = this;
|
143 |
|
144 | if (!this.csfExports[fileName]) {
|
145 | return;
|
146 | }
|
147 |
|
148 |
|
149 | Object.entries(this.stories).forEach(function (_ref3) {
|
150 | var _ref4 = _slicedToArray(_ref3, 2),
|
151 | id = _ref4[0],
|
152 | importPath = _ref4[1].importPath;
|
153 |
|
154 | if (importPath === fileName) {
|
155 | delete _this3.stories[id];
|
156 | }
|
157 | });
|
158 |
|
159 | this.csfExports[fileName] = {};
|
160 | }
|
161 |
|
162 | }, {
|
163 | key: "addStoriesFromExports",
|
164 | value: function addStoriesFromExports(fileName, fileExports) {
|
165 | var _this4 = this;
|
166 |
|
167 |
|
168 | if (this.csfExports[fileName] === fileExports) {
|
169 | return;
|
170 | }
|
171 |
|
172 |
|
173 | this.clearFilenameExports(fileName);
|
174 |
|
175 | var defaultExport = fileExports.default,
|
176 | __namedExportsOrder = fileExports.__namedExportsOrder,
|
177 | namedExports = _objectWithoutProperties(fileExports, _excluded);
|
178 |
|
179 |
|
180 | var _ref5 = defaultExport || {},
|
181 | componentId = _ref5.id,
|
182 | title = _ref5.title;
|
183 |
|
184 | var specifiers = (global.STORIES || []).map(function (specifier) {
|
185 | return Object.assign({}, specifier, {
|
186 | importPathMatcher: new RegExp(specifier.importPathMatcher)
|
187 | });
|
188 | });
|
189 | title = userOrAutoTitle(fileName, specifiers, title);
|
190 |
|
191 | if (!title) {
|
192 | logger.info("Unexpected default export without title in '".concat(fileName, "': ").concat(JSON.stringify(fileExports.default)));
|
193 | return;
|
194 | }
|
195 |
|
196 | this.csfExports[fileName] = Object.assign({}, fileExports, {
|
197 | default: Object.assign({}, defaultExport, {
|
198 | title: title
|
199 | })
|
200 | });
|
201 | var sortedExports = namedExports;
|
202 |
|
203 |
|
204 |
|
205 | if (Array.isArray(__namedExportsOrder)) {
|
206 | sortedExports = {};
|
207 |
|
208 | __namedExportsOrder.forEach(function (name) {
|
209 | var namedExport = namedExports[name];
|
210 | if (namedExport) sortedExports[name] = namedExport;
|
211 | });
|
212 | }
|
213 |
|
214 | Object.entries(sortedExports).filter(function (_ref6) {
|
215 | var _ref7 = _slicedToArray(_ref6, 1),
|
216 | key = _ref7[0];
|
217 |
|
218 | return isExportStory(key, defaultExport);
|
219 | }).forEach(function (_ref8) {
|
220 | var _storyExport$paramete, _storyExport$story;
|
221 |
|
222 | var _ref9 = _slicedToArray(_ref8, 2),
|
223 | key = _ref9[0],
|
224 | storyExport = _ref9[1];
|
225 |
|
226 | var exportName = storyNameFromExport(key);
|
227 | var id = ((_storyExport$paramete = storyExport.parameters) === null || _storyExport$paramete === void 0 ? void 0 : _storyExport$paramete.__id) || toId(componentId || title, exportName);
|
228 | var name = typeof storyExport !== 'function' && storyExport.name || storyExport.storyName || ((_storyExport$story = storyExport.story) === null || _storyExport$story === void 0 ? void 0 : _storyExport$story.name) || exportName;
|
229 | _this4.stories[id] = {
|
230 | id: id,
|
231 | name: name,
|
232 | title: title,
|
233 | importPath: fileName
|
234 | };
|
235 | });
|
236 | }
|
237 | }]);
|
238 |
|
239 | return StoryStoreFacade;
|
240 | }(); |
\ | No newline at end of file |