@sveltejs/kit 1.17.1 → 1.19.0
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 +6 -1
- package/src/core/adapt/builder.js +3 -3
- package/src/core/config/index.js +2 -2
- package/src/core/config/options.js +8 -3
- package/src/core/env.js +1 -1
- package/src/core/generate_manifest/index.js +2 -2
- package/src/core/postbuild/analyse.js +3 -3
- package/src/core/postbuild/fallback.js +1 -1
- package/src/core/postbuild/prerender.js +1 -1
- package/src/core/sync/create_manifest_data/index.js +2 -2
- package/src/core/sync/write_ambient.js +1 -1
- package/src/core/sync/write_client_manifest.js +1 -1
- package/src/core/sync/write_server.js +2 -1
- package/src/core/sync/write_types/index.js +24 -24
- package/src/exports/hooks/sequence.js +71 -7
- package/src/exports/index.js +88 -12
- package/src/exports/node/index.js +14 -3
- package/src/exports/node/polyfills.js +8 -0
- package/src/exports/public.d.ts +1264 -0
- package/src/exports/vite/build/build_server.js +2 -2
- package/src/exports/vite/build/build_service_worker.js +1 -1
- package/src/exports/vite/dev/index.js +3 -3
- package/src/exports/vite/index.js +11 -6
- package/src/runtime/app/environment.js +3 -4
- package/src/runtime/app/forms.js +63 -7
- package/src/runtime/app/navigation.js +95 -0
- package/src/runtime/app/stores.js +28 -7
- package/src/runtime/client/client.js +26 -14
- package/src/runtime/client/singletons.js +6 -4
- package/src/runtime/client/start.js +1 -1
- package/src/runtime/client/types.d.ts +4 -12
- package/src/runtime/client/utils.js +29 -10
- package/src/runtime/control.js +12 -9
- package/src/runtime/server/ambient.d.ts +3 -3
- package/src/runtime/server/cookie.js +3 -3
- package/src/runtime/server/data/index.js +5 -4
- package/src/runtime/server/endpoint.js +11 -4
- package/src/runtime/server/fetch.js +4 -6
- package/src/runtime/server/index.js +2 -2
- package/src/runtime/server/page/actions.js +13 -13
- package/src/runtime/server/page/csp.js +7 -2
- package/src/runtime/server/page/index.js +6 -5
- package/src/runtime/server/page/load_data.js +20 -9
- package/src/runtime/server/page/render.js +11 -11
- package/src/runtime/server/page/respond_with_error.js +4 -3
- package/src/runtime/server/respond.js +6 -6
- package/src/runtime/server/utils.js +7 -7
- package/src/types/ambient-private.d.ts +11 -0
- package/src/types/ambient.d.ts +108 -0
- package/{types → src/types}/internal.d.ts +4 -13
- package/{types → src/types}/private.d.ts +1 -10
- package/src/utils/error.js +3 -3
- package/src/utils/exports.js +2 -2
- package/src/utils/routing.js +1 -39
- package/src/utils/streaming.js +2 -2
- package/types/index.d.ts +2081 -1100
- package/types/index.d.ts.map +165 -0
- package/src/internal.d.ts +0 -16
- package/types/ambient.d.ts +0 -486
- /package/{types → src/types}/synthetic/$env+dynamic+private.md +0 -0
- /package/{types → src/types}/synthetic/$env+dynamic+public.md +0 -0
- /package/{types → src/types}/synthetic/$env+static+private.md +0 -0
- /package/{types → src/types}/synthetic/$env+static+public.md +0 -0
- /package/{types → src/types}/synthetic/$lib.md +0 -0
|
@@ -58,13 +58,13 @@ export function build_server_nodes(out, kit, manifest_data, server_manifest, cli
|
|
|
58
58
|
|
|
59
59
|
if (node.universal) {
|
|
60
60
|
imports.push(`import * as universal from '../${server_manifest[node.universal].file}';`);
|
|
61
|
-
exports.push(
|
|
61
|
+
exports.push('export { universal };');
|
|
62
62
|
exports.push(`export const universal_id = ${s(node.universal)};`);
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
if (node.server) {
|
|
66
66
|
imports.push(`import * as server from '../${server_manifest[node.server].file}';`);
|
|
67
|
-
exports.push(
|
|
67
|
+
exports.push('export { server };');
|
|
68
68
|
exports.push(`export const server_id = ${s(node.server)};`);
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -35,7 +35,7 @@ export async function build_service_worker(
|
|
|
35
35
|
|
|
36
36
|
// in a service worker, `location` is the location of the service worker itself,
|
|
37
37
|
// which is guaranteed to be `<base>/service-worker.js`
|
|
38
|
-
const base =
|
|
38
|
+
const base = "location.pathname.split('/').slice(0, -1).join('/')";
|
|
39
39
|
|
|
40
40
|
fs.writeFileSync(
|
|
41
41
|
service_worker,
|
|
@@ -44,7 +44,7 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
44
44
|
|
|
45
45
|
/** @type {import('types').ManifestData} */
|
|
46
46
|
let manifest_data;
|
|
47
|
-
/** @type {import('
|
|
47
|
+
/** @type {import('@sveltejs/kit').SSRManifest} */
|
|
48
48
|
let manifest;
|
|
49
49
|
|
|
50
50
|
/** @type {Error | null} */
|
|
@@ -226,7 +226,7 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
226
226
|
})
|
|
227
227
|
),
|
|
228
228
|
matchers: async () => {
|
|
229
|
-
/** @type {Record<string, import('
|
|
229
|
+
/** @type {Record<string, import('@sveltejs/kit').ParamMatcher>} */
|
|
230
230
|
const matchers = {};
|
|
231
231
|
|
|
232
232
|
for (const key in manifest_data.matchers) {
|
|
@@ -346,7 +346,7 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
346
346
|
// This shameful hack allows us to load runtime server code via Vite
|
|
347
347
|
// while apps load `HttpError` and `Redirect` in Node, without
|
|
348
348
|
// causing `instanceof` checks to fail
|
|
349
|
-
const control_module_node = await import(
|
|
349
|
+
const control_module_node = await import('../../../runtime/control.js');
|
|
350
350
|
const control_module_vite = await vite.ssrLoadModule(`${runtime_base}/control.js`);
|
|
351
351
|
|
|
352
352
|
control_module_node.replace_implementations({
|
|
@@ -101,7 +101,7 @@ const warning_preprocessor = {
|
|
|
101
101
|
if (basename.startsWith('+layout.') && !content.includes('<slot')) {
|
|
102
102
|
const message =
|
|
103
103
|
`\n${colors.bold().red(path.relative('.', filename))}\n` +
|
|
104
|
-
|
|
104
|
+
'`<slot />` missing — inner content will not be rendered';
|
|
105
105
|
|
|
106
106
|
if (!warned.has(message)) {
|
|
107
107
|
console.log(message);
|
|
@@ -111,7 +111,10 @@ const warning_preprocessor = {
|
|
|
111
111
|
}
|
|
112
112
|
};
|
|
113
113
|
|
|
114
|
-
/**
|
|
114
|
+
/**
|
|
115
|
+
* Returns the SvelteKit Vite plugins.
|
|
116
|
+
* @returns {Promise<import('vite').Plugin[]>}
|
|
117
|
+
*/
|
|
115
118
|
export async function sveltekit() {
|
|
116
119
|
const svelte_config = await load_config();
|
|
117
120
|
|
|
@@ -342,7 +345,7 @@ function kit({ svelte_config }) {
|
|
|
342
345
|
|
|
343
346
|
const global = is_build
|
|
344
347
|
? `globalThis.__sveltekit_${version_hash}`
|
|
345
|
-
:
|
|
348
|
+
: 'globalThis.__sveltekit_dev';
|
|
346
349
|
|
|
347
350
|
if (options?.ssr === false && process.env.TEST !== 'true') {
|
|
348
351
|
const normalized_cwd = vite.normalizePath(cwd);
|
|
@@ -388,7 +391,7 @@ function kit({ svelte_config }) {
|
|
|
388
391
|
|
|
389
392
|
// for internal use only. it's published as $app/paths externally
|
|
390
393
|
// we use this alias so that we won't collide with user aliases
|
|
391
|
-
case '\0__sveltekit/paths':
|
|
394
|
+
case '\0__sveltekit/paths': {
|
|
392
395
|
const { assets, base } = svelte_config.kit.paths;
|
|
393
396
|
|
|
394
397
|
// use the values defined in `global`, but fall back to hard-coded values
|
|
@@ -424,8 +427,9 @@ function kit({ svelte_config }) {
|
|
|
424
427
|
assets = initial.assets = path;
|
|
425
428
|
}
|
|
426
429
|
`;
|
|
430
|
+
}
|
|
427
431
|
|
|
428
|
-
case '\0__sveltekit/environment':
|
|
432
|
+
case '\0__sveltekit/environment': {
|
|
429
433
|
const { version } = svelte_config.kit;
|
|
430
434
|
|
|
431
435
|
return dedent`
|
|
@@ -436,6 +440,7 @@ function kit({ svelte_config }) {
|
|
|
436
440
|
building = true;
|
|
437
441
|
}
|
|
438
442
|
`;
|
|
443
|
+
}
|
|
439
444
|
}
|
|
440
445
|
}
|
|
441
446
|
};
|
|
@@ -653,7 +658,7 @@ function kit({ svelte_config }) {
|
|
|
653
658
|
app_dir: kit.appDir,
|
|
654
659
|
app_path: `${kit.paths.base.slice(1)}${kit.paths.base ? '/' : ''}${kit.appDir}`,
|
|
655
660
|
manifest_data,
|
|
656
|
-
service_worker:
|
|
661
|
+
service_worker: service_worker_entry_file ? 'service-worker.js' : null, // TODO make file configurable?
|
|
657
662
|
client: null,
|
|
658
663
|
server_manifest
|
|
659
664
|
};
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { BROWSER, DEV } from 'esm-env';
|
|
2
|
+
export { building, version } from '__sveltekit/environment';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
+
* `true` if the app is running in the browser.
|
|
5
6
|
*/
|
|
6
7
|
export const browser = BROWSER;
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
|
-
*
|
|
10
|
+
* Whether the dev server is running. This is not guaranteed to correspond to `NODE_ENV` or `MODE`.
|
|
10
11
|
*/
|
|
11
12
|
export const dev = DEV;
|
|
12
|
-
|
|
13
|
-
export { building, version } from '__sveltekit/environment';
|
package/src/runtime/app/forms.js
CHANGED
|
@@ -1,11 +1,46 @@
|
|
|
1
1
|
import * as devalue from 'devalue';
|
|
2
|
-
import { DEV } from 'esm-env';
|
|
3
|
-
import {
|
|
2
|
+
import { BROWSER, DEV } from 'esm-env';
|
|
3
|
+
import { client } from '../client/singletons.js';
|
|
4
4
|
import { invalidateAll } from './navigation.js';
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
/**
|
|
7
|
+
* This action updates the `form` property of the current page with the given data and updates `$page.status`.
|
|
8
|
+
* In case of an error, it redirects to the nearest error page.
|
|
9
|
+
* @template {Record<string, unknown> | undefined} Success
|
|
10
|
+
* @template {Record<string, unknown> | undefined} Failure
|
|
11
|
+
* @param {import('@sveltejs/kit').ActionResult<Success, Failure>} result
|
|
12
|
+
* @returns {Promise<void>}
|
|
13
|
+
*/
|
|
14
|
+
export function applyAction(result) {
|
|
15
|
+
if (BROWSER) {
|
|
16
|
+
return client.apply_action(result);
|
|
17
|
+
} else {
|
|
18
|
+
throw new Error('Cannot call applyAction(...) on the server');
|
|
19
|
+
}
|
|
20
|
+
}
|
|
7
21
|
|
|
8
|
-
/**
|
|
22
|
+
/**
|
|
23
|
+
* Use this function to deserialize the response from a form submission.
|
|
24
|
+
* Usage:
|
|
25
|
+
*
|
|
26
|
+
* ```js
|
|
27
|
+
* import { deserialize } from '$app/forms';
|
|
28
|
+
*
|
|
29
|
+
* async function handleSubmit(event) {
|
|
30
|
+
* const response = await fetch('/form?/action', {
|
|
31
|
+
* method: 'POST',
|
|
32
|
+
* body: new FormData(event.target)
|
|
33
|
+
* });
|
|
34
|
+
*
|
|
35
|
+
* const result = deserialize(await response.text());
|
|
36
|
+
* // ...
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
39
|
+
* @template {Record<string, unknown> | undefined} Success
|
|
40
|
+
* @template {Record<string, unknown> | undefined} Failure
|
|
41
|
+
* @param {string} result
|
|
42
|
+
* @returns {import('@sveltejs/kit').ActionResult<Success, Failure>}
|
|
43
|
+
*/
|
|
9
44
|
export function deserialize(result) {
|
|
10
45
|
const parsed = JSON.parse(result);
|
|
11
46
|
if (parsed.data) {
|
|
@@ -39,7 +74,28 @@ function clone(element) {
|
|
|
39
74
|
return /** @type {T} */ (HTMLElement.prototype.cloneNode.call(element));
|
|
40
75
|
}
|
|
41
76
|
|
|
42
|
-
/**
|
|
77
|
+
/**
|
|
78
|
+
* This action enhances a `<form>` element that otherwise would work without JavaScript.
|
|
79
|
+
*
|
|
80
|
+
* The `submit` function is called upon submission with the given FormData and the `action` that should be triggered.
|
|
81
|
+
* If `cancel` is called, the form will not be submitted.
|
|
82
|
+
* You can use the abort `controller` to cancel the submission in case another one starts.
|
|
83
|
+
* If a function is returned, that function is called with the response from the server.
|
|
84
|
+
* If nothing is returned, the fallback will be used.
|
|
85
|
+
*
|
|
86
|
+
* If this function or its return value isn't set, it
|
|
87
|
+
* - falls back to updating the `form` prop with the returned data if the action is one same page as the form
|
|
88
|
+
* - updates `$page.status`
|
|
89
|
+
* - resets the `<form>` element and invalidates all data in case of successful submission with no redirect response
|
|
90
|
+
* - redirects in case of a redirect response
|
|
91
|
+
* - redirects to the nearest error page in case of an unexpected error
|
|
92
|
+
*
|
|
93
|
+
* If you provide a custom function with a callback and want to use the default behavior, invoke `update` in your callback.
|
|
94
|
+
* @template {Record<string, unknown> | undefined} Success
|
|
95
|
+
* @template {Record<string, unknown> | undefined} Failure
|
|
96
|
+
* @param {HTMLFormElement} form_element The form element
|
|
97
|
+
* @param {import('@sveltejs/kit').SubmitFunction<Success, Failure>} submit Submit callback
|
|
98
|
+
*/
|
|
43
99
|
export function enhance(form_element, submit = () => {}) {
|
|
44
100
|
if (DEV && clone(form_element).method !== 'post') {
|
|
45
101
|
throw new Error('use:enhance can only be used on <form> fields with method="POST"');
|
|
@@ -48,7 +104,7 @@ export function enhance(form_element, submit = () => {}) {
|
|
|
48
104
|
/**
|
|
49
105
|
* @param {{
|
|
50
106
|
* action: URL;
|
|
51
|
-
* result: import('
|
|
107
|
+
* result: import('@sveltejs/kit').ActionResult;
|
|
52
108
|
* reset?: boolean
|
|
53
109
|
* }} opts
|
|
54
110
|
*/
|
|
@@ -127,7 +183,7 @@ export function enhance(form_element, submit = () => {}) {
|
|
|
127
183
|
})) ?? fallback_callback;
|
|
128
184
|
if (cancelled) return;
|
|
129
185
|
|
|
130
|
-
/** @type {import('
|
|
186
|
+
/** @type {import('@sveltejs/kit').ActionResult} */
|
|
131
187
|
let result;
|
|
132
188
|
|
|
133
189
|
try {
|
|
@@ -1,17 +1,112 @@
|
|
|
1
1
|
import { client_method } from '../client/singletons.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* 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.
|
|
5
|
+
* This is generally discouraged, since it breaks user expectations.
|
|
6
|
+
* @returns {void}
|
|
7
|
+
*/
|
|
3
8
|
export const disableScrollHandling = /* @__PURE__ */ client_method('disable_scroll_handling');
|
|
4
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Returns a Promise that resolves when SvelteKit navigates (or fails to navigate, in which case the promise rejects) to the specified `url`.
|
|
12
|
+
* For external URLs, use `window.location = url` instead of calling `goto(url)`.
|
|
13
|
+
*
|
|
14
|
+
* @type {(url: string | URL, opts?: {
|
|
15
|
+
* replaceState?: boolean;
|
|
16
|
+
* noScroll?: boolean;
|
|
17
|
+
* keepFocus?: boolean;
|
|
18
|
+
* invalidateAll?: boolean;
|
|
19
|
+
* state?: any
|
|
20
|
+
* }) => Promise<void>}
|
|
21
|
+
* @param {string | URL} url Where to navigate to. Note that if you've set [`config.kit.paths.base`](https://kit.svelte.dev/docs/configuration#paths) and the URL is root-relative, you need to prepend the base path if you want to navigate within the app.
|
|
22
|
+
* @param {Object} [opts] Options related to the navigation
|
|
23
|
+
* @param {boolean} [opts.replaceState] If `true`, will replace the current `history` entry rather than creating a new one with `pushState`
|
|
24
|
+
* @param {boolean} [opts.noScroll] If `true`, the browser will maintain its scroll position rather than scrolling to the top of the page after navigation
|
|
25
|
+
* @param {boolean} [opts.keepFocus] If `true`, the currently focused element will retain focus after navigation. Otherwise, focus will be reset to the body
|
|
26
|
+
* @param {boolean} [invalidateAll] If `true`, all `load` functions of the page will be rerun. See https://kit.svelte.dev/docs/load#rerunning-load-functions for more info on invalidation.
|
|
27
|
+
* @param {any} [opts.state] The state of the new/updated history entry
|
|
28
|
+
* @returns {Promise<void>}
|
|
29
|
+
*/
|
|
5
30
|
export const goto = /* @__PURE__ */ client_method('goto');
|
|
6
31
|
|
|
32
|
+
/**
|
|
33
|
+
* Causes any `load` functions belonging to the currently active page to re-run if they depend on the `url` in question, via `fetch` or `depends`. Returns a `Promise` that resolves when the page is subsequently updated.
|
|
34
|
+
*
|
|
35
|
+
* If the argument is given as a `string` or `URL`, it must resolve to the same URL that was passed to `fetch` or `depends` (including query parameters).
|
|
36
|
+
* To create a custom identifier, use a string beginning with `[a-z]+:` (e.g. `custom:state`) — this is a valid URL.
|
|
37
|
+
*
|
|
38
|
+
* The `function` argument can be used define a custom predicate. It receives the full `URL` and causes `load` to rerun if `true` is returned.
|
|
39
|
+
* This can be useful if you want to invalidate based on a pattern instead of a exact match.
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* // Example: Match '/path' regardless of the query parameters
|
|
43
|
+
* import { invalidate } from '$app/navigation';
|
|
44
|
+
*
|
|
45
|
+
* invalidate((url) => url.pathname === '/path');
|
|
46
|
+
* ```
|
|
47
|
+
* @type {(url: string | URL | ((url: URL) => boolean)) => Promise<void>}
|
|
48
|
+
* @param {string | URL | ((url: URL) => boolean)} url The invalidated URL
|
|
49
|
+
* @returns {Promise<void>}
|
|
50
|
+
*/
|
|
7
51
|
export const invalidate = /* @__PURE__ */ client_method('invalidate');
|
|
8
52
|
|
|
53
|
+
/**
|
|
54
|
+
* Causes all `load` functions belonging to the currently active page to re-run. Returns a `Promise` that resolves when the page is subsequently updated.
|
|
55
|
+
* @type {() => Promise<void>}
|
|
56
|
+
* @returns {Promise<void>}
|
|
57
|
+
*/
|
|
9
58
|
export const invalidateAll = /* @__PURE__ */ client_method('invalidate_all');
|
|
10
59
|
|
|
60
|
+
/**
|
|
61
|
+
* Programmatically preloads the given page, which means
|
|
62
|
+
* 1. ensuring that the code for the page is loaded, and
|
|
63
|
+
* 2. calling the page's load function with the appropriate options.
|
|
64
|
+
*
|
|
65
|
+
* This is the same behaviour that SvelteKit triggers when the user taps or mouses over an `<a>` element with `data-sveltekit-preload-data`.
|
|
66
|
+
* If the next navigation is to `href`, the values returned from load will be used, making navigation instantaneous.
|
|
67
|
+
* Returns a Promise that resolves when the preload is complete.
|
|
68
|
+
*
|
|
69
|
+
* @type {(href: string) => Promise<void>}
|
|
70
|
+
* @param {string} href Page to preload
|
|
71
|
+
* @returns {Promise<void>}
|
|
72
|
+
*/
|
|
11
73
|
export const preloadData = /* @__PURE__ */ client_method('preload_data');
|
|
12
74
|
|
|
75
|
+
/**
|
|
76
|
+
* Programmatically imports the code for routes that haven't yet been fetched.
|
|
77
|
+
* Typically, you might call this to speed up subsequent navigation.
|
|
78
|
+
*
|
|
79
|
+
* You can specify routes by any matching pathname such as `/about` (to match `src/routes/about/+page.svelte`) or `/blog/*` (to match `src/routes/blog/[slug]/+page.svelte`).
|
|
80
|
+
*
|
|
81
|
+
* Unlike `preloadData`, this won't call `load` functions.
|
|
82
|
+
* Returns a Promise that resolves when the modules have been imported.
|
|
83
|
+
*
|
|
84
|
+
* @type {(...urls: string[]) => Promise<void>}
|
|
85
|
+
* @param {...string[]} urls
|
|
86
|
+
* @returns {Promise<void>}
|
|
87
|
+
*/
|
|
13
88
|
export const preloadCode = /* @__PURE__ */ client_method('preload_code');
|
|
14
89
|
|
|
90
|
+
/**
|
|
91
|
+
* 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.
|
|
92
|
+
* Calling `cancel()` will prevent the navigation from completing. If the navigation would have directly unloaded the current page, calling `cancel` will trigger the native
|
|
93
|
+
* browser unload confirmation dialog. In these cases, `navigation.willUnload` is `true`.
|
|
94
|
+
*
|
|
95
|
+
* When a navigation isn't client side, `navigation.to.route.id` will be `null`.
|
|
96
|
+
*
|
|
97
|
+
* `beforeNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
|
|
98
|
+
* @type {(callback: (navigation: import('@sveltejs/kit').BeforeNavigate) => void) => void}
|
|
99
|
+
* @param {(navigation: import('@sveltejs/kit').BeforeNavigate) => void} callback
|
|
100
|
+
* @returns {void}
|
|
101
|
+
*/
|
|
15
102
|
export const beforeNavigate = /* @__PURE__ */ client_method('before_navigate');
|
|
16
103
|
|
|
104
|
+
/**
|
|
105
|
+
* A lifecycle function that runs the supplied `callback` when the current component mounts, and also whenever we navigate to a new URL.
|
|
106
|
+
*
|
|
107
|
+
* `afterNavigate` must be called during a component initialization. It remains active as long as the component is mounted.
|
|
108
|
+
* @type {(callback: (navigation: import('@sveltejs/kit').AfterNavigate) => void) => void}
|
|
109
|
+
* @param {(navigation: import('@sveltejs/kit').AfterNavigate) => void} callback
|
|
110
|
+
* @returns {void}
|
|
111
|
+
*/
|
|
17
112
|
export const afterNavigate = /* @__PURE__ */ client_method('after_navigate');
|
|
@@ -3,32 +3,48 @@ import { browser } from './environment.js';
|
|
|
3
3
|
import { stores as browser_stores } from '../client/singletons.js';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
6
|
+
* A function that returns all of the contextual stores. On the server, this must be called during component initialization.
|
|
7
|
+
* Only use this if you need to defer store subscription until after the component has mounted, for some reason.
|
|
7
8
|
*/
|
|
8
9
|
export const getStores = () => {
|
|
9
10
|
const stores = browser ? browser_stores : getContext('__svelte__');
|
|
10
11
|
|
|
11
12
|
return {
|
|
13
|
+
/** @type {typeof page} */
|
|
12
14
|
page: {
|
|
13
15
|
subscribe: stores.page.subscribe
|
|
14
16
|
},
|
|
17
|
+
/** @type {typeof navigating} */
|
|
15
18
|
navigating: {
|
|
16
19
|
subscribe: stores.navigating.subscribe
|
|
17
20
|
},
|
|
21
|
+
/** @type {typeof updated} */
|
|
18
22
|
updated: stores.updated
|
|
19
23
|
};
|
|
20
24
|
};
|
|
21
25
|
|
|
22
|
-
/**
|
|
26
|
+
/**
|
|
27
|
+
* A readable store whose value contains page data.
|
|
28
|
+
*
|
|
29
|
+
* On the server, this store can only be subscribed to during component initialization. In the browser, it can be subscribed to at any time.
|
|
30
|
+
*
|
|
31
|
+
* @type {import('svelte/store').Readable<import('@sveltejs/kit').Page>}
|
|
32
|
+
*/
|
|
23
33
|
export const page = {
|
|
24
|
-
/** @param {(value: any) => void} fn */
|
|
25
34
|
subscribe(fn) {
|
|
26
35
|
const store = __SVELTEKIT_DEV__ ? get_store('page') : getStores().page;
|
|
27
36
|
return store.subscribe(fn);
|
|
28
37
|
}
|
|
29
38
|
};
|
|
30
39
|
|
|
31
|
-
/**
|
|
40
|
+
/**
|
|
41
|
+
* A readable store.
|
|
42
|
+
* When navigating starts, its value is a `Navigation` object with `from`, `to`, `type` and (if `type === 'popstate'`) `delta` properties.
|
|
43
|
+
* When navigating finishes, its value reverts to `null`.
|
|
44
|
+
*
|
|
45
|
+
* On the server, this store can only be subscribed to during component initialization. In the browser, it can be subscribed to at any time.
|
|
46
|
+
* @type {import('svelte/store').Readable<import('@sveltejs/kit').Navigation | null>}
|
|
47
|
+
*/
|
|
32
48
|
export const navigating = {
|
|
33
49
|
subscribe(fn) {
|
|
34
50
|
const store = __SVELTEKIT_DEV__ ? get_store('navigating') : getStores().navigating;
|
|
@@ -36,7 +52,12 @@ export const navigating = {
|
|
|
36
52
|
}
|
|
37
53
|
};
|
|
38
54
|
|
|
39
|
-
/**
|
|
55
|
+
/**
|
|
56
|
+
* A readable store whose initial value is `false`. If [`version.pollInterval`](https://kit.svelte.dev/docs/configuration#version) is a non-zero value, SvelteKit will poll for new versions of the app and update the store value to `true` when it detects one. `updated.check()` will force an immediate check, regardless of polling.
|
|
57
|
+
*
|
|
58
|
+
* On the server, this store can only be subscribed to during component initialization. In the browser, it can be subscribed to at any time.
|
|
59
|
+
* @type {import('svelte/store').Readable<boolean> & { check(): Promise<boolean> }}
|
|
60
|
+
*/
|
|
40
61
|
export const updated = {
|
|
41
62
|
subscribe(fn) {
|
|
42
63
|
const store = __SVELTEKIT_DEV__ ? get_store('updated') : getStores().updated;
|
|
@@ -50,8 +71,8 @@ export const updated = {
|
|
|
50
71
|
check: () => {
|
|
51
72
|
throw new Error(
|
|
52
73
|
browser
|
|
53
|
-
?
|
|
54
|
-
:
|
|
74
|
+
? 'Cannot check updated store before subscribing'
|
|
75
|
+
: 'Can only check updated store in browser'
|
|
55
76
|
);
|
|
56
77
|
}
|
|
57
78
|
};
|
|
@@ -86,10 +86,10 @@ export function create_client(app, target) {
|
|
|
86
86
|
let load_cache = null;
|
|
87
87
|
|
|
88
88
|
const callbacks = {
|
|
89
|
-
/** @type {Array<(navigation: import('
|
|
89
|
+
/** @type {Array<(navigation: import('@sveltejs/kit').BeforeNavigate) => void>} */
|
|
90
90
|
before_navigate: [],
|
|
91
91
|
|
|
92
|
-
/** @type {Array<(navigation: import('
|
|
92
|
+
/** @type {Array<(navigation: import('@sveltejs/kit').AfterNavigate) => void>} */
|
|
93
93
|
after_navigate: []
|
|
94
94
|
};
|
|
95
95
|
|
|
@@ -138,7 +138,7 @@ export function create_client(app, target) {
|
|
|
138
138
|
scrollTo(scroll.x, scroll.y);
|
|
139
139
|
}
|
|
140
140
|
|
|
141
|
-
/** @type {import('
|
|
141
|
+
/** @type {import('@sveltejs/kit').Page} */
|
|
142
142
|
let page;
|
|
143
143
|
|
|
144
144
|
/** @type {{}} */
|
|
@@ -279,7 +279,7 @@ export function create_client(app, target) {
|
|
|
279
279
|
const style = document.querySelector('style[data-sveltekit]');
|
|
280
280
|
if (style) style.remove();
|
|
281
281
|
|
|
282
|
-
page = /** @type {import('
|
|
282
|
+
page = /** @type {import('@sveltejs/kit').Page} */ (result.props.page);
|
|
283
283
|
|
|
284
284
|
root = new app.root({
|
|
285
285
|
target,
|
|
@@ -289,7 +289,7 @@ export function create_client(app, target) {
|
|
|
289
289
|
|
|
290
290
|
restore_snapshot(current_history_index);
|
|
291
291
|
|
|
292
|
-
/** @type {import('
|
|
292
|
+
/** @type {import('@sveltejs/kit').AfterNavigate} */
|
|
293
293
|
const navigation = {
|
|
294
294
|
from: null,
|
|
295
295
|
to: {
|
|
@@ -332,6 +332,7 @@ export function create_client(app, target) {
|
|
|
332
332
|
if (node?.slash !== undefined) slash = node.slash;
|
|
333
333
|
}
|
|
334
334
|
url.pathname = normalize_path(url.pathname, slash);
|
|
335
|
+
// eslint-disable-next-line
|
|
335
336
|
url.search = url.search; // turn `/?` into `/`
|
|
336
337
|
|
|
337
338
|
/** @type {import('./types').NavigationFinished} */
|
|
@@ -445,7 +446,7 @@ export function create_client(app, target) {
|
|
|
445
446
|
}
|
|
446
447
|
}
|
|
447
448
|
|
|
448
|
-
/** @type {import('
|
|
449
|
+
/** @type {import('@sveltejs/kit').LoadEvent} */
|
|
449
450
|
const load_input = {
|
|
450
451
|
route: {
|
|
451
452
|
get id() {
|
|
@@ -900,7 +901,7 @@ export function create_client(app, target) {
|
|
|
900
901
|
/**
|
|
901
902
|
* @param {{
|
|
902
903
|
* url: URL;
|
|
903
|
-
* type: import('
|
|
904
|
+
* type: import('@sveltejs/kit').NavigationType;
|
|
904
905
|
* intent?: import('./types').NavigationIntent;
|
|
905
906
|
* delta?: number;
|
|
906
907
|
* }} opts
|
|
@@ -908,7 +909,7 @@ export function create_client(app, target) {
|
|
|
908
909
|
function before_navigate({ url, type, intent, delta }) {
|
|
909
910
|
let should_block = false;
|
|
910
911
|
|
|
911
|
-
/** @type {import('
|
|
912
|
+
/** @type {import('@sveltejs/kit').Navigation} */
|
|
912
913
|
const navigation = {
|
|
913
914
|
from: {
|
|
914
915
|
params: current.params,
|
|
@@ -953,7 +954,7 @@ export function create_client(app, target) {
|
|
|
953
954
|
* replaceState: boolean;
|
|
954
955
|
* state: any;
|
|
955
956
|
* } | null;
|
|
956
|
-
* type: import('
|
|
957
|
+
* type: import('@sveltejs/kit').NavigationType;
|
|
957
958
|
* delta?: number;
|
|
958
959
|
* nav_token?: {};
|
|
959
960
|
* accepted: () => void;
|
|
@@ -1141,7 +1142,7 @@ export function create_client(app, target) {
|
|
|
1141
1142
|
}
|
|
1142
1143
|
|
|
1143
1144
|
callbacks.after_navigate.forEach((fn) =>
|
|
1144
|
-
fn(/** @type {import('
|
|
1145
|
+
fn(/** @type {import('@sveltejs/kit').AfterNavigate} */ (navigation))
|
|
1145
1146
|
);
|
|
1146
1147
|
stores.navigating.set(null);
|
|
1147
1148
|
|
|
@@ -1173,7 +1174,7 @@ export function create_client(app, target) {
|
|
|
1173
1174
|
'An error occurred while loading the page. This will cause a full page reload. (This message will only appear during development.)'
|
|
1174
1175
|
);
|
|
1175
1176
|
|
|
1176
|
-
debugger;
|
|
1177
|
+
debugger; // eslint-disable-line
|
|
1177
1178
|
}
|
|
1178
1179
|
|
|
1179
1180
|
return await native_navigation(url);
|
|
@@ -1295,7 +1296,7 @@ export function create_client(app, target) {
|
|
|
1295
1296
|
|
|
1296
1297
|
/**
|
|
1297
1298
|
* @param {unknown} error
|
|
1298
|
-
* @param {import('
|
|
1299
|
+
* @param {import('@sveltejs/kit').NavigationEvent} event
|
|
1299
1300
|
* @returns {import('types').MaybePromise<App.Error>}
|
|
1300
1301
|
*/
|
|
1301
1302
|
function handle_error(error, event) {
|
|
@@ -1444,7 +1445,7 @@ export function create_client(app, target) {
|
|
|
1444
1445
|
if (!navigating) {
|
|
1445
1446
|
// If we're navigating, beforeNavigate was already called. If we end up in here during navigation,
|
|
1446
1447
|
// it's due to an external or full-page-reload link, for which we don't want to call the hook again.
|
|
1447
|
-
/** @type {import('
|
|
1448
|
+
/** @type {import('@sveltejs/kit').BeforeNavigate} */
|
|
1448
1449
|
const navigation = {
|
|
1449
1450
|
from: {
|
|
1450
1451
|
params: current.params,
|
|
@@ -1538,6 +1539,15 @@ export function create_client(app, target) {
|
|
|
1538
1539
|
// Removing the hash does a full page navigation in the browser, so make sure a hash is present
|
|
1539
1540
|
const [nonhash, hash] = url.href.split('#');
|
|
1540
1541
|
if (hash !== undefined && nonhash === location.href.split('#')[0]) {
|
|
1542
|
+
// If we are trying to navigate to the same hash, we should only
|
|
1543
|
+
// attempt to scroll to that element and avoid any history changes.
|
|
1544
|
+
// Otherwise, this can cause Firefox to incorrectly assign a null
|
|
1545
|
+
// history state value without any signal that we can detect.
|
|
1546
|
+
if (current.url.hash === url.hash) {
|
|
1547
|
+
event.preventDefault();
|
|
1548
|
+
a.ownerDocument.getElementById(hash)?.scrollIntoView();
|
|
1549
|
+
return;
|
|
1550
|
+
}
|
|
1541
1551
|
// set this flag to distinguish between navigations triggered by
|
|
1542
1552
|
// clicking a hash link and those triggered by popstate
|
|
1543
1553
|
hash_navigating = true;
|
|
@@ -1679,7 +1689,7 @@ export function create_client(app, target) {
|
|
|
1679
1689
|
// URLs after a pushState/replaceState, resulting in a 404 — see
|
|
1680
1690
|
// https://github.com/sveltejs/kit/issues/3748#issuecomment-1125980897
|
|
1681
1691
|
for (const link of document.querySelectorAll('link')) {
|
|
1682
|
-
if (link.rel === 'icon') link.href = link.href;
|
|
1692
|
+
if (link.rel === 'icon') link.href = link.href; // eslint-disable-line
|
|
1683
1693
|
}
|
|
1684
1694
|
|
|
1685
1695
|
addEventListener('pageshow', (event) => {
|
|
@@ -1806,6 +1816,8 @@ async function load_data(url, invalid) {
|
|
|
1806
1816
|
throw new HttpError(res.status, await res.json());
|
|
1807
1817
|
}
|
|
1808
1818
|
|
|
1819
|
+
// TODO: fix eslint error
|
|
1820
|
+
// eslint-disable-next-line
|
|
1809
1821
|
return new Promise(async (resolve) => {
|
|
1810
1822
|
/**
|
|
1811
1823
|
* Map of deferred promises that will be resolved by a subsequent chunk of data
|
|
@@ -44,8 +44,10 @@ export function client_method(key) {
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
export const stores = {
|
|
47
|
-
url: notifiable_store({}),
|
|
48
|
-
page: notifiable_store({}),
|
|
49
|
-
navigating:
|
|
50
|
-
|
|
47
|
+
url: /* @__PURE__ */ notifiable_store({}),
|
|
48
|
+
page: /* @__PURE__ */ notifiable_store({}),
|
|
49
|
+
navigating: /* @__PURE__ */ writable(
|
|
50
|
+
/** @type {import('@sveltejs/kit').Navigation | null} */ (null)
|
|
51
|
+
),
|
|
52
|
+
updated: /* @__PURE__ */ create_updated_store()
|
|
51
53
|
};
|
|
@@ -10,7 +10,7 @@ import { init } from './singletons.js';
|
|
|
10
10
|
export async function start(app, target, hydrate) {
|
|
11
11
|
if (DEV && target === document.body) {
|
|
12
12
|
console.warn(
|
|
13
|
-
|
|
13
|
+
'Placing %sveltekit.body% directly inside <body> is not recommended, as your app may break for users who have certain browser extensions installed.\n\nConsider wrapping it in an element:\n\n<div style="display: contents">\n %sveltekit.body%\n</div>'
|
|
14
14
|
);
|
|
15
15
|
}
|
|
16
16
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { applyAction } from '
|
|
1
|
+
import { applyAction } from '../app/forms';
|
|
2
2
|
import {
|
|
3
3
|
afterNavigate,
|
|
4
4
|
beforeNavigate,
|
|
@@ -7,18 +7,10 @@ import {
|
|
|
7
7
|
invalidateAll,
|
|
8
8
|
preloadCode,
|
|
9
9
|
preloadData
|
|
10
|
-
} from '
|
|
10
|
+
} from '../app/navigation';
|
|
11
11
|
import { SvelteComponent } from 'svelte';
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
CSRPageNode,
|
|
15
|
-
CSRPageNodeLoader,
|
|
16
|
-
CSRRoute,
|
|
17
|
-
Page,
|
|
18
|
-
ParamMatcher,
|
|
19
|
-
TrailingSlash,
|
|
20
|
-
Uses
|
|
21
|
-
} from 'types';
|
|
12
|
+
import { ClientHooks, CSRPageNode, CSRPageNodeLoader, CSRRoute, TrailingSlash, Uses } from 'types';
|
|
13
|
+
import { Page, ParamMatcher } from '@sveltejs/kit';
|
|
22
14
|
|
|
23
15
|
export interface SvelteKitApp {
|
|
24
16
|
/**
|