@rolster/forms 2.6.4 → 2.7.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/dist/cjs/arguments.js +27 -25
- package/dist/cjs/arguments.js.map +1 -1
- package/dist/cjs/index.js +205 -171
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/arguments.js +27 -25
- package/dist/es/arguments.js.map +1 -1
- package/dist/es/index.js +204 -172
- package/dist/es/index.js.map +1 -1
- package/dist/esm/arguments.d.ts +4 -4
- package/dist/esm/arguments.js +27 -25
- package/dist/esm/arguments.js.map +1 -1
- package/dist/esm/form-array/arguments.d.ts +6 -0
- package/dist/esm/form-array/arguments.js +2 -0
- package/dist/esm/form-array/arguments.js.map +1 -0
- package/dist/esm/form-array/form-array-control.d.ts +3 -3
- package/dist/esm/form-array/form-array-list.d.ts +14 -0
- package/dist/esm/form-array/form-array-list.js +32 -0
- package/dist/esm/form-array/form-array-list.js.map +1 -0
- package/dist/esm/form-array/form-array.d.ts +2 -2
- package/dist/esm/form-array/index.d.ts +3 -2
- package/dist/esm/form-array/index.js +2 -1
- package/dist/esm/form-array/index.js.map +1 -1
- package/dist/esm/form-control.d.ts +16 -15
- package/dist/esm/form-control.js +2 -2
- package/dist/esm/form-control.js.map +1 -1
- package/dist/esm/form-group.d.ts +2 -2
- package/dist/esm/helpers.d.ts +2 -2
- package/dist/esm/helpers.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types.d.ts +18 -11
- package/package.json +1 -1
package/dist/cjs/arguments.js
CHANGED
|
@@ -2,48 +2,50 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
function
|
|
6
|
-
return (typeof
|
|
5
|
+
function itIsControlOptions(options) {
|
|
6
|
+
return (typeof options === 'object' &&
|
|
7
|
+
('value' in options || 'validators' in options));
|
|
7
8
|
}
|
|
8
|
-
function
|
|
9
|
-
return typeof
|
|
9
|
+
function itIsGroupOptions(options) {
|
|
10
|
+
return typeof options === 'object' && 'controls' in options;
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
-
return (typeof
|
|
12
|
+
function itIsArrayOptions(options) {
|
|
13
|
+
return (typeof options === 'object' &&
|
|
14
|
+
('groups' in options || 'validators' in options));
|
|
13
15
|
}
|
|
14
|
-
function createFormControlOptions(...
|
|
15
|
-
const [
|
|
16
|
-
if (!
|
|
17
|
-
return { value:
|
|
16
|
+
function createFormControlOptions(...controlOptions) {
|
|
17
|
+
const [options, validators] = controlOptions;
|
|
18
|
+
if (!options) {
|
|
19
|
+
return { value: options, validators };
|
|
18
20
|
}
|
|
19
|
-
if (!validators &&
|
|
20
|
-
return
|
|
21
|
+
if (!validators && itIsControlOptions(options)) {
|
|
22
|
+
return options;
|
|
21
23
|
}
|
|
22
24
|
return {
|
|
23
|
-
value:
|
|
25
|
+
value: options,
|
|
24
26
|
validators
|
|
25
27
|
};
|
|
26
28
|
}
|
|
27
|
-
function createFormGroupOptions(...
|
|
28
|
-
const [
|
|
29
|
-
if (!validators &&
|
|
30
|
-
return
|
|
29
|
+
function createFormGroupOptions(...groupOptions) {
|
|
30
|
+
const [options, validators] = groupOptions;
|
|
31
|
+
if (!validators && itIsGroupOptions(options)) {
|
|
32
|
+
return options;
|
|
31
33
|
}
|
|
32
34
|
return {
|
|
33
|
-
controls:
|
|
35
|
+
controls: options,
|
|
34
36
|
validators
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
|
-
function createFormArrayOptions(...
|
|
38
|
-
const [
|
|
39
|
-
if (!
|
|
40
|
-
return { groups:
|
|
39
|
+
function createFormArrayOptions(...arrayOptions) {
|
|
40
|
+
const [options, validators] = arrayOptions;
|
|
41
|
+
if (!options) {
|
|
42
|
+
return { groups: options, validators };
|
|
41
43
|
}
|
|
42
|
-
if (!validators &&
|
|
43
|
-
return
|
|
44
|
+
if (!validators && itIsArrayOptions(options)) {
|
|
45
|
+
return options;
|
|
44
46
|
}
|
|
45
47
|
return {
|
|
46
|
-
groups:
|
|
48
|
+
groups: options,
|
|
47
49
|
validators
|
|
48
50
|
};
|
|
49
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arguments.js","sources":["../esm/arguments.js"],"sourcesContent":["function
|
|
1
|
+
{"version":3,"file":"arguments.js","sources":["../esm/arguments.js"],"sourcesContent":["function itIsControlOptions(options) {\r\n return (typeof options === 'object' &&\r\n ('value' in options || 'validators' in options));\r\n}\r\nfunction itIsGroupOptions(options) {\r\n return typeof options === 'object' && 'controls' in options;\r\n}\r\nfunction itIsArrayOptions(options) {\r\n return (typeof options === 'object' &&\r\n ('groups' in options || 'validators' in options));\r\n}\r\nexport function createFormControlOptions(...controlOptions) {\r\n const [options, validators] = controlOptions;\r\n if (!options) {\r\n return { value: options, validators };\r\n }\r\n if (!validators && itIsControlOptions(options)) {\r\n return options;\r\n }\r\n return {\r\n value: options,\r\n validators\r\n };\r\n}\r\nexport function createFormGroupOptions(...groupOptions) {\r\n const [options, validators] = groupOptions;\r\n if (!validators && itIsGroupOptions(options)) {\r\n return options;\r\n }\r\n return {\r\n controls: options,\r\n validators\r\n };\r\n}\r\nexport function createFormArrayOptions(...arrayOptions) {\r\n const [options, validators] = arrayOptions;\r\n if (!options) {\r\n return { groups: options, validators };\r\n }\r\n if (!validators && itIsArrayOptions(options)) {\r\n return options;\r\n }\r\n return {\r\n groups: options,\r\n validators\r\n };\r\n}\r\n//# sourceMappingURL=arguments.js.map"],"names":[],"mappings":";;;;AAAA,SAAS,kBAAkB,CAAC,OAAO,EAAE;AACrC,IAAI,QAAQ,OAAO,OAAO,KAAK,QAAQ;AACvC,SAAS,OAAO,IAAI,OAAO,IAAI,YAAY,IAAI,OAAO,CAAC,EAAE;AACzD,CAAC;AACD,SAAS,gBAAgB,CAAC,OAAO,EAAE;AACnC,IAAI,OAAO,OAAO,OAAO,KAAK,QAAQ,IAAI,UAAU,IAAI,OAAO,CAAC;AAChE,CAAC;AACD,SAAS,gBAAgB,CAAC,OAAO,EAAE;AACnC,IAAI,QAAQ,OAAO,OAAO,KAAK,QAAQ;AACvC,SAAS,QAAQ,IAAI,OAAO,IAAI,YAAY,IAAI,OAAO,CAAC,EAAE;AAC1D,CAAC;AACM,SAAS,wBAAwB,CAAC,GAAG,cAAc,EAAE;AAC5D,IAAI,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,cAAc,CAAC;AACjD,IAAI,IAAI,CAAC,OAAO,EAAE;AAClB,QAAQ,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AAC9C,KAAK;AACL,IAAI,IAAI,CAAC,UAAU,IAAI,kBAAkB,CAAC,OAAO,CAAC,EAAE;AACpD,QAAQ,OAAO,OAAO,CAAC;AACvB,KAAK;AACL,IAAI,OAAO;AACX,QAAQ,KAAK,EAAE,OAAO;AACtB,QAAQ,UAAU;AAClB,KAAK,CAAC;AACN,CAAC;AACM,SAAS,sBAAsB,CAAC,GAAG,YAAY,EAAE;AACxD,IAAI,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,YAAY,CAAC;AAC/C,IAAI,IAAI,CAAC,UAAU,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE;AAClD,QAAQ,OAAO,OAAO,CAAC;AACvB,KAAK;AACL,IAAI,OAAO;AACX,QAAQ,QAAQ,EAAE,OAAO;AACzB,QAAQ,UAAU;AAClB,KAAK,CAAC;AACN,CAAC;AACM,SAAS,sBAAsB,CAAC,GAAG,YAAY,EAAE;AACxD,IAAI,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,YAAY,CAAC;AAC/C,IAAI,IAAI,CAAC,OAAO,EAAE;AAClB,QAAQ,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,CAAC;AAC/C,KAAK;AACL,IAAI,IAAI,CAAC,UAAU,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE;AAClD,QAAQ,OAAO,OAAO,CAAC;AACvB,KAAK;AACL,IAAI,OAAO;AACX,QAAQ,MAAM,EAAE,OAAO;AACvB,QAAQ,UAAU;AAClB,KAAK,CAAC;AACN;;;;;;"}
|
package/dist/cjs/index.js
CHANGED
|
@@ -2,51 +2,53 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var commons = require('@rolster/commons');
|
|
6
5
|
var uuid = require('uuid');
|
|
6
|
+
var commons = require('@rolster/commons');
|
|
7
7
|
|
|
8
|
-
function
|
|
9
|
-
return (typeof
|
|
8
|
+
function itIsControlOptions(options) {
|
|
9
|
+
return (typeof options === 'object' &&
|
|
10
|
+
('value' in options || 'validators' in options));
|
|
10
11
|
}
|
|
11
|
-
function
|
|
12
|
-
return typeof
|
|
12
|
+
function itIsGroupOptions(options) {
|
|
13
|
+
return typeof options === 'object' && 'controls' in options;
|
|
13
14
|
}
|
|
14
|
-
function
|
|
15
|
-
return (typeof
|
|
15
|
+
function itIsArrayOptions(options) {
|
|
16
|
+
return (typeof options === 'object' &&
|
|
17
|
+
('groups' in options || 'validators' in options));
|
|
16
18
|
}
|
|
17
|
-
function createFormControlOptions(...
|
|
18
|
-
const [
|
|
19
|
-
if (!
|
|
20
|
-
return { value:
|
|
19
|
+
function createFormControlOptions(...controlOptions) {
|
|
20
|
+
const [options, validators] = controlOptions;
|
|
21
|
+
if (!options) {
|
|
22
|
+
return { value: options, validators };
|
|
21
23
|
}
|
|
22
|
-
if (!validators &&
|
|
23
|
-
return
|
|
24
|
+
if (!validators && itIsControlOptions(options)) {
|
|
25
|
+
return options;
|
|
24
26
|
}
|
|
25
27
|
return {
|
|
26
|
-
value:
|
|
28
|
+
value: options,
|
|
27
29
|
validators
|
|
28
30
|
};
|
|
29
31
|
}
|
|
30
|
-
function createFormGroupOptions(...
|
|
31
|
-
const [
|
|
32
|
-
if (!validators &&
|
|
33
|
-
return
|
|
32
|
+
function createFormGroupOptions(...groupOptions) {
|
|
33
|
+
const [options, validators] = groupOptions;
|
|
34
|
+
if (!validators && itIsGroupOptions(options)) {
|
|
35
|
+
return options;
|
|
34
36
|
}
|
|
35
37
|
return {
|
|
36
|
-
controls:
|
|
38
|
+
controls: options,
|
|
37
39
|
validators
|
|
38
40
|
};
|
|
39
41
|
}
|
|
40
|
-
function createFormArrayOptions(...
|
|
41
|
-
const [
|
|
42
|
-
if (!
|
|
43
|
-
return { groups:
|
|
42
|
+
function createFormArrayOptions(...arrayOptions) {
|
|
43
|
+
const [options, validators] = arrayOptions;
|
|
44
|
+
if (!options) {
|
|
45
|
+
return { groups: options, validators };
|
|
44
46
|
}
|
|
45
|
-
if (!validators &&
|
|
46
|
-
return
|
|
47
|
+
if (!validators && itIsArrayOptions(options)) {
|
|
48
|
+
return options;
|
|
47
49
|
}
|
|
48
50
|
return {
|
|
49
|
-
groups:
|
|
51
|
+
groups: options,
|
|
50
52
|
validators
|
|
51
53
|
};
|
|
52
54
|
}
|
|
@@ -106,158 +108,15 @@ function someErrors(errors, keys) {
|
|
|
106
108
|
return reduceErrors(errors).some((key) => keys.includes(key));
|
|
107
109
|
}
|
|
108
110
|
|
|
109
|
-
class FormArray {
|
|
110
|
-
constructor(arrayOptions, arrayValidators) {
|
|
111
|
-
this.currentGroups = [];
|
|
112
|
-
this.currentValid = true;
|
|
113
|
-
this.currentDisabled = false;
|
|
114
|
-
this.currentErrors = [];
|
|
115
|
-
const { groups, validators } = createFormArrayOptions(arrayOptions, arrayValidators);
|
|
116
|
-
this.unsusbcriptions = new Map();
|
|
117
|
-
this.initialState = groups;
|
|
118
|
-
this.validators = validators;
|
|
119
|
-
this.refresh(this.initialState);
|
|
120
|
-
this.observable = commons.observable(this.value);
|
|
121
|
-
groups?.forEach((group) => {
|
|
122
|
-
this.subscription(group);
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
get groups() {
|
|
126
|
-
return this.currentGroups;
|
|
127
|
-
}
|
|
128
|
-
get controls() {
|
|
129
|
-
return this.groups.map(({ controls }) => controls);
|
|
130
|
-
}
|
|
131
|
-
get touched() {
|
|
132
|
-
return groupPartialChecked(this.groups, 'touched');
|
|
133
|
-
}
|
|
134
|
-
get touchedAll() {
|
|
135
|
-
return groupAllChecked(this.groups, 'touchedAll');
|
|
136
|
-
}
|
|
137
|
-
get untouched() {
|
|
138
|
-
return !this.touched;
|
|
139
|
-
}
|
|
140
|
-
get untouchedAll() {
|
|
141
|
-
return !this.touchedAll;
|
|
142
|
-
}
|
|
143
|
-
get dirty() {
|
|
144
|
-
return groupPartialChecked(this.groups, 'dirty');
|
|
145
|
-
}
|
|
146
|
-
get dirtyAll() {
|
|
147
|
-
return groupAllChecked(this.groups, 'dirtyAll');
|
|
148
|
-
}
|
|
149
|
-
get pristine() {
|
|
150
|
-
return !this.dirty;
|
|
151
|
-
}
|
|
152
|
-
get pristineAll() {
|
|
153
|
-
return !this.dirtyAll;
|
|
154
|
-
}
|
|
155
|
-
get disabled() {
|
|
156
|
-
return this.currentDisabled;
|
|
157
|
-
}
|
|
158
|
-
get enabled() {
|
|
159
|
-
return !this.currentDisabled;
|
|
160
|
-
}
|
|
161
|
-
get valid() {
|
|
162
|
-
return this.currentValid && groupAllChecked(this.groups, 'valid');
|
|
163
|
-
}
|
|
164
|
-
get invalid() {
|
|
165
|
-
return !this.currentValid;
|
|
166
|
-
}
|
|
167
|
-
get value() {
|
|
168
|
-
return this.groups.map(({ value: state }) => state);
|
|
169
|
-
}
|
|
170
|
-
get error() {
|
|
171
|
-
return this.currentError;
|
|
172
|
-
}
|
|
173
|
-
get errors() {
|
|
174
|
-
return this.currentErrors;
|
|
175
|
-
}
|
|
176
|
-
get wrong() {
|
|
177
|
-
return this.touched && this.invalid;
|
|
178
|
-
}
|
|
179
|
-
hasError(key) {
|
|
180
|
-
return hasError(this.errors, key);
|
|
181
|
-
}
|
|
182
|
-
someErrors(keys) {
|
|
183
|
-
return someErrors(this.errors, keys);
|
|
184
|
-
}
|
|
185
|
-
reset() {
|
|
186
|
-
this.refresh(this.initialState);
|
|
187
|
-
}
|
|
188
|
-
disable() {
|
|
189
|
-
this.currentDisabled = true;
|
|
190
|
-
}
|
|
191
|
-
enable() {
|
|
192
|
-
this.currentDisabled = false;
|
|
193
|
-
}
|
|
194
|
-
push(group) {
|
|
195
|
-
this.subscription(group);
|
|
196
|
-
this.refresh([...this.groups, group]);
|
|
197
|
-
}
|
|
198
|
-
merge(groups) {
|
|
199
|
-
groups.forEach((group) => {
|
|
200
|
-
this.subscription(group);
|
|
201
|
-
});
|
|
202
|
-
this.refresh([...this.groups, ...groups]);
|
|
203
|
-
}
|
|
204
|
-
set(groups) {
|
|
205
|
-
this.currentGroups.forEach(({ uuid }) => {
|
|
206
|
-
this.unsusbcriptions.delete(uuid);
|
|
207
|
-
});
|
|
208
|
-
groups.forEach((group) => {
|
|
209
|
-
this.subscription(group);
|
|
210
|
-
});
|
|
211
|
-
this.refresh(groups); // Update groups
|
|
212
|
-
}
|
|
213
|
-
remove({ uuid }) {
|
|
214
|
-
this.refresh(this.groups.filter((group) => group.uuid !== uuid));
|
|
215
|
-
}
|
|
216
|
-
setValidators(validators) {
|
|
217
|
-
this.validators = validators;
|
|
218
|
-
this.updateValidityStatus(this.groups, validators);
|
|
219
|
-
}
|
|
220
|
-
subscribe(subscriber) {
|
|
221
|
-
return this.observable.subscribe(subscriber);
|
|
222
|
-
}
|
|
223
|
-
subscription(group) {
|
|
224
|
-
const unsusbcription = group.subscribe(() => {
|
|
225
|
-
this.updateValidityStatus(this.groups, this.validators);
|
|
226
|
-
});
|
|
227
|
-
this.unsusbcriptions.set(group.uuid, unsusbcription);
|
|
228
|
-
}
|
|
229
|
-
updateValidityStatus(groups, validators) {
|
|
230
|
-
if (validators) {
|
|
231
|
-
const errors = arrayIsValid({ groups, validators });
|
|
232
|
-
this.currentErrors = errors;
|
|
233
|
-
this.currentError = errors[0];
|
|
234
|
-
this.currentValid = errors.length === 0;
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
this.currentValid = true;
|
|
238
|
-
this.currentErrors = [];
|
|
239
|
-
this.currentError = undefined;
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
refresh(newGroups) {
|
|
243
|
-
const groups = newGroups || [];
|
|
244
|
-
this.currentGroups = groups;
|
|
245
|
-
this.updateValidityStatus(groups, this.validators);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
function formArray(options, validators) {
|
|
249
|
-
return new FormArray(createFormArrayOptions(options, validators));
|
|
250
|
-
}
|
|
251
|
-
|
|
252
111
|
class FormControl {
|
|
253
|
-
constructor(
|
|
112
|
+
constructor(controlOptions, controlValidators) {
|
|
254
113
|
this.currentFocused = false;
|
|
255
114
|
this.currentTouched = false;
|
|
256
115
|
this.currentDirty = false;
|
|
257
116
|
this.currentDisabled = false;
|
|
258
117
|
this.currentValid = true;
|
|
259
118
|
this.currentErrors = [];
|
|
260
|
-
const { value, validators } = createFormControlOptions(
|
|
119
|
+
const { value, validators } = createFormControlOptions(controlOptions, controlValidators);
|
|
261
120
|
this.observable = commons.observable(value);
|
|
262
121
|
this.initialValue = value;
|
|
263
122
|
this.validators = validators;
|
|
@@ -480,14 +339,189 @@ function formArrayGroup(options, validators) {
|
|
|
480
339
|
return new FormArrayGroup(createFormGroupOptions(options, validators));
|
|
481
340
|
}
|
|
482
341
|
|
|
342
|
+
class FormArrayList extends FormControl {
|
|
343
|
+
constructor(valueToControls, value, validators) {
|
|
344
|
+
super(value || [], validators);
|
|
345
|
+
this.valueToControls = valueToControls;
|
|
346
|
+
this.currentControls = (value || []).map((value) => this.createControls(value));
|
|
347
|
+
this.uuid = uuid.v4();
|
|
348
|
+
}
|
|
349
|
+
get controls() {
|
|
350
|
+
return this.currentControls;
|
|
351
|
+
}
|
|
352
|
+
setValue(values) {
|
|
353
|
+
this.currentControls = values.map((value) => this.createControls(value));
|
|
354
|
+
super.setValue(values);
|
|
355
|
+
}
|
|
356
|
+
createControls(value) {
|
|
357
|
+
const controls = this.valueToControls(value);
|
|
358
|
+
Object.values(controls).forEach((control) => {
|
|
359
|
+
control.subscribe(() => {
|
|
360
|
+
const { value, validators } = this;
|
|
361
|
+
this.updateValueAndValidity(value, validators);
|
|
362
|
+
this.observable.next(value);
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
return controls;
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
function formArrayList(valueToControl, value, validators) {
|
|
369
|
+
return new FormArrayList(valueToControl, value, validators);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
class FormArray {
|
|
373
|
+
constructor(arrayOptions, arrayValidators) {
|
|
374
|
+
this.currentGroups = [];
|
|
375
|
+
this.currentValid = true;
|
|
376
|
+
this.currentDisabled = false;
|
|
377
|
+
this.currentErrors = [];
|
|
378
|
+
const { groups, validators } = createFormArrayOptions(arrayOptions, arrayValidators);
|
|
379
|
+
this.unsusbcriptions = new Map();
|
|
380
|
+
this.initialState = groups;
|
|
381
|
+
this.validators = validators;
|
|
382
|
+
this.refresh(this.initialState);
|
|
383
|
+
this.observable = commons.observable(this.value);
|
|
384
|
+
groups?.forEach((group) => {
|
|
385
|
+
this.subscription(group);
|
|
386
|
+
});
|
|
387
|
+
}
|
|
388
|
+
get groups() {
|
|
389
|
+
return this.currentGroups;
|
|
390
|
+
}
|
|
391
|
+
get controls() {
|
|
392
|
+
return this.groups.map(({ controls }) => controls);
|
|
393
|
+
}
|
|
394
|
+
get touched() {
|
|
395
|
+
return groupPartialChecked(this.groups, 'touched');
|
|
396
|
+
}
|
|
397
|
+
get touchedAll() {
|
|
398
|
+
return groupAllChecked(this.groups, 'touchedAll');
|
|
399
|
+
}
|
|
400
|
+
get untouched() {
|
|
401
|
+
return !this.touched;
|
|
402
|
+
}
|
|
403
|
+
get untouchedAll() {
|
|
404
|
+
return !this.touchedAll;
|
|
405
|
+
}
|
|
406
|
+
get dirty() {
|
|
407
|
+
return groupPartialChecked(this.groups, 'dirty');
|
|
408
|
+
}
|
|
409
|
+
get dirtyAll() {
|
|
410
|
+
return groupAllChecked(this.groups, 'dirtyAll');
|
|
411
|
+
}
|
|
412
|
+
get pristine() {
|
|
413
|
+
return !this.dirty;
|
|
414
|
+
}
|
|
415
|
+
get pristineAll() {
|
|
416
|
+
return !this.dirtyAll;
|
|
417
|
+
}
|
|
418
|
+
get disabled() {
|
|
419
|
+
return this.currentDisabled;
|
|
420
|
+
}
|
|
421
|
+
get enabled() {
|
|
422
|
+
return !this.currentDisabled;
|
|
423
|
+
}
|
|
424
|
+
get valid() {
|
|
425
|
+
return this.currentValid && groupAllChecked(this.groups, 'valid');
|
|
426
|
+
}
|
|
427
|
+
get invalid() {
|
|
428
|
+
return !this.currentValid;
|
|
429
|
+
}
|
|
430
|
+
get value() {
|
|
431
|
+
return this.groups.map(({ value: state }) => state);
|
|
432
|
+
}
|
|
433
|
+
get error() {
|
|
434
|
+
return this.currentError;
|
|
435
|
+
}
|
|
436
|
+
get errors() {
|
|
437
|
+
return this.currentErrors;
|
|
438
|
+
}
|
|
439
|
+
get wrong() {
|
|
440
|
+
return this.touched && this.invalid;
|
|
441
|
+
}
|
|
442
|
+
hasError(key) {
|
|
443
|
+
return hasError(this.errors, key);
|
|
444
|
+
}
|
|
445
|
+
someErrors(keys) {
|
|
446
|
+
return someErrors(this.errors, keys);
|
|
447
|
+
}
|
|
448
|
+
reset() {
|
|
449
|
+
this.refresh(this.initialState);
|
|
450
|
+
}
|
|
451
|
+
disable() {
|
|
452
|
+
this.currentDisabled = true;
|
|
453
|
+
}
|
|
454
|
+
enable() {
|
|
455
|
+
this.currentDisabled = false;
|
|
456
|
+
}
|
|
457
|
+
push(group) {
|
|
458
|
+
this.subscription(group);
|
|
459
|
+
this.refresh([...this.groups, group]);
|
|
460
|
+
}
|
|
461
|
+
merge(groups) {
|
|
462
|
+
groups.forEach((group) => {
|
|
463
|
+
this.subscription(group);
|
|
464
|
+
});
|
|
465
|
+
this.refresh([...this.groups, ...groups]);
|
|
466
|
+
}
|
|
467
|
+
set(groups) {
|
|
468
|
+
this.currentGroups.forEach(({ uuid }) => {
|
|
469
|
+
this.unsusbcriptions.delete(uuid);
|
|
470
|
+
});
|
|
471
|
+
groups.forEach((group) => {
|
|
472
|
+
this.subscription(group);
|
|
473
|
+
});
|
|
474
|
+
this.refresh(groups); // Update groups
|
|
475
|
+
}
|
|
476
|
+
remove({ uuid }) {
|
|
477
|
+
this.refresh(this.groups.filter((group) => group.uuid !== uuid));
|
|
478
|
+
}
|
|
479
|
+
setValidators(validators) {
|
|
480
|
+
this.validators = validators;
|
|
481
|
+
this.updateValidityStatus(this.groups, validators);
|
|
482
|
+
}
|
|
483
|
+
subscribe(subscriber) {
|
|
484
|
+
return this.observable.subscribe(subscriber);
|
|
485
|
+
}
|
|
486
|
+
subscription(group) {
|
|
487
|
+
const unsusbcription = group.subscribe(() => {
|
|
488
|
+
this.updateValidityStatus(this.groups, this.validators);
|
|
489
|
+
});
|
|
490
|
+
this.unsusbcriptions.set(group.uuid, unsusbcription);
|
|
491
|
+
}
|
|
492
|
+
updateValidityStatus(groups, validators) {
|
|
493
|
+
if (validators) {
|
|
494
|
+
const errors = arrayIsValid({ groups, validators });
|
|
495
|
+
this.currentErrors = errors;
|
|
496
|
+
this.currentError = errors[0];
|
|
497
|
+
this.currentValid = errors.length === 0;
|
|
498
|
+
}
|
|
499
|
+
else {
|
|
500
|
+
this.currentValid = true;
|
|
501
|
+
this.currentErrors = [];
|
|
502
|
+
this.currentError = undefined;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
refresh(newGroups) {
|
|
506
|
+
const groups = newGroups || [];
|
|
507
|
+
this.currentGroups = groups;
|
|
508
|
+
this.updateValidityStatus(groups, this.validators);
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
function formArray(options, validators) {
|
|
512
|
+
return new FormArray(createFormArrayOptions(options, validators));
|
|
513
|
+
}
|
|
514
|
+
|
|
483
515
|
exports.FormArray = FormArray;
|
|
484
516
|
exports.FormArrayControl = FormArrayControl;
|
|
485
517
|
exports.FormArrayGroup = FormArrayGroup;
|
|
518
|
+
exports.FormArrayList = FormArrayList;
|
|
486
519
|
exports.FormControl = FormControl;
|
|
487
520
|
exports.FormGroup = FormGroup;
|
|
488
521
|
exports.formArray = formArray;
|
|
489
522
|
exports.formArrayControl = formArrayControl;
|
|
490
523
|
exports.formArrayGroup = formArrayGroup;
|
|
524
|
+
exports.formArrayList = formArrayList;
|
|
491
525
|
exports.formControl = formControl;
|
|
492
526
|
exports.formGroup = formGroup;
|
|
493
527
|
//# sourceMappingURL=index.js.map
|