react-hook-form 7.72.1 → 7.73.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.
- package/README.md +3 -19
- package/dist/__tests__/nested-null.test.d.ts +2 -0
- package/dist/__tests__/nested-null.test.d.ts.map +1 -0
- package/dist/form.d.ts.map +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +66 -39
- package/dist/index.esm.mjs.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/logic/createFormControl.d.ts.map +1 -1
- package/dist/react-server.esm.mjs +46 -30
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/useFieldArray.d.ts.map +1 -1
- package/dist/utils/deepEqual.d.ts +1 -1
- package/dist/utils/deepEqual.d.ts.map +1 -1
- package/dist/utils/unset.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAaV,WAAW,EAiBX,YAAY,EAIZ,aAAa,EAWd,MAAM,UAAU,CAAC;AAsDlB,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,
|
|
1
|
+
{"version":3,"file":"createFormControl.d.ts","sourceRoot":"","sources":["../../src/logic/createFormControl.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAaV,WAAW,EAiBX,YAAY,EAIZ,aAAa,EAWd,MAAM,UAAU,CAAC;AAsDlB,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,CAwmDA"}
|
|
@@ -108,7 +108,10 @@ var createSubject = () => {
|
|
|
108
108
|
|
|
109
109
|
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
110
110
|
|
|
111
|
-
function deepEqual(object1, object2,
|
|
111
|
+
function deepEqual(object1, object2, visited = new WeakSet()) {
|
|
112
|
+
if (object1 === object2) {
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
112
115
|
if (isPrimitive(object1) || isPrimitive(object2)) {
|
|
113
116
|
return Object.is(object1, object2);
|
|
114
117
|
}
|
|
@@ -120,14 +123,14 @@ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
|
120
123
|
if (keys1.length !== keys2.length) {
|
|
121
124
|
return false;
|
|
122
125
|
}
|
|
123
|
-
if (
|
|
126
|
+
if (visited.has(object1) || visited.has(object2)) {
|
|
124
127
|
return true;
|
|
125
128
|
}
|
|
126
|
-
|
|
127
|
-
|
|
129
|
+
visited.add(object1);
|
|
130
|
+
visited.add(object2);
|
|
128
131
|
for (const key of keys1) {
|
|
129
132
|
const val1 = object1[key];
|
|
130
|
-
if (!
|
|
133
|
+
if (!(key in object2)) {
|
|
131
134
|
return false;
|
|
132
135
|
}
|
|
133
136
|
if (key !== 'ref') {
|
|
@@ -135,7 +138,7 @@ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
|
135
138
|
if ((isDateObject(val1) && isDateObject(val2)) ||
|
|
136
139
|
((isObject(val1) || Array.isArray(val1)) &&
|
|
137
140
|
(isObject(val2) || Array.isArray(val2)))
|
|
138
|
-
? !deepEqual(val1, val2,
|
|
141
|
+
? !deepEqual(val1, val2, visited)
|
|
139
142
|
: !Object.is(val1, val2)) {
|
|
140
143
|
return false;
|
|
141
144
|
}
|
|
@@ -174,7 +177,10 @@ var get = (object, path, defaultValue) => {
|
|
|
174
177
|
if (!path || !isObject(object)) {
|
|
175
178
|
return defaultValue;
|
|
176
179
|
}
|
|
177
|
-
const
|
|
180
|
+
const paths = isKey(path) ? [path] : stringToPath(path);
|
|
181
|
+
const result = paths.reduce((result, key) => {
|
|
182
|
+
return isNullOrUndefined(result) ? undefined : result[key];
|
|
183
|
+
}, object);
|
|
178
184
|
return isUndefined(result) || result === object
|
|
179
185
|
? isUndefined(object[path])
|
|
180
186
|
? defaultValue
|
|
@@ -253,6 +259,10 @@ function isEmptyArray(obj) {
|
|
|
253
259
|
return true;
|
|
254
260
|
}
|
|
255
261
|
function unset(object, path) {
|
|
262
|
+
if (isString(path) && Object.prototype.hasOwnProperty.call(object, path)) {
|
|
263
|
+
delete object[path];
|
|
264
|
+
return object;
|
|
265
|
+
}
|
|
256
266
|
const paths = Array.isArray(path)
|
|
257
267
|
? path
|
|
258
268
|
: isKey(path)
|
|
@@ -1237,17 +1247,15 @@ function createFormControl(props = {}) {
|
|
|
1237
1247
|
const field = get(_fields, name);
|
|
1238
1248
|
const isFieldArray = _names.array.has(name);
|
|
1239
1249
|
const cloneValue = cloneObject(value);
|
|
1250
|
+
const previousValue = get(_formValues, name);
|
|
1251
|
+
const isValueUnchanged = deepEqual(previousValue, cloneValue);
|
|
1240
1252
|
set(_formValues, name, cloneValue);
|
|
1241
1253
|
if (isFieldArray) {
|
|
1242
1254
|
_subjects.array.next({
|
|
1243
1255
|
name,
|
|
1244
1256
|
values: cloneObject(_formValues),
|
|
1245
1257
|
});
|
|
1246
|
-
if (
|
|
1247
|
-
_proxyFormState.dirtyFields ||
|
|
1248
|
-
_proxySubscribeFormState.isDirty ||
|
|
1249
|
-
_proxySubscribeFormState.dirtyFields) &&
|
|
1250
|
-
options.shouldDirty) {
|
|
1258
|
+
if (options.shouldDirty) {
|
|
1251
1259
|
_updateDirtyFields(name);
|
|
1252
1260
|
_subjects.state.next({
|
|
1253
1261
|
name,
|
|
@@ -1257,22 +1265,29 @@ function createFormControl(props = {}) {
|
|
|
1257
1265
|
}
|
|
1258
1266
|
}
|
|
1259
1267
|
else {
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
values: cloneObject(_formValues),
|
|
1269
|
-
});
|
|
1268
|
+
const isEmpty = (Array.isArray(cloneValue) && !cloneValue.length) ||
|
|
1269
|
+
isEmptyObject(cloneValue);
|
|
1270
|
+
if (!field || field._f || isNullOrUndefined(cloneValue) || isEmpty) {
|
|
1271
|
+
setFieldValue(name, cloneValue, options);
|
|
1272
|
+
}
|
|
1273
|
+
else {
|
|
1274
|
+
setValues(name, cloneValue, options);
|
|
1275
|
+
}
|
|
1270
1276
|
}
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1277
|
+
if (!isValueUnchanged) {
|
|
1278
|
+
if (isWatched(name, _names)) {
|
|
1279
|
+
_subjects.state.next({
|
|
1280
|
+
..._formState,
|
|
1281
|
+
name,
|
|
1282
|
+
values: cloneObject(_formValues),
|
|
1283
|
+
});
|
|
1284
|
+
}
|
|
1285
|
+
else {
|
|
1286
|
+
_subjects.state.next({
|
|
1287
|
+
name: _state.mount ? name : undefined,
|
|
1288
|
+
values: cloneObject(_formValues),
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1276
1291
|
}
|
|
1277
1292
|
};
|
|
1278
1293
|
const onChange = async (event) => {
|
|
@@ -1491,15 +1506,16 @@ function createFormControl(props = {}) {
|
|
|
1491
1506
|
const watch = (name, defaultValue) => isFunction(name)
|
|
1492
1507
|
? _subjects.state.subscribe({
|
|
1493
1508
|
next: (payload) => 'values' in payload &&
|
|
1494
|
-
name(_getWatch(undefined, defaultValue), payload),
|
|
1509
|
+
name(payload.values || _getWatch(undefined, defaultValue), payload),
|
|
1495
1510
|
})
|
|
1496
1511
|
: _getWatch(name, defaultValue, true);
|
|
1497
1512
|
const _subscribe = (props) => _subjects.state.subscribe({
|
|
1498
1513
|
next: (formState) => {
|
|
1499
1514
|
if (shouldSubscribeByName(props.name, formState.name, props.exact) &&
|
|
1500
1515
|
shouldRenderFormState(formState, props.formState || _proxyFormState, _setFormState, props.reRenderRoot)) {
|
|
1516
|
+
const snapshot = { ..._formValues };
|
|
1501
1517
|
props.callback({
|
|
1502
|
-
values:
|
|
1518
|
+
values: snapshot,
|
|
1503
1519
|
..._formState,
|
|
1504
1520
|
...formState,
|
|
1505
1521
|
defaultValues: _defaultValues,
|
|
@@ -1561,7 +1577,7 @@ function createFormControl(props = {}) {
|
|
|
1561
1577
|
const register = (name, options = {}) => {
|
|
1562
1578
|
let field = get(_fields, name);
|
|
1563
1579
|
const disabledIsDefined = isBoolean(options.disabled) || isBoolean(_options.disabled);
|
|
1564
|
-
const shouldRevalidateRemount = !_names.registerName.has(name) && field && !field._f.mount;
|
|
1580
|
+
const shouldRevalidateRemount = !_names.registerName.has(name) && field && field._f && !field._f.mount;
|
|
1565
1581
|
set(_fields, name, {
|
|
1566
1582
|
...(field || {}),
|
|
1567
1583
|
_f: {
|