@reformer/core 1.1.0-beta.8 → 2.0.0-beta.10

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 (151) 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 +27 -20
  18. package/dist/core/behavior/behavior-context.d.ts +27 -13
  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 +42 -22
  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 +37 -212
  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 +27 -27
  39. package/dist/core/types/{group-node-proxy.d.ts → form-proxy.d.ts} +12 -42
  40. package/dist/core/types/index.d.ts +52 -6
  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 +3 -20
  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/{validation → utils}/field-path.d.ts +23 -6
  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 +10 -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 +67 -28
  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 +328 -0
  90. package/dist/hooks/useArrayLength.d.ts +31 -0
  91. package/dist/hooks/useFormControl.d.ts +15 -39
  92. package/dist/hooks/useFormControlValue.d.ts +167 -0
  93. package/dist/hooks/useHiddenCondition.d.ts +25 -0
  94. package/dist/hooks/useSignalSubscription.d.ts +17 -0
  95. package/dist/index-D25LsbRm.js +73 -0
  96. package/dist/index.d.ts +5 -1
  97. package/dist/index.js +1248 -1357
  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 +53 -28
  137. package/llms.txt +8069 -357
  138. package/package.json +87 -8
  139. package/dist/behaviors-BRaiR-UY.js +0 -528
  140. package/dist/core/behavior/behavior-applicator.d.ts +0 -71
  141. package/dist/core/behavior/create-field-path.d.ts +0 -20
  142. package/dist/core/context/form-context-impl.d.ts +0 -29
  143. package/dist/core/nodes/group-node/field-registry.d.ts +0 -191
  144. package/dist/core/nodes/group-node/index.d.ts +0 -11
  145. package/dist/core/nodes/group-node/proxy-builder.d.ts +0 -71
  146. package/dist/core/nodes/group-node/state-manager.d.ts +0 -184
  147. package/dist/core/utils/debounce.d.ts +0 -160
  148. package/dist/core/utils/resources.d.ts +0 -41
  149. package/dist/core/validation/validators/date.d.ts +0 -38
  150. package/dist/registry-helpers-BfCZcMkO.js +0 -426
  151. package/dist/validators-DjXtDVoE.js +0 -455
