@ilokesto/form 1.0.0 → 1.0.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/README.ko.md +52 -18
- package/README.md +54 -18
- package/dist/CreateForm-hQ4cxAK-.js +1283 -0
- package/dist/{FormStateSummary-YyGT9nfY.js → FormStateSummary-gmEQdNXj.js} +54 -38
- package/dist/adapters/FormInput.d.ts +8 -0
- package/dist/adapters/FormStateSummary.d.ts +2 -0
- package/dist/adapters/dom/SubmitHandler.d.ts +9 -0
- package/dist/adapters/dom/index.d.ts +2 -0
- package/dist/core/form/CreateForm.d.ts +2 -2
- package/dist/core/index.d.ts +1 -1
- package/dist/core/state/FormStateInitializer.d.ts +1 -1
- package/dist/core/state/FormStateStore.d.ts +5 -4
- package/dist/core/state/FormStateWriter.d.ts +4 -3
- package/dist/core/types.d.ts +12 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -1243
- package/dist/react/index.d.ts +1 -1
- package/dist/react/index.js +57 -53
- package/dist/react/types.d.ts +10 -3
- package/dist/react/useForm.d.ts +2 -1
- package/dist/solid/index.js +39 -32
- package/dist/solid/types.d.ts +4 -1
- package/dist/solid/useForm.d.ts +2 -1
- package/dist/svelte/index.js +37 -33
- package/dist/svelte/types.d.ts +2 -1
- package/dist/svelte/useForm.d.ts +2 -1
- package/dist/vue/index.js +38 -31
- package/dist/vue/types.d.ts +4 -1
- package/dist/vue/useForm.d.ts +2 -1
- package/package.json +1 -1
package/dist/react/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { useForm } from './useForm.js';
|
|
2
|
-
export type { RegisterOptions, } from './types.js';
|
|
2
|
+
export type { ReactFormOptions, RegisterOptions, } from './types.js';
|
package/dist/react/index.js
CHANGED
|
@@ -1,83 +1,87 @@
|
|
|
1
|
-
import { useEffect as h, useSyncExternalStore as
|
|
2
|
-
import { c as
|
|
3
|
-
function
|
|
4
|
-
const
|
|
1
|
+
import { useEffect as h, useSyncExternalStore as y, useMemo as i, useCallback as R, useRef as S } from "react";
|
|
2
|
+
import { c as b, f as g, g as v, b as O, a as A, i as k, d as E } from "../FormStateSummary-gmEQdNXj.js";
|
|
3
|
+
function f(e, n, r, s) {
|
|
4
|
+
const t = b(e, n, () => r, s);
|
|
5
5
|
return {
|
|
6
|
-
name:
|
|
7
|
-
type:
|
|
8
|
-
value:
|
|
9
|
-
checked:
|
|
6
|
+
name: t.name,
|
|
7
|
+
type: t.type,
|
|
8
|
+
value: t.value,
|
|
9
|
+
checked: t.checked,
|
|
10
10
|
onChange: (c) => {
|
|
11
|
-
|
|
11
|
+
t.change(c.currentTarget);
|
|
12
12
|
},
|
|
13
13
|
onBlur: () => {
|
|
14
|
-
|
|
14
|
+
t.blur();
|
|
15
15
|
},
|
|
16
16
|
onFocus: () => {
|
|
17
|
-
|
|
17
|
+
t.focus();
|
|
18
18
|
}
|
|
19
19
|
};
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
const { name:
|
|
21
|
+
function N(e, n) {
|
|
22
|
+
const { name: r, schema: s, schemaOptions: t } = n;
|
|
23
23
|
h(() => {
|
|
24
|
-
if (
|
|
25
|
-
return e.registerFieldSchema(
|
|
26
|
-
}, [e,
|
|
24
|
+
if (s)
|
|
25
|
+
return e.registerFieldSchema(r, { schema: s, schemaOptions: t });
|
|
26
|
+
}, [e, r, s, t]);
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
const
|
|
28
|
+
function V(e, n) {
|
|
29
|
+
const r = n.map((s) => `${g(s.name)}:${s.schema ? "schema" : "none"}`).join("|");
|
|
30
30
|
h(() => {
|
|
31
|
-
const
|
|
31
|
+
const s = n.flatMap((t) => t.schema ? [e.registerFieldSchema(t.name, { schema: t.schema, schemaOptions: t.schemaOptions })] : []);
|
|
32
32
|
return () => {
|
|
33
|
-
|
|
33
|
+
s.forEach((t) => t());
|
|
34
34
|
};
|
|
35
|
-
}, [e,
|
|
35
|
+
}, [e, n, r]);
|
|
36
36
|
}
|
|
37
|
-
function
|
|
38
|
-
return
|
|
39
|
-
(
|
|
37
|
+
function F(e) {
|
|
38
|
+
return y(
|
|
39
|
+
(n) => e.subscribe(n),
|
|
40
40
|
() => e.getState(),
|
|
41
41
|
() => e.getState()
|
|
42
42
|
);
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
e.setValue(
|
|
48
|
-
}, [e,
|
|
44
|
+
function W(e, n) {
|
|
45
|
+
N(e, n);
|
|
46
|
+
const r = F(e), s = v(e, r, n.name), t = g(n.name), a = i(() => f(e, n, s, t), [e, n, s, t]), c = R((u) => {
|
|
47
|
+
e.setValue(n.name, u, { source: "program" });
|
|
48
|
+
}, [e, n.name]);
|
|
49
49
|
return i(() => ({
|
|
50
|
-
props:
|
|
51
|
-
value:
|
|
50
|
+
props: a,
|
|
51
|
+
value: s.value,
|
|
52
52
|
setValue: c,
|
|
53
|
-
errors: [...
|
|
54
|
-
dirty:
|
|
55
|
-
touched:
|
|
56
|
-
}), [
|
|
53
|
+
errors: [...s.errors],
|
|
54
|
+
dirty: s.dirty,
|
|
55
|
+
touched: s.touched
|
|
56
|
+
}), [s, a, c]);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
59
|
-
const
|
|
60
|
-
return i(() =>
|
|
58
|
+
function x(e) {
|
|
59
|
+
const n = F(e);
|
|
60
|
+
return i(() => O(n), [n]);
|
|
61
61
|
}
|
|
62
|
-
function
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
const
|
|
66
|
-
() =>
|
|
67
|
-
const
|
|
68
|
-
return
|
|
62
|
+
function B(e, n, ...r) {
|
|
63
|
+
const s = Array.isArray(n) || r.length > 0, t = C(n, r);
|
|
64
|
+
V(e, t);
|
|
65
|
+
const a = F(e), c = i(
|
|
66
|
+
() => t.map((u) => {
|
|
67
|
+
const m = v(e, a, u.name), l = g(u.name);
|
|
68
|
+
return f(e, u, m, l);
|
|
69
69
|
}),
|
|
70
|
-
[e,
|
|
70
|
+
[e, t, a]
|
|
71
71
|
);
|
|
72
|
-
return
|
|
72
|
+
return s ? c : c[0];
|
|
73
73
|
}
|
|
74
|
-
function
|
|
75
|
-
return Array.isArray(e) ? e :
|
|
74
|
+
function C(e, n) {
|
|
75
|
+
return Array.isArray(e) ? e : n.length > 0 ? [e, ...n] : [e];
|
|
76
76
|
}
|
|
77
|
-
function
|
|
78
|
-
const
|
|
79
|
-
|
|
77
|
+
function P(e) {
|
|
78
|
+
const n = S(void 0), r = S(void 0), s = k(e), t = s ? e : n.current ??= A(e), a = s ? void 0 : e.values, c = s ? void 0 : e.resetOptions;
|
|
79
|
+
h(() => {
|
|
80
|
+
a === void 0 || r.current === a || (r.current = a, t.reset(a, c));
|
|
81
|
+
}, [t, c, a]);
|
|
82
|
+
const u = ((o, ...d) => B(t, o, ...d)), m = ((o) => W(t, o)), l = () => x(t), p = ((o, d) => E(t, o, d));
|
|
83
|
+
return i(() => ({ form: t, useRegister: u, useField: m, useFormState: l, handleSubmit: p }), [t]);
|
|
80
84
|
}
|
|
81
85
|
export {
|
|
82
|
-
|
|
86
|
+
P as useForm
|
|
83
87
|
};
|
package/dist/react/types.d.ts
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import type { ChangeEventHandler, FocusEventHandler, InputHTMLAttributes, SelectHTMLAttributes, TextareaHTMLAttributes } from 'react';
|
|
2
|
-
import type { Form, FormError, FormState } from '../core/index.js';
|
|
3
|
-
import type { RegisterOptions } from '../adapters/dom.js';
|
|
1
|
+
import type { ChangeEventHandler, FocusEventHandler, InputHTMLAttributes, SelectHTMLAttributes, TextareaHTMLAttributes, FormEvent } from 'react';
|
|
2
|
+
import type { CreateFormOptions, Form, FormError, FormState, ResetOptions } from '../core/index.js';
|
|
3
|
+
import type { RegisterOptions, SubmitHandler, SubmitInvalidHandler, SubmitValidHandler } from '../adapters/dom.js';
|
|
4
4
|
export type { RegisterOptions } from '../adapters/dom.js';
|
|
5
|
+
export type ReactFormOptions<TValues> = CreateFormOptions<TValues> & {
|
|
6
|
+
values?: TValues;
|
|
7
|
+
resetOptions?: ResetOptions;
|
|
8
|
+
};
|
|
5
9
|
type InputValue = InputHTMLAttributes<HTMLInputElement>['value'];
|
|
6
10
|
type InputType = InputHTMLAttributes<HTMLInputElement>['type'];
|
|
7
11
|
type SelectValue = SelectHTMLAttributes<HTMLSelectElement>['value'];
|
|
@@ -49,6 +53,8 @@ export type UseFormStateReturn<TValues> = {
|
|
|
49
53
|
isDirty: boolean;
|
|
50
54
|
isValid: boolean;
|
|
51
55
|
isSubmitting: boolean;
|
|
56
|
+
isSubmitted: boolean;
|
|
57
|
+
isSubmitSuccessful: boolean;
|
|
52
58
|
submitCount: number;
|
|
53
59
|
};
|
|
54
60
|
export type RegisterPropsList<TElement extends RegisterElement, TOptions extends readonly RegisterOptions[]> = {
|
|
@@ -61,4 +67,5 @@ export type ReactForm<TValues> = {
|
|
|
61
67
|
useRegister<TElement extends RegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(...options: TOptions): RegisterPropsList<TElement, TOptions>;
|
|
62
68
|
useField<TElement extends RegisterElement = HTMLInputElement>(options: RegisterOptions): UseFieldReturn<RegisterPropsForElement<TElement>>;
|
|
63
69
|
useFormState(): UseFormStateReturn<TValues>;
|
|
70
|
+
handleSubmit<TResult>(onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler): SubmitHandler<FormEvent<HTMLFormElement>, TResult>;
|
|
64
71
|
};
|
package/dist/react/useForm.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { Form } from '../core/index.js';
|
|
2
|
-
import type { ReactForm } from './types.js';
|
|
2
|
+
import type { ReactForm, ReactFormOptions } from './types.js';
|
|
3
3
|
export declare function useForm<TValues>(form: Form<TValues>): ReactForm<TValues>;
|
|
4
|
+
export declare function useForm<TValues>(options: ReactFormOptions<TValues>): ReactForm<TValues>;
|
package/dist/solid/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { onCleanup as
|
|
3
|
-
function
|
|
4
|
-
const s =
|
|
1
|
+
import { c as h, f as o, g as m, b as S, i as F, a as p, d as b } from "../FormStateSummary-gmEQdNXj.js";
|
|
2
|
+
import { onCleanup as g, createSignal as y } from "solid-js";
|
|
3
|
+
function l(e, t, r, n) {
|
|
4
|
+
const s = h(e, t, r, n);
|
|
5
5
|
return {
|
|
6
6
|
name: s.name,
|
|
7
7
|
type: s.type,
|
|
@@ -11,11 +11,11 @@ function h(e, t, r, n) {
|
|
|
11
11
|
get checked() {
|
|
12
12
|
return s.checked;
|
|
13
13
|
},
|
|
14
|
-
onInput: (
|
|
15
|
-
s.input(
|
|
14
|
+
onInput: (u) => {
|
|
15
|
+
s.input(u.currentTarget);
|
|
16
16
|
},
|
|
17
|
-
onChange: (
|
|
18
|
-
s.change(
|
|
17
|
+
onChange: (u) => {
|
|
18
|
+
s.change(u.currentTarget);
|
|
19
19
|
},
|
|
20
20
|
onBlur: () => {
|
|
21
21
|
s.blur();
|
|
@@ -25,28 +25,28 @@ function h(e, t, r, n) {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function d(e, t) {
|
|
29
29
|
const r = t.flatMap((n) => n.schema ? [e.registerFieldSchema(n.name, { schema: n.schema, schemaOptions: n.schemaOptions })] : []);
|
|
30
|
-
r.length !== 0 &&
|
|
30
|
+
r.length !== 0 && g(() => {
|
|
31
31
|
r.forEach((n) => n());
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
function c(e) {
|
|
35
|
-
const [t, r] =
|
|
35
|
+
const [t, r] = y(e.getState(), { equals: !1 }), n = e.subscribe(() => {
|
|
36
36
|
r(e.getState());
|
|
37
37
|
});
|
|
38
|
-
return
|
|
38
|
+
return g(n), t;
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
const r = c(e), n = () =>
|
|
40
|
+
function f(e, t) {
|
|
41
|
+
d(e, [t]);
|
|
42
|
+
const r = c(e), n = () => m(e, r(), t.name);
|
|
43
43
|
return {
|
|
44
|
-
props:
|
|
44
|
+
props: l(e, t, n, o(t.name)),
|
|
45
45
|
get value() {
|
|
46
46
|
return n().value;
|
|
47
47
|
},
|
|
48
|
-
setValue(
|
|
49
|
-
e.setValue(t.name,
|
|
48
|
+
setValue(i) {
|
|
49
|
+
e.setValue(t.name, i, { source: "program" });
|
|
50
50
|
},
|
|
51
51
|
get errors() {
|
|
52
52
|
return [...n().errors];
|
|
@@ -59,8 +59,8 @@ function S(e, t) {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
function
|
|
63
|
-
const t = c(e), r = () =>
|
|
62
|
+
function R(e) {
|
|
63
|
+
const t = c(e), r = () => S(t());
|
|
64
64
|
return {
|
|
65
65
|
get state() {
|
|
66
66
|
return t();
|
|
@@ -83,28 +83,35 @@ function y(e) {
|
|
|
83
83
|
get isSubmitting() {
|
|
84
84
|
return r().isSubmitting;
|
|
85
85
|
},
|
|
86
|
+
get isSubmitted() {
|
|
87
|
+
return r().isSubmitted;
|
|
88
|
+
},
|
|
89
|
+
get isSubmitSuccessful() {
|
|
90
|
+
return r().isSubmitSuccessful;
|
|
91
|
+
},
|
|
86
92
|
get submitCount() {
|
|
87
93
|
return r().submitCount;
|
|
88
94
|
}
|
|
89
95
|
};
|
|
90
96
|
}
|
|
91
|
-
function
|
|
92
|
-
const n = Array.isArray(t) || r.length > 0, s =
|
|
93
|
-
|
|
94
|
-
const
|
|
97
|
+
function v(e, t, ...r) {
|
|
98
|
+
const n = Array.isArray(t) || r.length > 0, s = A(t, r);
|
|
99
|
+
d(e, s);
|
|
100
|
+
const i = c(e), u = s.map((a) => l(
|
|
95
101
|
e,
|
|
96
|
-
|
|
97
|
-
() =>
|
|
98
|
-
o(
|
|
102
|
+
a,
|
|
103
|
+
() => m(e, i(), a.name),
|
|
104
|
+
o(a.name)
|
|
99
105
|
));
|
|
100
|
-
return n ?
|
|
106
|
+
return n ? u : u[0];
|
|
101
107
|
}
|
|
102
|
-
function
|
|
108
|
+
function A(e, t) {
|
|
103
109
|
return Array.isArray(e) ? e : t.length > 0 ? [e, ...t] : [e];
|
|
104
110
|
}
|
|
105
|
-
function
|
|
106
|
-
|
|
111
|
+
function O(e) {
|
|
112
|
+
const t = F(e) ? e : p(e);
|
|
113
|
+
return { form: t, useRegister: ((u, ...a) => v(t, u, ...a)), useField: ((u) => f(t, u)), useFormState: () => R(t), handleSubmit: ((u, a) => b(t, u, a)) };
|
|
107
114
|
}
|
|
108
115
|
export {
|
|
109
|
-
|
|
116
|
+
O as useForm
|
|
110
117
|
};
|
package/dist/solid/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Form, FormError, FormState } from '../core/index.js';
|
|
2
|
-
import type { DomValue, RegisterOptions } from '../adapters/dom.js';
|
|
2
|
+
import type { DomValue, RegisterOptions, SubmitHandler, SubmitInvalidHandler, SubmitValidHandler } from '../adapters/dom.js';
|
|
3
3
|
export type { RegisterOptions } from '../adapters/dom.js';
|
|
4
4
|
type SolidBindingHandlers<TElement extends HTMLElement> = {
|
|
5
5
|
onInput: (event: InputEvent & {
|
|
@@ -56,6 +56,8 @@ export type SolidFormStateReturn<TValues> = {
|
|
|
56
56
|
readonly isDirty: boolean;
|
|
57
57
|
readonly isValid: boolean;
|
|
58
58
|
readonly isSubmitting: boolean;
|
|
59
|
+
readonly isSubmitted: boolean;
|
|
60
|
+
readonly isSubmitSuccessful: boolean;
|
|
59
61
|
readonly submitCount: number;
|
|
60
62
|
};
|
|
61
63
|
export type SolidForm<TValues> = {
|
|
@@ -65,4 +67,5 @@ export type SolidForm<TValues> = {
|
|
|
65
67
|
useRegister<TElement extends SolidRegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(...options: TOptions): SolidRegisterPropsList<TElement, TOptions>;
|
|
66
68
|
useField<TElement extends SolidRegisterElement = HTMLInputElement>(options: RegisterOptions): SolidFieldReturn<SolidRegisterPropsForElement<TElement>>;
|
|
67
69
|
useFormState(): SolidFormStateReturn<TValues>;
|
|
70
|
+
handleSubmit<TResult>(onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler): SubmitHandler<Event, TResult>;
|
|
68
71
|
};
|
package/dist/solid/useForm.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { Form } from '../core/index.js';
|
|
1
|
+
import type { CreateFormOptions, Form } from '../core/index.js';
|
|
2
2
|
import type { SolidForm } from './types.js';
|
|
3
3
|
export declare function useForm<TValues>(form: Form<TValues>): SolidForm<TValues>;
|
|
4
|
+
export declare function useForm<TValues>(options: CreateFormOptions<TValues>): SolidForm<TValues>;
|
package/dist/svelte/index.js
CHANGED
|
@@ -1,76 +1,76 @@
|
|
|
1
|
-
import { c as h, f as S, g, a as
|
|
2
|
-
import { readable as
|
|
3
|
-
function
|
|
1
|
+
import { c as h, f as S, g, b as i, i as E, a as F, d as L } from "../FormStateSummary-gmEQdNXj.js";
|
|
2
|
+
import { readable as A } from "svelte/store";
|
|
3
|
+
function B(e) {
|
|
4
4
|
return (t, r) => {
|
|
5
|
-
let a = r, n =
|
|
5
|
+
let a = r, n = p(e, a);
|
|
6
6
|
const u = () => h(
|
|
7
7
|
e,
|
|
8
|
-
|
|
8
|
+
T(t, a),
|
|
9
9
|
() => g(e, e.getState(), a.name),
|
|
10
10
|
S(a.name)
|
|
11
|
-
),
|
|
12
|
-
|
|
11
|
+
), s = () => {
|
|
12
|
+
k(t, u(), a);
|
|
13
13
|
}, m = (c) => {
|
|
14
14
|
u().input(c.currentTarget);
|
|
15
|
-
},
|
|
15
|
+
}, o = (c) => {
|
|
16
16
|
u().change(c.currentTarget);
|
|
17
|
-
},
|
|
17
|
+
}, v = () => {
|
|
18
18
|
u().blur();
|
|
19
19
|
}, f = () => {
|
|
20
20
|
u().focus();
|
|
21
21
|
};
|
|
22
|
-
t.addEventListener("input", m), t.addEventListener("change",
|
|
23
|
-
const y = e.subscribe(
|
|
24
|
-
return
|
|
22
|
+
t.addEventListener("input", m), t.addEventListener("change", o), t.addEventListener("blur", v), t.addEventListener("focus", f);
|
|
23
|
+
const y = e.subscribe(s);
|
|
24
|
+
return s(), {
|
|
25
25
|
update(c) {
|
|
26
|
-
n(), a = c, n =
|
|
26
|
+
n(), a = c, n = p(e, a), s();
|
|
27
27
|
},
|
|
28
28
|
destroy() {
|
|
29
|
-
y(), n(), t.removeEventListener("input", m), t.removeEventListener("change",
|
|
29
|
+
y(), n(), t.removeEventListener("input", m), t.removeEventListener("change", o), t.removeEventListener("blur", v), t.removeEventListener("focus", f);
|
|
30
30
|
}
|
|
31
31
|
};
|
|
32
32
|
};
|
|
33
33
|
}
|
|
34
|
-
function
|
|
34
|
+
function p(e, t) {
|
|
35
35
|
return t.schema ? e.registerFieldSchema(t.name, { schema: t.schema, schemaOptions: t.schemaOptions }) : () => {
|
|
36
36
|
};
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function T(e, t) {
|
|
39
39
|
return t.type !== void 0 || !(e instanceof HTMLInputElement) ? t : {
|
|
40
40
|
...t,
|
|
41
41
|
type: e.type || "text"
|
|
42
42
|
};
|
|
43
43
|
}
|
|
44
|
-
function
|
|
45
|
-
if (
|
|
46
|
-
|
|
44
|
+
function k(e, t, r) {
|
|
45
|
+
if (N(e, t.name), e instanceof HTMLInputElement) {
|
|
46
|
+
b(e, t, r);
|
|
47
47
|
return;
|
|
48
48
|
}
|
|
49
49
|
if (e instanceof HTMLSelectElement) {
|
|
50
|
-
|
|
50
|
+
x(e, t);
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
if (e instanceof HTMLTextAreaElement) {
|
|
54
54
|
l(e, t.value);
|
|
55
55
|
return;
|
|
56
56
|
}
|
|
57
|
-
|
|
57
|
+
H(e, t);
|
|
58
58
|
}
|
|
59
|
-
function
|
|
59
|
+
function N(e, t) {
|
|
60
60
|
if ("name" in e) {
|
|
61
61
|
e.name = t;
|
|
62
62
|
return;
|
|
63
63
|
}
|
|
64
64
|
e.setAttribute("name", t);
|
|
65
65
|
}
|
|
66
|
-
function
|
|
66
|
+
function b(e, t, r) {
|
|
67
67
|
if (r.type !== void 0 && e.type !== r.type && (e.type = r.type), e.type === "checkbox" || e.type === "radio") {
|
|
68
68
|
t.value !== void 0 && (e.value = String(Array.isArray(t.value) ? t.value[0] : t.value)), e.checked = !!t.checked;
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
71
|
l(e, t.value);
|
|
72
72
|
}
|
|
73
|
-
function
|
|
73
|
+
function x(e, t) {
|
|
74
74
|
const r = t.value;
|
|
75
75
|
if (e.multiple) {
|
|
76
76
|
const a = new Set((Array.isArray(r) ? r : r === void 0 ? [] : [r]).map(String));
|
|
@@ -85,23 +85,27 @@ function l(e, t) {
|
|
|
85
85
|
const r = t === void 0 ? "" : String(Array.isArray(t) ? t[0] ?? "" : t);
|
|
86
86
|
e.value !== r && (e.value = r);
|
|
87
87
|
}
|
|
88
|
-
function
|
|
88
|
+
function H(e, t) {
|
|
89
89
|
"value" in e && (e.value = t.value), "checked" in e && (e.checked = !!t.checked);
|
|
90
90
|
}
|
|
91
|
-
function
|
|
92
|
-
return
|
|
93
|
-
t(
|
|
91
|
+
function I(e) {
|
|
92
|
+
return A(i(e.getState()), (t) => (t(i(e.getState())), e.subscribe(() => {
|
|
93
|
+
t(i(e.getState()));
|
|
94
94
|
})));
|
|
95
95
|
}
|
|
96
|
-
function
|
|
96
|
+
function C(e) {
|
|
97
|
+
const t = E(e) ? e : F(e);
|
|
97
98
|
return {
|
|
98
|
-
form:
|
|
99
|
-
register:
|
|
99
|
+
form: t,
|
|
100
|
+
register: B(t),
|
|
100
101
|
useFormState() {
|
|
101
|
-
return
|
|
102
|
+
return I(t);
|
|
103
|
+
},
|
|
104
|
+
handleSubmit(r, a) {
|
|
105
|
+
return L(t, r, a);
|
|
102
106
|
}
|
|
103
107
|
};
|
|
104
108
|
}
|
|
105
109
|
export {
|
|
106
|
-
|
|
110
|
+
C as useForm
|
|
107
111
|
};
|
package/dist/svelte/types.d.ts
CHANGED
|
@@ -2,11 +2,12 @@ import type { Action } from 'svelte/action';
|
|
|
2
2
|
import type { Readable } from 'svelte/store';
|
|
3
3
|
import type { Form } from '../core/index.js';
|
|
4
4
|
import type { FormStateSummary } from '../adapters/FormStateSummary.js';
|
|
5
|
-
import type { RegisterOptions } from '../adapters/dom.js';
|
|
5
|
+
import type { RegisterOptions, SubmitHandler, SubmitInvalidHandler, SubmitValidHandler } from '../adapters/dom.js';
|
|
6
6
|
export type { RegisterOptions } from '../adapters/dom.js';
|
|
7
7
|
export type SvelteRegisterAction = Action<HTMLElement, RegisterOptions>;
|
|
8
8
|
export type SvelteForm<TValues> = {
|
|
9
9
|
form: Form<TValues>;
|
|
10
10
|
register: SvelteRegisterAction;
|
|
11
11
|
useFormState(): Readable<FormStateSummary<TValues>>;
|
|
12
|
+
handleSubmit<TResult>(onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler): SubmitHandler<Event, TResult>;
|
|
12
13
|
};
|
package/dist/svelte/useForm.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { Form } from '../core/index.js';
|
|
1
|
+
import type { CreateFormOptions, Form } from '../core/index.js';
|
|
2
2
|
import type { SvelteForm } from './types.js';
|
|
3
3
|
export declare function useForm<TValues>(form: Form<TValues>): SvelteForm<TValues>;
|
|
4
|
+
export declare function useForm<TValues>(options: CreateFormOptions<TValues>): SvelteForm<TValues>;
|
package/dist/vue/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { c as
|
|
2
|
-
import { getCurrentScope as
|
|
3
|
-
function
|
|
4
|
-
const s =
|
|
1
|
+
import { c as S, f as o, g as m, b as F, i as p, a as b, d as y } from "../FormStateSummary-gmEQdNXj.js";
|
|
2
|
+
import { getCurrentScope as g, onScopeDispose as l, shallowRef as f } from "vue";
|
|
3
|
+
function d(e, t, r, n) {
|
|
4
|
+
const s = S(e, t, r, n);
|
|
5
5
|
return {
|
|
6
6
|
name: s.name,
|
|
7
7
|
type: s.type,
|
|
@@ -11,11 +11,11 @@ function m(e, t, r, n) {
|
|
|
11
11
|
get checked() {
|
|
12
12
|
return s.checked;
|
|
13
13
|
},
|
|
14
|
-
onInput: (
|
|
15
|
-
s.input(
|
|
14
|
+
onInput: (u) => {
|
|
15
|
+
s.input(u.currentTarget);
|
|
16
16
|
},
|
|
17
|
-
onChange: (
|
|
18
|
-
s.change(
|
|
17
|
+
onChange: (u) => {
|
|
18
|
+
s.change(u.currentTarget);
|
|
19
19
|
},
|
|
20
20
|
onBlur: () => {
|
|
21
21
|
s.blur();
|
|
@@ -25,28 +25,28 @@ function m(e, t, r, n) {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
function
|
|
28
|
+
function h(e, t) {
|
|
29
29
|
const r = t.flatMap((n) => n.schema ? [e.registerFieldSchema(n.name, { schema: n.schema, schemaOptions: n.schemaOptions })] : []);
|
|
30
|
-
r.length !== 0 &&
|
|
30
|
+
r.length !== 0 && g() && l(() => {
|
|
31
31
|
r.forEach((n) => n());
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
34
|
function c(e) {
|
|
35
|
-
const t =
|
|
35
|
+
const t = f(e.getState()), r = e.subscribe(() => {
|
|
36
36
|
t.value = e.getState();
|
|
37
37
|
});
|
|
38
|
-
return
|
|
38
|
+
return g() && l(r), t;
|
|
39
39
|
}
|
|
40
|
-
function
|
|
41
|
-
|
|
42
|
-
const r = c(e), n = () =>
|
|
40
|
+
function v(e, t) {
|
|
41
|
+
h(e, [t]);
|
|
42
|
+
const r = c(e), n = () => m(e, r.value, t.name);
|
|
43
43
|
return {
|
|
44
|
-
props:
|
|
44
|
+
props: d(e, t, n, o(t.name)),
|
|
45
45
|
get value() {
|
|
46
46
|
return n().value;
|
|
47
47
|
},
|
|
48
|
-
setValue(
|
|
49
|
-
e.setValue(t.name,
|
|
48
|
+
setValue(i) {
|
|
49
|
+
e.setValue(t.name, i, { source: "program" });
|
|
50
50
|
},
|
|
51
51
|
get errors() {
|
|
52
52
|
return [...n().errors];
|
|
@@ -59,7 +59,7 @@ function y(e, t) {
|
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
61
|
}
|
|
62
|
-
function
|
|
62
|
+
function R(e) {
|
|
63
63
|
const t = c(e), r = () => F(t.value);
|
|
64
64
|
return {
|
|
65
65
|
get state() {
|
|
@@ -83,28 +83,35 @@ function b(e) {
|
|
|
83
83
|
get isSubmitting() {
|
|
84
84
|
return r().isSubmitting;
|
|
85
85
|
},
|
|
86
|
+
get isSubmitted() {
|
|
87
|
+
return r().isSubmitted;
|
|
88
|
+
},
|
|
89
|
+
get isSubmitSuccessful() {
|
|
90
|
+
return r().isSubmitSuccessful;
|
|
91
|
+
},
|
|
86
92
|
get submitCount() {
|
|
87
93
|
return r().submitCount;
|
|
88
94
|
}
|
|
89
95
|
};
|
|
90
96
|
}
|
|
91
|
-
function
|
|
92
|
-
const n = Array.isArray(t) || r.length > 0, s =
|
|
93
|
-
|
|
94
|
-
const
|
|
97
|
+
function D(e, t, ...r) {
|
|
98
|
+
const n = Array.isArray(t) || r.length > 0, s = A(t, r);
|
|
99
|
+
h(e, s);
|
|
100
|
+
const i = c(e), u = s.map((a) => d(
|
|
95
101
|
e,
|
|
96
|
-
|
|
97
|
-
() =>
|
|
98
|
-
o(
|
|
102
|
+
a,
|
|
103
|
+
() => m(e, i.value, a.name),
|
|
104
|
+
o(a.name)
|
|
99
105
|
));
|
|
100
|
-
return n ?
|
|
106
|
+
return n ? u : u[0];
|
|
101
107
|
}
|
|
102
|
-
function
|
|
108
|
+
function A(e, t) {
|
|
103
109
|
return Array.isArray(e) ? e : t.length > 0 ? [e, ...t] : [e];
|
|
104
110
|
}
|
|
105
|
-
function
|
|
106
|
-
|
|
111
|
+
function V(e) {
|
|
112
|
+
const t = p(e) ? e : b(e);
|
|
113
|
+
return { form: t, useRegister: ((u, ...a) => D(t, u, ...a)), useField: ((u) => v(t, u)), useFormState: () => R(t), handleSubmit: ((u, a) => y(t, u, a)) };
|
|
107
114
|
}
|
|
108
115
|
export {
|
|
109
|
-
|
|
116
|
+
V as useForm
|
|
110
117
|
};
|
package/dist/vue/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Form, FormError, FormState } from '../core/index.js';
|
|
2
|
-
import type { DomValue, RegisterOptions } from '../adapters/dom.js';
|
|
2
|
+
import type { DomValue, RegisterOptions, SubmitHandler, SubmitInvalidHandler, SubmitValidHandler } from '../adapters/dom.js';
|
|
3
3
|
export type { RegisterOptions } from '../adapters/dom.js';
|
|
4
4
|
type VueBindingHandlers<TElement extends HTMLElement> = {
|
|
5
5
|
onInput: (event: Event & {
|
|
@@ -56,6 +56,8 @@ export type VueFormStateReturn<TValues> = {
|
|
|
56
56
|
readonly isDirty: boolean;
|
|
57
57
|
readonly isValid: boolean;
|
|
58
58
|
readonly isSubmitting: boolean;
|
|
59
|
+
readonly isSubmitted: boolean;
|
|
60
|
+
readonly isSubmitSuccessful: boolean;
|
|
59
61
|
readonly submitCount: number;
|
|
60
62
|
};
|
|
61
63
|
export type VueForm<TValues> = {
|
|
@@ -65,4 +67,5 @@ export type VueForm<TValues> = {
|
|
|
65
67
|
useRegister<TElement extends VueRegisterElement = HTMLInputElement, TOptions extends readonly RegisterOptions[] = readonly RegisterOptions[]>(...options: TOptions): VueRegisterPropsList<TElement, TOptions>;
|
|
66
68
|
useField<TElement extends VueRegisterElement = HTMLInputElement>(options: RegisterOptions): VueFieldReturn<VueRegisterPropsForElement<TElement>>;
|
|
67
69
|
useFormState(): VueFormStateReturn<TValues>;
|
|
70
|
+
handleSubmit<TResult>(onValid: SubmitValidHandler<TValues, TResult>, onInvalid?: SubmitInvalidHandler): SubmitHandler<Event, TResult>;
|
|
68
71
|
};
|
package/dist/vue/useForm.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import type { Form } from '../core/index.js';
|
|
1
|
+
import type { CreateFormOptions, Form } from '../core/index.js';
|
|
2
2
|
import type { VueForm } from './types.js';
|
|
3
3
|
export declare function useForm<TValues>(form: Form<TValues>): VueForm<TValues>;
|
|
4
|
+
export declare function useForm<TValues>(options: CreateFormOptions<TValues>): VueForm<TValues>;
|