@paragrav/rhf-utils 0.0.118 → 0.0.119
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 -6
- package/dist/esm/client/index.mjs +32 -31
- package/dist/esm/form/Form.mjs +52 -62
- package/dist/types/client/config/RhfUtilsClientConfig.d.ts +4 -0
- package/dist/types/form/RhfUtilsFormOptions.d.ts +0 -5
- package/dist/types/form/UseRhfUtilsFormProps.d.ts +3 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@ To configure, create a file `config.tsx` with desired configuration settings. Th
|
|
|
16
16
|
export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
|
|
17
17
|
// defaults -- overridable per form instance
|
|
18
18
|
defaults: {
|
|
19
|
-
// globally
|
|
19
|
+
// globally-relevant subset of RHF's `UseFormProps` options
|
|
20
20
|
rhf: {
|
|
21
21
|
mode: 'onBlur',
|
|
22
22
|
},
|
|
@@ -26,6 +26,12 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
|
|
|
26
26
|
// enable dev tool on dev env
|
|
27
27
|
devTool: import.meta.env.DEV,
|
|
28
28
|
},
|
|
29
|
+
|
|
30
|
+
// default form props
|
|
31
|
+
form: {
|
|
32
|
+
noValidate: true,
|
|
33
|
+
className: 'my-form-class',
|
|
34
|
+
},
|
|
29
35
|
},
|
|
30
36
|
|
|
31
37
|
// optional (defaults to primitive HTML form)
|
|
@@ -191,11 +197,6 @@ These options can be set globally and/or per form.
|
|
|
191
197
|
|
|
192
198
|
```ts
|
|
193
199
|
type RhfUtilsFormOptions = {
|
|
194
|
-
/**
|
|
195
|
-
* Style via your own classes.
|
|
196
|
-
*/
|
|
197
|
-
classNames?: string[];
|
|
198
|
-
|
|
199
200
|
/** Request submit via listener on form change. */
|
|
200
201
|
submitOnChange?: boolean;
|
|
201
202
|
|
|
@@ -1,50 +1,51 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
const
|
|
5
|
-
const m =
|
|
1
|
+
import { jsx as u } from "react/jsx-runtime";
|
|
2
|
+
import a from "../form/FormWithProviders.mjs";
|
|
3
|
+
import F from "../form/useRhfUtilsForm.mjs";
|
|
4
|
+
const v = (e) => (r) => {
|
|
5
|
+
const m = d(e, r);
|
|
6
6
|
return {
|
|
7
|
-
useForm: (
|
|
8
|
-
const
|
|
7
|
+
useForm: (s, t) => {
|
|
8
|
+
const o = m(s, t);
|
|
9
9
|
return {
|
|
10
|
-
...
|
|
11
|
-
FormWithProviders: () => /* @__PURE__ */
|
|
10
|
+
...F(o),
|
|
11
|
+
FormWithProviders: () => /* @__PURE__ */ u(a, { ...o })
|
|
12
12
|
};
|
|
13
13
|
},
|
|
14
|
-
FormWithProviders:
|
|
14
|
+
FormWithProviders: P(e, r)
|
|
15
15
|
};
|
|
16
|
-
},
|
|
17
|
-
var
|
|
16
|
+
}, d = (e, r) => function(s, t) {
|
|
17
|
+
var o, i, f, l, n, h;
|
|
18
18
|
return {
|
|
19
|
-
...
|
|
19
|
+
...t,
|
|
20
20
|
rhf: {
|
|
21
|
-
...(
|
|
22
|
-
...
|
|
23
|
-
resolver: e(
|
|
21
|
+
...(o = r.defaults) == null ? void 0 : o.rhf,
|
|
22
|
+
...t.rhf,
|
|
23
|
+
resolver: e(s)
|
|
24
24
|
},
|
|
25
25
|
utils: {
|
|
26
26
|
...(i = r.defaults) == null ? void 0 : i.utils,
|
|
27
|
-
...
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
...t.utils
|
|
28
|
+
},
|
|
29
|
+
form: {
|
|
30
|
+
...(f = r.defaults) == null ? void 0 : f.form,
|
|
31
|
+
...t.form,
|
|
32
|
+
className: [(n = (l = r.defaults) == null ? void 0 : l.form) == null ? void 0 : n.className, (h = t.form) == null ? void 0 : h.className].filter(Boolean).join(" ")
|
|
32
33
|
}
|
|
33
34
|
};
|
|
34
|
-
},
|
|
35
|
-
schema:
|
|
36
|
-
children:
|
|
37
|
-
...
|
|
35
|
+
}, P = (e, r) => function({
|
|
36
|
+
schema: s,
|
|
37
|
+
children: t,
|
|
38
|
+
...o
|
|
38
39
|
}) {
|
|
39
|
-
const i =
|
|
40
|
-
return /* @__PURE__ */
|
|
41
|
-
|
|
40
|
+
const i = d(e, r);
|
|
41
|
+
return /* @__PURE__ */ u(
|
|
42
|
+
a,
|
|
42
43
|
{
|
|
43
|
-
...i(
|
|
44
|
-
children:
|
|
44
|
+
...i(s, o),
|
|
45
|
+
children: t
|
|
45
46
|
}
|
|
46
47
|
);
|
|
47
48
|
};
|
|
48
49
|
export {
|
|
49
|
-
|
|
50
|
+
v as createRhfUtilsClient
|
|
50
51
|
};
|
package/dist/esm/form/Form.mjs
CHANGED
|
@@ -1,92 +1,82 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as a, jsxs as v, Fragment as E } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
3
|
import { useFormContext as P } from "react-hook-form";
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { FormSubmitError as
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
function
|
|
10
|
-
formId:
|
|
11
|
-
formRef:
|
|
4
|
+
import w from "../client/config/useRhfUtilsClientConfigContext.mjs";
|
|
5
|
+
import S from "../devtool/LazyDevTool.mjs";
|
|
6
|
+
import { FormSubmitError as h } from "../submit/error/FormSubmitError.mjs";
|
|
7
|
+
import U from "../submit/error/setCtxErrorsByFormSubmitErrors.mjs";
|
|
8
|
+
import _ from "./_Controller.mjs";
|
|
9
|
+
function G({
|
|
10
|
+
formId: n,
|
|
11
|
+
formRef: p,
|
|
12
12
|
//
|
|
13
|
-
onSubmit:
|
|
13
|
+
onSubmit: c,
|
|
14
14
|
onSubmitError: d,
|
|
15
|
-
onSubmitInvalid:
|
|
16
|
-
Children:
|
|
15
|
+
onSubmitInvalid: F,
|
|
16
|
+
Children: i,
|
|
17
17
|
//
|
|
18
|
-
form:
|
|
18
|
+
form: l,
|
|
19
19
|
utils: o
|
|
20
20
|
}) {
|
|
21
|
-
const
|
|
21
|
+
const e = P(), r = w(), y = async (t) => {
|
|
22
22
|
o != null && o.stopSubmitPropagation && t.stopPropagation();
|
|
23
23
|
try {
|
|
24
|
-
await
|
|
25
|
-
} catch (
|
|
26
|
-
|
|
24
|
+
await e.handleSubmit(f, F)(t);
|
|
25
|
+
} catch (m) {
|
|
26
|
+
b(m, t);
|
|
27
27
|
}
|
|
28
|
-
},
|
|
28
|
+
}, f = (t, m) => c == null ? void 0 : c(
|
|
29
29
|
t,
|
|
30
30
|
{
|
|
31
|
-
formId:
|
|
32
|
-
formRef:
|
|
33
|
-
context:
|
|
31
|
+
formId: n,
|
|
32
|
+
formRef: p,
|
|
33
|
+
context: e,
|
|
34
34
|
utils: o,
|
|
35
|
-
FormSubmitError:
|
|
35
|
+
FormSubmitError: h
|
|
36
36
|
},
|
|
37
|
-
|
|
38
|
-
),
|
|
39
|
-
var
|
|
40
|
-
const
|
|
37
|
+
m
|
|
38
|
+
), b = (t, m) => {
|
|
39
|
+
var x;
|
|
40
|
+
const C = t instanceof h ? (
|
|
41
41
|
// consumer can manually throw FormSubmitError (e.g., manual validation)
|
|
42
42
|
t.errors
|
|
43
43
|
) : (
|
|
44
44
|
// if error is not FormSubmitError, consumer can provide global handler
|
|
45
|
-
(
|
|
45
|
+
(x = r == null ? void 0 : r.onSubmitUnknownError) == null ? void 0 : x.call(r, t)
|
|
46
46
|
);
|
|
47
|
-
|
|
47
|
+
C && U(e, C), d == null || d(
|
|
48
48
|
t,
|
|
49
49
|
{
|
|
50
|
-
formId:
|
|
51
|
-
formRef:
|
|
52
|
-
context:
|
|
50
|
+
formId: n,
|
|
51
|
+
formRef: p,
|
|
52
|
+
context: e,
|
|
53
53
|
utils: o
|
|
54
54
|
},
|
|
55
|
-
|
|
55
|
+
m
|
|
56
56
|
);
|
|
57
|
-
},
|
|
58
|
-
formId:
|
|
59
|
-
formRef:
|
|
60
|
-
context:
|
|
57
|
+
}, s = {
|
|
58
|
+
formId: n,
|
|
59
|
+
formRef: p,
|
|
60
|
+
context: e,
|
|
61
61
|
utils: o,
|
|
62
|
-
Controller:
|
|
63
|
-
FormSubmitError:
|
|
64
|
-
}, T = (r == null ? void 0 : r.FormComponent) ?? "form",
|
|
65
|
-
return /* @__PURE__ */
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
(o == null ? void 0 : o.devTool) && /* @__PURE__ */ c(
|
|
75
|
-
w,
|
|
76
|
-
{
|
|
77
|
-
props: typeof o.devTool == "object" ? o.devTool : void 0
|
|
78
|
-
}
|
|
79
|
-
),
|
|
80
|
-
h && /* @__PURE__ */ c(h, { ...x })
|
|
81
|
-
] })
|
|
82
|
-
}
|
|
83
|
-
);
|
|
62
|
+
Controller: _,
|
|
63
|
+
FormSubmitError: h
|
|
64
|
+
}, T = (r == null ? void 0 : r.FormComponent) ?? "form", j = (r == null ? void 0 : r.FormChildren) ?? k;
|
|
65
|
+
return /* @__PURE__ */ a(T, { ...l, ref: p, onSubmit: y, children: /* @__PURE__ */ v(j, { ...s, children: [
|
|
66
|
+
(o == null ? void 0 : o.devTool) && /* @__PURE__ */ a(
|
|
67
|
+
S,
|
|
68
|
+
{
|
|
69
|
+
props: typeof o.devTool == "object" ? o.devTool : void 0
|
|
70
|
+
}
|
|
71
|
+
),
|
|
72
|
+
/* @__PURE__ */ a(i, { ...s })
|
|
73
|
+
] }) });
|
|
84
74
|
}
|
|
85
|
-
function
|
|
86
|
-
children:
|
|
75
|
+
function k({
|
|
76
|
+
children: n
|
|
87
77
|
}) {
|
|
88
|
-
return /* @__PURE__ */
|
|
78
|
+
return /* @__PURE__ */ a(E, { children: n });
|
|
89
79
|
}
|
|
90
80
|
export {
|
|
91
|
-
|
|
81
|
+
G as default
|
|
92
82
|
};
|
|
@@ -27,6 +27,10 @@ export type RhfUtilsClientConfig = {
|
|
|
27
27
|
* (Extend this type via `Register` type to inject custom options/functionality via `Children` component.)
|
|
28
28
|
*/
|
|
29
29
|
utils?: RhfUtilsFormOptions;
|
|
30
|
+
/**
|
|
31
|
+
* Default props for form element.
|
|
32
|
+
*/
|
|
33
|
+
form?: Omit<React.PropsWithoutRef<JSX.IntrinsicElements['form']>, 'onSubmit'>;
|
|
30
34
|
};
|
|
31
35
|
/**
|
|
32
36
|
* Supply your own `<form>` component.
|
|
@@ -8,11 +8,6 @@ import { Register } from '../register';
|
|
|
8
8
|
* Can be extended using {@link Register.RhfUtilsFormOptions}.
|
|
9
9
|
*/
|
|
10
10
|
export type RhfUtilsFormOptions = {
|
|
11
|
-
/**
|
|
12
|
-
* Style via your own classes.
|
|
13
|
-
* (Defaults merged with individual class names.)
|
|
14
|
-
*/
|
|
15
|
-
classNames?: string[];
|
|
16
11
|
/** Request submit via listener on form change. */
|
|
17
12
|
submitOnChange?: boolean;
|
|
18
13
|
/** Reset form values if submit throw errors. (Use case: optimistic UI toggle form that submits on each change.) */
|
|
@@ -12,11 +12,11 @@ export type UseRhfUtilsFormProps<TFieldValues extends SafeFieldValues, TTransfor
|
|
|
12
12
|
/** Submit handler when form is invalid. */
|
|
13
13
|
onSubmitInvalid?: SubmitErrorHandler<TFieldValues>;
|
|
14
14
|
defaultValues?: UseFormProps<TFieldValues>['defaultValues'];
|
|
15
|
-
Children
|
|
15
|
+
Children: React.FC<UseRhfUtilsFormChildrenProps<TFieldValues, TTransformedValues>>;
|
|
16
16
|
/** {@link RhfUseFormProps} props for RHF's {@link useForm}. */
|
|
17
17
|
rhf?: Omit<UseFormProps<TFieldValues>, 'defaultValues'>;
|
|
18
|
-
/** {@link FormProps} props for Form. */
|
|
19
|
-
form?: React.PropsWithoutRef<JSX.IntrinsicElements['form']>;
|
|
20
18
|
/** {@link RhfUtilsFormOptions} to enabled utils functionality. */
|
|
21
19
|
utils?: RhfUtilsFormOptions;
|
|
20
|
+
/** {@link FormProps} props for Form. */
|
|
21
|
+
form?: Omit<React.PropsWithoutRef<JSX.IntrinsicElements['form']>, 'onSubmit'>;
|
|
22
22
|
};
|