@inertiajs/svelte 2.3.17 → 3.0.0-beta.1
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 +120 -44
- package/dist/components/App.svelte.d.ts +10 -19
- package/dist/components/Deferred.svelte +68 -9
- package/dist/components/Deferred.svelte.d.ts +9 -20
- package/dist/components/Form.svelte +358 -242
- package/dist/components/Form.svelte.d.ts +51 -96
- package/dist/components/InfiniteScroll.svelte +227 -167
- package/dist/components/InfiniteScroll.svelte.d.ts +29 -116
- package/dist/components/Link.svelte +96 -48
- package/dist/components/Link.svelte.d.ts +49 -56
- package/dist/components/Render.svelte +62 -21
- package/dist/components/Render.svelte.d.ts +9 -25
- package/dist/components/WhenVisible.svelte +83 -66
- package/dist/components/WhenVisible.svelte.d.ts +11 -26
- package/dist/components/createForm.d.ts +8 -0
- package/dist/components/createForm.js +4 -0
- package/dist/components/formContext.d.ts +3 -3
- package/dist/components/formContext.js +9 -3
- package/dist/createInertiaApp.d.ts +12 -7
- package/dist/createInertiaApp.js +63 -24
- package/dist/index.d.ts +8 -5
- package/dist/index.js +8 -5
- package/dist/layoutProps.svelte.d.ts +6 -0
- package/dist/layoutProps.svelte.js +25 -0
- package/dist/link.js +13 -2
- package/dist/page.svelte.d.ts +10 -0
- package/dist/page.svelte.js +14 -0
- package/dist/types.d.ts +11 -4
- package/dist/types.js +1 -1
- package/dist/{useForm.d.ts → useForm.svelte.d.ts} +4 -4
- package/dist/useForm.svelte.js +116 -0
- package/dist/useFormState.svelte.d.ts +84 -0
- package/dist/useFormState.svelte.js +290 -0
- package/dist/useHttp.svelte.d.ts +61 -0
- package/dist/useHttp.svelte.js +154 -0
- package/dist/usePrefetch.svelte.d.ts +7 -0
- package/dist/{usePrefetch.js → usePrefetch.svelte.js} +18 -13
- package/dist/useRemember.svelte.d.ts +1 -0
- package/dist/useRemember.svelte.js +10 -0
- package/package.json +11 -11
- package/dist/page.d.ts +0 -13
- package/dist/page.js +0 -8
- package/dist/useForm.js +0 -356
- package/dist/usePrefetch.d.ts +0 -7
- package/dist/useRemember.d.ts +0 -1
- package/dist/useRemember.js +0 -11
|
@@ -1,76 +1,93 @@
|
|
|
1
|
-
<script
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
observer =
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
fetching = true;
|
|
33
|
-
const reloadParams = getReloadParams();
|
|
34
|
-
router.reload({
|
|
35
|
-
...reloadParams,
|
|
36
|
-
onStart: (event) => {
|
|
37
|
-
fetching = true;
|
|
38
|
-
reloadParams.onStart?.(event);
|
|
39
|
-
},
|
|
40
|
-
onFinish: (event) => {
|
|
41
|
-
loaded = true;
|
|
42
|
-
fetching = false;
|
|
43
|
-
reloadParams.onFinish?.(event);
|
|
44
|
-
if (!always) {
|
|
45
|
-
observer?.disconnect();
|
|
46
|
-
}
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { router, type ReloadOptions } from '@inertiajs/core'
|
|
3
|
+
import { get } from 'lodash-es'
|
|
4
|
+
import { usePage } from '../page.svelte'
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
data?: string | string[]
|
|
8
|
+
params?: ReloadOptions
|
|
9
|
+
buffer?: number
|
|
10
|
+
as?: keyof HTMLElementTagNameMap
|
|
11
|
+
always?: boolean
|
|
12
|
+
children?: import('svelte').Snippet<[any]>
|
|
13
|
+
fallback?: import('svelte').Snippet
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let { data = '', params = {}, buffer = 0, as = 'div', always = false, children, fallback }: Props = $props()
|
|
17
|
+
|
|
18
|
+
let keys = $derived(data ? (Array.isArray(data) ? data : [data]) : [])
|
|
19
|
+
let loaded = $derived(keys.length > 0 && keys.every((key) => get(page.props, key) !== undefined))
|
|
20
|
+
let fetching = $state(false)
|
|
21
|
+
let observer: IntersectionObserver | null = null
|
|
22
|
+
|
|
23
|
+
const page = usePage()
|
|
24
|
+
|
|
25
|
+
function attachObserver(el: HTMLElement) {
|
|
26
|
+
observer = new IntersectionObserver(
|
|
27
|
+
(entries) => {
|
|
28
|
+
if (!entries[0].isIntersecting) {
|
|
29
|
+
return
|
|
47
30
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
31
|
+
|
|
32
|
+
if (fetching) {
|
|
33
|
+
return
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!always && loaded) {
|
|
37
|
+
return
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
fetching = true
|
|
41
|
+
|
|
42
|
+
const reloadParams = getReloadParams()
|
|
43
|
+
|
|
44
|
+
router.reload({
|
|
45
|
+
...reloadParams,
|
|
46
|
+
onStart: (event) => {
|
|
47
|
+
fetching = true
|
|
48
|
+
reloadParams.onStart?.(event)
|
|
49
|
+
},
|
|
50
|
+
onFinish: (event) => {
|
|
51
|
+
loaded = true
|
|
52
|
+
fetching = false
|
|
53
|
+
reloadParams.onFinish?.(event)
|
|
54
|
+
|
|
55
|
+
if (!always) {
|
|
56
|
+
observer?.disconnect()
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
})
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
rootMargin: `${buffer}px`,
|
|
63
|
+
},
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
observer.observe(el)
|
|
67
|
+
|
|
68
|
+
// Clean up will run like onDestroy
|
|
69
|
+
return () => {
|
|
70
|
+
observer?.disconnect()
|
|
52
71
|
}
|
|
53
|
-
);
|
|
54
|
-
observer.observe(el);
|
|
55
|
-
}
|
|
56
|
-
onDestroy(() => {
|
|
57
|
-
observer?.disconnect();
|
|
58
|
-
});
|
|
59
|
-
function getReloadParams() {
|
|
60
|
-
const reloadParams = { ...params };
|
|
61
|
-
if (data !== "") {
|
|
62
|
-
reloadParams.only = Array.isArray(data) ? data : [data];
|
|
63
72
|
}
|
|
64
|
-
|
|
65
|
-
|
|
73
|
+
|
|
74
|
+
function getReloadParams(): Partial<ReloadOptions> {
|
|
75
|
+
const reloadParams: Partial<ReloadOptions> = { preserveErrors: true, ...params }
|
|
76
|
+
|
|
77
|
+
if (data !== '') {
|
|
78
|
+
reloadParams.only = (Array.isArray(data) ? data : [data]) as string[]
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return reloadParams
|
|
82
|
+
}
|
|
66
83
|
</script>
|
|
67
84
|
|
|
68
85
|
{#if always || !loaded}
|
|
69
|
-
<svelte:element this={as}
|
|
86
|
+
<svelte:element this={as} {@attach attachObserver} />
|
|
70
87
|
{/if}
|
|
71
88
|
|
|
72
89
|
{#if loaded}
|
|
73
|
-
|
|
74
|
-
{:else if
|
|
75
|
-
|
|
90
|
+
{@render children?.({ fetching })}
|
|
91
|
+
{:else if fallback}
|
|
92
|
+
{@render fallback?.()}
|
|
76
93
|
{/if}
|
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
import { SvelteComponent } from "svelte";
|
|
2
1
|
import { type ReloadOptions } from '@inertiajs/core';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
events: {
|
|
12
|
-
[evt: string]: CustomEvent<any>;
|
|
13
|
-
};
|
|
14
|
-
slots: {
|
|
15
|
-
default: {
|
|
16
|
-
fetching: boolean;
|
|
17
|
-
};
|
|
18
|
-
fallback: {};
|
|
19
|
-
};
|
|
20
|
-
exports?: {} | undefined;
|
|
21
|
-
bindings?: string | undefined;
|
|
22
|
-
};
|
|
23
|
-
export type WhenVisibleProps = typeof __propDef.props;
|
|
24
|
-
export type WhenVisibleEvents = typeof __propDef.events;
|
|
25
|
-
export type WhenVisibleSlots = typeof __propDef.slots;
|
|
26
|
-
export default class WhenVisible extends SvelteComponent<WhenVisibleProps, WhenVisibleEvents, WhenVisibleSlots> {
|
|
2
|
+
interface Props {
|
|
3
|
+
data?: string | string[];
|
|
4
|
+
params?: ReloadOptions;
|
|
5
|
+
buffer?: number;
|
|
6
|
+
as?: keyof HTMLElementTagNameMap;
|
|
7
|
+
always?: boolean;
|
|
8
|
+
children?: import('svelte').Snippet<[any]>;
|
|
9
|
+
fallback?: import('svelte').Snippet;
|
|
27
10
|
}
|
|
28
|
-
|
|
11
|
+
declare const WhenVisible: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type WhenVisible = ReturnType<typeof WhenVisible>;
|
|
13
|
+
export default WhenVisible;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { FormComponentSlotProps } from '@inertiajs/core';
|
|
2
|
+
import type { Component, ComponentProps, Snippet } from 'svelte';
|
|
3
|
+
import Form from './Form.svelte';
|
|
4
|
+
type TypedFormComponent<TForm extends Record<string, any>> = Component<Omit<ComponentProps<typeof Form>, 'children'> & {
|
|
5
|
+
children?: Snippet<[FormComponentSlotProps<TForm>]>;
|
|
6
|
+
}>;
|
|
7
|
+
export declare function createForm<TForm extends Record<string, any> = Record<string, any>>(): TypedFormComponent<TForm>;
|
|
8
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { FormComponentRef } from '@inertiajs/core';
|
|
2
|
-
|
|
3
|
-
export declare
|
|
4
|
-
export
|
|
2
|
+
declare const setFormContext: (context: FormComponentRef) => FormComponentRef;
|
|
3
|
+
export declare function useFormContext<TForm extends object = Record<string, any>>(): FormComponentRef<TForm> | undefined;
|
|
4
|
+
export { setFormContext };
|
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { createContext } from 'svelte';
|
|
2
|
+
const [getFormContext, setFormContext] = createContext();
|
|
3
3
|
export function useFormContext() {
|
|
4
|
-
|
|
4
|
+
try {
|
|
5
|
+
return getFormContext();
|
|
6
|
+
}
|
|
7
|
+
catch {
|
|
8
|
+
return undefined;
|
|
9
|
+
}
|
|
5
10
|
}
|
|
11
|
+
export { setFormContext };
|
|
@@ -1,18 +1,23 @@
|
|
|
1
|
-
import { type CreateInertiaAppOptionsForCSR, type
|
|
1
|
+
import { type CreateInertiaAppOptions, type CreateInertiaAppOptionsForCSR, type InertiaAppSSRResponse, type Page, type PageProps } from '@inertiajs/core';
|
|
2
2
|
import App, { type InertiaAppProps } from './components/App.svelte';
|
|
3
3
|
import type { ComponentResolver, SvelteInertiaAppConfig } from './types';
|
|
4
4
|
type SvelteRenderResult = {
|
|
5
|
-
|
|
5
|
+
body: string;
|
|
6
6
|
head: string;
|
|
7
|
-
css?: {
|
|
8
|
-
code: string;
|
|
9
|
-
};
|
|
10
7
|
};
|
|
11
8
|
type SetupOptions<SharedProps extends PageProps> = {
|
|
12
9
|
el: HTMLElement | null;
|
|
13
10
|
App: typeof App;
|
|
14
11
|
props: InertiaAppProps<SharedProps>;
|
|
15
12
|
};
|
|
16
|
-
type
|
|
17
|
-
|
|
13
|
+
type InertiaAppOptionsForCSR<SharedProps extends PageProps> = CreateInertiaAppOptionsForCSR<SharedProps, ComponentResolver, SetupOptions<SharedProps>, SvelteRenderResult | void, SvelteInertiaAppConfig>;
|
|
14
|
+
type InertiaAppOptionsAuto<SharedProps extends PageProps> = CreateInertiaAppOptions<ComponentResolver, SetupOptions<SharedProps>, SvelteRenderResult | void, SvelteInertiaAppConfig> & {
|
|
15
|
+
page?: Page<SharedProps>;
|
|
16
|
+
};
|
|
17
|
+
type SvelteServerRender = (component: typeof App, options: {
|
|
18
|
+
props: InertiaAppProps<PageProps>;
|
|
19
|
+
}) => SvelteRenderResult;
|
|
20
|
+
type RenderFunction<SharedProps extends PageProps> = (page: Page<SharedProps>, render: SvelteServerRender) => Promise<InertiaAppSSRResponse>;
|
|
21
|
+
export default function createInertiaApp<SharedProps extends PageProps = PageProps>(options: InertiaAppOptionsForCSR<SharedProps>): Promise<InertiaAppSSRResponse | void>;
|
|
22
|
+
export default function createInertiaApp<SharedProps extends PageProps = PageProps>(options?: InertiaAppOptionsAuto<SharedProps>): Promise<void | RenderFunction<SharedProps>>;
|
|
18
23
|
export {};
|
package/dist/createInertiaApp.js
CHANGED
|
@@ -1,33 +1,72 @@
|
|
|
1
|
-
import { getInitialPageFromDOM, router, setupProgress, } from '@inertiajs/core';
|
|
2
|
-
import {
|
|
1
|
+
import { buildSSRBody, getInitialPageFromDOM, http as httpModule, router, setupProgress, } from '@inertiajs/core';
|
|
2
|
+
import { hydrate, mount } from 'svelte';
|
|
3
3
|
import App, {} from './components/App.svelte';
|
|
4
4
|
import { config } from './index';
|
|
5
|
-
export default async function createInertiaApp({ id = 'app', resolve, setup, progress = {}, page, defaults = {}, }) {
|
|
5
|
+
export default async function createInertiaApp({ id = 'app', resolve, setup, progress = {}, page, defaults = {}, http, layout, } = {}) {
|
|
6
6
|
config.replace(defaults);
|
|
7
|
+
if (http) {
|
|
8
|
+
httpModule.setClient(http);
|
|
9
|
+
}
|
|
7
10
|
const isServer = typeof window === 'undefined';
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
11
|
+
const resolveComponent = (name, page) => Promise.resolve(resolve(name, page));
|
|
12
|
+
if (isServer && !page) {
|
|
13
|
+
return async (page, render) => {
|
|
14
|
+
const initialComponent = (await resolveComponent(page.component, page));
|
|
15
|
+
const props = {
|
|
16
|
+
initialPage: page,
|
|
17
|
+
initialComponent,
|
|
18
|
+
resolveComponent,
|
|
19
|
+
defaultLayout: layout,
|
|
20
|
+
};
|
|
21
|
+
let svelteApp;
|
|
22
|
+
if (setup) {
|
|
23
|
+
const result = await setup({ el: null, App, props });
|
|
24
|
+
if (!result) {
|
|
25
|
+
throw new Error('Inertia SSR setup function must return a render result ({ body, head })');
|
|
26
|
+
}
|
|
27
|
+
svelteApp = result;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
svelteApp = render(App, { props });
|
|
31
|
+
}
|
|
32
|
+
const body = buildSSRBody(id, page, svelteApp.body);
|
|
33
|
+
return {
|
|
34
|
+
body,
|
|
35
|
+
head: [svelteApp.head],
|
|
36
|
+
};
|
|
28
37
|
};
|
|
29
38
|
}
|
|
30
|
-
|
|
39
|
+
const initialPage = page || getInitialPageFromDOM(id);
|
|
40
|
+
const [initialComponent] = await Promise.all([
|
|
41
|
+
resolveComponent(initialPage.component, initialPage),
|
|
42
|
+
router.decryptHistory().catch(() => { }),
|
|
43
|
+
]);
|
|
44
|
+
const props = { initialPage, initialComponent, resolveComponent, defaultLayout: layout };
|
|
45
|
+
if (isServer) {
|
|
46
|
+
if (!setup) {
|
|
47
|
+
throw new Error('Inertia SSR requires a setup function that returns a render result ({ body, head })');
|
|
48
|
+
}
|
|
49
|
+
const svelteApp = await setup({ el: null, App, props });
|
|
50
|
+
if (svelteApp) {
|
|
51
|
+
const body = buildSSRBody(id, initialPage, svelteApp.body);
|
|
52
|
+
return {
|
|
53
|
+
body,
|
|
54
|
+
head: [svelteApp.head],
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const target = document.getElementById(id);
|
|
60
|
+
if (setup) {
|
|
61
|
+
await setup({ el: target, App, props });
|
|
62
|
+
}
|
|
63
|
+
else if (target.hasAttribute('data-server-rendered')) {
|
|
64
|
+
hydrate(App, { target, props });
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
mount(App, { target, props });
|
|
68
|
+
}
|
|
69
|
+
if (progress) {
|
|
31
70
|
setupProgress(progress);
|
|
32
71
|
}
|
|
33
72
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
export { progress, router } from '@inertiajs/core';
|
|
1
|
+
export { http, progress, router } from '@inertiajs/core';
|
|
2
2
|
export { default as App } from './components/App.svelte';
|
|
3
|
+
export { createForm } from './components/createForm';
|
|
3
4
|
export { default as Deferred } from './components/Deferred.svelte';
|
|
4
5
|
export { default as Form } from './components/Form.svelte';
|
|
5
6
|
export { useFormContext } from './components/formContext';
|
|
@@ -7,11 +8,13 @@ export { default as InfiniteScroll } from './components/InfiniteScroll.svelte';
|
|
|
7
8
|
export { default as Link } from './components/Link.svelte';
|
|
8
9
|
export { default as WhenVisible } from './components/WhenVisible.svelte';
|
|
9
10
|
export { default as createInertiaApp } from './createInertiaApp';
|
|
11
|
+
export { resetLayoutProps, setLayoutProps, setLayoutPropsFor, useLayoutProps } from './layoutProps.svelte';
|
|
10
12
|
export { default as inertia } from './link';
|
|
11
|
-
export { default as page, usePage } from './page';
|
|
13
|
+
export { default as page, usePage } from './page.svelte';
|
|
12
14
|
export { type ResolvedComponent, type SvelteInertiaAppConfig } from './types';
|
|
13
|
-
export { default as useForm, type InertiaForm, type InertiaFormProps, type InertiaPrecognitiveForm } from './useForm';
|
|
15
|
+
export { default as useForm, type InertiaForm, type InertiaFormProps, type InertiaPrecognitiveForm, } from './useForm.svelte';
|
|
16
|
+
export { default as useHttp } from './useHttp.svelte';
|
|
14
17
|
export { default as usePoll } from './usePoll';
|
|
15
|
-
export { default as usePrefetch } from './usePrefetch';
|
|
16
|
-
export { default as useRemember } from './useRemember';
|
|
18
|
+
export { default as usePrefetch } from './usePrefetch.svelte';
|
|
19
|
+
export { default as useRemember } from './useRemember.svelte';
|
|
17
20
|
export declare const config: import("@inertiajs/core").Config<import("@inertiajs/core").InertiaAppConfig>;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { config as coreConfig } from '@inertiajs/core';
|
|
2
|
-
export { progress, router } from '@inertiajs/core';
|
|
2
|
+
export { http, progress, router } from '@inertiajs/core';
|
|
3
3
|
export { default as App } from './components/App.svelte';
|
|
4
|
+
export { createForm } from './components/createForm';
|
|
4
5
|
export { default as Deferred } from './components/Deferred.svelte';
|
|
5
6
|
export { default as Form } from './components/Form.svelte';
|
|
6
7
|
export { useFormContext } from './components/formContext';
|
|
@@ -8,11 +9,13 @@ export { default as InfiniteScroll } from './components/InfiniteScroll.svelte';
|
|
|
8
9
|
export { default as Link } from './components/Link.svelte';
|
|
9
10
|
export { default as WhenVisible } from './components/WhenVisible.svelte';
|
|
10
11
|
export { default as createInertiaApp } from './createInertiaApp';
|
|
12
|
+
export { resetLayoutProps, setLayoutProps, setLayoutPropsFor, useLayoutProps } from './layoutProps.svelte';
|
|
11
13
|
export { default as inertia } from './link';
|
|
12
|
-
export { default as page, usePage } from './page';
|
|
14
|
+
export { default as page, usePage } from './page.svelte';
|
|
13
15
|
export {} from './types';
|
|
14
|
-
export { default as useForm } from './useForm';
|
|
16
|
+
export { default as useForm, } from './useForm.svelte';
|
|
17
|
+
export { default as useHttp } from './useHttp.svelte';
|
|
15
18
|
export { default as usePoll } from './usePoll';
|
|
16
|
-
export { default as usePrefetch } from './usePrefetch';
|
|
17
|
-
export { default as useRemember } from './useRemember';
|
|
19
|
+
export { default as usePrefetch } from './usePrefetch.svelte';
|
|
20
|
+
export { default as useRemember } from './useRemember.svelte';
|
|
18
21
|
export const config = coreConfig.extend({});
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Readable } from 'svelte/store';
|
|
2
|
+
export declare function setLayoutProps(props: Record<string, unknown>): void;
|
|
3
|
+
export declare function setLayoutPropsFor(name: string, props: Record<string, unknown>): void;
|
|
4
|
+
export declare function resetLayoutProps(): void;
|
|
5
|
+
export declare const LAYOUT_CONTEXT_KEY: unique symbol;
|
|
6
|
+
export declare function useLayoutProps<T extends Record<string, unknown>>(defaults: T): Readable<T>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createLayoutPropsStore, mergeLayoutProps } from '@inertiajs/core';
|
|
2
|
+
import { getContext } from 'svelte';
|
|
3
|
+
import { readable } from 'svelte/store';
|
|
4
|
+
const store = createLayoutPropsStore();
|
|
5
|
+
export function setLayoutProps(props) {
|
|
6
|
+
store.set(props);
|
|
7
|
+
}
|
|
8
|
+
export function setLayoutPropsFor(name, props) {
|
|
9
|
+
store.setFor(name, props);
|
|
10
|
+
}
|
|
11
|
+
export function resetLayoutProps() {
|
|
12
|
+
store.reset();
|
|
13
|
+
}
|
|
14
|
+
export const LAYOUT_CONTEXT_KEY = Symbol('inertia-layout');
|
|
15
|
+
export function useLayoutProps(defaults) {
|
|
16
|
+
const context = getContext(LAYOUT_CONTEXT_KEY);
|
|
17
|
+
const resolve = () => {
|
|
18
|
+
const staticProps = context?.staticProps ?? {};
|
|
19
|
+
const name = context?.name;
|
|
20
|
+
const { shared, named } = store.get();
|
|
21
|
+
const dynamicProps = name ? { ...shared, ...named[name] } : shared;
|
|
22
|
+
return mergeLayoutProps(defaults, staticProps, dynamicProps);
|
|
23
|
+
};
|
|
24
|
+
return readable(resolve(), (set) => store.subscribe(() => set(resolve())));
|
|
25
|
+
}
|
package/dist/link.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isUrlMethodPair, mergeDataIntoQueryString, router, shouldIntercept, shouldNavigate, } from '@inertiajs/core';
|
|
1
|
+
import { isUrlMethodPair, mergeDataIntoQueryString, resolveUrlMethodPairComponent, router, shouldIntercept, shouldNavigate, } from '@inertiajs/core';
|
|
2
2
|
import { config } from '.';
|
|
3
3
|
function link(node, initialParams = {}) {
|
|
4
4
|
let inFlightCount = 0;
|
|
@@ -55,7 +55,7 @@ function link(node, initialParams = {}) {
|
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
57
|
};
|
|
58
|
-
function update({ cacheFor = 0, prefetch = false, cacheTags: cacheTagValues = [], viewTransition = false, ...params }) {
|
|
58
|
+
function update({ cacheFor = 0, prefetch = false, cacheTags: cacheTagValues = [], viewTransition = false, component: componentProp, instant = false, pageProps: pagePropsProp = null, ...params }) {
|
|
59
59
|
prefetchModes = (() => {
|
|
60
60
|
if (prefetch === true) {
|
|
61
61
|
return ['hover'];
|
|
@@ -77,6 +77,15 @@ function link(node, initialParams = {}) {
|
|
|
77
77
|
cacheTags = Array.isArray(cacheTagValues) ? cacheTagValues : [cacheTagValues];
|
|
78
78
|
method = isUrlMethodPair(params.href) ? params.href.method : params.method?.toLowerCase() || 'get';
|
|
79
79
|
[href, data] = hrefAndData(method, params);
|
|
80
|
+
const resolvedComponent = (() => {
|
|
81
|
+
if (componentProp) {
|
|
82
|
+
return componentProp;
|
|
83
|
+
}
|
|
84
|
+
if (instant && isUrlMethodPair(params.href)) {
|
|
85
|
+
return resolveUrlMethodPairComponent(params.href);
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
})();
|
|
80
89
|
if (node.tagName === 'A') {
|
|
81
90
|
node.href = href;
|
|
82
91
|
}
|
|
@@ -91,6 +100,8 @@ function link(node, initialParams = {}) {
|
|
|
91
100
|
except: params.except || [],
|
|
92
101
|
headers: params.headers || {},
|
|
93
102
|
async: params.async || false,
|
|
103
|
+
component: resolvedComponent,
|
|
104
|
+
pageProps: pagePropsProp,
|
|
94
105
|
};
|
|
95
106
|
visitParams = {
|
|
96
107
|
...baseParams,
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type Page, type PageProps, type SharedPageProps } from '@inertiajs/core';
|
|
2
|
+
type SveltePage<TPageProps extends PageProps = PageProps> = Omit<Page<TPageProps & SharedPageProps>, 'props'> & {
|
|
3
|
+
props: Page<TPageProps & SharedPageProps>['props'] & {
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
};
|
|
6
|
+
};
|
|
7
|
+
declare const page: SveltePage<PageProps>;
|
|
8
|
+
export declare function setPage(newPage: SveltePage): void;
|
|
9
|
+
export declare function usePage<TPageProps extends PageProps = PageProps>(): SveltePage<TPageProps>;
|
|
10
|
+
export default page;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import {} from '@inertiajs/core';
|
|
2
|
+
const page = $state({
|
|
3
|
+
component: '',
|
|
4
|
+
props: {},
|
|
5
|
+
url: '',
|
|
6
|
+
version: null,
|
|
7
|
+
});
|
|
8
|
+
export function setPage(newPage) {
|
|
9
|
+
Object.assign(page, newPage);
|
|
10
|
+
}
|
|
11
|
+
export function usePage() {
|
|
12
|
+
return page;
|
|
13
|
+
}
|
|
14
|
+
export default page;
|
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Page } from '@inertiajs/core';
|
|
2
|
+
import type { Component } from 'svelte';
|
|
2
3
|
import type { RenderFunction, RenderProps } from './components/Render.svelte';
|
|
3
|
-
export type ComponentResolver = (name: string) => ResolvedComponent | Promise<ResolvedComponent>;
|
|
4
|
+
export type ComponentResolver = (name: string, page?: Page) => ResolvedComponent | Promise<ResolvedComponent>;
|
|
4
5
|
export type LayoutResolver = (h: RenderFunction, page: RenderProps) => RenderProps;
|
|
5
|
-
export type
|
|
6
|
+
export type LayoutTuple = [Component, Record<string, unknown>?];
|
|
7
|
+
export type LayoutObject = {
|
|
8
|
+
component: Component;
|
|
9
|
+
props?: Record<string, unknown>;
|
|
10
|
+
};
|
|
11
|
+
export type NamedLayouts = Record<string, Component | LayoutTuple | LayoutObject>;
|
|
12
|
+
export type LayoutType = LayoutResolver | Component | Component[] | LayoutTuple | LayoutObject | NamedLayouts | (Component | LayoutTuple | LayoutObject)[];
|
|
6
13
|
export type ResolvedComponent = {
|
|
7
|
-
default:
|
|
14
|
+
default: Component;
|
|
8
15
|
layout?: LayoutType;
|
|
9
16
|
};
|
|
10
17
|
export type SvelteInertiaAppConfig = {};
|
package/dist/types.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import {} from '@inertiajs/core';
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import type { ErrorValue, FormDataErrors, FormDataKeys, FormDataType, FormDataValues, Method, Progress, UrlMethodPair, UseFormSubmitArguments, UseFormSubmitOptions, UseFormTransformCallback, UseFormWithPrecognitionArguments } from '@inertiajs/core';
|
|
1
|
+
import type { ErrorValue, FormDataErrors, FormDataKeys, FormDataType, FormDataValues, Method, OptimisticCallback, Progress, UrlMethodPair, UseFormSubmitArguments, UseFormSubmitOptions, UseFormTransformCallback, UseFormWithPrecognitionArguments } from '@inertiajs/core';
|
|
2
2
|
import type { NamedInputEvent, PrecognitionPath, ValidationConfig, Validator } from 'laravel-precognition';
|
|
3
|
-
|
|
4
|
-
type
|
|
5
|
-
type InertiaPrecognitiveFormStore<TForm extends object> = Writable<InertiaPrecognitiveForm<TForm>> & InertiaPrecognitiveForm<TForm>;
|
|
3
|
+
type InertiaFormStore<TForm extends object> = InertiaForm<TForm>;
|
|
4
|
+
type InertiaPrecognitiveFormStore<TForm extends object> = InertiaPrecognitiveForm<TForm>;
|
|
6
5
|
type PrecognitionValidationConfig<TKeys> = ValidationConfig & {
|
|
7
6
|
only?: TKeys[] | Iterable<TKeys> | ArrayLike<TKeys>;
|
|
8
7
|
};
|
|
@@ -34,6 +33,7 @@ export interface InertiaFormProps<TForm extends object> {
|
|
|
34
33
|
delete(url: string, options?: UseFormSubmitOptions): void;
|
|
35
34
|
cancel(): void;
|
|
36
35
|
dontRemember<K extends FormDataKeys<TForm>>(...fields: K[]): this;
|
|
36
|
+
optimistic<TProps>(callback: OptimisticCallback<TProps>): this;
|
|
37
37
|
withPrecognition: (...args: UseFormWithPrecognitionArguments) => InertiaPrecognitiveFormStore<TForm>;
|
|
38
38
|
}
|
|
39
39
|
export interface InertiaFormValidationProps<TForm extends object> {
|