@@ -1,160 +0,0 @@
1
- /**
2
- * Debouncer - утилита для отложенного выполнения функций
3
- *
4
- * Устраняет дублирование debounce логики между field-node.ts и behavior-registry.ts
5
- *
6
- * @internal
7
- *
8
- * @example
9
- * ```typescript
10
- * const debouncer = new Debouncer(300);
11
- *
12
- * // Отложить выполнение на 300мс
13
- * await debouncer.debounce(async () => {
14
- * await validateField();
15
- * });
16
- *
17
- * // Отменить отложенное выполнение
18
- * debouncer.cancel();
19
- *
20
- * // Выполнить немедленно, отменив отложенное
21
- * await debouncer.flush(async () => {
22
- * await validateField();
23
- * });
24
- * ```
25
- */
26
- /**
27
- * Класс для debouncing (отложенного выполнения) функций
28
- *
29
- * @internal
30
- *
31
- * Откладывает выполнение функции на заданное время. Если функция вызывается
32
- * повторно до истечения времени, предыдущий вызов отменяется.
33
- *
34
- * Полезно для:
35
- * - Отложенной валидации при вводе (debounced validation)
36
- * - Отложенного сохранения данных
37
- * - Отложенной обработки событий behaviors
38
- *
39
- * @example
40
- * ```typescript
41
- * // В FieldNode
42
- * class FieldNode {
43
- * private validationDebouncer: Debouncer;
44
- *
45
- * constructor(config) {
46
- * this.validationDebouncer = new Debouncer(config.debounce || 0);
47
- * }
48
- *
49
- * async validate(): Promise<boolean> {
50
- * return this.validationDebouncer.debounce(async () => {
51
- * // Валидация выполнится через debounce мс
52
- * return await this.runValidation();
53
- * });
54
- * }
55
- * }
56
- * ```
57
- */
58
- export declare class Debouncer {
59
- private readonly delay;
60
- /**
61
- * Таймер для отложенного выполнения
62
- * @private
63
- */
64
- private timer?;
65
- /**
66
- * Создать Debouncer с заданной задержкой
67
- *
68
- * @param delay Задержка в миллисекундах (0 = без задержки)
69
- *
70
- * @example
71
- * ```typescript
72
- * const debouncer = new Debouncer(300); // 300мс задержка
73
- * const immediate = new Debouncer(0); // Без задержки
74
- * ```
75
- */
76
- constructor(delay: number);
77
- /**
78
- * Отложить выполнение функции
79
- *
80
- * Если вызывается повторно до истечения delay, предыдущий вызов отменяется
81
- * и таймер перезапускается.
82
- *
83
- * @param fn Функция для выполнения (может быть async)
84
- * @returns Promise, который разрешается результатом функции
85
- *
86
- * @example
87
- * ```typescript
88
- * const debouncer = new Debouncer(300);
89
- *
90
- * // Первый вызов - запланирован через 300мс
91
- * debouncer.debounce(async () => console.log('First'));
92
- *
93
- * // Второй вызов через 100мс - отменяет первый, запланирован через 300мс
94
- * debouncer.debounce(async () => console.log('Second'));
95
- *
96
- * // Через 300мс выведет только: "Second"
97
- * ```
98
- */
99
- debounce<T>(fn: () => T | Promise<T>): Promise<T>;
100
- /**
101
- * Отменить отложенное выполнение
102
- *
103
- * Если есть запланированный вызов, он будет отменен и не выполнится.
104
- * Promise из debounce() никогда не разрешится.
105
- *
106
- * @example
107
- * ```typescript
108
- * const debouncer = new Debouncer(300);
109
- *
110
- * debouncer.debounce(async () => {
111
- * console.log('This will not execute');
112
- * });
113
- *
114
- * debouncer.cancel(); // Отменяем вызов
115
- * ```
116
- */
117
- cancel(): void;
118
- /**
119
- * Выполнить функцию немедленно, отменив любой отложенный вызов
120
- *
121
- * Полезно когда нужно принудительно выполнить действие сейчас,
122
- * игнорируя debounce.
123
- *
124
- * @param fn Функция для немедленного выполнения
125
- * @returns Promise с результатом функции
126
- *
127
- * @example
128
- * ```typescript
129
- * const debouncer = new Debouncer(300);
130
- *
131
- * // Запланировано через 300мс
132
- * debouncer.debounce(async () => console.log('Delayed'));
133
- *
134
- * // Отменяем отложенный и выполняем немедленно
135
- * await debouncer.flush(async () => console.log('Immediate'));
136
- * // Выведет: "Immediate" (сразу)
137
- * // "Delayed" не выполнится (отменен)
138
- * ```
139
- */
140
- flush<T>(fn: () => T | Promise<T>): Promise<T>;
141
- /**
142
- * Проверить, есть ли активный (запланированный) вызов
143
- *
144
- * @returns true если есть запланированный вызов
145
- *
146
- * @example
147
- * ```typescript
148
- * const debouncer = new Debouncer(300);
149
- *
150
- * console.log(debouncer.isPending()); // false
151
- *
152
- * debouncer.debounce(() => console.log('Test'));
153
- * console.log(debouncer.isPending()); // true
154
- *
155
- * // Через 300мс
156
- * console.log(debouncer.isPending()); // false
157
- * ```
158
- */
159
- isPending(): boolean;
160
- }
@@ -1,41 +0,0 @@
1
- export interface ResourceItem<T> {
2
- id: string | number;
3
- label: string;
4
- description: string;
5
- value: T;
6
- [key: string]: unknown;
7
- }
8
- export interface ResourceResult<T> {
9
- items: ResourceItem<T>[];
10
- totalCount: number;
11
- }
12
- export interface ResourceConfig<T> {
13
- type: 'static' | 'preload' | 'partial';
14
- load: (params?: ResourceLoadParams) => Promise<ResourceResult<T>>;
15
- }
16
- export interface ResourceLoadParams {
17
- search?: string;
18
- page?: number;
19
- pageSize?: number;
20
- [key: string]: unknown;
21
- }
22
- /**
23
- * Статический ресурс - данные загружаются один раз
24
- * @param items - массив элементов
25
- */
26
- export declare function staticResource<T>(items: ResourceItem<T>[]): ResourceConfig<T>;
27
- /**
28
- * Предзагрузка - данные загружаются один раз при первом обращении через функцию
29
- * @param loader - функция загрузки, принимает параметры и возвращает массив
30
- */
31
- export declare function preloadResource<T>(loader: (params?: ResourceLoadParams) => Promise<ResourceItem<T>[]>): ResourceConfig<T>;
32
- /**
33
- * Парциональная загрузка - данные загружаются порциями с учетом поиска/пагинации
34
- * @param loader - функция загрузки, принимает параметры и возвращает массив
35
- */
36
- export declare function partialResource<T>(loader: (params?: ResourceLoadParams) => Promise<ResourceItem<T>[]>): ResourceConfig<T>;
37
- export declare const Resources: {
38
- static: typeof staticResource;
39
- preload: typeof preloadResource;
40
- partial: typeof partialResource;
41
- };
@@ -1,38 +0,0 @@
1
- /**
2
- * Валидатор даты
3
- *
4
- * @group Validation
5
- * @category Validators
6
- * @module validators/date
7
- */
8
- import type { ValidateOptions } from '../../types/validation-schema';
9
- import type { FieldPathNode } from '../../types';
10
- /**
11
- * Адаптер для date валидатора
12
- * Проверяет, что значение является валидной датой и соответствует ограничениям
13
- *
14
- * @group Validation
15
- * @category Validators
16
- *
17
- * @example
18
- * ```typescript
19
- * date(path.birthDate);
20
- * date(path.birthDate, { maxDate: new Date() }); // Не позже сегодня
21
- * date(path.eventDate, { minDate: new Date(), message: 'Дата не может быть в прошлом' });
22
- * date(path.age, { minAge: 18, maxAge: 100 });
23
- * ```
24
- */
25
- export declare function date<TForm, TField extends string | Date | undefined = string | Date>(fieldPath: FieldPathNode<TForm, TField> | undefined, options?: ValidateOptions & {
26
- /** Минимальная дата (включительно) */
27
- minDate?: Date;
28
- /** Максимальная дата (включительно) */
29
- maxDate?: Date;
30
- /** Минимальный возраст (для дат рождения) */
31
- minAge?: number;
32
- /** Максимальный возраст (для дат рождения) */
33
- maxAge?: number;
34
- /** Не разрешать будущие даты */
35
- noFuture?: boolean;
36
- /** Не разрешать прошлые даты */
37
- noPast?: boolean;
38
- }): void;
@@ -1,426 +0,0 @@
1
- class h {
2
- stack = [];
3
- /**
4
- * Добавить элемент в стек
5
- * @param item - Элемент для добавления
6
- */
7
- push(t) {
8
- this.stack.push(t);
9
- }
10
- /**
11
- * Извлечь элемент из стека
12
- * @returns Извлеченный элемент или undefined если стек пуст
13
- */
14
- pop() {
15
- return this.stack.pop();
16
- }
17
- /**
18
- * Получить текущий элемент (вершину стека) без извлечения
19
- * @returns Текущий элемент или null если стек пуст
20
- */
21
- getCurrent() {
22
- return this.stack.length > 0 ? this.stack[this.stack.length - 1] : null;
23
- }
24
- /**
25
- * Извлечь элемент из стека с проверкой
26
- * Выводит предупреждение в DEV режиме если извлеченный элемент не совпадает с ожидаемым
27
- *
28
- * @param expected - Ожидаемый элемент
29
- * @param name - Имя реестра для отладки (например, 'ValidationRegistry')
30
- */
31
- verify(t, e) {
32
- this.pop();
33
- }
34
- /**
35
- * Получить длину стека
36
- * @returns Количество элементов в стеке
37
- */
38
- get length() {
39
- return this.stack.length;
40
- }
41
- /**
42
- * Проверить, пуст ли стек
43
- * @returns true если стек пуст
44
- */
45
- isEmpty() {
46
- return this.stack.length === 0;
47
- }
48
- /**
49
- * Очистить стек
50
- */
51
- clear() {
52
- this.stack = [];
53
- }
54
- }
55
- class f {
56
- validators = [];
57
- conditionStack = [];
58
- /**
59
- * Добавить валидатор в контекст
60
- */
61
- addValidator(t) {
62
- if (this.conditionStack.length > 0) {
63
- const e = this.conditionStack[this.conditionStack.length - 1];
64
- t.condition = e;
65
- }
66
- this.validators.push(t);
67
- }
68
- /**
69
- * Войти в условный блок
70
- */
71
- enterCondition(t, e) {
72
- this.conditionStack.push({ fieldPath: t, conditionFn: e });
73
- }
74
- /**
75
- * Выйти из условного блока
76
- */
77
- exitCondition() {
78
- this.conditionStack.pop();
79
- }
80
- /**
81
- * Получить все зарегистрированные валидаторы
82
- */
83
- getValidators() {
84
- return this.validators;
85
- }
86
- }
87
- class a {
88
- /**
89
- * Global stack активных реестров
90
- * Используется для изоляции форм друг от друга
91
- */
92
- static registryStack = new h();
93
- contextStack = [];
94
- validators = [];
95
- /**
96
- * Получить текущий активный реестр из global stack
97
- *
98
- * @returns Текущий активный реестр или null
99
- *
100
- * @example
101
- * ```typescript
102
- * // В schema-validators.ts
103
- * export function required(...) {
104
- * const registry = ValidationRegistry.getCurrent();
105
- * if (registry) {
106
- * registry.registerSync(...);
107
- * }
108
- * }
109
- * ```
110
- */
111
- static getCurrent() {
112
- return a.registryStack.getCurrent();
113
- }
114
- /**
115
- * Начать регистрацию валидаторов для формы
116
- *
117
- * Помещает this в global stack для изоляции форм
118
- */
119
- beginRegistration() {
120
- const t = new f();
121
- return this.contextStack.push(t), a.registryStack.push(this), t;
122
- }
123
- /**
124
- * Завершить регистрацию и применить валидаторы к GroupNode
125
- *
126
- * Извлекает this из global stack
127
- *
128
- * Сохраняет валидаторы в локальном состоянии (this.validators) вместо глобального WeakMap.
129
- */
130
- endRegistration(t) {
131
- const e = this.contextStack.pop();
132
- if (!e)
133
- throw new Error("No active registration context");
134
- a.registryStack.verify(this, "ValidationRegistry"), this.validators = e.getValidators(), this.applyValidators(t, this.validators), this.applyArrayItemValidators(t, this.validators);
135
- }
136
- /**
137
- * Отменить регистрацию без применения валидаторов
138
- * Используется для временной валидации (например, в validateForm)
139
- *
140
- * Извлекает this из global stack
141
- */
142
- cancelRegistration() {
143
- if (!this.contextStack.pop())
144
- throw new Error("No active registration context to cancel");
145
- a.registryStack.verify(this, "ValidationRegistry");
146
- }
147
- /**
148
- * Получить текущий контекст регистрации
149
- */
150
- getCurrentContext() {
151
- return this.contextStack[this.contextStack.length - 1];
152
- }
153
- /**
154
- * Зарегистрировать синхронный валидатор
155
- */
156
- registerSync(t, e, i) {
157
- const r = this.getCurrentContext();
158
- if (!r)
159
- throw new Error("Validators can only be registered inside a validation schema function");
160
- r.addValidator({
161
- fieldPath: t,
162
- type: "sync",
163
- validator: e,
164
- options: i
165
- });
166
- }
167
- /**
168
- * Зарегистрировать асинхронный валидатор
169
- */
170
- registerAsync(t, e, i) {
171
- const r = this.getCurrentContext();
172
- if (!r)
173
- throw new Error("Validators can only be registered inside a validation schema function");
174
- r.addValidator({
175
- fieldPath: t,
176
- type: "async",
177
- validator: e,
178
- options: i
179
- });
180
- }
181
- /**
182
- * Зарегистрировать tree валидатор
183
- */
184
- registerTree(t, e) {
185
- const i = this.getCurrentContext();
186
- if (!i)
187
- throw new Error("Validators can only be registered inside a validation schema function");
188
- i.addValidator({
189
- fieldPath: e?.targetField || "__tree__",
190
- type: "tree",
191
- validator: t,
192
- options: e
193
- });
194
- }
195
- /**
196
- * Войти в условный блок
197
- */
198
- enterCondition(t, e) {
199
- const i = this.getCurrentContext();
200
- if (!i)
201
- throw new Error("Conditions can only be used inside a validation schema function");
202
- i.enterCondition(t, e);
203
- }
204
- /**
205
- * Выйти из условного блока
206
- */
207
- exitCondition() {
208
- const t = this.getCurrentContext();
209
- if (!t)
210
- throw new Error("No active condition");
211
- t.exitCondition();
212
- }
213
- /**
214
- * Зарегистрировать validation schema для элементов массива
215
- *
216
- * Используется функцией validateItems() для регистрации схемы валидации,
217
- * которая будет применяться к каждому элементу ArrayNode.
218
- *
219
- * @param fieldPath - Путь к ArrayNode полю
220
- * @param itemSchemaFn - Validation schema для элемента массива
221
- */
222
- registerArrayItemValidation(t, e) {
223
- const i = this.getCurrentContext();
224
- if (!i)
225
- throw new Error(
226
- "Array item validators can only be registered inside a validation schema function"
227
- );
228
- i.addValidator({
229
- fieldPath: t,
230
- type: "array-items",
231
- validator: e,
232
- options: {}
233
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
234
- });
235
- }
236
- /**
237
- * Получить зарегистрированные валидаторы для этого реестра
238
- *
239
- * Возвращает локальный массив валидаторов (без аргумента form).
240
- */
241
- getValidators() {
242
- return this.validators;
243
- }
244
- /**
245
- * Применить зарегистрированные валидаторы к GroupNode
246
- * @private
247
- */
248
- applyValidators(t, e) {
249
- const i = /* @__PURE__ */ new Map();
250
- for (const r of e) {
251
- if (r.type === "tree" || r.type === "array-items")
252
- continue;
253
- const n = i.get(r.fieldPath) || [];
254
- n.push(r), i.set(r.fieldPath, n);
255
- }
256
- }
257
- /**
258
- * Применить array-items validators к ArrayNode элементам
259
- * @private
260
- */
261
- applyArrayItemValidators(t, e) {
262
- const i = e.filter((r) => r.type === "array-items");
263
- if (i.length !== 0)
264
- for (const r of i) {
265
- const n = t[r.fieldPath.split(".")[0]];
266
- if (n && "applyValidationSchema" in n) {
267
- const s = r.validator;
268
- n.applyValidationSchema(s);
269
- }
270
- }
271
- }
272
- }
273
- class p {
274
- /**
275
- * Форма с типизированным Proxy-доступом к полям
276
- */
277
- form;
278
- _form;
279
- constructor(t) {
280
- this._form = t;
281
- const e = t._proxyInstance || t;
282
- this.form = e;
283
- }
284
- /**
285
- * Безопасно установить значение поля по строковому пути или FieldPath
286
- *
287
- * Автоматически использует emitEvent: false для предотвращения циклов
288
- *
289
- * @param path - Строковый путь к полю или FieldPath объект
290
- * @param value - Новое значение
291
- */
292
- setFieldValue(t, e) {
293
- const i = typeof t == "string" ? t : t.toString(), r = this._form.getFieldByPath(i);
294
- r && r.setValue(e, { emitEvent: !1 });
295
- }
296
- }
297
- class c {
298
- /**
299
- * Stack активных контекстов регистрации
300
- * Используется для изоляции форм друг от друга
301
- */
302
- static contextStack = new h();
303
- registrations = [];
304
- isRegistering = !1;
305
- /**
306
- * Получить текущий активный реестр из context stack
307
- *
308
- * @returns Текущий активный реестр или null
309
- *
310
- * @example
311
- * ```typescript
312
- * // В schema-behaviors.ts
313
- * export function copyFrom(...) {
314
- * const registry = BehaviorRegistry.getCurrent();
315
- * if (registry) {
316
- * registry.register({ ... });
317
- * }
318
- * }
319
- * ```
320
- */
321
- static getCurrent() {
322
- return c.contextStack.getCurrent();
323
- }
324
- /**
325
- * Начать регистрацию behaviors
326
- * Вызывается перед применением схемы
327
- *
328
- * Помещает this в context stack для изоляции форм
329
- */
330
- beginRegistration() {
331
- this.isRegistering = !0, this.registrations = [], c.contextStack.push(this);
332
- }
333
- /**
334
- * Зарегистрировать behavior handler
335
- * Вызывается функциями из schema-behaviors.ts
336
- *
337
- * @param handler - BehaviorHandlerFn функция
338
- * @param options - Опции behavior (debounce)
339
- *
340
- * @example
341
- * ```typescript
342
- * const handler = createCopyBehavior(target, source, { when: ... });
343
- * registry.register(handler, { debounce: 300 });
344
- * ```
345
- */
346
- register(t, e) {
347
- this.isRegistering && this.registrations.push({
348
- // Type assertion безопасен: handler будет вызван с правильным типом формы в createEffect
349
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
350
- handler: t,
351
- debounce: e?.debounce
352
- });
353
- }
354
- /**
355
- * Завершить регистрацию и применить behaviors к форме
356
- * Создает effect подписки для всех зарегистрированных behaviors
357
- *
358
- * Извлекает this из context stack
359
- *
360
- * @param form - GroupNode формы
361
- * @returns Количество зарегистрированных behaviors и функция cleanup
362
- */
363
- endRegistration(t) {
364
- this.isRegistering = !1, c.contextStack.verify(this, "BehaviorRegistry");
365
- const e = new p(t), i = [];
366
- for (const n of this.registrations) {
367
- const s = this.createEffect(n, t, e);
368
- s && i.push(s);
369
- }
370
- const r = () => {
371
- i.forEach((n) => n());
372
- };
373
- return {
374
- count: this.registrations.length,
375
- cleanup: r
376
- };
377
- }
378
- /**
379
- * Создать effect подписку для behavior
380
- * @private
381
- */
382
- createEffect(t, e, i) {
383
- const { handler: r, debounce: n = 0 } = t;
384
- let s = null;
385
- const g = (l) => {
386
- n > 0 ? (s && clearTimeout(s), s = setTimeout(l, n)) : l();
387
- }, u = () => {
388
- s && (clearTimeout(s), s = null);
389
- }, d = r(e, i, g);
390
- return d ? () => {
391
- u(), d && d();
392
- } : null;
393
- }
394
- }
395
- function y() {
396
- const o = a.getCurrent();
397
- return o || {
398
- registerSync: () => {
399
- },
400
- registerAsync: () => {
401
- },
402
- registerTree: () => {
403
- },
404
- enterCondition: () => {
405
- },
406
- exitCondition: () => {
407
- },
408
- registerArrayItemValidation: () => {
409
- }
410
- };
411
- }
412
- function x() {
413
- const o = c.getCurrent();
414
- return o || {
415
- register: () => {
416
- }
417
- };
418
- }
419
- export {
420
- c as B,
421
- h as R,
422
- a as V,
423
- x as a,
424
- p as b,
425
- y as g
426
- };