@storybook/addon-links 7.0.0-alpha.7 → 7.0.0-beta.0

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.
Files changed (46) hide show
  1. package/dist/chunk-HG45ZTEM.mjs +4 -0
  2. package/dist/chunk-JT3VIYBO.mjs +1 -0
  3. package/dist/chunk-UXWXBGPY.mjs +1 -0
  4. package/dist/index.d.ts +18 -0
  5. package/dist/index.js +4 -0
  6. package/dist/index.mjs +1 -0
  7. package/dist/manager.d.ts +1 -0
  8. package/dist/manager.js +1 -0
  9. package/dist/manager.mjs +1 -0
  10. package/dist/preview.d.ts +5 -0
  11. package/dist/preview.js +1 -0
  12. package/dist/preview.mjs +1 -0
  13. package/dist/{types/react/components/link.d.ts → react/index.d.ts} +4 -2
  14. package/dist/react/index.js +1 -0
  15. package/dist/react/index.mjs +1 -0
  16. package/jest.config.js +7 -0
  17. package/manager.js +1 -1
  18. package/package.json +66 -12
  19. package/preview.js +1 -1
  20. package/react.d.ts +2 -2
  21. package/react.js +1 -1
  22. package/LICENSE +0 -21
  23. package/dist/cjs/constants.js +0 -16
  24. package/dist/cjs/index.js +0 -55
  25. package/dist/cjs/manager.js +0 -21
  26. package/dist/cjs/preview.js +0 -11
  27. package/dist/cjs/react/components/RoutedLink.js +0 -53
  28. package/dist/cjs/react/components/link.js +0 -110
  29. package/dist/cjs/react/index.js +0 -13
  30. package/dist/cjs/utils.js +0 -141
  31. package/dist/esm/constants.js +0 -7
  32. package/dist/esm/index.js +0 -19
  33. package/dist/esm/manager.js +0 -12
  34. package/dist/esm/preview.js +0 -2
  35. package/dist/esm/react/components/RoutedLink.js +0 -42
  36. package/dist/esm/react/components/link.js +0 -95
  37. package/dist/esm/react/index.js +0 -2
  38. package/dist/esm/utils.js +0 -117
  39. package/dist/types/constants.d.ts +0 -8
  40. package/dist/types/index.d.ts +0 -2
  41. package/dist/types/manager.d.ts +0 -1
  42. package/dist/types/preview.d.ts +0 -1
  43. package/dist/types/react/components/RoutedLink.d.ts +0 -3
  44. package/dist/types/react/index.d.ts +0 -2
  45. package/dist/types/utils.d.ts +0 -13
  46. package/register.js +0 -6
