vite-plugin-storybook-nextjs 0.0.3--canary.253ba44.0 → 0.0.4--canary.fb0538a.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 (29) hide show
  1. package/dist/index.d.ts +12 -0
  2. package/dist/index.js +218 -216
  3. package/dist/mocks/storybook.global.d.ts +2 -0
  4. package/dist/mocks/storybook.global.js +15 -0
  5. package/dist/plugins/next-image/alias/image-context.d.ts +13 -0
  6. package/dist/plugins/next-image/alias/image-context.js +1 -1
  7. package/dist/plugins/next-image/alias/image-default-loader.d.ts +5 -0
  8. package/dist/plugins/next-image/alias/next-image.d.ts +30 -0
  9. package/dist/plugins/next-image/alias/next-legacy-image.d.ts +6 -0
  10. package/dist/plugins/next-mocks/alias/cache/index.d.ts +16 -0
  11. package/dist/plugins/next-mocks/alias/cache/index.js +18 -0
  12. package/dist/plugins/next-mocks/alias/headers/cookies.d.ts +14 -0
  13. package/dist/plugins/next-mocks/alias/headers/cookies.js +34 -0
  14. package/dist/plugins/next-mocks/alias/headers/headers.d.ts +21 -0
  15. package/dist/plugins/next-mocks/alias/headers/headers.js +38 -0
  16. package/dist/plugins/next-mocks/alias/headers/index.d.ts +10 -0
  17. package/dist/plugins/next-mocks/alias/headers/index.js +71 -0
  18. package/dist/plugins/next-mocks/alias/navigation/index.d.ts +30 -0
  19. package/dist/plugins/next-mocks/alias/navigation/index.js +65 -0
  20. package/dist/plugins/next-mocks/alias/router/index.d.ts +45 -0
  21. package/dist/plugins/next-mocks/alias/router/index.js +108 -0
  22. package/dist/plugins/next-mocks/alias/rsc/server-only.d.ts +3 -0
  23. package/dist/plugins/next-mocks/alias/rsc/server-only.js +4 -0
  24. package/package.json +8 -4
  25. package/dist/index.cjs +0 -960
  26. package/dist/plugins/next-image/alias/image-context.cjs +0 -8
  27. package/dist/plugins/next-image/alias/image-default-loader.cjs +0 -40
  28. package/dist/plugins/next-image/alias/next-image.cjs +0 -53
  29. package/dist/plugins/next-image/alias/next-legacy-image.cjs +0 -27
@@ -0,0 +1,15 @@
1
+ import moduleAlias from 'module-alias';
2
+
3
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
4
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
5
+ }) : x)(function(x) {
6
+ if (typeof require !== "undefined") return require.apply(this, arguments);
7
+ throw Error('Dynamic require of "' + x + '" is not supported');
8
+ });
9
+ moduleAlias.addAliases({
10
+ react: "next/dist/compiled/react",
11
+ "react-dom/test-utils": __require.resolve(
12
+ "next/dist/compiled/react-dom/cjs/react-dom-test-utils.production.js"
13
+ ),
14
+ "react-dom": "next/dist/compiled/react-dom"
15
+ });
@@ -0,0 +1,13 @@
1
+ import * as next_dist_compiled_react from 'next/dist/compiled/react';
2
+ import { ImageProps, StaticImageData } from 'next/image';
3
+ import { ImageProps as ImageProps$1 } from 'next/legacy/image';
4
+
5
+ interface StaticRequire {
6
+ default: StaticImageData;
7
+ }
8
+ declare type StaticImport = StaticRequire | StaticImageData;
9
+ declare const ImageContext: next_dist_compiled_react.Context<Partial<Omit<ImageProps, "src"> & {
10
+ src: string | StaticImport;
11
+ }> & Omit<ImageProps$1, "src">>;
12
+
13
+ export { ImageContext };
@@ -1,4 +1,4 @@
1
- import { createContext } from 'react';
1
+ import { createContext } from 'next/dist/compiled/react';
2
2
 
