@yamada-ui/autocomplete 1.6.9-dev-20241212135810 → 1.6.9-dev-20241213210300
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/autocomplete-create.js.map +1 -1
- package/dist/autocomplete-create.mjs +2 -2
- package/dist/autocomplete-empty.js.map +1 -1
- package/dist/autocomplete-empty.mjs +2 -2
- package/dist/autocomplete-option.js +44 -43
- package/dist/autocomplete-option.js.map +1 -1
- package/dist/autocomplete-option.mjs +2 -2
- package/dist/autocomplete.js +44 -43
- package/dist/autocomplete.js.map +1 -1
- package/dist/autocomplete.mjs +6 -6
- package/dist/{chunk-PWV7X7G6.mjs → chunk-3FXEJSLI.mjs} +4 -4
- package/dist/chunk-3FXEJSLI.mjs.map +1 -0
- package/dist/{chunk-IFH3PPSD.mjs → chunk-3KSLP2QT.mjs} +4 -4
- package/dist/{chunk-YPKDYYEV.mjs → chunk-KG6IO6XB.mjs} +2 -2
- package/dist/{chunk-RK5E5J5E.mjs → chunk-M5EWJFSX.mjs} +2 -2
- package/dist/{chunk-2LP57WVB.mjs → chunk-NPRQXPV7.mjs} +44 -43
- package/dist/chunk-NPRQXPV7.mjs.map +1 -0
- package/dist/{chunk-ZR77IT3O.mjs → chunk-Y5WDMYXH.mjs} +2 -2
- package/dist/{chunk-2CVB4NO5.mjs → chunk-Y7WZLESA.mjs} +4 -4
- package/dist/index.js +44 -43
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +7 -7
- package/dist/multi-autocomplete.js +44 -43
- package/dist/multi-autocomplete.js.map +1 -1
- package/dist/multi-autocomplete.mjs +6 -6
- package/dist/use-autocomplete-option.d.mts +3 -3
- package/dist/use-autocomplete-option.d.ts +3 -3
- package/dist/use-autocomplete-option.js +42 -41
- package/dist/use-autocomplete-option.js.map +1 -1
- package/dist/use-autocomplete-option.mjs +1 -1
- package/dist/use-autocomplete.js +44 -43
- package/dist/use-autocomplete.js.map +1 -1
- package/dist/use-autocomplete.mjs +3 -3
- package/package.json +13 -13
- package/dist/chunk-2LP57WVB.mjs.map +0 -1
- package/dist/chunk-PWV7X7G6.mjs.map +0 -1
- /package/dist/{chunk-IFH3PPSD.mjs.map → chunk-3KSLP2QT.mjs.map} +0 -0
- /package/dist/{chunk-YPKDYYEV.mjs.map → chunk-KG6IO6XB.mjs.map} +0 -0
- /package/dist/{chunk-RK5E5J5E.mjs.map → chunk-M5EWJFSX.mjs.map} +0 -0
- /package/dist/{chunk-ZR77IT3O.mjs.map → chunk-Y5WDMYXH.mjs.map} +0 -0
- /package/dist/{chunk-2CVB4NO5.mjs.map → chunk-Y7WZLESA.mjs.map} +0 -0
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
import {
|
|
3
3
|
useAutocomplete,
|
|
4
4
|
useAutocompleteInput
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-Y5WDMYXH.mjs";
|
|
6
6
|
import {
|
|
7
7
|
AutocompleteCreate
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-M5EWJFSX.mjs";
|
|
9
9
|
import {
|
|
10
10
|
AutocompleteEmpty
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-KG6IO6XB.mjs";
|
|
12
12
|
import {
|
|
13
13
|
AutocompleteList
|
|
14
14
|
} from "./chunk-LIBFONYN.mjs";
|
|
@@ -259,4 +259,4 @@ MultiAutocompleteField.__ui__ = "MultiAutocompleteField";
|
|
|
259
259
|
export {
|
|
260
260
|
MultiAutocomplete
|
|
261
261
|
};
|
|
262
|
-
//# sourceMappingURL=chunk-
|
|
262
|
+
//# sourceMappingURL=chunk-3KSLP2QT.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
import {
|
|
3
3
|
useAutocompleteEmpty
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NPRQXPV7.mjs";
|
|
5
5
|
import {
|
|
6
6
|
AutocompleteItemIcon
|
|
7
7
|
} from "./chunk-7QCZ5NGS.mjs";
|
|
@@ -61,4 +61,4 @@ AutocompleteMinusIcon.__ui__ = "AutocompleteMinusIcon";
|
|
|
61
61
|
export {
|
|
62
62
|
AutocompleteEmpty
|
|
63
63
|
};
|
|
64
|
-
//# sourceMappingURL=chunk-
|
|
64
|
+
//# sourceMappingURL=chunk-KG6IO6XB.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use client"
|
|
2
2
|
import {
|
|
3
3
|
useAutocompleteCreate
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-NPRQXPV7.mjs";
|
|
5
5
|
import {
|
|
6
6
|
AutocompleteItemIcon
|
|
7
7
|
} from "./chunk-7QCZ5NGS.mjs";
|
|
@@ -60,4 +60,4 @@ AutocompletePlusIcon.__ui__ = "AutocompletePlusIcon";
|
|
|
60
60
|
export {
|
|
61
61
|
AutocompleteCreate
|
|
62
62
|
};
|
|
63
|
-
//# sourceMappingURL=chunk-
|
|
63
|
+
//# sourceMappingURL=chunk-M5EWJFSX.mjs.map
|
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
isUndefined,
|
|
17
17
|
mergeRefs
|
|
18
18
|
} from "@yamada-ui/utils";
|
|
19
|
-
import { useCallback, useId, useRef } from "react";
|
|
19
|
+
import { useCallback, useId, useMemo, useRef } from "react";
|
|
20
20
|
var isTargetOption = (target) => {
|
|
21
21
|
var _a;
|
|
22
22
|
return isHTMLElement(target) && !!((_a = target.getAttribute("role")) == null ? void 0 : _a.startsWith("option"));
|
|
@@ -29,7 +29,7 @@ var useAutocompleteOption = (props) => {
|
|
|
29
29
|
inputRef,
|
|
30
30
|
omitSelectedValues,
|
|
31
31
|
setFocusedIndex,
|
|
32
|
-
value,
|
|
32
|
+
value: selectedValue,
|
|
33
33
|
optionProps,
|
|
34
34
|
onChange,
|
|
35
35
|
onClose,
|
|
@@ -37,43 +37,44 @@ var useAutocompleteOption = (props) => {
|
|
|
37
37
|
} = useAutocompleteContext();
|
|
38
38
|
const uuid = useId();
|
|
39
39
|
const itemRef = useRef(null);
|
|
40
|
-
|
|
41
|
-
id,
|
|
40
|
+
const {
|
|
41
|
+
id = uuid,
|
|
42
42
|
children,
|
|
43
43
|
closeOnSelect: customCloseOnSelect,
|
|
44
|
-
disabled,
|
|
45
|
-
focusable,
|
|
46
|
-
icon: customIcon,
|
|
47
44
|
isDisabled,
|
|
45
|
+
disabled = isDisabled,
|
|
48
46
|
isFocusable,
|
|
47
|
+
focusable = isFocusable,
|
|
48
|
+
icon: customIcon,
|
|
49
49
|
value: optionValue,
|
|
50
50
|
...computedProps
|
|
51
51
|
} = { ...optionProps, ...props };
|
|
52
|
-
disabled != null ? disabled : disabled = isDisabled;
|
|
53
|
-
focusable != null ? focusable : focusable = isFocusable;
|
|
54
52
|
const trulyDisabled = !!disabled && !focusable;
|
|
55
53
|
const { descendants, index, register } = useAutocompleteDescendant({
|
|
56
54
|
disabled: trulyDisabled
|
|
57
55
|
});
|
|
58
56
|
const values = descendants.values();
|
|
59
57
|
const frontValues = values.slice(0, index);
|
|
60
|
-
const
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
)
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: Cannot infer the option value of complex children. Pass a \`value\` prop or use a plain string as children to <Option>.`
|
|
74
|
-
);
|
|
58
|
+
const multi = isArray(selectedValue);
|
|
59
|
+
const target = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
|
|
60
|
+
const focused = index === focusedIndex;
|
|
61
|
+
const value = useMemo(() => {
|
|
62
|
+
let value2 = optionValue;
|
|
63
|
+
if (isUndefined(optionValue)) {
|
|
64
|
+
if (isString(children) || isNumber(children)) {
|
|
65
|
+
value2 = children.toString();
|
|
66
|
+
} else {
|
|
67
|
+
console.warn(
|
|
68
|
+
`${!multi ? "Autocomplete" : "MultiAutocomplete"}: Cannot infer the option value of complex children. Pass a \`value\` prop or use a plain string as children to <Option>.`
|
|
69
|
+
);
|
|
70
|
+
}
|
|
75
71
|
}
|
|
76
|
-
|
|
72
|
+
return value2 != null ? value2 : "";
|
|
73
|
+
}, [children, multi, optionValue]);
|
|
74
|
+
const duplicated = frontValues.some(
|
|
75
|
+
({ node }) => node.dataset.value === value
|
|
76
|
+
);
|
|
77
|
+
const selected = !duplicated && (!multi ? value === selectedValue : selectedValue.includes(value));
|
|
77
78
|
const onClick = useCallback(
|
|
78
79
|
(ev) => {
|
|
79
80
|
ev.stopPropagation();
|
|
@@ -81,18 +82,18 @@ var useAutocompleteOption = (props) => {
|
|
|
81
82
|
if (inputRef.current) inputRef.current.focus();
|
|
82
83
|
return;
|
|
83
84
|
}
|
|
84
|
-
if (!
|
|
85
|
-
onChange(
|
|
85
|
+
if (!duplicated) setFocusedIndex(index);
|
|
86
|
+
onChange(value);
|
|
86
87
|
if (inputRef.current) inputRef.current.focus();
|
|
87
88
|
if (customCloseOnSelect != null ? customCloseOnSelect : closeOnSelect) onClose();
|
|
88
89
|
if (omitSelectedValues) onFocusNext(index);
|
|
89
90
|
},
|
|
90
91
|
[
|
|
91
|
-
|
|
92
|
+
duplicated,
|
|
92
93
|
onFocusNext,
|
|
93
94
|
omitSelectedValues,
|
|
94
95
|
disabled,
|
|
95
|
-
|
|
96
|
+
value,
|
|
96
97
|
setFocusedIndex,
|
|
97
98
|
index,
|
|
98
99
|
onChange,
|
|
@@ -104,7 +105,7 @@ var useAutocompleteOption = (props) => {
|
|
|
104
105
|
);
|
|
105
106
|
const getOptionProps = useCallback(
|
|
106
107
|
(props2 = {}, ref = null) => {
|
|
107
|
-
const isHidden = !
|
|
108
|
+
const isHidden = !target || omitSelectedValues && selected;
|
|
108
109
|
const style = {
|
|
109
110
|
border: "0px",
|
|
110
111
|
clip: "rect(0px, 0px, 0px, 0px)",
|
|
@@ -125,37 +126,37 @@ var useAutocompleteOption = (props) => {
|
|
|
125
126
|
style: isHidden ? style : void 0,
|
|
126
127
|
"aria-disabled": ariaAttr(disabled),
|
|
127
128
|
"aria-hidden": ariaAttr(isHidden),
|
|
128
|
-
"aria-selected":
|
|
129
|
+
"aria-selected": selected,
|
|
129
130
|
"data-disabled": dataAttr(disabled),
|
|
130
|
-
"data-duplicated": dataAttr(
|
|
131
|
-
"data-focus": dataAttr(
|
|
131
|
+
"data-duplicated": dataAttr(duplicated),
|
|
132
|
+
"data-focus": dataAttr(focused),
|
|
132
133
|
"data-target": dataAttr(true),
|
|
133
|
-
"data-value":
|
|
134
|
+
"data-value": value,
|
|
134
135
|
tabIndex: -1,
|
|
135
136
|
onClick: handlerAll(computedProps.onClick, props2.onClick, onClick)
|
|
136
137
|
};
|
|
137
138
|
},
|
|
138
139
|
[
|
|
139
140
|
id,
|
|
140
|
-
|
|
141
|
-
|
|
141
|
+
duplicated,
|
|
142
|
+
value,
|
|
142
143
|
computedProps,
|
|
143
144
|
disabled,
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
145
|
+
focused,
|
|
146
|
+
selected,
|
|
147
|
+
target,
|
|
147
148
|
omitSelectedValues,
|
|
148
149
|
onClick,
|
|
149
150
|
register
|
|
150
151
|
]
|
|
151
152
|
);
|
|
152
153
|
return {
|
|
154
|
+
target,
|
|
153
155
|
children,
|
|
154
156
|
customIcon,
|
|
155
|
-
|
|
156
|
-
isSelected,
|
|
157
|
-
isTarget,
|
|
157
|
+
focused,
|
|
158
158
|
omitSelectedValues,
|
|
159
|
+
selected,
|
|
159
160
|
getOptionProps
|
|
160
161
|
};
|
|
161
162
|
};
|
|
@@ -224,4 +225,4 @@ export {
|
|
|
224
225
|
useAutocompleteCreate,
|
|
225
226
|
useAutocompleteEmpty
|
|
226
227
|
};
|
|
227
|
-
//# sourceMappingURL=chunk-
|
|
228
|
+
//# sourceMappingURL=chunk-NPRQXPV7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/use-autocomplete-option.ts"],"sourcesContent":["import type { HTMLUIProps, PropGetter } from \"@yamada-ui/core\"\nimport type { CSSProperties, MouseEvent } from \"react\"\nimport {\n ariaAttr,\n dataAttr,\n handlerAll,\n isArray,\n isHTMLElement,\n isNumber,\n isString,\n isUndefined,\n mergeRefs,\n} from \"@yamada-ui/utils\"\nimport { useCallback, useId, useMemo, useRef } from \"react\"\nimport {\n useAutocompleteContext,\n useAutocompleteDescendant,\n} from \"./autocomplete-context\"\n\nconst isTargetOption = (target: EventTarget | null): boolean =>\n isHTMLElement(target) && !!target.getAttribute(\"role\")?.startsWith(\"option\")\n\nexport interface UseAutocompleteOptionProps\n extends Omit<HTMLUIProps, \"children\" | \"value\"> {\n /**\n * The label of the autocomplete option.\n */\n children?: string\n /**\n * If `true`, the list element will be closed when selected.\n *\n * @default false\n */\n closeOnSelect?: boolean\n /**\n * If `true`, the autocomplete option will be disabled.\n *\n * @default false\n */\n disabled?: boolean\n /**\n * If `true`, the autocomplete option will be focusable.\n *\n * @default false\n */\n focusable?: boolean\n /**\n * If `true`, the autocomplete option will be disabled.\n *\n * @default false\n *\n * @deprecated Use `disabled` instead.\n */\n isDisabled?: boolean\n /**\n * If `true`, the autocomplete option will be focusable.\n *\n * @default false\n *\n * @deprecated Use `focusable` instead.\n */\n isFocusable?: boolean\n /**\n * The value of the autocomplete option.\n */\n value?: string\n}\n\nexport const useAutocompleteOption = (props: UseAutocompleteOptionProps) => {\n const {\n closeOnSelect,\n focusedIndex,\n inputRef,\n omitSelectedValues,\n setFocusedIndex,\n value: selectedValue,\n optionProps,\n onChange,\n onClose,\n onFocusNext,\n } = useAutocompleteContext()\n const uuid = useId()\n const itemRef = useRef<HTMLLIElement>(null)\n const {\n id = uuid,\n children,\n closeOnSelect: customCloseOnSelect,\n isDisabled,\n disabled = isDisabled,\n isFocusable,\n focusable = isFocusable,\n icon: customIcon,\n value: optionValue,\n ...computedProps\n } = { ...optionProps, ...props }\n const trulyDisabled = !!disabled && !focusable\n const { descendants, index, register } = useAutocompleteDescendant({\n disabled: trulyDisabled,\n })\n const values = descendants.values()\n const frontValues = values.slice(0, index)\n const multi = isArray(selectedValue)\n const target = \"target\" in (itemRef.current?.dataset ?? {})\n const focused = index === focusedIndex\n\n const value = useMemo(() => {\n let value = optionValue\n\n if (isUndefined(optionValue)) {\n if (isString(children) || isNumber(children)) {\n value = children.toString()\n } else {\n console.warn(\n `${\n !multi ? \"Autocomplete\" : \"MultiAutocomplete\"\n }: Cannot infer the option value of complex children. Pass a \\`value\\` prop or use a plain string as children to <Option>.`,\n )\n }\n }\n\n return value ?? \"\"\n }, [children, multi, optionValue])\n\n const duplicated = frontValues.some(\n ({ node }) => node.dataset.value === value,\n )\n const selected =\n !duplicated &&\n (!multi ? value === selectedValue : selectedValue.includes(value))\n\n const onClick = useCallback(\n (ev: MouseEvent<HTMLDivElement>) => {\n ev.stopPropagation()\n\n if (disabled || !isTargetOption(ev.currentTarget)) {\n if (inputRef.current) inputRef.current.focus()\n\n return\n }\n\n if (!duplicated) setFocusedIndex(index)\n\n onChange(value)\n\n if (inputRef.current) inputRef.current.focus()\n\n if (customCloseOnSelect ?? closeOnSelect) onClose()\n\n if (omitSelectedValues) onFocusNext(index)\n },\n [\n duplicated,\n onFocusNext,\n omitSelectedValues,\n disabled,\n value,\n setFocusedIndex,\n index,\n onChange,\n customCloseOnSelect,\n closeOnSelect,\n onClose,\n inputRef,\n ],\n )\n\n const getOptionProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n const isHidden = !target || (omitSelectedValues && selected)\n\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: \"0px\",\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: \"1px\",\n }\n\n return {\n ref: mergeRefs(itemRef, ref, register),\n role: \"option\",\n ...computedProps,\n ...props,\n id,\n style: isHidden ? style : undefined,\n \"aria-disabled\": ariaAttr(disabled),\n \"aria-hidden\": ariaAttr(isHidden),\n \"aria-selected\": selected,\n \"data-disabled\": dataAttr(disabled),\n \"data-duplicated\": dataAttr(duplicated),\n \"data-focus\": dataAttr(focused),\n \"data-target\": dataAttr(true),\n \"data-value\": value,\n tabIndex: -1,\n onClick: handlerAll(computedProps.onClick, props.onClick, onClick),\n }\n },\n [\n id,\n duplicated,\n value,\n computedProps,\n disabled,\n focused,\n selected,\n target,\n omitSelectedValues,\n onClick,\n register,\n ],\n )\n\n return {\n target,\n children,\n customIcon,\n focused,\n omitSelectedValues,\n selected,\n getOptionProps,\n }\n}\n\nexport type UseAutocompleteOptionReturn = ReturnType<\n typeof useAutocompleteOption\n>\n\nexport const useAutocompleteCreate = () => {\n const { isHit, onCreate } = useAutocompleteContext()\n\n const getCreateProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: \"0px\",\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: \"1px\",\n }\n\n return {\n ref,\n role: \"option\",\n ...props,\n style: isHit ? style : undefined,\n \"aria-hidden\": ariaAttr(isHit),\n \"data-focus\": dataAttr(!isHit),\n tabIndex: -1,\n onClick: handlerAll(props.onClick, onCreate),\n }\n },\n [isHit, onCreate],\n )\n\n return { getCreateProps }\n}\n\nexport type UseAutocompleteCreateReturn = ReturnType<\n typeof useAutocompleteCreate\n>\n\nexport const useAutocompleteEmpty = () => {\n const { isEmpty, isHit } = useAutocompleteContext()\n\n const getEmptyProps: PropGetter = useCallback(\n (props = {}, ref = null) => {\n const isHidden = isHit && !isEmpty\n\n const style: CSSProperties = {\n border: \"0px\",\n clip: \"rect(0px, 0px, 0px, 0px)\",\n height: \"1px\",\n margin: \"-1px\",\n overflow: \"hidden\",\n padding: \"0px\",\n position: \"absolute\",\n whiteSpace: \"nowrap\",\n width: \"1px\",\n }\n\n return {\n ref,\n role: \"presentation\",\n ...props,\n style: isHidden ? style : undefined,\n \"aria-hidden\": ariaAttr(isHidden),\n tabIndex: -1,\n }\n },\n [isHit, isEmpty],\n )\n\n return { getEmptyProps }\n}\n\nexport type UseAutocompleteEmptyReturn = ReturnType<typeof useAutocompleteEmpty>\n"],"mappings":";;;;;;;AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa,OAAO,SAAS,cAAc;AAMpD,IAAM,iBAAiB,CAAC,WAAqC;AAnB7D;AAoBE,uBAAc,MAAM,KAAK,CAAC,GAAC,YAAO,aAAa,MAAM,MAA1B,mBAA6B,WAAW;AAAA;AAgD9D,IAAM,wBAAwB,CAAC,UAAsC;AApE5E;AAqEE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,uBAAuB;AAC3B,QAAM,OAAO,MAAM;AACnB,QAAM,UAAU,OAAsB,IAAI;AAC1C,QAAM;AAAA,IACJ,KAAK;AAAA,IACL;AAAA,IACA,eAAe;AAAA,IACf;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA,YAAY;AAAA,IACZ,MAAM;AAAA,IACN,OAAO;AAAA,IACP,GAAG;AAAA,EACL,IAAI,EAAE,GAAG,aAAa,GAAG,MAAM;AAC/B,QAAM,gBAAgB,CAAC,CAAC,YAAY,CAAC;AACrC,QAAM,EAAE,aAAa,OAAO,SAAS,IAAI,0BAA0B;AAAA,IACjE,UAAU;AAAA,EACZ,CAAC;AACD,QAAM,SAAS,YAAY,OAAO;AAClC,QAAM,cAAc,OAAO,MAAM,GAAG,KAAK;AACzC,QAAM,Q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ACT,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,OAAO;AAAA,MACT;AAEA,aAAO;AAAA,QACL;AAAA,QACA,MAAM;AAAA,QACN,GAAG;AAAA,QACH,OAAO,QAAQ,QAAQ;AAAA,QACvB,eAAe,SAAS,KAAK;AAAA,QAC7B,cAAc,SAAS,CAAC,KAAK;AAAA,QAC7B,UAAU;AAAA,QACV,SAAS,WAAW,MAAM,SAAS,QAAQ;AAAA,MAC7C;AAAA,IACF;AAAA,IACA,CAAC,OAAO,QAAQ;AAAA,EAClB;AAEA,SAAO,EAAE,eAAe;AAC1B;AAMO,IAAM,uBAAuB,MAAM;AACxC,QAAM,EAAE,SAAS,MAAM,IAAI,uBAAuB;AAElD,QAAM,gBAA4B;AAAA,IAChC,CAAC,QAAQ,CAAC,GAAG,MAAM,SAAS;AAC1B,YAAM,WAAW,SAAS,CAAC;AAE3B,YAAM,QAAuB;AAAA,QAC3B,QAAQ;AAAA,QACR,MAAM;AAAA,QACN,QAAQ;AAAA,QACR,QAAQ;AAAA,QACR,UAAU;AAAA,QACV,SAAS;AAAA,QACT,UAAU;AAAA,QACV,YAAY;AAAA,QACZ,OAAO;AAAA,MACT;AAEA,aAAO;AAAA,QACL;AAAA,QACA,MAAM;AAAA,QACN,GAAG;AAAA,QACH,OAAO,WAAW,QAAQ;AAAA,QAC1B,eAAe,SAAS,QAAQ;AAAA,QAChC,UAAU;AAAA,MACZ;AAAA,IACF;AAAA,IACA,CAAC,OAAO,OAAO;AAAA,EACjB;AAEA,SAAO,EAAE,cAAc;AACzB;","names":["value","props"]}
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from "./chunk-ABCTEZN5.mjs";
|
|
5
5
|
import {
|
|
6
6
|
AutocompleteOption
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-3FXEJSLI.mjs";
|
|
8
8
|
import {
|
|
9
9
|
useAutocompleteContext,
|
|
10
10
|
useAutocompleteDescendants
|
|
@@ -903,4 +903,4 @@ export {
|
|
|
903
903
|
useAutocomplete,
|
|
904
904
|
useAutocompleteInput
|
|
905
905
|
};
|
|
906
|
-
//# sourceMappingURL=chunk-
|
|
906
|
+
//# sourceMappingURL=chunk-Y5WDMYXH.mjs.map
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
import {
|
|
3
3
|
useAutocomplete,
|
|
4
4
|
useAutocompleteInput
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-Y5WDMYXH.mjs";
|
|
6
6
|
import {
|
|
7
7
|
AutocompleteCreate
|
|
8
|
-
} from "./chunk-
|
|
8
|
+
} from "./chunk-M5EWJFSX.mjs";
|
|
9
9
|
import {
|
|
10
10
|
AutocompleteEmpty
|
|
11
|
-
} from "./chunk-
|
|
11
|
+
} from "./chunk-KG6IO6XB.mjs";
|
|
12
12
|
import {
|
|
13
13
|
AutocompleteList
|
|
14
14
|
} from "./chunk-LIBFONYN.mjs";
|
|
@@ -181,4 +181,4 @@ AutocompleteField.__ui__ = "AutocompleteField";
|
|
|
181
181
|
export {
|
|
182
182
|
Autocomplete
|
|
183
183
|
};
|
|
184
|
-
//# sourceMappingURL=chunk-
|
|
184
|
+
//# sourceMappingURL=chunk-Y7WZLESA.mjs.map
|
package/dist/index.js
CHANGED
|
@@ -166,7 +166,7 @@ var useAutocompleteOption = (props) => {
|
|
|
166
166
|
inputRef,
|
|
167
167
|
omitSelectedValues,
|
|
168
168
|
setFocusedIndex,
|
|
169
|
-
value,
|
|
169
|
+
value: selectedValue,
|
|
170
170
|
optionProps,
|
|
171
171
|
onChange,
|
|
172
172
|
onClose,
|
|
@@ -174,43 +174,44 @@ var useAutocompleteOption = (props) => {
|
|
|
174
174
|
} = useAutocompleteContext();
|
|
175
175
|
const uuid = (0, import_react2.useId)();
|
|
176
176
|
const itemRef = (0, import_react2.useRef)(null);
|
|
177
|
-
|
|
178
|
-
id,
|
|
177
|
+
const {
|
|
178
|
+
id = uuid,
|
|
179
179
|
children,
|
|
180
180
|
closeOnSelect: customCloseOnSelect,
|
|
181
|
-
disabled,
|
|
182
|
-
focusable,
|
|
183
|
-
icon: customIcon,
|
|
184
181
|
isDisabled,
|
|
182
|
+
disabled = isDisabled,
|
|
185
183
|
isFocusable,
|
|
184
|
+
focusable = isFocusable,
|
|
185
|
+
icon: customIcon,
|
|
186
186
|
value: optionValue,
|
|
187
187
|
...computedProps
|
|
188
188
|
} = { ...optionProps, ...props };
|
|
189
|
-
disabled != null ? disabled : disabled = isDisabled;
|
|
190
|
-
focusable != null ? focusable : focusable = isFocusable;
|
|
191
189
|
const trulyDisabled = !!disabled && !focusable;
|
|
192
190
|
const { descendants, index, register } = useAutocompleteDescendant({
|
|
193
191
|
disabled: trulyDisabled
|
|
194
192
|
});
|
|
195
193
|
const values = descendants.values();
|
|
196
194
|
const frontValues = values.slice(0, index);
|
|
197
|
-
const
|
|
198
|
-
const
|
|
199
|
-
|
|
200
|
-
)
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
`${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: Cannot infer the option value of complex children. Pass a \`value\` prop or use a plain string as children to <Option>.`
|
|
211
|
-
);
|
|
195
|
+
const multi = (0, import_utils3.isArray)(selectedValue);
|
|
196
|
+
const target = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
|
|
197
|
+
const focused = index === focusedIndex;
|
|
198
|
+
const value = (0, import_react2.useMemo)(() => {
|
|
199
|
+
let value2 = optionValue;
|
|
200
|
+
if ((0, import_utils3.isUndefined)(optionValue)) {
|
|
201
|
+
if ((0, import_utils3.isString)(children) || (0, import_utils3.isNumber)(children)) {
|
|
202
|
+
value2 = children.toString();
|
|
203
|
+
} else {
|
|
204
|
+
console.warn(
|
|
205
|
+
`${!multi ? "Autocomplete" : "MultiAutocomplete"}: Cannot infer the option value of complex children. Pass a \`value\` prop or use a plain string as children to <Option>.`
|
|
206
|
+
);
|
|
207
|
+
}
|
|
212
208
|
}
|
|
213
|
-
|
|
209
|
+
return value2 != null ? value2 : "";
|
|
210
|
+
}, [children, multi, optionValue]);
|
|
211
|
+
const duplicated = frontValues.some(
|
|
212
|
+
({ node }) => node.dataset.value === value
|
|
213
|
+
);
|
|
214
|
+
const selected = !duplicated && (!multi ? value === selectedValue : selectedValue.includes(value));
|
|
214
215
|
const onClick = (0, import_react2.useCallback)(
|
|
215
216
|
(ev) => {
|
|
216
217
|
ev.stopPropagation();
|
|
@@ -218,18 +219,18 @@ var useAutocompleteOption = (props) => {
|
|
|
218
219
|
if (inputRef.current) inputRef.current.focus();
|
|
219
220
|
return;
|
|
220
221
|
}
|
|
221
|
-
if (!
|
|
222
|
-
onChange(
|
|
222
|
+
if (!duplicated) setFocusedIndex(index);
|
|
223
|
+
onChange(value);
|
|
223
224
|
if (inputRef.current) inputRef.current.focus();
|
|
224
225
|
if (customCloseOnSelect != null ? customCloseOnSelect : closeOnSelect) onClose();
|
|
225
226
|
if (omitSelectedValues) onFocusNext(index);
|
|
226
227
|
},
|
|
227
228
|
[
|
|
228
|
-
|
|
229
|
+
duplicated,
|
|
229
230
|
onFocusNext,
|
|
230
231
|
omitSelectedValues,
|
|
231
232
|
disabled,
|
|
232
|
-
|
|
233
|
+
value,
|
|
233
234
|
setFocusedIndex,
|
|
234
235
|
index,
|
|
235
236
|
onChange,
|
|
@@ -241,7 +242,7 @@ var useAutocompleteOption = (props) => {
|
|
|
241
242
|
);
|
|
242
243
|
const getOptionProps = (0, import_react2.useCallback)(
|
|
243
244
|
(props2 = {}, ref = null) => {
|
|
244
|
-
const isHidden = !
|
|
245
|
+
const isHidden = !target || omitSelectedValues && selected;
|
|
245
246
|
const style = {
|
|
246
247
|
border: "0px",
|
|
247
248
|
clip: "rect(0px, 0px, 0px, 0px)",
|
|
@@ -262,37 +263,37 @@ var useAutocompleteOption = (props) => {
|
|
|
262
263
|
style: isHidden ? style : void 0,
|
|
263
264
|
"aria-disabled": (0, import_utils3.ariaAttr)(disabled),
|
|
264
265
|
"aria-hidden": (0, import_utils3.ariaAttr)(isHidden),
|
|
265
|
-
"aria-selected":
|
|
266
|
+
"aria-selected": selected,
|
|
266
267
|
"data-disabled": (0, import_utils3.dataAttr)(disabled),
|
|
267
|
-
"data-duplicated": (0, import_utils3.dataAttr)(
|
|
268
|
-
"data-focus": (0, import_utils3.dataAttr)(
|
|
268
|
+
"data-duplicated": (0, import_utils3.dataAttr)(duplicated),
|
|
269
|
+
"data-focus": (0, import_utils3.dataAttr)(focused),
|
|
269
270
|
"data-target": (0, import_utils3.dataAttr)(true),
|
|
270
|
-
"data-value":
|
|
271
|
+
"data-value": value,
|
|
271
272
|
tabIndex: -1,
|
|
272
273
|
onClick: (0, import_utils3.handlerAll)(computedProps.onClick, props2.onClick, onClick)
|
|
273
274
|
};
|
|
274
275
|
},
|
|
275
276
|
[
|
|
276
277
|
id,
|
|
277
|
-
|
|
278
|
-
|
|
278
|
+
duplicated,
|
|
279
|
+
value,
|
|
279
280
|
computedProps,
|
|
280
281
|
disabled,
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
282
|
+
focused,
|
|
283
|
+
selected,
|
|
284
|
+
target,
|
|
284
285
|
omitSelectedValues,
|
|
285
286
|
onClick,
|
|
286
287
|
register
|
|
287
288
|
]
|
|
288
289
|
);
|
|
289
290
|
return {
|
|
291
|
+
target,
|
|
290
292
|
children,
|
|
291
293
|
customIcon,
|
|
292
|
-
|
|
293
|
-
isSelected,
|
|
294
|
-
isTarget,
|
|
294
|
+
focused,
|
|
295
295
|
omitSelectedValues,
|
|
296
|
+
selected,
|
|
296
297
|
getOptionProps
|
|
297
298
|
};
|
|
298
299
|
};
|
|
@@ -612,7 +613,7 @@ var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
|
612
613
|
var AutocompleteOption = (0, import_core5.forwardRef)(
|
|
613
614
|
({ className, icon, ...rest }, ref) => {
|
|
614
615
|
const { styles } = useAutocompleteContext();
|
|
615
|
-
const { children, customIcon,
|
|
616
|
+
const { children, customIcon, selected, getOptionProps } = useAutocompleteOption(rest);
|
|
616
617
|
icon != null ? icon : icon = customIcon;
|
|
617
618
|
const css = {
|
|
618
619
|
alignItems: "center",
|
|
@@ -634,7 +635,7 @@ var AutocompleteOption = (0, import_core5.forwardRef)(
|
|
|
634
635
|
__css: css,
|
|
635
636
|
...getOptionProps({}, ref),
|
|
636
637
|
children: [
|
|
637
|
-
icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AutocompleteItemIcon, { opacity:
|
|
638
|
+
icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AutocompleteItemIcon, { opacity: selected ? 1 : 0, children: icon || /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AutocompleteCheckIcon, {}) }) : null,
|
|
638
639
|
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_core5.ui.span, { style: { flex: 1 }, "data-label": true, children })
|
|
639
640
|
]
|
|
640
641
|
}
|