@storybook/addon-docs 7.0.0-alpha.1 → 7.0.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/blocks/Anchor.js +7 -10
- package/dist/cjs/blocks/ArgsTable.js +134 -205
- package/dist/cjs/blocks/Canvas.js +38 -73
- package/dist/cjs/blocks/Description.js +41 -68
- package/dist/cjs/blocks/DocsContainer.js +40 -68
- package/dist/cjs/blocks/DocsContext.js +1 -1
- package/dist/cjs/blocks/DocsPage.js +3 -5
- package/dist/cjs/blocks/DocsStory.js +18 -28
- package/dist/cjs/blocks/Heading.js +5 -9
- package/dist/cjs/blocks/Meta.js +11 -33
- package/dist/cjs/blocks/Preview.js +4 -10
- package/dist/cjs/blocks/Primary.js +11 -39
- package/dist/cjs/blocks/Props.js +4 -10
- package/dist/cjs/blocks/Source.js +62 -80
- package/dist/cjs/blocks/SourceContainer.js +19 -68
- package/dist/cjs/blocks/Stories.js +16 -47
- package/dist/cjs/blocks/Story.js +60 -180
- package/dist/cjs/blocks/Subheading.js +5 -9
- package/dist/cjs/blocks/Subtitle.js +15 -35
- package/dist/cjs/blocks/Title.js +12 -36
- package/dist/cjs/blocks/Wrapper.js +7 -8
- package/dist/cjs/blocks/enhanceSource.js +30 -67
- package/dist/cjs/blocks/index.js +28 -34
- package/dist/cjs/blocks/mdx.js +85 -96
- package/dist/cjs/blocks/types.js +2 -2
- package/dist/cjs/blocks/useStory.js +16 -101
- package/dist/cjs/blocks/utils.js +4 -25
- package/dist/cjs/index.js +1 -7
- package/dist/cjs/manager.js +9 -15
- package/dist/cjs/preset.js +120 -288
- package/dist/cjs/preview.js +5 -103
- package/dist/cjs/shared.js +5 -5
- package/dist/esm/blocks/Story.js +21 -73
- package/dist/types/blocks/Story.d.ts +2 -2
- package/package.json +15 -14
|
@@ -1,74 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
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.array.iterator.js");
|
|
12
|
-
|
|
13
|
-
require("core-js/modules/es.string.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
3
|
Object.defineProperty(exports, "__esModule", {
|
|
22
4
|
value: true
|
|
23
5
|
});
|
|
24
6
|
exports.enhanceSource = void 0;
|
|
25
7
|
|
|
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.regexp.exec.js");
|
|
33
|
-
|
|
34
|
-
require("core-js/modules/es.string.replace.js");
|
|
35
|
-
|
|
36
|
-
require("core-js/modules/es.string.split.js");
|
|
37
|
-
|
|
38
8
|
var _store = require("@storybook/store");
|
|
39
9
|
|
|
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" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) 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
10
|
/**
|
|
53
11
|
* given a location, extract the text from the full source
|
|
54
12
|
*/
|
|
55
13
|
function extractSource(location, lines) {
|
|
56
|
-
|
|
57
|
-
|
|
14
|
+
const {
|
|
15
|
+
startBody: start,
|
|
16
|
+
endBody: end
|
|
17
|
+
} = location;
|
|
58
18
|
|
|
59
19
|
if (start.line === end.line && lines[start.line - 1] !== undefined) {
|
|
60
20
|
return lines[start.line - 1].substring(start.col, end.col);
|
|
61
21
|
} // NOTE: storysource locations are 1-based not 0-based!
|
|
62
22
|
|
|
63
23
|
|
|
64
|
-
|
|
65
|
-
|
|
24
|
+
const startLine = lines[start.line - 1];
|
|
25
|
+
const endLine = lines[end.line - 1];
|
|
66
26
|
|
|
67
27
|
if (startLine === undefined || endLine === undefined) {
|
|
68
28
|
return null;
|
|
69
29
|
}
|
|
70
30
|
|
|
71
|
-
return [startLine.substring(start.col)
|
|
31
|
+
return [startLine.substring(start.col), ...lines.slice(start.line, end.line - 1), endLine.substring(0, end.col)].join('\n');
|
|
72
32
|
} // ============================================================
|
|
73
33
|
// END @storybook/source-loader/extract-source
|
|
74
34
|
// ============================================================
|
|
@@ -78,49 +38,52 @@ function extractSource(location, lines) {
|
|
|
78
38
|
* Replaces full story id name like: story-kind--story-name -> story-name
|
|
79
39
|
* @param id
|
|
80
40
|
*/
|
|
81
|
-
|
|
82
|
-
return id.replace(/^.*?--/, '');
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
var extract = function extract(targetId, _ref) {
|
|
86
|
-
var source = _ref.source,
|
|
87
|
-
locationsMap = _ref.locationsMap;
|
|
41
|
+
const storyIdToSanitizedStoryName = id => id.replace(/^.*?--/, '');
|
|
88
42
|
|
|
43
|
+
const extract = (targetId, {
|
|
44
|
+
source,
|
|
45
|
+
locationsMap
|
|
46
|
+
}) => {
|
|
89
47
|
if (!locationsMap) {
|
|
90
48
|
return source;
|
|
91
49
|
}
|
|
92
50
|
|
|
93
|
-
|
|
94
|
-
|
|
51
|
+
const sanitizedStoryName = storyIdToSanitizedStoryName(targetId);
|
|
52
|
+
const location = locationsMap[sanitizedStoryName];
|
|
95
53
|
|
|
96
54
|
if (!location) {
|
|
97
55
|
return source;
|
|
98
56
|
}
|
|
99
57
|
|
|
100
|
-
|
|
58
|
+
const lines = source.split('\n');
|
|
101
59
|
return extractSource(location, lines);
|
|
102
60
|
};
|
|
103
61
|
|
|
104
|
-
|
|
62
|
+
const enhanceSource = story => {
|
|
105
63
|
var _docs$source;
|
|
106
64
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
65
|
+
const {
|
|
66
|
+
id,
|
|
67
|
+
parameters
|
|
68
|
+
} = story;
|
|
69
|
+
const {
|
|
70
|
+
storySource,
|
|
71
|
+
docs = {}
|
|
72
|
+
} = parameters;
|
|
73
|
+
const {
|
|
74
|
+
transformSource
|
|
75
|
+
} = docs; // no input or user has manually overridden the output
|
|
113
76
|
|
|
114
77
|
if (!(storySource !== null && storySource !== void 0 && storySource.source) || (_docs$source = docs.source) !== null && _docs$source !== void 0 && _docs$source.code) {
|
|
115
78
|
return null;
|
|
116
79
|
}
|
|
117
80
|
|
|
118
|
-
|
|
119
|
-
|
|
81
|
+
const input = extract(id, storySource);
|
|
82
|
+
const code = transformSource ? transformSource(input, story) : input;
|
|
120
83
|
return {
|
|
121
84
|
docs: (0, _store.combineParameters)(docs, {
|
|
122
85
|
source: {
|
|
123
|
-
code
|
|
86
|
+
code
|
|
124
87
|
}
|
|
125
88
|
})
|
|
126
89
|
};
|
package/dist/cjs/blocks/index.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("core-js/modules/es.object.to-string.js");
|
|
4
|
-
|
|
5
|
-
require("core-js/modules/web.dom-collections.for-each.js");
|
|
6
|
-
|
|
7
|
-
require("core-js/modules/es.object.keys.js");
|
|
8
|
-
|
|
9
3
|
Object.defineProperty(exports, "__esModule", {
|
|
10
4
|
value: true
|
|
11
5
|
});
|
|
@@ -18,31 +12,31 @@ var _exportNames = {
|
|
|
18
12
|
};
|
|
19
13
|
Object.defineProperty(exports, "ColorItem", {
|
|
20
14
|
enumerable: true,
|
|
21
|
-
get: function
|
|
15
|
+
get: function () {
|
|
22
16
|
return _components.ColorItem;
|
|
23
17
|
}
|
|
24
18
|
});
|
|
25
19
|
Object.defineProperty(exports, "ColorPalette", {
|
|
26
20
|
enumerable: true,
|
|
27
|
-
get: function
|
|
21
|
+
get: function () {
|
|
28
22
|
return _components.ColorPalette;
|
|
29
23
|
}
|
|
30
24
|
});
|
|
31
25
|
Object.defineProperty(exports, "IconGallery", {
|
|
32
26
|
enumerable: true,
|
|
33
|
-
get: function
|
|
27
|
+
get: function () {
|
|
34
28
|
return _components.IconGallery;
|
|
35
29
|
}
|
|
36
30
|
});
|
|
37
31
|
Object.defineProperty(exports, "IconItem", {
|
|
38
32
|
enumerable: true,
|
|
39
|
-
get: function
|
|
33
|
+
get: function () {
|
|
40
34
|
return _components.IconItem;
|
|
41
35
|
}
|
|
42
36
|
});
|
|
43
37
|
Object.defineProperty(exports, "Typeset", {
|
|
44
38
|
enumerable: true,
|
|
45
|
-
get: function
|
|
39
|
+
get: function () {
|
|
46
40
|
return _components.Typeset;
|
|
47
41
|
}
|
|
48
42
|
});
|
|
@@ -57,7 +51,7 @@ Object.keys(_Anchor).forEach(function (key) {
|
|
|
57
51
|
if (key in exports && exports[key] === _Anchor[key]) return;
|
|
58
52
|
Object.defineProperty(exports, key, {
|
|
59
53
|
enumerable: true,
|
|
60
|
-
get: function
|
|
54
|
+
get: function () {
|
|
61
55
|
return _Anchor[key];
|
|
62
56
|
}
|
|
63
57
|
});
|
|
@@ -71,7 +65,7 @@ Object.keys(_ArgsTable).forEach(function (key) {
|
|
|
71
65
|
if (key in exports && exports[key] === _ArgsTable[key]) return;
|
|
72
66
|
Object.defineProperty(exports, key, {
|
|
73
67
|
enumerable: true,
|
|
74
|
-
get: function
|
|
68
|
+
get: function () {
|
|
75
69
|
return _ArgsTable[key];
|
|
76
70
|
}
|
|
77
71
|
});
|
|
@@ -85,7 +79,7 @@ Object.keys(_Canvas).forEach(function (key) {
|
|
|
85
79
|
if (key in exports && exports[key] === _Canvas[key]) return;
|
|
86
80
|
Object.defineProperty(exports, key, {
|
|
87
81
|
enumerable: true,
|
|
88
|
-
get: function
|
|
82
|
+
get: function () {
|
|
89
83
|
return _Canvas[key];
|
|
90
84
|
}
|
|
91
85
|
});
|
|
@@ -99,7 +93,7 @@ Object.keys(_Description).forEach(function (key) {
|
|
|
99
93
|
if (key in exports && exports[key] === _Description[key]) return;
|
|
100
94
|
Object.defineProperty(exports, key, {
|
|
101
95
|
enumerable: true,
|
|
102
|
-
get: function
|
|
96
|
+
get: function () {
|
|
103
97
|
return _Description[key];
|
|
104
98
|
}
|
|
105
99
|
});
|
|
@@ -113,7 +107,7 @@ Object.keys(_DocsContext).forEach(function (key) {
|
|
|
113
107
|
if (key in exports && exports[key] === _DocsContext[key]) return;
|
|
114
108
|
Object.defineProperty(exports, key, {
|
|
115
109
|
enumerable: true,
|
|
116
|
-
get: function
|
|
110
|
+
get: function () {
|
|
117
111
|
return _DocsContext[key];
|
|
118
112
|
}
|
|
119
113
|
});
|
|
@@ -127,7 +121,7 @@ Object.keys(_DocsPage).forEach(function (key) {
|
|
|
127
121
|
if (key in exports && exports[key] === _DocsPage[key]) return;
|
|
128
122
|
Object.defineProperty(exports, key, {
|
|
129
123
|
enumerable: true,
|
|
130
|
-
get: function
|
|
124
|
+
get: function () {
|
|
131
125
|
return _DocsPage[key];
|
|
132
126
|
}
|
|
133
127
|
});
|
|
@@ -141,7 +135,7 @@ Object.keys(_DocsContainer).forEach(function (key) {
|
|
|
141
135
|
if (key in exports && exports[key] === _DocsContainer[key]) return;
|
|
142
136
|
Object.defineProperty(exports, key, {
|
|
143
137
|
enumerable: true,
|
|
144
|
-
get: function
|
|
138
|
+
get: function () {
|
|
145
139
|
return _DocsContainer[key];
|
|
146
140
|
}
|
|
147
141
|
});
|
|
@@ -155,7 +149,7 @@ Object.keys(_DocsStory).forEach(function (key) {
|
|
|
155
149
|
if (key in exports && exports[key] === _DocsStory[key]) return;
|
|
156
150
|
Object.defineProperty(exports, key, {
|
|
157
151
|
enumerable: true,
|
|
158
|
-
get: function
|
|
152
|
+
get: function () {
|
|
159
153
|
return _DocsStory[key];
|
|
160
154
|
}
|
|
161
155
|
});
|
|
@@ -169,7 +163,7 @@ Object.keys(_Heading).forEach(function (key) {
|
|
|
169
163
|
if (key in exports && exports[key] === _Heading[key]) return;
|
|
170
164
|
Object.defineProperty(exports, key, {
|
|
171
165
|
enumerable: true,
|
|
172
|
-
get: function
|
|
166
|
+
get: function () {
|
|
173
167
|
return _Heading[key];
|
|
174
168
|
}
|
|
175
169
|
});
|
|
@@ -183,7 +177,7 @@ Object.keys(_Meta).forEach(function (key) {
|
|
|
183
177
|
if (key in exports && exports[key] === _Meta[key]) return;
|
|
184
178
|
Object.defineProperty(exports, key, {
|
|
185
179
|
enumerable: true,
|
|
186
|
-
get: function
|
|
180
|
+
get: function () {
|
|
187
181
|
return _Meta[key];
|
|
188
182
|
}
|
|
189
183
|
});
|
|
@@ -197,7 +191,7 @@ Object.keys(_Preview).forEach(function (key) {
|
|
|
197
191
|
if (key in exports && exports[key] === _Preview[key]) return;
|
|
198
192
|
Object.defineProperty(exports, key, {
|
|
199
193
|
enumerable: true,
|
|
200
|
-
get: function
|
|
194
|
+
get: function () {
|
|
201
195
|
return _Preview[key];
|
|
202
196
|
}
|
|
203
197
|
});
|
|
@@ -211,7 +205,7 @@ Object.keys(_Primary).forEach(function (key) {
|
|
|
211
205
|
if (key in exports && exports[key] === _Primary[key]) return;
|
|
212
206
|
Object.defineProperty(exports, key, {
|
|
213
207
|
enumerable: true,
|
|
214
|
-
get: function
|
|
208
|
+
get: function () {
|
|
215
209
|
return _Primary[key];
|
|
216
210
|
}
|
|
217
211
|
});
|
|
@@ -225,7 +219,7 @@ Object.keys(_Props).forEach(function (key) {
|
|
|
225
219
|
if (key in exports && exports[key] === _Props[key]) return;
|
|
226
220
|
Object.defineProperty(exports, key, {
|
|
227
221
|
enumerable: true,
|
|
228
|
-
get: function
|
|
222
|
+
get: function () {
|
|
229
223
|
return _Props[key];
|
|
230
224
|
}
|
|
231
225
|
});
|
|
@@ -239,7 +233,7 @@ Object.keys(_Source).forEach(function (key) {
|
|
|
239
233
|
if (key in exports && exports[key] === _Source[key]) return;
|
|
240
234
|
Object.defineProperty(exports, key, {
|
|
241
235
|
enumerable: true,
|
|
242
|
-
get: function
|
|
236
|
+
get: function () {
|
|
243
237
|
return _Source[key];
|
|
244
238
|
}
|
|
245
239
|
});
|
|
@@ -253,7 +247,7 @@ Object.keys(_SourceContainer).forEach(function (key) {
|
|
|
253
247
|
if (key in exports && exports[key] === _SourceContainer[key]) return;
|
|
254
248
|
Object.defineProperty(exports, key, {
|
|
255
249
|
enumerable: true,
|
|
256
|
-
get: function
|
|
250
|
+
get: function () {
|
|
257
251
|
return _SourceContainer[key];
|
|
258
252
|
}
|
|
259
253
|
});
|
|
@@ -267,7 +261,7 @@ Object.keys(_Stories).forEach(function (key) {
|
|
|
267
261
|
if (key in exports && exports[key] === _Stories[key]) return;
|
|
268
262
|
Object.defineProperty(exports, key, {
|
|
269
263
|
enumerable: true,
|
|
270
|
-
get: function
|
|
264
|
+
get: function () {
|
|
271
265
|
return _Stories[key];
|
|
272
266
|
}
|
|
273
267
|
});
|
|
@@ -281,7 +275,7 @@ Object.keys(_Story).forEach(function (key) {
|
|
|
281
275
|
if (key in exports && exports[key] === _Story[key]) return;
|
|
282
276
|
Object.defineProperty(exports, key, {
|
|
283
277
|
enumerable: true,
|
|
284
|
-
get: function
|
|
278
|
+
get: function () {
|
|
285
279
|
return _Story[key];
|
|
286
280
|
}
|
|
287
281
|
});
|
|
@@ -295,7 +289,7 @@ Object.keys(_Subheading).forEach(function (key) {
|
|
|
295
289
|
if (key in exports && exports[key] === _Subheading[key]) return;
|
|
296
290
|
Object.defineProperty(exports, key, {
|
|
297
291
|
enumerable: true,
|
|
298
|
-
get: function
|
|
292
|
+
get: function () {
|
|
299
293
|
return _Subheading[key];
|
|
300
294
|
}
|
|
301
295
|
});
|
|
@@ -309,7 +303,7 @@ Object.keys(_Subtitle).forEach(function (key) {
|
|
|
309
303
|
if (key in exports && exports[key] === _Subtitle[key]) return;
|
|
310
304
|
Object.defineProperty(exports, key, {
|
|
311
305
|
enumerable: true,
|
|
312
|
-
get: function
|
|
306
|
+
get: function () {
|
|
313
307
|
return _Subtitle[key];
|
|
314
308
|
}
|
|
315
309
|
});
|
|
@@ -323,7 +317,7 @@ Object.keys(_Title).forEach(function (key) {
|
|
|
323
317
|
if (key in exports && exports[key] === _Title[key]) return;
|
|
324
318
|
Object.defineProperty(exports, key, {
|
|
325
319
|
enumerable: true,
|
|
326
|
-
get: function
|
|
320
|
+
get: function () {
|
|
327
321
|
return _Title[key];
|
|
328
322
|
}
|
|
329
323
|
});
|
|
@@ -337,7 +331,7 @@ Object.keys(_Wrapper).forEach(function (key) {
|
|
|
337
331
|
if (key in exports && exports[key] === _Wrapper[key]) return;
|
|
338
332
|
Object.defineProperty(exports, key, {
|
|
339
333
|
enumerable: true,
|
|
340
|
-
get: function
|
|
334
|
+
get: function () {
|
|
341
335
|
return _Wrapper[key];
|
|
342
336
|
}
|
|
343
337
|
});
|
|
@@ -351,7 +345,7 @@ Object.keys(_types).forEach(function (key) {
|
|
|
351
345
|
if (key in exports && exports[key] === _types[key]) return;
|
|
352
346
|
Object.defineProperty(exports, key, {
|
|
353
347
|
enumerable: true,
|
|
354
|
-
get: function
|
|
348
|
+
get: function () {
|
|
355
349
|
return _types[key];
|
|
356
350
|
}
|
|
357
351
|
});
|
|
@@ -365,7 +359,7 @@ Object.keys(_mdx).forEach(function (key) {
|
|
|
365
359
|
if (key in exports && exports[key] === _mdx[key]) return;
|
|
366
360
|
Object.defineProperty(exports, key, {
|
|
367
361
|
enumerable: true,
|
|
368
|
-
get: function
|
|
362
|
+
get: function () {
|
|
369
363
|
return _mdx[key];
|
|
370
364
|
}
|
|
371
365
|
});
|
package/dist/cjs/blocks/mdx.js
CHANGED
|
@@ -1,26 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
require("core-js/modules/es.object.keys.js");
|
|
4
|
-
|
|
5
|
-
require("core-js/modules/es.symbol.js");
|
|
6
|
-
|
|
7
3
|
Object.defineProperty(exports, "__esModule", {
|
|
8
4
|
value: true
|
|
9
5
|
});
|
|
10
6
|
exports.assertIsFn = exports.HeadersMdx = exports.HeaderMdx = exports.CodeOrSourceMdx = exports.AnchorMdx = exports.AddContext = void 0;
|
|
11
7
|
|
|
12
|
-
require("core-js/modules/es.object.assign.js");
|
|
13
|
-
|
|
14
|
-
require("core-js/modules/es.regexp.exec.js");
|
|
15
|
-
|
|
16
|
-
require("core-js/modules/es.string.match.js");
|
|
17
|
-
|
|
18
|
-
require("core-js/modules/es.string.split.js");
|
|
19
|
-
|
|
20
|
-
require("core-js/modules/es.string.starts-with.js");
|
|
21
|
-
|
|
22
|
-
require("core-js/modules/es.object.to-string.js");
|
|
23
|
-
|
|
24
8
|
var _react = _interopRequireDefault(require("react"));
|
|
25
9
|
|
|
26
10
|
var _addons = require("@storybook/addons");
|
|
@@ -35,27 +19,25 @@ var _theming = require("@storybook/theming");
|
|
|
35
19
|
|
|
36
20
|
var _DocsContext = require("./DocsContext");
|
|
37
21
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
22
|
+
const _excluded = ["children"],
|
|
23
|
+
_excluded2 = ["className", "children"],
|
|
24
|
+
_excluded3 = ["href", "target", "children"],
|
|
25
|
+
_excluded4 = ["as", "id", "children"],
|
|
26
|
+
_excluded5 = ["as", "id", "children"];
|
|
43
27
|
|
|
44
28
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
45
29
|
|
|
46
|
-
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; }
|
|
47
|
-
|
|
48
30
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
49
31
|
|
|
50
|
-
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; }
|
|
51
|
-
|
|
52
32
|
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; }
|
|
53
33
|
|
|
54
|
-
|
|
34
|
+
const {
|
|
35
|
+
document
|
|
36
|
+
} = _global.default; // Hacky utility for asserting identifiers in MDX Story elements
|
|
55
37
|
|
|
56
|
-
|
|
38
|
+
const assertIsFn = val => {
|
|
57
39
|
if (typeof val !== 'function') {
|
|
58
|
-
throw new Error(
|
|
40
|
+
throw new Error(`Expected story function, got: ${val}`);
|
|
59
41
|
}
|
|
60
42
|
|
|
61
43
|
return val;
|
|
@@ -64,11 +46,13 @@ var assertIsFn = function assertIsFn(val) {
|
|
|
64
46
|
|
|
65
47
|
exports.assertIsFn = assertIsFn;
|
|
66
48
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
49
|
+
const AddContext = props => {
|
|
50
|
+
const {
|
|
51
|
+
children
|
|
52
|
+
} = props,
|
|
53
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded);
|
|
70
54
|
|
|
71
|
-
|
|
55
|
+
const parentContext = _react.default.useContext(_DocsContext.DocsContext);
|
|
72
56
|
|
|
73
57
|
return /*#__PURE__*/_react.default.createElement(_DocsContext.DocsContext.Provider, {
|
|
74
58
|
value: Object.assign({}, parentContext, rest)
|
|
@@ -77,10 +61,12 @@ var AddContext = function AddContext(props) {
|
|
|
77
61
|
|
|
78
62
|
exports.AddContext = AddContext;
|
|
79
63
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
64
|
+
const CodeOrSourceMdx = _ref => {
|
|
65
|
+
let {
|
|
66
|
+
className,
|
|
67
|
+
children
|
|
68
|
+
} = _ref,
|
|
69
|
+
rest = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
84
70
|
|
|
85
71
|
// markdown-to-jsx does not add className to inline code
|
|
86
72
|
if (typeof className !== 'string' && (typeof children !== 'string' || !children.match(/[\n\r]/g))) {
|
|
@@ -88,7 +74,7 @@ var CodeOrSourceMdx = function CodeOrSourceMdx(_ref) {
|
|
|
88
74
|
} // className: "lang-jsx"
|
|
89
75
|
|
|
90
76
|
|
|
91
|
-
|
|
77
|
+
const language = className && className.split('-');
|
|
92
78
|
return /*#__PURE__*/_react.default.createElement(_components.Source, _extends({
|
|
93
79
|
language: language && language[1] || 'plaintext',
|
|
94
80
|
format: false,
|
|
@@ -103,30 +89,31 @@ function navigate(url) {
|
|
|
103
89
|
} // @ts-ignore
|
|
104
90
|
|
|
105
91
|
|
|
106
|
-
|
|
92
|
+
const A = _components.components.a;
|
|
107
93
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
94
|
+
const AnchorInPage = ({
|
|
95
|
+
hash,
|
|
96
|
+
children
|
|
97
|
+
}) => /*#__PURE__*/_react.default.createElement(A, {
|
|
98
|
+
href: hash,
|
|
99
|
+
target: "_self",
|
|
100
|
+
onClick: event => {
|
|
101
|
+
const id = hash.substring(1);
|
|
102
|
+
const element = document.getElementById(id);
|
|
117
103
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
104
|
+
if (element) {
|
|
105
|
+
navigate(hash);
|
|
121
106
|
}
|
|
122
|
-
}
|
|
123
|
-
};
|
|
107
|
+
}
|
|
108
|
+
}, children);
|
|
124
109
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
110
|
+
const AnchorMdx = props => {
|
|
111
|
+
const {
|
|
112
|
+
href,
|
|
113
|
+
target,
|
|
114
|
+
children
|
|
115
|
+
} = props,
|
|
116
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded3);
|
|
130
117
|
|
|
131
118
|
if (href) {
|
|
132
119
|
// Enable scrolling for in-page anchors.
|
|
@@ -140,7 +127,7 @@ var AnchorMdx = function AnchorMdx(props) {
|
|
|
140
127
|
if (target !== '_blank' && !href.startsWith('https://')) {
|
|
141
128
|
return /*#__PURE__*/_react.default.createElement(A, _extends({
|
|
142
129
|
href: href,
|
|
143
|
-
onClick:
|
|
130
|
+
onClick: event => {
|
|
144
131
|
event.preventDefault(); // use the A element's href, which has been modified for
|
|
145
132
|
// local paths without a `?path=` query param prefix
|
|
146
133
|
|
|
@@ -156,37 +143,38 @@ var AnchorMdx = function AnchorMdx(props) {
|
|
|
156
143
|
};
|
|
157
144
|
|
|
158
145
|
exports.AnchorMdx = AnchorMdx;
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
146
|
+
const SUPPORTED_MDX_HEADERS = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'];
|
|
147
|
+
const OcticonHeaders = SUPPORTED_MDX_HEADERS.reduce((acc, headerType) => Object.assign({}, acc, {
|
|
148
|
+
// @ts-ignore
|
|
149
|
+
[headerType]: (0, _theming.styled)(_components.components[headerType])({
|
|
162
150
|
'& svg': {
|
|
163
151
|
visibility: 'hidden'
|
|
164
152
|
},
|
|
165
153
|
'&:hover svg': {
|
|
166
154
|
visibility: 'visible'
|
|
167
155
|
}
|
|
168
|
-
})
|
|
169
|
-
}, {});
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
rest =
|
|
156
|
+
})
|
|
157
|
+
}), {});
|
|
158
|
+
|
|
159
|
+
const OcticonAnchor = _theming.styled.a(() => ({
|
|
160
|
+
float: 'left',
|
|
161
|
+
paddingRight: '4px',
|
|
162
|
+
marginLeft: '-20px',
|
|
163
|
+
// Allow the theme's text color to override the default link color.
|
|
164
|
+
color: 'inherit'
|
|
165
|
+
}));
|
|
166
|
+
|
|
167
|
+
const HeaderWithOcticonAnchor = _ref2 => {
|
|
168
|
+
let {
|
|
169
|
+
as,
|
|
170
|
+
id,
|
|
171
|
+
children
|
|
172
|
+
} = _ref2,
|
|
173
|
+
rest = _objectWithoutPropertiesLoose(_ref2, _excluded4);
|
|
186
174
|
|
|
187
175
|
// @ts-ignore
|
|
188
|
-
|
|
189
|
-
|
|
176
|
+
const OcticonHeader = OcticonHeaders[as];
|
|
177
|
+
const hash = `#${id}`;
|
|
190
178
|
return /*#__PURE__*/_react.default.createElement(OcticonHeader, _extends({
|
|
191
179
|
id: id
|
|
192
180
|
}, rest), /*#__PURE__*/_react.default.createElement(OcticonAnchor, {
|
|
@@ -194,8 +182,8 @@ var HeaderWithOcticonAnchor = function HeaderWithOcticonAnchor(_ref3) {
|
|
|
194
182
|
href: hash,
|
|
195
183
|
tabIndex: -1,
|
|
196
184
|
target: "_self",
|
|
197
|
-
onClick:
|
|
198
|
-
|
|
185
|
+
onClick: event => {
|
|
186
|
+
const element = document.getElementById(id);
|
|
199
187
|
|
|
200
188
|
if (element) {
|
|
201
189
|
navigate(hash);
|
|
@@ -214,11 +202,13 @@ var HeaderWithOcticonAnchor = function HeaderWithOcticonAnchor(_ref3) {
|
|
|
214
202
|
}))), children);
|
|
215
203
|
};
|
|
216
204
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
205
|
+
const HeaderMdx = props => {
|
|
206
|
+
const {
|
|
207
|
+
as,
|
|
208
|
+
id,
|
|
209
|
+
children
|
|
210
|
+
} = props,
|
|
211
|
+
rest = _objectWithoutPropertiesLoose(props, _excluded5); // An id should have been added on every header by the "remark-slug" plugin.
|
|
222
212
|
|
|
223
213
|
|
|
224
214
|
if (id) {
|
|
@@ -229,17 +219,16 @@ var HeaderMdx = function HeaderMdx(props) {
|
|
|
229
219
|
} // @ts-ignore
|
|
230
220
|
|
|
231
221
|
|
|
232
|
-
|
|
222
|
+
const Header = _components.components[as]; // Make sure it still work if "remark-slug" plugin is not present.
|
|
233
223
|
|
|
234
224
|
return /*#__PURE__*/_react.default.createElement(Header, props);
|
|
235
225
|
};
|
|
236
226
|
|
|
237
227
|
exports.HeaderMdx = HeaderMdx;
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
}, {});
|
|
228
|
+
const HeadersMdx = SUPPORTED_MDX_HEADERS.reduce((acc, headerType) => Object.assign({}, acc, {
|
|
229
|
+
// @ts-ignore
|
|
230
|
+
[headerType]: props => /*#__PURE__*/_react.default.createElement(HeaderMdx, _extends({
|
|
231
|
+
as: headerType
|
|
232
|
+
}, props))
|
|
233
|
+
}), {});
|
|
245
234
|
exports.HeadersMdx = HeadersMdx;
|