@reactables/forms 1.3.0-beta.3 → 2.0.0-beta.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/Helpers/addAsyncValidationEffects.d.ts +9 -6
- package/dist/Helpers/buildFormState.d.ts +6 -6
- package/dist/Helpers/buildHub2Source.d.ts +4 -4
- package/dist/Helpers/controlRefCheck.d.ts +5 -5
- package/dist/Helpers/controlRefCheck.test.d.ts +1 -1
- package/dist/Helpers/generateKey.d.ts +1 -1
- package/dist/Helpers/getAncestorControls.d.ts +3 -3
- package/dist/Helpers/getAncestorControls.test.d.ts +1 -1
- package/dist/Helpers/getArrayItems.d.ts +3 -3
- package/dist/Helpers/getArrayItems.test.d.ts +1 -1
- package/dist/Helpers/getControl.d.ts +3 -3
- package/dist/Helpers/getControlBranch.d.ts +3 -3
- package/dist/Helpers/getControlBranch.test.d.ts +1 -1
- package/dist/Helpers/getDescendantControls.d.ts +3 -3
- package/dist/Helpers/getDescendantControls.test.d.ts +1 -1
- package/dist/Helpers/getFormKey.d.ts +2 -2
- package/dist/Helpers/getValueFromControlConfig.d.ts +2 -2
- package/dist/Helpers/getValueFromControlConfig.test.d.ts +1 -1
- package/dist/Helpers/index.d.ts +4 -4
- package/dist/Helpers/isChildRef.d.ts +2 -2
- package/dist/Helpers/reverseObjectKeys.d.ts +2 -2
- package/dist/Models/Configs.d.ts +22 -22
- package/dist/Models/ControlRef.d.ts +1 -1
- package/dist/Models/Controls.d.ts +48 -48
- package/dist/Models/FormErrors.d.ts +3 -3
- package/dist/Models/Payloads.d.ts +24 -24
- package/dist/Models/Validators.d.ts +5 -5
- package/dist/Models/index.d.ts +6 -6
- package/dist/Reducers/Hub1/addControl.d.ts +5 -5
- package/dist/Reducers/Hub1/getErrors.d.ts +4 -4
- package/dist/Reducers/Hub1/index.d.ts +6 -7
- package/dist/Reducers/Hub1/markControlAsPristine.d.ts +4 -4
- package/dist/Reducers/Hub1/markControlAsTouched.d.ts +4 -4
- package/dist/Reducers/Hub1/markControlAsUntouched.d.ts +4 -4
- package/dist/Reducers/Hub1/pushControl.d.ts +5 -5
- package/dist/Reducers/Hub1/removeControl.d.ts +5 -5
- package/dist/Reducers/Hub1/resetControl.d.ts +5 -5
- package/dist/Reducers/Hub1/updateAncestorPristineValues.d.ts +5 -5
- package/dist/Reducers/Hub1/updateAncestorValues.d.ts +6 -6
- package/dist/Reducers/Hub1/updateAncestorValuesAddControl.d.ts +6 -6
- package/dist/Reducers/Hub1/updateAncestorValuesRemoveControl.d.ts +6 -6
- package/dist/Reducers/Hub1/updateValues.d.ts +5 -5
- package/dist/Reducers/Hub2/asyncValidation.d.ts +4 -4
- package/dist/Reducers/Hub2/asyncValidationResponse.d.ts +4 -0
- package/dist/Reducers/Hub2/formChange.d.ts +3 -3
- package/dist/Reducers/Hub2/index.d.ts +3 -3
- package/dist/Reducers/Hub2/mergeBranchErrors.d.ts +3 -3
- package/dist/Reducers/Hub2/mergeControls.d.ts +5 -5
- package/dist/Reducers/Hub2/mergeErrors.d.ts +2 -2
- package/dist/Reducers/Hub2/mergeRemoveControl.d.ts +6 -6
- package/dist/Reducers/index.d.ts +2 -2
- package/dist/RxForm/RxForm.d.ts +103 -99
- package/dist/RxForm/Tests/addControl.test.d.ts +1 -1
- package/dist/RxForm/Tests/combinedTest.test.d.ts +1 -1
- package/dist/RxForm/Tests/customReducers.test.d.ts +1 -1
- package/dist/RxForm/Tests/initialization.test.d.ts +1 -1
- package/dist/RxForm/Tests/load.test.d.ts +1 -1
- package/dist/RxForm/Tests/markControlAsPristine.test.d.ts +1 -1
- package/dist/RxForm/Tests/markControlTouchStatus.test.d.ts +1 -1
- package/dist/RxForm/Tests/pushControl.test.d.ts +1 -1
- package/dist/RxForm/Tests/removeControl.test.d.ts +1 -1
- package/dist/RxForm/Tests/resetControl.test.d.ts +1 -1
- package/dist/RxForm/Tests/updateValues.test.d.ts +1 -1
- package/dist/RxForm/index.d.ts +1 -1
- package/dist/Testing/AsyncValidators.d.ts +9 -8
- package/dist/Testing/Models/Contact.d.ts +11 -11
- package/dist/Testing/Models/DoctorInfo.d.ts +6 -6
- package/dist/Testing/Models/EmergencyContact.d.ts +6 -6
- package/dist/Testing/Models/initialState.d.ts +667 -667
- package/dist/Testing/Validators.d.ts +10 -10
- package/dist/Testing/asyncConfig.d.ts +3 -3
- package/dist/Testing/config.d.ts +3 -3
- package/dist/Validators/Validators.d.ts +4 -4
- package/dist/Validators/index.d.ts +1 -1
- package/dist/index.cjs +1213 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +4 -4
- package/dist/index.js +1064 -1075
- package/dist/index.js.map +1 -0
- package/package.json +10 -3
- package/dist/Reducers/Hub2/asyncValidationResponseSuccess.d.ts +0 -4
- package/dist/Reducers/Hub2/hub2Reducer.d.ts +0 -3
- package/dist/Testing/Effects.d.ts +0 -10
package/dist/index.js
CHANGED
|
@@ -1,61 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
import { RxBuilder } from '@reactables/core';
|
|
2
|
+
import { map, mergeMap, catchError, startWith, pairwise, skip, filter } from 'rxjs/operators';
|
|
3
|
+
import { concat, of } from 'rxjs';
|
|
4
|
+
import isEqual from 'lodash.isequal';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
-
|
|
12
|
-
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual);
|
|
13
|
-
|
|
14
|
-
var DEFAULT_HUB2_FIELDS = {
|
|
15
|
-
asyncValidatorErrors: {},
|
|
16
|
-
asyncValidateInProgress: {},
|
|
17
|
-
pending: false,
|
|
18
|
-
valid: null,
|
|
19
|
-
childrenValid: null,
|
|
20
|
-
errors: null
|
|
6
|
+
var DEFAULT_HUB2_FIELDS = {
|
|
7
|
+
asyncValidatorErrors: {},
|
|
8
|
+
asyncValidateInProgress: {},
|
|
9
|
+
pending: false,
|
|
10
|
+
valid: null,
|
|
11
|
+
childrenValid: null,
|
|
12
|
+
errors: null
|
|
21
13
|
};
|
|
22
14
|
|
|
23
15
|
var Controls = /*#__PURE__*/Object.freeze({
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
__proto__: null,
|
|
17
|
+
DEFAULT_HUB2_FIELDS: DEFAULT_HUB2_FIELDS
|
|
26
18
|
});
|
|
27
19
|
|
|
28
|
-
var required = function (value) {
|
|
29
|
-
if (typeof value === 'string' || typeof value === 'object') {
|
|
30
|
-
return { required: !Boolean(value) };
|
|
31
|
-
}
|
|
32
|
-
if (typeof value === 'number') {
|
|
33
|
-
return { required: !(value !== undefined && value !== null) };
|
|
34
|
-
}
|
|
35
|
-
if (typeof value === 'boolean') {
|
|
36
|
-
return { required: !value };
|
|
37
|
-
}
|
|
38
|
-
return { required: false };
|
|
39
|
-
};
|
|
40
|
-
var arrayNotEmpty = function (value) { return ({
|
|
41
|
-
arrayNotEmpty: !Boolean(value.length)
|
|
42
|
-
}); };
|
|
43
|
-
var email = function (value) {
|
|
44
|
-
return value && !/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g.test(value) ? { email: true } : { email: false };
|
|
20
|
+
var required = function (value) {
|
|
21
|
+
if (typeof value === 'string' || typeof value === 'object') {
|
|
22
|
+
return { required: !Boolean(value) };
|
|
23
|
+
}
|
|
24
|
+
if (typeof value === 'number') {
|
|
25
|
+
return { required: !(value !== undefined && value !== null) };
|
|
26
|
+
}
|
|
27
|
+
if (typeof value === 'boolean') {
|
|
28
|
+
return { required: !value };
|
|
29
|
+
}
|
|
30
|
+
return { required: false };
|
|
31
|
+
};
|
|
32
|
+
var arrayNotEmpty = function (value) { return ({
|
|
33
|
+
arrayNotEmpty: !Boolean(value.length)
|
|
34
|
+
}); };
|
|
35
|
+
var email = function (value) {
|
|
36
|
+
return value && !/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g.test(value) ? { email: true } : { email: false };
|
|
45
37
|
};
|
|
46
38
|
|
|
47
39
|
var Validators = /*#__PURE__*/Object.freeze({
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
__proto__: null,
|
|
41
|
+
arrayNotEmpty: arrayNotEmpty,
|
|
42
|
+
email: email,
|
|
43
|
+
required: required
|
|
52
44
|
});
|
|
53
45
|
|
|
54
46
|
var index = /*#__PURE__*/Object.freeze({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
47
|
+
__proto__: null,
|
|
48
|
+
arrayNotEmpty: arrayNotEmpty,
|
|
49
|
+
email: email,
|
|
50
|
+
required: required
|
|
59
51
|
});
|
|
60
52
|
|
|
61
53
|
/******************************************************************************
|
|
@@ -72,6 +64,8 @@ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
|
72
64
|
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
73
65
|
PERFORMANCE OF THIS SOFTWARE.
|
|
74
66
|
***************************************************************************** */
|
|
67
|
+
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
68
|
+
|
|
75
69
|
|
|
76
70
|
var __assign = function() {
|
|
77
71
|
__assign = Object.assign || function __assign(t) {
|
|
@@ -111,1102 +105,1097 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
111
105
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
112
106
|
};
|
|
113
107
|
|
|
114
|
-
var getValueFromControlConfig = function (controlConfig) {
|
|
115
|
-
var controls = controlConfig.controls;
|
|
116
|
-
if (controls && !(controls instanceof Array)) {
|
|
117
|
-
var result = {};
|
|
118
|
-
for (var key in controlConfig.controls) {
|
|
119
|
-
var control = controlConfig.controls[key];
|
|
120
|
-
result[key] = getValueFromControlConfig(control);
|
|
121
|
-
}
|
|
122
|
-
return result;
|
|
123
|
-
}
|
|
124
|
-
else if (controls && controls instanceof Array) {
|
|
125
|
-
var configs = controlConfig.controls;
|
|
126
|
-
var result = configs
|
|
127
|
-
? configs.map(function (controlConfig) { return getValueFromControlConfig(controlConfig); })
|
|
128
|
-
: [];
|
|
129
|
-
return result;
|
|
130
|
-
}
|
|
131
|
-
else {
|
|
132
|
-
return controlConfig.initialValue;
|
|
133
|
-
}
|
|
108
|
+
var getValueFromControlConfig = function (controlConfig) {
|
|
109
|
+
var controls = controlConfig.controls;
|
|
110
|
+
if (controls && !(controls instanceof Array)) {
|
|
111
|
+
var result = {};
|
|
112
|
+
for (var key in controlConfig.controls) {
|
|
113
|
+
var control = controlConfig.controls[key];
|
|
114
|
+
result[key] = getValueFromControlConfig(control);
|
|
115
|
+
}
|
|
116
|
+
return result;
|
|
117
|
+
}
|
|
118
|
+
else if (controls && controls instanceof Array) {
|
|
119
|
+
var configs = controlConfig.controls;
|
|
120
|
+
var result = configs
|
|
121
|
+
? configs.map(function (controlConfig) { return getValueFromControlConfig(controlConfig); })
|
|
122
|
+
: [];
|
|
123
|
+
return result;
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
return controlConfig.initialValue;
|
|
127
|
+
}
|
|
134
128
|
};
|
|
135
129
|
|
|
136
|
-
var getFormKey = function (controlRef) {
|
|
137
|
-
return controlRef.length ? controlRef.join('.') : 'root';
|
|
130
|
+
var getFormKey = function (controlRef) {
|
|
131
|
+
return controlRef.length ? controlRef.join('.') : 'root';
|
|
138
132
|
};
|
|
139
133
|
|
|
140
|
-
var generateKey = function (length) {
|
|
141
|
-
var result = '';
|
|
142
|
-
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
143
|
-
var charactersLength = characters.length;
|
|
144
|
-
var counter = 0;
|
|
145
|
-
while (counter < length) {
|
|
146
|
-
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
147
|
-
counter += 1;
|
|
148
|
-
}
|
|
149
|
-
return result;
|
|
134
|
+
var generateKey = function (length) {
|
|
135
|
+
var result = '';
|
|
136
|
+
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
|
|
137
|
+
var charactersLength = characters.length;
|
|
138
|
+
var counter = 0;
|
|
139
|
+
while (counter < length) {
|
|
140
|
+
result += characters.charAt(Math.floor(Math.random() * charactersLength));
|
|
141
|
+
counter += 1;
|
|
142
|
+
}
|
|
143
|
+
return result;
|
|
150
144
|
};
|
|
151
145
|
|
|
152
|
-
var getErrors = function (control, value, _a) {
|
|
153
|
-
var _b;
|
|
154
|
-
var validators = _a.validators;
|
|
155
|
-
return ((_b = control.config.validators) === null || _b === void 0 ? void 0 : _b.reduce(function (acc, validator) {
|
|
156
|
-
if (!validators[validator]) {
|
|
157
|
-
throw "You have not provided a validator for \"".concat(validator, "\"");
|
|
158
|
-
}
|
|
159
|
-
return __assign(__assign({}, acc), validators[validator](value));
|
|
160
|
-
}, {})) || {};
|
|
146
|
+
var getErrors = function (control, value, _a) {
|
|
147
|
+
var _b;
|
|
148
|
+
var validators = _a.validators;
|
|
149
|
+
return ((_b = control.config.validators) === null || _b === void 0 ? void 0 : _b.reduce(function (acc, validator) {
|
|
150
|
+
if (!validators[validator]) {
|
|
151
|
+
throw "You have not provided a validator for \"".concat(validator, "\"");
|
|
152
|
+
}
|
|
153
|
+
return __assign(__assign({}, acc), validators[validator](value));
|
|
154
|
+
}, {})) || {};
|
|
161
155
|
};
|
|
162
156
|
|
|
163
|
-
var buildState = function (config, form, controlRef, providers) {
|
|
164
|
-
var _a;
|
|
165
|
-
if (form === void 0) { form = { root: null }; }
|
|
166
|
-
if (controlRef === void 0) { controlRef = []; }
|
|
167
|
-
var value = getValueFromControlConfig(config);
|
|
168
|
-
var control = {
|
|
169
|
-
pristineValue: value,
|
|
170
|
-
dirty: false,
|
|
171
|
-
touched: false,
|
|
172
|
-
value: value,
|
|
173
|
-
controlRef: controlRef,
|
|
174
|
-
validatorErrors: {},
|
|
175
|
-
config: config,
|
|
176
|
-
key: generateKey(5)
|
|
177
|
-
};
|
|
178
|
-
var newForm = __assign(__assign({}, form), (_a = {}, _a[getFormKey(controlRef)] = __assign(__assign({}, control), { validatorErrors: getErrors(control, value, providers) }), _a));
|
|
179
|
-
var controls = config.controls;
|
|
180
|
-
// Adding controls for Form Group
|
|
181
|
-
if (controls && !(controls instanceof Array)) {
|
|
182
|
-
newForm = Object.entries(config.controls).reduce(function (acc, _a) {
|
|
183
|
-
var key = _a[0], controlConfig = _a[1];
|
|
184
|
-
return buildState(controlConfig, acc, controlRef.concat(key), providers);
|
|
185
|
-
}, newForm);
|
|
186
|
-
}
|
|
187
|
-
else if (controls && controls instanceof Array) {
|
|
188
|
-
// Adding controls for Form Array
|
|
189
|
-
newForm = config.controls.reduce(function (acc, controlConfig, index) {
|
|
190
|
-
return buildState(controlConfig, acc, controlRef.concat(index), providers);
|
|
191
|
-
}, newForm);
|
|
192
|
-
}
|
|
193
|
-
return newForm;
|
|
194
|
-
};
|
|
195
|
-
var buildFormState = function (config, form, controlRef, providers) {
|
|
196
|
-
if (form === void 0) { form = { root: null }; }
|
|
197
|
-
if (controlRef === void 0) { controlRef = []; }
|
|
198
|
-
return {
|
|
199
|
-
form: buildState(config, form, controlRef, providers)
|
|
200
|
-
};
|
|
157
|
+
var buildState = function (config, form, controlRef, providers) {
|
|
158
|
+
var _a;
|
|
159
|
+
if (form === void 0) { form = { root: null }; }
|
|
160
|
+
if (controlRef === void 0) { controlRef = []; }
|
|
161
|
+
var value = getValueFromControlConfig(config);
|
|
162
|
+
var control = {
|
|
163
|
+
pristineValue: value,
|
|
164
|
+
dirty: false,
|
|
165
|
+
touched: false,
|
|
166
|
+
value: value,
|
|
167
|
+
controlRef: controlRef,
|
|
168
|
+
validatorErrors: {},
|
|
169
|
+
config: config,
|
|
170
|
+
key: generateKey(5)
|
|
171
|
+
};
|
|
172
|
+
var newForm = __assign(__assign({}, form), (_a = {}, _a[getFormKey(controlRef)] = __assign(__assign({}, control), { validatorErrors: getErrors(control, value, providers) }), _a));
|
|
173
|
+
var controls = config.controls;
|
|
174
|
+
// Adding controls for Form Group
|
|
175
|
+
if (controls && !(controls instanceof Array)) {
|
|
176
|
+
newForm = Object.entries(config.controls).reduce(function (acc, _a) {
|
|
177
|
+
var key = _a[0], controlConfig = _a[1];
|
|
178
|
+
return buildState(controlConfig, acc, controlRef.concat(key), providers);
|
|
179
|
+
}, newForm);
|
|
180
|
+
}
|
|
181
|
+
else if (controls && controls instanceof Array) {
|
|
182
|
+
// Adding controls for Form Array
|
|
183
|
+
newForm = config.controls.reduce(function (acc, controlConfig, index) {
|
|
184
|
+
return buildState(controlConfig, acc, controlRef.concat(index), providers);
|
|
185
|
+
}, newForm);
|
|
186
|
+
}
|
|
187
|
+
return newForm;
|
|
188
|
+
};
|
|
189
|
+
var buildFormState = function (config, form, controlRef, providers) {
|
|
190
|
+
if (form === void 0) { form = { root: null }; }
|
|
191
|
+
if (controlRef === void 0) { controlRef = []; }
|
|
192
|
+
return {
|
|
193
|
+
form: buildState(config, form, controlRef, providers)
|
|
194
|
+
};
|
|
201
195
|
};
|
|
202
196
|
|
|
203
|
-
var getScopedEffectsForControl = function (formControl, providers) {
|
|
204
|
-
var config = formControl.config, key = formControl.key;
|
|
205
|
-
var asyncValidators = config.asyncValidators;
|
|
206
|
-
var scopedEffects = [];
|
|
207
|
-
if (asyncValidators && asyncValidators.length) {
|
|
208
|
-
scopedEffects = asyncValidators.reduce(function (acc, asyncValidator, validatorIndex) {
|
|
209
|
-
var effect = function (actions$) {
|
|
210
|
-
if (!providers.asyncValidators[asyncValidator]) {
|
|
211
|
-
throw "You have not provided an asyncValidator for \"".concat(asyncValidator, "\"");
|
|
212
|
-
}
|
|
213
|
-
return actions$.pipe(
|
|
214
|
-
var control = _a.payload;
|
|
215
|
-
return control;
|
|
216
|
-
}), providers.asyncValidators[asyncValidator],
|
|
217
|
-
type: '
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
197
|
+
var getScopedEffectsForControl = function (formControl, providers) {
|
|
198
|
+
var config = formControl.config, key = formControl.key, controlRef = formControl.controlRef;
|
|
199
|
+
var asyncValidators = config.asyncValidators;
|
|
200
|
+
var scopedEffects = [];
|
|
201
|
+
if (asyncValidators && asyncValidators.length) {
|
|
202
|
+
scopedEffects = asyncValidators.reduce(function (acc, asyncValidator, validatorIndex) {
|
|
203
|
+
var effect = function (actions$) {
|
|
204
|
+
if (!providers.asyncValidators[asyncValidator]) {
|
|
205
|
+
throw "You have not provided an asyncValidator for \"".concat(asyncValidator, "\"");
|
|
206
|
+
}
|
|
207
|
+
return actions$.pipe(map(function (_a) {
|
|
208
|
+
var control = _a.payload;
|
|
209
|
+
return control;
|
|
210
|
+
}), providers.asyncValidators[asyncValidator], mergeMap(function (errors$) {
|
|
211
|
+
return concat(of({ type: 'asyncValidation', payload: controlRef }), errors$.pipe(map(function (errors) { return ({
|
|
212
|
+
type: 'asyncValidationResponse',
|
|
213
|
+
payload: {
|
|
214
|
+
key: key,
|
|
215
|
+
errors: errors,
|
|
216
|
+
validatorIndex: validatorIndex
|
|
217
|
+
}
|
|
218
|
+
}); }), catchError(function () {
|
|
219
|
+
return of({
|
|
220
|
+
type: 'asyncValidationResponse',
|
|
221
|
+
payload: {
|
|
222
|
+
key: key,
|
|
223
|
+
errors: { asyncValidationApiError: true },
|
|
224
|
+
validatorIndex: validatorIndex
|
|
225
|
+
}
|
|
226
|
+
});
|
|
227
|
+
})));
|
|
228
|
+
}));
|
|
229
|
+
};
|
|
230
|
+
return acc.concat(effect);
|
|
231
|
+
}, []);
|
|
232
|
+
}
|
|
233
|
+
return scopedEffects;
|
|
234
|
+
};
|
|
235
|
+
var getAsyncValidationEffects = function (formControls) {
|
|
236
|
+
return formControls.reduce(function (acc, control) {
|
|
237
|
+
var _a;
|
|
238
|
+
if (!((_a = control.config.asyncValidators) === null || _a === void 0 ? void 0 : _a.length))
|
|
239
|
+
return acc;
|
|
240
|
+
var action = { type: 'asyncValidationEffect', payload: control };
|
|
241
|
+
return acc.concat(action);
|
|
242
|
+
}, []);
|
|
238
243
|
};
|
|
239
244
|
|
|
240
|
-
var buildHub2Source = function (hub1State$, initialBaseState) {
|
|
241
|
-
var hub1StateMapped$ = hub1State$.pipe(
|
|
242
|
-
var initialAction = { type: 'formChange', payload: initialBaseState };
|
|
243
|
-
var sourceForHub2$ = hub1StateMapped$.pipe(
|
|
244
|
-
var prevForm = _a[0].payload.form, currAction = _a[1];
|
|
245
|
-
var _b = currAction.payload, _changedControls = _b._changedControls, currentForm = _b.form;
|
|
246
|
-
var valueChanged = !
|
|
247
|
-
var controlsToCheck = _changedControls && valueChanged ? Object.values(_changedControls) : [];
|
|
248
|
-
var
|
|
249
|
-
return
|
|
250
|
-
}));
|
|
251
|
-
return sourceForHub2$;
|
|
245
|
+
var buildHub2Source = function (hub1State$, initialBaseState) {
|
|
246
|
+
var hub1StateMapped$ = hub1State$.pipe(map(function (payload) { return ({ type: 'formChange', payload: payload }); }));
|
|
247
|
+
var initialAction = { type: 'formChange', payload: initialBaseState };
|
|
248
|
+
var sourceForHub2$ = hub1StateMapped$.pipe(startWith(initialAction), pairwise(), mergeMap(function (_a) {
|
|
249
|
+
var prevForm = _a[0].payload.form, currAction = _a[1];
|
|
250
|
+
var _b = currAction.payload, _changedControls = _b._changedControls, currentForm = _b.form;
|
|
251
|
+
var valueChanged = !isEqual(prevForm.root.value, currentForm.root.value);
|
|
252
|
+
var controlsToCheck = _changedControls && valueChanged ? Object.values(_changedControls) : [];
|
|
253
|
+
var asyncValidationEffectActions = getAsyncValidationEffects(controlsToCheck);
|
|
254
|
+
return of.apply(void 0, __spreadArray([currAction], asyncValidationEffectActions, false));
|
|
255
|
+
}));
|
|
256
|
+
return sourceForHub2$;
|
|
252
257
|
};
|
|
253
258
|
|
|
254
|
-
var getControl = function (controlRef, form) {
|
|
255
|
-
return form[getFormKey(controlRef)];
|
|
259
|
+
var getControl = function (controlRef, form) {
|
|
260
|
+
return form[getFormKey(controlRef)];
|
|
256
261
|
};
|
|
257
262
|
|
|
258
|
-
var
|
|
259
|
-
var
|
|
260
|
-
var
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
var
|
|
264
|
-
var
|
|
265
|
-
var
|
|
266
|
-
var
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
return form;
|
|
263
|
+
var updateAncestorValues = function (form, _a, providers) {
|
|
264
|
+
var _b, _c;
|
|
265
|
+
var _d = _a.payload, controlRef = _d.controlRef, value = _d.value;
|
|
266
|
+
if (controlRef.length) {
|
|
267
|
+
var parentRef = controlRef.slice(0, -1);
|
|
268
|
+
var parentControl = getControl(parentRef, form);
|
|
269
|
+
var parentFormKey = getFormKey(parentControl.controlRef);
|
|
270
|
+
var childKey_1 = controlRef.slice(-1)[0];
|
|
271
|
+
var newValue = void 0;
|
|
272
|
+
// If parent is a Form Array
|
|
273
|
+
if (Array.isArray(parentControl.value)) {
|
|
274
|
+
newValue = parentControl.value.map(function (item, index) {
|
|
275
|
+
return index === childKey_1 ? value : item;
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
// If parent is a Form Group
|
|
280
|
+
newValue = __assign(__assign({}, parentControl.value), (_b = {}, _b[childKey_1] = value, _b));
|
|
281
|
+
}
|
|
282
|
+
var newParentControl = __assign(__assign({}, parentControl), { validatorErrors: getErrors(parentControl, newValue, providers), value: newValue, dirty: !isEqual(newValue, parentControl.pristineValue) });
|
|
283
|
+
return updateAncestorValues(__assign(__assign({}, form), (_c = {}, _c[parentFormKey] = newParentControl, _c)), {
|
|
284
|
+
payload: { controlRef: parentRef, value: newValue }
|
|
285
|
+
}, providers);
|
|
286
|
+
}
|
|
287
|
+
return form;
|
|
285
288
|
};
|
|
286
289
|
|
|
287
|
-
var isChildRef = function (controlRef, parentRef) {
|
|
288
|
-
return (parentRef.every(function (key, index) { return controlRef[index] === key; }) &&
|
|
289
|
-
controlRef.length === parentRef.length + 1);
|
|
290
|
+
var isChildRef = function (controlRef, parentRef) {
|
|
291
|
+
return (parentRef.every(function (key, index) { return controlRef[index] === key; }) &&
|
|
292
|
+
controlRef.length === parentRef.length + 1);
|
|
290
293
|
};
|
|
291
294
|
|
|
292
|
-
// Includes the original control of interest unless excludeSelf === true
|
|
293
|
-
var getDescendantControls = function (controlRef, form, excludeSelf) {
|
|
294
|
-
if (excludeSelf === void 0) { excludeSelf = false; }
|
|
295
|
-
if (!controlRef.length) {
|
|
296
|
-
return Object.values(form).filter(function (_a) {
|
|
297
|
-
var controlRef = _a.controlRef;
|
|
298
|
-
return excludeSelf ? controlRef.length !== 0 : true;
|
|
299
|
-
});
|
|
300
|
-
}
|
|
301
|
-
var control = getControl(controlRef, form);
|
|
302
|
-
var value = control.value, config = control.config;
|
|
303
|
-
var descendants;
|
|
304
|
-
if (Array.isArray(config.controls)) {
|
|
305
|
-
// If control is a Form Array
|
|
306
|
-
descendants = value.reduce(function (acc, item, index) {
|
|
307
|
-
return acc.concat(getDescendantControls(controlRef.concat(index), form));
|
|
308
|
-
}, []);
|
|
309
|
-
}
|
|
310
|
-
else if (config.controls) {
|
|
311
|
-
// If control is a Form Group
|
|
312
|
-
descendants = Object.keys(value).reduce(function (acc, key) {
|
|
313
|
-
return acc.concat(getDescendantControls(controlRef.concat(key), form));
|
|
314
|
-
}, []);
|
|
315
|
-
}
|
|
316
|
-
if (excludeSelf)
|
|
317
|
-
return descendants;
|
|
318
|
-
return [control].concat(descendants || []);
|
|
295
|
+
// Includes the original control of interest unless excludeSelf === true
|
|
296
|
+
var getDescendantControls = function (controlRef, form, excludeSelf) {
|
|
297
|
+
if (excludeSelf === void 0) { excludeSelf = false; }
|
|
298
|
+
if (!controlRef.length) {
|
|
299
|
+
return Object.values(form).filter(function (_a) {
|
|
300
|
+
var controlRef = _a.controlRef;
|
|
301
|
+
return excludeSelf ? controlRef.length !== 0 : true;
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
var control = getControl(controlRef, form);
|
|
305
|
+
var value = control.value, config = control.config;
|
|
306
|
+
var descendants;
|
|
307
|
+
if (Array.isArray(config.controls)) {
|
|
308
|
+
// If control is a Form Array
|
|
309
|
+
descendants = value.reduce(function (acc, item, index) {
|
|
310
|
+
return acc.concat(getDescendantControls(controlRef.concat(index), form));
|
|
311
|
+
}, []);
|
|
312
|
+
}
|
|
313
|
+
else if (config.controls) {
|
|
314
|
+
// If control is a Form Group
|
|
315
|
+
descendants = Object.keys(value).reduce(function (acc, key) {
|
|
316
|
+
return acc.concat(getDescendantControls(controlRef.concat(key), form));
|
|
317
|
+
}, []);
|
|
318
|
+
}
|
|
319
|
+
if (excludeSelf)
|
|
320
|
+
return descendants;
|
|
321
|
+
return [control].concat(descendants || []);
|
|
319
322
|
};
|
|
320
323
|
|
|
321
|
-
// Includes the original control of interest unless excludeSelf === true
|
|
322
|
-
var getAncestorControls = function (controlRef, form, excludeSelf) {
|
|
323
|
-
if (excludeSelf === void 0) { excludeSelf = false; }
|
|
324
|
-
var formControls = controlRef.reduce(function (acc, key) {
|
|
325
|
-
var currentRef = acc.currentRef.concat(key);
|
|
326
|
-
var formControls = acc.formControls.concat(getControl(currentRef, form));
|
|
327
|
-
return {
|
|
328
|
-
currentRef: currentRef,
|
|
329
|
-
formControls: formControls
|
|
330
|
-
};
|
|
331
|
-
}, {
|
|
332
|
-
currentRef: [],
|
|
333
|
-
formControls: []
|
|
334
|
-
}).formControls;
|
|
335
|
-
var root = form['root'];
|
|
336
|
-
var result = [root].concat(formControls);
|
|
337
|
-
return result.filter(function (control) {
|
|
338
|
-
return excludeSelf ? getFormKey(control.controlRef) !== getFormKey(controlRef) : true;
|
|
339
|
-
});
|
|
324
|
+
// Includes the original control of interest unless excludeSelf === true
|
|
325
|
+
var getAncestorControls = function (controlRef, form, excludeSelf) {
|
|
326
|
+
if (excludeSelf === void 0) { excludeSelf = false; }
|
|
327
|
+
var formControls = controlRef.reduce(function (acc, key) {
|
|
328
|
+
var currentRef = acc.currentRef.concat(key);
|
|
329
|
+
var formControls = acc.formControls.concat(getControl(currentRef, form));
|
|
330
|
+
return {
|
|
331
|
+
currentRef: currentRef,
|
|
332
|
+
formControls: formControls
|
|
333
|
+
};
|
|
334
|
+
}, {
|
|
335
|
+
currentRef: [],
|
|
336
|
+
formControls: []
|
|
337
|
+
}).formControls;
|
|
338
|
+
var root = form['root'];
|
|
339
|
+
var result = [root].concat(formControls);
|
|
340
|
+
return result.filter(function (control) {
|
|
341
|
+
return excludeSelf ? getFormKey(control.controlRef) !== getFormKey(controlRef) : true;
|
|
342
|
+
});
|
|
340
343
|
};
|
|
341
344
|
|
|
342
|
-
/**
|
|
343
|
-
* @description see if any keys in a ControlRef has a "." probably a mistake by developer
|
|
344
|
-
*/
|
|
345
|
-
var controlRefCheck = function (ref) {
|
|
346
|
-
try {
|
|
347
|
-
var hasError = ref.some(function (key) {
|
|
348
|
-
if (typeof key === 'string') {
|
|
349
|
-
return key.includes('.');
|
|
350
|
-
}
|
|
351
|
-
return false;
|
|
352
|
-
});
|
|
353
|
-
if (hasError) {
|
|
354
|
-
var refString = "[".concat(ref.reduce(function (acc, key, index) {
|
|
355
|
-
if (index > 0) {
|
|
356
|
-
acc = acc.concat(', ');
|
|
357
|
-
}
|
|
358
|
-
if (typeof key === 'number') {
|
|
359
|
-
return acc.concat(key.toString());
|
|
360
|
-
}
|
|
361
|
-
return acc.concat("'".concat(key, "'"));
|
|
362
|
-
}, ''), "]");
|
|
363
|
-
var suggestion = "[".concat(ref.reduce(function (acc, key, index) {
|
|
364
|
-
if (index > 0) {
|
|
365
|
-
acc = acc.concat(', ');
|
|
366
|
-
}
|
|
367
|
-
if (typeof key === 'number') {
|
|
368
|
-
return acc.concat(key.toString());
|
|
369
|
-
}
|
|
370
|
-
var splitted = key
|
|
371
|
-
.split('.')
|
|
372
|
-
.map(function (key) { return "'".concat(key, "'"); })
|
|
373
|
-
.join(', ');
|
|
374
|
-
return acc.concat("".concat(splitted));
|
|
375
|
-
}, ''), "]");
|
|
376
|
-
console.warn("You provided ".concat(refString, ". Did you mean ").concat(suggestion, "?"));
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
catch (_a) { }
|
|
345
|
+
/**
|
|
346
|
+
* @description see if any keys in a ControlRef has a "." probably a mistake by developer
|
|
347
|
+
*/
|
|
348
|
+
var controlRefCheck = function (ref) {
|
|
349
|
+
try {
|
|
350
|
+
var hasError = ref.some(function (key) {
|
|
351
|
+
if (typeof key === 'string') {
|
|
352
|
+
return key.includes('.');
|
|
353
|
+
}
|
|
354
|
+
return false;
|
|
355
|
+
});
|
|
356
|
+
if (hasError) {
|
|
357
|
+
var refString = "[".concat(ref.reduce(function (acc, key, index) {
|
|
358
|
+
if (index > 0) {
|
|
359
|
+
acc = acc.concat(', ');
|
|
360
|
+
}
|
|
361
|
+
if (typeof key === 'number') {
|
|
362
|
+
return acc.concat(key.toString());
|
|
363
|
+
}
|
|
364
|
+
return acc.concat("'".concat(key, "'"));
|
|
365
|
+
}, ''), "]");
|
|
366
|
+
var suggestion = "[".concat(ref.reduce(function (acc, key, index) {
|
|
367
|
+
if (index > 0) {
|
|
368
|
+
acc = acc.concat(', ');
|
|
369
|
+
}
|
|
370
|
+
if (typeof key === 'number') {
|
|
371
|
+
return acc.concat(key.toString());
|
|
372
|
+
}
|
|
373
|
+
var splitted = key
|
|
374
|
+
.split('.')
|
|
375
|
+
.map(function (key) { return "'".concat(key, "'"); })
|
|
376
|
+
.join(', ');
|
|
377
|
+
return acc.concat("".concat(splitted));
|
|
378
|
+
}, ''), "]");
|
|
379
|
+
console.warn("You provided ".concat(refString, ". Did you mean ").concat(suggestion, "?"));
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
catch (_a) { }
|
|
380
383
|
};
|
|
381
384
|
|
|
382
|
-
var
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
var
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
var
|
|
418
|
-
var
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
}
|
|
433
|
-
var
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
var
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
385
|
+
var checkKeys = function (obj1, obj2) {
|
|
386
|
+
if (Object.keys(obj1).slice().sort().join() !== Object.keys(obj2).slice().sort().join()) {
|
|
387
|
+
throw 'Can not update value because keys are not the same.';
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
var updateDescendantValues = function (form, _a, providers) {
|
|
391
|
+
var _b = _a.payload, controlRef = _b.controlRef, value = _b.value;
|
|
392
|
+
var descendants = getDescendantControls(controlRef, form, true).map(function (control) { return [getFormKey(control.controlRef), control]; });
|
|
393
|
+
var result = descendants.reduce(function (acc, _a) {
|
|
394
|
+
var _b;
|
|
395
|
+
var key = _a[0], control = _a[1];
|
|
396
|
+
if (isChildRef(control.controlRef, controlRef)) {
|
|
397
|
+
var newChildValue = value[control.controlRef.at(-1)];
|
|
398
|
+
var validatorErrors = getErrors(control, newChildValue, providers);
|
|
399
|
+
var oldChildValue = control.value;
|
|
400
|
+
var newControl = __assign(__assign({}, control), { value: newChildValue, validatorErrors: validatorErrors, dirty: !isEqual(newChildValue, control.pristineValue) });
|
|
401
|
+
acc = __assign(__assign({}, acc), (_b = {}, _b[key] = newControl, _b));
|
|
402
|
+
var configControls = control.config.controls;
|
|
403
|
+
if (configControls) {
|
|
404
|
+
checkKeys(oldChildValue, newChildValue);
|
|
405
|
+
acc = updateDescendantValues(acc, {
|
|
406
|
+
payload: { controlRef: control.controlRef, value: newChildValue }
|
|
407
|
+
}, providers);
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
return acc;
|
|
411
|
+
}, form);
|
|
412
|
+
return result;
|
|
413
|
+
};
|
|
414
|
+
// Will only update child controls that are present.
|
|
415
|
+
// Use AddControlPayload/RemoveControl action reducers to add/remove control
|
|
416
|
+
var updateValues = function (_a, action, providers, mergeChanges) {
|
|
417
|
+
var _b, _c;
|
|
418
|
+
var form = _a.form, _d = _a._changedControls, _changedControls = _d === void 0 ? {} : _d, _e = _a._removedControls, _removedControls = _e === void 0 ? {} : _e;
|
|
419
|
+
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
420
|
+
var normalizers = providers.normalizers;
|
|
421
|
+
var _f = action.payload, controlRef = _f.controlRef, value = _f.value;
|
|
422
|
+
controlRefCheck(controlRef);
|
|
423
|
+
// Update its own value
|
|
424
|
+
var ctrlKey = getFormKey(controlRef);
|
|
425
|
+
var newValue = value;
|
|
426
|
+
var oldValue = form[ctrlKey].value;
|
|
427
|
+
var config = form[ctrlKey].config;
|
|
428
|
+
if (config.normalizers) {
|
|
429
|
+
newValue = config.normalizers.reduce(function (acc, normalizer) {
|
|
430
|
+
if (!normalizers[normalizer]) {
|
|
431
|
+
throw "You have not provided a normalizer for \"".concat(normalizer, "\"");
|
|
432
|
+
}
|
|
433
|
+
return normalizers[normalizer](acc);
|
|
434
|
+
}, value);
|
|
435
|
+
}
|
|
436
|
+
var validatorErrors = getErrors(form[ctrlKey], newValue, providers);
|
|
437
|
+
var newControl = __assign(__assign({}, form[ctrlKey]), { validatorErrors: validatorErrors, dirty: !isEqual(value, form[ctrlKey].pristineValue), value: newValue });
|
|
438
|
+
var result = {
|
|
439
|
+
form: __assign(__assign({}, form), (_b = {}, _b[ctrlKey] = newControl, _b)),
|
|
440
|
+
_changedControls: (_c = {}, _c[newControl.key] = newControl, _c)
|
|
441
|
+
};
|
|
442
|
+
var configControls = config.controls;
|
|
443
|
+
// Update its descendants
|
|
444
|
+
if (configControls) {
|
|
445
|
+
checkKeys(oldValue, newValue);
|
|
446
|
+
var updatedDescendants = updateDescendantValues(result.form, {
|
|
447
|
+
payload: {
|
|
448
|
+
controlRef: controlRef,
|
|
449
|
+
value: newValue
|
|
450
|
+
}
|
|
451
|
+
}, providers);
|
|
452
|
+
var changedDescendantControls = getDescendantControls(controlRef, updatedDescendants).reduce(function (acc, control) {
|
|
453
|
+
var _a;
|
|
454
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[control.key] = control, _a)));
|
|
455
|
+
}, {});
|
|
456
|
+
result = __assign(__assign({}, result), { form: updatedDescendants, _changedControls: __assign(__assign({}, result._changedControls), changedDescendantControls) });
|
|
457
|
+
}
|
|
458
|
+
// Update its Ancestors
|
|
459
|
+
if (controlRef.length) {
|
|
460
|
+
result = __assign(__assign({}, result), { form: updateAncestorValues(result.form, {
|
|
461
|
+
payload: { controlRef: controlRef, value: newValue }
|
|
462
|
+
}, providers) });
|
|
463
|
+
}
|
|
464
|
+
var changedAncestorControls = getAncestorControls(controlRef, result.form).reduce(function (acc, control) {
|
|
465
|
+
var _a;
|
|
466
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[control.key] = control, _a)));
|
|
467
|
+
}, {});
|
|
468
|
+
var mergedResult = __assign(__assign({}, result), { _changedControls: __assign(__assign(__assign({}, (mergeChanges ? _changedControls : undefined)), changedAncestorControls), result._changedControls), _removedControls: mergeChanges ? _removedControls : undefined });
|
|
469
|
+
return mergedResult;
|
|
462
470
|
};
|
|
463
471
|
|
|
464
|
-
var
|
|
465
|
-
var
|
|
466
|
-
var
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
var
|
|
470
|
-
var
|
|
471
|
-
var
|
|
472
|
-
var
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
newValue
|
|
481
|
-
|
|
482
|
-
}
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
489
|
-
return form;
|
|
472
|
+
var updateAncestorValuesRemoveControl = function (form, _a, providers) {
|
|
473
|
+
var _b;
|
|
474
|
+
var controlRef = _a.payload;
|
|
475
|
+
if (controlRef.length) {
|
|
476
|
+
var parentRef = controlRef.slice(0, -1);
|
|
477
|
+
var parentControl = getControl(parentRef, form);
|
|
478
|
+
var parentFormKey = getFormKey(parentControl.controlRef);
|
|
479
|
+
var childKey_1 = controlRef.slice(-1)[0];
|
|
480
|
+
var newValue = void 0;
|
|
481
|
+
// If parent is a Form Array
|
|
482
|
+
if (Array.isArray(parentControl.value)) {
|
|
483
|
+
newValue = parentControl.value.filter(function (item, index) { return index !== childKey_1; });
|
|
484
|
+
}
|
|
485
|
+
else {
|
|
486
|
+
// If parent is a Form Group
|
|
487
|
+
newValue = __assign({}, parentControl.value);
|
|
488
|
+
delete newValue[childKey_1];
|
|
489
|
+
}
|
|
490
|
+
var newParentControl = __assign(__assign({}, parentControl), { value: newValue, validatorErrors: getErrors(parentControl, newValue, providers), dirty: !isEqual(newValue, parentControl.pristineValue) });
|
|
491
|
+
return updateAncestorValues(__assign(__assign({}, form), (_b = {}, _b[parentFormKey] = newParentControl, _b)), {
|
|
492
|
+
payload: { controlRef: parentRef, value: newValue }
|
|
493
|
+
}, providers);
|
|
494
|
+
}
|
|
495
|
+
return form;
|
|
490
496
|
};
|
|
491
497
|
|
|
492
|
-
var removeControl = function (state, action, providers, mergeChanges) {
|
|
493
|
-
var _a;
|
|
494
|
-
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
495
|
-
var form = state.form;
|
|
496
|
-
var controlRef = action.payload;
|
|
497
|
-
controlRefCheck(controlRef);
|
|
498
|
-
var controlToRemove = getControl(controlRef, form);
|
|
499
|
-
if (!controlToRemove) {
|
|
500
|
-
throw 'Control not found';
|
|
501
|
-
}
|
|
502
|
-
// Can't remove the root of the form
|
|
503
|
-
if (!controlRef.length)
|
|
504
|
-
return { form: form };
|
|
505
|
-
var parentRef = controlRef.slice(0, -1);
|
|
506
|
-
var parentIsFormArray = Array.isArray(getControl(parentRef, form).config.controls);
|
|
507
|
-
var descendants = getDescendantControls(controlRef, form);
|
|
508
|
-
var descendantkeys = descendants.map(function (_a) {
|
|
509
|
-
var controlRef = _a.controlRef;
|
|
510
|
-
return getFormKey(controlRef);
|
|
511
|
-
});
|
|
512
|
-
var controlsRemoved = __assign({}, form);
|
|
513
|
-
descendantkeys.forEach(function (key) {
|
|
514
|
-
delete controlsRemoved[key];
|
|
515
|
-
});
|
|
516
|
-
// Remove control and all descendants
|
|
517
|
-
var controlRemoved = Object.entries(controlsRemoved).reduce(function (acc, _a) {
|
|
518
|
-
var _b, _c;
|
|
519
|
-
var key = _a[0], control = _a[1];
|
|
520
|
-
// May need to reindex array items of removed control
|
|
521
|
-
// if it was part of a Form Array.
|
|
522
|
-
if (parentIsFormArray) {
|
|
523
|
-
var oldIndex = control.controlRef.at(parentRef.length);
|
|
524
|
-
if (
|
|
525
|
-
// If control is descendant.
|
|
526
|
-
parentRef.every(function (ref, index) { return control.controlRef[index] === ref; }) &&
|
|
527
|
-
control.controlRef.length > parentRef.length &&
|
|
528
|
-
// If the array item index was greater than the index of item removed
|
|
529
|
-
// we need to decrement its index by 1.
|
|
530
|
-
oldIndex > controlRef.at(-1)) {
|
|
531
|
-
var newRef = parentRef
|
|
532
|
-
.concat(oldIndex - 1)
|
|
533
|
-
.concat(control.controlRef.slice(parentRef.length + 1));
|
|
534
|
-
return __assign(__assign({}, acc), (_b = {}, _b[getFormKey(newRef)] = __assign(__assign({}, control), { controlRef: newRef }), _b));
|
|
535
|
-
}
|
|
536
|
-
}
|
|
537
|
-
return __assign(__assign({}, acc), (_c = {}, _c[key] = control, _c));
|
|
538
|
-
}, {});
|
|
539
|
-
var result = updateAncestorValuesRemoveControl(controlRemoved, {
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
},
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
var
|
|
551
|
-
var
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
//
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
.concat(
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
}
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
};
|
|
498
|
+
var removeControl = function (state, action, providers, mergeChanges) {
|
|
499
|
+
var _a;
|
|
500
|
+
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
501
|
+
var form = state.form;
|
|
502
|
+
var controlRef = action.payload;
|
|
503
|
+
controlRefCheck(controlRef);
|
|
504
|
+
var controlToRemove = getControl(controlRef, form);
|
|
505
|
+
if (!controlToRemove) {
|
|
506
|
+
throw 'Control not found';
|
|
507
|
+
}
|
|
508
|
+
// Can't remove the root of the form
|
|
509
|
+
if (!controlRef.length)
|
|
510
|
+
return { form: form };
|
|
511
|
+
var parentRef = controlRef.slice(0, -1);
|
|
512
|
+
var parentIsFormArray = Array.isArray(getControl(parentRef, form).config.controls);
|
|
513
|
+
var descendants = getDescendantControls(controlRef, form);
|
|
514
|
+
var descendantkeys = descendants.map(function (_a) {
|
|
515
|
+
var controlRef = _a.controlRef;
|
|
516
|
+
return getFormKey(controlRef);
|
|
517
|
+
});
|
|
518
|
+
var controlsRemoved = __assign({}, form);
|
|
519
|
+
descendantkeys.forEach(function (key) {
|
|
520
|
+
delete controlsRemoved[key];
|
|
521
|
+
});
|
|
522
|
+
// Remove control and all descendants
|
|
523
|
+
var controlRemoved = Object.entries(controlsRemoved).reduce(function (acc, _a) {
|
|
524
|
+
var _b, _c;
|
|
525
|
+
var key = _a[0], control = _a[1];
|
|
526
|
+
// May need to reindex array items of removed control
|
|
527
|
+
// if it was part of a Form Array.
|
|
528
|
+
if (parentIsFormArray) {
|
|
529
|
+
var oldIndex = control.controlRef.at(parentRef.length);
|
|
530
|
+
if (
|
|
531
|
+
// If control is descendant.
|
|
532
|
+
parentRef.every(function (ref, index) { return control.controlRef[index] === ref; }) &&
|
|
533
|
+
control.controlRef.length > parentRef.length &&
|
|
534
|
+
// If the array item index was greater than the index of item removed
|
|
535
|
+
// we need to decrement its index by 1.
|
|
536
|
+
oldIndex > controlRef.at(-1)) {
|
|
537
|
+
var newRef = parentRef
|
|
538
|
+
.concat(oldIndex - 1)
|
|
539
|
+
.concat(control.controlRef.slice(parentRef.length + 1));
|
|
540
|
+
return __assign(__assign({}, acc), (_b = {}, _b[getFormKey(newRef)] = __assign(__assign({}, control), { controlRef: newRef }), _b));
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
return __assign(__assign({}, acc), (_c = {}, _c[key] = control, _c));
|
|
544
|
+
}, {});
|
|
545
|
+
var result = updateAncestorValuesRemoveControl(controlRemoved, {
|
|
546
|
+
payload: controlRef
|
|
547
|
+
}, providers);
|
|
548
|
+
var _changedControls = __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), getAncestorControls(controlRef.slice(0, -1), result).reduce(function (acc, control) {
|
|
549
|
+
var _a;
|
|
550
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[control.key] = control, _a)));
|
|
551
|
+
}, {}));
|
|
552
|
+
// Check for reindexing for changed controls
|
|
553
|
+
if (parentIsFormArray) {
|
|
554
|
+
_changedControls = Object.entries(_changedControls).reduce(function (acc, _a) {
|
|
555
|
+
var _b, _c;
|
|
556
|
+
var key = _a[0], control = _a[1];
|
|
557
|
+
var oldIndex = control.controlRef.at(parentRef.length);
|
|
558
|
+
if (
|
|
559
|
+
// If control is descendant.
|
|
560
|
+
parentRef.every(function (ref, index) { return control.controlRef[index] === ref; }) &&
|
|
561
|
+
control.controlRef.length > parentRef.length &&
|
|
562
|
+
// If the array item index was greater than the index of item removed
|
|
563
|
+
// we need to decrement its index by 1.
|
|
564
|
+
oldIndex > controlRef.at(-1)) {
|
|
565
|
+
var newRef = parentRef
|
|
566
|
+
.concat(oldIndex - 1)
|
|
567
|
+
.concat(control.controlRef.slice(parentRef.length + 1));
|
|
568
|
+
return __assign(__assign({}, acc), (_b = {}, _b[getFormKey(newRef)] = __assign(__assign({}, control), { controlRef: newRef }), _b));
|
|
569
|
+
}
|
|
570
|
+
else {
|
|
571
|
+
return __assign(__assign({}, acc), (_c = {}, _c[key] = control, _c));
|
|
572
|
+
}
|
|
573
|
+
}, {});
|
|
574
|
+
}
|
|
575
|
+
var _removedControls = __assign(__assign({}, (mergeChanges ? state._removedControls || {} : undefined)), (_a = {}, _a[controlToRemove.key] = controlToRemove, _a));
|
|
576
|
+
descendants
|
|
577
|
+
.map(function (_a) {
|
|
578
|
+
var key = _a.key;
|
|
579
|
+
return key;
|
|
580
|
+
})
|
|
581
|
+
.forEach(function (key) {
|
|
582
|
+
delete _changedControls[key];
|
|
583
|
+
});
|
|
584
|
+
return {
|
|
585
|
+
form: result,
|
|
586
|
+
_changedControls: _changedControls,
|
|
587
|
+
_removedControls: _removedControls
|
|
588
|
+
};
|
|
584
589
|
};
|
|
585
590
|
|
|
586
|
-
var
|
|
587
|
-
var
|
|
588
|
-
var
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
var
|
|
592
|
-
var
|
|
593
|
-
var
|
|
594
|
-
var
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
}
|
|
610
|
-
return form;
|
|
591
|
+
var updateAncestorValuesAddControl = function (form, _a, providers) {
|
|
592
|
+
var _b, _c;
|
|
593
|
+
var _d = _a.payload, controlRef = _d.controlRef, value = _d.value;
|
|
594
|
+
if (controlRef.length) {
|
|
595
|
+
var parentRef = controlRef.slice(0, -1);
|
|
596
|
+
var parentControl = getControl(parentRef, form);
|
|
597
|
+
var parentFormKey = getFormKey(parentControl.controlRef);
|
|
598
|
+
var childKey = controlRef.slice(-1)[0];
|
|
599
|
+
var newValue = void 0;
|
|
600
|
+
// If parent is a Form Array
|
|
601
|
+
if (Array.isArray(parentControl.value)) {
|
|
602
|
+
newValue = parentControl.value.concat(value);
|
|
603
|
+
}
|
|
604
|
+
else {
|
|
605
|
+
// If parent is a Form Group
|
|
606
|
+
newValue = __assign(__assign({}, form[parentFormKey].value), (_b = {}, _b[childKey] = value, _b));
|
|
607
|
+
}
|
|
608
|
+
var newParentControl = __assign(__assign({}, parentControl), { value: newValue, validatorErrors: getErrors(parentControl, newValue, providers), dirty: !isEqual(newValue, parentControl.pristineValue) });
|
|
609
|
+
return updateAncestorValues(__assign(__assign({}, form), (_c = {}, _c[parentFormKey] = newParentControl, _c)), {
|
|
610
|
+
payload: { controlRef: parentRef, value: newValue }
|
|
611
|
+
}, providers);
|
|
612
|
+
}
|
|
613
|
+
return form;
|
|
611
614
|
};
|
|
612
615
|
|
|
613
|
-
var getControlBranch = function (controlRef, form) {
|
|
614
|
-
var ancestors = getAncestorControls(controlRef, form);
|
|
615
|
-
var childControls = getDescendantControls(controlRef, form).slice(1);
|
|
616
|
-
return ancestors.concat(childControls).sort(function (a, b) { return a.controlRef.length - b.controlRef.length; });
|
|
616
|
+
var getControlBranch = function (controlRef, form) {
|
|
617
|
+
var ancestors = getAncestorControls(controlRef, form);
|
|
618
|
+
var childControls = getDescendantControls(controlRef, form).slice(1);
|
|
619
|
+
return ancestors.concat(childControls).sort(function (a, b) { return a.controlRef.length - b.controlRef.length; });
|
|
617
620
|
};
|
|
618
621
|
|
|
619
|
-
var addControl = function (state, action, providers, mergeChanges) {
|
|
620
|
-
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
621
|
-
var _a = action.payload, config = _a.config, controlRef = _a.controlRef;
|
|
622
|
-
controlRefCheck(controlRef);
|
|
623
|
-
// If controlRef does not exist we are adding control to a Form Group
|
|
624
|
-
if (!getControl(controlRef.slice(0, -1), state.form)) {
|
|
625
|
-
throw 'You are attempting to add a control to a non-existent form group';
|
|
626
|
-
}
|
|
627
|
-
var newForm = buildState(config, state.form, controlRef, providers);
|
|
628
|
-
var newValue = getControl(controlRef, newForm).value;
|
|
629
|
-
var ancestorsUpdated = updateAncestorValuesAddControl(newForm, {
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
};
|
|
622
|
+
var addControl = function (state, action, providers, mergeChanges) {
|
|
623
|
+
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
624
|
+
var _a = action.payload, config = _a.config, controlRef = _a.controlRef;
|
|
625
|
+
controlRefCheck(controlRef);
|
|
626
|
+
// If controlRef does not exist we are adding control to a Form Group
|
|
627
|
+
if (!getControl(controlRef.slice(0, -1), state.form)) {
|
|
628
|
+
throw 'You are attempting to add a control to a non-existent form group';
|
|
629
|
+
}
|
|
630
|
+
var newForm = buildState(config, state.form, controlRef, providers);
|
|
631
|
+
var newValue = getControl(controlRef, newForm).value;
|
|
632
|
+
var ancestorsUpdated = updateAncestorValuesAddControl(newForm, {
|
|
633
|
+
payload: { controlRef: controlRef, value: newValue }
|
|
634
|
+
}, providers);
|
|
635
|
+
var _changedControls = getControlBranch(controlRef, ancestorsUpdated).reduce(function (acc, control) {
|
|
636
|
+
var _a;
|
|
637
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[control.key] = control, _a)));
|
|
638
|
+
}, {});
|
|
639
|
+
return {
|
|
640
|
+
form: ancestorsUpdated,
|
|
641
|
+
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
642
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
643
|
+
};
|
|
642
644
|
};
|
|
643
645
|
|
|
644
|
-
var pushControl = function (state, action, providers, mergeChanges) {
|
|
645
|
-
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
646
|
-
var newControlRef;
|
|
647
|
-
var _a = action.payload, config = _a.config, controlRef = _a.controlRef;
|
|
648
|
-
controlRefCheck(controlRef);
|
|
649
|
-
var existingControl = getControl(controlRef, state.form);
|
|
650
|
-
if (!existingControl)
|
|
651
|
-
throw 'You are attempting to push to a control that does not exist';
|
|
652
|
-
// If controlRef exists we are adding control to a Form Array
|
|
653
|
-
if (Array.isArray(existingControl.config.controls)) {
|
|
654
|
-
newControlRef = controlRef.concat(existingControl.value.length);
|
|
655
|
-
}
|
|
656
|
-
else {
|
|
657
|
-
throw 'You are attempting to push to a control that is not a Form Array';
|
|
658
|
-
}
|
|
659
|
-
var newForm = buildState(config, state.form, newControlRef, providers);
|
|
660
|
-
var newValue = getControl(newControlRef, newForm).value;
|
|
661
|
-
var ancestorsUpdated = updateAncestorValuesAddControl(newForm, {
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
};
|
|
646
|
+
var pushControl = function (state, action, providers, mergeChanges) {
|
|
647
|
+
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
648
|
+
var newControlRef;
|
|
649
|
+
var _a = action.payload, config = _a.config, controlRef = _a.controlRef;
|
|
650
|
+
controlRefCheck(controlRef);
|
|
651
|
+
var existingControl = getControl(controlRef, state.form);
|
|
652
|
+
if (!existingControl)
|
|
653
|
+
throw 'You are attempting to push to a control that does not exist';
|
|
654
|
+
// If controlRef exists we are adding control to a Form Array
|
|
655
|
+
if (Array.isArray(existingControl.config.controls)) {
|
|
656
|
+
newControlRef = controlRef.concat(existingControl.value.length);
|
|
657
|
+
}
|
|
658
|
+
else {
|
|
659
|
+
throw 'You are attempting to push to a control that is not a Form Array';
|
|
660
|
+
}
|
|
661
|
+
var newForm = buildState(config, state.form, newControlRef, providers);
|
|
662
|
+
var newValue = getControl(newControlRef, newForm).value;
|
|
663
|
+
var ancestorsUpdated = updateAncestorValuesAddControl(newForm, {
|
|
664
|
+
payload: { controlRef: newControlRef, value: newValue }
|
|
665
|
+
}, providers);
|
|
666
|
+
var _changedControls = getControlBranch(newControlRef, ancestorsUpdated).reduce(function (acc, control) {
|
|
667
|
+
var _a;
|
|
668
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[control.key] = control, _a)));
|
|
669
|
+
}, {});
|
|
670
|
+
return {
|
|
671
|
+
form: ancestorsUpdated,
|
|
672
|
+
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
673
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
674
|
+
};
|
|
674
675
|
};
|
|
675
676
|
|
|
676
|
-
|
|
677
|
-
var
|
|
678
|
-
var
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
var
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
.
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
});
|
|
708
|
-
}
|
|
709
|
-
return form;
|
|
677
|
+
var updateAncestorPristineValues = function (form, _a) {
|
|
678
|
+
var _b;
|
|
679
|
+
var controlRef = _a.payload;
|
|
680
|
+
if (controlRef.length) {
|
|
681
|
+
var parentRef = controlRef.slice(0, -1);
|
|
682
|
+
var parentKey = getFormKey(parentRef);
|
|
683
|
+
var siblingControls = getDescendantControls(parentRef, form).filter(
|
|
684
|
+
// Out of descendants we only need the siblings
|
|
685
|
+
function (control) { return control.controlRef.length === controlRef.length; });
|
|
686
|
+
var newValue = void 0;
|
|
687
|
+
// If parent is a Form Array
|
|
688
|
+
if (Array.isArray(form[parentKey].value)) {
|
|
689
|
+
newValue = siblingControls
|
|
690
|
+
.slice()
|
|
691
|
+
.sort(function (a, b) { return a.controlRef.at(-1) - b.controlRef.at(-1); })
|
|
692
|
+
.map(function (control) { return control.pristineValue; });
|
|
693
|
+
}
|
|
694
|
+
else {
|
|
695
|
+
// If parent is a Form Group
|
|
696
|
+
newValue = siblingControls.reduce(function (acc, _a) {
|
|
697
|
+
var _b;
|
|
698
|
+
var controlRef = _a.controlRef, pristineValue = _a.pristineValue;
|
|
699
|
+
return __assign(__assign({}, acc), (_b = {}, _b[controlRef.at(-1)] = pristineValue, _b));
|
|
700
|
+
}, {});
|
|
701
|
+
}
|
|
702
|
+
var newParentControl = __assign(__assign({}, form[parentKey]), { pristineValue: newValue, dirty: isEqual(form[parentKey].value, newValue) });
|
|
703
|
+
return updateAncestorPristineValues(__assign(__assign({}, form), (_b = {}, _b[parentKey] = newParentControl, _b)), {
|
|
704
|
+
payload: parentRef
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
return form;
|
|
710
708
|
};
|
|
711
709
|
|
|
712
|
-
var markControlAsPristine = function (state, action, mergeChanges) {
|
|
713
|
-
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
714
|
-
var form = state.form;
|
|
715
|
-
var controlRef = action.payload;
|
|
716
|
-
controlRefCheck(controlRef);
|
|
717
|
-
var descendants = getDescendantControls(controlRef, form).reduce(function (acc, control) {
|
|
718
|
-
var _a;
|
|
719
|
-
return (__assign(__assign({}, acc), (_a = {}, _a[getFormKey(control.controlRef)] = __assign(__assign({}, control), { dirty: false, pristineValue: control.value }), _a)));
|
|
720
|
-
}, {});
|
|
721
|
-
var result = __assign(__assign({}, form), descendants);
|
|
722
|
-
if (controlRef.length) {
|
|
723
|
-
result = updateAncestorPristineValues(result, {
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
};
|
|
710
|
+
var markControlAsPristine = function (state, action, mergeChanges) {
|
|
711
|
+
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
712
|
+
var form = state.form;
|
|
713
|
+
var controlRef = action.payload;
|
|
714
|
+
controlRefCheck(controlRef);
|
|
715
|
+
var descendants = getDescendantControls(controlRef, form).reduce(function (acc, control) {
|
|
716
|
+
var _a;
|
|
717
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[getFormKey(control.controlRef)] = __assign(__assign({}, control), { dirty: false, pristineValue: control.value }), _a)));
|
|
718
|
+
}, {});
|
|
719
|
+
var result = __assign(__assign({}, form), descendants);
|
|
720
|
+
if (controlRef.length) {
|
|
721
|
+
result = updateAncestorPristineValues(result, {
|
|
722
|
+
payload: controlRef
|
|
723
|
+
});
|
|
724
|
+
}
|
|
725
|
+
var _changedControls = getControlBranch(controlRef, result).reduce(function (acc, control) {
|
|
726
|
+
var _a;
|
|
727
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[control.key] = control, _a)));
|
|
728
|
+
}, {});
|
|
729
|
+
return {
|
|
730
|
+
form: result,
|
|
731
|
+
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
732
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
733
|
+
};
|
|
737
734
|
};
|
|
738
735
|
|
|
739
|
-
var markControlAsTouched = function (state, action, mergeChanges) {
|
|
740
|
-
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
741
|
-
var form = state.form;
|
|
742
|
-
var _a = action.payload, controlRef = _a.controlRef, _b = _a.markAll, markAll = _b === void 0 ? false : _b;
|
|
743
|
-
controlRefCheck(controlRef);
|
|
744
|
-
var controls = (markAll ? getControlBranch(controlRef, form) : getAncestorControls(controlRef, form)).reduce(function (acc, control) {
|
|
745
|
-
var _a;
|
|
746
|
-
return (__assign(__assign({}, acc), (_a = {}, _a[getFormKey(control.controlRef)] = __assign(__assign({}, control), { touched: true }), _a)));
|
|
747
|
-
}, {});
|
|
748
|
-
var result = {
|
|
749
|
-
form: __assign(__assign({}, form), controls)
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
760
|
-
};
|
|
736
|
+
var markControlAsTouched = function (state, action, mergeChanges) {
|
|
737
|
+
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
738
|
+
var form = state.form;
|
|
739
|
+
var _a = action.payload, controlRef = _a.controlRef, _b = _a.markAll, markAll = _b === void 0 ? false : _b;
|
|
740
|
+
controlRefCheck(controlRef);
|
|
741
|
+
var controls = (markAll ? getControlBranch(controlRef, form) : getAncestorControls(controlRef, form)).reduce(function (acc, control) {
|
|
742
|
+
var _a;
|
|
743
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[getFormKey(control.controlRef)] = __assign(__assign({}, control), { touched: true }), _a)));
|
|
744
|
+
}, {});
|
|
745
|
+
var result = {
|
|
746
|
+
form: __assign(__assign({}, form), controls)};
|
|
747
|
+
var _changedControls = getControlBranch(controlRef, result.form).reduce(function (acc, control) {
|
|
748
|
+
var _a;
|
|
749
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[control.key] = control, _a)));
|
|
750
|
+
}, {});
|
|
751
|
+
return {
|
|
752
|
+
form: __assign(__assign({}, form), controls),
|
|
753
|
+
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
754
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
755
|
+
};
|
|
761
756
|
};
|
|
762
757
|
|
|
763
|
-
var markControlAsUntouched = function (state, action, mergeChanges) {
|
|
764
|
-
var _a;
|
|
765
|
-
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
766
|
-
var form = state.form;
|
|
767
|
-
var controlRef = action.payload;
|
|
768
|
-
controlRefCheck(controlRef);
|
|
769
|
-
var result = getDescendantControls(controlRef, form).reduce(function (acc, control) {
|
|
770
|
-
var _a;
|
|
771
|
-
return (__assign(__assign({}, acc), (_a = {}, _a[getFormKey(control.controlRef)] = __assign(__assign({}, control), { touched: false }), _a)));
|
|
772
|
-
}, {});
|
|
773
|
-
result = __assign(__assign({}, form), result);
|
|
774
|
-
// Update ancestors
|
|
775
|
-
var currentRef = controlRef;
|
|
776
|
-
var key;
|
|
777
|
-
while (currentRef.length > 0) {
|
|
778
|
-
currentRef = currentRef.slice(0, -1);
|
|
779
|
-
key = getFormKey(currentRef);
|
|
780
|
-
result = __assign(__assign({}, result), (_a = {}, _a[key] = __assign(__assign({}, result[key]), { touched: getDescendantControls(currentRef, result, true).some(function (control) { return control.touched; }) }), _a));
|
|
781
|
-
}
|
|
782
|
-
var _changedControls = getControlBranch(controlRef, result).reduce(function (acc, control) {
|
|
783
|
-
var _a;
|
|
784
|
-
return (__assign(__assign({}, acc), (_a = {}, _a[control.key] = control, _a)));
|
|
785
|
-
}, {});
|
|
786
|
-
return {
|
|
787
|
-
form: result,
|
|
788
|
-
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
789
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
790
|
-
};
|
|
758
|
+
var markControlAsUntouched = function (state, action, mergeChanges) {
|
|
759
|
+
var _a;
|
|
760
|
+
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
761
|
+
var form = state.form;
|
|
762
|
+
var controlRef = action.payload;
|
|
763
|
+
controlRefCheck(controlRef);
|
|
764
|
+
var result = getDescendantControls(controlRef, form).reduce(function (acc, control) {
|
|
765
|
+
var _a;
|
|
766
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[getFormKey(control.controlRef)] = __assign(__assign({}, control), { touched: false }), _a)));
|
|
767
|
+
}, {});
|
|
768
|
+
result = __assign(__assign({}, form), result);
|
|
769
|
+
// Update ancestors
|
|
770
|
+
var currentRef = controlRef;
|
|
771
|
+
var key;
|
|
772
|
+
while (currentRef.length > 0) {
|
|
773
|
+
currentRef = currentRef.slice(0, -1);
|
|
774
|
+
key = getFormKey(currentRef);
|
|
775
|
+
result = __assign(__assign({}, result), (_a = {}, _a[key] = __assign(__assign({}, result[key]), { touched: getDescendantControls(currentRef, result, true).some(function (control) { return control.touched; }) }), _a));
|
|
776
|
+
}
|
|
777
|
+
var _changedControls = getControlBranch(controlRef, result).reduce(function (acc, control) {
|
|
778
|
+
var _a;
|
|
779
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[control.key] = control, _a)));
|
|
780
|
+
}, {});
|
|
781
|
+
return {
|
|
782
|
+
form: result,
|
|
783
|
+
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
784
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
785
|
+
};
|
|
791
786
|
};
|
|
792
787
|
|
|
793
|
-
var resetControl = function (state, action, providers, mergeChanges) {
|
|
794
|
-
var _a;
|
|
795
|
-
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
796
|
-
var form = state.form;
|
|
797
|
-
var controlRef = action.payload;
|
|
798
|
-
controlRefCheck(controlRef);
|
|
799
|
-
var controlToReset = getControl(controlRef, form);
|
|
800
|
-
var descendantsRemoved = __assign({}, form);
|
|
801
|
-
var descendants = getDescendantControls(controlRef, form);
|
|
802
|
-
var descendantKeys = descendants.map(function (_a) {
|
|
803
|
-
var controlRef = _a.controlRef;
|
|
804
|
-
return getFormKey(controlRef);
|
|
805
|
-
});
|
|
806
|
-
descendantKeys.forEach(function (key) {
|
|
807
|
-
delete descendantsRemoved[key];
|
|
808
|
-
});
|
|
809
|
-
// Remove all descendants
|
|
810
|
-
var restoredControls = buildState(controlToReset.config, descendantsRemoved, controlToReset.controlRef, providers);
|
|
811
|
-
var restoredControlValue = getControl(controlRef, restoredControls).value;
|
|
812
|
-
var result = updateAncestorValues(restoredControls, {
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
},
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
}, {}));
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
};
|
|
788
|
+
var resetControl = function (state, action, providers, mergeChanges) {
|
|
789
|
+
var _a;
|
|
790
|
+
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
791
|
+
var form = state.form;
|
|
792
|
+
var controlRef = action.payload;
|
|
793
|
+
controlRefCheck(controlRef);
|
|
794
|
+
var controlToReset = getControl(controlRef, form);
|
|
795
|
+
var descendantsRemoved = __assign({}, form);
|
|
796
|
+
var descendants = getDescendantControls(controlRef, form);
|
|
797
|
+
var descendantKeys = descendants.map(function (_a) {
|
|
798
|
+
var controlRef = _a.controlRef;
|
|
799
|
+
return getFormKey(controlRef);
|
|
800
|
+
});
|
|
801
|
+
descendantKeys.forEach(function (key) {
|
|
802
|
+
delete descendantsRemoved[key];
|
|
803
|
+
});
|
|
804
|
+
// Remove all descendants
|
|
805
|
+
var restoredControls = buildState(controlToReset.config, descendantsRemoved, controlToReset.controlRef, providers);
|
|
806
|
+
var restoredControlValue = getControl(controlRef, restoredControls).value;
|
|
807
|
+
var result = updateAncestorValues(restoredControls, {
|
|
808
|
+
payload: { controlRef: controlRef, value: restoredControlValue }
|
|
809
|
+
}, providers);
|
|
810
|
+
var _changedControls = __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), getControlBranch(controlRef, result).reduce(function (acc, control) {
|
|
811
|
+
var _a;
|
|
812
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[control.key] = control, _a)));
|
|
813
|
+
}, {}));
|
|
814
|
+
var _removedControls = __assign(__assign({}, (mergeChanges ? state._removedControls || {} : undefined)), (_a = {}, _a[controlToReset.key] = controlToReset, _a));
|
|
815
|
+
// If control is removed, we can delete it from the _changedControls check
|
|
816
|
+
descendants
|
|
817
|
+
.map(function (_a) {
|
|
818
|
+
var key = _a.key;
|
|
819
|
+
return key;
|
|
820
|
+
})
|
|
821
|
+
.forEach(function (key) {
|
|
822
|
+
delete _changedControls[key];
|
|
823
|
+
});
|
|
824
|
+
return {
|
|
825
|
+
form: result,
|
|
826
|
+
_changedControls: _changedControls,
|
|
827
|
+
_removedControls: _removedControls
|
|
828
|
+
};
|
|
835
829
|
};
|
|
836
830
|
|
|
837
|
-
var asyncValidation = function (form, _a) {
|
|
838
|
-
var controlRef = _a.payload
|
|
839
|
-
var updatedSelfAndAncestors = getAncestorControls(controlRef, form).reduce(function (acc, control) {
|
|
840
|
-
var _a;
|
|
841
|
-
var isChangedControl = getFormKey(control.controlRef) === getFormKey(controlRef);
|
|
842
|
-
return __assign(__assign({}, acc), (_a = {}, _a[getFormKey(control.controlRef)] = __assign(__assign({}, control), { pending: true,
|
|
843
|
-
? __assign({}, control.config.asyncValidators.reduce(function (acc, _, index) {
|
|
844
|
-
var _a;
|
|
845
|
-
return (__assign(__assign({}, acc), (_a = {}, _a[index] = true, _a)));
|
|
846
|
-
}, {})) : control.asyncValidateInProgress }), _a));
|
|
847
|
-
}, {});
|
|
848
|
-
return __assign(__assign({}, form), updatedSelfAndAncestors);
|
|
831
|
+
var asyncValidation = function (form, _a) {
|
|
832
|
+
var controlRef = _a.payload;
|
|
833
|
+
var updatedSelfAndAncestors = getAncestorControls(controlRef, form).reduce(function (acc, control) {
|
|
834
|
+
var _a;
|
|
835
|
+
var isChangedControl = getFormKey(control.controlRef) === getFormKey(controlRef);
|
|
836
|
+
return __assign(__assign({}, acc), (_a = {}, _a[getFormKey(control.controlRef)] = __assign(__assign({}, control), { pending: true, asyncValidateInProgress: isChangedControl
|
|
837
|
+
? __assign({}, control.config.asyncValidators.reduce(function (acc, _, index) {
|
|
838
|
+
var _a;
|
|
839
|
+
return (__assign(__assign({}, acc), (_a = {}, _a[index] = true, _a)));
|
|
840
|
+
}, {})) : control.asyncValidateInProgress }), _a));
|
|
841
|
+
}, {});
|
|
842
|
+
return __assign(__assign({}, form), updatedSelfAndAncestors);
|
|
849
843
|
};
|
|
850
844
|
|
|
851
|
-
var reverseObjectKeys = function (form) {
|
|
852
|
-
return Object.keys(form)
|
|
853
|
-
.reverse()
|
|
854
|
-
.reduce(function (acc, key) {
|
|
855
|
-
acc[key] = form[key];
|
|
856
|
-
return acc;
|
|
857
|
-
}, {});
|
|
845
|
+
var reverseObjectKeys = function (form) {
|
|
846
|
+
return Object.keys(form)
|
|
847
|
+
.reverse()
|
|
848
|
+
.reduce(function (acc, key) {
|
|
849
|
+
acc[key] = form[key];
|
|
850
|
+
return acc;
|
|
851
|
+
}, {});
|
|
858
852
|
};
|
|
859
853
|
|
|
860
|
-
var hasErrors$3 = function (errors) {
|
|
861
|
-
return Object.values(errors).some(function (hasError) { return hasError; });
|
|
862
|
-
};
|
|
863
|
-
var mergeBranchErrors = function (form, controlRef) {
|
|
864
|
-
var controlBranch = getControlBranch(controlRef, form).reduce(function (acc, ctrl) {
|
|
865
|
-
var _a;
|
|
866
|
-
return __assign(__assign({}, acc), (_a = {}, _a[getFormKey(ctrl.controlRef)] = ctrl, _a));
|
|
867
|
-
}, {});
|
|
868
|
-
var errorsMerged = Object.entries(controlBranch)
|
|
869
|
-
.reverse()
|
|
870
|
-
.reduce(function (acc, _a) {
|
|
871
|
-
var _b;
|
|
872
|
-
var key = _a[0], control = _a[1];
|
|
873
|
-
var errors = __assign(__assign({}, control.validatorErrors), control.asyncValidatorErrors);
|
|
874
|
-
var selfValid = !hasErrors$3(errors);
|
|
875
|
-
var childrenValid = true;
|
|
876
|
-
if (Array.isArray(control.config.controls)) {
|
|
877
|
-
// If control is a FormArray
|
|
878
|
-
childrenValid = control.value.every(function (item, index) {
|
|
879
|
-
var formKey = getFormKey(control.controlRef.concat(index));
|
|
880
|
-
var valid = acc[formKey] === undefined ? form[formKey].valid : acc[formKey].valid;
|
|
881
|
-
return valid;
|
|
882
|
-
});
|
|
883
|
-
}
|
|
884
|
-
else if (control.config.controls) {
|
|
885
|
-
// If control is a FormGroup
|
|
886
|
-
childrenValid = Object.keys(control.value).every(function (childKey) {
|
|
887
|
-
var formKey = getFormKey(control.controlRef.concat(childKey));
|
|
888
|
-
var valid = acc[formKey] === undefined ? form[formKey].valid : acc[formKey].valid;
|
|
889
|
-
return valid;
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
return __assign(__assign({}, acc), (_b = {}, _b[key] = __assign(__assign({}, control), { errors: errors, valid: selfValid && childrenValid
|
|
893
|
-
}, {});
|
|
894
|
-
var errorsMergedOrderRestored = reverseObjectKeys(errorsMerged);
|
|
895
|
-
return __assign(__assign({}, form), errorsMergedOrderRestored);
|
|
854
|
+
var hasErrors$3 = function (errors) {
|
|
855
|
+
return Object.values(errors).some(function (hasError) { return hasError; });
|
|
856
|
+
};
|
|
857
|
+
var mergeBranchErrors = function (form, controlRef) {
|
|
858
|
+
var controlBranch = getControlBranch(controlRef, form).reduce(function (acc, ctrl) {
|
|
859
|
+
var _a;
|
|
860
|
+
return __assign(__assign({}, acc), (_a = {}, _a[getFormKey(ctrl.controlRef)] = ctrl, _a));
|
|
861
|
+
}, {});
|
|
862
|
+
var errorsMerged = Object.entries(controlBranch)
|
|
863
|
+
.reverse()
|
|
864
|
+
.reduce(function (acc, _a) {
|
|
865
|
+
var _b;
|
|
866
|
+
var key = _a[0], control = _a[1];
|
|
867
|
+
var errors = __assign(__assign({}, control.validatorErrors), control.asyncValidatorErrors);
|
|
868
|
+
var selfValid = !hasErrors$3(errors);
|
|
869
|
+
var childrenValid = true;
|
|
870
|
+
if (Array.isArray(control.config.controls)) {
|
|
871
|
+
// If control is a FormArray
|
|
872
|
+
childrenValid = control.value.every(function (item, index) {
|
|
873
|
+
var formKey = getFormKey(control.controlRef.concat(index));
|
|
874
|
+
var valid = acc[formKey] === undefined ? form[formKey].valid : acc[formKey].valid;
|
|
875
|
+
return valid;
|
|
876
|
+
});
|
|
877
|
+
}
|
|
878
|
+
else if (control.config.controls) {
|
|
879
|
+
// If control is a FormGroup
|
|
880
|
+
childrenValid = Object.keys(control.value).every(function (childKey) {
|
|
881
|
+
var formKey = getFormKey(control.controlRef.concat(childKey));
|
|
882
|
+
var valid = acc[formKey] === undefined ? form[formKey].valid : acc[formKey].valid;
|
|
883
|
+
return valid;
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
return __assign(__assign({}, acc), (_b = {}, _b[key] = __assign(__assign({}, control), { errors: errors, valid: selfValid && childrenValid, childrenValid: childrenValid }), _b));
|
|
887
|
+
}, {});
|
|
888
|
+
var errorsMergedOrderRestored = reverseObjectKeys(errorsMerged);
|
|
889
|
+
return __assign(__assign({}, form), errorsMergedOrderRestored);
|
|
896
890
|
};
|
|
897
891
|
|
|
898
|
-
var isControlValidating = function (control) {
|
|
899
|
-
if (!control.asyncValidateInProgress)
|
|
900
|
-
return false;
|
|
901
|
-
return Object.values(control.asyncValidateInProgress).some(function (pending) { return pending; });
|
|
902
|
-
};
|
|
903
|
-
var getControlByKey = function (key, form) {
|
|
904
|
-
return Object.values(form).find(function (control) { return control.key === key; });
|
|
905
|
-
};
|
|
906
|
-
var
|
|
907
|
-
var _b, _c;
|
|
908
|
-
var _d = _a.payload, key = _d.key, validatorIndex = _d.validatorIndex, errors = _d.errors;
|
|
909
|
-
var control = getControlByKey(key, form);
|
|
910
|
-
if (!control) {
|
|
911
|
-
return form;
|
|
912
|
-
}
|
|
913
|
-
var controlUpdated = __assign(__assign({}, form), (_b = {}, _b[getFormKey(control.controlRef)] = __assign(__assign({}, control), { asyncValidateInProgress: __assign(__assign({}, control.asyncValidateInProgress), (_c = {}, _c[validatorIndex] = false, _c)), asyncValidatorErrors: __assign(__assign({}, control.asyncValidatorErrors), errors) }), _b));
|
|
914
|
-
var ancestors = getAncestorControls(control.controlRef, controlUpdated);
|
|
915
|
-
var ancestorsUpdated = Object.entries(controlUpdated).reduce(function (acc, _a) {
|
|
916
|
-
var _b, _c;
|
|
917
|
-
var key = _a[0], control = _a[1];
|
|
918
|
-
if (ancestors.includes(control)) {
|
|
919
|
-
var descendants = getDescendantControls(control.controlRef, controlUpdated);
|
|
920
|
-
var pending_1 = descendants.some(function (control) { return isControlValidating(control); });
|
|
921
|
-
return __assign(__assign({}, acc), (_b = {}, _b[key] = __assign(__assign({}, control), { pending: pending_1 }), _b));
|
|
922
|
-
}
|
|
923
|
-
return __assign(__assign({}, acc), (_c = {}, _c[key] = control, _c));
|
|
924
|
-
}, {});
|
|
925
|
-
return mergeBranchErrors(ancestorsUpdated, control.controlRef);
|
|
892
|
+
var isControlValidating = function (control) {
|
|
893
|
+
if (!control.asyncValidateInProgress)
|
|
894
|
+
return false;
|
|
895
|
+
return Object.values(control.asyncValidateInProgress).some(function (pending) { return pending; });
|
|
896
|
+
};
|
|
897
|
+
var getControlByKey = function (key, form) {
|
|
898
|
+
return Object.values(form).find(function (control) { return control.key === key; });
|
|
899
|
+
};
|
|
900
|
+
var asyncValidationResponse = function (form, _a) {
|
|
901
|
+
var _b, _c;
|
|
902
|
+
var _d = _a.payload, key = _d.key, validatorIndex = _d.validatorIndex, errors = _d.errors;
|
|
903
|
+
var control = getControlByKey(key, form);
|
|
904
|
+
if (!control) {
|
|
905
|
+
return form;
|
|
906
|
+
}
|
|
907
|
+
var controlUpdated = __assign(__assign({}, form), (_b = {}, _b[getFormKey(control.controlRef)] = __assign(__assign({}, control), { asyncValidateInProgress: __assign(__assign({}, control.asyncValidateInProgress), (_c = {}, _c[validatorIndex] = false, _c)), asyncValidatorErrors: __assign(__assign({}, control.asyncValidatorErrors), errors) }), _b));
|
|
908
|
+
var ancestors = getAncestorControls(control.controlRef, controlUpdated);
|
|
909
|
+
var ancestorsUpdated = Object.entries(controlUpdated).reduce(function (acc, _a) {
|
|
910
|
+
var _b, _c;
|
|
911
|
+
var key = _a[0], control = _a[1];
|
|
912
|
+
if (ancestors.includes(control)) {
|
|
913
|
+
var descendants = getDescendantControls(control.controlRef, controlUpdated);
|
|
914
|
+
var pending_1 = descendants.some(function (control) { return isControlValidating(control); });
|
|
915
|
+
return __assign(__assign({}, acc), (_b = {}, _b[key] = __assign(__assign({}, control), { pending: pending_1 }), _b));
|
|
916
|
+
}
|
|
917
|
+
return __assign(__assign({}, acc), (_c = {}, _c[key] = control, _c));
|
|
918
|
+
}, {});
|
|
919
|
+
return mergeBranchErrors(ancestorsUpdated, control.controlRef);
|
|
926
920
|
};
|
|
927
921
|
|
|
928
|
-
var hasErrors$2 = function (errors) {
|
|
929
|
-
return Object.values(errors).some(function (hasError) { return hasError; });
|
|
930
|
-
};
|
|
931
|
-
// TODO: update merge errors to not do the entire form but just a subset of it
|
|
932
|
-
// TODO: separation of concern to update validity of control and ancestors
|
|
933
|
-
var mergeErrors = function (form) {
|
|
934
|
-
var errorsMerged = Object.entries(form)
|
|
935
|
-
.reverse()
|
|
936
|
-
.reduce(function (acc, _a) {
|
|
937
|
-
var _b;
|
|
938
|
-
var key = _a[0], control = _a[1];
|
|
939
|
-
var errors = __assign(__assign({}, control.validatorErrors), control.asyncValidatorErrors);
|
|
940
|
-
var selfValid = !hasErrors$2(errors);
|
|
941
|
-
var childrenValid = true;
|
|
942
|
-
if (Array.isArray(control.config.controls)) {
|
|
943
|
-
// If control is a FormArray
|
|
944
|
-
childrenValid = control.value.every(function (item, index) { return acc[getFormKey(control.controlRef.concat(index))].valid; });
|
|
945
|
-
}
|
|
946
|
-
else if (control.config.controls) {
|
|
947
|
-
// If control is a FormGroup
|
|
948
|
-
childrenValid = Object.keys(control.value).every(function (childKey) { return acc[getFormKey(control.controlRef.concat(childKey))].valid; });
|
|
949
|
-
}
|
|
950
|
-
return __assign(__assign({}, acc), (_b = {}, _b[key] = __assign(__assign({}, control), { errors: errors, valid: selfValid && childrenValid
|
|
951
|
-
}, {});
|
|
952
|
-
var restoredOrder = reverseObjectKeys(errorsMerged);
|
|
953
|
-
return restoredOrder;
|
|
922
|
+
var hasErrors$2 = function (errors) {
|
|
923
|
+
return Object.values(errors).some(function (hasError) { return hasError; });
|
|
924
|
+
};
|
|
925
|
+
// TODO: update merge errors to not do the entire form but just a subset of it
|
|
926
|
+
// TODO: separation of concern to update validity of control and ancestors
|
|
927
|
+
var mergeErrors = function (form) {
|
|
928
|
+
var errorsMerged = Object.entries(form)
|
|
929
|
+
.reverse()
|
|
930
|
+
.reduce(function (acc, _a) {
|
|
931
|
+
var _b;
|
|
932
|
+
var key = _a[0], control = _a[1];
|
|
933
|
+
var errors = __assign(__assign({}, control.validatorErrors), control.asyncValidatorErrors);
|
|
934
|
+
var selfValid = !hasErrors$2(errors);
|
|
935
|
+
var childrenValid = true;
|
|
936
|
+
if (Array.isArray(control.config.controls)) {
|
|
937
|
+
// If control is a FormArray
|
|
938
|
+
childrenValid = control.value.every(function (item, index) { return acc[getFormKey(control.controlRef.concat(index))].valid; });
|
|
939
|
+
}
|
|
940
|
+
else if (control.config.controls) {
|
|
941
|
+
// If control is a FormGroup
|
|
942
|
+
childrenValid = Object.keys(control.value).every(function (childKey) { return acc[getFormKey(control.controlRef.concat(childKey))].valid; });
|
|
943
|
+
}
|
|
944
|
+
return __assign(__assign({}, acc), (_b = {}, _b[key] = __assign(__assign({}, control), { errors: errors, valid: selfValid && childrenValid, childrenValid: childrenValid }), _b));
|
|
945
|
+
}, {});
|
|
946
|
+
var restoredOrder = reverseObjectKeys(errorsMerged);
|
|
947
|
+
return restoredOrder;
|
|
954
948
|
};
|
|
955
949
|
|
|
956
|
-
var hasErrors$1 = function (errors) {
|
|
957
|
-
return Object.values(errors).some(function (hasError) { return hasError; });
|
|
958
|
-
};
|
|
959
|
-
var mergeRemoveControl = function (state, form, controlRef) {
|
|
960
|
-
var parentRef = controlRef.slice(0, -1);
|
|
961
|
-
var existingBranch = getControlBranch(parentRef, state);
|
|
962
|
-
var updatedControlBranch = getControlBranch(parentRef, form)
|
|
963
|
-
.reverse()
|
|
964
|
-
.reduce(function (acc, baseControl) {
|
|
965
|
-
var _a;
|
|
966
|
-
var key = getFormKey(baseControl.controlRef);
|
|
967
|
-
var existingControl = existingBranch.find(function (control) { return baseControl.key === control.key; }) ||
|
|
968
|
-
structuredClone(DEFAULT_HUB2_FIELDS);
|
|
969
|
-
var errors = __assign(__assign({}, baseControl.validatorErrors), existingControl.asyncValidatorErrors);
|
|
970
|
-
var selfValid = !hasErrors$1(errors);
|
|
971
|
-
var childrenValid = true;
|
|
972
|
-
if (Array.isArray(baseControl.config.controls)) {
|
|
973
|
-
// If control is a FormArray
|
|
974
|
-
childrenValid = baseControl.value.every(function (item, index) {
|
|
975
|
-
var formKey = getFormKey(baseControl.controlRef.concat(index));
|
|
976
|
-
var valid = acc[formKey] === undefined ? state[formKey].valid : acc[formKey].valid;
|
|
977
|
-
return valid;
|
|
978
|
-
});
|
|
979
|
-
}
|
|
980
|
-
else if (baseControl.config.controls) {
|
|
981
|
-
// If control is a FormGroup
|
|
982
|
-
childrenValid = Object.keys(baseControl.value).every(function (childKey) {
|
|
983
|
-
var formKey = getFormKey(baseControl.controlRef.concat(childKey));
|
|
984
|
-
var valid = acc[formKey] === undefined ? state[formKey].valid : acc[formKey].valid;
|
|
985
|
-
return valid;
|
|
986
|
-
});
|
|
987
|
-
}
|
|
988
|
-
return __assign(__assign({}, acc), (_a = {}, _a[key] = __assign(__assign(__assign({}, existingControl), baseControl), { errors: errors, valid: selfValid && childrenValid
|
|
989
|
-
}, {});
|
|
990
|
-
var updatedControlBranchOrderRestored = reverseObjectKeys(updatedControlBranch);
|
|
991
|
-
var descendants = existingBranch.filter(function (control) { return control.controlRef.length > parentRef.length; });
|
|
992
|
-
var _removedControls = __assign({}, state);
|
|
993
|
-
descendants.forEach(function (control) {
|
|
994
|
-
delete _removedControls[getFormKey(control.controlRef)];
|
|
995
|
-
});
|
|
996
|
-
delete _removedControls[getFormKey(controlRef)];
|
|
997
|
-
return __assign(__assign({}, _removedControls), updatedControlBranchOrderRestored);
|
|
950
|
+
var hasErrors$1 = function (errors) {
|
|
951
|
+
return Object.values(errors).some(function (hasError) { return hasError; });
|
|
952
|
+
};
|
|
953
|
+
var mergeRemoveControl = function (state, form, controlRef) {
|
|
954
|
+
var parentRef = controlRef.slice(0, -1);
|
|
955
|
+
var existingBranch = getControlBranch(parentRef, state);
|
|
956
|
+
var updatedControlBranch = getControlBranch(parentRef, form)
|
|
957
|
+
.reverse()
|
|
958
|
+
.reduce(function (acc, baseControl) {
|
|
959
|
+
var _a;
|
|
960
|
+
var key = getFormKey(baseControl.controlRef);
|
|
961
|
+
var existingControl = existingBranch.find(function (control) { return baseControl.key === control.key; }) ||
|
|
962
|
+
structuredClone(DEFAULT_HUB2_FIELDS);
|
|
963
|
+
var errors = __assign(__assign({}, baseControl.validatorErrors), existingControl.asyncValidatorErrors);
|
|
964
|
+
var selfValid = !hasErrors$1(errors);
|
|
965
|
+
var childrenValid = true;
|
|
966
|
+
if (Array.isArray(baseControl.config.controls)) {
|
|
967
|
+
// If control is a FormArray
|
|
968
|
+
childrenValid = baseControl.value.every(function (item, index) {
|
|
969
|
+
var formKey = getFormKey(baseControl.controlRef.concat(index));
|
|
970
|
+
var valid = acc[formKey] === undefined ? state[formKey].valid : acc[formKey].valid;
|
|
971
|
+
return valid;
|
|
972
|
+
});
|
|
973
|
+
}
|
|
974
|
+
else if (baseControl.config.controls) {
|
|
975
|
+
// If control is a FormGroup
|
|
976
|
+
childrenValid = Object.keys(baseControl.value).every(function (childKey) {
|
|
977
|
+
var formKey = getFormKey(baseControl.controlRef.concat(childKey));
|
|
978
|
+
var valid = acc[formKey] === undefined ? state[formKey].valid : acc[formKey].valid;
|
|
979
|
+
return valid;
|
|
980
|
+
});
|
|
981
|
+
}
|
|
982
|
+
return __assign(__assign({}, acc), (_a = {}, _a[key] = __assign(__assign(__assign({}, existingControl), baseControl), { errors: errors, valid: selfValid && childrenValid, childrenValid: childrenValid }), _a));
|
|
983
|
+
}, {});
|
|
984
|
+
var updatedControlBranchOrderRestored = reverseObjectKeys(updatedControlBranch);
|
|
985
|
+
var descendants = existingBranch.filter(function (control) { return control.controlRef.length > parentRef.length; });
|
|
986
|
+
var _removedControls = __assign({}, state);
|
|
987
|
+
descendants.forEach(function (control) {
|
|
988
|
+
delete _removedControls[getFormKey(control.controlRef)];
|
|
989
|
+
});
|
|
990
|
+
delete _removedControls[getFormKey(controlRef)];
|
|
991
|
+
return __assign(__assign({}, _removedControls), updatedControlBranchOrderRestored);
|
|
998
992
|
};
|
|
999
993
|
|
|
1000
|
-
var hasErrors = function (errors) {
|
|
1001
|
-
return Object.values(errors).some(function (hasError) { return hasError; });
|
|
1002
|
-
};
|
|
1003
|
-
var mergeControls = function (state, _a) {
|
|
1004
|
-
var form = _a.form, _b = _a._changedControls, _changedControls = _b === void 0 ? {} : _b, _removedControls = _a._removedControls;
|
|
1005
|
-
var controlsRemoved = _removedControls
|
|
1006
|
-
? Object.values(_removedControls).reduce(function (acc, _a) {
|
|
1007
|
-
var controlRef = _a.controlRef;
|
|
1008
|
-
return mergeRemoveControl(acc, form, controlRef);
|
|
1009
|
-
}, state)
|
|
1010
|
-
: state;
|
|
1011
|
-
var updatedBranch = Object.values(_changedControls)
|
|
1012
|
-
.reverse()
|
|
1013
|
-
.reduce(function (acc, control) {
|
|
1014
|
-
var _a;
|
|
1015
|
-
var formKey = getFormKey(control.controlRef);
|
|
1016
|
-
var existingControl = controlsRemoved && controlsRemoved[formKey];
|
|
1017
|
-
var newControl = __assign(__assign({}, (existingControl
|
|
1018
|
-
? existingControl
|
|
1019
|
-
: structuredClone(DEFAULT_HUB2_FIELDS))), control);
|
|
1020
|
-
var errors = __assign(__assign({}, newControl.validatorErrors), newControl.asyncValidatorErrors);
|
|
1021
|
-
var selfValid = !hasErrors(errors);
|
|
1022
|
-
var childrenValid = true;
|
|
1023
|
-
if (Array.isArray(control.config.controls)) {
|
|
1024
|
-
// If control is a FormArray
|
|
1025
|
-
childrenValid = control.value.every(function (item, index) {
|
|
1026
|
-
var formKey = getFormKey(control.controlRef.concat(index));
|
|
1027
|
-
var valid = acc[formKey] === undefined ? controlsRemoved[formKey].valid : acc[formKey].valid;
|
|
1028
|
-
return valid;
|
|
1029
|
-
});
|
|
1030
|
-
}
|
|
1031
|
-
else if (control.config.controls) {
|
|
1032
|
-
// If control is a FormGroup
|
|
1033
|
-
childrenValid = Object.keys(control.value).every(function (childKey) {
|
|
1034
|
-
var formKey = getFormKey(control.controlRef.concat(childKey));
|
|
1035
|
-
var valid = acc[formKey] === undefined ? controlsRemoved[formKey].valid : acc[formKey].valid;
|
|
1036
|
-
return valid;
|
|
1037
|
-
});
|
|
1038
|
-
}
|
|
1039
|
-
return __assign(__assign({}, acc), (_a = {}, _a[formKey] = __assign(__assign({}, newControl), { errors: errors, valid: selfValid && childrenValid
|
|
1040
|
-
}, {});
|
|
1041
|
-
var orderRestored = reverseObjectKeys(updatedBranch);
|
|
1042
|
-
var result = __assign(__assign({}, controlsRemoved), orderRestored);
|
|
1043
|
-
return result;
|
|
994
|
+
var hasErrors = function (errors) {
|
|
995
|
+
return Object.values(errors).some(function (hasError) { return hasError; });
|
|
996
|
+
};
|
|
997
|
+
var mergeControls = function (state, _a) {
|
|
998
|
+
var form = _a.form, _b = _a._changedControls, _changedControls = _b === void 0 ? {} : _b, _removedControls = _a._removedControls;
|
|
999
|
+
var controlsRemoved = _removedControls
|
|
1000
|
+
? Object.values(_removedControls).reduce(function (acc, _a) {
|
|
1001
|
+
var controlRef = _a.controlRef;
|
|
1002
|
+
return mergeRemoveControl(acc, form, controlRef);
|
|
1003
|
+
}, state)
|
|
1004
|
+
: state;
|
|
1005
|
+
var updatedBranch = Object.values(_changedControls)
|
|
1006
|
+
.reverse()
|
|
1007
|
+
.reduce(function (acc, control) {
|
|
1008
|
+
var _a;
|
|
1009
|
+
var formKey = getFormKey(control.controlRef);
|
|
1010
|
+
var existingControl = controlsRemoved && controlsRemoved[formKey];
|
|
1011
|
+
var newControl = __assign(__assign({}, (existingControl
|
|
1012
|
+
? existingControl
|
|
1013
|
+
: structuredClone(DEFAULT_HUB2_FIELDS))), control);
|
|
1014
|
+
var errors = __assign(__assign({}, newControl.validatorErrors), newControl.asyncValidatorErrors);
|
|
1015
|
+
var selfValid = !hasErrors(errors);
|
|
1016
|
+
var childrenValid = true;
|
|
1017
|
+
if (Array.isArray(control.config.controls)) {
|
|
1018
|
+
// If control is a FormArray
|
|
1019
|
+
childrenValid = control.value.every(function (item, index) {
|
|
1020
|
+
var formKey = getFormKey(control.controlRef.concat(index));
|
|
1021
|
+
var valid = acc[formKey] === undefined ? controlsRemoved[formKey].valid : acc[formKey].valid;
|
|
1022
|
+
return valid;
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
else if (control.config.controls) {
|
|
1026
|
+
// If control is a FormGroup
|
|
1027
|
+
childrenValid = Object.keys(control.value).every(function (childKey) {
|
|
1028
|
+
var formKey = getFormKey(control.controlRef.concat(childKey));
|
|
1029
|
+
var valid = acc[formKey] === undefined ? controlsRemoved[formKey].valid : acc[formKey].valid;
|
|
1030
|
+
return valid;
|
|
1031
|
+
});
|
|
1032
|
+
}
|
|
1033
|
+
return __assign(__assign({}, acc), (_a = {}, _a[formKey] = __assign(__assign({}, newControl), { errors: errors, valid: selfValid && childrenValid, childrenValid: childrenValid }), _a));
|
|
1034
|
+
}, {});
|
|
1035
|
+
var orderRestored = reverseObjectKeys(updatedBranch);
|
|
1036
|
+
var result = __assign(__assign({}, controlsRemoved), orderRestored);
|
|
1037
|
+
return result;
|
|
1044
1038
|
};
|
|
1045
1039
|
|
|
1046
|
-
var formChange = function (state, _a) {
|
|
1047
|
-
if (state === void 0) { state = null; }
|
|
1048
|
-
var payload = _a.payload;
|
|
1049
|
-
var form = payload.form;
|
|
1050
|
-
if (state === null) {
|
|
1051
|
-
return mergeErrors(Object.entries(form).reduce(function (acc, _a) {
|
|
1052
|
-
var _b;
|
|
1053
|
-
var dictKey = _a[0], baseControl = _a[1];
|
|
1054
|
-
return __assign(__assign({}, acc), (_b = {}, _b[dictKey] = __assign(__assign({}, structuredClone(DEFAULT_HUB2_FIELDS)), baseControl), _b));
|
|
1055
|
-
}, {}));
|
|
1056
|
-
}
|
|
1057
|
-
return mergeControls(state, payload);
|
|
1040
|
+
var formChange = function (state, _a) {
|
|
1041
|
+
if (state === void 0) { state = null; }
|
|
1042
|
+
var payload = _a.payload;
|
|
1043
|
+
var form = payload.form;
|
|
1044
|
+
if (state === null) {
|
|
1045
|
+
return mergeErrors(Object.entries(form).reduce(function (acc, _a) {
|
|
1046
|
+
var _b;
|
|
1047
|
+
var dictKey = _a[0], baseControl = _a[1];
|
|
1048
|
+
return __assign(__assign({}, acc), (_b = {}, _b[dictKey] = __assign(__assign({}, structuredClone(DEFAULT_HUB2_FIELDS)), baseControl), _b));
|
|
1049
|
+
}, {}));
|
|
1050
|
+
}
|
|
1051
|
+
return mergeControls(state, payload);
|
|
1058
1052
|
};
|
|
1059
1053
|
|
|
1060
|
-
var control = function (config) {
|
|
1061
|
-
if (Array.isArray(config)) {
|
|
1062
|
-
return config.reduce(function (acc, item, index) {
|
|
1063
|
-
var _a;
|
|
1064
|
-
var indexMap = {
|
|
1065
|
-
0: 'initialValue',
|
|
1066
|
-
1: 'validators',
|
|
1067
|
-
2: 'asyncValidators'
|
|
1068
|
-
};
|
|
1069
|
-
return __assign(__assign({}, acc), (_a = {}, _a[indexMap[index]] = index < 1 ? item : [].concat(item || []), _a));
|
|
1070
|
-
}, {});
|
|
1071
|
-
}
|
|
1072
|
-
return config;
|
|
1073
|
-
};
|
|
1074
|
-
var array = function (config) { return config; };
|
|
1075
|
-
var group = function (config) { return config; };
|
|
1076
|
-
var reducerTools = function (providers) { return ({
|
|
1077
|
-
updateValues: function (state, payload) {
|
|
1078
|
-
return updateValues(state, { payload: payload }, providers, true);
|
|
1079
|
-
},
|
|
1080
|
-
removeControl: function (state, payload) {
|
|
1081
|
-
return removeControl(state, { payload: payload }, providers, true);
|
|
1082
|
-
},
|
|
1083
|
-
pushControl: function (state, payload) {
|
|
1084
|
-
return pushControl(state, { payload: payload }, providers, true);
|
|
1085
|
-
},
|
|
1086
|
-
addControl: function (state, payload) {
|
|
1087
|
-
return addControl(state, { payload: payload }, providers, true);
|
|
1088
|
-
},
|
|
1089
|
-
resetControl: function (state, payload) {
|
|
1090
|
-
return resetControl(state, { payload: payload }, providers, true);
|
|
1091
|
-
},
|
|
1092
|
-
markControlAsPristine: function (state, payload) {
|
|
1093
|
-
return markControlAsPristine(state, { payload: payload }, true);
|
|
1094
|
-
},
|
|
1095
|
-
markControlAsTouched: function (state, payload) {
|
|
1096
|
-
return markControlAsTouched(state, { payload: payload }, true);
|
|
1097
|
-
},
|
|
1098
|
-
markControlAsUntouched: function (state, payload) {
|
|
1099
|
-
return markControlAsUntouched(state, { payload: payload }, true);
|
|
1100
|
-
}
|
|
1101
|
-
}); };
|
|
1102
|
-
var build = function (config, options) {
|
|
1103
|
-
var _a, _b, _c;
|
|
1104
|
-
if (options === void 0) { options = {}; }
|
|
1105
|
-
var providers = {
|
|
1106
|
-
normalizers: __assign({}, (_a = options.providers) === null || _a === void 0 ? void 0 : _a.normalizers),
|
|
1107
|
-
validators: __assign(__assign({}, Validators), (_b = options.providers) === null || _b === void 0 ? void 0 : _b.validators),
|
|
1108
|
-
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators)
|
|
1109
|
-
};
|
|
1110
|
-
var initialState = buildFormState(config, undefined, undefined, providers);
|
|
1111
|
-
return createReactable(initialState, options);
|
|
1112
|
-
};
|
|
1113
|
-
var load = function (state, options) {
|
|
1114
|
-
if (options === void 0) { options = {}; }
|
|
1115
|
-
var baseFormState = {
|
|
1116
|
-
form: Object.entries(state).reduce(function (acc, _a) {
|
|
1117
|
-
var _b;
|
|
1118
|
-
var key = _a[0], control = _a[1];
|
|
1119
|
-
return __assign(__assign({}, acc), (_b = {}, _b[key] = Object.entries(control)
|
|
1120
|
-
.filter(function (_a) {
|
|
1121
|
-
var key = _a[0];
|
|
1122
|
-
return !Object.keys(DEFAULT_HUB2_FIELDS).includes(key);
|
|
1123
|
-
})
|
|
1124
|
-
.reduce(function (acc, _a) {
|
|
1125
|
-
var _b;
|
|
1126
|
-
var key = _a[0], value = _a[1];
|
|
1127
|
-
return (__assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)));
|
|
1128
|
-
}, {}), _b));
|
|
1129
|
-
}, {})
|
|
1130
|
-
};
|
|
1131
|
-
return createReactable(baseFormState, options);
|
|
1132
|
-
};
|
|
1133
|
-
var createReactable = function (initialBaseState, options, initialFormState) {
|
|
1134
|
-
var _a, _b, _c;
|
|
1135
|
-
if (options === void 0) { options = {}; }
|
|
1136
|
-
var providers = {
|
|
1137
|
-
normalizers: __assign({}, (_a = options.providers) === null || _a === void 0 ? void 0 : _a.normalizers),
|
|
1138
|
-
validators: __assign(__assign({}, Validators), (_b = options.providers) === null || _b === void 0 ? void 0 : _b.validators),
|
|
1139
|
-
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators)
|
|
1140
|
-
};
|
|
1141
|
-
var reducers = options.reducers, debug = options.debug, name = options.name,
|
|
1142
|
-
var customReducers = Object.entries(reducers || {}).reduce(function (acc, _a) {
|
|
1143
|
-
var _b;
|
|
1144
|
-
var key = _a[0], _case = _a[1];
|
|
1145
|
-
var _reducer = typeof _case === 'function' ? _case : _case.reducer;
|
|
1146
|
-
var effects = typeof _case === 'function' ? [] : _case.effects;
|
|
1147
|
-
return __assign(__assign({}, acc), (_b = {}, _b[key] = {
|
|
1148
|
-
reducer: function (_a, action) {
|
|
1149
|
-
var form = _a.form;
|
|
1150
|
-
return _reducer(reducerTools(providers), { form: form }, action);
|
|
1151
|
-
},
|
|
1152
|
-
effects: effects
|
|
1153
|
-
}, _b));
|
|
1154
|
-
}, {});
|
|
1155
|
-
var _d =
|
|
1156
|
-
return updateValues(state, action, providers);
|
|
1157
|
-
}, removeControl: function (state, action) { return removeControl(state, action, providers); }, addControl: function (state, action) {
|
|
1158
|
-
return addControl(state, action, providers);
|
|
1159
|
-
}, pushControl: function (state, action) {
|
|
1160
|
-
return pushControl(state, action, providers);
|
|
1161
|
-
}, resetControl: function (state, action) { return resetControl(state, action, providers); }, markControlAsPristine: function (state, action) {
|
|
1162
|
-
return markControlAsPristine(state, action);
|
|
1163
|
-
}, markControlAsTouched: function (state, action) {
|
|
1164
|
-
return markControlAsTouched(state, action);
|
|
1165
|
-
}, markControlAsUntouched: function (state, action) {
|
|
1166
|
-
return markControlAsUntouched(state, action);
|
|
1167
|
-
} }, customReducers) }, otherOptions)), hub1State$ = _d[0], hub1Actions = _d[1], hub1Actions$ = _d[2];
|
|
1168
|
-
var
|
|
1169
|
-
sources: [buildHub2Source(hub1State$, initialBaseState).pipe(
|
|
1170
|
-
initialState:
|
|
1171
|
-
name: "Stage 2 ".concat(name ? name : 'rxForm'),
|
|
1172
|
-
debug: debug,
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
}
|
|
1185
|
-
})[0];
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1054
|
+
var control = function (config) {
|
|
1055
|
+
if (Array.isArray(config)) {
|
|
1056
|
+
return config.reduce(function (acc, item, index) {
|
|
1057
|
+
var _a;
|
|
1058
|
+
var indexMap = {
|
|
1059
|
+
0: 'initialValue',
|
|
1060
|
+
1: 'validators',
|
|
1061
|
+
2: 'asyncValidators'
|
|
1062
|
+
};
|
|
1063
|
+
return __assign(__assign({}, acc), (_a = {}, _a[indexMap[index]] = index < 1 ? item : [].concat(item || []), _a));
|
|
1064
|
+
}, {});
|
|
1065
|
+
}
|
|
1066
|
+
return config;
|
|
1067
|
+
};
|
|
1068
|
+
var array = function (config) { return config; };
|
|
1069
|
+
var group = function (config) { return config; };
|
|
1070
|
+
var reducerTools = function (providers) { return ({
|
|
1071
|
+
updateValues: function (state, payload) {
|
|
1072
|
+
return updateValues(state, { payload: payload }, providers, true);
|
|
1073
|
+
},
|
|
1074
|
+
removeControl: function (state, payload) {
|
|
1075
|
+
return removeControl(state, { payload: payload }, providers, true);
|
|
1076
|
+
},
|
|
1077
|
+
pushControl: function (state, payload) {
|
|
1078
|
+
return pushControl(state, { payload: payload }, providers, true);
|
|
1079
|
+
},
|
|
1080
|
+
addControl: function (state, payload) {
|
|
1081
|
+
return addControl(state, { payload: payload }, providers, true);
|
|
1082
|
+
},
|
|
1083
|
+
resetControl: function (state, payload) {
|
|
1084
|
+
return resetControl(state, { payload: payload }, providers, true);
|
|
1085
|
+
},
|
|
1086
|
+
markControlAsPristine: function (state, payload) {
|
|
1087
|
+
return markControlAsPristine(state, { payload: payload }, true);
|
|
1088
|
+
},
|
|
1089
|
+
markControlAsTouched: function (state, payload) {
|
|
1090
|
+
return markControlAsTouched(state, { payload: payload }, true);
|
|
1091
|
+
},
|
|
1092
|
+
markControlAsUntouched: function (state, payload) {
|
|
1093
|
+
return markControlAsUntouched(state, { payload: payload }, true);
|
|
1094
|
+
}
|
|
1095
|
+
}); };
|
|
1096
|
+
var build = function (config, options) {
|
|
1097
|
+
var _a, _b, _c;
|
|
1098
|
+
if (options === void 0) { options = {}; }
|
|
1099
|
+
var providers = {
|
|
1100
|
+
normalizers: __assign({}, (_a = options.providers) === null || _a === void 0 ? void 0 : _a.normalizers),
|
|
1101
|
+
validators: __assign(__assign({}, Validators), (_b = options.providers) === null || _b === void 0 ? void 0 : _b.validators),
|
|
1102
|
+
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators)
|
|
1103
|
+
};
|
|
1104
|
+
var initialState = buildFormState(config, undefined, undefined, providers);
|
|
1105
|
+
return createReactable(initialState, options);
|
|
1106
|
+
};
|
|
1107
|
+
var load = function (state, options) {
|
|
1108
|
+
if (options === void 0) { options = {}; }
|
|
1109
|
+
var baseFormState = {
|
|
1110
|
+
form: Object.entries(state).reduce(function (acc, _a) {
|
|
1111
|
+
var _b;
|
|
1112
|
+
var key = _a[0], control = _a[1];
|
|
1113
|
+
return __assign(__assign({}, acc), (_b = {}, _b[key] = Object.entries(control)
|
|
1114
|
+
.filter(function (_a) {
|
|
1115
|
+
var key = _a[0];
|
|
1116
|
+
return !Object.keys(DEFAULT_HUB2_FIELDS).includes(key);
|
|
1117
|
+
})
|
|
1118
|
+
.reduce(function (acc, _a) {
|
|
1119
|
+
var _b;
|
|
1120
|
+
var key = _a[0], value = _a[1];
|
|
1121
|
+
return (__assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)));
|
|
1122
|
+
}, {}), _b));
|
|
1123
|
+
}, {})
|
|
1124
|
+
};
|
|
1125
|
+
return createReactable(baseFormState, options);
|
|
1126
|
+
};
|
|
1127
|
+
var createReactable = function (initialBaseState, options, initialFormState) {
|
|
1128
|
+
var _a, _b, _c;
|
|
1129
|
+
if (options === void 0) { options = {}; }
|
|
1130
|
+
var providers = {
|
|
1131
|
+
normalizers: __assign({}, (_a = options.providers) === null || _a === void 0 ? void 0 : _a.normalizers),
|
|
1132
|
+
validators: __assign(__assign({}, Validators), (_b = options.providers) === null || _b === void 0 ? void 0 : _b.validators),
|
|
1133
|
+
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators)
|
|
1134
|
+
};
|
|
1135
|
+
var reducers = options.reducers, debug = options.debug, name = options.name, otherOptions = __rest(options, ["reducers", "debug", "name"]);
|
|
1136
|
+
var customReducers = Object.entries(reducers || {}).reduce(function (acc, _a) {
|
|
1137
|
+
var _b;
|
|
1138
|
+
var key = _a[0], _case = _a[1];
|
|
1139
|
+
var _reducer = typeof _case === 'function' ? _case : _case.reducer;
|
|
1140
|
+
var effects = typeof _case === 'function' ? [] : _case.effects;
|
|
1141
|
+
return __assign(__assign({}, acc), (_b = {}, _b[key] = {
|
|
1142
|
+
reducer: function (_a, action) {
|
|
1143
|
+
var form = _a.form;
|
|
1144
|
+
return _reducer(reducerTools(providers), { form: form }, action);
|
|
1145
|
+
},
|
|
1146
|
+
effects: effects
|
|
1147
|
+
}, _b));
|
|
1148
|
+
}, {});
|
|
1149
|
+
var _d = RxBuilder(__assign({ initialState: initialBaseState, name: "Stage 1 ".concat(name ? name : 'rxForm'), debug: debug, reducers: __assign({ updateValues: function (state, action) {
|
|
1150
|
+
return updateValues(state, action, providers);
|
|
1151
|
+
}, removeControl: function (state, action) { return removeControl(state, action, providers); }, addControl: function (state, action) {
|
|
1152
|
+
return addControl(state, action, providers);
|
|
1153
|
+
}, pushControl: function (state, action) {
|
|
1154
|
+
return pushControl(state, action, providers);
|
|
1155
|
+
}, resetControl: function (state, action) { return resetControl(state, action, providers); }, markControlAsPristine: function (state, action) {
|
|
1156
|
+
return markControlAsPristine(state, action);
|
|
1157
|
+
}, markControlAsTouched: function (state, action) {
|
|
1158
|
+
return markControlAsTouched(state, action);
|
|
1159
|
+
}, markControlAsUntouched: function (state, action) {
|
|
1160
|
+
return markControlAsUntouched(state, action);
|
|
1161
|
+
} }, customReducers) }, otherOptions)), hub1State$ = _d[0], hub1Actions = _d[1], hub1Actions$ = _d[2];
|
|
1162
|
+
var _e = RxBuilder({
|
|
1163
|
+
sources: [buildHub2Source(hub1State$, initialBaseState).pipe(skip(0))],
|
|
1164
|
+
initialState: null,
|
|
1165
|
+
name: "Stage 2 ".concat(name ? name : 'rxForm'),
|
|
1166
|
+
debug: debug,
|
|
1167
|
+
reducers: {
|
|
1168
|
+
formChange: formChange,
|
|
1169
|
+
asyncValidationEffect: {
|
|
1170
|
+
reducer: function (state) { return state; },
|
|
1171
|
+
effects: function (control) { return ({
|
|
1172
|
+
key: control.key,
|
|
1173
|
+
effects: getScopedEffectsForControl(control, providers)
|
|
1174
|
+
}); }
|
|
1175
|
+
},
|
|
1176
|
+
asyncValidation: asyncValidation,
|
|
1177
|
+
asyncValidationResponse: asyncValidationResponse
|
|
1178
|
+
}
|
|
1179
|
+
}), state$ = _e[0], hub2Actions = _e[1];
|
|
1180
|
+
var destroy = function () {
|
|
1181
|
+
hub1Actions.destroy();
|
|
1182
|
+
hub2Actions.destroy();
|
|
1183
|
+
};
|
|
1184
|
+
return [
|
|
1185
|
+
state$.pipe(filter(function (form) { return form !== null; })),
|
|
1186
|
+
__assign(__assign({}, hub1Actions), { destroy: destroy }),
|
|
1187
|
+
hub1Actions$,
|
|
1188
|
+
];
|
|
1191
1189
|
};
|
|
1192
1190
|
|
|
1193
|
-
var getArrayItems = function (controlRef, form) {
|
|
1194
|
-
var control = getControl(controlRef, form);
|
|
1195
|
-
if (!Array.isArray(control.config.controls)) {
|
|
1196
|
-
throw "".concat(controlRef.join('.'), " is not a Form Array control");
|
|
1197
|
-
}
|
|
1198
|
-
var result = control.value.map(function (_, index) { return form[getFormKey(controlRef.concat(index))]; });
|
|
1199
|
-
return result;
|
|
1191
|
+
var getArrayItems = function (controlRef, form) {
|
|
1192
|
+
var control = getControl(controlRef, form);
|
|
1193
|
+
if (!Array.isArray(control.config.controls)) {
|
|
1194
|
+
throw "".concat(controlRef.join('.'), " is not a Form Array control");
|
|
1195
|
+
}
|
|
1196
|
+
var result = control.value.map(function (_, index) { return form[getFormKey(controlRef.concat(index))]; });
|
|
1197
|
+
return result;
|
|
1200
1198
|
};
|
|
1201
1199
|
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
exports.array = array;
|
|
1205
|
-
exports.build = build;
|
|
1206
|
-
exports.control = control;
|
|
1207
|
-
exports.getAncestorControls = getAncestorControls;
|
|
1208
|
-
exports.getArrayItems = getArrayItems;
|
|
1209
|
-
exports.getDescendantControls = getDescendantControls;
|
|
1210
|
-
exports.getValueFromControlConfig = getValueFromControlConfig;
|
|
1211
|
-
exports.group = group;
|
|
1212
|
-
exports.load = load;
|
|
1200
|
+
export { Controls as ControlModels, index as Validators, array, build, control, getAncestorControls, getArrayItems, getDescendantControls, getValueFromControlConfig, group, load };
|
|
1201
|
+
//# sourceMappingURL=index.js.map
|