react-hook-form 7.28.1 → 8.0.0-alpha.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.
Files changed (116) hide show
  1. package/dist/__typetests__/__fixtures__/index.d.ts +2 -0
  2. package/dist/__typetests__/__fixtures__/index.d.ts.map +1 -0
  3. package/dist/__typetests__/__fixtures__/type.d.ts +12 -0
  4. package/dist/__typetests__/__fixtures__/type.d.ts.map +1 -0
  5. package/dist/__typetests__/types/__fixtures__/index.d.ts +4 -0
  6. package/dist/__typetests__/types/__fixtures__/index.d.ts.map +1 -0
  7. package/dist/__typetests__/types/__fixtures__/pathString.d.ts +4 -0
  8. package/dist/__typetests__/types/__fixtures__/pathString.d.ts.map +1 -0
  9. package/dist/__typetests__/types/__fixtures__/traversable.d.ts +14 -0
  10. package/dist/__typetests__/types/__fixtures__/traversable.d.ts.map +1 -0
  11. package/dist/__typetests__/types/__fixtures__/tuple.d.ts +15 -0
  12. package/dist/__typetests__/types/__fixtures__/tuple.d.ts.map +1 -0
  13. package/dist/__typetests__/types/form.test-d.d.ts +2 -0
  14. package/dist/__typetests__/types/form.test-d.d.ts.map +1 -0
  15. package/dist/__typetests__/types/path/auto.test-d.d.ts +2 -0
  16. package/dist/__typetests__/types/path/auto.test-d.d.ts.map +1 -0
  17. package/dist/__typetests__/types/path/internal/autoCompletePath.test-d.d.ts +2 -0
  18. package/dist/__typetests__/types/path/internal/autoCompletePath.test-d.d.ts.map +1 -0
  19. package/dist/__typetests__/types/path/internal/hasPath.test-d.d.ts +2 -0
  20. package/dist/__typetests__/types/path/internal/hasPath.test-d.d.ts.map +1 -0
  21. package/dist/__typetests__/types/path/internal/keys.test-d.d.ts +2 -0
  22. package/dist/__typetests__/types/path/internal/keys.test-d.d.ts.map +1 -0
  23. package/dist/__typetests__/types/path/internal/pathGetValue.test-d.d.ts +2 -0
  24. package/dist/__typetests__/types/path/internal/pathGetValue.test-d.d.ts.map +1 -0
  25. package/dist/__typetests__/types/path/internal/pathSetValue.test-d.d.ts +2 -0
  26. package/dist/__typetests__/types/path/internal/pathSetValue.test-d.d.ts.map +1 -0
  27. package/dist/__typetests__/types/path/internal/pathTuple.test-d.d.ts +2 -0
  28. package/dist/__typetests__/types/path/internal/pathTuple.test-d.d.ts.map +1 -0
  29. package/dist/__typetests__/types/path/internal/utils.test-d.d.ts +2 -0
  30. package/dist/__typetests__/types/path/internal/utils.test-d.d.ts.map +1 -0
  31. package/dist/__typetests__/types/path/lazy.test-d.d.ts +2 -0
  32. package/dist/__typetests__/types/path/lazy.test-d.d.ts.map +1 -0
  33. package/dist/__typetests__/types/path/value.test-d.d.ts +2 -0
  34. package/dist/__typetests__/types/path/value.test-d.d.ts.map +1 -0
  35. package/dist/__typetests__/types/util.test-d.d.ts +2 -0
  36. package/dist/__typetests__/types/util.test-d.d.ts.map +1 -0
  37. package/dist/__typetests__/utils/join.test-d.d.ts +2 -0
  38. package/dist/__typetests__/utils/join.test-d.d.ts.map +1 -0
  39. package/dist/__typetests__/utils/of.test-d.d.ts +2 -0
  40. package/dist/__typetests__/utils/of.test-d.d.ts.map +1 -0
  41. package/dist/controller.d.ts +1 -1
  42. package/dist/controller.d.ts.map +1 -1
  43. package/dist/index.cjs.js +1 -1
  44. package/dist/index.cjs.js.map +1 -1
  45. package/dist/index.esm.mjs +210 -109
  46. package/dist/index.esm.mjs.map +1 -1
  47. package/dist/index.umd.js +1 -1
  48. package/dist/index.umd.js.map +1 -1
  49. package/dist/logic/createFormControl.d.ts.map +1 -1
  50. package/dist/logic/focusFieldBy.d.ts.map +1 -1
  51. package/dist/logic/getResolverOptions.d.ts +2 -2
  52. package/dist/logic/hasValidation.d.ts +1 -1
  53. package/dist/logic/shouldRenderFormState.d.ts.map +1 -1
  54. package/dist/types/controller.d.ts +8 -8
  55. package/dist/types/controller.d.ts.map +1 -1
  56. package/dist/types/errors.d.ts +8 -2
  57. package/dist/types/errors.d.ts.map +1 -1
  58. package/dist/types/fieldArray.d.ts +14 -14
  59. package/dist/types/fieldArray.d.ts.map +1 -1
  60. package/dist/types/form.d.ts +34 -44
  61. package/dist/types/form.d.ts.map +1 -1
  62. package/dist/types/path/auto.d.ts +76 -0
  63. package/dist/types/path/auto.d.ts.map +1 -0
  64. package/dist/types/path/branded.d.ts +61 -0
  65. package/dist/types/path/branded.d.ts.map +1 -0
  66. package/dist/types/path/index.d.ts +7 -3
  67. package/dist/types/path/index.d.ts.map +1 -1
  68. package/dist/types/path/internal/autoCompletePath.d.ts +173 -0
  69. package/dist/types/path/internal/autoCompletePath.d.ts.map +1 -0
  70. package/dist/types/path/internal/hasPath.d.ts +56 -0
  71. package/dist/types/path/internal/hasPath.d.ts.map +1 -0
  72. package/dist/types/path/internal/keys.d.ts +103 -0
  73. package/dist/types/path/internal/keys.d.ts.map +1 -0
  74. package/dist/types/path/internal/pathGetValue.d.ts +76 -0
  75. package/dist/types/path/internal/pathGetValue.d.ts.map +1 -0
  76. package/dist/types/path/internal/pathSetValue.d.ts +96 -0
  77. package/dist/types/path/internal/pathSetValue.d.ts.map +1 -0
  78. package/dist/types/path/internal/pathTuple.d.ts +73 -0
  79. package/dist/types/path/internal/pathTuple.d.ts.map +1 -0
  80. package/dist/types/path/internal/utils.d.ts +84 -0
  81. package/dist/types/path/internal/utils.d.ts.map +1 -0
  82. package/dist/types/path/lazy.d.ts +62 -0
  83. package/dist/types/path/lazy.d.ts.map +1 -0
  84. package/dist/types/path/pathString.d.ts +6 -0
  85. package/dist/types/path/pathString.d.ts.map +1 -0
  86. package/dist/types/path/value.d.ts +49 -0
  87. package/dist/types/path/value.d.ts.map +1 -0
  88. package/dist/types/resolvers.d.ts +3 -3
  89. package/dist/types/resolvers.d.ts.map +1 -1
  90. package/dist/types/utils.d.ts +15 -7
  91. package/dist/types/utils.d.ts.map +1 -1
  92. package/dist/types/validator.d.ts +2 -2
  93. package/dist/types/validator.d.ts.map +1 -1
  94. package/dist/useController.d.ts +2 -2
  95. package/dist/useController.d.ts.map +1 -1
  96. package/dist/useFieldArray.d.ts +2 -2
  97. package/dist/useFieldArray.d.ts.map +1 -1
  98. package/dist/useForm.d.ts.map +1 -1
  99. package/dist/useFormContext.d.ts.map +1 -1
  100. package/dist/useFormState.d.ts +2 -2
  101. package/dist/useFormState.d.ts.map +1 -1
  102. package/dist/useWatch.d.ts +9 -23
  103. package/dist/useWatch.d.ts.map +1 -1
  104. package/dist/utils/index.d.ts +3 -1
  105. package/dist/utils/index.d.ts.map +1 -1
  106. package/dist/utils/join.d.ts +16 -0
  107. package/dist/utils/join.d.ts.map +1 -0
  108. package/dist/utils/of.d.ts +13 -0
  109. package/dist/utils/of.d.ts.map +1 -0
  110. package/package.json +9 -9
  111. package/dist/types/path/common.d.ts +0 -316
  112. package/dist/types/path/common.d.ts.map +0 -1
  113. package/dist/types/path/eager.d.ts +0 -82
  114. package/dist/types/path/eager.d.ts.map +0 -1
  115. package/dist/utils/omitKeys.d.ts +0 -3
  116. package/dist/utils/omitKeys.d.ts.map +0 -1
