@paragrav/rhf-utils 0.59.0 → 0.61.0

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
@@ -72,14 +72,15 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
72
72
  },
73
73
 
74
74
  // optional form component to use (defaults to primitive HTML form)
75
- // also, is used to inject your own hooks and components
76
- // for all RhfUtilsZodForm instances
77
- FormComponent: (
75
+ FormComponent: Form.Root,
76
+
77
+ // inject your own hooks and components
78
+ // into all RhfUtilsZodForm instances
79
+ FormChildren: (
78
80
  // RhfUtilsFormComponentProps
79
81
  {
80
- formProps, // computed form props
81
82
  formId, // unique id string
82
- formRef, // ref
83
+ formRef, // form element ref
83
84
  context, // rhf UseFormReturn (without proxy `formState`)
84
85
  options, // RhfUtilsFormOptions (with any custom props)
85
86
  Controller, // rhf controller (SafeFieldValues-typed; no schema at this level)
@@ -96,13 +97,13 @@ export const rhfUtilsClientConfig: RhfUtilsClientConfig = {
96
97
  });
97
98
 
98
99
  return (
99
- <Form.Root {...formProps} ref={formRef}>
100
+ <>
100
101
  {/* RhfUtilsZodForm.Children "outlet" (see "Component Hierarchy" section) */}
101
102
  {children}
102
103
 
103
104
  {/* root errors list */}
104
105
  <RootErrorsList />
105
- </Form.Root>
106
+ </>
106
107
  );
107
108
  },
108
109
 
@@ -11,3 +11,4 @@ export * from './errors';
11
11
  export * from './form';
12
12
  export * from './submit';
13
13
  export * from './zod';
14
+ export type { Register } from '../Register';
@@ -4,4 +4,4 @@ export type * from './relay';
4
4
  export type * from './submit';
5
5
  export type * from './trpc';
6
6
  export type * from './zod';
7
- export type { Register } from '../Register';
7
+ export type { FlatFieldErrors } from '../errors/flat/types';
@@ -15,15 +15,19 @@ export type RhfUtilsClientConfig = {
15
15
  */
16
16
  defaults?: UseRhfUtilsFormGlobalDefaults;
17
17
  /**
18
- * Supply your own `<form>` component. (By default, a native {@link HTMLFormElement} is used.)
18
+ * Supply your own `<form>` component.
19
19
  *
20
- * @description
20
+ * (By default, a native {@link HTMLFormElement} is used.)
21
+ */
22
+ FormComponent?: React.FC<React.PropsWithChildren<React.HTMLAttributes<HTMLFormElement>>>;
23
+ /**
24
+ * Inject your own hooks, components, etc., into every form instance.
21
25
  *
22
- * Can be used to inject your own hooks, components, etc.
26
+ * @description
23
27
  *
24
28
  * (NOTE: context params are not schema-typed as not possible at this level.)
25
29
  */
26
- FormComponent?: React.FC<React.PropsWithChildren<RhfUtilsFormComponentProps>>;
30
+ FormChildren?: React.FC<React.PropsWithChildren<RhfUtilsFormComponentProps>>;
27
31
  /**
28
32
  * A hook that returns a callback that determines whether form can be cancelled at event-time.
29
33
  *
@@ -2,16 +2,12 @@ import { UseFormReturn } from 'react-hook-form';
2
2
  import { FormSubmitError } from '../submit/error/FormSubmitError';
3
3
  import { _Controller } from './_Controller';
4
4
  import { RhfUtilsContextProps } from './context/utils/RhfUtilsContextPropsType';
5
- import { UseRhfUtilsFormInstanceFormProps } from './defaults/form/UseRhfUtilsFormInstanceFormProps';
6
5
  import { SafeFieldValues } from './rhf/SafeFieldValuesType';
7
6
  /**
8
7
  * RhfUtilsClientConfig's FormComponent props.
9
8
  */
10
9
  export type RhfUtilsFormComponentProps<TFieldValues extends SafeFieldValues = SafeFieldValues, TTransformedValues extends SafeFieldValues = TFieldValues> = RhfUtilsContextProps & {
11
10
  rhf: UseFormReturn<TFieldValues, unknown, TTransformedValues>;
12
- formProps: UseRhfUtilsFormInstanceFormProps & {
13
- onSubmit: NonNullable<React.PropsWithoutRef<React.JSX.IntrinsicElements['form']>['onSubmit']>;
14
- };
15
11
  Controller: typeof _Controller<TFieldValues>;
16
12
  FormSubmitError: typeof FormSubmitError<TFieldValues>;
17
13
  };
@@ -1,25 +1,25 @@
1
- import { jsx as c, jsxs as X } from "react/jsx-runtime";
2
- import u from "react";
3
- import { c as L, u as v, g as Y, i as D, _ as tt } from "./getFlatFieldErrors.mjs";
1
+ import { jsx as u, jsxs as X } from "react/jsx-runtime";
2
+ import c from "react";
3
+ import { c as j, u as v, g as Y, i as _, _ as tt } from "./getFlatFieldErrors.mjs";
4
4
  import { Controller as rt, useFormContext as b, useFormState as I, useWatch as et, useForm as ot, FormProvider as st } from "react-hook-form";
5
5
  import { zodResolver as nt } from "@hookform/resolvers/zod";
6
- const B = u.createContext(void 0), er = ({
6
+ const L = c.createContext(void 0), or = ({
7
7
  config: t,
8
8
  children: r
9
9
  }) => {
10
- const [e] = u.useState(t ?? {});
11
- return /* @__PURE__ */ c(B.Provider, { value: e, children: r });
10
+ const [e] = c.useState(t ?? {});
11
+ return /* @__PURE__ */ u(L.Provider, { value: e, children: r });
12
12
  }, {
13
13
  Provider: it,
14
- useRequired: M
15
- } = L(), or = () => {
16
- const t = M();
17
- return u.useMemo(() => !t.hasErrors || !t.hasOrphans ? !1 : Object.keys(t.orphans).length === Object.keys(t.all).length, [t]);
18
- }, N = "data-rhfutils-nonfield-error-marker-path", sr = ({ path: t }) => {
14
+ useRequired: B
15
+ } = j(), sr = () => {
16
+ const t = B();
17
+ return c.useMemo(() => !t.hasErrors || !t.hasOrphans ? !1 : Object.keys(t.orphans).length === Object.keys(t.all).length, [t]);
18
+ }, M = "data-rhfutils-nonfield-error-marker-path", nr = ({ path: t }) => {
19
19
  const r = {
20
- [N]: t
20
+ [M]: t
21
21
  };
22
- return /* @__PURE__ */ c(
22
+ return /* @__PURE__ */ u(
23
23
  "div",
24
24
  {
25
25
  role: "alert",
@@ -28,13 +28,13 @@ const B = u.createContext(void 0), er = ({
28
28
  ...r
29
29
  }
30
30
  );
31
- }, ut = (t) => u.useCallback(
31
+ }, ct = (t) => c.useCallback(
32
32
  (r) => {
33
33
  if (!t.current) throw new Error();
34
- ct(t.current, r);
34
+ ut(t.current, r);
35
35
  },
36
36
  [t]
37
- ), ct = (t, r) => {
37
+ ), ut = (t, r) => {
38
38
  t.requestSubmit(r);
39
39
  };
40
40
  class E extends Error {
@@ -44,21 +44,21 @@ class E extends Error {
44
44
  }
45
45
  const {
46
46
  Provider: lt,
47
- useRequired: q
48
- } = L(), nr = () => q().current, at = u.lazy(
47
+ useRequired: N
48
+ } = j(), ir = () => N().current, at = c.lazy(
49
49
  () => import("@hookform/devtools").then((t) => ({
50
50
  default: t.DevTool
51
51
  }))
52
52
  ), mt = ({ config: t }) => {
53
- const [r] = u.useState(t);
53
+ const [r] = c.useState(t);
54
54
  if (!r) return null;
55
55
  const e = typeof r == "object" ? r : void 0;
56
- return /* @__PURE__ */ c(u.Suspense, { children: /* @__PURE__ */ c(at, { ...e }) });
56
+ return /* @__PURE__ */ u(c.Suspense, { children: /* @__PURE__ */ u(at, { ...e }) });
57
57
  }, ft = () => {
58
58
  const t = v();
59
- return /* @__PURE__ */ c(mt, { config: t.options.devTool });
60
- }, H = (t) => /* @__PURE__ */ c(rt, { ...t }), R = () => {
61
- const t = u.useContext(B);
59
+ return /* @__PURE__ */ u(mt, { config: t.options.devTool });
60
+ }, q = (t) => /* @__PURE__ */ u(rt, { ...t }), C = () => {
61
+ const t = c.useContext(L);
62
62
  if (t === void 0) throw new Error();
63
63
  return t;
64
64
  }, dt = () => {
@@ -77,7 +77,7 @@ const {
77
77
  return Promise.resolve(t());
78
78
  };
79
79
  }, Ft = (t) => {
80
- const { useCanFormBeCancelled: r } = R(), e = dt();
80
+ const { useCanFormBeCancelled: r } = C(), e = dt();
81
81
  return ht(
82
82
  t,
83
83
  r,
@@ -88,13 +88,13 @@ const {
88
88
  Children: r
89
89
  }) => {
90
90
  const e = b(), o = v(), s = Ft(t);
91
- return /* @__PURE__ */ c(
91
+ return /* @__PURE__ */ u(
92
92
  r,
93
93
  {
94
94
  ...o,
95
95
  rhf: e,
96
96
  onCancel: s,
97
- Controller: H,
97
+ Controller: q,
98
98
  FormSubmitError: E
99
99
  }
100
100
  );
@@ -106,23 +106,25 @@ const {
106
106
  ...o
107
107
  });
108
108
  });
109
- }, pt = (t, r, e) => ({
109
+ }, pt = ({
110
+ children: t
111
+ }) => t, Et = (t, r, e) => ({
110
112
  ...t,
111
113
  ...r,
112
114
  className: [t?.className, r?.className, e?.className].filter(Boolean).join(" ").trim() || void 0
113
115
  // replace empty string with undefined
114
- }), Et = (t, r, e) => {
115
- const o = R();
116
+ }), vt = (t, r, e) => {
117
+ const o = C();
116
118
  return {
117
119
  id: r,
118
- ...pt(
120
+ ...Et(
119
121
  o.defaults?.form,
120
122
  t,
121
123
  e
122
124
  )
123
125
  };
124
- }, vt = (t) => {
125
- const r = q();
126
+ }, Ct = (t) => {
127
+ const r = N();
126
128
  return async function(e) {
127
129
  try {
128
130
  return r.reset(), await t(e);
@@ -136,17 +138,17 @@ const {
136
138
  onError: e,
137
139
  onFinally: o
138
140
  }) => {
139
- const s = b(), { options: n, lastSubmitStateRef: i } = v(), a = s.handleSubmit(t, r), m = vt(a);
141
+ const s = b(), { options: n, lastSubmitStateRef: i } = v(), a = s.handleSubmit(t, r), m = Ct(a);
140
142
  return (l) => {
141
143
  i.current = "submitting", n.stopSubmitPropagation && l.stopPropagation(), Promise.resolve(m(l)).then(() => {
142
144
  i.current = "success";
143
- }).catch((h) => {
144
- i.current = "error", e(h, l);
145
+ }).catch((d) => {
146
+ i.current = "error", e(d, l);
145
147
  }).finally(() => {
146
148
  o?.();
147
149
  });
148
150
  };
149
- }, Ct = ({
151
+ }, gt = ({
150
152
  getApiData: t,
151
153
  // handlers
152
154
  onSubmitInvalid: r,
@@ -160,29 +162,29 @@ const {
160
162
  form: m,
161
163
  className: l,
162
164
  //
163
- children: h
165
+ children: d
164
166
  }) => {
165
- const f = b(), d = v(), S = R(), P = Et(
167
+ const f = b(), h = v(), S = C(), P = vt(
166
168
  m,
167
- d.formId,
169
+ h.formId,
168
170
  {
169
171
  className: l
170
172
  }
171
- ), y = S.FormComponent ?? "form", x = async (F, U) => {
172
- const p = f.getValues(), G = t?.(F), C = { input: p, output: F, api: G }, g = {
173
- utils: d,
173
+ ), y = async (F, U) => {
174
+ const p = f.getValues(), G = t?.(F), R = { input: p, output: F, api: G }, g = {
175
+ utils: h,
174
176
  rhf: f,
175
177
  FormSubmitError: E
176
178
  }, O = U;
177
- e && await gt(e, C, g, O), await Promise.resolve(o?.(C, g, O));
179
+ e && await Ot(e, R, g, O), await Promise.resolve(o?.(R, g, O));
178
180
  const K = await Promise.resolve(
179
- s?.(C, g, O)
181
+ s?.(R, g, O)
180
182
  );
181
- d.lastSubmitStateRef.current = "success", await Promise.resolve(
182
- n?.(K, C, g, O)
183
+ h.lastSubmitStateRef.current = "success", await Promise.resolve(
184
+ n?.(K, R, g, O)
183
185
  );
184
186
  };
185
- function W(F, U) {
187
+ function x(F, U) {
186
188
  const p = F instanceof E ? (
187
189
  // consumer can manually throw FormSubmitError (e.g., manual validation)
188
190
  F.errors
@@ -193,7 +195,7 @@ const {
193
195
  p && St(f, p), i?.(
194
196
  F,
195
197
  {
196
- utils: d,
198
+ utils: h,
197
199
  errors: p,
198
200
  rhf: f
199
201
  },
@@ -202,34 +204,27 @@ const {
202
204
  );
203
205
  }
204
206
  const V = Rt({
205
- onValid: x,
207
+ onValid: y,
206
208
  onInvalid: r,
207
- onError: W,
209
+ onError: x,
208
210
  onFinally: a
209
- }), _ = {
210
- ...P,
211
- id: d.formId,
212
- onSubmit: V
213
- };
214
- if (!S.FormComponent)
215
- return /* @__PURE__ */ c("form", { ref: d.formRef, ..._, children: h });
216
- const $ = {
217
- ...d,
218
- formProps: _,
211
+ }), W = {
212
+ ...h,
219
213
  rhf: f,
220
- Controller: H,
214
+ Controller: q,
221
215
  FormSubmitError: E
222
- };
223
- return /* @__PURE__ */ c(
224
- y,
216
+ }, Q = S.FormComponent ?? "form", $ = S.FormChildren ?? pt;
217
+ return /* @__PURE__ */ u(
218
+ Q,
225
219
  {
226
- ref: d.formRef,
227
- id: d.formId,
228
- ...$,
229
- children: h
220
+ ...P,
221
+ id: h.formId,
222
+ ref: h.formRef,
223
+ onSubmit: V,
224
+ children: /* @__PURE__ */ u($, { ...W, children: d })
230
225
  }
231
226
  );
232
- }, gt = async (t, r, e, o) => {
227
+ }, Ot = async (t, r, e, o) => {
233
228
  const n = (await Promise.resolve(
234
229
  t(r, e, o)
235
230
  )).filter(([, , i]) => !i).map(([i, a]) => [i, { message: a }]);
@@ -237,7 +232,7 @@ const {
237
232
  throw new e.FormSubmitError(
238
233
  Object.fromEntries(n)
239
234
  );
240
- }, z = ({
235
+ }, H = ({
241
236
  getApiData: t,
242
237
  // handlers
243
238
  onCancel: r,
@@ -251,10 +246,10 @@ const {
251
246
  //
252
247
  Children: l,
253
248
  // attrs
254
- form: h,
249
+ form: d,
255
250
  className: f
256
251
  }) => /* @__PURE__ */ X(
257
- Ct,
252
+ gt,
258
253
  {
259
254
  getApiData: t,
260
255
  onSubmitInvalid: e,
@@ -264,11 +259,11 @@ const {
264
259
  onSubmitSuccess: i,
265
260
  onSubmitError: a,
266
261
  onSubmitFinally: m,
267
- form: h,
262
+ form: d,
268
263
  className: f,
269
264
  children: [
270
- /* @__PURE__ */ c(ft, {}),
271
- /* @__PURE__ */ c(
265
+ /* @__PURE__ */ u(ft, {}),
266
+ /* @__PURE__ */ u(
272
267
  bt,
273
268
  {
274
269
  onCancel: r,
@@ -277,18 +272,18 @@ const {
277
272
  )
278
273
  ]
279
274
  }
280
- ), ir = (t) => /* @__PURE__ */ c(z, { ...t }), k = (t) => (r) => (
275
+ ), cr = (t) => /* @__PURE__ */ u(H, { ...t }), k = (t) => (r) => (
281
276
  // re-create object from entries
282
277
  Object.fromEntries(
283
278
  // break down to entries
284
279
  Object.entries(r).filter(t)
285
280
  )
286
- ), A = (t) => !!t.ref, Ot = ([
281
+ ), z = (t) => !!t.ref, Pt = ([
287
282
  ,
288
283
  t
289
- ]) => A(t), Pt = k(
290
- Ot
291
- ), yt = (t, r) => (
284
+ ]) => z(t), yt = k(
285
+ Pt
286
+ ), xt = (t, r) => (
292
287
  // list of selector variants
293
288
  [
294
289
  // equals
@@ -301,48 +296,48 @@ const {
301
296
  "."
302
297
  ]
303
298
  ].map(
304
- ([e, o]) => xt(
305
- N + e,
299
+ ([e, o]) => Ut(
300
+ M + e,
306
301
  t + o
307
302
  )
308
303
  ).join(", ")
309
- ), xt = (t, r) => `[role="alert"][${t}="${r}"]`, Ut = (t, r) => !!r.querySelector(
310
- yt(t)
311
- ), T = "root", Z = (t) => t === T || t.startsWith(T + "."), wt = (t, r, e) => (
304
+ ), Ut = (t, r) => `[role="alert"][${t}="${r}"]`, wt = (t, r) => !!r.querySelector(
305
+ xt(t)
306
+ ), D = "root", A = (t) => t === D || t.startsWith(D + "."), It = (t, r, e) => (
312
307
  // non-field
313
- !A(r) && // non-root
314
- !Z(t) && // not marked in DOM
315
- !Ut(t, e)
316
- ), It = (t) => ([r, e]) => wt(r, e, t), kt = (t, r) => k(
317
- It(r)
318
- )(t), Wt = ([t]) => Z(t), Vt = k(
308
+ !z(r) && // non-root
309
+ !A(t) && // not marked in DOM
310
+ !wt(t, e)
311
+ ), kt = (t) => ([r, e]) => It(r, e, t), Vt = (t, r) => k(
312
+ kt(r)
313
+ )(t), Wt = ([t]) => A(t), _t = k(
319
314
  Wt
320
- ), _t = ({
315
+ ), Dt = ({
321
316
  formRef: t,
322
317
  children: r
323
318
  }) => {
324
319
  const { errors: e } = I(), o = Y(e), s = (
325
320
  // eslint-disable-next-line react-hooks/refs
326
- t.current ? kt(
321
+ t.current ? Vt(
327
322
  o,
328
323
  // eslint-disable-next-line react-hooks/refs
329
324
  t.current
330
325
  ) : {}
331
326
  ), n = {
332
327
  all: o,
333
- fields: Pt(o),
334
- roots: Vt(o),
328
+ fields: yt(o),
329
+ roots: _t(o),
335
330
  orphans: s,
336
331
  // computed
337
- hasErrors: !D(e),
338
- hasOrphans: !D(s)
332
+ hasErrors: !_(e),
333
+ hasOrphans: !_(s)
339
334
  };
340
- return /* @__PURE__ */ c(it, { value: n, children: r });
341
- }, Dt = ({
335
+ return /* @__PURE__ */ u(it, { value: n, children: r });
336
+ }, Tt = ({
342
337
  children: t
343
338
  }) => {
344
- const [r, e] = u.useState(void 0);
345
- return /* @__PURE__ */ c(
339
+ const [r, e] = c.useState(void 0);
340
+ return /* @__PURE__ */ u(
346
341
  lt,
347
342
  {
348
343
  value: {
@@ -357,38 +352,38 @@ const {
357
352
  children: t
358
353
  }
359
354
  );
360
- }, Tt = (t, r, e, o = "debug") => {
355
+ }, jt = (t, r, e, o = "debug") => {
361
356
  console[o](t, { values: r, errors: e });
362
- }, jt = (t) => {
363
- const r = b(), e = M();
364
- u.useEffect(() => {
357
+ }, Lt = (t) => {
358
+ const r = b(), e = B();
359
+ c.useEffect(() => {
365
360
  if (!e.hasErrors) return;
366
361
  const o = t?.console?.(e);
367
- o && Tt(
368
- o.message ?? j,
362
+ o && jt(
363
+ o.message ?? T,
369
364
  r.getValues(),
370
365
  e,
371
366
  o.type
372
367
  );
373
368
  const s = t?.throw?.(e);
374
369
  if (s)
375
- throw new Error(typeof s == "string" ? s : j);
370
+ throw new Error(typeof s == "string" ? s : T);
376
371
  }, [e]);
377
- }, j = "Form errors", Lt = (t) => {
378
- const r = u.useRef(!1);
379
- return u.useEffect(() => {
372
+ }, T = "Form errors", Bt = (t) => {
373
+ const r = c.useRef(!1);
374
+ return c.useEffect(() => {
380
375
  t && (r.current = !0);
381
376
  }, [t]), [r, () => {
382
377
  r.current = !1;
383
378
  }];
384
- }, Bt = (t, r) => {
385
- const { isSubmitSuccessful: e, isSubmitting: o } = I(), [s, n] = Lt(o);
386
- u.useEffect(() => {
379
+ }, Mt = (t, r) => {
380
+ const { isSubmitSuccessful: e, isSubmitting: o } = I(), [s, n] = Bt(o);
381
+ c.useEffect(() => {
387
382
  t && (o || s.current && (n(), t(e)));
388
383
  }, [o]);
389
- }, Mt = (t) => {
384
+ }, Nt = (t) => {
390
385
  const { getValues: r, reset: e } = b();
391
- Bt((o) => {
386
+ Mt((o) => {
392
387
  if (!t) return;
393
388
  const s = t[o ? "success" : "error"]?.values;
394
389
  if (!s) return;
@@ -415,21 +410,21 @@ const {
415
410
  keepErrors: !0
416
411
  });
417
412
  });
418
- }, Nt = () => {
419
- const t = u.useRef(w);
420
- return u.useEffect(() => (t.current && (t.current = !w), () => {
413
+ }, qt = () => {
414
+ const t = c.useRef(w);
415
+ return c.useEffect(() => (t.current && (t.current = !w), () => {
421
416
  t.current = w;
422
417
  }), []), t;
423
- }, w = !0, qt = ({
418
+ }, w = !0, Ht = ({
424
419
  onChange: t,
425
420
  delay: r
426
421
  }) => {
427
- const e = u.useRef(null), o = () => {
422
+ const e = c.useRef(null), o = () => {
428
423
  e.current && (t(e.current.value), e.current = null);
429
424
  }, s = () => {
430
425
  e.current && clearTimeout(e.current.timer);
431
426
  };
432
- return u.useEffect(
427
+ return c.useEffect(
433
428
  // return timeout clearer
434
429
  () => s,
435
430
  []
@@ -441,8 +436,8 @@ const {
441
436
  timer: setTimeout(o, r)
442
437
  };
443
438
  }];
444
- }, Ht = (t, r) => {
445
- const e = ut(t), [o] = qt({
439
+ }, zt = (t, r) => {
440
+ const e = ct(t), [o] = Ht({
446
441
  delay: r?.debounce ?? 0,
447
442
  // on change value after debounce
448
443
  onChange: () => {
@@ -450,11 +445,11 @@ const {
450
445
  }
451
446
  });
452
447
  return o;
453
- }, zt = (t, r) => {
454
- const e = Ht(t, {
448
+ }, At = (t, r) => {
449
+ const e = zt(t, {
455
450
  debounce: r?.debounce
456
- }), o = et(), { isValid: s, isDirty: n, isValidating: i, isSubmitting: a } = I(), m = u.useMemo(() => JSON.stringify(o), [o]), l = Nt();
457
- u.useEffect(
451
+ }), o = et(), { isValid: s, isDirty: n, isValidating: i, isSubmitting: a } = I(), m = c.useMemo(() => JSON.stringify(o), [o]), l = qt();
452
+ c.useEffect(
458
453
  // on form values/state change, call callback
459
454
  () => {
460
455
  l.current || i || a || s && n && e(o);
@@ -466,20 +461,20 @@ const {
466
461
  // - isSubmitting not included bc would create infinite loop of submits after first submission
467
462
  // - expect form to block changes while submitting to avoid changes that get swallowed
468
463
  );
469
- }, At = ({
464
+ }, Zt = ({
470
465
  formId: t,
471
466
  formRef: r,
472
467
  options: e,
473
468
  //
474
469
  children: o
475
470
  }) => {
476
- const [s] = u.useState(e), n = R();
477
- jt(n.fieldErrors?.output), (s.submitOnWatch ? zt : void 0)?.(
471
+ const [s] = c.useState(e), n = C();
472
+ Lt(n.fieldErrors?.output), (s.submitOnWatch ? At : void 0)?.(
478
473
  r,
479
474
  s.submitOnWatch
480
- ), Mt(s.resetOnSubmitted);
481
- const i = u.useRef(null);
482
- return /* @__PURE__ */ c(
475
+ ), Nt(s.resetOnSubmitted);
476
+ const i = c.useRef(null);
477
+ return /* @__PURE__ */ u(
483
478
  tt,
484
479
  {
485
480
  value: {
@@ -491,7 +486,7 @@ const {
491
486
  children: o
492
487
  }
493
488
  );
494
- }, Zt = (t, r) => ({
489
+ }, Jt = (t, r) => ({
495
490
  ...t,
496
491
  ...r,
497
492
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- false positive
@@ -501,19 +496,19 @@ const {
501
496
  ...r?.resetOnSubmitted
502
497
  }
503
498
  }
504
- }), Jt = (t, r) => u.useMemo(
505
- () => Zt(t.defaults?.options, r),
499
+ }), Qt = (t, r) => c.useMemo(
500
+ () => Jt(t.defaults?.options, r),
506
501
  // eslint-disable-next-line react-hooks/exhaustive-deps
507
502
  [JSON.stringify(r)]
508
- ), Qt = (t, r) => ({
503
+ ), $t = (t, r) => ({
509
504
  ...t,
510
505
  ...r
511
- }), $t = (t, r, e, o) => ot({
512
- ...Qt(r.defaults?.rhf, t),
506
+ }), Gt = (t, r, e, o) => ot({
507
+ ...$t(r.defaults?.rhf, t),
513
508
  resolver: o,
514
509
  defaultValues: e
515
510
  });
516
- function J({
511
+ function Z({
517
512
  formId: t,
518
513
  rhf: r,
519
514
  resolver: e,
@@ -522,28 +517,28 @@ function J({
522
517
  //
523
518
  children: n
524
519
  }) {
525
- const i = R(), a = u.useId(), m = t || a, l = u.useRef(null), h = $t(
520
+ const i = C(), a = c.useId(), m = t || a, l = c.useRef(null), d = Gt(
526
521
  r,
527
522
  i,
528
523
  o,
529
524
  e
530
- ), f = Jt(i, s);
531
- return /* @__PURE__ */ c(st, { ...h, children: /* @__PURE__ */ c(_t, { formRef: l, children: /* @__PURE__ */ c(
532
- At,
525
+ ), f = Qt(i, s);
526
+ return /* @__PURE__ */ u(st, { ...d, children: /* @__PURE__ */ u(Dt, { formRef: l, children: /* @__PURE__ */ u(
527
+ Zt,
533
528
  {
534
529
  formId: m,
535
530
  formRef: l,
536
531
  options: f,
537
- children: /* @__PURE__ */ c(Dt, { children: n })
532
+ children: /* @__PURE__ */ u(Tt, { children: n })
538
533
  }
539
534
  ) }) });
540
535
  }
541
- const Q = (t) => nt(t), ur = ({
536
+ const J = (t) => nt(t), ur = ({
542
537
  schema: t,
543
538
  children: r,
544
539
  ...e
545
- }) => /* @__PURE__ */ c(J, { ...e, resolver: Q(t), children: r });
546
- function Gt({
540
+ }) => /* @__PURE__ */ u(Z, { ...e, resolver: J(t), children: r });
541
+ function Kt({
547
542
  getApiData: t,
548
543
  // provider
549
544
  resolver: r,
@@ -556,49 +551,49 @@ function Gt({
556
551
  onBeforeSubmitInvariants: a,
557
552
  onBeforeSubmit: m,
558
553
  onSubmit: l,
559
- onSubmitSuccess: h,
554
+ onSubmitSuccess: d,
560
555
  onSubmitError: f,
561
- onSubmitFinally: d,
556
+ onSubmitFinally: h,
562
557
  Children: S,
563
558
  form: P,
564
559
  formId: y,
565
560
  className: x
566
561
  }) {
567
- return /* @__PURE__ */ c(J, { ...{
562
+ return /* @__PURE__ */ u(Z, { ...{
568
563
  formId: y,
569
564
  resolver: r,
570
565
  rhf: e,
571
566
  defaultValues: o,
572
567
  options: s
573
- }, children: /* @__PURE__ */ c(z, { ...{
568
+ }, children: /* @__PURE__ */ u(H, { ...{
574
569
  getApiData: t,
575
570
  onCancel: n,
576
571
  onSubmitInvalid: i,
577
572
  onBeforeSubmitInvariants: a,
578
573
  onBeforeSubmit: m,
579
574
  onSubmit: l,
580
- onSubmitSuccess: h,
575
+ onSubmitSuccess: d,
581
576
  onSubmitError: f,
582
- onSubmitFinally: d,
577
+ onSubmitFinally: h,
583
578
  Children: S,
584
579
  form: P,
585
580
  className: x
586
581
  } }) });
587
582
  }
588
- const cr = ({
583
+ const lr = ({
589
584
  schema: t,
590
585
  ...r
591
- }) => /* @__PURE__ */ c(Gt, { ...r, resolver: Q(t) });
586
+ }) => /* @__PURE__ */ u(Kt, { ...r, resolver: J(t) });
592
587
  export {
593
588
  E as FormSubmitError,
594
- er as RhfUtilsClientConfigProvider,
595
- sr as RhfUtilsNonFieldErrorMarker,
596
- ir as RhfUtilsZodForm,
589
+ or as RhfUtilsClientConfigProvider,
590
+ nr as RhfUtilsNonFieldErrorMarker,
591
+ cr as RhfUtilsZodForm,
597
592
  ur as RhfUtilsZodFormProviders,
598
- cr as RhfUtilsZodFormWithProviders,
599
- M as useFlatFieldErrorsContext,
600
- or as useFlatFieldErrorsContextHasOnlyOrphans,
601
- ut as useFormRequestSubmit,
602
- nr as useLastSubmitError,
593
+ lr as RhfUtilsZodFormWithProviders,
594
+ B as useFlatFieldErrorsContext,
595
+ sr as useFlatFieldErrorsContextHasOnlyOrphans,
596
+ ct as useFormRequestSubmit,
597
+ ir as useLastSubmitError,
603
598
  v as useRhfUtilsContext
604
599
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@paragrav/rhf-utils",
3
3
  "author": "paragrav.dev",
4
- "version": "0.59.0",
4
+ "version": "0.61.0",
5
5
  "description": "Integration utilities for react-hook-form.",
6
6
  "type": "module",
7
7
  "sideEffects": false,