@reformer/core 3.0.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (147) hide show
  1. package/dist/behaviors/compute-from.d.ts +2 -0
  2. package/dist/behaviors/compute-from.js +31 -0
  3. package/dist/behaviors/copy-from.d.ts +2 -0
  4. package/dist/behaviors/copy-from.js +29 -0
  5. package/dist/behaviors/enable-when.d.ts +2 -0
  6. package/dist/behaviors/enable-when.js +25 -0
  7. package/dist/behaviors/reset-when.d.ts +2 -0
  8. package/dist/behaviors/reset-when.js +24 -0
  9. package/dist/behaviors/revalidate-when.d.ts +2 -0
  10. package/dist/behaviors/revalidate-when.js +18 -0
  11. package/dist/behaviors/sync-fields.d.ts +2 -0
  12. package/dist/behaviors/sync-fields.js +41 -0
  13. package/dist/behaviors/transform-value.d.ts +2 -0
  14. package/dist/behaviors/transform-value.js +45 -0
  15. package/dist/behaviors/watch-field.d.ts +2 -0
  16. package/dist/behaviors/watch-field.js +21 -0
  17. package/dist/behaviors.js +26 -19
  18. package/dist/core/behavior/behavior-context.d.ts +26 -12
  19. package/dist/core/behavior/behavior-registry.d.ts +15 -27
  20. package/dist/core/behavior/behaviors/compute-from.d.ts +50 -21
  21. package/dist/core/behavior/behaviors/copy-from.d.ts +39 -14
  22. package/dist/core/behavior/behaviors/enable-when.d.ts +88 -19
  23. package/dist/core/behavior/behaviors/reset-when.d.ts +31 -18
  24. package/dist/core/behavior/behaviors/revalidate-when.d.ts +40 -17
  25. package/dist/core/behavior/behaviors/sync-fields.d.ts +34 -14
  26. package/dist/core/behavior/behaviors/transform-value.d.ts +116 -44
  27. package/dist/core/behavior/behaviors/watch-field.d.ts +66 -21
  28. package/dist/core/behavior/compose-behavior.d.ts +2 -12
  29. package/dist/core/behavior/index.d.ts +0 -1
  30. package/dist/core/behavior/types.d.ts +2 -8
  31. package/dist/core/factories/node-factory.d.ts +6 -29
  32. package/dist/core/nodes/array-node.d.ts +39 -19
  33. package/dist/core/nodes/field-node.d.ts +51 -26
  34. package/dist/core/nodes/form-node.d.ts +18 -20
  35. package/dist/core/nodes/group-node.d.ts +25 -21
  36. package/dist/core/types/deep-schema.d.ts +2 -12
  37. package/dist/core/types/field-path.d.ts +1 -1
  38. package/dist/core/types/form-context.d.ts +26 -26
  39. package/dist/core/types/form-proxy.d.ts +2 -32
  40. package/dist/core/types/index.d.ts +51 -5
  41. package/dist/core/types/validation-schema.d.ts +3 -12
  42. package/dist/core/utils/abstract-registry.d.ts +74 -0
  43. package/dist/core/utils/aggregate-signals.d.ts +71 -0
  44. package/dist/core/utils/create-form.d.ts +1 -18
  45. package/dist/core/utils/error-handler.d.ts +1 -18
  46. package/dist/core/utils/field-path-navigator.d.ts +1 -1
  47. package/dist/core/utils/field-path.d.ts +23 -11
  48. package/dist/core/utils/form-observer.d.ts +176 -0
  49. package/dist/core/utils/form-proxy-builder.d.ts +25 -0
  50. package/dist/core/utils/form-submitter.d.ts +121 -0
  51. package/dist/core/utils/index.d.ts +9 -2
  52. package/dist/core/utils/registry-helpers.d.ts +0 -7
  53. package/dist/core/utils/safe-effect.d.ts +73 -0
  54. package/dist/core/utils/status-machine.d.ts +153 -0
  55. package/dist/core/utils/type-guards.d.ts +5 -23
  56. package/dist/core/utils/unique-id.d.ts +53 -0
  57. package/dist/core/validation/core/apply-when.d.ts +3 -9
  58. package/dist/core/validation/core/apply.d.ts +2 -13
  59. package/dist/core/validation/core/validate-async.d.ts +2 -8
  60. package/dist/core/validation/core/validate-tree.d.ts +0 -6
  61. package/dist/core/validation/core/validate.d.ts +1 -7
  62. package/dist/core/validation/index.d.ts +8 -2
  63. package/dist/core/validation/validate-form.d.ts +1 -38
  64. package/dist/core/validation/validation-applicator.d.ts +2 -21
  65. package/dist/core/validation/validation-context.d.ts +58 -42
  66. package/dist/core/validation/validation-registry.d.ts +11 -25
  67. package/dist/core/validation/validators/array-validators.d.ts +2 -12
  68. package/dist/core/validation/validators/date-utils.d.ts +26 -0
  69. package/dist/core/validation/validators/email.d.ts +2 -9
  70. package/dist/core/validation/validators/future-date.d.ts +35 -0
  71. package/dist/core/validation/validators/index.d.ts +7 -1
  72. package/dist/core/validation/validators/is-date.d.ts +36 -0
  73. package/dist/core/validation/validators/max-age.d.ts +36 -0
  74. package/dist/core/validation/validators/max-date.d.ts +36 -0
  75. package/dist/core/validation/validators/max-length.d.ts +3 -10
  76. package/dist/core/validation/validators/max.d.ts +3 -10
  77. package/dist/core/validation/validators/min-age.d.ts +36 -0
  78. package/dist/core/validation/validators/min-date.d.ts +36 -0
  79. package/dist/core/validation/validators/min-length.d.ts +3 -10
  80. package/dist/core/validation/validators/min.d.ts +3 -10
  81. package/dist/core/validation/validators/number.d.ts +2 -9
  82. package/dist/core/validation/validators/past-date.d.ts +35 -0
  83. package/dist/core/validation/validators/pattern.d.ts +2 -9
  84. package/dist/core/validation/validators/phone.d.ts +2 -9
  85. package/dist/core/validation/validators/required.d.ts +2 -9
  86. package/dist/core/validation/validators/url.d.ts +2 -9
  87. package/dist/date-utils-xUWFslTj.js +29 -0
  88. package/dist/field-path-DuKdGcIE.js +66 -0
  89. package/dist/hooks/types.d.ts +1 -1
  90. package/dist/hooks/useArrayLength.d.ts +31 -0
  91. package/dist/hooks/useFormControl.d.ts +4 -4
  92. package/dist/hooks/useFormControlValue.d.ts +2 -2
  93. package/dist/hooks/useHiddenCondition.d.ts +25 -0
  94. package/dist/hooks/useSignalSubscription.d.ts +1 -1
  95. package/dist/index-D25LsbRm.js +73 -0
  96. package/dist/index.d.ts +2 -0
  97. package/dist/index.js +1171 -786
  98. package/dist/registry-helpers-Bv_BJ1s-.js +615 -0
  99. package/dist/safe-effect-Dh8uw81c.js +20 -0
  100. package/dist/validate-C3XiA_zf.js +10 -0
  101. package/dist/validators/email.d.ts +2 -0
  102. package/dist/validators/email.js +13 -0
  103. package/dist/validators/future-date.d.ts +2 -0
  104. package/dist/validators/future-date.js +20 -0
  105. package/dist/validators/is-date.d.ts +2 -0
  106. package/dist/validators/is-date.js +12 -0
  107. package/dist/validators/max-age.d.ts +2 -0
  108. package/dist/validators/max-age.js +20 -0
  109. package/dist/validators/max-date.d.ts +2 -0
  110. package/dist/validators/max-date.js +20 -0
  111. package/dist/validators/max-length.d.ts +2 -0
  112. package/dist/validators/max-length.js +11 -0
  113. package/dist/validators/max.d.ts +2 -0
  114. package/dist/validators/max.js +11 -0
  115. package/dist/validators/min-age.d.ts +2 -0
  116. package/dist/validators/min-age.js +20 -0
  117. package/dist/validators/min-date.d.ts +2 -0
  118. package/dist/validators/min-date.js +20 -0
  119. package/dist/validators/min-length.d.ts +2 -0
  120. package/dist/validators/min-length.js +11 -0
  121. package/dist/validators/min.d.ts +2 -0
  122. package/dist/validators/min.js +11 -0
  123. package/dist/validators/number.d.ts +2 -0
  124. package/dist/validators/number.js +35 -0
  125. package/dist/validators/past-date.d.ts +2 -0
  126. package/dist/validators/past-date.js +20 -0
  127. package/dist/validators/pattern.d.ts +2 -0
  128. package/dist/validators/pattern.js +11 -0
  129. package/dist/validators/phone.d.ts +2 -0
  130. package/dist/validators/phone.js +35 -0
  131. package/dist/validators/required.d.ts +2 -0
  132. package/dist/validators/required.js +15 -0
  133. package/dist/validators/url.d.ts +2 -0
  134. package/dist/validators/url.js +19 -0
  135. package/dist/validators-BGsNOgT1.js +207 -0
  136. package/dist/validators.js +54 -29
  137. package/llms.txt +7878 -311
  138. package/package.json +83 -9
  139. package/dist/behaviors-DzYL8kY_.js +0 -499
  140. package/dist/core/behavior/create-field-path.d.ts +0 -7
  141. package/dist/core/context/form-context-impl.d.ts +0 -29
  142. package/dist/core/utils/debounce.d.ts +0 -160
  143. package/dist/core/utils/resources.d.ts +0 -41
  144. package/dist/core/validation/field-path.d.ts +0 -7
  145. package/dist/core/validation/validators/date.d.ts +0 -38
  146. package/dist/registry-helpers-BRxAr6nG.js +0 -490
  147. package/dist/validators-gXoHPdqM.js +0 -418
