@sveltejs/kit 1.0.0-next.464 → 1.0.0-next.465
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 +2 -2
- package/src/runtime/client/client.js +48 -20
- package/types/ambient.d.ts +14 -6
- package/types/index.d.ts +6 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sveltejs/kit",
|
|
3
|
-
"version": "1.0.0-next.
|
|
3
|
+
"version": "1.0.0-next.465",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/sveltejs/kit",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"svelte-preprocess": "^4.10.6",
|
|
39
39
|
"typescript": "^4.8.2",
|
|
40
40
|
"uvu": "^0.5.3",
|
|
41
|
-
"vite": "^3.1.0-beta.
|
|
41
|
+
"vite": "^3.1.0-beta.2"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"svelte": "^3.44.0",
|
|
@@ -80,10 +80,10 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
const callbacks = {
|
|
83
|
-
/** @type {Array<(
|
|
83
|
+
/** @type {Array<(navigation: import('types').Navigation & { cancel: () => void }) => void>} */
|
|
84
84
|
before_navigate: [],
|
|
85
85
|
|
|
86
|
-
/** @type {Array<(
|
|
86
|
+
/** @type {Array<(navigation: import('types').Navigation) => void>} */
|
|
87
87
|
after_navigate: []
|
|
88
88
|
};
|
|
89
89
|
|
|
@@ -142,8 +142,10 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
142
142
|
|
|
143
143
|
function invalidate() {
|
|
144
144
|
if (!invalidating) {
|
|
145
|
+
const url = new URL(location.href);
|
|
146
|
+
|
|
145
147
|
invalidating = Promise.resolve().then(async () => {
|
|
146
|
-
await update(
|
|
148
|
+
await update(url, []);
|
|
147
149
|
|
|
148
150
|
invalidating = null;
|
|
149
151
|
force_invalidation = false;
|
|
@@ -177,7 +179,8 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
177
179
|
replaceState
|
|
178
180
|
},
|
|
179
181
|
accepted: () => {},
|
|
180
|
-
blocked: () => {}
|
|
182
|
+
blocked: () => {},
|
|
183
|
+
type: 'goto'
|
|
181
184
|
});
|
|
182
185
|
}
|
|
183
186
|
|
|
@@ -395,7 +398,8 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
395
398
|
});
|
|
396
399
|
}
|
|
397
400
|
|
|
398
|
-
|
|
401
|
+
/** @type {import('types').Navigation} */
|
|
402
|
+
const navigation = { from: null, to: new URL(location.href), type: 'load' };
|
|
399
403
|
callbacks.after_navigate.forEach((fn) => fn(navigation));
|
|
400
404
|
|
|
401
405
|
started = true;
|
|
@@ -977,21 +981,44 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
977
981
|
* replaceState: boolean;
|
|
978
982
|
* state: any;
|
|
979
983
|
* } | null;
|
|
984
|
+
* type: import('types').NavigationType;
|
|
985
|
+
* delta?: number;
|
|
980
986
|
* accepted: () => void;
|
|
981
987
|
* blocked: () => void;
|
|
982
988
|
* }} opts
|
|
983
989
|
*/
|
|
984
|
-
async function navigate({
|
|
985
|
-
|
|
990
|
+
async function navigate({
|
|
991
|
+
url,
|
|
992
|
+
scroll,
|
|
993
|
+
keepfocus,
|
|
994
|
+
redirect_chain,
|
|
995
|
+
details,
|
|
996
|
+
type,
|
|
997
|
+
delta,
|
|
998
|
+
accepted,
|
|
999
|
+
blocked
|
|
1000
|
+
}) {
|
|
986
1001
|
let should_block = false;
|
|
987
1002
|
|
|
1003
|
+
/** @type {import('types').Navigation} */
|
|
988
1004
|
const navigation = {
|
|
989
|
-
from,
|
|
1005
|
+
from: current.url,
|
|
990
1006
|
to: url,
|
|
991
|
-
|
|
1007
|
+
type
|
|
1008
|
+
};
|
|
1009
|
+
|
|
1010
|
+
if (delta !== undefined) {
|
|
1011
|
+
navigation.delta = delta;
|
|
1012
|
+
}
|
|
1013
|
+
|
|
1014
|
+
const cancellable = {
|
|
1015
|
+
...navigation,
|
|
1016
|
+
cancel: () => {
|
|
1017
|
+
should_block = true;
|
|
1018
|
+
}
|
|
992
1019
|
};
|
|
993
1020
|
|
|
994
|
-
callbacks.before_navigate.forEach((fn) => fn(
|
|
1021
|
+
callbacks.before_navigate.forEach((fn) => fn(cancellable));
|
|
995
1022
|
|
|
996
1023
|
if (should_block) {
|
|
997
1024
|
blocked();
|
|
@@ -1003,10 +1030,7 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
1003
1030
|
accepted();
|
|
1004
1031
|
|
|
1005
1032
|
if (started) {
|
|
1006
|
-
stores.navigating.set(
|
|
1007
|
-
from: current.url,
|
|
1008
|
-
to: url
|
|
1009
|
-
});
|
|
1033
|
+
stores.navigating.set(navigation);
|
|
1010
1034
|
}
|
|
1011
1035
|
|
|
1012
1036
|
await update(
|
|
@@ -1018,9 +1042,7 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
1018
1042
|
details
|
|
1019
1043
|
},
|
|
1020
1044
|
() => {
|
|
1021
|
-
const navigation = { from, to: url };
|
|
1022
1045
|
callbacks.after_navigate.forEach((fn) => fn(navigation));
|
|
1023
|
-
|
|
1024
1046
|
stores.navigating.set(null);
|
|
1025
1047
|
}
|
|
1026
1048
|
);
|
|
@@ -1129,9 +1151,11 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
1129
1151
|
addEventListener('beforeunload', (e) => {
|
|
1130
1152
|
let should_block = false;
|
|
1131
1153
|
|
|
1154
|
+
/** @type {import('types').Navigation & { cancel: () => void }} */
|
|
1132
1155
|
const navigation = {
|
|
1133
1156
|
from: current.url,
|
|
1134
1157
|
to: null,
|
|
1158
|
+
type: 'unload',
|
|
1135
1159
|
cancel: () => (should_block = true)
|
|
1136
1160
|
};
|
|
1137
1161
|
|
|
@@ -1244,7 +1268,8 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
1244
1268
|
replaceState: url.href === location.href
|
|
1245
1269
|
},
|
|
1246
1270
|
accepted: () => event.preventDefault(),
|
|
1247
|
-
blocked: () => event.preventDefault()
|
|
1271
|
+
blocked: () => event.preventDefault(),
|
|
1272
|
+
type: 'link'
|
|
1248
1273
|
});
|
|
1249
1274
|
});
|
|
1250
1275
|
|
|
@@ -1254,6 +1279,8 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
1254
1279
|
// with history.go, which means we end up back here, hence this check
|
|
1255
1280
|
if (event.state[INDEX_KEY] === current_history_index) return;
|
|
1256
1281
|
|
|
1282
|
+
const delta = event.state[INDEX_KEY] - current_history_index;
|
|
1283
|
+
|
|
1257
1284
|
navigate({
|
|
1258
1285
|
url: new URL(location.href),
|
|
1259
1286
|
scroll: scroll_positions[event.state[INDEX_KEY]],
|
|
@@ -1264,9 +1291,10 @@ export function create_client({ target, base, trailing_slash }) {
|
|
|
1264
1291
|
current_history_index = event.state[INDEX_KEY];
|
|
1265
1292
|
},
|
|
1266
1293
|
blocked: () => {
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1294
|
+
history.go(-delta);
|
|
1295
|
+
},
|
|
1296
|
+
type: 'popstate',
|
|
1297
|
+
delta
|
|
1270
1298
|
});
|
|
1271
1299
|
}
|
|
1272
1300
|
});
|
package/types/ambient.d.ts
CHANGED
|
@@ -95,6 +95,8 @@ declare module '$app/environment' {
|
|
|
95
95
|
* ```
|
|
96
96
|
*/
|
|
97
97
|
declare module '$app/navigation' {
|
|
98
|
+
import { Navigation } from '@sveltejs/kit';
|
|
99
|
+
|
|
98
100
|
/**
|
|
99
101
|
* 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.
|
|
100
102
|
* This is generally discouraged, since it breaks user expectations.
|
|
@@ -158,17 +160,23 @@ declare module '$app/navigation' {
|
|
|
158
160
|
export function prefetchRoutes(routes?: string[]): Promise<void>;
|
|
159
161
|
|
|
160
162
|
/**
|
|
161
|
-
* A navigation interceptor that triggers before we navigate to a new URL
|
|
162
|
-
*
|
|
163
|
+
* A navigation interceptor that triggers before we navigate to a new URL, whether by clicking a link, calling `goto(...)`, or using the browser back/forward controls.
|
|
164
|
+
* Calling `cancel()` will prevent the navigation from completing.
|
|
165
|
+
*
|
|
166
|
+
* When navigating to an external URL, `navigation.to` will be `null`.
|
|
167
|
+
*
|
|
168
|
+
* `beforeNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
|
|
163
169
|
*/
|
|
164
170
|
export function beforeNavigate(
|
|
165
|
-
|
|
171
|
+
callback: (navigation: Navigation & { cancel: () => void }) => void
|
|
166
172
|
): void;
|
|
167
173
|
|
|
168
174
|
/**
|
|
169
|
-
* A lifecycle function that runs when the
|
|
175
|
+
* A lifecycle function that runs the supplied `callback` when the current component mounts, and also whenever we navigate to a new URL.
|
|
176
|
+
*
|
|
177
|
+
* `afterNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
|
|
170
178
|
*/
|
|
171
|
-
export function afterNavigate(
|
|
179
|
+
export function afterNavigate(callback: (navigation: Navigation) => void): void;
|
|
172
180
|
}
|
|
173
181
|
|
|
174
182
|
/**
|
|
@@ -210,7 +218,7 @@ declare module '$app/stores' {
|
|
|
210
218
|
export const page: Readable<Page>;
|
|
211
219
|
/**
|
|
212
220
|
* A readable store.
|
|
213
|
-
* When navigating starts, its value is `
|
|
221
|
+
* When navigating starts, its value is a `Navigation` object with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
|
|
214
222
|
* When navigating finishes, its value reverts to `null`.
|
|
215
223
|
*/
|
|
216
224
|
export const navigating: Readable<Navigation | null>;
|
package/types/index.d.ts
CHANGED
|
@@ -219,9 +219,13 @@ export interface LoadEvent<
|
|
|
219
219
|
depends: (...deps: string[]) => void;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
export type NavigationType = 'load' | 'unload' | 'link' | 'goto' | 'popstate';
|
|
223
|
+
|
|
222
224
|
export interface Navigation {
|
|
223
|
-
from: URL;
|
|
224
|
-
to: URL;
|
|
225
|
+
from: URL | null;
|
|
226
|
+
to: URL | null;
|
|
227
|
+
type: NavigationType;
|
|
228
|
+
delta?: number;
|
|
225
229
|
}
|
|
226
230
|
|
|
227
231
|
export interface Page<Params extends Record<string, string> = Record<string, string>> {
|