@storybook/nextjs-vite 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.
- package/README.md +3 -1
- package/dist/_browser-chunks/chunk-2RWWBM6A.js +261 -0
- package/dist/_browser-chunks/chunk-L5NVL7MD.js +37 -0
- package/dist/_browser-chunks/react-18-G7Q4PNHD.js +71 -0
- package/dist/_node-chunks/chunk-IHKOVONR.js +54 -0
- package/dist/_node-chunks/dist-YEP22NZU.js +7476 -0
- package/dist/_node-chunks/jiti-4UV67MCQ.js +32362 -0
- package/dist/export-mocks/cache/index.d.ts +308 -1
- package/dist/export-mocks/cache/index.js +22 -1
- package/dist/export-mocks/headers/index.d.ts +309 -1
- package/dist/export-mocks/headers/index.js +77 -1
- package/dist/export-mocks/navigation/index.js +81 -1
- package/dist/export-mocks/router/index.d.ts +2 -2
- package/dist/export-mocks/router/index.js +97 -1
- package/dist/index.d.ts +51 -7
- package/dist/index.js +22153 -45
- package/dist/node/index.d.ts +25 -5
- package/dist/node/index.js +23 -1
- package/dist/preset.js +714 -580
- package/dist/preview.d.ts +3 -19
- package/dist/preview.d.tsx +19 -0
- package/dist/preview.js +11 -1
- package/dist/vite-plugin/index.d.ts +1 -3
- package/dist/vite-plugin/index.js +21 -1
- package/package.json +35 -83
- package/preset.js +1 -1
- package/template/cli/js/Configure.mdx +11 -11
- package/template/cli/ts/Configure.mdx +11 -11
- package/dist/chunk-GKRSUUNG.mjs +0 -6
- package/dist/chunk-J3BB7LEU.mjs +0 -20
- package/dist/chunk-XP5HYGXS.mjs +0 -3
- package/dist/export-mocks/cache/index.mjs +0 -6
- package/dist/export-mocks/headers/index.mjs +0 -12
- package/dist/export-mocks/navigation/index.mjs +0 -11
- package/dist/export-mocks/router/index.mjs +0 -10
- package/dist/images/decorator.d.ts +0 -6
- package/dist/images/decorator.js +0 -1
- package/dist/images/decorator.mjs +0 -2
- package/dist/index.d-ff220430.d.ts +0 -310
- package/dist/index.mjs +0 -57
- package/dist/node/index.mjs +0 -5
- package/dist/preset.d.ts +0 -9
- package/dist/preview.mjs +0 -3
- package/dist/react-18-IGIL3GJQ.mjs +0 -7
- package/dist/types-d044381e.d.ts +0 -52
- package/dist/vite-plugin/index.mjs +0 -6
|
@@ -1 +1,77 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "../../_browser-chunks/chunk-L5NVL7MD.js";
|
|
4
|
+
|
|
5
|
+
// src/export-mocks/headers/index.ts
|
|
6
|
+
import { draftMode as originalDraftMode } from "next/dist/server/request/draft-mode";
|
|
7
|
+
import * as headers3 from "next/dist/server/request/headers";
|
|
8
|
+
import { fn as fn3 } from "storybook/test";
|
|
9
|
+
export * from "next/dist/server/request/headers";
|
|
10
|
+
|
|
11
|
+
// src/export-mocks/headers/headers.ts
|
|
12
|
+
import { HeadersAdapter } from "next/dist/server/web/spec-extension/adapters/headers";
|
|
13
|
+
import { fn } from "storybook/test";
|
|
14
|
+
var _HeadersAdapterMock = class _HeadersAdapterMock extends HeadersAdapter {
|
|
15
|
+
constructor() {
|
|
16
|
+
super({});
|
|
17
|
+
this.append = fn(super.append.bind(this)).mockName("next/headers::headers().append");
|
|
18
|
+
this.delete = fn(super.delete.bind(this)).mockName("next/headers::headers().delete");
|
|
19
|
+
this.get = fn(super.get.bind(this)).mockName("next/headers::headers().get");
|
|
20
|
+
this.has = fn(super.has.bind(this)).mockName("next/headers::headers().has");
|
|
21
|
+
this.set = fn(super.set.bind(this)).mockName("next/headers::headers().set");
|
|
22
|
+
this.forEach = fn(super.forEach.bind(this)).mockName("next/headers::headers().forEach");
|
|
23
|
+
this.entries = fn(super.entries.bind(this)).mockName("next/headers::headers().entries");
|
|
24
|
+
this.keys = fn(super.keys.bind(this)).mockName("next/headers::headers().keys");
|
|
25
|
+
this.values = fn(super.values.bind(this)).mockName("next/headers::headers().values");
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
__name(_HeadersAdapterMock, "HeadersAdapterMock");
|
|
29
|
+
var HeadersAdapterMock = _HeadersAdapterMock;
|
|
30
|
+
var headersAdapterMock;
|
|
31
|
+
var headers = /* @__PURE__ */ __name(() => {
|
|
32
|
+
if (!headersAdapterMock) {
|
|
33
|
+
headersAdapterMock = new HeadersAdapterMock();
|
|
34
|
+
}
|
|
35
|
+
return headersAdapterMock;
|
|
36
|
+
}, "headers");
|
|
37
|
+
headers.mockRestore = () => {
|
|
38
|
+
headersAdapterMock = new HeadersAdapterMock();
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/export-mocks/headers/cookies.ts
|
|
42
|
+
import { headers as headers2 } from "@storybook/nextjs-vite/headers.mock";
|
|
43
|
+
import { RequestCookies } from "next/dist/compiled/@edge-runtime/cookies";
|
|
44
|
+
import { fn as fn2 } from "storybook/test";
|
|
45
|
+
var _RequestCookiesMock = class _RequestCookiesMock extends RequestCookies {
|
|
46
|
+
constructor() {
|
|
47
|
+
super(...arguments);
|
|
48
|
+
this.get = fn2(super.get.bind(this)).mockName("next/headers::cookies().get");
|
|
49
|
+
this.getAll = fn2(super.getAll.bind(this)).mockName("next/headers::cookies().getAll");
|
|
50
|
+
this.has = fn2(super.has.bind(this)).mockName("next/headers::cookies().has");
|
|
51
|
+
this.set = fn2(super.set.bind(this)).mockName("next/headers::cookies().set");
|
|
52
|
+
this.delete = fn2(super.delete.bind(this)).mockName("next/headers::cookies().delete");
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
__name(_RequestCookiesMock, "RequestCookiesMock");
|
|
56
|
+
var RequestCookiesMock = _RequestCookiesMock;
|
|
57
|
+
var requestCookiesMock;
|
|
58
|
+
var cookies = fn2(() => {
|
|
59
|
+
if (!requestCookiesMock) {
|
|
60
|
+
requestCookiesMock = new RequestCookiesMock(headers2());
|
|
61
|
+
}
|
|
62
|
+
return requestCookiesMock;
|
|
63
|
+
}).mockName("next/headers::cookies()");
|
|
64
|
+
var originalRestore = cookies.mockRestore.bind(null);
|
|
65
|
+
cookies.mockRestore = () => {
|
|
66
|
+
originalRestore();
|
|
67
|
+
headers2.mockRestore();
|
|
68
|
+
requestCookiesMock = new RequestCookiesMock(headers2());
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
// src/export-mocks/headers/index.ts
|
|
72
|
+
var draftMode2 = fn3(originalDraftMode ?? headers3.draftMode).mockName("draftMode");
|
|
73
|
+
export {
|
|
74
|
+
cookies,
|
|
75
|
+
draftMode2 as draftMode,
|
|
76
|
+
headers
|
|
77
|
+
};
|
|
@@ -1 +1,81 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "../../_browser-chunks/chunk-L5NVL7MD.js";
|
|
4
|
+
|
|
5
|
+
// src/export-mocks/navigation/index.ts
|
|
6
|
+
import { NextjsRouterMocksNotAvailable } from "storybook/internal/preview-errors";
|
|
7
|
+
import * as actual from "next/dist/client/components/navigation";
|
|
8
|
+
import { getRedirectError } from "next/dist/client/components/redirect";
|
|
9
|
+
import { RedirectStatusCode } from "next/dist/client/components/redirect-status-code";
|
|
10
|
+
import { fn } from "storybook/test";
|
|
11
|
+
export * from "next/dist/client/components/navigation";
|
|
12
|
+
var navigationAPI;
|
|
13
|
+
var createNavigation = /* @__PURE__ */ __name((overrides) => {
|
|
14
|
+
const navigationActions = {
|
|
15
|
+
push: fn().mockName("next/navigation::useRouter().push"),
|
|
16
|
+
replace: fn().mockName("next/navigation::useRouter().replace"),
|
|
17
|
+
forward: fn().mockName("next/navigation::useRouter().forward"),
|
|
18
|
+
back: fn().mockName("next/navigation::useRouter().back"),
|
|
19
|
+
prefetch: fn().mockName("next/navigation::useRouter().prefetch"),
|
|
20
|
+
refresh: fn().mockName("next/navigation::useRouter().refresh")
|
|
21
|
+
};
|
|
22
|
+
if (overrides) {
|
|
23
|
+
Object.keys(navigationActions).forEach((key) => {
|
|
24
|
+
if (key in overrides) {
|
|
25
|
+
navigationActions[key] = fn((...args) => {
|
|
26
|
+
return overrides[key](...args);
|
|
27
|
+
}).mockName(`useRouter().${key}`);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
navigationAPI = navigationActions;
|
|
32
|
+
return navigationAPI;
|
|
33
|
+
}, "createNavigation");
|
|
34
|
+
var getRouter = /* @__PURE__ */ __name(() => {
|
|
35
|
+
if (!navigationAPI) {
|
|
36
|
+
throw new NextjsRouterMocksNotAvailable({
|
|
37
|
+
importType: "next/navigation"
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return navigationAPI;
|
|
41
|
+
}, "getRouter");
|
|
42
|
+
var redirect = fn(
|
|
43
|
+
(url, type = actual.RedirectType.push) => {
|
|
44
|
+
throw getRedirectError(url, type, RedirectStatusCode.SeeOther);
|
|
45
|
+
}
|
|
46
|
+
).mockName("next/navigation::redirect");
|
|
47
|
+
var permanentRedirect = fn(
|
|
48
|
+
(url, type = actual.RedirectType.push) => {
|
|
49
|
+
throw getRedirectError(url, type, RedirectStatusCode.SeeOther);
|
|
50
|
+
}
|
|
51
|
+
).mockName("next/navigation::permanentRedirect");
|
|
52
|
+
var useSearchParams2 = fn(actual.useSearchParams).mockName(
|
|
53
|
+
"next/navigation::useSearchParams"
|
|
54
|
+
);
|
|
55
|
+
var usePathname2 = fn(actual.usePathname).mockName("next/navigation::usePathname");
|
|
56
|
+
var useSelectedLayoutSegment2 = fn(actual.useSelectedLayoutSegment).mockName(
|
|
57
|
+
"next/navigation::useSelectedLayoutSegment"
|
|
58
|
+
);
|
|
59
|
+
var useSelectedLayoutSegments2 = fn(actual.useSelectedLayoutSegments).mockName(
|
|
60
|
+
"next/navigation::useSelectedLayoutSegments"
|
|
61
|
+
);
|
|
62
|
+
var useRouter2 = fn(actual.useRouter).mockName("next/navigation::useRouter");
|
|
63
|
+
var useServerInsertedHTML2 = fn(actual.useServerInsertedHTML).mockName(
|
|
64
|
+
"next/navigation::useServerInsertedHTML"
|
|
65
|
+
);
|
|
66
|
+
var notFound2 = fn(actual.notFound).mockName("next/navigation::notFound");
|
|
67
|
+
var useParams2 = fn(actual.useParams).mockName("next/navigation::useParams");
|
|
68
|
+
export {
|
|
69
|
+
createNavigation,
|
|
70
|
+
getRouter,
|
|
71
|
+
notFound2 as notFound,
|
|
72
|
+
permanentRedirect,
|
|
73
|
+
redirect,
|
|
74
|
+
useParams2 as useParams,
|
|
75
|
+
usePathname2 as usePathname,
|
|
76
|
+
useRouter2 as useRouter,
|
|
77
|
+
useSearchParams2 as useSearchParams,
|
|
78
|
+
useSelectedLayoutSegment2 as useSelectedLayoutSegment,
|
|
79
|
+
useSelectedLayoutSegments2 as useSelectedLayoutSegments,
|
|
80
|
+
useServerInsertedHTML2 as useServerInsertedHTML
|
|
81
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as react from 'react';
|
|
2
2
|
import * as next_dist_client_with_router from 'next/dist/client/with-router';
|
|
3
3
|
import * as next from 'next';
|
|
4
4
|
import * as singletonRouter from 'next/dist/client/router';
|
|
@@ -41,6 +41,6 @@ declare const getRouter: () => {
|
|
|
41
41
|
};
|
|
42
42
|
|
|
43
43
|
declare const useRouter: Mock<typeof singletonRouter.useRouter>;
|
|
44
|
-
declare const withRouter: Mock<(ComposedComponent: next.NextComponentType<next.NextPageContext, any, next_dist_client_with_router.WithRouterProps>) =>
|
|
44
|
+
declare const withRouter: Mock<(ComposedComponent: next.NextComponentType<next.NextPageContext, any, next_dist_client_with_router.WithRouterProps>) => react.ComponentType<next_dist_client_with_router.ExcludeRouterProps<next_dist_client_with_router.WithRouterProps>>>;
|
|
45
45
|
|
|
46
46
|
export { createRouter, getRouter, useRouter, withRouter };
|
|
@@ -1 +1,97 @@
|
|
|
1
|
-
|
|
1
|
+
import {
|
|
2
|
+
__name
|
|
3
|
+
} from "../../_browser-chunks/chunk-L5NVL7MD.js";
|
|
4
|
+
|
|
5
|
+
// src/export-mocks/router/index.ts
|
|
6
|
+
import { NextjsRouterMocksNotAvailable } from "storybook/internal/preview-errors";
|
|
7
|
+
import singletonRouter, * as originalRouter from "next/dist/client/router";
|
|
8
|
+
import { fn } from "storybook/test";
|
|
9
|
+
export * from "next/dist/client/router";
|
|
10
|
+
var defaultRouterState = {
|
|
11
|
+
route: "/",
|
|
12
|
+
asPath: "/",
|
|
13
|
+
basePath: "/",
|
|
14
|
+
pathname: "/",
|
|
15
|
+
query: {},
|
|
16
|
+
isFallback: false,
|
|
17
|
+
isLocaleDomain: false,
|
|
18
|
+
isReady: true,
|
|
19
|
+
isPreview: false
|
|
20
|
+
};
|
|
21
|
+
var routerAPI;
|
|
22
|
+
var createRouter = /* @__PURE__ */ __name((overrides) => {
|
|
23
|
+
const routerActions = {
|
|
24
|
+
push: fn((..._args) => {
|
|
25
|
+
return Promise.resolve(true);
|
|
26
|
+
}).mockName("next/router::useRouter().push"),
|
|
27
|
+
replace: fn((..._args) => {
|
|
28
|
+
return Promise.resolve(true);
|
|
29
|
+
}).mockName("next/router::useRouter().replace"),
|
|
30
|
+
reload: fn((..._args) => {
|
|
31
|
+
}).mockName("next/router::useRouter().reload"),
|
|
32
|
+
back: fn((..._args) => {
|
|
33
|
+
}).mockName("next/router::useRouter().back"),
|
|
34
|
+
forward: fn(() => {
|
|
35
|
+
}).mockName("next/router::useRouter().forward"),
|
|
36
|
+
prefetch: fn((..._args) => {
|
|
37
|
+
return Promise.resolve();
|
|
38
|
+
}).mockName("next/router::useRouter().prefetch"),
|
|
39
|
+
beforePopState: fn((..._args) => {
|
|
40
|
+
}).mockName("next/router::useRouter().beforePopState")
|
|
41
|
+
};
|
|
42
|
+
const routerEvents = {
|
|
43
|
+
on: fn((..._args) => {
|
|
44
|
+
}).mockName("next/router::useRouter().events.on"),
|
|
45
|
+
off: fn((..._args) => {
|
|
46
|
+
}).mockName("next/router::useRouter().events.off"),
|
|
47
|
+
emit: fn((..._args) => {
|
|
48
|
+
}).mockName("next/router::useRouter().events.emit")
|
|
49
|
+
};
|
|
50
|
+
if (overrides) {
|
|
51
|
+
Object.keys(routerActions).forEach((key) => {
|
|
52
|
+
if (key in overrides) {
|
|
53
|
+
routerActions[key] = fn((...args) => {
|
|
54
|
+
return overrides[key](...args);
|
|
55
|
+
}).mockName(`useRouter().${key}`);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
if (overrides?.events) {
|
|
60
|
+
Object.keys(routerEvents).forEach((key) => {
|
|
61
|
+
if (key in routerEvents) {
|
|
62
|
+
routerEvents[key] = fn((...args) => {
|
|
63
|
+
return overrides.events[key](...args);
|
|
64
|
+
}).mockName(`useRouter().events.${key}`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
routerAPI = {
|
|
69
|
+
...defaultRouterState,
|
|
70
|
+
...overrides,
|
|
71
|
+
...routerActions,
|
|
72
|
+
// @ts-expect-error TODO improve typings
|
|
73
|
+
events: routerEvents
|
|
74
|
+
};
|
|
75
|
+
singletonRouter.router = routerAPI;
|
|
76
|
+
singletonRouter.readyCallbacks.forEach((cb) => cb());
|
|
77
|
+
singletonRouter.readyCallbacks = [];
|
|
78
|
+
return routerAPI;
|
|
79
|
+
}, "createRouter");
|
|
80
|
+
var getRouter = /* @__PURE__ */ __name(() => {
|
|
81
|
+
if (!routerAPI) {
|
|
82
|
+
throw new NextjsRouterMocksNotAvailable({
|
|
83
|
+
importType: "next/router"
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
return routerAPI;
|
|
87
|
+
}, "getRouter");
|
|
88
|
+
var router_default = singletonRouter;
|
|
89
|
+
var useRouter2 = fn(originalRouter.useRouter).mockName("next/router::useRouter");
|
|
90
|
+
var withRouter2 = fn(originalRouter.withRouter).mockName("next/router::withRouter");
|
|
91
|
+
export {
|
|
92
|
+
createRouter,
|
|
93
|
+
router_default as default,
|
|
94
|
+
getRouter,
|
|
95
|
+
useRouter2 as useRouter,
|
|
96
|
+
withRouter2 as withRouter
|
|
97
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,13 +1,57 @@
|
|
|
1
1
|
import { PreviewAddon, InferTypes, AddonTypes } from 'storybook/internal/csf';
|
|
2
|
-
import { NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations, Args, StoryAnnotationsOrFn, ProjectAnnotations, ComposedStoryFn, Store_CSFExports, StoriesWithPartialProps } from 'storybook/internal/types';
|
|
2
|
+
import { CompatibleString, NamedOrDefaultProjectAnnotations, NormalizedProjectAnnotations, Args, StoryAnnotationsOrFn, ProjectAnnotations, ComposedStoryFn, Store_CSFExports, StoriesWithPartialProps } from 'storybook/internal/types';
|
|
3
3
|
import { ReactRenderer, Meta, ReactTypes, ReactPreview } from '@storybook/react';
|
|
4
4
|
export * from '@storybook/react';
|
|
5
5
|
import vitePluginStorybookNextJs from 'vite-plugin-storybook-nextjs';
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import '
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
import { BuilderOptions } from '@storybook/builder-vite';
|
|
7
|
+
import { StorybookConfig as StorybookConfig$1 } from '@storybook/react-vite';
|
|
8
|
+
import { NextRouter } from 'next/router';
|
|
9
|
+
|
|
10
|
+
type FrameworkName = CompatibleString<'@storybook/nextjs-vite'>;
|
|
11
|
+
type BuilderName = CompatibleString<'@storybook/builder-vite'>;
|
|
12
|
+
type FrameworkOptions = {
|
|
13
|
+
/** The path to the Next.js configuration file. */
|
|
14
|
+
nextConfigPath?: string;
|
|
15
|
+
builder?: BuilderOptions;
|
|
16
|
+
};
|
|
17
|
+
type StorybookConfigFramework = {
|
|
18
|
+
framework: FrameworkName | {
|
|
19
|
+
name: FrameworkName;
|
|
20
|
+
options: FrameworkOptions;
|
|
21
|
+
};
|
|
22
|
+
core?: StorybookConfig$1['core'] & {
|
|
23
|
+
builder?: BuilderName | {
|
|
24
|
+
name: BuilderName;
|
|
25
|
+
options: BuilderOptions;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
/** The interface for Storybook configuration in `main.ts` files. */
|
|
30
|
+
type StorybookConfig = Omit<StorybookConfig$1, keyof StorybookConfigFramework> & StorybookConfigFramework;
|
|
31
|
+
interface NextJsParameters {
|
|
32
|
+
/**
|
|
33
|
+
* Next.js framework configuration
|
|
34
|
+
*
|
|
35
|
+
* @see https://storybook.js.org/docs/get-started/frameworks/nextjs
|
|
36
|
+
*/
|
|
37
|
+
nextjs?: {
|
|
38
|
+
/**
|
|
39
|
+
* Enable App Directory features If your story imports components that use next/navigation, you
|
|
40
|
+
* need to set this parameter to true
|
|
41
|
+
*/
|
|
42
|
+
appDirectory?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Next.js navigation configuration when using `next/navigation`. Please note that it can only
|
|
45
|
+
* be used in components/pages in the app directory.
|
|
46
|
+
*/
|
|
47
|
+
navigation?: Partial<NextRouter>;
|
|
48
|
+
/** Next.js router configuration */
|
|
49
|
+
router?: Partial<NextRouter>;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
interface NextJsTypes {
|
|
53
|
+
parameters: NextJsParameters;
|
|
54
|
+
}
|
|
11
55
|
|
|
12
56
|
/**
|
|
13
57
|
* Function that sets the globalConfig of your storybook. The global config is the preview module of
|
|
@@ -96,4 +140,4 @@ declare function definePreview<Addons extends PreviewAddon<never>[]>(preview: {
|
|
|
96
140
|
interface NextPreview<T extends AddonTypes> extends ReactPreview<NextJsTypes & T> {
|
|
97
141
|
}
|
|
98
142
|
|
|
99
|
-
export { NextJsTypes, composeStories, composeStory, definePreview, setProjectAnnotations };
|
|
143
|
+
export { type FrameworkOptions, type NextJsParameters, type NextJsTypes, type StorybookConfig, composeStories, composeStory, definePreview, setProjectAnnotations };
|