@paragrav/rhf-utils 0.60.0 → 0.62.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.
Files changed (46) hide show
  1. package/README.md +57 -96
  2. package/dist/dts/_exports/relay.d.ts +7 -8
  3. package/dist/dts/_exports/types.d.ts +1 -0
  4. package/dist/dts/client/config/RhfUtilsClientConfigType.d.ts +8 -4
  5. package/dist/dts/errors/flat/getFlatFieldErrors.d.ts +5 -1
  6. package/dist/dts/form/RhfUtilsFormComponentPropsType.d.ts +2 -6
  7. package/dist/dts/form/UseRhfUtilsFormChildrenPropsType.d.ts +2 -2
  8. package/dist/dts/form/context/utils/LastSubmitStateType.d.ts +1 -0
  9. package/dist/dts/form/context/utils/{RhfUtilsContextPropsType.d.ts → RhfUtilsContextType.d.ts} +3 -2
  10. package/dist/dts/form/context/utils/useRhfUtilsContext.d.ts +4 -4
  11. package/dist/dts/form/defaults/form/useRhfUtilsFormResolvedFormProps.d.ts +10 -10
  12. package/dist/dts/form/providers/RhfUtilsFormProviders.d.ts +1 -1
  13. package/dist/dts/form/providers/RhfUtilsFormProvidersPropsType.d.ts +2 -0
  14. package/dist/dts/form/relay/FormRelayOptions.d.ts +16 -0
  15. package/dist/dts/form/{state/relay/FormStateRelayContextProvider.d.ts → relay/context/FormRelayContextProvider.d.ts} +1 -1
  16. package/dist/dts/form/relay/context/useFormRelayContext.d.ts +12 -0
  17. package/dist/dts/form/relay/context/utils.d.ts +4 -0
  18. package/dist/dts/form/relay/get/FormRelayGroupType.d.ts +16 -0
  19. package/dist/dts/form/relay/get/grouper/context/hooks.d.ts +8 -0
  20. package/dist/dts/form/relay/get/grouper/context/index.d.ts +5 -0
  21. package/dist/dts/form/relay/get/grouper/context/provider.d.ts +9 -0
  22. package/dist/dts/form/relay/get/grouper/useFirstFormStateGroup.d.ts +9 -0
  23. package/dist/dts/form/relay/get/useFormRelay.d.ts +13 -0
  24. package/dist/dts/form/relay/set/FormRelaySetter.d.ts +6 -0
  25. package/dist/dts/form/relay/set/useFormRelaySet.d.ts +2 -0
  26. package/dist/dts/form/relay/types.d.ts +12 -0
  27. package/dist/dts/form/with-handlers-and-children/RhfUtilsFormProps.d.ts +5 -1
  28. package/dist/dts/form/with-handlers-and-children/_useHandleSubmit.d.ts +1 -1
  29. package/dist/dts/form/with-providers/RhfUtilsFormWithProviders.d.ts +1 -1
  30. package/dist/dts/submit/UseRhfUtilsFormOnSubmitContextType.d.ts +3 -3
  31. package/dist/dts/submit/last-error/useLastSubmitErrorContextWith.d.ts +1 -1
  32. package/dist/esm/FormRelaySetter.mjs +140 -0
  33. package/dist/esm/index.mjs +203 -202
  34. package/dist/esm/relay.mjs +71 -209
  35. package/package.json +17 -17
  36. package/dist/dts/form/RhfUtilsFormStateWithUtilsType.d.ts +0 -7
  37. package/dist/dts/form/state/relay/FormStateRelayedAggregatedType.d.ts +0 -10
  38. package/dist/dts/form/state/relay/FormStateRelayedItemType.d.ts +0 -11
  39. package/dist/dts/form/state/relay/FormStateRelayedOptionsType.d.ts +0 -20
  40. package/dist/dts/form/state/relay/FormStateRelayedType.d.ts +0 -3
  41. package/dist/dts/form/state/relay/pull/hooks.d.ts +0 -31
  42. package/dist/dts/form/state/relay/push/FormStateRelayPusher.d.ts +0 -4
  43. package/dist/dts/form/state/relay/push/useFormStateRelayPusher.d.ts +0 -3
  44. package/dist/dts/form/state/relay/useFormStateRelayContext.d.ts +0 -20
  45. package/dist/dts/form/state/relay/utils.d.ts +0 -4
  46. package/dist/esm/getFlatFieldErrors.mjs +0 -55
