@depup/react-hook-form 7.83.0-depup.0 → 7.84.0-depup.0

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.
@@ -0,0 +1,3 @@
1
+ import type { FieldValues } from '../types';
2
+ export default function collectDirtyFieldNames(dirtyTree: FieldValues, cachedDirtyFields: FieldValues, prefix?: string, names?: string[]): string[];
3
+ //# sourceMappingURL=collectDirtyFieldNames.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collectDirtyFieldNames.d.ts","sourceRoot":"","sources":["../../src/logic/collectDirtyFieldNames.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAQ5C,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,SAAS,EAAE,WAAW,EACtB,iBAAiB,EAAE,WAAW,EAC9B,MAAM,SAAK,EACX,KAAK,GAAE,MAAM,EAAO,YAiBrB"}
@@ -1 +1 @@
1
- {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAcV,WAAW,EAkBX,YAAY,EAKZ,aAAa,EAYd,MAAM,UAAU,CAAC;AAuElB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;CAY9B,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAM,GACnE,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,CAAC;CACH,CAo3DA"}
1
+ {"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAcV,WAAW,EAkBX,YAAY,EAKZ,aAAa,EAYd,MAAM,UAAU,CAAC;AAwElB,eAAO,MAAM,kBAAkB;;;;;;;;;;;;CAY9B,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C,QAAQ,GAAG,GAAG,EACd,kBAAkB,GAAG,YAAY,EAEjC,KAAK,GAAE,YAAY,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAM,GACnE,IAAI,CACL,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,GAAG;IACF,WAAW,EAAE,IAAI,CACf,aAAa,CAAC,YAAY,EAAE,QAAQ,EAAE,kBAAkB,CAAC,EACzD,WAAW,CACZ,CAAC;CACH,CA83DA"}
@@ -1 +1 @@
1
- {"version":3,"file":"getFieldValue.d.ts","sourceRoot":"","sources":["../../src/logic/getFieldValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAWtC,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,OAoBpD"}
1
+ {"version":3,"file":"getFieldValue.d.ts","sourceRoot":"","sources":["../../src/logic/getFieldValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAUtC,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,EAAE,KAAK,CAAC,IAAI,CAAC,OAoBpD"}
@@ -1 +1 @@
1
- {"version":3,"file":"iterateFieldsByAction.d.ts","sourceRoot":"","sources":["../../src/logic/iterateFieldsByAction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAIlE,QAAA,MAAM,qBAAqB,GACzB,QAAQ,SAAS,EACjB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,GAAG,IAAI,EACxD,cAAc,GAAG,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,EAAE,GAAG,CAAC,EAC9D,aAAa,OAAO,qBA0BrB,CAAC;AACF,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"iterateFieldsByAction.d.ts","sourceRoot":"","sources":["../../src/logic/iterateFieldsByAction.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,iBAAiB,EAAE,GAAG,EAAE,MAAM,UAAU,CAAC;AAIlE,QAAA,MAAM,qBAAqB,GACzB,QAAQ,SAAS,EACjB,QAAQ,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,KAAK,CAAC,GAAG,SAAS,GAAG,IAAI,EACxD,cAAc,GAAG,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,EAAE,GAAG,CAAC,EAC9D,aAAa,OAAO,qBA8BrB,CAAC;AACF,eAAe,qBAAqB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"shouldRenderFormState.d.ts","sourceRoot":"","sources":["../../src/logic/shouldRenderFormState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,aAAa,EACd,MAAM,UAAU,CAAC;yBAEF,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,aAAa,EAC5D,eAAe,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG;IACrC,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,MAAM,CAAC,EAAE,CAAC,CAAC;CACZ,EACD,iBAAiB,CAAC,EAClB,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAC3D,SAAS,OAAO;AAPlB,wBAsBE"}
1
+ {"version":3,"file":"shouldRenderFormState.d.ts","sourceRoot":"","sources":["../../src/logic/shouldRenderFormState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,SAAS,EACT,iBAAiB,EACjB,aAAa,EACd,MAAM,UAAU,CAAC;yBAEF,CAAC,SAAS,WAAW,EAAE,CAAC,SAAS,aAAa,EAC5D,eAAe,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG;IACrC,IAAI,CAAC,EAAE,iBAAiB,CAAC;IACzB,MAAM,CAAC,EAAE,CAAC,CAAC;CACZ,EACD,iBAAiB,CAAC,EAClB,iBAAiB,CAAC,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,EAC3D,SAAS,OAAO;AAPlB,wBAqBE"}
@@ -281,7 +281,7 @@ var set = (object, path, value) => {
281
281
  };
282
282
 
283
283
  function baseGet(object, updatePath) {
284
- const length = updatePath.slice(0, -1).length;
284
+ const length = updatePath.length - 1;
285
285
  let index = 0;
286
286
  while (index < length) {
287
287
  if (isNullOrUndefined(object)) {
@@ -328,6 +328,24 @@ function unset(object, path) {
328
328
  return object;
329
329
  }
330
330
 
331
+ function isDirtyContainer(value) {
332
+ return Array.isArray(value) || isObject(value);
333
+ }
334
+ function collectDirtyFieldNames(dirtyTree, cachedDirtyFields, prefix = '', names = []) {
335
+ for (const key in dirtyTree) {
336
+ const path = prefix ? `${prefix}.${key}` : key;
337
+ const value = dirtyTree[key];
338
+ if (isDirtyContainer(value) &&
339
+ isDirtyContainer(get(cachedDirtyFields, path))) {
340
+ collectDirtyFieldNames(value, cachedDirtyFields, path, names);
341
+ }
342
+ else {
343
+ names.push(path);
344
+ }
345
+ }
346
+ return names;
347
+ }
348
+
331
349
  var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
332
350
  if (isString(names)) {
333
351
  isGlobal && _names.watch.add(names);
@@ -490,7 +508,7 @@ function getFieldValue(_f) {
490
508
  if (isCheckBoxInput(ref)) {
491
509
  return getCheckboxValue(_f.refs).value;
492
510
  }
493
- return getFieldValueAs(isUndefined(ref.value) ? _f.ref.value : ref.value, _f);
511
+ return getFieldValueAs(ref.value, _f);
494
512
  }
495
513
 
496
514
  var getResolverOptions = (fieldsNames, _fields, criteriaMode, shouldUseNativeValidation) => {
@@ -572,9 +590,12 @@ var isWatched = (name, _names, isBlurEvent) => {
572
590
 
573
591
  const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
574
592
  for (const key of fieldsNames || Object.keys(fields)) {
575
- const field = get(fields, key);
593
+ if (key === '_f') {
594
+ continue;
595
+ }
596
+ const field = fieldsNames ? get(fields, key) : fields[key];
576
597
  if (field) {
577
- const { _f, ...currentField } = field;
598
+ const { _f } = field;
578
599
  if (_f) {
579
600
  if (_f.refs && _f.refs[0] && action(_f.refs[0], key) && !abortEarly) {
580
601
  return true;
@@ -583,13 +604,13 @@ const iterateFieldsByAction = (fields, action, fieldsNames, abortEarly) => {
583
604
  return true;
584
605
  }
585
606
  else {
586
- if (iterateFieldsByAction(currentField, action)) {
607
+ if (iterateFieldsByAction(field, action)) {
587
608
  break;
588
609
  }
589
610
  }
590
611
  }
591
- else if (isObject(currentField)) {
592
- if (iterateFieldsByAction(currentField, action)) {
612
+ else if (isObject(field) || Array.isArray(field)) {
613
+ if (iterateFieldsByAction(field, action)) {
593
614
  break;
594
615
  }
595
616
  }
@@ -635,8 +656,7 @@ function schemaErrorLookup(errors, _fields, name) {
635
656
 
636
657
  var shouldRenderFormState = (formStateData, _proxyFormState, updateFormState, isRoot) => {
637
658
  updateFormState(formStateData);
638
- const { name, ...formState } = formStateData;
639
- const keys = Object.keys(formState);
659
+ const keys = Object.keys(formStateData).filter((key) => key !== 'name');
640
660
  return (!keys.length ||
641
661
  (isRoot && keys.length >= Object.keys(_proxyFormState).length) ||
642
662
  keys.find((key) => _proxyFormState[key] ===
@@ -1399,6 +1419,12 @@ function createFormControl(props = {}) {
1399
1419
  });
1400
1420
  };
1401
1421
  const setFieldValues = (name, value, options, skipClone = false, skipRender = false) => {
1422
+ if (_names.array.has(name)) {
1423
+ _subjects.array.next({
1424
+ name,
1425
+ values: skipClone ? _formValues : cloneObject(_formValues),
1426
+ });
1427
+ }
1402
1428
  for (const fieldKey in value) {
1403
1429
  if (!value.hasOwnProperty(fieldKey)) {
1404
1430
  return;
@@ -1934,6 +1960,7 @@ function createFormControl(props = {}) {
1934
1960
  }
1935
1961
  };
1936
1962
  const handleSubmit = (onValid, onInvalid) => async (e) => {
1963
+ let result = undefined;
1937
1964
  let onValidError = undefined;
1938
1965
  if (e) {
1939
1966
  e.preventDefault && e.preventDefault();
@@ -1967,7 +1994,7 @@ function createFormControl(props = {}) {
1967
1994
  errors: {},
1968
1995
  });
1969
1996
  try {
1970
- await onValid(fieldValues, e);
1997
+ result = await onValid(fieldValues, e);
1971
1998
  }
1972
1999
  catch (error) {
1973
2000
  onValidError = error;
@@ -1990,6 +2017,7 @@ function createFormControl(props = {}) {
1990
2017
  if (onValidError) {
1991
2018
  throw onValidError;
1992
2019
  }
2020
+ return result;
1993
2021
  };
1994
2022
  const resetField = (name, options = {}) => {
1995
2023
  if (get(_fields, name)) {
@@ -2029,7 +2057,7 @@ function createFormControl(props = {}) {
2029
2057
  if (keepStateOptions.keepDirtyValues) {
2030
2058
  const fieldsToCheck = new Set([
2031
2059
  ..._names.mount,
2032
- ...Object.keys(getDirtyFields(_defaultValues, _formValues, undefined, fieldRefs)),
2060
+ ...collectDirtyFieldNames(getDirtyFields(_defaultValues, _formValues, undefined, fieldRefs), _formState.dirtyFields),
2033
2061
  ]);
2034
2062
  for (const fieldName of Array.from(fieldsToCheck)) {
2035
2063
  const isDirty = get(_formState.dirtyFields, fieldName);