@sveltejs/kit 1.0.0-next.576 → 1.0.0-next.577
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 +1 -1
- package/src/core/config/options.js +2 -0
- package/src/exports/vite/build/build_server.js +1 -0
- package/src/exports/vite/build/utils.js +2 -1
- package/src/exports/vite/dev/index.js +1 -0
- package/src/exports/vite/index.js +2 -1
- package/src/runtime/client/client.js +24 -9
- package/src/runtime/server/page/render.js +30 -13
- package/types/index.d.ts +5 -0
- package/types/internal.d.ts +2 -0
package/package.json
CHANGED
|
@@ -129,6 +129,8 @@ const options = object(
|
|
|
129
129
|
checkOrigin: boolean(true)
|
|
130
130
|
}),
|
|
131
131
|
|
|
132
|
+
embedded: boolean(false),
|
|
133
|
+
|
|
132
134
|
// TODO: remove this for the 1.0 release
|
|
133
135
|
endpointExtensions: error(
|
|
134
136
|
(keypath) => `${keypath} has been renamed to config.kit.moduleExtensions`
|
|
@@ -147,7 +147,8 @@ export function get_default_build_config({ config, input, ssr, outDir }) {
|
|
|
147
147
|
__SVELTEKIT_APP_VERSION_FILE__: JSON.stringify(`${config.kit.appDir}/version.json`),
|
|
148
148
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: JSON.stringify(config.kit.version.pollInterval),
|
|
149
149
|
__SVELTEKIT_BROWSER__: ssr ? 'false' : 'true',
|
|
150
|
-
__SVELTEKIT_DEV__: 'false'
|
|
150
|
+
__SVELTEKIT_DEV__: 'false',
|
|
151
|
+
__SVELTEKIT_EMBEDDED__: config.kit.embedded ? 'true' : 'false'
|
|
151
152
|
},
|
|
152
153
|
publicDir: ssr ? false : config.kit.files.assets,
|
|
153
154
|
resolve: {
|
|
@@ -449,6 +449,7 @@ export async function dev(vite, vite_config, svelte_config) {
|
|
|
449
449
|
check_origin: svelte_config.kit.csrf.checkOrigin
|
|
450
450
|
},
|
|
451
451
|
dev: true,
|
|
452
|
+
embedded: svelte_config.kit.embedded,
|
|
452
453
|
handle_error: async (error, event) => {
|
|
453
454
|
const error_object = await hooks.handleError({
|
|
454
455
|
error: new Proxy(error, {
|
|
@@ -262,7 +262,8 @@ function kit({ svelte_config }) {
|
|
|
262
262
|
define: {
|
|
263
263
|
__SVELTEKIT_APP_VERSION_POLL_INTERVAL__: '0',
|
|
264
264
|
__SVELTEKIT_BROWSER__: config_env.ssrBuild ? 'false' : 'true',
|
|
265
|
-
__SVELTEKIT_DEV__: 'true'
|
|
265
|
+
__SVELTEKIT_DEV__: 'true',
|
|
266
|
+
__SVELTEKIT_EMBEDDED__: svelte_config.kit.embedded ? 'true' : 'false'
|
|
266
267
|
},
|
|
267
268
|
publicDir: svelte_config.kit.files.assets,
|
|
268
269
|
resolve: {
|
|
@@ -89,6 +89,7 @@ function check_for_removed_attributes() {
|
|
|
89
89
|
* @returns {import('./types').Client}
|
|
90
90
|
*/
|
|
91
91
|
export function create_client({ target, base }) {
|
|
92
|
+
const container = __SVELTEKIT_EMBEDDED__ ? target : document.documentElement;
|
|
92
93
|
/** @type {Array<((url: URL) => boolean)>} */
|
|
93
94
|
const invalidated = [];
|
|
94
95
|
|
|
@@ -1199,7 +1200,7 @@ export function create_client({ target, base }) {
|
|
|
1199
1200
|
/** @type {NodeJS.Timeout} */
|
|
1200
1201
|
let mousemove_timeout;
|
|
1201
1202
|
|
|
1202
|
-
|
|
1203
|
+
container.addEventListener('mousemove', (event) => {
|
|
1203
1204
|
const target = /** @type {Element} */ (event.target);
|
|
1204
1205
|
|
|
1205
1206
|
clearTimeout(mousemove_timeout);
|
|
@@ -1213,8 +1214,8 @@ export function create_client({ target, base }) {
|
|
|
1213
1214
|
preload(/** @type {Element} */ (event.composedPath()[0]), 1);
|
|
1214
1215
|
}
|
|
1215
1216
|
|
|
1216
|
-
|
|
1217
|
-
|
|
1217
|
+
container.addEventListener('mousedown', tap);
|
|
1218
|
+
container.addEventListener('touchstart', tap, { passive: true });
|
|
1218
1219
|
|
|
1219
1220
|
const observer = new IntersectionObserver(
|
|
1220
1221
|
(entries) => {
|
|
@@ -1233,7 +1234,7 @@ export function create_client({ target, base }) {
|
|
|
1233
1234
|
* @param {number} priority
|
|
1234
1235
|
*/
|
|
1235
1236
|
function preload(element, priority) {
|
|
1236
|
-
const a = find_anchor(element,
|
|
1237
|
+
const a = find_anchor(element, container);
|
|
1237
1238
|
if (!a) return;
|
|
1238
1239
|
|
|
1239
1240
|
const { url, external } = get_link_info(a, base);
|
|
@@ -1253,7 +1254,7 @@ export function create_client({ target, base }) {
|
|
|
1253
1254
|
function after_navigate() {
|
|
1254
1255
|
observer.disconnect();
|
|
1255
1256
|
|
|
1256
|
-
for (const a of
|
|
1257
|
+
for (const a of container.querySelectorAll('a')) {
|
|
1257
1258
|
const { url, external } = get_link_info(a, base);
|
|
1258
1259
|
if (external) continue;
|
|
1259
1260
|
|
|
@@ -1457,14 +1458,14 @@ export function create_client({ target, base }) {
|
|
|
1457
1458
|
}
|
|
1458
1459
|
|
|
1459
1460
|
/** @param {MouseEvent} event */
|
|
1460
|
-
|
|
1461
|
+
container.addEventListener('click', (event) => {
|
|
1461
1462
|
// Adapted from https://github.com/visionmedia/page.js
|
|
1462
1463
|
// MIT license https://github.com/visionmedia/page.js#license
|
|
1463
1464
|
if (event.button || event.which !== 1) return;
|
|
1464
1465
|
if (event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
|
|
1465
1466
|
if (event.defaultPrevented) return;
|
|
1466
1467
|
|
|
1467
|
-
const a = find_anchor(/** @type {Element} */ (event.composedPath()[0]),
|
|
1468
|
+
const a = find_anchor(/** @type {Element} */ (event.composedPath()[0]), container);
|
|
1468
1469
|
if (!a) return;
|
|
1469
1470
|
|
|
1470
1471
|
const { url, external, has } = get_link_info(a, base);
|
|
@@ -1534,7 +1535,7 @@ export function create_client({ target, base }) {
|
|
|
1534
1535
|
});
|
|
1535
1536
|
});
|
|
1536
1537
|
|
|
1537
|
-
|
|
1538
|
+
container.addEventListener('submit', (event) => {
|
|
1538
1539
|
if (event.defaultPrevented) return;
|
|
1539
1540
|
|
|
1540
1541
|
const form = /** @type {HTMLFormElement} */ (
|
|
@@ -1639,11 +1640,25 @@ export function create_client({ target, base }) {
|
|
|
1639
1640
|
});
|
|
1640
1641
|
},
|
|
1641
1642
|
|
|
1642
|
-
_hydrate: async ({
|
|
1643
|
+
_hydrate: async ({
|
|
1644
|
+
status = 200,
|
|
1645
|
+
error,
|
|
1646
|
+
node_ids,
|
|
1647
|
+
params,
|
|
1648
|
+
route,
|
|
1649
|
+
data: server_data_nodes,
|
|
1650
|
+
form
|
|
1651
|
+
}) => {
|
|
1643
1652
|
hydrated = true;
|
|
1644
1653
|
|
|
1645
1654
|
const url = new URL(location.href);
|
|
1646
1655
|
|
|
1656
|
+
if (!__SVELTEKIT_EMBEDDED__) {
|
|
1657
|
+
// See https://github.com/sveltejs/kit/pull/4935#issuecomment-1328093358 for one motivation
|
|
1658
|
+
// of determining the params on the client side.
|
|
1659
|
+
({ params = {}, route = { id: null } } = get_navigation_intent(url, false) || {});
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1647
1662
|
/** @type {import('./types').NavigationFinished | undefined} */
|
|
1648
1663
|
let result;
|
|
1649
1664
|
|
|
@@ -266,24 +266,41 @@ export async function render_response({
|
|
|
266
266
|
}
|
|
267
267
|
|
|
268
268
|
if (page_config.csr) {
|
|
269
|
+
const opts = [
|
|
270
|
+
`env: ${s(options.public_env)}`,
|
|
271
|
+
`paths: ${s(options.paths)}`,
|
|
272
|
+
`target: document.querySelector('[data-sveltekit-hydrate="${target}"]').parentNode`,
|
|
273
|
+
`version: ${s(options.version)}`
|
|
274
|
+
];
|
|
275
|
+
|
|
276
|
+
if (page_config.ssr) {
|
|
277
|
+
const hydrate = [
|
|
278
|
+
`node_ids: [${branch.map(({ node }) => node.index).join(', ')}]`,
|
|
279
|
+
`data: ${serialized.data}`,
|
|
280
|
+
`form: ${serialized.form}`
|
|
281
|
+
];
|
|
282
|
+
|
|
283
|
+
if (status !== 200) {
|
|
284
|
+
hydrate.push(`status: ${status}`);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
if (error) {
|
|
288
|
+
hydrate.push(`error: ${devalue.uneval(error)}`);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (options.embedded) {
|
|
292
|
+
hydrate.push(`params: ${devalue.uneval(event.params)}`, `route: ${s(event.route)}`);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
opts.push(`hydrate: {\n\t\t\t\t\t${hydrate.join(',\n\t\t\t\t\t')}\n\t\t\t\t}`);
|
|
296
|
+
}
|
|
297
|
+
|
|
269
298
|
// prettier-ignore
|
|
270
299
|
const init_app = `
|
|
271
300
|
import { start } from ${s(prefixed(entry.file))};
|
|
272
301
|
|
|
273
302
|
start({
|
|
274
|
-
|
|
275
|
-
hydrate: ${page_config.ssr ? `{
|
|
276
|
-
status: ${status},
|
|
277
|
-
error: ${devalue.uneval(error)},
|
|
278
|
-
node_ids: [${branch.map(({ node }) => node.index).join(', ')}],
|
|
279
|
-
params: ${devalue.uneval(event.params)},
|
|
280
|
-
route: ${s(event.route)},
|
|
281
|
-
data: ${serialized.data},
|
|
282
|
-
form: ${serialized.form}
|
|
283
|
-
}` : 'null'},
|
|
284
|
-
paths: ${s(options.paths)},
|
|
285
|
-
target: document.querySelector('[data-sveltekit-hydrate="${target}"]').parentNode,
|
|
286
|
-
version: ${s(options.version)}
|
|
303
|
+
${opts.join(',\n\t\t\t\t')}
|
|
287
304
|
});
|
|
288
305
|
`;
|
|
289
306
|
|
package/types/index.d.ts
CHANGED
|
@@ -325,6 +325,11 @@ export interface KitConfig {
|
|
|
325
325
|
*/
|
|
326
326
|
checkOrigin?: boolean;
|
|
327
327
|
};
|
|
328
|
+
/**
|
|
329
|
+
* Whether or not the app is embedded inside a larger app. If `true`, SvelteKit will add its event listeners related to navigation etc on the parent of `%sveltekit.body%` instead of `window`, and will pass `params` from the server rather than inferring them from `location.pathname`.
|
|
330
|
+
* @default false
|
|
331
|
+
*/
|
|
332
|
+
embedded?: boolean;
|
|
328
333
|
/**
|
|
329
334
|
* Environment variable configuration
|
|
330
335
|
*/
|
package/types/internal.d.ts
CHANGED
|
@@ -299,6 +299,7 @@ export interface SSROptions {
|
|
|
299
299
|
check_origin: boolean;
|
|
300
300
|
};
|
|
301
301
|
dev: boolean;
|
|
302
|
+
embedded: boolean;
|
|
302
303
|
handle_error(error: Error & { frame?: string }, event: RequestEvent): MaybePromise<App.Error>;
|
|
303
304
|
hooks: ServerHooks;
|
|
304
305
|
manifest: SSRManifest;
|
|
@@ -387,4 +388,5 @@ declare global {
|
|
|
387
388
|
const __SVELTEKIT_APP_VERSION_POLL_INTERVAL__: number;
|
|
388
389
|
const __SVELTEKIT_BROWSER__: boolean;
|
|
389
390
|
const __SVELTEKIT_DEV__: boolean;
|
|
391
|
+
const __SVELTEKIT_EMBEDDED__: boolean;
|
|
390
392
|
}
|