@fuf-stack/uniform 1.6.5 → 1.8.0
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 +13 -11
- package/dist/Checkboxes/index.cjs.map +1 -1
- package/dist/Checkboxes/index.d.cts +3 -2
- package/dist/Checkboxes/index.d.ts +3 -2
- package/dist/Checkboxes/index.js +12 -10
- package/dist/{Checkboxes-CR0Uu2g9.d.ts → Checkboxes-CDjOYw76.d.cts} +3 -0
- package/dist/{Checkboxes-CR0Uu2g9.d.cts → Checkboxes-wWzFP2sn.d.ts} +3 -0
- package/dist/FieldArray/index.cjs +13 -11
- package/dist/FieldArray/index.cjs.map +1 -1
- package/dist/FieldArray/index.js +12 -10
- package/dist/Form/index.cjs +13 -11
- package/dist/Form/index.cjs.map +1 -1
- package/dist/Form/index.d.cts +3 -3
- package/dist/Form/index.d.ts +3 -3
- package/dist/Form/index.js +12 -10
- package/dist/{Form-Cu0lWRDN.d.cts → Form-BZZJPLsi.d.cts} +1 -1
- package/dist/{Form-C_11i6PA.d.ts → Form-zsUjI2yq.d.ts} +1 -1
- package/dist/FormContext-9Firwt4k.d.cts +14 -0
- package/dist/FormContext-9Firwt4k.d.ts +14 -0
- package/dist/Input/index.cjs +13 -11
- package/dist/Input/index.cjs.map +1 -1
- package/dist/Input/index.d.cts +2 -2
- package/dist/Input/index.d.ts +2 -2
- package/dist/Input/index.js +12 -10
- package/dist/{Input-CCIEnvIp.d.ts → Input-BcdS2xBM.d.ts} +2 -2
- package/dist/{Input-D7HT_8jf.d.cts → Input-DMVTcinm.d.cts} +2 -2
- package/dist/RadioBoxes/index.cjs +13 -11
- package/dist/RadioBoxes/index.cjs.map +1 -1
- package/dist/RadioBoxes/index.js +12 -10
- package/dist/RadioTabs/index.cjs +13 -11
- package/dist/RadioTabs/index.cjs.map +1 -1
- package/dist/RadioTabs/index.js +12 -10
- package/dist/Radios/index.cjs +13 -11
- package/dist/Radios/index.cjs.map +1 -1
- package/dist/Radios/index.js +12 -10
- package/dist/Select/index.cjs +13 -11
- package/dist/Select/index.cjs.map +1 -1
- package/dist/Select/index.js +12 -10
- package/dist/SubmitButton/index.cjs +13 -11
- package/dist/SubmitButton/index.cjs.map +1 -1
- package/dist/SubmitButton/index.js +12 -10
- package/dist/Switch/index.cjs +13 -11
- package/dist/Switch/index.cjs.map +1 -1
- package/dist/Switch/index.js +12 -10
- package/dist/TextArea/index.cjs +13 -11
- package/dist/TextArea/index.cjs.map +1 -1
- package/dist/TextArea/index.js +12 -10
- package/dist/{chunk-HANR2BDX.cjs → chunk-4CWB5XBW.cjs} +5 -5
- package/dist/{chunk-HANR2BDX.cjs.map → chunk-4CWB5XBW.cjs.map} +1 -1
- package/dist/chunk-4F45XA7Y.cjs +26 -0
- package/dist/chunk-4F45XA7Y.cjs.map +1 -0
- package/dist/{chunk-42NCLEX4.cjs → chunk-4L3JXJ62.cjs} +35 -104
- package/dist/chunk-4L3JXJ62.cjs.map +1 -0
- package/dist/{chunk-RI45RSNN.js → chunk-4TQ53WAY.js} +2 -2
- package/dist/{chunk-4WYC2RBE.cjs → chunk-56TQOKG7.cjs} +6 -3
- package/dist/chunk-56TQOKG7.cjs.map +1 -0
- package/dist/{chunk-4Z7LIJHZ.cjs → chunk-6F5EZ6QN.cjs} +3 -3
- package/dist/{chunk-4Z7LIJHZ.cjs.map → chunk-6F5EZ6QN.cjs.map} +1 -1
- package/dist/chunk-6LQ2O6SC.cjs +115 -0
- package/dist/chunk-6LQ2O6SC.cjs.map +1 -0
- package/dist/{chunk-JMFDNTVC.cjs → chunk-7KEUEGRC.cjs} +9 -2
- package/dist/chunk-7KEUEGRC.cjs.map +1 -0
- package/dist/{chunk-HBVHOUAR.js → chunk-BUJNCVUR.js} +3 -3
- package/dist/{chunk-7KLFK2IT.js → chunk-CNTOODUQ.js} +6 -3
- package/dist/chunk-CNTOODUQ.js.map +1 -0
- package/dist/{chunk-CMTSX5UA.cjs → chunk-EB3RNELT.cjs} +6 -4
- package/dist/chunk-EB3RNELT.cjs.map +1 -0
- package/dist/{chunk-D3JYMGTB.js → chunk-EGFB5WEK.js} +47 -37
- package/dist/chunk-EGFB5WEK.js.map +1 -0
- package/dist/{chunk-AAGOHXSZ.js → chunk-EUO4VWRX.js} +2 -2
- package/dist/{chunk-D3EZXJQH.cjs → chunk-EUTTXFWA.cjs} +3 -3
- package/dist/{chunk-D3EZXJQH.cjs.map → chunk-EUTTXFWA.cjs.map} +1 -1
- package/dist/{chunk-QAQ3UP7W.cjs → chunk-FFGFPXNE.cjs} +3 -3
- package/dist/{chunk-QAQ3UP7W.cjs.map → chunk-FFGFPXNE.cjs.map} +1 -1
- package/dist/{chunk-X37C4SVI.js → chunk-FND5Z5BW.js} +4 -7
- package/dist/{chunk-X37C4SVI.js.map → chunk-FND5Z5BW.js.map} +1 -1
- package/dist/{chunk-4RIJJ5AV.js → chunk-GEJUMUTH.js} +55 -41
- package/dist/chunk-GEJUMUTH.js.map +1 -0
- package/dist/{chunk-CK362NWK.js → chunk-GKP3ONKO.js} +9 -2
- package/dist/chunk-GKP3ONKO.js.map +1 -0
- package/dist/{chunk-VDTYZM6N.cjs → chunk-IFBKJ5UZ.cjs} +6 -9
- package/dist/chunk-IFBKJ5UZ.cjs.map +1 -0
- package/dist/{chunk-IK5IWKUC.js → chunk-K33E67GR.js} +6 -6
- package/dist/{chunk-R6IWQWZ6.js → chunk-KGN5JQGG.js} +5 -3
- package/dist/{chunk-R6IWQWZ6.js.map → chunk-KGN5JQGG.js.map} +1 -1
- package/dist/{chunk-M7TOCXYB.js → chunk-KQQAESO7.js} +3 -3
- package/dist/chunk-KWJMKX5J.cjs +1 -0
- package/dist/{chunk-LTKRK3OS.cjs.map → chunk-KWJMKX5J.cjs.map} +1 -1
- package/dist/{chunk-NZ54JBSR.js → chunk-LKR6D3RL.js} +36 -105
- package/dist/chunk-LKR6D3RL.js.map +1 -0
- package/dist/{chunk-65UJEB4P.js → chunk-N24A7PIL.js} +2 -2
- package/dist/{chunk-BZ5OMN4Y.cjs → chunk-NTOYCWCJ.cjs} +12 -26
- package/dist/chunk-NTOYCWCJ.cjs.map +1 -0
- package/dist/{chunk-4ATOAQOF.cjs → chunk-OJGPW4Z6.cjs} +3 -3
- package/dist/{chunk-4ATOAQOF.cjs.map → chunk-OJGPW4Z6.cjs.map} +1 -1
- package/dist/{chunk-SOQ6GCN3.cjs → chunk-OQUTHTOK.cjs} +48 -38
- package/dist/chunk-OQUTHTOK.cjs.map +1 -0
- package/dist/chunk-PY4GCAFN.js +26 -0
- package/dist/chunk-PY4GCAFN.js.map +1 -0
- package/dist/{chunk-V3NNJJHY.cjs → chunk-S3H432Z2.cjs} +3 -3
- package/dist/{chunk-V3NNJJHY.cjs.map → chunk-S3H432Z2.cjs.map} +1 -1
- package/dist/{chunk-TB5WXGWX.js → chunk-SWPFSD3Y.js} +9 -27
- package/dist/chunk-SWPFSD3Y.js.map +1 -0
- package/dist/{chunk-HX2JJ2ZK.cjs → chunk-TJY5FK4B.cjs} +8 -8
- package/dist/{chunk-HX2JJ2ZK.cjs.map → chunk-TJY5FK4B.cjs.map} +1 -1
- package/dist/chunk-U45RW4FC.js +115 -0
- package/dist/chunk-U45RW4FC.js.map +1 -0
- package/dist/{chunk-NM66XFQH.js → chunk-UEOED4GU.js} +2 -2
- package/dist/{chunk-3NNANHVC.cjs → chunk-UT6VUGFP.cjs} +6 -6
- package/dist/{chunk-3NNANHVC.cjs.map → chunk-UT6VUGFP.cjs.map} +1 -1
- package/dist/chunk-V3GDAELU.js +1 -0
- package/dist/{chunk-I5RBXUIV.js → chunk-VUW522KH.js} +2 -2
- package/dist/{chunk-NUGEM725.js → chunk-WWGKXYZB.js} +2 -2
- package/dist/{chunk-PC3VCEGM.cjs → chunk-ZEJ45LLM.cjs} +3 -3
- package/dist/{chunk-PC3VCEGM.cjs.map → chunk-ZEJ45LLM.cjs.map} +1 -1
- package/dist/{chunk-HEGORLRF.cjs → chunk-ZFZK6EM2.cjs} +10 -28
- package/dist/chunk-ZFZK6EM2.cjs.map +1 -0
- package/dist/{chunk-MODD3TFE.js → chunk-ZJDU5EPE.js} +12 -26
- package/dist/chunk-ZJDU5EPE.js.map +1 -0
- package/dist/{chunk-7NZVPVK3.cjs → chunk-ZLTMRO6X.cjs} +56 -42
- package/dist/chunk-ZLTMRO6X.cjs.map +1 -0
- package/dist/hooks/index.cjs +17 -12
- package/dist/hooks/index.cjs.map +1 -1
- package/dist/hooks/index.d.cts +2 -1
- package/dist/hooks/index.d.ts +2 -1
- package/dist/hooks/index.js +17 -12
- package/dist/hooks/useClientValidation/index.cjs +4 -3
- package/dist/hooks/useClientValidation/index.cjs.map +1 -1
- package/dist/hooks/useClientValidation/index.js +3 -2
- package/dist/hooks/useController/index.cjs +3 -2
- package/dist/hooks/useController/index.cjs.map +1 -1
- package/dist/hooks/useController/index.d.cts +1 -0
- package/dist/hooks/useController/index.d.ts +1 -0
- package/dist/hooks/useController/index.js +2 -1
- package/dist/hooks/useFormContext/index.cjs +3 -2
- package/dist/hooks/useFormContext/index.cjs.map +1 -1
- package/dist/hooks/useFormContext/index.d.cts +5 -1
- package/dist/hooks/useFormContext/index.d.ts +5 -1
- package/dist/hooks/useFormContext/index.js +2 -1
- package/dist/hooks/useInputValueDebounce/index.cjs +2 -3
- package/dist/hooks/useInputValueDebounce/index.cjs.map +1 -1
- package/dist/hooks/useInputValueDebounce/index.d.cts +17 -52
- package/dist/hooks/useInputValueDebounce/index.d.ts +17 -52
- package/dist/hooks/useInputValueDebounce/index.js +1 -2
- package/dist/hooks/useInputValueTransform/index.cjs +2 -2
- package/dist/hooks/useInputValueTransform/index.d.cts +31 -13
- package/dist/hooks/useInputValueTransform/index.d.ts +31 -13
- package/dist/hooks/useInputValueTransform/index.js +1 -1
- package/dist/hooks/useUniformField/index.cjs +7 -5
- package/dist/hooks/useUniformField/index.cjs.map +1 -1
- package/dist/hooks/useUniformField/index.d.cts +16 -5
- package/dist/hooks/useUniformField/index.d.ts +16 -5
- package/dist/hooks/useUniformField/index.js +6 -4
- package/dist/hooks/useUniformFieldArray/index.cjs +8 -6
- package/dist/hooks/useUniformFieldArray/index.cjs.map +1 -1
- package/dist/hooks/useUniformFieldArray/index.d.cts +2 -2
- package/dist/hooks/useUniformFieldArray/index.d.ts +2 -2
- package/dist/hooks/useUniformFieldArray/index.js +7 -5
- package/dist/hooks/useWatchUserChange/index.cjs +11 -0
- package/dist/hooks/useWatchUserChange/index.cjs.map +1 -0
- package/dist/hooks/useWatchUserChange/index.d.cts +73 -0
- package/dist/hooks/useWatchUserChange/index.d.ts +73 -0
- package/dist/hooks/useWatchUserChange/index.js +11 -0
- package/dist/hooks/useWatchUserChange/index.js.map +1 -0
- package/dist/index.cjs +26 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +29 -24
- package/package.json +9 -3
- package/dist/FormContext-LRho0tno.d.cts +0 -8
- package/dist/FormContext-LRho0tno.d.ts +0 -8
- package/dist/chunk-35V726MB.js +0 -1
- package/dist/chunk-42NCLEX4.cjs.map +0 -1
- package/dist/chunk-4RIJJ5AV.js.map +0 -1
- package/dist/chunk-4WYC2RBE.cjs.map +0 -1
- package/dist/chunk-7KLFK2IT.js.map +0 -1
- package/dist/chunk-7NZVPVK3.cjs.map +0 -1
- package/dist/chunk-BZ5OMN4Y.cjs.map +0 -1
- package/dist/chunk-CK362NWK.js.map +0 -1
- package/dist/chunk-CMTSX5UA.cjs.map +0 -1
- package/dist/chunk-D3JYMGTB.js.map +0 -1
- package/dist/chunk-HEGORLRF.cjs.map +0 -1
- package/dist/chunk-JMFDNTVC.cjs.map +0 -1
- package/dist/chunk-LTKRK3OS.cjs +0 -1
- package/dist/chunk-MODD3TFE.js.map +0 -1
- package/dist/chunk-NZ54JBSR.js.map +0 -1
- package/dist/chunk-SOQ6GCN3.cjs.map +0 -1
- package/dist/chunk-TB5WXGWX.js.map +0 -1
- package/dist/chunk-VDTYZM6N.cjs.map +0 -1
- /package/dist/{chunk-RI45RSNN.js.map → chunk-4TQ53WAY.js.map} +0 -0
- /package/dist/{chunk-HBVHOUAR.js.map → chunk-BUJNCVUR.js.map} +0 -0
- /package/dist/{chunk-AAGOHXSZ.js.map → chunk-EUO4VWRX.js.map} +0 -0
- /package/dist/{chunk-IK5IWKUC.js.map → chunk-K33E67GR.js.map} +0 -0
- /package/dist/{chunk-M7TOCXYB.js.map → chunk-KQQAESO7.js.map} +0 -0
- /package/dist/{chunk-65UJEB4P.js.map → chunk-N24A7PIL.js.map} +0 -0
- /package/dist/{chunk-NM66XFQH.js.map → chunk-UEOED4GU.js.map} +0 -0
- /package/dist/{chunk-35V726MB.js.map → chunk-V3GDAELU.js.map} +0 -0
- /package/dist/{chunk-I5RBXUIV.js.map → chunk-VUW522KH.js.map} +0 -0
- /package/dist/{chunk-NUGEM725.js.map → chunk-WWGKXYZB.js.map} +0 -0
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import {
|
|
2
2
|
useInputValueDebounce
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ZJDU5EPE.js";
|
|
4
4
|
import {
|
|
5
5
|
useUniformField
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-EGFB5WEK.js";
|
|
7
7
|
import {
|
|
8
8
|
__objRest,
|
|
9
|
+
__spreadProps,
|
|
9
10
|
__spreadValues
|
|
10
11
|
} from "./chunk-K2V4ULA2.js";
|
|
11
12
|
|
|
12
13
|
// src/Input/Input.tsx
|
|
13
14
|
import { Input as HeroInput } from "@heroui/input";
|
|
15
|
+
import { NumberInput as HeroNumberInput } from "@heroui/number-input";
|
|
14
16
|
import { tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
|
|
15
17
|
import { jsx } from "react/jsx-runtime";
|
|
16
18
|
var inputVariants = tv({
|
|
@@ -36,7 +38,6 @@ var Input = (_a) => {
|
|
|
36
38
|
placeholder = " ",
|
|
37
39
|
size = void 0,
|
|
38
40
|
startContent = void 0,
|
|
39
|
-
transform = void 0,
|
|
40
41
|
type = void 0
|
|
41
42
|
} = _b, uniformFieldProps = __objRest(_b, [
|
|
42
43
|
"className",
|
|
@@ -48,7 +49,6 @@ var Input = (_a) => {
|
|
|
48
49
|
"placeholder",
|
|
49
50
|
"size",
|
|
50
51
|
"startContent",
|
|
51
|
-
"transform",
|
|
52
52
|
"type"
|
|
53
53
|
]);
|
|
54
54
|
const {
|
|
@@ -65,13 +65,11 @@ var Input = (_a) => {
|
|
|
65
65
|
required,
|
|
66
66
|
testId,
|
|
67
67
|
resetField
|
|
68
|
-
} = useUniformField(__spreadValues({ name }, uniformFieldProps));
|
|
68
|
+
} = useUniformField(__spreadValues({ name, type }, uniformFieldProps));
|
|
69
69
|
const { onChange, onBlur, value } = useInputValueDebounce({
|
|
70
70
|
debounceDelay,
|
|
71
71
|
onBlur: fieldOnBlur,
|
|
72
72
|
onChange: fieldOnChange,
|
|
73
|
-
transform,
|
|
74
|
-
type,
|
|
75
73
|
value: fieldValue
|
|
76
74
|
});
|
|
77
75
|
const clearableProps = clearable ? {
|
|
@@ -85,39 +83,55 @@ var Input = (_a) => {
|
|
|
85
83
|
} : {};
|
|
86
84
|
const variants = inputVariants();
|
|
87
85
|
const classNames = variantsToClassNames(variants, _className, "base");
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
86
|
+
const commonProps = __spreadValues({
|
|
87
|
+
ref,
|
|
88
|
+
classNames: {
|
|
89
|
+
base: classNames.base,
|
|
90
|
+
clearButton: classNames.clearButton,
|
|
91
|
+
// set padding to 0 for error message exit animation
|
|
92
|
+
helperWrapper: "p-0",
|
|
93
|
+
input: classNames.input,
|
|
94
|
+
inputWrapper: classNames.inputWrapper
|
|
95
|
+
},
|
|
96
|
+
"data-testid": testId,
|
|
97
|
+
endContent,
|
|
98
|
+
errorMessage,
|
|
99
|
+
id: testId,
|
|
100
|
+
isDisabled: disabled,
|
|
101
|
+
isInvalid: invalid,
|
|
102
|
+
isRequired: required,
|
|
103
|
+
label,
|
|
104
|
+
labelPlacement: "outside",
|
|
105
|
+
name,
|
|
106
|
+
onBlur,
|
|
107
|
+
placeholder,
|
|
108
|
+
radius: "sm",
|
|
109
|
+
size,
|
|
110
|
+
startContent,
|
|
111
|
+
variant: "bordered"
|
|
112
|
+
}, clearableProps);
|
|
113
|
+
if (type === "number") {
|
|
114
|
+
const numberValue = value !== "" && value != null && !Number.isNaN(Number(value)) ? Number(value) : void 0;
|
|
115
|
+
return /* @__PURE__ */ jsx(
|
|
116
|
+
HeroNumberInput,
|
|
117
|
+
__spreadProps(__spreadValues({}, commonProps), {
|
|
118
|
+
value: numberValue,
|
|
119
|
+
formatOptions: {
|
|
120
|
+
useGrouping: false
|
|
121
|
+
},
|
|
122
|
+
onChange: (e) => {
|
|
123
|
+
if (typeof e === "number") {
|
|
124
|
+
onChange({
|
|
125
|
+
target: { value: String(e) }
|
|
126
|
+
});
|
|
127
|
+
} else {
|
|
128
|
+
onChange(e);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
})
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
return /* @__PURE__ */ jsx(HeroInput, __spreadProps(__spreadValues({}, commonProps), { onChange, type, value }));
|
|
121
135
|
};
|
|
122
136
|
var Input_default = Input;
|
|
123
137
|
|
|
@@ -128,4 +142,4 @@ export {
|
|
|
128
142
|
Input_default,
|
|
129
143
|
Input_default2
|
|
130
144
|
};
|
|
131
|
-
//# sourceMappingURL=chunk-
|
|
145
|
+
//# sourceMappingURL=chunk-GEJUMUTH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Input/Input.tsx","../src/Input/index.ts"],"sourcesContent":["import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\nimport type { InputProps as HeroInputProps } from '@heroui/input';\nimport type { ReactNode } from 'react';\nimport type { InputValueTransform } from '../hooks';\n\nimport { Input as HeroInput } from '@heroui/input';\n// eslint-disable-next-line import-x/no-unresolved\nimport { NumberInput as HeroNumberInput } from '@heroui/number-input';\n\nimport { tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { useInputValueDebounce, useUniformField } from '../hooks';\n\n// input variants\nexport const inputVariants = tv({\n slots: {\n /** wrapper around the whole input */\n base: '',\n /** clear button */\n clearButton: '',\n /** actual input element */\n input: '',\n /** inner wrapper (HeroUI inputWrapper slot) */\n inputWrapper: 'bg-content1 group-data-[focus=true]:border-focus',\n },\n});\n\ntype VariantProps = TVProps<typeof inputVariants>;\ntype ClassName = TVClassName<typeof inputVariants>;\n\nexport interface InputProps extends VariantProps {\n /** CSS class name */\n className?: ClassName;\n /** shows clear button when input has value */\n clearable?: boolean;\n /** debounce delay in milliseconds for form state updates (default: 300ms) */\n debounceDelay?: number;\n /** input field is disabled */\n disabled?: boolean;\n /** added content to the end of the input Field. */\n endContent?: ReactNode;\n /** form field label (set to false to disable label) */\n label?: string | false;\n /** form field name */\n name: string;\n /** callback that is fired when the value is cleared */\n onClear?: () => void;\n /** form field placeholder */\n placeholder?: string;\n /** size of the input */\n size?: 'sm' | 'md' | 'lg';\n /** content added to the start of the input field */\n startContent?: ReactNode;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** allows disentangled display and form values for a field */\n transform?: InputValueTransform<string>;\n /** input type */\n type?: 'number' | 'password';\n}\n\n/**\n * Input component based on [HeroUI Input](https://www.heroui.com//docs/components/input)\n */\nconst Input = ({\n className: _className = undefined,\n clearable = false,\n debounceDelay = 300,\n endContent = undefined,\n name,\n onClear = undefined,\n placeholder = ' ',\n size = undefined,\n startContent = undefined,\n type = undefined,\n ...uniformFieldProps\n}: InputProps) => {\n const {\n disabled,\n field: {\n onChange: fieldOnChange,\n onBlur: fieldOnBlur,\n value: fieldValue,\n ref,\n },\n errorMessage,\n invalid,\n label,\n required,\n testId,\n resetField,\n } = useUniformField({ name, type, ...uniformFieldProps });\n\n // Use hook that provides debounced onChange and enhanced blur handling\n const { onChange, onBlur, value } = useInputValueDebounce({\n debounceDelay,\n onBlur: fieldOnBlur,\n onChange: fieldOnChange,\n value: fieldValue,\n });\n\n // If input is clearable add props for clearing input value\n const clearableProps: Pick<HeroInputProps, 'isClearable' | 'onClear'> =\n clearable\n ? {\n isClearable: true,\n onClear: () => {\n // if field had initial value we do not reset it\n // to that value, but clear it instead\n resetField(name, { defaultValue: null });\n // if onClear cb provided we call it\n if (onClear) {\n onClear();\n }\n },\n }\n : {};\n\n // classNames from slots\n const variants = inputVariants();\n const classNames = variantsToClassNames(variants, _className, 'base');\n\n // Common props for both Input and NumberInput\n const commonProps = {\n ref,\n classNames: {\n base: classNames.base,\n clearButton: classNames.clearButton,\n // set padding to 0 for error message exit animation\n helperWrapper: 'p-0',\n input: classNames.input,\n inputWrapper: classNames.inputWrapper,\n },\n 'data-testid': testId,\n endContent,\n errorMessage,\n id: testId,\n isDisabled: disabled,\n isInvalid: invalid,\n isRequired: required,\n label,\n labelPlacement: 'outside' as const,\n name,\n onBlur,\n placeholder,\n radius: 'sm' as const,\n size,\n startContent,\n variant: 'bordered' as const,\n ...clearableProps,\n };\n\n // Render NumberInput for number type\n if (type === 'number') {\n // Parse the string value to number - use undefined for empty/cleared state\n const numberValue =\n value !== '' && value != null && !Number.isNaN(Number(value))\n ? Number(value)\n : undefined;\n\n return (\n <HeroNumberInput\n {...commonProps}\n value={numberValue}\n // Disable thousands separator to avoid parsing issues\n formatOptions={{\n useGrouping: false,\n }}\n // NumberInput onChange receives either an event or a number\n onChange={(e: React.ChangeEvent<HTMLInputElement> | number) => {\n if (typeof e === 'number') {\n // Convert number to synthetic event and pass through debounced onChange\n onChange({\n target: { value: String(e) },\n } as React.ChangeEvent<HTMLInputElement>);\n } else {\n // Pass event through debounced onChange\n onChange(e);\n }\n }}\n />\n );\n }\n\n // Render regular Input for text/password\n return (\n <HeroInput {...commonProps} onChange={onChange} type={type} value={value} />\n );\n};\n\nexport default Input;\n","import Input from './Input';\n\nexport type { InputProps } from './Input';\n\nexport { Input };\n\nexport default Input;\n"],"mappings":";;;;;;;;;;;;;AAKA,SAAS,SAAS,iBAAiB;AAEnC,SAAS,eAAe,uBAAuB;AAE/C,SAAS,IAAI,4BAA4B;AAwJnC;AAnJC,IAAM,gBAAgB,GAAG;AAAA,EAC9B,OAAO;AAAA;AAAA,IAEL,MAAM;AAAA;AAAA,IAEN,aAAa;AAAA;AAAA,IAEb,OAAO;AAAA;AAAA,IAEP,cAAc;AAAA,EAChB;AACF,CAAC;AAuCD,IAAM,QAAQ,CAAC,OAYG;AAZH,eACb;AAAA,eAAW,aAAa;AAAA,IACxB,YAAY;AAAA,IACZ,gBAAgB;AAAA,IAChB,aAAa;AAAA,IACb;AAAA,IACA,UAAU;AAAA,IACV,cAAc;AAAA,IACd,OAAO;AAAA,IACP,eAAe;AAAA,IACf,OAAO;AAAA,EA1ET,IAgEe,IAWV,8BAXU,IAWV;AAAA,IAVH;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAGA,QAAM;AAAA,IACJ;AAAA,IACA,OAAO;AAAA,MACL,UAAU;AAAA,MACV,QAAQ;AAAA,MACR,OAAO;AAAA,MACP;AAAA,IACF;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IA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1C,OAAO;AAEL,qBAAS,CAAC;AAAA,UACZ;AAAA,QACF;AAAA;AAAA,IACF;AAAA,EAEJ;AAGA,SACE,oBAAC,4CAAc,cAAd,EAA2B,UAAoB,MAAY,QAAc;AAE9E;AAEA,IAAO,gBAAQ;;;ACxLf,IAAOA,iBAAQ;","names":["Input_default"]}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import {
|
|
2
|
+
UniformContext
|
|
3
|
+
} from "./chunk-LKR6D3RL.js";
|
|
1
4
|
import {
|
|
2
5
|
fromNullishString,
|
|
3
6
|
toNullishString
|
|
@@ -8,9 +11,11 @@ import {
|
|
|
8
11
|
} from "./chunk-K2V4ULA2.js";
|
|
9
12
|
|
|
10
13
|
// src/hooks/useController/useController.ts
|
|
14
|
+
import { useContext } from "react";
|
|
11
15
|
import { useController as useRHFController } from "react-hook-form";
|
|
12
16
|
var useController = (props) => {
|
|
13
17
|
const { field, formState, fieldState } = useRHFController(props);
|
|
18
|
+
const { userChange } = useContext(UniformContext);
|
|
14
19
|
return {
|
|
15
20
|
field: __spreadProps(__spreadValues({}, field), {
|
|
16
21
|
// Handles both direct values (onChange("value")) and events (onChange(event))
|
|
@@ -18,7 +23,9 @@ var useController = (props) => {
|
|
|
18
23
|
onChange: (...event) => {
|
|
19
24
|
var _a, _b, _c;
|
|
20
25
|
const value = (_c = (_b = (_a = event[0]) == null ? void 0 : _a.target) == null ? void 0 : _b.value) != null ? _c : event[0];
|
|
21
|
-
|
|
26
|
+
const formattedValue = value === "" ? "" : toNullishString(value);
|
|
27
|
+
field.onChange(formattedValue);
|
|
28
|
+
userChange.notify(field.name, formattedValue);
|
|
22
29
|
},
|
|
23
30
|
// Convert null/undefined to empty string for UI display
|
|
24
31
|
value: fromNullishString(field.value)
|
|
@@ -31,4 +38,4 @@ var useController = (props) => {
|
|
|
31
38
|
export {
|
|
32
39
|
useController
|
|
33
40
|
};
|
|
34
|
-
//# sourceMappingURL=chunk-
|
|
41
|
+
//# sourceMappingURL=chunk-GKP3ONKO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/hooks/useController/useController.ts"],"sourcesContent":["import type {\n ControllerFieldState,\n ControllerRenderProps,\n UseControllerProps as RHFUseControllerProps,\n UseFormStateReturn,\n} from 'react-hook-form';\n\nimport { useContext } from 'react';\nimport { useController as useRHFController } from 'react-hook-form';\n\nimport { UniformContext } from '../../Form/subcomponents/FormContext';\nimport { fromNullishString, toNullishString } from '../../helpers';\n\nexport type UseControllerProps<TFieldValues extends object = object> =\n RHFUseControllerProps<TFieldValues>;\n\nexport interface UseControllerReturn<TFieldValues extends object = object> {\n field: Omit<ControllerRenderProps<TFieldValues>, 'onChange' | 'value'> & {\n // Using any[] to support both direct value changes and React synthetic events\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => void;\n value: string;\n };\n formState: UseFormStateReturn<TFieldValues>;\n fieldState: ControllerFieldState;\n}\n\n/**\n * A wrapper around react-hook-form's useController that transparently handles nullish string conversions.\n *\n * Key features:\n * 1. Empty strings ('') in the UI are stored as null in form state\n * 2. Null/undefined values in form state are displayed as empty strings in the UI\n * 3. Handles both direct value changes and React synthetic events\n * 4. Maintains the same API as react-hook-form's useController\n * 5. Notifies UniformContext's userChange listeners on field changes (enables useWatchUserChange hook)\n *\n * This enables consistent handling of empty/null values while keeping a clean API\n * for form inputs that expect string values.\n *\n * @see https://react-hook-form.com/docs/usecontroller\n */\nexport const useController = <TFieldValues extends object = object>(\n props: UseControllerProps<TFieldValues>,\n): UseControllerReturn<TFieldValues> => {\n const { field, formState, fieldState } = useRHFController(props);\n const { userChange } = useContext(UniformContext);\n\n return {\n field: {\n ...field,\n // Handles both direct values (onChange(\"value\")) and events (onChange(event))\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n onChange: (...event: any[]) => {\n const value = event[0]?.target?.value ?? event[0];\n const formattedValue = value === '' ? '' : toNullishString(value);\n\n // Update form state first\n field.onChange(formattedValue);\n\n // Then notify userChange listeners (for useWatchUserChange hook)\n // This ensures getValues() in listeners returns the updated value\n userChange.notify(field.name, formattedValue);\n },\n // Convert null/undefined to empty string for UI display\n value: fromNullishString(field.value) as string,\n },\n formState,\n fieldState,\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAOA,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB,wBAAwB;AAkC3C,IAAM,gBAAgB,CAC3B,UACsC;AACtC,QAAM,EAAE,OAAO,WAAW,WAAW,IAAI,iBAAiB,KAAK;AAC/D,QAAM,EAAE,WAAW,IAAI,WAAW,cAAc;AAEhD,SAAO;AAAA,IACL,OAAO,iCACF,QADE;AAAA;AAAA;AAAA,MAIL,UAAU,IAAI,UAAiB;AArDrC;AAsDQ,cAAM,SAAQ,uBAAM,CAAC,MAAP,mBAAU,WAAV,mBAAkB,UAAlB,YAA2B,MAAM,CAAC;AAChD,cAAM,iBAAiB,UAAU,KAAK,KAAK,gBAAgB,KAAK;AAGhE,cAAM,SAAS,cAAc;AAI7B,mBAAW,OAAO,MAAM,MAAM,cAAc;AAAA,MAC9C;AAAA;AAAA,MAEA,OAAO,kBAAkB,MAAM,KAAK;AAAA,IACtC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkOQUTHTOKcjs = require('./chunk-OQUTHTOK.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunk6LQ2O6SCcjs = require('./chunk-6LQ2O6SC.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkZ353BLWIcjs = require('./chunk-Z353BLWI.cjs');
|
|
@@ -24,7 +24,7 @@ var useUniformFieldArray = ({
|
|
|
24
24
|
testId: explicitTestId,
|
|
25
25
|
label
|
|
26
26
|
}) => {
|
|
27
|
-
const uniformField =
|
|
27
|
+
const uniformField = _chunkOQUTHTOKcjs.useUniformField.call(void 0, {
|
|
28
28
|
name,
|
|
29
29
|
disabled,
|
|
30
30
|
testId: explicitTestId,
|
|
@@ -35,7 +35,7 @@ var useUniformFieldArray = ({
|
|
|
35
35
|
control,
|
|
36
36
|
name
|
|
37
37
|
});
|
|
38
|
-
const { trigger, setValue } =
|
|
38
|
+
const { trigger, setValue } = _chunk6LQ2O6SCcjs.useFormContext.call(void 0, );
|
|
39
39
|
const needsInitialize = _react.useMemo.call(void 0, () => {
|
|
40
40
|
return lastElementNotRemovable && fields.length === 0;
|
|
41
41
|
}, [lastElementNotRemovable, fields.length]);
|
|
@@ -65,15 +65,12 @@ var useUniformFieldArray = ({
|
|
|
65
65
|
_react.useEffect.call(void 0,
|
|
66
66
|
() => {
|
|
67
67
|
if (needsInitialize) {
|
|
68
|
-
if (!disableAnimation) {
|
|
69
|
-
setDisableAnimation(true);
|
|
70
|
-
}
|
|
71
68
|
setValue(name, [elementInitialValue], {
|
|
72
69
|
shouldDirty: false,
|
|
73
70
|
shouldTouch: false
|
|
74
71
|
});
|
|
75
72
|
hasInitialized.current = true;
|
|
76
|
-
if (!prefersReducedMotion) {
|
|
73
|
+
if (!prefersReducedMotion && disableAnimation) {
|
|
77
74
|
setTimeout(() => {
|
|
78
75
|
setDisableAnimation(false);
|
|
79
76
|
}, 1);
|
|
@@ -103,4 +100,4 @@ var useUniformFieldArray = ({
|
|
|
103
100
|
|
|
104
101
|
|
|
105
102
|
exports.useUniformFieldArray = useUniformFieldArray;
|
|
106
|
-
//# sourceMappingURL=chunk-
|
|
103
|
+
//# sourceMappingURL=chunk-IFBKJ5UZ.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-IFBKJ5UZ.cjs","../src/hooks/useUniformFieldArray/useUniformFieldArray.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AAC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AAA,EAAA,GAAM;AACf,YAAA,mBAAA,CAAoB,KAAK,CAAA;AAAA,UAC3B,CAAA,EAAG,CAAC,CAAA;AAAA,QACN;AAAA,MACF;AAAA,IACF,CAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAOA,CAAC,eAAe;AAAA,EAClB,CAAA;AAEA,EAAA,OAAO,8CAAA;AAAA;AAAA,IAEL,MAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,IACA,MAAA;AAAA,IACA,IAAA;AAAA,IACA,gBAAA;AAAA,IACA;AAAA,EAAA,CAAA,EAEG,YAAA,CAAA;AAEP,CAAA;ADvFA;AACA;AACE;AACF,oDAAC","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-IFBKJ5UZ.cjs","sourcesContent":[null,"import type { ReactNode } from 'react';\nimport type { ArrayPath, FieldValues, Path } from 'react-hook-form';\n\nimport { useEffect, useMemo, useRef, useState } from 'react';\nimport { useFieldArray as useRHFFieldArray } from 'react-hook-form';\n\nimport { useReducedMotion } from '@fuf-stack/pixel-motion';\n\nimport { flatArrayKey } from '../../helpers';\nimport { useFormContext } from '../useFormContext/useFormContext';\nimport { useUniformField } from '../useUniformField/useUniformField';\n\nexport interface UseUniformFieldArrayProps<\n TFieldValues extends FieldValues = FieldValues,\n> {\n /** Field name for the array */\n name: ArrayPath<TFieldValues>;\n /** Whether this is a flat array (array of primitives) */\n flat?: boolean;\n /** Initial value for new array elements */\n elementInitialValue?: unknown;\n /** Whether the last element cannot be removed (always maintain at least one element) */\n lastElementNotRemovable?: boolean;\n /** Disable the field */\n disabled?: boolean;\n /** Optional explicit test id used to build stable test ids */\n testId?: string;\n /** Optional label content; pass false to suppress label entirely */\n label?: ReactNode | false;\n}\n\n/**\n * Enhanced useFieldArray hook with initialization and animation logic.\n * Based on React Hook Form's useFieldArray with additional features:\n * - Automatic initialization when lastElementNotRemovable is set\n * - Animation control (disabled during initialization)\n * - Support for flat arrays (arrays of primitives)\n *\n * Note: Automatic validation triggering on length change is disabled to prevent\n * triggering form-wide validation. Array validation still runs on form submission.\n *\n * @see https://react-hook-form.com/docs/usefieldarray\n */\nexport const useUniformFieldArray = <\n TFieldValues extends FieldValues = FieldValues,\n>({\n name,\n flat = false,\n elementInitialValue: _elementInitialValue = null,\n lastElementNotRemovable = false,\n disabled,\n testId: explicitTestId,\n label,\n}: UseUniformFieldArrayProps<TFieldValues>) => {\n // Get uniform field state and utilities\n const uniformField = useUniformField<TFieldValues>({\n name: name as Path<TFieldValues> & string,\n disabled,\n testId: explicitTestId,\n label,\n });\n\n const { control } = uniformField;\n\n const { fields, append, remove, insert, move } = useRHFFieldArray({\n control,\n name,\n });\n\n const { trigger, setValue } = useFormContext<TFieldValues>();\n\n // Determine if initialization is needed (initially or after reset).\n // This flag automatically handles both scenarios:\n // - Initial mount: fields.length starts at 0\n // - Form reset: fields.length becomes 0 again\n // Additional initialization conditions can be added here later (e.g., minElements > 0)\n // Using useMemo ensures this value is properly tracked by React and effects can depend on it\n const needsInitialize = useMemo(() => {\n return lastElementNotRemovable && fields.length === 0;\n }, [lastElementNotRemovable, fields.length]);\n\n // Track whether initialization has completed. Initialized contextually:\n // - If initialization IS needed (needsInitialize = true): starts as false, set to true after init\n // - If initialization is NOT needed (needsInitialize = false): starts as true (already initialized)\n // This ref is used to:\n // 1. Skip validation during initialization/re-initialization\n // 2. Gate animation enabling until after initialization\n // 3. Gate motion preference effect until after initialization\n const hasInitialized = useRef(!needsInitialize);\n\n // Reset initialization flag when needsInitialize changes to true.\n // This handles form reset: when fields become empty (needsInitialize becomes true),\n // hasInitialized is reset to false, triggering re-initialization in the effect below.\n useEffect(() => {\n if (needsInitialize) {\n hasInitialized.current = false;\n }\n }, [needsInitialize]);\n\n // Validate array-level constraints (min/max items) when length changes.\n // Skip validation during initialization/re-initialization to avoid showing errors prematurely.\n useEffect(() => {\n if (hasInitialized.current) {\n setTimeout(() => {\n // Trigger validation so min/max errors appear instantly when user adds/removes items\n trigger(name as Path<TFieldValues>);\n }, 200);\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [fields.length]);\n\n // Animation control: Start with animations disabled to prevent animating in initial elements.\n // Will be enabled after initialization completes (unless user prefers reduced motion).\n const [disableAnimation, setDisableAnimation] = useState(true);\n\n // Respond to user's motion preference changes (after initialization).\n // During initialization, animations stay disabled regardless of preference.\n const prefersReducedMotion = useReducedMotion();\n useEffect(() => {\n if (hasInitialized.current) {\n setDisableAnimation(!!prefersReducedMotion);\n }\n }, [prefersReducedMotion]);\n\n // Prepare initial element value based on mode\n // - flat=true: arrays of primitives → object with flatArrayKey and null value by default\n // - flat=false: arrays of objects → empty object by default\n const elementInitialValue = useMemo(() => {\n return flat\n ? { [flatArrayKey]: _elementInitialValue ?? null }\n : (_elementInitialValue ?? {});\n }, [flat, _elementInitialValue]);\n\n // Initialization/Re-initialization: Add initial element when needed.\n // This handles both initial mount and form reset scenarios by reacting to needsInitialize.\n // CRITICAL: This effect MUST be the LAST hook in this component.\n // It sets hasInitialized.current = true, which acts as a gate for other effects.\n // If this runs before other effects, hasInitialized will be true during their first run,\n // causing them to execute logic meant only for post-initialization (e.g., validation,\n // animation enabling). By placing this last, all other effects run first with\n // hasInitialized = false, allowing them to skip initialization-phase logic.\n useEffect(\n () => {\n if (needsInitialize) {\n // use setValue instead of append to avoid focusing the added element\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n setValue(name as Path<TFieldValues>, [elementInitialValue] as any, {\n shouldDirty: false,\n shouldTouch: false,\n });\n\n // Mark initialization as complete\n hasInitialized.current = true;\n\n // Enable animations after a brief delay (unless user prefers reduced motion or animations are already enabled).\n // This only runs on initial mount when animations start disabled.\n // On reset, disableAnimation is typically false, so this setTimeout won't run and animations stay enabled.\n if (!prefersReducedMotion && disableAnimation) {\n setTimeout(() => {\n setDisableAnimation(false);\n }, 1);\n }\n }\n },\n // Run when needsInitialize changes (initial mount or reset)\n // needsInitialize is memoized based on fields.length and lastElementNotRemovable\n // Other dependencies are intentionally omitted:\n // - append, setValue, trigger, setDisableAnimation are stable refs/functions\n // - elementInitialValue, name, flat, prefersReducedMotion, disableAnimation are props/stable values\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [needsInitialize],\n );\n\n return {\n // Field array methods and state\n fields,\n append,\n remove,\n insert,\n move,\n disableAnimation,\n elementInitialValue,\n // Uniform field state and utilities (spread all)\n ...uniformField,\n };\n};\n"]}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldCopyTestIdButton_default
|
|
3
|
+
} from "./chunk-NTDKZW4E.js";
|
|
1
4
|
import {
|
|
2
5
|
FieldValidationError_default
|
|
3
6
|
} from "./chunk-ELYGQTXB.js";
|
|
4
7
|
import {
|
|
5
8
|
useController
|
|
6
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-GKP3ONKO.js";
|
|
7
10
|
import {
|
|
8
11
|
useInput
|
|
9
12
|
} from "./chunk-AHJJIANM.js";
|
|
10
|
-
import {
|
|
11
|
-
FieldCopyTestIdButton_default
|
|
12
|
-
} from "./chunk-NTDKZW4E.js";
|
|
13
13
|
import {
|
|
14
14
|
useFormContext
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-U45RW4FC.js";
|
|
16
16
|
import {
|
|
17
17
|
__spreadProps,
|
|
18
18
|
__spreadValues
|
|
@@ -102,4 +102,4 @@ export {
|
|
|
102
102
|
Switch_default,
|
|
103
103
|
Switch_default2
|
|
104
104
|
};
|
|
105
|
-
//# sourceMappingURL=chunk-
|
|
105
|
+
//# sourceMappingURL=chunk-K33E67GR.js.map
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
-
FormContext_default,
|
|
3
2
|
useFormContext
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-U45RW4FC.js";
|
|
4
|
+
import {
|
|
5
|
+
FormContext_default
|
|
6
|
+
} from "./chunk-LKR6D3RL.js";
|
|
5
7
|
|
|
6
8
|
// src/Form/Form.tsx
|
|
7
9
|
import { cn as cn2, slugify } from "@fuf-stack/pixel-utils";
|
|
@@ -167,4 +169,4 @@ export {
|
|
|
167
169
|
Form_default,
|
|
168
170
|
Form_default2
|
|
169
171
|
};
|
|
170
|
-
//# sourceMappingURL=chunk-
|
|
172
|
+
//# sourceMappingURL=chunk-KGN5JQGG.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/Form/Form.tsx","../src/Form/subcomponents/FormDebugViewer.tsx","../src/Form/index.ts"],"sourcesContent":["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 { 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';\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 Form from './Form';\n\nexport type { FormProps } from './Form';\n\nexport { Form };\n\nexport default Form;\n"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../src/Form/Form.tsx","../src/Form/subcomponents/FormDebugViewer.tsx","../src/Form/index.ts"],"sourcesContent":["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 { 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';\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 Form from './Form';\n\nexport type { FormProps } from './Form';\n\nexport { Form };\n\nexport default Form;\n"],"mappings":";;;;;;;;AAKA,SAAS,MAAAA,KAAI,eAAe;;;ACL5B,SAAS,WAAW,gBAA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;AAAA,YAAC;AAAA;AAAA,cACC,WAAWE,IAAG,QAAQ,SAAS;AAAA,cAC/B,sBAAoB;AAAA,cACpB,eAAa,SAAQ,+BAAU,SAAV,YAAkB,EAAE;AAAA,cACzC;AAAA,cACA,UAAU;AAAA,cAET;AAAA;AAAA,UACH;AAAA,UAEC,CAAC,WAAW,EAAC,+BAAO,YACnB,gBAAAF,KAAC,2BAAgB,WAAU,eAAc;AAAA,WAE7C;AAAA,MAEJ;AAAA;AAAA,EACF;AAEJ;AAEA,IAAO,eAAQ;;;AExEf,IAAOG,gBAAQ;","names":["cn","_a","jsx","jsxs","cn","Form_default"]}
|
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
} from "./chunk-B62HKKMS.js";
|
|
4
4
|
import {
|
|
5
5
|
useUniformFieldArray
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-FND5Z5BW.js";
|
|
7
7
|
import {
|
|
8
8
|
useUniformField
|
|
9
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-EGFB5WEK.js";
|
|
10
10
|
import {
|
|
11
11
|
FieldValidationError_default
|
|
12
12
|
} from "./chunk-ELYGQTXB.js";
|
|
@@ -696,4 +696,4 @@ export {
|
|
|
696
696
|
FieldArray_default,
|
|
697
697
|
FieldArray_default2
|
|
698
698
|
};
|
|
699
|
-
//# sourceMappingURL=chunk-
|
|
699
|
+
//# sourceMappingURL=chunk-KQQAESO7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";//# sourceMappingURL=chunk-KWJMKX5J.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-KWJMKX5J.cjs"],"names":[],"mappings":"AAAA","file":"/home/runner/work/pixels/pixels/packages/uniform/dist/chunk-KWJMKX5J.cjs"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
flatArrayKey,
|
|
3
2
|
toFormFormat,
|
|
4
3
|
toValidationFormat
|
|
5
4
|
} from "./chunk-76KOVUDN.js";
|
|
@@ -11,13 +10,8 @@ import {
|
|
|
11
10
|
__spreadValues
|
|
12
11
|
} from "./chunk-K2V4ULA2.js";
|
|
13
12
|
|
|
14
|
-
// src/hooks/useFormContext/useFormContext.ts
|
|
15
|
-
import { useContext } from "react";
|
|
16
|
-
import { useFormContext as useHookFormContext } from "react-hook-form";
|
|
17
|
-
import { slugify } from "@fuf-stack/pixel-utils";
|
|
18
|
-
|
|
19
13
|
// src/Form/subcomponents/FormContext.tsx
|
|
20
|
-
import React, { useMemo as useMemo2, useState as useState2 } from "react";
|
|
14
|
+
import React, { useCallback, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
|
|
21
15
|
import { FormProvider as HookFormProvider, useForm } from "react-hook-form";
|
|
22
16
|
import { useLocalStorage } from "@fuf-stack/pixels";
|
|
23
17
|
|
|
@@ -131,6 +125,16 @@ if (!window.__UNIFORM_CONTEXT__) {
|
|
|
131
125
|
triggerSubmit: () => {
|
|
132
126
|
return void 0;
|
|
133
127
|
},
|
|
128
|
+
userChange: {
|
|
129
|
+
subscribe: () => {
|
|
130
|
+
return () => {
|
|
131
|
+
return void 0;
|
|
132
|
+
};
|
|
133
|
+
},
|
|
134
|
+
notify: () => {
|
|
135
|
+
return void 0;
|
|
136
|
+
}
|
|
137
|
+
},
|
|
134
138
|
validation: {
|
|
135
139
|
setClientValidationSchema: () => {
|
|
136
140
|
return void 0;
|
|
@@ -164,6 +168,24 @@ var FormProvider = ({
|
|
|
164
168
|
});
|
|
165
169
|
const isValid = (_b = methods.formState) == null ? void 0 : _b.isValid;
|
|
166
170
|
const [preventSubmit, setPreventSubmit] = useState2(false);
|
|
171
|
+
const userChangeListenersRef = useRef2(/* @__PURE__ */ new Set());
|
|
172
|
+
const subscribeUserChange = useCallback(
|
|
173
|
+
(listener) => {
|
|
174
|
+
userChangeListenersRef.current.add(listener);
|
|
175
|
+
return () => {
|
|
176
|
+
userChangeListenersRef.current.delete(listener);
|
|
177
|
+
};
|
|
178
|
+
},
|
|
179
|
+
[]
|
|
180
|
+
);
|
|
181
|
+
const notifyUserChange = useCallback(
|
|
182
|
+
(fieldName, value) => {
|
|
183
|
+
userChangeListenersRef.current.forEach((listener) => {
|
|
184
|
+
listener(fieldName, value);
|
|
185
|
+
});
|
|
186
|
+
},
|
|
187
|
+
[]
|
|
188
|
+
);
|
|
167
189
|
const handleSubmit = (e) => __async(null, null, function* () {
|
|
168
190
|
if (methods.formState.isValid && preventSubmit) {
|
|
169
191
|
console.warn(
|
|
@@ -191,6 +213,10 @@ var FormProvider = ({
|
|
|
191
213
|
setClientValidationSchema,
|
|
192
214
|
setDebugMode,
|
|
193
215
|
triggerSubmit: handleSubmit,
|
|
216
|
+
userChange: {
|
|
217
|
+
subscribe: subscribeUserChange,
|
|
218
|
+
notify: notifyUserChange
|
|
219
|
+
},
|
|
194
220
|
validation: {
|
|
195
221
|
baseInstance: baseValidation,
|
|
196
222
|
instance: extendedValidation,
|
|
@@ -206,103 +232,8 @@ var FormProvider = ({
|
|
|
206
232
|
};
|
|
207
233
|
var FormContext_default = FormProvider;
|
|
208
234
|
|
|
209
|
-
// src/hooks/useFormContext/useFormContext.ts
|
|
210
|
-
var checkFieldIsRequired = (validation, path) => {
|
|
211
|
-
const checkPath = path[path.length - 1] === flatArrayKey ? path.slice(0, -1) : path;
|
|
212
|
-
const checkRequired = (schema) => {
|
|
213
|
-
if (schema.type === "array") {
|
|
214
|
-
if (schema.isOptional || schema.isNullable) {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
return true;
|
|
218
|
-
}
|
|
219
|
-
return !schema.isOptional && !schema.isNullable;
|
|
220
|
-
};
|
|
221
|
-
return validation.checkSchemaPath(checkRequired, checkPath);
|
|
222
|
-
};
|
|
223
|
-
var getValidationErrorsByName = (errors, name) => {
|
|
224
|
-
const keys = name.split(".").filter((k) => {
|
|
225
|
-
return k !== flatArrayKey;
|
|
226
|
-
});
|
|
227
|
-
let current = errors;
|
|
228
|
-
keys.forEach((key) => {
|
|
229
|
-
if (current && typeof current === "object") {
|
|
230
|
-
current = current[key];
|
|
231
|
-
} else {
|
|
232
|
-
current = void 0;
|
|
233
|
-
}
|
|
234
|
-
});
|
|
235
|
-
return current;
|
|
236
|
-
};
|
|
237
|
-
var useFormContext = () => {
|
|
238
|
-
const _a = useHookFormContext(), {
|
|
239
|
-
formState,
|
|
240
|
-
getFieldState: getFieldStateOrig,
|
|
241
|
-
getValues: getValuesOrig,
|
|
242
|
-
watch: watchOrig,
|
|
243
|
-
subscribe: subscribeOrig
|
|
244
|
-
} = _a, otherMethods = __objRest(_a, [
|
|
245
|
-
"formState",
|
|
246
|
-
// some methods that will be enhanced below
|
|
247
|
-
"getFieldState",
|
|
248
|
-
"getValues",
|
|
249
|
-
"watch",
|
|
250
|
-
"subscribe"
|
|
251
|
-
]);
|
|
252
|
-
const uniformContext = useContext(UniformContext);
|
|
253
|
-
const getFieldState = (name, testId) => {
|
|
254
|
-
var _a2, _b;
|
|
255
|
-
const fieldPath = typeof name === "string" ? name.replace(/\[\d+\]/g, "").split(".") : name;
|
|
256
|
-
const validationInstance = (_a2 = uniformContext == null ? void 0 : uniformContext.validation.baseInstance) != null ? _a2 : uniformContext == null ? void 0 : uniformContext.validation.instance;
|
|
257
|
-
const required = validationInstance ? checkFieldIsRequired(validationInstance, fieldPath) : false;
|
|
258
|
-
const error = getValidationErrorsByName(
|
|
259
|
-
(_b = uniformContext == null ? void 0 : uniformContext.validation.errors) != null ? _b : {},
|
|
260
|
-
name
|
|
261
|
-
);
|
|
262
|
-
const fieldState = getFieldStateOrig(name, formState);
|
|
263
|
-
return __spreadProps(__spreadValues({}, fieldState), {
|
|
264
|
-
error,
|
|
265
|
-
invalid: !!error,
|
|
266
|
-
required,
|
|
267
|
-
testId: slugify(testId != null ? testId : name, { replaceDots: true })
|
|
268
|
-
});
|
|
269
|
-
};
|
|
270
|
-
const getValues = ((...args) => {
|
|
271
|
-
const result = getValuesOrig(...args);
|
|
272
|
-
return toValidationFormat(result);
|
|
273
|
-
});
|
|
274
|
-
const watch = ((...args) => {
|
|
275
|
-
const result = watchOrig(...args);
|
|
276
|
-
return toValidationFormat(result);
|
|
277
|
-
});
|
|
278
|
-
const subscribe = ((...args) => {
|
|
279
|
-
const [options] = args;
|
|
280
|
-
if (options == null ? void 0 : options.callback) {
|
|
281
|
-
const originalCallback = options.callback;
|
|
282
|
-
const wrappedOptions = __spreadProps(__spreadValues({}, options), {
|
|
283
|
-
callback: (subscribeFormState) => {
|
|
284
|
-
const convertedFormState = __spreadValues(__spreadValues({}, subscribeFormState), subscribeFormState.values && {
|
|
285
|
-
values: toValidationFormat(subscribeFormState.values)
|
|
286
|
-
});
|
|
287
|
-
return originalCallback(convertedFormState);
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
return subscribeOrig(wrappedOptions);
|
|
291
|
-
}
|
|
292
|
-
return subscribeOrig(...args);
|
|
293
|
-
});
|
|
294
|
-
return __spreadProps(__spreadValues(__spreadValues({}, otherMethods), uniformContext), {
|
|
295
|
-
formState,
|
|
296
|
-
getFieldState,
|
|
297
|
-
getValues,
|
|
298
|
-
subscribe,
|
|
299
|
-
watch
|
|
300
|
-
});
|
|
301
|
-
};
|
|
302
|
-
|
|
303
235
|
export {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
useFormContext
|
|
236
|
+
UniformContext,
|
|
237
|
+
FormContext_default
|
|
307
238
|
};
|
|
308
|
-
//# sourceMappingURL=chunk-
|
|
239
|
+
//# sourceMappingURL=chunk-LKR6D3RL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Form/subcomponents/FormContext.tsx","../src/Form/subcomponents/FormResolver.ts"],"sourcesContent":["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 { useLocalStorage } from '@fuf-stack/pixels';\n\nimport { toFormFormat, toValidationFormat } from '../../helpers';\nimport { useExtendedValidation, useFormResolver } from './FormResolver';\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/**\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 *\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 from debug mode */\n debugModeSettings?: DebugModeSettings;\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 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}\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\n// Define props for the FormProvider component, extending HookForm's props\ninterface FormProviderProps {\n /** children form render function */\n children: (childProps: {\n handleSubmit: (e?: BaseSyntheticEvent) => Promise<void>;\n isValid: boolean;\n }) => ReactNode;\n /** settings for from 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 * - Client validation schema management\n * - Submit handler with automatic data conversion and submission control with preventSubmit\n * - Form Debug Mode state\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 + get current validation errors\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 // 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 // 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 console.warn(\n '[FormProvider] form submit was prevented because preventSubmit is true...',\n );\n e?.preventDefault();\n return Promise.resolve();\n }\n\n // Convert nullish strings and filter out empty values before submission\n const wrappedOnSubmit = (data: FieldValues, event?: BaseSyntheticEvent) => {\n const submitData = toValidationFormat(data) ?? {};\n return onSubmit(submitData, event);\n };\n\n await methods.handleSubmit(wrappedOnSubmit)(e);\n };\n\n // Memoize the context value to prevent re-renders\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 setPreventSubmit(prevent);\n },\n setClientValidationSchema,\n setDebugMode,\n triggerSubmit: handleSubmit,\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","import type {\n VetoFormattedError,\n VetoInstance,\n VetoTypeAny,\n} from '@fuf-stack/veto';\nimport type { FieldValues } from 'react-hook-form';\n\nimport { useMemo, useRef, 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(\n () => {\n const keys = Object.keys(clientValidationSchemas).sort();\n return keys\n .map((key) => {\n return clientValidationSchemas[key];\n })\n .filter(Boolean);\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 = clientSchemaValues.reduce(\n // @ts-expect-error is ok, because initially it is null\n (combined, clientSchema) => {\n return combined ? and(combined, clientSchema) : clientSchema;\n },\n null,\n );\n\n // return combined validation\n if (hasBaseValidation && clientSchemasCombined) {\n return veto(and(baseValidation.schema, clientSchemasCombined));\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 * Hook that creates a React Hook Form resolver from an extended validation instance.\n *\n * @param extendedValidation - Extended validation instance from useExtendedValidation\n * @returns Object containing resolver function, current validation errors, and optimization hash\n */\nexport const useFormResolver = (extendedValidation?: VetoInstance) => {\n // Use ref to store validation errors without triggering re-renders\n const validationErrors = useRef<VetoFormattedError>(undefined);\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 validationErrors.current = 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]);\n\n // Hash for memo dependency optimization in consuming components\n const validationErrorsHash = JSON.stringify(validationErrors.current);\n\n return {\n resolver,\n validationErrors: validationErrors.current,\n validationErrorsHash,\n };\n};\n"],"mappings":";;;;;;;;;;;;;AAQA,OAAO,SAAS,aAAa,WAAAA,UAAS,UAAAC,SAAQ,YAAAC,iBAAgB;AAC9D,SAAS,gBAAgB,kBAAkB,eAAe;AAE1D,SAAS,uBAAuB;;;ACJhC,SAAS,SAAS,QAAQ,gBAAgB;AAE1C,SAAS,KAAK,YAAY;AAYnB,IAAM,6BAA6B,MAAM;AAE9C,QAAM,CAAC,yBAAyB,0BAA0B,IAAI,SAE5D,CAAC,CAAC;AAGJ,QAAM,4BAA4B,QAAQ,MAAM;AAC9C,WAAO,CAAC,KAAa,WAA+B;AAElD,iCAA2B,CAAC,SAAS;AAEnC,YAAI,CAAC,KAAK,GAAG,KAAK,CAAC,QAAQ;AACzB,iBAAO;AAAA,QACT;AAEA,YAAI,CAAC,QAAQ;AACX,gBAAqC,WAA5B,EAtCnB,CAsCmB,MAAM,SAtCzB,IAsC+C,IAAT,iBAAS,IAAT,CAAnB;AACT,iBAAO;AAAA,QACT;AAEA,eAAO,iCAAK,OAAL,EAAW,CAAC,GAAG,GAAG,OAAO;AAAA,MAClC,CAAC;AAAA,IACH;AAAA,EACF,GAAG,CAAC,CAAC;AAEL,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;AAQO,IAAM,wBAAwB,CAAC,mBAAkC;AAEtE,QAAM,EAAE,yBAAyB,0BAA0B,IACzD,2BAA2B;AAG7B,QAAM,qBAAqB;AAAA,IACzB,MAAM;AACJ,YAAM,OAAO,OAAO,KAAK,uBAAuB,EAAE,KAAK;AACvD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