-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfjson.d.ts
186 lines (163 loc) · 3.68 KB
/
fjson.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
type FJSON = {
version: 1;
fileds: Field[];
};
type Field =
| CheckboxField
| ColorFiled
| CustomFiled
| DateFiled
| EmailField
| FileField
| ImageField
| MonthField
| NumberField
| PasswordField
| RadioField
| RangeField
| TelField
| TextField
| TextAreaField
| ToggleField
| TimeField
| SelectField
| UrlField;
type Validator = (value: unknown) => boolean;
interface CommonFiled {
type: string;
name: string;
label?: string;
validations?: Record<string, ValidatorSettings<unknown>>;
title?: string;
placeholder?: string;
required?: boolean; // default: false
disabled?: boolean; // default: false
readOnly?: boolean; // default: false
}
interface ValidatorSettings<T> {
arguments: Array<T>;
errorMessage?: string;
}
interface CheckboxField extends CommonFiled {
type: 'checkbox';
}
interface ColorFiled extends CommonFiled {
type: 'color';
}
interface CustomFiled extends CommonFiled {
type: 'custom';
}
interface DateFiled extends CommonFiled {
type: 'date';
validations?: {
min?: ValidatorSettings<number>;
max?: ValidatorSettings<number>;
};
}
interface EmailField extends CommonFiled {
type: 'email';
validations?: {
minLength?: ValidatorSettings<number>;
maxLenght?: ValidatorSettings<number>;
};
}
interface FileField extends CommonFiled {
type: 'file';
validations?: {
maxSizeKb?: ValidatorSettings<number>;
allowedFormats?: ValidatorSettings<string>;
maxFiles?: ValidatorSettings<number>;
};
}
interface ImageField extends CommonFiled {
type: 'image';
validations?: {
maxSizeKb?: ValidatorSettings<number>;
allowedFormats?: ValidatorSettings<string>;
maxFiles?: ValidatorSettings<number>;
};
}
interface MonthField extends CommonFiled {
type: 'month';
}
interface NumberField extends CommonFiled {
type: 'number';
validations?: {
min: ValidatorSettings<number>;
max: ValidatorSettings<number>;
};
}
interface PasswordField extends CommonFiled {
type: 'password';
validations?: {
minLength?: ValidatorSettings<number>;
maxLenght?: ValidatorSettings<number>;
haveSymbols?: ValidatorSettings<boolean>;
haveCapitalLetters?: ValidatorSettings<boolean>;
haveNumbers?: ValidatorSettings<boolean>;
};
}
interface RadioField extends CommonFiled {
type: 'radio';
options: Array<{
name: string;
label: string;
}>;
}
interface RangeField extends CommonFiled {
type: 'range';
validations?: {
min?: ValidatorSettings<number>;
max?: ValidatorSettings<number>;
};
}
interface TelField extends CommonFiled {
type: 'tel';
validations?: {
minLength?: ValidatorSettings<number>;
maxLenght?: ValidatorSettings<number>;
};
}
interface TextField extends CommonFiled {
type: 'text';
validations?: {
minLength?: ValidatorSettings<number>;
maxLenght?: ValidatorSettings<number>;
};
}
interface TextAreaField extends CommonFiled {
type: 'text_area';
validations?: {
minLength?: ValidatorSettings<number>;
maxLenght?: ValidatorSettings<number>;
};
}
interface ToggleField extends CommonFiled {
type: 'toggle';
}
interface TimeField extends CommonFiled {
type: 'time';
validations?: {
min: ValidatorSettings<number>;
max: ValidatorSettings<number>;
};
}
interface UrlField extends CommonFiled {
type: 'url';
validations?: {
minLength?: ValidatorSettings<number>;
maxLenght?: ValidatorSettings<number>;
};
}
interface SelectField extends CommonFiled {
type: 'select';
options: Array<{
name: string;
label: string;
}>;
multiselect?: boolean; // default: false
validations?: {
minLength?: ValidatorSettings<number>;
maxLenght?: ValidatorSettings<number>;
};
}