Skip to content
Permalink
Browse files

CHANGE storysource addon to use storyId instead of kind + name && ADD…

… toId to router package

CHANGE storysource to use toId from router package
CHANGE core tp use toId from router package
CHANGE client-api to use toId from router package
CHANGE storyshots-puppeteer to use toId from router package
  • Loading branch information...
ndelangen committed Feb 19, 2019
1 parent eb72c1c commit 54faca3793338cb521c8b1aaf5801c597f037cb8
@@ -21,7 +21,7 @@
"prepare": "node ../../../scripts/prepare.js"
},
"dependencies": {
"@storybook/core": "5.0.0-beta.3",
"@storybook/router": "5.0.0-beta.3",
"@storybook/node-logger": "5.0.0-beta.3",
"core-js": "^2.6.2",
"jest-image-snapshot": "^2.6.0",
@@ -1,4 +1,4 @@
import { toId } from '@storybook/core/client';
import { toId } from '@storybook/router/utils';

import { URL } from 'url';

@@ -24,6 +24,7 @@
"@storybook/addons": "5.0.0-beta.3",
"@storybook/components": "5.0.0-beta.3",
"@storybook/theming": "5.0.0-beta.3",
"@storybook/router": "5.0.0-beta.3",
"core-js": "^2.6.2",
"estraverse": "^4.2.0",
"loader-utils": "^1.2.1",
@@ -1,7 +1,8 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { styled } from '@storybook/theming';
import { Link, SyntaxHighlighter } from '@storybook/components';
import { Link } from '@storybook/router';
import { SyntaxHighlighter } from '@storybook/components';

import { createElement } from 'react-syntax-highlighter';
import { EVENT_ID } from './events';
@@ -73,14 +74,6 @@ export default class StoryPanel extends Component {
});
};

clickOnStory = (kind, story) => {
const { api } = this.props;

if (kind && story) {
api.selectStory(kind, story);
}
};

