import { LoaderFunction, Renderer, DecoratorFunction } from 'storybook/internal/types'; import { applyDecorators as applyDecorators$1 } from '@storybook/react/entry-preview-docs'; import { Register, AnyRoute, FileRoutesByPath } from '@tanstack/react-router'; import { RoutesByPath, RouteOptions, ResolveParams, AnyContext } from '@tanstack/router-core'; import { Decorator } from '@storybook/react'; /** Union of every registered full path (e.g. `'/' | '/admin/users' | '/$libraryId/$version'`). */ type RegisteredFullPath = keyof Register['router']['routesByPath']; type IsAppRouteTree = TRoute extends Register['router']['routeTree'] ? true : false; type IsRoute = T extends AnyRoute ? true : T extends FileRoutesByPath[keyof FileRoutesByPath] ? true : false; type ExtractAllPathsFromFileRoutes = TRoute['path']; type StoryRoutePath = TRoute extends FileRoutesByPath[keyof FileRoutesByPath] ? ExtractAllPathsFromFileRoutes : keyof FileRoutesByPath | `/${string}`; type StoryRouteSearch = IsAppRouteTree extends true ? Record : TRoute extends FileRoutesByPath[keyof FileRoutesByPath] ? TRoute['preLoaderRoute'] extends { types: { allSearch: infer A; }; } ? A : never : Record; type StoryRouteFileOptions = IsRoute extends true ? TRoute extends { options: infer O; } ? Pick> : Pick, 'loader' | 'beforeLoad' | 'validateSearch' | 'loaderDeps' | 'context' | 'params' | 'head' | 'search' | 'parseParams' | 'context'> : Pick, 'loader' | 'beforeLoad' | 'validateSearch' | 'loaderDeps' | 'context' | 'params' | 'head' | 'search' | 'parseParams' | 'context'>; type CreateStoryRouteOptions = StoryRouteFileOptions & { path?: StoryRoutePath; }; type StoryRouteOptions = CreateStoryRouteOptions | (TRoute extends AnyRoute ? TRoute : AnyRoute); /** * Per-route override options for use inside `RouteTreeOverrides`. * Users can override `loader`, `beforeLoad`, etc. for a specific route. */ interface RouteOverrideOptions { /** Override the route's loader function. */ loader?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['loader'] | ((ctx: unknown) => Promise | unknown) : (ctx: unknown) => Promise | unknown; /** Override the route's beforeLoad function. */ beforeLoad?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['beforeLoad'] | ((ctx: unknown) => Promise | void) : (ctx: unknown) => Promise | void; /** Override the route's search params validation. */ validateSearch?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['validateSearch'] | ((search: unknown) => Promise | void) : (search: unknown) => Promise | void; /** Override the route's loader dependencies. */ loaderDeps?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['loaderDeps'] | string[] : string[]; /** Override the route's context function. */ context?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['context'] | ((ctx: unknown) => Promise | unknown) : (ctx: unknown) => Promise | unknown; } /** * A map of route overrides keyed by route ID. * Each entry can override `loader`, `beforeLoad`, etc. for that route. * * @example * ```ts * routeOverrides: { * '/_authed': { beforeLoad: () => {} }, * '/demo/form/simple/$id': { * loader: async () => ({ name: 'Mock User' }), * }, * } * ``` */ type RouteTreeOverrides = Partial<{ [routePath in keyof FileRoutesByPath]: RouteOverrideOptions | undefined; }>; interface RouterParameters : RegisteredFullPath = TRoute extends AnyRoute ? keyof RoutesByPath : keyof FileRoutesByPath> { route?: StoryRouteOptions; /** * Path to resolve the story route against. * Constrained to known registered paths in route tree mode, but can be any string in app route mode (since the user may be passing a custom `route` that doesn't exist in the registered tree). */ path?: Path; /** URL params to interpolate into the path (e.g. `{ id: '42' }` for `/$id`). */ params?: ResolveParams; /** Search/query params to append to the URL (e.g. `{ tab: 'details' }`). */ query?: Partial>; /** * Override options for specific routes in the app route tree (route tree mode only). * * Each key is a route ID (e.g. `'/about'`, `'__root__'`, `'/demo/form/simple/$id'`). * Values can override `loader`, `beforeLoad`, etc. for that route. * * @example * ```ts * routeOverrides: { * '/_authed': { beforeLoad: () => {} }, * '/demo/form/simple/$id': { * loader: async () => ({ name: 'Mock User' }), * }, * } * ``` */ routeOverrides?: RouteTreeOverrides; context?: Record; /** * */ useRouterContext?: ({ storyContext }: { storyContext: Parameters[1]; }) => AnyContext; } /** Path constraint mirroring `RouterParameters`'s second generic. */ type DefaultStoryPath = TRoute extends AnyRoute ? keyof RoutesByPath : RegisteredFullPath; interface TanStackPreviewOptions = DefaultStoryPath> { /** Router configuration for stories */ router?: RouterParameters; } interface TanStackParameters = DefaultStoryPath> { /** TanStack framework configuration (router integration). */ tanstack?: TanStackPreviewOptions; } declare const loaders: LoaderFunction[]; declare const applyDecorators: (storyFn: Parameters[0], allDecorators: DecoratorFunction[]) => any; declare const parameters: TanStackParameters; declare const optimizeDeps: string[]; export { applyDecorators, loaders, optimizeDeps, parameters };