suprform 1.0.8 → 1.0.9
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/dist/suprform.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import F, { createContext as Qr, useContext as Gr, useMemo as We, useImperativeHandle as
|
|
1
|
+
import { jsx as ne, Fragment as jr, jsxs as cr } from "react/jsx-runtime";
|
|
2
|
+
import F, { createContext as Qr, useContext as Gr, useMemo as We, useImperativeHandle as Fr, cloneElement as He, Children as zr, isValidElement as Kr } from "react";
|
|
3
3
|
var ve = (e) => e.type === "checkbox", le = (e) => e instanceof Date, G = (e) => e == null;
|
|
4
|
-
const
|
|
5
|
-
var M = (e) => !G(e) && !Array.isArray(e) &&
|
|
4
|
+
const br = (e) => typeof e == "object";
|
|
5
|
+
var M = (e) => !G(e) && !Array.isArray(e) && br(e) && !le(e), Ar = (e) => M(e) && e.target ? ve(e.target) ? e.target.checked : e.target.value : e, Yr = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e, pr = (e, t) => e.has(Yr(t)), Jr = (e) => {
|
|
6
6
|
const t = e.constructor && e.constructor.prototype;
|
|
7
7
|
return M(t) && t.hasOwnProperty("isPrototypeOf");
|
|
8
8
|
}, ze = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
|
|
@@ -51,7 +51,7 @@ const be = {
|
|
|
51
51
|
onSubmit: "onSubmit",
|
|
52
52
|
onTouched: "onTouched",
|
|
53
53
|
all: "all"
|
|
54
|
-
},
|
|
54
|
+
}, ae = {
|
|
55
55
|
max: "max",
|
|
56
56
|
min: "min",
|
|
57
57
|
maxLength: "maxLength",
|
|
@@ -65,7 +65,7 @@ const _e = () => F.useContext(Ye), Xr = (e) => {
|
|
|
65
65
|
const { children: t, ...r } = e;
|
|
66
66
|
return F.createElement(Ye.Provider, { value: r }, t);
|
|
67
67
|
};
|
|
68
|
-
var
|
|
68
|
+
var xr = (e, t, r, s = !0) => {
|
|
69
69
|
const u = {
|
|
70
70
|
defaultValues: t._defaultValues
|
|
71
71
|
};
|
|
@@ -102,9 +102,9 @@ function Zr(e) {
|
|
|
102
102
|
}
|
|
103
103
|
}), [u, s, i]), F.useEffect(() => {
|
|
104
104
|
v.current.isValid && r._setValid(!0);
|
|
105
|
-
}, [r]), F.useMemo(() =>
|
|
105
|
+
}, [r]), F.useMemo(() => xr(l, r, v.current, !1), [l, r]);
|
|
106
106
|
}
|
|
107
|
-
var Y = (e) => typeof e == "string", $e = (e, t, r, s, u) => Y(e) ? (s && t.watch.add(e), m(r, e, u)) : Array.isArray(e) ? e.map((i) => (s && t.watch.add(i), m(r, i))) : (s && (t.watchAll = !0), r), qe = (e) => G(e) || !
|
|
107
|
+
var Y = (e) => typeof e == "string", $e = (e, t, r, s, u) => Y(e) ? (s && t.watch.add(e), m(r, e, u)) : Array.isArray(e) ? e.map((i) => (s && t.watch.add(i), m(r, i))) : (s && (t.watchAll = !0), r), qe = (e) => G(e) || !br(e);
|
|
108
108
|
function ee(e, t, r = /* @__PURE__ */ new WeakSet()) {
|
|
109
109
|
if (qe(e) || qe(t))
|
|
110
110
|
return Object.is(e, t);
|
|
@@ -128,7 +128,7 @@ function ee(e, t, r = /* @__PURE__ */ new WeakSet()) {
|
|
|
128
128
|
}
|
|
129
129
|
return !0;
|
|
130
130
|
}
|
|
131
|
-
function
|
|
131
|
+
function Sr(e) {
|
|
132
132
|
const t = _e(), { control: r = t.control, name: s, defaultValue: u, disabled: i, exact: l, compute: c } = e || {}, v = F.useRef(u), p = F.useRef(c), V = F.useRef(void 0), g = F.useRef(r), b = F.useRef(s);
|
|
133
133
|
p.current = c;
|
|
134
134
|
const [H, I] = F.useState(() => {
|
|
@@ -166,7 +166,7 @@ function Er(e) {
|
|
|
166
166
|
return P !== null ? P : H;
|
|
167
167
|
}
|
|
168
168
|
function et(e) {
|
|
169
|
-
const t = _e(), { name: r, disabled: s, control: u = t.control, shouldUnregister: i, defaultValue: l, exact: c = !0 } = e, v =
|
|
169
|
+
const t = _e(), { name: r, disabled: s, control: u = t.control, shouldUnregister: i, defaultValue: l, exact: c = !0 } = e, v = pr(u._names.array, r), p = F.useMemo(() => m(u._formValues, r, m(u._defaultValues, r, l)), [u, r, l]), V = Sr({
|
|
170
170
|
control: u,
|
|
171
171
|
name: r,
|
|
172
172
|
defaultValue: p,
|
|
@@ -204,7 +204,7 @@ function et(e) {
|
|
|
204
204
|
}
|
|
205
205
|
}), [g, r]), B = F.useCallback((f) => I.current.onChange({
|
|
206
206
|
target: {
|
|
207
|
-
value:
|
|
207
|
+
value: Ar(f),
|
|
208
208
|
name: r
|
|
209
209
|
},
|
|
210
210
|
type: be.CHANGE
|
|
@@ -285,13 +285,13 @@ var tt = (e, t, r, s, u) => t ? {
|
|
|
285
285
|
}
|
|
286
286
|
};
|
|
287
287
|
};
|
|
288
|
-
function
|
|
288
|
+
function Er(e, t) {
|
|
289
289
|
const r = {};
|
|
290
290
|
for (const s in e)
|
|
291
291
|
if (e.hasOwnProperty(s)) {
|
|
292
292
|
const u = e[s], i = t[s];
|
|
293
293
|
if (u && M(u) && i) {
|
|
294
|
-
const l =
|
|
294
|
+
const l = Er(u, i);
|
|
295
295
|
M(l) && (r[s] = l);
|
|
296
296
|
} else e[s] && (r[s] = i);
|
|
297
297
|
}
|
|
@@ -302,7 +302,7 @@ var $ = (e) => M(e) && !Object.keys(e).length, Je = (e) => e.type === "file", re
|
|
|
302
302
|
return !1;
|
|
303
303
|
const t = e ? e.ownerDocument : 0;
|
|
304
304
|
return e instanceof (t && t.defaultView ? t.defaultView.HTMLElement : HTMLElement);
|
|
305
|
-
},
|
|
305
|
+
}, wr = (e) => e.type === "select-multiple", Xe = (e) => e.type === "radio", st = (e) => Xe(e) || ve(e), Oe = (e) => Ae(e) && e.isConnected;
|
|
306
306
|
function at(e, t) {
|
|
307
307
|
const r = t.slice(0, -1).length;
|
|
308
308
|
let s = 0;
|
|
@@ -326,13 +326,13 @@ var it = (e) => {
|
|
|
326
326
|
return !0;
|
|
327
327
|
return !1;
|
|
328
328
|
};
|
|
329
|
-
function
|
|
329
|
+
function Cr(e) {
|
|
330
330
|
return Array.isArray(e) || M(e) && !it(e);
|
|
331
331
|
}
|
|
332
332
|
function je(e, t = {}) {
|
|
333
333
|
for (const r in e) {
|
|
334
334
|
const s = e[r];
|
|
335
|
-
|
|
335
|
+
Cr(s) ? (t[r] = Array.isArray(s) ? [] : {}, je(s, t[r])) : T(s) || (t[r] = !0);
|
|
336
336
|
}
|
|
337
337
|
return t;
|
|
338
338
|
}
|
|
@@ -340,7 +340,7 @@ function fe(e, t, r) {
|
|
|
340
340
|
r || (r = je(t));
|
|
341
341
|
for (const s in e) {
|
|
342
342
|
const u = e[s];
|
|
343
|
-
if (
|
|
343
|
+
if (Cr(u))
|
|
344
344
|
T(t) || qe(r[s]) ? r[s] = je(u, Array.isArray(u) ? [] : {}) : fe(u, G(t) ? {} : t[s], r[s]);
|
|
345
345
|
else {
|
|
346
346
|
const i = t[s];
|
|
@@ -353,7 +353,7 @@ const fr = {
|
|
|
353
353
|
value: !1,
|
|
354
354
|
isValid: !1
|
|
355
355
|
}, yr = { value: !0, isValid: !0 };
|
|
356
|
-
var
|
|
356
|
+
var kr = (e) => {
|
|
357
357
|
if (Array.isArray(e)) {
|
|
358
358
|
if (e.length > 1) {
|
|
359
359
|
const t = e.filter((r) => r && r.checked && !r.disabled).map((r) => r.value);
|
|
@@ -365,18 +365,18 @@ var Dr = (e) => {
|
|
|
365
365
|
) : fr;
|
|
366
366
|
}
|
|
367
367
|
return fr;
|
|
368
|
-
},
|
|
368
|
+
}, Dr = (e, { valueAsNumber: t, valueAsDate: r, setValueAs: s }) => T(e) ? e : t ? e === "" ? NaN : e && +e : r && Y(e) ? new Date(e) : s ? s(e) : e;
|
|
369
369
|
const mr = {
|
|
370
370
|
isValid: !1,
|
|
371
371
|
value: null
|
|
372
372
|
};
|
|
373
|
-
var
|
|
373
|
+
var Rr = (e) => Array.isArray(e) ? e.reduce((t, r) => r && r.checked && !r.disabled ? {
|
|
374
374
|
isValid: !0,
|
|
375
375
|
value: r.value
|
|
376
376
|
} : t, mr) : mr;
|
|
377
377
|
function _r(e) {
|
|
378
378
|
const t = e.ref;
|
|
379
|
-
return Je(t) ? t.files : Xe(t) ?
|
|
379
|
+
return Je(t) ? t.files : Xe(t) ? Rr(e.refs).value : wr(t) ? [...t.selectedOptions].map(({ value: r }) => r) : ve(t) ? kr(e.refs).value : Dr(T(t.value) ? e.ref.value : t.value, e);
|
|
380
380
|
}
|
|
381
381
|
var ut = (e, t, r, s) => {
|
|
382
382
|
const u = {};
|
|
@@ -448,7 +448,7 @@ var ct = (e, t, r, s) => {
|
|
|
448
448
|
r(e);
|
|
449
449
|
const { name: u, ...i } = e;
|
|
450
450
|
return $(i) || Object.keys(i).length >= Object.keys(t).length || Object.keys(i).find((l) => t[l] === (!s || X.all));
|
|
451
|
-
}, dt = (e, t, r) => !e || !t || e === t || z(e).some((s) => s && (r ? s === t : s.startsWith(t) || t.startsWith(s))), ft = (e, t, r, s, u) => u.isOnAll ? !1 : !r && u.isOnTouch ? !(t || e) : (r ? s.isOnBlur : u.isOnBlur) ? !e : (r ? s.isOnChange : u.isOnChange) ? e : !0, yt = (e, t) => !Se(m(e, t)).length && L(e, t),
|
|
451
|
+
}, dt = (e, t, r) => !e || !t || e === t || z(e).some((s) => s && (r ? s === t : s.startsWith(t) || t.startsWith(s))), ft = (e, t, r, s, u) => u.isOnAll ? !1 : !r && u.isOnTouch ? !(t || e) : (r ? s.isOnBlur : u.isOnBlur) ? !e : (r ? s.isOnChange : u.isOnChange) ? e : !0, yt = (e, t) => !Se(m(e, t)).length && L(e, t), Or = (e, t, r) => {
|
|
452
452
|
const s = z(m(e, r));
|
|
453
453
|
return R(s, "root", t[r]), R(e, r, s), e;
|
|
454
454
|
};
|
|
@@ -469,7 +469,7 @@ var de = (e) => M(e) && !pe(e) ? e : {
|
|
|
469
469
|
return {};
|
|
470
470
|
const P = c ? c[0] : l, f = (w) => {
|
|
471
471
|
u && P.reportValidity && (P.setCustomValidity(K(w) ? "" : w || ""), P.reportValidity());
|
|
472
|
-
}, y = {}, x = Xe(l), E = ve(l), Z = x || E, W = (B || Je(l)) && T(l.value) && T(S) || Ae(l) && l.value === "" || S === "" || Array.isArray(S) && !S.length, oe = tt.bind(null, C, s, y), te = (w, D, N, q =
|
|
472
|
+
}, y = {}, x = Xe(l), E = ve(l), Z = x || E, W = (B || Je(l)) && T(l.value) && T(S) || Ae(l) && l.value === "" || S === "" || Array.isArray(S) && !S.length, oe = tt.bind(null, C, s, y), te = (w, D, N, q = ae.maxLength, Q = ae.minLength) => {
|
|
473
473
|
const se = w ? D : N;
|
|
474
474
|
y[C] = {
|
|
475
475
|
type: w ? q : Q,
|
|
@@ -478,13 +478,13 @@ var de = (e) => M(e) && !pe(e) ? e : {
|
|
|
478
478
|
...oe(w ? q : Q, se)
|
|
479
479
|
};
|
|
480
480
|
};
|
|
481
|
-
if (i ? !Array.isArray(S) || !S.length : v && (!Z && (W || G(S)) || K(S) && !S || E && !
|
|
481
|
+
if (i ? !Array.isArray(S) || !S.length : v && (!Z && (W || G(S)) || K(S) && !S || E && !kr(c).isValid || x && !Rr(c).isValid)) {
|
|
482
482
|
const { value: w, message: D } = Y(v) ? { value: !!v, message: v } : de(v);
|
|
483
483
|
if (w && (y[C] = {
|
|
484
|
-
type:
|
|
484
|
+
type: ae.required,
|
|
485
485
|
message: D,
|
|
486
486
|
ref: P,
|
|
487
|
-
...oe(
|
|
487
|
+
...oe(ae.required, D)
|
|
488
488
|
}, !s))
|
|
489
489
|
return f(D), y;
|
|
490
490
|
}
|
|
@@ -498,7 +498,7 @@ var de = (e) => M(e) && !pe(e) ? e : {
|
|
|
498
498
|
const Q = l.valueAsDate || new Date(S), se = (Ve) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + Ve), ge = l.type == "time", ce = l.type == "week";
|
|
499
499
|
Y(N.value) && S && (w = ge ? se(S) > se(N.value) : ce ? S > N.value : Q > new Date(N.value)), Y(q.value) && S && (D = ge ? se(S) < se(q.value) : ce ? S < q.value : Q < new Date(q.value));
|
|
500
500
|
}
|
|
501
|
-
if ((w || D) && (te(!!w, N.message, q.message,
|
|
501
|
+
if ((w || D) && (te(!!w, N.message, q.message, ae.max, ae.min), !s))
|
|
502
502
|
return f(y[C].message), y;
|
|
503
503
|
}
|
|
504
504
|
if ((p || V) && !W && (Y(S) || i && Array.isArray(S))) {
|
|
@@ -509,10 +509,10 @@ var de = (e) => M(e) && !pe(e) ? e : {
|
|
|
509
509
|
if (H && !W && Y(S)) {
|
|
510
510
|
const { value: w, message: D } = de(H);
|
|
511
511
|
if (pe(w) && !S.match(w) && (y[C] = {
|
|
512
|
-
type:
|
|
512
|
+
type: ae.pattern,
|
|
513
513
|
message: D,
|
|
514
514
|
ref: l,
|
|
515
|
-
...oe(
|
|
515
|
+
...oe(ae.pattern, D)
|
|
516
516
|
}, !s))
|
|
517
517
|
return f(D), y;
|
|
518
518
|
}
|
|
@@ -521,7 +521,7 @@ var de = (e) => M(e) && !pe(e) ? e : {
|
|
|
521
521
|
const w = await I(S, r), D = vr(w, P);
|
|
522
522
|
if (D && (y[C] = {
|
|
523
523
|
...D,
|
|
524
|
-
...oe(
|
|
524
|
+
...oe(ae.validate, D.message)
|
|
525
525
|
}, !s))
|
|
526
526
|
return f(D.message), y;
|
|
527
527
|
} else if (M(I)) {
|
|
@@ -707,7 +707,7 @@ function _t(e = {}) {
|
|
|
707
707
|
const J = await Ge(_, c.disabled, i, H, t.shouldUseNativeValidation && !n, k);
|
|
708
708
|
if (O && V.validatingFields && B([d.name]), J[d.name] && (o.valid = !1, n))
|
|
709
709
|
break;
|
|
710
|
-
!n && (m(J, d.name) ? k ?
|
|
710
|
+
!n && (m(J, d.name) ? k ? Or(r.errors, J, d.name) : R(r.errors, d.name, J[d.name]) : L(r.errors, d.name));
|
|
711
711
|
}
|
|
712
712
|
!$(A) && await W(A, n, o);
|
|
713
713
|
}
|
|
@@ -726,7 +726,7 @@ function _t(e = {}) {
|
|
|
726
726
|
let _ = n;
|
|
727
727
|
if (h) {
|
|
728
728
|
const d = h._f;
|
|
729
|
-
d && (!d.disabled && R(i, a,
|
|
729
|
+
d && (!d.disabled && R(i, a, Dr(n, d)), _ = Ae(d.ref) && G(n) ? "" : n, wr(d.ref) ? [...d.ref.options].forEach((A) => A.selected = _.includes(A.value)) : d.refs ? ve(d.ref) ? d.refs.forEach((A) => {
|
|
730
730
|
(!A.defaultChecked || !A.disabled) && (Array.isArray(_) ? A.checked = !!_.find((k) => k === A.value) : A.checked = _ === A.value || !!_);
|
|
731
731
|
}) : d.refs.forEach((A) => A.checked = A.value === _) : Je(d.ref) ? d.ref.value = "" : (d.ref.value = _, d.ref.type || b.state.next({
|
|
732
732
|
name: a,
|
|
@@ -763,19 +763,19 @@ function _t(e = {}) {
|
|
|
763
763
|
}, A = ye(t.mode), k = ye(t.reValidateMode);
|
|
764
764
|
if (_) {
|
|
765
765
|
let O, J;
|
|
766
|
-
const Fe = n.type ? _r(_._f) :
|
|
766
|
+
const Fe = n.type ? _r(_._f) : Ar(a), ie = a.type === be.BLUR || a.type === be.FOCUS_OUT, Hr = !lt(_._f) && !t.resolver && !m(r.errors, o) && !_._f.deps || ft(ie, m(r.touchedFields, o), r.isSubmitted, k, A), De = Qe(o, c, ie);
|
|
767
767
|
R(i, o, Fe), ie ? (!n || !n.readOnly) && (_._f.onBlur && _._f.onBlur(a), v && v(0)) : _._f.onChange && _._f.onChange(a);
|
|
768
|
-
const Re = y(o, Fe, ie),
|
|
768
|
+
const Re = y(o, Fe, ie), $r = !$(Re) || De;
|
|
769
769
|
if (!ie && b.state.next({
|
|
770
770
|
name: o,
|
|
771
771
|
type: a.type,
|
|
772
772
|
values: U(i)
|
|
773
|
-
}),
|
|
774
|
-
return (V.isValid || g.isValid) && (t.mode === "onBlur" ? ie && C() : ie || C()),
|
|
773
|
+
}), Hr)
|
|
774
|
+
return (V.isValid || g.isValid) && (t.mode === "onBlur" ? ie && C() : ie || C()), $r && b.state.next({ name: o, ...De ? {} : Re });
|
|
775
775
|
if (!ie && De && b.state.next({ ...r }), t.resolver) {
|
|
776
776
|
const { errors: or } = await E([o]);
|
|
777
777
|
if (d(Fe), h) {
|
|
778
|
-
const
|
|
778
|
+
const qr = hr(r.errors, s, o), lr = hr(or, s, qr.name || o);
|
|
779
779
|
O = lr.error, o = lr.name, J = $(or);
|
|
780
780
|
}
|
|
781
781
|
} else
|
|
@@ -804,14 +804,14 @@ function _t(e = {}) {
|
|
|
804
804
|
let o = {
|
|
805
805
|
...l.mount ? i : u
|
|
806
806
|
};
|
|
807
|
-
return n && (o =
|
|
807
|
+
return n && (o = Er(n.dirtyFields ? r.dirtyFields : r.touchedFields, o)), T(a) ? o : Y(a) ? m(o, a) : a.map((h) => m(o, h));
|
|
808
808
|
}, er = (a, n) => ({
|
|
809
809
|
invalid: !!m((n || r).errors, a),
|
|
810
810
|
isDirty: !!m((n || r).dirtyFields, a),
|
|
811
811
|
error: m((n || r).errors, a),
|
|
812
812
|
isValidating: !!m(r.validatingFields, a),
|
|
813
813
|
isTouched: !!m((n || r).touchedFields, a)
|
|
814
|
-
}),
|
|
814
|
+
}), Nr = (a) => {
|
|
815
815
|
a && z(a).forEach((n) => L(r.errors, n)), b.state.next({
|
|
816
816
|
errors: a ? r.errors : {}
|
|
817
817
|
});
|
|
@@ -826,18 +826,18 @@ function _t(e = {}) {
|
|
|
826
826
|
errors: r.errors,
|
|
827
827
|
isValid: !1
|
|
828
828
|
}), o && o.shouldFocus && h && h.focus && h.focus();
|
|
829
|
-
},
|
|
829
|
+
}, Lr = (a, n) => re(a) ? b.state.subscribe({
|
|
830
830
|
next: (o) => "values" in o && a(w(void 0, n), o)
|
|
831
831
|
}) : w(a, n, !0), tr = (a) => b.state.subscribe({
|
|
832
832
|
next: (n) => {
|
|
833
|
-
dt(a.name, n.name, a.exact) && ct(n, a.formState || V,
|
|
833
|
+
dt(a.name, n.name, a.exact) && ct(n, a.formState || V, Wr, a.reRenderRoot) && a.callback({
|
|
834
834
|
values: { ...i },
|
|
835
835
|
...r,
|
|
836
836
|
...n,
|
|
837
837
|
defaultValues: u
|
|
838
838
|
});
|
|
839
839
|
}
|
|
840
|
-
}).unsubscribe,
|
|
840
|
+
}).unsubscribe, Mr = (a) => (l.mount = !0, g = {
|
|
841
841
|
...g,
|
|
842
842
|
...a.formState
|
|
843
843
|
}, tr({
|
|
@@ -901,10 +901,10 @@ function _t(e = {}) {
|
|
|
901
901
|
}
|
|
902
902
|
}), f(a, !1, void 0, d);
|
|
903
903
|
} else
|
|
904
|
-
o = m(s, a, {}), o._f && (o._f.mount = !1), (t.shouldUnregister || n.shouldUnregister) && !(
|
|
904
|
+
o = m(s, a, {}), o._f && (o._f.mount = !1), (t.shouldUnregister || n.shouldUnregister) && !(pr(c.array, a) && l.action) && c.unMount.add(a);
|
|
905
905
|
}
|
|
906
906
|
};
|
|
907
|
-
}, ke = () => t.shouldFocusError && me(s, ge, c.mount),
|
|
907
|
+
}, ke = () => t.shouldFocusError && me(s, ge, c.mount), Ir = (a) => {
|
|
908
908
|
K(a) && (b.state.next({ disabled: a }), me(s, (n, o) => {
|
|
909
909
|
const h = m(s, o);
|
|
910
910
|
h && (n.disabled = h._f.disabled || a, Array.isArray(h._f.refs) && h._f.refs.forEach((_) => {
|
|
@@ -944,7 +944,7 @@ function _t(e = {}) {
|
|
|
944
944
|
errors: r.errors
|
|
945
945
|
}), h)
|
|
946
946
|
throw h;
|
|
947
|
-
},
|
|
947
|
+
}, Br = (a, n = {}) => {
|
|
948
948
|
m(s, a) && (T(n.defaultValue) ? Q(a, U(m(u, a))) : (Q(a, n.defaultValue), R(u, a, U(n.defaultValue))), n.keepTouched || L(r.touchedFields, a), n.keepDirty || (L(r.dirtyFields, a), r.isDirty = n.defaultValue ? te(a, U(m(u, a))) : te()), n.keepError || (L(r.errors, a), V.isValid && C()), b.state.next({ ...r }));
|
|
949
949
|
}, nr = (a, n = {}) => {
|
|
950
950
|
const o = a ? U(a) : u, h = U(o), _ = $(a), d = _ ? u : h;
|
|
@@ -1002,13 +1002,13 @@ function _t(e = {}) {
|
|
|
1002
1002
|
isSubmitting: !1,
|
|
1003
1003
|
defaultValues: u
|
|
1004
1004
|
});
|
|
1005
|
-
}, ir = (a, n) => nr(re(a) ? a(i) : a, n),
|
|
1005
|
+
}, ir = (a, n) => nr(re(a) ? a(i) : a, n), Pr = (a, n = {}) => {
|
|
1006
1006
|
const o = m(s, a), h = o && o._f;
|
|
1007
1007
|
if (h) {
|
|
1008
1008
|
const _ = h.refs ? h.refs[0] : h.ref;
|
|
1009
1009
|
_.focus && (_.focus(), n.shouldSelect && re(_.select) && _.select());
|
|
1010
1010
|
}
|
|
1011
|
-
},
|
|
1011
|
+
}, Wr = (a) => {
|
|
1012
1012
|
r = {
|
|
1013
1013
|
...r,
|
|
1014
1014
|
...a
|
|
@@ -1037,7 +1037,7 @@ function _t(e = {}) {
|
|
|
1037
1037
|
});
|
|
1038
1038
|
}),
|
|
1039
1039
|
_removeUnmounted: oe,
|
|
1040
|
-
_disableForm:
|
|
1040
|
+
_disableForm: Ir,
|
|
1041
1041
|
_subjects: b,
|
|
1042
1042
|
_proxyFormState: V,
|
|
1043
1043
|
get _fields() {
|
|
@@ -1074,19 +1074,19 @@ function _t(e = {}) {
|
|
|
1074
1074
|
};
|
|
1075
1075
|
}
|
|
1076
1076
|
},
|
|
1077
|
-
subscribe:
|
|
1077
|
+
subscribe: Mr,
|
|
1078
1078
|
trigger: ce,
|
|
1079
1079
|
register: Ce,
|
|
1080
1080
|
handleSubmit: ar,
|
|
1081
|
-
watch:
|
|
1081
|
+
watch: Lr,
|
|
1082
1082
|
setValue: Q,
|
|
1083
1083
|
getValues: Ve,
|
|
1084
1084
|
reset: ir,
|
|
1085
|
-
resetField:
|
|
1086
|
-
clearErrors:
|
|
1085
|
+
resetField: Br,
|
|
1086
|
+
clearErrors: Nr,
|
|
1087
1087
|
unregister: we,
|
|
1088
1088
|
setError: rr,
|
|
1089
|
-
setFocus:
|
|
1089
|
+
setFocus: Pr,
|
|
1090
1090
|
getFieldState: er
|
|
1091
1091
|
};
|
|
1092
1092
|
return {
|
|
@@ -1197,7 +1197,7 @@ function ht(e) {
|
|
|
1197
1197
|
else {
|
|
1198
1198
|
const f = m(r._fields, s);
|
|
1199
1199
|
f && f._f && !(ye(r._options.reValidateMode).isOnSubmit && ye(r._options.mode).isOnSubmit) && Ge(f, r._names.disabled, r._formValues, r._options.criteriaMode === X.all, r._options.shouldUseNativeValidation, !0).then((y) => !$(y) && r._subjects.state.next({
|
|
1200
|
-
errors:
|
|
1200
|
+
errors: Or(r._formState.errors, y, s)
|
|
1201
1201
|
}));
|
|
1202
1202
|
}
|
|
1203
1203
|
r._subjects.state.next({
|
|
@@ -1293,10 +1293,10 @@ function vt(e = {}) {
|
|
|
1293
1293
|
}), !((l = i._options.resetOptions) === null || l === void 0) && l.keepIsValid || i._setValid(), r.current = e.values, u((c) => ({ ...c }))) : i._resetDefaultValues();
|
|
1294
1294
|
}, [i, e.values]), F.useEffect(() => {
|
|
1295
1295
|
i._state.mount || (i._setValid(), i._state.mount = !0), i._state.watch && (i._state.watch = !1, i._subjects.state.next({ ...i._formState })), i._removeUnmounted();
|
|
1296
|
-
}), t.current.formState =
|
|
1296
|
+
}), t.current.formState = xr(s, i), t.current;
|
|
1297
1297
|
}
|
|
1298
|
-
const
|
|
1299
|
-
const e = Gr(
|
|
1298
|
+
const Tr = Qr(void 0), Vt = ({ showAsterisk: e, children: t }) => /* @__PURE__ */ ne(Tr.Provider, { value: { showAsterisk: e }, children: t }), Ft = () => {
|
|
1299
|
+
const e = Gr(Tr);
|
|
1300
1300
|
if (!e)
|
|
1301
1301
|
throw new Error("useSuprFormContext must be used within a SuprFormProvider");
|
|
1302
1302
|
return e;
|
|
@@ -1304,7 +1304,7 @@ const Ur = Qr(void 0), Vt = ({ showAsterisk: e, children: t }) => /* @__PURE__ *
|
|
|
1304
1304
|
children: e,
|
|
1305
1305
|
visibility: t
|
|
1306
1306
|
}) => {
|
|
1307
|
-
const { getValues: r } = _e(), s = We(() => typeof t == "boolean" ? [] : (t == null ? void 0 : t.conditions.map((l) => l.name)) || [], [t]), u =
|
|
1307
|
+
const { getValues: r } = _e(), s = We(() => typeof t == "boolean" ? [] : (t == null ? void 0 : t.conditions.map((l) => l.name)) || [], [t]), u = Sr({ name: s });
|
|
1308
1308
|
return We(() => {
|
|
1309
1309
|
if (typeof t == "boolean") return t;
|
|
1310
1310
|
if (!t || (t == null ? void 0 : t.conditions.length) === 0) return !0;
|
|
@@ -1337,7 +1337,7 @@ const Ur = Qr(void 0), Vt = ({ showAsterisk: e, children: t }) => /* @__PURE__ *
|
|
|
1337
1337
|
});
|
|
1338
1338
|
return c === "AND" ? p.every(Boolean) : p.some(Boolean);
|
|
1339
1339
|
}, [t, s, u, r]) ? e : null;
|
|
1340
|
-
},
|
|
1340
|
+
}, Ur = ({
|
|
1341
1341
|
children: e,
|
|
1342
1342
|
onSubmit: t = () => {
|
|
1343
1343
|
},
|
|
@@ -1355,7 +1355,7 @@ const Ur = Qr(void 0), Vt = ({ showAsterisk: e, children: t }) => /* @__PURE__ *
|
|
|
1355
1355
|
shouldFocusError: !0,
|
|
1356
1356
|
...i
|
|
1357
1357
|
});
|
|
1358
|
-
return
|
|
1358
|
+
return Fr(
|
|
1359
1359
|
c,
|
|
1360
1360
|
() => ({
|
|
1361
1361
|
setValue: v.setValue,
|
|
@@ -1370,7 +1370,7 @@ const Ur = Qr(void 0), Vt = ({ showAsterisk: e, children: t }) => /* @__PURE__ *
|
|
|
1370
1370
|
watch: v.watch
|
|
1371
1371
|
}),
|
|
1372
1372
|
[v]
|
|
1373
|
-
), /* @__PURE__ */
|
|
1373
|
+
), /* @__PURE__ */ ne(Vt, { showAsterisk: l, children: /* @__PURE__ */ ne(Xr, { ...v, children: /* @__PURE__ */ ne(
|
|
1374
1374
|
"form",
|
|
1375
1375
|
{
|
|
1376
1376
|
noValidate: !0,
|
|
@@ -1391,8 +1391,7 @@ const Ur = Qr(void 0), Vt = ({ showAsterisk: e, children: t }) => /* @__PURE__ *
|
|
|
1391
1391
|
shouldUnregister: c,
|
|
1392
1392
|
visibility: v
|
|
1393
1393
|
}) => {
|
|
1394
|
-
const { control: p } = _e(), V = e.props.value, { showAsterisk: g } = Ft(), b = e.props.onChange, H = e.props.onBlur, I = We(() => i || crypto.randomUUID(), [])
|
|
1395
|
-
return /* @__PURE__ */ ae(
|
|
1394
|
+
const { control: p } = _e(), V = e.props.value, { showAsterisk: g } = Ft(), b = e.props.onChange, H = e.props.onBlur, I = We(() => i || crypto.randomUUID(), []), C = /* @__PURE__ */ ne(
|
|
1396
1395
|
rt,
|
|
1397
1396
|
{
|
|
1398
1397
|
control: p,
|
|
@@ -1401,45 +1400,43 @@ const Ur = Qr(void 0), Vt = ({ showAsterisk: e, children: t }) => /* @__PURE__ *
|
|
|
1401
1400
|
defaultValue: V,
|
|
1402
1401
|
disabled: l,
|
|
1403
1402
|
shouldUnregister: c,
|
|
1404
|
-
render: ({ field: { name:
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
{
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
children: [
|
|
1411
|
-
u
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
);
|
|
1433
|
-
return v ? /* @__PURE__ */ ae(bt, { visibility: v, children: y }) : /* @__PURE__ */ ae(Fr, { children: y });
|
|
1434
|
-
}
|
|
1403
|
+
render: ({ field: { name: B, onBlur: j, value: S, onChange: P, ref: f }, fieldState: { error: y } }) => /* @__PURE__ */ cr(
|
|
1404
|
+
"div",
|
|
1405
|
+
{
|
|
1406
|
+
className: `controlled-field ${s}`,
|
|
1407
|
+
style: { display: "flex", flexDirection: "column", gap: "5px" },
|
|
1408
|
+
children: [
|
|
1409
|
+
u && /* @__PURE__ */ cr("label", { htmlFor: I, className: "controlled-field-label", children: [
|
|
1410
|
+
u,
|
|
1411
|
+
g && !!r && /* @__PURE__ */ ne("span", { style: { color: "red" }, children: " *" })
|
|
1412
|
+
] }),
|
|
1413
|
+
He(e, {
|
|
1414
|
+
...e.props,
|
|
1415
|
+
id: I,
|
|
1416
|
+
name: B,
|
|
1417
|
+
disabled: l,
|
|
1418
|
+
onChange: (...x) => {
|
|
1419
|
+
P(...x), b == null || b(...x);
|
|
1420
|
+
},
|
|
1421
|
+
value: S,
|
|
1422
|
+
onBlur: (...x) => {
|
|
1423
|
+
j(), H == null || H(...x);
|
|
1424
|
+
},
|
|
1425
|
+
ref: f
|
|
1426
|
+
}),
|
|
1427
|
+
y && /* @__PURE__ */ ne("div", { style: { color: "red", fontSize: 13 }, className: "controlled-field-error", children: y.message })
|
|
1428
|
+
]
|
|
1429
|
+
}
|
|
1430
|
+
)
|
|
1435
1431
|
}
|
|
1436
1432
|
);
|
|
1433
|
+
return v ? /* @__PURE__ */ ne(bt, { visibility: v, children: C }) : C;
|
|
1437
1434
|
}, At = ({ name: e, rules: t, ref: r, children: s }) => {
|
|
1438
1435
|
const u = ht({
|
|
1439
1436
|
name: e,
|
|
1440
1437
|
rules: t
|
|
1441
1438
|
});
|
|
1442
|
-
|
|
1439
|
+
Fr(r, () => u, [u]);
|
|
1443
1440
|
const i = (l, c) => zr.map(l, (v) => {
|
|
1444
1441
|
if (!Kr(v))
|
|
1445
1442
|
return v;
|
|
@@ -1456,15 +1453,15 @@ const Ur = Qr(void 0), Vt = ({ showAsterisk: e, children: t }) => /* @__PURE__ *
|
|
|
1456
1453
|
children: i(p.children, c)
|
|
1457
1454
|
}) : v;
|
|
1458
1455
|
});
|
|
1459
|
-
return /* @__PURE__ */
|
|
1456
|
+
return /* @__PURE__ */ ne(jr, { children: u.fields.map((l, c) => {
|
|
1460
1457
|
const v = `${e}.${c}.`;
|
|
1461
1458
|
return i(s, v);
|
|
1462
1459
|
}) });
|
|
1463
1460
|
};
|
|
1464
1461
|
Ze.displayName = "SuprFormControl";
|
|
1465
|
-
|
|
1466
|
-
|
|
1462
|
+
Ur.Control = Ze;
|
|
1463
|
+
Ur.ControlArray = At;
|
|
1467
1464
|
export {
|
|
1468
|
-
|
|
1465
|
+
Ur as SuprForm
|
|
1469
1466
|
};
|
|
1470
1467
|
//# sourceMappingURL=suprform.es.js.map
|