@paragrav/rhf-utils 0.0.127 → 0.0.128

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
@@ -50,7 +50,7 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
50
50
  formRef, // ref
51
51
  context, // rhf UseFormReturn
52
52
  options, // RhfUtilsFormOptions (with any custom props)
53
- Controller, // strictly-typed controller
53
+ Controller, // strictly-typed rhf controller
54
54
  FormSubmitError, // strictly-typed error class
55
55
  children, // RhfUtilsZodForm's Children instance
56
56
  },
@@ -108,7 +108,7 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
108
108
 
109
109
  ## Provider
110
110
 
111
- And add the context provider to your stack:
111
+ And add the context provider to your global provider stack:
112
112
 
113
113
  ```tsx
114
114
  <RhfUtilsClientForZodContextProvider config={rhfUtilsClientConfig}>
@@ -150,7 +150,7 @@ Currently, only `zod` is supported.
150
150
  formRef, // ref
151
151
  context, // rhf UseFormReturn
152
152
  options, // RhfUtilsFormOptions
153
- Controller, // strictly-typed controller
153
+ Controller, // strictly-typed rhf controller
154
154
  FormSubmitError, // strictly-typed error class
155
155
  }) => (
156
156
  <>
@@ -1,20 +1,21 @@
1
- import { jsx as n } from "react/jsx-runtime";
2
- import m from "../form/FormWithProviders.mjs";
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ import "react";
3
+ import n from "../form/FormWithProviders.mjs";
3
4
  import l from "../form/useRhfUtilsForm.mjs";
4
5
  import { mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps as F } from "./utils.mjs";
5
- const p = (r) => (o) => {
6
- const i = f(r, o);
6
+ const c = (r) => (o) => {
7
+ const e = f(r, o);
7
8
  return {
8
- useForm: (e, t) => {
9
- const s = i(e, t);
9
+ useForm: (s, t) => {
10
+ const i = e(s, t);
10
11
  return {
11
- ...l(s),
12
- FormWithProviders: () => /* @__PURE__ */ n(m, { ...s })
12
+ ...l(i),
13
+ FormWithProviders: () => /* @__PURE__ */ m(n, { ...i })
13
14
  };
14
15
  },
15
16
  FormWithProviders: u(r, o)
16
17
  };
17
- }, f = (r, o) => function(e, t) {
18
+ }, f = (r, o) => function(s, t) {
18
19
  return {
19
20
  ...t,
20
21
  ...F(
@@ -22,25 +23,27 @@ const p = (r) => (o) => {
22
23
  t,
23
24
  {
24
25
  rhf: {
25
- resolver: r(e)
26
+ resolver: r(s)
26
27
  }
27
28
  }
28
29
  )
29
30
  };
30
- }, u = (r, o) => function({
31
- schema: e,
32
- children: t,
33
- ...s
34
- }) {
35
- const h = f(r, o);
36
- return /* @__PURE__ */ n(
37
- m,
38
- {
39
- ...h(e, s),
40
- children: t
41
- }
42
- );
31
+ }, u = (r, o) => {
32
+ const e = f(r, o);
33
+ return function({
34
+ schema: t,
35
+ children: i,
36
+ ...h
37
+ }) {
38
+ return /* @__PURE__ */ m(
39
+ n,
40
+ {
41
+ ...e(t, h),
42
+ children: i
43
+ }
44
+ );
45
+ };
43
46
  };
44
47
  export {
45
- p as createRhfUtilsClient
48
+ c as createRhfUtilsClient
46
49
  };
@@ -1,23 +1,28 @@
1
- const i = (l, ...t) => t.reduce(
2
- (s, e) => {
3
- var f, o;
4
- return {
5
- rhf: {
6
- ...s == null ? void 0 : s.rhf,
7
- ...e.rhf
8
- },
9
- utils: {
10
- ...s == null ? void 0 : s.utils,
11
- ...e.utils
12
- },
13
- form: {
14
- ...s == null ? void 0 : s.form,
15
- ...e.form,
16
- className: [(f = s == null ? void 0 : s.form) == null ? void 0 : f.className, (o = e.form) == null ? void 0 : o.className].filter(Boolean).join(" ")
17
- }
18
- };
19
- },
20
- l
1
+ const i = (l, ...t) => (
2
+ // sequentially merge each set of props into defaults
3
+ t.reduce(
4
+ (s, e) => {
5
+ var f, o;
6
+ return {
7
+ rhf: {
8
+ ...s == null ? void 0 : s.rhf,
9
+ ...e.rhf
10
+ },
11
+ utils: {
12
+ ...s == null ? void 0 : s.utils,
13
+ ...e.utils
14
+ },
15
+ form: {
16
+ ...s == null ? void 0 : s.form,
17
+ ...e.form,
18
+ className: [(f = s == null ? void 0 : s.form) == null ? void 0 : f.className, (o = e.form) == null ? void 0 : o.className].filter(Boolean).join(" ")
19
+ // stringify
20
+ }
21
+ };
22
+ },
23
+ // start with defaults
24
+ l
25
+ )
21
26
  );
22
27
  export {
23
28
  i as mergeRhfUtilsClientConfigDefaultsWithUseRhfUtilsFormProps
@@ -1,9 +1,8 @@
1
- import { jsx as t } from "react/jsx-runtime";
2
- import { useFormContext as n, Controller as e } from "react-hook-form";
3
- function f(o) {
4
- const { control: r } = n();
5
- return /* @__PURE__ */ t(e, { control: r, ...o });
1
+ import { jsx as o } from "react/jsx-runtime";
2
+ import { Controller as t } from "react-hook-form";
3
+ function n(r) {
4
+ return /* @__PURE__ */ o(t, { ...r });
6
5
  }
7
6
  export {
8
- f as default
7
+ n as default
9
8
  };
@@ -1,23 +1,36 @@
1
- import { useFormContext as c } from "react-hook-form";
1
+ import { useFormContext as n } from "react-hook-form";
2
2
  import i from "./useFormOnSubmitted.mjs";
3
- const f = (e) => {
4
- const { reset: u, getValues: s } = c();
5
- i((o) => {
6
- var r;
3
+ const p = (e) => {
4
+ const { getValues: s, reset: o } = n();
5
+ i((m) => {
6
+ var u;
7
7
  if (!e) return;
8
- const t = (r = e[o ? "success" : "error"]) == null ? void 0 : r.values;
8
+ const t = (u = e[m ? "success" : "error"]) == null ? void 0 : u.values;
9
9
  if (!t) return;
10
- const m = t === "current" ? s() : void 0;
11
- u(m, {
10
+ const r = t === "current", c = r ? s() : void 0;
11
+ o(c, {
12
12
  // keep submit stuff for tracking relevant state (e.g., `useFormOnSubmitSuccessful`)
13
13
  keepIsSubmitSuccessful: !0,
14
14
  keepIsSubmitted: !0,
15
15
  keepSubmitCount: !0,
16
+ /**
17
+ * This is necessary when setting default values to current values (lest form stop updating).
18
+ *
19
+ * Technically, we are keeping values and resetting default values to same values.
20
+ *
21
+ * Steps to repro:
22
+ * - RhfUtilsClientConfig with resetOnSubmitted set to success values to current
23
+ * - remove `keepValues` prop from reset
24
+ * - create valid form, submit
25
+ * - form values should be unchanged
26
+ * - unexpectedly: can no longer type into input
27
+ */
28
+ keepValues: r,
16
29
  // keep errors in the case of unsuccessful submit
17
30
  keepErrors: !0
18
31
  });
19
32
  });
20
33
  };
21
34
  export {
22
- f as default
35
+ p as default
23
36
  };
@@ -1,3 +1,4 @@
1
+ import { default as React } from 'react';
1
2
  import { Resolver } from 'react-hook-form';
2
3
  import { RhfUtilsClientConfig } from './config/RhfUtilsClientConfig';
3
4
  import { FormWithProvidersProps } from '../form/FormWithProviders';
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.127",
5
+ "version": "0.0.128",
6
6
  "description": "Integration utilities for react-hook-form.",
7
7
  "type": "module",
8
8
  "sideEffects": false,