@fuf-stack/uniform 1.28.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 +6 -35
- 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 +1278 -496
- 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-9xTF-DBW.mjs → FieldCopyTestIdButton-DV0tkdh2.mjs} +4 -2
- 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 +12 -12
- package/dist/Form/index.d.mts.map +1 -1
- package/dist/Form/index.mjs +9 -7
- package/dist/Form/index.mjs.map +1 -1
- package/dist/{FormContext-CB7Glm02.mjs → FormContext-CHctWFAP.mjs} +51 -8
- 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 +638 -394
- package/dist/Input/index.d.mts.map +1 -1
- package/dist/Input/index.mjs +414 -165
- package/dist/Input/index.mjs.map +1 -1
- package/dist/RadioBoxes/index.d.mts +1588 -125
- 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 +1354 -109
- 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 +554 -3009
- 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 +416 -1328
- 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 +135 -39
- 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-BBSbeKbn.mjs → useController-BCFeZbBZ.mjs} +2 -2
- package/dist/{useController-BBSbeKbn.mjs.map → useController-BCFeZbBZ.mjs.map} +1 -1
- package/dist/{useFormContext-DNb_B8LQ.mjs → useFormContext-BPjJjNnM.mjs} +2 -2
- package/dist/{useFormContext-DNb_B8LQ.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-9xTF-DBW.mjs.map +0 -1
- package/dist/FieldValidationError-ByRoIxaM.mjs +0 -50
- package/dist/FieldValidationError-ByRoIxaM.mjs.map +0 -1
- package/dist/FormContext-CB7Glm02.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 -100
- package/dist/hooks/useUniformField/index.d.mts.map +0 -1
- package/dist/hooks/useUniformField/index.mjs +0 -139
- 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-CwJo1b4Z.d.mts +0 -1
- package/dist/useController-DcK2YHbw.d.mts +0 -32
- package/dist/useController-DcK2YHbw.d.mts.map +0 -1
- package/dist/useFormContext-BegmYvGA.d.mts +0 -66
- package/dist/useFormContext-BegmYvGA.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,101 +0,0 @@
|
|
|
1
|
-
import { flatArrayKey, isValueEmpty } from "../../helpers/index.mjs";
|
|
2
|
-
import { n as useFormContext$1 } from "../../useFormContext-DNb_B8LQ.mjs";
|
|
3
|
-
import { useUniformField } from "../useUniformField/index.mjs";
|
|
4
|
-
import { useWatchFormReset } from "../useWatchFormReset/index.mjs";
|
|
5
|
-
import { useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
-
import { useReducedMotion } from "@fuf-stack/pixel-motion";
|
|
7
|
-
import { useFieldArray } from "react-hook-form";
|
|
8
|
-
//#region src/hooks/useUniformFieldArray/useUniformFieldArray.ts
|
|
9
|
-
/**
|
|
10
|
-
* Enhanced useFieldArray hook with initialization and animation logic.
|
|
11
|
-
* Based on React Hook Form's useFieldArray with additional features:
|
|
12
|
-
* - Automatic initialization when lastElementNotRemovable is set
|
|
13
|
-
* - Reset-only normalization for stale empty placeholder rows (via useWatchFormReset)
|
|
14
|
-
* - Animation control (disabled during initialization)
|
|
15
|
-
* - Temporary animation disable during reset normalization collapse
|
|
16
|
-
* - Support for flat arrays (arrays of primitives)
|
|
17
|
-
*
|
|
18
|
-
* Note: Automatic validation triggering on length change is disabled to prevent
|
|
19
|
-
* triggering form-wide validation. Array validation still runs on form submission.
|
|
20
|
-
*
|
|
21
|
-
* @see https://react-hook-form.com/docs/usefieldarray
|
|
22
|
-
*/
|
|
23
|
-
const useUniformFieldArray = ({ name, flat = false, elementInitialValue: _elementInitialValue = null, lastElementNotRemovable = false, disabled, testId: explicitTestId, label }) => {
|
|
24
|
-
const uniformField = useUniformField({
|
|
25
|
-
name,
|
|
26
|
-
disabled,
|
|
27
|
-
testId: explicitTestId,
|
|
28
|
-
label
|
|
29
|
-
});
|
|
30
|
-
const { control } = uniformField;
|
|
31
|
-
const { fields, append, remove, insert, move, replace } = useFieldArray({
|
|
32
|
-
control,
|
|
33
|
-
name
|
|
34
|
-
});
|
|
35
|
-
const { trigger, setValue, getValues } = useFormContext$1();
|
|
36
|
-
const needsInitialize = useMemo(() => {
|
|
37
|
-
return lastElementNotRemovable && fields.length === 0;
|
|
38
|
-
}, [lastElementNotRemovable, fields.length]);
|
|
39
|
-
const hasInitialized = useRef(!needsInitialize);
|
|
40
|
-
useEffect(() => {
|
|
41
|
-
if (needsInitialize) hasInitialized.current = false;
|
|
42
|
-
}, [needsInitialize]);
|
|
43
|
-
useEffect(() => {
|
|
44
|
-
if (hasInitialized.current) setTimeout(() => {
|
|
45
|
-
trigger(name);
|
|
46
|
-
}, 200);
|
|
47
|
-
}, [fields.length]);
|
|
48
|
-
const [disableAnimation, setDisableAnimation] = useState(true);
|
|
49
|
-
const prefersReducedMotion = useReducedMotion();
|
|
50
|
-
useEffect(() => {
|
|
51
|
-
if (hasInitialized.current) setDisableAnimation(!!prefersReducedMotion);
|
|
52
|
-
}, [prefersReducedMotion]);
|
|
53
|
-
const elementInitialValue = useMemo(() => {
|
|
54
|
-
return flat ? { [flatArrayKey]: _elementInitialValue ?? null } : _elementInitialValue ?? {};
|
|
55
|
-
}, [flat, _elementInitialValue]);
|
|
56
|
-
useWatchFormReset({ onReset: () => {
|
|
57
|
-
const currentValue = getValues(name);
|
|
58
|
-
const valueIsArray = Array.isArray(currentValue);
|
|
59
|
-
const arrayValue = valueIsArray ? currentValue : [];
|
|
60
|
-
const normalizedLength = lastElementNotRemovable ? 1 : 0;
|
|
61
|
-
const alreadyNormalized = valueIsArray && arrayValue.length === normalizedLength;
|
|
62
|
-
if (!(!valueIsArray || arrayValue.length === 0 || arrayValue.every((entry) => {
|
|
63
|
-
return isValueEmpty(entry);
|
|
64
|
-
}))) return;
|
|
65
|
-
if (alreadyNormalized) return;
|
|
66
|
-
setDisableAnimation(true);
|
|
67
|
-
replace(lastElementNotRemovable ? [elementInitialValue] : []);
|
|
68
|
-
if (!prefersReducedMotion) setTimeout(() => {
|
|
69
|
-
setDisableAnimation(false);
|
|
70
|
-
}, 1);
|
|
71
|
-
} });
|
|
72
|
-
useEffect(() => {
|
|
73
|
-
if (needsInitialize) {
|
|
74
|
-
setValue(name, [elementInitialValue], {
|
|
75
|
-
shouldDirty: false,
|
|
76
|
-
shouldTouch: false
|
|
77
|
-
});
|
|
78
|
-
hasInitialized.current = true;
|
|
79
|
-
if (!prefersReducedMotion && disableAnimation) setTimeout(() => {
|
|
80
|
-
setDisableAnimation(false);
|
|
81
|
-
}, 1);
|
|
82
|
-
}
|
|
83
|
-
}, [needsInitialize]);
|
|
84
|
-
return {
|
|
85
|
-
fields,
|
|
86
|
-
append,
|
|
87
|
-
remove,
|
|
88
|
-
insert,
|
|
89
|
-
move,
|
|
90
|
-
disableAnimation,
|
|
91
|
-
elementInitialValue,
|
|
92
|
-
...uniformField
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
//#endregion
|
|
96
|
-
//#region src/hooks/useUniformFieldArray/index.ts
|
|
97
|
-
/* v8 ignore stop */
|
|
98
|
-
//#endregion
|
|
99
|
-
export { useUniformFieldArray };
|
|
100
|
-
|
|
101
|
-
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["useRHFFieldArray","useFormContext"],"sources":["../../../src/hooks/useUniformFieldArray/useUniformFieldArray.ts","../../../src/hooks/useUniformFieldArray/index.ts"],"sourcesContent":["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, isValueEmpty } from '../../helpers';\nimport { useFormContext } from '../useFormContext';\nimport { useUniformField } from '../useUniformField';\nimport { useWatchFormReset } from '../useWatchFormReset';\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 */\n label?: ReactNode;\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 * - Reset-only normalization for stale empty placeholder rows (via useWatchFormReset)\n * - Animation control (disabled during initialization)\n * - Temporary animation disable during reset normalization collapse\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, replace } = useRHFFieldArray({\n control,\n name,\n });\n\n const { trigger, setValue, getValues } = useFormContext<TFieldValues>();\n\n // Determine if initialization is needed (initially or after reset).\n // lastElementNotRemovable is purely a minimum-count guarantee: when there are\n // no rows, add one. This handles both:\n // - Initial mount: fields.length starts at 0\n // - Form reset to an empty array: fields.length becomes 0 again\n // It intentionally does NOT inspect row contents, so manually added empty rows\n // are never collapsed.\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 // This ensures min/max errors appear instantly when user adds/removes items.\n // Note: Child field validation also runs, but new empty fields won't show as invalid\n // because useFormContext only sets invalid=true for touched fields or after form submission.\n // Skip validation during initialization/re-initialization to avoid showing errors prematurely.\n useEffect(() => {\n if (hasInitialized.current) {\n setTimeout(() => {\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 // Reset normalization:\n // Run ONLY when an actual form reset is emitted (via useWatchFormReset), not\n // on regular field edits. This does not collapse rows users add manually.\n //\n // Why this exists:\n // RHF can keep stale field-array rows after reset when array defaults are\n // missing (e.g. value becomes undefined or [null, null] while UI still has\n // multiple rows). We normalize this reset-only state to:\n // - one row when lastElementNotRemovable is enabled\n // - zero rows otherwise\n useWatchFormReset({\n onReset: () => {\n const currentValue = getValues(name as Path<TFieldValues>) as unknown;\n const valueIsArray = Array.isArray(currentValue);\n const arrayValue = valueIsArray ? (currentValue as unknown[]) : [];\n const normalizedLength = lastElementNotRemovable ? 1 : 0;\n const alreadyNormalized =\n valueIsArray && arrayValue.length === normalizedLength;\n\n // Treat these as \"effectively empty after reset\":\n // - value missing/not-array\n // - empty array\n // - array where all entries are empty placeholders\n const isEffectivelyEmptyAfterReset =\n !valueIsArray ||\n arrayValue.length === 0 ||\n arrayValue.every((entry) => {\n return isValueEmpty(entry);\n });\n\n // Nothing to fix when the reset restored real values (e.g. from defaults).\n if (!isEffectivelyEmptyAfterReset) {\n return;\n }\n\n // Already normalized to the target row count.\n if (alreadyNormalized) {\n return;\n }\n\n // Avoid collapse animation flicker during reset normalization.\n setDisableAnimation(true);\n\n // use replace so the RHF field-array length actually matches the target.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n replace((lastElementNotRemovable ? [elementInitialValue] : []) as any);\n\n // Restore normal animation state right after normalization.\n if (!prefersReducedMotion) {\n setTimeout(() => {\n setDisableAnimation(false);\n }, 1);\n }\n },\n });\n\n // Initialization/Re-initialization: add one element only when array length is 0.\n // This is the min-count behavior for lastElementNotRemovable and is intentionally\n // separate from reset normalization above.\n //\n // Reset behavior in this hook is split into two phases:\n // 1) Reset normalization (useWatchFormReset): collapse stale placeholder rows\n // left by reset edge cases.\n // 2) Length-based initialization (this effect): ensure a min-one array when\n // the field array is truly empty.\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","/* v8 ignore start */\n\nexport * from './useUniformFieldArray';\n\n/* v8 ignore stop */\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA8CA,MAAa,wBAEX,EACA,MACA,OAAO,OACP,qBAAqB,uBAAuB,MAC5C,0BAA0B,OAC1B,UACA,QAAQ,gBACR,YAC6C;CAE7C,MAAM,eAAe,gBAA8B;EAC3C;EACN;EACA,QAAQ;EACR;CACF,CAAC;CAED,MAAM,EAAE,YAAY;CAEpB,MAAM,EAAE,QAAQ,QAAQ,QAAQ,QAAQ,MAAM,YAAYA,cAAiB;EACzE;EACA;CACF,CAAC;CAED,MAAM,EAAE,SAAS,UAAU,cAAcC,iBAA6B;CAStE,MAAM,kBAAkB,cAAc;EACpC,OAAO,2BAA2B,OAAO,WAAW;CACtD,GAAG,CAAC,yBAAyB,OAAO,MAAM,CAAC;CAS3C,MAAM,iBAAiB,OAAO,CAAC,eAAe;CAK9C,gBAAgB;EACd,IAAI,iBACF,eAAe,UAAU;CAE7B,GAAG,CAAC,eAAe,CAAC;CAOpB,gBAAgB;EACd,IAAI,eAAe,SACjB,iBAAiB;GACf,QAAQ,IAA0B;EACpC,GAAG,GAAG;CAGV,GAAG,CAAC,OAAO,MAAM,CAAC;CAIlB,MAAM,CAAC,kBAAkB,uBAAuB,SAAS,IAAI;CAI7D,MAAM,uBAAuB,iBAAiB;CAC9C,gBAAgB;EACd,IAAI,eAAe,SACjB,oBAAoB,CAAC,CAAC,oBAAoB;CAE9C,GAAG,CAAC,oBAAoB,CAAC;CAKzB,MAAM,sBAAsB,cAAc;EACxC,OAAO,OACH,GAAG,eAAe,wBAAwB,KAAK,IAC9C,wBAAwB,CAAC;CAChC,GAAG,CAAC,MAAM,oBAAoB,CAAC;CAY/B,kBAAkB,EAChB,eAAe;EACb,MAAM,eAAe,UAAU,IAA0B;EACzD,MAAM,eAAe,MAAM,QAAQ,YAAY;EAC/C,MAAM,aAAa,eAAgB,eAA6B,CAAC;EACjE,MAAM,mBAAmB,0BAA0B,IAAI;EACvD,MAAM,oBACJ,gBAAgB,WAAW,WAAW;EAcxC,IAAI,EAPF,CAAC,gBACD,WAAW,WAAW,KACtB,WAAW,OAAO,UAAU;GAC1B,OAAO,aAAa,KAAK;EAC3B,CAAC,IAID;EAIF,IAAI,mBACF;EAIF,oBAAoB,IAAI;EAIxB,QAAS,0BAA0B,CAAC,mBAAmB,IAAI,CAAC,CAAS;EAGrE,IAAI,CAAC,sBACH,iBAAiB;GACf,oBAAoB,KAAK;EAC3B,GAAG,CAAC;CAER,EACF,CAAC;CAiBD,gBACQ;EACJ,IAAI,iBAAiB;GAGnB,SAAS,MAA4B,CAAC,mBAAmB,GAAU;IACjE,aAAa;IACb,aAAa;GACf,CAAC;GAGD,eAAe,UAAU;GAKzB,IAAI,CAAC,wBAAwB,kBAC3B,iBAAiB;IACf,oBAAoB,KAAK;GAC3B,GAAG,CAAC;EAER;CACF,GAOA,CAAC,eAAe,CAClB;CAEA,OAAO;EAEL;EACA;EACA;EACA;EACA;EACA;EACA;EAEA,GAAG;CACL;AACF"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./useController-DcK2YHbw.mjs";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import "./useFormContext-BegmYvGA.mjs";
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import { ControllerFieldState, ControllerRenderProps, UseControllerProps, UseFormStateReturn } from "react-hook-form";
|
|
2
|
-
//#region src/hooks/useController/useController.d.ts
|
|
3
|
-
type UseControllerProps$1<TFieldValues extends object = object> = UseControllerProps<TFieldValues>;
|
|
4
|
-
interface UseControllerReturn<TFieldValues extends object = object> {
|
|
5
|
-
field: Omit<ControllerRenderProps<TFieldValues>, 'onChange' | 'value'> & {
|
|
6
|
-
onChange: (...event: any[]) => void;
|
|
7
|
-
value: string;
|
|
8
|
-
};
|
|
9
|
-
formState: UseFormStateReturn<TFieldValues>;
|
|
10
|
-
fieldState: ControllerFieldState;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* A wrapper around react-hook-form's useController that transparently handles nullish string conversions.
|
|
14
|
-
*
|
|
15
|
-
* Key features:
|
|
16
|
-
* 1. Empty strings ('') in the UI are stored as null in form state
|
|
17
|
-
* 2. Null/undefined values in form state are displayed as empty strings in the UI
|
|
18
|
-
* 3. Handles both direct value changes and React synthetic events
|
|
19
|
-
* 4. Maintains the same API as react-hook-form's useController
|
|
20
|
-
* 5. Notifies UniformContext's userChange listeners on field changes (enables useWatchUserChange hook)
|
|
21
|
-
* 6. No-op when value unchanged: onChange is ignored if the new value equals the current value
|
|
22
|
-
* (prevents unnecessary re-renders and spurious useWatchUserChange triggers)
|
|
23
|
-
*
|
|
24
|
-
* This enables consistent handling of empty/null values while keeping a clean API
|
|
25
|
-
* for form inputs that expect string values.
|
|
26
|
-
*
|
|
27
|
-
* @see https://react-hook-form.com/docs/usecontroller
|
|
28
|
-
*/
|
|
29
|
-
declare const useController$1: <TFieldValues extends object = object>(props: UseControllerProps$1<TFieldValues>) => UseControllerReturn<TFieldValues>;
|
|
30
|
-
//#endregion
|
|
31
|
-
export { UseControllerReturn as n, useController$1 as r, UseControllerProps$1 as t };
|
|
32
|
-
//# sourceMappingURL=useController-DcK2YHbw.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useController-DcK2YHbw.d.mts","names":[],"sources":["../src/hooks/useController/useController.ts"],"mappings":";;KAaY,qBAAmB,wCAC7B,mBAAsB;UAEP,oBAAoB;EACnC,OAAO,KAAK,sBAAsB;IAGhC,cAAc;IACd;;EAEF,WAAW,mBAAmB;EAC9B,YAAY;;;;;;;;;;;;;;;;;;;cAoBD,kBAAiB,sCAC5B,OAAO,qBAAmB,kBACzB,oBAAoB"}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { n as FormResetListener, r as UserChangeListener, t as DebugModeSettings } from "./FormContext-CsFiNvuJ.mjs";
|
|
2
|
-
import { FieldError, FieldValues, Path } from "react-hook-form";
|
|
3
|
-
import { VetoFormattedError, VetoInstance } from "@fuf-stack/veto";
|
|
4
|
-
//#region src/hooks/useFormContext/useFormContext.d.ts
|
|
5
|
-
/** Schema check whether a field is required or optional */
|
|
6
|
-
declare const checkFieldIsRequired: (validation: VetoInstance, path: string[]) => boolean;
|
|
7
|
-
/**
|
|
8
|
-
* Custom hook that extends react-hook-form's useFormContext to add validation and state management.
|
|
9
|
-
*
|
|
10
|
-
* Key features:
|
|
11
|
-
* - Enhanced `getFieldState` that includes validation schema-based "required" status and testId generation
|
|
12
|
-
* - Automatic conversion of form values via `getValues`, `watch`, and `subscribe`:
|
|
13
|
-
* - Unwraps flat array wrappers (`{ __FLAT__: value }` → `value`)
|
|
14
|
-
* - Converts nullish string markers (`__NULL__` → `null`, `__FALSE__` → `false`, `__ZERO__` → `0`)
|
|
15
|
-
* - Filters out empty/null values
|
|
16
|
-
*/
|
|
17
|
-
declare const useFormContext$1: <TFieldValues extends FieldValues = FieldValues, TContext = any, TTransformedValues = TFieldValues>() => {
|
|
18
|
-
formState: import("react-hook-form").FormState<TFieldValues>;
|
|
19
|
-
getFieldState: (name: Path<TFieldValues>, testId?: string) => {
|
|
20
|
-
error: FieldError[] | undefined;
|
|
21
|
-
invalid: boolean;
|
|
22
|
-
required: boolean;
|
|
23
|
-
testId: string;
|
|
24
|
-
isDirty: boolean;
|
|
25
|
-
isTouched: boolean;
|
|
26
|
-
isValidating: boolean;
|
|
27
|
-
};
|
|
28
|
-
getValues: import("react-hook-form").UseFormGetValues<TFieldValues>;
|
|
29
|
-
reset: import("react-hook-form").UseFormReset<TFieldValues>;
|
|
30
|
-
subscribe: import("react-hook-form").UseFormSubscribe<TFieldValues>;
|
|
31
|
-
watch: import("react-hook-form").UseFormWatch<TFieldValues>;
|
|
32
|
-
debugMode: "debug" | "debug-testids" | "off" | "disabled";
|
|
33
|
-
debugModeSettings?: DebugModeSettings;
|
|
34
|
-
formReset: {
|
|
35
|
-
subscribe: (listener: FormResetListener) => () => void;
|
|
36
|
-
notify: () => void;
|
|
37
|
-
};
|
|
38
|
-
preventSubmit: (prevent: boolean) => void;
|
|
39
|
-
setDebugMode: (debugMode: "debug" | "debug-testids" | "off" | "disabled") => void;
|
|
40
|
-
triggerSubmit: (e?: import("react").BaseSyntheticEvent) => Promise<void> | void;
|
|
41
|
-
userChange: {
|
|
42
|
-
subscribe: (listener: UserChangeListener) => () => void;
|
|
43
|
-
notify: (fieldName: string, value: unknown) => void;
|
|
44
|
-
};
|
|
45
|
-
validation: {
|
|
46
|
-
baseInstance?: VetoInstance;
|
|
47
|
-
instance?: VetoInstance;
|
|
48
|
-
errors?: VetoFormattedError;
|
|
49
|
-
setClientValidationSchema: (key: string, schema: import("@fuf-stack/veto").VetoTypeAny | null) => void;
|
|
50
|
-
};
|
|
51
|
-
setError: import("react-hook-form").UseFormSetError<TFieldValues>;
|
|
52
|
-
clearErrors: import("react-hook-form").UseFormClearErrors<TFieldValues>;
|
|
53
|
-
setValue: import("react-hook-form").UseFormSetValue<TFieldValues>;
|
|
54
|
-
setValues: import("react-hook-form").UseFormSetValues<TFieldValues>;
|
|
55
|
-
trigger: import("react-hook-form").UseFormTrigger<TFieldValues>;
|
|
56
|
-
resetField: import("react-hook-form").UseFormResetField<TFieldValues>;
|
|
57
|
-
resetDefaultValues: import("react-hook-form").UseFormResetDefaultValues<TFieldValues>;
|
|
58
|
-
handleSubmit: import("react-hook-form").UseFormHandleSubmit<TFieldValues, TTransformedValues>;
|
|
59
|
-
unregister: import("react-hook-form").UseFormUnregister<TFieldValues>;
|
|
60
|
-
control: import("react-hook-form").Control<TFieldValues, TContext, TTransformedValues>;
|
|
61
|
-
register: import("react-hook-form").UseFormRegister<TFieldValues>;
|
|
62
|
-
setFocus: import("react-hook-form").UseFormSetFocus<TFieldValues>;
|
|
63
|
-
};
|
|
64
|
-
//#endregion
|
|
65
|
-
export { useFormContext$1 as n, checkFieldIsRequired as t };
|
|
66
|
-
//# sourceMappingURL=useFormContext-BegmYvGA.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useFormContext-BegmYvGA.d.mts","names":[],"sources":["../src/hooks/useFormContext/useFormContext.ts"],"mappings":";;;;;cAYa,uBACX,YAAY,cACZ;;;;;;;;;;;cAmEW,mBACX,qBAAqB,cAAc,aACnC,gBACA,qBAAqB;;EAoCQ,gBAAA,MAAA,KAAK,eAAa;;;;;;;;;;;;;;;;;;;;;EA4B7B,gBAAA,oBAAC,uBAAA;;0BAAA;;;;IAeH,eAAA;IAEJ,WAAC;IAGC,SAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useInputValueTransform-LOaEim7k.d.mts","names":[],"sources":["../src/hooks/useInputValueTransform/useInputValueTransform.ts"],"mappings":";UAEiB,oBAAoB;;EAEnC,iBAAiB,mBAAmB;;EAEpC,cAAc,OAAO;;UAGN,8BAA8B;;EAE7C;;EAEA,YAAY,oBAAoB;;UAGjB,6BAA6B;;EAE5C,iBAAiB,uBAAuB;;EAExC,cAAc,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cAqFjB,yBAA0B,sBAAoB,MAAA,aAGxD,8BAA8B,cAAY,6BAA6B"}
|