@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":"FieldCard-D9c1j_RX.cjs","names":["useUniformField","AnimatePresence","motion","FieldValidationError","useUniformField","useFormContext","checkFieldIsRequired"],"sources":["../src/FieldCard/subcomponents/FieldCardValidationError.tsx","../src/FieldCard/FieldCard.tsx"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\n\nimport {\n AnimatePresence,\n motion,\n useReducedMotion,\n} from '@fuf-stack/pixel-motion';\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { useUniformField } from '../../hooks/useUniformField';\nimport FieldValidationError from '../../partials/FieldValidationError/FieldValidationError';\n\nexport interface FieldCardValidationErrorProps {\n /** CSS class name for the error footer wrapper */\n className?: string;\n /** Error object from parent FieldCard (passed directly to avoid duplicate hook calls) */\n error?: FieldError[] | undefined;\n /** CSS class name for the error text (controls color based on invalid state) */\n errorTextClassName?: string;\n /** Field name */\n name: string;\n}\n\n/**\n * Renders validation errors in the footer of a FieldCard component.\n *\n * This component handles displaying field-level validation errors with proper\n * accessibility attributes and animates them in/out using Framer Motion.\n *\n * Note: Object-level errors (_errors) are always shown when they exist,\n * but the danger styling is controlled by the parent FieldCard based on\n * whether child fields have been touched.\n */\nconst FieldCardValidationError = ({\n className = undefined,\n error = undefined,\n errorTextClassName = undefined,\n name,\n}: FieldCardValidationErrorProps) => {\n const { getErrorMessageProps, getHelperWrapperProps, testId } =\n useUniformField({\n name,\n });\n\n // disable all animation if user prefers reduced motion\n const disableAnimation = useReducedMotion();\n\n // Always show object-level errors (_errors) when they exist\n // @ts-expect-error - error._errors exists but not typed\n const hasErrors = !!error?._errors;\n\n return (\n <AnimatePresence initial={!disableAnimation}>\n {hasErrors ? (\n <motion.div\n key=\"field-card-errors\"\n exit={disableAnimation ? undefined : { opacity: 0, height: 0 }}\n initial={disableAnimation ? false : { height: 0, opacity: 0 }}\n style={{ overflow: 'hidden' }}\n transition={{ duration: 0.4, ease: 'circOut' }}\n animate={\n disableAnimation ? undefined : { opacity: 1, height: 'auto' }\n }\n >\n <div\n {...getHelperWrapperProps()}\n className={cn(getHelperWrapperProps()?.className, className)}\n >\n <div\n {...getErrorMessageProps()}\n className={cn(\n getErrorMessageProps()?.className,\n errorTextClassName,\n )}\n >\n <FieldValidationError\n // @ts-expect-error - error._errors exists but not typed\n error={error._errors}\n testId={testId}\n />\n </div>\n </div>\n </motion.div>\n ) : null}\n </AnimatePresence>\n );\n};\n\nexport default FieldCardValidationError;\n","import type { TVClassName } from '@fuf-stack/pixel-utils';\nimport type { ReactNode } from 'react';\n\nimport { tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\nimport { useDebounce } from '@fuf-stack/pixels';\n\nimport { checkFieldIsRequired, useFormContext } from '../hooks/useFormContext';\nimport { useUniformField } from '../hooks/useUniformField';\nimport FieldCardValidationError from './subcomponents/FieldCardValidationError';\n\n/**\n * Recursively checks if any child field has an error (regardless of touched state).\n * Returns true if at least one child has an error.\n */\nexport const hasAnyChildErrors = (\n errors: Record<string, unknown> | undefined,\n): boolean => {\n if (!errors) {\n return false;\n }\n\n return Object.keys(errors)\n .filter((key) => {\n return key !== '_errors';\n })\n .some((key) => {\n const errorValue = errors[key];\n if (errorValue === undefined) {\n return false;\n }\n // If errorValue is an array, it's a leaf field error\n if (Array.isArray(errorValue)) {\n return true;\n }\n // Recursively check nested objects\n if (typeof errorValue === 'object' && errorValue !== null) {\n return hasAnyChildErrors(errorValue as Record<string, unknown>);\n }\n return false;\n });\n};\n\n/**\n * Recursively checks if any child field is touched.\n * Returns true if at least one child is touched.\n */\nexport const hasAnyChildTouched = (\n touched: Record<string, unknown> | undefined,\n): boolean => {\n if (!touched) {\n return false;\n }\n\n return Object.keys(touched)\n .filter((key) => {\n return key !== '_errors';\n })\n .some((key) => {\n const touchedValue = touched[key];\n if (touchedValue === undefined) {\n return false;\n }\n // If touchedValue is truthy (boolean true), field is touched\n if (touchedValue === true) {\n return true;\n }\n // Recursively check nested objects\n if (typeof touchedValue === 'object' && touchedValue !== null) {\n return hasAnyChildTouched(touchedValue as Record<string, unknown>);\n }\n return false;\n });\n};\n\n/**\n * Recursively checks if any child field with an error is also touched.\n * Returns true if at least one touched child has an error.\n */\nexport const hasVisibleChildErrors = (\n errors: Record<string, unknown> | undefined,\n touched: Record<string, unknown> | undefined,\n): boolean => {\n if (!errors || !touched) {\n return false;\n }\n\n return Object.keys(errors)\n .filter((key) => {\n // Skip object-level errors (_errors) - those are handled separately\n return key !== '_errors';\n })\n .some((key) => {\n const errorValue = errors[key];\n const touchedValue = touched[key];\n\n // If this key doesn't exist in both errors and touched, skip\n if (errorValue === undefined || touchedValue === undefined) {\n return false;\n }\n\n // If errorValue is an array, it's a leaf field error\n if (Array.isArray(errorValue)) {\n // touchedValue being truthy means the field is touched\n return !!touchedValue;\n }\n\n // Recursively check nested objects\n if (typeof errorValue === 'object' && errorValue !== null) {\n return hasVisibleChildErrors(\n errorValue as Record<string, unknown>,\n touchedValue as Record<string, unknown>,\n );\n }\n\n return false;\n });\n};\n\nexport const fieldCardVariants = tv({\n slots: {\n /** base class for the field card wrapper */\n base: [\n // base styles\n 'overflow-hidden rounded-small border bg-content1',\n // animate border color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the label/header */\n label: [\n // override HeroUI label positioning and display\n 'pointer-events-auto! static! z-auto! block! w-full!',\n // reset any transforms or translations\n 'translate-x-0! translate-y-0! transform-none!',\n // card header styling - use text-medium (16px) for proper header size\n 'rounded-t-small border-b p-3 font-semibold text-medium',\n // animate border and text color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the content */\n content: [\n // same as p-3 of Card component\n 'p-3',\n // default grid for form components (see Grid component)\n 'grid gap-4',\n ],\n /** class for the error footer wrapper */\n errorFooter: [\n 'border-t',\n // force helper to be visible and add padding (pt-1 to compensate for inner content's top padding)\n 'block px-3 pb-2 pt-1',\n // animate border color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the error text (empty base, color controlled by variant) */\n errorText: [],\n },\n variants: {\n invalid: {\n true: {\n base: 'border-danger-200',\n label: 'border-danger-200 text-danger',\n errorFooter: 'border-danger-200',\n errorText: '!text-danger text-tiny',\n },\n false: {\n base: 'border-divider',\n label: 'border-divider text-foreground',\n errorFooter: 'border-divider',\n errorText: '!text-foreground-500 text-tiny',\n },\n },\n },\n defaultVariants: {\n invalid: false,\n },\n});\n\ntype ClassName = TVClassName<typeof fieldCardVariants>;\n\nexport interface FieldCardProps {\n /** Content to render inside the card */\n children: ReactNode;\n /** CSS class name */\n className?: ClassName;\n /** Label content for the card header */\n label: ReactNode;\n /** Field name for validation */\n name: string;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n}\n\n/**\n * FieldCard component - A card-styled container with label header and error footer\n *\n * Displays form field content in a card layout with:\n * - Label/title in the header\n * - Content in the body\n * - Validation errors in the footer\n * - Danger outline when validation errors exist\n */\nconst FieldCard = ({\n children,\n className: _className = undefined,\n name,\n ...uniformFieldProps\n}: FieldCardProps) => {\n const { error, getLabelProps, label } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n const {\n control,\n formState: { touchedFields, submitCount },\n validation,\n } = useFormContext();\n\n // Check if any registered child field is required\n const validationInstance = validation?.baseInstance ?? validation?.instance;\n const registeredFields: string[] = Array.from(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (control as any)._names?.mount ?? [],\n );\n const childFieldPrefix = `${name}.`;\n const isRequired = validationInstance\n ? registeredFields\n .filter((f) => {\n return f.startsWith(childFieldPrefix);\n })\n .some((f) => {\n return checkFieldIsRequired(\n validationInstance,\n f.split('.').filter((k) => {\n return k !== '';\n }),\n );\n })\n : false;\n\n // Get touched state for this field's children by traversing the path\n const getNestedValue = (\n obj: Record<string, unknown> | undefined,\n path: string,\n ): Record<string, unknown> | undefined => {\n if (!obj) {\n return undefined;\n }\n const keys = path.split('.');\n let current: unknown = obj;\n keys.every((key) => {\n if (current && typeof current === 'object') {\n current = (current as Record<string, unknown>)[key];\n return true;\n }\n current = undefined;\n return false;\n });\n return current as Record<string, unknown> | undefined;\n };\n\n const fieldTouched = getNestedValue(\n touchedFields as Record<string, unknown>,\n name,\n );\n\n // Check for object-level errors (_errors)\n // @ts-expect-error - error._errors exists but not typed\n const hasObjectErrors = !!error?._errors;\n\n const errorRecord = error as unknown as Record<string, unknown>;\n\n // Check if any child field has errors (regardless of touched state)\n const hasChildErrors = hasAnyChildErrors(errorRecord);\n // Check if any child field is touched\n const isAnyChildTouched = hasAnyChildTouched(fieldTouched);\n\n // Show invalid styling (danger border/header/error text) when:\n // 1. Any child field has an error AND (it's touched OR form was submitted), OR\n // 2. Object-level _errors exists AND no child errors AND (any child touched OR submitted)\n const rawShowInvalid =\n (hasChildErrors &&\n (hasVisibleChildErrors(errorRecord, fieldTouched) || submitCount > 0)) ||\n (hasObjectErrors &&\n !hasChildErrors &&\n (isAnyChildTouched || submitCount > 0));\n\n // Debounce to prevent flickering during rapid state changes\n const showInvalid = useDebounce(rawShowInvalid, 200);\n\n // className from slots\n const variants = fieldCardVariants({ invalid: showInvalid });\n const className = variantsToClassNames(variants, _className, 'base');\n\n return (\n <div className={className.base}>\n {/* card header with label */}\n {label ? (\n <div\n {...getLabelProps()}\n aria-level={3}\n // Override getLabelProps className to use our own invalid styling based on hasErrors,\n // not HeroUI's which is based on any child field being invalid\n className={className.label}\n role=\"heading\"\n >\n {label}\n {/* Manual asterisk: getLabelProps uses schema-required for the object itself,\n but FieldCard needs asterisk based on whether any CHILD field is required */}\n {isRequired ? (\n <span aria-hidden=\"true\" className=\"ml-0.5 text-danger\">\n *\n </span>\n ) : null}\n </div>\n ) : null}\n\n {/* card content */}\n <div className={className.content}>{children}</div>\n\n {/* card footer with validation errors - always show _errors, but danger styling controlled by showInvalid */}\n <FieldCardValidationError\n className={className.errorFooter}\n error={error}\n errorTextClassName={className.errorText}\n name={name}\n />\n </div>\n );\n};\n\nexport default FieldCard;\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAiCA,MAAM,4BAA4B,EAChC,YAAY,KAAA,GACZ,QAAQ,KAAA,GACR,qBAAqB,KAAA,GACrB,WACmC;CACnC,MAAM,EAAE,sBAAsB,uBAAuB,WACnDA,oCAAAA,gBAAgB,EACd,KACF,CAAC;CAGH,MAAM,oBAAA,GAAA,wBAAA,kBAAoC;CAI1C,MAAM,YAAY,CAAC,CAAC,OAAO;CAE3B,OACE,iBAAA,GAAA,kBAAA,KAACC,wBAAAA,iBAAD;EAAiB,SAAS,CAAC;YACxB,YACC,iBAAA,GAAA,kBAAA,KAACC,wBAAAA,OAAO,KAAR;GAEE,MAAM,mBAAmB,KAAA,IAAY;IAAE,SAAS;IAAG,QAAQ;GAAE;GAC7D,SAAS,mBAAmB,QAAQ;IAAE,QAAQ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C,0BAAD;IACE,WAAW,UAAU;IACd;IACP,oBAAoB,UAAU;IACxB;GACP,CAAA;EACE;;AAET"}
|
|
1
|
+
{"version":3,"file":"FieldCard-C-DZ5ARr.cjs","names":["useUniformField","AnimatePresence","motion","FieldValidationError","useUniformField","useFormContext","checkFieldIsRequired"],"sources":["../src/FieldCard/subcomponents/FieldCardValidationError.tsx","../src/FieldCard/FieldCard.tsx"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\n\nimport {\n AnimatePresence,\n motion,\n useReducedMotion,\n} from '@fuf-stack/pixel-motion';\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { useUniformField } from '../../hooks/useUniformField';\nimport FieldValidationError from '../../partials/FieldValidationError/FieldValidationError';\n\nexport interface FieldCardValidationErrorProps {\n /** CSS class name for the error footer wrapper */\n className?: string;\n /** Error object from parent FieldCard (passed directly to avoid duplicate hook calls) */\n error?: FieldError[] | undefined;\n /** CSS class name for the error text (controls color based on invalid state) */\n errorTextClassName?: string;\n /** Field name */\n name: string;\n}\n\n/**\n * Renders validation errors in the footer of a FieldCard component.\n *\n * This component handles displaying field-level validation errors with proper\n * accessibility attributes and animates them in/out using Framer Motion.\n *\n * Note: Object-level errors (_errors) are always shown when they exist,\n * but the danger styling is controlled by the parent FieldCard based on\n * whether child fields have been touched.\n */\nconst FieldCardValidationError = ({\n className = undefined,\n error = undefined,\n errorTextClassName = undefined,\n name,\n}: FieldCardValidationErrorProps) => {\n const { getErrorMessageProps, getHelperWrapperProps, testId } =\n useUniformField({\n name,\n });\n\n // disable all animation if user prefers reduced motion\n const disableAnimation = useReducedMotion();\n\n // Always show object-level errors (_errors) when they exist\n // @ts-expect-error - error._errors exists but not typed\n const hasErrors = !!error?._errors;\n\n return (\n <AnimatePresence initial={!disableAnimation}>\n {hasErrors ? (\n <motion.div\n key=\"field-card-errors\"\n exit={disableAnimation ? undefined : { opacity: 0, height: 0 }}\n initial={disableAnimation ? false : { height: 0, opacity: 0 }}\n style={{ overflow: 'hidden' }}\n transition={{ duration: 0.4, ease: 'circOut' }}\n animate={\n disableAnimation ? undefined : { opacity: 1, height: 'auto' }\n }\n >\n <div\n {...getHelperWrapperProps()}\n className={cn(getHelperWrapperProps()?.className, className)}\n >\n <div\n {...getErrorMessageProps()}\n className={cn(\n getErrorMessageProps()?.className,\n errorTextClassName,\n )}\n >\n <FieldValidationError\n // @ts-expect-error - error._errors exists but not typed\n error={error._errors}\n testId={testId}\n />\n </div>\n </div>\n </motion.div>\n ) : null}\n </AnimatePresence>\n );\n};\n\nexport default FieldCardValidationError;\n","import type { TVClassName } from '@fuf-stack/pixel-utils';\nimport type { ReactNode } from 'react';\n\nimport { tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\nimport { useDebounce } from '@fuf-stack/pixels';\n\nimport { checkFieldIsRequired, useFormContext } from '../hooks/useFormContext';\nimport { useUniformField } from '../hooks/useUniformField';\nimport FieldCardValidationError from './subcomponents/FieldCardValidationError';\n\n/**\n * Recursively checks if any child field has an error (regardless of touched state).\n * Returns true if at least one child has an error.\n */\nexport const hasAnyChildErrors = (\n errors: Record<string, unknown> | undefined,\n): boolean => {\n if (!errors) {\n return false;\n }\n\n return Object.keys(errors)\n .filter((key) => {\n return key !== '_errors';\n })\n .some((key) => {\n const errorValue = errors[key];\n if (errorValue === undefined) {\n return false;\n }\n // If errorValue is an array, it's a leaf field error\n if (Array.isArray(errorValue)) {\n return true;\n }\n // Recursively check nested objects\n if (typeof errorValue === 'object' && errorValue !== null) {\n return hasAnyChildErrors(errorValue as Record<string, unknown>);\n }\n return false;\n });\n};\n\n/**\n * Recursively checks if any child field is touched.\n * Returns true if at least one child is touched.\n */\nexport const hasAnyChildTouched = (\n touched: Record<string, unknown> | undefined,\n): boolean => {\n if (!touched) {\n return false;\n }\n\n return Object.keys(touched)\n .filter((key) => {\n return key !== '_errors';\n })\n .some((key) => {\n const touchedValue = touched[key];\n if (touchedValue === undefined) {\n return false;\n }\n // If touchedValue is truthy (boolean true), field is touched\n if (touchedValue === true) {\n return true;\n }\n // Recursively check nested objects\n if (typeof touchedValue === 'object' && touchedValue !== null) {\n return hasAnyChildTouched(touchedValue as Record<string, unknown>);\n }\n return false;\n });\n};\n\n/**\n * Recursively checks if any child field with an error is also touched.\n * Returns true if at least one touched child has an error.\n */\nexport const hasVisibleChildErrors = (\n errors: Record<string, unknown> | undefined,\n touched: Record<string, unknown> | undefined,\n): boolean => {\n if (!errors || !touched) {\n return false;\n }\n\n return Object.keys(errors)\n .filter((key) => {\n // Skip object-level errors (_errors) - those are handled separately\n return key !== '_errors';\n })\n .some((key) => {\n const errorValue = errors[key];\n const touchedValue = touched[key];\n\n // If this key doesn't exist in both errors and touched, skip\n if (errorValue === undefined || touchedValue === undefined) {\n return false;\n }\n\n // If errorValue is an array, it's a leaf field error\n if (Array.isArray(errorValue)) {\n // touchedValue being truthy means the field is touched\n return !!touchedValue;\n }\n\n // Recursively check nested objects\n if (typeof errorValue === 'object' && errorValue !== null) {\n return hasVisibleChildErrors(\n errorValue as Record<string, unknown>,\n touchedValue as Record<string, unknown>,\n );\n }\n\n return false;\n });\n};\n\nexport const fieldCardVariants = tv({\n slots: {\n /** base class for the field card wrapper */\n base: [\n // base styles\n 'overflow-hidden rounded-small border bg-content1',\n // animate border color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the label/header */\n label: [\n // override HeroUI label positioning and display\n 'pointer-events-auto! static! z-auto! block! w-full!',\n // reset any transforms or translations\n 'translate-x-0! translate-y-0! transform-none!',\n // card header styling - use text-medium (16px) for proper header size\n 'rounded-t-small border-b p-3 font-semibold text-medium',\n // animate border and text color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the content */\n content: [\n // same as p-3 of Card component\n 'p-3',\n // default grid for form components (see Grid component)\n 'grid gap-4',\n ],\n /** class for the error footer wrapper */\n errorFooter: [\n 'border-t',\n // force helper to be visible and add padding (pt-1 to compensate for inner content's top padding)\n 'block px-3 pb-2 pt-1',\n // animate border color change, respect reduced motion\n 'transition-colors duration-150 motion-reduce:transition-none',\n ],\n /** class for the error text (empty base, color controlled by variant) */\n errorText: [],\n },\n variants: {\n invalid: {\n true: {\n base: 'border-danger-200',\n label: 'border-danger-200 text-danger',\n errorFooter: 'border-danger-200',\n errorText: '!text-danger text-tiny',\n },\n false: {\n base: 'border-divider',\n label: 'border-divider text-foreground',\n errorFooter: 'border-divider',\n errorText: '!text-foreground-500 text-tiny',\n },\n },\n },\n defaultVariants: {\n invalid: false,\n },\n});\n\ntype ClassName = TVClassName<typeof fieldCardVariants>;\n\nexport interface FieldCardProps {\n /** Content to render inside the card */\n children: ReactNode;\n /** CSS class name */\n className?: ClassName;\n /** Label content for the card header */\n label: ReactNode;\n /** Field name for validation */\n name: string;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n}\n\n/**\n * FieldCard component - A card-styled container with label header and error footer\n *\n * Displays form field content in a card layout with:\n * - Label/title in the header\n * - Content in the body\n * - Validation errors in the footer\n * - Danger outline when validation errors exist\n */\nconst FieldCard = ({\n children,\n className: _className = undefined,\n name,\n ...uniformFieldProps\n}: FieldCardProps) => {\n const { error, getLabelProps, label } = useUniformField({\n name,\n ...uniformFieldProps,\n });\n\n const {\n control,\n formState: { touchedFields, submitCount },\n validation,\n } = useFormContext();\n\n // Check if any registered child field is required\n const validationInstance = validation?.baseInstance ?? validation?.instance;\n const registeredFields: string[] = Array.from(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (control as any)._names?.mount ?? [],\n );\n const childFieldPrefix = `${name}.`;\n const isRequired = validationInstance\n ? registeredFields\n .filter((f) => {\n return f.startsWith(childFieldPrefix);\n })\n .some((f) => {\n return checkFieldIsRequired(\n validationInstance,\n f.split('.').filter((k) => {\n return k !== '';\n }),\n );\n })\n : false;\n\n // Get touched state for this field's children by traversing the path\n const getNestedValue = (\n obj: Record<string, unknown> | undefined,\n path: string,\n ): Record<string, unknown> | undefined => {\n if (!obj) {\n return undefined;\n }\n const keys = path.split('.');\n let current: unknown = obj;\n keys.every((key) => {\n if (current && typeof current === 'object') {\n current = (current as Record<string, unknown>)[key];\n return true;\n }\n current = undefined;\n return false;\n });\n return current as Record<string, unknown> | undefined;\n };\n\n const fieldTouched = getNestedValue(\n touchedFields as Record<string, unknown>,\n name,\n );\n\n // Check for object-level errors (_errors)\n // @ts-expect-error - error._errors exists but not typed\n const hasObjectErrors = !!error?._errors;\n\n const errorRecord = error as unknown as Record<string, unknown>;\n\n // Check if any child field has errors (regardless of touched state)\n const hasChildErrors = hasAnyChildErrors(errorRecord);\n // Check if any child field is touched\n const isAnyChildTouched = hasAnyChildTouched(fieldTouched);\n\n // Show invalid styling (danger border/header/error text) when:\n // 1. Any child field has an error AND (it's touched OR form was submitted), OR\n // 2. Object-level _errors exists AND no child errors AND (any child touched OR submitted)\n const rawShowInvalid =\n (hasChildErrors &&\n (hasVisibleChildErrors(errorRecord, fieldTouched) || submitCount > 0)) ||\n (hasObjectErrors &&\n !hasChildErrors &&\n (isAnyChildTouched || submitCount > 0));\n\n // Debounce to prevent flickering during rapid state changes\n const showInvalid = useDebounce(rawShowInvalid, 200);\n\n // className from slots\n const variants = fieldCardVariants({ invalid: showInvalid });\n const className = variantsToClassNames(variants, _className, 'base');\n\n return (\n <div className={className.base}>\n {/* card header with label */}\n {label ? (\n <div\n {...getLabelProps()}\n aria-level={3}\n // Override getLabelProps className to use our own invalid styling based on hasErrors,\n // not HeroUI's which is based on any child field being invalid\n className={className.label}\n role=\"heading\"\n >\n {label}\n {/* Manual asterisk: getLabelProps uses schema-required for the object itself,\n but FieldCard needs asterisk based on whether any CHILD field is required */}\n {isRequired ? (\n <span aria-hidden=\"true\" className=\"ml-0.5 text-danger\">\n *\n </span>\n ) : null}\n </div>\n ) : null}\n\n {/* card content */}\n <div className={className.content}>{children}</div>\n\n {/* card footer with validation errors - always show _errors, but danger styling controlled by showInvalid */}\n <FieldCardValidationError\n className={className.errorFooter}\n error={error}\n errorTextClassName={className.err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kBAAkB,EAAE,UAAA,GAAA,kBAAA,aAVlC,mBACE,sBAAsB,aAAa,YAAY,KAAK,cAAc,MACpE,mBACC,CAAC,mBACA,qBAAqB,cAAc,IAGQ,GAGQ,EAAE,CACZ,GAAG,YAAY,MAAM;CAEnE,OACE,iBAAA,GAAA,kBAAA,MAAC,OAAD;EAAK,WAAW,UAAU;YAA1B;GAEG,QACC,iBAAA,GAAA,kBAAA,MAAC,OAAD;IACE,GAAI,cAAc;IAClB,cAAY;IAGZ,WAAW,UAAU;IACrB,MAAK;cANP,CAQG,OAGA,aACC,iBAAA,GAAA,kBAAA,KAAC,QAAD;KAAM,eAAY;KAAO,WAAU;eAAqB;IAElD,CAAA,IACJ,IACD;QACH;GAGJ,iBAAA,GAAA,kBAAA,KAAC,OAAD;IAAK,WAAW,UAAU;IAAU;GAAc,CAAA;GAGlD,iBAAA,GAAA,kBAAA,KAAC,0BAAD;IACE,WAAW,UAAU;IACd;IACP,oBAAoB,UAAU;IACxB;GACP,CAAA;EACE;;AAET"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require("./FormContext-
|
|
1
|
+
require("./FormContext-DsmS_mkO.cjs");
|
|
2
2
|
let _fuf_stack_pixel_utils = require("@fuf-stack/pixel-utils");
|
|
3
3
|
let _fuf_stack_pixels = require("@fuf-stack/pixels");
|
|
4
4
|
let react_icons_fa6 = require("react-icons/fa6");
|
|
@@ -35,4 +35,4 @@ Object.defineProperty(exports, "FieldCopyTestIdButton_default", {
|
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
37
|
|
|
38
|
-
//# sourceMappingURL=FieldCopyTestIdButton-
|
|
38
|
+
//# sourceMappingURL=FieldCopyTestIdButton-ptoB1F75.cjs.map
|
package/dist/{FieldCopyTestIdButton-slAdYh6I.cjs.map → FieldCopyTestIdButton-ptoB1F75.cjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldCopyTestIdButton-
|
|
1
|
+
{"version":3,"file":"FieldCopyTestIdButton-ptoB1F75.cjs","names":["Button","FaBullseye"],"sources":["../src/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.tsx","../src/partials/FieldCopyTestIdButton/index.ts"],"sourcesContent":["import { FaBullseye } from 'react-icons/fa6';\n\nimport { cn } from '@fuf-stack/pixel-utils';\nimport { Button } from '@fuf-stack/pixels';\n\nexport interface FieldCopyTestIdButtonProps {\n /** CSS class name */\n className?: string;\n /** HTML data-testid attribute used in e2e tests */\n testId: string;\n}\n\nconst FieldCopyTestIdButton = ({\n className = undefined,\n testId,\n}: FieldCopyTestIdButtonProps) => {\n const copyToClipboard = () => {\n navigator.clipboard.writeText(testId).catch((err) => {\n console.error('Error copying TestId to clipboard', err);\n });\n };\n\n return (\n <Button\n className={cn(className, 'pointer-events-auto')}\n icon={<FaBullseye />}\n onClick={copyToClipboard}\n size=\"sm\"\n variant=\"light\"\n />\n );\n};\nexport default FieldCopyTestIdButton;\n","import FieldCopyTestIdButton from './FieldCopyTestIdButton';\n\nexport type { FieldCopyTestIdButtonProps } from './FieldCopyTestIdButton';\n\nexport { FieldCopyTestIdButton };\n\nexport default FieldCopyTestIdButton;\n"],"mappings":";;;;;;AAYA,MAAM,yBAAyB,EAC7B,YAAY,KAAA,GACZ,aACgC;CAChC,MAAM,wBAAwB;EAC5B,UAAU,UAAU,UAAU,MAAM,EAAE,OAAO,QAAQ;GACnD,QAAQ,MAAM,qCAAqC,GAAG;EACxD,CAAC;CACH;CAEA,OACE,iBAAA,GAAA,kBAAA,KAACA,kBAAAA,QAAD;EACE,YAAA,GAAA,uBAAA,IAAc,WAAW,qBAAqB;EAC9C,MAAM,iBAAA,GAAA,kBAAA,KAACC,gBAAAA,YAAD,CAAa,CAAA;EACnB,SAAS;EACT,MAAK;EACL,SAAQ;CACT,CAAA;AAEL;;;ACzBA,IAAA,gCAAe"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require("./FormContext-
|
|
1
|
+
require("./FormContext-DsmS_mkO.cjs");
|
|
2
2
|
let _fuf_stack_pixel_utils = require("@fuf-stack/pixel-utils");
|
|
3
3
|
let react_jsx_runtime = require("react/jsx-runtime");
|
|
4
4
|
let _fuf_stack_pixel_motion = require("@fuf-stack/pixel-motion");
|
|
@@ -59,4 +59,4 @@ Object.defineProperty(exports, "FieldValidationError_default", {
|
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
61
|
|
|
62
|
-
//# sourceMappingURL=FieldValidationError-
|
|
62
|
+
//# sourceMappingURL=FieldValidationError-BQcvvU9i.cjs.map
|
package/dist/{FieldValidationError-BWrQN-Im.cjs.map → FieldValidationError-BQcvvU9i.cjs.map}
RENAMED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FieldValidationError-
|
|
1
|
+
{"version":3,"file":"FieldValidationError-BQcvvU9i.cjs","names":["AnimatePresence","motion"],"sources":["../src/partials/FieldValidationError/FieldValidationError.tsx","../src/partials/FieldValidationError/index.ts"],"sourcesContent":["import type { FieldError } from 'react-hook-form';\n\nimport {\n AnimatePresence,\n motion,\n useReducedMotion,\n} from '@fuf-stack/pixel-motion';\nimport { slugify } from '@fuf-stack/pixel-utils';\n\nexport interface FieldValidationErrorProps {\n /** CSS class name */\n className?: string;\n /** Field errors */\n error?: FieldError[];\n /** HTML data-testid attribute used in e2e tests */\n testId: string;\n}\n\n/**\n * Renders a validation error of a field\n */\nconst FieldValidationError = ({\n className = undefined,\n error = undefined,\n testId,\n}: FieldValidationErrorProps) => {\n // disable all animation if user prefers reduced motion\n const disableAnimation = useReducedMotion();\n\n return (\n <ul\n aria-label={`Validation errors of field ${testId}`}\n className={className}\n data-testid={slugify(`${testId}_error`)}\n >\n <AnimatePresence initial={!disableAnimation}>\n {error?.map(({ message }, i) => {\n return (\n <motion.li\n key={slugify(`${testId}_error_${i}`)}\n exit={disableAnimation ? undefined : { opacity: 0, height: 0 }}\n initial={disableAnimation ? false : { height: 0, opacity: 0 }}\n style={{ overflow: 'hidden' }}\n transition={{ duration: 0.2, ease: 'circOut' }}\n animate={\n disableAnimation ? undefined : { opacity: 1, height: 'auto' }\n }\n >\n {/* wrap in div to apply padding and animation does not jump */}\n <div className=\"px-1 pt-1\">{message}</div>\n </motion.li>\n );\n })}\n </AnimatePresence>\n </ul>\n );\n};\n\nexport default FieldValidationError;\n","import FieldValidationError from './FieldValidationError';\n\nexport type { FieldValidationErrorProps } from './FieldValidationError';\n\nexport { FieldValidationError };\n\nexport default FieldValidationError;\n"],"mappings":";;;;;;;;AAqBA,MAAM,wBAAwB,EAC5B,YAAY,KAAA,GACZ,QAAQ,KAAA,GACR,aAC+B;CAE/B,MAAM,oBAAA,GAAA,wBAAA,kBAAoC;CAE1C,OACE,iBAAA,GAAA,kBAAA,KAAC,MAAD;EACE,cAAY,8BAA8B;EAC/B;EACX,gBAAA,GAAA,uBAAA,SAAqB,GAAG,OAAO,OAAO;YAEtC,iBAAA,GAAA,kBAAA,KAACA,wBAAAA,iBAAD;GAAiB,SAAS,CAAC;aACxB,OAAO,KAAK,EAAE,WAAW,MAAM;IAC9B,OACE,iBAAA,GAAA,kBAAA,KAACC,wBAAAA,OAAO,IAAR;KAEE,MAAM,mBAAmB,KAAA,IAAY;MAAE,SAAS;MAAG,QAAQ;KAAE;KAC7D,SAAS,mBAAmB,QAAQ;MAAE,QAAQ;MAAG,SAAS;KAAE;KAC5D,OAAO,EAAE,UAAU,SAAS;KAC5B,YAAY;MAAE,UAAU;MAAK,MAAM;KAAU;KAC7C,SACE,mBAAmB,KAAA,IAAY;MAAE,SAAS;MAAG,QAAQ;KAAO;eAI9D,iBAAA,GAAA,kBAAA,KAAC,OAAD;MAAK,WAAU;gBAAa;KAAa,CAAA;IAChC,IAAA,GAAA,uBAAA,SAXI,GAAG,OAAO,SAAS,GAAG,CAW1B;GAEf,CAAC;EACc,CAAA;CACf,CAAA;AAER;;;AClDA,IAAA,+BAAe"}
|
package/dist/Form/index.cjs
CHANGED
|
@@ -2,6 +2,6 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_Form = require("../Form-
|
|
5
|
+
const require_Form = require("../Form-CYlsIABv.cjs");
|
|
6
6
|
exports.Form = require_Form.Form;
|
|
7
7
|
exports.default = require_Form.Form_default;
|
package/dist/Form/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as FormProps, t as Form } from "../index-
|
|
1
|
+
import { n as FormProps, t as Form } from "../index-C3-TV4Up.cjs";
|
|
2
2
|
export { Form, Form as default, type FormProps };
|
package/dist/Form/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as FormProps, t as Form } from "../index-
|
|
1
|
+
import { n as FormProps, t as Form } from "../index-54OZEaUU.js";
|
|
2
2
|
export { Form, Form as default, type FormProps };
|
package/dist/Form/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as Form, t as Form_default } from "../Form-
|
|
1
|
+
import { n as Form, t as Form_default } from "../Form-D3yfDu4L.js";
|
|
2
2
|
export { Form, Form_default as default };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
const require_FormContext = require("./FormContext-
|
|
2
|
-
const require_useFormContext = require("./useFormContext-
|
|
1
|
+
const require_FormContext = require("./FormContext-DsmS_mkO.cjs");
|
|
2
|
+
const require_useFormContext = require("./useFormContext-CrXwNYiB.cjs");
|
|
3
3
|
let _fuf_stack_pixel_utils = require("@fuf-stack/pixel-utils");
|
|
4
4
|
let react = require("react");
|
|
5
5
|
let react_icons_fa6 = require("react-icons/fa6");
|
|
@@ -122,4 +122,4 @@ Object.defineProperty(exports, "Form_default", {
|
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
|
|
125
|
-
//# sourceMappingURL=Form-
|
|
125
|
+
//# sourceMappingURL=Form-CYlsIABv.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form-
|
|
1
|
+
{"version":3,"file":"Form-CYlsIABv.cjs","names":["useFormContext","Button","FaBug","Card","FaTimes","FaBullseye","Json","FormProvider"],"sources":["../src/Form/subcomponents/FormDebugViewer.tsx","../src/Form/Form.tsx","../src/Form/index.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { FaTimes } from 'react-icons/fa';\nimport { FaBug, FaBullseye } from 'react-icons/fa6';\n\nimport { cn } from '@fuf-stack/pixel-utils';\nimport { Button } from '@fuf-stack/pixels/Button';\nimport { Card } from '@fuf-stack/pixels/Card';\nimport { Json } from '@fuf-stack/pixels/Json';\n\nimport { useFormContext } from '../../hooks/useFormContext';\n\n// import Json css (theme)\nimport '@fuf-stack/pixels/Json.css';\n\ninterface FormDebugViewerProps {\n /** CSS class name */\n className?: string;\n}\n\n/** Renders a form debug panel with information about the current form state */\nconst FormDebugViewer = ({ className = undefined }: FormDebugViewerProps) => {\n const {\n debugMode,\n formState: { isValid, isSubmitting, submitCount, isSubmitSuccessful },\n getValues,\n setDebugMode,\n validation: { errors },\n subscribe,\n } = useFormContext();\n\n const showDebugButton = debugMode === 'off';\n const showDebugCard = debugMode === 'debug' || debugMode === 'debug-testids';\n const showDebugTestIds = debugMode === 'debug-testids';\n\n // Use subscribe instead of watch() to avoid triggering re-renders on parent components.\n // This component manages its own state and only updates itself when form values change.\n const [values, setValues] = useState<Record<string, unknown>>({});\n\n useEffect(() => {\n // Only subscribe when debug card is visible\n if (!showDebugCard) {\n return undefined;\n }\n\n // Initialize with current values when debug card is opened\n setValues(getValues() ?? {});\n\n const subscription = subscribe({\n formState: { values: true },\n callback: (state) => {\n setValues(state.values ?? {});\n },\n });\n\n return () => {\n subscription();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [showDebugCard]);\n\n if (showDebugButton) {\n return (\n <Button\n ariaLabel=\"Enable form debug mode\"\n className=\"fixed bottom-2.5 right-2.5 w-5 text-default-400\"\n icon={<FaBug />}\n variant=\"light\"\n onClick={() => {\n setDebugMode('debug');\n }}\n />\n );\n }\n\n // do not show card\n if (!showDebugCard) {\n return null;\n }\n\n return (\n <Card\n className={cn(className)}\n header={\n <div className=\"flex w-full flex-row justify-between\">\n <span className=\"text-lg\">Debug Mode</span>\n <Button\n color=\"danger\"\n icon={<FaTimes />}\n size=\"sm\"\n variant=\"light\"\n onClick={() => {\n setDebugMode('off');\n }}\n />\n </div>\n }\n >\n <Button\n className=\"mb-4 ml-auto mr-auto\"\n icon={<FaBullseye />}\n variant={showDebugTestIds ? 'solid' : 'light'}\n onClick={() => {\n setDebugMode(debugMode === 'debug' ? 'debug-testids' : 'debug');\n }}\n >\n {showDebugTestIds ? 'Hide CopyButton' : 'Show CopyButton'}\n </Button>\n <Json\n value={{\n values,\n errors: errors ?? null,\n submit: {\n isValid,\n isSubmitting,\n isSubmitSuccessful,\n submitCount,\n },\n }}\n />\n </Card>\n );\n};\n\nexport default FormDebugViewer;\n","import type { VetoInstance } from '@fuf-stack/veto';\nimport type { ReactNode } from 'react';\nimport type { FieldValues, SubmitHandler } from 'react-hook-form';\nimport type { DebugModeSettings } from './subcomponents/FormContext';\n\nimport { cn, slugify } from '@fuf-stack/pixel-utils';\n\nimport FormProvider from './subcomponents/FormContext';\nimport FormDebugViewer from './subcomponents/FormDebugViewer';\n\nconst IS_TEST = process.env.NODE_ENV === 'test';\n\nexport interface FormProps {\n /** form children */\n children: ReactNode | ReactNode[];\n /** CSS class name */\n className?: string | string[];\n /** settings for from debug mode */\n debug?: DebugModeSettings;\n /** initial form values */\n initialValues?: FieldValues;\n /** name of the form */\n name?: string;\n /** form submit handler */\n onSubmit: SubmitHandler<FieldValues>;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** veto validation schema */\n validation?: VetoInstance;\n /** when the validation should be triggered */\n validationTrigger?: 'onChange' | 'onBlur' | 'onSubmit' | 'onTouched' | 'all';\n}\n\n/**\n * Form component that has to wrap every uniform\n */\nconst Form = ({\n children,\n className = undefined,\n debug = undefined,\n initialValues = undefined,\n name = undefined,\n onSubmit,\n testId = undefined,\n validation = undefined,\n validationTrigger = 'all',\n}: FormProps) => {\n return (\n <FormProvider\n debugModeSettings={debug}\n initialValues={initialValues}\n onSubmit={onSubmit}\n validation={validation}\n validationTrigger={validationTrigger}\n >\n {({ handleSubmit, isValid }) => {\n return (\n <div className=\"flex w-full flex-row justify-between gap-6\">\n <form\n className={cn('grow', className)}\n data-form-is-valid={isValid}\n data-testid={slugify(testId ?? name ?? '')}\n name={name}\n onSubmit={handleSubmit}\n >\n {children}\n </form>\n {/* render debug viewer when not in test environment and debug not disabled */}\n {!IS_TEST && !debug?.disable && (\n <FormDebugViewer className=\"w-96 shrink\" />\n )}\n </div>\n );\n }}\n </FormProvider>\n );\n};\n\nexport default Form;\n","import Form from './Form';\n\nexport type { FormProps } from './Form';\n\nexport { Form };\n\nexport default Form;\n"],"mappings":";;;;;;;;;;;;;AAoBA,MAAM,mBAAmB,EAAE,YAAY,KAAA,QAAsC;CAC3E,MAAM,EACJ,WACA,WAAW,EAAE,SAAS,cAAc,aAAa,sBACjD,WACA,cACA,YAAY,EAAE,UACd,cACEA,uBAAAA,eAAe;CAEnB,MAAM,kBAAkB,cAAc;CACtC,MAAM,gBAAgB,cAAc,WAAW,cAAc;CAC7D,MAAM,mBAAmB,cAAc;CAIvC,MAAM,CAAC,QAAQ,cAAA,GAAA,MAAA,UAA+C,CAAC,CAAC;CAEhE,CAAA,GAAA,MAAA,iBAAgB;EAEd,IAAI,CAAC,eACH;EAIF,UAAU,UAAU,KAAK,CAAC,CAAC;EAE3B,MAAM,eAAe,UAAU;GAC7B,WAAW,EAAE,QAAQ,KAAK;GAC1B,WAAW,UAAU;IACnB,UAAU,MAAM,UAAU,CAAC,CAAC;GAC9B;EACF,CAAC;EAED,aAAa;GACX,aAAa;EACf;CAEF,GAAG,CAAC,aAAa,CAAC;CAElB,IAAI,iBACF,OACE,iBAAA,GAAA,kBAAA,KAACC,yBAAAA,QAAD;EACE,WAAU;EAC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;EACL;EACE;EACO;aAEjB,EAAE,cAAc,cAAc;GAC9B,OACE,iBAAA,GAAA,kBAAA,MAAC,OAAD;IAAK,WAAU;cAAf,CACE,iBAAA,GAAA,kBAAA,KAAC,QAAD;KACE,YAAA,GAAA,uBAAA,IAAc,QAAQ,SAAS;KAC/B,sBAAoB;KACpB,gBAAA,GAAA,uBAAA,SAAqB,UAAU,QAAQ,EAAE;KACnC;KACN,UAAU;KAET;IACG,CAAA,GAEL,CAAC,WAAW,CAAC,OAAO,WACnB,iBAAA,GAAA,kBAAA,KAAC,iBAAD,EAAiB,WAAU,cAAe,CAAA,CAEzC;;EAET;CACY,CAAA;AAElB;;;ACtEA,IAAA,eAAe"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { t as FormProvider } from "./FormContext-
|
|
2
|
-
import { n as useFormContext } from "./useFormContext-
|
|
1
|
+
import { t as FormProvider } from "./FormContext-BQeKOV-0.js";
|
|
2
|
+
import { n as useFormContext } from "./useFormContext-CT8H8xIe.js";
|
|
3
3
|
import { cn, slugify } from "@fuf-stack/pixel-utils";
|
|
4
4
|
import { useEffect, useState } from "react";
|
|
5
5
|
import { FaBug, FaBullseye } from "react-icons/fa6";
|
|
@@ -111,4 +111,4 @@ var Form_default = Form;
|
|
|
111
111
|
//#endregion
|
|
112
112
|
export { Form as n, Form_default as t };
|
|
113
113
|
|
|
114
|
-
//# sourceMappingURL=Form-
|
|
114
|
+
//# sourceMappingURL=Form-D3yfDu4L.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Form-
|
|
1
|
+
{"version":3,"file":"Form-D3yfDu4L.js","names":[],"sources":["../src/Form/subcomponents/FormDebugViewer.tsx","../src/Form/Form.tsx","../src/Form/index.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport { FaTimes } from 'react-icons/fa';\nimport { FaBug, FaBullseye } from 'react-icons/fa6';\n\nimport { cn } from '@fuf-stack/pixel-utils';\nimport { Button } from '@fuf-stack/pixels/Button';\nimport { Card } from '@fuf-stack/pixels/Card';\nimport { Json } from '@fuf-stack/pixels/Json';\n\nimport { useFormContext } from '../../hooks/useFormContext';\n\n// import Json css (theme)\nimport '@fuf-stack/pixels/Json.css';\n\ninterface FormDebugViewerProps {\n /** CSS class name */\n className?: string;\n}\n\n/** Renders a form debug panel with information about the current form state */\nconst FormDebugViewer = ({ className = undefined }: FormDebugViewerProps) => {\n const {\n debugMode,\n formState: { isValid, isSubmitting, submitCount, isSubmitSuccessful },\n getValues,\n setDebugMode,\n validation: { errors },\n subscribe,\n } = useFormContext();\n\n const showDebugButton = debugMode === 'off';\n const showDebugCard = debugMode === 'debug' || debugMode === 'debug-testids';\n const showDebugTestIds = debugMode === 'debug-testids';\n\n // Use subscribe instead of watch() to avoid triggering re-renders on parent components.\n // This component manages its own state and only updates itself when form values change.\n const [values, setValues] = useState<Record<string, unknown>>({});\n\n useEffect(() => {\n // Only subscribe when debug card is visible\n if (!showDebugCard) {\n return undefined;\n }\n\n // Initialize with current values when debug card is opened\n setValues(getValues() ?? {});\n\n const subscription = subscribe({\n formState: { values: true },\n callback: (state) => {\n setValues(state.values ?? {});\n },\n });\n\n return () => {\n subscription();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [showDebugCard]);\n\n if (showDebugButton) {\n return (\n <Button\n ariaLabel=\"Enable form debug mode\"\n className=\"fixed bottom-2.5 right-2.5 w-5 text-default-400\"\n icon={<FaBug />}\n variant=\"light\"\n onClick={() => {\n setDebugMode('debug');\n }}\n />\n );\n }\n\n // do not show card\n if (!showDebugCard) {\n return null;\n }\n\n return (\n <Card\n className={cn(className)}\n header={\n <div className=\"flex w-full flex-row justify-between\">\n <span className=\"text-lg\">Debug Mode</span>\n <Button\n color=\"danger\"\n icon={<FaTimes />}\n size=\"sm\"\n variant=\"light\"\n onClick={() => {\n setDebugMode('off');\n }}\n />\n </div>\n }\n >\n <Button\n className=\"mb-4 ml-auto mr-auto\"\n icon={<FaBullseye />}\n variant={showDebugTestIds ? 'solid' : 'light'}\n onClick={() => {\n setDebugMode(debugMode === 'debug' ? 'debug-testids' : 'debug');\n }}\n >\n {showDebugTestIds ? 'Hide CopyButton' : 'Show CopyButton'}\n </Button>\n <Json\n value={{\n values,\n errors: errors ?? null,\n submit: {\n isValid,\n isSubmitting,\n isSubmitSuccessful,\n submitCount,\n },\n }}\n />\n </Card>\n );\n};\n\nexport default FormDebugViewer;\n","import type { VetoInstance } from '@fuf-stack/veto';\nimport type { ReactNode } from 'react';\nimport type { FieldValues, SubmitHandler } from 'react-hook-form';\nimport type { DebugModeSettings } from './subcomponents/FormContext';\n\nimport { cn, slugify } from '@fuf-stack/pixel-utils';\n\nimport FormProvider from './subcomponents/FormContext';\nimport FormDebugViewer from './subcomponents/FormDebugViewer';\n\nconst IS_TEST = process.env.NODE_ENV === 'test';\n\nexport interface FormProps {\n /** form children */\n children: ReactNode | ReactNode[];\n /** CSS class name */\n className?: string | string[];\n /** settings for from debug mode */\n debug?: DebugModeSettings;\n /** initial form values */\n initialValues?: FieldValues;\n /** name of the form */\n name?: string;\n /** form submit handler */\n onSubmit: SubmitHandler<FieldValues>;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** veto validation schema */\n validation?: VetoInstance;\n /** when the validation should be triggered */\n validationTrigger?: 'onChange' | 'onBlur' | 'onSubmit' | 'onTouched' | 'all';\n}\n\n/**\n * Form component that has to wrap every uniform\n */\nconst Form = ({\n children,\n className = undefined,\n debug = undefined,\n initialValues = undefined,\n name = undefined,\n onSubmit,\n testId = undefined,\n validation = undefined,\n validationTrigger = 'all',\n}: FormProps) => {\n return (\n <FormProvider\n debugModeSettings={debug}\n initialValues={initialValues}\n onSubmit={onSubmit}\n validation={validation}\n validationTrigger={validationTrigger}\n >\n {({ handleSubmit, isValid }) => {\n return (\n <div className=\"flex w-full flex-row justify-between gap-6\">\n <form\n className={cn('grow', className)}\n data-form-is-valid={isValid}\n data-testid={slugify(testId ?? name ?? '')}\n name={name}\n onSubmit={handleSubmit}\n >\n {children}\n </form>\n {/* render debug viewer when not in test environment and debug not disabled */}\n {!IS_TEST && !debug?.disable && (\n <FormDebugViewer className=\"w-96 shrink\" />\n )}\n </div>\n );\n }}\n </FormProvider>\n );\n};\n\nexport default Form;\n","import Form from './Form';\n\nexport type { FormProps } from './Form';\n\nexport { Form };\n\nexport default Form;\n"],"mappings":";;;;;;;;;;;;;AAoBA,MAAM,mBAAmB,EAAE,YAAY,KAAA,QAAsC;CAC3E,MAAM,EACJ,WACA,WAAW,EAAE,SAAS,cAAc,aAAa,sBACjD,WACA,cACA,YAAY,EAAE,UACd,cACE,eAAe;CAEnB,MAAM,kBAAkB,cAAc;CACtC,MAAM,gBAAgB,cAAc,WAAW,cAAc;CAC7D,MAAM,mBAAmB,cAAc;CAIvC,MAAM,CAAC,QAAQ,aAAa,SAAkC,CAAC,CAAC;CAEhE,gBAAgB;EAEd,IAAI,CAAC,eACH;EAIF,UAAU,UAAU,KAAK,CAAC,CAAC;EAE3B,MAAM,eAAe,UAAU;GAC7B,WAAW,EAAE,QAAQ,KAAK;GAC1B,WAAW,UAAU;IACnB,UAAU,MAAM,UAAU,CAAC,CAAC;GAC9B;EACF,CAAC;EAED,aAAa;GACX,aAAa;EACf;CAEF,GAAG,CAAC,aAAa,CAAC;CAElB,IAAI,iBACF,OACE,oBAAC,QAAD;EACE,WAAU;EACV,WAAU;EACV,MAAM,oBAAC,OAAD,CAAQ,CAAA;EACd,SAAQ;EACR,eAAe;GACb,aAAa,OAAO;EACtB;CACD,CAAA;CAKL,IAAI,CAAC,eACH,OAAO;CAGT,OACE,qBAAC,MAAD;EACE,WAAW,GAAG,SAAS;EACvB,QACE,qBAAC,OAAD;GAAK,WAAU;aAAf,CACE,oBAAC,QAAD;IAAM,WAAU;cAAU;GAAgB,CAAA,GAC1C,oBAAC,QAAD;IACE,OAAM;IACN,MAAM,oBAAC,SAAD,CAAU,CAAA;IAChB,MAAK;IACL,SAAQ;IACR,eAAe;KACb,aAAa,KAAK;IACpB;GACD,CAAA,CACE;;YAdT,CAiBE,oBAAC,QAAD;GACE,WAAU;GACV,MAAM,oBAAC,YAAD,CAAa,CAAA;GACnB,SAAS,mBAAmB,UAAU;GACtC,eAAe;IACb,aAAa,cAAc,UAAU,kBAAkB,OAAO;GAChE;aAEC,mBAAmB,oBAAoB;EAClC,CAAA,GACR,oBAAC,MAAD,EACE,OAAO;GACL;GACA,QAAQ,UAAU;GAClB,QAAQ;IACN;IACA;IACA;IACA;GACF;EACF,EACD,CAAA,CACG;;AAEV;;;AC/GA,MAAM,UAAU,QAAQ,IAAI,aAAa;;;;AA0BzC,MAAM,QAAQ,EACZ,UACA,YAAY,KAAA,GACZ,QAAQ,KAAA,GACR,gBAAgB,KAAA,GAChB,OAAO,KAAA,GACP,UACA,SAAS,KAAA,GACT,aAAa,KAAA,GACb,oBAAoB,YACL;CACf,OACE,oBAAC,cAAD;EACE,mBAAmB;EACJ;EACL;EACE;EACO;aAEjB,EAAE,cAAc,cAAc;GAC9B,OACE,qBAAC,OAAD;IAAK,WAAU;cAAf,CACE,oBAAC,QAAD;KACE,WAAW,GAAG,QAAQ,SAAS;KAC/B,sBAAoB;KACpB,eAAa,QAAQ,UAAU,QAAQ,EAAE;KACnC;KACN,UAAU;KAET;IACG,CAAA,GAEL,CAAC,WAAW,CAAC,OAAO,WACnB,oBAAC,iBAAD,EAAiB,WAAU,cAAe,CAAA,CAEzC;;EAET;CACY,CAAA;AAElB;;;ACtEA,IAAA,eAAe"}
|
|
@@ -9,10 +9,12 @@ interface DebugModeSettings {
|
|
|
9
9
|
/** custom localStorage key to save debug mode state */
|
|
10
10
|
localStorageKey?: string;
|
|
11
11
|
}
|
|
12
|
+
/** Listener function that gets called when a form reset is triggered */
|
|
13
|
+
type FormResetListener = () => void;
|
|
12
14
|
/**
|
|
13
15
|
* Listener function that gets called when a field changes due to user input
|
|
14
16
|
*/
|
|
15
17
|
type UserChangeListener<TFieldValues extends object = object> = (fieldName: Path<TFieldValues>, value: unknown) => void;
|
|
16
18
|
//#endregion
|
|
17
|
-
export {
|
|
18
|
-
//# sourceMappingURL=FormContext-
|
|
19
|
+
export { FormResetListener as n, UserChangeListener as r, DebugModeSettings as t };
|
|
20
|
+
//# sourceMappingURL=FormContext-3kamRn2C.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormContext-3kamRn2C.d.cts","names":[],"sources":["../src/Form/subcomponents/FormContext.tsx"],"mappings":";;;;;UAsBiB,iBAAA;EAAiB;EAEhC,OAAA;EAAA;EAEA,eAAe;AAAA;;KAIL,iBAAA;;AAAiB;AAK7B;KAAY,kBAAA,0CACV,SAAA,EAAW,IAAI,CAAC,YAAA,GAChB,KAAA"}
|
|
@@ -125,6 +125,12 @@ const DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT = "uniform:debug-mode";
|
|
|
125
125
|
if (!window.__UNIFORM_CONTEXT__) {
|
|
126
126
|
window.__UNIFORM_CONTEXT__ = React.createContext({
|
|
127
127
|
debugMode: "off",
|
|
128
|
+
formReset: {
|
|
129
|
+
subscribe: () => {
|
|
130
|
+
return () => {};
|
|
131
|
+
},
|
|
132
|
+
notify: () => {}
|
|
133
|
+
},
|
|
128
134
|
preventSubmit: () => {},
|
|
129
135
|
setDebugMode: () => {},
|
|
130
136
|
triggerSubmit: () => {},
|
|
@@ -151,6 +157,8 @@ debug("UniformContext exported", {
|
|
|
151
157
|
* - Client validation schema management
|
|
152
158
|
* - Submit handler with automatic data conversion and submission control with preventSubmit
|
|
153
159
|
* - Form Debug Mode state
|
|
160
|
+
* - Form reset pub/sub notifications (`formReset`)
|
|
161
|
+
* - User change pub/sub notifications (`userChange`)
|
|
154
162
|
* - React Hook Form context
|
|
155
163
|
*/
|
|
156
164
|
const FormProvider$1 = ({ children, debugModeSettings = void 0, initialValues = void 0, onSubmit, validation: baseValidation = void 0, validationTrigger }) => {
|
|
@@ -164,6 +172,18 @@ const FormProvider$1 = ({ children, debugModeSettings = void 0, initialValues =
|
|
|
164
172
|
});
|
|
165
173
|
const isValid = methods.formState?.isValid;
|
|
166
174
|
const [preventSubmit, setPreventSubmit] = useState(false);
|
|
175
|
+
const formResetListenersRef = useRef(/* @__PURE__ */ new Set());
|
|
176
|
+
const subscribeFormReset = useCallback((listener) => {
|
|
177
|
+
formResetListenersRef.current.add(listener);
|
|
178
|
+
return () => {
|
|
179
|
+
formResetListenersRef.current.delete(listener);
|
|
180
|
+
};
|
|
181
|
+
}, []);
|
|
182
|
+
const notifyFormReset = useCallback(() => {
|
|
183
|
+
formResetListenersRef.current.forEach((listener) => {
|
|
184
|
+
listener();
|
|
185
|
+
});
|
|
186
|
+
}, []);
|
|
167
187
|
const userChangeListenersRef = useRef(/* @__PURE__ */ new Set());
|
|
168
188
|
const subscribeUserChange = useCallback((listener) => {
|
|
169
189
|
userChangeListenersRef.current.add(listener);
|
|
@@ -221,6 +241,10 @@ const FormProvider$1 = ({ children, debugModeSettings = void 0, initialValues =
|
|
|
221
241
|
setClientValidationSchema,
|
|
222
242
|
setDebugMode,
|
|
223
243
|
triggerSubmit: handleSubmit,
|
|
244
|
+
formReset: {
|
|
245
|
+
subscribe: subscribeFormReset,
|
|
246
|
+
notify: notifyFormReset
|
|
247
|
+
},
|
|
224
248
|
userChange: {
|
|
225
249
|
subscribe: subscribeUserChange,
|
|
226
250
|
notify: notifyUserChange
|
|
@@ -251,4 +275,4 @@ const FormProvider$1 = ({ children, debugModeSettings = void 0, initialValues =
|
|
|
251
275
|
//#endregion
|
|
252
276
|
export { UniformContext as n, FormProvider$1 as t };
|
|
253
277
|
|
|
254
|
-
//# sourceMappingURL=FormContext-
|
|
278
|
+
//# sourceMappingURL=FormContext-BQeKOV-0.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormContext-BQeKOV-0.js","names":["FormProvider","HookFormProvider"],"sources":["../src/Form/subcomponents/FormResolver.ts","../src/Form/subcomponents/FormContext.tsx"],"sourcesContent":["import type {\n VetoFormattedError,\n VetoInstance,\n VetoTypeAny,\n} from '@fuf-stack/veto';\nimport type { FieldValues } from 'react-hook-form';\n\nimport { useCallback, useMemo, useState } from 'react';\n\nimport { and, veto } from '@fuf-stack/veto';\n\nimport { toValidationFormat } from '../../helpers';\n\n/**\n * Hook that manages client validation schemas state.\n *\n * Provides a centralized way to add/remove dynamic validation schemas\n * that can be combined with base form validation.\n *\n * @returns Object with client validation state and memoized setter function\n */\nexport const useClientValidationManager = () => {\n // Client validation schemas state\n const [clientValidationSchemas, setClientValidationSchemas] = useState<\n Record<string, VetoTypeAny>\n >({});\n\n // Memoized function to set/clear client validation schema\n const setClientValidationSchema = useMemo(() => {\n return (key: string, schema: VetoTypeAny | null) => {\n // update client validation schemas\n setClientValidationSchemas((prev) => {\n // if no schema and no existing client validation schema for this key, do nothing\n if (!prev[key] && !schema) {\n return prev;\n }\n // if no schema, remove the client validation schema for this key\n if (!schema) {\n const { [key]: _removed, ...rest } = prev;\n return rest;\n }\n // if schema, add or update the client validation schema for this key\n return { ...prev, [key]: schema };\n });\n };\n }, []);\n\n return {\n clientValidationSchemas,\n setClientValidationSchema,\n };\n};\n\n/**\n * Hook that creates an extended validation instance combining base Veto validation with dynamic client validation.\n *\n * @param baseValidation - Optional base Veto validation schema\n * @returns Combined validation instance and client schema setter\n */\nexport const useExtendedValidation = (baseValidation?: VetoInstance) => {\n // Setup client validation schemas\n const { clientValidationSchemas, setClientValidationSchema } =\n useClientValidationManager();\n\n // Create a stable dependency array from the client validation schemas\n const clientSchemaValues = useMemo<VetoTypeAny[]>(\n () => {\n const keys = Object.keys(clientValidationSchemas).sort();\n return keys\n .map((key) => {\n return clientValidationSchemas[key];\n })\n .filter((schema): schema is VetoTypeAny => {\n return Boolean(schema);\n });\n },\n // Include the object identity to react to schema instance updates with same shape\n [clientValidationSchemas],\n );\n\n // Memoized extended validation instance\n const extendedValidation = useMemo(\n () => {\n const hasBaseValidation = !!baseValidation;\n const hasClientSchemas = clientSchemaValues.length > 0;\n\n // If no base validation and no client schemas, return undefined\n if (!hasBaseValidation && !hasClientSchemas) {\n return undefined;\n }\n\n // If no client schemas, return base validation\n if (!hasClientSchemas) {\n return baseValidation;\n }\n\n // Combine client validation schemas\n const clientSchemasCombined =\n clientSchemaValues.reduce<VetoTypeAny | null>(\n (combined, clientSchema) => {\n return combined ? and(combined, clientSchema) : clientSchema;\n },\n null,\n );\n\n // return combined validation\n if (baseValidation && clientSchemasCombined) {\n // Put client validation first so dynamic/domain-specific messages\n // are returned before generic base validation errors.\n const baseSchema = baseValidation.schema as VetoTypeAny;\n return veto(and(clientSchemasCombined, baseSchema));\n }\n\n // If we only have client schemas, return them as a veto instance\n if (clientSchemasCombined) {\n return veto(clientSchemasCombined);\n }\n\n // This should not happen due to the conditions above, but just in case\n return baseValidation;\n },\n // Recompute when validation schema instances change\n [baseValidation, clientSchemaValues],\n );\n\n return {\n extendedValidation,\n setClientValidationSchema,\n };\n};\n\n/**\n * Render state for formatted validation errors produced by the resolver.\n *\n * `errors` is the value exposed through Uniform context. `hash` is the stable\n * comparison key used to avoid re-rendering context consumers when validation\n * returns an equivalent error object with a new identity.\n */\ninterface ValidationErrorsState {\n /** Formatted validation errors exposed to Uniform consumers. */\n errors: VetoFormattedError | undefined;\n /** JSON hash of `errors`, used as a cheap equality signal. */\n hash: string | undefined;\n}\n\n/**\n * Creates a React Hook Form resolver from an extended validation instance and\n * stores its latest formatted Veto errors as React state.\n *\n * Keeping the resolver errors in state lets Uniform context consumers re-render\n * when validation output changes, while the hash prevents repeated validations\n * with equivalent errors from causing unnecessary updates.\n *\n * @param extendedValidation - Extended validation instance from useExtendedValidation\n * @returns Resolver function plus the latest validation errors and their hash\n */\nexport const useFormResolver = (extendedValidation?: VetoInstance) => {\n // Keep the latest resolver errors in React state so Uniform context consumers\n // re-render when validation output changes. The paired hash lets us skip the\n // state update when a resolver run returns equivalent errors.\n const [validationErrorsState, setValidationErrorsState] =\n useState<ValidationErrorsState>({\n errors: undefined,\n hash: undefined,\n });\n\n /**\n * Updates resolver error state only when the formatted validation result\n * actually changes. Veto/RHF may create new error objects for equivalent\n * validation output, so the hash is the guard against avoidable context\n * refreshes.\n */\n const updateValidationErrors = useCallback(\n (errors: VetoFormattedError | undefined): void => {\n const nextHash = JSON.stringify(errors);\n\n setValidationErrorsState((current) => {\n if (current.hash === nextHash) {\n return current;\n }\n\n return {\n errors,\n hash: nextHash,\n };\n });\n },\n [],\n );\n\n // Memoized resolver function for React Hook Form\n const resolver = useMemo(() => {\n if (!extendedValidation) {\n return undefined;\n }\n\n return async (values: FieldValues) => {\n const validationValues = toValidationFormat(values) ?? {};\n const result = await extendedValidation.validateAsync(validationValues);\n updateValidationErrors(result.errors ?? undefined);\n\n // Transform veto result to React Hook Form format\n return {\n values: result.data ?? {},\n errors: result.errors ?? {},\n };\n };\n }, [extendedValidation, updateValidationErrors]);\n\n return {\n resolver,\n validationErrors: validationErrorsState.errors,\n validationErrorsHash: validationErrorsState.hash,\n };\n};\n","import type {\n VetoFormattedError,\n VetoInstance,\n VetoTypeAny,\n} from '@fuf-stack/veto';\nimport type { BaseSyntheticEvent, ReactNode } from 'react';\nimport type { FieldValues, Path, SubmitHandler } from 'react-hook-form';\n\nimport React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { FormProvider as HookFormProvider, useForm } from 'react-hook-form';\n\nimport createDebug from 'debug';\n\nimport { useLocalStorage } from '@fuf-stack/pixels';\n\nimport { toFormFormat, toSubmitFormat } from '../../helpers';\nimport { useExtendedValidation, useFormResolver } from './FormResolver';\n\nconst debug = createDebug('uniform:FormContext');\n\ntype DebugMode = 'debug' | 'debug-testids' | 'off' | 'disabled';\n\nexport interface DebugModeSettings {\n /** disable form debug completely */\n disable?: boolean;\n /** custom localStorage key to save debug mode state */\n localStorageKey?: string;\n}\n\n/** Listener function that gets called when a form reset is triggered */\nexport type FormResetListener = () => void;\n\n/**\n * Listener function that gets called when a field changes due to user input\n */\nexport type UserChangeListener<TFieldValues extends object = object> = (\n fieldName: Path<TFieldValues>,\n value: unknown,\n) => void;\n\nconst DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT = 'uniform:debug-mode';\n\n/**\n * The `UniformContext` provides control over the form's submission behavior and may optionally include\n * a Veto validation schema for form validation.\n *\n * Specifically, this context offers:\n * 1. **Form Submission Control**: The `preventSubmit` function allows components to enable or disable\n * form submissions.\n * 2. **Optional Validation Schema**: The `validation` property may hold a Veto validation schema instance\n * that can be used to validate form fields and handle validation logic.\n * 3. **Client Validation**: The `setClientValidationSchema` function allows setting dynamic client-side\n * validation schemas that complement the base Veto validation.\n * 4. **User Change Tracking**: The `userChange` property provides a pub/sub system for tracking\n * user-initiated field changes (typing, clicking, selecting) - NOT programmatic changes like\n * form.reset() or form.setValue(). Used by the `useWatchUserChange` hook to enable reactive\n * field dependencies.\n * 5. **Form Reset Tracking**: The `formReset` property provides a pub/sub system for tracking\n * programmatic form resets triggered via the wrapped `reset()` from `useFormContext`.\n * Used by hooks like `useWatchFormReset` to run reset-specific normalization logic.\n *\n * This context is useful for components that need to interact with or control the form submission state,\n * or access the validation schema for managing form validation logic.\n *\n * IMPORTANT: Context Singleton Pattern for HMR (Hot Module Replacement)\n * =====================================================================\n *\n * We use a global window variable to ensure only ONE context instance exists across\n * hot module reloads during development. This is critical because:\n *\n * **The Problem:**\n * When using Vite/Storybook with Fast Refresh (HMR), editing this file causes it to\n * be re-evaluated. Each re-evaluation runs `React.createContext()` again, creating a\n * NEW context instance. This leads to \"context instance mismatch\":\n *\n * 1. FormProvider (provider) loads and uses context instance A\n * 2. File is edited, HMR triggers\n * 3. SubmitButton (consumer) hot-reloads and imports context instance B\n * 4. Provider writes to instance A, Consumer reads from instance B\n * 5. Result: Consumer sees default values (triggerSubmit = () => undefined)\n * 6. Clicking submit does nothing because it calls the empty default function\n *\n * **The Solution:**\n * By storing the context in `window.__UNIFORM_CONTEXT__`, we ensure:\n * - First load: Create context and store in window\n * - Subsequent HMRs: Reuse the same context from window\n * - All components always reference the SAME context instance\n * - Provider and consumers can properly communicate\n *\n * **Why This Is Safe:**\n * - Only affects development (production has no HMR)\n * - Context type never changes (same interface)\n * - React handles cleanup on unmount normally\n * - No memory leaks (context is lightweight)\n *\n * Without this pattern, you'd need to restart the dev server after every edit\n * to FormContext.tsx to ensure all components use the same context instance.\n */\n\n// Define the context type\ninterface UniformContextType {\n /** Form debug mode enabled or not */\n debugMode: DebugMode;\n /** settings for form debug mode */\n debugModeSettings?: DebugModeSettings;\n /** Form reset tracking (programmatic reset calls) */\n formReset: {\n /**\n * Subscribe to programmatic form resets.\n * Returns an unsubscribe function.\n */\n subscribe: (listener: FormResetListener) => () => void;\n /**\n * Notify all subscribers about a programmatic form reset.\n * Called from useFormContext when reset() is invoked.\n */\n notify: () => void;\n };\n /** Function to update if the form can currently be submitted */\n preventSubmit: (prevent: boolean) => void;\n /** Setter to enable or disable form debug mode */\n setDebugMode: (debugMode: DebugMode) => void;\n /** Function to trigger form submit programmatically */\n triggerSubmit: (e?: BaseSyntheticEvent) => Promise<void> | void;\n /** User change tracking (user input only, not programmatic changes) */\n userChange: {\n /**\n * Subscribe to user field changes.\n * Returns an unsubscribe function.\n */\n subscribe: (listener: UserChangeListener) => () => void;\n /**\n * Notify all subscribers about a user field change.\n * Called from useController when user interacts with a field.\n */\n notify: (fieldName: string, value: unknown) => void;\n };\n /** Form validation configuration */\n validation: {\n /** Base validation schema instance (without client validation) */\n baseInstance?: VetoInstance;\n /** Veto validation schema instance for form validation */\n instance?: VetoInstance;\n /** Current validation errors in form */\n errors?: VetoFormattedError;\n /** Function to set client validation schema for a specific key */\n setClientValidationSchema: (\n key: string,\n schema: VetoTypeAny | null,\n ) => void;\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nif (!(window as any).__UNIFORM_CONTEXT__) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (window as any).__UNIFORM_CONTEXT__ = React.createContext<UniformContextType>(\n {\n debugMode: 'off',\n formReset: {\n subscribe: () => {\n return () => {\n return undefined;\n };\n },\n notify: () => {\n return undefined;\n },\n },\n preventSubmit: () => {\n return undefined;\n },\n setDebugMode: () => {\n return undefined;\n },\n triggerSubmit: () => {\n return undefined;\n },\n userChange: {\n subscribe: () => {\n return () => {\n return undefined;\n };\n },\n notify: () => {\n return undefined;\n },\n },\n validation: {\n setClientValidationSchema: () => {\n return undefined;\n },\n },\n },\n );\n debug('Creating new UniformContext instance');\n} else {\n debug(\n 'Reusing existing UniformContext instance from window.__UNIFORM_CONTEXT__',\n );\n}\n\n// Export the singleton context instance from window\n// This ensures all imports get the same context, even after HMR\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const UniformContext = (window as any)\n .__UNIFORM_CONTEXT__ as React.Context<UniformContextType>;\n\ndebug('UniformContext exported', {\n contextExists: !!UniformContext,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n windowContextExists: !!(window as any).__UNIFORM_CONTEXT__,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n contextsMatch: UniformContext === (window as any).__UNIFORM_CONTEXT__,\n});\n\n// Define props for the internal FormProvider component\ninterface FormProviderProps {\n /** children form render function */\n children: (childProps: {\n handleSubmit: (e?: BaseSyntheticEvent) => Promise<void>;\n isValid: boolean;\n }) => ReactNode;\n /** settings for form debug mode */\n debugModeSettings?: DebugModeSettings;\n /** initial form values */\n initialValues?: FieldValues;\n /** form submit handler */\n onSubmit: SubmitHandler<FieldValues>;\n /** Veto validation schema instance */\n validation?: VetoInstance;\n /** when the validation should be triggered */\n validationTrigger: 'onChange' | 'onBlur' | 'onSubmit' | 'onTouched' | 'all';\n}\n\n/**\n * FormProvider component provides:\n * - Veto validation schema context\n * - Resolver-backed validation error state\n * - Client validation schema management\n * - Submit handler with automatic data conversion and submission control with preventSubmit\n * - Form Debug Mode state\n * - Form reset pub/sub notifications (`formReset`)\n * - User change pub/sub notifications (`userChange`)\n * - React Hook Form context\n */\nconst FormProvider: React.FC<FormProviderProps> = ({\n children,\n debugModeSettings = undefined,\n initialValues = undefined,\n onSubmit,\n validation: baseValidation = undefined,\n validationTrigger,\n}) => {\n // Form Debug mode state is handled in the form context\n const [debugMode, setDebugMode] = useLocalStorage<DebugMode>(\n debugModeSettings?.localStorageKey ?? DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT,\n 'off',\n );\n\n // Create extended validation combining base + client validations\n const { extendedValidation, setClientValidationSchema } =\n useExtendedValidation(baseValidation);\n\n // Create resolver from extended validation + reactive validation error state\n const { resolver, validationErrors, validationErrorsHash } =\n useFormResolver(extendedValidation);\n\n // Initialize react hook form with the resolver\n const methods = useForm({\n defaultValues: initialValues ? toFormFormat(initialValues) : initialValues,\n // set rhf mode\n // see: https://react-hook-form.com/docs/useform#mode\n mode: validationTrigger,\n resolver,\n });\n\n // Get isValid from React Hook Form's formState\n const isValid = methods.formState?.isValid;\n\n // Control if the form can currently be submitted\n const [preventSubmit, setPreventSubmit] = useState(false);\n\n // Form reset listener registry (stored in ref to avoid re-renders)\n const formResetListenersRef = useRef<Set<FormResetListener>>(new Set());\n\n // Subscribe to form reset notifications\n const subscribeFormReset = useCallback(\n (listener: FormResetListener): (() => void) => {\n formResetListenersRef.current.add(listener);\n return () => {\n formResetListenersRef.current.delete(listener);\n };\n },\n [],\n );\n\n // Notify all subscribers about a programmatic form reset\n const notifyFormReset = useCallback((): void => {\n formResetListenersRef.current.forEach((listener) => {\n listener();\n });\n }, []);\n\n // User change listener registry (stored in ref to avoid re-renders)\n const userChangeListenersRef = useRef<Set<UserChangeListener>>(new Set());\n\n // Subscribe to user changes\n const subscribeUserChange = useCallback(\n (listener: UserChangeListener): (() => void) => {\n userChangeListenersRef.current.add(listener);\n // Return cleanup function to unsubscribe\n return () => {\n userChangeListenersRef.current.delete(listener);\n };\n },\n [],\n );\n\n // Notify all subscribers about user change\n const notifyUserChange = useCallback(\n (fieldName: string, value: unknown): void => {\n // Notify all registered listeners\n userChangeListenersRef.current.forEach((listener) => {\n listener(fieldName as Path<object>, value);\n });\n },\n [],\n );\n\n // Create submit handler with automatic data conversion\n // eslint-disable-next-line consistent-return\n const handleSubmit = async (e?: React.BaseSyntheticEvent) => {\n debug('handleSubmit called', {\n preventSubmit,\n formStateIsValid: methods.formState.isValid,\n validationErrors: methods.formState.errors,\n validationTrigger,\n formValues: methods.getValues(),\n });\n\n // only prevent submit when form state is valid, because otherwise\n // submit will only trigger validation and add errors / focus invalid fields\n if (methods.formState.isValid && preventSubmit) {\n debug('⛔ Form submit PREVENTED', {\n formStateIsValid: methods.formState.isValid,\n preventSubmit,\n });\n console.warn(\n '[FormProvider] form submit was prevented because preventSubmit is true...',\n );\n e?.preventDefault();\n return Promise.resolve();\n }\n\n debug('✓ Form submit ALLOWED', {\n formStateIsValid: methods.formState.isValid,\n preventSubmit,\n reason: !methods.formState.isValid\n ? 'Form is invalid (will trigger validation and show errors)'\n : 'Form is valid and preventSubmit is false',\n });\n\n // Convert form data to submission format:\n // - Unwrap flat array wrappers and convert markers\n // - Remove empty strings, nulls, empty arrays, and empty objects\n const wrappedOnSubmit = (data: FieldValues, event?: BaseSyntheticEvent) => {\n const submitData = toSubmitFormat(data) ?? {};\n debug('onSubmit callback called', { submitData });\n return onSubmit(submitData, event);\n };\n\n await methods.handleSubmit(wrappedOnSubmit)(e);\n\n debug('handleSubmit completed');\n };\n\n // Memoize the context value so consumers only re-render when context-relevant\n // state changes, including resolver-backed validation errors.\n const contextValue = useMemo(\n () => {\n return {\n // set debugMode to disabled when debugModeSettings.disable is true\n // otherwise use current debug mode from localStorage\n debugMode: debugModeSettings?.disable ? 'disabled' : debugMode,\n preventSubmit: (prevent: boolean) => {\n debug('preventSubmit called', {\n previousValue: preventSubmit,\n newValue: prevent,\n formStateIsValid: methods.formState.isValid,\n validationErrors: methods.formState.errors,\n });\n setPreventSubmit(prevent);\n },\n setClientValidationSchema,\n setDebugMode,\n triggerSubmit: handleSubmit,\n formReset: {\n subscribe: subscribeFormReset,\n notify: notifyFormReset,\n },\n userChange: {\n subscribe: subscribeUserChange,\n notify: notifyUserChange,\n },\n validation: {\n baseInstance: baseValidation,\n instance: extendedValidation,\n errors: validationErrors,\n setClientValidationSchema,\n },\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [debugMode, debugModeSettings?.disable, validationErrorsHash],\n );\n\n return (\n <UniformContext.Provider value={contextValue}>\n {/* Spread all hook form props into HookFormProvider */}\n <HookFormProvider {...methods}>\n {children({ handleSubmit, isValid })}\n </HookFormProvider>\n </UniformContext.Provider>\n );\n};\n\nexport default FormProvider;\n"],"mappings":";;;;;;;;;;;;;;;;AAqBA,MAAa,mCAAmC;CAE9C,MAAM,CAAC,yBAAyB,8BAA8B,SAE5D,CAAC,CAAC;CAsBJ,OAAO;EACL;EACA,2BArBgC,cAAc;GAC9C,QAAQ,KAAa,WAA+B;IAElD,4BAA4B,SAAS;KAEnC,IAAI,CAAC,KAAK,QAAQ,CAAC,QACjB,OAAO;KAGT,IAAI,CAAC,QAAQ;MACX,MAAM,GAAG,MAAM,UAAU,GAAG,SAAS;MACrC,OAAO;KACT;KAEA,OAAO;MAAE,GAAG;OAAO,MAAM;KAAO;IAClC,CAAC;GACH;EACF,GAAG,CAAC,CAIsB;CAC1B;AACF;;;;;;;AAQA,MAAa,yBAAyB,mBAAkC;CAEtE,MAAM,EAAE,yBAAyB,8BAC/B,2BAA2B;CAG7B,MAAM,qBAAqB,cACnB;EAEJ,OADa,OAAO,KAAK,uBAAuB,EAAE,KACxC,EACP,KAAK,QAAQ;GACZ,OAAO,wBAAwB;EACjC,CAAC,EACA,QAAQ,WAAkC;GACzC,OAAO,QAAQ,MAAM;EACvB,CAAC;CACL,GAEA,CAAC,uBAAuB,CAC1B;CA+CA,OAAO;EACL,oBA7CyB,cACnB;GACJ,MAAM,oBAAoB,CAAC,CAAC;GAC5B,MAAM,mBAAmB,mBAAmB,SAAS;GAGrD,IAAI,CAAC,qBAAqB,CAAC,kBACzB;GAIF,IAAI,CAAC,kBACH,OAAO;GAIT,MAAM,wBAC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ACV;GACA,YAAY;IACV,cAAc;IACd,UAAU;IACV,QAAQ;IACR;GACF;EACF;CACF,GAEA;EAAC;EAAW,mBAAmB;EAAS;CAAoB,CAC9D;CAEA,OACE,oBAAC,eAAe,UAAhB;EAAyB,OAAO;YAE9B,oBAACC,cAAD;GAAkB,GAAI;aACnB,SAAS;IAAE;IAAc;GAAQ,CAAC;EACnB,CAAA;CACK,CAAA;AAE7B"}
|
|
@@ -149,6 +149,12 @@ const DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT = "uniform:debug-mode";
|
|
|
149
149
|
if (!window.__UNIFORM_CONTEXT__) {
|
|
150
150
|
window.__UNIFORM_CONTEXT__ = react.default.createContext({
|
|
151
151
|
debugMode: "off",
|
|
152
|
+
formReset: {
|
|
153
|
+
subscribe: () => {
|
|
154
|
+
return () => {};
|
|
155
|
+
},
|
|
156
|
+
notify: () => {}
|
|
157
|
+
},
|
|
152
158
|
preventSubmit: () => {},
|
|
153
159
|
setDebugMode: () => {},
|
|
154
160
|
triggerSubmit: () => {},
|
|
@@ -175,6 +181,8 @@ debug$1("UniformContext exported", {
|
|
|
175
181
|
* - Client validation schema management
|
|
176
182
|
* - Submit handler with automatic data conversion and submission control with preventSubmit
|
|
177
183
|
* - Form Debug Mode state
|
|
184
|
+
* - Form reset pub/sub notifications (`formReset`)
|
|
185
|
+
* - User change pub/sub notifications (`userChange`)
|
|
178
186
|
* - React Hook Form context
|
|
179
187
|
*/
|
|
180
188
|
const FormProvider = ({ children, debugModeSettings = void 0, initialValues = void 0, onSubmit, validation: baseValidation = void 0, validationTrigger }) => {
|
|
@@ -188,6 +196,18 @@ const FormProvider = ({ children, debugModeSettings = void 0, initialValues = vo
|
|
|
188
196
|
});
|
|
189
197
|
const isValid = methods.formState?.isValid;
|
|
190
198
|
const [preventSubmit, setPreventSubmit] = (0, react.useState)(false);
|
|
199
|
+
const formResetListenersRef = (0, react.useRef)(/* @__PURE__ */ new Set());
|
|
200
|
+
const subscribeFormReset = (0, react.useCallback)((listener) => {
|
|
201
|
+
formResetListenersRef.current.add(listener);
|
|
202
|
+
return () => {
|
|
203
|
+
formResetListenersRef.current.delete(listener);
|
|
204
|
+
};
|
|
205
|
+
}, []);
|
|
206
|
+
const notifyFormReset = (0, react.useCallback)(() => {
|
|
207
|
+
formResetListenersRef.current.forEach((listener) => {
|
|
208
|
+
listener();
|
|
209
|
+
});
|
|
210
|
+
}, []);
|
|
191
211
|
const userChangeListenersRef = (0, react.useRef)(/* @__PURE__ */ new Set());
|
|
192
212
|
const subscribeUserChange = (0, react.useCallback)((listener) => {
|
|
193
213
|
userChangeListenersRef.current.add(listener);
|
|
@@ -245,6 +265,10 @@ const FormProvider = ({ children, debugModeSettings = void 0, initialValues = vo
|
|
|
245
265
|
setClientValidationSchema,
|
|
246
266
|
setDebugMode,
|
|
247
267
|
triggerSubmit: handleSubmit,
|
|
268
|
+
formReset: {
|
|
269
|
+
subscribe: subscribeFormReset,
|
|
270
|
+
notify: notifyFormReset
|
|
271
|
+
},
|
|
248
272
|
userChange: {
|
|
249
273
|
subscribe: subscribeUserChange,
|
|
250
274
|
notify: notifyUserChange
|
|
@@ -292,4 +316,4 @@ Object.defineProperty(exports, "__toESM", {
|
|
|
292
316
|
}
|
|
293
317
|
});
|
|
294
318
|
|
|
295
|
-
//# sourceMappingURL=FormContext-
|
|
319
|
+
//# sourceMappingURL=FormContext-DsmS_mkO.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormContext-DsmS_mkO.cjs","names":["toValidationFormat","debug","React","toFormFormat","toSubmitFormat","HookFormProvider"],"sources":["../src/Form/subcomponents/FormResolver.ts","../src/Form/subcomponents/FormContext.tsx"],"sourcesContent":["import type {\n VetoFormattedError,\n VetoInstance,\n VetoTypeAny,\n} from '@fuf-stack/veto';\nimport type { FieldValues } from 'react-hook-form';\n\nimport { useCallback, useMemo, useState } from 'react';\n\nimport { and, veto } from '@fuf-stack/veto';\n\nimport { toValidationFormat } from '../../helpers';\n\n/**\n * Hook that manages client validation schemas state.\n *\n * Provides a centralized way to add/remove dynamic validation schemas\n * that can be combined with base form validation.\n *\n * @returns Object with client validation state and memoized setter function\n */\nexport const useClientValidationManager = () => {\n // Client validation schemas state\n const [clientValidationSchemas, setClientValidationSchemas] = useState<\n Record<string, VetoTypeAny>\n >({});\n\n // Memoized function to set/clear client validation schema\n const setClientValidationSchema = useMemo(() => {\n return (key: string, schema: VetoTypeAny | null) => {\n // update client validation schemas\n setClientValidationSchemas((prev) => {\n // if no schema and no existing client validation schema for this key, do nothing\n if (!prev[key] && !schema) {\n return prev;\n }\n // if no schema, remove the client validation schema for this key\n if (!schema) {\n const { [key]: _removed, ...rest } = prev;\n return rest;\n }\n // if schema, add or update the client validation schema for this key\n return { ...prev, [key]: schema };\n });\n };\n }, []);\n\n return {\n clientValidationSchemas,\n setClientValidationSchema,\n };\n};\n\n/**\n * Hook that creates an extended validation instance combining base Veto validation with dynamic client validation.\n *\n * @param baseValidation - Optional base Veto validation schema\n * @returns Combined validation instance and client schema setter\n */\nexport const useExtendedValidation = (baseValidation?: VetoInstance) => {\n // Setup client validation schemas\n const { clientValidationSchemas, setClientValidationSchema } =\n useClientValidationManager();\n\n // Create a stable dependency array from the client validation schemas\n const clientSchemaValues = useMemo<VetoTypeAny[]>(\n () => {\n const keys = Object.keys(clientValidationSchemas).sort();\n return keys\n .map((key) => {\n return clientValidationSchemas[key];\n })\n .filter((schema): schema is VetoTypeAny => {\n return Boolean(schema);\n });\n },\n // Include the object identity to react to schema instance updates with same shape\n [clientValidationSchemas],\n );\n\n // Memoized extended validation instance\n const extendedValidation = useMemo(\n () => {\n const hasBaseValidation = !!baseValidation;\n const hasClientSchemas = clientSchemaValues.length > 0;\n\n // If no base validation and no client schemas, return undefined\n if (!hasBaseValidation && !hasClientSchemas) {\n return undefined;\n }\n\n // If no client schemas, return base validation\n if (!hasClientSchemas) {\n return baseValidation;\n }\n\n // Combine client validation schemas\n const clientSchemasCombined =\n clientSchemaValues.reduce<VetoTypeAny | null>(\n (combined, clientSchema) => {\n return combined ? and(combined, clientSchema) : clientSchema;\n },\n null,\n );\n\n // return combined validation\n if (baseValidation && clientSchemasCombined) {\n // Put client validation first so dynamic/domain-specific messages\n // are returned before generic base validation errors.\n const baseSchema = baseValidation.schema as VetoTypeAny;\n return veto(and(clientSchemasCombined, baseSchema));\n }\n\n // If we only have client schemas, return them as a veto instance\n if (clientSchemasCombined) {\n return veto(clientSchemasCombined);\n }\n\n // This should not happen due to the conditions above, but just in case\n return baseValidation;\n },\n // Recompute when validation schema instances change\n [baseValidation, clientSchemaValues],\n );\n\n return {\n extendedValidation,\n setClientValidationSchema,\n };\n};\n\n/**\n * Render state for formatted validation errors produced by the resolver.\n *\n * `errors` is the value exposed through Uniform context. `hash` is the stable\n * comparison key used to avoid re-rendering context consumers when validation\n * returns an equivalent error object with a new identity.\n */\ninterface ValidationErrorsState {\n /** Formatted validation errors exposed to Uniform consumers. */\n errors: VetoFormattedError | undefined;\n /** JSON hash of `errors`, used as a cheap equality signal. */\n hash: string | undefined;\n}\n\n/**\n * Creates a React Hook Form resolver from an extended validation instance and\n * stores its latest formatted Veto errors as React state.\n *\n * Keeping the resolver errors in state lets Uniform context consumers re-render\n * when validation output changes, while the hash prevents repeated validations\n * with equivalent errors from causing unnecessary updates.\n *\n * @param extendedValidation - Extended validation instance from useExtendedValidation\n * @returns Resolver function plus the latest validation errors and their hash\n */\nexport const useFormResolver = (extendedValidation?: VetoInstance) => {\n // Keep the latest resolver errors in React state so Uniform context consumers\n // re-render when validation output changes. The paired hash lets us skip the\n // state update when a resolver run returns equivalent errors.\n const [validationErrorsState, setValidationErrorsState] =\n useState<ValidationErrorsState>({\n errors: undefined,\n hash: undefined,\n });\n\n /**\n * Updates resolver error state only when the formatted validation result\n * actually changes. Veto/RHF may create new error objects for equivalent\n * validation output, so the hash is the guard against avoidable context\n * refreshes.\n */\n const updateValidationErrors = useCallback(\n (errors: VetoFormattedError | undefined): void => {\n const nextHash = JSON.stringify(errors);\n\n setValidationErrorsState((current) => {\n if (current.hash === nextHash) {\n return current;\n }\n\n return {\n errors,\n hash: nextHash,\n };\n });\n },\n [],\n );\n\n // Memoized resolver function for React Hook Form\n const resolver = useMemo(() => {\n if (!extendedValidation) {\n return undefined;\n }\n\n return async (values: FieldValues) => {\n const validationValues = toValidationFormat(values) ?? {};\n const result = await extendedValidation.validateAsync(validationValues);\n updateValidationErrors(result.errors ?? undefined);\n\n // Transform veto result to React Hook Form format\n return {\n values: result.data ?? {},\n errors: result.errors ?? {},\n };\n };\n }, [extendedValidation, updateValidationErrors]);\n\n return {\n resolver,\n validationErrors: validationErrorsState.errors,\n validationErrorsHash: validationErrorsState.hash,\n };\n};\n","import type {\n VetoFormattedError,\n VetoInstance,\n VetoTypeAny,\n} from '@fuf-stack/veto';\nimport type { BaseSyntheticEvent, ReactNode } from 'react';\nimport type { FieldValues, Path, SubmitHandler } from 'react-hook-form';\n\nimport React, { useCallback, useMemo, useRef, useState } from 'react';\nimport { FormProvider as HookFormProvider, useForm } from 'react-hook-form';\n\nimport createDebug from 'debug';\n\nimport { useLocalStorage } from '@fuf-stack/pixels';\n\nimport { toFormFormat, toSubmitFormat } from '../../helpers';\nimport { useExtendedValidation, useFormResolver } from './FormResolver';\n\nconst debug = createDebug('uniform:FormContext');\n\ntype DebugMode = 'debug' | 'debug-testids' | 'off' | 'disabled';\n\nexport interface DebugModeSettings {\n /** disable form debug completely */\n disable?: boolean;\n /** custom localStorage key to save debug mode state */\n localStorageKey?: string;\n}\n\n/** Listener function that gets called when a form reset is triggered */\nexport type FormResetListener = () => void;\n\n/**\n * Listener function that gets called when a field changes due to user input\n */\nexport type UserChangeListener<TFieldValues extends object = object> = (\n fieldName: Path<TFieldValues>,\n value: unknown,\n) => void;\n\nconst DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT = 'uniform:debug-mode';\n\n/**\n * The `UniformContext` provides control over the form's submission behavior and may optionally include\n * a Veto validation schema for form validation.\n *\n * Specifically, this context offers:\n * 1. **Form Submission Control**: The `preventSubmit` function allows components to enable or disable\n * form submissions.\n * 2. **Optional Validation Schema**: The `validation` property may hold a Veto validation schema instance\n * that can be used to validate form fields and handle validation logic.\n * 3. **Client Validation**: The `setClientValidationSchema` function allows setting dynamic client-side\n * validation schemas that complement the base Veto validation.\n * 4. **User Change Tracking**: The `userChange` property provides a pub/sub system for tracking\n * user-initiated field changes (typing, clicking, selecting) - NOT programmatic changes like\n * form.reset() or form.setValue(). Used by the `useWatchUserChange` hook to enable reactive\n * field dependencies.\n * 5. **Form Reset Tracking**: The `formReset` property provides a pub/sub system for tracking\n * programmatic form resets triggered via the wrapped `reset()` from `useFormContext`.\n * Used by hooks like `useWatchFormReset` to run reset-specific normalization logic.\n *\n * This context is useful for components that need to interact with or control the form submission state,\n * or access the validation schema for managing form validation logic.\n *\n * IMPORTANT: Context Singleton Pattern for HMR (Hot Module Replacement)\n * =====================================================================\n *\n * We use a global window variable to ensure only ONE context instance exists across\n * hot module reloads during development. This is critical because:\n *\n * **The Problem:**\n * When using Vite/Storybook with Fast Refresh (HMR), editing this file causes it to\n * be re-evaluated. Each re-evaluation runs `React.createContext()` again, creating a\n * NEW context instance. This leads to \"context instance mismatch\":\n *\n * 1. FormProvider (provider) loads and uses context instance A\n * 2. File is edited, HMR triggers\n * 3. SubmitButton (consumer) hot-reloads and imports context instance B\n * 4. Provider writes to instance A, Consumer reads from instance B\n * 5. Result: Consumer sees default values (triggerSubmit = () => undefined)\n * 6. Clicking submit does nothing because it calls the empty default function\n *\n * **The Solution:**\n * By storing the context in `window.__UNIFORM_CONTEXT__`, we ensure:\n * - First load: Create context and store in window\n * - Subsequent HMRs: Reuse the same context from window\n * - All components always reference the SAME context instance\n * - Provider and consumers can properly communicate\n *\n * **Why This Is Safe:**\n * - Only affects development (production has no HMR)\n * - Context type never changes (same interface)\n * - React handles cleanup on unmount normally\n * - No memory leaks (context is lightweight)\n *\n * Without this pattern, you'd need to restart the dev server after every edit\n * to FormContext.tsx to ensure all components use the same context instance.\n */\n\n// Define the context type\ninterface UniformContextType {\n /** Form debug mode enabled or not */\n debugMode: DebugMode;\n /** settings for form debug mode */\n debugModeSettings?: DebugModeSettings;\n /** Form reset tracking (programmatic reset calls) */\n formReset: {\n /**\n * Subscribe to programmatic form resets.\n * Returns an unsubscribe function.\n */\n subscribe: (listener: FormResetListener) => () => void;\n /**\n * Notify all subscribers about a programmatic form reset.\n * Called from useFormContext when reset() is invoked.\n */\n notify: () => void;\n };\n /** Function to update if the form can currently be submitted */\n preventSubmit: (prevent: boolean) => void;\n /** Setter to enable or disable form debug mode */\n setDebugMode: (debugMode: DebugMode) => void;\n /** Function to trigger form submit programmatically */\n triggerSubmit: (e?: BaseSyntheticEvent) => Promise<void> | void;\n /** User change tracking (user input only, not programmatic changes) */\n userChange: {\n /**\n * Subscribe to user field changes.\n * Returns an unsubscribe function.\n */\n subscribe: (listener: UserChangeListener) => () => void;\n /**\n * Notify all subscribers about a user field change.\n * Called from useController when user interacts with a field.\n */\n notify: (fieldName: string, value: unknown) => void;\n };\n /** Form validation configuration */\n validation: {\n /** Base validation schema instance (without client validation) */\n baseInstance?: VetoInstance;\n /** Veto validation schema instance for form validation */\n instance?: VetoInstance;\n /** Current validation errors in form */\n errors?: VetoFormattedError;\n /** Function to set client validation schema for a specific key */\n setClientValidationSchema: (\n key: string,\n schema: VetoTypeAny | null,\n ) => void;\n };\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nif (!(window as any).__UNIFORM_CONTEXT__) {\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n (window as any).__UNIFORM_CONTEXT__ = React.createContext<UniformContextType>(\n {\n debugMode: 'off',\n formReset: {\n subscribe: () => {\n return () => {\n return undefined;\n };\n },\n notify: () => {\n return undefined;\n },\n },\n preventSubmit: () => {\n return undefined;\n },\n setDebugMode: () => {\n return undefined;\n },\n triggerSubmit: () => {\n return undefined;\n },\n userChange: {\n subscribe: () => {\n return () => {\n return undefined;\n };\n },\n notify: () => {\n return undefined;\n },\n },\n validation: {\n setClientValidationSchema: () => {\n return undefined;\n },\n },\n },\n );\n debug('Creating new UniformContext instance');\n} else {\n debug(\n 'Reusing existing UniformContext instance from window.__UNIFORM_CONTEXT__',\n );\n}\n\n// Export the singleton context instance from window\n// This ensures all imports get the same context, even after HMR\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const UniformContext = (window as any)\n .__UNIFORM_CONTEXT__ as React.Context<UniformContextType>;\n\ndebug('UniformContext exported', {\n contextExists: !!UniformContext,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n windowContextExists: !!(window as any).__UNIFORM_CONTEXT__,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n contextsMatch: UniformContext === (window as any).__UNIFORM_CONTEXT__,\n});\n\n// Define props for the internal FormProvider component\ninterface FormProviderProps {\n /** children form render function */\n children: (childProps: {\n handleSubmit: (e?: BaseSyntheticEvent) => Promise<void>;\n isValid: boolean;\n }) => ReactNode;\n /** settings for form debug mode */\n debugModeSettings?: DebugModeSettings;\n /** initial form values */\n initialValues?: FieldValues;\n /** form submit handler */\n onSubmit: SubmitHandler<FieldValues>;\n /** Veto validation schema instance */\n validation?: VetoInstance;\n /** when the validation should be triggered */\n validationTrigger: 'onChange' | 'onBlur' | 'onSubmit' | 'onTouched' | 'all';\n}\n\n/**\n * FormProvider component provides:\n * - Veto validation schema context\n * - Resolver-backed validation error state\n * - Client validation schema management\n * - Submit handler with automatic data conversion and submission control with preventSubmit\n * - Form Debug Mode state\n * - Form reset pub/sub notifications (`formReset`)\n * - User change pub/sub notifications (`userChange`)\n * - React Hook Form context\n */\nconst FormProvider: React.FC<FormProviderProps> = ({\n children,\n debugModeSettings = undefined,\n initialValues = undefined,\n onSubmit,\n validation: baseValidation = undefined,\n validationTrigger,\n}) => {\n // Form Debug mode state is handled in the form context\n const [debugMode, setDebugMode] = useLocalStorage<DebugMode>(\n debugModeSettings?.localStorageKey ?? DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT,\n 'off',\n );\n\n // Create extended validation combining base + client validations\n const { extendedValidation, setClientValidationSchema } =\n useExtendedValidation(baseValidation);\n\n // Create resolver from extended validation + reactive validation error state\n const { resolver, validationErrors, validationErrorsHash } =\n useFormResolver(extendedValidation);\n\n // Initialize react hook form with the resolver\n const methods = useForm({\n defaultValues: initialValues ? toFormFormat(initialValues) : initialValues,\n // set rhf mode\n // see: https://react-hook-form.com/docs/useform#mode\n mode: validationTrigger,\n resolver,\n });\n\n // Get isValid from React Hook Form's formState\n const isValid = methods.formState?.isValid;\n\n // Control if the form can currently be submitted\n const [preventSubmit, setPreventSubmit] = useState(false);\n\n // Form reset listener registry (stored in ref to avoid re-renders)\n const formResetListenersRef = useRef<Set<FormResetListener>>(new Set());\n\n // Subscribe to form reset notifications\n const subscribeFormReset = useCallback(\n (listener: FormResetListener): (() => void) => {\n formResetListenersRef.current.add(listener);\n return () => {\n formResetListenersRef.current.delete(listener);\n };\n },\n [],\n );\n\n // Notify all subscribers about a programmatic form reset\n const notifyFormReset = useCallback((): void => {\n formResetListenersRef.current.forEach((listener) => {\n listener();\n });\n }, []);\n\n // User change listener registry (stored in ref to avoid re-renders)\n const userChangeListenersRef = useRef<Set<UserChangeListener>>(new Set());\n\n // Subscribe to user changes\n const subscribeUserChange = useCallback(\n (listener: UserChangeListener): (() => void) => {\n userChangeListenersRef.current.add(listener);\n // Return cleanup function to unsubscribe\n return () => {\n userChangeListenersRef.current.delete(listener);\n };\n },\n [],\n );\n\n // Notify all subscribers about user change\n const notifyUserChange = useCallback(\n (fieldName: string, value: unknown): void => {\n // Notify all registered listeners\n userChangeListenersRef.current.forEach((listener) => {\n listener(fieldName as Path<object>, value);\n });\n },\n [],\n );\n\n // Create submit handler with automatic data conversion\n // eslint-disable-next-line consistent-return\n const handleSubmit = async (e?: React.BaseSyntheticEvent) => {\n debug('handleSubmit called', {\n preventSubmit,\n formStateIsValid: methods.formState.isValid,\n validationErrors: methods.formState.errors,\n validationTrigger,\n formValues: methods.getValues(),\n });\n\n // only prevent submit when form state is valid, because otherwise\n // submit will only trigger validation and add errors / focus invalid fields\n if (methods.formState.isValid && preventSubmit) {\n debug('⛔ Form submit PREVENTED', {\n formStateIsValid: methods.formState.isValid,\n preventSubmit,\n });\n console.warn(\n '[FormProvider] form submit was prevented because preventSubmit is true...',\n );\n e?.preventDefault();\n return Promise.resolve();\n }\n\n debug('✓ Form submit ALLOWED', {\n formStateIsValid: methods.formState.isValid,\n preventSubmit,\n reason: !methods.formState.isValid\n ? 'Form is invalid (will trigger validation and show errors)'\n : 'Form is valid and preventSubmit is false',\n });\n\n // Convert form data to submission format:\n // - Unwrap flat array wrappers and convert markers\n // - Remove empty strings, nulls, empty arrays, and empty objects\n const wrappedOnSubmit = (data: FieldValues, event?: BaseSyntheticEvent) => {\n const submitData = toSubmitFormat(data) ?? {};\n debug('onSubmit callback called', { submitData });\n return onSubmit(submitData, event);\n };\n\n await methods.handleSubmit(wrappedOnSubmit)(e);\n\n debug('handleSubmit completed');\n };\n\n // Memoize the context value so consumers only re-render when context-relevant\n // state changes, including resolver-backed validation errors.\n const contextValue = useMemo(\n () => {\n return {\n // set debugMode to disabled when debugModeSettings.disable is true\n // otherwise use current debug mode from localStorage\n debugMode: debugModeSettings?.disable ? 'disabled' : debugMode,\n preventSubmit: (prevent: boolean) => {\n debug('preventSubmit called', {\n previousValue: preventSubmit,\n newValue: prevent,\n formStateIsValid: methods.formState.isValid,\n validationErrors: methods.formState.errors,\n });\n setPreventSubmit(prevent);\n },\n setClientValidationSchema,\n setDebugMode,\n triggerSubmit: handleSubmit,\n formReset: {\n subscribe: subscribeFormReset,\n notify: notifyFormReset,\n },\n userChange: {\n subscribe: subscribeUserChange,\n notify: notifyUserChange,\n },\n validation: {\n baseInstance: baseValidation,\n instance: extendedValidation,\n errors: validationErrors,\n setClientValidationSchema,\n },\n };\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [debugMode, debugModeSettings?.disable, validationErrorsHash],\n );\n\n return (\n <UniformContext.Provider value={contextValue}>\n {/* Spread all hook form props into HookFormProvider */}\n <HookFormProvider {...methods}>\n {children({ handleSubmit, isValid })}\n </HookFormProvider>\n </UniformContext.Provider>\n );\n};\n\nexport default FormProvider;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqBA,MAAa,mCAAmC;CAE9C,MAAM,CAAC,yBAAyB,+BAAA,GAAA,MAAA,UAE9B,CAAC,CAAC;CAsBJ,OAAO;EACL;EACA,4BAAA,GAAA,MAAA,eArB8C;GAC9C,QAAQ,KAAa,WAA+B;IAElD,4BAA4B,SAAS;KAEnC,IAAI,CAAC,KAAK,QAAQ,CAAC,QACjB,OAAO;KAGT,IAAI,CAAC,QAAQ;MACX,MAAM,GAAG,MAAM,UAAU,GAAG,SAAS;MACrC,OAAO;KACT;KAEA,OAAO;MAAE,GAAG;OAAO,MAAM;KAAO;IAClC,CAAC;GACH;EACF,GAAG,CAAC,CAIsB;CAC1B;AACF;;;;;;;AAQA,MAAa,yBAAyB,mBAAkC;CAEtE,MAAM,EAAE,yBAAyB,8BAC/B,2BAA2B;CAG7B,MAAM,sBAAA,GAAA,MAAA,eACE;EAEJ,OADa,OAAO,KAAK,uBAAuB,EAAE,KACxC,EACP,KAAK,QAAQ;GACZ,OAAO,wBAAwB;EACjC,CAAC,EACA,QAAQ,WAAkC;GACzC,OAAO,QAAQ,MAAM;EACvB,CAAC;CACL,GAEA,CAAC,uBAAuB,CAC1B;CA+CA,OAAO;EACL,qBAAA,GAAA,MAAA,eA5CM;GACJ,MAAM,oBAAoB,CAAC,CAAC;GAC5B,MAAM,mBAAmB,mBAAmB,SAAS;GAGrD,IAAI,CAAC,qBAAqB,CAAC,kBACzB;GAIF,IAAI,CAAC,kBACH,OAAO;GAIT,MAAM,wBACJ,mBAAmB,QAChB,UAAU,iBAAiB;IAC1B,OAAO,YAAA,GAAA,gBAAA,KAAe,UAAU,YAAY,IAAI;G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KACpC,kBAAkB,QAAQ,UAAU;IACtC,CAAC;IACD,iBAAiB,OAAO;GAC1B;GACA;GACA;GACA,eAAe;GACf,WAAW;IACT,WAAW;IACX,QAAQ;GACV;GACA,YAAY;IACV,WAAW;IACX,QAAQ;GACV;GACA,YAAY;IACV,cAAc;IACd,UAAU;IACV,QAAQ;IACR;GACF;EACF;CACF,GAEA;EAAC;EAAW,mBAAmB;EAAS;CAAoB,CAC9D;CAEA,OACE,iBAAA,GAAA,kBAAA,KAAC,eAAe,UAAhB;EAAyB,OAAO;YAE9B,iBAAA,GAAA,kBAAA,KAACC,gBAAAA,cAAD;GAAkB,GAAI;aACnB,SAAS;IAAE;IAAc;GAAQ,CAAC;EACnB,CAAA;CACK,CAAA;AAE7B"}
|
|
@@ -9,10 +9,12 @@ interface DebugModeSettings {
|
|
|
9
9
|
/** custom localStorage key to save debug mode state */
|
|
10
10
|
localStorageKey?: string;
|
|
11
11
|
}
|
|
12
|
+
/** Listener function that gets called when a form reset is triggered */
|
|
13
|
+
type FormResetListener = () => void;
|
|
12
14
|
/**
|
|
13
15
|
* Listener function that gets called when a field changes due to user input
|
|
14
16
|
*/
|
|
15
17
|
type UserChangeListener<TFieldValues extends object = object> = (fieldName: Path<TFieldValues>, value: unknown) => void;
|
|
16
18
|
//#endregion
|
|
17
|
-
export {
|
|
18
|
-
//# sourceMappingURL=FormContext-
|
|
19
|
+
export { FormResetListener as n, UserChangeListener as r, DebugModeSettings as t };
|
|
20
|
+
//# sourceMappingURL=FormContext-i66vM5f1.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"FormContext-i66vM5f1.d.ts","names":[],"sources":["../src/Form/subcomponents/FormContext.tsx"],"mappings":";;;;;UAsBiB,iBAAA;EAAiB;EAEhC,OAAA;EAAA;EAEA,eAAe;AAAA;;KAIL,iBAAA;;AAAiB;AAK7B;KAAY,kBAAA,0CACV,SAAA,EAAW,IAAI,CAAC,YAAA,GAChB,KAAA"}
|
package/dist/Grid/index.cjs
CHANGED
|
@@ -2,6 +2,6 @@ Object.defineProperties(exports, {
|
|
|
2
2
|
__esModule: { value: true },
|
|
3
3
|
[Symbol.toStringTag]: { value: "Module" }
|
|
4
4
|
});
|
|
5
|
-
const require_Grid = require("../Grid-
|
|
5
|
+
const require_Grid = require("../Grid-D-VcRGi9.cjs");
|
|
6
6
|
exports.Grid = require_Grid.Grid;
|
|
7
7
|
exports.default = require_Grid.Grid_default;
|