@void/svelte 0.0.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/README.md +112 -0
- package/dist/plugin.d.mts +16 -0
- package/dist/plugin.mjs +681 -0
- package/package.json +54 -0
- package/src/runtime/App.svelte +81 -0
- package/src/runtime/Link.svelte +316 -0
- package/src/runtime/action.ts +50 -0
- package/src/runtime/index.ts +8 -0
- package/src/runtime/prefetch.ts +2 -0
- package/src/runtime/use-form.svelte.ts +205 -0
- package/src/runtime/use-island-form.svelte.ts +175 -0
- package/src/runtime/use-navigation.ts +22 -0
- package/src/runtime/use-router.ts +9 -0
- package/src/runtime/use-shared.ts +10 -0
package/README.md
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# @void/svelte
|
|
2
|
+
|
|
3
|
+
Svelte 5 adapter for Void Pages mode.
|
|
4
|
+
|
|
5
|
+
## Setup
|
|
6
|
+
|
|
7
|
+
```ts
|
|
8
|
+
import { defineConfig } from 'vite';
|
|
9
|
+
import { voidPlugin } from 'void';
|
|
10
|
+
import { voidSvelte } from '@void/svelte/plugin';
|
|
11
|
+
|
|
12
|
+
export default defineConfig({
|
|
13
|
+
plugins: [voidPlugin(), voidSvelte()],
|
|
14
|
+
});
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Plugin
|
|
18
|
+
|
|
19
|
+
`voidSvelte(options?)` returns:
|
|
20
|
+
|
|
21
|
+
- `@sveltejs/vite-plugin-svelte`
|
|
22
|
+
- the Svelte pages plugin
|
|
23
|
+
- the Svelte islands plugin
|
|
24
|
+
|
|
25
|
+
Options:
|
|
26
|
+
|
|
27
|
+
- `svelte?` — forwarded to the Svelte Vite plugin
|
|
28
|
+
- `viewTransitions?` — enable View Transitions for SPA navigation
|
|
29
|
+
- `prefetch?` — link prefetch behavior
|
|
30
|
+
|
|
31
|
+
## Runtime
|
|
32
|
+
|
|
33
|
+
Main runtime APIs live at `@void/svelte`:
|
|
34
|
+
|
|
35
|
+
- `Link`
|
|
36
|
+
- `useRouter()`
|
|
37
|
+
- `useNavigation()`
|
|
38
|
+
- `useShared()`
|
|
39
|
+
- `useForm()`
|
|
40
|
+
- `useIslandForm()`
|
|
41
|
+
- `action()`
|
|
42
|
+
|
|
43
|
+
### Link
|
|
44
|
+
|
|
45
|
+
`Link` renders an `<a>` for GET navigation and a `<button>` for mutation methods:
|
|
46
|
+
|
|
47
|
+
```svelte
|
|
48
|
+
<Link href="/users" data={{ page: 2, tag: ["active", "new"] }}>Filtered users</Link>
|
|
49
|
+
<Link href="/users" replace>Users</Link>
|
|
50
|
+
<Link href="/logout" reloadDocument>Sign out</Link>
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
GET `data` is merged into the rendered `href` query string. Primitive values are serialized with `String(value)`, arrays become repeated keys, `null` and `undefined` are omitted, and nested objects throw.
|
|
54
|
+
|
|
55
|
+
`prefetch` and `reloadDocument` are GET-only and throw for mutation links. `onNavigate` can cancel client-side navigation by calling `event.preventDefault()`.
|
|
56
|
+
|
|
57
|
+
### Forms
|
|
58
|
+
|
|
59
|
+
`useForm()` tracks form state for Pages actions. Use `pending` for in-flight
|
|
60
|
+
state, `errors` for field validation, and `error` for non-validation call-site
|
|
61
|
+
failures. The submit helpers return promises so boundary-class failures can
|
|
62
|
+
propagate through Svelte async error handling or explicit `catch` handlers.
|
|
63
|
+
|
|
64
|
+
```svelte
|
|
65
|
+
<script lang="ts">
|
|
66
|
+
import { useForm } from '@void/svelte';
|
|
67
|
+
|
|
68
|
+
const form = useForm('/users', { name: '', email: '' });
|
|
69
|
+
</script>
|
|
70
|
+
|
|
71
|
+
<form
|
|
72
|
+
onsubmit={(event) => {
|
|
73
|
+
event.preventDefault();
|
|
74
|
+
return form.post();
|
|
75
|
+
}}
|
|
76
|
+
>
|
|
77
|
+
<input bind:value={form.data.name} name="name" />
|
|
78
|
+
{#if form.errors.name}<p>{form.errors.name}</p>{/if}
|
|
79
|
+
{#if form.error}<p>{form.error.message}</p>{/if}
|
|
80
|
+
<button disabled={form.pending}>Save</button>
|
|
81
|
+
</form>
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Use `action()` for the awaitable imperative escape hatch. It returns
|
|
85
|
+
`{ ok: true, pageData }` or `{ ok: false, error }` for call-site action errors,
|
|
86
|
+
while boundary-class failures are thrown. `action()` uses `POST` by default and
|
|
87
|
+
accepts `{ method: "PUT" | "PATCH" | "DELETE" }`.
|
|
88
|
+
|
|
89
|
+
## Pages
|
|
90
|
+
|
|
91
|
+
Pages are `.svelte` files in `pages/` with companion `.server.ts` files:
|
|
92
|
+
|
|
93
|
+
```svelte
|
|
94
|
+
<script>
|
|
95
|
+
let { title } = $props();
|
|
96
|
+
</script>
|
|
97
|
+
|
|
98
|
+
<h1>{title}</h1>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
```ts
|
|
102
|
+
import { defineHandler } from 'void';
|
|
103
|
+
|
|
104
|
+
export const loader = defineHandler(() => ({ title: 'Home' }));
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
## Tests
|
|
108
|
+
|
|
109
|
+
- `test/unit/use-form.test.ts`
|
|
110
|
+
- `test/integration/svelte-pages-client.test.ts`
|
|
111
|
+
|
|
112
|
+
Cross-package SSR/protocol coverage for Svelte pages mode also lives in `framework/packages/void/test/integration/*`.
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { svelte } from "@sveltejs/vite-plugin-svelte";
|
|
2
|
+
import { Plugin } from "vite";
|
|
3
|
+
|
|
4
|
+
//#region src/plugin.d.ts
|
|
5
|
+
interface PrefetchConfig {
|
|
6
|
+
hoverDelay?: number;
|
|
7
|
+
cacheFor?: number | string | [string, string];
|
|
8
|
+
}
|
|
9
|
+
interface VoidSvelteOptions {
|
|
10
|
+
svelte?: Parameters<typeof svelte>[0];
|
|
11
|
+
viewTransitions?: boolean;
|
|
12
|
+
prefetch?: PrefetchConfig;
|
|
13
|
+
}
|
|
14
|
+
declare function voidSvelte(options?: VoidSvelteOptions): Array<Plugin>;
|
|
15
|
+
//#endregion
|
|
16
|
+
export { VoidSvelteOptions, voidSvelte };
|