3
3
  // src/plugins/next-image/alias/image-context.tsx
4
4
  var ImageContext = createContext({});
@@ -0,0 +1,5 @@
1
+ import * as _NextImage from 'next/image';
2
+
3
+ declare const defaultLoader: ({ src, width, quality, }: _NextImage.ImageLoaderProps) => string;
4
+
5
+ export { defaultLoader };
@@ -0,0 +1,30 @@
1
+ import * as next_dist_shared_lib_get_img_props from 'next/dist/shared/lib/get-img-props';
2
+ import * as _NextImage from 'next/image';
3
+ import React__default from 'react';
4
+
5
+ declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "height" | "width" | "loading" | "ref" | "alt" | "src" | "srcSet"> & {
6
+ src: string | next_dist_shared_lib_get_img_props.StaticImport;
7
+ alt: string;
8
+ width?: number | `${number}` | undefined;
9
+ height?: number | `${number}` | undefined;
10
+ fill?: boolean | undefined;
11
+ loader?: _NextImage.ImageLoader | undefined;
12
+ quality?: number | `${number}` | undefined;
13
+ priority?: boolean | undefined;
14
+ loading?: "lazy" | "eager" | undefined;
15
+ placeholder?: next_dist_shared_lib_get_img_props.PlaceholderValue | undefined;
16
+ blurDataURL?: string | undefined;
17
+ unoptimized?: boolean | undefined;
18
+ overrideSrc?: string | undefined;
19
+ onLoadingComplete?: next_dist_shared_lib_get_img_props.OnLoadingComplete | undefined;
20
+ layout?: string | undefined;
21
+ objectFit?: string | undefined;
22
+ objectPosition?: string | undefined;
23
+ lazyBoundary?: string | undefined;
24
+ lazyRoot?: string | undefined;
25
+ } & React__default.RefAttributes<HTMLImageElement>>;
26
+ declare const getImageProps: (props: _NextImage.ImageProps) => {
27
+ props: next_dist_shared_lib_get_img_props.ImgProps;
28
+ };
29
+
30
+ export { MockedNextImage as default, getImageProps };
@@ -0,0 +1,6 @@
1
+ import * as _NextLegacyImage from 'next/legacy/image';
2
+ import React__default from 'react';
3
+
4
+ declare function NextLegacyImage({ loader, ...props }: _NextLegacyImage.ImageProps): React__default.JSX.Element;
5
+
6
+ export { NextLegacyImage as default };
@@ -0,0 +1,16 @@
1
+ import * as vitest from 'vitest';
2
+ import { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache';
3
+ export { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache';
4
+ import { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store';
5
+ export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store';
6
+
7
+ declare const revalidatePath: vitest.Mock<any, any>;
8
+ declare const revalidateTag: vitest.Mock<any, any>;
9
+ declare const cacheExports: {
10
+ unstable_cache: typeof unstable_cache;
11
+ revalidateTag: vitest.Mock<any, any>;
12
+ revalidatePath: vitest.Mock<any, any>;
13
+ unstable_noStore: typeof unstable_noStore;
14
+ };
15
+
16
+ export { cacheExports as default, revalidatePath, revalidateTag };
@@ -0,0 +1,18 @@
1
+ import { fn } from '@storybook/test';
2
+ import { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache';
3
+ export { unstable_cache } from 'next/dist/server/web/spec-extension/unstable-cache';
4
+ import { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store';
5
+ export { unstable_noStore } from 'next/dist/server/web/spec-extension/unstable-no-store';
6
+
7
+ // src/plugins/next-mocks/alias/cache/index.ts
8
+ var revalidatePath = fn().mockName("next/cache::revalidatePath");
9
+ var revalidateTag = fn().mockName("next/cache::revalidateTag");
10
+ var cacheExports = {
11
+ unstable_cache,
12
+ revalidateTag,
13
+ revalidatePath,
14
+ unstable_noStore
15
+ };
16
+ var cache_default = cacheExports;
17
+
18
+ export { cache_default as default, revalidatePath, revalidateTag };
@@ -0,0 +1,14 @@
1
+ import * as vitest from 'vitest';
2
+ import * as next_dist_compiled__edge_runtime_cookies from 'next/dist/compiled/@edge-runtime/cookies';
3
+ import { RequestCookies } from 'next/dist/compiled/@edge-runtime/cookies';
4
+
5
+ declare class RequestCookiesMock extends RequestCookies {
6
+ get: vitest.Mock<[name: string] | [next_dist_compiled__edge_runtime_cookies.RequestCookie], next_dist_compiled__edge_runtime_cookies.RequestCookie | undefined>;
7
+ getAll: vitest.Mock<[next_dist_compiled__edge_runtime_cookies.RequestCookie] | [name: string] | [], next_dist_compiled__edge_runtime_cookies.RequestCookie[]>;
8
+ has: vitest.Mock<[name: string], boolean>;
9
+ set: vitest.Mock<[key: string, value: string] | [options: next_dist_compiled__edge_runtime_cookies.RequestCookie], this>;
10
+ delete: vitest.Mock<[names: string | string[]], boolean | boolean[]>;
11
+ }
12
+ declare const cookies: vitest.Mock<[], RequestCookiesMock>;
13
+
14
+ export { cookies };
@@ -0,0 +1,34 @@
1
+ import { headers } from '@storybook/nextjs/headers.mock';
2
+ import { fn } from '@storybook/test';
3
+ import { RequestCookies } from 'next/dist/compiled/@edge-runtime/cookies';
4
+
5
+ // src/plugins/next-mocks/alias/headers/cookies.ts
6
+ var RequestCookiesMock = class extends RequestCookies {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.get = fn(super.get.bind(this)).mockName("next/headers::cookies().get");
10
+ this.getAll = fn(super.getAll.bind(this)).mockName(
11
+ "next/headers::cookies().getAll"
12
+ );
13
+ this.has = fn(super.has.bind(this)).mockName("next/headers::cookies().has");
14
+ this.set = fn(super.set.bind(this)).mockName("next/headers::cookies().set");
15
+ this.delete = fn(super.delete.bind(this)).mockName(
16
+ "next/headers::cookies().delete"
17
+ );
18
+ }
19
+ };
20
+ var requestCookiesMock;
21
+ var cookies = fn(() => {
22
+ if (!requestCookiesMock) {
23
+ requestCookiesMock = new RequestCookiesMock(headers());
24
+ }
25
+ return requestCookiesMock;
26
+ }).mockName("next/headers::cookies()");
27
+ var originalRestore = cookies.mockRestore.bind(null);
28
+ cookies.mockRestore = () => {
29
+ originalRestore();
30
+ headers.mockRestore();
31
+ requestCookiesMock = new RequestCookiesMock(headers());
32
+ };
33
+
34
+ export { cookies };
@@ -0,0 +1,21 @@
1
+ import * as vitest from 'vitest';
2
+ import { HeadersAdapter } from 'next/dist/server/web/spec-extension/adapters/headers';
3
+
4
+ declare class HeadersAdapterMock extends HeadersAdapter {
5
+ constructor();
6
+ append: vitest.Mock<[name: string, value: string], void>;
7
+ delete: vitest.Mock<[name: string], void>;
8
+ get: vitest.Mock<[name: string], string | null>;
9
+ has: vitest.Mock<[name: string], boolean>;
10
+ set: vitest.Mock<[name: string, value: string], void>;
11
+ forEach: vitest.Mock<[callbackfn: (value: string, name: string, parent: Headers) => void, thisArg?: any], void>;
12
+ entries: vitest.Mock<[], IterableIterator<[string, string]>>;
13
+ keys: vitest.Mock<[], IterableIterator<string>>;
14
+ values: vitest.Mock<[], IterableIterator<string>>;
15
+ }
16
+ declare const headers: {
17
+ (): HeadersAdapterMock;
18
+ mockRestore(): void;
19
+ };
20
+
21
+ export { headers };
@@ -0,0 +1,38 @@
1
+ import { fn } from '@storybook/test';
2
+ import { HeadersAdapter } from 'next/dist/server/web/spec-extension/adapters/headers';
3
+
4
+ // src/plugins/next-mocks/alias/headers/headers.ts
5
+ var HeadersAdapterMock = class extends HeadersAdapter {
6
+ constructor() {
7
+ super({});
8
+ this.append = fn(super.append.bind(this)).mockName(
9
+ "next/headers::headers().append"
10
+ );
11
+ this.delete = fn(super.delete.bind(this)).mockName(
12
+ "next/headers::headers().delete"
13
+ );
14
+ this.get = fn(super.get.bind(this)).mockName("next/headers::headers().get");
15
+ this.has = fn(super.has.bind(this)).mockName("next/headers::headers().has");
16
+ this.set = fn(super.set.bind(this)).mockName("next/headers::headers().set");
17
+ this.forEach = fn(super.forEach.bind(this)).mockName(
18
+ "next/headers::headers().forEach"
19
+ );
20
+ this.entries = fn(super.entries.bind(this)).mockName(
21
+ "next/headers::headers().entries"
22
+ );
23
+ this.keys = fn(super.keys.bind(this)).mockName("next/headers::headers().keys");
24
+ this.values = fn(super.values.bind(this)).mockName(
25
+ "next/headers::headers().values"
26
+ );
27
+ }
28
+ };
29
+ var headersAdapterMock;
30
+ var headers = () => {
31
+ if (!headersAdapterMock) headersAdapterMock = new HeadersAdapterMock();
32
+ return headersAdapterMock;
33
+ };
34
+ headers.mockRestore = () => {
35
+ headersAdapterMock = new HeadersAdapterMock();
36
+ };
37
+
38
+ export { headers };
@@ -0,0 +1,10 @@
1
+ import * as vitest from 'vitest';
2
+ import * as next_dist_client_components_draft_mode from 'next/dist/client/components/draft-mode';
3
+ export { headers } from './headers.js';
4
+ export { cookies } from './cookies.js';
5
+ import 'next/dist/server/web/spec-extension/adapters/headers';
6
+ import 'next/dist/compiled/@edge-runtime/cookies';
7
+
8
+ declare const draftMode: vitest.Mock<[], next_dist_client_components_draft_mode.DraftMode>;
9
+
10
+ export { draftMode };
@@ -0,0 +1,71 @@
1
+ import { fn } from '@storybook/test';
2
+ import * as originalHeaders from 'next/dist/client/components/headers';
3
+ import { HeadersAdapter } from 'next/dist/server/web/spec-extension/adapters/headers';
4
+ import { headers as headers$1 } from '@storybook/nextjs/headers.mock';
5
+ import { RequestCookies } from 'next/dist/compiled/@edge-runtime/cookies';
6
+
7
+ // src/plugins/next-mocks/alias/headers/index.ts
8
+ var HeadersAdapterMock = class extends HeadersAdapter {
9
+ constructor() {
10
+ super({});
11
+ this.append = fn(super.append.bind(this)).mockName(
12
+ "next/headers::headers().append"
13
+ );
14
+ this.delete = fn(super.delete.bind(this)).mockName(
15
+ "next/headers::headers().delete"
16
+ );
17
+ this.get = fn(super.get.bind(this)).mockName("next/headers::headers().get");
18
+ this.has = fn(super.has.bind(this)).mockName("next/headers::headers().has");
19
+ this.set = fn(super.set.bind(this)).mockName("next/headers::headers().set");
20
+ this.forEach = fn(super.forEach.bind(this)).mockName(
21
+ "next/headers::headers().forEach"
22
+ );
23
+ this.entries = fn(super.entries.bind(this)).mockName(
24
+ "next/headers::headers().entries"
25
+ );
26
+ this.keys = fn(super.keys.bind(this)).mockName("next/headers::headers().keys");
27
+ this.values = fn(super.values.bind(this)).mockName(
28
+ "next/headers::headers().values"
29
+ );
30
+ }
31
+ };
32
+ var headersAdapterMock;
33
+ var headers = () => {
34
+ if (!headersAdapterMock) headersAdapterMock = new HeadersAdapterMock();
35
+ return headersAdapterMock;
36
+ };
37
+ headers.mockRestore = () => {
38
+ headersAdapterMock = new HeadersAdapterMock();
39
+ };
40
+ var RequestCookiesMock = class extends RequestCookies {
41
+ constructor() {
42
+ super(...arguments);
43
+ this.get = fn(super.get.bind(this)).mockName("next/headers::cookies().get");
44
+ this.getAll = fn(super.getAll.bind(this)).mockName(
45
+ "next/headers::cookies().getAll"
46
+ );
47
+ this.has = fn(super.has.bind(this)).mockName("next/headers::cookies().has");
48
+ this.set = fn(super.set.bind(this)).mockName("next/headers::cookies().set");
49
+ this.delete = fn(super.delete.bind(this)).mockName(
50
+ "next/headers::cookies().delete"
51
+ );
52
+ }
53
+ };
54
+ var requestCookiesMock;
55
+ var cookies = fn(() => {
56
+ if (!requestCookiesMock) {
57
+ requestCookiesMock = new RequestCookiesMock(headers$1());
58
+ }
59
+ return requestCookiesMock;
60
+ }).mockName("next/headers::cookies()");
61
+ var originalRestore = cookies.mockRestore.bind(null);
62
+ cookies.mockRestore = () => {
63
+ originalRestore();
64
+ headers$1.mockRestore();
65
+ requestCookiesMock = new RequestCookiesMock(headers$1());
66
+ };
67
+
68
+ // src/plugins/next-mocks/alias/headers/index.ts
69
+ var draftMode2 = fn(originalHeaders.draftMode).mockName("draftMode");
70
+
71
+ export { cookies, draftMode2 as draftMode, headers };
@@ -0,0 +1,30 @@
1
+ import * as React from 'react';
2
+ import * as next_dist_shared_lib_app_router_context_shared_runtime from 'next/dist/shared/lib/app-router-context.shared-runtime';
3
+ import { Mock } from '@storybook/test';
4
+ import * as actual from 'next/dist/client/components/navigation';
5
+ export * from 'next/dist/client/components/navigation';
6
+
7
+ declare const createNavigation: (overrides?: Record<string, (...params: unknown[]) => unknown>) => {
8
+ push: Mock;
9
+ replace: Mock;
10
+ forward: Mock;
11
+ back: Mock;
12
+ prefetch: Mock;
13
+ refresh: Mock;
14
+ };
15
+
16
+ declare const redirect: Mock<[url: string, type?: actual.RedirectType | undefined], never>;
17
+ declare const permanentRedirect: Mock<[url: string, type?: actual.RedirectType | undefined], never>;
18
+ declare const useSearchParams: Mock<[], actual.ReadonlyURLSearchParams>;
19
+ declare const usePathname: Mock<[], string>;
20
+ declare const useSelectedLayoutSegment: Mock<[parallelRouteKey?: string | undefined], string | null>;
21
+ declare const useSelectedLayoutSegments: Mock<[parallelRouteKey?: string | undefined], string[]>;
22
+ declare const useRouter: Mock<[], next_dist_shared_lib_app_router_context_shared_runtime.AppRouterInstance>;
23
+ declare const useServerInsertedHTML: Mock<[callback: () => React.ReactNode], void>;
24
+ declare const notFound: Mock<[], never>;
25
+ interface Params {
26
+ [key: string]: string | string[];
27
+ }
28
+ declare const useParams: Mock<[], Params>;
29
+
30
+ export { createNavigation, notFound, permanentRedirect, redirect, useParams, usePathname, useRouter, useSearchParams, useSelectedLayoutSegment, useSelectedLayoutSegments, useServerInsertedHTML };
@@ -0,0 +1,65 @@
1
+ import { fn } from '@storybook/test';
2
+ import * as actual from 'next/dist/client/components/navigation';
3
+ export * from 'next/dist/client/components/navigation';
4
+ import { getRedirectError } from 'next/dist/client/components/redirect';
5
+ import { RedirectStatusCode } from 'next/dist/client/components/redirect-status-code';
6
+
7
+ // src/plugins/next-mocks/alias/navigation/index.ts
8
+ var navigationAPI;
9
+ var createNavigation = (overrides) => {
10
+ const navigationActions = {
11
+ push: fn().mockName("next/navigation::useRouter().push"),
12
+ replace: fn().mockName("next/navigation::useRouter().replace"),
13
+ forward: fn().mockName("next/navigation::useRouter().forward"),
14
+ back: fn().mockName("next/navigation::useRouter().back"),
15
+ prefetch: fn().mockName("next/navigation::useRouter().prefetch"),
16
+ refresh: fn().mockName("next/navigation::useRouter().refresh")
17
+ };
18
+ if (overrides) {
19
+ for (const key of Object.keys(navigationActions)) {
20
+ if (key in overrides) {
21
+ navigationActions[key] = fn((...args) => {
22
+ return overrides[key](...args);
23
+ }).mockName(`useRouter().${key}`);
24
+ }
25
+ }
26
+ }
27
+ navigationAPI = navigationActions;
28
+ return navigationAPI;
29
+ };
30
+ var redirect = fn(
31
+ (url, type = actual.RedirectType.push) => {
32
+ throw getRedirectError(url, type, RedirectStatusCode.SeeOther);
33
+ }
34
+ ).mockName("next/navigation::redirect");
35
+ var permanentRedirect = fn(
36
+ (url, type = actual.RedirectType.push) => {
37
+ throw getRedirectError(url, type, RedirectStatusCode.SeeOther);
38
+ }
39
+ ).mockName("next/navigation::permanentRedirect");
40
+ var useSearchParams2 = fn(actual.useSearchParams).mockName(
41
+ "next/navigation::useSearchParams"
42
+ );
43
+ var usePathname2 = fn(actual.usePathname).mockName(
44
+ "next/navigation::usePathname"
45
+ );
46
+ var useSelectedLayoutSegment2 = fn(
47
+ actual.useSelectedLayoutSegment
48
+ ).mockName("next/navigation::useSelectedLayoutSegment");
49
+ var useSelectedLayoutSegments2 = fn(
50
+ actual.useSelectedLayoutSegments
51
+ ).mockName("next/navigation::useSelectedLayoutSegments");
52
+ var useRouter2 = fn(actual.useRouter).mockName(
53
+ "next/navigation::useRouter"
54
+ );
55
+ var useServerInsertedHTML2 = fn(actual.useServerInsertedHTML).mockName(
56
+ "next/navigation::useServerInsertedHTML"
57
+ );
58
+ var notFound2 = fn(actual.notFound).mockName(
59
+ "next/navigation::notFound"
60
+ );
61
+ var useParams2 = fn(actual.useParams).mockName(
62
+ "next/navigation::useParams"
63
+ );
64
+
65
+ export { createNavigation, notFound2 as notFound, permanentRedirect, redirect, useParams2 as useParams, usePathname2 as usePathname, useRouter2 as useRouter, useSearchParams2 as useSearchParams, useSelectedLayoutSegment2 as useSelectedLayoutSegment, useSelectedLayoutSegments2 as useSelectedLayoutSegments, useServerInsertedHTML2 as useServerInsertedHTML };
@@ -0,0 +1,45 @@
1
+ import * as React from 'react';
2
+ import * as next_dist_client_with_router from 'next/dist/client/with-router';
3
+ import * as next_types from 'next/types';
4
+ import { Mock } from '@storybook/test';
5
+ import * as originalRouter from 'next/dist/client/router';
6
+ import originalRouter__default from 'next/dist/client/router';
7
+ export * from 'next/dist/client/router';
8
+ export { default } from 'next/dist/client/router';
9
+ import { NextRouter } from 'next/router';
10
+
11
+ /**
12
+ * Creates a next/router router API mock. Used internally.
13
+ * @ignore
14
+ * @internal
15
+ * */
16
+ declare const createRouter: (overrides: Partial<NextRouter>) => originalRouter.NextRouter;
17
+ declare const getRouter: () => {
18
+ push: Mock;
19
+ replace: Mock;
20
+ reload: Mock;
21
+ back: Mock;
22
+ forward: Mock;
23
+ prefetch: Mock;
24
+ beforePopState: Mock;
25
+ events: {
26
+ on: Mock;
27
+ off: Mock;
28
+ emit: Mock;
29
+ };
30
+ } & {
31
+ route: string;
32
+ asPath: string;
33
+ basePath: string;
34
+ pathname: string;
35
+ query: {};
36
+ isFallback: boolean;
37
+ isLocaleDomain: boolean;
38
+ isReady: boolean;
39
+ isPreview: boolean;
40
+ };
41
+
42
+ declare const useRouter: Mock<[], originalRouter.NextRouter>;
43
+ declare const withRouter: Mock<[ComposedComponent: next_types.NextComponentType<next_types.NextPageContext, any, next_dist_client_with_router.WithRouterProps>], React.ComponentType<next_dist_client_with_router.ExcludeRouterProps<next_dist_client_with_router.WithRouterProps>>>;
44
+
45
+ export { createRouter, getRouter, useRouter, withRouter };
@@ -0,0 +1,108 @@
1
+ import { fn } from '@storybook/test';
2
+ import * as singletonRouter from 'next/dist/client/router';
3
+ import singletonRouter__default from 'next/dist/client/router';
4
+ export * from 'next/dist/client/router';
5
+ import { NextjsRouterMocksNotAvailable } from 'storybook/internal/preview-errors';
6
+
7
+ // src/plugins/next-mocks/alias/router/index.ts
8
+ var defaultRouterState = {
9
+ route: "/",
10
+ asPath: "/",
11
+ basePath: "/",
12
+ pathname: "/",
13
+ query: {},
14
+ isFallback: false,
15
+ isLocaleDomain: false,
16
+ isReady: true,
17
+ isPreview: false
18
+ };
19
+ var routerAPI;
20
+ var createRouter = (overrides) => {
21
+ const routerActions = {
22
+ push: fn((..._args) => {
23
+ return Promise.resolve(true);
24
+ }).mockName("next/router::useRouter().push"),
25
+ replace: fn((..._args) => {
26
+ return Promise.resolve(true);
27
+ }).mockName("next/router::useRouter().replace"),
28
+ reload: fn((..._args) => {
29
+ }).mockName(
30
+ "next/router::useRouter().reload"
31
+ ),
32
+ back: fn((..._args) => {
33
+ }).mockName(
34
+ "next/router::useRouter().back"
35
+ ),
36
+ forward: fn(() => {
37
+ }).mockName("next/router::useRouter().forward"),
38
+ prefetch: fn((..._args) => {
39
+ return Promise.resolve();
40
+ }).mockName("next/router::useRouter().prefetch"),
41
+ beforePopState: fn((..._args) => {
42
+ }).mockName(
43
+ "next/router::useRouter().beforePopState"
44
+ )
45
+ };
46
+ const routerEvents = {
47
+ on: fn((..._args) => {
48
+ }).mockName(
49
+ "next/router::useRouter().events.on"
50
+ ),
51
+ off: fn((..._args) => {
52
+ }).mockName(
53
+ "next/router::useRouter().events.off"
54
+ ),
55
+ emit: fn((..._args) => {
56
+ }).mockName(
57
+ "next/router::useRouter().events.emit"
58
+ )
59
+ };
60
+ if (overrides) {
61
+ for (const key of Object.keys(routerActions)) {
62
+ if (key in overrides) {
63
+ routerActions[key] = fn((...args) => {
64
+ return overrides[key](...args);
65
+ }).mockName(`useRouter().${key}`);
66
+ }
67
+ }
68
+ }
69
+ if (overrides?.events) {
70
+ for (const key of Object.keys(routerEvents)) {
71
+ if (key in routerEvents) {
72
+ routerEvents[key] = fn((...args) => {
73
+ return overrides.events[key](...args);
74
+ }).mockName(`useRouter().events.${key}`);
75
+ }
76
+ }
77
+ }
78
+ routerAPI = {
79
+ ...defaultRouterState,
80
+ ...overrides,
81
+ ...routerActions,
82
+ // @ts-expect-error TODO improve typings
83
+ events: routerEvents
84
+ };
85
+ singletonRouter__default.router = routerAPI;
86
+ for (const cb of singletonRouter__default.readyCallbacks) {
87
+ cb();
88
+ }
89
+ singletonRouter__default.readyCallbacks = [];
90
+ return routerAPI;
91
+ };
92
+ var getRouter = () => {
93
+ if (!routerAPI) {
94
+ throw new NextjsRouterMocksNotAvailable({
95
+ importType: "next/router"
96
+ });
97
+ }
98
+ return routerAPI;
99
+ };
100
+ var router_default = singletonRouter__default;
101
+ var useRouter2 = fn(singletonRouter.useRouter).mockName(
102
+ "next/router::useRouter"
103
+ );
104
+ var withRouter2 = fn(singletonRouter.withRouter).mockName(
105
+ "next/router::withRouter"
106
+ );
107
+
108
+ export { createRouter, router_default as default, getRouter, useRouter2 as useRouter, withRouter2 as withRouter };
@@ -0,0 +1,3 @@
1
+ declare const _default: {};
2
+
3
+ export { _default as default };
@@ -0,0 +1,4 @@
1
+ // src/plugins/next-mocks/alias/rsc/server-only.ts
2
+ var server_only_default = {};
3
+
4
+ export { server_only_default as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-storybook-nextjs",
3
- "version": "0.0.3--canary.253ba44.0",
3
+ "version": "0.0.4--canary.fb0538a.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "vite-plugin",
@@ -20,8 +20,7 @@
20
20
  "exports": {
21
21
  ".": {
22
22
  "types": "./dist/index.d.ts",
23
- "import": "./dist/index.js",
24
- "require": "./dist/index.cjs"
23
+ "import": "./dist/index.js"
25
24
  }
26
25
  },
27
26
  "scripts": {
@@ -33,12 +32,15 @@
33
32
  "release": "auto shipit"
34
33
  },
35
34
  "peerDependencies": {
35
+ "@storybook/test": "^8.3.0-alpha.3",
36
36
  "next": "^14.0.0",
37
+ "storybook": "^8.3.0-alpha.3",
37
38
  "vite": "^5.0.0"
38
39
  },
39
40
  "devDependencies": {
40
41
  "@biomejs/biome": "1.8.1",
41
- "@types/node": "^20.0.0",
42
+ "@storybook/test": "8.3.0-alpha.3",
43
+ "@types/node": "^18",
42
44
  "@types/react": "^18",
43
45
  "auto": "^11.2.0",
44
46
  "lefthook": "^1.6.16",
@@ -46,6 +48,7 @@
46
48
  "react": "^18",
47
49
  "rollup": "^4.18.0",
48
50
  "sharp": "^0.33.4",
51
+ "storybook": "8.3.0-alpha.3",
49
52
  "tsup": "^8.1.0",
50
53
  "typescript": "^5.0.0",
51
54
  "vite": "^5.0.0",
@@ -56,6 +59,7 @@
56
59
  "@next/env": "^14.2.4",
57
60
  "find-up": "^7.0.0",
58
61
  "image-size": "^1.1.1",
62
+ "module-alias": "^2.2.3",
59
63
  "ts-dedent": "^2.2.0"
60
64
  },
61
65
  "optionalDependencies": {