@sveltejs/kit 1.0.0-next.536 → 1.0.0-next.537

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sveltejs/kit",
3
- "version": "1.0.0-next.536",
3
+ "version": "1.0.0-next.537",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/sveltejs/kit",
@@ -83,10 +83,10 @@ export function create_client({ target, base, trailing_slash }) {
83
83
  let load_cache = null;
84
84
 
85
85
  const callbacks = {
86
- /** @type {Array<(navigation: import('types').Navigation & { cancel: () => void }) => void>} */
86
+ /** @type {Array<(navigation: import('types').BeforeNavigate) => void>} */
87
87
  before_navigate: [],
88
88
 
89
- /** @type {Array<(navigation: import('types').Navigation) => void>} */
89
+ /** @type {Array<(navigation: import('types').AfterNavigate) => void>} */
90
90
  after_navigate: []
91
91
  };
92
92
 
@@ -382,7 +382,7 @@ export function create_client({ target, base, trailing_slash }) {
382
382
  });
383
383
  post_update();
384
384
 
385
- /** @type {import('types').Navigation} */
385
+ /** @type {import('types').AfterNavigate} */
386
386
  const navigation = {
387
387
  from: null,
388
388
  to: add_url_properties('to', {
@@ -1116,7 +1116,9 @@ export function create_client({ target, base, trailing_slash }) {
1116
1116
  nav_token,
1117
1117
  () => {
1118
1118
  navigating = false;
1119
- callbacks.after_navigate.forEach((fn) => fn(navigation));
1119
+ callbacks.after_navigate.forEach((fn) =>
1120
+ fn(/** @type {import('types').AfterNavigate} */ (navigation))
1121
+ );
1120
1122
  stores.navigating.set(null);
1121
1123
  }
1122
1124
  );
@@ -1307,7 +1309,7 @@ export function create_client({ target, base, trailing_slash }) {
1307
1309
  if (!navigating) {
1308
1310
  // If we're navigating, beforeNavigate was already called. If we end up in here during navigation,
1309
1311
  // it's due to an external or full-page-reload link, for which we don't want to call the hook again.
1310
- /** @type {import('types').Navigation & { cancel: () => void }} */
1312
+ /** @type {import('types').BeforeNavigate} */
1311
1313
  const navigation = {
1312
1314
  from: add_url_properties('from', {
1313
1315
  params: current.params,
@@ -171,7 +171,7 @@ declare module '$app/forms' {
171
171
  * ```
172
172
  */
173
173
  declare module '$app/navigation' {
174
- import { Navigation } from '@sveltejs/kit';
174
+ import { BeforeNavigate, AfterNavigate } from '@sveltejs/kit';
175
175
 
176
176
  /**
177
177
  * If called when the page is being updated following a navigation (in `onMount` or `afterNavigate` or an action, for example), this disables SvelteKit's built-in scroll handling.
@@ -261,16 +261,14 @@ declare module '$app/navigation' {
261
261
  *
262
262
  * `beforeNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
263
263
  */
264
- export function beforeNavigate(
265
- callback: (navigation: Navigation & { cancel(): void }) => void
266
- ): void;
264
+ export function beforeNavigate(callback: (navigation: BeforeNavigate) => void): void;
267
265
 
268
266
  /**
269
267
  * A lifecycle function that runs the supplied `callback` when the current component mounts, and also whenever we navigate to a new URL.
270
268
  *
271
269
  * `afterNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
272
270
  */
273
- export function afterNavigate(callback: (navigation: Navigation) => void): void;
271
+ export function afterNavigate(callback: (navigation: AfterNavigate) => void): void;
274
272
  }
275
273
 
276
274
  /**
package/types/index.d.ts CHANGED
@@ -414,13 +414,12 @@ export interface Navigation {
414
414
  to: NavigationTarget | null;
415
415
  /**
416
416
  * The type of navigation:
417
- * - `enter`: The app has hydrated
418
417
  * - `leave`: The user is leaving the app by closing the tab or using the back/forward buttons to go to a different document
419
418
  * - `link`: Navigation was triggered by a link click
420
419
  * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
421
420
  * - `popstate`: Navigation was triggered by back/forward navigation
422
421
  */
423
- type: NavigationType;
422
+ type: Omit<NavigationType, 'enter'>;
424
423
  /**
425
424
  * Whether or not the navigation will result in the page being unloaded (i.e. not a client-side navigation)
426
425
  */
@@ -431,6 +430,31 @@ export interface Navigation {
431
430
  delta?: number;
432
431
  }
433
432
 
433
+ /**
434
+ * The interface that corresponds to the `beforeNavigate`'s input parameter.
435
+ */
436
+ export interface BeforeNavigate extends Navigation {
437
+ /**
438
+ * Call this to prevent the navigation from starting.
439
+ */
440
+ cancel(): void;
441
+ }
442
+
443
+ /**
444
+ * The interface that corresponds to the `afterNavigate`'s input parameter.
445
+ */
446
+ export interface AfterNavigate extends Navigation {
447
+ /**
448
+ * The type of navigation:
449
+ * - `enter`: The app has hydrated
450
+ * - `link`: Navigation was triggered by a link click
451
+ * - `goto`: Navigation was triggered by a `goto(...)` call or a redirect
452
+ * - `popstate`: Navigation was triggered by back/forward navigation
453
+ */
454
+ type: Omit<NavigationType, 'leave'>;
455
+ willUnload: false;
456
+ }
457
+
434
458
  /**
435
459
  * The shape of the `$page` store
436
460
  */