@storybook/tanstack-react 0.0.0-pr-34403-sha-da307159 → 0.0.0-pr-34403-sha-e7426ce1
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/_browser-chunks/{chunk-IAMEPSEQ.js → chunk-UYQAUY5K.js} +22 -8
- package/dist/export-mocks/react-router.d.ts +1 -1
- package/dist/export-mocks/react-router.js +15 -12
- package/dist/export-mocks/start.js +7 -4
- package/dist/index.d.ts +15 -18
- package/dist/index.js +1 -1
- package/dist/node/index.js +6 -6
- package/dist/preset.js +11 -11
- package/dist/preview.d.ts +15 -16
- package/dist/preview.js +1 -1
- package/package.json +5 -5
- package/template/cli/ts/Page.stories.ts +7 -1
- package/template/cli/ts/Page.tsx +1 -7
|
@@ -27,34 +27,47 @@ function isRoute(value) {
|
|
|
27
27
|
return value instanceof Route || value instanceof RootRoute;
|
|
28
28
|
}
|
|
29
29
|
function getRouteFromContext(Story, context) {
|
|
30
|
-
let metaRoute = context.route, routerParameters = context.parameters.tanstack?.router ?? {}, routerParameterRoute = routerParameters.route, {
|
|
30
|
+
let metaRoute = context.route, routerParameters = context.parameters.tanstack?.router ?? {}, routerParameterRoute = routerParameters.route, {
|
|
31
|
+
route: _route,
|
|
32
|
+
context: _context,
|
|
33
|
+
path: _path,
|
|
34
|
+
params: _params,
|
|
35
|
+
query: _query,
|
|
36
|
+
routeOverrides
|
|
37
|
+
} = routerParameters ?? {}, resolvedRoute = isRoute(routerParameterRoute) ? routerParameterRoute : isRoute(metaRoute) ? metaRoute : void 0;
|
|
31
38
|
if (resolvedRoute instanceof RootRoute) {
|
|
32
|
-
let clonedRoot = createRootRoute({
|
|
39
|
+
let clonedRoot = createRootRoute({
|
|
40
|
+
...resolvedRoute.options,
|
|
41
|
+
...routeOverrides.__root__
|
|
42
|
+
}), children = resolvedRoute.children;
|
|
33
43
|
if (children?.length) {
|
|
34
44
|
let clonedChildren = children.map((child2) => {
|
|
35
45
|
let { id: _id, getParentRoute: _g, ...childOpts } = child2.options ?? {};
|
|
36
46
|
return createRoute({
|
|
37
47
|
...childOpts,
|
|
38
|
-
...routeOverrides,
|
|
48
|
+
...routeOverrides?.[child2.id],
|
|
39
49
|
component: () => React.createElement(Story, null),
|
|
40
50
|
getParentRoute: () => clonedRoot
|
|
41
51
|
});
|
|
42
52
|
});
|
|
43
53
|
clonedRoot.addChildren(clonedChildren);
|
|
44
54
|
} else
|
|
45
|
-
clonedRoot.update({
|
|
55
|
+
clonedRoot.update({
|
|
56
|
+
component: () => React.createElement(Story, null),
|
|
57
|
+
...routeOverrides.__root__
|
|
58
|
+
});
|
|
46
59
|
return clonedRoot;
|
|
47
60
|
}
|
|
48
61
|
if (resolvedRoute instanceof Route) {
|
|
49
|
-
let root2 = createRootRoute(), { id: _id, ...routeOpts } = resolvedRoute.options ?? {}, child2 = createRoute({
|
|
62
|
+
let root2 = createRootRoute(routeOverrides?.__root__), { id: _id, ...routeOpts } = resolvedRoute.options ?? {}, child2 = createRoute({
|
|
50
63
|
...routeOpts,
|
|
51
|
-
...routeOverrides,
|
|
64
|
+
...routeOverrides?.[resolvedRoute.id],
|
|
52
65
|
component: () => React.createElement(Story, null),
|
|
53
66
|
getParentRoute: () => root2
|
|
54
67
|
});
|
|
55
68
|
return root2.addChildren([child2]), root2;
|
|
56
69
|
}
|
|
57
|
-
let root = createRootRoute(), child = createRoute({
|
|
70
|
+
let root = createRootRoute(routeOverrides?.__root__), child = createRoute({
|
|
58
71
|
component: () => React.createElement(Story, null),
|
|
59
72
|
...routerParameterRoute,
|
|
60
73
|
path: routerParameterRoute?.path ?? "/",
|
|
@@ -76,7 +89,8 @@ function createStoryRouter({ Story, context }) {
|
|
|
76
89
|
history,
|
|
77
90
|
defaultNotFoundComponent(props) {
|
|
78
91
|
return React.createElement("div", null, "Route not found: ", props.routeId);
|
|
79
|
-
}
|
|
92
|
+
},
|
|
93
|
+
context: routerParameters?.context
|
|
80
94
|
});
|
|
81
95
|
}
|
|
82
96
|
var tanstackRouteDecorator = (Story, context) => {
|
|
@@ -341,7 +341,7 @@ declare const Link: ({ to, children, ...props }: {
|
|
|
341
341
|
onClick: (e: React.MouseEvent) => void;
|
|
342
342
|
}, HTMLElement>;
|
|
343
343
|
/**
|
|
344
|
-
* Override
|
|
344
|
+
* Override createFileRoute from tanstack react router
|
|
345
345
|
* because the org `createFileRoute` doesn't set the path in the Route
|
|
346
346
|
*/
|
|
347
347
|
declare function createFileRoute(path: string): (options: any) => _tanstack_react_router.Route<unknown, _tanstack_router_core.AnyRoute, "/", "/" | `/${any}/`, string, "/" | `/${any}/`, undefined, _tanstack_router_core.ResolveParams<"/">, _tanstack_router_core.AnyContext, _tanstack_router_core.AnyContext, _tanstack_router_core.AnyContext, {}, undefined, unknown, unknown, unknown, unknown, undefined>;
|
|
@@ -37,22 +37,25 @@ var useNavigate = fn(_useNavigate).mockName("@tanstack/react-router::useNavigate
|
|
|
37
37
|
), useChildMatches = fn(_useChildMatches).mockName(
|
|
38
38
|
"@tanstack/react-router::useChildMatches"
|
|
39
39
|
), useCanGoBack = fn(_useCanGoBack).mockName("@tanstack/react-router::useCanGoBack"), useLinkProps = fn(_useLinkProps).mockName("@tanstack/react-router::useLinkProps"), Outlet = () => null, Navigate = ({ to, href }) => (useEffect(() => {
|
|
40
|
-
onNavigate(to || href);
|
|
41
|
-
}, []), null), Link = ({
|
|
40
|
+
onNavigate({ to: to || href });
|
|
41
|
+
}, [to, href]), null), Link = ({
|
|
42
42
|
to,
|
|
43
43
|
children,
|
|
44
44
|
...props
|
|
45
|
-
}) =>
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
45
|
+
}) => {
|
|
46
|
+
let location = useLocation();
|
|
47
|
+
return React.createElement(
|
|
48
|
+
"a",
|
|
49
|
+
{
|
|
50
|
+
href: to,
|
|
51
|
+
onClick: (e) => {
|
|
52
|
+
e.preventDefault(), onNavigate({ to, from: location.href });
|
|
53
|
+
},
|
|
54
|
+
...props
|
|
51
55
|
},
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
);
|
|
56
|
+
children
|
|
57
|
+
);
|
|
58
|
+
};
|
|
56
59
|
function createFileRoute(path) {
|
|
57
60
|
return (options) => createRoute({
|
|
58
61
|
path,
|
|
@@ -15,13 +15,16 @@ function useServerFn(serverFn) {
|
|
|
15
15
|
);
|
|
16
16
|
}
|
|
17
17
|
function createMockServerFnBuilder() {
|
|
18
|
-
let builder = () => createMockServerFnBuilder();
|
|
19
|
-
return builder.options =
|
|
18
|
+
let builder = () => createMockServerFnBuilder(), _storedOptions;
|
|
19
|
+
return builder.options = (opts) => (_storedOptions = opts, builder), builder.middleware = () => createMockServerFnBuilder(), builder.inputValidator = () => createMockServerFnBuilder(), builder.handler = (handlerFn) => {
|
|
20
20
|
let mock = fn().mockName("@tanstack/start-client-core::createServerFn.handler()");
|
|
21
21
|
return handlerFn && mock.mockImplementation(async (opts) => handlerFn(opts)), mock;
|
|
22
|
-
}, builder;
|
|
22
|
+
}, builder._getOptions = () => _storedOptions, builder;
|
|
23
23
|
}
|
|
24
|
-
var createServerFn = () =>
|
|
24
|
+
var createServerFn = (options) => {
|
|
25
|
+
let builder = createMockServerFnBuilder();
|
|
26
|
+
return options !== void 0 && builder.options(options), builder;
|
|
27
|
+
}, Link = ({
|
|
25
28
|
to,
|
|
26
29
|
children,
|
|
27
30
|
...props
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ import { ReactTypes, ReactPreview, ReactMeta, ReactRenderer, Meta as Meta$1, Sto
|
|
|
6
6
|
export * from '@storybook/react';
|
|
7
7
|
import { BuilderOptions } from '@storybook/builder-vite';
|
|
8
8
|
import { StorybookConfig as StorybookConfig$1 } from '@storybook/react-vite';
|
|
9
|
-
import { RouteOptions } from '@tanstack/router-core';
|
|
9
|
+
import { RouteOptions, ResolveParams } from '@tanstack/router-core';
|
|
10
10
|
|
|
11
11
|
declare global {
|
|
12
12
|
interface SymbolConstructor {
|
|
@@ -265,15 +265,13 @@ type UnionToIntersection<Union> = (
|
|
|
265
265
|
: never;
|
|
266
266
|
|
|
267
267
|
type IsRoute<T> = T extends AnyRoute ? true : T extends FileRoutesByPath[keyof FileRoutesByPath] ? true : false;
|
|
268
|
-
type
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
type StoryRoutePath<TRoute = undefined> = IsRoute<TRoute> extends true ? StoryRoutePathForRoute<TRoute> : keyof FileRoutesByPath | (string & {});
|
|
272
|
-
type StoryRouteParams<TRoute> = IsRoute<TRoute> extends true ? TRoute extends {
|
|
268
|
+
type ExtractAllPathsFromFileRoutes<TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] | AnyRoute> = TRoute['path'];
|
|
269
|
+
type StoryRoutePath<TRoute = undefined> = TRoute extends FileRoutesByPath[keyof FileRoutesByPath] ? ExtractAllPathsFromFileRoutes<TRoute> : keyof FileRoutesByPath | `/${string}`;
|
|
270
|
+
type StoryRouteParams<TRoute> = TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? ResolveParams<ExtractAllPathsFromFileRoutes<TRoute>> : IsRoute<TRoute> extends true ? TRoute extends {
|
|
273
271
|
types: {
|
|
274
272
|
allParams: infer P;
|
|
275
273
|
};
|
|
276
|
-
} ? unknown extends P ?
|
|
274
|
+
} ? unknown extends P ? never : P : never : never;
|
|
277
275
|
type StoryRouteSearch<TRoute> = IsRoute<TRoute> extends true ? TRoute extends {
|
|
278
276
|
types: {
|
|
279
277
|
fullSearchSchema: infer S;
|
|
@@ -290,19 +288,17 @@ type StoryRouteOptions<TRoute = undefined> = CreateStoryRouteOptions<TRoute> | A
|
|
|
290
288
|
* Per-route override options for use inside `RouteTreeOverrides`.
|
|
291
289
|
* Users can override `loader`, `beforeLoad`, etc. for a specific route.
|
|
292
290
|
*/
|
|
293
|
-
interface RouteOverrideOptions {
|
|
291
|
+
interface RouteOverrideOptions<TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] | undefined = undefined> {
|
|
294
292
|
/** Override the route's loader function. */
|
|
295
|
-
loader?: (() => unknown
|
|
293
|
+
loader?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['loader'] | ((ctx: unknown) => Promise<unknown> | unknown) : (ctx: unknown) => Promise<unknown> | unknown;
|
|
296
294
|
/** Override the route's beforeLoad function. */
|
|
297
|
-
beforeLoad?:
|
|
295
|
+
beforeLoad?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['beforeLoad'] | ((ctx: unknown) => Promise<void> | void) : (ctx: unknown) => Promise<void> | void;
|
|
298
296
|
/** Override the route's search params validation. */
|
|
299
|
-
validateSearch?: (
|
|
297
|
+
validateSearch?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['validateSearch'] | ((search: unknown) => Promise<void> | void) : (search: unknown) => Promise<void> | void;
|
|
300
298
|
/** Override the route's loader dependencies. */
|
|
301
|
-
loaderDeps?:
|
|
302
|
-
search: Record<string, unknown>;
|
|
303
|
-
}) => Record<string, unknown>;
|
|
299
|
+
loaderDeps?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['loaderDeps'] | string[] : string[];
|
|
304
300
|
/** Override the route's context function. */
|
|
305
|
-
context?: (() =>
|
|
301
|
+
context?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['context'] | ((ctx: unknown) => Promise<unknown> | unknown) : (ctx: unknown) => Promise<unknown> | unknown;
|
|
306
302
|
}
|
|
307
303
|
/**
|
|
308
304
|
* A map of route overrides keyed by route ID.
|
|
@@ -318,7 +314,9 @@ interface RouteOverrideOptions {
|
|
|
318
314
|
* }
|
|
319
315
|
* ```
|
|
320
316
|
*/
|
|
321
|
-
type RouteTreeOverrides =
|
|
317
|
+
type RouteTreeOverrides = Partial<{
|
|
318
|
+
[routePath in keyof FileRoutesByPath]: RouteOverrideOptions<FileRoutesByPath[routePath]['preLoaderRoute']> | undefined;
|
|
319
|
+
}>;
|
|
322
320
|
interface RouterParameters<TRoute = undefined> {
|
|
323
321
|
/** A route object or route options to use for this story. */
|
|
324
322
|
route?: StoryRouteOptions<TRoute>;
|
|
@@ -345,6 +343,7 @@ interface RouterParameters<TRoute = undefined> {
|
|
|
345
343
|
* ```
|
|
346
344
|
*/
|
|
347
345
|
routeOverrides?: RouteTreeOverrides;
|
|
346
|
+
context?: Record<string, unknown>;
|
|
348
347
|
}
|
|
349
348
|
|
|
350
349
|
type FrameworkName = CompatibleString<'@storybook/tanstack-react'>;
|
|
@@ -411,8 +410,6 @@ interface TanStackPreview<T extends AddonTypes, TRoute extends AnyRoute | undefi
|
|
|
411
410
|
meta<TMetaRoute extends AnyRoute, TArgs extends Args, Decorators extends DecoratorFunction<ReactTypes & TanStackTypes<TMetaRoute> & T, any>, TMetaArgs extends Partial<TArgs & (TanStackTypes<TMetaRoute> & T)['args']>>(meta: {
|
|
412
411
|
render?: ArgsStoryFn<ReactTypes & TanStackTypes<TMetaRoute> & T, TArgs & (TanStackTypes<TMetaRoute> & T)['args']>;
|
|
413
412
|
component?: ComponentType<TArgs>;
|
|
414
|
-
/** Provide a route to enable type-safe params/query/loader inference for this meta. */
|
|
415
|
-
route: TMetaRoute;
|
|
416
413
|
decorators?: Decorators | Decorators[];
|
|
417
414
|
args?: TMetaArgs;
|
|
418
415
|
} & Omit<ComponentAnnotations<ReactTypes & TanStackTypes<TMetaRoute> & T, TArgs>, 'decorators' | 'component' | 'args' | 'render'>): ReactMeta<InferCombinedTypes<TanStackTypes<TMetaRoute> & T, TArgs, Decorators>, Omit<ComponentAnnotations<InferCombinedTypes<TanStackTypes<TMetaRoute> & T, TArgs, Decorators>>, 'args'> & {
|
package/dist/index.js
CHANGED
package/dist/node/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_t4g8ab37o6 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_t4g8ab37o6 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_t4g8ab37o6 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_t4g8ab37o6.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_t4g8ab37o6.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_t4g8ab37o6.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
package/dist/preset.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_t4g8ab37o6 from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_t4g8ab37o6 from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_t4g8ab37o6 from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_t4g8ab37o6.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_t4g8ab37o6.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_t4g8ab37o6.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -30,7 +30,8 @@ import {
|
|
|
30
30
|
importSpecifier
|
|
31
31
|
} from "@babel/types";
|
|
32
32
|
var SERVER_FN_RE = /\bcreateServerFn\b/, MIDDLEWARE_RE = /\bcreateMiddleware\b/, ISOMORPHIC_FN_RE = /\bcreateIsomorphicFn\b/, SERVER_ONLY_FN_RE = /\bcreateServerOnlyFn\b/, CLIENT_ONLY_FN_RE = /\bcreateClientOnlyFn\b/, ANY_PATTERN_RE = /\b(createServerFn|createMiddleware|createIsomorphicFn|createServerOnlyFn|createClientOnlyFn)\b/;
|
|
33
|
-
function serverCodeEliminationPlugin() {
|
|
33
|
+
function serverCodeEliminationPlugin(options = {}) {
|
|
34
|
+
let excludeFiles = new Set(options.excludeFiles ?? []);
|
|
34
35
|
return {
|
|
35
36
|
name: "storybook:tanstack-react:server-code-elimination",
|
|
36
37
|
enforce: "pre",
|
|
@@ -40,13 +41,12 @@ function serverCodeEliminationPlugin() {
|
|
|
40
41
|
filter: {
|
|
41
42
|
id: {
|
|
42
43
|
include: [/\.tsx?$/],
|
|
43
|
-
|
|
44
|
-
exclude: [/node_modules/, /export-mocks/]
|
|
44
|
+
exclude: [/node_modules/]
|
|
45
45
|
},
|
|
46
46
|
code: ANY_PATTERN_RE
|
|
47
47
|
},
|
|
48
48
|
async handler(code, id) {
|
|
49
|
-
if (!/\.[mc]?[jt]sx?$/.test(id) || !ANY_PATTERN_RE.test(code))
|
|
49
|
+
if (!/\.[mc]?[jt]sx?$/.test(id) || excludeFiles.has(id) || !ANY_PATTERN_RE.test(code))
|
|
50
50
|
return null;
|
|
51
51
|
let state = { code, modified: !1, needsFnImport: !1 }, result = transformSync(code, {
|
|
52
52
|
filename: id,
|
|
@@ -224,7 +224,7 @@ var INTERCEPTED_PATTERNS = ["virtual:cloudflare", "server-entry", "worker-entry"
|
|
|
224
224
|
import.meta.resolve("@storybook/tanstack-react/react-router")
|
|
225
225
|
), plugins = [
|
|
226
226
|
...(reactConfig.plugins ?? []).filter((p) => !isTanStackStartPlugin(p)),
|
|
227
|
-
serverCodeEliminationPlugin(),
|
|
227
|
+
serverCodeEliminationPlugin({ excludeFiles: [stubPath] }),
|
|
228
228
|
{
|
|
229
229
|
name: "tanstack-start-plugin-remover",
|
|
230
230
|
enforce: "pre",
|
package/dist/preview.d.ts
CHANGED
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { Decorator } from '@storybook/react';
|
|
2
2
|
import { LoaderFunction, Renderer } from 'storybook/internal/types';
|
|
3
3
|
import { AnyRoute, FileRoutesByPath } from '@tanstack/react-router';
|
|
4
|
-
import { RouteOptions } from '@tanstack/router-core';
|
|
4
|
+
import { RouteOptions, ResolveParams } from '@tanstack/router-core';
|
|
5
5
|
|
|
6
6
|
type IsRoute<T> = T extends AnyRoute ? true : T extends FileRoutesByPath[keyof FileRoutesByPath] ? true : false;
|
|
7
|
-
type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
type StoryRoutePath<TRoute = undefined> = IsRoute<TRoute> extends true ? StoryRoutePathForRoute<TRoute> : keyof FileRoutesByPath | (string & {});
|
|
11
|
-
type StoryRouteParams<TRoute> = IsRoute<TRoute> extends true ? TRoute extends {
|
|
7
|
+
type ExtractAllPathsFromFileRoutes<TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] | AnyRoute> = TRoute['path'];
|
|
8
|
+
type StoryRoutePath<TRoute = undefined> = TRoute extends FileRoutesByPath[keyof FileRoutesByPath] ? ExtractAllPathsFromFileRoutes<TRoute> : keyof FileRoutesByPath | `/${string}`;
|
|
9
|
+
type StoryRouteParams<TRoute> = TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? ResolveParams<ExtractAllPathsFromFileRoutes<TRoute>> : IsRoute<TRoute> extends true ? TRoute extends {
|
|
12
10
|
types: {
|
|
13
11
|
allParams: infer P;
|
|
14
12
|
};
|
|
15
|
-
} ? unknown extends P ?
|
|
13
|
+
} ? unknown extends P ? never : P : never : never;
|
|
16
14
|
type StoryRouteSearch<TRoute> = IsRoute<TRoute> extends true ? TRoute extends {
|
|
17
15
|
types: {
|
|
18
16
|
fullSearchSchema: infer S;
|
|
@@ -29,19 +27,17 @@ type StoryRouteOptions<TRoute = undefined> = CreateStoryRouteOptions<TRoute> | A
|
|
|
29
27
|
* Per-route override options for use inside `RouteTreeOverrides`.
|
|
30
28
|
* Users can override `loader`, `beforeLoad`, etc. for a specific route.
|
|
31
29
|
*/
|
|
32
|
-
interface RouteOverrideOptions {
|
|
30
|
+
interface RouteOverrideOptions<TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] | undefined = undefined> {
|
|
33
31
|
/** Override the route's loader function. */
|
|
34
|
-
loader?: (() => unknown
|
|
32
|
+
loader?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['loader'] | ((ctx: unknown) => Promise<unknown> | unknown) : (ctx: unknown) => Promise<unknown> | unknown;
|
|
35
33
|
/** Override the route's beforeLoad function. */
|
|
36
|
-
beforeLoad?:
|
|
34
|
+
beforeLoad?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['beforeLoad'] | ((ctx: unknown) => Promise<void> | void) : (ctx: unknown) => Promise<void> | void;
|
|
37
35
|
/** Override the route's search params validation. */
|
|
38
|
-
validateSearch?: (
|
|
36
|
+
validateSearch?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['validateSearch'] | ((search: unknown) => Promise<void> | void) : (search: unknown) => Promise<void> | void;
|
|
39
37
|
/** Override the route's loader dependencies. */
|
|
40
|
-
loaderDeps?:
|
|
41
|
-
search: Record<string, unknown>;
|
|
42
|
-
}) => Record<string, unknown>;
|
|
38
|
+
loaderDeps?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['loaderDeps'] | string[] : string[];
|
|
43
39
|
/** Override the route's context function. */
|
|
44
|
-
context?: (() =>
|
|
40
|
+
context?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['context'] | ((ctx: unknown) => Promise<unknown> | unknown) : (ctx: unknown) => Promise<unknown> | unknown;
|
|
45
41
|
}
|
|
46
42
|
/**
|
|
47
43
|
* A map of route overrides keyed by route ID.
|
|
@@ -57,7 +53,9 @@ interface RouteOverrideOptions {
|
|
|
57
53
|
* }
|
|
58
54
|
* ```
|
|
59
55
|
*/
|
|
60
|
-
type RouteTreeOverrides =
|
|
56
|
+
type RouteTreeOverrides = Partial<{
|
|
57
|
+
[routePath in keyof FileRoutesByPath]: RouteOverrideOptions<FileRoutesByPath[routePath]['preLoaderRoute']> | undefined;
|
|
58
|
+
}>;
|
|
61
59
|
interface RouterParameters<TRoute = undefined> {
|
|
62
60
|
/** A route object or route options to use for this story. */
|
|
63
61
|
route?: StoryRouteOptions<TRoute>;
|
|
@@ -84,6 +82,7 @@ interface RouterParameters<TRoute = undefined> {
|
|
|
84
82
|
* ```
|
|
85
83
|
*/
|
|
86
84
|
routeOverrides?: RouteTreeOverrides;
|
|
85
|
+
context?: Record<string, unknown>;
|
|
87
86
|
}
|
|
88
87
|
|
|
89
88
|
interface TanStackPreviewOptions<TRoute = undefined> {
|
package/dist/preview.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/tanstack-react",
|
|
3
|
-
"version": "0.0.0-pr-34403-sha-
|
|
3
|
+
"version": "0.0.0-pr-34403-sha-e7426ce1",
|
|
4
4
|
"description": "Storybook for TanStack (React, Vite): Router + Query ready Storybook framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -82,9 +82,9 @@
|
|
|
82
82
|
"dependencies": {
|
|
83
83
|
"@babel/core": "7.29.0",
|
|
84
84
|
"@babel/types": "7.29.0",
|
|
85
|
-
"@storybook/builder-vite": "0.0.0-pr-34403-sha-
|
|
86
|
-
"@storybook/react": "0.0.0-pr-34403-sha-
|
|
87
|
-
"@storybook/react-vite": "0.0.0-pr-34403-sha-
|
|
85
|
+
"@storybook/builder-vite": "0.0.0-pr-34403-sha-e7426ce1",
|
|
86
|
+
"@storybook/react": "0.0.0-pr-34403-sha-e7426ce1",
|
|
87
|
+
"@storybook/react-vite": "0.0.0-pr-34403-sha-e7426ce1"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@tanstack/react-router": "^1.168.10",
|
|
@@ -103,7 +103,7 @@
|
|
|
103
103
|
"@tanstack/start-client-core": "^1.167.9",
|
|
104
104
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
105
105
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
106
|
-
"storybook": "^0.0.0-pr-34403-sha-
|
|
106
|
+
"storybook": "^0.0.0-pr-34403-sha-e7426ce1",
|
|
107
107
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
108
108
|
},
|
|
109
109
|
"peerDependenciesMeta": {
|
|
@@ -6,10 +6,16 @@ import { Route } from './Page';
|
|
|
6
6
|
|
|
7
7
|
const meta = {
|
|
8
8
|
title: 'Example/Page',
|
|
9
|
-
component: Route,
|
|
10
9
|
parameters: {
|
|
11
10
|
// More on how to position stories at: https://storybook.js.org/docs/configure/story-layout
|
|
12
11
|
layout: 'fullscreen',
|
|
12
|
+
tanstack: {
|
|
13
|
+
router: {
|
|
14
|
+
// Example of providing a custom route for a story.
|
|
15
|
+
// The page component is extracted if a component is not set for the story.
|
|
16
|
+
route: Route,
|
|
17
|
+
},
|
|
18
|
+
},
|
|
13
19
|
},
|
|
14
20
|
} satisfies Meta<typeof Route>;
|
|
15
21
|
|
package/template/cli/ts/Page.tsx
CHANGED
|
@@ -8,13 +8,7 @@ type User = {
|
|
|
8
8
|
name: string;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
interface FileRoutesByPath {
|
|
13
|
-
'/storybook': {};
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const Route = createFileRoute('/storybook')({
|
|
11
|
+
export const Route = createFileRoute('/')({
|
|
18
12
|
loader: async () => {
|
|
19
13
|
return {
|
|
20
14
|
featuredItems: [
|