@fuf-stack/uniform 1.28.0 → 2.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (148) hide show
  1. package/README.md +6 -35
  2. package/dist/Checkboxes/index.d.mts +192 -263
  3. package/dist/Checkboxes/index.d.mts.map +1 -1
  4. package/dist/Checkboxes/index.mjs +294 -90
  5. package/dist/Checkboxes/index.mjs.map +1 -1
  6. package/dist/DatePicker/index.d.mts +1278 -496
  7. package/dist/DatePicker/index.d.mts.map +1 -1
  8. package/dist/DatePicker/index.mjs +403 -83
  9. package/dist/DatePicker/index.mjs.map +1 -1
  10. package/dist/FieldArray/index.d.mts +105 -98
  11. package/dist/FieldArray/index.d.mts.map +1 -1
  12. package/dist/FieldArray/index.mjs +344 -195
  13. package/dist/FieldArray/index.mjs.map +1 -1
  14. package/dist/FieldCard/index.d.mts +37 -35
  15. package/dist/FieldCard/index.d.mts.map +1 -1
  16. package/dist/FieldCard/index.mjs +187 -128
  17. package/dist/FieldCard/index.mjs.map +1 -1
  18. package/dist/{FieldCopyTestIdButton-9xTF-DBW.mjs → FieldCopyTestIdButton-DV0tkdh2.mjs} +4 -2
  19. package/dist/FieldCopyTestIdButton-DV0tkdh2.mjs.map +1 -0
  20. package/dist/FieldDescription-C4l0HKGL.mjs +36 -0
  21. package/dist/FieldDescription-C4l0HKGL.mjs.map +1 -0
  22. package/dist/FieldLabel-DKzqkuY1.mjs +125 -0
  23. package/dist/FieldLabel-DKzqkuY1.mjs.map +1 -0
  24. package/dist/FieldLayout-BLW5S-Jm.mjs +46 -0
  25. package/dist/FieldLayout-BLW5S-Jm.mjs.map +1 -0
  26. package/dist/FieldValidationError-DgkCL3cC.mjs +77 -0
  27. package/dist/FieldValidationError-DgkCL3cC.mjs.map +1 -0
  28. package/dist/Form/index.d.mts +12 -12
  29. package/dist/Form/index.d.mts.map +1 -1
  30. package/dist/Form/index.mjs +9 -7
  31. package/dist/Form/index.mjs.map +1 -1
  32. package/dist/{FormContext-CB7Glm02.mjs → FormContext-CHctWFAP.mjs} +51 -8
  33. package/dist/FormContext-CHctWFAP.mjs.map +1 -0
  34. package/dist/FormContext-CsFiNvuJ.d.mts.map +1 -1
  35. package/dist/Grid/index.mjs +1 -2
  36. package/dist/{Grid-CTs-Rb9G.mjs → Grid-DfcZeuib.mjs} +4 -2
  37. package/dist/Grid-DfcZeuib.mjs.map +1 -0
  38. package/dist/Input/index.d.mts +638 -394
  39. package/dist/Input/index.d.mts.map +1 -1
  40. package/dist/Input/index.mjs +414 -165
  41. package/dist/Input/index.mjs.map +1 -1
  42. package/dist/RadioBoxes/index.d.mts +1588 -125
  43. package/dist/RadioBoxes/index.d.mts.map +1 -1
  44. package/dist/RadioBoxes/index.mjs +159 -114
  45. package/dist/RadioBoxes/index.mjs.map +1 -1
  46. package/dist/RadioTabs/index.d.mts +300 -81
  47. package/dist/RadioTabs/index.d.mts.map +1 -1
  48. package/dist/RadioTabs/index.mjs +277 -86
  49. package/dist/RadioTabs/index.mjs.map +1 -1
  50. package/dist/Radios/index.d.mts +1354 -109
  51. package/dist/Radios/index.d.mts.map +1 -1
  52. package/dist/Radios/index.mjs +105 -54
  53. package/dist/Radios/index.mjs.map +1 -1
  54. package/dist/Select/index.d.mts +554 -3009
  55. package/dist/Select/index.d.mts.map +1 -1
  56. package/dist/Select/index.mjs +319 -177
  57. package/dist/Select/index.mjs.map +1 -1
  58. package/dist/Slider/index.d.mts +416 -1328
  59. package/dist/Slider/index.d.mts.map +1 -1
  60. package/dist/Slider/index.mjs +276 -94
  61. package/dist/Slider/index.mjs.map +1 -1
  62. package/dist/SubmitButton/index.d.mts.map +1 -1
  63. package/dist/SubmitButton/index.mjs +4 -1
  64. package/dist/SubmitButton/index.mjs.map +1 -1
  65. package/dist/Switch/index.d.mts +2 -1248
  66. package/dist/Switch/index.mjs +167 -68
  67. package/dist/Switch/index.mjs.map +1 -1
  68. package/dist/Switch-CvPO8IF9.d.mts +601 -0
  69. package/dist/Switch-CvPO8IF9.d.mts.map +1 -0
  70. package/dist/SwitchBox/index.d.mts +135 -39
  71. package/dist/SwitchBox/index.d.mts.map +1 -1
  72. package/dist/SwitchBox/index.mjs +142 -87
  73. package/dist/SwitchBox/index.mjs.map +1 -1
  74. package/dist/TextArea/index.d.mts +295 -411
  75. package/dist/TextArea/index.d.mts.map +1 -1
  76. package/dist/TextArea/index.mjs +200 -48
  77. package/dist/TextArea/index.mjs.map +1 -1
  78. package/dist/Time/index.d.mts +1170 -601
  79. package/dist/Time/index.d.mts.map +1 -1
  80. package/dist/Time/index.mjs +162 -74
  81. package/dist/Time/index.mjs.map +1 -1
  82. package/dist/helpers/index.d.mts +1 -1
  83. package/dist/helpers/index.mjs +1 -1
  84. package/dist/helpers/index.mjs.map +1 -1
  85. package/dist/hooks/useClientValidation/index.mjs +1 -1
  86. package/dist/hooks/useController/index.d.mts +31 -3
  87. package/dist/hooks/useController/index.d.mts.map +1 -0
  88. package/dist/hooks/useController/index.mjs +1 -2
  89. package/dist/hooks/useFormContext/index.d.mts +65 -3
  90. package/dist/hooks/useFormContext/index.d.mts.map +1 -0
  91. package/dist/hooks/useFormContext/index.mjs +1 -2
  92. package/dist/hooks/useInputValueDebounce/index.d.mts +11 -5
  93. package/dist/hooks/useInputValueDebounce/index.d.mts.map +1 -1
  94. package/dist/hooks/useInputValueDebounce/index.mjs +27 -5
  95. package/dist/hooks/useInputValueDebounce/index.mjs.map +1 -1
  96. package/dist/hooks/useInputValueTransform/index.d.mts +1 -2
  97. package/dist/hooks/useInputValueTransform/index.mjs +1 -2
  98. package/dist/hooks/useWatchFormReset/index.mjs +1 -1
  99. package/dist/hooks/useWatchUserChange/index.d.mts +2 -2
  100. package/dist/hooks/useWatchUserChange/index.d.mts.map +1 -1
  101. package/dist/hooks/useWatchUserChange/index.mjs +1 -1
  102. package/dist/hooks/useWatchUserChange/index.mjs.map +1 -1
  103. package/dist/{useInputValueTransform-LOaEim7k.d.mts → index-BS8IoBOn.d.mts} +3 -3
  104. package/dist/index-BS8IoBOn.d.mts.map +1 -0
  105. package/dist/partials/FieldCopyTestIdButton/index.mjs +1 -2
  106. package/dist/partials/FieldValidationError/index.d.mts +637 -3
  107. package/dist/partials/FieldValidationError/index.d.mts.map +1 -1
  108. package/dist/partials/FieldValidationError/index.mjs +1 -2
  109. package/dist/radioControlVariants-Cm6WufWo.mjs +188 -0
  110. package/dist/radioControlVariants-Cm6WufWo.mjs.map +1 -0
  111. package/dist/switchVariants-BaQw2DA7.mjs +67 -0
  112. package/dist/switchVariants-BaQw2DA7.mjs.map +1 -0
  113. package/dist/timeVariants-B9HDfNYt.mjs +58 -0
  114. package/dist/timeVariants-B9HDfNYt.mjs.map +1 -0
  115. package/dist/{useController-BBSbeKbn.mjs → useController-BCFeZbBZ.mjs} +2 -2
  116. package/dist/{useController-BBSbeKbn.mjs.map → useController-BCFeZbBZ.mjs.map} +1 -1
  117. package/dist/{useFormContext-DNb_B8LQ.mjs → useFormContext-BPjJjNnM.mjs} +2 -2
  118. package/dist/{useFormContext-DNb_B8LQ.mjs.map → useFormContext-BPjJjNnM.mjs.map} +1 -1
  119. package/dist/{useInputValueTransform-DJ5zkqSy.mjs → useInputValueTransform-Mw8YEOXT.mjs} +2 -2
  120. package/dist/{useInputValueTransform-DJ5zkqSy.mjs.map → useInputValueTransform-Mw8YEOXT.mjs.map} +1 -1
  121. package/package.json +17 -29
  122. package/dist/FieldCopyTestIdButton-9xTF-DBW.mjs.map +0 -1
  123. package/dist/FieldValidationError-ByRoIxaM.mjs +0 -50
  124. package/dist/FieldValidationError-ByRoIxaM.mjs.map +0 -1
  125. package/dist/FormContext-CB7Glm02.mjs.map +0 -1
  126. package/dist/Grid-CTs-Rb9G.mjs.map +0 -1
  127. package/dist/Switch/index.d.mts.map +0 -1
  128. package/dist/hooks/useInput/index.d.mts +0 -2
  129. package/dist/hooks/useInput/index.mjs +0 -7
  130. package/dist/hooks/useInput/index.mjs.map +0 -1
  131. package/dist/hooks/useUniformField/index.d.mts +0 -100
  132. package/dist/hooks/useUniformField/index.d.mts.map +0 -1
  133. package/dist/hooks/useUniformField/index.mjs +0 -139
  134. package/dist/hooks/useUniformField/index.mjs.map +0 -1
  135. package/dist/hooks/useUniformFieldArray/index.d.mts +0 -73
  136. package/dist/hooks/useUniformFieldArray/index.d.mts.map +0 -1
  137. package/dist/hooks/useUniformFieldArray/index.mjs +0 -101
  138. package/dist/hooks/useUniformFieldArray/index.mjs.map +0 -1
  139. package/dist/index-CAdGtKE_.d.mts +0 -1
  140. package/dist/index-CaxrMD1A.d.mts +0 -1
  141. package/dist/index-CwJo1b4Z.d.mts +0 -1
  142. package/dist/useController-DcK2YHbw.d.mts +0 -32
  143. package/dist/useController-DcK2YHbw.d.mts.map +0 -1
  144. package/dist/useFormContext-BegmYvGA.d.mts +0 -66
  145. package/dist/useFormContext-BegmYvGA.d.mts.map +0 -1
  146. package/dist/useInput-C0aJaAGe.mjs +0 -2
  147. package/dist/useInput-ClpHDPdr.d.mts +0 -2
  148. package/dist/useInputValueTransform-LOaEim7k.d.mts.map +0 -1
