@storybook/tanstack-react 10.6.0-alpha.4 → 10.6.0-alpha.5
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-5B7CRIA6.js → chunk-HRV4LMK3.js} +42 -15
- package/dist/{chunk-CT6Edisg.d.ts → chunk-B0pqNVvJ.d.ts} +5 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.js +6 -6
- package/dist/preset.js +6 -6
- package/dist/preview.d.ts +4 -3
- package/dist/preview.js +3 -1
- package/package.json +5 -5
- package/template/stories/LoaderContextInjection.stories.tsx +45 -0
- package/template/stories/RouterContextInjection.stories.tsx +45 -0
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
var preview_exports = {};
|
|
10
10
|
__export(preview_exports, {
|
|
11
11
|
applyDecorators: () => applyDecorators,
|
|
12
|
+
beforeEach: () => beforeEach,
|
|
12
13
|
loaders: () => loaders,
|
|
13
14
|
optimizeDeps: () => optimizeDeps,
|
|
14
15
|
parameters: () => parameters
|
|
@@ -16,16 +17,16 @@ __export(preview_exports, {
|
|
|
16
17
|
import { applyDecorators as reactApplyDecorators } from "@storybook/react/entry-preview-docs";
|
|
17
18
|
|
|
18
19
|
// src/routing/decorator.tsx
|
|
19
|
-
import React from "react";
|
|
20
20
|
import {
|
|
21
21
|
createMemoryHistory,
|
|
22
22
|
createRootRoute,
|
|
23
23
|
createRoute as createRoute2,
|
|
24
24
|
createRouter,
|
|
25
|
-
|
|
25
|
+
defaultStringifySearch,
|
|
26
26
|
interpolatePath as interpolatePath2,
|
|
27
|
-
|
|
27
|
+
RouterProvider
|
|
28
28
|
} from "@tanstack/react-router";
|
|
29
|
+
import React from "react";
|
|
29
30
|
|
|
30
31
|
// src/routing/duplicate-tree.ts
|
|
31
32
|
import {
|
|
@@ -55,9 +56,12 @@ function initSourceTree(route, counter) {
|
|
|
55
56
|
for (let child of children)
|
|
56
57
|
initSourceTree(child, counter);
|
|
57
58
|
}
|
|
59
|
+
function layoutIdFor(id) {
|
|
60
|
+
return id.length > 1 && id.endsWith("/") ? id.slice(0, -1) : id;
|
|
61
|
+
}
|
|
58
62
|
function cloneChild(oldRoute, parent, overrides, byId) {
|
|
59
63
|
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 } : {},
|
|
64
|
+
...!merged.path && explicitId != null ? { id: layoutIdFor(explicitId) } : {},
|
|
61
65
|
...merged,
|
|
62
66
|
getParentRoute: () => parent
|
|
63
67
|
});
|
|
@@ -155,17 +159,15 @@ var StoryContext = React.createContext({ Story: () => null }), StoryFromContext
|
|
|
155
159
|
return React.createElement(Story, null);
|
|
156
160
|
}, tanstackRouteDecorator = (Story, context) => React.createElement(TanStackRouterStory, { Story, context });
|
|
157
161
|
function TanStackRouterStory({ Story, context }) {
|
|
158
|
-
let routerContext = context.parameters.tanstack?.router?.useRouterContext?.({
|
|
162
|
+
let router = context.tanstackRouter, routerContext = context.parameters.tanstack?.router?.useRouterContext?.({
|
|
159
163
|
storyContext: context
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
...routerContext
|
|
168
|
-
}),
|
|
164
|
+
});
|
|
165
|
+
if (!router)
|
|
166
|
+
throw new Error(
|
|
167
|
+
"No story router found on the story context: the `routerBeforeEach` hook of @storybook/tanstack-react did not run before rendering. Note that portable stories are not supported by this framework."
|
|
168
|
+
);
|
|
169
|
+
let providerContext = React.useMemo(
|
|
170
|
+
() => routerContext,
|
|
169
171
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
170
172
|
[context.id, routerContext]
|
|
171
173
|
);
|
|
@@ -265,6 +267,30 @@ function resolveTree(Story, context) {
|
|
|
265
267
|
};
|
|
266
268
|
}
|
|
267
269
|
|
|
270
|
+
// src/routing/before-each.ts
|
|
271
|
+
var storyRouters = /* @__PURE__ */ new Map(), routerBeforeEach = async (context) => {
|
|
272
|
+
let cached = storyRouters.get(context.id);
|
|
273
|
+
if (cached) {
|
|
274
|
+
context.tanstackRouter = cached;
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
let storyContext = context, parameterContext = (context.parameters.tanstack?.router ?? {}).context, routerContext = typeof parameterContext == "function" ? parameterContext({ storyContext }) : parameterContext, router = createStoryRouter({
|
|
278
|
+
Story: StoryFromContext,
|
|
279
|
+
context: storyContext,
|
|
280
|
+
routerContext
|
|
281
|
+
}), load = router.load();
|
|
282
|
+
if (context.abortSignal && !context.abortSignal.aborted ? (load.catch(() => {
|
|
283
|
+
}), await Promise.race([
|
|
284
|
+
load,
|
|
285
|
+
new Promise(
|
|
286
|
+
(resolve) => context.abortSignal.addEventListener("abort", () => resolve(), { once: !0 })
|
|
287
|
+
)
|
|
288
|
+
])) : await load, !context.abortSignal?.aborted)
|
|
289
|
+
return storyRouters.set(context.id, router), context.tanstackRouter = router, () => {
|
|
290
|
+
storyRouters.delete(context.id);
|
|
291
|
+
};
|
|
292
|
+
};
|
|
293
|
+
|
|
268
294
|
// src/routing/loader.ts
|
|
269
295
|
import { RootRoute as RootRoute3 } from "@tanstack/react-router";
|
|
270
296
|
function getComponentFromRoute(route) {
|
|
@@ -285,7 +311,7 @@ var routeComponentLoader = (context) => {
|
|
|
285
311
|
};
|
|
286
312
|
|
|
287
313
|
// src/preview.tsx
|
|
288
|
-
var loaders = [routeComponentLoader], applyDecorators = (storyFn, allDecorators) => (
|
|
314
|
+
var loaders = [routeComponentLoader], beforeEach = [routerBeforeEach], applyDecorators = (storyFn, allDecorators) => (
|
|
289
315
|
// reorder decorators so `jsxDecorator` is innermost, and `tanstackRouteDecorator` is just outside it
|
|
290
316
|
// There is an issue if `tanstackRouteDecorator` is innermost. All stories crashes due to a bug with the jsxDecorator.
|
|
291
317
|
reactApplyDecorators(storyFn, [
|
|
@@ -302,6 +328,7 @@ var loaders = [routeComponentLoader], applyDecorators = (storyFn, allDecorators)
|
|
|
302
328
|
|
|
303
329
|
export {
|
|
304
330
|
loaders,
|
|
331
|
+
beforeEach,
|
|
305
332
|
applyDecorators,
|
|
306
333
|
parameters,
|
|
307
334
|
optimizeDeps,
|
|
@@ -86,10 +86,11 @@ interface RouterParameters<TRoute = undefined, Path extends (TRoute extends AnyR
|
|
|
86
86
|
* ```
|
|
87
87
|
*/
|
|
88
88
|
routeOverrides?: RouteTreeOverrides;
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
89
|
+
/** Object or factory; the factory runs before initial router load outside React, so loader and beforeLoad can read its values. */
|
|
90
|
+
context?: Record<string, unknown> | ((options: {
|
|
91
|
+
storyContext: Parameters<Decorator>[1];
|
|
92
|
+
}) => Record<string, unknown>);
|
|
93
|
+
/** React hook render context reaches components, not the initial loader or beforeLoad; use the context factory for loader-visible values. */
|
|
93
94
|
useRouterContext?: ({
|
|
94
95
|
storyContext
|
|
95
96
|
}: {
|
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-
|
|
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-B0pqNVvJ.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
package/dist/node/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as StorybookConfig } from "../chunk-
|
|
1
|
+
import { r as StorybookConfig } from "../chunk-B0pqNVvJ.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;
|
package/dist/node/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import CJS_COMPAT_NODE_URL_zvu6fwxyfs from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_zvu6fwxyfs from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_zvu6fwxyfs from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_zvu6fwxyfs.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_zvu6fwxyfs.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_zvu6fwxyfs.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_zvu6fwxyfs from 'node:url';
|
|
2
|
+
import CJS_COMPAT_NODE_PATH_zvu6fwxyfs from 'node:path';
|
|
3
|
+
import CJS_COMPAT_NODE_MODULE_zvu6fwxyfs from "node:module";
|
|
4
4
|
|
|
5
|
-
var __filename =
|
|
6
|
-
var __dirname =
|
|
7
|
-
var require =
|
|
5
|
+
var __filename = CJS_COMPAT_NODE_URL_zvu6fwxyfs.fileURLToPath(import.meta.url);
|
|
6
|
+
var __dirname = CJS_COMPAT_NODE_PATH_zvu6fwxyfs.dirname(__filename);
|
|
7
|
+
var require = CJS_COMPAT_NODE_MODULE_zvu6fwxyfs.createRequire(import.meta.url);
|
|
8
8
|
|
|
9
9
|
// ------------------------------------------------------------
|
|
10
10
|
// end of CJS compatibility banner, injected by Storybook's esbuild configuration
|
package/dist/preview.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { i as TanStackParameters } from "./chunk-
|
|
2
|
-
import { DecoratorFunction, LoaderFunction, Renderer } from "storybook/internal/types";
|
|
1
|
+
import { i as TanStackParameters } from "./chunk-B0pqNVvJ.js";
|
|
2
|
+
import { BeforeEach, DecoratorFunction, LoaderFunction, Renderer } from "storybook/internal/types";
|
|
3
3
|
import { applyDecorators as applyDecorators$1 } from "@storybook/react/entry-preview-docs";
|
|
4
4
|
|
|
5
5
|
//#region code/frameworks/tanstack-react/.dts-emit/code/frameworks/tanstack-react/src/preview.d.ts
|
|
6
6
|
declare const loaders: LoaderFunction<Renderer>[];
|
|
7
|
+
declare const beforeEach: BeforeEach<Renderer>[];
|
|
7
8
|
declare const applyDecorators: (storyFn: Parameters<typeof applyDecorators$1>[0], allDecorators: DecoratorFunction[]) => any;
|
|
8
9
|
declare const parameters: TanStackParameters;
|
|
9
10
|
declare const optimizeDeps: string[];
|
|
10
11
|
//#endregion
|
|
11
|
-
export { applyDecorators, loaders, optimizeDeps, parameters };
|
|
12
|
+
export { applyDecorators, beforeEach, loaders, optimizeDeps, parameters };
|
package/dist/preview.js
CHANGED
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
applyDecorators,
|
|
3
|
+
beforeEach,
|
|
3
4
|
loaders,
|
|
4
5
|
optimizeDeps,
|
|
5
6
|
parameters
|
|
6
|
-
} from "./_browser-chunks/chunk-
|
|
7
|
+
} from "./_browser-chunks/chunk-HRV4LMK3.js";
|
|
7
8
|
import "./_browser-chunks/chunk-LTDGLEVR.js";
|
|
8
9
|
import "./_browser-chunks/chunk-4BE7D4DS.js";
|
|
9
10
|
export {
|
|
10
11
|
applyDecorators,
|
|
12
|
+
beforeEach,
|
|
11
13
|
loaders,
|
|
12
14
|
optimizeDeps,
|
|
13
15
|
parameters
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@storybook/tanstack-react",
|
|
3
|
-
"version": "10.6.0-alpha.
|
|
3
|
+
"version": "10.6.0-alpha.5",
|
|
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.
|
|
79
|
-
"@storybook/react": "10.6.0-alpha.
|
|
80
|
-
"@storybook/react-vite": "10.6.0-alpha.
|
|
78
|
+
"@storybook/builder-vite": "10.6.0-alpha.5",
|
|
79
|
+
"@storybook/react": "10.6.0-alpha.5",
|
|
80
|
+
"@storybook/react-vite": "10.6.0-alpha.5"
|
|
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.
|
|
98
|
+
"storybook": "^10.6.0-alpha.5",
|
|
99
99
|
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0 || ^8.0.0"
|
|
100
100
|
},
|
|
101
101
|
"peerDependenciesMeta": {
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/tanstack-react';
|
|
4
|
+
|
|
5
|
+
import { expect, within } from 'storybook/test';
|
|
6
|
+
|
|
7
|
+
const loaderCalls: unknown[] = [];
|
|
8
|
+
|
|
9
|
+
function LoaderContextViewer() {
|
|
10
|
+
return <p data-testid="loader-context">{String(loaderCalls[0] ?? 'missing')}</p>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const meta = {
|
|
14
|
+
component: LoaderContextViewer,
|
|
15
|
+
parameters: {
|
|
16
|
+
tanstack: {
|
|
17
|
+
router: {
|
|
18
|
+
context: () => {
|
|
19
|
+
loaderCalls.length = 0;
|
|
20
|
+
return { injected: 'from-factory' };
|
|
21
|
+
},
|
|
22
|
+
route: {
|
|
23
|
+
loader: ({ context }: { context: unknown }) => {
|
|
24
|
+
loaderCalls.push((context as any)?.injected ?? null);
|
|
25
|
+
},
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
} satisfies Meta<typeof LoaderContextViewer>;
|
|
31
|
+
|
|
32
|
+
export default meta;
|
|
33
|
+
|
|
34
|
+
type Story = StoryObj<typeof meta>;
|
|
35
|
+
|
|
36
|
+
/** Factory router context is visible to the route loader before render. */
|
|
37
|
+
export const FactoryValuesReachLoader: Story = {
|
|
38
|
+
play: async ({ canvasElement }) => {
|
|
39
|
+
const canvas = within(canvasElement);
|
|
40
|
+
await expect(canvas.getByTestId('loader-context')).toHaveTextContent('from-factory');
|
|
41
|
+
|
|
42
|
+
await expect(loaderCalls.length).toBeGreaterThan(0);
|
|
43
|
+
await expect(loaderCalls.every((call) => call === 'from-factory')).toBe(true);
|
|
44
|
+
},
|
|
45
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import type { Meta, StoryObj } from '@storybook/tanstack-react';
|
|
4
|
+
|
|
5
|
+
import { useRouter } from '@tanstack/react-router';
|
|
6
|
+
import { expect, within } from 'storybook/test';
|
|
7
|
+
|
|
8
|
+
const InjectedContext = React.createContext('missing-provider');
|
|
9
|
+
|
|
10
|
+
function RouterContextViewer() {
|
|
11
|
+
const router = useRouter();
|
|
12
|
+
const injected = (router.options.context as { injected?: string } | undefined)?.injected;
|
|
13
|
+
return <p data-testid="injected-router-context">{injected ?? 'missing-context'}</p>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const meta = {
|
|
17
|
+
component: RouterContextViewer,
|
|
18
|
+
decorators: [
|
|
19
|
+
(Story) => (
|
|
20
|
+
<InjectedContext.Provider value="from-react-hook">
|
|
21
|
+
<Story />
|
|
22
|
+
</InjectedContext.Provider>
|
|
23
|
+
),
|
|
24
|
+
],
|
|
25
|
+
parameters: {
|
|
26
|
+
tanstack: {
|
|
27
|
+
router: {
|
|
28
|
+
useRouterContext: () => ({ injected: React.useContext(InjectedContext) }),
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
},
|
|
32
|
+
} satisfies Meta<typeof RouterContextViewer>;
|
|
33
|
+
|
|
34
|
+
export default meta;
|
|
35
|
+
|
|
36
|
+
type Story = StoryObj<typeof meta>;
|
|
37
|
+
|
|
38
|
+
/** Hook-derived values read from a decorator's React provider must reach the story's router. */
|
|
39
|
+
export const HookValuesReachRouter: Story = {
|
|
40
|
+
play: async ({ canvasElement }) => {
|
|
41
|
+
await expect(within(canvasElement).getByTestId('injected-router-context')).toHaveTextContent(
|
|
42
|
+
'from-react-hook'
|
|
43
|
+
);
|
|
44
|
+
},
|
|
45
|
+
};
|