@4riders/reform 3.0.24

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 (48) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +266 -0
  3. package/dist/index.d.ts +2715 -0
  4. package/dist/index.es.js +1715 -0
  5. package/dist/index.es.js.map +1 -0
  6. package/package.json +70 -0
  7. package/src/index.ts +90 -0
  8. package/src/reform/ArrayHelper.ts +164 -0
  9. package/src/reform/Form.tsx +81 -0
  10. package/src/reform/FormManager.ts +494 -0
  11. package/src/reform/Reform.ts +15 -0
  12. package/src/reform/components/BaseCheckboxField.tsx +72 -0
  13. package/src/reform/components/BaseDateField.tsx +84 -0
  14. package/src/reform/components/BaseRadioField.tsx +72 -0
  15. package/src/reform/components/BaseSelectField.tsx +103 -0
  16. package/src/reform/components/BaseTextAreaField.tsx +87 -0
  17. package/src/reform/components/BaseTextField.tsx +135 -0
  18. package/src/reform/components/InputHTMLProps.tsx +89 -0
  19. package/src/reform/observers/observer.ts +131 -0
  20. package/src/reform/observers/observerPath.ts +327 -0
  21. package/src/reform/observers/useObservers.ts +232 -0
  22. package/src/reform/useForm.ts +246 -0
  23. package/src/reform/useFormContext.tsx +37 -0
  24. package/src/reform/useFormField.ts +75 -0
  25. package/src/reform/useRender.ts +12 -0
  26. package/src/yop/MessageProvider.ts +204 -0
  27. package/src/yop/Metadata.ts +304 -0
  28. package/src/yop/ObjectsUtil.ts +811 -0
  29. package/src/yop/TypesUtil.ts +148 -0
  30. package/src/yop/ValidationContext.ts +207 -0
  31. package/src/yop/Yop.ts +430 -0
  32. package/src/yop/constraints/CommonConstraints.ts +124 -0
  33. package/src/yop/constraints/Constraint.ts +135 -0
  34. package/src/yop/constraints/MinMaxConstraints.ts +53 -0
  35. package/src/yop/constraints/OneOfConstraint.ts +40 -0
  36. package/src/yop/constraints/TestConstraint.ts +176 -0
  37. package/src/yop/decorators/array.ts +157 -0
  38. package/src/yop/decorators/boolean.ts +69 -0
  39. package/src/yop/decorators/date.ts +73 -0
  40. package/src/yop/decorators/email.ts +66 -0
  41. package/src/yop/decorators/file.ts +69 -0
  42. package/src/yop/decorators/id.ts +35 -0
  43. package/src/yop/decorators/ignored.ts +40 -0
  44. package/src/yop/decorators/instance.ts +110 -0
  45. package/src/yop/decorators/number.ts +73 -0
  46. package/src/yop/decorators/string.ts +90 -0
  47. package/src/yop/decorators/test.ts +41 -0
  48. package/src/yop/decorators/time.ts +112 -0
