vike 0.4.199-commit-6991a96 → 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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prefetch = exports.reload = exports.navigate = void 0;
3
+ exports.onPopState = exports.prefetch = exports.reload = exports.navigate = void 0;
4
4
  const assert_js_1 = require("../../utils/assert.js");
5
5
  // `never` to ensure package.json#exports["./client/router"].types points to type defined by the client-side code
6
6
  const navigate = (() => warnNoEffect('navigate'));
@@ -9,6 +9,8 @@ const reload = (() => warnNoEffect('reload'));
9
9
  exports.reload = reload;
10
10
  const prefetch = (() => warnNoEffect('prefetch'));
11
11
  exports.prefetch = prefetch;
12
+ const onPopState = (() => { });
13
+ exports.onPopState = onPopState;
12
14
  function warnNoEffect(caller) {
13
15
  (0, assert_js_1.assertWarning)(false, `Calling ${caller}() on the server-side has no effect`, {
14
16
  showStackTrace: true,
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROJECT_VERSION = void 0;
4
4
  // Automatically updated by @brillout/release-me
5
- exports.PROJECT_VERSION = '0.4.199-commit-6991a96';
5
+ exports.PROJECT_VERSION = '0.4.199-commit-43cc34a';
@@ -3,18 +3,16 @@ export { updateState };
3
3
  export { onPopState };
4
4
  declare function initOnPopState(): void;
5
5
  type Listener = (arg: {
6
- _experimental: {
7
- previousState: ReturnType<typeof getState>;
8
- };
9
- }) => undefined | boolean;
6
+ previous: ReturnType<typeof getState>;
7
+ }) => void | boolean;
10
8
  /** Control client-side navigation.
11
9
  *
12
10
  * https://vike.dev/onPopState
13
11
  */
14
12
  declare function onPopState(listener: Listener): void;
15
13
  declare function getState(): {
16
- urlWithoutHash: string;
17
- historyState: {
14
+ url: `/${string}`;
15
+ state: {
18
16
  timestamp: number;
19
17
  scrollPosition: null | import("./history.js").ScrollPosition;
20
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 { previousState } = globalObject;
21
- const currentState = getState();
22
- globalObject.previousState = currentState;
23
- const scrollTarget = currentState.historyState?.scrollPosition || undefined;
24
- const isHashNavigation = currentState.urlWithoutHash === previousState.urlWithoutHash;
25
- const isBackwardNavigation = !currentState.historyState?.timestamp || !previousState.historyState?.timestamp
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
- : currentState.historyState.timestamp < previousState.historyState.timestamp;
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({ _experimental: { previousState } }));
56
+ abort || (abort = listener({ previous }));
57
57
  });
58
58
  if (abort)
59
59
  return;
@@ -69,10 +69,13 @@ function onPopState(listener) {
69
69
  }
70
70
  function getState() {
71
71
  return {
72
- urlWithoutHash: getCurrentUrl({ withoutHash: true }),
73
- historyState: getHistoryState()
72
+ url: getCurrentUrl(),
73
+ state: getHistoryState()
74
74
  };
75
75
  }
76
+ function removeHash(url) {
77
+ return url.split('#')[0];
78
+ }
76
79
  function updateState() {
77
80
  globalObject.previousState = getState();
78
81
  }
@@ -1,6 +1,8 @@
1
1
  export { navigate };
2
2
  export { reload };
3
3
  export { prefetch };
4
+ export { onPopState };
4
5
  declare const navigate: never;
5
6
  declare const reload: never;
6
7
  declare const prefetch: never;
8
+ declare const onPopState: never;
@@ -1,11 +1,13 @@
1
1
  export { navigate };
2
2
  export { reload };
3
3
  export { prefetch };
4
+ export { onPopState };
4
5
  import { assertWarning } from '../../utils/assert.js';
5
6
  // `never` to ensure package.json#exports["./client/router"].types points to type defined by the client-side code
6
7
  const navigate = (() => warnNoEffect('navigate'));
7
8
  const reload = (() => warnNoEffect('reload'));
8
9
  const prefetch = (() => warnNoEffect('prefetch'));
10
+ const onPopState = (() => { });
9
11
  function warnNoEffect(caller) {
10
12
  assertWarning(false, `Calling ${caller}() on the server-side has no effect`, {
11
13
  showStackTrace: true,
@@ -1 +1 @@
1
- export declare const PROJECT_VERSION: "0.4.199-commit-6991a96";
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-6991a96';
2
+ export const PROJECT_VERSION = '0.4.199-commit-43cc34a';
@@ -1,4 +1,4 @@
1
1
  export { getCurrentUrl };
2
2
  declare function getCurrentUrl(options?: {
3
3
  withoutHash: true;
4
- }): string;
4
+ }): `/${string}`;
@@ -1,4 +1,4 @@
1
1
  export declare const projectInfo: {
2
2
  projectName: "Vike";
3
- projectVersion: "0.4.199-commit-6991a96";
3
+ projectVersion: "0.4.199-commit-43cc34a";
4
4
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike",
3
- "version": "0.4.199-commit-6991a96",
3
+ "version": "0.4.199-commit-43cc34a",
4
4
  "repository": "https://github.com/vikejs/vike",
5
5
  "exports": {
6
6
  "./server": {