storybook-addon-source-link
Version:
Add a button to the Storybook toolbar that opens the file containing the Story in an IDE like VSCode.
101 lines (97 loc) • 3.05 kB
TypeScript
import * as _std_path_types from '@std/path/types';
import * as iconsModule from '@storybook/icons';
import { API_LeafEntry } from 'storybook/internal/types';
declare const getFileUrl: (rootPath: string, importPath: string) => URL;
/**
* Joins path segments into a path.
*/
declare const joinPath: (...paths: [string, ...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) => _std_path_types.ParsedPath;
/**
* Normalizes a path, resolving `.` and `..` segments.
*
* @example "./src/stories/Button.stories.tsx" -> "src/stories/Button.stories.tsx"
*/
declare const normalizePath: (path: string) => string;
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.
* - `"editor"`: The link will be opened in the code editor.
*
* @default "linkBlank"
*/
type?: "link" | "linkBlank" | "copy" | "editor" | undefined;
} | undefined;
export { type ResolveContext, type SourceLinkParameter, getFileUrl, joinPath, normalizePath, parsePath };