@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 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 relevant subset of RHF's `UseFormProps` options
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 h } from "react/jsx-runtime";
2
- import f from "../form/FormWithProviders.mjs";
3
- import d from "../form/useRhfUtilsForm.mjs";
4
- const R = (e) => (r) => {
5
- const m = F(e, r);
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: (o, s) => {
8
- const t = m(o, s);
7
+ useForm: (s, t) => {
8
+ const o = m(s, t);
9
9
  return {
10
- ...d(t),
11
- FormWithProviders: () => /* @__PURE__ */ h(f, { ...t })
10
+ ...F(o),
11
+ FormWithProviders: () => /* @__PURE__ */ u(a, { ...o })
12
12
  };
13
13
  },
14
- FormWithProviders: a(e, r)
14
+ FormWithProviders: P(e, r)
15
15
  };
16
- }, F = (e, r) => function(o, s) {
17
- var t, i, l, n, u;
16
+ }, d = (e, r) => function(s, t) {
17
+ var o, i, f, l, n, h;
18
18
  return {
19
- ...s,
19
+ ...t,
20
20
  rhf: {
21
- ...(t = r.defaults) == null ? void 0 : t.rhf,
22
- ...s.rhf,
23
- resolver: e(o)
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
- ...s.utils,
28
- classNames: [
29
- ...((n = (l = r.defaults) == null ? void 0 : l.utils) == null ? void 0 : n.classNames) ?? [],
30
- ...((u = s.utils) == null ? void 0 : u.classNames) ?? []
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
- }, a = (e, r) => function({
35
- schema: o,
36
- children: s,
37
- ...t
35
+ }, P = (e, r) => function({
36
+ schema: s,
37
+ children: t,
38
+ ...o
38
39
  }) {
39
- const i = F(e, r);
40
- return /* @__PURE__ */ h(
41
- f,
40
+ const i = d(e, r);
41
+ return /* @__PURE__ */ u(
42
+ a,
42
43
  {
43
- ...i(o, t),
44
- children: s
44
+ ...i(s, o),
45
+ children: t
45
46
  }
46
47
  );
47
48
  };
48
49
  export {
49
- R as createRhfUtilsClient
50
+ v as createRhfUtilsClient
50
51
  };
@@ -1,92 +1,82 @@
1
- import { jsx as c, jsxs as E, Fragment as N } from "react/jsx-runtime";
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 f from "../client/config/useRhfUtilsClientConfigContext.mjs";
5
- import w from "../devtool/LazyDevTool.mjs";
6
- import { FormSubmitError as C } from "../submit/error/FormSubmitError.mjs";
7
- import B from "../submit/error/setCtxErrorsByFormSubmitErrors.mjs";
8
- import S from "./_Controller.mjs";
9
- function A({
10
- formId: e,
11
- formRef: m,
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: s,
13
+ onSubmit: c,
14
14
  onSubmitError: d,
15
- onSubmitInvalid: y,
16
- Children: h,
15
+ onSubmitInvalid: F,
16
+ Children: i,
17
17
  //
18
- form: p,
18
+ form: l,
19
19
  utils: o
20
20
  }) {
21
- const n = P(), r = f(), i = async (t) => {
21
+ const e = P(), r = w(), y = async (t) => {
22
22
  o != null && o.stopSubmitPropagation && t.stopPropagation();
23
23
  try {
24
- await n.handleSubmit(b, y)(t);
25
- } catch (a) {
26
- j(a, t);
24
+ await e.handleSubmit(f, F)(t);
25
+ } catch (m) {
26
+ b(m, t);
27
27
  }
28
- }, b = (t, a) => s == null ? void 0 : s(
28
+ }, f = (t, m) => c == null ? void 0 : c(
29
29
  t,
30
30
  {
31
- formId: e,
32
- formRef: m,
33
- context: n,
31
+ formId: n,
32
+ formRef: p,
33
+ context: e,
34
34
  utils: o,
35
- FormSubmitError: C
35
+ FormSubmitError: h
36
36
  },
37
- a
38
- ), j = (t, a) => {
39
- var l;
40
- const F = t instanceof C ? (
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
- (l = r == null ? void 0 : r.onSubmitUnknownError) == null ? void 0 : l.call(r, t)
45
+ (x = r == null ? void 0 : r.onSubmitUnknownError) == null ? void 0 : x.call(r, t)
46
46
  );
47
- F && B(n, F), d == null || d(
47
+ C && U(e, C), d == null || d(
48
48
  t,
49
49
  {
50
- formId: e,
51
- formRef: m,
52
- context: n,
50
+ formId: n,
51
+ formRef: p,
52
+ context: e,
53
53
  utils: o
54
54
  },
55
- a
55
+ m
56
56
  );
57
- }, x = {
58
- formId: e,
59
- formRef: m,
60
- context: n,
57
+ }, s = {
58
+ formId: n,
59
+ formRef: p,
60
+ context: e,
61
61
  utils: o,
62
- Controller: S,
63
- FormSubmitError: C
64
- }, T = (r == null ? void 0 : r.FormComponent) ?? "form", v = (r == null ? void 0 : r.FormChildren) ?? U;
65
- return /* @__PURE__ */ c(
66
- T,
67
- {
68
- noValidate: !0,
69
- ref: m,
70
- ...p,
71
- className: [o == null ? void 0 : o.classNames, p == null ? void 0 : p.className].filter(Boolean).join(" "),
72
- onSubmit: i,
73
- children: /* @__PURE__ */ E(v, { ...x, children: [
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 U({
86
- children: e
75
+ function k({
76
+ children: n
87
77
  }) {
88
- return /* @__PURE__ */ c(N, { children: e });
78
+ return /* @__PURE__ */ a(E, { children: n });
89
79
  }
90
80
  export {
91
- A as default
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?: React.FC<UseRhfUtilsFormChildrenProps<TFieldValues, TTransformedValues>>;
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
  };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@paragrav/rhf-utils",
3
3
  "author": "paragrav.dev",
4
4
  "license": "MIT",
5
- "version": "0.0.118",
5
+ "version": "0.0.119",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,