@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.cjs
CHANGED
|
@@ -11,12 +11,14 @@ var DEFAULT_HUB2_FIELDS = {
|
|
|
11
11
|
pending: false,
|
|
12
12
|
valid: null,
|
|
13
13
|
childrenValid: null,
|
|
14
|
-
errors:
|
|
14
|
+
errors: {},
|
|
15
15
|
};
|
|
16
|
+
var cloneHub2Fields = function () { return JSON.parse(JSON.stringify(DEFAULT_HUB2_FIELDS)); };
|
|
16
17
|
|
|
17
18
|
var Controls = /*#__PURE__*/Object.freeze({
|
|
18
19
|
__proto__: null,
|
|
19
|
-
DEFAULT_HUB2_FIELDS: DEFAULT_HUB2_FIELDS
|
|
20
|
+
DEFAULT_HUB2_FIELDS: DEFAULT_HUB2_FIELDS,
|
|
21
|
+
cloneHub2Fields: cloneHub2Fields
|
|
20
22
|
});
|
|
21
23
|
|
|
22
24
|
var required = function (value) {
|
|
@@ -32,7 +34,7 @@ var required = function (value) {
|
|
|
32
34
|
return { required: false };
|
|
33
35
|
};
|
|
34
36
|
var arrayNotEmpty = function (value) { return ({
|
|
35
|
-
arrayNotEmpty: !Boolean(value.length)
|
|
37
|
+
arrayNotEmpty: !Boolean(value.length),
|
|
36
38
|
}); };
|
|
37
39
|
var email = function (value) {
|
|
38
40
|
return value && !/^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/g.test(value) ? { email: true } : { email: false };
|
|
@@ -149,16 +151,15 @@ var getErrors = function (control, value, _a) {
|
|
|
149
151
|
var _b;
|
|
150
152
|
var validators = _a.validators;
|
|
151
153
|
return ((_b = control.config.validators) === null || _b === void 0 ? void 0 : _b.reduce(function (acc, validator) {
|
|
152
|
-
if (!validators[validator]) {
|
|
154
|
+
if (!(validators === null || validators === void 0 ? void 0 : validators[validator])) {
|
|
153
155
|
throw "You have not provided a validator for \"".concat(validator, "\"");
|
|
154
156
|
}
|
|
155
157
|
return __assign(__assign({}, acc), validators[validator](value));
|
|
156
158
|
}, {})) || {};
|
|
157
159
|
};
|
|
158
160
|
|
|
159
|
-
var buildState = function (config,
|
|
161
|
+
var buildState = function (config, controlRef, providers, form) {
|
|
160
162
|
var _a;
|
|
161
|
-
if (form === void 0) { form = { root: null }; }
|
|
162
163
|
if (controlRef === void 0) { controlRef = []; }
|
|
163
164
|
var value = getValueFromControlConfig(config);
|
|
164
165
|
var control = {
|
|
@@ -169,7 +170,7 @@ var buildState = function (config, form, controlRef, providers) {
|
|
|
169
170
|
controlRef: controlRef,
|
|
170
171
|
validatorErrors: {},
|
|
171
172
|
config: config,
|
|
172
|
-
key: generateKey(5)
|
|
173
|
+
key: generateKey(5),
|
|
173
174
|
};
|
|
174
175
|
var newForm = __assign(__assign({}, form), (_a = {}, _a[getFormKey(controlRef)] = __assign(__assign({}, control), { validatorErrors: getErrors(control, value, providers) }), _a));
|
|
175
176
|
var controls = config.controls;
|
|
@@ -177,22 +178,21 @@ var buildState = function (config, form, controlRef, providers) {
|
|
|
177
178
|
if (controls && !(controls instanceof Array)) {
|
|
178
179
|
newForm = Object.entries(config.controls).reduce(function (acc, _a) {
|
|
179
180
|
var key = _a[0], controlConfig = _a[1];
|
|
180
|
-
return buildState(controlConfig,
|
|
181
|
+
return buildState(controlConfig, controlRef.concat(key), providers, acc);
|
|
181
182
|
}, newForm);
|
|
182
183
|
}
|
|
183
184
|
else if (controls && controls instanceof Array) {
|
|
184
185
|
// Adding controls for Form Array
|
|
185
186
|
newForm = config.controls.reduce(function (acc, controlConfig, index) {
|
|
186
|
-
return buildState(controlConfig,
|
|
187
|
+
return buildState(controlConfig, controlRef.concat(index), providers, acc);
|
|
187
188
|
}, newForm);
|
|
188
189
|
}
|
|
189
190
|
return newForm;
|
|
190
191
|
};
|
|
191
|
-
var buildFormState = function (config,
|
|
192
|
-
if (form === void 0) { form = { root: null }; }
|
|
192
|
+
var buildFormState = function (config, controlRef, providers, form) {
|
|
193
193
|
if (controlRef === void 0) { controlRef = []; }
|
|
194
194
|
return {
|
|
195
|
-
form: buildState(config,
|
|
195
|
+
form: buildState(config, controlRef, providers, form),
|
|
196
196
|
};
|
|
197
197
|
};
|
|
198
198
|
|
|
@@ -203,7 +203,8 @@ var getScopedEffectsForControl = function (formControl, providers) {
|
|
|
203
203
|
if (asyncValidators && asyncValidators.length) {
|
|
204
204
|
scopedEffects = asyncValidators.reduce(function (acc, asyncValidator, validatorIndex) {
|
|
205
205
|
var effect = function (actions$) {
|
|
206
|
-
|
|
206
|
+
var _a;
|
|
207
|
+
if (!((_a = providers.asyncValidators) === null || _a === void 0 ? void 0 : _a[asyncValidator])) {
|
|
207
208
|
throw "You have not provided an asyncValidator for \"".concat(asyncValidator, "\"");
|
|
208
209
|
}
|
|
209
210
|
return actions$.pipe(operators.map(function (_a) {
|
|
@@ -215,16 +216,16 @@ var getScopedEffectsForControl = function (formControl, providers) {
|
|
|
215
216
|
payload: {
|
|
216
217
|
key: key,
|
|
217
218
|
errors: errors,
|
|
218
|
-
validatorIndex: validatorIndex
|
|
219
|
-
}
|
|
219
|
+
validatorIndex: validatorIndex,
|
|
220
|
+
},
|
|
220
221
|
}); }), operators.catchError(function () {
|
|
221
222
|
return rxjs.of({
|
|
222
223
|
type: 'asyncValidationResponse',
|
|
223
224
|
payload: {
|
|
224
225
|
key: key,
|
|
225
226
|
errors: { asyncValidationApiError: true },
|
|
226
|
-
validatorIndex: validatorIndex
|
|
227
|
-
}
|
|
227
|
+
validatorIndex: validatorIndex,
|
|
228
|
+
},
|
|
228
229
|
});
|
|
229
230
|
})));
|
|
230
231
|
}));
|
|
@@ -283,7 +284,7 @@ var updateAncestorValues = function (form, _a, providers) {
|
|
|
283
284
|
}
|
|
284
285
|
var newParentControl = __assign(__assign({}, parentControl), { validatorErrors: getErrors(parentControl, newValue, providers), value: newValue, dirty: !isEqual(newValue, parentControl.pristineValue) });
|
|
285
286
|
return updateAncestorValues(__assign(__assign({}, form), (_c = {}, _c[parentFormKey] = newParentControl, _c)), {
|
|
286
|
-
payload: { controlRef: parentRef, value: newValue }
|
|
287
|
+
payload: { controlRef: parentRef, value: newValue },
|
|
287
288
|
}, providers);
|
|
288
289
|
}
|
|
289
290
|
return form;
|
|
@@ -305,7 +306,7 @@ var getDescendantControls = function (controlRef, form, excludeSelf) {
|
|
|
305
306
|
}
|
|
306
307
|
var control = getControl(controlRef, form);
|
|
307
308
|
var value = control.value, config = control.config;
|
|
308
|
-
var descendants;
|
|
309
|
+
var descendants = [];
|
|
309
310
|
if (Array.isArray(config.controls)) {
|
|
310
311
|
// If control is a Form Array
|
|
311
312
|
descendants = value.reduce(function (acc, item, index) {
|
|
@@ -331,11 +332,11 @@ var getAncestorControls = function (controlRef, form, excludeSelf) {
|
|
|
331
332
|
var formControls = acc.formControls.concat(getControl(currentRef, form));
|
|
332
333
|
return {
|
|
333
334
|
currentRef: currentRef,
|
|
334
|
-
formControls: formControls
|
|
335
|
+
formControls: formControls,
|
|
335
336
|
};
|
|
336
337
|
}, {
|
|
337
338
|
currentRef: [],
|
|
338
|
-
formControls: []
|
|
339
|
+
formControls: [],
|
|
339
340
|
}).formControls;
|
|
340
341
|
var root = form['root'];
|
|
341
342
|
var result = [root].concat(formControls);
|
|
@@ -407,7 +408,7 @@ var updateDescendantValues = function (form, _a, providers) {
|
|
|
407
408
|
if (configControls) {
|
|
408
409
|
checkKeys(oldChildValue, newChildValue);
|
|
409
410
|
acc = updateDescendantValues(acc, {
|
|
410
|
-
payload: { controlRef: control.controlRef, value: newChildValue }
|
|
411
|
+
payload: { controlRef: control.controlRef, value: newChildValue },
|
|
411
412
|
}, providers);
|
|
412
413
|
}
|
|
413
414
|
}
|
|
@@ -419,10 +420,11 @@ var updateDescendantValues = function (form, _a, providers) {
|
|
|
419
420
|
// Use AddControlPayload/RemoveControl action reducers to add/remove control
|
|
420
421
|
var updateValues = function (_a, action, providers, mergeChanges) {
|
|
421
422
|
var _b, _c;
|
|
422
|
-
var
|
|
423
|
+
var _d;
|
|
424
|
+
var form = _a.form, _e = _a._changedControls, _changedControls = _e === void 0 ? {} : _e, _f = _a._removedControls, _removedControls = _f === void 0 ? {} : _f;
|
|
423
425
|
if (mergeChanges === void 0) { mergeChanges = false; }
|
|
424
426
|
var normalizers = providers.normalizers;
|
|
425
|
-
var
|
|
427
|
+
var _g = action.payload, controlRef = _g.controlRef, value = _g.value;
|
|
426
428
|
controlRefCheck(controlRef);
|
|
427
429
|
// Update its own value
|
|
428
430
|
var ctrlKey = getFormKey(controlRef);
|
|
@@ -430,8 +432,8 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
430
432
|
var oldValue = form[ctrlKey].value;
|
|
431
433
|
var config = form[ctrlKey].config;
|
|
432
434
|
if (config.normalizers) {
|
|
433
|
-
newValue = config.normalizers.reduce(function (acc, normalizer) {
|
|
434
|
-
if (!normalizers[normalizer]) {
|
|
435
|
+
newValue = (_d = config.normalizers) === null || _d === void 0 ? void 0 : _d.reduce(function (acc, normalizer) {
|
|
436
|
+
if (!(normalizers === null || normalizers === void 0 ? void 0 : normalizers[normalizer])) {
|
|
435
437
|
throw "You have not provided a normalizer for \"".concat(normalizer, "\"");
|
|
436
438
|
}
|
|
437
439
|
return normalizers[normalizer](acc);
|
|
@@ -441,7 +443,7 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
441
443
|
var newControl = __assign(__assign({}, form[ctrlKey]), { validatorErrors: validatorErrors, dirty: !isEqual(value, form[ctrlKey].pristineValue), value: newValue });
|
|
442
444
|
var result = {
|
|
443
445
|
form: __assign(__assign({}, form), (_b = {}, _b[ctrlKey] = newControl, _b)),
|
|
444
|
-
_changedControls: (_c = {}, _c[newControl.key] = newControl, _c)
|
|
446
|
+
_changedControls: (_c = {}, _c[newControl.key] = newControl, _c),
|
|
445
447
|
};
|
|
446
448
|
var configControls = config.controls;
|
|
447
449
|
// Update its descendants
|
|
@@ -450,8 +452,8 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
450
452
|
var updatedDescendants = updateDescendantValues(result.form, {
|
|
451
453
|
payload: {
|
|
452
454
|
controlRef: controlRef,
|
|
453
|
-
value: newValue
|
|
454
|
-
}
|
|
455
|
+
value: newValue,
|
|
456
|
+
},
|
|
455
457
|
}, providers);
|
|
456
458
|
var changedDescendantControls = getDescendantControls(controlRef, updatedDescendants).reduce(function (acc, control) {
|
|
457
459
|
var _a;
|
|
@@ -462,7 +464,7 @@ var updateValues = function (_a, action, providers, mergeChanges) {
|
|
|
462
464
|
// Update its Ancestors
|
|
463
465
|
if (controlRef.length) {
|
|
464
466
|
result = __assign(__assign({}, result), { form: updateAncestorValues(result.form, {
|
|
465
|
-
payload: { controlRef: controlRef, value: newValue }
|
|
467
|
+
payload: { controlRef: controlRef, value: newValue },
|
|
466
468
|
}, providers) });
|
|
467
469
|
}
|
|
468
470
|
var changedAncestorControls = getAncestorControls(controlRef, result.form).reduce(function (acc, control) {
|
|
@@ -493,7 +495,7 @@ var updateAncestorValuesRemoveControl = function (form, _a, providers) {
|
|
|
493
495
|
}
|
|
494
496
|
var newParentControl = __assign(__assign({}, parentControl), { value: newValue, validatorErrors: getErrors(parentControl, newValue, providers), dirty: !isEqual(newValue, parentControl.pristineValue) });
|
|
495
497
|
return updateAncestorValues(__assign(__assign({}, form), (_b = {}, _b[parentFormKey] = newParentControl, _b)), {
|
|
496
|
-
payload: { controlRef: parentRef, value: newValue }
|
|
498
|
+
payload: { controlRef: parentRef, value: newValue },
|
|
497
499
|
}, providers);
|
|
498
500
|
}
|
|
499
501
|
return form;
|
|
@@ -547,7 +549,7 @@ var removeControl = function (state, action, providers, mergeChanges) {
|
|
|
547
549
|
return __assign(__assign({}, acc), (_c = {}, _c[key] = control, _c));
|
|
548
550
|
}, {});
|
|
549
551
|
var result = updateAncestorValuesRemoveControl(controlRemoved, {
|
|
550
|
-
payload: controlRef
|
|
552
|
+
payload: controlRef,
|
|
551
553
|
}, providers);
|
|
552
554
|
var _changedControls = __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), getAncestorControls(controlRef.slice(0, -1), result).reduce(function (acc, control) {
|
|
553
555
|
var _a;
|
|
@@ -588,7 +590,7 @@ var removeControl = function (state, action, providers, mergeChanges) {
|
|
|
588
590
|
return {
|
|
589
591
|
form: result,
|
|
590
592
|
_changedControls: _changedControls,
|
|
591
|
-
_removedControls: _removedControls
|
|
593
|
+
_removedControls: _removedControls,
|
|
592
594
|
};
|
|
593
595
|
};
|
|
594
596
|
|
|
@@ -611,7 +613,7 @@ var updateAncestorValuesAddControl = function (form, _a, providers) {
|
|
|
611
613
|
}
|
|
612
614
|
var newParentControl = __assign(__assign({}, parentControl), { value: newValue, validatorErrors: getErrors(parentControl, newValue, providers), dirty: !isEqual(newValue, parentControl.pristineValue) });
|
|
613
615
|
return updateAncestorValues(__assign(__assign({}, form), (_c = {}, _c[parentFormKey] = newParentControl, _c)), {
|
|
614
|
-
payload: { controlRef: parentRef, value: newValue }
|
|
616
|
+
payload: { controlRef: parentRef, value: newValue },
|
|
615
617
|
}, providers);
|
|
616
618
|
}
|
|
617
619
|
return form;
|
|
@@ -631,10 +633,10 @@ var addControl = function (state, action, providers, mergeChanges) {
|
|
|
631
633
|
if (!getControl(controlRef.slice(0, -1), state.form)) {
|
|
632
634
|
throw 'You are attempting to add a control to a non-existent form group';
|
|
633
635
|
}
|
|
634
|
-
var newForm = buildState(config,
|
|
636
|
+
var newForm = buildState(config, controlRef, providers, state.form);
|
|
635
637
|
var newValue = getControl(controlRef, newForm).value;
|
|
636
638
|
var ancestorsUpdated = updateAncestorValuesAddControl(newForm, {
|
|
637
|
-
payload: { controlRef: controlRef, value: newValue }
|
|
639
|
+
payload: { controlRef: controlRef, value: newValue },
|
|
638
640
|
}, providers);
|
|
639
641
|
var _changedControls = getControlBranch(controlRef, ancestorsUpdated).reduce(function (acc, control) {
|
|
640
642
|
var _a;
|
|
@@ -643,7 +645,7 @@ var addControl = function (state, action, providers, mergeChanges) {
|
|
|
643
645
|
return {
|
|
644
646
|
form: ancestorsUpdated,
|
|
645
647
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
646
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
648
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
647
649
|
};
|
|
648
650
|
};
|
|
649
651
|
|
|
@@ -662,10 +664,10 @@ var pushControl = function (state, action, providers, mergeChanges) {
|
|
|
662
664
|
else {
|
|
663
665
|
throw 'You are attempting to push to a control that is not a Form Array';
|
|
664
666
|
}
|
|
665
|
-
var newForm = buildState(config,
|
|
667
|
+
var newForm = buildState(config, newControlRef, providers, state.form);
|
|
666
668
|
var newValue = getControl(newControlRef, newForm).value;
|
|
667
669
|
var ancestorsUpdated = updateAncestorValuesAddControl(newForm, {
|
|
668
|
-
payload: { controlRef: newControlRef, value: newValue }
|
|
670
|
+
payload: { controlRef: newControlRef, value: newValue },
|
|
669
671
|
}, providers);
|
|
670
672
|
var _changedControls = getControlBranch(newControlRef, ancestorsUpdated).reduce(function (acc, control) {
|
|
671
673
|
var _a;
|
|
@@ -674,7 +676,7 @@ var pushControl = function (state, action, providers, mergeChanges) {
|
|
|
674
676
|
return {
|
|
675
677
|
form: ancestorsUpdated,
|
|
676
678
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
677
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
679
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
678
680
|
};
|
|
679
681
|
};
|
|
680
682
|
|
|
@@ -705,7 +707,7 @@ var updateAncestorPristineValues = function (form, _a) {
|
|
|
705
707
|
}
|
|
706
708
|
var newParentControl = __assign(__assign({}, form[parentKey]), { pristineValue: newValue, dirty: isEqual(form[parentKey].value, newValue) });
|
|
707
709
|
return updateAncestorPristineValues(__assign(__assign({}, form), (_b = {}, _b[parentKey] = newParentControl, _b)), {
|
|
708
|
-
payload: parentRef
|
|
710
|
+
payload: parentRef,
|
|
709
711
|
});
|
|
710
712
|
}
|
|
711
713
|
return form;
|
|
@@ -723,7 +725,7 @@ var markControlAsPristine = function (state, action, mergeChanges) {
|
|
|
723
725
|
var result = __assign(__assign({}, form), descendants);
|
|
724
726
|
if (controlRef.length) {
|
|
725
727
|
result = updateAncestorPristineValues(result, {
|
|
726
|
-
payload: controlRef
|
|
728
|
+
payload: controlRef,
|
|
727
729
|
});
|
|
728
730
|
}
|
|
729
731
|
var _changedControls = getControlBranch(controlRef, result).reduce(function (acc, control) {
|
|
@@ -733,7 +735,7 @@ var markControlAsPristine = function (state, action, mergeChanges) {
|
|
|
733
735
|
return {
|
|
734
736
|
form: result,
|
|
735
737
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
736
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
738
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
737
739
|
};
|
|
738
740
|
};
|
|
739
741
|
|
|
@@ -755,7 +757,7 @@ var markControlAsTouched = function (state, action, mergeChanges) {
|
|
|
755
757
|
return {
|
|
756
758
|
form: __assign(__assign({}, form), controls),
|
|
757
759
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
758
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
760
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
759
761
|
};
|
|
760
762
|
};
|
|
761
763
|
|
|
@@ -785,7 +787,7 @@ var markControlAsUntouched = function (state, action, mergeChanges) {
|
|
|
785
787
|
return {
|
|
786
788
|
form: result,
|
|
787
789
|
_changedControls: __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), _changedControls),
|
|
788
|
-
_removedControls: mergeChanges ? state._removedControls || {} : undefined
|
|
790
|
+
_removedControls: mergeChanges ? state._removedControls || {} : undefined,
|
|
789
791
|
};
|
|
790
792
|
};
|
|
791
793
|
|
|
@@ -806,10 +808,10 @@ var resetControl = function (state, action, providers, mergeChanges) {
|
|
|
806
808
|
delete descendantsRemoved[key];
|
|
807
809
|
});
|
|
808
810
|
// Remove all descendants
|
|
809
|
-
var restoredControls = buildState(controlToReset.config,
|
|
811
|
+
var restoredControls = buildState(controlToReset.config, controlToReset.controlRef, providers, descendantsRemoved);
|
|
810
812
|
var restoredControlValue = getControl(controlRef, restoredControls).value;
|
|
811
813
|
var result = updateAncestorValues(restoredControls, {
|
|
812
|
-
payload: { controlRef: controlRef, value: restoredControlValue }
|
|
814
|
+
payload: { controlRef: controlRef, value: restoredControlValue },
|
|
813
815
|
}, providers);
|
|
814
816
|
var _changedControls = __assign(__assign({}, (mergeChanges ? state._changedControls || {} : undefined)), getControlBranch(controlRef, result).reduce(function (acc, control) {
|
|
815
817
|
var _a;
|
|
@@ -828,7 +830,7 @@ var resetControl = function (state, action, providers, mergeChanges) {
|
|
|
828
830
|
return {
|
|
829
831
|
form: result,
|
|
830
832
|
_changedControls: _changedControls,
|
|
831
|
-
_removedControls: _removedControls
|
|
833
|
+
_removedControls: _removedControls,
|
|
832
834
|
};
|
|
833
835
|
};
|
|
834
836
|
|
|
@@ -836,12 +838,14 @@ var asyncValidation = function (form, _a) {
|
|
|
836
838
|
var controlRef = _a.payload;
|
|
837
839
|
var updatedSelfAndAncestors = getAncestorControls(controlRef, form).reduce(function (acc, control) {
|
|
838
840
|
var _a;
|
|
841
|
+
var _b;
|
|
839
842
|
var isChangedControl = getFormKey(control.controlRef) === getFormKey(controlRef);
|
|
840
843
|
return __assign(__assign({}, acc), (_a = {}, _a[getFormKey(control.controlRef)] = __assign(__assign({}, control), { pending: true, asyncValidateInProgress: isChangedControl
|
|
841
|
-
? __assign({}, control.config.asyncValidators.reduce(function (acc, _, index) {
|
|
844
|
+
? __assign({}, (_b = control.config.asyncValidators) === null || _b === void 0 ? void 0 : _b.reduce(function (acc, _, index) {
|
|
842
845
|
var _a;
|
|
843
846
|
return (__assign(__assign({}, acc), (_a = {}, _a[index] = true, _a)));
|
|
844
|
-
}, {}))
|
|
847
|
+
}, {}))
|
|
848
|
+
: control.asyncValidateInProgress }), _a));
|
|
845
849
|
}, {});
|
|
846
850
|
return __assign(__assign({}, form), updatedSelfAndAncestors);
|
|
847
851
|
};
|
|
@@ -962,8 +966,7 @@ var mergeRemoveControl = function (state, form, controlRef) {
|
|
|
962
966
|
.reduce(function (acc, baseControl) {
|
|
963
967
|
var _a;
|
|
964
968
|
var key = getFormKey(baseControl.controlRef);
|
|
965
|
-
var existingControl = existingBranch.find(function (control) { return baseControl.key === control.key; }) ||
|
|
966
|
-
structuredClone(DEFAULT_HUB2_FIELDS);
|
|
969
|
+
var existingControl = existingBranch.find(function (control) { return baseControl.key === control.key; }) || cloneHub2Fields();
|
|
967
970
|
var errors = __assign(__assign({}, baseControl.validatorErrors), existingControl.asyncValidatorErrors);
|
|
968
971
|
var selfValid = !hasErrors$1(errors);
|
|
969
972
|
var childrenValid = true;
|
|
@@ -1012,9 +1015,7 @@ var mergeControls = function (state, _a) {
|
|
|
1012
1015
|
var _a;
|
|
1013
1016
|
var formKey = getFormKey(control.controlRef);
|
|
1014
1017
|
var existingControl = controlsRemoved && controlsRemoved[formKey];
|
|
1015
|
-
var newControl = __assign(__assign({}, (existingControl
|
|
1016
|
-
? existingControl
|
|
1017
|
-
: structuredClone(DEFAULT_HUB2_FIELDS))), control);
|
|
1018
|
+
var newControl = __assign(__assign({}, (existingControl ? existingControl : cloneHub2Fields())), control);
|
|
1018
1019
|
var errors = __assign(__assign({}, newControl.validatorErrors), newControl.asyncValidatorErrors);
|
|
1019
1020
|
var selfValid = !hasErrors(errors);
|
|
1020
1021
|
var childrenValid = true;
|
|
@@ -1049,7 +1050,7 @@ var formChange = function (state, _a) {
|
|
|
1049
1050
|
return mergeErrors(Object.entries(form).reduce(function (acc, _a) {
|
|
1050
1051
|
var _b;
|
|
1051
1052
|
var dictKey = _a[0], baseControl = _a[1];
|
|
1052
|
-
return __assign(__assign({}, acc), (_b = {}, _b[dictKey] = __assign(__assign({},
|
|
1053
|
+
return __assign(__assign({}, acc), (_b = {}, _b[dictKey] = __assign(__assign({}, cloneHub2Fields()), baseControl), _b));
|
|
1053
1054
|
}, {}));
|
|
1054
1055
|
}
|
|
1055
1056
|
return mergeControls(state, payload);
|
|
@@ -1062,7 +1063,7 @@ var control = function (config) {
|
|
|
1062
1063
|
var indexMap = {
|
|
1063
1064
|
0: 'initialValue',
|
|
1064
1065
|
1: 'validators',
|
|
1065
|
-
2: 'asyncValidators'
|
|
1066
|
+
2: 'asyncValidators',
|
|
1066
1067
|
};
|
|
1067
1068
|
return __assign(__assign({}, acc), (_a = {}, _a[indexMap[index]] = index < 1 ? item : [].concat(item || []), _a));
|
|
1068
1069
|
}, {});
|
|
@@ -1095,7 +1096,7 @@ var reducerTools = function (providers) { return ({
|
|
|
1095
1096
|
},
|
|
1096
1097
|
markControlAsUntouched: function (state, payload) {
|
|
1097
1098
|
return markControlAsUntouched(state, { payload: payload }, true);
|
|
1098
|
-
}
|
|
1099
|
+
},
|
|
1099
1100
|
}); };
|
|
1100
1101
|
var build = function (config, options) {
|
|
1101
1102
|
var _a, _b, _c;
|
|
@@ -1103,9 +1104,9 @@ var build = function (config, options) {
|
|
|
1103
1104
|
var providers = {
|
|
1104
1105
|
normalizers: __assign({}, (_a = options.providers) === null || _a === void 0 ? void 0 : _a.normalizers),
|
|
1105
1106
|
validators: __assign(__assign({}, Validators), (_b = options.providers) === null || _b === void 0 ? void 0 : _b.validators),
|
|
1106
|
-
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators)
|
|
1107
|
+
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators),
|
|
1107
1108
|
};
|
|
1108
|
-
var initialState = buildFormState(config, undefined,
|
|
1109
|
+
var initialState = buildFormState(config, undefined, providers);
|
|
1109
1110
|
return createReactable(initialState, options);
|
|
1110
1111
|
};
|
|
1111
1112
|
var load = function (state, options) {
|
|
@@ -1124,7 +1125,7 @@ var load = function (state, options) {
|
|
|
1124
1125
|
var key = _a[0], value = _a[1];
|
|
1125
1126
|
return (__assign(__assign({}, acc), (_b = {}, _b[key] = value, _b)));
|
|
1126
1127
|
}, {}), _b));
|
|
1127
|
-
}, {})
|
|
1128
|
+
}, {}),
|
|
1128
1129
|
};
|
|
1129
1130
|
return createReactable(baseFormState, options);
|
|
1130
1131
|
};
|
|
@@ -1134,7 +1135,7 @@ var createReactable = function (initialBaseState, options, initialFormState) {
|
|
|
1134
1135
|
var providers = {
|
|
1135
1136
|
normalizers: __assign({}, (_a = options.providers) === null || _a === void 0 ? void 0 : _a.normalizers),
|
|
1136
1137
|
validators: __assign(__assign({}, Validators), (_b = options.providers) === null || _b === void 0 ? void 0 : _b.validators),
|
|
1137
|
-
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators)
|
|
1138
|
+
asyncValidators: __assign({}, (_c = options.providers) === null || _c === void 0 ? void 0 : _c.asyncValidators),
|
|
1138
1139
|
};
|
|
1139
1140
|
var reducers = options.reducers, debug = options.debug, name = options.name, otherOptions = __rest(options, ["reducers", "debug", "name"]);
|
|
1140
1141
|
var customReducers = Object.entries(reducers || {}).reduce(function (acc, _a) {
|
|
@@ -1147,7 +1148,7 @@ var createReactable = function (initialBaseState, options, initialFormState) {
|
|
|
1147
1148
|
var form = _a.form;
|
|
1148
1149
|
return _reducer(reducerTools(providers), { form: form }, action);
|
|
1149
1150
|
},
|
|
1150
|
-
effects: effects
|
|
1151
|
+
effects: effects,
|
|
1151
1152
|
}, _b));
|
|
1152
1153
|
}, {});
|
|
1153
1154
|
var _d = core.RxBuilder(__assign({ initialState: initialBaseState, name: "Stage 1 ".concat(name ? name : 'rxForm'), debug: debug, reducers: __assign({ updateValues: function (state, action) {
|
|
@@ -1174,20 +1175,21 @@ var createReactable = function (initialBaseState, options, initialFormState) {
|
|
|
1174
1175
|
reducer: function (state) { return state; },
|
|
1175
1176
|
effects: function (control) { return ({
|
|
1176
1177
|
key: control.key,
|
|
1177
|
-
effects: getScopedEffectsForControl(control, providers)
|
|
1178
|
-
}); }
|
|
1178
|
+
effects: getScopedEffectsForControl(control, providers),
|
|
1179
|
+
}); },
|
|
1179
1180
|
},
|
|
1180
1181
|
asyncValidation: asyncValidation,
|
|
1181
|
-
asyncValidationResponse: asyncValidationResponse
|
|
1182
|
-
}
|
|
1182
|
+
asyncValidationResponse: asyncValidationResponse,
|
|
1183
|
+
},
|
|
1183
1184
|
}), state$ = _e[0], hub2Actions = _e[1];
|
|
1184
1185
|
var destroy = function () {
|
|
1185
1186
|
hub1Actions.destroy();
|
|
1186
1187
|
hub2Actions.destroy();
|
|
1187
1188
|
};
|
|
1189
|
+
var actions = __assign(__assign({}, hub1Actions), { destroy: destroy });
|
|
1188
1190
|
return [
|
|
1189
1191
|
state$.pipe(operators.filter(function (form) { return form !== null; })),
|
|
1190
|
-
|
|
1192
|
+
actions,
|
|
1191
1193
|
hub1Actions$,
|
|
1192
1194
|
];
|
|
1193
1195
|
};
|