@fuf-stack/uniform 1.22.1 → 1.22.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Checkboxes/index.cjs +1 -1
- package/dist/{Checkboxes-Ce7gp6L_.cjs → Checkboxes-DHk09GmH.cjs} +3 -3
- package/dist/{Checkboxes-Ce7gp6L_.cjs.map → Checkboxes-DHk09GmH.cjs.map} +1 -1
- package/dist/DatePicker/index.cjs +1 -1
- package/dist/DatePicker/index.d.cts +1 -1
- package/dist/DatePicker/index.d.ts +1 -1
- package/dist/{DatePicker-BAe4t169.cjs → DatePicker-DuBjvS5g.cjs} +2 -2
- package/dist/{DatePicker-BAe4t169.cjs.map → DatePicker-DuBjvS5g.cjs.map} +1 -1
- package/dist/FieldArray/index.cjs +1 -1
- package/dist/{FieldArray-iHmWagv3.cjs → FieldArray-DgiQpIdr.cjs} +4 -4
- package/dist/{FieldArray-iHmWagv3.cjs.map → FieldArray-DgiQpIdr.cjs.map} +1 -1
- package/dist/FieldCard/index.cjs +1 -1
- package/dist/FieldCard/index.js +1 -1
- package/dist/{FieldCard-x142VXrR.js → FieldCard-BK6SNqFY.js} +2 -2
- package/dist/{FieldCard-x142VXrR.js.map → FieldCard-BK6SNqFY.js.map} +1 -1
- package/dist/{FieldCard-D9c1j_RX.cjs → FieldCard-C-DZ5ARr.cjs} +4 -4
- package/dist/{FieldCard-D9c1j_RX.cjs.map → FieldCard-C-DZ5ARr.cjs.map} +1 -1
- package/dist/{FieldCopyTestIdButton-slAdYh6I.cjs → FieldCopyTestIdButton-ptoB1F75.cjs} +2 -2
- package/dist/{FieldCopyTestIdButton-slAdYh6I.cjs.map → FieldCopyTestIdButton-ptoB1F75.cjs.map} +1 -1
- package/dist/{FieldValidationError-BWrQN-Im.cjs → FieldValidationError-BQcvvU9i.cjs} +2 -2
- package/dist/{FieldValidationError-BWrQN-Im.cjs.map → FieldValidationError-BQcvvU9i.cjs.map} +1 -1
- package/dist/Form/index.cjs +1 -1
- package/dist/Form/index.d.cts +1 -1
- package/dist/Form/index.d.ts +1 -1
- package/dist/Form/index.js +1 -1
- package/dist/{Form-qbwbBna_.cjs → Form-CYlsIABv.cjs} +3 -3
- package/dist/{Form-qbwbBna_.cjs.map → Form-CYlsIABv.cjs.map} +1 -1
- package/dist/{Form-CwzO0-Wf.js → Form-D3yfDu4L.js} +3 -3
- package/dist/{Form-CwzO0-Wf.js.map → Form-D3yfDu4L.js.map} +1 -1
- package/dist/{FormContext-BuG3xZFe.d.cts → FormContext-3kamRn2C.d.cts} +4 -2
- package/dist/FormContext-3kamRn2C.d.cts.map +1 -0
- package/dist/{FormContext-Fwnjz-qH.js → FormContext-BQeKOV-0.js} +25 -1
- package/dist/FormContext-BQeKOV-0.js.map +1 -0
- package/dist/{FormContext-CjDd8Zej.cjs → FormContext-DsmS_mkO.cjs} +25 -1
- package/dist/FormContext-DsmS_mkO.cjs.map +1 -0
- package/dist/{FormContext-qrel_XTj.d.ts → FormContext-i66vM5f1.d.ts} +4 -2
- package/dist/FormContext-i66vM5f1.d.ts.map +1 -0
- package/dist/Grid/index.cjs +1 -1
- package/dist/{Grid-RbL6tNfn.cjs → Grid-D-VcRGi9.cjs} +2 -2
- package/dist/{Grid-RbL6tNfn.cjs.map → Grid-D-VcRGi9.cjs.map} +1 -1
- package/dist/Input/index.cjs +1 -1
- package/dist/Input/index.d.cts +1 -1
- package/dist/Input/index.d.ts +1 -1
- package/dist/{Input-CoY-URbn.cjs → Input-DvVViuWH.cjs} +2 -2
- package/dist/{Input-CoY-URbn.cjs.map → Input-DvVViuWH.cjs.map} +1 -1
- package/dist/RadioBoxes/index.cjs +1 -1
- package/dist/RadioBoxes/index.d.cts +1 -1
- package/dist/RadioBoxes/index.d.ts +1 -1
- package/dist/{RadioBoxes-D1hnc1Ri.cjs → RadioBoxes-CR--FBhQ.cjs} +2 -2
- package/dist/{RadioBoxes-D1hnc1Ri.cjs.map → RadioBoxes-CR--FBhQ.cjs.map} +1 -1
- package/dist/RadioTabs/index.cjs +1 -1
- package/dist/{RadioTabs-cOxm4bUG.cjs → RadioTabs-Btt582Nl.cjs} +2 -2
- package/dist/{RadioTabs-cOxm4bUG.cjs.map → RadioTabs-Btt582Nl.cjs.map} +1 -1
- package/dist/Radios/index.cjs +1 -1
- package/dist/Radios/index.d.cts +1 -1
- package/dist/Radios/index.d.ts +1 -1
- package/dist/{Radios-2ItHXQvj.cjs → Radios-Jg9mwE0B.cjs} +2 -2
- package/dist/{Radios-2ItHXQvj.cjs.map → Radios-Jg9mwE0B.cjs.map} +1 -1
- package/dist/Select/index.cjs +1 -1
- package/dist/Select/index.d.cts +1 -1
- package/dist/Select/index.d.ts +1 -1
- package/dist/Select/index.js +1 -1
- package/dist/{Select-B_4WR3xS.cjs → Select-CZwuEAB5.cjs} +3 -3
- package/dist/{Select-B_4WR3xS.cjs.map → Select-CZwuEAB5.cjs.map} +1 -1
- package/dist/{Select-CJm6d_2K.js → Select-CgeqhZIC.js} +2 -2
- package/dist/{Select-CJm6d_2K.js.map → Select-CgeqhZIC.js.map} +1 -1
- package/dist/Slider/index.cjs +1 -1
- package/dist/Slider/index.d.cts +1 -1
- package/dist/Slider/index.d.ts +1 -1
- package/dist/{Slider-BC5TEf2D.cjs → Slider-Bpxt-Qgj.cjs} +2 -2
- package/dist/{Slider-BC5TEf2D.cjs.map → Slider-Bpxt-Qgj.cjs.map} +1 -1
- package/dist/SubmitButton/index.cjs +1 -1
- package/dist/SubmitButton/index.js +1 -1
- package/dist/{SubmitButton-BeHeUxQw.cjs → SubmitButton-D-wn1PJV.cjs} +3 -3
- package/dist/{SubmitButton-BeHeUxQw.cjs.map → SubmitButton-D-wn1PJV.cjs.map} +1 -1
- package/dist/{SubmitButton-DULHEFre.js → SubmitButton-D6aU7IgC.js} +2 -2
- package/dist/{SubmitButton-DULHEFre.js.map → SubmitButton-D6aU7IgC.js.map} +1 -1
- package/dist/Switch/index.cjs +1 -1
- package/dist/Switch/index.d.cts +1 -1
- package/dist/Switch/index.d.ts +1 -1
- package/dist/{Switch-CEiKCrNc.cjs → Switch-hjjy34QB.cjs} +2 -2
- package/dist/{Switch-CEiKCrNc.cjs.map → Switch-hjjy34QB.cjs.map} +1 -1
- package/dist/SwitchBox/index.cjs +1 -1
- package/dist/{SwitchBox-D_wdu74r.cjs → SwitchBox-Dl-F5y2m.cjs} +2 -2
- package/dist/{SwitchBox-D_wdu74r.cjs.map → SwitchBox-Dl-F5y2m.cjs.map} +1 -1
- package/dist/TextArea/index.cjs +1 -1
- package/dist/TextArea/index.d.cts +1 -1
- package/dist/TextArea/index.d.ts +1 -1
- package/dist/{TextArea-euLXwb_s.cjs → TextArea-CMXm-kTK.cjs} +2 -2
- package/dist/{TextArea-euLXwb_s.cjs.map → TextArea-CMXm-kTK.cjs.map} +1 -1
- package/dist/Time/index.cjs +1 -1
- package/dist/Time/index.d.cts +1 -1
- package/dist/Time/index.d.ts +1 -1
- package/dist/{Time-mmSE7FJg.cjs → Time-WKgbji5k.cjs} +2 -2
- package/dist/{Time-mmSE7FJg.cjs.map → Time-WKgbji5k.cjs.map} +1 -1
- package/dist/helpers/index.cjs +1 -1
- package/dist/helpers/index.d.cts +224 -2
- package/dist/helpers/index.d.cts.map +1 -0
- package/dist/helpers/index.d.ts +224 -2
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/hooks/useClientValidation/index.cjs +1 -1
- package/dist/hooks/useClientValidation/index.d.cts +1 -1
- package/dist/hooks/useClientValidation/index.d.ts +1 -1
- package/dist/hooks/useClientValidation/index.js +1 -1
- package/dist/hooks/useController/index.cjs +1 -1
- package/dist/hooks/useController/index.d.cts +1 -1
- package/dist/hooks/useController/index.d.ts +1 -1
- package/dist/hooks/useController/index.js +1 -1
- package/dist/hooks/useFormContext/index.cjs +1 -1
- package/dist/hooks/useFormContext/index.d.cts +1 -1
- package/dist/hooks/useFormContext/index.d.ts +1 -1
- package/dist/hooks/useFormContext/index.js +1 -1
- package/dist/hooks/useInput/index.cjs +1 -1
- package/dist/hooks/useInputValueDebounce/index.cjs +2 -2
- package/dist/hooks/useInputValueDebounce/index.js +1 -1
- package/dist/hooks/useInputValueTransform/index.cjs +1 -1
- package/dist/hooks/useUniformField/index.cjs +6 -6
- package/dist/hooks/useUniformField/index.d.cts +1 -1
- package/dist/hooks/useUniformField/index.d.ts +1 -1
- package/dist/hooks/useUniformField/index.js +2 -2
- package/dist/hooks/useUniformFieldArray/index.cjs +23 -4
- package/dist/hooks/useUniformFieldArray/index.cjs.map +1 -1
- package/dist/hooks/useUniformFieldArray/index.d.cts +1 -1
- package/dist/hooks/useUniformFieldArray/index.d.ts +1 -1
- package/dist/hooks/useUniformFieldArray/index.js +23 -4
- package/dist/hooks/useUniformFieldArray/index.js.map +1 -1
- package/dist/hooks/useWatchFormReset/index.cjs +39 -0
- package/dist/hooks/useWatchFormReset/index.cjs.map +1 -0
- package/dist/hooks/useWatchFormReset/index.d.cts +2 -0
- package/dist/hooks/useWatchFormReset/index.d.ts +2 -0
- package/dist/hooks/useWatchFormReset/index.js +37 -0
- package/dist/hooks/useWatchFormReset/index.js.map +1 -0
- package/dist/hooks/useWatchUserChange/index.cjs +1 -1
- package/dist/hooks/useWatchUserChange/index.js +1 -1
- package/dist/{index-B3JBVqnz.d.ts → index-54OZEaUU.d.ts} +2 -2
- package/dist/{index-B3JBVqnz.d.ts.map → index-54OZEaUU.d.ts.map} +1 -1
- package/dist/{index-Dhlp1At5.d.ts → index-B4jKGy-P.d.ts} +16 -16
- package/dist/{index-Dhlp1At5.d.ts.map → index-B4jKGy-P.d.ts.map} +1 -1
- package/dist/{index-CSmkHvH5.d.cts → index-B61zRzeS.d.cts} +4 -4
- package/dist/{index-CSmkHvH5.d.cts.map → index-B61zRzeS.d.cts.map} +1 -1
- package/dist/{index-1EuWAERx.d.ts → index-BDFJDKmz.d.ts} +4 -4
- package/dist/{index-1EuWAERx.d.ts.map → index-BDFJDKmz.d.ts.map} +1 -1
- package/dist/{index-BIvupnq_.d.cts → index-BE4OAqJ2.d.cts} +7 -7
- package/dist/{index-BIvupnq_.d.cts.map → index-BE4OAqJ2.d.cts.map} +1 -1
- package/dist/{index-GxTY7aAc.d.ts → index-BMEKfOWp.d.ts} +4 -4
- package/dist/{index-GxTY7aAc.d.ts.map → index-BMEKfOWp.d.ts.map} +1 -1
- package/dist/{index-9_3XTDJC.d.cts → index-Bgo2Dr6X.d.cts} +4 -4
- package/dist/{index-9_3XTDJC.d.cts.map → index-Bgo2Dr6X.d.cts.map} +1 -1
- package/dist/{index-C9EqOSHz.d.cts → index-BvbHkoH5.d.cts} +10 -10
- package/dist/{index-C9EqOSHz.d.cts.map → index-BvbHkoH5.d.cts.map} +1 -1
- package/dist/index-C2gUMYkE.d.cts +1 -0
- package/dist/{index-D76g-bjx.d.cts → index-C3-TV4Up.d.cts} +2 -2
- package/dist/{index-D76g-bjx.d.cts.map → index-C3-TV4Up.d.cts.map} +1 -1
- package/dist/{index-2VnDgA2J.d.ts → index-C6DBVs7t.d.ts} +7 -7
- package/dist/{index-2VnDgA2J.d.ts.map → index-C6DBVs7t.d.ts.map} +1 -1
- package/dist/{index-CqyMqRhI.d.cts → index-CEJxjf5R.d.ts} +1 -1
- package/dist/index-CEJxjf5R.d.ts.map +1 -0
- package/dist/{index-COBktROL2.d.ts → index-CHQKk_fN2.d.ts} +1 -1
- package/dist/{index-BqiVSpJW.d.cts.map → index-CHQKk_fN2.d.ts.map} +1 -1
- package/dist/{index-DuOH2kzW.d.cts → index-CSRKNes5.d.cts} +16 -16
- package/dist/{index-DuOH2kzW.d.cts.map → index-CSRKNes5.d.cts.map} +1 -1
- package/dist/{index-BqiVSpJW.d.cts → index-CXvUaeCL.d.cts} +1 -1
- package/dist/{index-COBktROL2.d.ts.map → index-CXvUaeCL.d.cts.map} +1 -1
- package/dist/{index-B0MgOw9G.d.ts → index-CbPJiRK2.d.ts} +4 -4
- package/dist/{index-B0MgOw9G.d.ts.map → index-CbPJiRK2.d.ts.map} +1 -1
- package/dist/{index-DbRnysyM.d.ts → index-CbQ8Ft4o.d.ts} +7 -7
- package/dist/{index-DbRnysyM.d.ts.map → index-CbQ8Ft4o.d.ts.map} +1 -1
- package/dist/{index-dgho7gpc.d.ts → index-Cz4JaCWd.d.ts} +4 -4
- package/dist/{index-dgho7gpc.d.ts.map → index-Cz4JaCWd.d.ts.map} +1 -1
- package/dist/{index-BjKXOuyP.d.cts → index-DMOhTl4I.d.cts} +7 -7
- package/dist/{index-BjKXOuyP.d.cts.map → index-DMOhTl4I.d.cts.map} +1 -1
- package/dist/{index-Cq8UB0ir.d.cts → index-DUmNI6cE.d.cts} +4 -4
- package/dist/{index-Cq8UB0ir.d.cts.map → index-DUmNI6cE.d.cts.map} +1 -1
- package/dist/{index-DDuUbZ3x.d.cts → index-Db0WD4d1.d.cts} +4 -4
- package/dist/{index-DDuUbZ3x.d.cts.map → index-Db0WD4d1.d.cts.map} +1 -1
- package/dist/{index-BpaOeWBo.d.ts → index-GqydEAFk.d.ts} +10 -10
- package/dist/{index-BpaOeWBo.d.ts.map → index-GqydEAFk.d.ts.map} +1 -1
- package/dist/{index-D1m6qfLO2.d.ts → index-P30z4VRT.d.cts} +1 -1
- package/dist/{index-CqyMqRhI.d.cts.map → index-P30z4VRT.d.cts.map} +1 -1
- package/dist/{index-B87U0Tx5.d.ts → index-PMCqBX0t.d.ts} +4 -4
- package/dist/{index-B87U0Tx5.d.ts.map → index-PMCqBX0t.d.ts.map} +1 -1
- package/dist/{index-QgVr4iWX.d.cts → index-Q3BWGyUO.d.cts} +4 -4
- package/dist/{index-QgVr4iWX.d.cts.map → index-Q3BWGyUO.d.cts.map} +1 -1
- package/dist/index-h64gcVNJ.d.ts +1 -0
- package/dist/index.cjs +27 -25
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -19
- package/dist/index.d.ts +20 -19
- package/dist/index.js +10 -9
- package/dist/index.js.map +1 -1
- package/dist/partials/FieldCopyTestIdButton/index.cjs +1 -1
- package/dist/partials/FieldCopyTestIdButton/index.d.cts +1 -1
- package/dist/partials/FieldCopyTestIdButton/index.d.ts +1 -1
- package/dist/partials/FieldValidationError/index.cjs +1 -1
- package/dist/partials/FieldValidationError/index.d.cts +1 -1
- package/dist/partials/FieldValidationError/index.d.ts +1 -1
- package/dist/{useClientValidation-THb-oOkO.cjs → useClientValidation-BRfhqRom.cjs} +3 -3
- package/dist/{useClientValidation-THb-oOkO.cjs.map → useClientValidation-BRfhqRom.cjs.map} +1 -1
- package/dist/{useClientValidation-DW5pYWyi.d.cts → useClientValidation-C2dLJnDI.d.cts} +1 -1
- package/dist/{useClientValidation-DW5pYWyi.d.cts.map → useClientValidation-C2dLJnDI.d.cts.map} +1 -1
- package/dist/{useClientValidation-DJLKWU1v.js → useClientValidation-DpLdzIAb.js} +2 -2
- package/dist/{useClientValidation-DJLKWU1v.js.map → useClientValidation-DpLdzIAb.js.map} +1 -1
- package/dist/{useClientValidation-BkIsMCEl.d.ts → useClientValidation-qRq2_spX.d.ts} +1 -1
- package/dist/{useClientValidation-BkIsMCEl.d.ts.map → useClientValidation-qRq2_spX.d.ts.map} +1 -1
- package/dist/{useController-BCvnjoe0.cjs → useController--lRPWBuD.cjs} +2 -2
- package/dist/{useController-BCvnjoe0.cjs.map → useController--lRPWBuD.cjs.map} +1 -1
- package/dist/{useController-DVF2y3O3.js → useController-B287flU_.js} +2 -2
- package/dist/{useController-DVF2y3O3.js.map → useController-B287flU_.js.map} +1 -1
- package/dist/{useController-C8DLa8j5.d.cts → useController-BT3Fd0IO.d.cts} +1 -1
- package/dist/{useController-C8DLa8j5.d.cts.map → useController-BT3Fd0IO.d.cts.map} +1 -1
- package/dist/{useController-Bl0Qup0s.d.ts → useController-CzP0aVFC.d.ts} +1 -1
- package/dist/{useController-Bl0Qup0s.d.ts.map → useController-CzP0aVFC.d.ts.map} +1 -1
- package/dist/{useFormContext-BbTP0PIW.d.ts → useFormContext-Bj1gXLt_.d.ts} +7 -3
- package/dist/useFormContext-Bj1gXLt_.d.ts.map +1 -0
- package/dist/{useFormContext-DJ-9hs8X.js → useFormContext-CT8H8xIe.js} +14 -3
- package/dist/useFormContext-CT8H8xIe.js.map +1 -0
- package/dist/{useFormContext-C_EQr8dV.cjs → useFormContext-CrXwNYiB.cjs} +14 -3
- package/dist/useFormContext-CrXwNYiB.cjs.map +1 -0
- package/dist/{useFormContext-BSDtq3J5.d.cts → useFormContext-M94eQfHm.d.cts} +7 -3
- package/dist/useFormContext-M94eQfHm.d.cts.map +1 -0
- package/dist/{useInputValueTransform-f50WxOkF.cjs → useInputValueTransform-Bm65K8LX.cjs} +2 -2
- package/dist/{useInputValueTransform-f50WxOkF.cjs.map → useInputValueTransform-Bm65K8LX.cjs.map} +1 -1
- package/dist/{useUniformField-CXK_23F9.d.cts → useUniformField-BE-e3C4Y.d.cts} +3 -3
- package/dist/{useUniformField-CXK_23F9.d.cts.map → useUniformField-BE-e3C4Y.d.cts.map} +1 -1
- package/dist/{useUniformField-BWef-AXr.d.ts → useUniformField-DUW-svZD.d.ts} +3 -3
- package/dist/{useUniformField-BWef-AXr.d.ts.map → useUniformField-DUW-svZD.d.ts.map} +1 -1
- package/dist/{useUniformFieldArray-9kCb5G9q.d.ts → useUniformFieldArray-CdWv1SEk.d.ts} +5 -3
- package/dist/useUniformFieldArray-CdWv1SEk.d.ts.map +1 -0
- package/dist/{useUniformFieldArray-Bx7v1U2d.d.cts → useUniformFieldArray-kkOHxNFF.d.cts} +5 -3
- package/dist/useUniformFieldArray-kkOHxNFF.d.cts.map +1 -0
- package/dist/useWatchFormReset-BSd6jMxU.d.cts +38 -0
- package/dist/useWatchFormReset-BSd6jMxU.d.cts.map +1 -0
- package/dist/useWatchFormReset-C7YJ-I3N.d.ts +38 -0
- package/dist/useWatchFormReset-C7YJ-I3N.d.ts.map +1 -0
- package/dist/{useWatchUserChange-YtVWYw_E.cjs → useWatchUserChange-C1xWHtFG.cjs} +3 -3
- package/dist/{useWatchUserChange-YtVWYw_E.cjs.map → useWatchUserChange-C1xWHtFG.cjs.map} +1 -1
- package/dist/{useWatchUserChange-Bnx3tOOR.js → useWatchUserChange-DSQGsl1R.js} +2 -2
- package/dist/{useWatchUserChange-Bnx3tOOR.js.map → useWatchUserChange-DSQGsl1R.js.map} +1 -1
- package/package.json +7 -3
- package/dist/FormContext-BuG3xZFe.d.cts.map +0 -1
- package/dist/FormContext-CjDd8Zej.cjs.map +0 -1
- package/dist/FormContext-Fwnjz-qH.js.map +0 -1
- package/dist/FormContext-qrel_XTj.d.ts.map +0 -1
- package/dist/index-BAg613AJ.d.cts +0 -224
- package/dist/index-BAg613AJ.d.cts.map +0 -1
- package/dist/index-BvCTs-LU.d.ts +0 -224
- package/dist/index-BvCTs-LU.d.ts.map +0 -1
- package/dist/index-D1m6qfLO2.d.ts.map +0 -1
- package/dist/useFormContext-BSDtq3J5.d.cts.map +0 -1
- package/dist/useFormContext-BbTP0PIW.d.ts.map +0 -1
- package/dist/useFormContext-C_EQr8dV.cjs.map +0 -1
- package/dist/useFormContext-DJ-9hs8X.js.map +0 -1
- package/dist/useUniformFieldArray-9kCb5G9q.d.ts.map +0 -1
- package/dist/useUniformFieldArray-Bx7v1U2d.d.cts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClientValidation-THb-oOkO.cjs","names":["useFormContext"],"sources":["../src/hooks/useClientValidation/useClientValidation.ts"],"sourcesContent":["import type { VetoTypeAny } from '@fuf-stack/veto';\n\nimport { useEffect, useId } from 'react';\n\nimport { array, objectLoose } from '@fuf-stack/veto';\n\nimport { flatArrayKey } from '../../helpers';\nimport { useFormContext } from '../useFormContext/useFormContext';\n\n/**\n * Hook for adding dynamic client-side validation to forms.\n *\n * Client validation is used for context-dependent validation rules that require external data\n * (e.g., checking if a username already exists). It complements base validation (passed to Form),\n * which handles static rules like \"required\", min/max length, format, etc.\n *\n * **Typical pattern:**\n * - Base validation: Static, always-on rules (required, format, length constraints)\n * - Client validation: Dynamic rules based on external data (uniqueness, business logic)\n * - Client schemas should use `.nullish()` to allow empty values (base validation handles \"required\")\n *\n * Automatically manages validation schema lifecycle: sets schema when data is provided,\n * clears schema when data is null/undefined, and cleans up on unmount. When the client\n * validation schema changes, automatically re-validates all touched fields.\n *\n * @param data - Data to create validation schema from (or null/undefined to clear validation)\n * @param schemaFactory - Function that creates a validation schema from the data. Schemas should typically use `.nullish()`.\n * @param options - Optional configuration object\n * @param options.key - Optional custom key for registration. Useful when multiple instances should share validation (e.g., in field arrays)\n *\n * @example\n * ```tsx\n * // Base validation handles \"required\" and format\n * const baseSchema = veto({ username: vt.string({ min: 3 }) });\n *\n * // Client validation adds dynamic uniqueness check\n * const { data: teamData } = useTeamQuery(teamId);\n * useClientValidation(teamData, (data) =>\n * vt.objectLoose({\n * username: vt.string()\n * .refine(\n * (value) => !data.existingUsers.includes(value),\n * { message: 'Username already exists' }\n * )\n * .nullish() // Allow empty - base validation handles \"required\"\n * })\n * );\n * ```\n *\n * @example\n * ```tsx\n * // Using custom key in a field array to avoid multiple registrations\n * fields.map((field, index) => (\n * useClientValidation(\n * userData,\n * (data) => clientValidationSchemaByName(\n * `items.${index}.name`,\n * vt.string()\n * .refine((val) => !data.forbidden.includes(val), { message: 'Name not allowed' })\n * .nullish()\n * ),\n * { key: 'items-validation' } // All instances share the same key\n * )\n * ));\n * ```\n */\nexport const useClientValidation = <TData = unknown>(\n data: TData | null | undefined,\n schemaFactory: (data: TData) => VetoTypeAny,\n options?: { key?: string },\n): void => {\n const {\n formState: { touchedFields },\n validation: { setClientValidationSchema },\n trigger,\n } = useFormContext();\n\n // Use provided key or auto-generate unique key\n const autoGeneratedKey = useId();\n const key = options?.key ?? autoGeneratedKey;\n\n // Use data hash instead of object reference to avoid unnecessary re-runs\n // when data object reference changes but data remains the same\n const dataHash = JSON.stringify(data);\n\n // Single effect to manage validation schema lifecycle\n useEffect(() => {\n // Set validation schema when data is available\n if (data != null) {\n const validationSchema = schemaFactory(data);\n setClientValidationSchema(key, validationSchema);\n } else {\n // Clear validation schema when no data\n setClientValidationSchema(key, null);\n }\n\n // Re-validate all touched fields when client validation schema changes\n const touchedFieldNames = Object.keys(touchedFields);\n if (touchedFieldNames.length > 0) {\n // Use setTimeout to ensure the client validation schema update has propagated\n // before triggering re-validation (fixes race condition)\n setTimeout(async () => {\n return trigger(touchedFieldNames);\n }, 1);\n }\n\n // Cleanup on unmount or when dependencies change\n return () => {\n setClientValidationSchema(key, null);\n };\n // Only re-run when data (dataHash) or key changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [dataHash, key]);\n};\n\n/**\n * Helper function to create a veto looseObject schema for a single field with nested path support.\n *\n * Parses field paths (dot-notation) and creates properly nested loose object schemas with array support.\n * All intermediate objects and arrays are marked as optional to allow partial data structures.\n * Numeric segments in the path are treated as array indices, and the parent field is wrapped in an array schema.\n * Supports flat arrays (arrays of primitives) via the special `__FLAT__` key.\n *\n * **Important:** The fieldSchema should typically use `.nullish()` to allow empty values. This is because:\n * - Base validation (passed to Form) handles \"required\" constraints\n * - Client validation adds dynamic, context-dependent rules (e.g., \"username already exists\")\n * - Form data processing converts empty strings in flat arrays to `null` (not `undefined`)\n * - `.nullish()` accepts both `null` and `undefined`, while `.optional()` only accepts `undefined`\n *\n * This pattern ensures client validation only validates non-empty values, while base validation\n * enforces required fields and basic constraints (min length, format, etc.).\n *\n * @param name - The dot-separated path to the field (e.g., 'username', 'user.profile.email', 'items.0.name', 'tags.0.__FLAT__')\n * @param fieldSchema - The veto validation schema for the field. Should typically use `.nullish()` to allow empty values.\n * @returns A nested loose object schema matching the field path structure with proper type inference\n *\n * @example\n * ```tsx\n * // Typical usage: base validation handles \"required\", client validation adds dynamic rules\n * // Base validation (in Form component)\n * const baseSchema = veto({ username: vt.string({ min: 3 }) }); // Required + min length\n *\n * // Client validation (dynamic check for existing usernames)\n * const { data: userData } = useUserQuery(userId);\n * useClientValidation(userData, (data) =>\n * clientValidationSchemaByName(\n * 'username',\n * vt.string()\n * .refine(\n * (value) => !data.existingUsernames.includes(value),\n * { message: 'Username already taken' }\n * )\n * .nullish() // Allow empty - base validation handles \"required\"\n * )\n * );\n * ```\n *\n * @example\n * ```tsx\n * // Nested field path with dynamic validation\n * clientValidationSchemaByName(\n * 'user.profile.email',\n * vt.string()\n * .refine(\n * (value) => !reservedEmails.includes(value),\n * { message: 'This email is reserved' }\n * )\n * .nullish()\n * )\n * // => objectLoose({ user: objectLoose({ profile: objectLoose({ email: ... }).optional() }).optional() })\n * ```\n *\n * @example\n * ```tsx\n * // Array of objects with dynamic validation\n * clientValidationSchemaByName(\n * 'items.0.tag',\n * vt.string()\n * .refine((value) => !forbiddenTags.includes(value), { message: 'Tag not allowed' })\n * .nullish()\n * )\n * // => objectLoose({ items: array(objectLoose({ tag: ... })).optional() })\n * ```\n *\n * @example\n * ```tsx\n * // Flat array (array of primitives) with dynamic validation\n * clientValidationSchemaByName(\n * 'tags.0.__FLAT__',\n * vt.string()\n * .refine((value) => !forbiddenWords.includes(value), { message: 'Word not allowed' })\n * .nullish()\n * )\n * // => objectLoose({ tags: array(vt.string().refine(...).nullish()).optional() })\n * ```\n */\nexport const clientValidationSchemaByName = <T extends VetoTypeAny>(\n name: string,\n fieldSchema: T,\n) => {\n const segments = name.split('.');\n\n // Build schema from innermost to outermost\n let schema: VetoTypeAny = fieldSchema;\n\n // Process segments in reverse order to build nested structure\n for (let i = segments.length - 1; i >= 0; i -= 1) {\n const segment = segments[i];\n\n const isNumeric = /^\\d+$/.test(segment);\n const isFlatArrayKey = segment === flatArrayKey;\n\n if (isFlatArrayKey) {\n // Skip the __FLAT__ key - it's just a marker for flat arrays\n // The schema is already correct (primitive type), just continue\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (isNumeric) {\n // Current segment is an array index - wrap current schema in optional array\n schema = array(schema).optional();\n } else {\n // Current segment is a field name - wrap in objectLoose\n // Make it optional if it's an intermediate object (not the root)\n const obj = objectLoose({\n [segment]: schema,\n });\n schema = i > 0 ? obj.optional() : obj;\n }\n }\n\n return schema;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,MAAa,uBACX,MACA,eACA,YACS;CACT,MAAM,EACJ,WAAW,EAAE,iBACb,YAAY,EAAE,6BACd,YACEA,uBAAAA,eAAe;CAGnB,MAAM,oBAAA,GAAA,MAAA,OAAyB;CAC/B,MAAM,MAAM,SAAS,OAAO;CAO5B,CAAA,GAAA,MAAA,iBAAgB;EAEd,IAAI,QAAQ,MAEV,0BAA0B,KADD,cAAc,IACO,CAAC;OAG/C,0BAA0B,KAAK,IAAI;EAIrC,MAAM,oBAAoB,OAAO,KAAK,aAAa;EACnD,IAAI,kBAAkB,SAAS,GAG7B,WAAW,YAAY;GACrB,OAAO,QAAQ,iBAAiB;EAClC,GAAG,CAAC;EAIN,aAAa;GACX,0BAA0B,KAAK,IAAI;EACrC;CAGF,GAAG,CA7Bc,KAAK,UAAU,IA6BrB,GAAG,GAAG,CAAC;AACpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,MAAa,gCACX,MACA,gBACG;CACH,MAAM,WAAW,KAAK,MAAM,GAAG;CAG/B,IAAI,SAAsB;CAG1B,KAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;EAChD,MAAM,UAAU,SAAS;EAEzB,MAAM,YAAY,QAAQ,KAAK,OAAO;EAGtC,IAFuB,YAAA,YAMrB;EAGF,IAAI,WAEF,UAAA,GAAA,gBAAA,OAAe,MAAM,EAAE,SAAS;OAC3B;GAGL,MAAM,OAAA,GAAA,gBAAA,aAAkB,GACrB,UAAU,OACb,CAAC;GACD,SAAS,IAAI,IAAI,IAAI,SAAS,IAAI;EACpC;CACF;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"useClientValidation-BRfhqRom.cjs","names":["useFormContext"],"sources":["../src/hooks/useClientValidation/useClientValidation.ts"],"sourcesContent":["import type { VetoTypeAny } from '@fuf-stack/veto';\n\nimport { useEffect, useId } from 'react';\n\nimport { array, objectLoose } from '@fuf-stack/veto';\n\nimport { flatArrayKey } from '../../helpers';\nimport { useFormContext } from '../useFormContext/useFormContext';\n\n/**\n * Hook for adding dynamic client-side validation to forms.\n *\n * Client validation is used for context-dependent validation rules that require external data\n * (e.g., checking if a username already exists). It complements base validation (passed to Form),\n * which handles static rules like \"required\", min/max length, format, etc.\n *\n * **Typical pattern:**\n * - Base validation: Static, always-on rules (required, format, length constraints)\n * - Client validation: Dynamic rules based on external data (uniqueness, business logic)\n * - Client schemas should use `.nullish()` to allow empty values (base validation handles \"required\")\n *\n * Automatically manages validation schema lifecycle: sets schema when data is provided,\n * clears schema when data is null/undefined, and cleans up on unmount. When the client\n * validation schema changes, automatically re-validates all touched fields.\n *\n * @param data - Data to create validation schema from (or null/undefined to clear validation)\n * @param schemaFactory - Function that creates a validation schema from the data. Schemas should typically use `.nullish()`.\n * @param options - Optional configuration object\n * @param options.key - Optional custom key for registration. Useful when multiple instances should share validation (e.g., in field arrays)\n *\n * @example\n * ```tsx\n * // Base validation handles \"required\" and format\n * const baseSchema = veto({ username: vt.string({ min: 3 }) });\n *\n * // Client validation adds dynamic uniqueness check\n * const { data: teamData } = useTeamQuery(teamId);\n * useClientValidation(teamData, (data) =>\n * vt.objectLoose({\n * username: vt.string()\n * .refine(\n * (value) => !data.existingUsers.includes(value),\n * { message: 'Username already exists' }\n * )\n * .nullish() // Allow empty - base validation handles \"required\"\n * })\n * );\n * ```\n *\n * @example\n * ```tsx\n * // Using custom key in a field array to avoid multiple registrations\n * fields.map((field, index) => (\n * useClientValidation(\n * userData,\n * (data) => clientValidationSchemaByName(\n * `items.${index}.name`,\n * vt.string()\n * .refine((val) => !data.forbidden.includes(val), { message: 'Name not allowed' })\n * .nullish()\n * ),\n * { key: 'items-validation' } // All instances share the same key\n * )\n * ));\n * ```\n */\nexport const useClientValidation = <TData = unknown>(\n data: TData | null | undefined,\n schemaFactory: (data: TData) => VetoTypeAny,\n options?: { key?: string },\n): void => {\n const {\n formState: { touchedFields },\n validation: { setClientValidationSchema },\n trigger,\n } = useFormContext();\n\n // Use provided key or auto-generate unique key\n const autoGeneratedKey = useId();\n const key = options?.key ?? autoGeneratedKey;\n\n // Use data hash instead of object reference to avoid unnecessary re-runs\n // when data object reference changes but data remains the same\n const dataHash = JSON.stringify(data);\n\n // Single effect to manage validation schema lifecycle\n useEffect(() => {\n // Set validation schema when data is available\n if (data != null) {\n const validationSchema = schemaFactory(data);\n setClientValidationSchema(key, validationSchema);\n } else {\n // Clear validation schema when no data\n setClientValidationSchema(key, null);\n }\n\n // Re-validate all touched fields when client validation schema changes\n const touchedFieldNames = Object.keys(touchedFields);\n if (touchedFieldNames.length > 0) {\n // Use setTimeout to ensure the client validation schema update has propagated\n // before triggering re-validation (fixes race condition)\n setTimeout(async () => {\n return trigger(touchedFieldNames);\n }, 1);\n }\n\n // Cleanup on unmount or when dependencies change\n return () => {\n setClientValidationSchema(key, null);\n };\n // Only re-run when data (dataHash) or key changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [dataHash, key]);\n};\n\n/**\n * Helper function to create a veto looseObject schema for a single field with nested path support.\n *\n * Parses field paths (dot-notation) and creates properly nested loose object schemas with array support.\n * All intermediate objects and arrays are marked as optional to allow partial data structures.\n * Numeric segments in the path are treated as array indices, and the parent field is wrapped in an array schema.\n * Supports flat arrays (arrays of primitives) via the special `__FLAT__` key.\n *\n * **Important:** The fieldSchema should typically use `.nullish()` to allow empty values. This is because:\n * - Base validation (passed to Form) handles \"required\" constraints\n * - Client validation adds dynamic, context-dependent rules (e.g., \"username already exists\")\n * - Form data processing converts empty strings in flat arrays to `null` (not `undefined`)\n * - `.nullish()` accepts both `null` and `undefined`, while `.optional()` only accepts `undefined`\n *\n * This pattern ensures client validation only validates non-empty values, while base validation\n * enforces required fields and basic constraints (min length, format, etc.).\n *\n * @param name - The dot-separated path to the field (e.g., 'username', 'user.profile.email', 'items.0.name', 'tags.0.__FLAT__')\n * @param fieldSchema - The veto validation schema for the field. Should typically use `.nullish()` to allow empty values.\n * @returns A nested loose object schema matching the field path structure with proper type inference\n *\n * @example\n * ```tsx\n * // Typical usage: base validation handles \"required\", client validation adds dynamic rules\n * // Base validation (in Form component)\n * const baseSchema = veto({ username: vt.string({ min: 3 }) }); // Required + min length\n *\n * // Client validation (dynamic check for existing usernames)\n * const { data: userData } = useUserQuery(userId);\n * useClientValidation(userData, (data) =>\n * clientValidationSchemaByName(\n * 'username',\n * vt.string()\n * .refine(\n * (value) => !data.existingUsernames.includes(value),\n * { message: 'Username already taken' }\n * )\n * .nullish() // Allow empty - base validation handles \"required\"\n * )\n * );\n * ```\n *\n * @example\n * ```tsx\n * // Nested field path with dynamic validation\n * clientValidationSchemaByName(\n * 'user.profile.email',\n * vt.string()\n * .refine(\n * (value) => !reservedEmails.includes(value),\n * { message: 'This email is reserved' }\n * )\n * .nullish()\n * )\n * // => objectLoose({ user: objectLoose({ profile: objectLoose({ email: ... }).optional() }).optional() })\n * ```\n *\n * @example\n * ```tsx\n * // Array of objects with dynamic validation\n * clientValidationSchemaByName(\n * 'items.0.tag',\n * vt.string()\n * .refine((value) => !forbiddenTags.includes(value), { message: 'Tag not allowed' })\n * .nullish()\n * )\n * // => objectLoose({ items: array(objectLoose({ tag: ... })).optional() })\n * ```\n *\n * @example\n * ```tsx\n * // Flat array (array of primitives) with dynamic validation\n * clientValidationSchemaByName(\n * 'tags.0.__FLAT__',\n * vt.string()\n * .refine((value) => !forbiddenWords.includes(value), { message: 'Word not allowed' })\n * .nullish()\n * )\n * // => objectLoose({ tags: array(vt.string().refine(...).nullish()).optional() })\n * ```\n */\nexport const clientValidationSchemaByName = <T extends VetoTypeAny>(\n name: string,\n fieldSchema: T,\n) => {\n const segments = name.split('.');\n\n // Build schema from innermost to outermost\n let schema: VetoTypeAny = fieldSchema;\n\n // Process segments in reverse order to build nested structure\n for (let i = segments.length - 1; i >= 0; i -= 1) {\n const segment = segments[i];\n\n const isNumeric = /^\\d+$/.test(segment);\n const isFlatArrayKey = segment === flatArrayKey;\n\n if (isFlatArrayKey) {\n // Skip the __FLAT__ key - it's just a marker for flat arrays\n // The schema is already correct (primitive type), just continue\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (isNumeric) {\n // Current segment is an array index - wrap current schema in optional array\n schema = array(schema).optional();\n } else {\n // Current segment is a field name - wrap in objectLoose\n // Make it optional if it's an intermediate object (not the root)\n const obj = objectLoose({\n [segment]: schema,\n });\n schema = i > 0 ? obj.optional() : obj;\n }\n }\n\n return schema;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,MAAa,uBACX,MACA,eACA,YACS;CACT,MAAM,EACJ,WAAW,EAAE,iBACb,YAAY,EAAE,6BACd,YACEA,uBAAAA,eAAe;CAGnB,MAAM,oBAAA,GAAA,MAAA,OAAyB;CAC/B,MAAM,MAAM,SAAS,OAAO;CAO5B,CAAA,GAAA,MAAA,iBAAgB;EAEd,IAAI,QAAQ,MAEV,0BAA0B,KADD,cAAc,IACO,CAAC;OAG/C,0BAA0B,KAAK,IAAI;EAIrC,MAAM,oBAAoB,OAAO,KAAK,aAAa;EACnD,IAAI,kBAAkB,SAAS,GAG7B,WAAW,YAAY;GACrB,OAAO,QAAQ,iBAAiB;EAClC,GAAG,CAAC;EAIN,aAAa;GACX,0BAA0B,KAAK,IAAI;EACrC;CAGF,GAAG,CA7Bc,KAAK,UAAU,IA6BrB,GAAG,GAAG,CAAC;AACpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,MAAa,gCACX,MACA,gBACG;CACH,MAAM,WAAW,KAAK,MAAM,GAAG;CAG/B,IAAI,SAAsB;CAG1B,KAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;EAChD,MAAM,UAAU,SAAS;EAEzB,MAAM,YAAY,QAAQ,KAAK,OAAO;EAGtC,IAFuB,YAAA,YAMrB;EAGF,IAAI,WAEF,UAAA,GAAA,gBAAA,OAAe,MAAM,EAAE,SAAS;OAC3B;GAGL,MAAM,OAAA,GAAA,gBAAA,aAAkB,GACrB,UAAU,OACb,CAAC;GACD,SAAS,IAAI,IAAI,IAAI,SAAS,IAAI;EACpC;CACF;CAEA,OAAO;AACT"}
|
|
@@ -145,4 +145,4 @@ declare const useClientValidation: <TData = unknown>(data: TData | null | undefi
|
|
|
145
145
|
declare const clientValidationSchemaByName: <T extends VetoTypeAny>(name: string, fieldSchema: T) => VetoTypeAny;
|
|
146
146
|
//#endregion
|
|
147
147
|
export { useClientValidation as n, clientValidationSchemaByName as t };
|
|
148
|
-
//# sourceMappingURL=useClientValidation-
|
|
148
|
+
//# sourceMappingURL=useClientValidation-C2dLJnDI.d.cts.map
|
package/dist/{useClientValidation-DW5pYWyi.d.cts.map → useClientValidation-C2dLJnDI.d.cts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClientValidation-
|
|
1
|
+
{"version":3,"file":"useClientValidation-C2dLJnDI.d.cts","names":[],"sources":["../src/hooks/useClientValidation/useClientValidation.ts"],"mappings":";;;;;AAkEA;;;;;;;;;;;;;;;;;;AAG4B;AA+H5B;;;;;;;;;;;;;;;AAqCC;;;;;;;;;;;;;;;;;;;;;cAvKY,mBAAA,oBACX,IAAA,EAAM,KAAA,qBACN,aAAA,GAAgB,IAAA,EAAM,KAAA,KAAU,WAAA,EAChC,OAAA;EAAY,GAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+HD,4BAAA,aAA0C,WAAA,EACrD,IAAA,UACA,WAAA,EAAa,CAAA,KAAC,WAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./helpers/index.js";
|
|
2
|
-
import { n as useFormContext } from "./useFormContext-
|
|
2
|
+
import { n as useFormContext } from "./useFormContext-CT8H8xIe.js";
|
|
3
3
|
import { useEffect, useId } from "react";
|
|
4
4
|
import { array, objectLoose } from "@fuf-stack/veto";
|
|
5
5
|
//#region src/hooks/useClientValidation/useClientValidation.ts
|
|
@@ -175,4 +175,4 @@ const clientValidationSchemaByName = (name, fieldSchema) => {
|
|
|
175
175
|
//#endregion
|
|
176
176
|
export { useClientValidation as n, clientValidationSchemaByName as t };
|
|
177
177
|
|
|
178
|
-
//# sourceMappingURL=useClientValidation-
|
|
178
|
+
//# sourceMappingURL=useClientValidation-DpLdzIAb.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClientValidation-DJLKWU1v.js","names":[],"sources":["../src/hooks/useClientValidation/useClientValidation.ts"],"sourcesContent":["import type { VetoTypeAny } from '@fuf-stack/veto';\n\nimport { useEffect, useId } from 'react';\n\nimport { array, objectLoose } from '@fuf-stack/veto';\n\nimport { flatArrayKey } from '../../helpers';\nimport { useFormContext } from '../useFormContext/useFormContext';\n\n/**\n * Hook for adding dynamic client-side validation to forms.\n *\n * Client validation is used for context-dependent validation rules that require external data\n * (e.g., checking if a username already exists). It complements base validation (passed to Form),\n * which handles static rules like \"required\", min/max length, format, etc.\n *\n * **Typical pattern:**\n * - Base validation: Static, always-on rules (required, format, length constraints)\n * - Client validation: Dynamic rules based on external data (uniqueness, business logic)\n * - Client schemas should use `.nullish()` to allow empty values (base validation handles \"required\")\n *\n * Automatically manages validation schema lifecycle: sets schema when data is provided,\n * clears schema when data is null/undefined, and cleans up on unmount. When the client\n * validation schema changes, automatically re-validates all touched fields.\n *\n * @param data - Data to create validation schema from (or null/undefined to clear validation)\n * @param schemaFactory - Function that creates a validation schema from the data. Schemas should typically use `.nullish()`.\n * @param options - Optional configuration object\n * @param options.key - Optional custom key for registration. Useful when multiple instances should share validation (e.g., in field arrays)\n *\n * @example\n * ```tsx\n * // Base validation handles \"required\" and format\n * const baseSchema = veto({ username: vt.string({ min: 3 }) });\n *\n * // Client validation adds dynamic uniqueness check\n * const { data: teamData } = useTeamQuery(teamId);\n * useClientValidation(teamData, (data) =>\n * vt.objectLoose({\n * username: vt.string()\n * .refine(\n * (value) => !data.existingUsers.includes(value),\n * { message: 'Username already exists' }\n * )\n * .nullish() // Allow empty - base validation handles \"required\"\n * })\n * );\n * ```\n *\n * @example\n * ```tsx\n * // Using custom key in a field array to avoid multiple registrations\n * fields.map((field, index) => (\n * useClientValidation(\n * userData,\n * (data) => clientValidationSchemaByName(\n * `items.${index}.name`,\n * vt.string()\n * .refine((val) => !data.forbidden.includes(val), { message: 'Name not allowed' })\n * .nullish()\n * ),\n * { key: 'items-validation' } // All instances share the same key\n * )\n * ));\n * ```\n */\nexport const useClientValidation = <TData = unknown>(\n data: TData | null | undefined,\n schemaFactory: (data: TData) => VetoTypeAny,\n options?: { key?: string },\n): void => {\n const {\n formState: { touchedFields },\n validation: { setClientValidationSchema },\n trigger,\n } = useFormContext();\n\n // Use provided key or auto-generate unique key\n const autoGeneratedKey = useId();\n const key = options?.key ?? autoGeneratedKey;\n\n // Use data hash instead of object reference to avoid unnecessary re-runs\n // when data object reference changes but data remains the same\n const dataHash = JSON.stringify(data);\n\n // Single effect to manage validation schema lifecycle\n useEffect(() => {\n // Set validation schema when data is available\n if (data != null) {\n const validationSchema = schemaFactory(data);\n setClientValidationSchema(key, validationSchema);\n } else {\n // Clear validation schema when no data\n setClientValidationSchema(key, null);\n }\n\n // Re-validate all touched fields when client validation schema changes\n const touchedFieldNames = Object.keys(touchedFields);\n if (touchedFieldNames.length > 0) {\n // Use setTimeout to ensure the client validation schema update has propagated\n // before triggering re-validation (fixes race condition)\n setTimeout(async () => {\n return trigger(touchedFieldNames);\n }, 1);\n }\n\n // Cleanup on unmount or when dependencies change\n return () => {\n setClientValidationSchema(key, null);\n };\n // Only re-run when data (dataHash) or key changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [dataHash, key]);\n};\n\n/**\n * Helper function to create a veto looseObject schema for a single field with nested path support.\n *\n * Parses field paths (dot-notation) and creates properly nested loose object schemas with array support.\n * All intermediate objects and arrays are marked as optional to allow partial data structures.\n * Numeric segments in the path are treated as array indices, and the parent field is wrapped in an array schema.\n * Supports flat arrays (arrays of primitives) via the special `__FLAT__` key.\n *\n * **Important:** The fieldSchema should typically use `.nullish()` to allow empty values. This is because:\n * - Base validation (passed to Form) handles \"required\" constraints\n * - Client validation adds dynamic, context-dependent rules (e.g., \"username already exists\")\n * - Form data processing converts empty strings in flat arrays to `null` (not `undefined`)\n * - `.nullish()` accepts both `null` and `undefined`, while `.optional()` only accepts `undefined`\n *\n * This pattern ensures client validation only validates non-empty values, while base validation\n * enforces required fields and basic constraints (min length, format, etc.).\n *\n * @param name - The dot-separated path to the field (e.g., 'username', 'user.profile.email', 'items.0.name', 'tags.0.__FLAT__')\n * @param fieldSchema - The veto validation schema for the field. Should typically use `.nullish()` to allow empty values.\n * @returns A nested loose object schema matching the field path structure with proper type inference\n *\n * @example\n * ```tsx\n * // Typical usage: base validation handles \"required\", client validation adds dynamic rules\n * // Base validation (in Form component)\n * const baseSchema = veto({ username: vt.string({ min: 3 }) }); // Required + min length\n *\n * // Client validation (dynamic check for existing usernames)\n * const { data: userData } = useUserQuery(userId);\n * useClientValidation(userData, (data) =>\n * clientValidationSchemaByName(\n * 'username',\n * vt.string()\n * .refine(\n * (value) => !data.existingUsernames.includes(value),\n * { message: 'Username already taken' }\n * )\n * .nullish() // Allow empty - base validation handles \"required\"\n * )\n * );\n * ```\n *\n * @example\n * ```tsx\n * // Nested field path with dynamic validation\n * clientValidationSchemaByName(\n * 'user.profile.email',\n * vt.string()\n * .refine(\n * (value) => !reservedEmails.includes(value),\n * { message: 'This email is reserved' }\n * )\n * .nullish()\n * )\n * // => objectLoose({ user: objectLoose({ profile: objectLoose({ email: ... }).optional() }).optional() })\n * ```\n *\n * @example\n * ```tsx\n * // Array of objects with dynamic validation\n * clientValidationSchemaByName(\n * 'items.0.tag',\n * vt.string()\n * .refine((value) => !forbiddenTags.includes(value), { message: 'Tag not allowed' })\n * .nullish()\n * )\n * // => objectLoose({ items: array(objectLoose({ tag: ... })).optional() })\n * ```\n *\n * @example\n * ```tsx\n * // Flat array (array of primitives) with dynamic validation\n * clientValidationSchemaByName(\n * 'tags.0.__FLAT__',\n * vt.string()\n * .refine((value) => !forbiddenWords.includes(value), { message: 'Word not allowed' })\n * .nullish()\n * )\n * // => objectLoose({ tags: array(vt.string().refine(...).nullish()).optional() })\n * ```\n */\nexport const clientValidationSchemaByName = <T extends VetoTypeAny>(\n name: string,\n fieldSchema: T,\n) => {\n const segments = name.split('.');\n\n // Build schema from innermost to outermost\n let schema: VetoTypeAny = fieldSchema;\n\n // Process segments in reverse order to build nested structure\n for (let i = segments.length - 1; i >= 0; i -= 1) {\n const segment = segments[i];\n\n const isNumeric = /^\\d+$/.test(segment);\n const isFlatArrayKey = segment === flatArrayKey;\n\n if (isFlatArrayKey) {\n // Skip the __FLAT__ key - it's just a marker for flat arrays\n // The schema is already correct (primitive type), just continue\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (isNumeric) {\n // Current segment is an array index - wrap current schema in optional array\n schema = array(schema).optional();\n } else {\n // Current segment is a field name - wrap in objectLoose\n // Make it optional if it's an intermediate object (not the root)\n const obj = objectLoose({\n [segment]: schema,\n });\n schema = i > 0 ? obj.optional() : obj;\n }\n }\n\n return schema;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,MAAa,uBACX,MACA,eACA,YACS;CACT,MAAM,EACJ,WAAW,EAAE,iBACb,YAAY,EAAE,6BACd,YACE,eAAe;CAGnB,MAAM,mBAAmB,MAAM;CAC/B,MAAM,MAAM,SAAS,OAAO;CAO5B,gBAAgB;EAEd,IAAI,QAAQ,MAEV,0BAA0B,KADD,cAAc,IACO,CAAC;OAG/C,0BAA0B,KAAK,IAAI;EAIrC,MAAM,oBAAoB,OAAO,KAAK,aAAa;EACnD,IAAI,kBAAkB,SAAS,GAG7B,WAAW,YAAY;GACrB,OAAO,QAAQ,iBAAiB;EAClC,GAAG,CAAC;EAIN,aAAa;GACX,0BAA0B,KAAK,IAAI;EACrC;CAGF,GAAG,CA7Bc,KAAK,UAAU,IA6BrB,GAAG,GAAG,CAAC;AACpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,MAAa,gCACX,MACA,gBACG;CACH,MAAM,WAAW,KAAK,MAAM,GAAG;CAG/B,IAAI,SAAsB;CAG1B,KAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;EAChD,MAAM,UAAU,SAAS;EAEzB,MAAM,YAAY,QAAQ,KAAK,OAAO;EAGtC,IAFuB,YAAA,YAMrB;EAGF,IAAI,WAEF,SAAS,MAAM,MAAM,EAAE,SAAS;OAC3B;GAGL,MAAM,MAAM,YAAY,GACrB,UAAU,OACb,CAAC;GACD,SAAS,IAAI,IAAI,IAAI,SAAS,IAAI;EACpC;CACF;CAEA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"useClientValidation-DpLdzIAb.js","names":[],"sources":["../src/hooks/useClientValidation/useClientValidation.ts"],"sourcesContent":["import type { VetoTypeAny } from '@fuf-stack/veto';\n\nimport { useEffect, useId } from 'react';\n\nimport { array, objectLoose } from '@fuf-stack/veto';\n\nimport { flatArrayKey } from '../../helpers';\nimport { useFormContext } from '../useFormContext/useFormContext';\n\n/**\n * Hook for adding dynamic client-side validation to forms.\n *\n * Client validation is used for context-dependent validation rules that require external data\n * (e.g., checking if a username already exists). It complements base validation (passed to Form),\n * which handles static rules like \"required\", min/max length, format, etc.\n *\n * **Typical pattern:**\n * - Base validation: Static, always-on rules (required, format, length constraints)\n * - Client validation: Dynamic rules based on external data (uniqueness, business logic)\n * - Client schemas should use `.nullish()` to allow empty values (base validation handles \"required\")\n *\n * Automatically manages validation schema lifecycle: sets schema when data is provided,\n * clears schema when data is null/undefined, and cleans up on unmount. When the client\n * validation schema changes, automatically re-validates all touched fields.\n *\n * @param data - Data to create validation schema from (or null/undefined to clear validation)\n * @param schemaFactory - Function that creates a validation schema from the data. Schemas should typically use `.nullish()`.\n * @param options - Optional configuration object\n * @param options.key - Optional custom key for registration. Useful when multiple instances should share validation (e.g., in field arrays)\n *\n * @example\n * ```tsx\n * // Base validation handles \"required\" and format\n * const baseSchema = veto({ username: vt.string({ min: 3 }) });\n *\n * // Client validation adds dynamic uniqueness check\n * const { data: teamData } = useTeamQuery(teamId);\n * useClientValidation(teamData, (data) =>\n * vt.objectLoose({\n * username: vt.string()\n * .refine(\n * (value) => !data.existingUsers.includes(value),\n * { message: 'Username already exists' }\n * )\n * .nullish() // Allow empty - base validation handles \"required\"\n * })\n * );\n * ```\n *\n * @example\n * ```tsx\n * // Using custom key in a field array to avoid multiple registrations\n * fields.map((field, index) => (\n * useClientValidation(\n * userData,\n * (data) => clientValidationSchemaByName(\n * `items.${index}.name`,\n * vt.string()\n * .refine((val) => !data.forbidden.includes(val), { message: 'Name not allowed' })\n * .nullish()\n * ),\n * { key: 'items-validation' } // All instances share the same key\n * )\n * ));\n * ```\n */\nexport const useClientValidation = <TData = unknown>(\n data: TData | null | undefined,\n schemaFactory: (data: TData) => VetoTypeAny,\n options?: { key?: string },\n): void => {\n const {\n formState: { touchedFields },\n validation: { setClientValidationSchema },\n trigger,\n } = useFormContext();\n\n // Use provided key or auto-generate unique key\n const autoGeneratedKey = useId();\n const key = options?.key ?? autoGeneratedKey;\n\n // Use data hash instead of object reference to avoid unnecessary re-runs\n // when data object reference changes but data remains the same\n const dataHash = JSON.stringify(data);\n\n // Single effect to manage validation schema lifecycle\n useEffect(() => {\n // Set validation schema when data is available\n if (data != null) {\n const validationSchema = schemaFactory(data);\n setClientValidationSchema(key, validationSchema);\n } else {\n // Clear validation schema when no data\n setClientValidationSchema(key, null);\n }\n\n // Re-validate all touched fields when client validation schema changes\n const touchedFieldNames = Object.keys(touchedFields);\n if (touchedFieldNames.length > 0) {\n // Use setTimeout to ensure the client validation schema update has propagated\n // before triggering re-validation (fixes race condition)\n setTimeout(async () => {\n return trigger(touchedFieldNames);\n }, 1);\n }\n\n // Cleanup on unmount or when dependencies change\n return () => {\n setClientValidationSchema(key, null);\n };\n // Only re-run when data (dataHash) or key changes\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [dataHash, key]);\n};\n\n/**\n * Helper function to create a veto looseObject schema for a single field with nested path support.\n *\n * Parses field paths (dot-notation) and creates properly nested loose object schemas with array support.\n * All intermediate objects and arrays are marked as optional to allow partial data structures.\n * Numeric segments in the path are treated as array indices, and the parent field is wrapped in an array schema.\n * Supports flat arrays (arrays of primitives) via the special `__FLAT__` key.\n *\n * **Important:** The fieldSchema should typically use `.nullish()` to allow empty values. This is because:\n * - Base validation (passed to Form) handles \"required\" constraints\n * - Client validation adds dynamic, context-dependent rules (e.g., \"username already exists\")\n * - Form data processing converts empty strings in flat arrays to `null` (not `undefined`)\n * - `.nullish()` accepts both `null` and `undefined`, while `.optional()` only accepts `undefined`\n *\n * This pattern ensures client validation only validates non-empty values, while base validation\n * enforces required fields and basic constraints (min length, format, etc.).\n *\n * @param name - The dot-separated path to the field (e.g., 'username', 'user.profile.email', 'items.0.name', 'tags.0.__FLAT__')\n * @param fieldSchema - The veto validation schema for the field. Should typically use `.nullish()` to allow empty values.\n * @returns A nested loose object schema matching the field path structure with proper type inference\n *\n * @example\n * ```tsx\n * // Typical usage: base validation handles \"required\", client validation adds dynamic rules\n * // Base validation (in Form component)\n * const baseSchema = veto({ username: vt.string({ min: 3 }) }); // Required + min length\n *\n * // Client validation (dynamic check for existing usernames)\n * const { data: userData } = useUserQuery(userId);\n * useClientValidation(userData, (data) =>\n * clientValidationSchemaByName(\n * 'username',\n * vt.string()\n * .refine(\n * (value) => !data.existingUsernames.includes(value),\n * { message: 'Username already taken' }\n * )\n * .nullish() // Allow empty - base validation handles \"required\"\n * )\n * );\n * ```\n *\n * @example\n * ```tsx\n * // Nested field path with dynamic validation\n * clientValidationSchemaByName(\n * 'user.profile.email',\n * vt.string()\n * .refine(\n * (value) => !reservedEmails.includes(value),\n * { message: 'This email is reserved' }\n * )\n * .nullish()\n * )\n * // => objectLoose({ user: objectLoose({ profile: objectLoose({ email: ... }).optional() }).optional() })\n * ```\n *\n * @example\n * ```tsx\n * // Array of objects with dynamic validation\n * clientValidationSchemaByName(\n * 'items.0.tag',\n * vt.string()\n * .refine((value) => !forbiddenTags.includes(value), { message: 'Tag not allowed' })\n * .nullish()\n * )\n * // => objectLoose({ items: array(objectLoose({ tag: ... })).optional() })\n * ```\n *\n * @example\n * ```tsx\n * // Flat array (array of primitives) with dynamic validation\n * clientValidationSchemaByName(\n * 'tags.0.__FLAT__',\n * vt.string()\n * .refine((value) => !forbiddenWords.includes(value), { message: 'Word not allowed' })\n * .nullish()\n * )\n * // => objectLoose({ tags: array(vt.string().refine(...).nullish()).optional() })\n * ```\n */\nexport const clientValidationSchemaByName = <T extends VetoTypeAny>(\n name: string,\n fieldSchema: T,\n) => {\n const segments = name.split('.');\n\n // Build schema from innermost to outermost\n let schema: VetoTypeAny = fieldSchema;\n\n // Process segments in reverse order to build nested structure\n for (let i = segments.length - 1; i >= 0; i -= 1) {\n const segment = segments[i];\n\n const isNumeric = /^\\d+$/.test(segment);\n const isFlatArrayKey = segment === flatArrayKey;\n\n if (isFlatArrayKey) {\n // Skip the __FLAT__ key - it's just a marker for flat arrays\n // The schema is already correct (primitive type), just continue\n // eslint-disable-next-line no-continue\n continue;\n }\n\n if (isNumeric) {\n // Current segment is an array index - wrap current schema in optional array\n schema = array(schema).optional();\n } else {\n // Current segment is a field name - wrap in objectLoose\n // Make it optional if it's an intermediate object (not the root)\n const obj = objectLoose({\n [segment]: schema,\n });\n schema = i > 0 ? obj.optional() : obj;\n }\n }\n\n return schema;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkEA,MAAa,uBACX,MACA,eACA,YACS;CACT,MAAM,EACJ,WAAW,EAAE,iBACb,YAAY,EAAE,6BACd,YACE,eAAe;CAGnB,MAAM,mBAAmB,MAAM;CAC/B,MAAM,MAAM,SAAS,OAAO;CAO5B,gBAAgB;EAEd,IAAI,QAAQ,MAEV,0BAA0B,KADD,cAAc,IACO,CAAC;OAG/C,0BAA0B,KAAK,IAAI;EAIrC,MAAM,oBAAoB,OAAO,KAAK,aAAa;EACnD,IAAI,kBAAkB,SAAS,GAG7B,WAAW,YAAY;GACrB,OAAO,QAAQ,iBAAiB;EAClC,GAAG,CAAC;EAIN,aAAa;GACX,0BAA0B,KAAK,IAAI;EACrC;CAGF,GAAG,CA7Bc,KAAK,UAAU,IA6BrB,GAAG,GAAG,CAAC;AACpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmFA,MAAa,gCACX,MACA,gBACG;CACH,MAAM,WAAW,KAAK,MAAM,GAAG;CAG/B,IAAI,SAAsB;CAG1B,KAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,KAAK,GAAG;EAChD,MAAM,UAAU,SAAS;EAEzB,MAAM,YAAY,QAAQ,KAAK,OAAO;EAGtC,IAFuB,YAAA,YAMrB;EAGF,IAAI,WAEF,SAAS,MAAM,MAAM,EAAE,SAAS;OAC3B;GAGL,MAAM,MAAM,YAAY,GACrB,UAAU,OACb,CAAC;GACD,SAAS,IAAI,IAAI,IAAI,SAAS,IAAI;EACpC;CACF;CAEA,OAAO;AACT"}
|
|
@@ -145,4 +145,4 @@ declare const useClientValidation: <TData = unknown>(data: TData | null | undefi
|
|
|
145
145
|
declare const clientValidationSchemaByName: <T extends VetoTypeAny>(name: string, fieldSchema: T) => VetoTypeAny;
|
|
146
146
|
//#endregion
|
|
147
147
|
export { useClientValidation as n, clientValidationSchemaByName as t };
|
|
148
|
-
//# sourceMappingURL=useClientValidation-
|
|
148
|
+
//# sourceMappingURL=useClientValidation-qRq2_spX.d.ts.map
|
package/dist/{useClientValidation-BkIsMCEl.d.ts.map → useClientValidation-qRq2_spX.d.ts.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClientValidation-
|
|
1
|
+
{"version":3,"file":"useClientValidation-qRq2_spX.d.ts","names":[],"sources":["../src/hooks/useClientValidation/useClientValidation.ts"],"mappings":";;;;;AAkEA;;;;;;;;;;;;;;;;;;AAG4B;AA+H5B;;;;;;;;;;;;;;;AAqCC;;;;;;;;;;;;;;;;;;;;;cAvKY,mBAAA,oBACX,IAAA,EAAM,KAAA,qBACN,aAAA,GAAgB,IAAA,EAAM,KAAA,KAAU,WAAA,EAChC,OAAA;EAAY,GAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+HD,4BAAA,aAA0C,WAAA,EACrD,IAAA,UACA,WAAA,EAAa,CAAA,KAAC,WAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_FormContext = require("./FormContext-
|
|
1
|
+
const require_FormContext = require("./FormContext-DsmS_mkO.cjs");
|
|
2
2
|
const require_helpers_index = require("./helpers/index.cjs");
|
|
3
3
|
let react = require("react");
|
|
4
4
|
let react_hook_form = require("react-hook-form");
|
|
@@ -47,4 +47,4 @@ Object.defineProperty(exports, "useController", {
|
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
-
//# sourceMappingURL=useController
|
|
50
|
+
//# sourceMappingURL=useController--lRPWBuD.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useController
|
|
1
|
+
{"version":3,"file":"useController--lRPWBuD.cjs","names":["UniformContext","toNullishString","fromNullishString"],"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,MAAa,iBACX,UACsC;CACtC,MAAM,EAAE,OAAO,WAAW,gBAAA,GAAA,gBAAA,eAAgC,KAAK;CAC/D,MAAM,EAAE,gBAAA,GAAA,MAAA,YAA0BA,oBAAAA,cAAc;CAEhD,OAAO;EACL,OAAO;GACL,GAAG;GAGH,WAAW,GAAG,UAAiB;IAC7B,MAAM,QAAQ,MAAM,IAAI,QAAQ,SAAS,MAAM;IAC/C,MAAM,iBAAiB,UAAU,KAAK,KAAKC,sBAAAA,gBAAgB,KAAK;IAKhE,IAAI,mBAAmB,MAAM,OAC3B;IAIF,MAAM,SAAS,cAAc;IAQ7B,YAAY,OAAO,MAAM,MAAM,KAAK;GACtC;GAEA,OAAOC,sBAAAA,kBAAkB,MAAM,KAAK;EACtC;EACA;EACA;CACF;AACF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { fromNullishString, toNullishString } from "./helpers/index.js";
|
|
2
|
-
import { n as UniformContext } from "./FormContext-
|
|
2
|
+
import { n as UniformContext } from "./FormContext-BQeKOV-0.js";
|
|
3
3
|
import { useContext } from "react";
|
|
4
4
|
import { useController } from "react-hook-form";
|
|
5
5
|
//#region src/hooks/useController/useController.ts
|
|
@@ -42,4 +42,4 @@ const useController$1 = (props) => {
|
|
|
42
42
|
//#endregion
|
|
43
43
|
export { useController$1 as t };
|
|
44
44
|
|
|
45
|
-
//# sourceMappingURL=useController-
|
|
45
|
+
//# sourceMappingURL=useController-B287flU_.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useController-
|
|
1
|
+
{"version":3,"file":"useController-B287flU_.js","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,IAAI,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"}
|
|
@@ -30,4 +30,4 @@ interface UseControllerReturn<TFieldValues extends object = object> {
|
|
|
30
30
|
declare const useController: <TFieldValues extends object = object>(props: UseControllerProps$1<TFieldValues>) => UseControllerReturn<TFieldValues>;
|
|
31
31
|
//#endregion
|
|
32
32
|
export { UseControllerReturn as n, useController as r, UseControllerProps$1 as t };
|
|
33
|
-
//# sourceMappingURL=useController-
|
|
33
|
+
//# sourceMappingURL=useController-BT3Fd0IO.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useController-
|
|
1
|
+
{"version":3,"file":"useController-BT3Fd0IO.d.cts","names":[],"sources":["../src/hooks/useController/useController.ts"],"mappings":";;;KAaY,oBAAA,yCACV,kBAAqB,CAAC,YAAA;AAAA,UAEP,mBAAA;EACf,KAAA,EAAO,IAAA,CAAK,qBAAA,CAAsB,YAAA;IAGhC,QAAA,MAAc,KAAA;IACd,KAAA;EAAA;EAEF,SAAA,EAAW,kBAAA,CAAmB,YAAA;EAC9B,UAAA,EAAY,oBAAA;AAAA;;AAVsB;AAEpC;;;;;;;;;;;;;;;cA4Ba,aAAA,yCACX,KAAA,EAAO,oBAAA,CAAmB,YAAA,MACzB,mBAAA,CAAoB,YAAA"}
|
|
@@ -30,4 +30,4 @@ interface UseControllerReturn<TFieldValues extends object = object> {
|
|
|
30
30
|
declare const useController$1: <TFieldValues extends object = object>(props: UseControllerProps$1<TFieldValues>) => UseControllerReturn<TFieldValues>;
|
|
31
31
|
//#endregion
|
|
32
32
|
export { UseControllerReturn as n, useController$1 as r, UseControllerProps$1 as t };
|
|
33
|
-
//# sourceMappingURL=useController-
|
|
33
|
+
//# sourceMappingURL=useController-CzP0aVFC.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useController-
|
|
1
|
+
{"version":3,"file":"useController-CzP0aVFC.d.ts","names":[],"sources":["../src/hooks/useController/useController.ts"],"mappings":";;;KAaY,oBAAA,yCACV,kBAAqB,CAAC,YAAA;AAAA,UAEP,mBAAA;EACf,KAAA,EAAO,IAAA,CAAK,qBAAA,CAAsB,YAAA;IAGhC,QAAA,MAAc,KAAA;IACd,KAAA;EAAA;EAEF,SAAA,EAAW,kBAAA,CAAmB,YAAA;EAC9B,UAAA,EAAY,oBAAA;AAAA;;AAVsB;AAEpC;;;;;;;;;;;;;;;cA4Ba,eAAA,yCACX,KAAA,EAAO,oBAAA,CAAmB,YAAA,MACzB,mBAAA,CAAoB,YAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as UserChangeListener, t as DebugModeSettings } from "./FormContext-
|
|
1
|
+
import { n as FormResetListener, r as UserChangeListener, t as DebugModeSettings } from "./FormContext-i66vM5f1.js";
|
|
2
2
|
import { FieldError, FieldValues, Path } from "react-hook-form";
|
|
3
3
|
import { VetoFormattedError, VetoInstance } from "@fuf-stack/veto";
|
|
4
4
|
|
|
@@ -27,10 +27,15 @@ declare const useFormContext$1: <TFieldValues extends FieldValues = FieldValues,
|
|
|
27
27
|
isValidating: boolean;
|
|
28
28
|
};
|
|
29
29
|
getValues: import("react-hook-form").UseFormGetValues<TFieldValues>;
|
|
30
|
+
reset: import("react-hook-form").UseFormReset<TFieldValues>;
|
|
30
31
|
subscribe: import("react-hook-form").UseFormSubscribe<TFieldValues>;
|
|
31
32
|
watch: import("react-hook-form").UseFormWatch<TFieldValues>;
|
|
32
33
|
debugMode: "disabled" | "debug" | "debug-testids" | "off";
|
|
33
34
|
debugModeSettings?: DebugModeSettings;
|
|
35
|
+
formReset: {
|
|
36
|
+
subscribe: (listener: FormResetListener) => () => void;
|
|
37
|
+
notify: () => void;
|
|
38
|
+
};
|
|
34
39
|
preventSubmit: (prevent: boolean) => void;
|
|
35
40
|
setDebugMode: (debugMode: "disabled" | "debug" | "debug-testids" | "off") => void;
|
|
36
41
|
triggerSubmit: (e?: import("react").BaseSyntheticEvent) => Promise<void> | void;
|
|
@@ -50,7 +55,6 @@ declare const useFormContext$1: <TFieldValues extends FieldValues = FieldValues,
|
|
|
50
55
|
setValues: import("react-hook-form").UseFormSetValues<TFieldValues>;
|
|
51
56
|
trigger: import("react-hook-form").UseFormTrigger<TFieldValues>;
|
|
52
57
|
resetField: import("react-hook-form").UseFormResetField<TFieldValues>;
|
|
53
|
-
reset: import("react-hook-form").UseFormReset<TFieldValues>;
|
|
54
58
|
handleSubmit: import("react-hook-form").UseFormHandleSubmit<TFieldValues, TTransformedValues>;
|
|
55
59
|
unregister: import("react-hook-form").UseFormUnregister<TFieldValues>;
|
|
56
60
|
control: import("react-hook-form").Control<TFieldValues, TContext, TTransformedValues>;
|
|
@@ -59,4 +63,4 @@ declare const useFormContext$1: <TFieldValues extends FieldValues = FieldValues,
|
|
|
59
63
|
};
|
|
60
64
|
//#endregion
|
|
61
65
|
export { useFormContext$1 as n, checkFieldIsRequired as t };
|
|
62
|
-
//# sourceMappingURL=useFormContext-
|
|
66
|
+
//# sourceMappingURL=useFormContext-Bj1gXLt_.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormContext-Bj1gXLt_.d.ts","names":[],"sources":["../src/hooks/useFormContext/useFormContext.ts"],"mappings":";;;;;;cAYa,oBAAA,GACX,UAAA,EAAY,YAAY,EACxB,IAAA;;AAFF;;;;;;;;AAEgB;cAmEH,gBAAA,wBACU,WAAA,GAAc,WAAA,uCAEd,YAAA;;wBAoCQ,IAAA,CAAK,YAAA,GAAa,MAAA;;;;;;;;;;;;;;;;;;;;;sCAwB3C,kBAAA,KAAA,OAAA;;0BAAA,kBAAA;;;;mBAiBa,YAAA;eAEE,YAAA;aAC6B,kBAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { flatArrayKey, nameToTestId, toValidationFormat } from "./helpers/index.js";
|
|
2
|
-
import { n as UniformContext } from "./FormContext-
|
|
2
|
+
import { n as UniformContext } from "./FormContext-BQeKOV-0.js";
|
|
3
3
|
import { useContext } from "react";
|
|
4
4
|
import { useFormContext } from "react-hook-form";
|
|
5
5
|
//#region src/hooks/useFormContext/useFormContext.ts
|
|
@@ -49,9 +49,19 @@ const getValidationErrorsByName = (errors, name) => {
|
|
|
49
49
|
* - Filters out empty/null values
|
|
50
50
|
*/
|
|
51
51
|
const useFormContext$1 = () => {
|
|
52
|
-
const { formState, getFieldState: getFieldStateOrig, getValues: getValuesOrig, watch: watchOrig, subscribe: subscribeOrig, ...otherMethods } = useFormContext();
|
|
52
|
+
const { formState, getFieldState: getFieldStateOrig, getValues: getValuesOrig, watch: watchOrig, subscribe: subscribeOrig, reset: resetOrig, ...otherMethods } = useFormContext();
|
|
53
53
|
const uniformContext = useContext(UniformContext);
|
|
54
54
|
/**
|
|
55
|
+
* Wrap react-hook-form's `reset` so the uniform context is notified about
|
|
56
|
+
* programmatic resets. Field components (e.g. FieldArray) use this signal to
|
|
57
|
+
* normalize their state on reset instead of inferring it from field contents.
|
|
58
|
+
*/
|
|
59
|
+
const notifyReset = uniformContext?.formReset?.notify;
|
|
60
|
+
const reset = ((...args) => {
|
|
61
|
+
resetOrig(...args);
|
|
62
|
+
notifyReset?.();
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
55
65
|
* Updated getFieldState method which returns:
|
|
56
66
|
* - Whether the field is required by checking the validation schema
|
|
57
67
|
* - Existing field state information (errors, etc.)
|
|
@@ -112,6 +122,7 @@ const useFormContext$1 = () => {
|
|
|
112
122
|
formState,
|
|
113
123
|
getFieldState,
|
|
114
124
|
getValues,
|
|
125
|
+
reset,
|
|
115
126
|
subscribe,
|
|
116
127
|
watch
|
|
117
128
|
};
|
|
@@ -119,4 +130,4 @@ const useFormContext$1 = () => {
|
|
|
119
130
|
//#endregion
|
|
120
131
|
export { useFormContext$1 as n, checkFieldIsRequired as t };
|
|
121
132
|
|
|
122
|
-
//# sourceMappingURL=useFormContext-
|
|
133
|
+
//# sourceMappingURL=useFormContext-CT8H8xIe.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormContext-CT8H8xIe.js","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 { FieldError, FieldValues, Path } 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/**\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>() => {\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 = (name: Path<TFieldValues>, testId?: string) => {\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":";;;;;;AAYA,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,EAAE,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;;;;;;;;;;;AAYA,MAAaA,yBAIN;CACL,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,iBAAiB,MAA0B,WAAoB;EACnE,MAAM,YACJ,OAAO,SAAS,WAAW,KAAK,QAAQ,YAAY,EAAE,EAAE,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;EAErC,OAAO,mBADS,cAAsB,GAAG,IACV,CAAC;CAClC;CAEA,MAAM,UAAU,GAAG,SAAgB;EAEjC,OAAO,mBADS,UAAkB,GAAG,IACN,CAAC;CAClC;CAEA,MAAM,cAAc,GAAG,SAAgB;EAErC,MAAM,CAAC,WAAW;EAClB,IAAI,SAAS,UAAU;GACrB,MAAM,mBAAmB,QAAQ;GAejC,OAAO,cAAc;IAbnB,GAAG;IACH,WAAW,uBAA4B;KASrC,OAAO,iBAAiB;MANtB,GAAG;MACH,GAAI,mBAAmB,UAAU,EAC/B,QAAQ,mBAAmB,mBAAmB,MAAM,EACtD;KAGuC,CAAC;IAC5C;GAEgC,CAAC;EACrC;EAEA,OAAQ,cAAsB,GAAG,IAAI;CACvC;CAEA,OAAO;EACL,GAAG;EACH,GAAG;EACH;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_FormContext = require("./FormContext-
|
|
1
|
+
const require_FormContext = require("./FormContext-DsmS_mkO.cjs");
|
|
2
2
|
const require_helpers_index = require("./helpers/index.cjs");
|
|
3
3
|
let react = require("react");
|
|
4
4
|
let react_hook_form = require("react-hook-form");
|
|
@@ -49,9 +49,19 @@ const getValidationErrorsByName = (errors, name) => {
|
|
|
49
49
|
* - Filters out empty/null values
|
|
50
50
|
*/
|
|
51
51
|
const useFormContext = () => {
|
|
52
|
-
const { formState, getFieldState: getFieldStateOrig, getValues: getValuesOrig, watch: watchOrig, subscribe: subscribeOrig, ...otherMethods } = (0, react_hook_form.useFormContext)();
|
|
52
|
+
const { formState, getFieldState: getFieldStateOrig, getValues: getValuesOrig, watch: watchOrig, subscribe: subscribeOrig, reset: resetOrig, ...otherMethods } = (0, react_hook_form.useFormContext)();
|
|
53
53
|
const uniformContext = (0, react.useContext)(require_FormContext.UniformContext);
|
|
54
54
|
/**
|
|
55
|
+
* Wrap react-hook-form's `reset` so the uniform context is notified about
|
|
56
|
+
* programmatic resets. Field components (e.g. FieldArray) use this signal to
|
|
57
|
+
* normalize their state on reset instead of inferring it from field contents.
|
|
58
|
+
*/
|
|
59
|
+
const notifyReset = uniformContext?.formReset?.notify;
|
|
60
|
+
const reset = ((...args) => {
|
|
61
|
+
resetOrig(...args);
|
|
62
|
+
notifyReset?.();
|
|
63
|
+
});
|
|
64
|
+
/**
|
|
55
65
|
* Updated getFieldState method which returns:
|
|
56
66
|
* - Whether the field is required by checking the validation schema
|
|
57
67
|
* - Existing field state information (errors, etc.)
|
|
@@ -112,6 +122,7 @@ const useFormContext = () => {
|
|
|
112
122
|
formState,
|
|
113
123
|
getFieldState,
|
|
114
124
|
getValues,
|
|
125
|
+
reset,
|
|
115
126
|
subscribe,
|
|
116
127
|
watch
|
|
117
128
|
};
|
|
@@ -130,4 +141,4 @@ Object.defineProperty(exports, "useFormContext", {
|
|
|
130
141
|
}
|
|
131
142
|
});
|
|
132
143
|
|
|
133
|
-
//# sourceMappingURL=useFormContext-
|
|
144
|
+
//# sourceMappingURL=useFormContext-CrXwNYiB.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormContext-CrXwNYiB.cjs","names":["flatArrayKey","UniformContext","nameToTestId","toValidationFormat"],"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 { FieldError, FieldValues, Path } 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/**\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>() => {\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 = (name: Path<TFieldValues>, testId?: string) => {\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":";;;;;;AAYA,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,EAAE,QAAQ,MAAM;EACzC,OAAO,MAAMA,sBAAAA;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;;;;;;;;;;;AAYA,MAAa,uBAIN;CACL,MAAM,EACJ,WAEA,eAAe,mBACf,WAAW,eACX,OAAO,WACP,WAAW,eACX,OAAO,WAEP,GAAG,kBAAA,GAAA,gBAAA,gBAC8D;CAEnE,MAAM,kBAAA,GAAA,MAAA,YAA4BC,oBAAAA,cAAc;;;;;;CAOhD,MAAM,cAAc,gBAAgB,WAAW;CAC/C,MAAM,UAAU,GAAG,SAAuC;EACxD,UAAU,GAAG,IAAI;EACjB,cAAc;CAChB;;;;;;;;;;CAWA,MAAM,iBAAiB,MAA0B,WAAoB;EACnE,MAAM,YACJ,OAAO,SAAS,WAAW,KAAK,QAAQ,YAAY,EAAE,EAAE,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,QAAQC,sBAAAA,aAAa,UAAU,IAAI;EACrC;CACF;;;;;;;;;;;;CAaA,MAAM,cAAc,GAAG,SAAgB;EAErC,OAAOC,sBAAAA,mBADS,cAAsB,GAAG,IACV,CAAC;CAClC;CAEA,MAAM,UAAU,GAAG,SAAgB;EAEjC,OAAOA,sBAAAA,mBADS,UAAkB,GAAG,IACN,CAAC;CAClC;CAEA,MAAM,cAAc,GAAG,SAAgB;EAErC,MAAM,CAAC,WAAW;EAClB,IAAI,SAAS,UAAU;GACrB,MAAM,mBAAmB,QAAQ;GAejC,OAAO,cAAc;IAbnB,GAAG;IACH,WAAW,uBAA4B;KASrC,OAAO,iBAAiB;MANtB,GAAG;MACH,GAAI,mBAAmB,UAAU,EAC/B,QAAQA,sBAAAA,mBAAmB,mBAAmB,MAAM,EACtD;KAGuC,CAAC;IAC5C;GAEgC,CAAC;EACrC;EAEA,OAAQ,cAAsB,GAAG,IAAI;CACvC;CAEA,OAAO;EACL,GAAG;EACH,GAAG;EACH;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as UserChangeListener, t as DebugModeSettings } from "./FormContext-
|
|
1
|
+
import { n as FormResetListener, r as UserChangeListener, t as DebugModeSettings } from "./FormContext-3kamRn2C.cjs";
|
|
2
2
|
import { VetoFormattedError, VetoInstance } from "@fuf-stack/veto";
|
|
3
3
|
import { FieldError, FieldValues, Path } from "react-hook-form";
|
|
4
4
|
|
|
@@ -27,10 +27,15 @@ declare const useFormContext: <TFieldValues extends FieldValues = FieldValues, T
|
|
|
27
27
|
isValidating: boolean;
|
|
28
28
|
};
|
|
29
29
|
getValues: import("react-hook-form").UseFormGetValues<TFieldValues>;
|
|
30
|
+
reset: import("react-hook-form").UseFormReset<TFieldValues>;
|
|
30
31
|
subscribe: import("react-hook-form").UseFormSubscribe<TFieldValues>;
|
|
31
32
|
watch: import("react-hook-form").UseFormWatch<TFieldValues>;
|
|
32
33
|
debugMode: "disabled" | "debug" | "debug-testids" | "off";
|
|
33
34
|
debugModeSettings?: DebugModeSettings;
|
|
35
|
+
formReset: {
|
|
36
|
+
subscribe: (listener: FormResetListener) => () => void;
|
|
37
|
+
notify: () => void;
|
|
38
|
+
};
|
|
34
39
|
preventSubmit: (prevent: boolean) => void;
|
|
35
40
|
setDebugMode: (debugMode: "disabled" | "debug" | "debug-testids" | "off") => void;
|
|
36
41
|
triggerSubmit: (e?: import("react").BaseSyntheticEvent) => Promise<void> | void;
|
|
@@ -50,7 +55,6 @@ declare const useFormContext: <TFieldValues extends FieldValues = FieldValues, T
|
|
|
50
55
|
setValues: import("react-hook-form").UseFormSetValues<TFieldValues>;
|
|
51
56
|
trigger: import("react-hook-form").UseFormTrigger<TFieldValues>;
|
|
52
57
|
resetField: import("react-hook-form").UseFormResetField<TFieldValues>;
|
|
53
|
-
reset: import("react-hook-form").UseFormReset<TFieldValues>;
|
|
54
58
|
handleSubmit: import("react-hook-form").UseFormHandleSubmit<TFieldValues, TTransformedValues>;
|
|
55
59
|
unregister: import("react-hook-form").UseFormUnregister<TFieldValues>;
|
|
56
60
|
control: import("react-hook-form").Control<TFieldValues, TContext, TTransformedValues>;
|
|
@@ -59,4 +63,4 @@ declare const useFormContext: <TFieldValues extends FieldValues = FieldValues, T
|
|
|
59
63
|
};
|
|
60
64
|
//#endregion
|
|
61
65
|
export { useFormContext as n, checkFieldIsRequired as t };
|
|
62
|
-
//# sourceMappingURL=useFormContext-
|
|
66
|
+
//# sourceMappingURL=useFormContext-M94eQfHm.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormContext-M94eQfHm.d.cts","names":[],"sources":["../src/hooks/useFormContext/useFormContext.ts"],"mappings":";;;;;;cAYa,oBAAA,GACX,UAAA,EAAY,YAAY,EACxB,IAAA;;AAFF;;;;;;;;AAEgB;cAmEH,cAAA,wBACU,WAAA,GAAc,WAAA,uCAEd,YAAA;;wBAoCQ,IAAA,CAAK,YAAA,GAAa,MAAA;;;;;;;;;;;;;;;;;;;;;sCAwB3C,kBAAA,KAAA,OAAA;;0BAAA,kBAAA;;;;mBAiBa,YAAA;eAEE,YAAA;aAC6B,kBAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require("./FormContext-
|
|
1
|
+
require("./FormContext-DsmS_mkO.cjs");
|
|
2
2
|
let react = require("react");
|
|
3
3
|
//#region src/hooks/useInputValueTransform/useInputValueTransform.ts
|
|
4
4
|
/**
|
|
@@ -113,4 +113,4 @@ Object.defineProperty(exports, "useInputValueTransform", {
|
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
115
|
|
|
116
|
-
//# sourceMappingURL=useInputValueTransform-
|
|
116
|
+
//# sourceMappingURL=useInputValueTransform-Bm65K8LX.cjs.map
|
package/dist/{useInputValueTransform-f50WxOkF.cjs.map → useInputValueTransform-Bm65K8LX.cjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useInputValueTransform-
|
|
1
|
+
{"version":3,"file":"useInputValueTransform-Bm65K8LX.cjs","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,iBAAA,GAAA,MAAA,cA7CC,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,cAAA,GAAA,MAAA,cAtBC,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,6 +1,6 @@
|
|
|
1
1
|
import { t as InputValueTransform } from "./useInputValueTransform-CNCBU7a9.cjs";
|
|
2
|
-
import { r as useController } from "./useController-
|
|
3
|
-
import { n as useFormContext } from "./useFormContext-
|
|
2
|
+
import { r as useController } from "./useController-BT3Fd0IO.cjs";
|
|
3
|
+
import { n as useFormContext } from "./useFormContext-M94eQfHm.cjs";
|
|
4
4
|
import { t as useInput } from "./useInput-DZOmMKcp.cjs";
|
|
5
5
|
import { ReactNode } from "react";
|
|
6
6
|
import { FieldError, FieldValues, Path } from "react-hook-form";
|
|
@@ -95,4 +95,4 @@ interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues>
|
|
|
95
95
|
declare const useUniformField: <TFieldValues extends FieldValues = FieldValues, TDisplay = unknown>(params: UseUniformFieldParams<TFieldValues, TDisplay>) => UseUniformFieldReturn<TFieldValues>;
|
|
96
96
|
//#endregion
|
|
97
97
|
export { UseUniformFieldReturn as n, useUniformField as r, UseUniformFieldParams as t };
|
|
98
|
-
//# sourceMappingURL=useUniformField-
|
|
98
|
+
//# sourceMappingURL=useUniformField-BE-e3C4Y.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUniformField-
|
|
1
|
+
{"version":3,"file":"useUniformField-BE-e3C4Y.d.cts","names":[],"sources":["../src/hooks/useUniformField/useUniformField.tsx"],"mappings":";;;;;;;;UAgBiB,qBAAA,sBACM,WAAA,GAAc,WAAA;;EAInC,IAAA,EAAM,IAAA,CAAK,YAAA;EALyB;EAOpC,SAAA;EANqB;EAQrB,QAAA;EAJW;EAMX,KAAA,GAAQ,SAAA;EAAA;EAER,MAAA;EAEY;EAAZ,SAAA,GAAY,mBAAA,CAAoB,QAAA;EAAD;EAE/B,IAAA;AAAA;AAAA,UAGe,qBAAA,sBACM,WAAA,GAAc,WAAA;EAnBnC;EAsBA,SAAA;EAnBM;EAqBN,OAAA,EAAS,UAAA,QAAkB,cAAA,CAAe,YAAA;EAnB1C;EAqBA,SAAA,EAAW,UAAA,QAAkB,cAAA,CAAe,YAAA;EAjB5C;EAmBA,YAAA;EAjBA;EAmBA,QAAA;EAjBY;EAmBZ,KAAA,EAAO,UAAA;EAjBP;EAmBA,YAAA,EAAc,SAAA;EAnBV;EAqBJ,KAAA,EAAO,UAAA,QAAkB,aAAA,CAAc,YAAA;EAlBH;EAoBpC,oBAAA,EAAsB,UAAA,QAAkB,QAAA;EAnBnB;EAqBrB,qBAAA,EAAuB,UAAA,QAAkB,QAAA;EAhBC;EAkB1C,aAAA,EAAe,UAAA,QAAkB,QAAA;EAlBxB;EAoBT,SAAA,EAAW,UAAA,QAAkB,cAAA,CAAe,YAAA;EAlBf;EAoB7B,OAAA;EAdO;EAgBP,KAAA,EAAO,SAAA;EAZgC;EAcvC,MAAA,EAAQ,UAAA,QAAkB,aAAA,CAAc,YAAA;EAdjC;EAgBP,QAAA,EAAU,UAAA,QAAkB,aAAA,CAAc,YAAA;EAdpB;EAgBtB,GAAA,EAAK,UAAA,QAAkB,aAAA,CAAc,YAAA;EAdd;EAgBvB,QAAA;EAde;EAgBf,UAAA,EAAY,UAAA,QAAkB,cAAA,CAAe,YAAA;EAdhB;EAgB7B,MAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+BW,eAAA,wBACU,WAAA,GAAc,WAAA,sBAGnC,MAAA,EAAQ,qBAAA,CAAsB,YAAA,EAAc,QAAA,MAC3C,qBAAA,CAAsB,YAAA"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as InputValueTransform } from "./useInputValueTransform-dLfFIYW4.js";
|
|
2
|
-
import { r as useController$1 } from "./useController-
|
|
3
|
-
import { n as useFormContext$1 } from "./useFormContext-
|
|
2
|
+
import { r as useController$1 } from "./useController-CzP0aVFC.js";
|
|
3
|
+
import { n as useFormContext$1 } from "./useFormContext-Bj1gXLt_.js";
|
|
4
4
|
import { t as useInput } from "./useInput-BdH8oftG.js";
|
|
5
5
|
import { ReactNode } from "react";
|
|
6
6
|
import { FieldError, FieldValues, Path } from "react-hook-form";
|
|
@@ -95,4 +95,4 @@ interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues>
|
|
|
95
95
|
declare const useUniformField: <TFieldValues extends FieldValues = FieldValues, TDisplay = unknown>(params: UseUniformFieldParams<TFieldValues, TDisplay>) => UseUniformFieldReturn<TFieldValues>;
|
|
96
96
|
//#endregion
|
|
97
97
|
export { UseUniformFieldReturn as n, useUniformField as r, UseUniformFieldParams as t };
|
|
98
|
-
//# sourceMappingURL=useUniformField-
|
|
98
|
+
//# sourceMappingURL=useUniformField-DUW-svZD.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useUniformField-
|
|
1
|
+
{"version":3,"file":"useUniformField-DUW-svZD.d.ts","names":[],"sources":["../src/hooks/useUniformField/useUniformField.tsx"],"mappings":";;;;;;;;UAgBiB,qBAAA,sBACM,WAAA,GAAc,WAAA;;EAInC,IAAA,EAAM,IAAA,CAAK,YAAA;EALyB;EAOpC,SAAA;EANqB;EAQrB,QAAA;EAJW;EAMX,KAAA,GAAQ,SAAA;EAAA;EAER,MAAA;EAEY;EAAZ,SAAA,GAAY,mBAAA,CAAoB,QAAA;EAAD;EAE/B,IAAA;AAAA;AAAA,UAGe,qBAAA,sBACM,WAAA,GAAc,WAAA;EAnBnC;EAsBA,SAAA;EAnBM;EAqBN,OAAA,EAAS,UAAA,QAAkB,gBAAA,CAAe,YAAA;EAnB1C;EAqBA,SAAA,EAAW,UAAA,QAAkB,gBAAA,CAAe,YAAA;EAjB5C;EAmBA,YAAA;EAjBA;EAmBA,QAAA;EAjBY;EAmBZ,KAAA,EAAO,UAAA;EAjBP;EAmBA,YAAA,EAAc,SAAA;EAnBV;EAqBJ,KAAA,EAAO,UAAA,QAAkB,eAAA,CAAc,YAAA;EAlBH;EAoBpC,oBAAA,EAAsB,UAAA,QAAkB,QAAA;EAnBnB;EAqBrB,qBAAA,EAAuB,UAAA,QAAkB,QAAA;EAhBC;EAkB1C,aAAA,EAAe,UAAA,QAAkB,QAAA;EAlBxB;EAoBT,SAAA,EAAW,UAAA,QAAkB,gBAAA,CAAe,YAAA;EAlBf;EAoB7B,OAAA;EAdO;EAgBP,KAAA,EAAO,SAAA;EAZgC;EAcvC,MAAA,EAAQ,UAAA,QAAkB,eAAA,CAAc,YAAA;EAdjC;EAgBP,QAAA,EAAU,UAAA,QAAkB,eAAA,CAAc,YAAA;EAdpB;EAgBtB,GAAA,EAAK,UAAA,QAAkB,eAAA,CAAc,YAAA;EAdd;EAgBvB,QAAA;EAde;EAgBf,UAAA,EAAY,UAAA,QAAkB,gBAAA,CAAe,YAAA;EAdhB;EAgB7B,MAAA;AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cA+BW,eAAA,wBACU,WAAA,GAAc,WAAA,sBAGnC,MAAA,EAAQ,qBAAA,CAAsB,YAAA,EAAc,QAAA,MAC3C,qBAAA,CAAsB,YAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { r as useController$1 } from "./useController-
|
|
2
|
-
import { n as useFormContext$1 } from "./useFormContext-
|
|
1
|
+
import { r as useController$1 } from "./useController-CzP0aVFC.js";
|
|
2
|
+
import { n as useFormContext$1 } from "./useFormContext-Bj1gXLt_.js";
|
|
3
3
|
import { ReactNode } from "react";
|
|
4
4
|
import { ArrayPath, FieldValues } from "react-hook-form";
|
|
5
5
|
|
|
@@ -24,7 +24,9 @@ interface UseUniformFieldArrayProps<TFieldValues extends FieldValues = FieldValu
|
|
|
24
24
|
* Enhanced useFieldArray hook with initialization and animation logic.
|
|
25
25
|
* Based on React Hook Form's useFieldArray with additional features:
|
|
26
26
|
* - Automatic initialization when lastElementNotRemovable is set
|
|
27
|
+
* - Reset-only normalization for stale empty placeholder rows (via useWatchFormReset)
|
|
27
28
|
* - Animation control (disabled during initialization)
|
|
29
|
+
* - Temporary animation disable during reset normalization collapse
|
|
28
30
|
* - Support for flat arrays (arrays of primitives)
|
|
29
31
|
*
|
|
30
32
|
* Note: Automatic validation triggering on length change is disabled to prevent
|
|
@@ -74,4 +76,4 @@ declare const useUniformFieldArray: <TFieldValues extends FieldValues = FieldVal
|
|
|
74
76
|
};
|
|
75
77
|
//#endregion
|
|
76
78
|
export { useUniformFieldArray as n, UseUniformFieldArrayProps as t };
|
|
77
|
-
//# sourceMappingURL=useUniformFieldArray-
|
|
79
|
+
//# sourceMappingURL=useUniformFieldArray-CdWv1SEk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useUniformFieldArray-CdWv1SEk.d.ts","names":[],"sources":["../src/hooks/useUniformFieldArray/useUniformFieldArray.ts"],"mappings":";;;;;;UAaiB,yBAAA,sBACM,WAAA,GAAc,WAAA;;EAGnC,IAAA,EAAM,SAAA,CAAU,YAAA;;EAEhB,IAAA;EANe;EAQf,mBAAA;EARwC;EAUxC,uBAAA;EATmC;EAWnC,QAAA;EARM;EAUN,MAAA;EAEiB;EAAjB,KAAA,GAAQ,SAAA;AAAA;;;;;;;;;;;;;;AAAS;cAiBN,oBAAA,wBACU,WAAA,GAAc,WAAA;EACnC,IAAA;EAAA,IAAA;EAAA,mBAAA,EAAA,oBAAA;EAAA,uBAAA;EAAA,QAAA;EAAA,MAAA,EAAA,cAAA;EAAA;AAAA,GAQC,yBAAA,CAA0B,YAAA;;;;;;;;;kBAnCR,KAAA;;;;;;;;;UAoEJ,UAAA;YAEuB,UAAA,QAFvB,eAAA;OAK4B,UAAA,QAHL,eAAA"}
|