1 | import "core-js/modules/es.object.keys.js";
|
2 | import "core-js/modules/es.symbol.js";
|
3 | import "core-js/modules/es.array.slice.js";
|
4 | import "core-js/modules/es.object.freeze.js";
|
5 | import "core-js/modules/es.symbol.description.js";
|
6 | import "core-js/modules/es.symbol.iterator.js";
|
7 | import "core-js/modules/es.array.iterator.js";
|
8 | import "core-js/modules/es.string.iterator.js";
|
9 | import "core-js/modules/web.dom-collections.iterator.js";
|
10 | import "core-js/modules/es.function.name.js";
|
11 | import "core-js/modules/es.array.from.js";
|
12 | import "core-js/modules/es.regexp.exec.js";
|
13 |
|
14 | var _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
15 |
|
16 | var _excluded = ["full", "panel", "nav", "shortcuts", "addonPanel", "tabs", "addons", "panelRight", "stories", "selectedKind", "selectedStory", "path"],
|
17 | _excluded2 = ["store", "navigate", "state", "provider", "fullAPI"];
|
18 |
|
19 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
20 |
|
21 | 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."); }
|
22 |
|
23 | function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
24 |
|
25 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
26 |
|
27 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
28 |
|
29 | 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."); }
|
30 |
|
31 | 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); }
|
32 |
|
33 | 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; }
|
34 |
|
35 | 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; }
|
36 |
|
37 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
38 |
|
39 | function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
40 |
|
41 | import "core-js/modules/es.array.includes.js";
|
42 | import "core-js/modules/es.array.map.js";
|
43 | import "core-js/modules/es.array.sort.js";
|
44 | import "core-js/modules/es.array.filter.js";
|
45 | import "core-js/modules/es.object.to-string.js";
|
46 | import "core-js/modules/es.object.entries.js";
|
47 | import "core-js/modules/es.array.concat.js";
|
48 | import "core-js/modules/es.array.join.js";
|
49 | import "core-js/modules/es.object.assign.js";
|
50 |
|
51 | 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; }
|
52 |
|
53 | 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; }
|
54 |
|
55 | import { once } from '@storybook/client-logger';
|
56 | import { NAVIGATE_URL, STORY_ARGS_UPDATED, SET_CURRENT_STORY, GLOBALS_UPDATED, UPDATE_QUERY_PARAMS } from '@storybook/core-events';
|
57 | import { queryFromLocation, buildArgsParam } from '@storybook/router';
|
58 | import { toId, sanitize } from '@storybook/csf';
|
59 | import deepEqual from 'fast-deep-equal';
|
60 | import global from 'global';
|
61 | import dedent from 'ts-dedent';
|
62 | import { isStory } from '../lib/stories';
|
63 | var globalWindow = global.window;
|
64 |
|
65 | var parseBoolean = function parseBoolean(value) {
|
66 | if (value === 'true' || value === '1') return true;
|
67 | if (value === 'false' || value === '0') return false;
|
68 | return undefined;
|
69 | };
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 | var prevParams;
|
81 |
|
82 | var initialUrlSupport = function initialUrlSupport(_ref) {
|
83 | var _ref$state = _ref.state,
|
84 | location = _ref$state.location,
|
85 | path = _ref$state.path,
|
86 | viewMode = _ref$state.viewMode,
|
87 | storyIdFromUrl = _ref$state.storyId,
|
88 | singleStory = _ref.singleStory;
|
89 |
|
90 | var _queryFromLocation = queryFromLocation(location),
|
91 | full = _queryFromLocation.full,
|
92 | panel = _queryFromLocation.panel,
|
93 | nav = _queryFromLocation.nav,
|
94 | shortcuts = _queryFromLocation.shortcuts,
|
95 | addonPanel = _queryFromLocation.addonPanel,
|
96 | tabs = _queryFromLocation.tabs,
|
97 | addons = _queryFromLocation.addons,
|
98 | panelRight = _queryFromLocation.panelRight,
|
99 | stories = _queryFromLocation.stories,
|
100 | selectedKind = _queryFromLocation.selectedKind,
|
101 | selectedStory = _queryFromLocation.selectedStory,
|
102 | queryPath = _queryFromLocation.path,
|
103 | otherParams = _objectWithoutProperties(_queryFromLocation, _excluded);
|
104 |
|
105 | var layout = {
|
106 | isFullscreen: parseBoolean(full),
|
107 | showNav: !singleStory && parseBoolean(nav),
|
108 | showPanel: parseBoolean(panel),
|
109 | panelPosition: ['right', 'bottom'].includes(panel) ? panel : undefined,
|
110 | showTabs: parseBoolean(tabs)
|
111 | };
|
112 | var ui = {
|
113 | enableShortcuts: parseBoolean(shortcuts)
|
114 | };
|
115 | var selectedPanel = addonPanel || undefined;
|
116 |
|
117 | if (addons === '0') {
|
118 | once.warn(dedent(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n The 'addons' query param is deprecated and will be removed in Storybook 7.0. Use 'panel=false' instead.\n\n More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-layout-url-params\n "]))));
|
119 | layout.showPanel = false;
|
120 | }
|
121 |
|
122 |
|
123 | if (panelRight === '1') {
|
124 | once.warn(dedent(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n The 'panelRight' query param is deprecated and will be removed in Storybook 7.0. Use 'panel=right' instead.\n\n More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-layout-url-params\n "]))));
|
125 | layout.panelPosition = 'right';
|
126 | }
|
127 |
|
128 |
|
129 | if (stories === '0') {
|
130 | once.warn(dedent(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n The 'stories' query param is deprecated and will be removed in Storybook 7.0. Use 'nav=false' instead.\n\n More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-layout-url-params\n "]))));
|
131 | layout.showNav = false;
|
132 | }
|
133 |
|
134 |
|
135 |
|
136 |
|
137 | var storyId = storyIdFromUrl;
|
138 |
|
139 | if (!storyId && selectedKind) {
|
140 | once.warn(dedent(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n The 'selectedKind' and 'selectedStory' query params are deprecated and will be removed in Storybook 7.0. Use 'path' instead.\n\n More info: https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-layout-url-params\n "]))));
|
141 | storyId = selectedStory ? toId(selectedKind, selectedStory) : sanitize(selectedKind);
|
142 | }
|
143 |
|
144 |
|
145 | var customQueryParams = deepEqual(prevParams, otherParams) ? prevParams : otherParams;
|
146 | prevParams = customQueryParams;
|
147 | return {
|
148 | viewMode: viewMode,
|
149 | layout: layout,
|
150 | ui: ui,
|
151 | selectedPanel: selectedPanel,
|
152 | location: location,
|
153 | path: path,
|
154 | customQueryParams: customQueryParams,
|
155 | storyId: storyId
|
156 | };
|
157 | };
|
158 |
|
159 | export var init = function init(_ref2) {
|
160 | var store = _ref2.store,
|
161 | navigate = _ref2.navigate,
|
162 | state = _ref2.state,
|
163 | provider = _ref2.provider,
|
164 | fullAPI = _ref2.fullAPI,
|
165 | rest = _objectWithoutProperties(_ref2, _excluded2);
|
166 |
|
167 | var navigateTo = function navigateTo(path) {
|
168 | var queryParams = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
169 | var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
170 | var params = Object.entries(queryParams).filter(function (_ref3) {
|
171 | var _ref4 = _slicedToArray(_ref3, 2),
|
172 | v = _ref4[1];
|
173 |
|
174 | return v;
|
175 | }).sort(function (_ref5, _ref6) {
|
176 | var _ref7 = _slicedToArray(_ref5, 1),
|
177 | a = _ref7[0];
|
178 |
|
179 | var _ref8 = _slicedToArray(_ref6, 1),
|
180 | b = _ref8[0];
|
181 |
|
182 | return a < b ? -1 : 1;
|
183 | }).map(function (_ref9) {
|
184 | var _ref10 = _slicedToArray(_ref9, 2),
|
185 | k = _ref10[0],
|
186 | v = _ref10[1];
|
187 |
|
188 | return "".concat(k, "=").concat(v);
|
189 | });
|
190 | var to = [path].concat(_toConsumableArray(params)).join('&');
|
191 | return navigate(to, options);
|
192 | };
|
193 |
|
194 | var api = {
|
195 | getQueryParam: function getQueryParam(key) {
|
196 | var _store$getState = store.getState(),
|
197 | customQueryParams = _store$getState.customQueryParams;
|
198 |
|
199 | return customQueryParams ? customQueryParams[key] : undefined;
|
200 | },
|
201 | getUrlState: function getUrlState() {
|
202 | var _store$getState2 = store.getState(),
|
203 | path = _store$getState2.path,
|
204 | customQueryParams = _store$getState2.customQueryParams,
|
205 | storyId = _store$getState2.storyId,
|
206 | url = _store$getState2.url,
|
207 | viewMode = _store$getState2.viewMode;
|
208 |
|
209 | return {
|
210 | path: path,
|
211 | queryParams: customQueryParams,
|
212 | storyId: storyId,
|
213 | url: url,
|
214 | viewMode: viewMode
|
215 | };
|
216 | },
|
217 | setQueryParams: function setQueryParams(input) {
|
218 | var _store$getState3 = store.getState(),
|
219 | customQueryParams = _store$getState3.customQueryParams;
|
220 |
|
221 | var queryParams = {};
|
222 | var update = Object.assign({}, customQueryParams, Object.entries(input).reduce(function (acc, _ref11) {
|
223 | var _ref12 = _slicedToArray(_ref11, 2),
|
224 | key = _ref12[0],
|
225 | value = _ref12[1];
|
226 |
|
227 | if (value !== null) {
|
228 | acc[key] = value;
|
229 | }
|
230 |
|
231 | return acc;
|
232 | }, queryParams));
|
233 |
|
234 | if (!deepEqual(customQueryParams, update)) {
|
235 | store.setState({
|
236 | customQueryParams: update
|
237 | });
|
238 | fullAPI.emit(UPDATE_QUERY_PARAMS, update);
|
239 | }
|
240 | },
|
241 | navigateUrl: function navigateUrl(url, options) {
|
242 | navigate(url, Object.assign({}, options, {
|
243 | plain: true
|
244 | }));
|
245 | }
|
246 | };
|
247 |
|
248 | var initModule = function initModule() {
|
249 |
|
250 | var updateArgsParam = function updateArgsParam() {
|
251 | var _fullAPI$getUrlState = fullAPI.getUrlState(),
|
252 | path = _fullAPI$getUrlState.path,
|
253 | queryParams = _fullAPI$getUrlState.queryParams,
|
254 | viewMode = _fullAPI$getUrlState.viewMode;
|
255 |
|
256 | if (viewMode !== 'story') return;
|
257 | var currentStory = fullAPI.getCurrentStoryData();
|
258 | if (!isStory(currentStory)) return;
|
259 | var args = currentStory.args,
|
260 | initialArgs = currentStory.initialArgs;
|
261 | var argsString = buildArgsParam(initialArgs, args);
|
262 | navigateTo(path, Object.assign({}, queryParams, {
|
263 | args: argsString
|
264 | }), {
|
265 | replace: true
|
266 | });
|
267 | api.setQueryParams({
|
268 | args: argsString
|
269 | });
|
270 | };
|
271 |
|
272 | fullAPI.on(SET_CURRENT_STORY, function () {
|
273 | return updateArgsParam();
|
274 | });
|
275 | var handleOrId;
|
276 | fullAPI.on(STORY_ARGS_UPDATED, function () {
|
277 | if ('requestIdleCallback' in globalWindow) {
|
278 | if (handleOrId) globalWindow.cancelIdleCallback(handleOrId);
|
279 | handleOrId = globalWindow.requestIdleCallback(updateArgsParam, {
|
280 | timeout: 1000
|
281 | });
|
282 | } else {
|
283 | if (handleOrId) clearTimeout(handleOrId);
|
284 | setTimeout(updateArgsParam, 100);
|
285 | }
|
286 | });
|
287 | fullAPI.on(GLOBALS_UPDATED, function (_ref13) {
|
288 | var globals = _ref13.globals,
|
289 | initialGlobals = _ref13.initialGlobals;
|
290 |
|
291 | var _fullAPI$getUrlState2 = fullAPI.getUrlState(),
|
292 | path = _fullAPI$getUrlState2.path,
|
293 | queryParams = _fullAPI$getUrlState2.queryParams;
|
294 |
|
295 | var globalsString = buildArgsParam(initialGlobals, globals);
|
296 | navigateTo(path, Object.assign({}, queryParams, {
|
297 | globals: globalsString
|
298 | }), {
|
299 | replace: true
|
300 | });
|
301 | api.setQueryParams({
|
302 | globals: globalsString
|
303 | });
|
304 | });
|
305 | fullAPI.on(NAVIGATE_URL, function (url, options) {
|
306 | fullAPI.navigateUrl(url, options);
|
307 | });
|
308 |
|
309 | if (fullAPI.showReleaseNotesOnLaunch()) {
|
310 | navigate('/settings/release-notes');
|
311 | }
|
312 | };
|
313 |
|
314 | return {
|
315 | api: api,
|
316 | state: initialUrlSupport(Object.assign({
|
317 | store: store,
|
318 | navigate: navigate,
|
319 | state: state,
|
320 | provider: provider,
|
321 | fullAPI: fullAPI
|
322 | }, rest)),
|
323 | init: initModule
|
324 | };
|
325 | }; |
\ | No newline at end of file |