@reformer/core 2.0.0-beta.7 → 2.0.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.
- package/dist/behaviors/compute-from.d.ts +2 -0
- package/dist/behaviors/compute-from.js +31 -0
- package/dist/behaviors/copy-from.d.ts +2 -0
- package/dist/behaviors/copy-from.js +29 -0
- package/dist/behaviors/enable-when.d.ts +2 -0
- package/dist/behaviors/enable-when.js +25 -0
- package/dist/behaviors/reset-when.d.ts +2 -0
- package/dist/behaviors/reset-when.js +24 -0
- package/dist/behaviors/revalidate-when.d.ts +2 -0
- package/dist/behaviors/revalidate-when.js +18 -0
- package/dist/behaviors/sync-fields.d.ts +2 -0
- package/dist/behaviors/sync-fields.js +41 -0
- package/dist/behaviors/transform-value.d.ts +2 -0
- package/dist/behaviors/transform-value.js +45 -0
- package/dist/behaviors/watch-field.d.ts +2 -0
- package/dist/behaviors/watch-field.js +21 -0
- package/dist/behaviors.js +26 -19
- package/dist/core/behavior/behavior-context.d.ts +26 -12
- package/dist/core/behavior/behavior-registry.d.ts +15 -27
- package/dist/core/behavior/behaviors/compute-from.d.ts +50 -21
- package/dist/core/behavior/behaviors/copy-from.d.ts +39 -14
- package/dist/core/behavior/behaviors/enable-when.d.ts +88 -19
- package/dist/core/behavior/behaviors/reset-when.d.ts +31 -18
- package/dist/core/behavior/behaviors/revalidate-when.d.ts +40 -17
- package/dist/core/behavior/behaviors/sync-fields.d.ts +34 -14
- package/dist/core/behavior/behaviors/transform-value.d.ts +116 -44
- package/dist/core/behavior/behaviors/watch-field.d.ts +66 -21
- package/dist/core/behavior/compose-behavior.d.ts +2 -12
- package/dist/core/behavior/index.d.ts +0 -1
- package/dist/core/behavior/types.d.ts +2 -8
- package/dist/core/factories/node-factory.d.ts +6 -29
- package/dist/core/nodes/array-node.d.ts +11 -15
- package/dist/core/nodes/field-node.d.ts +43 -24
- package/dist/core/nodes/form-node.d.ts +18 -20
- package/dist/core/nodes/group-node.d.ts +25 -21
- package/dist/core/types/deep-schema.d.ts +2 -12
- package/dist/core/types/field-path.d.ts +1 -1
- package/dist/core/types/form-context.d.ts +26 -26
- package/dist/core/types/form-proxy.d.ts +1 -31
- package/dist/core/types/index.d.ts +16 -4
- package/dist/core/types/validation-schema.d.ts +3 -12
- package/dist/core/utils/abstract-registry.d.ts +74 -0
- package/dist/core/utils/aggregate-signals.d.ts +71 -0
- package/dist/core/utils/create-form.d.ts +1 -20
- package/dist/core/utils/error-handler.d.ts +1 -18
- package/dist/core/utils/field-path-navigator.d.ts +1 -1
- package/dist/core/utils/field-path.d.ts +23 -11
- package/dist/core/utils/form-observer.d.ts +176 -0
- package/dist/core/utils/form-proxy-builder.d.ts +25 -0
- package/dist/core/utils/form-submitter.d.ts +121 -0
- package/dist/core/utils/index.d.ts +8 -2
- package/dist/core/utils/registry-helpers.d.ts +0 -7
- package/dist/core/utils/safe-effect.d.ts +73 -0
- package/dist/core/utils/status-machine.d.ts +153 -0
- package/dist/core/utils/type-guards.d.ts +5 -23
- package/dist/core/utils/unique-id.d.ts +34 -7
- package/dist/core/validation/core/apply-when.d.ts +3 -9
- package/dist/core/validation/core/apply.d.ts +2 -13
- package/dist/core/validation/core/validate-async.d.ts +2 -8
- package/dist/core/validation/core/validate-tree.d.ts +0 -6
- package/dist/core/validation/core/validate.d.ts +1 -7
- package/dist/core/validation/index.d.ts +8 -2
- package/dist/core/validation/validate-form.d.ts +1 -38
- package/dist/core/validation/validation-applicator.d.ts +2 -21
- package/dist/core/validation/validation-context.d.ts +38 -14
- package/dist/core/validation/validation-registry.d.ts +11 -20
- package/dist/core/validation/validators/array-validators.d.ts +2 -12
- package/dist/core/validation/validators/date-utils.d.ts +26 -0
- package/dist/core/validation/validators/email.d.ts +2 -9
- package/dist/core/validation/validators/future-date.d.ts +35 -0
- package/dist/core/validation/validators/index.d.ts +7 -1
- package/dist/core/validation/validators/is-date.d.ts +36 -0
- package/dist/core/validation/validators/max-age.d.ts +36 -0
- package/dist/core/validation/validators/max-date.d.ts +36 -0
- package/dist/core/validation/validators/max-length.d.ts +3 -10
- package/dist/core/validation/validators/max.d.ts +3 -10
- package/dist/core/validation/validators/min-age.d.ts +36 -0
- package/dist/core/validation/validators/min-date.d.ts +36 -0
- package/dist/core/validation/validators/min-length.d.ts +3 -10
- package/dist/core/validation/validators/min.d.ts +3 -10
- package/dist/core/validation/validators/number.d.ts +2 -9
- package/dist/core/validation/validators/past-date.d.ts +35 -0
- package/dist/core/validation/validators/pattern.d.ts +2 -9
- package/dist/core/validation/validators/phone.d.ts +2 -9
- package/dist/core/validation/validators/required.d.ts +2 -9
- package/dist/core/validation/validators/url.d.ts +2 -9
- package/dist/date-utils-xUWFslTj.js +29 -0
- package/dist/field-path-DuKdGcIE.js +66 -0
- package/dist/hooks/types.d.ts +1 -1
- package/dist/hooks/useArrayLength.d.ts +31 -0
- package/dist/hooks/useFormControl.d.ts +4 -4
- package/dist/hooks/useFormControlValue.d.ts +2 -2
- package/dist/hooks/useHiddenCondition.d.ts +25 -0
- package/dist/hooks/useSignalSubscription.d.ts +1 -1
- package/dist/index-D25LsbRm.js +73 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1031 -714
- package/dist/registry-helpers-Bv_BJ1s-.js +615 -0
- package/dist/safe-effect-Dh8uw81c.js +20 -0
- package/dist/validate-C3XiA_zf.js +10 -0
- package/dist/validators/email.d.ts +2 -0
- package/dist/validators/email.js +13 -0
- package/dist/validators/future-date.d.ts +2 -0
- package/dist/validators/future-date.js +20 -0
- package/dist/validators/is-date.d.ts +2 -0
- package/dist/validators/is-date.js +12 -0
- package/dist/validators/max-age.d.ts +2 -0
- package/dist/validators/max-age.js +20 -0
- package/dist/validators/max-date.d.ts +2 -0
- package/dist/validators/max-date.js +20 -0
- package/dist/validators/max-length.d.ts +2 -0
- package/dist/validators/max-length.js +11 -0
- package/dist/validators/max.d.ts +2 -0
- package/dist/validators/max.js +11 -0
- package/dist/validators/min-age.d.ts +2 -0
- package/dist/validators/min-age.js +20 -0
- package/dist/validators/min-date.d.ts +2 -0
- package/dist/validators/min-date.js +20 -0
- package/dist/validators/min-length.d.ts +2 -0
- package/dist/validators/min-length.js +11 -0
- package/dist/validators/min.d.ts +2 -0
- package/dist/validators/min.js +11 -0
- package/dist/validators/number.d.ts +2 -0
- package/dist/validators/number.js +35 -0
- package/dist/validators/past-date.d.ts +2 -0
- package/dist/validators/past-date.js +20 -0
- package/dist/validators/pattern.d.ts +2 -0
- package/dist/validators/pattern.js +11 -0
- package/dist/validators/phone.d.ts +2 -0
- package/dist/validators/phone.js +35 -0
- package/dist/validators/required.d.ts +2 -0
- package/dist/validators/required.js +15 -0
- package/dist/validators/url.d.ts +2 -0
- package/dist/validators/url.js +19 -0
- package/dist/validators-BGsNOgT1.js +207 -0
- package/dist/validators.js +54 -29
- package/llms.txt +7878 -311
- package/package.json +83 -9
- package/dist/behaviors-DyPzh2-X.js +0 -508
- package/dist/core/behavior/create-field-path.d.ts +0 -7
- package/dist/core/context/form-context-impl.d.ts +0 -29
- package/dist/core/utils/debounce.d.ts +0 -160
- package/dist/core/utils/resources.d.ts +0 -41
- package/dist/core/validation/field-path.d.ts +0 -7
- package/dist/core/validation/validators/date.d.ts +0 -38
- package/dist/registry-helpers--8-OogF8.js +0 -477
- package/dist/validators-CWdzevnC.js +0 -397
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
var f = /* @__PURE__ */ ((s) => (s.THROW = "throw", s.LOG = "log", s.CONVERT = "convert", s))(f || {});
|
|
2
|
+
class y {
|
|
3
|
+
/**
|
|
4
|
+
* Обработать ошибку согласно заданной стратегии
|
|
5
|
+
*
|
|
6
|
+
* @param error Ошибка для обработки (Error | string | unknown)
|
|
7
|
+
* @param context Контекст ошибки для логирования (например, 'AsyncValidator', 'BehaviorRegistry')
|
|
8
|
+
* @param strategy Стратегия обработки (THROW | LOG | CONVERT)
|
|
9
|
+
* @returns ValidationError если strategy = CONVERT, undefined если strategy = LOG, никогда не возвращается если strategy = THROW
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* // THROW - пробросить ошибку
|
|
14
|
+
* try {
|
|
15
|
+
* riskyOperation();
|
|
16
|
+
* } catch (error) {
|
|
17
|
+
* FormErrorHandler.handle(error, 'RiskyOperation', ErrorStrategy.THROW);
|
|
18
|
+
* // Этот код никогда не выполнится
|
|
19
|
+
* }
|
|
20
|
+
*
|
|
21
|
+
* // LOG - залогировать и продолжить
|
|
22
|
+
* try {
|
|
23
|
+
* nonCriticalOperation();
|
|
24
|
+
* } catch (error) {
|
|
25
|
+
* FormErrorHandler.handle(error, 'NonCritical', ErrorStrategy.LOG);
|
|
26
|
+
* // Продолжаем выполнение
|
|
27
|
+
* }
|
|
28
|
+
*
|
|
29
|
+
* // CONVERT - конвертировать в ValidationError
|
|
30
|
+
* try {
|
|
31
|
+
* await validator(value);
|
|
32
|
+
* } catch (error) {
|
|
33
|
+
* const validationError = FormErrorHandler.handle(
|
|
34
|
+
* error,
|
|
35
|
+
* 'AsyncValidator',
|
|
36
|
+
* ErrorStrategy.CONVERT
|
|
37
|
+
* );
|
|
38
|
+
* return validationError;
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
static handle(t, e, i = "throw") {
|
|
43
|
+
const n = this.extractMessage(t);
|
|
44
|
+
switch (i) {
|
|
45
|
+
case "throw":
|
|
46
|
+
throw t;
|
|
47
|
+
case "log":
|
|
48
|
+
return;
|
|
49
|
+
case "convert":
|
|
50
|
+
return {
|
|
51
|
+
code: "validator_error",
|
|
52
|
+
message: n,
|
|
53
|
+
params: { field: e }
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Извлечь сообщение из ошибки
|
|
59
|
+
*
|
|
60
|
+
* Обрабатывает различные типы ошибок:
|
|
61
|
+
* - Error объекты → error.message
|
|
62
|
+
* - Строки → возвращает как есть
|
|
63
|
+
* - Объекты с message → извлекает message
|
|
64
|
+
* - Другое → String(error)
|
|
65
|
+
*
|
|
66
|
+
* @param error Ошибка для извлечения сообщения
|
|
67
|
+
* @returns Сообщение ошибки
|
|
68
|
+
* @private
|
|
69
|
+
*
|
|
70
|
+
* @example
|
|
71
|
+
* ```typescript
|
|
72
|
+
* FormErrorHandler.extractMessage(new Error('Test'));
|
|
73
|
+
* // 'Test'
|
|
74
|
+
*
|
|
75
|
+
* FormErrorHandler.extractMessage('String error');
|
|
76
|
+
* // 'String error'
|
|
77
|
+
*
|
|
78
|
+
* FormErrorHandler.extractMessage({ message: 'Object error' });
|
|
79
|
+
* // 'Object error'
|
|
80
|
+
*
|
|
81
|
+
* FormErrorHandler.extractMessage(null);
|
|
82
|
+
* // 'null'
|
|
83
|
+
* ```
|
|
84
|
+
*/
|
|
85
|
+
static extractMessage(t) {
|
|
86
|
+
return t instanceof Error ? t.message : typeof t == "string" ? t : typeof t == "object" && t !== null && "message" in t ? String(t.message) : String(t);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Создать ValidationError с заданными параметрами
|
|
90
|
+
*
|
|
91
|
+
* Утилитная функция для создания ValidationError объектов
|
|
92
|
+
*
|
|
93
|
+
* @param code Код ошибки
|
|
94
|
+
* @param message Сообщение ошибки
|
|
95
|
+
* @param field Поле (опционально)
|
|
96
|
+
* @returns ValidationError объект
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* const error = FormErrorHandler.createValidationError(
|
|
101
|
+
* 'required',
|
|
102
|
+
* 'This field is required',
|
|
103
|
+
* 'email'
|
|
104
|
+
* );
|
|
105
|
+
* // { code: 'required', message: 'This field is required', field: 'email' }
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
static createValidationError(t, e, i) {
|
|
109
|
+
return {
|
|
110
|
+
code: t,
|
|
111
|
+
message: e,
|
|
112
|
+
params: i ? { field: i } : void 0
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Проверить, является ли объект ValidationError
|
|
117
|
+
*
|
|
118
|
+
* Type guard для ValidationError
|
|
119
|
+
*
|
|
120
|
+
* @param value Значение для проверки
|
|
121
|
+
* @returns true если value является ValidationError
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```typescript
|
|
125
|
+
* if (FormErrorHandler.isValidationError(result)) {
|
|
126
|
+
* console.log(result.code); // OK, типобезопасно
|
|
127
|
+
* }
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
static isValidationError(t) {
|
|
131
|
+
return typeof t == "object" && t !== null && "code" in t && "message" in t && typeof t.code == "string" && typeof t.message == "string";
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
class m {
|
|
135
|
+
stack = [];
|
|
136
|
+
/**
|
|
137
|
+
* Добавить элемент в стек
|
|
138
|
+
* @param item - Элемент для добавления
|
|
139
|
+
*/
|
|
140
|
+
push(t) {
|
|
141
|
+
this.stack.push(t);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Извлечь элемент из стека
|
|
145
|
+
* @returns Извлеченный элемент или undefined если стек пуст
|
|
146
|
+
*/
|
|
147
|
+
pop() {
|
|
148
|
+
return this.stack.pop();
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Получить текущий элемент (вершину стека) без извлечения
|
|
152
|
+
* @returns Текущий элемент или null если стек пуст
|
|
153
|
+
*/
|
|
154
|
+
getCurrent() {
|
|
155
|
+
return this.stack.length > 0 ? this.stack[this.stack.length - 1] : null;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Извлечь элемент из стека с проверкой
|
|
159
|
+
* Выводит предупреждение в DEV режиме если извлеченный элемент не совпадает с ожидаемым
|
|
160
|
+
*
|
|
161
|
+
* @param expected - Ожидаемый элемент
|
|
162
|
+
* @param name - Имя реестра для отладки (например, 'ValidationRegistry')
|
|
163
|
+
*/
|
|
164
|
+
verify(t, e) {
|
|
165
|
+
this.pop();
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Получить длину стека
|
|
169
|
+
* @returns Количество элементов в стеке
|
|
170
|
+
*/
|
|
171
|
+
get length() {
|
|
172
|
+
return this.stack.length;
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* Проверить, пуст ли стек
|
|
176
|
+
* @returns true если стек пуст
|
|
177
|
+
*/
|
|
178
|
+
isEmpty() {
|
|
179
|
+
return this.stack.length === 0;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Очистить стек
|
|
183
|
+
*/
|
|
184
|
+
clear() {
|
|
185
|
+
this.stack = [];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
const l = /* @__PURE__ */ new Map();
|
|
189
|
+
class o {
|
|
190
|
+
/** Флаг активной регистрации */
|
|
191
|
+
isRegistering = !1;
|
|
192
|
+
/** Массив зарегистрированных элементов */
|
|
193
|
+
registrations = [];
|
|
194
|
+
/**
|
|
195
|
+
* Получить стек для конкретного класса реестра
|
|
196
|
+
* Создает новый стек если не существует
|
|
197
|
+
*
|
|
198
|
+
* @param ctor - Конструктор класса реестра
|
|
199
|
+
* @returns RegistryStack для данного класса
|
|
200
|
+
*/
|
|
201
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
202
|
+
static getStack(t) {
|
|
203
|
+
return l.has(t) || l.set(t, new m()), l.get(t);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Получить текущий активный реестр из стека
|
|
207
|
+
* Должен быть переопределен в наследниках как static метод
|
|
208
|
+
*
|
|
209
|
+
* @param ctor - Конструктор класса реестра
|
|
210
|
+
* @returns Текущий активный реестр или null
|
|
211
|
+
*/
|
|
212
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
213
|
+
static getCurrentFromStack(t) {
|
|
214
|
+
return this.getStack(t).getCurrent();
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Начать регистрацию
|
|
218
|
+
*
|
|
219
|
+
* Помещает this в global stack для изоляции форм
|
|
220
|
+
* Вызывает hook onBeginRegistration()
|
|
221
|
+
*/
|
|
222
|
+
beginRegistration() {
|
|
223
|
+
this.isRegistering = !0, this.registrations = [], o.getStack(this.constructor).push(this), this.onBeginRegistration();
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Проверить, активна ли регистрация
|
|
227
|
+
*/
|
|
228
|
+
isActive() {
|
|
229
|
+
return this.isRegistering;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Получить зарегистрированные элементы
|
|
233
|
+
*/
|
|
234
|
+
getRegistrations() {
|
|
235
|
+
return this.registrations;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Hook: вызывается в начале регистрации
|
|
239
|
+
* Может быть переопределен в наследниках для инициализации
|
|
240
|
+
*/
|
|
241
|
+
onBeginRegistration() {
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Завершить регистрацию и извлечь из стека
|
|
245
|
+
*
|
|
246
|
+
* @param registryName - Имя реестра для отладки
|
|
247
|
+
*/
|
|
248
|
+
completeRegistration(t) {
|
|
249
|
+
this.isRegistering = !1, o.getStack(this.constructor).verify(this, t);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Отменить регистрацию без применения
|
|
253
|
+
*
|
|
254
|
+
* @param registryName - Имя реестра для отладки
|
|
255
|
+
*/
|
|
256
|
+
cancelRegistration(t) {
|
|
257
|
+
this.isRegistering = !1, this.registrations = [], o.getStack(this.constructor).verify(this, t);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
class x {
|
|
261
|
+
validators = [];
|
|
262
|
+
conditionStack = [];
|
|
263
|
+
/**
|
|
264
|
+
* Добавить валидатор в контекст
|
|
265
|
+
*/
|
|
266
|
+
addValidator(t) {
|
|
267
|
+
if (this.conditionStack.length > 0) {
|
|
268
|
+
const e = this.conditionStack[this.conditionStack.length - 1];
|
|
269
|
+
t.condition = e;
|
|
270
|
+
}
|
|
271
|
+
this.validators.push(t);
|
|
272
|
+
}
|
|
273
|
+
/**
|
|
274
|
+
* Войти в условный блок
|
|
275
|
+
*/
|
|
276
|
+
enterCondition(t, e) {
|
|
277
|
+
this.conditionStack.push({ fieldPath: t, conditionFn: e });
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Выйти из условного блока
|
|
281
|
+
*/
|
|
282
|
+
exitCondition() {
|
|
283
|
+
this.conditionStack.pop();
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Получить все зарегистрированные валидаторы
|
|
287
|
+
*/
|
|
288
|
+
getValidators() {
|
|
289
|
+
return this.validators;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
class d extends o {
|
|
293
|
+
/** Внутренний стек контекстов для управления condition blocks */
|
|
294
|
+
contextStack = [];
|
|
295
|
+
/** Финальные валидаторы после завершения регистрации */
|
|
296
|
+
validators = [];
|
|
297
|
+
/**
|
|
298
|
+
* Получить текущий активный реестр из global stack
|
|
299
|
+
*
|
|
300
|
+
* @returns Текущий активный реестр или null
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* // В schema-validators.ts
|
|
305
|
+
* export function required(...) {
|
|
306
|
+
* const registry = ValidationRegistry.getCurrent();
|
|
307
|
+
* if (registry) {
|
|
308
|
+
* registry.registerSync(...);
|
|
309
|
+
* }
|
|
310
|
+
* }
|
|
311
|
+
* ```
|
|
312
|
+
*/
|
|
313
|
+
static getCurrent() {
|
|
314
|
+
return o.getCurrentFromStack(d);
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Начать регистрацию валидаторов для формы
|
|
318
|
+
*
|
|
319
|
+
* Помещает this в global stack для изоляции форм
|
|
320
|
+
* Создает новый RegistrationContext для condition management
|
|
321
|
+
*/
|
|
322
|
+
beginRegistration() {
|
|
323
|
+
super.beginRegistration();
|
|
324
|
+
const t = new x();
|
|
325
|
+
return this.contextStack.push(t), t;
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Завершить регистрацию и применить валидаторы к GroupNode
|
|
329
|
+
*
|
|
330
|
+
* Извлекает this из global stack
|
|
331
|
+
*
|
|
332
|
+
* Сохраняет валидаторы в локальном состоянии (this.validators) вместо глобального WeakMap.
|
|
333
|
+
*/
|
|
334
|
+
endRegistration(t) {
|
|
335
|
+
const e = this.contextStack.pop();
|
|
336
|
+
if (!e)
|
|
337
|
+
throw new Error("No active registration context");
|
|
338
|
+
this.completeRegistration("ValidationRegistry"), this.validators = e.getValidators(), this.applyArrayItemValidators(t, this.validators);
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Отменить регистрацию без применения валидаторов
|
|
342
|
+
* Используется для временной валидации (например, в validateForm)
|
|
343
|
+
*
|
|
344
|
+
* Извлекает this из global stack
|
|
345
|
+
*/
|
|
346
|
+
cancelRegistration() {
|
|
347
|
+
if (!this.contextStack.pop())
|
|
348
|
+
throw new Error("No active registration context to cancel");
|
|
349
|
+
super.cancelRegistration("ValidationRegistry");
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Получить текущий контекст регистрации
|
|
353
|
+
*/
|
|
354
|
+
getCurrentContext() {
|
|
355
|
+
return this.contextStack[this.contextStack.length - 1];
|
|
356
|
+
}
|
|
357
|
+
/**
|
|
358
|
+
* Зарегистрировать синхронный валидатор
|
|
359
|
+
*/
|
|
360
|
+
registerSync(t, e, i) {
|
|
361
|
+
const n = this.getCurrentContext();
|
|
362
|
+
if (!n)
|
|
363
|
+
throw new Error("Validators can only be registered inside a validation schema function");
|
|
364
|
+
n.addValidator({
|
|
365
|
+
fieldPath: t,
|
|
366
|
+
type: "sync",
|
|
367
|
+
validator: e,
|
|
368
|
+
options: i
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Зарегистрировать асинхронный валидатор
|
|
373
|
+
*/
|
|
374
|
+
registerAsync(t, e, i) {
|
|
375
|
+
const n = this.getCurrentContext();
|
|
376
|
+
if (!n)
|
|
377
|
+
throw new Error("Validators can only be registered inside a validation schema function");
|
|
378
|
+
n.addValidator({
|
|
379
|
+
fieldPath: t,
|
|
380
|
+
type: "async",
|
|
381
|
+
validator: e,
|
|
382
|
+
options: i
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Зарегистрировать tree валидатор
|
|
387
|
+
*/
|
|
388
|
+
registerTree(t, e) {
|
|
389
|
+
const i = this.getCurrentContext();
|
|
390
|
+
if (!i)
|
|
391
|
+
throw new Error("Validators can only be registered inside a validation schema function");
|
|
392
|
+
i.addValidator({
|
|
393
|
+
fieldPath: e?.targetField || "__tree__",
|
|
394
|
+
type: "tree",
|
|
395
|
+
validator: t,
|
|
396
|
+
options: e
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Войти в условный блок
|
|
401
|
+
*/
|
|
402
|
+
enterCondition(t, e) {
|
|
403
|
+
const i = this.getCurrentContext();
|
|
404
|
+
if (!i)
|
|
405
|
+
throw new Error("Conditions can only be used inside a validation schema function");
|
|
406
|
+
i.enterCondition(t, e);
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Выйти из условного блока
|
|
410
|
+
*/
|
|
411
|
+
exitCondition() {
|
|
412
|
+
const t = this.getCurrentContext();
|
|
413
|
+
if (!t)
|
|
414
|
+
throw new Error("No active condition");
|
|
415
|
+
t.exitCondition();
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* Зарегистрировать validation schema для элементов массива
|
|
419
|
+
*
|
|
420
|
+
* Используется функцией validateItems() для регистрации схемы валидации,
|
|
421
|
+
* которая будет применяться к каждому элементу ArrayNode.
|
|
422
|
+
*
|
|
423
|
+
* @param fieldPath - Путь к ArrayNode полю
|
|
424
|
+
* @param itemSchemaFn - Validation schema для элемента массива
|
|
425
|
+
*/
|
|
426
|
+
registerArrayItemValidation(t, e) {
|
|
427
|
+
const i = this.getCurrentContext();
|
|
428
|
+
if (!i)
|
|
429
|
+
throw new Error(
|
|
430
|
+
"Array item validators can only be registered inside a validation schema function"
|
|
431
|
+
);
|
|
432
|
+
i.addValidator({
|
|
433
|
+
fieldPath: t,
|
|
434
|
+
type: "array-items",
|
|
435
|
+
validator: e,
|
|
436
|
+
options: {}
|
|
437
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
/**
|
|
441
|
+
* Получить зарегистрированные валидаторы для этого реестра
|
|
442
|
+
*
|
|
443
|
+
* Возвращает локальный массив валидаторов (без аргумента form).
|
|
444
|
+
*/
|
|
445
|
+
getValidators() {
|
|
446
|
+
return this.validators;
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* Применить array-items validators к ArrayNode элементам
|
|
450
|
+
* @private
|
|
451
|
+
*/
|
|
452
|
+
applyArrayItemValidators(t, e) {
|
|
453
|
+
const i = e.filter((n) => n.type === "array-items");
|
|
454
|
+
if (i.length !== 0)
|
|
455
|
+
for (const n of i) {
|
|
456
|
+
const a = t[n.fieldPath.split(".")[0]];
|
|
457
|
+
if (a && "applyValidationSchema" in a) {
|
|
458
|
+
const r = n.validator;
|
|
459
|
+
a.applyValidationSchema(r);
|
|
460
|
+
} else
|
|
461
|
+
y.handle(
|
|
462
|
+
new Error(`Field ${n.fieldPath} is not an ArrayNode or doesn't exist`),
|
|
463
|
+
"ValidationRegistry.applyArrayItemValidators",
|
|
464
|
+
f.LOG
|
|
465
|
+
);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
class C {
|
|
470
|
+
/**
|
|
471
|
+
* Форма с типизированным Proxy-доступом к полям
|
|
472
|
+
*/
|
|
473
|
+
form;
|
|
474
|
+
_form;
|
|
475
|
+
constructor(t) {
|
|
476
|
+
this._form = t;
|
|
477
|
+
const e = t._proxyInstance || t;
|
|
478
|
+
this.form = e;
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Безопасно установить значение поля по строковому пути или FieldPath
|
|
482
|
+
*
|
|
483
|
+
* Автоматически использует emitEvent: false для предотвращения циклов
|
|
484
|
+
*
|
|
485
|
+
* @param path - Строковый путь к полю или FieldPath объект
|
|
486
|
+
* @param value - Новое значение
|
|
487
|
+
*/
|
|
488
|
+
setFieldValue(t, e) {
|
|
489
|
+
const i = typeof t == "string" ? t : t.__path, n = this._form.getFieldByPath(i);
|
|
490
|
+
n && n.setValue(e, { emitEvent: !1 });
|
|
491
|
+
}
|
|
492
|
+
/**
|
|
493
|
+
* Получить поле формы по строковому пути
|
|
494
|
+
*
|
|
495
|
+
* Используется для динамического доступа к вложенным полям, например:
|
|
496
|
+
* - `ctx.getFieldByPath('address.city')` -> FieldNode
|
|
497
|
+
* - `ctx.getFieldByPath(path.city.__path)` -> FieldNode (для nested behaviors)
|
|
498
|
+
*
|
|
499
|
+
* @param path - Строковый путь к полю (например "address.city")
|
|
500
|
+
* @returns FieldNode или undefined если поле не найдено
|
|
501
|
+
*/
|
|
502
|
+
getFieldByPath(t) {
|
|
503
|
+
return this._form.getFieldByPath(t);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
class h extends o {
|
|
507
|
+
/**
|
|
508
|
+
* Получить текущий активный реестр из context stack
|
|
509
|
+
*
|
|
510
|
+
* @returns Текущий активный реестр или null
|
|
511
|
+
*
|
|
512
|
+
* @example
|
|
513
|
+
* ```typescript
|
|
514
|
+
* // В schema-behaviors.ts
|
|
515
|
+
* export function copyFrom(...) {
|
|
516
|
+
* const registry = BehaviorRegistry.getCurrent();
|
|
517
|
+
* if (registry) {
|
|
518
|
+
* registry.register({ ... });
|
|
519
|
+
* }
|
|
520
|
+
* }
|
|
521
|
+
* ```
|
|
522
|
+
*/
|
|
523
|
+
static getCurrent() {
|
|
524
|
+
return o.getCurrentFromStack(h);
|
|
525
|
+
}
|
|
526
|
+
/**
|
|
527
|
+
* Зарегистрировать behavior handler
|
|
528
|
+
* Вызывается функциями из schema-behaviors.ts
|
|
529
|
+
*
|
|
530
|
+
* @param handler - BehaviorHandlerFn функция
|
|
531
|
+
* @param options - Опции behavior (debounce)
|
|
532
|
+
*
|
|
533
|
+
* @example
|
|
534
|
+
* ```typescript
|
|
535
|
+
* const handler = createCopyBehavior(target, source, { when: ... });
|
|
536
|
+
* registry.register(handler, { debounce: 300 });
|
|
537
|
+
* ```
|
|
538
|
+
*/
|
|
539
|
+
register(t, e) {
|
|
540
|
+
this.isActive() && this.registrations.push({
|
|
541
|
+
// Type assertion безопасен: handler будет вызван с правильным типом формы в createEffect
|
|
542
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
543
|
+
handler: t,
|
|
544
|
+
debounce: e?.debounce
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Завершить регистрацию и применить behaviors к форме
|
|
549
|
+
* Создает effect подписки для всех зарегистрированных behaviors
|
|
550
|
+
*
|
|
551
|
+
* @param form - GroupNode формы
|
|
552
|
+
* @returns Количество зарегистрированных behaviors и функция cleanup
|
|
553
|
+
*/
|
|
554
|
+
endRegistration(t) {
|
|
555
|
+
const e = this.registrations.length, i = new C(t), n = [];
|
|
556
|
+
for (const r of this.registrations) {
|
|
557
|
+
const c = this.createEffect(r, t, i);
|
|
558
|
+
c && n.push(c);
|
|
559
|
+
}
|
|
560
|
+
return this.completeRegistration("BehaviorRegistry"), { count: e, cleanup: () => {
|
|
561
|
+
n.forEach((r) => r());
|
|
562
|
+
} };
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Создать effect подписку для behavior
|
|
566
|
+
* @private
|
|
567
|
+
*/
|
|
568
|
+
createEffect(t, e, i) {
|
|
569
|
+
const { handler: n, debounce: a = 0 } = t;
|
|
570
|
+
let r = null;
|
|
571
|
+
const c = (u) => {
|
|
572
|
+
a > 0 ? (r && clearTimeout(r), r = setTimeout(u, a)) : u();
|
|
573
|
+
}, p = () => {
|
|
574
|
+
r && (clearTimeout(r), r = null);
|
|
575
|
+
}, g = n(e, i, c);
|
|
576
|
+
return g ? () => {
|
|
577
|
+
p(), g && g();
|
|
578
|
+
} : null;
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
function k() {
|
|
582
|
+
const s = d.getCurrent();
|
|
583
|
+
return s || {
|
|
584
|
+
registerSync: () => {
|
|
585
|
+
},
|
|
586
|
+
registerAsync: () => {
|
|
587
|
+
},
|
|
588
|
+
registerTree: () => {
|
|
589
|
+
},
|
|
590
|
+
enterCondition: () => {
|
|
591
|
+
},
|
|
592
|
+
exitCondition: () => {
|
|
593
|
+
},
|
|
594
|
+
registerArrayItemValidation: () => {
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
function V() {
|
|
599
|
+
const s = h.getCurrent();
|
|
600
|
+
return s || {
|
|
601
|
+
register: () => {
|
|
602
|
+
}
|
|
603
|
+
};
|
|
604
|
+
}
|
|
605
|
+
export {
|
|
606
|
+
o as A,
|
|
607
|
+
h as B,
|
|
608
|
+
f as E,
|
|
609
|
+
y as F,
|
|
610
|
+
m as R,
|
|
611
|
+
d as V,
|
|
612
|
+
C as a,
|
|
613
|
+
V as b,
|
|
614
|
+
k as g
|
|
615
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
function a(e) {
|
|
2
|
+
return (...u) => {
|
|
3
|
+
queueMicrotask(() => e(...u));
|
|
4
|
+
};
|
|
5
|
+
}
|
|
6
|
+
function t(e) {
|
|
7
|
+
queueMicrotask(e);
|
|
8
|
+
}
|
|
9
|
+
function c(e, u) {
|
|
10
|
+
return () => {
|
|
11
|
+
u(() => {
|
|
12
|
+
queueMicrotask(e);
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
c as a,
|
|
18
|
+
t as r,
|
|
19
|
+
a as s
|
|
20
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { v as m } from "../validate-C3XiA_zf.js";
|
|
2
|
+
function i(e, r) {
|
|
3
|
+
if (!e) return;
|
|
4
|
+
const s = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
5
|
+
m(e, (a) => a ? s.test(a) ? null : {
|
|
6
|
+
code: "email",
|
|
7
|
+
message: r?.message || "Неверный формат email",
|
|
8
|
+
params: r?.params
|
|
9
|
+
} : null);
|
|
10
|
+
}
|
|
11
|
+
export {
|
|
12
|
+
i as email
|
|
13
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { v as o } from "../validate-C3XiA_zf.js";
|
|
2
|
+
import { p as u, n as l, g as m } from "../date-utils-xUWFslTj.js";
|
|
3
|
+
function d(a, e) {
|
|
4
|
+
a && o(a, (r) => {
|
|
5
|
+
if (r == null || r === "")
|
|
6
|
+
return null;
|
|
7
|
+
const t = u(r);
|
|
8
|
+
if (t === null)
|
|
9
|
+
return null;
|
|
10
|
+
const n = l(t), s = m();
|
|
11
|
+
return n < s ? {
|
|
12
|
+
code: "date_past",
|
|
13
|
+
message: e?.message || "Дата не может быть в прошлом",
|
|
14
|
+
params: e?.params
|
|
15
|
+
} : null;
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
export {
|
|
19
|
+
d as futureDate
|
|
20
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { v as s } from "../validate-C3XiA_zf.js";
|
|
2
|
+
import { p as n } from "../date-utils-xUWFslTj.js";
|
|
3
|
+
function p(a, e) {
|
|
4
|
+
a && s(a, (r) => r == null || r === "" ? null : n(r) === null ? {
|
|
5
|
+
code: "date_invalid",
|
|
6
|
+
message: e?.message || "Неверный формат даты",
|
|
7
|
+
params: e?.params
|
|
8
|
+
} : null);
|
|
9
|
+
}
|
|
10
|
+
export {
|
|
11
|
+
p as isDate
|
|
12
|
+
};
|