Skip to content

Commit

Permalink
Source-loader: Overhaul to remove decorators, support user-conf… (#9547)
Browse files Browse the repository at this point in the history
Source-loader: Overhaul to remove decorators, support user-configurable source
  • Loading branch information
shilman committed Jan 28, 2020
2 parents 21a4592 + d0096dc commit 2bee5dd
Show file tree
Hide file tree
Showing 43 changed files with 436 additions and 627 deletions.
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) {
return source;
}
return [
startLine.substring(start.col),
...lines.slice(start.line, end.line - 1),
Expand Down
8 changes: 8 additions & 0 deletions addons/storysource/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
"*.d.ts"
],
"main": "dist/index.js",
"types": "dist/index.d.ts",
"scripts": {
"prepare": "node ../../scripts/prepare.js"
},
"dependencies": {
"@storybook/addons": "6.0.0-alpha.1",
"@storybook/api": "6.0.0-alpha.1",
"@storybook/client-logger": "6.0.0-alpha.1",
"@storybook/components": "6.0.0-alpha.1",
"@storybook/router": "6.0.0-alpha.1",
"@storybook/source-loader": "6.0.0-alpha.1",
Expand All @@ -37,10 +40,15 @@
"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

0 comments on commit 2bee5dd

Please sign in to comment.