@storybook/nextjs 9.2.0-alpha.3 → 10.0.0-beta.0

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.
Files changed (85) hide show
  1. package/README.md +3 -1
  2. package/dist/_browser-chunks/chunk-I5RFHXDS.js +40 -0
  3. package/dist/_browser-chunks/chunk-JOMP7DUK.js +261 -0
  4. package/dist/_browser-chunks/chunk-L5NVL7MD.js +37 -0
  5. package/dist/_browser-chunks/react-18-G7Q4PNHD.js +71 -0
  6. package/dist/_node-chunks/chunk-24UYJEDD.js +74 -0
  7. package/dist/_node-chunks/chunk-EZEBG77A.js +88 -0
  8. package/dist/_node-chunks/chunk-WCSGFZKZ.js +17 -0
  9. package/dist/_node-chunks/chunk-YMVPQWBH.js +167 -0
  10. package/dist/_node-chunks/configureNextFont-HBRWHAUG.js +36 -0
  11. package/dist/_node-chunks/loader-KXTZ5PJ5.js +51 -0
  12. package/dist/_node-chunks/loader-Z4IXWF5M.js +64 -0
  13. package/dist/_node-chunks/utils-4LRBHVQD.js +31 -0
  14. package/dist/_node-chunks/webpack-6HAXGE7X.js +38 -0
  15. package/dist/_node-chunks/webpack-AGNCA7HZ.js +77 -0
  16. package/dist/_node-chunks/webpack-CXSD35E6.js +30 -0
  17. package/dist/_node-chunks/webpack-EWT6TRQB.js +26 -0
  18. package/dist/_node-chunks/webpack-K2R3GUFU.js +29 -0
  19. package/dist/_node-chunks/webpack-PD7PIB6X.js +43 -0
  20. package/dist/_node-chunks/webpack-QFTZE3CE.js +27 -0
  21. package/dist/_node-chunks/webpack-SWQY6JJY.js +107 -0
  22. package/dist/compatibility/draft-mode.compat.js +7 -1
  23. package/dist/export-mocks/cache/index.d.ts +309 -1
  24. package/dist/export-mocks/cache/index.js +22 -1
  25. package/dist/export-mocks/headers/index.d.ts +309 -1
  26. package/dist/export-mocks/headers/index.js +77 -1
  27. package/dist/export-mocks/index.js +20 -1
  28. package/dist/export-mocks/navigation/index.js +88 -1
  29. package/dist/export-mocks/router/index.d.ts +2 -2
  30. package/dist/export-mocks/router/index.js +97 -1
  31. package/dist/font/webpack/loader/storybook-nextjs-font-loader.js +201 -14
  32. package/dist/image-context.js +8 -1
  33. package/dist/images/next-image.js +35 -1
  34. package/dist/images/next-legacy-image.js +21 -1
  35. package/dist/index.d.ts +53 -8
  36. package/dist/index.js +20237 -45
  37. package/dist/next-image-loader-stub.js +33 -1
  38. package/dist/node/index.d.ts +27 -6
  39. package/dist/node/index.js +23 -1
  40. package/dist/preset.js +830 -1
  41. package/dist/preview.d.ts +3 -18
  42. package/dist/preview.d.tsx +18 -0
  43. package/dist/preview.js +11 -1
  44. package/dist/rsc/server-only.js +7 -1
  45. package/dist/swc/next-swc-loader-patch.js +136 -1
  46. package/package.json +41 -122
  47. package/preset.js +1 -1
  48. package/template/cli/js/Configure.mdx +11 -11
  49. package/template/cli/ts/Configure.mdx +11 -11
  50. package/dist/chunk-2TZKD6A5.mjs +0 -20
  51. package/dist/chunk-ETFXNGLC.mjs +0 -3
  52. package/dist/chunk-L66KIASX.mjs +0 -3
  53. package/dist/chunk-NQ32RFK2.mjs +0 -6
  54. package/dist/compatibility/draft-mode.compat.d.ts +0 -1
  55. package/dist/compatibility/draft-mode.compat.mjs +0 -2
  56. package/dist/export-mocks/cache/index.mjs +0 -10
  57. package/dist/export-mocks/headers/index.mjs +0 -12
  58. package/dist/export-mocks/index.d.ts +0 -7
  59. package/dist/export-mocks/index.mjs +0 -11
  60. package/dist/export-mocks/navigation/index.mjs +0 -11
  61. package/dist/export-mocks/router/index.mjs +0 -10
  62. package/dist/font/webpack/loader/storybook-nextjs-font-loader.d.ts +0 -3
  63. package/dist/font/webpack/loader/storybook-nextjs-font-loader.mjs +0 -56
  64. package/dist/image-context.d.ts +0 -13
  65. package/dist/image-context.mjs +0 -6
  66. package/dist/images/decorator.d.ts +0 -6
  67. package/dist/images/decorator.js +0 -1
  68. package/dist/images/decorator.mjs +0 -2
  69. package/dist/images/next-image.d.ts +0 -28
  70. package/dist/images/next-image.mjs +0 -9
  71. package/dist/images/next-legacy-image.d.ts +0 -6
  72. package/dist/images/next-legacy-image.mjs +0 -9
  73. package/dist/index.d-ff220430.d.ts +0 -310
  74. package/dist/index.mjs +0 -58
  75. package/dist/next-image-loader-stub.d.ts +0 -10
  76. package/dist/next-image-loader-stub.mjs +0 -7
  77. package/dist/node/index.mjs +0 -5
  78. package/dist/preset.d.ts +0 -14
  79. package/dist/preview.mjs +0 -3
  80. package/dist/react-18-WSPZ3BUV.mjs +0 -7
  81. package/dist/rsc/server-only.d.ts +0 -3
  82. package/dist/rsc/server-only.mjs +0 -5
  83. package/dist/swc/next-swc-loader-patch.d.ts +0 -21
  84. package/dist/swc/next-swc-loader-patch.mjs +0 -8
  85. package/dist/types-f6ea2c09.d.ts +0 -54
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Storybook for Next.js
2
2
 
