UNPKG

storybook-addon-source-link

Version:

Add a button to the Storybook toolbar that opens the file containing the Story in an IDE like VSCode.

137 lines (132 loc) 3.8 kB
import * as iconsModule from '@storybook/icons'; import { API_LeafEntry } from '@storybook/types'; type IconName = Exclude<keyof typeof iconsModule, "iconList">; type SourceLinkParameter = { links: Record<string, Resolvable<LinkEntry>>; }; type ResolveContext = { /** * The root path of the Storybook project. * This is the path where the `.storybook` directory is located. * * @example `"/Users/username/path/to/project"` */ rootPath: string | undefined; /** * Whether the Storybook is being executed with a static build. */ isStaticBuild: boolean; /** * The type of entry. */ type: API_LeafEntry["type"]; /** * The path to the source file. * @example `"./src/stories/Button.tsx"` */ importPath: API_LeafEntry["importPath"]; /** * The id of the entry. * @example `"example-button--primary"` */ id: API_LeafEntry["id"]; /** * The title of the entry. * @example `"Example/Button"` */ title: API_LeafEntry["title"]; /** * The name of the entry. * @example `"Primary"` */ name: API_LeafEntry["name"]; /** * The tags of the entry. */ tags: API_LeafEntry["tags"]; }; type Resolvable<T> = ((context: ResolveContext) => T) | T; type LinkEntry = { /** * The label of the link. */ label: string; /** * The URL of the link. */ href: string; /** * The icon name in [@storybook/icons](https://main--64b56e737c0aeefed9d5e675.chromatic.com/?path=/docs/introduction--docs) */ icon?: IconName | undefined; /** * When order is specified, it will be sorted in ascending order. The default value is `0`. */ order?: number | undefined; /** * The type of the link. * * - `"link"`: The link will be opened in the same tab. * - `"linkBlank"`: The link will be opened in a new tab. Added target="_blank" to the link. * - `"copy"`: The link will be copied to the clipboard. * * @default "linkBlank" */ type?: "link" | "linkBlank" | "copy" | undefined; } | undefined; /** * A parsed path object generated by path.parse() or consumed by path.format(). * * @example * ```ts * import { parse } from "@std/path"; * * const parsedPathObj = parse("c:\\path\\dir\\index.html"); * parsedPathObj.root; // "c:\\" * parsedPathObj.dir; // "c:\\path\\dir" * parsedPathObj.base; // "index.html" * parsedPathObj.ext; // ".html" * parsedPathObj.name; // "index" * ``` */ interface ParsedPath { /** * The root of the path such as '/' or 'c:\' */ root: string; /** * The full directory path of the parent such as '/home/user/dir' or 'c:\path\dir' */ dir: string; /** * The file name including extension (if any) such as 'index.html' */ base: string; /** * The file extension (if any) such as '.html' */ ext: string; /** * The file name without extension (if any) such as 'index' */ name: string; } declare const getFileUrl: (rootPath: string, importPath: string) => URL; /** * Joins path segments into a path. */ declare const joinPath: (paths_0: string, ...paths_1: string[]) => string; /** * Parses a path into an object. * * @example "./src/stories/Button.stories.tsx" * -> { root: "", dir: "./src/stories", base: "Button.stories.tsx", ext: ".tsx", name: "Button.stories" } */ declare const parsePath: (path: string) => ParsedPath; /** * Normalizes a path, resolving `.` and `..` segments. * * @example "./src/stories/Button.stories.tsx" -> "src/stories/Button.stories.tsx" */ declare const normalizePath: (path: string) => string; export { type SourceLinkParameter, getFileUrl, joinPath, normalizePath, parsePath };