@reformer/core 1.1.0-beta.7 → 1.1.0-beta.8

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 (80) hide show
  1. package/dist/behaviors-BRaiR-UY.js +528 -0
  2. package/dist/behaviors.d.ts +6 -2
  3. package/dist/behaviors.js +18 -227
  4. package/dist/index.d.ts +2 -0
  5. package/dist/index.js +3380 -10
  6. package/dist/validators-DjXtDVoE.js +455 -0
  7. package/dist/validators.d.ts +6 -2
  8. package/dist/validators.js +29 -281
  9. package/package.json +1 -1
  10. package/dist/core/behavior/behavior-applicator.js +0 -92
  11. package/dist/core/behavior/behavior-context.js +0 -43
  12. package/dist/core/behavior/behavior-registry.js +0 -198
  13. package/dist/core/behavior/behaviors/compute-from.js +0 -84
  14. package/dist/core/behavior/behaviors/copy-from.js +0 -64
  15. package/dist/core/behavior/behaviors/enable-when.js +0 -81
  16. package/dist/core/behavior/behaviors/index.js +0 -11
  17. package/dist/core/behavior/behaviors/reset-when.js +0 -63
  18. package/dist/core/behavior/behaviors/revalidate-when.js +0 -51
  19. package/dist/core/behavior/behaviors/sync-fields.js +0 -66
  20. package/dist/core/behavior/behaviors/transform-value.js +0 -110
  21. package/dist/core/behavior/behaviors/watch-field.js +0 -56
  22. package/dist/core/behavior/compose-behavior.js +0 -166
  23. package/dist/core/behavior/create-field-path.js +0 -69
  24. package/dist/core/behavior/index.js +0 -17
  25. package/dist/core/behavior/types.js +0 -7
  26. package/dist/core/context/form-context-impl.js +0 -37
  27. package/dist/core/factories/index.js +0 -6
  28. package/dist/core/factories/node-factory.js +0 -281
  29. package/dist/core/nodes/array-node.js +0 -534
  30. package/dist/core/nodes/field-node.js +0 -510
  31. package/dist/core/nodes/form-node.js +0 -343
  32. package/dist/core/nodes/group-node/field-registry.js +0 -215
  33. package/dist/core/nodes/group-node/index.js +0 -11
  34. package/dist/core/nodes/group-node/proxy-builder.js +0 -161
  35. package/dist/core/nodes/group-node/state-manager.js +0 -265
  36. package/dist/core/nodes/group-node.js +0 -770
  37. package/dist/core/types/deep-schema.js +0 -11
  38. package/dist/core/types/field-path.js +0 -4
  39. package/dist/core/types/form-context.js +0 -25
  40. package/dist/core/types/group-node-proxy.js +0 -31
  41. package/dist/core/types/index.js +0 -4
  42. package/dist/core/types/validation-schema.js +0 -10
  43. package/dist/core/utils/create-form.js +0 -24
  44. package/dist/core/utils/debounce.js +0 -197
  45. package/dist/core/utils/error-handler.js +0 -226
  46. package/dist/core/utils/field-path-navigator.js +0 -374
  47. package/dist/core/utils/index.js +0 -14
  48. package/dist/core/utils/registry-helpers.js +0 -79
  49. package/dist/core/utils/registry-stack.js +0 -86
  50. package/dist/core/utils/resources.js +0 -69
  51. package/dist/core/utils/subscription-manager.js +0 -214
  52. package/dist/core/utils/type-guards.js +0 -169
  53. package/dist/core/validation/core/apply-when.js +0 -41
  54. package/dist/core/validation/core/apply.js +0 -38
  55. package/dist/core/validation/core/index.js +0 -8
  56. package/dist/core/validation/core/validate-async.js +0 -45
  57. package/dist/core/validation/core/validate-tree.js +0 -43
  58. package/dist/core/validation/core/validate.js +0 -38
  59. package/dist/core/validation/field-path.js +0 -147
  60. package/dist/core/validation/index.js +0 -33
  61. package/dist/core/validation/validate-form.js +0 -152
  62. package/dist/core/validation/validation-applicator.js +0 -217
  63. package/dist/core/validation/validation-context.js +0 -75
  64. package/dist/core/validation/validation-registry.js +0 -298
  65. package/dist/core/validation/validators/array-validators.js +0 -86
  66. package/dist/core/validation/validators/date.js +0 -117
  67. package/dist/core/validation/validators/email.js +0 -60
  68. package/dist/core/validation/validators/index.js +0 -14
  69. package/dist/core/validation/validators/max-length.js +0 -60
  70. package/dist/core/validation/validators/max.js +0 -60
  71. package/dist/core/validation/validators/min-length.js +0 -60
  72. package/dist/core/validation/validators/min.js +0 -60
  73. package/dist/core/validation/validators/number.js +0 -90
  74. package/dist/core/validation/validators/pattern.js +0 -62
  75. package/dist/core/validation/validators/phone.js +0 -58
  76. package/dist/core/validation/validators/required.js +0 -69
  77. package/dist/core/validation/validators/url.js +0 -55
  78. package/dist/create-field-path-nXfTtl55.js +0 -283
  79. package/dist/hooks/useFormControl.js +0 -298
  80. package/dist/validation-context-cWXmh_Ho.js +0 -156
