@ram_28/kf-ai-sdk 2.0.15 → 2.0.16

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.
Files changed (83) hide show
  1. package/README.md +8 -8
  2. package/dist/bdo/core/BaseBdo.d.ts +1 -1
  3. package/dist/bdo.mjs +2 -2
  4. package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts +1 -1
  5. package/dist/components/hooks/useActivityForm/createActivityItemProxy.d.ts.map +1 -1
  6. package/dist/components/hooks/useActivityForm/types.d.ts +2 -2
  7. package/dist/components/hooks/useActivityForm/types.d.ts.map +1 -1
  8. package/dist/components/hooks/useActivityForm/useActivityForm.d.ts.map +1 -1
  9. package/dist/components/hooks/useActivityTable/types.d.ts +4 -4
  10. package/dist/components/hooks/useActivityTable/types.d.ts.map +1 -1
  11. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts +1 -1
  12. package/dist/components/hooks/useActivityTable/useActivityTable.d.ts.map +1 -1
  13. package/dist/components/hooks/useBDOForm/createItemProxy.d.ts.map +1 -0
  14. package/dist/components/hooks/useBDOForm/createResolver.d.ts.map +1 -0
  15. package/dist/components/hooks/useBDOForm/index.d.ts +6 -0
  16. package/dist/components/hooks/useBDOForm/index.d.ts.map +1 -0
  17. package/dist/components/hooks/useBDOForm/shared.d.ts +50 -0
  18. package/dist/components/hooks/useBDOForm/shared.d.ts.map +1 -0
  19. package/dist/components/hooks/{useForm → useBDOForm}/types.d.ts +6 -6
  20. package/dist/components/hooks/useBDOForm/types.d.ts.map +1 -0
  21. package/dist/components/hooks/{useForm/useForm.d.ts → useBDOForm/useBDOForm.d.ts} +4 -4
  22. package/dist/components/hooks/useBDOForm/useBDOForm.d.ts.map +1 -0
  23. package/dist/components/hooks/useBDOTable/types.d.ts +1 -3
  24. package/dist/components/hooks/useBDOTable/types.d.ts.map +1 -1
  25. package/dist/components/hooks/useBDOTable/useBDOTable.d.ts.map +1 -1
  26. package/dist/form.cjs +1 -1
  27. package/dist/form.d.ts +1 -1
  28. package/dist/form.d.ts.map +1 -1
  29. package/dist/form.mjs +250 -253
  30. package/dist/form.types.d.ts +1 -1
  31. package/dist/form.types.d.ts.map +1 -1
  32. package/dist/shared-5a7UkED1.js +1180 -0
  33. package/dist/shared-nnmlRVs7.cjs +1 -0
  34. package/dist/table.cjs +1 -1
  35. package/dist/table.mjs +12 -11
  36. package/dist/types/constants.d.ts +3 -3
  37. package/dist/workflow/Activity.d.ts +15 -3
  38. package/dist/workflow/Activity.d.ts.map +1 -1
  39. package/dist/workflow/client.d.ts +2 -2
  40. package/dist/workflow/client.d.ts.map +1 -1
  41. package/dist/workflow/types.d.ts +7 -3
  42. package/dist/workflow/types.d.ts.map +1 -1
  43. package/dist/workflow.cjs +1 -1
  44. package/dist/workflow.mjs +503 -546
  45. package/docs/bdo.md +1 -1
  46. package/docs/gaps.md +14 -64
  47. package/docs/useActivityForm.md +393 -0
  48. package/docs/useActivityTable.md +42 -105
  49. package/docs/{useForm.md → useBDOForm.md} +24 -24
  50. package/docs/useBDOTable.md +6 -39
  51. package/docs/workflow.md +43 -301
  52. package/package.json +2 -2
  53. package/sdk/bdo/core/BaseBdo.ts +2 -2
  54. package/sdk/components/hooks/useActivityForm/createActivityItemProxy.ts +1 -1
  55. package/sdk/components/hooks/useActivityForm/createActivityResolver.ts +1 -1
  56. package/sdk/components/hooks/useActivityForm/types.ts +4 -4
  57. package/sdk/components/hooks/useActivityForm/useActivityForm.ts +44 -194
  58. package/sdk/components/hooks/useActivityTable/types.ts +4 -2
  59. package/sdk/components/hooks/useActivityTable/useActivityTable.ts +8 -39
  60. package/sdk/components/hooks/{useForm → useBDOForm}/index.ts +4 -3
  61. package/sdk/components/hooks/useBDOForm/shared.ts +250 -0
  62. package/sdk/components/hooks/{useForm → useBDOForm}/types.ts +9 -9
  63. package/sdk/components/hooks/{useForm/useForm.ts → useBDOForm/useBDOForm.ts} +70 -96
  64. package/sdk/components/hooks/useBDOTable/types.ts +1 -3
  65. package/sdk/components/hooks/useBDOTable/useBDOTable.ts +3 -2
  66. package/sdk/form.ts +2 -2
  67. package/sdk/form.types.ts +4 -4
  68. package/sdk/types/constants.ts +3 -3
  69. package/sdk/workflow/Activity.ts +29 -6
  70. package/sdk/workflow/client.ts +65 -25
  71. package/sdk/workflow/types.ts +10 -2
  72. package/dist/components/hooks/useForm/createItemProxy.d.ts.map +0 -1
  73. package/dist/components/hooks/useForm/createResolver.d.ts.map +0 -1
  74. package/dist/components/hooks/useForm/index.d.ts +0 -5
  75. package/dist/components/hooks/useForm/index.d.ts.map +0 -1
  76. package/dist/components/hooks/useForm/types.d.ts.map +0 -1
  77. package/dist/components/hooks/useForm/useForm.d.ts.map +0 -1
  78. package/dist/createResolver-AIgUwoS6.cjs +0 -1
  79. package/dist/createResolver-ZHXQ7QMa.js +0 -1078
  80. /package/dist/components/hooks/{useForm → useBDOForm}/createItemProxy.d.ts +0 -0
  81. /package/dist/components/hooks/{useForm → useBDOForm}/createResolver.d.ts +0 -0
  82. /package/sdk/components/hooks/{useForm → useBDOForm}/createItemProxy.ts +0 -0
  83. /package/sdk/components/hooks/{useForm → useBDOForm}/createResolver.ts +0 -0
