vite-plugin-storybook-nextjs 3.3.0 → 3.3.1
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.
|
@@ -2,7 +2,7 @@ import * as next_dist_shared_lib_get_img_props from 'next/dist/shared/lib/get-im
|
|
|
2
2
|
import * as _NextImage from 'next/image';
|
|
3
3
|
import React__default from 'next/dist/compiled/react';
|
|
4
4
|
|
|
5
|
-
declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "
|
|
5
|
+
declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "srcSet" | "ref" | "alt" | "width" | "height" | "loading"> & {
|
|
6
6
|
src: string | next_dist_shared_lib_get_img_props.StaticImport;
|
|
7
7
|
alt: string;
|
|
8
8
|
width?: number | `${number}`;
|
|
@@ -2,7 +2,7 @@ import * as next_dist_shared_lib_get_img_props from 'next/dist/shared/lib/get-im
|
|
|
2
2
|
import * as _NextImage from 'next/image';
|
|
3
3
|
import React__default from 'next/dist/compiled/react';
|
|
4
4
|
|
|
5
|
-
declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "
|
|
5
|
+
declare const MockedNextImage: React__default.ForwardRefExoticComponent<Omit<React__default.DetailedHTMLProps<React__default.ImgHTMLAttributes<HTMLImageElement>, HTMLImageElement>, "src" | "srcSet" | "ref" | "alt" | "width" | "height" | "loading"> & {
|
|
6
6
|
src: string | next_dist_shared_lib_get_img_props.StaticImport;
|
|
7
7
|
alt: string;
|
|
8
8
|
width?: number | `${number}`;
|
|
@@ -11,6 +11,33 @@ var React__default = /*#__PURE__*/_interopDefault(React);
|
|
|
11
11
|
|
|
12
12
|
// src/plugins/next-mocks/alias/link/index.tsx
|
|
13
13
|
var linkAction = test.fn().mockName("next/link::Link");
|
|
14
|
+
var removeTrailingSlash = (route) => route.endsWith("/") && route.length > 1 ? route.slice(0, -1) : route;
|
|
15
|
+
var parsePath = (path) => {
|
|
16
|
+
const hashIndex = path.indexOf("#");
|
|
17
|
+
const queryIndex = path.indexOf("?");
|
|
18
|
+
const hasQuery = queryIndex > -1 && (hashIndex < 0 || queryIndex < hashIndex);
|
|
19
|
+
if (hasQuery || hashIndex > -1) {
|
|
20
|
+
return {
|
|
21
|
+
pathname: path.substring(0, hasQuery ? queryIndex : hashIndex),
|
|
22
|
+
query: hasQuery ? path.substring(queryIndex, hashIndex > -1 ? hashIndex : void 0) : "",
|
|
23
|
+
hash: hashIndex > -1 ? path.slice(hashIndex) : ""
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
return { pathname: path, query: "", hash: "" };
|
|
27
|
+
};
|
|
28
|
+
var normalizePathTrailingSlash = (path) => {
|
|
29
|
+
if (!path.startsWith("/") || process.env.__NEXT_MANUAL_TRAILING_SLASH) {
|
|
30
|
+
return path;
|
|
31
|
+
}
|
|
32
|
+
const { pathname, query, hash } = parsePath(path);
|
|
33
|
+
if (process.env.__NEXT_TRAILING_SLASH) {
|
|
34
|
+
if (/\.[^/]+\/?$/.test(pathname)) {
|
|
35
|
+
return `${removeTrailingSlash(pathname)}${query}${hash}`;
|
|
36
|
+
}
|
|
37
|
+
return `${pathname.endsWith("/") ? pathname : `${pathname}/`}${query}${hash}`;
|
|
38
|
+
}
|
|
39
|
+
return `${removeTrailingSlash(pathname)}${query}${hash}`;
|
|
40
|
+
};
|
|
14
41
|
var MockLink = React__default.default.forwardRef(
|
|
15
42
|
function MockLink2({
|
|
16
43
|
href,
|
|
@@ -26,9 +53,10 @@ var MockLink = React__default.default.forwardRef(
|
|
|
26
53
|
children,
|
|
27
54
|
...rest
|
|
28
55
|
}, ref) {
|
|
29
|
-
const
|
|
56
|
+
const rawHref = typeof href === "object" ? `${href.pathname || ""}${href.query ? `?${new URLSearchParams(
|
|
30
57
|
href.query
|
|
31
58
|
).toString()}` : ""}${href.hash || ""}` : href;
|
|
59
|
+
const hrefString = typeof rawHref === "string" ? normalizePathTrailingSlash(rawHref) : rawHref;
|
|
32
60
|
const handleClick = (e) => {
|
|
33
61
|
e.preventDefault();
|
|
34
62
|
onClick?.(e);
|
|
@@ -3,6 +3,33 @@ import { fn } from 'storybook/test';
|
|
|
3
3
|
|
|
4
4
|
// src/plugins/next-mocks/alias/link/index.tsx
|
|
5
5
|
var linkAction = fn().mockName("next/link::Link");
|
|
6
|
+
var removeTrailingSlash = (route) => route.endsWith("/") && route.length > 1 ? route.slice(0, -1) : route;
|
|
7
|
+
var parsePath = (path) => {
|
|
8
|
+
const hashIndex = path.indexOf("#");
|
|
9
|
+
const queryIndex = path.indexOf("?");
|
|
10
|
+
const hasQuery = queryIndex > -1 && (hashIndex < 0 || queryIndex < hashIndex);
|
|
11
|
+
if (hasQuery || hashIndex > -1) {
|
|
12
|
+
return {
|
|
13
|
+
pathname: path.substring(0, hasQuery ? queryIndex : hashIndex),
|
|
14
|
+
query: hasQuery ? path.substring(queryIndex, hashIndex > -1 ? hashIndex : void 0) : "",
|
|
15
|
+
hash: hashIndex > -1 ? path.slice(hashIndex) : ""
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return { pathname: path, query: "", hash: "" };
|
|
19
|
+
};
|
|
20
|
+
var normalizePathTrailingSlash = (path) => {
|
|
21
|
+
if (!path.startsWith("/") || process.env.__NEXT_MANUAL_TRAILING_SLASH) {
|
|
22
|
+
return path;
|
|
23
|
+
}
|
|
24
|
+
const { pathname, query, hash } = parsePath(path);
|
|
25
|
+
if (process.env.__NEXT_TRAILING_SLASH) {
|
|
26
|
+
if (/\.[^/]+\/?$/.test(pathname)) {
|
|
27
|
+
return `${removeTrailingSlash(pathname)}${query}${hash}`;
|
|
28
|
+
}
|
|
29
|
+
return `${pathname.endsWith("/") ? pathname : `${pathname}/`}${query}${hash}`;
|
|
30
|
+
}
|
|
31
|
+
return `${removeTrailingSlash(pathname)}${query}${hash}`;
|
|
32
|
+
};
|
|
6
33
|
var MockLink = React.forwardRef(
|
|
7
34
|
function MockLink2({
|
|
8
35
|
href,
|
|
@@ -18,9 +45,10 @@ var MockLink = React.forwardRef(
|
|
|
18
45
|
children,
|
|
19
46
|
...rest
|
|
20
47
|
}, ref) {
|
|
21
|
-
const
|
|
48
|
+
const rawHref = typeof href === "object" ? `${href.pathname || ""}${href.query ? `?${new URLSearchParams(
|
|
22
49
|
href.query
|
|
23
50
|
).toString()}` : ""}${href.hash || ""}` : href;
|
|
51
|
+
const hrefString = typeof rawHref === "string" ? normalizePathTrailingSlash(rawHref) : rawHref;
|
|
24
52
|
const handleClick = (e) => {
|
|
25
53
|
e.preventDefault();
|
|
26
54
|
onClick?.(e);
|