1 | import "core-js/modules/es.array.slice.js";
|
2 | import "core-js/modules/es.object.freeze.js";
|
3 | import "core-js/modules/es.symbol.js";
|
4 | import "core-js/modules/es.symbol.description.js";
|
5 | import "core-js/modules/es.symbol.iterator.js";
|
6 | import "core-js/modules/es.array.iterator.js";
|
7 | import "core-js/modules/es.string.iterator.js";
|
8 | import "core-js/modules/web.dom-collections.iterator.js";
|
9 | import "core-js/modules/es.array.from.js";
|
10 |
|
11 | var _templateObject, _templateObject2, _templateObject3;
|
12 |
|
13 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
14 |
|
15 | function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
16 |
|
17 | function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
18 |
|
19 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
20 |
|
21 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
22 |
|
23 | 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."); }
|
24 |
|
25 | 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); }
|
26 |
|
27 | 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; }
|
28 |
|
29 | 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; }
|
30 |
|
31 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
32 |
|
33 | import "core-js/modules/es.object.assign.js";
|
34 | import "core-js/modules/es.object.values.js";
|
35 | import "core-js/modules/es.object.to-string.js";
|
36 | import "core-js/modules/es.object.entries.js";
|
37 | import "core-js/modules/es.function.name.js";
|
38 | import "core-js/modules/es.array.filter.js";
|
39 | import "core-js/modules/es.regexp.exec.js";
|
40 | import "core-js/modules/es.string.match.js";
|
41 | import "core-js/modules/es.string.split.js";
|
42 | import "core-js/modules/es.string.trim.js";
|
43 | import "core-js/modules/es.array.concat.js";
|
44 | import "core-js/modules/es.array.includes.js";
|
45 | import "core-js/modules/es.string.includes.js";
|
46 | import "core-js/modules/es.array.map.js";
|
47 | import "core-js/modules/web.dom-collections.for-each.js";
|
48 | import "core-js/modules/es.object.keys.js";
|
49 |
|
50 | function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
51 |
|
52 | import memoize from 'memoizerific';
|
53 | import deprecate from 'util-deprecate';
|
54 | import dedent from 'ts-dedent';
|
55 | import mapValues from 'lodash/mapValues';
|
56 | import countBy from 'lodash/countBy';
|
57 | import global from 'global';
|
58 | import { sanitize } from '@storybook/csf';
|
59 | import { combineParameters } from '../index';
|
60 | import merge from './merge';
|
61 | var FEATURES = global.FEATURES;
|
62 | var warnLegacyShowRoots = deprecate(function () {}, dedent(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n The 'showRoots' config option is deprecated and will be removed in Storybook 7.0. Use 'sidebar.showRoots' instead.\n Read more about it in the migration guide: https://github.com/storybookjs/storybook/blob/master/MIGRATION.md\n "]))));
|
63 | var warnChangedDefaultHierarchySeparators = deprecate(function () {}, dedent(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n The default hierarchy separators changed in Storybook 6.0.\n '|' and '.' will no longer create a hierarchy, but codemods are available.\n Read more about it in the migration guide: https://github.com/storybookjs/storybook/blob/master/MIGRATION.md\n "]))));
|
64 | export var denormalizeStoryParameters = function denormalizeStoryParameters(_ref) {
|
65 | var globalParameters = _ref.globalParameters,
|
66 | kindParameters = _ref.kindParameters,
|
67 | stories = _ref.stories;
|
68 | return mapValues(stories, function (storyData) {
|
69 | return Object.assign({}, storyData, {
|
70 | parameters: combineParameters(globalParameters, kindParameters[storyData.kind], storyData.parameters)
|
71 | });
|
72 | });
|
73 | };
|
74 | var STORY_KIND_PATH_SEPARATOR = /\s*\/\s*/;
|
75 | export var transformStoryIndexToStoriesHash = function transformStoryIndexToStoriesHash(index, _ref2) {
|
76 | var provider = _ref2.provider;
|
77 | var countByTitle = countBy(Object.values(index.stories), 'title');
|
78 | var input = Object.entries(index.stories).reduce(function (acc, _ref3) {
|
79 | var _ref4 = _slicedToArray(_ref3, 2),
|
80 | id = _ref4[0],
|
81 | _ref4$ = _ref4[1],
|
82 | title = _ref4$.title,
|
83 | name = _ref4$.name,
|
84 | importPath = _ref4$.importPath,
|
85 | parameters = _ref4$.parameters;
|
86 |
|
87 | var docsOnly = name === 'Page' && countByTitle[title] === 1;
|
88 | acc[id] = {
|
89 | id: id,
|
90 | kind: title,
|
91 | name: name,
|
92 | parameters: Object.assign({
|
93 | fileName: importPath,
|
94 | options: {},
|
95 | docsOnly: docsOnly
|
96 | }, parameters)
|
97 | };
|
98 | return acc;
|
99 | }, {});
|
100 | return transformStoriesRawToStoriesHash(input, {
|
101 | provider: provider,
|
102 | prepared: false
|
103 | });
|
104 | };
|
105 | export var transformStoriesRawToStoriesHash = function transformStoriesRawToStoriesHash(input, _ref5) {
|
106 | var provider = _ref5.provider,
|
107 | _ref5$prepared = _ref5.prepared,
|
108 | prepared = _ref5$prepared === void 0 ? true : _ref5$prepared;
|
109 | var values = Object.values(input).filter(Boolean);
|
110 | var usesOldHierarchySeparator = values.some(function (_ref6) {
|
111 | var kind = _ref6.kind;
|
112 | return kind.match(/\.|\|/);
|
113 | });
|
114 |
|
115 | var storiesHashOutOfOrder = values.reduce(function (acc, item) {
|
116 | var _item$parameters;
|
117 |
|
118 | var kind = item.kind,
|
119 | parameters = item.parameters;
|
120 |
|
121 | var _provider$getConfig = provider.getConfig(),
|
122 | _provider$getConfig$s = _provider$getConfig.sidebar,
|
123 | sidebar = _provider$getConfig$s === void 0 ? {} : _provider$getConfig$s,
|
124 | deprecatedShowRoots = _provider$getConfig.showRoots;
|
125 |
|
126 | var _sidebar$showRoots = sidebar.showRoots,
|
127 | showRoots = _sidebar$showRoots === void 0 ? deprecatedShowRoots : _sidebar$showRoots,
|
128 | _sidebar$collapsedRoo = sidebar.collapsedRoots,
|
129 | collapsedRoots = _sidebar$collapsedRoo === void 0 ? [] : _sidebar$collapsedRoo,
|
130 | renderLabel = sidebar.renderLabel;
|
131 |
|
132 | if (typeof deprecatedShowRoots !== 'undefined') {
|
133 | warnLegacyShowRoots();
|
134 | }
|
135 |
|
136 | var setShowRoots = typeof showRoots !== 'undefined';
|
137 |
|
138 | if (usesOldHierarchySeparator && !setShowRoots && FEATURES !== null && FEATURES !== void 0 && FEATURES.warnOnLegacyHierarchySeparator) {
|
139 | warnChangedDefaultHierarchySeparators();
|
140 | }
|
141 |
|
142 | var groups = kind.trim().split(STORY_KIND_PATH_SEPARATOR);
|
143 | var root = (!setShowRoots || showRoots) && groups.length > 1 ? [groups.shift()] : [];
|
144 | var rootAndGroups = [].concat(root, _toConsumableArray(groups)).reduce(function (list, name, index) {
|
145 | var parent = index > 0 && list[index - 1].id;
|
146 | var id = sanitize(parent ? "".concat(parent, "-").concat(name) : name);
|
147 |
|
148 | if (parent === id) {
|
149 | throw new Error(dedent(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n Invalid part '", "', leading to id === parentId ('", "'), inside kind '", "'\n\n Did you create a path that uses the separator char accidentally, such as 'Vue <docs/>' where '/' is a separator char? See https://github.com/storybookjs/storybook/issues/6128\n "])), name, id, kind));
|
150 | }
|
151 |
|
152 | if (root.length && index === 0) {
|
153 | list.push({
|
154 | type: 'root',
|
155 | id: id,
|
156 | name: name,
|
157 | depth: index,
|
158 | children: [],
|
159 | isComponent: false,
|
160 | isLeaf: false,
|
161 | isRoot: true,
|
162 | renderLabel: renderLabel,
|
163 | startCollapsed: collapsedRoots.includes(id)
|
164 | });
|
165 | } else {
|
166 | list.push({
|
167 | type: 'group',
|
168 | id: id,
|
169 | name: name,
|
170 | parent: parent,
|
171 | depth: index,
|
172 | children: [],
|
173 | isComponent: false,
|
174 | isLeaf: false,
|
175 | isRoot: false,
|
176 | renderLabel: renderLabel,
|
177 | parameters: {
|
178 | docsOnly: parameters === null || parameters === void 0 ? void 0 : parameters.docsOnly,
|
179 | viewMode: parameters === null || parameters === void 0 ? void 0 : parameters.viewMode
|
180 | }
|
181 | });
|
182 | }
|
183 |
|
184 | return list;
|
185 | }, []);
|
186 | var paths = [].concat(_toConsumableArray(rootAndGroups.map(function (_ref7) {
|
187 | var id = _ref7.id;
|
188 | return id;
|
189 | })), [item.id]);
|
190 |
|
191 | rootAndGroups.forEach(function (group, index) {
|
192 | var child = paths[index + 1];
|
193 | var id = group.id;
|
194 | acc[id] = merge(acc[id] || {}, Object.assign({}, group, child && {
|
195 | children: [child]
|
196 | }));
|
197 | });
|
198 | acc[item.id] = Object.assign({
|
199 | type: (_item$parameters = item.parameters) !== null && _item$parameters !== void 0 && _item$parameters.docsOnly ? 'docs' : 'story'
|
200 | }, item, {
|
201 | depth: rootAndGroups.length,
|
202 | parent: rootAndGroups[rootAndGroups.length - 1].id,
|
203 | isLeaf: true,
|
204 | isComponent: false,
|
205 | isRoot: false,
|
206 | renderLabel: renderLabel,
|
207 | prepared: prepared
|
208 | });
|
209 | return acc;
|
210 | }, {});
|
211 |
|
212 | function addItem(acc, item) {
|
213 | if (!acc[item.id]) {
|
214 |
|
215 | acc[item.id] = item;
|
216 | var children = item.children;
|
217 |
|
218 | if (children) {
|
219 | var childNodes = children.map(function (id) {
|
220 | return storiesHashOutOfOrder[id];
|
221 | });
|
222 |
|
223 | if (childNodes.every(function (childNode) {
|
224 | return childNode.isLeaf;
|
225 | })) {
|
226 | acc[item.id].isComponent = true;
|
227 | acc[item.id].type = 'component';
|
228 | }
|
229 |
|
230 | childNodes.forEach(function (childNode) {
|
231 | return addItem(acc, childNode);
|
232 | });
|
233 | }
|
234 | }
|
235 |
|
236 | return acc;
|
237 | }
|
238 |
|
239 | return Object.values(storiesHashOutOfOrder).reduce(addItem, {});
|
240 | };
|
241 | export function isRoot(item) {
|
242 | if (item) {
|
243 | return item.isRoot;
|
244 | }
|
245 |
|
246 | return false;
|
247 | }
|
248 | export function isGroup(item) {
|
249 | if (item) {
|
250 | return !item.isRoot && !item.isLeaf;
|
251 | }
|
252 |
|
253 | return false;
|
254 | }
|
255 | export function isStory(item) {
|
256 | if (item) {
|
257 | return item.isLeaf;
|
258 | }
|
259 |
|
260 | return false;
|
261 | }
|
262 | export var getComponentLookupList = memoize(1)(function (hash) {
|
263 | return Object.entries(hash).reduce(function (acc, i) {
|
264 | var value = i[1];
|
265 |
|
266 | if (value.isComponent) {
|
267 | acc.push(_toConsumableArray(i[1].children));
|
268 | }
|
269 |
|
270 | return acc;
|
271 | }, []);
|
272 | });
|
273 | export var getStoriesLookupList = memoize(1)(function (hash) {
|
274 | return Object.keys(hash).filter(function (k) {
|
275 | return !(hash[k].children || Array.isArray(hash[k]));
|
276 | });
|
277 | }); |
\ | No newline at end of file |