1 | function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
2 |
|
3 | 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."); }
|
4 |
|
5 | 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); }
|
6 |
|
7 | 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; }
|
8 |
|
9 | 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; }
|
10 |
|
11 | function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
12 |
|
13 | import "core-js/modules/es.array.concat.js";
|
14 | import "core-js/modules/es.function.name.js";
|
15 | import "core-js/modules/es.string.ends-with.js";
|
16 | import "core-js/modules/es.array.join.js";
|
17 | import "core-js/modules/es.array.filter.js";
|
18 | import "core-js/modules/es.object.to-string.js";
|
19 | import "core-js/modules/es.array.map.js";
|
20 | import "core-js/modules/es.object.entries.js";
|
21 | import "core-js/modules/es.array.find.js";
|
22 | import "core-js/modules/es.symbol.js";
|
23 | import "core-js/modules/es.symbol.description.js";
|
24 | import "core-js/modules/es.symbol.iterator.js";
|
25 | import "core-js/modules/es.array.iterator.js";
|
26 | import "core-js/modules/es.string.iterator.js";
|
27 | import "core-js/modules/web.dom-collections.iterator.js";
|
28 | import "core-js/modules/es.array.slice.js";
|
29 | import "core-js/modules/es.array.from.js";
|
30 | import "core-js/modules/es.regexp.exec.js";
|
31 | import { addons, useEffect } from '@storybook/addons';
|
32 | import { once } from '@storybook/client-logger';
|
33 | import { SourceType, SNIPPET_RENDERED } from '@storybook/docs-tools';
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | var skipSourceRender = function skipSourceRender(context) {
|
41 | var _context$parameters$d;
|
42 |
|
43 | var sourceParams = context === null || context === void 0 ? void 0 : (_context$parameters$d = context.parameters.docs) === null || _context$parameters$d === void 0 ? void 0 : _context$parameters$d.source;
|
44 | var isArgsStory = context === null || context === void 0 ? void 0 : context.parameters.__isArgsStory;
|
45 |
|
46 | if ((sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.type) === SourceType.DYNAMIC) {
|
47 | return false;
|
48 | }
|
49 |
|
50 |
|
51 |
|
52 | return !isArgsStory || (sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.code) || (sourceParams === null || sourceParams === void 0 ? void 0 : sourceParams.type) === SourceType.CODE;
|
53 | };
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 | function toSvelteProperty(key, value, argTypes) {
|
66 | if (value === undefined || value === null) {
|
67 | return null;
|
68 | }
|
69 |
|
70 |
|
71 | if (argTypes[key] && argTypes[key].defaultValue === value) {
|
72 | return null;
|
73 | }
|
74 |
|
75 | if (value === true) {
|
76 | return key;
|
77 | }
|
78 |
|
79 | if (typeof value === 'string') {
|
80 | return "".concat(key, "=").concat(JSON.stringify(value));
|
81 | }
|
82 |
|
83 | return "".concat(key, "={").concat(JSON.stringify(value), "}");
|
84 | }
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | function getComponentName(component) {
|
93 | if (component == null) {
|
94 | return null;
|
95 | }
|
96 |
|
97 | var _component$__docgen = component.__docgen,
|
98 | __docgen = _component$__docgen === void 0 ? {} : _component$__docgen;
|
99 |
|
100 | var name = __docgen.name;
|
101 |
|
102 | if (!name) {
|
103 | return component.name;
|
104 | }
|
105 |
|
106 | if (name.endsWith('.svelte')) {
|
107 | name = name.substring(0, name.length - 7);
|
108 | }
|
109 |
|
110 | return name;
|
111 | }
|
112 |
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 |
|
119 |
|
120 |
|
121 |
|
122 | export function generateSvelteSource(component, args, argTypes, slotProperty) {
|
123 | var name = getComponentName(component);
|
124 |
|
125 | if (!name) {
|
126 | return null;
|
127 | }
|
128 |
|
129 | var props = Object.entries(args).filter(function (_ref) {
|
130 | var _ref2 = _slicedToArray(_ref, 1),
|
131 | k = _ref2[0];
|
132 |
|
133 | return k !== slotProperty;
|
134 | }).map(function (_ref3) {
|
135 | var _ref4 = _slicedToArray(_ref3, 2),
|
136 | k = _ref4[0],
|
137 | v = _ref4[1];
|
138 |
|
139 | return toSvelteProperty(k, v, argTypes);
|
140 | }).filter(function (p) {
|
141 | return p;
|
142 | }).join(' ');
|
143 | var slotValue = slotProperty ? args[slotProperty] : null;
|
144 |
|
145 | if (slotValue) {
|
146 | return "<".concat(name, " ").concat(props, ">\n ").concat(slotValue, "\n</").concat(name, ">");
|
147 | }
|
148 |
|
149 | return "<".concat(name, " ").concat(props, "/>");
|
150 | }
|
151 |
|
152 |
|
153 |
|
154 |
|
155 |
|
156 |
|
157 |
|
158 |
|
159 |
|
160 |
|
161 |
|
162 |
|
163 |
|
164 | function getWrapperProperties(component) {
|
165 | var __docgen = component.__docgen;
|
166 |
|
167 | if (!__docgen) {
|
168 | return {
|
169 | wrapper: false
|
170 | };
|
171 | }
|
172 |
|
173 |
|
174 | if (!__docgen.keywords.find(function (kw) {
|
175 | return kw.name === 'wrapper';
|
176 | })) {
|
177 | return {
|
178 | wrapper: false
|
179 | };
|
180 | }
|
181 |
|
182 | var slotProp = __docgen.data.find(function (prop) {
|
183 | return prop.keywords.find(function (kw) {
|
184 | return kw.name === 'slot';
|
185 | });
|
186 | });
|
187 |
|
188 | return {
|
189 | wrapper: true,
|
190 | slotProperty: slotProp === null || slotProp === void 0 ? void 0 : slotProp.name
|
191 | };
|
192 | }
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | export var sourceDecorator = function sourceDecorator(storyFn, context) {
|
201 | var channel = addons.getChannel();
|
202 | var skip = skipSourceRender(context);
|
203 | var story = storyFn();
|
204 | var source;
|
205 | useEffect(function () {
|
206 | if (!skip && source) {
|
207 | channel.emit(SNIPPET_RENDERED, (context || {}).id, source);
|
208 | }
|
209 | });
|
210 |
|
211 | if (skip) {
|
212 | return story;
|
213 | }
|
214 |
|
215 | var _ref5 = context || {},
|
216 | _ref5$parameters = _ref5.parameters,
|
217 | parameters = _ref5$parameters === void 0 ? {} : _ref5$parameters,
|
218 | _ref5$args = _ref5.args,
|
219 | args = _ref5$args === void 0 ? {} : _ref5$args,
|
220 | ctxtComponent = _ref5.component;
|
221 |
|
222 | var _story$Component = story.Component,
|
223 | component = _story$Component === void 0 ? {} : _story$Component;
|
224 |
|
225 | var _getWrapperProperties = getWrapperProperties(component),
|
226 | wrapper = _getWrapperProperties.wrapper,
|
227 | slotProperty = _getWrapperProperties.slotProperty;
|
228 |
|
229 | if (wrapper) {
|
230 | if (parameters.component) {
|
231 | once.warn('parameters.component is deprecated. Using context.component instead.');
|
232 | }
|
233 |
|
234 | component = ctxtComponent;
|
235 | }
|
236 |
|
237 | source = generateSvelteSource(component, args, context === null || context === void 0 ? void 0 : context.argTypes, slotProperty);
|
238 | return story;
|
239 | }; |
\ | No newline at end of file |