@fuf-stack/uniform 1.27.0 → 1.28.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 (145) hide show
  1. package/README.md +9 -0
  2. package/dist/Checkboxes/index.d.mts +11 -13
  3. package/dist/Checkboxes/index.d.mts.map +1 -1
  4. package/dist/Checkboxes/index.mjs +2 -4
  5. package/dist/Checkboxes/index.mjs.map +1 -1
  6. package/dist/DatePicker/index.d.mts +14 -16
  7. package/dist/DatePicker/index.d.mts.map +1 -1
  8. package/dist/DatePicker/index.mjs +3 -6
  9. package/dist/DatePicker/index.mjs.map +1 -1
  10. package/dist/FieldArray/index.d.mts +2 -8
  11. package/dist/FieldArray/index.d.mts.map +1 -1
  12. package/dist/FieldArray/index.mjs +12 -22
  13. package/dist/FieldArray/index.mjs.map +1 -1
  14. package/dist/FieldCard/index.d.mts +0 -2
  15. package/dist/FieldCard/index.d.mts.map +1 -1
  16. package/dist/FieldCard/index.mjs +5 -8
  17. package/dist/FieldCard/index.mjs.map +1 -1
  18. package/dist/{FieldCopyTestIdButton-CRJBix9D.mjs → FieldCopyTestIdButton-Y9SfvaM9.mjs} +4 -6
  19. package/dist/{FieldCopyTestIdButton-CRJBix9D.mjs.map → FieldCopyTestIdButton-Y9SfvaM9.mjs.map} +1 -1
  20. package/dist/{FieldValidationError-ByRoIxaM.mjs → FieldValidationError-BcUV0r1I.mjs} +3 -5
  21. package/dist/{FieldValidationError-ByRoIxaM.mjs.map → FieldValidationError-BcUV0r1I.mjs.map} +1 -1
  22. package/dist/Form/index.d.mts +1 -3
  23. package/dist/Form/index.d.mts.map +1 -1
  24. package/dist/Form/index.mjs +10 -12
  25. package/dist/Form/index.mjs.map +1 -1
  26. package/dist/FormContext-B8G_Xxd6.mjs +512 -0
  27. package/dist/FormContext-B8G_Xxd6.mjs.map +1 -0
  28. package/dist/FormContext-BnNJYZOo.d.mts +124 -0
  29. package/dist/FormContext-BnNJYZOo.d.mts.map +1 -0
  30. package/dist/Grid/index.d.mts +0 -2
  31. package/dist/Grid/index.d.mts.map +1 -1
  32. package/dist/Grid/index.mjs +1 -2
  33. package/dist/{Grid-CTs-Rb9G.mjs → Grid-Us2JFczS.mjs} +3 -5
  34. package/dist/{Grid-CTs-Rb9G.mjs.map → Grid-Us2JFczS.mjs.map} +1 -1
  35. package/dist/Input/index.d.mts +21 -19
  36. package/dist/Input/index.d.mts.map +1 -1
  37. package/dist/Input/index.mjs +106 -13
  38. package/dist/Input/index.mjs.map +1 -1
  39. package/dist/RadioBoxes/index.d.mts +2 -6
  40. package/dist/RadioBoxes/index.d.mts.map +1 -1
  41. package/dist/RadioBoxes/index.mjs +3 -6
  42. package/dist/RadioBoxes/index.mjs.map +1 -1
  43. package/dist/RadioTabs/index.d.mts +46 -48
  44. package/dist/RadioTabs/index.d.mts.map +1 -1
  45. package/dist/RadioTabs/index.mjs +2 -4
  46. package/dist/RadioTabs/index.mjs.map +1 -1
  47. package/dist/Radios/index.d.mts +14 -16
  48. package/dist/Radios/index.d.mts.map +1 -1
  49. package/dist/Radios/index.mjs +2 -4
  50. package/dist/Radios/index.mjs.map +1 -1
  51. package/dist/Select/index.d.mts +5 -7
  52. package/dist/Select/index.d.mts.map +1 -1
  53. package/dist/Select/index.mjs +4 -7
  54. package/dist/Select/index.mjs.map +1 -1
  55. package/dist/Slider/index.d.mts +31 -33
  56. package/dist/Slider/index.d.mts.map +1 -1
  57. package/dist/Slider/index.mjs +2 -4
  58. package/dist/Slider/index.mjs.map +1 -1
  59. package/dist/SubmitButton/index.d.mts +0 -2
  60. package/dist/SubmitButton/index.d.mts.map +1 -1
  61. package/dist/SubmitButton/index.mjs +2 -4
  62. package/dist/SubmitButton/index.mjs.map +1 -1
  63. package/dist/Switch/index.d.mts +16 -18
  64. package/dist/Switch/index.d.mts.map +1 -1
  65. package/dist/Switch/index.mjs +2 -4
  66. package/dist/Switch/index.mjs.map +1 -1
  67. package/dist/SwitchBox/index.d.mts +35 -37
  68. package/dist/SwitchBox/index.d.mts.map +1 -1
  69. package/dist/SwitchBox/index.mjs +2 -4
  70. package/dist/SwitchBox/index.mjs.map +1 -1
  71. package/dist/TextArea/index.d.mts +0 -2
  72. package/dist/TextArea/index.d.mts.map +1 -1
  73. package/dist/TextArea/index.mjs +2 -4
  74. package/dist/TextArea/index.mjs.map +1 -1
  75. package/dist/Time/index.d.mts +0 -2
  76. package/dist/Time/index.d.mts.map +1 -1
  77. package/dist/Time/index.mjs +3 -6
  78. package/dist/Time/index.mjs.map +1 -1
  79. package/dist/helpers/index.d.mts +0 -6
  80. package/dist/helpers/index.d.mts.map +1 -1
  81. package/dist/helpers/index.mjs +3 -6
  82. package/dist/helpers/index.mjs.map +1 -1
  83. package/dist/hooks/useClientValidation/index.d.mts +0 -2
  84. package/dist/hooks/useClientValidation/index.d.mts.map +1 -1
  85. package/dist/hooks/useClientValidation/index.mjs +3 -5
  86. package/dist/hooks/useController/index.d.mts +1 -2
  87. package/dist/hooks/useController/index.mjs +2 -4
  88. package/dist/hooks/useFormContext/index.d.mts +2 -3
  89. package/dist/hooks/useFormContext/index.mjs +2 -4
  90. package/dist/hooks/useInput/index.mjs +2 -4
  91. package/dist/hooks/useInputValueDebounce/index.d.mts +2 -4
  92. package/dist/hooks/useInputValueDebounce/index.d.mts.map +1 -1
  93. package/dist/hooks/useInputValueDebounce/index.mjs +3 -5
  94. package/dist/hooks/useInputValueDebounce/index.mjs.map +1 -1
  95. package/dist/hooks/useInputValueTransform/index.d.mts +1 -1
  96. package/dist/hooks/useInputValueTransform/index.mjs +2 -4
  97. package/dist/hooks/useUniformField/index.d.mts +2 -98
  98. package/dist/hooks/useUniformField/index.mjs +11 -11
  99. package/dist/hooks/useUniformField/index.mjs.map +1 -1
  100. package/dist/hooks/useUniformFieldArray/index.d.mts +23 -49
  101. package/dist/hooks/useUniformFieldArray/index.d.mts.map +1 -1
  102. package/dist/hooks/useUniformFieldArray/index.mjs +3 -5
  103. package/dist/hooks/useUniformFieldArray/index.mjs.map +1 -1
  104. package/dist/hooks/useWatchFormReset/index.d.mts +0 -2
  105. package/dist/hooks/useWatchFormReset/index.d.mts.map +1 -1
  106. package/dist/hooks/useWatchFormReset/index.mjs +3 -5
  107. package/dist/hooks/useWatchUserChange/index.d.mts +2 -4
  108. package/dist/hooks/useWatchUserChange/index.d.mts.map +1 -1
  109. package/dist/hooks/useWatchUserChange/index.mjs +3 -5
  110. package/dist/hooks/useWatchUserChange/index.mjs.map +1 -1
  111. package/dist/index-DaiTW5Bl.d.mts +99 -0
  112. package/dist/index-DaiTW5Bl.d.mts.map +1 -0
  113. package/dist/partials/FieldCopyTestIdButton/index.d.mts +0 -2
  114. package/dist/partials/FieldCopyTestIdButton/index.d.mts.map +1 -1
  115. package/dist/partials/FieldCopyTestIdButton/index.mjs +1 -2
  116. package/dist/partials/FieldValidationError/index.d.mts +0 -2
  117. package/dist/partials/FieldValidationError/index.d.mts.map +1 -1
  118. package/dist/partials/FieldValidationError/index.mjs +1 -2
  119. package/dist/{useController-CK39i6HI.mjs → useController-CJjMqXU5.mjs} +3 -4
  120. package/dist/{useController-CK39i6HI.mjs.map → useController-CJjMqXU5.mjs.map} +1 -1
  121. package/dist/{useController-DcK2YHbw.d.mts → useController-CdFEp-Wa.d.mts} +2 -4
  122. package/dist/useController-CdFEp-Wa.d.mts.map +1 -0
  123. package/dist/{useFormContext-fYWtlnpE.mjs → useFormContext-BEjPBdzb.mjs} +3 -4
  124. package/dist/useFormContext-BEjPBdzb.mjs.map +1 -0
  125. package/dist/useFormContext-BhPzFXwF.d.mts +45 -0
  126. package/dist/useFormContext-BhPzFXwF.d.mts.map +1 -0
  127. package/dist/useInput-NPbS4w_n.mjs +1 -0
  128. package/dist/{useInputValueTransform-DJ5zkqSy.mjs → useInputValueTransform-D44BLp1Z.mjs} +2 -3
  129. package/dist/{useInputValueTransform-DJ5zkqSy.mjs.map → useInputValueTransform-D44BLp1Z.mjs.map} +1 -1
  130. package/dist/{useInputValueTransform-LOaEim7k.d.mts → useInputValueTransform-cevZBrIN.d.mts} +3 -5
  131. package/dist/useInputValueTransform-cevZBrIN.d.mts.map +1 -0
  132. package/package.json +10 -10
  133. package/dist/FormContext-CsFiNvuJ.d.mts +0 -19
  134. package/dist/FormContext-CsFiNvuJ.d.mts.map +0 -1
  135. package/dist/FormContext-gHSwOlcy.mjs +0 -278
  136. package/dist/FormContext-gHSwOlcy.mjs.map +0 -1
  137. package/dist/hooks/useUniformField/index.d.mts.map +0 -1
  138. package/dist/index-CAdGtKE_.d.mts +0 -1
  139. package/dist/index-D5HVU2jP.d.mts +0 -1
  140. package/dist/useController-DcK2YHbw.d.mts.map +0 -1
  141. package/dist/useFormContext-B3QGVVaO.d.mts +0 -66
  142. package/dist/useFormContext-B3QGVVaO.d.mts.map +0 -1
  143. package/dist/useFormContext-fYWtlnpE.mjs.map +0 -1
  144. package/dist/useInput-C0aJaAGe.mjs +0 -2
  145. package/dist/useInputValueTransform-LOaEim7k.d.mts.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"useController-CK39i6HI.mjs","names":["useController","useRHFController"],"sources":["../src/hooks/useController/useController.ts"],"sourcesContent":["import type {\n ControllerFieldState,\n ControllerRenderProps,\n UseControllerProps as RHFUseControllerProps,\n UseFormStateReturn,\n} from 'react-hook-form';\n\nimport { useContext } from 'react';\nimport { useController as useRHFController } from 'react-hook-form';\n\nimport { UniformContext } from '../../Form/subcomponents/FormContext';\nimport { fromNullishString, toNullishString } from '../../helpers';\n\nexport type UseControllerProps<TFieldValues extends object = object> =\n RHFUseControllerProps<TFieldValues>;\n\nexport interface UseControllerReturn<TFieldValues extends object = object> {\n field: Omit<ControllerRenderProps<TFieldValues>, 'onChange' | 'value'> & {\n // Using any[] to support both direct value changes and React synthetic events\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => void;\n value: string;\n };\n formState: UseFormStateReturn<TFieldValues>;\n fieldState: ControllerFieldState;\n}\n\n/**\n * A wrapper around react-hook-form's useController that transparently handles nullish string conversions.\n *\n * Key features:\n * 1. Empty strings ('') in the UI are stored as null in form state\n * 2. Null/undefined values in form state are displayed as empty strings in the UI\n * 3. Handles both direct value changes and React synthetic events\n * 4. Maintains the same API as react-hook-form's useController\n * 5. Notifies UniformContext's userChange listeners on field changes (enables useWatchUserChange hook)\n * 6. No-op when value unchanged: onChange is ignored if the new value equals the current value\n * (prevents unnecessary re-renders and spurious useWatchUserChange triggers)\n *\n * This enables consistent handling of empty/null values while keeping a clean API\n * for form inputs that expect string values.\n *\n * @see https://react-hook-form.com/docs/usecontroller\n */\nexport const useController = <TFieldValues extends object = object>(\n props: UseControllerProps<TFieldValues>,\n): UseControllerReturn<TFieldValues> => {\n const { field, formState, fieldState } = useRHFController(props);\n const { userChange } = useContext(UniformContext);\n\n return {\n field: {\n ...field,\n // Handles both direct values (onChange(\"value\")) and events (onChange(event))\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => {\n const value = event[0]?.target?.value ?? event[0];\n const formattedValue = value === '' ? '' : toNullishString(value);\n\n // Skip if value hasn't changed (e.g., user re-selects same option)\n // We compare formattedValue (the new value after nullish conversion) with\n // field.value (the current stored value, also in nullish format)\n if (formattedValue === field.value) {\n return;\n }\n\n // Update form state first\n field.onChange(formattedValue);\n\n // Then notify userChange listeners (for useWatchUserChange hook)\n // This ensures getValues() in listeners returns the updated value\n // Guard against undefined userChange (when used outside FormProvider)\n // NOTE: We notify with the original value (not formattedValue) so that\n // listeners receive the actual value (false, 0, null) instead of marker\n // strings like '__FALSE__', '__ZERO__', '__NULL__'\n userChange?.notify(field.name, value);\n },\n // Convert null/undefined to empty string for UI display\n value: fromNullishString(field.value) as string,\n },\n formState,\n fieldState,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAaA,mBACX,UACsC;CACtC,MAAM,EAAE,OAAO,WAAW,eAAeC,cAAiB,KAAK;CAC/D,MAAM,EAAE,eAAe,WAAW,cAAc;CAEhD,OAAO;EACL,OAAO;GACL,GAAG;GAGH,WAAW,GAAG,UAAiB;IAC7B,MAAM,QAAQ,MAAM,EAAE,EAAE,QAAQ,SAAS,MAAM;IAC/C,MAAM,iBAAiB,UAAU,KAAK,KAAK,gBAAgB,KAAK;IAKhE,IAAI,mBAAmB,MAAM,OAC3B;IAIF,MAAM,SAAS,cAAc;IAQ7B,YAAY,OAAO,MAAM,MAAM,KAAK;GACtC;GAEA,OAAO,kBAAkB,MAAM,KAAK;EACtC;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"useController-CJjMqXU5.mjs","names":["useController","useRHFController"],"sources":["../src/hooks/useController/useController.ts"],"sourcesContent":["import type {\n ControllerFieldState,\n ControllerRenderProps,\n UseControllerProps as RHFUseControllerProps,\n UseFormStateReturn,\n} from 'react-hook-form';\n\nimport { useContext } from 'react';\nimport { useController as useRHFController } from 'react-hook-form';\n\nimport { UniformContext } from '../../Form/subcomponents/FormContext';\nimport { fromNullishString, toNullishString } from '../../helpers';\n\nexport type UseControllerProps<TFieldValues extends object = object> =\n RHFUseControllerProps<TFieldValues>;\n\nexport interface UseControllerReturn<TFieldValues extends object = object> {\n field: Omit<ControllerRenderProps<TFieldValues>, 'onChange' | 'value'> & {\n // Using any[] to support both direct value changes and React synthetic events\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => void;\n value: string;\n };\n fieldState: ControllerFieldState;\n formState: UseFormStateReturn<TFieldValues>;\n}\n\n/**\n * A wrapper around react-hook-form's useController that transparently handles nullish string conversions.\n *\n * Key features:\n * 1. Empty strings ('') in the UI are stored as null in form state\n * 2. Null/undefined values in form state are displayed as empty strings in the UI\n * 3. Handles both direct value changes and React synthetic events\n * 4. Maintains the same API as react-hook-form's useController\n * 5. Notifies UniformContext's userChange listeners on field changes (enables useWatchUserChange hook)\n * 6. No-op when value unchanged: onChange is ignored if the new value equals the current value\n * (prevents unnecessary re-renders and spurious useWatchUserChange triggers)\n *\n * This enables consistent handling of empty/null values while keeping a clean API\n * for form inputs that expect string values.\n *\n * @see https://react-hook-form.com/docs/usecontroller\n */\nexport const useController = <TFieldValues extends object = object>(\n props: UseControllerProps<TFieldValues>,\n): UseControllerReturn<TFieldValues> => {\n const { field, formState, fieldState } = useRHFController(props);\n const { userChange } = useContext(UniformContext);\n\n return {\n field: {\n ...field,\n // Handles both direct values (onChange(\"value\")) and events (onChange(event))\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => {\n const value = event[0]?.target?.value ?? event[0];\n const formattedValue = value === '' ? '' : toNullishString(value);\n\n // Skip if value hasn't changed (e.g., user re-selects same option)\n // We compare formattedValue (the new value after nullish conversion) with\n // field.value (the current stored value, also in nullish format)\n if (formattedValue === field.value) {\n return;\n }\n\n // Update form state first\n field.onChange(formattedValue);\n\n // Then notify userChange listeners (for useWatchUserChange hook)\n // This ensures getValues() in listeners returns the updated value\n // Guard against undefined userChange (when used outside FormProvider)\n // NOTE: We notify with the original value (not formattedValue) so that\n // listeners receive the actual value (false, 0, null) instead of marker\n // strings like '__FALSE__', '__ZERO__', '__NULL__'\n userChange?.notify(field.name, value);\n },\n // Convert null/undefined to empty string for UI display\n value: fromNullishString(field.value) as string,\n },\n formState,\n fieldState,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA4CA,MAAaA,mBACX,UACsC;CACtC,MAAM,EAAE,OAAO,WAAW,eAAeC,cAAiB,KAAK;CAC/D,MAAM,EAAE,eAAe,WAAW,cAAc;CAEhD,OAAO;EACL,OAAO;GACL,GAAG;GAGH,WAAW,GAAG,UAAiB;IAC7B,MAAM,QAAQ,MAAM,EAAE,EAAE,QAAQ,SAAS,MAAM;IAC/C,MAAM,iBAAiB,UAAU,KAAK,KAAK,gBAAgB,KAAK;IAKhE,IAAI,mBAAmB,MAAM,OAC3B;IAIF,MAAM,SAAS,cAAc;IAQ7B,YAAY,OAAO,MAAM,MAAM,KAAK;GACtC;GAEA,OAAO,kBAAkB,MAAM,KAAK;EACtC;EACA;EACA;CACF;AACF"}
@@ -1,13 +1,12 @@
1
1
  import { ControllerFieldState, ControllerRenderProps, UseControllerProps, UseFormStateReturn } from "react-hook-form";
2
- //#region src/hooks/useController/useController.d.ts
3
2
  type UseControllerProps$1<TFieldValues extends object = object> = UseControllerProps<TFieldValues>;
4
3
  interface UseControllerReturn<TFieldValues extends object = object> {
5
4
  field: Omit<ControllerRenderProps<TFieldValues>, 'onChange' | 'value'> & {
6
5
  onChange: (...event: any[]) => void;
7
6
  value: string;
8
7
  };
9
- formState: UseFormStateReturn<TFieldValues>;
10
8
  fieldState: ControllerFieldState;
9
+ formState: UseFormStateReturn<TFieldValues>;
11
10
  }
12
11
  /**
13
12
  * A wrapper around react-hook-form's useController that transparently handles nullish string conversions.
@@ -27,6 +26,5 @@ interface UseControllerReturn<TFieldValues extends object = object> {
27
26
  * @see https://react-hook-form.com/docs/usecontroller
28
27
  */
29
28
  declare const useController$1: <TFieldValues extends object = object>(props: UseControllerProps$1<TFieldValues>) => UseControllerReturn<TFieldValues>;
30
- //#endregion
31
29
  export { UseControllerReturn as n, useController$1 as r, UseControllerProps$1 as t };
32
- //# sourceMappingURL=useController-DcK2YHbw.d.mts.map
30
+ //# sourceMappingURL=useController-CdFEp-Wa.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useController-CdFEp-Wa.d.mts","names":["UseControllerProps","RHFUseControllerProps","useController"],"sources":["../src/hooks/useController/useController.ts"],"mappings":";KAaYA,qBAAmB,wCAC7BC,mBAAsB;UAEP,oBAAoB;EACnC,OAAO,KAAK,sBAAsB;IAGhC,cAAc;IACd;;EAEF,YAAY;EACZ,WAAW,mBAAmB;;;;;;;;;;;;;;;;;;;cAoBnBC,kBAAiB,sCAC5B,OAAOF,qBAAmB,kBACzB,oBAAoB"}
@@ -1,8 +1,8 @@
1
+ import { n as UniformContext } from "./FormContext-B8G_Xxd6.mjs";
1
2
  import { flatArrayKey, nameToTestId, toValidationFormat } from "./helpers/index.mjs";
2
- import { n as UniformContext } from "./FormContext-gHSwOlcy.mjs";
3
3
  import { useContext } from "react";
4
4
  import { useFormContext } from "react-hook-form";
5
- //#region src/hooks/useFormContext/useFormContext.ts
5
+ // src/hooks/useFormContext/useFormContext.ts
6
6
  /** Schema check whether a field is required or optional */
7
7
  const checkFieldIsRequired = (validation, path) => {
8
8
  const checkPath = path[path.length - 1] === "__FLAT__" ? path.slice(0, -1) : path;
@@ -131,7 +131,6 @@ const useFormContext$1 = () => {
131
131
  watch
132
132
  };
133
133
  };
134
- //#endregion
135
134
  export { useFormContext$1 as n, checkFieldIsRequired as t };
136
135
 
137
- //# sourceMappingURL=useFormContext-fYWtlnpE.mjs.map
136
+ //# sourceMappingURL=useFormContext-BEjPBdzb.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormContext-BEjPBdzb.mjs","names":["useFormContext","useHookFormContext"],"sources":["../src/hooks/useFormContext/useFormContext.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport type { VetoFormattedError, VetoInstance } from '@fuf-stack/veto';\nimport type { ContextType } from 'react';\nimport type {\n FieldError,\n FieldValues,\n Path,\n UseFormReturn,\n} from 'react-hook-form';\n\nimport { useContext } from 'react';\nimport { useFormContext as useHookFormContext } from 'react-hook-form';\n\nimport { UniformContext } from '../../Form/subcomponents/FormContext';\nimport { flatArrayKey, nameToTestId, toValidationFormat } from '../../helpers';\n\n/** Schema check whether a field is required or optional */\nexport const checkFieldIsRequired = (\n validation: VetoInstance,\n path: string[],\n): boolean => {\n // Handle flat array paths: strip the flatArrayKey to check the array element schema\n // e.g., ['arrayField', '0', '__FLAT__'] -> check schema at ['arrayField', '0']\n const checkPath =\n path[path.length - 1] === flatArrayKey ? path.slice(0, -1) : path;\n\n const checkRequired = (schema: any) => {\n // arrays ...\n if (schema.type === 'array') {\n // ... if array is optional or nullable it is not required\n if (schema.isOptional || schema.isNullable) {\n return false;\n }\n // ... otherwise arrays are required (display logic wise -> no asterisk in the label)\n return true;\n }\n\n // all other fields are required if they are\n // not optional and not nullable\n return !schema.isOptional && !schema.isNullable;\n };\n\n return validation.checkSchemaPath(checkRequired, checkPath);\n};\n\n/**\n * Resolve validation errors for a given field path.\n *\n * Traverses a nested `VetoFormattedError` structure using a dotted path\n * (for example: \"user.address.0.street\") and returns the matching\n * `FieldError[]` if present. If no error exists at the path, returns\n * `undefined`.\n *\n * @param errors - The formatted validation errors from Uniform's context\n * @param name - The dotted field path to resolve\n * @returns An array of `FieldError` entries for the field, or `undefined`\n */\nconst getValidationErrorsByName = (\n errors: VetoFormattedError,\n name: string,\n) => {\n // Traverse nested error structure; ignore flat array wrapper key\n const keys = name.split('.').filter((k) => {\n return k !== flatArrayKey;\n });\n let current: unknown = errors;\n keys.forEach((key) => {\n if (current && typeof current === 'object') {\n current = (current as Record<string, unknown>)[key];\n } else {\n current = undefined;\n }\n });\n return current as FieldError[] | undefined;\n};\n\n/** Field state returned by the enhanced `getFieldState` */\nexport interface UniformFieldState {\n /** Validation errors for the field from the Uniform validation schema */\n error: FieldError[] | undefined;\n /** Whether the field has validation errors */\n invalid: boolean;\n /** Whether the field value differs from its default value */\n isDirty: boolean;\n /** Whether the field has been touched */\n isTouched: boolean;\n /** Whether the field is currently being validated */\n isValidating: boolean;\n /** Whether the validation schema requires the field */\n required: boolean;\n /** Generated HTML data-testid for the field */\n testId: string;\n}\n\n/**\n * Return type of `useFormContext`.\n *\n * Declared explicitly so the published declarations only reference types that\n * react-hook-form exports from its package root.\n */\nexport type UseFormContextReturn<\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n> = Omit<\n UseFormReturn<TFieldValues, TContext, TTransformedValues>,\n 'getFieldState'\n> &\n ContextType<typeof UniformContext> & {\n getFieldState: (\n name: Path<TFieldValues>,\n testId?: string,\n ) => UniformFieldState;\n };\n\n/**\n * Custom hook that extends react-hook-form's useFormContext to add validation and state management.\n *\n * Key features:\n * - Enhanced `getFieldState` that includes validation schema-based \"required\" status and testId generation\n * - Automatic conversion of form values via `getValues`, `watch`, and `subscribe`:\n * - Unwraps flat array wrappers (`{ __FLAT__: value }` → `value`)\n * - Converts nullish string markers (`__NULL__` → `null`, `__FALSE__` → `false`, `__ZERO__` → `0`)\n * - Filters out empty/null values\n */\nexport const useFormContext = <\n TFieldValues extends FieldValues = FieldValues,\n TContext = any,\n TTransformedValues = TFieldValues,\n>(): UseFormContextReturn<TFieldValues, TContext, TTransformedValues> => {\n const {\n formState,\n // some methods that will be enhanced below\n getFieldState: getFieldStateOrig,\n getValues: getValuesOrig,\n watch: watchOrig,\n subscribe: subscribeOrig,\n reset: resetOrig,\n // the rest of the methods pass through unchanged\n ...otherMethods\n } = useHookFormContext<TFieldValues, TContext, TTransformedValues>();\n\n const uniformContext = useContext(UniformContext);\n\n /**\n * Wrap react-hook-form's `reset` so the uniform context is notified about\n * programmatic resets. Field components (e.g. FieldArray) use this signal to\n * normalize their state on reset instead of inferring it from field contents.\n */\n const notifyReset = uniformContext?.formReset?.notify;\n const reset = ((...args: Parameters<typeof resetOrig>) => {\n resetOrig(...args);\n notifyReset?.();\n }) as typeof resetOrig;\n\n /**\n * Updated getFieldState method which returns:\n * - Whether the field is required by checking the validation schema\n * - Existing field state information (errors, etc.)\n * - A testId generated from the field name (with flat array keys removed and slugified)\n *\n * @param name - The field path (string or array)\n * @param testId - Optional explicit testId. If provided, will be slugified. If not provided, generated from name.\n */\n const getFieldState = (\n name: Path<TFieldValues>,\n testId?: string,\n ): UniformFieldState => {\n const fieldPath =\n typeof name === 'string' ? name.replace(/\\[\\d+\\]/g, '').split('.') : name;\n\n // Use base validation instance for checking \"required\" status\n // Client validation often uses .nullish() which would incorrectly mark fields as optional\n const validationInstance =\n uniformContext?.validation.baseInstance ??\n uniformContext?.validation.instance;\n\n // Check if the field is required using the validation schema\n const required = validationInstance\n ? checkFieldIsRequired(validationInstance, fieldPath)\n : false;\n\n const error = getValidationErrorsByName(\n uniformContext?.validation.errors ?? {},\n name,\n );\n\n // Get everything but the error from the original field state\n const fieldState = getFieldStateOrig(name, formState);\n\n return {\n ...fieldState,\n error,\n invalid: !!error,\n required,\n testId: nameToTestId(testId ?? name),\n };\n };\n\n /**\n * Wrap form value accessor methods to automatically convert from internal storage format\n * to component-friendly format:\n *\n * - Unwrap flat array wrappers: `{ __FLAT__: value }` → `value`\n * - Convert nullish string markers: `__NULL__` → `null`, `__FALSE__` → `false`, `__ZERO__` → `0`\n * - Filter out empty/null values: fields with converted null/empty values are removed entirely\n *\n * This ensures components receive clean, predictable data without needing to handle\n * the internal nullish string conversion system or flat array wrapping manually.\n */\n const getValues = ((...args: any[]) => {\n const result = (getValuesOrig as any)(...args);\n return toValidationFormat(result);\n }) as typeof getValuesOrig;\n\n const watch = ((...args: any[]) => {\n const result = (watchOrig as any)(...args);\n return toValidationFormat(result);\n }) as typeof watchOrig;\n\n const subscribe = ((...args: any[]) => {\n // For subscribe, we need to wrap the callback to convert the values property\n const [options] = args;\n if (options?.callback) {\n const originalCallback = options.callback;\n const wrappedOptions = {\n ...options,\n callback: (subscribeFormState: any) => {\n // Convert the values property if it exists\n const convertedFormState = {\n ...subscribeFormState,\n ...(subscribeFormState.values && {\n values: toValidationFormat(subscribeFormState.values),\n }),\n };\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return originalCallback(convertedFormState);\n },\n };\n return subscribeOrig(wrappedOptions);\n }\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return (subscribeOrig as any)(...args);\n }) as typeof subscribeOrig;\n\n return {\n ...otherMethods,\n ...uniformContext,\n formState,\n getFieldState,\n getValues,\n reset,\n subscribe,\n watch,\n };\n};\n"],"mappings":";;;;;;AAkBA,MAAa,wBACX,YACA,SACY;CAGZ,MAAM,YACJ,KAAK,KAAK,SAAS,OAAA,aAAsB,KAAK,MAAM,GAAG,EAAE,IAAI;CAE/D,MAAM,iBAAiB,WAAgB;EAErC,IAAI,OAAO,SAAS,SAAS;GAE3B,IAAI,OAAO,cAAc,OAAO,YAC9B,OAAO;GAGT,OAAO;EACT;EAIA,OAAO,CAAC,OAAO,cAAc,CAAC,OAAO;CACvC;CAEA,OAAO,WAAW,gBAAgB,eAAe,SAAS;AAC5D;;;;;;;;;;;;;AAcA,MAAM,6BACJ,QACA,SACG;CAEH,MAAM,OAAO,KAAK,MAAM,GAAG,CAAC,CAAC,QAAQ,MAAM;EACzC,OAAO,MAAM;CACf,CAAC;CACD,IAAI,UAAmB;CACvB,KAAK,SAAS,QAAQ;EACpB,IAAI,WAAW,OAAO,YAAY,UAChC,UAAW,QAAoC;OAE/C,UAAU,KAAA;CAEd,CAAC;CACD,OAAO;AACT;;;;;;;;;;;AAmDA,MAAaA,yBAI4D;CACvE,MAAM,EACJ,WAEA,eAAe,mBACf,WAAW,eACX,OAAO,WACP,WAAW,eACX,OAAO,WAEP,GAAG,iBACDC,eAA+D;CAEnE,MAAM,iBAAiB,WAAW,cAAc;;;;;;CAOhD,MAAM,cAAc,gBAAgB,WAAW;CAC/C,MAAM,UAAU,GAAG,SAAuC;EACxD,UAAU,GAAG,IAAI;EACjB,cAAc;CAChB;;;;;;;;;;CAWA,MAAM,iBACJ,MACA,WACsB;EACtB,MAAM,YACJ,OAAO,SAAS,WAAW,KAAK,QAAQ,YAAY,EAAE,CAAC,CAAC,MAAM,GAAG,IAAI;EAIvE,MAAM,qBACJ,gBAAgB,WAAW,gBAC3B,gBAAgB,WAAW;EAG7B,MAAM,WAAW,qBACb,qBAAqB,oBAAoB,SAAS,IAClD;EAEJ,MAAM,QAAQ,0BACZ,gBAAgB,WAAW,UAAU,CAAC,GACtC,IACF;EAKA,OAAO;GACL,GAHiB,kBAAkB,MAAM,SAG7B;GACZ;GACA,SAAS,CAAC,CAAC;GACX;GACA,QAAQ,aAAa,UAAU,IAAI;EACrC;CACF;;;;;;;;;;;;CAaA,MAAM,cAAc,GAAG,SAAgB;EACrC,MAAM,SAAU,cAAsB,GAAG,IAAI;EAC7C,OAAO,mBAAmB,MAAM;CAClC;CAEA,MAAM,UAAU,GAAG,SAAgB;EACjC,MAAM,SAAU,UAAkB,GAAG,IAAI;EACzC,OAAO,mBAAmB,MAAM;CAClC;CAEA,MAAM,cAAc,GAAG,SAAgB;EAErC,MAAM,CAAC,WAAW;EAClB,IAAI,SAAS,UAAU;GACrB,MAAM,mBAAmB,QAAQ;GACjC,MAAM,iBAAiB;IACrB,GAAG;IACH,WAAW,uBAA4B;KAErC,MAAM,qBAAqB;MACzB,GAAG;MACH,GAAI,mBAAmB,UAAU,EAC/B,QAAQ,mBAAmB,mBAAmB,MAAM,EACtD;KACF;KAEA,OAAO,iBAAiB,kBAAkB;IAC5C;GACF;GACA,OAAO,cAAc,cAAc;EACrC;EAEA,OAAQ,cAAsB,GAAG,IAAI;CACvC;CAEA,OAAO;EACL,GAAG;EACH,GAAG;EACH;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -0,0 +1,45 @@
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
+ declare const checkFieldIsRequired: (validation: VetoInstance, path: string[]) => boolean;
7
+ /** Field state returned by the enhanced `getFieldState` */
8
+ 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
+ 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
+ declare const useFormContext$1: <TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues>() => UseFormContextReturn<TFieldValues, TContext, TTransformedValues>;
44
+ export { useFormContext$1 as i, UseFormContextReturn as n, checkFieldIsRequired as r, UniformFieldState as t };
45
+ //# sourceMappingURL=useFormContext-BhPzFXwF.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormContext-BhPzFXwF.d.mts","names":["useFormContext"],"sources":["../src/hooks/useFormContext/useFormContext.ts"],"mappings":";;;;;cAkBa,uBACX,YAAY,cACZ;;UA0De;;EAEf,OAAO;;EAEP;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;;;;KASU,qBACV,qBAAqB,cAAc,aACnC,gBACA,qBAAqB,gBACnB,KACF,cAAc,cAAc,UAAU,wCAGtC,mBAAmB;EACjB,gBACE,MAAM,KAAK,eACX,oBACG;;;;;;;;;;;;cAaIA,mBACX,qBAAqB,cAAc,aACnC,gBACA,qBAAqB,mBAClB,qBAAqB,cAAc,UAAU"}
@@ -0,0 +1 @@
1
+ export { useInput as t } from "@heroui/input";
@@ -1,5 +1,5 @@
1
1
  import { useCallback } from "react";
2
- //#region src/hooks/useInputValueTransform/useInputValueTransform.ts
2
+ // src/hooks/useInputValueTransform/useInputValueTransform.ts
3
3
  /**
4
4
  * Custom hook providing utility functions for value transformations between display and form values.
5
5
  *
@@ -104,7 +104,6 @@ const useInputValueTransform = ({ type, transform }) => {
104
104
  }, [type, transform])
105
105
  };
106
106
  };
107
- //#endregion
108
107
  export { useInputValueTransform as t };
109
108
 
110
- //# sourceMappingURL=useInputValueTransform-DJ5zkqSy.mjs.map
109
+ //# sourceMappingURL=useInputValueTransform-D44BLp1Z.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useInputValueTransform-DJ5zkqSy.mjs","names":[],"sources":["../src/hooks/useInputValueTransform/useInputValueTransform.ts"],"sourcesContent":["import { useCallback } from 'react';\n\nexport interface InputValueTransform<TDisplay = unknown> {\n /** Transforms the form value to display value (e.g., 1000 → \"$1,000\" or 'a' → ['a']) */\n toDisplayValue: (value: unknown) => TDisplay;\n /** Transforms the display value to form value (e.g., \"$1,000\" → 1000 or ['a'] → 'a') */\n toFormValue: (value: TDisplay) => unknown;\n}\n\nexport interface UseInputValueTransformOptions<TDisplay = unknown> {\n /** Input type for special number handling */\n type?: 'text' | 'number' | 'password';\n /** Value transformation functions */\n transform?: InputValueTransform<TDisplay>;\n}\n\nexport interface UseInputValueTransformReturn<TDisplay = unknown> {\n /** Converts any form value to display value */\n toDisplayValue: (formValue: unknown) => TDisplay;\n /** Converts any display value to form value */\n toFormValue: (displayValue: TDisplay) => unknown;\n}\n\n/**\n * Custom hook providing utility functions for value transformations between display and form values.\n *\n * This hook provides pure conversion functions without any state management. It's useful for:\n * - Currency formatting ($1,000 display vs 1000 stored)\n * - Number inputs with special handling\n * - Date formatting (MM/DD/YYYY display vs ISO date stored)\n * - Phone number formatting ((555) 123-4567 display vs 5551234567 stored)\n * - Array/Object transformations (single value ↔ array, nested structures)\n *\n * **Key Features:**\n * - Pure conversion functions (no state)\n * - Generic support for any data type (strings, numbers, arrays, objects)\n * - Special number input handling (empty string preservation)\n * - Bidirectional value transformations\n * - Memoized functions for performance\n *\n * @param options Configuration for value transformation\n * @returns Pure conversion utility functions\n *\n * @example\n * ```tsx\n * // Currency formatting\n * const currencyTransform = {\n * toDisplayValue: (val) => val ? `$${Number(val).toLocaleString()}` : '',\n * toFormValue: (val) => parseFloat(val.replace(/[$,]/g, '')) || 0\n * };\n *\n * const { toDisplayValue, toFormValue } = useInputValueTransform({\n * transform: currencyTransform\n * });\n *\n * const displayVal = toDisplayValue(1000); // \"$1,000\"\n * const formVal = toFormValue(\"$1,500\"); // 1500\n * ```\n *\n * @example\n * ```tsx\n * // Number input (no transforms needed)\n * const { toDisplayValue, toFormValue } = useInputValueTransform({\n * type: 'number'\n * });\n *\n * // Handles empty string → empty string (not NaN)\n * // Handles \"123\" → 123 (string to number conversion)\n * ```\n *\n * @example\n * ```tsx\n * // Array to single value (for single checkbox)\n * const singleValueTransform = {\n * toDisplayValue: (val: string[]) => val?.[0] || '',\n * toFormValue: (val: string) => val ? [val] : []\n * };\n *\n * const { toDisplayValue, toFormValue } = useInputValueTransform({\n * transform: singleValueTransform\n * });\n *\n * const displayVal = toDisplayValue(['option1']); // \"option1\"\n * const formVal = toFormValue(\"option2\"); // [\"option2\"]\n * ```\n *\n * @example\n * ```tsx\n * // Integration with debouncing\n * const MyInput = ({ field, transform }) => {\n * const transform = useInputValueTransform({ transform });\n *\n * const { onChange, onBlur, value } = useInputValueDebounce({\n * ...transform,\n * debounceDelay: 300,\n * name: 'fieldName',\n * onBlur: field.onBlur,\n * onChange: field.onChange,\n * value: field.value,\n * });\n *\n * return <input value={value} onChange={onChange} onBlur={onBlur} />;\n * };\n * ```\n */\nexport const useInputValueTransform = <TDisplay = unknown>({\n type,\n transform,\n}: UseInputValueTransformOptions<TDisplay>): UseInputValueTransformReturn<TDisplay> => {\n /**\n * Converts any form value to display value\n */\n const toDisplayValue = useCallback(\n (formValue: unknown): TDisplay => {\n if (transform?.toDisplayValue) {\n return transform.toDisplayValue(formValue);\n }\n\n // For number type, convert valid strings to numbers for display\n if (type === 'number') {\n if (formValue === '') {\n return '' as TDisplay;\n }\n const numValue = Number(formValue);\n return (Number.isNaN(numValue) ? formValue : numValue) as TDisplay;\n }\n\n // Default: pass through (handles primitives, arrays, objects, etc.)\n return (formValue ?? '') as TDisplay;\n },\n [type, transform],\n );\n\n /**\n * Converts any display value to form value\n */\n const toFormValue = useCallback(\n (displayValue: TDisplay): unknown => {\n if (transform?.toFormValue) {\n return transform.toFormValue(displayValue);\n }\n\n // For number type, convert strings to numbers\n if (type === 'number') {\n if (displayValue === '') {\n return '';\n }\n const numValue = Number(displayValue);\n return Number.isNaN(numValue) ? displayValue : numValue;\n }\n\n // Default: pass through (handles primitives, arrays, objects, etc.)\n return displayValue;\n },\n [type, transform],\n );\n\n return {\n toDisplayValue,\n toFormValue,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,MAAa,0BAA8C,EACzD,MACA,gBACqF;CAiDrF,OAAO;EACL,gBA9CqB,aACpB,cAAiC;GAChC,IAAI,WAAW,gBACb,OAAO,UAAU,eAAe,SAAS;GAI3C,IAAI,SAAS,UAAU;IACrB,IAAI,cAAc,IAChB,OAAO;IAET,MAAM,WAAW,OAAO,SAAS;IACjC,OAAQ,OAAO,MAAM,QAAQ,IAAI,YAAY;GAC/C;GAGA,OAAQ,aAAa;EACvB,GACA,CAAC,MAAM,SAAS,CA4BH;EACb,aAvBkB,aACjB,iBAAoC;GACnC,IAAI,WAAW,aACb,OAAO,UAAU,YAAY,YAAY;GAI3C,IAAI,SAAS,UAAU;IACrB,IAAI,iBAAiB,IACnB,OAAO;IAET,MAAM,WAAW,OAAO,YAAY;IACpC,OAAO,OAAO,MAAM,QAAQ,IAAI,eAAe;GACjD;GAGA,OAAO;EACT,GACA,CAAC,MAAM,SAAS,CAKN;CACZ;AACF"}
1
+ {"version":3,"file":"useInputValueTransform-D44BLp1Z.mjs","names":[],"sources":["../src/hooks/useInputValueTransform/useInputValueTransform.ts"],"sourcesContent":["import { useCallback } from 'react';\n\nexport interface InputValueTransform<TDisplay = unknown> {\n /** Transforms the form value to display value (e.g., 1000 → \"$1,000\" or 'a' → ['a']) */\n toDisplayValue: (value: unknown) => TDisplay;\n /** Transforms the display value to form value (e.g., \"$1,000\" → 1000 or ['a'] → 'a') */\n toFormValue: (value: TDisplay) => unknown;\n}\n\nexport interface UseInputValueTransformOptions<TDisplay = unknown> {\n /** Value transformation functions */\n transform?: InputValueTransform<TDisplay>;\n /** Input type for special number handling */\n type?: 'text' | 'number' | 'password';\n}\n\nexport interface UseInputValueTransformReturn<TDisplay = unknown> {\n /** Converts any form value to display value */\n toDisplayValue: (formValue: unknown) => TDisplay;\n /** Converts any display value to form value */\n toFormValue: (displayValue: TDisplay) => unknown;\n}\n\n/**\n * Custom hook providing utility functions for value transformations between display and form values.\n *\n * This hook provides pure conversion functions without any state management. It's useful for:\n * - Currency formatting ($1,000 display vs 1000 stored)\n * - Number inputs with special handling\n * - Date formatting (MM/DD/YYYY display vs ISO date stored)\n * - Phone number formatting ((555) 123-4567 display vs 5551234567 stored)\n * - Array/Object transformations (single value ↔ array, nested structures)\n *\n * **Key Features:**\n * - Pure conversion functions (no state)\n * - Generic support for any data type (strings, numbers, arrays, objects)\n * - Special number input handling (empty string preservation)\n * - Bidirectional value transformations\n * - Memoized functions for performance\n *\n * @param options Configuration for value transformation\n * @returns Pure conversion utility functions\n *\n * @example\n * ```tsx\n * // Currency formatting\n * const currencyTransform = {\n * toDisplayValue: (val) => val ? `$${Number(val).toLocaleString()}` : '',\n * toFormValue: (val) => parseFloat(val.replace(/[$,]/g, '')) || 0\n * };\n *\n * const { toDisplayValue, toFormValue } = useInputValueTransform({\n * transform: currencyTransform\n * });\n *\n * const displayVal = toDisplayValue(1000); // \"$1,000\"\n * const formVal = toFormValue(\"$1,500\"); // 1500\n * ```\n *\n * @example\n * ```tsx\n * // Number input (no transforms needed)\n * const { toDisplayValue, toFormValue } = useInputValueTransform({\n * type: 'number'\n * });\n *\n * // Handles empty string → empty string (not NaN)\n * // Handles \"123\" → 123 (string to number conversion)\n * ```\n *\n * @example\n * ```tsx\n * // Array to single value (for single checkbox)\n * const singleValueTransform = {\n * toDisplayValue: (val: string[]) => val?.[0] || '',\n * toFormValue: (val: string) => val ? [val] : []\n * };\n *\n * const { toDisplayValue, toFormValue } = useInputValueTransform({\n * transform: singleValueTransform\n * });\n *\n * const displayVal = toDisplayValue(['option1']); // \"option1\"\n * const formVal = toFormValue(\"option2\"); // [\"option2\"]\n * ```\n *\n * @example\n * ```tsx\n * // Integration with debouncing\n * const MyInput = ({ field, transform }) => {\n * const transform = useInputValueTransform({ transform });\n *\n * const { onChange, onBlur, value } = useInputValueDebounce({\n * ...transform,\n * debounceDelay: 300,\n * name: 'fieldName',\n * onBlur: field.onBlur,\n * onChange: field.onChange,\n * value: field.value,\n * });\n *\n * return <input value={value} onChange={onChange} onBlur={onBlur} />;\n * };\n * ```\n */\nexport const useInputValueTransform = <TDisplay = unknown>({\n type,\n transform,\n}: UseInputValueTransformOptions<TDisplay>): UseInputValueTransformReturn<TDisplay> => {\n /**\n * Converts any form value to display value\n */\n const toDisplayValue = useCallback(\n (formValue: unknown): TDisplay => {\n if (transform?.toDisplayValue) {\n return transform.toDisplayValue(formValue);\n }\n\n // For number type, convert valid strings to numbers for display\n if (type === 'number') {\n if (formValue === '') {\n return '' as TDisplay;\n }\n const numValue = Number(formValue);\n return (Number.isNaN(numValue) ? formValue : numValue) as TDisplay;\n }\n\n // Default: pass through (handles primitives, arrays, objects, etc.)\n return (formValue ?? '') as TDisplay;\n },\n [type, transform],\n );\n\n /**\n * Converts any display value to form value\n */\n const toFormValue = useCallback(\n (displayValue: TDisplay): unknown => {\n if (transform?.toFormValue) {\n return transform.toFormValue(displayValue);\n }\n\n // For number type, convert strings to numbers\n if (type === 'number') {\n if (displayValue === '') {\n return '';\n }\n const numValue = Number(displayValue);\n return Number.isNaN(numValue) ? displayValue : numValue;\n }\n\n // Default: pass through (handles primitives, arrays, objects, etc.)\n return displayValue;\n },\n [type, transform],\n );\n\n return {\n toDisplayValue,\n toFormValue,\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,MAAa,0BAA8C,EACzD,MACA,gBACqF;CAiDrF,OAAO;EACL,gBA9CqB,aACpB,cAAiC;GAChC,IAAI,WAAW,gBACb,OAAO,UAAU,eAAe,SAAS;GAI3C,IAAI,SAAS,UAAU;IACrB,IAAI,cAAc,IAChB,OAAO;IAET,MAAM,WAAW,OAAO,SAAS;IACjC,OAAQ,OAAO,MAAM,QAAQ,IAAI,YAAY;GAC/C;GAGA,OAAQ,aAAa;EACvB,GACA,CAAC,MAAM,SAAS,CA4BH;EACb,aAvBkB,aACjB,iBAAoC;GACnC,IAAI,WAAW,aACb,OAAO,UAAU,YAAY,YAAY;GAI3C,IAAI,SAAS,UAAU;IACrB,IAAI,iBAAiB,IACnB,OAAO;IAET,MAAM,WAAW,OAAO,YAAY;IACpC,OAAO,OAAO,MAAM,QAAQ,IAAI,eAAe;GACjD;GAGA,OAAO;EACT,GACA,CAAC,MAAM,SAAS,CAKN;CACZ;AACF"}
@@ -1,4 +1,3 @@
1
- //#region src/hooks/useInputValueTransform/useInputValueTransform.d.ts
2
1
  interface InputValueTransform<TDisplay = unknown> {
3
2
  /** Transforms the form value to display value (e.g., 1000 → "$1,000" or 'a' → ['a']) */
4
3
  toDisplayValue: (value: unknown) => TDisplay;
@@ -6,10 +5,10 @@ interface InputValueTransform<TDisplay = unknown> {
6
5
  toFormValue: (value: TDisplay) => unknown;
7
6
  }
8
7
  interface UseInputValueTransformOptions<TDisplay = unknown> {
9
- /** Input type for special number handling */
10
- type?: 'text' | 'number' | 'password';
11
8
  /** Value transformation functions */
12
9
  transform?: InputValueTransform<TDisplay>;
10
+ /** Input type for special number handling */
11
+ type?: 'text' | 'number' | 'password';
13
12
  }
14
13
  interface UseInputValueTransformReturn<TDisplay = unknown> {
15
14
  /** Converts any form value to display value */
@@ -100,6 +99,5 @@ interface UseInputValueTransformReturn<TDisplay = unknown> {
100
99
  * ```
101
100
  */
102
101
  declare const useInputValueTransform: <TDisplay = unknown>({ type, transform }: UseInputValueTransformOptions<TDisplay>) => UseInputValueTransformReturn<TDisplay>;
103
- //#endregion
104
102
  export { useInputValueTransform as i, UseInputValueTransformOptions as n, UseInputValueTransformReturn as r, InputValueTransform as t };
105
- //# sourceMappingURL=useInputValueTransform-LOaEim7k.d.mts.map
103
+ //# sourceMappingURL=useInputValueTransform-cevZBrIN.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInputValueTransform-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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuf-stack/uniform",
3
- "version": "1.27.0",
3
+ "version": "1.28.1",
4
4
  "description": "fuf react form library",
5
5
  "author": "Fröhlich ∧ Frei",
6
6
  "homepage": "https://github.com/fuf-stack/pixels#readme",
@@ -69,9 +69,9 @@
69
69
  "@dnd-kit/sortable": "10.0.0",
70
70
  "@dnd-kit/utilities": "3.2.2",
71
71
  "@fuf-stack/pixel-motion": "1.4.0",
72
- "@fuf-stack/pixel-utils": "1.4.0",
73
- "@fuf-stack/pixels": "1.14.0",
74
- "@fuf-stack/veto": "1.11.0",
72
+ "@fuf-stack/pixel-utils": "1.4.1",
73
+ "@fuf-stack/pixels": "1.15.0",
74
+ "@fuf-stack/veto": "1.11.1",
75
75
  "@heroui/button": "2.2.32",
76
76
  "@heroui/checkbox": "2.3.32",
77
77
  "@heroui/date-input": "2.3.32",
@@ -88,16 +88,16 @@
88
88
  "@react-aria/visually-hidden": "3.9.1",
89
89
  "debug": "4.4.3",
90
90
  "framer-motion": "12.43.0",
91
- "react-hook-form": "7.81.0",
91
+ "react-hook-form": "7.91.0",
92
92
  "react-icons": "5.7.0",
93
93
  "react-select": "5.10.2"
94
94
  },
95
95
  "devDependencies": {
96
96
  "@types/debug": "4.1.13",
97
- "@types/react": "19.2.18",
98
- "@types/react-dom": "19.2.7",
99
- "react": "19.2.8",
100
- "react-dom": "19.2.8"
97
+ "@types/react": "19.3.0",
98
+ "@types/react-dom": "19.3.0",
99
+ "react": "19.3.1",
100
+ "react-dom": "19.3.1"
101
101
  },
102
- "gitHead": "ce8395ec7be03495876e5da7c3cb3649c0e6fc40"
102
+ "gitHead": "fa0ef48d2005686a8a7166028d9c75262b6ad071"
103
103
  }
@@ -1,19 +0,0 @@
1
- import React, { ReactNode } from "react";
2
- import { FieldValues, Path, SubmitHandler } from "react-hook-form";
3
- import { VetoFormattedError, VetoInstance, VetoTypeAny } from "@fuf-stack/veto";
4
- //#region src/Form/subcomponents/FormContext.d.ts
5
- interface DebugModeSettings {
6
- /** disable form debug completely */
7
- disable?: boolean;
8
- /** custom localStorage key to save debug mode state */
9
- localStorageKey?: string;
10
- }
11
- /** Listener function that gets called when a form reset is triggered */
12
- type FormResetListener = () => void;
13
- /**
14
- * Listener function that gets called when a field changes due to user input
15
- */
16
- type UserChangeListener<TFieldValues extends object = object> = (fieldName: Path<TFieldValues>, value: unknown) => void;
17
- //#endregion
18
- export { FormResetListener as n, UserChangeListener as r, DebugModeSettings as t };
19
- //# sourceMappingURL=FormContext-CsFiNvuJ.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"FormContext-CsFiNvuJ.d.mts","names":[],"sources":["../src/Form/subcomponents/FormContext.tsx"],"mappings":";;;;UAsBiB;;EAEf;;EAEA;;;KAIU;;;;KAKA,mBAAmB,yCAC7B,WAAW,KAAK,eAChB"}
@@ -1,278 +0,0 @@
1
- import { toFormFormat, toSubmitFormat, toValidationFormat } from "./helpers/index.mjs";
2
- import React, { useCallback, useMemo, useRef, useState } from "react";
3
- import { useLocalStorage } from "@fuf-stack/pixels";
4
- import { jsx } from "react/jsx-runtime";
5
- import { FormProvider, useForm } from "react-hook-form";
6
- import createDebug from "debug";
7
- import { and, veto } from "@fuf-stack/veto";
8
- //#region src/Form/subcomponents/FormResolver.ts
9
- /**
10
- * Hook that manages client validation schemas state.
11
- *
12
- * Provides a centralized way to add/remove dynamic validation schemas
13
- * that can be combined with base form validation.
14
- *
15
- * @returns Object with client validation state and memoized setter function
16
- */
17
- const useClientValidationManager = () => {
18
- const [clientValidationSchemas, setClientValidationSchemas] = useState({});
19
- return {
20
- clientValidationSchemas,
21
- setClientValidationSchema: useMemo(() => {
22
- return (key, schema) => {
23
- setClientValidationSchemas((prev) => {
24
- if (!prev[key] && !schema) return prev;
25
- if (!schema) {
26
- const { [key]: _removed, ...rest } = prev;
27
- return rest;
28
- }
29
- return {
30
- ...prev,
31
- [key]: schema
32
- };
33
- });
34
- };
35
- }, [])
36
- };
37
- };
38
- /**
39
- * Hook that creates an extended validation instance combining base Veto validation with dynamic client validation.
40
- *
41
- * @param baseValidation - Optional base Veto validation schema
42
- * @returns Combined validation instance and client schema setter
43
- */
44
- const useExtendedValidation = (baseValidation) => {
45
- const { clientValidationSchemas, setClientValidationSchema } = useClientValidationManager();
46
- const clientSchemaValues = useMemo(() => {
47
- return Object.keys(clientValidationSchemas).sort().map((key) => {
48
- return clientValidationSchemas[key];
49
- }).filter((schema) => {
50
- return Boolean(schema);
51
- });
52
- }, [clientValidationSchemas]);
53
- return {
54
- extendedValidation: useMemo(() => {
55
- const hasBaseValidation = !!baseValidation;
56
- const hasClientSchemas = clientSchemaValues.length > 0;
57
- if (!hasBaseValidation && !hasClientSchemas) return;
58
- if (!hasClientSchemas) return baseValidation;
59
- const clientSchemasCombined = clientSchemaValues.reduce((combined, clientSchema) => {
60
- return combined ? and(combined, clientSchema) : clientSchema;
61
- }, null);
62
- if (baseValidation && clientSchemasCombined) {
63
- const baseSchema = baseValidation.schema;
64
- return veto(and(clientSchemasCombined, baseSchema));
65
- }
66
- if (clientSchemasCombined) return veto(clientSchemasCombined);
67
- return baseValidation;
68
- }, [baseValidation, clientSchemaValues]),
69
- setClientValidationSchema
70
- };
71
- };
72
- /**
73
- * Creates a React Hook Form resolver from an extended validation instance and
74
- * stores its latest formatted Veto errors as React state.
75
- *
76
- * Keeping the resolver errors in state lets Uniform context consumers re-render
77
- * when validation output changes, while the hash prevents repeated validations
78
- * with equivalent errors from causing unnecessary updates.
79
- *
80
- * @param extendedValidation - Extended validation instance from useExtendedValidation
81
- * @returns Resolver function plus the latest validation errors and their hash
82
- */
83
- const useFormResolver = (extendedValidation) => {
84
- const [validationErrorsState, setValidationErrorsState] = useState({
85
- errors: void 0,
86
- hash: void 0
87
- });
88
- /**
89
- * Updates resolver error state only when the formatted validation result
90
- * actually changes. Veto/RHF may create new error objects for equivalent
91
- * validation output, so the hash is the guard against avoidable context
92
- * refreshes.
93
- */
94
- const updateValidationErrors = useCallback((errors) => {
95
- const nextHash = JSON.stringify(errors);
96
- setValidationErrorsState((current) => {
97
- if (current.hash === nextHash) return current;
98
- return {
99
- errors,
100
- hash: nextHash
101
- };
102
- });
103
- }, []);
104
- return {
105
- resolver: useMemo(() => {
106
- if (!extendedValidation) return;
107
- return async (values) => {
108
- const validationValues = toValidationFormat(values) ?? {};
109
- const result = await extendedValidation.validateAsync(validationValues);
110
- updateValidationErrors(result.errors ?? void 0);
111
- return {
112
- values: result.data ?? {},
113
- errors: result.errors ?? {}
114
- };
115
- };
116
- }, [extendedValidation, updateValidationErrors]),
117
- validationErrors: validationErrorsState.errors,
118
- validationErrorsHash: validationErrorsState.hash
119
- };
120
- };
121
- //#endregion
122
- //#region src/Form/subcomponents/FormContext.tsx
123
- const debug = createDebug("uniform:FormContext");
124
- const DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT = "uniform:debug-mode";
125
- if (!window.__UNIFORM_CONTEXT__) {
126
- window.__UNIFORM_CONTEXT__ = React.createContext({
127
- debugMode: "off",
128
- formReset: {
129
- subscribe: () => {
130
- return () => {};
131
- },
132
- notify: () => {}
133
- },
134
- preventSubmit: () => {},
135
- setDebugMode: () => {},
136
- triggerSubmit: () => {},
137
- userChange: {
138
- subscribe: () => {
139
- return () => {};
140
- },
141
- notify: () => {}
142
- },
143
- validation: { setClientValidationSchema: () => {} }
144
- });
145
- debug("Creating new UniformContext instance");
146
- } else debug("Reusing existing UniformContext instance from window.__UNIFORM_CONTEXT__");
147
- const UniformContext = window.__UNIFORM_CONTEXT__;
148
- debug("UniformContext exported", {
149
- contextExists: !!UniformContext,
150
- windowContextExists: !!window.__UNIFORM_CONTEXT__,
151
- contextsMatch: UniformContext === window.__UNIFORM_CONTEXT__
152
- });
153
- /**
154
- * FormProvider component provides:
155
- * - Veto validation schema context
156
- * - Resolver-backed validation error state
157
- * - Client validation schema management
158
- * - Submit handler with automatic data conversion and submission control with preventSubmit
159
- * - Form Debug Mode state
160
- * - Form reset pub/sub notifications (`formReset`)
161
- * - User change pub/sub notifications (`userChange`)
162
- * - React Hook Form context
163
- */
164
- const FormProvider$1 = ({ children, debugModeSettings = void 0, initialValues = void 0, onSubmit, validation: baseValidation = void 0, validationTrigger }) => {
165
- const [debugMode, setDebugMode] = useLocalStorage(debugModeSettings?.localStorageKey ?? DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT, "off");
166
- const { extendedValidation, setClientValidationSchema } = useExtendedValidation(baseValidation);
167
- const { resolver, validationErrors, validationErrorsHash } = useFormResolver(extendedValidation);
168
- const methods = useForm({
169
- defaultValues: initialValues ? toFormFormat(initialValues) : initialValues,
170
- mode: validationTrigger,
171
- resolver
172
- });
173
- const isValid = methods.formState?.isValid;
174
- const [preventSubmit, setPreventSubmit] = useState(false);
175
- const formResetListenersRef = useRef(/* @__PURE__ */ new Set());
176
- const subscribeFormReset = useCallback((listener) => {
177
- formResetListenersRef.current.add(listener);
178
- return () => {
179
- formResetListenersRef.current.delete(listener);
180
- };
181
- }, []);
182
- const notifyFormReset = useCallback(() => {
183
- formResetListenersRef.current.forEach((listener) => {
184
- listener();
185
- });
186
- }, []);
187
- const userChangeListenersRef = useRef(/* @__PURE__ */ new Set());
188
- const subscribeUserChange = useCallback((listener) => {
189
- userChangeListenersRef.current.add(listener);
190
- return () => {
191
- userChangeListenersRef.current.delete(listener);
192
- };
193
- }, []);
194
- const notifyUserChange = useCallback((fieldName, value) => {
195
- userChangeListenersRef.current.forEach((listener) => {
196
- listener(fieldName, value);
197
- });
198
- }, []);
199
- const handleSubmit = async (e) => {
200
- debug("handleSubmit called", {
201
- preventSubmit,
202
- formStateIsValid: methods.formState.isValid,
203
- validationErrors: methods.formState.errors,
204
- validationTrigger,
205
- formValues: methods.getValues()
206
- });
207
- if (methods.formState.isValid && preventSubmit) {
208
- debug("⛔ Form submit PREVENTED", {
209
- formStateIsValid: methods.formState.isValid,
210
- preventSubmit
211
- });
212
- console.warn("[FormProvider] form submit was prevented because preventSubmit is true...");
213
- e?.preventDefault();
214
- return Promise.resolve();
215
- }
216
- debug("✓ Form submit ALLOWED", {
217
- formStateIsValid: methods.formState.isValid,
218
- preventSubmit,
219
- reason: !methods.formState.isValid ? "Form is invalid (will trigger validation and show errors)" : "Form is valid and preventSubmit is false"
220
- });
221
- const wrappedOnSubmit = (data, event) => {
222
- const submitData = toSubmitFormat(data) ?? {};
223
- debug("onSubmit callback called", { submitData });
224
- return onSubmit(submitData, event);
225
- };
226
- await methods.handleSubmit(wrappedOnSubmit)(e);
227
- debug("handleSubmit completed");
228
- };
229
- const contextValue = useMemo(() => {
230
- return {
231
- debugMode: debugModeSettings?.disable ? "disabled" : debugMode,
232
- preventSubmit: (prevent) => {
233
- debug("preventSubmit called", {
234
- previousValue: preventSubmit,
235
- newValue: prevent,
236
- formStateIsValid: methods.formState.isValid,
237
- validationErrors: methods.formState.errors
238
- });
239
- setPreventSubmit(prevent);
240
- },
241
- setClientValidationSchema,
242
- setDebugMode,
243
- triggerSubmit: handleSubmit,
244
- formReset: {
245
- subscribe: subscribeFormReset,
246
- notify: notifyFormReset
247
- },
248
- userChange: {
249
- subscribe: subscribeUserChange,
250
- notify: notifyUserChange
251
- },
252
- validation: {
253
- baseInstance: baseValidation,
254
- instance: extendedValidation,
255
- errors: validationErrors,
256
- setClientValidationSchema
257
- }
258
- };
259
- }, [
260
- debugMode,
261
- debugModeSettings?.disable,
262
- validationErrorsHash
263
- ]);
264
- return /* @__PURE__ */ jsx(UniformContext.Provider, {
265
- value: contextValue,
266
- children: /* @__PURE__ */ jsx(FormProvider, {
267
- ...methods,
268
- children: children({
269
- handleSubmit,
270
- isValid
271
- })
272
- })
273
- });
274
- };
275
- //#endregion
276
- export { UniformContext as n, FormProvider$1 as t };
277
-
278
- //# sourceMappingURL=FormContext-gHSwOlcy.mjs.map