@@ -0,0 +1,4 @@
1
+ import{dedent}from"ts-dedent";var hasWarned=!1;function LinkTo(){return hasWarned||(console.error(dedent`
2
+ LinkTo has moved to addon-links/react:
3
+ import LinkTo from '@storybook/addon-links/react';
4
+ `),hasWarned=!0),null}module&&module.hot&&module.hot.decline&&module.hot.decline();export{LinkTo};
@@ -0,0 +1 @@
1
+ var ADDON_ID="storybook/links",PARAM_KEY="links",constants_default={NAVIGATE:`${ADDON_ID}/navigate`,REQUEST:`${ADDON_ID}/request`,RECEIVE:`${ADDON_ID}/receive`};export{ADDON_ID,PARAM_KEY,constants_default};
@@ -0,0 +1 @@
1
+ import{PARAM_KEY}from"./chunk-JT3VIYBO.mjs";import global from"global";import{addons,makeDecorator}from"@storybook/preview-api";import{STORY_CHANGED,SELECT_STORY}from"@storybook/core-events";import{toId}from"@storybook/csf";var{document,HTMLElement}=global;function parseQuery(queryString){let query={},pairs=(queryString[0]==="?"?queryString.substring(1):queryString).split("&").filter(Boolean);for(let i=0;i<pairs.length;i++){let pair=pairs[i].split("=");query[decodeURIComponent(pair[0])]=decodeURIComponent(pair[1]||"")}return query}var navigate=params=>addons.getChannel().emit(SELECT_STORY,params),hrefTo=(title,name)=>new Promise(resolve=>{let{location}=document,query=parseQuery(location.search),existingId=[].concat(query.id)[0],titleToLink=title||existingId.split("--",2)[0],id=toId(titleToLink,name),url=`${location.origin+location.pathname}?${Object.entries({...query,id}).map(item=>`${item[0]}=${item[1]}`).join("&")}`;resolve(url)}),valueOrCall=args=>value=>typeof value=="function"?value(...args):value,linkTo=(idOrTitle,nameInput)=>(...args)=>{let resolver=valueOrCall(args),title=resolver(idOrTitle),name=nameInput?resolver(nameInput):!1;title?.match(/--/)&&!name?navigate({storyId:title}):name&&title?navigate({kind:title,story:name}):title?navigate({kind:title}):name&&navigate({story:name})},linksListener=e=>{let{target}=e;if(!(target instanceof HTMLElement))return;let element=target,{sbKind:kind,sbStory:story}=element.dataset;(kind||story)&&(e.preventDefault(),navigate({kind,story}))},hasListener=!1,on=()=>{hasListener||(hasListener=!0,document.addEventListener("click",linksListener))},off=()=>{hasListener&&(hasListener=!1,document.removeEventListener("click",linksListener))},withLinks=makeDecorator({name:"withLinks",parameterName:PARAM_KEY,wrapper:(getStory,context)=>(on(),addons.getChannel().once(STORY_CHANGED,off),getStory(context))});export{navigate,hrefTo,linkTo,withLinks};
@@ -0,0 +1,18 @@
1
+ import * as lib_preview_api_dist_storybook_channel_mock_a19cd233 from 'lib/preview-api/dist/storybook-channel-mock-a19cd233';
2
+ import { ComponentTitle, StoryName, StoryId } from '@storybook/types';
3
+
4
+ interface ParamsId {
5
+ storyId: StoryId;
6
+ }
7
+ interface ParamsCombo {
8
+ kind?: ComponentTitle;
9
+ story?: StoryName;
10
+ }
11
+ declare const navigate: (params: ParamsId | ParamsCombo) => void;
12
+ declare const hrefTo: (title: ComponentTitle, name: StoryName) => Promise<string>;
13
+ declare const linkTo: (idOrTitle: string | ((...args: any[]) => string), nameInput?: string | ((...args: any[]) => string) | undefined) => (...args: any[]) => void;
14
+ declare const withLinks: lib_preview_api_dist_storybook_channel_mock_a19cd233.M;
15
+
16
+ declare function LinkTo(): null;
17
+
18
+ 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})},g=(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)):{},g(o||!t||!t.__esModule?c(n,"default",{value:t,enumerable:!0}):n,t)),w=t=>g(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 y=D(require("global")),a=require("@storybook/preview-api"),m=require("@storybook/core-events"),u=require("@storybook/csf");var d="storybook/links",k="links",G={NAVIGATE:`${d}/navigate`,REQUEST:`${d}/request`,RECEIVE:`${d}/receive`};var{document:f,HTMLElement:O}=y.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,u.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:k,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{LinkTo}from"./chunk-HG45ZTEM.mjs";import{hrefTo,linkTo,navigate,withLinks}from"./chunk-UXWXBGPY.mjs";import"./chunk-JT3VIYBO.mjs";export{LinkTo,hrefTo,linkTo,navigate,withLinks};
@@ -0,0 +1 @@
1
+
@@ -0,0 +1 @@
1
+ "use strict";var t=require("@storybook/manager-api");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)})});
@@ -0,0 +1 @@
1
+ import{ADDON_ID,constants_default}from"./chunk-JT3VIYBO.mjs";import{addons}from"@storybook/manager-api";addons.register(ADDON_ID,api=>{addons.getChannel().on(constants_default.REQUEST,({kind,name})=>{let id=api.storyId(kind,name);api.emit(constants_default.RECEIVE,id)})});
@@ -0,0 +1,5 @@
1
+ import * as lib_preview_api_dist_storybook_channel_mock_a19cd233 from 'lib/preview-api/dist/storybook-channel-mock-a19cd233';
2
+
3
+ declare const decorators: lib_preview_api_dist_storybook_channel_mock_a19cd233.M[];
4
+
5
+ export { decorators };
@@ -0,0 +1 @@
1
+ "use strict";var u=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?u(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/preview-api"),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 y=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",y))},A=()=>{a&&(a=!1,k.removeEventListener("click",y))},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});
@@ -0,0 +1 @@
1
+ import"./chunk-HG45ZTEM.mjs";import{withLinks}from"./chunk-UXWXBGPY.mjs";import"./chunk-JT3VIYBO.mjs";var decorators=[withLinks];export{decorators};
@@ -1,4 +1,5 @@
1
1
  import { PureComponent, ReactNode } from 'react';
