vike 0.4.167-commit-c08a6bb → 0.4.167-commit-aa83fde
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,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PROJECT_VERSION = exports.projectInfo = void 0;
|
|
4
|
-
const PROJECT_VERSION = '0.4.167-commit-
|
|
4
|
+
const PROJECT_VERSION = '0.4.167-commit-aa83fde';
|
|
5
5
|
exports.PROJECT_VERSION = PROJECT_VERSION;
|
|
6
6
|
const projectInfo = {
|
|
7
7
|
projectName: 'Vike',
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export { initHistoryState, getHistoryState, pushHistory, saveScrollPosition, monkeyPatchHistoryPushState };
|
|
2
|
-
import { assert, assertUsage,
|
|
3
|
-
const globalObject = getGlobalObject('history.ts', {});
|
|
2
|
+
import { assert, assertUsage, hasProp, isObject } from './utils.js';
|
|
4
3
|
// Fill missing state information:
|
|
5
4
|
// - `history.state` can uninitialized (i.e. `null`):
|
|
6
5
|
// - The very first render
|
|
@@ -8,9 +7,10 @@ const globalObject = getGlobalObject('history.ts', {});
|
|
|
8
7
|
// - The user clicks on an anchor link `<a href="#section">Section</a>` (Vike's `onLinkClick()` handler skips hash links).
|
|
9
8
|
// - State information may be incomplete if `history.state` is set by an old Vike version. (E.g. `state.timestamp` was introduced for `pageContext.isBackwardNavigation` in `0.4.19`.)
|
|
10
9
|
function initHistoryState() {
|
|
10
|
+
// No way found to add TypeScript types to `window.history.state`: https://github.com/microsoft/TypeScript/issues/36178
|
|
11
11
|
let state = window.history.state;
|
|
12
12
|
if (!state) {
|
|
13
|
-
state = {};
|
|
13
|
+
state = { _isVikeEnhanced: true };
|
|
14
14
|
}
|
|
15
15
|
let hasModifications = false;
|
|
16
16
|
if (!('timestamp' in state)) {
|
|
@@ -49,7 +49,7 @@ function saveScrollPosition() {
|
|
|
49
49
|
function pushHistory(url, overwriteLastHistoryEntry) {
|
|
50
50
|
if (!overwriteLastHistoryEntry) {
|
|
51
51
|
const timestamp = getTimestamp();
|
|
52
|
-
pushHistoryState({ timestamp, scrollPosition: null, triggeredBy: 'vike' }, url);
|
|
52
|
+
pushHistoryState({ timestamp, scrollPosition: null, triggeredBy: 'vike', _isVikeEnhanced: true }, url);
|
|
53
53
|
}
|
|
54
54
|
else {
|
|
55
55
|
replaceHistoryState(getHistoryState(), url);
|
|
@@ -69,25 +69,29 @@ function assertState(state) {
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
function replaceHistoryState(state, url) {
|
|
72
|
-
|
|
72
|
+
const url_ = url ?? null; // Passing `undefined` chokes older Edge versions.
|
|
73
|
+
window.history.replaceState(state, '', url_);
|
|
73
74
|
}
|
|
74
75
|
function pushHistoryState(state, url) {
|
|
75
|
-
pushStateOriginal(
|
|
76
|
+
// Vike should call window.history.pushState() (and not the orignal `pushStateOriginal()`) so that other tools (e.g. user tracking) can listen to Vike's pushState() calls, see https://github.com/vikejs/vike/issues/1582.
|
|
77
|
+
window.history.pushState(state, '', url);
|
|
76
78
|
}
|
|
77
79
|
function monkeyPatchHistoryPushState() {
|
|
78
|
-
|
|
79
|
-
window.history.pushState = (
|
|
80
|
-
assertUsage(
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
80
|
+
const pushStateOriginal = window.history.pushState;
|
|
81
|
+
window.history.pushState = (stateOriginal = {}, ...rest) => {
|
|
82
|
+
assertUsage(stateOriginal === undefined || stateOriginal === null || isObject(stateOriginal), 'history.pushState(state) argument state must be an object');
|
|
83
|
+
const stateEnhanced = isVikeEnhanced(stateOriginal)
|
|
84
|
+
? stateOriginal
|
|
85
|
+
: {
|
|
86
|
+
_isVikeEnhanced: true,
|
|
87
|
+
scrollPosition: getScrollPosition(),
|
|
88
|
+
timestamp: getTimestamp(),
|
|
89
|
+
triggeredBy: 'user',
|
|
90
|
+
...stateOriginal
|
|
91
|
+
};
|
|
92
|
+
return pushStateOriginal(stateEnhanced, ...rest);
|
|
89
93
|
};
|
|
90
94
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
95
|
+
function isVikeEnhanced(state) {
|
|
96
|
+
return isObject(state) && '_isVikeEnhanced' in state;
|
|
93
97
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { projectInfo };
|
|
2
2
|
export { PROJECT_VERSION };
|
|
3
|
-
declare const PROJECT_VERSION: "0.4.167-commit-
|
|
3
|
+
declare const PROJECT_VERSION: "0.4.167-commit-aa83fde";
|
|
4
4
|
declare const projectInfo: {
|
|
5
5
|
projectName: "Vike";
|
|
6
|
-
projectVersion: "0.4.167-commit-
|
|
6
|
+
projectVersion: "0.4.167-commit-aa83fde";
|
|
7
7
|
};
|