@storybook/addon-links 7.0.0-alpha.2 → 7.0.0-alpha.5
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/react/components/RoutedLink.js +4 -1
- package/dist/cjs/react/components/link.js +18 -5
- package/dist/cjs/utils.js +14 -4
- package/dist/esm/react/components/RoutedLink.js +4 -1
- package/dist/esm/react/components/link.js +18 -5
- package/dist/esm/utils.js +14 -4
- package/dist/types/react/components/link.d.ts +2 -2
- package/dist/types/utils.d.ts +1 -1
- package/package.json +6 -7
|
@@ -45,14 +45,27 @@ class LinkTo extends _react.PureComponent {
|
|
|
45
45
|
kind,
|
|
46
46
|
story
|
|
47
47
|
} = this.props;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
href
|
|
51
|
-
|
|
48
|
+
|
|
49
|
+
if (kind && story) {
|
|
50
|
+
const href = await (0, _utils.hrefTo)(kind, story);
|
|
51
|
+
this.setState({
|
|
52
|
+
href
|
|
53
|
+
});
|
|
54
|
+
}
|
|
52
55
|
};
|
|
53
56
|
|
|
54
57
|
this.handleClick = () => {
|
|
55
|
-
|
|
58
|
+
const {
|
|
59
|
+
kind,
|
|
60
|
+
story
|
|
61
|
+
} = this.props;
|
|
62
|
+
|
|
63
|
+
if (kind && story) {
|
|
64
|
+
(0, _utils.navigate)({
|
|
65
|
+
kind,
|
|
66
|
+
story
|
|
67
|
+
});
|
|
68
|
+
}
|
|
56
69
|
};
|
|
57
70
|
}
|
|
58
71
|
|
package/dist/cjs/utils.js
CHANGED
|
@@ -43,8 +43,10 @@ const hrefTo = (title, name) => {
|
|
|
43
43
|
const {
|
|
44
44
|
location
|
|
45
45
|
} = document;
|
|
46
|
-
const query = parseQuery(location.search);
|
|
47
|
-
|
|
46
|
+
const query = parseQuery(location.search); // @ts-ignore
|
|
47
|
+
|
|
48
|
+
const existingId = [].concat(query.id)[0]; // @ts-ignore
|
|
49
|
+
|
|
48
50
|
const titleToLink = title || existingId.split('--', 2)[0];
|
|
49
51
|
const id = (0, _csf.toId)(titleToLink, name);
|
|
50
52
|
const url = `${location.origin + location.pathname}?${Object.entries(Object.assign({}, query, {
|
|
@@ -61,17 +63,25 @@ const valueOrCall = args => value => typeof value === 'function' ? value(...args
|
|
|
61
63
|
const linkTo = (idOrTitle, nameInput) => (...args) => {
|
|
62
64
|
const resolver = valueOrCall(args);
|
|
63
65
|
const title = resolver(idOrTitle);
|
|
64
|
-
const name = resolver(nameInput);
|
|
66
|
+
const name = nameInput ? resolver(nameInput) : false;
|
|
65
67
|
|
|
66
68
|
if (title !== null && title !== void 0 && title.match(/--/) && !name) {
|
|
67
69
|
navigate({
|
|
68
70
|
storyId: title
|
|
69
71
|
});
|
|
70
|
-
} else {
|
|
72
|
+
} else if (name && title) {
|
|
71
73
|
navigate({
|
|
72
74
|
kind: title,
|
|
73
75
|
story: name
|
|
74
76
|
});
|
|
77
|
+
} else if (title) {
|
|
78
|
+
navigate({
|
|
79
|
+
kind: title
|
|
80
|
+
});
|
|
81
|
+
} else if (name) {
|
|
82
|
+
navigate({
|
|
83
|
+
story: name
|
|
84
|
+
});
|
|
75
85
|
}
|
|
76
86
|
};
|
|
77
87
|
|
|
@@ -32,14 +32,27 @@ export default class LinkTo extends PureComponent {
|
|
|
32
32
|
kind,
|
|
33
33
|
story
|
|
34
34
|
} = this.props;
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
href
|
|
38
|
-
|
|
35
|
+
|
|
36
|
+
if (kind && story) {
|
|
37
|
+
const href = await hrefTo(kind, story);
|
|
38
|
+
this.setState({
|
|
39
|
+
href
|
|
40
|
+
});
|
|
41
|
+
}
|
|
39
42
|
};
|
|
40
43
|
|
|
41
44
|
this.handleClick = () => {
|
|
42
|
-
|
|
45
|
+
const {
|
|
46
|
+
kind,
|
|
47
|
+
story
|
|
48
|
+
} = this.props;
|
|
49
|
+
|
|
50
|
+
if (kind && story) {
|
|
51
|
+
navigate({
|
|
52
|
+
kind,
|
|
53
|
+
story
|
|
54
|
+
});
|
|
55
|
+
}
|
|
43
56
|
};
|
|
44
57
|
}
|
|
45
58
|
|
package/dist/esm/utils.js
CHANGED
|
@@ -26,8 +26,10 @@ export const hrefTo = (title, name) => {
|
|
|
26
26
|
const {
|
|
27
27
|
location
|
|
28
28
|
} = document;
|
|
29
|
-
const query = parseQuery(location.search);
|
|
30
|
-
|
|
29
|
+
const query = parseQuery(location.search); // @ts-ignore
|
|
30
|
+
|
|
31
|
+
const existingId = [].concat(query.id)[0]; // @ts-ignore
|
|
32
|
+
|
|
31
33
|
const titleToLink = title || existingId.split('--', 2)[0];
|
|
32
34
|
const id = toId(titleToLink, name);
|
|
33
35
|
const url = `${location.origin + location.pathname}?${Object.entries(Object.assign({}, query, {
|
|
@@ -42,17 +44,25 @@ const valueOrCall = args => value => typeof value === 'function' ? value(...args
|
|
|
42
44
|
export const linkTo = (idOrTitle, nameInput) => (...args) => {
|
|
43
45
|
const resolver = valueOrCall(args);
|
|
44
46
|
const title = resolver(idOrTitle);
|
|
45
|
-
const name = resolver(nameInput);
|
|
47
|
+
const name = nameInput ? resolver(nameInput) : false;
|
|
46
48
|
|
|
47
49
|
if (title?.match(/--/) && !name) {
|
|
48
50
|
navigate({
|
|
49
51
|
storyId: title
|
|
50
52
|
});
|
|
51
|
-
} else {
|
|
53
|
+
} else if (name && title) {
|
|
52
54
|
navigate({
|
|
53
55
|
kind: title,
|
|
54
56
|
story: name
|
|
55
57
|
});
|
|
58
|
+
} else if (title) {
|
|
59
|
+
navigate({
|
|
60
|
+
kind: title
|
|
61
|
+
});
|
|
62
|
+
} else if (name) {
|
|
63
|
+
navigate({
|
|
64
|
+
story: name
|
|
65
|
+
});
|
|
56
66
|
}
|
|
57
67
|
};
|
|
58
68
|
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ interface ParamsCombo {
|
|
|
8
8
|
}
|
|
9
9
|
export declare const navigate: (params: ParamsId | ParamsCombo) => void;
|
|
10
10
|
export declare const hrefTo: (title: ComponentTitle, name: StoryName) => Promise<string>;
|
|
11
|
-
export declare const linkTo: (idOrTitle: string, nameInput?: string | ((...args: any[]) => string)) => (...args: any[]) => void;
|
|
11
|
+
export declare const linkTo: (idOrTitle: string, nameInput?: string | ((...args: any[]) => string) | undefined) => (...args: any[]) => void;
|
|
12
12
|
export declare const withLinks: (...args: any) => any;
|
|
13
13
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/addon-links",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.5",
|
|
4
4
|
"description": "Link stories together to build demos and prototypes with your UI components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"addon",
|
|
@@ -34,15 +34,14 @@
|
|
|
34
34
|
"prepare": "node ../../scripts/prepare.js"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@storybook/addons": "7.0.0-alpha.
|
|
38
|
-
"@storybook/client-logger": "7.0.0-alpha.
|
|
39
|
-
"@storybook/core-events": "7.0.0-alpha.
|
|
37
|
+
"@storybook/addons": "7.0.0-alpha.5",
|
|
38
|
+
"@storybook/client-logger": "7.0.0-alpha.5",
|
|
39
|
+
"@storybook/core-events": "7.0.0-alpha.5",
|
|
40
40
|
"@storybook/csf": "0.0.2--canary.4566f4d.1",
|
|
41
|
-
"@storybook/router": "7.0.0-alpha.
|
|
41
|
+
"@storybook/router": "7.0.0-alpha.5",
|
|
42
42
|
"core-js": "^3.8.2",
|
|
43
43
|
"global": "^4.4.0",
|
|
44
44
|
"prop-types": "^15.7.2",
|
|
45
|
-
"regenerator-runtime": "^0.13.7",
|
|
46
45
|
"ts-dedent": "^2.0.0"
|
|
47
46
|
},
|
|
48
47
|
"peerDependencies": {
|
|
@@ -60,7 +59,7 @@
|
|
|
60
59
|
"publishConfig": {
|
|
61
60
|
"access": "public"
|
|
62
61
|
},
|
|
63
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "3dd46982823b34d9f37be917b6247631081feff7",
|
|
64
63
|
"storybook": {
|
|
65
64
|
"displayName": "Links",
|
|
66
65
|
"icon": "https://user-images.githubusercontent.com/263385/101991673-48355c80-3c7c-11eb-9b6e-b627c96a75f6.png",
|