@storybook/addon-links 7.0.0-alpha.2 → 7.0.0-alpha.22
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/chunk-DUAG4ME5.mjs +1 -0
- package/dist/chunk-KSS336ZV.mjs +4 -0
- package/dist/chunk-LYIASPRR.mjs +1 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +4 -0
- package/dist/index.mjs +1 -0
- package/dist/manager.d.ts +1 -0
- package/dist/manager.js +1 -0
- package/dist/manager.mjs +1 -0
- package/dist/preview.d.ts +3 -0
- package/dist/preview.js +1 -0
- package/dist/preview.mjs +1 -0
- package/dist/{types/react/components/link.d.ts → react/index.d.ts} +6 -4
- package/dist/react/index.js +1 -0
- package/dist/react/index.mjs +1 -0
- package/manager.js +1 -1
- package/package.json +51 -12
- package/preview.js +1 -1
- package/react.js +1 -1
- package/LICENSE +0 -21
- package/dist/cjs/constants.js +0 -16
- package/dist/cjs/index.js +0 -55
- package/dist/cjs/manager.js +0 -21
- package/dist/cjs/preview.js +0 -11
- package/dist/cjs/react/components/RoutedLink.js +0 -50
- package/dist/cjs/react/components/link.js +0 -97
- package/dist/cjs/react/index.js +0 -13
- package/dist/cjs/utils.js +0 -131
- package/dist/esm/constants.js +0 -7
- package/dist/esm/index.js +0 -19
- package/dist/esm/manager.js +0 -12
- package/dist/esm/preview.js +0 -2
- package/dist/esm/react/components/RoutedLink.js +0 -39
- package/dist/esm/react/components/link.js +0 -82
- package/dist/esm/react/index.js +0 -2
- package/dist/esm/utils.js +0 -107
- package/dist/types/constants.d.ts +0 -8
- package/dist/types/index.d.ts +0 -2
- package/dist/types/manager.d.ts +0 -1
- package/dist/types/preview.d.ts +0 -1
- package/dist/types/react/components/RoutedLink.d.ts +0 -3
- package/dist/types/react/index.d.ts +0 -2
- package/dist/types/utils.d.ts +0 -13
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e="storybook/links",o="links",E={NAVIGATE:`${e}/navigate`,REQUEST:`${e}/request`,RECEIVE:`${e}/receive`};export{e as a,o as b,E as c};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{b as l}from"./chunk-DUAG4ME5.mjs";import k from"global";import{addons as f,makeDecorator as C}from"@storybook/addons";import{STORY_CHANGED as T,SELECT_STORY as h}from"@storybook/core-events";import{toId as u}from"@storybook/csf";var{document:c,HTMLElement:L}=k;function E(t){let o={},r=(t[0]==="?"?t.substring(1):t).split("&").filter(Boolean);for(let n=0;n<r.length;n++){let e=r[n].split("=");o[decodeURIComponent(e[0])]=decodeURIComponent(e[1]||"")}return o}var i=t=>f.getChannel().emit(h,t),O=(t,o)=>new Promise(r=>{let{location:n}=c,e=E(n.search),s=[].concat(e.id)[0],d=t||s.split("--",2)[0],g=u(d,o),y=`${n.origin+n.pathname}?${Object.entries({...e,id:g}).map(m=>`${m[0]}=${m[1]}`).join("&")}`;r(y)}),I=t=>o=>typeof o=="function"?o(...t):o,$=(t,o)=>(...r)=>{let n=I(r),e=n(t),s=o?n(o):!1;e?.match(/--/)&&!s?i({storyId:e}):s&&e?i({kind:e,story:s}):e?i({kind:e}):s&&i({story:s})},p=t=>{let{target:o}=t;if(!(o instanceof L))return;let r=o,{sbKind:n,sbStory:e}=r.dataset;(n||e)&&(t.preventDefault(),i({kind:n,story:e}))},a=!1,b=()=>{a||(a=!0,c.addEventListener("click",p))},P=()=>{a&&(a=!1,c.removeEventListener("click",p))},A=C({name:"withLinks",parameterName:l,wrapper:(t,o)=>(b(),f.getChannel().once(T,P),t(o))});export{i as a,O as b,$ as c,A as d};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ComponentTitle, StoryName, StoryId } from '@storybook/csf';
|
|
2
|
+
|
|
3
|
+
interface ParamsId {
|
|
4
|
+
storyId: StoryId;
|
|
5
|
+
}
|
|
6
|
+
interface ParamsCombo {
|
|
7
|
+
kind?: ComponentTitle;
|
|
8
|
+
story?: StoryName;
|
|
9
|
+
}
|
|
10
|
+
declare const navigate: (params: ParamsId | ParamsCombo) => void;
|
|
11
|
+
declare const hrefTo: (title: ComponentTitle, name: StoryName) => Promise<string>;
|
|
12
|
+
declare const linkTo: (idOrTitle: string, nameInput?: string | ((...args: any[]) => string) | undefined) => (...args: any[]) => void;
|
|
13
|
+
declare const withLinks: (...args: any) => any;
|
|
14
|
+
|
|
15
|
+
declare function LinkTo(): null;
|
|
16
|
+
|
|
17
|
+
export { LinkTo, hrefTo, linkTo, navigate, withLinks };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
"use strict";var R=Object.create;var c=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var P=Object.getOwnPropertyNames;var S=Object.getPrototypeOf,N=Object.prototype.hasOwnProperty;var $=(t,o)=>{for(var n in o)c(t,n,{get:o[n],enumerable:!0})},k=(t,o,n,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let e of P(o))!N.call(t,e)&&e!==n&&c(t,e,{get:()=>o[e],enumerable:!(r=A(o,e))||r.enumerable});return t};var D=(t,o,n)=>(n=t!=null?R(S(t)):{},k(o||!t||!t.__esModule?c(n,"default",{value:t,enumerable:!0}):n,t)),w=t=>k(c({},"__esModule",{value:!0}),t);var U={};$(U,{LinkTo:()=>K,hrefTo:()=>T,linkTo:()=>h,navigate:()=>i,withLinks:()=>L});module.exports=w(U);var I=require("ts-dedent");var u=D(require("global")),a=require("@storybook/addons"),m=require("@storybook/core-events"),y=require("@storybook/csf");var d="storybook/links",g="links",G={NAVIGATE:`${d}/navigate`,REQUEST:`${d}/request`,RECEIVE:`${d}/receive`};var{document:f,HTMLElement:O}=u.default;function _(t){let o={},n=(t[0]==="?"?t.substring(1):t).split("&").filter(Boolean);for(let r=0;r<n.length;r++){let e=n[r].split("=");o[decodeURIComponent(e[0])]=decodeURIComponent(e[1]||"")}return o}var i=t=>a.addons.getChannel().emit(m.SELECT_STORY,t),T=(t,o)=>new Promise(n=>{let{location:r}=f,e=_(r.search),s=[].concat(e.id)[0],b=t||s.split("--",2)[0],v=(0,y.toId)(b,o),x=`${r.origin+r.pathname}?${Object.entries({...e,id:v}).map(p=>`${p[0]}=${p[1]}`).join("&")}`;n(x)}),M=t=>o=>typeof o=="function"?o(...t):o,h=(t,o)=>(...n)=>{let r=M(n),e=r(t),s=o?r(o):!1;(e==null?void 0:e.match(/--/))&&!s?i({storyId:e}):s&&e?i({kind:e,story:s}):e?i({kind:e}):s&&i({story:s})},E=t=>{let{target:o}=t;if(!(o instanceof O))return;let n=o,{sbKind:r,sbStory:e}=n.dataset;(r||e)&&(t.preventDefault(),i({kind:r,story:e}))},l=!1,Y=()=>{l||(l=!0,f.addEventListener("click",E))},H=()=>{l&&(l=!1,f.removeEventListener("click",E))},L=(0,a.makeDecorator)({name:"withLinks",parameterName:g,wrapper:(t,o)=>(Y(),a.addons.getChannel().once(m.STORY_CHANGED,H),t(o))});var C=!1;function K(){return C||(console.error(I.dedent`
|
|
2
|
+
LinkTo has moved to addon-links/react:
|
|
3
|
+
import LinkTo from '@storybook/addon-links/react';
|
|
4
|
+
`),C=!0),null}module&&module.hot&&module.hot.decline&&module.hot.decline();0&&(module.exports={LinkTo,hrefTo,linkTo,navigate,withLinks});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as e}from"./chunk-KSS336ZV.mjs";import{a,b,c,d}from"./chunk-LYIASPRR.mjs";import"./chunk-DUAG4ME5.mjs";export{e as LinkTo,b as hrefTo,c as linkTo,a as navigate,d as withLinks};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
package/dist/manager.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var t=require("@storybook/addons");var e="storybook/links";var o={NAVIGATE:`${e}/navigate`,REQUEST:`${e}/request`,RECEIVE:`${e}/receive`};t.addons.register(e,n=>{t.addons.getChannel().on(o.REQUEST,({kind:E,name:r})=>{let s=n.storyId(E,r);n.emit(o.RECEIVE,s)})});
|
package/dist/manager.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as t,c as n}from"./chunk-DUAG4ME5.mjs";import{addons as e}from"@storybook/addons";e.register(t,o=>{e.getChannel().on(n.REQUEST,({kind:r,name:E})=>{let m=o.storyId(r,E);o.emit(n.RECEIVE,m)})});
|
package/dist/preview.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var y=Object.create;var i=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var C=(t,o)=>{for(var e in o)i(t,e,{get:o[e],enumerable:!0})},d=(t,o,e,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of T(o))!L.call(t,n)&&n!==e&&i(t,n,{get:()=>o[n],enumerable:!(r=h(o,n))||r.enumerable});return t};var I=(t,o,e)=>(e=t!=null?y(E(t)):{},d(o||!t||!t.__esModule?i(e,"default",{value:t,enumerable:!0}):e,t)),x=t=>d(i({},"__esModule",{value:!0}),t);var N={};C(N,{decorators:()=>S});module.exports=x(N);var P=require("ts-dedent");var p=I(require("global")),s=require("@storybook/addons"),c=require("@storybook/core-events"),b=require("@storybook/csf");var l="storybook/links",f="links",w={NAVIGATE:`${l}/navigate`,REQUEST:`${l}/request`,RECEIVE:`${l}/receive`};var{document:k,HTMLElement:v}=p.default;var g=t=>s.addons.getChannel().emit(c.SELECT_STORY,t);var u=t=>{let{target:o}=t;if(!(o instanceof v))return;let e=o,{sbKind:r,sbStory:n}=e.dataset;(r||n)&&(t.preventDefault(),g({kind:r,story:n}))},a=!1,R=()=>{a||(a=!0,k.addEventListener("click",u))},A=()=>{a&&(a=!1,k.removeEventListener("click",u))},m=(0,s.makeDecorator)({name:"withLinks",parameterName:f,wrapper:(t,o)=>(R(),s.addons.getChannel().once(c.STORY_CHANGED,A),t(o))});module&&module.hot&&module.hot.decline&&module.hot.decline();var S=[m];0&&(module.exports={decorators});
|
package/dist/preview.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import"./chunk-KSS336ZV.mjs";import{d as o}from"./chunk-LYIASPRR.mjs";import"./chunk-DUAG4ME5.mjs";var i=[o];export{i as decorators};
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { PureComponent, ReactNode } from 'react';
|
|
2
|
+
|
|
2
3
|
interface Props {
|
|
3
|
-
kind: string;
|
|
4
|
-
story: string;
|
|
4
|
+
kind: string | null;
|
|
5
|
+
story: string | null;
|
|
5
6
|
children: ReactNode;
|
|
6
7
|
}
|
|
7
8
|
interface State {
|
|
8
9
|
href: string;
|
|
9
10
|
}
|
|
10
|
-
|
|
11
|
+
declare class LinkTo extends PureComponent<Props, State> {
|
|
11
12
|
static defaultProps: Props;
|
|
12
13
|
state: State;
|
|
13
14
|
componentDidMount(): void;
|
|
@@ -16,4 +17,5 @@ export default class LinkTo extends PureComponent<Props, State> {
|
|
|
16
17
|
handleClick: () => void;
|
|
17
18
|
render(): JSX.Element;
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
|
|
21
|
+
export { LinkTo as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var S=Object.create;var a=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var b=Object.getPrototypeOf,A=Object.prototype.hasOwnProperty;var M=(t,n)=>{for(var e in n)a(t,e,{get:n[e],enumerable:!0})},g=(t,n,e,o)=>{if(n&&typeof n=="object"||typeof n=="function")for(let r of R(n))!A.call(t,r)&&r!==e&&a(t,r,{get:()=>n[r],enumerable:!(o=x(n,r))||o.enumerable});return t};var E=(t,n,e)=>(e=t!=null?S(b(t)):{},g(n||!t||!t.__esModule?a(e,"default",{value:t,enumerable:!0}):e,t)),N=t=>g(a({},"__esModule",{value:!0}),t);var Y={};M(Y,{default:()=>U});module.exports=N(Y);var f=E(require("react"));var T=E(require("global")),i=require("@storybook/addons"),l=require("@storybook/core-events"),P=require("@storybook/csf");var h="storybook/links",C="links",B={NAVIGATE:`${h}/navigate`,REQUEST:`${h}/request`,RECEIVE:`${h}/receive`};var{document:y,HTMLElement:D}=T.default;function H(t){let n={},e=(t[0]==="?"?t.substring(1):t).split("&").filter(Boolean);for(let o=0;o<e.length;o++){let r=e[o].split("=");n[decodeURIComponent(r[0])]=decodeURIComponent(r[1]||"")}return n}var u=t=>i.addons.getChannel().emit(l.SELECT_STORY,t),L=(t,n)=>new Promise(e=>{let{location:o}=y,r=H(o.search),d=[].concat(r.id)[0],p=t||d.split("--",2)[0],m=(0,P.toId)(p,n),I=`${o.origin+o.pathname}?${Object.entries({...r,id:m}).map(k=>`${k[0]}=${k[1]}`).join("&")}`;e(I)});var v=t=>{let{target:n}=t;if(!(n instanceof D))return;let e=n,{sbKind:o,sbStory:r}=e.dataset;(o||r)&&(t.preventDefault(),u({kind:o,story:r}))},c=!1,K=()=>{c||(c=!0,y.addEventListener("click",v))},_=()=>{c&&(c=!1,y.removeEventListener("click",v))},V=(0,i.makeDecorator)({name:"withLinks",parameterName:C,wrapper:(t,n)=>(K(),i.addons.getChannel().once(l.STORY_CHANGED,_),t(n))});var $=0,O=t=>t.button===$&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey,w=(t,n=e=>{})=>{O(t)&&(t.preventDefault(),n(t))},s=class extends f.PureComponent{constructor(){super(...arguments);this.state={href:"/"};this.updateHref=async()=>{let{kind:e,story:o}=this.props;if(e&&o){let r=await L(e,o);this.setState({href:r})}};this.handleClick=()=>{let{kind:e,story:o}=this.props;e&&o&&u({kind:e,story:o})}}componentDidMount(){this.updateHref()}componentDidUpdate(e){let{kind:o,story:r}=this.props;(e.kind!==o||e.story!==r)&&this.updateHref()}render(){let{kind:e,story:o,children:r,...d}=this.props,{href:p}=this.state;return f.default.createElement("a",{href:p,onClick:m=>w(m,this.handleClick),...d},r)}};s.defaultProps={kind:null,story:null,children:void 0};var U=s;0&&(module.exports={});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{a as i,b as a}from"../chunk-LYIASPRR.mjs";import"../chunk-DUAG4ME5.mjs";import p,{PureComponent as h}from"react";var u=0,y=t=>t.button===u&&!t.altKey&&!t.ctrlKey&&!t.metaKey&&!t.shiftKey,m=(t,o=e=>{})=>{y(t)&&(t.preventDefault(),o(t))},s=class extends h{constructor(){super(...arguments);this.state={href:"/"};this.updateHref=async()=>{let{kind:e,story:n}=this.props;if(e&&n){let r=await a(e,n);this.setState({href:r})}};this.handleClick=()=>{let{kind:e,story:n}=this.props;e&&n&&i({kind:e,story:n})}}componentDidMount(){this.updateHref()}componentDidUpdate(e){let{kind:n,story:r}=this.props;(e.kind!==n||e.story!==r)&&this.updateHref()}render(){let{kind:e,story:n,children:r,...c}=this.props,{href:l}=this.state;return p.createElement("a",{href:l,onClick:d=>m(d,this.handleClick),...c},r)}};s.defaultProps={kind:null,story:null,children:void 0};var T=s;export{T as default};
|
package/manager.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import './dist/
|
|
1
|
+
import './dist/manager';
|
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.22",
|
|
4
4
|
"description": "Link stories together to build demos and prototypes with your UI components",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"addon",
|
|
@@ -21,9 +21,37 @@
|
|
|
21
21
|
"url": "https://opencollective.com/storybook"
|
|
22
22
|
},
|
|
23
23
|
"license": "MIT",
|
|
24
|
-
"
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
"exports": {
|
|
25
|
+
".": {
|
|
26
|
+
"require": "./dist/index.js",
|
|
27
|
+
"import": "./dist/index.mjs",
|
|
28
|
+
"types": "./dist/index.d.ts"
|
|
29
|
+
},
|
|
30
|
+
"./manager": {
|
|
31
|
+
"require": "./dist/manager.js",
|
|
32
|
+
"import": "./dist/manager.mjs",
|
|
33
|
+
"types": "./dist/manager.d.ts"
|
|
34
|
+
},
|
|
35
|
+
"./preview": {
|
|
36
|
+
"require": "./dist/preview.js",
|
|
37
|
+
"import": "./dist/preview.mjs",
|
|
38
|
+
"types": "./dist/preview.d.ts"
|
|
39
|
+
},
|
|
40
|
+
"./react": {
|
|
41
|
+
"require": "./dist/react/index.js",
|
|
42
|
+
"import": "./dist/react/index.mjs",
|
|
43
|
+
"types": "./dist/react.d.ts"
|
|
44
|
+
},
|
|
45
|
+
"./register.js": {
|
|
46
|
+
"require": "./dist/manager.js",
|
|
47
|
+
"import": "./dist/manager.mjs",
|
|
48
|
+
"types": "./dist/manager.d.ts"
|
|
49
|
+
},
|
|
50
|
+
"./package.json": "./package.json"
|
|
51
|
+
},
|
|
52
|
+
"main": "dist/index.js",
|
|
53
|
+
"module": "dist/index.mjs",
|
|
54
|
+
"types": "dist/index.d.ts",
|
|
27
55
|
"files": [
|
|
28
56
|
"dist/**/*",
|
|
29
57
|
"README.md",
|
|
@@ -31,20 +59,23 @@
|
|
|
31
59
|
"*.d.ts"
|
|
32
60
|
],
|
|
33
61
|
"scripts": {
|
|
34
|
-
"
|
|
62
|
+
"check": "tsc --noEmit",
|
|
63
|
+
"prepare": "../../../scripts/prepare/bundle.ts"
|
|
35
64
|
},
|
|
36
65
|
"dependencies": {
|
|
37
|
-
"@storybook/addons": "7.0.0-alpha.
|
|
38
|
-
"@storybook/client-logger": "7.0.0-alpha.
|
|
39
|
-
"@storybook/core-events": "7.0.0-alpha.
|
|
40
|
-
"@storybook/csf": "0.0.2--canary.
|
|
41
|
-
"@storybook/router": "7.0.0-alpha.
|
|
66
|
+
"@storybook/addons": "7.0.0-alpha.22",
|
|
67
|
+
"@storybook/client-logger": "7.0.0-alpha.22",
|
|
68
|
+
"@storybook/core-events": "7.0.0-alpha.22",
|
|
69
|
+
"@storybook/csf": "0.0.2--canary.0899bb7.0",
|
|
70
|
+
"@storybook/router": "7.0.0-alpha.22",
|
|
42
71
|
"core-js": "^3.8.2",
|
|
43
72
|
"global": "^4.4.0",
|
|
44
73
|
"prop-types": "^15.7.2",
|
|
45
|
-
"regenerator-runtime": "^0.13.7",
|
|
46
74
|
"ts-dedent": "^2.0.0"
|
|
47
75
|
},
|
|
76
|
+
"devDependencies": {
|
|
77
|
+
"typescript": "~4.6.3"
|
|
78
|
+
},
|
|
48
79
|
"peerDependencies": {
|
|
49
80
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0",
|
|
50
81
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
|
|
@@ -60,7 +91,15 @@
|
|
|
60
91
|
"publishConfig": {
|
|
61
92
|
"access": "public"
|
|
62
93
|
},
|
|
63
|
-
"
|
|
94
|
+
"bundler": {
|
|
95
|
+
"entries": [
|
|
96
|
+
"./src/index.ts",
|
|
97
|
+
"./src/manager.ts",
|
|
98
|
+
"./src/preview.ts",
|
|
99
|
+
"./src/react/index.ts"
|
|
100
|
+
]
|
|
101
|
+
},
|
|
102
|
+
"gitHead": "408cd2770da3f5cfb54843d74dfcf31b6c7e0d58",
|
|
64
103
|
"storybook": {
|
|
65
104
|
"displayName": "Links",
|
|
66
105
|
"icon": "https://user-images.githubusercontent.com/263385/101991673-48355c80-3c7c-11eb-9b6e-b627c96a75f6.png",
|
package/preview.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './dist/
|
|
1
|
+
export * from './dist/preview';
|
package/react.js
CHANGED
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
The MIT License (MIT)
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2017 Kadira Inc. <hello@kadira.io>
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
-
THE SOFTWARE.
|
package/dist/cjs/constants.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = exports.PARAM_KEY = exports.ADDON_ID = void 0;
|
|
7
|
-
const ADDON_ID = 'storybook/links';
|
|
8
|
-
exports.ADDON_ID = ADDON_ID;
|
|
9
|
-
const PARAM_KEY = `links`;
|
|
10
|
-
exports.PARAM_KEY = PARAM_KEY;
|
|
11
|
-
var _default = {
|
|
12
|
-
NAVIGATE: `${ADDON_ID}/navigate`,
|
|
13
|
-
REQUEST: `${ADDON_ID}/request`,
|
|
14
|
-
RECEIVE: `${ADDON_ID}/receive`
|
|
15
|
-
};
|
|
16
|
-
exports.default = _default;
|
package/dist/cjs/index.js
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.LinkTo = LinkTo;
|
|
7
|
-
Object.defineProperty(exports, "hrefTo", {
|
|
8
|
-
enumerable: true,
|
|
9
|
-
get: function () {
|
|
10
|
-
return _utils.hrefTo;
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
Object.defineProperty(exports, "linkTo", {
|
|
14
|
-
enumerable: true,
|
|
15
|
-
get: function () {
|
|
16
|
-
return _utils.linkTo;
|
|
17
|
-
}
|
|
18
|
-
});
|
|
19
|
-
Object.defineProperty(exports, "navigate", {
|
|
20
|
-
enumerable: true,
|
|
21
|
-
get: function () {
|
|
22
|
-
return _utils.navigate;
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
Object.defineProperty(exports, "withLinks", {
|
|
26
|
-
enumerable: true,
|
|
27
|
-
get: function () {
|
|
28
|
-
return _utils.withLinks;
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
var _tsDedent = _interopRequireDefault(require("ts-dedent"));
|
|
33
|
-
|
|
34
|
-
var _utils = require("./utils");
|
|
35
|
-
|
|
36
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
37
|
-
|
|
38
|
-
let hasWarned = false;
|
|
39
|
-
|
|
40
|
-
function LinkTo() {
|
|
41
|
-
if (!hasWarned) {
|
|
42
|
-
// eslint-disable-next-line no-console
|
|
43
|
-
console.error((0, _tsDedent.default)`
|
|
44
|
-
LinkTo has moved to addon-links/react:
|
|
45
|
-
import LinkTo from '@storybook/addon-links/react';
|
|
46
|
-
`);
|
|
47
|
-
hasWarned = true;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return null;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if (module && module.hot && module.hot.decline) {
|
|
54
|
-
module.hot.decline();
|
|
55
|
-
}
|
package/dist/cjs/manager.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _addons = require("@storybook/addons");
|
|
4
|
-
|
|
5
|
-
var _constants = _interopRequireWildcard(require("./constants"));
|
|
6
|
-
|
|
7
|
-
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); }
|
|
8
|
-
|
|
9
|
-
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; }
|
|
10
|
-
|
|
11
|
-
_addons.addons.register(_constants.ADDON_ID, api => {
|
|
12
|
-
const channel = _addons.addons.getChannel();
|
|
13
|
-
|
|
14
|
-
channel.on(_constants.default.REQUEST, ({
|
|
15
|
-
kind,
|
|
16
|
-
name
|
|
17
|
-
}) => {
|
|
18
|
-
const id = api.storyId(kind, name);
|
|
19
|
-
api.emit(_constants.default.RECEIVE, id);
|
|
20
|
-
});
|
|
21
|
-
});
|
package/dist/cjs/preview.js
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
// NOTE: this is a copy of `lib/components/src/navigation/RoutedLink.tsx`.
|
|
13
|
-
// It's duplicated here because that copy has an explicit dependency on
|
|
14
|
-
// React 16.3+, which breaks older versions of React running in the preview.
|
|
15
|
-
// The proper DRY solution is to create a new package that doesn't depend
|
|
16
|
-
// on a specific react version. However, that's a heavy-handed solution for
|
|
17
|
-
// one trivial file.
|
|
18
|
-
const LEFT_BUTTON = 0; // Cmd/Ctrl/Shift/Alt + Click should trigger default browser behaviour. Same applies to non-left clicks
|
|
19
|
-
|
|
20
|
-
const isPlainLeftClick = e => e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
|
|
21
|
-
|
|
22
|
-
const RoutedLink = ({
|
|
23
|
-
href = '#',
|
|
24
|
-
children,
|
|
25
|
-
onClick,
|
|
26
|
-
className,
|
|
27
|
-
style
|
|
28
|
-
}) => {
|
|
29
|
-
const handleClick = e => {
|
|
30
|
-
if (isPlainLeftClick(e)) {
|
|
31
|
-
e.preventDefault();
|
|
32
|
-
onClick(e);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
const props = onClick ? {
|
|
37
|
-
href,
|
|
38
|
-
className,
|
|
39
|
-
style,
|
|
40
|
-
onClick: handleClick
|
|
41
|
-
} : {
|
|
42
|
-
href,
|
|
43
|
-
className,
|
|
44
|
-
style
|
|
45
|
-
};
|
|
46
|
-
return /*#__PURE__*/_react.default.createElement("a", props, children);
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
var _default = RoutedLink;
|
|
50
|
-
exports.default = _default;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
-
|
|
10
|
-
var _utils = require("../../utils");
|
|
11
|
-
|
|
12
|
-
const _excluded = ["kind", "story", "children"];
|
|
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
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
19
|
-
|
|
20
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
21
|
-
|
|
22
|
-
// FIXME: copied from Typography.Link. Code is duplicated to
|
|
23
|
-
// avoid emotion dependency which breaks React 15.x back-compat
|
|
24
|
-
// Cmd/Ctrl/Shift/Alt + Click should trigger default browser behaviour. Same applies to non-left clicks
|
|
25
|
-
const LEFT_BUTTON = 0;
|
|
26
|
-
|
|
27
|
-
const isPlainLeftClick = e => e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
|
|
28
|
-
|
|
29
|
-
const cancelled = (e, cb = _e => {}) => {
|
|
30
|
-
if (isPlainLeftClick(e)) {
|
|
31
|
-
e.preventDefault();
|
|
32
|
-
cb(e);
|
|
33
|
-
}
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
class LinkTo extends _react.PureComponent {
|
|
37
|
-
constructor(...args) {
|
|
38
|
-
super(...args);
|
|
39
|
-
this.state = {
|
|
40
|
-
href: '/'
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
this.updateHref = async () => {
|
|
44
|
-
const {
|
|
45
|
-
kind,
|
|
46
|
-
story
|
|
47
|
-
} = this.props;
|
|
48
|
-
const href = await (0, _utils.hrefTo)(kind, story);
|
|
49
|
-
this.setState({
|
|
50
|
-
href
|
|
51
|
-
});
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
this.handleClick = () => {
|
|
55
|
-
(0, _utils.navigate)(this.props);
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
componentDidMount() {
|
|
60
|
-
this.updateHref();
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
componentDidUpdate(prevProps) {
|
|
64
|
-
const {
|
|
65
|
-
kind,
|
|
66
|
-
story
|
|
67
|
-
} = this.props;
|
|
68
|
-
|
|
69
|
-
if (prevProps.kind !== kind || prevProps.story !== story) {
|
|
70
|
-
this.updateHref();
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
render() {
|
|
75
|
-
const _this$props = this.props,
|
|
76
|
-
{
|
|
77
|
-
children
|
|
78
|
-
} = _this$props,
|
|
79
|
-
rest = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
80
|
-
|
|
81
|
-
const {
|
|
82
|
-
href
|
|
83
|
-
} = this.state;
|
|
84
|
-
return /*#__PURE__*/_react.default.createElement("a", _extends({
|
|
85
|
-
href: href,
|
|
86
|
-
onClick: e => cancelled(e, this.handleClick)
|
|
87
|
-
}, rest), children);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
exports.default = LinkTo;
|
|
93
|
-
LinkTo.defaultProps = {
|
|
94
|
-
kind: null,
|
|
95
|
-
story: null,
|
|
96
|
-
children: undefined
|
|
97
|
-
};
|
package/dist/cjs/react/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _link = _interopRequireDefault(require("./components/link"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
var _default = _link.default;
|
|
13
|
-
exports.default = _default;
|
package/dist/cjs/utils.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.withLinks = exports.navigate = exports.linkTo = exports.hrefTo = void 0;
|
|
7
|
-
|
|
8
|
-
var _global = _interopRequireDefault(require("global"));
|
|
9
|
-
|
|
10
|
-
var _addons = require("@storybook/addons");
|
|
11
|
-
|
|
12
|
-
var _coreEvents = require("@storybook/core-events");
|
|
13
|
-
|
|
14
|
-
var _csf = require("@storybook/csf");
|
|
15
|
-
|
|
16
|
-
var _constants = require("./constants");
|
|
17
|
-
|
|
18
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
-
|
|
20
|
-
const {
|
|
21
|
-
document,
|
|
22
|
-
HTMLElement
|
|
23
|
-
} = _global.default;
|
|
24
|
-
|
|
25
|
-
function parseQuery(queryString) {
|
|
26
|
-
const query = {};
|
|
27
|
-
const pairs = (queryString[0] === '?' ? queryString.substring(1) : queryString).split('&').filter(Boolean); // eslint-disable-next-line no-plusplus
|
|
28
|
-
|
|
29
|
-
for (let i = 0; i < pairs.length; i++) {
|
|
30
|
-
const pair = pairs[i].split('=');
|
|
31
|
-
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return query;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const navigate = params => _addons.addons.getChannel().emit(_coreEvents.SELECT_STORY, params);
|
|
38
|
-
|
|
39
|
-
exports.navigate = navigate;
|
|
40
|
-
|
|
41
|
-
const hrefTo = (title, name) => {
|
|
42
|
-
return new Promise(resolve => {
|
|
43
|
-
const {
|
|
44
|
-
location
|
|
45
|
-
} = document;
|
|
46
|
-
const query = parseQuery(location.search);
|
|
47
|
-
const existingId = [].concat(query.id)[0];
|
|
48
|
-
const titleToLink = title || existingId.split('--', 2)[0];
|
|
49
|
-
const id = (0, _csf.toId)(titleToLink, name);
|
|
50
|
-
const url = `${location.origin + location.pathname}?${Object.entries(Object.assign({}, query, {
|
|
51
|
-
id
|
|
52
|
-
})).map(item => `${item[0]}=${item[1]}`).join('&')}`;
|
|
53
|
-
resolve(url);
|
|
54
|
-
});
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
exports.hrefTo = hrefTo;
|
|
58
|
-
|
|
59
|
-
const valueOrCall = args => value => typeof value === 'function' ? value(...args) : value;
|
|
60
|
-
|
|
61
|
-
const linkTo = (idOrTitle, nameInput) => (...args) => {
|
|
62
|
-
const resolver = valueOrCall(args);
|
|
63
|
-
const title = resolver(idOrTitle);
|
|
64
|
-
const name = resolver(nameInput);
|
|
65
|
-
|
|
66
|
-
if (title !== null && title !== void 0 && title.match(/--/) && !name) {
|
|
67
|
-
navigate({
|
|
68
|
-
storyId: title
|
|
69
|
-
});
|
|
70
|
-
} else {
|
|
71
|
-
navigate({
|
|
72
|
-
kind: title,
|
|
73
|
-
story: name
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
|
|
78
|
-
exports.linkTo = linkTo;
|
|
79
|
-
|
|
80
|
-
const linksListener = e => {
|
|
81
|
-
const {
|
|
82
|
-
target
|
|
83
|
-
} = e;
|
|
84
|
-
|
|
85
|
-
if (!(target instanceof HTMLElement)) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const element = target;
|
|
90
|
-
const {
|
|
91
|
-
sbKind: kind,
|
|
92
|
-
sbStory: story
|
|
93
|
-
} = element.dataset;
|
|
94
|
-
|
|
95
|
-
if (kind || story) {
|
|
96
|
-
e.preventDefault();
|
|
97
|
-
navigate({
|
|
98
|
-
kind,
|
|
99
|
-
story
|
|
100
|
-
});
|
|
101
|
-
}
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
let hasListener = false;
|
|
105
|
-
|
|
106
|
-
const on = () => {
|
|
107
|
-
if (!hasListener) {
|
|
108
|
-
hasListener = true;
|
|
109
|
-
document.addEventListener('click', linksListener);
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
const off = () => {
|
|
114
|
-
if (hasListener) {
|
|
115
|
-
hasListener = false;
|
|
116
|
-
document.removeEventListener('click', linksListener);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const withLinks = (0, _addons.makeDecorator)({
|
|
121
|
-
name: 'withLinks',
|
|
122
|
-
parameterName: _constants.PARAM_KEY,
|
|
123
|
-
wrapper: (getStory, context) => {
|
|
124
|
-
on();
|
|
125
|
-
|
|
126
|
-
_addons.addons.getChannel().once(_coreEvents.STORY_CHANGED, off);
|
|
127
|
-
|
|
128
|
-
return getStory(context);
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
exports.withLinks = withLinks;
|
package/dist/esm/constants.js
DELETED
package/dist/esm/index.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import dedent from 'ts-dedent';
|
|
2
|
-
let hasWarned = false;
|
|
3
|
-
export function LinkTo() {
|
|
4
|
-
if (!hasWarned) {
|
|
5
|
-
// eslint-disable-next-line no-console
|
|
6
|
-
console.error(dedent`
|
|
7
|
-
LinkTo has moved to addon-links/react:
|
|
8
|
-
import LinkTo from '@storybook/addon-links/react';
|
|
9
|
-
`);
|
|
10
|
-
hasWarned = true;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
return null;
|
|
14
|
-
}
|
|
15
|
-
export { linkTo, hrefTo, withLinks, navigate } from './utils';
|
|
16
|
-
|
|
17
|
-
if (module && module.hot && module.hot.decline) {
|
|
18
|
-
module.hot.decline();
|
|
19
|
-
}
|
package/dist/esm/manager.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { addons } from '@storybook/addons';
|
|
2
|
-
import EVENTS, { ADDON_ID } from './constants';
|
|
3
|
-
addons.register(ADDON_ID, api => {
|
|
4
|
-
const channel = addons.getChannel();
|
|
5
|
-
channel.on(EVENTS.REQUEST, ({
|
|
6
|
-
kind,
|
|
7
|
-
name
|
|
8
|
-
}) => {
|
|
9
|
-
const id = api.storyId(kind, name);
|
|
10
|
-
api.emit(EVENTS.RECEIVE, id);
|
|
11
|
-
});
|
|
12
|
-
});
|
package/dist/esm/preview.js
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import React from 'react'; // NOTE: this is a copy of `lib/components/src/navigation/RoutedLink.tsx`.
|
|
2
|
-
// It's duplicated here because that copy has an explicit dependency on
|
|
3
|
-
// React 16.3+, which breaks older versions of React running in the preview.
|
|
4
|
-
// The proper DRY solution is to create a new package that doesn't depend
|
|
5
|
-
// on a specific react version. However, that's a heavy-handed solution for
|
|
6
|
-
// one trivial file.
|
|
7
|
-
|
|
8
|
-
const LEFT_BUTTON = 0; // Cmd/Ctrl/Shift/Alt + Click should trigger default browser behaviour. Same applies to non-left clicks
|
|
9
|
-
|
|
10
|
-
const isPlainLeftClick = e => e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
|
|
11
|
-
|
|
12
|
-
const RoutedLink = ({
|
|
13
|
-
href = '#',
|
|
14
|
-
children,
|
|
15
|
-
onClick,
|
|
16
|
-
className,
|
|
17
|
-
style
|
|
18
|
-
}) => {
|
|
19
|
-
const handleClick = e => {
|
|
20
|
-
if (isPlainLeftClick(e)) {
|
|
21
|
-
e.preventDefault();
|
|
22
|
-
onClick(e);
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const props = onClick ? {
|
|
27
|
-
href,
|
|
28
|
-
className,
|
|
29
|
-
style,
|
|
30
|
-
onClick: handleClick
|
|
31
|
-
} : {
|
|
32
|
-
href,
|
|
33
|
-
className,
|
|
34
|
-
style
|
|
35
|
-
};
|
|
36
|
-
return /*#__PURE__*/React.createElement("a", props, children);
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
export default RoutedLink;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
const _excluded = ["kind", "story", "children"];
|
|
2
|
-
|
|
3
|
-
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
|
-
|
|
5
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
6
|
-
|
|
7
|
-
import React, { PureComponent } from 'react';
|
|
8
|
-
import { navigate, hrefTo } from '../../utils'; // FIXME: copied from Typography.Link. Code is duplicated to
|
|
9
|
-
// avoid emotion dependency which breaks React 15.x back-compat
|
|
10
|
-
// Cmd/Ctrl/Shift/Alt + Click should trigger default browser behaviour. Same applies to non-left clicks
|
|
11
|
-
|
|
12
|
-
const LEFT_BUTTON = 0;
|
|
13
|
-
|
|
14
|
-
const isPlainLeftClick = e => e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
|
|
15
|
-
|
|
16
|
-
const cancelled = (e, cb = _e => {}) => {
|
|
17
|
-
if (isPlainLeftClick(e)) {
|
|
18
|
-
e.preventDefault();
|
|
19
|
-
cb(e);
|
|
20
|
-
}
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default class LinkTo extends PureComponent {
|
|
24
|
-
constructor(...args) {
|
|
25
|
-
super(...args);
|
|
26
|
-
this.state = {
|
|
27
|
-
href: '/'
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
this.updateHref = async () => {
|
|
31
|
-
const {
|
|
32
|
-
kind,
|
|
33
|
-
story
|
|
34
|
-
} = this.props;
|
|
35
|
-
const href = await hrefTo(kind, story);
|
|
36
|
-
this.setState({
|
|
37
|
-
href
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
this.handleClick = () => {
|
|
42
|
-
navigate(this.props);
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
componentDidMount() {
|
|
47
|
-
this.updateHref();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
componentDidUpdate(prevProps) {
|
|
51
|
-
const {
|
|
52
|
-
kind,
|
|
53
|
-
story
|
|
54
|
-
} = this.props;
|
|
55
|
-
|
|
56
|
-
if (prevProps.kind !== kind || prevProps.story !== story) {
|
|
57
|
-
this.updateHref();
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
render() {
|
|
62
|
-
const _this$props = this.props,
|
|
63
|
-
{
|
|
64
|
-
children
|
|
65
|
-
} = _this$props,
|
|
66
|
-
rest = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
67
|
-
|
|
68
|
-
const {
|
|
69
|
-
href
|
|
70
|
-
} = this.state;
|
|
71
|
-
return /*#__PURE__*/React.createElement("a", _extends({
|
|
72
|
-
href: href,
|
|
73
|
-
onClick: e => cancelled(e, this.handleClick)
|
|
74
|
-
}, rest), children);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
}
|
|
78
|
-
LinkTo.defaultProps = {
|
|
79
|
-
kind: null,
|
|
80
|
-
story: null,
|
|
81
|
-
children: undefined
|
|
82
|
-
};
|
package/dist/esm/react/index.js
DELETED
package/dist/esm/utils.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import global from 'global';
|
|
2
|
-
import { addons, makeDecorator } from '@storybook/addons';
|
|
3
|
-
import { STORY_CHANGED, SELECT_STORY } from '@storybook/core-events';
|
|
4
|
-
import { toId } from '@storybook/csf';
|
|
5
|
-
import { PARAM_KEY } from './constants';
|
|
6
|
-
const {
|
|
7
|
-
document,
|
|
8
|
-
HTMLElement
|
|
9
|
-
} = global;
|
|
10
|
-
|
|
11
|
-
function parseQuery(queryString) {
|
|
12
|
-
const query = {};
|
|
13
|
-
const pairs = (queryString[0] === '?' ? queryString.substring(1) : queryString).split('&').filter(Boolean); // eslint-disable-next-line no-plusplus
|
|
14
|
-
|
|
15
|
-
for (let i = 0; i < pairs.length; i++) {
|
|
16
|
-
const pair = pairs[i].split('=');
|
|
17
|
-
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return query;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const navigate = params => addons.getChannel().emit(SELECT_STORY, params);
|
|
24
|
-
export const hrefTo = (title, name) => {
|
|
25
|
-
return new Promise(resolve => {
|
|
26
|
-
const {
|
|
27
|
-
location
|
|
28
|
-
} = document;
|
|
29
|
-
const query = parseQuery(location.search);
|
|
30
|
-
const existingId = [].concat(query.id)[0];
|
|
31
|
-
const titleToLink = title || existingId.split('--', 2)[0];
|
|
32
|
-
const id = toId(titleToLink, name);
|
|
33
|
-
const url = `${location.origin + location.pathname}?${Object.entries(Object.assign({}, query, {
|
|
34
|
-
id
|
|
35
|
-
})).map(item => `${item[0]}=${item[1]}`).join('&')}`;
|
|
36
|
-
resolve(url);
|
|
37
|
-
});
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const valueOrCall = args => value => typeof value === 'function' ? value(...args) : value;
|
|
41
|
-
|
|
42
|
-
export const linkTo = (idOrTitle, nameInput) => (...args) => {
|
|
43
|
-
const resolver = valueOrCall(args);
|
|
44
|
-
const title = resolver(idOrTitle);
|
|
45
|
-
const name = resolver(nameInput);
|
|
46
|
-
|
|
47
|
-
if (title?.match(/--/) && !name) {
|
|
48
|
-
navigate({
|
|
49
|
-
storyId: title
|
|
50
|
-
});
|
|
51
|
-
} else {
|
|
52
|
-
navigate({
|
|
53
|
-
kind: title,
|
|
54
|
-
story: name
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const linksListener = e => {
|
|
60
|
-
const {
|
|
61
|
-
target
|
|
62
|
-
} = e;
|
|
63
|
-
|
|
64
|
-
if (!(target instanceof HTMLElement)) {
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const element = target;
|
|
69
|
-
const {
|
|
70
|
-
sbKind: kind,
|
|
71
|
-
sbStory: story
|
|
72
|
-
} = element.dataset;
|
|
73
|
-
|
|
74
|
-
if (kind || story) {
|
|
75
|
-
e.preventDefault();
|
|
76
|
-
navigate({
|
|
77
|
-
kind,
|
|
78
|
-
story
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
let hasListener = false;
|
|
84
|
-
|
|
85
|
-
const on = () => {
|
|
86
|
-
if (!hasListener) {
|
|
87
|
-
hasListener = true;
|
|
88
|
-
document.addEventListener('click', linksListener);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const off = () => {
|
|
93
|
-
if (hasListener) {
|
|
94
|
-
hasListener = false;
|
|
95
|
-
document.removeEventListener('click', linksListener);
|
|
96
|
-
}
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
export const withLinks = makeDecorator({
|
|
100
|
-
name: 'withLinks',
|
|
101
|
-
parameterName: PARAM_KEY,
|
|
102
|
-
wrapper: (getStory, context) => {
|
|
103
|
-
on();
|
|
104
|
-
addons.getChannel().once(STORY_CHANGED, off);
|
|
105
|
-
return getStory(context);
|
|
106
|
-
}
|
|
107
|
-
});
|
package/dist/types/index.d.ts
DELETED
package/dist/types/manager.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/types/preview.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare const decorators: ((...args: any) => any)[];
|
package/dist/types/utils.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { StoryId, StoryName, ComponentTitle } from '@storybook/csf';
|
|
2
|
-
interface ParamsId {
|
|
3
|
-
storyId: StoryId;
|
|
4
|
-
}
|
|
5
|
-
interface ParamsCombo {
|
|
6
|
-
kind?: ComponentTitle;
|
|
7
|
-
story?: StoryName;
|
|
8
|
-
}
|
|
9
|
-
export declare const navigate: (params: ParamsId | ParamsCombo) => void;
|
|
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;
|
|
12
|
-
export declare const withLinks: (...args: any) => any;
|
|
13
|
-
export {};
|