1 | import "core-js/modules/es.symbol.iterator.js";
|
2 | import "core-js/modules/es.string.iterator.js";
|
3 | import "core-js/modules/es.array.iterator.js";
|
4 | import "core-js/modules/web.dom-collections.iterator.js";
|
5 | import "core-js/modules/es.function.name.js";
|
6 | import "core-js/modules/es.array.from.js";
|
7 | import "core-js/modules/es.object.freeze.js";
|
8 |
|
9 | var _templateObject;
|
10 |
|
11 | function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
|
12 |
|
13 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
14 |
|
15 | 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); }
|
16 |
|
17 | import "core-js/modules/es.string.match.js";
|
18 | import "core-js/modules/es.regexp.exec.js";
|
19 | import "core-js/modules/es.object.assign.js";
|
20 | import "core-js/modules/es.symbol.js";
|
21 | import "core-js/modules/es.symbol.description.js";
|
22 | import "core-js/modules/es.object.to-string.js";
|
23 | import "core-js/modules/es.array.concat.js";
|
24 | import "core-js/modules/es.array.fill.js";
|
25 | import "core-js/modules/es.object.keys.js";
|
26 | import "core-js/modules/es.object.entries.js";
|
27 | import "core-js/modules/es.array.slice.js";
|
28 | import "core-js/modules/es.string.replace.js";
|
29 | import "core-js/modules/es.array.map.js";
|
30 | import "core-js/modules/es.array.join.js";
|
31 | import "core-js/modules/es.string.split.js";
|
32 | import "core-js/modules/es.string.search.js";
|
33 | import "core-js/modules/es.string.starts-with.js";
|
34 |
|
35 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
36 |
|
37 | 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."); }
|
38 |
|
39 | 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); }
|
40 |
|
41 | 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; }
|
42 |
|
43 | function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_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; }
|
44 |
|
45 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
46 |
|
47 | import { once } from '@storybook/client-logger';
|
48 | import deepEqual from 'fast-deep-equal';
|
49 | import isPlainObject from 'lodash/isPlainObject';
|
50 | import memoize from 'memoizerific';
|
51 | import qs from 'qs';
|
52 | import dedent from 'ts-dedent';
|
53 | var splitPathRegex = /\/([^/]+)\/(?:(.*)_)?([^/]+)?/;
|
54 | export var parsePath = memoize(1000)(function (path) {
|
55 | var result = {
|
56 | viewMode: undefined,
|
57 | storyId: undefined,
|
58 | refId: undefined
|
59 | };
|
60 |
|
61 | if (path) {
|
62 | var _ref = path.toLowerCase().match(splitPathRegex) || [],
|
63 | _ref2 = _slicedToArray(_ref, 4),
|
64 | viewMode = _ref2[1],
|
65 | refId = _ref2[2],
|
66 | storyId = _ref2[3];
|
67 |
|
68 | if (viewMode) {
|
69 | Object.assign(result, {
|
70 | viewMode: viewMode,
|
71 | storyId: storyId,
|
72 | refId: refId
|
73 | });
|
74 | }
|
75 | }
|
76 |
|
77 | return result;
|
78 | });
|
79 | export var DEEPLY_EQUAL = Symbol('Deeply equal');
|
80 | export var deepDiff = function deepDiff(value, update) {
|
81 | if (_typeof(value) !== _typeof(update)) return update;
|
82 | if (deepEqual(value, update)) return DEEPLY_EQUAL;
|
83 |
|
84 | if (Array.isArray(value) && Array.isArray(update)) {
|
85 | var res = update.reduce(function (acc, upd, index) {
|
86 | var diff = deepDiff(value[index], upd);
|
87 | if (diff !== DEEPLY_EQUAL) acc[index] = diff;
|
88 | return acc;
|
89 | }, new Array(update.length));
|
90 | if (update.length >= value.length) return res;
|
91 | return res.concat(new Array(value.length - update.length).fill(undefined));
|
92 | }
|
93 |
|
94 | if (isPlainObject(value) && isPlainObject(update)) {
|
95 | return Object.keys(Object.assign({}, value, update)).reduce(function (acc, key) {
|
96 | var diff = deepDiff(value === null || value === void 0 ? void 0 : value[key], update === null || update === void 0 ? void 0 : update[key]);
|
97 | return diff === DEEPLY_EQUAL ? acc : Object.assign(acc, _defineProperty({}, key, diff));
|
98 | }, {});
|
99 | }
|
100 |
|
101 | return update;
|
102 | };
|
103 |
|
104 | var VALIDATION_REGEXP = /^[a-zA-Z0-9 _-]*$/;
|
105 | var NUMBER_REGEXP = /^-?[0-9]+(\.[0-9]+)?$/;
|
106 | var HEX_REGEXP = /^#([a-f0-9]{3,4}|[a-f0-9]{6}|[a-f0-9]{8})$/i;
|
107 | var COLOR_REGEXP = /^(rgba?|hsla?)\(([0-9]{1,3}),\s?([0-9]{1,3})%?,\s?([0-9]{1,3})%?,?\s?([0-9](\.[0-9]{1,2})?)?\)$/i;
|
108 |
|
109 | var validateArgs = function validateArgs() {
|
110 | var key = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
111 | var value = arguments.length > 1 ? arguments[1] : undefined;
|
112 | if (key === null) return false;
|
113 | if (key === '' || !VALIDATION_REGEXP.test(key)) return false;
|
114 | if (value === null || value === undefined) return true;
|
115 |
|
116 | if (value instanceof Date) return true;
|
117 |
|
118 | if (typeof value === 'number' || typeof value === 'boolean') return true;
|
119 |
|
120 | if (typeof value === 'string') {
|
121 | return VALIDATION_REGEXP.test(value) || NUMBER_REGEXP.test(value) || HEX_REGEXP.test(value) || COLOR_REGEXP.test(value);
|
122 | }
|
123 |
|
124 | if (Array.isArray(value)) return value.every(function (v) {
|
125 | return validateArgs(key, v);
|
126 | });
|
127 | if (isPlainObject(value)) return Object.entries(value).every(function (_ref3) {
|
128 | var _ref4 = _slicedToArray(_ref3, 2),
|
129 | k = _ref4[0],
|
130 | v = _ref4[1];
|
131 |
|
132 | return validateArgs(k, v);
|
133 | });
|
134 | return false;
|
135 | };
|
136 |
|
137 | var encodeSpecialValues = function encodeSpecialValues(value) {
|
138 | if (value === undefined) return '!undefined';
|
139 | if (value === null) return '!null';
|
140 |
|
141 | if (typeof value === 'string') {
|
142 | if (HEX_REGEXP.test(value)) return "!hex(".concat(value.slice(1), ")");
|
143 | if (COLOR_REGEXP.test(value)) return "!".concat(value.replace(/[\s%]/g, ''));
|
144 | return value;
|
145 | }
|
146 |
|
147 | if (Array.isArray(value)) return value.map(encodeSpecialValues);
|
148 |
|
149 | if (isPlainObject(value)) {
|
150 | return Object.entries(value).reduce(function (acc, _ref5) {
|
151 | var _ref6 = _slicedToArray(_ref5, 2),
|
152 | key = _ref6[0],
|
153 | val = _ref6[1];
|
154 |
|
155 | return Object.assign(acc, _defineProperty({}, key, encodeSpecialValues(val)));
|
156 | }, {});
|
157 | }
|
158 |
|
159 | return value;
|
160 | };
|
161 |
|
162 | var QS_OPTIONS = {
|
163 | encode: false,
|
164 |
|
165 | delimiter: ';',
|
166 |
|
167 | allowDots: true,
|
168 |
|
169 | format: 'RFC1738',
|
170 |
|
171 | serializeDate: function serializeDate(date) {
|
172 | return "!date(".concat(date.toISOString(), ")");
|
173 | }
|
174 | };
|
175 | export var buildArgsParam = function buildArgsParam(initialArgs, args) {
|
176 | var update = deepDiff(initialArgs, args);
|
177 | if (!update || update === DEEPLY_EQUAL) return '';
|
178 | var object = Object.entries(update).reduce(function (acc, _ref7) {
|
179 | var _ref8 = _slicedToArray(_ref7, 2),
|
180 | key = _ref8[0],
|
181 | value = _ref8[1];
|
182 |
|
183 | if (validateArgs(key, value)) return Object.assign(acc, _defineProperty({}, key, value));
|
184 | once.warn(dedent(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n Omitted potentially unsafe URL args.\n\n More info: https://storybook.js.org/docs/react/writing-stories/args#setting-args-through-the-url\n "]))));
|
185 | return acc;
|
186 | }, {});
|
187 | return qs.stringify(encodeSpecialValues(object), QS_OPTIONS).replace(/ /g, '+').split(';').map(function (part) {
|
188 | return part.replace('=', ':');
|
189 | }).join(';');
|
190 | };
|
191 | export var queryFromString = memoize(1000)(function (s) {
|
192 | return qs.parse(s, {
|
193 | ignoreQueryPrefix: true
|
194 | });
|
195 | });
|
196 | export var queryFromLocation = function queryFromLocation(location) {
|
197 | return queryFromString(location.search);
|
198 | };
|
199 | export var stringifyQuery = function stringifyQuery(query) {
|
200 | return qs.stringify(query, {
|
201 | addQueryPrefix: true,
|
202 | encode: false
|
203 | });
|
204 | };
|
205 | export var getMatch = memoize(1000)(function (current, target) {
|
206 | var startsWith = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
|
207 | var startsWithTarget = current && startsWith && current.startsWith(target);
|
208 | var currentIsTarget = typeof target === 'string' && current === target;
|
209 | var matchTarget = current && target && current.match(target);
|
210 |
|
211 | if (startsWithTarget || currentIsTarget || matchTarget) {
|
212 | return {
|
213 | path: current
|
214 | };
|
215 | }
|
216 |
|
217 | return null;
|
218 | }); |
\ | No newline at end of file |