@storybook/tanstack-react 10.6.0-alpha.2 → 10.6.0-alpha.4

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.
@@ -23,7 +23,7 @@ import {
23
23
  createRoute as createRoute2,
24
24
  createRouter,
25
25
  RouterProvider,
26
- interpolatePath,
26
+ interpolatePath as interpolatePath2,
27
27
  defaultStringifySearch
28
28
  } from "@tanstack/react-router";
29
29
 
@@ -32,6 +32,7 @@ import {
32
32
  createRoute,
33
33
  RootRoute,
34
34
  createRootRouteWithContext,
35
+ interpolatePath,
35
36
  joinPaths
36
37
  } from "@tanstack/react-router";
37
38
  var MAX_PARENT_WALK = 50;
@@ -55,12 +56,14 @@ function initSourceTree(route, counter) {
55
56
  initSourceTree(child, counter);
56
57
  }
57
58
  function cloneChild(oldRoute, parent, overrides, byId) {
58
- let options = oldRoute.options ?? {}, { id: originalId, getParentRoute: _g, ...rest } = options, override = getOverrideFor(overrides, oldRoute.id), merged = { ...rest, ...override }, cloned = createRoute({
59
- ...!merged.path && originalId != null ? { id: originalId } : {},
59
+ let options = oldRoute.options ?? {}, { id: originalId, getParentRoute: _g, ...rest } = options, override = getOverrideFor(overrides, oldRoute.id), { id: overrideId, ...overrideRest } = override, merged = { ...rest, ...overrideRest }, explicitId = "id" in override ? overrideId : originalId, cloned = createRoute({
60
+ ...!merged.path && explicitId != null ? { id: explicitId } : {},
60
61
  ...merged,
61
62
  getParentRoute: () => parent
62
63
  });
63
- byId.set(oldRoute.id, cloned);
64
+ merged.path && explicitId != null && cloned.update({ id: explicitId });
65
+ let lazyFn = oldRoute.lazyFn;
66
+ lazyFn && cloned.lazy(lazyFn), byId.set(oldRoute.id, cloned);
64
67
  let children = oldRoute.children;
65
68
  if (children?.length) {
66
69
  let clonedChildren = children.map(
@@ -80,8 +83,8 @@ function duplicateRouteTree(rootRoute, { overrides } = {}) {
80
83
  } = rootOptions, newRoot = createRootRouteWithContext()({
81
84
  ...restRoot,
82
85
  ...rootOverride
83
- });
84
- byId.set("__root__", newRoot);
86
+ }), rootLazyFn = rootRoute.lazyFn;
87
+ rootLazyFn && newRoot.lazy(rootLazyFn), byId.set("__root__", newRoot);
85
88
  let children = rootRoute.children;
86
89
  if (children?.length) {
87
90
  let clonedChildren = children.map(
@@ -101,13 +104,32 @@ function mountPathFor(route) {
101
104
  }
102
105
  return joinPaths(["/", ...segments]);
103
106
  }
104
- function resolveStoryLeaf(tree, { path, boundRouteId }) {
107
+ function originalRouteId(tree, route) {
108
+ for (let [id, cloned] of tree.byId)
109
+ if (cloned === route)
110
+ return id;
111
+ }
112
+ function resolveStoryLeaf(tree, {
113
+ path,
114
+ boundRouteId,
115
+ params
116
+ }) {
105
117
  let { root, byId } = tree;
106
118
  if (path) {
107
- let bestMatch, bestMatchLength = -1;
119
+ let bound = boundRouteId ? byId.get(boundRouteId) : void 0;
120
+ if (bound) {
121
+ let boundCandidate = mountPathFor(bound), boundInterpolated = params ? interpolatePath({ path: boundCandidate, params }).interpolatedPath : boundCandidate;
122
+ if (boundCandidate === path || boundInterpolated === path)
123
+ return bound;
124
+ }
125
+ let bestMatch, bestLiteral = !1, bestMatchLength = -1;
108
126
  for (let route of byId.values()) {
109
- let fullPath = route.fullPath;
110
- fullPath && fullPath === path && fullPath.length > bestMatchLength && (bestMatch = route, bestMatchLength = fullPath.length);
127
+ if (route === root)
128
+ continue;
129
+ let candidate = mountPathFor(route), isLiteral = candidate === path, interpolated = params ? interpolatePath({ path: candidate, params }).interpolatedPath : candidate;
130
+ if (!isLiteral && interpolated !== path)
131
+ continue;
132
+ (isLiteral === bestLiteral ? candidate.length > bestMatchLength : isLiteral) && (bestMatch = route, bestLiteral = isLiteral, bestMatchLength = candidate.length);
111
133
  }
112
134
  if (bestMatch)
113
135
  return bestMatch;
@@ -154,7 +176,7 @@ function createStoryRouter({
154
176
  context,
155
177
  routerContext
156
178
  }) {
157
- let routerParameters = context.parameters.tanstack?.router ?? {}, { tree, leaf } = resolveTree(Story, context), routeTree = tree.root, inferredPath = routerParameters?.path || leaf.fullPath || (leaf.id ? normalizeFileRoutePath(leaf.id) : void 0) || mountPathFor(leaf), resolvedPath = interpolatePath({
179
+ let routerParameters = context.parameters.tanstack?.router ?? {}, { tree, leaf } = resolveTree(Story, context), routeTree = tree.root, inferredPath = routerParameters?.path || leaf.fullPath || (leaf.id ? normalizeFileRoutePath(leaf.id) : void 0) || mountPathFor(leaf), resolvedPath = interpolatePath2({
158
180
  path: inferredPath,
159
181
  params: routerParameters?.params ?? {}
160
182
  }).interpolatedPath, search = routerParameters?.query ? defaultStringifySearch(routerParameters.query) : "";
@@ -201,9 +223,10 @@ function resolveTree(Story, context) {
201
223
  if (rootRoute) {
202
224
  let tree = duplicateRouteTree(rootRoute, { overrides: routeOverrides }), leaf = resolveStoryLeaf(tree, {
203
225
  path: routerParameters.path,
204
- boundRouteId: resolvedRoute && resolvedRoute !== rootRoute ? resolvedRoute.id : void 0
226
+ boundRouteId: resolvedRoute && resolvedRoute !== rootRoute ? resolvedRoute.id : void 0,
227
+ params: routerParameters.params
205
228
  });
206
- injectStoryComponent(leaf, Story, routeOverrides, leaf.id);
229
+ injectStoryComponent(leaf, Story, routeOverrides, originalRouteId(tree, leaf) ?? leaf.id);
207
230
  let renderLeaf = ensureMatchableLeaf(tree, leaf);
208
231
  return { tree, leaf: renderLeaf };
209
232
  }
@@ -213,7 +236,7 @@ function resolveTree(Story, context) {
213
236
  );
214
237
  routerParameterRoute.update({ getParentRoute: () => syntheticRoot2 }), syntheticRoot2.addChildren([routerParameterRoute]);
215
238
  let tree = duplicateRouteTree(syntheticRoot2, { overrides: routeOverrides }), leaf = tree.byId.get(routerParameterRoute.id) ?? tree.root;
216
- injectStoryComponent(leaf, Story, routeOverrides, leaf.id);
239
+ injectStoryComponent(leaf, Story, routeOverrides, routerParameterRoute.id);
217
240
  let renderLeaf = ensureMatchableLeaf(tree, leaf);
218
241
  return { tree, leaf: renderLeaf };
219
242
  }
@@ -223,14 +246,20 @@ function resolveTree(Story, context) {
223
246
  ...plainRouteRest
224
247
  } = plainOptions, syntheticRouteId = plainRoutePath ? void 0 : plainRouteId ?? "storybook-story", syntheticRoot = createRootRoute(
225
248
  routeOverrides?.__root__ ?? {}
226
- ), syntheticChild = createRoute2({
249
+ ), leafOverrideKey = syntheticRouteId ?? plainRoutePath, leafOverride = leafOverrideKey ? routeOverrides?.[leafOverrideKey] ?? {} : {}, syntheticChild = createRoute2({
227
250
  component: () => React.createElement(Story, null),
228
251
  id: syntheticRouteId,
229
252
  path: plainRoutePath,
230
253
  ...plainRouteRest,
254
+ ...leafOverride,
231
255
  getParentRoute: () => syntheticRoot
232
256
  });
233
- return syntheticRoot.addChildren([syntheticChild]), injectStoryComponent(syntheticChild, Story, routeOverrides, syntheticChild.id), {
257
+ return syntheticRoot.addChildren([syntheticChild]), injectStoryComponent(
258
+ syntheticChild,
259
+ Story,
260
+ routeOverrides,
261
+ syntheticRouteId ?? plainRoutePath ?? syntheticChild.id
262
+ ), {
234
263
  tree: { root: syntheticRoot, byId: /* @__PURE__ */ new Map([[syntheticChild.id, syntheticChild]]) },
235
264
  leaf: syntheticChild
236
265
  };
@@ -1,3 +1,4 @@
1
+ import { ComponentType } from "react";
1
2
  import { CompatibleString } from "storybook/internal/types";
2
3
  import { AnyRoute, FileRoutesByPath, Register } from "@tanstack/react-router";
3
4
  import { Decorator } from "@storybook/react";
@@ -29,6 +30,8 @@ type StoryRouteOptions<TRoute = undefined> = CreateStoryRouteOptions<TRoute> | (
29
30
  * Users can override `loader`, `beforeLoad`, etc. for a specific route.
30
31
  */
31
32
  interface RouteOverrideOptions<TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] | undefined = undefined> {
33
+ /** Override the route's component. */
34
+ component?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['component'] | ComponentType : ComponentType;
32
35
  /** Override the route's loader function. */
33
36
  loader?: TRoute extends FileRoutesByPath[keyof FileRoutesByPath]['preLoaderRoute'] ? TRoute['options']['loader'] | ((ctx: unknown) => Promise<unknown> | unknown) : (ctx: unknown) => Promise<unknown> | unknown;
34
37
  /** Override the route's beforeLoad function. */
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as TanStackPreviewOptions, c as IsRoute, d as StoryRouteOptions, i as TanStackParameters, l as RouterParameters, n as FrameworkOptions, o as TanStackTypes, r as StorybookConfig, s as CreateStoryRouteOptions, t as DefaultStoryPath, u as StoryRouteFileOptions } from "./chunk-B2-fTWlC.js";
1
+ import { a as TanStackPreviewOptions, c as IsRoute, d as StoryRouteOptions, i as TanStackParameters, l as RouterParameters, n as FrameworkOptions, o as TanStackTypes, r as StorybookConfig, s as CreateStoryRouteOptions, t as DefaultStoryPath, u as StoryRouteFileOptions } from "./chunk-CT6Edisg.js";
2
2
  import { ComponentType } from "react";
3
3
  import { AddonTypes, InferTypes, PreviewAddon } from "storybook/internal/csf";
4
4
  import { Args, ArgsStoryFn, ComponentAnnotations, DecoratorFunction, Parameters, ProjectAnnotations, Renderer, StoryAnnotations } from "storybook/internal/types";
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  preview_exports
3
- } from "./_browser-chunks/chunk-FF4C4TUQ.js";
3
+ } from "./_browser-chunks/chunk-5B7CRIA6.js";
4
4
  import "./_browser-chunks/chunk-LTDGLEVR.js";
5
5
  import "./_browser-chunks/chunk-4BE7D4DS.js";
6
6
 
@@ -1,4 +1,4 @@
1
- import { r as StorybookConfig } from "../chunk-B2-fTWlC.js";
1
+ import { r as StorybookConfig } from "../chunk-CT6Edisg.js";
2
2
 
3
3
  //#region code/frameworks/tanstack-react/.dts-emit/code/frameworks/tanstack-react/src/node/index.d.ts
4
4
  declare function defineMain(config: StorybookConfig): StorybookConfig;
@@ -1,10 +1,10 @@
1
- import CJS_COMPAT_NODE_URL_u7g6u19rsi from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_u7g6u19rsi from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_u7g6u19rsi from "node:module";
1
+ import CJS_COMPAT_NODE_URL_fr5elf42854 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_fr5elf42854 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_fr5elf42854 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_u7g6u19rsi.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_u7g6u19rsi.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_u7g6u19rsi.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_fr5elf42854.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_fr5elf42854.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_fr5elf42854.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 CJS_COMPAT_NODE_URL_u7g6u19rsi from 'node:url';
2
- import CJS_COMPAT_NODE_PATH_u7g6u19rsi from 'node:path';
3
- import CJS_COMPAT_NODE_MODULE_u7g6u19rsi from "node:module";
1
+ import CJS_COMPAT_NODE_URL_fr5elf42854 from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_fr5elf42854 from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_fr5elf42854 from "node:module";
4
4
 
5
- var __filename = CJS_COMPAT_NODE_URL_u7g6u19rsi.fileURLToPath(import.meta.url);
6
- var __dirname = CJS_COMPAT_NODE_PATH_u7g6u19rsi.dirname(__filename);
7
- var require = CJS_COMPAT_NODE_MODULE_u7g6u19rsi.createRequire(import.meta.url);
5
+ var __filename = CJS_COMPAT_NODE_URL_fr5elf42854.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_fr5elf42854.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_fr5elf42854.createRequire(import.meta.url);
8
8
 
9
9
  // ------------------------------------------------------------
10
10
  // end of CJS compatibility banner, injected by Storybook's esbuild configuration
@@ -360,16 +360,17 @@ function moduleInterceptionPlugin({
360
360
  enforce: "pre",
361
361
  resolveId: {
362
362
  order: "pre",
363
- handler(id, importer) {
363
+ async handler(id, importer) {
364
+ let resolveMock = async (mockPath) => await this.resolve(mockPath, importer, { skipSelf: !0 }) ?? mockPath;
364
365
  if ((id === "@tanstack/react-router" || id.startsWith("@tanstack/react-router/")) && importer && !importer.includes("export-mocks"))
365
- return routerMockPath;
366
+ return resolveMock(routerMockPath);
366
367
  if (START_SERVER_MODULES.includes(id) || id === "@tanstack/react-start")
367
- return startMockPath;
368
+ return resolveMock(startMockPath);
368
369
  if (id === "@tanstack/start-storage-context")
369
- return startStorageContextMockPath;
370
+ return resolveMock(startStorageContextMockPath);
370
371
  for (let pattern of INTERCEPTED_PATTERNS)
371
372
  if (id.includes(pattern))
372
- return startMockPath;
373
+ return resolveMock(startMockPath);
373
374
  return null;
374
375
  }
375
376
  },
package/dist/preview.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { i as TanStackParameters } from "./chunk-B2-fTWlC.js";
1
+ import { i as TanStackParameters } from "./chunk-CT6Edisg.js";
2
2
  import { DecoratorFunction, LoaderFunction, Renderer } from "storybook/internal/types";
3
3
  import { applyDecorators as applyDecorators$1 } from "@storybook/react/entry-preview-docs";
4
4
 
package/dist/preview.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  loaders,
4
4
  optimizeDeps,
5
5
  parameters
6
- } from "./_browser-chunks/chunk-FF4C4TUQ.js";
6
+ } from "./_browser-chunks/chunk-5B7CRIA6.js";
7
7
  import "./_browser-chunks/chunk-LTDGLEVR.js";
8
8
  import "./_browser-chunks/chunk-4BE7D4DS.js";
9
9
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/tanstack-react",
3
- "version": "10.6.0-alpha.2",
3
+ "version": "10.6.0-alpha.4",
4
4
  "description": "Storybook for TanStack (React, Vite): Router and Start ready Storybook framework",
5
5
  "keywords": [
6
6
  "storybook",
@@ -75,9 +75,9 @@
75
75
  "!src/**/*"
76
76
  ],
77
77
  "dependencies": {
78
- "@storybook/builder-vite": "10.6.0-alpha.2",
79
- "@storybook/react": "10.6.0-alpha.2",
80
- "@storybook/react-vite": "10.6.0-alpha.2"
78
+ "@storybook/builder-vite": "10.6.0-alpha.4",
79
+ "@storybook/react": "10.6.0-alpha.4",
80
+ "@storybook/react-vite": "10.6.0-alpha.4"
81
81
  },
82
82
  "devDependencies": {
83
83
  "@tanstack/react-router": "^1.168.10",
@@ -95,7 +95,7 @@
95
95
  "@tanstack/start-client-core": "^1.167.9",
96
96
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
97
97
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0",
98
- "storybook": "^10.6.0-alpha.2",
98
+ "storybook": "^10.6.0-alpha.4",
99
99
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
100
100
  },
101
101
  "peerDependenciesMeta": {