@@ -1,23 +1,23 @@
1
- import { jsx as c, jsxs as X } from "react/jsx-runtime";
1
+ import { jsx as c, jsxs as L } from "react/jsx-runtime";
2
2
  import u from "react";
3
- import { c as L, u as v, g as Y, i as D, _ as tt } from "./getFlatFieldErrors.mjs";
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
- import { zodResolver as nt } from "@hookform/resolvers/zod";
6
- const B = u.createContext(void 0), er = ({
3
+ import { F as Y, c as B, u as v, g as tt, i as D, _ as rt, a as et } from "./FormRelaySetter.mjs";
4
+ import { Controller as ot, useFormContext as b, useFormState as k, useWatch as st, useForm as nt, FormProvider as it } from "react-hook-form";
5
+ import { zodResolver as ct } from "@hookform/resolvers/zod";
6
+ const M = u.createContext(void 0), nr = ({
7
7
  config: t,
8
8
  children: r
9
9
  }) => {
10
10
  const [e] = u.useState(t ?? {});
11
- return /* @__PURE__ */ c(B.Provider, { value: e, children: r });
11
+ return /* @__PURE__ */ c(M.Provider, { value: e, children: /* @__PURE__ */ c(Y, { children: r }) });
12
12
  }, {
13
- Provider: it,
14
- useRequired: M
15
- } = L(), or = () => {
16
- const t = M();
13
+ Provider: ut,
14
+ useRequired: N
15
+ } = B(), ir = () => {
16
+ const t = N();
17
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 }) => {
18
+ }, q = "data-rhfutils-nonfield-error-marker-path", cr = ({ path: t }) => {
19
19
  const r = {
20
- [N]: t
20
+ [q]: t
21
21
  };
22
22
  return /* @__PURE__ */ c(
23
23
  "div",
@@ -28,13 +28,13 @@ const B = u.createContext(void 0), er = ({
28
28
  ...r
29
29
  }
30
30
  );
31
- }, ut = (t) => u.useCallback(
31
+ }, lt = (t) => u.useCallback(
32
32
  (r) => {
33
33
  if (!t.current) throw new Error();
34
- ct(t.current, r);
34
+ at(t.current, r);
35
35
  },
36
36
  [t]
37
- ), ct = (t, r) => {
37
+ ), at = (t, r) => {
38
38
  t.requestSubmit(r);
39
39
  };
40
40
  class E extends Error {
@@ -43,32 +43,32 @@ class E extends Error {
43
43
  }
44
44
  }
45
45
  const {
46
- Provider: lt,
47
- useRequired: q
48
- } = L(), nr = () => q().current, at = u.lazy(
46
+ Provider: mt,
47
+ useRequired: H
48
+ } = B(), ur = () => H().current, dt = u.lazy(
49
49
  () => import("@hookform/devtools").then((t) => ({
50
50
  default: t.DevTool
51
51
  }))
52
- ), mt = ({ config: t }) => {
52
+ ), ft = ({ config: t }) => {
53
53
  const [r] = u.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 }) });
