@chris-c-brine/rhf-mui-kit 0.5.0 → 0.5.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.
|
@@ -21,7 +21,7 @@ export type ObjectElementDisplayProps<TValue, Multiple extends boolean | undefin
|
|
|
21
21
|
* @param value - The option value or null
|
|
22
22
|
* @returns A unique string key for the value
|
|
23
23
|
*/
|
|
24
|
-
getItemKey: (value: TValue | null) => string;
|
|
24
|
+
getItemKey: (value: TValue | null) => string | null;
|
|
25
25
|
/**
|
|
26
26
|
* Function to generate a display label for an option value.
|
|
27
27
|
* Can return any ReactNode for custom rendering.
|
|
@@ -29,7 +29,7 @@ export type ObjectElementDisplayProps<TValue, Multiple extends boolean | undefin
|
|
|
29
29
|
* @param value - The option value or null
|
|
30
30
|
* @returns A string to display as the option label
|
|
31
31
|
*/
|
|
32
|
-
getItemLabel: (value: TValue | null) => string;
|
|
32
|
+
getItemLabel: (value: TValue | null) => string | null;
|
|
33
33
|
/**
|
|
34
34
|
* Function to get additional props for an option list item.
|
|
35
35
|
* Used for customizing the rendering of the option.
|
|
@@ -91,9 +91,9 @@ export const ObjectElementDisplay = ({ options, autocompleteProps, getItemKey, g
|
|
|
91
91
|
const searchValue = inputValue.toLowerCase();
|
|
92
92
|
// Filter options that match the input value (by key or label)
|
|
93
93
|
const filteredOptions = options.filter((option) => {
|
|
94
|
-
const key = getItemKey(option)
|
|
94
|
+
const key = getItemKey(option)?.toLowerCase();
|
|
95
95
|
const label = String(getItemLabel(option)).toLowerCase();
|
|
96
|
-
return key
|
|
96
|
+
return key?.includes(searchValue) || label.includes(searchValue);
|
|
97
97
|
});
|
|
98
98
|
// For freeSolo mode, add "Add [value]" option if no exact match exists
|
|
99
99
|
if (freeSolo && stringToNewItem && inputValue.length > 0) {
|
package/dist/index.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),T=require("react-hook-form-mui"),h=require("react"),g=require("lodash"),M=require("@mui/material"),B=require("react-hook-form"),{merge:R}=g;function L(e,n){return n?.multiple,n?.freeSolo,e}const S=(e,n=!1,r=!1)=>R(e,n?{disabled:!0,variant:"standard",sx:{"& .MuiAutocomplete-endAdornment":{display:"none"},...r&&{"& .MuiInput-underline:before":{borderBottom:"none"},"& .MuiInput-underline:after":{borderBottom:"none"},"& .MuiInput-underline:hover:not(.Mui-disabled):before":{borderBottom:"none"}}}}:{});function w(e){return e!=null&&typeof e=="string"}const{merge:z}=g,$=({viewOnly:e=void 0,disableUnderline:n,textFieldProps:r,autocompleteProps:c,...E})=>{const f=h.useMemo(()=>z({readOnly:e,disableClearable:c?.disableClearable||e,disabled:e},c,e?{sx:{".MuiAutocomplete-tag":{opacity:"1 !important"}}}:{}),[c,e]),A=h.useMemo(()=>S(r,e,n),[r,e,n]);return y.jsx(T.AutocompleteElement,{autocompleteProps:f,textFieldProps:A,...E})},G=({options:e,autocompleteProps:n,getItemKey:r,getItemLabel:c,getChipProps:E,stringToNewItem:f,transformValue:A,name:C,freeSolo:F,control:q,getOptionProps:_,...V})=>{const{field:a}=T.useController({name:C,control:q}),[b,k]=h.useState(()=>a.value?(Array.isArray(a.value)?a.value:[a.value]).filter(t=>typeof t!="string"&&!e.some(s=>r(s)===r(t))):[]);h.useEffect(()=>{if(!a.value)return;const t=(Array.isArray(a.value)?a.value:[a.value]).filter(s=>typeof s!="string"&&![...e,...b].some(u=>r(u)===r(s)));t.length>0&&k(s=>[...s,...t])},[a.value,e,b,r]);const H=h.useMemo(()=>{const i=new Set;return[...e,...b].filter(t=>{const s=r(t);return i.has(s)?!1:(i.add(s),!0)})},[e,b]);return y.jsx($,{name:C,control:q,options:H,...V,autocompleteProps:{isOptionEqualToValue:(i,t)=>r(i)===r(t),filterOptions:(i,{inputValue:t})=>{if(!t)return i;const s=t.toLowerCase(),u=i.filter(l=>{const d=r(l)
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("react/jsx-runtime"),T=require("react-hook-form-mui"),h=require("react"),g=require("lodash"),M=require("@mui/material"),B=require("react-hook-form"),{merge:R}=g;function L(e,n){return n?.multiple,n?.freeSolo,e}const S=(e,n=!1,r=!1)=>R(e,n?{disabled:!0,variant:"standard",sx:{"& .MuiAutocomplete-endAdornment":{display:"none"},...r&&{"& .MuiInput-underline:before":{borderBottom:"none"},"& .MuiInput-underline:after":{borderBottom:"none"},"& .MuiInput-underline:hover:not(.Mui-disabled):before":{borderBottom:"none"}}}}:{});function w(e){return e!=null&&typeof e=="string"}const{merge:z}=g,$=({viewOnly:e=void 0,disableUnderline:n,textFieldProps:r,autocompleteProps:c,...E})=>{const f=h.useMemo(()=>z({readOnly:e,disableClearable:c?.disableClearable||e,disabled:e},c,e?{sx:{".MuiAutocomplete-tag":{opacity:"1 !important"}}}:{}),[c,e]),A=h.useMemo(()=>S(r,e,n),[r,e,n]);return y.jsx(T.AutocompleteElement,{autocompleteProps:f,textFieldProps:A,...E})},G=({options:e,autocompleteProps:n,getItemKey:r,getItemLabel:c,getChipProps:E,stringToNewItem:f,transformValue:A,name:C,freeSolo:F,control:q,getOptionProps:_,...V})=>{const{field:a}=T.useController({name:C,control:q}),[b,k]=h.useState(()=>a.value?(Array.isArray(a.value)?a.value:[a.value]).filter(t=>typeof t!="string"&&!e.some(s=>r(s)===r(t))):[]);h.useEffect(()=>{if(!a.value)return;const t=(Array.isArray(a.value)?a.value:[a.value]).filter(s=>typeof s!="string"&&![...e,...b].some(u=>r(u)===r(s)));t.length>0&&k(s=>[...s,...t])},[a.value,e,b,r]);const H=h.useMemo(()=>{const i=new Set;return[...e,...b].filter(t=>{const s=r(t);return i.has(s)?!1:(i.add(s),!0)})},[e,b]);return y.jsx($,{name:C,control:q,options:H,...V,autocompleteProps:{isOptionEqualToValue:(i,t)=>r(i)===r(t),filterOptions:(i,{inputValue:t})=>{if(!t)return i;const s=t.toLowerCase(),u=i.filter(l=>{const d=r(l)?.toLowerCase(),j=String(c(l)).toLowerCase();return d?.includes(s)||j.includes(s)});return F&&f&&t.length>0&&!u.some(d=>String(c(d)).toLowerCase()===s)?[{__isAddOption:!0,inputValue:t,...f(t)},...u]:u},freeSolo:F,autoComplete:!0,autoHighlight:!0,openOnFocus:!0,renderOption:(i,t,{selected:s},u)=>{const l=g.merge(i,_?.(t)??{});if(u?.freeSolo&&typeof t=="object"&&t!==null&&"__isAddOption"in t){const d=t.inputValue;return h.createElement(M.ListItem,{...l,key:`${C}-add-option-${d}`},"Add: '",d,"'")}return h.createElement(M.ListItem,{...l,key:`${C}-option-${r(t)}`},V?.showCheckbox&&u?.multiple&&y.jsx(M.Checkbox,{sx:{marginRight:1},checked:s}),typeof t=="string"?t:c(t))},onChange:(i,t,s,u)=>{const l=o=>A&&o!==null?a.onChange(A(o)):a.onChange(o),d=o=>{const p=r(o);[...e,...b].some(x=>r(x)===p)||k(x=>[...x,o])},j=o=>typeof o=="string"&&o.length>0?o:typeof o=="object"&&o!==null&&"__isAddOption"in o?o.inputValue:null;if(F&&f){const o=j(t);if(o){const p=f(o);if(V.multiple){const x=[...Array.isArray(a.value)?a.value:[],p];l(x)}else l(p);d(p);return}if(Array.isArray(t)&&V.multiple){const p=t?.map(m=>{const D=j(m);return D?f(D):m})??[];l(p);const O=[...e,...b].map(m=>r(m)),x=p.filter(m=>typeof m!="string"&&!O.includes(r(m)));x.length>0&&k(m=>[...m,...x]);return}}A&&t!==null?l(t):n?.onChange?.(i,t,s,u)},renderValue:(i,t,s)=>{const u=L(i,s);return Array.isArray(u)?u.map((l,d)=>{const{key:j,...o}=t({index:d}),p=typeof l=="string"?l:c(l),O=typeof l!="string"&&E?E({value:l,index:d}):{};return y.jsx(M.Chip,{...O,...o,label:p},`${C}-chip-${j}`)}):w(u)?u:u?c(u):""},...n}})},J=({viewOnly:e,disableUnderline:n,...r})=>{const c=h.useMemo(()=>S(r,e,n),[r,e,n]);return y.jsx(T.TextFieldElement,{...c})},{get:N}=g;function P(e,n){const r=N(e,n);return{error:!!r,helperText:r?.message||""}}function Q(e){const n=h.useRef(!1);h.useEffect(()=>(n.current||(e(),n.current=!0),()=>{n.current=!0}),[])}const W=({name:e,rules:n,formControlProps:r={}})=>{const{register:c,formState:{errors:E}}=B.useFormContext(),{error:f,helperText:A}=P(E,e);return y.jsxs(M.FormControl,{error:f,...r,children:[y.jsx("input",{type:"hidden",...c(e,n)}),f&&y.jsx(M.FormHelperText,{children:A})]})};exports.AutocompleteElementDisplay=$;exports.ObjectElementDisplay=G;exports.TextElementDisplay=J;exports.ValidationElement=W;exports.useFormError=P;exports.useOnMount=Q;
|
|
2
2
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/components/AutocompleteElementDisplay.tsx","../src/components/ObjectElementDisplay.tsx","../src/components/TextElementDisplay.tsx","../src/hooks/useFormError.ts","../src/hooks/useOnMount.ts","../src/components/ValidationElement.tsx"],"sourcesContent":["import type {\r\n AutocompleteOwnerState,\r\n AutocompleteRenderValue,\r\n AutocompleteValue,\r\n ChipTypeMap,\r\n TextFieldProps,\r\n} from \"@mui/material\";\r\nimport { ElementType } from \"react\";\r\n\r\nimport lodash from \"lodash\";\r\n\r\nconst { merge } = lodash;\r\n\r\nexport function getAutocompleteTypedValue<\r\n TValue,\r\n Multiple extends boolean | undefined,\r\n DisableClearable extends boolean | undefined,\r\n FreeSolo extends boolean | undefined,\r\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\r\n>(\r\n value:\r\n | AutocompleteRenderValue<TValue, Multiple, FreeSolo>\r\n | AutocompleteValue<TValue, Multiple, DisableClearable, FreeSolo>,\r\n ownerState?: AutocompleteOwnerState<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent>,\r\n) {\r\n if (ownerState?.multiple) {\r\n if (ownerState?.freeSolo) return value as Array<TValue | string>;\r\n return value as TValue[];\r\n } else if (ownerState?.freeSolo) {\r\n return value as NonNullable<TValue | string>;\r\n }\r\n return value as NonNullable<TValue>;\r\n}\r\n\r\n// Apply view-only properties directly to the TextFieldElement props\r\nexport const getTextElementDisplayProps = <PropType>(\r\n props: PropType,\r\n viewOnly = false,\r\n disableUnderline = false,\r\n) =>\r\n merge<PropType, Partial<TextFieldProps>>(\r\n props,\r\n viewOnly\r\n ? {\r\n disabled: true,\r\n variant: \"standard\",\r\n sx: {\r\n \"& .MuiAutocomplete-endAdornment\": {\r\n display: \"none\",\r\n },\r\n // Hide the underline without using slotProps.input.disableUnderline which clears out chips\r\n ...(disableUnderline && {\r\n \"& .MuiInput-underline:before\": { borderBottom: \"none\" },\r\n \"& .MuiInput-underline:after\": { borderBottom: \"none\" },\r\n \"& .MuiInput-underline:hover:not(.Mui-disabled):before\": { borderBottom: \"none\" },\r\n }),\r\n },\r\n }\r\n : {},\r\n ) as PropType;\r\n\r\nexport function isNonNullableString(value: any): value is NonNullable<string> {\r\nreturn value != null && typeof value === 'string';\r\n}","import { AutocompleteElement, type AutocompleteElementProps } from \"react-hook-form-mui\";\r\nimport { type ChipTypeMap } from \"@mui/material\";\r\nimport type { FieldPath, FieldValues } from \"react-hook-form\";\r\nimport { type ElementType, useMemo } from \"react\";\r\nimport lodash from \"lodash\";\r\nimport { getTextElementDisplayProps } from \"../utils\";\r\n\r\nconst { merge } = lodash;\r\n\r\nexport type AutocompleteElementDisplayProps<\r\n TValue,\r\n Multiple extends boolean | undefined,\r\n DisableClearable extends boolean | undefined,\r\n FreeSolo extends boolean | undefined,\r\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\r\n> = AutocompleteElementProps<\r\n TValue,\r\n Multiple,\r\n DisableClearable,\r\n FreeSolo,\r\n ChipComponent,\r\n TFieldValues,\r\n TName\r\n> & {\r\n viewOnly?: boolean;\r\n disableUnderline?: boolean;\r\n}\r\n\r\nexport const AutocompleteElementDisplay = <\r\n TValue,\r\n Multiple extends boolean | undefined,\r\n DisableClearable extends boolean | undefined,\r\n FreeSolo extends boolean | undefined,\r\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\r\n>({\r\n viewOnly = undefined as boolean | undefined,\r\n disableUnderline,\r\n textFieldProps,\r\n autocompleteProps,\r\n ...props\r\n}: AutocompleteElementDisplayProps<\r\n TValue,\r\n Multiple,\r\n DisableClearable,\r\n FreeSolo,\r\n ChipComponent,\r\n TFieldValues,\r\n TName\r\n>) => {\r\n const autocompleteAdjustedProps: AutocompleteElementDisplayProps<\r\n TValue,\r\n Multiple,\r\n DisableClearable,\r\n FreeSolo,\r\n ChipComponent,\r\n TFieldValues,\r\n TName\r\n >[\"autocompleteProps\"] = useMemo(\r\n () =>\r\n merge<\r\n AutocompleteElementDisplayProps<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent, TFieldValues, TName>[\"autocompleteProps\"],\r\n AutocompleteElementDisplayProps<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent, TFieldValues, TName>[\"autocompleteProps\"],\r\n AutocompleteElementDisplayProps<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent, TFieldValues, TName>[\"autocompleteProps\"]\r\n >(\r\n {\r\n readOnly: viewOnly,\r\n disableClearable: autocompleteProps?.disableClearable || viewOnly as DisableClearable,\r\n disabled: viewOnly,\r\n\r\n },\r\n autocompleteProps,\r\n viewOnly\r\n ? {\r\n sx: {\r\n \".MuiAutocomplete-tag\": {\r\n opacity: \"1 !important\",\r\n },\r\n },\r\n }\r\n : {},\r\n ),\r\n [autocompleteProps, viewOnly],\r\n );\r\n\r\n const textFieldAdjustedProps= useMemo(\r\n () => getTextElementDisplayProps(textFieldProps, viewOnly, disableUnderline),\r\n [textFieldProps, viewOnly, disableUnderline],\r\n );\r\n\r\n return (\r\n <AutocompleteElement\r\n autocompleteProps={autocompleteAdjustedProps}\r\n textFieldProps={textFieldAdjustedProps}\r\n {...props}\r\n />\r\n );\r\n};\r\n\r\n\r\n","import { type ElementType, useMemo, useState, useEffect } from \"react\";\nimport {\n Checkbox,\n Chip,\n ListItem,\n type ChipProps,\n type ChipTypeMap,\n type ListItemProps,\n} from \"@mui/material\";\nimport type { FieldPath, FieldValue, FieldValues } from \"react-hook-form\";\nimport {\n AutocompleteElementDisplay,\n type AutocompleteElementDisplayProps,\n} from \"./AutocompleteElementDisplay\";\nimport { getAutocompleteTypedValue, isNonNullableString } from \"../utils\";\nimport { useController } from \"react-hook-form-mui\";\nimport { merge } from \"lodash\";\n\n/**\n * Interface for special \"add option\" objects used in freeSolo mode\n * These objects represent a new item that can be created from user input\n */\ninterface AddOptionType {\n __isAddOption: true;\n inputValue: string;\n\n [key: string]: any; // Allow for additional properties from stringToNewItem\n}\n\n/**\n * Extends AutocompleteElementDisplayProps with additional properties for handling object values.\n *\n * @template TValue - The type of the option values\n * @template Multiple - Boolean flag indicating if multiple selections are allowed\n * @template DisableClearable - Boolean flag indicating if clearing the selection is disabled\n * @template FreeSolo - Boolean flag indicating if free text input is allowed\n * @template ChipComponent - The component type used for rendering chips in multiple selection mode\n * @template TFieldValues - The type of the form values\n * @template TName - The type of the field name\n */\nexport type ObjectElementDisplayProps<\n TValue,\n Multiple extends boolean | undefined,\n DisableClearable extends boolean | undefined,\n FreeSolo extends boolean | undefined,\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = AutocompleteElementDisplayProps<\n TValue,\n Multiple,\n DisableClearable,\n FreeSolo,\n ChipComponent,\n TFieldValues,\n TName\n> & {\n /**\n * Function to extract a unique key from an option value.\n * Used for option comparison and deduplication.\n *\n * @param value - The option value or null\n * @returns A unique string key for the value\n */\n getItemKey: (value: TValue | null) => string;\n\n /**\n * Function to generate a display label for an option value.\n * Can return any ReactNode for custom rendering.\n *\n * @param value - The option value or null\n * @returns A string to display as the option label\n */\n getItemLabel: (value: TValue | null) => string;\n\n /**\n * Function to get additional props for an option list item.\n * Used for customizing the rendering of the option.\n *\n * @param value - The option value or null\n * @returns Additional props to apply to the list item\n */\n getOptionProps?: (value: TValue | null) => ListItemProps;\n\n /**\n * Function to convert a free text input string to a TValue object.\n * Required when freeSolo is true to create new items from text input.\n *\n * @param value - The string value entered by the user\n * @returns A new TValue object created from the string\n */\n stringToNewItem?: (value: string) => TValue;\n\n /**\n * Whether the input allows free text entry.\n * When true, users can enter values that are not in the options.\n */\n freeSolo?: FreeSolo;\n\n /**\n * Optional function that returns additional chip props based on the value.\n * This allows for customizing chip appearance and behavior based on the value it represents.\n *\n * @param value - The option value being rendered as a chip\n * @returns Additional props to apply to the Chip component\n */\n getChipProps?: (props: { value: TValue; index: number }) => Partial<ChipProps> | undefined;\n\n /**\n * Optional function to transform the value before it's updated in the form.\n * This allows for custom processing or enrichment of the selected value.\n *\n * @param value - The value that would normally be sent to the form\n * @returns The transformed value to be stored in the form\n */\n transformValue?: (\n value: Multiple extends true ? TValue[] : TValue | null\n ) => FieldValue<FieldValues>;\n};\n\n/**\n * A form component that displays a searchable dropdown for selecting object values.\n * Extends AutocompleteElementDisplay with object-specific functionality.\n *\n * Features:\n * - Works with complex object values instead of just primitive types\n * - Supports both single and multiple selection modes\n * - Supports free-solo mode for creating new items from text input\n * - Handles initial values that aren't in the default options\n * - Deduplicates options based on item keys\n *\n * @template TValue - The type of the option values\n * @template Multiple - Boolean flag indicating if multiple selections are allowed\n * @template DisableClearable - Boolean flag indicating if clearing the selection is disabled\n * @template FreeSolo - Boolean flag indicating if free text input is allowed\n * @template ChipComponent - The component type used for rendering chips in multiple selection mode\n * @template TFieldValues - The type of the form values\n * @template TName - The type of the field name\n *\n * @returns A React component for selecting object values\n */\nexport const ObjectElementDisplay = <\n TValue,\n Multiple extends boolean | undefined,\n DisableClearable extends boolean | undefined,\n FreeSolo extends boolean | undefined,\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n options,\n autocompleteProps,\n getItemKey,\n getItemLabel,\n getChipProps,\n stringToNewItem,\n transformValue,\n name,\n freeSolo,\n control,\n getOptionProps,\n ...props\n}: ObjectElementDisplayProps<\n TValue,\n Multiple,\n DisableClearable,\n FreeSolo,\n ChipComponent,\n TFieldValues,\n TName\n>) => {\n /**\n * Access to the form field controller\n */\n const { field } = useController({ name, control });\n\n /**\n * State for storing dynamically added options that aren't in the original options list\n * Includes both default values and values added during freeSolo mode\n */\n const [newOptions, setNewOptions] = useState<TValue[]>(() => {\n if (!field.value) return [];\n\n // Convert field value to array for consistent handling\n const fieldValues: TValue[] = Array.isArray(field.value) ? field.value : [field.value];\n\n // Keep only object values that don't exist in the options array\n return fieldValues.filter(\n (value) =>\n typeof value !== \"string\" &&\n !options.some((option) => getItemKey(option) === getItemKey(value)),\n );\n });\n\n /**\n * Update newOptions when field.value changes\n * This ensures that any new values added to the field after rendering\n * are properly included in newOptions and displayed\n */\n useEffect(() => {\n if (!field.value) return;\n\n const fieldValues: TValue[] = Array.isArray(field.value) ? field.value : [field.value];\n const newFieldOptions = fieldValues.filter(\n (value) =>\n typeof value !== \"string\" &&\n ![...options, ...newOptions].some((option) => getItemKey(option) === getItemKey(value)),\n );\n\n // Only update newOptions if there are new values to add\n if (newFieldOptions.length > 0) {\n setNewOptions((prevOptions) => [...prevOptions, ...newFieldOptions]);\n }\n }, [field.value, options, newOptions, getItemKey]);\n\n /**\n * Combined list of all available options (original + dynamically added)\n */\n const allOptions = useMemo(() => {\n const seen = new Set();\n return [...options, ...newOptions].filter((option) => {\n const key = getItemKey(option);\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n })\n }, [options, newOptions]);\n\n return (\n <AutocompleteElementDisplay\n name={name}\n control={control}\n options={allOptions}\n {...props}\n autocompleteProps={{\n /**\n * Determines if two options should be considered equal\n * Uses the getItemKey function to compare option values\n */\n isOptionEqualToValue: (o, v) => getItemKey(o) === getItemKey(v),\n\n /**\n * Filters options based on the input value\n * Checks if the option key or label contains the input value (case-insensitive)\n * For freeSolo mode, adds a special \"Add [value]\" option when there's no exact match\n */\n filterOptions: (options, { inputValue }) => {\n if (!inputValue) return options;\n\n const searchValue = inputValue.toLowerCase();\n\n // Filter options that match the input value (by key or label)\n const filteredOptions = options.filter((option) => {\n const key = getItemKey(option).toLowerCase();\n const label = String(getItemLabel(option)).toLowerCase();\n return key.includes(searchValue) || label.includes(searchValue);\n });\n\n // For freeSolo mode, add \"Add [value]\" option if no exact match exists\n if (freeSolo && stringToNewItem && inputValue.length > 0) {\n const hasExactMatch = filteredOptions.some(\n (option) => String(getItemLabel(option)).toLowerCase() === searchValue,\n );\n\n if (!hasExactMatch) {\n // Create a special option with a __isAddOption flag\n const addOption: AddOptionType = {\n __isAddOption: true,\n inputValue,\n ...stringToNewItem(inputValue), // Include properties for type compatibility\n };\n\n return [addOption as unknown as TValue, ...filteredOptions];\n }\n }\n\n return filteredOptions;\n },\n freeSolo, // Allowed to enter own string value\n autoComplete: true,\n autoHighlight: true, // The first option is highlighted by default\n openOnFocus: true, // Opens the menu when tabbed into\n\n /**\n * Custom rendering for each option in the dropdown list\n * Handles both regular options and special \"Add\" options in freeSolo mode\n */\n renderOption: (liProps, option, { selected }, ownerState) => {\n const itemProps = merge(liProps, getOptionProps?.(option) ?? {});\n\n // Handles the special \"Add\" option in freeSolo mode\n if (\n ownerState?.freeSolo &&\n typeof option === \"object\" &&\n option !== null &&\n \"__isAddOption\" in option\n ) {\n const inputValue = (option as unknown as AddOptionType).inputValue;\n return (\n <ListItem {...itemProps} key={`${name}-add-option-${inputValue}`}>\n Add: '{inputValue}'\n </ListItem>\n );\n }\n\n // Handle regular option\n return (\n <ListItem {...itemProps} key={`${name}-option-${getItemKey(option)}`}>\n {(props?.showCheckbox && ownerState?.multiple) && (\n <Checkbox sx={{ marginRight: 1 }} checked={selected} />\n )}\n {typeof option === \"string\" ? option : getItemLabel(option)}\n </ListItem>\n );\n },\n\n onChange: (event, value, reason, details) => {\n /**\n * Helper function to apply transformValue if provided, otherwise return the original value\n */\n const applyTransform = (val: any) => {\n return transformValue && val !== null\n ? field.onChange(transformValue(val))\n : field.onChange(val);\n };\n\n /**\n * Helper function to add a new item to newOptions if it doesn't exist already\n */\n const addToNewOptions = (item: TValue) => {\n const itemKey = getItemKey(item);\n const itemExists = [...options, ...newOptions].some(\n (option) => getItemKey(option) === itemKey,\n );\n\n if (!itemExists) {\n setNewOptions((prev) => [...prev, item]);\n }\n };\n\n /**\n * Helper function to extract input value from string or AddOption\n */\n const getInputValue = (item: any): string | null => {\n if (typeof item === \"string\" && item.length > 0) {\n return item;\n }\n if (typeof item === \"object\" && item !== null && \"__isAddOption\" in item) {\n return (item as unknown as AddOptionType).inputValue;\n }\n return null;\n };\n\n // Handle freeSolo mode with stringToNewItem function\n if (freeSolo && stringToNewItem) {\n // Handle special add option selection or string input\n const inputValue = getInputValue(value);\n\n if (inputValue) {\n const newItem = stringToNewItem(inputValue);\n\n if (props.multiple) {\n // For multiple selection, add the new item to the current values\n const currentValues = Array.isArray(field.value) ? field.value : [];\n const newValues = [...currentValues, newItem];\n applyTransform(newValues);\n } else {\n // For single selection, just use the new item\n applyTransform(newItem);\n }\n\n addToNewOptions(newItem);\n return;\n }\n\n // Handle array values (multiple selection)\n if (Array.isArray(value) && props.multiple) {\n // Convert any string values to objects and handle special add options\n const newValues =\n value?.map((item) => {\n const inputVal = getInputValue(item);\n return inputVal ? stringToNewItem(inputVal) : item;\n }) ?? [];\n\n applyTransform(newValues);\n\n // Add any new items to newOptions\n const allOptionsKeys = [...options, ...newOptions].map((option) =>\n getItemKey(option),\n );\n const newItems = newValues.filter(\n (item) => typeof item !== \"string\" && !allOptionsKeys.includes(getItemKey(item)),\n );\n\n if (newItems.length > 0) {\n setNewOptions((prev) => [...prev, ...newItems]);\n }\n return;\n }\n }\n\n // Default behavior for non-freeSolo cases\n if (transformValue && value !== null) {\n applyTransform(value as TValue | TValue[]);\n } else {\n autocompleteProps?.onChange?.(event, value, reason, details);\n }\n },\n\n /**\n * Custom rendering for the selected value(s)\n * For multiple selection, renders a Chip for each selected value\n * For single selection, renders the value as text\n * Uses getItemLabel to render the value labels\n */\n renderValue: (value, getItemProps, ownerState) => {\n const typedValue = getAutocompleteTypedValue(value, ownerState);\n\n // Handle array values (multiple selection)\n if (Array.isArray(typedValue)) {\n return typedValue.map((v, index) => {\n // @ts-expect-error a key is returned, and the linter doesn't pick this up\n const { key, ...chipProps } = getItemProps({ index });\n\n // Get the label - use string directly or extract from object\n const label = typeof v === \"string\" ? v : getItemLabel(v);\n\n // Get additional chip props if available\n const valueSpecificProps =\n typeof v !== \"string\" && getChipProps ? getChipProps({ value: v, index }) : {};\n\n return (\n <Chip\n key={`${name}-chip-${key}`}\n {...valueSpecificProps}\n {...chipProps}\n label={label}\n />\n );\n });\n }\n\n // Handles single value - return string or extracted label\n return isNonNullableString(typedValue)\n ? typedValue\n : typedValue\n ? getItemLabel(typedValue as NonNullable<TValue>)\n : \"\";\n },\n ...autocompleteProps,\n }}\n />\n );\n};\n","import { TextFieldElement, type TextFieldElementProps } from \"react-hook-form-mui\";\nimport { type FieldPath, type FieldValues } from \"react-hook-form\";\nimport { useMemo } from \"react\";\nimport { getTextElementDisplayProps } from \"../utils\";\n\nexport type TextElementDisplayProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> = TextFieldElementProps<TFieldValues, TName> & Viewable;\n\n/**\n * A form component that displays a text field with view-only capabilities.\n * Extends TextFieldElement with view-only functionality.\n *\n * @template TFieldValues - The type of the form values\n * @template TName - The type of the field name\n *\n * @returns A React component for text input with view-only support\n */\nexport const TextElementDisplay = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n viewOnly,\n disableUnderline,\n ...props\n}: TextElementDisplayProps<TFieldValues, TName>) => {\n\n const adjustedProps = useMemo(\n () => getTextElementDisplayProps(props, viewOnly, disableUnderline),\n [props, viewOnly, disableUnderline],\n );\n\n return <TextFieldElement {...adjustedProps} />;\n};\n\ntype Viewable = {\n viewOnly?: boolean;\n disableUnderline?: boolean;\n};\n","import { FieldError, FieldErrors, FieldValues } from 'react-hook-form';\r\nimport lodash from 'lodash';\r\nconst { get } = lodash;\r\n\r\n/**\r\n * A hook to get the error message for a field from react-hook-form\r\n * @param errors The errors object from react-hook-form\r\n * @param name The name of the field (supports dot notation for nested fields)\r\n * @returns An object with error and helperText properties\r\n */\r\nexport function useFormError<T extends FieldValues>(\r\n errors: FieldErrors<T>,\r\n name: string\r\n): { error: boolean; helperText: string } {\r\n // Get the error for the field, supporting nested paths with dot notation\r\n const fieldError = get(errors, name) as FieldError | undefined;\r\n\r\n // Return error state and helper text\r\n return {\r\n error: !!fieldError,\r\n helperText: fieldError?.message || '',\r\n };\r\n}\r\n","// src/hooks/useOnMount.ts\r\nimport { useEffect, useRef } from \"react\";\r\n\r\n/**\r\n * Runs a provided callback function once on the first component mount.\r\n *\r\n * @param callback - The function to run on first mount.\r\n */\r\nexport function useOnMount(callback: () => void): void {\r\n const hasMounted = useRef(false);\r\n\r\n useEffect(() => {\r\n if (!hasMounted.current) {\r\n callback();\r\n hasMounted.current = true;\r\n }\r\n\r\n // Cleanup to prevent callback logic from running during cleanup\r\n return () => {\r\n hasMounted.current = true;\r\n };\r\n \r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, []);\r\n}\r\n\r\n","import type { JSX } from \"react\";\r\nimport { FormControl, FormHelperText } from \"@mui/material\";\r\nimport type { FormControlProps } from \"@mui/material\";\r\nimport { useFormContext, type RegisterOptions, type FieldValues, type Path } from \"react-hook-form\";\r\nimport { useFormError } from \"../hooks\";\r\n\r\n/**\r\n * Props for the RHFHiddenInput component\r\n */\r\nexport interface ValidationElementProps<TFieldValues extends FieldValues> {\r\n /**\r\n * Name of the field in the form\r\n */\r\n name: Path<TFieldValues>;\r\n /**\r\n * Optional validation rules\r\n */\r\n rules: RegisterOptions<TFieldValues>;\r\n /**\r\n * Props to pass to the FormControl component\r\n */\r\n formControlProps?: Omit<FormControlProps, \"error\">;\r\n}\r\n\r\nexport const ValidationElement = <TFieldValues extends FieldValues = FieldValues>({\r\n name,\r\n rules,\r\n formControlProps = {},\r\n}: ValidationElementProps<TFieldValues>): JSX.Element => {\r\n const {\r\n register,\r\n formState: { errors },\r\n } = useFormContext<TFieldValues>();\r\n\r\n const { error, helperText } = useFormError(errors, name);\r\n\r\n return (\r\n <FormControl error={error} {...formControlProps}>\r\n <input type=\"hidden\" {...register(name, rules)} />\r\n {error && <FormHelperText>{helperText}</FormHelperText>}\r\n </FormControl>\r\n );\r\n};\r\n"],"names":["merge","lodash","getAutocompleteTypedValue","value","ownerState","getTextElementDisplayProps","props","viewOnly","disableUnderline","isNonNullableString","AutocompleteElementDisplay","textFieldProps","autocompleteProps","autocompleteAdjustedProps","useMemo","textFieldAdjustedProps","jsx","AutocompleteElement","ObjectElementDisplay","options","getItemKey","getItemLabel","getChipProps","stringToNewItem","transformValue","name","freeSolo","control","getOptionProps","field","useController","newOptions","setNewOptions","useState","option","useEffect","newFieldOptions","prevOptions","allOptions","seen","key","o","v","inputValue","searchValue","filteredOptions","label","liProps","selected","itemProps","createElement","ListItem","Checkbox","event","reason","details","applyTransform","val","addToNewOptions","item","itemKey","prev","getInputValue","newItem","newValues","inputVal","allOptionsKeys","newItems","getItemProps","typedValue","index","chipProps","valueSpecificProps","Chip","TextElementDisplay","adjustedProps","TextFieldElement","get","useFormError","errors","fieldError","useOnMount","callback","hasMounted","useRef","ValidationElement","rules","formControlProps","register","useFormContext","error","helperText","jsxs","FormControl","FormHelperText"],"mappings":"qPAWM,CAAA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E,EACdC,EACAtD,EACwC,CAExC,MAAMuD,EAAaH,EAAIE,EAAQtD,CAAI,EAGnC,MAAO,CACL,MAAO,CAAC,CAACuD,EACT,WAAYA,GAAY,SAAW,EAAA,CAEvC,CCdO,SAASC,EAAWC,EAA4B,CACrD,MAAMC,EAAaC,EAAAA,OAAO,EAAK,EAE/BjD,EAAAA,UAAU,KACHgD,EAAW,UACdD,EAAA,EACAC,EAAW,QAAU,IAIhB,IAAM,CACXA,EAAW,QAAU,EACvB,GAGC,CAAA,CAAE,CACP,CCAO,MAAME,EAAoB,CAAiD,CAChF,KAAA5D,EACA,MAAA6D,EACA,iBAAAC,EAAmB,CAAA,CACrB,IAAyD,CACvD,KAAM,CACJ,SAAAC,EACA,UAAW,CAAE,OAAAT,CAAA,CAAO,EAClBU,iBAAA,EAEE,CAAE,MAAAC,EAAO,WAAAC,CAAA,EAAeb,EAAaC,EAAQtD,CAAI,EAEvD,OACEmE,EAAAA,KAACC,EAAAA,YAAA,CAAY,MAAAH,EAAe,GAAGH,EAC7B,SAAA,CAAAvE,MAAC,SAAM,KAAK,SAAU,GAAGwE,EAAS/D,EAAM6D,CAAK,EAAG,EAC/CI,GAAS1E,EAAAA,IAAC8E,EAAAA,eAAA,CAAgB,SAAAH,CAAA,CAAW,CAAA,EACxC,CAEJ"}
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":["../src/utils.ts","../src/components/AutocompleteElementDisplay.tsx","../src/components/ObjectElementDisplay.tsx","../src/components/TextElementDisplay.tsx","../src/hooks/useFormError.ts","../src/hooks/useOnMount.ts","../src/components/ValidationElement.tsx"],"sourcesContent":["import type {\r\n AutocompleteOwnerState,\r\n AutocompleteRenderValue,\r\n AutocompleteValue,\r\n ChipTypeMap,\r\n TextFieldProps,\r\n} from \"@mui/material\";\r\nimport { ElementType } from \"react\";\r\n\r\nimport lodash from \"lodash\";\r\n\r\nconst { merge } = lodash;\r\n\r\nexport function getAutocompleteTypedValue<\r\n TValue,\r\n Multiple extends boolean | undefined,\r\n DisableClearable extends boolean | undefined,\r\n FreeSolo extends boolean | undefined,\r\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\r\n>(\r\n value:\r\n | AutocompleteRenderValue<TValue, Multiple, FreeSolo>\r\n | AutocompleteValue<TValue, Multiple, DisableClearable, FreeSolo>,\r\n ownerState?: AutocompleteOwnerState<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent>,\r\n) {\r\n if (ownerState?.multiple) {\r\n if (ownerState?.freeSolo) return value as Array<TValue | string>;\r\n return value as TValue[];\r\n } else if (ownerState?.freeSolo) {\r\n return value as NonNullable<TValue | string>;\r\n }\r\n return value as NonNullable<TValue>;\r\n}\r\n\r\n// Apply view-only properties directly to the TextFieldElement props\r\nexport const getTextElementDisplayProps = <PropType>(\r\n props: PropType,\r\n viewOnly = false,\r\n disableUnderline = false,\r\n) =>\r\n merge<PropType, Partial<TextFieldProps>>(\r\n props,\r\n viewOnly\r\n ? {\r\n disabled: true,\r\n variant: \"standard\",\r\n sx: {\r\n \"& .MuiAutocomplete-endAdornment\": {\r\n display: \"none\",\r\n },\r\n // Hide the underline without using slotProps.input.disableUnderline which clears out chips\r\n ...(disableUnderline && {\r\n \"& .MuiInput-underline:before\": { borderBottom: \"none\" },\r\n \"& .MuiInput-underline:after\": { borderBottom: \"none\" },\r\n \"& .MuiInput-underline:hover:not(.Mui-disabled):before\": { borderBottom: \"none\" },\r\n }),\r\n },\r\n }\r\n : {},\r\n ) as PropType;\r\n\r\nexport function isNonNullableString(value: any): value is NonNullable<string> {\r\nreturn value != null && typeof value === 'string';\r\n}","import { AutocompleteElement, type AutocompleteElementProps } from \"react-hook-form-mui\";\r\nimport { type ChipTypeMap } from \"@mui/material\";\r\nimport type { FieldPath, FieldValues } from \"react-hook-form\";\r\nimport { type ElementType, useMemo } from \"react\";\r\nimport lodash from \"lodash\";\r\nimport { getTextElementDisplayProps } from \"../utils\";\r\n\r\nconst { merge } = lodash;\r\n\r\nexport type AutocompleteElementDisplayProps<\r\n TValue,\r\n Multiple extends boolean | undefined,\r\n DisableClearable extends boolean | undefined,\r\n FreeSolo extends boolean | undefined,\r\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\r\n> = AutocompleteElementProps<\r\n TValue,\r\n Multiple,\r\n DisableClearable,\r\n FreeSolo,\r\n ChipComponent,\r\n TFieldValues,\r\n TName\r\n> & {\r\n viewOnly?: boolean;\r\n disableUnderline?: boolean;\r\n}\r\n\r\nexport const AutocompleteElementDisplay = <\r\n TValue,\r\n Multiple extends boolean | undefined,\r\n DisableClearable extends boolean | undefined,\r\n FreeSolo extends boolean | undefined,\r\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\r\n>({\r\n viewOnly = undefined as boolean | undefined,\r\n disableUnderline,\r\n textFieldProps,\r\n autocompleteProps,\r\n ...props\r\n}: AutocompleteElementDisplayProps<\r\n TValue,\r\n Multiple,\r\n DisableClearable,\r\n FreeSolo,\r\n ChipComponent,\r\n TFieldValues,\r\n TName\r\n>) => {\r\n const autocompleteAdjustedProps: AutocompleteElementDisplayProps<\r\n TValue,\r\n Multiple,\r\n DisableClearable,\r\n FreeSolo,\r\n ChipComponent,\r\n TFieldValues,\r\n TName\r\n >[\"autocompleteProps\"] = useMemo(\r\n () =>\r\n merge<\r\n AutocompleteElementDisplayProps<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent, TFieldValues, TName>[\"autocompleteProps\"],\r\n AutocompleteElementDisplayProps<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent, TFieldValues, TName>[\"autocompleteProps\"],\r\n AutocompleteElementDisplayProps<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent, TFieldValues, TName>[\"autocompleteProps\"]\r\n >(\r\n {\r\n readOnly: viewOnly,\r\n disableClearable: autocompleteProps?.disableClearable || viewOnly as DisableClearable,\r\n disabled: viewOnly,\r\n\r\n },\r\n autocompleteProps,\r\n viewOnly\r\n ? {\r\n sx: {\r\n \".MuiAutocomplete-tag\": {\r\n opacity: \"1 !important\",\r\n },\r\n },\r\n }\r\n : {},\r\n ),\r\n [autocompleteProps, viewOnly],\r\n );\r\n\r\n const textFieldAdjustedProps= useMemo(\r\n () => getTextElementDisplayProps(textFieldProps, viewOnly, disableUnderline),\r\n [textFieldProps, viewOnly, disableUnderline],\r\n );\r\n\r\n return (\r\n <AutocompleteElement\r\n autocompleteProps={autocompleteAdjustedProps}\r\n textFieldProps={textFieldAdjustedProps}\r\n {...props}\r\n />\r\n );\r\n};\r\n\r\n\r\n","import { type ElementType, useMemo, useState, useEffect } from \"react\";\nimport {\n Checkbox,\n Chip,\n ListItem,\n type ChipProps,\n type ChipTypeMap,\n type ListItemProps,\n} from \"@mui/material\";\nimport type { FieldPath, FieldValue, FieldValues } from \"react-hook-form\";\nimport {\n AutocompleteElementDisplay,\n type AutocompleteElementDisplayProps,\n} from \"./AutocompleteElementDisplay\";\nimport { getAutocompleteTypedValue, isNonNullableString } from \"../utils\";\nimport { useController } from \"react-hook-form-mui\";\nimport { merge } from \"lodash\";\n\n/**\n * Interface for special \"add option\" objects used in freeSolo mode\n * These objects represent a new item that can be created from user input\n */\ninterface AddOptionType {\n __isAddOption: true;\n inputValue: string;\n\n [key: string]: any; // Allow for additional properties from stringToNewItem\n}\n\n/**\n * Extends AutocompleteElementDisplayProps with additional properties for handling object values.\n *\n * @template TValue - The type of the option values\n * @template Multiple - Boolean flag indicating if multiple selections are allowed\n * @template DisableClearable - Boolean flag indicating if clearing the selection is disabled\n * @template FreeSolo - Boolean flag indicating if free text input is allowed\n * @template ChipComponent - The component type used for rendering chips in multiple selection mode\n * @template TFieldValues - The type of the form values\n * @template TName - The type of the field name\n */\nexport type ObjectElementDisplayProps<\n TValue,\n Multiple extends boolean | undefined,\n DisableClearable extends boolean | undefined,\n FreeSolo extends boolean | undefined,\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = AutocompleteElementDisplayProps<\n TValue,\n Multiple,\n DisableClearable,\n FreeSolo,\n ChipComponent,\n TFieldValues,\n TName\n> & {\n /**\n * Function to extract a unique key from an option value.\n * Used for option comparison and deduplication.\n *\n * @param value - The option value or null\n * @returns A unique string key for the value\n */\n getItemKey: (value: TValue | null) => string | null;\n\n /**\n * Function to generate a display label for an option value.\n * Can return any ReactNode for custom rendering.\n *\n * @param value - The option value or null\n * @returns A string to display as the option label\n */\n getItemLabel: (value: TValue | null) => string | null;\n\n /**\n * Function to get additional props for an option list item.\n * Used for customizing the rendering of the option.\n *\n * @param value - The option value or null\n * @returns Additional props to apply to the list item\n */\n getOptionProps?: (value: TValue | null) => ListItemProps;\n\n /**\n * Function to convert a free text input string to a TValue object.\n * Required when freeSolo is true to create new items from text input.\n *\n * @param value - The string value entered by the user\n * @returns A new TValue object created from the string\n */\n stringToNewItem?: (value: string) => TValue;\n\n /**\n * Whether the input allows free text entry.\n * When true, users can enter values that are not in the options.\n */\n freeSolo?: FreeSolo;\n\n /**\n * Optional function that returns additional chip props based on the value.\n * This allows for customizing chip appearance and behavior based on the value it represents.\n *\n * @param value - The option value being rendered as a chip\n * @returns Additional props to apply to the Chip component\n */\n getChipProps?: (props: { value: TValue; index: number }) => Partial<ChipProps> | undefined;\n\n /**\n * Optional function to transform the value before it's updated in the form.\n * This allows for custom processing or enrichment of the selected value.\n *\n * @param value - The value that would normally be sent to the form\n * @returns The transformed value to be stored in the form\n */\n transformValue?: (\n value: Multiple extends true ? TValue[] : TValue | null\n ) => FieldValue<FieldValues>;\n};\n\n/**\n * A form component that displays a searchable dropdown for selecting object values.\n * Extends AutocompleteElementDisplay with object-specific functionality.\n *\n * Features:\n * - Works with complex object values instead of just primitive types\n * - Supports both single and multiple selection modes\n * - Supports free-solo mode for creating new items from text input\n * - Handles initial values that aren't in the default options\n * - Deduplicates options based on item keys\n *\n * @template TValue - The type of the option values\n * @template Multiple - Boolean flag indicating if multiple selections are allowed\n * @template DisableClearable - Boolean flag indicating if clearing the selection is disabled\n * @template FreeSolo - Boolean flag indicating if free text input is allowed\n * @template ChipComponent - The component type used for rendering chips in multiple selection mode\n * @template TFieldValues - The type of the form values\n * @template TName - The type of the field name\n *\n * @returns A React component for selecting object values\n */\nexport const ObjectElementDisplay = <\n TValue,\n Multiple extends boolean | undefined,\n DisableClearable extends boolean | undefined,\n FreeSolo extends boolean | undefined,\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n options,\n autocompleteProps,\n getItemKey,\n getItemLabel,\n getChipProps,\n stringToNewItem,\n transformValue,\n name,\n freeSolo,\n control,\n getOptionProps,\n ...props\n}: ObjectElementDisplayProps<\n TValue,\n Multiple,\n DisableClearable,\n FreeSolo,\n ChipComponent,\n TFieldValues,\n TName\n>) => {\n /**\n * Access to the form field controller\n */\n const { field } = useController({ name, control });\n\n /**\n * State for storing dynamically added options that aren't in the original options list\n * Includes both default values and values added during freeSolo mode\n */\n const [newOptions, setNewOptions] = useState<TValue[]>(() => {\n if (!field.value) return [];\n\n // Convert field value to array for consistent handling\n const fieldValues: TValue[] = Array.isArray(field.value) ? field.value : [field.value];\n\n // Keep only object values that don't exist in the options array\n return fieldValues.filter(\n (value) =>\n typeof value !== \"string\" &&\n !options.some((option) => getItemKey(option) === getItemKey(value)),\n );\n });\n\n /**\n * Update newOptions when field.value changes\n * This ensures that any new values added to the field after rendering\n * are properly included in newOptions and displayed\n */\n useEffect(() => {\n if (!field.value) return;\n\n const fieldValues: TValue[] = Array.isArray(field.value) ? field.value : [field.value];\n const newFieldOptions = fieldValues.filter(\n (value) =>\n typeof value !== \"string\" &&\n ![...options, ...newOptions].some((option) => getItemKey(option) === getItemKey(value)),\n );\n\n // Only update newOptions if there are new values to add\n if (newFieldOptions.length > 0) {\n setNewOptions((prevOptions) => [...prevOptions, ...newFieldOptions]);\n }\n }, [field.value, options, newOptions, getItemKey]);\n\n /**\n * Combined list of all available options (original + dynamically added)\n */\n const allOptions = useMemo(() => {\n const seen = new Set();\n return [...options, ...newOptions].filter((option) => {\n const key = getItemKey(option);\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n })\n }, [options, newOptions]);\n\n return (\n <AutocompleteElementDisplay\n name={name}\n control={control}\n options={allOptions}\n {...props}\n autocompleteProps={{\n /**\n * Determines if two options should be considered equal\n * Uses the getItemKey function to compare option values\n */\n isOptionEqualToValue: (o, v) => getItemKey(o) === getItemKey(v),\n\n /**\n * Filters options based on the input value\n * Checks if the option key or label contains the input value (case-insensitive)\n * For freeSolo mode, adds a special \"Add [value]\" option when there's no exact match\n */\n filterOptions: (options, { inputValue }) => {\n if (!inputValue) return options;\n\n const searchValue = inputValue.toLowerCase();\n\n // Filter options that match the input value (by key or label)\n const filteredOptions = options.filter((option) => {\n const key = getItemKey(option)?.toLowerCase();\n const label = String(getItemLabel(option)).toLowerCase();\n return key?.includes(searchValue) || label.includes(searchValue);\n });\n\n // For freeSolo mode, add \"Add [value]\" option if no exact match exists\n if (freeSolo && stringToNewItem && inputValue.length > 0) {\n const hasExactMatch = filteredOptions.some(\n (option) => String(getItemLabel(option)).toLowerCase() === searchValue,\n );\n\n if (!hasExactMatch) {\n // Create a special option with a __isAddOption flag\n const addOption: AddOptionType = {\n __isAddOption: true,\n inputValue,\n ...stringToNewItem(inputValue), // Include properties for type compatibility\n };\n\n return [addOption as unknown as TValue, ...filteredOptions];\n }\n }\n\n return filteredOptions;\n },\n freeSolo, // Allowed to enter own string value\n autoComplete: true,\n autoHighlight: true, // The first option is highlighted by default\n openOnFocus: true, // Opens the menu when tabbed into\n\n /**\n * Custom rendering for each option in the dropdown list\n * Handles both regular options and special \"Add\" options in freeSolo mode\n */\n renderOption: (liProps, option, { selected }, ownerState) => {\n const itemProps = merge(liProps, getOptionProps?.(option) ?? {});\n\n // Handles the special \"Add\" option in freeSolo mode\n if (\n ownerState?.freeSolo &&\n typeof option === \"object\" &&\n option !== null &&\n \"__isAddOption\" in option\n ) {\n const inputValue = (option as unknown as AddOptionType).inputValue;\n return (\n <ListItem {...itemProps} key={`${name}-add-option-${inputValue}`}>\n Add: '{inputValue}'\n </ListItem>\n );\n }\n\n // Handle regular option\n return (\n <ListItem {...itemProps} key={`${name}-option-${getItemKey(option)}`}>\n {(props?.showCheckbox && ownerState?.multiple) && (\n <Checkbox sx={{ marginRight: 1 }} checked={selected} />\n )}\n {typeof option === \"string\" ? option : getItemLabel(option)}\n </ListItem>\n );\n },\n\n onChange: (event, value, reason, details) => {\n /**\n * Helper function to apply transformValue if provided, otherwise return the original value\n */\n const applyTransform = (val: any) => {\n return transformValue && val !== null\n ? field.onChange(transformValue(val))\n : field.onChange(val);\n };\n\n /**\n * Helper function to add a new item to newOptions if it doesn't exist already\n */\n const addToNewOptions = (item: TValue) => {\n const itemKey = getItemKey(item);\n const itemExists = [...options, ...newOptions].some(\n (option) => getItemKey(option) === itemKey,\n );\n\n if (!itemExists) {\n setNewOptions((prev) => [...prev, item]);\n }\n };\n\n /**\n * Helper function to extract input value from string or AddOption\n */\n const getInputValue = (item: any): string | null => {\n if (typeof item === \"string\" && item.length > 0) {\n return item;\n }\n if (typeof item === \"object\" && item !== null && \"__isAddOption\" in item) {\n return (item as unknown as AddOptionType).inputValue;\n }\n return null;\n };\n\n // Handle freeSolo mode with stringToNewItem function\n if (freeSolo && stringToNewItem) {\n // Handle special add option selection or string input\n const inputValue = getInputValue(value);\n\n if (inputValue) {\n const newItem = stringToNewItem(inputValue);\n\n if (props.multiple) {\n // For multiple selection, add the new item to the current values\n const currentValues = Array.isArray(field.value) ? field.value : [];\n const newValues = [...currentValues, newItem];\n applyTransform(newValues);\n } else {\n // For single selection, just use the new item\n applyTransform(newItem);\n }\n\n addToNewOptions(newItem);\n return;\n }\n\n // Handle array values (multiple selection)\n if (Array.isArray(value) && props.multiple) {\n // Convert any string values to objects and handle special add options\n const newValues =\n value?.map((item) => {\n const inputVal = getInputValue(item);\n return inputVal ? stringToNewItem(inputVal) : item;\n }) ?? [];\n\n applyTransform(newValues);\n\n // Add any new items to newOptions\n const allOptionsKeys = [...options, ...newOptions].map((option) =>\n getItemKey(option),\n );\n const newItems = newValues.filter(\n (item) => typeof item !== \"string\" && !allOptionsKeys.includes(getItemKey(item)),\n );\n\n if (newItems.length > 0) {\n setNewOptions((prev) => [...prev, ...newItems]);\n }\n return;\n }\n }\n\n // Default behavior for non-freeSolo cases\n if (transformValue && value !== null) {\n applyTransform(value as TValue | TValue[]);\n } else {\n autocompleteProps?.onChange?.(event, value, reason, details);\n }\n },\n\n /**\n * Custom rendering for the selected value(s)\n * For multiple selection, renders a Chip for each selected value\n * For single selection, renders the value as text\n * Uses getItemLabel to render the value labels\n */\n renderValue: (value, getItemProps, ownerState) => {\n const typedValue = getAutocompleteTypedValue(value, ownerState);\n\n // Handle array values (multiple selection)\n if (Array.isArray(typedValue)) {\n return typedValue.map((v, index) => {\n // @ts-expect-error a key is returned, and the linter doesn't pick this up\n const { key, ...chipProps } = getItemProps({ index });\n\n // Get the label - use string directly or extract from object\n const label = typeof v === \"string\" ? v : getItemLabel(v);\n\n // Get additional chip props if available\n const valueSpecificProps =\n typeof v !== \"string\" && getChipProps ? getChipProps({ value: v, index }) : {};\n\n return (\n <Chip\n key={`${name}-chip-${key}`}\n {...valueSpecificProps}\n {...chipProps}\n label={label}\n />\n );\n });\n }\n\n // Handles single value - return string or extracted label\n return isNonNullableString(typedValue)\n ? typedValue\n : typedValue\n ? getItemLabel(typedValue as NonNullable<TValue>)\n : \"\";\n },\n ...autocompleteProps,\n }}\n />\n );\n};\n","import { TextFieldElement, type TextFieldElementProps } from \"react-hook-form-mui\";\nimport { type FieldPath, type FieldValues } from \"react-hook-form\";\nimport { useMemo } from \"react\";\nimport { getTextElementDisplayProps } from \"../utils\";\n\nexport type TextElementDisplayProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> = TextFieldElementProps<TFieldValues, TName> & Viewable;\n\n/**\n * A form component that displays a text field with view-only capabilities.\n * Extends TextFieldElement with view-only functionality.\n *\n * @template TFieldValues - The type of the form values\n * @template TName - The type of the field name\n *\n * @returns A React component for text input with view-only support\n */\nexport const TextElementDisplay = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n viewOnly,\n disableUnderline,\n ...props\n}: TextElementDisplayProps<TFieldValues, TName>) => {\n\n const adjustedProps = useMemo(\n () => getTextElementDisplayProps(props, viewOnly, disableUnderline),\n [props, viewOnly, disableUnderline],\n );\n\n return <TextFieldElement {...adjustedProps} />;\n};\n\ntype Viewable = {\n viewOnly?: boolean;\n disableUnderline?: boolean;\n};\n","import { FieldError, FieldErrors, FieldValues } from 'react-hook-form';\r\nimport lodash from 'lodash';\r\nconst { get } = lodash;\r\n\r\n/**\r\n * A hook to get the error message for a field from react-hook-form\r\n * @param errors The errors object from react-hook-form\r\n * @param name The name of the field (supports dot notation for nested fields)\r\n * @returns An object with error and helperText properties\r\n */\r\nexport function useFormError<T extends FieldValues>(\r\n errors: FieldErrors<T>,\r\n name: string\r\n): { error: boolean; helperText: string } {\r\n // Get the error for the field, supporting nested paths with dot notation\r\n const fieldError = get(errors, name) as FieldError | undefined;\r\n\r\n // Return error state and helper text\r\n return {\r\n error: !!fieldError,\r\n helperText: fieldError?.message || '',\r\n };\r\n}\r\n","// src/hooks/useOnMount.ts\r\nimport { useEffect, useRef } from \"react\";\r\n\r\n/**\r\n * Runs a provided callback function once on the first component mount.\r\n *\r\n * @param callback - The function to run on first mount.\r\n */\r\nexport function useOnMount(callback: () => void): void {\r\n const hasMounted = useRef(false);\r\n\r\n useEffect(() => {\r\n if (!hasMounted.current) {\r\n callback();\r\n hasMounted.current = true;\r\n }\r\n\r\n // Cleanup to prevent callback logic from running during cleanup\r\n return () => {\r\n hasMounted.current = true;\r\n };\r\n \r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, []);\r\n}\r\n\r\n","import type { JSX } from \"react\";\r\nimport { FormControl, FormHelperText } from \"@mui/material\";\r\nimport type { FormControlProps } from \"@mui/material\";\r\nimport { useFormContext, type RegisterOptions, type FieldValues, type Path } from \"react-hook-form\";\r\nimport { useFormError } from \"../hooks\";\r\n\r\n/**\r\n * Props for the RHFHiddenInput component\r\n */\r\nexport interface ValidationElementProps<TFieldValues extends FieldValues> {\r\n /**\r\n * Name of the field in the form\r\n */\r\n name: Path<TFieldValues>;\r\n /**\r\n * Optional validation rules\r\n */\r\n rules: RegisterOptions<TFieldValues>;\r\n /**\r\n * Props to pass to the FormControl component\r\n */\r\n formControlProps?: Omit<FormControlProps, \"error\">;\r\n}\r\n\r\nexport const ValidationElement = <TFieldValues extends FieldValues = FieldValues>({\r\n name,\r\n rules,\r\n formControlProps = {},\r\n}: ValidationElementProps<TFieldValues>): JSX.Element => {\r\n const {\r\n register,\r\n formState: { errors },\r\n } = useFormContext<TFieldValues>();\r\n\r\n const { error, helperText } = useFormError(errors, name);\r\n\r\n return (\r\n <FormControl error={error} {...formControlProps}>\r\n <input type=\"hidden\" {...register(name, rules)} />\r\n {error && <FormHelperText>{helperText}</FormHelperText>}\r\n </FormControl>\r\n );\r\n};\r\n"],"names":["merge","lodash","getAutocompleteTypedValue","value","ownerState","getTextElementDisplayProps","props","viewOnly","disableUnderline","isNonNullableString","AutocompleteElementDisplay","textFieldProps","autocompleteProps","autocompleteAdjustedProps","useMemo","textFieldAdjustedProps","jsx","AutocompleteElement","ObjectElementDisplay","options","getItemKey","getItemLabel","getChipProps","stringToNewItem","transformValue","name","freeSolo","control","getOptionProps","field","useController","newOptions","setNewOptions","useState","option","useEffect","newFieldOptions","prevOptions","allOptions","seen","key","o","v","inputValue","searchValue","filteredOptions","label","liProps","selected","itemProps","createElement","ListItem","Checkbox","event","reason","details","applyTransform","val","addToNewOptions","item","itemKey","prev","getInputValue","newItem","newValues","inputVal","allOptionsKeys","newItems","getItemProps","typedValue","index","chipProps","valueSpecificProps","Chip","TextElementDisplay","adjustedProps","TextFieldElement","get","useFormError","errors","fieldError","useOnMount","callback","hasMounted","useRef","ValidationElement","rules","formControlProps","register","useFormContext","error","helperText","jsxs","FormControl","FormHelperText"],"mappings":"qPAWM,CAAA,MAAEA,GAAUC,EAEX,SAASC,EAOdC,EAGAC,EACA,CACA,OAAIA,GAAY,SACVA,GAAY,SAAiBD,CAMrC,CAGO,MAAME,EAA6B,CACxCC,EACAC,EAAW,GACXC,EAAmB,KAEnBR,EACEM,EACAC,EACI,CACE,SAAU,GACV,QAAS,WACT,GAAI,CACF,kCAAmC,CACjC,QAAS,MAAA,EAGX,GAAIC,GAAoB,CACtB,+BAAgC,CAAE,aAAc,MAAA,EAChD,8BAA+B,CAAE,aAAc,MAAA,EAC/C,wDAAyD,CAAE,aAAc,MAAA,CAAO,CAClF,CACF,EAEF,CAAA,CACN,EAEK,SAASC,EAAoBN,EAA0C,CAC9E,OAAOA,GAAS,MAAQ,OAAOA,GAAU,QACzC,CCxDA,KAAM,CAAE,MAAAH,GAAUC,EAuBLS,EAA6B,CAQxC,CACA,SAAAH,EAAW,OACX,iBAAAC,EACA,eAAAG,EACA,kBAAAC,EACA,GAAGN,CACL,IAQM,CACJ,MAAMO,EAQmBC,EAAAA,QACvB,IACEd,EAKE,CACE,SAAUO,EACV,iBAAkBK,GAAmB,kBAAoBL,EACzD,SAAUA,CAAA,EAGZK,EACAL,EACI,CACE,GAAI,CACF,uBAAwB,CACtB,QAAS,cAAA,CACX,CACF,EAEF,CAAA,CAAC,EAET,CAACK,EAAmBL,CAAQ,CAAA,EAGxBQ,EAAwBD,EAAAA,QAC5B,IAAMT,EAA2BM,EAAgBJ,EAAUC,CAAgB,EAC3E,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: r }) => {
|
|
118
118
|
if (!r) return i;
|
|
119
119
|
const s = r.toLowerCase(), u = i.filter((l) => {
|
|
120
|
-
const f = t(l)
|
|
121
|
-
return f
|
|
120
|
+
const f = t(l)?.toLowerCase(), E = String(c(l)).toLowerCase();
|
|
121
|
+
return f?.includes(s) || E.includes(s);
|
|
122
122
|
});
|
|
123
123
|
return M && d && r.length > 0 && !u.some(
|
|
124
124
|
(f) => String(c(f)).toLowerCase() === s
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/components/AutocompleteElementDisplay.tsx","../src/components/ObjectElementDisplay.tsx","../src/components/TextElementDisplay.tsx","../src/hooks/useFormError.ts","../src/hooks/useOnMount.ts","../src/components/ValidationElement.tsx"],"sourcesContent":["import type {\r\n AutocompleteOwnerState,\r\n AutocompleteRenderValue,\r\n AutocompleteValue,\r\n ChipTypeMap,\r\n TextFieldProps,\r\n} from \"@mui/material\";\r\nimport { ElementType } from \"react\";\r\n\r\nimport lodash from \"lodash\";\r\n\r\nconst { merge } = lodash;\r\n\r\nexport function getAutocompleteTypedValue<\r\n TValue,\r\n Multiple extends boolean | undefined,\r\n DisableClearable extends boolean | undefined,\r\n FreeSolo extends boolean | undefined,\r\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\r\n>(\r\n value:\r\n | AutocompleteRenderValue<TValue, Multiple, FreeSolo>\r\n | AutocompleteValue<TValue, Multiple, DisableClearable, FreeSolo>,\r\n ownerState?: AutocompleteOwnerState<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent>,\r\n) {\r\n if (ownerState?.multiple) {\r\n if (ownerState?.freeSolo) return value as Array<TValue | string>;\r\n return value as TValue[];\r\n } else if (ownerState?.freeSolo) {\r\n return value as NonNullable<TValue | string>;\r\n }\r\n return value as NonNullable<TValue>;\r\n}\r\n\r\n// Apply view-only properties directly to the TextFieldElement props\r\nexport const getTextElementDisplayProps = <PropType>(\r\n props: PropType,\r\n viewOnly = false,\r\n disableUnderline = false,\r\n) =>\r\n merge<PropType, Partial<TextFieldProps>>(\r\n props,\r\n viewOnly\r\n ? {\r\n disabled: true,\r\n variant: \"standard\",\r\n sx: {\r\n \"& .MuiAutocomplete-endAdornment\": {\r\n display: \"none\",\r\n },\r\n // Hide the underline without using slotProps.input.disableUnderline which clears out chips\r\n ...(disableUnderline && {\r\n \"& .MuiInput-underline:before\": { borderBottom: \"none\" },\r\n \"& .MuiInput-underline:after\": { borderBottom: \"none\" },\r\n \"& .MuiInput-underline:hover:not(.Mui-disabled):before\": { borderBottom: \"none\" },\r\n }),\r\n },\r\n }\r\n : {},\r\n ) as PropType;\r\n\r\nexport function isNonNullableString(value: any): value is NonNullable<string> {\r\nreturn value != null && typeof value === 'string';\r\n}","import { AutocompleteElement, type AutocompleteElementProps } from \"react-hook-form-mui\";\r\nimport { type ChipTypeMap } from \"@mui/material\";\r\nimport type { FieldPath, FieldValues } from \"react-hook-form\";\r\nimport { type ElementType, useMemo } from \"react\";\r\nimport lodash from \"lodash\";\r\nimport { getTextElementDisplayProps } from \"../utils\";\r\n\r\nconst { merge } = lodash;\r\n\r\nexport type AutocompleteElementDisplayProps<\r\n TValue,\r\n Multiple extends boolean | undefined,\r\n DisableClearable extends boolean | undefined,\r\n FreeSolo extends boolean | undefined,\r\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\r\n> = AutocompleteElementProps<\r\n TValue,\r\n Multiple,\r\n DisableClearable,\r\n FreeSolo,\r\n ChipComponent,\r\n TFieldValues,\r\n TName\r\n> & {\r\n viewOnly?: boolean;\r\n disableUnderline?: boolean;\r\n}\r\n\r\nexport const AutocompleteElementDisplay = <\r\n TValue,\r\n Multiple extends boolean | undefined,\r\n DisableClearable extends boolean | undefined,\r\n FreeSolo extends boolean | undefined,\r\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\r\n>({\r\n viewOnly = undefined as boolean | undefined,\r\n disableUnderline,\r\n textFieldProps,\r\n autocompleteProps,\r\n ...props\r\n}: AutocompleteElementDisplayProps<\r\n TValue,\r\n Multiple,\r\n DisableClearable,\r\n FreeSolo,\r\n ChipComponent,\r\n TFieldValues,\r\n TName\r\n>) => {\r\n const autocompleteAdjustedProps: AutocompleteElementDisplayProps<\r\n TValue,\r\n Multiple,\r\n DisableClearable,\r\n FreeSolo,\r\n ChipComponent,\r\n TFieldValues,\r\n TName\r\n >[\"autocompleteProps\"] = useMemo(\r\n () =>\r\n merge<\r\n AutocompleteElementDisplayProps<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent, TFieldValues, TName>[\"autocompleteProps\"],\r\n AutocompleteElementDisplayProps<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent, TFieldValues, TName>[\"autocompleteProps\"],\r\n AutocompleteElementDisplayProps<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent, TFieldValues, TName>[\"autocompleteProps\"]\r\n >(\r\n {\r\n readOnly: viewOnly,\r\n disableClearable: autocompleteProps?.disableClearable || viewOnly as DisableClearable,\r\n disabled: viewOnly,\r\n\r\n },\r\n autocompleteProps,\r\n viewOnly\r\n ? {\r\n sx: {\r\n \".MuiAutocomplete-tag\": {\r\n opacity: \"1 !important\",\r\n },\r\n },\r\n }\r\n : {},\r\n ),\r\n [autocompleteProps, viewOnly],\r\n );\r\n\r\n const textFieldAdjustedProps= useMemo(\r\n () => getTextElementDisplayProps(textFieldProps, viewOnly, disableUnderline),\r\n [textFieldProps, viewOnly, disableUnderline],\r\n );\r\n\r\n return (\r\n <AutocompleteElement\r\n autocompleteProps={autocompleteAdjustedProps}\r\n textFieldProps={textFieldAdjustedProps}\r\n {...props}\r\n />\r\n );\r\n};\r\n\r\n\r\n","import { type ElementType, useMemo, useState, useEffect } from \"react\";\nimport {\n Checkbox,\n Chip,\n ListItem,\n type ChipProps,\n type ChipTypeMap,\n type ListItemProps,\n} from \"@mui/material\";\nimport type { FieldPath, FieldValue, FieldValues } from \"react-hook-form\";\nimport {\n AutocompleteElementDisplay,\n type AutocompleteElementDisplayProps,\n} from \"./AutocompleteElementDisplay\";\nimport { getAutocompleteTypedValue, isNonNullableString } from \"../utils\";\nimport { useController } from \"react-hook-form-mui\";\nimport { merge } from \"lodash\";\n\n/**\n * Interface for special \"add option\" objects used in freeSolo mode\n * These objects represent a new item that can be created from user input\n */\ninterface AddOptionType {\n __isAddOption: true;\n inputValue: string;\n\n [key: string]: any; // Allow for additional properties from stringToNewItem\n}\n\n/**\n * Extends AutocompleteElementDisplayProps with additional properties for handling object values.\n *\n * @template TValue - The type of the option values\n * @template Multiple - Boolean flag indicating if multiple selections are allowed\n * @template DisableClearable - Boolean flag indicating if clearing the selection is disabled\n * @template FreeSolo - Boolean flag indicating if free text input is allowed\n * @template ChipComponent - The component type used for rendering chips in multiple selection mode\n * @template TFieldValues - The type of the form values\n * @template TName - The type of the field name\n */\nexport type ObjectElementDisplayProps<\n TValue,\n Multiple extends boolean | undefined,\n DisableClearable extends boolean | undefined,\n FreeSolo extends boolean | undefined,\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = AutocompleteElementDisplayProps<\n TValue,\n Multiple,\n DisableClearable,\n FreeSolo,\n ChipComponent,\n TFieldValues,\n TName\n> & {\n /**\n * Function to extract a unique key from an option value.\n * Used for option comparison and deduplication.\n *\n * @param value - The option value or null\n * @returns A unique string key for the value\n */\n getItemKey: (value: TValue | null) => string;\n\n /**\n * Function to generate a display label for an option value.\n * Can return any ReactNode for custom rendering.\n *\n * @param value - The option value or null\n * @returns A string to display as the option label\n */\n getItemLabel: (value: TValue | null) => string;\n\n /**\n * Function to get additional props for an option list item.\n * Used for customizing the rendering of the option.\n *\n * @param value - The option value or null\n * @returns Additional props to apply to the list item\n */\n getOptionProps?: (value: TValue | null) => ListItemProps;\n\n /**\n * Function to convert a free text input string to a TValue object.\n * Required when freeSolo is true to create new items from text input.\n *\n * @param value - The string value entered by the user\n * @returns A new TValue object created from the string\n */\n stringToNewItem?: (value: string) => TValue;\n\n /**\n * Whether the input allows free text entry.\n * When true, users can enter values that are not in the options.\n */\n freeSolo?: FreeSolo;\n\n /**\n * Optional function that returns additional chip props based on the value.\n * This allows for customizing chip appearance and behavior based on the value it represents.\n *\n * @param value - The option value being rendered as a chip\n * @returns Additional props to apply to the Chip component\n */\n getChipProps?: (props: { value: TValue; index: number }) => Partial<ChipProps> | undefined;\n\n /**\n * Optional function to transform the value before it's updated in the form.\n * This allows for custom processing or enrichment of the selected value.\n *\n * @param value - The value that would normally be sent to the form\n * @returns The transformed value to be stored in the form\n */\n transformValue?: (\n value: Multiple extends true ? TValue[] : TValue | null\n ) => FieldValue<FieldValues>;\n};\n\n/**\n * A form component that displays a searchable dropdown for selecting object values.\n * Extends AutocompleteElementDisplay with object-specific functionality.\n *\n * Features:\n * - Works with complex object values instead of just primitive types\n * - Supports both single and multiple selection modes\n * - Supports free-solo mode for creating new items from text input\n * - Handles initial values that aren't in the default options\n * - Deduplicates options based on item keys\n *\n * @template TValue - The type of the option values\n * @template Multiple - Boolean flag indicating if multiple selections are allowed\n * @template DisableClearable - Boolean flag indicating if clearing the selection is disabled\n * @template FreeSolo - Boolean flag indicating if free text input is allowed\n * @template ChipComponent - The component type used for rendering chips in multiple selection mode\n * @template TFieldValues - The type of the form values\n * @template TName - The type of the field name\n *\n * @returns A React component for selecting object values\n */\nexport const ObjectElementDisplay = <\n TValue,\n Multiple extends boolean | undefined,\n DisableClearable extends boolean | undefined,\n FreeSolo extends boolean | undefined,\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n options,\n autocompleteProps,\n getItemKey,\n getItemLabel,\n getChipProps,\n stringToNewItem,\n transformValue,\n name,\n freeSolo,\n control,\n getOptionProps,\n ...props\n}: ObjectElementDisplayProps<\n TValue,\n Multiple,\n DisableClearable,\n FreeSolo,\n ChipComponent,\n TFieldValues,\n TName\n>) => {\n /**\n * Access to the form field controller\n */\n const { field } = useController({ name, control });\n\n /**\n * State for storing dynamically added options that aren't in the original options list\n * Includes both default values and values added during freeSolo mode\n */\n const [newOptions, setNewOptions] = useState<TValue[]>(() => {\n if (!field.value) return [];\n\n // Convert field value to array for consistent handling\n const fieldValues: TValue[] = Array.isArray(field.value) ? field.value : [field.value];\n\n // Keep only object values that don't exist in the options array\n return fieldValues.filter(\n (value) =>\n typeof value !== \"string\" &&\n !options.some((option) => getItemKey(option) === getItemKey(value)),\n );\n });\n\n /**\n * Update newOptions when field.value changes\n * This ensures that any new values added to the field after rendering\n * are properly included in newOptions and displayed\n */\n useEffect(() => {\n if (!field.value) return;\n\n const fieldValues: TValue[] = Array.isArray(field.value) ? field.value : [field.value];\n const newFieldOptions = fieldValues.filter(\n (value) =>\n typeof value !== \"string\" &&\n ![...options, ...newOptions].some((option) => getItemKey(option) === getItemKey(value)),\n );\n\n // Only update newOptions if there are new values to add\n if (newFieldOptions.length > 0) {\n setNewOptions((prevOptions) => [...prevOptions, ...newFieldOptions]);\n }\n }, [field.value, options, newOptions, getItemKey]);\n\n /**\n * Combined list of all available options (original + dynamically added)\n */\n const allOptions = useMemo(() => {\n const seen = new Set();\n return [...options, ...newOptions].filter((option) => {\n const key = getItemKey(option);\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n })\n }, [options, newOptions]);\n\n return (\n <AutocompleteElementDisplay\n name={name}\n control={control}\n options={allOptions}\n {...props}\n autocompleteProps={{\n /**\n * Determines if two options should be considered equal\n * Uses the getItemKey function to compare option values\n */\n isOptionEqualToValue: (o, v) => getItemKey(o) === getItemKey(v),\n\n /**\n * Filters options based on the input value\n * Checks if the option key or label contains the input value (case-insensitive)\n * For freeSolo mode, adds a special \"Add [value]\" option when there's no exact match\n */\n filterOptions: (options, { inputValue }) => {\n if (!inputValue) return options;\n\n const searchValue = inputValue.toLowerCase();\n\n // Filter options that match the input value (by key or label)\n const filteredOptions = options.filter((option) => {\n const key = getItemKey(option).toLowerCase();\n const label = String(getItemLabel(option)).toLowerCase();\n return key.includes(searchValue) || label.includes(searchValue);\n });\n\n // For freeSolo mode, add \"Add [value]\" option if no exact match exists\n if (freeSolo && stringToNewItem && inputValue.length > 0) {\n const hasExactMatch = filteredOptions.some(\n (option) => String(getItemLabel(option)).toLowerCase() === searchValue,\n );\n\n if (!hasExactMatch) {\n // Create a special option with a __isAddOption flag\n const addOption: AddOptionType = {\n __isAddOption: true,\n inputValue,\n ...stringToNewItem(inputValue), // Include properties for type compatibility\n };\n\n return [addOption as unknown as TValue, ...filteredOptions];\n }\n }\n\n return filteredOptions;\n },\n freeSolo, // Allowed to enter own string value\n autoComplete: true,\n autoHighlight: true, // The first option is highlighted by default\n openOnFocus: true, // Opens the menu when tabbed into\n\n /**\n * Custom rendering for each option in the dropdown list\n * Handles both regular options and special \"Add\" options in freeSolo mode\n */\n renderOption: (liProps, option, { selected }, ownerState) => {\n const itemProps = merge(liProps, getOptionProps?.(option) ?? {});\n\n // Handles the special \"Add\" option in freeSolo mode\n if (\n ownerState?.freeSolo &&\n typeof option === \"object\" &&\n option !== null &&\n \"__isAddOption\" in option\n ) {\n const inputValue = (option as unknown as AddOptionType).inputValue;\n return (\n <ListItem {...itemProps} key={`${name}-add-option-${inputValue}`}>\n Add: '{inputValue}'\n </ListItem>\n );\n }\n\n // Handle regular option\n return (\n <ListItem {...itemProps} key={`${name}-option-${getItemKey(option)}`}>\n {(props?.showCheckbox && ownerState?.multiple) && (\n <Checkbox sx={{ marginRight: 1 }} checked={selected} />\n )}\n {typeof option === \"string\" ? option : getItemLabel(option)}\n </ListItem>\n );\n },\n\n onChange: (event, value, reason, details) => {\n /**\n * Helper function to apply transformValue if provided, otherwise return the original value\n */\n const applyTransform = (val: any) => {\n return transformValue && val !== null\n ? field.onChange(transformValue(val))\n : field.onChange(val);\n };\n\n /**\n * Helper function to add a new item to newOptions if it doesn't exist already\n */\n const addToNewOptions = (item: TValue) => {\n const itemKey = getItemKey(item);\n const itemExists = [...options, ...newOptions].some(\n (option) => getItemKey(option) === itemKey,\n );\n\n if (!itemExists) {\n setNewOptions((prev) => [...prev, item]);\n }\n };\n\n /**\n * Helper function to extract input value from string or AddOption\n */\n const getInputValue = (item: any): string | null => {\n if (typeof item === \"string\" && item.length > 0) {\n return item;\n }\n if (typeof item === \"object\" && item !== null && \"__isAddOption\" in item) {\n return (item as unknown as AddOptionType).inputValue;\n }\n return null;\n };\n\n // Handle freeSolo mode with stringToNewItem function\n if (freeSolo && stringToNewItem) {\n // Handle special add option selection or string input\n const inputValue = getInputValue(value);\n\n if (inputValue) {\n const newItem = stringToNewItem(inputValue);\n\n if (props.multiple) {\n // For multiple selection, add the new item to the current values\n const currentValues = Array.isArray(field.value) ? field.value : [];\n const newValues = [...currentValues, newItem];\n applyTransform(newValues);\n } else {\n // For single selection, just use the new item\n applyTransform(newItem);\n }\n\n addToNewOptions(newItem);\n return;\n }\n\n // Handle array values (multiple selection)\n if (Array.isArray(value) && props.multiple) {\n // Convert any string values to objects and handle special add options\n const newValues =\n value?.map((item) => {\n const inputVal = getInputValue(item);\n return inputVal ? stringToNewItem(inputVal) : item;\n }) ?? [];\n\n applyTransform(newValues);\n\n // Add any new items to newOptions\n const allOptionsKeys = [...options, ...newOptions].map((option) =>\n getItemKey(option),\n );\n const newItems = newValues.filter(\n (item) => typeof item !== \"string\" && !allOptionsKeys.includes(getItemKey(item)),\n );\n\n if (newItems.length > 0) {\n setNewOptions((prev) => [...prev, ...newItems]);\n }\n return;\n }\n }\n\n // Default behavior for non-freeSolo cases\n if (transformValue && value !== null) {\n applyTransform(value as TValue | TValue[]);\n } else {\n autocompleteProps?.onChange?.(event, value, reason, details);\n }\n },\n\n /**\n * Custom rendering for the selected value(s)\n * For multiple selection, renders a Chip for each selected value\n * For single selection, renders the value as text\n * Uses getItemLabel to render the value labels\n */\n renderValue: (value, getItemProps, ownerState) => {\n const typedValue = getAutocompleteTypedValue(value, ownerState);\n\n // Handle array values (multiple selection)\n if (Array.isArray(typedValue)) {\n return typedValue.map((v, index) => {\n // @ts-expect-error a key is returned, and the linter doesn't pick this up\n const { key, ...chipProps } = getItemProps({ index });\n\n // Get the label - use string directly or extract from object\n const label = typeof v === \"string\" ? v : getItemLabel(v);\n\n // Get additional chip props if available\n const valueSpecificProps =\n typeof v !== \"string\" && getChipProps ? getChipProps({ value: v, index }) : {};\n\n return (\n <Chip\n key={`${name}-chip-${key}`}\n {...valueSpecificProps}\n {...chipProps}\n label={label}\n />\n );\n });\n }\n\n // Handles single value - return string or extracted label\n return isNonNullableString(typedValue)\n ? typedValue\n : typedValue\n ? getItemLabel(typedValue as NonNullable<TValue>)\n : \"\";\n },\n ...autocompleteProps,\n }}\n />\n );\n};\n","import { TextFieldElement, type TextFieldElementProps } from \"react-hook-form-mui\";\nimport { type FieldPath, type FieldValues } from \"react-hook-form\";\nimport { useMemo } from \"react\";\nimport { getTextElementDisplayProps } from \"../utils\";\n\nexport type TextElementDisplayProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> = TextFieldElementProps<TFieldValues, TName> & Viewable;\n\n/**\n * A form component that displays a text field with view-only capabilities.\n * Extends TextFieldElement with view-only functionality.\n *\n * @template TFieldValues - The type of the form values\n * @template TName - The type of the field name\n *\n * @returns A React component for text input with view-only support\n */\nexport const TextElementDisplay = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n viewOnly,\n disableUnderline,\n ...props\n}: TextElementDisplayProps<TFieldValues, TName>) => {\n\n const adjustedProps = useMemo(\n () => getTextElementDisplayProps(props, viewOnly, disableUnderline),\n [props, viewOnly, disableUnderline],\n );\n\n return <TextFieldElement {...adjustedProps} />;\n};\n\ntype Viewable = {\n viewOnly?: boolean;\n disableUnderline?: boolean;\n};\n","import { FieldError, FieldErrors, FieldValues } from 'react-hook-form';\r\nimport lodash from 'lodash';\r\nconst { get } = lodash;\r\n\r\n/**\r\n * A hook to get the error message for a field from react-hook-form\r\n * @param errors The errors object from react-hook-form\r\n * @param name The name of the field (supports dot notation for nested fields)\r\n * @returns An object with error and helperText properties\r\n */\r\nexport function useFormError<T extends FieldValues>(\r\n errors: FieldErrors<T>,\r\n name: string\r\n): { error: boolean; helperText: string } {\r\n // Get the error for the field, supporting nested paths with dot notation\r\n const fieldError = get(errors, name) as FieldError | undefined;\r\n\r\n // Return error state and helper text\r\n return {\r\n error: !!fieldError,\r\n helperText: fieldError?.message || '',\r\n };\r\n}\r\n","// src/hooks/useOnMount.ts\r\nimport { useEffect, useRef } from \"react\";\r\n\r\n/**\r\n * Runs a provided callback function once on the first component mount.\r\n *\r\n * @param callback - The function to run on first mount.\r\n */\r\nexport function useOnMount(callback: () => void): void {\r\n const hasMounted = useRef(false);\r\n\r\n useEffect(() => {\r\n if (!hasMounted.current) {\r\n callback();\r\n hasMounted.current = true;\r\n }\r\n\r\n // Cleanup to prevent callback logic from running during cleanup\r\n return () => {\r\n hasMounted.current = true;\r\n };\r\n \r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, []);\r\n}\r\n\r\n","import type { JSX } from \"react\";\r\nimport { FormControl, FormHelperText } from \"@mui/material\";\r\nimport type { FormControlProps } from \"@mui/material\";\r\nimport { useFormContext, type RegisterOptions, type FieldValues, type Path } from \"react-hook-form\";\r\nimport { useFormError } from \"../hooks\";\r\n\r\n/**\r\n * Props for the RHFHiddenInput component\r\n */\r\nexport interface ValidationElementProps<TFieldValues extends FieldValues> {\r\n /**\r\n * Name of the field in the form\r\n */\r\n name: Path<TFieldValues>;\r\n /**\r\n * Optional validation rules\r\n */\r\n rules: RegisterOptions<TFieldValues>;\r\n /**\r\n * Props to pass to the FormControl component\r\n */\r\n formControlProps?: Omit<FormControlProps, \"error\">;\r\n}\r\n\r\nexport const ValidationElement = <TFieldValues extends FieldValues = FieldValues>({\r\n name,\r\n rules,\r\n formControlProps = {},\r\n}: ValidationElementProps<TFieldValues>): JSX.Element => {\r\n const {\r\n register,\r\n formState: { errors },\r\n } = useFormContext<TFieldValues>();\r\n\r\n const { error, helperText } = useFormError(errors, name);\r\n\r\n return (\r\n <FormControl error={error} {...formControlProps}>\r\n <input type=\"hidden\" {...register(name, rules)} />\r\n {error && <FormHelperText>{helperText}</FormHelperText>}\r\n </FormControl>\r\n );\r\n};\r\n"],"names":["merge","lodash","getAutocompleteTypedValue","value","ownerState","getTextElementDisplayProps","props","viewOnly","disableUnderline","isNonNullableString","AutocompleteElementDisplay","textFieldProps","autocompleteProps","autocompleteAdjustedProps","useMemo","textFieldAdjustedProps","jsx","AutocompleteElement","ObjectElementDisplay","options","getItemKey","getItemLabel","getChipProps","stringToNewItem","transformValue","name","freeSolo","control","getOptionProps","field","useController","newOptions","setNewOptions","useState","option","useEffect","newFieldOptions","prevOptions","allOptions","seen","key","o","v","inputValue","searchValue","filteredOptions","label","liProps","selected","itemProps","createElement","ListItem","Checkbox","event","reason","details","applyTransform","val","addToNewOptions","item","itemKey","prev","getInputValue","newItem","newValues","inputVal","allOptionsKeys","newItems","getItemProps","typedValue","index","chipProps","valueSpecificProps","Chip","TextElementDisplay","adjustedProps","TextFieldElement","get","useFormError","errors","fieldError","useOnMount","callback","hasMounted","useRef","ValidationElement","rules","formControlProps","register","useFormContext","error","helperText","jsxs","FormControl","FormHelperText"],"mappings":";;;;;;AAWA,MAAM,EAAA,OAAEA,MAAUC;AAEX,SAASC,EAOdC,GAGAC,GACA;AACA,SAAIA,GAAY,UACVA,GAAY,UAAiBD;AAMrC;AAGO,MAAME,IAA6B,CACxCC,GACAC,IAAW,IACXC,IAAmB,OAEnBR;AAAAA,E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AA5D;AAAA,EACA,OAAA6D;AAAA,EACA,kBAAAC,IAAmB,CAAA;AACrB,MAAyD;AACvD,QAAM;AAAA,IACJ,UAAAC;AAAA,IACA,WAAW,EAAE,QAAAT,EAAA;AAAA,EAAO,IAClBU,EAAA,GAEE,EAAE,OAAAC,GAAO,YAAAC,EAAA,IAAeb,GAAaC,GAAQtD,CAAI;AAEvD,SACE,gBAAAmE,EAACC,GAAA,EAAY,OAAAH,GAAe,GAAGH,GAC7B,UAAA;AAAA,IAAA,gBAAAvE,EAAC,WAAM,MAAK,UAAU,GAAGwE,EAAS/D,GAAM6D,CAAK,GAAG;AAAA,IAC/CI,KAAS,gBAAA1E,EAAC8E,GAAA,EAAgB,UAAAH,EAAA,CAAW;AAAA,EAAA,GACxC;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/utils.ts","../src/components/AutocompleteElementDisplay.tsx","../src/components/ObjectElementDisplay.tsx","../src/components/TextElementDisplay.tsx","../src/hooks/useFormError.ts","../src/hooks/useOnMount.ts","../src/components/ValidationElement.tsx"],"sourcesContent":["import type {\r\n AutocompleteOwnerState,\r\n AutocompleteRenderValue,\r\n AutocompleteValue,\r\n ChipTypeMap,\r\n TextFieldProps,\r\n} from \"@mui/material\";\r\nimport { ElementType } from \"react\";\r\n\r\nimport lodash from \"lodash\";\r\n\r\nconst { merge } = lodash;\r\n\r\nexport function getAutocompleteTypedValue<\r\n TValue,\r\n Multiple extends boolean | undefined,\r\n DisableClearable extends boolean | undefined,\r\n FreeSolo extends boolean | undefined,\r\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\r\n>(\r\n value:\r\n | AutocompleteRenderValue<TValue, Multiple, FreeSolo>\r\n | AutocompleteValue<TValue, Multiple, DisableClearable, FreeSolo>,\r\n ownerState?: AutocompleteOwnerState<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent>,\r\n) {\r\n if (ownerState?.multiple) {\r\n if (ownerState?.freeSolo) return value as Array<TValue | string>;\r\n return value as TValue[];\r\n } else if (ownerState?.freeSolo) {\r\n return value as NonNullable<TValue | string>;\r\n }\r\n return value as NonNullable<TValue>;\r\n}\r\n\r\n// Apply view-only properties directly to the TextFieldElement props\r\nexport const getTextElementDisplayProps = <PropType>(\r\n props: PropType,\r\n viewOnly = false,\r\n disableUnderline = false,\r\n) =>\r\n merge<PropType, Partial<TextFieldProps>>(\r\n props,\r\n viewOnly\r\n ? {\r\n disabled: true,\r\n variant: \"standard\",\r\n sx: {\r\n \"& .MuiAutocomplete-endAdornment\": {\r\n display: \"none\",\r\n },\r\n // Hide the underline without using slotProps.input.disableUnderline which clears out chips\r\n ...(disableUnderline && {\r\n \"& .MuiInput-underline:before\": { borderBottom: \"none\" },\r\n \"& .MuiInput-underline:after\": { borderBottom: \"none\" },\r\n \"& .MuiInput-underline:hover:not(.Mui-disabled):before\": { borderBottom: \"none\" },\r\n }),\r\n },\r\n }\r\n : {},\r\n ) as PropType;\r\n\r\nexport function isNonNullableString(value: any): value is NonNullable<string> {\r\nreturn value != null && typeof value === 'string';\r\n}","import { AutocompleteElement, type AutocompleteElementProps } from \"react-hook-form-mui\";\r\nimport { type ChipTypeMap } from \"@mui/material\";\r\nimport type { FieldPath, FieldValues } from \"react-hook-form\";\r\nimport { type ElementType, useMemo } from \"react\";\r\nimport lodash from \"lodash\";\r\nimport { getTextElementDisplayProps } from \"../utils\";\r\n\r\nconst { merge } = lodash;\r\n\r\nexport type AutocompleteElementDisplayProps<\r\n TValue,\r\n Multiple extends boolean | undefined,\r\n DisableClearable extends boolean | undefined,\r\n FreeSolo extends boolean | undefined,\r\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\r\n> = AutocompleteElementProps<\r\n TValue,\r\n Multiple,\r\n DisableClearable,\r\n FreeSolo,\r\n ChipComponent,\r\n TFieldValues,\r\n TName\r\n> & {\r\n viewOnly?: boolean;\r\n disableUnderline?: boolean;\r\n}\r\n\r\nexport const AutocompleteElementDisplay = <\r\n TValue,\r\n Multiple extends boolean | undefined,\r\n DisableClearable extends boolean | undefined,\r\n FreeSolo extends boolean | undefined,\r\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\r\n TFieldValues extends FieldValues = FieldValues,\r\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\r\n>({\r\n viewOnly = undefined as boolean | undefined,\r\n disableUnderline,\r\n textFieldProps,\r\n autocompleteProps,\r\n ...props\r\n}: AutocompleteElementDisplayProps<\r\n TValue,\r\n Multiple,\r\n DisableClearable,\r\n FreeSolo,\r\n ChipComponent,\r\n TFieldValues,\r\n TName\r\n>) => {\r\n const autocompleteAdjustedProps: AutocompleteElementDisplayProps<\r\n TValue,\r\n Multiple,\r\n DisableClearable,\r\n FreeSolo,\r\n ChipComponent,\r\n TFieldValues,\r\n TName\r\n >[\"autocompleteProps\"] = useMemo(\r\n () =>\r\n merge<\r\n AutocompleteElementDisplayProps<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent, TFieldValues, TName>[\"autocompleteProps\"],\r\n AutocompleteElementDisplayProps<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent, TFieldValues, TName>[\"autocompleteProps\"],\r\n AutocompleteElementDisplayProps<TValue, Multiple, DisableClearable, FreeSolo, ChipComponent, TFieldValues, TName>[\"autocompleteProps\"]\r\n >(\r\n {\r\n readOnly: viewOnly,\r\n disableClearable: autocompleteProps?.disableClearable || viewOnly as DisableClearable,\r\n disabled: viewOnly,\r\n\r\n },\r\n autocompleteProps,\r\n viewOnly\r\n ? {\r\n sx: {\r\n \".MuiAutocomplete-tag\": {\r\n opacity: \"1 !important\",\r\n },\r\n },\r\n }\r\n : {},\r\n ),\r\n [autocompleteProps, viewOnly],\r\n );\r\n\r\n const textFieldAdjustedProps= useMemo(\r\n () => getTextElementDisplayProps(textFieldProps, viewOnly, disableUnderline),\r\n [textFieldProps, viewOnly, disableUnderline],\r\n );\r\n\r\n return (\r\n <AutocompleteElement\r\n autocompleteProps={autocompleteAdjustedProps}\r\n textFieldProps={textFieldAdjustedProps}\r\n {...props}\r\n />\r\n );\r\n};\r\n\r\n\r\n","import { type ElementType, useMemo, useState, useEffect } from \"react\";\nimport {\n Checkbox,\n Chip,\n ListItem,\n type ChipProps,\n type ChipTypeMap,\n type ListItemProps,\n} from \"@mui/material\";\nimport type { FieldPath, FieldValue, FieldValues } from \"react-hook-form\";\nimport {\n AutocompleteElementDisplay,\n type AutocompleteElementDisplayProps,\n} from \"./AutocompleteElementDisplay\";\nimport { getAutocompleteTypedValue, isNonNullableString } from \"../utils\";\nimport { useController } from \"react-hook-form-mui\";\nimport { merge } from \"lodash\";\n\n/**\n * Interface for special \"add option\" objects used in freeSolo mode\n * These objects represent a new item that can be created from user input\n */\ninterface AddOptionType {\n __isAddOption: true;\n inputValue: string;\n\n [key: string]: any; // Allow for additional properties from stringToNewItem\n}\n\n/**\n * Extends AutocompleteElementDisplayProps with additional properties for handling object values.\n *\n * @template TValue - The type of the option values\n * @template Multiple - Boolean flag indicating if multiple selections are allowed\n * @template DisableClearable - Boolean flag indicating if clearing the selection is disabled\n * @template FreeSolo - Boolean flag indicating if free text input is allowed\n * @template ChipComponent - The component type used for rendering chips in multiple selection mode\n * @template TFieldValues - The type of the form values\n * @template TName - The type of the field name\n */\nexport type ObjectElementDisplayProps<\n TValue,\n Multiple extends boolean | undefined,\n DisableClearable extends boolean | undefined,\n FreeSolo extends boolean | undefined,\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n> = AutocompleteElementDisplayProps<\n TValue,\n Multiple,\n DisableClearable,\n FreeSolo,\n ChipComponent,\n TFieldValues,\n TName\n> & {\n /**\n * Function to extract a unique key from an option value.\n * Used for option comparison and deduplication.\n *\n * @param value - The option value or null\n * @returns A unique string key for the value\n */\n getItemKey: (value: TValue | null) => string | null;\n\n /**\n * Function to generate a display label for an option value.\n * Can return any ReactNode for custom rendering.\n *\n * @param value - The option value or null\n * @returns A string to display as the option label\n */\n getItemLabel: (value: TValue | null) => string | null;\n\n /**\n * Function to get additional props for an option list item.\n * Used for customizing the rendering of the option.\n *\n * @param value - The option value or null\n * @returns Additional props to apply to the list item\n */\n getOptionProps?: (value: TValue | null) => ListItemProps;\n\n /**\n * Function to convert a free text input string to a TValue object.\n * Required when freeSolo is true to create new items from text input.\n *\n * @param value - The string value entered by the user\n * @returns A new TValue object created from the string\n */\n stringToNewItem?: (value: string) => TValue;\n\n /**\n * Whether the input allows free text entry.\n * When true, users can enter values that are not in the options.\n */\n freeSolo?: FreeSolo;\n\n /**\n * Optional function that returns additional chip props based on the value.\n * This allows for customizing chip appearance and behavior based on the value it represents.\n *\n * @param value - The option value being rendered as a chip\n * @returns Additional props to apply to the Chip component\n */\n getChipProps?: (props: { value: TValue; index: number }) => Partial<ChipProps> | undefined;\n\n /**\n * Optional function to transform the value before it's updated in the form.\n * This allows for custom processing or enrichment of the selected value.\n *\n * @param value - The value that would normally be sent to the form\n * @returns The transformed value to be stored in the form\n */\n transformValue?: (\n value: Multiple extends true ? TValue[] : TValue | null\n ) => FieldValue<FieldValues>;\n};\n\n/**\n * A form component that displays a searchable dropdown for selecting object values.\n * Extends AutocompleteElementDisplay with object-specific functionality.\n *\n * Features:\n * - Works with complex object values instead of just primitive types\n * - Supports both single and multiple selection modes\n * - Supports free-solo mode for creating new items from text input\n * - Handles initial values that aren't in the default options\n * - Deduplicates options based on item keys\n *\n * @template TValue - The type of the option values\n * @template Multiple - Boolean flag indicating if multiple selections are allowed\n * @template DisableClearable - Boolean flag indicating if clearing the selection is disabled\n * @template FreeSolo - Boolean flag indicating if free text input is allowed\n * @template ChipComponent - The component type used for rendering chips in multiple selection mode\n * @template TFieldValues - The type of the form values\n * @template TName - The type of the field name\n *\n * @returns A React component for selecting object values\n */\nexport const ObjectElementDisplay = <\n TValue,\n Multiple extends boolean | undefined,\n DisableClearable extends boolean | undefined,\n FreeSolo extends boolean | undefined,\n ChipComponent extends ElementType = ChipTypeMap[\"defaultComponent\"],\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n options,\n autocompleteProps,\n getItemKey,\n getItemLabel,\n getChipProps,\n stringToNewItem,\n transformValue,\n name,\n freeSolo,\n control,\n getOptionProps,\n ...props\n}: ObjectElementDisplayProps<\n TValue,\n Multiple,\n DisableClearable,\n FreeSolo,\n ChipComponent,\n TFieldValues,\n TName\n>) => {\n /**\n * Access to the form field controller\n */\n const { field } = useController({ name, control });\n\n /**\n * State for storing dynamically added options that aren't in the original options list\n * Includes both default values and values added during freeSolo mode\n */\n const [newOptions, setNewOptions] = useState<TValue[]>(() => {\n if (!field.value) return [];\n\n // Convert field value to array for consistent handling\n const fieldValues: TValue[] = Array.isArray(field.value) ? field.value : [field.value];\n\n // Keep only object values that don't exist in the options array\n return fieldValues.filter(\n (value) =>\n typeof value !== \"string\" &&\n !options.some((option) => getItemKey(option) === getItemKey(value)),\n );\n });\n\n /**\n * Update newOptions when field.value changes\n * This ensures that any new values added to the field after rendering\n * are properly included in newOptions and displayed\n */\n useEffect(() => {\n if (!field.value) return;\n\n const fieldValues: TValue[] = Array.isArray(field.value) ? field.value : [field.value];\n const newFieldOptions = fieldValues.filter(\n (value) =>\n typeof value !== \"string\" &&\n ![...options, ...newOptions].some((option) => getItemKey(option) === getItemKey(value)),\n );\n\n // Only update newOptions if there are new values to add\n if (newFieldOptions.length > 0) {\n setNewOptions((prevOptions) => [...prevOptions, ...newFieldOptions]);\n }\n }, [field.value, options, newOptions, getItemKey]);\n\n /**\n * Combined list of all available options (original + dynamically added)\n */\n const allOptions = useMemo(() => {\n const seen = new Set();\n return [...options, ...newOptions].filter((option) => {\n const key = getItemKey(option);\n if (seen.has(key)) return false;\n seen.add(key);\n return true;\n })\n }, [options, newOptions]);\n\n return (\n <AutocompleteElementDisplay\n name={name}\n control={control}\n options={allOptions}\n {...props}\n autocompleteProps={{\n /**\n * Determines if two options should be considered equal\n * Uses the getItemKey function to compare option values\n */\n isOptionEqualToValue: (o, v) => getItemKey(o) === getItemKey(v),\n\n /**\n * Filters options based on the input value\n * Checks if the option key or label contains the input value (case-insensitive)\n * For freeSolo mode, adds a special \"Add [value]\" option when there's no exact match\n */\n filterOptions: (options, { inputValue }) => {\n if (!inputValue) return options;\n\n const searchValue = inputValue.toLowerCase();\n\n // Filter options that match the input value (by key or label)\n const filteredOptions = options.filter((option) => {\n const key = getItemKey(option)?.toLowerCase();\n const label = String(getItemLabel(option)).toLowerCase();\n return key?.includes(searchValue) || label.includes(searchValue);\n });\n\n // For freeSolo mode, add \"Add [value]\" option if no exact match exists\n if (freeSolo && stringToNewItem && inputValue.length > 0) {\n const hasExactMatch = filteredOptions.some(\n (option) => String(getItemLabel(option)).toLowerCase() === searchValue,\n );\n\n if (!hasExactMatch) {\n // Create a special option with a __isAddOption flag\n const addOption: AddOptionType = {\n __isAddOption: true,\n inputValue,\n ...stringToNewItem(inputValue), // Include properties for type compatibility\n };\n\n return [addOption as unknown as TValue, ...filteredOptions];\n }\n }\n\n return filteredOptions;\n },\n freeSolo, // Allowed to enter own string value\n autoComplete: true,\n autoHighlight: true, // The first option is highlighted by default\n openOnFocus: true, // Opens the menu when tabbed into\n\n /**\n * Custom rendering for each option in the dropdown list\n * Handles both regular options and special \"Add\" options in freeSolo mode\n */\n renderOption: (liProps, option, { selected }, ownerState) => {\n const itemProps = merge(liProps, getOptionProps?.(option) ?? {});\n\n // Handles the special \"Add\" option in freeSolo mode\n if (\n ownerState?.freeSolo &&\n typeof option === \"object\" &&\n option !== null &&\n \"__isAddOption\" in option\n ) {\n const inputValue = (option as unknown as AddOptionType).inputValue;\n return (\n <ListItem {...itemProps} key={`${name}-add-option-${inputValue}`}>\n Add: '{inputValue}'\n </ListItem>\n );\n }\n\n // Handle regular option\n return (\n <ListItem {...itemProps} key={`${name}-option-${getItemKey(option)}`}>\n {(props?.showCheckbox && ownerState?.multiple) && (\n <Checkbox sx={{ marginRight: 1 }} checked={selected} />\n )}\n {typeof option === \"string\" ? option : getItemLabel(option)}\n </ListItem>\n );\n },\n\n onChange: (event, value, reason, details) => {\n /**\n * Helper function to apply transformValue if provided, otherwise return the original value\n */\n const applyTransform = (val: any) => {\n return transformValue && val !== null\n ? field.onChange(transformValue(val))\n : field.onChange(val);\n };\n\n /**\n * Helper function to add a new item to newOptions if it doesn't exist already\n */\n const addToNewOptions = (item: TValue) => {\n const itemKey = getItemKey(item);\n const itemExists = [...options, ...newOptions].some(\n (option) => getItemKey(option) === itemKey,\n );\n\n if (!itemExists) {\n setNewOptions((prev) => [...prev, item]);\n }\n };\n\n /**\n * Helper function to extract input value from string or AddOption\n */\n const getInputValue = (item: any): string | null => {\n if (typeof item === \"string\" && item.length > 0) {\n return item;\n }\n if (typeof item === \"object\" && item !== null && \"__isAddOption\" in item) {\n return (item as unknown as AddOptionType).inputValue;\n }\n return null;\n };\n\n // Handle freeSolo mode with stringToNewItem function\n if (freeSolo && stringToNewItem) {\n // Handle special add option selection or string input\n const inputValue = getInputValue(value);\n\n if (inputValue) {\n const newItem = stringToNewItem(inputValue);\n\n if (props.multiple) {\n // For multiple selection, add the new item to the current values\n const currentValues = Array.isArray(field.value) ? field.value : [];\n const newValues = [...currentValues, newItem];\n applyTransform(newValues);\n } else {\n // For single selection, just use the new item\n applyTransform(newItem);\n }\n\n addToNewOptions(newItem);\n return;\n }\n\n // Handle array values (multiple selection)\n if (Array.isArray(value) && props.multiple) {\n // Convert any string values to objects and handle special add options\n const newValues =\n value?.map((item) => {\n const inputVal = getInputValue(item);\n return inputVal ? stringToNewItem(inputVal) : item;\n }) ?? [];\n\n applyTransform(newValues);\n\n // Add any new items to newOptions\n const allOptionsKeys = [...options, ...newOptions].map((option) =>\n getItemKey(option),\n );\n const newItems = newValues.filter(\n (item) => typeof item !== \"string\" && !allOptionsKeys.includes(getItemKey(item)),\n );\n\n if (newItems.length > 0) {\n setNewOptions((prev) => [...prev, ...newItems]);\n }\n return;\n }\n }\n\n // Default behavior for non-freeSolo cases\n if (transformValue && value !== null) {\n applyTransform(value as TValue | TValue[]);\n } else {\n autocompleteProps?.onChange?.(event, value, reason, details);\n }\n },\n\n /**\n * Custom rendering for the selected value(s)\n * For multiple selection, renders a Chip for each selected value\n * For single selection, renders the value as text\n * Uses getItemLabel to render the value labels\n */\n renderValue: (value, getItemProps, ownerState) => {\n const typedValue = getAutocompleteTypedValue(value, ownerState);\n\n // Handle array values (multiple selection)\n if (Array.isArray(typedValue)) {\n return typedValue.map((v, index) => {\n // @ts-expect-error a key is returned, and the linter doesn't pick this up\n const { key, ...chipProps } = getItemProps({ index });\n\n // Get the label - use string directly or extract from object\n const label = typeof v === \"string\" ? v : getItemLabel(v);\n\n // Get additional chip props if available\n const valueSpecificProps =\n typeof v !== \"string\" && getChipProps ? getChipProps({ value: v, index }) : {};\n\n return (\n <Chip\n key={`${name}-chip-${key}`}\n {...valueSpecificProps}\n {...chipProps}\n label={label}\n />\n );\n });\n }\n\n // Handles single value - return string or extracted label\n return isNonNullableString(typedValue)\n ? typedValue\n : typedValue\n ? getItemLabel(typedValue as NonNullable<TValue>)\n : \"\";\n },\n ...autocompleteProps,\n }}\n />\n );\n};\n","import { TextFieldElement, type TextFieldElementProps } from \"react-hook-form-mui\";\nimport { type FieldPath, type FieldValues } from \"react-hook-form\";\nimport { useMemo } from \"react\";\nimport { getTextElementDisplayProps } from \"../utils\";\n\nexport type TextElementDisplayProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> = TextFieldElementProps<TFieldValues, TName> & Viewable;\n\n/**\n * A form component that displays a text field with view-only capabilities.\n * Extends TextFieldElement with view-only functionality.\n *\n * @template TFieldValues - The type of the form values\n * @template TName - The type of the field name\n *\n * @returns A React component for text input with view-only support\n */\nexport const TextElementDisplay = <\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>,\n>({\n viewOnly,\n disableUnderline,\n ...props\n}: TextElementDisplayProps<TFieldValues, TName>) => {\n\n const adjustedProps = useMemo(\n () => getTextElementDisplayProps(props, viewOnly, disableUnderline),\n [props, viewOnly, disableUnderline],\n );\n\n return <TextFieldElement {...adjustedProps} />;\n};\n\ntype Viewable = {\n viewOnly?: boolean;\n disableUnderline?: boolean;\n};\n","import { FieldError, FieldErrors, FieldValues } from 'react-hook-form';\r\nimport lodash from 'lodash';\r\nconst { get } = lodash;\r\n\r\n/**\r\n * A hook to get the error message for a field from react-hook-form\r\n * @param errors The errors object from react-hook-form\r\n * @param name The name of the field (supports dot notation for nested fields)\r\n * @returns An object with error and helperText properties\r\n */\r\nexport function useFormError<T extends FieldValues>(\r\n errors: FieldErrors<T>,\r\n name: string\r\n): { error: boolean; helperText: string } {\r\n // Get the error for the field, supporting nested paths with dot notation\r\n const fieldError = get(errors, name) as FieldError | undefined;\r\n\r\n // Return error state and helper text\r\n return {\r\n error: !!fieldError,\r\n helperText: fieldError?.message || '',\r\n };\r\n}\r\n","// src/hooks/useOnMount.ts\r\nimport { useEffect, useRef } from \"react\";\r\n\r\n/**\r\n * Runs a provided callback function once on the first component mount.\r\n *\r\n * @param callback - The function to run on first mount.\r\n */\r\nexport function useOnMount(callback: () => void): void {\r\n const hasMounted = useRef(false);\r\n\r\n useEffect(() => {\r\n if (!hasMounted.current) {\r\n callback();\r\n hasMounted.current = true;\r\n }\r\n\r\n // Cleanup to prevent callback logic from running during cleanup\r\n return () => {\r\n hasMounted.current = true;\r\n };\r\n \r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, []);\r\n}\r\n\r\n","import type { JSX } from \"react\";\r\nimport { FormControl, FormHelperText } from \"@mui/material\";\r\nimport type { FormControlProps } from \"@mui/material\";\r\nimport { useFormContext, type RegisterOptions, type FieldValues, type Path } from \"react-hook-form\";\r\nimport { useFormError } from \"../hooks\";\r\n\r\n/**\r\n * Props for the RHFHiddenInput component\r\n */\r\nexport interface ValidationElementProps<TFieldValues extends FieldValues> {\r\n /**\r\n * Name of the field in the form\r\n */\r\n name: Path<TFieldValues>;\r\n /**\r\n * Optional validation rules\r\n */\r\n rules: RegisterOptions<TFieldValues>;\r\n /**\r\n * Props to pass to the FormControl component\r\n */\r\n formControlProps?: Omit<FormControlProps, \"error\">;\r\n}\r\n\r\nexport const ValidationElement = <TFieldValues extends FieldValues = FieldValues>({\r\n name,\r\n rules,\r\n formControlProps = {},\r\n}: ValidationElementProps<TFieldValues>): JSX.Element => {\r\n const {\r\n register,\r\n formState: { errors },\r\n } = useFormContext<TFieldValues>();\r\n\r\n const { error, helperText } = useFormError(errors, name);\r\n\r\n return (\r\n <FormControl error={error} {...formControlProps}>\r\n <input type=\"hidden\" {...register(name, rules)} />\r\n {error && <FormHelperText>{helperText}</FormHelperText>}\r\n </FormControl>\r\n );\r\n};\r\n"],"names":["merge","lodash","getAutocompleteTypedValue","value","ownerState","getTextElementDisplayProps","props","viewOnly","disableUnderline","isNonNullableString","AutocompleteElementDisplay","textFieldProps","autocompleteProps","autocompleteAdjustedProps","useMemo","textFieldAdjustedProps","jsx","AutocompleteElement","ObjectElementDisplay","options","getItemKey","getItemLabel","getChipProps","stringToNewItem","transformValue","name","freeSolo","control","getOptionProps","field","useController","newOptions","setNewOptions","useState","option","useEffect","newFieldOptions","prevOptions","allOptions","seen","key","o","v","inputValue","searchValue","filteredOptions","label","liProps","selected","itemProps","createElement","ListItem","Checkbox","event","reason","details","applyTransform","val","addToNewOptions","item","itemKey","prev","getInputValue","newItem","newValues","inputVal","allOptionsKeys","newItems","getItemProps","typedValue","index","chipProps","valueSpecificProps","Chip","TextElementDisplay","adjustedProps","TextFieldElement","get","useFormError","errors","fieldError","useOnMount","callback","hasMounted","useRef","ValidationElement","rules","formControlProps","register","useFormContext","error","helperText","jsxs","FormControl","FormHelperText"],"mappings":";;;;;;AAWA,MA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