@void/solid 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 ADDED
@@ -0,0 +1,116 @@
1
+ # @void/solid
2
+
3
+ Solid adapter for Void Pages mode.
4
+
5
+ ## Setup
6
+
7
+ ```ts
8
+ import { defineConfig } from 'vite';
9
+ import { voidPlugin } from 'void';
10
+ import { voidSolid } from '@void/solid/plugin';
11
+
12
+ export default defineConfig({
13
+ plugins: [voidPlugin(), voidSolid()],
14
+ });
15
+ ```
16
+
17
+ ## Plugin
18
+
19
+ `voidSolid(options?)` returns:
20
+
21
+ - `vite-plugin-solid`
22
+ - the Solid pages plugin
23
+ - the Solid islands plugin
24
+
25
+ Options:
26
+
27
+ - `solid?` — forwarded to `vite-plugin-solid`
28
+ - `viewTransitions?` — enable View Transitions for SPA navigation
29
+ - `prefetch?` — link prefetch behavior
30
+
31
+ ## Runtime
32
+
33
+ Main runtime APIs live at `@void/solid`:
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
+ ```tsx
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 Solid async error handling or explicit `catch` handlers.
63
+
64
+ ```tsx
65
+ import { useForm } from '@void/solid';
66
+
67
+ export default function CreateUser() {
68
+ const form = useForm('/users', { name: '', email: '' });
69
+
70
+ return (
71
+ <form
72
+ onSubmit={(event) => {
73
+ event.preventDefault();
74
+ return form.post();
75
+ }}
76
+ >
77
+ <input
78
+ name="name"
79
+ value={form.data.name}
80
+ onInput={(event) => form.setData('name', event.currentTarget.value)}
81
+ />
82
+ {form.errors.name && <p>{form.errors.name}</p>}
83
+ {form.error && <p>{form.error.message}</p>}
84
+ <button disabled={form.pending}>Save</button>
85
+ </form>
86
+ );
87
+ }
88
+ ```
89
+
90
+ Use `action()` for the awaitable imperative escape hatch. It returns
91
+ `{ ok: true, pageData }` or `{ ok: false, error }` for call-site action errors,
92
+ while boundary-class failures are thrown. `action()` uses `POST` by default and
93
+ accepts `{ method: "PUT" | "PATCH" | "DELETE" }`.
94
+
95
+ ## Pages
96
+
97
+ Pages are `.tsx` files in `pages/` with companion `.server.ts` files:
98
+
99
+ ```tsx
100
+ export default function Home(props: { title: string }) {
101
+ return <h1>{props.title}</h1>;
102
+ }
103
+ ```
104
+
105
+ ```ts
106
+ import { defineHandler } from 'void';
107
+
108
+ export const loader = defineHandler(() => ({ title: 'Home' }));
109
+ ```
110
+
111
+ ## Tests
112
+
113
+ - `test/unit/use-form.test.ts`
114
+ - `test/integration/solid-pages-playground.test.ts`
115
+
116
+ The Solid integration test covers both SSR output and browser-side navigation/forms.
@@ -0,0 +1,16 @@
1
+ import solid from "vite-plugin-solid";
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 VoidSolidOptions {
10
+ solid?: Parameters<typeof solid>[0];
11
+ viewTransitions?: boolean;
12
+ prefetch?: PrefetchConfig;
13
+ }
14
+ declare function voidSolid(options?: VoidSolidOptions): Array<Plugin>;
15
+ //#endregion
16
+ export { VoidSolidOptions, voidSolid };