@fuf-stack/uniform 1.27.0 → 2.0.0-next.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -0
- package/dist/Checkboxes/index.d.mts +192 -263
- package/dist/Checkboxes/index.d.mts.map +1 -1
- package/dist/Checkboxes/index.mjs +294 -90
- package/dist/Checkboxes/index.mjs.map +1 -1
- package/dist/DatePicker/index.d.mts +1282 -500
- package/dist/DatePicker/index.d.mts.map +1 -1
- package/dist/DatePicker/index.mjs +403 -83
- package/dist/DatePicker/index.mjs.map +1 -1
- package/dist/FieldArray/index.d.mts +105 -98
- package/dist/FieldArray/index.d.mts.map +1 -1
- package/dist/FieldArray/index.mjs +344 -195
- package/dist/FieldArray/index.mjs.map +1 -1
- package/dist/FieldCard/index.d.mts +37 -35
- package/dist/FieldCard/index.d.mts.map +1 -1
- package/dist/FieldCard/index.mjs +187 -128
- package/dist/FieldCard/index.mjs.map +1 -1
- package/dist/{FieldCopyTestIdButton-CRJBix9D.mjs → FieldCopyTestIdButton-DV0tkdh2.mjs} +5 -3
- package/dist/FieldCopyTestIdButton-DV0tkdh2.mjs.map +1 -0
- package/dist/FieldDescription-C4l0HKGL.mjs +36 -0
- package/dist/FieldDescription-C4l0HKGL.mjs.map +1 -0
- package/dist/FieldLabel-DKzqkuY1.mjs +125 -0
- package/dist/FieldLabel-DKzqkuY1.mjs.map +1 -0
- package/dist/FieldLayout-BLW5S-Jm.mjs +46 -0
- package/dist/FieldLayout-BLW5S-Jm.mjs.map +1 -0
- package/dist/FieldValidationError-DgkCL3cC.mjs +77 -0
- package/dist/FieldValidationError-DgkCL3cC.mjs.map +1 -0
- package/dist/Form/index.d.mts +11 -11
- package/dist/Form/index.d.mts.map +1 -1
- package/dist/Form/index.mjs +14 -11
- package/dist/Form/index.mjs.map +1 -1
- package/dist/FormContext-CHctWFAP.mjs +520 -0
- package/dist/FormContext-CHctWFAP.mjs.map +1 -0
- package/dist/FormContext-CsFiNvuJ.d.mts.map +1 -1
- package/dist/Grid/index.mjs +1 -2
- package/dist/{Grid-CTs-Rb9G.mjs → Grid-DfcZeuib.mjs} +4 -2
- package/dist/Grid-DfcZeuib.mjs.map +1 -0
- package/dist/Input/index.d.mts +640 -392
- package/dist/Input/index.d.mts.map +1 -1
- package/dist/Input/index.mjs +421 -76
- package/dist/Input/index.mjs.map +1 -1
- package/dist/RadioBoxes/index.d.mts +1583 -120
- package/dist/RadioBoxes/index.d.mts.map +1 -1
- package/dist/RadioBoxes/index.mjs +159 -114
- package/dist/RadioBoxes/index.mjs.map +1 -1
- package/dist/RadioTabs/index.d.mts +300 -81
- package/dist/RadioTabs/index.d.mts.map +1 -1
- package/dist/RadioTabs/index.mjs +277 -86
- package/dist/RadioTabs/index.mjs.map +1 -1
- package/dist/Radios/index.d.mts +1353 -108
- package/dist/Radios/index.d.mts.map +1 -1
- package/dist/Radios/index.mjs +105 -54
- package/dist/Radios/index.mjs.map +1 -1
- package/dist/Select/index.d.mts +558 -3013
- package/dist/Select/index.d.mts.map +1 -1
- package/dist/Select/index.mjs +319 -177
- package/dist/Select/index.mjs.map +1 -1
- package/dist/Slider/index.d.mts +414 -1326
- package/dist/Slider/index.d.mts.map +1 -1
- package/dist/Slider/index.mjs +276 -94
- package/dist/Slider/index.mjs.map +1 -1
- package/dist/SubmitButton/index.d.mts.map +1 -1
- package/dist/SubmitButton/index.mjs +4 -1
- package/dist/SubmitButton/index.mjs.map +1 -1
- package/dist/Switch/index.d.mts +2 -1248
- package/dist/Switch/index.mjs +167 -68
- package/dist/Switch/index.mjs.map +1 -1
- package/dist/Switch-CvPO8IF9.d.mts +601 -0
- package/dist/Switch-CvPO8IF9.d.mts.map +1 -0
- package/dist/SwitchBox/index.d.mts +139 -43
- package/dist/SwitchBox/index.d.mts.map +1 -1
- package/dist/SwitchBox/index.mjs +142 -87
- package/dist/SwitchBox/index.mjs.map +1 -1
- package/dist/TextArea/index.d.mts +295 -411
- package/dist/TextArea/index.d.mts.map +1 -1
- package/dist/TextArea/index.mjs +200 -48
- package/dist/TextArea/index.mjs.map +1 -1
- package/dist/Time/index.d.mts +1170 -601
- package/dist/Time/index.d.mts.map +1 -1
- package/dist/Time/index.mjs +162 -74
- package/dist/Time/index.mjs.map +1 -1
- package/dist/helpers/index.d.mts +1 -1
- package/dist/helpers/index.mjs +1 -1
- package/dist/helpers/index.mjs.map +1 -1
- package/dist/hooks/useClientValidation/index.mjs +1 -1
- package/dist/hooks/useController/index.d.mts +31 -3
- package/dist/hooks/useController/index.d.mts.map +1 -0
- package/dist/hooks/useController/index.mjs +1 -2
- package/dist/hooks/useFormContext/index.d.mts +65 -3
- package/dist/hooks/useFormContext/index.d.mts.map +1 -0
- package/dist/hooks/useFormContext/index.mjs +1 -2
- package/dist/hooks/useInputValueDebounce/index.d.mts +11 -5
- package/dist/hooks/useInputValueDebounce/index.d.mts.map +1 -1
- package/dist/hooks/useInputValueDebounce/index.mjs +27 -5
- package/dist/hooks/useInputValueDebounce/index.mjs.map +1 -1
- package/dist/hooks/useInputValueTransform/index.d.mts +1 -2
- package/dist/hooks/useInputValueTransform/index.mjs +1 -2
- package/dist/hooks/useWatchFormReset/index.mjs +1 -1
- package/dist/hooks/useWatchUserChange/index.d.mts +2 -2
- package/dist/hooks/useWatchUserChange/index.d.mts.map +1 -1
- package/dist/hooks/useWatchUserChange/index.mjs +1 -1
- package/dist/hooks/useWatchUserChange/index.mjs.map +1 -1
- package/dist/{useInputValueTransform-LOaEim7k.d.mts → index-BS8IoBOn.d.mts} +3 -3
- package/dist/index-BS8IoBOn.d.mts.map +1 -0
- package/dist/partials/FieldCopyTestIdButton/index.mjs +1 -2
- package/dist/partials/FieldValidationError/index.d.mts +637 -3
- package/dist/partials/FieldValidationError/index.d.mts.map +1 -1
- package/dist/partials/FieldValidationError/index.mjs +1 -2
- package/dist/radioControlVariants-Cm6WufWo.mjs +188 -0
- package/dist/radioControlVariants-Cm6WufWo.mjs.map +1 -0
- package/dist/switchVariants-BaQw2DA7.mjs +67 -0
- package/dist/switchVariants-BaQw2DA7.mjs.map +1 -0
- package/dist/timeVariants-B9HDfNYt.mjs +58 -0
- package/dist/timeVariants-B9HDfNYt.mjs.map +1 -0
- package/dist/{useController-CK39i6HI.mjs → useController-BCFeZbBZ.mjs} +2 -2
- package/dist/{useController-CK39i6HI.mjs.map → useController-BCFeZbBZ.mjs.map} +1 -1
- package/dist/{useFormContext-fYWtlnpE.mjs → useFormContext-BPjJjNnM.mjs} +2 -2
- package/dist/{useFormContext-fYWtlnpE.mjs.map → useFormContext-BPjJjNnM.mjs.map} +1 -1
- package/dist/{useInputValueTransform-DJ5zkqSy.mjs → useInputValueTransform-Mw8YEOXT.mjs} +2 -2
- package/dist/{useInputValueTransform-DJ5zkqSy.mjs.map → useInputValueTransform-Mw8YEOXT.mjs.map} +1 -1
- package/package.json +17 -29
- package/dist/FieldCopyTestIdButton-CRJBix9D.mjs.map +0 -1
- package/dist/FieldValidationError-ByRoIxaM.mjs +0 -50
- package/dist/FieldValidationError-ByRoIxaM.mjs.map +0 -1
- package/dist/FormContext-gHSwOlcy.mjs +0 -278
- package/dist/FormContext-gHSwOlcy.mjs.map +0 -1
- package/dist/Grid-CTs-Rb9G.mjs.map +0 -1
- package/dist/Switch/index.d.mts.map +0 -1
- package/dist/hooks/useInput/index.d.mts +0 -2
- package/dist/hooks/useInput/index.mjs +0 -7
- package/dist/hooks/useInput/index.mjs.map +0 -1
- package/dist/hooks/useUniformField/index.d.mts +0 -98
- package/dist/hooks/useUniformField/index.d.mts.map +0 -1
- package/dist/hooks/useUniformField/index.mjs +0 -137
- package/dist/hooks/useUniformField/index.mjs.map +0 -1
- package/dist/hooks/useUniformFieldArray/index.d.mts +0 -73
- package/dist/hooks/useUniformFieldArray/index.d.mts.map +0 -1
- package/dist/hooks/useUniformFieldArray/index.mjs +0 -101
- package/dist/hooks/useUniformFieldArray/index.mjs.map +0 -1
- package/dist/index-CAdGtKE_.d.mts +0 -1
- package/dist/index-CaxrMD1A.d.mts +0 -1
- package/dist/index-D5HVU2jP.d.mts +0 -1
- package/dist/useController-DcK2YHbw.d.mts +0 -32
- package/dist/useController-DcK2YHbw.d.mts.map +0 -1
- package/dist/useFormContext-B3QGVVaO.d.mts +0 -66
- package/dist/useFormContext-B3QGVVaO.d.mts.map +0 -1
- package/dist/useInput-C0aJaAGe.mjs +0 -2
- package/dist/useInput-ClpHDPdr.d.mts +0 -2
- package/dist/useInputValueTransform-LOaEim7k.d.mts.map +0 -1
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { slugify } from "@fuf-stack/pixel-utils";
|
|
2
|
-
import { jsx } from "react/jsx-runtime";
|
|
3
|
-
import { AnimatePresence, motion, useReducedMotion } from "@fuf-stack/pixel-motion";
|
|
4
|
-
//#region src/partials/FieldValidationError/FieldValidationError.tsx
|
|
5
|
-
/**
|
|
6
|
-
* Renders a validation error of a field
|
|
7
|
-
*/
|
|
8
|
-
const FieldValidationError = ({ className = void 0, error = void 0, testId }) => {
|
|
9
|
-
const disableAnimation = useReducedMotion();
|
|
10
|
-
return /* @__PURE__ */ jsx("ul", {
|
|
11
|
-
"aria-label": `Validation errors of field ${testId}`,
|
|
12
|
-
className,
|
|
13
|
-
"data-testid": slugify(`${testId}_error`),
|
|
14
|
-
children: /* @__PURE__ */ jsx(AnimatePresence, {
|
|
15
|
-
initial: !disableAnimation,
|
|
16
|
-
children: error?.map(({ message }, i) => {
|
|
17
|
-
return /* @__PURE__ */ jsx(motion.li, {
|
|
18
|
-
animate: disableAnimation ? void 0 : {
|
|
19
|
-
opacity: 1,
|
|
20
|
-
height: "auto"
|
|
21
|
-
},
|
|
22
|
-
exit: disableAnimation ? void 0 : {
|
|
23
|
-
opacity: 0,
|
|
24
|
-
height: 0
|
|
25
|
-
},
|
|
26
|
-
initial: disableAnimation ? false : {
|
|
27
|
-
height: 0,
|
|
28
|
-
opacity: 0
|
|
29
|
-
},
|
|
30
|
-
style: { overflow: "hidden" },
|
|
31
|
-
transition: {
|
|
32
|
-
duration: .2,
|
|
33
|
-
ease: "circOut"
|
|
34
|
-
},
|
|
35
|
-
children: /* @__PURE__ */ jsx("div", {
|
|
36
|
-
className: "px-1 pt-1",
|
|
37
|
-
children: message
|
|
38
|
-
})
|
|
39
|
-
}, slugify(`${testId}_error_${i}`));
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/partials/FieldValidationError/index.ts
|
|
46
|
-
var FieldValidationError_default = FieldValidationError;
|
|
47
|
-
//#endregion
|
|
48
|
-
export { FieldValidationError as n, FieldValidationError_default as t };
|
|
49
|
-
|
|
50
|
-
//# sourceMappingURL=FieldValidationError-ByRoIxaM.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FieldValidationError-ByRoIxaM.mjs","names":[],"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 animate={\n disableAnimation ? undefined : { opacity: 1, height: 'auto' }\n }\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 >\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 default FieldValidationError;\n"],"mappings":";;;;;;;AAqBA,MAAM,wBAAwB,EAC5B,YAAY,KAAA,GACZ,QAAQ,KAAA,GACR,aAC+B;CAE/B,MAAM,mBAAmB,iBAAiB;CAE1C,OACE,oBAAC,MAAD;EACE,cAAY,8BAA8B;EAC/B;EACX,eAAa,QAAQ,GAAG,OAAO,OAAO;EAEtC,UAAA,oBAAC,iBAAD;GAAiB,SAAS,CAAC;GACxB,UAAA,OAAO,KAAK,EAAE,WAAW,MAAM;IAC9B,OACE,oBAAC,OAAO,IAAR;KAEE,SACE,mBAAmB,KAAA,IAAY;MAAE,SAAS;MAAG,QAAQ;KAAO;KAE9D,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;KAG7C,UAAA,oBAAC,OAAD;MAAK,WAAU;MAAa,UAAA;KAAa,CAAA;IAChC,GAXJ,QAAQ,GAAG,OAAO,SAAS,GAAG,CAW1B;GAEf,CAAC;EACc,CAAA;CACf,CAAA;AAER;;;ACpDA,IAAA,+BAAe"}
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import { toFormFormat, toSubmitFormat, toValidationFormat } from "./helpers/index.mjs";
|
|
2
|
-
import React, { useCallback, useMemo, useRef, useState } from "react";
|
|
3
|
-
import { useLocalStorage } from "@fuf-stack/pixels";
|
|
4
|
-
import { jsx } from "react/jsx-runtime";
|
|
5
|
-
import { FormProvider, useForm } from "react-hook-form";
|
|
6
|
-
import createDebug from "debug";
|
|
7
|
-
import { and, veto } from "@fuf-stack/veto";
|
|
8
|
-
//#region src/Form/subcomponents/FormResolver.ts
|
|
9
|
-
/**
|
|
10
|
-
* Hook that manages client validation schemas state.
|
|
11
|
-
*
|
|
12
|
-
* Provides a centralized way to add/remove dynamic validation schemas
|
|
13
|
-
* that can be combined with base form validation.
|
|
14
|
-
*
|
|
15
|
-
* @returns Object with client validation state and memoized setter function
|
|
16
|
-
*/
|
|
17
|
-
const useClientValidationManager = () => {
|
|
18
|
-
const [clientValidationSchemas, setClientValidationSchemas] = useState({});
|
|
19
|
-
return {
|
|
20
|
-
clientValidationSchemas,
|
|
21
|
-
setClientValidationSchema: useMemo(() => {
|
|
22
|
-
return (key, schema) => {
|
|
23
|
-
setClientValidationSchemas((prev) => {
|
|
24
|
-
if (!prev[key] && !schema) return prev;
|
|
25
|
-
if (!schema) {
|
|
26
|
-
const { [key]: _removed, ...rest } = prev;
|
|
27
|
-
return rest;
|
|
28
|
-
}
|
|
29
|
-
return {
|
|
30
|
-
...prev,
|
|
31
|
-
[key]: schema
|
|
32
|
-
};
|
|
33
|
-
});
|
|
34
|
-
};
|
|
35
|
-
}, [])
|
|
36
|
-
};
|
|
37
|
-
};
|
|
38
|
-
/**
|
|
39
|
-
* Hook that creates an extended validation instance combining base Veto validation with dynamic client validation.
|
|
40
|
-
*
|
|
41
|
-
* @param baseValidation - Optional base Veto validation schema
|
|
42
|
-
* @returns Combined validation instance and client schema setter
|
|
43
|
-
*/
|
|
44
|
-
const useExtendedValidation = (baseValidation) => {
|
|
45
|
-
const { clientValidationSchemas, setClientValidationSchema } = useClientValidationManager();
|
|
46
|
-
const clientSchemaValues = useMemo(() => {
|
|
47
|
-
return Object.keys(clientValidationSchemas).sort().map((key) => {
|
|
48
|
-
return clientValidationSchemas[key];
|
|
49
|
-
}).filter((schema) => {
|
|
50
|
-
return Boolean(schema);
|
|
51
|
-
});
|
|
52
|
-
}, [clientValidationSchemas]);
|
|
53
|
-
return {
|
|
54
|
-
extendedValidation: useMemo(() => {
|
|
55
|
-
const hasBaseValidation = !!baseValidation;
|
|
56
|
-
const hasClientSchemas = clientSchemaValues.length > 0;
|
|
57
|
-
if (!hasBaseValidation && !hasClientSchemas) return;
|
|
58
|
-
if (!hasClientSchemas) return baseValidation;
|
|
59
|
-
const clientSchemasCombined = clientSchemaValues.reduce((combined, clientSchema) => {
|
|
60
|
-
return combined ? and(combined, clientSchema) : clientSchema;
|
|
61
|
-
}, null);
|
|
62
|
-
if (baseValidation && clientSchemasCombined) {
|
|
63
|
-
const baseSchema = baseValidation.schema;
|
|
64
|
-
return veto(and(clientSchemasCombined, baseSchema));
|
|
65
|
-
}
|
|
66
|
-
if (clientSchemasCombined) return veto(clientSchemasCombined);
|
|
67
|
-
return baseValidation;
|
|
68
|
-
}, [baseValidation, clientSchemaValues]),
|
|
69
|
-
setClientValidationSchema
|
|
70
|
-
};
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Creates a React Hook Form resolver from an extended validation instance and
|
|
74
|
-
* stores its latest formatted Veto errors as React state.
|
|
75
|
-
*
|
|
76
|
-
* Keeping the resolver errors in state lets Uniform context consumers re-render
|
|
77
|
-
* when validation output changes, while the hash prevents repeated validations
|
|
78
|
-
* with equivalent errors from causing unnecessary updates.
|
|
79
|
-
*
|
|
80
|
-
* @param extendedValidation - Extended validation instance from useExtendedValidation
|
|
81
|
-
* @returns Resolver function plus the latest validation errors and their hash
|
|
82
|
-
*/
|
|
83
|
-
const useFormResolver = (extendedValidation) => {
|
|
84
|
-
const [validationErrorsState, setValidationErrorsState] = useState({
|
|
85
|
-
errors: void 0,
|
|
86
|
-
hash: void 0
|
|
87
|
-
});
|
|
88
|
-
/**
|
|
89
|
-
* Updates resolver error state only when the formatted validation result
|
|
90
|
-
* actually changes. Veto/RHF may create new error objects for equivalent
|
|
91
|
-
* validation output, so the hash is the guard against avoidable context
|
|
92
|
-
* refreshes.
|
|
93
|
-
*/
|
|
94
|
-
const updateValidationErrors = useCallback((errors) => {
|
|
95
|
-
const nextHash = JSON.stringify(errors);
|
|
96
|
-
setValidationErrorsState((current) => {
|
|
97
|
-
if (current.hash === nextHash) return current;
|
|
98
|
-
return {
|
|
99
|
-
errors,
|
|
100
|
-
hash: nextHash
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
}, []);
|
|
104
|
-
return {
|
|
105
|
-
resolver: useMemo(() => {
|
|
106
|
-
if (!extendedValidation) return;
|
|
107
|
-
return async (values) => {
|
|
108
|
-
const validationValues = toValidationFormat(values) ?? {};
|
|
109
|
-
const result = await extendedValidation.validateAsync(validationValues);
|
|
110
|
-
updateValidationErrors(result.errors ?? void 0);
|
|
111
|
-
return {
|
|
112
|
-
values: result.data ?? {},
|
|
113
|
-
errors: result.errors ?? {}
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
|
-
}, [extendedValidation, updateValidationErrors]),
|
|
117
|
-
validationErrors: validationErrorsState.errors,
|
|
118
|
-
validationErrorsHash: validationErrorsState.hash
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
//#endregion
|
|
122
|
-
//#region src/Form/subcomponents/FormContext.tsx
|
|
123
|
-
const debug = createDebug("uniform:FormContext");
|
|
124
|
-
const DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT = "uniform:debug-mode";
|
|
125
|
-
if (!window.__UNIFORM_CONTEXT__) {
|
|
126
|
-
window.__UNIFORM_CONTEXT__ = React.createContext({
|
|
127
|
-
debugMode: "off",
|
|
128
|
-
formReset: {
|
|
129
|
-
subscribe: () => {
|
|
130
|
-
return () => {};
|
|
131
|
-
},
|
|
132
|
-
notify: () => {}
|
|
133
|
-
},
|
|
134
|
-
preventSubmit: () => {},
|
|
135
|
-
setDebugMode: () => {},
|
|
136
|
-
triggerSubmit: () => {},
|
|
137
|
-
userChange: {
|
|
138
|
-
subscribe: () => {
|
|
139
|
-
return () => {};
|
|
140
|
-
},
|
|
141
|
-
notify: () => {}
|
|
142
|
-
},
|
|
143
|
-
validation: { setClientValidationSchema: () => {} }
|
|
144
|
-
});
|
|
145
|
-
debug("Creating new UniformContext instance");
|
|
146
|
-
} else debug("Reusing existing UniformContext instance from window.__UNIFORM_CONTEXT__");
|
|
147
|
-
const UniformContext = window.__UNIFORM_CONTEXT__;
|
|
148
|
-
debug("UniformContext exported", {
|
|
149
|
-
contextExists: !!UniformContext,
|
|
150
|
-
windowContextExists: !!window.__UNIFORM_CONTEXT__,
|
|
151
|
-
contextsMatch: UniformContext === window.__UNIFORM_CONTEXT__
|
|
152
|
-
});
|
|
153
|
-
/**
|
|
154
|
-
* FormProvider component provides:
|
|
155
|
-
* - Veto validation schema context
|
|
156
|
-
* - Resolver-backed validation error state
|
|
157
|
-
* - Client validation schema management
|
|
158
|
-
* - Submit handler with automatic data conversion and submission control with preventSubmit
|
|
159
|
-
* - Form Debug Mode state
|
|
160
|
-
* - Form reset pub/sub notifications (`formReset`)
|
|
161
|
-
* - User change pub/sub notifications (`userChange`)
|
|
162
|
-
* - React Hook Form context
|
|
163
|
-
*/
|
|
164
|
-
const FormProvider$1 = ({ children, debugModeSettings = void 0, initialValues = void 0, onSubmit, validation: baseValidation = void 0, validationTrigger }) => {
|
|
165
|
-
const [debugMode, setDebugMode] = useLocalStorage(debugModeSettings?.localStorageKey ?? DEBUG_MODE_LOCAL_STORAGE_KEY_DEFAULT, "off");
|
|
166
|
-
const { extendedValidation, setClientValidationSchema } = useExtendedValidation(baseValidation);
|
|
167
|
-
const { resolver, validationErrors, validationErrorsHash } = useFormResolver(extendedValidation);
|
|
168
|
-
const methods = useForm({
|
|
169
|
-
defaultValues: initialValues ? toFormFormat(initialValues) : initialValues,
|
|
170
|
-
mode: validationTrigger,
|
|
171
|
-
resolver
|
|
172
|
-
});
|
|
173
|
-
const isValid = methods.formState?.isValid;
|
|
174
|
-
const [preventSubmit, setPreventSubmit] = useState(false);
|
|
175
|
-
const formResetListenersRef = useRef(/* @__PURE__ */ new Set());
|
|
176
|
-
const subscribeFormReset = useCallback((listener) => {
|
|
177
|
-
formResetListenersRef.current.add(listener);
|
|
178
|
-
return () => {
|
|
179
|
-
formResetListenersRef.current.delete(listener);
|
|
180
|
-
};
|
|
181
|
-
}, []);
|
|
182
|
-
const notifyFormReset = useCallback(() => {
|
|
183
|
-
formResetListenersRef.current.forEach((listener) => {
|
|
184
|
-
listener();
|
|
185
|
-
});
|
|
186
|
-
}, []);
|
|
187
|
-
const userChangeListenersRef = useRef(/* @__PURE__ */ new Set());
|
|
188
|
-
const subscribeUserChange = useCallback((listener) => {
|
|
189
|
-
userChangeListenersRef.current.add(listener);
|
|
190
|
-
return () => {
|
|
191
|
-
userChangeListenersRef.current.delete(listener);
|
|
192
|
-
};
|
|
193
|
-
}, []);
|
|
194
|
-
const notifyUserChange = useCallback((fieldName, value) => {
|
|
195
|
-
userChangeListenersRef.current.forEach((listener) => {
|
|
196
|
-
listener(fieldName, value);
|
|
197
|
-
});
|
|
198
|
-
}, []);
|
|
199
|
-
const handleSubmit = async (e) => {
|
|
200
|
-
debug("handleSubmit called", {
|
|
201
|
-
preventSubmit,
|
|
202
|
-
formStateIsValid: methods.formState.isValid,
|
|
203
|
-
validationErrors: methods.formState.errors,
|
|
204
|
-
validationTrigger,
|
|
205
|
-
formValues: methods.getValues()
|
|
206
|
-
});
|
|
207
|
-
if (methods.formState.isValid && preventSubmit) {
|
|
208
|
-
debug("⛔ Form submit PREVENTED", {
|
|
209
|
-
formStateIsValid: methods.formState.isValid,
|
|
210
|
-
preventSubmit
|
|
211
|
-
});
|
|
212
|
-
console.warn("[FormProvider] form submit was prevented because preventSubmit is true...");
|
|
213
|
-
e?.preventDefault();
|
|
214
|
-
return Promise.resolve();
|
|
215
|
-
}
|
|
216
|
-
debug("✓ Form submit ALLOWED", {
|
|
217
|
-
formStateIsValid: methods.formState.isValid,
|
|
218
|
-
preventSubmit,
|
|
219
|
-
reason: !methods.formState.isValid ? "Form is invalid (will trigger validation and show errors)" : "Form is valid and preventSubmit is false"
|
|
220
|
-
});
|
|
221
|
-
const wrappedOnSubmit = (data, event) => {
|
|
222
|
-
const submitData = toSubmitFormat(data) ?? {};
|
|
223
|
-
debug("onSubmit callback called", { submitData });
|
|
224
|
-
return onSubmit(submitData, event);
|
|
225
|
-
};
|
|
226
|
-
await methods.handleSubmit(wrappedOnSubmit)(e);
|
|
227
|
-
debug("handleSubmit completed");
|
|
228
|
-
};
|
|
229
|
-
const contextValue = useMemo(() => {
|
|
230
|
-
return {
|
|
231
|
-
debugMode: debugModeSettings?.disable ? "disabled" : debugMode,
|
|
232
|
-
preventSubmit: (prevent) => {
|
|
233
|
-
debug("preventSubmit called", {
|
|
234
|
-
previousValue: preventSubmit,
|
|
235
|
-
newValue: prevent,
|
|
236
|
-
formStateIsValid: methods.formState.isValid,
|
|
237
|
-
validationErrors: methods.formState.errors
|
|
238
|
-
});
|
|
239
|
-
setPreventSubmit(prevent);
|
|
240
|
-
},
|
|
241
|
-
setClientValidationSchema,
|
|
242
|
-
setDebugMode,
|
|
243
|
-
triggerSubmit: handleSubmit,
|
|
244
|
-
formReset: {
|
|
245
|
-
subscribe: subscribeFormReset,
|
|
246
|
-
notify: notifyFormReset
|
|
247
|
-
},
|
|
248
|
-
userChange: {
|
|
249
|
-
subscribe: subscribeUserChange,
|
|
250
|
-
notify: notifyUserChange
|
|
251
|
-
},
|
|
252
|
-
validation: {
|
|
253
|
-
baseInstance: baseValidation,
|
|
254
|
-
instance: extendedValidation,
|
|
255
|
-
errors: validationErrors,
|
|
256
|
-
setClientValidationSchema
|
|
257
|
-
}
|
|
258
|
-
};
|
|
259
|
-
}, [
|
|
260
|
-
debugMode,
|
|
261
|
-
debugModeSettings?.disable,
|
|
262
|
-
validationErrorsHash
|
|
263
|
-
]);
|
|
264
|
-
return /* @__PURE__ */ jsx(UniformContext.Provider, {
|
|
265
|
-
value: contextValue,
|
|
266
|
-
children: /* @__PURE__ */ jsx(FormProvider, {
|
|
267
|
-
...methods,
|
|
268
|
-
children: children({
|
|
269
|
-
handleSubmit,
|
|
270
|
-
isValid
|
|
271
|
-
})
|
|
272
|
-
})
|
|
273
|
-
});
|
|
274
|
-
};
|
|
275
|
-
//#endregion
|
|
276
|
-
export { UniformContext as n, FormProvider$1 as t };
|
|
277
|
-
|
|
278
|
-
//# sourceMappingURL=FormContext-gHSwOlcy.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FormContext-gHSwOlcy.mjs","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,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,KAAK,CAAC;GAC5C,MAAM,4BAA4B,EAAE,WAAW,CAAC;GAChD,OAAO,SAAS,YAAY,KAAK;EACnC;EAEA,MAAM,QAAQ,aAAa,eAAe,CAAC,CAAC,CAAC;EAE7C,MAAM,wBAAwB;CAChC;CAIA,MAAM,eAAe,cACb;EACJ,OAAO;GAGL,WAAW,mBAAmB,UAAU,aAAa;GACrD,gBAAgB,YAAqB;IACnC,MAAM,wBAAwB;KAC5B,eAAe;KACf,UAAU;KACV,kBAAkB,QAAQ,UAAU;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,oBAAC,eAAe,UAAhB;EAAyB,OAAO;EAE9B,UAAA,oBAACC,cAAD;GAAkB,GAAI;GACnB,UAAA,SAAS;IAAE;IAAc;GAAQ,CAAC;EACnB,CAAA;CACK,CAAA;AAE7B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Grid-CTs-Rb9G.mjs","names":[],"sources":["../src/Grid/Grid.tsx","../src/Grid/index.ts"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\nexport interface GridProps {\n /** child components */\n children?: ReactNode;\n /** CSS class name */\n className?: string;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n}\n\n/**\n * Defines the default grid for form components\n */\nconst Grid = ({\n children = null,\n className = undefined,\n testId = undefined,\n}: GridProps) => {\n return (\n <div className={cn('grid gap-6', className)} data-testid={testId}>\n {children}\n </div>\n );\n};\n\nexport default Grid;\n","import Grid from './Grid';\n\nexport type { GridProps } from './Grid';\n\nexport default Gr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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;KAiBtB,eAAe,eAAe;KAC9B,YAAY,mBAAmB;UAEnB,oBAAoB;;EAEnC;;EAEA,YAAY;;EAEZ;;EAEA,aAAa;;EAEb,QAAQ;;EAER;EAEA;;EAEA,eAAe;;EAEf;;EAEA,YAAY;;;;;cAMR,WAAU,WAAA,YAAA,MAAA,MAAA,cAAA,cAAA,qBAQb,gCAAW,IAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../../src/hooks/useInput/index.ts"],"sourcesContent":["/* v8 ignore start */\n\nexport * from './useInput';\n\n/* v8 ignore stop */\n"],"mappings":""}
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { t as InputValueTransform } from "../../useInputValueTransform-LOaEim7k.mjs";
|
|
2
|
-
import { r as useController$1 } from "../../useController-DcK2YHbw.mjs";
|
|
3
|
-
import { n as useFormContext$1 } from "../../useFormContext-B3QGVVaO.mjs";
|
|
4
|
-
import { t as useInput } from "../../useInput-ClpHDPdr.mjs";
|
|
5
|
-
import { ReactNode } from "react";
|
|
6
|
-
import { FieldError, FieldValues, Path } from "react-hook-form";
|
|
7
|
-
//#region src/hooks/useUniformField/useUniformField.d.ts
|
|
8
|
-
export interface UseUniformFieldParams<TFieldValues extends FieldValues = FieldValues, TDisplay = unknown> {
|
|
9
|
-
/** Form field name */
|
|
10
|
-
name: Path<TFieldValues> & string;
|
|
11
|
-
/** Custom aria-label for accessibility. If not provided, falls back to field name when no visible label exists */
|
|
12
|
-
ariaLabel?: string;
|
|
13
|
-
/** Disable the field */
|
|
14
|
-
disabled?: boolean;
|
|
15
|
-
/** Normalize nested RHF errors into a flat array for array-like fields */
|
|
16
|
-
isArrayValue?: boolean;
|
|
17
|
-
/** Optional label content */
|
|
18
|
-
label?: ReactNode;
|
|
19
|
-
/** Optional explicit test id used to build stable test ids */
|
|
20
|
-
testId?: string;
|
|
21
|
-
/** Optional value transformation between form and display values */
|
|
22
|
-
transform?: InputValueTransform<TDisplay>;
|
|
23
|
-
/** Input type for special number handling */
|
|
24
|
-
type?: 'text' | 'number' | 'password';
|
|
25
|
-
}
|
|
26
|
-
export interface UseUniformFieldReturn<TFieldValues extends FieldValues = FieldValues> {
|
|
27
|
-
/** Computed aria-label fallback (field name) when no visible label exists. Components can override based on their accessibility needs (e.g., if placeholder provides sufficient context) */
|
|
28
|
-
ariaLabel: string | undefined;
|
|
29
|
-
/** react-hook-form control instance for advanced integrations */
|
|
30
|
-
control: ReturnType<typeof useFormContext$1<TFieldValues>>['control'];
|
|
31
|
-
/** Debug mode from Uniform provider */
|
|
32
|
-
debugMode: ReturnType<typeof useFormContext$1<TFieldValues>>['debugMode'];
|
|
33
|
-
/** Current value used to initialize uncontrolled components */
|
|
34
|
-
defaultValue: unknown;
|
|
35
|
-
/** Whether the field is currently disabled (from RHF) */
|
|
36
|
-
disabled: boolean | undefined;
|
|
37
|
-
/** Validation errors from form state; flattened only when `isArrayValue` is enabled */
|
|
38
|
-
error: FieldError[] | undefined;
|
|
39
|
-
/** Pre-built errorMessage node to plug into components */
|
|
40
|
-
errorMessage: ReactNode | null;
|
|
41
|
-
/** RHF controller field with transformed value/onChange (use this for simple components) */
|
|
42
|
-
field: ReturnType<typeof useController$1<TFieldValues>>['field'];
|
|
43
|
-
/** Helper to spread standardized error message props to underlying components */
|
|
44
|
-
getErrorMessageProps: ReturnType<typeof useInput>['getErrorMessageProps'];
|
|
45
|
-
/** Helper to spread standardized helper wrapper props (for spacing/animation) */
|
|
46
|
-
getHelperWrapperProps: ReturnType<typeof useInput>['getHelperWrapperProps'];
|
|
47
|
-
/** Helper to spread standardized label props to underlying components */
|
|
48
|
-
getLabelProps: ReturnType<typeof useInput>['getLabelProps'];
|
|
49
|
-
/** Access current form values (converted to validation-friendly format) */
|
|
50
|
-
getValues: ReturnType<typeof useFormContext$1<TFieldValues>>['getValues'];
|
|
51
|
-
/** Whether the field should show invalid state (debounced for smooth animations). True when field is invalid AND (dirty OR touched OR submitted) */
|
|
52
|
-
invalid: boolean;
|
|
53
|
-
/** Computed label node including optional test id copy button */
|
|
54
|
-
label: ReactNode | null;
|
|
55
|
-
/** onBlur handler from controller */
|
|
56
|
-
onBlur: ReturnType<typeof useController$1<TFieldValues>>['field']['onBlur'];
|
|
57
|
-
/** onChange handler from controller (with transform applied) */
|
|
58
|
-
onChange: ReturnType<typeof useController$1<TFieldValues>>['field']['onChange'];
|
|
59
|
-
/** Ref to forward to underlying control */
|
|
60
|
-
ref: ReturnType<typeof useController$1<TFieldValues>>['field']['ref'];
|
|
61
|
-
/** Whether the field is required according to validation schema */
|
|
62
|
-
required: boolean;
|
|
63
|
-
/** Reset a specific field in the form */
|
|
64
|
-
resetField: ReturnType<typeof useFormContext$1<TFieldValues>>['resetField'];
|
|
65
|
-
/** Generated HTML data-testid for the field */
|
|
66
|
-
testId: string;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Combines frequently used form field logic into a single hook.
|
|
70
|
-
*
|
|
71
|
-
* Provides:
|
|
72
|
-
* - Enhanced form context (validation-aware state, `testId`, value transforms)
|
|
73
|
-
* - Controller field with nullish conversion handling
|
|
74
|
-
* - Value transformation via `transform` prop:
|
|
75
|
-
* • Allows disentangled display and form values (e.g., string ↔ object, boolean ↔ array)
|
|
76
|
-
* • Automatically applies `toDisplayValue` to field value for components
|
|
77
|
-
* • Automatically applies `toFormValue` to display value when onChange is called
|
|
78
|
-
* • Works with `type` prop for automatic number/string conversion
|
|
79
|
-
* • Examples: storing objects while displaying strings, storing booleans as arrays, enriching values with metadata
|
|
80
|
-
* - Debounced `invalid` state with smart timing:
|
|
81
|
-
* • `true` (field becomes invalid): applies immediately so errors show right away
|
|
82
|
-
* • `false` (field becomes valid): delayed 200ms to allow smooth exit animations
|
|
83
|
-
* • Respects `prefers-reduced-motion` by skipping delays when user prefers reduced motion
|
|
84
|
-
* - Smart `invalid` visibility (via `showInvalid`):
|
|
85
|
-
* • Shows errors when field is dirty OR touched OR form has been submitted
|
|
86
|
-
* • Prevents showing errors on pristine/untouched fields for better UX
|
|
87
|
-
* • Works well for all field types (text inputs, checkboxes, radios, arrays)
|
|
88
|
-
* - Prebuilt `errorMessage` React node (with optional array-error normalization via `isArrayValue`)
|
|
89
|
-
* - Computed `label` node which appends a `FieldCopyTestIdButton` in
|
|
90
|
-
* `debug-testids` mode
|
|
91
|
-
* - `defaultValue` for uncontrolled defaults and all usual field handlers
|
|
92
|
-
* - Access to form utilities: `control`, `getValues`, `resetField`
|
|
93
|
-
* - Presentation helpers: `getLabelProps`, `getErrorMessageProps`,
|
|
94
|
-
* `getHelperWrapperProps` for consistent wiring to underlying UI components
|
|
95
|
-
*/
|
|
96
|
-
export declare const useUniformField: <TFieldValues extends FieldValues = FieldValues, TDisplay = unknown>(params: UseUniformFieldParams<TFieldValues, TDisplay>) => UseUniformFieldReturn<TFieldValues>;
|
|
97
|
-
//#endregion
|
|
98
|
-
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../../src/hooks/useUniformField/useUniformField.tsx"],"mappings":";;;;;;;iBAgBiB,sBACf,qBAAqB,cAAc,aACnC;;EAGA,MAAM,KAAK;;EAEX;;EAEA;;EAEA;;EAEA,QAAQ;;EAER;;EAEA,YAAY,oBAAoB;;EAEhC;;iBAGe,sBACf,qBAAqB,cAAc;;EAGnC;;EAEA,SAAS,kBAAkB,iBAAe;;EAE1C,WAAW,kBAAkB,iBAAe;;EAE5C;;EAEA;;EAEA,OAAO;;EAEP,cAAc;;EAEd,OAAO,kBAAkB,gBAAc;;EAEvC,sBAAsB,kBAAkB;;EAExC,uBAAuB,kBAAkB;;EAEzC,eAAe,kBAAkB;;EAEjC,WAAW,kBAAkB,iBAAe;;EAE5C;;EAEA,OAAO;;EAEP,QAAQ,kBAAkB,gBAAc;;EAExC,UAAU,kBAAkB,gBAAc;;EAE1C,KAAK,kBAAkB,gBAAc;;EAErC;;EAEA,YAAY,kBAAkB,iBAAe;;EAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;qBA+BW,kBACX,qBAAqB,cAAc,aACnC,oBAEA,QAAQ,sBAAsB,cAAc,cAC3C,sBAAsB"}
|