createPart = (rows, stylesheet, useInlineStyles) =>
rows.map((node, i) =>
createElement({
@@ -91,7 +84,7 @@ export default class StoryPanel extends Component {
})
);

createStoryPart = (rows, stylesheet, useInlineStyles, location, kindStory) => {
createStoryPart = (rows, stylesheet, useInlineStyles, location, id) => {
const { currentLocation } = this.state;
const first = location.startLoc.line - 1;
const last = location.endLoc.line;
@@ -108,15 +101,8 @@ export default class StoryPanel extends Component {
);
}

const [selectedKind, selectedStory] = kindStory.split('@');
const url = `/?selectedKind=${selectedKind}&selectedStory=${selectedStory}`;

return (
<StyledStoryLink
href={url}
key={storyKey}
onClick={() => this.clickOnStory(selectedKind, selectedStory)}
>
<StyledStoryLink to={`/story/${id}`} key={storyKey}>
{story}
</StyledStoryLink>
);
@@ -252,7 +252,7 @@ storiesOf('Addons|Info.GitHub issues', module).add(

exports[`inject-decorator positive - angular calculates "adds" map 1`] = `
Object {
"Custom|ng-content@Default": Object {
"custom-ng-content--default": Object {
"endLoc": Object {
"col": 2,
"line": 17,
@@ -284,20 +284,7 @@ storiesOf('Custom|ng-content', module).addDecorator(withStorySource(__STORY__, _
"
`;

exports[`inject-decorator positive - flow calculates "adds" map 1`] = `
Object {
"@Flow Class": Object {
"endLoc": Object {
"col": 70,
"line": 35,
},
"startLoc": Object {
"col": 12,
"line": 35,
},
},
}
`;
exports[`inject-decorator positive - flow calculates "adds" map 1`] = `Object {}`;

exports[`inject-decorator positive - flow injects stories decorator after the all "storiesOf" functions 1`] = `
"// @flow
@@ -340,7 +327,7 @@ stories.add('Flow Class', withInfo('Lorum Ipsum Nem')(() => <Table />));

exports[`inject-decorator positive - ts calculates "adds" map 1`] = `
Object {
"ngrx|Store@With component": Object {
"ngrx-store--with-component": Object {
"endLoc": Object {
"col": 3,
"line": 32,
@@ -390,7 +377,7 @@ storiesOf('ngrx|Store', module).addDecorator(withStorySource(__STORY__, __ADDS_M

exports[`inject-decorator positive calculates "adds" map 1`] = `
Object {
"Addons|Info.Decorator@Use Info as story decorator": Object {
"addons-info-decorator--use-info-as-story-decorator": Object {
"endLoc": Object {
"col": 73,
"line": 137,
@@ -400,7 +387,7 @@ Object {
"line": 137,
},
},
"Addons|Info.GitHub issues@#1814": Object {
"addons-info-github-issues--1814": Object {
"endLoc": Object {
"col": 4,
"line": 152,
@@ -410,7 +397,7 @@ Object {
"line": 146,
},
},
"Addons|Info.Markdown@Displays Markdown in description": Object {
"addons-info-markdown--displays-markdown-in-description": Object {
"endLoc": Object {
"col": 96,
"line": 44,
@@ -420,17 +407,7 @@ Object {
"line": 43,
},
},
"Addons|Info.Options.TableComponent@Use a custom component for the table": Object {
"endLoc": Object {
"col": 41,
"line": 130,
},
"startLoc": Object {
"col": 2,
"line": 127,
},
},
"Addons|Info.Options.header@Shows or hides Info Addon header": Object {
"addons-info-options-header--shows-or-hides-info-addon-header": Object {
"endLoc": Object {
"col": 41,
"line": 60,
@@ -440,7 +417,7 @@ Object {
"line": 56,
},
},
"Addons|Info.Options.inline@Inlines component inside story": Object {
"addons-info-options-inline--inlines-component-inside-story": Object {
"endLoc": Object {
"col": 41,
"line": 52,
@@ -450,7 +427,7 @@ Object {
"line": 48,
},
},
"Addons|Info.Options.propTables@Shows additional component prop tables": Object {
"addons-info-options-proptables--shows-additional-component-prop-tables": Object {
"endLoc": Object {
"col": 41,
"line": 76,
@@ -460,7 +437,7 @@ Object {
"line": 72,
},
},
"Addons|Info.Options.propTablesExclude@Exclude component from prop tables": Object {
"addons-info-options-proptablesexclude--exclude-component-from-prop-tables": Object {
"endLoc": Object {
"col": 4,
"line": 89,
@@ -470,7 +447,7 @@ Object {
"line": 80,
},
},
"Addons|Info.Options.source@Shows or hides Info Addon source": Object {
"addons-info-options-source--shows-or-hides-info-addon-source": Object {
"endLoc": Object {
"col": 41,
"line": 68,
@@ -480,7 +457,7 @@ Object {
"line": 64,
},
},
"Addons|Info.Options.styles@Extend info styles with an object": Object {
"addons-info-options-styles--extend-info-styles-with-an-object": Object {
"endLoc": Object {
"col": 43,
"line": 108,
@@ -490,7 +467,7 @@ Object {
"line": 94,
},
},
"Addons|Info.Options.styles@Full control over styles using a function": Object {
"addons-info-options-styles--full-control-over-styles-using-a-function": Object {
"endLoc": Object {
"col": 43,
"line": 123,
@@ -500,34 +477,44 @@ Object {
"line": 111,
},
},
"Addons|Info.React Docgen@Comments from Flow declarations": Object {
"addons-info-options-tablecomponent--use-a-custom-component-for-the-table": Object {
"endLoc": Object {
"col": 85,
"line": 22,
"col": 41,
"line": 130,
},
"startLoc": Object {
"col": 2,
"line": 127,
},
},
"addons-info-react-docgen--comments-from-component-declaration": Object {
"endLoc": Object {
"col": 70,
"line": 28,
},
"startLoc": Object {
"col": 4,
"line": 19,
"line": 25,
},
},
"Addons|Info.React Docgen@Comments from PropType declarations": Object {
"addons-info-react-docgen--comments-from-flow-declarations": Object {
"endLoc": Object {
"col": 79,
"line": 16,
"col": 85,
"line": 22,
},
"startLoc": Object {
"col": 4,
"line": 13,
"line": 19,
},
},
"Addons|Info.React Docgen@Comments from component declaration": Object {
"addons-info-react-docgen--comments-from-proptype-declarations": Object {
"endLoc": Object {
"col": 70,
"line": 28,
"col": 79,
"line": 16,
},
"startLoc": Object {
"col": 4,
"line": 25,
"line": 13,
},
},
}
@@ -1,3 +1,5 @@
const { toId } = require('@storybook/router/utils');

const STORIES_OF = 'storiesOf';

function pushParts(source, parts, from, to) {
@@ -79,20 +81,22 @@ export function handleADD(node, parent, adds) {
}

const kind = findRelatedKind(node.object) || '';
const key = `${kind}@${storyName.value}`;

// eslint-disable-next-line no-param-reassign
adds[key] = {
// Debug: code: source.slice(storyName.start, lastArg.end),
startLoc: {
col: storyName.loc.start.column,
line: storyName.loc.start.line,
},
endLoc: {
col: lastArg.loc.end.column,
line: lastArg.loc.end.line,
},
};
if (kind && storyName.value) {
const key = toId(kind, storyName.value);

// eslint-disable-next-line no-param-reassign
adds[key] = {
// Debug: code: source.slice(storyName.start, lastArg.end),
startLoc: {
col: storyName.loc.start.column,
line: storyName.loc.start.line,
},
endLoc: {
col: lastArg.loc.end.column,
line: lastArg.loc.end.line,
},
};
}
}

export function handleSTORYOF(node, parts, source, lastIndex) {
@@ -1,9 +1,7 @@
import addons from '@storybook/addons';
import { EVENT_ID } from './events';

function getLocation(context, locationsMap) {
return locationsMap[`${context.kind}@${context.name}`] || locationsMap[`@${context.name}`];
}
const getLocation = (context, locationsMap) => locationsMap[context.id];

function setStorySource(context, source, locationsMap) {
const channel = addons.getChannel();
@@ -22,6 +22,7 @@
"@storybook/addons": "5.0.0-beta.3",
"@storybook/client-logger": "5.0.0-beta.3",
"@storybook/core-events": "5.0.0-beta.3",
"@storybook/router": "5.0.0-beta.3",
"common-tags": "^1.8.0",
"eventemitter3": "^3.1.0",
"global": "^4.3.2",
@@ -4,12 +4,12 @@ import isPlainObject from 'is-plain-object';
import { logger } from '@storybook/client-logger';
import addons from '@storybook/addons';
import Events from '@storybook/core-events';
import { toId } from '@storybook/router/utils';
import memoize from 'memoizerific';
import mergeWith from 'lodash.mergewith';
import isEqual from 'lodash.isequal';

import subscriptionsStore from './subscriptions_store';
import toId from './id';

// merge with concatenating arrays, but no duplicates
const merge = (a, b) =>
@@ -57,7 +57,9 @@ const metaSubscription = () => {
};

const withSubscriptionTracking = storyFn => {
if (!addons.hasChannel()) return storyFn();
if (!addons.hasChannel()) {
return storyFn();
}
subscriptionsStore.markAllAsUnused();
subscriptionsStore.register(metaSubscription);
const result = storyFn();

This file was deleted.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 54faca3

Please sign in to comment.
You can’t perform that action at this time.