Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source-loader: Overhaul to remove decorators, support user-configurable source #9547

Merged
merged 10 commits into from
Jan 28, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion addons/docs/src/blocks/Source.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,23 @@ interface StorySource {
}

const extract = (targetId: string, { source, locationsMap }: StorySource) => {
if (!locationsMap) {
return source;
}
const location = locationsMap[targetId];
// FIXME: bad locationsMap generated for module export functions whose titles are overridden
if (!location) return null;
const { startBody: start, endBody: end } = location;
const lines = source.split('\n');
if (start.line === end.line) {
if (start.line === end.line && lines[start.line - 1] !== undefined) {
return lines[start.line - 1].substring(start.col, end.col);
}
// NOTE: storysource locations are 1-based not 0-based!
const startLine = lines[start.line - 1];
const endLine = lines[end.line - 1];
if (startLine === undefined || endLine === undefined) {
atanasster marked this conversation as resolved.
Show resolved Hide resolved
return source;
}
return [
startLine.substring(start.col),
...lines.slice(start.line, end.line - 1),
Expand Down
9 changes: 9 additions & 0 deletions addons/storysource/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,33 @@
"*.d.ts"
],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/addons": "5.3.5",
"@storybook/api": "5.3.5",
"@storybook/components": "5.3.5",
"@storybook/core-events": "5.3.5",
"@storybook/router": "5.3.5",
"@storybook/source-loader": "5.3.5",
"@storybook/theming": "5.3.5",
"@types/react-syntax-highlighter": "11.0.2",
atanasster marked this conversation as resolved.
Show resolved Hide resolved
"core-js": "^3.0.1",
"estraverse": "^4.2.0",
"loader-utils": "^1.2.3",
"prettier": "^1.16.4",
"prop-types": "^15.7.2",
"react": "^16.9.17",
"react-syntax-highlighter": "^11.0.2",
"regenerator-runtime": "^0.13.3",
"util-deprecate": "^1.0.2"
},
"devDependencies": {
"@types/react": "^16.9.17",
"@types/react-syntax-highlighter": "^11.0.4"
},
"peerDependencies": {
"@storybook/source-loader": "*",
"react": "*"
Expand Down
188 changes: 0 additions & 188 deletions addons/storysource/src/StoryPanel.js

This file was deleted.

Loading