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