@allurereport/web-commons 3.6.1 → 3.7.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.
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { computed } from "@preact/signals-core";
|
|
2
2
|
import { paramsToSearchParams } from "../url/helpers.js";
|
|
3
|
-
import { currentUrl, goTo } from "../url/index.js";
|
|
3
|
+
import { currentUrl, getCurrentUrl, goTo } from "../url/index.js";
|
|
4
4
|
export const router = computed(() => {
|
|
5
5
|
const hash = currentUrl.value.hash.startsWith("#") ? currentUrl.value.hash.slice(1) : currentUrl.value.hash;
|
|
6
6
|
return {
|
|
@@ -31,9 +31,9 @@ const createRouteUrl = (path, params) => {
|
|
|
31
31
|
};
|
|
32
32
|
export const navigateTo = (to) => {
|
|
33
33
|
const { path, params = {}, replace = false, searchParams = {}, keepSearchParams = false } = to;
|
|
34
|
-
const
|
|
35
|
-
const newUrl = new URL(currentPathname, currentUrl.value.origin);
|
|
34
|
+
const newUrl = new URL(getCurrentUrl());
|
|
36
35
|
const routeUrl = createRouteUrl(path, params);
|
|
36
|
+
newUrl.search = "";
|
|
37
37
|
newUrl.hash = routeUrl === "" || routeUrl === "/" ? "" : `#${routeUrl}`;
|
|
38
38
|
if (keepSearchParams) {
|
|
39
39
|
paramsToSearchParams(currentUrl.value.params, newUrl.searchParams);
|
|
@@ -5,6 +5,9 @@ type NavigateTo = URL | string | {
|
|
|
5
5
|
type NavigateToOptions = {
|
|
6
6
|
replace?: boolean;
|
|
7
7
|
};
|
|
8
|
+
export declare const isSameDocumentUrl: (url: URL, currentHref?: string) => boolean;
|
|
9
|
+
export declare const toSameDocumentHistoryUrl: (url: URL) => string;
|
|
10
|
+
export declare const getHistoryUrl: (to: NavigateTo, currentHref?: string) => string | URL;
|
|
8
11
|
export declare const goTo: (to: NavigateTo, options?: NavigateToOptions) => void;
|
|
9
12
|
export declare const getCurrentUrl: () => string;
|
|
10
13
|
export declare const paramsToSearchParams: (params: Record<string, string | string[]>, searchParams?: URLSearchParams) => URLSearchParams;
|
|
@@ -22,11 +22,42 @@ const getUrl = (to) => {
|
|
|
22
22
|
}
|
|
23
23
|
return new URL(to.path, getCurrentUrl());
|
|
24
24
|
};
|
|
25
|
+
export const isSameDocumentUrl = (url, currentHref = getCurrentUrl()) => {
|
|
26
|
+
try {
|
|
27
|
+
const currentUrl = new URL(currentHref);
|
|
28
|
+
return url.protocol === currentUrl.protocol && url.host === currentUrl.host && url.pathname === currentUrl.pathname;
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
export const toSameDocumentHistoryUrl = (url) => {
|
|
35
|
+
if (url.search) {
|
|
36
|
+
return `${url.search}${url.hash}`;
|
|
37
|
+
}
|
|
38
|
+
if (url.hash) {
|
|
39
|
+
return url.hash;
|
|
40
|
+
}
|
|
41
|
+
return url.pathname.split("/").pop() || ".";
|
|
42
|
+
};
|
|
43
|
+
export const getHistoryUrl = (to, currentHref = getCurrentUrl()) => {
|
|
44
|
+
const url = getUrl(to);
|
|
45
|
+
if (url instanceof URL) {
|
|
46
|
+
return isSameDocumentUrl(url, currentHref) ? toSameDocumentHistoryUrl(url) : url;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
const absoluteUrl = new URL(url, currentHref);
|
|
50
|
+
return isSameDocumentUrl(absoluteUrl, currentHref) ? toSameDocumentHistoryUrl(absoluteUrl) : url;
|
|
51
|
+
}
|
|
52
|
+
catch {
|
|
53
|
+
return url;
|
|
54
|
+
}
|
|
55
|
+
};
|
|
25
56
|
export const goTo = (to, options) => {
|
|
26
57
|
if (typeof window === "undefined") {
|
|
27
58
|
return;
|
|
28
59
|
}
|
|
29
|
-
const url =
|
|
60
|
+
const url = getHistoryUrl(to);
|
|
30
61
|
if (options?.replace) {
|
|
31
62
|
window.history.replaceState(null, "", url);
|
|
32
63
|
window.dispatchEvent(new Event("replaceState"));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@allurereport/web-commons",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.0",
|
|
4
4
|
"description": "Collection of utilities used across the web Allure reports",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"allure",
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"lint:fix": "oxlint --import-plugin --fix src test features stories"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@allurereport/aql": "3.
|
|
30
|
-
"@allurereport/charts-api": "3.
|
|
31
|
-
"@allurereport/core-api": "3.
|
|
32
|
-
"@allurereport/plugin-api": "3.
|
|
29
|
+
"@allurereport/aql": "3.7.0",
|
|
30
|
+
"@allurereport/charts-api": "3.7.0",
|
|
31
|
+
"@allurereport/core-api": "3.7.0",
|
|
32
|
+
"@allurereport/plugin-api": "3.7.0",
|
|
33
33
|
"@preact/signals": "^2.6.1",
|
|
34
34
|
"@preact/signals-core": "^1.12.2",
|
|
35
35
|
"ansi-to-html": "^0.7.2",
|