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