@inertiajs/svelte 3.0.0-beta.4 → 3.0.0-beta.6
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.
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import type { FormComponentSlotProps } from '@inertiajs/core';
|
|
1
|
+
import type { FormComponentProps, FormComponentSlotProps } from '@inertiajs/core';
|
|
2
2
|
import type { Component, ComponentProps, Snippet } from 'svelte';
|
|
3
3
|
import Form from './Form.svelte';
|
|
4
|
-
type TypedFormComponent<TForm extends Record<string, any>> = Component<Omit<ComponentProps<typeof Form>, 'children'> & {
|
|
4
|
+
type TypedFormComponent<TForm extends Record<string, any>> = Component<Omit<ComponentProps<typeof Form>, 'children' | 'optimistic' | 'transform'> & {
|
|
5
|
+
optimistic?: FormComponentProps<TForm>['optimistic'];
|
|
6
|
+
transform?: FormComponentProps<TForm>['transform'];
|
|
5
7
|
children?: Snippet<[FormComponentSlotProps<TForm>]>;
|
|
6
8
|
}>;
|
|
7
9
|
export declare function createForm<TForm extends Record<string, any> = Record<string, any>>(): TypedFormComponent<TForm>;
|
package/dist/useHttp.svelte.d.ts
CHANGED
|
@@ -21,12 +21,12 @@ export interface UseHttpProps<TForm extends object, TResponse = unknown> {
|
|
|
21
21
|
resetAndClearErrors<K extends FormDataKeys<TForm>>(...fields: K[]): this;
|
|
22
22
|
setError<K extends FormDataKeys<TForm>>(field: K, value: ErrorValue): this;
|
|
23
23
|
setError(errors: FormDataErrors<TForm>): this;
|
|
24
|
-
submit
|
|
25
|
-
get
|
|
26
|
-
post
|
|
27
|
-
put
|
|
28
|
-
patch
|
|
29
|
-
delete
|
|
24
|
+
submit(...args: UseHttpSubmitArguments<TResponse, TForm>): Promise<TResponse>;
|
|
25
|
+
get(url: string, options?: UseHttpSubmitOptions<TResponse, TForm>): Promise<TResponse>;
|
|
26
|
+
post(url: string, options?: UseHttpSubmitOptions<TResponse, TForm>): Promise<TResponse>;
|
|
27
|
+
put(url: string, options?: UseHttpSubmitOptions<TResponse, TForm>): Promise<TResponse>;
|
|
28
|
+
patch(url: string, options?: UseHttpSubmitOptions<TResponse, TForm>): Promise<TResponse>;
|
|
29
|
+
delete(url: string, options?: UseHttpSubmitOptions<TResponse, TForm>): Promise<TResponse>;
|
|
30
30
|
cancel(): void;
|
|
31
31
|
dontRemember<K extends FormDataKeys<TForm>>(...fields: K[]): this;
|
|
32
32
|
optimistic(callback: (currentData: TForm) => Partial<TForm>): this;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@inertiajs/svelte",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.6",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "The Svelte adapter for Inertia.js",
|
|
6
6
|
"contributors": [
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"es-toolkit": "^1.33.0",
|
|
57
57
|
"laravel-precognition": "2.0.0-beta.5",
|
|
58
|
-
"@inertiajs/core": "3.0.0-beta.
|
|
58
|
+
"@inertiajs/core": "3.0.0-beta.6"
|
|
59
59
|
},
|
|
60
60
|
"scripts": {
|
|
61
61
|
"build": "pnpm package && svelte-check --tsconfig ./tsconfig.json && publint",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: inertia-svelte-development
|
|
3
|
-
description: "Develops Inertia.js v3 Svelte 5 client-side applications. Activates when creating Svelte pages, forms, or navigation; using Link, Form, useForm, useHttp,
|
|
3
|
+
description: "Develops Inertia.js v3 Svelte 5 client-side applications. Activates when creating Svelte pages, forms, or navigation; using Link, Form, useForm, useHttp, setLayoutProps, or router; working with deferred props, prefetching, optimistic updates, instant visits, or polling; or when user mentions Svelte with Inertia, Svelte pages, Svelte forms, or Svelte navigation."
|
|
4
4
|
license: MIT
|
|
5
5
|
metadata:
|
|
6
6
|
author: laravel
|
|
@@ -379,18 +379,11 @@ Share dynamic data between pages and persistent layouts:
|
|
|
379
379
|
|
|
380
380
|
@boostsnippet("Layout Props in Layout", "svelte")
|
|
381
381
|
<script>
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
const layout = useLayoutProps({
|
|
385
|
-
title: 'My App',
|
|
386
|
-
showSidebar: true,
|
|
387
|
-
})
|
|
388
|
-
|
|
389
|
-
let { children } = $props()
|
|
382
|
+
let { title = 'My App', showSidebar = true, children } = $props()
|
|
390
383
|
</script>
|
|
391
384
|
|
|
392
|
-
<header>{
|
|
393
|
-
{#if
|
|
385
|
+
<header>{title}</header>
|
|
386
|
+
{#if showSidebar}
|
|
394
387
|
<aside>Sidebar</aside>
|
|
395
388
|
{/if}
|
|
396
389
|
<main>
|
|
@@ -439,30 +432,54 @@ let { users } = $props()
|
|
|
439
432
|
|
|
440
433
|
### Polling
|
|
441
434
|
|
|
442
|
-
|
|
435
|
+
Use the `usePoll` hook to automatically refresh data at intervals. It handles cleanup on unmount and throttles polling when the tab is inactive.
|
|
443
436
|
|
|
444
|
-
@boostsnippet("Polling
|
|
437
|
+
@boostsnippet("Basic Polling", "svelte")
|
|
445
438
|
<script>
|
|
446
|
-
import {
|
|
447
|
-
import { onMount } from 'svelte'
|
|
439
|
+
import { usePoll } from '@inertiajs/svelte'
|
|
448
440
|
|
|
449
441
|
let { stats } = $props()
|
|
450
442
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
443
|
+
usePoll(5000)
|
|
444
|
+
</script>
|
|
445
|
+
|
|
446
|
+
<div>
|
|
447
|
+
<h1>Dashboard</h1>
|
|
448
|
+
<div>Active Users: {stats.activeUsers}</div>
|
|
449
|
+
</div>
|
|
450
|
+
@endboostsnippet
|
|
451
|
+
|
|
452
|
+
@boostsnippet("Polling With Request Options and Manual Control", "svelte")
|
|
453
|
+
<script>
|
|
454
|
+
import { usePoll } from '@inertiajs/svelte'
|
|
455
|
+
|
|
456
|
+
let { stats } = $props()
|
|
455
457
|
|
|
456
|
-
|
|
458
|
+
const { start, stop } = usePoll(5000, {
|
|
459
|
+
only: ['stats'],
|
|
460
|
+
onStart() {
|
|
461
|
+
console.log('Polling request started')
|
|
462
|
+
},
|
|
463
|
+
onFinish() {
|
|
464
|
+
console.log('Polling request finished')
|
|
465
|
+
},
|
|
466
|
+
}, {
|
|
467
|
+
autoStart: false,
|
|
468
|
+
keepAlive: true,
|
|
457
469
|
})
|
|
458
470
|
</script>
|
|
459
471
|
|
|
460
472
|
<div>
|
|
461
473
|
<h1>Dashboard</h1>
|
|
462
474
|
<div>Active Users: {stats.activeUsers}</div>
|
|
475
|
+
<button onclick={start}>Start Polling</button>
|
|
476
|
+
<button onclick={stop}>Stop Polling</button>
|
|
463
477
|
</div>
|
|
464
478
|
@endboostsnippet
|
|
465
479
|
|
|
480
|
+
- `autoStart` (default `true`) - set to `false` to start polling manually via the returned `start()` function
|
|
481
|
+
- `keepAlive` (default `false`) - set to `true` to prevent throttling when the browser tab is inactive
|
|
482
|
+
|
|
466
483
|
### WhenVisible
|
|
467
484
|
|
|
468
485
|
Lazy-load a prop when an element scrolls into view. Useful for deferring expensive data that sits below the fold:
|
|
@@ -490,6 +507,26 @@ let { stats } = $props()
|
|
|
490
507
|
</div>
|
|
491
508
|
@endboostsnippet
|
|
492
509
|
|
|
510
|
+
### InfiniteScroll
|
|
511
|
+
|
|
512
|
+
Automatically load additional pages of paginated data as users scroll:
|
|
513
|
+
|
|
514
|
+
@boostsnippet("InfiniteScroll Example", "svelte")
|
|
515
|
+
<script>
|
|
516
|
+
import { InfiniteScroll } from '@inertiajs/svelte'
|
|
517
|
+
|
|
518
|
+
let { users } = $props()
|
|
519
|
+
</script>
|
|
520
|
+
|
|
521
|
+
<InfiniteScroll data="users">
|
|
522
|
+
{#each users.data as user (user.id)}
|
|
523
|
+
<div>{user.name}</div>
|
|
524
|
+
{/each}
|
|
525
|
+
</InfiniteScroll>
|
|
526
|
+
@endboostsnippet
|
|
527
|
+
|
|
528
|
+
The server must use `Inertia::scroll()` to configure the paginated data. Use the `search-docs` tool with a query of `infinite scroll` for detailed guidance on buffers, manual loading, reverse mode, and custom trigger elements.
|
|
529
|
+
|
|
493
530
|
## Server-Side Patterns
|
|
494
531
|
|
|
495
532
|
Server-side patterns (Inertia::render, props, middleware) are covered in inertia-laravel guidelines.
|