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