storybook-addon-source-link
Version:
Add a button to the Storybook toolbar that opens the file containing the Story in an IDE like VSCode.
10 lines (8 loc) • 1.61 kB
JavaScript
import { DocsContainer } from '@storybook/blocks';
import { join } from '@std/path/posix';
import d, { useEffect } from 'react';
import { addons } from '@storybook/preview-api';
var i=(e,r)=>new URL(`file:///${join(e,r)}`);var c="storybook-addon-source-link",n={REQUEST_RESOLVABLE_PARAM:`${c}/request-resolve`,RESPONSE_RESOLVABLE_PARAM:`${c}/response-resolve`};var p=(e,r)=>{useEffect(()=>{let o=addons.getChannel();if(r)return;let t=u=>{let f=Object.entries(e.links).map(([s,E])=>{let a=y(E,u);if(a)return {id:s,...a}}).filter(s=>!!s);o.emit(n.RESPONSE_RESOLVABLE_PARAM,f);};return o.on(n.REQUEST_RESOLVABLE_PARAM,t),()=>{o.off(n.REQUEST_RESOLVABLE_PARAM,t);}});},l=(e,r)=>(p(r.parameters.sourceLink,r.viewMode==="docs"),e()),m=({parameter:e})=>(p(e),null),y=(e,r)=>e instanceof Function?e(r):e;var I={sourceLink:{links:{"component-vscode":({importPath:e,rootPath:r})=>{if(!r)return;let o=e.replace(/\.stories\.tsx?$/,".tsx"),t=i(r,o);return {label:o,href:`vscode://${t.href}`,icon:"VSCodeIcon"}},"story-vscode":({importPath:e,rootPath:r})=>{if(!r)return;let t=`vscode://${i(r,e).href}`;return {label:e,href:t,icon:"VSCodeIcon"}},"addon-powered-by":{label:"Powered by addon-source-link",href:"https://github.com/elecdeer/storybook-addon-source-link",order:Number.MAX_SAFE_INTEGER,icon:"InfoIcon"}}},docs:{container:({children:e,...r})=>{let{projectAnnotations:o}=r.context;return d.createElement(DocsContainer,{...r},e,o.parameters&&d.createElement(m,{parameter:o.parameters.sourceLink}))}}},M=[l];
export { M as decorators, I as parameters };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=preview.js.map