3
- See [documentation](https://storybook.js.org/docs/get-started/frameworks/nextjs?renderer=react) for installation instructions, usage examples, APIs, and more.
3
+ See [documentation](https://storybook.js.org/docs/get-started/frameworks/nextjs?renderer=react&ref=readme) for installation instructions, usage examples, APIs, and more.
4
4
 
5
5
  ## Acknowledgements
6
6
 
@@ -8,3 +8,5 @@ This framework borrows heavily from these Storybook addons:
8
8
 
9
9
  - [storybook-addon-next](https://github.com/RyanClementsHax/storybook-addon-next) by [RyanClementsHax](https://github.com/RyanClementsHax/)
10
10
  - [storybook-addon-next-router](https://github.com/lifeiscontent/storybook-addon-next-router) by [lifeiscontent](https://github.com/lifeiscontent)
11
+
12
+ Learn more about Storybook at [storybook.js.org](https://storybook.js.org/?ref=readme).
@@ -0,0 +1,40 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-L5NVL7MD.js";
4
+
5
+ // src/images/next-image-default-loader.tsx
6
+ var defaultLoader = /* @__PURE__ */ __name(({ src, width, quality = 75 }) => {
7
+ const missingValues = [];
8
+ if (!src) {
9
+ missingValues.push("src");
10
+ }
11
+ if (!width) {
12
+ missingValues.push("width");
13
+ }
14
+ if (missingValues.length > 0) {
15
+ throw new Error(
16
+ `Next Image Optimization requires ${missingValues.join(
17
+ ", "
18
+ )} to be provided. Make sure you pass them as props to the \`next/image\` component. Received: ${JSON.stringify(
19
+ {
20
+ src,
21
+ width,
22
+ quality
23
+ }
24
+ )}`
25
+ );
26
+ }
27
+ const url = new URL(src, window.location.href);
28
+ if (!url.searchParams.has("w") && !url.searchParams.has("q")) {
29
+ url.searchParams.set("w", width.toString());
30
+ url.searchParams.set("q", quality.toString());
31
+ }
32
+ if (!src.startsWith("http://") && !src.startsWith("https://")) {
33
+ return url.toString().slice(url.origin.length);
34
+ }
35
+ return url.toString();
36
+ }, "defaultLoader");
37
+
38
+ export {
39
+ defaultLoader
40
+ };
@@ -0,0 +1,261 @@
1
+ import {
2
+ __export,
3
+ __name
4
+ } from "./chunk-L5NVL7MD.js";
5
+
6
+ // src/preview.tsx
7
+ var preview_exports = {};
8
+ __export(preview_exports, {
9
+ decorators: () => decorators,
10
+ loaders: () => loaders,
11
+ parameters: () => parameters
12
+ });
13
+ import { createNavigation } from "@storybook/nextjs/navigation.mock";
14
+ import { createRouter } from "@storybook/nextjs/router.mock";
15
+ import { isNextRouterError } from "next/dist/client/components/is-next-router-error";
16
+
17
+ // src/config/preview.ts
18
+ import { setConfig } from "next/config";
19
+ setConfig(process.env.__NEXT_RUNTIME_CONFIG);
20
+
21
+ // src/head-manager/decorator.tsx
22
+ import * as React2 from "react";
23
+
24
+ // src/head-manager/head-manager-provider.tsx
25
+ import React, { useMemo } from "react";
26
+ import initHeadManager from "next/dist/client/head-manager";
27
+ import { HeadManagerContext } from "next/dist/shared/lib/head-manager-context.shared-runtime";
28
+ var HeadManagerProvider = /* @__PURE__ */ __name(({ children }) => {
29
+ const headManager = useMemo(initHeadManager, []);
30
+ headManager.getIsSsr = () => false;
31
+ return React.createElement(HeadManagerContext.Provider, { value: headManager }, children);
32
+ }, "HeadManagerProvider");
33
+ var head_manager_provider_default = HeadManagerProvider;
34
+
35
+ // src/head-manager/decorator.tsx
36
+ var HeadManagerDecorator = /* @__PURE__ */ __name((Story) => {
37
+ return React2.createElement(head_manager_provider_default, null, React2.createElement(Story, null));
38
+ }, "HeadManagerDecorator");
39
+
40
+ // src/images/decorator.tsx
41
+ import * as React3 from "react";
42
+ import { ImageContext as ImageContextValue } from "@storybook/nextjs/image-context";
43
+ var ImageContext = ImageContextValue;
44
+ var ImageDecorator = /* @__PURE__ */ __name((Story, { parameters: parameters2 }) => {
45
+ if (!parameters2.nextjs?.image) {
46
+ return React3.createElement(Story, null);
47
+ }
48
+ return React3.createElement(ImageContext.Provider, { value: parameters2.nextjs.image }, React3.createElement(Story, null));
49
+ }, "ImageDecorator");
50
+
51
+ // src/routing/decorator.tsx
52
+ import * as React6 from "react";
53
+ import { RedirectBoundary } from "next/dist/client/components/redirect-boundary";
54
+
55
+ // src/routing/app-router-provider.tsx
56
+ import React4, { useMemo as useMemo2 } from "react";
57
+ import { getRouter } from "@storybook/nextjs/navigation.mock";
58
+ import {
59
+ AppRouterContext,
60
+ GlobalLayoutRouterContext,
61
+ LayoutRouterContext
62
+ } from "next/dist/shared/lib/app-router-context.shared-runtime";
63
+ import {
64
+ PathParamsContext,
65
+ PathnameContext,
66
+ SearchParamsContext
67
+ } from "next/dist/shared/lib/hooks-client-context.shared-runtime";
68
+ import { PAGE_SEGMENT_KEY } from "next/dist/shared/lib/segment";
69
+ var getParallelRoutes = /* @__PURE__ */ __name((segmentsList) => {
70
+ const segment = segmentsList.shift();
71
+ if (segment) {
72
+ return [segment, { children: getParallelRoutes(segmentsList) }];
73
+ }
74
+ return [];
75
+ }, "getParallelRoutes");
76
+ var AppRouterProvider = /* @__PURE__ */ __name(({
77
+ children,
78
+ routeParams
79
+ }) => {
80
+ const { pathname, query, segments = [] } = routeParams;
81
+ const tree = [pathname, { children: getParallelRoutes([...segments]) }];
82
+ const pathParams = useMemo2(() => {
83
+ const params = {};
84
+ const currentSegments = routeParams.segments;
85
+ if (currentSegments) {
86
+ if (Array.isArray(currentSegments)) {
87
+ for (const segmentEntry of currentSegments) {
88
+ if (Array.isArray(segmentEntry) && segmentEntry.length === 2 && typeof segmentEntry[0] === "string") {
89
+ const key = segmentEntry[0];
90
+ const value = segmentEntry[1];
91
+ params[key] = value;
92
+ }
93
+ }
94
+ } else if (typeof currentSegments === "object" && !Array.isArray(currentSegments)) {
95
+ const segmentObject = currentSegments;
96
+ for (const key in segmentObject) {
97
+ if (Object.prototype.hasOwnProperty.call(segmentObject, key)) {
98
+ params[key] = segmentObject[key];
99
+ }
100
+ }
101
+ }
102
+ }
103
+ return params;
104
+ }, [routeParams.segments]);
105
+ const newLazyCacheNode = {
106
+ lazyData: null,
107
+ rsc: null,
108
+ prefetchRsc: null,
109
+ head: null,
110
+ prefetchHead: null,
111
+ parallelRoutes: /* @__PURE__ */ new Map(),
112
+ loading: null
113
+ };
114
+ return React4.createElement(PathParamsContext.Provider, { value: pathParams }, React4.createElement(PathnameContext.Provider, { value: pathname }, React4.createElement(SearchParamsContext.Provider, { value: new URLSearchParams(query) }, React4.createElement(
115
+ GlobalLayoutRouterContext.Provider,
116
+ {
117
+ value: {
118
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
119
+ // @ts-ignore (Only available in Next.js >= v15.1.1)
120
+ changeByServerResponse() {
121
+ },
122
+ buildId: "storybook",
123
+ tree,
124
+ focusAndScrollRef: {
125
+ apply: false,
126
+ hashFragment: null,
127
+ segmentPaths: [tree],
128
+ onlyHashChange: false
129
+ },
130
+ nextUrl: pathname
131
+ }
132
+ },
133
+ React4.createElement(AppRouterContext.Provider, { value: getRouter() }, React4.createElement(
134
+ LayoutRouterContext.Provider,
135
+ {
136
+ value: {
137
+ // TODO Remove when dropping Next.js < v15.1.1
138
+ childNodes: /* @__PURE__ */ new Map(),
139
+ tree,
140
+ // TODO END
141
+ // START Next.js v15.2 support
142
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
143
+ // @ts-ignore Only available in Next.js >= v15.1.1
144
+ parentTree: tree,
145
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
146
+ // @ts-ignore Only available in Next.js >= v15.1.1
147
+ parentCacheNode: newLazyCacheNode,
148
+ // END
149
+ url: pathname,
150
+ loading: null
151
+ }
152
+ },
153
+ children
154
+ ))
155
+ ))));
156
+ }, "AppRouterProvider");
157
+
158
+ // src/routing/page-router-provider.tsx
159
+ import React5 from "react";
160
+ import { getRouter as getRouter2 } from "@storybook/nextjs/router.mock";
161
+ import { RouterContext } from "next/dist/shared/lib/router-context.shared-runtime";
162
+ var PageRouterProvider = /* @__PURE__ */ __name(({ children }) => React5.createElement(RouterContext.Provider, { value: getRouter2() }, children), "PageRouterProvider");
163
+
164
+ // src/routing/decorator.tsx
165
+ var defaultRouterParams = {
166
+ pathname: "/",
167
+ query: {}
168
+ };
169
+ var RouterDecorator = /* @__PURE__ */ __name((Story, { parameters: parameters2 }) => {
170
+ const nextAppDirectory = parameters2.nextjs?.appDirectory ?? false;
171
+ if (nextAppDirectory) {
172
+ if (!AppRouterProvider) {
173
+ return null;
174
+ }
175
+ return React6.createElement(
176
+ AppRouterProvider,
177
+ {
178
+ routeParams: {
179
+ ...defaultRouterParams,
180
+ ...parameters2.nextjs?.navigation
181
+ }
182
+ },
183
+ React6.createElement(RedirectBoundary, null, React6.createElement(Story, null))
184
+ );
185
+ }
186
+ return React6.createElement(PageRouterProvider, null, React6.createElement(Story, null));
187
+ }, "RouterDecorator");
188
+
189
+ // src/styledJsx/decorator.tsx
190
+ import * as React7 from "react";
191
+ import { StyleRegistry } from "styled-jsx";
192
+ var StyledJsxDecorator = /* @__PURE__ */ __name((Story) => React7.createElement(StyleRegistry, null, React7.createElement(Story, null)), "StyledJsxDecorator");
193
+
194
+ // src/preview.tsx
195
+ function addNextHeadCount() {
196
+ const meta = document.createElement("meta");
197
+ meta.name = "next-head-count";
198
+ meta.content = "0";
199
+ document.head.appendChild(meta);
200
+ }
201
+ __name(addNextHeadCount, "addNextHeadCount");
202
+ function isAsyncClientComponentError(error) {
203
+ return typeof error === "string" && (error.includes("Only Server Components can be async at the moment.") || error.includes("A component was suspended by an uncached promise.") || error.includes("async/await is not yet supported in Client Components"));
204
+ }
205
+ __name(isAsyncClientComponentError, "isAsyncClientComponentError");
206
+ addNextHeadCount();
207
+ var origConsoleError = globalThis.console.error;
208
+ globalThis.console.error = (...args) => {
209
+ const error = args[0];
210
+ if (isNextRouterError(error) || isAsyncClientComponentError(error)) {
211
+ return;
212
+ }
213
+ origConsoleError.apply(globalThis.console, args);
214
+ };
215
+ globalThis.addEventListener("error", (ev) => {
216
+ if (isNextRouterError(ev.error) || isAsyncClientComponentError(ev.error)) {
217
+ ev.preventDefault();
218
+ return;
219
+ }
220
+ });
221
+ var decorators = [
222
+ StyledJsxDecorator,
223
+ ImageDecorator,
224
+ RouterDecorator,
225
+ HeadManagerDecorator
226
+ ];
227
+ var loaders = /* @__PURE__ */ __name(async ({ globals, parameters: parameters2 }) => {
228
+ const { router, appDirectory } = parameters2.nextjs ?? {};
229
+ if (appDirectory) {
230
+ createNavigation(router);
231
+ } else {
232
+ createRouter({
233
+ locale: globals.locale,
234
+ ...router
235
+ });
236
+ }
237
+ }, "loaders");
238
+ var parameters = {
239
+ docs: {
240
+ source: {
241
+ excludeDecorators: true
242
+ }
243
+ },
244
+ react: {
245
+ rootOptions: {
246
+ onCaughtError(error) {
247
+ if (isNextRouterError(error)) {
248
+ return;
249
+ }
250
+ console.error(error);
251
+ }
252
+ }
253
+ }
254
+ };
255
+
256
+ export {
257
+ decorators,
258
+ loaders,
259
+ parameters,
260
+ preview_exports
261
+ };
@@ -0,0 +1,37 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __commonJS = (cb, mod) => function __require() {
9
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
10
+ };
11
+ var __export = (target, all) => {
12
+ for (var name in all)
13
+ __defProp(target, name, { get: all[name], enumerable: true });
14
+ };
15
+ var __copyProps = (to, from, except, desc) => {
16
+ if (from && typeof from === "object" || typeof from === "function") {
17
+ for (let key of __getOwnPropNames(from))
18
+ if (!__hasOwnProp.call(to, key) && key !== except)
19
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
20
+ }
21
+ return to;
22
+ };
23
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
24
+ // If the importer is in node compatibility mode or this is not an ESM
25
+ // file that has been converted to a CommonJS file using a Babel-
26
+ // compatible transform (i.e. "__esModule" has not been set), then set
27
+ // "default" to the CommonJS "module.exports" for node compatibility.
28
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
29
+ mod
30
+ ));
31
+
32
+ export {
33
+ __name,
34
+ __commonJS,
35
+ __export,
36
+ __toESM
37
+ };
@@ -0,0 +1,71 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-L5NVL7MD.js";
4
+
5
+ // ../../lib/react-dom-shim/dist/_browser-chunks/chunk-JK72E6FR.js
6
+ var __defProp = Object.defineProperty;
7
+ var __name2 = /* @__PURE__ */ __name((target, value) => __defProp(target, "name", { value, configurable: true }), "__name");
8
+
9
+ // ../../lib/react-dom-shim/dist/react-18.js
10
+ import * as React from "react";
11
+ import * as ReactDOM from "react-dom/client";
12
+ var nodes = /* @__PURE__ */ new Map();
13
+ function getIsReactActEnvironment() {
14
+ return globalThis.IS_REACT_ACT_ENVIRONMENT;
15
+ }
16
+ __name(getIsReactActEnvironment, "getIsReactActEnvironment");
17
+ __name2(getIsReactActEnvironment, "getIsReactActEnvironment");
18
+ var WithCallback = __name2(({
19
+ callback,
20
+ children
21
+ }) => {
22
+ const once = React.useRef();
23
+ React.useLayoutEffect(() => {
24
+ if (once.current === callback) {
25
+ return;
26
+ }
27
+ once.current = callback;
28
+ callback();
29
+ }, [callback]);
30
+ return children;
31
+ }, "WithCallback");
32
+ if (typeof Promise.withResolvers === "undefined") {
33
+ Promise.withResolvers = () => {
34
+ let resolve = null;
35
+ let reject = null;
36
+ const promise = new Promise((res, rej) => {
37
+ resolve = res;
38
+ reject = rej;
39
+ });
40
+ return { promise, resolve, reject };
41
+ };
42
+ }
43
+ var renderElement = __name2(async (node, el, rootOptions) => {
44
+ const root = await getReactRoot(el, rootOptions);
45
+ if (getIsReactActEnvironment()) {
46
+ root.render(node);
47
+ return;
48
+ }
49
+ const { promise, resolve } = Promise.withResolvers();
50
+ root.render(React.createElement(WithCallback, { callback: resolve }, node));
51
+ return promise;
52
+ }, "renderElement");
53
+ var unmountElement = __name2((el, shouldUseNewRootApi) => {
54
+ const root = nodes.get(el);
55
+ if (root) {
56
+ root.unmount();
57
+ nodes.delete(el);
58
+ }
59
+ }, "unmountElement");
60
+ var getReactRoot = __name2(async (el, rootOptions) => {
61
+ let root = nodes.get(el);
62
+ if (!root) {
63
+ root = ReactDOM.createRoot(el, rootOptions);
64
+ nodes.set(el, root);
65
+ }
66
+ return root;
67
+ }, "getReactRoot");
68
+ export {
69
+ renderElement,
70
+ unmountElement
71
+ };
@@ -0,0 +1,74 @@
1
+ import CJS_COMPAT_NODE_URL_e3twfmexlgl from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_e3twfmexlgl from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_e3twfmexlgl from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_e3twfmexlgl.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_e3twfmexlgl.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_e3twfmexlgl.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import {
13
+ addScopedAlias,
14
+ getNextjsVersion,
15
+ setAlias
16
+ } from "./chunk-EZEBG77A.js";
17
+ import {
18
+ __name
19
+ } from "./chunk-WCSGFZKZ.js";
20
+
21
+ // src/compatibility/compatibility-map.ts
22
+ import semver from "semver";
23
+ var mapping = {
24
+ "<15.0.0": {
25
+ "next/dist/server/request/headers": "next/dist/client/components/headers",
26
+ // this path only exists from Next 15 onwards
27
+ "next/dist/server/request/draft-mode": "@storybook/nextjs/compatibility/draft-mode.compat"
28
+ }
29
+ };
30
+ var getCompatibilityAliases = /* @__PURE__ */ __name(() => {
31
+ const version = getNextjsVersion();
32
+ const result = {};
33
+ Object.keys(mapping).forEach((key) => {
34
+ if (semver.intersects(version, key)) {
35
+ Object.assign(result, mapping[key]);
36
+ }
37
+ });
38
+ return result;
39
+ }, "getCompatibilityAliases");
40
+ var configureCompatibilityAliases = /* @__PURE__ */ __name((baseConfig) => {
41
+ const aliases = getCompatibilityAliases();
42
+ Object.entries(aliases).forEach(([name, alias]) => {
43
+ if (typeof alias === "string") {
44
+ addScopedAlias(baseConfig, name, alias);
45
+ } else {
46
+ setAlias(baseConfig, name, alias);
47
+ }
48
+ });
49
+ }, "configureCompatibilityAliases");
50
+
51
+ // src/export-mocks/webpack.ts
52
+ var mapping2 = {
53
+ "next/headers": "@storybook/nextjs/headers.mock",
54
+ "next/navigation": "@storybook/nextjs/navigation.mock",
55
+ "next/router": "@storybook/nextjs/router.mock",
56
+ "next/cache": "@storybook/nextjs/cache.mock",
57
+ ...getCompatibilityAliases()
58
+ };
59
+ var getPackageAliases = /* @__PURE__ */ __name(() => {
60
+ return mapping2;
61
+ }, "getPackageAliases");
62
+ var configureNextExportMocks = /* @__PURE__ */ __name((baseConfig) => {
63
+ const resolve = baseConfig.resolve ?? {};
64
+ resolve.alias = {
65
+ ...resolve.alias,
66
+ ...mapping2
67
+ };
68
+ }, "configureNextExportMocks");
69
+
70
+ export {
71
+ configureCompatibilityAliases,
72
+ getPackageAliases,
73
+ configureNextExportMocks
74
+ };
@@ -0,0 +1,88 @@
1
+ import CJS_COMPAT_NODE_URL_e3twfmexlgl from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_e3twfmexlgl from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_e3twfmexlgl from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_e3twfmexlgl.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_e3twfmexlgl.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_e3twfmexlgl.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ import {
13
+ resolvePackageDir
14
+ } from "./chunk-YMVPQWBH.js";
15
+ import {
16
+ __name
17
+ } from "./chunk-WCSGFZKZ.js";
18
+
19
+ // src/utils.ts
20
+ import { readFileSync } from "node:fs";
21
+ import { dirname, join, sep } from "node:path";
22
+ import { fileURLToPath } from "node:url";
23
+ import { getProjectRoot } from "storybook/internal/common";
24
+ import { PHASE_DEVELOPMENT_SERVER } from "next/constants.js";
25
+ import nextJsLoadConfigModule from "next/dist/server/config.js";
26
+ import webpack from "webpack";
27
+ var configureRuntimeNextjsVersionResolution = /* @__PURE__ */ __name((baseConfig) => {
28
+ const { DefinePlugin } = webpack;
29
+ baseConfig.plugins?.push(
30
+ new DefinePlugin({
31
+ "process.env.__NEXT_VERSION": JSON.stringify(getNextjsVersion())
32
+ })
33
+ );
34
+ }, "configureRuntimeNextjsVersionResolution");
35
+ var getNextjsVersion = /* @__PURE__ */ __name(() => JSON.parse(readFileSync(join(resolvePackageDir("next"), "package.json"), "utf8")).version, "getNextjsVersion");
36
+ var resolveNextConfig = /* @__PURE__ */ __name(async ({
37
+ nextConfigPath
38
+ }) => {
39
+ const dir = nextConfigPath ? dirname(nextConfigPath) : getProjectRoot();
40
+ const loadConfig = nextJsLoadConfigModule.default ?? nextJsLoadConfigModule;
41
+ return loadConfig(PHASE_DEVELOPMENT_SERVER, dir, void 0);
42
+ }, "resolveNextConfig");
43
+ function setAlias(baseConfig, name, alias) {
44
+ baseConfig.resolve ??= {};
45
+ baseConfig.resolve.alias ??= {};
46
+ const aliasConfig = baseConfig.resolve.alias;
47
+ if (Array.isArray(aliasConfig)) {
48
+ aliasConfig.push({
49
+ name,
50
+ alias
51
+ });
52
+ } else {
53
+ aliasConfig[name] = alias;
54
+ }
55
+ }
56
+ __name(setAlias, "setAlias");
57
+ var addScopedAlias = /* @__PURE__ */ __name((baseConfig, name, alias) => {
58
+ const scopedAlias = scopedResolve(`${alias ?? name}`);
59
+ setAlias(baseConfig, name, scopedAlias);
60
+ }, "addScopedAlias");
61
+ var scopedResolve = /* @__PURE__ */ __name((id) => {
62
+ const scopedModulePath = fileURLToPath(import.meta.resolve(id));
63
+ const idWithNativePathSep = id.replace(/\//g, sep);
64
+ if (scopedModulePath.endsWith(idWithNativePathSep)) {
65
+ return scopedModulePath;
66
+ }
67
+ const moduleFolderStrPosition = scopedModulePath.lastIndexOf(idWithNativePathSep);
68
+ const beginningOfMainScriptPath = moduleFolderStrPosition + id.length;
69
+ return scopedModulePath.substring(0, beginningOfMainScriptPath);
70
+ }, "scopedResolve");
71
+ function getNodeModulesExcludeRegex(transpilePackages) {
72
+ if (!transpilePackages || transpilePackages.length === 0) {
73
+ return /node_modules/;
74
+ }
75
+ const escaped = transpilePackages.map((pkg) => pkg.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")).join("|");
76
+ return new RegExp(`node_modules/(?!(${escaped})/)`);
77
+ }
78
+ __name(getNodeModulesExcludeRegex, "getNodeModulesExcludeRegex");
79
+
80
+ export {
81
+ configureRuntimeNextjsVersionResolution,
82
+ getNextjsVersion,
83
+ resolveNextConfig,
84
+ setAlias,
85
+ addScopedAlias,
86
+ scopedResolve,
87
+ getNodeModulesExcludeRegex
88
+ };
@@ -0,0 +1,17 @@
1
+ import CJS_COMPAT_NODE_URL_e3twfmexlgl from 'node:url';
2
+ import CJS_COMPAT_NODE_PATH_e3twfmexlgl from 'node:path';
3
+ import CJS_COMPAT_NODE_MODULE_e3twfmexlgl from "node:module";
4
+
5
+ var __filename = CJS_COMPAT_NODE_URL_e3twfmexlgl.fileURLToPath(import.meta.url);
6
+ var __dirname = CJS_COMPAT_NODE_PATH_e3twfmexlgl.dirname(__filename);
7
+ var require = CJS_COMPAT_NODE_MODULE_e3twfmexlgl.createRequire(import.meta.url);
8
+
9
+ // ------------------------------------------------------------
10
+ // end of CJS compatibility banner, injected by Storybook's esbuild configuration
11
+ // ------------------------------------------------------------
12
+ var __defProp = Object.defineProperty;
13
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
14
+
15
+ export {
16
+ __name
17
+ };