@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 +21 -0
- package/README.md +62 -2
- package/dist/action-hKFilV-5.js +10 -0
- package/dist/action.d.ts +4 -0
- package/dist/app-C92pEfKv.js +50 -0
- package/dist/app.d.ts +56 -0
- package/dist/client.d.ts +11 -0
- package/dist/client.js +146 -0
- package/dist/context-fQy_XW7o.js +13 -0
- package/dist/context.d.ts +19 -0
- package/dist/form-state.d.ts +33 -0
- package/dist/form.d.ts +18 -0
- package/dist/hooks.d.ts +12 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +342 -0
- package/dist/islands.d.ts +11 -0
- package/dist/islands.js +15 -0
- package/dist/link.d.ts +41 -0
- package/dist/plugin-islands.d.ts +27 -0
- package/dist/plugin-pages.d.ts +22 -0
- package/dist/plugin.d.ts +14 -0
- package/dist/plugin.js +393 -0
- package/dist/server.d.ts +38 -0
- package/dist/server.js +95 -0
- package/dist/types.d.ts +22 -0
- package/dist/use-form.d.ts +27 -0
- package/dist/use-island-form.d.ts +14 -0
- package/package.json +70 -4
package/dist/index.js
ADDED
|
@@ -0,0 +1,342 @@
|
|
|
1
|
+
import { n as setActionRouter, t as action } from "./action-hKFilV-5.js";
|
|
2
|
+
import { t as VoidContext } from "./context-fQy_XW7o.js";
|
|
3
|
+
import { VoidActionError, categorizeActionError, formErrorMessage, formRetryMessage, formSubmissionBlocked, getValidationErrors, idleNavigationState, interpolateRouteParams, isAbortError, isEqualFormValue, isModifiedEvent, mergeDataIntoHref, scheduleFormRetry, ssrProxy, submitAction } from "void/pages-client";
|
|
4
|
+
import { atom, batch, context, h, watch } from "ilha";
|
|
5
|
+
|
|
6
|
+
//#region src/form.ts
|
|
7
|
+
/**
|
|
8
|
+
* Submit `form` on `submit`, show its error, and block resubmits while a
|
|
9
|
+
* rate-limit retry window is open.
|
|
10
|
+
*/
|
|
11
|
+
const Form = ({ children, form, method = "post", renderError, ...attributes }) => {
|
|
12
|
+
const now = atom(Date.now(), { snapshot: false });
|
|
13
|
+
const { error } = form;
|
|
14
|
+
watch.once(() => globalThis.window === void 0 ? void 0 : scheduleFormRetry(error, () => now.set(Date.now())));
|
|
15
|
+
const message = formErrorMessage(form);
|
|
16
|
+
const retry = formRetryMessage(error);
|
|
17
|
+
return h("form", {
|
|
18
|
+
...attributes,
|
|
19
|
+
"aria-busy": String(form.pending),
|
|
20
|
+
onsubmit: async (event) => {
|
|
21
|
+
event.preventDefault();
|
|
22
|
+
now.set(Date.now());
|
|
23
|
+
if (!formSubmissionBlocked(form, now())) await form[method]();
|
|
24
|
+
}
|
|
25
|
+
}, message ? h("div", {
|
|
26
|
+
"data-void-form-error": "",
|
|
27
|
+
role: "alert"
|
|
28
|
+
}, error && renderError ? renderError(error) : message, retry ? h("p", null, retry) : null) : null, children);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/hooks.ts
|
|
33
|
+
const readPage = (hook) => {
|
|
34
|
+
const page = context(VoidContext)();
|
|
35
|
+
if (!page) throw new Error(`${hook}: must be used inside a Void page.`);
|
|
36
|
+
return page;
|
|
37
|
+
};
|
|
38
|
+
/** The Void Router. Outside a hydrated regular page it is a server-safe stub. */
|
|
39
|
+
const useRouter = () => context(VoidContext)()?.router ?? ssrProxy;
|
|
40
|
+
/** Route params of the current page. Rerenders the component when they change. */
|
|
41
|
+
const useParams = () => readPage("useParams()").params;
|
|
42
|
+
/** Values the app's middleware shares with every page. */
|
|
43
|
+
const useShared = () => readPage("useShared()").shared;
|
|
44
|
+
/** Pending navigation state. Idle on island pages and during SSR. */
|
|
45
|
+
const useNavigation = () => context(VoidContext)()?.navigation ?? idleNavigationState();
|
|
46
|
+
/** Validation errors the last page action returned. */
|
|
47
|
+
const usePageErrors = () => context(VoidContext)()?.errors ?? {};
|
|
48
|
+
|
|
49
|
+
//#endregion
|
|
50
|
+
//#region src/link.ts
|
|
51
|
+
const DEFAULT_HOVER_DELAY = 75;
|
|
52
|
+
const isStrategyList = (prefetch) => Array.isArray(prefetch);
|
|
53
|
+
const strategiesOf = ({ prefetch, reloadDocument }) => {
|
|
54
|
+
if (prefetch === void 0 || prefetch === false || reloadDocument) return [];
|
|
55
|
+
if (prefetch === true) return ["hover"];
|
|
56
|
+
return isStrategyList(prefetch) ? prefetch : [prefetch];
|
|
57
|
+
};
|
|
58
|
+
const isSameOrigin = (href) => new URL(href, window.location.origin).origin === window.location.origin;
|
|
59
|
+
const unlessPrevented = (handler, then) => (event) => {
|
|
60
|
+
handler?.(event);
|
|
61
|
+
if (!event.defaultPrevented) then();
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Navigate through the Void Router. GET links render an `<a>`; other methods
|
|
65
|
+
* render a `<button>` that submits `data`. Outside a regular page (island
|
|
66
|
+
* pages, SSR) clicks fall back to the browser.
|
|
67
|
+
*/
|
|
68
|
+
const Link = (props) => {
|
|
69
|
+
const { cacheFor, children, data, href, method = "GET", onNavigate, onclick, onfocus, onmousedown, onmouseenter, onmouseleave, ontouchstart, prefetch: _prefetch, preserveScroll, preserveState, reloadDocument, replace, viewTransition, ...attributes } = props;
|
|
70
|
+
const router = context(VoidContext)()?.router ?? null;
|
|
71
|
+
const verb = method.toUpperCase();
|
|
72
|
+
const isGet = verb === "GET";
|
|
73
|
+
const strategies = strategiesOf(props);
|
|
74
|
+
if (strategies.length > 0 && !isGet) throw new Error("Link: prefetch only supports GET links. Remove `prefetch` or use method=\"GET\".");
|
|
75
|
+
if (reloadDocument && !isGet) throw new Error("Link: reloadDocument only supports GET links.");
|
|
76
|
+
const target = isGet ? mergeDataIntoHref(href, data) : href;
|
|
77
|
+
const timers = atom.lazy(() => ({}), { snapshot: false });
|
|
78
|
+
const runPrefetch = () => {
|
|
79
|
+
if (router && target !== window.location.pathname + window.location.search) router.prefetch(target, cacheFor === void 0 ? {} : { cacheFor });
|
|
80
|
+
};
|
|
81
|
+
watch.once(() => {
|
|
82
|
+
if (globalThis.window !== void 0 && strategies.includes("mount")) runPrefetch();
|
|
83
|
+
return () => {
|
|
84
|
+
clearTimeout(timers().hover);
|
|
85
|
+
timers().observer?.disconnect();
|
|
86
|
+
};
|
|
87
|
+
});
|
|
88
|
+
const handleClick = (event) => {
|
|
89
|
+
onclick?.(event);
|
|
90
|
+
if (reloadDocument || !router || event.defaultPrevented || isModifiedEvent(event) || event.currentTarget instanceof Element && event.currentTarget.hasAttribute("download") || !isSameOrigin(target)) return;
|
|
91
|
+
event.preventDefault();
|
|
92
|
+
let cancelled = false;
|
|
93
|
+
onNavigate?.({ preventDefault: () => {
|
|
94
|
+
cancelled = true;
|
|
95
|
+
} });
|
|
96
|
+
if (cancelled) return;
|
|
97
|
+
router.visit(target, {
|
|
98
|
+
data: isGet ? void 0 : data,
|
|
99
|
+
method: verb,
|
|
100
|
+
preserveScroll,
|
|
101
|
+
preserveState,
|
|
102
|
+
replace,
|
|
103
|
+
viewTransition
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
const hover = strategies.includes("hover");
|
|
107
|
+
const click = strategies.includes("click");
|
|
108
|
+
const handlers = {
|
|
109
|
+
onclick: handleClick,
|
|
110
|
+
onfocus: hover ? unlessPrevented(onfocus, runPrefetch) : onfocus,
|
|
111
|
+
onmousedown: click ? unlessPrevented(onmousedown, runPrefetch) : onmousedown,
|
|
112
|
+
onmouseenter: hover ? unlessPrevented(onmouseenter, () => {
|
|
113
|
+
clearTimeout(timers().hover);
|
|
114
|
+
timers().hover = setTimeout(runPrefetch, router?._hoverDelay ?? DEFAULT_HOVER_DELAY);
|
|
115
|
+
}) : onmouseenter,
|
|
116
|
+
onmouseleave: hover ? (event) => {
|
|
117
|
+
onmouseleave?.(event);
|
|
118
|
+
clearTimeout(timers().hover);
|
|
119
|
+
} : onmouseleave,
|
|
120
|
+
ontouchstart: hover || click ? unlessPrevented(ontouchstart, runPrefetch) : ontouchstart
|
|
121
|
+
};
|
|
122
|
+
const ref = strategies.includes("visible") ? (el) => {
|
|
123
|
+
timers().observer?.disconnect();
|
|
124
|
+
timers().observer = void 0;
|
|
125
|
+
if (!el) return;
|
|
126
|
+
const observer = new IntersectionObserver((entries) => {
|
|
127
|
+
if (entries.some((entry) => entry.isIntersecting)) {
|
|
128
|
+
observer.disconnect();
|
|
129
|
+
runPrefetch();
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
observer.observe(el);
|
|
133
|
+
timers().observer = observer;
|
|
134
|
+
} : void 0;
|
|
135
|
+
if (isGet) return h("a", {
|
|
136
|
+
...attributes,
|
|
137
|
+
href: target,
|
|
138
|
+
ref,
|
|
139
|
+
...handlers
|
|
140
|
+
}, children);
|
|
141
|
+
return h("button", {
|
|
142
|
+
type: "button",
|
|
143
|
+
...attributes,
|
|
144
|
+
ref,
|
|
145
|
+
...handlers
|
|
146
|
+
}, children);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
//#endregion
|
|
150
|
+
//#region src/form-state.ts
|
|
151
|
+
const RECENT_SUCCESS_MS = 2e3;
|
|
152
|
+
const without = (errors, fields) => Object.fromEntries(Object.entries(errors).filter(([field]) => !fields.includes(field)));
|
|
153
|
+
/**
|
|
154
|
+
* Declare the atoms behind a form helper. Call it at the top level of a
|
|
155
|
+
* component, like any other primitive.
|
|
156
|
+
*/
|
|
157
|
+
const formState = (defaults, globalErrors = () => ({})) => {
|
|
158
|
+
const data = atom({ ...defaults });
|
|
159
|
+
const baseline = atom({ ...defaults });
|
|
160
|
+
const errors = atom({});
|
|
161
|
+
const error = atom(null);
|
|
162
|
+
const pending = atom(false);
|
|
163
|
+
const wasSuccessful = atom(false);
|
|
164
|
+
const recentlySuccessful = atom(false);
|
|
165
|
+
const timer = atom.lazy(() => ({}), { snapshot: false });
|
|
166
|
+
watch.once(() => () => clearTimeout(timer().current));
|
|
167
|
+
return {
|
|
168
|
+
begin: () => {
|
|
169
|
+
clearTimeout(timer().current);
|
|
170
|
+
batch(() => {
|
|
171
|
+
pending.set(true);
|
|
172
|
+
wasSuccessful.set(false);
|
|
173
|
+
recentlySuccessful.set(false);
|
|
174
|
+
errors.set({});
|
|
175
|
+
error.set(null);
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
fail: (next) => error.set(next),
|
|
179
|
+
fields: {
|
|
180
|
+
clearError: () => error.set(null),
|
|
181
|
+
clearErrors: (...names) => errors.update((current) => names.length === 0 ? {} : without(current, names)),
|
|
182
|
+
get data() {
|
|
183
|
+
return data();
|
|
184
|
+
},
|
|
185
|
+
get error() {
|
|
186
|
+
return error();
|
|
187
|
+
},
|
|
188
|
+
get errors() {
|
|
189
|
+
const local = errors();
|
|
190
|
+
return Object.keys(local).length > 0 ? local : globalErrors();
|
|
191
|
+
},
|
|
192
|
+
get hasChanges() {
|
|
193
|
+
const current = data();
|
|
194
|
+
const base = baseline();
|
|
195
|
+
return Object.keys(base).some((key) => !isEqualFormValue(current[key], base[key]));
|
|
196
|
+
},
|
|
197
|
+
get pending() {
|
|
198
|
+
return pending();
|
|
199
|
+
},
|
|
200
|
+
get recentlySuccessful() {
|
|
201
|
+
return recentlySuccessful();
|
|
202
|
+
},
|
|
203
|
+
reset: (...names) => {
|
|
204
|
+
const base = baseline();
|
|
205
|
+
if (names.length === 0) {
|
|
206
|
+
data.set({ ...base });
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
data.update((current) => {
|
|
210
|
+
const next = { ...current };
|
|
211
|
+
for (const name of names) next[name] = base[name];
|
|
212
|
+
return next;
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
setData: (field, value) => {
|
|
216
|
+
data.update((current) => ({
|
|
217
|
+
...current,
|
|
218
|
+
[field]: value
|
|
219
|
+
}));
|
|
220
|
+
},
|
|
221
|
+
get wasSuccessful() {
|
|
222
|
+
return wasSuccessful();
|
|
223
|
+
}
|
|
224
|
+
},
|
|
225
|
+
finish: () => pending.set(false),
|
|
226
|
+
read: () => ({ ...data() }),
|
|
227
|
+
setErrors: (next) => errors.set(next),
|
|
228
|
+
succeed: () => {
|
|
229
|
+
batch(() => {
|
|
230
|
+
wasSuccessful.set(true);
|
|
231
|
+
recentlySuccessful.set(true);
|
|
232
|
+
baseline.set({ ...data() });
|
|
233
|
+
});
|
|
234
|
+
timer().current = setTimeout(() => recentlySuccessful.set(false), RECENT_SUCCESS_MS);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
//#endregion
|
|
240
|
+
//#region src/use-form.ts
|
|
241
|
+
const createForm = (url, defaults, options) => {
|
|
242
|
+
const router = useRouter();
|
|
243
|
+
const pageErrors = usePageErrors();
|
|
244
|
+
const state = formState(defaults, () => pageErrors);
|
|
245
|
+
const submit = async (method, submitOptions = {}) => {
|
|
246
|
+
state.begin();
|
|
247
|
+
try {
|
|
248
|
+
const result = await submitAction(router, interpolateRouteParams(url, options?.params), {
|
|
249
|
+
data: state.read(),
|
|
250
|
+
method,
|
|
251
|
+
...submitOptions
|
|
252
|
+
});
|
|
253
|
+
if (result.ok) {
|
|
254
|
+
state.succeed();
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
const validationErrors = getValidationErrors(result.error.body);
|
|
258
|
+
if (validationErrors) state.setErrors(validationErrors);
|
|
259
|
+
else state.fail(result.error);
|
|
260
|
+
} catch (error) {
|
|
261
|
+
if (!isAbortError(error)) throw error;
|
|
262
|
+
} finally {
|
|
263
|
+
state.finish();
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
return Object.defineProperties(state.fields, {
|
|
267
|
+
delete: { value: (o) => submit("DELETE", o) },
|
|
268
|
+
patch: { value: (o) => submit("PATCH", o) },
|
|
269
|
+
post: { value: (o) => submit("POST", o) },
|
|
270
|
+
put: { value: (o) => submit("PUT", o) }
|
|
271
|
+
});
|
|
272
|
+
};
|
|
273
|
+
/**
|
|
274
|
+
* Bind form state to a page action. Submits through the Void Router, so a
|
|
275
|
+
* success refreshes page props without a full reload. Island pages use
|
|
276
|
+
* `useIslandForm()` instead.
|
|
277
|
+
*/
|
|
278
|
+
const useForm = createForm;
|
|
279
|
+
|
|
280
|
+
//#endregion
|
|
281
|
+
//#region src/use-island-form.ts
|
|
282
|
+
const UNPROCESSABLE = 422;
|
|
283
|
+
/** Read an action error body: JSON when the server sent JSON, else text. */
|
|
284
|
+
const readErrorBody = async (response) => {
|
|
285
|
+
try {
|
|
286
|
+
if (response.headers.get("content-type")?.includes("application/json")) return await response.json();
|
|
287
|
+
return await response.text() || null;
|
|
288
|
+
} catch {
|
|
289
|
+
return null;
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* Form state for island pages, which have no Void Router. Submits with
|
|
294
|
+
* `fetch()`, then reloads the page or follows the redirect.
|
|
295
|
+
*/
|
|
296
|
+
const useIslandForm = (defaults) => {
|
|
297
|
+
const state = formState(defaults);
|
|
298
|
+
const submit = async (url, method) => {
|
|
299
|
+
state.begin();
|
|
300
|
+
try {
|
|
301
|
+
const response = await fetch(url, {
|
|
302
|
+
body: JSON.stringify(state.read()),
|
|
303
|
+
headers: { "Content-Type": "application/json" },
|
|
304
|
+
method
|
|
305
|
+
});
|
|
306
|
+
if (response.redirected) {
|
|
307
|
+
window.location.href = response.url;
|
|
308
|
+
return;
|
|
309
|
+
}
|
|
310
|
+
if (response.ok) {
|
|
311
|
+
state.succeed();
|
|
312
|
+
window.location.reload();
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const body = await readErrorBody(response);
|
|
316
|
+
const validationErrors = response.status === UNPROCESSABLE ? getValidationErrors(body) : null;
|
|
317
|
+
if (validationErrors) {
|
|
318
|
+
state.setErrors(validationErrors);
|
|
319
|
+
return;
|
|
320
|
+
}
|
|
321
|
+
const error = new VoidActionError({
|
|
322
|
+
body,
|
|
323
|
+
status: response.status,
|
|
324
|
+
statusText: response.statusText,
|
|
325
|
+
url
|
|
326
|
+
});
|
|
327
|
+
if (categorizeActionError(response.status) === "boundary") throw error;
|
|
328
|
+
state.fail(error);
|
|
329
|
+
} finally {
|
|
330
|
+
state.finish();
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
return Object.defineProperties(state.fields, {
|
|
334
|
+
delete: { value: (url) => submit(url, "DELETE") },
|
|
335
|
+
patch: { value: (url) => submit(url, "PATCH") },
|
|
336
|
+
post: { value: (url) => submit(url, "POST") },
|
|
337
|
+
put: { value: (url) => submit(url, "PUT") }
|
|
338
|
+
});
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
//#endregion
|
|
342
|
+
export { Form, Link, VoidContext, action, setActionRouter, useForm, useIslandForm, useNavigation, usePageErrors, useParams, useRouter, useShared };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { View } from "ilha";
|
|
2
|
+
import type { JsonRecord } from "./types";
|
|
3
|
+
/** An island module: its default export is an ilha component. */
|
|
4
|
+
export interface IslandModule<P extends JsonRecord> {
|
|
5
|
+
readonly default: (props: P) => View;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Mount one island from its `data-island` marker. The islands client entry
|
|
9
|
+
* passes this to Void's `initIslands`, which applies the hydration strategy.
|
|
10
|
+
*/
|
|
11
|
+
export declare const mountIsland: <P extends JsonRecord>(el: HTMLElement, { default: Component }: IslandModule<P>, props: P) => void;
|
package/dist/islands.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { mount } from "ilha";
|
|
2
|
+
|
|
3
|
+
//#region src/islands.ts
|
|
4
|
+
/**
|
|
5
|
+
* Mount one island from its `data-island` marker. The islands client entry
|
|
6
|
+
* passes this to Void's `initIslands`, which applies the hydration strategy.
|
|
7
|
+
*/
|
|
8
|
+
const mountIsland = (el, { default: Component }, props) => {
|
|
9
|
+
const host = el.querySelector(":scope > [data-ilha]");
|
|
10
|
+
mount(host ?? el, () => Component(props), { hydrate: host !== null });
|
|
11
|
+
el.dataset.hydrated = "true";
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
//#endregion
|
|
15
|
+
export { mountIsland };
|
package/dist/link.d.ts
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { View } from "ilha";
|
|
2
|
+
import type { JSX } from "ilha/jsx-runtime";
|
|
3
|
+
import type { PrefetchOptions } from "void/pages-client";
|
|
4
|
+
import type { FormValues } from "./types";
|
|
5
|
+
export type PrefetchStrategy = "hover" | "click" | "mount" | "visible";
|
|
6
|
+
export type LinkMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
|
|
7
|
+
type Handler<E extends Event> = (event: E) => void;
|
|
8
|
+
interface LinkOptions {
|
|
9
|
+
href: string;
|
|
10
|
+
method?: LinkMethod | Lowercase<LinkMethod>;
|
|
11
|
+
/** Query params for GET links; the request body for other methods. */
|
|
12
|
+
data?: FormValues;
|
|
13
|
+
preserveScroll?: boolean;
|
|
14
|
+
preserveState?: boolean;
|
|
15
|
+
replace?: boolean;
|
|
16
|
+
/** Skip the Void Router and load the document. GET links only. */
|
|
17
|
+
reloadDocument?: boolean;
|
|
18
|
+
viewTransition?: boolean;
|
|
19
|
+
/** `true` prefetches on hover. GET links only. */
|
|
20
|
+
prefetch?: boolean | PrefetchStrategy | readonly PrefetchStrategy[];
|
|
21
|
+
cacheFor?: PrefetchOptions["cacheFor"];
|
|
22
|
+
onNavigate?: (event: {
|
|
23
|
+
preventDefault: () => void;
|
|
24
|
+
}) => void;
|
|
25
|
+
onclick?: Handler<MouseEvent>;
|
|
26
|
+
onmouseenter?: Handler<MouseEvent>;
|
|
27
|
+
onmouseleave?: Handler<MouseEvent>;
|
|
28
|
+
onmousedown?: Handler<MouseEvent>;
|
|
29
|
+
onfocus?: Handler<FocusEvent>;
|
|
30
|
+
ontouchstart?: Handler<TouchEvent>;
|
|
31
|
+
children?: View;
|
|
32
|
+
}
|
|
33
|
+
/** Link options plus `<a>` attributes, which pass through to the element. */
|
|
34
|
+
export type LinkProps = LinkOptions & Omit<JSX.IntrinsicElements["a"], keyof LinkOptions>;
|
|
35
|
+
/**
|
|
36
|
+
* Navigate through the Void Router. GET links render an `<a>`; other methods
|
|
37
|
+
* render a `<button>` that submits `data`. Outside a regular page (island
|
|
38
|
+
* pages, SSR) clicks fall back to the browser.
|
|
39
|
+
*/
|
|
40
|
+
export declare const Link: (props: LinkProps) => View;
|
|
41
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
import type { PageScanResult } from "void/pages";
|
|
3
|
+
import type { IslandEntry } from "void/pages-islands-plugin";
|
|
4
|
+
interface WrapperMeta {
|
|
5
|
+
src: string;
|
|
6
|
+
islandId: string;
|
|
7
|
+
hydrate: string;
|
|
8
|
+
}
|
|
9
|
+
export declare const generateWrapperModule: ({ hydrate, islandId, src, }: WrapperMeta) => string;
|
|
10
|
+
export interface IslandRendererOptions {
|
|
11
|
+
markdownScriptIds: ReadonlySet<string>;
|
|
12
|
+
pagesNeedingClientJS: ReadonlySet<string>;
|
|
13
|
+
}
|
|
14
|
+
export declare const generateIslandRendererModule: (scan: PageScanResult, pagesDir: string, { markdownScriptIds, pagesNeedingClientJS }: IslandRendererOptions) => string;
|
|
15
|
+
export interface IslandClientOptions {
|
|
16
|
+
/** Static CSS imports from island pages and layouts, as import lines. */
|
|
17
|
+
cssImports: readonly string[];
|
|
18
|
+
}
|
|
19
|
+
export declare const generateIslandClientEntry: (manifest: ReadonlyMap<string, IslandEntry>, { cssImports }: IslandClientOptions) => string;
|
|
20
|
+
/**
|
|
21
|
+
* Turn `with { island }` imports in `.island` pages into SSR wrappers and
|
|
22
|
+
* serve Void's island renderer and client entry.
|
|
23
|
+
*/
|
|
24
|
+
export declare const islandsPlugin: (pagesDir: string, { root }: {
|
|
25
|
+
root: string;
|
|
26
|
+
}) => Plugin;
|
|
27
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
import type { PageScanResult, StaticPageDataBuildOptions } from "void/pages";
|
|
3
|
+
export interface PrefetchConfig {
|
|
4
|
+
/** Milliseconds a pointer rests on a link before hover prefetch. Default: 75. */
|
|
5
|
+
hoverDelay?: number;
|
|
6
|
+
/** How long prefetched page data stays fresh. Default: `"30s"`. */
|
|
7
|
+
cacheFor?: number | string | [string, string];
|
|
8
|
+
}
|
|
9
|
+
export interface PagesPluginOptions {
|
|
10
|
+
root: string;
|
|
11
|
+
viewTransitions?: boolean;
|
|
12
|
+
prefetch?: PrefetchConfig;
|
|
13
|
+
}
|
|
14
|
+
export declare const generateRendererModule: (scan: PageScanResult, pagesDir: string) => string;
|
|
15
|
+
export interface ClientEntryOptions {
|
|
16
|
+
viewTransitions?: boolean;
|
|
17
|
+
prefetch?: PrefetchConfig;
|
|
18
|
+
staticPageData?: StaticPageDataBuildOptions;
|
|
19
|
+
}
|
|
20
|
+
export declare const generateClientEntry: (scan: PageScanResult, pagesDir: string, { prefetch, staticPageData, viewTransitions }: ClientEntryOptions) => string;
|
|
21
|
+
/** Serve Void's pages renderer and client entry for Ilha components. */
|
|
22
|
+
export declare const pagesPlugin: (pagesDir: string, options: PagesPluginOptions) => Plugin;
|
package/dist/plugin.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Plugin } from "vite";
|
|
2
|
+
import type { PrefetchConfig } from "./plugin-pages";
|
|
3
|
+
export type { PrefetchConfig } from "./plugin-pages";
|
|
4
|
+
export interface VoidIlhaOptions {
|
|
5
|
+
/** Wrap Void Router navigations in `document.startViewTransition`. */
|
|
6
|
+
viewTransitions?: boolean;
|
|
7
|
+
/** Defaults for `<Link prefetch>`. */
|
|
8
|
+
prefetch?: PrefetchConfig;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Render Void pages, layouts, and islands with ilha. Add it after
|
|
12
|
+
* `voidPlugin()` in your Vite config.
|
|
13
|
+
*/
|
|
14
|
+
export declare const voidIlha: (options?: VoidIlhaOptions) => Plugin[];
|