@storybook/tanstack-react 10.5.2 → 10.6.0-alpha.1
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.
- package/dist/chunk-B2-fTWlC.d.ts +131 -0
- package/dist/export-mocks/react-router.d.ts +294 -291
- package/dist/export-mocks/start-storage-context.d.ts +12 -10
- package/dist/export-mocks/start.d.ts +61 -53
- package/dist/index.d.ts +54 -186
- package/dist/node/index.d.ts +4 -26
- package/dist/node/index.js +6 -6
- package/dist/preset.d.ts +5 -4
- package/dist/preset.js +6 -6
- package/dist/preview.d.ts +6 -106
- package/package.json +6 -6
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { CompatibleString } from "storybook/internal/types";
|
|
2
|
+
import { AnyRoute, FileRoutesByPath, Register } from "@tanstack/react-router";
|
|
3
|
+
import { Decorator } from "@storybook/react";
|
|
4
|
+
import { AnyContext, ResolveParams, RouteOptions, RoutesByPath } from "@tanstack/router-core";
|
|
5
|
+
import { BuilderOptions } from "@storybook/builder-vite";
|
|
6
|
+
import { StorybookConfig } from "@storybook/react-vite";
|
|
7
|
+
|
|
8
|
+
//#region code/frameworks/tanstack-react/.dts-emit/code/frameworks/tanstack-react/src/routing/types.d.ts
|
|
9
|
+
/** Union of every registered full path (e.g. `'/' | '/admin/users' | '/$libraryId/$version'`). */
|
|
10
|
+
type RegisteredFullPath = keyof Register['router']['routesByPath'];
|
|
11
|
+
type IsAppRouteTree<TRoute> = TRoute extends Register['router']['routeTree'] ? true : false;
|
|
12
|
+
type IsRoute<T> = T extends AnyRoute ? true : T extends FileRoutesByPath[keyof FileRoutesByPath] ? true : false;
|
|
13
|
+
type ExtractAllPathsFromFileRoutes<TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] | AnyRoute> = TRoute['path'];
|
|
14
|
+
type StoryRoutePath<TRoute = undefined> = TRoute extends FileRoutesByPath[keyof FileRoutesByPath] ? ExtractAllPathsFromFileRoutes<TRoute> : keyof FileRoutesByPath | `/${string}`;
|
|
15
|
+
type StoryRouteSearch<TRoute> = IsAppRouteTree<TRoute> extends true ? Record<string, unknown> : TRoute extends FileRoutesByPath[keyof FileRoutesByPath] ? TRoute['preLoaderRoute'] extends {
|
|
16
|
+
types: {
|
|
17
|
+
allSearch: infer A;
|
|
18
|
+
};
|
|
19
|
+
} ? A : never : Record<string, unknown>;
|
|
20
|
+
type StoryRouteFileOptions<TRoute = undefined> = IsRoute<TRoute> extends true ? TRoute extends {
|
|
21
|
+
options: infer O;
|
|
22
|
+
} ? Pick<O, Extract<keyof O, 'loader' | 'beforeLoad' | 'validateSearch' | 'loaderDeps' | 'context' | 'params' | 'head' | 'search' | 'parseParams' | 'context'>> : Pick<RouteOptions<unknown>, 'loader' | 'beforeLoad' | 'validateSearch' | 'loaderDeps' | 'context' | 'params' | 'head' | 'search' | 'parseParams' | 'context'> : Pick<RouteOptions<unknown>, 'loader' | 'beforeLoad' | 'validateSearch' | 'loaderDeps' | 'context' | 'params' | 'head' | 'search' | 'parseParams' | 'context'>;
|
|
23
|
+
type CreateStoryRouteOptions<TRoute = undefined> = StoryRouteFileOptions<TRoute> & {
|
|
24
|
+
path?: StoryRoutePath<TRoute>;
|
|
25
|
+
};
|
|
26
|
+
type StoryRouteOptions<TRoute = undefined> = CreateStoryRouteOptions<TRoute> | (TRoute extends AnyRoute ? TRoute : AnyRoute);
|
|
27
|
+
/**
|
|
28
|
+
* Per-route override options for use inside `RouteTreeOverrides`.
|
|
29
|
+
* Users can override `loader`, `beforeLoad`, etc. for a specific route.
|
|
30
|
+
*/
|
|
31
|
+
interface RouteOverrideOptions<TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] | undefined = undefined> {
|
|
32
|
+
/** Override the route's loader function. */
|
|
33
|
+
loader?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['loader'] | ((ctx: unknown) => Promise<unknown> | unknown) : (ctx: unknown) => Promise<unknown> | unknown;
|
|
34
|
+
/** Override the route's beforeLoad function. */
|
|
35
|
+
beforeLoad?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['beforeLoad'] | ((ctx: unknown) => Promise<void> | void) : (ctx: unknown) => Promise<void> | void;
|
|
36
|
+
/** Override the route's search params validation. */
|
|
37
|
+
validateSearch?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['validateSearch'] | ((search: unknown) => Promise<void> | void) : (search: unknown) => Promise<void> | void;
|
|
38
|
+
/** Override the route's loader dependencies. */
|
|
39
|
+
loaderDeps?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['loaderDeps'] | string[] : string[];
|
|
40
|
+
/** Override the route's context function. */
|
|
41
|
+
context?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['context'] | ((ctx: unknown) => Promise<unknown> | unknown) : (ctx: unknown) => Promise<unknown> | unknown;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A map of route overrides keyed by route ID.
|
|
45
|
+
* Each entry can override `loader`, `beforeLoad`, etc. for that route.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```ts
|
|
49
|
+
* routeOverrides: {
|
|
50
|
+
* '/_authed': { beforeLoad: () => {} },
|
|
51
|
+
* '/demo/form/simple/$id': {
|
|
52
|
+
* loader: async () => ({ name: 'Mock User' }),
|
|
53
|
+
* },
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
type RouteTreeOverrides = Partial<{ [routePath in keyof FileRoutesByPath]: RouteOverrideOptions<FileRoutesByPath[routePath]['preLoaderRoute']> | undefined }>;
|
|
58
|
+
interface RouterParameters<TRoute = undefined, Path extends (TRoute extends AnyRoute ? keyof RoutesByPath<TRoute> : RegisteredFullPath) = (TRoute extends AnyRoute ? keyof RoutesByPath<TRoute> : keyof FileRoutesByPath)> {
|
|
59
|
+
route?: StoryRouteOptions<TRoute>;
|
|
60
|
+
/**
|
|
61
|
+
* Path to resolve the story route against.
|
|
62
|
+
* 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).
|
|
63
|
+
*/
|
|
64
|
+
path?: Path;
|
|
65
|
+
/** URL params to interpolate into the path (e.g. `{ id: '42' }` for `/$id`). */
|
|
66
|
+
params?: ResolveParams<Path>;
|
|
67
|
+
/** Search/query params to append to the URL (e.g. `{ tab: 'details' }`). */
|
|
68
|
+
query?: Partial<StoryRouteSearch<TRoute>>;
|
|
69
|
+
/**
|
|
70
|
+
* Override options for specific routes in the app route tree (route tree mode only).
|
|
71
|
+
*
|
|
72
|
+
* Each key is a route ID (e.g. `'/about'`, `'__root__'`, `'/demo/form/simple/$id'`).
|
|
73
|
+
* Values can override `loader`, `beforeLoad`, etc. for that route.
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* routeOverrides: {
|
|
78
|
+
* '/_authed': { beforeLoad: () => {} },
|
|
79
|
+
* '/demo/form/simple/$id': {
|
|
80
|
+
* loader: async () => ({ name: 'Mock User' }),
|
|
81
|
+
* },
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
routeOverrides?: RouteTreeOverrides;
|
|
86
|
+
context?: Record<string, unknown>;
|
|
87
|
+
/**
|
|
88
|
+
*
|
|
89
|
+
*/
|
|
90
|
+
useRouterContext?: ({
|
|
91
|
+
storyContext
|
|
92
|
+
}: {
|
|
93
|
+
storyContext: Parameters<Decorator>[1];
|
|
94
|
+
}) => AnyContext;
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region code/frameworks/tanstack-react/.dts-emit/code/frameworks/tanstack-react/src/types.d.ts
|
|
98
|
+
type FrameworkName = CompatibleString<'@storybook/tanstack-react'>;
|
|
99
|
+
type BuilderName = CompatibleString<'@storybook/builder-vite'>;
|
|
100
|
+
type FrameworkOptions = {
|
|
101
|
+
/** Builder options passed through to @storybook/builder-vite. */builder?: BuilderOptions;
|
|
102
|
+
};
|
|
103
|
+
type StorybookConfigFramework = {
|
|
104
|
+
framework: FrameworkName | {
|
|
105
|
+
name: FrameworkName;
|
|
106
|
+
options: FrameworkOptions;
|
|
107
|
+
};
|
|
108
|
+
core?: StorybookConfig['core'] & {
|
|
109
|
+
builder?: BuilderName | {
|
|
110
|
+
name: BuilderName;
|
|
111
|
+
options: BuilderOptions;
|
|
112
|
+
};
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
/** The interface for Storybook configuration in `main.ts` files. */
|
|
116
|
+
type StorybookConfig$1 = Omit<StorybookConfig, keyof StorybookConfigFramework> & StorybookConfigFramework;
|
|
117
|
+
/** Path constraint mirroring `RouterParameters`'s second generic. */
|
|
118
|
+
type DefaultStoryPath<TRoute> = TRoute extends AnyRoute ? keyof RoutesByPath<TRoute> : RegisteredFullPath;
|
|
119
|
+
interface TanStackPreviewOptions<TRoute = undefined, Path extends DefaultStoryPath<TRoute> = DefaultStoryPath<TRoute>> {
|
|
120
|
+
/** Router configuration for stories */
|
|
121
|
+
router?: RouterParameters<TRoute, Path>;
|
|
122
|
+
}
|
|
123
|
+
interface TanStackParameters<TRoute = undefined, Path extends DefaultStoryPath<TRoute> = DefaultStoryPath<TRoute>> {
|
|
124
|
+
/** TanStack framework configuration (router integration). */
|
|
125
|
+
tanstack?: TanStackPreviewOptions<TRoute, Path>;
|
|
126
|
+
}
|
|
127
|
+
interface TanStackTypes<TRoute = undefined, Path extends DefaultStoryPath<TRoute> = DefaultStoryPath<TRoute>> {
|
|
128
|
+
parameters: TanStackParameters<TRoute, Path>;
|
|
129
|
+
}
|
|
130
|
+
//#endregion
|
|
131
|
+
export { TanStackPreviewOptions as a, IsRoute as c, StoryRouteOptions as d, TanStackParameters as i, RouterParameters as l, FrameworkOptions as n, TanStackTypes as o, StorybookConfig$1 as r, CreateStoryRouteOptions as s, DefaultStoryPath as t, StoryRouteFileOptions as u };
|