@dreamtree-org/twreact-ui 1.1.0 → 1.1.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.
- package/dist/index.css +1 -1
- package/dist/index.esm.css +1 -1
- package/dist/index.esm.js +217 -153
- package/dist/index.js +217 -153
- package/package.json +9 -11
package/dist/index.js
CHANGED
|
@@ -5284,29 +5284,23 @@ var isWeb = typeof window !== 'undefined' &&
|
|
|
5284
5284
|
typeof document !== 'undefined';
|
|
5285
5285
|
|
|
5286
5286
|
function cloneObject(data) {
|
|
5287
|
-
let copy;
|
|
5288
|
-
const isArray = Array.isArray(data);
|
|
5289
|
-
const isFileListInstance = typeof FileList !== 'undefined' ? data instanceof FileList : false;
|
|
5290
5287
|
if (data instanceof Date) {
|
|
5291
|
-
|
|
5288
|
+
return new Date(data);
|
|
5292
5289
|
}
|
|
5293
|
-
|
|
5294
|
-
|
|
5295
|
-
|
|
5296
|
-
if (!isArray && !isPlainObject$3(data)) {
|
|
5297
|
-
copy = data;
|
|
5298
|
-
}
|
|
5299
|
-
else {
|
|
5300
|
-
for (const key in data) {
|
|
5301
|
-
if (data.hasOwnProperty(key)) {
|
|
5302
|
-
copy[key] = cloneObject(data[key]);
|
|
5303
|
-
}
|
|
5304
|
-
}
|
|
5305
|
-
}
|
|
5290
|
+
const isFileListInstance = typeof FileList !== 'undefined' && data instanceof FileList;
|
|
5291
|
+
if (isWeb && (data instanceof Blob || isFileListInstance)) {
|
|
5292
|
+
return data;
|
|
5306
5293
|
}
|
|
5307
|
-
|
|
5294
|
+
const isArray = Array.isArray(data);
|
|
5295
|
+
if (!isArray && !(isObject$1(data) && isPlainObject$3(data))) {
|
|
5308
5296
|
return data;
|
|
5309
5297
|
}
|
|
5298
|
+
const copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
|
|
5299
|
+
for (const key in data) {
|
|
5300
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
5301
|
+
copy[key] = cloneObject(data[key]);
|
|
5302
|
+
}
|
|
5303
|
+
}
|
|
5310
5304
|
return copy;
|
|
5311
5305
|
}
|
|
5312
5306
|
|
|
@@ -5332,6 +5326,8 @@ var get$1 = (object, path, defaultValue) => {
|
|
|
5332
5326
|
|
|
5333
5327
|
var isBoolean$3 = (value) => typeof value === 'boolean';
|
|
5334
5328
|
|
|
5329
|
+
var isFunction$3 = (value) => typeof value === 'function';
|
|
5330
|
+
|
|
5335
5331
|
var set$1 = (object, path, value) => {
|
|
5336
5332
|
let index = -1;
|
|
5337
5333
|
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
@@ -5379,73 +5375,16 @@ const INPUT_VALIDATION_RULES = {
|
|
|
5379
5375
|
validate: 'validate',
|
|
5380
5376
|
};
|
|
5381
5377
|
|
|
5382
|
-
const HookFormContext = React.createContext(null);
|
|
5383
|
-
HookFormContext.displayName = 'HookFormContext';
|
|
5384
5378
|
/**
|
|
5385
|
-
*
|
|
5386
|
-
*
|
|
5387
|
-
* @remarks
|
|
5388
|
-
* [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
|
5389
|
-
*
|
|
5390
|
-
* @returns return all useForm methods
|
|
5391
|
-
*
|
|
5392
|
-
* @example
|
|
5393
|
-
* ```tsx
|
|
5394
|
-
* function App() {
|
|
5395
|
-
* const methods = useForm();
|
|
5396
|
-
* const onSubmit = data => console.log(data);
|
|
5397
|
-
*
|
|
5398
|
-
* return (
|
|
5399
|
-
* <FormProvider {...methods} >
|
|
5400
|
-
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
5401
|
-
* <NestedInput />
|
|
5402
|
-
* <input type="submit" />
|
|
5403
|
-
* </form>
|
|
5404
|
-
* </FormProvider>
|
|
5405
|
-
* );
|
|
5406
|
-
* }
|
|
5407
|
-
*
|
|
5408
|
-
* function NestedInput() {
|
|
5409
|
-
* const { register } = useFormContext(); // retrieve all hook methods
|
|
5410
|
-
* return <input {...register("test")} />;
|
|
5411
|
-
* }
|
|
5412
|
-
* ```
|
|
5379
|
+
* Separate context for `control` to prevent unnecessary rerenders.
|
|
5380
|
+
* Internal hooks that only need control use this instead of full form context.
|
|
5413
5381
|
*/
|
|
5414
|
-
const
|
|
5382
|
+
const HookFormControlContext = React.createContext(null);
|
|
5383
|
+
HookFormControlContext.displayName = 'HookFormControlContext';
|
|
5415
5384
|
/**
|
|
5416
|
-
*
|
|
5417
|
-
*
|
|
5418
|
-
* @remarks
|
|
5419
|
-
* [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
|
5420
|
-
*
|
|
5421
|
-
* @param props - all useForm methods
|
|
5422
|
-
*
|
|
5423
|
-
* @example
|
|
5424
|
-
* ```tsx
|
|
5425
|
-
* function App() {
|
|
5426
|
-
* const methods = useForm();
|
|
5427
|
-
* const onSubmit = data => console.log(data);
|
|
5428
|
-
*
|
|
5429
|
-
* return (
|
|
5430
|
-
* <FormProvider {...methods} >
|
|
5431
|
-
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
5432
|
-
* <NestedInput />
|
|
5433
|
-
* <input type="submit" />
|
|
5434
|
-
* </form>
|
|
5435
|
-
* </FormProvider>
|
|
5436
|
-
* );
|
|
5437
|
-
* }
|
|
5438
|
-
*
|
|
5439
|
-
* function NestedInput() {
|
|
5440
|
-
* const { register } = useFormContext(); // retrieve all hook methods
|
|
5441
|
-
* return <input {...register("test")} />;
|
|
5442
|
-
* }
|
|
5443
|
-
* ```
|
|
5385
|
+
* @internal Internal hook to access only control from context.
|
|
5444
5386
|
*/
|
|
5445
|
-
const
|
|
5446
|
-
const { children, ...data } = props;
|
|
5447
|
-
return (React.createElement(HookFormContext.Provider, { value: data }, children));
|
|
5448
|
-
};
|
|
5387
|
+
const useFormControlContext = () => React.useContext(HookFormControlContext);
|
|
5449
5388
|
|
|
5450
5389
|
var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
|
|
5451
5390
|
const result = {
|
|
@@ -5499,8 +5438,8 @@ const useIsomorphicLayoutEffect$1 = typeof window !== 'undefined' ? React.useLay
|
|
|
5499
5438
|
* ```
|
|
5500
5439
|
*/
|
|
5501
5440
|
function useFormState(props) {
|
|
5502
|
-
const
|
|
5503
|
-
const { control =
|
|
5441
|
+
const formControl = useFormControlContext();
|
|
5442
|
+
const { control = formControl, disabled, name, exact } = props || {};
|
|
5504
5443
|
const [formState, updateFormState] = React.useState(control._formState);
|
|
5505
5444
|
const _localProxyFormState = React.useRef({
|
|
5506
5445
|
isDirty: false,
|
|
@@ -5552,7 +5491,7 @@ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
|
5552
5491
|
return Object.is(object1, object2);
|
|
5553
5492
|
}
|
|
5554
5493
|
if (isDateObject(object1) && isDateObject(object2)) {
|
|
5555
|
-
return object1.getTime()
|
|
5494
|
+
return Object.is(object1.getTime(), object2.getTime());
|
|
5556
5495
|
}
|
|
5557
5496
|
const keys1 = Object.keys(object1);
|
|
5558
5497
|
const keys2 = Object.keys(object2);
|
|
@@ -5600,8 +5539,8 @@ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
|
5600
5539
|
* ```
|
|
5601
5540
|
*/
|
|
5602
5541
|
function useWatch(props) {
|
|
5603
|
-
const
|
|
5604
|
-
const { control =
|
|
5542
|
+
const formControl = useFormControlContext();
|
|
5543
|
+
const { control = formControl, name, defaultValue, disabled, exact, compute, } = props || {};
|
|
5605
5544
|
const _defaultValue = React.useRef(defaultValue);
|
|
5606
5545
|
const _compute = React.useRef(compute);
|
|
5607
5546
|
const _computeFormValues = React.useRef(undefined);
|
|
@@ -5694,8 +5633,8 @@ function useWatch(props) {
|
|
|
5694
5633
|
* ```
|
|
5695
5634
|
*/
|
|
5696
5635
|
function useController(props) {
|
|
5697
|
-
const
|
|
5698
|
-
const { name, disabled, control =
|
|
5636
|
+
const formControl = useFormControlContext();
|
|
5637
|
+
const { name, disabled, control = formControl, shouldUnregister, defaultValue, exact = true, } = props;
|
|
5699
5638
|
const isArrayField = isNameInFieldArray(control._names.array, name);
|
|
5700
5639
|
const defaultValueMemo = React.useMemo(() => get$1(control._formValues, name, get$1(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
|
|
5701
5640
|
const value = useWatch({
|
|
@@ -5755,12 +5694,12 @@ function useController(props) {
|
|
|
5755
5694
|
}), [name, control._formValues]);
|
|
5756
5695
|
const ref = React.useCallback((elm) => {
|
|
5757
5696
|
const field = get$1(control._fields, name);
|
|
5758
|
-
if (field && elm) {
|
|
5697
|
+
if (field && field._f && elm) {
|
|
5759
5698
|
field._f.ref = {
|
|
5760
|
-
focus: () => elm.focus && elm.focus(),
|
|
5761
|
-
select: () => elm.select && elm.select(),
|
|
5762
|
-
setCustomValidity: (message) => elm.setCustomValidity(message),
|
|
5763
|
-
reportValidity: () => elm.reportValidity(),
|
|
5699
|
+
focus: () => isFunction$3(elm.focus) && elm.focus(),
|
|
5700
|
+
select: () => isFunction$3(elm.select) && elm.select(),
|
|
5701
|
+
setCustomValidity: (message) => isFunction$3(elm.setCustomValidity) && elm.setCustomValidity(message),
|
|
5702
|
+
reportValidity: () => isFunction$3(elm.reportValidity) && elm.reportValidity(),
|
|
5764
5703
|
};
|
|
5765
5704
|
}
|
|
5766
5705
|
}, [control._fields, name]);
|
|
@@ -5867,6 +5806,78 @@ function useController(props) {
|
|
|
5867
5806
|
*/
|
|
5868
5807
|
const Controller = (props) => props.render(useController(props));
|
|
5869
5808
|
|
|
5809
|
+
const HookFormContext = React.createContext(null);
|
|
5810
|
+
HookFormContext.displayName = 'HookFormContext';
|
|
5811
|
+
/**
|
|
5812
|
+
* A provider component that propagates the `useForm` methods to all children components via [React Context](https://react.dev/reference/react/useContext) API. To be used with {@link useFormContext}.
|
|
5813
|
+
*
|
|
5814
|
+
* @remarks
|
|
5815
|
+
* [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
|
5816
|
+
*
|
|
5817
|
+
* @param props - all useForm methods
|
|
5818
|
+
*
|
|
5819
|
+
* @example
|
|
5820
|
+
* ```tsx
|
|
5821
|
+
* function App() {
|
|
5822
|
+
* const methods = useForm();
|
|
5823
|
+
* const onSubmit = data => console.log(data);
|
|
5824
|
+
*
|
|
5825
|
+
* return (
|
|
5826
|
+
* <FormProvider {...methods} >
|
|
5827
|
+
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
5828
|
+
* <NestedInput />
|
|
5829
|
+
* <input type="submit" />
|
|
5830
|
+
* </form>
|
|
5831
|
+
* </FormProvider>
|
|
5832
|
+
* );
|
|
5833
|
+
* }
|
|
5834
|
+
*
|
|
5835
|
+
* function NestedInput() {
|
|
5836
|
+
* const { register } = useFormContext(); // retrieve all hook methods
|
|
5837
|
+
* return <input {...register("test")} />;
|
|
5838
|
+
* }
|
|
5839
|
+
* ```
|
|
5840
|
+
*/
|
|
5841
|
+
const FormProvider = (props) => {
|
|
5842
|
+
const { children, watch, getValues, getFieldState, setError, clearErrors, setValue, trigger, formState, resetField, reset, handleSubmit, unregister, control, register, setFocus, subscribe, } = props;
|
|
5843
|
+
return (React.createElement(HookFormContext.Provider, { value: React.useMemo(() => ({
|
|
5844
|
+
watch,
|
|
5845
|
+
getValues,
|
|
5846
|
+
getFieldState,
|
|
5847
|
+
setError,
|
|
5848
|
+
clearErrors,
|
|
5849
|
+
setValue,
|
|
5850
|
+
trigger,
|
|
5851
|
+
formState,
|
|
5852
|
+
resetField,
|
|
5853
|
+
reset,
|
|
5854
|
+
handleSubmit,
|
|
5855
|
+
unregister,
|
|
5856
|
+
control,
|
|
5857
|
+
register,
|
|
5858
|
+
setFocus,
|
|
5859
|
+
subscribe,
|
|
5860
|
+
}), [
|
|
5861
|
+
clearErrors,
|
|
5862
|
+
control,
|
|
5863
|
+
formState,
|
|
5864
|
+
getFieldState,
|
|
5865
|
+
getValues,
|
|
5866
|
+
handleSubmit,
|
|
5867
|
+
register,
|
|
5868
|
+
reset,
|
|
5869
|
+
resetField,
|
|
5870
|
+
setError,
|
|
5871
|
+
setFocus,
|
|
5872
|
+
setValue,
|
|
5873
|
+
subscribe,
|
|
5874
|
+
trigger,
|
|
5875
|
+
unregister,
|
|
5876
|
+
watch,
|
|
5877
|
+
]) },
|
|
5878
|
+
React.createElement(HookFormControlContext.Provider, { value: control }, children)));
|
|
5879
|
+
};
|
|
5880
|
+
|
|
5870
5881
|
var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
|
|
5871
5882
|
? {
|
|
5872
5883
|
...errors[name],
|
|
@@ -5931,8 +5942,6 @@ var isEmptyObject$1 = (value) => isObject$1(value) && !Object.keys(value).length
|
|
|
5931
5942
|
|
|
5932
5943
|
var isFileInput = (element) => element.type === 'file';
|
|
5933
5944
|
|
|
5934
|
-
var isFunction$3 = (value) => typeof value === 'function';
|
|
5935
|
-
|
|
5936
5945
|
var isHTMLElement = (value) => {
|
|
5937
5946
|
if (!isWeb) {
|
|
5938
5947
|
return false;
|
|
@@ -6500,6 +6509,7 @@ function createFormControl(props = {}) {
|
|
|
6500
6509
|
action: false,
|
|
6501
6510
|
mount: false,
|
|
6502
6511
|
watch: false,
|
|
6512
|
+
keepIsValid: false,
|
|
6503
6513
|
};
|
|
6504
6514
|
let _names = {
|
|
6505
6515
|
mount: new Set(),
|
|
@@ -6510,7 +6520,7 @@ function createFormControl(props = {}) {
|
|
|
6510
6520
|
};
|
|
6511
6521
|
let delayErrorCallback;
|
|
6512
6522
|
let timer = 0;
|
|
6513
|
-
const
|
|
6523
|
+
const defaultProxyFormState = {
|
|
6514
6524
|
isDirty: false,
|
|
6515
6525
|
dirtyFields: false,
|
|
6516
6526
|
validatingFields: false,
|
|
@@ -6519,6 +6529,9 @@ function createFormControl(props = {}) {
|
|
|
6519
6529
|
isValid: false,
|
|
6520
6530
|
errors: false,
|
|
6521
6531
|
};
|
|
6532
|
+
const _proxyFormState = {
|
|
6533
|
+
...defaultProxyFormState,
|
|
6534
|
+
};
|
|
6522
6535
|
let _proxySubscribeFormState = {
|
|
6523
6536
|
..._proxyFormState,
|
|
6524
6537
|
};
|
|
@@ -6532,13 +6545,21 @@ function createFormControl(props = {}) {
|
|
|
6532
6545
|
timer = setTimeout(callback, wait);
|
|
6533
6546
|
};
|
|
6534
6547
|
const _setValid = async (shouldUpdateValid) => {
|
|
6548
|
+
if (_state.keepIsValid) {
|
|
6549
|
+
return;
|
|
6550
|
+
}
|
|
6535
6551
|
if (!_options.disabled &&
|
|
6536
6552
|
(_proxyFormState.isValid ||
|
|
6537
6553
|
_proxySubscribeFormState.isValid ||
|
|
6538
6554
|
shouldUpdateValid)) {
|
|
6539
|
-
|
|
6540
|
-
|
|
6541
|
-
|
|
6555
|
+
let isValid;
|
|
6556
|
+
if (_options.resolver) {
|
|
6557
|
+
isValid = isEmptyObject$1((await _runSchema()).errors);
|
|
6558
|
+
_updateIsValidating();
|
|
6559
|
+
}
|
|
6560
|
+
else {
|
|
6561
|
+
isValid = await executeBuiltInValidation(_fields, true);
|
|
6562
|
+
}
|
|
6542
6563
|
if (isValid !== _formState.isValid) {
|
|
6543
6564
|
_subjects.state.next({
|
|
6544
6565
|
isValid,
|
|
@@ -6701,11 +6722,11 @@ function createFormControl(props = {}) {
|
|
|
6701
6722
|
const _runSchema = async (name) => {
|
|
6702
6723
|
_updateIsValidating(name, true);
|
|
6703
6724
|
const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
|
|
6704
|
-
_updateIsValidating(name);
|
|
6705
6725
|
return result;
|
|
6706
6726
|
};
|
|
6707
6727
|
const executeSchemaAndUpdateState = async (names) => {
|
|
6708
6728
|
const { errors } = await _runSchema(names);
|
|
6729
|
+
_updateIsValidating(names);
|
|
6709
6730
|
if (names) {
|
|
6710
6731
|
for (const name of names) {
|
|
6711
6732
|
const error = get$1(errors, name);
|
|
@@ -6738,7 +6759,7 @@ function createFormControl(props = {}) {
|
|
|
6738
6759
|
}
|
|
6739
6760
|
if (fieldError[_f.name]) {
|
|
6740
6761
|
context.valid = false;
|
|
6741
|
-
if (shouldOnlyCheckValid) {
|
|
6762
|
+
if (shouldOnlyCheckValid || props.shouldUseNativeValidation) {
|
|
6742
6763
|
break;
|
|
6743
6764
|
}
|
|
6744
6765
|
}
|
|
@@ -6873,11 +6894,19 @@ function createFormControl(props = {}) {
|
|
|
6873
6894
|
? setValues(name, cloneValue, options)
|
|
6874
6895
|
: setFieldValue(name, cloneValue, options);
|
|
6875
6896
|
}
|
|
6876
|
-
isWatched(name, _names)
|
|
6877
|
-
|
|
6878
|
-
|
|
6879
|
-
|
|
6880
|
-
|
|
6897
|
+
if (isWatched(name, _names)) {
|
|
6898
|
+
_subjects.state.next({
|
|
6899
|
+
..._formState,
|
|
6900
|
+
name,
|
|
6901
|
+
values: cloneObject(_formValues),
|
|
6902
|
+
});
|
|
6903
|
+
}
|
|
6904
|
+
else {
|
|
6905
|
+
_subjects.state.next({
|
|
6906
|
+
name: _state.mount ? name : undefined,
|
|
6907
|
+
values: cloneObject(_formValues),
|
|
6908
|
+
});
|
|
6909
|
+
}
|
|
6881
6910
|
};
|
|
6882
6911
|
const onChange = async (event) => {
|
|
6883
6912
|
_state.mount = true;
|
|
@@ -6941,6 +6970,7 @@ function createFormControl(props = {}) {
|
|
|
6941
6970
|
!isBlurEvent && watched && _subjects.state.next({ ..._formState });
|
|
6942
6971
|
if (_options.resolver) {
|
|
6943
6972
|
const { errors } = await _runSchema([name]);
|
|
6973
|
+
_updateIsValidating([name]);
|
|
6944
6974
|
_updateIsFieldValueUpdated(fieldValue);
|
|
6945
6975
|
if (isFieldValueUpdated) {
|
|
6946
6976
|
const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
|
|
@@ -7086,7 +7116,10 @@ function createFormControl(props = {}) {
|
|
|
7086
7116
|
};
|
|
7087
7117
|
return _subscribe({
|
|
7088
7118
|
...props,
|
|
7089
|
-
formState:
|
|
7119
|
+
formState: {
|
|
7120
|
+
...defaultProxyFormState,
|
|
7121
|
+
...props.formState,
|
|
7122
|
+
},
|
|
7090
7123
|
});
|
|
7091
7124
|
};
|
|
7092
7125
|
const unregister = (name, options = {}) => {
|
|
@@ -7119,7 +7152,11 @@ function createFormControl(props = {}) {
|
|
|
7119
7152
|
if ((isBoolean$3(disabled) && _state.mount) ||
|
|
7120
7153
|
!!disabled ||
|
|
7121
7154
|
_names.disabled.has(name)) {
|
|
7155
|
+
const wasDisabled = _names.disabled.has(name);
|
|
7156
|
+
const isDisabled = !!disabled;
|
|
7157
|
+
const disabledStateChanged = wasDisabled !== isDisabled;
|
|
7122
7158
|
disabled ? _names.disabled.add(name) : _names.disabled.delete(name);
|
|
7159
|
+
disabledStateChanged && _state.mount && !_state.action && _setValid();
|
|
7123
7160
|
}
|
|
7124
7161
|
};
|
|
7125
7162
|
const register = (name, options = {}) => {
|
|
@@ -7239,6 +7276,7 @@ function createFormControl(props = {}) {
|
|
|
7239
7276
|
});
|
|
7240
7277
|
if (_options.resolver) {
|
|
7241
7278
|
const { errors, values } = await _runSchema();
|
|
7279
|
+
_updateIsValidating();
|
|
7242
7280
|
_formState.errors = errors;
|
|
7243
7281
|
fieldValues = cloneObject(values);
|
|
7244
7282
|
}
|
|
@@ -7320,9 +7358,15 @@ function createFormControl(props = {}) {
|
|
|
7320
7358
|
...Object.keys(getDirtyFields(_defaultValues, _formValues)),
|
|
7321
7359
|
]);
|
|
7322
7360
|
for (const fieldName of Array.from(fieldsToCheck)) {
|
|
7323
|
-
get$1(_formState.dirtyFields, fieldName)
|
|
7324
|
-
|
|
7325
|
-
|
|
7361
|
+
const isDirty = get$1(_formState.dirtyFields, fieldName);
|
|
7362
|
+
const existingValue = get$1(_formValues, fieldName);
|
|
7363
|
+
const newValue = get$1(values, fieldName);
|
|
7364
|
+
if (isDirty && !isUndefined$1(existingValue)) {
|
|
7365
|
+
set$1(values, fieldName, existingValue);
|
|
7366
|
+
}
|
|
7367
|
+
else if (!isDirty && !isUndefined$1(newValue)) {
|
|
7368
|
+
setValue(fieldName, newValue);
|
|
7369
|
+
}
|
|
7326
7370
|
}
|
|
7327
7371
|
}
|
|
7328
7372
|
else {
|
|
@@ -7379,6 +7423,14 @@ function createFormControl(props = {}) {
|
|
|
7379
7423
|
!!keepStateOptions.keepDirtyValues ||
|
|
7380
7424
|
(!_options.shouldUnregister && !isEmptyObject$1(values));
|
|
7381
7425
|
_state.watch = !!_options.shouldUnregister;
|
|
7426
|
+
_state.keepIsValid = !!keepStateOptions.keepIsValid;
|
|
7427
|
+
_state.action = false;
|
|
7428
|
+
// Clear errors synchronously to prevent validation errors on subsequent submissions
|
|
7429
|
+
// This fixes the issue where form.reset() causes validation errors on subsequent
|
|
7430
|
+
// submissions in Next.js 16 with Server Actions
|
|
7431
|
+
if (!keepStateOptions.keepErrors) {
|
|
7432
|
+
_formState.errors = {};
|
|
7433
|
+
}
|
|
7382
7434
|
_subjects.state.next({
|
|
7383
7435
|
submitCount: keepStateOptions.keepSubmitCount
|
|
7384
7436
|
? _formState.submitCount
|
|
@@ -7416,7 +7468,7 @@ function createFormControl(props = {}) {
|
|
|
7416
7468
|
};
|
|
7417
7469
|
const reset = (formValues, keepStateOptions) => _reset(isFunction$3(formValues)
|
|
7418
7470
|
? formValues(_formValues)
|
|
7419
|
-
: formValues, keepStateOptions);
|
|
7471
|
+
: formValues, { ..._options.resetOptions, ...keepStateOptions });
|
|
7420
7472
|
const setFocus = (name, options = {}) => {
|
|
7421
7473
|
const field = get$1(_fields, name);
|
|
7422
7474
|
const fieldReference = field && field._f;
|
|
@@ -7425,10 +7477,14 @@ function createFormControl(props = {}) {
|
|
|
7425
7477
|
? fieldReference.refs[0]
|
|
7426
7478
|
: fieldReference.ref;
|
|
7427
7479
|
if (fieldRef.focus) {
|
|
7428
|
-
|
|
7429
|
-
|
|
7430
|
-
|
|
7431
|
-
fieldRef.
|
|
7480
|
+
// Use setTimeout to ensure focus happens after any pending state updates
|
|
7481
|
+
// This fixes the issue where setFocus doesn't work immediately after setError
|
|
7482
|
+
setTimeout(() => {
|
|
7483
|
+
fieldRef.focus();
|
|
7484
|
+
options.shouldSelect &&
|
|
7485
|
+
isFunction$3(fieldRef.select) &&
|
|
7486
|
+
fieldRef.select();
|
|
7487
|
+
});
|
|
7432
7488
|
}
|
|
7433
7489
|
}
|
|
7434
7490
|
};
|
|
@@ -7454,6 +7510,7 @@ function createFormControl(props = {}) {
|
|
|
7454
7510
|
setError,
|
|
7455
7511
|
_subscribe,
|
|
7456
7512
|
_runSchema,
|
|
7513
|
+
_updateIsValidating,
|
|
7457
7514
|
_focusError,
|
|
7458
7515
|
_getWatch,
|
|
7459
7516
|
_getDirty,
|
|
@@ -7666,7 +7723,7 @@ function useForm(props = {}) {
|
|
|
7666
7723
|
}
|
|
7667
7724
|
control._removeUnmounted();
|
|
7668
7725
|
});
|
|
7669
|
-
_formControl.current.formState = getProxyFormState(formState, control);
|
|
7726
|
+
_formControl.current.formState = React.useMemo(() => getProxyFormState(formState, control), [control, formState]);
|
|
7670
7727
|
return _formControl.current;
|
|
7671
7728
|
}
|
|
7672
7729
|
|
|
@@ -18721,6 +18778,10 @@ var isSet = (target) => target instanceof Set;
|
|
|
18721
18778
|
var isObjectish = (target) => typeof target === "object";
|
|
18722
18779
|
var isFunction$2 = (target) => typeof target === "function";
|
|
18723
18780
|
var isBoolean$2 = (target) => typeof target === "boolean";
|
|
18781
|
+
function isArrayIndex(value) {
|
|
18782
|
+
const n = +value;
|
|
18783
|
+
return Number.isInteger(n) && String(n) === value;
|
|
18784
|
+
}
|
|
18724
18785
|
var latest = (state) => state.copy_ || state.base_;
|
|
18725
18786
|
var getFinalValue = (state) => state.modified_ ? state.copy_ : state.base_;
|
|
18726
18787
|
function shallowCopy(base, strict) {
|
|
@@ -18800,6 +18861,7 @@ function isFrozen(obj) {
|
|
|
18800
18861
|
// src/utils/plugins.ts
|
|
18801
18862
|
var PluginMapSet = "MapSet";
|
|
18802
18863
|
var PluginPatches = "Patches";
|
|
18864
|
+
var PluginArrayMethods = "ArrayMethods";
|
|
18803
18865
|
var plugins = {};
|
|
18804
18866
|
function getPlugin(pluginKey) {
|
|
18805
18867
|
const plugin = plugins[pluginKey];
|
|
@@ -18823,7 +18885,8 @@ var createScope = (parent_, immer_) => ({
|
|
|
18823
18885
|
unfinalizedDrafts_: 0,
|
|
18824
18886
|
handledSet_: /* @__PURE__ */ new Set(),
|
|
18825
18887
|
processedForPatches_: /* @__PURE__ */ new Set(),
|
|
18826
|
-
mapSetPlugin_: isPluginLoaded(PluginMapSet) ? getPlugin(PluginMapSet) : void 0
|
|
18888
|
+
mapSetPlugin_: isPluginLoaded(PluginMapSet) ? getPlugin(PluginMapSet) : void 0,
|
|
18889
|
+
arrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods) ? getPlugin(PluginArrayMethods) : void 0
|
|
18827
18890
|
});
|
|
18828
18891
|
function usePatchesInScope(scope, patchListener) {
|
|
18829
18892
|
if (patchListener) {
|
|
@@ -18958,7 +19021,7 @@ function registerChildFinalizationCallback(parent, child, key) {
|
|
|
18958
19021
|
});
|
|
18959
19022
|
}
|
|
18960
19023
|
function generatePatchesAndFinalize(state, rootScope) {
|
|
18961
|
-
const shouldFinalize = state.modified_ && !state.finalized_ && (state.type_ === 3 /* Set */ || (state.assigned_?.size ?? 0) > 0);
|
|
19024
|
+
const shouldFinalize = state.modified_ && !state.finalized_ && (state.type_ === 3 /* Set */ || state.type_ === 1 /* Array */ && state.allIndicesReassigned_ || (state.assigned_?.size ?? 0) > 0);
|
|
18962
19025
|
if (shouldFinalize) {
|
|
18963
19026
|
const { patchPlugin_ } = rootScope;
|
|
18964
19027
|
if (patchPlugin_) {
|
|
@@ -18984,13 +19047,19 @@ function handleCrossReference(target, key, value) {
|
|
|
18984
19047
|
} else if (isDraftable(value)) {
|
|
18985
19048
|
target.callbacks_.push(function nestedDraftCleanup() {
|
|
18986
19049
|
const targetCopy = latest(target);
|
|
18987
|
-
if (
|
|
18988
|
-
if (
|
|
18989
|
-
handleValue(
|
|
18990
|
-
|
|
18991
|
-
|
|
18992
|
-
|
|
18993
|
-
)
|
|
19050
|
+
if (target.type_ === 3 /* Set */) {
|
|
19051
|
+
if (targetCopy.has(value)) {
|
|
19052
|
+
handleValue(value, scope_.handledSet_, scope_);
|
|
19053
|
+
}
|
|
19054
|
+
} else {
|
|
19055
|
+
if (get(targetCopy, key, target.type_) === value) {
|
|
19056
|
+
if (scope_.drafts_.length > 1 && (target.assigned_.get(key) ?? false) === true && target.copy_) {
|
|
19057
|
+
handleValue(
|
|
19058
|
+
get(target.copy_, key, target.type_),
|
|
19059
|
+
scope_.handledSet_,
|
|
19060
|
+
scope_
|
|
19061
|
+
);
|
|
19062
|
+
}
|
|
18994
19063
|
}
|
|
18995
19064
|
}
|
|
18996
19065
|
});
|
|
@@ -19063,6 +19132,13 @@ var objectTraps = {
|
|
|
19063
19132
|
get(state, prop) {
|
|
19064
19133
|
if (prop === DRAFT_STATE)
|
|
19065
19134
|
return state;
|
|
19135
|
+
let arrayPlugin = state.scope_.arrayMethodsPlugin_;
|
|
19136
|
+
const isArrayWithStringProp = state.type_ === 1 /* Array */ && typeof prop === "string";
|
|
19137
|
+
if (isArrayWithStringProp) {
|
|
19138
|
+
if (arrayPlugin?.isArrayOperationMethod(prop)) {
|
|
19139
|
+
return arrayPlugin.createMethodInterceptor(state, prop);
|
|
19140
|
+
}
|
|
19141
|
+
}
|
|
19066
19142
|
const source = latest(state);
|
|
19067
19143
|
if (!has(source, prop, state.type_)) {
|
|
19068
19144
|
return readPropFromProto(state, source, prop);
|
|
@@ -19071,6 +19147,11 @@ var objectTraps = {
|
|
|
19071
19147
|
if (state.finalized_ || !isDraftable(value)) {
|
|
19072
19148
|
return value;
|
|
19073
19149
|
}
|
|
19150
|
+
if (isArrayWithStringProp && state.operationMethod && arrayPlugin?.isMutatingArrayMethod(
|
|
19151
|
+
state.operationMethod
|
|
19152
|
+
) && isArrayIndex(prop)) {
|
|
19153
|
+
return value;
|
|
19154
|
+
}
|
|
19074
19155
|
if (value === peek(state.base_, prop)) {
|
|
19075
19156
|
prepareCopy(state);
|
|
19076
19157
|
const childKey = state.type_ === 1 /* Array */ ? +prop : prop;
|
|
@@ -19151,13 +19232,14 @@ var objectTraps = {
|
|
|
19151
19232
|
}
|
|
19152
19233
|
};
|
|
19153
19234
|
var arrayTraps = {};
|
|
19154
|
-
|
|
19235
|
+
for (let key in objectTraps) {
|
|
19236
|
+
let fn = objectTraps[key];
|
|
19155
19237
|
arrayTraps[key] = function() {
|
|
19156
19238
|
const args = arguments;
|
|
19157
19239
|
args[0] = args[0][0];
|
|
19158
19240
|
return fn.apply(this, args);
|
|
19159
19241
|
};
|
|
19160
|
-
}
|
|
19242
|
+
}
|
|
19161
19243
|
arrayTraps.deleteProperty = function(state, prop) {
|
|
19162
19244
|
if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
|
|
19163
19245
|
die(13);
|
|
@@ -20461,29 +20543,11 @@ var addAbortSignalListener = (abortSignal, callback) => {
|
|
|
20461
20543
|
});
|
|
20462
20544
|
return () => abortSignal.removeEventListener("abort", callback);
|
|
20463
20545
|
};
|
|
20464
|
-
var abortControllerWithReason = (abortController, reason) => {
|
|
20465
|
-
const signal = abortController.signal;
|
|
20466
|
-
if (signal.aborted) {
|
|
20467
|
-
return;
|
|
20468
|
-
}
|
|
20469
|
-
if (!("reason" in signal)) {
|
|
20470
|
-
Object.defineProperty(signal, "reason", {
|
|
20471
|
-
enumerable: true,
|
|
20472
|
-
value: reason,
|
|
20473
|
-
configurable: true,
|
|
20474
|
-
writable: true
|
|
20475
|
-
});
|
|
20476
|
-
}
|
|
20477
|
-
abortController.abort(reason);
|
|
20478
|
-
};
|
|
20479
20546
|
|
|
20480
20547
|
// src/listenerMiddleware/task.ts
|
|
20481
20548
|
var validateActive = (signal) => {
|
|
20482
20549
|
if (signal.aborted) {
|
|
20483
|
-
|
|
20484
|
-
reason
|
|
20485
|
-
} = signal;
|
|
20486
|
-
throw new TaskAbortError(reason);
|
|
20550
|
+
throw new TaskAbortError(signal.reason);
|
|
20487
20551
|
}
|
|
20488
20552
|
};
|
|
20489
20553
|
function raceWithSignal(signal, promise) {
|
|
@@ -20539,7 +20603,7 @@ var {
|
|
|
20539
20603
|
var INTERNAL_NIL_TOKEN = {};
|
|
20540
20604
|
var alm = "listenerMiddleware";
|
|
20541
20605
|
var createFork = (parentAbortSignal, parentBlockingPromises) => {
|
|
20542
|
-
const linkControllers = (controller) => addAbortSignalListener(parentAbortSignal, () =>
|
|
20606
|
+
const linkControllers = (controller) => addAbortSignalListener(parentAbortSignal, () => controller.abort(parentAbortSignal.reason));
|
|
20543
20607
|
return (taskExecutor, opts) => {
|
|
20544
20608
|
assertFunction(taskExecutor, "taskExecutor");
|
|
20545
20609
|
const childAbortController = new AbortController();
|
|
@@ -20554,14 +20618,14 @@ var createFork = (parentAbortSignal, parentBlockingPromises) => {
|
|
|
20554
20618
|
});
|
|
20555
20619
|
validateActive(childAbortController.signal);
|
|
20556
20620
|
return result2;
|
|
20557
|
-
}, () =>
|
|
20621
|
+
}, () => childAbortController.abort(taskCompleted));
|
|
20558
20622
|
if (opts?.autoJoin) {
|
|
20559
20623
|
parentBlockingPromises.push(result.catch(noop2));
|
|
20560
20624
|
}
|
|
20561
20625
|
return {
|
|
20562
20626
|
result: createPause(parentAbortSignal)(result),
|
|
20563
20627
|
cancel() {
|
|
20564
|
-
|
|
20628
|
+
childAbortController.abort(taskCancelled);
|
|
20565
20629
|
}
|
|
20566
20630
|
};
|
|
20567
20631
|
};
|
|
@@ -20656,7 +20720,7 @@ var findListenerEntry = (listenerMap, options) => {
|
|
|
20656
20720
|
};
|
|
20657
20721
|
var cancelActiveListeners = (entry) => {
|
|
20658
20722
|
entry.pending.forEach((controller) => {
|
|
20659
|
-
|
|
20723
|
+
controller.abort(listenerCancelled);
|
|
20660
20724
|
});
|
|
20661
20725
|
};
|
|
20662
20726
|
var createClearListenerMiddleware = (listenerMap, executingListeners) => {
|
|
@@ -20762,13 +20826,13 @@ var createListenerMiddleware = (middlewareOptions = {}) => {
|
|
|
20762
20826
|
cancelActiveListeners: () => {
|
|
20763
20827
|
entry.pending.forEach((controller, _, set) => {
|
|
20764
20828
|
if (controller !== internalTaskController) {
|
|
20765
|
-
|
|
20829
|
+
controller.abort(listenerCancelled);
|
|
20766
20830
|
set.delete(controller);
|
|
20767
20831
|
}
|
|
20768
20832
|
});
|
|
20769
20833
|
},
|
|
20770
20834
|
cancel: () => {
|
|
20771
|
-
|
|
20835
|
+
internalTaskController.abort(listenerCancelled);
|
|
20772
20836
|
entry.pending.delete(internalTaskController);
|
|
20773
20837
|
},
|
|
20774
20838
|
throwIfCancelled: () => {
|
|
@@ -20784,7 +20848,7 @@ var createListenerMiddleware = (middlewareOptions = {}) => {
|
|
|
20784
20848
|
}
|
|
20785
20849
|
} finally {
|
|
20786
20850
|
await Promise.all(autoJoinPromises);
|
|
20787
|
-
|
|
20851
|
+
internalTaskController.abort(listenerCompleted);
|
|
20788
20852
|
untrackExecutingListener(entry);
|
|
20789
20853
|
entry.pending.delete(internalTaskController);
|
|
20790
20854
|
}
|