adaptform 2.0.5 → 2.1.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.
@@ -14,10 +14,11 @@ declare class ArrayField<T = any> {
14
14
  protected options: ArrayFieldOptions;
15
15
  protected _items: Field<T>[];
16
16
  protected _errors: string[];
17
+ private _hasValidationResult;
17
18
  isTouched: boolean;
18
- constructor(factory: (value?: T) => Field<T>, options?: ArrayFieldOptions, initial?: T[]);
19
- set itemsValue(items: T[]);
20
- get itemsValue(): T[];
19
+ constructor(factory: (value?: T) => Field<T>, options?: ArrayFieldOptions, initial?: (T | null)[]);
20
+ set itemsValue(items: (T | null)[]);
21
+ get itemsValue(): (T | null)[];
21
22
  get items(): Field<T>[];
22
23
  add(value?: T, force_check?: boolean): Field<T>;
23
24
  remove(index: number): void;
@@ -37,12 +38,14 @@ declare class ArrayFormField<T extends Form = Form> {
37
38
  private options;
38
39
  private _forms;
39
40
  private _errors;
41
+ private _hasValidationResult;
40
42
  isTouched: boolean;
41
- constructor(FormConstructor: new () => T, options?: ArrayFormFieldOptions, initial?: any[]);
42
- set forms(forms: any[]);
43
- get forms(): Form[];
44
- get formsFieldsValue(): any[];
45
- add(data?: any, force_check?: boolean): T;
43
+ constructor(FormConstructor: new () => T, options?: ArrayFormFieldOptions, initial?: unknown[]);
44
+ set forms(forms: unknown[]);
45
+ setForms(forms: unknown[], validate?: boolean): void;
46
+ get forms(): T[];
47
+ get formsFieldsValue(): FormFieldsValue<T>[];
48
+ add(data?: unknown, force_check?: boolean): T;
46
49
  remove(index: number): void;
47
50
  clear(): void;
48
51
  reset(): void;
@@ -181,10 +184,12 @@ declare class Field<T = any, O extends FieldOptions = FieldOptions> {
181
184
  set options(options: O);
182
185
  get rawValue(): T | null;
183
186
  set rawValue(input: any);
187
+ setRawValue(input: any, validate?: boolean): void;
188
+ private assignRawValue;
184
189
  get errors(): string[];
185
190
  get error(): string;
186
191
  set error(message: string | null);
187
- get valueClear(): any;
192
+ get valueClear(): T | null;
188
193
  private isRequired;
189
194
  checkValid(form?: Form): boolean;
190
195
  checkAndSetValid(form?: Form): boolean;
@@ -192,92 +197,108 @@ declare class Field<T = any, O extends FieldOptions = FieldOptions> {
192
197
  reset(): void;
193
198
  }
194
199
 
200
+ type ErrorFieldMapping = string | ((errorValue: any) => string);
195
201
  interface ParsedError {
196
202
  fieldName: string;
197
203
  message: string;
198
204
  sourceKey: string;
199
205
  matchedBy: 'static' | 'dynamic' | 'fallback';
200
206
  }
207
+ interface DynamicRule {
208
+ pattern: RegExp;
209
+ mapping: ErrorFieldMapping | ((match: RegExpMatchArray, value?: any) => string);
210
+ priority: number;
211
+ }
201
212
  declare class ErrorsSchema {
202
213
  private _staticRules;
203
214
  private _dynamicRules;
204
215
  private _fallbackHandler?;
205
216
  private _valueTransformers;
206
217
  /**
207
- * Добавляет статическое правило - точное соответствие ключа ошибки
208
- * @param errorKey - точный ключ ошибки из ответа сервера
209
- * @param fieldName - имя поля в форме или функция для динамического определения
218
+ * Add a static rule that matches an exact error key.
219
+ * @param errorKey - Exact error key returned by the server.
220
+ * @param fieldName - Form field name or a function that resolves it dynamically.
210
221
  */
211
222
  staticKey(errorKey: string, fieldName: string | ((errorValue: any) => string)): this;
212
223
  /**
213
- * Добавляет динамическое правило с регулярным выражением
214
- * @param pattern - регулярное выражение для сопоставления ключа ошибки
215
- * @param mapping - имя поля или функция для извлечения имени поля из совпадения
216
- * @param options - дополнительные опции (приоритет и т.д.)
224
+ * Add a dynamic rule using a regular expression.
225
+ * @param pattern - Regular expression used to match an error key.
226
+ * @param mapping - Field name or function that derives it from the match.
227
+ * @param options - Additional options, such as rule priority.
217
228
  */
218
- dynamicKey(pattern: RegExp, mapping: string | ((match: RegExpMatchArray) => string), options?: {
229
+ dynamicKey(pattern: RegExp, mapping: string | ((match: RegExpMatchArray, value?: any) => string), options?: {
219
230
  priority?: number;
220
231
  }): this;
221
232
  /**
222
- * Устанавливает обработчик для ошибок, которые не подошли ни под одно правило
233
+ * Set a handler for errors that do not match any rule.
223
234
  */
224
235
  fallback(handler: (key: string, value: any) => string | null): this;
225
236
  /**
226
- * Добавляет трансформер для значений ошибок
227
- * Полезно для нормализации сообщений (например, если сервер возвращает массив ошибок)
237
+ * Add a transformer for error values.
238
+ * Useful for normalizing messages, such as server responses containing arrays.
228
239
  */
229
240
  transformValue(transformer: (value: any) => any): this;
230
241
  /**
231
- * Быстрый метод для создания схемы из простого объекта маппинга
242
+ * Create a schema from a simple mapping object.
232
243
  */
233
244
  static fromObject(mapping: Record<string, string>): ErrorsSchema;
234
245
  /**
235
- * Создает схему для массива однотипных форм
246
+ * Create a schema for an array of similarly structured forms.
236
247
  */
237
248
  static forArray(itemSchema: ErrorsSchema, arrayFieldName: string, indexExtractor?: (key: string) => number): ErrorsSchema;
238
249
  /**
239
- * Основной метод парсинга ошибок с поддержкой трансформеров
240
- * Поддерживает вложенные структуры через точечную нотацию
250
+ * Parse errors while applying configured value transformers.
251
+ * Supports nested structures using dot notation.
241
252
  */
242
253
  parseErrors(errors: Record<string, any>, prefix?: string): Record<string, string>;
243
254
  /**
244
- * Парсит ошибки сервера и возвращает расширенную информацию
255
+ * Parse server errors and return detailed metadata.
245
256
  */
246
257
  parseErrorsDetailed(errors: Record<string, any>, prefix?: string): Record<string, ParsedError>;
247
258
  /**
248
- * Создает схему для вложенной формы
259
+ * Create a schema for a nested form.
249
260
  */
250
261
  nest(prefix: string): ErrorsSchema;
251
262
  /**
252
- * Клонирует текущую схему
263
+ * Clone the current schema.
253
264
  */
254
265
  clone(): ErrorsSchema;
255
266
  /**
256
- * Объединяет текущую схему с другой
267
+ * Merge the current schema with another schema.
257
268
  */
258
269
  merge(other: ErrorsSchema): ErrorsSchema;
259
270
  private isNestedObject;
260
271
  private findMappingDetailed;
261
272
  private findMapping;
262
273
  }
274
+ /**
275
+ * Default base schema.
276
+ */
277
+ declare const DefaultErrorsSchema: ErrorsSchema;
263
278
 
279
+ type FormFieldValue<TField> = TField extends Field<infer TValue, infer _Options> ? TValue | null : TField extends ArrayField<infer TValue> ? (TValue | null)[] : TField extends ArrayFormField<infer TForm> ? TForm extends Form ? FormFieldsValue<TForm>[] : unknown[] : never;
280
+ type FormFieldsValue<TForm extends Form> = {
281
+ [K in keyof TForm as TForm[K] extends Field<infer _Value, infer _Options> | ArrayField<infer _ArrayValue> | ArrayFormField<infer _NestedForm> ? K : never]: FormFieldValue<TForm[K]>;
282
+ };
264
283
  declare abstract class Form {
265
284
  private _globalErrors;
266
285
  errorsShema: ErrorsSchema;
267
286
  protected get _fields(): Record<string, Field<any> | ArrayField<any> | ArrayFormField<any>>;
268
287
  checkValid(form?: this): boolean;
269
- get fieldsValue(): Record<string, any>;
270
- set fields(data: Record<string, any>);
288
+ get fieldsValue(): FormFieldsValue<this>;
289
+ set fields(data: Record<string, unknown>);
290
+ setFields(data: Record<string, unknown>, validate?: boolean): void;
271
291
  get allErrors(): Record<string, string[]>;
272
292
  /**
273
- * Рекурсивно собирает все ошибки из ArrayFormField
293
+ * Recursively collect all errors from an ArrayFormField.
274
294
  */
275
295
  private collectArrayFormErrors;
276
296
  get globalErrors(): Record<string, string>;
277
- set errors(errors: Record<string, any>);
297
+ set errors(errors: Record<string, unknown>);
298
+ private clearErrorsRecursively;
278
299
  /**
279
- * Применяет ошибку к соответствующему полю
280
- * Поддерживает вложенные поля через точечную нотацию
300
+ * Apply an error to the corresponding field.
301
+ * Supports nested fields using dot notation.
281
302
  */
282
303
  private applyErrorToField;
283
304
  private applyNestedError;
@@ -287,7 +308,8 @@ declare abstract class Form {
287
308
  get isTouched(): boolean;
288
309
  get isValid(): boolean;
289
310
  toFormData(): FormData;
290
- toJSON(): Record<string, any>;
311
+ toJSON(): Record<string, unknown>;
312
+ private serializeJsonValue;
291
313
  }
292
314
 
293
- export { ArrayField as A, BasePlugin as B, type DecimalOptions as D, Field as F, type MaskPluginOptions as M, type NumberOptions as N, type PluginOptions as P, type StringOptions as S, FieldType as a, type BooleanOptions as b, type DateOptions as c, type ArrayFieldOptions as d, ArrayFormField as e, type ArrayFormFieldOptions as f, type FieldOptions as g, type FieldPlugin as h, Form as i, type messagesArrayFormFieldOptions as j, type messagesBooleanOptions as k, type messagesDateOptions as l, type messagesArrayFieldOptions as m, type messagesDecimalOptions as n, type messagesNumberOptions as o, type messagesOptions as p, type messagesStringOptions as q };
315
+ export { ArrayField as A, BasePlugin as B, type DecimalOptions as D, ErrorsSchema as E, Field as F, type MaskPluginOptions as M, type NumberOptions as N, type PluginOptions as P, type StringOptions as S, FieldType as a, type BooleanOptions as b, type DateOptions as c, type ArrayFieldOptions as d, ArrayFormField as e, type ArrayFormFieldOptions as f, DefaultErrorsSchema as g, type DynamicRule as h, type FieldOptions as i, type FieldPlugin as j, Form as k, type FormFieldValue as l, type FormFieldsValue as m, type ParsedError as n, type messagesArrayFieldOptions as o, type messagesArrayFormFieldOptions as p, type messagesBooleanOptions as q, type messagesDateOptions as r, type messagesDecimalOptions as s, type messagesNumberOptions as t, type messagesOptions as u, type messagesStringOptions as v };