@@ -0,0 +1,455 @@
1
+ import { g as u, V as y } from "./registry-helpers-BfCZcMkO.js";
2
+ function o() {
3
+ return d("");
4
+ }
5
+ function d(r) {
6
+ return new Proxy({}, {
7
+ get(e, t) {
8
+ if (typeof t == "symbol")
9
+ return;
10
+ if (t === "__path")
11
+ return r || t;
12
+ if (t === "__key") {
13
+ const n = r.split(".");
14
+ return n[n.length - 1] || t;
15
+ }
16
+ if (t === "then" || t === "catch" || t === "finally" || t === "constructor" || t === "toString" || t === "valueOf" || t === "toJSON")
17
+ return;
18
+ const a = r ? `${r}.${t}` : t, s = {
19
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
20
+ __key: t,
21
+ __path: a,
22
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
23
+ __formType: void 0,
24
+ __fieldType: void 0
25
+ };
26
+ return new Proxy(s, {
27
+ get(n, i) {
28
+ if (typeof i != "symbol") {
29
+ if (i === "__path") return a;
30
+ if (i === "__key") return t;
31
+ if (i !== "__formType" && i !== "__fieldType" && !(i === "then" || i === "catch" || i === "finally" || i === "constructor" || i === "toString" || i === "valueOf" || i === "toJSON"))
32
+ return d(`${a}.${i}`);
33
+ }
34
+ }
35
+ });
36
+ }
37
+ });
38
+ }
39
+ function f(r) {
40
+ if (typeof r == "string")
41
+ return r;
42
+ if (r && typeof r == "object") {
43
+ const e = r.__path;
44
+ if (typeof e == "string")
45
+ return e;
46
+ }
47
+ throw new Error("Invalid field path node: " + JSON.stringify(r));
48
+ }
49
+ function _(r) {
50
+ const e = f(r);
51
+ return d(e);
52
+ }
53
+ function N(r) {
54
+ if (r && typeof r == "object" && "__key" in r)
55
+ return r.__key;
56
+ if (typeof r == "string") {
57
+ const e = r.split(".");
58
+ return e[e.length - 1];
59
+ }
60
+ throw new Error("Invalid field path node");
61
+ }
62
+ function m(r, e, t) {
63
+ if (!r) return;
64
+ const a = f(r);
65
+ u().registerSync(a, e, t);
66
+ }
67
+ function b(r, e, t) {
68
+ const a = f(r);
69
+ u().registerAsync(a, e, t);
70
+ }
71
+ function D(r, e) {
72
+ u().registerTree(r, e);
73
+ }
74
+ function T(r, e) {
75
+ if (!Array.isArray(r) && !Array.isArray(e) && r && !("__key" in r) && !("__path" in r)) {
76
+ e(r);
77
+ return;
78
+ }
79
+ const t = (Array.isArray(r) ? r : [r]).filter(
80
+ Boolean
81
+ ), a = Array.isArray(e) ? e : [e];
82
+ for (const s of t) {
83
+ const n = _(s);
84
+ for (const i of a)
85
+ i(n);
86
+ }
87
+ }
88
+ function V(r, e, t) {
89
+ const a = f(r);
90
+ u().enterCondition(a, e);
91
+ try {
92
+ const s = o();
93
+ t(s);
94
+ } finally {
95
+ u().exitCondition();
96
+ }
97
+ }
98
+ function R(r, e) {
99
+ r && m(r, (t) => t == null || t === "" ? {
100
+ code: "required",
101
+ message: e?.message || "Поле обязательно для заполнения",
102
+ params: e?.params
103
+ } : typeof t == "boolean" && t !== !0 ? {
104
+ code: "required",
105
+ message: e?.message || "Поле обязательно для заполнения",
106
+ params: e?.params
107
+ } : null);
108
+ }
109
+ function C(r, e, t) {
110
+ r && m(r, (a) => a == null ? null : a < e ? {
111
+ code: "min",
112
+ message: t?.message || `Минимальное значение: ${e}`,
113
+ params: { min: e, actual: a, ...t?.params }
114
+ } : null);
115
+ }
116
+ function F(r, e, t) {
117
+ r && m(r, (a) => a == null ? null : a > e ? {
118
+ code: "max",
119
+ message: t?.message || `Максимальное значение: ${e}`,
120
+ params: { max: e, actual: a, ...t?.params }
121
+ } : null);
122
+ }
123
+ function h(r, e, t) {
124
+ r && m(r, (a) => a && a.length < e ? {
125
+ code: "minLength",
126
+ message: t?.message || `Минимальная длина: ${e} символов`,
127
+ params: { minLength: e, actualLength: a.length, ...t?.params }
128
+ } : null);
129
+ }
130
+ function L(r, e, t) {
131
+ r && m(r, (a) => a && a.length > e ? {
132
+ code: "maxLength",
133
+ message: t?.message || `Максимальная длина: ${e} символов`,
134
+ params: { maxLength: e, actualLength: a.length, ...t?.params }
135
+ } : null);
136
+ }
137
+ function k(r, e) {
138
+ if (!r) return;
139
+ const t = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
140
+ m(r, (a) => a ? t.test(a) ? null : {
141
+ code: "email",
142
+ message: e?.message || "Неверный формат email",
143
+ params: e?.params
144
+ } : null);
145
+ }
146
+ function I(r, e, t) {
147
+ r && m(r, (a) => a ? e.test(a) ? null : {
148
+ code: "pattern",
149
+ message: t?.message || "Значение не соответствует требуемому формату",
150
+ params: { pattern: e.source, ...t?.params }
151
+ } : null);
152
+ }
153
+ function S(r, e) {
154
+ if (!r) return;
155
+ const t = /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/i, a = /^https?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/i;
156
+ m(r, (s) => s ? (e?.requireProtocol ? a : t).test(s) ? e?.allowedProtocols && e.allowedProtocols.length > 0 && !e.allowedProtocols.some(
157
+ (l) => s.toLowerCase().startsWith(`${l}://`)
158
+ ) ? {
159
+ code: "url_protocol",
160
+ message: e?.message || `URL должен использовать один из протоколов: ${e.allowedProtocols.join(", ")}`,
161
+ params: { allowedProtocols: e.allowedProtocols, ...e?.params }
162
+ } : null : {
163
+ code: "url",
164
+ message: e?.message || "Неверный формат URL",
165
+ params: e?.params
166
+ } : null);
167
+ }
168
+ function j(r, e) {
169
+ if (!r) return;
170
+ const t = e?.format || "any", a = {
171
+ // Международный формат: +1234567890 или +1 234 567 8900
172
+ international: /^\+?[1-9]\d{1,14}$/,
173
+ // Российский формат: +7 (XXX) XXX-XX-XX, 8 (XXX) XXX-XX-XX, и вариации
174
+ ru: /^(\+7|7|8)?[\s\-]?\(?[489][0-9]{2}\)?[\s\-]?[0-9]{3}[\s\-]?[0-9]{2}[\s\-]?[0-9]{2}$/,
175
+ // US формат: (123) 456-7890, 123-456-7890, 1234567890
176
+ us: /^(\+?1)?[\s\-]?\(?[2-9]\d{2}\)?[\s\-]?\d{3}[\s\-]?\d{4}$/,
177
+ // Любой формат: минимум 10 цифр с возможными разделителями
178
+ any: /^[\+]?[(]?[0-9]{1,4}[)]?[-\s\.]?[(]?[0-9]{1,4}[)]?[-\s\.]?[0-9]{1,9}$/
179
+ };
180
+ m(r, (s) => {
181
+ if (!s)
182
+ return null;
183
+ if (!a[t].test(s)) {
184
+ const i = {
185
+ international: "Введите телефон в международном формате (например, +1234567890)",
186
+ ru: "Введите российский номер телефона (например, +7 900 123-45-67)",
187
+ us: "Введите американский номер телефона (например, (123) 456-7890)",
188
+ any: "Неверный формат телефона"
189
+ };
190
+ return {
191
+ code: "phone",
192
+ message: e?.message || i[t],
193
+ params: { format: t, ...e?.params }
194
+ };
195
+ }
196
+ return null;
197
+ });
198
+ }
199
+ function p(r, e) {
200
+ r && m(r, (t) => t == null ? null : typeof t != "number" || isNaN(t) ? {
201
+ code: "number",
202
+ message: e?.message || "Значение должно быть числом",
203
+ params: e?.params
204
+ } : e?.integer && !Number.isInteger(t) ? {
205
+ code: "number_integer",
206
+ message: e?.message || "Значение должно быть целым числом",
207
+ params: e?.params
208
+ } : e?.min !== void 0 && t < e.min ? {
209
+ code: "number_min",
210
+ message: e?.message || `Значение должно быть не менее ${e.min}`,
211
+ params: { min: e.min, ...e?.params }
212
+ } : e?.max !== void 0 && t > e.max ? {
213
+ code: "number_max",
214
+ message: e?.message || `Значение должно быть не более ${e.max}`,
215
+ params: { max: e.max, ...e?.params }
216
+ } : e?.multipleOf !== void 0 && t % e.multipleOf !== 0 ? {
217
+ code: "number_multiple",
218
+ message: e?.message || `Значение должно быть кратно ${e.multipleOf}`,
219
+ params: { multipleOf: e.multipleOf, ...e?.params }
220
+ } : e?.allowNegative === !1 && t < 0 ? {
221
+ code: "number_negative",
222
+ message: e?.message || "Отрицательные числа не допускаются",
223
+ params: e?.params
224
+ } : e?.allowZero === !1 && t === 0 ? {
225
+ code: "number_zero",
226
+ message: e?.message || "Ноль не допускается",
227
+ params: e?.params
228
+ } : null);
229
+ }
230
+ function z(r, e) {
231
+ r && m(r, (t) => {
232
+ if (!t)
233
+ return null;
234
+ let a;
235
+ if (t instanceof Date)
236
+ a = t;
237
+ else if (typeof t == "string")
238
+ a = new Date(t);
239
+ else
240
+ return {
241
+ code: "date_invalid",
242
+ message: e?.message || "Неверный формат даты",
243
+ params: e?.params
244
+ };
245
+ if (isNaN(a.getTime()))
246
+ return {
247
+ code: "date_invalid",
248
+ message: e?.message || "Неверный формат даты",
249
+ params: e?.params
250
+ };
251
+ const s = /* @__PURE__ */ new Date();
252
+ if (s.setHours(0, 0, 0, 0), e?.minDate) {
253
+ const n = new Date(e.minDate);
254
+ if (n.setHours(0, 0, 0, 0), a < n)
255
+ return {
256
+ code: "date_min",
257
+ message: e?.message || `Дата должна быть не ранее ${n.toLocaleDateString()}`,
258
+ params: { minDate: e.minDate, ...e?.params }
259
+ };
260
+ }
261
+ if (e?.maxDate) {
262
+ const n = new Date(e.maxDate);
263
+ if (n.setHours(0, 0, 0, 0), a > n)
264
+ return {
265
+ code: "date_max",
266
+ message: e?.message || `Дата должна быть не позднее ${n.toLocaleDateString()}`,
267
+ params: { maxDate: e.maxDate, ...e?.params }
268
+ };
269
+ }
270
+ if (e?.noFuture && a > s)
271
+ return {
272
+ code: "date_future",
273
+ message: e?.message || "Дата не может быть в будущем",
274
+ params: e?.params
275
+ };
276
+ if (e?.noPast && a < s)
277
+ return {
278
+ code: "date_past",
279
+ message: e?.message || "Дата не может быть в прошлом",
280
+ params: e?.params
281
+ };
282
+ if (e?.minAge !== void 0 || e?.maxAge !== void 0) {
283
+ const n = Math.floor(
284
+ (s.getTime() - a.getTime()) / 315576e5
285
+ );
286
+ if (e?.minAge !== void 0 && n < e.minAge)
287
+ return {
288
+ code: "date_min_age",
289
+ message: e?.message || `Минимальный возраст: ${e.minAge} лет`,
290
+ params: { minAge: e.minAge, currentAge: n, ...e?.params }
291
+ };
292
+ if (e?.maxAge !== void 0 && n > e.maxAge)
293
+ return {
294
+ code: "date_max_age",
295
+ message: e?.message || `Максимальный возраст: ${e.maxAge} лет`,
296
+ params: { maxAge: e.maxAge, currentAge: n, ...e?.params }
297
+ };
298
+ }
299
+ return null;
300
+ });
301
+ }
302
+ function q(r, e) {
303
+ r && h(r, 1, {
304
+ message: e?.message || "Массив не должен быть пустым",
305
+ params: { minLength: 1, ...e?.params }
306
+ });
307
+ }
308
+ function B(r, e) {
309
+ if (!r) return;
310
+ const t = f(r);
311
+ u().registerArrayItemValidation(t, e);
312
+ }
313
+ function c(r) {
314
+ return r == null ? !1 : typeof r == "object" && "value" in r && "setValue" in r && "getValue" in r && "validate" in r;
315
+ }
316
+ function x(r) {
317
+ return r == null ? !1 : c(r) && "validators" in r && "asyncValidators" in r && // FieldNode имеет markAsTouched метод
318
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
319
+ typeof r.markAsTouched == "function" && // У FieldNode нет fields или items
320
+ !("fields" in r) && !("items" in r);
321
+ }
322
+ function A(r) {
323
+ return r == null ? !1 : c(r) && "applyValidationSchema" in r && "applyBehaviorSchema" in r && "getFieldByPath" in r && // GroupNode НЕ имеет items/push/removeAt (это ArrayNode)
324
+ !("items" in r) && !("push" in r) && !("removeAt" in r);
325
+ }
326
+ function w(r) {
327
+ return r == null ? !1 : c(r) && "items" in r && "length" in r && "push" in r && "removeAt" in r && "at" in r && // eslint-disable-next-line @typescript-eslint/no-explicit-any
328
+ typeof r.push == "function" && // eslint-disable-next-line @typescript-eslint/no-explicit-any
329
+ typeof r.removeAt == "function";
330
+ }
331
+ function J(r) {
332
+ return x(r) ? "FieldNode" : A(r) ? "GroupNode" : w(r) ? "ArrayNode" : c(r) ? "FormNode" : "Unknown";
333
+ }
334
+ function g(r) {
335
+ return x(r) ? [r] : A(r) ? Array.from(r.getAllFields()).flatMap(g) : w(r) ? r.map((e) => g(e)).flat() : [];
336
+ }
337
+ async function E(r, e) {
338
+ const t = new y();
339
+ t.beginRegistration();
340
+ let a = [], s = !1;
341
+ try {
342
+ const n = o();
343
+ e(n), a = t.getCurrentContext()?.getValidators() || [], t.cancelRegistration(), s = !0, r.clearErrors();
344
+ const l = g(r);
345
+ return await Promise.all(l.map(($) => $.validate())), a.length > 0 && await r.applyContextualValidators(a), r.valid.value;
346
+ } catch (n) {
347
+ throw s || t.cancelRegistration(), n;
348
+ }
349
+ }
350
+ class O {
351
+ _form;
352
+ control;
353
+ /**
354
+ * Форма с типизированным Proxy-доступом к полям
355
+ */
356
+ form;
357
+ constructor(e, t, a) {
358
+ this._form = e, this.control = a, this.form = e._proxyInstance || e.getProxy();
359
+ }
360
+ /**
361
+ * Получить текущее значение поля (внутренний метод для validation-applicator)
362
+ * @internal
363
+ */
364
+ value() {
365
+ return this.control.value.value;
366
+ }
367
+ /**
368
+ * Безопасно установить значение поля по строковому пути
369
+ * Автоматически использует emitEvent: false для предотвращения циклов
370
+ */
371
+ setFieldValue(e, t) {
372
+ const a = this._form.getFieldByPath(e);
373
+ a && c(a) && a.setValue(t, { emitEvent: !1 });
374
+ }
375
+ }
376
+ class M {
377
+ _form;
378
+ /**
379
+ * Форма с типизированным Proxy-доступом к полям
380
+ */
381
+ form;
382
+ constructor(e) {
383
+ this._form = e, this.form = e._proxyInstance || e.getProxy();
384
+ }
385
+ /**
386
+ * Безопасно установить значение поля по строковому пути
387
+ * Автоматически использует emitEvent: false для предотвращения циклов
388
+ */
389
+ setFieldValue(e, t) {
390
+ const a = this._form.getFieldByPath(e);
391
+ a && c(a) && a.setValue(t, { emitEvent: !1 });
392
+ }
393
+ }
394
+ const U = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
395
+ __proto__: null,
396
+ TreeValidationContextImpl: M,
397
+ ValidationContextImpl: O,
398
+ ValidationRegistry: y,
399
+ apply: T,
400
+ applyWhen: V,
401
+ createFieldPath: o,
402
+ date: z,
403
+ email: k,
404
+ extractKey: N,
405
+ extractPath: f,
406
+ max: F,
407
+ maxLength: L,
408
+ min: C,
409
+ minLength: h,
410
+ notEmpty: q,
411
+ number: p,
412
+ pattern: I,
413
+ phone: j,
414
+ required: R,
415
+ toFieldPath: _,
416
+ url: S,
417
+ validate: m,
418
+ validateAsync: b,
419
+ validateForm: E,
420
+ validateItems: B,
421
+ validateTree: D
422
+ }, Symbol.toStringTag, { value: "Module" }));
423
+ export {
424
+ f as A,
425
+ N as B,
426
+ _ as C,
427
+ M as T,
428
+ O as V,
429
+ U as a,
430
+ c as b,
431
+ o as c,
432
+ A as d,
433
+ w as e,
434
+ m as f,
435
+ J as g,
436
+ b as h,
437
+ x as i,
438
+ D as j,
439
+ T as k,
440
+ V as l,
441
+ C as m,
442
+ F as n,
443
+ h as o,
444
+ L as p,
445
+ k as q,
446
+ R as r,
447
+ I as s,
448
+ j as t,
449
+ S as u,
450
+ E as v,
451
+ p as w,
452
+ z as x,
453
+ q as y,
454
+ B as z
455
+ };
@@ -1,2 +1,6 @@
1
- export * from './core/validation/index'
2
- export {}
1
+ /**
2
+ * Re-export validators from the main index to ensure single module instance.
3
+ * This prevents static registry isolation issues when consuming the library.
4
+ */
5
+ export { validators as default } from './index';
6
+ export * from './core/validation';