@reactables/forms 2.0.0 → 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.
@@ -46,4 +46,5 @@ export type Form<T> = {
46
46
  [key: string]: FormControl<unknown>;
47
47
  };
48
48
  export declare const DEFAULT_HUB2_FIELDS: Hub2Fields;
49
+ export declare const cloneHub2Fields: () => Hub2Fields;
49
50
  export {};
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) {
@@ -964,8 +966,7 @@ var mergeRemoveControl = function (state, form, controlRef) {
964
966
  .reduce(function (acc, baseControl) {
965
967
  var _a;
966
968
  var key = getFormKey(baseControl.controlRef);
967
- var existingControl = existingBranch.find(function (control) { return baseControl.key === control.key; }) ||
968
- structuredClone(DEFAULT_HUB2_FIELDS);
969
+ var existingControl = existingBranch.find(function (control) { return baseControl.key === control.key; }) || cloneHub2Fields();
969
970
  var errors = __assign(__assign({}, baseControl.validatorErrors), existingControl.asyncValidatorErrors);
970
971
  var selfValid = !hasErrors$1(errors);
971
972
  var childrenValid = true;
@@ -1014,9 +1015,7 @@ var mergeControls = function (state, _a) {
1014
1015
  var _a;
1015
1016
  var formKey = getFormKey(control.controlRef);
1016
1017
  var existingControl = controlsRemoved && controlsRemoved[formKey];
1017
- var newControl = __assign(__assign({}, (existingControl
1018
- ? existingControl
1019
- : structuredClone(DEFAULT_HUB2_FIELDS))), control);
1018
+ var newControl = __assign(__assign({}, (existingControl ? existingControl : cloneHub2Fields())), control);
1020
1019
  var errors = __assign(__assign({}, newControl.validatorErrors), newControl.asyncValidatorErrors);
1021
1020
  var selfValid = !hasErrors(errors);
1022
1021
  var childrenValid = true;
@@ -1051,7 +1050,7 @@ var formChange = function (state, _a) {
1051
1050
  return mergeErrors(Object.entries(form).reduce(function (acc, _a) {
1052
1051
  var _b;
1053
1052
  var dictKey = _a[0], baseControl = _a[1];
1054
- return __assign(__assign({}, acc), (_b = {}, _b[dictKey] = __assign(__assign({}, structuredClone(DEFAULT_HUB2_FIELDS)), baseControl), _b));
1053
+ return __assign(__assign({}, acc), (_b = {}, _b[dictKey] = __assign(__assign({}, cloneHub2Fields()), baseControl), _b));
1055
1054
  }, {}));
1056
1055
  }
1057
1056
  return mergeControls(state, payload);