2
+
2
3
  interface Props {
3
4
  kind: string | null;
4
5
  story: string | null;
@@ -7,7 +8,7 @@ interface Props {
7
8
  interface State {
8
9
  href: string;
9
10
  }
10
- export default class LinkTo extends PureComponent<Props, State> {
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
- export {};
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})},k=(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)):{},k(n||!t||!t.__esModule?a(e,"default",{value:t,enumerable:!0}):e,t)),N=t=>k(a({},"__esModule",{value:!0}),t);var Y={};M(Y,{default:()=>U});module.exports=N(Y);var p=E(require("react"));var T=E(require("global")),i=require("@storybook/preview-api"),l=require("@storybook/core-events"),P=require("@storybook/csf");var y="storybook/links",C="links",B={NAVIGATE:`${y}/navigate`,REQUEST:`${y}/request`,RECEIVE:`${y}/receive`};var{document:h,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}=h,r=H(o.search),f=[].concat(r.id)[0],d=t||f.split("--",2)[0],m=(0,P.toId)(d,n),I=`${o.origin+o.pathname}?${Object.entries({...r,id:m}).map(g=>`${g[0]}=${g[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,h.addEventListener("click",v))},_=()=>{c&&(c=!1,h.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 p.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,...f}=this.props,{href:d}=this.state;return p.default.createElement("a",{href:d,onClick:m=>w(m,this.handleClick),...f},r)}};s.defaultProps={kind:null,story:null,children:void 0};var U=s;0&&(module.exports={});
@@ -0,0 +1 @@
1
+ import{hrefTo,navigate}from"../chunk-UXWXBGPY.mjs";import"../chunk-JT3VIYBO.mjs";import React,{PureComponent}from"react";var LEFT_BUTTON=0,isPlainLeftClick=e=>e.button===LEFT_BUTTON&&!e.altKey&&!e.ctrlKey&&!e.metaKey&&!e.shiftKey,cancelled=(e,cb=_e=>{})=>{isPlainLeftClick(e)&&(e.preventDefault(),cb(e))},LinkTo=class extends PureComponent{constructor(){super(...arguments);this.state={href:"/"};this.updateHref=async()=>{let{kind,story}=this.props;if(kind&&story){let href=await hrefTo(kind,story);this.setState({href})}};this.handleClick=()=>{let{kind,story}=this.props;kind&&story&&navigate({kind,story})}}componentDidMount(){this.updateHref()}componentDidUpdate(prevProps){let{kind,story}=this.props;(prevProps.kind!==kind||prevProps.story!==story)&&this.updateHref()}render(){let{kind,story,children,...rest}=this.props,{href}=this.state;return React.createElement("a",{href,onClick:e=>cancelled(e,this.handleClick),...rest},children)}};LinkTo.defaultProps={kind:null,story:null,children:void 0};var react_default=LinkTo;export{react_default as default};
package/jest.config.js ADDED
@@ -0,0 +1,7 @@
1
+ const path = require('path');
2
+ const baseConfig = require('../../jest.config.browser');
3
+
4
+ module.exports = {
5
+ ...baseConfig,
6
+ displayName: __dirname.split(path.sep).slice(-2).join(path.posix.sep),
7
+ };
package/manager.js CHANGED
@@ -1 +1 @@
1
- import './dist/esm/manager';
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.7",
3
+ "version": "7.0.0-beta.0",
4
4
  "description": "Link stories together to build demos and prototypes with your UI components",
5
5
  "keywords": [
6
6
  "addon",
@@ -21,9 +21,50 @@
21
21
  "url": "https://opencollective.com/storybook"
22
22
  },
23
23
  "license": "MIT",
