@storybook/addon-docs 7.0.0-alpha.5 → 7.0.0-alpha.51
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/README.md +14 -77
- package/angular/index.js +1 -1
- package/dist/DocsRenderer-MHI45CTG.mjs +1 -0
- package/dist/chunk-HKSD7XQF.mjs +1 -0
- package/dist/chunk-WMY67HY3.mjs +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/dist/preset.d.ts +5 -0
- package/dist/preset.js +7 -0
- package/dist/preset.mjs +7 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +1 -0
- package/dist/preview.mjs +1 -0
- package/jest-transform-mdx.js +4 -3
- package/jest.config.js +7 -0
- package/package.json +65 -38
- package/preset.js +1 -1
- package/preview.js +1 -1
- package/web-components/README.md +1 -0
- package/LICENSE +0 -21
- package/blocks.d.ts +0 -2
- package/blocks.js +0 -14
- package/dist/cjs/blocks/Anchor.js +0 -23
- package/dist/cjs/blocks/ArgsTable.js +0 -329
- package/dist/cjs/blocks/Canvas.js +0 -109
- package/dist/cjs/blocks/Description.js +0 -126
- package/dist/cjs/blocks/DocsContainer.js +0 -127
- package/dist/cjs/blocks/DocsContext.js +0 -25
- package/dist/cjs/blocks/DocsPage.js +0 -30
- package/dist/cjs/blocks/DocsStory.js +0 -68
- package/dist/cjs/blocks/Heading.js +0 -31
- package/dist/cjs/blocks/Meta.js +0 -50
- package/dist/cjs/blocks/Preview.js +0 -23
- package/dist/cjs/blocks/Primary.js +0 -39
- package/dist/cjs/blocks/Props.js +0 -29
- package/dist/cjs/blocks/Source.js +0 -179
- package/dist/cjs/blocks/SourceContainer.js +0 -67
- package/dist/cjs/blocks/Stories.js +0 -51
- package/dist/cjs/blocks/Story.js +0 -143
- package/dist/cjs/blocks/Subheading.js +0 -31
- package/dist/cjs/blocks/Subtitle.js +0 -39
- package/dist/cjs/blocks/Title.js +0 -44
- package/dist/cjs/blocks/Wrapper.js +0 -20
- package/dist/cjs/blocks/enhanceSource.js +0 -92
- package/dist/cjs/blocks/index.js +0 -366
- package/dist/cjs/blocks/mdx.js +0 -234
- package/dist/cjs/blocks/types.js +0 -10
- package/dist/cjs/blocks/useStory.js +0 -37
- package/dist/cjs/blocks/utils.js +0 -40
- package/dist/cjs/index.js +0 -18
- package/dist/cjs/manager.js +0 -20
- package/dist/cjs/preset.js +0 -162
- package/dist/cjs/preview.js +0 -18
- package/dist/cjs/shared.js +0 -22
- package/dist/esm/blocks/Anchor.js +0 -8
- package/dist/esm/blocks/ArgsTable.js +0 -292
- package/dist/esm/blocks/Canvas.js +0 -83
- package/dist/esm/blocks/Description.js +0 -107
- package/dist/esm/blocks/DocsContainer.js +0 -98
- package/dist/esm/blocks/DocsContext.js +0 -16
- package/dist/esm/blocks/DocsPage.js +0 -11
- package/dist/esm/blocks/DocsStory.js +0 -46
- package/dist/esm/blocks/Heading.js +0 -17
- package/dist/esm/blocks/Meta.js +0 -31
- package/dist/esm/blocks/Preview.js +0 -9
- package/dist/esm/blocks/Primary.js +0 -23
- package/dist/esm/blocks/Props.js +0 -14
- package/dist/esm/blocks/Source.js +0 -144
- package/dist/esm/blocks/SourceContainer.js +0 -44
- package/dist/esm/blocks/Stories.js +0 -30
- package/dist/esm/blocks/Story.js +0 -114
- package/dist/esm/blocks/Subheading.js +0 -17
- package/dist/esm/blocks/Subtitle.js +0 -23
- package/dist/esm/blocks/Title.js +0 -24
- package/dist/esm/blocks/Wrapper.js +0 -8
- package/dist/esm/blocks/enhanceSource.js +0 -87
- package/dist/esm/blocks/index.js +0 -24
- package/dist/esm/blocks/mdx.js +0 -203
- package/dist/esm/blocks/types.js +0 -2
- package/dist/esm/blocks/useStory.js +0 -27
- package/dist/esm/blocks/utils.js +0 -29
- package/dist/esm/index.js +0 -1
- package/dist/esm/manager.js +0 -16
- package/dist/esm/preset.js +0 -132
- package/dist/esm/preview.js +0 -6
- package/dist/esm/shared.js +0 -11
- package/dist/types/blocks/Anchor.d.ts +0 -6
- package/dist/types/blocks/ArgsTable.d.ts +0 -33
- package/dist/types/blocks/Canvas.d.ts +0 -9
- package/dist/types/blocks/Description.d.ts +0 -20
- package/dist/types/blocks/DocsContainer.d.ts +0 -7
- package/dist/types/blocks/DocsContext.d.ts +0 -5
- package/dist/types/blocks/DocsPage.d.ts +0 -2
- package/dist/types/blocks/DocsStory.d.ts +0 -3
- package/dist/types/blocks/Heading.d.ts +0 -6
- package/dist/types/blocks/Meta.d.ts +0 -9
- package/dist/types/blocks/Preview.d.ts +0 -3
- package/dist/types/blocks/Primary.d.ts +0 -6
- package/dist/types/blocks/Props.d.ts +0 -3
- package/dist/types/blocks/Source.d.ts +0 -38
- package/dist/types/blocks/SourceContainer.d.ts +0 -14
- package/dist/types/blocks/Stories.d.ts +0 -7
- package/dist/types/blocks/Story.d.ts +0 -28
- package/dist/types/blocks/Subheading.d.ts +0 -3
- package/dist/types/blocks/Subtitle.d.ts +0 -6
- package/dist/types/blocks/Title.d.ts +0 -8
- package/dist/types/blocks/Wrapper.d.ts +0 -2
- package/dist/types/blocks/enhanceSource.d.ts +0 -3
- package/dist/types/blocks/index.d.ts +0 -24
- package/dist/types/blocks/mdx.d.ts +0 -20
- package/dist/types/blocks/types.d.ts +0 -13
- package/dist/types/blocks/useStory.d.ts +0 -5
- package/dist/types/blocks/utils.d.ts +0 -3
- package/dist/types/index.d.ts +0 -1
- package/dist/types/manager.d.ts +0 -1
- package/dist/types/preset.d.ts +0 -12
- package/dist/types/preview.d.ts +0 -6
- package/dist/types/shared.d.ts +0 -24
- package/manager.js +0 -1
- package/mdx-compiler-plugin.js +0 -1
- package/register.js +0 -6
package/dist/cjs/blocks/Story.js
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.storyBlockIdFromId = exports.lookupStoryId = exports.getStoryProps = exports.getStoryId = exports.Story = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _react2 = require("@mdx-js/react");
|
|
11
|
-
|
|
12
|
-
var _components = require("@storybook/components");
|
|
13
|
-
|
|
14
|
-
var _csf = require("@storybook/csf");
|
|
15
|
-
|
|
16
|
-
var _types = require("./types");
|
|
17
|
-
|
|
18
|
-
var _DocsContext = require("./DocsContext");
|
|
19
|
-
|
|
20
|
-
var _useStory = require("./useStory");
|
|
21
|
-
|
|
22
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
|
-
|
|
24
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
25
|
-
|
|
26
|
-
const storyBlockIdFromId = storyId => `story--${storyId}`;
|
|
27
|
-
|
|
28
|
-
exports.storyBlockIdFromId = storyBlockIdFromId;
|
|
29
|
-
|
|
30
|
-
const lookupStoryId = (storyName, {
|
|
31
|
-
mdxStoryNameToKey,
|
|
32
|
-
mdxComponentAnnotations
|
|
33
|
-
}) => (0, _csf.toId)(mdxComponentAnnotations.id || mdxComponentAnnotations.title, (0, _csf.storyNameFromExport)(mdxStoryNameToKey[storyName]));
|
|
34
|
-
|
|
35
|
-
exports.lookupStoryId = lookupStoryId;
|
|
36
|
-
|
|
37
|
-
const getStoryId = (props, context) => {
|
|
38
|
-
const {
|
|
39
|
-
id
|
|
40
|
-
} = props;
|
|
41
|
-
const {
|
|
42
|
-
name
|
|
43
|
-
} = props;
|
|
44
|
-
const inputId = id === _types.CURRENT_SELECTION ? context.id : id;
|
|
45
|
-
return inputId || lookupStoryId(name, context);
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
exports.getStoryId = getStoryId;
|
|
49
|
-
|
|
50
|
-
const getStoryProps = ({
|
|
51
|
-
height,
|
|
52
|
-
inline
|
|
53
|
-
}, story) => {
|
|
54
|
-
const {
|
|
55
|
-
name: storyName,
|
|
56
|
-
parameters
|
|
57
|
-
} = story;
|
|
58
|
-
const {
|
|
59
|
-
docs = {}
|
|
60
|
-
} = parameters;
|
|
61
|
-
|
|
62
|
-
if (docs.disable) {
|
|
63
|
-
return null;
|
|
64
|
-
} // prefer block props, then story parameters defined by the framework-specific settings and optionally overridden by users
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
const {
|
|
68
|
-
inlineStories = false,
|
|
69
|
-
iframeHeight = 100
|
|
70
|
-
} = docs;
|
|
71
|
-
const storyIsInline = typeof inline === 'boolean' ? inline : inlineStories;
|
|
72
|
-
return Object.assign({
|
|
73
|
-
inline: storyIsInline,
|
|
74
|
-
id: story.id,
|
|
75
|
-
height: height || (storyIsInline ? undefined : iframeHeight),
|
|
76
|
-
title: storyName
|
|
77
|
-
}, storyIsInline && {
|
|
78
|
-
parameters
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
exports.getStoryProps = getStoryProps;
|
|
83
|
-
|
|
84
|
-
const Story = props => {
|
|
85
|
-
const context = (0, _react.useContext)(_DocsContext.DocsContext);
|
|
86
|
-
const storyRef = (0, _react.useRef)();
|
|
87
|
-
const storyId = getStoryId(props, context);
|
|
88
|
-
const story = (0, _useStory.useStory)(storyId, context);
|
|
89
|
-
const [showLoader, setShowLoader] = (0, _react.useState)(true);
|
|
90
|
-
(0, _react.useEffect)(() => {
|
|
91
|
-
let cleanup;
|
|
92
|
-
|
|
93
|
-
if (story && storyRef.current) {
|
|
94
|
-
const element = storyRef.current;
|
|
95
|
-
cleanup = context.renderStoryToElement(story, element);
|
|
96
|
-
setShowLoader(false);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
return () => cleanup && cleanup();
|
|
100
|
-
}, [story]);
|
|
101
|
-
|
|
102
|
-
if (!story) {
|
|
103
|
-
return /*#__PURE__*/_react.default.createElement(_components.StorySkeleton, null);
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
const storyProps = getStoryProps(props, story);
|
|
107
|
-
|
|
108
|
-
if (!storyProps) {
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
if (storyProps.inline) {
|
|
113
|
-
// We do this so React doesn't complain when we replace the span in a secondary render
|
|
114
|
-
const htmlContents = `<span></span>`; // FIXME: height/style/etc. lifted from PureStory
|
|
115
|
-
|
|
116
|
-
const {
|
|
117
|
-
height
|
|
118
|
-
} = storyProps;
|
|
119
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
120
|
-
id: storyBlockIdFromId(story.id)
|
|
121
|
-
}, /*#__PURE__*/_react.default.createElement(_react2.MDXProvider, {
|
|
122
|
-
components: _components.resetComponents
|
|
123
|
-
}, height ? /*#__PURE__*/_react.default.createElement("style", null, `#story--${story.id} { min-height: ${height}; transform: translateZ(0); overflow: auto }`) : null, showLoader && /*#__PURE__*/_react.default.createElement(_components.StorySkeleton, null), /*#__PURE__*/_react.default.createElement("div", {
|
|
124
|
-
ref: storyRef,
|
|
125
|
-
"data-name": story.name,
|
|
126
|
-
dangerouslySetInnerHTML: {
|
|
127
|
-
__html: htmlContents
|
|
128
|
-
}
|
|
129
|
-
})));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return /*#__PURE__*/_react.default.createElement("div", {
|
|
133
|
-
id: storyBlockIdFromId(story.id)
|
|
134
|
-
}, /*#__PURE__*/_react.default.createElement(_react2.MDXProvider, {
|
|
135
|
-
components: _components.resetComponents
|
|
136
|
-
}, /*#__PURE__*/_react.default.createElement(_components.Story, storyProps)));
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
exports.Story = Story;
|
|
140
|
-
Story.defaultProps = {
|
|
141
|
-
children: null,
|
|
142
|
-
name: null
|
|
143
|
-
};
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Subheading = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
var _components = require("@storybook/components");
|
|
11
|
-
|
|
12
|
-
var _mdx = require("./mdx");
|
|
13
|
-
|
|
14
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
-
|
|
16
|
-
const Subheading = ({
|
|
17
|
-
children,
|
|
18
|
-
disableAnchor
|
|
19
|
-
}) => {
|
|
20
|
-
if (disableAnchor || typeof children !== 'string') {
|
|
21
|
-
return /*#__PURE__*/_react.default.createElement(_components.H3, null, children);
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const tagID = children.toLowerCase().replace(/[^a-z0-9]/gi, '-');
|
|
25
|
-
return /*#__PURE__*/_react.default.createElement(_mdx.HeaderMdx, {
|
|
26
|
-
as: "h3",
|
|
27
|
-
id: tagID
|
|
28
|
-
}, children);
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
exports.Subheading = Subheading;
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Subtitle = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _components = require("@storybook/components");
|
|
11
|
-
|
|
12
|
-
var _DocsContext = require("./DocsContext");
|
|
13
|
-
|
|
14
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
-
|
|
16
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
-
|
|
18
|
-
const Subtitle = ({
|
|
19
|
-
children
|
|
20
|
-
}) => {
|
|
21
|
-
const {
|
|
22
|
-
id,
|
|
23
|
-
storyById
|
|
24
|
-
} = (0, _react.useContext)(_DocsContext.DocsContext);
|
|
25
|
-
const {
|
|
26
|
-
parameters
|
|
27
|
-
} = storyById(id);
|
|
28
|
-
let text = children;
|
|
29
|
-
|
|
30
|
-
if (!text) {
|
|
31
|
-
text = parameters === null || parameters === void 0 ? void 0 : parameters.componentSubtitle;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return text ? /*#__PURE__*/_react.default.createElement(_components.Subtitle, {
|
|
35
|
-
className: "sbdocs-subtitle"
|
|
36
|
-
}, text) : null;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
exports.Subtitle = Subtitle;
|
package/dist/cjs/blocks/Title.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.extractTitle = exports.Title = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _components = require("@storybook/components");
|
|
11
|
-
|
|
12
|
-
var _DocsContext = require("./DocsContext");
|
|
13
|
-
|
|
14
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
-
|
|
16
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
17
|
-
|
|
18
|
-
const STORY_KIND_PATH_SEPARATOR = /\s*\/\s*/;
|
|
19
|
-
|
|
20
|
-
const extractTitle = ({
|
|
21
|
-
title
|
|
22
|
-
}) => {
|
|
23
|
-
const groups = title.trim().split(STORY_KIND_PATH_SEPARATOR);
|
|
24
|
-
return groups && groups[groups.length - 1] || title;
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
exports.extractTitle = extractTitle;
|
|
28
|
-
|
|
29
|
-
const Title = ({
|
|
30
|
-
children
|
|
31
|
-
}) => {
|
|
32
|
-
const context = (0, _react.useContext)(_DocsContext.DocsContext);
|
|
33
|
-
let text = children;
|
|
34
|
-
|
|
35
|
-
if (!text) {
|
|
36
|
-
text = extractTitle(context);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return text ? /*#__PURE__*/_react.default.createElement(_components.Title, {
|
|
40
|
-
className: "sbdocs-title"
|
|
41
|
-
}, text) : null;
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
exports.Title = Title;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Wrapper = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
const Wrapper = ({
|
|
13
|
-
children
|
|
14
|
-
}) => /*#__PURE__*/_react.default.createElement("div", {
|
|
15
|
-
style: {
|
|
16
|
-
fontFamily: 'sans-serif'
|
|
17
|
-
}
|
|
18
|
-
}, children);
|
|
19
|
-
|
|
20
|
-
exports.Wrapper = Wrapper;
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.enhanceSource = void 0;
|
|
7
|
-
|
|
8
|
-
var _store = require("@storybook/store");
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* given a location, extract the text from the full source
|
|
12
|
-
*/
|
|
13
|
-
function extractSource(location, lines) {
|
|
14
|
-
const {
|
|
15
|
-
startBody: start,
|
|
16
|
-
endBody: end
|
|
17
|
-
} = location;
|
|
18
|
-
|
|
19
|
-
if (start.line === end.line && lines[start.line - 1] !== undefined) {
|
|
20
|
-
return lines[start.line - 1].substring(start.col, end.col);
|
|
21
|
-
} // NOTE: storysource locations are 1-based not 0-based!
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const startLine = lines[start.line - 1];
|
|
25
|
-
const endLine = lines[end.line - 1];
|
|
26
|
-
|
|
27
|
-
if (startLine === undefined || endLine === undefined) {
|
|
28
|
-
return null;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return [startLine.substring(start.col), ...lines.slice(start.line, end.line - 1), endLine.substring(0, end.col)].join('\n');
|
|
32
|
-
} // ============================================================
|
|
33
|
-
// END @storybook/source-loader/extract-source
|
|
34
|
-
// ============================================================
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Replaces full story id name like: story-kind--story-name -> story-name
|
|
39
|
-
* @param id
|
|
40
|
-
*/
|
|
41
|
-
const storyIdToSanitizedStoryName = id => id.replace(/^.*?--/, '');
|
|
42
|
-
|
|
43
|
-
const extract = (targetId, {
|
|
44
|
-
source,
|
|
45
|
-
locationsMap
|
|
46
|
-
}) => {
|
|
47
|
-
if (!locationsMap) {
|
|
48
|
-
return source;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const sanitizedStoryName = storyIdToSanitizedStoryName(targetId);
|
|
52
|
-
const location = locationsMap[sanitizedStoryName];
|
|
53
|
-
|
|
54
|
-
if (!location) {
|
|
55
|
-
return source;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const lines = source.split('\n');
|
|
59
|
-
return extractSource(location, lines);
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
const enhanceSource = story => {
|
|
63
|
-
var _docs$source;
|
|
64
|
-
|
|
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
|
|
76
|
-
|
|
77
|
-
if (!(storySource !== null && storySource !== void 0 && storySource.source) || (_docs$source = docs.source) !== null && _docs$source !== void 0 && _docs$source.code) {
|
|
78
|
-
return null;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const input = extract(id, storySource);
|
|
82
|
-
const code = transformSource ? transformSource(input, story) : input;
|
|
83
|
-
return {
|
|
84
|
-
docs: (0, _store.combineParameters)(docs, {
|
|
85
|
-
source: {
|
|
86
|
-
code
|
|
87
|
-
}
|
|
88
|
-
})
|
|
89
|
-
};
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
exports.enhanceSource = enhanceSource;
|