@@ -60,12 +60,6 @@ const INPUT_VALIDATION_RULES = {
60
60
  validate: 'validate',
61
61
  };
62
62
 
63
- var omit = (source, key) => {
64
- const copy = Object.assign({}, source);
65
- delete copy[key];
66
- return copy;
67
- };
68
-
69
63
  const HookFormContext = React.createContext(null);
70
64
  /**
71
65
  * This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.
@@ -128,7 +122,10 @@ const useFormContext = () => React.useContext(HookFormContext);
128
122
  * }
129
123
  * ```
130
124
  */
131
- const FormProvider = (props) => (React.createElement(HookFormContext.Provider, { value: omit(props, 'children') }, props.children));
125
+ const FormProvider = (props) => {
126
+ const { children, ...data } = props;
127
+ return (React.createElement(HookFormContext.Provider, { value: data }, props.children));
128
+ };
132
129
 
133
130
  var getProxyFormState = (formState, _proxyFormState, localProxyFormState, isRoot = true) => {
134
131
  const result = {};
@@ -150,7 +147,7 @@ var getProxyFormState = (formState, _proxyFormState, localProxyFormState, isRoot
150
147
  var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
151
148
 
152
149
  var shouldRenderFormState = (formStateData, _proxyFormState, isRoot) => {
153
- const formState = omit(formStateData, 'name');
150
+ const { name, ...formState } = formStateData;
154
151
  return (isEmptyObject(formState) ||
155
152
  Object.keys(formState).length >= Object.keys(_proxyFormState).length ||
156
153
  Object.keys(formState).find((key) => _proxyFormState[key] ===
@@ -233,14 +230,20 @@ function useFormState(props) {
233
230
  const callback = React.useCallback((value) => _mounted.current &&
234
231
  shouldSubscribeByName(_name.current, value.name, exact) &&
235
232
  shouldRenderFormState(value, _localProxyFormState.current) &&
236
- updateFormState(Object.assign(Object.assign({}, control._formState), value)), [control, exact]);
233
+ updateFormState({
234
+ ...control._formState,
235
+ ...value,
236
+ }), [control, exact]);
237
237
  useSubscribe({
238
238
  disabled,
239
239
  callback,
240
240
  subject: control._subjects.state,
241
241
  });
242
- React.useEffect(() => () => {
243
- _mounted.current = false;
242
+ React.useEffect(() => {
243
+ _mounted.current = true;
244
+ return () => {
245
+ _mounted.current = false;
246
+ };
244
247
  }, []);
245
248
  return getProxyFormState(formState, control._proxyFormState, _localProxyFormState.current, false);
246
249
  }
@@ -281,11 +284,8 @@ var objectHasFunction = (data) => {
281
284
  *
282
285
  * @example
283
286
  * ```tsx
284
- * const { watch } = useForm();
285
- * const values = useWatch({
286
- * name: "fieldName"
287
- * control,
288
- * })
287
+ * // can skip passing down the control into useWatch if the form is wrapped with the FormProvider
288
+ * const values = useWatch()
289
289
  * ```
290
290
  */
291
291
  function useWatch(props) {
@@ -298,11 +298,12 @@ function useWatch(props) {
298
298
  const fieldValues = generateWatchOutput(_name.current, control._names, formState.values || control._formValues);
299
299
  updateValue(isUndefined(_name.current) ||
300
300
  (isObject(fieldValues) && !objectHasFunction(fieldValues))
301
- ? Object.assign({}, fieldValues) : Array.isArray(fieldValues)
302
- ? [...fieldValues]
303
- : isUndefined(fieldValues)
304
- ? defaultValue
305
- : fieldValues);
301
+ ? { ...fieldValues }
302
+ : Array.isArray(fieldValues)
303
+ ? [...fieldValues]
304
+ : isUndefined(fieldValues)
305
+ ? defaultValue
306
+ : fieldValues);
306
307
  }
307
308
  }, [control, exact, defaultValue]);
308
309
  useSubscribe({
@@ -357,7 +358,10 @@ function useController(props) {
357
358
  control,
358
359
  name,
359
360
  });
360
- const _registerProps = React.useRef(control.register(name, Object.assign(Object.assign({}, props.rules), { value })));
361
+ const _registerProps = React.useRef(control.register(name, {
362
+ ...props.rules,
363
+ value: value,
364
+ }));
361
365
  React.useEffect(() => {
362
366
  const updateMounted = (name, value) => {
363
367
  const field = get(control._fields, name);
@@ -377,7 +381,7 @@ function useController(props) {
377
381
  }, [name, control, isArrayField, shouldUnregister]);
378
382
  return {
379
383
  field: {
380
- name,
384
+ name: name,
381
385
  value,
382
386
  onChange: React.useCallback((event) => {
383
387
  _registerProps.current.onChange({
@@ -458,7 +462,45 @@ function useController(props) {
458
462
  const Controller = (props) => props.render(useController(props));
459
463
 
460
464
  var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
461
- ? Object.assign(Object.assign({}, errors[name]), { types: Object.assign(Object.assign({}, (errors[name] && errors[name].types ? errors[name].types : {})), { [type]: message || true }) }) : {};
465
+ ? {
466
+ ...errors[name],
467
+ types: {
468
+ ...(errors[name] && errors[name].types ? errors[name].types : {}),
469
+ [type]: message || true,
470
+ },
471
+ }
472
+ : {};
473
+
474
+ /**
475
+ * Function for joining two paths / path strings to a {@link TypedFieldPath}.
476
+ * @param path - base path
477
+ * @param childPath - the path which should be appended to the base path
478
+ * @example
479
+ * ```
480
+ * type Baz = { baz: string }
481
+ * type FooBarBaz = { foo: { bar: Baz }}
482
+ *
483
+ * const path: TypedFieldPath<FooBarBaz, Baz> = of('foo.bar')
484
+ * const joinedPath: TypedFieldPath<FooBar, string> = join(path, 'baz')
485
+ * ```
486
+ */
487
+ function join(path, childPath) {
488
+ return `${path}.${childPath}`;
489
+ }
490
+
491
+ /**
492
+ * Function for creating a {@link TypedFieldPath} from a path string.
493
+ * @param path - path string
494
+ * @example
495
+ * ```
496
+ * type FooBar = { foo: { bar: string }}
497
+ *
498
+ * const path: TypedFieldPath<FooBar, string> = of('foo.bar')
499
+ * ```
500
+ */
501
+ function of(path) {
502
+ return path;
503
+ }
462
504
 
463
505
  var isKey = (value) => /^\w*$/.test(value);
464
506
 
@@ -491,8 +533,7 @@ const focusFieldBy = (fields, callback, fieldsNames) => {
491
533
  for (const key of fieldsNames || Object.keys(fields)) {
492
534
  const field = get(fields, key);
493
535
  if (field) {
494
- const _f = field._f;
495
- const current = omit(field, '_f');
536
+ const { _f, ...currentField } = field;
496
537
  if (_f && callback(_f.name)) {
497
538
  if (_f.ref.focus && isUndefined(_f.ref.focus())) {
498
539
  break;
@@ -502,8 +543,8 @@ const focusFieldBy = (fields, callback, fieldsNames) => {
502
543
  break;
503
544
  }
504
545
  }
505
- else if (isObject(current)) {
506
- focusFieldBy(current, callback);
546
+ else if (isObject(currentField)) {
547
+ focusFieldBy(currentField, callback);
507
548
  }
508
549
  }
509
550
  }
@@ -643,7 +684,7 @@ var updateAt = (fieldValues, index, value) => {
643
684
  */
644
685
  function useFieldArray(props) {
645
686
  const methods = useFormContext();
646
- const { control = methods.control, name, keyName = 'id', shouldUnregister, } = props;
687
+ const { control = methods.control, name, shouldUnregister } = props;
647
688
  const [fields, setFields] = React.useState(control._getFieldArray(name));
648
689
  const ids = React.useRef(control._getFieldArray(name).map(generateId));
649
690
  const _fieldIds = React.useRef(fields);
@@ -734,7 +775,7 @@ function useFieldArray(props) {
734
775
  };
735
776
  const update = (index, value) => {
736
777
  const updateValue = cloneObject(value);
737
- const updatedFieldArrayValues = updateAt(control._getFieldArray(name), index, updateValue);
778
+ const updatedFieldArrayValues = updateAt(control._getFieldArray(name), index, value);
738
779
  ids.current = [...updatedFieldArrayValues].map((item, i) => !item || i === index ? generateId() : ids.current[i]);
739
780
  updateValues(updatedFieldArrayValues);
740
781
  setFields([...updatedFieldArrayValues]);
@@ -779,7 +820,7 @@ function useFieldArray(props) {
779
820
  (control._options.shouldUnregister || shouldUnregister) &&
780
821
  control.unregister(name);
781
822
  };
782
- }, [name, control, keyName, shouldUnregister]);
823
+ }, [name, control, shouldUnregister]);
783
824
  return {
784
825
  swap: React.useCallback(swap, [updateValues, name, control]),
785
826
  move: React.useCallback(move, [updateValues, name, control]),
@@ -789,7 +830,10 @@ function useFieldArray(props) {
789
830
  insert: React.useCallback(insert$1, [updateValues, name, control]),
790
831
  update: React.useCallback(update, [updateValues, name, control]),
791
832
  replace: React.useCallback(replace, [updateValues, name, control]),
792
- fields: React.useMemo(() => fields.map((field, index) => (Object.assign(Object.assign({}, field), { [keyName]: ids.current[index] || generateId() }))), [fields, keyName]),
833
+ fields: React.useMemo(() => fields.map((field, index) => ({
834
+ ...field,
835
+ id: ids.current[index] || generateId(),
836
+ })), [fields]),
793
837
  };
794
838
  }
795
839
 
@@ -945,7 +989,7 @@ function getDirtyFieldsFromDefaultValues(data, formValues, dirtyFieldsFromValues
945
989
  isPrimitive(dirtyFieldsFromValues[key])) {
946
990
  dirtyFieldsFromValues[key] = Array.isArray(data[key])
947
991
  ? markFieldsDirty(data[key], [])
948
- : Object.assign({}, markFieldsDirty(data[key]));
992
+ : { ...markFieldsDirty(data[key]) };
949
993
  }
950
994
  else {
951
995
  getDirtyFieldsFromDefaultValues(data[key], isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
@@ -1155,8 +1199,12 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
1155
1199
  const appendErrorsCurry = appendErrors.bind(null, name, validateAllFieldCriteria, error);
1156
1200
  const getMinMaxMessage = (exceedMax, maxLengthMessage, minLengthMessage, maxType = INPUT_VALIDATION_RULES.maxLength, minType = INPUT_VALIDATION_RULES.minLength) => {
1157
1201
  const message = exceedMax ? maxLengthMessage : minLengthMessage;
1158
- error[name] = Object.assign({ type: exceedMax ? maxType : minType, message,
1159
- ref }, appendErrorsCurry(exceedMax ? maxType : minType, message));
1202
+ error[name] = {
1203
+ type: exceedMax ? maxType : minType,
1204
+ message,
1205
+ ref,
1206
+ ...appendErrorsCurry(exceedMax ? maxType : minType, message),
1207
+ };
1160
1208
  };
1161
1209
  if (required &&
1162
1210
  ((!isRadioOrCheckbox && (isEmpty || isNullOrUndefined(inputValue))) ||
@@ -1167,7 +1215,12 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
1167
1215
  ? { value: !!required, message: required }
1168
1216
  : getValueAndMessage(required);
1169
1217
  if (value) {
1170
- error[name] = Object.assign({ type: INPUT_VALIDATION_RULES.required, message, ref: inputRef }, appendErrorsCurry(INPUT_VALIDATION_RULES.required, message));
1218
+ error[name] = {
1219
+ type: INPUT_VALIDATION_RULES.required,
1220
+ message,
1221
+ ref: inputRef,
1222
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.required, message),
1223
+ };
1171
1224
  if (!validateAllFieldCriteria) {
1172
1225
  setCustomValidity(message);
1173
1226
  return error;
@@ -1223,8 +1276,12 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
1223
1276
  if (pattern && !isEmpty && isString(inputValue)) {
1224
1277
  const { value: patternValue, message } = getValueAndMessage(pattern);
1225
1278
  if (isRegex(patternValue) && !inputValue.match(patternValue)) {
1226
- error[name] = Object.assign({ type: INPUT_VALIDATION_RULES.pattern, message,
1227
- ref }, appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message));
1279
+ error[name] = {
1280
+ type: INPUT_VALIDATION_RULES.pattern,
1281
+ message,
1282
+ ref,
1283
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.pattern, message),
1284
+ };
1228
1285
  if (!validateAllFieldCriteria) {
1229
1286
  setCustomValidity(message);
1230
1287
  return error;
@@ -1236,7 +1293,10 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
1236
1293
  const result = await validate(inputValue);
1237
1294
  const validateError = getValidateError(result, inputRef);
1238
1295
  if (validateError) {
1239
- error[name] = Object.assign(Object.assign({}, validateError), appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message));
1296
+ error[name] = {
1297
+ ...validateError,
1298
+ ...appendErrorsCurry(INPUT_VALIDATION_RULES.validate, validateError.message),
1299
+ };
1240
1300
  if (!validateAllFieldCriteria) {
1241
1301
  setCustomValidity(validateError.message);
1242
1302
  return error;
@@ -1251,7 +1311,10 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
1251
1311
  }
1252
1312
  const validateError = getValidateError(await validate[key](inputValue), inputRef, key);
1253
1313
  if (validateError) {
1254
- validationResult = Object.assign(Object.assign({}, validateError), appendErrorsCurry(key, validateError.message));
1314
+ validationResult = {
1315
+ ...validateError,
1316
+ ...appendErrorsCurry(key, validateError.message),
1317
+ };
1255
1318
  setCustomValidity(validateError.message);
1256
1319
  if (validateAllFieldCriteria) {
1257
1320
  error[name] = validationResult;
@@ -1259,7 +1322,10 @@ var validateField = async (field, inputValue, validateAllFieldCriteria, shouldUs
1259
1322
  }
1260
1323
  }
1261
1324
  if (!isEmptyObject(validationResult)) {
1262
- error[name] = Object.assign({ ref: inputRef }, validationResult);
1325
+ error[name] = {
1326
+ ref: inputRef,
1327
+ ...validationResult,
1328
+ };
1263
1329
  if (!validateAllFieldCriteria) {
1264
1330
  return error;
1265
1331
  }
@@ -1276,7 +1342,10 @@ const defaultOptions = {
1276
1342
  shouldFocusError: true,
1277
1343
  };
1278
1344
  function createFormControl(props = {}) {
1279
- let _options = Object.assign(Object.assign({}, defaultOptions), props);
1345
+ let _options = {
1346
+ ...defaultOptions,
1347
+ ...props,
1348
+ };
1280
1349
  let _formState = {
1281
1350
  isDirty: false,
1282
1351
  isValidating: false,
@@ -1290,7 +1359,7 @@ function createFormControl(props = {}) {
1290
1359
  errors: {},
1291
1360
  };
1292
1361
  let _fields = {};
1293
- let _defaultValues = _options.defaultValues || {};
1362
+ let _defaultValues = cloneObject(_options.defaultValues) || {};
1294
1363
  let _formValues = _options.shouldUnregister
1295
1364
  ? {}
1296
1365
  : cloneObject(_defaultValues);
@@ -1444,8 +1513,16 @@ function createFormControl(props = {}) {
1444
1513
  !isEmptyObject(fieldState) ||
1445
1514
  shouldUpdateValid) &&
1446
1515
  !shouldSkipRender) {
1447
- const updatedFormState = Object.assign(Object.assign(Object.assign({}, fieldState), (shouldUpdateValid ? { isValid } : {})), { errors: _formState.errors, name });
1448
- _formState = Object.assign(Object.assign({}, _formState), updatedFormState);
1516
+ const updatedFormState = {
1517
+ ...fieldState,
1518
+ ...(shouldUpdateValid ? { isValid } : {}),
1519
+ errors: _formState.errors,
1520
+ name,
1521
+ };
1522
+ _formState = {
1523
+ ..._formState,
1524
+ ...updatedFormState,
1525
+ };
1449
1526
  _subjects.state.next(updatedFormState);
1450
1527
  }
1451
1528
  validateFields[name]--;
@@ -1458,7 +1535,7 @@ function createFormControl(props = {}) {
1458
1535
  }
1459
1536
  };
1460
1537
  const _executeSchema = async (name) => _options.resolver
1461
- ? await _options.resolver(Object.assign({}, _formValues), _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation))
1538
+ ? await _options.resolver({ ..._formValues }, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation))
1462
1539
  : {};
1463
1540
  const executeSchemaAndUpdateState = async (names) => {
1464
1541
  const { errors } = await _executeSchema();
@@ -1481,8 +1558,7 @@ function createFormControl(props = {}) {
1481
1558
  for (const name in fields) {
1482
1559
  const field = fields[name];
1483
1560
  if (field) {
1484
- const fieldReference = field._f;
1485
- const fieldValue = omit(field, '_f');
1561
+ const { _f: fieldReference, ...fieldValue } = field;
1486
1562
  if (fieldReference) {
1487
1563
  const fieldError = await validateField(field, get(_formValues, fieldReference.name), shouldDisplayAllAssociatedErrors, _options.shouldUseNativeValidation);
1488
1564
  if (fieldError[fieldReference.name]) {
@@ -1517,13 +1593,15 @@ function createFormControl(props = {}) {
1517
1593
  const _getDirty = (name, data) => (name && data && set(_formValues, name, data),
1518
1594
  !deepEqual(getValues(), _defaultValues));
1519
1595
  const _getWatch = (names, defaultValue, isGlobal) => {
1520
- const fieldValues = Object.assign({}, (_stateFlags.mount
1521
- ? _formValues
1522
- : isUndefined(defaultValue)
1523
- ? _defaultValues
1524
- : isString(names)
1525
- ? { [names]: defaultValue }
1526
- : defaultValue));
1596
+ const fieldValues = {
1597
+ ...(_stateFlags.mount
1598
+ ? _formValues
1599
+ : isUndefined(defaultValue)
1600
+ ? _defaultValues
1601
+ : isString(names)
1602
+ ? { [names]: defaultValue }
1603
+ : defaultValue),
1604
+ };
1527
1605
  return generateWatchOutput(names, _names, fieldValues, isGlobal);
1528
1606
  };
1529
1607
  const _getFieldArray = (name) => compact(get(_stateFlags.mount ? _formValues : _defaultValues, name, props.shouldUnregister ? get(_defaultValues, name, []) : []));
@@ -1649,7 +1727,7 @@ function createFormControl(props = {}) {
1649
1727
  });
1650
1728
  if (shouldSkipValidation) {
1651
1729
  return (shouldRender &&
1652
- _subjects.state.next(Object.assign({ name }, (watched ? {} : fieldState))));
1730
+ _subjects.state.next({ name, ...(watched ? {} : fieldState) }));
1653
1731
  }
1654
1732
  !isBlurEvent && watched && _subjects.state.next({});
1655
1733
  validateFields[name] = validateFields[name] ? +1 : 1;
@@ -1697,17 +1775,25 @@ function createFormControl(props = {}) {
1697
1775
  else {
1698
1776
  validationResult = isValid = await executeBuildInValidation(_fields);
1699
1777
  }
1700
- _subjects.state.next(Object.assign(Object.assign(Object.assign({}, (!isString(name) ||
1701
- (_proxyFormState.isValid && isValid !== _formState.isValid)
1702
- ? {}
1703
- : { name })), (_options.resolver ? { isValid } : {})), { errors: _formState.errors, isValidating: false }));
1778
+ _subjects.state.next({
1779
+ ...(!isString(name) ||
1780
+ (_proxyFormState.isValid && isValid !== _formState.isValid)
1781
+ ? {}
1782
+ : { name }),
1783
+ ...(_options.resolver ? { isValid } : {}),
1784
+ errors: _formState.errors,
1785
+ isValidating: false,
1786
+ });
1704
1787
  options.shouldFocus &&
1705
1788
  !validationResult &&
1706
1789
  focusFieldBy(_fields, (key) => get(_formState.errors, key), name ? fieldNames : _names.mount);
1707
1790
  return validationResult;
1708
1791
  };
1709
1792
  const getValues = (fieldNames) => {
1710
- const values = Object.assign(Object.assign({}, _defaultValues), (_stateFlags.mount ? _formValues : {}));
1793
+ const values = {
1794
+ ..._defaultValues,
1795
+ ...(_stateFlags.mount ? _formValues : {}),
1796
+ };
1711
1797
  return isUndefined(fieldNames)
1712
1798
  ? values
1713
1799
  : isString(fieldNames)
@@ -1730,7 +1816,10 @@ function createFormControl(props = {}) {
1730
1816
  };
1731
1817
  const setError = (name, error, options) => {
1732
1818
  const ref = (get(_fields, name, { _f: {} })._f || {}).ref;
1733
- set(_formState.errors, name, Object.assign(Object.assign({}, error), { ref }));
1819
+ set(_formState.errors, name, {
1820
+ ...error,
1821
+ ref,
1822
+ });
1734
1823
  _subjects.state.next({
1735
1824
  name,
1736
1825
  errors: _formState.errors,
@@ -1761,14 +1850,22 @@ function createFormControl(props = {}) {
1761
1850
  }
1762
1851
  }
1763
1852
  _subjects.watch.next({});
1764
- _subjects.state.next(Object.assign(Object.assign({}, _formState), (!options.keepDirty ? {} : { isDirty: _getDirty() })));
1765
- !options.keepIsValid && _updateValid();
1853
+ _subjects.state.next({
1854
+ ..._formState,
1855
+ ...(!options.keepDirty ? {} : { isDirty: _getDirty() }),
1856
+ });
1857
+ _proxyFormState.isValid && _updateValid();
1766
1858
  };
1767
1859
  const register = (name, options = {}) => {
1768
1860
  let field = get(_fields, name);
1769
1861
  const disabledIsDefined = isBoolean(options.disabled);
1770
1862
  set(_fields, name, {
1771
- _f: Object.assign(Object.assign(Object.assign({}, (field && field._f ? field._f : { ref: { name } })), { name, mount: true }), options),
1863
+ _f: {
1864
+ ...(field && field._f ? field._f : { ref: { name } }),
1865
+ name,
1866
+ mount: true,
1867
+ ...options,
1868
+ },
1772
1869
  });
1773
1870
  _names.mount.add(name);
1774
1871
  field
@@ -1777,17 +1874,22 @@ function createFormControl(props = {}) {
1777
1874
  ? undefined
1778
1875
  : get(_formValues, name, getFieldValue(field._f)))
1779
1876
  : updateValidAndValue(name, true, options.value);
1780
- return Object.assign(Object.assign(Object.assign({}, (disabledIsDefined ? { disabled: options.disabled } : {})), (_options.shouldUseNativeValidation
1781
- ? {
1782
- required: !!options.required,
1783
- min: getRuleValue(options.min),
1784
- max: getRuleValue(options.max),
1785
- minLength: getRuleValue(options.minLength),
1786
- maxLength: getRuleValue(options.maxLength),
1787
- pattern: getRuleValue(options.pattern),
1788
- }
1789
- : {})), { name,
1790
- onChange, onBlur: onChange, ref: (ref) => {
1877
+ return {
1878
+ ...(disabledIsDefined ? { disabled: options.disabled } : {}),
1879
+ ...(_options.shouldUseNativeValidation
1880
+ ? {
1881
+ required: !!options.required,
1882
+ min: getRuleValue(options.min),
1883
+ max: getRuleValue(options.max),
1884
+ minLength: getRuleValue(options.minLength),
1885
+ maxLength: getRuleValue(options.maxLength),
1886
+ pattern: getRuleValue(options.pattern),
1887
+ }
1888
+ : {}),
1889
+ name,
1890
+ onChange,
1891
+ onBlur: onChange,
1892
+ ref: (ref) => {
1791
1893
  if (ref) {
1792
1894
  register(name, options);
1793
1895
  field = get(_fields, name);
@@ -1804,12 +1906,15 @@ function createFormControl(props = {}) {
1804
1906
  return;
1805
1907
  }
1806
1908
  set(_fields, name, {
1807
- _f: Object.assign(Object.assign({}, field._f), (radioOrCheckbox
1808
- ? {
1809
- refs: [...refs.filter(live), fieldRef],
1810
- ref: { type: fieldRef.type, name },
1811
- }
1812
- : { ref: fieldRef })),
1909
+ _f: {
1910
+ ...field._f,
1911
+ ...(radioOrCheckbox
1912
+ ? {
1913
+ refs: [...refs.filter(live), fieldRef],
1914
+ ref: { type: fieldRef.type, name },
1915
+ }
1916
+ : { ref: fieldRef }),
1917
+ },
1813
1918
  });
1814
1919
  updateValidAndValue(name, false, undefined, fieldRef);
1815
1920
  }
@@ -1822,7 +1927,8 @@ function createFormControl(props = {}) {
1822
1927
  !(isNameInFieldArray(_names.array, name) && _stateFlags.action) &&
1823
1928
  _names.unMount.add(name);
1824
1929
  }
1825
- } });
1930
+ },
1931
+ };
1826
1932
  };
1827
1933
  const handleSubmit = (onValid, onInvalid) => async (e) => {
1828
1934
  if (e) {
@@ -1853,7 +1959,7 @@ function createFormControl(props = {}) {
1853
1959
  }
1854
1960
  else {
1855
1961
  if (onInvalid) {
1856
- await onInvalid(Object.assign({}, _formState.errors), e);
1962
+ await onInvalid({ ..._formState.errors }, e);
1857
1963
  }
1858
1964
  _options.shouldFocusError &&
1859
1965
  focusFieldBy(_fields, (key) => get(_formState.errors, key), _names.mount);
@@ -1896,7 +2002,7 @@ function createFormControl(props = {}) {
1896
2002
  unset(_formState.errors, name);
1897
2003
  _proxyFormState.isValid && _updateValid();
1898
2004
  }
1899
- _subjects.state.next(Object.assign({}, _formState));
2005
+ _subjects.state.next({ ..._formState });
1900
2006
  }
1901
2007
  };
1902
2008
  const reset = (formValues, keepStateOptions = {}) => {
@@ -1909,22 +2015,6 @@ function createFormControl(props = {}) {
1909
2015
  _defaultValues = updatedValues;
1910
2016
  }
1911
2017
  if (!keepStateOptions.keepValues) {
1912
- if (isWeb && isUndefined(formValues)) {
1913
- for (const name of _names.mount) {
1914
- const field = get(_fields, name);
1915
- if (field && field._f) {
1916
- const fieldReference = Array.isArray(field._f.refs)
1917
- ? field._f.refs[0]
1918
- : field._f.ref;
1919
- try {
1920
- isHTMLElement(fieldReference) &&
1921
- fieldReference.closest('form').reset();
1922
- break;
1923
- }
1924
- catch (_a) { }
1925
- }
1926
- }
1927
- }
1928
2018
  _formValues = props.shouldUnregister
1929
2019
  ? keepStateOptions.keepDefaultValues
1930
2020
  ? cloneObject(_defaultValues)
@@ -1946,8 +2036,7 @@ function createFormControl(props = {}) {
1946
2036
  watchAll: false,
1947
2037
  focus: '',
1948
2038
  };
1949
- _stateFlags.mount =
1950
- !_proxyFormState.isValid || !!keepStateOptions.keepIsValid;
2039
+ _stateFlags.mount = !_proxyFormState.isValid;
1951
2040
  _stateFlags.watch = !!props.shouldUnregister;
1952
2041
  _subjects.state.next({
1953
2042
  submitCount: keepStateOptions.keepSubmitCount
@@ -1964,7 +2053,10 @@ function createFormControl(props = {}) {
1964
2053
  dirtyFields: keepStateOptions.keepDirty
1965
2054
  ? _formState.dirtyFields
1966
2055
  : (keepStateOptions.keepDefaultValues && formValues
1967
- ? Object.entries(formValues).reduce((previous, [key, value]) => (Object.assign(Object.assign({}, previous), { [key]: value !== get(_defaultValues, key) })), {})
2056
+ ? Object.entries(formValues).reduce((previous, [key, value]) => ({
2057
+ ...previous,
2058
+ [key]: value !== get(_defaultValues, key),
2059
+ }), {})
1968
2060
  : {}),
1969
2061
  touchedFields: keepStateOptions.keepTouched
1970
2062
  ? _formState.touchedFields
@@ -2026,7 +2118,10 @@ function createFormControl(props = {}) {
2026
2118
  return _options;
2027
2119
  },
2028
2120
  set _options(value) {
2029
- _options = Object.assign(Object.assign({}, _options), value);
2121
+ _options = {
2122
+ ..._options,
2123
+ ...value,
2124
+ };
2030
2125
  },
2031
2126
  },
2032
2127
  trigger,
@@ -2092,13 +2187,19 @@ function useForm(props = {}) {
2092
2187
  _formControl.current.control._options = props;
2093
2188
  }
2094
2189
  else {
2095
- _formControl.current = Object.assign(Object.assign({}, createFormControl(props)), { formState });
2190
+ _formControl.current = {
2191
+ ...createFormControl(props),
2192
+ formState,
2193
+ };
2096
2194
  }
2097
2195
  const control = _formControl.current.control;
2098
2196
  const callback = React.useCallback((value) => {
2099
2197
  if (shouldRenderFormState(value, control._proxyFormState, true)) {
2100
- control._formState = Object.assign(Object.assign({}, control._formState), value);
2101
- updateFormState(Object.assign({}, control._formState));
2198
+ control._formState = {
2199
+ ...control._formState,
2200
+ ...value,
2201
+ };
2202
+ updateFormState({ ...control._formState });
2102
2203
  }
2103
2204
  }, [control]);
2104
2205
  useSubscribe({
@@ -2120,5 +2221,5 @@ function useForm(props = {}) {
2120
2221
  return _formControl.current;
2121
2222
  }
2122
2223
 
2123
- export { Controller, FormProvider, appendErrors, get, set, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
2224
+ export { Controller, FormProvider, appendErrors, get, join, of, set, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch };
2124
2225
  //# sourceMappingURL=index.esm.mjs.map