@@ -1,490 +0,0 @@
1
- function k() {
2
- return h("");
3
- }
4
- function h(i) {
5
- return new Proxy({}, {
6
- get(t, e) {
7
- if (typeof e == "symbol")
8
- return;
9
- if (e === "__path" || e === "__fieldPath")
10
- return i || e;
11
- if (e === "__key") {
12
- const a = i.split(".");
13
- return a[a.length - 1] || e;
14
- }
15
- if (e === "then" || e === "catch" || e === "finally" || e === "constructor" || e === "toString" || e === "valueOf" || e === "toJSON")
16
- return;
17
- const r = i ? `${i}.${e}` : e, s = {
18
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
19
- __key: e,
20
- __path: r,
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
- __formType: void 0,
23
- __fieldType: void 0
24
- };
25
- return new Proxy(s, {
26
- get(a, n) {
27
- if (typeof n != "symbol") {
28
- if (n === "__path" || n === "__fieldPath") return r;
29
- if (n === "__key") return e;
30
- if (n !== "__formType" && n !== "__fieldType" && !(n === "then" || n === "catch" || n === "finally" || n === "constructor" || n === "toString" || n === "valueOf" || n === "toJSON"))
31
- return h(`${r}.${n}`);
32
- }
33
- }
34
- });
35
- }
36
- });
37
- }
38
- function y(i) {
39
- if (typeof i == "string")
40
- return i;
41
- if (i && typeof i == "object") {
42
- const t = i.__path;
43
- if (typeof t == "string")
44
- return t;
45
- }
46
- throw new Error("Invalid field path node: " + JSON.stringify(i));
47
- }
48
- function C(i) {
49
- const t = y(i);
50
- return h(t);
51
- }
52
- function S(i) {
53
- if (i && typeof i == "object" && "__key" in i)
54
- return i.__key;
55
- if (typeof i == "string") {
56
- const t = i.split(".");
57
- return t[t.length - 1];
58
- }
59
- throw new Error("Invalid field path node");
60
- }
61
- class d {
62
- stack = [];
63
- /**
64
- * Добавить элемент в стек
65
- * @param item - Элемент для добавления
66
- */
67
- push(t) {
68
- this.stack.push(t);
69
- }
70
- /**
71
- * Извлечь элемент из стека
72
- * @returns Извлеченный элемент или undefined если стек пуст
73
- */
74
- pop() {
75
- return this.stack.pop();
76
- }
77
- /**
78
- * Получить текущий элемент (вершину стека) без извлечения
79
- * @returns Текущий элемент или null если стек пуст
80
- */
81
- getCurrent() {
82
- return this.stack.length > 0 ? this.stack[this.stack.length - 1] : null;
83
- }
84
- /**
85
- * Извлечь элемент из стека с проверкой
86
- * Выводит предупреждение в DEV режиме если извлеченный элемент не совпадает с ожидаемым
87
- *
88
- * @param expected - Ожидаемый элемент
89
- * @param name - Имя реестра для отладки (например, 'ValidationRegistry')
90
- */
91
- verify(t, e) {
92
- this.pop();
93
- }
94
- /**
95
- * Получить длину стека
96
- * @returns Количество элементов в стеке
97
- */
98
- get length() {
99
- return this.stack.length;
100
- }
101
- /**
102
- * Проверить, пуст ли стек
103
- * @returns true если стек пуст
104
- */
105
- isEmpty() {
106
- return this.stack.length === 0;
107
- }
108
- /**
109
- * Очистить стек
110
- */
111
- clear() {
112
- this.stack = [];
113
- }
114
- }
115
- class x {
116
- validators = [];
117
- conditionStack = [];
118
- /**
119
- * Добавить валидатор в контекст
120
- */
121
- addValidator(t) {
122
- if (this.conditionStack.length > 0) {
123
- const e = this.conditionStack[this.conditionStack.length - 1];
124
- t.condition = e;
125
- }
126
- this.validators.push(t);
127
- }
128
- /**
129
- * Войти в условный блок
130
- */
131
- enterCondition(t, e) {
132
- this.conditionStack.push({ fieldPath: t, conditionFn: e });
133
- }
134
- /**
135
- * Выйти из условного блока
136
- */
137
- exitCondition() {
138
- this.conditionStack.pop();
139
- }
140
- /**
141
- * Получить все зарегистрированные валидаторы
142
- */
143
- getValidators() {
144
- return this.validators;
145
- }
146
- }
147
- class o {
148
- /**
149
- * Global stack активных реестров
150
- * Используется для изоляции форм друг от друга
151
- */
152
- static registryStack = new d();
153
- contextStack = [];
154
- validators = [];
155
- /**
156
- * Получить текущий активный реестр из global stack
157
- *
158
- * @returns Текущий активный реестр или null
159
- *
160
- * @example
161
- * ```typescript
162
- * // В schema-validators.ts
163
- * export function required(...) {
164
- * const registry = ValidationRegistry.getCurrent();
165
- * if (registry) {
166
- * registry.registerSync(...);
167
- * }
168
- * }
169
- * ```
170
- */
171
- static getCurrent() {
172
- return o.registryStack.getCurrent();
173
- }
174
- /**
175
- * Начать регистрацию валидаторов для формы
176
- *
177
- * Помещает this в global stack для изоляции форм
178
- */
179
- beginRegistration() {
180
- const t = new x();
181
- return this.contextStack.push(t), o.registryStack.push(this), t;
182
- }
183
- /**
184
- * Завершить регистрацию и применить валидаторы к GroupNode
185
- *
186
- * Извлекает this из global stack
187
- *
188
- * Сохраняет валидаторы в локальном состоянии (this.validators) вместо глобального WeakMap.
189
- */
190
- endRegistration(t) {
191
- const e = this.contextStack.pop();
192
- if (!e)
193
- throw new Error("No active registration context");
194
- o.registryStack.verify(this, "ValidationRegistry"), this.validators = e.getValidators(), this.applyValidators(t, this.validators), this.applyArrayItemValidators(t, this.validators);
195
- }
196
- /**
197
- * Отменить регистрацию без применения валидаторов
198
- * Используется для временной валидации (например, в validateForm)
199
- *
200
- * Извлекает this из global stack
201
- */
202
- cancelRegistration() {
203
- if (!this.contextStack.pop())
204
- throw new Error("No active registration context to cancel");
205
- o.registryStack.verify(this, "ValidationRegistry");
206
- }
207
- /**
208
- * Получить текущий контекст регистрации
209
- */
210
- getCurrentContext() {
211
- return this.contextStack[this.contextStack.length - 1];
212
- }
213
- /**
214
- * Зарегистрировать синхронный валидатор
215
- */
216
- registerSync(t, e, r) {
217
- const s = this.getCurrentContext();
218
- if (!s)
219
- throw new Error("Validators can only be registered inside a validation schema function");
220
- s.addValidator({
221
- fieldPath: t,
222
- type: "sync",
223
- validator: e,
224
- options: r
225
- });
226
- }
227
- /**
228
- * Зарегистрировать асинхронный валидатор
229
- */
230
- registerAsync(t, e, r) {
231
- const s = this.getCurrentContext();
232
- if (!s)
233
- throw new Error("Validators can only be registered inside a validation schema function");
234
- s.addValidator({
235
- fieldPath: t,
236
- type: "async",
237
- validator: e,
238
- options: r
239
- });
240
- }
241
- /**
242
- * Зарегистрировать tree валидатор
243
- */
244
- registerTree(t, e) {
245
- const r = this.getCurrentContext();
246
- if (!r)
247
- throw new Error("Validators can only be registered inside a validation schema function");
248
- r.addValidator({
249
- fieldPath: e?.targetField || "__tree__",
250
- type: "tree",
251
- validator: t,
252
- options: e
253
- });
254
- }
255
- /**
256
- * Войти в условный блок
257
- */
258
- enterCondition(t, e) {
259
- const r = this.getCurrentContext();
260
- if (!r)
261
- throw new Error("Conditions can only be used inside a validation schema function");
262
- r.enterCondition(t, e);
263
- }
264
- /**
265
- * Выйти из условного блока
266
- */
267
- exitCondition() {
268
- const t = this.getCurrentContext();
269
- if (!t)
270
- throw new Error("No active condition");
271
- t.exitCondition();
272
- }
273
- /**
274
- * Зарегистрировать validation schema для элементов массива
275
- *
276
- * Используется функцией validateItems() для регистрации схемы валидации,
277
- * которая будет применяться к каждому элементу ArrayNode.
278
- *
279
- * @param fieldPath - Путь к ArrayNode полю
280
- * @param itemSchemaFn - Validation schema для элемента массива
281
- */
282
- registerArrayItemValidation(t, e) {
283
- const r = this.getCurrentContext();
284
- if (!r)
285
- throw new Error(
286
- "Array item validators can only be registered inside a validation schema function"
287
- );
288
- r.addValidator({
289
- fieldPath: t,
290
- type: "array-items",
291
- validator: e,
292
- options: {}
293
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
294
- });
295
- }
296
- /**
297
- * Получить зарегистрированные валидаторы для этого реестра
298
- *
299
- * Возвращает локальный массив валидаторов (без аргумента form).
300
- */
301
- getValidators() {
302
- return this.validators;
303
- }
304
- /**
305
- * Применить зарегистрированные валидаторы к GroupNode
306
- * @private
307
- */
308
- applyValidators(t, e) {
309
- const r = /* @__PURE__ */ new Map();
310
- for (const s of e) {
311
- if (s.type === "tree" || s.type === "array-items")
312
- continue;
313
- const a = r.get(s.fieldPath) || [];
314
- a.push(s), r.set(s.fieldPath, a);
315
- }
316
- }
317
- /**
318
- * Применить array-items validators к ArrayNode элементам
319
- * @private
320
- */
321
- applyArrayItemValidators(t, e) {
322
- const r = e.filter((s) => s.type === "array-items");
323
- if (r.length !== 0)
324
- for (const s of r) {
325
- const a = t[s.fieldPath.split(".")[0]];
326
- if (a && "applyValidationSchema" in a) {
327
- const n = s.validator;
328
- a.applyValidationSchema(n);
329
- }
330
- }
331
- }
332
- }
333
- class v {
334
- /**
335
- * Форма с типизированным Proxy-доступом к полям
336
- */
337
- form;
338
- _form;
339
- constructor(t) {
340
- this._form = t;
341
- const e = t._proxyInstance || t;
342
- this.form = e;
343
- }
344
- /**
345
- * Безопасно установить значение поля по строковому пути или FieldPath
346
- *
347
- * Автоматически использует emitEvent: false для предотвращения циклов
348
- *
349
- * @param path - Строковый путь к полю или FieldPath объект
350
- * @param value - Новое значение
351
- */
352
- setFieldValue(t, e) {
353
- const r = typeof t == "string" ? t : t.toString(), s = this._form.getFieldByPath(r);
354
- s && s.setValue(e, { emitEvent: !1 });
355
- }
356
- }
357
- class c {
358
- /**
359
- * Stack активных контекстов регистрации
360
- * Используется для изоляции форм друг от друга
361
- */
362
- static contextStack = new d();
363
- registrations = [];
364
- isRegistering = !1;
365
- /**
366
- * Получить текущий активный реестр из context stack
367
- *
368
- * @returns Текущий активный реестр или null
369
- *
370
- * @example
371
- * ```typescript
372
- * // В schema-behaviors.ts
373
- * export function copyFrom(...) {
374
- * const registry = BehaviorRegistry.getCurrent();
375
- * if (registry) {
376
- * registry.register({ ... });
377
- * }
378
- * }
379
- * ```
380
- */
381
- static getCurrent() {
382
- return c.contextStack.getCurrent();
383
- }
384
- /**
385
- * Начать регистрацию behaviors
386
- * Вызывается перед применением схемы
387
- *
388
- * Помещает this в context stack для изоляции форм
389
- */
390
- beginRegistration() {
391
- this.isRegistering = !0, this.registrations = [], c.contextStack.push(this);
392
- }
393
- /**
394
- * Зарегистрировать behavior handler
395
- * Вызывается функциями из schema-behaviors.ts
396
- *
397
- * @param handler - BehaviorHandlerFn функция
398
- * @param options - Опции behavior (debounce)
399
- *
400
- * @example
401
- * ```typescript
402
- * const handler = createCopyBehavior(target, source, { when: ... });
403
- * registry.register(handler, { debounce: 300 });
404
- * ```
405
- */
406
- register(t, e) {
407
- this.isRegistering && this.registrations.push({
408
- // Type assertion безопасен: handler будет вызван с правильным типом формы в createEffect
409
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
410
- handler: t,
411
- debounce: e?.debounce
412
- });
413
- }
414
- /**
415
- * Завершить регистрацию и применить behaviors к форме
416
- * Создает effect подписки для всех зарегистрированных behaviors
417
- *
418
- * Извлекает this из context stack
419
- *
420
- * @param form - GroupNode формы
421
- * @returns Количество зарегистрированных behaviors и функция cleanup
422
- */
423
- endRegistration(t) {
424
- this.isRegistering = !1, c.contextStack.verify(this, "BehaviorRegistry");
425
- const e = new v(t), r = [];
426
- for (const a of this.registrations) {
427
- const n = this.createEffect(a, t, e);
428
- n && r.push(n);
429
- }
430
- const s = () => {
431
- r.forEach((a) => a());
432
- };
433
- return {
434
- count: this.registrations.length,
435
- cleanup: s
436
- };
437
- }
438
- /**
439
- * Создать effect подписку для behavior
440
- * @private
441
- */
442
- createEffect(t, e, r) {
443
- const { handler: s, debounce: a = 0 } = t;
444
- let n = null;
445
- const f = (u) => {
446
- a > 0 ? (n && clearTimeout(n), n = setTimeout(u, a)) : u();
447
- }, g = () => {
448
- n && (clearTimeout(n), n = null);
449
- }, l = s(e, r, f);
450
- return l ? () => {
451
- g(), l && l();
452
- } : null;
453
- }
454
- }
455
- function _() {
456
- const i = o.getCurrent();
457
- return i || {
458
- registerSync: () => {
459
- },
460
- registerAsync: () => {
461
- },
462
- registerTree: () => {
463
- },
464
- enterCondition: () => {
465
- },
466
- exitCondition: () => {
467
- },
468
- registerArrayItemValidation: () => {
469
- }
470
- };
471
- }
472
- function m() {
473
- const i = c.getCurrent();
474
- return i || {
475
- register: () => {
476
- }
477
- };
478
- }
479
- export {
480
- c as B,
481
- d as R,
482
- o as V,
483
- S as a,
484
- m as b,
485
- k as c,
486
- v as d,
487
- y as e,
488
- _ as g,
489
- C as t
490
- };