@reactables/forms 2.0.0 → 2.0.2
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/Models/Controls.d.ts +1 -0
- package/dist/index.cjs +16 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +16 -14
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -13,10 +13,12 @@ var DEFAULT_HUB2_FIELDS = {
|
|
|
13
13
|
childrenValid: null,
|
|
14
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) {
|
|
@@ -397,7 +399,7 @@ var updateDescendantValues = function (form, _a, providers) {
|
|
|
397
399
|
var _b;
|
|
398
400
|
var key = _a[0], control = _a[1];
|
|
399
401
|
if (isChildRef(control.controlRef, controlRef)) {
|
|
400
|
-
var newChildValue = value[control.controlRef.
|
|
402
|
+
var newChildValue = value[control.controlRef[control.controlRef.length - 1]];
|
|
401
403
|
var validatorErrors = getErrors(control, newChildValue, providers);
|
|
402
404
|
var oldChildValue = control.value;
|
|
403
405
|
var newControl = __assign(__assign({}, control), { value: newChildValue, validatorErrors: validatorErrors, dirty: !isEqual(newChildValue, control.pristineValue) });
|
|
@@ -530,14 +532,14 @@ var removeControl = function (state, action, providers, mergeChanges) {
|
|
|
530
532
|
// May need to reindex array items of removed control
|
|
531
533
|
// if it was part of a Form Array.
|
|
532
534
|
if (parentIsFormArray) {
|
|
533
|
-
var oldIndex = control.controlRef
|
|
535
|
+
var oldIndex = control.controlRef[parentRef.length];
|
|
534
536
|
if (
|
|
535
537
|
// If control is descendant.
|
|
536
538
|
parentRef.every(function (ref, index) { return control.controlRef[index] === ref; }) &&
|
|
537
539
|
control.controlRef.length > parentRef.length &&
|
|
538
540
|
// If the array item index was greater than the index of item removed
|
|
539
541
|
// we need to decrement its index by 1.
|
|
540
|
-
oldIndex > controlRef.
|
|
542
|
+
oldIndex > controlRef[controlRef.length - 1]) {
|
|
541
543
|
var newRef = parentRef
|
|
542
544
|
.concat(oldIndex - 1)
|
|
543
545
|
.concat(control.controlRef.slice(parentRef.length + 1));
|
|
@@ -558,14 +560,14 @@ var removeControl = function (state, action, providers, mergeChanges) {
|
|
|
558
560
|
_changedControls = Object.entries(_changedControls).reduce(function (acc, _a) {
|
|
559
561
|
var _b, _c;
|
|
560
562
|
var key = _a[0], control = _a[1];
|
|
561
|
-
var oldIndex = control.controlRef
|
|
563
|
+
var oldIndex = control.controlRef[parentRef.length];
|
|
562
564
|
if (
|
|
563
565
|
// If control is descendant.
|
|
564
566
|
parentRef.every(function (ref, index) { return control.controlRef[index] === ref; }) &&
|
|
565
567
|
control.controlRef.length > parentRef.length &&
|
|
566
568
|
// If the array item index was greater than the index of item removed
|
|
567
569
|
// we need to decrement its index by 1.
|
|
568
|
-
oldIndex > controlRef.
|
|
570
|
+
oldIndex > controlRef[controlRef.length - 1]) {
|
|
569
571
|
var newRef = parentRef
|
|
570
572
|
.concat(oldIndex - 1)
|
|
571
573
|
.concat(control.controlRef.slice(parentRef.length + 1));
|
|
@@ -692,7 +694,10 @@ var updateAncestorPristineValues = function (form, _a) {
|
|
|
692
694
|
if (Array.isArray(form[parentKey].value)) {
|
|
693
695
|
newValue = siblingControls
|
|
694
696
|
.slice()
|
|
695
|
-
.sort(function (a, b) {
|
|
697
|
+
.sort(function (a, b) {
|
|
698
|
+
return a.controlRef[a.controlRef.length - 1] -
|
|
699
|
+
b.controlRef[b.controlRef.length - 1];
|
|
700
|
+
})
|
|
696
701
|
.map(function (control) { return control.pristineValue; });
|
|
697
702
|
}
|
|
698
703
|
else {
|
|
@@ -700,7 +705,7 @@ var updateAncestorPristineValues = function (form, _a) {
|
|
|
700
705
|
newValue = siblingControls.reduce(function (acc, _a) {
|
|
701
706
|
var _b;
|
|
702
707
|
var controlRef = _a.controlRef, pristineValue = _a.pristineValue;
|
|
703
|
-
return __assign(__assign({}, acc), (_b = {}, _b[controlRef.
|
|
708
|
+
return __assign(__assign({}, acc), (_b = {}, _b[controlRef[controlRef.length - 1]] = pristineValue, _b));
|
|
704
709
|
}, {});
|
|
705
710
|
}
|
|
706
711
|
var newParentControl = __assign(__assign({}, form[parentKey]), { pristineValue: newValue, dirty: isEqual(form[parentKey].value, newValue) });
|
|
@@ -964,8 +969,7 @@ var mergeRemoveControl = function (state, form, controlRef) {
|
|
|
964
969
|
.reduce(function (acc, baseControl) {
|
|
965
970
|
var _a;
|
|
966
971
|
var key = getFormKey(baseControl.controlRef);
|
|
967
|
-
var existingControl = existingBranch.find(function (control) { return baseControl.key === control.key; }) ||
|
|
968
|
-
structuredClone(DEFAULT_HUB2_FIELDS);
|
|
972
|
+
var existingControl = existingBranch.find(function (control) { return baseControl.key === control.key; }) || cloneHub2Fields();
|
|
969
973
|
var errors = __assign(__assign({}, baseControl.validatorErrors), existingControl.asyncValidatorErrors);
|
|
970
974
|
var selfValid = !hasErrors$1(errors);
|
|
971
975
|
var childrenValid = true;
|
|
@@ -1014,9 +1018,7 @@ var mergeControls = function (state, _a) {
|
|
|
1014
1018
|
var _a;
|
|
1015
1019
|
var formKey = getFormKey(control.controlRef);
|
|
1016
1020
|
var existingControl = controlsRemoved && controlsRemoved[formKey];
|
|
1017
|
-
var newControl = __assign(__assign({}, (existingControl
|
|
1018
|
-
? existingControl
|
|
1019
|
-
: structuredClone(DEFAULT_HUB2_FIELDS))), control);
|
|
1021
|
+
var newControl = __assign(__assign({}, (existingControl ? existingControl : cloneHub2Fields())), control);
|
|
1020
1022
|
var errors = __assign(__assign({}, newControl.validatorErrors), newControl.asyncValidatorErrors);
|
|
1021
1023
|
var selfValid = !hasErrors(errors);
|
|
1022
1024
|
var childrenValid = true;
|
|
@@ -1051,7 +1053,7 @@ var formChange = function (state, _a) {
|
|
|
1051
1053
|
return mergeErrors(Object.entries(form).reduce(function (acc, _a) {
|
|
1052
1054
|
var _b;
|
|
1053
1055
|
var dictKey = _a[0], baseControl = _a[1];
|
|
1054
|
-
return __assign(__assign({}, acc), (_b = {}, _b[dictKey] = __assign(__assign({},
|
|
1056
|
+
return __assign(__assign({}, acc), (_b = {}, _b[dictKey] = __assign(__assign({}, cloneHub2Fields()), baseControl), _b));
|
|
1055
1057
|
}, {}));
|
|
1056
1058
|
}
|
|
1057
1059
|
return mergeControls(state, payload);
|