@storybook/tanstack-react 0.0.0-pr-34403-sha-bf1e9a7f → 0.0.0-pr-34403-sha-da307159
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-DWOHA7QX.js → chunk-IAMEPSEQ.js} +16 -3
- package/dist/index.d.ts +48 -15
- package/dist/index.js +1 -1
- package/dist/node/index.js +6 -6
- package/dist/preset.js +191 -19
- package/dist/preview.d.ts +48 -15
- package/dist/preview.js +1 -1
- package/package.json +7 -6
|
@@ -29,8 +29,21 @@ function isRoute(value) {
|
|
|
29
29
|
function getRouteFromContext(Story, context) {
|
|
30
30
|
let metaRoute = context.route, routerParameters = context.parameters.tanstack?.router ?? {}, routerParameterRoute = routerParameters.route, { route: _route, ...routeOverrides } = routerParameters ?? {}, resolvedRoute = isRoute(routerParameterRoute) ? routerParameterRoute : isRoute(metaRoute) ? metaRoute : void 0;
|
|
31
31
|
if (resolvedRoute instanceof RootRoute) {
|
|
32
|
-
let children = resolvedRoute.children;
|
|
33
|
-
|
|
32
|
+
let clonedRoot = createRootRoute({ ...resolvedRoute.options }), children = resolvedRoute.children;
|
|
33
|
+
if (children?.length) {
|
|
34
|
+
let clonedChildren = children.map((child2) => {
|
|
35
|
+
let { id: _id, getParentRoute: _g, ...childOpts } = child2.options ?? {};
|
|
36
|
+
return createRoute({
|
|
37
|
+
...childOpts,
|
|
38
|
+
...routeOverrides,
|
|
39
|
+
component: () => React.createElement(Story, null),
|
|
40
|
+
getParentRoute: () => clonedRoot
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
clonedRoot.addChildren(clonedChildren);
|
|
44
|
+
} else
|
|
45
|
+
clonedRoot.update({ component: () => React.createElement(Story, null), ...routeOverrides });
|
|
46
|
+
return clonedRoot;
|
|
34
47
|
}
|
|
35
48
|
if (resolvedRoute instanceof Route) {
|
|
36
49
|
let root2 = createRootRoute(), { id: _id, ...routeOpts } = resolvedRoute.options ?? {}, child2 = createRoute({
|
|
@@ -50,7 +63,7 @@ function getRouteFromContext(Story, context) {
|
|
|
50
63
|
return root.addChildren([child]), root;
|
|
51
64
|
}
|
|
52
65
|
function createStoryRouter({ Story, context }) {
|
|
53
|
-
let routerParameters = context.parameters.tanstack?.router ?? {}, routeTree = getRouteFromContext(Story, context), initialPath = (routerParameters?.path || routeTree.children[0]?.fullPath || routeTree.children[0]?.path || routeTree.children[0]?.options?.path) ?? "/", resolvedPath = interpolatePath({
|
|
66
|
+
let routerParameters = context.parameters.tanstack?.router ?? {}, routeTree = getRouteFromContext(Story, context), initialPath = (routerParameters?.path || routeTree.children?.[0]?.fullPath || routeTree.children?.[0]?.path || routeTree.children?.[0]?.options?.path) ?? "/", resolvedPath = interpolatePath({
|
|
54
67
|
path: initialPath,
|
|
55
68
|
params: routerParameters?.params ?? {}
|
|
56
69
|
}).interpolatedPath, search = routerParameters?.query ? defaultStringifySearch(routerParameters.query) : "";
|
package/dist/index.d.ts
CHANGED
|
@@ -287,12 +287,38 @@ type CreateStoryRouteOptions<TRoute = undefined> = StoryRouteFileOptions<TRoute>
|
|
|
287
287
|
};
|
|
288
288
|
type StoryRouteOptions<TRoute = undefined> = CreateStoryRouteOptions<TRoute> | AnyRoute;
|
|
289
289
|
/**
|
|
290
|
-
*
|
|
291
|
-
*
|
|
290
|
+
* Per-route override options for use inside `RouteTreeOverrides`.
|
|
291
|
+
* Users can override `loader`, `beforeLoad`, etc. for a specific route.
|
|
292
292
|
*/
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
293
|
+
interface RouteOverrideOptions {
|
|
294
|
+
/** Override the route's loader function. */
|
|
295
|
+
loader?: (() => unknown) | (() => Promise<unknown>);
|
|
296
|
+
/** Override the route's beforeLoad function. */
|
|
297
|
+
beforeLoad?: (() => void) | (() => Promise<void>) | (() => Record<string, unknown>);
|
|
298
|
+
/** Override the route's search params validation. */
|
|
299
|
+
validateSearch?: (input: Record<string, unknown>) => Record<string, unknown>;
|
|
300
|
+
/** Override the route's loader dependencies. */
|
|
301
|
+
loaderDeps?: (opts: {
|
|
302
|
+
search: Record<string, unknown>;
|
|
303
|
+
}) => Record<string, unknown>;
|
|
304
|
+
/** Override the route's context function. */
|
|
305
|
+
context?: (() => Record<string, unknown>) | Record<string, unknown>;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* A map of route overrides keyed by route ID.
|
|
309
|
+
* Each entry can override `loader`, `beforeLoad`, etc. for that route.
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```ts
|
|
313
|
+
* routeOverrides: {
|
|
314
|
+
* '/_authed': { beforeLoad: () => {} },
|
|
315
|
+
* '/demo/form/simple/$id': {
|
|
316
|
+
* loader: async () => ({ name: 'Mock User' }),
|
|
317
|
+
* },
|
|
318
|
+
* }
|
|
319
|
+
* ```
|
|
320
|
+
*/
|
|
321
|
+
type RouteTreeOverrides = Record<keyof FileRoutesByPath, RouteOverrideOptions>;
|
|
296
322
|
interface RouterParameters<TRoute = undefined> {
|
|
297
323
|
/** A route object or route options to use for this story. */
|
|
298
324
|
route?: StoryRouteOptions<TRoute>;
|
|
@@ -302,16 +328,23 @@ interface RouterParameters<TRoute = undefined> {
|
|
|
302
328
|
params?: StoryRouteParams<TRoute>;
|
|
303
329
|
/** Search/query params to append to the URL (e.g. `{ tab: 'details' }`). */
|
|
304
330
|
query?: Partial<StoryRouteSearch<TRoute>>;
|
|
305
|
-
/**
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
331
|
+
/**
|
|
332
|
+
* Override options for specific routes in the app route tree (route tree mode only).
|
|
333
|
+
*
|
|
334
|
+
* Each key is a route ID (e.g. `'/about'`, `'__root__'`, `'/demo/form/simple/$id'`).
|
|
335
|
+
* Values can override `loader`, `beforeLoad`, etc. for that route.
|
|
336
|
+
*
|
|
337
|
+
* @example
|
|
338
|
+
* ```ts
|
|
339
|
+
* routeOverrides: {
|
|
340
|
+
* '/_authed': { beforeLoad: () => {} },
|
|
341
|
+
* '/demo/form/simple/$id': {
|
|
342
|
+
* loader: async () => ({ name: 'Mock User' }),
|
|
343
|
+
* },
|
|
344
|
+
* }
|
|
345
|
+
* ```
|
|
346
|
+
*/
|
|
347
|
+
routeOverrides?: RouteTreeOverrides;
|
|
315
348
|
}
|
|
316
349
|
|
|
317
350
|
type FrameworkName = CompatibleString<'@storybook/tanstack-react'>;
|
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_v7smzxhmon from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_v7smzxhmon from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_v7smzxhmon from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_v7smzxhmon.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_v7smzxhmon.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_v7smzxhmon.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_v7smzxhmon from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_v7smzxhmon from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_v7smzxhmon from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_v7smzxhmon.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_v7smzxhmon.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_v7smzxhmon.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
|
@@ -13,7 +13,188 @@ var require = CJS_COMPAT_NODE_MODULE_hvuj3m650wv.createRequire(import.meta.url);
|
|
|
13
13
|
// src/preset.ts
|
|
14
14
|
import { fileURLToPath } from "node:url";
|
|
15
15
|
import { viteFinal as reactViteFinal } from "@storybook/react-vite/preset";
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
// src/plugins/server-code-elimination.ts
|
|
18
|
+
import { transformSync } from "@babel/core";
|
|
19
|
+
import {
|
|
20
|
+
isImportDeclaration,
|
|
21
|
+
isIdentifier,
|
|
22
|
+
isImportSpecifier,
|
|
23
|
+
isMemberExpression,
|
|
24
|
+
isCallExpression,
|
|
25
|
+
isExpression,
|
|
26
|
+
identifier,
|
|
27
|
+
stringLiteral,
|
|
28
|
+
callExpression,
|
|
29
|
+
importDeclaration,
|
|
30
|
+
importSpecifier
|
|
31
|
+
} from "@babel/types";
|
|
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() {
|
|
34
|
+
return {
|
|
35
|
+
name: "storybook:tanstack-react:server-code-elimination",
|
|
36
|
+
enforce: "pre",
|
|
37
|
+
transform: {
|
|
38
|
+
// we can fully rely on transform.filter
|
|
39
|
+
// and not worry about the handler since tanstack start users are Vite > 8 only
|
|
40
|
+
filter: {
|
|
41
|
+
id: {
|
|
42
|
+
include: [/\.tsx?$/],
|
|
43
|
+
// todo make export-mocks more robust (currently we just exclude all files in that folder, but ideally we should only exclude the relevant ones)
|
|
44
|
+
exclude: [/node_modules/, /export-mocks/]
|
|
45
|
+
},
|
|
46
|
+
code: ANY_PATTERN_RE
|
|
47
|
+
},
|
|
48
|
+
async handler(code, id) {
|
|
49
|
+
if (!/\.[mc]?[jt]sx?$/.test(id) || !ANY_PATTERN_RE.test(code))
|
|
50
|
+
return null;
|
|
51
|
+
let state = { code, modified: !1, needsFnImport: !1 }, result = transformSync(code, {
|
|
52
|
+
filename: id,
|
|
53
|
+
sourceType: "module",
|
|
54
|
+
parserOpts: {
|
|
55
|
+
plugins: ["typescript", "jsx"]
|
|
56
|
+
},
|
|
57
|
+
plugins: [() => serverCodeElimination(state)],
|
|
58
|
+
sourceMaps: !0,
|
|
59
|
+
configFile: !1,
|
|
60
|
+
babelrc: !1
|
|
61
|
+
});
|
|
62
|
+
return !state.modified || !result?.code ? null : {
|
|
63
|
+
code: result.code,
|
|
64
|
+
map: result.map
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function serverCodeElimination(state) {
|
|
71
|
+
function sbFnCall() {
|
|
72
|
+
return state.needsFnImport = !0, buildFnCall();
|
|
73
|
+
}
|
|
74
|
+
function sbFnCallWithImpl(impl) {
|
|
75
|
+
return state.needsFnImport = !0, buildFnCallWithImpl(impl);
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
visitor: {
|
|
79
|
+
Program(programPath) {
|
|
80
|
+
let tanstackImports = collectTanstackImports(programPath.node.body), resolves = (name, factory) => resolvesToFactory(tanstackImports, name, factory);
|
|
81
|
+
programPath.traverse({
|
|
82
|
+
CallExpression(path) {
|
|
83
|
+
let node = path.node;
|
|
84
|
+
if (isIdentifier(node.callee) && resolves(node.callee.name, "createServerOnlyFn") && SERVER_ONLY_FN_RE.test(state.code)) {
|
|
85
|
+
path.replaceWith(sbFnCall()), state.modified = !0;
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (isIdentifier(node.callee) && resolves(node.callee.name, "createClientOnlyFn") && CLIENT_ONLY_FN_RE.test(state.code)) {
|
|
89
|
+
let innerFn = node.arguments[0];
|
|
90
|
+
innerFn && isExpression(innerFn) && (path.replaceWith(sbFnCallWithImpl(innerFn)), state.modified = !0);
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
let methodName = getMethodName(node);
|
|
94
|
+
if (!methodName)
|
|
95
|
+
return;
|
|
96
|
+
let root = findChainRoot(node);
|
|
97
|
+
if (root) {
|
|
98
|
+
if (methodName === "handler" && resolves(root.rootName, "createServerFn") && SERVER_FN_RE.test(state.code)) {
|
|
99
|
+
let handlerArg = node.arguments[0];
|
|
100
|
+
if (handlerArg) {
|
|
101
|
+
if (isIdentifier(handlerArg)) {
|
|
102
|
+
let binding = path.scope.getBinding(handlerArg.name);
|
|
103
|
+
binding && binding.path.remove();
|
|
104
|
+
}
|
|
105
|
+
node.arguments[0] = sbFnCall();
|
|
106
|
+
}
|
|
107
|
+
state.modified = !0;
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (resolves(root.rootName, "createMiddleware") && MIDDLEWARE_RE.test(state.code)) {
|
|
111
|
+
(methodName === "server" || methodName === "inputValidator") && isMemberExpression(path.node.callee) && (path.replaceWith(path.node.callee.object), state.modified = !0);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
if (resolves(root.rootName, "createIsomorphicFn") && ISOMORPHIC_FN_RE.test(state.code)) {
|
|
115
|
+
if (methodName === "client") {
|
|
116
|
+
let innerFn = node.arguments[0];
|
|
117
|
+
innerFn && isExpression(innerFn) && (path.replaceWith(sbFnCallWithImpl(innerFn)), state.modified = !0);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
if (methodName === "server") {
|
|
121
|
+
let parent = path.parent;
|
|
122
|
+
(!isMemberExpression(parent) || !isCallExpression(path.parentPath?.parent)) && (path.replaceWith(sbFnCall()), state.modified = !0);
|
|
123
|
+
}
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}), state.modified && (state.needsFnImport && programPath.node.body.unshift(buildFnImport()), eliminateDeadImports(programPath));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
function buildFnImport() {
|
|
134
|
+
return importDeclaration(
|
|
135
|
+
[importSpecifier(identifier("__sb_fn"), identifier("fn"))],
|
|
136
|
+
stringLiteral("storybook/test")
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
function buildFnCall() {
|
|
140
|
+
return callExpression(identifier("__sb_fn"), []);
|
|
141
|
+
}
|
|
142
|
+
function buildFnCallWithImpl(impl) {
|
|
143
|
+
return callExpression(identifier("__sb_fn"), [impl]);
|
|
144
|
+
}
|
|
145
|
+
function collectTanstackImports(body) {
|
|
146
|
+
let imports = /* @__PURE__ */ new Map();
|
|
147
|
+
for (let node of body) {
|
|
148
|
+
if (!isImportDeclaration(node))
|
|
149
|
+
continue;
|
|
150
|
+
let src = node.source.value;
|
|
151
|
+
if (!(!src.includes("@tanstack/") && !src.includes("export-mocks") && !src.includes("@storybook/tanstack-react"))) {
|
|
152
|
+
for (let spec of node.specifiers)
|
|
153
|
+
if (isImportSpecifier(spec)) {
|
|
154
|
+
let importedName = isIdentifier(spec.imported) ? spec.imported.name : spec.imported.value;
|
|
155
|
+
imports.set(spec.local.name, importedName);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return imports;
|
|
160
|
+
}
|
|
161
|
+
function resolvesToFactory(imports, name, factoryName) {
|
|
162
|
+
return name === factoryName || imports.get(name) === factoryName;
|
|
163
|
+
}
|
|
164
|
+
function findChainRoot(node) {
|
|
165
|
+
let current = node;
|
|
166
|
+
for (; ; ) {
|
|
167
|
+
let callee = current.callee;
|
|
168
|
+
if (isIdentifier(callee))
|
|
169
|
+
return { rootCall: current, rootName: callee.name };
|
|
170
|
+
if (isMemberExpression(callee) && isCallExpression(callee.object)) {
|
|
171
|
+
current = callee.object;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
function getMethodName(node) {
|
|
178
|
+
return isMemberExpression(node.callee) && isIdentifier(node.callee.property) ? node.callee.property.name : null;
|
|
179
|
+
}
|
|
180
|
+
function eliminateDeadImports(programPath) {
|
|
181
|
+
let referencedIdentifiers = /* @__PURE__ */ new Set();
|
|
182
|
+
programPath.traverse({
|
|
183
|
+
enter(path) {
|
|
184
|
+
let { node } = path;
|
|
185
|
+
isIdentifier(node) && !path.isBindingIdentifier() && referencedIdentifiers.add(node.name);
|
|
186
|
+
}
|
|
187
|
+
}), programPath.traverse({
|
|
188
|
+
ImportDeclaration(path) {
|
|
189
|
+
let specifiers = path.node.specifiers.filter(
|
|
190
|
+
(spec) => referencedIdentifiers.has(spec.local.name)
|
|
191
|
+
);
|
|
192
|
+
specifiers.length === 0 ? path.remove() : specifiers.length !== path.node.specifiers.length && (path.node.specifiers = specifiers);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// src/preset.ts
|
|
17
198
|
var INTERCEPTED_PATTERNS = ["virtual:cloudflare", "server-entry", "worker-entry"], INTERCEPTED_MODULES = ["@tanstack/react-start"], START_SERVER_MODULES = [
|
|
18
199
|
"@tanstack/react-start/server",
|
|
19
200
|
"@tanstack/react-start-server",
|
|
@@ -32,13 +213,7 @@ var INTERCEPTED_PATTERNS = ["virtual:cloudflare", "server-entry", "worker-entry"
|
|
|
32
213
|
...entry,
|
|
33
214
|
fileURLToPath(import.meta.resolve("@storybook/tanstack-react/preview"))
|
|
34
215
|
], viteFinal = async (config, options) => {
|
|
35
|
-
let
|
|
36
|
-
nodeCompat: !0,
|
|
37
|
-
npmShims: !0,
|
|
38
|
-
resolve: !0,
|
|
39
|
-
overrides: {},
|
|
40
|
-
presets: []
|
|
41
|
-
}), { alias, inject, external, polyfill } = env, reactConfig = await reactViteFinal(config, options), isTanStackStartPlugin = (p) => {
|
|
216
|
+
let reactConfig = await reactViteFinal(config, options), isTanStackStartPlugin = (p) => {
|
|
42
217
|
if (Array.isArray(p))
|
|
43
218
|
return p.some(isTanStackStartPlugin);
|
|
44
219
|
let pluginRecord = p;
|
|
@@ -49,6 +224,7 @@ var INTERCEPTED_PATTERNS = ["virtual:cloudflare", "server-entry", "worker-entry"
|
|
|
49
224
|
import.meta.resolve("@storybook/tanstack-react/react-router")
|
|
50
225
|
), plugins = [
|
|
51
226
|
...(reactConfig.plugins ?? []).filter((p) => !isTanStackStartPlugin(p)),
|
|
227
|
+
serverCodeEliminationPlugin(),
|
|
52
228
|
{
|
|
53
229
|
name: "tanstack-start-plugin-remover",
|
|
54
230
|
enforce: "pre",
|
|
@@ -79,11 +255,7 @@ var INTERCEPTED_PATTERNS = ["virtual:cloudflare", "server-entry", "worker-entry"
|
|
|
79
255
|
"@tanstack/react-start-server",
|
|
80
256
|
"@tanstack/start-server-core"
|
|
81
257
|
]
|
|
82
|
-
}
|
|
83
|
-
resolve: {
|
|
84
|
-
alias
|
|
85
|
-
},
|
|
86
|
-
external
|
|
258
|
+
}
|
|
87
259
|
};
|
|
88
260
|
}
|
|
89
261
|
}
|
package/dist/preview.d.ts
CHANGED
|
@@ -26,12 +26,38 @@ type CreateStoryRouteOptions<TRoute = undefined> = StoryRouteFileOptions<TRoute>
|
|
|
26
26
|
};
|
|
27
27
|
type StoryRouteOptions<TRoute = undefined> = CreateStoryRouteOptions<TRoute> | AnyRoute;
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
30
|
-
*
|
|
29
|
+
* Per-route override options for use inside `RouteTreeOverrides`.
|
|
30
|
+
* Users can override `loader`, `beforeLoad`, etc. for a specific route.
|
|
31
31
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
interface RouteOverrideOptions {
|
|
33
|
+
/** Override the route's loader function. */
|
|
34
|
+
loader?: (() => unknown) | (() => Promise<unknown>);
|
|
35
|
+
/** Override the route's beforeLoad function. */
|
|
36
|
+
beforeLoad?: (() => void) | (() => Promise<void>) | (() => Record<string, unknown>);
|
|
37
|
+
/** Override the route's search params validation. */
|
|
38
|
+
validateSearch?: (input: Record<string, unknown>) => Record<string, unknown>;
|
|
39
|
+
/** Override the route's loader dependencies. */
|
|
40
|
+
loaderDeps?: (opts: {
|
|
41
|
+
search: Record<string, unknown>;
|
|
42
|
+
}) => Record<string, unknown>;
|
|
43
|
+
/** Override the route's context function. */
|
|
44
|
+
context?: (() => Record<string, unknown>) | Record<string, unknown>;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* A map of route overrides keyed by route ID.
|
|
48
|
+
* Each entry can override `loader`, `beforeLoad`, etc. for that route.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* routeOverrides: {
|
|
53
|
+
* '/_authed': { beforeLoad: () => {} },
|
|
54
|
+
* '/demo/form/simple/$id': {
|
|
55
|
+
* loader: async () => ({ name: 'Mock User' }),
|
|
56
|
+
* },
|
|
57
|
+
* }
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
type RouteTreeOverrides = Record<keyof FileRoutesByPath, RouteOverrideOptions>;
|
|
35
61
|
interface RouterParameters<TRoute = undefined> {
|
|
36
62
|
/** A route object or route options to use for this story. */
|
|
37
63
|
route?: StoryRouteOptions<TRoute>;
|
|
@@ -41,16 +67,23 @@ interface RouterParameters<TRoute = undefined> {
|
|
|
41
67
|
params?: StoryRouteParams<TRoute>;
|
|
42
68
|
/** Search/query params to append to the URL (e.g. `{ tab: 'details' }`). */
|
|
43
69
|
query?: Partial<StoryRouteSearch<TRoute>>;
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
70
|
+
/**
|
|
71
|
+
* Override options for specific routes in the app route tree (route tree mode only).
|
|
72
|
+
*
|
|
73
|
+
* Each key is a route ID (e.g. `'/about'`, `'__root__'`, `'/demo/form/simple/$id'`).
|
|
74
|
+
* Values can override `loader`, `beforeLoad`, etc. for that route.
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* ```ts
|
|
78
|
+
* routeOverrides: {
|
|
79
|
+
* '/_authed': { beforeLoad: () => {} },
|
|
80
|
+
* '/demo/form/simple/$id': {
|
|
81
|
+
* loader: async () => ({ name: 'Mock User' }),
|
|
82
|
+
* },
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
routeOverrides?: RouteTreeOverrides;
|
|
54
87
|
}
|
|
55
88
|
|
|
56
89
|
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-da307159",
|
|
4
4
|
"description": "Storybook for TanStack (React, Vite): Router + Query ready Storybook framework",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"storybook",
|
|
@@ -80,10 +80,11 @@
|
|
|
80
80
|
"!src/**/*"
|
|
81
81
|
],
|
|
82
82
|
"dependencies": {
|
|
83
|
-
"@
|
|
84
|
-
"@
|
|
85
|
-
"@storybook/
|
|
86
|
-
"
|
|
83
|
+
"@babel/core": "7.29.0",
|
|
84
|
+
"@babel/types": "7.29.0",
|
|
85
|
+
"@storybook/builder-vite": "0.0.0-pr-34403-sha-da307159",
|
|
86
|
+
"@storybook/react": "0.0.0-pr-34403-sha-da307159",
|
|
87
|
+
"@storybook/react-vite": "0.0.0-pr-34403-sha-da307159"
|
|
87
88
|
},
|
|
88
89
|
"devDependencies": {
|
|
89
90
|
"@tanstack/react-router": "^1.168.10",
|
|
@@ -102,7 +103,7 @@
|
|
|
102
103
|
"@tanstack/start-client-core": "^1.167.9",
|
|
103
104
|
"react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
104
105
|
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
|
|
105
|
-
"storybook": "^0.0.0-pr-34403-sha-
|
|
106
|
+
"storybook": "^0.0.0-pr-34403-sha-da307159",
|
|
106
107
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
107
108
|
},
|
|
108
109
|
"peerDependenciesMeta": {
|