@yamada-ui/autocomplete 1.5.1 → 1.5.2-dev-20240917033401

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.
Files changed (105) hide show
  1. package/dist/autocomplete-context.d.mts +210 -0
  2. package/dist/autocomplete-context.d.ts +210 -0
  3. package/dist/autocomplete-context.js +53 -0
  4. package/dist/autocomplete-context.js.map +1 -0
  5. package/dist/autocomplete-context.mjs +18 -0
  6. package/dist/autocomplete-context.mjs.map +1 -0
  7. package/dist/autocomplete-create.d.mts +4 -3
  8. package/dist/autocomplete-create.d.ts +4 -3
  9. package/dist/autocomplete-create.js +56 -61
  10. package/dist/autocomplete-create.js.map +1 -1
  11. package/dist/autocomplete-create.mjs +4 -1
  12. package/dist/autocomplete-empty.d.mts +4 -3
  13. package/dist/autocomplete-empty.d.ts +4 -3
  14. package/dist/autocomplete-empty.js +54 -59
  15. package/dist/autocomplete-empty.js.map +1 -1
  16. package/dist/autocomplete-empty.mjs +4 -1
  17. package/dist/autocomplete-icon.d.mts +6 -4
  18. package/dist/autocomplete-icon.d.ts +6 -4
  19. package/dist/autocomplete-icon.js +15 -22
  20. package/dist/autocomplete-icon.js.map +1 -1
  21. package/dist/autocomplete-icon.mjs +2 -1
  22. package/dist/autocomplete-list.d.mts +2 -2
  23. package/dist/autocomplete-list.d.ts +2 -2
  24. package/dist/autocomplete-list.js +20 -23
  25. package/dist/autocomplete-list.js.map +1 -1
  26. package/dist/autocomplete-list.mjs +3 -1
  27. package/dist/autocomplete-option-group.d.mts +5 -9
  28. package/dist/autocomplete-option-group.d.ts +5 -9
  29. package/dist/autocomplete-option-group.js +14 -16
  30. package/dist/autocomplete-option-group.js.map +1 -1
  31. package/dist/autocomplete-option-group.mjs +3 -1
  32. package/dist/autocomplete-option.d.mts +15 -8
  33. package/dist/autocomplete-option.d.ts +15 -8
  34. package/dist/autocomplete-option.js +97 -102
  35. package/dist/autocomplete-option.js.map +1 -1
  36. package/dist/autocomplete-option.mjs +4 -1
  37. package/dist/autocomplete.d.mts +13 -7
  38. package/dist/autocomplete.d.ts +13 -7
  39. package/dist/autocomplete.js +673 -661
  40. package/dist/autocomplete.js.map +1 -1
  41. package/dist/autocomplete.mjs +12 -1
  42. package/dist/chunk-7GCVSXCV.mjs +190 -0
  43. package/dist/chunk-7GCVSXCV.mjs.map +1 -0
  44. package/dist/chunk-BD7VZQOL.mjs +267 -0
  45. package/dist/chunk-BD7VZQOL.mjs.map +1 -0
  46. package/dist/chunk-FZM3BH3D.mjs +57 -0
  47. package/dist/chunk-FZM3BH3D.mjs.map +1 -0
  48. package/dist/chunk-GM7RV2YY.mjs +959 -0
  49. package/dist/chunk-GM7RV2YY.mjs.map +1 -0
  50. package/dist/chunk-GOMUH7TZ.mjs +60 -0
  51. package/dist/chunk-GOMUH7TZ.mjs.map +1 -0
  52. package/dist/chunk-HL2KEBRX.mjs +87 -0
  53. package/dist/chunk-HL2KEBRX.mjs.map +1 -0
  54. package/dist/chunk-JMX72TSD.mjs +78 -0
  55. package/dist/chunk-JMX72TSD.mjs.map +1 -0
  56. package/dist/chunk-JPUKYLBW.mjs +25 -0
  57. package/dist/chunk-JPUKYLBW.mjs.map +1 -0
  58. package/dist/chunk-JXFXCGZK.mjs +102 -0
  59. package/dist/chunk-JXFXCGZK.mjs.map +1 -0
  60. package/dist/chunk-KCALQJLK.mjs +59 -0
  61. package/dist/chunk-KCALQJLK.mjs.map +1 -0
  62. package/dist/chunk-PRDD3JJO.mjs +202 -0
  63. package/dist/chunk-PRDD3JJO.mjs.map +1 -0
  64. package/dist/chunk-QGOCVO2C.mjs +68 -0
  65. package/dist/chunk-QGOCVO2C.mjs.map +1 -0
  66. package/dist/chunk-QQFSHTTC.mjs +59 -0
  67. package/dist/chunk-QQFSHTTC.mjs.map +1 -0
  68. package/dist/index.d.mts +4 -1
  69. package/dist/index.d.ts +4 -1
  70. package/dist/index.js +1550 -1536
  71. package/dist/index.js.map +1 -1
  72. package/dist/index.mjs +23 -6
  73. package/dist/multi-autocomplete.d.mts +13 -7
  74. package/dist/multi-autocomplete.d.ts +13 -7
  75. package/dist/multi-autocomplete.js +1516 -1504
  76. package/dist/multi-autocomplete.js.map +1 -1
  77. package/dist/multi-autocomplete.mjs +12 -1
  78. package/dist/use-autocomplete-list.d.mts +8 -0
  79. package/dist/use-autocomplete-list.d.ts +8 -0
  80. package/dist/use-autocomplete-list.js +103 -0
  81. package/dist/use-autocomplete-list.js.map +1 -0
  82. package/dist/use-autocomplete-list.mjs +9 -0
  83. package/dist/use-autocomplete-list.mjs.map +1 -0
  84. package/dist/use-autocomplete-option-group.d.mts +16 -0
  85. package/dist/use-autocomplete-option-group.d.ts +16 -0
  86. package/dist/use-autocomplete-option-group.js +113 -0
  87. package/dist/use-autocomplete-option-group.js.map +1 -0
  88. package/dist/use-autocomplete-option-group.mjs +9 -0
  89. package/dist/use-autocomplete-option-group.mjs.map +1 -0
  90. package/dist/use-autocomplete-option.d.mts +49 -0
  91. package/dist/use-autocomplete-option.d.ts +49 -0
  92. package/dist/use-autocomplete-option.js +231 -0
  93. package/dist/use-autocomplete-option.js.map +1 -0
  94. package/dist/use-autocomplete-option.mjs +13 -0
  95. package/dist/use-autocomplete-option.mjs.map +1 -0
  96. package/dist/use-autocomplete.d.mts +188 -8
  97. package/dist/use-autocomplete.d.ts +188 -8
  98. package/dist/use-autocomplete.js +359 -481
  99. package/dist/use-autocomplete.js.map +1 -1
  100. package/dist/use-autocomplete.mjs +9 -25
  101. package/package.json +13 -13
  102. package/dist/chunk-ZD25NCFE.mjs +0 -2038
  103. package/dist/chunk-ZD25NCFE.mjs.map +0 -1
  104. package/dist/use-autocomplete-BJNWa6hL.d.mts +0 -389
  105. package/dist/use-autocomplete-BJNWa6hL.d.ts +0 -389
