vike 0.4.199-commit-33e1230 → 0.4.199-commit-43cc34a
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/dist/cjs/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/client/client-routing-runtime/initOnPopState.d.ts +2 -2
- package/dist/esm/client/client-routing-runtime/initOnPopState.js +9 -9
- package/dist/esm/utils/PROJECT_VERSION.d.ts +1 -1
- package/dist/esm/utils/PROJECT_VERSION.js +1 -1
- package/dist/esm/utils/projectInfo.d.ts +1 -1
- package/package.json +1 -1
|
@@ -3,7 +3,7 @@ export { updateState };
|
|
|
3
3
|
export { onPopState };
|
|
4
4
|
declare function initOnPopState(): void;
|
|
5
5
|
type Listener = (arg: {
|
|
6
|
-
|
|
6
|
+
previous: ReturnType<typeof getState>;
|
|
7
7
|
}) => void | boolean;
|
|
8
8
|
/** Control client-side navigation.
|
|
9
9
|
*
|
|
@@ -12,7 +12,7 @@ type Listener = (arg: {
|
|
|
12
12
|
declare function onPopState(listener: Listener): void;
|
|
13
13
|
declare function getState(): {
|
|
14
14
|
url: `/${string}`;
|
|
15
|
-
|
|
15
|
+
state: {
|
|
16
16
|
timestamp: number;
|
|
17
17
|
scrollPosition: null | import("./history.js").ScrollPosition;
|
|
18
18
|
triggeredBy: "user" | "vike" | "browser";
|
|
@@ -17,14 +17,14 @@ function initOnPopState() {
|
|
|
17
17
|
// - `location.hash = 'some-hash'`
|
|
18
18
|
// - The `event` argument of `window.addEventListener('popstate', (event) => /*...*/)` is useless: the History API doesn't provide the previous state (the popped state), see https://stackoverflow.com/questions/48055323/is-history-state-always-the-same-as-popstate-event-state
|
|
19
19
|
window.addEventListener('popstate', async () => {
|
|
20
|
-
const
|
|
21
|
-
const
|
|
22
|
-
globalObject.previousState =
|
|
23
|
-
const scrollTarget =
|
|
24
|
-
const isHashNavigation = removeHash(
|
|
25
|
-
const isBackwardNavigation = !
|
|
20
|
+
const previous = globalObject.previousState;
|
|
21
|
+
const current = getState();
|
|
22
|
+
globalObject.previousState = current;
|
|
23
|
+
const scrollTarget = current.state?.scrollPosition || undefined;
|
|
24
|
+
const isHashNavigation = removeHash(current.url) === removeHash(previous.url);
|
|
25
|
+
const isBackwardNavigation = !current.state?.timestamp || !previous.state?.timestamp
|
|
26
26
|
? null
|
|
27
|
-
:
|
|
27
|
+
: current.state.timestamp < previous.state.timestamp;
|
|
28
28
|
// - `history.state === null` when:
|
|
29
29
|
// - Click on `<a href="#some-hash" />` (note that Vike's `initOnLinkClick()` handler skips hash links)
|
|
30
30
|
// - `location.hash = 'some-hash'`
|
|
@@ -53,7 +53,7 @@ function initOnPopState() {
|
|
|
53
53
|
}
|
|
54
54
|
let abort;
|
|
55
55
|
globalObject.listeners.forEach((listener) => {
|
|
56
|
-
abort || (abort = listener({
|
|
56
|
+
abort || (abort = listener({ previous }));
|
|
57
57
|
});
|
|
58
58
|
if (abort)
|
|
59
59
|
return;
|
|
@@ -70,7 +70,7 @@ function onPopState(listener) {
|
|
|
70
70
|
function getState() {
|
|
71
71
|
return {
|
|
72
72
|
url: getCurrentUrl(),
|
|
73
|
-
|
|
73
|
+
state: getHistoryState()
|
|
74
74
|
};
|
|
75
75
|
}
|
|
76
76
|
function removeHash(url) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const PROJECT_VERSION: "0.4.199-commit-
|
|
1
|
+
export declare const PROJECT_VERSION: "0.4.199-commit-43cc34a";
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// Automatically updated by @brillout/release-me
|
|
2
|
-
export const PROJECT_VERSION = '0.4.199-commit-
|
|
2
|
+
export const PROJECT_VERSION = '0.4.199-commit-43cc34a';
|