@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.esm.js
CHANGED
|
@@ -5264,29 +5264,23 @@ var isWeb = typeof window !== 'undefined' &&
|
|
|
5264
5264
|
typeof document !== 'undefined';
|
|
5265
5265
|
|
|
5266
5266
|
function cloneObject(data) {
|
|
5267
|
-
let copy;
|
|
5268
|
-
const isArray = Array.isArray(data);
|
|
5269
|
-
const isFileListInstance = typeof FileList !== 'undefined' ? data instanceof FileList : false;
|
|
5270
5267
|
if (data instanceof Date) {
|
|
5271
|
-
|
|
5268
|
+
return new Date(data);
|
|
5272
5269
|
}
|
|
5273
|
-
|
|
5274
|
-
|
|
5275
|
-
|
|
5276
|
-
if (!isArray && !isPlainObject$3(data)) {
|
|
5277
|
-
copy = data;
|
|
5278
|
-
}
|
|
5279
|
-
else {
|
|
5280
|
-
for (const key in data) {
|
|
5281
|
-
if (data.hasOwnProperty(key)) {
|
|
5282
|
-
copy[key] = cloneObject(data[key]);
|
|
5283
|
-
}
|
|
5284
|
-
}
|
|
5285
|
-
}
|
|
5270
|
+
const isFileListInstance = typeof FileList !== 'undefined' && data instanceof FileList;
|
|
5271
|
+
if (isWeb && (data instanceof Blob || isFileListInstance)) {
|
|
5272
|
+
return data;
|
|
5286
5273
|
}
|
|
5287
|
-
|
|
5274
|
+
const isArray = Array.isArray(data);
|
|
5275
|
+
if (!isArray && !(isObject$1(data) && isPlainObject$3(data))) {
|
|
5288
5276
|
return data;
|
|
5289
5277
|
}
|
|
5278
|
+
const copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
|
|
5279
|
+
for (const key in data) {
|
|
5280
|
+
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
5281
|
+
copy[key] = cloneObject(data[key]);
|
|
5282
|
+
}
|
|
5283
|
+
}
|
|
5290
5284
|
return copy;
|
|
5291
5285
|
}
|
|
5292
5286
|
|
|
@@ -5312,6 +5306,8 @@ var get$1 = (object, path, defaultValue) => {
|
|
|
5312
5306
|
|
|
5313
5307
|
var isBoolean$3 = (value) => typeof value === 'boolean';
|
|
5314
5308
|
|
|
5309
|
+
var isFunction$3 = (value) => typeof value === 'function';
|
|
5310
|
+
|
|
5315
5311
|
var set$1 = (object, path, value) => {
|
|
5316
5312
|
let index = -1;
|
|
5317
5313
|
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
@@ -5359,73 +5355,16 @@ const INPUT_VALIDATION_RULES = {
|
|
|
5359
5355
|
validate: 'validate',
|
|
5360
5356
|
};
|
|
5361
5357
|
|
|
5362
|
-
const HookFormContext = React__default.createContext(null);
|
|
5363
|
-
HookFormContext.displayName = 'HookFormContext';
|
|
5364
5358
|
/**
|
|
5365
|
-
*
|
|
5366
|
-
*
|
|
5367
|
-
* @remarks
|
|
5368
|
-
* [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
|
5369
|
-
*
|
|
5370
|
-
* @returns return all useForm methods
|
|
5371
|
-
*
|
|
5372
|
-
* @example
|
|
5373
|
-
* ```tsx
|
|
5374
|
-
* function App() {
|
|
5375
|
-
* const methods = useForm();
|
|
5376
|
-
* const onSubmit = data => console.log(data);
|
|
5377
|
-
*
|
|
5378
|
-
* return (
|
|
5379
|
-
* <FormProvider {...methods} >
|
|
5380
|
-
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
5381
|
-
* <NestedInput />
|
|
5382
|
-
* <input type="submit" />
|
|
5383
|
-
* </form>
|
|
5384
|
-
* </FormProvider>
|
|
5385
|
-
* );
|
|
5386
|
-
* }
|
|
5387
|
-
*
|
|
5388
|
-
* function NestedInput() {
|
|
5389
|
-
* const { register } = useFormContext(); // retrieve all hook methods
|
|
5390
|
-
* return <input {...register("test")} />;
|
|
5391
|
-
* }
|
|
5392
|
-
* ```
|
|
5359
|
+
* Separate context for `control` to prevent unnecessary rerenders.
|
|
5360
|
+
* Internal hooks that only need control use this instead of full form context.
|
|
5393
5361
|
*/
|
|
5394
|
-
const
|
|
5362
|
+
const HookFormControlContext = React__default.createContext(null);
|
|
5363
|
+
HookFormControlContext.displayName = 'HookFormControlContext';
|
|
5395
5364
|
/**
|
|
5396
|
-
*
|
|
5397
|
-
*
|
|
5398
|
-
* @remarks
|
|
5399
|
-
* [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
|
5400
|
-
*
|
|
5401
|
-
* @param props - all useForm methods
|
|
5402
|
-
*
|
|
5403
|
-
* @example
|
|
5404
|
-
* ```tsx
|
|
5405
|
-
* function App() {
|
|
5406
|
-
* const methods = useForm();
|
|
5407
|
-
* const onSubmit = data => console.log(data);
|
|
5408
|
-
*
|
|
5409
|
-
* return (
|
|
5410
|
-
* <FormProvider {...methods} >
|
|
5411
|
-
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
5412
|
-
* <NestedInput />
|
|
5413
|
-
* <input type="submit" />
|
|
5414
|
-
* </form>
|
|
5415
|
-
* </FormProvider>
|
|
5416
|
-
* );
|
|
5417
|
-
* }
|
|
5418
|
-
*
|
|
5419
|
-
* function NestedInput() {
|
|
5420
|
-
* const { register } = useFormContext(); // retrieve all hook methods
|
|
5421
|
-
* return <input {...register("test")} />;
|
|
5422
|
-
* }
|
|
5423
|
-
* ```
|
|
5365
|
+
* @internal Internal hook to access only control from context.
|
|
5424
5366
|
*/
|
|
5425
|
-
const
|
|
5426
|
-
const { children, ...data } = props;
|
|
5427
|
-
return (React__default.createElement(HookFormContext.Provider, { value: data }, children));
|
|
5428
|
-
};
|
|
5367
|
+
const useFormControlContext = () => React__default.useContext(HookFormControlContext);
|
|
5429
5368
|
|
|
5430
5369
|
var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
|
|
5431
5370
|
const result = {
|
|
@@ -5479,8 +5418,8 @@ const useIsomorphicLayoutEffect$1 = typeof window !== 'undefined' ? React__defau
|
|
|
5479
5418
|
* ```
|
|
5480
5419
|
*/
|
|
5481
5420
|
function useFormState(props) {
|
|
5482
|
-
const
|
|
5483
|
-
const { control =
|
|
5421
|
+
const formControl = useFormControlContext();
|
|
5422
|
+
const { control = formControl, disabled, name, exact } = props || {};
|
|
5484
5423
|
const [formState, updateFormState] = React__default.useState(control._formState);
|
|
5485
5424
|
const _localProxyFormState = React__default.useRef({
|
|
5486
5425
|
isDirty: false,
|
|
@@ -5532,7 +5471,7 @@ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
|
5532
5471
|
return Object.is(object1, object2);
|
|
5533
5472
|
}
|
|
5534
5473
|
if (isDateObject(object1) && isDateObject(object2)) {
|
|
5535
|
-
return object1.getTime()
|
|
5474
|
+
return Object.is(object1.getTime(), object2.getTime());
|
|
5536
5475
|
}
|
|
5537
5476
|
const keys1 = Object.keys(object1);
|
|
5538
5477
|
const keys2 = Object.keys(object2);
|
|
@@ -5580,8 +5519,8 @@ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
|
5580
5519
|
* ```
|
|
5581
5520
|
*/
|
|
5582
5521
|
function useWatch(props) {
|
|
5583
|
-
const
|
|
5584
|
-
const { control =
|
|
5522
|
+
const formControl = useFormControlContext();
|
|
5523
|
+
const { control = formControl, name, defaultValue, disabled, exact, compute, } = props || {};
|
|
5585
5524
|
const _defaultValue = React__default.useRef(defaultValue);
|
|
5586
5525
|
const _compute = React__default.useRef(compute);
|
|
5587
5526
|
const _computeFormValues = React__default.useRef(undefined);
|
|
@@ -5674,8 +5613,8 @@ function useWatch(props) {
|
|
|
5674
5613
|
* ```
|
|
5675
5614
|
*/
|
|
5676
5615
|
function useController(props) {
|
|
5677
|
-
const
|
|
5678
|
-
const { name, disabled, control =
|
|
5616
|
+
const formControl = useFormControlContext();
|
|
5617
|
+
const { name, disabled, control = formControl, shouldUnregister, defaultValue, exact = true, } = props;
|
|
5679
5618
|
const isArrayField = isNameInFieldArray(control._names.array, name);
|
|
5680
5619
|
const defaultValueMemo = React__default.useMemo(() => get$1(control._formValues, name, get$1(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
|
|
5681
5620
|
const value = useWatch({
|
|
@@ -5735,12 +5674,12 @@ function useController(props) {
|
|
|
5735
5674
|
}), [name, control._formValues]);
|
|
5736
5675
|
const ref = React__default.useCallback((elm) => {
|
|
5737
5676
|
const field = get$1(control._fields, name);
|
|
5738
|
-
if (field && elm) {
|
|
5677
|
+
if (field && field._f && elm) {
|
|
5739
5678
|
field._f.ref = {
|
|
5740
|
-
focus: () => elm.focus && elm.focus(),
|
|
5741
|
-
select: () => elm.select && elm.select(),
|
|
5742
|
-
setCustomValidity: (message) => elm.setCustomValidity(message),
|
|
5743
|
-
reportValidity: () => elm.reportValidity(),
|
|
5679
|
+
focus: () => isFunction$3(elm.focus) && elm.focus(),
|
|
5680
|
+
select: () => isFunction$3(elm.select) && elm.select(),
|
|
5681
|
+
setCustomValidity: (message) => isFunction$3(elm.setCustomValidity) && elm.setCustomValidity(message),
|
|
5682
|
+
reportValidity: () => isFunction$3(elm.reportValidity) && elm.reportValidity(),
|
|
5744
5683
|
};
|
|
5745
5684
|
}
|
|
5746
5685
|
}, [control._fields, name]);
|
|
@@ -5847,6 +5786,78 @@ function useController(props) {
|
|
|
5847
5786
|
*/
|
|
5848
5787
|
const Controller = (props) => props.render(useController(props));
|
|
5849
5788
|
|
|
5789
|
+
const HookFormContext = React__default.createContext(null);
|
|
5790
|
+
HookFormContext.displayName = 'HookFormContext';
|
|
5791
|
+
/**
|
|
5792
|
+
* 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}.
|
|
5793
|
+
*
|
|
5794
|
+
* @remarks
|
|
5795
|
+
* [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
|
5796
|
+
*
|
|
5797
|
+
* @param props - all useForm methods
|
|
5798
|
+
*
|
|
5799
|
+
* @example
|
|
5800
|
+
* ```tsx
|
|
5801
|
+
* function App() {
|
|
5802
|
+
* const methods = useForm();
|
|
5803
|
+
* const onSubmit = data => console.log(data);
|
|
5804
|
+
*
|
|
5805
|
+
* return (
|
|
5806
|
+
* <FormProvider {...methods} >
|
|
5807
|
+
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
5808
|
+
* <NestedInput />
|
|
5809
|
+
* <input type="submit" />
|
|
5810
|
+
* </form>
|
|
5811
|
+
* </FormProvider>
|
|
5812
|
+
* );
|
|
5813
|
+
* }
|
|
5814
|
+
*
|
|
5815
|
+
* function NestedInput() {
|
|
5816
|
+
* const { register } = useFormContext(); // retrieve all hook methods
|
|
5817
|
+
* return <input {...register("test")} />;
|
|
5818
|
+
* }
|
|
5819
|
+
* ```
|
|
5820
|
+
*/
|
|
5821
|
+
const FormProvider = (props) => {
|
|
5822
|
+
const { children, watch, getValues, getFieldState, setError, clearErrors, setValue, trigger, formState, resetField, reset, handleSubmit, unregister, control, register, setFocus, subscribe, } = props;
|
|
5823
|
+
return (React__default.createElement(HookFormContext.Provider, { value: React__default.useMemo(() => ({
|
|
5824
|
+
watch,
|
|
5825
|
+
getValues,
|
|
5826
|
+
getFieldState,
|
|
5827
|
+
setError,
|
|
5828
|
+
clearErrors,
|
|
5829
|
+
setValue,
|
|
5830
|
+
trigger,
|
|
5831
|
+
formState,
|
|
5832
|
+
resetField,
|
|
5833
|
+
reset,
|
|
5834
|
+
handleSubmit,
|
|
5835
|
+
unregister,
|
|
5836
|
+
control,
|
|
5837
|
+
register,
|
|
5838
|
+
setFocus,
|
|
5839
|
+
subscribe,
|
|
5840
|
+
}), [
|
|
5841
|
+
clearErrors,
|
|
5842
|
+
control,
|
|
5843
|
+
formState,
|
|
5844
|
+
getFieldState,
|
|
5845
|
+
getValues,
|
|
5846
|
+
handleSubmit,
|
|
5847
|
+
register,
|
|
5848
|
+
reset,
|
|
5849
|
+
resetField,
|
|
5850
|
+
setError,
|
|
5851
|
+
setFocus,
|
|
5852
|
+
setValue,
|
|
5853
|
+
subscribe,
|
|
5854
|
+
trigger,
|
|
5855
|
+
unregister,
|
|
5856
|
+
watch,
|
|
5857
|
+
]) },
|
|
5858
|
+
React__default.createElement(HookFormControlContext.Provider, { value: control }, children)));
|
|
5859
|
+
};
|
|
5860
|
+
|
|
5850
5861
|
var appendErrors = (name, validateAllFieldCriteria, errors, type, message) => validateAllFieldCriteria
|
|
5851
5862
|
? {
|
|
5852
5863
|
...errors[name],
|
|
@@ -5911,8 +5922,6 @@ var isEmptyObject$1 = (value) => isObject$1(value) && !Object.keys(value).length
|
|
|
5911
5922
|
|
|
5912
5923
|
var isFileInput = (element) => element.type === 'file';
|
|
5913
5924
|
|
|
5914
|
-
var isFunction$3 = (value) => typeof value === 'function';
|
|
5915
|
-
|
|
5916
5925
|
var isHTMLElement = (value) => {
|
|
5917
5926
|
if (!isWeb) {
|
|
5918
5927
|
return false;
|
|
@@ -6480,6 +6489,7 @@ function createFormControl(props = {}) {
|
|
|
6480
6489
|
action: false,
|
|
6481
6490
|
mount: false,
|
|
6482
6491
|
watch: false,
|
|
6492
|
+
keepIsValid: false,
|
|
6483
6493
|
};
|
|
6484
6494
|
let _names = {
|
|
6485
6495
|
mount: new Set(),
|
|
@@ -6490,7 +6500,7 @@ function createFormControl(props = {}) {
|
|
|
6490
6500
|
};
|
|
6491
6501
|
let delayErrorCallback;
|
|
6492
6502
|
let timer = 0;
|
|
6493
|
-
const
|
|
6503
|
+
const defaultProxyFormState = {
|
|
6494
6504
|
isDirty: false,
|
|
6495
6505
|
dirtyFields: false,
|
|
6496
6506
|
validatingFields: false,
|
|
@@ -6499,6 +6509,9 @@ function createFormControl(props = {}) {
|
|
|
6499
6509
|
isValid: false,
|
|
6500
6510
|
errors: false,
|
|
6501
6511
|
};
|
|
6512
|
+
const _proxyFormState = {
|
|
6513
|
+
...defaultProxyFormState,
|
|
6514
|
+
};
|
|
6502
6515
|
let _proxySubscribeFormState = {
|
|
6503
6516
|
..._proxyFormState,
|
|
6504
6517
|
};
|
|
@@ -6512,13 +6525,21 @@ function createFormControl(props = {}) {
|
|
|
6512
6525
|
timer = setTimeout(callback, wait);
|
|
6513
6526
|
};
|
|
6514
6527
|
const _setValid = async (shouldUpdateValid) => {
|
|
6528
|
+
if (_state.keepIsValid) {
|
|
6529
|
+
return;
|
|
6530
|
+
}
|
|
6515
6531
|
if (!_options.disabled &&
|
|
6516
6532
|
(_proxyFormState.isValid ||
|
|
6517
6533
|
_proxySubscribeFormState.isValid ||
|
|
6518
6534
|
shouldUpdateValid)) {
|
|
6519
|
-
|
|
6520
|
-
|
|
6521
|
-
|
|
6535
|
+
let isValid;
|
|
6536
|
+
if (_options.resolver) {
|
|
6537
|
+
isValid = isEmptyObject$1((await _runSchema()).errors);
|
|
6538
|
+
_updateIsValidating();
|
|
6539
|
+
}
|
|
6540
|
+
else {
|
|
6541
|
+
isValid = await executeBuiltInValidation(_fields, true);
|
|
6542
|
+
}
|
|
6522
6543
|
if (isValid !== _formState.isValid) {
|
|
6523
6544
|
_subjects.state.next({
|
|
6524
6545
|
isValid,
|
|
@@ -6681,11 +6702,11 @@ function createFormControl(props = {}) {
|
|
|
6681
6702
|
const _runSchema = async (name) => {
|
|
6682
6703
|
_updateIsValidating(name, true);
|
|
6683
6704
|
const result = await _options.resolver(_formValues, _options.context, getResolverOptions(name || _names.mount, _fields, _options.criteriaMode, _options.shouldUseNativeValidation));
|
|
6684
|
-
_updateIsValidating(name);
|
|
6685
6705
|
return result;
|
|
6686
6706
|
};
|
|
6687
6707
|
const executeSchemaAndUpdateState = async (names) => {
|
|
6688
6708
|
const { errors } = await _runSchema(names);
|
|
6709
|
+
_updateIsValidating(names);
|
|
6689
6710
|
if (names) {
|
|
6690
6711
|
for (const name of names) {
|
|
6691
6712
|
const error = get$1(errors, name);
|
|
@@ -6718,7 +6739,7 @@ function createFormControl(props = {}) {
|
|
|
6718
6739
|
}
|
|
6719
6740
|
if (fieldError[_f.name]) {
|
|
6720
6741
|
context.valid = false;
|
|
6721
|
-
if (shouldOnlyCheckValid) {
|
|
6742
|
+
if (shouldOnlyCheckValid || props.shouldUseNativeValidation) {
|
|
6722
6743
|
break;
|
|
6723
6744
|
}
|
|
6724
6745
|
}
|
|
@@ -6853,11 +6874,19 @@ function createFormControl(props = {}) {
|
|
|
6853
6874
|
? setValues(name, cloneValue, options)
|
|
6854
6875
|
: setFieldValue(name, cloneValue, options);
|
|
6855
6876
|
}
|
|
6856
|
-
isWatched(name, _names)
|
|
6857
|
-
|
|
6858
|
-
|
|
6859
|
-
|
|
6860
|
-
|
|
6877
|
+
if (isWatched(name, _names)) {
|
|
6878
|
+
_subjects.state.next({
|
|
6879
|
+
..._formState,
|
|
6880
|
+
name,
|
|
6881
|
+
values: cloneObject(_formValues),
|
|
6882
|
+
});
|
|
6883
|
+
}
|
|
6884
|
+
else {
|
|
6885
|
+
_subjects.state.next({
|
|
6886
|
+
name: _state.mount ? name : undefined,
|
|
6887
|
+
values: cloneObject(_formValues),
|
|
6888
|
+
});
|
|
6889
|
+
}
|
|
6861
6890
|
};
|
|
6862
6891
|
const onChange = async (event) => {
|
|
6863
6892
|
_state.mount = true;
|
|
@@ -6921,6 +6950,7 @@ function createFormControl(props = {}) {
|
|
|
6921
6950
|
!isBlurEvent && watched && _subjects.state.next({ ..._formState });
|
|
6922
6951
|
if (_options.resolver) {
|
|
6923
6952
|
const { errors } = await _runSchema([name]);
|
|
6953
|
+
_updateIsValidating([name]);
|
|
6924
6954
|
_updateIsFieldValueUpdated(fieldValue);
|
|
6925
6955
|
if (isFieldValueUpdated) {
|
|
6926
6956
|
const previousErrorLookupResult = schemaErrorLookup(_formState.errors, _fields, name);
|
|
@@ -7066,7 +7096,10 @@ function createFormControl(props = {}) {
|
|
|
7066
7096
|
};
|
|
7067
7097
|
return _subscribe({
|
|
7068
7098
|
...props,
|
|
7069
|
-
formState:
|
|
7099
|
+
formState: {
|
|
7100
|
+
...defaultProxyFormState,
|
|
7101
|
+
...props.formState,
|
|
7102
|
+
},
|
|
7070
7103
|
});
|
|
7071
7104
|
};
|
|
7072
7105
|
const unregister = (name, options = {}) => {
|
|
@@ -7099,7 +7132,11 @@ function createFormControl(props = {}) {
|
|
|
7099
7132
|
if ((isBoolean$3(disabled) && _state.mount) ||
|
|
7100
7133
|
!!disabled ||
|
|
7101
7134
|
_names.disabled.has(name)) {
|
|
7135
|
+
const wasDisabled = _names.disabled.has(name);
|
|
7136
|
+
const isDisabled = !!disabled;
|
|
7137
|
+
const disabledStateChanged = wasDisabled !== isDisabled;
|
|
7102
7138
|
disabled ? _names.disabled.add(name) : _names.disabled.delete(name);
|
|
7139
|
+
disabledStateChanged && _state.mount && !_state.action && _setValid();
|
|
7103
7140
|
}
|
|
7104
7141
|
};
|
|
7105
7142
|
const register = (name, options = {}) => {
|
|
@@ -7219,6 +7256,7 @@ function createFormControl(props = {}) {
|
|
|
7219
7256
|
});
|
|
7220
7257
|
if (_options.resolver) {
|
|
7221
7258
|
const { errors, values } = await _runSchema();
|
|
7259
|
+
_updateIsValidating();
|
|
7222
7260
|
_formState.errors = errors;
|
|
7223
7261
|
fieldValues = cloneObject(values);
|
|
7224
7262
|
}
|
|
@@ -7300,9 +7338,15 @@ function createFormControl(props = {}) {
|
|
|
7300
7338
|
...Object.keys(getDirtyFields(_defaultValues, _formValues)),
|
|
7301
7339
|
]);
|
|
7302
7340
|
for (const fieldName of Array.from(fieldsToCheck)) {
|
|
7303
|
-
get$1(_formState.dirtyFields, fieldName)
|
|
7304
|
-
|
|
7305
|
-
|
|
7341
|
+
const isDirty = get$1(_formState.dirtyFields, fieldName);
|
|
7342
|
+
const existingValue = get$1(_formValues, fieldName);
|
|
7343
|
+
const newValue = get$1(values, fieldName);
|
|
7344
|
+
if (isDirty && !isUndefined$1(existingValue)) {
|
|
7345
|
+
set$1(values, fieldName, existingValue);
|
|
7346
|
+
}
|
|
7347
|
+
else if (!isDirty && !isUndefined$1(newValue)) {
|
|
7348
|
+
setValue(fieldName, newValue);
|
|
7349
|
+
}
|
|
7306
7350
|
}
|
|
7307
7351
|
}
|
|
7308
7352
|
else {
|
|
@@ -7359,6 +7403,14 @@ function createFormControl(props = {}) {
|
|
|
7359
7403
|
!!keepStateOptions.keepDirtyValues ||
|
|
7360
7404
|
(!_options.shouldUnregister && !isEmptyObject$1(values));
|
|
7361
7405
|
_state.watch = !!_options.shouldUnregister;
|
|
7406
|
+
_state.keepIsValid = !!keepStateOptions.keepIsValid;
|
|
7407
|
+
_state.action = false;
|
|
7408
|
+
// Clear errors synchronously to prevent validation errors on subsequent submissions
|
|
7409
|
+
// This fixes the issue where form.reset() causes validation errors on subsequent
|
|
7410
|
+
// submissions in Next.js 16 with Server Actions
|
|
7411
|
+
if (!keepStateOptions.keepErrors) {
|
|
7412
|
+
_formState.errors = {};
|
|
7413
|
+
}
|
|
7362
7414
|
_subjects.state.next({
|
|
7363
7415
|
submitCount: keepStateOptions.keepSubmitCount
|
|
7364
7416
|
? _formState.submitCount
|
|
@@ -7396,7 +7448,7 @@ function createFormControl(props = {}) {
|
|
|
7396
7448
|
};
|
|
7397
7449
|
const reset = (formValues, keepStateOptions) => _reset(isFunction$3(formValues)
|
|
7398
7450
|
? formValues(_formValues)
|
|
7399
|
-
: formValues, keepStateOptions);
|
|
7451
|
+
: formValues, { ..._options.resetOptions, ...keepStateOptions });
|
|
7400
7452
|
const setFocus = (name, options = {}) => {
|
|
7401
7453
|
const field = get$1(_fields, name);
|
|
7402
7454
|
const fieldReference = field && field._f;
|
|
@@ -7405,10 +7457,14 @@ function createFormControl(props = {}) {
|
|
|
7405
7457
|
? fieldReference.refs[0]
|
|
7406
7458
|
: fieldReference.ref;
|
|
7407
7459
|
if (fieldRef.focus) {
|
|
7408
|
-
|
|
7409
|
-
|
|
7410
|
-
|
|
7411
|
-
fieldRef.
|
|
7460
|
+
// Use setTimeout to ensure focus happens after any pending state updates
|
|
7461
|
+
// This fixes the issue where setFocus doesn't work immediately after setError
|
|
7462
|
+
setTimeout(() => {
|
|
7463
|
+
fieldRef.focus();
|
|
7464
|
+
options.shouldSelect &&
|
|
7465
|
+
isFunction$3(fieldRef.select) &&
|
|
7466
|
+
fieldRef.select();
|
|
7467
|
+
});
|
|
7412
7468
|
}
|
|
7413
7469
|
}
|
|
7414
7470
|
};
|
|
@@ -7434,6 +7490,7 @@ function createFormControl(props = {}) {
|
|
|
7434
7490
|
setError,
|
|
7435
7491
|
_subscribe,
|
|
7436
7492
|
_runSchema,
|
|
7493
|
+
_updateIsValidating,
|
|
7437
7494
|
_focusError,
|
|
7438
7495
|
_getWatch,
|
|
7439
7496
|
_getDirty,
|
|
@@ -7646,7 +7703,7 @@ function useForm(props = {}) {
|
|
|
7646
7703
|
}
|
|
7647
7704
|
control._removeUnmounted();
|
|
7648
7705
|
});
|
|
7649
|
-
_formControl.current.formState = getProxyFormState(formState, control);
|
|
7706
|
+
_formControl.current.formState = React__default.useMemo(() => getProxyFormState(formState, control), [control, formState]);
|
|
7650
7707
|
return _formControl.current;
|
|
7651
7708
|
}
|
|
7652
7709
|
|
|
@@ -18701,6 +18758,10 @@ var isSet = (target) => target instanceof Set;
|
|
|
18701
18758
|
var isObjectish = (target) => typeof target === "object";
|
|
18702
18759
|
var isFunction$2 = (target) => typeof target === "function";
|
|
18703
18760
|
var isBoolean$2 = (target) => typeof target === "boolean";
|
|
18761
|
+
function isArrayIndex(value) {
|
|
18762
|
+
const n = +value;
|
|
18763
|
+
return Number.isInteger(n) && String(n) === value;
|
|
18764
|
+
}
|
|
18704
18765
|
var latest = (state) => state.copy_ || state.base_;
|
|
18705
18766
|
var getFinalValue = (state) => state.modified_ ? state.copy_ : state.base_;
|
|
18706
18767
|
function shallowCopy(base, strict) {
|
|
@@ -18780,6 +18841,7 @@ function isFrozen(obj) {
|
|
|
18780
18841
|
// src/utils/plugins.ts
|
|
18781
18842
|
var PluginMapSet = "MapSet";
|
|
18782
18843
|
var PluginPatches = "Patches";
|
|
18844
|
+
var PluginArrayMethods = "ArrayMethods";
|
|
18783
18845
|
var plugins = {};
|
|
18784
18846
|
function getPlugin(pluginKey) {
|
|
18785
18847
|
const plugin = plugins[pluginKey];
|
|
@@ -18803,7 +18865,8 @@ var createScope = (parent_, immer_) => ({
|
|
|
18803
18865
|
unfinalizedDrafts_: 0,
|
|
18804
18866
|
handledSet_: /* @__PURE__ */ new Set(),
|
|
18805
18867
|
processedForPatches_: /* @__PURE__ */ new Set(),
|
|
18806
|
-
mapSetPlugin_: isPluginLoaded(PluginMapSet) ? getPlugin(PluginMapSet) : void 0
|
|
18868
|
+
mapSetPlugin_: isPluginLoaded(PluginMapSet) ? getPlugin(PluginMapSet) : void 0,
|
|
18869
|
+
arrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods) ? getPlugin(PluginArrayMethods) : void 0
|
|
18807
18870
|
});
|
|
18808
18871
|
function usePatchesInScope(scope, patchListener) {
|
|
18809
18872
|
if (patchListener) {
|
|
@@ -18938,7 +19001,7 @@ function registerChildFinalizationCallback(parent, child, key) {
|
|
|
18938
19001
|
});
|
|
18939
19002
|
}
|
|
18940
19003
|
function generatePatchesAndFinalize(state, rootScope) {
|
|
18941
|
-
const shouldFinalize = state.modified_ && !state.finalized_ && (state.type_ === 3 /* Set */ || (state.assigned_?.size ?? 0) > 0);
|
|
19004
|
+
const shouldFinalize = state.modified_ && !state.finalized_ && (state.type_ === 3 /* Set */ || state.type_ === 1 /* Array */ && state.allIndicesReassigned_ || (state.assigned_?.size ?? 0) > 0);
|
|
18942
19005
|
if (shouldFinalize) {
|
|
18943
19006
|
const { patchPlugin_ } = rootScope;
|
|
18944
19007
|
if (patchPlugin_) {
|
|
@@ -18964,13 +19027,19 @@ function handleCrossReference(target, key, value) {
|
|
|
18964
19027
|
} else if (isDraftable(value)) {
|
|
18965
19028
|
target.callbacks_.push(function nestedDraftCleanup() {
|
|
18966
19029
|
const targetCopy = latest(target);
|
|
18967
|
-
if (
|
|
18968
|
-
if (
|
|
18969
|
-
handleValue(
|
|
18970
|
-
|
|
18971
|
-
|
|
18972
|
-
|
|
18973
|
-
)
|
|
19030
|
+
if (target.type_ === 3 /* Set */) {
|
|
19031
|
+
if (targetCopy.has(value)) {
|
|
19032
|
+
handleValue(value, scope_.handledSet_, scope_);
|
|
19033
|
+
}
|
|
19034
|
+
} else {
|
|
19035
|
+
if (get(targetCopy, key, target.type_) === value) {
|
|
19036
|
+
if (scope_.drafts_.length > 1 && (target.assigned_.get(key) ?? false) === true && target.copy_) {
|
|
19037
|
+
handleValue(
|
|
19038
|
+
get(target.copy_, key, target.type_),
|
|
19039
|
+
scope_.handledSet_,
|
|
19040
|
+
scope_
|
|
19041
|
+
);
|
|
19042
|
+
}
|
|
18974
19043
|
}
|
|
18975
19044
|
}
|
|
18976
19045
|
});
|
|
@@ -19043,6 +19112,13 @@ var objectTraps = {
|
|
|
19043
19112
|
get(state, prop) {
|
|
19044
19113
|
if (prop === DRAFT_STATE)
|
|
19045
19114
|
return state;
|
|
19115
|
+
let arrayPlugin = state.scope_.arrayMethodsPlugin_;
|
|
19116
|
+
const isArrayWithStringProp = state.type_ === 1 /* Array */ && typeof prop === "string";
|
|
19117
|
+
if (isArrayWithStringProp) {
|
|
19118
|
+
if (arrayPlugin?.isArrayOperationMethod(prop)) {
|
|
19119
|
+
return arrayPlugin.createMethodInterceptor(state, prop);
|
|
19120
|
+
}
|
|
19121
|
+
}
|
|
19046
19122
|
const source = latest(state);
|
|
19047
19123
|
if (!has(source, prop, state.type_)) {
|
|
19048
19124
|
return readPropFromProto(state, source, prop);
|
|
@@ -19051,6 +19127,11 @@ var objectTraps = {
|
|
|
19051
19127
|
if (state.finalized_ || !isDraftable(value)) {
|
|
19052
19128
|
return value;
|
|
19053
19129
|
}
|
|
19130
|
+
if (isArrayWithStringProp && state.operationMethod && arrayPlugin?.isMutatingArrayMethod(
|
|
19131
|
+
state.operationMethod
|
|
19132
|
+
) && isArrayIndex(prop)) {
|
|
19133
|
+
return value;
|
|
19134
|
+
}
|
|
19054
19135
|
if (value === peek(state.base_, prop)) {
|
|
19055
19136
|
prepareCopy(state);
|
|
19056
19137
|
const childKey = state.type_ === 1 /* Array */ ? +prop : prop;
|
|
@@ -19131,13 +19212,14 @@ var objectTraps = {
|
|
|
19131
19212
|
}
|
|
19132
19213
|
};
|
|
19133
19214
|
var arrayTraps = {};
|
|
19134
|
-
|
|
19215
|
+
for (let key in objectTraps) {
|
|
19216
|
+
let fn = objectTraps[key];
|
|
19135
19217
|
arrayTraps[key] = function() {
|
|
19136
19218
|
const args = arguments;
|
|
19137
19219
|
args[0] = args[0][0];
|
|
19138
19220
|
return fn.apply(this, args);
|
|
19139
19221
|
};
|
|
19140
|
-
}
|
|
19222
|
+
}
|
|
19141
19223
|
arrayTraps.deleteProperty = function(state, prop) {
|
|
19142
19224
|
if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
|
|
19143
19225
|
die(13);
|
|
@@ -20441,29 +20523,11 @@ var addAbortSignalListener = (abortSignal, callback) => {
|
|
|
20441
20523
|
});
|
|
20442
20524
|
return () => abortSignal.removeEventListener("abort", callback);
|
|
20443
20525
|
};
|
|
20444
|
-
var abortControllerWithReason = (abortController, reason) => {
|
|
20445
|
-
const signal = abortController.signal;
|
|
20446
|
-
if (signal.aborted) {
|
|
20447
|
-
return;
|
|
20448
|
-
}
|
|
20449
|
-
if (!("reason" in signal)) {
|
|
20450
|
-
Object.defineProperty(signal, "reason", {
|
|
20451
|
-
enumerable: true,
|
|
20452
|
-
value: reason,
|
|
20453
|
-
configurable: true,
|
|
20454
|
-
writable: true
|
|
20455
|
-
});
|
|
20456
|
-
}
|
|
20457
|
-
abortController.abort(reason);
|
|
20458
|
-
};
|
|
20459
20526
|
|
|
20460
20527
|
// src/listenerMiddleware/task.ts
|
|
20461
20528
|
var validateActive = (signal) => {
|
|
20462
20529
|
if (signal.aborted) {
|
|
20463
|
-
|
|
20464
|
-
reason
|
|
20465
|
-
} = signal;
|
|
20466
|
-
throw new TaskAbortError(reason);
|
|
20530
|
+
throw new TaskAbortError(signal.reason);
|
|
20467
20531
|
}
|
|
20468
20532
|
};
|
|
20469
20533
|
function raceWithSignal(signal, promise) {
|
|
@@ -20519,7 +20583,7 @@ var {
|
|
|
20519
20583
|
var INTERNAL_NIL_TOKEN = {};
|
|
20520
20584
|
var alm = "listenerMiddleware";
|
|
20521
20585
|
var createFork = (parentAbortSignal, parentBlockingPromises) => {
|
|
20522
|
-
const linkControllers = (controller) => addAbortSignalListener(parentAbortSignal, () =>
|
|
20586
|
+
const linkControllers = (controller) => addAbortSignalListener(parentAbortSignal, () => controller.abort(parentAbortSignal.reason));
|
|
20523
20587
|
return (taskExecutor, opts) => {
|
|
20524
20588
|
assertFunction(taskExecutor, "taskExecutor");
|
|
20525
20589
|
const childAbortController = new AbortController();
|
|
@@ -20534,14 +20598,14 @@ var createFork = (parentAbortSignal, parentBlockingPromises) => {
|
|
|
20534
20598
|
});
|
|
20535
20599
|
validateActive(childAbortController.signal);
|
|
20536
20600
|
return result2;
|
|
20537
|
-
}, () =>
|
|
20601
|
+
}, () => childAbortController.abort(taskCompleted));
|
|
20538
20602
|
if (opts?.autoJoin) {
|
|
20539
20603
|
parentBlockingPromises.push(result.catch(noop2));
|
|
20540
20604
|
}
|
|
20541
20605
|
return {
|
|
20542
20606
|
result: createPause(parentAbortSignal)(result),
|
|
20543
20607
|
cancel() {
|
|
20544
|
-
|
|
20608
|
+
childAbortController.abort(taskCancelled);
|
|
20545
20609
|
}
|
|
20546
20610
|
};
|
|
20547
20611
|
};
|
|
@@ -20636,7 +20700,7 @@ var findListenerEntry = (listenerMap, options) => {
|
|
|
20636
20700
|
};
|
|
20637
20701
|
var cancelActiveListeners = (entry) => {
|
|
20638
20702
|
entry.pending.forEach((controller) => {
|
|
20639
|
-
|
|
20703
|
+
controller.abort(listenerCancelled);
|
|
20640
20704
|
});
|
|
20641
20705
|
};
|
|
20642
20706
|
var createClearListenerMiddleware = (listenerMap, executingListeners) => {
|
|
@@ -20742,13 +20806,13 @@ var createListenerMiddleware = (middlewareOptions = {}) => {
|
|
|
20742
20806
|
cancelActiveListeners: () => {
|
|
20743
20807
|
entry.pending.forEach((controller, _, set) => {
|
|
20744
20808
|
if (controller !== internalTaskController) {
|
|
20745
|
-
|
|
20809
|
+
controller.abort(listenerCancelled);
|
|
20746
20810
|
set.delete(controller);
|
|
20747
20811
|
}
|
|
20748
20812
|
});
|
|
20749
20813
|
},
|
|
20750
20814
|
cancel: () => {
|
|
20751
|
-
|
|
20815
|
+
internalTaskController.abort(listenerCancelled);
|
|
20752
20816
|
entry.pending.delete(internalTaskController);
|
|
20753
20817
|
},
|
|
20754
20818
|
throwIfCancelled: () => {
|
|
@@ -20764,7 +20828,7 @@ var createListenerMiddleware = (middlewareOptions = {}) => {
|
|
|
20764
20828
|
}
|
|
20765
20829
|
} finally {
|
|
20766
20830
|
await Promise.all(autoJoinPromises);
|
|
20767
|
-
|
|
20831
|
+
internalTaskController.abort(listenerCompleted);
|
|
20768
20832
|
untrackExecutingListener(entry);
|
|
20769
20833
|
entry.pending.delete(internalTaskController);
|
|
20770
20834
|
}
|