package/dist/index.js CHANGED
@@ -31,1422 +31,1614 @@ __export(src_exports, {
31
31
  module.exports = __toCommonJS(src_exports);
32
32
 
33
33
  // src/autocomplete.tsx
34
- var import_core4 = require("@yamada-ui/core");
34
+ var import_core9 = require("@yamada-ui/core");
35
35
  var import_popover2 = require("@yamada-ui/popover");
36
36
  var import_portal = require("@yamada-ui/portal");
37
+ var import_utils12 = require("@yamada-ui/utils");
38
+
39
+ // src/autocomplete-context.ts
40
+ var import_use_descendant = require("@yamada-ui/use-descendant");
41
+ var import_utils = require("@yamada-ui/utils");
42
+ var {
43
+ DescendantsContextProvider: AutocompleteDescendantsContextProvider,
44
+ useDescendantsContext: useAutocompleteDescendantsContext,
45
+ useDescendants: useAutocompleteDescendants,
46
+ useDescendant: useAutocompleteDescendant
47
+ } = (0, import_use_descendant.createDescendant)();
48
+ var [AutocompleteProvider, useAutocompleteContext] = (0, import_utils.createContext)({
49
+ name: "AutocompleteContext",
50
+ errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in "<Autocomplete />" or "<MultiAutocomplete />"`
51
+ });
52
+
53
+ // src/autocomplete-create.tsx
54
+ var import_core2 = require("@yamada-ui/core");
37
55
  var import_utils4 = require("@yamada-ui/utils");
38
56
 
39
57
  // src/autocomplete-icon.tsx
40
- var import_core2 = require("@yamada-ui/core");
58
+ var import_core = require("@yamada-ui/core");
41
59
  var import_icon = require("@yamada-ui/icon");
42
60
  var import_use_clickable = require("@yamada-ui/use-clickable");
43
61
  var import_utils2 = require("@yamada-ui/utils");
44
- var import_react2 = require("react");
45
-
46
- // src/use-autocomplete.tsx
47
- var import_core = require("@yamada-ui/core");
48
- var import_form_control = require("@yamada-ui/form-control");
49
- var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
50
- var import_use_descendant = require("@yamada-ui/use-descendant");
51
- var import_use_disclosure = require("@yamada-ui/use-disclosure");
52
- var import_use_outside_click = require("@yamada-ui/use-outside-click");
53
- var import_utils = require("@yamada-ui/utils");
54
62
  var import_react = require("react");
55
63
  var import_jsx_runtime = require("react/jsx-runtime");
56
- var kanaMap = {
57
- \uFF76\uFF9E: "\u30AC",
58
- \uFF77\uFF9E: "\u30AE",
59
- \uFF78\uFF9E: "\u30B0",
60
- \uFF79\uFF9E: "\u30B2",
61
- \uFF7A\uFF9E: "\u30B4",
62
- \uFF7B\uFF9E: "\u30B6",
63
- \uFF7C\uFF9E: "\u30B8",
64
- \uFF7D\uFF9E: "\u30BA",
65
- \uFF7E\uFF9E: "\u30BC",
66
- \uFF7F\uFF9E: "\u30BE",
67
- \uFF80\uFF9E: "\u30C0",
68
- \uFF81\uFF9E: "\u30C2",
69
- \uFF82\uFF9E: "\u30C5",
70
- \uFF83\uFF9E: "\u30C7",
71
- \uFF84\uFF9E: "\u30C9",
72
- \uFF8A\uFF9E: "\u30D0",
73
- \uFF8B\uFF9E: "\u30D3",
74
- \uFF8C\uFF9E: "\u30D6",
75
- \uFF8D\uFF9E: "\u30D9",
76
- \uFF8E\uFF9E: "\u30DC",
77
- \uFF8A\uFF9F: "\u30D1",
78
- \uFF8B\uFF9F: "\u30D4",
79
- \uFF8C\uFF9F: "\u30D7",
80
- \uFF8D\uFF9F: "\u30DA",
81
- \uFF8E\uFF9F: "\u30DD",
82
- \uFF73\uFF9E: "\u30F4",
83
- \uFF9C\uFF9E: "\u30F7",
84
- \uFF66\uFF9E: "\u30FA",
85
- \uFF71: "\u30A2",
86
- \uFF72: "\u30A4",
87
- \uFF73: "\u30A6",
88
- \uFF74: "\u30A8",
89
- \uFF75: "\u30AA",
90
- \uFF76: "\u30AB",
91
- \uFF77: "\u30AD",
92
- \uFF78: "\u30AF",
93
- \uFF79: "\u30B1",
94
- \uFF7A: "\u30B3",
95
- \uFF7B: "\u30B5",
96
- \uFF7C: "\u30B7",
97
- \uFF7D: "\u30B9",
98
- \uFF7E: "\u30BB",
99
- \uFF7F: "\u30BD",
100
- \uFF80: "\u30BF",
101
- \uFF81: "\u30C1",
102
- \uFF82: "\u30C4",
103
- \uFF83: "\u30C6",
104
- \uFF84: "\u30C8",
105
- \uFF85: "\u30CA",
106
- \uFF86: "\u30CB",
107
- \uFF87: "\u30CC",
108
- \uFF88: "\u30CD",
109
- \uFF89: "\u30CE",
110
- \uFF8A: "\u30CF",
111
- \uFF8B: "\u30D2",
112
- \uFF8C: "\u30D5",
113
- \uFF8D: "\u30D8",
114
- \uFF8E: "\u30DB",
115
- \uFF8F: "\u30DE",
116
- \uFF90: "\u30DF",
117
- \uFF91: "\u30E0",
118
- \uFF92: "\u30E1",
119
- \uFF93: "\u30E2",
120
- \uFF94: "\u30E4",
121
- \uFF95: "\u30E6",
122
- \uFF96: "\u30E8",
123
- \uFF97: "\u30E9",
124
- \uFF98: "\u30EA",
125
- \uFF99: "\u30EB",
126
- \uFF9A: "\u30EC",
127
- \uFF9B: "\u30ED",
128
- \uFF9C: "\u30EF",
129
- \uFF66: "\u30F2",
130
- \uFF9D: "\u30F3",
131
- \uFF67: "\u30A1",
132
- \uFF68: "\u30A3",
133
- \uFF69: "\u30A5",
134
- \uFF6A: "\u30A7",
135
- \uFF6B: "\u30A9",
136
- \uFF6F: "\u30C3",
137
- \uFF6C: "\u30E3",
138
- \uFF6D: "\u30E5",
139
- \uFF6E: "\u30E7",
140
- "\uFF61": "\u3002",
141
- "\uFF64": "\u3001",
142
- \uFF70: "\u30FC",
143
- "\uFF62": "\u300C",
144
- "\uFF63": "\u300D",
145
- "\uFF65": "\u30FB"
146
- };
147
- var defaultFormat = (value) => {
148
- value = value.replace(
149
- /[!-~]/g,
150
- (v) => String.fromCharCode(v.charCodeAt(0) - 65248)
64
+ var AutocompleteIcon = (0, import_core.forwardRef)(
65
+ ({ className, children, __css, ...rest }, ref) => {
66
+ const { styles } = useAutocompleteContext();
67
+ const css = {
68
+ position: "absolute",
69
+ top: "50%",
70
+ transform: "translateY(-50%)",
71
+ display: "inline-flex",
72
+ alignItems: "center",
73
+ justifyContent: "center",
74
+ pointerEvents: "none",
75
+ cursor: "pointer",
76
+ ...styles.icon,
77
+ ...__css
78
+ };
79
+ const validChildren = (0, import_utils2.getValidChildren)(children);
80
+ const cloneChildren = validChildren.map(
81
+ (child) => (0, import_react.cloneElement)(child, {
82
+ focusable: false,
83
+ "aria-hidden": true,
84
+ style: {
85
+ maxWidth: "1em",
86
+ maxHeight: "1em",
87
+ color: "currentColor"
88
+ }
89
+ })
90
+ );
91
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
92
+ import_core.ui.div,
93
+ {
94
+ ref,
95
+ className: (0, import_utils2.cx)("ui-autocomplete__icon", className),
96
+ __css: css,
97
+ ...rest,
98
+ children: (0, import_utils2.isValidElement)(children) ? cloneChildren : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.ChevronIcon, {})
99
+ }
100
+ );
101
+ }
102
+ );
103
+ var AutocompleteClearIcon = ({
104
+ className,
105
+ children,
106
+ ...props
107
+ }) => {
108
+ const ref = (0, import_react.useRef)(null);
109
+ const { styles } = useAutocompleteContext();
110
+ const isDisabled = props.disabled;
111
+ const rest = (0, import_use_clickable.useClickable)({
112
+ ref,
113
+ isDisabled,
114
+ ...props
115
+ });
116
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
117
+ AutocompleteIcon,
118
+ {
119
+ "aria-label": "Clear value",
120
+ className: (0, import_utils2.cx)("ui-autocomplete__icon--clear", className),
121
+ __css: styles.clearIcon,
122
+ ...rest,
123
+ children: children != null ? children : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.CloseIcon, { w: "0.5em", h: "0.5em" })
124
+ }
151
125
  );
152
- const reg = new RegExp("(" + Object.keys(kanaMap).join("|") + ")", "g");
153
- value = value.replace(reg, (v) => kanaMap[v]).replace(/゙/g, "\u309B").replace(/゚/g, "\u309C");
154
- value = value.toUpperCase();
155
- return value;
156
126
  };
157
- var flattenItems = (items) => {
158
- const filterItems = (items2) => items2.map((item) => {
159
- var _a;
160
- const { isDisabled, isFocusable } = item;
161
- const trulyDisabled = !!isDisabled && !isFocusable;
162
- if (trulyDisabled) return;
163
- if ("items" in item) {
164
- return filterItems((_a = item.items) != null ? _a : []);
165
- } else {
166
- return item;
127
+ var AutocompleteItemIcon = (0, import_core.forwardRef)(({ className, ...rest }, ref) => {
128
+ const { styles } = useAutocompleteContext();
129
+ const css = {
130
+ flexShrink: 0,
131
+ display: "inline-flex",
132
+ justifyContent: "center",
133
+ alignItems: "center",
134
+ fontSize: "0.85em",
135
+ ...styles.itemIcon
136
+ };
137
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
138
+ import_core.ui.span,
139
+ {
140
+ ref,
141
+ className: (0, import_utils2.cx)("ui-autocomplete__item__icon", className),
142
+ __css: css,
143
+ ...rest
167
144
  }
168
- }).filter(Boolean);
169
- return filterItems(items).flat(Infinity);
170
- };
145
+ );
146
+ });
147
+
148
+ // src/use-autocomplete-option.ts
149
+ var import_utils3 = require("@yamada-ui/utils");
150
+ var import_react2 = require("react");
171
151
  var isTargetOption = (target) => {
172
152
  var _a;
173
- return (0, import_utils.isHTMLElement)(target) && !!((_a = target == null ? void 0 : target.getAttribute("role")) == null ? void 0 : _a.startsWith("option"));
153
+ return (0, import_utils3.isHTMLElement)(target) && !!((_a = target == null ? void 0 : target.getAttribute("role")) == null ? void 0 : _a.startsWith("option"));
174
154
  };
175
- var {
176
- DescendantsContextProvider: AutocompleteDescendantsContextProvider,
177
- useDescendantsContext: useAutocompleteDescendantsContext,
178
- useDescendants: useAutocompleteDescendants,
179
- useDescendant: useAutocompleteDescendant
180
- } = (0, import_use_descendant.createDescendant)();
181
- var [AutocompleteProvider, useAutocompleteContext] = (0, import_utils.createContext)({
182
- name: "AutocompleteContext",
183
- errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in "<Autocomplete />" or "<MultiAutocomplete />"`
184
- });
185
- var useAutocomplete = (props) => {
155
+ var useAutocompleteOption = (props) => {
156
+ var _a, _b;
186
157
  const {
187
- value: valueProp,
188
- defaultValue,
189
- onChange: onChangeProp,
190
- onCreate: onCreateProp,
191
- onSearch: onSearchProp,
192
- closeOnSelect = true,
193
- omitSelectedValues = false,
194
- maxSelectValues,
195
- allowCreate = false,
196
- allowFree = false,
197
- insertPositionItem = "first",
198
- emptyMessage = "No results found",
199
- format = defaultFormat,
158
+ value,
159
+ omitSelectedValues,
160
+ onChange,
161
+ onChangeLabel,
162
+ focusedIndex,
163
+ setFocusedIndex,
164
+ onClose,
165
+ closeOnSelect: generalCloseOnSelect,
200
166
  optionProps,
201
- placeholder,
202
- onKeyDown: onKeyDownProp,
203
- isOpen: isOpenProp,
204
- defaultIsOpen,
205
- onOpen: onOpenProp,
206
- onClose: onCloseProp,
207
- closeOnBlur = true,
208
- closeOnEsc = true,
209
- openDelay,
210
- closeDelay,
211
- isLazy,
212
- lazyBehavior,
213
- animation,
214
- duration = 0.2,
215
- offset,
216
- gutter,
217
- preventOverflow,
218
- flip,
219
- matchWidth = true,
220
- boundary,
221
- eventListeners,
222
- strategy,
223
- placement = "bottom-start",
224
- modifiers,
225
- items,
167
+ inputRef,
168
+ onFocusNext
169
+ } = useAutocompleteContext();
170
+ let {
171
+ icon: customIcon,
172
+ isDisabled,
173
+ isFocusable,
174
+ closeOnSelect: customCloseOnSelect,
226
175
  children,
227
- ...rest
228
- } = (0, import_form_control.useFormControlProps)(props);
229
- const {
230
- "aria-readonly": _ariaReadonly,
231
- onFocus: onFocusProp,
232
- ...formControlProps
233
- } = (0, import_utils.pickObject)(rest, import_form_control.formControlProperties);
234
- const [containerProps, inputProps] = (0, import_utils.splitObject)(rest, import_core.layoutStyleProperties);
235
- const { id } = rest;
236
- const descendants = useAutocompleteDescendants();
237
- const containerRef = (0, import_react.useRef)(null);
238
- const listRef = (0, import_react.useRef)(null);
239
- const inputRef = (0, import_react.useRef)(null);
240
- const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
241
- const isComposition = (0, import_react.useRef)(false);
242
- const prevValue = (0, import_react.useRef)(void 0);
243
- const [resolvedItems, setResolvedItems] = (0, import_react.useState)(items ? JSON.parse(JSON.stringify(items)) : void 0);
244
- const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
245
- value: valueProp,
246
- defaultValue,
247
- onChange: onChangeProp
248
- });
249
- const [label, setLabel] = (0, import_react.useState)(void 0);
250
- const [inputValue, setInputValue] = (0, import_react.useState)("");
251
- const [focusedIndex, setFocusedIndex] = (0, import_react.useState)(-1);
252
- const [isAllSelected, setIsAllSelected] = (0, import_react.useState)(false);
253
- const [isHit, setIsHit] = (0, import_react.useState)(true);
254
- const {
255
- isOpen,
256
- onOpen: onInternalOpen,
257
- onClose
258
- } = (0, import_use_disclosure.useDisclosure)({
259
- isOpen: isOpenProp,
260
- defaultIsOpen,
261
- onOpen: onOpenProp,
262
- onClose: onCloseProp
176
+ value: optionValue,
177
+ ...computedProps
178
+ } = { ...optionProps, ...props };
179
+ const trulyDisabled = !!isDisabled && !isFocusable;
180
+ const itemRef = (0, import_react2.useRef)(null);
181
+ const { index, register, descendants } = useAutocompleteDescendant({
182
+ disabled: trulyDisabled
263
183
  });
264
- const isFocused = focusedIndex > -1;
265
- const isCreate = focusedIndex === -2 && allowCreate;
266
- const isMulti = (0, import_utils.isArray)(value);
267
- const isEmptyValue = !isMulti ? !value : !value.length;
268
- const [firstInsertPositionItem, secondInsertPositionItem] = (0, import_react.useMemo)(() => {
269
- if ((0, import_utils.isArray)(insertPositionItem)) {
270
- return insertPositionItem;
271
- } else {
272
- return [insertPositionItem, "first"];
273
- }
274
- }, [insertPositionItem]);
275
- if (allowCreate && !(0, import_utils.isUndefined)(children)) {
276
- console.warn(
277
- `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'allowCreate' is true, it will not be reflected correctly. If want to reflect, please set 'items' in props.`
278
- );
279
- }
280
- const selectedValues = descendants.enabledValues(
281
- ({ node }) => {
282
- var _a;
283
- return isMulti && value.includes((_a = node.dataset.value) != null ? _a : "");
284
- }
285
- );
286
- const selectedIndexes = selectedValues.map(({ index }) => index);
287
- const enabledValues = descendants.enabledValues(
288
- ({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
289
- );
290
- const validChildren = (0, import_utils.getValidChildren)(children);
291
- const computedChildren = (0, import_react.useMemo)(
292
- () => resolvedItems == null ? void 0 : resolvedItems.map((item, i) => {
293
- if ("value" in item) {
294
- const { label: label2, value: value2, ...props2 } = item;
295
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AutocompleteOption, { value: value2, ...props2, children: label2 }, i);
296
- } else if ("items" in item) {
297
- const { label: label2, items: items2 = [], ...props2 } = item;
298
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
299
- AutocompleteOptionGroup,
300
- {
301
- label: label2,
302
- ...props2,
303
- children: items2.map(({ label: label3, value: value2, ...props3 }, i2) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(AutocompleteOption, { value: value2, ...props3, children: label3 }, i2))
304
- },
305
- i
306
- );
307
- }
308
- }),
309
- [resolvedItems]
310
- );
311
- const isEmpty = !validChildren.length && !(computedChildren == null ? void 0 : computedChildren.length);
312
- const onOpen = (0, import_react.useCallback)(() => {
313
- if (formControlProps.disabled || formControlProps.readOnly) return;
314
- if (!allowCreate && (isEmpty || isAllSelected)) return;
315
- onInternalOpen();
316
- if (inputRef.current) inputRef.current.focus();
317
- }, [allowCreate, formControlProps, isAllSelected, isEmpty, onInternalOpen]);
318
- const onFocusFirst = (0, import_react.useCallback)(() => {
319
- const id2 = setTimeout(() => {
320
- if (isEmpty || isAllSelected) return;
321
- const first = descendants.enabledFirstValue(
322
- ({ node }) => "target" in node.dataset
323
- );
324
- if (!first) return;
325
- if (!isMulti || !omitSelectedValues) {
326
- setFocusedIndex(first.index);
327
- } else {
328
- if (selectedIndexes.includes(first.index)) {
329
- const enabledFirst = enabledValues[0];
330
- setFocusedIndex(enabledFirst.index);
331
- } else {
332
- setFocusedIndex(first.index);
333
- }
184
+ const values = descendants.values();
185
+ const frontValues = values.slice(0, index);
186
+ const isMulti = (0, import_utils3.isArray)(value);
187
+ const isDuplicated = !isMulti ? frontValues.some(({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")) : false;
188
+ const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
189
+ const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
190
+ const isFocused = index === focusedIndex;
191
+ const onClick = (0, import_react2.useCallback)(
192
+ (ev) => {
193
+ ev.stopPropagation();
194
+ if (isDisabled) {
195
+ if (inputRef.current) inputRef.current.focus();
196
+ return;
334
197
  }
335
- });
336
- timeoutIds.current.add(id2);
337
- }, [
338
- descendants,
339
- enabledValues,
340
- isAllSelected,
341
- isEmpty,
342
- isMulti,
343
- omitSelectedValues,
344
- selectedIndexes
345
- ]);
346
- const onFocusLast = (0, import_react.useCallback)(() => {
347
- const id2 = setTimeout(() => {
348
- if (isEmpty || isAllSelected) return;
349
- const last = descendants.enabledLastValue(
350
- ({ node }) => "target" in node.dataset
351
- );
352
- if (!last) return;
353
- if (!isMulti || !omitSelectedValues) {
354
- setFocusedIndex(last.index);
355
- } else {
356
- if (selectedIndexes.includes(last.index)) {
357
- const enabledLast = enabledValues.reverse()[0];
358
- setFocusedIndex(enabledLast.index);
359
- } else {
360
- setFocusedIndex(last.index);
361
- }
198
+ if (!isTargetOption(ev.currentTarget)) {
199
+ if (inputRef.current) inputRef.current.focus();
200
+ return;
362
201
  }
363
- });
364
- timeoutIds.current.add(id2);
365
- }, [
366
- descendants,
367
- enabledValues,
368
- isAllSelected,
369
- isEmpty,
370
- isMulti,
371
- omitSelectedValues,
372
- selectedIndexes
373
- ]);
374
- const onFocusSelected = (0, import_react.useCallback)(() => {
375
- const id2 = setTimeout(() => {
376
- const values = descendants.enabledValues();
377
- const selected = values.find(
378
- ({ node }) => {
379
- var _a;
380
- return !isMulti ? node.dataset.value === value : value.includes((_a = node.dataset.value) != null ? _a : "");
381
- }
382
- );
383
- if (selected) setFocusedIndex(selected.index);
384
- });
385
- timeoutIds.current.add(id2);
386
- }, [descendants, isMulti, value]);
387
- const onFocusNext = (0, import_react.useCallback)(
388
- (index = focusedIndex) => {
389
- const id2 = setTimeout(() => {
390
- var _a;
391
- const next = descendants.enabledNextValue(
392
- index,
393
- ({ node }) => "target" in node.dataset
394
- );
395
- if (!next) return;
396
- if (!isMulti || !omitSelectedValues) {
397
- setFocusedIndex(next.index);
398
- } else {
399
- if (selectedIndexes.includes(next.index)) {
400
- const enabledNext = (_a = enabledValues.find(({ index: index2 }) => next.index < index2)) != null ? _a : enabledValues[0];
401
- setFocusedIndex(enabledNext.index);
402
- } else {
403
- setFocusedIndex(next.index);
404
- }
405
- }
406
- });
407
- timeoutIds.current.add(id2);
202
+ setFocusedIndex(index);
203
+ onChange(optionValue != null ? optionValue : "");
204
+ if (inputRef.current) inputRef.current.focus();
205
+ if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect) onClose();
206
+ if (omitSelectedValues) onFocusNext(index);
408
207
  },
409
208
  [
410
- descendants,
411
- enabledValues,
412
- focusedIndex,
413
- isMulti,
209
+ onFocusNext,
414
210
  omitSelectedValues,
415
- selectedIndexes
211
+ isDisabled,
212
+ optionValue,
213
+ setFocusedIndex,
214
+ index,
215
+ onChange,
216
+ customCloseOnSelect,
217
+ generalCloseOnSelect,
218
+ onClose,
219
+ inputRef
416
220
  ]
417
221
  );
418
- const onFocusPrev = (0, import_react.useCallback)(
419
- (index = focusedIndex) => {
420
- const id2 = setTimeout(() => {
421
- var _a;
422
- const prev = descendants.enabledPrevValue(
423
- index,
424
- ({ node }) => "target" in node.dataset
425
- );
426
- if (!prev) return;
427
- if (!isMulti || !omitSelectedValues) {
428
- setFocusedIndex(prev.index);
429
- } else {
430
- if (selectedIndexes.includes(prev.index)) {
431
- const enabledPrev = (_a = enabledValues.reverse().find(({ index: index2 }) => index2 < prev.index)) != null ? _a : enabledValues[0];
432
- setFocusedIndex(enabledPrev.index);
433
- } else {
434
- setFocusedIndex(prev.index);
435
- }
436
- }
437
- });
438
- timeoutIds.current.add(id2);
222
+ (0, import_utils3.useUpdateEffect)(() => {
223
+ if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", { runOmit: false });
224
+ }, [optionValue]);
225
+ const getOptionProps = (0, import_react2.useCallback)(
226
+ (props2 = {}, ref = null) => {
227
+ const style = {
228
+ border: "0px",
229
+ clip: "rect(0px, 0px, 0px, 0px)",
230
+ height: "1px",
231
+ width: "1px",
232
+ margin: "-1px",
233
+ padding: "0px",
234
+ overflow: "hidden",
235
+ whiteSpace: "nowrap",
236
+ position: "absolute"
237
+ };
238
+ return {
239
+ ref: (0, import_utils3.mergeRefs)(itemRef, ref, register),
240
+ id: (0, import_react2.useId)(),
241
+ role: "option",
242
+ ...computedProps,
243
+ ...props2,
244
+ tabIndex: -1,
245
+ style: !isTarget || omitSelectedValues && isSelected ? style : void 0,
246
+ "data-target": (0, import_utils3.dataAttr)(true),
247
+ "data-value": optionValue != null ? optionValue : "",
248
+ "data-focus": (0, import_utils3.dataAttr)(isFocused),
249
+ "data-disabled": (0, import_utils3.dataAttr)(isDisabled),
250
+ "aria-checked": isSelected,
251
+ "aria-disabled": (0, import_utils3.ariaAttr)(isDisabled),
252
+ onClick: (0, import_utils3.handlerAll)(computedProps.onClick, props2.onClick, onClick)
253
+ };
439
254
  },
440
255
  [
441
- descendants,
442
- enabledValues,
443
- focusedIndex,
444
- isMulti,
256
+ optionValue,
257
+ computedProps,
258
+ isDisabled,
259
+ isFocused,
260
+ isSelected,
261
+ isTarget,
445
262
  omitSelectedValues,
446
- selectedIndexes
263
+ onClick,
264
+ register
447
265
  ]
448
266
  );
449
- const onFocusFirstOrSelected = isEmptyValue || omitSelectedValues ? onFocusFirst : onFocusSelected;
450
- const onFocusLastOrSelected = isEmptyValue || omitSelectedValues ? onFocusLast : onFocusSelected;
451
- const pickOptions = (0, import_react.useCallback)(
452
- (value2) => {
453
- const values = descendants.values();
454
- let isHit2 = false;
455
- let isFocused2 = false;
456
- values.forEach(({ node, index }) => {
457
- var _a;
458
- if (format((_a = node.textContent) != null ? _a : "").includes(value2)) {
459
- isHit2 = true;
460
- const isDisabled = "disabled" in node.dataset;
461
- node.dataset.target = "";
462
- if (!isFocused2 && !isDisabled) {
463
- isFocused2 = true;
464
- setFocusedIndex(index);
465
- }
466
- } else {
467
- delete node.dataset.target;
468
- }
469
- });
470
- setIsHit(isHit2);
471
- },
472
- [descendants, format]
473
- );
474
- const rebirthOptions = (0, import_react.useCallback)(
475
- (runFocus = true) => {
476
- const values = descendants.values();
477
- values.forEach(({ node }) => {
478
- node.dataset.target = "";
479
- });
480
- if (runFocus) onFocusFirst();
481
- setIsHit(true);
267
+ return {
268
+ isSelected,
269
+ isFocused,
270
+ customIcon,
271
+ children,
272
+ getOptionProps
273
+ };
274
+ };
275
+ var useAutocompleteCreate = () => {
276
+ const { isHit, onCreate } = useAutocompleteContext();
277
+ const getCreateProps = (0, import_react2.useCallback)(
278
+ (props = {}, ref = null) => {
279
+ const style = {
280
+ border: "0px",
281
+ clip: "rect(0px, 0px, 0px, 0px)",
282
+ height: "1px",
283
+ width: "1px",
284
+ margin: "-1px",
285
+ padding: "0px",
286
+ overflow: "hidden",
287
+ whiteSpace: "nowrap",
288
+ position: "absolute"
289
+ };
290
+ return {
291
+ ref,
292
+ ...props,
293
+ tabIndex: -1,
294
+ style: isHit ? style : void 0,
295
+ "data-focus": (0, import_utils3.dataAttr)(!isHit),
296
+ onClick: (0, import_utils3.handlerAll)(props.onClick, onCreate)
297
+ };
482
298
  },
483
- [descendants, onFocusFirst]
299
+ [isHit, onCreate]
484
300
  );
485
- const getSelectedValues = (0, import_react.useCallback)(
486
- (newValues) => {
487
- const enabledValues2 = descendants.enabledValues();
488
- const resolvedValues = (0, import_utils.isArray)(newValues) ? newValues : [newValues];
489
- const selectedValues2 = resolvedValues.map((value2) => {
490
- var _a, _b;
491
- const { node } = (_a = enabledValues2.find(({ node: node2 }) => node2.dataset.value === value2)) != null ? _a : {};
492
- if (node) {
493
- const el = Array.from(node.children).find(
494
- (child) => child.getAttribute("data-label") !== null
495
- );
496
- return (_b = el == null ? void 0 : el.textContent) != null ? _b : void 0;
497
- } else {
498
- return allowFree ? value2 : void 0;
499
- }
500
- }).filter(Boolean);
501
- return selectedValues2;
301
+ return { getCreateProps };
302
+ };
303
+ var useAutocompleteEmpty = () => {
304
+ const { isHit, isEmpty } = useAutocompleteContext();
305
+ const getEmptyProps = (0, import_react2.useCallback)(
306
+ (props = {}, ref = null) => {
307
+ const style = {
308
+ border: "0px",
309
+ clip: "rect(0px, 0px, 0px, 0px)",
310
+ height: "1px",
311
+ width: "1px",
312
+ margin: "-1px",
313
+ padding: "0px",
314
+ overflow: "hidden",
315
+ whiteSpace: "nowrap",
316
+ position: "absolute"
317
+ };
318
+ return {
319
+ ref,
320
+ ...props,
321
+ tabIndex: -1,
322
+ style: isHit && !isEmpty ? style : void 0
323
+ };
502
324
  },
503
- [allowFree, descendants]
325
+ [isHit, isEmpty]
504
326
  );
505
- const onChangeLabel = (0, import_react.useCallback)(
506
- (newValue, { forceUpdate, runOmit = true } = {}) => {
507
- const selectedValues2 = getSelectedValues(newValue);
508
- if (!forceUpdate && !selectedValues2.length) return;
509
- setLabel((prev) => {
510
- if (!isMulti) {
511
- return selectedValues2[0];
327
+ return { getEmptyProps };
328
+ };
329
+
330
+ // src/autocomplete-create.tsx
331
+ var import_jsx_runtime2 = require("react/jsx-runtime");
332
+ var AutocompleteCreate = (0, import_core2.forwardRef)(
333
+ ({ className, icon, children, ...rest }, ref) => {
334
+ const { inputValue, styles } = useAutocompleteContext();
335
+ const { getCreateProps } = useAutocompleteCreate();
336
+ children != null ? children : children = inputValue;
337
+ const css = {
338
+ textDecoration: "none",
339
+ color: "inherit",
340
+ userSelect: "none",
341
+ display: "flex",
342
+ width: "100%",
343
+ alignItems: "center",
344
+ textAlign: "start",
345
+ flex: "0 0 auto",
346
+ outline: 0,
347
+ gap: "0.75rem",
348
+ ...styles.item
349
+ };
350
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
351
+ import_core2.ui.li,
352
+ {
353
+ className: (0, import_utils4.cx)("ui-autocomplete__item--create", className),
354
+ __css: css,
355
+ ...getCreateProps(rest, ref),
356
+ children: [
357
+ icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AutocompleteItemIcon, { children: icon || /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PlusIcon, {}) }) : null,
358
+ icon ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.span, { style: { pointerEvents: "none", flex: 1 }, lineClamp: 1, children: (0, import_utils4.runIfFunc)(children, inputValue) }) : (0, import_utils4.runIfFunc)(children, inputValue)
359
+ ]
360
+ }
361
+ );
362
+ }
363
+ );
364
+ var PlusIcon = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { viewBox: "0 0 45.402 45.402", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
365
+ "path",
366
+ {
367
+ fill: "currentColor",
368
+ d: "M41.267,18.557H26.832V4.134C26.832,1.851,24.99,0,22.707,0c-2.283,0-4.124,1.851-4.124,4.135v14.432H4.141 c-2.283,0-4.139,1.851-4.138,4.135c-0.001,1.141,0.46,2.187,1.207,2.934c0.748,0.749,1.78,1.222,2.92,1.222h14.453V41.27 c0,1.142,0.453,2.176,1.201,2.922c0.748,0.748,1.777,1.211,2.919,1.211c2.282,0,4.129-1.851,4.129-4.133V26.857h14.435 c2.283,0,4.134-1.867,4.133-4.15C45.399,20.425,43.548,18.557,41.267,18.557z"
369
+ }
370
+ ) });
371
+
372
+ // src/autocomplete-empty.tsx
373
+ var import_core3 = require("@yamada-ui/core");
374
+ var import_utils5 = require("@yamada-ui/utils");
375
+ var import_jsx_runtime3 = require("react/jsx-runtime");
376
+ var AutocompleteEmpty = (0, import_core3.forwardRef)(
377
+ ({ className, icon, children, ...rest }, ref) => {
378
+ const { emptyMessage, styles } = useAutocompleteContext();
379
+ const { getEmptyProps } = useAutocompleteEmpty();
380
+ children != null ? children : children = emptyMessage;
381
+ const css = {
382
+ textDecoration: "none",
383
+ color: "inherit",
384
+ userSelect: "none",
385
+ display: "flex",
386
+ width: "100%",
387
+ alignItems: "center",
388
+ textAlign: "start",
389
+ flex: "0 0 auto",
390
+ outline: 0,
391
+ gap: "0.75rem",
392
+ pointerEvents: "none",
393
+ ...styles.item
394
+ };
395
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
396
+ import_core3.ui.li,
397
+ {
398
+ className: (0, import_utils5.cx)("ui-autocomplete__item--empty", className),
399
+ __css: css,
400
+ ...getEmptyProps(rest, ref),
401
+ children: [
402
+ icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AutocompleteItemIcon, { children: icon || /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MinusIcon, {}) }) : null,
403
+ icon ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core3.ui.span, { style: { pointerEvents: "none", flex: 1 }, lineClamp: 1, children }) : children
404
+ ]
405
+ }
406
+ );
407
+ }
408
+ );
409
+ var MinusIcon = () => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { viewBox: "0 0 448 512", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
410
+ "path",
411
+ {
412
+ fill: "currentColor",
413
+ d: "M432 256c0 17.7-14.3 32-32 32L48 288c-17.7 0-32-14.3-32-32s14.3-32 32-32l352 0c17.7 0 32 14.3 32 32z"
414
+ }
415
+ ) });
416
+
417
+ // src/autocomplete-list.tsx
418
+ var import_core4 = require("@yamada-ui/core");
419
+ var import_popover = require("@yamada-ui/popover");
420
+ var import_utils7 = require("@yamada-ui/utils");
421
+
422
+ // src/use-autocomplete-list.ts
423
+ var import_utils6 = require("@yamada-ui/utils");
424
+ var import_react3 = require("react");
425
+ var useAutocompleteList = () => {
426
+ const { focusedIndex, isOpen, listRef, rebirthOptions } = useAutocompleteContext();
427
+ const descendants = useAutocompleteDescendantsContext();
428
+ const beforeFocusedIndex = (0, import_react3.useRef)(-1);
429
+ const selectedValue = descendants.value(focusedIndex);
430
+ const onAnimationComplete = (0, import_react3.useCallback)(() => {
431
+ if (!isOpen) rebirthOptions(false);
432
+ }, [isOpen, rebirthOptions]);
433
+ (0, import_react3.useEffect)(() => {
434
+ if (!listRef.current || !selectedValue) return;
435
+ if (beforeFocusedIndex.current === selectedValue.index) return;
436
+ const parent = listRef.current;
437
+ const child = selectedValue.node;
438
+ const parentHeight = parent.clientHeight;
439
+ const viewTop = parent.scrollTop;
440
+ const viewBottom = viewTop + parentHeight;
441
+ const childHeight = child.clientHeight;
442
+ const childTop = child.offsetTop;
443
+ const childBottom = childTop + childHeight;
444
+ const isInView = viewTop <= childTop && childBottom <= viewBottom;
445
+ const isScrollBottom = beforeFocusedIndex.current < selectedValue.index;
446
+ if (!isInView) {
447
+ if (childBottom <= parentHeight) {
448
+ listRef.current.scrollTo({ top: 0 });
449
+ } else {
450
+ if (!isScrollBottom) {
451
+ listRef.current.scrollTo({ top: childTop + 1 });
512
452
  } else {
513
- selectedValues2.forEach((selectedValue) => {
514
- const isSelected = (0, import_utils.isArray)(prev) && prev.includes(selectedValue != null ? selectedValue : "");
515
- if (!isSelected) {
516
- prev = [...(0, import_utils.isArray)(prev) ? prev : [], selectedValue];
517
- } else if (runOmit) {
518
- prev = (0, import_utils.isArray)(prev) ? prev.filter((value2) => value2 !== selectedValue) : void 0;
519
- }
520
- });
521
- return prev;
453
+ listRef.current.scrollTo({ top: childBottom - parentHeight });
522
454
  }
523
- });
524
- },
525
- [getSelectedValues, isMulti]
455
+ }
456
+ }
457
+ beforeFocusedIndex.current = selectedValue.index;
458
+ }, [listRef, selectedValue]);
459
+ (0, import_utils6.useUpdateEffect)(() => {
460
+ if (!isOpen) beforeFocusedIndex.current = -1;
461
+ }, [isOpen]);
462
+ const getListProps = (0, import_react3.useCallback)(
463
+ (props = {}, ref = null) => ({
464
+ as: "ul",
465
+ ref: (0, import_utils6.mergeRefs)(listRef, ref),
466
+ role: "listbox",
467
+ tabIndex: -1,
468
+ position: "relative",
469
+ id: props.id || (0, import_react3.useId)(),
470
+ ...props
471
+ }),
472
+ [listRef]
526
473
  );
527
- const onChange = (0, import_react.useCallback)(
528
- (newValue, { forceUpdate, runRebirth = true } = {}) => {
529
- setValue((prev) => {
530
- let next;
531
- if (!(0, import_utils.isArray)(prev)) {
532
- next = newValue;
533
- } else {
534
- const isSelected = prev.includes(newValue);
535
- if (!isSelected) {
536
- next = [...prev, newValue];
537
- } else {
538
- next = prev.filter((value2) => value2 !== newValue);
539
- }
540
- }
541
- prevValue.current = next;
542
- return next;
543
- });
544
- const isHit2 = descendants.values().filter(
545
- ({ node }) => {
546
- var _a;
547
- return format((_a = node.textContent) != null ? _a : "").includes(newValue);
548
- }
549
- ).length > 0;
550
- onChangeLabel(newValue, { forceUpdate });
551
- if (allowFree || isHit2) setInputValue("");
552
- if (isMulti && runRebirth) rebirthOptions(false);
474
+ return {
475
+ onAnimationComplete,
476
+ getListProps
477
+ };
478
+ };
479
+
480
+ // src/autocomplete-list.tsx
481
+ var import_jsx_runtime4 = require("react/jsx-runtime");
482
+ var AutocompleteList = (0, import_core4.forwardRef)(
483
+ ({
484
+ className,
485
+ w,
486
+ width,
487
+ minW,
488
+ minWidth,
489
+ maxW,
490
+ maxWidth,
491
+ contentProps,
492
+ header,
493
+ footer,
494
+ children,
495
+ ...rest
496
+ }, ref) => {
497
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
498
+ const { styles } = useAutocompleteContext();
499
+ const { onAnimationComplete, getListProps } = useAutocompleteList();
500
+ width != null ? width : width = w;
501
+ width != null ? width : width = (_c = (_a = styles.list) == null ? void 0 : _a.width) != null ? _c : (_b = styles.list) == null ? void 0 : _b.w;
502
+ minWidth != null ? minWidth : minWidth = minW;
503
+ minWidth != null ? minWidth : minWidth = (_f = (_d = styles.list) == null ? void 0 : _d.minWidth) != null ? _f : (_e = styles.list) == null ? void 0 : _e.minW;
504
+ maxWidth != null ? maxWidth : maxWidth = maxW;
505
+ maxWidth != null ? maxWidth : maxWidth = (_i = (_g = styles.list) == null ? void 0 : _g.maxWidth) != null ? _i : (_h = styles.list) == null ? void 0 : _h.maxW;
506
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
507
+ import_popover.PopoverContent,
508
+ {
509
+ as: "div",
510
+ className: "ui-autocomplete__popover",
511
+ width,
512
+ minWidth,
513
+ maxWidth,
514
+ __css: { ...styles.content, width, minWidth, maxWidth },
515
+ ...contentProps,
516
+ onAnimationComplete: (0, import_utils7.handlerAll)(
517
+ contentProps == null ? void 0 : contentProps.onAnimationComplete,
518
+ onAnimationComplete
519
+ ),
520
+ children: [
521
+ header ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
522
+ import_core4.ui.div,
523
+ {
524
+ className: "ui-autocomplete__header",
525
+ __css: { ...styles.header },
526
+ children: header
527
+ }
528
+ ) : null,
529
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
530
+ import_core4.ui.ul,
531
+ {
532
+ className: (0, import_utils7.cx)("ui-autocomplete__list", className),
533
+ __css: { ...styles.list },
534
+ ...getListProps(rest, ref),
535
+ children
536
+ }
537
+ ),
538
+ footer ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
539
+ import_core4.ui.div,
540
+ {
541
+ className: "ui-autocomplete__footer",
542
+ __css: { ...styles.footer },
543
+ children: footer
544
+ }
545
+ ) : null
546
+ ]
547
+ }
548
+ );
549
+ }
550
+ );
551
+
552
+ // src/use-autocomplete.tsx
553
+ var import_core8 = require("@yamada-ui/core");
554
+ var import_form_control = require("@yamada-ui/form-control");
555
+ var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
556
+ var import_use_disclosure = require("@yamada-ui/use-disclosure");
557
+ var import_use_outside_click = require("@yamada-ui/use-outside-click");
558
+ var import_utils11 = require("@yamada-ui/utils");
559
+ var import_react5 = require("react");
560
+
561
+ // src/autocomplete-option.tsx
562
+ var import_core5 = require("@yamada-ui/core");
563
+ var import_utils8 = require("@yamada-ui/utils");
564
+ var import_jsx_runtime5 = require("react/jsx-runtime");
565
+ var AutocompleteOption = (0, import_core5.forwardRef)(
566
+ ({ className, icon, ...rest }, ref) => {
567
+ const { styles } = useAutocompleteContext();
568
+ const { isSelected, customIcon, children, getOptionProps } = useAutocompleteOption(rest);
569
+ icon != null ? icon : icon = customIcon;
570
+ const css = {
571
+ textDecoration: "none",
572
+ color: "inherit",
573
+ userSelect: "none",
574
+ display: "flex",
575
+ width: "100%",
576
+ alignItems: "center",
577
+ textAlign: "start",
578
+ flex: "0 0 auto",
579
+ outline: 0,
580
+ gap: "0.75rem",
581
+ ...styles.item
582
+ };
583
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
584
+ import_core5.ui.li,
585
+ {
586
+ className: (0, import_utils8.cx)("ui-autocomplete__item", className),
587
+ __css: css,
588
+ ...getOptionProps({}, ref),
589
+ children: [
590
+ icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AutocompleteItemIcon, { opacity: isSelected ? 1 : 0, children: icon || /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CheckIcon, {}) }) : null,
591
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_core5.ui.span, { style: { flex: 1 }, "data-label": true, children })
592
+ ]
593
+ }
594
+ );
595
+ }
596
+ );
597
+ var CheckIcon = () => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("svg", { viewBox: "0 0 14 14", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
598
+ "polygon",
599
+ {
600
+ fill: "currentColor",
601
+ points: "5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039"
602
+ }
603
+ ) });
604
+
605
+ // src/autocomplete-option-group.tsx
606
+ var import_core7 = require("@yamada-ui/core");
607
+ var import_utils10 = require("@yamada-ui/utils");
608
+
609
+ // src/use-autocomplete-option-group.ts
610
+ var import_core6 = require("@yamada-ui/core");
611
+ var import_utils9 = require("@yamada-ui/utils");
612
+ var import_react4 = require("react");
613
+ var useAutocompleteOptionGroup = ({
614
+ label,
615
+ ...rest
616
+ }) => {
617
+ const { value, omitSelectedValues } = useAutocompleteContext();
618
+ const isMulti = (0, import_utils9.isArray)(value);
619
+ const descendants = useAutocompleteDescendantsContext();
620
+ const values = descendants.values();
621
+ const selectedValues = isMulti && omitSelectedValues ? descendants.values(
622
+ ({ node }) => {
623
+ var _a;
624
+ return value.includes((_a = node.dataset.value) != null ? _a : "");
625
+ }
626
+ ) : [];
627
+ const selectedIndexes = selectedValues.map(({ index }) => index);
628
+ const childValues = values.filter(
629
+ ({ node, index }) => {
630
+ var _a;
631
+ return ((_a = node.parentElement) == null ? void 0 : _a.dataset.label) === label && !selectedIndexes.includes(index) && "target" in node.dataset;
632
+ }
633
+ );
634
+ const isEmpty = !childValues.length;
635
+ const [containerProps, groupProps] = (0, import_utils9.splitObject)(rest, import_core6.layoutStyleProperties);
636
+ const getContainerProps = (0, import_react4.useCallback)(
637
+ (props = {}, ref = null) => {
638
+ const style = {
639
+ border: "0px",
640
+ clip: "rect(0px, 0px, 0px, 0px)",
641
+ height: "1px",
642
+ width: "1px",
643
+ margin: "-1px",
644
+ padding: "0px",
645
+ overflow: "hidden",
646
+ whiteSpace: "nowrap",
647
+ position: "absolute"
648
+ };
649
+ return {
650
+ ref,
651
+ ...props,
652
+ ...containerProps,
653
+ style: isEmpty ? style : void 0,
654
+ "data-label": label,
655
+ role: "autocomplete-group-container"
656
+ };
553
657
  },
554
- [
555
- allowFree,
556
- isMulti,
557
- onChangeLabel,
558
- rebirthOptions,
559
- setValue,
560
- descendants,
561
- format
562
- ]
658
+ [containerProps, isEmpty, label]
659
+ );
660
+ const getGroupProps = (0, import_react4.useCallback)(
661
+ (props = {}, ref = null) => ({
662
+ ref,
663
+ ...props,
664
+ ...groupProps,
665
+ "data-label": label,
666
+ role: "autocomplete-group"
667
+ }),
668
+ [groupProps, label]
669
+ );
670
+ return {
671
+ label,
672
+ getContainerProps,
673
+ getGroupProps
674
+ };
675
+ };
676
+
677
+ // src/autocomplete-option-group.tsx
678
+ var import_jsx_runtime6 = require("react/jsx-runtime");
679
+ var AutocompleteOptionGroup = (0, import_core7.forwardRef)(
680
+ ({ className, color, h, height, minH, minHeight, children, ...rest }, ref) => {
681
+ const { styles } = useAutocompleteContext();
682
+ const { label, getContainerProps, getGroupProps } = useAutocompleteOptionGroup(rest);
683
+ h != null ? h : h = height;
684
+ minH != null ? minH : minH = minHeight;
685
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
686
+ import_core7.ui.li,
687
+ {
688
+ className: (0, import_utils10.cx)(
689
+ "ui-autocomplete__item",
690
+ "ui-autocomplete__item--group",
691
+ className
692
+ ),
693
+ __css: { w: "100%", h: "fit-content", color },
694
+ ...getContainerProps(),
695
+ children: [
696
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
697
+ import_core7.ui.span,
698
+ {
699
+ className: "ui-autocomplete__item__group-label",
700
+ __css: styles.groupLabel,
701
+ lineClamp: 1,
702
+ children: label
703
+ }
704
+ ),
705
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
706
+ import_core7.ui.ul,
707
+ {
708
+ ...getGroupProps({}, ref),
709
+ className: "ui-autocomplete__item__group",
710
+ __css: { h, minH, ...styles.group },
711
+ children
712
+ }
713
+ )
714
+ ]
715
+ }
716
+ );
717
+ }
718
+ );
719
+
720
+ // src/use-autocomplete.tsx
721
+ var import_jsx_runtime7 = require("react/jsx-runtime");
722
+ var kanaMap = {
723
+ \uFF76\uFF9E: "\u30AC",
724
+ \uFF77\uFF9E: "\u30AE",
725
+ \uFF78\uFF9E: "\u30B0",
726
+ \uFF79\uFF9E: "\u30B2",
727
+ \uFF7A\uFF9E: "\u30B4",
728
+ \uFF7B\uFF9E: "\u30B6",
729
+ \uFF7C\uFF9E: "\u30B8",
730
+ \uFF7D\uFF9E: "\u30BA",
731
+ \uFF7E\uFF9E: "\u30BC",
732
+ \uFF7F\uFF9E: "\u30BE",
733
+ \uFF80\uFF9E: "\u30C0",
734
+ \uFF81\uFF9E: "\u30C2",
735
+ \uFF82\uFF9E: "\u30C5",
736
+ \uFF83\uFF9E: "\u30C7",
737
+ \uFF84\uFF9E: "\u30C9",
738
+ \uFF8A\uFF9E: "\u30D0",
739
+ \uFF8B\uFF9E: "\u30D3",
740
+ \uFF8C\uFF9E: "\u30D6",
741
+ \uFF8D\uFF9E: "\u30D9",
742
+ \uFF8E\uFF9E: "\u30DC",
743
+ \uFF8A\uFF9F: "\u30D1",
744
+ \uFF8B\uFF9F: "\u30D4",
745
+ \uFF8C\uFF9F: "\u30D7",
746
+ \uFF8D\uFF9F: "\u30DA",
747
+ \uFF8E\uFF9F: "\u30DD",
748
+ \uFF73\uFF9E: "\u30F4",
749
+ \uFF9C\uFF9E: "\u30F7",
750
+ \uFF66\uFF9E: "\u30FA",
751
+ \uFF71: "\u30A2",
752
+ \uFF72: "\u30A4",
753
+ \uFF73: "\u30A6",
754
+ \uFF74: "\u30A8",
755
+ \uFF75: "\u30AA",
756
+ \uFF76: "\u30AB",
757
+ \uFF77: "\u30AD",
758
+ \uFF78: "\u30AF",
759
+ \uFF79: "\u30B1",
760
+ \uFF7A: "\u30B3",
761
+ \uFF7B: "\u30B5",
762
+ \uFF7C: "\u30B7",
763
+ \uFF7D: "\u30B9",
764
+ \uFF7E: "\u30BB",
765
+ \uFF7F: "\u30BD",
766
+ \uFF80: "\u30BF",
767
+ \uFF81: "\u30C1",
768
+ \uFF82: "\u30C4",
769
+ \uFF83: "\u30C6",
770
+ \uFF84: "\u30C8",
771
+ \uFF85: "\u30CA",
772
+ \uFF86: "\u30CB",
773
+ \uFF87: "\u30CC",
774
+ \uFF88: "\u30CD",
775
+ \uFF89: "\u30CE",
776
+ \uFF8A: "\u30CF",
777
+ \uFF8B: "\u30D2",
778
+ \uFF8C: "\u30D5",
779
+ \uFF8D: "\u30D8",
780
+ \uFF8E: "\u30DB",
781
+ \uFF8F: "\u30DE",
782
+ \uFF90: "\u30DF",
783
+ \uFF91: "\u30E0",
784
+ \uFF92: "\u30E1",
785
+ \uFF93: "\u30E2",
786
+ \uFF94: "\u30E4",
787
+ \uFF95: "\u30E6",
788
+ \uFF96: "\u30E8",
789
+ \uFF97: "\u30E9",
790
+ \uFF98: "\u30EA",
791
+ \uFF99: "\u30EB",
792
+ \uFF9A: "\u30EC",
793
+ \uFF9B: "\u30ED",
794
+ \uFF9C: "\u30EF",
795
+ \uFF66: "\u30F2",
796
+ \uFF9D: "\u30F3",
797
+ \uFF67: "\u30A1",
798
+ \uFF68: "\u30A3",
799
+ \uFF69: "\u30A5",
800
+ \uFF6A: "\u30A7",
801
+ \uFF6B: "\u30A9",
802
+ \uFF6F: "\u30C3",
803
+ \uFF6C: "\u30E3",
804
+ \uFF6D: "\u30E5",
805
+ \uFF6E: "\u30E7",
806
+ "\uFF61": "\u3002",
807
+ "\uFF64": "\u3001",
808
+ \uFF70: "\u30FC",
809
+ "\uFF62": "\u300C",
810
+ "\uFF63": "\u300D",
811
+ "\uFF65": "\u30FB"
812
+ };
813
+ var defaultFormat = (value) => {
814
+ value = value.replace(
815
+ /[!-~]/g,
816
+ (v) => String.fromCharCode(v.charCodeAt(0) - 65248)
817
+ );
818
+ const reg = new RegExp("(" + Object.keys(kanaMap).join("|") + ")", "g");
819
+ value = value.replace(reg, (v) => kanaMap[v]).replace(/゙/g, "\u309B").replace(/゚/g, "\u309C");
820
+ value = value.toUpperCase();
821
+ return value;
822
+ };
823
+ var flattenItems = (items) => {
824
+ const filterItems = (items2) => items2.map((item) => {
825
+ var _a;
826
+ const { isDisabled, isFocusable } = item;
827
+ const trulyDisabled = !!isDisabled && !isFocusable;
828
+ if (trulyDisabled) return;
829
+ if ("items" in item) {
830
+ return filterItems((_a = item.items) != null ? _a : []);
831
+ } else {
832
+ return item;
833
+ }
834
+ }).filter(Boolean);
835
+ return filterItems(items).flat(Infinity);
836
+ };
837
+ var useAutocomplete = (props) => {
838
+ const {
839
+ value: valueProp,
840
+ defaultValue,
841
+ onChange: onChangeProp,
842
+ onCreate: onCreateProp,
843
+ onSearch: onSearchProp,
844
+ closeOnSelect = true,
845
+ omitSelectedValues = false,
846
+ maxSelectValues,
847
+ allowCreate = false,
848
+ allowFree = false,
849
+ insertPositionItem = "first",
850
+ emptyMessage = "No results found",
851
+ format = defaultFormat,
852
+ optionProps,
853
+ placeholder,
854
+ onKeyDown: onKeyDownProp,
855
+ isOpen: isOpenProp,
856
+ defaultIsOpen,
857
+ onOpen: onOpenProp,
858
+ onClose: onCloseProp,
859
+ closeOnBlur = true,
860
+ closeOnEsc = true,
861
+ openDelay,
862
+ closeDelay,
863
+ isLazy,
864
+ lazyBehavior,
865
+ animation,
866
+ duration = 0.2,
867
+ offset,
868
+ gutter,
869
+ preventOverflow,
870
+ flip,
871
+ matchWidth = true,
872
+ boundary,
873
+ eventListeners,
874
+ strategy,
875
+ placement = "bottom-start",
876
+ modifiers,
877
+ items,
878
+ children,
879
+ ...rest
880
+ } = (0, import_form_control.useFormControlProps)(props);
881
+ const {
882
+ "aria-readonly": _ariaReadonly,
883
+ onFocus: onFocusProp,
884
+ ...formControlProps
885
+ } = (0, import_utils11.pickObject)(rest, import_form_control.formControlProperties);
886
+ const [containerProps, inputProps] = (0, import_utils11.splitObject)(rest, import_core8.layoutStyleProperties);
887
+ const { id } = rest;
888
+ const descendants = useAutocompleteDescendants();
889
+ const containerRef = (0, import_react5.useRef)(null);
890
+ const listRef = (0, import_react5.useRef)(null);
891
+ const inputRef = (0, import_react5.useRef)(null);
892
+ const timeoutIds = (0, import_react5.useRef)(/* @__PURE__ */ new Set([]));
893
+ const isComposition = (0, import_react5.useRef)(false);
894
+ const prevValue = (0, import_react5.useRef)(void 0);
895
+ const [resolvedItems, setResolvedItems] = (0, import_react5.useState)(items ? JSON.parse(JSON.stringify(items)) : void 0);
896
+ const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
897
+ value: valueProp,
898
+ defaultValue,
899
+ onChange: onChangeProp
900
+ });
901
+ const [label, setLabel] = (0, import_react5.useState)(void 0);
902
+ const [inputValue, setInputValue] = (0, import_react5.useState)("");
903
+ const [focusedIndex, setFocusedIndex] = (0, import_react5.useState)(-1);
904
+ const [isAllSelected, setIsAllSelected] = (0, import_react5.useState)(false);
905
+ const [isHit, setIsHit] = (0, import_react5.useState)(true);
906
+ const {
907
+ isOpen,
908
+ onOpen: onInternalOpen,
909
+ onClose
910
+ } = (0, import_use_disclosure.useDisclosure)({
911
+ isOpen: isOpenProp,
912
+ defaultIsOpen,
913
+ onOpen: onOpenProp,
914
+ onClose: onCloseProp
915
+ });
916
+ const isFocused = focusedIndex > -1;
917
+ const isCreate = focusedIndex === -2 && allowCreate;
918
+ const isMulti = (0, import_utils11.isArray)(value);
919
+ const isEmptyValue = !isMulti ? !value : !value.length;
920
+ const [firstInsertPositionItem, secondInsertPositionItem] = (0, import_react5.useMemo)(() => {
921
+ if ((0, import_utils11.isArray)(insertPositionItem)) {
922
+ return insertPositionItem;
923
+ } else {
924
+ return [insertPositionItem, "first"];
925
+ }
926
+ }, [insertPositionItem]);
927
+ if (allowCreate && !(0, import_utils11.isUndefined)(children)) {
928
+ console.warn(
929
+ `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'allowCreate' is true, it will not be reflected correctly. If want to reflect, please set 'items' in props.`
930
+ );
931
+ }
932
+ const selectedValues = descendants.enabledValues(
933
+ ({ node }) => {
934
+ var _a;
935
+ return isMulti && value.includes((_a = node.dataset.value) != null ? _a : "");
936
+ }
563
937
  );