57
- }, ft = () => {
56
+ return /* @__PURE__ */ c(u.Suspense, { children: /* @__PURE__ */ c(dt, { ...e }) });
57
+ }, ht = () => {
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__ */ c(ft, { config: t.options.devTool });
60
+ }, z = (t) => /* @__PURE__ */ c(ot, { ...t }), R = () => {
61
+ const t = u.useContext(M);
62
62
  if (t === void 0) throw new Error();
63
63
  return t;
64
- }, dt = () => {
64
+ }, Ft = () => {
65
65
  const t = v(), r = b();
66
66
  return {
67
67
  utils: t,
68
68
  rhf: r,
69
69
  FormSubmitError: E
70
70
  };
71
- }, ht = (t, r, e) => {
71
+ }, bt = (t, r, e) => {
72
72
  const o = r?.();
73
73
  return async () => {
74
74
  if (!(!t || await Promise.resolve(
@@ -76,29 +76,29 @@ const {
76
76
  ) === !1))
77
77
  return Promise.resolve(t());
78
78
  };
79
- }, Ft = (t) => {
80
- const { useCanFormBeCancelled: r } = R(), e = dt();
81
- return ht(
79
+ }, St = (t) => {
80
+ const { useCanFormBeCancelled: r } = R(), e = Ft();
81
+ return bt(
82
82
  t,
83
83
  r,
84
84
  e
85
85
  );
86
- }, bt = ({
86
+ }, pt = ({
87
87
  onCancel: t,
88
88
  Children: r
89
89
  }) => {
90
- const e = b(), o = v(), s = Ft(t);
90
+ const e = b(), o = v(), s = St(t);
91
91
  return /* @__PURE__ */ c(
92
92
  r,
93
93
  {
94
94
  ...o,
95
95
  rhf: e,
96
96
  onCancel: s,
97
- Controller: H,
97
+ Controller: z,
98
98
  FormSubmitError: E
99
99
  }
100
100
  );
101
- }, St = (t, r) => {
101
+ }, Et = (t, r) => {
102
102
  Object.entries(r).forEach(([e, o]) => {
103
103
  t.setError(e, {
104
104
  type: "FormSubmitFieldError",
@@ -106,23 +106,25 @@ const {
106
106
  ...o
107
107
  });
108
108
  });
109
- }, pt = (t, r, e) => ({
109
+ }, vt = ({
110
+ children: t
111
+ }) => t, Rt = (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) => {
116
+ }), Ct = (t, r, e) => {
115
117
  const o = R();
116
118
  return {
117
119
  id: r,
118
- ...pt(
120
+ ...Rt(
119
121
  o.defaults?.form,
120
122
  t,
121
123
  e
122
124
  )
123
125
  };
124
- }, vt = (t) => {
125
- const r = q();
126
+ }, gt = (t) => {
127
+ const r = H();
126
128
  return async function(e) {
127
129
  try {
128
130
  return r.reset(), await t(e);
@@ -130,23 +132,23 @@ const {
130
132
  throw r.set(o, e), o;
131
133
  }
132
134
  };
133
- }, Rt = ({
135
+ }, Ot = ({
134
136
  onValid: t,
135
137
  onInvalid: r,
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);
140
- return (l) => {
141
- i.current = "submitting", n.stopSubmitPropagation && l.stopPropagation(), Promise.resolve(m(l)).then(() => {
141
+ const s = b(), { options: n, lastSubmitStateRef: i } = v(), l = s.handleSubmit(t, r), m = gt(l);
142
+ return (a) => {
143
+ i.current = "submitting", n.stopSubmitPropagation && a.stopPropagation(), Promise.resolve(m(a)).then(() => {
142
144
  i.current = "success";
143
145
  }).catch((h) => {
144
- i.current = "error", e(h, l);
146
+ i.current = "error", e(h, a);
145
147
  }).finally(() => {
146
148
  o?.();
147
149
  });
148
150
  };
149
- }, Ct = ({
151
+ }, Pt = ({
150
152
  getApiData: t,
151
153
  // handlers
152
154
  onSubmitInvalid: r,
@@ -155,34 +157,34 @@ const {
155
157
  onSubmit: s,
156
158
  onSubmitSuccess: n,
157
159
  onSubmitError: i,
158
- onSubmitFinally: a,
160
+ onSubmitFinally: l,
159
161
  // other
160
162
  form: m,
161
- className: l,
163
+ className: a,
162
164
  //
163
165
  children: h
164
166
  }) => {
165
- const f = b(), d = v(), S = R(), P = Et(
167
+ const d = b(), f = v(), S = R(), P = Ct(
166
168
  m,
167
- d.formId,
169
+ f.formId,
168
170
  {
169
- className: l
171
+ className: a
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,
174
- rhf: f,
173
+ ), y = async (F, w) => {
174
+ const p = d.getValues(), K = t?.(F), C = { input: p, output: F, api: K }, g = {
175
+ utils: f,
176
+ rhf: d,
175
177
  FormSubmitError: E
176
- }, O = U;
177
- e && await gt(e, C, g, O), await Promise.resolve(o?.(C, g, O));
178
- const K = await Promise.resolve(
178
+ }, O = w;
179
+ e && await yt(e, C, g, O), await Promise.resolve(o?.(C, g, O));
180
+ const X = await Promise.resolve(
179
181
  s?.(C, g, O)
180
182
  );
181
- d.lastSubmitStateRef.current = "success", await Promise.resolve(
182
- n?.(K, C, g, O)
183
+ f.lastSubmitStateRef.current = "success", await Promise.resolve(
184
+ n?.(X, C, g, O)
183
185
  );
184
186
  };
185
- function W(F, U) {
187
+ function x(F, w) {
186
188
  const p = F instanceof E ? (
187
189
  // consumer can manually throw FormSubmitError (e.g., manual validation)
188
190
  F.errors
@@ -190,54 +192,47 @@ const {
190
192
  // if error is not FormSubmitError, consumer can provide global handler
191
193
  S.onSubmitErrorUnknown?.(F)
192
194
  );
193
- p && St(f, p), i?.(
195
+ p && Et(d, p), i?.(
194
196
  F,
195
197
  {
196
- utils: d,
198
+ utils: f,
197
199
  errors: p,
198
- rhf: f
200
+ rhf: d
199
201
  },
200
- U
202
+ w
201
203
  // `as` required due to conditional generic
202
204
  );
203
205
  }
204
- const V = Rt({
205
- onValid: x,
206
+ const U = Ot({
207
+ onValid: y,
206
208
  onInvalid: r,
207
- onError: W,
208
- 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: _,
219
- rhf: f,
220
- Controller: H,
209
+ onError: x,
210
+ onFinally: l
211
+ }), W = {
212
+ ...f,
213
+ rhf: d,
214
+ Controller: z,
221
215
  FormSubmitError: E
222
- };
216
+ }, _ = S.FormComponent ?? "form", G = S.FormChildren ?? vt;
223
217
  return /* @__PURE__ */ c(
224
- y,
218
+ _,
225
219
  {
226
- ref: d.formRef,
227
- id: d.formId,
228
- ...$,
229
- children: h
220
+ ...P,
221
+ id: f.formId,
222
+ ref: f.formRef,
223
+ onSubmit: U,
224
+ children: /* @__PURE__ */ c(G, { ...W, children: h })
230
225
  }
231
226
  );
232
- }, gt = async (t, r, e, o) => {
227
+ }, yt = async (t, r, e, o) => {
233
228
  const n = (await Promise.resolve(
234
229
  t(r, e, o)
235
- )).filter(([, , i]) => !i).map(([i, a]) => [i, { message: a }]);
230
+ )).filter(({ valid: i }) => !i).map(({ field: i, message: l }) => [i, { message: l }]);
236
231
  if (n.length)
237
232
  throw new e.FormSubmitError(
238
233
  Object.fromEntries(n)
239
234
  );
240
- }, z = ({
235
+ }, A = ({
241
236
  getApiData: t,
242
237
  // handlers
243
238
  onCancel: r,
@@ -246,15 +241,15 @@ const {
246
241
  onBeforeSubmit: s,
247
242
  onSubmit: n,
248
243
  onSubmitSuccess: i,
249
- onSubmitError: a,
244
+ onSubmitError: l,
250
245
  onSubmitFinally: m,
251
246
  //
252
- Children: l,
247
+ Children: a,
253
248
  // attrs
254
249
  form: h,
255
- className: f
256
- }) => /* @__PURE__ */ X(
257
- Ct,
250
+ className: d
251
+ }) => /* @__PURE__ */ L(
252
+ Pt,
258
253
  {
259
254
  getApiData: t,
260
255
  onSubmitInvalid: e,
@@ -262,33 +257,33 @@ const {
262
257
  onBeforeSubmit: s,
263
258
  onSubmit: n,
264
259
  onSubmitSuccess: i,
265
- onSubmitError: a,
260
+ onSubmitError: l,
266
261
  onSubmitFinally: m,
267
262
  form: h,
268
- className: f,
263
+ className: d,
269
264
  children: [
270
- /* @__PURE__ */ c(ft, {}),
265
+ /* @__PURE__ */ c(ht, {}),
271
266
  /* @__PURE__ */ c(
272
- bt,
267
+ pt,
273
268
  {
274
269
  onCancel: r,
275
- Children: l
270
+ Children: a
276
271
  }
277
272
  )
278
273
  ]
279
274
  }
280
- ), ir = (t) => /* @__PURE__ */ c(z, { ...t }), k = (t) => (r) => (
275
+ ), lr = (t) => /* @__PURE__ */ c(A, { ...t }), V = (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, xt = ([
287
282
  ,
288
283
  t
289
- ]) => A(t), Pt = k(
290
- Ot
291
- ), yt = (t, r) => (
284
+ ]) => Z(t), Ut = V(
285
+ xt
286
+ ), wt = (t, r) => (
292
287
  // list of selector variants
293
288
  [
294
289
  // equals
@@ -301,49 +296,49 @@ const {
301
296
  "."
302
297
  ]
303
298
  ].map(
304
- ([e, o]) => xt(
305
- N + e,
299
+ ([e, o]) => It(
300
+ q + 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
+ ), It = (t, r) => `[role="alert"][${t}="${r}"]`, kt = (t, r) => !!r.querySelector(
305
+ wt(t)
306
+ ), T = "root", J = (t) => t === T || t.startsWith(T + "."), Vt = (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(
319
- Wt
320
- ), _t = ({
308
+ !Z(r) && // non-root
309
+ !J(t) && // not marked in DOM
310
+ !kt(t, e)
311
+ ), Wt = (t) => ([r, e]) => Vt(r, e, t), _t = (t, r) => V(
312
+ Wt(r)
313
+ )(t), Dt = ([t]) => J(t), Tt = V(
314
+ Dt
315
+ ), jt = ({
321
316
  formRef: t,
322
317
  children: r
323
318
  }) => {
324
- const { errors: e } = I(), o = Y(e), s = (
319
+ const { errors: e } = k(), o = tt(e), s = (
325
320
  // eslint-disable-next-line react-hooks/refs
326
- t.current ? kt(
321
+ t.current ? _t(
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: Ut(o),
329
+ roots: Tt(o),
335
330
  orphans: s,
336
331
  // computed
337
332
  hasErrors: !D(e),
338
333
  hasOrphans: !D(s)
339
334
  };
340
- return /* @__PURE__ */ c(it, { value: n, children: r });
341
- }, Dt = ({
335
+ return /* @__PURE__ */ c(ut, { value: n, children: r });
336
+ }, Lt = ({
342
337
  children: t
343
338
  }) => {
344
339
  const [r, e] = u.useState(void 0);
345
340
  return /* @__PURE__ */ c(
346
- lt,
341
+ mt,
347
342
  {
348
343
  value: {
349
344
  current: r,
@@ -357,14 +352,14 @@ const {
357
352
  children: t
358
353
  }
359
354
  );
360
- }, Tt = (t, r, e, o = "debug") => {
355
+ }, Bt = (t, r, e, o = "debug") => {
361
356
  console[o](t, { values: r, errors: e });
362
- }, jt = (t) => {
363
- const r = b(), e = M();
357
+ }, Mt = (t) => {
358
+ const r = b(), e = N();
364
359
  u.useEffect(() => {
365
360
  if (!e.hasErrors) return;
366
361
  const o = t?.console?.(e);
367
- o && Tt(
362
+ o && Bt(
368
363
  o.message ?? j,
369
364
  r.getValues(),
370
365
  e,
@@ -374,21 +369,21 @@ const {
374
369
  if (s)
375
370
  throw new Error(typeof s == "string" ? s : j);
376
371
  }, [e]);
377
- }, j = "Form errors", Lt = (t) => {
372
+ }, j = "Form errors", Nt = (t) => {
378
373
  const r = u.useRef(!1);
379
374
  return u.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);
379
+ }, qt = (t, r) => {
380
+ const { isSubmitSuccessful: e, isSubmitting: o } = k(), [s, n] = Nt(o);
386
381
  u.useEffect(() => {
387
382
  t && (o || s.current && (n(), t(e)));
388
383
  }, [o]);
389
- }, Mt = (t) => {
384
+ }, Ht = (t) => {
390
385
  const { getValues: r, reset: e } = b();
391
- Bt((o) => {
386
+ qt((o) => {
392
387
  if (!t) return;
393
388
  const s = t[o ? "success" : "error"]?.values;
394
389
  if (!s) return;
@@ -415,12 +410,12 @@ 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), () => {
421
- t.current = w;
413
+ }, zt = () => {
414
+ const t = u.useRef(I);
415
+ return u.useEffect(() => (t.current && (t.current = !I), () => {
416
+ t.current = I;
422
417
  }), []), t;
423
- }, w = !0, qt = ({
418
+ }, I = !0, At = ({
424
419
  onChange: t,
425
420
  delay: r
426
421
  }) => {
@@ -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 = lt(t), [o] = At({
446
441
  delay: r?.debounce ?? 0,
447
442
  // on change value after debounce
448
443
  onChange: () => {
@@ -450,14 +445,14 @@ const {
450
445
  }
451
446
  });
452
447
  return o;
453
- }, zt = (t, r) => {
454
- const e = Ht(t, {
448
+ }, Jt = (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();
451
+ }), o = st(), { isValid: s, isDirty: n, isValidating: i, isSubmitting: l } = k(), m = u.useMemo(() => JSON.stringify(o), [o]), a = zt();
457
452
  u.useEffect(
458
453
  // on form values/state change, call callback
459
454
  () => {
460
- l.current || i || a || s && n && e(o);
455
+ a.current || i || l || s && n && e(o);
461
456
  },
462
457
  // eslint-disable-next-line react-hooks/exhaustive-deps
463
458
  [s, n, m, i]
@@ -466,7 +461,7 @@ 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
+ }, Qt = ({
470
465
  formId: t,
471
466
  formRef: r,
472
467
  options: e,
@@ -474,13 +469,13 @@ const {
474
469
  children: o
475
470
  }) => {
476
471
  const [s] = u.useState(e), n = R();
477
- jt(n.fieldErrors?.output), (s.submitOnWatch ? zt : void 0)?.(
472
+ Mt(n.fieldErrors?.output), (s.submitOnWatch ? Jt : void 0)?.(
478
473
  r,
479
474
  s.submitOnWatch
480
- ), Mt(s.resetOnSubmitted);
475
+ ), Ht(s.resetOnSubmitted);
481
476
  const i = u.useRef(null);
482
477
  return /* @__PURE__ */ c(
483
- tt,
478
+ rt,
484
479
  {
485
480
  value: {
486
481
  formId: t,
@@ -491,7 +486,7 @@ const {
491
486
  children: o
492
487
  }
493
488
  );
494
- }, Zt = (t, r) => ({
489
+ }, $t = (t, r) => ({
495
490
  ...t,
496
491
  ...r,
497
492
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing -- false positive
@@ -501,104 +496,110 @@ const {
501
496
  ...r?.resetOnSubmitted
502
497
  }
503
498
  }
504
- }), Jt = (t, r) => u.useMemo(
505
- () => Zt(t.defaults?.options, r),
499
+ }), Gt = (t, r) => u.useMemo(
500
+ () => $t(t.defaults?.options, r),
506
501
  // eslint-disable-next-line react-hooks/exhaustive-deps
507
502
  [JSON.stringify(r)]
508
- ), Qt = (t, r) => ({
503
+ ), Kt = (t, r) => ({
509
504
  ...t,
510
505
  ...r
511
- }), $t = (t, r, e, o) => ot({
512
- ...Qt(r.defaults?.rhf, t),
506
+ }), Xt = (t, r, e, o) => nt({
507
+ ...Kt(r.defaults?.rhf, t),
513
508
  resolver: o,
514
509
  defaultValues: e
515
510
  });
516
- function J({
511
+ function Q({
517
512
  formId: t,
518
513
  rhf: r,
519
514
  resolver: e,
520
515
  defaultValues: o,
521
516
  options: s,
517
+ relay: n,
522
518
  //
523
- children: n
519
+ children: i
524
520
  }) {
525
- const i = R(), a = u.useId(), m = t || a, l = u.useRef(null), h = $t(
521
+ const l = R(), m = u.useId(), a = t || m, h = u.useRef(null), d = Xt(
526
522
  r,
527
- i,
523
+ l,
528
524
  o,
529
525
  e
530
- ), f = Jt(i, s);
531
- return /* @__PURE__ */ c(st, { ...h, children: /* @__PURE__ */ c(_t, { formRef: l, children: /* @__PURE__ */ c(
532
- At,
526
+ ), f = Gt(l, s);
527
+ return /* @__PURE__ */ c(it, { ...d, children: /* @__PURE__ */ c(jt, { formRef: h, children: /* @__PURE__ */ L(
528
+ Qt,
533
529
  {
534
- formId: m,
535
- formRef: l,
530
+ formId: a,
531
+ formRef: h,
536
532
  options: f,
537
- children: /* @__PURE__ */ c(Dt, { children: n })
533
+ children: [
534
+ /* @__PURE__ */ c(et, { options: n }),
535
+ /* @__PURE__ */ c(Lt, { children: i })
536
+ ]
538
537
  }
539
538
  ) }) });
540
539
  }
541
- const Q = (t) => nt(t), ur = ({
540
+ const $ = (t) => ct(t), ar = ({
542
541
  schema: t,
543
542
  children: r,
544
543
  ...e
545
- }) => /* @__PURE__ */ c(J, { ...e, resolver: Q(t), children: r });
546
- function Gt({
544
+ }) => /* @__PURE__ */ c(Q, { ...e, resolver: $(t), children: r });
545
+ function Yt({
547
546
  getApiData: t,
548
547
  // provider
549
548
  resolver: r,
550
549
  rhf: e,
551
550
  defaultValues: o,
552
551
  options: s,
552
+ relay: n,
553
553
  // form
554
- onCancel: n,
555
- onSubmitInvalid: i,
556
- onBeforeSubmitInvariants: a,
557
- onBeforeSubmit: m,
558
- onSubmit: l,
559
- onSubmitSuccess: h,
554
+ onCancel: i,
555
+ onSubmitInvalid: l,
556
+ onBeforeSubmitInvariants: m,
557
+ onBeforeSubmit: a,
558
+ onSubmit: h,
559
+ onSubmitSuccess: d,
560
560
  onSubmitError: f,
561
- onSubmitFinally: d,
562
- Children: S,
563
- form: P,
564
- formId: y,
565
- className: x
561
+ onSubmitFinally: S,
562
+ Children: P,
563
+ form: y,
564
+ formId: x,
565
+ className: U
566
566
  }) {
567
- return /* @__PURE__ */ c(J, { ...{
568
- formId: y,
567
+ return /* @__PURE__ */ c(Q, { ...{
568
+ formId: x,
569
569
  resolver: r,
570
570
  rhf: e,
571
571
  defaultValues: o,
572
- options: s
573
- }, children: /* @__PURE__ */ c(z, { ...{
572
+ options: s,
573
+ relay: n
574
+ }, children: /* @__PURE__ */ c(A, { ...{
574
575
  getApiData: t,
575
- onCancel: n,
576
- onSubmitInvalid: i,
577
- onBeforeSubmitInvariants: a,
578
- onBeforeSubmit: m,
579
- onSubmit: l,
580
- onSubmitSuccess: h,
576
+ onCancel: i,
577
+ onSubmitInvalid: l,
578
+ onBeforeSubmitInvariants: m,
579
+ onBeforeSubmit: a,
580
+ onSubmit: h,
581
+ onSubmitSuccess: d,
581
582
  onSubmitError: f,
582
- onSubmitFinally: d,
583
- Children: S,
584
- form: P,
585
- className: x
583
+ onSubmitFinally: S,
584
+ Children: P,
585
+ form: y,
586
+ className: U
586
587
  } }) });
587
588
  }
588
- const cr = ({
589
+ const mr = ({
589
590
  schema: t,
590
591
  ...r
591
- }) => /* @__PURE__ */ c(Gt, { ...r, resolver: Q(t) });
592
+ }) => /* @__PURE__ */ c(Yt, { ...r, resolver: $(t) });
592
593
  export {
593
594
  E as FormSubmitError,
594
- er as RhfUtilsClientConfigProvider,
595
- sr as RhfUtilsNonFieldErrorMarker,
596
- ir as RhfUtilsZodForm,
597
- ur as RhfUtilsZodFormProviders,
598
- cr as RhfUtilsZodFormWithProviders,
599
- M as useFlatFieldErrorsContext,
600
- or as useFlatFieldErrorsContextHasOnlyOrphans,
601
- ut as useFormRequestSubmit,
602
- nr as useLastSubmitError,
595
+ nr as RhfUtilsClientConfigProvider,
596
+ cr as RhfUtilsNonFieldErrorMarker,
597
+ lr as RhfUtilsZodForm,
598
+ ar as RhfUtilsZodFormProviders,
599
+ mr as RhfUtilsZodFormWithProviders,
600
+ N as useFlatFieldErrorsContext,
601
+ ir as useFlatFieldErrorsContextHasOnlyOrphans,
602
+ lt as useFormRequestSubmit,
603
+ ur as useLastSubmitError,
603
604
  v as useRhfUtilsContext
604
605
  };