@websolutespa/bom-mixer-forms 0.0.1
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 +7 -0
- package/dist/index.d.ts +306 -0
- package/dist/index.js +1131 -0
- package/dist/index.mjs +1080 -0
- package/package.json +62 -0
package/CHANGELOG.md
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { IEquatable, IOption } from '@websolutespa/bom-mixer-core';
|
|
2
|
+
import { DependencyList } from 'react';
|
|
3
|
+
|
|
4
|
+
declare class EventEmitter {
|
|
5
|
+
protected events_: {
|
|
6
|
+
[key: string]: ((...args: any[]) => any)[];
|
|
7
|
+
};
|
|
8
|
+
on(event: string, listener: (...args: any[]) => any): void;
|
|
9
|
+
off(event: string, listener: (...args: any[]) => any): void;
|
|
10
|
+
emit(event: string, ...args: any[]): void;
|
|
11
|
+
once(event: string, listener: (...args: any[]) => any): void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
declare class FormAbstractCollection<T extends FormControls> extends FormAbstract {
|
|
15
|
+
controls_: T;
|
|
16
|
+
constructor(controls: T, validators?: (FormValidator | FormValidator[]));
|
|
17
|
+
initControl_(controlOrValue: FormAbstract | any, key: any): FormAbstract;
|
|
18
|
+
protected setInitialOptions(options?: FormOptions): void;
|
|
19
|
+
protected checkAsyncPropState_(key: string, option?: FormActivator, root?: FormCollection): Promise<boolean>;
|
|
20
|
+
updateState_(): void;
|
|
21
|
+
revalidate_(): Promise<void>;
|
|
22
|
+
protected validate_(root?: FormCollection): Promise<void>;
|
|
23
|
+
reset(): void;
|
|
24
|
+
patch(value: any): void;
|
|
25
|
+
get(key: keyof T): FormAbstract;
|
|
26
|
+
set(control: FormAbstract, key: keyof T): void;
|
|
27
|
+
add(control: FormAbstract, key: keyof T): void;
|
|
28
|
+
remove(control: FormAbstract): void;
|
|
29
|
+
removeKey(key: keyof T): void;
|
|
30
|
+
addValidators(...validators: FormValidator[]): void;
|
|
31
|
+
replaceValidators(...validators: FormValidator[]): void;
|
|
32
|
+
clearValidators(): void;
|
|
33
|
+
protected forEach_(callback: Function): void;
|
|
34
|
+
protected reduce_(callback: Function, result: any): any;
|
|
35
|
+
protected all_(key: (keyof FormAbstract), value: any): boolean;
|
|
36
|
+
protected any_(key: (keyof FormAbstract), value: any): boolean;
|
|
37
|
+
protected map_(): FormAbstract[];
|
|
38
|
+
get controls(): T;
|
|
39
|
+
set controls(controls: T);
|
|
40
|
+
set disabled(disabled: boolean);
|
|
41
|
+
set readonly(readonly: boolean);
|
|
42
|
+
set hidden(hidden: boolean);
|
|
43
|
+
set submitted(submitted: boolean);
|
|
44
|
+
set touched(touched: boolean);
|
|
45
|
+
get value(): {
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
};
|
|
48
|
+
set value(value: {
|
|
49
|
+
[key: string]: any;
|
|
50
|
+
});
|
|
51
|
+
get errors(): {
|
|
52
|
+
[key: string]: any;
|
|
53
|
+
};
|
|
54
|
+
set errors(errors: {
|
|
55
|
+
[key: string]: any;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare class FormArray extends FormAbstractCollection<FormAbstract[]> {
|
|
60
|
+
constructor(controls?: FormAbstract[], validators?: FormValidator | FormValidator[], initialOptions?: FormOptions);
|
|
61
|
+
forEach_(callback: (control: FormAbstract, key: number) => any): void;
|
|
62
|
+
map_(): FormAbstract[];
|
|
63
|
+
get value(): any[];
|
|
64
|
+
get length(): number;
|
|
65
|
+
protected init(control: FormAbstract, key: number): void;
|
|
66
|
+
set(control: FormAbstract, key: number): void;
|
|
67
|
+
add(control: FormAbstract, key: number): void;
|
|
68
|
+
push(control: FormAbstract): void;
|
|
69
|
+
insert(control: FormAbstract, key: number): void;
|
|
70
|
+
remove(control: FormAbstract): void;
|
|
71
|
+
removeKey(key: number): void;
|
|
72
|
+
at(key: number): FormAbstract;
|
|
73
|
+
}
|
|
74
|
+
declare function formArray(controls?: FormAbstract[], validators?: FormValidator | FormValidator[]): FormArray;
|
|
75
|
+
|
|
76
|
+
declare class FormControl extends FormAbstract {
|
|
77
|
+
constructor(value?: any, validators?: FormValidator | FormValidator[], initialOptions?: FormOptions);
|
|
78
|
+
}
|
|
79
|
+
declare function formControl(value?: any, validators?: FormValidator | FormValidator[]): FormControl;
|
|
80
|
+
|
|
81
|
+
declare class FormGroup extends FormAbstractCollection<{
|
|
82
|
+
[key: string]: FormAbstract;
|
|
83
|
+
}> {
|
|
84
|
+
constructor(controls?: {
|
|
85
|
+
[key: string]: FormAbstract | any;
|
|
86
|
+
}, validators?: FormValidator | FormValidator[], initialOptions?: FormOptions);
|
|
87
|
+
}
|
|
88
|
+
declare function formGroup(controls?: {
|
|
89
|
+
[key: string]: FormAbstract | any;
|
|
90
|
+
}, validators?: FormValidator | FormValidator[]): FormGroup;
|
|
91
|
+
|
|
92
|
+
type IControlParam = {
|
|
93
|
+
uid: number;
|
|
94
|
+
control: FormControl;
|
|
95
|
+
};
|
|
96
|
+
type IFormOption = {
|
|
97
|
+
id: IEquatable;
|
|
98
|
+
name: string;
|
|
99
|
+
};
|
|
100
|
+
type FormOptions = {
|
|
101
|
+
schema?: ControlType;
|
|
102
|
+
name?: string;
|
|
103
|
+
label?: string;
|
|
104
|
+
value?: string;
|
|
105
|
+
placeholder?: string;
|
|
106
|
+
required?: FormActivator;
|
|
107
|
+
hidden?: FormActivator;
|
|
108
|
+
disabled?: FormActivator;
|
|
109
|
+
readonly?: FormActivator;
|
|
110
|
+
options?: IOption[];
|
|
111
|
+
optionsExtra?: {
|
|
112
|
+
asEquatable: boolean;
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
type ValidationError = {
|
|
116
|
+
[key: string]: any;
|
|
117
|
+
};
|
|
118
|
+
type FormControls = {
|
|
119
|
+
[key: string]: FormAbstract;
|
|
120
|
+
} | FormAbstract[];
|
|
121
|
+
type FormCollection = FormAbstractCollection<FormControls>;
|
|
122
|
+
type FormActivator = boolean | ((value: any, rootValue: any, control?: FormAbstract, root?: FormCollection) => boolean | Promise<boolean>);
|
|
123
|
+
type FormValidator = (value: any, rootValue: any, control?: FormAbstract, root?: FormCollection) => null | ValidationError;
|
|
124
|
+
type FormAsyncValidator = (value: any, rootValue: any, control?: FormAbstract, root?: FormCollection) => Promise<null | ValidationError>;
|
|
125
|
+
type FormFlags = {
|
|
126
|
+
[key: string]: boolean;
|
|
127
|
+
};
|
|
128
|
+
type FormErrors = {
|
|
129
|
+
[key: string]: any;
|
|
130
|
+
};
|
|
131
|
+
type FormValidationError = {
|
|
132
|
+
key: string;
|
|
133
|
+
value: any;
|
|
134
|
+
};
|
|
135
|
+
type FormValidationErrors = FormValidationError[];
|
|
136
|
+
type FormState<T> = {
|
|
137
|
+
value: T | null;
|
|
138
|
+
flags: FormFlags;
|
|
139
|
+
errors: FormValidationErrors;
|
|
140
|
+
};
|
|
141
|
+
type ControlType = 'group' | 'array' | string;
|
|
142
|
+
type IFormBuilderControlSchema = {
|
|
143
|
+
schema: ControlType;
|
|
144
|
+
name?: string;
|
|
145
|
+
label?: string;
|
|
146
|
+
value?: string;
|
|
147
|
+
placeholder?: string;
|
|
148
|
+
required?: FormActivator;
|
|
149
|
+
hidden?: FormActivator;
|
|
150
|
+
disabled?: FormActivator;
|
|
151
|
+
readonly?: FormActivator;
|
|
152
|
+
options?: IOption[];
|
|
153
|
+
optionsExtra?: {
|
|
154
|
+
asEquatable: boolean;
|
|
155
|
+
};
|
|
156
|
+
validators?: FormValidator | FormValidator[];
|
|
157
|
+
children?: IFormBuilderSchema;
|
|
158
|
+
};
|
|
159
|
+
type IFormBuilderGroupSchema = {
|
|
160
|
+
[key: string]: IFormBuilderControlSchema;
|
|
161
|
+
};
|
|
162
|
+
type IFormBuilderArraySchema = IFormBuilderControlSchema[];
|
|
163
|
+
type IFormBuilderGroupValues = {
|
|
164
|
+
[key: string]: FormGroup | FormArray | FormControl;
|
|
165
|
+
};
|
|
166
|
+
type IFormBuilderSchema = IFormBuilderGroupSchema | IFormBuilderArraySchema;
|
|
167
|
+
type StateValue = StateValue[] | {
|
|
168
|
+
[key: string]: StateValue;
|
|
169
|
+
} | number | string | boolean | null | undefined;
|
|
170
|
+
|
|
171
|
+
declare class FormAbstract extends EventEmitter {
|
|
172
|
+
errors_: ValidationError;
|
|
173
|
+
value_: any;
|
|
174
|
+
validators_: FormValidator[];
|
|
175
|
+
state_: any;
|
|
176
|
+
name?: string | number;
|
|
177
|
+
parent?: FormCollection;
|
|
178
|
+
schema: ControlType;
|
|
179
|
+
options?: IOption[];
|
|
180
|
+
optionsExtra?: {
|
|
181
|
+
asEquatable: boolean;
|
|
182
|
+
};
|
|
183
|
+
protected initialOptions_?: FormOptions;
|
|
184
|
+
private markAsDirty_;
|
|
185
|
+
constructor(value: any, validators?: (FormValidator | FormValidator[]));
|
|
186
|
+
protected setInitialOptions(options?: FormOptions): void;
|
|
187
|
+
protected checkAsyncState_(root?: FormCollection): Promise<boolean>;
|
|
188
|
+
protected checkAsyncPropState_(key: string, option?: FormActivator, root?: FormCollection): Promise<boolean>;
|
|
189
|
+
protected revalidate_(): Promise<void>;
|
|
190
|
+
protected validate_(root?: FormCollection): Promise<void>;
|
|
191
|
+
validateAndChange_(root?: FormCollection): Promise<void>;
|
|
192
|
+
protected updateStateAndChange_(): Promise<void>;
|
|
193
|
+
protected change_(propagate?: boolean): void;
|
|
194
|
+
protected updateState_(): void;
|
|
195
|
+
reset(): void;
|
|
196
|
+
patch(value: any): void;
|
|
197
|
+
addValidators(...validators: FormValidator[]): void;
|
|
198
|
+
replaceValidators(...validators: FormValidator[]): void;
|
|
199
|
+
clearValidators(): void;
|
|
200
|
+
protected get path(): (string | number)[];
|
|
201
|
+
protected get root(): FormCollection | FormAbstract;
|
|
202
|
+
private label_?;
|
|
203
|
+
get label(): string;
|
|
204
|
+
set label(label: string);
|
|
205
|
+
private placeholder_?;
|
|
206
|
+
get placeholder(): string;
|
|
207
|
+
set placeholder(placeholder: string);
|
|
208
|
+
get validators(): FormValidator[];
|
|
209
|
+
set validators(validators: FormValidator[]);
|
|
210
|
+
get state(): any;
|
|
211
|
+
get errors(): ValidationError;
|
|
212
|
+
get invalid(): any;
|
|
213
|
+
get disabled(): any;
|
|
214
|
+
set disabled(disabled: any);
|
|
215
|
+
get hidden(): any;
|
|
216
|
+
set hidden(hidden: any);
|
|
217
|
+
get readonly(): any;
|
|
218
|
+
set readonly(readonly: any);
|
|
219
|
+
get dirty(): any;
|
|
220
|
+
set dirty(dirty: any);
|
|
221
|
+
get touched(): any;
|
|
222
|
+
set touched(touched: any);
|
|
223
|
+
get submitted(): any;
|
|
224
|
+
set submitted(submitted: any);
|
|
225
|
+
get valid(): any;
|
|
226
|
+
get enabled(): any;
|
|
227
|
+
get visible(): any;
|
|
228
|
+
get writeable(): any;
|
|
229
|
+
get pristine(): any;
|
|
230
|
+
get untouched(): any;
|
|
231
|
+
get unsubmitted(): any;
|
|
232
|
+
get value(): any;
|
|
233
|
+
set value(value: any);
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
declare function validValue(value: any): any;
|
|
237
|
+
declare function isThenable(result: any): any;
|
|
238
|
+
declare function mapErrors_(errors: FormErrors): FormValidationError[];
|
|
239
|
+
declare function deepCopy<T>(source: T): T;
|
|
240
|
+
declare function valueToString(value: IOption | IOption[] | IEquatable | IEquatable[] | null): string | string[] | undefined;
|
|
241
|
+
declare function stringToValue(value: string | string[] | undefined, options?: IOption[], optionsExtra?: {
|
|
242
|
+
asEquatable: boolean;
|
|
243
|
+
}): IOption | IOption[] | IEquatable | IEquatable[] | null;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* an email pattern validator
|
|
247
|
+
*/
|
|
248
|
+
declare function EmailValidator(): FormValidator;
|
|
249
|
+
|
|
250
|
+
/**
|
|
251
|
+
* an equality match validation on another field
|
|
252
|
+
*/
|
|
253
|
+
declare function MatchValidator(getOtherValue: (value: any, rootValue: any, control?: FormAbstract, root?: FormAbstract) => any): FormValidator;
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* a max string length validator
|
|
257
|
+
*/
|
|
258
|
+
declare function MaxLengthValidator(maxlength: number): FormValidator;
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* a max number value validator
|
|
262
|
+
*/
|
|
263
|
+
declare function MaxValidator(max: number): FormValidator;
|
|
264
|
+
|
|
265
|
+
/**
|
|
266
|
+
* a min string length validator
|
|
267
|
+
*/
|
|
268
|
+
declare function MinLengthValidator(minlength: number): FormValidator;
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* a min number value validator
|
|
272
|
+
*/
|
|
273
|
+
declare function MinValidator(min: number): FormValidator;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* a null validator
|
|
277
|
+
*/
|
|
278
|
+
declare function NullValidator(): FormValidator;
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* a regex pattern validator
|
|
282
|
+
*/
|
|
283
|
+
declare function PatternValidator(pattern: string | RegExp): FormValidator;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* a required dependant on another field
|
|
287
|
+
*/
|
|
288
|
+
declare function RequiredIfValidator(condition: (value: any, rootValue: any, control?: FormAbstract, root?: FormAbstract) => boolean): FormValidator;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* a required and true validator
|
|
292
|
+
*/
|
|
293
|
+
declare function RequiredTrueValidator(): FormValidator;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* a required validator
|
|
297
|
+
*/
|
|
298
|
+
declare function RequiredValidator(): FormValidator;
|
|
299
|
+
|
|
300
|
+
declare function useControl<T>(control: FormAbstract): [FormState<T>, (value: T | null) => void, () => void, () => void, FormAbstract];
|
|
301
|
+
|
|
302
|
+
declare function useForm<T, U extends (FormGroup | FormArray)>(factory: () => U, deps?: DependencyList): [FormState<T>, (value: any) => void, () => void, () => void, U];
|
|
303
|
+
|
|
304
|
+
declare function useFormBuilder<T, U extends (FormGroup | FormArray)>(schema: IFormBuilderSchema, deps?: DependencyList): [FormState<T>, (value: Partial<T>) => void, () => void, () => void, U];
|
|
305
|
+
|
|
306
|
+
export { ControlType, EmailValidator, FormAbstract, FormAbstractCollection, FormActivator, FormArray, FormAsyncValidator, FormCollection, FormControl, FormControls, FormErrors, FormFlags, FormGroup, FormOptions, FormState, FormValidationError, FormValidationErrors, FormValidator, IControlParam, IFormBuilderArraySchema, IFormBuilderControlSchema, IFormBuilderGroupSchema, IFormBuilderGroupValues, IFormBuilderSchema, IFormOption, MatchValidator, MaxLengthValidator, MaxValidator, MinLengthValidator, MinValidator, NullValidator, PatternValidator, RequiredIfValidator, RequiredTrueValidator, RequiredValidator, StateValue, ValidationError, deepCopy, formArray, formControl, formGroup, isThenable, mapErrors_, stringToValue, useControl, useForm, useFormBuilder, validValue, valueToString };
|