@@ -1,3 +1,65 @@
1
- import { n as useFormContext, t as checkFieldIsRequired } from "../../useFormContext-BegmYvGA.mjs";
2
- import "../../index-CwJo1b4Z.mjs";
3
- export { checkFieldIsRequired, useFormContext };
1
+ import { n as FormResetListener, r as UserChangeListener, t as DebugModeSettings } from "../../FormContext-CsFiNvuJ.mjs";
2
+ import { FieldError, FieldValues, Path } from "react-hook-form";
3
+ import { VetoFormattedError, VetoInstance } from "@fuf-stack/veto";
4
+ //#region src/hooks/useFormContext/useFormContext.d.ts
5
+ /** Schema check whether a field is required or optional */
6
+ export declare const checkFieldIsRequired: (validation: VetoInstance, path: string[]) => boolean;
7
+ /**
8
+ * Custom hook that extends react-hook-form's useFormContext to add validation and state management.
9
+ *
10
+ * Key features:
11
+ * - Enhanced `getFieldState` that includes validation schema-based "required" status and testId generation
12
+ * - Automatic conversion of form values via `getValues`, `watch`, and `subscribe`:
13
+ * - Unwraps flat array wrappers (`{ __FLAT__: value }` → `value`)
14
+ * - Converts nullish string markers (`__NULL__` → `null`, `__FALSE__` → `false`, `__ZERO__` → `0`)
15
+ * - Filters out empty/null values
16
+ */
17
+ export declare const useFormContext: <TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues>() => {
18
+ formState: import("react-hook-form").FormState<TFieldValues>;
19
+ getFieldState: (name: Path<TFieldValues>, testId?: string) => {
20
+ error: FieldError[] | undefined;
21
+ invalid: boolean;
22
+ required: boolean;
23
+ testId: string;
24
+ isDirty: boolean;
25
+ isTouched: boolean;
26
+ isValidating: boolean;
27
+ };
28
+ getValues: import("react-hook-form").UseFormGetValues<TFieldValues>;
29
+ reset: import("react-hook-form").UseFormReset<TFieldValues>;
30
+ subscribe: import("react-hook-form").UseFormSubscribe<TFieldValues>;
31
+ watch: import("react-hook-form").UseFormWatch<TFieldValues>;
32
+ debugMode: "debug" | "debug-testids" | "off" | "disabled";
33
+ debugModeSettings?: DebugModeSettings;
34
+ formReset: {
35
+ subscribe: (listener: FormResetListener) => () => void;
36
+ notify: () => void;
37
+ };
38
+ preventSubmit: (prevent: boolean) => void;
39
+ setDebugMode: (debugMode: "debug" | "debug-testids" | "off" | "disabled") => void;
40
+ triggerSubmit: (e?: import("react").BaseSyntheticEvent) => Promise<void> | void;
41
+ userChange: {
42
+ subscribe: (listener: UserChangeListener) => () => void;
43
+ notify: (fieldName: string, value: unknown) => void;
44
+ };
45
+ validation: {
46
+ baseInstance?: VetoInstance;
47
+ instance?: VetoInstance;
48
+ errors?: VetoFormattedError;
49
+ setClientValidationSchema: (key: string, schema: import("@fuf-stack/veto").VetoTypeAny | null) => void;
50
+ };
51
+ setError: import("react-hook-form").UseFormSetError<TFieldValues>;
52
+ clearErrors: import("react-hook-form").UseFormClearErrors<TFieldValues>;
53
+ setValue: import("react-hook-form").UseFormSetValue<TFieldValues>;
54
+ setValues: import("react-hook-form").UseFormSetValues<TFieldValues>;
55
+ trigger: import("react-hook-form").UseFormTrigger<TFieldValues>;
56
+ resetField: import("react-hook-form").UseFormResetField<TFieldValues>;
57
+ resetDefaultValues: import("react-hook-form").UseFormResetDefaultValues<TFieldValues>;
58
+ handleSubmit: import("react-hook-form").UseFormHandleSubmit<TFieldValues, TTransformedValues>;
59
+ unregister: import("react-hook-form").UseFormUnregister<TFieldValues>;
60
+ control: import("react-hook-form").Control<TFieldValues, TContext, TTransformedValues>;
61
+ register: import("react-hook-form").UseFormRegister<TFieldValues>;
62
+ setFocus: import("react-hook-form").UseFormSetFocus<TFieldValues>;
63
+ };
64
+ //#endregion
65
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","names":["_$______Form_subcomponents_FormContext0.DebugModeSettings","_$______Form_subcomponents_FormContext0.FormResetListener","_$______Form_subcomponents_FormContext0.UserChangeListener"],"sources":["../../../src/hooks/useFormContext/useFormContext.ts"],"mappings":";;;;;qBAYa,uBACX,YAAY,cACZ;;;;;;;;;;;qBAmEW,iBACX,qBAAqB,cAAc,aACnC,gBACA,qBAAqB;;EAoCQ,gBAAA,MAAA,KAAK,eAAa;;;;;;;;;;;;;;;;;;;;;EA6B7C,gBAAA,oBAAC,uBAAA;;0BAAAE;;;;IAeD,eAAD;IAEA,WAAC;IAGC,SAAC"}
@@ -1,7 +1,6 @@
1
- import { n as useFormContext, t as checkFieldIsRequired } from "../../useFormContext-DNb_B8LQ.mjs";
2
1
  //#region src/hooks/useFormContext/index.ts
