@ram_28/kf-ai-sdk 1.0.12 → 1.0.13
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/auth.cjs +1 -1
- package/dist/auth.mjs +15 -15
- package/dist/form.cjs +1 -1
- package/dist/form.mjs +1745 -736
- package/dist/kanban.cjs +2 -2
- package/dist/kanban.mjs +835 -469
- package/dist/table.cjs +1 -1
- package/dist/table.mjs +1 -1
- package/dist/useQuery-BScHEo7x.cjs +1 -0
- package/dist/useQuery-KpZFg80c.js +748 -0
- package/package.json +1 -1
package/dist/form.mjs
CHANGED
|
@@ -1,16 +1,1025 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { useState as
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
var Bt = Object.defineProperty;
|
|
2
|
+
var Pt = (e, t, r) => t in e ? Bt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
+
var we = (e, t, r) => Pt(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import X, { useState as ye, useRef as qe, useEffect as $e, useMemo as Ne, useCallback as te } from "react";
|
|
5
|
+
import { u as ct } from "./useQuery-KpZFg80c.js";
|
|
6
|
+
import { a as pe } from "./client-CfvLiGfP.js";
|
|
7
|
+
import { g as qt } from "./metadata-DBcoDth-.js";
|
|
8
|
+
var Le = (e) => e.type === "checkbox", ge = (e) => e instanceof Date, G = (e) => e == null;
|
|
9
|
+
const St = (e) => typeof e == "object";
|
|
10
|
+
var I = (e) => !G(e) && !Array.isArray(e) && St(e) && !ge(e), $t = (e) => I(e) && e.target ? Le(e.target) ? e.target.checked : e.target.value : e, jt = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e, Wt = (e, t) => e.has(jt(t)), Ht = (e) => {
|
|
11
|
+
const t = e.constructor && e.constructor.prototype;
|
|
12
|
+
return I(t) && t.hasOwnProperty("isPrototypeOf");
|
|
13
|
+
}, rt = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
|
|
14
|
+
function k(e) {
|
|
15
|
+
if (e instanceof Date)
|
|
16
|
+
return new Date(e);
|
|
17
|
+
const t = typeof FileList < "u" && e instanceof FileList;
|
|
18
|
+
if (rt && (e instanceof Blob || t))
|
|
19
|
+
return e;
|
|
20
|
+
const r = Array.isArray(e);
|
|
21
|
+
if (!r && !(I(e) && Ht(e)))
|
|
22
|
+
return e;
|
|
23
|
+
const s = r ? [] : Object.create(Object.getPrototypeOf(e));
|
|
24
|
+
for (const i in e)
|
|
25
|
+
Object.prototype.hasOwnProperty.call(e, i) && (s[i] = k(e[i]));
|
|
26
|
+
return s;
|
|
27
|
+
}
|
|
28
|
+
var He = (e) => /^\w*$/.test(e), C = (e) => e === void 0, st = (e) => Array.isArray(e) ? e.filter(Boolean) : [], it = (e) => st(e.replace(/["|']|\]/g, "").split(/\.|\[/)), g = (e, t, r) => {
|
|
29
|
+
if (!t || !I(e))
|
|
30
|
+
return r;
|
|
31
|
+
const s = (He(t) ? [t] : it(t)).reduce((i, n) => G(i) ? i : i[n], e);
|
|
32
|
+
return C(s) || s === e ? C(e[t]) ? r : e[t] : s;
|
|
33
|
+
}, ie = (e) => typeof e == "boolean", re = (e) => typeof e == "function", R = (e, t, r) => {
|
|
34
|
+
let s = -1;
|
|
35
|
+
const i = He(t) ? [t] : it(t), n = i.length, l = n - 1;
|
|
36
|
+
for (; ++s < n; ) {
|
|
37
|
+
const d = i[s];
|
|
38
|
+
let w = r;
|
|
39
|
+
if (s !== l) {
|
|
40
|
+
const p = e[d];
|
|
41
|
+
w = I(p) || Array.isArray(p) ? p : isNaN(+i[s + 1]) ? {} : [];
|
|
42
|
+
}
|
|
43
|
+
if (d === "__proto__" || d === "constructor" || d === "prototype")
|
|
44
|
+
return;
|
|
45
|
+
e[d] = w, e = e[d];
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const dt = {
|
|
49
|
+
BLUR: "blur",
|
|
50
|
+
FOCUS_OUT: "focusout"
|
|
51
|
+
}, se = {
|
|
52
|
+
onBlur: "onBlur",
|
|
53
|
+
onChange: "onChange",
|
|
54
|
+
onSubmit: "onSubmit",
|
|
55
|
+
onTouched: "onTouched",
|
|
56
|
+
all: "all"
|
|
57
|
+
}, ue = {
|
|
58
|
+
max: "max",
|
|
59
|
+
min: "min",
|
|
60
|
+
maxLength: "maxLength",
|
|
61
|
+
minLength: "minLength",
|
|
62
|
+
pattern: "pattern",
|
|
63
|
+
required: "required",
|
|
64
|
+
validate: "validate"
|
|
65
|
+
}, Yt = X.createContext(null);
|
|
66
|
+
Yt.displayName = "HookFormContext";
|
|
67
|
+
var Kt = (e, t, r, s = !0) => {
|
|
68
|
+
const i = {
|
|
69
|
+
defaultValues: t._defaultValues
|
|
70
|
+
};
|
|
71
|
+
for (const n in e)
|
|
72
|
+
Object.defineProperty(i, n, {
|
|
73
|
+
get: () => {
|
|
74
|
+
const l = n;
|
|
75
|
+
return t._proxyFormState[l] !== se.all && (t._proxyFormState[l] = !s || se.all), e[l];
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
return i;
|
|
79
|
+
};
|
|
80
|
+
const zt = typeof window < "u" ? X.useLayoutEffect : X.useEffect;
|
|
81
|
+
var Q = (e) => typeof e == "string", Jt = (e, t, r, s, i) => Q(e) ? (s && t.watch.add(e), g(r, e, i)) : Array.isArray(e) ? e.map((n) => (s && t.watch.add(n), g(r, n))) : (s && (t.watchAll = !0), r), et = (e) => G(e) || !St(e);
|
|
82
|
+
function de(e, t, r = /* @__PURE__ */ new WeakSet()) {
|
|
83
|
+
if (et(e) || et(t))
|
|
84
|
+
return Object.is(e, t);
|
|
85
|
+
if (ge(e) && ge(t))
|
|
86
|
+
return Object.is(e.getTime(), t.getTime());
|
|
87
|
+
const s = Object.keys(e), i = Object.keys(t);
|
|
88
|
+
if (s.length !== i.length)
|
|
89
|
+
return !1;
|
|
90
|
+
if (r.has(e) || r.has(t))
|
|
91
|
+
return !0;
|
|
92
|
+
r.add(e), r.add(t);
|
|
93
|
+
for (const n of s) {
|
|
94
|
+
const l = e[n];
|
|
95
|
+
if (!i.includes(n))
|
|
96
|
+
return !1;
|
|
97
|
+
if (n !== "ref") {
|
|
98
|
+
const d = t[n];
|
|
99
|
+
if (ge(l) && ge(d) || I(l) && I(d) || Array.isArray(l) && Array.isArray(d) ? !de(l, d, r) : !Object.is(l, d))
|
|
100
|
+
return !1;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return !0;
|
|
104
|
+
}
|
|
105
|
+
var Gt = (e, t, r, s, i) => t ? {
|
|
106
|
+
...r[e],
|
|
107
|
+
types: {
|
|
108
|
+
...r[e] && r[e].types ? r[e].types : {},
|
|
109
|
+
[s]: i || !0
|
|
110
|
+
}
|
|
111
|
+
} : {}, Ce = (e) => Array.isArray(e) ? e : [e], ft = () => {
|
|
112
|
+
let e = [];
|
|
11
113
|
return {
|
|
12
|
-
|
|
13
|
-
|
|
114
|
+
get observers() {
|
|
115
|
+
return e;
|
|
116
|
+
},
|
|
117
|
+
next: (i) => {
|
|
118
|
+
for (const n of e)
|
|
119
|
+
n.next && n.next(i);
|
|
120
|
+
},
|
|
121
|
+
subscribe: (i) => (e.push(i), {
|
|
122
|
+
unsubscribe: () => {
|
|
123
|
+
e = e.filter((n) => n !== i);
|
|
124
|
+
}
|
|
125
|
+
}),
|
|
126
|
+
unsubscribe: () => {
|
|
127
|
+
e = [];
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
};
|
|
131
|
+
function Rt(e, t) {
|
|
132
|
+
const r = {};
|
|
133
|
+
for (const s in e)
|
|
134
|
+
if (e.hasOwnProperty(s)) {
|
|
135
|
+
const i = e[s], n = t[s];
|
|
136
|
+
if (i && I(i) && n) {
|
|
137
|
+
const l = Rt(i, n);
|
|
138
|
+
I(l) && (r[s] = l);
|
|
139
|
+
} else e[s] && (r[s] = n);
|
|
140
|
+
}
|
|
141
|
+
return r;
|
|
142
|
+
}
|
|
143
|
+
var Y = (e) => I(e) && !Object.keys(e).length, at = (e) => e.type === "file", je = (e) => {
|
|
144
|
+
if (!rt)
|
|
145
|
+
return !1;
|
|
146
|
+
const t = e ? e.ownerDocument : 0;
|
|
147
|
+
return e instanceof (t && t.defaultView ? t.defaultView.HTMLElement : HTMLElement);
|
|
148
|
+
}, Nt = (e) => e.type === "select-multiple", nt = (e) => e.type === "radio", Xt = (e) => nt(e) || Le(e), Qe = (e) => je(e) && e.isConnected;
|
|
149
|
+
function Qt(e, t) {
|
|
150
|
+
const r = t.slice(0, -1).length;
|
|
151
|
+
let s = 0;
|
|
152
|
+
for (; s < r; )
|
|
153
|
+
e = C(e) ? s++ : e[t[s++]];
|
|
154
|
+
return e;
|
|
155
|
+
}
|
|
156
|
+
function Zt(e) {
|
|
157
|
+
for (const t in e)
|
|
158
|
+
if (e.hasOwnProperty(t) && !C(e[t]))
|
|
159
|
+
return !1;
|
|
160
|
+
return !0;
|
|
161
|
+
}
|
|
162
|
+
function M(e, t) {
|
|
163
|
+
const r = Array.isArray(t) ? t : He(t) ? [t] : it(t), s = r.length === 1 ? e : Qt(e, r), i = r.length - 1, n = r[i];
|
|
164
|
+
return s && delete s[n], i !== 0 && (I(s) && Y(s) || Array.isArray(s) && Zt(s)) && M(e, r.slice(0, -1)), e;
|
|
165
|
+
}
|
|
166
|
+
var er = (e) => {
|
|
167
|
+
for (const t in e)
|
|
168
|
+
if (re(e[t]))
|
|
169
|
+
return !0;
|
|
170
|
+
return !1;
|
|
171
|
+
};
|
|
172
|
+
function Ot(e) {
|
|
173
|
+
return Array.isArray(e) || I(e) && !er(e);
|
|
174
|
+
}
|
|
175
|
+
function tt(e, t = {}) {
|
|
176
|
+
for (const r in e) {
|
|
177
|
+
const s = e[r];
|
|
178
|
+
Ot(s) ? (t[r] = Array.isArray(s) ? [] : {}, tt(s, t[r])) : C(s) || (t[r] = !0);
|
|
179
|
+
}
|
|
180
|
+
return t;
|
|
181
|
+
}
|
|
182
|
+
function Fe(e, t, r) {
|
|
183
|
+
r || (r = tt(t));
|
|
184
|
+
for (const s in e) {
|
|
185
|
+
const i = e[s];
|
|
186
|
+
if (Ot(i))
|
|
187
|
+
C(t) || et(r[s]) ? r[s] = tt(i, Array.isArray(i) ? [] : {}) : Fe(i, G(t) ? {} : t[s], r[s]);
|
|
188
|
+
else {
|
|
189
|
+
const n = t[s];
|
|
190
|
+
r[s] = !de(i, n);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return r;
|
|
194
|
+
}
|
|
195
|
+
const ht = {
|
|
196
|
+
value: !1,
|
|
197
|
+
isValid: !1
|
|
198
|
+
}, mt = { value: !0, isValid: !0 };
|
|
199
|
+
var Ct = (e) => {
|
|
200
|
+
if (Array.isArray(e)) {
|
|
201
|
+
if (e.length > 1) {
|
|
202
|
+
const t = e.filter((r) => r && r.checked && !r.disabled).map((r) => r.value);
|
|
203
|
+
return { value: t, isValid: !!t.length };
|
|
204
|
+
}
|
|
205
|
+
return e[0].checked && !e[0].disabled ? (
|
|
206
|
+
// @ts-expect-error expected to work in the browser
|
|
207
|
+
e[0].attributes && !C(e[0].attributes.value) ? C(e[0].value) || e[0].value === "" ? mt : { value: e[0].value, isValid: !0 } : mt
|
|
208
|
+
) : ht;
|
|
209
|
+
}
|
|
210
|
+
return ht;
|
|
211
|
+
}, Tt = (e, { valueAsNumber: t, valueAsDate: r, setValueAs: s }) => C(e) ? e : t ? e === "" ? NaN : e && +e : r && Q(e) ? new Date(e) : s ? s(e) : e;
|
|
212
|
+
const yt = {
|
|
213
|
+
isValid: !1,
|
|
214
|
+
value: null
|
|
215
|
+
};
|
|
216
|
+
var Lt = (e) => Array.isArray(e) ? e.reduce((t, r) => r && r.checked && !r.disabled ? {
|
|
217
|
+
isValid: !0,
|
|
218
|
+
value: r.value
|
|
219
|
+
} : t, yt) : yt;
|
|
220
|
+
function gt(e) {
|
|
221
|
+
const t = e.ref;
|
|
222
|
+
return at(t) ? t.files : nt(t) ? Lt(e.refs).value : Nt(t) ? [...t.selectedOptions].map(({ value: r }) => r) : Le(t) ? Ct(e.refs).value : Tt(C(t.value) ? e.ref.value : t.value, e);
|
|
223
|
+
}
|
|
224
|
+
var tr = (e, t, r, s) => {
|
|
225
|
+
const i = {};
|
|
226
|
+
for (const n of e) {
|
|
227
|
+
const l = g(t, n);
|
|
228
|
+
l && R(i, n, l._f);
|
|
229
|
+
}
|
|
230
|
+
return {
|
|
231
|
+
criteriaMode: r,
|
|
232
|
+
names: [...e],
|
|
233
|
+
fields: i,
|
|
234
|
+
shouldUseNativeValidation: s
|
|
235
|
+
};
|
|
236
|
+
}, We = (e) => e instanceof RegExp, Oe = (e) => C(e) ? e : We(e) ? e.source : I(e) ? We(e.value) ? e.value.source : e.value : e, pt = (e) => ({
|
|
237
|
+
isOnSubmit: !e || e === se.onSubmit,
|
|
238
|
+
isOnBlur: e === se.onBlur,
|
|
239
|
+
isOnChange: e === se.onChange,
|
|
240
|
+
isOnAll: e === se.all,
|
|
241
|
+
isOnTouch: e === se.onTouched
|
|
242
|
+
});
|
|
243
|
+
const bt = "AsyncFunction";
|
|
244
|
+
var rr = (e) => !!e && !!e.validate && !!(re(e.validate) && e.validate.constructor.name === bt || I(e.validate) && Object.values(e.validate).find((t) => t.constructor.name === bt)), sr = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate), wt = (e, t, r) => !r && (t.watchAll || t.watch.has(e) || [...t.watch].some((s) => e.startsWith(s) && /^\.\w+/.test(e.slice(s.length))));
|
|
245
|
+
const Te = (e, t, r, s) => {
|
|
246
|
+
for (const i of r || Object.keys(e)) {
|
|
247
|
+
const n = g(e, i);
|
|
248
|
+
if (n) {
|
|
249
|
+
const { _f: l, ...d } = n;
|
|
250
|
+
if (l) {
|
|
251
|
+
if (l.refs && l.refs[0] && t(l.refs[0], i) && !s)
|
|
252
|
+
return !0;
|
|
253
|
+
if (l.ref && t(l.ref, l.name) && !s)
|
|
254
|
+
return !0;
|
|
255
|
+
if (Te(d, t))
|
|
256
|
+
break;
|
|
257
|
+
} else if (I(d) && Te(d, t))
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
function vt(e, t, r) {
|
|
263
|
+
const s = g(e, r);
|
|
264
|
+
if (s || He(r))
|
|
265
|
+
return {
|
|
266
|
+
error: s,
|
|
267
|
+
name: r
|
|
268
|
+
};
|
|
269
|
+
const i = r.split(".");
|
|
270
|
+
for (; i.length; ) {
|
|
271
|
+
const n = i.join("."), l = g(t, n), d = g(e, n);
|
|
272
|
+
if (l && !Array.isArray(l) && r !== n)
|
|
273
|
+
return { name: r };
|
|
274
|
+
if (d && d.type)
|
|
275
|
+
return {
|
|
276
|
+
name: n,
|
|
277
|
+
error: d
|
|
278
|
+
};
|
|
279
|
+
if (d && d.root && d.root.type)
|
|
280
|
+
return {
|
|
281
|
+
name: `${n}.root`,
|
|
282
|
+
error: d.root
|
|
283
|
+
};
|
|
284
|
+
i.pop();
|
|
285
|
+
}
|
|
286
|
+
return {
|
|
287
|
+
name: r
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
var ir = (e, t, r, s) => {
|
|
291
|
+
r(e);
|
|
292
|
+
const { name: i, ...n } = e;
|
|
293
|
+
return Y(n) || Object.keys(n).length >= Object.keys(t).length || Object.keys(n).find((l) => t[l] === (!s || se.all));
|
|
294
|
+
}, ar = (e, t, r) => !e || !t || e === t || Ce(e).some((s) => s && (r ? s === t : s.startsWith(t) || t.startsWith(s))), nr = (e, t, r, s, i) => i.isOnAll ? !1 : !r && i.isOnTouch ? !(t || e) : (r ? s.isOnBlur : i.isOnBlur) ? !e : (r ? s.isOnChange : i.isOnChange) ? e : !0, ur = (e, t) => !st(g(e, t)).length && M(e, t), or = (e, t, r) => {
|
|
295
|
+
const s = Ce(g(e, r));
|
|
296
|
+
return R(s, "root", t[r]), R(e, r, s), e;
|
|
297
|
+
};
|
|
298
|
+
function Ft(e, t, r = "validate") {
|
|
299
|
+
if (Q(e) || Array.isArray(e) && e.every(Q) || ie(e) && !e)
|
|
300
|
+
return {
|
|
301
|
+
type: r,
|
|
302
|
+
message: Q(e) ? e : "",
|
|
303
|
+
ref: t
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
var ve = (e) => I(e) && !We(e) ? e : {
|
|
307
|
+
value: e,
|
|
308
|
+
message: ""
|
|
309
|
+
}, Vt = async (e, t, r, s, i, n) => {
|
|
310
|
+
const { ref: l, refs: d, required: w, maxLength: p, minLength: N, min: D, max: v, pattern: m, validate: K, name: O, valueAsNumber: Z, mount: H } = e._f, x = g(r, O);
|
|
311
|
+
if (!H || t.has(O))
|
|
312
|
+
return {};
|
|
313
|
+
const ee = d ? d[0] : l, L = (V) => {
|
|
314
|
+
i && ee.reportValidity && (ee.setCustomValidity(ie(V) ? "" : V || ""), ee.reportValidity());
|
|
315
|
+
}, T = {}, oe = nt(l), he = Le(l), ae = oe || he, ne = (Z || at(l)) && C(l.value) && C(x) || je(l) && l.value === "" || x === "" || Array.isArray(x) && !x.length, B = Gt.bind(null, O, s, T), le = (V, E, S, U = ue.maxLength, $ = ue.minLength) => {
|
|
316
|
+
const j = V ? E : S;
|
|
317
|
+
T[O] = {
|
|
318
|
+
type: V ? U : $,
|
|
319
|
+
message: j,
|
|
320
|
+
ref: l,
|
|
321
|
+
...B(V ? U : $, j)
|
|
322
|
+
};
|
|
323
|
+
};
|
|
324
|
+
if (n ? !Array.isArray(x) || !x.length : w && (!ae && (ne || G(x)) || ie(x) && !x || he && !Ct(d).isValid || oe && !Lt(d).isValid)) {
|
|
325
|
+
const { value: V, message: E } = Q(w) ? { value: !!w, message: w } : ve(w);
|
|
326
|
+
if (V && (T[O] = {
|
|
327
|
+
type: ue.required,
|
|
328
|
+
message: E,
|
|
329
|
+
ref: ee,
|
|
330
|
+
...B(ue.required, E)
|
|
331
|
+
}, !s))
|
|
332
|
+
return L(E), T;
|
|
333
|
+
}
|
|
334
|
+
if (!ne && (!G(D) || !G(v))) {
|
|
335
|
+
let V, E;
|
|
336
|
+
const S = ve(v), U = ve(D);
|
|
337
|
+
if (!G(x) && !isNaN(x)) {
|
|
338
|
+
const $ = l.valueAsNumber || x && +x;
|
|
339
|
+
G(S.value) || (V = $ > S.value), G(U.value) || (E = $ < U.value);
|
|
340
|
+
} else {
|
|
341
|
+
const $ = l.valueAsDate || new Date(x), j = (me) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + me), z = l.type == "time", ce = l.type == "week";
|
|
342
|
+
Q(S.value) && x && (V = z ? j(x) > j(S.value) : ce ? x > S.value : $ > new Date(S.value)), Q(U.value) && x && (E = z ? j(x) < j(U.value) : ce ? x < U.value : $ < new Date(U.value));
|
|
343
|
+
}
|
|
344
|
+
if ((V || E) && (le(!!V, S.message, U.message, ue.max, ue.min), !s))
|
|
345
|
+
return L(T[O].message), T;
|
|
346
|
+
}
|
|
347
|
+
if ((p || N) && !ne && (Q(x) || n && Array.isArray(x))) {
|
|
348
|
+
const V = ve(p), E = ve(N), S = !G(V.value) && x.length > +V.value, U = !G(E.value) && x.length < +E.value;
|
|
349
|
+
if ((S || U) && (le(S, V.message, E.message), !s))
|
|
350
|
+
return L(T[O].message), T;
|
|
351
|
+
}
|
|
352
|
+
if (m && !ne && Q(x)) {
|
|
353
|
+
const { value: V, message: E } = ve(m);
|
|
354
|
+
if (We(V) && !x.match(V) && (T[O] = {
|
|
355
|
+
type: ue.pattern,
|
|
356
|
+
message: E,
|
|
357
|
+
ref: l,
|
|
358
|
+
...B(ue.pattern, E)
|
|
359
|
+
}, !s))
|
|
360
|
+
return L(E), T;
|
|
361
|
+
}
|
|
362
|
+
if (K) {
|
|
363
|
+
if (re(K)) {
|
|
364
|
+
const V = await K(x, r), E = Ft(V, ee);
|
|
365
|
+
if (E && (T[O] = {
|
|
366
|
+
...E,
|
|
367
|
+
...B(ue.validate, E.message)
|
|
368
|
+
}, !s))
|
|
369
|
+
return L(E.message), T;
|
|
370
|
+
} else if (I(K)) {
|
|
371
|
+
let V = {};
|
|
372
|
+
for (const E in K) {
|
|
373
|
+
if (!Y(V) && !s)
|
|
374
|
+
break;
|
|
375
|
+
const S = Ft(await K[E](x, r), ee, E);
|
|
376
|
+
S && (V = {
|
|
377
|
+
...S,
|
|
378
|
+
...B(E, S.message)
|
|
379
|
+
}, L(S.message), s && (T[O] = V));
|
|
380
|
+
}
|
|
381
|
+
if (!Y(V) && (T[O] = {
|
|
382
|
+
ref: ee,
|
|
383
|
+
...V
|
|
384
|
+
}, !s))
|
|
385
|
+
return T;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
return L(!0), T;
|
|
389
|
+
};
|
|
390
|
+
const lr = {
|
|
391
|
+
mode: se.onSubmit,
|
|
392
|
+
reValidateMode: se.onChange,
|
|
393
|
+
shouldFocusError: !0
|
|
394
|
+
};
|
|
395
|
+
function cr(e = {}) {
|
|
396
|
+
let t = {
|
|
397
|
+
...lr,
|
|
398
|
+
...e
|
|
399
|
+
}, r = {
|
|
400
|
+
submitCount: 0,
|
|
401
|
+
isDirty: !1,
|
|
402
|
+
isReady: !1,
|
|
403
|
+
isLoading: re(t.defaultValues),
|
|
404
|
+
isValidating: !1,
|
|
405
|
+
isSubmitted: !1,
|
|
406
|
+
isSubmitting: !1,
|
|
407
|
+
isSubmitSuccessful: !1,
|
|
408
|
+
isValid: !1,
|
|
409
|
+
touchedFields: {},
|
|
410
|
+
dirtyFields: {},
|
|
411
|
+
validatingFields: {},
|
|
412
|
+
errors: t.errors || {},
|
|
413
|
+
disabled: t.disabled || !1
|
|
414
|
+
}, s = {}, i = I(t.defaultValues) || I(t.values) ? k(t.defaultValues || t.values) || {} : {}, n = t.shouldUnregister ? {} : k(i), l = {
|
|
415
|
+
action: !1,
|
|
416
|
+
mount: !1,
|
|
417
|
+
watch: !1,
|
|
418
|
+
keepIsValid: !1
|
|
419
|
+
}, d = {
|
|
420
|
+
mount: /* @__PURE__ */ new Set(),
|
|
421
|
+
disabled: /* @__PURE__ */ new Set(),
|
|
422
|
+
unMount: /* @__PURE__ */ new Set(),
|
|
423
|
+
array: /* @__PURE__ */ new Set(),
|
|
424
|
+
watch: /* @__PURE__ */ new Set()
|
|
425
|
+
}, w, p = 0;
|
|
426
|
+
const N = {
|
|
427
|
+
isDirty: !1,
|
|
428
|
+
dirtyFields: !1,
|
|
429
|
+
validatingFields: !1,
|
|
430
|
+
touchedFields: !1,
|
|
431
|
+
isValidating: !1,
|
|
432
|
+
isValid: !1,
|
|
433
|
+
errors: !1
|
|
434
|
+
}, D = {
|
|
435
|
+
...N
|
|
436
|
+
};
|
|
437
|
+
let v = {
|
|
438
|
+
...D
|
|
439
|
+
};
|
|
440
|
+
const m = {
|
|
441
|
+
array: ft(),
|
|
442
|
+
state: ft()
|
|
443
|
+
}, K = t.criteriaMode === se.all, O = (a) => (u) => {
|
|
444
|
+
clearTimeout(p), p = setTimeout(a, u);
|
|
445
|
+
}, Z = async (a) => {
|
|
446
|
+
if (!l.keepIsValid && !t.disabled && (D.isValid || v.isValid || a)) {
|
|
447
|
+
let u;
|
|
448
|
+
t.resolver ? (u = Y((await ae()).errors), H()) : u = await B(s, !0), u !== r.isValid && m.state.next({
|
|
449
|
+
isValid: u
|
|
450
|
+
});
|
|
451
|
+
}
|
|
452
|
+
}, H = (a, u) => {
|
|
453
|
+
!t.disabled && (D.isValidating || D.validatingFields || v.isValidating || v.validatingFields) && ((a || Array.from(d.mount)).forEach((o) => {
|
|
454
|
+
o && (u ? R(r.validatingFields, o, u) : M(r.validatingFields, o));
|
|
455
|
+
}), m.state.next({
|
|
456
|
+
validatingFields: r.validatingFields,
|
|
457
|
+
isValidating: !Y(r.validatingFields)
|
|
458
|
+
}));
|
|
459
|
+
}, x = (a, u = [], o, f, h = !0, c = !0) => {
|
|
460
|
+
if (f && o && !t.disabled) {
|
|
461
|
+
if (l.action = !0, c && Array.isArray(g(s, a))) {
|
|
462
|
+
const y = o(g(s, a), f.argA, f.argB);
|
|
463
|
+
h && R(s, a, y);
|
|
464
|
+
}
|
|
465
|
+
if (c && Array.isArray(g(r.errors, a))) {
|
|
466
|
+
const y = o(g(r.errors, a), f.argA, f.argB);
|
|
467
|
+
h && R(r.errors, a, y), ur(r.errors, a);
|
|
468
|
+
}
|
|
469
|
+
if ((D.touchedFields || v.touchedFields) && c && Array.isArray(g(r.touchedFields, a))) {
|
|
470
|
+
const y = o(g(r.touchedFields, a), f.argA, f.argB);
|
|
471
|
+
h && R(r.touchedFields, a, y);
|
|
472
|
+
}
|
|
473
|
+
(D.dirtyFields || v.dirtyFields) && (r.dirtyFields = Fe(i, n)), m.state.next({
|
|
474
|
+
name: a,
|
|
475
|
+
isDirty: V(a, u),
|
|
476
|
+
dirtyFields: r.dirtyFields,
|
|
477
|
+
errors: r.errors,
|
|
478
|
+
isValid: r.isValid
|
|
479
|
+
});
|
|
480
|
+
} else
|
|
481
|
+
R(n, a, u);
|
|
482
|
+
}, ee = (a, u) => {
|
|
483
|
+
R(r.errors, a, u), m.state.next({
|
|
484
|
+
errors: r.errors
|
|
485
|
+
});
|
|
486
|
+
}, L = (a) => {
|
|
487
|
+
r.errors = a, m.state.next({
|
|
488
|
+
errors: r.errors,
|
|
489
|
+
isValid: !1
|
|
490
|
+
});
|
|
491
|
+
}, T = (a, u, o, f) => {
|
|
492
|
+
const h = g(s, a);
|
|
493
|
+
if (h) {
|
|
494
|
+
const c = g(n, a, C(o) ? g(i, a) : o);
|
|
495
|
+
C(c) || f && f.defaultChecked || u ? R(n, a, u ? c : gt(h._f)) : U(a, c), l.mount && !l.action && Z();
|
|
496
|
+
}
|
|
497
|
+
}, oe = (a, u, o, f, h) => {
|
|
498
|
+
let c = !1, y = !1;
|
|
499
|
+
const F = {
|
|
500
|
+
name: a
|
|
501
|
+
};
|
|
502
|
+
if (!t.disabled) {
|
|
503
|
+
if (!o || f) {
|
|
504
|
+
(D.isDirty || v.isDirty) && (y = r.isDirty, r.isDirty = F.isDirty = V(), c = y !== F.isDirty);
|
|
505
|
+
const b = de(g(i, a), u);
|
|
506
|
+
y = !!g(r.dirtyFields, a), b ? M(r.dirtyFields, a) : R(r.dirtyFields, a, !0), F.dirtyFields = r.dirtyFields, c = c || (D.dirtyFields || v.dirtyFields) && y !== !b;
|
|
507
|
+
}
|
|
508
|
+
if (o) {
|
|
509
|
+
const b = g(r.touchedFields, a);
|
|
510
|
+
b || (R(r.touchedFields, a, o), F.touchedFields = r.touchedFields, c = c || (D.touchedFields || v.touchedFields) && b !== o);
|
|
511
|
+
}
|
|
512
|
+
c && h && m.state.next(F);
|
|
513
|
+
}
|
|
514
|
+
return c ? F : {};
|
|
515
|
+
}, he = (a, u, o, f) => {
|
|
516
|
+
const h = g(r.errors, a), c = (D.isValid || v.isValid) && ie(u) && r.isValid !== u;
|
|
517
|
+
if (t.delayError && o ? (w = O(() => ee(a, o)), w(t.delayError)) : (clearTimeout(p), w = null, o ? R(r.errors, a, o) : M(r.errors, a)), (o ? !de(h, o) : h) || !Y(f) || c) {
|
|
518
|
+
const y = {
|
|
519
|
+
...f,
|
|
520
|
+
...c && ie(u) ? { isValid: u } : {},
|
|
521
|
+
errors: r.errors,
|
|
522
|
+
name: a
|
|
523
|
+
};
|
|
524
|
+
r = {
|
|
525
|
+
...r,
|
|
526
|
+
...y
|
|
527
|
+
}, m.state.next(y);
|
|
528
|
+
}
|
|
529
|
+
}, ae = async (a) => (H(a, !0), await t.resolver(n, t.context, tr(a || d.mount, s, t.criteriaMode, t.shouldUseNativeValidation))), ne = async (a) => {
|
|
530
|
+
const { errors: u } = await ae(a);
|
|
531
|
+
if (H(a), a)
|
|
532
|
+
for (const o of a) {
|
|
533
|
+
const f = g(u, o);
|
|
534
|
+
f ? R(r.errors, o, f) : M(r.errors, o);
|
|
535
|
+
}
|
|
536
|
+
else
|
|
537
|
+
r.errors = u;
|
|
538
|
+
return u;
|
|
539
|
+
}, B = async (a, u, o = {
|
|
540
|
+
valid: !0
|
|
541
|
+
}) => {
|
|
542
|
+
for (const f in a) {
|
|
543
|
+
const h = a[f];
|
|
544
|
+
if (h) {
|
|
545
|
+
const { _f: c, ...y } = h;
|
|
546
|
+
if (c) {
|
|
547
|
+
const F = d.array.has(c.name), b = h._f && rr(h._f);
|
|
548
|
+
b && D.validatingFields && H([c.name], !0);
|
|
549
|
+
const _ = await Vt(h, d.disabled, n, K, t.shouldUseNativeValidation && !u, F);
|
|
550
|
+
if (b && D.validatingFields && H([c.name]), _[c.name] && (o.valid = !1, u || e.shouldUseNativeValidation))
|
|
551
|
+
break;
|
|
552
|
+
!u && (g(_, c.name) ? F ? or(r.errors, _, c.name) : R(r.errors, c.name, _[c.name]) : M(r.errors, c.name));
|
|
553
|
+
}
|
|
554
|
+
!Y(y) && await B(y, u, o);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
return o.valid;
|
|
558
|
+
}, le = () => {
|
|
559
|
+
for (const a of d.unMount) {
|
|
560
|
+
const u = g(s, a);
|
|
561
|
+
u && (u._f.refs ? u._f.refs.every((o) => !Qe(o)) : !Qe(u._f.ref)) && xe(a);
|
|
562
|
+
}
|
|
563
|
+
d.unMount = /* @__PURE__ */ new Set();
|
|
564
|
+
}, V = (a, u) => !t.disabled && (a && u && R(n, a, u), !de(Me(), i)), E = (a, u, o) => Jt(a, d, {
|
|
565
|
+
...l.mount ? n : C(u) ? i : Q(a) ? { [a]: u } : u
|
|
566
|
+
}, o, u), S = (a) => st(g(l.mount ? n : i, a, t.shouldUnregister ? g(i, a, []) : [])), U = (a, u, o = {}) => {
|
|
567
|
+
const f = g(s, a);
|
|
568
|
+
let h = u;
|
|
569
|
+
if (f) {
|
|
570
|
+
const c = f._f;
|
|
571
|
+
c && (!c.disabled && R(n, a, Tt(u, c)), h = je(c.ref) && G(u) ? "" : u, Nt(c.ref) ? [...c.ref.options].forEach((y) => y.selected = h.includes(y.value)) : c.refs ? Le(c.ref) ? c.refs.forEach((y) => {
|
|
572
|
+
(!y.defaultChecked || !y.disabled) && (Array.isArray(h) ? y.checked = !!h.find((F) => F === y.value) : y.checked = h === y.value || !!h);
|
|
573
|
+
}) : c.refs.forEach((y) => y.checked = y.value === h) : at(c.ref) ? c.ref.value = "" : (c.ref.value = h, c.ref.type || m.state.next({
|
|
574
|
+
name: a,
|
|
575
|
+
values: k(n)
|
|
576
|
+
})));
|
|
577
|
+
}
|
|
578
|
+
(o.shouldDirty || o.shouldTouch) && oe(a, h, o.shouldTouch, o.shouldDirty, !0), o.shouldValidate && me(a);
|
|
579
|
+
}, $ = (a, u, o) => {
|
|
580
|
+
for (const f in u) {
|
|
581
|
+
if (!u.hasOwnProperty(f))
|
|
582
|
+
return;
|
|
583
|
+
const h = u[f], c = a + "." + f, y = g(s, c);
|
|
584
|
+
(d.array.has(a) || I(h) || y && !y._f) && !ge(h) ? $(c, h, o) : U(c, h, o);
|
|
585
|
+
}
|
|
586
|
+
}, j = (a, u, o = {}) => {
|
|
587
|
+
const f = g(s, a), h = d.array.has(a), c = k(u);
|
|
588
|
+
R(n, a, c), h ? (m.array.next({
|
|
589
|
+
name: a,
|
|
590
|
+
values: k(n)
|
|
591
|
+
}), (D.isDirty || D.dirtyFields || v.isDirty || v.dirtyFields) && o.shouldDirty && m.state.next({
|
|
592
|
+
name: a,
|
|
593
|
+
dirtyFields: Fe(i, n),
|
|
594
|
+
isDirty: V(a, c)
|
|
595
|
+
})) : f && !f._f && !G(c) ? $(a, c, o) : U(a, c, o), wt(a, d) ? m.state.next({
|
|
596
|
+
...r,
|
|
597
|
+
name: a,
|
|
598
|
+
values: k(n)
|
|
599
|
+
}) : m.state.next({
|
|
600
|
+
name: l.mount ? a : void 0,
|
|
601
|
+
values: k(n)
|
|
602
|
+
});
|
|
603
|
+
}, z = async (a) => {
|
|
604
|
+
l.mount = !0;
|
|
605
|
+
const u = a.target;
|
|
606
|
+
let o = u.name, f = !0;
|
|
607
|
+
const h = g(s, o), c = (b) => {
|
|
608
|
+
f = Number.isNaN(b) || ge(b) && isNaN(b.getTime()) || de(b, g(n, o, b));
|
|
609
|
+
}, y = pt(t.mode), F = pt(t.reValidateMode);
|
|
610
|
+
if (h) {
|
|
611
|
+
let b, _;
|
|
612
|
+
const P = u.type ? gt(h._f) : $t(a), W = a.type === dt.BLUR || a.type === dt.FOCUS_OUT, q = !sr(h._f) && !t.resolver && !g(r.errors, o) && !h._f.deps || nr(W, g(r.touchedFields, o), r.isSubmitted, F, y), J = wt(o, d, W);
|
|
613
|
+
R(n, o, P), W ? (!u || !u.readOnly) && (h._f.onBlur && h._f.onBlur(a), w && w(0)) : h._f.onChange && h._f.onChange(a);
|
|
614
|
+
const be = oe(o, P, W), ot = !Y(be) || J;
|
|
615
|
+
if (!W && m.state.next({
|
|
616
|
+
name: o,
|
|
617
|
+
type: a.type,
|
|
618
|
+
values: k(n)
|
|
619
|
+
}), q)
|
|
620
|
+
return (D.isValid || v.isValid) && (t.mode === "onBlur" ? W && Z() : W || Z()), ot && m.state.next({ name: o, ...J ? {} : be });
|
|
621
|
+
if (!W && J && m.state.next({ ...r }), t.resolver) {
|
|
622
|
+
const { errors: Xe } = await ae([o]);
|
|
623
|
+
if (H([o]), c(P), f) {
|
|
624
|
+
const Ut = vt(r.errors, s, o), lt = vt(Xe, s, Ut.name || o);
|
|
625
|
+
b = lt.error, o = lt.name, _ = Y(Xe);
|
|
626
|
+
}
|
|
627
|
+
} else
|
|
628
|
+
H([o], !0), b = (await Vt(h, d.disabled, n, K, t.shouldUseNativeValidation))[o], H([o]), c(P), f && (b ? _ = !1 : (D.isValid || v.isValid) && (_ = await B(s, !0)));
|
|
629
|
+
f && (h._f.deps && (!Array.isArray(h._f.deps) || h._f.deps.length > 0) && me(h._f.deps), he(o, _, b, be));
|
|
630
|
+
}
|
|
631
|
+
}, ce = (a, u) => {
|
|
632
|
+
if (g(r.errors, u) && a.focus)
|
|
633
|
+
return a.focus(), 1;
|
|
634
|
+
}, me = async (a, u = {}) => {
|
|
635
|
+
let o, f;
|
|
636
|
+
const h = Ce(a);
|
|
637
|
+
if (t.resolver) {
|
|
638
|
+
const c = await ne(C(a) ? a : h);
|
|
639
|
+
o = Y(c), f = a ? !h.some((y) => g(c, y)) : o;
|
|
640
|
+
} else a ? (f = (await Promise.all(h.map(async (c) => {
|
|
641
|
+
const y = g(s, c);
|
|
642
|
+
return await B(y && y._f ? { [c]: y } : y);
|
|
643
|
+
}))).every(Boolean), !(!f && !r.isValid) && Z()) : f = o = await B(s);
|
|
644
|
+
return m.state.next({
|
|
645
|
+
...!Q(a) || (D.isValid || v.isValid) && o !== r.isValid ? {} : { name: a },
|
|
646
|
+
...t.resolver || !a ? { isValid: o } : {},
|
|
647
|
+
errors: r.errors
|
|
648
|
+
}), u.shouldFocus && !f && Te(s, ce, a ? h : d.mount), f;
|
|
649
|
+
}, Me = (a, u) => {
|
|
650
|
+
let o = {
|
|
651
|
+
...l.mount ? n : i
|
|
652
|
+
};
|
|
653
|
+
return u && (o = Rt(u.dirtyFields ? r.dirtyFields : r.touchedFields, o)), C(a) ? o : Q(a) ? g(o, a) : a.map((f) => g(o, f));
|
|
654
|
+
}, A = (a, u) => ({
|
|
655
|
+
invalid: !!g((u || r).errors, a),
|
|
656
|
+
isDirty: !!g((u || r).dirtyFields, a),
|
|
657
|
+
error: g((u || r).errors, a),
|
|
658
|
+
isValidating: !!g(r.validatingFields, a),
|
|
659
|
+
isTouched: !!g((u || r).touchedFields, a)
|
|
660
|
+
}), Ee = (a) => {
|
|
661
|
+
a && Ce(a).forEach((u) => M(r.errors, u)), m.state.next({
|
|
662
|
+
errors: a ? r.errors : {}
|
|
663
|
+
});
|
|
664
|
+
}, Ae = (a, u, o) => {
|
|
665
|
+
const f = (g(s, a, { _f: {} })._f || {}).ref, h = g(r.errors, a) || {}, { ref: c, message: y, type: F, ...b } = h;
|
|
666
|
+
R(r.errors, a, {
|
|
667
|
+
...b,
|
|
668
|
+
...u,
|
|
669
|
+
ref: f
|
|
670
|
+
}), m.state.next({
|
|
671
|
+
name: a,
|
|
672
|
+
errors: r.errors,
|
|
673
|
+
isValid: !1
|
|
674
|
+
}), o && o.shouldFocus && f && f.focus && f.focus();
|
|
675
|
+
}, Ye = (a, u) => re(a) ? m.state.subscribe({
|
|
676
|
+
next: (o) => "values" in o && a(E(void 0, u), o)
|
|
677
|
+
}) : E(a, u, !0), Ie = (a) => m.state.subscribe({
|
|
678
|
+
next: (u) => {
|
|
679
|
+
ar(a.name, u.name, a.exact) && ir(u, a.formState || D, Ge, a.reRenderRoot) && a.callback({
|
|
680
|
+
values: { ...n },
|
|
681
|
+
...r,
|
|
682
|
+
...u,
|
|
683
|
+
defaultValues: i
|
|
684
|
+
});
|
|
685
|
+
}
|
|
686
|
+
}).unsubscribe, Ke = (a) => (l.mount = !0, v = {
|
|
687
|
+
...v,
|
|
688
|
+
...a.formState
|
|
689
|
+
}, Ie({
|
|
690
|
+
...a,
|
|
691
|
+
formState: {
|
|
692
|
+
...N,
|
|
693
|
+
...a.formState
|
|
694
|
+
}
|
|
695
|
+
})), xe = (a, u = {}) => {
|
|
696
|
+
for (const o of a ? Ce(a) : d.mount)
|
|
697
|
+
d.mount.delete(o), d.array.delete(o), u.keepValue || (M(s, o), M(n, o)), !u.keepError && M(r.errors, o), !u.keepDirty && M(r.dirtyFields, o), !u.keepTouched && M(r.touchedFields, o), !u.keepIsValidating && M(r.validatingFields, o), !t.shouldUnregister && !u.keepDefaultValue && M(i, o);
|
|
698
|
+
m.state.next({
|
|
699
|
+
values: k(n)
|
|
700
|
+
}), m.state.next({
|
|
701
|
+
...r,
|
|
702
|
+
...u.keepDirty ? { isDirty: V() } : {}
|
|
703
|
+
}), !u.keepIsValid && Z();
|
|
704
|
+
}, ke = ({ disabled: a, name: u }) => {
|
|
705
|
+
(ie(a) && l.mount || a || d.disabled.has(u)) && (a ? d.disabled.add(u) : d.disabled.delete(u));
|
|
706
|
+
}, _e = (a, u = {}) => {
|
|
707
|
+
let o = g(s, a);
|
|
708
|
+
const f = ie(u.disabled) || ie(t.disabled);
|
|
709
|
+
return R(s, a, {
|
|
710
|
+
...o || {},
|
|
711
|
+
_f: {
|
|
712
|
+
...o && o._f ? o._f : { ref: { name: a } },
|
|
713
|
+
name: a,
|
|
714
|
+
mount: !0,
|
|
715
|
+
...u
|
|
716
|
+
}
|
|
717
|
+
}), d.mount.add(a), o ? ke({
|
|
718
|
+
disabled: ie(u.disabled) ? u.disabled : t.disabled,
|
|
719
|
+
name: a
|
|
720
|
+
}) : T(a, !0, u.value), {
|
|
721
|
+
...f ? { disabled: u.disabled || t.disabled } : {},
|
|
722
|
+
...t.progressive ? {
|
|
723
|
+
required: !!u.required,
|
|
724
|
+
min: Oe(u.min),
|
|
725
|
+
max: Oe(u.max),
|
|
726
|
+
minLength: Oe(u.minLength),
|
|
727
|
+
maxLength: Oe(u.maxLength),
|
|
728
|
+
pattern: Oe(u.pattern)
|
|
729
|
+
} : {},
|
|
730
|
+
name: a,
|
|
731
|
+
onChange: z,
|
|
732
|
+
onBlur: z,
|
|
733
|
+
ref: (h) => {
|
|
734
|
+
if (h) {
|
|
735
|
+
_e(a, u), o = g(s, a);
|
|
736
|
+
const c = C(h.value) && h.querySelectorAll && h.querySelectorAll("input,select,textarea")[0] || h, y = Xt(c), F = o._f.refs || [];
|
|
737
|
+
if (y ? F.find((b) => b === c) : c === o._f.ref)
|
|
738
|
+
return;
|
|
739
|
+
R(s, a, {
|
|
740
|
+
_f: {
|
|
741
|
+
...o._f,
|
|
742
|
+
...y ? {
|
|
743
|
+
refs: [
|
|
744
|
+
...F.filter(Qe),
|
|
745
|
+
c,
|
|
746
|
+
...Array.isArray(g(i, a)) ? [{}] : []
|
|
747
|
+
],
|
|
748
|
+
ref: { type: c.type, name: a }
|
|
749
|
+
} : { ref: c }
|
|
750
|
+
}
|
|
751
|
+
}), T(a, !1, void 0, c);
|
|
752
|
+
} else
|
|
753
|
+
o = g(s, a, {}), o._f && (o._f.mount = !1), (t.shouldUnregister || u.shouldUnregister) && !(Wt(d.array, a) && l.action) && d.unMount.add(a);
|
|
754
|
+
}
|
|
755
|
+
};
|
|
756
|
+
}, De = () => t.shouldFocusError && Te(s, ce, d.mount), ze = (a) => {
|
|
757
|
+
ie(a) && (m.state.next({ disabled: a }), Te(s, (u, o) => {
|
|
758
|
+
const f = g(s, o);
|
|
759
|
+
f && (u.disabled = f._f.disabled || a, Array.isArray(f._f.refs) && f._f.refs.forEach((h) => {
|
|
760
|
+
h.disabled = f._f.disabled || a;
|
|
761
|
+
}));
|
|
762
|
+
}, 0, !1));
|
|
763
|
+
}, Ue = (a, u) => async (o) => {
|
|
764
|
+
let f;
|
|
765
|
+
o && (o.preventDefault && o.preventDefault(), o.persist && o.persist());
|
|
766
|
+
let h = k(n);
|
|
767
|
+
if (m.state.next({
|
|
768
|
+
isSubmitting: !0
|
|
769
|
+
}), t.resolver) {
|
|
770
|
+
const { errors: c, values: y } = await ae();
|
|
771
|
+
H(), r.errors = c, h = k(y);
|
|
772
|
+
} else
|
|
773
|
+
await B(s);
|
|
774
|
+
if (d.disabled.size)
|
|
775
|
+
for (const c of d.disabled)
|
|
776
|
+
M(h, c);
|
|
777
|
+
if (M(r.errors, "root"), Y(r.errors)) {
|
|
778
|
+
m.state.next({
|
|
779
|
+
errors: {}
|
|
780
|
+
});
|
|
781
|
+
try {
|
|
782
|
+
await a(h, o);
|
|
783
|
+
} catch (c) {
|
|
784
|
+
f = c;
|
|
785
|
+
}
|
|
786
|
+
} else
|
|
787
|
+
u && await u({ ...r.errors }, o), De(), setTimeout(De);
|
|
788
|
+
if (m.state.next({
|
|
789
|
+
isSubmitted: !0,
|
|
790
|
+
isSubmitting: !1,
|
|
791
|
+
isSubmitSuccessful: Y(r.errors) && !f,
|
|
792
|
+
submitCount: r.submitCount + 1,
|
|
793
|
+
errors: r.errors
|
|
794
|
+
}), f)
|
|
795
|
+
throw f;
|
|
796
|
+
}, Be = (a, u = {}) => {
|
|
797
|
+
g(s, a) && (C(u.defaultValue) ? j(a, k(g(i, a))) : (j(a, u.defaultValue), R(i, a, k(u.defaultValue))), u.keepTouched || M(r.touchedFields, a), u.keepDirty || (M(r.dirtyFields, a), r.isDirty = u.defaultValue ? V(a, k(g(i, a))) : V()), u.keepError || (M(r.errors, a), D.isValid && Z()), m.state.next({ ...r }));
|
|
798
|
+
}, Pe = (a, u = {}) => {
|
|
799
|
+
const o = a ? k(a) : i, f = k(o), h = Y(a), c = h ? i : f;
|
|
800
|
+
if (u.keepDefaultValues || (i = o), !u.keepValues) {
|
|
801
|
+
if (u.keepDirtyValues) {
|
|
802
|
+
const y = /* @__PURE__ */ new Set([
|
|
803
|
+
...d.mount,
|
|
804
|
+
...Object.keys(Fe(i, n))
|
|
805
|
+
]);
|
|
806
|
+
for (const F of Array.from(y)) {
|
|
807
|
+
const b = g(r.dirtyFields, F), _ = g(n, F), P = g(c, F);
|
|
808
|
+
b && !C(_) ? R(c, F, _) : !b && !C(P) && j(F, P);
|
|
809
|
+
}
|
|
810
|
+
} else {
|
|
811
|
+
if (rt && C(a))
|
|
812
|
+
for (const y of d.mount) {
|
|
813
|
+
const F = g(s, y);
|
|
814
|
+
if (F && F._f) {
|
|
815
|
+
const b = Array.isArray(F._f.refs) ? F._f.refs[0] : F._f.ref;
|
|
816
|
+
if (je(b)) {
|
|
817
|
+
const _ = b.closest("form");
|
|
818
|
+
if (_) {
|
|
819
|
+
_.reset();
|
|
820
|
+
break;
|
|
821
|
+
}
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (u.keepFieldsRef)
|
|
826
|
+
for (const y of d.mount)
|
|
827
|
+
j(y, g(c, y));
|
|
828
|
+
else
|
|
829
|
+
s = {};
|
|
830
|
+
}
|
|
831
|
+
n = t.shouldUnregister ? u.keepDefaultValues ? k(i) : {} : k(c), m.array.next({
|
|
832
|
+
values: { ...c }
|
|
833
|
+
}), m.state.next({
|
|
834
|
+
values: { ...c }
|
|
835
|
+
});
|
|
836
|
+
}
|
|
837
|
+
d = {
|
|
838
|
+
mount: u.keepDirtyValues ? d.mount : /* @__PURE__ */ new Set(),
|
|
839
|
+
unMount: /* @__PURE__ */ new Set(),
|
|
840
|
+
array: /* @__PURE__ */ new Set(),
|
|
841
|
+
disabled: /* @__PURE__ */ new Set(),
|
|
842
|
+
watch: /* @__PURE__ */ new Set(),
|
|
843
|
+
watchAll: !1,
|
|
844
|
+
focus: ""
|
|
845
|
+
}, l.mount = !D.isValid || !!u.keepIsValid || !!u.keepDirtyValues || !t.shouldUnregister && !Y(c), l.watch = !!t.shouldUnregister, l.keepIsValid = !!u.keepIsValid, l.action = !1, u.keepErrors || (r.errors = {}), m.state.next({
|
|
846
|
+
submitCount: u.keepSubmitCount ? r.submitCount : 0,
|
|
847
|
+
isDirty: h ? !1 : u.keepDirty ? r.isDirty : !!(u.keepDefaultValues && !de(a, i)),
|
|
848
|
+
isSubmitted: u.keepIsSubmitted ? r.isSubmitted : !1,
|
|
849
|
+
dirtyFields: h ? {} : u.keepDirtyValues ? u.keepDefaultValues && n ? Fe(i, n) : r.dirtyFields : u.keepDefaultValues && a ? Fe(i, a) : u.keepDirty ? r.dirtyFields : {},
|
|
850
|
+
touchedFields: u.keepTouched ? r.touchedFields : {},
|
|
851
|
+
errors: u.keepErrors ? r.errors : {},
|
|
852
|
+
isSubmitSuccessful: u.keepIsSubmitSuccessful ? r.isSubmitSuccessful : !1,
|
|
853
|
+
isSubmitting: !1,
|
|
854
|
+
defaultValues: i
|
|
855
|
+
});
|
|
856
|
+
}, Se = (a, u) => Pe(re(a) ? a(n) : a, { ...t.resetOptions, ...u }), Je = (a, u = {}) => {
|
|
857
|
+
const o = g(s, a), f = o && o._f;
|
|
858
|
+
if (f) {
|
|
859
|
+
const h = f.refs ? f.refs[0] : f.ref;
|
|
860
|
+
h.focus && setTimeout(() => {
|
|
861
|
+
h.focus(), u.shouldSelect && re(h.select) && h.select();
|
|
862
|
+
});
|
|
863
|
+
}
|
|
864
|
+
}, Ge = (a) => {
|
|
865
|
+
r = {
|
|
866
|
+
...r,
|
|
867
|
+
...a
|
|
868
|
+
};
|
|
869
|
+
}, Re = {
|
|
870
|
+
control: {
|
|
871
|
+
register: _e,
|
|
872
|
+
unregister: xe,
|
|
873
|
+
getFieldState: A,
|
|
874
|
+
handleSubmit: Ue,
|
|
875
|
+
setError: Ae,
|
|
876
|
+
_subscribe: Ie,
|
|
877
|
+
_runSchema: ae,
|
|
878
|
+
_updateIsValidating: H,
|
|
879
|
+
_focusError: De,
|
|
880
|
+
_getWatch: E,
|
|
881
|
+
_getDirty: V,
|
|
882
|
+
_setValid: Z,
|
|
883
|
+
_setFieldArray: x,
|
|
884
|
+
_setDisabledField: ke,
|
|
885
|
+
_setErrors: L,
|
|
886
|
+
_getFieldArray: S,
|
|
887
|
+
_reset: Pe,
|
|
888
|
+
_resetDefaultValues: () => re(t.defaultValues) && t.defaultValues().then((a) => {
|
|
889
|
+
Se(a, t.resetOptions), m.state.next({
|
|
890
|
+
isLoading: !1
|
|
891
|
+
});
|
|
892
|
+
}),
|
|
893
|
+
_removeUnmounted: le,
|
|
894
|
+
_disableForm: ze,
|
|
895
|
+
_subjects: m,
|
|
896
|
+
_proxyFormState: D,
|
|
897
|
+
get _fields() {
|
|
898
|
+
return s;
|
|
899
|
+
},
|
|
900
|
+
get _formValues() {
|
|
901
|
+
return n;
|
|
902
|
+
},
|
|
903
|
+
get _state() {
|
|
904
|
+
return l;
|
|
905
|
+
},
|
|
906
|
+
set _state(a) {
|
|
907
|
+
l = a;
|
|
908
|
+
},
|
|
909
|
+
get _defaultValues() {
|
|
910
|
+
return i;
|
|
911
|
+
},
|
|
912
|
+
get _names() {
|
|
913
|
+
return d;
|
|
914
|
+
},
|
|
915
|
+
set _names(a) {
|
|
916
|
+
d = a;
|
|
917
|
+
},
|
|
918
|
+
get _formState() {
|
|
919
|
+
return r;
|
|
920
|
+
},
|
|
921
|
+
get _options() {
|
|
922
|
+
return t;
|
|
923
|
+
},
|
|
924
|
+
set _options(a) {
|
|
925
|
+
t = {
|
|
926
|
+
...t,
|
|
927
|
+
...a
|
|
928
|
+
};
|
|
929
|
+
}
|
|
930
|
+
},
|
|
931
|
+
subscribe: Ke,
|
|
932
|
+
trigger: me,
|
|
933
|
+
register: _e,
|
|
934
|
+
handleSubmit: Ue,
|
|
935
|
+
watch: Ye,
|
|
936
|
+
setValue: j,
|
|
937
|
+
getValues: Me,
|
|
938
|
+
reset: Se,
|
|
939
|
+
resetField: Be,
|
|
940
|
+
clearErrors: Ee,
|
|
941
|
+
unregister: xe,
|
|
942
|
+
setError: Ae,
|
|
943
|
+
setFocus: Je,
|
|
944
|
+
getFieldState: A
|
|
945
|
+
};
|
|
946
|
+
return {
|
|
947
|
+
...Re,
|
|
948
|
+
formControl: Re
|
|
949
|
+
};
|
|
950
|
+
}
|
|
951
|
+
function dr(e = {}) {
|
|
952
|
+
const t = X.useRef(void 0), r = X.useRef(void 0), [s, i] = X.useState({
|
|
953
|
+
isDirty: !1,
|
|
954
|
+
isValidating: !1,
|
|
955
|
+
isLoading: re(e.defaultValues),
|
|
956
|
+
isSubmitted: !1,
|
|
957
|
+
isSubmitting: !1,
|
|
958
|
+
isSubmitSuccessful: !1,
|
|
959
|
+
isValid: !1,
|
|
960
|
+
submitCount: 0,
|
|
961
|
+
dirtyFields: {},
|
|
962
|
+
touchedFields: {},
|
|
963
|
+
validatingFields: {},
|
|
964
|
+
errors: e.errors || {},
|
|
965
|
+
disabled: e.disabled || !1,
|
|
966
|
+
isReady: !1,
|
|
967
|
+
defaultValues: re(e.defaultValues) ? void 0 : e.defaultValues
|
|
968
|
+
});
|
|
969
|
+
if (!t.current)
|
|
970
|
+
if (e.formControl)
|
|
971
|
+
t.current = {
|
|
972
|
+
...e.formControl,
|
|
973
|
+
formState: s
|
|
974
|
+
}, e.defaultValues && !re(e.defaultValues) && e.formControl.reset(e.defaultValues, e.resetOptions);
|
|
975
|
+
else {
|
|
976
|
+
const { formControl: l, ...d } = cr(e);
|
|
977
|
+
t.current = {
|
|
978
|
+
...d,
|
|
979
|
+
formState: s
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
const n = t.current.control;
|
|
983
|
+
return n._options = e, zt(() => {
|
|
984
|
+
const l = n._subscribe({
|
|
985
|
+
formState: n._proxyFormState,
|
|
986
|
+
callback: () => i({ ...n._formState }),
|
|
987
|
+
reRenderRoot: !0
|
|
988
|
+
});
|
|
989
|
+
return i((d) => ({
|
|
990
|
+
...d,
|
|
991
|
+
isReady: !0
|
|
992
|
+
})), n._formState.isReady = !0, l;
|
|
993
|
+
}, [n]), X.useEffect(() => n._disableForm(e.disabled), [n, e.disabled]), X.useEffect(() => {
|
|
994
|
+
e.mode && (n._options.mode = e.mode), e.reValidateMode && (n._options.reValidateMode = e.reValidateMode);
|
|
995
|
+
}, [n, e.mode, e.reValidateMode]), X.useEffect(() => {
|
|
996
|
+
e.errors && (n._setErrors(e.errors), n._focusError());
|
|
997
|
+
}, [n, e.errors]), X.useEffect(() => {
|
|
998
|
+
e.shouldUnregister && n._subjects.state.next({
|
|
999
|
+
values: n._getWatch()
|
|
1000
|
+
});
|
|
1001
|
+
}, [n, e.shouldUnregister]), X.useEffect(() => {
|
|
1002
|
+
if (n._proxyFormState.isDirty) {
|
|
1003
|
+
const l = n._getDirty();
|
|
1004
|
+
l !== s.isDirty && n._subjects.state.next({
|
|
1005
|
+
isDirty: l
|
|
1006
|
+
});
|
|
1007
|
+
}
|
|
1008
|
+
}, [n, s.isDirty]), X.useEffect(() => {
|
|
1009
|
+
var l;
|
|
1010
|
+
e.values && !de(e.values, r.current) ? (n._reset(e.values, {
|
|
1011
|
+
keepFieldsRef: !0,
|
|
1012
|
+
...n._options.resetOptions
|
|
1013
|
+
}), !((l = n._options.resetOptions) === null || l === void 0) && l.keepIsValid || n._setValid(), r.current = e.values, i((d) => ({ ...d }))) : n._resetDefaultValues();
|
|
1014
|
+
}, [n, e.values]), X.useEffect(() => {
|
|
1015
|
+
n._state.mount || (n._setValid(), n._state.mount = !0), n._state.watch && (n._state.watch = !1, n._subjects.state.next({ ...n._formState })), n._removeUnmounted();
|
|
1016
|
+
}), t.current.formState = Kt(s, n), t.current;
|
|
1017
|
+
}
|
|
1018
|
+
function fr() {
|
|
1019
|
+
const e = /* @__PURE__ */ new Date();
|
|
1020
|
+
return {
|
|
1021
|
+
NOW: e,
|
|
1022
|
+
TODAY: new Date(e.getFullYear(), e.getMonth(), e.getDate()),
|
|
14
1023
|
CURRENT_USER: {
|
|
15
1024
|
// These would typically come from auth context
|
|
16
1025
|
EmpId: 1,
|
|
@@ -22,211 +1031,211 @@ function Be() {
|
|
|
22
1031
|
CURRENT_USER_ID: 1
|
|
23
1032
|
};
|
|
24
1033
|
}
|
|
25
|
-
const
|
|
1034
|
+
const hr = {
|
|
26
1035
|
// String functions
|
|
27
|
-
CONCAT: (...
|
|
28
|
-
TRIM: (
|
|
29
|
-
LENGTH: (
|
|
30
|
-
UPPER: (
|
|
31
|
-
LOWER: (
|
|
32
|
-
SUBSTRING: (
|
|
33
|
-
const s = String(
|
|
34
|
-
return r !== void 0 ? s.substring(
|
|
1036
|
+
CONCAT: (...e) => e.map((t) => String(t || "")).join(""),
|
|
1037
|
+
TRIM: (e) => String(e || "").trim(),
|
|
1038
|
+
LENGTH: (e) => String(e || "").length,
|
|
1039
|
+
UPPER: (e) => String(e || "").toUpperCase(),
|
|
1040
|
+
LOWER: (e) => String(e || "").toLowerCase(),
|
|
1041
|
+
SUBSTRING: (e, t, r) => {
|
|
1042
|
+
const s = String(e || "");
|
|
1043
|
+
return r !== void 0 ? s.substring(t, t + r) : s.substring(t);
|
|
35
1044
|
},
|
|
36
|
-
CONTAINS: (
|
|
1045
|
+
CONTAINS: (e, t) => String(e || "").includes(String(t || "")),
|
|
37
1046
|
// Date functions
|
|
38
|
-
YEAR: (
|
|
39
|
-
MONTH: (
|
|
1047
|
+
YEAR: (e) => new Date(e).getFullYear(),
|
|
1048
|
+
MONTH: (e) => new Date(e).getMonth() + 1,
|
|
40
1049
|
// 1-based
|
|
41
|
-
DAY: (
|
|
42
|
-
DATE_DIFF: (
|
|
43
|
-
const r = new Date(
|
|
44
|
-
return Math.ceil(
|
|
1050
|
+
DAY: (e) => new Date(e).getDate(),
|
|
1051
|
+
DATE_DIFF: (e, t) => {
|
|
1052
|
+
const r = new Date(e), s = new Date(t), i = Math.abs(r.getTime() - s.getTime());
|
|
1053
|
+
return Math.ceil(i / (1e3 * 60 * 60 * 24));
|
|
45
1054
|
},
|
|
46
|
-
ADD_DAYS: (
|
|
47
|
-
const r = new Date(
|
|
48
|
-
return r.setDate(r.getDate() +
|
|
1055
|
+
ADD_DAYS: (e, t) => {
|
|
1056
|
+
const r = new Date(e);
|
|
1057
|
+
return r.setDate(r.getDate() + t), r;
|
|
49
1058
|
},
|
|
50
|
-
ADD_MONTHS: (
|
|
51
|
-
const r = new Date(
|
|
52
|
-
return r.setMonth(r.getMonth() +
|
|
1059
|
+
ADD_MONTHS: (e, t) => {
|
|
1060
|
+
const r = new Date(e);
|
|
1061
|
+
return r.setMonth(r.getMonth() + t), r;
|
|
53
1062
|
},
|
|
54
1063
|
// Math functions
|
|
55
|
-
SUM: (...
|
|
56
|
-
AVG: (...
|
|
57
|
-
const
|
|
58
|
-
return
|
|
1064
|
+
SUM: (...e) => e.reduce((t, r) => t + (Number(r) || 0), 0),
|
|
1065
|
+
AVG: (...e) => {
|
|
1066
|
+
const t = e.filter((r) => !isNaN(Number(r)));
|
|
1067
|
+
return t.length > 0 ? t.reduce((r, s) => r + Number(s), 0) / t.length : 0;
|
|
59
1068
|
},
|
|
60
|
-
MIN: (...
|
|
61
|
-
MAX: (...
|
|
62
|
-
ROUND: (
|
|
63
|
-
FLOOR: (
|
|
64
|
-
CEIL: (
|
|
65
|
-
ABS: (
|
|
1069
|
+
MIN: (...e) => Math.min(...e.map((t) => Number(t) || 0)),
|
|
1070
|
+
MAX: (...e) => Math.max(...e.map((t) => Number(t) || 0)),
|
|
1071
|
+
ROUND: (e) => Math.round(Number(e) || 0),
|
|
1072
|
+
FLOOR: (e) => Math.floor(Number(e) || 0),
|
|
1073
|
+
CEIL: (e) => Math.ceil(Number(e) || 0),
|
|
1074
|
+
ABS: (e) => Math.abs(Number(e) || 0),
|
|
66
1075
|
// Conditional functions
|
|
67
|
-
IF: (
|
|
1076
|
+
IF: (e, t, r) => e ? t : r,
|
|
68
1077
|
// Validation functions
|
|
69
|
-
IS_NULL: (
|
|
70
|
-
IS_EMPTY: (
|
|
71
|
-
IS_NUMBER: (
|
|
72
|
-
IS_DATE: (
|
|
73
|
-
const
|
|
74
|
-
return !isNaN(
|
|
1078
|
+
IS_NULL: (e) => e == null,
|
|
1079
|
+
IS_EMPTY: (e) => !e || String(e).trim() === "",
|
|
1080
|
+
IS_NUMBER: (e) => !isNaN(Number(e)) && e !== "" && e !== null && e !== void 0,
|
|
1081
|
+
IS_DATE: (e) => {
|
|
1082
|
+
const t = new Date(e);
|
|
1083
|
+
return !isNaN(t.getTime());
|
|
75
1084
|
},
|
|
76
1085
|
// System functions
|
|
77
1086
|
AUTO_NUMBER: () => Math.floor(Math.random() * 1e4) + 1e3,
|
|
78
1087
|
// Mock implementation
|
|
79
|
-
UUID: () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (
|
|
80
|
-
const
|
|
81
|
-
return (
|
|
1088
|
+
UUID: () => "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (e) => {
|
|
1089
|
+
const t = Math.random() * 16 | 0;
|
|
1090
|
+
return (e == "x" ? t : t & 3 | 8).toString(16);
|
|
82
1091
|
}),
|
|
83
1092
|
// Array functions
|
|
84
|
-
ARRAY_LENGTH: (
|
|
85
|
-
ARRAY_CONTAINS: (
|
|
86
|
-
ARRAY_JOIN: (
|
|
1093
|
+
ARRAY_LENGTH: (e) => Array.isArray(e) ? e.length : 0,
|
|
1094
|
+
ARRAY_CONTAINS: (e, t) => Array.isArray(e) ? e.includes(t) : !1,
|
|
1095
|
+
ARRAY_JOIN: (e, t = ",") => Array.isArray(e) ? e.join(t) : ""
|
|
87
1096
|
};
|
|
88
|
-
function
|
|
1097
|
+
function fe(e, t) {
|
|
89
1098
|
var r;
|
|
90
|
-
switch (
|
|
1099
|
+
switch (e.Type) {
|
|
91
1100
|
case "Literal":
|
|
92
|
-
return
|
|
1101
|
+
return e.Value;
|
|
93
1102
|
case "SystemIdentifier":
|
|
94
|
-
if (
|
|
95
|
-
const
|
|
96
|
-
return
|
|
1103
|
+
if (e.Property) {
|
|
1104
|
+
const p = t.systemValues[e.Name];
|
|
1105
|
+
return Ze(p, e.Property.Name);
|
|
97
1106
|
}
|
|
98
|
-
return
|
|
1107
|
+
return t.systemValues[e.Name];
|
|
99
1108
|
case "Identifier":
|
|
100
|
-
if (
|
|
101
|
-
const
|
|
102
|
-
return
|
|
1109
|
+
if (e.Property) {
|
|
1110
|
+
const p = Et(e, t);
|
|
1111
|
+
return Ze(p, e.Property.Name);
|
|
103
1112
|
}
|
|
104
|
-
return
|
|
1113
|
+
return Et(e, t);
|
|
105
1114
|
case "MemberExpression":
|
|
106
|
-
if (!
|
|
1115
|
+
if (!e.Arguments || e.Arguments.length === 0)
|
|
107
1116
|
throw new Error("MemberExpression requires Arguments array");
|
|
108
|
-
const s =
|
|
109
|
-
return
|
|
1117
|
+
const s = fe(e.Arguments[0], t), i = (r = e.Arguments[0].Property) == null ? void 0 : r.Name;
|
|
1118
|
+
return i ? Ze(s, i) : s;
|
|
110
1119
|
case "BinaryExpression":
|
|
111
|
-
if (!
|
|
1120
|
+
if (!e.Arguments || e.Arguments.length !== 2)
|
|
112
1121
|
throw new Error("BinaryExpression requires exactly 2 arguments");
|
|
113
|
-
const n =
|
|
114
|
-
return
|
|
1122
|
+
const n = fe(e.Arguments[0], t), l = fe(e.Arguments[1], t);
|
|
1123
|
+
return mr(e.Operator, n, l);
|
|
115
1124
|
case "LogicalExpression":
|
|
116
|
-
if (!
|
|
1125
|
+
if (!e.Arguments || e.Arguments.length < 2)
|
|
117
1126
|
throw new Error("LogicalExpression requires at least 2 arguments");
|
|
118
|
-
return
|
|
1127
|
+
return yr(e.Operator, e.Arguments, t);
|
|
119
1128
|
case "CallExpression":
|
|
120
|
-
if (!
|
|
1129
|
+
if (!e.Callee)
|
|
121
1130
|
throw new Error("CallExpression requires Callee");
|
|
122
|
-
const
|
|
123
|
-
if (!
|
|
124
|
-
throw new Error(`Unknown function: ${
|
|
125
|
-
const
|
|
126
|
-
(
|
|
1131
|
+
const d = hr[e.Callee];
|
|
1132
|
+
if (!d)
|
|
1133
|
+
throw new Error(`Unknown function: ${e.Callee}`);
|
|
1134
|
+
const w = (e.Arguments || []).map(
|
|
1135
|
+
(p) => fe(p, t)
|
|
127
1136
|
);
|
|
128
|
-
return
|
|
1137
|
+
return d(...w);
|
|
129
1138
|
case "AssignmentExpression":
|
|
130
|
-
if (!
|
|
1139
|
+
if (!e.Arguments || e.Arguments.length !== 1)
|
|
131
1140
|
throw new Error("AssignmentExpression requires exactly 1 argument");
|
|
132
|
-
return
|
|
1141
|
+
return fe(e.Arguments[0], t);
|
|
133
1142
|
default:
|
|
134
|
-
throw new Error(`Unknown expression type: ${
|
|
1143
|
+
throw new Error(`Unknown expression type: ${e.Type}`);
|
|
135
1144
|
}
|
|
136
1145
|
}
|
|
137
|
-
function
|
|
138
|
-
const { Name: r, Source: s } =
|
|
1146
|
+
function Et(e, t) {
|
|
1147
|
+
const { Name: r, Source: s } = e;
|
|
139
1148
|
if (!r)
|
|
140
1149
|
throw new Error("Identifier requires Name");
|
|
141
1150
|
switch (s) {
|
|
142
1151
|
case "Input":
|
|
143
1152
|
default:
|
|
144
|
-
return
|
|
1153
|
+
return t.formValues[r];
|
|
145
1154
|
}
|
|
146
1155
|
}
|
|
147
|
-
function
|
|
148
|
-
if (!(!
|
|
149
|
-
return t
|
|
1156
|
+
function Ze(e, t) {
|
|
1157
|
+
if (!(!e || typeof e != "object"))
|
|
1158
|
+
return e[t];
|
|
150
1159
|
}
|
|
151
|
-
function
|
|
152
|
-
const s = (
|
|
153
|
-
switch (
|
|
1160
|
+
function mr(e, t, r) {
|
|
1161
|
+
const s = (i) => i == null ? 0 : typeof i == "number" ? i : typeof i == "object" && i !== null && "value" in i ? Number(i.value) || 0 : Number(i) || 0;
|
|
1162
|
+
switch (e) {
|
|
154
1163
|
case "==":
|
|
155
|
-
return
|
|
1164
|
+
return t == r;
|
|
156
1165
|
case "!=":
|
|
157
|
-
return
|
|
1166
|
+
return t != r;
|
|
158
1167
|
case ">":
|
|
159
|
-
return s(
|
|
1168
|
+
return s(t) > s(r);
|
|
160
1169
|
case "<":
|
|
161
|
-
return s(
|
|
1170
|
+
return s(t) < s(r);
|
|
162
1171
|
case ">=":
|
|
163
|
-
return s(
|
|
1172
|
+
return s(t) >= s(r);
|
|
164
1173
|
case "<=":
|
|
165
|
-
return s(
|
|
1174
|
+
return s(t) <= s(r);
|
|
166
1175
|
case "+":
|
|
167
|
-
return s(
|
|
1176
|
+
return s(t) + s(r);
|
|
168
1177
|
case "-":
|
|
169
|
-
return s(
|
|
1178
|
+
return s(t) - s(r);
|
|
170
1179
|
case "*":
|
|
171
|
-
return s(
|
|
1180
|
+
return s(t) * s(r);
|
|
172
1181
|
case "/":
|
|
173
|
-
const
|
|
174
|
-
return
|
|
1182
|
+
const i = s(r);
|
|
1183
|
+
return i !== 0 ? s(t) / i : 0;
|
|
175
1184
|
default:
|
|
176
|
-
throw new Error(`Unknown binary operator: ${
|
|
1185
|
+
throw new Error(`Unknown binary operator: ${e}`);
|
|
177
1186
|
}
|
|
178
1187
|
}
|
|
179
|
-
function
|
|
180
|
-
switch (
|
|
1188
|
+
function yr(e, t, r) {
|
|
1189
|
+
switch (e) {
|
|
181
1190
|
case "AND":
|
|
182
|
-
return
|
|
1191
|
+
return t.every((s) => !!fe(s, r));
|
|
183
1192
|
case "OR":
|
|
184
|
-
return
|
|
1193
|
+
return t.some((s) => !!fe(s, r));
|
|
185
1194
|
default:
|
|
186
|
-
throw new Error(`Unknown logical operator: ${
|
|
1195
|
+
throw new Error(`Unknown logical operator: ${e}`);
|
|
187
1196
|
}
|
|
188
1197
|
}
|
|
189
|
-
function
|
|
1198
|
+
function Mt(e, t, r = {}) {
|
|
190
1199
|
const s = {
|
|
191
|
-
formValues:
|
|
192
|
-
systemValues:
|
|
1200
|
+
formValues: t,
|
|
1201
|
+
systemValues: fr(),
|
|
193
1202
|
referenceData: r
|
|
194
1203
|
};
|
|
195
1204
|
try {
|
|
196
|
-
return
|
|
197
|
-
} catch (
|
|
198
|
-
return console.warn("Expression evaluation failed:",
|
|
1205
|
+
return fe(e, s);
|
|
1206
|
+
} catch (i) {
|
|
1207
|
+
return console.warn("Expression evaluation failed:", i), !1;
|
|
199
1208
|
}
|
|
200
1209
|
}
|
|
201
|
-
function
|
|
1210
|
+
function At(e, t, r = {}) {
|
|
202
1211
|
const s = [];
|
|
203
|
-
for (const
|
|
1212
|
+
for (const i of e)
|
|
204
1213
|
try {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
1214
|
+
Mt(
|
|
1215
|
+
i.Condition.ExpressionTree,
|
|
1216
|
+
t,
|
|
208
1217
|
r
|
|
209
1218
|
) || s.push({
|
|
210
1219
|
isValid: !1,
|
|
211
|
-
message:
|
|
212
|
-
fieldName:
|
|
1220
|
+
message: i.Message,
|
|
1221
|
+
fieldName: i.Id
|
|
213
1222
|
});
|
|
214
1223
|
} catch (n) {
|
|
215
|
-
console.warn(`Cross-field validation rule ${
|
|
1224
|
+
console.warn(`Cross-field validation rule ${i.Id} failed:`, n);
|
|
216
1225
|
}
|
|
217
1226
|
return s;
|
|
218
1227
|
}
|
|
219
|
-
function
|
|
1228
|
+
function gr(e, t = {}, r = {}) {
|
|
220
1229
|
try {
|
|
221
|
-
return
|
|
1230
|
+
return Mt(e, t, r);
|
|
222
1231
|
} catch (s) {
|
|
223
1232
|
return console.warn("Default value calculation failed:", s), null;
|
|
224
1233
|
}
|
|
225
1234
|
}
|
|
226
|
-
function
|
|
227
|
-
var
|
|
228
|
-
const r = ((
|
|
229
|
-
return s.includes("required") ||
|
|
1235
|
+
function xt(e, t) {
|
|
1236
|
+
var d, w, p;
|
|
1237
|
+
const r = ((d = e.Expression) == null ? void 0 : d.toLowerCase()) || "", s = ((w = e.Name) == null ? void 0 : w.toLowerCase()) || "", i = ((p = e.Id) == null ? void 0 : p.toLowerCase()) || "", n = t.toLowerCase();
|
|
1238
|
+
return s.includes("required") || i.includes("required") ? !0 : [
|
|
230
1239
|
`${n} != null`,
|
|
231
1240
|
`${n} != ''`,
|
|
232
1241
|
`trim(${n}) != ''`,
|
|
@@ -234,124 +1243,124 @@ function de(t, e) {
|
|
|
234
1243
|
`${n}!=''`
|
|
235
1244
|
].some((N) => r.includes(N));
|
|
236
1245
|
}
|
|
237
|
-
function
|
|
238
|
-
const
|
|
239
|
-
|
|
1246
|
+
function pr(e) {
|
|
1247
|
+
const t = { ...e };
|
|
1248
|
+
t.Rules || (t.Rules = {
|
|
240
1249
|
Validation: {},
|
|
241
1250
|
Computation: {},
|
|
242
1251
|
BusinessLogic: {}
|
|
243
|
-
}),
|
|
244
|
-
const r = { ...
|
|
245
|
-
return Object.entries(r).forEach(([s,
|
|
246
|
-
let n =
|
|
247
|
-
if (
|
|
248
|
-
if (
|
|
249
|
-
const
|
|
250
|
-
|
|
251
|
-
|
|
1252
|
+
}), t.Rules.Validation || (t.Rules.Validation = {}), t.Rules.Computation || (t.Rules.Computation = {}), t.Rules.BusinessLogic || (t.Rules.BusinessLogic = {});
|
|
1253
|
+
const r = { ...t.Fields };
|
|
1254
|
+
return Object.entries(r).forEach(([s, i]) => {
|
|
1255
|
+
let n = i.Required || !1;
|
|
1256
|
+
if (i.Validation && Array.isArray(i.Validation))
|
|
1257
|
+
if (i.Validation.length > 0 && typeof i.Validation[0] == "object") {
|
|
1258
|
+
const l = [];
|
|
1259
|
+
i.Validation.forEach((d) => {
|
|
1260
|
+
t.Rules.Validation[d.Id] = d, l.push(d.Id), xt(d, s) && (n = !0);
|
|
252
1261
|
}), r[s] = {
|
|
253
|
-
...
|
|
254
|
-
Validation:
|
|
1262
|
+
...i,
|
|
1263
|
+
Validation: l,
|
|
255
1264
|
Required: n
|
|
256
1265
|
};
|
|
257
1266
|
} else
|
|
258
|
-
|
|
259
|
-
var
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
}), n && !
|
|
263
|
-
...
|
|
1267
|
+
i.Validation.forEach((d) => {
|
|
1268
|
+
var p;
|
|
1269
|
+
const w = (p = t.Rules.Validation) == null ? void 0 : p[d];
|
|
1270
|
+
w && xt(w, s) && (n = !0);
|
|
1271
|
+
}), n && !i.Required && (r[s] = {
|
|
1272
|
+
...i,
|
|
264
1273
|
Required: !0
|
|
265
1274
|
});
|
|
266
|
-
if (
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
Id:
|
|
270
|
-
Name:
|
|
271
|
-
Description:
|
|
272
|
-
Expression:
|
|
273
|
-
ExpressionTree:
|
|
274
|
-
ResultType:
|
|
1275
|
+
if (i.Formula) {
|
|
1276
|
+
const l = `RULE_COMPUTE_${s.toUpperCase()}`;
|
|
1277
|
+
t.Rules.Computation[l] = {
|
|
1278
|
+
Id: l,
|
|
1279
|
+
Name: i.Formula.Id || `Compute ${s}`,
|
|
1280
|
+
Description: i.Formula.Description || `Computes value for ${s}`,
|
|
1281
|
+
Expression: i.Formula.Expression,
|
|
1282
|
+
ExpressionTree: i.Formula.ExpressionTree,
|
|
1283
|
+
ResultType: i.Type
|
|
275
1284
|
};
|
|
276
1285
|
}
|
|
277
|
-
}),
|
|
1286
|
+
}), t.Fields = r, t;
|
|
278
1287
|
}
|
|
279
|
-
function
|
|
280
|
-
var r, s,
|
|
281
|
-
const
|
|
1288
|
+
function br(e) {
|
|
1289
|
+
var r, s, i;
|
|
1290
|
+
const t = {
|
|
282
1291
|
validation: {},
|
|
283
1292
|
computation: {},
|
|
284
1293
|
businessLogic: {}
|
|
285
1294
|
};
|
|
286
|
-
return (r =
|
|
1295
|
+
return (r = e.Rules) != null && r.Validation && (t.validation = { ...e.Rules.Validation }), (s = e.Rules) != null && s.Computation && (t.computation = { ...e.Rules.Computation }), (i = e.Rules) != null && i.BusinessLogic && (t.businessLogic = { ...e.Rules.BusinessLogic }), t;
|
|
287
1296
|
}
|
|
288
|
-
function
|
|
1297
|
+
function wr(e) {
|
|
289
1298
|
var s;
|
|
290
|
-
const
|
|
291
|
-
if (!((s =
|
|
292
|
-
const r = Object.entries(
|
|
293
|
-
return r.sort((
|
|
294
|
-
const
|
|
295
|
-
for (const
|
|
296
|
-
const
|
|
297
|
-
if (
|
|
298
|
-
|
|
1299
|
+
const t = {};
|
|
1300
|
+
if (!((s = e.Rules) != null && s.Computation)) return t;
|
|
1301
|
+
const r = Object.entries(e.Fields).filter(([i, n]) => n.Computed).map(([i]) => i);
|
|
1302
|
+
return r.sort((i, n) => n.length - i.length), Object.entries(e.Rules.Computation).forEach(([i, n]) => {
|
|
1303
|
+
const l = i.toUpperCase().replace(/[_-]/g, "");
|
|
1304
|
+
for (const w of r) {
|
|
1305
|
+
const p = w.toUpperCase().replace(/[_-]/g, "");
|
|
1306
|
+
if (l.includes(p)) {
|
|
1307
|
+
t[i] = w;
|
|
299
1308
|
return;
|
|
300
1309
|
}
|
|
301
1310
|
}
|
|
302
|
-
const
|
|
303
|
-
for (const
|
|
304
|
-
if (
|
|
305
|
-
|
|
1311
|
+
const d = `${n.Name || ""} ${n.Description || ""}`.toLowerCase();
|
|
1312
|
+
for (const w of r)
|
|
1313
|
+
if (d.includes(w.toLowerCase())) {
|
|
1314
|
+
t[i] = w;
|
|
306
1315
|
return;
|
|
307
1316
|
}
|
|
308
|
-
}),
|
|
1317
|
+
}), t;
|
|
309
1318
|
}
|
|
310
|
-
function
|
|
1319
|
+
function vr(e, t) {
|
|
311
1320
|
const r = {};
|
|
312
|
-
Object.keys(
|
|
313
|
-
r[
|
|
1321
|
+
Object.keys(e.Fields).forEach((i) => {
|
|
1322
|
+
r[i] = {
|
|
314
1323
|
validation: [],
|
|
315
1324
|
computation: [],
|
|
316
1325
|
businessLogic: []
|
|
317
1326
|
};
|
|
318
|
-
}), Object.entries(
|
|
319
|
-
n.Validation && Array.isArray(n.Validation) && n.Validation.forEach((
|
|
320
|
-
|
|
321
|
-
}), n.Formula && Object.entries(
|
|
322
|
-
var
|
|
323
|
-
|
|
1327
|
+
}), Object.entries(e.Fields).forEach(([i, n]) => {
|
|
1328
|
+
n.Validation && Array.isArray(n.Validation) && n.Validation.forEach((d) => {
|
|
1329
|
+
t.validation[d] ? r[i].validation.push(d) : t.computation[d] ? r[i].computation.push(d) : t.businessLogic[d] && r[i].businessLogic.push(d);
|
|
1330
|
+
}), n.Formula && Object.entries(t.computation).forEach(([l, d]) => {
|
|
1331
|
+
var w;
|
|
1332
|
+
d.Expression === ((w = n.Formula) == null ? void 0 : w.Expression) && (r[i].computation.includes(l) || r[i].computation.push(l));
|
|
324
1333
|
});
|
|
325
1334
|
});
|
|
326
|
-
const s =
|
|
327
|
-
return Object.entries(s).forEach(([
|
|
328
|
-
r[n] && !r[n].computation.includes(
|
|
1335
|
+
const s = wr(e);
|
|
1336
|
+
return Object.entries(s).forEach(([i, n]) => {
|
|
1337
|
+
r[n] && !r[n].computation.includes(i) && r[n].computation.push(i);
|
|
329
1338
|
}), r;
|
|
330
1339
|
}
|
|
331
|
-
function
|
|
1340
|
+
function Fr(e, t) {
|
|
332
1341
|
const r = {}, s = {
|
|
333
1342
|
editable: !0,
|
|
334
1343
|
readable: !0,
|
|
335
1344
|
hidden: !1
|
|
336
1345
|
};
|
|
337
|
-
return Object.keys(
|
|
338
|
-
var
|
|
339
|
-
if (!
|
|
340
|
-
r[
|
|
1346
|
+
return Object.keys(e.Fields).forEach((i) => {
|
|
1347
|
+
var w, p, N, D, v, m;
|
|
1348
|
+
if (!t || !((w = e.RolePermission) != null && w[t])) {
|
|
1349
|
+
r[i] = s;
|
|
341
1350
|
return;
|
|
342
1351
|
}
|
|
343
|
-
const n =
|
|
344
|
-
r[
|
|
345
|
-
editable:
|
|
346
|
-
readable:
|
|
347
|
-
hidden: !
|
|
1352
|
+
const n = e.RolePermission[t], l = ((p = n.Editable) == null ? void 0 : p.includes(i)) || ((N = n.Editable) == null ? void 0 : N.includes("*")) || !1, d = ((D = n.ReadOnly) == null ? void 0 : D.includes(i)) || ((v = n.ReadOnly) == null ? void 0 : v.includes("*")) || l;
|
|
1353
|
+
r[i] = {
|
|
1354
|
+
editable: l && !((m = n.ReadOnly) != null && m.includes(i)),
|
|
1355
|
+
readable: d,
|
|
1356
|
+
hidden: !d
|
|
348
1357
|
};
|
|
349
1358
|
}), r;
|
|
350
1359
|
}
|
|
351
|
-
function
|
|
352
|
-
switch (
|
|
1360
|
+
function Vr(e, t) {
|
|
1361
|
+
switch (e) {
|
|
353
1362
|
case "String":
|
|
354
|
-
return
|
|
1363
|
+
return t.toLowerCase().includes("email") ? "email" : t.toLowerCase().includes("password") ? "password" : "text";
|
|
355
1364
|
case "Number":
|
|
356
1365
|
return "number";
|
|
357
1366
|
case "Boolean":
|
|
@@ -369,15 +1378,15 @@ function Ge(t, e) {
|
|
|
369
1378
|
return "text";
|
|
370
1379
|
}
|
|
371
1380
|
}
|
|
372
|
-
function
|
|
373
|
-
return
|
|
1381
|
+
function It(e) {
|
|
1382
|
+
return e.replace(/([A-Z])/g, " $1").replace(/^./, (t) => t.toUpperCase()).replace(/_/g, " ").trim();
|
|
374
1383
|
}
|
|
375
|
-
function
|
|
1384
|
+
function Er(e, t, r) {
|
|
376
1385
|
const s = {};
|
|
377
|
-
switch (
|
|
1386
|
+
switch (t.Required && (s.required = {
|
|
378
1387
|
value: !0,
|
|
379
|
-
message: `${
|
|
380
|
-
}),
|
|
1388
|
+
message: `${It(e)} is required`
|
|
1389
|
+
}), t.Type) {
|
|
381
1390
|
case "Number":
|
|
382
1391
|
s.valueAsNumber = !0;
|
|
383
1392
|
break;
|
|
@@ -386,17 +1395,17 @@ function Xe(t, e, r) {
|
|
|
386
1395
|
s.valueAsDate = !0;
|
|
387
1396
|
break;
|
|
388
1397
|
}
|
|
389
|
-
return
|
|
1398
|
+
return t.Validation && t.Validation.length > 0 && (s.validate = () => !0), s;
|
|
390
1399
|
}
|
|
391
|
-
function
|
|
392
|
-
return
|
|
393
|
-
value:
|
|
394
|
-
label:
|
|
395
|
-
})) :
|
|
1400
|
+
function Ar(e) {
|
|
1401
|
+
return e.Values ? e.Values.Mode === "Static" && e.Values.Items ? e.Values.Items.map((t) => ({
|
|
1402
|
+
value: t.Value,
|
|
1403
|
+
label: t.Label
|
|
1404
|
+
})) : e.Values.Mode === "Dynamic" && e.Values.Reference ? [] : [] : [];
|
|
396
1405
|
}
|
|
397
|
-
function
|
|
398
|
-
if (!
|
|
399
|
-
switch (
|
|
1406
|
+
function xr(e, t = {}) {
|
|
1407
|
+
if (!e.DefaultValue)
|
|
1408
|
+
switch (e.Type) {
|
|
400
1409
|
case "Boolean":
|
|
401
1410
|
return !1;
|
|
402
1411
|
case "Number":
|
|
@@ -410,272 +1419,272 @@ function Ze(t, e = {}) {
|
|
|
410
1419
|
default:
|
|
411
1420
|
return;
|
|
412
1421
|
}
|
|
413
|
-
return
|
|
414
|
-
|
|
415
|
-
|
|
1422
|
+
return gr(
|
|
1423
|
+
e.DefaultValue.ExpressionTree,
|
|
1424
|
+
t
|
|
416
1425
|
);
|
|
417
1426
|
}
|
|
418
|
-
function
|
|
419
|
-
const
|
|
1427
|
+
function _r(e, t, r, s = {}, i, n) {
|
|
1428
|
+
const l = {
|
|
420
1429
|
editable: !0,
|
|
421
1430
|
readable: !0,
|
|
422
1431
|
hidden: !1
|
|
423
|
-
},
|
|
1432
|
+
}, w = n || {
|
|
424
1433
|
validation: [],
|
|
425
1434
|
computation: [],
|
|
426
1435
|
businessLogic: []
|
|
427
|
-
},
|
|
428
|
-
return
|
|
429
|
-
name:
|
|
430
|
-
type:
|
|
431
|
-
label:
|
|
432
|
-
required:
|
|
433
|
-
computed:
|
|
434
|
-
defaultValue:
|
|
435
|
-
options:
|
|
1436
|
+
}, p = t.Computed || !!t.Formula || w.computation.length > 0, N = Er(e, t);
|
|
1437
|
+
return p && (N.disabled = !0), {
|
|
1438
|
+
name: e,
|
|
1439
|
+
type: Vr(t.Type, e),
|
|
1440
|
+
label: t.Name || It(e),
|
|
1441
|
+
required: t.Required || !1,
|
|
1442
|
+
computed: p,
|
|
1443
|
+
defaultValue: xr(t, s),
|
|
1444
|
+
options: Ar(t),
|
|
436
1445
|
validation: N,
|
|
437
|
-
description:
|
|
438
|
-
_bdoField:
|
|
439
|
-
permission:
|
|
440
|
-
rules:
|
|
1446
|
+
description: t.Description,
|
|
1447
|
+
_bdoField: t,
|
|
1448
|
+
permission: i || l,
|
|
1449
|
+
rules: w
|
|
441
1450
|
};
|
|
442
1451
|
}
|
|
443
|
-
function
|
|
444
|
-
let s =
|
|
445
|
-
s =
|
|
446
|
-
const
|
|
447
|
-
for (const [
|
|
448
|
-
if (
|
|
1452
|
+
function Dr(e, t = {}, r) {
|
|
1453
|
+
let s = e;
|
|
1454
|
+
s = pr(s);
|
|
1455
|
+
const i = {}, n = [], l = [], d = [], w = [], p = br(s), N = vr(s, p), D = Fr(s, r);
|
|
1456
|
+
for (const [v, m] of Object.entries(s.Fields)) {
|
|
1457
|
+
if (v.startsWith("_") && !["_id"].includes(v))
|
|
449
1458
|
continue;
|
|
450
|
-
const
|
|
451
|
-
if (
|
|
1459
|
+
const K = D[v];
|
|
1460
|
+
if (K.hidden)
|
|
452
1461
|
continue;
|
|
453
|
-
const
|
|
454
|
-
|
|
455
|
-
|
|
1462
|
+
const O = _r(
|
|
1463
|
+
v,
|
|
1464
|
+
m,
|
|
456
1465
|
s.Fields,
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
N[
|
|
1466
|
+
t,
|
|
1467
|
+
K,
|
|
1468
|
+
N[v] || {
|
|
460
1469
|
validation: [],
|
|
461
1470
|
computation: [],
|
|
462
1471
|
businessLogic: []
|
|
463
1472
|
}
|
|
464
1473
|
);
|
|
465
|
-
|
|
1474
|
+
i[v] = O, n.push(v), O.computed && l.push(v), O.required && d.push(v);
|
|
466
1475
|
}
|
|
467
1476
|
return {
|
|
468
|
-
fields:
|
|
1477
|
+
fields: i,
|
|
469
1478
|
fieldOrder: n,
|
|
470
|
-
computedFields:
|
|
471
|
-
requiredFields:
|
|
472
|
-
crossFieldValidation:
|
|
473
|
-
rules:
|
|
1479
|
+
computedFields: l,
|
|
1480
|
+
requiredFields: d,
|
|
1481
|
+
crossFieldValidation: w,
|
|
1482
|
+
rules: p,
|
|
474
1483
|
fieldRules: N,
|
|
475
1484
|
rolePermissions: s.RolePermission
|
|
476
1485
|
};
|
|
477
1486
|
}
|
|
478
|
-
function
|
|
1487
|
+
function Sr(e) {
|
|
479
1488
|
var r;
|
|
480
|
-
if (
|
|
1489
|
+
if (e.type !== "reference" || !((r = e._bdoField.Values) != null && r.Reference))
|
|
481
1490
|
return null;
|
|
482
|
-
const
|
|
1491
|
+
const t = e._bdoField.Values.Reference;
|
|
483
1492
|
return {
|
|
484
|
-
businessObject:
|
|
485
|
-
fields:
|
|
1493
|
+
businessObject: t.BusinessObject,
|
|
1494
|
+
fields: t.Fields || ["_id"],
|
|
486
1495
|
// Default to ID field
|
|
487
|
-
filters:
|
|
488
|
-
sort:
|
|
1496
|
+
filters: t.Filters,
|
|
1497
|
+
sort: t.Sort
|
|
489
1498
|
};
|
|
490
1499
|
}
|
|
491
|
-
function
|
|
492
|
-
const
|
|
493
|
-
for (const [r, s] of Object.entries(
|
|
1500
|
+
function Rr(e) {
|
|
1501
|
+
const t = {};
|
|
1502
|
+
for (const [r, s] of Object.entries(e.fields))
|
|
494
1503
|
if (s.type === "reference") {
|
|
495
|
-
const
|
|
496
|
-
|
|
1504
|
+
const i = Sr(s);
|
|
1505
|
+
i && (t[r] = i);
|
|
497
1506
|
}
|
|
498
|
-
return
|
|
1507
|
+
return t;
|
|
499
1508
|
}
|
|
500
|
-
async function
|
|
1509
|
+
async function Nr(e) {
|
|
501
1510
|
try {
|
|
502
|
-
const r = (await
|
|
1511
|
+
const r = (await qt(e)).BOBlob;
|
|
503
1512
|
if (!r || typeof r != "object" || !r.Fields)
|
|
504
|
-
throw new Error(`Invalid BDO schema response for ${
|
|
1513
|
+
throw new Error(`Invalid BDO schema response for ${e}`);
|
|
505
1514
|
return r;
|
|
506
|
-
} catch (
|
|
507
|
-
throw console.error(`Schema fetch error for ${
|
|
508
|
-
`Failed to load form schema: ${
|
|
1515
|
+
} catch (t) {
|
|
1516
|
+
throw console.error(`Schema fetch error for ${e}:`, t), new Error(
|
|
1517
|
+
`Failed to load form schema: ${t instanceof Error ? t.message : "Unknown error"}`
|
|
509
1518
|
);
|
|
510
1519
|
}
|
|
511
1520
|
}
|
|
512
|
-
async function
|
|
1521
|
+
async function Or(e, t = 3) {
|
|
513
1522
|
let r;
|
|
514
|
-
for (let s = 1; s <=
|
|
1523
|
+
for (let s = 1; s <= t; s++)
|
|
515
1524
|
try {
|
|
516
|
-
return await
|
|
517
|
-
} catch (
|
|
518
|
-
if (r =
|
|
1525
|
+
return await Nr(e);
|
|
1526
|
+
} catch (i) {
|
|
1527
|
+
if (r = i, s < t) {
|
|
519
1528
|
const n = Math.min(1e3 * Math.pow(2, s - 1), 5e3);
|
|
520
|
-
await new Promise((
|
|
1529
|
+
await new Promise((l) => setTimeout(l, n));
|
|
521
1530
|
continue;
|
|
522
1531
|
}
|
|
523
1532
|
}
|
|
524
1533
|
throw r;
|
|
525
1534
|
}
|
|
526
|
-
async function
|
|
1535
|
+
async function Cr(e, t) {
|
|
527
1536
|
try {
|
|
528
|
-
return await
|
|
1537
|
+
return await pe(e).get(t);
|
|
529
1538
|
} catch (r) {
|
|
530
|
-
throw console.error(`Record fetch error for ${
|
|
1539
|
+
throw console.error(`Record fetch error for ${e}/${t}:`, r), new Error(
|
|
531
1540
|
`Failed to load record: ${r instanceof Error ? r.message : "Unknown error"}`
|
|
532
1541
|
);
|
|
533
1542
|
}
|
|
534
1543
|
}
|
|
535
|
-
async function
|
|
1544
|
+
async function Tr(e, t, r, s) {
|
|
536
1545
|
try {
|
|
537
|
-
let
|
|
538
|
-
if (
|
|
539
|
-
return
|
|
1546
|
+
let i;
|
|
1547
|
+
if (t === "create")
|
|
1548
|
+
return i = await pe(e).create(r), {
|
|
540
1549
|
success: !0,
|
|
541
|
-
data:
|
|
542
|
-
recordId:
|
|
1550
|
+
data: i,
|
|
1551
|
+
recordId: i._id || s
|
|
543
1552
|
};
|
|
544
|
-
if (
|
|
1553
|
+
if (t === "update") {
|
|
545
1554
|
if (!s)
|
|
546
1555
|
throw new Error("Record ID is required for update operations");
|
|
547
|
-
return
|
|
1556
|
+
return i = await pe(e).update(s, r), {
|
|
548
1557
|
success: !0,
|
|
549
|
-
data:
|
|
550
|
-
recordId:
|
|
1558
|
+
data: i,
|
|
1559
|
+
recordId: i._id || s
|
|
551
1560
|
};
|
|
552
1561
|
} else
|
|
553
|
-
throw new Error(`Unsupported operation: ${
|
|
554
|
-
} catch (
|
|
555
|
-
return console.error("Form submission error:",
|
|
1562
|
+
throw new Error(`Unsupported operation: ${t}`);
|
|
1563
|
+
} catch (i) {
|
|
1564
|
+
return console.error("Form submission error:", i), {
|
|
556
1565
|
success: !1,
|
|
557
1566
|
error: new Error(
|
|
558
|
-
`Failed to ${
|
|
1567
|
+
`Failed to ${t} record: ${i instanceof Error ? i.message : "Unknown error"}`
|
|
559
1568
|
)
|
|
560
1569
|
};
|
|
561
1570
|
}
|
|
562
1571
|
}
|
|
563
|
-
async function
|
|
1572
|
+
async function Lr(e, t = ["_id"], r, s) {
|
|
564
1573
|
try {
|
|
565
|
-
const
|
|
566
|
-
return r && (
|
|
567
|
-
} catch (
|
|
568
|
-
return console.error(`Reference data fetch error for ${
|
|
1574
|
+
const i = {};
|
|
1575
|
+
return r && (i.Filter = r), s && (i.Sort = s), t.length > 0 && (i.Field = t), (await pe(e).list(i)).Data || [];
|
|
1576
|
+
} catch (i) {
|
|
1577
|
+
return console.error(`Reference data fetch error for ${e}:`, i), [];
|
|
569
1578
|
}
|
|
570
1579
|
}
|
|
571
|
-
async function
|
|
572
|
-
const
|
|
573
|
-
async ([
|
|
1580
|
+
async function Mr(e) {
|
|
1581
|
+
const t = {}, r = Object.entries(e).map(
|
|
1582
|
+
async ([i, n]) => {
|
|
574
1583
|
try {
|
|
575
|
-
const
|
|
1584
|
+
const l = await Lr(
|
|
576
1585
|
n.businessObject,
|
|
577
1586
|
n.fields,
|
|
578
1587
|
n.filters,
|
|
579
1588
|
n.sort
|
|
580
1589
|
);
|
|
581
|
-
return [
|
|
582
|
-
} catch (
|
|
583
|
-
return console.warn(`Failed to fetch reference data for ${
|
|
1590
|
+
return [i, l];
|
|
1591
|
+
} catch (l) {
|
|
1592
|
+
return console.warn(`Failed to fetch reference data for ${i}:`, l), [i, []];
|
|
584
1593
|
}
|
|
585
1594
|
}
|
|
586
1595
|
);
|
|
587
|
-
return (await Promise.allSettled(r)).forEach((
|
|
588
|
-
if (
|
|
589
|
-
const [n,
|
|
590
|
-
|
|
1596
|
+
return (await Promise.allSettled(r)).forEach((i) => {
|
|
1597
|
+
if (i.status === "fulfilled") {
|
|
1598
|
+
const [n, l] = i.value;
|
|
1599
|
+
t[n] = Array.isArray(l) ? l : [];
|
|
591
1600
|
}
|
|
592
|
-
}),
|
|
1601
|
+
}), t;
|
|
593
1602
|
}
|
|
594
|
-
function
|
|
595
|
-
const
|
|
596
|
-
return Object.keys(
|
|
597
|
-
const
|
|
598
|
-
if (!
|
|
1603
|
+
function Ir(e, t, r = "create", s) {
|
|
1604
|
+
const i = {};
|
|
1605
|
+
return Object.keys(e).forEach((n) => {
|
|
1606
|
+
const l = n, d = e[l];
|
|
1607
|
+
if (!t.includes(n) && d !== void 0) {
|
|
599
1608
|
if (r === "create") {
|
|
600
|
-
|
|
1609
|
+
i[l] = d;
|
|
601
1610
|
return;
|
|
602
1611
|
}
|
|
603
1612
|
if (r === "update") {
|
|
604
1613
|
if (!s) {
|
|
605
|
-
|
|
1614
|
+
i[l] = d;
|
|
606
1615
|
return;
|
|
607
1616
|
}
|
|
608
|
-
const
|
|
609
|
-
JSON.stringify(
|
|
1617
|
+
const w = s[l];
|
|
1618
|
+
JSON.stringify(d) !== JSON.stringify(w) && (i[l] = d);
|
|
610
1619
|
}
|
|
611
1620
|
}
|
|
612
|
-
}),
|
|
1621
|
+
}), i;
|
|
613
1622
|
}
|
|
614
|
-
function
|
|
615
|
-
var
|
|
616
|
-
return typeof
|
|
1623
|
+
function zr(e) {
|
|
1624
|
+
var t, r, s, i;
|
|
1625
|
+
return typeof e == "string" ? e : e != null && e.message ? e.message : (r = (t = e == null ? void 0 : e.response) == null ? void 0 : t.data) != null && r.message ? e.response.data.message : (i = (s = e == null ? void 0 : e.response) == null ? void 0 : s.data) != null && i.error ? e.response.data.error : "An unexpected error occurred";
|
|
617
1626
|
}
|
|
618
|
-
function
|
|
619
|
-
var
|
|
620
|
-
return !navigator.onLine || (
|
|
1627
|
+
function Jr(e) {
|
|
1628
|
+
var t, r;
|
|
1629
|
+
return !navigator.onLine || (e == null ? void 0 : e.code) === "NETWORK_ERROR" || ((t = e == null ? void 0 : e.message) == null ? void 0 : t.toLowerCase().includes("network")) || ((r = e == null ? void 0 : e.message) == null ? void 0 : r.toLowerCase().includes("fetch"));
|
|
621
1630
|
}
|
|
622
|
-
function
|
|
623
|
-
var
|
|
624
|
-
return (
|
|
1631
|
+
function Gr(e) {
|
|
1632
|
+
var t, r, s;
|
|
1633
|
+
return (e == null ? void 0 : e.status) === 400 || ((t = e == null ? void 0 : e.response) == null ? void 0 : t.status) === 400 || ((r = e == null ? void 0 : e.message) == null ? void 0 : r.toLowerCase().includes("validation")) || ((s = e == null ? void 0 : e.message) == null ? void 0 : s.toLowerCase().includes("invalid"));
|
|
625
1634
|
}
|
|
626
|
-
const
|
|
627
|
-
function
|
|
628
|
-
|
|
629
|
-
data:
|
|
1635
|
+
const Ve = /* @__PURE__ */ new Map();
|
|
1636
|
+
function kr(e, t, r = 10) {
|
|
1637
|
+
Ve.set(e, {
|
|
1638
|
+
data: t,
|
|
630
1639
|
timestamp: Date.now(),
|
|
631
1640
|
ttl: r * 60 * 1e3
|
|
632
1641
|
});
|
|
633
1642
|
}
|
|
634
|
-
function
|
|
635
|
-
const
|
|
636
|
-
return
|
|
1643
|
+
function Ur(e) {
|
|
1644
|
+
const t = Ve.get(e);
|
|
1645
|
+
return t ? Date.now() - t.timestamp > t.ttl ? (Ve.delete(e), null) : t.data : null;
|
|
637
1646
|
}
|
|
638
|
-
function
|
|
639
|
-
|
|
640
|
-
(r) => r.startsWith(
|
|
641
|
-
).forEach((r) =>
|
|
1647
|
+
function Xr(e) {
|
|
1648
|
+
e ? Array.from(Ve.keys()).filter(
|
|
1649
|
+
(r) => r.startsWith(e)
|
|
1650
|
+
).forEach((r) => Ve.delete(r)) : Ve.clear();
|
|
642
1651
|
}
|
|
643
|
-
async function
|
|
644
|
-
const
|
|
1652
|
+
async function Br(e) {
|
|
1653
|
+
const t = `schema:${e}`, r = Ur(t);
|
|
645
1654
|
if (r)
|
|
646
1655
|
return r;
|
|
647
|
-
const s = await
|
|
648
|
-
return
|
|
1656
|
+
const s = await Or(e);
|
|
1657
|
+
return kr(t, s, 30), s;
|
|
649
1658
|
}
|
|
650
|
-
class
|
|
651
|
-
constructor(
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
this.maxSize =
|
|
1659
|
+
class _t {
|
|
1660
|
+
constructor(t = 1e3) {
|
|
1661
|
+
we(this, "cache", /* @__PURE__ */ new Map());
|
|
1662
|
+
we(this, "maxSize");
|
|
1663
|
+
this.maxSize = t;
|
|
655
1664
|
}
|
|
656
|
-
get(
|
|
657
|
-
const r = this.cache.get(
|
|
658
|
-
return r !== void 0 && (this.cache.delete(
|
|
1665
|
+
get(t) {
|
|
1666
|
+
const r = this.cache.get(t);
|
|
1667
|
+
return r !== void 0 && (this.cache.delete(t), this.cache.set(t, r)), r;
|
|
659
1668
|
}
|
|
660
|
-
set(
|
|
661
|
-
if (this.cache.has(
|
|
662
|
-
this.cache.delete(
|
|
1669
|
+
set(t, r) {
|
|
1670
|
+
if (this.cache.has(t))
|
|
1671
|
+
this.cache.delete(t);
|
|
663
1672
|
else if (this.cache.size >= this.maxSize) {
|
|
664
1673
|
const s = this.cache.keys().next().value;
|
|
665
1674
|
this.cache.delete(s);
|
|
666
1675
|
}
|
|
667
|
-
this.cache.set(
|
|
1676
|
+
this.cache.set(t, r);
|
|
668
1677
|
}
|
|
669
1678
|
clear() {
|
|
670
1679
|
this.cache.clear();
|
|
671
1680
|
}
|
|
672
1681
|
}
|
|
673
|
-
function
|
|
674
|
-
const
|
|
1682
|
+
function Pr(e) {
|
|
1683
|
+
const t = /* @__PURE__ */ new Set();
|
|
675
1684
|
function r(s) {
|
|
676
1685
|
switch (s.Type) {
|
|
677
1686
|
case "Identifier":
|
|
678
|
-
s.Name && !s.Name.startsWith("$") &&
|
|
1687
|
+
s.Name && !s.Name.startsWith("$") && t.add(s.Name);
|
|
679
1688
|
break;
|
|
680
1689
|
case "MemberExpression":
|
|
681
1690
|
s.Arguments && s.Arguments.forEach(r);
|
|
@@ -687,159 +1696,159 @@ function pt(t) {
|
|
|
687
1696
|
break;
|
|
688
1697
|
}
|
|
689
1698
|
}
|
|
690
|
-
return r(
|
|
1699
|
+
return r(e), t;
|
|
691
1700
|
}
|
|
692
|
-
class
|
|
1701
|
+
class qr {
|
|
693
1702
|
constructor() {
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
1703
|
+
we(this, "resultCache", new _t(500));
|
|
1704
|
+
we(this, "dependencyCache", new _t(200));
|
|
1705
|
+
we(this, "compiledExpressions", /* @__PURE__ */ new Map());
|
|
697
1706
|
}
|
|
698
1707
|
/**
|
|
699
1708
|
* Create cache key from expression and context
|
|
700
1709
|
*/
|
|
701
|
-
createCacheKey(
|
|
702
|
-
const s = JSON.stringify(
|
|
703
|
-
return `${s}:${
|
|
1710
|
+
createCacheKey(t, r) {
|
|
1711
|
+
const s = JSON.stringify(t), i = JSON.stringify(r);
|
|
1712
|
+
return `${s}:${i}`;
|
|
704
1713
|
}
|
|
705
1714
|
/**
|
|
706
1715
|
* Get expression dependencies (cached)
|
|
707
1716
|
*/
|
|
708
|
-
getDependencies(
|
|
709
|
-
const r = JSON.stringify(
|
|
1717
|
+
getDependencies(t) {
|
|
1718
|
+
const r = JSON.stringify(t);
|
|
710
1719
|
let s = this.dependencyCache.get(r);
|
|
711
|
-
return s || (s =
|
|
1720
|
+
return s || (s = Pr(t), this.dependencyCache.set(r, s)), s;
|
|
712
1721
|
}
|
|
713
1722
|
/**
|
|
714
1723
|
* Check if expression result is cached and context hasn't changed
|
|
715
1724
|
*/
|
|
716
|
-
getCachedResult(
|
|
1725
|
+
getCachedResult(t, r, s) {
|
|
717
1726
|
if (!s) return;
|
|
718
|
-
const
|
|
719
|
-
for (const
|
|
720
|
-
if (r[
|
|
1727
|
+
const i = this.getDependencies(t);
|
|
1728
|
+
for (const l of i)
|
|
1729
|
+
if (r[l] !== s[l])
|
|
721
1730
|
return;
|
|
722
|
-
const n = this.createCacheKey(
|
|
1731
|
+
const n = this.createCacheKey(t, r);
|
|
723
1732
|
return this.resultCache.get(n);
|
|
724
1733
|
}
|
|
725
1734
|
/**
|
|
726
1735
|
* Evaluate expression with caching
|
|
727
1736
|
*/
|
|
728
|
-
evaluate(
|
|
729
|
-
const
|
|
730
|
-
if (
|
|
731
|
-
return
|
|
732
|
-
const n = this.evaluateNode(
|
|
733
|
-
return this.resultCache.set(
|
|
1737
|
+
evaluate(t, r, s) {
|
|
1738
|
+
const i = this.getCachedResult(t, r, s);
|
|
1739
|
+
if (i !== void 0)
|
|
1740
|
+
return i;
|
|
1741
|
+
const n = this.evaluateNode(t, r), l = this.createCacheKey(t, r);
|
|
1742
|
+
return this.resultCache.set(l, n), n;
|
|
734
1743
|
}
|
|
735
1744
|
/**
|
|
736
1745
|
* Core expression evaluation logic
|
|
737
1746
|
*/
|
|
738
|
-
evaluateNode(
|
|
739
|
-
switch (
|
|
1747
|
+
evaluateNode(t, r) {
|
|
1748
|
+
switch (t.Type) {
|
|
740
1749
|
case "Literal":
|
|
741
|
-
return
|
|
1750
|
+
return t.Value;
|
|
742
1751
|
case "Identifier":
|
|
743
|
-
return this.getIdentifierValue(
|
|
1752
|
+
return this.getIdentifierValue(t, r);
|
|
744
1753
|
case "BinaryExpression":
|
|
745
|
-
return this.evaluateBinaryExpression(
|
|
1754
|
+
return this.evaluateBinaryExpression(t, r);
|
|
746
1755
|
case "LogicalExpression":
|
|
747
|
-
return this.evaluateLogicalExpression(
|
|
1756
|
+
return this.evaluateLogicalExpression(t, r);
|
|
748
1757
|
case "CallExpression":
|
|
749
|
-
return this.evaluateCallExpression(
|
|
1758
|
+
return this.evaluateCallExpression(t, r);
|
|
750
1759
|
case "MemberExpression":
|
|
751
|
-
return this.evaluateMemberExpression(
|
|
1760
|
+
return this.evaluateMemberExpression(t, r);
|
|
752
1761
|
default:
|
|
753
|
-
throw new Error(`Unsupported expression type: ${
|
|
1762
|
+
throw new Error(`Unsupported expression type: ${t.Type}`);
|
|
754
1763
|
}
|
|
755
1764
|
}
|
|
756
1765
|
/**
|
|
757
1766
|
* Get identifier value with system context support
|
|
758
1767
|
*/
|
|
759
|
-
getIdentifierValue(
|
|
760
|
-
if (
|
|
761
|
-
if (
|
|
762
|
-
if (
|
|
1768
|
+
getIdentifierValue(t, r) {
|
|
1769
|
+
if (t.Name) {
|
|
1770
|
+
if (t.Name === "NOW") return /* @__PURE__ */ new Date();
|
|
1771
|
+
if (t.Name === "TODAY") {
|
|
763
1772
|
const s = /* @__PURE__ */ new Date();
|
|
764
1773
|
return new Date(s.getFullYear(), s.getMonth(), s.getDate());
|
|
765
1774
|
}
|
|
766
|
-
return
|
|
1775
|
+
return t.Name === "CURRENT_USER_ID" ? 1 : t.Name === "CURRENT_USER" ? {
|
|
767
1776
|
EmpId: 1,
|
|
768
1777
|
Email: "user@example.com",
|
|
769
1778
|
FirstName: "John",
|
|
770
1779
|
LastName: "Doe",
|
|
771
1780
|
Role: "User"
|
|
772
|
-
} : r[
|
|
1781
|
+
} : r[t.Name];
|
|
773
1782
|
}
|
|
774
1783
|
}
|
|
775
1784
|
/**
|
|
776
1785
|
* Evaluate binary expressions with type coercion
|
|
777
1786
|
*/
|
|
778
|
-
evaluateBinaryExpression(
|
|
779
|
-
if (!
|
|
1787
|
+
evaluateBinaryExpression(t, r) {
|
|
1788
|
+
if (!t.Arguments || t.Arguments.length !== 2)
|
|
780
1789
|
throw new Error("Binary expression requires exactly 2 arguments");
|
|
781
|
-
const s = this.evaluateNode(
|
|
782
|
-
switch (
|
|
1790
|
+
const s = this.evaluateNode(t.Arguments[0], r), i = this.evaluateNode(t.Arguments[1], r);
|
|
1791
|
+
switch (t.Operator) {
|
|
783
1792
|
case "==":
|
|
784
|
-
return s ==
|
|
1793
|
+
return s == i;
|
|
785
1794
|
case "!=":
|
|
786
|
-
return s !=
|
|
1795
|
+
return s != i;
|
|
787
1796
|
case "===":
|
|
788
|
-
return s ===
|
|
1797
|
+
return s === i;
|
|
789
1798
|
case "!==":
|
|
790
|
-
return s !==
|
|
1799
|
+
return s !== i;
|
|
791
1800
|
case "<":
|
|
792
|
-
return Number(s) < Number(
|
|
1801
|
+
return Number(s) < Number(i);
|
|
793
1802
|
case "<=":
|
|
794
|
-
return Number(s) <= Number(
|
|
1803
|
+
return Number(s) <= Number(i);
|
|
795
1804
|
case ">":
|
|
796
|
-
return Number(s) > Number(
|
|
1805
|
+
return Number(s) > Number(i);
|
|
797
1806
|
case ">=":
|
|
798
|
-
return Number(s) >= Number(
|
|
1807
|
+
return Number(s) >= Number(i);
|
|
799
1808
|
case "+":
|
|
800
|
-
return Number(s) + Number(
|
|
1809
|
+
return Number(s) + Number(i);
|
|
801
1810
|
case "-":
|
|
802
|
-
return Number(s) - Number(
|
|
1811
|
+
return Number(s) - Number(i);
|
|
803
1812
|
case "*":
|
|
804
|
-
return Number(s) * Number(
|
|
1813
|
+
return Number(s) * Number(i);
|
|
805
1814
|
case "/":
|
|
806
|
-
return Number(s) / Number(
|
|
1815
|
+
return Number(s) / Number(i);
|
|
807
1816
|
case "%":
|
|
808
|
-
return Number(s) % Number(
|
|
1817
|
+
return Number(s) % Number(i);
|
|
809
1818
|
default:
|
|
810
|
-
throw new Error(`Unsupported binary operator: ${
|
|
1819
|
+
throw new Error(`Unsupported binary operator: ${t.Operator}`);
|
|
811
1820
|
}
|
|
812
1821
|
}
|
|
813
1822
|
/**
|
|
814
1823
|
* Evaluate logical expressions with short-circuiting
|
|
815
1824
|
*/
|
|
816
|
-
evaluateLogicalExpression(
|
|
817
|
-
if (!
|
|
1825
|
+
evaluateLogicalExpression(t, r) {
|
|
1826
|
+
if (!t.Arguments || t.Arguments.length < 2)
|
|
818
1827
|
throw new Error("Logical expression requires at least 2 arguments");
|
|
819
|
-
switch (
|
|
1828
|
+
switch (t.Operator) {
|
|
820
1829
|
case "AND":
|
|
821
|
-
for (const s of
|
|
1830
|
+
for (const s of t.Arguments)
|
|
822
1831
|
if (!this.evaluateNode(s, r)) return !1;
|
|
823
1832
|
return !0;
|
|
824
1833
|
case "OR":
|
|
825
|
-
for (const s of
|
|
1834
|
+
for (const s of t.Arguments)
|
|
826
1835
|
if (this.evaluateNode(s, r)) return !0;
|
|
827
1836
|
return !1;
|
|
828
1837
|
default:
|
|
829
|
-
throw new Error(`Unsupported logical operator: ${
|
|
1838
|
+
throw new Error(`Unsupported logical operator: ${t.Operator}`);
|
|
830
1839
|
}
|
|
831
1840
|
}
|
|
832
1841
|
/**
|
|
833
1842
|
* Evaluate function calls with built-in functions
|
|
834
1843
|
*/
|
|
835
|
-
evaluateCallExpression(
|
|
836
|
-
var
|
|
837
|
-
if (!
|
|
1844
|
+
evaluateCallExpression(t, r) {
|
|
1845
|
+
var i;
|
|
1846
|
+
if (!t.Callee)
|
|
838
1847
|
throw new Error("Call expression requires a function name");
|
|
839
|
-
const s = ((
|
|
840
|
-
switch (
|
|
1848
|
+
const s = ((i = t.Arguments) == null ? void 0 : i.map((n) => this.evaluateNode(n, r))) || [];
|
|
1849
|
+
switch (t.Callee) {
|
|
841
1850
|
case "CONCAT":
|
|
842
|
-
return s.map((
|
|
1851
|
+
return s.map((p) => String(p || "")).join("");
|
|
843
1852
|
case "TRIM":
|
|
844
1853
|
return String(s[0] || "").trim();
|
|
845
1854
|
case "LENGTH":
|
|
@@ -853,14 +1862,14 @@ class ht {
|
|
|
853
1862
|
case "MATCHES":
|
|
854
1863
|
return new RegExp(String(s[1])).test(String(s[0] || ""));
|
|
855
1864
|
case "SUM":
|
|
856
|
-
return s.reduce((
|
|
1865
|
+
return s.reduce((p, N) => p + (Number(N) || 0), 0);
|
|
857
1866
|
case "AVG":
|
|
858
|
-
const n = s.filter((
|
|
859
|
-
return n.length > 0 ? n.reduce((
|
|
1867
|
+
const n = s.filter((p) => !isNaN(Number(p)));
|
|
1868
|
+
return n.length > 0 ? n.reduce((p, N) => p + Number(N), 0) / n.length : 0;
|
|
860
1869
|
case "MIN":
|
|
861
|
-
return Math.min(...s.map((
|
|
1870
|
+
return Math.min(...s.map((p) => Number(p) || 0));
|
|
862
1871
|
case "MAX":
|
|
863
|
-
return Math.max(...s.map((
|
|
1872
|
+
return Math.max(...s.map((p) => Number(p) || 0));
|
|
864
1873
|
case "ROUND":
|
|
865
1874
|
return Math.round(Number(s[0]) || 0);
|
|
866
1875
|
case "FLOOR":
|
|
@@ -876,25 +1885,25 @@ class ht {
|
|
|
876
1885
|
case "DAY":
|
|
877
1886
|
return new Date(s[0]).getDate();
|
|
878
1887
|
case "DATE_DIFF":
|
|
879
|
-
const
|
|
880
|
-
return Math.ceil(
|
|
1888
|
+
const l = new Date(s[0]), d = new Date(s[1]), w = Math.abs(l.getTime() - d.getTime());
|
|
1889
|
+
return Math.ceil(w / (1e3 * 60 * 60 * 24));
|
|
881
1890
|
case "IF":
|
|
882
1891
|
return s[0] ? s[1] : s[2];
|
|
883
1892
|
case "AUTO_NUMBER":
|
|
884
1893
|
return Math.floor(Math.random() * 1e4);
|
|
885
1894
|
default:
|
|
886
|
-
throw new Error(`Unknown function: ${
|
|
1895
|
+
throw new Error(`Unknown function: ${t.Callee}`);
|
|
887
1896
|
}
|
|
888
1897
|
}
|
|
889
1898
|
/**
|
|
890
1899
|
* Evaluate member expressions
|
|
891
1900
|
*/
|
|
892
|
-
evaluateMemberExpression(
|
|
1901
|
+
evaluateMemberExpression(t, r) {
|
|
893
1902
|
var n;
|
|
894
|
-
if (!
|
|
1903
|
+
if (!t.Arguments || t.Arguments.length === 0)
|
|
895
1904
|
throw new Error("Member expression requires arguments");
|
|
896
|
-
const s = this.evaluateNode(
|
|
897
|
-
return
|
|
1905
|
+
const s = this.evaluateNode(t.Arguments[0], r), i = (n = t.Arguments[0].Property) == null ? void 0 : n.Name;
|
|
1906
|
+
return i && s && typeof s == "object" ? s[i] : s;
|
|
898
1907
|
}
|
|
899
1908
|
/**
|
|
900
1909
|
* Clear all caches
|
|
@@ -903,58 +1912,58 @@ class ht {
|
|
|
903
1912
|
this.resultCache.clear(), this.dependencyCache.clear(), this.compiledExpressions.clear();
|
|
904
1913
|
}
|
|
905
1914
|
}
|
|
906
|
-
const
|
|
907
|
-
function
|
|
1915
|
+
const kt = new qr();
|
|
1916
|
+
function $r(e, t, r, s, i) {
|
|
908
1917
|
if (!r || r.length === 0)
|
|
909
1918
|
return { isValid: !0 };
|
|
910
|
-
const n = { ...s, [
|
|
911
|
-
for (const
|
|
1919
|
+
const n = { ...s, [e]: t };
|
|
1920
|
+
for (const l of r)
|
|
912
1921
|
try {
|
|
913
|
-
if (!
|
|
914
|
-
|
|
1922
|
+
if (!kt.evaluate(
|
|
1923
|
+
l.ExpressionTree,
|
|
915
1924
|
n,
|
|
916
|
-
|
|
1925
|
+
i
|
|
917
1926
|
))
|
|
918
1927
|
return {
|
|
919
1928
|
isValid: !1,
|
|
920
|
-
message:
|
|
921
|
-
fieldName:
|
|
1929
|
+
message: l.Message || `Validation failed for ${l.Name}`,
|
|
1930
|
+
fieldName: e
|
|
922
1931
|
};
|
|
923
|
-
} catch (
|
|
924
|
-
console.warn(`Validation rule ${
|
|
1932
|
+
} catch (d) {
|
|
1933
|
+
console.warn(`Validation rule ${l.Id} failed to evaluate:`, d);
|
|
925
1934
|
}
|
|
926
1935
|
return { isValid: !0 };
|
|
927
1936
|
}
|
|
928
|
-
function
|
|
929
|
-
return Array.from(
|
|
1937
|
+
function Dt(e) {
|
|
1938
|
+
return Array.from(kt.getDependencies(e));
|
|
930
1939
|
}
|
|
931
|
-
function
|
|
1940
|
+
function Qr(e) {
|
|
932
1941
|
const {
|
|
933
|
-
source:
|
|
1942
|
+
source: t,
|
|
934
1943
|
operation: r,
|
|
935
1944
|
recordId: s,
|
|
936
|
-
defaultValues:
|
|
1945
|
+
defaultValues: i = {},
|
|
937
1946
|
mode: n = "onBlur",
|
|
938
1947
|
// Validation mode - controls when errors are shown (see types.ts for details)
|
|
939
|
-
enabled:
|
|
940
|
-
userRole:
|
|
941
|
-
onSchemaError:
|
|
942
|
-
skipSchemaFetch:
|
|
1948
|
+
enabled: l = !0,
|
|
1949
|
+
userRole: d,
|
|
1950
|
+
onSchemaError: w,
|
|
1951
|
+
skipSchemaFetch: p = !1,
|
|
943
1952
|
schema: N,
|
|
944
|
-
interactionMode:
|
|
945
|
-
} =
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
}, [
|
|
1953
|
+
interactionMode: D = "interactive"
|
|
1954
|
+
} = e, v = D === "interactive", [m, K] = ye(null), [O, Z] = ye({}), [H, x] = ye(!1), [ee] = ye({}), [L, T] = ye(null), [oe, he] = ye(!1), [ae, ne] = ye(null), B = qe(!1), le = qe(null), V = qe(null), E = qe(w);
|
|
1955
|
+
$e(() => {
|
|
1956
|
+
E.current = w;
|
|
1957
|
+
}, [w]);
|
|
949
1958
|
const {
|
|
950
|
-
data:
|
|
951
|
-
isLoading:
|
|
952
|
-
error:
|
|
953
|
-
refetch:
|
|
954
|
-
} =
|
|
955
|
-
queryKey: ["form-schema",
|
|
956
|
-
queryFn: () =>
|
|
957
|
-
enabled:
|
|
1959
|
+
data: S,
|
|
1960
|
+
isLoading: U,
|
|
1961
|
+
error: $,
|
|
1962
|
+
refetch: j
|
|
1963
|
+
} = ct({
|
|
1964
|
+
queryKey: ["form-schema", t],
|
|
1965
|
+
queryFn: () => p ? Promise.resolve(N || {}) : Br(t),
|
|
1966
|
+
enabled: l && (!p || !!N),
|
|
958
1967
|
retry: 3,
|
|
959
1968
|
staleTime: 30 * 60 * 1e3,
|
|
960
1969
|
// 30 minutes - schemas don't change frequently
|
|
@@ -962,133 +1971,133 @@ function xt(t) {
|
|
|
962
1971
|
// 1 hour - keep schemas in cache longer
|
|
963
1972
|
throwOnError: !1
|
|
964
1973
|
}), {
|
|
965
|
-
data:
|
|
966
|
-
isLoading:
|
|
967
|
-
error:
|
|
968
|
-
} =
|
|
969
|
-
queryKey: ["form-record",
|
|
970
|
-
queryFn: () =>
|
|
971
|
-
enabled:
|
|
1974
|
+
data: z,
|
|
1975
|
+
isLoading: ce,
|
|
1976
|
+
error: me
|
|
1977
|
+
} = ct({
|
|
1978
|
+
queryKey: ["form-record", t, s],
|
|
1979
|
+
queryFn: () => Cr(t, s),
|
|
1980
|
+
enabled: l && r === "update" && !!s,
|
|
972
1981
|
retry: 3,
|
|
973
1982
|
staleTime: 5 * 60 * 1e3,
|
|
974
1983
|
// 5 minutes - records can change more frequently
|
|
975
1984
|
gcTime: 15 * 60 * 1e3,
|
|
976
1985
|
// 15 minutes - keep records for a reasonable time
|
|
977
1986
|
throwOnError: !1
|
|
978
|
-
}),
|
|
979
|
-
const
|
|
980
|
-
if (r === "update" &&
|
|
981
|
-
for (const [
|
|
982
|
-
|
|
983
|
-
return
|
|
984
|
-
}, [
|
|
1987
|
+
}), Me = Ne(() => {
|
|
1988
|
+
const u = { ...i };
|
|
1989
|
+
if (r === "update" && z && Object.assign(u, z), m)
|
|
1990
|
+
for (const [o, f] of Object.entries(m.fields))
|
|
1991
|
+
f.defaultValue !== void 0 && !(o in u) && (u[o] = f.defaultValue);
|
|
1992
|
+
return u;
|
|
1993
|
+
}, [i, z, r, m]), A = dr({
|
|
985
1994
|
mode: n,
|
|
986
|
-
defaultValues:
|
|
987
|
-
values: r === "update" &&
|
|
1995
|
+
defaultValues: i,
|
|
1996
|
+
values: r === "update" && z ? Me : void 0
|
|
988
1997
|
});
|
|
989
|
-
|
|
990
|
-
var
|
|
991
|
-
if (
|
|
1998
|
+
$e(() => {
|
|
1999
|
+
var u;
|
|
2000
|
+
if (S)
|
|
992
2001
|
try {
|
|
993
|
-
const
|
|
994
|
-
|
|
2002
|
+
const o = Dr(
|
|
2003
|
+
S,
|
|
995
2004
|
{},
|
|
996
2005
|
// Pass empty object - validation functions get live values from react-hook-form
|
|
997
|
-
|
|
2006
|
+
d
|
|
998
2007
|
);
|
|
999
|
-
|
|
1000
|
-
const
|
|
1001
|
-
Object.keys(
|
|
1002
|
-
} catch (
|
|
1003
|
-
console.error("Schema processing failed:",
|
|
2008
|
+
K(o);
|
|
2009
|
+
const f = Rr(o);
|
|
2010
|
+
Object.keys(f).length > 0 && Mr(f).then(Z).catch(console.warn);
|
|
2011
|
+
} catch (o) {
|
|
2012
|
+
console.error("Schema processing failed:", o), (u = E.current) == null || u.call(E, o);
|
|
1004
2013
|
}
|
|
1005
|
-
}, [
|
|
1006
|
-
var
|
|
1007
|
-
|
|
1008
|
-
}, [
|
|
1009
|
-
if (!
|
|
2014
|
+
}, [S, d]), $e(() => {
|
|
2015
|
+
var u;
|
|
2016
|
+
$ && ((u = E.current) == null || u.call(E, $));
|
|
2017
|
+
}, [$]), $e(() => {
|
|
2018
|
+
if (!v || r !== "create" || !m || !l || L)
|
|
1010
2019
|
return;
|
|
1011
2020
|
(async () => {
|
|
1012
|
-
|
|
2021
|
+
he(!0), ne(null);
|
|
1013
2022
|
try {
|
|
1014
|
-
const
|
|
1015
|
-
|
|
2023
|
+
const f = await pe(t).draftInteraction({});
|
|
2024
|
+
T(f._id), f && typeof f == "object" && Object.entries(f).forEach(([h, c]) => {
|
|
1016
2025
|
if (h === "_id") return;
|
|
1017
|
-
|
|
2026
|
+
A.getValues(h) !== c && A.setValue(h, c, {
|
|
1018
2027
|
shouldDirty: !1,
|
|
1019
2028
|
shouldValidate: !1
|
|
1020
2029
|
});
|
|
1021
2030
|
});
|
|
1022
|
-
} catch (
|
|
1023
|
-
console.error("Failed to create initial draft:",
|
|
2031
|
+
} catch (o) {
|
|
2032
|
+
console.error("Failed to create initial draft:", o), ne(o);
|
|
1024
2033
|
} finally {
|
|
1025
|
-
|
|
2034
|
+
he(!1);
|
|
1026
2035
|
}
|
|
1027
2036
|
})();
|
|
1028
|
-
}, [
|
|
1029
|
-
const
|
|
1030
|
-
if (!
|
|
1031
|
-
const
|
|
1032
|
-
return Object.entries(
|
|
1033
|
-
h.computation.forEach((
|
|
1034
|
-
const
|
|
1035
|
-
|
|
1036
|
-
|
|
2037
|
+
}, [v, r, m, l, L, t, A]);
|
|
2038
|
+
const Ee = Ne(() => {
|
|
2039
|
+
if (!m) return [];
|
|
2040
|
+
const u = /* @__PURE__ */ new Set(), o = new Set(m.computedFields);
|
|
2041
|
+
return Object.entries(m.fieldRules).forEach(([f, h]) => {
|
|
2042
|
+
h.computation.forEach((c) => {
|
|
2043
|
+
const y = m.rules.computation[c];
|
|
2044
|
+
y != null && y.ExpressionTree && Dt(y.ExpressionTree).forEach((b) => {
|
|
2045
|
+
m.fields[b] && b !== f && !o.has(b) && u.add(b);
|
|
1037
2046
|
});
|
|
1038
2047
|
});
|
|
1039
|
-
}),
|
|
1040
|
-
const h =
|
|
1041
|
-
h._bdoField.Formula &&
|
|
2048
|
+
}), m.computedFields.forEach((f) => {
|
|
2049
|
+
const h = m.fields[f];
|
|
2050
|
+
h._bdoField.Formula && Dt(
|
|
1042
2051
|
h._bdoField.Formula.ExpressionTree
|
|
1043
|
-
).forEach((
|
|
1044
|
-
|
|
2052
|
+
).forEach((y) => {
|
|
2053
|
+
m.fields[y] && y !== f && !o.has(y) && u.add(y);
|
|
1045
2054
|
});
|
|
1046
|
-
}), Array.from(
|
|
1047
|
-
}, [
|
|
1048
|
-
async (
|
|
1049
|
-
if (!(!
|
|
1050
|
-
if (
|
|
2055
|
+
}), Array.from(u);
|
|
2056
|
+
}, [m]), Ae = te(
|
|
2057
|
+
async (u) => {
|
|
2058
|
+
if (!(!m || !(v || Ee.length > 0 && Ee.includes(u)))) {
|
|
2059
|
+
if (v && r === "create" && !L) {
|
|
1051
2060
|
console.warn("Interactive create mode: waiting for draft ID");
|
|
1052
2061
|
return;
|
|
1053
2062
|
}
|
|
1054
|
-
B.current || (
|
|
1055
|
-
if (!
|
|
2063
|
+
B.current || (le.current && clearTimeout(le.current), le.current = setTimeout(() => {
|
|
2064
|
+
if (!m || B.current)
|
|
1056
2065
|
return;
|
|
1057
|
-
const
|
|
2066
|
+
const f = A.getValues();
|
|
1058
2067
|
(async () => {
|
|
1059
2068
|
B.current = !0;
|
|
1060
2069
|
try {
|
|
1061
|
-
const
|
|
1062
|
-
r === "update" && s && "_id" in
|
|
1063
|
-
const
|
|
1064
|
-
|
|
2070
|
+
const c = pe(t), y = {};
|
|
2071
|
+
r === "update" && s && "_id" in f && (y._id = f._id), v && r === "create" && L && (y._id = L);
|
|
2072
|
+
const F = V.current ?? (r === "update" ? z : null) ?? {}, b = new Set(
|
|
2073
|
+
m.computedFields || []
|
|
1065
2074
|
);
|
|
1066
|
-
Object.keys(
|
|
1067
|
-
if (
|
|
1068
|
-
const
|
|
1069
|
-
JSON.stringify(
|
|
2075
|
+
Object.keys(f).forEach((q) => {
|
|
2076
|
+
if (q === "_id" || b.has(q)) return;
|
|
2077
|
+
const J = f[q], be = F[q];
|
|
2078
|
+
JSON.stringify(J) !== JSON.stringify(be) && (J !== "" && J !== null && J !== void 0) && (y[q] = J);
|
|
1070
2079
|
});
|
|
1071
|
-
const
|
|
1072
|
-
...
|
|
2080
|
+
const _ = y, P = {
|
|
2081
|
+
...V.current
|
|
1073
2082
|
};
|
|
1074
|
-
Object.keys(
|
|
1075
|
-
|
|
1076
|
-
}),
|
|
1077
|
-
let
|
|
1078
|
-
r === "update" && s ?
|
|
1079
|
-
([
|
|
1080
|
-
|
|
2083
|
+
Object.keys(f).forEach((q) => {
|
|
2084
|
+
b.has(q) || (P[q] = f[q]);
|
|
2085
|
+
}), V.current = P;
|
|
2086
|
+
let W;
|
|
2087
|
+
r === "update" && s ? W = await c.draftPatch(s, _) : v && L ? W = await c.draftInteraction(_) : W = await c.draft(_), W && typeof W == "object" && (Object.entries(W).forEach(
|
|
2088
|
+
([q, J]) => {
|
|
2089
|
+
f[q] !== J && A.setValue(q, J, {
|
|
1081
2090
|
shouldDirty: !1,
|
|
1082
2091
|
shouldValidate: !1
|
|
1083
2092
|
});
|
|
1084
2093
|
}
|
|
1085
|
-
), Object.entries(
|
|
1086
|
-
([
|
|
1087
|
-
|
|
2094
|
+
), Object.entries(W).forEach(
|
|
2095
|
+
([q, J]) => {
|
|
2096
|
+
b.has(q) && (V.current[q] = J);
|
|
1088
2097
|
}
|
|
1089
2098
|
));
|
|
1090
|
-
} catch (
|
|
1091
|
-
console.warn("Failed to compute fields via API:",
|
|
2099
|
+
} catch (c) {
|
|
2100
|
+
console.warn("Failed to compute fields via API:", c);
|
|
1092
2101
|
} finally {
|
|
1093
2102
|
B.current = !1;
|
|
1094
2103
|
}
|
|
@@ -1097,160 +2106,160 @@ function xt(t) {
|
|
|
1097
2106
|
}
|
|
1098
2107
|
},
|
|
1099
2108
|
[
|
|
1100
|
-
|
|
2109
|
+
m,
|
|
1101
2110
|
r,
|
|
1102
2111
|
s,
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
2112
|
+
z,
|
|
2113
|
+
t,
|
|
2114
|
+
A,
|
|
2115
|
+
Ee,
|
|
2116
|
+
v,
|
|
2117
|
+
L
|
|
1109
2118
|
]
|
|
1110
|
-
),
|
|
1111
|
-
if (!
|
|
2119
|
+
), Ye = te(async () => {
|
|
2120
|
+
if (!m)
|
|
1112
2121
|
return !1;
|
|
1113
|
-
const
|
|
1114
|
-
if (!await
|
|
2122
|
+
const u = A.getValues();
|
|
2123
|
+
if (!await A.trigger())
|
|
1115
2124
|
return !1;
|
|
1116
|
-
const
|
|
1117
|
-
(
|
|
1118
|
-
Id:
|
|
1119
|
-
Condition: { ExpressionTree:
|
|
1120
|
-
Message:
|
|
2125
|
+
const f = m.crossFieldValidation.map(
|
|
2126
|
+
(c) => ({
|
|
2127
|
+
Id: c.Id,
|
|
2128
|
+
Condition: { ExpressionTree: c.ExpressionTree },
|
|
2129
|
+
Message: c.Message || `Validation failed for ${c.Name}`
|
|
1121
2130
|
})
|
|
1122
|
-
), h =
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
2131
|
+
), h = At(
|
|
2132
|
+
f,
|
|
2133
|
+
u,
|
|
2134
|
+
O
|
|
1126
2135
|
);
|
|
1127
|
-
return h.length > 0 ? (h.forEach((
|
|
1128
|
-
|
|
2136
|
+
return h.length > 0 ? (h.forEach((c, y) => {
|
|
2137
|
+
A.setError(`root.crossField${y}`, {
|
|
1129
2138
|
type: "validate",
|
|
1130
|
-
message:
|
|
2139
|
+
message: c.message
|
|
1131
2140
|
});
|
|
1132
2141
|
}), !1) : !0;
|
|
1133
2142
|
}, [
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
]),
|
|
1140
|
-
(
|
|
2143
|
+
m,
|
|
2144
|
+
A.getValues,
|
|
2145
|
+
A.trigger,
|
|
2146
|
+
A.setError,
|
|
2147
|
+
O
|
|
2148
|
+
]), Ie = te(
|
|
2149
|
+
(u, o) => A.handleSubmit(
|
|
1141
2150
|
// RHF onValid handler - validation passed, now do cross-field + API
|
|
1142
|
-
async (
|
|
1143
|
-
if (!
|
|
1144
|
-
const
|
|
1145
|
-
|
|
2151
|
+
async (f, h) => {
|
|
2152
|
+
if (!m) {
|
|
2153
|
+
const c = new Error("Schema not loaded");
|
|
2154
|
+
o == null || o(c, h);
|
|
1146
2155
|
return;
|
|
1147
2156
|
}
|
|
1148
|
-
|
|
2157
|
+
x(!0);
|
|
1149
2158
|
try {
|
|
1150
|
-
const
|
|
1151
|
-
(
|
|
1152
|
-
Id:
|
|
1153
|
-
Condition: { ExpressionTree:
|
|
1154
|
-
Message:
|
|
2159
|
+
const c = m.crossFieldValidation.map(
|
|
2160
|
+
(_) => ({
|
|
2161
|
+
Id: _.Id,
|
|
2162
|
+
Condition: { ExpressionTree: _.ExpressionTree },
|
|
2163
|
+
Message: _.Message || `Validation failed for ${_.Name}`
|
|
1155
2164
|
})
|
|
1156
|
-
),
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
2165
|
+
), y = At(
|
|
2166
|
+
c,
|
|
2167
|
+
f,
|
|
2168
|
+
O
|
|
1160
2169
|
);
|
|
1161
|
-
if (
|
|
1162
|
-
|
|
1163
|
-
|
|
2170
|
+
if (y.length > 0) {
|
|
2171
|
+
y.forEach((_, P) => {
|
|
2172
|
+
A.setError(`root.crossField${P}`, {
|
|
1164
2173
|
type: "validate",
|
|
1165
|
-
message:
|
|
2174
|
+
message: _.message
|
|
1166
2175
|
});
|
|
1167
|
-
}),
|
|
2176
|
+
}), o == null || o(A.formState.errors, h);
|
|
1168
2177
|
return;
|
|
1169
2178
|
}
|
|
1170
|
-
const
|
|
1171
|
-
|
|
1172
|
-
|
|
2179
|
+
const F = Ir(
|
|
2180
|
+
f,
|
|
2181
|
+
m.computedFields,
|
|
1173
2182
|
r,
|
|
1174
|
-
|
|
2183
|
+
z
|
|
1175
2184
|
);
|
|
1176
|
-
let
|
|
1177
|
-
if (
|
|
1178
|
-
const
|
|
2185
|
+
let b;
|
|
2186
|
+
if (v) {
|
|
2187
|
+
const _ = pe(t);
|
|
1179
2188
|
if (r === "create") {
|
|
1180
|
-
if (!
|
|
2189
|
+
if (!L)
|
|
1181
2190
|
throw new Error(
|
|
1182
2191
|
"Interactive create mode requires a draft ID. Draft creation may have failed."
|
|
1183
2192
|
);
|
|
1184
|
-
|
|
1185
|
-
...
|
|
1186
|
-
_id:
|
|
2193
|
+
b = { success: !0, data: await _.draft({
|
|
2194
|
+
...F,
|
|
2195
|
+
_id: L
|
|
1187
2196
|
}) };
|
|
1188
2197
|
} else
|
|
1189
|
-
|
|
1190
|
-
} else if (
|
|
1191
|
-
|
|
2198
|
+
b = { success: !0, data: await _.draftUpdate(s, F) };
|
|
2199
|
+
} else if (b = await Tr(
|
|
2200
|
+
t,
|
|
1192
2201
|
r,
|
|
1193
|
-
|
|
2202
|
+
F,
|
|
1194
2203
|
s
|
|
1195
|
-
), !
|
|
1196
|
-
throw
|
|
1197
|
-
r === "create" && (
|
|
1198
|
-
} catch (
|
|
1199
|
-
|
|
2204
|
+
), !b.success)
|
|
2205
|
+
throw b.error || new Error("Submission failed");
|
|
2206
|
+
r === "create" && (A.reset(), v && T(null)), await (u == null ? void 0 : u(b.data || f, h));
|
|
2207
|
+
} catch (c) {
|
|
2208
|
+
o == null || o(c, h);
|
|
1200
2209
|
} finally {
|
|
1201
|
-
|
|
2210
|
+
x(!1);
|
|
1202
2211
|
}
|
|
1203
2212
|
},
|
|
1204
2213
|
// RHF onInvalid handler - validation failed
|
|
1205
|
-
(
|
|
1206
|
-
|
|
2214
|
+
(f, h) => {
|
|
2215
|
+
o == null || o(f, h);
|
|
1207
2216
|
}
|
|
1208
2217
|
),
|
|
1209
2218
|
[
|
|
2219
|
+
A,
|
|
1210
2220
|
m,
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
e,
|
|
2221
|
+
O,
|
|
2222
|
+
t,
|
|
1214
2223
|
r,
|
|
1215
2224
|
s,
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
2225
|
+
z,
|
|
2226
|
+
v,
|
|
2227
|
+
L
|
|
1219
2228
|
]
|
|
1220
|
-
),
|
|
1221
|
-
(
|
|
1222
|
-
[
|
|
1223
|
-
),
|
|
1224
|
-
if (!
|
|
1225
|
-
const
|
|
1226
|
-
return Object.entries(
|
|
1227
|
-
|
|
1228
|
-
}),
|
|
1229
|
-
}, [
|
|
1230
|
-
(
|
|
1231
|
-
[
|
|
1232
|
-
),
|
|
1233
|
-
(
|
|
1234
|
-
[
|
|
1235
|
-
),
|
|
1236
|
-
(
|
|
1237
|
-
[
|
|
1238
|
-
),
|
|
1239
|
-
await
|
|
1240
|
-
}, [
|
|
1241
|
-
|
|
1242
|
-
}, [
|
|
1243
|
-
() => (
|
|
1244
|
-
[
|
|
1245
|
-
),
|
|
1246
|
-
() => (
|
|
1247
|
-
[
|
|
1248
|
-
),
|
|
1249
|
-
if (!
|
|
1250
|
-
const
|
|
1251
|
-
return Object.entries(
|
|
2229
|
+
), Ke = te(
|
|
2230
|
+
(u) => (m == null ? void 0 : m.fields[u]) || null,
|
|
2231
|
+
[m]
|
|
2232
|
+
), xe = te(() => {
|
|
2233
|
+
if (!m) return {};
|
|
2234
|
+
const u = {};
|
|
2235
|
+
return Object.entries(m.fields).forEach(([o, f]) => {
|
|
2236
|
+
u[o] = f;
|
|
2237
|
+
}), u;
|
|
2238
|
+
}, [m]), ke = te(
|
|
2239
|
+
(u) => !!(m != null && m.fields[u]),
|
|
2240
|
+
[m]
|
|
2241
|
+
), _e = te(
|
|
2242
|
+
(u) => (m == null ? void 0 : m.requiredFields.includes(u)) || !1,
|
|
2243
|
+
[m]
|
|
2244
|
+
), De = te(
|
|
2245
|
+
(u) => (m == null ? void 0 : m.computedFields.includes(u)) || !1,
|
|
2246
|
+
[m]
|
|
2247
|
+
), ze = te(async () => {
|
|
2248
|
+
await j();
|
|
2249
|
+
}, [j]), Ue = te(() => {
|
|
2250
|
+
A.clearErrors();
|
|
2251
|
+
}, [A]), Be = U || r === "update" && ce || v && r === "create" && oe, Pe = Be || H, Se = $ || me || ae, Je = !!Se, Ge = Ne(
|
|
2252
|
+
() => (m == null ? void 0 : m.computedFields) || [],
|
|
2253
|
+
[m]
|
|
2254
|
+
), ut = Ne(
|
|
2255
|
+
() => (m == null ? void 0 : m.requiredFields) || [],
|
|
2256
|
+
[m]
|
|
2257
|
+
), Re = Ne(() => {
|
|
2258
|
+
if (!m) return {};
|
|
2259
|
+
const u = {};
|
|
2260
|
+
return Object.entries(m.fields).forEach(([o, f]) => {
|
|
1252
2261
|
const h = {};
|
|
1253
|
-
switch (
|
|
2262
|
+
switch (f.required && (h.required = `${f.label} is required`), f.permission.editable || (h.disabled = !0), f.type) {
|
|
1254
2263
|
case "number":
|
|
1255
2264
|
h.valueAsNumber = !0;
|
|
1256
2265
|
break;
|
|
@@ -1259,88 +2268,88 @@ function xt(t) {
|
|
|
1259
2268
|
h.valueAsDate = !0;
|
|
1260
2269
|
break;
|
|
1261
2270
|
}
|
|
1262
|
-
const
|
|
1263
|
-
|
|
1264
|
-
expressionValidation: (
|
|
1265
|
-
const
|
|
1266
|
-
for (const
|
|
1267
|
-
const
|
|
1268
|
-
if (
|
|
1269
|
-
const
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
[
|
|
1273
|
-
|
|
1274
|
-
|
|
2271
|
+
const c = f.rules.validation;
|
|
2272
|
+
c.length > 0 && (h.validate = {
|
|
2273
|
+
expressionValidation: (y) => {
|
|
2274
|
+
const F = A.getValues();
|
|
2275
|
+
for (const b of c) {
|
|
2276
|
+
const _ = m.rules.validation[b];
|
|
2277
|
+
if (_) {
|
|
2278
|
+
const P = $r(
|
|
2279
|
+
o,
|
|
2280
|
+
y,
|
|
2281
|
+
[_],
|
|
2282
|
+
F,
|
|
2283
|
+
ee
|
|
1275
2284
|
);
|
|
1276
|
-
if (!
|
|
1277
|
-
return
|
|
2285
|
+
if (!P.isValid)
|
|
2286
|
+
return P.message || _.Message || "Invalid value";
|
|
1278
2287
|
}
|
|
1279
2288
|
}
|
|
1280
2289
|
return !0;
|
|
1281
2290
|
}
|
|
1282
|
-
}),
|
|
1283
|
-
}),
|
|
1284
|
-
}, [
|
|
2291
|
+
}), u[o] = h;
|
|
2292
|
+
}), u;
|
|
2293
|
+
}, [m, A, O]);
|
|
1285
2294
|
return {
|
|
1286
2295
|
// Form methods with strict typing
|
|
1287
|
-
register:
|
|
1288
|
-
(
|
|
1289
|
-
const
|
|
1290
|
-
h && await h(
|
|
1291
|
-
let
|
|
1292
|
-
n === "onBlur" || n === "onTouched" || n === "all" ?
|
|
2296
|
+
register: te(
|
|
2297
|
+
(u, o) => {
|
|
2298
|
+
const f = Re[u], h = o == null ? void 0 : o.onBlur, c = async (y) => {
|
|
2299
|
+
h && await h(y);
|
|
2300
|
+
let F = !0;
|
|
2301
|
+
n === "onBlur" || n === "onTouched" || n === "all" ? F = await A.trigger(u) : F = !A.getFieldState(u, A.formState).error, F && await Ae(u);
|
|
1293
2302
|
};
|
|
1294
|
-
return
|
|
1295
|
-
...
|
|
1296
|
-
...
|
|
1297
|
-
onBlur:
|
|
2303
|
+
return A.register(u, {
|
|
2304
|
+
...f,
|
|
2305
|
+
...o,
|
|
2306
|
+
onBlur: c
|
|
1298
2307
|
});
|
|
1299
2308
|
},
|
|
1300
|
-
[
|
|
2309
|
+
[A, Re, Ae, n]
|
|
1301
2310
|
),
|
|
1302
|
-
handleSubmit:
|
|
1303
|
-
watch:
|
|
2311
|
+
handleSubmit: Ie,
|
|
2312
|
+
watch: A.watch,
|
|
1304
2313
|
// Type assertion for complex generic constraints
|
|
1305
|
-
setValue:
|
|
1306
|
-
reset:
|
|
2314
|
+
setValue: A.setValue,
|
|
2315
|
+
reset: A.reset,
|
|
1307
2316
|
// Flattened form state (NEW - direct access, no nested formState)
|
|
1308
|
-
errors:
|
|
1309
|
-
isValid:
|
|
1310
|
-
isDirty:
|
|
1311
|
-
isSubmitting:
|
|
1312
|
-
isSubmitSuccessful:
|
|
2317
|
+
errors: A.formState.errors,
|
|
2318
|
+
isValid: A.formState.isValid,
|
|
2319
|
+
isDirty: A.formState.isDirty,
|
|
2320
|
+
isSubmitting: A.formState.isSubmitting || H,
|
|
2321
|
+
isSubmitSuccessful: A.formState.isSubmitSuccessful,
|
|
1313
2322
|
// Loading states
|
|
1314
|
-
isLoadingInitialData:
|
|
1315
|
-
isLoadingRecord:
|
|
1316
|
-
isLoading:
|
|
2323
|
+
isLoadingInitialData: Be,
|
|
2324
|
+
isLoadingRecord: ce,
|
|
2325
|
+
isLoading: Pe,
|
|
1317
2326
|
// Interactive mode state
|
|
1318
|
-
draftId:
|
|
1319
|
-
isCreatingDraft:
|
|
2327
|
+
draftId: L,
|
|
2328
|
+
isCreatingDraft: oe,
|
|
1320
2329
|
// Error handling
|
|
1321
|
-
loadError:
|
|
1322
|
-
hasError:
|
|
2330
|
+
loadError: Se,
|
|
2331
|
+
hasError: Je,
|
|
1323
2332
|
// Schema information
|
|
1324
|
-
schema:
|
|
1325
|
-
schemaConfig:
|
|
1326
|
-
computedFields:
|
|
1327
|
-
requiredFields:
|
|
2333
|
+
schema: S,
|
|
2334
|
+
schemaConfig: m,
|
|
2335
|
+
computedFields: Ge,
|
|
2336
|
+
requiredFields: ut,
|
|
1328
2337
|
// Field helpers
|
|
1329
|
-
getField:
|
|
1330
|
-
getFields:
|
|
1331
|
-
hasField:
|
|
1332
|
-
isFieldRequired:
|
|
1333
|
-
isFieldComputed:
|
|
2338
|
+
getField: Ke,
|
|
2339
|
+
getFields: xe,
|
|
2340
|
+
hasField: ke,
|
|
2341
|
+
isFieldRequired: _e,
|
|
2342
|
+
isFieldComputed: De,
|
|
1334
2343
|
// Operations
|
|
1335
|
-
refreshSchema:
|
|
1336
|
-
validateForm:
|
|
1337
|
-
clearErrors:
|
|
2344
|
+
refreshSchema: ze,
|
|
2345
|
+
validateForm: Ye,
|
|
2346
|
+
clearErrors: Ue
|
|
1338
2347
|
};
|
|
1339
2348
|
}
|
|
1340
2349
|
export {
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
2350
|
+
Xr as clearFormCache,
|
|
2351
|
+
Jr as isNetworkError,
|
|
2352
|
+
Gr as isValidationError,
|
|
2353
|
+
zr as parseApiError,
|
|
2354
|
+
Qr as useForm
|
|
1346
2355
|
};
|