@inertiajs/svelte 2.0.0-beta.1 → 2.0.0-beta.2
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/dist/components/App.svelte +36 -13
- package/dist/components/App.svelte.d.ts +12 -1
- package/dist/components/Deferred.svelte +11 -1
- package/dist/components/Link.svelte.d.ts +5 -5
- package/dist/components/Render.svelte.d.ts +1 -1
- package/dist/components/WhenVisible.svelte +2 -2
- package/dist/components/WhenVisible.svelte.d.ts +1 -1
- package/dist/createInertiaApp.d.ts +16 -9
- package/dist/createInertiaApp.js +12 -53
- package/dist/link.js +0 -7
- package/dist/page.d.ts +12 -2
- package/dist/page.js +5 -4
- package/dist/usePrefetch.js +8 -4
- package/package.json +2 -2
- package/dist/store.d.ts +0 -9
- package/dist/store.js +0 -7
|
@@ -1,25 +1,48 @@
|
|
|
1
|
-
<script>import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
<script context="module">import {} from "@inertiajs/core";
|
|
2
|
+
</script>
|
|
3
|
+
|
|
4
|
+
<script>import { router } from "@inertiajs/core";
|
|
5
|
+
import Render, { h } from "./Render.svelte";
|
|
6
|
+
import { setPage } from "../page";
|
|
7
|
+
export let initialComponent;
|
|
8
|
+
export let initialPage;
|
|
9
|
+
export let resolveComponent;
|
|
10
|
+
let component = initialComponent;
|
|
11
|
+
let key = null;
|
|
12
|
+
let page = initialPage;
|
|
13
|
+
let renderProps = resolveRenderProps(component, page, key);
|
|
14
|
+
setPage(page);
|
|
15
|
+
const isServer = typeof window === "undefined";
|
|
16
|
+
if (!isServer) {
|
|
17
|
+
router.init({
|
|
18
|
+
initialPage,
|
|
19
|
+
resolveComponent,
|
|
20
|
+
swapComponent: async (args) => {
|
|
21
|
+
component = args.component;
|
|
22
|
+
page = args.page;
|
|
23
|
+
key = args.preserveState ? key : Date.now();
|
|
24
|
+
renderProps = resolveRenderProps(component, page, key);
|
|
25
|
+
setPage(page);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
function resolveRenderProps(component2, page2, key2 = null) {
|
|
30
|
+
const child = h(component2.default, page2.props, [], key2);
|
|
31
|
+
const layout = component2.layout;
|
|
32
|
+
return layout ? resolveLayout(layout, child, page2.props, key2) : child;
|
|
8
33
|
}
|
|
9
|
-
function resolveLayout(layout, child, pageProps,
|
|
34
|
+
function resolveLayout(layout, child, pageProps, key2) {
|
|
10
35
|
if (isLayoutFunction(layout)) {
|
|
11
36
|
return layout(h, child);
|
|
12
37
|
}
|
|
13
38
|
if (Array.isArray(layout)) {
|
|
14
|
-
return layout.slice().reverse().reduce((currentRender, layoutComponent) => h(layoutComponent, pageProps, [currentRender],
|
|
39
|
+
return layout.slice().reverse().reduce((currentRender, layoutComponent) => h(layoutComponent, pageProps, [currentRender], key2), child);
|
|
15
40
|
}
|
|
16
|
-
return h(layout, pageProps, child ? [child] : [],
|
|
41
|
+
return h(layout, pageProps, child ? [child] : [], key2);
|
|
17
42
|
}
|
|
18
43
|
function isLayoutFunction(layout) {
|
|
19
44
|
return typeof layout === "function" && layout.length === 2 && typeof layout.prototype === "undefined";
|
|
20
45
|
}
|
|
21
46
|
</script>
|
|
22
47
|
|
|
23
|
-
{
|
|
24
|
-
<Render {...props} />
|
|
25
|
-
{/if}
|
|
48
|
+
<Render {...renderProps} />
|
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { ComponentResolver, ResolvedComponent } from '../types';
|
|
3
|
+
import { type Page } from '@inertiajs/core';
|
|
4
|
+
export interface InertiaAppProps {
|
|
5
|
+
initialComponent: ResolvedComponent;
|
|
6
|
+
initialPage: Page;
|
|
7
|
+
resolveComponent: ComponentResolver;
|
|
8
|
+
}
|
|
2
9
|
declare const __propDef: {
|
|
3
|
-
props:
|
|
10
|
+
props: {
|
|
11
|
+
initialComponent: InertiaAppProps["initialComponent"];
|
|
12
|
+
initialPage: InertiaAppProps["initialPage"];
|
|
13
|
+
resolveComponent: InertiaAppProps["resolveComponent"];
|
|
14
|
+
};
|
|
4
15
|
events: {
|
|
5
16
|
[evt: string]: CustomEvent<any>;
|
|
6
17
|
};
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
<script>import { page } from "../index";
|
|
2
|
+
import { onDestroy } from "svelte";
|
|
2
3
|
export let data;
|
|
3
4
|
const keys = Array.isArray(data) ? data : [data];
|
|
5
|
+
let loaded = false;
|
|
6
|
+
const unsubscribe = page.subscribe(({ props }) => {
|
|
7
|
+
window.queueMicrotask(() => {
|
|
8
|
+
loaded = keys.every((key) => typeof props[key] !== "undefined");
|
|
9
|
+
});
|
|
10
|
+
});
|
|
11
|
+
onDestroy(() => {
|
|
12
|
+
unsubscribe();
|
|
13
|
+
});
|
|
4
14
|
if (!$$slots.fallback) {
|
|
5
15
|
throw new Error('`<Deferred>` requires a `<svelte:fragment slot="fallback">` slot');
|
|
6
16
|
}
|
|
7
17
|
</script>
|
|
8
18
|
|
|
9
|
-
{#if
|
|
19
|
+
{#if loaded}
|
|
10
20
|
<slot />
|
|
11
21
|
{:else}
|
|
12
22
|
<slot name="fallback" />
|
|
@@ -28,13 +28,13 @@ declare const __propDef: {
|
|
|
28
28
|
mouseout: MouseEvent;
|
|
29
29
|
mouseover: MouseEvent;
|
|
30
30
|
mouseup: MouseEvent;
|
|
31
|
-
'cancel-token':
|
|
32
|
-
before:
|
|
33
|
-
start:
|
|
31
|
+
'cancel-token': Event | FocusEvent | UIEvent | MouseEvent | ProgressEvent<EventTarget> | AnimationEvent | InputEvent | CompositionEvent | ClipboardEvent | DragEvent | ErrorEvent | FormDataEvent | PointerEvent | KeyboardEvent | SecurityPolicyViolationEvent | SubmitEvent | TouchEvent | TransitionEvent | WheelEvent;
|
|
32
|
+
before: Event | FocusEvent | UIEvent | MouseEvent | ProgressEvent<EventTarget> | AnimationEvent | InputEvent | CompositionEvent | ClipboardEvent | DragEvent | ErrorEvent | FormDataEvent | PointerEvent | KeyboardEvent | SecurityPolicyViolationEvent | SubmitEvent | TouchEvent | TransitionEvent | WheelEvent;
|
|
33
|
+
start: Event | FocusEvent | UIEvent | MouseEvent | ProgressEvent<EventTarget> | AnimationEvent | InputEvent | CompositionEvent | ClipboardEvent | DragEvent | ErrorEvent | FormDataEvent | PointerEvent | KeyboardEvent | SecurityPolicyViolationEvent | SubmitEvent | TouchEvent | TransitionEvent | WheelEvent;
|
|
34
34
|
progress: ProgressEvent<EventTarget>;
|
|
35
|
-
finish:
|
|
35
|
+
finish: Event | FocusEvent | UIEvent | MouseEvent | ProgressEvent<EventTarget> | AnimationEvent | InputEvent | CompositionEvent | ClipboardEvent | DragEvent | ErrorEvent | FormDataEvent | PointerEvent | KeyboardEvent | SecurityPolicyViolationEvent | SubmitEvent | TouchEvent | TransitionEvent | WheelEvent;
|
|
36
36
|
cancel: Event;
|
|
37
|
-
success:
|
|
37
|
+
success: Event | FocusEvent | UIEvent | MouseEvent | ProgressEvent<EventTarget> | AnimationEvent | InputEvent | CompositionEvent | ClipboardEvent | DragEvent | ErrorEvent | FormDataEvent | PointerEvent | KeyboardEvent | SecurityPolicyViolationEvent | SubmitEvent | TouchEvent | TransitionEvent | WheelEvent;
|
|
38
38
|
error: ErrorEvent;
|
|
39
39
|
} & {
|
|
40
40
|
[evt: string]: CustomEvent<any>;
|
|
@@ -6,7 +6,7 @@ export type RenderProps = {
|
|
|
6
6
|
props?: PageProps;
|
|
7
7
|
children?: RenderProps[];
|
|
8
8
|
key?: number | null;
|
|
9
|
-
}
|
|
9
|
+
};
|
|
10
10
|
export type RenderFunction = {
|
|
11
11
|
(component: ComponentType, props?: PageProps, children?: RenderProps[], key?: number | null): RenderProps;
|
|
12
12
|
(component: ComponentType, children?: RenderProps[], key?: number | null): RenderProps;
|
|
@@ -3,7 +3,7 @@ import { onDestroy, onMount } from "svelte";
|
|
|
3
3
|
export let data = "";
|
|
4
4
|
export let params = {};
|
|
5
5
|
export let buffer = 0;
|
|
6
|
-
export let
|
|
6
|
+
export let as = "div";
|
|
7
7
|
export let always = false;
|
|
8
8
|
let loaded = false;
|
|
9
9
|
let fetching = false;
|
|
@@ -62,7 +62,7 @@ function getReloadParams() {
|
|
|
62
62
|
</script>
|
|
63
63
|
|
|
64
64
|
{#if always || !loaded}
|
|
65
|
-
<svelte:element this={
|
|
65
|
+
<svelte:element this={as} bind:this={el} />
|
|
66
66
|
{/if}
|
|
67
67
|
|
|
68
68
|
{#if loaded}
|
|
@@ -1,18 +1,25 @@
|
|
|
1
1
|
import { type InertiaAppResponse, type Page } from '@inertiajs/core';
|
|
2
2
|
import type { ComponentType } from 'svelte';
|
|
3
|
-
import App from './components/App.svelte';
|
|
3
|
+
import App, { type InertiaAppProps } from './components/App.svelte';
|
|
4
4
|
import type { ComponentResolver } from './types';
|
|
5
|
+
type SvelteRenderResult = {
|
|
6
|
+
html: string;
|
|
7
|
+
head: string;
|
|
8
|
+
css?: {
|
|
9
|
+
code: string;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
type AppComponent = ComponentType<App> & {
|
|
13
|
+
render: (props: InertiaAppProps) => SvelteRenderResult;
|
|
14
|
+
};
|
|
5
15
|
interface CreateInertiaAppProps {
|
|
6
16
|
id?: string;
|
|
7
17
|
resolve: ComponentResolver;
|
|
8
|
-
setup
|
|
9
|
-
el: HTMLElement;
|
|
10
|
-
App:
|
|
11
|
-
props:
|
|
12
|
-
|
|
13
|
-
resolveComponent: ComponentResolver;
|
|
14
|
-
};
|
|
15
|
-
}) => void | App;
|
|
18
|
+
setup: (props: {
|
|
19
|
+
el: HTMLElement | null;
|
|
20
|
+
App: AppComponent;
|
|
21
|
+
props: InertiaAppProps;
|
|
22
|
+
}) => void | App | SvelteRenderResult;
|
|
16
23
|
progress?: false | {
|
|
17
24
|
delay?: number;
|
|
18
25
|
color?: string;
|
package/dist/createInertiaApp.js
CHANGED
|
@@ -1,70 +1,29 @@
|
|
|
1
1
|
import { router, setupProgress } from '@inertiajs/core';
|
|
2
2
|
import escape from 'html-escape';
|
|
3
|
-
import {
|
|
4
|
-
import App from './components/App.svelte';
|
|
5
|
-
import store from './store';
|
|
3
|
+
import App, {} from './components/App.svelte';
|
|
6
4
|
export default async function createInertiaApp({ id = 'app', resolve, setup, progress = {}, page, }) {
|
|
7
5
|
const isServer = typeof window === 'undefined';
|
|
8
6
|
const el = isServer ? null : document.getElementById(id);
|
|
9
|
-
const initialPage = page || JSON.parse(el?.dataset
|
|
7
|
+
const initialPage = page || JSON.parse(el?.dataset.page || '{}');
|
|
10
8
|
const resolveComponent = (name) => Promise.resolve(resolve(name));
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
const [initialComponent] = await Promise.all([
|
|
10
|
+
resolveComponent(initialPage.component),
|
|
11
|
+
router.decryptHistory().catch(() => { }),
|
|
12
|
+
]);
|
|
13
|
+
const props = { initialPage, initialComponent, resolveComponent };
|
|
14
|
+
const svelteApp = setup({
|
|
15
|
+
el,
|
|
16
|
+
App: App,
|
|
17
|
+
props
|
|
17
18
|
});
|
|
18
19
|
if (isServer) {
|
|
19
|
-
const
|
|
20
|
-
const { html, head, css } = await (async () => {
|
|
21
|
-
if (isSvelte5) {
|
|
22
|
-
const { render } = await dynamicImport('svelte/server');
|
|
23
|
-
if (typeof render === 'function') {
|
|
24
|
-
return render(App);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
return App.render();
|
|
28
|
-
})();
|
|
20
|
+
const { html, head, css } = svelteApp;
|
|
29
21
|
return {
|
|
30
22
|
body: `<div data-server-rendered="true" id="${id}" data-page="${escape(JSON.stringify(initialPage))}">${html}</div>`,
|
|
31
23
|
head: [head, css ? `<style data-vite-css>${css.code}</style>` : ''],
|
|
32
24
|
};
|
|
33
25
|
}
|
|
34
|
-
if (!el) {
|
|
35
|
-
throw new Error(`Element with ID "${id}" not found.`);
|
|
36
|
-
}
|
|
37
|
-
router.init({
|
|
38
|
-
initialPage,
|
|
39
|
-
resolveComponent,
|
|
40
|
-
swapComponent: async ({ component, page, preserveState }) => {
|
|
41
|
-
store.update((current) => ({
|
|
42
|
-
component: component,
|
|
43
|
-
page,
|
|
44
|
-
key: preserveState ? current.key : Date.now(),
|
|
45
|
-
}));
|
|
46
|
-
},
|
|
47
|
-
});
|
|
48
26
|
if (progress) {
|
|
49
27
|
setupProgress(progress);
|
|
50
28
|
}
|
|
51
|
-
setup({
|
|
52
|
-
el,
|
|
53
|
-
App,
|
|
54
|
-
props: {
|
|
55
|
-
initialPage,
|
|
56
|
-
resolveComponent,
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
// Loads the module dynamically during execution instead of at
|
|
61
|
-
// build time. The `@vite-ignore` flag prevents Vite from
|
|
62
|
-
// analyzing or pre-bundling this import.
|
|
63
|
-
async function dynamicImport(module) {
|
|
64
|
-
try {
|
|
65
|
-
return await import(/* @vite-ignore */ module);
|
|
66
|
-
}
|
|
67
|
-
catch {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
70
29
|
}
|
package/dist/link.js
CHANGED
|
@@ -2,7 +2,6 @@ import { mergeDataIntoQueryString, router, shouldIntercept, } from '@inertiajs/c
|
|
|
2
2
|
function link(node, initialParams = {}) {
|
|
3
3
|
let inFlightCount = 0;
|
|
4
4
|
let hoverTimeout;
|
|
5
|
-
// Variables initialized and controlled by the "update" function
|
|
6
5
|
let prefetchModes = [];
|
|
7
6
|
let cacheForValue;
|
|
8
7
|
let method;
|
|
@@ -36,7 +35,6 @@ function link(node, initialParams = {}) {
|
|
|
36
35
|
},
|
|
37
36
|
click: (event) => {
|
|
38
37
|
if (shouldIntercept(event)) {
|
|
39
|
-
// Let the mouseup event handle the visit
|
|
40
38
|
event.preventDefault();
|
|
41
39
|
}
|
|
42
40
|
},
|
|
@@ -53,15 +51,11 @@ function link(node, initialParams = {}) {
|
|
|
53
51
|
})();
|
|
54
52
|
cacheForValue = (() => {
|
|
55
53
|
if (cacheFor !== 0) {
|
|
56
|
-
// If they've provided a value, respect it
|
|
57
54
|
return cacheFor;
|
|
58
55
|
}
|
|
59
56
|
if (prefetchModes.length === 1 && prefetchModes[0] === 'click') {
|
|
60
|
-
// If they've only provided a prefetch mode of 'click',
|
|
61
|
-
// we should only prefetch for the next request but not keep it around
|
|
62
57
|
return 0;
|
|
63
58
|
}
|
|
64
|
-
// Otherwise, default to 30 seconds
|
|
65
59
|
return 30_000;
|
|
66
60
|
})();
|
|
67
61
|
method = (params.method?.toLowerCase() || 'get');
|
|
@@ -147,7 +141,6 @@ function link(node, initialParams = {}) {
|
|
|
147
141
|
removeEventListeners();
|
|
148
142
|
}
|
|
149
143
|
update(initialParams);
|
|
150
|
-
// TODO: Confirm is this needs to rerun when "prefetchModes" changes
|
|
151
144
|
if (prefetchModes.includes('mount')) {
|
|
152
145
|
prefetch();
|
|
153
146
|
}
|
package/dist/page.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import { type Page } from '@inertiajs/core';
|
|
2
|
+
export declare const setPage: {
|
|
3
|
+
(this: void, value: Page<import("@inertiajs/core").PageProps>): void;
|
|
4
|
+
(this: void, value: Page<import("@inertiajs/core").PageProps>): void;
|
|
5
|
+
};
|
|
6
|
+
declare const _default: {
|
|
7
|
+
subscribe: {
|
|
8
|
+
(this: void, run: import("svelte/store").Subscriber<Page<import("@inertiajs/core").PageProps>>, invalidate?: import("svelte/store").Invalidator<Page<import("@inertiajs/core").PageProps>> | undefined): import("svelte/store").Unsubscriber;
|
|
9
|
+
(this: void, run: import("svelte/store").Subscriber<Page<import("@inertiajs/core").PageProps>>, invalidate?: import("svelte/store").Invalidator<Page<import("@inertiajs/core").PageProps>> | undefined): import("svelte/store").Unsubscriber;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export default _default;
|
package/dist/page.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
const
|
|
4
|
-
export
|
|
1
|
+
import {} from '@inertiajs/core';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
const { set, subscribe } = writable();
|
|
4
|
+
export const setPage = set;
|
|
5
|
+
export default { subscribe };
|
package/dist/usePrefetch.js
CHANGED
|
@@ -5,8 +5,8 @@ export default function usePrefetch(options = {}) {
|
|
|
5
5
|
const isPrefetched = writable(false);
|
|
6
6
|
const isPrefetching = writable(false);
|
|
7
7
|
const lastUpdatedAt = writable(null);
|
|
8
|
-
const cached = router.getCached(window.location.pathname, options);
|
|
9
|
-
const inFlight = router.getPrefetching(window.location.pathname, options);
|
|
8
|
+
const cached = typeof window === 'undefined' ? null : router.getCached(window.location.pathname, options);
|
|
9
|
+
const inFlight = typeof window === 'undefined' ? null : router.getPrefetching(window.location.pathname, options);
|
|
10
10
|
isPrefetched.set(cached !== null);
|
|
11
11
|
isPrefetching.set(inFlight !== null);
|
|
12
12
|
lastUpdatedAt.set(cached?.staleTimestamp || null);
|
|
@@ -26,8 +26,12 @@ export default function usePrefetch(options = {}) {
|
|
|
26
26
|
});
|
|
27
27
|
});
|
|
28
28
|
onDestroy(() => {
|
|
29
|
-
removePrefetchedListener
|
|
30
|
-
|
|
29
|
+
if (removePrefetchedListener) {
|
|
30
|
+
removePrefetchedListener();
|
|
31
|
+
}
|
|
32
|
+
if (removePrefetchingListener) {
|
|
33
|
+
removePrefetchingListener();
|
|
34
|
+
}
|
|
31
35
|
});
|
|
32
36
|
return {
|
|
33
37
|
isPrefetched: readonly(isPrefetched),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inertiajs/svelte",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.2",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The Svelte adapter for Inertia.js",
|
|
6
6
|
"contributors": [
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"svelte": "^4.0.0 || ^5.0.0 || ^5.0.0-next.244"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@inertiajs/core": "2.0.0-beta.
|
|
46
|
+
"@inertiajs/core": "2.0.0-beta.2",
|
|
47
47
|
"html-escape": "^2.0.0",
|
|
48
48
|
"lodash": "^4.5.0"
|
|
49
49
|
},
|
package/dist/store.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Page } from '@inertiajs/core';
|
|
2
|
-
import type { ResolvedComponent } from './types';
|
|
3
|
-
export interface InertiaStore {
|
|
4
|
-
component: ResolvedComponent;
|
|
5
|
-
page: Page;
|
|
6
|
-
key: number | null;
|
|
7
|
-
}
|
|
8
|
-
declare const store: import("svelte/store").Writable<InertiaStore>;
|
|
9
|
-
export default store;
|