564
- const onSelect = (0, import_react.useCallback)(() => {
565
- var _a, _b;
566
- let enabledValue = descendants.value(focusedIndex);
567
- if ("disabled" in ((_a = enabledValue == null ? void 0 : enabledValue.node.dataset) != null ? _a : {}))
568
- enabledValue = void 0;
569
- if (!enabledValue) return;
570
- const value2 = (_b = enabledValue.node.dataset.value) != null ? _b : "";
571
- onChange(value2);
572
- if (closeOnSelect) onClose();
573
- if (omitSelectedValues) onFocusNext();
938
+ const selectedIndexes = selectedValues.map(({ index }) => index);
939
+ const enabledValues = descendants.enabledValues(
940
+ ({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
941
+ );
942
+ const validChildren = (0, import_utils11.getValidChildren)(children);
943
+ const computedChildren = (0, import_react5.useMemo)(
944
+ () => resolvedItems == null ? void 0 : resolvedItems.map((item, i) => {
945
+ if ("value" in item) {
946
+ const { label: label2, value: value2, ...props2 } = item;
947
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AutocompleteOption, { value: value2, ...props2, children: label2 }, i);
948
+ } else if ("items" in item) {
949
+ const { label: label2, items: items2 = [], ...props2 } = item;
950
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AutocompleteOptionGroup, { label: label2, ...props2, children: items2.map(({ label: label3, value: value2, ...props3 }, i2) => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AutocompleteOption, { value: value2, ...props3, children: label3 }, i2)) }, i);
951
+ }
952
+ }),
953
+ [resolvedItems]
954
+ );
955
+ const isEmpty = !validChildren.length && !(computedChildren == null ? void 0 : computedChildren.length);
956
+ const onOpen = (0, import_react5.useCallback)(() => {
957
+ if (formControlProps.disabled || formControlProps.readOnly) return;
958
+ if (!allowCreate && (isEmpty || isAllSelected)) return;
959
+ onInternalOpen();
960
+ if (inputRef.current) inputRef.current.focus();
961
+ }, [allowCreate, formControlProps, isAllSelected, isEmpty, onInternalOpen]);
962
+ const onFocusFirst = (0, import_react5.useCallback)(() => {
963
+ const id2 = setTimeout(() => {
964
+ if (isEmpty || isAllSelected) return;
965
+ const first = descendants.enabledFirstValue(
966
+ ({ node }) => "target" in node.dataset
967
+ );
968
+ if (!first) return;
969
+ if (!isMulti || !omitSelectedValues) {
970
+ setFocusedIndex(first.index);
971
+ } else {
972
+ if (selectedIndexes.includes(first.index)) {
973
+ const enabledFirst = enabledValues[0];
974
+ setFocusedIndex(enabledFirst.index);
975
+ } else {
976
+ setFocusedIndex(first.index);
977
+ }
978
+ }
979
+ });
980
+ timeoutIds.current.add(id2);
574
981
  }, [
575
- closeOnSelect,
576
982
  descendants,
577
- focusedIndex,
983
+ enabledValues,
984
+ isAllSelected,
985
+ isEmpty,
986
+ isMulti,
578
987
  omitSelectedValues,
579
- onChange,
580
- onClose,
581
- onFocusNext
988
+ selectedIndexes
582
989
  ]);
583
- const onSearch = (0, import_react.useCallback)(
584
- (ev) => {
585
- if (!isOpen) onOpen();
586
- onSearchProp == null ? void 0 : onSearchProp(ev);
587
- const value2 = ev.target.value;
588
- const computedValue = format(value2);
589
- if (computedValue) {
590
- pickOptions(computedValue);
591
- } else {
592
- rebirthOptions();
593
- }
594
- setInputValue(value2);
595
- },
596
- [isOpen, onOpen, format, onSearchProp, pickOptions, rebirthOptions]
597
- );
598
- const onCompositionStart = (0, import_react.useCallback)(() => {
599
- isComposition.current = true;
600
- }, []);
601
- const onCompositionEnd = (0, import_react.useCallback)(() => {
602
- isComposition.current = false;
603
- }, []);
604
- const onCreate = (0, import_react.useCallback)(() => {
605
- var _a, _b;
606
- if (!listRef.current) return;
607
- const newItem = { label: inputValue, value: inputValue };
608
- let newItems = [];
609
- if (resolvedItems) newItems = [...resolvedItems];
610
- if (firstInsertPositionItem === "first") {
611
- newItems = [newItem, ...newItems];
612
- } else if (firstInsertPositionItem === "last") {
613
- newItems = [...newItems, newItem];
614
- } else {
615
- const i = newItems.findIndex(
616
- ({ label: label2 }) => label2 === firstInsertPositionItem
990
+ const onFocusLast = (0, import_react5.useCallback)(() => {
991
+ const id2 = setTimeout(() => {
992
+ if (isEmpty || isAllSelected) return;
993
+ const last = descendants.enabledLastValue(
994
+ ({ node }) => "target" in node.dataset
617
995
  );
618
- const targetItem = newItems[i];
619
- if (i !== -1 && "items" in targetItem) {
620
- if (secondInsertPositionItem === "first") {
621
- targetItem.items = [newItem, ...(_a = targetItem.items) != null ? _a : []];
996
+ if (!last) return;
997
+ if (!isMulti || !omitSelectedValues) {
998
+ setFocusedIndex(last.index);
999
+ } else {
1000
+ if (selectedIndexes.includes(last.index)) {
1001
+ const enabledLast = enabledValues.reverse()[0];
1002
+ setFocusedIndex(enabledLast.index);
622
1003
  } else {
623
- targetItem.items = [...(_b = targetItem.items) != null ? _b : [], newItem];
1004
+ setFocusedIndex(last.index);
624
1005
  }
625
- newItems[i] = targetItem;
626
- } else {
627
- console.warn(
628
- `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionItem}' specified in insertPositionItem does not exist in the option group.`
629
- );
630
1006
  }
631
- }
632
- setResolvedItems(newItems);
633
- onChange(inputValue);
634
- rebirthOptions(false);
635
- const index = flattenItems(newItems).findIndex(
636
- ({ value: value2 }) => value2 === inputValue
637
- );
638
- setFocusedIndex(index);
639
- onCreateProp == null ? void 0 : onCreateProp(newItem, newItems);
1007
+ });
1008
+ timeoutIds.current.add(id2);
640
1009
  }, [
641
- inputValue,
642
- resolvedItems,
643
- firstInsertPositionItem,
644
- onChange,
645
- rebirthOptions,
646
- onCreateProp,
647
- secondInsertPositionItem,
648
- isMulti
1010
+ descendants,
1011
+ enabledValues,
1012
+ isAllSelected,
1013
+ isEmpty,
1014
+ isMulti,
1015
+ omitSelectedValues,
1016
+ selectedIndexes
649
1017
  ]);
650
- const onClick = (0, import_react.useCallback)(() => {
651
- if (isOpen) {
652
- if (inputRef.current) inputRef.current.focus();
653
- } else {
654
- onOpen();
655
- onFocusFirstOrSelected();
656
- }
657
- }, [isOpen, onFocusFirstOrSelected, onOpen]);
658
- const onFocus = (0, import_react.useCallback)(() => {
659
- if (isOpen) return;
660
- onOpen();
661
- onFocusFirstOrSelected();
662
- }, [isOpen, onFocusFirstOrSelected, onOpen]);
663
- const onBlur = (0, import_react.useCallback)(
664
- (ev) => {
665
- const relatedTarget = (0, import_utils.getEventRelatedTarget)(ev);
666
- if ((0, import_utils.isContains)(containerRef.current, relatedTarget)) return;
667
- if (!closeOnBlur && isHit) return;
668
- if (allowFree && !!inputValue) onChange(inputValue, { runRebirth: false });
669
- setInputValue("");
670
- if (isOpen) onClose();
671
- },
672
- [closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
673
- );
674
- const onDelete = (0, import_react.useCallback)(() => {
675
- if (!isMulti) {
676
- onChange("", { forceUpdate: true });
677
- } else {
678
- onChange(value[value.length - 1]);
679
- }
680
- if (!isOpen) onFocus();
681
- }, [isMulti, isOpen, onChange, onFocus, value]);
682
- const onClear = (0, import_react.useCallback)(
683
- (ev) => {
684
- ev.stopPropagation();
685
- prevValue.current = [];
686
- setValue([]);
687
- setLabel(void 0);
688
- setInputValue("");
689
- rebirthOptions();
690
- if (isOpen && inputRef.current) inputRef.current.focus();
691
- },
692
- [isOpen, setLabel, setInputValue, setValue, rebirthOptions]
693
- );
694
- const onKeyDown = (0, import_react.useCallback)(
695
- (ev) => {
696
- if (ev.key === " ") ev.key = ev.code;
697
- if (formControlProps.disabled || formControlProps.readOnly) return;
698
- if (isComposition.current) return;
699
- const enabledDelete = label === inputValue || !inputValue.length;
700
- const actions = {
701
- ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
702
- ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
703
- Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
704
- Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
705
- if (inputValue) onChange(inputValue);
706
- setFocusedIndex(0);
707
- } : void 0,
708
- Home: isOpen ? onFocusFirst : void 0,
709
- End: isOpen ? onFocusLast : void 0,
710
- Escape: closeOnEsc ? onClose : void 0,
711
- Backspace: !isEmptyValue && enabledDelete ? onDelete : void 0
712
- };
713
- const action = actions[ev.key];
714
- if (!action) return;
715
- ev.preventDefault();
716
- ev.stopPropagation();
717
- action(ev);
1018
+ const onFocusSelected = (0, import_react5.useCallback)(() => {
1019
+ const id2 = setTimeout(() => {
1020
+ const values = descendants.enabledValues();
1021
+ const selected = values.find(
1022
+ ({ node }) => {
1023
+ var _a;
1024
+ return !isMulti ? node.dataset.value === value : value.includes((_a = node.dataset.value) != null ? _a : "");
1025
+ }
1026
+ );
1027
+ if (selected) setFocusedIndex(selected.index);
1028
+ });
1029
+ timeoutIds.current.add(id2);
1030
+ }, [descendants, isMulti, value]);
1031
+ const onFocusNext = (0, import_react5.useCallback)(
1032
+ (index = focusedIndex) => {
1033
+ const id2 = setTimeout(() => {
1034
+ var _a;
1035
+ const next = descendants.enabledNextValue(
1036
+ index,
1037
+ ({ node }) => "target" in node.dataset
1038
+ );
1039
+ if (!next) return;
1040
+ if (!isMulti || !omitSelectedValues) {
1041
+ setFocusedIndex(next.index);
1042
+ } else {
1043
+ if (selectedIndexes.includes(next.index)) {
1044
+ const enabledNext = (_a = enabledValues.find(({ index: index2 }) => next.index < index2)) != null ? _a : enabledValues[0];
1045
+ setFocusedIndex(enabledNext.index);
1046
+ } else {
1047
+ setFocusedIndex(next.index);
1048
+ }
1049
+ }
1050
+ });
1051
+ timeoutIds.current.add(id2);
718
1052
  },
719
1053
  [
720
- allowFree,
721
- formControlProps,
722
- label,
723
- inputValue,
724
- onOpen,
725
- isFocused,
1054
+ descendants,
1055
+ enabledValues,
1056
+ focusedIndex,
726
1057
  isMulti,
727
- onFocusFirstOrSelected,
728
- onFocusNext,
729
- onFocusLastOrSelected,
730
- onFocusPrev,
731
- isCreate,
732
- onCreate,
733
- onSelect,
734
- isOpen,
735
- onFocusFirst,
736
- onFocusLast,
737
- closeOnEsc,
738
- onClose,
739
- isEmptyValue,
740
- onDelete,
741
- onChange
1058
+ omitSelectedValues,
1059
+ selectedIndexes
742
1060
  ]
743
1061
  );
744
- (0, import_react.useEffect)(() => {
745
- if (!isMulti) return;
746
- if (!omitSelectedValues && (0, import_utils.isUndefined)(maxSelectValues)) return;
747
- const isAll = value.length > 0 && value.length === descendants.count();
748
- const isMax = value.length === maxSelectValues;
749
- if (isAll || isMax) {
750
- onClose();
751
- setIsAllSelected(true);
752
- } else {
753
- setIsAllSelected(false);
754
- }
755
- }, [
756
- omitSelectedValues,
757
- value,
758
- descendants,
759
- isMulti,
760
- onClose,
761
- maxSelectValues
762
- ]);
763
- (0, import_react.useEffect)(() => {
764
- var _a;
765
- if (isMulti) {
766
- if (JSON.stringify((_a = prevValue.current) != null ? _a : []) === JSON.stringify(value != null ? value : []))
767
- return;
768
- const label2 = getSelectedValues(value);
769
- setLabel(label2);
770
- } else {
771
- if (prevValue.current === value) return;
772
- onChangeLabel(value, { runOmit: false });
773
- }
774
- }, [isMulti, value, onChangeLabel, getSelectedValues]);
775
- (0, import_utils.useUpdateEffect)(() => {
776
- if (isOpen || allowFree) return;
777
- setFocusedIndex(-1);
778
- setInputValue("");
779
- }, [isOpen]);
780
- (0, import_utils.useUpdateEffect)(() => {
781
- if (!isHit) setFocusedIndex(-2);
782
- }, [isHit]);
783
- (0, import_utils.useUpdateEffect)(() => {
784
- setResolvedItems(items ? JSON.parse(JSON.stringify(items)) : void 0);
785
- }, [items]);
786
- (0, import_utils.useUnmountEffect)(() => {
787
- timeoutIds.current.forEach((id2) => clearTimeout(id2));
788
- timeoutIds.current.clear();
789
- });
790
- (0, import_use_outside_click.useOutsideClick)({
791
- ref: containerRef,
792
- handler: onClose,
793
- enabled: isOpen && (closeOnBlur || !isHit)
794
- });
795
- const getPopoverProps = (0, import_react.useCallback)(
796
- (props2) => ({
797
- closeOnBlur,
798
- openDelay,
799
- closeDelay,
800
- isLazy,
801
- lazyBehavior,
802
- animation,
803
- duration,
804
- offset,
805
- gutter,
806
- preventOverflow,
807
- flip,
808
- matchWidth,
809
- boundary,
810
- eventListeners,
811
- strategy,
812
- placement,
813
- modifiers,
814
- ...props2,
815
- trigger: "never",
816
- closeOnButton: false,
817
- isOpen,
818
- onOpen,
819
- onClose
820
- }),
1062
+ const onFocusPrev = (0, import_react5.useCallback)(
1063
+ (index = focusedIndex) => {
1064
+ const id2 = setTimeout(() => {
1065
+ var _a;
1066
+ const prev = descendants.enabledPrevValue(
1067
+ index,
1068
+ ({ node }) => "target" in node.dataset
1069
+ );
1070
+ if (!prev) return;
1071
+ if (!isMulti || !omitSelectedValues) {
1072
+ setFocusedIndex(prev.index);
1073
+ } else {
1074
+ if (selectedIndexes.includes(prev.index)) {
1075
+ const enabledPrev = (_a = enabledValues.reverse().find(({ index: index2 }) => index2 < prev.index)) != null ? _a : enabledValues[0];
1076
+ setFocusedIndex(enabledPrev.index);
1077
+ } else {
1078
+ setFocusedIndex(prev.index);
1079
+ }
1080
+ }
1081
+ });
1082
+ timeoutIds.current.add(id2);
1083
+ },
821
1084
  [
822
- closeOnBlur,
823
- openDelay,
824
- closeDelay,
825
- isLazy,
826
- lazyBehavior,
827
- animation,
828
- duration,
829
- offset,
830
- gutter,
831
- preventOverflow,
832
- flip,
833
- matchWidth,
834
- boundary,
835
- eventListeners,
836
- strategy,
837
- placement,
838
- modifiers,
839
- isOpen,
840
- onOpen,
841
- onClose
1085
+ descendants,
1086
+ enabledValues,
1087
+ focusedIndex,
1088
+ isMulti,
1089
+ omitSelectedValues,
1090
+ selectedIndexes
842
1091
  ]
843
1092
  );
844
- const getContainerProps = (0, import_react.useCallback)(
845
- (props2 = {}, ref = null) => ({
846
- ref: (0, import_utils.mergeRefs)(containerRef, ref),
847
- ...containerProps,
848
- ...props2,
849
- ...formControlProps,
850
- onClick: (0, import_utils.handlerAll)(props2.onClick, rest.onClick, onClick),
851
- onBlur: (0, import_utils.handlerAll)(props2.onBlur, rest.onBlur, onBlur)
852
- }),
853
- [containerProps, formControlProps, onBlur, onClick, rest]
1093
+ const onFocusFirstOrSelected = isEmptyValue || omitSelectedValues ? onFocusFirst : onFocusSelected;
1094
+ const onFocusLastOrSelected = isEmptyValue || omitSelectedValues ? onFocusLast : onFocusSelected;
1095
+ const pickOptions = (0, import_react5.useCallback)(
1096
+ (value2) => {
1097
+ const values = descendants.values();
1098
+ let isHit2 = false;
1099
+ let isFocused2 = false;
1100
+ values.forEach(({ node, index }) => {
1101
+ var _a;
1102
+ if (format((_a = node.textContent) != null ? _a : "").includes(value2)) {
1103
+ isHit2 = true;
1104
+ const isDisabled = "disabled" in node.dataset;
1105
+ node.dataset.target = "";
1106
+ if (!isFocused2 && !isDisabled) {
1107
+ isFocused2 = true;
1108
+ setFocusedIndex(index);
1109
+ }
1110
+ } else {
1111
+ delete node.dataset.target;
1112
+ }
1113
+ });
1114
+ setIsHit(isHit2);
1115
+ },
1116
+ [descendants, format]
854
1117
  );
855
- const getFieldProps = (0, import_react.useCallback)(
856
- (props2 = {}, ref = null) => ({
857
- ref,
858
- tabIndex: -1,
859
- ...props2,
860
- ...formControlProps,
861
- placeholder,
862
- "data-active": (0, import_utils.dataAttr)(isOpen),
863
- "aria-expanded": (0, import_utils.dataAttr)(isOpen),
864
- onFocus: (0, import_utils.handlerAll)(props2.onFocus, onFocusProp, onFocus),
865
- onKeyDown: (0, import_utils.handlerAll)(props2.onKeyDown, onKeyDownProp, onKeyDown)
866
- }),
1118
+ const rebirthOptions = (0, import_react5.useCallback)(
1119
+ (runFocus = true) => {
1120
+ const values = descendants.values();
1121
+ values.forEach(({ node }) => {
1122
+ node.dataset.target = "";
1123
+ });
1124
+ if (runFocus) onFocusFirst();
1125
+ setIsHit(true);
1126
+ },
1127
+ [descendants, onFocusFirst]
1128
+ );
1129
+ const getSelectedValues = (0, import_react5.useCallback)(
1130
+ (newValues) => {
1131
+ const enabledValues2 = descendants.enabledValues();
1132
+ const resolvedValues = (0, import_utils11.isArray)(newValues) ? newValues : [newValues];
1133
+ const selectedValues2 = resolvedValues.map((value2) => {
1134
+ var _a, _b;
1135
+ const { node } = (_a = enabledValues2.find(({ node: node2 }) => node2.dataset.value === value2)) != null ? _a : {};
1136
+ if (node) {
1137
+ const el = Array.from(node.children).find(
1138
+ (child) => child.getAttribute("data-label") !== null
1139
+ );
1140
+ return (_b = el == null ? void 0 : el.textContent) != null ? _b : void 0;
1141
+ } else {
1142
+ return allowFree ? value2 : void 0;
1143
+ }
1144
+ }).filter(Boolean);
1145
+ return selectedValues2;
1146
+ },
1147
+ [allowFree, descendants]
1148
+ );
1149
+ const onChangeLabel = (0, import_react5.useCallback)(
1150
+ (newValue, { forceUpdate, runOmit = true } = {}) => {
1151
+ const selectedValues2 = getSelectedValues(newValue);
1152
+ if (!forceUpdate && !selectedValues2.length) return;
1153
+ setLabel((prev) => {
1154
+ if (!isMulti) {
1155
+ return selectedValues2[0];
1156
+ } else {
1157
+ selectedValues2.forEach((selectedValue) => {
1158
+ const isSelected = (0, import_utils11.isArray)(prev) && prev.includes(selectedValue != null ? selectedValue : "");
1159
+ if (!isSelected) {
1160
+ prev = [...(0, import_utils11.isArray)(prev) ? prev : [], selectedValue];
1161
+ } else if (runOmit) {
1162
+ prev = (0, import_utils11.isArray)(prev) ? prev.filter((value2) => value2 !== selectedValue) : void 0;
1163
+ }
1164
+ });
1165
+ return prev;
1166
+ }
1167
+ });
1168
+ },
1169
+ [getSelectedValues, isMulti]
1170
+ );
1171
+ const onChange = (0, import_react5.useCallback)(
1172
+ (newValue, { forceUpdate, runRebirth = true } = {}) => {
1173
+ setValue((prev) => {
1174
+ let next;
1175
+ if (!(0, import_utils11.isArray)(prev)) {
1176
+ next = newValue;
1177
+ } else {
1178
+ const isSelected = prev.includes(newValue);
1179
+ if (!isSelected) {
1180
+ next = [...prev, newValue];
1181
+ } else {
1182
+ next = prev.filter((value2) => value2 !== newValue);
1183
+ }
1184
+ }
1185
+ prevValue.current = next;
1186
+ return next;
1187
+ });
1188
+ const isHit2 = descendants.values().filter(
1189
+ ({ node }) => {
1190
+ var _a;
1191
+ return format((_a = node.textContent) != null ? _a : "").includes(newValue);
1192
+ }
1193
+ ).length > 0;
1194
+ onChangeLabel(newValue, { forceUpdate });
1195
+ if (allowFree || isHit2) setInputValue("");
1196
+ if (isMulti && runRebirth) rebirthOptions(false);
1197
+ },
867
1198
  [
868
- formControlProps,
869
- placeholder,
870
- isOpen,
871
- onFocusProp,
872
- onFocus,
873
- onKeyDownProp,
874
- onKeyDown
1199
+ allowFree,
1200
+ isMulti,
1201
+ onChangeLabel,
1202
+ rebirthOptions,
1203
+ setValue,
1204
+ descendants,
1205
+ format
875
1206
  ]
876
1207
  );
877
- return {
878
- id,
1208
+ const onSelect = (0, import_react5.useCallback)(() => {
1209
+ var _a, _b;
1210
+ let enabledValue = descendants.value(focusedIndex);
1211
+ if ("disabled" in ((_a = enabledValue == null ? void 0 : enabledValue.node.dataset) != null ? _a : {}))
1212
+ enabledValue = void 0;
1213
+ if (!enabledValue) return;
1214
+ const value2 = (_b = enabledValue.node.dataset.value) != null ? _b : "";
1215
+ onChange(value2);
1216
+ if (closeOnSelect) onClose();
1217
+ if (omitSelectedValues) onFocusNext();
1218
+ }, [
1219
+ closeOnSelect,
879
1220
  descendants,
880
- value,
881
- label,
882
- inputValue,
883
- isHit,
884
- isEmpty,
885
- computedChildren,
886
1221
  focusedIndex,
887
1222
  omitSelectedValues,
888
- closeOnSelect,
889
- allowCreate,
890
- allowFree,
891
- emptyMessage,
892
- isOpen,
893
- isAllSelected,
894
- listRef,
895
- inputRef,
896
- optionProps,
897
- formControlProps,
898
- setFocusedIndex,
899
- onChangeLabel,
900
1223
  onChange,
901
- onSearch,
902
- onCreate,
903
- onClear,
904
- onCompositionStart,
905
- onCompositionEnd,
906
- pickOptions,
907
- rebirthOptions,
908
- onOpen,
909
1224
  onClose,
910
- onFocusFirst,
911
- onFocusLast,
912
- onFocusSelected,
913
- onFocusNext,
914
- onFocusPrev,
915
- getPopoverProps,
916
- getContainerProps,
917
- getFieldProps,
918
- inputProps
919
- };
920
- };
921
- var useAutocompleteInput = () => {
922
- const {
923
- id,
924
- inputRef,
925
- onSearch,
926
- onCompositionStart,
927
- onCompositionEnd,
928
- isAllSelected,
929
- formControlProps,
930
- inputProps,
931
- isOpen,
932
- focusedIndex,
933
- listRef
934
- } = useAutocompleteContext();
935
- const { value } = useAutocompleteDescendantsContext();
936
- (0, import_utils.useUpdateEffect)(() => {
937
- if (isAllSelected && inputRef.current) inputRef.current.blur();
938
- }, [isAllSelected]);
939
- const getInputProps = (0, import_react.useCallback)(
940
- (props = {}, ref = null) => {
941
- var _a, _b;
942
- return {
943
- ref: (0, import_utils.mergeRefs)(inputRef, ref),
944
- ...formControlProps,
945
- role: "combobox",
946
- "aria-haspopup": "listbox",
947
- "aria-autocomplete": "list",
948
- "aria-expanded": isOpen,
949
- "aria-activedescendant": (_a = value(focusedIndex)) == null ? void 0 : _a.node.id,
950
- "aria-controls": (_b = listRef.current) == null ? void 0 : _b.id,
951
- autoCapitalize: "none",
952
- autoComplete: "off",
953
- spellCheck: "false",
954
- ...inputProps,
955
- ...props,
956
- id,
957
- cursor: formControlProps.readOnly ? "default" : "text",
958
- pointerEvents: formControlProps.disabled || isAllSelected ? "none" : "auto",
959
- tabIndex: isAllSelected ? -1 : 0,
960
- onChange: (0, import_utils.handlerAll)(props.onChange, onSearch),
961
- onCompositionStart: (0, import_utils.handlerAll)(
962
- props.onCompositionStart,
963
- inputProps.onCompositionStart,
964
- onCompositionStart
965
- ),
966
- onCompositionEnd: (0, import_utils.handlerAll)(
967
- props.onCompositionEnd,
968
- inputProps.onCompositionEnd,
969
- onCompositionEnd
970
- )
971
- };
1225
+ onFocusNext
1226
+ ]);
1227
+ const onSearch = (0, import_react5.useCallback)(
1228
+ (ev) => {
1229
+ if (!isOpen) onOpen();
1230
+ onSearchProp == null ? void 0 : onSearchProp(ev);
1231
+ const value2 = ev.target.value;
1232
+ const computedValue = format(value2);
1233
+ if (computedValue) {
1234
+ pickOptions(computedValue);
1235
+ } else {
1236
+ rebirthOptions();
1237
+ }
1238
+ setInputValue(value2);
972
1239
  },
973
- [
974
- listRef,
975
- focusedIndex,
976
- isOpen,
977
- inputProps,
978
- inputRef,
979
- formControlProps,
980
- id,
981
- isAllSelected,
982
- value,
983
- onSearch,
984
- onCompositionStart,
985
- onCompositionEnd
986
- ]
1240
+ [isOpen, onOpen, format, onSearchProp, pickOptions, rebirthOptions]
987
1241
  );
988
- return {
989
- getInputProps
990
- };
991
- };
992
- var useAutocompleteList = () => {
993
- const { focusedIndex, isOpen, listRef, rebirthOptions } = useAutocompleteContext();
994
- const descendants = useAutocompleteDescendantsContext();
995
- const beforeFocusedIndex = (0, import_react.useRef)(-1);
996
- const selectedValue = descendants.value(focusedIndex);
997
- const onAnimationComplete = (0, import_react.useCallback)(() => {
998
- if (!isOpen) rebirthOptions(false);
999
- }, [isOpen, rebirthOptions]);
1000
- (0, import_react.useEffect)(() => {
1001
- if (!listRef.current || !selectedValue) return;
1002
- if (beforeFocusedIndex.current === selectedValue.index) return;
1003
- const parent = listRef.current;
1004
- const child = selectedValue.node;
1005
- const parentHeight = parent.clientHeight;
1006
- const viewTop = parent.scrollTop;
1007
- const viewBottom = viewTop + parentHeight;
1008
- const childHeight = child.clientHeight;
1009
- const childTop = child.offsetTop;
1010
- const childBottom = childTop + childHeight;
1011
- const isInView = viewTop <= childTop && childBottom <= viewBottom;
1012
- const isScrollBottom = beforeFocusedIndex.current < selectedValue.index;
1013
- if (!isInView) {
1014
- if (childBottom <= parentHeight) {
1015
- listRef.current.scrollTo({ top: 0 });
1016
- } else {
1017
- if (!isScrollBottom) {
1018
- listRef.current.scrollTo({ top: childTop + 1 });
1242
+ const onCompositionStart = (0, import_react5.useCallback)(() => {
1243
+ isComposition.current = true;
1244
+ }, []);
1245
+ const onCompositionEnd = (0, import_react5.useCallback)(() => {
1246
+ isComposition.current = false;
1247
+ }, []);
1248
+ const onCreate = (0, import_react5.useCallback)(() => {
1249
+ var _a, _b;
1250
+ if (!listRef.current) return;
1251
+ const newItem = { label: inputValue, value: inputValue };
1252
+ let newItems = [];
1253
+ if (resolvedItems) newItems = [...resolvedItems];
1254
+ if (firstInsertPositionItem === "first") {
1255
+ newItems = [newItem, ...newItems];
1256
+ } else if (firstInsertPositionItem === "last") {
1257
+ newItems = [...newItems, newItem];
1258
+ } else {
1259
+ const i = newItems.findIndex(
1260
+ ({ label: label2 }) => label2 === firstInsertPositionItem
1261
+ );
1262
+ const targetItem = newItems[i];
1263
+ if (i !== -1 && "items" in targetItem) {
1264
+ if (secondInsertPositionItem === "first") {
1265
+ targetItem.items = [newItem, ...(_a = targetItem.items) != null ? _a : []];
1019
1266
  } else {
1020
- listRef.current.scrollTo({ top: childBottom - parentHeight });
1267
+ targetItem.items = [...(_b = targetItem.items) != null ? _b : [], newItem];
1021
1268
  }
1269
+ newItems[i] = targetItem;
1270
+ } else {
1271
+ console.warn(
1272
+ `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${firstInsertPositionItem}' specified in insertPositionItem does not exist in the option group.`
1273
+ );
1022
1274
  }
1023
1275
  }
1024
- beforeFocusedIndex.current = selectedValue.index;
1025
- }, [listRef, selectedValue]);
1026
- (0, import_utils.useUpdateEffect)(() => {
1027
- if (!isOpen) beforeFocusedIndex.current = -1;
1028
- }, [isOpen]);
1029
- const getListProps = (0, import_react.useCallback)(
1030
- (props = {}, ref = null) => ({
1031
- as: "ul",
1032
- ref: (0, import_utils.mergeRefs)(listRef, ref),
1033
- role: "listbox",
1034
- tabIndex: -1,
1035
- position: "relative",
1036
- id: props.id || (0, import_react.useId)(),
1037
- ...props
1038
- }),
1039
- [listRef]
1040
- );
1041
- return {
1042
- onAnimationComplete,
1043
- getListProps
1044
- };
1045
- };
1046
- var useAutocompleteOptionGroup = ({
1047
- label,
1048
- ...rest
1049
- }) => {
1050
- const { value, omitSelectedValues } = useAutocompleteContext();
1051
- const isMulti = (0, import_utils.isArray)(value);
1052
- const descendants = useAutocompleteDescendantsContext();
1053
- const values = descendants.values();
1054
- const selectedValues = isMulti && omitSelectedValues ? descendants.values(
1055
- ({ node }) => {
1056
- var _a;
1057
- return value.includes((_a = node.dataset.value) != null ? _a : "");
1058
- }
1059
- ) : [];
1060
- const selectedIndexes = selectedValues.map(({ index }) => index);
1061
- const childValues = values.filter(
1062
- ({ node, index }) => {
1063
- var _a;
1064
- return ((_a = node.parentElement) == null ? void 0 : _a.dataset.label) === label && !selectedIndexes.includes(index) && "target" in node.dataset;
1276
+ setResolvedItems(newItems);
1277
+ onChange(inputValue);
1278
+ rebirthOptions(false);
1279
+ const index = flattenItems(newItems).findIndex(
1280
+ ({ value: value2 }) => value2 === inputValue
1281
+ );
1282
+ setFocusedIndex(index);
1283
+ onCreateProp == null ? void 0 : onCreateProp(newItem, newItems);
1284
+ }, [
1285
+ inputValue,
1286
+ resolvedItems,
1287
+ firstInsertPositionItem,
1288
+ onChange,
1289
+ rebirthOptions,
1290
+ onCreateProp,
1291
+ secondInsertPositionItem,
1292
+ isMulti
1293
+ ]);
1294
+ const onClick = (0, import_react5.useCallback)(() => {
1295
+ if (isOpen) {
1296
+ if (inputRef.current) inputRef.current.focus();
1297
+ } else {
1298
+ onOpen();
1299
+ onFocusFirstOrSelected();
1065
1300
  }
1066
- );
1067
- const isEmpty = !childValues.length;
1068
- const [containerProps, groupProps] = (0, import_utils.splitObject)(rest, import_core.layoutStyleProperties);
1069
- const getContainerProps = (0, import_react.useCallback)(
1070
- (props = {}, ref = null) => {
1071
- const style = {
1072
- border: "0px",
1073
- clip: "rect(0px, 0px, 0px, 0px)",
1074
- height: "1px",
1075
- width: "1px",
1076
- margin: "-1px",
1077
- padding: "0px",
1078
- overflow: "hidden",
1079
- whiteSpace: "nowrap",
1080
- position: "absolute"
1081
- };
1082
- return {
1083
- ref,
1084
- ...props,
1085
- ...containerProps,
1086
- style: isEmpty ? style : void 0,
1087
- "data-label": label,
1088
- role: "autocomplete-group-container"
1089
- };
1301
+ }, [isOpen, onFocusFirstOrSelected, onOpen]);
1302
+ const onFocus = (0, import_react5.useCallback)(() => {
1303
+ if (isOpen) return;
1304
+ onOpen();
1305
+ onFocusFirstOrSelected();
1306
+ }, [isOpen, onFocusFirstOrSelected, onOpen]);
1307
+ const onBlur = (0, import_react5.useCallback)(
1308
+ (ev) => {
1309
+ const relatedTarget = (0, import_utils11.getEventRelatedTarget)(ev);
1310
+ if ((0, import_utils11.isContains)(containerRef.current, relatedTarget)) return;
1311
+ if (!closeOnBlur && isHit) return;
1312
+ if (allowFree && !!inputValue) onChange(inputValue, { runRebirth: false });
1313
+ setInputValue("");
1314
+ if (isOpen) onClose();
1090
1315
  },
1091
- [containerProps, isEmpty, label]
1316
+ [closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
1092
1317
  );
1093
- const getGroupProps = (0, import_react.useCallback)(
1094
- (props = {}, ref = null) => ({
1095
- ref,
1096
- ...props,
1097
- ...groupProps,
1098
- "data-label": label,
1099
- role: "autocomplete-group"
1100
- }),
1101
- [groupProps, label]
1318
+ const onDelete = (0, import_react5.useCallback)(() => {
1319
+ if (!isMulti) {
1320
+ onChange("", { forceUpdate: true });
1321
+ } else {
1322
+ onChange(value[value.length - 1]);
1323
+ }
1324
+ if (!isOpen) onFocus();
1325
+ }, [isMulti, isOpen, onChange, onFocus, value]);
1326
+ const onClear = (0, import_react5.useCallback)(
1327
+ (ev) => {
1328
+ ev.stopPropagation();
1329
+ prevValue.current = [];
1330
+ setValue([]);
1331
+ setLabel(void 0);
1332
+ setInputValue("");
1333
+ rebirthOptions();
1334
+ if (isOpen && inputRef.current) inputRef.current.focus();
1335
+ },
1336
+ [isOpen, setLabel, setInputValue, setValue, rebirthOptions]
1102
1337
  );
1103
- return {
1104
- label,
1105
- getContainerProps,
1106
- getGroupProps
1107
- };
1108
- };
1109
- var useAutocompleteOption = (props) => {
1110
- var _a, _b;
1111
- const {
1112
- value,
1113
- omitSelectedValues,
1114
- onChange,
1115
- onChangeLabel,
1116
- focusedIndex,
1117
- setFocusedIndex,
1118
- onClose,
1119
- closeOnSelect: generalCloseOnSelect,
1120
- optionProps,
1121
- inputRef,
1122
- onFocusNext
1123
- } = useAutocompleteContext();
1124
- let {
1125
- icon: customIcon,
1126
- isDisabled,
1127
- isFocusable,
1128
- closeOnSelect: customCloseOnSelect,
1129
- children,
1130
- value: optionValue,
1131
- ...computedProps
1132
- } = { ...optionProps, ...props };
1133
- const trulyDisabled = !!isDisabled && !isFocusable;
1134
- const itemRef = (0, import_react.useRef)(null);
1135
- const { index, register, descendants } = useAutocompleteDescendant({
1136
- disabled: trulyDisabled
1137
- });
1138
- const values = descendants.values();
1139
- const frontValues = values.slice(0, index);
1140
- const isMulti = (0, import_utils.isArray)(value);
1141
- const isDuplicated = !isMulti ? frontValues.some(({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")) : false;
1142
- const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
1143
- const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
1144
- const isFocused = index === focusedIndex;
1145
- const onClick = (0, import_react.useCallback)(
1338
+ const onKeyDown = (0, import_react5.useCallback)(
1146
1339
  (ev) => {
1340
+ if (ev.key === " ") ev.key = ev.code;
1341
+ if (formControlProps.disabled || formControlProps.readOnly) return;
1342
+ if (isComposition.current) return;
1343
+ const enabledDelete = label === inputValue || !inputValue.length;
1344
+ const actions = {
1345
+ ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils11.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
1346
+ ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils11.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
1347
+ Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils11.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
1348
+ Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils11.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
1349
+ if (inputValue) onChange(inputValue);
1350
+ setFocusedIndex(0);
1351
+ } : void 0,
1352
+ Home: isOpen ? onFocusFirst : void 0,
1353
+ End: isOpen ? onFocusLast : void 0,
1354
+ Escape: closeOnEsc ? onClose : void 0,
1355
+ Backspace: !isEmptyValue && enabledDelete ? onDelete : void 0
1356
+ };
1357
+ const action = actions[ev.key];
1358
+ if (!action) return;
1359
+ ev.preventDefault();
1147
1360
  ev.stopPropagation();
1148
- if (isDisabled) {
1149
- if (inputRef.current) inputRef.current.focus();
1150
- return;
1151
- }
1152
- if (!isTargetOption(ev.currentTarget)) {
1153
- if (inputRef.current) inputRef.current.focus();
1154
- return;
1155
- }
1156
- setFocusedIndex(index);
1157
- onChange(optionValue != null ? optionValue : "");
1158
- if (inputRef.current) inputRef.current.focus();
1159
- if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect) onClose();
1160
- if (omitSelectedValues) onFocusNext(index);
1361
+ action(ev);
1161
1362
  },
1162
1363
  [
1364
+ allowFree,
1365
+ formControlProps,
1366
+ label,
1367
+ inputValue,
1368
+ onOpen,
1369
+ isFocused,
1370
+ isMulti,
1371
+ onFocusFirstOrSelected,
1163
1372
  onFocusNext,
1164
- omitSelectedValues,
1165
- isDisabled,
1166
- optionValue,
1167
- setFocusedIndex,
1168
- index,
1169
- onChange,
1170
- customCloseOnSelect,
1171
- generalCloseOnSelect,
1373
+ onFocusLastOrSelected,
1374
+ onFocusPrev,
1375
+ isCreate,
1376
+ onCreate,
1377
+ onSelect,
1378
+ isOpen,
1379
+ onFocusFirst,
1380
+ onFocusLast,
1381
+ closeOnEsc,
1172
1382
  onClose,
1173
- inputRef
1383
+ isEmptyValue,
1384
+ onDelete,
1385
+ onChange
1386
+ ]
1387
+ );
1388
+ (0, import_react5.useEffect)(() => {
1389
+ if (!isMulti) return;
1390
+ if (!omitSelectedValues && (0, import_utils11.isUndefined)(maxSelectValues)) return;
1391
+ const isAll = value.length > 0 && value.length === descendants.count();
1392
+ const isMax = value.length === maxSelectValues;
1393
+ if (isAll || isMax) {
1394
+ onClose();
1395
+ setIsAllSelected(true);
1396
+ } else {
1397
+ setIsAllSelected(false);
1398
+ }
1399
+ }, [
1400
+ omitSelectedValues,
1401
+ value,
1402
+ descendants,
1403
+ isMulti,
1404
+ onClose,
1405
+ maxSelectValues
1406
+ ]);
1407
+ (0, import_react5.useEffect)(() => {
1408
+ var _a;
1409
+ if (isMulti) {
1410
+ if (JSON.stringify((_a = prevValue.current) != null ? _a : []) === JSON.stringify(value != null ? value : []))
1411
+ return;
1412
+ const label2 = getSelectedValues(value);
1413
+ setLabel(label2);
1414
+ } else {
1415
+ if (prevValue.current === value) return;
1416
+ onChangeLabel(value, { runOmit: false });
1417
+ }
1418
+ }, [isMulti, value, onChangeLabel, getSelectedValues]);
1419
+ (0, import_utils11.useUpdateEffect)(() => {
1420
+ if (isOpen || allowFree) return;
1421
+ setFocusedIndex(-1);
1422
+ setInputValue("");
1423
+ }, [isOpen]);
1424
+ (0, import_utils11.useUpdateEffect)(() => {
1425
+ if (!isHit) setFocusedIndex(-2);
1426
+ }, [isHit]);
1427
+ (0, import_utils11.useUpdateEffect)(() => {
1428
+ setResolvedItems(items ? JSON.parse(JSON.stringify(items)) : void 0);
1429
+ }, [items]);
1430
+ (0, import_utils11.useUnmountEffect)(() => {
1431
+ timeoutIds.current.forEach((id2) => clearTimeout(id2));
1432
+ timeoutIds.current.clear();
1433
+ });
1434
+ (0, import_use_outside_click.useOutsideClick)({
1435
+ ref: containerRef,
1436
+ handler: onClose,
1437
+ enabled: isOpen && (closeOnBlur || !isHit)
1438
+ });
1439
+ const getPopoverProps = (0, import_react5.useCallback)(
1440
+ (props2) => ({
1441
+ closeOnBlur,
1442
+ openDelay,
1443
+ closeDelay,
1444
+ isLazy,
1445
+ lazyBehavior,
1446
+ animation,
1447
+ duration,
1448
+ offset,
1449
+ gutter,
1450
+ preventOverflow,
1451
+ flip,
1452
+ matchWidth,
1453
+ boundary,
1454
+ eventListeners,
1455
+ strategy,
1456
+ placement,
1457
+ modifiers,
1458
+ ...props2,
1459
+ trigger: "never",
1460
+ closeOnButton: false,
1461
+ isOpen,
1462
+ onOpen,
1463
+ onClose
1464
+ }),
1465
+ [
1466
+ closeOnBlur,
1467
+ openDelay,
1468
+ closeDelay,
1469
+ isLazy,
1470
+ lazyBehavior,
1471
+ animation,
1472
+ duration,
1473
+ offset,
1474
+ gutter,
1475
+ preventOverflow,
1476
+ flip,
1477
+ matchWidth,
1478
+ boundary,
1479
+ eventListeners,
1480
+ strategy,
1481
+ placement,
1482
+ modifiers,
1483
+ isOpen,
1484
+ onOpen,
1485
+ onClose
1174
1486
  ]
1175
1487
  );
1176
- (0, import_utils.useUpdateEffect)(() => {
1177
- if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", { runOmit: false });
1178
- }, [optionValue]);
1179
- const getOptionProps = (0, import_react.useCallback)(
1180
- (props2 = {}, ref = null) => {
1181
- const style = {
1182
- border: "0px",
1183
- clip: "rect(0px, 0px, 0px, 0px)",
1184
- height: "1px",
1185
- width: "1px",
1186
- margin: "-1px",
1187
- padding: "0px",
1188
- overflow: "hidden",
1189
- whiteSpace: "nowrap",
1190
- position: "absolute"
1191
- };
1192
- return {
1193
- ref: (0, import_utils.mergeRefs)(itemRef, ref, register),
1194
- id: (0, import_react.useId)(),
1195
- role: "option",
1196
- ...computedProps,
1197
- ...props2,
1198
- tabIndex: -1,
1199
- style: !isTarget || omitSelectedValues && isSelected ? style : void 0,
1200
- "data-target": (0, import_utils.dataAttr)(true),
1201
- "data-value": optionValue != null ? optionValue : "",
1202
- "data-focus": (0, import_utils.dataAttr)(isFocused),
1203
- "data-disabled": (0, import_utils.dataAttr)(isDisabled),
1204
- "aria-checked": isSelected,
1205
- "aria-disabled": (0, import_utils.ariaAttr)(isDisabled),
1206
- onClick: (0, import_utils.handlerAll)(computedProps.onClick, props2.onClick, onClick)
1207
- };
1208
- },
1488
+ const getContainerProps = (0, import_react5.useCallback)(
1489
+ (props2 = {}, ref = null) => ({
1490
+ ref: (0, import_utils11.mergeRefs)(containerRef, ref),
1491
+ ...containerProps,
1492
+ ...props2,
1493
+ ...formControlProps,
1494
+ onClick: (0, import_utils11.handlerAll)(props2.onClick, rest.onClick, onClick),
1495
+ onBlur: (0, import_utils11.handlerAll)(props2.onBlur, rest.onBlur, onBlur)
1496
+ }),
1497
+ [containerProps, formControlProps, onBlur, onClick, rest]
1498
+ );
1499
+ const getFieldProps = (0, import_react5.useCallback)(
1500
+ (props2 = {}, ref = null) => ({
1501
+ ref,
1502
+ tabIndex: -1,
1503
+ ...props2,
1504
+ ...formControlProps,
1505
+ placeholder,
1506
+ "data-active": (0, import_utils11.dataAttr)(isOpen),
1507
+ "aria-expanded": (0, import_utils11.dataAttr)(isOpen),
1508
+ onFocus: (0, import_utils11.handlerAll)(props2.onFocus, onFocusProp, onFocus),
1509
+ onKeyDown: (0, import_utils11.handlerAll)(props2.onKeyDown, onKeyDownProp, onKeyDown)
1510
+ }),
1209
1511
  [
1210
- optionValue,
1211
- computedProps,
1212
- isDisabled,
1213
- isFocused,
1214
- isSelected,
1215
- isTarget,
1216
- omitSelectedValues,
1217
- onClick,
1218
- register
1512
+ formControlProps,
1513
+ placeholder,
1514
+ isOpen,
1515
+ onFocusProp,
1516
+ onFocus,
1517
+ onKeyDownProp,
1518
+ onKeyDown
1219
1519
  ]
1220
1520
  );
1221
1521
  return {
1222
- isSelected,
1223
- isFocused,
1224
- customIcon,
1225
- children,
1226
- getOptionProps
1522
+ id,
1523
+ descendants,
1524
+ value,
1525
+ label,
1526
+ inputValue,
1527
+ isHit,
1528
+ isEmpty,
1529
+ computedChildren,
1530
+ focusedIndex,
1531
+ omitSelectedValues,
1532
+ closeOnSelect,
1533
+ allowCreate,
1534
+ allowFree,
1535
+ emptyMessage,
1536
+ isOpen,
1537
+ isAllSelected,
1538
+ listRef,
1539
+ inputRef,
1540
+ optionProps,
1541
+ formControlProps,
1542
+ setFocusedIndex,
1543
+ onChangeLabel,
1544
+ onChange,
1545
+ onSearch,
1546
+ onCreate,
1547
+ onClear,
1548
+ onCompositionStart,
1549
+ onCompositionEnd,
1550
+ pickOptions,
1551
+ rebirthOptions,
1552
+ onOpen,
1553
+ onClose,
1554
+ onFocusFirst,
1555
+ onFocusLast,
1556
+ onFocusSelected,
1557
+ onFocusNext,
1558
+ onFocusPrev,
1559
+ getPopoverProps,
1560
+ getContainerProps,
1561
+ getFieldProps,
1562
+ inputProps
1227
1563
  };
1228
1564
  };
1229
- var useAutocompleteCreate = () => {
1230
- const { isHit, onCreate } = useAutocompleteContext();
1231
- const getCreateProps = (0, import_react.useCallback)(
1232
- (props = {}, ref = null) => {
1233
- const style = {
1234
- border: "0px",
1235
- clip: "rect(0px, 0px, 0px, 0px)",
1236
- height: "1px",
1237
- width: "1px",
1238
- margin: "-1px",
1239
- padding: "0px",
1240
- overflow: "hidden",
1241
- whiteSpace: "nowrap",
1242
- position: "absolute"
1243
- };
1244
- return {
1245
- ref,
1246
- ...props,
1247
- tabIndex: -1,
1248
- style: isHit ? style : void 0,
1249
- "data-focus": (0, import_utils.dataAttr)(!isHit),
1250
- onClick: (0, import_utils.handlerAll)(props.onClick, onCreate)
1251
- };
1252
- },
1253
- [isHit, onCreate]
1254
- );
1255
- return { getCreateProps };
1256
- };
1257
- var useAutocompleteEmpty = () => {
1258
- const { isHit, isEmpty } = useAutocompleteContext();
1259
- const getEmptyProps = (0, import_react.useCallback)(
1565
+ var useAutocompleteInput = () => {
1566
+ const {
1567
+ id,
1568
+ inputRef,
1569
+ onSearch,
1570
+ onCompositionStart,
1571
+ onCompositionEnd,
1572
+ isAllSelected,
1573
+ formControlProps,
1574
+ inputProps,
1575
+ isOpen,
1576
+ focusedIndex,
1577
+ listRef
1578
+ } = useAutocompleteContext();
1579
+ const { value } = useAutocompleteDescendantsContext();
1580
+ (0, import_utils11.useUpdateEffect)(() => {
1581
+ if (isAllSelected && inputRef.current) inputRef.current.blur();
1582
+ }, [isAllSelected]);
1583
+ const getInputProps = (0, import_react5.useCallback)(
1260
1584
  (props = {}, ref = null) => {
1261
- const style = {
1262
- border: "0px",
1263
- clip: "rect(0px, 0px, 0px, 0px)",
1264
- height: "1px",
1265
- width: "1px",
1266
- margin: "-1px",
1267
- padding: "0px",
1268
- overflow: "hidden",
1269
- whiteSpace: "nowrap",
1270
- position: "absolute"
1271
- };
1585
+ var _a, _b;
1272
1586
  return {
1273
- ref,
1587
+ ref: (0, import_utils11.mergeRefs)(inputRef, ref),
1588
+ ...formControlProps,
1589
+ role: "combobox",
1590
+ "aria-haspopup": "listbox",
1591
+ "aria-autocomplete": "list",
1592
+ "aria-expanded": isOpen,
1593
+ "aria-activedescendant": (_a = value(focusedIndex)) == null ? void 0 : _a.node.id,
1594
+ "aria-controls": (_b = listRef.current) == null ? void 0 : _b.id,
1595
+ autoCapitalize: "none",
1596
+ autoComplete: "off",
1597
+ spellCheck: "false",
1598
+ ...inputProps,
1274
1599
  ...props,
1275
- tabIndex: -1,
1276
- style: isHit && !isEmpty ? style : void 0
1600
+ id,
1601
+ cursor: formControlProps.readOnly ? "default" : "text",
1602
+ pointerEvents: formControlProps.disabled || isAllSelected ? "none" : "auto",
1603
+ tabIndex: isAllSelected ? -1 : 0,
1604
+ onChange: (0, import_utils11.handlerAll)(props.onChange, onSearch),
1605
+ onCompositionStart: (0, import_utils11.handlerAll)(
1606
+ props.onCompositionStart,
1607
+ inputProps.onCompositionStart,
1608
+ onCompositionStart
1609
+ ),
1610
+ onCompositionEnd: (0, import_utils11.handlerAll)(
1611
+ props.onCompositionEnd,
1612
+ inputProps.onCompositionEnd,
1613
+ onCompositionEnd
1614
+ )
1277
1615
  };
1278
1616
  },
1279
- [isHit, isEmpty]
1280
- );
1281
- return { getEmptyProps };
1282
- };
1283
-
1284
- // src/autocomplete-icon.tsx
1285
- var import_jsx_runtime2 = require("react/jsx-runtime");
1286
- var AutocompleteIcon = (0, import_core2.forwardRef)(
1287
- ({ className, children, __css, ...rest }, ref) => {
1288
- const { styles } = useAutocompleteContext();
1289
- const css = {
1290
- position: "absolute",
1291
- top: "50%",
1292
- transform: "translateY(-50%)",
1293
- display: "inline-flex",
1294
- alignItems: "center",
1295
- justifyContent: "center",
1296
- pointerEvents: "none",
1297
- cursor: "pointer",
1298
- ...styles.icon,
1299
- ...__css
1300
- };
1301
- const validChildren = (0, import_utils2.getValidChildren)(children);
1302
- const cloneChildren = validChildren.map(
1303
- (child) => (0, import_react2.cloneElement)(child, {
1304
- focusable: false,
1305
- "aria-hidden": true,
1306
- style: {
1307
- maxWidth: "1em",
1308
- maxHeight: "1em",
1309
- color: "currentColor"
1310
- }
1311
- })
1312
- );
1313
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1314
- import_core2.ui.div,
1315
- {
1316
- ref,
1317
- className: (0, import_utils2.cx)("ui-autocomplete__icon", className),
1318
- __css: css,
1319
- ...rest,
1320
- children: (0, import_utils2.isValidElement)(children) ? cloneChildren : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icon.ChevronIcon, {})
1321
- }
1322
- );
1323
- }
1324
- );
1325
- var AutocompleteClearIcon = ({
1326
- className,
1327
- children,
1328
- ...props
1329
- }) => {
1330
- const ref = (0, import_react2.useRef)(null);
1331
- const { styles } = useAutocompleteContext();
1332
- const isDisabled = props.disabled;
1333
- const rest = (0, import_use_clickable.useClickable)({
1334
- ref,
1335
- isDisabled,
1336
- ...props
1337
- });
1338
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1339
- AutocompleteIcon,
1340
- {
1341
- "aria-label": "Clear value",
1342
- className: (0, import_utils2.cx)("ui-autocomplete__icon--clear", className),
1343
- __css: styles.clearIcon,
1344
- ...rest,
1345
- children: children != null ? children : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_icon.CloseIcon, { w: "0.5em", h: "0.5em" })
1346
- }
1617
+ [
1618
+ listRef,
1619
+ focusedIndex,
1620
+ isOpen,
1621
+ inputProps,
1622
+ inputRef,
1623
+ formControlProps,
1624
+ id,
1625
+ isAllSelected,
1626
+ value,
1627
+ onSearch,
1628
+ onCompositionStart,
1629
+ onCompositionEnd
1630
+ ]
1347
1631
  );
1348
- };
1349
- var AutocompleteItemIcon = (0, import_core2.forwardRef)(({ className, ...rest }, ref) => {
1350
- const { styles } = useAutocompleteContext();
1351
- const css = {
1352
- flexShrink: 0,
1353
- display: "inline-flex",
1354
- justifyContent: "center",
1355
- alignItems: "center",
1356
- fontSize: "0.85em",
1357
- ...styles.itemIcon
1632
+ return {
1633
+ getInputProps
1358
1634
  };
1359
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
1360
- import_core2.ui.span,
1361
- {
1362
- ref,
1363
- className: (0, import_utils2.cx)("ui-autocomplete__item__icon", className),
1364
- __css: css,
1365
- ...rest
1366
- }
1367
- );
1368
- });
1369
-
1370
- // src/autocomplete-list.tsx
1371
- var import_core3 = require("@yamada-ui/core");
1372
- var import_popover = require("@yamada-ui/popover");
1373
- var import_utils3 = require("@yamada-ui/utils");
1374
- var import_jsx_runtime3 = require("react/jsx-runtime");
1375
- var AutocompleteList = (0, import_core3.forwardRef)(
1376
- ({
1377
- className,
1378
- w,
1379
- width,
1380
- minW,
1381
- minWidth,
1382
- maxW,
1383
- maxWidth,
1384
- contentProps,
1385
- header,
1386
- footer,
1387
- children,
1388
- ...rest
1389
- }, ref) => {
1390
- var _a, _b, _c, _d, _e, _f, _g, _h, _i;
1391
- const { styles } = useAutocompleteContext();
1392
- const { onAnimationComplete, getListProps } = useAutocompleteList();
1393
- width != null ? width : width = w;
1394
- width != null ? width : width = (_c = (_a = styles.list) == null ? void 0 : _a.width) != null ? _c : (_b = styles.list) == null ? void 0 : _b.w;
1395
- minWidth != null ? minWidth : minWidth = minW;
1396
- minWidth != null ? minWidth : minWidth = (_f = (_d = styles.list) == null ? void 0 : _d.minWidth) != null ? _f : (_e = styles.list) == null ? void 0 : _e.minW;
1397
- maxWidth != null ? maxWidth : maxWidth = maxW;
1398
- maxWidth != null ? maxWidth : maxWidth = (_i = (_g = styles.list) == null ? void 0 : _g.maxWidth) != null ? _i : (_h = styles.list) == null ? void 0 : _h.maxW;
1399
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1400
- import_popover.PopoverContent,
1401
- {
1402
- as: "div",
1403
- className: "ui-autocomplete__popover",
1404
- width,
1405
- minWidth,
1406
- maxWidth,
1407
- __css: { ...styles.content, width, minWidth, maxWidth },
1408
- ...contentProps,
1409
- onAnimationComplete: (0, import_utils3.handlerAll)(
1410
- contentProps == null ? void 0 : contentProps.onAnimationComplete,
1411
- onAnimationComplete
1412
- ),
1413
- children: [
1414
- header ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1415
- import_core3.ui.div,
1416
- {
1417
- className: "ui-autocomplete__header",
1418
- __css: { ...styles.header },
1419
- children: header
1420
- }
1421
- ) : null,
1422
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1423
- import_core3.ui.ul,
1424
- {
1425
- className: (0, import_utils3.cx)("ui-autocomplete__list", className),
1426
- __css: { ...styles.list },
1427
- ...getListProps(rest, ref),
1428
- children
1429
- }
1430
- ),
1431
- footer ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1432
- import_core3.ui.div,
1433
- {
1434
- className: "ui-autocomplete__footer",
1435
- __css: { ...styles.footer },
1436
- children: footer
1437
- }
1438
- ) : null
1439
- ]
1440
- }
1441
- );
1442
- }
1443
- );
1635
+ };
1444
1636
 
1445
1637
  // src/autocomplete.tsx
1446
- var import_jsx_runtime4 = require("react/jsx-runtime");
1447
- var Autocomplete = (0, import_core4.forwardRef)(
1638
+ var import_jsx_runtime8 = require("react/jsx-runtime");
1639
+ var Autocomplete = (0, import_core9.forwardRef)(
1448
1640
  (props, ref) => {
1449
- const [styles, mergedProps] = (0, import_core4.useMultiComponentStyle)("Autocomplete", props);
1641
+ const [styles, mergedProps] = (0, import_core9.useComponentMultiStyle)("Autocomplete", props);
1450
1642
  let {
1451
1643
  className,
1452
1644
  defaultValue = "",
@@ -1468,7 +1660,7 @@ var Autocomplete = (0, import_core4.forwardRef)(
1468
1660
  footer,
1469
1661
  children,
1470
1662
  ...computedProps
1471
- } = (0, import_core4.omitThemeProps)(mergedProps);
1663
+ } = (0, import_core9.omitThemeProps)(mergedProps);
1472
1664
  const {
1473
1665
  value,
1474
1666
  onClose,
@@ -1491,7 +1683,7 @@ var Autocomplete = (0, import_core4.forwardRef)(
1491
1683
  color,
1492
1684
  ...styles.container
1493
1685
  };
1494
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteDescendantsContextProvider, { value: descendants, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1686
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteDescendantsContextProvider, { value: descendants, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1495
1687
  AutocompleteProvider,
1496
1688
  {
1497
1689
  value: {
@@ -1504,20 +1696,20 @@ var Autocomplete = (0, import_core4.forwardRef)(
1504
1696
  isEmpty,
1505
1697
  styles
1506
1698
  },
1507
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_popover2.Popover, { ...getPopoverProps(), children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1508
- import_core4.ui.div,
1699
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_popover2.Popover, { ...getPopoverProps(), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1700
+ import_core9.ui.div,
1509
1701
  {
1510
- className: (0, import_utils4.cx)("ui-autocomplete", className),
1702
+ className: (0, import_utils12.cx)("ui-autocomplete", className),
1511
1703
  __css: css,
1512
1704
  ...getContainerProps(containerProps),
1513
1705
  children: [
1514
- /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1515
- import_core4.ui.div,
1706
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1707
+ import_core9.ui.div,
1516
1708
  {
1517
1709
  className: "ui-autocomplete__inner",
1518
1710
  __css: { position: "relative", ...styles.inner },
1519
1711
  children: [
1520
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1712
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1521
1713
  AutocompleteField,
1522
1714
  {
1523
1715
  h,
@@ -1526,30 +1718,30 @@ var Autocomplete = (0, import_core4.forwardRef)(
1526
1718
  ...getFieldProps(fieldProps, ref)
1527
1719
  }
1528
1720
  ),
1529
- /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteIcon, { ...iconProps, ...formControlProps })
1721
+ /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteIcon, { ...iconProps, ...formControlProps })
1530
1722
  ]
1531
1723
  }
1532
1724
  ),
1533
- !isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_portal.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
1725
+ !isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_portal.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1534
1726
  AutocompleteList,
1535
1727
  {
1536
- header: (0, import_utils4.runIfFunc)(header, { value, onClose }),
1537
- footer: (0, import_utils4.runIfFunc)(footer, { value, onClose }),
1728
+ header: (0, import_utils12.runIfFunc)(header, { value, onClose }),
1729
+ footer: (0, import_utils12.runIfFunc)(footer, { value, onClose }),
1538
1730
  contentProps,
1539
1731
  ...listProps,
1540
1732
  children: [
1541
- allowCreate ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteEmpty, { ...emptyProps }),
1733
+ allowCreate ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteEmpty, { ...emptyProps }),
1542
1734
  children != null ? children : computedChildren
1543
1735
  ]
1544
1736
  }
1545
- ) }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_portal.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1737
+ ) }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_portal.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1546
1738
  AutocompleteList,
1547
1739
  {
1548
- header: (0, import_utils4.runIfFunc)(header, { value, onClose }),
1549
- footer: (0, import_utils4.runIfFunc)(footer, { value, onClose }),
1740
+ header: (0, import_utils12.runIfFunc)(header, { value, onClose }),
1741
+ footer: (0, import_utils12.runIfFunc)(footer, { value, onClose }),
1550
1742
  contentProps,
1551
1743
  ...listProps,
1552
- children: allowCreate && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteEmpty, { ...emptyProps })
1744
+ children: allowCreate && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteEmpty, { ...emptyProps })
1553
1745
  }
1554
1746
  ) })
1555
1747
  ]
@@ -1559,7 +1751,7 @@ var Autocomplete = (0, import_core4.forwardRef)(
1559
1751
  ) });
1560
1752
  }
1561
1753
  );
1562
- var AutocompleteField = (0, import_core4.forwardRef)(
1754
+ var AutocompleteField = (0, import_core9.forwardRef)(
1563
1755
  ({ className, h, minH, placeholder, inputProps, ...rest }, ref) => {
1564
1756
  const { label, inputValue, styles } = useAutocompleteContext();
1565
1757
  const { getInputProps } = useAutocompleteInput();
@@ -1572,14 +1764,14 @@ var AutocompleteField = (0, import_core4.forwardRef)(
1572
1764
  ...styles.field,
1573
1765
  cursor: "text"
1574
1766
  };
1575
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_popover2.PopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1576
- import_core4.ui.div,
1767
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_popover2.PopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1768
+ import_core9.ui.div,
1577
1769
  {
1578
- className: (0, import_utils4.cx)("ui-autocomplete__field", className),
1770
+ className: (0, import_utils12.cx)("ui-autocomplete__field", className),
1579
1771
  __css: css,
1580
1772
  ...rest,
1581
- children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
1582
- import_core4.ui.input,
1773
+ children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1774
+ import_core9.ui.input,
1583
1775
  {
1584
1776
  className: "ui-autocomplete__field__input",
1585
1777
  display: "inline-block",
@@ -1596,194 +1788,16 @@ var AutocompleteField = (0, import_core4.forwardRef)(
1596
1788
  }
1597
1789
  );
1598
1790
 
1599
- // src/autocomplete-option-group.tsx
1600
- var import_core5 = require("@yamada-ui/core");
1601
- var import_utils5 = require("@yamada-ui/utils");
1602
- var import_jsx_runtime5 = require("react/jsx-runtime");
1603
- var AutocompleteOptionGroup = (0, import_core5.forwardRef)(
1604
- ({ className, color, h, height, minH, minHeight, children, ...rest }, ref) => {
1605
- const { styles } = useAutocompleteContext();
1606
- const { label, getContainerProps, getGroupProps } = useAutocompleteOptionGroup(rest);
1607
- h != null ? h : h = height;
1608
- minH != null ? minH : minH = minHeight;
1609
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
1610
- import_core5.ui.li,
1611
- {
1612
- className: (0, import_utils5.cx)(
1613
- "ui-autocomplete__item",
1614
- "ui-autocomplete__item--group",
1615
- className
1616
- ),
1617
- __css: { w: "100%", h: "fit-content", color },
1618
- ...getContainerProps(),
1619
- children: [
1620
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1621
- import_core5.ui.span,
1622
- {
1623
- className: "ui-autocomplete__item__group-label",
1624
- __css: styles.groupLabel,
1625
- lineClamp: 1,
1626
- children: label
1627
- }
1628
- ),
1629
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
1630
- import_core5.ui.ul,
1631
- {
1632
- ...getGroupProps({}, ref),
1633
- className: "ui-autocomplete__item__group",
1634
- __css: { h, minH, ...styles.group },
1635
- children
1636
- }
1637
- )
1638
- ]
1639
- }
1640
- );
1641
- }
1642
- );
1643
-
1644
- // src/autocomplete-option.tsx
1645
- var import_core6 = require("@yamada-ui/core");
1646
- var import_utils6 = require("@yamada-ui/utils");
1647
- var import_jsx_runtime6 = require("react/jsx-runtime");
1648
- var AutocompleteOption = (0, import_core6.forwardRef)(
1649
- ({ className, icon, ...rest }, ref) => {
1650
- const { styles } = useAutocompleteContext();
1651
- const { isSelected, customIcon, children, getOptionProps } = useAutocompleteOption(rest);
1652
- icon != null ? icon : icon = customIcon;
1653
- const css = {
1654
- textDecoration: "none",
1655
- color: "inherit",
1656
- userSelect: "none",
1657
- display: "flex",
1658
- width: "100%",
1659
- alignItems: "center",
1660
- textAlign: "start",
1661
- flex: "0 0 auto",
1662
- outline: 0,
1663
- gap: "0.75rem",
1664
- ...styles.item
1665
- };
1666
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
1667
- import_core6.ui.li,
1668
- {
1669
- className: (0, import_utils6.cx)("ui-autocomplete__item", className),
1670
- __css: css,
1671
- ...getOptionProps({}, ref),
1672
- children: [
1673
- icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AutocompleteItemIcon, { opacity: isSelected ? 1 : 0, children: icon || /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(CheckIcon, {}) }) : null,
1674
- /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_core6.ui.span, { style: { flex: 1 }, "data-label": true, children })
1675
- ]
1676
- }
1677
- );
1678
- }
1679
- );
1680
- var CheckIcon = () => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("svg", { viewBox: "0 0 14 14", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
1681
- "polygon",
1682
- {
1683
- fill: "currentColor",
1684
- points: "5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039"
1685
- }
1686
- ) });
1687
-
1688
- // src/autocomplete-create.tsx
1689
- var import_core7 = require("@yamada-ui/core");
1690
- var import_utils7 = require("@yamada-ui/utils");
1691
- var import_jsx_runtime7 = require("react/jsx-runtime");
1692
- var AutocompleteCreate = (0, import_core7.forwardRef)(
1693
- ({ className, icon, children, ...rest }, ref) => {
1694
- const { inputValue, styles } = useAutocompleteContext();
1695
- const { getCreateProps } = useAutocompleteCreate();
1696
- children != null ? children : children = inputValue;
1697
- const css = {
1698
- textDecoration: "none",
1699
- color: "inherit",
1700
- userSelect: "none",
1701
- display: "flex",
1702
- width: "100%",
1703
- alignItems: "center",
1704
- textAlign: "start",
1705
- flex: "0 0 auto",
1706
- outline: 0,
1707
- gap: "0.75rem",
1708
- ...styles.item
1709
- };
1710
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
1711
- import_core7.ui.li,
1712
- {
1713
- className: (0, import_utils7.cx)("ui-autocomplete__item--create", className),
1714
- __css: css,
1715
- ...getCreateProps(rest, ref),
1716
- children: [
1717
- icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AutocompleteItemIcon, { children: icon || /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PlusIcon, {}) }) : null,
1718
- icon ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_core7.ui.span, { style: { pointerEvents: "none", flex: 1 }, lineClamp: 1, children: (0, import_utils7.runIfFunc)(children, inputValue) }) : (0, import_utils7.runIfFunc)(children, inputValue)
1719
- ]
1720
- }
1721
- );
1722
- }
1723
- );
1724
- var PlusIcon = () => /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("svg", { viewBox: "0 0 45.402 45.402", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1725
- "path",
1726
- {
1727
- fill: "currentColor",
1728
- d: "M41.267,18.557H26.832V4.134C26.832,1.851,24.99,0,22.707,0c-2.283,0-4.124,1.851-4.124,4.135v14.432H4.141 c-2.283,0-4.139,1.851-4.138,4.135c-0.001,1.141,0.46,2.187,1.207,2.934c0.748,0.749,1.78,1.222,2.92,1.222h14.453V41.27 c0,1.142,0.453,2.176,1.201,2.922c0.748,0.748,1.777,1.211,2.919,1.211c2.282,0,4.129-1.851,4.129-4.133V26.857h14.435 c2.283,0,4.134-1.867,4.133-4.15C45.399,20.425,43.548,18.557,41.267,18.557z"
1729
- }
1730
- ) });
1731
-
1732
- // src/autocomplete-empty.tsx
1733
- var import_core8 = require("@yamada-ui/core");
1734
- var import_utils8 = require("@yamada-ui/utils");
1735
- var import_jsx_runtime8 = require("react/jsx-runtime");
1736
- var AutocompleteEmpty = (0, import_core8.forwardRef)(
1737
- ({ className, icon, children, ...rest }, ref) => {
1738
- const { emptyMessage, styles } = useAutocompleteContext();
1739
- const { getEmptyProps } = useAutocompleteEmpty();
1740
- children != null ? children : children = emptyMessage;
1741
- const css = {
1742
- textDecoration: "none",
1743
- color: "inherit",
1744
- userSelect: "none",
1745
- display: "flex",
1746
- width: "100%",
1747
- alignItems: "center",
1748
- textAlign: "start",
1749
- flex: "0 0 auto",
1750
- outline: 0,
1751
- gap: "0.75rem",
1752
- pointerEvents: "none",
1753
- ...styles.item
1754
- };
1755
- return /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1756
- import_core8.ui.li,
1757
- {
1758
- className: (0, import_utils8.cx)("ui-autocomplete__item--empty", className),
1759
- __css: css,
1760
- ...getEmptyProps(rest, ref),
1761
- children: [
1762
- icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteItemIcon, { children: icon || /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(MinusIcon, {}) }) : null,
1763
- icon ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_core8.ui.span, { style: { pointerEvents: "none", flex: 1 }, lineClamp: 1, children }) : children
1764
- ]
1765
- }
1766
- );
1767
- }
1768
- );
1769
- var MinusIcon = () => /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("svg", { viewBox: "0 0 448 512", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1770
- "path",
1771
- {
1772
- fill: "currentColor",
1773
- d: "M432 256c0 17.7-14.3 32-32 32L48 288c-17.7 0-32-14.3-32-32s14.3-32 32-32l352 0c17.7 0 32 14.3 32 32z"
1774
- }
1775
- ) });
1776
-
1777
1791
  // src/multi-autocomplete.tsx