@@ -0,0 +1,1180 @@
1
+ import p from "react";
2
+ var he = (e) => e.type === "checkbox", se = (e) => e instanceof Date, N = (e) => e == null;
3
+ const rt = (e) => typeof e == "object";
4
+ var T = (e) => !N(e) && !Array.isArray(e) && rt(e) && !se(e), Ft = (e) => T(e) && e.target ? he(e.target) ? e.target.checked : e.target.value : e, _t = (e) => e.substring(0, e.search(/\.\d+(\.|$)/)) || e, mt = (e, r) => e.has(_t(r)), wt = (e) => {
5
+ const r = e.constructor && e.constructor.prototype;
6
+ return T(r) && r.hasOwnProperty("isPrototypeOf");
7
+ }, Se = typeof window < "u" && typeof window.HTMLElement < "u" && typeof document < "u";
8
+ function O(e) {
9
+ if (e instanceof Date)
10
+ return new Date(e);
11
+ const r = typeof FileList < "u" && e instanceof FileList;
12
+ if (Se && (e instanceof Blob || r))
13
+ return e;
14
+ const t = Array.isArray(e);
15
+ if (!t && !(T(e) && wt(e)))
16
+ return e;
17
+ const a = t ? [] : Object.create(Object.getPrototypeOf(e));
18
+ for (const u in e)
19
+ Object.prototype.hasOwnProperty.call(e, u) && (a[u] = O(e[u]));
20
+ return a;
21
+ }
22
+ var Fe = (e) => /^\w*$/.test(e), E = (e) => e === void 0, Ce = (e) => Array.isArray(e) ? e.filter(Boolean) : [], Te = (e) => Ce(e.replace(/["|']|\]/g, "").split(/\.|\[/)), h = (e, r, t) => {
23
+ if (!r || !T(e))
24
+ return t;
25
+ const a = (Fe(r) ? [r] : Te(r)).reduce((u, n) => N(u) ? u : u[n], e);
26
+ return E(a) || a === e ? E(e[r]) ? t : e[r] : a;
27
+ }, K = (e) => typeof e == "boolean", Z = (e) => typeof e == "function", k = (e, r, t) => {
28
+ let a = -1;
29
+ const u = Fe(r) ? [r] : Te(r), n = u.length, o = n - 1;
30
+ for (; ++a < n; ) {
31
+ const f = u[a];
32
+ let D = t;
33
+ if (a !== o) {
34
+ const w = e[f];
35
+ D = T(w) || Array.isArray(w) ? w : isNaN(+u[a + 1]) ? {} : [];
36
+ }
37
+ if (f === "__proto__" || f === "constructor" || f === "prototype")
38
+ return;
39
+ e[f] = D, e = e[f];
40
+ }
41
+ };
42
+ const je = {
43
+ BLUR: "blur",
44
+ FOCUS_OUT: "focusout"
45
+ }, z = {
46
+ onBlur: "onBlur",
47
+ onChange: "onChange",
48
+ onSubmit: "onSubmit",
49
+ onTouched: "onTouched",
50
+ all: "all"
51
+ }, X = {
52
+ max: "max",
53
+ min: "min",
54
+ maxLength: "maxLength",
55
+ minLength: "minLength",
56
+ pattern: "pattern",
57
+ required: "required",
58
+ validate: "validate"
59
+ }, At = p.createContext(null);
60
+ At.displayName = "HookFormContext";
61
+ var xt = (e, r, t, a = !0) => {
62
+ const u = {
63
+ defaultValues: r._defaultValues
64
+ };
65
+ for (const n in e)
66
+ Object.defineProperty(u, n, {
67
+ get: () => {
68
+ const o = n;
69
+ return r._proxyFormState[o] !== z.all && (r._proxyFormState[o] = !a || z.all), e[o];
70
+ }
71
+ });
72
+ return u;
73
+ };
74
+ const Dt = typeof window < "u" ? p.useLayoutEffect : p.useEffect;
75
+ var W = (e) => typeof e == "string", kt = (e, r, t, a, u) => W(e) ? (a && r.watch.add(e), h(t, e, u)) : Array.isArray(e) ? e.map((n) => (a && r.watch.add(n), h(t, n))) : (a && (r.watchAll = !0), t), ke = (e) => N(e) || !rt(e);
76
+ function ee(e, r, t = /* @__PURE__ */ new WeakSet()) {
77
+ if (ke(e) || ke(r))
78
+ return Object.is(e, r);
79
+ if (se(e) && se(r))
80
+ return Object.is(e.getTime(), r.getTime());
81
+ const a = Object.keys(e), u = Object.keys(r);
82
+ if (a.length !== u.length)
83
+ return !1;
84
+ if (t.has(e) || t.has(r))
85
+ return !0;
86
+ t.add(e), t.add(r);
87
+ for (const n of a) {
88
+ const o = e[n];
89
+ if (!u.includes(n))
90
+ return !1;
91
+ if (n !== "ref") {
92
+ const f = r[n];
93
+ if (se(o) && se(f) || T(o) && T(f) || Array.isArray(o) && Array.isArray(f) ? !ee(o, f, t) : !Object.is(o, f))
94
+ return !1;
95
+ }
96
+ }
97
+ return !0;
98
+ }
99
+ var Et = (e, r, t, a, u) => r ? {
100
+ ...t[e],
101
+ types: {
102
+ ...t[e] && t[e].types ? t[e].types : {},
103
+ [a]: u || !0
104
+ }
105
+ } : {}, de = (e) => Array.isArray(e) ? e : [e], He = () => {
106
+ let e = [];
107
+ return {
108
+ get observers() {
109
+ return e;
110
+ },
111
+ next: (u) => {
112
+ for (const n of e)
113
+ n.next && n.next(u);
114
+ },
115
+ subscribe: (u) => (e.push(u), {
116
+ unsubscribe: () => {
117
+ e = e.filter((n) => n !== u);
118
+ }
119
+ }),
120
+ unsubscribe: () => {
121
+ e = [];
122
+ }
123
+ };
124
+ };
125
+ function st(e, r) {
126
+ const t = {};
127
+ for (const a in e)
128
+ if (e.hasOwnProperty(a)) {
129
+ const u = e[a], n = r[a];
130
+ if (u && T(u) && n) {
131
+ const o = st(u, n);
132
+ T(o) && (t[a] = o);
133
+ } else e[a] && (t[a] = n);
134
+ }
135
+ return t;
136
+ }
137
+ var B = (e) => T(e) && !Object.keys(e).length, Re = (e) => e.type === "file", be = (e) => {
138
+ if (!Se)
139
+ return !1;
140
+ const r = e ? e.ownerDocument : 0;
141
+ return e instanceof (r && r.defaultView ? r.defaultView.HTMLElement : HTMLElement);
142
+ }, it = (e) => e.type === "select-multiple", Le = (e) => e.type === "radio", St = (e) => Le(e) || he(e), De = (e) => be(e) && e.isConnected;
143
+ function Ct(e, r) {
144
+ const t = r.slice(0, -1).length;
145
+ let a = 0;
146
+ for (; a < t; )
147
+ e = E(e) ? a++ : e[r[a++]];
148
+ return e;
149
+ }
150
+ function Tt(e) {
151
+ for (const r in e)
152
+ if (e.hasOwnProperty(r) && !E(e[r]))
153
+ return !1;
154
+ return !0;
155
+ }
156
+ function C(e, r) {
157
+ const t = Array.isArray(r) ? r : Fe(r) ? [r] : Te(r), a = t.length === 1 ? e : Ct(e, t), u = t.length - 1, n = t[u];
158
+ return a && delete a[n], u !== 0 && (T(a) && B(a) || Array.isArray(a) && Tt(a)) && C(e, t.slice(0, -1)), e;
159
+ }
160
+ var Rt = (e) => {
161
+ for (const r in e)
162
+ if (Z(e[r]))
163
+ return !0;
164
+ return !1;
165
+ };
166
+ function at(e) {
167
+ return Array.isArray(e) || T(e) && !Rt(e);
168
+ }
169
+ function Ee(e, r = {}) {
170
+ for (const t in e) {
171
+ const a = e[t];
172
+ at(a) ? (r[t] = Array.isArray(a) ? [] : {}, Ee(a, r[t])) : E(a) || (r[t] = !0);
173
+ }
174
+ return r;
175
+ }
176
+ function ne(e, r, t) {
177
+ t || (t = Ee(r));
178
+ for (const a in e) {
179
+ const u = e[a];
180
+ if (at(u))
181
+ E(r) || ke(t[a]) ? t[a] = Ee(u, Array.isArray(u) ? [] : {}) : ne(u, N(r) ? {} : r[a], t[a]);
182
+ else {
183
+ const n = r[a];
184
+ t[a] = !ee(u, n);
185
+ }
186
+ }
187
+ return t;
188
+ }
189
+ const Ze = {
190
+ value: !1,
191
+ isValid: !1
192
+ }, ze = { value: !0, isValid: !0 };
193
+ var nt = (e) => {
194
+ if (Array.isArray(e)) {
195
+ if (e.length > 1) {
196
+ const r = e.filter((t) => t && t.checked && !t.disabled).map((t) => t.value);
197
+ return { value: r, isValid: !!r.length };
198
+ }
199
+ return e[0].checked && !e[0].disabled ? (
200
+ // @ts-expect-error expected to work in the browser
201
+ e[0].attributes && !E(e[0].attributes.value) ? E(e[0].value) || e[0].value === "" ? ze : { value: e[0].value, isValid: !0 } : ze
202
+ ) : Ze;
203
+ }
204
+ return Ze;
205
+ }, lt = (e, { valueAsNumber: r, valueAsDate: t, setValueAs: a }) => E(e) ? e : r ? e === "" ? NaN : e && +e : t && W(e) ? new Date(e) : a ? a(e) : e;
206
+ const Ke = {
207
+ isValid: !1,
208
+ value: null
209
+ };
210
+ var ut = (e) => Array.isArray(e) ? e.reduce((r, t) => t && t.checked && !t.disabled ? {
211
+ isValid: !0,
212
+ value: t.value
213
+ } : r, Ke) : Ke;
214
+ function Ye(e) {
215
+ const r = e.ref;
216
+ return Re(r) ? r.files : Le(r) ? ut(e.refs).value : it(r) ? [...r.selectedOptions].map(({ value: t }) => t) : he(r) ? nt(e.refs).value : lt(E(r.value) ? e.ref.value : r.value, e);
217
+ }
218
+ var Lt = (e, r, t, a) => {
219
+ const u = {};
220
+ for (const n of e) {
221
+ const o = h(r, n);
222
+ o && k(u, n, o._f);
223
+ }
224
+ return {
225
+ criteriaMode: t,
226
+ names: [...e],
227
+ fields: u,
228
+ shouldUseNativeValidation: a
229
+ };
230
+ }, Ve = (e) => e instanceof RegExp, ce = (e) => E(e) ? e : Ve(e) ? e.source : T(e) ? Ve(e.value) ? e.value.source : e.value : e, Je = (e) => ({
231
+ isOnSubmit: !e || e === z.onSubmit,
232
+ isOnBlur: e === z.onBlur,
233
+ isOnChange: e === z.onChange,
234
+ isOnAll: e === z.all,
235
+ isOnTouch: e === z.onTouched
236
+ });
237
+ const Qe = "AsyncFunction";
238
+ var Ot = (e) => !!e && !!e.validate && !!(Z(e.validate) && e.validate.constructor.name === Qe || T(e.validate) && Object.values(e.validate).find((r) => r.constructor.name === Qe)), Pt = (e) => e.mount && (e.required || e.min || e.max || e.maxLength || e.minLength || e.pattern || e.validate), Xe = (e, r, t) => !t && (r.watchAll || r.watch.has(e) || [...r.watch].some((a) => e.startsWith(a) && /^\.\w+/.test(e.slice(a.length))));
239
+ const ye = (e, r, t, a) => {
240
+ for (const u of t || Object.keys(e)) {
241
+ const n = h(e, u);
242
+ if (n) {
243
+ const { _f: o, ...f } = n;
244
+ if (o) {
245
+ if (o.refs && o.refs[0] && r(o.refs[0], u) && !a)
246
+ return !0;
247
+ if (o.ref && r(o.ref, o.name) && !a)
248
+ return !0;
249
+ if (ye(f, r))
250
+ break;
251
+ } else if (T(f) && ye(f, r))
252
+ break;
253
+ }
254
+ }
255
+ };
256
+ function Ge(e, r, t) {
257
+ const a = h(e, t);
258
+ if (a || Fe(t))
259
+ return {
260
+ error: a,
261
+ name: t
262
+ };
263
+ const u = t.split(".");
264
+ for (; u.length; ) {
265
+ const n = u.join("."), o = h(r, n), f = h(e, n);
266
+ if (o && !Array.isArray(o) && t !== n)
267
+ return { name: t };
268
+ if (f && f.type)
269
+ return {
270
+ name: n,
271
+ error: f
272
+ };
273
+ if (f && f.root && f.root.type)
274
+ return {
275
+ name: `${n}.root`,
276
+ error: f.root
277
+ };
278
+ u.pop();
279
+ }
280
+ return {
281
+ name: t
282
+ };
283
+ }
284
+ var Ut = (e, r, t, a) => {
285
+ t(e);
286
+ const { name: u, ...n } = e;
287
+ return B(n) || Object.keys(n).length >= Object.keys(r).length || Object.keys(n).find((o) => r[o] === (!a || z.all));
288
+ }, Mt = (e, r, t) => !e || !r || e === r || de(e).some((a) => a && (t ? a === r : a.startsWith(r) || r.startsWith(a))), Bt = (e, r, t, a, u) => u.isOnAll ? !1 : !t && u.isOnTouch ? !(r || e) : (t ? a.isOnBlur : u.isOnBlur) ? !e : (t ? a.isOnChange : u.isOnChange) ? e : !0, It = (e, r) => !Ce(h(e, r)).length && C(e, r), Nt = (e, r, t) => {
289
+ const a = de(h(e, t));
290
+ return k(a, "root", r[t]), k(e, t, a), e;
291
+ };
292
+ function et(e, r, t = "validate") {
293
+ if (W(e) || Array.isArray(e) && e.every(W) || K(e) && !e)
294
+ return {
295
+ type: t,
296
+ message: W(e) ? e : "",
297
+ ref: r
298
+ };
299
+ }
300
+ var ae = (e) => T(e) && !Ve(e) ? e : {
301
+ value: e,
302
+ message: ""
303
+ }, tt = async (e, r, t, a, u, n) => {
304
+ const { ref: o, refs: f, required: D, maxLength: w, minLength: S, min: b, max: V, pattern: v, validate: P, name: I, valueAsNumber: Y, mount: $ } = e._f, _ = h(t, I);
305
+ if (!$ || r.has(I))
306
+ return {};
307
+ const J = f ? f[0] : o, Q = (F) => {
308
+ u && J.reportValidity && (J.setCustomValidity(K(F) ? "" : F || ""), J.reportValidity());
309
+ }, R = {}, le = Le(o), ge = he(o), te = le || ge, ie = (Y || Re(o)) && E(o.value) && E(_) || be(o) && o.value === "" || _ === "" || Array.isArray(_) && !_.length, j = Et.bind(null, I, a, R), ve = (F, m, L, U = X.maxLength, H = X.minLength) => {
310
+ const q = F ? m : L;
311
+ R[I] = {
312
+ type: F ? U : H,
313
+ message: q,
314
+ ref: o,
315
+ ...j(F ? U : H, q)
316
+ };
317
+ };
318
+ if (n ? !Array.isArray(_) || !_.length : D && (!te && (ie || N(_)) || K(_) && !_ || ge && !nt(f).isValid || le && !ut(f).isValid)) {
319
+ const { value: F, message: m } = W(D) ? { value: !!D, message: D } : ae(D);
320
+ if (F && (R[I] = {
321
+ type: X.required,
322
+ message: m,
323
+ ref: J,
324
+ ...j(X.required, m)
325
+ }, !a))
326
+ return Q(m), R;
327
+ }
328
+ if (!ie && (!N(b) || !N(V))) {
329
+ let F, m;
330
+ const L = ae(V), U = ae(b);
331
+ if (!N(_) && !isNaN(_)) {
332
+ const H = o.valueAsNumber || _ && +_;
333
+ N(L.value) || (F = H > L.value), N(U.value) || (m = H < U.value);
334
+ } else {
335
+ const H = o.valueAsDate || new Date(_), q = (fe) => /* @__PURE__ */ new Date((/* @__PURE__ */ new Date()).toDateString() + " " + fe), ue = o.type == "time", oe = o.type == "week";
336
+ W(L.value) && _ && (F = ue ? q(_) > q(L.value) : oe ? _ > L.value : H > new Date(L.value)), W(U.value) && _ && (m = ue ? q(_) < q(U.value) : oe ? _ < U.value : H < new Date(U.value));
337
+ }
338
+ if ((F || m) && (ve(!!F, L.message, U.message, X.max, X.min), !a))
339
+ return Q(R[I].message), R;
340
+ }
341
+ if ((w || S) && !ie && (W(_) || n && Array.isArray(_))) {
342
+ const F = ae(w), m = ae(S), L = !N(F.value) && _.length > +F.value, U = !N(m.value) && _.length < +m.value;
343
+ if ((L || U) && (ve(L, F.message, m.message), !a))
344
+ return Q(R[I].message), R;
345
+ }
346
+ if (v && !ie && W(_)) {
347
+ const { value: F, message: m } = ae(v);
348
+ if (Ve(F) && !_.match(F) && (R[I] = {
349
+ type: X.pattern,
350
+ message: m,
351
+ ref: o,
352
+ ...j(X.pattern, m)
353
+ }, !a))
354
+ return Q(m), R;
355
+ }
356
+ if (P) {
357
+ if (Z(P)) {
358
+ const F = await P(_, t), m = et(F, J);
359
+ if (m && (R[I] = {
360
+ ...m,
361
+ ...j(X.validate, m.message)
362
+ }, !a))
363
+ return Q(m.message), R;
364
+ } else if (T(P)) {
365
+ let F = {};
366
+ for (const m in P) {
367
+ if (!B(F) && !a)
368
+ break;
369
+ const L = et(await P[m](_, t), J, m);
370
+ L && (F = {
371
+ ...L,
372
+ ...j(m, L.message)
373
+ }, Q(L.message), a && (R[I] = F));
374
+ }
375
+ if (!B(F) && (R[I] = {
376
+ ref: J,
377
+ ...F
378
+ }, !a))
379
+ return R;
380
+ }
381
+ }
382
+ return Q(!0), R;
383
+ };
384
+ const qt = {
385
+ mode: z.onSubmit,
386
+ reValidateMode: z.onChange,
387
+ shouldFocusError: !0
388
+ };
389
+ function pt(e = {}) {
390
+ let r = {
391
+ ...qt,
392
+ ...e
393
+ }, t = {
394
+ submitCount: 0,
395
+ isDirty: !1,
396
+ isReady: !1,
397
+ isLoading: Z(r.defaultValues),
398
+ isValidating: !1,
399
+ isSubmitted: !1,
400
+ isSubmitting: !1,
401
+ isSubmitSuccessful: !1,
402
+ isValid: !1,
403
+ touchedFields: {},
404
+ dirtyFields: {},
405
+ validatingFields: {},
406
+ errors: r.errors || {},
407
+ disabled: r.disabled || !1
408
+ }, a = {}, u = T(r.defaultValues) || T(r.values) ? O(r.defaultValues || r.values) || {} : {}, n = r.shouldUnregister ? {} : O(u), o = {
409
+ action: !1,
410
+ mount: !1,
411
+ watch: !1,
412
+ keepIsValid: !1
413
+ }, f = {
414
+ mount: /* @__PURE__ */ new Set(),
415
+ disabled: /* @__PURE__ */ new Set(),
416
+ unMount: /* @__PURE__ */ new Set(),
417
+ array: /* @__PURE__ */ new Set(),
418
+ watch: /* @__PURE__ */ new Set()
419
+ }, D, w = 0;
420
+ const S = {
421
+ isDirty: !1,
422
+ dirtyFields: !1,
423
+ validatingFields: !1,
424
+ touchedFields: !1,
425
+ isValidating: !1,
426
+ isValid: !1,
427
+ errors: !1
428
+ }, b = {
429
+ ...S
430
+ };
431
+ let V = {
432
+ ...b
433
+ };
434
+ const v = {
435
+ array: He(),
436
+ state: He()
437
+ }, P = r.criteriaMode === z.all, I = (s) => (i) => {
438
+ clearTimeout(w), w = setTimeout(s, i);
439
+ }, Y = async (s) => {
440
+ if (!o.keepIsValid && !r.disabled && (b.isValid || V.isValid || s)) {
441
+ let i;
442
+ r.resolver ? (i = B((await te()).errors), $()) : i = await j(a, !0), i !== t.isValid && v.state.next({
443
+ isValid: i
444
+ });
445
+ }
446
+ }, $ = (s, i) => {
447
+ !r.disabled && (b.isValidating || b.validatingFields || V.isValidating || V.validatingFields) && ((s || Array.from(f.mount)).forEach((l) => {
448
+ l && (i ? k(t.validatingFields, l, i) : C(t.validatingFields, l));
449
+ }), v.state.next({
450
+ validatingFields: t.validatingFields,
451
+ isValidating: !B(t.validatingFields)
452
+ }));
453
+ }, _ = (s, i = [], l, y, d = !0, c = !0) => {
454
+ if (y && l && !r.disabled) {
455
+ if (o.action = !0, c && Array.isArray(h(a, s))) {
456
+ const g = l(h(a, s), y.argA, y.argB);
457
+ d && k(a, s, g);
458
+ }
459
+ if (c && Array.isArray(h(t.errors, s))) {
460
+ const g = l(h(t.errors, s), y.argA, y.argB);
461
+ d && k(t.errors, s, g), It(t.errors, s);
462
+ }
463
+ if ((b.touchedFields || V.touchedFields) && c && Array.isArray(h(t.touchedFields, s))) {
464
+ const g = l(h(t.touchedFields, s), y.argA, y.argB);
465
+ d && k(t.touchedFields, s, g);
466
+ }
467
+ (b.dirtyFields || V.dirtyFields) && (t.dirtyFields = ne(u, n)), v.state.next({
468
+ name: s,
469
+ isDirty: F(s, i),
470
+ dirtyFields: t.dirtyFields,
471
+ errors: t.errors,
472
+ isValid: t.isValid
473
+ });
474
+ } else
475
+ k(n, s, i);
476
+ }, J = (s, i) => {
477
+ k(t.errors, s, i), v.state.next({
478
+ errors: t.errors
479
+ });
480
+ }, Q = (s) => {
481
+ t.errors = s, v.state.next({
482
+ errors: t.errors,
483
+ isValid: !1
484
+ });
485
+ }, R = (s, i, l, y) => {
486
+ const d = h(a, s);
487
+ if (d) {
488
+ const c = h(n, s, E(l) ? h(u, s) : l);
489
+ E(c) || y && y.defaultChecked || i ? k(n, s, i ? c : Ye(d._f)) : U(s, c), o.mount && !o.action && Y();
490
+ }
491
+ }, le = (s, i, l, y, d) => {
492
+ let c = !1, g = !1;
493
+ const A = {
494
+ name: s
495
+ };
496
+ if (!r.disabled) {
497
+ if (!l || y) {
498
+ (b.isDirty || V.isDirty) && (g = t.isDirty, t.isDirty = A.isDirty = F(), c = g !== A.isDirty);
499
+ const x = ee(h(u, s), i);
500
+ g = !!h(t.dirtyFields, s), x ? C(t.dirtyFields, s) : k(t.dirtyFields, s, !0), A.dirtyFields = t.dirtyFields, c = c || (b.dirtyFields || V.dirtyFields) && g !== !x;
501
+ }
502
+ if (l) {
503
+ const x = h(t.touchedFields, s);
504
+ x || (k(t.touchedFields, s, l), A.touchedFields = t.touchedFields, c = c || (b.touchedFields || V.touchedFields) && x !== l);
505
+ }
506
+ c && d && v.state.next(A);
507
+ }
508
+ return c ? A : {};
509
+ }, ge = (s, i, l, y) => {
510
+ const d = h(t.errors, s), c = (b.isValid || V.isValid) && K(i) && t.isValid !== i;
511
+ if (r.delayError && l ? (D = I(() => J(s, l)), D(r.delayError)) : (clearTimeout(w), D = null, l ? k(t.errors, s, l) : C(t.errors, s)), (l ? !ee(d, l) : d) || !B(y) || c) {
512
+ const g = {
513
+ ...y,
514
+ ...c && K(i) ? { isValid: i } : {},
515
+ errors: t.errors,
516
+ name: s
517
+ };
518
+ t = {
519
+ ...t,
520
+ ...g
521
+ }, v.state.next(g);
522
+ }
523
+ }, te = async (s) => ($(s, !0), await r.resolver(n, r.context, Lt(s || f.mount, a, r.criteriaMode, r.shouldUseNativeValidation))), ie = async (s) => {
524
+ const { errors: i } = await te(s);
525
+ if ($(s), s)
526
+ for (const l of s) {
527
+ const y = h(i, l);
528
+ y ? k(t.errors, l, y) : C(t.errors, l);
529
+ }
530
+ else
531
+ t.errors = i;
532
+ return i;
533
+ }, j = async (s, i, l = {
534
+ valid: !0
535
+ }) => {
536
+ for (const y in s) {
537
+ const d = s[y];
538
+ if (d) {
539
+ const { _f: c, ...g } = d;
540
+ if (c) {
541
+ const A = f.array.has(c.name), x = d._f && Ot(d._f);
542
+ x && b.validatingFields && $([c.name], !0);
543
+ const M = await tt(d, f.disabled, n, P, r.shouldUseNativeValidation && !i, A);
544
+ if (x && b.validatingFields && $([c.name]), M[c.name] && (l.valid = !1, i || e.shouldUseNativeValidation))
545
+ break;
546
+ !i && (h(M, c.name) ? A ? Nt(t.errors, M, c.name) : k(t.errors, c.name, M[c.name]) : C(t.errors, c.name));
547
+ }
548
+ !B(g) && await j(g, i, l);
549
+ }
550
+ }
551
+ return l.valid;
552
+ }, ve = () => {
553
+ for (const s of f.unMount) {
554
+ const i = h(a, s);
555
+ i && (i._f.refs ? i._f.refs.every((l) => !De(l)) : !De(i._f.ref)) && _e(s);
556
+ }
557
+ f.unMount = /* @__PURE__ */ new Set();
558
+ }, F = (s, i) => !r.disabled && (s && i && k(n, s, i), !ee(Oe(), u)), m = (s, i, l) => kt(s, f, {
559
+ ...o.mount ? n : E(i) ? u : W(s) ? { [s]: i } : i
560
+ }, l, i), L = (s) => Ce(h(o.mount ? n : u, s, r.shouldUnregister ? h(u, s, []) : [])), U = (s, i, l = {}) => {
561
+ const y = h(a, s);
562
+ let d = i;
563
+ if (y) {
564
+ const c = y._f;
565
+ c && (!c.disabled && k(n, s, lt(i, c)), d = be(c.ref) && N(i) ? "" : i, it(c.ref) ? [...c.ref.options].forEach((g) => g.selected = d.includes(g.value)) : c.refs ? he(c.ref) ? c.refs.forEach((g) => {
566
+ (!g.defaultChecked || !g.disabled) && (Array.isArray(d) ? g.checked = !!d.find((A) => A === g.value) : g.checked = d === g.value || !!d);
567
+ }) : c.refs.forEach((g) => g.checked = g.value === d) : Re(c.ref) ? c.ref.value = "" : (c.ref.value = d, c.ref.type || v.state.next({
568
+ name: s,
569
+ values: O(n)
570
+ })));
571
+ }
572
+ (l.shouldDirty || l.shouldTouch) && le(s, d, l.shouldTouch, l.shouldDirty, !0), l.shouldValidate && fe(s);
573
+ }, H = (s, i, l) => {
574
+ for (const y in i) {
575
+ if (!i.hasOwnProperty(y))
576
+ return;
577
+ const d = i[y], c = s + "." + y, g = h(a, c);
578
+ (f.array.has(s) || T(d) || g && !g._f) && !se(d) ? H(c, d, l) : U(c, d, l);
579
+ }
580
+ }, q = (s, i, l = {}) => {
581
+ const y = h(a, s), d = f.array.has(s), c = O(i);
582
+ k(n, s, c), d ? (v.array.next({
583
+ name: s,
584
+ values: O(n)
585
+ }), (b.isDirty || b.dirtyFields || V.isDirty || V.dirtyFields) && l.shouldDirty && v.state.next({
586
+ name: s,
587
+ dirtyFields: ne(u, n),
588
+ isDirty: F(s, c)
589
+ })) : y && !y._f && !N(c) ? H(s, c, l) : U(s, c, l), Xe(s, f) ? v.state.next({
590
+ ...t,
591
+ name: s,
592
+ values: O(n)
593
+ }) : v.state.next({
594
+ name: o.mount ? s : void 0,
595
+ values: O(n)
596
+ });
597
+ }, ue = async (s) => {
598
+ o.mount = !0;
599
+ const i = s.target;
600
+ let l = i.name, y = !0;
601
+ const d = h(a, l), c = (x) => {
602
+ y = Number.isNaN(x) || se(x) && isNaN(x.getTime()) || ee(x, h(n, l, x));
603
+ }, g = Je(r.mode), A = Je(r.reValidateMode);
604
+ if (d) {
605
+ let x, M;
606
+ const re = i.type ? Ye(d._f) : Ft(s), G = s.type === je.BLUR || s.type === je.FOCUS_OUT, vt = !Pt(d._f) && !r.resolver && !h(t.errors, l) && !d._f.deps || Bt(G, h(t.touchedFields, l), t.isSubmitted, A, g), Ae = Xe(l, f, G);
607
+ k(n, l, re), G ? (!i || !i.readOnly) && (d._f.onBlur && d._f.onBlur(s), D && D(0)) : d._f.onChange && d._f.onChange(s);
608
+ const xe = le(l, re, G), bt = !B(xe) || Ae;
609
+ if (!G && v.state.next({
610
+ name: l,
611
+ type: s.type,
612
+ values: O(n)
613
+ }), vt)
614
+ return (b.isValid || V.isValid) && (r.mode === "onBlur" ? G && Y() : G || Y()), bt && v.state.next({ name: l, ...Ae ? {} : xe });
615
+ if (!G && Ae && v.state.next({ ...t }), r.resolver) {
616
+ const { errors: We } = await te([l]);
617
+ if ($([l]), c(re), y) {
618
+ const Vt = Ge(t.errors, a, l), $e = Ge(We, a, Vt.name || l);
619
+ x = $e.error, l = $e.name, M = B(We);
620
+ }
621
+ } else
622
+ $([l], !0), x = (await tt(d, f.disabled, n, P, r.shouldUseNativeValidation))[l], $([l]), c(re), y && (x ? M = !1 : (b.isValid || V.isValid) && (M = await j(a, !0)));
623
+ y && (d._f.deps && (!Array.isArray(d._f.deps) || d._f.deps.length > 0) && fe(d._f.deps), ge(l, M, x, xe));
624
+ }
625
+ }, oe = (s, i) => {
626
+ if (h(t.errors, i) && s.focus)
627
+ return s.focus(), 1;
628
+ }, fe = async (s, i = {}) => {
629
+ let l, y;
630
+ const d = de(s);
631
+ if (r.resolver) {
632
+ const c = await ie(E(s) ? s : d);
633
+ l = B(c), y = s ? !d.some((g) => h(c, g)) : l;
634
+ } else s ? (y = (await Promise.all(d.map(async (c) => {
635
+ const g = h(a, c);
636
+ return await j(g && g._f ? { [c]: g } : g);
637
+ }))).every(Boolean), !(!y && !t.isValid) && Y()) : y = l = await j(a);
638
+ return v.state.next({
639
+ ...!W(s) || (b.isValid || V.isValid) && l !== t.isValid ? {} : { name: s },
640
+ ...r.resolver || !s ? { isValid: l } : {},
641
+ errors: t.errors
642
+ }), i.shouldFocus && !y && ye(a, oe, s ? d : f.mount), y;
643
+ }, Oe = (s, i) => {
644
+ let l = {
645
+ ...o.mount ? n : u
646
+ };
647
+ return i && (l = st(i.dirtyFields ? t.dirtyFields : t.touchedFields, l)), E(s) ? l : W(s) ? h(l, s) : s.map((y) => h(l, y));
648
+ }, Pe = (s, i) => ({
649
+ invalid: !!h((i || t).errors, s),
650
+ isDirty: !!h((i || t).dirtyFields, s),
651
+ error: h((i || t).errors, s),
652
+ isValidating: !!h(t.validatingFields, s),
653
+ isTouched: !!h((i || t).touchedFields, s)
654
+ }), ot = (s) => {
655
+ s && de(s).forEach((i) => C(t.errors, i)), v.state.next({
656
+ errors: s ? t.errors : {}
657
+ });
658
+ }, Ue = (s, i, l) => {
659
+ const y = (h(a, s, { _f: {} })._f || {}).ref, d = h(t.errors, s) || {}, { ref: c, message: g, type: A, ...x } = d;
660
+ k(t.errors, s, {
661
+ ...x,
662
+ ...i,
663
+ ref: y
664
+ }), v.state.next({
665
+ name: s,
666
+ errors: t.errors,
667
+ isValid: !1
668
+ }), l && l.shouldFocus && y && y.focus && y.focus();
669
+ }, ft = (s, i) => Z(s) ? v.state.subscribe({
670
+ next: (l) => "values" in l && s(m(void 0, i), l)
671
+ }) : m(s, i, !0), Me = (s) => v.state.subscribe({
672
+ next: (i) => {
673
+ Mt(s.name, i.name, s.exact) && Ut(i, s.formState || b, gt, s.reRenderRoot) && s.callback({
674
+ values: { ...n },
675
+ ...t,
676
+ ...i,
677
+ defaultValues: u
678
+ });
679
+ }
680
+ }).unsubscribe, ct = (s) => (o.mount = !0, V = {
681
+ ...V,
682
+ ...s.formState
683
+ }, Me({
684
+ ...s,
685
+ formState: {
686
+ ...S,
687
+ ...s.formState
688
+ }
689
+ })), _e = (s, i = {}) => {
690
+ for (const l of s ? de(s) : f.mount)
691
+ f.mount.delete(l), f.array.delete(l), i.keepValue || (C(a, l), C(n, l)), !i.keepError && C(t.errors, l), !i.keepDirty && C(t.dirtyFields, l), !i.keepTouched && C(t.touchedFields, l), !i.keepIsValidating && C(t.validatingFields, l), !r.shouldUnregister && !i.keepDefaultValue && C(u, l);
692
+ v.state.next({
693
+ values: O(n)
694
+ }), v.state.next({
695
+ ...t,
696
+ ...i.keepDirty ? { isDirty: F() } : {}
697
+ }), !i.keepIsValid && Y();
698
+ }, Be = ({ disabled: s, name: i }) => {
699
+ (K(s) && o.mount || s || f.disabled.has(i)) && (s ? f.disabled.add(i) : f.disabled.delete(i));
700
+ }, me = (s, i = {}) => {
701
+ let l = h(a, s);
702
+ const y = K(i.disabled) || K(r.disabled);
703
+ return k(a, s, {
704
+ ...l || {},
705
+ _f: {
706
+ ...l && l._f ? l._f : { ref: { name: s } },
707
+ name: s,
708
+ mount: !0,
709
+ ...i
710
+ }
711
+ }), f.mount.add(s), l ? Be({
712
+ disabled: K(i.disabled) ? i.disabled : r.disabled,
713
+ name: s
714
+ }) : R(s, !0, i.value), {
715
+ ...y ? { disabled: i.disabled || r.disabled } : {},
716
+ ...r.progressive ? {
717
+ required: !!i.required,
718
+ min: ce(i.min),
719
+ max: ce(i.max),
720
+ minLength: ce(i.minLength),
721
+ maxLength: ce(i.maxLength),
722
+ pattern: ce(i.pattern)
723
+ } : {},
724
+ name: s,
725
+ onChange: ue,
726
+ onBlur: ue,
727
+ ref: (d) => {
728
+ if (d) {
729
+ me(s, i), l = h(a, s);
730
+ const c = E(d.value) && d.querySelectorAll && d.querySelectorAll("input,select,textarea")[0] || d, g = St(c), A = l._f.refs || [];
731
+ if (g ? A.find((x) => x === c) : c === l._f.ref)
732
+ return;
733
+ k(a, s, {
734
+ _f: {
735
+ ...l._f,
736
+ ...g ? {
737
+ refs: [
738
+ ...A.filter(De),
739
+ c,
740
+ ...Array.isArray(h(u, s)) ? [{}] : []
741
+ ],
742
+ ref: { type: c.type, name: s }
743
+ } : { ref: c }
744
+ }
745
+ }), R(s, !1, void 0, c);
746
+ } else
747
+ l = h(a, s, {}), l._f && (l._f.mount = !1), (r.shouldUnregister || i.shouldUnregister) && !(mt(f.array, s) && o.action) && f.unMount.add(s);
748
+ }
749
+ };
750
+ }, we = () => r.shouldFocusError && ye(a, oe, f.mount), dt = (s) => {
751
+ K(s) && (v.state.next({ disabled: s }), ye(a, (i, l) => {
752
+ const y = h(a, l);
753
+ y && (i.disabled = y._f.disabled || s, Array.isArray(y._f.refs) && y._f.refs.forEach((d) => {
754
+ d.disabled = y._f.disabled || s;
755
+ }));
756
+ }, 0, !1));
757
+ }, Ie = (s, i) => async (l) => {
758
+ let y;
759
+ l && (l.preventDefault && l.preventDefault(), l.persist && l.persist());
760
+ let d = O(n);
761
+ if (v.state.next({
762
+ isSubmitting: !0
763
+ }), r.resolver) {
764
+ const { errors: c, values: g } = await te();
765
+ $(), t.errors = c, d = O(g);
766
+ } else
767
+ await j(a);
768
+ if (f.disabled.size)
769
+ for (const c of f.disabled)
770
+ C(d, c);
771
+ if (C(t.errors, "root"), B(t.errors)) {
772
+ v.state.next({
773
+ errors: {}
774
+ });
775
+ try {
776
+ await s(d, l);
777
+ } catch (c) {
778
+ y = c;
779
+ }
780
+ } else
781
+ i && await i({ ...t.errors }, l), we(), setTimeout(we);
782
+ if (v.state.next({
783
+ isSubmitted: !0,
784
+ isSubmitting: !1,
785
+ isSubmitSuccessful: B(t.errors) && !y,
786
+ submitCount: t.submitCount + 1,
787
+ errors: t.errors
788
+ }), y)
789
+ throw y;
790
+ }, yt = (s, i = {}) => {
791
+ h(a, s) && (E(i.defaultValue) ? q(s, O(h(u, s))) : (q(s, i.defaultValue), k(u, s, O(i.defaultValue))), i.keepTouched || C(t.touchedFields, s), i.keepDirty || (C(t.dirtyFields, s), t.isDirty = i.defaultValue ? F(s, O(h(u, s))) : F()), i.keepError || (C(t.errors, s), b.isValid && Y()), v.state.next({ ...t }));
792
+ }, Ne = (s, i = {}) => {
793
+ const l = s ? O(s) : u, y = O(l), d = B(s), c = d ? u : y;
794
+ if (i.keepDefaultValues || (u = l), !i.keepValues) {
795
+ if (i.keepDirtyValues) {
796
+ const g = /* @__PURE__ */ new Set([
797
+ ...f.mount,
798
+ ...Object.keys(ne(u, n))
799
+ ]);
800
+ for (const A of Array.from(g)) {
801
+ const x = h(t.dirtyFields, A), M = h(n, A), re = h(c, A);
802
+ x && !E(M) ? k(c, A, M) : !x && !E(re) && q(A, re);
803
+ }
804
+ } else {
805
+ if (Se && E(s))
806
+ for (const g of f.mount) {
807
+ const A = h(a, g);
808
+ if (A && A._f) {
809
+ const x = Array.isArray(A._f.refs) ? A._f.refs[0] : A._f.ref;
810
+ if (be(x)) {
811
+ const M = x.closest("form");
812
+ if (M) {
813
+ M.reset();
814
+ break;
815
+ }
816
+ }
817
+ }
818
+ }
819
+ if (i.keepFieldsRef)
820
+ for (const g of f.mount)
821
+ q(g, h(c, g));
822
+ else
823
+ a = {};
824
+ }
825
+ n = r.shouldUnregister ? i.keepDefaultValues ? O(u) : {} : O(c), v.array.next({
826
+ values: { ...c }
827
+ }), v.state.next({
828
+ values: { ...c }
829
+ });
830
+ }
831
+ f = {
832
+ mount: i.keepDirtyValues ? f.mount : /* @__PURE__ */ new Set(),
833
+ unMount: /* @__PURE__ */ new Set(),
834
+ array: /* @__PURE__ */ new Set(),
835
+ disabled: /* @__PURE__ */ new Set(),
836
+ watch: /* @__PURE__ */ new Set(),
837
+ watchAll: !1,
838
+ focus: ""
839
+ }, o.mount = !b.isValid || !!i.keepIsValid || !!i.keepDirtyValues || !r.shouldUnregister && !B(c), o.watch = !!r.shouldUnregister, o.keepIsValid = !!i.keepIsValid, o.action = !1, i.keepErrors || (t.errors = {}), v.state.next({
840
+ submitCount: i.keepSubmitCount ? t.submitCount : 0,
841
+ isDirty: d ? !1 : i.keepDirty ? t.isDirty : !!(i.keepDefaultValues && !ee(s, u)),
842
+ isSubmitted: i.keepIsSubmitted ? t.isSubmitted : !1,
843
+ dirtyFields: d ? {} : i.keepDirtyValues ? i.keepDefaultValues && n ? ne(u, n) : t.dirtyFields : i.keepDefaultValues && s ? ne(u, s) : i.keepDirty ? t.dirtyFields : {},
844
+ touchedFields: i.keepTouched ? t.touchedFields : {},
845
+ errors: i.keepErrors ? t.errors : {},
846
+ isSubmitSuccessful: i.keepIsSubmitSuccessful ? t.isSubmitSuccessful : !1,
847
+ isSubmitting: !1,
848
+ defaultValues: u
849
+ });
850
+ }, qe = (s, i) => Ne(Z(s) ? s(n) : s, { ...r.resetOptions, ...i }), ht = (s, i = {}) => {
851
+ const l = h(a, s), y = l && l._f;
852
+ if (y) {
853
+ const d = y.refs ? y.refs[0] : y.ref;
854
+ d.focus && setTimeout(() => {
855
+ d.focus(), i.shouldSelect && Z(d.select) && d.select();
856
+ });
857
+ }
858
+ }, gt = (s) => {
859
+ t = {
860
+ ...t,
861
+ ...s
862
+ };
863
+ }, pe = {
864
+ control: {
865
+ register: me,
866
+ unregister: _e,
867
+ getFieldState: Pe,
868
+ handleSubmit: Ie,
869
+ setError: Ue,
870
+ _subscribe: Me,
871
+ _runSchema: te,
872
+ _updateIsValidating: $,
873
+ _focusError: we,
874
+ _getWatch: m,
875
+ _getDirty: F,
876
+ _setValid: Y,
877
+ _setFieldArray: _,
878
+ _setDisabledField: Be,
879
+ _setErrors: Q,
880
+ _getFieldArray: L,
881
+ _reset: Ne,
882
+ _resetDefaultValues: () => Z(r.defaultValues) && r.defaultValues().then((s) => {
883
+ qe(s, r.resetOptions), v.state.next({
884
+ isLoading: !1
885
+ });
886
+ }),
887
+ _removeUnmounted: ve,
888
+ _disableForm: dt,
889
+ _subjects: v,
890
+ _proxyFormState: b,
891
+ get _fields() {
892
+ return a;
893
+ },
894
+ get _formValues() {
895
+ return n;
896
+ },
897
+ get _state() {
898
+ return o;
899
+ },
900
+ set _state(s) {
901
+ o = s;
902
+ },
903
+ get _defaultValues() {
904
+ return u;
905
+ },
906
+ get _names() {
907
+ return f;
908
+ },
909
+ set _names(s) {
910
+ f = s;
911
+ },
912
+ get _formState() {
913
+ return t;
914
+ },
915
+ get _options() {
916
+ return r;
917
+ },
918
+ set _options(s) {
919
+ r = {
920
+ ...r,
921
+ ...s
922
+ };
923
+ }
924
+ },
925
+ subscribe: ct,
926
+ trigger: fe,
927
+ register: me,
928
+ handleSubmit: Ie,
929
+ watch: ft,
930
+ setValue: q,
931
+ getValues: Oe,
932
+ reset: qe,
933
+ resetField: yt,
934
+ clearErrors: ot,
935
+ unregister: _e,
936
+ setError: Ue,
937
+ setFocus: ht,
938
+ getFieldState: Pe
939
+ };
940
+ return {
941
+ ...pe,
942
+ formControl: pe
943
+ };
944
+ }
945
+ function Zt(e = {}) {
946
+ const r = p.useRef(void 0), t = p.useRef(void 0), [a, u] = p.useState({
947
+ isDirty: !1,
948
+ isValidating: !1,
949
+ isLoading: Z(e.defaultValues),
950
+ isSubmitted: !1,
951
+ isSubmitting: !1,
952
+ isSubmitSuccessful: !1,
953
+ isValid: !1,
954
+ submitCount: 0,
955
+ dirtyFields: {},
956
+ touchedFields: {},
957
+ validatingFields: {},
958
+ errors: e.errors || {},
959
+ disabled: e.disabled || !1,
960
+ isReady: !1,
961
+ defaultValues: Z(e.defaultValues) ? void 0 : e.defaultValues
962
+ });
963
+ if (!r.current)
964
+ if (e.formControl)
965
+ r.current = {
966
+ ...e.formControl,
967
+ formState: a
968
+ }, e.defaultValues && !Z(e.defaultValues) && e.formControl.reset(e.defaultValues, e.resetOptions);
969
+ else {
970
+ const { formControl: o, ...f } = pt(e);
971
+ r.current = {
972
+ ...f,
973
+ formState: a
974
+ };
975
+ }
976
+ const n = r.current.control;
977
+ return n._options = e, Dt(() => {
978
+ const o = n._subscribe({
979
+ formState: n._proxyFormState,
980
+ callback: () => u({ ...n._formState }),
981
+ reRenderRoot: !0
982
+ });
983
+ return u((f) => ({
984
+ ...f,
985
+ isReady: !0
986
+ })), n._formState.isReady = !0, o;
987
+ }, [n]), p.useEffect(() => n._disableForm(e.disabled), [n, e.disabled]), p.useEffect(() => {
988
+ e.mode && (n._options.mode = e.mode), e.reValidateMode && (n._options.reValidateMode = e.reValidateMode);
989
+ }, [n, e.mode, e.reValidateMode]), p.useEffect(() => {
990
+ e.errors && (n._setErrors(e.errors), n._focusError());
991
+ }, [n, e.errors]), p.useEffect(() => {
992
+ e.shouldUnregister && n._subjects.state.next({
993
+ values: n._getWatch()
994
+ });
995
+ }, [n, e.shouldUnregister]), p.useEffect(() => {
996
+ if (n._proxyFormState.isDirty) {
997
+ const o = n._getDirty();
998
+ o !== a.isDirty && n._subjects.state.next({
999
+ isDirty: o
1000
+ });
1001
+ }
1002
+ }, [n, a.isDirty]), p.useEffect(() => {
1003
+ var o;
1004
+ e.values && !ee(e.values, t.current) ? (n._reset(e.values, {
1005
+ keepFieldsRef: !0,
1006
+ ...n._options.resetOptions
1007
+ }), !((o = n._options.resetOptions) === null || o === void 0) && o.keepIsValid || n._setValid(), t.current = e.values, u((f) => ({ ...f }))) : n._resetDefaultValues();
1008
+ }, [n, e.values]), p.useEffect(() => {
1009
+ n._state.mount || (n._setValid(), n._state.mount = !0), n._state.watch && (n._state.watch = !1, n._subjects.state.next({ ...n._formState })), n._removeUnmounted();
1010
+ }), r.current.formState = xt(a, n), r.current;
1011
+ }
1012
+ function Wt(e, r) {
1013
+ const t = [];
1014
+ if (e.required && (r == null || r === "" || Array.isArray(r) && r.length === 0))
1015
+ return t.push(`${e.label} is required`), { valid: !1, errors: t };
1016
+ if (r == null || r === "")
1017
+ return { valid: !0, errors: [] };
1018
+ if ("length" in e && typeof e.length == "number" && typeof r == "string" && r.length > e.length && t.push(`${e.label} must be at most ${e.length} characters`), "integerPart" in e && typeof r == "number") {
1019
+ const a = Math.floor(Math.abs(r)), u = e.integerPart ?? 9;
1020
+ a.toString().length > u && t.push(`${e.label} integer part must be at most ${u} digits`);
1021
+ const n = e.fractionPart;
1022
+ n !== void 0 && (r.toString().split(".")[1] ?? "").length > n && t.push(`${e.label} can have at most ${n} decimal places`);
1023
+ }
1024
+ return t.length > 0 ? { valid: !1, errors: t } : { valid: !0, errors: [] };
1025
+ }
1026
+ function zt(e, r) {
1027
+ return async (t, a, u) => {
1028
+ var D;
1029
+ const n = {}, o = e.getFields(), f = (u == null ? void 0 : u.names) ?? Object.keys(o);
1030
+ for (const w of f) {
1031
+ if (w === "_id" || (D = o[w]) != null && D.readOnly) continue;
1032
+ const S = o[w];
1033
+ if (!S) continue;
1034
+ let b = t[w];
1035
+ if ("integerPart" in S && typeof b == "string" && b !== "") {
1036
+ const v = Number(b);
1037
+ isNaN(v) || (b = v, t[w] = v);
1038
+ }
1039
+ if (!S.required && (b == null || b === "" || Array.isArray(b) && b.length === 0))
1040
+ continue;
1041
+ const V = S.validate(b);
1042
+ if (!V.valid && V.errors.length > 0) {
1043
+ n[w] = {
1044
+ type: "validate",
1045
+ message: V.errors[0] || `${w} is invalid`
1046
+ };
1047
+ continue;
1048
+ }
1049
+ if ((r == null ? void 0 : r.enableConstraintValidation) !== !1) {
1050
+ const v = Wt(S, b);
1051
+ if (!v.valid && v.errors.length > 0) {
1052
+ n[w] = {
1053
+ type: "constraint",
1054
+ message: v.errors[0]
1055
+ };
1056
+ continue;
1057
+ }
1058
+ }
1059
+ if (e.hasMetadata()) {
1060
+ const v = e.validateFieldExpression(
1061
+ w,
1062
+ b,
1063
+ t
1064
+ );
1065
+ !v.valid && v.errors.length > 0 && (n[w] = {
1066
+ type: "validate",
1067
+ message: v.errors[0]
1068
+ });
1069
+ }
1070
+ }
1071
+ return Object.keys(n).length === 0 ? { values: t, errors: {} } : { values: {}, errors: n };
1072
+ };
1073
+ }
1074
+ function $t(e, r) {
1075
+ const t = e.meta.Type;
1076
+ if (typeof r == "string" && t === "Number")
1077
+ return r === "" ? void 0 : Number(r);
1078
+ if (!(typeof r == "string" && r === "" && (t === "Date" || t === "DateTime"))) {
1079
+ if (typeof r == "string" && r !== "" && t === "DateTime") {
1080
+ let a = r;
1081
+ return a.endsWith("Z") && (a = a.slice(0, -1)), ((a.split("T")[1] || "").match(/:/g) || []).length === 1 && (a += ":00"), a + "Z";
1082
+ }
1083
+ return r;
1084
+ }
1085
+ }
1086
+ function Kt(e, r) {
1087
+ var a;
1088
+ const t = { ...r };
1089
+ for (const [u, n] of Object.entries(t))
1090
+ typeof n == "string" && ((a = e[u]) == null ? void 0 : a.meta.Type) === "DateTime" && n.endsWith("Z") && (t[u] = n.slice(0, -1));
1091
+ return t;
1092
+ }
1093
+ function Yt(e) {
1094
+ const { apiFn: r, allFields: t, readonlyFieldNames: a, rhf: u, isComputingRef: n } = e;
1095
+ return async (o) => {
1096
+ if (!n.current) {
1097
+ n.current = !0;
1098
+ try {
1099
+ if (!await u.trigger(o)) return;
1100
+ const D = u.getValues(o), w = t[o], S = w ? $t(w, D) : D, b = await r(o, S);
1101
+ if (b === void 0) return;
1102
+ if (u.resetField(o, {
1103
+ defaultValue: D,
1104
+ keepTouched: !0,
1105
+ keepError: !0
1106
+ }), b && typeof b == "object") {
1107
+ const V = b.Data ?? b;
1108
+ if (V && typeof V == "object") {
1109
+ const v = new Set(a);
1110
+ for (const P of Object.keys(V))
1111
+ v.has(P) && V[P] !== void 0 && u.getValues(P) !== V[P] && u.setValue(
1112
+ P,
1113
+ V[P],
1114
+ { shouldDirty: !1, shouldValidate: !1 }
1115
+ );
1116
+ }
1117
+ }
1118
+ } catch (f) {
1119
+ console.warn("syncField failed:", f);
1120
+ } finally {
1121
+ n.current = !1;
1122
+ }
1123
+ }
1124
+ };
1125
+ }
1126
+ function Jt(e) {
1127
+ const { rhf: r, allFields: t, syncField: a, syncOnBlur: u, syncOnChange: n } = e;
1128
+ return (o, f) => {
1129
+ const D = t[o], w = D ? D.readOnly : !1, S = r.register(o, {
1130
+ ...f,
1131
+ ...u ? {
1132
+ onBlur: async (b) => {
1133
+ var V;
1134
+ await ((V = f == null ? void 0 : f.onBlur) == null ? void 0 : V.call(f, b)), await a(o);
1135
+ }
1136
+ } : {},
1137
+ ...n ? {
1138
+ onChange: async (b) => {
1139
+ var V;
1140
+ await ((V = f == null ? void 0 : f.onChange) == null ? void 0 : V.call(f, b)), await a(o);
1141
+ }
1142
+ } : {},
1143
+ ...w ? { disabled: !0 } : {}
1144
+ });
1145
+ return w ? { ...S, disabled: !0 } : S;
1146
+ };
1147
+ }
1148
+ function Qt(e) {
1149
+ const { control: r, syncField: t, syncOnBlur: a, syncOnChange: u } = e;
1150
+ return new Proxy(r, {
1151
+ get(n, o, f) {
1152
+ return o === "register" ? (D, w) => {
1153
+ const S = n.register(D, w), b = S.onChange, V = S.onBlur;
1154
+ return {
1155
+ ...S,
1156
+ ...u ? {
1157
+ onChange: async (v) => {
1158
+ await b(v), await t(D);
1159
+ }
1160
+ } : {},
1161
+ ...a ? {
1162
+ onBlur: async (v) => {
1163
+ await V(v), await t(D);
1164
+ }
1165
+ } : {}
1166
+ };
1167
+ } : Reflect.get(n, o, f);
1168
+ }
1169
+ });
1170
+ }
1171
+ export {
1172
+ Kt as a,
1173
+ Yt as b,
1174
+ zt as c,
1175
+ Jt as d,
1176
+ Qt as e,
1177
+ $t as f,
1178
+ Zt as u,
1179
+ Wt as v
1180
+ };