@fuf-stack/uniform 1.30.0 → 2.0.0-next.3
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 +0 -6
- package/dist/Checkboxes/index.d.mts +178 -274
- package/dist/Checkboxes/index.d.mts.map +1 -1
- package/dist/Checkboxes/index.mjs +294 -94
- package/dist/Checkboxes/index.mjs.map +1 -1
- package/dist/DatePicker/index.d.mts +1963 -148
- package/dist/DatePicker/index.d.mts.map +1 -1
- package/dist/DatePicker/index.mjs +401 -82
- package/dist/DatePicker/index.mjs.map +1 -1
- package/dist/FieldArray/index.d.mts +102 -97
- package/dist/FieldArray/index.d.mts.map +1 -1
- package/dist/FieldArray/index.mjs +340 -195
- package/dist/FieldArray/index.mjs.map +1 -1
- package/dist/FieldCard/index.d.mts +34 -34
- package/dist/FieldCard/index.d.mts.map +1 -1
- package/dist/FieldCard/index.mjs +181 -127
- package/dist/FieldCard/index.mjs.map +1 -1
- package/dist/{FieldCopyTestIdButton-Y9SfvaM9.mjs → FieldCopyTestIdButton-D3_jZYJ1.mjs} +4 -2
- package/dist/FieldCopyTestIdButton-D3_jZYJ1.mjs.map +1 -0
- package/dist/FieldDescription-X_0s1Lhu.mjs +35 -0
- package/dist/FieldDescription-X_0s1Lhu.mjs.map +1 -0
- package/dist/FieldLabel-DrNWJIVh.mjs +128 -0
- package/dist/FieldLabel-DrNWJIVh.mjs.map +1 -0
- package/dist/FieldLayout-DcvQU0zN.mjs +45 -0
- package/dist/FieldLayout-DcvQU0zN.mjs.map +1 -0
- package/dist/FieldReset/index.d.mts +17 -12
- package/dist/FieldReset/index.d.mts.map +1 -1
- package/dist/FieldReset/index.mjs +50 -33
- package/dist/FieldReset/index.mjs.map +1 -1
- package/dist/FieldValidationError-iAayfTEw.mjs +75 -0
- package/dist/FieldValidationError-iAayfTEw.mjs.map +1 -0
- package/dist/Form/index.d.mts +2 -2
- package/dist/Form/index.d.mts.map +1 -1
- package/dist/Form/index.mjs +9 -7
- package/dist/Form/index.mjs.map +1 -1
- package/dist/{FormContext-Dvt3MiKq.d.mts → FormContext-BnNJYZOo.d.mts} +3 -3
- package/dist/{FormContext-Dvt3MiKq.d.mts.map → FormContext-BnNJYZOo.d.mts.map} +1 -1
- package/dist/{FormContext-B8G_Xxd6.mjs → FormContext-PXkVlBdU.mjs} +6 -2
- package/dist/FormContext-PXkVlBdU.mjs.map +1 -0
- package/dist/Grid/index.mjs +1 -1
- package/dist/{Grid-Us2JFczS.mjs → Grid-DBL29Kwb.mjs} +4 -2
- package/dist/Grid-DBL29Kwb.mjs.map +1 -0
- package/dist/Input/index.d.mts +734 -47
- package/dist/Input/index.d.mts.map +1 -1
- package/dist/Input/index.mjs +411 -168
- package/dist/Input/index.mjs.map +1 -1
- package/dist/RadioBoxes/index.d.mts +300 -98
- package/dist/RadioBoxes/index.d.mts.map +1 -1
- package/dist/RadioBoxes/index.mjs +156 -119
- package/dist/RadioBoxes/index.mjs.map +1 -1
- package/dist/RadioTabs/index.d.mts +302 -76
- package/dist/RadioTabs/index.d.mts.map +1 -1
- package/dist/RadioTabs/index.mjs +274 -87
- package/dist/RadioTabs/index.mjs.map +1 -1
- package/dist/Radios/index.d.mts +314 -78
- package/dist/Radios/index.d.mts.map +1 -1
- package/dist/Radios/index.mjs +90 -44
- package/dist/Radios/index.mjs.map +1 -1
- package/dist/Select/index.d.mts +410 -142
- package/dist/Select/index.d.mts.map +1 -1
- package/dist/Select/index.mjs +284 -157
- package/dist/Select/index.mjs.map +1 -1
- package/dist/Slider/index.d.mts +382 -63
- package/dist/Slider/index.d.mts.map +1 -1
- package/dist/Slider/index.mjs +269 -90
- package/dist/Slider/index.mjs.map +1 -1
- package/dist/SubmitButton/index.d.mts.map +1 -1
- package/dist/SubmitButton/index.mjs +4 -1
- package/dist/SubmitButton/index.mjs.map +1 -1
- package/dist/Switch/index.d.mts +2 -427
- package/dist/Switch/index.mjs +167 -72
- package/dist/Switch/index.mjs.map +1 -1
- package/dist/Switch-Db2dpGz7.d.mts +648 -0
- package/dist/Switch-Db2dpGz7.d.mts.map +1 -0
- package/dist/SwitchBox/index.d.mts +191 -91
- package/dist/SwitchBox/index.d.mts.map +1 -1
- package/dist/SwitchBox/index.mjs +142 -88
- package/dist/SwitchBox/index.mjs.map +1 -1
- package/dist/TextArea/index.d.mts +347 -29
- package/dist/TextArea/index.d.mts.map +1 -1
- package/dist/TextArea/index.mjs +195 -47
- package/dist/TextArea/index.mjs.map +1 -1
- package/dist/Time/index.d.mts +1373 -139
- package/dist/Time/index.d.mts.map +1 -1
- package/dist/Time/index.mjs +160 -77
- package/dist/Time/index.mjs.map +1 -1
- package/dist/helpers/index.d.mts +1 -1
- package/dist/helpers/index.mjs +1 -1
- package/dist/helpers/index.mjs.map +1 -1
- package/dist/hooks/useClientValidation/index.mjs +1 -1
- package/dist/hooks/useController/index.d.mts +29 -2
- package/dist/hooks/useController/index.d.mts.map +1 -0
- package/dist/hooks/useController/index.mjs +1 -1
- package/dist/hooks/useFormContext/index.d.mts +44 -2
- package/dist/hooks/useFormContext/index.d.mts.map +1 -0
- package/dist/hooks/useFormContext/index.mjs +1 -1
- package/dist/hooks/useInputValueDebounce/index.d.mts +9 -3
- package/dist/hooks/useInputValueDebounce/index.d.mts.map +1 -1
- package/dist/hooks/useInputValueDebounce/index.mjs +27 -5
- package/dist/hooks/useInputValueDebounce/index.mjs.map +1 -1
- package/dist/hooks/useInputValueTransform/index.d.mts +1 -2
- package/dist/hooks/useInputValueTransform/index.mjs +1 -1
- package/dist/hooks/useWatchFormReset/index.mjs +1 -1
- package/dist/hooks/useWatchUserChange/index.mjs +1 -1
- package/dist/{useInputValueTransform-cevZBrIN.d.mts → index-cevZBrIN.d.mts} +1 -1
- package/dist/index-cevZBrIN.d.mts.map +1 -0
- package/dist/partials/FieldCopyTestIdButton/index.mjs +1 -1
- package/dist/partials/FieldValidationError/index.d.mts +637 -3
- package/dist/partials/FieldValidationError/index.d.mts.map +1 -1
- package/dist/partials/FieldValidationError/index.mjs +1 -1
- package/dist/radioControlVariants-BYRfaD6y.mjs +187 -0
- package/dist/radioControlVariants-BYRfaD6y.mjs.map +1 -0
- package/dist/switchVariants-D16b2VaT.mjs +67 -0
- package/dist/switchVariants-D16b2VaT.mjs.map +1 -0
- package/dist/timeVariants-CtXyNKmW.mjs +58 -0
- package/dist/timeVariants-CtXyNKmW.mjs.map +1 -0
- package/dist/{useController-CJjMqXU5.mjs → useController-JtIeurpw.mjs} +2 -2
- package/dist/{useController-CJjMqXU5.mjs.map → useController-JtIeurpw.mjs.map} +1 -1
- package/dist/{useFormContext-BEjPBdzb.mjs → useFormContext-piqnN2L-.mjs} +2 -2
- package/dist/{useFormContext-BEjPBdzb.mjs.map → useFormContext-piqnN2L-.mjs.map} +1 -1
- package/dist/{useInputValueTransform-D44BLp1Z.mjs → useInputValueTransform-CXWWFhy_.mjs} +2 -2
- package/dist/{useInputValueTransform-D44BLp1Z.mjs.map → useInputValueTransform-CXWWFhy_.mjs.map} +1 -1
- package/package.json +13 -25
- package/dist/FieldCopyTestIdButton-Y9SfvaM9.mjs.map +0 -1
- package/dist/FieldValidationError-BcUV0r1I.mjs +0 -48
- package/dist/FieldValidationError-BcUV0r1I.mjs.map +0 -1
- package/dist/FormContext-B8G_Xxd6.mjs.map +0 -1
- package/dist/Grid-Us2JFczS.mjs.map +0 -1
- package/dist/Switch/index.d.mts.map +0 -1
- package/dist/hooks/useInput/index.d.mts +0 -2
- package/dist/hooks/useInput/index.mjs +0 -5
- package/dist/hooks/useInput/index.mjs.map +0 -1
- package/dist/hooks/useUniformField/index.d.mts +0 -2
- package/dist/hooks/useUniformField/index.mjs +0 -141
- package/dist/hooks/useUniformField/index.mjs.map +0 -1
- package/dist/hooks/useUniformFieldArray/index.d.mts +0 -47
- package/dist/hooks/useUniformFieldArray/index.d.mts.map +0 -1
- package/dist/hooks/useUniformFieldArray/index.mjs +0 -99
- package/dist/hooks/useUniformFieldArray/index.mjs.map +0 -1
- package/dist/index-CaxrMD1A.d.mts +0 -1
- package/dist/index-DsB0_365.d.mts +0 -106
- package/dist/index-DsB0_365.d.mts.map +0 -1
- package/dist/useController-CdFEp-Wa.d.mts +0 -30
- package/dist/useController-CdFEp-Wa.d.mts.map +0 -1
- package/dist/useFormContext-BSSUZ0Md.d.mts +0 -45
- package/dist/useFormContext-BSSUZ0Md.d.mts.map +0 -1
- package/dist/useInput-ClpHDPdr.d.mts +0 -2
- package/dist/useInput-NPbS4w_n.mjs +0 -1
- package/dist/useInputValueTransform-cevZBrIN.d.mts.map +0 -1
|
@@ -1,2 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import { n as UniformContext } from "../../FormContext-BnNJYZOo.mjs";
|
|
2
|
+
import { ContextType } from "react";
|
|
3
|
+
import { FieldError, FieldValues, Path, UseFormReturn } from "react-hook-form";
|
|
4
|
+
import { VetoInstance } from "@fuf-stack/veto";
|
|
5
|
+
/** Schema check whether a field is required or optional */
|
|
6
|
+
export declare const checkFieldIsRequired: (validation: VetoInstance, path: string[]) => boolean;
|
|
7
|
+
/** Field state returned by the enhanced `getFieldState` */
|
|
8
|
+
export interface UniformFieldState {
|
|
9
|
+
/** Validation errors for the field from the Uniform validation schema */
|
|
10
|
+
error: FieldError[] | undefined;
|
|
11
|
+
/** Whether the field has validation errors */
|
|
12
|
+
invalid: boolean;
|
|
13
|
+
/** Whether the field value differs from its default value */
|
|
14
|
+
isDirty: boolean;
|
|
15
|
+
/** Whether the field has been touched */
|
|
16
|
+
isTouched: boolean;
|
|
17
|
+
/** Whether the field is currently being validated */
|
|
18
|
+
isValidating: boolean;
|
|
19
|
+
/** Whether the validation schema requires the field */
|
|
20
|
+
required: boolean;
|
|
21
|
+
/** Generated HTML data-testid for the field */
|
|
22
|
+
testId: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Return type of `useFormContext`.
|
|
26
|
+
*
|
|
27
|
+
* Declared explicitly so the published declarations only reference types that
|
|
28
|
+
* react-hook-form exports from its package root.
|
|
29
|
+
*/
|
|
30
|
+
export type UseFormContextReturn<TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues> = Omit<UseFormReturn<TFieldValues, TContext, TTransformedValues>, 'getFieldState'> & ContextType<typeof UniformContext> & {
|
|
31
|
+
getFieldState: (name: Path<TFieldValues>, testId?: string) => UniformFieldState;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Custom hook that extends react-hook-form's useFormContext to add validation and state management.
|
|
35
|
+
*
|
|
36
|
+
* Key features:
|
|
37
|
+
* - Enhanced `getFieldState` that includes validation schema-based "required" status and testId generation
|
|
38
|
+
* - Automatic conversion of form values via `getValues`, `watch`, and `subscribe`:
|
|
39
|
+
* - Unwraps flat array wrappers (`{ __FLAT__: value }` → `value`)
|
|
40
|
+
* - Converts nullish string markers (`__NULL__` → `null`, `__FALSE__` → `false`, `__ZERO__` → `0`)
|
|
41
|
+
* - Filters out empty/null values
|
|
42
|
+
*/
|
|
43
|
+
export declare const useFormContext: <TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues>() => UseFormContextReturn<TFieldValues, TContext, TTransformedValues>;
|
|
44
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/hooks/useFormContext/useFormContext.ts"],"mappings":";;;;;qBAkBa,uBACX,YAAY,cACZ;;iBA0De;;EAEf,OAAO;;EAEP;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;YASU,qBACV,qBAAqB,cAAc,aACnC,gBACA,qBAAqB,gBACnB,KACF,cAAc,cAAc,UAAU,wCAGtC,mBAAmB;EACjB,gBACE,MAAM,KAAK,eACX,oBACG;;;;;;;;;;;;qBAaI,iBACX,qBAAqB,cAAc,aACnC,gBACA,qBAAqB,mBAClB,qBAAqB,cAAc,UAAU"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/hooks/useFormContext/index.ts
|
|
2
2
|
/* v8 ignore stop */
|
|
3
|
-
export { t as checkFieldIsRequired, n as useFormContext } from "../../useFormContext-
|
|
3
|
+
export { t as checkFieldIsRequired, n as useFormContext } from "../../useFormContext-piqnN2L-.mjs";
|
|
4
4
|
|
|
5
5
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export interface UseInputValueDebounceOptions<TValue = unknown> {
|
|
2
2
|
/** Debounce delay in milliseconds (default: 300) */
|
|
3
3
|
debounceDelay?: number;
|
|
4
|
+
/** Immediate display value when cleared, otherwise follows the reset form value */
|
|
5
|
+
emptyValue?: TValue;
|
|
4
6
|
/** Field name for triggering validation after debounced value commits */
|
|
5
7
|
name: string;
|
|
6
8
|
/** The onBlur function to call after flushing debounced value */
|
|
@@ -11,6 +13,10 @@ export interface UseInputValueDebounceOptions<TValue = unknown> {
|
|
|
11
13
|
value: TValue;
|
|
12
14
|
}
|
|
13
15
|
export interface UseInputValueDebounceReturn<TValue = unknown> {
|
|
16
|
+
/** Cancel queued edits and replace only the displayed value (for clear/reset). */
|
|
17
|
+
cancelPendingChange: (value: TValue) => void;
|
|
18
|
+
/** Cancels pending edits and resets the field to null */
|
|
19
|
+
clear: () => void;
|
|
14
20
|
/** Enhanced onBlur function that flushes current value immediately */
|
|
15
21
|
onBlur: () => void;
|
|
16
22
|
/** Enhanced onChange function with debouncing */
|
|
@@ -31,8 +37,8 @@ export interface UseInputValueDebounceReturn<TValue = unknown> {
|
|
|
31
37
|
* - **Immediate value updates**: UI stays responsive during debouncing
|
|
32
38
|
* - **Blur flushing**: Immediately applies pending changes on blur
|
|
33
39
|
*
|
|
34
|
-
* **Note:** Value transformations should be handled at the
|
|
35
|
-
* not in this hook.
|
|
40
|
+
* **Note:** Value transformations should be handled at the private field-state level,
|
|
41
|
+
* not in this hook. Clearing cancels queued edits before resetting the form field.
|
|
36
42
|
*
|
|
37
43
|
* @param options Configuration for debounced value handling
|
|
38
44
|
* @param options.debounceDelay Delay in milliseconds (default: 300)
|
|
@@ -53,5 +59,5 @@ export interface UseInputValueDebounceReturn<TValue = unknown> {
|
|
|
53
59
|
* });
|
|
54
60
|
* ```
|
|
55
61
|
*/
|
|
56
|
-
export declare const useInputValueDebounce: <TValue = unknown>({ debounceDelay, name, onBlur, onChange, value }: UseInputValueDebounceOptions<TValue>) => UseInputValueDebounceReturn<TValue>;
|
|
62
|
+
export declare const useInputValueDebounce: <TValue = unknown>({ debounceDelay, name, onBlur, onChange, value, emptyValue }: UseInputValueDebounceOptions<TValue>) => UseInputValueDebounceReturn<TValue>;
|
|
57
63
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/hooks/useInputValueDebounce/useInputValueDebounce.ts"],"mappings":"A,
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/hooks/useInputValueDebounce/useInputValueDebounce.ts"],"mappings":"A,iBAKiB,6BAA6B;;EAE5C;;EAEA,aAAa;;EAEb;;EAEA;;EAGA,cAAc;;EAEd,OAAO;;iBAGQ,4BAA4B;;EAE3C,sBAAsB,OAAO;;EAE7B;;EAEA;;EAGA,cAAc;;EAEd,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAsCI,wBAAyB,oBAAkB,eAAA,MAAA,QAAA,UAAA,OAAA,cAOrD,6BAA6B,YAAU,4BAA4B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { n as useFormContext } from "../../useFormContext-
|
|
1
|
+
import { n as useFormContext } from "../../useFormContext-piqnN2L-.mjs";
|
|
2
|
+
import { useWatchFormReset } from "../useWatchFormReset/index.mjs";
|
|
2
3
|
import { useCallback, useRef, useState } from "react";
|
|
3
4
|
// src/hooks/useInputValueDebounce/useInputValueDebounce.ts
|
|
4
5
|
/**
|
|
@@ -14,8 +15,8 @@ import { useCallback, useRef, useState } from "react";
|
|
|
14
15
|
* - **Immediate value updates**: UI stays responsive during debouncing
|
|
15
16
|
* - **Blur flushing**: Immediately applies pending changes on blur
|
|
16
17
|
*
|
|
17
|
-
* **Note:** Value transformations should be handled at the
|
|
18
|
-
* not in this hook.
|
|
18
|
+
* **Note:** Value transformations should be handled at the private field-state level,
|
|
19
|
+
* not in this hook. Clearing cancels queued edits before resetting the form field.
|
|
19
20
|
*
|
|
20
21
|
* @param options Configuration for debounced value handling
|
|
21
22
|
* @param options.debounceDelay Delay in milliseconds (default: 300)
|
|
@@ -36,16 +37,37 @@ import { useCallback, useRef, useState } from "react";
|
|
|
36
37
|
* });
|
|
37
38
|
* ```
|
|
38
39
|
*/
|
|
39
|
-
const useInputValueDebounce = ({ debounceDelay = 300, name, onBlur, onChange, value }) => {
|
|
40
|
-
const { trigger } = useFormContext();
|
|
40
|
+
const useInputValueDebounce = ({ debounceDelay = 300, name, onBlur, onChange, value, emptyValue = value }) => {
|
|
41
|
+
const { resetField, trigger } = useFormContext();
|
|
41
42
|
const [currentValue, setCurrentValue] = useState(value);
|
|
42
43
|
const [lastExternalValue, setLastExternalValue] = useState(value);
|
|
43
44
|
const timeoutRef = useRef(null);
|
|
45
|
+
const cancelPendingChange = useCallback((nextValue) => {
|
|
46
|
+
if (timeoutRef.current) {
|
|
47
|
+
clearTimeout(timeoutRef.current);
|
|
48
|
+
timeoutRef.current = null;
|
|
49
|
+
}
|
|
50
|
+
setCurrentValue(nextValue);
|
|
51
|
+
}, []);
|
|
52
|
+
const clear = useCallback(() => {
|
|
53
|
+
cancelPendingChange(emptyValue);
|
|
54
|
+
resetField(name, { defaultValue: null });
|
|
55
|
+
}, [
|
|
56
|
+
cancelPendingChange,
|
|
57
|
+
emptyValue,
|
|
58
|
+
name,
|
|
59
|
+
resetField
|
|
60
|
+
]);
|
|
61
|
+
useWatchFormReset({ onReset: useCallback(() => {
|
|
62
|
+
cancelPendingChange(value);
|
|
63
|
+
}, [cancelPendingChange, value]) });
|
|
44
64
|
if (!Object.is(lastExternalValue, value)) {
|
|
45
65
|
setLastExternalValue(value);
|
|
46
66
|
setCurrentValue(value);
|
|
47
67
|
}
|
|
48
68
|
return {
|
|
69
|
+
cancelPendingChange,
|
|
70
|
+
clear,
|
|
49
71
|
onChange: useCallback((...event) => {
|
|
50
72
|
const newValue = event[0]?.target?.value ?? event[0];
|
|
51
73
|
setCurrentValue(newValue);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/hooks/useInputValueDebounce/useInputValueDebounce.ts","../../../src/hooks/useInputValueDebounce/index.ts"],"sourcesContent":["import { useCallback, useRef, useState } from 'react';\n\nimport { useFormContext } from '../useFormContext';\n\nexport interface UseInputValueDebounceOptions<TValue = unknown> {\n /** Debounce delay in milliseconds (default: 300) */\n debounceDelay?: number;\n /** Field name for triggering validation after debounced value commits */\n name: string;\n /** The onBlur function to call after flushing debounced value */\n onBlur: () => void;\n /** The onChange function to call with debounced value */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => void;\n /** The field value */\n value: TValue;\n}\n\nexport interface UseInputValueDebounceReturn<TValue = unknown> {\n /** Enhanced onBlur function that flushes current value immediately */\n onBlur: () => void;\n /** Enhanced onChange function with debouncing */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => void;\n /** The field value that is displayed - updates immediately */\n value: TValue;\n}\n\n/**\n * Custom hook for debouncing value changes with immediate blur support.\n *\n * Provides immediate visual feedback by updating the value instantly,\n * while debouncing the actual onChange calls. When focus is lost,\n * any pending debounced changes are immediately flushed.\n *\n * **Key Features:**\n * - **Debouncing**: Delays onChange calls until user stops typing\n * - **Generic type support**: Works with any data type (strings, numbers, arrays, objects)\n * - **Immediate value updates**: UI stays responsive during debouncing\n * - **Blur flushing**: Immediately applies pending changes on blur\n *\n * **Note:** Value transformations should be handled at the
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/hooks/useInputValueDebounce/useInputValueDebounce.ts","../../../src/hooks/useInputValueDebounce/index.ts"],"sourcesContent":["import { useCallback, useRef, useState } from 'react';\n\nimport { useFormContext } from '../useFormContext';\nimport { useWatchFormReset } from '../useWatchFormReset';\n\nexport interface UseInputValueDebounceOptions<TValue = unknown> {\n /** Debounce delay in milliseconds (default: 300) */\n debounceDelay?: number;\n /** Immediate display value when cleared, otherwise follows the reset form value */\n emptyValue?: TValue;\n /** Field name for triggering validation after debounced value commits */\n name: string;\n /** The onBlur function to call after flushing debounced value */\n onBlur: () => void;\n /** The onChange function to call with debounced value */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => void;\n /** The field value */\n value: TValue;\n}\n\nexport interface UseInputValueDebounceReturn<TValue = unknown> {\n /** Cancel queued edits and replace only the displayed value (for clear/reset). */\n cancelPendingChange: (value: TValue) => void;\n /** Cancels pending edits and resets the field to null */\n clear: () => void;\n /** Enhanced onBlur function that flushes current value immediately */\n onBlur: () => void;\n /** Enhanced onChange function with debouncing */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => void;\n /** The field value that is displayed - updates immediately */\n value: TValue;\n}\n\n/**\n * Custom hook for debouncing value changes with immediate blur support.\n *\n * Provides immediate visual feedback by updating the value instantly,\n * while debouncing the actual onChange calls. When focus is lost,\n * any pending debounced changes are immediately flushed.\n *\n * **Key Features:**\n * - **Debouncing**: Delays onChange calls until user stops typing\n * - **Generic type support**: Works with any data type (strings, numbers, arrays, objects)\n * - **Immediate value updates**: UI stays responsive during debouncing\n * - **Blur flushing**: Immediately applies pending changes on blur\n *\n * **Note:** Value transformations should be handled at the private field-state level,\n * not in this hook. Clearing cancels queued edits before resetting the form field.\n *\n * @param options Configuration for debounced value handling\n * @param options.debounceDelay Delay in milliseconds (default: 300)\n * @param options.onBlur Function to call after flushing debounced value\n * @param options.onChange Function to call with debounced value\n * @param options.value The field value\n * @returns Object containing enhanced onChange, onBlur, and immediate value\n *\n * @example\n * Basic usage with debouncing:\n * ```tsx\n * const { onChange, onBlur, value } = useInputValueDebounce({\n * debounceDelay: 300,\n * name: 'fieldName',\n * onBlur: field.onBlur,\n * onChange: field.onChange,\n * value: field.value,\n * });\n * ```\n */\nexport const useInputValueDebounce = <TValue = unknown>({\n debounceDelay = 300,\n name,\n onBlur,\n onChange,\n value,\n emptyValue = value,\n}: UseInputValueDebounceOptions<TValue>): UseInputValueDebounceReturn<TValue> => {\n const { resetField, trigger } = useFormContext();\n\n // Track value for synchronous updates\n const [currentValue, setCurrentValue] = useState<TValue>(value);\n const [lastExternalValue, setLastExternalValue] = useState<TValue>(value);\n\n const timeoutRef = useRef<NodeJS.Timeout | null>(null);\n const cancelPendingChange = useCallback((nextValue: TValue) => {\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n }\n setCurrentValue(nextValue);\n }, []);\n\n // cancel queued edits before resetting, so they cannot restore the old value\n const clear = useCallback(() => {\n cancelPendingChange(emptyValue);\n resetField(name, { defaultValue: null });\n }, [cancelPendingChange, emptyValue, name, resetField]);\n\n useWatchFormReset({\n onReset: useCallback(() => {\n cancelPendingChange(value);\n }, [cancelPendingChange, value]),\n });\n\n // Keep the displayed value in sync during the same render when the form\n // replaces it (for example after reset), without an extra effect render.\n if (!Object.is(lastExternalValue, value)) {\n setLastExternalValue(value);\n setCurrentValue(value);\n }\n\n // Enhanced onChange handler with debouncing\n const handleChange = useCallback(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (...event: any[]) => {\n // Extract the raw value\n const newValue = (event[0]?.target?.value ?? event[0]) as TValue;\n setCurrentValue(newValue);\n\n // Clear existing timeout\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n }\n\n const executeOnChange = () => {\n // Preserve event structure if original was an event\n if (event[0]?.target) {\n const convertedEvent = {\n ...event[0],\n target: {\n ...event[0].target,\n value: newValue,\n },\n };\n onChange(convertedEvent, ...event.slice(1));\n } else {\n onChange(newValue);\n }\n // Trigger validation after debounced value commits\n // This ensures errors are updated immediately when field becomes valid\n trigger(name);\n };\n\n // Execute immediately or after delay\n if (debounceDelay <= 0) {\n executeOnChange();\n } else {\n timeoutRef.current = setTimeout(executeOnChange, debounceDelay);\n }\n },\n [onChange, debounceDelay, trigger, name],\n );\n\n // Enhanced blur handler\n const handleBlur = useCallback(() => {\n // Flush pending changes\n if (timeoutRef.current) {\n clearTimeout(timeoutRef.current);\n timeoutRef.current = null;\n onChange(currentValue);\n }\n onBlur();\n }, [onChange, onBlur, currentValue]);\n\n return {\n cancelPendingChange,\n clear,\n onChange: handleChange,\n onBlur: handleBlur,\n value: currentValue,\n };\n};\n","/* v8 ignore start */\n\nexport * from './useInputValueDebounce';\n\n/* v8 ignore stop */\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsEA,MAAa,yBAA2C,EACtD,gBAAgB,KAChB,MACA,QACA,UACA,OACA,aAAa,YACkE;CAC/E,MAAM,EAAE,YAAY,YAAY,eAAe;CAG/C,MAAM,CAAC,cAAc,mBAAmB,SAAiB,KAAK;CAC9D,MAAM,CAAC,mBAAmB,wBAAwB,SAAiB,KAAK;CAExE,MAAM,aAAa,OAA8B,IAAI;CACrD,MAAM,sBAAsB,aAAa,cAAsB;EAC7D,IAAI,WAAW,SAAS;GACtB,aAAa,WAAW,OAAO;GAC/B,WAAW,UAAU;EACvB;EACA,gBAAgB,SAAS;CAC3B,GAAG,CAAC,CAAC;CAGL,MAAM,QAAQ,kBAAkB;EAC9B,oBAAoB,UAAU;EAC9B,WAAW,MAAM,EAAE,cAAc,KAAK,CAAC;CACzC,GAAG;EAAC;EAAqB;EAAY;EAAM;CAAU,CAAC;CAEtD,kBAAkB,EAChB,SAAS,kBAAkB;EACzB,oBAAoB,KAAK;CAC3B,GAAG,CAAC,qBAAqB,KAAK,CAAC,EACjC,CAAC;CAID,IAAI,CAAC,OAAO,GAAG,mBAAmB,KAAK,GAAG;EACxC,qBAAqB,KAAK;EAC1B,gBAAgB,KAAK;CACvB;CAuDA,OAAO;EACL;EACA;EACA,UAvDmB,aAElB,GAAG,UAAiB;GAEnB,MAAM,WAAY,MAAM,EAAE,EAAE,QAAQ,SAAS,MAAM;GACnD,gBAAgB,QAAQ;GAGxB,IAAI,WAAW,SACb,aAAa,WAAW,OAAO;GAGjC,MAAM,wBAAwB;IAE5B,IAAI,MAAM,EAAE,EAAE,QAQZ,SAAS;KANP,GAAG,MAAM;KACT,QAAQ;MACN,GAAG,MAAM,EAAE,CAAC;MACZ,OAAO;KACT;IAEoB,GAAG,GAAG,MAAM,MAAM,CAAC,CAAC;SAE1C,SAAS,QAAQ;IAInB,QAAQ,IAAI;GACd;GAGA,IAAI,iBAAiB,GACnB,gBAAgB;QAEhB,WAAW,UAAU,WAAW,iBAAiB,aAAa;EAElE,GACA;GAAC;GAAU;GAAe;GAAS;EAAI,CAiBlB;EACrB,QAdiB,kBAAkB;GAEnC,IAAI,WAAW,SAAS;IACtB,aAAa,WAAW,OAAO;IAC/B,WAAW,UAAU;IACrB,SAAS,YAAY;GACvB;GACA,OAAO;EACT,GAAG;GAAC;GAAU;GAAQ;EAAY,CAMf;EACjB,OAAO;CACT;AACF"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import { i as useInputValueTransform, n as UseInputValueTransformOptions, r as UseInputValueTransformReturn, t as InputValueTransform } from "../../
|
|
2
|
-
import "../../index-CaxrMD1A.mjs";
|
|
1
|
+
import { i as useInputValueTransform, n as UseInputValueTransformOptions, r as UseInputValueTransformReturn, t as InputValueTransform } from "../../index-cevZBrIN.mjs";
|
|
3
2
|
export { InputValueTransform, UseInputValueTransformOptions, UseInputValueTransformReturn, useInputValueTransform };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/hooks/useInputValueTransform/index.ts
|
|
2
2
|
/* v8 ignore stop */
|
|
3
|
-
export { t as useInputValueTransform } from "../../useInputValueTransform-
|
|
3
|
+
export { t as useInputValueTransform } from "../../useInputValueTransform-CXWWFhy_.mjs";
|
|
4
4
|
|
|
5
5
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -100,4 +100,4 @@ interface UseInputValueTransformReturn<TDisplay = unknown> {
|
|
|
100
100
|
*/
|
|
101
101
|
declare const useInputValueTransform: <TDisplay = unknown>({ type, transform }: UseInputValueTransformOptions<TDisplay>) => UseInputValueTransformReturn<TDisplay>;
|
|
102
102
|
export { useInputValueTransform as i, UseInputValueTransformOptions as n, UseInputValueTransformReturn as r, InputValueTransform as t };
|
|
103
|
-
//# sourceMappingURL=
|
|
103
|
+
//# sourceMappingURL=index-cevZBrIN.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index-cevZBrIN.d.mts","names":[],"sources":["../src/hooks/useInputValueTransform/useInputValueTransform.ts"],"mappings":"A,UAEiB,oBAAoB;;EAEnC,iBAAiB,mBAAmB;;EAEpC,cAAc,OAAO;;UAGN,8BAA8B;;EAE7C,YAAY,oBAAoB;;EAEhC;;UAGe,6BAA6B;;EAE5C,iBAAiB,uBAAuB;;EAExC,cAAc,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqFjB,yBAA0B,sBAAoB,MAAA,aAGxD,8BAA8B,cAAY,6BAA6B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as default } from "../../FieldCopyTestIdButton-
|
|
1
|
+
export { t as default } from "../../FieldCopyTestIdButton-D3_jZYJ1.mjs";
|