3
2
  /* v8 ignore stop */
4
3
  //#endregion
5
- export { checkFieldIsRequired, useFormContext };
4
+ export { t as checkFieldIsRequired, n as useFormContext } from "../../useFormContext-BPjJjNnM.mjs";
6
5
 
7
6
  //# sourceMappingURL=index.mjs.map
@@ -2,6 +2,8 @@
2
2
  export interface UseInputValueDebounceOptions<TValue = unknown> {
3
3
  /** Debounce delay in milliseconds (default: 300) */
4
4
  debounceDelay?: number;
5
+ /** Immediate display value when cleared, otherwise follows the reset form value */
6
+ emptyValue?: TValue;
5
7
  /** Field name for triggering validation after debounced value commits */
6
8
  name: string;
7
9
  /** The onBlur function to call after flushing debounced value */
@@ -12,10 +14,14 @@ export interface UseInputValueDebounceOptions<TValue = unknown> {
12
14
  value: TValue;
13
15
  }
14
16
  export interface UseInputValueDebounceReturn<TValue = unknown> {
15
- /** Enhanced onChange function with debouncing */
16
- onChange: (...event: any[]) => void;
17
+ /** Cancel queued edits and replace only the displayed value (for clear/reset). */
18
+ cancelPendingChange: (value: TValue) => void;
19
+ /** Cancels pending edits and resets the field to null */
20
+ clear: () => void;
17
21
  /** Enhanced onBlur function that flushes current value immediately */
18
22
  onBlur: () => void;
23
+ /** Enhanced onChange function with debouncing */
24
+ onChange: (...event: any[]) => void;
19
25
  /** The field value that is displayed - updates immediately */
20
26
  value: TValue;
21
27
  }
@@ -32,8 +38,8 @@ export interface UseInputValueDebounceReturn<TValue = unknown> {
32
38
  * - **Immediate value updates**: UI stays responsive during debouncing
33
39
  * - **Blur flushing**: Immediately applies pending changes on blur
34
40
  *
35
- * **Note:** Value transformations should be handled at the `useUniformField` level,
36
- * not in this hook. This hook only handles debouncing timing.
41
+ * **Note:** Value transformations should be handled at the private field-state level,
42
+ * not in this hook. Clearing cancels queued edits before resetting the form field.
37
43
  *
38
44
  * @param options Configuration for debounced value handling
39
45
  * @param options.debounceDelay Delay in milliseconds (default: 300)
@@ -54,6 +60,6 @@ export interface UseInputValueDebounceReturn<TValue = unknown> {
54
60
  * });
55
61
  * ```
56
62
  */
57
- export declare const useInputValueDebounce: <TValue = unknown>({ debounceDelay, name, onBlur, onChange, value }: UseInputValueDebounceOptions<TValue>) => UseInputValueDebounceReturn<TValue>;
63
+ export declare const useInputValueDebounce: <TValue = unknown>({ debounceDelay, name, onBlur, onChange, value, emptyValue }: UseInputValueDebounceOptions<TValue>) => UseInputValueDebounceReturn<TValue>;
58
64
  //#endregion
59
65
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/hooks/useInputValueDebounce/useInputValueDebounce.ts"],"mappings":";iBAIiB,6BAA6B;;EAE5C;;EAEA;;EAEA;;EAGA,cAAc;;EAEd,OAAO;;iBAGQ,4BAA4B;;EAG3C,cAAc;;EAEd;;EAEA,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBAsCI,wBAAyB,oBAAkB,eAAA,MAAA,QAAA,UAAA,SAMrD,6BAA6B,YAAU,4BAA4B"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/hooks/useInputValueDebounce/useInputValueDebounce.ts"],"mappings":";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-DNb_B8LQ.mjs";
1
+ import { n as useFormContext } from "../../useFormContext-BPjJjNnM.mjs";
2
+ import { useWatchFormReset } from "../useWatchFormReset/index.mjs";
2
3
  import { useCallback, useRef, useState } from "react";
3
4
  //#region 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 `useUniformField` level,
18
- * not in this hook. This hook only handles debouncing timing.
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 onChange function with debouncing */\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => void;\n /** Enhanced onBlur function that flushes current value immediately */\n onBlur: () => 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 `useUniformField` level,\n * not in this hook. This hook only handles debouncing timing.\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}: UseInputValueDebounceOptions<TValue>): UseInputValueDebounceReturn<TValue> => {\n const { 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\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 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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+DA,MAAa,yBAA2C,EACtD,gBAAgB,KAChB,MACA,QACA,UACA,YAC+E;CAC/E,MAAM,EAAE,YAAY,eAAe;CAGnC,MAAM,CAAC,cAAc,mBAAmB,SAAiB,KAAK;CAC9D,MAAM,CAAC,mBAAmB,wBAAwB,SAAiB,KAAK;CAExE,MAAM,aAAa,OAA8B,IAAI;CAIrD,IAAI,CAAC,OAAO,GAAG,mBAAmB,KAAK,GAAG;EACxC,qBAAqB,KAAK;EAC1B,gBAAgB,KAAK;CACvB;CAuDA,OAAO;EACL,UArDmB,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,CAelB;EACrB,QAZiB,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,CAIf;EACjB,OAAO;CACT;AACF"}
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 "../../useInputValueTransform-LOaEim7k.mjs";
2
- import "../../index-CaxrMD1A.mjs";
1
+ import { i as useInputValueTransform, n as UseInputValueTransformOptions, r as UseInputValueTransformReturn, t as InputValueTransform } from "../../index-BS8IoBOn.mjs";
3
2
  export { InputValueTransform, UseInputValueTransformOptions, UseInputValueTransformReturn, useInputValueTransform };
@@ -1,7 +1,6 @@
1
- import { t as useInputValueTransform } from "../../useInputValueTransform-DJ5zkqSy.mjs";
2
1
  //#region src/hooks/useInputValueTransform/index.ts
3
2
  /* v8 ignore stop */
4
3
  //#endregion
5
- export { useInputValueTransform };
4
+ export { t as useInputValueTransform } from "../../useInputValueTransform-Mw8YEOXT.mjs";
6
5
 
7
6
  //# sourceMappingURL=index.mjs.map
@@ -1,4 +1,4 @@
1
- import { n as useFormContext } from "../../useFormContext-DNb_B8LQ.mjs";
1
+ import { n as useFormContext } from "../../useFormContext-BPjJjNnM.mjs";
2
2
  import { useEffect } from "react";
3
3
  //#region src/hooks/useWatchFormReset/useWatchFormReset.ts
4
4
  /**
@@ -1,8 +1,6 @@
1
1
  import { FieldValues, Path, UseFormReset, UseFormResetField, UseFormSetValue } from "react-hook-form";
2
2
  //#region src/hooks/useWatchUserChange/useWatchUserChange.d.ts
3
3
  export interface UseWatchUserChangeOptions<TFieldValues extends FieldValues> {
4
- /** Field name to watch for user changes */
5
- watch: Path<TFieldValues>;
6
4
  /**
7
5
  * Callback when watched field is changed by user input.
8
6
  * Receives the new value and form helpers (setValue, resetField, reset).
@@ -12,6 +10,8 @@ export interface UseWatchUserChangeOptions<TFieldValues extends FieldValues> {
12
10
  resetField: UseFormResetField<TFieldValues>;
13
11
  reset: UseFormReset<TFieldValues>;
14
12
  }) => void;
13
+ /** Field name to watch for user changes */
14
+ watch: Path<TFieldValues>;
15
15
  }
16
16
  /**
17
17
  * Hook that watches for user changes on a specific form field.
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/hooks/useWatchUserChange/useWatchUserChange.ts"],"mappings":";;iBAYiB,0BAA0B,qBAAqB;;EAE9D,OAAO,KAAK;;;;;EAKZ,WACE,gBACA;IACE,UAAU,gBAAgB;IAC1B,YAAY,kBAAkB;IAC9B,OAAO,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA8Db,qBACX,qBAAqB,cAAc,eACnC,OAAA,YAAA,YAGC,0BAA0B"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/hooks/useWatchUserChange/useWatchUserChange.ts"],"mappings":";;iBAYiB,0BAA0B,qBAAqB;;;;;EAK9D,WACE,gBACA;IACE,UAAU,gBAAgB;IAC1B,YAAY,kBAAkB;IAC9B,OAAO,aAAa;;;EAIxB,OAAO,KAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA4DD,qBACX,qBAAqB,cAAc,eACnC,OAAA,YAAA,YAGC,0BAA0B"}
@@ -1,4 +1,4 @@
1
- import { n as useFormContext } from "../../useFormContext-DNb_B8LQ.mjs";
1
+ import { n as useFormContext } from "../../useFormContext-BPjJjNnM.mjs";
2
2
  import { useEffect, useRef } from "react";
3
3
  //#region src/hooks/useWatchUserChange/useWatchUserChange.ts
4
4
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/hooks/useWatchUserChange/useWatchUserChange.ts","../../../src/hooks/useWatchUserChange/index.ts"],"sourcesContent":["import type {\n FieldValues,\n Path,\n UseFormReset,\n UseFormResetField,\n UseFormSetValue,\n} from 'react-hook-form';\n\nimport { useEffect, useRef } from 'react';\n\nimport { useFormContext } from '../useFormContext/useFormContext';\n\nexport interface UseWatchUserChangeOptions<TFieldValues extends FieldValues> {\n /** Field name to watch for user changes */\n watch: Path<TFieldValues>;\n /**\n * Callback when watched field is changed by user input.\n * Receives the new value and form helpers (setValue, resetField, reset).\n */\n onChange: (\n value: unknown,\n helpers: {\n setValue: UseFormSetValue<TFieldValues>;\n resetField: UseFormResetField<TFieldValues>;\n reset: UseFormReset<TFieldValues>;\n },\n ) => void;\n}\n\n/**\n * Hook that watches for user changes on a specific form field.\n *\n * Only triggers on manual user input (typing, clicking, selecting),\n * NOT on programmatic changes like form.reset() or form.setValue().\n * Also does NOT trigger when selecting the same value (e.g., clicking\n * an already-selected option in a Select).\n *\n * This hook subscribes to field changes at the source (useController),\n * ensuring immediate and accurate detection of user interactions.\n *\n * Use cases:\n * - Reset dependent fields when parent field changes\n * - Set mode-specific default values when a toggle changes\n * - Clear form sections based on user selections\n * - Trigger side effects only on user interaction\n *\n * Note: To watch multiple fields, call this hook multiple times.\n *\n * @example\n * ```tsx\n * // Reset city and address when user changes country\n * useWatchUserChange({\n * watch: 'country',\n * onChange: (value, { resetField }) => {\n * resetField('city');\n * resetField('address');\n * },\n * });\n *\n * // Set defaults when user changes payment method\n * useWatchUserChange({\n * watch: 'paymentMethod',\n * onChange: (value, { setValue }) => {\n * if (value === 'credit') {\n * setValue('installments', 3);\n * } else {\n * setValue('installments', 1);\n * }\n * },\n * });\n *\n * // Watch multiple fields by calling the hook multiple times\n * useWatchUserChange({\n * watch: 'category',\n * onChange: (value, { resetField }) => {\n * resetField('productId');\n * },\n * });\n * useWatchUserChange({\n * watch: 'brand',\n * onChange: (value, { resetField }) => {\n * resetField('productId');\n * },\n * });\n * ```\n */\nexport const useWatchUserChange = <\n TFieldValues extends FieldValues = FieldValues,\n>({\n watch: watchField,\n onChange,\n}: UseWatchUserChangeOptions<TFieldValues>) => {\n const { setValue, resetField, reset, userChange } =\n useFormContext<TFieldValues>();\n\n // Callers commonly pass an inline callback, and useFormContext may return new\n // helper wrappers after a form render. Keep their latest values in a ref so\n // those identity changes do not tear down and recreate the subscription.\n const callbackRef = useRef({ onChange, reset, resetField, setValue });\n\n useEffect(() => {\n callbackRef.current = { onChange, reset, resetField, setValue };\n }, [onChange, reset, resetField, setValue]);\n\n // The subscribe function is stable even when the surrounding userChange\n // object is reconstructed. Depending on it directly keeps one active listener.\n const { subscribe } = userChange;\n\n useEffect(() => {\n // Create listener that checks if changed field is the one we're watching\n const listener = (fieldName: Path<TFieldValues>, value: unknown) => {\n // Check if this is the field we're watching\n if (fieldName === watchField) {\n // Read at notification time so the stable listener never closes over a\n // stale callback or stale form helpers.\n const { onChange: callback, ...helpers } = callbackRef.current;\n callback(value, helpers);\n }\n };\n\n // Subscribe to user changes\n const unsubscribe = subscribe(listener);\n\n // Cleanup on unmount\n return unsubscribe;\n }, [subscribe, watchField]);\n};\n","/* v8 ignore start */\n\nexport * from './useWatchUserChange';\n\n/* v8 ignore stop */\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,MAAa,sBAEX,EACA,OAAO,YACP,eAC6C;CAC7C,MAAM,EAAE,UAAU,YAAY,OAAO,eACnC,eAA6B;CAK/B,MAAM,cAAc,OAAO;EAAE;EAAU;EAAO;EAAY;CAAS,CAAC;CAEpE,gBAAgB;EACd,YAAY,UAAU;GAAE;GAAU;GAAO;GAAY;EAAS;CAChE,GAAG;EAAC;EAAU;EAAO;EAAY;CAAQ,CAAC;CAI1C,MAAM,EAAE,cAAc;CAEtB,gBAAgB;EAEd,MAAM,YAAY,WAA+B,UAAmB;GAElE,IAAI,cAAc,YAAY;IAG5B,MAAM,EAAE,UAAU,UAAU,GAAG,YAAY,YAAY;IACvD,SAAS,OAAO,OAAO;GACzB;EACF;EAMA,OAHoB,UAAU,QAGb;CACnB,GAAG,CAAC,WAAW,UAAU,CAAC;AAC5B"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/hooks/useWatchUserChange/useWatchUserChange.ts","../../../src/hooks/useWatchUserChange/index.ts"],"sourcesContent":["import type {\n FieldValues,\n Path,\n UseFormReset,\n UseFormResetField,\n UseFormSetValue,\n} from 'react-hook-form';\n\nimport { useEffect, useRef } from 'react';\n\nimport { useFormContext } from '../useFormContext/useFormContext';\n\nexport interface UseWatchUserChangeOptions<TFieldValues extends FieldValues> {\n /**\n * Callback when watched field is changed by user input.\n * Receives the new value and form helpers (setValue, resetField, reset).\n */\n onChange: (\n value: unknown,\n helpers: {\n setValue: UseFormSetValue<TFieldValues>;\n resetField: UseFormResetField<TFieldValues>;\n reset: UseFormReset<TFieldValues>;\n },\n ) => void;\n /** Field name to watch for user changes */\n watch: Path<TFieldValues>;\n}\n\n/**\n * Hook that watches for user changes on a specific form field.\n *\n * Only triggers on manual user input (typing, clicking, selecting),\n * NOT on programmatic changes like form.reset() or form.setValue().\n * Also does NOT trigger when selecting the same value (e.g., clicking\n * an already-selected option in a Select).\n *\n * This hook subscribes to field changes at the source (useController),\n * ensuring immediate and accurate detection of user interactions.\n *\n * Use cases:\n * - Reset dependent fields when parent field changes\n * - Set mode-specific default values when a toggle changes\n * - Clear form sections based on user selections\n * - Trigger side effects only on user interaction\n *\n * Note: To watch multiple fields, call this hook multiple times.\n *\n * @example\n * ```tsx\n * // Reset city and address when user changes country\n * useWatchUserChange({\n * watch: 'country',\n * onChange: (value, { resetField }) => {\n * resetField('city');\n * resetField('address');\n * },\n * });\n *\n * // Set defaults when user changes payment method\n * useWatchUserChange({\n * watch: 'paymentMethod',\n * onChange: (value, { setValue }) => {\n * if (value === 'credit') {\n * setValue('installments', 3);\n * } else {\n * setValue('installments', 1);\n * }\n * },\n * });\n *\n * // Watch multiple fields by calling the hook multiple times\n * useWatchUserChange({\n * watch: 'category',\n * onChange: (value, { resetField }) => {\n * resetField('productId');\n * },\n * });\n * useWatchUserChange({\n * watch: 'brand',\n * onChange: (value, { resetField }) => {\n * resetField('productId');\n * },\n * });\n * ```\n */\nexport const useWatchUserChange = <\n TFieldValues extends FieldValues = FieldValues,\n>({\n watch: watchField,\n onChange,\n}: UseWatchUserChangeOptions<TFieldValues>) => {\n const { setValue, resetField, reset, userChange } =\n useFormContext<TFieldValues>();\n\n // Callers commonly pass an inline callback, and useFormContext may return new\n // helper wrappers after a form render. Keep their latest values in a ref so\n // those identity changes do not tear down and recreate the subscription.\n const callbackRef = useRef({ onChange, reset, resetField, setValue });\n\n useEffect(() => {\n callbackRef.current = { onChange, reset, resetField, setValue };\n }, [onChange, reset, resetField, setValue]);\n\n // The subscribe function is stable even when the surrounding userChange\n // object is reconstructed. Depending on it directly keeps one active listener.\n const { subscribe } = userChange;\n\n useEffect(() => {\n // Create listener that checks if changed field is the one we're watching\n const listener = (fieldName: Path<TFieldValues>, value: unknown) => {\n // Check if this is the field we're watching\n if (fieldName === watchField) {\n // Read at notification time so the stable listener never closes over a\n // stale callback or stale form helpers.\n const { onChange: callback, ...helpers } = callbackRef.current;\n callback(value, helpers);\n }\n };\n\n // Subscribe to user changes\n const unsubscribe = subscribe(listener);\n\n // Cleanup on unmount\n return unsubscribe;\n }, [subscribe, watchField]);\n};\n","/* v8 ignore start */\n\nexport * from './useWatchUserChange';\n\n/* v8 ignore stop */\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsFA,MAAa,sBAEX,EACA,OAAO,YACP,eAC6C;CAC7C,MAAM,EAAE,UAAU,YAAY,OAAO,eACnC,eAA6B;CAK/B,MAAM,cAAc,OAAO;EAAE;EAAU;EAAO;EAAY;CAAS,CAAC;CAEpE,gBAAgB;EACd,YAAY,UAAU;GAAE;GAAU;GAAO;GAAY;EAAS;CAChE,GAAG;EAAC;EAAU;EAAO;EAAY;CAAQ,CAAC;CAI1C,MAAM,EAAE,cAAc;CAEtB,gBAAgB;EAEd,MAAM,YAAY,WAA+B,UAAmB;GAElE,IAAI,cAAc,YAAY;IAG5B,MAAM,EAAE,UAAU,UAAU,GAAG,YAAY,YAAY;IACvD,SAAS,OAAO,OAAO;GACzB;EACF;EAMA,OAHoB,UAAU,QAGb;CACnB,GAAG,CAAC,WAAW,UAAU,CAAC;AAC5B"}
@@ -6,10 +6,10 @@ interface InputValueTransform<TDisplay = unknown> {
6
6
  toFormValue: (value: TDisplay) => unknown;
7
7
  }
8
8
  interface UseInputValueTransformOptions<TDisplay = unknown> {
9
- /** Input type for special number handling */
10
- type?: 'text' | 'number' | 'password';
11
9
  /** Value transformation functions */
12
10
  transform?: InputValueTransform<TDisplay>;
11
+ /** Input type for special number handling */
12
+ type?: 'text' | 'number' | 'password';
13
13
  }
14
14
  interface UseInputValueTransformReturn<TDisplay = unknown> {
15
15
  /** Converts any form value to display value */
@@ -102,4 +102,4 @@ interface UseInputValueTransformReturn<TDisplay = unknown> {
102
102
  declare const useInputValueTransform: <TDisplay = unknown>({ type, transform }: UseInputValueTransformOptions<TDisplay>) => UseInputValueTransformReturn<TDisplay>;
103
103
  //#endregion
104
104
  export { useInputValueTransform as i, UseInputValueTransformOptions as n, UseInputValueTransformReturn as r, InputValueTransform as t };
105
- //# sourceMappingURL=useInputValueTransform-LOaEim7k.d.mts.map
105
+ //# sourceMappingURL=index-BS8IoBOn.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-BS8IoBOn.d.mts","names":[],"sources":["../src/hooks/useInputValueTransform/useInputValueTransform.ts"],"mappings":";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,2 +1 @@
1
- import { t as FieldCopyTestIdButton_default } from "../../FieldCopyTestIdButton-9xTF-DBW.mjs";
2
- export { FieldCopyTestIdButton_default as default };
1
+ export { t as default } from "../../FieldCopyTestIdButton-DV0tkdh2.mjs";