@middag-io/react 0.36.2 → 0.37.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/dist-lib/{resolve-field-error-D19vvPuS.js → FormField-CEkzkfTY.js} +2384 -2065
- package/dist-lib/FormPanelBlock-CIZejEGw.js +1499 -0
- package/dist-lib/base/form/fields/MultiSelectField.d.ts +6 -1
- package/dist-lib/base/form/fields/MultiSelectField.d.ts.map +1 -1
- package/dist-lib/index.d.ts +1 -0
- package/dist-lib/index.d.ts.map +1 -1
- package/dist-lib/middag-react.js +3770 -3770
- package/package.json +1 -1
- package/dist-lib/FormPanelBlock-Dj-SSYZf.js +0 -1816
|
@@ -1,1816 +0,0 @@
|
|
|
1
|
-
import { $ as e, A as t, D as n, Dt as r, E as i, Et as a, Ft as o, J as s, K as c, Nt as l, O as u, Ot as d, Pt as f, T as p, Tt as m, U as h, V as g, Y as _, Z as v, _ as y, a as b, at as x, b as S, c as C, d as ee, et as w, f as T, g as E, h as D, i as O, jt as k, kt as A, l as te, m as ne, n as re, nt as ie, o as ae, p as oe, r as se, t as j, tt as ce, u as le, v as ue, w as de, wt as fe, y as pe } from "./resolve-field-error-D19vvPuS.js";
|
|
2
|
-
import { t as me } from "./button-Bm0X9WO5.js";
|
|
3
|
-
import { t as he } from "./useTranslation-D-tjJhTn.js";
|
|
4
|
-
import { t as ge } from "./utils-CpaZ5_iF.js";
|
|
5
|
-
import { t as _e } from "./skeleton-xL_Hzxj-.js";
|
|
6
|
-
import M, { Suspense as N, lazy as P, useCallback as ve, useEffect as ye, useId as be, useMemo as F, useRef as xe, useState as Se } from "react";
|
|
7
|
-
import { router as Ce } from "@inertiajs/core";
|
|
8
|
-
import { Fragment as we, jsx as I, jsxs as L } from "react/jsx-runtime";
|
|
9
|
-
//#region node_modules/react-hook-form/dist/index.esm.mjs
|
|
10
|
-
var Te = (e) => e.type === "checkbox", R = (e) => e instanceof Date, z = (e) => e == null, Ee = (e) => typeof e == "object", B = (e) => !z(e) && !Array.isArray(e) && Ee(e) && !R(e), De = (e) => B(e) && e.target ? Te(e.target) ? e.target.checked : e.target.value : e, Oe = (e, t) => t.split(".").some((t, n, r) => !isNaN(Number(t)) && e.has(r.slice(0, n).join("."))), ke = (e) => {
|
|
11
|
-
let t = e.constructor && e.constructor.prototype;
|
|
12
|
-
return B(t) && t.hasOwnProperty("isPrototypeOf");
|
|
13
|
-
}, Ae = typeof window < "u" && window.HTMLElement !== void 0 && typeof document < "u";
|
|
14
|
-
function V(e) {
|
|
15
|
-
if (e instanceof Date) return new Date(e);
|
|
16
|
-
let t = typeof FileList < "u" && e instanceof FileList;
|
|
17
|
-
if (Ae && (e instanceof Blob || t)) return e;
|
|
18
|
-
let n = Array.isArray(e);
|
|
19
|
-
if (!n && !(B(e) && ke(e))) return e;
|
|
20
|
-
let r = n ? [] : Object.create(Object.getPrototypeOf(e));
|
|
21
|
-
for (let t in e) Object.prototype.hasOwnProperty.call(e, t) && (r[t] = V(e[t]));
|
|
22
|
-
return r;
|
|
23
|
-
}
|
|
24
|
-
var je = (e) => /^\w*$/.test(e), H = (e) => e === void 0, Me = (e) => Array.isArray(e) ? e.filter(Boolean) : [], Ne = (e) => Me(e.replace(/["|']|\]/g, "").split(/\.|\[/)), U = (e, t, n) => {
|
|
25
|
-
if (!t || !B(e)) return n;
|
|
26
|
-
let r = (je(t) ? [t] : Ne(t)).reduce((e, t) => z(e) ? void 0 : e[t], e);
|
|
27
|
-
return H(r) || r === e ? H(e[t]) ? n : e[t] : r;
|
|
28
|
-
}, W = (e) => typeof e == "boolean", G = (e) => typeof e == "function", K = (e, t, n) => {
|
|
29
|
-
let r = -1, i = je(t) ? [t] : Ne(t), a = i.length, o = a - 1;
|
|
30
|
-
for (; ++r < a;) {
|
|
31
|
-
let t = i[r], a = n;
|
|
32
|
-
if (r !== o) {
|
|
33
|
-
let n = e[t];
|
|
34
|
-
a = B(n) || Array.isArray(n) ? n : isNaN(+i[r + 1]) ? {} : [];
|
|
35
|
-
}
|
|
36
|
-
if (t === "__proto__" || t === "constructor" || t === "prototype") return;
|
|
37
|
-
e[t] = a, e = e[t];
|
|
38
|
-
}
|
|
39
|
-
}, Pe = {
|
|
40
|
-
BLUR: "blur",
|
|
41
|
-
FOCUS_OUT: "focusout",
|
|
42
|
-
CHANGE: "change",
|
|
43
|
-
SUBMIT: "submit",
|
|
44
|
-
TRIGGER: "trigger",
|
|
45
|
-
VALID: "valid"
|
|
46
|
-
}, q = {
|
|
47
|
-
onBlur: "onBlur",
|
|
48
|
-
onChange: "onChange",
|
|
49
|
-
onSubmit: "onSubmit",
|
|
50
|
-
onTouched: "onTouched",
|
|
51
|
-
all: "all"
|
|
52
|
-
}, J = {
|
|
53
|
-
max: "max",
|
|
54
|
-
min: "min",
|
|
55
|
-
maxLength: "maxLength",
|
|
56
|
-
minLength: "minLength",
|
|
57
|
-
pattern: "pattern",
|
|
58
|
-
required: "required",
|
|
59
|
-
validate: "validate"
|
|
60
|
-
}, Fe = "form", Ie = "root", Le = M.createContext(null);
|
|
61
|
-
Le.displayName = "HookFormControlContext";
|
|
62
|
-
var Re = () => M.useContext(Le), ze = (e, t, n, r = !0) => {
|
|
63
|
-
let i = {};
|
|
64
|
-
for (let a in e) Object.defineProperty(i, a, { get: () => {
|
|
65
|
-
let i = a;
|
|
66
|
-
return t._proxyFormState[i] !== q.all && (t._proxyFormState[i] = !r || q.all), n && (n[i] = !0), e[i];
|
|
67
|
-
} });
|
|
68
|
-
return i;
|
|
69
|
-
}, Be = typeof window < "u" ? M.useLayoutEffect : M.useEffect, Y = (e) => typeof e == "string", Ve = (e, t, n, r, i) => Y(e) ? (r && t.watch.add(e), U(n, e, i)) : Array.isArray(e) ? e.map((e) => (r && t.watch.add(e), U(n, e))) : (r && (t.watchAll = !0), n), He = (e) => z(e) || !Ee(e);
|
|
70
|
-
function X(e, t, n = /* @__PURE__ */ new WeakSet()) {
|
|
71
|
-
if (e === t) return !0;
|
|
72
|
-
if (He(e) || He(t)) return Object.is(e, t);
|
|
73
|
-
if (R(e) && R(t)) return Object.is(e.getTime(), t.getTime());
|
|
74
|
-
let r = Object.keys(e), i = Object.keys(t);
|
|
75
|
-
if (r.length !== i.length) return !1;
|
|
76
|
-
if (n.has(e) || n.has(t)) return !0;
|
|
77
|
-
n.add(e), n.add(t);
|
|
78
|
-
for (let i of r) {
|
|
79
|
-
let r = e[i];
|
|
80
|
-
if (!(i in t)) return !1;
|
|
81
|
-
if (i !== "ref") {
|
|
82
|
-
let e = t[i];
|
|
83
|
-
if (R(r) && R(e) || (B(r) || Array.isArray(r)) && (B(e) || Array.isArray(e)) ? !X(r, e, n) : !Object.is(r, e)) return !1;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return !0;
|
|
87
|
-
}
|
|
88
|
-
function Ue(e) {
|
|
89
|
-
let t = Re(), { control: n = t, name: r, defaultValue: i, disabled: a, exact: o, compute: s } = e || {}, c = M.useRef(i), l = M.useRef(s), u = M.useRef(void 0), d = M.useRef(n), f = M.useRef(r);
|
|
90
|
-
l.current = s;
|
|
91
|
-
let [p, m] = M.useState(() => {
|
|
92
|
-
let e = n._getWatch(r, c.current);
|
|
93
|
-
return l.current ? l.current(e) : e;
|
|
94
|
-
}), h = M.useCallback((e) => {
|
|
95
|
-
let t = Ve(r, n._names, e || n._formValues, !1, c.current);
|
|
96
|
-
return l.current ? l.current(t) : t;
|
|
97
|
-
}, [
|
|
98
|
-
n._formValues,
|
|
99
|
-
n._names,
|
|
100
|
-
r
|
|
101
|
-
]), g = M.useCallback((e) => {
|
|
102
|
-
if (!a) {
|
|
103
|
-
let t = Ve(r, n._names, e || n._formValues, !1, c.current);
|
|
104
|
-
if (l.current) {
|
|
105
|
-
let e = l.current(t);
|
|
106
|
-
X(e, u.current) || (m(e), u.current = e);
|
|
107
|
-
} else m(t);
|
|
108
|
-
}
|
|
109
|
-
}, [
|
|
110
|
-
n._formValues,
|
|
111
|
-
n._names,
|
|
112
|
-
a,
|
|
113
|
-
r
|
|
114
|
-
]);
|
|
115
|
-
Be(() => ((d.current !== n || !X(f.current, r)) && (d.current = n, f.current = r, g()), n._subscribe({
|
|
116
|
-
name: r,
|
|
117
|
-
formState: { values: !0 },
|
|
118
|
-
exact: o,
|
|
119
|
-
callback: (e) => {
|
|
120
|
-
g(e.values);
|
|
121
|
-
}
|
|
122
|
-
})), [
|
|
123
|
-
n,
|
|
124
|
-
o,
|
|
125
|
-
r,
|
|
126
|
-
g
|
|
127
|
-
]), M.useEffect(() => n._removeUnmounted());
|
|
128
|
-
let _ = d.current !== n, v = f.current, y = M.useMemo(() => {
|
|
129
|
-
if (a) return null;
|
|
130
|
-
let e = !_ && !X(v, r);
|
|
131
|
-
return _ || e ? h() : null;
|
|
132
|
-
}, [
|
|
133
|
-
a,
|
|
134
|
-
_,
|
|
135
|
-
r,
|
|
136
|
-
v,
|
|
137
|
-
h
|
|
138
|
-
]);
|
|
139
|
-
return y === null ? p : y;
|
|
140
|
-
}
|
|
141
|
-
var We = M.createContext(null);
|
|
142
|
-
We.displayName = "HookFormContext";
|
|
143
|
-
var Ge = (e, t, n, r, i) => t ? {
|
|
144
|
-
...n[e],
|
|
145
|
-
types: {
|
|
146
|
-
...n[e] && n[e].types ? n[e].types : {},
|
|
147
|
-
[r]: i || !0
|
|
148
|
-
}
|
|
149
|
-
} : {}, Ke = (e) => Array.isArray(e) ? e : [e], qe = () => {
|
|
150
|
-
let e = [];
|
|
151
|
-
return {
|
|
152
|
-
get observers() {
|
|
153
|
-
return e;
|
|
154
|
-
},
|
|
155
|
-
next: (t) => {
|
|
156
|
-
for (let n of e) n.next && n.next(t);
|
|
157
|
-
},
|
|
158
|
-
subscribe: (t) => (e.push(t), { unsubscribe: () => {
|
|
159
|
-
e = e.filter((e) => e !== t);
|
|
160
|
-
} }),
|
|
161
|
-
unsubscribe: () => {
|
|
162
|
-
e = [];
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
function Je(e, t) {
|
|
167
|
-
let n = {};
|
|
168
|
-
for (let r in e) if (e.hasOwnProperty(r)) {
|
|
169
|
-
let i = e[r], a = t[r];
|
|
170
|
-
if (i && B(i) && a) {
|
|
171
|
-
let e = Je(i, a);
|
|
172
|
-
B(e) && (n[r] = e);
|
|
173
|
-
} else e[r] && (n[r] = a);
|
|
174
|
-
}
|
|
175
|
-
return n;
|
|
176
|
-
}
|
|
177
|
-
var Z = (e) => B(e) && !Object.keys(e).length, Ye = (e) => e.type === "file", Xe = (e) => {
|
|
178
|
-
if (!Ae) return !1;
|
|
179
|
-
let t = e ? e.ownerDocument : 0;
|
|
180
|
-
return e instanceof (t && t.defaultView ? t.defaultView.HTMLElement : HTMLElement);
|
|
181
|
-
}, Ze = (e) => e.type === "select-multiple", Qe = (e) => e.type === "radio", $e = (e) => Qe(e) || Te(e), et = (e) => Xe(e) && e.isConnected;
|
|
182
|
-
function tt(e, t) {
|
|
183
|
-
let n = t.slice(0, -1).length, r = 0;
|
|
184
|
-
for (; r < n;) {
|
|
185
|
-
if (z(e)) {
|
|
186
|
-
e = void 0;
|
|
187
|
-
break;
|
|
188
|
-
}
|
|
189
|
-
e = e[t[r]], r++;
|
|
190
|
-
}
|
|
191
|
-
return e;
|
|
192
|
-
}
|
|
193
|
-
function nt(e) {
|
|
194
|
-
for (let t in e) if (e.hasOwnProperty(t) && !H(e[t])) return !1;
|
|
195
|
-
return !0;
|
|
196
|
-
}
|
|
197
|
-
function Q(e, t) {
|
|
198
|
-
if (Y(t) && Object.prototype.hasOwnProperty.call(e, t)) return delete e[t], e;
|
|
199
|
-
let n = Array.isArray(t) ? t : je(t) ? [t] : Ne(t), r = n.length === 1 ? e : tt(e, n), i = n.length - 1, a = n[i];
|
|
200
|
-
return r && delete r[a], i !== 0 && (B(r) && Z(r) || Array.isArray(r) && nt(r)) && Q(e, n.slice(0, -1)), e;
|
|
201
|
-
}
|
|
202
|
-
var rt = (e) => {
|
|
203
|
-
for (let t in e) if (G(e[t])) return !0;
|
|
204
|
-
return !1;
|
|
205
|
-
};
|
|
206
|
-
function it(e) {
|
|
207
|
-
return Array.isArray(e) || B(e) && !rt(e);
|
|
208
|
-
}
|
|
209
|
-
function at(e, t = {}) {
|
|
210
|
-
for (let n in e) {
|
|
211
|
-
let r = e[n];
|
|
212
|
-
it(r) ? (t[n] = Array.isArray(r) ? [] : {}, at(r, t[n])) : H(r) || (t[n] = !0);
|
|
213
|
-
}
|
|
214
|
-
return t;
|
|
215
|
-
}
|
|
216
|
-
function ot(e) {
|
|
217
|
-
if (e !== !1) {
|
|
218
|
-
if (e === !0) return !0;
|
|
219
|
-
if (Array.isArray(e)) {
|
|
220
|
-
let t = e.map((e) => ot(e));
|
|
221
|
-
return t.some((e) => e !== void 0) ? t : void 0;
|
|
222
|
-
}
|
|
223
|
-
if (B(e)) {
|
|
224
|
-
let t = {};
|
|
225
|
-
for (let n in e) {
|
|
226
|
-
let r = ot(e[n]);
|
|
227
|
-
H(r) || (t[n] = r);
|
|
228
|
-
}
|
|
229
|
-
return Object.keys(t).length ? t : void 0;
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
function st(e, t, n) {
|
|
234
|
-
n ||= at(t);
|
|
235
|
-
for (let r in e) {
|
|
236
|
-
let i = e[r];
|
|
237
|
-
if (it(i)) H(t) || He(n[r]) ? n[r] = at(i, Array.isArray(i) ? [] : {}) : st(i, z(t) ? {} : t[r], n[r]);
|
|
238
|
-
else {
|
|
239
|
-
let e = t[r];
|
|
240
|
-
n[r] = !X(i, e);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
return ot(n) || {};
|
|
244
|
-
}
|
|
245
|
-
var ct = {
|
|
246
|
-
value: !1,
|
|
247
|
-
isValid: !1
|
|
248
|
-
}, lt = {
|
|
249
|
-
value: !0,
|
|
250
|
-
isValid: !0
|
|
251
|
-
}, ut = (e) => {
|
|
252
|
-
if (Array.isArray(e)) {
|
|
253
|
-
if (e.length > 1) {
|
|
254
|
-
let t = e.filter((e) => e && e.checked && !e.disabled).map((e) => e.value);
|
|
255
|
-
return {
|
|
256
|
-
value: t,
|
|
257
|
-
isValid: !!t.length
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
return e[0].checked && !e[0].disabled ? e[0].attributes && !H(e[0].attributes.value) ? H(e[0].value) || e[0].value === "" ? lt : {
|
|
261
|
-
value: e[0].value,
|
|
262
|
-
isValid: !0
|
|
263
|
-
} : lt : ct;
|
|
264
|
-
}
|
|
265
|
-
return ct;
|
|
266
|
-
}, dt = (e, { valueAsNumber: t, valueAsDate: n, setValueAs: r }) => H(e) ? e : t ? e === "" ? NaN : e && +e : n && Y(e) ? new Date(e) : r ? r(e) : e, ft = {
|
|
267
|
-
isValid: !1,
|
|
268
|
-
value: null
|
|
269
|
-
}, pt = (e) => Array.isArray(e) ? e.reduce((e, t) => t && t.checked && !t.disabled ? {
|
|
270
|
-
isValid: !0,
|
|
271
|
-
value: t.value
|
|
272
|
-
} : e, ft) : ft;
|
|
273
|
-
function mt(e) {
|
|
274
|
-
let t = e.ref;
|
|
275
|
-
return Ye(t) ? t.files : Qe(t) ? pt(e.refs).value : Ze(t) ? [...t.selectedOptions].map(({ value: e }) => e) : Te(t) ? ut(e.refs).value : dt(H(t.value) ? e.ref.value : t.value, e);
|
|
276
|
-
}
|
|
277
|
-
var ht = (e, t, n, r) => {
|
|
278
|
-
let i = {};
|
|
279
|
-
for (let n of e) {
|
|
280
|
-
let e = U(t, n);
|
|
281
|
-
e && K(i, n, e._f);
|
|
282
|
-
}
|
|
283
|
-
return {
|
|
284
|
-
criteriaMode: n,
|
|
285
|
-
names: [...e],
|
|
286
|
-
fields: i,
|
|
287
|
-
shouldUseNativeValidation: r
|
|
288
|
-
};
|
|
289
|
-
}, gt = (e) => e instanceof RegExp, _t = (e) => H(e) ? e : gt(e) ? e.source : B(e) ? gt(e.value) ? e.value.source : e.value : e, vt = (e) => ({
|
|
290
|
-
isOnSubmit: !e || e === q.onSubmit,
|
|
291
|
-
isOnBlur: e === q.onBlur,
|
|
292
|
-
isOnChange: e === q.onChange,
|
|
293
|
-
isOnAll: e === q.all,
|
|
294
|
-
isOnTouch: e === q.onTouched
|
|
295
|
-
}), yt = "AsyncFunction", bt = (e) => !!e && !!e.validate && !!(G(e.validate) && e.validate.constructor.name === yt || B(e.validate) && Object.values(e.validate).find((e) => e.constructor.name === yt)), xt = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate), St = (e, t, n) => !n && (t.watchAll || t.watch.has(e) || [...t.watch].some((t) => e.startsWith(t) && /^\.\w+/.test(e.slice(t.length)))), Ct = (e, t, n, r) => {
|
|
296
|
-
for (let i of n || Object.keys(e)) {
|
|
297
|
-
let n = U(e, i);
|
|
298
|
-
if (n) {
|
|
299
|
-
let { _f: e, ...a } = n;
|
|
300
|
-
if (e) {
|
|
301
|
-
if (e.refs && e.refs[0] && t(e.refs[0], i) && !r || e.ref && t(e.ref, e.name) && !r) return !0;
|
|
302
|
-
if (Ct(a, t)) break;
|
|
303
|
-
} else if (B(a) && Ct(a, t)) break;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
function wt(e, t, n) {
|
|
308
|
-
let r = U(e, n);
|
|
309
|
-
if (r || je(n)) return {
|
|
310
|
-
error: r,
|
|
311
|
-
name: n
|
|
312
|
-
};
|
|
313
|
-
let i = n.split(".");
|
|
314
|
-
for (; i.length;) {
|
|
315
|
-
let r = i.join("."), a = U(t, r), o = U(e, r);
|
|
316
|
-
if (a && !Array.isArray(a) && n !== r) return { name: n };
|
|
317
|
-
if (o && o.type) return {
|
|
318
|
-
name: r,
|
|
319
|
-
error: o
|
|
320
|
-
};
|
|
321
|
-
if (o && o.root && o.root.type) return {
|
|
322
|
-
name: `${r}.root`,
|
|
323
|
-
error: o.root
|
|
324
|
-
};
|
|
325
|
-
i.pop();
|
|
326
|
-
}
|
|
327
|
-
return { name: n };
|
|
328
|
-
}
|
|
329
|
-
var Tt = (e, t, n, r) => {
|
|
330
|
-
n(e);
|
|
331
|
-
let { name: i, ...a } = e;
|
|
332
|
-
return Z(a) || r && Object.keys(a).length >= Object.keys(t).length || Object.keys(a).find((e) => t[e] === (!r || q.all));
|
|
333
|
-
}, Et = (e, t, n) => !e || !t || e === t || Ke(e).some((e) => e && (n ? e === t : e.startsWith(t) || t.startsWith(e))), Dt = (e, t, n, r, i) => i.isOnAll ? !1 : !n && i.isOnTouch ? !(t || e) : (n ? r.isOnBlur : i.isOnBlur) ? !e : (n ? r.isOnChange : i.isOnChange) ? e : !0, Ot = (e, t) => !Me(U(e, t)).length && Q(e, t), kt = (e, t, n) => {
|
|
334
|
-
let r = Ke(U(e, n));
|
|
335
|
-
return K(r, Ie, t[n]), K(e, n, r), e;
|
|
336
|
-
};
|
|
337
|
-
function At(e, t, n = "validate") {
|
|
338
|
-
if (Y(e) || Array.isArray(e) && e.every(Y) || W(e) && !e) return {
|
|
339
|
-
type: n,
|
|
340
|
-
message: Y(e) ? e : "",
|
|
341
|
-
ref: t
|
|
342
|
-
};
|
|
343
|
-
}
|
|
344
|
-
var $ = (e) => B(e) && !gt(e) ? e : {
|
|
345
|
-
value: e,
|
|
346
|
-
message: ""
|
|
347
|
-
}, jt = async (e, t, n, r, i, a) => {
|
|
348
|
-
let { ref: o, refs: s, required: c, maxLength: l, minLength: u, min: d, max: f, pattern: p, validate: m, name: h, valueAsNumber: g, mount: _ } = e._f, v = U(n, h);
|
|
349
|
-
if (!_ || t.has(h)) return {};
|
|
350
|
-
let y = s ? s[0] : o, b = (e) => {
|
|
351
|
-
i && y.reportValidity && (y.setCustomValidity(W(e) ? "" : e || ""), y.reportValidity());
|
|
352
|
-
}, x = {}, S = Qe(o), C = Te(o), ee = S || C, w = (g || Ye(o)) && H(o.value) && H(v) || Xe(o) && o.value === "" || v === "" || Array.isArray(v) && !v.length || g && typeof v == "number" && isNaN(v), T = Ge.bind(null, h, r, x), E = (e, t, n, r = J.maxLength, i = J.minLength) => {
|
|
353
|
-
let a = e ? t : n;
|
|
354
|
-
x[h] = {
|
|
355
|
-
type: e ? r : i,
|
|
356
|
-
message: a,
|
|
357
|
-
ref: o,
|
|
358
|
-
...T(e ? r : i, a)
|
|
359
|
-
};
|
|
360
|
-
};
|
|
361
|
-
if (a ? !Array.isArray(v) || !v.length : c && (!ee && (w || z(v)) || W(v) && !v || C && !ut(s).isValid || S && !pt(s).isValid)) {
|
|
362
|
-
let { value: e, message: t } = Y(c) ? {
|
|
363
|
-
value: !!c,
|
|
364
|
-
message: c
|
|
365
|
-
} : $(c);
|
|
366
|
-
if (e && (x[h] = {
|
|
367
|
-
type: J.required,
|
|
368
|
-
message: t,
|
|
369
|
-
ref: y,
|
|
370
|
-
...T(J.required, t)
|
|
371
|
-
}, !r)) return b(t), x;
|
|
372
|
-
}
|
|
373
|
-
if (!w && (!z(d) || !z(f))) {
|
|
374
|
-
let e, t, n = $(f), i = $(d);
|
|
375
|
-
if (!z(v) && !isNaN(v)) {
|
|
376
|
-
let r = o.valueAsNumber || v && +v;
|
|
377
|
-
z(n.value) || (e = r > n.value), z(i.value) || (t = r < i.value);
|
|
378
|
-
} else {
|
|
379
|
-
let r = o.valueAsDate || new Date(v), a = (e) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + e), s = o.type == "time", c = o.type == "week";
|
|
380
|
-
Y(n.value) && v && (e = s ? a(v) > a(n.value) : c ? v > n.value : r > new Date(n.value)), Y(i.value) && v && (t = s ? a(v) < a(i.value) : c ? v < i.value : r < new Date(i.value));
|
|
381
|
-
}
|
|
382
|
-
if ((e || t) && (E(!!e, n.message, i.message, J.max, J.min), !r)) return b(x[h].message), x;
|
|
383
|
-
}
|
|
384
|
-
if ((l || u) && !w && (Y(v) || a && Array.isArray(v))) {
|
|
385
|
-
let e = $(l), t = $(u), n = !z(e.value) && v.length > +e.value, i = !z(t.value) && v.length < +t.value;
|
|
386
|
-
if ((n || i) && (E(n, e.message, t.message), !r)) return b(x[h].message), x;
|
|
387
|
-
}
|
|
388
|
-
if (p && !w && Y(v)) {
|
|
389
|
-
let { value: e, message: t } = $(p);
|
|
390
|
-
if (gt(e) && !v.match(e) && (x[h] = {
|
|
391
|
-
type: J.pattern,
|
|
392
|
-
message: t,
|
|
393
|
-
ref: o,
|
|
394
|
-
...T(J.pattern, t)
|
|
395
|
-
}, !r)) return b(t), x;
|
|
396
|
-
}
|
|
397
|
-
if (m) {
|
|
398
|
-
if (G(m)) {
|
|
399
|
-
let e = At(await m(v, n), y);
|
|
400
|
-
if (e && (x[h] = {
|
|
401
|
-
...e,
|
|
402
|
-
...T(J.validate, e.message)
|
|
403
|
-
}, !r)) return b(e.message), x;
|
|
404
|
-
} else if (B(m)) {
|
|
405
|
-
let e = {};
|
|
406
|
-
for (let t in m) {
|
|
407
|
-
if (!Z(e) && !r) break;
|
|
408
|
-
let i = At(await m[t](v, n), y, t);
|
|
409
|
-
i && (e = {
|
|
410
|
-
...i,
|
|
411
|
-
...T(t, i.message)
|
|
412
|
-
}, b(i.message), r && (x[h] = e));
|
|
413
|
-
}
|
|
414
|
-
if (!Z(e) && (x[h] = {
|
|
415
|
-
ref: y,
|
|
416
|
-
...e
|
|
417
|
-
}, !r)) return x;
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
return b(!0), x;
|
|
421
|
-
}, Mt = {
|
|
422
|
-
mode: q.onSubmit,
|
|
423
|
-
reValidateMode: q.onChange,
|
|
424
|
-
shouldFocusError: !0
|
|
425
|
-
}, Nt = {
|
|
426
|
-
submitCount: 0,
|
|
427
|
-
isDirty: !1,
|
|
428
|
-
isReady: !1,
|
|
429
|
-
isValidating: !1,
|
|
430
|
-
isSubmitted: !1,
|
|
431
|
-
isSubmitting: !1,
|
|
432
|
-
isSubmitSuccessful: !1,
|
|
433
|
-
isValid: !1,
|
|
434
|
-
touchedFields: {},
|
|
435
|
-
dirtyFields: {},
|
|
436
|
-
validatingFields: {}
|
|
437
|
-
};
|
|
438
|
-
function Pt(e = {}) {
|
|
439
|
-
let t = {
|
|
440
|
-
...Mt,
|
|
441
|
-
...e
|
|
442
|
-
}, n = {
|
|
443
|
-
...V(Nt),
|
|
444
|
-
isLoading: G(t.defaultValues),
|
|
445
|
-
errors: t.errors || {},
|
|
446
|
-
disabled: t.disabled || !1
|
|
447
|
-
}, r = {}, i = (B(t.defaultValues) || B(t.values)) && V(t.defaultValues || t.values) || {}, a = t.shouldUnregister ? {} : V(i), o = {
|
|
448
|
-
action: !1,
|
|
449
|
-
mount: !1,
|
|
450
|
-
watch: !1,
|
|
451
|
-
keepIsValid: !1
|
|
452
|
-
}, s = {
|
|
453
|
-
mount: /* @__PURE__ */ new Set(),
|
|
454
|
-
disabled: /* @__PURE__ */ new Set(),
|
|
455
|
-
unMount: /* @__PURE__ */ new Set(),
|
|
456
|
-
array: /* @__PURE__ */ new Set(),
|
|
457
|
-
watch: /* @__PURE__ */ new Set(),
|
|
458
|
-
registerName: /* @__PURE__ */ new Set()
|
|
459
|
-
}, c, l = 0, u = {
|
|
460
|
-
isDirty: !1,
|
|
461
|
-
dirtyFields: !1,
|
|
462
|
-
validatingFields: !1,
|
|
463
|
-
touchedFields: !1,
|
|
464
|
-
isValidating: !1,
|
|
465
|
-
isValid: !1,
|
|
466
|
-
errors: !1
|
|
467
|
-
}, d = { ...u }, f = { ...d }, p = {
|
|
468
|
-
array: qe(),
|
|
469
|
-
state: qe()
|
|
470
|
-
}, m = t.criteriaMode === q.all, h = (e) => (t) => {
|
|
471
|
-
clearTimeout(l), l = setTimeout(e, t);
|
|
472
|
-
}, g = async (e) => {
|
|
473
|
-
if (!o.keepIsValid && !t.disabled && (d.isValid || f.isValid || e)) {
|
|
474
|
-
let e;
|
|
475
|
-
t.resolver ? (e = Z((await w()).errors), _()) : e = await D({
|
|
476
|
-
fields: r,
|
|
477
|
-
onlyCheckValid: !0,
|
|
478
|
-
eventType: Pe.VALID
|
|
479
|
-
}), e !== n.isValid && p.state.next({ isValid: e });
|
|
480
|
-
}
|
|
481
|
-
}, _ = (e, r) => {
|
|
482
|
-
!t.disabled && (d.isValidating || d.validatingFields || f.isValidating || f.validatingFields) && ((e || Array.from(s.mount)).forEach((e) => {
|
|
483
|
-
e && (r ? K(n.validatingFields, e, r) : Q(n.validatingFields, e));
|
|
484
|
-
}), p.state.next({
|
|
485
|
-
validatingFields: n.validatingFields,
|
|
486
|
-
isValidating: !Z(n.validatingFields)
|
|
487
|
-
}));
|
|
488
|
-
}, v = () => {
|
|
489
|
-
n.dirtyFields = st(i, a);
|
|
490
|
-
}, y = (e, i = [], s, c, l = !0, u = !0) => {
|
|
491
|
-
if (c && s && !t.disabled) {
|
|
492
|
-
if (o.action = !0, u && Array.isArray(U(r, e))) {
|
|
493
|
-
let t = s(U(r, e), c.argA, c.argB);
|
|
494
|
-
l && K(r, e, t);
|
|
495
|
-
}
|
|
496
|
-
if (u && Array.isArray(U(n.errors, e))) {
|
|
497
|
-
let t = s(U(n.errors, e), c.argA, c.argB);
|
|
498
|
-
l && K(n.errors, e, t), Ot(n.errors, e);
|
|
499
|
-
}
|
|
500
|
-
if ((d.touchedFields || f.touchedFields) && u && Array.isArray(U(n.touchedFields, e))) {
|
|
501
|
-
let t = s(U(n.touchedFields, e), c.argA, c.argB);
|
|
502
|
-
l && K(n.touchedFields, e, t);
|
|
503
|
-
}
|
|
504
|
-
(d.dirtyFields || f.dirtyFields) && v(), p.state.next({
|
|
505
|
-
name: e,
|
|
506
|
-
isDirty: k(e, i),
|
|
507
|
-
dirtyFields: n.dirtyFields,
|
|
508
|
-
errors: n.errors,
|
|
509
|
-
isValid: n.isValid
|
|
510
|
-
});
|
|
511
|
-
} else K(a, e, i);
|
|
512
|
-
}, b = (e, t) => {
|
|
513
|
-
K(n.errors, e, t), p.state.next({ errors: n.errors });
|
|
514
|
-
}, x = (e) => {
|
|
515
|
-
n.errors = e, p.state.next({
|
|
516
|
-
errors: n.errors,
|
|
517
|
-
isValid: !1
|
|
518
|
-
});
|
|
519
|
-
}, S = (e, t, s, c) => {
|
|
520
|
-
let l = U(r, e);
|
|
521
|
-
if (l) {
|
|
522
|
-
let r = H(U(a, e)), u = U(a, e, H(s) ? U(i, e) : s);
|
|
523
|
-
H(u) || c && c.defaultChecked || t ? K(a, e, t ? u : mt(l._f)) : ne(e, u), o.mount && !o.action && (g(), r && n.isDirty && (d.isDirty || f.isDirty) && (k() || (n.isDirty = !1, p.state.next({ ...n }))));
|
|
524
|
-
}
|
|
525
|
-
}, C = (e, r, a, o, s) => {
|
|
526
|
-
let c = !1, l = !1, u = { name: e };
|
|
527
|
-
if (!t.disabled) {
|
|
528
|
-
if (!a || o) {
|
|
529
|
-
(d.isDirty || f.isDirty) && (l = n.isDirty, n.isDirty = u.isDirty = k(), c = l !== u.isDirty);
|
|
530
|
-
let t = X(U(i, e), r);
|
|
531
|
-
l = !!U(n.dirtyFields, e), t ? Q(n.dirtyFields, e) : K(n.dirtyFields, e, !0), u.dirtyFields = n.dirtyFields, c ||= (d.dirtyFields || f.dirtyFields) && l !== !t;
|
|
532
|
-
}
|
|
533
|
-
if (a) {
|
|
534
|
-
let t = U(n.touchedFields, e);
|
|
535
|
-
t || (K(n.touchedFields, e, a), u.touchedFields = n.touchedFields, c ||= (d.touchedFields || f.touchedFields) && t !== a);
|
|
536
|
-
}
|
|
537
|
-
c && s && p.state.next(u);
|
|
538
|
-
}
|
|
539
|
-
return c ? u : {};
|
|
540
|
-
}, ee = (e, r, i, a) => {
|
|
541
|
-
let o = U(n.errors, e), s = (d.isValid || f.isValid) && W(r) && n.isValid !== r;
|
|
542
|
-
if (t.delayError && i ? (c = h(() => b(e, i)), c(t.delayError)) : (clearTimeout(l), c = null, i ? K(n.errors, e, i) : Q(n.errors, e)), (i ? !X(o, i) : o) || !Z(a) || s) {
|
|
543
|
-
let t = {
|
|
544
|
-
...a,
|
|
545
|
-
...s && W(r) ? { isValid: r } : {},
|
|
546
|
-
errors: n.errors,
|
|
547
|
-
name: e
|
|
548
|
-
};
|
|
549
|
-
n = {
|
|
550
|
-
...n,
|
|
551
|
-
...t
|
|
552
|
-
}, p.state.next(t);
|
|
553
|
-
}
|
|
554
|
-
}, w = async (e) => (_(e, !0), await t.resolver(a, t.context, ht(e || s.mount, r, t.criteriaMode, t.shouldUseNativeValidation))), T = async (e) => {
|
|
555
|
-
let { errors: t } = await w(e);
|
|
556
|
-
if (_(e), e) for (let r of e) {
|
|
557
|
-
let e = U(t, r);
|
|
558
|
-
e ? K(n.errors, r, e) : Q(n.errors, r);
|
|
559
|
-
}
|
|
560
|
-
else n.errors = t;
|
|
561
|
-
return t;
|
|
562
|
-
}, E = async ({ name: t, eventType: r }) => {
|
|
563
|
-
if (e.validate) {
|
|
564
|
-
let i = await e.validate({
|
|
565
|
-
formValues: a,
|
|
566
|
-
formState: n,
|
|
567
|
-
name: t,
|
|
568
|
-
eventType: r
|
|
569
|
-
});
|
|
570
|
-
if (B(i)) for (let e in i) i[e] && de(`${Fe}.${e}`, {
|
|
571
|
-
message: Y(i.message) ? i.message : "",
|
|
572
|
-
type: J.validate
|
|
573
|
-
});
|
|
574
|
-
else Y(i) || !i ? de(Fe, {
|
|
575
|
-
message: i || "",
|
|
576
|
-
type: J.validate
|
|
577
|
-
}) : ue(Fe);
|
|
578
|
-
return i;
|
|
579
|
-
}
|
|
580
|
-
return !0;
|
|
581
|
-
}, D = async ({ fields: r, onlyCheckValid: i, name: o, eventType: c, context: l = {
|
|
582
|
-
valid: !0,
|
|
583
|
-
runRootValidation: !1
|
|
584
|
-
} }) => {
|
|
585
|
-
if (e.validate && (l.runRootValidation = !0, !await E({
|
|
586
|
-
name: o,
|
|
587
|
-
eventType: c
|
|
588
|
-
}) && (l.valid = !1, i))) return l.valid;
|
|
589
|
-
for (let o in r) {
|
|
590
|
-
let u = r[o];
|
|
591
|
-
if (u) {
|
|
592
|
-
let { _f: r, ...f } = u;
|
|
593
|
-
if (r) {
|
|
594
|
-
let o = s.array.has(r.name), c = u._f && bt(u._f);
|
|
595
|
-
c && d.validatingFields && _([r.name], !0);
|
|
596
|
-
let f = await jt(u, s.disabled, a, m, t.shouldUseNativeValidation && !i, o);
|
|
597
|
-
if (c && d.validatingFields && _([r.name]), f[r.name] && (l.valid = !1, i) || (!i && (U(f, r.name) ? o ? kt(n.errors, f, r.name) : K(n.errors, r.name, f[r.name]) : Q(n.errors, r.name)), e.shouldUseNativeValidation && f[r.name])) break;
|
|
598
|
-
}
|
|
599
|
-
!Z(f) && await D({
|
|
600
|
-
context: l,
|
|
601
|
-
onlyCheckValid: i,
|
|
602
|
-
fields: f,
|
|
603
|
-
name: o,
|
|
604
|
-
eventType: c
|
|
605
|
-
});
|
|
606
|
-
}
|
|
607
|
-
}
|
|
608
|
-
return l.valid;
|
|
609
|
-
}, O = () => {
|
|
610
|
-
for (let e of s.unMount) {
|
|
611
|
-
let t = U(r, e);
|
|
612
|
-
t && (t._f.refs ? t._f.refs.every((e) => !et(e)) : !et(t._f.ref)) && he(e);
|
|
613
|
-
}
|
|
614
|
-
s.unMount = /* @__PURE__ */ new Set();
|
|
615
|
-
}, k = (e, n) => !t.disabled && (e && n && K(a, e, n), !X(ce(), i)), A = (e, t, n) => Ve(e, s, { ...o.mount ? a : H(t) ? i : Y(e) ? { [e]: t } : t }, n, t), te = (e) => Me(U(o.mount ? a : i, e, t.shouldUnregister ? U(i, e, []) : [])), ne = (e, t, n = {}) => {
|
|
616
|
-
let i = U(r, e), o = t;
|
|
617
|
-
if (i) {
|
|
618
|
-
let n = i._f;
|
|
619
|
-
n && (!n.disabled && K(a, e, dt(t, n)), o = Xe(n.ref) && z(t) ? "" : t, Ze(n.ref) ? [...n.ref.options].forEach((e) => e.selected = o.includes(e.value)) : n.refs ? Te(n.ref) ? n.refs.forEach((e) => {
|
|
620
|
-
(!e.defaultChecked || !e.disabled) && (Array.isArray(o) ? e.checked = !!o.find((t) => t === e.value) : e.checked = o === e.value || !!o);
|
|
621
|
-
}) : n.refs.forEach((e) => e.checked = e.value === o) : Ye(n.ref) ? n.ref.value = "" : (n.ref.value = o, n.ref.type || p.state.next({
|
|
622
|
-
name: e,
|
|
623
|
-
values: V(a)
|
|
624
|
-
})));
|
|
625
|
-
}
|
|
626
|
-
(n.shouldDirty || n.shouldTouch) && C(e, o, n.shouldTouch, n.shouldDirty, !0), n.shouldValidate && j(e);
|
|
627
|
-
}, re = (e, t, n) => {
|
|
628
|
-
for (let i in t) {
|
|
629
|
-
if (!t.hasOwnProperty(i)) return;
|
|
630
|
-
let a = t[i], o = e + "." + i, c = U(r, o);
|
|
631
|
-
(s.array.has(e) || B(a) || c && !c._f) && !R(a) ? re(o, a, n) : ne(o, a, n);
|
|
632
|
-
}
|
|
633
|
-
}, ie = (e, t, i = {}) => {
|
|
634
|
-
let c = U(r, e), l = s.array.has(e), u = V(t), m = X(U(a, e), u);
|
|
635
|
-
if (K(a, e, u), l) p.array.next({
|
|
636
|
-
name: e,
|
|
637
|
-
values: V(a)
|
|
638
|
-
}), (d.isDirty || d.dirtyFields || f.isDirty || f.dirtyFields) && i.shouldDirty && (v(), p.state.next({
|
|
639
|
-
name: e,
|
|
640
|
-
dirtyFields: n.dirtyFields,
|
|
641
|
-
isDirty: k(e, u)
|
|
642
|
-
}));
|
|
643
|
-
else {
|
|
644
|
-
let t = Array.isArray(u) && !u.length || Z(u);
|
|
645
|
-
!c || c._f || z(u) || t ? ne(e, u, i) : re(e, u, i);
|
|
646
|
-
}
|
|
647
|
-
if (!m) {
|
|
648
|
-
let t = St(e, s);
|
|
649
|
-
p.state.next({
|
|
650
|
-
...t && n,
|
|
651
|
-
name: o.mount || t ? e : void 0,
|
|
652
|
-
values: V(a)
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
}, ae = (e) => {
|
|
656
|
-
let t = G(e) ? e(a) : e;
|
|
657
|
-
X(a, t) || (a = {
|
|
658
|
-
...a,
|
|
659
|
-
...t
|
|
660
|
-
}, p.state.next({
|
|
661
|
-
...n,
|
|
662
|
-
values: a
|
|
663
|
-
}));
|
|
664
|
-
}, oe = async (i) => {
|
|
665
|
-
o.mount = !0;
|
|
666
|
-
let l = i.target, u = l.name, h = !0, v = U(r, u), y = (e) => {
|
|
667
|
-
h = Number.isNaN(e) || R(e) && isNaN(e.getTime()) || X(e, U(a, u, e));
|
|
668
|
-
}, b = vt(t.mode), x = vt(t.reValidateMode);
|
|
669
|
-
if (v) {
|
|
670
|
-
let o, S, T = l.type ? mt(v._f) : De(i), O = i.type === Pe.BLUR || i.type === Pe.FOCUS_OUT, k = !xt(v._f) && !e.validate && !t.resolver && !U(n.errors, u) && !v._f.deps || Dt(O, U(n.touchedFields, u), n.isSubmitted, x, b), A = St(u, s, O);
|
|
671
|
-
K(a, u, T), O ? (!l || !l.readOnly) && (v._f.onBlur && v._f.onBlur(i), c && c(0)) : v._f.onChange && v._f.onChange(i);
|
|
672
|
-
let te = C(u, T, O), ne = !Z(te) || A;
|
|
673
|
-
if (!O && p.state.next({
|
|
674
|
-
name: u,
|
|
675
|
-
type: i.type,
|
|
676
|
-
values: V(a)
|
|
677
|
-
}), k) return (d.isValid || f.isValid) && (t.mode === "onBlur" ? O && g() : O || g()), ne && p.state.next({
|
|
678
|
-
name: u,
|
|
679
|
-
...A ? {} : te
|
|
680
|
-
});
|
|
681
|
-
if (!t.resolver && e.validate && await E({
|
|
682
|
-
name: u,
|
|
683
|
-
eventType: i.type
|
|
684
|
-
}), !O && A && p.state.next({ ...n }), t.resolver) {
|
|
685
|
-
let { errors: e } = await w([u]);
|
|
686
|
-
if (_([u]), y(T), h) {
|
|
687
|
-
let t = wt(n.errors, r, u), i = wt(e, r, t.name || u);
|
|
688
|
-
o = i.error, u = i.name, S = Z(e);
|
|
689
|
-
}
|
|
690
|
-
} else _([u], !0), o = (await jt(v, s.disabled, a, m, t.shouldUseNativeValidation))[u], _([u]), y(T), h && (o ? S = !1 : (d.isValid || f.isValid) && (S = await D({
|
|
691
|
-
fields: r,
|
|
692
|
-
onlyCheckValid: !0,
|
|
693
|
-
name: u,
|
|
694
|
-
eventType: i.type
|
|
695
|
-
})));
|
|
696
|
-
h && (v._f.deps && (!Array.isArray(v._f.deps) || v._f.deps.length > 0) && j(v._f.deps), ee(u, S, o, te));
|
|
697
|
-
}
|
|
698
|
-
}, se = (e, t) => {
|
|
699
|
-
if (U(n.errors, t) && e.focus) return e.focus(), 1;
|
|
700
|
-
}, j = async (e, i = {}) => {
|
|
701
|
-
let a, o, c = Ke(e);
|
|
702
|
-
if (t.resolver) {
|
|
703
|
-
let t = await T(H(e) ? e : c);
|
|
704
|
-
a = Z(t), o = e ? !c.some((e) => U(t, e)) : a;
|
|
705
|
-
} else e ? (o = (await Promise.all(c.map(async (e) => {
|
|
706
|
-
let t = U(r, e);
|
|
707
|
-
return await D({
|
|
708
|
-
fields: t && t._f ? { [e]: t } : t,
|
|
709
|
-
eventType: Pe.TRIGGER
|
|
710
|
-
});
|
|
711
|
-
}))).every(Boolean), !(!o && !n.isValid) && g()) : o = a = await D({
|
|
712
|
-
fields: r,
|
|
713
|
-
name: e,
|
|
714
|
-
eventType: Pe.TRIGGER
|
|
715
|
-
});
|
|
716
|
-
return p.state.next({
|
|
717
|
-
...!Y(e) || (d.isValid || f.isValid) && a !== n.isValid ? {} : { name: e },
|
|
718
|
-
...t.resolver || !e ? { isValid: a } : {},
|
|
719
|
-
errors: n.errors
|
|
720
|
-
}), i.shouldFocus && !o && Ct(r, se, e ? c : s.mount), o;
|
|
721
|
-
}, ce = (e, t) => {
|
|
722
|
-
let r = { ...o.mount ? a : i };
|
|
723
|
-
return t && (r = Je(t.dirtyFields ? n.dirtyFields : n.touchedFields, r)), H(e) ? r : Y(e) ? U(r, e) : e.map((e) => U(r, e));
|
|
724
|
-
}, le = (e, t) => ({
|
|
725
|
-
invalid: !!U((t || n).errors, e),
|
|
726
|
-
isDirty: !!U((t || n).dirtyFields, e),
|
|
727
|
-
error: U((t || n).errors, e),
|
|
728
|
-
isValidating: !!U(n.validatingFields, e),
|
|
729
|
-
isTouched: !!U((t || n).touchedFields, e)
|
|
730
|
-
}), ue = (e) => {
|
|
731
|
-
let t = e ? Ke(e) : void 0;
|
|
732
|
-
t?.forEach((e) => Q(n.errors, e)), t ? t.forEach((e) => {
|
|
733
|
-
p.state.next({
|
|
734
|
-
name: e,
|
|
735
|
-
errors: n.errors
|
|
736
|
-
});
|
|
737
|
-
}) : p.state.next({ errors: {} });
|
|
738
|
-
}, de = (e, t, i) => {
|
|
739
|
-
let a = (U(r, e, { _f: {} })._f || {}).ref, { ref: o, message: s, type: c, ...l } = U(n.errors, e) || {};
|
|
740
|
-
K(n.errors, e, {
|
|
741
|
-
...l,
|
|
742
|
-
...t,
|
|
743
|
-
ref: a
|
|
744
|
-
}), p.state.next({
|
|
745
|
-
name: e,
|
|
746
|
-
errors: n.errors,
|
|
747
|
-
isValid: !1
|
|
748
|
-
}), i && i.shouldFocus && a && a.focus && a.focus();
|
|
749
|
-
}, fe = (e, t) => G(e) ? p.state.subscribe({ next: (n) => "values" in n && e(n.values || A(void 0, t), n) }) : A(e, t, !0), pe = (e) => p.state.subscribe({ next: (t) => {
|
|
750
|
-
if (Et(e.name, t.name, e.exact) && Tt(t, e.formState || d, xe, e.reRenderRoot)) {
|
|
751
|
-
let r = { ...a };
|
|
752
|
-
e.callback({
|
|
753
|
-
values: r,
|
|
754
|
-
...n,
|
|
755
|
-
...t,
|
|
756
|
-
defaultValues: i
|
|
757
|
-
});
|
|
758
|
-
}
|
|
759
|
-
} }).unsubscribe, me = (e) => (o.mount = !0, f = {
|
|
760
|
-
...f,
|
|
761
|
-
...e.formState
|
|
762
|
-
}, pe({
|
|
763
|
-
...e,
|
|
764
|
-
formState: {
|
|
765
|
-
...u,
|
|
766
|
-
...e.formState
|
|
767
|
-
}
|
|
768
|
-
})), he = (e, o = {}) => {
|
|
769
|
-
for (let c of e ? Ke(e) : s.mount) s.mount.delete(c), s.array.delete(c), o.keepValue || (Q(r, c), Q(a, c)), !o.keepError && Q(n.errors, c), !o.keepDirty && Q(n.dirtyFields, c), !o.keepTouched && Q(n.touchedFields, c), !o.keepIsValidating && Q(n.validatingFields, c), !t.shouldUnregister && !o.keepDefaultValue && Q(i, c);
|
|
770
|
-
p.state.next({ values: V(a) }), p.state.next({
|
|
771
|
-
...n,
|
|
772
|
-
...o.keepDirty ? { isDirty: k() } : {}
|
|
773
|
-
}), !o.keepIsValid && g();
|
|
774
|
-
}, ge = ({ disabled: e, name: t }) => {
|
|
775
|
-
if (W(e) && o.mount || e || s.disabled.has(t)) {
|
|
776
|
-
let n = s.disabled.has(t) !== !!e;
|
|
777
|
-
e ? s.disabled.add(t) : s.disabled.delete(t), n && o.mount && !o.action && g();
|
|
778
|
-
}
|
|
779
|
-
}, _e = (e, n = {}) => {
|
|
780
|
-
let a = U(r, e), c = W(n.disabled) || W(t.disabled), l = !s.registerName.has(e) && a && a._f && !a._f.mount;
|
|
781
|
-
return K(r, e, {
|
|
782
|
-
...a || {},
|
|
783
|
-
_f: {
|
|
784
|
-
...a && a._f ? a._f : { ref: { name: e } },
|
|
785
|
-
name: e,
|
|
786
|
-
mount: !0,
|
|
787
|
-
...n
|
|
788
|
-
}
|
|
789
|
-
}), s.mount.add(e), a && !l ? ge({
|
|
790
|
-
disabled: W(n.disabled) ? n.disabled : t.disabled,
|
|
791
|
-
name: e
|
|
792
|
-
}) : S(e, !0, n.value), {
|
|
793
|
-
...c ? { disabled: n.disabled || t.disabled } : {},
|
|
794
|
-
...t.progressive ? {
|
|
795
|
-
required: !!n.required,
|
|
796
|
-
min: _t(n.min),
|
|
797
|
-
max: _t(n.max),
|
|
798
|
-
minLength: _t(n.minLength),
|
|
799
|
-
maxLength: _t(n.maxLength),
|
|
800
|
-
pattern: _t(n.pattern)
|
|
801
|
-
} : {},
|
|
802
|
-
name: e,
|
|
803
|
-
onChange: oe,
|
|
804
|
-
onBlur: oe,
|
|
805
|
-
ref: (c) => {
|
|
806
|
-
if (c) {
|
|
807
|
-
s.registerName.add(e), _e(e, n), s.registerName.delete(e), a = U(r, e);
|
|
808
|
-
let t = H(c.value) && c.querySelectorAll && c.querySelectorAll("input,select,textarea")[0] || c, o = $e(t), l = a._f.refs || [];
|
|
809
|
-
if (o ? l.find((e) => e === t) : t === a._f.ref) return;
|
|
810
|
-
K(r, e, { _f: {
|
|
811
|
-
...a._f,
|
|
812
|
-
...o ? {
|
|
813
|
-
refs: [
|
|
814
|
-
...l.filter(et),
|
|
815
|
-
t,
|
|
816
|
-
...Array.isArray(U(i, e)) ? [{}] : []
|
|
817
|
-
],
|
|
818
|
-
ref: {
|
|
819
|
-
type: t.type,
|
|
820
|
-
name: e
|
|
821
|
-
}
|
|
822
|
-
} : { ref: t }
|
|
823
|
-
} }), S(e, !1, void 0, t);
|
|
824
|
-
} else a = U(r, e, {}), a._f && (a._f.mount = !1), (t.shouldUnregister || n.shouldUnregister) && !(Oe(s.array, e) && o.action) && s.unMount.add(e);
|
|
825
|
-
}
|
|
826
|
-
};
|
|
827
|
-
}, M = () => t.shouldFocusError && Ct(r, se, s.mount), N = (e) => {
|
|
828
|
-
W(e) && (p.state.next({ disabled: e }), Ct(r, (t, n) => {
|
|
829
|
-
let i = U(r, n);
|
|
830
|
-
i && (t.disabled = i._f.disabled || e, Array.isArray(i._f.refs) && i._f.refs.forEach((t) => {
|
|
831
|
-
t.disabled = i._f.disabled || e;
|
|
832
|
-
}));
|
|
833
|
-
}, 0, !1));
|
|
834
|
-
}, P = (e, i) => async (o) => {
|
|
835
|
-
let c;
|
|
836
|
-
o && (o.preventDefault && o.preventDefault(), o.persist && o.persist());
|
|
837
|
-
let l = V(a);
|
|
838
|
-
if (p.state.next({ isSubmitting: !0 }), t.resolver) {
|
|
839
|
-
let { errors: e, values: t } = await w();
|
|
840
|
-
_(), n.errors = e, l = V(t);
|
|
841
|
-
} else await D({
|
|
842
|
-
fields: r,
|
|
843
|
-
eventType: Pe.SUBMIT
|
|
844
|
-
});
|
|
845
|
-
if (s.disabled.size) for (let e of s.disabled) Q(l, e);
|
|
846
|
-
if (Q(n.errors, Ie), Z(n.errors)) {
|
|
847
|
-
p.state.next({ errors: {} });
|
|
848
|
-
try {
|
|
849
|
-
await e(l, o);
|
|
850
|
-
} catch (e) {
|
|
851
|
-
c = e;
|
|
852
|
-
}
|
|
853
|
-
} else i && await i({ ...n.errors }, o), M(), setTimeout(M);
|
|
854
|
-
if (p.state.next({
|
|
855
|
-
isSubmitted: !0,
|
|
856
|
-
isSubmitting: !1,
|
|
857
|
-
isSubmitSuccessful: Z(n.errors) && !c,
|
|
858
|
-
submitCount: n.submitCount + 1,
|
|
859
|
-
errors: n.errors
|
|
860
|
-
}), c) throw c;
|
|
861
|
-
}, ve = (e, t = {}) => {
|
|
862
|
-
U(r, e) && (H(t.defaultValue) ? ie(e, V(U(i, e))) : (ie(e, t.defaultValue), K(i, e, V(t.defaultValue))), t.keepTouched || Q(n.touchedFields, e), t.keepDirty || (Q(n.dirtyFields, e), n.isDirty = t.defaultValue ? k(e, V(U(i, e))) : k()), t.keepError || (Q(n.errors, e), d.isValid && g()), p.state.next({ ...n }));
|
|
863
|
-
}, ye = (e, c = {}) => {
|
|
864
|
-
let l = e ? V(e) : i, u = V(l), f = Z(e), m = f ? i : u;
|
|
865
|
-
if (c.keepDefaultValues || (i = l), !c.keepValues) {
|
|
866
|
-
if (c.keepDirtyValues) {
|
|
867
|
-
let e = new Set([...s.mount, ...Object.keys(st(i, a))]);
|
|
868
|
-
for (let t of Array.from(e)) {
|
|
869
|
-
let e = U(n.dirtyFields, t), r = U(a, t), i = U(m, t);
|
|
870
|
-
e && !H(r) ? K(m, t, r) : !e && !H(i) && ie(t, i);
|
|
871
|
-
}
|
|
872
|
-
} else {
|
|
873
|
-
if (Ae && H(e)) for (let e of s.mount) {
|
|
874
|
-
let t = U(r, e);
|
|
875
|
-
if (t && t._f) {
|
|
876
|
-
let e = Array.isArray(t._f.refs) ? t._f.refs[0] : t._f.ref;
|
|
877
|
-
if (Xe(e)) {
|
|
878
|
-
let t = e.closest("form");
|
|
879
|
-
if (t) {
|
|
880
|
-
t.reset();
|
|
881
|
-
break;
|
|
882
|
-
}
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
}
|
|
886
|
-
if (c.keepFieldsRef) for (let e of s.mount) ie(e, U(m, e));
|
|
887
|
-
else r = {};
|
|
888
|
-
}
|
|
889
|
-
a = t.shouldUnregister ? c.keepDefaultValues ? V(i) : {} : V(m), p.array.next({ values: { ...m } }), p.state.next({ values: { ...m } });
|
|
890
|
-
}
|
|
891
|
-
s = {
|
|
892
|
-
mount: c.keepDirtyValues ? s.mount : /* @__PURE__ */ new Set(),
|
|
893
|
-
unMount: /* @__PURE__ */ new Set(),
|
|
894
|
-
array: /* @__PURE__ */ new Set(),
|
|
895
|
-
registerName: /* @__PURE__ */ new Set(),
|
|
896
|
-
disabled: /* @__PURE__ */ new Set(),
|
|
897
|
-
watch: /* @__PURE__ */ new Set(),
|
|
898
|
-
watchAll: !1,
|
|
899
|
-
focus: ""
|
|
900
|
-
}, o.mount = !d.isValid || !!c.keepIsValid || !!c.keepDirtyValues || !t.shouldUnregister && !Z(m), o.watch = !!t.shouldUnregister, o.keepIsValid = !!c.keepIsValid, o.action = !1, c.keepErrors || (n.errors = {}), p.state.next({
|
|
901
|
-
submitCount: c.keepSubmitCount ? n.submitCount : 0,
|
|
902
|
-
isDirty: f ? !1 : c.keepDirty ? n.isDirty : !!(c.keepDefaultValues && !X(e, i)),
|
|
903
|
-
isSubmitted: c.keepIsSubmitted ? n.isSubmitted : !1,
|
|
904
|
-
dirtyFields: f ? {} : c.keepDirtyValues ? c.keepDefaultValues && a ? st(i, a) : n.dirtyFields : c.keepDefaultValues && e ? st(i, e) : c.keepDirty ? n.dirtyFields : {},
|
|
905
|
-
touchedFields: c.keepTouched ? n.touchedFields : {},
|
|
906
|
-
errors: c.keepErrors ? n.errors : {},
|
|
907
|
-
isSubmitSuccessful: c.keepIsSubmitSuccessful ? n.isSubmitSuccessful : !1,
|
|
908
|
-
isSubmitting: !1,
|
|
909
|
-
defaultValues: i
|
|
910
|
-
});
|
|
911
|
-
}, be = (e, n) => ye(G(e) ? e(a) : e, {
|
|
912
|
-
...t.resetOptions,
|
|
913
|
-
...n
|
|
914
|
-
}), F = (e, t = {}) => {
|
|
915
|
-
let n = U(r, e), i = n && n._f;
|
|
916
|
-
if (i) {
|
|
917
|
-
let e = i.refs ? i.refs[0] : i.ref;
|
|
918
|
-
e.focus && setTimeout(() => {
|
|
919
|
-
e.focus(), t.shouldSelect && G(e.select) && e.select();
|
|
920
|
-
});
|
|
921
|
-
}
|
|
922
|
-
}, xe = (e) => {
|
|
923
|
-
n = {
|
|
924
|
-
...n,
|
|
925
|
-
...e
|
|
926
|
-
};
|
|
927
|
-
}, Se = {
|
|
928
|
-
control: {
|
|
929
|
-
register: _e,
|
|
930
|
-
unregister: he,
|
|
931
|
-
getFieldState: le,
|
|
932
|
-
handleSubmit: P,
|
|
933
|
-
setError: de,
|
|
934
|
-
_subscribe: pe,
|
|
935
|
-
_runSchema: w,
|
|
936
|
-
_updateIsValidating: _,
|
|
937
|
-
_focusError: M,
|
|
938
|
-
_getWatch: A,
|
|
939
|
-
_getDirty: k,
|
|
940
|
-
_setValid: g,
|
|
941
|
-
_setFieldArray: y,
|
|
942
|
-
_setDisabledField: ge,
|
|
943
|
-
_setErrors: x,
|
|
944
|
-
_getFieldArray: te,
|
|
945
|
-
_reset: ye,
|
|
946
|
-
_resetDefaultValues: () => G(t.defaultValues) && t.defaultValues().then((e) => {
|
|
947
|
-
be(e, t.resetOptions), p.state.next({ isLoading: !1 });
|
|
948
|
-
}),
|
|
949
|
-
_removeUnmounted: O,
|
|
950
|
-
_disableForm: N,
|
|
951
|
-
_subjects: p,
|
|
952
|
-
_proxyFormState: d,
|
|
953
|
-
get _fields() {
|
|
954
|
-
return r;
|
|
955
|
-
},
|
|
956
|
-
get _formValues() {
|
|
957
|
-
return a;
|
|
958
|
-
},
|
|
959
|
-
get _state() {
|
|
960
|
-
return o;
|
|
961
|
-
},
|
|
962
|
-
set _state(e) {
|
|
963
|
-
o = e;
|
|
964
|
-
},
|
|
965
|
-
get _defaultValues() {
|
|
966
|
-
return i;
|
|
967
|
-
},
|
|
968
|
-
get _names() {
|
|
969
|
-
return s;
|
|
970
|
-
},
|
|
971
|
-
set _names(e) {
|
|
972
|
-
s = e;
|
|
973
|
-
},
|
|
974
|
-
get _formState() {
|
|
975
|
-
return n;
|
|
976
|
-
},
|
|
977
|
-
get _options() {
|
|
978
|
-
return t;
|
|
979
|
-
},
|
|
980
|
-
set _options(e) {
|
|
981
|
-
t = {
|
|
982
|
-
...t,
|
|
983
|
-
...e
|
|
984
|
-
};
|
|
985
|
-
}
|
|
986
|
-
},
|
|
987
|
-
subscribe: me,
|
|
988
|
-
trigger: j,
|
|
989
|
-
register: _e,
|
|
990
|
-
handleSubmit: P,
|
|
991
|
-
watch: fe,
|
|
992
|
-
setValue: ie,
|
|
993
|
-
setValues: ae,
|
|
994
|
-
getValues: ce,
|
|
995
|
-
reset: be,
|
|
996
|
-
resetField: ve,
|
|
997
|
-
clearErrors: ue,
|
|
998
|
-
unregister: he,
|
|
999
|
-
setError: de,
|
|
1000
|
-
setFocus: F,
|
|
1001
|
-
getFieldState: le
|
|
1002
|
-
};
|
|
1003
|
-
return {
|
|
1004
|
-
...Se,
|
|
1005
|
-
formControl: Se
|
|
1006
|
-
};
|
|
1007
|
-
}
|
|
1008
|
-
function Ft(e = {}) {
|
|
1009
|
-
let t = M.useRef(void 0), n = M.useRef(void 0), [r, i] = M.useState(() => ({
|
|
1010
|
-
...V(Nt),
|
|
1011
|
-
isLoading: G(e.defaultValues),
|
|
1012
|
-
errors: e.errors || {},
|
|
1013
|
-
disabled: e.disabled || !1,
|
|
1014
|
-
defaultValues: G(e.defaultValues) ? void 0 : e.defaultValues
|
|
1015
|
-
}));
|
|
1016
|
-
if (!t.current) if (e.formControl) t.current = {
|
|
1017
|
-
...e.formControl,
|
|
1018
|
-
formState: r
|
|
1019
|
-
}, e.defaultValues && !G(e.defaultValues) && e.formControl.reset(e.defaultValues, e.resetOptions);
|
|
1020
|
-
else {
|
|
1021
|
-
let { formControl: n, ...i } = Pt(e);
|
|
1022
|
-
t.current = {
|
|
1023
|
-
...i,
|
|
1024
|
-
formState: r
|
|
1025
|
-
};
|
|
1026
|
-
}
|
|
1027
|
-
let a = t.current.control;
|
|
1028
|
-
return a._options = e, Be(() => {
|
|
1029
|
-
let e = a._subscribe({
|
|
1030
|
-
formState: a._proxyFormState,
|
|
1031
|
-
callback: () => i({ ...a._formState }),
|
|
1032
|
-
reRenderRoot: !0
|
|
1033
|
-
});
|
|
1034
|
-
return i((e) => ({
|
|
1035
|
-
...e,
|
|
1036
|
-
isReady: !0
|
|
1037
|
-
})), a._formState.isReady = !0, e;
|
|
1038
|
-
}, [a]), M.useEffect(() => a._disableForm(e.disabled), [a, e.disabled]), M.useEffect(() => {
|
|
1039
|
-
e.mode && (a._options.mode = e.mode), e.reValidateMode && (a._options.reValidateMode = e.reValidateMode);
|
|
1040
|
-
}, [
|
|
1041
|
-
a,
|
|
1042
|
-
e.mode,
|
|
1043
|
-
e.reValidateMode
|
|
1044
|
-
]), M.useEffect(() => {
|
|
1045
|
-
e.errors && (a._setErrors(e.errors), a._focusError());
|
|
1046
|
-
}, [a, e.errors]), M.useEffect(() => {
|
|
1047
|
-
e.shouldUnregister && a._subjects.state.next({ values: a._getWatch() });
|
|
1048
|
-
}, [a, e.shouldUnregister]), M.useEffect(() => {
|
|
1049
|
-
if (a._proxyFormState.isDirty) {
|
|
1050
|
-
let e = a._getDirty();
|
|
1051
|
-
e !== r.isDirty && a._subjects.state.next({ isDirty: e });
|
|
1052
|
-
}
|
|
1053
|
-
}, [a, r.isDirty]), M.useEffect(() => {
|
|
1054
|
-
e.values && !X(e.values, n.current) ? (a._reset(e.values, {
|
|
1055
|
-
keepFieldsRef: !0,
|
|
1056
|
-
...a._options.resetOptions
|
|
1057
|
-
}), a._options.resetOptions?.keepIsValid || a._setValid(), n.current = e.values, i((e) => ({ ...e }))) : a._resetDefaultValues();
|
|
1058
|
-
}, [a, e.values]), M.useEffect(() => {
|
|
1059
|
-
a._state.mount || (a._setValid(), a._state.mount = !0), a._state.watch && (a._state.watch = !1, a._subjects.state.next({ ...a._formState })), a._removeUnmounted();
|
|
1060
|
-
}), t.current.formState = M.useMemo(() => ze(r, a), [a, r]), t.current;
|
|
1061
|
-
}
|
|
1062
|
-
//#endregion
|
|
1063
|
-
//#region node_modules/@hookform/resolvers/dist/resolvers.mjs
|
|
1064
|
-
var It = (e, t, n) => {
|
|
1065
|
-
if (e && "reportValidity" in e) {
|
|
1066
|
-
let r = U(n, t);
|
|
1067
|
-
e.setCustomValidity(r && r.message || ""), e.reportValidity();
|
|
1068
|
-
}
|
|
1069
|
-
}, Lt = (e, t) => {
|
|
1070
|
-
for (let n in t.fields) {
|
|
1071
|
-
let r = t.fields[n];
|
|
1072
|
-
r && r.ref && "reportValidity" in r.ref ? It(r.ref, n, e) : r && r.refs && r.refs.forEach((t) => It(t, n, e));
|
|
1073
|
-
}
|
|
1074
|
-
}, Rt = (e, t) => {
|
|
1075
|
-
t.shouldUseNativeValidation && Lt(e, t);
|
|
1076
|
-
let n = {};
|
|
1077
|
-
for (let r in e) {
|
|
1078
|
-
let i = U(t.fields, r), a = Object.assign(e[r] || {}, { ref: i && i.ref });
|
|
1079
|
-
if (zt(t.names || Object.keys(e), r)) {
|
|
1080
|
-
let e = Object.assign({}, U(n, r));
|
|
1081
|
-
K(e, "root", a), K(n, r, e);
|
|
1082
|
-
} else K(n, r, a);
|
|
1083
|
-
}
|
|
1084
|
-
return n;
|
|
1085
|
-
}, zt = (e, t) => {
|
|
1086
|
-
let n = Bt(t);
|
|
1087
|
-
return e.some((e) => Bt(e).match(`^${n}\\.\\d+`));
|
|
1088
|
-
};
|
|
1089
|
-
function Bt(e) {
|
|
1090
|
-
return e.replace(/\]|\[/g, "");
|
|
1091
|
-
}
|
|
1092
|
-
//#endregion
|
|
1093
|
-
//#region node_modules/@hookform/resolvers/zod/dist/zod.mjs
|
|
1094
|
-
function Vt(e, t) {
|
|
1095
|
-
try {
|
|
1096
|
-
var n = e();
|
|
1097
|
-
} catch (e) {
|
|
1098
|
-
return t(e);
|
|
1099
|
-
}
|
|
1100
|
-
return n && n.then ? n.then(void 0, t) : n;
|
|
1101
|
-
}
|
|
1102
|
-
function Ht(e, t) {
|
|
1103
|
-
for (var n = {}; e.length;) {
|
|
1104
|
-
var r = e[0], i = r.code, a = r.message, o = r.path.join(".");
|
|
1105
|
-
if (!n[o]) if ("unionErrors" in r) {
|
|
1106
|
-
var s = r.unionErrors[0].errors[0];
|
|
1107
|
-
n[o] = {
|
|
1108
|
-
message: s.message,
|
|
1109
|
-
type: s.code
|
|
1110
|
-
};
|
|
1111
|
-
} else n[o] = {
|
|
1112
|
-
message: a,
|
|
1113
|
-
type: i
|
|
1114
|
-
};
|
|
1115
|
-
if ("unionErrors" in r && r.unionErrors.forEach(function(t) {
|
|
1116
|
-
return t.errors.forEach(function(t) {
|
|
1117
|
-
return e.push(t);
|
|
1118
|
-
});
|
|
1119
|
-
}), t) {
|
|
1120
|
-
var c = n[o].types, l = c && c[r.code];
|
|
1121
|
-
n[o] = Ge(o, t, n, i, l ? [].concat(l, r.message) : r.message);
|
|
1122
|
-
}
|
|
1123
|
-
e.shift();
|
|
1124
|
-
}
|
|
1125
|
-
return n;
|
|
1126
|
-
}
|
|
1127
|
-
function Ut(e, t) {
|
|
1128
|
-
for (var n = {}; e.length;) {
|
|
1129
|
-
var r = e[0], i = r.code, a = r.message, o = r.path.join(".");
|
|
1130
|
-
if (!n[o]) if (r.code === "invalid_union" && r.errors.length > 0) {
|
|
1131
|
-
var s = r.errors[0][0];
|
|
1132
|
-
n[o] = {
|
|
1133
|
-
message: s.message,
|
|
1134
|
-
type: s.code
|
|
1135
|
-
};
|
|
1136
|
-
} else n[o] = {
|
|
1137
|
-
message: a,
|
|
1138
|
-
type: i
|
|
1139
|
-
};
|
|
1140
|
-
if (r.code === "invalid_union" && r.errors.forEach(function(t) {
|
|
1141
|
-
return t.forEach(function(t) {
|
|
1142
|
-
return e.push(t);
|
|
1143
|
-
});
|
|
1144
|
-
}), t) {
|
|
1145
|
-
var c = n[o].types, l = c && c[r.code];
|
|
1146
|
-
n[o] = Ge(o, t, n, i, l ? [].concat(l, r.message) : r.message);
|
|
1147
|
-
}
|
|
1148
|
-
e.shift();
|
|
1149
|
-
}
|
|
1150
|
-
return n;
|
|
1151
|
-
}
|
|
1152
|
-
function Wt(e, t, n) {
|
|
1153
|
-
if (n === void 0 && (n = {}), function(e) {
|
|
1154
|
-
return "_def" in e && typeof e._def == "object" && "typeName" in e._def;
|
|
1155
|
-
}(e)) return function(r, i, a) {
|
|
1156
|
-
try {
|
|
1157
|
-
return Promise.resolve(Vt(function() {
|
|
1158
|
-
return Promise.resolve(e[n.mode === "sync" ? "parse" : "parseAsync"](r, t)).then(function(e) {
|
|
1159
|
-
return a.shouldUseNativeValidation && Lt({}, a), {
|
|
1160
|
-
errors: {},
|
|
1161
|
-
values: n.raw ? Object.assign({}, r) : e
|
|
1162
|
-
};
|
|
1163
|
-
});
|
|
1164
|
-
}, function(e) {
|
|
1165
|
-
if (function(e) {
|
|
1166
|
-
return Array.isArray(e?.issues);
|
|
1167
|
-
}(e)) return {
|
|
1168
|
-
values: {},
|
|
1169
|
-
errors: Rt(Ht(e.errors, !a.shouldUseNativeValidation && a.criteriaMode === "all"), a)
|
|
1170
|
-
};
|
|
1171
|
-
throw e;
|
|
1172
|
-
}));
|
|
1173
|
-
} catch (e) {
|
|
1174
|
-
return Promise.reject(e);
|
|
1175
|
-
}
|
|
1176
|
-
};
|
|
1177
|
-
if (function(e) {
|
|
1178
|
-
return "_zod" in e && typeof e._zod == "object";
|
|
1179
|
-
}(e)) return function(r, i, a) {
|
|
1180
|
-
try {
|
|
1181
|
-
return Promise.resolve(Vt(function() {
|
|
1182
|
-
return Promise.resolve((n.mode === "sync" ? l : f)(e, r, t)).then(function(e) {
|
|
1183
|
-
return a.shouldUseNativeValidation && Lt({}, a), {
|
|
1184
|
-
errors: {},
|
|
1185
|
-
values: n.raw ? Object.assign({}, r) : e
|
|
1186
|
-
};
|
|
1187
|
-
});
|
|
1188
|
-
}, function(e) {
|
|
1189
|
-
if (function(e) {
|
|
1190
|
-
return e instanceof o;
|
|
1191
|
-
}(e)) return {
|
|
1192
|
-
values: {},
|
|
1193
|
-
errors: Rt(Ut(e.issues, !a.shouldUseNativeValidation && a.criteriaMode === "all"), a)
|
|
1194
|
-
};
|
|
1195
|
-
throw e;
|
|
1196
|
-
}));
|
|
1197
|
-
} catch (e) {
|
|
1198
|
-
return Promise.reject(e);
|
|
1199
|
-
}
|
|
1200
|
-
};
|
|
1201
|
-
throw Error("Invalid input: not a Zod schema");
|
|
1202
|
-
}
|
|
1203
|
-
//#endregion
|
|
1204
|
-
//#region src/base/form/form-utils.ts
|
|
1205
|
-
function Gt(e) {
|
|
1206
|
-
let t = [];
|
|
1207
|
-
for (let n of e) n.kind === "field" ? t.push(n) : (n.kind === "section" || n.kind === "group") && t.push(...Gt(n.children));
|
|
1208
|
-
return t;
|
|
1209
|
-
}
|
|
1210
|
-
function Kt(e, t) {
|
|
1211
|
-
if (e.component === "header") return !0;
|
|
1212
|
-
let { props: n } = e;
|
|
1213
|
-
return !(n.hidden_when && u(n.hidden_when, t) || n.visible_when && !u(n.visible_when, t));
|
|
1214
|
-
}
|
|
1215
|
-
function qt(e, t) {
|
|
1216
|
-
if (e.component === "header") return !1;
|
|
1217
|
-
let { props: n } = e;
|
|
1218
|
-
return !!(n.disabled || n.disabled_when && u(n.disabled_when, t));
|
|
1219
|
-
}
|
|
1220
|
-
function Jt(e, t) {
|
|
1221
|
-
if (e.component === "header" || qt(e, t)) return !1;
|
|
1222
|
-
let { props: n } = e;
|
|
1223
|
-
return !!(n.required || n.required_when && u(n.required_when, t));
|
|
1224
|
-
}
|
|
1225
|
-
//#endregion
|
|
1226
|
-
//#region src/base/form/form-schema-builder.ts
|
|
1227
|
-
function Yt(e, t, n) {
|
|
1228
|
-
let { component: i, props: o } = e, s = o.validation, c = n;
|
|
1229
|
-
switch (i) {
|
|
1230
|
-
case "text":
|
|
1231
|
-
case "textarea":
|
|
1232
|
-
case "password":
|
|
1233
|
-
case "slug":
|
|
1234
|
-
case "color": {
|
|
1235
|
-
let e = k();
|
|
1236
|
-
return c && (e = e.min(1, t("middag.ui.validation.required"))), s?.minLength && (e = e.min(s.minLength, t("middag.ui.validation.min_length", { min: s.minLength }))), s?.maxLength && (e = e.max(s.maxLength, t("middag.ui.validation.max_length", { max: s.maxLength }))), s?.pattern && (e = e.regex(new RegExp(s.pattern), s.patternMessage ?? t("middag.ui.validation.pattern"))), c ? e : e.or(r(""));
|
|
1237
|
-
}
|
|
1238
|
-
case "email": {
|
|
1239
|
-
let e = k();
|
|
1240
|
-
if (c) e = e.min(1, t("middag.ui.validation.required")).email(t("middag.ui.validation.email"));
|
|
1241
|
-
else return e.email(t("middag.ui.validation.email")).or(r(""));
|
|
1242
|
-
return e;
|
|
1243
|
-
}
|
|
1244
|
-
case "url": {
|
|
1245
|
-
let e = k();
|
|
1246
|
-
if (c) e = e.min(1, t("middag.ui.validation.required")).url(t("middag.ui.validation.url"));
|
|
1247
|
-
else return e.url(t("middag.ui.validation.url")).or(r(""));
|
|
1248
|
-
return e;
|
|
1249
|
-
}
|
|
1250
|
-
case "int": {
|
|
1251
|
-
let e = d({ message: t("middag.ui.validation.integer") }).int(t("middag.ui.validation.integer"));
|
|
1252
|
-
return o.min != null && (e = e.min(o.min, t("middag.ui.validation.min_value", { min: o.min }))), o.max != null && (e = e.max(o.max, t("middag.ui.validation.max_value", { max: o.max }))), c ? e : e.nullable();
|
|
1253
|
-
}
|
|
1254
|
-
case "float": {
|
|
1255
|
-
let e = d();
|
|
1256
|
-
return o.min != null && (e = e.min(o.min, t("middag.ui.validation.min_value", { min: o.min }))), o.max != null && (e = e.max(o.max, t("middag.ui.validation.max_value", { max: o.max }))), c ? e : e.nullable();
|
|
1257
|
-
}
|
|
1258
|
-
case "currency": {
|
|
1259
|
-
let e = d();
|
|
1260
|
-
return c ? e : e.nullable();
|
|
1261
|
-
}
|
|
1262
|
-
case "select":
|
|
1263
|
-
case "radio":
|
|
1264
|
-
case "entity_picker": {
|
|
1265
|
-
let e = k();
|
|
1266
|
-
return c ? e.min(1, t("middag.ui.validation.required")) : e;
|
|
1267
|
-
}
|
|
1268
|
-
case "multiselect":
|
|
1269
|
-
case "tags": {
|
|
1270
|
-
let e = m(k());
|
|
1271
|
-
return c ? e.min(1, t("middag.ui.validation.required")) : e;
|
|
1272
|
-
}
|
|
1273
|
-
case "checkbox":
|
|
1274
|
-
case "switch": return a();
|
|
1275
|
-
case "date":
|
|
1276
|
-
case "datetime": {
|
|
1277
|
-
let e = k();
|
|
1278
|
-
return c ? e.min(1, t("middag.ui.validation.required")) : e;
|
|
1279
|
-
}
|
|
1280
|
-
case "phone": {
|
|
1281
|
-
let e = k();
|
|
1282
|
-
return c ? e.min(1, t("middag.ui.validation.required")) : e;
|
|
1283
|
-
}
|
|
1284
|
-
case "document": {
|
|
1285
|
-
let e = o.documentType ?? "generic", n = o.documentScope ?? "any", r = k(), i = async (t) => {
|
|
1286
|
-
let { isValidDocument: r } = await import("./document-validation-BSjTDZhG.js");
|
|
1287
|
-
return r(t, e, n);
|
|
1288
|
-
};
|
|
1289
|
-
return c ? r.min(1, t("middag.ui.validation.required")).refine(i, t("middag.ui.validation.document_invalid")) : r.refine(async (e) => e === "" || await i(e), t("middag.ui.validation.document_invalid"));
|
|
1290
|
-
}
|
|
1291
|
-
default: return fe();
|
|
1292
|
-
}
|
|
1293
|
-
}
|
|
1294
|
-
function Xt(e, t, n) {
|
|
1295
|
-
let r = Gt(e), i = {};
|
|
1296
|
-
for (let e of r) e.component === "header" || e.component === "hidden" || e.component === "static" || Kt(e, t) && (i[e.key] = Yt(e, n, Jt(e, t)));
|
|
1297
|
-
return A(i);
|
|
1298
|
-
}
|
|
1299
|
-
//#endregion
|
|
1300
|
-
//#region src/base/form/FormField.tsx
|
|
1301
|
-
var Zt = P(() => import("./PhoneField-BtLI699n.js").then((e) => ({ default: e.PhoneField }))), Qt = P(() => import("./DateField-CryguepA.js").then((e) => ({ default: e.DateField }))), $t = P(() => import("./DocumentField-4wTGkMH-.js").then((e) => ({ default: e.DocumentField }))), en = P(() => import("./DateRangeField-o5tUrAR8.js").then((e) => ({ default: e.DateRangeField })));
|
|
1302
|
-
function tn() {
|
|
1303
|
-
return /* @__PURE__ */ I(_e, { className: "h-9 w-full rounded-md" });
|
|
1304
|
-
}
|
|
1305
|
-
function nn({ label: e }) {
|
|
1306
|
-
return /* @__PURE__ */ I("div", {
|
|
1307
|
-
className: "pt-4 pb-1",
|
|
1308
|
-
children: /* @__PURE__ */ I("h4", {
|
|
1309
|
-
className: "text-foreground text-sm font-semibold",
|
|
1310
|
-
children: e
|
|
1311
|
-
})
|
|
1312
|
-
});
|
|
1313
|
-
}
|
|
1314
|
-
function rn({ id: e, value: t }) {
|
|
1315
|
-
return /* @__PURE__ */ I("input", {
|
|
1316
|
-
type: "hidden",
|
|
1317
|
-
id: e,
|
|
1318
|
-
value: String(t ?? "")
|
|
1319
|
-
});
|
|
1320
|
-
}
|
|
1321
|
-
function an({ field: e, value: t, onChange: r, error: i, sourceValues: a = {} }) {
|
|
1322
|
-
let { t: o } = he(), s = be(), c = `field-${e.key}-${s}`, l = `${c}-help`, u = `${c}-error`, { component: d, props: f } = e;
|
|
1323
|
-
if (d === "header") return /* @__PURE__ */ I(nn, { label: f.label });
|
|
1324
|
-
if (d === "hidden") return /* @__PURE__ */ I(rn, {
|
|
1325
|
-
id: c,
|
|
1326
|
-
value: t
|
|
1327
|
-
});
|
|
1328
|
-
let p = qt(e, a), m = Jt(e, a), h = d === "checkbox" || d === "switch", g = on(d, c, t, r, f, i, l, u, o, a, p, m);
|
|
1329
|
-
return /* @__PURE__ */ L("div", {
|
|
1330
|
-
className: "space-y-1.5",
|
|
1331
|
-
children: [
|
|
1332
|
-
!h && /* @__PURE__ */ L(n, {
|
|
1333
|
-
htmlFor: c,
|
|
1334
|
-
children: [f.label, m && /* @__PURE__ */ I("span", {
|
|
1335
|
-
className: "text-destructive ml-0.5",
|
|
1336
|
-
children: "*"
|
|
1337
|
-
})]
|
|
1338
|
-
}),
|
|
1339
|
-
f.helpText && /* @__PURE__ */ I("p", {
|
|
1340
|
-
id: l,
|
|
1341
|
-
className: "text-muted-foreground text-xs",
|
|
1342
|
-
children: f.helpText
|
|
1343
|
-
}),
|
|
1344
|
-
g,
|
|
1345
|
-
i && /* @__PURE__ */ I("p", {
|
|
1346
|
-
id: u,
|
|
1347
|
-
className: "text-destructive text-xs",
|
|
1348
|
-
"aria-live": "polite",
|
|
1349
|
-
children: i
|
|
1350
|
-
})
|
|
1351
|
-
]
|
|
1352
|
-
});
|
|
1353
|
-
}
|
|
1354
|
-
function on(e, t, n, r, a, o, s, c, l, u, d, f) {
|
|
1355
|
-
let m = {
|
|
1356
|
-
id: t,
|
|
1357
|
-
error: o,
|
|
1358
|
-
helpTextId: s,
|
|
1359
|
-
errorId: c,
|
|
1360
|
-
disabled: d,
|
|
1361
|
-
required: f
|
|
1362
|
-
};
|
|
1363
|
-
switch (e) {
|
|
1364
|
-
case "text": return /* @__PURE__ */ I(se, {
|
|
1365
|
-
...m,
|
|
1366
|
-
type: "text",
|
|
1367
|
-
value: n,
|
|
1368
|
-
onChange: r,
|
|
1369
|
-
placeholder: a.placeholder,
|
|
1370
|
-
readOnly: a.readOnly
|
|
1371
|
-
});
|
|
1372
|
-
case "email": return /* @__PURE__ */ I(se, {
|
|
1373
|
-
...m,
|
|
1374
|
-
type: "email",
|
|
1375
|
-
value: n,
|
|
1376
|
-
onChange: r,
|
|
1377
|
-
placeholder: a.placeholder,
|
|
1378
|
-
readOnly: a.readOnly
|
|
1379
|
-
});
|
|
1380
|
-
case "url": return /* @__PURE__ */ I(se, {
|
|
1381
|
-
...m,
|
|
1382
|
-
type: "url",
|
|
1383
|
-
value: n,
|
|
1384
|
-
onChange: r,
|
|
1385
|
-
placeholder: a.placeholder,
|
|
1386
|
-
readOnly: a.readOnly
|
|
1387
|
-
});
|
|
1388
|
-
case "textarea": return /* @__PURE__ */ I(O, {
|
|
1389
|
-
...m,
|
|
1390
|
-
value: n,
|
|
1391
|
-
onChange: r,
|
|
1392
|
-
placeholder: a.placeholder,
|
|
1393
|
-
rows: a.rows,
|
|
1394
|
-
readOnly: a.readOnly
|
|
1395
|
-
});
|
|
1396
|
-
case "password": return /* @__PURE__ */ I(ne, {
|
|
1397
|
-
...m,
|
|
1398
|
-
value: n,
|
|
1399
|
-
onChange: r,
|
|
1400
|
-
placeholder: a.placeholder
|
|
1401
|
-
});
|
|
1402
|
-
case "otp": return /* @__PURE__ */ I(D, {
|
|
1403
|
-
...m,
|
|
1404
|
-
value: n,
|
|
1405
|
-
onChange: r,
|
|
1406
|
-
maxLength: a.maxLength,
|
|
1407
|
-
pattern: a.pattern,
|
|
1408
|
-
groupSize: a.groupSize
|
|
1409
|
-
});
|
|
1410
|
-
case "select": return /* @__PURE__ */ I(ee, {
|
|
1411
|
-
...m,
|
|
1412
|
-
value: n,
|
|
1413
|
-
onChange: r,
|
|
1414
|
-
options: a.options ?? [],
|
|
1415
|
-
placeholder: a.placeholder
|
|
1416
|
-
});
|
|
1417
|
-
case "native_select": return /* @__PURE__ */ I(y, {
|
|
1418
|
-
...m,
|
|
1419
|
-
value: n,
|
|
1420
|
-
onChange: r,
|
|
1421
|
-
options: a.options ?? [],
|
|
1422
|
-
placeholder: a.placeholder
|
|
1423
|
-
});
|
|
1424
|
-
case "multiselect": return /* @__PURE__ */ I(ue, {
|
|
1425
|
-
...m,
|
|
1426
|
-
value: n,
|
|
1427
|
-
onChange: r,
|
|
1428
|
-
options: a.options ?? [],
|
|
1429
|
-
placeholder: a.placeholder
|
|
1430
|
-
});
|
|
1431
|
-
case "radio": return /* @__PURE__ */ I(oe, {
|
|
1432
|
-
...m,
|
|
1433
|
-
value: n,
|
|
1434
|
-
onChange: r,
|
|
1435
|
-
options: a.options ?? []
|
|
1436
|
-
});
|
|
1437
|
-
case "int": return /* @__PURE__ */ I(E, {
|
|
1438
|
-
...m,
|
|
1439
|
-
value: n,
|
|
1440
|
-
onChange: r,
|
|
1441
|
-
min: a.min,
|
|
1442
|
-
max: a.max,
|
|
1443
|
-
step: 1
|
|
1444
|
-
});
|
|
1445
|
-
case "float": return /* @__PURE__ */ I(E, {
|
|
1446
|
-
...m,
|
|
1447
|
-
value: n,
|
|
1448
|
-
onChange: r,
|
|
1449
|
-
min: a.min,
|
|
1450
|
-
max: a.max,
|
|
1451
|
-
step: a.step ?? .1
|
|
1452
|
-
});
|
|
1453
|
-
case "slider": return /* @__PURE__ */ I(le, {
|
|
1454
|
-
...m,
|
|
1455
|
-
value: n,
|
|
1456
|
-
onChange: r,
|
|
1457
|
-
min: a.min,
|
|
1458
|
-
max: a.max,
|
|
1459
|
-
step: a.step,
|
|
1460
|
-
multiple: a.multiple
|
|
1461
|
-
});
|
|
1462
|
-
case "checkbox": return /* @__PURE__ */ I(i, {
|
|
1463
|
-
...m,
|
|
1464
|
-
value: n,
|
|
1465
|
-
onChange: r,
|
|
1466
|
-
label: a.label
|
|
1467
|
-
});
|
|
1468
|
-
case "switch": return /* @__PURE__ */ I(ae, {
|
|
1469
|
-
...m,
|
|
1470
|
-
value: n,
|
|
1471
|
-
onChange: r,
|
|
1472
|
-
label: a.label
|
|
1473
|
-
});
|
|
1474
|
-
case "date": return /* @__PURE__ */ I(N, {
|
|
1475
|
-
fallback: /* @__PURE__ */ I(tn, {}),
|
|
1476
|
-
children: /* @__PURE__ */ I(Qt, {
|
|
1477
|
-
...m,
|
|
1478
|
-
mode: "date",
|
|
1479
|
-
value: n,
|
|
1480
|
-
onChange: r,
|
|
1481
|
-
placeholder: a.placeholder
|
|
1482
|
-
})
|
|
1483
|
-
});
|
|
1484
|
-
case "datetime": return /* @__PURE__ */ I(N, {
|
|
1485
|
-
fallback: /* @__PURE__ */ I(tn, {}),
|
|
1486
|
-
children: /* @__PURE__ */ I(Qt, {
|
|
1487
|
-
...m,
|
|
1488
|
-
mode: "datetime",
|
|
1489
|
-
value: n,
|
|
1490
|
-
onChange: r,
|
|
1491
|
-
placeholder: a.placeholder
|
|
1492
|
-
})
|
|
1493
|
-
});
|
|
1494
|
-
case "file": return /* @__PURE__ */ I(pe, {
|
|
1495
|
-
...m,
|
|
1496
|
-
value: n,
|
|
1497
|
-
onChange: r,
|
|
1498
|
-
accept: a.accept,
|
|
1499
|
-
multiple: a.multiple,
|
|
1500
|
-
maxFiles: a.maxFiles,
|
|
1501
|
-
maxSize: a.maxSize
|
|
1502
|
-
});
|
|
1503
|
-
case "entity_picker": return /* @__PURE__ */ I(S, {
|
|
1504
|
-
...m,
|
|
1505
|
-
value: n,
|
|
1506
|
-
onChange: r,
|
|
1507
|
-
options: a.options,
|
|
1508
|
-
autocompleteHref: a.autocompleteHref,
|
|
1509
|
-
autocompleteMinChars: a.autocompleteMinChars,
|
|
1510
|
-
initialOption: a.initialOption,
|
|
1511
|
-
entityAvatarField: a.entityAvatarField,
|
|
1512
|
-
entitySubtitleField: a.entitySubtitleField,
|
|
1513
|
-
placeholder: a.placeholder
|
|
1514
|
-
});
|
|
1515
|
-
case "static": return /* @__PURE__ */ I(C, {
|
|
1516
|
-
id: t,
|
|
1517
|
-
value: n
|
|
1518
|
-
});
|
|
1519
|
-
case "phone": return /* @__PURE__ */ I(N, {
|
|
1520
|
-
fallback: /* @__PURE__ */ I(tn, {}),
|
|
1521
|
-
children: /* @__PURE__ */ I(Zt, {
|
|
1522
|
-
...m,
|
|
1523
|
-
value: n,
|
|
1524
|
-
onChange: r,
|
|
1525
|
-
placeholder: a.placeholder,
|
|
1526
|
-
defaultCountry: a.defaultCountry,
|
|
1527
|
-
fixedCountry: a.fixedCountry
|
|
1528
|
-
})
|
|
1529
|
-
});
|
|
1530
|
-
case "document": return /* @__PURE__ */ I(N, {
|
|
1531
|
-
fallback: /* @__PURE__ */ I(tn, {}),
|
|
1532
|
-
children: /* @__PURE__ */ I($t, {
|
|
1533
|
-
...m,
|
|
1534
|
-
value: n,
|
|
1535
|
-
onChange: r,
|
|
1536
|
-
documentType: a.documentType,
|
|
1537
|
-
documentScope: a.documentScope,
|
|
1538
|
-
documentMasks: a.documentMasks,
|
|
1539
|
-
placeholder: a.placeholder
|
|
1540
|
-
})
|
|
1541
|
-
});
|
|
1542
|
-
case "currency": return /* @__PURE__ */ I(de, {
|
|
1543
|
-
...m,
|
|
1544
|
-
value: n,
|
|
1545
|
-
onChange: r,
|
|
1546
|
-
currency: a.currency,
|
|
1547
|
-
placeholder: a.placeholder,
|
|
1548
|
-
min: a.min,
|
|
1549
|
-
max: a.max
|
|
1550
|
-
});
|
|
1551
|
-
case "color": return /* @__PURE__ */ I(p, {
|
|
1552
|
-
...m,
|
|
1553
|
-
value: n,
|
|
1554
|
-
onChange: r,
|
|
1555
|
-
placeholder: a.placeholder
|
|
1556
|
-
});
|
|
1557
|
-
case "slug": return /* @__PURE__ */ I(te, {
|
|
1558
|
-
...m,
|
|
1559
|
-
value: n,
|
|
1560
|
-
onChange: r,
|
|
1561
|
-
sourceValue: a.sourceField === void 0 ? void 0 : String(u[a.sourceField] ?? ""),
|
|
1562
|
-
prefix: a.prefix,
|
|
1563
|
-
placeholder: a.placeholder
|
|
1564
|
-
});
|
|
1565
|
-
case "tags": return /* @__PURE__ */ I(b, {
|
|
1566
|
-
...m,
|
|
1567
|
-
value: n,
|
|
1568
|
-
onChange: r,
|
|
1569
|
-
placeholder: a.placeholder,
|
|
1570
|
-
maxTags: a.maxTags
|
|
1571
|
-
});
|
|
1572
|
-
case "date_range": return /* @__PURE__ */ I(N, {
|
|
1573
|
-
fallback: /* @__PURE__ */ I(tn, {}),
|
|
1574
|
-
children: /* @__PURE__ */ I(en, {
|
|
1575
|
-
...m,
|
|
1576
|
-
value: n,
|
|
1577
|
-
onChange: r,
|
|
1578
|
-
operator: a.operator
|
|
1579
|
-
})
|
|
1580
|
-
});
|
|
1581
|
-
case "rating": return /* @__PURE__ */ I(T, {
|
|
1582
|
-
...m,
|
|
1583
|
-
value: n,
|
|
1584
|
-
onChange: r,
|
|
1585
|
-
maxRating: a.maxRating
|
|
1586
|
-
});
|
|
1587
|
-
default: return /* @__PURE__ */ L("p", {
|
|
1588
|
-
className: "text-destructive text-xs",
|
|
1589
|
-
children: ["Unknown field component: ", e]
|
|
1590
|
-
});
|
|
1591
|
-
}
|
|
1592
|
-
}
|
|
1593
|
-
//#endregion
|
|
1594
|
-
//#region src/base/blocks/FormPanelBlock.tsx
|
|
1595
|
-
function sn(e, t) {
|
|
1596
|
-
let n = t[e.key];
|
|
1597
|
-
if (n != null) return n;
|
|
1598
|
-
switch (e.component) {
|
|
1599
|
-
case "int":
|
|
1600
|
-
case "float":
|
|
1601
|
-
case "currency":
|
|
1602
|
-
case "slider":
|
|
1603
|
-
case "rating": return null;
|
|
1604
|
-
case "checkbox":
|
|
1605
|
-
case "switch": return !1;
|
|
1606
|
-
case "multiselect":
|
|
1607
|
-
case "tags": return [];
|
|
1608
|
-
default: return "";
|
|
1609
|
-
}
|
|
1610
|
-
}
|
|
1611
|
-
function cn(e, t) {
|
|
1612
|
-
return Object.prototype.hasOwnProperty.call(t, e.key) ? t[e.key] : sn(e, t);
|
|
1613
|
-
}
|
|
1614
|
-
function ln({ nodes: e, values: n, errors: r, onChange: i, sourceValues: a }) {
|
|
1615
|
-
return /* @__PURE__ */ I(we, { children: e.map((e, o) => {
|
|
1616
|
-
switch (e.kind) {
|
|
1617
|
-
case "field": return Kt(e, n) ? /* @__PURE__ */ I(an, {
|
|
1618
|
-
field: e,
|
|
1619
|
-
value: cn(e, n),
|
|
1620
|
-
onChange: (t) => i(e.key, t),
|
|
1621
|
-
error: r[e.key],
|
|
1622
|
-
sourceValues: a
|
|
1623
|
-
}, e.key) : null;
|
|
1624
|
-
case "section": return /* @__PURE__ */ I(re, {
|
|
1625
|
-
id: e.id,
|
|
1626
|
-
title: e.label,
|
|
1627
|
-
defaultCollapsed: e.defaultCollapsed,
|
|
1628
|
-
hasErrors: e.children.some((e) => e.kind === "field" && !!r[e.key]),
|
|
1629
|
-
errorCount: e.children.filter((e) => e.kind === "field" && !!r[e.key]).length,
|
|
1630
|
-
children: /* @__PURE__ */ I(ln, {
|
|
1631
|
-
nodes: e.children,
|
|
1632
|
-
values: n,
|
|
1633
|
-
errors: r,
|
|
1634
|
-
onChange: i,
|
|
1635
|
-
sourceValues: a
|
|
1636
|
-
})
|
|
1637
|
-
}, e.id);
|
|
1638
|
-
case "group": return /* @__PURE__ */ I("div", {
|
|
1639
|
-
className: ge("grid gap-6", e.columns === 2 ? "md:grid-cols-2" : "grid-cols-1"),
|
|
1640
|
-
children: /* @__PURE__ */ I(ln, {
|
|
1641
|
-
nodes: e.children,
|
|
1642
|
-
values: n,
|
|
1643
|
-
errors: r,
|
|
1644
|
-
onChange: i,
|
|
1645
|
-
sourceValues: a
|
|
1646
|
-
})
|
|
1647
|
-
}, e.id);
|
|
1648
|
-
case "header": return /* @__PURE__ */ L("div", {
|
|
1649
|
-
className: "space-y-2",
|
|
1650
|
-
children: [/* @__PURE__ */ I(t, {}), /* @__PURE__ */ I("h4", {
|
|
1651
|
-
className: "text-foreground text-base font-semibold",
|
|
1652
|
-
children: e.label
|
|
1653
|
-
})]
|
|
1654
|
-
}, `header-${o}`);
|
|
1655
|
-
default: return null;
|
|
1656
|
-
}
|
|
1657
|
-
}) });
|
|
1658
|
-
}
|
|
1659
|
-
function un({ block: t }) {
|
|
1660
|
-
let { t: n } = he(), { data: r } = t, i = F(() => Gt(r.schema), [r.schema]), a = F(() => new Set(i.map((e) => e.key)), [i]), o = (r.meta.validation ?? "both") !== "server", l = F(() => Object.fromEntries(i.map((e) => [e.key, sn(e, r.values)])), [i, r.values]), u = xe(o ? Xt(r.schema, l, n) : null), d = Ft({
|
|
1661
|
-
defaultValues: l,
|
|
1662
|
-
mode: "onTouched",
|
|
1663
|
-
resolver: F(() => {
|
|
1664
|
-
if (o) return async (e, t, n) => u.current ? Wt(u.current)(e, t, n) : {
|
|
1665
|
-
values: e,
|
|
1666
|
-
errors: {}
|
|
1667
|
-
};
|
|
1668
|
-
}, [o])
|
|
1669
|
-
}), f = Ue({ control: d.control }) ?? l, p = i.map((e) => `${Kt(e, f) ? "1" : "0"}${Jt(e, f) ? "1" : "0"}`).join("");
|
|
1670
|
-
ye(() => {
|
|
1671
|
-
o && (u.current = Xt(r.schema, f, n));
|
|
1672
|
-
}, [
|
|
1673
|
-
o,
|
|
1674
|
-
r.schema,
|
|
1675
|
-
n,
|
|
1676
|
-
p
|
|
1677
|
-
]);
|
|
1678
|
-
let [m, y] = Se(!1), [b, S] = Se(null), [C, ee] = Se({}), T = JSON.stringify(r.values), E = xe(!0);
|
|
1679
|
-
ye(() => {
|
|
1680
|
-
if (E.current) {
|
|
1681
|
-
E.current = !1;
|
|
1682
|
-
return;
|
|
1683
|
-
}
|
|
1684
|
-
d.reset(l);
|
|
1685
|
-
for (let [e, t] of Object.entries(r.errors)) a.has(e) && d.setError(e, {
|
|
1686
|
-
type: "server",
|
|
1687
|
-
message: j(t, n)
|
|
1688
|
-
});
|
|
1689
|
-
}, [T]), ye(() => {
|
|
1690
|
-
if (Object.keys(r.errors).length > 0) for (let [e, t] of Object.entries(r.errors)) a.has(e) && d.setError(e, {
|
|
1691
|
-
type: "server",
|
|
1692
|
-
message: j(t, n)
|
|
1693
|
-
});
|
|
1694
|
-
}, [JSON.stringify(r.errors)]);
|
|
1695
|
-
let { isDirty: D, isSubmitting: O } = d.formState;
|
|
1696
|
-
ye(() => {
|
|
1697
|
-
if (!D) return;
|
|
1698
|
-
let e = (e) => {
|
|
1699
|
-
e.preventDefault();
|
|
1700
|
-
};
|
|
1701
|
-
return window.addEventListener("beforeunload", e), () => window.removeEventListener("beforeunload", e);
|
|
1702
|
-
}, [D]);
|
|
1703
|
-
let k = ve((e, t) => {
|
|
1704
|
-
d.setValue(e, t, {
|
|
1705
|
-
shouldDirty: !0,
|
|
1706
|
-
shouldValidate: d.formState.isSubmitted
|
|
1707
|
-
}), d.clearErrors(e);
|
|
1708
|
-
}, [d]), A = ve((e) => {
|
|
1709
|
-
ee({});
|
|
1710
|
-
let t = i.filter((t) => Kt(t, e)), o = Object.fromEntries(t.map((t) => [t.key, e[t.key]])), s = Object.values(o).some((e) => e instanceof File || Array.isArray(e) && e.some((e) => e instanceof File));
|
|
1711
|
-
Ce[r.method === "put" ? "put" : r.method === "patch" ? "patch" : "post"](r.action, o, {
|
|
1712
|
-
forceFormData: s,
|
|
1713
|
-
onProgress: (e) => {
|
|
1714
|
-
e && typeof e.percentage == "number" && S(Math.round(e.percentage));
|
|
1715
|
-
},
|
|
1716
|
-
onError: (e) => {
|
|
1717
|
-
let t = {};
|
|
1718
|
-
for (let [r, i] of Object.entries(e)) a.has(r) ? d.setError(r, {
|
|
1719
|
-
type: "server",
|
|
1720
|
-
message: j(i, n)
|
|
1721
|
-
}) : t[r] = i;
|
|
1722
|
-
Object.keys(t).length > 0 && ee((e) => ({
|
|
1723
|
-
...e,
|
|
1724
|
-
...t
|
|
1725
|
-
}));
|
|
1726
|
-
},
|
|
1727
|
-
onFinish: () => S(null)
|
|
1728
|
-
});
|
|
1729
|
-
}, [
|
|
1730
|
-
i,
|
|
1731
|
-
r,
|
|
1732
|
-
d,
|
|
1733
|
-
n,
|
|
1734
|
-
a
|
|
1735
|
-
]), te = ve(() => {
|
|
1736
|
-
D ? y(!0) : r.meta.cancelHref ? Ce.visit(r.meta.cancelHref) : window.history.back();
|
|
1737
|
-
}, [D, r.meta.cancelHref]), ne = F(() => {
|
|
1738
|
-
let e = {};
|
|
1739
|
-
for (let [t, n] of Object.entries(d.formState.errors)) n?.message && (e[t] = n.message);
|
|
1740
|
-
return e;
|
|
1741
|
-
}, [d.formState.errors]), re = F(() => {
|
|
1742
|
-
let e = /* @__PURE__ */ new Map(), t = (t) => {
|
|
1743
|
-
for (let [r, i] of Object.entries(t)) {
|
|
1744
|
-
if (a.has(r)) continue;
|
|
1745
|
-
let t = j(i, n);
|
|
1746
|
-
t && e.set(r, t);
|
|
1747
|
-
}
|
|
1748
|
-
};
|
|
1749
|
-
return t(r.errors), t(C), Array.from(e, ([e, t]) => ({
|
|
1750
|
-
key: e,
|
|
1751
|
-
message: t
|
|
1752
|
-
}));
|
|
1753
|
-
}, [
|
|
1754
|
-
r.errors,
|
|
1755
|
-
C,
|
|
1756
|
-
a,
|
|
1757
|
-
n
|
|
1758
|
-
]);
|
|
1759
|
-
return i.filter((e) => Kt(e, f)).length === 0 && r.schema.length === 0 ? /* @__PURE__ */ I(g, {
|
|
1760
|
-
variant: "inline",
|
|
1761
|
-
title: n("middag.ui.form.no_fields")
|
|
1762
|
-
}) : /* @__PURE__ */ L(we, { children: [/* @__PURE__ */ L("form", {
|
|
1763
|
-
onSubmit: d.handleSubmit(A),
|
|
1764
|
-
className: "mx-auto max-w-[720px] space-y-6",
|
|
1765
|
-
noValidate: !0,
|
|
1766
|
-
role: "form",
|
|
1767
|
-
"aria-label": h(t.title, n) || n("middag.ui.form.default_title"),
|
|
1768
|
-
children: [
|
|
1769
|
-
re.length > 0 && /* @__PURE__ */ L(c, {
|
|
1770
|
-
variant: "destructive",
|
|
1771
|
-
children: [/* @__PURE__ */ I(_, { children: n("middag.ui.form.errors_title") }), /* @__PURE__ */ I(s, { children: /* @__PURE__ */ I("ul", {
|
|
1772
|
-
className: "list-disc ps-4",
|
|
1773
|
-
children: re.map((e) => /* @__PURE__ */ I("li", { children: e.message }, e.key))
|
|
1774
|
-
}) })]
|
|
1775
|
-
}),
|
|
1776
|
-
/* @__PURE__ */ I(ln, {
|
|
1777
|
-
nodes: r.schema,
|
|
1778
|
-
values: f,
|
|
1779
|
-
errors: ne,
|
|
1780
|
-
onChange: k,
|
|
1781
|
-
sourceValues: f
|
|
1782
|
-
}),
|
|
1783
|
-
/* @__PURE__ */ L("div", {
|
|
1784
|
-
className: "flex gap-3 pt-4",
|
|
1785
|
-
children: [/* @__PURE__ */ I(me, {
|
|
1786
|
-
type: "submit",
|
|
1787
|
-
disabled: O,
|
|
1788
|
-
"aria-disabled": O,
|
|
1789
|
-
"aria-busy": O,
|
|
1790
|
-
children: O ? b === null ? n("middag.ui.form.saving") : `${n("middag.ui.form.saving")} ${b}%` : r.meta.submitLabel ?? n("middag.ui.form.save")
|
|
1791
|
-
}), /* @__PURE__ */ I(me, {
|
|
1792
|
-
type: "button",
|
|
1793
|
-
variant: "outline",
|
|
1794
|
-
onClick: te,
|
|
1795
|
-
children: r.meta.cancelLabel ?? n("middag.ui.cancel")
|
|
1796
|
-
})]
|
|
1797
|
-
})
|
|
1798
|
-
]
|
|
1799
|
-
}), /* @__PURE__ */ I(v, {
|
|
1800
|
-
open: m,
|
|
1801
|
-
onOpenChange: y,
|
|
1802
|
-
children: /* @__PURE__ */ L(e, { children: [/* @__PURE__ */ L(ie, { children: [/* @__PURE__ */ I(x, { children: n("middag.ui.form.dirty_title") }), /* @__PURE__ */ I(w, { children: n("middag.ui.form.dirty_message") })] }), /* @__PURE__ */ L(ce, { children: [/* @__PURE__ */ I(me, {
|
|
1803
|
-
variant: "outline",
|
|
1804
|
-
onClick: () => y(!1),
|
|
1805
|
-
children: n("middag.ui.cancel")
|
|
1806
|
-
}), /* @__PURE__ */ I(me, {
|
|
1807
|
-
variant: "destructive",
|
|
1808
|
-
onClick: () => {
|
|
1809
|
-
y(!1), r.meta.cancelHref ? Ce.visit(r.meta.cancelHref) : window.history.back();
|
|
1810
|
-
},
|
|
1811
|
-
children: n("middag.ui.form.dirty_leave")
|
|
1812
|
-
})] })] })
|
|
1813
|
-
})] });
|
|
1814
|
-
}
|
|
1815
|
-
//#endregion
|
|
1816
|
-
export { un as FormPanelBlock };
|