adaptform 2.1.0 → 2.2.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 +52 -4
- package/CHANGELOG.ru.md +52 -4
- package/README.md +43 -9
- package/README.ru.md +43 -9
- package/dist/{Form-kPYL4f-n.d.cts → Form-uHUaTUZS.d.cts} +81 -9
- package/dist/{Form-kPYL4f-n.d.ts → Form-uHUaTUZS.d.ts} +81 -9
- package/dist/index.cjs +735 -236
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.mjs +735 -236
- package/dist/index.mjs.map +1 -1
- package/dist/luxon.d.cts +1 -1
- package/dist/luxon.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,3 +1,47 @@
|
|
|
1
|
+
/** Shared mutation boundary; subclasses only describe state and their mutations. */
|
|
2
|
+
declare abstract class ObservableNode<TSnapshot> {
|
|
3
|
+
private readonly _stateStore;
|
|
4
|
+
protected abstract captureState(): TSnapshot;
|
|
5
|
+
protected stateChildren(): readonly ObservableNode<unknown>[];
|
|
6
|
+
private contains;
|
|
7
|
+
protected validateAfterMutation(callback: () => unknown): void;
|
|
8
|
+
protected batchUpdate<TResult>(callback: () => TResult, validate: () => unknown): TResult;
|
|
9
|
+
subscribe(listener: () => void): () => void;
|
|
10
|
+
getSnapshot(): TSnapshot;
|
|
11
|
+
protected update<TResult>(callback: () => TResult): TResult;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** Snapshots contain data only: mutable built-ins and opaque instances are described. */
|
|
15
|
+
type SnapshotValue = null | undefined | string | number | boolean | bigint | readonly SnapshotValue[] | {
|
|
16
|
+
readonly [key: string]: SnapshotValue;
|
|
17
|
+
};
|
|
18
|
+
interface NodeSnapshot {
|
|
19
|
+
readonly isValid: boolean | null;
|
|
20
|
+
readonly isTouched: boolean;
|
|
21
|
+
readonly isDirty: boolean;
|
|
22
|
+
}
|
|
23
|
+
interface FieldSnapshot extends NodeSnapshot {
|
|
24
|
+
readonly rawValue: SnapshotValue;
|
|
25
|
+
readonly valueClear: SnapshotValue;
|
|
26
|
+
readonly errors: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
interface FormSnapshot extends NodeSnapshot {
|
|
29
|
+
readonly fieldsValue: Readonly<Record<string, SnapshotValue>>;
|
|
30
|
+
readonly allErrors: Readonly<Record<string, readonly string[]>>;
|
|
31
|
+
readonly globalErrors: Readonly<Record<string, string>>;
|
|
32
|
+
readonly fields: Readonly<Record<string, FieldSnapshot | ArrayFieldSnapshot | ArrayFormSnapshot>>;
|
|
33
|
+
}
|
|
34
|
+
interface ArrayFieldSnapshot extends NodeSnapshot {
|
|
35
|
+
readonly itemsValue: readonly SnapshotValue[];
|
|
36
|
+
readonly errors: readonly string[];
|
|
37
|
+
readonly items: readonly FieldSnapshot[];
|
|
38
|
+
}
|
|
39
|
+
interface ArrayFormSnapshot extends NodeSnapshot {
|
|
40
|
+
readonly formsFieldsValue: readonly Readonly<Record<string, SnapshotValue>>[];
|
|
41
|
+
readonly errors: readonly string[];
|
|
42
|
+
readonly forms: readonly FormSnapshot[];
|
|
43
|
+
}
|
|
44
|
+
|
|
1
45
|
interface FieldPlugin<T = any> {
|
|
2
46
|
pluginOptions?: PluginOptions;
|
|
3
47
|
init?(field: Field<T>): void;
|
|
@@ -9,15 +53,23 @@ declare abstract class BasePlugin<T = any> implements FieldPlugin<T> {
|
|
|
9
53
|
constructor(pluginOptions?: PluginOptions);
|
|
10
54
|
}
|
|
11
55
|
|
|
12
|
-
declare class ArrayField<T = any> {
|
|
56
|
+
declare class ArrayField<T = any> extends ObservableNode<ArrayFieldSnapshot> {
|
|
13
57
|
protected factory: (value?: T) => Field<T>;
|
|
58
|
+
protected captureState(): ArrayFieldSnapshot;
|
|
14
59
|
protected options: ArrayFieldOptions;
|
|
15
60
|
protected _items: Field<T>[];
|
|
16
61
|
protected _errors: string[];
|
|
62
|
+
protected stateChildren(): readonly ObservableNode<unknown>[];
|
|
63
|
+
private _baseline;
|
|
17
64
|
private _hasValidationResult;
|
|
18
|
-
|
|
65
|
+
private _isTouched;
|
|
66
|
+
get isTouched(): boolean;
|
|
67
|
+
set isTouched(value: boolean);
|
|
19
68
|
constructor(factory: (value?: T) => Field<T>, options?: ArrayFieldOptions, initial?: (T | null)[]);
|
|
69
|
+
get isDirty(): boolean;
|
|
70
|
+
commitBaseline(): void;
|
|
20
71
|
set itemsValue(items: (T | null)[]);
|
|
72
|
+
setItemsValue(items: (T | null)[], validate?: boolean): void;
|
|
21
73
|
get itemsValue(): (T | null)[];
|
|
22
74
|
get items(): Field<T>[];
|
|
23
75
|
add(value?: T, force_check?: boolean): Field<T>;
|
|
@@ -33,14 +85,21 @@ declare class ArrayField<T = any> {
|
|
|
33
85
|
reset(): void;
|
|
34
86
|
}
|
|
35
87
|
|
|
36
|
-
declare class ArrayFormField<T extends Form = Form> {
|
|
88
|
+
declare class ArrayFormField<T extends Form = Form> extends ObservableNode<ArrayFormSnapshot> {
|
|
37
89
|
private FormConstructor;
|
|
38
90
|
private options;
|
|
91
|
+
protected captureState(): ArrayFormSnapshot;
|
|
39
92
|
private _forms;
|
|
40
93
|
private _errors;
|
|
94
|
+
protected stateChildren(): readonly ObservableNode<unknown>[];
|
|
95
|
+
private _baseline;
|
|
41
96
|
private _hasValidationResult;
|
|
42
|
-
|
|
97
|
+
private _isTouched;
|
|
98
|
+
get isTouched(): boolean;
|
|
99
|
+
set isTouched(value: boolean);
|
|
43
100
|
constructor(FormConstructor: new () => T, options?: ArrayFormFieldOptions, initial?: unknown[]);
|
|
101
|
+
get isDirty(): boolean;
|
|
102
|
+
commitBaseline(): void;
|
|
44
103
|
set forms(forms: unknown[]);
|
|
45
104
|
setForms(forms: unknown[], validate?: boolean): void;
|
|
46
105
|
get forms(): T[];
|
|
@@ -170,15 +229,21 @@ declare abstract class FieldType<T, O extends FieldOptions = FieldOptions> {
|
|
|
170
229
|
}
|
|
171
230
|
|
|
172
231
|
type FieldTypeConstructor<T, O extends FieldOptions = FieldOptions> = new (options: O) => FieldType<T, O>;
|
|
173
|
-
declare class Field<T = any, O extends FieldOptions = FieldOptions> {
|
|
232
|
+
declare class Field<T = any, O extends FieldOptions = FieldOptions> extends ObservableNode<FieldSnapshot> {
|
|
174
233
|
protected _rawValue: any;
|
|
175
234
|
protected _valueClear: T | null;
|
|
176
235
|
protected fieldType: FieldType<T, O>;
|
|
177
236
|
protected defaultValue: T | null;
|
|
237
|
+
private _baseline;
|
|
178
238
|
protected _errors: string[];
|
|
179
|
-
|
|
180
|
-
|
|
239
|
+
private _isValid;
|
|
240
|
+
get isValid(): boolean | null;
|
|
241
|
+
set isValid(value: boolean | null);
|
|
242
|
+
private _isTouched;
|
|
243
|
+
get isTouched(): boolean;
|
|
244
|
+
set isTouched(value: boolean);
|
|
181
245
|
constructor(TypeConstructor: FieldTypeConstructor<T, O>, defaultValue?: T | null, options?: O | null);
|
|
246
|
+
protected captureState(): FieldSnapshot;
|
|
182
247
|
protected get plugins(): FieldPlugin<any>[];
|
|
183
248
|
get options(): O;
|
|
184
249
|
set options(options: O);
|
|
@@ -190,6 +255,8 @@ declare class Field<T = any, O extends FieldOptions = FieldOptions> {
|
|
|
190
255
|
get error(): string;
|
|
191
256
|
set error(message: string | null);
|
|
192
257
|
get valueClear(): T | null;
|
|
258
|
+
get isDirty(): boolean;
|
|
259
|
+
commitBaseline(): void;
|
|
193
260
|
private isRequired;
|
|
194
261
|
checkValid(form?: Form): boolean;
|
|
195
262
|
checkAndSetValid(form?: Form): boolean;
|
|
@@ -280,7 +347,10 @@ type FormFieldValue<TField> = TField extends Field<infer TValue, infer _Options>
|
|
|
280
347
|
type FormFieldsValue<TForm extends Form> = {
|
|
281
348
|
[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
349
|
};
|
|
283
|
-
declare abstract class Form {
|
|
350
|
+
declare abstract class Form extends ObservableNode<FormSnapshot> {
|
|
351
|
+
protected captureState(): FormSnapshot;
|
|
352
|
+
protected stateChildren(): readonly ObservableNode<unknown>[];
|
|
353
|
+
batch<TResult>(callback: () => TResult & (TResult extends PromiseLike<unknown> ? never : unknown)): TResult;
|
|
284
354
|
private _globalErrors;
|
|
285
355
|
errorsShema: ErrorsSchema;
|
|
286
356
|
protected get _fields(): Record<string, Field<any> | ArrayField<any> | ArrayFormField<any>>;
|
|
@@ -305,6 +375,8 @@ declare abstract class Form {
|
|
|
305
375
|
setGlobalError(key: string, message: string): void;
|
|
306
376
|
clearGlobalErrors(): void;
|
|
307
377
|
reset(): void;
|
|
378
|
+
get isDirty(): boolean;
|
|
379
|
+
commitBaseline(): void;
|
|
308
380
|
get isTouched(): boolean;
|
|
309
381
|
get isValid(): boolean;
|
|
310
382
|
toFormData(): FormData;
|
|
@@ -312,4 +384,4 @@ declare abstract class Form {
|
|
|
312
384
|
private serializeJsonValue;
|
|
313
385
|
}
|
|
314
386
|
|
|
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,
|
|
387
|
+
export { ArrayField as A, BasePlugin as B, type messagesOptions as C, type DecimalOptions as D, ErrorsSchema as E, Field as F, type messagesStringOptions as G, 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, type ArrayFieldSnapshot as e, ArrayFormField as f, type ArrayFormFieldOptions as g, type ArrayFormSnapshot as h, DefaultErrorsSchema as i, type DynamicRule as j, type FieldOptions as k, type FieldPlugin as l, type FieldSnapshot as m, Form as n, type FormFieldValue as o, type FormFieldsValue as p, type FormSnapshot as q, type NodeSnapshot as r, type ParsedError as s, type SnapshotValue as t, type messagesArrayFieldOptions as u, type messagesArrayFormFieldOptions as v, type messagesBooleanOptions as w, type messagesDateOptions as x, type messagesDecimalOptions as y, type messagesNumberOptions as z };
|