@paragrav/rhf-utils 0.0.82 → 0.0.84
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/dist/esm/client/index.mjs +36 -27
- package/dist/esm/exports.mjs +46 -44
- package/dist/esm/form/_Form.mjs +56 -58
- package/dist/esm/form/useForm.mjs +33 -18
- package/dist/types/client/index.d.ts +5 -1
- package/dist/types/exports.d.ts +1 -0
- package/dist/types/form/_Form.d.ts +3 -3
- package/dist/types/form/useForm.d.ts +27 -11
- package/package.json +1 -1
|
@@ -1,51 +1,60 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
1
|
+
import { jsx as d } from "react/jsx-runtime";
|
|
2
|
+
import f from "../form/FormWithProviders.mjs";
|
|
3
|
+
import l from "../form/useForm.mjs";
|
|
4
|
+
const p = (s) => (r) => {
|
|
5
|
+
const n = a(
|
|
6
|
+
s,
|
|
7
7
|
r
|
|
8
8
|
);
|
|
9
9
|
return {
|
|
10
|
-
useForm: (o,
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
useForm: (o, t, e, i, u) => {
|
|
11
|
+
const m = Array.isArray(t) ? t : [t, void 0, void 0];
|
|
12
|
+
return l(
|
|
13
|
+
n(o, {
|
|
14
|
+
onSubmit: m[0],
|
|
15
|
+
onSubmitError: m[1],
|
|
16
|
+
onSubmitInvalid: m[2],
|
|
17
|
+
defaultValues: e,
|
|
18
|
+
Fields: i,
|
|
19
|
+
...u
|
|
20
|
+
})
|
|
21
|
+
);
|
|
22
|
+
},
|
|
23
|
+
FormWithProviders: h(s, r)
|
|
14
24
|
};
|
|
15
|
-
},
|
|
25
|
+
}, h = (s, r) => function({
|
|
16
26
|
schema: o,
|
|
17
|
-
children:
|
|
18
|
-
...
|
|
27
|
+
children: t,
|
|
28
|
+
...e
|
|
19
29
|
}) {
|
|
20
|
-
const i = a(
|
|
21
|
-
return /* @__PURE__ */
|
|
22
|
-
|
|
30
|
+
const i = a(s, r);
|
|
31
|
+
return /* @__PURE__ */ d(
|
|
32
|
+
f,
|
|
23
33
|
{
|
|
24
|
-
...i(o,
|
|
25
|
-
children:
|
|
34
|
+
...i(o, e),
|
|
35
|
+
children: t
|
|
26
36
|
}
|
|
27
37
|
);
|
|
28
|
-
}, a = (
|
|
29
|
-
var
|
|
38
|
+
}, a = (s, r) => (n, o) => {
|
|
39
|
+
var t, e, i, u, m;
|
|
30
40
|
return {
|
|
31
41
|
...o,
|
|
32
42
|
config: r,
|
|
33
43
|
rhf: {
|
|
34
|
-
...(
|
|
44
|
+
...(t = r.defaultOptions) == null ? void 0 : t.rhf,
|
|
35
45
|
...o.rhf,
|
|
36
|
-
resolver:
|
|
46
|
+
resolver: s(n)
|
|
37
47
|
},
|
|
38
|
-
form: o.form,
|
|
39
48
|
options: {
|
|
40
|
-
...(
|
|
49
|
+
...(e = r.defaultOptions) == null ? void 0 : e.form,
|
|
41
50
|
...o.options,
|
|
42
51
|
classNames: [
|
|
43
|
-
...((
|
|
44
|
-
...((
|
|
52
|
+
...((u = (i = r.defaultOptions) == null ? void 0 : i.form) == null ? void 0 : u.classNames) ?? [],
|
|
53
|
+
...((m = o.options) == null ? void 0 : m.classNames) ?? []
|
|
45
54
|
]
|
|
46
55
|
}
|
|
47
56
|
};
|
|
48
57
|
};
|
|
49
58
|
export {
|
|
50
|
-
|
|
59
|
+
p as createRhfUtilsClient
|
|
51
60
|
};
|
package/dist/esm/exports.mjs
CHANGED
|
@@ -6,77 +6,79 @@ import { default as d } from "./errors/flat/context/FlatFieldErrorsContextProvid
|
|
|
6
6
|
import { default as x } from "./errors/flat/context/useFlatFieldErrorsContext.mjs";
|
|
7
7
|
import { default as i } from "./errors/flat/FlatFieldErrorsList.mjs";
|
|
8
8
|
import { default as E } from "./errors/message/FormErrorMessage.mjs";
|
|
9
|
-
import { default as
|
|
9
|
+
import { default as h } from "./errors/message/FormErrorMessageByPath.mjs";
|
|
10
10
|
import { default as S } from "./errors/nonfield/FormNonFieldErrorMarker.mjs";
|
|
11
11
|
import { default as y } from "./errors/nonfield/FormNonFieldErrorMarkerHtmlAttribute.mjs";
|
|
12
12
|
import { default as O } from "./errors/orphan/useFormHasOnlyOrphanFieldErrorsMemo.mjs";
|
|
13
|
-
import { default as
|
|
13
|
+
import { default as R } from "./errors/orphan/useOrphanFormErrorsMemo.mjs";
|
|
14
14
|
import { default as I } from "./errors/orphan/useOrphanFormErrorsToConsole.mjs";
|
|
15
15
|
import { default as g } from "./errors/root/RootErrorsListFromFlatFieldErrorsContext.mjs";
|
|
16
|
-
import { default as
|
|
16
|
+
import { default as v } from "./errors/root/useRootFormFieldErrorsMemo.mjs";
|
|
17
17
|
import { default as A } from "./errors/useFormErrorConsoleDebug.mjs";
|
|
18
18
|
import { default as D } from "./errors/useFormErrorsEffect.mjs";
|
|
19
19
|
import { default as Z } from "./errors/useFormErrorsIfAny.mjs";
|
|
20
20
|
import { default as N } from "./errors/useFormErrorsTransformMemo.mjs";
|
|
21
21
|
import { default as z } from "./errors/useFormRequestSubmit.mjs";
|
|
22
|
-
import { default as
|
|
23
|
-
import { default as
|
|
24
|
-
import { default as
|
|
25
|
-
import { default as X } from "./form/context/
|
|
26
|
-
import { default as _ } from "./form/context/group/
|
|
27
|
-
import { default as rr } from "./form/context/group/
|
|
28
|
-
import { default as er } from "./form/context/group/
|
|
29
|
-
import { default as sr } from "./form/context/group/
|
|
30
|
-
import { default as ur } from "./form/context/group/
|
|
31
|
-
import { default as mr } from "./form/context/group/
|
|
32
|
-
import { default as dr } from "./form/context/group/
|
|
33
|
-
import { default as xr } from "./form/context/group/
|
|
34
|
-
import { default as ir } from "./form/
|
|
35
|
-
import {
|
|
36
|
-
import {
|
|
37
|
-
import { default as Sr } from "./submit/
|
|
38
|
-
import { default as yr } from "./submit/
|
|
39
|
-
import { default as Or } from "./submit/
|
|
40
|
-
import { default as
|
|
22
|
+
import { default as j } from "./form/FormWithProviders.mjs";
|
|
23
|
+
import { default as J } from "./form/useForm.mjs";
|
|
24
|
+
import { default as Q } from "./form/context/utils/FormUtilsContextProvider.mjs";
|
|
25
|
+
import { default as X } from "./form/context/utils/useFormUtilsContext.mjs";
|
|
26
|
+
import { default as _ } from "./form/context/group/FormGroupContextProvider.mjs";
|
|
27
|
+
import { default as rr } from "./form/context/group/useFormGroupChildIsMountedTracker.mjs";
|
|
28
|
+
import { default as er } from "./form/context/group/useFormGroupChildIsSubmittingTracker.mjs";
|
|
29
|
+
import { default as sr } from "./form/context/group/useFormGroupChildTracker.mjs";
|
|
30
|
+
import { default as ur } from "./form/context/group/useFormGroupIsAnyBusy.mjs";
|
|
31
|
+
import { default as mr } from "./form/context/group/useFormGroupIsChildBusy.mjs";
|
|
32
|
+
import { default as dr } from "./form/context/group/useFormGroupIsParentBusy.mjs";
|
|
33
|
+
import { default as xr } from "./form/context/group/useFormGroupParentTracker.mjs";
|
|
34
|
+
import { default as ir } from "./form/context/group/useFormOrParentIsBusy.mjs";
|
|
35
|
+
import { default as Er } from "./form/utils/getSubmitterButtonData.mjs";
|
|
36
|
+
import { FormSubmitError as hr } from "./submit/error/FormSubmitError.mjs";
|
|
37
|
+
import { default as Sr } from "./submit/useFormOnSubmitSuccessful.mjs";
|
|
38
|
+
import { default as yr } from "./submit/useFormOnSubmitSuccessfulAndReset.mjs";
|
|
39
|
+
import { default as Or } from "./submit/useResetFormOnSubmitError.mjs";
|
|
40
|
+
import { default as Rr } from "./submit/useResetFormOnSubmitSuccessful.mjs";
|
|
41
|
+
import { default as Ir } from "./submit/useSubmitFormOnChange.mjs";
|
|
41
42
|
export {
|
|
42
43
|
d as FlatFieldErrorsContextProvider,
|
|
43
44
|
i as FlatFieldErrorsList,
|
|
44
45
|
E as FormErrorMessage,
|
|
45
|
-
|
|
46
|
-
|
|
46
|
+
h as FormErrorMessageByPath,
|
|
47
|
+
_ as FormGroupContextProvider,
|
|
47
48
|
S as FormNonFieldErrorMarker,
|
|
48
49
|
y as FormNonFieldErrorMarkerHtmlAttribute,
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
hr as FormSubmitError,
|
|
51
|
+
Q as FormUtilsContextProvider,
|
|
52
|
+
j as FormWithProviders,
|
|
51
53
|
m as LazyDevTool,
|
|
52
54
|
e as RhfUtilsClientForZodContextProvider,
|
|
53
55
|
g as RootErrorsListFromFlatFieldErrorsContext,
|
|
54
56
|
u as createRhfUtilsClientForZod,
|
|
55
|
-
|
|
57
|
+
Er as getSubmitterButtonData,
|
|
56
58
|
x as useFlatFieldErrorsContext,
|
|
57
|
-
|
|
59
|
+
J as useForm,
|
|
58
60
|
A as useFormErrorConsoleDebug,
|
|
59
61
|
D as useFormErrorsEffect,
|
|
60
62
|
Z as useFormErrorsIfAny,
|
|
61
63
|
N as useFormErrorsTransformMemo,
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
rr as useFormGroupChildIsMountedTracker,
|
|
65
|
+
er as useFormGroupChildIsSubmittingTracker,
|
|
66
|
+
sr as useFormGroupChildTracker,
|
|
67
|
+
ur as useFormGroupIsAnyBusy,
|
|
68
|
+
mr as useFormGroupIsChildBusy,
|
|
69
|
+
dr as useFormGroupIsParentBusy,
|
|
70
|
+
xr as useFormGroupParentTracker,
|
|
69
71
|
O as useFormHasOnlyOrphanFieldErrorsMemo,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
72
|
+
Sr as useFormOnSubmitSuccessful,
|
|
73
|
+
yr as useFormOnSubmitSuccessfulAndReset,
|
|
74
|
+
ir as useFormOrParentIsBusy,
|
|
73
75
|
z as useFormRequestSubmit,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
+
X as useFormUtilsContext,
|
|
77
|
+
R as useOrphanFormErrorsMemo,
|
|
76
78
|
I as useOrphanFormErrorsToConsole,
|
|
77
|
-
|
|
78
|
-
|
|
79
|
+
Rr as useResetFormAfterSubmitSuccessful,
|
|
80
|
+
Or as useResetFormOnSubmitError,
|
|
79
81
|
s as useRhfUtilsClientForZodContext,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
v as useRootFormFieldErrorsMemo,
|
|
83
|
+
Ir as useSubmitFormOnChange
|
|
82
84
|
};
|
package/dist/esm/form/_Form.mjs
CHANGED
|
@@ -1,83 +1,81 @@
|
|
|
1
|
-
import { jsxs as
|
|
1
|
+
import { jsxs as T, jsx as u } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
|
-
import { useFormContext as
|
|
3
|
+
import { useFormContext as _ } from "react-hook-form";
|
|
4
4
|
import v from "../devtool/LazyDevTool.mjs";
|
|
5
|
-
import { FormSubmitError as
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
function
|
|
9
|
-
formId:
|
|
10
|
-
formRef:
|
|
11
|
-
|
|
5
|
+
import { FormSubmitError as E } from "../submit/error/FormSubmitError.mjs";
|
|
6
|
+
import V from "../submit/error/setCtxErrorsByFormSubmitError.mjs";
|
|
7
|
+
import w from "./_FormBase.mjs";
|
|
8
|
+
function H({
|
|
9
|
+
formId: B,
|
|
10
|
+
formRef: x,
|
|
11
|
+
//
|
|
12
|
+
onSubmit: s,
|
|
13
|
+
onSubmitError: h,
|
|
14
|
+
onSubmitInvalid: F,
|
|
15
|
+
Fields: C,
|
|
16
|
+
//
|
|
17
|
+
form: d,
|
|
12
18
|
options: a,
|
|
13
|
-
config:
|
|
14
|
-
|
|
19
|
+
config: t,
|
|
20
|
+
//
|
|
21
|
+
children: j
|
|
15
22
|
}) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
a != null && a.stopSubmitPropagation && e.stopPropagation();
|
|
23
|
+
const l = _(), N = async (r) => {
|
|
24
|
+
a != null && a.stopSubmitPropagation && r.stopPropagation();
|
|
19
25
|
try {
|
|
20
|
-
await
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
)(e);
|
|
24
|
-
} catch (u) {
|
|
25
|
-
n(u, e);
|
|
26
|
+
await l.handleSubmit(P, F)(r);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
S(e, r);
|
|
26
29
|
}
|
|
27
|
-
},
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
);
|
|
35
|
-
}, n = (e, u) => {
|
|
36
|
-
var x, C;
|
|
37
|
-
const d = e instanceof N ? (
|
|
30
|
+
}, P = (r, e) => s == null ? void 0 : s(
|
|
31
|
+
r,
|
|
32
|
+
l,
|
|
33
|
+
e
|
|
34
|
+
), S = (r, e) => {
|
|
35
|
+
var b;
|
|
36
|
+
const m = r instanceof E ? (
|
|
38
37
|
// consumer can manually throw FormSubmitError (e.g., manual validation)
|
|
39
|
-
|
|
38
|
+
r
|
|
40
39
|
) : (
|
|
41
40
|
// if error is not FormSubmitError, consumer can provide global handler
|
|
42
|
-
(
|
|
41
|
+
(b = t == null ? void 0 : t.onSubmitError) == null ? void 0 : b.call(t, r)
|
|
43
42
|
);
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
u
|
|
43
|
+
m && V(l, m), h == null || h(
|
|
44
|
+
r,
|
|
45
|
+
l,
|
|
46
|
+
e
|
|
49
47
|
);
|
|
50
|
-
},
|
|
51
|
-
formId:
|
|
52
|
-
formRef:
|
|
53
|
-
ctx:
|
|
48
|
+
}, c = {
|
|
49
|
+
formId: B,
|
|
50
|
+
formRef: x,
|
|
51
|
+
ctx: l,
|
|
54
52
|
options: a
|
|
55
|
-
},
|
|
56
|
-
var
|
|
57
|
-
const
|
|
58
|
-
return
|
|
53
|
+
}, y = (r) => {
|
|
54
|
+
var m;
|
|
55
|
+
const e = (m = t == null ? void 0 : t.Children) == null ? void 0 : m[r];
|
|
56
|
+
return e && /* @__PURE__ */ u(e, { ...c });
|
|
59
57
|
};
|
|
60
|
-
return /* @__PURE__ */
|
|
61
|
-
|
|
58
|
+
return /* @__PURE__ */ T(
|
|
59
|
+
w,
|
|
62
60
|
{
|
|
63
61
|
noValidate: !0,
|
|
64
62
|
style: {
|
|
65
63
|
position: "relative"
|
|
66
64
|
},
|
|
67
|
-
...
|
|
68
|
-
className: [a == null ? void 0 : a.classNames,
|
|
69
|
-
onSubmit:
|
|
70
|
-
formRef:
|
|
65
|
+
...d,
|
|
66
|
+
className: [a == null ? void 0 : a.classNames, d == null ? void 0 : d.className].filter(Boolean).join(" "),
|
|
67
|
+
onSubmit: N,
|
|
68
|
+
formRef: x,
|
|
71
69
|
children: [
|
|
72
|
-
|
|
73
|
-
(a == null ? void 0 : a.devTool) !== "disabled" && /* @__PURE__ */
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
70
|
+
y("top"),
|
|
71
|
+
(a == null ? void 0 : a.devTool) !== "disabled" && /* @__PURE__ */ u(v, { placement: "top-right", ...a == null ? void 0 : a.devTool }),
|
|
72
|
+
C && /* @__PURE__ */ u(C, { ...c }),
|
|
73
|
+
j,
|
|
74
|
+
y("bottom")
|
|
77
75
|
]
|
|
78
76
|
}
|
|
79
77
|
);
|
|
80
78
|
}
|
|
81
79
|
export {
|
|
82
|
-
|
|
80
|
+
H as default
|
|
83
81
|
};
|
|
@@ -1,30 +1,45 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useForm as
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import t from "react";
|
|
2
|
+
import { useForm as a } from "react-hook-form";
|
|
3
|
+
import { FormSubmitError as l } from "../submit/error/FormSubmitError.mjs";
|
|
4
|
+
const E = ({
|
|
5
|
+
onSubmit: e,
|
|
6
|
+
onSubmitError: m,
|
|
7
|
+
onSubmitInvalid: f,
|
|
8
|
+
defaultValues: n,
|
|
9
|
+
Fields: p,
|
|
10
|
+
config: u,
|
|
11
|
+
rhf: c,
|
|
12
|
+
form: i,
|
|
13
|
+
options: d
|
|
8
14
|
}) => {
|
|
9
|
-
const
|
|
15
|
+
const r = t.useId(), s = a({
|
|
16
|
+
...c,
|
|
17
|
+
defaultValues: n
|
|
18
|
+
}), o = t.useRef(null);
|
|
10
19
|
return {
|
|
11
|
-
id:
|
|
12
|
-
ref:
|
|
20
|
+
id: r,
|
|
21
|
+
ref: o,
|
|
13
22
|
context: s,
|
|
14
23
|
providerProps: {
|
|
15
|
-
formId:
|
|
16
|
-
formRef:
|
|
24
|
+
formId: r,
|
|
25
|
+
formRef: o,
|
|
17
26
|
rhfForm: s,
|
|
18
|
-
options:
|
|
27
|
+
options: d
|
|
19
28
|
},
|
|
20
29
|
formProps: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
30
|
+
Fields: p,
|
|
31
|
+
onSubmit: e,
|
|
32
|
+
onSubmitError: m,
|
|
33
|
+
onSubmitInvalid: f,
|
|
34
|
+
formId: r,
|
|
35
|
+
formRef: o,
|
|
36
|
+
config: u,
|
|
37
|
+
form: i
|
|
38
|
+
},
|
|
39
|
+
SubmitError: class extends l {
|
|
25
40
|
}
|
|
26
41
|
};
|
|
27
42
|
};
|
|
28
43
|
export {
|
|
29
|
-
|
|
44
|
+
E as default
|
|
30
45
|
};
|
|
@@ -13,7 +13,11 @@ export type ObjectSchema<TInputKey extends string, TOutputKey extends string> =
|
|
|
13
13
|
[key in TOutputKey]: SafeFieldValues;
|
|
14
14
|
};
|
|
15
15
|
export type CreateRhfUtilsClient<TObjectSchema extends ObjectSchema<TObjectSchemaInputKey, TObjectSchemaOutputKey>, TObjectSchemaInputKey extends string, TObjectSchemaOutputKey extends string> = {
|
|
16
|
-
useForm: <TSchema extends TObjectSchema, TSchemaInput extends SafeFieldValues = TSchema[TObjectSchemaInputKey], TSchemaOutput extends SafeFieldValues = TSchema[TObjectSchemaOutputKey]
|
|
16
|
+
useForm: <TSchema extends TObjectSchema, TSchemaInput extends SafeFieldValues = TSchema[TObjectSchemaInputKey], TSchemaOutput extends SafeFieldValues = TSchema[TObjectSchemaOutputKey], UseFormPropsForm extends UseFormProps<TSchemaInput, TSchemaOutput> = UseFormProps<TSchemaInput, TSchemaOutput>>(schema: TSchema, handlers: NonNullable<UseFormPropsForm['onSubmit']> | [
|
|
17
|
+
NonNullable<UseFormPropsForm['onSubmit']>,
|
|
18
|
+
UseFormPropsForm['onSubmitError'],
|
|
19
|
+
UseFormPropsForm['onSubmitInvalid']
|
|
20
|
+
], defaultValues: UseFormPropsForm['defaultValues'], Fields: UseFormPropsForm['Fields'], props: UseFormProps<TSchemaInput, TSchemaOutput>) => UseFormReturn<TSchemaInput, TSchemaOutput>;
|
|
17
21
|
FormWithProviders: <TSchema extends TObjectSchema, TSchemaInput extends SafeFieldValues = TSchema[TObjectSchemaInputKey], TSchemaOutput extends SafeFieldValues = TSchema[TObjectSchemaOutputKey]>(props: {
|
|
18
22
|
schema: TSchema;
|
|
19
23
|
} & FormWithProvidersProps<TSchemaInput, TSchemaOutput>) => JSX.Element;
|
package/dist/types/exports.d.ts
CHANGED
|
@@ -21,6 +21,7 @@ export { default as useFormErrorsEffect } from './errors/useFormErrorsEffect';
|
|
|
21
21
|
export { default as useFormErrorsIfAny } from './errors/useFormErrorsIfAny';
|
|
22
22
|
export { default as useFormErrorsTransformMemo } from './errors/useFormErrorsTransformMemo';
|
|
23
23
|
export { default as useFormRequestSubmit } from './errors/useFormRequestSubmit';
|
|
24
|
+
export { default as FormWithProviders } from './form/FormWithProviders';
|
|
24
25
|
export type { SafeFieldValues } from './form/SafeFieldValues';
|
|
25
26
|
export type { UseFormFieldsProps } from './form/useForm';
|
|
26
27
|
export { default as useForm } from './form/useForm';
|
|
@@ -3,9 +3,9 @@ import { SafeFieldValues } from './SafeFieldValues';
|
|
|
3
3
|
import { default as React } from 'react';
|
|
4
4
|
|
|
5
5
|
export type _FormSlots = 'top' | 'bottom';
|
|
6
|
-
export type _FormProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = React.PropsWithChildren<
|
|
6
|
+
export type _FormProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = React.PropsWithChildren<{
|
|
7
7
|
formId: string;
|
|
8
8
|
formRef: React.RefObject<HTMLFormElement>;
|
|
9
|
-
}
|
|
10
|
-
declare function _Form<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ formId, formRef, form, options, config, children, }: _FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
} & Pick<UseFormProps<TFieldValues, TTransformedValues>, 'onSubmit' | 'onSubmitError' | 'onSubmitInvalid' | 'Fields' | 'form' | 'options' | 'config'>>;
|
|
10
|
+
declare function _Form<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ formId, formRef, onSubmit, onSubmitError, onSubmitInvalid, Fields, form, options, config, children, }: _FormProps<TFieldValues, TTransformedValues>): import("react/jsx-runtime").JSX.Element;
|
|
11
11
|
export default _Form;
|
|
@@ -13,19 +13,18 @@ export type UseFormFieldsProps<TFieldValues extends SafeFieldValues = SafeFieldV
|
|
|
13
13
|
options?: UseFormOptions;
|
|
14
14
|
};
|
|
15
15
|
export type UseFormProps<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = {
|
|
16
|
+
onSubmit?: (values: TTransformedValues, context: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
|
|
17
|
+
/** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
|
|
18
|
+
onSubmitError?: (error: unknown, context: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
|
|
19
|
+
/** Submit handler when form is invalid. */
|
|
20
|
+
onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
|
|
21
|
+
defaultValues?: RhfUseFormProps<TFieldValues>['defaultValues'];
|
|
22
|
+
Fields?: React.FC<UseFormFieldsProps<TFieldValues, TTransformedValues>>;
|
|
16
23
|
config?: ClientConfig;
|
|
17
24
|
/** {@link RhfUseFormProps} props for RHF's {@link useRhfForm}. */
|
|
18
|
-
rhf?: RhfUseFormProps<TFieldValues>;
|
|
25
|
+
rhf?: Omit<RhfUseFormProps<TFieldValues>, 'defaultValues'>;
|
|
19
26
|
/** {@link FormProps} props for Form. */
|
|
20
|
-
form?:
|
|
21
|
-
Fields?: React.FC<UseFormFieldsProps<TFieldValues, TTransformedValues>>;
|
|
22
|
-
onSubmit?: (values: TTransformedValues, context: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => unknown | Promise<unknown>;
|
|
23
|
-
/** Submit error handler. (Only for errors not of instance `FormError`, which are handled internally.) */
|
|
24
|
-
onSubmitError?: (error: unknown, context: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>, event: React.BaseSyntheticEvent<SubmitEvent>) => void;
|
|
25
|
-
/** Submit handler when form is invalid. */
|
|
26
|
-
onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
|
|
27
|
-
props?: React.PropsWithoutRef<JSX.IntrinsicElements['form']>;
|
|
28
|
-
};
|
|
27
|
+
form?: React.PropsWithoutRef<JSX.IntrinsicElements['form']>;
|
|
29
28
|
options?: UseFormOptions;
|
|
30
29
|
};
|
|
31
30
|
/**
|
|
@@ -37,12 +36,29 @@ export type UseFormProps<TFieldValues extends SafeFieldValues, TTransformedValue
|
|
|
37
36
|
* see https://caniuse.com/?search=form%20attribute
|
|
38
37
|
* @returns Form provider and form.
|
|
39
38
|
*/
|
|
40
|
-
declare const useForm: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ config, rhf, form, options, }: UseFormProps<TFieldValues, TTransformedValues>) => {
|
|
39
|
+
declare const useForm: <TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues>({ onSubmit, onSubmitError, onSubmitInvalid, defaultValues, Fields, config, rhf, form, options, }: UseFormProps<TFieldValues, TTransformedValues>) => {
|
|
41
40
|
readonly id: string;
|
|
42
41
|
readonly ref: React.RefObject<HTMLFormElement>;
|
|
43
42
|
readonly context: RhfUseFormReturn<TFieldValues, unknown, TTransformedValues>;
|
|
44
43
|
readonly providerProps: _FormProvidersProps<TFieldValues, TTransformedValues>;
|
|
45
44
|
readonly formProps: _FormProps<TFieldValues, TTransformedValues>;
|
|
45
|
+
readonly SubmitError: {
|
|
46
|
+
new (errors: Record<`root.${string}` | import('react-hook-form').Path<TFieldValues>, {
|
|
47
|
+
type?: string | undefined;
|
|
48
|
+
message: string;
|
|
49
|
+
}>, message?: string | undefined): {
|
|
50
|
+
errors: Record<`root.${string}` | import('react-hook-form').Path<TFieldValues>, {
|
|
51
|
+
type?: string | undefined;
|
|
52
|
+
message: string;
|
|
53
|
+
}>;
|
|
54
|
+
name: string;
|
|
55
|
+
message: string;
|
|
56
|
+
stack?: string | undefined;
|
|
57
|
+
};
|
|
58
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function | undefined): void;
|
|
59
|
+
prepareStackTrace?: ((err: Error, stackTraces: NodeJS.CallSite[]) => any) | undefined;
|
|
60
|
+
stackTraceLimit: number;
|
|
61
|
+
};
|
|
46
62
|
};
|
|
47
63
|
export default useForm;
|
|
48
64
|
export type UseForm<TFieldValues extends SafeFieldValues, TTransformedValues extends SafeFieldValues> = typeof useForm<TFieldValues, TTransformedValues>;
|