@storybook/addon-docs 6.5.0-alpha.50 → 6.5.0-alpha.53
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/Source.js +15 -2
- package/dist/cjs/blocks/SourceContainer.js +19 -11
- package/dist/cjs/{register.js → manager.js} +0 -0
- package/dist/cjs/{frameworks/common/preset.js → preset.js} +6 -22
- package/dist/cjs/{frameworks/common/config.js → preview.js} +3 -5
- package/dist/esm/blocks/Source.js +15 -2
- package/dist/esm/blocks/SourceContainer.js +19 -11
- package/dist/esm/{register.js → manager.js} +0 -0
- package/dist/esm/{frameworks/common/preset.js → preset.js} +4 -19
- package/dist/esm/{frameworks/common/config.js → preview.js} +3 -5
- package/dist/modern/blocks/Source.js +17 -2
- package/dist/modern/blocks/SourceContainer.js +18 -12
- package/dist/modern/{register.js → manager.js} +0 -0
- package/dist/modern/{frameworks/common/preset.js → preset.js} +1 -8
- package/dist/modern/preview.js +6 -0
- package/dist/ts3.4/blocks/Source.d.ts +5 -3
- package/dist/ts3.4/blocks/SourceContainer.d.ts +5 -1
- package/dist/ts3.4/{register.d.ts → manager.d.ts} +0 -0
- package/dist/ts3.4/{frameworks/common/preset.d.ts → preset.d.ts} +0 -0
- package/dist/{ts3.9/frameworks/common/config.d.ts → ts3.4/preview.d.ts} +6 -8
- package/dist/ts3.9/blocks/Source.d.ts +5 -3
- package/dist/ts3.9/blocks/SourceContainer.d.ts +6 -2
- package/dist/ts3.9/{register.d.ts → manager.d.ts} +0 -0
- package/dist/ts3.9/{frameworks/common/preset.d.ts → preset.d.ts} +0 -0
- package/dist/{ts3.4/frameworks/common/config.d.ts → ts3.9/preview.d.ts} +6 -8
- package/manager.js +1 -0
- package/package.json +18 -28
- package/preset.js +1 -16
- package/preview.js +1 -0
- package/register.js +6 -2
- package/dist/modern/frameworks/common/config.js +0 -8
|
@@ -75,7 +75,10 @@ var getStorySource = function getStorySource(storyId, sourceContext) {
|
|
|
75
75
|
var sources = sourceContext.sources; // source rendering is async so source is unavailable at the start of the render cycle,
|
|
76
76
|
// so we fail gracefully here without warning
|
|
77
77
|
|
|
78
|
-
return (sources === null || sources === void 0 ? void 0 : sources[storyId]) ||
|
|
78
|
+
return (sources === null || sources === void 0 ? void 0 : sources[storyId]) || {
|
|
79
|
+
code: '',
|
|
80
|
+
format: false
|
|
81
|
+
};
|
|
79
82
|
};
|
|
80
83
|
|
|
81
84
|
var getSnippet = function getSnippet(snippet, story) {
|
|
@@ -127,6 +130,8 @@ var getSourceProps = function getSourceProps(props, docsContext, sourceContext)
|
|
|
127
130
|
var multiProps = props;
|
|
128
131
|
var source = codeProps.code; // prefer user-specified code
|
|
129
132
|
|
|
133
|
+
var format = codeProps.format; // prefer user-specified code
|
|
134
|
+
|
|
130
135
|
var targetIds = multiProps.ids || [singleProps.id || currentId];
|
|
131
136
|
var storyIds = targetIds.map(function (targetId) {
|
|
132
137
|
return targetId === _types.CURRENT_SELECTION ? currentId : targetId;
|
|
@@ -141,8 +146,15 @@ var getSourceProps = function getSourceProps(props, docsContext, sourceContext)
|
|
|
141
146
|
}
|
|
142
147
|
|
|
143
148
|
if (!source) {
|
|
149
|
+
// just take the format from the first story, given how they're all concatinated together...
|
|
150
|
+
// TODO: we should consider sending an event with all the sources separately, instead of concatenating them here
|
|
151
|
+
var _getStorySource = getStorySource(storyIds[0], sourceContext);
|
|
152
|
+
|
|
153
|
+
format = _getStorySource.format;
|
|
144
154
|
source = storyIds.map(function (storyId, idx) {
|
|
145
|
-
var
|
|
155
|
+
var _getStorySource2 = getStorySource(storyId, sourceContext),
|
|
156
|
+
storySource = _getStorySource2.code;
|
|
157
|
+
|
|
146
158
|
var storyObj = stories[idx];
|
|
147
159
|
return getSnippet(storySource, storyObj);
|
|
148
160
|
}).join('\n\n');
|
|
@@ -158,6 +170,7 @@ var getSourceProps = function getSourceProps(props, docsContext, sourceContext)
|
|
|
158
170
|
return source ? {
|
|
159
171
|
code: source,
|
|
160
172
|
state: state,
|
|
173
|
+
format: format,
|
|
161
174
|
language: props.language || docsLanguage || 'jsx',
|
|
162
175
|
dark: props.dark || false
|
|
163
176
|
} : {
|
|
@@ -79,25 +79,33 @@ var SourceContainer = function SourceContainer(_ref) {
|
|
|
79
79
|
var channel = _addons.addons.getChannel();
|
|
80
80
|
|
|
81
81
|
(0, _react.useEffect)(function () {
|
|
82
|
-
var handleSnippetRendered = function handleSnippetRendered(id,
|
|
83
|
-
|
|
84
|
-
setSources(function (current) {
|
|
85
|
-
var newSources = Object.assign({}, current, _defineProperty({}, id, newItem));
|
|
82
|
+
var handleSnippetRendered = function handleSnippetRendered(id, newSource) {
|
|
83
|
+
var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
86
84
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
return current;
|
|
92
|
-
});
|
|
85
|
+
// optimization: if the source is the same, ignore the incoming event
|
|
86
|
+
if (sources[id] && sources[id].code === newSource) {
|
|
87
|
+
return;
|
|
93
88
|
}
|
|
89
|
+
|
|
90
|
+
setSources(function (current) {
|
|
91
|
+
var newSources = Object.assign({}, current, _defineProperty({}, id, {
|
|
92
|
+
code: newSource,
|
|
93
|
+
format: format
|
|
94
|
+
}));
|
|
95
|
+
|
|
96
|
+
if (!(0, _fastDeepEqual.default)(current, newSources)) {
|
|
97
|
+
return newSources;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return current;
|
|
101
|
+
});
|
|
94
102
|
};
|
|
95
103
|
|
|
96
104
|
channel.on(_shared.SNIPPET_RENDERED, handleSnippetRendered);
|
|
97
105
|
return function () {
|
|
98
106
|
return channel.off(_shared.SNIPPET_RENDERED, handleSnippetRendered);
|
|
99
107
|
};
|
|
100
|
-
});
|
|
108
|
+
}, []);
|
|
101
109
|
return /*#__PURE__*/_react.default.createElement(SourceContext.Provider, {
|
|
102
110
|
value: {
|
|
103
111
|
sources: sources
|
|
File without changes
|
|
@@ -16,6 +16,8 @@ require("core-js/modules/es.array.from.js");
|
|
|
16
16
|
|
|
17
17
|
require("core-js/modules/es.array.slice.js");
|
|
18
18
|
|
|
19
|
+
require("core-js/modules/es.function.name.js");
|
|
20
|
+
|
|
19
21
|
require("core-js/modules/es.promise.js");
|
|
20
22
|
|
|
21
23
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -29,16 +31,12 @@ require("core-js/modules/es.array.concat.js");
|
|
|
29
31
|
|
|
30
32
|
require("core-js/modules/es.object.assign.js");
|
|
31
33
|
|
|
32
|
-
require("core-js/modules/es.function.name.js");
|
|
33
|
-
|
|
34
|
-
require("core-js/modules/es.regexp.exec.js");
|
|
35
|
-
|
|
36
|
-
require("core-js/modules/es.string.match.js");
|
|
37
|
-
|
|
38
34
|
require("core-js/modules/es.array.filter.js");
|
|
39
35
|
|
|
40
36
|
require("core-js/modules/es.object.to-string.js");
|
|
41
37
|
|
|
38
|
+
require("core-js/modules/es.regexp.exec.js");
|
|
39
|
+
|
|
42
40
|
require("core-js/modules/es.regexp.to-string.js");
|
|
43
41
|
|
|
44
42
|
require("core-js/modules/es.regexp.constructor.js");
|
|
@@ -100,10 +98,6 @@ function _webpack() {
|
|
|
100
98
|
|
|
101
99
|
var webpackConfig,
|
|
102
100
|
options,
|
|
103
|
-
_yield$options$preset,
|
|
104
|
-
_yield$options$preset2,
|
|
105
|
-
builder,
|
|
106
|
-
builderName,
|
|
107
101
|
resolvedBabelLoader,
|
|
108
102
|
_webpackConfig$module,
|
|
109
103
|
module,
|
|
@@ -129,17 +123,7 @@ function _webpack() {
|
|
|
129
123
|
case 0:
|
|
130
124
|
webpackConfig = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
131
125
|
options = _args.length > 1 ? _args[1] : undefined;
|
|
132
|
-
|
|
133
|
-
return options.presets.apply('core', {});
|
|
134
|
-
|
|
135
|
-
case 4:
|
|
136
|
-
_yield$options$preset = _context.sent;
|
|
137
|
-
_yield$options$preset2 = _yield$options$preset.builder;
|
|
138
|
-
builder = _yield$options$preset2 === void 0 ? 'webpack4' : _yield$options$preset2;
|
|
139
|
-
builderName = typeof builder === 'string' ? builder : builder.name;
|
|
140
|
-
resolvedBabelLoader = require.resolve('babel-loader', {
|
|
141
|
-
paths: builderName.match(/^webpack(4|5)$/) ? [require.resolve("@storybook/builder-".concat(builderName))] : [builderName]
|
|
142
|
-
});
|
|
126
|
+
resolvedBabelLoader = require.resolve('babel-loader');
|
|
143
127
|
_webpackConfig$module = webpackConfig.module, module = _webpackConfig$module === void 0 ? {} : _webpackConfig$module; // it will reuse babel options that are already in use in storybook
|
|
144
128
|
// also, these babel options are chained with other presets.
|
|
145
129
|
|
|
@@ -231,7 +215,7 @@ function _webpack() {
|
|
|
231
215
|
});
|
|
232
216
|
return _context.abrupt("return", result);
|
|
233
217
|
|
|
234
|
-
case
|
|
218
|
+
case 14:
|
|
235
219
|
case "end":
|
|
236
220
|
return _context.stop();
|
|
237
221
|
}
|
|
@@ -39,7 +39,6 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
39
39
|
|
|
40
40
|
var parameters = {
|
|
41
41
|
docs: {
|
|
42
|
-
inlineStories: false,
|
|
43
42
|
getContainer: function () {
|
|
44
43
|
var _getContainer = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
45
44
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
@@ -48,7 +47,7 @@ var parameters = {
|
|
|
48
47
|
case 0:
|
|
49
48
|
_context.next = 2;
|
|
50
49
|
return Promise.resolve().then(function () {
|
|
51
|
-
return _interopRequireWildcard(require('
|
|
50
|
+
return _interopRequireWildcard(require('./blocks'));
|
|
52
51
|
});
|
|
53
52
|
|
|
54
53
|
case 2:
|
|
@@ -76,7 +75,7 @@ var parameters = {
|
|
|
76
75
|
case 0:
|
|
77
76
|
_context2.next = 2;
|
|
78
77
|
return Promise.resolve().then(function () {
|
|
79
|
-
return _interopRequireWildcard(require('
|
|
78
|
+
return _interopRequireWildcard(require('./blocks'));
|
|
80
79
|
});
|
|
81
80
|
|
|
82
81
|
case 2:
|
|
@@ -95,8 +94,7 @@ var parameters = {
|
|
|
95
94
|
}
|
|
96
95
|
|
|
97
96
|
return getPage;
|
|
98
|
-
}()
|
|
99
|
-
iframeHeight: 100
|
|
97
|
+
}()
|
|
100
98
|
}
|
|
101
99
|
};
|
|
102
100
|
exports.parameters = parameters;
|
|
@@ -33,7 +33,10 @@ var getStorySource = function getStorySource(storyId, sourceContext) {
|
|
|
33
33
|
var sources = sourceContext.sources; // source rendering is async so source is unavailable at the start of the render cycle,
|
|
34
34
|
// so we fail gracefully here without warning
|
|
35
35
|
|
|
36
|
-
return (sources === null || sources === void 0 ? void 0 : sources[storyId]) ||
|
|
36
|
+
return (sources === null || sources === void 0 ? void 0 : sources[storyId]) || {
|
|
37
|
+
code: '',
|
|
38
|
+
format: false
|
|
39
|
+
};
|
|
37
40
|
};
|
|
38
41
|
|
|
39
42
|
var getSnippet = function getSnippet(snippet, story) {
|
|
@@ -85,6 +88,8 @@ export var getSourceProps = function getSourceProps(props, docsContext, sourceCo
|
|
|
85
88
|
var multiProps = props;
|
|
86
89
|
var source = codeProps.code; // prefer user-specified code
|
|
87
90
|
|
|
91
|
+
var format = codeProps.format; // prefer user-specified code
|
|
92
|
+
|
|
88
93
|
var targetIds = multiProps.ids || [singleProps.id || currentId];
|
|
89
94
|
var storyIds = targetIds.map(function (targetId) {
|
|
90
95
|
return targetId === CURRENT_SELECTION ? currentId : targetId;
|
|
@@ -99,8 +104,15 @@ export var getSourceProps = function getSourceProps(props, docsContext, sourceCo
|
|
|
99
104
|
}
|
|
100
105
|
|
|
101
106
|
if (!source) {
|
|
107
|
+
// just take the format from the first story, given how they're all concatinated together...
|
|
108
|
+
// TODO: we should consider sending an event with all the sources separately, instead of concatenating them here
|
|
109
|
+
var _getStorySource = getStorySource(storyIds[0], sourceContext);
|
|
110
|
+
|
|
111
|
+
format = _getStorySource.format;
|
|
102
112
|
source = storyIds.map(function (storyId, idx) {
|
|
103
|
-
var
|
|
113
|
+
var _getStorySource2 = getStorySource(storyId, sourceContext),
|
|
114
|
+
storySource = _getStorySource2.code;
|
|
115
|
+
|
|
104
116
|
var storyObj = stories[idx];
|
|
105
117
|
return getSnippet(storySource, storyObj);
|
|
106
118
|
}).join('\n\n');
|
|
@@ -116,6 +128,7 @@ export var getSourceProps = function getSourceProps(props, docsContext, sourceCo
|
|
|
116
128
|
return source ? {
|
|
117
129
|
code: source,
|
|
118
130
|
state: state,
|
|
131
|
+
format: format,
|
|
119
132
|
language: props.language || docsLanguage || 'jsx',
|
|
120
133
|
dark: props.dark || false
|
|
121
134
|
} : {
|
|
@@ -42,25 +42,33 @@ export var SourceContainer = function SourceContainer(_ref) {
|
|
|
42
42
|
|
|
43
43
|
var channel = addons.getChannel();
|
|
44
44
|
useEffect(function () {
|
|
45
|
-
var handleSnippetRendered = function handleSnippetRendered(id,
|
|
46
|
-
|
|
47
|
-
setSources(function (current) {
|
|
48
|
-
var newSources = Object.assign({}, current, _defineProperty({}, id, newItem));
|
|
45
|
+
var handleSnippetRendered = function handleSnippetRendered(id, newSource) {
|
|
46
|
+
var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
return current;
|
|
55
|
-
});
|
|
48
|
+
// optimization: if the source is the same, ignore the incoming event
|
|
49
|
+
if (sources[id] && sources[id].code === newSource) {
|
|
50
|
+
return;
|
|
56
51
|
}
|
|
52
|
+
|
|
53
|
+
setSources(function (current) {
|
|
54
|
+
var newSources = Object.assign({}, current, _defineProperty({}, id, {
|
|
55
|
+
code: newSource,
|
|
56
|
+
format: format
|
|
57
|
+
}));
|
|
58
|
+
|
|
59
|
+
if (!deepEqual(current, newSources)) {
|
|
60
|
+
return newSources;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return current;
|
|
64
|
+
});
|
|
57
65
|
};
|
|
58
66
|
|
|
59
67
|
channel.on(SNIPPET_RENDERED, handleSnippetRendered);
|
|
60
68
|
return function () {
|
|
61
69
|
return channel.off(SNIPPET_RENDERED, handleSnippetRendered);
|
|
62
70
|
};
|
|
63
|
-
});
|
|
71
|
+
}, []);
|
|
64
72
|
return /*#__PURE__*/React.createElement(SourceContext.Provider, {
|
|
65
73
|
value: {
|
|
66
74
|
sources: sources
|
|
File without changes
|
|
@@ -6,11 +6,9 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
6
6
|
|
|
7
7
|
import "core-js/modules/es.array.concat.js";
|
|
8
8
|
import "core-js/modules/es.object.assign.js";
|
|
9
|
-
import "core-js/modules/es.function.name.js";
|
|
10
|
-
import "core-js/modules/es.regexp.exec.js";
|
|
11
|
-
import "core-js/modules/es.string.match.js";
|
|
12
9
|
import "core-js/modules/es.array.filter.js";
|
|
13
10
|
import "core-js/modules/es.object.to-string.js";
|
|
11
|
+
import "core-js/modules/es.regexp.exec.js";
|
|
14
12
|
import "core-js/modules/es.regexp.to-string.js";
|
|
15
13
|
import "core-js/modules/es.regexp.constructor.js";
|
|
16
14
|
import "core-js/modules/es.symbol.js";
|
|
@@ -21,6 +19,7 @@ import "core-js/modules/es.string.iterator.js";
|
|
|
21
19
|
import "core-js/modules/web.dom-collections.iterator.js";
|
|
22
20
|
import "core-js/modules/es.array.from.js";
|
|
23
21
|
import "core-js/modules/es.array.slice.js";
|
|
22
|
+
import "core-js/modules/es.function.name.js";
|
|
24
23
|
import "core-js/modules/es.promise.js";
|
|
25
24
|
|
|
26
25
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
@@ -72,10 +71,6 @@ function _webpack() {
|
|
|
72
71
|
|
|
73
72
|
var webpackConfig,
|
|
74
73
|
options,
|
|
75
|
-
_yield$options$preset,
|
|
76
|
-
_yield$options$preset2,
|
|
77
|
-
builder,
|
|
78
|
-
builderName,
|
|
79
74
|
resolvedBabelLoader,
|
|
80
75
|
_webpackConfig$module,
|
|
81
76
|
module,
|
|
@@ -101,17 +96,7 @@ function _webpack() {
|
|
|
101
96
|
case 0:
|
|
102
97
|
webpackConfig = _args.length > 0 && _args[0] !== undefined ? _args[0] : {};
|
|
103
98
|
options = _args.length > 1 ? _args[1] : undefined;
|
|
104
|
-
|
|
105
|
-
return options.presets.apply('core', {});
|
|
106
|
-
|
|
107
|
-
case 4:
|
|
108
|
-
_yield$options$preset = _context.sent;
|
|
109
|
-
_yield$options$preset2 = _yield$options$preset.builder;
|
|
110
|
-
builder = _yield$options$preset2 === void 0 ? 'webpack4' : _yield$options$preset2;
|
|
111
|
-
builderName = typeof builder === 'string' ? builder : builder.name;
|
|
112
|
-
resolvedBabelLoader = require.resolve('babel-loader', {
|
|
113
|
-
paths: builderName.match(/^webpack(4|5)$/) ? [require.resolve("@storybook/builder-".concat(builderName))] : [builderName]
|
|
114
|
-
});
|
|
99
|
+
resolvedBabelLoader = require.resolve('babel-loader');
|
|
115
100
|
_webpackConfig$module = webpackConfig.module, module = _webpackConfig$module === void 0 ? {} : _webpackConfig$module; // it will reuse babel options that are already in use in storybook
|
|
116
101
|
// also, these babel options are chained with other presets.
|
|
117
102
|
|
|
@@ -201,7 +186,7 @@ function _webpack() {
|
|
|
201
186
|
});
|
|
202
187
|
return _context.abrupt("return", result);
|
|
203
188
|
|
|
204
|
-
case
|
|
189
|
+
case 14:
|
|
205
190
|
case "end":
|
|
206
191
|
return _context.stop();
|
|
207
192
|
}
|
|
@@ -8,7 +8,6 @@ function _asyncToGenerator(fn) { return function () { var self = this, args = ar
|
|
|
8
8
|
|
|
9
9
|
export var parameters = {
|
|
10
10
|
docs: {
|
|
11
|
-
inlineStories: false,
|
|
12
11
|
getContainer: function () {
|
|
13
12
|
var _getContainer = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
|
|
14
13
|
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
@@ -16,7 +15,7 @@ export var parameters = {
|
|
|
16
15
|
switch (_context.prev = _context.next) {
|
|
17
16
|
case 0:
|
|
18
17
|
_context.next = 2;
|
|
19
|
-
return import('
|
|
18
|
+
return import('./blocks');
|
|
20
19
|
|
|
21
20
|
case 2:
|
|
22
21
|
return _context.abrupt("return", _context.sent.DocsContainer);
|
|
@@ -42,7 +41,7 @@ export var parameters = {
|
|
|
42
41
|
switch (_context2.prev = _context2.next) {
|
|
43
42
|
case 0:
|
|
44
43
|
_context2.next = 2;
|
|
45
|
-
return import('
|
|
44
|
+
return import('./blocks');
|
|
46
45
|
|
|
47
46
|
case 2:
|
|
48
47
|
return _context2.abrupt("return", _context2.sent.DocsPage);
|
|
@@ -60,7 +59,6 @@ export var parameters = {
|
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
return getPage;
|
|
63
|
-
}()
|
|
64
|
-
iframeHeight: 100
|
|
62
|
+
}()
|
|
65
63
|
}
|
|
66
64
|
};
|
|
@@ -31,7 +31,10 @@ const getStorySource = (storyId, sourceContext) => {
|
|
|
31
31
|
} = sourceContext; // source rendering is async so source is unavailable at the start of the render cycle,
|
|
32
32
|
// so we fail gracefully here without warning
|
|
33
33
|
|
|
34
|
-
return (sources === null || sources === void 0 ? void 0 : sources[storyId]) ||
|
|
34
|
+
return (sources === null || sources === void 0 ? void 0 : sources[storyId]) || {
|
|
35
|
+
code: '',
|
|
36
|
+
format: false
|
|
37
|
+
};
|
|
35
38
|
};
|
|
36
39
|
|
|
37
40
|
const getSnippet = (snippet, story) => {
|
|
@@ -86,6 +89,10 @@ export const getSourceProps = (props, docsContext, sourceContext) => {
|
|
|
86
89
|
const multiProps = props;
|
|
87
90
|
let source = codeProps.code; // prefer user-specified code
|
|
88
91
|
|
|
92
|
+
let {
|
|
93
|
+
format
|
|
94
|
+
} = codeProps; // prefer user-specified code
|
|
95
|
+
|
|
89
96
|
const targetIds = multiProps.ids || [singleProps.id || currentId];
|
|
90
97
|
const storyIds = targetIds.map(targetId => targetId === CURRENT_SELECTION ? currentId : targetId);
|
|
91
98
|
const stories = useStories(storyIds, docsContext);
|
|
@@ -98,8 +105,15 @@ export const getSourceProps = (props, docsContext, sourceContext) => {
|
|
|
98
105
|
}
|
|
99
106
|
|
|
100
107
|
if (!source) {
|
|
108
|
+
// just take the format from the first story, given how they're all concatinated together...
|
|
109
|
+
// TODO: we should consider sending an event with all the sources separately, instead of concatenating them here
|
|
110
|
+
({
|
|
111
|
+
format
|
|
112
|
+
} = getStorySource(storyIds[0], sourceContext));
|
|
101
113
|
source = storyIds.map((storyId, idx) => {
|
|
102
|
-
const
|
|
114
|
+
const {
|
|
115
|
+
code: storySource
|
|
116
|
+
} = getStorySource(storyId, sourceContext);
|
|
103
117
|
const storyObj = stories[idx];
|
|
104
118
|
return getSnippet(storySource, storyObj);
|
|
105
119
|
}).join('\n\n');
|
|
@@ -118,6 +132,7 @@ export const getSourceProps = (props, docsContext, sourceContext) => {
|
|
|
118
132
|
return source ? {
|
|
119
133
|
code: source,
|
|
120
134
|
state,
|
|
135
|
+
format,
|
|
121
136
|
language: props.language || docsLanguage || 'jsx',
|
|
122
137
|
dark: props.dark || false
|
|
123
138
|
} : {
|
|
@@ -11,25 +11,31 @@ export const SourceContainer = ({
|
|
|
11
11
|
const [sources, setSources] = useState({});
|
|
12
12
|
const channel = addons.getChannel();
|
|
13
13
|
useEffect(() => {
|
|
14
|
-
const handleSnippetRendered = (id,
|
|
15
|
-
if
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
});
|
|
14
|
+
const handleSnippetRendered = (id, newSource, format = false) => {
|
|
15
|
+
// optimization: if the source is the same, ignore the incoming event
|
|
16
|
+
if (sources[id] && sources[id].code === newSource) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
setSources(current => {
|
|
21
|
+
const newSources = Object.assign({}, current, {
|
|
22
|
+
[id]: {
|
|
23
|
+
code: newSource,
|
|
24
|
+
format
|
|
23
25
|
}
|
|
24
|
-
|
|
25
|
-
return current;
|
|
26
26
|
});
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
if (!deepEqual(current, newSources)) {
|
|
29
|
+
return newSources;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return current;
|
|
33
|
+
});
|
|
28
34
|
};
|
|
29
35
|
|
|
30
36
|
channel.on(SNIPPET_RENDERED, handleSnippetRendered);
|
|
31
37
|
return () => channel.off(SNIPPET_RENDERED, handleSnippetRendered);
|
|
32
|
-
});
|
|
38
|
+
}, []);
|
|
33
39
|
return /*#__PURE__*/React.createElement(SourceContext.Provider, {
|
|
34
40
|
value: {
|
|
35
41
|
sources
|
|
File without changes
|
|
@@ -29,14 +29,7 @@ function createBabelOptions({
|
|
|
29
29
|
export async function webpack(webpackConfig = {}, options) {
|
|
30
30
|
var _global$FEATURES, _global$FEATURES2;
|
|
31
31
|
|
|
32
|
-
const
|
|
33
|
-
builder = 'webpack4'
|
|
34
|
-
} = await options.presets.apply('core', {});
|
|
35
|
-
const builderName = typeof builder === 'string' ? builder : builder.name;
|
|
36
|
-
|
|
37
|
-
const resolvedBabelLoader = require.resolve('babel-loader', {
|
|
38
|
-
paths: builderName.match(/^webpack(4|5)$/) ? [require.resolve(`@storybook/builder-${builderName}`)] : [builderName]
|
|
39
|
-
});
|
|
32
|
+
const resolvedBabelLoader = require.resolve('babel-loader');
|
|
40
33
|
|
|
41
34
|
const {
|
|
42
35
|
module = {}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { ComponentProps, FC } from 'react';
|
|
2
|
+
import { Source as PureSource } from '@storybook/components';
|
|
3
3
|
import { DocsContextProps } from './DocsContext';
|
|
4
4
|
import { SourceContextProps } from './SourceContainer';
|
|
5
5
|
export declare enum SourceState {
|
|
@@ -10,6 +10,7 @@ export declare enum SourceState {
|
|
|
10
10
|
interface CommonProps {
|
|
11
11
|
language?: string;
|
|
12
12
|
dark?: boolean;
|
|
13
|
+
format?: PureSourceProps['format'];
|
|
13
14
|
code?: string;
|
|
14
15
|
}
|
|
15
16
|
declare type SingleSourceProps = {
|
|
@@ -26,11 +27,12 @@ declare type SourceProps = SingleSourceProps | MultiSourceProps | CodeProps | No
|
|
|
26
27
|
declare type SourceStateProps = {
|
|
27
28
|
state: SourceState;
|
|
28
29
|
};
|
|
30
|
+
declare type PureSourceProps = ComponentProps<typeof PureSource>;
|
|
29
31
|
export declare const getSourceProps: (props: SourceProps, docsContext: DocsContextProps<any>, sourceContext: SourceContextProps) => PureSourceProps & SourceStateProps;
|
|
30
32
|
/**
|
|
31
33
|
* Story source doc block renders source code if provided,
|
|
32
34
|
* or the source for a story if `storyId` is provided, or
|
|
33
35
|
* the source for the current story if nothing is provided.
|
|
34
36
|
*/
|
|
35
|
-
export declare const Source: FC<
|
|
37
|
+
export declare const Source: FC<PureSourceProps>;
|
|
36
38
|
export {};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { FC, Context } from 'react';
|
|
2
|
+
import { SyntaxHighlighterFormatTypes } from '@storybook/components';
|
|
2
3
|
import { StoryId } from '@storybook/api';
|
|
3
|
-
export
|
|
4
|
+
export interface SourceItem {
|
|
5
|
+
code: string;
|
|
6
|
+
format: SyntaxHighlighterFormatTypes;
|
|
7
|
+
}
|
|
4
8
|
export declare type StorySources = Record<StoryId, SourceItem>;
|
|
5
9
|
export interface SourceContextProps {
|
|
6
10
|
sources: StorySources;
|
|
File without changes
|
|
File without changes
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export declare const parameters: {
|
|
2
|
-
docs: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
};
|
|
1
|
+
export declare const parameters: {
|
|
2
|
+
docs: {
|
|
3
|
+
getContainer: () => Promise<import("react").FunctionComponent<import("./blocks").DocsContainerProps<import("@storybook/csf").AnyFramework>>>;
|
|
4
|
+
getPage: () => Promise<import("react").FC<{}>>;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import {
|
|
1
|
+
import { ComponentProps, FC } from 'react';
|
|
2
|
+
import { Source as PureSource } from '@storybook/components';
|
|
3
3
|
import { DocsContextProps } from './DocsContext';
|
|
4
4
|
import { SourceContextProps } from './SourceContainer';
|
|
5
5
|
export declare enum SourceState {
|
|
@@ -10,6 +10,7 @@ export declare enum SourceState {
|
|
|
10
10
|
interface CommonProps {
|
|
11
11
|
language?: string;
|
|
12
12
|
dark?: boolean;
|
|
13
|
+
format?: PureSourceProps['format'];
|
|
13
14
|
code?: string;
|
|
14
15
|
}
|
|
15
16
|
declare type SingleSourceProps = {
|
|
@@ -26,11 +27,12 @@ declare type SourceProps = SingleSourceProps | MultiSourceProps | CodeProps | No
|
|
|
26
27
|
declare type SourceStateProps = {
|
|
27
28
|
state: SourceState;
|
|
28
29
|
};
|
|
30
|
+
declare type PureSourceProps = ComponentProps<typeof PureSource>;
|
|
29
31
|
export declare const getSourceProps: (props: SourceProps, docsContext: DocsContextProps<any>, sourceContext: SourceContextProps) => PureSourceProps & SourceStateProps;
|
|
30
32
|
/**
|
|
31
33
|
* Story source doc block renders source code if provided,
|
|
32
34
|
* or the source for a story if `storyId` is provided, or
|
|
33
35
|
* the source for the current story if nothing is provided.
|
|
34
36
|
*/
|
|
35
|
-
export declare const Source: FC<
|
|
37
|
+
export declare const Source: FC<PureSourceProps>;
|
|
36
38
|
export {};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { FC, Context } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import type { SyntaxHighlighterFormatTypes } from '@storybook/components';
|
|
3
|
+
import type { StoryId } from '@storybook/api';
|
|
4
|
+
export interface SourceItem {
|
|
5
|
+
code: string;
|
|
6
|
+
format: SyntaxHighlighterFormatTypes;
|
|
7
|
+
}
|
|
4
8
|
export declare type StorySources = Record<StoryId, SourceItem>;
|
|
5
9
|
export interface SourceContextProps {
|
|
6
10
|
sources: StorySources;
|
|
File without changes
|
|
File without changes
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export declare const parameters: {
|
|
2
|
-
docs: {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
};
|
|
8
|
-
};
|
|
1
|
+
export declare const parameters: {
|
|
2
|
+
docs: {
|
|
3
|
+
getContainer: () => Promise<import("react").FunctionComponent<import("./blocks").DocsContainerProps<import("@storybook/csf").AnyFramework>>>;
|
|
4
|
+
getPage: () => Promise<import("react").FC<{}>>;
|
|
5
|
+
};
|
|
6
|
+
};
|
package/manager.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import './dist/esm/manager';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/addon-docs",
|
|
3
|
-
"version": "6.5.0-alpha.
|
|
3
|
+
"version": "6.5.0-alpha.53",
|
|
4
4
|
"description": "Document component usage and properties in Markdown",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"addon",
|
|
@@ -59,24 +59,26 @@
|
|
|
59
59
|
"@babel/preset-env": "^7.12.11",
|
|
60
60
|
"@jest/transform": "^26.6.2",
|
|
61
61
|
"@mdx-js/react": "^1.6.22",
|
|
62
|
-
"@storybook/addons": "6.5.0-alpha.
|
|
63
|
-
"@storybook/api": "6.5.0-alpha.
|
|
64
|
-
"@storybook/components": "6.5.0-alpha.
|
|
65
|
-
"@storybook/core-common": "6.5.0-alpha.
|
|
66
|
-
"@storybook/core-events": "6.5.0-alpha.
|
|
62
|
+
"@storybook/addons": "6.5.0-alpha.53",
|
|
63
|
+
"@storybook/api": "6.5.0-alpha.53",
|
|
64
|
+
"@storybook/components": "6.5.0-alpha.53",
|
|
65
|
+
"@storybook/core-common": "6.5.0-alpha.53",
|
|
66
|
+
"@storybook/core-events": "6.5.0-alpha.53",
|
|
67
67
|
"@storybook/csf": "0.0.2--canary.507502b.0",
|
|
68
|
-
"@storybook/docs-tools": "6.5.0-alpha.
|
|
68
|
+
"@storybook/docs-tools": "6.5.0-alpha.53",
|
|
69
69
|
"@storybook/mdx1-csf": "canary",
|
|
70
|
-
"@storybook/node-logger": "6.5.0-alpha.
|
|
71
|
-
"@storybook/postinstall": "6.5.0-alpha.
|
|
72
|
-
"@storybook/preview-web": "6.5.0-alpha.
|
|
73
|
-
"@storybook/source-loader": "6.5.0-alpha.
|
|
74
|
-
"@storybook/store": "6.5.0-alpha.
|
|
75
|
-
"@storybook/theming": "6.5.0-alpha.
|
|
70
|
+
"@storybook/node-logger": "6.5.0-alpha.53",
|
|
71
|
+
"@storybook/postinstall": "6.5.0-alpha.53",
|
|
72
|
+
"@storybook/preview-web": "6.5.0-alpha.53",
|
|
73
|
+
"@storybook/source-loader": "6.5.0-alpha.53",
|
|
74
|
+
"@storybook/store": "6.5.0-alpha.53",
|
|
75
|
+
"@storybook/theming": "6.5.0-alpha.53",
|
|
76
|
+
"babel-loader": "^8.0.0",
|
|
76
77
|
"core-js": "^3.8.2",
|
|
77
78
|
"fast-deep-equal": "^3.1.3",
|
|
78
79
|
"global": "^4.4.0",
|
|
79
80
|
"lodash": "^4.17.21",
|
|
81
|
+
"regenerator-runtime": "^0.13.7",
|
|
80
82
|
"remark-external-links": "^8.0.0",
|
|
81
83
|
"remark-slug": "^6.0.0",
|
|
82
84
|
"ts-dedent": "^2.0.0",
|
|
@@ -85,23 +87,14 @@
|
|
|
85
87
|
"devDependencies": {
|
|
86
88
|
"@babel/core": "^7.12.10",
|
|
87
89
|
"@storybook/mdx2-csf": "canary",
|
|
88
|
-
"@types/util-deprecate": "^1.0.0"
|
|
89
|
-
"babel-loader": "^8.0.0",
|
|
90
|
-
"webpack": "4"
|
|
90
|
+
"@types/util-deprecate": "^1.0.0"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
93
|
"@storybook/mdx2-csf": "*",
|
|
94
94
|
"react": "^16.8.0 || ^17.0.0",
|
|
95
|
-
"react-dom": "^16.8.0 || ^17.0.0"
|
|
96
|
-
"webpack": "*"
|
|
95
|
+
"react-dom": "^16.8.0 || ^17.0.0"
|
|
97
96
|
},
|
|
98
97
|
"peerDependenciesMeta": {
|
|
99
|
-
"@storybook/builder-webpack4": {
|
|
100
|
-
"optional": true
|
|
101
|
-
},
|
|
102
|
-
"@storybook/builder-webpack5": {
|
|
103
|
-
"optional": true
|
|
104
|
-
},
|
|
105
98
|
"@storybook/mdx2-csf": {
|
|
106
99
|
"optional": true
|
|
107
100
|
},
|
|
@@ -110,15 +103,12 @@
|
|
|
110
103
|
},
|
|
111
104
|
"react-dom": {
|
|
112
105
|
"optional": true
|
|
113
|
-
},
|
|
114
|
-
"webpack": {
|
|
115
|
-
"optional": true
|
|
116
106
|
}
|
|
117
107
|
},
|
|
118
108
|
"publishConfig": {
|
|
119
109
|
"access": "public"
|
|
120
110
|
},
|
|
121
|
-
"gitHead": "
|
|
111
|
+
"gitHead": "652768b3ff83a355651d5636ccc4d78bee2cdbf9",
|
|
122
112
|
"sbmodern": "dist/modern/index.js",
|
|
123
113
|
"storybook": {
|
|
124
114
|
"displayName": "Docs",
|
package/preset.js
CHANGED
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
const { webpack } = require('./dist/cjs/frameworks/common/preset');
|
|
3
|
-
|
|
4
|
-
function managerEntries(entry = [], options) {
|
|
5
|
-
return [...entry, findDistEsm(__dirname, 'register')];
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
function config(entry = [], options = {}) {
|
|
9
|
-
return [findDistEsm(__dirname, 'frameworks/common/config'), ...entry];
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = {
|
|
13
|
-
webpack,
|
|
14
|
-
managerEntries,
|
|
15
|
-
config,
|
|
16
|
-
};
|
|
1
|
+
module.exports = require('./dist/cjs/preset');
|
package/preview.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './dist/esm/preview';
|
package/register.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { once } from '@storybook/client-logger';
|
|
2
|
+
import './manager';
|
|
3
|
+
|
|
4
|
+
once.warn(
|
|
5
|
+
'register.js is deprecated see https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-registerjs'
|
|
6
|
+
);
|