@reactables/forms 2.0.0-beta.9 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Helpers/addAsyncValidationEffects.d.ts +7 -5
- package/dist/Helpers/buildFormState.d.ts +2 -2
- package/dist/Helpers/buildHub2Source.d.ts +1 -1
- package/dist/Models/Controls.d.ts +10 -8
- package/dist/Models/Validators.d.ts +1 -1
- package/dist/Reducers/Hub2/asyncValidation.d.ts +1 -1
- package/dist/Reducers/Hub2/asyncValidationResponse.d.ts +1 -1
- package/dist/Reducers/Hub2/formChange.d.ts +3 -3
- package/dist/Reducers/Hub2/mergeControls.d.ts +1 -1
- package/dist/Reducers/Hub2/mergeRemoveControl.d.ts +1 -1
- package/dist/RxForm/RxForm.d.ts +14 -14
- package/dist/Testing/Models/initialState.d.ts +1 -1
- package/dist/index.cjs +70 -68
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +70 -68
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/Reducers/Hub1/index.d.ts +0 -6
- package/dist/Reducers/Hub2/index.d.ts +0 -3
- package/dist/Reducers/index.d.ts +0 -2
package/dist/index.js
CHANGED
|
@@ -9,12 +9,14 @@ var DEFAULT_HUB2_FIELDS = {
|
|
|
9
9
|
pending: false,
|
|
10
10
|
valid: null,
|
|
11
11
|
childrenValid: null,
|
|
12
|
-
errors:
|
|
12
|
+
errors: {},
|
|
13
13
|
};
|
|
14
|
+
var cloneHub2Fields = function () { return JSON.parse(JSON.stringify(DEFAULT_HUB2_FIELDS)); };
|
|
14
15
|
|
|
15
16
|
var Controls = /*#__PURE__*/Object.freeze({
|
|
16
17
|
__proto__: null,
|
|
17
|
-
DEFAULT_HUB2_FIELDS: DEFAULT_HUB2_FIELDS
|
|
18
|
+
DEFAULT_HUB2_FIELDS: DEFAULT_HUB2_FIELDS,
|
|
19
|
+
cloneHub2Fields: cloneHub2Fields
|
|
18
20
|
});
|
|
19
21
|
|
|
20
22
|
var required = function (value) {
|
|
@@ -30,7 +32,7 @@ var required = function (value) {
|
|
|
30
32
|
return { required: false };
|
|
31
33
|
};
|
|
32
34
|
var arrayNotEmpty = function (value) { return ({
|
|
33
|
-
arrayNotEmpty: !Boolean(value.length)
|
|
35
|
+
arrayNotEmpty: !Boolean(value.length),
|
|
34
36
|
}); };
|
|
35
37
|
var email = function (value) {
|
|
36
38
|
return value && !/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g.test(value) ? { email: true } : { email: false };
|
|
@@ -147,16 +149,15 @@ var getErrors = function (control, value, _a) {
|
|
|
147
149
|
var _b;
|
|
148
150
|
var validators = _a.validators;
|
|
149
151
|
return ((_b = control.config.validators) === null || _b === void 0 ? void 0 : _b.reduce(function (acc, validator) {
|
|
150
|
-
if (!validators[validator]) {
|
|
152
|
+
if (!(validators === null || validators === void 0 ? void 0 : validators[validator])) {
|
|
151
153
|
throw "You have not provided a validator for \"".concat(validator, "\"");
|
|
152
154
|
}
|
|
153
155
|
return __assign(__assign({}, acc), validators[validator](value));
|
|
154
156
|
}, {})) || {};
|
|
155
157
|
};
|
|
156
158
|
|
|
157
|
-
var buildState = function (config,
|
|
159
|
+
var buildState = function (config, controlRef, providers, form) {
|
|
158
160
|
var _a;
|
|
159
|
-
if (form === void 0) { form = { root: null }; }
|
|
160
161
|
if (controlRef === void 0) { controlRef = []; }
|
|
161
162
|
var value = getValueFromControlConfig(config);
|
|
162
163
|
var control = {
|
|
@@ -167,7 +168,7 @@ var buildState = function (config, form, controlRef, providers) {
|
|
|
167
168
|
controlRef: controlRef,
|
|
168
169
|
validatorErrors: {},
|
|
169
170
|
config: config,
|
|
170
|
-
key: generateKey(5)
|
|
171
|
+
key: generateKey(5),
|
|
171
172
|
};
|
|
172
173
|
var newForm = __assign(__assign({}, form), (_a = {}, _a[getFormKey(controlRef)] = __assign(__assign({}, control), { validatorErrors: getErrors(control, value, providers) }), _a));
|
|
173
174
|
var controls = config.controls;
|
|
@@ -175,22 +176,21 @@ var buildState = function (config, form, controlRef, providers) {
|
|
|
175
176
|
if (controls && !(controls instanceof Array)) {
|
|
176
177
|
newForm = Object.entries(config.controls).reduce(function (acc, _a) {
|
|
177
178
|
var key = _a[0], controlConfig = _a[1];
|
|
178
|
-
return buildState(controlConfig,
|
|
179
|
+
return buildState(controlConfig, controlRef.concat(key), providers, acc);
|
|
179
180
|
}, newForm);
|
|
180
181
|
}
|
|
181
182
|
else if (controls && controls instanceof Array) {
|
|
182
183
|
// Adding controls for Form Array
|
|
183
184
|
newForm = config.controls.reduce(function (acc, controlConfig, index) {
|
|
184
|
-
return buildState(controlConfig,
|
|
185
|
+
return buildState(controlConfig, controlRef.concat(index), providers, acc);
|
|
185
186
|
}, newForm);
|
|
186
187
|
}
|
|
187
188
|
return newForm;
|
|
188
189
|
};
|
|
189
|
-
var buildFormState = function (config,
|
|
190
|
-
if (form === void 0) { form = { root: null }; }
|
|
190
|
+
var buildFormState = function (config, controlRef, providers, form) {
|
|
191
191
|
if (controlRef === void 0) { controlRef = []; }
|
|
192
192
|
return {
|
|
193
|
-
form: buildState(config,
|
|
193
|
+
form: buildState(config, controlRef, providers, form),
|
|
194
194
|
};
|
|
195
195
|
};
|
|
196
196
|
|
|
@@ -201,7 +201,8 @@ var getScopedEffectsForControl = function (formControl, providers) {
|
|
|
201
201
|
if (asyncValidators && asyncValidators.length) {
|
|
202
202
|
scopedEffects = asyncValidators.reduce(function (acc, asyncValidator, validatorIndex) {
|
|
203
203
|
var effect = function (actions$) {
|
|
204
|
-
|
|
204
|
+
var _a;
|
|
205
|
+
if (!((_a = providers.asyncValidators) === null || _a === void 0 ? void 0 : _a[asyncValidator])) {
|
|
205
206
|
throw "You have not provided an asyncValidator for \"".concat(asyncValidator, "\"");
|
|
206
207
|
}
|
|
207
208
|
return actions$.pipe(map(function (_a) {
|
|
@@ -213,16 +214,16 @@ var getScopedEffectsForControl = function (formControl, providers) {
|
|
|
213
214
|
payload: {
|
|
214
215
|
key: key,
|
|
215
216
|
errors: errors,
|
|
216
|
-
validatorIndex: validatorIndex
|
|
217
|
-
}
|
|
217
|
+
validatorIndex: validatorIndex,
|
|
218
|
+
},
|
|
218
219
|
}); }), catchError(function () {
|
|
219
220
|
return of({
|
|
220
221
|
type: 'asyncValidationResponse',
|
|
221
222
|
payload: {
|
|
222
223
|
key: key,
|
|
223
224
|
errors: { asyncValidationApiError: true },
|
|
224
|
-
validatorIndex: validatorIndex
|
|
225
|
-
}
|
|
225
|
+
validatorIndex: validatorIndex,
|
|
226
|
+
},
|
|
226
227
|
});
|
|
227
228
|
})));
|
|
228
229
|
}));
|
|
@@ -281,7 +282,7 @@ var updateAncestorValues = function (form, _a, providers) {
|
|
|
281
282
|
}
|
|
282
283
|
var newParentControl = __assign(__assign({}, parentControl), { validatorErrors: getErrors(parentControl, newValue, providers), value: newValue, dirty: !isEqual(newValue, parentControl.pristineValue) });
|
|
283
284
|
return updateAncestorValues(__assign(__assign({}, form), (_c = {}, _c[parentFormKey] = newParentControl, _c)), {
|
|
284
|
-
payload: { controlRef: parentRef, value: newValue }
|
|
285
|
+
payload: { controlRef: parentRef, value: newValue },
|
|
285
286
|
}, providers);
|
|
286
287
|
}
|
|
287
288
|
return form;
|
|
@@ -303,7 +304,7 @@ var getDescendantControls = function (controlRef, form, excludeSelf) {
|
|
|
303
304
|
}
|
|
304
305
|
var control = getControl(controlRef, form);
|
|
305
306
|
var value = control.value, config = control.config;
|
|
306
|
-
var descendants;
|
|
307
|
+
var descendants = [];
|
|
307
308
|
if (Array.isArray(config.controls)) {
|
|
308
309
|
// If control is a Form Array
|
|
309
310
|
descendants = value.reduce(function (acc, item, index) {
|
|
@@ -329,11 +330,11 @@ var getAncestorControls = function (controlRef, form, excludeSelf) {
|
|
|
329
330
|
var formControls = acc.formControls.concat(getControl(currentRef, form));
|
|
330
331
|
return {
|
|
331
332
|
currentRef: currentRef,
|
|
332
|
-
formControls: formControls
|
|
333
|
+
formControls: formControls,
|
|
333
334
|
};
|
|
334
335
|
}, {
|
|
335
336
|
currentRef: [],
|
|
336
|
-
formControls: []
|
|
337
|
+
formControls: [],
|
|
337
338
|
}).formControls;
|
|
338
339
|
var root = form['root'];
|
|
339
340
|
var result = [root].concat(formControls);
|
|
@@ -405,7 +406,7 @@ var updateDescendantValues = function (form, _a, providers) {
|
|
|
405
406
|
if (configControls) {
|
|
406
407
|
checkKeys(oldChildValue, newChildValue);
|
|
407
408
|
acc = updateDescendantValues(acc, {
|
|
408
|
-
payload: { controlRef: control.controlRef, value: newChildValue }
|
|
409
|
+
payload: { controlRef: control.controlRef, value: newChildValue },
|
|
409
410
|
}, providers);
|
|
410
411
|
}
|
|
411
412
|
}
|
|
@@ -417,10 +418,11 @@ var updateDescendantValues = function (form, _a, providers) {
|
|
|
417
418
|
// Use AddControlPayload/RemoveControl action reducers to add/remove control
|
|
418
419
|
var updateValues = function (_a, action, providers, mergeChanges) {
|
|
419
420
|
var _b, _c;
|
|
420
|
-
var
|
|
421
|
+
var _d;
|
|
422
|
+
var form = _a.form, _e = _a._changedControls, _changedControls = _e === void 0 ? {} : _e, _f = _a._removedControls, _removedControls = _f === void 0 ? {} : _f;
|
|
421
423
|
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
422
424
|
var normalizers = providers.normalizers;
|
|
423
|
-
var
|
|
425
|
+
var _g = action.payload, controlRef = _g.controlRef, value = _g.value;
|
|
424
426
|
controlRefCheck(controlRef);
|
|
425
427
|
// Update its own value
|
|
426
428
|
var ctrlKey = getFormKey(controlRef);
|
|
@@ -428,8 +430,8 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
428
430
|
var oldValue = form[ctrlKey].value;
|
|
429
431
|
var config = form[ctrlKey].config;
|
|
430
432
|
if (config.normalizers) {
|
|
431
|
-
newValue = config.normalizers.reduce(function (acc, normalizer) {
|
|
432
|
-
if (!normalizers[normalizer]) {
|
|
433
|
+
newValue = (_d = config.normalizers) === null || _d === void 0 ? void 0 : _d.reduce(function (acc, normalizer) {
|
|
434
|
+
if (!(normalizers === null || normalizers === void 0 ? void 0 : normalizers[normalizer])) {
|
|
433
435
|
throw "You have not provided a normalizer for \"".concat(normalizer, "\"");
|
|
434
436
|
}
|
|
435
437
|
return normalizers[normalizer](acc);
|
|
@@ -439,7 +441,7 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
439
441
|
var newControl = __assign(__assign({}, form[ctrlKey]), { validatorErrors: validatorErrors, dirty: !isEqual(value, form[ctrlKey].pristineValue), value: newValue });
|
|
440
442
|
var result = {
|
|
441
443
|
form: __assign(__assign({}, form), (_b = {}, _b[ctrlKey] = newControl, _b)),
|
|
442
|
-
_changedControls: (_c = {}, _c[newControl.key] = newControl, _c)
|
|
444
|
+
_changedControls: (_c = {}, _c[newControl.key] = newControl, _c),
|
|
443
445
|
};
|
|
444
446
|
var configControls = config.controls;
|
|
445
447
|
// Update its descendants
|
|
@@ -448,8 +450,8 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
448
450
|
var updatedDescendants = updateDescendantValues(result.form, {
|
|
449
451
|
payload: {
|
|
450
452
|
controlRef: controlRef,
|
|
451
|
-
value: newValue
|
|
452
|
-
}
|
|
453
|
+
value: newValue,
|
|
454
|
+
},
|
|
453
455
|
}, providers);
|
|
454
456
|
var changedDescendantControls = getDescendantControls(controlRef, updatedDescendants).reduce(function (acc, control) {
|
|
455
457
|
var _a;
|
|
@@ -460,7 +462,7 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
460
462
|
// Update its Ancestors
|
|
461
463
|
if (controlRef.length) {
|
|
462
464
|
result = __assign(__assign({}, result), { form: updateAncestorValues(result.form, {
|
|
463
|
-
payload: { controlRef: controlRef, value: newValue }
|
|
465
|
+
payload: { controlRef: controlRef, value: newValue },
|
|
464
466
|
}, providers) });
|
|
465
467
|
}
|
|
466
468
|
var changedAncestorControls = getAncestorControls(controlRef, result.form).reduce(function (acc, control) {
|
|
@@ -491,7 +493,7 @@ var updateAncestorValuesRemoveControl = function (form, _a, providers) {
|
|
|
491
493
|
}
|
|
492
494
|
var newParentControl = __assign(__assign({}, parentControl), { value: newValue, validatorErrors: getErrors(parentControl, newValue, providers), dirty: !isEqual(newValue, parentControl.pristineValue) });
|
|
493
495
|
return updateAncestorValues(__assign(__assign({}, form), (_b = {}, _b[parentFormKey] = newParentControl, _b)), {
|
|
494
|
-
payload: { controlRef: parentRef, value: newValue }
|
|
496
|
+
payload: { controlRef: parentRef, value: newValue },
|
|
495
497
|
}, providers);
|
|
496
498
|
}
|
|
497
499
|
return form;
|
|
@@ -545,7 +547,7 @@ var removeControl = function (state, action, providers, mergeChanges) {
|
|
|
545
547
|
return __assign(__assign({}, acc), (_c = {}, _c[key] = control, _c));
|
|
546
548
|
}, {});
|
|
547
549
|
var result = updateAncestorValuesRemoveControl(controlRemoved, {
|
|
548
|
-
payload: controlRef
|
|
550
|
+
payload: controlRef,
|
|
549
551
|
}, providers);
|
|
550
552
|
var _changedControls = __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), getAncestorControls(controlRef.slice(0, -1), result).reduce(function (acc, control) {
|
|
551
553
|
var _a;
|
|
@@ -586,7 +588,7 @@ var removeControl = function (state, action, providers, mergeChanges) {
|
|
|
586
588
|
return {
|
|
587
589
|
form: result,
|
|
588
590
|
_changedControls: _changedControls,
|
|
589
|
-
_removedControls: _removedControls
|
|
591
|
+
_removedControls: _removedControls,
|
|
590
592
|
};
|
|
591
593
|
};
|
|
592
594
|
|
|
@@ -609,7 +611,7 @@ var updateAncestorValuesAddControl = function (form, _a, providers) {
|
|
|
609
611
|
}
|
|
610
612
|
var newParentControl = __assign(__assign({}, parentControl), { value: newValue, validatorErrors: getErrors(parentControl, newValue, providers), dirty: !isEqual(newValue, parentControl.pristineValue) });
|
|
611
613
|
return updateAncestorValues(__assign(__assign({}, form), (_c = {}, _c[parentFormKey] = newParentControl, _c)), {
|
|
612
|
-
payload: { controlRef: parentRef, value: newValue }
|
|
614
|
+
payload: { controlRef: parentRef, value: newValue },
|
|
613
615
|
}, providers);
|
|
614
616
|
}
|
|
615
617
|
return form;
|
|
@@ -629,10 +631,10 @@ var addControl = function (state, action, providers, mergeChanges) {
|
|
|
629
631
|
if (!getControl(controlRef.slice(0, -1), state.form)) {
|
|
630
632
|
throw 'You are attempting to add a control to a non-existent form group';
|
|
631
633
|
}
|
|
632
|
-
var newForm = buildState(config,
|
|
634
|
+
var newForm = buildState(config, controlRef, providers, state.form);
|
|
633
635
|
var newValue = getControl(controlRef, newForm).value;
|
|
634
636
|
var ancestorsUpdated = updateAncestorValuesAddControl(newForm, {
|
|
635
|
-
payload: { controlRef: controlRef, value: newValue }
|
|
637
|
+
payload: { controlRef: controlRef, value: newValue },
|
|
636
638
|
}, providers);
|
|
637
639
|
var _changedControls = getControlBranch(controlRef, ancestorsUpdated).reduce(function (acc, control) {
|
|
638
640
|
var _a;
|
|
@@ -641,7 +643,7 @@ var addControl = function (state, action, providers, mergeChanges) {
|
|
|
641
643
|
return {
|
|
642
644
|
form: ancestorsUpdated,
|
|
643
645
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
644
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
646
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
645
647
|
};
|
|
646
648
|
};
|
|
647
649
|
|
|
@@ -660,10 +662,10 @@ var pushControl = function (state, action, providers, mergeChanges) {
|
|
|
660
662
|
else {
|
|
661
663
|
throw 'You are attempting to push to a control that is not a Form Array';
|
|
662
664
|
}
|
|
663
|
-
var newForm = buildState(config,
|
|
665
|
+
var newForm = buildState(config, newControlRef, providers, state.form);
|
|
664
666
|
var newValue = getControl(newControlRef, newForm).value;
|
|
665
667
|
var ancestorsUpdated = updateAncestorValuesAddControl(newForm, {
|
|
666
|
-
payload: { controlRef: newControlRef, value: newValue }
|
|
668
|
+
payload: { controlRef: newControlRef, value: newValue },
|
|
667
669
|
}, providers);
|
|
668
670
|
var _changedControls = getControlBranch(newControlRef, ancestorsUpdated).reduce(function (acc, control) {
|
|
669
671
|
var _a;
|
|
@@ -672,7 +674,7 @@ var pushControl = function (state, action, providers, mergeChanges) {
|
|
|
672
674
|
return {
|
|
673
675
|
form: ancestorsUpdated,
|
|
674
676
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
675
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
677
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
676
678
|
};
|
|
677
679
|
};
|
|
678
680
|
|
|
@@ -703,7 +705,7 @@ var updateAncestorPristineValues = function (form, _a) {
|
|
|
703
705
|
}
|
|
704
706
|
var newParentControl = __assign(__assign({}, form[parentKey]), { pristineValue: newValue, dirty: isEqual(form[parentKey].value, newValue) });
|
|
705
707
|
return updateAncestorPristineValues(__assign(__assign({}, form), (_b = {}, _b[parentKey] = newParentControl, _b)), {
|
|
706
|
-
payload: parentRef
|
|
708
|
+
payload: parentRef,
|
|
707
709
|
});
|
|
708
710
|
}
|
|
709
711
|
return form;
|
|
@@ -721,7 +723,7 @@ var markControlAsPristine = function (state, action, mergeChanges) {
|
|
|
721
723
|
var result = __assign(__assign({}, form), descendants);
|
|
722
724
|
if (controlRef.length) {
|
|
723
725
|
result = updateAncestorPristineValues(result, {
|
|
724
|
-
payload: controlRef
|
|
726
|
+
payload: controlRef,
|
|
725
727
|
});
|
|
726
728
|
}
|
|
727
729
|
var _changedControls = getControlBranch(controlRef, result).reduce(function (acc, control) {
|
|
@@ -731,7 +733,7 @@ var markControlAsPristine = function (state, action, mergeChanges) {
|
|
|
731
733
|
return {
|
|
732
734
|
form: result,
|
|
733
735
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
734
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
736
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
735
737
|
};
|
|
736
738
|
};
|
|
737
739
|
|
|
@@ -753,7 +755,7 @@ var markControlAsTouched = function (state, action, mergeChanges) {
|
|
|
753
755
|
return {
|
|
754
756
|
form: __assign(__assign({}, form), controls),
|
|
755
757
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
756
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
758
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
757
759
|
};
|
|
758
760
|
};
|
|
759
761
|
|
|
@@ -783,7 +785,7 @@ var markControlAsUntouched = function (state, action, mergeChanges) {
|
|
|
783
785
|
return {
|
|
784
786
|
form: result,
|
|
785
787
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
786
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
788
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
787
789
|
};
|
|
788
790
|
};
|
|
789
791
|
|
|
@@ -804,10 +806,10 @@ var resetControl = function (state, action, providers, mergeChanges) {
|
|
|
804
806
|
delete descendantsRemoved[key];
|
|
805
807
|
});
|
|
806
808
|
// Remove all descendants
|
|
807
|
-
var restoredControls = buildState(controlToReset.config,
|
|
809
|
+
var restoredControls = buildState(controlToReset.config, controlToReset.controlRef, providers, descendantsRemoved);
|
|
808
810
|
var restoredControlValue = getControl(controlRef, restoredControls).value;
|
|
809
811
|
var result = updateAncestorValues(restoredControls, {
|
|
810
|
-
payload: { controlRef: controlRef, value: restoredControlValue }
|
|
812
|
+
payload: { controlRef: controlRef, value: restoredControlValue },
|
|
811
813
|
}, providers);
|
|
812
814
|
var _changedControls = __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), getControlBranch(controlRef, result).reduce(function (acc, control) {
|
|
813
815
|
var _a;
|
|
@@ -826,7 +828,7 @@ var resetControl = function (state, action, providers, mergeChanges) {
|
|
|
826
828
|
return {
|
|
827
829
|
form: result,
|
|
828
830
|
_changedControls: _changedControls,
|
|
829
|
-
_removedControls: _removedControls
|
|
831
|
+
_removedControls: _removedControls,
|
|
830
832
|
};
|
|
831
833
|
};
|
|
832
834
|
|
|
@@ -834,12 +836,14 @@ var asyncValidation = function (form, _a) {
|
|
|
834
836
|
var controlRef = _a.payload;
|
|
835
837
|
var updatedSelfAndAncestors = getAncestorControls(controlRef, form).reduce(function (acc, control) {
|
|
836
838
|
var _a;
|
|
839
|
+
var _b;
|
|
837
840
|
var isChangedControl = getFormKey(control.controlRef) === getFormKey(controlRef);
|
|
838
841
|
return __assign(__assign({}, acc), (_a = {}, _a[getFormKey(control.controlRef)] = __assign(__assign({}, control), { pending: true, asyncValidateInProgress: isChangedControl
|
|
839
|
-
? __assign({}, control.config.asyncValidators.reduce(function (acc, _, index) {
|
|
842
|
+
? __assign({}, (_b = control.config.asyncValidators) === null || _b === void 0 ? void 0 : _b.reduce(function (acc, _, index) {
|
|
840
843
|
var _a;
|
|
841
844
|
return (__assign(__assign({}, acc), (_a = {}, _a[index] = true, _a)));
|
|
842
|
-
}, {}))
|
|
845
|
+
}, {}))
|
|
846
|
+
: control.asyncValidateInProgress }), _a));
|
|
843
847
|
}, {});
|
|
844
848
|
return __assign(__assign({}, form), updatedSelfAndAncestors);
|
|
845
849
|
};
|
|
@@ -960,8 +964,7 @@ var mergeRemoveControl = function (state, form, controlRef) {
|
|
|
960
964
|
.reduce(function (acc, baseControl) {
|
|
961
965
|
var _a;
|
|
962
966
|
var key = getFormKey(baseControl.controlRef);
|
|
963
|
-
var existingControl = existingBranch.find(function (control) { return baseControl.key === control.key; }) ||
|
|
964
|
-
structuredClone(DEFAULT_HUB2_FIELDS);
|
|
967
|
+
var existingControl = existingBranch.find(function (control) { return baseControl.key === control.key; }) || cloneHub2Fields();
|
|
965
968
|
var errors = __assign(__assign({}, baseControl.validatorErrors), existingControl.asyncValidatorErrors);
|
|
966
969
|
var selfValid = !hasErrors$1(errors);
|
|
967
970
|
var childrenValid = true;
|
|
@@ -1010,9 +1013,7 @@ var mergeControls = function (state, _a) {
|
|
|
1010
1013
|
var _a;
|
|
1011
1014
|
var formKey = getFormKey(control.controlRef);
|
|
1012
1015
|
var existingControl = controlsRemoved && controlsRemoved[formKey];
|
|
1013
|
-
var newControl = __assign(__assign({}, (existingControl
|
|
1014
|
-
? existingControl
|
|
1015
|
-
: structuredClone(DEFAULT_HUB2_FIELDS))), control);
|
|
1016
|
+
var newControl = __assign(__assign({}, (existingControl ? existingControl : cloneHub2Fields())), control);
|
|
1016
1017
|
var errors = __assign(__assign({}, newControl.validatorErrors), newControl.asyncValidatorErrors);
|
|
1017
1018
|
var selfValid = !hasErrors(errors);
|
|
1018
1019
|
var childrenValid = true;
|
|
@@ -1047,7 +1048,7 @@ var formChange = function (state, _a) {
|
|
|
1047
1048
|
return mergeErrors(Object.entries(form).reduce(function (acc, _a) {
|
|
1048
1049
|
var _b;
|
|
1049
1050
|
var dictKey = _a[0], baseControl = _a[1];
|
|
1050
|
-
return __assign(__assign({}, acc), (_b = {}, _b[dictKey] = __assign(__assign({},
|
|
1051
|
+
return __assign(__assign({}, acc), (_b = {}, _b[dictKey] = __assign(__assign({}, cloneHub2Fields()), baseControl), _b));
|
|
1051
1052
|
}, {}));
|
|
1052
1053
|
}
|
|
1053
1054
|
return mergeControls(state, payload);
|
|
@@ -1060,7 +1061,7 @@ var control = function (config) {
|
|
|
1060
1061
|
var indexMap = {
|
|
1061
1062
|
0: 'initialValue',
|
|
1062
1063
|
1: 'validators',
|
|
1063
|
-
2: 'asyncValidators'
|
|
1064
|
+
2: 'asyncValidators',
|
|
1064
1065
|
};
|
|
1065
1066
|
return __assign(__assign({}, acc), (_a = {}, _a[indexMap[index]] = index < 1 ? item : [].concat(item || []), _a));
|
|
1066
1067
|
}, {});
|
|
@@ -1093,7 +1094,7 @@ var reducerTools = function (providers) { return ({
|
|
|
1093
1094
|
},
|
|
1094
1095
|
markControlAsUntouched: function (state, payload) {
|
|
1095
1096
|
return markControlAsUntouched(state, { payload: payload }, true);
|
|
1096
|
-
}
|
|
1097
|
+
},
|
|
1097
1098
|
}); };
|
|
1098
1099
|
var build = function (config, options) {
|
|
1099
1100
|
var _a, _b, _c;
|
|
@@ -1101,9 +1102,9 @@ var build = function (config, options) {
|
|
|
1101
1102
|
var providers = {
|
|
1102
1103
|
normalizers: __assign({}, (_a = options.providers) === null || _a === void 0 ? void 0 : _a.normalizers),
|
|
1103
1104
|
validators: __assign(__assign({}, Validators), (_b = options.providers) === null || _b === void 0 ? void 0 : _b.validators),
|
|
1104
|
-
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators)
|
|
1105
|
+
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators),
|
|
1105
1106
|
};
|
|
1106
|
-
var initialState = buildFormState(config, undefined,
|
|
1107
|
+
var initialState = buildFormState(config, undefined, providers);
|
|
1107
1108
|
return createReactable(initialState, options);
|
|
1108
1109
|
};
|
|
1109
1110
|
var load = function (state, options) {
|
|
@@ -1122,7 +1123,7 @@ var load = function (state, options) {
|
|
|
1122
1123
|
var key = _a[0], value = _a[1];
|
|
1123
1124
|
return (__assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)));
|
|
1124
1125
|
}, {}), _b));
|
|
1125
|
-
}, {})
|
|
1126
|
+
}, {}),
|
|
1126
1127
|
};
|
|
1127
1128
|
return createReactable(baseFormState, options);
|
|
1128
1129
|
};
|
|
@@ -1132,7 +1133,7 @@ var createReactable = function (initialBaseState, options, initialFormState) {
|
|
|
1132
1133
|
var providers = {
|
|
1133
1134
|
normalizers: __assign({}, (_a = options.providers) === null || _a === void 0 ? void 0 : _a.normalizers),
|
|
1134
1135
|
validators: __assign(__assign({}, Validators), (_b = options.providers) === null || _b === void 0 ? void 0 : _b.validators),
|
|
1135
|
-
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators)
|
|
1136
|
+
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators),
|
|
1136
1137
|
};
|
|
1137
1138
|
var reducers = options.reducers, debug = options.debug, name = options.name, otherOptions = __rest(options, ["reducers", "debug", "name"]);
|
|
1138
1139
|
var customReducers = Object.entries(reducers || {}).reduce(function (acc, _a) {
|
|
@@ -1145,7 +1146,7 @@ var createReactable = function (initialBaseState, options, initialFormState) {
|
|
|
1145
1146
|
var form = _a.form;
|
|
1146
1147
|
return _reducer(reducerTools(providers), { form: form }, action);
|
|
1147
1148
|
},
|
|
1148
|
-
effects: effects
|
|
1149
|
+
effects: effects,
|
|
1149
1150
|
}, _b));
|
|
1150
1151
|
}, {});
|
|
1151
1152
|
var _d = RxBuilder(__assign({ initialState: initialBaseState, name: "Stage 1 ".concat(name ? name : 'rxForm'), debug: debug, reducers: __assign({ updateValues: function (state, action) {
|
|
@@ -1172,20 +1173,21 @@ var createReactable = function (initialBaseState, options, initialFormState) {
|
|
|
1172
1173
|
reducer: function (state) { return state; },
|
|
1173
1174
|
effects: function (control) { return ({
|
|
1174
1175
|
key: control.key,
|
|
1175
|
-
effects: getScopedEffectsForControl(control, providers)
|
|
1176
|
-
}); }
|
|
1176
|
+
effects: getScopedEffectsForControl(control, providers),
|
|
1177
|
+
}); },
|
|
1177
1178
|
},
|
|
1178
1179
|
asyncValidation: asyncValidation,
|
|
1179
|
-
asyncValidationResponse: asyncValidationResponse
|
|
1180
|
-
}
|
|
1180
|
+
asyncValidationResponse: asyncValidationResponse,
|
|
1181
|
+
},
|
|
1181
1182
|
}), state$ = _e[0], hub2Actions = _e[1];
|
|
1182
1183
|
var destroy = function () {
|
|
1183
1184
|
hub1Actions.destroy();
|
|
1184
1185
|
hub2Actions.destroy();
|
|
1185
1186
|
};
|
|
1187
|
+
var actions = __assign(__assign({}, hub1Actions), { destroy: destroy });
|
|
1186
1188
|
return [
|
|
1187
1189
|
state$.pipe(filter(function (form) { return form !== null; })),
|
|
1188
|
-
|
|
1190
|
+
actions,
|
|
1189
1191
|
hub1Actions$,
|
|
1190
1192
|
];
|
|
1191
1193
|
};
|