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.
- package/CHANGELOG.md +103 -2
- package/CHANGELOG.ru.md +152 -0
- package/LICENSE.md +3 -1
- package/LICENSE.ru.md +25 -0
- package/README.md +271 -303
- package/README.ru.md +388 -0
- package/dist/{Form-Be3I6LX0.d.cts → Form-kPYL4f-n.d.cts} +58 -36
- package/dist/{Form-Be3I6LX0.d.ts → Form-kPYL4f-n.d.ts} +58 -36
- package/dist/index.cjs +184 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.mjs +183 -103
- package/dist/index.mjs.map +1 -1
- package/dist/luxon.d.cts +1 -1
- package/dist/luxon.d.ts +1 -1
- package/package.json +28 -9
|
@@ -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?:
|
|
42
|
-
set forms(forms:
|
|
43
|
-
|
|
44
|
-
get
|
|
45
|
-
|
|
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():
|
|
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():
|
|
270
|
-
set fields(data: Record<string,
|
|
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
|
-
*
|
|
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,
|
|
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,
|
|
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
|
|
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 };
|