@soyfri/shared-library 4.0.2 → 4.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{Autocomplete-Bd3bN4Cw.cjs → Autocomplete-Baqwboth.cjs} +59 -38
- package/Autocomplete-Baqwboth.cjs.map +1 -0
- package/{Autocomplete-E5aSUGVK.js → Autocomplete-Cvf16lFk.js} +59 -38
- package/Autocomplete-Cvf16lFk.js.map +1 -0
- package/{DatePicker-D__RSgs-.js → DatePicker-D5BH4v1p.js} +3 -2
- package/{DatePicker-D__RSgs-.js.map → DatePicker-D5BH4v1p.js.map} +1 -1
- package/{DatePicker-CMcQddi1.cjs → DatePicker-mz7CYtVw.cjs} +3 -2
- package/{DatePicker-CMcQddi1.cjs.map → DatePicker-mz7CYtVw.cjs.map} +1 -1
- package/{DateTimePicker-LeaE716a.js → DateTimePicker-ZCf0Wh4r.js} +6 -2
- package/DateTimePicker-ZCf0Wh4r.js.map +1 -0
- package/{DateTimePicker-BVJGq1A0.cjs → DateTimePicker-ejQDpjgX.cjs} +6 -2
- package/DateTimePicker-ejQDpjgX.cjs.map +1 -0
- package/{Input-BibHlnGN.js → Input-CmvuMwXZ.js} +3 -2
- package/{Input-BibHlnGN.js.map → Input-CmvuMwXZ.js.map} +1 -1
- package/{Input-Bpjw7qwq.cjs → Input-hnQ7g6b7.cjs} +3 -2
- package/{Input-Bpjw7qwq.cjs.map → Input-hnQ7g6b7.cjs.map} +1 -1
- package/{Select-BIUq3ZPy.js → Select-CZ0BiKVN.js} +3 -2
- package/{Select-BIUq3ZPy.js.map → Select-CZ0BiKVN.js.map} +1 -1
- package/{Select-C06gHRqZ.cjs → Select-ZhFf4SBp.cjs} +3 -2
- package/{Select-C06gHRqZ.cjs.map → Select-ZhFf4SBp.cjs.map} +1 -1
- package/{StatusMessage-B3nXpuRl.cjs → StatusMessageContext-BMsbLKRq.cjs} +19 -1
- package/StatusMessageContext-BMsbLKRq.cjs.map +1 -0
- package/{StatusMessage-D0WgSBx7.js → StatusMessageContext-DgYiObYE.js} +21 -3
- package/StatusMessageContext-DgYiObYE.js.map +1 -0
- package/components/Autocomplete/Autocomplete.cjs +1 -1
- package/components/Autocomplete/Autocomplete.d.ts +30 -13
- package/components/Autocomplete/Autocomplete.helpers.d.ts +4 -4
- package/components/Autocomplete/Autocomplete.js +1 -1
- package/components/Autocomplete/_parts/AutocompleteChips.d.ts +7 -6
- package/components/Autocomplete/_parts/AutocompleteOption.d.ts +5 -5
- package/components/Autocomplete/index.d.ts +1 -1
- package/components/DatePicker/DatePicker.cjs +1 -1
- package/components/DatePicker/DatePicker.js +1 -1
- package/components/DateTimePicker/DateTimePicker.cjs +1 -1
- package/components/DateTimePicker/DateTimePicker.d.ts +9 -0
- package/components/DateTimePicker/DateTimePicker.js +1 -1
- package/components/Input/Input.cjs +1 -1
- package/components/Input/Input.js +1 -1
- package/components/Select/Select.cjs +1 -1
- package/components/Select/Select.js +1 -1
- package/components/StatusMessage/StatusMessage.cjs +5 -3
- package/components/StatusMessage/StatusMessage.cjs.map +1 -1
- package/components/StatusMessage/StatusMessage.js +4 -2
- package/components/StatusMessage/index.d.ts +2 -0
- package/components/_shared/resolvePreset.d.ts +9 -5
- package/index.cjs +25 -9
- package/index.cjs.map +1 -1
- package/index.d.ts +4 -4
- package/index.js +13 -9
- package/mui.d.ts +1 -1
- package/package.json +2 -3
- package/resolvePreset-CxTI6_Ln.cjs.map +1 -1
- package/resolvePreset-K6_BfWHD.js.map +1 -1
- package/Autocomplete-Bd3bN4Cw.cjs.map +0 -1
- package/Autocomplete-E5aSUGVK.js.map +0 -1
- package/DateTimePicker-BVJGq1A0.cjs.map +0 -1
- package/DateTimePicker-LeaE716a.js.map +0 -1
- package/README.md +0 -251
- package/StatusMessage-B3nXpuRl.cjs.map +0 -1
- package/StatusMessage-D0WgSBx7.js.map +0 -1
- package/local/affiliations/affiliations.dev.soyfri.com-key.pem +0 -28
- package/local/affiliations/affiliations.dev.soyfri.com.pem +0 -27
- package/local/aficiliaciones/afiliaciones.dev.soyfri.com-key.pem +0 -28
- package/local/aficiliaciones/afiliaciones.dev.soyfri.com.pem +0 -27
- package/local/afiliaciones/afiliaciones.dev.soyfri.com-key.pem +0 -28
- package/local/afiliaciones/afiliaciones.dev.soyfri.com.pem +0 -27
- package/local/root/rootCA-key.pem +0 -40
- package/local/root/rootCA.pem +0 -30
- package/local/soporte/supportweb.dev.soyfri.com-key.pem +0 -28
- package/local/soporte/supportweb.dev.soyfri.com.pem +0 -27
- package/local/support/supportweb.dev.soyfri.com-key.pem +0 -28
- package/local/support/supportweb.dev.soyfri.com.pem +0 -27
|
@@ -59,34 +59,40 @@ const buildAutocompleteSx = (borderRadius, labelPosition) => formField_sx.buildF
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
});
|
|
62
|
-
const resolveSingleValue = (options, value) => {
|
|
62
|
+
const resolveSingleValue = (options, value, getKey) => {
|
|
63
63
|
var _a;
|
|
64
|
-
|
|
64
|
+
if (value === null || value === void 0) return null;
|
|
65
|
+
const key = getKey(value);
|
|
66
|
+
return (_a = options.find((o) => getKey(o.value) === key)) != null ? _a : null;
|
|
65
67
|
};
|
|
66
|
-
const resolveMultipleValue = (options, value) => {
|
|
68
|
+
const resolveMultipleValue = (options, value, getKey) => {
|
|
67
69
|
if (!Array.isArray(value)) return [];
|
|
68
|
-
|
|
70
|
+
const keys = new Set(value.map(getKey));
|
|
71
|
+
return options.filter((o) => keys.has(getKey(o.value)));
|
|
69
72
|
};
|
|
70
|
-
const areOptionsShallowEqual = (a, b) => {
|
|
73
|
+
const areOptionsShallowEqual = (a, b, getKey) => {
|
|
71
74
|
const keysA = Object.keys(a);
|
|
72
75
|
const keysB = Object.keys(b);
|
|
73
76
|
if (keysA.length !== keysB.length) return false;
|
|
74
|
-
return keysA.every((k) =>
|
|
77
|
+
return keysA.every((k) => {
|
|
78
|
+
if (k === "value") return getKey(a.value) === getKey(b.value);
|
|
79
|
+
return a[k] === b[k];
|
|
80
|
+
});
|
|
75
81
|
};
|
|
76
|
-
const areResolvedValuesEqual = (prev, next, multiple) => {
|
|
82
|
+
const areResolvedValuesEqual = (prev, next, multiple, getKey) => {
|
|
77
83
|
if (multiple) {
|
|
78
84
|
if (!Array.isArray(prev) || !Array.isArray(next)) return false;
|
|
79
85
|
if (prev.length !== next.length) return false;
|
|
80
86
|
return prev.every((o, i) => {
|
|
81
87
|
const n2 = next[i];
|
|
82
|
-
return !!n2 && areOptionsShallowEqual(o, n2);
|
|
88
|
+
return !!n2 && areOptionsShallowEqual(o, n2, getKey);
|
|
83
89
|
});
|
|
84
90
|
}
|
|
85
91
|
const p = prev;
|
|
86
92
|
const n = next;
|
|
87
93
|
if (p === n) return true;
|
|
88
94
|
if (!p || !n) return false;
|
|
89
|
-
return areOptionsShallowEqual(p, n);
|
|
95
|
+
return areOptionsShallowEqual(p, n, getKey);
|
|
90
96
|
};
|
|
91
97
|
const isResolvedValueEmpty = (resolvedValue, multiple) => {
|
|
92
98
|
if (multiple) {
|
|
@@ -106,7 +112,8 @@ const AutocompleteChips = ({
|
|
|
106
112
|
getTagProps,
|
|
107
113
|
size,
|
|
108
114
|
maxChipsToShow,
|
|
109
|
-
renderChipLabel
|
|
115
|
+
renderChipLabel,
|
|
116
|
+
getKey
|
|
110
117
|
}) => {
|
|
111
118
|
const displayed = value.slice(0, maxChipsToShow);
|
|
112
119
|
const hidden = value.length - maxChipsToShow;
|
|
@@ -121,7 +128,7 @@ const AutocompleteChips = ({
|
|
|
121
128
|
avatar: option.img ? /* @__PURE__ */ jsxRuntime.jsx(material.Avatar, { src: option.img }) : void 0,
|
|
122
129
|
deleteIcon: /* @__PURE__ */ jsxRuntime.jsx(ClearIcon, {})
|
|
123
130
|
}),
|
|
124
|
-
option.value
|
|
131
|
+
getKey(option.value)
|
|
125
132
|
);
|
|
126
133
|
}),
|
|
127
134
|
hidden > 0 && /* @__PURE__ */ jsxRuntime.jsx(material.Chip, { size, label: `+${hidden} más` })
|
|
@@ -147,6 +154,8 @@ function Autocomplete(props) {
|
|
|
147
154
|
maxChipsToShow = 3,
|
|
148
155
|
renderOptionItem,
|
|
149
156
|
renderChipLabel,
|
|
157
|
+
renderSingleValue,
|
|
158
|
+
getOptionKey,
|
|
150
159
|
borderRadius = tokens.FIELD_BORDER_RADIUS,
|
|
151
160
|
labelPosition = "outside",
|
|
152
161
|
size = "small",
|
|
@@ -163,23 +172,20 @@ function Autocomplete(props) {
|
|
|
163
172
|
onOpen,
|
|
164
173
|
onClose
|
|
165
174
|
} = props;
|
|
175
|
+
const getKey = getOptionKey != null ? getOptionKey : ((v) => v);
|
|
166
176
|
const [isFocused, setIsFocused] = React.useState(false);
|
|
167
|
-
const seenOptionsRef = React.useRef(
|
|
168
|
-
/* @__PURE__ */ new Map()
|
|
169
|
-
);
|
|
177
|
+
const seenOptionsRef = React.useRef(/* @__PURE__ */ new Map());
|
|
170
178
|
for (const opt of options) {
|
|
171
|
-
seenOptionsRef.current.set(opt.value, opt);
|
|
179
|
+
seenOptionsRef.current.set(getKey(opt.value), opt);
|
|
172
180
|
}
|
|
173
181
|
const resolvePool = React.useMemo(() => {
|
|
174
182
|
const merged = new Map(seenOptionsRef.current);
|
|
175
|
-
for (const opt of options) merged.set(opt.value, opt);
|
|
183
|
+
for (const opt of options) merged.set(getKey(opt.value), opt);
|
|
176
184
|
return Array.from(merged.values());
|
|
177
185
|
}, [options]);
|
|
178
|
-
const prevResolvedRef = React.useRef(
|
|
179
|
-
multiple ? [] : null
|
|
180
|
-
);
|
|
186
|
+
const prevResolvedRef = React.useRef(multiple ? [] : null);
|
|
181
187
|
const stabilizeResolved = (newVal) => {
|
|
182
|
-
if (areResolvedValuesEqual(prevResolvedRef.current, newVal, multiple)) {
|
|
188
|
+
if (areResolvedValuesEqual(prevResolvedRef.current, newVal, multiple, getKey)) {
|
|
183
189
|
return prevResolvedRef.current;
|
|
184
190
|
}
|
|
185
191
|
prevResolvedRef.current = newVal;
|
|
@@ -188,7 +194,8 @@ function Autocomplete(props) {
|
|
|
188
194
|
const theme = styles.useTheme();
|
|
189
195
|
const presetSx = resolvePreset.resolvePreset("Autocomplete", preset, theme);
|
|
190
196
|
const mergedSx = [
|
|
191
|
-
|
|
197
|
+
buildAutocompleteSx(borderRadius, labelPosition),
|
|
198
|
+
...presetSx ? [presetSx] : [],
|
|
192
199
|
...Array.isArray(sx) ? sx : sx ? [sx] : []
|
|
193
200
|
];
|
|
194
201
|
const renderAutocomplete = (resolvedValue2, handleChange, onBlur, inputRef, rhfError, rhfHelperText) => {
|
|
@@ -196,6 +203,7 @@ function Autocomplete(props) {
|
|
|
196
203
|
const finalHelperText = rhfHelperText || helperText;
|
|
197
204
|
const isEmpty = isResolvedValueEmpty(resolvedValue2, multiple);
|
|
198
205
|
const showPlaceholder = isEmpty && isFocused && !!placeholder;
|
|
206
|
+
const singleAdornment = !multiple && resolvedValue2 && renderSingleValue ? renderSingleValue(resolvedValue2) : null;
|
|
199
207
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
200
208
|
material.Autocomplete,
|
|
201
209
|
{
|
|
@@ -219,7 +227,8 @@ function Autocomplete(props) {
|
|
|
219
227
|
},
|
|
220
228
|
isOptionEqualToValue: (a, b) => {
|
|
221
229
|
if (typeof a === "string" || typeof b === "string") return a === b;
|
|
222
|
-
|
|
230
|
+
if (!a || !b) return a === b;
|
|
231
|
+
return getKey(a.value) === getKey(b.value);
|
|
223
232
|
},
|
|
224
233
|
getOptionDisabled: (opt) => typeof opt === "string" ? false : !!(opt == null ? void 0 : opt.disabled),
|
|
225
234
|
onChange: handleChange,
|
|
@@ -229,7 +238,7 @@ function Autocomplete(props) {
|
|
|
229
238
|
onBlur == null ? void 0 : onBlur();
|
|
230
239
|
},
|
|
231
240
|
renderOption: (liProps, option) => {
|
|
232
|
-
const _a = liProps, { key } = _a, liRest = __objRest(_a, ["key"]);
|
|
241
|
+
const _a = liProps, { key: _muiKey } = _a, liRest = __objRest(_a, ["key"]);
|
|
233
242
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
234
243
|
AutocompleteOption,
|
|
235
244
|
{
|
|
@@ -237,7 +246,7 @@ function Autocomplete(props) {
|
|
|
237
246
|
option,
|
|
238
247
|
customRender: renderOptionItem
|
|
239
248
|
},
|
|
240
|
-
|
|
249
|
+
getKey(option.value)
|
|
241
250
|
);
|
|
242
251
|
},
|
|
243
252
|
renderValue: multiple ? (value, getItemProps) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -247,13 +256,25 @@ function Autocomplete(props) {
|
|
|
247
256
|
getTagProps: getItemProps,
|
|
248
257
|
size,
|
|
249
258
|
maxChipsToShow,
|
|
250
|
-
renderChipLabel
|
|
259
|
+
renderChipLabel,
|
|
260
|
+
getKey
|
|
251
261
|
}
|
|
252
262
|
) : void 0,
|
|
253
263
|
noOptionsText,
|
|
254
264
|
loadingText: loadingText != null ? loadingText : /* @__PURE__ */ jsxRuntime.jsx(AutocompleteLoader, {}),
|
|
255
265
|
renderInput: (params) => {
|
|
256
|
-
var _a;
|
|
266
|
+
var _a, _b, _c, _d;
|
|
267
|
+
const paramsInputLabel = params.InputLabelProps;
|
|
268
|
+
const consumerInputLabel = (_b = (_a = textFieldProps == null ? void 0 : textFieldProps.slotProps) == null ? void 0 : _a.inputLabel) != null ? _b : textFieldProps == null ? void 0 : textFieldProps.InputLabelProps;
|
|
269
|
+
const muiInputProps = params.InputProps;
|
|
270
|
+
const consumerInputProps = (_d = (_c = textFieldProps == null ? void 0 : textFieldProps.slotProps) == null ? void 0 : _c.input) != null ? _d : textFieldProps == null ? void 0 : textFieldProps.InputProps;
|
|
271
|
+
const inputSlot = singleAdornment ? __spreadProps(__spreadValues(__spreadValues({}, muiInputProps), consumerInputProps), {
|
|
272
|
+
startAdornment: /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
273
|
+
singleAdornment,
|
|
274
|
+
consumerInputProps == null ? void 0 : consumerInputProps.startAdornment,
|
|
275
|
+
muiInputProps == null ? void 0 : muiInputProps.startAdornment
|
|
276
|
+
] })
|
|
277
|
+
}) : void 0;
|
|
257
278
|
return (
|
|
258
279
|
// @ts-ignore — Ref<any> type mismatch between @types/react versions in monorepo
|
|
259
280
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -267,8 +288,10 @@ function Autocomplete(props) {
|
|
|
267
288
|
helperText: finalHelperText,
|
|
268
289
|
inputRef
|
|
269
290
|
}), textFieldProps), {
|
|
270
|
-
|
|
271
|
-
|
|
291
|
+
slotProps: __spreadProps(__spreadValues(__spreadValues({}, textFieldProps == null ? void 0 : textFieldProps.slotProps), inputSlot ? { input: inputSlot } : {}), {
|
|
292
|
+
inputLabel: __spreadProps(__spreadValues(__spreadValues({}, paramsInputLabel), consumerInputLabel), {
|
|
293
|
+
shrink: labelPosition === "outside" ? !isEmpty || isFocused : paramsInputLabel == null ? void 0 : paramsInputLabel.shrink
|
|
294
|
+
})
|
|
272
295
|
})
|
|
273
296
|
})
|
|
274
297
|
)
|
|
@@ -279,14 +302,14 @@ function Autocomplete(props) {
|
|
|
279
302
|
};
|
|
280
303
|
const extractValue = (opt) => {
|
|
281
304
|
var _a;
|
|
282
|
-
|
|
305
|
+
if (opt === null || opt === void 0) return null;
|
|
306
|
+
if (typeof opt === "string") return opt;
|
|
307
|
+
return (_a = opt == null ? void 0 : opt.value) != null ? _a : null;
|
|
283
308
|
};
|
|
284
309
|
const handleControlledChange = (_event, newValue) => {
|
|
285
310
|
const onChange = props.onChange;
|
|
286
311
|
if (multiple) {
|
|
287
|
-
const values = (newValue != null ? newValue : []).map(
|
|
288
|
-
(opt) => extractValue(opt)
|
|
289
|
-
);
|
|
312
|
+
const values = (newValue != null ? newValue : []).map((opt) => extractValue(opt)).filter((v) => v !== null);
|
|
290
313
|
onChange(values);
|
|
291
314
|
} else {
|
|
292
315
|
onChange(extractValue(newValue));
|
|
@@ -302,13 +325,11 @@ function Autocomplete(props) {
|
|
|
302
325
|
rules: validation,
|
|
303
326
|
render: ({ field, fieldState: { error: fieldError } }) => {
|
|
304
327
|
const resolvedValue2 = stabilizeResolved(
|
|
305
|
-
multiple ? resolveMultipleValue(resolvePool, field.value) : resolveSingleValue(resolvePool, field.value)
|
|
328
|
+
multiple ? resolveMultipleValue(resolvePool, field.value, getKey) : resolveSingleValue(resolvePool, field.value, getKey)
|
|
306
329
|
);
|
|
307
330
|
const handleChange = (_event, newValue) => {
|
|
308
331
|
if (multiple) {
|
|
309
|
-
const next = (newValue != null ? newValue : []).map(
|
|
310
|
-
(opt) => extractValue(opt)
|
|
311
|
-
);
|
|
332
|
+
const next = (newValue != null ? newValue : []).map((opt) => extractValue(opt)).filter((v) => v !== null);
|
|
312
333
|
field.onChange(next);
|
|
313
334
|
onValueChange == null ? void 0 : onValueChange(next);
|
|
314
335
|
} else {
|
|
@@ -331,11 +352,11 @@ function Autocomplete(props) {
|
|
|
331
352
|
}
|
|
332
353
|
const controlledValue = props.value;
|
|
333
354
|
const resolvedValue = stabilizeResolved(
|
|
334
|
-
multiple ? resolveMultipleValue(resolvePool, controlledValue) : resolveSingleValue(resolvePool, controlledValue)
|
|
355
|
+
multiple ? resolveMultipleValue(resolvePool, controlledValue, getKey) : resolveSingleValue(resolvePool, controlledValue, getKey)
|
|
335
356
|
);
|
|
336
357
|
return renderAutocomplete(resolvedValue, handleControlledChange);
|
|
337
358
|
}
|
|
338
359
|
const AutocompleteSelect = Autocomplete;
|
|
339
360
|
exports.Autocomplete = Autocomplete;
|
|
340
361
|
exports.AutocompleteSelect = AutocompleteSelect;
|
|
341
|
-
//# sourceMappingURL=Autocomplete-
|
|
362
|
+
//# sourceMappingURL=Autocomplete-Baqwboth.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Autocomplete-Baqwboth.cjs","sources":["../src/components/Autocomplete/Autocomplete.sx.ts","../src/components/Autocomplete/Autocomplete.helpers.ts","../src/components/Autocomplete/_parts/AutocompleteOption.tsx","../src/components/Autocomplete/_parts/AutocompleteChips.tsx","../src/components/Autocomplete/_parts/AutocompleteLoader.tsx","../src/components/Autocomplete/Autocomplete.tsx"],"sourcesContent":["import type { SxProps, Theme } from '@mui/material/styles';\n\nimport { buildFormFieldSx } from '../_shared/formField.sx';\nimport { FIELD_INPUT_PADDING_Y } from '../../theme/tokens';\nimport type { LabelPosition } from './Autocomplete';\n\n/**\n * Builder del sx del Autocomplete. Reutiliza `buildFormFieldSx` y añade\n * los paddings propios del Autocomplete (chips + input interno).\n */\nexport const buildAutocompleteSx = (\n borderRadius: number | string,\n labelPosition: LabelPosition,\n): SxProps<Theme> =>\n buildFormFieldSx({\n borderRadius,\n labelPosition,\n extraOutsideSx: {\n // El Autocomplete es el único campo cuyo padding lo pinta MUI con\n // selectores calificados por tamaño (`.MuiOutlinedInput-root.MuiInputBase-sizeSmall`\n // y su descendiente `.MuiAutocomplete-input`). Un selector de menos clases\n // pierde por especificidad — por eso hay que repetir el calificador acá, o\n // el Autocomplete queda ~5px más bajo que Input/Select/pickers.\n '& .MuiOutlinedInput-root, & .MuiOutlinedInput-root.MuiInputBase-sizeSmall': {\n paddingTop: 0,\n paddingBottom: 0,\n },\n\n // La altura la fija el input interno, con el mismo token que el resto.\n '& .MuiOutlinedInput-root .MuiAutocomplete-input, & .MuiOutlinedInput-root.MuiInputBase-sizeSmall .MuiAutocomplete-input':\n {\n paddingTop: FIELD_INPUT_PADDING_Y,\n paddingBottom: FIELD_INPUT_PADDING_Y,\n },\n },\n });\n","import type { SxProps, Theme } from '@mui/material/styles';\nimport type { AutocompleteValueKey, SelectOption } from './Autocomplete';\n\n/** Resuelve un value único a su SelectOption dentro del pool. */\nexport const resolveSingleValue = <TValue,>(\n options: SelectOption<TValue>[],\n value: TValue | null | undefined,\n getKey: (v: TValue) => AutocompleteValueKey,\n): SelectOption<TValue> | null => {\n if (value === null || value === undefined) return null;\n const key = getKey(value);\n return options.find((o) => getKey(o.value) === key) ?? null;\n};\n\n/** Resuelve un array de values a sus SelectOption dentro del pool. */\nexport const resolveMultipleValue = <TValue,>(\n options: SelectOption<TValue>[],\n value: TValue[] | null | undefined,\n getKey: (v: TValue) => AutocompleteValueKey,\n): SelectOption<TValue>[] => {\n if (!Array.isArray(value)) return [];\n const keys = new Set(value.map(getKey));\n return options.filter((o) => keys.has(getKey(o.value)));\n};\n\n/** Merge de sx base + extra del consumer, respetando el contrato de MUI. */\nexport const mergeSx = (\n base: SxProps<Theme>,\n extra?: SxProps<Theme>,\n): SxProps<Theme> => {\n if (!extra) return base;\n return [base, ...(Array.isArray(extra) ? extra : [extra])] as SxProps<Theme>;\n};\n\n/**\n * Compara dos SelectOption por todas sus props (shallow). Se usa para detectar\n * cambios de metadata (p.ej. `label`, `img`) cuando `value` no cambió, para\n * que la estabilización no tape datos frescos del server. Para `value` se\n * compara vía `getKey` (no por `===`), de modo que values objeto con misma\n * identidad lógica pero referencia distinta no rompan la estabilización.\n */\nconst areOptionsShallowEqual = <TValue,>(\n a: SelectOption<TValue>,\n b: SelectOption<TValue>,\n getKey: (v: TValue) => AutocompleteValueKey,\n): boolean => {\n const keysA = Object.keys(a);\n const keysB = Object.keys(b);\n if (keysA.length !== keysB.length) return false;\n return keysA.every((k) => {\n if (k === 'value') return getKey(a.value) === getKey(b.value);\n return a[k] === b[k];\n });\n};\n\n/**\n * Compara dos valores resueltos (single o multiple) estructuralmente para\n * decidir si se puede reusar la referencia previa. Se usa para estabilizar la\n * referencia que se pasa a MUI Autocomplete (MUI compara value por referencia\n * con `!==`, y una nueva referencia — aunque el contenido sea igual — dispara\n * `resetInputValue` y borra el texto mientras el usuario tipea).\n *\n * Comparamos todas las props del SelectOption, no solo `value`, para que un\n * refresh de metadata (label/img/etc.) invalide la referencia estabilizada\n * y la UI muestre los datos actualizados.\n */\nexport const areResolvedValuesEqual = <TValue,>(\n prev: SelectOption<TValue> | SelectOption<TValue>[] | null,\n next: SelectOption<TValue> | SelectOption<TValue>[] | null,\n multiple: boolean,\n getKey: (v: TValue) => AutocompleteValueKey,\n): boolean => {\n if (multiple) {\n if (!Array.isArray(prev) || !Array.isArray(next)) return false;\n if (prev.length !== next.length) return false;\n return prev.every((o, i) => {\n const n = next[i];\n return !!n && areOptionsShallowEqual(o, n, getKey);\n });\n }\n const p = prev as SelectOption<TValue> | null;\n const n = next as SelectOption<TValue> | null;\n if (p === n) return true;\n if (!p || !n) return false;\n return areOptionsShallowEqual(p, n, getKey);\n};\n\n/** Determina si un valor resuelto está vacío (para placeholder/shrink). */\nexport const isResolvedValueEmpty = (\n resolvedValue: unknown,\n multiple: boolean,\n): boolean => {\n if (multiple) {\n return !Array.isArray(resolvedValue) || resolvedValue.length === 0;\n }\n return !resolvedValue;\n};\n","import React from 'react';\nimport type {\n AutocompleteValueKey,\n SelectOption,\n RenderOptionItem,\n} from '../Autocomplete';\n\ninterface AutocompleteOptionProps<TValue = AutocompleteValueKey> {\n liProps: React.HTMLAttributes<HTMLLIElement>;\n option: SelectOption<TValue>;\n customRender?: RenderOptionItem<TValue>;\n}\n\n/**\n * Render por defecto de un `<li>` del dropdown del Autocomplete.\n * MUI lo invoca desde `renderOption={(props, option) => ...}` en el padre.\n *\n * La `key` la maneja el padre (`renderOption` en Autocomplete.tsx). Este\n * componente solo recibe los props restantes del `<li>` para spread.\n */\nexport const AutocompleteOption = <TValue,>({\n liProps,\n option,\n customRender,\n}: AutocompleteOptionProps<TValue>) => {\n return (\n <li {...liProps}>\n {customRender ? customRender(option) : option.label}\n </li>\n );\n};\n\nexport default AutocompleteOption;\n","import { Avatar, Chip } from '@mui/material';\nimport ClearIcon from '@mui/icons-material/Clear';\n\nimport type {\n AutocompleteValueKey,\n SelectOption,\n RenderChipLabel,\n AutocompleteSize,\n} from '../Autocomplete';\n\ninterface AutocompleteChipsProps<TValue = AutocompleteValueKey> {\n value: SelectOption<TValue>[];\n getTagProps: (args: { index: number }) => Record<string, any>;\n size: AutocompleteSize;\n maxChipsToShow: number;\n renderChipLabel?: RenderChipLabel<TValue>;\n /** Key estable del value: React key del chip. Ver `getOptionKey`. */\n getKey: (value: TValue) => AutocompleteValueKey;\n}\n\n/**\n * Render de los chips del Autocomplete en modo multiple.\n * Trunca después de `maxChipsToShow` con un chip \"+N más\".\n * El `getTagProps({ index })` viene de MUI y contiene el handler de delete,\n * la key, etc. — se spreadea tal cual al Chip.\n */\nexport const AutocompleteChips = <TValue,>({\n value,\n getTagProps,\n size,\n maxChipsToShow,\n renderChipLabel,\n getKey,\n}: AutocompleteChipsProps<TValue>) => {\n const displayed = value.slice(0, maxChipsToShow);\n const hidden = value.length - maxChipsToShow;\n\n return (\n <>\n {displayed.map((option, index) => {\n const { key: _ignored, ...tagProps } = getTagProps({ index });\n return (\n <Chip\n key={getKey(option.value)}\n {...tagProps}\n size={size}\n label={renderChipLabel ? renderChipLabel(option) : option.label}\n avatar={option.img ? <Avatar src={option.img} /> : undefined}\n deleteIcon={<ClearIcon />}\n />\n );\n })}\n {hidden > 0 && <Chip size={size} label={`+${hidden} más`} />}\n </>\n );\n};\n\nexport default AutocompleteChips;\n","import React from 'react';\nimport { Box, CircularProgress, Typography } from '@mui/material';\n\n/**\n * Loader por defecto para el `loadingText` del Autocomplete.\n * El consumer puede sobrescribirlo pasando `loadingText` al componente padre.\n */\nexport const AutocompleteLoader: React.FC<{ text?: string }> = ({\n text = 'Cargando...',\n}) => (\n <Box sx={{ display: 'flex', alignItems: 'center', gap: 1 }}>\n <CircularProgress size={16} />\n <Typography variant=\"body2\">{text}</Typography>\n </Box>\n);\n\nexport default AutocompleteLoader;\n","import React, {\n useMemo,\n useRef,\n useState,\n type ReactNode,\n type SyntheticEvent,\n} from 'react';\nimport {\n Autocomplete as MuiAutocomplete,\n TextField,\n type TextFieldProps,\n} from '@mui/material';\nimport { useTheme, type SxProps, type Theme } from '@mui/material/styles';\nimport { Controller, type RegisterOptions } from 'react-hook-form';\n\nimport { buildAutocompleteSx } from './Autocomplete.sx';\nimport { FIELD_BORDER_RADIUS } from '../../theme/tokens';\nimport {\n areResolvedValuesEqual,\n isResolvedValueEmpty,\n resolveMultipleValue,\n resolveSingleValue,\n} from './Autocomplete.helpers';\nimport { resolvePreset } from '../_shared/resolvePreset';\nimport { AutocompleteOption } from './_parts/AutocompleteOption';\nimport { AutocompleteChips } from './_parts/AutocompleteChips';\nimport { AutocompleteLoader } from './_parts/AutocompleteLoader';\n\n// ── Tipos de dominio ─────────────────────────────────────────────────────\n/** Key estable usada para comparar values, indexar caches y como React key. */\nexport type AutocompleteValueKey = string | number;\n\nexport interface SelectOption<TValue = AutocompleteValueKey> {\n value: TValue;\n label: string;\n img?: string;\n disabled?: boolean;\n group?: string;\n [key: string]: any; //campos extras que puede tener la opcion\n}\n\nexport type LabelPosition = 'outside' | 'floating';\nexport type AutocompleteSize = 'small' | 'medium';\n\n// ── Render slots ─────────────────────────────────────────────────────────\nexport type RenderOptionItem<TValue = AutocompleteValueKey> = (\n item: SelectOption<TValue>,\n) => ReactNode;\nexport type RenderChipLabel<TValue = AutocompleteValueKey> = (\n item: SelectOption<TValue>,\n) => ReactNode;\nexport type RenderSingleValue<TValue = AutocompleteValueKey> = (\n item: SelectOption<TValue>,\n) => ReactNode;\n\n// ── Props base ───────────────────────────────────────────────────────────\nexport type BaseAutocompleteProps<TValue = AutocompleteValueKey> = {\n label?: string;\n options: SelectOption<TValue>[];\n placeholder?: string;\n multiple?: boolean;\n disabled?: boolean;\n readOnly?: boolean;\n loading?: boolean;\n error?: boolean;\n helperText?: string;\n maxChipsToShow?: number;\n renderOptionItem?: RenderOptionItem<TValue>;\n renderChipLabel?: RenderChipLabel<TValue>;\n /**\n * Renderiza JSX custom como `startAdornment` del input en single mode.\n * Recibe la `SelectOption` seleccionada. Útil para mostrar avatars, iconos,\n * etc. junto al texto del label. En `multiple` no aplica (se usa `renderChipLabel`).\n */\n renderSingleValue?: RenderSingleValue<TValue>;\n /**\n * Extrae una key estable (string | number) desde el `value`. Obligatorio\n * cuando `TValue` es un objeto: se usa para comparar values (`isOptionEqualToValue`,\n * resolución desde el value del form), indexar el cache interno de opciones\n * vistas y como React key en chips/options del dropdown. Para primitivos se\n * puede omitir (default: identidad, o sea `===`).\n */\n getOptionKey?: (value: TValue) => AutocompleteValueKey;\n /** Border radius del input. Default: 10. */\n borderRadius?: number | string;\n /** \"outside\" (default) = label arriba del input; \"floating\" = comportamiento nativo MUI. */\n labelPosition?: LabelPosition;\n /** Tamaño del TextField. Default: 'small'. */\n size?: AutocompleteSize;\n /** Texto cuando no hay coincidencias. */\n noOptionsText?: ReactNode;\n /** Texto cuando está cargando. */\n loadingText?: ReactNode;\n sx?: SxProps<Theme>;\n /**\n * Nombre del preset de estilo registrado en `theme.styles.Autocomplete`.\n * - `\"default\"` (o ausente) = estilo built-in del paquete.\n * - Cualquier otro string = mergea el preset encima del estilo built-in.\n */\n preset?: string;\n /** Props para el TextField subyacente. */\n textFieldProps?: Partial<TextFieldProps>;\n\n // ── Búsqueda asíncrona / remota ──────────────────────────────────────\n /** Se dispara cada vez que el usuario escribe. Útil para llamadas a servicios\n * (debounce recomendado en el consumer). */\n onInputChange?: (\n event: SyntheticEvent,\n value: string,\n reason: 'input' | 'reset' | 'clear' | 'blur' | 'selectOption' | 'removeOption',\n ) => void;\n /** Valor controlado del texto de búsqueda. */\n inputValue?: string;\n /** Filtro custom. Para búsqueda remota pasar `(x) => x` y confiar sólo en el servicio. */\n filterOptions?: (\n options: SelectOption<TValue>[],\n state: any,\n ) => SelectOption<TValue>[];\n /** Permite valores arbitrarios (no solo de la lista). */\n freeSolo?: boolean;\n open?: boolean;\n onOpen?: (event: SyntheticEvent) => void;\n onClose?: (event: SyntheticEvent, reason: string) => void;\n};\n\n// ── Variantes discriminadas (RHF vs controlado) ──────────────────────────\nexport interface ControlledAutocompleteProps<TValue = AutocompleteValueKey>\n extends BaseAutocompleteProps<TValue> {\n value: TValue | TValue[] | null;\n onChange: (val: TValue | TValue[] | null) => void;\n name?: string;\n control?: never;\n validation?: never;\n}\n\nexport interface RHFAutocompleteProps<TValue = AutocompleteValueKey>\n extends BaseAutocompleteProps<TValue> {\n name: string;\n // `any` plano (no `Control<any>`): RHF tipa `Control<T>` con generics en\n // posiciones tanto contravariantes como covariantes (ej. `_subjects.state`).\n // Cuando el componente o su uso involucra generics adicionales, TS se\n // confunde narroweando el discriminated union y `Control<any>` no logra\n // absorber `Control<MyForm>` en la comparación estructural profunda. El\n // `any` plano elimina ese ruido. RHF adentro sigue teniendo sus tipos\n // fuertes — solo degradamos la superficie del prop del componente.\n control: any;\n validation?: RegisterOptions;\n /**\n * Side-effect que corre después de que RHF actualiza el form state.\n * Útil para cascadas entre campos. NO reemplaza al handler de RHF.\n */\n onValueChange?: (val: TValue | TValue[] | null) => void;\n value?: never;\n onChange?: never;\n}\n\n// ── API pública final ────────────────────────────────────────────────────\nexport type AutocompleteProps<TValue = AutocompleteValueKey> =\n | ControlledAutocompleteProps<TValue>\n | RHFAutocompleteProps<TValue>;\n\nexport function Autocomplete<TValue = AutocompleteValueKey>(\n props: AutocompleteProps<TValue>,\n) {\n const {\n label,\n options,\n placeholder,\n multiple = false,\n disabled = false,\n readOnly = false,\n loading = false,\n error: errorProp = false,\n helperText,\n maxChipsToShow = 3,\n renderOptionItem,\n renderChipLabel,\n renderSingleValue,\n getOptionKey,\n borderRadius = FIELD_BORDER_RADIUS,\n labelPosition = 'outside',\n size = 'small',\n noOptionsText = 'No hay opciones',\n loadingText,\n sx,\n preset,\n textFieldProps,\n onInputChange,\n inputValue,\n filterOptions,\n freeSolo,\n open,\n onOpen,\n onClose,\n } = props as BaseAutocompleteProps<TValue>;\n\n // Default identidad: para primitivos (string|number) funciona como `===`.\n // Para values objeto, el consumer DEBE pasar `getOptionKey` o la igualdad\n // caerá a referencia (Map/Set agruparían por identidad).\n const getKey = (getOptionKey ??\n ((v: TValue) => v as unknown as AutocompleteValueKey)) as (\n v: TValue,\n ) => AutocompleteValueKey;\n\n // Focus tracking para mostrar placeholder solo cuando el label sube.\n const [isFocused, setIsFocused] = useState(false);\n\n // Cache interno de opciones vistas (indexado por key estable). Crítico para\n // async multiple: cuando `options` cambian por un nuevo search, los items\n // ya seleccionados no desaparecen de los chips porque los recordamos acá.\n const seenOptionsRef = useRef<\n Map<AutocompleteValueKey, SelectOption<TValue>>\n >(new Map());\n for (const opt of options) {\n seenOptionsRef.current.set(getKey(opt.value), opt);\n }\n\n // Pool de opciones para resolver values (merge de options + vistas).\n const resolvePool = useMemo<SelectOption<TValue>[]>(() => {\n const merged = new Map(seenOptionsRef.current);\n for (const opt of options) merged.set(getKey(opt.value), opt);\n return Array.from(merged.values());\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [options]);\n\n // Estabiliza la referencia del resolvedValue que pasamos a MUI Autocomplete.\n // MUI compara value con `!==`: una referencia nueva con mismo contenido\n // dispara resetInputValue() y borra el texto que el usuario está escribiendo.\n const prevResolvedRef = useRef<\n SelectOption<TValue>[] | SelectOption<TValue> | null\n >(multiple ? [] : null);\n\n const stabilizeResolved = (\n newVal: SelectOption<TValue>[] | SelectOption<TValue> | null,\n ): SelectOption<TValue>[] | SelectOption<TValue> | null => {\n if (\n areResolvedValuesEqual(prevResolvedRef.current, newVal, multiple, getKey)\n ) {\n return prevResolvedRef.current;\n }\n prevResolvedRef.current = newVal;\n return newVal;\n };\n\n const theme = useTheme();\n const presetSx = resolvePreset('Autocomplete', preset, theme);\n\n // Built-in primero, preset encima (ver Input).\n const mergedSx = [\n buildAutocompleteSx(borderRadius, labelPosition),\n ...(presetSx ? [presetSx] : []),\n ...(Array.isArray(sx) ? sx : sx ? [sx] : []),\n ];\n\n const renderAutocomplete = (\n resolvedValue: any,\n handleChange: (event: any, newValue: any) => void,\n onBlur?: () => void,\n inputRef?: React.Ref<any>,\n rhfError?: boolean,\n rhfHelperText?: string,\n ) => {\n const finalError = !!rhfError || !!errorProp;\n const finalHelperText = rhfHelperText || helperText;\n\n const isEmpty = isResolvedValueEmpty(resolvedValue, multiple);\n const showPlaceholder = isEmpty && isFocused && !!placeholder;\n const singleAdornment =\n !multiple && resolvedValue && renderSingleValue\n ? renderSingleValue(resolvedValue as SelectOption<TValue>)\n : null;\n\n return (\n <MuiAutocomplete\n multiple={multiple}\n options={options}\n value={resolvedValue}\n disabled={disabled}\n readOnly={readOnly}\n loading={loading}\n sx={mergedSx}\n freeSolo={freeSolo as any}\n open={open}\n onOpen={onOpen}\n onClose={onClose}\n inputValue={inputValue}\n onInputChange={onInputChange}\n filterOptions={filterOptions as any}\n getOptionLabel={(opt) =>\n typeof opt === 'string' ? opt : (opt?.label ?? '')\n }\n isOptionEqualToValue={(a, b) => {\n if (typeof a === 'string' || typeof b === 'string') return a === b;\n if (!a || !b) return a === b;\n return getKey(a.value) === getKey(b.value);\n }}\n getOptionDisabled={(opt) =>\n typeof opt === 'string' ? false : !!opt?.disabled\n }\n onChange={handleChange}\n onFocus={() => setIsFocused(true)}\n onBlur={() => {\n setIsFocused(false);\n onBlur?.();\n }}\n renderOption={(liProps, option) => {\n // MUI inyecta la `key` dentro de `liProps`. React necesita la key\n // en el elemento más externo que devuelve `renderOption` (acá el\n // wrapper), no en el `<li>` interno. El resto de `liProps` viaja\n // al `<li>`. La key auto-generada por MUI cae a `getOptionLabel`,\n // que colisiona si hay opciones con label duplicado. Usamos la key\n // estable del value para garantizar uniqueness aunque haya labels\n // repetidos.\n const { key: _muiKey, ...liRest } = liProps as React.HTMLAttributes<HTMLLIElement> & {\n key?: React.Key;\n };\n return (\n <AutocompleteOption<TValue>\n key={getKey(option.value)}\n liProps={liRest}\n option={option}\n customRender={renderOptionItem}\n />\n );\n }}\n renderValue={\n multiple\n ? (value, getItemProps) => (\n <AutocompleteChips<TValue>\n value={value as SelectOption<TValue>[]}\n getTagProps={getItemProps}\n size={size}\n maxChipsToShow={maxChipsToShow}\n renderChipLabel={renderChipLabel}\n getKey={getKey}\n />\n )\n : undefined\n }\n noOptionsText={noOptionsText}\n loadingText={loadingText ?? <AutocompleteLoader />}\n renderInput={(params) => {\n const paramsInputLabel = (params as any).InputLabelProps as\n | Record<string, any>\n | undefined;\n const consumerInputLabel =\n (textFieldProps?.slotProps as any)?.inputLabel ??\n (textFieldProps as any)?.InputLabelProps;\n // Para inyectar `singleAdornment` necesitamos pasar `slotProps.input`\n // a TextField, pero `slotProps.input` gana sobre `params.InputProps`\n // (que trae endAdornment con chevron + clear). Por eso, cuando hay\n // adornment custom, mergeamos params.InputProps + lo que el consumer\n // haya pasado por textFieldProps + nuestro startAdornment. Si no hay\n // adornment, no tocamos `slotProps.input` y se preserva el flujo legacy.\n const muiInputProps = (params as any).InputProps as\n | Record<string, any>\n | undefined;\n const consumerInputProps =\n (textFieldProps?.slotProps as any)?.input ??\n (textFieldProps as any)?.InputProps;\n const inputSlot = singleAdornment\n ? {\n ...muiInputProps,\n ...consumerInputProps,\n startAdornment: (\n <>\n {singleAdornment}\n {consumerInputProps?.startAdornment}\n {muiInputProps?.startAdornment}\n </>\n ),\n }\n : undefined;\n\n return (\n // @ts-ignore — Ref<any> type mismatch between @types/react versions in monorepo\n <TextField\n {...params}\n label={label}\n size={size}\n variant=\"outlined\"\n placeholder={showPlaceholder ? placeholder : undefined}\n error={finalError}\n helperText={finalHelperText}\n inputRef={inputRef}\n {...textFieldProps}\n slotProps={{\n ...textFieldProps?.slotProps,\n ...(inputSlot ? { input: inputSlot } : {}),\n inputLabel: {\n ...paramsInputLabel,\n ...consumerInputLabel,\n shrink:\n labelPosition === 'outside'\n ? !isEmpty || isFocused\n : paramsInputLabel?.shrink,\n },\n }}\n />\n );\n }}\n />\n );\n };\n\n //obtiene el primitivo (o el objeto) value desde la opción seleccionada\n const extractValue = (opt: any): TValue | null => {\n if (opt === null || opt === undefined) return null;\n if (typeof opt === 'string') return opt as unknown as TValue;\n return (opt?.value ?? null) as TValue | null;\n };\n\n const handleControlledChange = (_event: any, newValue: any) => {\n const onChange = (props as ControlledAutocompleteProps<TValue>).onChange;\n if (multiple) {\n const values = (newValue ?? [])\n .map((opt: SelectOption<TValue> | string) => extractValue(opt))\n .filter((v: TValue | null): v is TValue => v !== null);\n onChange(values);\n } else {\n onChange(extractValue(newValue));\n }\n };\n\n // --- RHF mode ---\n if ('control' in props && props.control) {\n const { name, control, validation, onValueChange } =\n props as RHFAutocompleteProps<TValue>;\n return (\n <Controller\n name={name}\n control={control}\n rules={validation}\n render={({ field, fieldState: { error: fieldError } }) => {\n const resolvedValue = stabilizeResolved(\n multiple\n ? resolveMultipleValue(resolvePool, field.value, getKey)\n : resolveSingleValue(resolvePool, field.value, getKey),\n );\n\n const handleChange = (_event: any, newValue: any) => {\n if (multiple) {\n const next = (newValue ?? [])\n .map((opt: SelectOption<TValue> | string) => extractValue(opt))\n .filter((v: TValue | null): v is TValue => v !== null);\n field.onChange(next);\n onValueChange?.(next);\n } else {\n const next = extractValue(newValue);\n field.onChange(next);\n onValueChange?.(next);\n }\n };\n\n return renderAutocomplete(\n resolvedValue,\n handleChange,\n field.onBlur,\n field.ref,\n !!fieldError,\n fieldError?.message,\n );\n }}\n />\n );\n }\n\n // --- Controlled mode ---\n const controlledValue = (props as ControlledAutocompleteProps<TValue>).value;\n const resolvedValue = stabilizeResolved(\n multiple\n ? resolveMultipleValue(resolvePool, controlledValue as TValue[], getKey)\n : resolveSingleValue(resolvePool, controlledValue as TValue, getKey),\n );\n\n return renderAutocomplete(resolvedValue, handleControlledChange);\n}\n\n/** Alias de `Autocomplete`. Ambos nombres son equivalentes. */\nexport const AutocompleteSelect = Autocomplete;\n\nexport default Autocomplete;\n"],"names":["buildFormFieldSx","FIELD_INPUT_PADDING_Y","n","jsx","jsxs","Fragment","Chip","Avatar","Box","CircularProgress","Typography","FIELD_BORDER_RADIUS","useState","useRef","useMemo","useTheme","resolvePreset","resolvedValue","MuiAutocomplete","TextField","Controller"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUO,MAAM,sBAAsB,CACjC,cACA,kBAEAA,8BAAiB;AAAA,EACf;AAAA,EACA;AAAA,EACA,gBAAgB;AAAA;AAAA;AAAA;AAA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AAmB;AACxD,gBAAMH,iBAAgB;AAAA,YACpB,WACI,qBAAqB,aAAa,MAAM,OAAO,MAAM,IACrD,mBAAmB,aAAa,MAAM,OAAO,MAAM;AAAA,UAAA;AAGzD,gBAAM,eAAe,CAAC,QAAa,aAAkB;AACnD,gBAAI,UAAU;AACZ,oBAAM,QAAQ,8BAAY,CAAA,GACvB,IAAI,CAAC,QAAuC,aAAa,GAAG,CAAC,EAC7D,OAAO,CAAC,MAAkC,MAAM,IAAI;AACvD,oBAAM,SAAS,IAAI;AACnB,6DAAgB;AAAA,YAClB,OAAO;AACL,oBAAM,OAAO,aAAa,QAAQ;AAClC,oBAAM,SAAS,IAAI;AACnB,6DAAgB;AAAA,YAClB;AAAA,UACF;AAEA,iBAAO;AAAA,YACLA;AAAAA,YACA;AAAA,YACA,MAAM;AAAA,YACN,MAAM;AAAA,YACN,CAAC,CAAC;AAAA,YACF,yCAAY;AAAA,UAAA;AAAA,QAEhB;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AAGA,QAAM,kBAAmB,MAA8C;AACvE,QAAM,gBAAgB;AAAA,IACpB,WACI,qBAAqB,aAAa,iBAA6B,MAAM,IACrE,mBAAmB,aAAa,iBAA2B,MAAM;AAAA,EAAA;AAGvE,SAAO,mBAAmB,eAAe,sBAAsB;AACjE;AAGO,MAAM,qBAAqB;;;"}
|
|
@@ -58,34 +58,40 @@ const buildAutocompleteSx = (borderRadius, labelPosition) => buildFormFieldSx({
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
});
|
|
61
|
-
const resolveSingleValue = (options, value) => {
|
|
61
|
+
const resolveSingleValue = (options, value, getKey) => {
|
|
62
62
|
var _a;
|
|
63
|
-
|
|
63
|
+
if (value === null || value === void 0) return null;
|
|
64
|
+
const key = getKey(value);
|
|
65
|
+
return (_a = options.find((o) => getKey(o.value) === key)) != null ? _a : null;
|
|
64
66
|
};
|
|
65
|
-
const resolveMultipleValue = (options, value) => {
|
|
67
|
+
const resolveMultipleValue = (options, value, getKey) => {
|
|
66
68
|
if (!Array.isArray(value)) return [];
|
|
67
|
-
|
|
69
|
+
const keys = new Set(value.map(getKey));
|
|
70
|
+
return options.filter((o) => keys.has(getKey(o.value)));
|
|
68
71
|
};
|
|
69
|
-
const areOptionsShallowEqual = (a, b) => {
|
|
72
|
+
const areOptionsShallowEqual = (a, b, getKey) => {
|
|
70
73
|
const keysA = Object.keys(a);
|
|
71
74
|
const keysB = Object.keys(b);
|
|
72
75
|
if (keysA.length !== keysB.length) return false;
|
|
73
|
-
return keysA.every((k) =>
|
|
76
|
+
return keysA.every((k) => {
|
|
77
|
+
if (k === "value") return getKey(a.value) === getKey(b.value);
|
|
78
|
+
return a[k] === b[k];
|
|
79
|
+
});
|
|
74
80
|
};
|
|
75
|
-
const areResolvedValuesEqual = (prev, next, multiple) => {
|
|
81
|
+
const areResolvedValuesEqual = (prev, next, multiple, getKey) => {
|
|
76
82
|
if (multiple) {
|
|
77
83
|
if (!Array.isArray(prev) || !Array.isArray(next)) return false;
|
|
78
84
|
if (prev.length !== next.length) return false;
|
|
79
85
|
return prev.every((o, i) => {
|
|
80
86
|
const n2 = next[i];
|
|
81
|
-
return !!n2 && areOptionsShallowEqual(o, n2);
|
|
87
|
+
return !!n2 && areOptionsShallowEqual(o, n2, getKey);
|
|
82
88
|
});
|
|
83
89
|
}
|
|
84
90
|
const p = prev;
|
|
85
91
|
const n = next;
|
|
86
92
|
if (p === n) return true;
|
|
87
93
|
if (!p || !n) return false;
|
|
88
|
-
return areOptionsShallowEqual(p, n);
|
|
94
|
+
return areOptionsShallowEqual(p, n, getKey);
|
|
89
95
|
};
|
|
90
96
|
const isResolvedValueEmpty = (resolvedValue, multiple) => {
|
|
91
97
|
if (multiple) {
|
|
@@ -105,7 +111,8 @@ const AutocompleteChips = ({
|
|
|
105
111
|
getTagProps,
|
|
106
112
|
size,
|
|
107
113
|
maxChipsToShow,
|
|
108
|
-
renderChipLabel
|
|
114
|
+
renderChipLabel,
|
|
115
|
+
getKey
|
|
109
116
|
}) => {
|
|
110
117
|
const displayed = value.slice(0, maxChipsToShow);
|
|
111
118
|
const hidden = value.length - maxChipsToShow;
|
|
@@ -120,7 +127,7 @@ const AutocompleteChips = ({
|
|
|
120
127
|
avatar: option.img ? /* @__PURE__ */ jsx(Avatar, { src: option.img }) : void 0,
|
|
121
128
|
deleteIcon: /* @__PURE__ */ jsx(ClearIcon, {})
|
|
122
129
|
}),
|
|
123
|
-
option.value
|
|
130
|
+
getKey(option.value)
|
|
124
131
|
);
|
|
125
132
|
}),
|
|
126
133
|
hidden > 0 && /* @__PURE__ */ jsx(Chip, { size, label: `+${hidden} más` })
|
|
@@ -146,6 +153,8 @@ function Autocomplete(props) {
|
|
|
146
153
|
maxChipsToShow = 3,
|
|
147
154
|
renderOptionItem,
|
|
148
155
|
renderChipLabel,
|
|
156
|
+
renderSingleValue,
|
|
157
|
+
getOptionKey,
|
|
149
158
|
borderRadius = FIELD_BORDER_RADIUS,
|
|
150
159
|
labelPosition = "outside",
|
|
151
160
|
size = "small",
|
|
@@ -162,23 +171,20 @@ function Autocomplete(props) {
|
|
|
162
171
|
onOpen,
|
|
163
172
|
onClose
|
|
164
173
|
} = props;
|
|
174
|
+
const getKey = getOptionKey != null ? getOptionKey : ((v) => v);
|
|
165
175
|
const [isFocused, setIsFocused] = useState(false);
|
|
166
|
-
const seenOptionsRef = useRef(
|
|
167
|
-
/* @__PURE__ */ new Map()
|
|
168
|
-
);
|
|
176
|
+
const seenOptionsRef = useRef(/* @__PURE__ */ new Map());
|
|
169
177
|
for (const opt of options) {
|
|
170
|
-
seenOptionsRef.current.set(opt.value, opt);
|
|
178
|
+
seenOptionsRef.current.set(getKey(opt.value), opt);
|
|
171
179
|
}
|
|
172
180
|
const resolvePool = useMemo(() => {
|
|
173
181
|
const merged = new Map(seenOptionsRef.current);
|
|
174
|
-
for (const opt of options) merged.set(opt.value, opt);
|
|
182
|
+
for (const opt of options) merged.set(getKey(opt.value), opt);
|
|
175
183
|
return Array.from(merged.values());
|
|
176
184
|
}, [options]);
|
|
177
|
-
const prevResolvedRef = useRef(
|
|
178
|
-
multiple ? [] : null
|
|
179
|
-
);
|
|
185
|
+
const prevResolvedRef = useRef(multiple ? [] : null);
|
|
180
186
|
const stabilizeResolved = (newVal) => {
|
|
181
|
-
if (areResolvedValuesEqual(prevResolvedRef.current, newVal, multiple)) {
|
|
187
|
+
if (areResolvedValuesEqual(prevResolvedRef.current, newVal, multiple, getKey)) {
|
|
182
188
|
return prevResolvedRef.current;
|
|
183
189
|
}
|
|
184
190
|
prevResolvedRef.current = newVal;
|
|
@@ -187,7 +193,8 @@ function Autocomplete(props) {
|
|
|
187
193
|
const theme = useTheme();
|
|
188
194
|
const presetSx = resolvePreset("Autocomplete", preset, theme);
|
|
189
195
|
const mergedSx = [
|
|
190
|
-
|
|
196
|
+
buildAutocompleteSx(borderRadius, labelPosition),
|
|
197
|
+
...presetSx ? [presetSx] : [],
|
|
191
198
|
...Array.isArray(sx) ? sx : sx ? [sx] : []
|
|
192
199
|
];
|
|
193
200
|
const renderAutocomplete = (resolvedValue2, handleChange, onBlur, inputRef, rhfError, rhfHelperText) => {
|
|
@@ -195,6 +202,7 @@ function Autocomplete(props) {
|
|
|
195
202
|
const finalHelperText = rhfHelperText || helperText;
|
|
196
203
|
const isEmpty = isResolvedValueEmpty(resolvedValue2, multiple);
|
|
197
204
|
const showPlaceholder = isEmpty && isFocused && !!placeholder;
|
|
205
|
+
const singleAdornment = !multiple && resolvedValue2 && renderSingleValue ? renderSingleValue(resolvedValue2) : null;
|
|
198
206
|
return /* @__PURE__ */ jsx(
|
|
199
207
|
Autocomplete$1,
|
|
200
208
|
{
|
|
@@ -218,7 +226,8 @@ function Autocomplete(props) {
|
|
|
218
226
|
},
|
|
219
227
|
isOptionEqualToValue: (a, b) => {
|
|
220
228
|
if (typeof a === "string" || typeof b === "string") return a === b;
|
|
221
|
-
|
|
229
|
+
if (!a || !b) return a === b;
|
|
230
|
+
return getKey(a.value) === getKey(b.value);
|
|
222
231
|
},
|
|
223
232
|
getOptionDisabled: (opt) => typeof opt === "string" ? false : !!(opt == null ? void 0 : opt.disabled),
|
|
224
233
|
onChange: handleChange,
|
|
@@ -228,7 +237,7 @@ function Autocomplete(props) {
|
|
|
228
237
|
onBlur == null ? void 0 : onBlur();
|
|
229
238
|
},
|
|
230
239
|
renderOption: (liProps, option) => {
|
|
231
|
-
const _a = liProps, { key } = _a, liRest = __objRest(_a, ["key"]);
|
|
240
|
+
const _a = liProps, { key: _muiKey } = _a, liRest = __objRest(_a, ["key"]);
|
|
232
241
|
return /* @__PURE__ */ jsx(
|
|
233
242
|
AutocompleteOption,
|
|
234
243
|
{
|
|
@@ -236,7 +245,7 @@ function Autocomplete(props) {
|
|
|
236
245
|
option,
|
|
237
246
|
customRender: renderOptionItem
|
|
238
247
|
},
|
|
239
|
-
|
|
248
|
+
getKey(option.value)
|
|
240
249
|
);
|
|
241
250
|
},
|
|
242
251
|
renderValue: multiple ? (value, getItemProps) => /* @__PURE__ */ jsx(
|
|
@@ -246,13 +255,25 @@ function Autocomplete(props) {
|
|
|
246
255
|
getTagProps: getItemProps,
|
|
247
256
|
size,
|
|
248
257
|
maxChipsToShow,
|
|
249
|
-
renderChipLabel
|
|
258
|
+
renderChipLabel,
|
|
259
|
+
getKey
|
|
250
260
|
}
|
|
251
261
|
) : void 0,
|
|
252
262
|
noOptionsText,
|
|
253
263
|
loadingText: loadingText != null ? loadingText : /* @__PURE__ */ jsx(AutocompleteLoader, {}),
|
|
254
264
|
renderInput: (params) => {
|
|
255
|
-
var _a;
|
|
265
|
+
var _a, _b, _c, _d;
|
|
266
|
+
const paramsInputLabel = params.InputLabelProps;
|
|
267
|
+
const consumerInputLabel = (_b = (_a = textFieldProps == null ? void 0 : textFieldProps.slotProps) == null ? void 0 : _a.inputLabel) != null ? _b : textFieldProps == null ? void 0 : textFieldProps.InputLabelProps;
|
|
268
|
+
const muiInputProps = params.InputProps;
|
|
269
|
+
const consumerInputProps = (_d = (_c = textFieldProps == null ? void 0 : textFieldProps.slotProps) == null ? void 0 : _c.input) != null ? _d : textFieldProps == null ? void 0 : textFieldProps.InputProps;
|
|
270
|
+
const inputSlot = singleAdornment ? __spreadProps(__spreadValues(__spreadValues({}, muiInputProps), consumerInputProps), {
|
|
271
|
+
startAdornment: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
272
|
+
singleAdornment,
|
|
273
|
+
consumerInputProps == null ? void 0 : consumerInputProps.startAdornment,
|
|
274
|
+
muiInputProps == null ? void 0 : muiInputProps.startAdornment
|
|
275
|
+
] })
|
|
276
|
+
}) : void 0;
|
|
256
277
|
return (
|
|
257
278
|
// @ts-ignore — Ref<any> type mismatch between @types/react versions in monorepo
|
|
258
279
|
/* @__PURE__ */ jsx(
|
|
@@ -266,8 +287,10 @@ function Autocomplete(props) {
|
|
|
266
287
|
helperText: finalHelperText,
|
|
267
288
|
inputRef
|
|
268
289
|
}), textFieldProps), {
|
|
269
|
-
|
|
270
|
-
|
|
290
|
+
slotProps: __spreadProps(__spreadValues(__spreadValues({}, textFieldProps == null ? void 0 : textFieldProps.slotProps), inputSlot ? { input: inputSlot } : {}), {
|
|
291
|
+
inputLabel: __spreadProps(__spreadValues(__spreadValues({}, paramsInputLabel), consumerInputLabel), {
|
|
292
|
+
shrink: labelPosition === "outside" ? !isEmpty || isFocused : paramsInputLabel == null ? void 0 : paramsInputLabel.shrink
|
|
293
|
+
})
|
|
271
294
|
})
|
|
272
295
|
})
|
|
273
296
|
)
|
|
@@ -278,14 +301,14 @@ function Autocomplete(props) {
|
|
|
278
301
|
};
|
|
279
302
|
const extractValue = (opt) => {
|
|
280
303
|
var _a;
|
|
281
|
-
|
|
304
|
+
if (opt === null || opt === void 0) return null;
|
|
305
|
+
if (typeof opt === "string") return opt;
|
|
306
|
+
return (_a = opt == null ? void 0 : opt.value) != null ? _a : null;
|
|
282
307
|
};
|
|
283
308
|
const handleControlledChange = (_event, newValue) => {
|
|
284
309
|
const onChange = props.onChange;
|
|
285
310
|
if (multiple) {
|
|
286
|
-
const values = (newValue != null ? newValue : []).map(
|
|
287
|
-
(opt) => extractValue(opt)
|
|
288
|
-
);
|
|
311
|
+
const values = (newValue != null ? newValue : []).map((opt) => extractValue(opt)).filter((v) => v !== null);
|
|
289
312
|
onChange(values);
|
|
290
313
|
} else {
|
|
291
314
|
onChange(extractValue(newValue));
|
|
@@ -301,13 +324,11 @@ function Autocomplete(props) {
|
|
|
301
324
|
rules: validation,
|
|
302
325
|
render: ({ field, fieldState: { error: fieldError } }) => {
|
|
303
326
|
const resolvedValue2 = stabilizeResolved(
|
|
304
|
-
multiple ? resolveMultipleValue(resolvePool, field.value) : resolveSingleValue(resolvePool, field.value)
|
|
327
|
+
multiple ? resolveMultipleValue(resolvePool, field.value, getKey) : resolveSingleValue(resolvePool, field.value, getKey)
|
|
305
328
|
);
|
|
306
329
|
const handleChange = (_event, newValue) => {
|
|
307
330
|
if (multiple) {
|
|
308
|
-
const next = (newValue != null ? newValue : []).map(
|
|
309
|
-
(opt) => extractValue(opt)
|
|
310
|
-
);
|
|
331
|
+
const next = (newValue != null ? newValue : []).map((opt) => extractValue(opt)).filter((v) => v !== null);
|
|
311
332
|
field.onChange(next);
|
|
312
333
|
onValueChange == null ? void 0 : onValueChange(next);
|
|
313
334
|
} else {
|
|
@@ -330,7 +351,7 @@ function Autocomplete(props) {
|
|
|
330
351
|
}
|
|
331
352
|
const controlledValue = props.value;
|
|
332
353
|
const resolvedValue = stabilizeResolved(
|
|
333
|
-
multiple ? resolveMultipleValue(resolvePool, controlledValue) : resolveSingleValue(resolvePool, controlledValue)
|
|
354
|
+
multiple ? resolveMultipleValue(resolvePool, controlledValue, getKey) : resolveSingleValue(resolvePool, controlledValue, getKey)
|
|
334
355
|
);
|
|
335
356
|
return renderAutocomplete(resolvedValue, handleControlledChange);
|
|
336
357
|
}
|
|
@@ -339,4 +360,4 @@ export {
|
|
|
339
360
|
Autocomplete as A,
|
|
340
361
|
AutocompleteSelect as a
|
|
341
362
|
};
|
|
342
|
-
//# sourceMappingURL=Autocomplete-
|
|
363
|
+
//# sourceMappingURL=Autocomplete-Cvf16lFk.js.map
|