@@ -0,0 +1,1715 @@
1
+ import e, { useCallback as t, useEffect as n, useMemo as r, useReducer as i, useRef as a } from "react";
2
+ import { renderToStaticMarkup as o } from "react-dom/server";
3
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
4
+ //#region src/reform/ArrayHelper.ts
5
+ var l = class {
6
+ array;
7
+ constructor(e, t) {
8
+ this.form = e, this.path = t, this.array = e.getValue(t), Array.isArray(this.array) || (this.array = void 0);
9
+ }
10
+ isArray() {
11
+ return this.array != null;
12
+ }
13
+ append(e, t = !0) {
14
+ this.array.push(e), this.form.touch(this.path), this.commit(t);
15
+ }
16
+ replace(e, t, n = !0) {
17
+ this.array[e] = t;
18
+ let r = this.form.getTouchedValue(this.path);
19
+ r == null ? this.form.touch(this.path) : Array.isArray(r) && (r[e] = void 0), this.commit(n);
20
+ }
21
+ insert(e, t, n = !0) {
22
+ this.array.splice(e, 0, t);
23
+ let r = this.form.getTouchedValue(this.path);
24
+ r == null ? this.form.touch(this.path) : Array.isArray(r) && r.splice(e, 0, void 0), this.commit(n);
25
+ }
26
+ remove(e, t = !0) {
27
+ this.array.splice(e, 1);
28
+ let n = this.form.getTouchedValue(this.path);
29
+ n == null ? this.form.touch(this.path) : Array.isArray(n) && n.splice(e, 1), this.commit(t);
30
+ }
31
+ swap(e, t, n = !0) {
32
+ let r = (n) => {
33
+ let r = n[e];
34
+ n[e] = n[t], n[t] = r;
35
+ };
36
+ r(this.array);
37
+ let i = this.form.getTouchedValue(this.path);
38
+ i == null ? this.form.touch(this.path) : Array.isArray(i) && r(i), this.commit(n);
39
+ }
40
+ move(e, t, n = !0) {
41
+ if (e !== t) {
42
+ let r = e < t ? (n) => {
43
+ let r = n[e];
44
+ for (let r = e; r < t; r++) n[r] = n[r + 1];
45
+ n[t] = r;
46
+ } : (n) => {
47
+ let r = n[t];
48
+ for (let r = t; r > e; r--) n[r + 1] = n[r];
49
+ n[e] = r;
50
+ };
51
+ r(this.array);
52
+ let i = this.form.getTouchedValue(this.path);
53
+ i == null ? this.form.touch(this.path) : Array.isArray(i) && r(i), this.commit(n);
54
+ }
55
+ }
56
+ clear(e = !0) {
57
+ this.array.splice(0, this.array.length), this.form.setTouchedValue(this.path, !0), this.commit(e);
58
+ }
59
+ commit(e) {
60
+ e && (this.form.validate(), this.form.render());
61
+ }
62
+ }, u = e.createContext(null);
63
+ function d() {
64
+ return e.useContext(u);
65
+ }
66
+ //#endregion
67
+ //#region src/reform/Reform.ts
68
+ var f = class {
69
+ static displayFormErrors = !1;
70
+ static logFormErrors = !0;
71
+ };
72
+ //#endregion
73
+ //#region src/reform/Form.tsx
74
+ function p(n) {
75
+ let { form: r, children: i, disabled: a, ...l } = n, d = t((e) => {
76
+ r.htmlForm = e;
77
+ }, [r]), p = new Map([...r.statuses].filter(([e, t]) => t.level === "error"));
78
+ return /* @__PURE__ */ s(u.Provider, {
79
+ value: r,
80
+ children: /* @__PURE__ */ c("form", {
81
+ ref: d,
82
+ onSubmit: (e) => r.submit(e),
83
+ ...l,
84
+ children: [/* @__PURE__ */ s("fieldset", {
85
+ disabled: a,
86
+ children: i
87
+ }), p.size > 0 && f.displayFormErrors && /* @__PURE__ */ s("div", {
88
+ style: {
89
+ all: "initial",
90
+ display: "block",
91
+ marginTop: "1em",
92
+ padding: "1em",
93
+ fontFamily: "monospace",
94
+ border: "2px solid firebrick",
95
+ borderInline: "2px solid firebrick",
96
+ color: "firebrick",
97
+ background: "white",
98
+ whiteSpace: "pre-wrap"
99
+ },
100
+ children: JSON.stringify(Object.fromEntries(p.entries()), (t, n) => t === "message" && e.isValidElement(n) ? o(n) : n, 4)
101
+ })]
102
+ })
103
+ });
104
+ }
105
+ //#endregion
106
+ //#region src/yop/ObjectsUtil.ts
107
+ var m = 1, h = 2, g = 3, _ = 4, v = 5, y = 6, ee = /^[$_\p{ID_Start}][$\p{ID_Continue}]*$/u;
108
+ function b(e) {
109
+ return ee.test(e);
110
+ }
111
+ function x(e, t) {
112
+ if (t != null) {
113
+ let n = t.get(e);
114
+ if (n != null) return n.slice();
115
+ }
116
+ let n = [], r, i = !1, a = "";
117
+ for (let t = 0; t < e.length; t++) {
118
+ let o = e.charAt(t);
119
+ switch (o) {
120
+ case "\\":
121
+ if (r !== g && r !== _) return;
122
+ i && (a += "\\"), i = !i;
123
+ continue;
124
+ case " ":
125
+ case " ":
126
+ case "\r":
127
+ case "\n":
128
+ if (r === g || r === _) a += o;
129
+ else {
130
+ for (; ++t < e.length && ((o = e.charAt(t)) === " " || o === " " || o === "\r" || o === "\n"););
131
+ if (r === h && e.charAt(t) !== "]" && a) return;
132
+ --t;
133
+ }
134
+ break;
135
+ case ".":
136
+ if (r === g || r === _) a += o;
137
+ else if (r === y) {
138
+ if (a) return;
139
+ r = m;
140
+ } else if (r === void 0 || r === m) {
141
+ if (!b(a)) return;
142
+ n.push(a), a = "", r = m;
143
+ } else return;
144
+ break;
145
+ case "[":
146
+ if (r === g || r === _) a += o;
147
+ else if (r === m) {
148
+ if (!b(a)) return;
149
+ n.push(a), a = "", r = h;
150
+ } else if (r === y) {
151
+ if (a) return;
152
+ r = h;
153
+ } else if (r === void 0) {
154
+ if (a) {
155
+ if (!b(a)) return;
156
+ n.push(a), a = "";
157
+ }
158
+ r = h;
159
+ } else return;
160
+ break;
161
+ case "]":
162
+ if (r === g || r === _) a += o;
163
+ else if (r === h) {
164
+ if (!a) return;
165
+ n.push(parseInt(a, 10)), a = "", r = y;
166
+ } else if (r === v) n.push(a), a = "", r = y;
167
+ else return;
168
+ break;
169
+ case "'":
170
+ if (i || r === _) a += o;
171
+ else if (r === g) r = v;
172
+ else if (r === h && !a) r = g;
173
+ else return;
174
+ break;
175
+ case "\"":
176
+ if (i || r === g) a += o;
177
+ else if (r === _) r = v;
178
+ else if (r === h && !a) r = _;
179
+ else return;
180
+ break;
181
+ default:
182
+ if (r === v || r === h && (o < "0" || o > "9")) return;
183
+ a += o;
184
+ break;
185
+ }
186
+ i = !1;
187
+ }
188
+ switch (r) {
189
+ case void 0:
190
+ if (a) {
191
+ if (!b(a)) return;
192
+ n.push(a);
193
+ }
194
+ break;
195
+ case y:
196
+ if (a) return;
197
+ break;
198
+ case m:
199
+ if (!b(a)) return;
200
+ n.push(a);
201
+ break;
202
+ default: return;
203
+ }
204
+ return t != null && (t.size >= 500 && t.clear(), t.set(e, n.slice())), n;
205
+ }
206
+ function S(e) {
207
+ let t = "";
208
+ for (let n of e) typeof n == "number" ? t += "[" + (Number.isNaN(n) ? "?" : n) + "]" : b(n) ? t += (t ? "." : "") + n : t += "['" + n.replaceAll("'", "\\'") + "']";
209
+ return t;
210
+ }
211
+ function C(e, t, n) {
212
+ let r = typeof t == "string" ? x(t, n) : t;
213
+ if (r == null) return;
214
+ let i = e;
215
+ for (let e of r) {
216
+ if (i == null) return;
217
+ i = i[e];
218
+ }
219
+ return i;
220
+ }
221
+ function w(e, t, n, r, i = { clone: !1 }) {
222
+ let a = typeof t == "string" ? x(t, r) : t;
223
+ if (a == null) return;
224
+ if (i.clone && (n = O(n)), a.length === 0) return { root: n };
225
+ let o = a.length - 1, s = a[o], c = typeof (a[0] ?? s) == "number" ? Array.isArray(e) ? e : [] : typeof e == "object" && e ? e : {}, l = c;
226
+ for (let e = 0; e < o; e++) {
227
+ let t = a[e], n = typeof (a[e + 1] ?? s) == "number";
228
+ l[t] == null ? l[t] = n ? [] : {} : n ? Array.isArray(l[t]) || (l[t] = []) : l[t] instanceof Object || (l[t] = {}), l = l[t];
229
+ }
230
+ let u = l[s];
231
+ return i.condition?.(u) !== !1 && (l[s] = n), {
232
+ root: c,
233
+ previousValue: u
234
+ };
235
+ }
236
+ function te(e, t, n) {
237
+ if (e == null) return !1;
238
+ let r = typeof t == "string" ? x(t, n) : t;
239
+ if (r == null || r.length === 0) return;
240
+ let i = r.length - 1, a = r[i], o = e;
241
+ for (let e = 0; e < i; e++) if (o = o[r[e]], o == null) return !1;
242
+ if (!(a in o)) return !1;
243
+ try {
244
+ delete o[a];
245
+ } catch {
246
+ return !1;
247
+ }
248
+ return !0;
249
+ }
250
+ function ne(e, t) {
251
+ if (e.equal) return !1;
252
+ let { a: n, b: r, tree: i } = e;
253
+ for (let e of t) {
254
+ if (i[e] == null) return n = C(n, t), r = C(r, t), !E(n, r) && (n != null || r != null);
255
+ i = i[e];
256
+ }
257
+ return !0;
258
+ }
259
+ function re(e, t) {
260
+ let n = [];
261
+ T(e, t, /* @__PURE__ */ new Map(), [], n);
262
+ let r = {
263
+ a: e,
264
+ b: t,
265
+ tree: {},
266
+ equal: n.length === 0
267
+ };
268
+ return n.forEach((e) => {
269
+ let t = r.tree;
270
+ e.forEach((e) => {
271
+ t[e] ?? (t[e] = {}), t = t[e];
272
+ });
273
+ }), r;
274
+ }
275
+ function T(e, t, n, r, i) {
276
+ if (e !== t) {
277
+ if (e == null || t == null) {
278
+ i.push(r);
279
+ return;
280
+ }
281
+ if (typeof e == "object" && typeof t == "object") {
282
+ if (e.constructor !== t.constructor) {
283
+ i.push(r);
284
+ return;
285
+ }
286
+ if (e instanceof Date) {
287
+ e.getTime() !== t.getTime() && i.push(r);
288
+ return;
289
+ }
290
+ if (e instanceof RegExp) {
291
+ (e.source !== t.source || e.flags !== t.flags) && i.push(r);
292
+ return;
293
+ }
294
+ if (e instanceof File) {
295
+ (e.name !== t.name || e.size !== t.size || e.type !== t.type || e.lastModified !== t.lastModified) && i.push(r);
296
+ return;
297
+ }
298
+ if (e instanceof Set) {
299
+ if (e.size !== t.size) {
300
+ i.push(r);
301
+ return;
302
+ }
303
+ for (let n of e.values()) if (!t.has(n)) {
304
+ i.push(r);
305
+ return;
306
+ }
307
+ return;
308
+ }
309
+ if (e instanceof ArrayBuffer || ArrayBuffer.isView(e)) {
310
+ if (ArrayBuffer.isView(e)) {
311
+ if (e.byteLength !== t.byteLength || e.byteOffset !== t.byteOffset) {
312
+ i.push(r);
313
+ return;
314
+ }
315
+ e = new Uint8Array(e.buffer, e.byteOffset, e.byteLength), t = new Uint8Array(t.buffer, t.byteOffset, t.byteLength);
316
+ } else {
317
+ if (e.byteLength !== t.byteLength) {
318
+ i.push(r);
319
+ return;
320
+ }
321
+ e = new Uint8Array(e), t = new Uint8Array(t);
322
+ }
323
+ for (let n = e.length; n-- !== 0;) if (e[n] !== t[n]) {
324
+ i.push(r);
325
+ return;
326
+ }
327
+ return;
328
+ }
329
+ if (n.get(e) === t) return;
330
+ if (n.set(e, t).set(t, e), Array.isArray(e)) {
331
+ let a = Math.max(e.length, t.length);
332
+ for (let o = 0; o < a; o++) T(e[o], t[o], n, [...r, o], i);
333
+ return;
334
+ }
335
+ if (e instanceof Map) {
336
+ let a = /* @__PURE__ */ new Set();
337
+ for (let o of e.entries()) {
338
+ let e = o[0];
339
+ a.add(e), T(o[1], t.get(e), n, [...r, e], i);
340
+ }
341
+ for (let o of t.entries()) {
342
+ let t = o[0];
343
+ a.has(t) || T(e.get(t), o[1], n, [...r, t], i);
344
+ }
345
+ return;
346
+ }
347
+ let a = /* @__PURE__ */ new Set();
348
+ for (let o of Object.keys(e)) a.add(o), T(e[o], t[o], n, [...r, o], i);
349
+ for (let o of Object.keys(t)) a.has(o) || T(e[o], t[o], n, [...r, o], i);
350
+ return;
351
+ }
352
+ e !== e && t !== t || i.push(r);
353
+ }
354
+ }
355
+ function E(e, t, n) {
356
+ return D(e, t, /* @__PURE__ */ new Map(), n ? typeof n == "string" ? x(n) : n : void 0);
357
+ }
358
+ function D(e, t, n, r) {
359
+ if (e === t) return !0;
360
+ if (e == null || t == null) return !1;
361
+ if (typeof e == "object" && typeof t == "object") {
362
+ if (e.constructor !== t.constructor) return !1;
363
+ if (e instanceof Date) return e.getTime() === t.getTime();
364
+ if (e instanceof RegExp) return e.source === t.source && e.flags === t.flags;
365
+ if (e instanceof File) return e.name === t.name && e.size === t.size && e.type === t.type && e.lastModified === t.lastModified;
366
+ if (e instanceof Set) {
367
+ if (e.size !== t.size) return !1;
368
+ for (let n of e.entries()) if (!t.has(n[0])) return !1;
369
+ return !0;
370
+ }
371
+ if (e instanceof ArrayBuffer || ArrayBuffer.isView(e)) {
372
+ if (ArrayBuffer.isView(e)) {
373
+ if (e.byteLength !== t.byteLength || e.byteOffset !== t.byteOffset) return !1;
374
+ e = new Uint8Array(e.buffer, e.byteOffset, e.byteLength), t = new Uint8Array(t.buffer, t.byteOffset, t.byteLength);
375
+ } else {
376
+ if (e.byteLength !== t.byteLength) return !1;
377
+ e = new Uint8Array(e), t = new Uint8Array(t);
378
+ }
379
+ for (let n = e.length; n-- !== 0;) if (e[n] !== t[n]) return !1;
380
+ return !0;
381
+ }
382
+ if (n.get(e) === t) return !0;
383
+ if (n.set(e, t).set(t, e), Array.isArray(e)) {
384
+ let i = e.length;
385
+ if (i !== t.length) return !1;
386
+ for (let a = i; a-- !== 0;) {
387
+ if (r != null && a === r[0]) {
388
+ if (r.length === 1) continue;
389
+ if (!D(e[a], t[a], n, r.slice(1))) return !1;
390
+ }
391
+ if (!D(e[a], t[a], n)) return !1;
392
+ }
393
+ return !0;
394
+ }
395
+ if (e instanceof Map) {
396
+ if (e.size !== t.size) return !1;
397
+ for (let n of e.entries()) if (!t.has(n[0])) return !1;
398
+ for (let i of e.entries()) {
399
+ let e = i[0];
400
+ if (r != null && e === r[0]) {
401
+ if (r.length === 1) continue;
402
+ if (!D(i[1], t.get(e), n, r.slice(1))) return !1;
403
+ }
404
+ if (!D(i[1], t.get(e), n)) return !1;
405
+ }
406
+ return !0;
407
+ }
408
+ let i = Object.keys(e), a = i.length;
409
+ if (a !== Object.keys(t).length) return !1;
410
+ for (let e = a; e-- !== 0;) if (!Object.prototype.hasOwnProperty.call(t, i[e])) return !1;
411
+ for (let o = a; o-- !== 0;) {
412
+ let a = i[o];
413
+ if (r != null && a === r[0]) {
414
+ if (r.length === 1) continue;
415
+ if (!D(e[a], t[a], n, r.slice(1))) return !1;
416
+ }
417
+ if (!D(e[a], t[a], n)) return !1;
418
+ }
419
+ return !0;
420
+ }
421
+ return e !== e && t !== t;
422
+ }
423
+ function O(e, t) {
424
+ if (typeof e != "object" || !e) return e;
425
+ if (t == null) t = /* @__PURE__ */ new Map();
426
+ else {
427
+ let n = t.get(e);
428
+ if (n != null) return n;
429
+ }
430
+ if (Array.isArray(e)) {
431
+ let n = [];
432
+ return t.set(e, n), e.forEach((e) => n.push(O(e, t))), n;
433
+ }
434
+ if (e instanceof Date) {
435
+ let n = new Date(e);
436
+ return t.set(e, n), n;
437
+ }
438
+ if (e instanceof RegExp) {
439
+ let n = new RegExp(e);
440
+ return t.set(e, n), n;
441
+ }
442
+ if (e instanceof Set) {
443
+ let n = /* @__PURE__ */ new Set();
444
+ return t.set(e, n), e.forEach((e) => n.add(O(e, t))), n;
445
+ }
446
+ if (e instanceof Map) {
447
+ let n = /* @__PURE__ */ new Map();
448
+ return t.set(e, n), e.forEach((e, r) => n.set(O(r, t), O(e, t))), n;
449
+ }
450
+ if (e instanceof File) return t.set(e, e), e;
451
+ let n = Object.create(Object.getPrototypeOf(e));
452
+ t.set(e, n);
453
+ let r = Object.getOwnPropertyDescriptors(e);
454
+ for (let e of Object.values(r)) e.get ?? (e.value = O(e.value, t));
455
+ return Object.defineProperties(n, r), n;
456
+ }
457
+ function k(e, t, n) {
458
+ Object.defineProperty(e, t, {
459
+ configurable: !0,
460
+ enumerable: !0,
461
+ get: function() {
462
+ let e = n(this);
463
+ return Object.defineProperty(this, t, {
464
+ value: e,
465
+ configurable: !0,
466
+ enumerable: !0,
467
+ writable: !0
468
+ }), e;
469
+ }
470
+ });
471
+ }
472
+ function ie(e, t, n) {
473
+ let r = Object.getOwnPropertyDescriptors(t);
474
+ if (n && (n.skipUndefined || n.includes || n.excludes)) for (let [e, t] of Object.entries(r)) (n.skipUndefined && t.get == null && t.value === void 0 || n.includes && !n.includes.includes(e) || n.excludes?.includes(e)) && delete r[e];
475
+ return Object.defineProperties(e, r), e;
476
+ }
477
+ //#endregion
478
+ //#region src/yop/TypesUtil.ts
479
+ var ae = (e, t) => e.prototype instanceof t, A = (e) => typeof e == "boolean", j = (e) => typeof e == "number" && !isNaN(e), M = (e) => typeof e == "string", oe = (e) => e != null && !Array.isArray(e) && typeof e == "object", N = (e) => typeof e == "function", P = (e) => e instanceof Date && !isNaN(e.getTime()), se = (e) => e instanceof File, ce = (e) => e instanceof RegExp, le = (e) => Array.isArray(e) && e.every(M), ue = (e) => Array.isArray(e) && e.every(A), de = (e) => Array.isArray(e) && e.every(j), fe = (e) => Array.isArray(e) && e.every(P), pe = (e) => typeof e == "object" && !!e && "then" in e && typeof e.then == "function" && "catch" in e && typeof e.catch == "function";
480
+ //#endregion
481
+ //#region src/yop/constraints/Constraint.ts
482
+ function F(e, t, n, r, i, a, o, s = !0) {
483
+ if (e.groups == null) {
484
+ let c = t[n];
485
+ return me(e, c, r, i, n, a, o, s);
486
+ }
487
+ let c = Array.isArray(e.groups) ? e.groups : [e.groups];
488
+ for (let l of c) if (!me(e, l == null ? t[n] : t.groups?.[l]?.[n], r, i, n, a, o, s)) return !1;
489
+ return !0;
490
+ }
491
+ function me(e, t, n, r, i, a, o, s = !0) {
492
+ if (t == null && a == null) return !0;
493
+ let c, l = "error";
494
+ if (N(t) && (t = t(e)), t != null && !n(t)) if (Array.isArray(t)) {
495
+ let [e, r, i, a] = t;
496
+ e == null || n(e) ? (t = e, c = r, l = i ?? "error") : t = void 0;
497
+ } else t = void 0;
498
+ return t == null && a != null && (t = a), c == null && o != null && (c = N(o) ? o(e) : o), t == null || r(e.value, t) || s === !0 && e.setStatus(i, t, c, l) == null;
499
+ }
500
+ //#endregion
501
+ //#region src/yop/constraints/MinMaxConstraints.ts
502
+ function I(e, t, n, r, i) {
503
+ return F(e, t, "min", n, r) && F(e, t, "max", n, i);
504
+ }
505
+ //#endregion
506
+ //#region src/yop/MessageProvider.ts
507
+ function he(e, t, n, r) {
508
+ return typeof e == "number" ? t.format(e) : e instanceof Date ? n.format(e) : Array.isArray(e) ? r.format(e.map((e) => he(e, t, n, r))) : String(e);
509
+ }
510
+ var ge = class {
511
+ numberFormat;
512
+ dateFormat;
513
+ listFormat;
514
+ pluralRules;
515
+ messages;
516
+ constructor(e, t) {
517
+ this.locale = e, this.numberFormat = new Intl.NumberFormat(this.locale), this.dateFormat = new Intl.DateTimeFormat(this.locale), this.listFormat = new Intl.ListFormat(this.locale, { type: "disjunction" }), this.pluralRules = new Intl.PluralRules(this.locale), this.messages = new Map(t);
518
+ }
519
+ getMessage(e, t, n, r, i) {
520
+ if (r != null) return r;
521
+ let a = this.messages.get(`${e.kind}.${t}`) ?? this.messages.get(t);
522
+ return a == null ? `Unexpected error: ${e.kind}.${t}` : a({
523
+ context: e,
524
+ code: t,
525
+ constraint: {
526
+ raw: n,
527
+ formatted: he(n, this.numberFormat, this.dateFormat, this.listFormat),
528
+ plural: typeof n == "number" ? this.pluralRules.select(n) : void 0
529
+ },
530
+ level: i
531
+ });
532
+ }
533
+ };
534
+ function L(e) {
535
+ return e == null || e === "one" ? "" : "s";
536
+ }
537
+ var _e = new ge("en-US", [
538
+ ["string.min", ({ constraint: e }) => `Minimum ${e.formatted} character${L(e.plural)}`],
539
+ ["string.max", ({ constraint: e }) => `Maximum ${e.formatted} character${L(e.plural)}`],
540
+ ["string.match", () => "Invalid format"],
541
+ ["email.min", ({ constraint: e }) => `Minimum ${e.formatted} character${L(e.plural)}`],
542
+ ["email.max", ({ constraint: e }) => `Maximum ${e.formatted} character${L(e.plural)}`],
543
+ ["email.match", () => "Invalid email format"],
544
+ ["time.min", ({ constraint: e }) => `Must be after or equal to ${e.formatted}`],
545
+ ["time.max", ({ constraint: e }) => `Must be before or equal to ${e.formatted}`],
546
+ ["time.match", () => "Invalid time format"],
547
+ ["number.min", ({ constraint: e }) => `Must be greater or equal to ${e.formatted}`],
548
+ ["number.max", ({ constraint: e }) => `Must be less or equal to ${e.formatted}`],
549
+ ["date.min", ({ constraint: e }) => `Date must be greater or equal to ${e.formatted}`],
550
+ ["date.max", ({ constraint: e }) => `Date must be less or equal to ${e.formatted}`],
551
+ ["file.min", ({ constraint: e }) => `File must have a size of at least ${e.formatted} byte${L(e.plural)}`],
552
+ ["file.max", ({ constraint: e }) => `File must have a size of at most ${e.formatted} byte${L(e.plural)}`],
553
+ ["array.min", ({ constraint: e }) => `At least ${e.formatted} element${L(e.plural)}`],
554
+ ["array.max", ({ constraint: e }) => `At most ${e.formatted} element${L(e.plural)}`],
555
+ ["type", ({ constraint: e }) => `Wrong value type (expected ${e.raw})`],
556
+ ["test", ({ level: e }) => e === "pending" ? "Pending..." : e === "error" ? "Invalid value" : ""],
557
+ ["oneOf", ({ constraint: e }) => `Must be one of: ${e.formatted}`],
558
+ ["exists", () => "Required field"],
559
+ ["defined", () => "Required field"],
560
+ ["notnull", () => "Required field"],
561
+ ["required", () => "Required field"]
562
+ ]), ve = new ge("fr-FR", [
563
+ ["string.min", ({ constraint: e }) => `Minimum ${e.formatted} caractère${L(e.plural)}`],
564
+ ["string.max", ({ constraint: e }) => `Maximum ${e.formatted} caractère${L(e.plural)}`],
565
+ ["string.match", () => "Format incorrect"],
566
+ ["email.min", ({ constraint: e }) => `Minimum ${e.formatted} caractère${L(e.plural)}`],
567
+ ["email.max", ({ constraint: e }) => `Maximum ${e.formatted} caractère${L(e.plural)}`],
568
+ ["email.match", () => "Format d'email incorrect"],
569
+ ["time.min", ({ constraint: e }) => `Doit être antérieur ou égal à ${e.formatted}`],
570
+ ["time.max", ({ constraint: e }) => `Doit être postérieur ou égal à ${e.formatted}`],
571
+ ["time.match", () => "Format horaire incorrect"],
572
+ ["number.min", ({ constraint: e }) => `Doit être supérieur ou égal à ${e.formatted}`],
573
+ ["number.max", ({ constraint: e }) => `Doit être inférieur ou égal à ${e.formatted}`],
574
+ ["date.min", ({ constraint: e }) => `La date doit être postérieure ou égale au ${e.formatted}`],
575
+ ["date.max", ({ constraint: e }) => `La date doit être antérieure ou égale au ${e.formatted}`],
576
+ ["file.min", ({ constraint: e }) => `Le fichier doit avoir une taille d'au moins ${e.formatted} octet${L(e.plural)}`],
577
+ ["file.max", ({ constraint: e }) => `Le fichier doit avoir une taille d'au plus ${e.formatted} octet${L(e.plural)}`],
578
+ ["array.min", ({ constraint: e }) => `Au moins ${e.formatted} élément${L(e.plural)}`],
579
+ ["array.max", ({ constraint: e }) => `Au plus ${e.formatted} élément${L(e.plural)}`],
580
+ ["type", ({ constraint: e }) => `Valeur du mauvais type (${e.raw} attendu)`],
581
+ ["test", ({ level: e }) => e === "pending" ? "En cours..." : e === "error" ? "Valeur incorrecte" : ""],
582
+ ["oneOf", ({ constraint: e }) => `Doit être parmi : ${e.formatted}`],
583
+ ["exists", () => "Champ obligatoire"],
584
+ ["defined", () => "Champ obligatoire"],
585
+ ["notnull", () => "Champ obligatoire"],
586
+ ["required", () => "Champ obligatoire"]
587
+ ]);
588
+ //#endregion
589
+ //#region src/yop/constraints/CommonConstraints.ts
590
+ function ye(e, t) {
591
+ return F(e, t, "defined", A, (e, t) => t !== !0 || e !== void 0) && F(e, t, "notnull", A, (e, t) => t !== !0 || e !== null) && F(e, t, "required", A, (e, t) => t !== !0 || e != null);
592
+ }
593
+ function R(e, t, n) {
594
+ return t(e.value) || e.setStatus("type", n) == null;
595
+ }
596
+ //#endregion
597
+ //#region src/yop/constraints/TestConstraint.ts
598
+ var be = (e) => [], xe = (e, t, n, r) => r?.level !== "unavailable" && n.some((e, n) => e !== t[n]);
599
+ function z(e, t) {
600
+ if (e.groups == null) return t.test == null || Se(e, t);
601
+ let n = Array.isArray(e.groups) ? e.groups : [e.groups];
602
+ for (let r of n) {
603
+ let n = r == null ? t.test : t.groups?.[r]?.test;
604
+ if (n != null && !Se(e, { test: n })) return !1;
605
+ }
606
+ return !0;
607
+ }
608
+ function Se(e, t) {
609
+ let n = t.test, r = N(n) ? n : Array.isArray(n) ? n[0] : void 0;
610
+ if (r != null && !Ce(e, r)) return !1;
611
+ let i = oe(n) ? n : Array.isArray(n) ? n[1] : void 0;
612
+ return i == null || we(e, i);
613
+ }
614
+ function Ce(e, t) {
615
+ let n, r, i;
616
+ if (n = t(e), Array.isArray(n)) {
617
+ let [e, t, a] = n;
618
+ n = e, r = t, i = a ?? void 0;
619
+ }
620
+ return n == null || n === !0 ? !0 : e.setStatus("test", !1, typeof n == "string" ? n : r, i ?? "error") == null;
621
+ }
622
+ function we(e, t) {
623
+ if (e.settings?.skipAsync) return !0;
624
+ let n = t.dependencies ?? be, r = [e.value].concat(n(e)), i = S(e.path), a = e.yop.asyncStatuses.get(i);
625
+ if (a != null) {
626
+ let n = a.dependencies;
627
+ if (a.dependencies = r, !(t.revalidate ?? xe)(e, n, r, a.status)) return a.status == null ? !0 : (e.statuses.set(i, a.status), !1);
628
+ }
629
+ a = { dependencies: r };
630
+ let o = t.promise(e).then((t) => {
631
+ if (t == null || t === !0) a.status = void 0;
632
+ else if (t === !1) a.status = e.createStatus("test", !1);
633
+ else if (!Array.isArray(t)) a.status = e.createStatus("test", !1, t);
634
+ else {
635
+ let [n, r] = t;
636
+ a.status = e.createStatus("test", !1, n, r ?? "error");
637
+ }
638
+ return a.status;
639
+ }).catch((n) => (a.status = e.createStatus("test", !1, n == null ? t.unavailableMessage : String(n), "unavailable"), Promise.resolve(a.status)));
640
+ return a.status = e.setStatus("test", o, t.pendingMessage, "pending"), e.yop.asyncStatuses.set(i, a), !1;
641
+ }
642
+ //#endregion
643
+ //#region src/yop/decorators/array.ts
644
+ function Te(e, t, n, r) {
645
+ return (r ? e.value != null && (!Array.isArray(e.value) || typeof n != "number") : e.value == null) ? [void 0, void 0] : [t.of?.[Symbol.metadata]?.[H], e.value?.[n]];
646
+ }
647
+ function Ee(e, t) {
648
+ if (!R(e, Array.isArray, "array") || !I(e, t, j, (e, t) => e.length >= t, (e, t) => e.length <= t) || t.of == null) return !1;
649
+ let n = !0, r = t.of[Symbol.metadata]?.[H];
650
+ if (r != null) for (let [t, i] of e.value.entries()) {
651
+ let a = e.createChildContext({
652
+ kind: r.kind,
653
+ value: i,
654
+ key: t
655
+ });
656
+ n = r.validate(a, r) && n;
657
+ }
658
+ return n && z(e, t);
659
+ }
660
+ var De = "array";
661
+ function Oe(e, t) {
662
+ if (Ve(e?.of) != null) {
663
+ let t = e.of;
664
+ k(e, "of", (e) => {
665
+ let n = { [H]: {} };
666
+ return t(null, {
667
+ metadata: n,
668
+ name: "of"
669
+ }), { [Symbol.metadata]: { [H]: n[H].fields.of } };
670
+ });
671
+ } else if (typeof e?.of == "string" || typeof e?.of == "function" && e.of.prototype == null) {
672
+ let t = e.of;
673
+ k(e, "of", (e) => U.resolveClass(t));
674
+ }
675
+ return V(De, e ?? {}, t, Ee, j, Te);
676
+ }
677
+ //#endregion
678
+ //#region src/yop/decorators/instance.ts
679
+ function ke(e, t, n, r) {
680
+ if (t.of == null) return [void 0, void 0];
681
+ let i = t.of[Symbol.metadata]?.[H];
682
+ return i == null ? [void 0, void 0] : i.traverse(e, i, n, r);
683
+ }
684
+ function Ae(e, t) {
685
+ if (!R(e, oe, "object") || !z(e, t) || t.of == null) return !1;
686
+ let n = t.of[Symbol.metadata]?.[H];
687
+ return n == null || Pe(e, n);
688
+ }
689
+ var je = "instance";
690
+ function Me(e, t) {
691
+ if (typeof e?.of == "string" || typeof e?.of == "function" && e.of.prototype == null) {
692
+ let t = e.of;
693
+ k(e, "of", (e) => U.resolveClass(t));
694
+ }
695
+ return V(je, e ?? {}, t, Ae, void 0, ke);
696
+ }
697
+ //#endregion
698
+ //#region src/yop/Metadata.ts
699
+ function Ne(e, t, n, r) {
700
+ return (r ? e.value != null && (typeof e.value != "object" || typeof n != "string") : e.value == null) ? [void 0, void 0] : [t.fields?.[n], e.value?.[n]];
701
+ }
702
+ function Pe(e, t) {
703
+ if (e.value == null || !R(e, oe, "object")) return !1;
704
+ let n = !0, r = e.value;
705
+ for (let [i, a] of Object.entries(t.fields)) {
706
+ if (a.validate == null) continue;
707
+ let t = e.createChildContext({
708
+ kind: a.kind,
709
+ value: r[i],
710
+ key: i
711
+ });
712
+ n = F(t, a, "exists", A, (e, t) => t !== !0 || i in r) && a.validate(t, a) && n;
713
+ }
714
+ return n && z(e, t);
715
+ }
716
+ function Fe(e) {
717
+ let t = e;
718
+ Object.hasOwnProperty.bind(t)(H) || (t[H] = O(t[H] ?? {}));
719
+ let n = t[H];
720
+ return n.validate ??= Pe, n.traverse ??= Ne, n.kind ??= "class", n;
721
+ }
722
+ function Ie(e) {
723
+ let t = { [H]: {} };
724
+ return e(null, {
725
+ metadata: t,
726
+ name: "placeholder"
727
+ }), t[H]?.fields?.placeholder;
728
+ }
729
+ function Le(e) {
730
+ return e?.[Symbol.metadata]?.[H];
731
+ }
732
+ function Re(e) {
733
+ return e?.[Symbol.metadata]?.[H]?.fields;
734
+ }
735
+ function ze(e) {
736
+ if (e?.kind === "array") {
737
+ let t = e.of;
738
+ if (typeof t == "function") return t;
739
+ e = t?.[Symbol.metadata]?.[H];
740
+ }
741
+ return e?.kind === "instance" ? e.of : void 0;
742
+ }
743
+ var Be = Symbol("YopValidationDecorator");
744
+ function Ve(e) {
745
+ return e?.[Be];
746
+ }
747
+ function B(e, t = !1) {
748
+ return (n, r) => {
749
+ let i = Fe(r.metadata);
750
+ Object.hasOwnProperty.bind(i)("fields") || (i.fields = O(i.fields ?? {}));
751
+ let a = r.name, o = i.fields;
752
+ (t || !Object.hasOwnProperty.bind(o)(a)) && (o[a] = {}), typeof e == "function" ? e(o[a]) : ie(o[a], e);
753
+ };
754
+ }
755
+ function He(e, t, n = () => {}) {
756
+ Object.values(t ?? {}).concat(e == null ? [] : [e]).forEach((e) => {
757
+ n(e);
758
+ });
759
+ }
760
+ function Ue(e, t) {
761
+ return (n, r) => {
762
+ e(n, r);
763
+ let i = r.metadata?.[H]?.fields;
764
+ if (i?.[r.name] != null) {
765
+ let e = i[r.name];
766
+ Object.entries(t).forEach(([t, n]) => {
767
+ let r = t;
768
+ e[r] === void 0 && (e[r] = n), e.groups != null && Object.keys(e.groups).forEach((t) => {
769
+ let i = t;
770
+ e.groups[i][r] === void 0 && (e.groups[i][r] = n);
771
+ });
772
+ });
773
+ }
774
+ };
775
+ }
776
+ function V(e, t, n, r, i, a) {
777
+ t = ie(O(t), {
778
+ groups: n,
779
+ kind: e,
780
+ validate: (e, t) => e.ignored() || !F(e, t, "ignored", A, (e, t) => t === !1, void 0, void 0, !1) ? !0 : ye(e, t) ? e.value == null ? !0 : r(e, t) : !1,
781
+ traverse: a,
782
+ isMinMaxType: i
783
+ });
784
+ let o = B(t);
785
+ return Object.defineProperty(o, Be, { value: e }), o;
786
+ }
787
+ //#endregion
788
+ //#region src/yop/ValidationContext.ts
789
+ var We = Object.freeze(Object.create(null)), Ge = class e {
790
+ yop;
791
+ kind;
792
+ value;
793
+ path;
794
+ parentContext;
795
+ rootContext;
796
+ settings;
797
+ store;
798
+ statuses;
799
+ constructor(e) {
800
+ if (e.parentContext != null && e.key == null) throw Error("key must be provided when parentContext is provided");
801
+ this.yop = e.yop, this.kind = e.kind, this.value = e.value, this.parentContext = e.parentContext, this.rootContext = e.rootContext, this.settings = e.settings, this.statuses = e.statuses ?? /* @__PURE__ */ new Map(), this.store = e.yop.store, this.path = e.key == null ? [] : e.parentContext?.path.concat(e.key) ?? [e.key];
802
+ }
803
+ ignored() {
804
+ return this.settings?.ignore?.(this.path) ?? !1;
805
+ }
806
+ get parent() {
807
+ return this.parentContext?.value || We;
808
+ }
809
+ get groups() {
810
+ return this.settings?.groups;
811
+ }
812
+ get form() {
813
+ return this.settings?.form;
814
+ }
815
+ getRoot() {
816
+ return this.rootContext?.value;
817
+ }
818
+ createChildContext(t) {
819
+ return new e({
820
+ yop: this.yop,
821
+ kind: t.kind,
822
+ value: t.value,
823
+ key: t.key,
824
+ parentContext: this,
825
+ rootContext: this.rootContext ?? this,
826
+ settings: this.settings,
827
+ statuses: this.statuses
828
+ });
829
+ }
830
+ createStatus(e, t, n, r = "error") {
831
+ return {
832
+ level: r,
833
+ path: S(this.path),
834
+ value: this.value,
835
+ kind: this.kind,
836
+ code: e,
837
+ constraint: t,
838
+ message: this.yop.messageProvider.getMessage(this, e, t, n, r)
839
+ };
840
+ }
841
+ setStatus(e, t, n, r = "error") {
842
+ let i = this.createStatus(e, t, n, r);
843
+ return this.statuses.set(i.path, i), i;
844
+ }
845
+ };
846
+ //#endregion
847
+ //#region src/yop/Yop.ts
848
+ Symbol.metadata ??= Symbol.for("Symbol.metadata");
849
+ var H = Symbol("YopValidation"), U = class e {
850
+ static defaultInstance;
851
+ static classIds = /* @__PURE__ */ new Map();
852
+ static messageProviders = /* @__PURE__ */ new Map();
853
+ static {
854
+ this.registerMessageProvider(_e), this.registerMessageProvider(ve);
855
+ }
856
+ locale = e.defaultInstance?.locale ?? "en-US";
857
+ _store = /* @__PURE__ */ new Map();
858
+ _asyncStatuses = /* @__PURE__ */ new Map();
859
+ get store() {
860
+ return this._store;
861
+ }
862
+ get asyncStatuses() {
863
+ return this._asyncStatuses;
864
+ }
865
+ static registerClass(t, n) {
866
+ e.classIds.set(t, n);
867
+ }
868
+ static resolveClass(t, n = !1) {
869
+ if (typeof t == "string") {
870
+ let r = e.classIds.get(t);
871
+ return r == null && n === !1 && console.error(`Class "${t}" unregistered in Yop. Did you forget to add a @id("${t}") decorator to the class?`), r;
872
+ }
873
+ return typeof t == "function" && t.prototype == null ? t() : t;
874
+ }
875
+ contextAt(e, t, n, r = !1) {
876
+ let i = Ie(e);
877
+ if (i == null) return;
878
+ let a = typeof n.path == "string" ? x(n.path) : n.path ?? [];
879
+ if (a == null) return;
880
+ let o = new Ge({
881
+ yop: this,
882
+ kind: i.kind,
883
+ value: t,
884
+ settings: n
885
+ });
886
+ for (let e of a) {
887
+ if ([i, t] = i.traverse?.(o, i, e, r) ?? [,], i == null) return;
888
+ o = o.createChildContext({
889
+ kind: i.kind,
890
+ value: t,
891
+ key: e
892
+ });
893
+ }
894
+ return [o, i];
895
+ }
896
+ constraintsAt(e, t, n) {
897
+ let [r, i] = this.contextAt(e, t, n ?? {}, !0) ?? [];
898
+ if (r != null && i != null) {
899
+ let e = { required: !1 };
900
+ F(r, i, "required", A, (t, n) => (e.required = n, !0));
901
+ let t = i.isMinMaxType;
902
+ return t != null && I(r, i, t, (t, n) => (e.min = n, !0), (t, n) => (e.max = n, !0)), n?.unsafeMetadata && (e.fieldMetadata = i), e;
903
+ }
904
+ }
905
+ static constraintsAt(t, n, r) {
906
+ return e.init().constraintsAt(t, n, r);
907
+ }
908
+ getAsyncStatus(e) {
909
+ return this.asyncStatuses.get(typeof e == "string" ? e : S(e))?.status;
910
+ }
911
+ rawValidate(e, t, n = { path: [] }) {
912
+ let [r, i] = this.contextAt(t, e, n) ?? [];
913
+ return r != null && i != null && i.validate(r, i), r;
914
+ }
915
+ validate(e, t, n = { path: [] }) {
916
+ let r = this.rawValidate(e, t, n);
917
+ return r == null ? [] : Array.from(r.statuses.values());
918
+ }
919
+ static validate(t, n, r) {
920
+ return e.init().validate(t, n, r);
921
+ }
922
+ static registerMessageProvider(t) {
923
+ try {
924
+ let n = Intl.getCanonicalLocales(t.locale)[0];
925
+ e.messageProviders.set(n, t);
926
+ } catch (e) {
927
+ console.error(`Invalid locale "${t.locale}" in message provider. Ignoring.`, e);
928
+ }
929
+ }
930
+ getLocale() {
931
+ return this.locale;
932
+ }
933
+ static getLocale() {
934
+ return e.init().locale;
935
+ }
936
+ setLocale(t) {
937
+ try {
938
+ t = Intl.getCanonicalLocales(t)[0], e.messageProviders.has(t) ? this.locale = t : console.error(`No message provider for locale "${t}". Ignoring`);
939
+ } catch (e) {
940
+ console.error(`Invalid locale "${t}". Ignoring.`, e);
941
+ }
942
+ }
943
+ static setLocale(t) {
944
+ e.init().setLocale(t);
945
+ }
946
+ get messageProvider() {
947
+ return e.messageProviders.get(this.locale);
948
+ }
949
+ static init() {
950
+ return e.defaultInstance ??= new e(), e.defaultInstance;
951
+ }
952
+ };
953
+ //#endregion
954
+ //#region src/yop/decorators/ignored.ts
955
+ function W(e = !0, t) {
956
+ return B((n) => {
957
+ if (n.ignored = e, t != null) {
958
+ n.groups ??= {};
959
+ for (let [e, r] of Object.entries(t)) n.groups?.[e] == null ? n.groups[e] = { ignored: r } : n.groups[e].ignored = r;
960
+ }
961
+ });
962
+ }
963
+ //#endregion
964
+ //#region src/reform/FormManager.ts
965
+ var Ke = "reform:set-value";
966
+ function qe(e, t, n, r, i) {
967
+ return new CustomEvent(Ke, { detail: {
968
+ form: e,
969
+ path: t,
970
+ previousValue: n,
971
+ value: r,
972
+ options: i
973
+ } });
974
+ }
975
+ var Je = class {
976
+ _config = { validationSchema: W() };
977
+ yop = new U();
978
+ pathCache = /* @__PURE__ */ new Map();
979
+ _initialValues = void 0;
980
+ _initialValuesPending = !1;
981
+ _values = void 0;
982
+ _statuses = /* @__PURE__ */ new Map();
983
+ touched = null;
984
+ _submitting = !1;
985
+ _submitted = !1;
986
+ eventTarget = new EventTarget();
987
+ htmlForm;
988
+ constructor(e) {
989
+ this.render = e;
990
+ }
991
+ addReformEventListener(e) {
992
+ this.eventTarget.addEventListener(Ke, e);
993
+ }
994
+ removeReformEventListener(e) {
995
+ this.eventTarget.removeEventListener(Ke, e);
996
+ }
997
+ get initialValuesPending() {
998
+ return this._initialValuesPending;
999
+ }
1000
+ get submitted() {
1001
+ return this._submitted;
1002
+ }
1003
+ get submitting() {
1004
+ return this._submitting;
1005
+ }
1006
+ get config() {
1007
+ return this._config;
1008
+ }
1009
+ get store() {
1010
+ return this.yop.store;
1011
+ }
1012
+ set initialValuesPending(e) {
1013
+ this._initialValuesPending = e;
1014
+ }
1015
+ setSubmitting(e) {
1016
+ this._submitting = e, this.render();
1017
+ }
1018
+ commitInitialValues() {
1019
+ this._initialValues = O(this._config.initialValues), this._config.initialValuesConverter != null && (this._initialValues = this._config.initialValuesConverter(this._initialValues)), this._values = O(this._initialValues), this.touched = null, this._statuses = /* @__PURE__ */ new Map();
1020
+ }
1021
+ onRender(e) {
1022
+ this._config = e;
1023
+ }
1024
+ get initialValues() {
1025
+ return this._initialValues;
1026
+ }
1027
+ get values() {
1028
+ return this._values == null && this._config.initialValues != null && this.commitInitialValues(), this._values;
1029
+ }
1030
+ getValue(e) {
1031
+ return C(this.values, e, this.pathCache);
1032
+ }
1033
+ setValue(e, t, n) {
1034
+ let r = w(this.values, e, t, this.pathCache, { clone: !0 });
1035
+ if (r == null) return;
1036
+ this._values = r.root;
1037
+ let { touch: i, validate: a, propagate: o } = {
1038
+ propagate: !0,
1039
+ ...typeof n == "boolean" ? { validate: n } : n
1040
+ };
1041
+ return i === !1 ? this.untouch(e) : (a || i) && this.touch(e), a && (this.validate(), this.render()), this._config.dispatchEvent !== !1 && o === !0 && setTimeout(() => {
1042
+ this.eventTarget.dispatchEvent(qe(this, typeof e == "string" ? e : S(e), r.previousValue, t, {
1043
+ touch: i,
1044
+ validate: a,
1045
+ propagate: o
1046
+ }));
1047
+ }), r;
1048
+ }
1049
+ isDirty(e, t) {
1050
+ return e == null || e.length === 0 ? !E(this.values, this._initialValues, t) : !E(C(this.values, e, this.pathCache), C(this._initialValues, e, this.pathCache), t);
1051
+ }
1052
+ isTouched(e = []) {
1053
+ return C(this.touched, e, this.pathCache) != null;
1054
+ }
1055
+ touch(e = []) {
1056
+ this.touched = w(this.touched, e, !0, this.pathCache, { condition: (e) => e === void 0 })?.root ?? null;
1057
+ }
1058
+ untouch(e = []) {
1059
+ e.length === 0 ? this.touched = null : te(this.touched, e, this.pathCache);
1060
+ }
1061
+ getTouchedValue(e) {
1062
+ return C(this.touched, e, this.pathCache);
1063
+ }
1064
+ setTouchedValue(e, t) {
1065
+ this.touched = w(this.touched, e, t, this.pathCache)?.root ?? null;
1066
+ }
1067
+ get statuses() {
1068
+ return this._statuses;
1069
+ }
1070
+ get errors() {
1071
+ return Array.from(this._statuses.values()).filter((e) => e.level === "error");
1072
+ }
1073
+ validate(e = !0, t) {
1074
+ let n = t;
1075
+ if (this._config.ignore != null && (n = t == null ? this._config.ignore : (e, n) => t(e, n) || this._config.ignore(e, n)), !this._submitted && e) if (n == null) n = (e, t) => !this.isTouched(e);
1076
+ else {
1077
+ let e = n;
1078
+ n = (t, n) => !this.isTouched(t) || e(t, n);
1079
+ }
1080
+ let r = this._config.validationSchema ?? W(), i = {
1081
+ method: "validate",
1082
+ form: this,
1083
+ groups: this._config.validationGroups,
1084
+ ignore: n == null ? void 0 : (e) => n(e, this)
1085
+ };
1086
+ if (Array.isArray(this._config.validationPath)) {
1087
+ this._statuses = /* @__PURE__ */ new Map();
1088
+ for (let e of this._config.validationPath) i.path = e, this.yop.rawValidate(this.values, r, i)?.statuses?.forEach((e, t) => this._statuses.set(t, e));
1089
+ } else i.path = this._config.validationPath, this._statuses = this.yop.rawValidate(this.values, r, i)?.statuses ?? /* @__PURE__ */ new Map();
1090
+ return this._statuses;
1091
+ }
1092
+ validateAt(e, t = !0, n = !0) {
1093
+ if (t && !this.submitted && !this.isTouched(e)) return {
1094
+ changed: !1,
1095
+ statuses: /* @__PURE__ */ new Map()
1096
+ };
1097
+ let r = !1, i = typeof e == "string" ? e : S(e);
1098
+ for (let e of this._statuses.keys()) e.startsWith(i) && (e.length === i.length || [".", "["].includes(e.charAt(i.length))) && (this._statuses.delete(e), r = !0);
1099
+ let a = {
1100
+ method: "validateAt",
1101
+ form: this,
1102
+ path: e,
1103
+ skipAsync: n,
1104
+ groups: this._config.validationGroups,
1105
+ ignore: this._config.ignore == null ? void 0 : (e) => this._config.ignore(e, this)
1106
+ }, o = this.yop.rawValidate(this.values, this._config.validationSchema ?? W(), a)?.statuses ?? /* @__PURE__ */ new Map();
1107
+ return o.forEach((e, t) => this._statuses.set(t, e)), {
1108
+ changed: r || o.size > 0,
1109
+ statuses: o
1110
+ };
1111
+ }
1112
+ constraintsAt(e, t) {
1113
+ let n = {
1114
+ method: "constraintsAt",
1115
+ form: this,
1116
+ path: e,
1117
+ unsafeMetadata: t
1118
+ };
1119
+ return this.yop.constraintsAt(this._config.validationSchema ?? W(), this.values, n);
1120
+ }
1121
+ updateAsyncStatus(e) {
1122
+ let t = this.yop.getAsyncStatus(e);
1123
+ t == null ? (e = typeof e == "string" ? e : S(e), this._statuses.get(e)?.level === "pending" && this._statuses.delete(e)) : this._statuses.set(t.path, t);
1124
+ }
1125
+ submit(e) {
1126
+ e.preventDefault(), e.stopPropagation(), this._submitted = !0, this.setSubmitting(!0), setTimeout(async () => {
1127
+ let e = Array.from(this.validate(!1).values()), t = e.filter((e) => e.level === "pending");
1128
+ if (t.length > 0) {
1129
+ this.render();
1130
+ let n = (await Promise.all(t.map((e) => e.constraint))).filter((e) => e != null);
1131
+ n.length > 0 && (n.forEach((e) => this._statuses.set(e.path, e)), e = Array.from(this._statuses.values()));
1132
+ }
1133
+ let n = e.filter((e) => e.level === "error" || e.level === "unavailable" && e.message), r = this._config.submitGuard?.(this);
1134
+ n.length === 0 && r !== !1 ? (this._config.onSubmit ?? ((e) => e.setSubmitting(!1)))(this) : (f.logFormErrors && n.length > 0 && console.error("Validation errors", n), r !== !1 && this.scrollToFirstError(n), this.setSubmitting(!1));
1135
+ });
1136
+ }
1137
+ scrollToFirstError(e) {
1138
+ e ??= Array.from(this.statuses.values()).filter((e) => e.level === "error" || e.level === "unavailable" && e.message);
1139
+ let t = e.map((e) => window.document.getElementById(e.path)).filter((e) => e != null).sort((e, t) => e.compareDocumentPosition(t) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1).shift();
1140
+ t != null && (t.scrollIntoView({
1141
+ behavior: "smooth",
1142
+ block: "center"
1143
+ }), t.focus({ preventScroll: !0 }));
1144
+ }
1145
+ array(e) {
1146
+ let t = new l(this, e);
1147
+ return t.isArray() ? t : void 0;
1148
+ }
1149
+ };
1150
+ //#endregion
1151
+ //#region src/reform/observers/observer.ts
1152
+ function Ye(e, t) {
1153
+ return B((n) => {
1154
+ let r = n;
1155
+ r.observers ??= /* @__PURE__ */ new Map(), t == null ? r.observers.delete(e) : r.observers.set(e, {
1156
+ path: e,
1157
+ callback: t
1158
+ });
1159
+ });
1160
+ }
1161
+ //#endregion
1162
+ //#region src/reform/observers/observerPath.ts
1163
+ var G = 1, K = 2, q = 3, J = 4, Y = 5, X = 6, Xe = /^[$_\p{ID_Start}][$\p{ID_Continue}]*$/u;
1164
+ function Z(e, t) {
1165
+ if (Xe.test(e)) t.push({
1166
+ kind: "property",
1167
+ value: e
1168
+ });
1169
+ else if (e === "*") t.push({ kind: "wildcard" });
1170
+ else if (e === "**") t.push({ kind: "double-wildcard" });
1171
+ else return !1;
1172
+ return !0;
1173
+ }
1174
+ function Ze(e, t) {
1175
+ if (e.length === 0) return;
1176
+ if (t != null) {
1177
+ let n = t.get(e);
1178
+ if (n != null) return n.slice();
1179
+ }
1180
+ let n = [], r, i = !1, a = "", o = 0;
1181
+ if (e.charAt(0) === "/") n.push({ kind: "root" }), r = G, o++;
1182
+ else for (; e.startsWith("..", o);) {
1183
+ if (n.push({ kind: "parent" }), o += 2, o === e.length) return n;
1184
+ let t = e.charAt(o);
1185
+ if (t === "/") o++, r = G;
1186
+ else if (t === "[") {
1187
+ o++, r = K;
1188
+ break;
1189
+ } else return;
1190
+ }
1191
+ for (; o < e.length; o++) {
1192
+ let t = e.charAt(o);
1193
+ switch (t) {
1194
+ case "\\":
1195
+ if (r !== q && r !== J) return;
1196
+ i && (a += "\\"), i = !i;
1197
+ continue;
1198
+ case " ":
1199
+ case " ":
1200
+ case "\r":
1201
+ case "\n":
1202
+ case ".":
1203
+ if (r !== q && r !== J) return;
1204
+ a += t;
1205
+ break;
1206
+ case "/":
1207
+ if (r === q || r === J) a += t;
1208
+ else if (r === X) {
1209
+ if (a) return;
1210
+ r = G;
1211
+ } else if (r === void 0 || r === G) {
1212
+ if (!Z(a, n)) return;
1213
+ a = "", r = G;
1214
+ } else return;
1215
+ break;
1216
+ case "[":
1217
+ if (r === q || r === J) a += t;
1218
+ else if (r === G) {
1219
+ if (!Z(a, n)) return;
1220
+ a = "", r = K;
1221
+ } else if (r === X) {
1222
+ if (a) return;
1223
+ r = K;
1224
+ } else if (r === void 0) {
1225
+ if (a) {
1226
+ if (!Z(a, n)) return;
1227
+ a = "";
1228
+ }
1229
+ r = K;
1230
+ } else return;
1231
+ break;
1232
+ case "]":
1233
+ if (r === q || r === J) a += t;
1234
+ else if (r === K) {
1235
+ if (!a) return;
1236
+ a === "*" ? n.push({ kind: "wildcard-index" }) : n.push({
1237
+ kind: "index",
1238
+ value: parseInt(a, 10)
1239
+ }), a = "", r = X;
1240
+ } else if (r === Y) n.push({
1241
+ kind: "key",
1242
+ value: a
1243
+ }), a = "", r = X;
1244
+ else return;
1245
+ break;
1246
+ case "'":
1247
+ if (i || r === J) a += t;
1248
+ else if (r === q) r = Y;
1249
+ else if (r === K && !a) r = q;
1250
+ else return;
1251
+ break;
1252
+ case "\"":
1253
+ if (i || r === q) a += t;
1254
+ else if (r === J) r = Y;
1255
+ else if (r === K && !a) r = J;
1256
+ else return;
1257
+ break;
1258
+ default:
1259
+ if (r === Y) return;
1260
+ if (r === K) if (t === "*") {
1261
+ if (a.length > 0) return;
1262
+ } else if (t >= "0" && t <= "9") {
1263
+ if (a === "*") return;
1264
+ } else return;
1265
+ a += t;
1266
+ break;
1267
+ }
1268
+ i = !1;
1269
+ }
1270
+ switch (r) {
1271
+ case void 0:
1272
+ if (a && !Z(a, n)) return;
1273
+ break;
1274
+ case X:
1275
+ if (a) return;
1276
+ break;
1277
+ case G:
1278
+ if (a && !Z(a, n)) return;
1279
+ break;
1280
+ default: return;
1281
+ }
1282
+ return t != null && (t.size >= 500 && t.clear(), t.set(e, n.slice())), n;
1283
+ }
1284
+ var Qe = /[\\^$.*+?()[\]{}|]/g, $e = RegExp(Qe.source), et = (e) => e && $e.test(e) ? e.replace(Qe, "\\$&") : e;
1285
+ function tt(e, t) {
1286
+ if (!(e == null || e.length === 0)) {
1287
+ if (e[0].kind === "root") e.shift();
1288
+ else {
1289
+ let n = t.slice(0, -1);
1290
+ for (; e[0].kind === "parent";) {
1291
+ if (n.pop() == null) return;
1292
+ e.shift();
1293
+ }
1294
+ e.unshift(...n.map((e) => ({
1295
+ kind: typeof e == "number" ? "index" : "property",
1296
+ value: e
1297
+ })));
1298
+ }
1299
+ return `^${e.map((e, t) => {
1300
+ switch (e.kind) {
1301
+ case "wildcard": return (t === 0 ? "" : "\\.") + "[$_\\p{ID_Start}][$\\p{ID_Continue}]*";
1302
+ case "double-wildcard": return (t === 0 ? "" : "\\.") + ".*";
1303
+ case "wildcard-index": return "\\[[0-9]+\\]";
1304
+ case "key": return `\\['${et(e.value)}'\\]`;
1305
+ case "index": return Number.isNaN(e.value) ? "\\[[0-9]+\\]" : `\\[${e.value.toFixed(0)}\\]`;
1306
+ default: return (t === 0 ? "" : "\\.") + et(e.value);
1307
+ }
1308
+ }).join("")}$`;
1309
+ }
1310
+ }
1311
+ //#endregion
1312
+ //#region src/reform/observers/useObservers.ts
1313
+ function nt(e, t, n) {
1314
+ let r = Re(t);
1315
+ Object.entries(r ?? {}).forEach(([t, r]) => {
1316
+ let i = r.kind === "array";
1317
+ e.push(t), i && e.push(NaN), r.observers?.forEach((t) => {
1318
+ let r = Ze(t.path);
1319
+ if (r != null) {
1320
+ let i = tt(r, e);
1321
+ if (i != null) {
1322
+ let r = n.get(i);
1323
+ r ?? (r = [], n.set(i, r)), r.push({
1324
+ observer: t,
1325
+ path: e.concat()
1326
+ });
1327
+ }
1328
+ }
1329
+ });
1330
+ let a = ze(r);
1331
+ a != null && nt(e, a, n), i && e.pop(), e.pop();
1332
+ });
1333
+ }
1334
+ function rt(e, t, n, r) {
1335
+ return {
1336
+ path: e,
1337
+ observedValue: n.detail.value,
1338
+ currentValue: t,
1339
+ setValue: (t, i) => {
1340
+ let a = {
1341
+ touch: !0,
1342
+ propagate: !1
1343
+ };
1344
+ i != null && (i.untouch === !0 && (a.touch = !1), i.propagate === !0 && (a.propagate = !0)), n.detail.form.setValue(e, t, a), r.value = !0;
1345
+ },
1346
+ event: n
1347
+ };
1348
+ }
1349
+ function it(e, t, n, r, i, a) {
1350
+ if (r.length === 0 || t == null) return;
1351
+ let o = r[0];
1352
+ if (typeof o == "string") o in t && (t = t[o], r.length === 1 ? e.observer.callback(rt(n.concat(o), t, i, a)) : t != null && it(e, t, n.concat(o), r.slice(1), i, a));
1353
+ else if (Array.isArray(t)) {
1354
+ let s = r.slice(1);
1355
+ if (Number.isNaN(o)) t.forEach((t, r) => {
1356
+ if (t != null) {
1357
+ let o = n.concat(r);
1358
+ s.length === 0 ? e.observer.callback(rt(o, t, i, a)) : it(e, t, o, s, i, a);
1359
+ }
1360
+ });
1361
+ else {
1362
+ let r = t[o];
1363
+ if (r != null) {
1364
+ let t = n.concat(o);
1365
+ s.length === 0 ? e.observer.callback(rt(t, r, i, a)) : it(e, r, t, s, i, a);
1366
+ }
1367
+ }
1368
+ }
1369
+ }
1370
+ function at(e) {
1371
+ let t = /* @__PURE__ */ new Map();
1372
+ nt([], e, t);
1373
+ let n = Array.from(t.entries()).map(([e, t]) => [new RegExp(e, "u"), t]);
1374
+ return ((e) => {
1375
+ let t = e.detail.form.values;
1376
+ if (t == null) return;
1377
+ let r = x(e.detail.path) ?? [], i = { value: !1 };
1378
+ n.forEach(([n, a]) => {
1379
+ n.test(e.detail.path) && a.forEach((n) => {
1380
+ let a = t, o = [];
1381
+ if (n.observer.path[0] !== "/") for (let e = 0; e < n.path.length && e < r.length; e++) {
1382
+ let t = n.path[e], i = r[e];
1383
+ if (t !== i && !(Number.isNaN(t) && typeof i == "number") || (o.push(i), a = a[i], a == null)) break;
1384
+ }
1385
+ let s = o.length > 0 ? n.path.slice(o.length) : n.path;
1386
+ it(n, a, o, s, e, i);
1387
+ });
1388
+ }), i.value && (e.detail.form.validate(), e.detail.form.render());
1389
+ });
1390
+ }
1391
+ function ot(e, t) {
1392
+ n(() => {
1393
+ if (e != null) {
1394
+ let n = at(e);
1395
+ return t.addReformEventListener(n), () => {
1396
+ t.removeReformEventListener(n);
1397
+ };
1398
+ }
1399
+ }, [e]);
1400
+ }
1401
+ //#endregion
1402
+ //#region src/reform/useRender.ts
1403
+ function st() {
1404
+ return i(() => ({}), {})[1];
1405
+ }
1406
+ //#endregion
1407
+ //#region src/reform/useForm.ts
1408
+ function ct(e, t, n = []) {
1409
+ let i = typeof e == "function" ? e : void 0, a = st();
1410
+ n = Array.isArray(t) ? t : n;
1411
+ let o = r(() => {
1412
+ let n = new Je(a);
1413
+ if (typeof e == "function") e = {
1414
+ initialValues: new e(),
1415
+ validationSchema: Me({
1416
+ of: e,
1417
+ required: !0
1418
+ }),
1419
+ onSubmit: t
1420
+ };
1421
+ else if (typeof e.initialValues == "function") {
1422
+ let t = e.initialValues();
1423
+ pe(t) && (n.initialValuesPending = !0, t.then((t) => {
1424
+ setTimeout(() => {
1425
+ e = {
1426
+ ...n.config,
1427
+ initialValues: t
1428
+ }, n.onRender(e), n.commitInitialValues(), n.initialValuesPending = !1, a();
1429
+ }, 0);
1430
+ }), t = n.initialValues), e = {
1431
+ ...e,
1432
+ initialValues: t
1433
+ };
1434
+ }
1435
+ return n.onRender(e), n;
1436
+ }, n);
1437
+ return typeof e == "function" ? e = {
1438
+ ...o.config,
1439
+ onSubmit: t
1440
+ } : typeof e.initialValues == "function" && (e = {
1441
+ ...e,
1442
+ initialValues: o.initialValues
1443
+ }), o.onRender(e), ot(i, o), o;
1444
+ }
1445
+ //#endregion
1446
+ //#region src/reform/useFormField.ts
1447
+ function Q(e, t = !1) {
1448
+ let n = st(), r = d(), i = a(void 0), o = r.statuses.get(e);
1449
+ return o?.level === "pending" && pe(o.constraint) && i.current !== o.constraint && (i.current = o.constraint, o.constraint.finally(() => {
1450
+ i.current === o.constraint && (r.updateAsyncStatus(e), r.render());
1451
+ })), {
1452
+ value: r.getValue(e),
1453
+ touched: r.isTouched(e),
1454
+ status: o,
1455
+ form: r,
1456
+ render: n,
1457
+ constraints: r.constraintsAt(e, t)
1458
+ };
1459
+ }
1460
+ //#endregion
1461
+ //#region src/reform/components/BaseCheckboxField.tsx
1462
+ function lt(e) {
1463
+ let { onChange: t, render: n, ...r } = e, { value: i, form: o } = Q(e.name), c = a(null), l = (n) => {
1464
+ let r = n.currentTarget.checked;
1465
+ r !== i && (o.setValue(e.name, r, !0), t?.(r, o));
1466
+ };
1467
+ if (c.current == null || c.current !== document.activeElement) {
1468
+ let e = i ?? !1;
1469
+ c.current ? c.current.checked = e : r.defaultChecked = e;
1470
+ }
1471
+ return /* @__PURE__ */ s("input", {
1472
+ ...r,
1473
+ type: "checkbox",
1474
+ ref: c,
1475
+ onChange: l
1476
+ });
1477
+ }
1478
+ //#endregion
1479
+ //#region src/reform/components/BaseDateField.tsx
1480
+ var ut = (e) => e && !isNaN(e.getTime()) ? `${e.getFullYear().toString().padStart(4, "0")}-${(e.getMonth() + 1).toString().padStart(2, "0")}-${e.getDate().toString().padStart(2, "0")}` : null, dt = (e) => {
1481
+ if (e == null || typeof e != "string") return null;
1482
+ let t = e.indexOf("T");
1483
+ t >= 0 && (e = e.substring(0, t));
1484
+ let n = /* @__PURE__ */ new Date(e + "T00:00:00");
1485
+ return isNaN(n.getTime()) ? null : n;
1486
+ };
1487
+ function ft(e) {
1488
+ let { onChange: t, onBlur: n, render: r, ...i } = e, { value: o, form: c } = Q(e.name), l = a(null), u = (e) => {
1489
+ let t = e.currentTarget.value;
1490
+ return dt(t);
1491
+ }, d = (n) => {
1492
+ if (!n.currentTarget.validity.badInput) {
1493
+ let i = u(n);
1494
+ i !== o && (c.setValue(e.name, i), c.validateAt(e.name).changed && r(), t?.(i, c));
1495
+ }
1496
+ }, f = (t) => {
1497
+ let { valid: r, valueMissing: i, badInput: a } = t.currentTarget.validity, s = r ? u(t) : i && !a ? null : o ?? null;
1498
+ c.setValue(e.name, s, !0), n?.(s, c);
1499
+ };
1500
+ if (l.current == null || l.current !== document.activeElement) {
1501
+ let e = ut(o) ?? "";
1502
+ l.current ? l.current.value = e : i.defaultValue = e;
1503
+ }
1504
+ return /* @__PURE__ */ s("input", {
1505
+ ...i,
1506
+ ref: l,
1507
+ onChange: d,
1508
+ onBlur: f
1509
+ });
1510
+ }
1511
+ //#endregion
1512
+ //#region src/reform/components/BaseRadioField.tsx
1513
+ function pt(e) {
1514
+ let { onChange: t, onBlur: n, modelValue: r, render: i, ...o } = e, { value: c, form: l } = Q(e.name), u = a(null), d = (n) => {
1515
+ n.currentTarget.checked && r !== c && (l.setValue(e.name, r, !0), t?.(r, l));
1516
+ };
1517
+ if (u.current == null || u.current !== document.activeElement) {
1518
+ let e = c === r;
1519
+ u.current ? u.current.checked = e : o.defaultChecked = e;
1520
+ }
1521
+ return /* @__PURE__ */ s("input", {
1522
+ ...o,
1523
+ type: "radio",
1524
+ ref: u,
1525
+ onChange: d
1526
+ });
1527
+ }
1528
+ //#endregion
1529
+ //#region src/reform/components/BaseSelectField.tsx
1530
+ function mt(e) {
1531
+ let { onChange: t, onBlur: n, toModelValue: r, render: i, modelValues: o, toOptionValue: c, toOptionContent: l, ...u } = e, { value: d, form: f } = Q(e.name), p = a(null), m = (n) => {
1532
+ let i = r(n.currentTarget.value);
1533
+ i !== d && (f.setValue(e.name, i, !0), t?.(i, f));
1534
+ };
1535
+ if (p.current == null || p.current !== document.activeElement) {
1536
+ let e = c(d ?? null);
1537
+ p.current == null ? u.defaultValue = e : p.current.value = e;
1538
+ }
1539
+ return /* @__PURE__ */ s("select", {
1540
+ ...u,
1541
+ ref: p,
1542
+ onChange: m,
1543
+ children: o.map((e) => {
1544
+ let t = c(e);
1545
+ return /* @__PURE__ */ s("option", {
1546
+ value: t,
1547
+ children: l(e)
1548
+ }, t);
1549
+ })
1550
+ });
1551
+ }
1552
+ //#endregion
1553
+ //#region src/reform/components/BaseTextAreaField.tsx
1554
+ function ht(e) {
1555
+ let { render: t, onChange: n, onBlur: r, ...i } = e, { value: o, form: c } = Q(e.name), l = a(null), u = (r) => {
1556
+ let i = r.currentTarget.value || null;
1557
+ i !== o && (c.setValue(e.name, i), c.validateAt(e.name) && t(), n?.(i, c));
1558
+ }, d = (t) => {
1559
+ let n = t.currentTarget.value || null;
1560
+ c.setValue(e.name, n, !0), r?.(n, c);
1561
+ };
1562
+ if (l.current == null || l.current !== document.activeElement) {
1563
+ let e = o ?? "";
1564
+ l.current == null ? i.defaultValue = e : l.current.value = e;
1565
+ }
1566
+ return /* @__PURE__ */ s("textarea", {
1567
+ ...i,
1568
+ ref: l,
1569
+ onChange: u,
1570
+ onBlur: d
1571
+ });
1572
+ }
1573
+ //#endregion
1574
+ //#region src/reform/components/BaseTextField.tsx
1575
+ function gt(e) {
1576
+ let { onChange: t, onBlur: n, toModelValue: r, toTextValue: i, acceptInputValue: o, formatDisplayedValue: c, formatOnEdit: l, render: u, ...d } = e, { value: f, form: p } = Q(e.name), m = a(null), h = a(""), g = a({
1577
+ start: null,
1578
+ end: null
1579
+ }), _ = (e) => {
1580
+ let t = e.currentTarget.value.replace(/\0/g, "");
1581
+ return r ? r(t) : t === "" ? null : t;
1582
+ }, v = (e) => {
1583
+ let t = e.currentTarget;
1584
+ if (g.current = {
1585
+ start: t.selectionStart,
1586
+ end: t.selectionEnd,
1587
+ direction: t.selectionDirection ?? void 0
1588
+ }, l !== !1 && c && t.selectionStart === t.value.length) {
1589
+ let e = c(t.value);
1590
+ t.value !== e && (t.value = e);
1591
+ }
1592
+ }, y = (e) => {
1593
+ let t = e.currentTarget;
1594
+ if (o?.(t.value) === !1) {
1595
+ t.value = h.current;
1596
+ let e = g.current;
1597
+ t.setSelectionRange(e.start, e.end, e.direction);
1598
+ } else if (l !== !1 && c && t.selectionStart === t.value.length) {
1599
+ let e = c(t.value);
1600
+ t.value !== e && (t.value = e);
1601
+ }
1602
+ }, ee = (n) => {
1603
+ h.current = n.currentTarget.value;
1604
+ let r = _(n);
1605
+ r !== f && (p.setValue(e.name, r), p.validateAt(e.name).changed && u(), t?.(r, p));
1606
+ }, b = (t) => {
1607
+ let r = _(t);
1608
+ p.setValue(e.name, r, !0), n?.(r, p);
1609
+ };
1610
+ if (m.current == null || m.current !== document.activeElement) {
1611
+ let e = i?.(f ?? null) ?? String(f ?? ""), t = c?.(e) ?? e;
1612
+ m.current ? m.current.value = t : d.defaultValue = t, h.current = t;
1613
+ }
1614
+ return /* @__PURE__ */ s("input", {
1615
+ ...d,
1616
+ ref: m,
1617
+ onSelect: v,
1618
+ onInput: y,
1619
+ onChange: ee,
1620
+ onBlur: b
1621
+ });
1622
+ }
1623
+ //#endregion
1624
+ //#region src/yop/constraints/OneOfConstraint.ts
1625
+ function $(e, t, n, r) {
1626
+ return F(e, t, "oneOf", n, (e, t) => r == null ? t.includes(e) : t.some((t) => r(e, t)));
1627
+ }
1628
+ //#endregion
1629
+ //#region src/yop/decorators/boolean.ts
1630
+ function _t(e, t) {
1631
+ return R(e, A, "boolean") && $(e, t, ue) && z(e, t);
1632
+ }
1633
+ function vt(e, t) {
1634
+ return V("boolean", e ?? {}, t, _t);
1635
+ }
1636
+ //#endregion
1637
+ //#region src/yop/decorators/date.ts
1638
+ function yt(e, t) {
1639
+ return R(e, P, "date") && I(e, t, P, (e, t) => e >= t, (e, t) => e <= t) && $(e, t, fe, (e, t) => e.getTime() === t.getTime()) && z(e, t);
1640
+ }
1641
+ function bt(e, t) {
1642
+ return V("date", e ?? {}, t, yt, P);
1643
+ }
1644
+ //#endregion
1645
+ //#region src/yop/decorators/string.ts
1646
+ function xt(e, t, n, r, i) {
1647
+ return R(e, M, i ?? "string") && I(e, t, j, (e, t) => e.length >= t, (e, t) => e.length <= t) && F(e, t, "match", ce, (e, t) => t.test(e), n, r) && $(e, t, le) && z(e, t);
1648
+ }
1649
+ function St(e, t) {
1650
+ return V("string", e ?? {}, t, xt, j);
1651
+ }
1652
+ //#endregion
1653
+ //#region src/yop/decorators/email.ts
1654
+ var Ct = /^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))$/i;
1655
+ function wt(e, t) {
1656
+ return xt(e, t, Ct, t.formatError, "email");
1657
+ }
1658
+ function Tt(e, t) {
1659
+ return V("email", e ?? {}, t, wt, j);
1660
+ }
1661
+ //#endregion
1662
+ //#region src/yop/decorators/file.ts
1663
+ function Et(e, t) {
1664
+ return R(e, se, "file") && I(e, t, j, (e, t) => e.size >= t, (e, t) => e.size <= t) && z(e, t);
1665
+ }
1666
+ function Dt(e, t) {
1667
+ return V("file", e ?? {}, t, Et, j);
1668
+ }
1669
+ //#endregion
1670
+ //#region src/yop/decorators/id.ts
1671
+ function Ot(e) {
1672
+ return function(t, n) {
1673
+ U.registerClass(e, t);
1674
+ };
1675
+ }
1676
+ //#endregion
1677
+ //#region src/yop/decorators/number.ts
1678
+ function kt(e, t) {
1679
+ return R(e, j, "number") && I(e, t, j, (e, t) => e >= t, (e, t) => e <= t) && $(e, t, de) && z(e, t);
1680
+ }
1681
+ function At(e, t) {
1682
+ return V("number", e ?? {}, t, kt, j);
1683
+ }
1684
+ //#endregion
1685
+ //#region src/yop/decorators/test.ts
1686
+ function jt(e) {
1687
+ return function(t, n) {
1688
+ let r = Fe(n.metadata);
1689
+ r.test = e;
1690
+ };
1691
+ }
1692
+ //#endregion
1693
+ //#region src/yop/decorators/time.ts
1694
+ var Mt = /^([01][0-9]|2[0-3]):([0-5][0-9])(?::([0-5][0-9])(?:\.([0-9]{1,3}))?)?$/;
1695
+ function Nt(e) {
1696
+ let t = Mt.exec(e);
1697
+ return t == null ? void 0 : t[1] * 3600 * 1e3 + t[2] * 60 * 1e3 + (t[3] ?? 0) * 1e3 + +(t[4] ?? 0);
1698
+ }
1699
+ var Pt = 24 * 3600 * 1e3 - 1;
1700
+ function Ft(e, t) {
1701
+ if (!R(e, M, "time")) return !1;
1702
+ let n = Nt(e.value);
1703
+ if (n == null) {
1704
+ let n = N(t.formatError) ? t.formatError(e) : t.formatError;
1705
+ return e.setStatus("match", Mt, n) == null;
1706
+ }
1707
+ return I(e, t, M, (e, t) => n >= (Nt(t) ?? 0), (e, t) => n <= (Nt(t) ?? Pt)) && $(e, t, le) && z(e, t);
1708
+ }
1709
+ function It(e, t) {
1710
+ return V("time", e ?? {}, t, Ft, M);
1711
+ }
1712
+ //#endregion
1713
+ export { l as ArrayHelper, lt as BaseCheckboxField, ft as BaseDateField, pt as BaseRadioField, mt as BaseSelectField, ht as BaseTextAreaField, gt as BaseTextField, ge as BasicMessageProvider, p as Form, u as FormContext, Je as InternalFormManager, Ge as InternalValidationContext, f as Reform, We as UndefinedParent, U as Yop, Oe as array, De as arrayKind, ie as assign, vt as boolean, O as clone, bt as date, k as defineLazyProperty, re as diff, ne as differs, Tt as email, Ct as emailRegex, E as equal, B as fieldDecorator, V as fieldValidationDecorator, Dt as file, C as get, ze as getClassConstructor, Le as getMetadata, Re as getMetadataFields, Ie as getMetadataFromDecorator, Ve as getValidationDecoratorKind, Ot as id, W as ignored, Fe as initClassConstraints, Me as instance, je as instanceKind, A as isBoolean, ue as isBooleanArray, P as isDate, fe as isDateArray, se as isFile, N as isFunction, j as isNumber, de as isNumberArray, oe as isObject, pe as isPromise, ce as isRegExp, M as isString, le as isStringArray, ae as isSubclassOf, S as joinPath, ut as localDateToString, Ue as mergeDefaultMetadata, He as mergeMetadata, _e as messageProvider_en_US, ve as messageProvider_fr_FR, At as number, Ye as observer, w as set, x as splitPath, St as string, dt as stringToLocalDate, jt as test, It as time, Mt as timeRegex, Nt as timeToMillis, Ne as traverseClass, te as unset, ct as useForm, d as useFormContext, Q as useFormField, ot as useObservers, st as useRender, Pe as validateClass, ye as validateCommonConstraints, F as validateConstraint, wt as validateEmail, I as validateMinMaxConstraints, $ as validateOneOfConstraint, xt as validateString, z as validateTestConstraint, Ft as validateTime, R as validateTypeConstraint, H as validationSymbol };
1714
+
1715
+ //# sourceMappingURL=index.es.js.map