@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 +8 -7
- package/dist/dts/_exports/index.d.ts +1 -0
- package/dist/dts/_exports/types.d.ts +1 -1
- package/dist/dts/client/config/RhfUtilsClientConfigType.d.ts +8 -4
- package/dist/dts/form/RhfUtilsFormComponentPropsType.d.ts +0 -4
- package/dist/esm/index.mjs +160 -165
- package/package.json +1 -1
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
100
|
+
<>
|
|
100
101
|
{/* RhfUtilsZodForm.Children "outlet" (see "Component Hierarchy" section) */}
|
|
101
102
|
{children}
|
|
102
103
|
|
|
103
104
|
{/* root errors list */}
|
|
104
105
|
<RootErrorsList />
|
|
105
|
-
|
|
106
|
+
</>
|
|
106
107
|
);
|
|
107
108
|
},
|
|
108
109
|
|
|
@@ -15,15 +15,19 @@ export type RhfUtilsClientConfig = {
|
|
|
15
15
|
*/
|
|
16
16
|
defaults?: UseRhfUtilsFormGlobalDefaults;
|
|
17
17
|
/**
|
|
18
|
-
* Supply your own `<form>` component.
|
|
18
|
+
* Supply your own `<form>` component.
|
|
19
19
|
*
|
|
20
|
-
* @
|
|
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
|
-
*
|
|
26
|
+
* @description
|
|
23
27
|
*
|
|
24
28
|
* (NOTE: context params are not schema-typed as not possible at this level.)
|
|
25
29
|
*/
|
|
26
|
-
|
|
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
|
};
|
package/dist/esm/index.mjs
CHANGED
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { c as
|
|
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
|
|
6
|
+
const L = c.createContext(void 0), or = ({
|
|
7
7
|
config: t,
|
|
8
8
|
children: r
|
|
9
9
|
}) => {
|
|
10
|
-
const [e] =
|
|
11
|
-
return /* @__PURE__ */
|
|
10
|
+
const [e] = c.useState(t ?? {});
|
|
11
|
+
return /* @__PURE__ */ u(L.Provider, { value: e, children: r });
|
|
12
12
|
}, {
|
|
13
13
|
Provider: it,
|
|
14
|
-
useRequired:
|
|
15
|
-
} =
|
|
16
|
-
const t =
|
|
17
|
-
return
|
|
18
|
-
},
|
|
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
|
-
[
|
|
20
|
+
[M]: t
|
|
21
21
|
};
|
|
22
|
-
return /* @__PURE__ */
|
|
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
|
-
},
|
|
31
|
+
}, ct = (t) => c.useCallback(
|
|
32
32
|
(r) => {
|
|
33
33
|
if (!t.current) throw new Error();
|
|
34
|
-
|
|
34
|
+
ut(t.current, r);
|
|
35
35
|
},
|
|
36
36
|
[t]
|
|
37
|
-
),
|
|
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:
|
|
48
|
-
} =
|
|
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] =
|
|
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
|
|
56
|
+
return /* @__PURE__ */ u(c.Suspense, { children: /* @__PURE__ */ u(at, { ...e }) });
|
|
57
57
|
}, ft = () => {
|
|
58
58
|
const t = v();
|
|
59
|
-
return /* @__PURE__ */
|
|
60
|
-
},
|
|
61
|
-
const t =
|
|
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 } =
|
|
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__ */
|
|
91
|
+
return /* @__PURE__ */ u(
|
|
92
92
|
r,
|
|
93
93
|
{
|
|
94
94
|
...o,
|
|
95
95
|
rhf: e,
|
|
96
96
|
onCancel: s,
|
|
97
|
-
Controller:
|
|
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 = (
|
|
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
|
-
}),
|
|
115
|
-
const o =
|
|
116
|
+
}), vt = (t, r, e) => {
|
|
117
|
+
const o = C();
|
|
116
118
|
return {
|
|
117
119
|
id: r,
|
|
118
|
-
...
|
|
120
|
+
...Et(
|
|
119
121
|
o.defaults?.form,
|
|
120
122
|
t,
|
|
121
123
|
e
|
|
122
124
|
)
|
|
123
125
|
};
|
|
124
|
-
},
|
|
125
|
-
const r =
|
|
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 =
|
|
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((
|
|
144
|
-
i.current = "error", e(
|
|
145
|
+
}).catch((d) => {
|
|
146
|
+
i.current = "error", e(d, l);
|
|
145
147
|
}).finally(() => {
|
|
146
148
|
o?.();
|
|
147
149
|
});
|
|
148
150
|
};
|
|
149
|
-
},
|
|
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:
|
|
165
|
+
children: d
|
|
164
166
|
}) => {
|
|
165
|
-
const f = b(),
|
|
167
|
+
const f = b(), h = v(), S = C(), P = vt(
|
|
166
168
|
m,
|
|
167
|
-
|
|
169
|
+
h.formId,
|
|
168
170
|
{
|
|
169
171
|
className: l
|
|
170
172
|
}
|
|
171
|
-
), y =
|
|
172
|
-
const p = f.getValues(), G = t?.(F),
|
|
173
|
-
utils:
|
|
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
|
|
179
|
+
e && await Ot(e, R, g, O), await Promise.resolve(o?.(R, g, O));
|
|
178
180
|
const K = await Promise.resolve(
|
|
179
|
-
s?.(
|
|
181
|
+
s?.(R, g, O)
|
|
180
182
|
);
|
|
181
|
-
|
|
182
|
-
n?.(K,
|
|
183
|
+
h.lastSubmitStateRef.current = "success", await Promise.resolve(
|
|
184
|
+
n?.(K, R, g, O)
|
|
183
185
|
);
|
|
184
186
|
};
|
|
185
|
-
function
|
|
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:
|
|
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:
|
|
207
|
+
onValid: y,
|
|
206
208
|
onInvalid: r,
|
|
207
|
-
onError:
|
|
209
|
+
onError: x,
|
|
208
210
|
onFinally: a
|
|
209
|
-
}),
|
|
210
|
-
...
|
|
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:
|
|
214
|
+
Controller: q,
|
|
221
215
|
FormSubmitError: E
|
|
222
|
-
};
|
|
223
|
-
return /* @__PURE__ */
|
|
224
|
-
|
|
216
|
+
}, Q = S.FormComponent ?? "form", $ = S.FormChildren ?? pt;
|
|
217
|
+
return /* @__PURE__ */ u(
|
|
218
|
+
Q,
|
|
225
219
|
{
|
|
226
|
-
|
|
227
|
-
id:
|
|
228
|
-
|
|
229
|
-
|
|
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
|
-
},
|
|
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
|
-
},
|
|
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:
|
|
249
|
+
form: d,
|
|
255
250
|
className: f
|
|
256
251
|
}) => /* @__PURE__ */ X(
|
|
257
|
-
|
|
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:
|
|
262
|
+
form: d,
|
|
268
263
|
className: f,
|
|
269
264
|
children: [
|
|
270
|
-
/* @__PURE__ */
|
|
271
|
-
/* @__PURE__ */
|
|
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
|
-
),
|
|
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
|
-
),
|
|
281
|
+
), z = (t) => !!t.ref, Pt = ([
|
|
287
282
|
,
|
|
288
283
|
t
|
|
289
|
-
]) =>
|
|
290
|
-
|
|
291
|
-
),
|
|
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]) =>
|
|
305
|
-
|
|
299
|
+
([e, o]) => Ut(
|
|
300
|
+
M + e,
|
|
306
301
|
t + o
|
|
307
302
|
)
|
|
308
303
|
).join(", ")
|
|
309
|
-
),
|
|
310
|
-
|
|
311
|
-
),
|
|
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
|
-
!
|
|
314
|
-
!
|
|
315
|
-
!
|
|
316
|
-
),
|
|
317
|
-
|
|
318
|
-
)(t), Wt = ([t]) =>
|
|
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
|
-
),
|
|
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 ?
|
|
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:
|
|
334
|
-
roots:
|
|
328
|
+
fields: yt(o),
|
|
329
|
+
roots: _t(o),
|
|
335
330
|
orphans: s,
|
|
336
331
|
// computed
|
|
337
|
-
hasErrors: !
|
|
338
|
-
hasOrphans: !
|
|
332
|
+
hasErrors: !_(e),
|
|
333
|
+
hasOrphans: !_(s)
|
|
339
334
|
};
|
|
340
|
-
return /* @__PURE__ */
|
|
341
|
-
},
|
|
335
|
+
return /* @__PURE__ */ u(it, { value: n, children: r });
|
|
336
|
+
}, Tt = ({
|
|
342
337
|
children: t
|
|
343
338
|
}) => {
|
|
344
|
-
const [r, e] =
|
|
345
|
-
return /* @__PURE__ */
|
|
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
|
-
},
|
|
355
|
+
}, jt = (t, r, e, o = "debug") => {
|
|
361
356
|
console[o](t, { values: r, errors: e });
|
|
362
|
-
},
|
|
363
|
-
const r = b(), e =
|
|
364
|
-
|
|
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 &&
|
|
368
|
-
o.message ??
|
|
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 :
|
|
370
|
+
throw new Error(typeof s == "string" ? s : T);
|
|
376
371
|
}, [e]);
|
|
377
|
-
},
|
|
378
|
-
const r =
|
|
379
|
-
return
|
|
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
|
-
},
|
|
385
|
-
const { isSubmitSuccessful: e, isSubmitting: o } = I(), [s, n] =
|
|
386
|
-
|
|
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
|
-
},
|
|
384
|
+
}, Nt = (t) => {
|
|
390
385
|
const { getValues: r, reset: e } = b();
|
|
391
|
-
|
|
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
|
-
},
|
|
419
|
-
const t =
|
|
420
|
-
return
|
|
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,
|
|
418
|
+
}, w = !0, Ht = ({
|
|
424
419
|
onChange: t,
|
|
425
420
|
delay: r
|
|
426
421
|
}) => {
|
|
427
|
-
const e =
|
|
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
|
|
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
|
-
},
|
|
445
|
-
const e =
|
|
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
|
-
},
|
|
454
|
-
const e =
|
|
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 =
|
|
457
|
-
|
|
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
|
-
},
|
|
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] =
|
|
477
|
-
|
|
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
|
-
),
|
|
481
|
-
const i =
|
|
482
|
-
return /* @__PURE__ */
|
|
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
|
-
},
|
|
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
|
-
}),
|
|
505
|
-
() =>
|
|
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
|
-
),
|
|
503
|
+
), $t = (t, r) => ({
|
|
509
504
|
...t,
|
|
510
505
|
...r
|
|
511
|
-
}),
|
|
512
|
-
|
|
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
|
|
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 =
|
|
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 =
|
|
531
|
-
return /* @__PURE__ */
|
|
532
|
-
|
|
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__ */
|
|
532
|
+
children: /* @__PURE__ */ u(Tt, { children: n })
|
|
538
533
|
}
|
|
539
534
|
) }) });
|
|
540
535
|
}
|
|
541
|
-
const
|
|
536
|
+
const J = (t) => nt(t), ur = ({
|
|
542
537
|
schema: t,
|
|
543
538
|
children: r,
|
|
544
539
|
...e
|
|
545
|
-
}) => /* @__PURE__ */
|
|
546
|
-
function
|
|
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:
|
|
554
|
+
onSubmitSuccess: d,
|
|
560
555
|
onSubmitError: f,
|
|
561
|
-
onSubmitFinally:
|
|
556
|
+
onSubmitFinally: h,
|
|
562
557
|
Children: S,
|
|
563
558
|
form: P,
|
|
564
559
|
formId: y,
|
|
565
560
|
className: x
|
|
566
561
|
}) {
|
|
567
|
-
return /* @__PURE__ */
|
|
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__ */
|
|
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:
|
|
575
|
+
onSubmitSuccess: d,
|
|
581
576
|
onSubmitError: f,
|
|
582
|
-
onSubmitFinally:
|
|
577
|
+
onSubmitFinally: h,
|
|
583
578
|
Children: S,
|
|
584
579
|
form: P,
|
|
585
580
|
className: x
|
|
586
581
|
} }) });
|
|
587
582
|
}
|
|
588
|
-
const
|
|
583
|
+
const lr = ({
|
|
589
584
|
schema: t,
|
|
590
585
|
...r
|
|
591
|
-
}) => /* @__PURE__ */
|
|
586
|
+
}) => /* @__PURE__ */ u(Kt, { ...r, resolver: J(t) });
|
|
592
587
|
export {
|
|
593
588
|
E as FormSubmitError,
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
589
|
+
or as RhfUtilsClientConfigProvider,
|
|
590
|
+
nr as RhfUtilsNonFieldErrorMarker,
|
|
591
|
+
cr as RhfUtilsZodForm,
|
|
597
592
|
ur as RhfUtilsZodFormProviders,
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
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
|
};
|