@underverse-ui/underverse 0.2.18 → 0.2.20
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/dist/index.cjs +155 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +155 -99
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -2406,29 +2406,28 @@ var useToast = () => {
|
|
|
2406
2406
|
}
|
|
2407
2407
|
return context;
|
|
2408
2408
|
};
|
|
2409
|
-
var ToastProvider = ({
|
|
2410
|
-
children,
|
|
2411
|
-
position = "top-right",
|
|
2412
|
-
maxToasts = 5
|
|
2413
|
-
}) => {
|
|
2409
|
+
var ToastProvider = ({ children, position = "top-right", maxToasts = 5 }) => {
|
|
2414
2410
|
const [toasts, setToasts] = (0, import_react7.useState)([]);
|
|
2415
2411
|
const idRef = (0, import_react7.useRef)(0);
|
|
2416
2412
|
const removeToast = (0, import_react7.useCallback)((id) => {
|
|
2417
2413
|
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
2418
2414
|
}, []);
|
|
2419
|
-
const addToast = (0, import_react7.useCallback)(
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
|
|
2424
|
-
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2415
|
+
const addToast = (0, import_react7.useCallback)(
|
|
2416
|
+
(toast) => {
|
|
2417
|
+
const id = `toast-${++idRef.current}`;
|
|
2418
|
+
const newToast = { ...toast, id };
|
|
2419
|
+
setToasts((prev) => {
|
|
2420
|
+
const updated = [newToast, ...prev];
|
|
2421
|
+
return updated.slice(0, maxToasts);
|
|
2422
|
+
});
|
|
2423
|
+
if (toast.duration !== 0) {
|
|
2424
|
+
setTimeout(() => {
|
|
2425
|
+
removeToast(id);
|
|
2426
|
+
}, toast.duration || 5e3);
|
|
2427
|
+
}
|
|
2428
|
+
},
|
|
2429
|
+
[maxToasts, removeToast]
|
|
2430
|
+
);
|
|
2432
2431
|
const positionClasses = {
|
|
2433
2432
|
"top-right": "top-4 right-4",
|
|
2434
2433
|
"top-left": "top-4 left-4",
|
|
@@ -2439,7 +2438,7 @@ var ToastProvider = ({
|
|
|
2439
2438
|
};
|
|
2440
2439
|
return /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(ToastContext.Provider, { value: { addToast, removeToast, toasts }, children: [
|
|
2441
2440
|
children,
|
|
2442
|
-
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: cn("fixed z-
|
|
2441
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("div", { className: cn("fixed z-[99999] flex flex-col gap-2 pointer-events-none", positionClasses[position]), "aria-live": "polite", "aria-atomic": true, children: toasts.map((toast) => /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ToastComponent, { toast, onRemove: removeToast }, toast.id)) })
|
|
2443
2442
|
] });
|
|
2444
2443
|
};
|
|
2445
2444
|
var ToastComponent = ({ toast, onRemove }) => {
|
|
@@ -3880,36 +3879,34 @@ var DropdownMenu = ({
|
|
|
3880
3879
|
if (open && triggerRef.current && contentRef.current) {
|
|
3881
3880
|
const rect = triggerRef.current.getBoundingClientRect();
|
|
3882
3881
|
const menuRect = contentRef.current.getBoundingClientRect();
|
|
3883
|
-
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
|
|
3884
|
-
const scrollLeft = window.pageXOffset || document.documentElement.scrollLeft;
|
|
3885
3882
|
const viewportHeight = window.innerHeight;
|
|
3886
|
-
let top = rect.bottom +
|
|
3887
|
-
let left = rect.left
|
|
3883
|
+
let top = rect.bottom + 4;
|
|
3884
|
+
let left = rect.left;
|
|
3888
3885
|
if (rect.bottom + menuRect.height > viewportHeight && rect.top > menuRect.height) {
|
|
3889
|
-
top = rect.top
|
|
3886
|
+
top = rect.top - menuRect.height - 4;
|
|
3890
3887
|
}
|
|
3891
3888
|
switch (placement) {
|
|
3892
3889
|
case "top":
|
|
3893
3890
|
case "top-start":
|
|
3894
|
-
top = rect.top
|
|
3891
|
+
top = rect.top - menuRect.height - 4;
|
|
3895
3892
|
break;
|
|
3896
3893
|
case "top-end":
|
|
3897
|
-
top = rect.top
|
|
3898
|
-
left = rect.right
|
|
3894
|
+
top = rect.top - menuRect.height - 4;
|
|
3895
|
+
left = rect.right - menuRect.width;
|
|
3899
3896
|
break;
|
|
3900
3897
|
case "bottom":
|
|
3901
3898
|
case "bottom-start":
|
|
3902
3899
|
break;
|
|
3903
3900
|
case "bottom-end":
|
|
3904
|
-
left = rect.right
|
|
3901
|
+
left = rect.right - menuRect.width;
|
|
3905
3902
|
break;
|
|
3906
3903
|
case "left":
|
|
3907
|
-
top = rect.top
|
|
3908
|
-
left = rect.left
|
|
3904
|
+
top = rect.top;
|
|
3905
|
+
left = rect.left - menuRect.width - 4;
|
|
3909
3906
|
break;
|
|
3910
3907
|
case "right":
|
|
3911
|
-
top = rect.top
|
|
3912
|
-
left = rect.right +
|
|
3908
|
+
top = rect.top;
|
|
3909
|
+
left = rect.right + 4;
|
|
3913
3910
|
break;
|
|
3914
3911
|
}
|
|
3915
3912
|
setPosition({ top, left });
|
|
@@ -3983,7 +3980,7 @@ var DropdownMenu = ({
|
|
|
3983
3980
|
"data-combobox-dropdown": true,
|
|
3984
3981
|
ref: contentRef,
|
|
3985
3982
|
style: {
|
|
3986
|
-
position: "
|
|
3983
|
+
position: "fixed",
|
|
3987
3984
|
top: position?.top ?? -9999,
|
|
3988
3985
|
left: position?.left ?? -9999,
|
|
3989
3986
|
zIndex: 9999,
|
|
@@ -10470,25 +10467,23 @@ var isPlainObject = (tempObject) => {
|
|
|
10470
10467
|
};
|
|
10471
10468
|
var isWeb = typeof window !== "undefined" && typeof window.HTMLElement !== "undefined" && typeof document !== "undefined";
|
|
10472
10469
|
function cloneObject(data) {
|
|
10473
|
-
let copy;
|
|
10474
|
-
const isArray = Array.isArray(data);
|
|
10475
|
-
const isFileListInstance = typeof FileList !== "undefined" ? data instanceof FileList : false;
|
|
10476
10470
|
if (data instanceof Date) {
|
|
10477
|
-
|
|
10478
|
-
}
|
|
10479
|
-
|
|
10480
|
-
|
|
10481
|
-
copy = data;
|
|
10482
|
-
} else {
|
|
10483
|
-
for (const key in data) {
|
|
10484
|
-
if (data.hasOwnProperty(key)) {
|
|
10485
|
-
copy[key] = cloneObject(data[key]);
|
|
10486
|
-
}
|
|
10487
|
-
}
|
|
10488
|
-
}
|
|
10489
|
-
} else {
|
|
10471
|
+
return new Date(data);
|
|
10472
|
+
}
|
|
10473
|
+
const isFileListInstance = typeof FileList !== "undefined" && data instanceof FileList;
|
|
10474
|
+
if (isWeb && (data instanceof Blob || isFileListInstance)) {
|
|
10490
10475
|
return data;
|
|
10491
10476
|
}
|
|
10477
|
+
const isArray = Array.isArray(data);
|
|
10478
|
+
if (!isArray && !(isObject(data) && isPlainObject(data))) {
|
|
10479
|
+
return data;
|
|
10480
|
+
}
|
|
10481
|
+
const copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
|
|
10482
|
+
for (const key in data) {
|
|
10483
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
10484
|
+
copy[key] = cloneObject(data[key]);
|
|
10485
|
+
}
|
|
10486
|
+
}
|
|
10492
10487
|
return copy;
|
|
10493
10488
|
}
|
|
10494
10489
|
var isKey = (value) => /^\w*$/.test(value);
|
|
@@ -10503,6 +10498,7 @@ var get = (object, path, defaultValue) => {
|
|
|
10503
10498
|
return isUndefined(result) || result === object ? isUndefined(object[path]) ? defaultValue : object[path] : result;
|
|
10504
10499
|
};
|
|
10505
10500
|
var isBoolean = (value) => typeof value === "boolean";
|
|
10501
|
+
var isFunction = (value) => typeof value === "function";
|
|
10506
10502
|
var set = (object, path, value) => {
|
|
10507
10503
|
let index = -1;
|
|
10508
10504
|
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
@@ -10614,7 +10610,7 @@ var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) =>
|
|
|
10614
10610
|
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
10615
10611
|
function deepEqual(object1, object2, _internal_visited = /* @__PURE__ */ new WeakSet()) {
|
|
10616
10612
|
if (isPrimitive(object1) || isPrimitive(object2)) {
|
|
10617
|
-
return object1
|
|
10613
|
+
return Object.is(object1, object2);
|
|
10618
10614
|
}
|
|
10619
10615
|
if (isDateObject(object1) && isDateObject(object2)) {
|
|
10620
10616
|
return object1.getTime() === object2.getTime();
|
|
@@ -10636,7 +10632,7 @@ function deepEqual(object1, object2, _internal_visited = /* @__PURE__ */ new Wea
|
|
|
10636
10632
|
}
|
|
10637
10633
|
if (key !== "ref") {
|
|
10638
10634
|
const val2 = object2[key];
|
|
10639
|
-
if (isDateObject(val1) && isDateObject(val2) || isObject(val1) && isObject(val2) || Array.isArray(val1) && Array.isArray(val2) ? !deepEqual(val1, val2, _internal_visited) : val1
|
|
10635
|
+
if (isDateObject(val1) && isDateObject(val2) || isObject(val1) && isObject(val2) || Array.isArray(val1) && Array.isArray(val2) ? !deepEqual(val1, val2, _internal_visited) : !Object.is(val1, val2)) {
|
|
10640
10636
|
return false;
|
|
10641
10637
|
}
|
|
10642
10638
|
}
|
|
@@ -10649,48 +10645,76 @@ function useWatch(props) {
|
|
|
10649
10645
|
const _defaultValue = import_react24.default.useRef(defaultValue);
|
|
10650
10646
|
const _compute = import_react24.default.useRef(compute);
|
|
10651
10647
|
const _computeFormValues = import_react24.default.useRef(void 0);
|
|
10648
|
+
const _prevControl = import_react24.default.useRef(control);
|
|
10649
|
+
const _prevName = import_react24.default.useRef(name);
|
|
10652
10650
|
_compute.current = compute;
|
|
10653
|
-
const
|
|
10654
|
-
|
|
10655
|
-
|
|
10656
|
-
|
|
10657
|
-
|
|
10658
|
-
|
|
10659
|
-
|
|
10660
|
-
|
|
10661
|
-
|
|
10662
|
-
|
|
10663
|
-
|
|
10664
|
-
|
|
10665
|
-
|
|
10666
|
-
|
|
10667
|
-
|
|
10668
|
-
|
|
10669
|
-
}
|
|
10670
|
-
} else {
|
|
10671
|
-
updateValue(formValues);
|
|
10651
|
+
const [value, updateValue] = import_react24.default.useState(() => {
|
|
10652
|
+
const defaultValue2 = control._getWatch(name, _defaultValue.current);
|
|
10653
|
+
return _compute.current ? _compute.current(defaultValue2) : defaultValue2;
|
|
10654
|
+
});
|
|
10655
|
+
const getCurrentOutput = import_react24.default.useCallback((values) => {
|
|
10656
|
+
const formValues = generateWatchOutput(name, control._names, values || control._formValues, false, _defaultValue.current);
|
|
10657
|
+
return _compute.current ? _compute.current(formValues) : formValues;
|
|
10658
|
+
}, [control._formValues, control._names, name]);
|
|
10659
|
+
const refreshValue = import_react24.default.useCallback((values) => {
|
|
10660
|
+
if (!disabled) {
|
|
10661
|
+
const formValues = generateWatchOutput(name, control._names, values || control._formValues, false, _defaultValue.current);
|
|
10662
|
+
if (_compute.current) {
|
|
10663
|
+
const computedFormValues = _compute.current(formValues);
|
|
10664
|
+
if (!deepEqual(computedFormValues, _computeFormValues.current)) {
|
|
10665
|
+
updateValue(computedFormValues);
|
|
10666
|
+
_computeFormValues.current = computedFormValues;
|
|
10672
10667
|
}
|
|
10668
|
+
} else {
|
|
10669
|
+
updateValue(formValues);
|
|
10673
10670
|
}
|
|
10674
10671
|
}
|
|
10675
|
-
}
|
|
10672
|
+
}, [control._formValues, control._names, disabled, name]);
|
|
10673
|
+
useIsomorphicLayoutEffect(() => {
|
|
10674
|
+
if (_prevControl.current !== control || !deepEqual(_prevName.current, name)) {
|
|
10675
|
+
_prevControl.current = control;
|
|
10676
|
+
_prevName.current = name;
|
|
10677
|
+
refreshValue();
|
|
10678
|
+
}
|
|
10679
|
+
return control._subscribe({
|
|
10680
|
+
name,
|
|
10681
|
+
formState: {
|
|
10682
|
+
values: true
|
|
10683
|
+
},
|
|
10684
|
+
exact,
|
|
10685
|
+
callback: (formState) => {
|
|
10686
|
+
refreshValue(formState.values);
|
|
10687
|
+
}
|
|
10688
|
+
});
|
|
10689
|
+
}, [control, exact, name, refreshValue]);
|
|
10676
10690
|
import_react24.default.useEffect(() => control._removeUnmounted());
|
|
10677
|
-
|
|
10691
|
+
const controlChanged = _prevControl.current !== control;
|
|
10692
|
+
const prevName = _prevName.current;
|
|
10693
|
+
const computedOutput = import_react24.default.useMemo(() => {
|
|
10694
|
+
if (disabled) {
|
|
10695
|
+
return null;
|
|
10696
|
+
}
|
|
10697
|
+
const nameChanged = !controlChanged && !deepEqual(prevName, name);
|
|
10698
|
+
const shouldReturnImmediate = controlChanged || nameChanged;
|
|
10699
|
+
return shouldReturnImmediate ? getCurrentOutput() : null;
|
|
10700
|
+
}, [disabled, controlChanged, name, prevName, getCurrentOutput]);
|
|
10701
|
+
return computedOutput !== null ? computedOutput : value;
|
|
10678
10702
|
}
|
|
10679
10703
|
function useController(props) {
|
|
10680
10704
|
const methods = useFormContext();
|
|
10681
|
-
const { name, disabled, control = methods.control, shouldUnregister, defaultValue } = props;
|
|
10705
|
+
const { name, disabled, control = methods.control, shouldUnregister, defaultValue, exact = true } = props;
|
|
10682
10706
|
const isArrayField = isNameInFieldArray(control._names.array, name);
|
|
10683
10707
|
const defaultValueMemo = import_react24.default.useMemo(() => get(control._formValues, name, get(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
|
|
10684
10708
|
const value = useWatch({
|
|
10685
10709
|
control,
|
|
10686
10710
|
name,
|
|
10687
10711
|
defaultValue: defaultValueMemo,
|
|
10688
|
-
exact
|
|
10712
|
+
exact
|
|
10689
10713
|
});
|
|
10690
10714
|
const formState = useFormState({
|
|
10691
10715
|
control,
|
|
10692
10716
|
name,
|
|
10693
|
-
exact
|
|
10717
|
+
exact
|
|
10694
10718
|
});
|
|
10695
10719
|
const _props = import_react24.default.useRef(props);
|
|
10696
10720
|
const _previousNameRef = import_react24.default.useRef(void 0);
|
|
@@ -10738,12 +10762,12 @@ function useController(props) {
|
|
|
10738
10762
|
}), [name, control._formValues]);
|
|
10739
10763
|
const ref = import_react24.default.useCallback((elm) => {
|
|
10740
10764
|
const field2 = get(control._fields, name);
|
|
10741
|
-
if (field2 && elm) {
|
|
10765
|
+
if (field2 && field2._f && elm) {
|
|
10742
10766
|
field2._f.ref = {
|
|
10743
|
-
focus: () => elm.focus && elm.focus(),
|
|
10744
|
-
select: () => elm.select && elm.select(),
|
|
10745
|
-
setCustomValidity: (message) => elm.setCustomValidity(message),
|
|
10746
|
-
reportValidity: () => elm.reportValidity()
|
|
10767
|
+
focus: () => isFunction(elm.focus) && elm.focus(),
|
|
10768
|
+
select: () => isFunction(elm.select) && elm.select(),
|
|
10769
|
+
setCustomValidity: (message) => isFunction(elm.setCustomValidity) && elm.setCustomValidity(message),
|
|
10770
|
+
reportValidity: () => isFunction(elm.reportValidity) && elm.reportValidity()
|
|
10747
10771
|
};
|
|
10748
10772
|
}
|
|
10749
10773
|
}, [control._fields, name]);
|
|
@@ -10853,7 +10877,6 @@ function extractFormValues(fieldsState, formValues) {
|
|
|
10853
10877
|
}
|
|
10854
10878
|
var isEmptyObject = (value) => isObject(value) && !Object.keys(value).length;
|
|
10855
10879
|
var isFileInput = (element) => element.type === "file";
|
|
10856
|
-
var isFunction = (value) => typeof value === "function";
|
|
10857
10880
|
var isHTMLElement = (value) => {
|
|
10858
10881
|
if (!isWeb) {
|
|
10859
10882
|
return false;
|
|
@@ -10907,10 +10930,11 @@ function isTraversable(value) {
|
|
|
10907
10930
|
}
|
|
10908
10931
|
function markFieldsDirty(data, fields = {}) {
|
|
10909
10932
|
for (const key in data) {
|
|
10910
|
-
|
|
10911
|
-
|
|
10912
|
-
|
|
10913
|
-
|
|
10933
|
+
const value = data[key];
|
|
10934
|
+
if (isTraversable(value)) {
|
|
10935
|
+
fields[key] = Array.isArray(value) ? [] : {};
|
|
10936
|
+
markFieldsDirty(value, fields[key]);
|
|
10937
|
+
} else if (!isUndefined(value)) {
|
|
10914
10938
|
fields[key] = true;
|
|
10915
10939
|
}
|
|
10916
10940
|
}
|
|
@@ -10921,14 +10945,16 @@ function getDirtyFields(data, formValues, dirtyFieldsFromValues) {
|
|
|
10921
10945
|
dirtyFieldsFromValues = markFieldsDirty(formValues);
|
|
10922
10946
|
}
|
|
10923
10947
|
for (const key in data) {
|
|
10924
|
-
|
|
10948
|
+
const value = data[key];
|
|
10949
|
+
if (isTraversable(value)) {
|
|
10925
10950
|
if (isUndefined(formValues) || isPrimitive(dirtyFieldsFromValues[key])) {
|
|
10926
|
-
dirtyFieldsFromValues[key] = markFieldsDirty(
|
|
10951
|
+
dirtyFieldsFromValues[key] = markFieldsDirty(value, Array.isArray(value) ? [] : {});
|
|
10927
10952
|
} else {
|
|
10928
|
-
getDirtyFields(
|
|
10953
|
+
getDirtyFields(value, isNullOrUndefined(formValues) ? {} : formValues[key], dirtyFieldsFromValues[key]);
|
|
10929
10954
|
}
|
|
10930
10955
|
} else {
|
|
10931
|
-
|
|
10956
|
+
const formValue = formValues[key];
|
|
10957
|
+
dirtyFieldsFromValues[key] = !deepEqual(value, formValue);
|
|
10932
10958
|
}
|
|
10933
10959
|
}
|
|
10934
10960
|
return dirtyFieldsFromValues;
|
|
@@ -11280,7 +11306,8 @@ function createFormControl(props = {}) {
|
|
|
11280
11306
|
let _state = {
|
|
11281
11307
|
action: false,
|
|
11282
11308
|
mount: false,
|
|
11283
|
-
watch: false
|
|
11309
|
+
watch: false,
|
|
11310
|
+
keepIsValid: false
|
|
11284
11311
|
};
|
|
11285
11312
|
let _names = {
|
|
11286
11313
|
mount: /* @__PURE__ */ new Set(),
|
|
@@ -11291,7 +11318,7 @@ function createFormControl(props = {}) {
|
|
|
11291
11318
|
};
|
|
11292
11319
|
let delayErrorCallback;
|
|
11293
11320
|
let timer = 0;
|
|
11294
|
-
const
|
|
11321
|
+
const defaultProxyFormState = {
|
|
11295
11322
|
isDirty: false,
|
|
11296
11323
|
dirtyFields: false,
|
|
11297
11324
|
validatingFields: false,
|
|
@@ -11300,6 +11327,9 @@ function createFormControl(props = {}) {
|
|
|
11300
11327
|
isValid: false,
|
|
11301
11328
|
errors: false
|
|
11302
11329
|
};
|
|
11330
|
+
const _proxyFormState = {
|
|
11331
|
+
...defaultProxyFormState
|
|
11332
|
+
};
|
|
11303
11333
|
let _proxySubscribeFormState = {
|
|
11304
11334
|
..._proxyFormState
|
|
11305
11335
|
};
|
|
@@ -11313,8 +11343,17 @@ function createFormControl(props = {}) {
|
|
|
11313
11343
|
timer = setTimeout(callback, wait);
|
|
11314
11344
|
};
|
|
11315
11345
|
const _setValid = async (shouldUpdateValid) => {
|
|
11346
|
+
if (_state.keepIsValid) {
|
|
11347
|
+
return;
|
|
11348
|
+
}
|
|
11316
11349
|
if (!_options.disabled && (_proxyFormState.isValid || _proxySubscribeFormState.isValid || shouldUpdateValid)) {
|
|
11317
|
-
|
|
11350
|
+
let isValid;
|
|
11351
|
+
if (_options.resolver) {
|
|
11352
|
+
isValid = isEmptyObject((await _runSchema()).errors);
|
|
11353
|
+
_updateIsValidating();
|
|
11354
|
+
} else {
|
|
11355
|
+
isValid = await executeBuiltInValidation(_fields, true);
|
|
11356
|
+
}
|
|
11318
11357
|
if (isValid !== _formState.isValid) {
|
|
11319
11358
|
_subjects.state.next({
|
|
11320
11359
|
isValid
|
|
@@ -11383,7 +11422,7 @@ function createFormControl(props = {}) {
|
|
|
11383
11422
|
if (field) {
|
|
11384
11423
|
const defaultValue = get(_formValues, name, isUndefined(value) ? get(_defaultValues, name) : value);
|
|
11385
11424
|
isUndefined(defaultValue) || ref && ref.defaultChecked || shouldSkipSetValueAs ? set(_formValues, name, shouldSkipSetValueAs ? defaultValue : getFieldValue(field._f)) : setFieldValue(name, defaultValue);
|
|
11386
|
-
_state.mount && _setValid();
|
|
11425
|
+
_state.mount && !_state.action && _setValid();
|
|
11387
11426
|
}
|
|
11388
11427
|
};
|
|
11389
11428
|
const updateTouchAndDirty = (name, fieldValue, isBlurEvent, shouldDirty, shouldRender) => {
|
|
@@ -11445,11 +11484,11 @@ function createFormControl(props = {}) {
|
|
|
11445
11484
|
const _runSchema = async (name) => {
|
|
11446
11485
|
_updateIsValidating(name, true);
|
|
11447
11486
|
const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
|
|
11448
|
-
_updateIsValidating(name);
|
|
11449
11487
|
return result;
|
|
11450
11488
|
};
|
|
11451
11489
|
const executeSchemaAndUpdateState = async (names) => {
|
|
11452
11490
|
const { errors } = await _runSchema(names);
|
|
11491
|
+
_updateIsValidating(names);
|
|
11453
11492
|
if (names) {
|
|
11454
11493
|
for (const name of names) {
|
|
11455
11494
|
const error = get(errors, name);
|
|
@@ -11628,6 +11667,7 @@ function createFormControl(props = {}) {
|
|
|
11628
11667
|
!isBlurEvent && watched && _subjects.state.next({ ..._formState });
|
|
11629
11668
|
if (_options.resolver) {
|
|
11630
11669
|
const { errors } = await _runSchema([name]);
|
|
11670
|
+
_updateIsValidating([name]);
|
|
11631
11671
|
_updateIsFieldValueUpdated(fieldValue);
|
|
11632
11672
|
if (isFieldValueUpdated) {
|
|
11633
11673
|
const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
|
|
@@ -11748,7 +11788,10 @@ function createFormControl(props = {}) {
|
|
|
11748
11788
|
};
|
|
11749
11789
|
return _subscribe({
|
|
11750
11790
|
...props2,
|
|
11751
|
-
formState:
|
|
11791
|
+
formState: {
|
|
11792
|
+
...defaultProxyFormState,
|
|
11793
|
+
...props2.formState
|
|
11794
|
+
}
|
|
11752
11795
|
});
|
|
11753
11796
|
};
|
|
11754
11797
|
const unregister = (name, options = {}) => {
|
|
@@ -11876,6 +11919,7 @@ function createFormControl(props = {}) {
|
|
|
11876
11919
|
});
|
|
11877
11920
|
if (_options.resolver) {
|
|
11878
11921
|
const { errors, values } = await _runSchema();
|
|
11922
|
+
_updateIsValidating();
|
|
11879
11923
|
_formState.errors = errors;
|
|
11880
11924
|
fieldValues = cloneObject(values);
|
|
11881
11925
|
} else {
|
|
@@ -11994,8 +12038,13 @@ function createFormControl(props = {}) {
|
|
|
11994
12038
|
watchAll: false,
|
|
11995
12039
|
focus: ""
|
|
11996
12040
|
};
|
|
11997
|
-
_state.mount = !_proxyFormState.isValid || !!keepStateOptions.keepIsValid || !!keepStateOptions.keepDirtyValues;
|
|
12041
|
+
_state.mount = !_proxyFormState.isValid || !!keepStateOptions.keepIsValid || !!keepStateOptions.keepDirtyValues || !_options.shouldUnregister && !isEmptyObject(values);
|
|
11998
12042
|
_state.watch = !!_options.shouldUnregister;
|
|
12043
|
+
_state.keepIsValid = !!keepStateOptions.keepIsValid;
|
|
12044
|
+
_state.action = false;
|
|
12045
|
+
if (!keepStateOptions.keepErrors) {
|
|
12046
|
+
_formState.errors = {};
|
|
12047
|
+
}
|
|
11999
12048
|
_subjects.state.next({
|
|
12000
12049
|
submitCount: keepStateOptions.keepSubmitCount ? _formState.submitCount : 0,
|
|
12001
12050
|
isDirty: isEmptyResetValues ? false : keepStateOptions.keepDirty ? _formState.isDirty : !!(keepStateOptions.keepDefaultValues && !deepEqual(formValues, _defaultValues)),
|
|
@@ -12008,15 +12057,17 @@ function createFormControl(props = {}) {
|
|
|
12008
12057
|
defaultValues: _defaultValues
|
|
12009
12058
|
});
|
|
12010
12059
|
};
|
|
12011
|
-
const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues) ? formValues(_formValues) : formValues, keepStateOptions);
|
|
12060
|
+
const reset = (formValues, keepStateOptions) => _reset(isFunction(formValues) ? formValues(_formValues) : formValues, { ..._options.resetOptions, ...keepStateOptions });
|
|
12012
12061
|
const setFocus = (name, options = {}) => {
|
|
12013
12062
|
const field = get(_fields, name);
|
|
12014
12063
|
const fieldReference = field && field._f;
|
|
12015
12064
|
if (fieldReference) {
|
|
12016
12065
|
const fieldRef = fieldReference.refs ? fieldReference.refs[0] : fieldReference.ref;
|
|
12017
12066
|
if (fieldRef.focus) {
|
|
12018
|
-
|
|
12019
|
-
|
|
12067
|
+
setTimeout(() => {
|
|
12068
|
+
fieldRef.focus();
|
|
12069
|
+
options.shouldSelect && isFunction(fieldRef.select) && fieldRef.select();
|
|
12070
|
+
});
|
|
12020
12071
|
}
|
|
12021
12072
|
}
|
|
12022
12073
|
};
|
|
@@ -12041,6 +12092,7 @@ function createFormControl(props = {}) {
|
|
|
12041
12092
|
setError,
|
|
12042
12093
|
_subscribe,
|
|
12043
12094
|
_runSchema,
|
|
12095
|
+
_updateIsValidating,
|
|
12044
12096
|
_focusError,
|
|
12045
12097
|
_getWatch,
|
|
12046
12098
|
_getDirty,
|
|
@@ -12192,11 +12244,15 @@ function useForm(props = {}) {
|
|
|
12192
12244
|
}
|
|
12193
12245
|
}, [control, formState.isDirty]);
|
|
12194
12246
|
import_react24.default.useEffect(() => {
|
|
12247
|
+
var _a;
|
|
12195
12248
|
if (props.values && !deepEqual(props.values, _values.current)) {
|
|
12196
12249
|
control._reset(props.values, {
|
|
12197
12250
|
keepFieldsRef: true,
|
|
12198
12251
|
...control._options.resetOptions
|
|
12199
12252
|
});
|
|
12253
|
+
if (!((_a = control._options.resetOptions) === null || _a === void 0 ? void 0 : _a.keepIsValid)) {
|
|
12254
|
+
control._setValid();
|
|
12255
|
+
}
|
|
12200
12256
|
_values.current = props.values;
|
|
12201
12257
|
updateFormState((state) => ({ ...state }));
|
|
12202
12258
|
} else {
|