@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.
- package/README.md +57 -96
- package/dist/dts/_exports/relay.d.ts +7 -8
- package/dist/dts/_exports/types.d.ts +1 -0
- package/dist/dts/client/config/RhfUtilsClientConfigType.d.ts +8 -4
- package/dist/dts/errors/flat/getFlatFieldErrors.d.ts +5 -1
- package/dist/dts/form/RhfUtilsFormComponentPropsType.d.ts +2 -6
- package/dist/dts/form/UseRhfUtilsFormChildrenPropsType.d.ts +2 -2
- package/dist/dts/form/context/utils/LastSubmitStateType.d.ts +1 -0
- package/dist/dts/form/context/utils/{RhfUtilsContextPropsType.d.ts → RhfUtilsContextType.d.ts} +3 -2
- package/dist/dts/form/context/utils/useRhfUtilsContext.d.ts +4 -4
- package/dist/dts/form/defaults/form/useRhfUtilsFormResolvedFormProps.d.ts +10 -10
- package/dist/dts/form/providers/RhfUtilsFormProviders.d.ts +1 -1
- package/dist/dts/form/providers/RhfUtilsFormProvidersPropsType.d.ts +2 -0
- package/dist/dts/form/relay/FormRelayOptions.d.ts +16 -0
- package/dist/dts/form/{state/relay/FormStateRelayContextProvider.d.ts → relay/context/FormRelayContextProvider.d.ts} +1 -1
- package/dist/dts/form/relay/context/useFormRelayContext.d.ts +12 -0
- package/dist/dts/form/relay/context/utils.d.ts +4 -0
- package/dist/dts/form/relay/get/FormRelayGroupType.d.ts +16 -0
- package/dist/dts/form/relay/get/grouper/context/hooks.d.ts +8 -0
- package/dist/dts/form/relay/get/grouper/context/index.d.ts +5 -0
- package/dist/dts/form/relay/get/grouper/context/provider.d.ts +9 -0
- package/dist/dts/form/relay/get/grouper/useFirstFormStateGroup.d.ts +9 -0
- package/dist/dts/form/relay/get/useFormRelay.d.ts +13 -0
- package/dist/dts/form/relay/set/FormRelaySetter.d.ts +6 -0
- package/dist/dts/form/relay/set/useFormRelaySet.d.ts +2 -0
- package/dist/dts/form/relay/types.d.ts +12 -0
- package/dist/dts/form/with-handlers-and-children/RhfUtilsFormProps.d.ts +5 -1
- package/dist/dts/form/with-handlers-and-children/_useHandleSubmit.d.ts +1 -1
- package/dist/dts/form/with-providers/RhfUtilsFormWithProviders.d.ts +1 -1
- package/dist/dts/submit/UseRhfUtilsFormOnSubmitContextType.d.ts +3 -3
- package/dist/dts/submit/last-error/useLastSubmitErrorContextWith.d.ts +1 -1
- package/dist/esm/FormRelaySetter.mjs +140 -0
- package/dist/esm/index.mjs +203 -202
- package/dist/esm/relay.mjs +71 -209
- package/package.json +17 -17
- package/dist/dts/form/RhfUtilsFormStateWithUtilsType.d.ts +0 -7
- package/dist/dts/form/state/relay/FormStateRelayedAggregatedType.d.ts +0 -10
- package/dist/dts/form/state/relay/FormStateRelayedItemType.d.ts +0 -11
- package/dist/dts/form/state/relay/FormStateRelayedOptionsType.d.ts +0 -20
- package/dist/dts/form/state/relay/FormStateRelayedType.d.ts +0 -3
- package/dist/dts/form/state/relay/pull/hooks.d.ts +0 -31
- package/dist/dts/form/state/relay/push/FormStateRelayPusher.d.ts +0 -4
- package/dist/dts/form/state/relay/push/useFormStateRelayPusher.d.ts +0 -3
- package/dist/dts/form/state/relay/useFormStateRelayContext.d.ts +0 -20
- package/dist/dts/form/state/relay/utils.d.ts +0 -4
- package/dist/esm/getFlatFieldErrors.mjs +0 -55
package/dist/esm/index.mjs
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
import { jsx as c, jsxs as
|
|
1
|
+
import { jsx as c, jsxs as L } from "react/jsx-runtime";
|
|
2
2
|
import u from "react";
|
|
3
|
-
import { c as
|
|
4
|
-
import { Controller as
|
|
5
|
-
import { zodResolver as
|
|
6
|
-
const
|
|
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(
|
|
11
|
+
return /* @__PURE__ */ c(M.Provider, { value: e, children: /* @__PURE__ */ c(Y, { children: r }) });
|
|
12
12
|
}, {
|
|
13
|
-
Provider:
|
|
14
|
-
useRequired:
|
|
15
|
-
} =
|
|
16
|
-
const t =
|
|
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
|
-
},
|
|
18
|
+
}, q = "data-rhfutils-nonfield-error-marker-path", cr = ({ path: t }) => {
|
|
19
19
|
const r = {
|
|
20
|
-
[
|
|
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
|
-
},
|
|
31
|
+
}, lt = (t) => u.useCallback(
|
|
32
32
|
(r) => {
|
|
33
33
|
if (!t.current) throw new Error();
|
|
34
|
-
|
|
34
|
+
at(t.current, r);
|
|
35
35
|
},
|
|
36
36
|
[t]
|
|
37
|
-
),
|
|
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:
|
|
47
|
-
useRequired:
|
|
48
|
-
} =
|
|
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
|
-
),
|
|
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(
|
|
57
|
-
},
|
|
56
|
+
return /* @__PURE__ */ c(u.Suspense, { children: /* @__PURE__ */ c(dt, { ...e }) });
|
|
57
|
+
}, ht = () => {
|
|
58
58
|
const t = v();
|
|
59
|
-
return /* @__PURE__ */ c(
|
|
60
|
-
},
|
|
61
|
-
const t = u.useContext(
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
80
|
-
const { useCanFormBeCancelled: r } = R(), e =
|
|
81
|
-
return
|
|
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
|
-
},
|
|
86
|
+
}, pt = ({
|
|
87
87
|
onCancel: t,
|
|
88
88
|
Children: r
|
|
89
89
|
}) => {
|
|
90
|
-
const e = b(), o = v(), s =
|
|
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:
|
|
97
|
+
Controller: z,
|
|
98
98
|
FormSubmitError: E
|
|
99
99
|
}
|
|
100
100
|
);
|
|
101
|
-
},
|
|
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
|
-
},
|
|
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
|
-
}),
|
|
116
|
+
}), Ct = (t, r, e) => {
|
|
115
117
|
const o = R();
|
|
116
118
|
return {
|
|
117
119
|
id: r,
|
|
118
|
-
...
|
|
120
|
+
...Rt(
|
|
119
121
|
o.defaults?.form,
|
|
120
122
|
t,
|
|
121
123
|
e
|
|
122
124
|
)
|
|
123
125
|
};
|
|
124
|
-
},
|
|
125
|
-
const r =
|
|
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
|
-
},
|
|
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(),
|
|
140
|
-
return (
|
|
141
|
-
i.current = "submitting", n.stopSubmitPropagation &&
|
|
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,
|
|
146
|
+
i.current = "error", e(h, a);
|
|
145
147
|
}).finally(() => {
|
|
146
148
|
o?.();
|
|
147
149
|
});
|
|
148
150
|
};
|
|
149
|
-
},
|
|
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:
|
|
160
|
+
onSubmitFinally: l,
|
|
159
161
|
// other
|
|
160
162
|
form: m,
|
|
161
|
-
className:
|
|
163
|
+
className: a,
|
|
162
164
|
//
|
|
163
165
|
children: h
|
|
164
166
|
}) => {
|
|
165
|
-
const
|
|
167
|
+
const d = b(), f = v(), S = R(), P = Ct(
|
|
166
168
|
m,
|
|
167
|
-
|
|
169
|
+
f.formId,
|
|
168
170
|
{
|
|
169
|
-
className:
|
|
171
|
+
className: a
|
|
170
172
|
}
|
|
171
|
-
), y =
|
|
172
|
-
const p =
|
|
173
|
-
utils:
|
|
174
|
-
rhf:
|
|
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 =
|
|
177
|
-
e && await
|
|
178
|
-
const
|
|
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
|
-
|
|
182
|
-
n?.(
|
|
183
|
+
f.lastSubmitStateRef.current = "success", await Promise.resolve(
|
|
184
|
+
n?.(X, C, g, O)
|
|
183
185
|
);
|
|
184
186
|
};
|
|
185
|
-
function
|
|
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 &&
|
|
195
|
+
p && Et(d, p), i?.(
|
|
194
196
|
F,
|
|
195
197
|
{
|
|
196
|
-
utils:
|
|
198
|
+
utils: f,
|
|
197
199
|
errors: p,
|
|
198
|
-
rhf:
|
|
200
|
+
rhf: d
|
|
199
201
|
},
|
|
200
|
-
|
|
202
|
+
w
|
|
201
203
|
// `as` required due to conditional generic
|
|
202
204
|
);
|
|
203
205
|
}
|
|
204
|
-
const
|
|
205
|
-
onValid:
|
|
206
|
+
const U = Ot({
|
|
207
|
+
onValid: y,
|
|
206
208
|
onInvalid: r,
|
|
207
|
-
onError:
|
|
208
|
-
onFinally:
|
|
209
|
-
}),
|
|
210
|
-
...
|
|
211
|
-
|
|
212
|
-
|
|
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
|
-
|
|
218
|
+
_,
|
|
225
219
|
{
|
|
226
|
-
|
|
227
|
-
id:
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
},
|
|
227
|
+
}, yt = async (t, r, e, o) => {
|
|
233
228
|
const n = (await Promise.resolve(
|
|
234
229
|
t(r, e, o)
|
|
235
|
-
)).filter((
|
|
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
|
-
},
|
|
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:
|
|
244
|
+
onSubmitError: l,
|
|
250
245
|
onSubmitFinally: m,
|
|
251
246
|
//
|
|
252
|
-
Children:
|
|
247
|
+
Children: a,
|
|
253
248
|
// attrs
|
|
254
249
|
form: h,
|
|
255
|
-
className:
|
|
256
|
-
}) => /* @__PURE__ */
|
|
257
|
-
|
|
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:
|
|
260
|
+
onSubmitError: l,
|
|
266
261
|
onSubmitFinally: m,
|
|
267
262
|
form: h,
|
|
268
|
-
className:
|
|
263
|
+
className: d,
|
|
269
264
|
children: [
|
|
270
|
-
/* @__PURE__ */ c(
|
|
265
|
+
/* @__PURE__ */ c(ht, {}),
|
|
271
266
|
/* @__PURE__ */ c(
|
|
272
|
-
|
|
267
|
+
pt,
|
|
273
268
|
{
|
|
274
269
|
onCancel: r,
|
|
275
|
-
Children:
|
|
270
|
+
Children: a
|
|
276
271
|
}
|
|
277
272
|
)
|
|
278
273
|
]
|
|
279
274
|
}
|
|
280
|
-
),
|
|
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
|
-
),
|
|
281
|
+
), Z = (t) => !!t.ref, xt = ([
|
|
287
282
|
,
|
|
288
283
|
t
|
|
289
|
-
]) =>
|
|
290
|
-
|
|
291
|
-
),
|
|
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]) =>
|
|
305
|
-
|
|
299
|
+
([e, o]) => It(
|
|
300
|
+
q + e,
|
|
306
301
|
t + o
|
|
307
302
|
)
|
|
308
303
|
).join(", ")
|
|
309
|
-
),
|
|
310
|
-
|
|
311
|
-
), T = "root",
|
|
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
|
-
!
|
|
314
|
-
!
|
|
315
|
-
!
|
|
316
|
-
),
|
|
317
|
-
|
|
318
|
-
)(t),
|
|
319
|
-
|
|
320
|
-
),
|
|
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 } =
|
|
319
|
+
const { errors: e } = k(), o = tt(e), s = (
|
|
325
320
|
// eslint-disable-next-line react-hooks/refs
|
|
326
|
-
t.current ?
|
|
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:
|
|
334
|
-
roots:
|
|
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(
|
|
341
|
-
},
|
|
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
|
-
|
|
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
|
-
},
|
|
355
|
+
}, Bt = (t, r, e, o = "debug") => {
|
|
361
356
|
console[o](t, { values: r, errors: e });
|
|
362
|
-
},
|
|
363
|
-
const r = b(), e =
|
|
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 &&
|
|
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",
|
|
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
|
-
},
|
|
385
|
-
const { isSubmitSuccessful: e, isSubmitting: 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
|
-
},
|
|
384
|
+
}, Ht = (t) => {
|
|
390
385
|
const { getValues: r, reset: e } = b();
|
|
391
|
-
|
|
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
|
-
},
|
|
419
|
-
const t = u.useRef(
|
|
420
|
-
return u.useEffect(() => (t.current && (t.current = !
|
|
421
|
-
t.current =
|
|
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
|
-
},
|
|
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
|
-
},
|
|
445
|
-
const e =
|
|
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
|
-
},
|
|
454
|
-
const e =
|
|
448
|
+
}, Jt = (t, r) => {
|
|
449
|
+
const e = Zt(t, {
|
|
455
450
|
debounce: r?.debounce
|
|
456
|
-
}), o =
|
|
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
|
-
|
|
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
|
-
},
|
|
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
|
-
|
|
472
|
+
Mt(n.fieldErrors?.output), (s.submitOnWatch ? Jt : void 0)?.(
|
|
478
473
|
r,
|
|
479
474
|
s.submitOnWatch
|
|
480
|
-
),
|
|
475
|
+
), Ht(s.resetOnSubmitted);
|
|
481
476
|
const i = u.useRef(null);
|
|
482
477
|
return /* @__PURE__ */ c(
|
|
483
|
-
|
|
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
|
-
},
|
|
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
|
-
}),
|
|
505
|
-
() =>
|
|
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
|
-
),
|
|
503
|
+
), Kt = (t, r) => ({
|
|
509
504
|
...t,
|
|
510
505
|
...r
|
|
511
|
-
}),
|
|
512
|
-
...
|
|
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
|
|
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:
|
|
519
|
+
children: i
|
|
524
520
|
}) {
|
|
525
|
-
const
|
|
521
|
+
const l = R(), m = u.useId(), a = t || m, h = u.useRef(null), d = Xt(
|
|
526
522
|
r,
|
|
527
|
-
|
|
523
|
+
l,
|
|
528
524
|
o,
|
|
529
525
|
e
|
|
530
|
-
), f =
|
|
531
|
-
return /* @__PURE__ */ c(
|
|
532
|
-
|
|
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:
|
|
535
|
-
formRef:
|
|
530
|
+
formId: a,
|
|
531
|
+
formRef: h,
|
|
536
532
|
options: f,
|
|
537
|
-
children:
|
|
533
|
+
children: [
|
|
534
|
+
/* @__PURE__ */ c(et, { options: n }),
|
|
535
|
+
/* @__PURE__ */ c(Lt, { children: i })
|
|
536
|
+
]
|
|
538
537
|
}
|
|
539
538
|
) }) });
|
|
540
539
|
}
|
|
541
|
-
const
|
|
540
|
+
const $ = (t) => ct(t), ar = ({
|
|
542
541
|
schema: t,
|
|
543
542
|
children: r,
|
|
544
543
|
...e
|
|
545
|
-
}) => /* @__PURE__ */ c(
|
|
546
|
-
function
|
|
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:
|
|
555
|
-
onSubmitInvalid:
|
|
556
|
-
onBeforeSubmitInvariants:
|
|
557
|
-
onBeforeSubmit:
|
|
558
|
-
onSubmit:
|
|
559
|
-
onSubmitSuccess:
|
|
554
|
+
onCancel: i,
|
|
555
|
+
onSubmitInvalid: l,
|
|
556
|
+
onBeforeSubmitInvariants: m,
|
|
557
|
+
onBeforeSubmit: a,
|
|
558
|
+
onSubmit: h,
|
|
559
|
+
onSubmitSuccess: d,
|
|
560
560
|
onSubmitError: f,
|
|
561
|
-
onSubmitFinally:
|
|
562
|
-
Children:
|
|
563
|
-
form:
|
|
564
|
-
formId:
|
|
565
|
-
className:
|
|
561
|
+
onSubmitFinally: S,
|
|
562
|
+
Children: P,
|
|
563
|
+
form: y,
|
|
564
|
+
formId: x,
|
|
565
|
+
className: U
|
|
566
566
|
}) {
|
|
567
|
-
return /* @__PURE__ */ c(
|
|
568
|
-
formId:
|
|
567
|
+
return /* @__PURE__ */ c(Q, { ...{
|
|
568
|
+
formId: x,
|
|
569
569
|
resolver: r,
|
|
570
570
|
rhf: e,
|
|
571
571
|
defaultValues: o,
|
|
572
|
-
options: s
|
|
573
|
-
|
|
572
|
+
options: s,
|
|
573
|
+
relay: n
|
|
574
|
+
}, children: /* @__PURE__ */ c(A, { ...{
|
|
574
575
|
getApiData: t,
|
|
575
|
-
onCancel:
|
|
576
|
-
onSubmitInvalid:
|
|
577
|
-
onBeforeSubmitInvariants:
|
|
578
|
-
onBeforeSubmit:
|
|
579
|
-
onSubmit:
|
|
580
|
-
onSubmitSuccess:
|
|
576
|
+
onCancel: i,
|
|
577
|
+
onSubmitInvalid: l,
|
|
578
|
+
onBeforeSubmitInvariants: m,
|
|
579
|
+
onBeforeSubmit: a,
|
|
580
|
+
onSubmit: h,
|
|
581
|
+
onSubmitSuccess: d,
|
|
581
582
|
onSubmitError: f,
|
|
582
|
-
onSubmitFinally:
|
|
583
|
-
Children:
|
|
584
|
-
form:
|
|
585
|
-
className:
|
|
583
|
+
onSubmitFinally: S,
|
|
584
|
+
Children: P,
|
|
585
|
+
form: y,
|
|
586
|
+
className: U
|
|
586
587
|
} }) });
|
|
587
588
|
}
|
|
588
|
-
const
|
|
589
|
+
const mr = ({
|
|
589
590
|
schema: t,
|
|
590
591
|
...r
|
|
591
|
-
}) => /* @__PURE__ */ c(
|
|
592
|
+
}) => /* @__PURE__ */ c(Yt, { ...r, resolver: $(t) });
|
|
592
593
|
export {
|
|
593
594
|
E as FormSubmitError,
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
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
|
};
|