1778
- var import_core9 = require("@yamada-ui/core");
1792
+ var import_core10 = require("@yamada-ui/core");
1779
1793
  var import_popover3 = require("@yamada-ui/popover");
1780
1794
  var import_portal2 = require("@yamada-ui/portal");
1781
- var import_utils9 = require("@yamada-ui/utils");
1782
- var import_react3 = require("react");
1795
+ var import_utils13 = require("@yamada-ui/utils");
1796
+ var import_react6 = require("react");
1783
1797
  var import_jsx_runtime9 = require("react/jsx-runtime");
1784
- var MultiAutocomplete = (0, import_core9.forwardRef)(
1798
+ var MultiAutocomplete = (0, import_core10.forwardRef)(
1785
1799
  (props, ref) => {
1786
- const [styles, mergedProps] = (0, import_core9.useMultiComponentStyle)(
1800
+ const [styles, mergedProps] = (0, import_core10.useComponentMultiStyle)(
1787
1801
  "MultiAutocomplete",
1788
1802
  props
1789
1803
  );
@@ -1814,7 +1828,7 @@ var MultiAutocomplete = (0, import_core9.forwardRef)(
1814
1828
  footer,
1815
1829
  children,
1816
1830
  ...computedProps
1817
- } = (0, import_core9.omitThemeProps)(mergedProps);
1831
+ } = (0, import_core10.omitThemeProps)(mergedProps);
1818
1832
  const {
1819
1833
  value,
1820
1834
  onClose,
@@ -1857,14 +1871,14 @@ var MultiAutocomplete = (0, import_core9.forwardRef)(
1857
1871
  styles
1858
1872
  },
1859
1873
  children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_popover3.Popover, { ...getPopoverProps(), children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1860
- import_core9.ui.div,
1874
+ import_core10.ui.div,
1861
1875
  {
1862
- className: (0, import_utils9.cx)("ui-multi-autocomplete", className),
1876
+ className: (0, import_utils13.cx)("ui-multi-autocomplete", className),
1863
1877
  __css: css,
1864
1878
  ...getContainerProps(containerProps),
1865
1879
  children: [
1866
1880
  /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1867
- import_core9.ui.div,
1881
+ import_core10.ui.div,
1868
1882
  {
1869
1883
  className: "ui-multi-autocomplete__inner",
1870
1884
  __css: { position: "relative", ...styles.inner },
@@ -1885,7 +1899,7 @@ var MultiAutocomplete = (0, import_core9.forwardRef)(
1885
1899
  AutocompleteClearIcon,
1886
1900
  {
1887
1901
  ...clearIconProps,
1888
- onClick: (0, import_utils9.handlerAll)(clearIconProps == null ? void 0 : clearIconProps.onClick, onClear),
1902
+ onClick: (0, import_utils13.handlerAll)(clearIconProps == null ? void 0 : clearIconProps.onClick, onClear),
1889
1903
  ...formControlProps
1890
1904
  }
1891
1905
  ) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteIcon, { ...iconProps, ...formControlProps })
@@ -1895,8 +1909,8 @@ var MultiAutocomplete = (0, import_core9.forwardRef)(
1895
1909
  !isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_portal2.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1896
1910
  AutocompleteList,
1897
1911
  {
1898
- header: (0, import_utils9.runIfFunc)(header, { value, onClose }),
1899
- footer: (0, import_utils9.runIfFunc)(footer, { value, onClose }),
1912
+ header: (0, import_utils13.runIfFunc)(header, { value, onClose }),
1913
+ footer: (0, import_utils13.runIfFunc)(footer, { value, onClose }),
1900
1914
  contentProps,
1901
1915
  ...listProps,
1902
1916
  children: [
@@ -1907,8 +1921,8 @@ var MultiAutocomplete = (0, import_core9.forwardRef)(
1907
1921
  ) }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_portal2.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1908
1922
  AutocompleteList,
1909
1923
  {
1910
- header: (0, import_utils9.runIfFunc)(header, { value, onClose }),
1911
- footer: (0, import_utils9.runIfFunc)(footer, { value, onClose }),
1924
+ header: (0, import_utils13.runIfFunc)(header, { value, onClose }),
1925
+ footer: (0, import_utils13.runIfFunc)(footer, { value, onClose }),
1912
1926
  contentProps,
1913
1927
  ...listProps,
1914
1928
  children: allowCreate && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(AutocompleteEmpty, { ...emptyProps })
@@ -1921,7 +1935,7 @@ var MultiAutocomplete = (0, import_core9.forwardRef)(
1921
1935
  ) });
1922
1936
  }
1923
1937
  );
1924
- var MultiAutocompleteField = (0, import_core9.forwardRef)(
1938
+ var MultiAutocompleteField = (0, import_core10.forwardRef)(
1925
1939
  ({
1926
1940
  className,
1927
1941
  component,
@@ -1935,7 +1949,7 @@ var MultiAutocompleteField = (0, import_core9.forwardRef)(
1935
1949
  }, ref) => {
1936
1950
  const { value, label, inputValue, onChange, isOpen, inputRef, styles } = useAutocompleteContext();
1937
1951
  const { getInputProps } = useAutocompleteInput();
1938
- const cloneChildren = (0, import_react3.useMemo)(() => {
1952
+ const cloneChildren = (0, import_react6.useMemo)(() => {
1939
1953
  if (!(label == null ? void 0 : label.length)) return null;
1940
1954
  if (component) {
1941
1955
  return label.map((label2, index) => {
@@ -1955,12 +1969,12 @@ var MultiAutocompleteField = (0, import_core9.forwardRef)(
1955
1969
  marginBlockEnd: "0.125rem",
1956
1970
  marginInlineEnd: "0.25rem"
1957
1971
  };
1958
- return el ? (0, import_react3.cloneElement)(el, { key: index, style }) : null;
1972
+ return el ? (0, import_react6.cloneElement)(el, { key: index, style }) : null;
1959
1973
  });
1960
1974
  } else {
1961
1975
  return label.map((value2, index) => {
1962
1976
  const isLast = label.length === index + 1;
1963
- return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_core9.ui.span, { display: "inline-block", me: "0.25rem", children: [
1977
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(import_core10.ui.span, { display: "inline-block", me: "0.25rem", children: [
1964
1978
  value2,
1965
1979
  !isLast || isOpen ? separator : null
1966
1980
  ] }, index);
@@ -1978,16 +1992,16 @@ var MultiAutocompleteField = (0, import_core9.forwardRef)(
1978
1992
  cursor: "text"
1979
1993
  };
1980
1994
  return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_popover3.PopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
1981
- import_core9.ui.div,
1995
+ import_core10.ui.div,
1982
1996
  {
1983
- className: (0, import_utils9.cx)("ui-multi-autocomplete__field", className),
1997
+ className: (0, import_utils13.cx)("ui-multi-autocomplete__field", className),
1984
1998
  __css: css,
1985
1999
  py: (label == null ? void 0 : label.length) && component ? "0.125rem" : void 0,
1986
2000
  ...rest,
1987
2001
  children: [
1988
2002
  cloneChildren,
1989
2003
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
1990
- import_core9.ui.input,
2004
+ import_core10.ui.input,
1991
2005
  {
1992
2006
  "aria-label": "Input value",
1993
2007
  className: "ui-multi-autocomplete__field__input",