1 | "use strict";
|
2 |
|
3 | require("core-js/modules/es.symbol.js");
|
4 |
|
5 | require("core-js/modules/es.symbol.description.js");
|
6 |
|
7 | require("core-js/modules/es.object.to-string.js");
|
8 |
|
9 | require("core-js/modules/es.symbol.iterator.js");
|
10 |
|
11 | require("core-js/modules/es.string.iterator.js");
|
12 |
|
13 | require("core-js/modules/es.array.iterator.js");
|
14 |
|
15 | require("core-js/modules/web.dom-collections.iterator.js");
|
16 |
|
17 | require("core-js/modules/es.array.from.js");
|
18 |
|
19 | require("core-js/modules/es.function.name.js");
|
20 |
|
21 | Object.defineProperty(exports, "__esModule", {
|
22 | value: true
|
23 | });
|
24 | exports.enhanceSource = void 0;
|
25 |
|
26 | require("core-js/modules/es.array.join.js");
|
27 |
|
28 | require("core-js/modules/es.array.concat.js");
|
29 |
|
30 | require("core-js/modules/es.array.slice.js");
|
31 |
|
32 | require("core-js/modules/es.string.replace.js");
|
33 |
|
34 | require("core-js/modules/es.regexp.exec.js");
|
35 |
|
36 | require("core-js/modules/es.string.split.js");
|
37 |
|
38 | var _store = require("@storybook/store");
|
39 |
|
40 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
41 |
|
42 | 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."); }
|
43 |
|
44 | 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); }
|
45 |
|
46 | function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
|
47 |
|
48 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
49 |
|
50 | 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; }
|
51 |
|
52 |
|
53 |
|
54 |
|
55 | function extractSource(location, lines) {
|
56 | var start = location.startBody,
|
57 | end = location.endBody;
|
58 |
|
59 | if (start.line === end.line && lines[start.line - 1] !== undefined) {
|
60 | return lines[start.line - 1].substring(start.col, end.col);
|
61 | }
|
62 |
|
63 |
|
64 | var startLine = lines[start.line - 1];
|
65 | var endLine = lines[end.line - 1];
|
66 |
|
67 | if (startLine === undefined || endLine === undefined) {
|
68 | return null;
|
69 | }
|
70 |
|
71 | return [startLine.substring(start.col)].concat(_toConsumableArray(lines.slice(start.line, end.line - 1)), [endLine.substring(0, end.col)]).join('\n');
|
72 | }
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | var storyIdToSanitizedStoryName = function storyIdToSanitizedStoryName(id) {
|
82 | return id.replace(/^.*?--/, '');
|
83 | };
|
84 |
|
85 | var extract = function extract(targetId, _ref) {
|
86 | var source = _ref.source,
|
87 | locationsMap = _ref.locationsMap;
|
88 |
|
89 | if (!locationsMap) {
|
90 | return source;
|
91 | }
|
92 |
|
93 | var sanitizedStoryName = storyIdToSanitizedStoryName(targetId);
|
94 | var location = locationsMap[sanitizedStoryName];
|
95 |
|
96 | if (!location) {
|
97 | return source;
|
98 | }
|
99 |
|
100 | var lines = source.split('\n');
|
101 | return extractSource(location, lines);
|
102 | };
|
103 |
|
104 | var enhanceSource = function enhanceSource(story) {
|
105 | var _docs$source;
|
106 |
|
107 | var id = story.id,
|
108 | parameters = story.parameters;
|
109 | var storySource = parameters.storySource,
|
110 | _parameters$docs = parameters.docs,
|
111 | docs = _parameters$docs === void 0 ? {} : _parameters$docs;
|
112 | var transformSource = docs.transformSource;
|
113 |
|
114 | if (!(storySource !== null && storySource !== void 0 && storySource.source) || (_docs$source = docs.source) !== null && _docs$source !== void 0 && _docs$source.code) {
|
115 | return null;
|
116 | }
|
117 |
|
118 | var input = extract(id, storySource);
|
119 | var code = transformSource ? transformSource(input, story) : input;
|
120 | return {
|
121 | docs: (0, _store.combineParameters)(docs, {
|
122 | source: {
|
123 | code: code
|
124 | }
|
125 | })
|
126 | };
|
127 | };
|
128 |
|
129 | exports.enhanceSource = enhanceSource; |
\ | No newline at end of file |