@bombillazo/rhf-plus 7.56.3-plus.0 → 7.56.3-plus.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 +2 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.mjs +74 -3
- 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 +3 -3
- package/dist/logic/createFormControl.d.ts.map +1 -1
- package/dist/react-server.esm.mjs +66 -2
- package/dist/react-server.esm.mjs.map +1 -1
- package/dist/types/form.d.ts +64 -9
- package/dist/types/form.d.ts.map +1 -1
- package/dist/useForm.d.ts +2 -2
- package/dist/useForm.d.ts.map +1 -1
- package/dist/useFormContext.d.ts +3 -3
- package/dist/useFormContext.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/index.esm.mjs
CHANGED
|
@@ -719,6 +719,25 @@ function deepEqual(object1, object2) {
|
|
|
719
719
|
return true;
|
|
720
720
|
}
|
|
721
721
|
|
|
722
|
+
function deepMerge(target, source) {
|
|
723
|
+
if (isPrimitive(target) || isPrimitive(source)) {
|
|
724
|
+
return source;
|
|
725
|
+
}
|
|
726
|
+
for (const key in source) {
|
|
727
|
+
const targetValue = target[key];
|
|
728
|
+
const sourceValue = source[key];
|
|
729
|
+
try {
|
|
730
|
+
target[key] =
|
|
731
|
+
(isObject(targetValue) && isObject(sourceValue)) ||
|
|
732
|
+
(Array.isArray(targetValue) && Array.isArray(sourceValue))
|
|
733
|
+
? deepMerge(targetValue, sourceValue)
|
|
734
|
+
: sourceValue;
|
|
735
|
+
}
|
|
736
|
+
catch (_a) { }
|
|
737
|
+
}
|
|
738
|
+
return target;
|
|
739
|
+
}
|
|
740
|
+
|
|
722
741
|
var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
|
|
723
742
|
|
|
724
743
|
var isFileInput = (element) => element.type === 'file';
|
|
@@ -1277,11 +1296,12 @@ function createFormControl(props = {}) {
|
|
|
1277
1296
|
...defaultOptions,
|
|
1278
1297
|
...props,
|
|
1279
1298
|
};
|
|
1299
|
+
let _internalLoading = _options.isLoading || isFunction(_options.defaultValues);
|
|
1280
1300
|
let _formState = {
|
|
1281
1301
|
submitCount: 0,
|
|
1282
1302
|
isDirty: false,
|
|
1283
1303
|
isReady: false,
|
|
1284
|
-
isLoading:
|
|
1304
|
+
isLoading: _internalLoading,
|
|
1285
1305
|
isValidating: false,
|
|
1286
1306
|
isSubmitted: false,
|
|
1287
1307
|
isSubmitting: false,
|
|
@@ -1292,6 +1312,7 @@ function createFormControl(props = {}) {
|
|
|
1292
1312
|
validatingFields: {},
|
|
1293
1313
|
errors: _options.errors || {},
|
|
1294
1314
|
disabled: _options.disabled || false,
|
|
1315
|
+
metadata: _options.defaultMetadata || {},
|
|
1295
1316
|
};
|
|
1296
1317
|
const _fields = {};
|
|
1297
1318
|
let _defaultValues = isObject(_options.defaultValues) || isObject(_options.values)
|
|
@@ -1333,6 +1354,7 @@ function createFormControl(props = {}) {
|
|
|
1333
1354
|
const validationModeBeforeSubmit = getValidationModes(_options.mode);
|
|
1334
1355
|
const validationModeAfterSubmit = getValidationModes(_options.reValidateMode);
|
|
1335
1356
|
const shouldDisplayAllAssociatedErrors = _options.criteriaMode === VALIDATION_MODE.all;
|
|
1357
|
+
const id = createId(props.id);
|
|
1336
1358
|
const debounce = (callback) => (wait) => {
|
|
1337
1359
|
clearTimeout(timer);
|
|
1338
1360
|
timer = setTimeout(callback, wait);
|
|
@@ -2222,11 +2244,50 @@ function createFormControl(props = {}) {
|
|
|
2222
2244
|
_subjects.state.next({
|
|
2223
2245
|
isLoading: false,
|
|
2224
2246
|
});
|
|
2247
|
+
_internalLoading = false;
|
|
2225
2248
|
});
|
|
2226
|
-
const id = createId(props.id);
|
|
2227
2249
|
const submit = () => {
|
|
2228
2250
|
submitForm(id);
|
|
2229
2251
|
};
|
|
2252
|
+
const _updateIsLoading = (isLoading) => {
|
|
2253
|
+
if (!isUndefined(isLoading)) {
|
|
2254
|
+
const _loading = isLoading || _internalLoading;
|
|
2255
|
+
if (_formState.isLoading !== _loading) {
|
|
2256
|
+
_formState.isLoading = _loading;
|
|
2257
|
+
_subjects.state.next({
|
|
2258
|
+
isLoading: _loading,
|
|
2259
|
+
});
|
|
2260
|
+
}
|
|
2261
|
+
}
|
|
2262
|
+
else if (!!isLoading !== _formState.isLoading) {
|
|
2263
|
+
_formState.isLoading = _internalLoading;
|
|
2264
|
+
_subjects.state.next({
|
|
2265
|
+
isLoading: _internalLoading,
|
|
2266
|
+
});
|
|
2267
|
+
}
|
|
2268
|
+
};
|
|
2269
|
+
const setMetadata = (metadata) => {
|
|
2270
|
+
let _metadata;
|
|
2271
|
+
if (!metadata) {
|
|
2272
|
+
_metadata = _options.defaultMetadata
|
|
2273
|
+
? cloneObject(_options.defaultMetadata)
|
|
2274
|
+
: {};
|
|
2275
|
+
}
|
|
2276
|
+
else {
|
|
2277
|
+
_metadata = metadata;
|
|
2278
|
+
}
|
|
2279
|
+
_formState.metadata = _metadata;
|
|
2280
|
+
_subjects.state.next({
|
|
2281
|
+
metadata: _metadata,
|
|
2282
|
+
});
|
|
2283
|
+
};
|
|
2284
|
+
const updateMetadata = (metadata) => {
|
|
2285
|
+
const _metadata = deepMerge(_formState.metadata, metadata);
|
|
2286
|
+
_formState.metadata = _metadata;
|
|
2287
|
+
_subjects.state.next({
|
|
2288
|
+
metadata: _metadata,
|
|
2289
|
+
});
|
|
2290
|
+
};
|
|
2230
2291
|
const methods = {
|
|
2231
2292
|
control: {
|
|
2232
2293
|
register,
|
|
@@ -2247,6 +2308,7 @@ function createFormControl(props = {}) {
|
|
|
2247
2308
|
_resetDefaultValues,
|
|
2248
2309
|
_removeUnmounted,
|
|
2249
2310
|
_disableForm,
|
|
2311
|
+
_updateIsLoading,
|
|
2250
2312
|
_subjects,
|
|
2251
2313
|
_proxyFormState,
|
|
2252
2314
|
get _fields() {
|
|
@@ -2299,6 +2361,8 @@ function createFormControl(props = {}) {
|
|
|
2299
2361
|
getFieldState,
|
|
2300
2362
|
id,
|
|
2301
2363
|
submit,
|
|
2364
|
+
setMetadata,
|
|
2365
|
+
updateMetadata,
|
|
2302
2366
|
};
|
|
2303
2367
|
return {
|
|
2304
2368
|
...methods,
|
|
@@ -2642,12 +2706,13 @@ function useFieldArray(props) {
|
|
|
2642
2706
|
* ```
|
|
2643
2707
|
*/
|
|
2644
2708
|
function useForm(props = {}) {
|
|
2709
|
+
var _a;
|
|
2645
2710
|
const _formControl = React__default.useRef(undefined);
|
|
2646
2711
|
const _values = React__default.useRef(undefined);
|
|
2647
2712
|
const [formState, updateFormState] = React__default.useState({
|
|
2648
2713
|
isDirty: false,
|
|
2649
2714
|
isValidating: false,
|
|
2650
|
-
isLoading: isFunction(props.defaultValues),
|
|
2715
|
+
isLoading: props.isLoading || isFunction(props.defaultValues),
|
|
2651
2716
|
isSubmitted: false,
|
|
2652
2717
|
isSubmitting: false,
|
|
2653
2718
|
isSubmitSuccessful: false,
|
|
@@ -2662,6 +2727,9 @@ function useForm(props = {}) {
|
|
|
2662
2727
|
defaultValues: isFunction(props.defaultValues)
|
|
2663
2728
|
? undefined
|
|
2664
2729
|
: props.defaultValues,
|
|
2730
|
+
metadata: props.defaultMetadata ||
|
|
2731
|
+
((_a = props.formControl) === null || _a === void 0 ? void 0 : _a.control._options.defaultMetadata) ||
|
|
2732
|
+
{},
|
|
2665
2733
|
});
|
|
2666
2734
|
if (!_formControl.current) {
|
|
2667
2735
|
_formControl.current = {
|
|
@@ -2690,6 +2758,9 @@ function useForm(props = {}) {
|
|
|
2690
2758
|
return sub;
|
|
2691
2759
|
}, [control]);
|
|
2692
2760
|
React__default.useEffect(() => control._disableForm(props.disabled), [control, props.disabled]);
|
|
2761
|
+
React__default.useEffect(() => {
|
|
2762
|
+
control._updateIsLoading(props.isLoading);
|
|
2763
|
+
}, [control, props.isLoading]);
|
|
2693
2764
|
React__default.useEffect(() => {
|
|
2694
2765
|
if (props.mode) {
|
|
2695
2766
|
control._options.mode = props.mode;
|