24
- "main": "dist/cjs/index.js",
25
- "module": "dist/esm/index.js",
26
- "types": "dist/types/index.d.ts",
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/index.d.ts"
44
+ },
45
+ "./register": {
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",
55
+ "typesVersions": {
56
+ "*": {
57
+ "*": [
58
+ "dist/index.d.ts"
59
+ ],
60
+ "manager": [
61
+ "dist/manager.d.ts"
62
+ ],
63
+ "preview": [
64
+ "dist/preview.d.ts"
65
+ ]
66
+ }
67
+ },
27
68
  "files": [
28
69
  "dist/**/*",
29
70
  "README.md",
@@ -31,19 +72,24 @@
31
72
  "*.d.ts"
32
73
  ],
33
74
  "scripts": {
34
- "prepare": "node ../../scripts/prepare.js"
75
+ "check": "../../../scripts/node_modules/.bin/tsc --noEmit",
76
+ "prep": "../../../scripts/prepare/bundle.ts"
35
77
  },
36
78
  "dependencies": {
37
- "@storybook/addons": "7.0.0-alpha.7",
38
- "@storybook/client-logger": "7.0.0-alpha.7",
39
- "@storybook/core-events": "7.0.0-alpha.7",
40
- "@storybook/csf": "0.0.2--canary.4566f4d.1",
41
- "@storybook/router": "7.0.0-alpha.7",
42
- "core-js": "^3.8.2",
79
+ "@storybook/client-logger": "7.0.0-beta.0",
80
+ "@storybook/core-events": "7.0.0-beta.0",
81
+ "@storybook/csf": "next",
82
+ "@storybook/manager-api": "7.0.0-beta.0",
83
+ "@storybook/preview-api": "7.0.0-beta.0",
84
+ "@storybook/router": "7.0.0-beta.0",
85
+ "@storybook/types": "7.0.0-beta.0",
43
86
  "global": "^4.4.0",
44
87
  "prop-types": "^15.7.2",
45
88
  "ts-dedent": "^2.0.0"
46
89
  },
90
+ "devDependencies": {
91
+ "typescript": "~4.9.3"
92
+ },
47
93
  "peerDependencies": {
48
94
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
49
95
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
@@ -59,7 +105,15 @@
59
105
  "publishConfig": {
60
106
  "access": "public"
61
107
  },
62
- "gitHead": "d334cabd251cd0ed8b845a87707dc84f007d4074",
108
+ "bundler": {
109
+ "entries": [
110
+ "./src/index.ts",
111
+ "./src/manager.ts",
112
+ "./src/preview.ts",
113
+ "./src/react/index.ts"
114
+ ]
115
+ },
116
+ "gitHead": "2e4ddde6a0a291266d91fe6a5ecda767bf119e70",
63
117
  "storybook": {
64
118
  "displayName": "Links",
65
119
  "icon": "https://user-images.githubusercontent.com/263385/101991673-48355c80-3c7c-11eb-9b6e-b627c96a75f6.png",
package/preview.js CHANGED
@@ -1 +1 @@
1
- export * from './dist/esm/preview';
1
+ export * from './dist/preview';
package/react.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './dist/types/react';
2
- export { default } from './dist/types/react';
1
+ export * from './dist/react';
2
+ export { default } from './dist/react';
package/react.js CHANGED
@@ -1,3 +1,3 @@
1
- import LinkTo from './dist/esm/react';
1
+ import LinkTo from './dist/react';
2
2
 
3
3
  export default LinkTo;
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.
@@ -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
- }
@@ -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
- });
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.decorators = void 0;
7
-
8
- var _index = require("./index");
9
-
10
- const decorators = [_index.withLinks];
11
- exports.decorators = decorators;
@@ -1,53 +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
-
33
- if (onClick) {
34
- onClick(e);
35
- }
36
- }
37
- };
38
-
39
- const props = onClick ? {
40
- href,
41
- className,
42
- style,
43
- onClick: handleClick
44
- } : {
45
- href,
46
- className,
47
- style
48
- };
49
- return /*#__PURE__*/_react.default.createElement("a", props, children);
50
- };
51
-
52
- var _default = RoutedLink;
53
- exports.default = _default;
@@ -1,110 +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
-
49
- if (kind && story) {
50
- const href = await (0, _utils.hrefTo)(kind, story);
51
- this.setState({
52
- href
53
- });
54
- }
55
- };
56
-
57
- this.handleClick = () => {
58
- const {
59
- kind,
60
- story
61
- } = this.props;
62
-
63
- if (kind && story) {
64
- (0, _utils.navigate)({
65
- kind,
66
- story
67
- });
68
- }
69
- };
70
- }
71
-
72
- componentDidMount() {
73
- this.updateHref();
74
- }
75
-
76
- componentDidUpdate(prevProps) {
77
- const {
78
- kind,
79
- story
80
- } = this.props;
81
-
82
- if (prevProps.kind !== kind || prevProps.story !== story) {
83
- this.updateHref();
84
- }
85
- }
86
-
87
- render() {
88
- const _this$props = this.props,
89
- {
90
- children
91
- } = _this$props,
92
- rest = _objectWithoutPropertiesLoose(_this$props, _excluded);
93
-
94
- const {
95
- href
96
- } = this.state;
97
- return /*#__PURE__*/_react.default.createElement("a", _extends({
98
- href: href,
99
- onClick: e => cancelled(e, this.handleClick)
100
- }, rest), children);
101
- }
102
-
103
- }
104
-
105
- exports.default = LinkTo;
106
- LinkTo.defaultProps = {
107
- kind: null,
108
- story: null,
109
- children: undefined
110
- };
@@ -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,141 +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); // @ts-ignore
47
-
48
- const existingId = [].concat(query.id)[0]; // @ts-ignore
49
-
50
- const titleToLink = title || existingId.split('--', 2)[0];
51
- const id = (0, _csf.toId)(titleToLink, name);
52
- const url = `${location.origin + location.pathname}?${Object.entries(Object.assign({}, query, {
53
- id
54
- })).map(item => `${item[0]}=${item[1]}`).join('&')}`;
55
- resolve(url);
56
- });
57
- };
58
-
59
- exports.hrefTo = hrefTo;
60
-
61
- const valueOrCall = args => value => typeof value === 'function' ? value(...args) : value;
62
-
63
- const linkTo = (idOrTitle, nameInput) => (...args) => {
64
- const resolver = valueOrCall(args);
65
- const title = resolver(idOrTitle);
66
- const name = nameInput ? resolver(nameInput) : false;
67
-
68
- if (title?.match(/--/) && !name) {
69
- navigate({
70
- storyId: title
71
- });
72
- } else if (name && title) {
73
- navigate({
74
- kind: title,
75
- story: name
76
- });
77
- } else if (title) {
78
- navigate({
79
- kind: title
80
- });
81
- } else if (name) {
82
- navigate({
83
- story: name
84
- });
85
- }
86
- };
87
-
88
- exports.linkTo = linkTo;
89
-
90
- const linksListener = e => {
91
- const {
92
- target
93
- } = e;
94
-
95
- if (!(target instanceof HTMLElement)) {
96
- return;
97
- }
98
-
99
- const element = target;
100
- const {
101
- sbKind: kind,
102
- sbStory: story
103
- } = element.dataset;
104
-
105
- if (kind || story) {
106
- e.preventDefault();
107
- navigate({
108
- kind,
109
- story
110
- });
111
- }
112
- };
113
-
114
- let hasListener = false;
115
-
116
- const on = () => {
117
- if (!hasListener) {
118
- hasListener = true;
119
- document.addEventListener('click', linksListener);
120
- }
121
- };
122
-
123
- const off = () => {
124
- if (hasListener) {
125
- hasListener = false;
126
- document.removeEventListener('click', linksListener);
127
- }
128
- };
129
-
130
- const withLinks = (0, _addons.makeDecorator)({
131
- name: 'withLinks',
132
- parameterName: _constants.PARAM_KEY,
133
- wrapper: (getStory, context) => {
134
- on();
135
-
136
- _addons.addons.getChannel().once(_coreEvents.STORY_CHANGED, off);
137
-
138
- return getStory(context);
139
- }
140
- });
141
- exports.withLinks = withLinks;
@@ -1,7 +0,0 @@
1
- export const ADDON_ID = 'storybook/links';
2
- export const PARAM_KEY = `links`;
3
- export default {
4
- NAVIGATE: `${ADDON_ID}/navigate`,
5
- REQUEST: `${ADDON_ID}/request`,
6
- RECEIVE: `${ADDON_ID}/receive`
7
- };
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
- }
@@ -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
- });
@@ -1,2 +0,0 @@
1
- import { withLinks } from './index';
2
- export const decorators = [withLinks];
@@ -1,42 +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
-
23
- if (onClick) {
24
- onClick(e);
25
- }
26
- }
27
- };
28
-
29
- const props = onClick ? {
30
- href,
31
- className,
32
- style,
33
- onClick: handleClick
34
- } : {
35
- href,
36
- className,
37
- style
38
- };
39
- return /*#__PURE__*/React.createElement("a", props, children);
40
- };
41
-
42
- export default RoutedLink;
@@ -1,95 +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
-
36
- if (kind && story) {
37
- const href = await hrefTo(kind, story);
38
- this.setState({
39
- href
40
- });
41
- }
42
- };
43
-
44
- this.handleClick = () => {
45
- const {
46
- kind,
47
- story
48
- } = this.props;
49
-
50
- if (kind && story) {
51
- navigate({
52
- kind,
53
- story
54
- });
55
- }
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.createElement("a", _extends({
85
- href: href,
86
- onClick: e => cancelled(e, this.handleClick)
87
- }, rest), children);
88
- }
89
-
90
- }
91
- LinkTo.defaultProps = {
92
- kind: null,
93
- story: null,
94
- children: undefined
95
- };
@@ -1,2 +0,0 @@
1
- import LinkTo from './components/link';
2
- export default LinkTo;
package/dist/esm/utils.js DELETED
@@ -1,117 +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); // @ts-ignore
30
-
31
- const existingId = [].concat(query.id)[0]; // @ts-ignore
32
-
33
- const titleToLink = title || existingId.split('--', 2)[0];
34
- const id = toId(titleToLink, name);
35
- const url = `${location.origin + location.pathname}?${Object.entries(Object.assign({}, query, {
36
- id
37
- })).map(item => `${item[0]}=${item[1]}`).join('&')}`;
38
- resolve(url);
39
- });
40
- };
41
-
42
- const valueOrCall = args => value => typeof value === 'function' ? value(...args) : value;
43
-
44
- export const linkTo = (idOrTitle, nameInput) => (...args) => {
45
- const resolver = valueOrCall(args);
46
- const title = resolver(idOrTitle);
47
- const name = nameInput ? resolver(nameInput) : false;
48
-
49
- if (title?.match(/--/) && !name) {
50
- navigate({
51
- storyId: title
52
- });
53
- } else if (name && title) {
54
- navigate({
55
- kind: title,
56
- story: name
57
- });
58
- } else if (title) {
59
- navigate({
60
- kind: title
61
- });
62
- } else if (name) {
63
- navigate({
64
- story: name
65
- });
66
- }
67
- };
68
-
69
- const linksListener = e => {
70
- const {
71
- target
72
- } = e;
73
-
74
- if (!(target instanceof HTMLElement)) {
75
- return;
76
- }
77
-
78
- const element = target;
79
- const {
80
- sbKind: kind,
81
- sbStory: story
82
- } = element.dataset;
83
-
84
- if (kind || story) {
85
- e.preventDefault();
86
- navigate({
87
- kind,
88
- story
89
- });
90
- }
91
- };
92
-
93
- let hasListener = false;
94
-
95
- const on = () => {
96
- if (!hasListener) {
97
- hasListener = true;
98
- document.addEventListener('click', linksListener);
99
- }
100
- };
101
-
102
- const off = () => {
103
- if (hasListener) {
104
- hasListener = false;
105
- document.removeEventListener('click', linksListener);
106
- }
107
- };
108
-
109
- export const withLinks = makeDecorator({
110
- name: 'withLinks',
111
- parameterName: PARAM_KEY,
112
- wrapper: (getStory, context) => {
113
- on();
114
- addons.getChannel().once(STORY_CHANGED, off);
115
- return getStory(context);
116
- }
117
- });
@@ -1,8 +0,0 @@
1
- export declare const ADDON_ID = "storybook/links";
2
- export declare const PARAM_KEY = "links";
3
- declare const _default: {
4
- NAVIGATE: string;
5
- REQUEST: string;
6
- RECEIVE: string;
7
- };
8
- export default _default;
@@ -1,2 +0,0 @@
1
- export declare function LinkTo(): null;
2
- export { linkTo, hrefTo, withLinks, navigate } from './utils';
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export declare const decorators: ((...args: any) => any)[];
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const RoutedLink: React.FC<React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>>;
3
- export default RoutedLink;
@@ -1,2 +0,0 @@
1
- import LinkTo from './components/link';
2
- export default LinkTo;
@@ -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) | undefined) => (...args: any[]) => void;
12
- export declare const withLinks: (...args: any) => any;
13
- export {};
package/register.js DELETED
@@ -1,6 +0,0 @@
1
- import { once } from '@storybook/client-logger';
2
- import './manager';
3
-
4
- once.warn(
5
- 'register.js is deprecated see https://github.com/storybookjs/storybook/blob/next/MIGRATION.md#deprecated-registerjs'
6
- );