@ilha/void 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2026 Ryuz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,63 @@
1
- # Temporary Holding Version
1
+ # `@ilha/void`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Render [Void](https://void.cloud) pages, layouts, forms, and islands with [Ilha](https://github.com/ilhajs/ilha). Void handles file routing, loaders, actions, and deployment. `@ilha/void` renders each page with `renderToString()` and hydrates it with `mount()`.
4
+
5
+ ---
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ bun add @ilha/void
11
+ ```
12
+
13
+ `ilha`, `vite`, and `void` are peer dependencies. Void needs Node.js 24.21 or newer.
14
+
15
+ ---
16
+
17
+ ## Usage
18
+
19
+ Add `voidIlha()` after `voidPlugin()` in your Vite config:
20
+
21
+ ```ts
22
+ // vite.config.ts
23
+ import { voidIlha } from "@ilha/void/plugin";
24
+ import { defineConfig } from "vite";
25
+ import { voidPlugin } from "void";
26
+
27
+ export default defineConfig({
28
+ plugins: [voidPlugin(), voidIlha()],
29
+ });
30
+ ```
31
+
32
+ Set `jsxImportSource` to `ilha` in `tsconfig.json`. Each file in `pages/` default-exports an Ilha component whose props come from the page's loader:
33
+
34
+ ```tsx
35
+ // pages/index.tsx
36
+ import { Link } from "@ilha/void";
37
+
38
+ export default function Home({ title }: { title: string }) {
39
+ return (
40
+ <main>
41
+ <h1>{title}</h1>
42
+ <Link href="/about" prefetch>
43
+ About
44
+ </Link>
45
+ </main>
46
+ );
47
+ }
48
+ ```
49
+
50
+ Name a page `*.island.tsx` for static HTML, and import components `with { island: "visible" }` to hydrate only those.
51
+
52
+ Scaffold an app with `npx giget@latest gh:ilhajs/ilha/templates/void`.
53
+
54
+ ---
55
+
56
+ ## Exports
57
+
58
+ | Import path | Exports |
59
+ | --- | --- |
60
+ | `@ilha/void` | `Link`, `Form`, `useForm`, `useIslandForm`, `useParams`, `useShared`, `useNavigation`, `useRouter`, `action` |
61
+ | `@ilha/void/plugin` | `voidIlha()` |
62
+
63
+ Docs: [ilha.build/guide/void](https://ilha.build/guide/void)
@@ -0,0 +1,10 @@
1
+ import { createActionClient } from "void/pages-client";
2
+
3
+ //#region src/action.ts
4
+ const client = createActionClient();
5
+ /** Call a page action; uses the Void Router once a regular page hydrates. */
6
+ const action = client.action;
7
+ const setActionRouter = client.setActionRouter;
8
+
9
+ //#endregion
10
+ export { setActionRouter as n, action as t };
@@ -0,0 +1,4 @@
1
+ import type { ActionClient } from "void/pages-client";
2
+ /** Call a page action; uses the Void Router once a regular page hydrates. */
3
+ export declare const action: ActionClient["action"];
4
+ export declare const setActionRouter: ActionClient["setActionRouter"];
@@ -0,0 +1,50 @@
1
+ import { t as VoidContext } from "./context-fQy_XW7o.js";
2
+ import { atom, h } from "ilha";
3
+
4
+ //#region src/app.ts
5
+ const composeTree = ({ layouts, page, pageKey, props, state }) => {
6
+ if (!page) return null;
7
+ let view = h(page, {
8
+ ...props,
9
+ key: pageKey
10
+ });
11
+ for (let index = layouts.length - 1; index >= 0; index -= 1) {
12
+ const layout = layouts[index];
13
+ if (layout) view = h(layout, null, view);
14
+ }
15
+ return h(VoidContext.Provider, { value: state }, view);
16
+ };
17
+ /**
18
+ * Root component for a Void page. The server and the client render the same
19
+ * root, so hydration snapshots line up slot for slot.
20
+ */
21
+ const createPageRoot = ({ connect, read }) => () => {
22
+ const version = atom(0);
23
+ connect?.(() => version.update((current) => current + 1));
24
+ version();
25
+ return composeTree(read());
26
+ };
27
+ /** Import a page component and its layout chain. */
28
+ const loadPageComponents = async ({ componentId, components, layoutTree }) => {
29
+ const load = async (id) => {
30
+ const importer = components[id];
31
+ if (!importer) throw new Error(`@ilha/void: no component registered for "${id}".`);
32
+ return (await importer()).default;
33
+ };
34
+ const [page, ...layouts] = await Promise.all([load(componentId), ...(layoutTree[componentId] ?? []).map(load)]);
35
+ return {
36
+ layouts,
37
+ page
38
+ };
39
+ };
40
+ /** Read the render inputs from a Void page object. */
41
+ const routeData = (pageData) => ({
42
+ errors: pageData.errors ?? {},
43
+ pageId: pageData.component,
44
+ params: pageData.params ?? {},
45
+ props: pageData.props,
46
+ shared: pageData.shared ?? {}
47
+ });
48
+
49
+ //#endregion
50
+ export { loadPageComponents as n, routeData as r, createPageRoot as t };
package/dist/app.d.ts ADDED
@@ -0,0 +1,56 @@
1
+ import type { View } from "ilha";
2
+ import type { PageObject } from "void/pages-protocol";
3
+ import type { VoidPageState } from "./context";
4
+ import type { FieldErrors, JsonRecord, PageProps } from "./types";
5
+ /** A page or layout component: the default export of a module in `pages/`. */
6
+ export type PageComponent = (props: never) => View | Promise<View | undefined> | Generator<View, View | undefined, View> | undefined;
7
+ export interface PageModule {
8
+ readonly default: PageComponent;
9
+ }
10
+ /** Lazy component imports generated by Void's component manifest. */
11
+ export type ComponentManifest = Readonly<Record<string, () => Promise<PageModule>>>;
12
+ /** Page component ID → layout IDs, outermost first. */
13
+ export type LayoutTree = Record<string, string[]>;
14
+ /** Everything one render of a Void page needs. */
15
+ export interface PageTree {
16
+ readonly page: PageComponent | null;
17
+ /**
18
+ * Identity of the page instance. A new key mounts the page with fresh
19
+ * state; layouts keep theirs because they stay unkeyed.
20
+ */
21
+ readonly pageKey: string;
22
+ readonly props: PageProps;
23
+ readonly layouts: readonly PageComponent[];
24
+ readonly state: VoidPageState;
25
+ }
26
+ export interface PageRootOptions {
27
+ /** Return the tree to render. Called on every render of the root. */
28
+ read: () => PageTree;
29
+ /** Receive a function that rerenders the root after the tree changes. */
30
+ connect?: (rerender: () => void) => void;
31
+ }
32
+ /**
33
+ * Root component for a Void page. The server and the client render the same
34
+ * root, so hydration snapshots line up slot for slot.
35
+ */
36
+ export declare const createPageRoot: ({ connect, read }: PageRootOptions) => () => View;
37
+ export interface LoadPageTreeOptions {
38
+ components: ComponentManifest;
39
+ layoutTree: LayoutTree;
40
+ componentId: string;
41
+ }
42
+ /** Import a page component and its layout chain. */
43
+ export declare const loadPageComponents: ({ componentId, components, layoutTree, }: LoadPageTreeOptions) => Promise<{
44
+ page: PageComponent;
45
+ layouts: PageComponent[];
46
+ }>;
47
+ /** The parts of Void page data a render reads. */
48
+ export interface RouteData {
49
+ pageId: string;
50
+ props: PageProps;
51
+ params: Readonly<Record<string, string>>;
52
+ shared: JsonRecord;
53
+ errors: FieldErrors;
54
+ }
55
+ /** Read the render inputs from a Void page object. */
56
+ export declare const routeData: (pageData: PageObject) => RouteData;
@@ -0,0 +1,11 @@
1
+ import type { VoidRouter, VoidRouterConfig } from "void/pages-client";
2
+ import type { ComponentManifest, LayoutTree } from "./app";
3
+ export type StartPagesOptions = Omit<VoidRouterConfig, "adapter" | "components" | "layoutTree" | "onNavigationChange" | "onRouteChange"> & {
4
+ components: ComponentManifest;
5
+ layoutTree: LayoutTree;
6
+ };
7
+ /**
8
+ * Hydrate `#app` and hand navigation to the Void Router. The generated
9
+ * `virtual:void-pages-client` entry calls this once per document.
10
+ */
11
+ export declare const startPages: ({ components, layoutTree, ...config }: StartPagesOptions) => Promise<VoidRouter>;
package/dist/client.js ADDED
@@ -0,0 +1,146 @@
1
+ import { n as setActionRouter } from "./action-hKFilV-5.js";
2
+ import { n as createPageState } from "./context-fQy_XW7o.js";
3
+ import { r as routeData, t as createPageRoot } from "./app-C92pEfKv.js";
4
+ import { createRouterFacade, createVoidRouter, idleNavigationState } from "void/pages-client";
5
+ import { mount } from "ilha";
6
+
7
+ //#region src/client.ts
8
+ const sameParams = (a, b) => {
9
+ const keys = Object.keys(a);
10
+ return keys.length === Object.keys(b).length && keys.every((key) => a[key] === b[key]);
11
+ };
12
+ const currentUrl = () => window.location.pathname + window.location.search + window.location.hash;
13
+ const noop = () => void 0;
14
+ /** Longest an update waits for the DOM before it lets the router go on. */
15
+ const PAINT_TIMEOUT_MS = 1e3;
16
+ const pendingDeferred = () => ({
17
+ error: null,
18
+ loading: true,
19
+ value: null
20
+ });
21
+ const settledDeferred = (value) => ({
22
+ error: null,
23
+ loading: false,
24
+ value
25
+ });
26
+ const failedDeferred = (error) => ({
27
+ error: new Error(error),
28
+ loading: false,
29
+ value: null
30
+ });
31
+ /**
32
+ * Hydrate `#app` and hand navigation to the Void Router. The generated
33
+ * `virtual:void-pages-client` entry calls this once per document.
34
+ */
35
+ const startPages = async ({ components, layoutTree, ...config }) => {
36
+ let rerender = noop;
37
+ const paintWaiters = [];
38
+ /** Rerender the page and resolve once the DOM reflects the new route. */
39
+ const repaint = async () => {
40
+ const { promise, resolve } = Promise.withResolvers();
41
+ const timer = setTimeout(() => resolve(null), PAINT_TIMEOUT_MS);
42
+ paintWaiters.push(() => {
43
+ clearTimeout(timer);
44
+ resolve(null);
45
+ });
46
+ rerender();
47
+ await promise;
48
+ };
49
+ let url = currentUrl();
50
+ let navigation = idleNavigationState();
51
+ let navigations = 0;
52
+ let route = {
53
+ errors: {},
54
+ layouts: [],
55
+ page: null,
56
+ pageId: "",
57
+ pageKey: "",
58
+ params: {},
59
+ props: {},
60
+ shared: {}
61
+ };
62
+ const update = (next) => {
63
+ route = {
64
+ ...route,
65
+ ...next
66
+ };
67
+ return repaint();
68
+ };
69
+ const { commitInitialRender, initialComponent, initialLayouts, initialPageData, router, start } = await createVoidRouter({
70
+ ...config,
71
+ adapter: {
72
+ applyUpdate(pageData, component, layouts, { preserveState }) {
73
+ const data = routeData(pageData);
74
+ const keep = preserveState && route.pageId === data.pageId && route.page === component && sameParams(route.params, data.params);
75
+ if (!keep) navigations += 1;
76
+ return update({
77
+ ...data,
78
+ layouts,
79
+ page: component,
80
+ pageKey: keep ? route.pageKey : `${data.pageId}#${String(navigations)}`
81
+ });
82
+ },
83
+ createDeferred: pendingDeferred,
84
+ isLoading: (ref) => ref.loading,
85
+ onDeferredUpdate(props) {
86
+ update({ props: { ...props } });
87
+ },
88
+ rejectDeferred: (_ref, error) => failedDeferred(error),
89
+ resolveDeferred: (_ref, value) => settledDeferred(value)
90
+ },
91
+ components,
92
+ layoutTree,
93
+ onNavigationChange(next) {
94
+ navigation = next;
95
+ repaint();
96
+ },
97
+ onRouteChange(next) {
98
+ url = next;
99
+ repaint();
100
+ }
101
+ });
102
+ const facade = createRouterFacade(router, () => url, () => route.params);
103
+ setActionRouter(facade);
104
+ const initial = routeData(initialPageData);
105
+ route = {
106
+ ...initial,
107
+ layouts: initialLayouts,
108
+ page: initialComponent,
109
+ pageKey: initial.pageId
110
+ };
111
+ const read = () => ({
112
+ layouts: route.layouts,
113
+ page: route.page,
114
+ pageKey: route.pageKey,
115
+ props: route.props,
116
+ state: createPageState({
117
+ errors: route.errors,
118
+ navigation,
119
+ params: route.params,
120
+ router: facade,
121
+ shared: route.shared
122
+ })
123
+ });
124
+ const app = document.querySelector("#app");
125
+ if (!app) throw new Error("@ilha/void: missing #app element for page hydration.");
126
+ const hydrate = app.dataset.voidSsr !== "false";
127
+ const host = hydrate && app.querySelector(":scope > [data-ilha]") || app;
128
+ mount(host, createPageRoot({
129
+ connect: (next) => {
130
+ rerender = next;
131
+ },
132
+ read
133
+ }), {
134
+ hydrate,
135
+ onIdle: () => {
136
+ for (const resolve of paintWaiters.splice(0)) resolve();
137
+ }
138
+ });
139
+ app.dataset.hydrated = "true";
140
+ start();
141
+ commitInitialRender();
142
+ return facade;
143
+ };
144
+
145
+ //#endregion
146
+ export { startPages };
@@ -0,0 +1,13 @@
1
+ import { createContext } from "ilha";
2
+
3
+ //#region src/context.ts
4
+ const VoidContext = createContext(null);
5
+ /**
6
+ * Freeze page state for `VoidContext.Provider`. The provider keeps its value
7
+ * out of the hydration snapshot; the client rebuilds it from
8
+ * `__VOID_PAGE_DATA__`.
9
+ */
10
+ const createPageState = (state) => Object.freeze({ ...state });
11
+
12
+ //#endregion
13
+ export { createPageState as n, VoidContext as t };
@@ -0,0 +1,19 @@
1
+ import type { NavigationState, VoidRouter } from "void/pages-client";
2
+ import type { FieldErrors, JsonRecord } from "./types";
3
+ /** Route state every component under a Void page can read. */
4
+ export interface VoidPageState {
5
+ /** The Void Router; `null` on island pages, which navigate with full loads. */
6
+ readonly router: VoidRouter | null;
7
+ readonly params: Readonly<Record<string, string>>;
8
+ readonly shared: JsonRecord;
9
+ /** Validation errors the last action returned through a redirect. */
10
+ readonly errors: FieldErrors;
11
+ readonly navigation: NavigationState;
12
+ }
13
+ export declare const VoidContext: import("ilha").IlhaContext<VoidPageState | null>;
14
+ /**
15
+ * Freeze page state for `VoidContext.Provider`. The provider keeps its value
16
+ * out of the hydration snapshot; the client rebuilds it from
17
+ * `__VOID_PAGE_DATA__`.
18
+ */
19
+ export declare const createPageState: (state: VoidPageState) => VoidPageState;
@@ -0,0 +1,33 @@
1
+ import type { VoidActionError } from "void/pages-client";
2
+ import type { FieldErrors, FormValues } from "./types";
3
+ /** Form state every Void form helper exposes. Reads subscribe the component. */
4
+ export interface FormFields<T extends object> {
5
+ readonly data: T;
6
+ setData: <K extends keyof T & string>(field: K, value: T[K]) => void;
7
+ readonly errors: FieldErrors;
8
+ readonly error: VoidActionError | null;
9
+ readonly pending: boolean;
10
+ readonly hasChanges: boolean;
11
+ readonly wasSuccessful: boolean;
12
+ readonly recentlySuccessful: boolean;
13
+ reset: (...fields: (keyof T & string)[]) => void;
14
+ clearErrors: (...fields: string[]) => void;
15
+ clearError: () => void;
16
+ }
17
+ export interface FormState<T extends FormValues> {
18
+ fields: FormFields<T>;
19
+ /** Clear submit state before a request. */
20
+ begin: () => void;
21
+ /** Mark a successful submit; the current data becomes the new baseline. */
22
+ succeed: () => void;
23
+ fail: (error: VoidActionError) => void;
24
+ setErrors: (errors: FieldErrors) => void;
25
+ finish: () => void;
26
+ /** Snapshot of the current data for a request body. */
27
+ read: () => T;
28
+ }
29
+ /**
30
+ * Declare the atoms behind a form helper. Call it at the top level of a
31
+ * component, like any other primitive.
32
+ */
33
+ export declare const formState: <T extends FormValues>(defaults: T, globalErrors?: () => FieldErrors) => FormState<T>;
package/dist/form.d.ts ADDED
@@ -0,0 +1,18 @@
1
+ import type { View } from "ilha";
2
+ import type { JSX } from "ilha/jsx-runtime";
3
+ import type { FormMethod, FormModel, VoidActionError } from "void/pages-client";
4
+ interface FormOptions {
5
+ /** A `useForm()` result: its submit helpers take no arguments. */
6
+ form: FormModel;
7
+ method?: FormMethod;
8
+ renderError?: (error: VoidActionError) => View;
9
+ children?: View;
10
+ }
11
+ /** Form options plus `<form>` attributes, which pass through to the element. */
12
+ export type FormProps = FormOptions & Omit<JSX.IntrinsicElements["form"], keyof FormOptions | "onsubmit">;
13
+ /**
14
+ * Submit `form` on `submit`, show its error, and block resubmits while a
15
+ * rate-limit retry window is open.
16
+ */
17
+ export declare const Form: ({ children, form, method, renderError, ...attributes }: FormProps) => View;
18
+ export {};
@@ -0,0 +1,12 @@
1
+ import type { CloudContextVariables } from "void";
2
+ import type { NavigationState, VoidRouter } from "void/pages-client";
3
+ /** The Void Router. Outside a hydrated regular page it is a server-safe stub. */
4
+ export declare const useRouter: () => VoidRouter;
5
+ /** Route params of the current page. Rerenders the component when they change. */
6
+ export declare const useParams: <T extends Record<string, string> = Record<string, string>>() => T;
7
+ /** Values the app's middleware shares with every page. */
8
+ export declare const useShared: <T = CloudContextVariables["shared"]>() => T;
9
+ /** Pending navigation state. Idle on island pages and during SSR. */
10
+ export declare const useNavigation: () => NavigationState;
11
+ /** Validation errors the last page action returned. */
12
+ export declare const usePageErrors: () => Readonly<Record<string, string>>;
@@ -0,0 +1,16 @@
1
+ export type { DeferredState as Deferred, InferProps } from "void";
2
+ export type { NavigationState, VoidActionError, VoidRouter, } from "void/pages-client";
3
+ export { action, setActionRouter } from "./action";
4
+ export { VoidContext } from "./context";
5
+ export type { VoidPageState } from "./context";
6
+ export { Form } from "./form";
7
+ export type { FormProps } from "./form";
8
+ export type { FormFields } from "./form-state";
9
+ export { useNavigation, usePageErrors, useParams, useRouter, useShared, } from "./hooks";
10
+ export { Link } from "./link";
11
+ export type { LinkMethod, LinkProps, PrefetchStrategy } from "./link";
12
+ export { useForm } from "./use-form";
13
+ export type { FormSubmitOptions, PageForm, UseForm } from "./use-form";
14
+ export { useIslandForm } from "./use-island-form";
15
+ export type { IslandForm } from "./use-island-form";
16
+ export type { FieldErrors, FormValue, FormValues, JsonRecord, JsonValue, PageProps, PageValue, } from "./types";