@void/vue 0.21.9 → 0.23.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 +7 -1
- package/dist/{index-CD3rUeKP.d.mts → index-vAbysUNV.d.mts} +8 -17
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +2 -2
- package/dist/runtime/index.d.mts +2 -2
- package/dist/runtime/index.mjs +2 -2
- package/dist/{runtime-lFhMSoX1.mjs → runtime-DU7JTkNy.mjs} +48 -27
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ Main runtime APIs live at `@void/vue`:
|
|
|
36
36
|
- `useParams()`
|
|
37
37
|
- `useNavigation()`
|
|
38
38
|
- `useShared()`
|
|
39
|
-
- `useForm()`
|
|
39
|
+
- `Form` and `useForm()`
|
|
40
40
|
- `useIslandForm()`
|
|
41
41
|
- `action()`
|
|
42
42
|
|
|
@@ -114,6 +114,12 @@ Export `ssr = false` from a page's `.server.ts` file to skip server-rendered
|
|
|
114
114
|
component HTML for that route while still running its loader on the first
|
|
115
115
|
request.
|
|
116
116
|
|
|
117
|
+
## Form
|
|
118
|
+
|
|
119
|
+
Use `Form` with `useForm()` to display action and validation errors automatically. It preserves controlled input after a failed submission and announces errors accessibly. Structured usage-limit responses display the application's message and an optional retry time. Submissions are blocked while pending and before that deadline; inputs remain editable and requests are never retried automatically.
|
|
120
|
+
|
|
121
|
+
`method` selects `post` (the default), `put`, `patch`, or `delete`. Use `renderError` to customize action-error presentation (a snippet in Svelte). Native forms remain available when you manage error presentation yourself.
|
|
122
|
+
|
|
117
123
|
## Tests
|
|
118
124
|
|
|
119
125
|
Shared prefetch-cache tests live in `packages/void/test/unit/prefetch.test.ts`.
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { ActionClient, NavigationState, VisitOptions, VoidActionError, VoidRouter } from "void/pages-client";
|
|
1
2
|
import { Component } from "vue";
|
|
2
|
-
import { ActionResult, NavigationState, VisitOptions, VoidActionError, VoidRouter } from "void/pages-client";
|
|
3
3
|
import { CloudContextVariables, DeferredState as Deferred, InferProps } from "void";
|
|
4
|
-
import { ActionFormOptions, ActionUrl, ResolveActionBody
|
|
4
|
+
import { ActionFormOptions, ActionUrl, ResolveActionBody } from "void/routes";
|
|
5
|
+
//#region src/runtime/form.d.ts
|
|
6
|
+
declare const Form: Component;
|
|
7
|
+
//#endregion
|
|
5
8
|
//#region src/runtime/link.d.ts
|
|
6
9
|
declare const Link: Component;
|
|
7
10
|
//#endregion
|
|
@@ -63,19 +66,7 @@ type IslandFormReturn<T extends Record<string, unknown>> = Readonly<{
|
|
|
63
66
|
declare function useIslandForm<T extends Record<string, unknown>>(defaults: T): IslandFormReturn<T>;
|
|
64
67
|
//#endregion
|
|
65
68
|
//#region src/runtime/action.d.ts
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
type ActionOptions<U extends string> = {
|
|
69
|
-
data?: ResolveActionBody<U>;
|
|
70
|
-
method?: ActionMethod;
|
|
71
|
-
} & (HasParams<U> extends true ? {
|
|
72
|
-
params: ResolveActionParams<U>;
|
|
73
|
-
} : {
|
|
74
|
-
params?: never;
|
|
75
|
-
});
|
|
76
|
-
/** Called during app initialization to store the router instance */
|
|
77
|
-
declare function setActionRouter(router: VoidRouter): void;
|
|
78
|
-
/** Programmatic one-shot page action call with Inertia page update */
|
|
79
|
-
declare function action<U extends ActionUrl & string>(url: U, ...args: HasParams<U> extends true ? [options: ActionOptions<U>] : [options?: ActionOptions<U>]): Promise<ActionResult>;
|
|
69
|
+
declare const action: ActionClient["action"];
|
|
70
|
+
declare const setActionRouter: ActionClient["setActionRouter"];
|
|
80
71
|
//#endregion
|
|
81
|
-
export { useIslandForm as a, useShared as c, Link as d, setActionRouter as i, useParams as l, InferProps as n, useNavigation as o, action as r, useForm as s, Deferred as t, useRouter as u };
|
|
72
|
+
export { useIslandForm as a, useShared as c, Link as d, Form as f, setActionRouter as i, useParams as l, InferProps as n, useNavigation as o, action as r, useForm as s, Deferred as t, useRouter as u };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as useIslandForm, c as useShared, d as Link, i as setActionRouter, l as useParams, n as InferProps, o as useNavigation, r as action, s as useForm, t as Deferred, u as useRouter } from "./index-
|
|
2
|
-
export { type Deferred, type InferProps, Link, action, setActionRouter, useForm, useIslandForm, useNavigation, useParams, useRouter, useShared };
|
|
1
|
+
import { a as useIslandForm, c as useShared, d as Link, f as Form, i as setActionRouter, l as useParams, n as InferProps, o as useNavigation, r as action, s as useForm, t as Deferred, u as useRouter } from "./index-vAbysUNV.mjs";
|
|
2
|
+
export { type Deferred, Form, type InferProps, Link, action, setActionRouter, useForm, useIslandForm, useNavigation, useParams, useRouter, useShared };
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as useForm, c as useRouter, i as useNavigation, l as Link, n as setActionRouter, o as useShared, r as useIslandForm, s as useParams, t as action } from "./runtime-
|
|
2
|
-
export { Link, action, setActionRouter, useForm, useIslandForm, useNavigation, useParams, useRouter, useShared };
|
|
1
|
+
import { a as useForm, c as useRouter, i as useNavigation, l as Link, n as setActionRouter, o as useShared, r as useIslandForm, s as useParams, t as action, u as Form } from "./runtime-DU7JTkNy.mjs";
|
|
2
|
+
export { Form, Link, action, setActionRouter, useForm, useIslandForm, useNavigation, useParams, useRouter, useShared };
|
package/dist/runtime/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as useIslandForm, c as useShared, d as Link, i as setActionRouter, l as useParams, n as InferProps, o as useNavigation, r as action, s as useForm, t as Deferred, u as useRouter } from "../index-
|
|
2
|
-
export { type Deferred, type InferProps, Link, action, setActionRouter, useForm, useIslandForm, useNavigation, useParams, useRouter, useShared };
|
|
1
|
+
import { a as useIslandForm, c as useShared, d as Link, f as Form, i as setActionRouter, l as useParams, n as InferProps, o as useNavigation, r as action, s as useForm, t as Deferred, u as useRouter } from "../index-vAbysUNV.mjs";
|
|
2
|
+
export { type Deferred, Form, type InferProps, Link, action, setActionRouter, useForm, useIslandForm, useNavigation, useParams, useRouter, useShared };
|
package/dist/runtime/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as useForm, c as useRouter, i as useNavigation, l as Link, n as setActionRouter, o as useShared, r as useIslandForm, s as useParams, t as action } from "../runtime-
|
|
2
|
-
export { Link, action, setActionRouter, useForm, useIslandForm, useNavigation, useParams, useRouter, useShared };
|
|
1
|
+
import { a as useForm, c as useRouter, i as useNavigation, l as Link, n as setActionRouter, o as useShared, r as useIslandForm, s as useParams, t as action, u as Form } from "../runtime-DU7JTkNy.mjs";
|
|
2
|
+
export { Form, Link, action, setActionRouter, useForm, useIslandForm, useNavigation, useParams, useRouter, useShared };
|
|
@@ -1,5 +1,48 @@
|
|
|
1
|
+
import { VoidActionError, categorizeActionError, createActionClient, formErrorMessage, formRetryMessage, formSubmissionBlocked, idleNavigationState, isAbortError, isEqualFormValue, scheduleFormRetry, ssrProxy, submitAction } from "void/pages-client";
|
|
1
2
|
import { computed, defineComponent, h, inject, onMounted, onUnmounted, reactive, ref, watch } from "vue";
|
|
2
|
-
|
|
3
|
+
//#region src/runtime/form.ts
|
|
4
|
+
const Form = defineComponent({
|
|
5
|
+
name: "VoidForm",
|
|
6
|
+
inheritAttrs: false,
|
|
7
|
+
props: {
|
|
8
|
+
form: {
|
|
9
|
+
type: Object,
|
|
10
|
+
required: true
|
|
11
|
+
},
|
|
12
|
+
method: {
|
|
13
|
+
type: String,
|
|
14
|
+
default: "post"
|
|
15
|
+
},
|
|
16
|
+
renderError: Function
|
|
17
|
+
},
|
|
18
|
+
setup(props, { attrs, slots }) {
|
|
19
|
+
const now = ref(Date.now());
|
|
20
|
+
let cancel = () => {};
|
|
21
|
+
onMounted(() => watch(() => props.form.error, (error) => {
|
|
22
|
+
cancel();
|
|
23
|
+
cancel = scheduleFormRetry(error, () => {
|
|
24
|
+
now.value = Date.now();
|
|
25
|
+
});
|
|
26
|
+
}, { immediate: true }));
|
|
27
|
+
onUnmounted(() => cancel());
|
|
28
|
+
return () => {
|
|
29
|
+
const form = props.form;
|
|
30
|
+
const message = formErrorMessage(form), retry = formRetryMessage(form.error);
|
|
31
|
+
return h("form", {
|
|
32
|
+
...attrs,
|
|
33
|
+
"aria-busy": form.pending,
|
|
34
|
+
onSubmit: async (event) => {
|
|
35
|
+
event.preventDefault();
|
|
36
|
+
if (!formSubmissionBlocked(form, now.value)) await form[props.method]();
|
|
37
|
+
}
|
|
38
|
+
}, [message ? h("div", {
|
|
39
|
+
role: "alert",
|
|
40
|
+
"data-void-form-error": ""
|
|
41
|
+
}, [form.error && props.renderError ? props.renderError(form.error) : message, retry ? h("p", retry) : null]) : null, slots.default?.()]);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
//#endregion
|
|
3
46
|
//#region src/runtime/link.ts
|
|
4
47
|
function appendQueryValue(params, key, value) {
|
|
5
48
|
if (value === null || value === void 0) return false;
|
|
@@ -440,30 +483,8 @@ function useIslandForm(defaults) {
|
|
|
440
483
|
}
|
|
441
484
|
//#endregion
|
|
442
485
|
//#region src/runtime/action.ts
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
_router = router;
|
|
447
|
-
}
|
|
448
|
-
/** Programmatic one-shot page action call with Inertia page update */
|
|
449
|
-
async function action(url, ...args) {
|
|
450
|
-
if (!_router) throw new Error("action(): called before router initialization.");
|
|
451
|
-
const options = args[0];
|
|
452
|
-
const data = options?.data;
|
|
453
|
-
const method = options?.method || "POST";
|
|
454
|
-
let resolvedUrl = url;
|
|
455
|
-
let actionQuery = "";
|
|
456
|
-
const qIdx = resolvedUrl.indexOf("?");
|
|
457
|
-
if (qIdx !== -1) {
|
|
458
|
-
actionQuery = resolvedUrl.slice(qIdx);
|
|
459
|
-
resolvedUrl = resolvedUrl.slice(0, qIdx);
|
|
460
|
-
}
|
|
461
|
-
if (options?.params) for (const [key, value] of Object.entries(options.params)) resolvedUrl = resolvedUrl.replace(`:${key}`, encodeURIComponent(value));
|
|
462
|
-
resolvedUrl = resolvedUrl + actionQuery;
|
|
463
|
-
return submitAction(_router, resolvedUrl, {
|
|
464
|
-
method,
|
|
465
|
-
data
|
|
466
|
-
});
|
|
467
|
-
}
|
|
486
|
+
const client = createActionClient();
|
|
487
|
+
const action = client.action;
|
|
488
|
+
const setActionRouter = client.setActionRouter;
|
|
468
489
|
//#endregion
|
|
469
|
-
export { useForm as a, useRouter as c, useNavigation as i, Link as l, setActionRouter as n, useShared as o, useIslandForm as r, useParams as s, action as t };
|
|
490
|
+
export { useForm as a, useRouter as c, useNavigation as i, Link as l, setActionRouter as n, useShared as o, useIslandForm as r, useParams as s, action as t, Form as u };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@void/vue",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/voidzero-dev/void.git",
|
|
@@ -28,19 +28,19 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
31
|
+
"@vitejs/plugin-vue": "^6.0.9"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"@types/node": "^26.
|
|
34
|
+
"@types/node": "^26.6.3",
|
|
35
35
|
"pathslash": "^0.1.0",
|
|
36
|
-
"vite": "npm:@voidzero-dev/vite-plus-core@0.
|
|
37
|
-
"vite-plus": "0.
|
|
38
|
-
"void": "0.
|
|
39
|
-
"vue": "^3.5.
|
|
36
|
+
"vite": "npm:@voidzero-dev/vite-plus-core@1.0.0",
|
|
37
|
+
"vite-plus": "1.0.0",
|
|
38
|
+
"void": "0.23.0",
|
|
39
|
+
"vue": "^3.5.43"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"vite": "^8.0.0",
|
|
43
|
-
"void": "0.
|
|
43
|
+
"void": "0.23.0",
|
|
44
44
|
"vue": "^3.5.0"
|
|
45
45
|
},
|
|
46
46
|
"scripts": {
|