@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,212 +24,431 @@ __export(autocomplete_exports, {
24
24
  Autocomplete: () => Autocomplete
25
25
  });
26
26
  module.exports = __toCommonJS(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
-
32
- // src/autocomplete-icon.tsx
33
- var import_core7 = require("@yamada-ui/core");
34
- var import_icon = require("@yamada-ui/icon");
35
- var import_use_clickable = require("@yamada-ui/use-clickable");
36
- var import_utils7 = require("@yamada-ui/utils");
37
- var import_react2 = require("react");
30
+ var import_utils12 = require("@yamada-ui/utils");
38
31
 
39
- // src/use-autocomplete.tsx
40
- var import_core6 = require("@yamada-ui/core");
41
- var import_form_control = require("@yamada-ui/form-control");
42
- var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
32
+ // src/autocomplete-context.ts
43
33
  var import_use_descendant = require("@yamada-ui/use-descendant");
44
- var import_use_disclosure = require("@yamada-ui/use-disclosure");
45
- var import_use_outside_click = require("@yamada-ui/use-outside-click");
46
- var import_utils6 = require("@yamada-ui/utils");
47
- var import_react = require("react");
48
-
49
- // src/autocomplete-option-group.tsx
50
- var import_core = require("@yamada-ui/core");
51
34
  var import_utils = require("@yamada-ui/utils");
52
- var import_jsx_runtime = require("react/jsx-runtime");
53
- var AutocompleteOptionGroup = (0, import_core.forwardRef)(
54
- ({ className, color, h, height, minH, minHeight, children, ...rest }, ref) => {
55
- const { styles } = useAutocompleteContext();
56
- const { label, getContainerProps, getGroupProps } = useAutocompleteOptionGroup(rest);
57
- h != null ? h : h = height;
58
- minH != null ? minH : minH = minHeight;
59
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
60
- import_core.ui.li,
61
- {
62
- className: (0, import_utils.cx)(
63
- "ui-autocomplete__item",
64
- "ui-autocomplete__item--group",
65
- className
66
- ),
67
- __css: { w: "100%", h: "fit-content", color },
68
- ...getContainerProps(),
69
- children: [
70
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
71
- import_core.ui.span,
72
- {
73
- className: "ui-autocomplete__item__group-label",
74
- __css: styles.groupLabel,
75
- lineClamp: 1,
76
- children: label
77
- }
78
- ),
79
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
80
- import_core.ui.ul,
81
- {
82
- ...getGroupProps({}, ref),
83
- className: "ui-autocomplete__item__group",
84
- __css: { h, minH, ...styles.group },
85
- children
86
- }
87
- )
88
- ]
89
- }
90
- );
91
- }
92
- );
35
+ var {
36
+ DescendantsContextProvider: AutocompleteDescendantsContextProvider,
37
+ useDescendantsContext: useAutocompleteDescendantsContext,
38
+ useDescendants: useAutocompleteDescendants,
39
+ useDescendant: useAutocompleteDescendant
40
+ } = (0, import_use_descendant.createDescendant)();
41
+ var [AutocompleteProvider, useAutocompleteContext] = (0, import_utils.createContext)({
42
+ name: "AutocompleteContext",
43
+ errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in "<Autocomplete />" or "<MultiAutocomplete />"`
44
+ });
93
45
 
94
- // src/autocomplete-option.tsx
46
+ // src/autocomplete-create.tsx
95
47
  var import_core2 = require("@yamada-ui/core");
48
+ var import_utils4 = require("@yamada-ui/utils");
49
+
50
+ // src/autocomplete-icon.tsx
51
+ var import_core = require("@yamada-ui/core");
52
+ var import_icon = require("@yamada-ui/icon");
53
+ var import_use_clickable = require("@yamada-ui/use-clickable");
96
54
  var import_utils2 = require("@yamada-ui/utils");
97
- var import_jsx_runtime2 = require("react/jsx-runtime");
98
- var AutocompleteOption = (0, import_core2.forwardRef)(
99
- ({ className, icon, ...rest }, ref) => {
55
+ var import_react = require("react");
56
+ var import_jsx_runtime = require("react/jsx-runtime");
57
+ var AutocompleteIcon = (0, import_core.forwardRef)(
58
+ ({ className, children, __css, ...rest }, ref) => {
100
59
  const { styles } = useAutocompleteContext();
101
- const { isSelected, customIcon, children, getOptionProps } = useAutocompleteOption(rest);
102
- icon != null ? icon : icon = customIcon;
103
60
  const css = {
104
- textDecoration: "none",
105
- color: "inherit",
106
- userSelect: "none",
107
- display: "flex",
108
- width: "100%",
61
+ position: "absolute",
62
+ top: "50%",
63
+ transform: "translateY(-50%)",
64
+ display: "inline-flex",
109
65
  alignItems: "center",
110
- textAlign: "start",
111
- flex: "0 0 auto",
112
- outline: 0,
113
- gap: "0.75rem",
114
- ...styles.item
66
+ justifyContent: "center",
67
+ pointerEvents: "none",
68
+ cursor: "pointer",
69
+ ...styles.icon,
70
+ ...__css
115
71
  };
116
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
117
- import_core2.ui.li,
72
+ const validChildren = (0, import_utils2.getValidChildren)(children);
73
+ const cloneChildren = validChildren.map(
74
+ (child) => (0, import_react.cloneElement)(child, {
75
+ focusable: false,
76
+ "aria-hidden": true,
77
+ style: {
78
+ maxWidth: "1em",
79
+ maxHeight: "1em",
80
+ color: "currentColor"
81
+ }
82
+ })
83
+ );
84
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
85
+ import_core.ui.div,
118
86
  {
119
- className: (0, import_utils2.cx)("ui-autocomplete__item", className),
87
+ ref,
88
+ className: (0, import_utils2.cx)("ui-autocomplete__icon", className),
120
89
  __css: css,
121
- ...getOptionProps({}, ref),
122
- children: [
123
- icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AutocompleteItemIcon, { opacity: isSelected ? 1 : 0, children: icon || /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(CheckIcon, {}) }) : null,
124
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_core2.ui.span, { style: { flex: 1 }, "data-label": true, children })
125
- ]
90
+ ...rest,
91
+ children: (0, import_utils2.isValidElement)(children) ? cloneChildren : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.ChevronIcon, {})
126
92
  }
127
93
  );
128
94
  }
129
95
  );
130
- var CheckIcon = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { viewBox: "0 0 14 14", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
131
- "polygon",
132
- {
133
- fill: "currentColor",
134
- points: "5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039"
135
- }
136
- ) });
96
+ var AutocompleteItemIcon = (0, import_core.forwardRef)(({ className, ...rest }, ref) => {
97
+ const { styles } = useAutocompleteContext();
98
+ const css = {
99
+ flexShrink: 0,
100
+ display: "inline-flex",
101
+ justifyContent: "center",
102
+ alignItems: "center",
103
+ fontSize: "0.85em",
104
+ ...styles.itemIcon
105
+ };
106
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
107
+ import_core.ui.span,
108
+ {
109
+ ref,
110
+ className: (0, import_utils2.cx)("ui-autocomplete__item__icon", className),
111
+ __css: css,
112
+ ...rest
113
+ }
114
+ );
115
+ });
137
116
 
138
- // src/autocomplete-create.tsx
139
- var import_core3 = require("@yamada-ui/core");
117
+ // src/use-autocomplete-option.ts
140
118
  var import_utils3 = require("@yamada-ui/utils");
141
- var import_jsx_runtime3 = require("react/jsx-runtime");
142
- var AutocompleteCreate = (0, import_core3.forwardRef)(
143
- ({ className, icon, children, ...rest }, ref) => {
144
- const { inputValue, styles } = useAutocompleteContext();
145
- const { getCreateProps } = useAutocompleteCreate();
146
- children != null ? children : children = inputValue;
147
- const css = {
148
- textDecoration: "none",
149
- color: "inherit",
150
- userSelect: "none",
151
- display: "flex",
152
- width: "100%",
153
- alignItems: "center",
154
- textAlign: "start",
155
- flex: "0 0 auto",
156
- outline: 0,
157
- gap: "0.75rem",
158
- ...styles.item
159
- };
160
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
161
- import_core3.ui.li,
162
- {
163
- className: (0, import_utils3.cx)("ui-autocomplete__item--create", className),
164
- __css: css,
165
- ...getCreateProps(rest, ref),
166
- children: [
167
- icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AutocompleteItemIcon, { children: icon || /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PlusIcon, {}) }) : null,
168
- icon ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core3.ui.span, { style: { pointerEvents: "none", flex: 1 }, lineClamp: 1, children: (0, import_utils3.runIfFunc)(children, inputValue) }) : (0, import_utils3.runIfFunc)(children, inputValue)
169
- ]
119
+ var import_react2 = require("react");
120
+ var isTargetOption = (target) => {
121
+ var _a;
122
+ return (0, import_utils3.isHTMLElement)(target) && !!((_a = target == null ? void 0 : target.getAttribute("role")) == null ? void 0 : _a.startsWith("option"));
123
+ };
124
+ var useAutocompleteOption = (props) => {
125
+ var _a, _b;
126
+ const {
127
+ value,
128
+ omitSelectedValues,
129
+ onChange,
130
+ onChangeLabel,
131
+ focusedIndex,
132
+ setFocusedIndex,
133
+ onClose,
134
+ closeOnSelect: generalCloseOnSelect,
135
+ optionProps,
136
+ inputRef,
137
+ onFocusNext
138
+ } = useAutocompleteContext();
139
+ let {
140
+ icon: customIcon,
141
+ isDisabled,
142
+ isFocusable,
143
+ closeOnSelect: customCloseOnSelect,
144
+ children,
145
+ value: optionValue,
146
+ ...computedProps
147
+ } = { ...optionProps, ...props };
148
+ const trulyDisabled = !!isDisabled && !isFocusable;
149
+ const itemRef = (0, import_react2.useRef)(null);
150
+ const { index, register, descendants } = useAutocompleteDescendant({
151
+ disabled: trulyDisabled
152
+ });
153
+ const values = descendants.values();
154
+ const frontValues = values.slice(0, index);
155
+ const isMulti = (0, import_utils3.isArray)(value);
156
+ const isDuplicated = !isMulti ? frontValues.some(({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")) : false;
157
+ const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
158
+ const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
159
+ const isFocused = index === focusedIndex;
160
+ const onClick = (0, import_react2.useCallback)(
161
+ (ev) => {
162
+ ev.stopPropagation();
163
+ if (isDisabled) {
164
+ if (inputRef.current) inputRef.current.focus();
165
+ return;
170
166
  }
171
- );
172
- }
173
- );
174
- var PlusIcon = () => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("svg", { viewBox: "0 0 45.402 45.402", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
175
- "path",
176
- {
177
- fill: "currentColor",
178
- 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"
179
- }
180
- ) });
181
-
182
- // src/autocomplete-empty.tsx
183
- var import_core4 = require("@yamada-ui/core");
184
- var import_utils4 = require("@yamada-ui/utils");
185
- var import_jsx_runtime4 = require("react/jsx-runtime");
186
- var AutocompleteEmpty = (0, import_core4.forwardRef)(
187
- ({ className, icon, children, ...rest }, ref) => {
188
- const { emptyMessage, styles } = useAutocompleteContext();
189
- const { getEmptyProps } = useAutocompleteEmpty();
190
- children != null ? children : children = emptyMessage;
191
- const css = {
192
- textDecoration: "none",
193
- color: "inherit",
194
- userSelect: "none",
195
- display: "flex",
196
- width: "100%",
197
- alignItems: "center",
198
- textAlign: "start",
199
- flex: "0 0 auto",
200
- outline: 0,
201
- gap: "0.75rem",
202
- pointerEvents: "none",
203
- ...styles.item
204
- };
205
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
206
- import_core4.ui.li,
207
- {
208
- className: (0, import_utils4.cx)("ui-autocomplete__item--empty", className),
209
- __css: css,
210
- ...getEmptyProps(rest, ref),
211
- children: [
212
- icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteItemIcon, { children: icon || /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(MinusIcon, {}) }) : null,
213
- icon ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core4.ui.span, { style: { pointerEvents: "none", flex: 1 }, lineClamp: 1, children }) : children
214
- ]
167
+ if (!isTargetOption(ev.currentTarget)) {
168
+ if (inputRef.current) inputRef.current.focus();
169
+ return;
215
170
  }
216
- );
217
- }
218
- );
219
- var MinusIcon = () => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("svg", { viewBox: "0 0 448 512", width: "1em", height: "1em", children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
220
- "path",
221
- {
222
- fill: "currentColor",
223
- 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"
224
- }
225
- ) });
226
-
171
+ setFocusedIndex(index);
172
+ onChange(optionValue != null ? optionValue : "");
173
+ if (inputRef.current) inputRef.current.focus();
174
+ if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect) onClose();
175
+ if (omitSelectedValues) onFocusNext(index);
176
+ },
177
+ [
178
+ onFocusNext,
179
+ omitSelectedValues,
180
+ isDisabled,
181
+ optionValue,
182
+ setFocusedIndex,
183
+ index,
184
+ onChange,
185
+ customCloseOnSelect,
186
+ generalCloseOnSelect,
187
+ onClose,
188
+ inputRef
189
+ ]
190
+ );
191
+ (0, import_utils3.useUpdateEffect)(() => {
192
+ if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", { runOmit: false });
193
+ }, [optionValue]);
194
+ const getOptionProps = (0, import_react2.useCallback)(
195
+ (props2 = {}, ref = null) => {
196
+ const style = {
197
+ border: "0px",
198
+ clip: "rect(0px, 0px, 0px, 0px)",
199
+ height: "1px",
200
+ width: "1px",
201
+ margin: "-1px",
202
+ padding: "0px",
203
+ overflow: "hidden",
204
+ whiteSpace: "nowrap",
205
+ position: "absolute"
206
+ };
207
+ return {
208
+ ref: (0, import_utils3.mergeRefs)(itemRef, ref, register),
209
+ id: (0, import_react2.useId)(),
210
+ role: "option",
211
+ ...computedProps,
212
+ ...props2,
213
+ tabIndex: -1,
214
+ style: !isTarget || omitSelectedValues && isSelected ? style : void 0,
215
+ "data-target": (0, import_utils3.dataAttr)(true),
216
+ "data-value": optionValue != null ? optionValue : "",
217
+ "data-focus": (0, import_utils3.dataAttr)(isFocused),
218
+ "data-disabled": (0, import_utils3.dataAttr)(isDisabled),
219
+ "aria-checked": isSelected,
220
+ "aria-disabled": (0, import_utils3.ariaAttr)(isDisabled),
221
+ onClick: (0, import_utils3.handlerAll)(computedProps.onClick, props2.onClick, onClick)
222
+ };
223
+ },
224
+ [
225
+ optionValue,
226
+ computedProps,
227
+ isDisabled,
228
+ isFocused,
229
+ isSelected,
230
+ isTarget,
231
+ omitSelectedValues,
232
+ onClick,
233
+ register
234
+ ]
235
+ );
236
+ return {
237
+ isSelected,
238
+ isFocused,
239
+ customIcon,
240
+ children,
241
+ getOptionProps
242
+ };
243
+ };
244
+ var useAutocompleteCreate = () => {
245
+ const { isHit, onCreate } = useAutocompleteContext();
246
+ const getCreateProps = (0, import_react2.useCallback)(
247
+ (props = {}, ref = null) => {
248
+ const style = {
249
+ border: "0px",
250
+ clip: "rect(0px, 0px, 0px, 0px)",
251
+ height: "1px",
252
+ width: "1px",
253
+ margin: "-1px",
254
+ padding: "0px",
255
+ overflow: "hidden",
256
+ whiteSpace: "nowrap",
257
+ position: "absolute"
258
+ };
259
+ return {
260
+ ref,
261
+ ...props,
262
+ tabIndex: -1,
263
+ style: isHit ? style : void 0,
264
+ "data-focus": (0, import_utils3.dataAttr)(!isHit),
265
+ onClick: (0, import_utils3.handlerAll)(props.onClick, onCreate)
266
+ };
267
+ },
268
+ [isHit, onCreate]
269
+ );
270
+ return { getCreateProps };
271
+ };
272
+ var useAutocompleteEmpty = () => {
273
+ const { isHit, isEmpty } = useAutocompleteContext();
274
+ const getEmptyProps = (0, import_react2.useCallback)(
275
+ (props = {}, ref = null) => {
276
+ const style = {
277
+ border: "0px",
278
+ clip: "rect(0px, 0px, 0px, 0px)",
279
+ height: "1px",
280
+ width: "1px",
281
+ margin: "-1px",
282
+ padding: "0px",
283
+ overflow: "hidden",
284
+ whiteSpace: "nowrap",
285
+ position: "absolute"
286
+ };
287
+ return {
288
+ ref,
289
+ ...props,
290
+ tabIndex: -1,
291
+ style: isHit && !isEmpty ? style : void 0
292
+ };
293
+ },
294
+ [isHit, isEmpty]
295
+ );
296
+ return { getEmptyProps };
297
+ };
298
+
299
+ // src/autocomplete-create.tsx
300
+ var import_jsx_runtime2 = require("react/jsx-runtime");
301
+ var AutocompleteCreate = (0, import_core2.forwardRef)(
302
+ ({ className, icon, children, ...rest }, ref) => {
303
+ const { inputValue, styles } = useAutocompleteContext();
304
+ const { getCreateProps } = useAutocompleteCreate();
305
+ children != null ? children : children = inputValue;
306
+ const css = {
307
+ textDecoration: "none",
308
+ color: "inherit",
309
+ userSelect: "none",
310
+ display: "flex",
311
+ width: "100%",
312
+ alignItems: "center",
313
+ textAlign: "start",
314
+ flex: "0 0 auto",
315
+ outline: 0,
316
+ gap: "0.75rem",
317
+ ...styles.item
318
+ };
319
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
320
+ import_core2.ui.li,
321
+ {
322
+ className: (0, import_utils4.cx)("ui-autocomplete__item--create", className),
323
+ __css: css,
324
+ ...getCreateProps(rest, ref),
325
+ children: [
326
+ icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(AutocompleteItemIcon, { children: icon || /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(PlusIcon, {}) }) : null,
327
+ 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)
328
+ ]
329
+ }
330
+ );
331
+ }
332
+ );
333
+ 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)(
334
+ "path",
335
+ {
336
+ fill: "currentColor",
337
+ 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"
338
+ }
339
+ ) });
340
+
341
+ // src/autocomplete-empty.tsx
342
+ var import_core3 = require("@yamada-ui/core");
343
+ var import_utils5 = require("@yamada-ui/utils");
344
+ var import_jsx_runtime3 = require("react/jsx-runtime");
345
+ var AutocompleteEmpty = (0, import_core3.forwardRef)(
346
+ ({ className, icon, children, ...rest }, ref) => {
347
+ const { emptyMessage, styles } = useAutocompleteContext();
348
+ const { getEmptyProps } = useAutocompleteEmpty();
349
+ children != null ? children : children = emptyMessage;
350
+ const css = {
351
+ textDecoration: "none",
352
+ color: "inherit",
353
+ userSelect: "none",
354
+ display: "flex",
355
+ width: "100%",
356
+ alignItems: "center",
357
+ textAlign: "start",
358
+ flex: "0 0 auto",
359
+ outline: 0,
360
+ gap: "0.75rem",
361
+ pointerEvents: "none",
362
+ ...styles.item
363
+ };
364
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
365
+ import_core3.ui.li,
366
+ {
367
+ className: (0, import_utils5.cx)("ui-autocomplete__item--empty", className),
368
+ __css: css,
369
+ ...getEmptyProps(rest, ref),
370
+ children: [
371
+ icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AutocompleteItemIcon, { children: icon || /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(MinusIcon, {}) }) : null,
372
+ icon ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core3.ui.span, { style: { pointerEvents: "none", flex: 1 }, lineClamp: 1, children }) : children
373
+ ]
374
+ }
375
+ );
376
+ }
377
+ );
378
+ 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)(
379
+ "path",
380
+ {
381
+ fill: "currentColor",
382
+ 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"
383
+ }
384
+ ) });
385
+
227
386
  // src/autocomplete-list.tsx
228
- var import_core5 = require("@yamada-ui/core");
387
+ var import_core4 = require("@yamada-ui/core");
229
388
  var import_popover = require("@yamada-ui/popover");
230
- var import_utils5 = require("@yamada-ui/utils");
231
- var import_jsx_runtime5 = require("react/jsx-runtime");
232
- var AutocompleteList = (0, import_core5.forwardRef)(
389
+ var import_utils7 = require("@yamada-ui/utils");
390
+
391
+ // src/use-autocomplete-list.ts
392
+ var import_utils6 = require("@yamada-ui/utils");
393
+ var import_react3 = require("react");
394
+ var useAutocompleteList = () => {
395
+ const { focusedIndex, isOpen, listRef, rebirthOptions } = useAutocompleteContext();
396
+ const descendants = useAutocompleteDescendantsContext();
397
+ const beforeFocusedIndex = (0, import_react3.useRef)(-1);
398
+ const selectedValue = descendants.value(focusedIndex);
399
+ const onAnimationComplete = (0, import_react3.useCallback)(() => {
400
+ if (!isOpen) rebirthOptions(false);
401
+ }, [isOpen, rebirthOptions]);
402
+ (0, import_react3.useEffect)(() => {
403
+ if (!listRef.current || !selectedValue) return;
404
+ if (beforeFocusedIndex.current === selectedValue.index) return;
405
+ const parent = listRef.current;
406
+ const child = selectedValue.node;
407
+ const parentHeight = parent.clientHeight;
408
+ const viewTop = parent.scrollTop;
409
+ const viewBottom = viewTop + parentHeight;
410
+ const childHeight = child.clientHeight;
411
+ const childTop = child.offsetTop;
412
+ const childBottom = childTop + childHeight;
413
+ const isInView = viewTop <= childTop && childBottom <= viewBottom;
414
+ const isScrollBottom = beforeFocusedIndex.current < selectedValue.index;
415
+ if (!isInView) {
416
+ if (childBottom <= parentHeight) {
417
+ listRef.current.scrollTo({ top: 0 });
418
+ } else {
419
+ if (!isScrollBottom) {
420
+ listRef.current.scrollTo({ top: childTop + 1 });
421
+ } else {
422
+ listRef.current.scrollTo({ top: childBottom - parentHeight });
423
+ }
424
+ }
425
+ }
426
+ beforeFocusedIndex.current = selectedValue.index;
427
+ }, [listRef, selectedValue]);
428
+ (0, import_utils6.useUpdateEffect)(() => {
429
+ if (!isOpen) beforeFocusedIndex.current = -1;
430
+ }, [isOpen]);
431
+ const getListProps = (0, import_react3.useCallback)(
432
+ (props = {}, ref = null) => ({
433
+ as: "ul",
434
+ ref: (0, import_utils6.mergeRefs)(listRef, ref),
435
+ role: "listbox",
436
+ tabIndex: -1,
437
+ position: "relative",
438
+ id: props.id || (0, import_react3.useId)(),
439
+ ...props
440
+ }),
441
+ [listRef]
442
+ );
443
+ return {
444
+ onAnimationComplete,
445
+ getListProps
446
+ };
447
+ };
448
+
449
+ // src/autocomplete-list.tsx
450
+ var import_jsx_runtime4 = require("react/jsx-runtime");
451
+ var AutocompleteList = (0, import_core4.forwardRef)(
233
452
  ({
234
453
  className,
235
454
  w,
@@ -253,7 +472,7 @@ var AutocompleteList = (0, import_core5.forwardRef)(
253
472
  minWidth != null ? minWidth : minWidth = (_f = (_d = styles.list) == null ? void 0 : _d.minWidth) != null ? _f : (_e = styles.list) == null ? void 0 : _e.minW;
254
473
  maxWidth != null ? maxWidth : maxWidth = maxW;
255
474
  maxWidth != null ? maxWidth : maxWidth = (_i = (_g = styles.list) == null ? void 0 : _g.maxWidth) != null ? _i : (_h = styles.list) == null ? void 0 : _h.maxW;
256
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
475
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
257
476
  import_popover.PopoverContent,
258
477
  {
259
478
  as: "div",
@@ -263,30 +482,30 @@ var AutocompleteList = (0, import_core5.forwardRef)(
263
482
  maxWidth,
264
483
  __css: { ...styles.content, width, minWidth, maxWidth },
265
484
  ...contentProps,
266
- onAnimationComplete: (0, import_utils5.handlerAll)(
485
+ onAnimationComplete: (0, import_utils7.handlerAll)(
267
486
  contentProps == null ? void 0 : contentProps.onAnimationComplete,
268
487
  onAnimationComplete
269
488
  ),
270
489
  children: [
271
- header ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
272
- import_core5.ui.div,
490
+ header ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
491
+ import_core4.ui.div,
273
492
  {
274
493
  className: "ui-autocomplete__header",
275
494
  __css: { ...styles.header },
276
495
  children: header
277
496
  }
278
497
  ) : null,
279
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
280
- import_core5.ui.ul,
498
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
499
+ import_core4.ui.ul,
281
500
  {
282
- className: (0, import_utils5.cx)("ui-autocomplete__list", className),
501
+ className: (0, import_utils7.cx)("ui-autocomplete__list", className),
283
502
  __css: { ...styles.list },
284
503
  ...getListProps(rest, ref),
285
504
  children
286
505
  }
287
506
  ),
288
- footer ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
289
- import_core5.ui.div,
507
+ footer ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
508
+ import_core4.ui.div,
290
509
  {
291
510
  className: "ui-autocomplete__footer",
292
511
  __css: { ...styles.footer },
@@ -300,9 +519,177 @@ var AutocompleteList = (0, import_core5.forwardRef)(
300
519
  );
301
520
 
302
521
  // src/use-autocomplete.tsx
303
- var import_jsx_runtime6 = require("react/jsx-runtime");
304
- var kanaMap = {
305
- \uFF76\uFF9E: "\u30AC",
522
+ var import_core8 = require("@yamada-ui/core");
523
+ var import_form_control = require("@yamada-ui/form-control");
524
+ var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
525
+ var import_use_disclosure = require("@yamada-ui/use-disclosure");
526
+ var import_use_outside_click = require("@yamada-ui/use-outside-click");
527
+ var import_utils11 = require("@yamada-ui/utils");
528
+ var import_react5 = require("react");
529
+
530
+ // src/autocomplete-option.tsx
531
+ var import_core5 = require("@yamada-ui/core");
532
+ var import_utils8 = require("@yamada-ui/utils");
533
+ var import_jsx_runtime5 = require("react/jsx-runtime");
534
+ var AutocompleteOption = (0, import_core5.forwardRef)(
535
+ ({ className, icon, ...rest }, ref) => {
536
+ const { styles } = useAutocompleteContext();
537
+ const { isSelected, customIcon, children, getOptionProps } = useAutocompleteOption(rest);
538
+ icon != null ? icon : icon = customIcon;
539
+ const css = {
540
+ textDecoration: "none",
541
+ color: "inherit",
542
+ userSelect: "none",
543
+ display: "flex",
544
+ width: "100%",
545
+ alignItems: "center",
546
+ textAlign: "start",
547
+ flex: "0 0 auto",
548
+ outline: 0,
549
+ gap: "0.75rem",
550
+ ...styles.item
551
+ };
552
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
553
+ import_core5.ui.li,
554
+ {
555
+ className: (0, import_utils8.cx)("ui-autocomplete__item", className),
556
+ __css: css,
557
+ ...getOptionProps({}, ref),
558
+ children: [
559
+ icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(AutocompleteItemIcon, { opacity: isSelected ? 1 : 0, children: icon || /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(CheckIcon, {}) }) : null,
560
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_core5.ui.span, { style: { flex: 1 }, "data-label": true, children })
561
+ ]
562
+ }
563
+ );
564
+ }
565
+ );
566
+ 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)(
567
+ "polygon",
568
+ {
569
+ fill: "currentColor",
570
+ points: "5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039"
571
+ }
572
+ ) });
573
+
574
+ // src/autocomplete-option-group.tsx
575
+ var import_core7 = require("@yamada-ui/core");
576
+ var import_utils10 = require("@yamada-ui/utils");
577
+
578
+ // src/use-autocomplete-option-group.ts
579
+ var import_core6 = require("@yamada-ui/core");
580
+ var import_utils9 = require("@yamada-ui/utils");
581
+ var import_react4 = require("react");
582
+ var useAutocompleteOptionGroup = ({
583
+ label,
584
+ ...rest
585
+ }) => {
586
+ const { value, omitSelectedValues } = useAutocompleteContext();
587
+ const isMulti = (0, import_utils9.isArray)(value);
588
+ const descendants = useAutocompleteDescendantsContext();
589
+ const values = descendants.values();
590
+ const selectedValues = isMulti && omitSelectedValues ? descendants.values(
591
+ ({ node }) => {
592
+ var _a;
593
+ return value.includes((_a = node.dataset.value) != null ? _a : "");
594
+ }
595
+ ) : [];
596
+ const selectedIndexes = selectedValues.map(({ index }) => index);
597
+ const childValues = values.filter(
598
+ ({ node, index }) => {
599
+ var _a;
600
+ return ((_a = node.parentElement) == null ? void 0 : _a.dataset.label) === label && !selectedIndexes.includes(index) && "target" in node.dataset;
601
+ }
602
+ );
603
+ const isEmpty = !childValues.length;
604
+ const [containerProps, groupProps] = (0, import_utils9.splitObject)(rest, import_core6.layoutStyleProperties);
605
+ const getContainerProps = (0, import_react4.useCallback)(
606
+ (props = {}, ref = null) => {
607
+ const style = {
608
+ border: "0px",
609
+ clip: "rect(0px, 0px, 0px, 0px)",
610
+ height: "1px",
611
+ width: "1px",
612
+ margin: "-1px",
613
+ padding: "0px",
614
+ overflow: "hidden",
615
+ whiteSpace: "nowrap",
616
+ position: "absolute"
617
+ };
618
+ return {
619
+ ref,
620
+ ...props,
621
+ ...containerProps,
622
+ style: isEmpty ? style : void 0,
623
+ "data-label": label,
624
+ role: "autocomplete-group-container"
625
+ };
626
+ },
627
+ [containerProps, isEmpty, label]
628
+ );
629
+ const getGroupProps = (0, import_react4.useCallback)(
630
+ (props = {}, ref = null) => ({
631
+ ref,
632
+ ...props,
633
+ ...groupProps,
634
+ "data-label": label,
635
+ role: "autocomplete-group"
636
+ }),
637
+ [groupProps, label]
638
+ );
639
+ return {
640
+ label,
641
+ getContainerProps,
642
+ getGroupProps
643
+ };
644
+ };
645
+
646
+ // src/autocomplete-option-group.tsx
647
+ var import_jsx_runtime6 = require("react/jsx-runtime");
648
+ var AutocompleteOptionGroup = (0, import_core7.forwardRef)(
649
+ ({ className, color, h, height, minH, minHeight, children, ...rest }, ref) => {
650
+ const { styles } = useAutocompleteContext();
651
+ const { label, getContainerProps, getGroupProps } = useAutocompleteOptionGroup(rest);
652
+ h != null ? h : h = height;
653
+ minH != null ? minH : minH = minHeight;
654
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
655
+ import_core7.ui.li,
656
+ {
657
+ className: (0, import_utils10.cx)(
658
+ "ui-autocomplete__item",
659
+ "ui-autocomplete__item--group",
660
+ className
661
+ ),
662
+ __css: { w: "100%", h: "fit-content", color },
663
+ ...getContainerProps(),
664
+ children: [
665
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
666
+ import_core7.ui.span,
667
+ {
668
+ className: "ui-autocomplete__item__group-label",
669
+ __css: styles.groupLabel,
670
+ lineClamp: 1,
671
+ children: label
672
+ }
673
+ ),
674
+ /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
675
+ import_core7.ui.ul,
676
+ {
677
+ ...getGroupProps({}, ref),
678
+ className: "ui-autocomplete__item__group",
679
+ __css: { h, minH, ...styles.group },
680
+ children
681
+ }
682
+ )
683
+ ]
684
+ }
685
+ );
686
+ }
687
+ );
688
+
689
+ // src/use-autocomplete.tsx
690
+ var import_jsx_runtime7 = require("react/jsx-runtime");
691
+ var kanaMap = {
692
+ \uFF76\uFF9E: "\u30AC",
306
693
  \uFF77\uFF9E: "\u30AE",
307
694
  \uFF78\uFF9E: "\u30B0",
308
695
  \uFF79\uFF9E: "\u30B2",
@@ -416,20 +803,6 @@ var flattenItems = (items) => {
416
803
  }).filter(Boolean);
417
804
  return filterItems(items).flat(Infinity);
418
805
  };
419
- var isTargetOption = (target) => {
420
- var _a;
421
- return (0, import_utils6.isHTMLElement)(target) && !!((_a = target == null ? void 0 : target.getAttribute("role")) == null ? void 0 : _a.startsWith("option"));
422
- };
423
- var {
424
- DescendantsContextProvider: AutocompleteDescendantsContextProvider,
425
- useDescendantsContext: useAutocompleteDescendantsContext,
426
- useDescendants: useAutocompleteDescendants,
427
- useDescendant: useAutocompleteDescendant
428
- } = (0, import_use_descendant.createDescendant)();
429
- var [AutocompleteProvider, useAutocompleteContext] = (0, import_utils6.createContext)({
430
- name: "AutocompleteContext",
431
- errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in "<Autocomplete />" or "<MultiAutocomplete />"`
432
- });
433
806
  var useAutocomplete = (props) => {
434
807
  const {
435
808
  value: valueProp,
@@ -478,27 +851,27 @@ var useAutocomplete = (props) => {
478
851
  "aria-readonly": _ariaReadonly,
479
852
  onFocus: onFocusProp,
480
853
  ...formControlProps
481
- } = (0, import_utils6.pickObject)(rest, import_form_control.formControlProperties);
482
- const [containerProps, inputProps] = (0, import_utils6.splitObject)(rest, import_core6.layoutStyleProperties);
854
+ } = (0, import_utils11.pickObject)(rest, import_form_control.formControlProperties);
855
+ const [containerProps, inputProps] = (0, import_utils11.splitObject)(rest, import_core8.layoutStyleProperties);
483
856
  const { id } = rest;
484
857
  const descendants = useAutocompleteDescendants();
485
- const containerRef = (0, import_react.useRef)(null);
486
- const listRef = (0, import_react.useRef)(null);
487
- const inputRef = (0, import_react.useRef)(null);
488
- const timeoutIds = (0, import_react.useRef)(/* @__PURE__ */ new Set([]));
489
- const isComposition = (0, import_react.useRef)(false);
490
- const prevValue = (0, import_react.useRef)(void 0);
491
- const [resolvedItems, setResolvedItems] = (0, import_react.useState)(items ? JSON.parse(JSON.stringify(items)) : void 0);
858
+ const containerRef = (0, import_react5.useRef)(null);
859
+ const listRef = (0, import_react5.useRef)(null);
860
+ const inputRef = (0, import_react5.useRef)(null);
861
+ const timeoutIds = (0, import_react5.useRef)(/* @__PURE__ */ new Set([]));
862
+ const isComposition = (0, import_react5.useRef)(false);
863
+ const prevValue = (0, import_react5.useRef)(void 0);
864
+ const [resolvedItems, setResolvedItems] = (0, import_react5.useState)(items ? JSON.parse(JSON.stringify(items)) : void 0);
492
865
  const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
493
866
  value: valueProp,
494
867
  defaultValue,
495
868
  onChange: onChangeProp
496
869
  });
497
- const [label, setLabel] = (0, import_react.useState)(void 0);
498
- const [inputValue, setInputValue] = (0, import_react.useState)("");
499
- const [focusedIndex, setFocusedIndex] = (0, import_react.useState)(-1);
500
- const [isAllSelected, setIsAllSelected] = (0, import_react.useState)(false);
501
- const [isHit, setIsHit] = (0, import_react.useState)(true);
870
+ const [label, setLabel] = (0, import_react5.useState)(void 0);
871
+ const [inputValue, setInputValue] = (0, import_react5.useState)("");
872
+ const [focusedIndex, setFocusedIndex] = (0, import_react5.useState)(-1);
873
+ const [isAllSelected, setIsAllSelected] = (0, import_react5.useState)(false);
874
+ const [isHit, setIsHit] = (0, import_react5.useState)(true);
502
875
  const {
503
876
  isOpen,
504
877
  onOpen: onInternalOpen,
@@ -511,16 +884,16 @@ var useAutocomplete = (props) => {
511
884
  });
512
885
  const isFocused = focusedIndex > -1;
513
886
  const isCreate = focusedIndex === -2 && allowCreate;
514
- const isMulti = (0, import_utils6.isArray)(value);
887
+ const isMulti = (0, import_utils11.isArray)(value);
515
888
  const isEmptyValue = !isMulti ? !value : !value.length;
516
- const [firstInsertPositionItem, secondInsertPositionItem] = (0, import_react.useMemo)(() => {
517
- if ((0, import_utils6.isArray)(insertPositionItem)) {
889
+ const [firstInsertPositionItem, secondInsertPositionItem] = (0, import_react5.useMemo)(() => {
890
+ if ((0, import_utils11.isArray)(insertPositionItem)) {
518
891
  return insertPositionItem;
519
892
  } else {
520
893
  return [insertPositionItem, "first"];
521
894
  }
522
895
  }, [insertPositionItem]);
523
- if (allowCreate && !(0, import_utils6.isUndefined)(children)) {
896
+ if (allowCreate && !(0, import_utils11.isUndefined)(children)) {
524
897
  console.warn(
525
898
  `${!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.`
526
899
  );
@@ -535,35 +908,27 @@ var useAutocomplete = (props) => {
535
908
  const enabledValues = descendants.enabledValues(
536
909
  ({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
537
910
  );
538
- const validChildren = (0, import_utils6.getValidChildren)(children);
539
- const computedChildren = (0, import_react.useMemo)(
911
+ const validChildren = (0, import_utils11.getValidChildren)(children);
912
+ const computedChildren = (0, import_react5.useMemo)(
540
913
  () => resolvedItems == null ? void 0 : resolvedItems.map((item, i) => {
541
914
  if ("value" in item) {
542
915
  const { label: label2, value: value2, ...props2 } = item;
543
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AutocompleteOption, { value: value2, ...props2, children: label2 }, i);
916
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(AutocompleteOption, { value: value2, ...props2, children: label2 }, i);
544
917
  } else if ("items" in item) {
545
918
  const { label: label2, items: items2 = [], ...props2 } = item;
546
- return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
547
- AutocompleteOptionGroup,
548
- {
549
- label: label2,
550
- ...props2,
551
- children: items2.map(({ label: label3, value: value2, ...props3 }, i2) => /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(AutocompleteOption, { value: value2, ...props3, children: label3 }, i2))
552
- },
553
- i
554
- );
919
+ 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);
555
920
  }
556
921
  }),
557
922
  [resolvedItems]
558
923
  );
559
924
  const isEmpty = !validChildren.length && !(computedChildren == null ? void 0 : computedChildren.length);
560
- const onOpen = (0, import_react.useCallback)(() => {
925
+ const onOpen = (0, import_react5.useCallback)(() => {
561
926
  if (formControlProps.disabled || formControlProps.readOnly) return;
562
927
  if (!allowCreate && (isEmpty || isAllSelected)) return;
563
928
  onInternalOpen();
564
929
  if (inputRef.current) inputRef.current.focus();
565
930
  }, [allowCreate, formControlProps, isAllSelected, isEmpty, onInternalOpen]);
566
- const onFocusFirst = (0, import_react.useCallback)(() => {
931
+ const onFocusFirst = (0, import_react5.useCallback)(() => {
567
932
  const id2 = setTimeout(() => {
568
933
  if (isEmpty || isAllSelected) return;
569
934
  const first = descendants.enabledFirstValue(
@@ -591,7 +956,7 @@ var useAutocomplete = (props) => {
591
956
  omitSelectedValues,
592
957
  selectedIndexes
593
958
  ]);
594
- const onFocusLast = (0, import_react.useCallback)(() => {
959
+ const onFocusLast = (0, import_react5.useCallback)(() => {
595
960
  const id2 = setTimeout(() => {
596
961
  if (isEmpty || isAllSelected) return;
597
962
  const last = descendants.enabledLastValue(
@@ -619,7 +984,7 @@ var useAutocomplete = (props) => {
619
984
  omitSelectedValues,
620
985
  selectedIndexes
621
986
  ]);
622
- const onFocusSelected = (0, import_react.useCallback)(() => {
987
+ const onFocusSelected = (0, import_react5.useCallback)(() => {
623
988
  const id2 = setTimeout(() => {
624
989
  const values = descendants.enabledValues();
625
990
  const selected = values.find(
@@ -632,7 +997,7 @@ var useAutocomplete = (props) => {
632
997
  });
633
998
  timeoutIds.current.add(id2);
634
999
  }, [descendants, isMulti, value]);
635
- const onFocusNext = (0, import_react.useCallback)(
1000
+ const onFocusNext = (0, import_react5.useCallback)(
636
1001
  (index = focusedIndex) => {
637
1002
  const id2 = setTimeout(() => {
638
1003
  var _a;
@@ -663,7 +1028,7 @@ var useAutocomplete = (props) => {
663
1028
  selectedIndexes
664
1029
  ]
665
1030
  );
666
- const onFocusPrev = (0, import_react.useCallback)(
1031
+ const onFocusPrev = (0, import_react5.useCallback)(
667
1032
  (index = focusedIndex) => {
668
1033
  const id2 = setTimeout(() => {
669
1034
  var _a;
@@ -696,7 +1061,7 @@ var useAutocomplete = (props) => {
696
1061
  );
697
1062
  const onFocusFirstOrSelected = isEmptyValue || omitSelectedValues ? onFocusFirst : onFocusSelected;
698
1063
  const onFocusLastOrSelected = isEmptyValue || omitSelectedValues ? onFocusLast : onFocusSelected;
699
- const pickOptions = (0, import_react.useCallback)(
1064
+ const pickOptions = (0, import_react5.useCallback)(
700
1065
  (value2) => {
701
1066
  const values = descendants.values();
702
1067
  let isHit2 = false;
@@ -719,7 +1084,7 @@ var useAutocomplete = (props) => {
719
1084
  },
720
1085
  [descendants, format]
721
1086
  );
722
- const rebirthOptions = (0, import_react.useCallback)(
1087
+ const rebirthOptions = (0, import_react5.useCallback)(
723
1088
  (runFocus = true) => {
724
1089
  const values = descendants.values();
725
1090
  values.forEach(({ node }) => {
@@ -730,10 +1095,10 @@ var useAutocomplete = (props) => {
730
1095
  },
731
1096
  [descendants, onFocusFirst]
732
1097
  );
733
- const getSelectedValues = (0, import_react.useCallback)(
1098
+ const getSelectedValues = (0, import_react5.useCallback)(
734
1099
  (newValues) => {
735
1100
  const enabledValues2 = descendants.enabledValues();
736
- const resolvedValues = (0, import_utils6.isArray)(newValues) ? newValues : [newValues];
1101
+ const resolvedValues = (0, import_utils11.isArray)(newValues) ? newValues : [newValues];
737
1102
  const selectedValues2 = resolvedValues.map((value2) => {
738
1103
  var _a, _b;
739
1104
  const { node } = (_a = enabledValues2.find(({ node: node2 }) => node2.dataset.value === value2)) != null ? _a : {};
@@ -750,7 +1115,7 @@ var useAutocomplete = (props) => {
750
1115
  },
751
1116
  [allowFree, descendants]
752
1117
  );
753
- const onChangeLabel = (0, import_react.useCallback)(
1118
+ const onChangeLabel = (0, import_react5.useCallback)(
754
1119
  (newValue, { forceUpdate, runOmit = true } = {}) => {
755
1120
  const selectedValues2 = getSelectedValues(newValue);
756
1121
  if (!forceUpdate && !selectedValues2.length) return;
@@ -759,11 +1124,11 @@ var useAutocomplete = (props) => {
759
1124
  return selectedValues2[0];
760
1125
  } else {
761
1126
  selectedValues2.forEach((selectedValue) => {
762
- const isSelected = (0, import_utils6.isArray)(prev) && prev.includes(selectedValue != null ? selectedValue : "");
1127
+ const isSelected = (0, import_utils11.isArray)(prev) && prev.includes(selectedValue != null ? selectedValue : "");
763
1128
  if (!isSelected) {
764
- prev = [...(0, import_utils6.isArray)(prev) ? prev : [], selectedValue];
1129
+ prev = [...(0, import_utils11.isArray)(prev) ? prev : [], selectedValue];
765
1130
  } else if (runOmit) {
766
- prev = (0, import_utils6.isArray)(prev) ? prev.filter((value2) => value2 !== selectedValue) : void 0;
1131
+ prev = (0, import_utils11.isArray)(prev) ? prev.filter((value2) => value2 !== selectedValue) : void 0;
767
1132
  }
768
1133
  });
769
1134
  return prev;
@@ -772,11 +1137,11 @@ var useAutocomplete = (props) => {
772
1137
  },
773
1138
  [getSelectedValues, isMulti]
774
1139
  );
775
- const onChange = (0, import_react.useCallback)(
1140
+ const onChange = (0, import_react5.useCallback)(
776
1141
  (newValue, { forceUpdate, runRebirth = true } = {}) => {
777
1142
  setValue((prev) => {
778
1143
  let next;
779
- if (!(0, import_utils6.isArray)(prev)) {
1144
+ if (!(0, import_utils11.isArray)(prev)) {
780
1145
  next = newValue;
781
1146
  } else {
782
1147
  const isSelected = prev.includes(newValue);
@@ -809,7 +1174,7 @@ var useAutocomplete = (props) => {
809
1174
  format
810
1175
  ]
811
1176
  );
812
- const onSelect = (0, import_react.useCallback)(() => {
1177
+ const onSelect = (0, import_react5.useCallback)(() => {
813
1178
  var _a, _b;
814
1179
  let enabledValue = descendants.value(focusedIndex);
815
1180
  if ("disabled" in ((_a = enabledValue == null ? void 0 : enabledValue.node.dataset) != null ? _a : {}))
@@ -828,7 +1193,7 @@ var useAutocomplete = (props) => {
828
1193
  onClose,
829
1194
  onFocusNext
830
1195
  ]);
831
- const onSearch = (0, import_react.useCallback)(
1196
+ const onSearch = (0, import_react5.useCallback)(
832
1197
  (ev) => {
833
1198
  if (!isOpen) onOpen();
834
1199
  onSearchProp == null ? void 0 : onSearchProp(ev);
@@ -843,13 +1208,13 @@ var useAutocomplete = (props) => {
843
1208
  },
844
1209
  [isOpen, onOpen, format, onSearchProp, pickOptions, rebirthOptions]
845
1210
  );
846
- const onCompositionStart = (0, import_react.useCallback)(() => {
1211
+ const onCompositionStart = (0, import_react5.useCallback)(() => {
847
1212
  isComposition.current = true;
848
1213
  }, []);
849
- const onCompositionEnd = (0, import_react.useCallback)(() => {
1214
+ const onCompositionEnd = (0, import_react5.useCallback)(() => {
850
1215
  isComposition.current = false;
851
1216
  }, []);
852
- const onCreate = (0, import_react.useCallback)(() => {
1217
+ const onCreate = (0, import_react5.useCallback)(() => {
853
1218
  var _a, _b;
854
1219
  if (!listRef.current) return;
855
1220
  const newItem = { label: inputValue, value: inputValue };
@@ -895,7 +1260,7 @@ var useAutocomplete = (props) => {
895
1260
  secondInsertPositionItem,
896
1261
  isMulti
897
1262
  ]);
898
- const onClick = (0, import_react.useCallback)(() => {
1263
+ const onClick = (0, import_react5.useCallback)(() => {
899
1264
  if (isOpen) {
900
1265
  if (inputRef.current) inputRef.current.focus();
901
1266
  } else {
@@ -903,15 +1268,15 @@ var useAutocomplete = (props) => {
903
1268
  onFocusFirstOrSelected();
904
1269
  }
905
1270
  }, [isOpen, onFocusFirstOrSelected, onOpen]);
906
- const onFocus = (0, import_react.useCallback)(() => {
1271
+ const onFocus = (0, import_react5.useCallback)(() => {
907
1272
  if (isOpen) return;
908
1273
  onOpen();
909
1274
  onFocusFirstOrSelected();
910
1275
  }, [isOpen, onFocusFirstOrSelected, onOpen]);
911
- const onBlur = (0, import_react.useCallback)(
1276
+ const onBlur = (0, import_react5.useCallback)(
912
1277
  (ev) => {
913
- const relatedTarget = (0, import_utils6.getEventRelatedTarget)(ev);
914
- if ((0, import_utils6.isContains)(containerRef.current, relatedTarget)) return;
1278
+ const relatedTarget = (0, import_utils11.getEventRelatedTarget)(ev);
1279
+ if ((0, import_utils11.isContains)(containerRef.current, relatedTarget)) return;
915
1280
  if (!closeOnBlur && isHit) return;
916
1281
  if (allowFree && !!inputValue) onChange(inputValue, { runRebirth: false });
917
1282
  setInputValue("");
@@ -919,7 +1284,7 @@ var useAutocomplete = (props) => {
919
1284
  },
920
1285
  [closeOnBlur, isHit, isOpen, inputValue, allowFree, onClose, onChange]
921
1286
  );
922
- const onDelete = (0, import_react.useCallback)(() => {
1287
+ const onDelete = (0, import_react5.useCallback)(() => {
923
1288
  if (!isMulti) {
924
1289
  onChange("", { forceUpdate: true });
925
1290
  } else {
@@ -927,7 +1292,7 @@ var useAutocomplete = (props) => {
927
1292
  }
928
1293
  if (!isOpen) onFocus();
929
1294
  }, [isMulti, isOpen, onChange, onFocus, value]);
930
- const onClear = (0, import_react.useCallback)(
1295
+ const onClear = (0, import_react5.useCallback)(
931
1296
  (ev) => {
932
1297
  ev.stopPropagation();
933
1298
  prevValue.current = [];
@@ -939,17 +1304,17 @@ var useAutocomplete = (props) => {
939
1304
  },
940
1305
  [isOpen, setLabel, setInputValue, setValue, rebirthOptions]
941
1306
  );
942
- const onKeyDown = (0, import_react.useCallback)(
1307
+ const onKeyDown = (0, import_react5.useCallback)(
943
1308
  (ev) => {
944
1309
  if (ev.key === " ") ev.key = ev.code;
945
1310
  if (formControlProps.disabled || formControlProps.readOnly) return;
946
1311
  if (isComposition.current) return;
947
1312
  const enabledDelete = label === inputValue || !inputValue.length;
948
1313
  const actions = {
949
- ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
950
- ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
951
- Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
952
- Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils6.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
1314
+ ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils11.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
1315
+ ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils11.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
1316
+ Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils11.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
1317
+ Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils11.funcAll)(onOpen, onFocusFirstOrSelected) : allowFree && isMulti ? () => {
953
1318
  if (inputValue) onChange(inputValue);
954
1319
  setFocusedIndex(0);
955
1320
  } : void 0,
@@ -989,9 +1354,9 @@ var useAutocomplete = (props) => {
989
1354
  onChange
990
1355
  ]
991
1356
  );
992
- (0, import_react.useEffect)(() => {
1357
+ (0, import_react5.useEffect)(() => {
993
1358
  if (!isMulti) return;
994
- if (!omitSelectedValues && (0, import_utils6.isUndefined)(maxSelectValues)) return;
1359
+ if (!omitSelectedValues && (0, import_utils11.isUndefined)(maxSelectValues)) return;
995
1360
  const isAll = value.length > 0 && value.length === descendants.count();
996
1361
  const isMax = value.length === maxSelectValues;
997
1362
  if (isAll || isMax) {
@@ -1008,7 +1373,7 @@ var useAutocomplete = (props) => {
1008
1373
  onClose,
1009
1374
  maxSelectValues
1010
1375
  ]);
1011
- (0, import_react.useEffect)(() => {
1376
+ (0, import_react5.useEffect)(() => {
1012
1377
  var _a;
1013
1378
  if (isMulti) {
1014
1379
  if (JSON.stringify((_a = prevValue.current) != null ? _a : []) === JSON.stringify(value != null ? value : []))
@@ -1020,18 +1385,18 @@ var useAutocomplete = (props) => {
1020
1385
  onChangeLabel(value, { runOmit: false });
1021
1386
  }
1022
1387
  }, [isMulti, value, onChangeLabel, getSelectedValues]);
1023
- (0, import_utils6.useUpdateEffect)(() => {
1388
+ (0, import_utils11.useUpdateEffect)(() => {
1024
1389
  if (isOpen || allowFree) return;
1025
1390
  setFocusedIndex(-1);
1026
1391
  setInputValue("");
1027
1392
  }, [isOpen]);
1028
- (0, import_utils6.useUpdateEffect)(() => {
1393
+ (0, import_utils11.useUpdateEffect)(() => {
1029
1394
  if (!isHit) setFocusedIndex(-2);
1030
1395
  }, [isHit]);
1031
- (0, import_utils6.useUpdateEffect)(() => {
1396
+ (0, import_utils11.useUpdateEffect)(() => {
1032
1397
  setResolvedItems(items ? JSON.parse(JSON.stringify(items)) : void 0);
1033
1398
  }, [items]);
1034
- (0, import_utils6.useUnmountEffect)(() => {
1399
+ (0, import_utils11.useUnmountEffect)(() => {
1035
1400
  timeoutIds.current.forEach((id2) => clearTimeout(id2));
1036
1401
  timeoutIds.current.clear();
1037
1402
  });
@@ -1040,7 +1405,7 @@ var useAutocomplete = (props) => {
1040
1405
  handler: onClose,
1041
1406
  enabled: isOpen && (closeOnBlur || !isHit)
1042
1407
  });
1043
- const getPopoverProps = (0, import_react.useCallback)(
1408
+ const getPopoverProps = (0, import_react5.useCallback)(
1044
1409
  (props2) => ({
1045
1410
  closeOnBlur,
1046
1411
  openDelay,
@@ -1089,28 +1454,28 @@ var useAutocomplete = (props) => {
1089
1454
  onClose
1090
1455
  ]
1091
1456
  );
1092
- const getContainerProps = (0, import_react.useCallback)(
1457
+ const getContainerProps = (0, import_react5.useCallback)(
1093
1458
  (props2 = {}, ref = null) => ({
1094
- ref: (0, import_utils6.mergeRefs)(containerRef, ref),
1459
+ ref: (0, import_utils11.mergeRefs)(containerRef, ref),
1095
1460
  ...containerProps,
1096
1461
  ...props2,
1097
1462
  ...formControlProps,
1098
- onClick: (0, import_utils6.handlerAll)(props2.onClick, rest.onClick, onClick),
1099
- onBlur: (0, import_utils6.handlerAll)(props2.onBlur, rest.onBlur, onBlur)
1463
+ onClick: (0, import_utils11.handlerAll)(props2.onClick, rest.onClick, onClick),
1464
+ onBlur: (0, import_utils11.handlerAll)(props2.onBlur, rest.onBlur, onBlur)
1100
1465
  }),
1101
1466
  [containerProps, formControlProps, onBlur, onClick, rest]
1102
1467
  );
1103
- const getFieldProps = (0, import_react.useCallback)(
1468
+ const getFieldProps = (0, import_react5.useCallback)(
1104
1469
  (props2 = {}, ref = null) => ({
1105
1470
  ref,
1106
1471
  tabIndex: -1,
1107
1472
  ...props2,
1108
1473
  ...formControlProps,
1109
1474
  placeholder,
1110
- "data-active": (0, import_utils6.dataAttr)(isOpen),
1111
- "aria-expanded": (0, import_utils6.dataAttr)(isOpen),
1112
- onFocus: (0, import_utils6.handlerAll)(props2.onFocus, onFocusProp, onFocus),
1113
- onKeyDown: (0, import_utils6.handlerAll)(props2.onKeyDown, onKeyDownProp, onKeyDown)
1475
+ "data-active": (0, import_utils11.dataAttr)(isOpen),
1476
+ "aria-expanded": (0, import_utils11.dataAttr)(isOpen),
1477
+ onFocus: (0, import_utils11.handlerAll)(props2.onFocus, onFocusProp, onFocus),
1478
+ onKeyDown: (0, import_utils11.handlerAll)(props2.onKeyDown, onKeyDownProp, onKeyDown)
1114
1479
  }),
1115
1480
  [
1116
1481
  formControlProps,
@@ -1181,14 +1546,14 @@ var useAutocompleteInput = () => {
1181
1546
  listRef
1182
1547
  } = useAutocompleteContext();
1183
1548
  const { value } = useAutocompleteDescendantsContext();
1184
- (0, import_utils6.useUpdateEffect)(() => {
1549
+ (0, import_utils11.useUpdateEffect)(() => {
1185
1550
  if (isAllSelected && inputRef.current) inputRef.current.blur();
1186
1551
  }, [isAllSelected]);
1187
- const getInputProps = (0, import_react.useCallback)(
1552
+ const getInputProps = (0, import_react5.useCallback)(
1188
1553
  (props = {}, ref = null) => {
1189
1554
  var _a, _b;
1190
1555
  return {
1191
- ref: (0, import_utils6.mergeRefs)(inputRef, ref),
1556
+ ref: (0, import_utils11.mergeRefs)(inputRef, ref),
1192
1557
  ...formControlProps,
1193
1558
  role: "combobox",
1194
1559
  "aria-haspopup": "listbox",
@@ -1205,13 +1570,13 @@ var useAutocompleteInput = () => {
1205
1570
  cursor: formControlProps.readOnly ? "default" : "text",
1206
1571
  pointerEvents: formControlProps.disabled || isAllSelected ? "none" : "auto",
1207
1572
  tabIndex: isAllSelected ? -1 : 0,
1208
- onChange: (0, import_utils6.handlerAll)(props.onChange, onSearch),
1209
- onCompositionStart: (0, import_utils6.handlerAll)(
1573
+ onChange: (0, import_utils11.handlerAll)(props.onChange, onSearch),
1574
+ onCompositionStart: (0, import_utils11.handlerAll)(
1210
1575
  props.onCompositionStart,
1211
1576
  inputProps.onCompositionStart,
1212
1577
  onCompositionStart
1213
1578
  ),
1214
- onCompositionEnd: (0, import_utils6.handlerAll)(
1579
+ onCompositionEnd: (0, import_utils11.handlerAll)(
1215
1580
  props.onCompositionEnd,
1216
1581
  inputProps.onCompositionEnd,
1217
1582
  onCompositionEnd
@@ -1237,365 +1602,12 @@ var useAutocompleteInput = () => {
1237
1602
  getInputProps
1238
1603
  };
1239
1604
  };
1240
- var useAutocompleteList = () => {
1241
- const { focusedIndex, isOpen, listRef, rebirthOptions } = useAutocompleteContext();
1242
- const descendants = useAutocompleteDescendantsContext();
1243
- const beforeFocusedIndex = (0, import_react.useRef)(-1);
1244
- const selectedValue = descendants.value(focusedIndex);
1245
- const onAnimationComplete = (0, import_react.useCallback)(() => {
1246
- if (!isOpen) rebirthOptions(false);
1247
- }, [isOpen, rebirthOptions]);
1248
- (0, import_react.useEffect)(() => {
1249
- if (!listRef.current || !selectedValue) return;
1250
- if (beforeFocusedIndex.current === selectedValue.index) return;
1251
- const parent = listRef.current;
1252
- const child = selectedValue.node;
1253
- const parentHeight = parent.clientHeight;
1254
- const viewTop = parent.scrollTop;
1255
- const viewBottom = viewTop + parentHeight;
1256
- const childHeight = child.clientHeight;
1257
- const childTop = child.offsetTop;
1258
- const childBottom = childTop + childHeight;
1259
- const isInView = viewTop <= childTop && childBottom <= viewBottom;
1260
- const isScrollBottom = beforeFocusedIndex.current < selectedValue.index;
1261
- if (!isInView) {
1262
- if (childBottom <= parentHeight) {
1263
- listRef.current.scrollTo({ top: 0 });
1264
- } else {
1265
- if (!isScrollBottom) {
1266
- listRef.current.scrollTo({ top: childTop + 1 });
1267
- } else {
1268
- listRef.current.scrollTo({ top: childBottom - parentHeight });
1269
- }
1270
- }
1271
- }
1272
- beforeFocusedIndex.current = selectedValue.index;
1273
- }, [listRef, selectedValue]);
1274
- (0, import_utils6.useUpdateEffect)(() => {
1275
- if (!isOpen) beforeFocusedIndex.current = -1;
1276
- }, [isOpen]);
1277
- const getListProps = (0, import_react.useCallback)(
1278
- (props = {}, ref = null) => ({
1279
- as: "ul",
1280
- ref: (0, import_utils6.mergeRefs)(listRef, ref),
1281
- role: "listbox",
1282
- tabIndex: -1,
1283
- position: "relative",
1284
- id: props.id || (0, import_react.useId)(),
1285
- ...props
1286
- }),
1287
- [listRef]
1288
- );
1289
- return {
1290
- onAnimationComplete,
1291
- getListProps
1292
- };
1293
- };
1294
- var useAutocompleteOptionGroup = ({
1295
- label,
1296
- ...rest
1297
- }) => {
1298
- const { value, omitSelectedValues } = useAutocompleteContext();
1299
- const isMulti = (0, import_utils6.isArray)(value);
1300
- const descendants = useAutocompleteDescendantsContext();
1301
- const values = descendants.values();
1302
- const selectedValues = isMulti && omitSelectedValues ? descendants.values(
1303
- ({ node }) => {
1304
- var _a;
1305
- return value.includes((_a = node.dataset.value) != null ? _a : "");
1306
- }
1307
- ) : [];
1308
- const selectedIndexes = selectedValues.map(({ index }) => index);
1309
- const childValues = values.filter(
1310
- ({ node, index }) => {
1311
- var _a;
1312
- return ((_a = node.parentElement) == null ? void 0 : _a.dataset.label) === label && !selectedIndexes.includes(index) && "target" in node.dataset;
1313
- }
1314
- );
1315
- const isEmpty = !childValues.length;
1316
- const [containerProps, groupProps] = (0, import_utils6.splitObject)(rest, import_core6.layoutStyleProperties);
1317
- const getContainerProps = (0, import_react.useCallback)(
1318
- (props = {}, ref = null) => {
1319
- const style = {
1320
- border: "0px",
1321
- clip: "rect(0px, 0px, 0px, 0px)",
1322
- height: "1px",
1323
- width: "1px",
1324
- margin: "-1px",
1325
- padding: "0px",
1326
- overflow: "hidden",
1327
- whiteSpace: "nowrap",
1328
- position: "absolute"
1329
- };
1330
- return {
1331
- ref,
1332
- ...props,
1333
- ...containerProps,
1334
- style: isEmpty ? style : void 0,
1335
- "data-label": label,
1336
- role: "autocomplete-group-container"
1337
- };
1338
- },
1339
- [containerProps, isEmpty, label]
1340
- );
1341
- const getGroupProps = (0, import_react.useCallback)(
1342
- (props = {}, ref = null) => ({
1343
- ref,
1344
- ...props,
1345
- ...groupProps,
1346
- "data-label": label,
1347
- role: "autocomplete-group"
1348
- }),
1349
- [groupProps, label]
1350
- );
1351
- return {
1352
- label,
1353
- getContainerProps,
1354
- getGroupProps
1355
- };
1356
- };
1357
- var useAutocompleteOption = (props) => {
1358
- var _a, _b;
1359
- const {
1360
- value,
1361
- omitSelectedValues,
1362
- onChange,
1363
- onChangeLabel,
1364
- focusedIndex,
1365
- setFocusedIndex,
1366
- onClose,
1367
- closeOnSelect: generalCloseOnSelect,
1368
- optionProps,
1369
- inputRef,
1370
- onFocusNext
1371
- } = useAutocompleteContext();
1372
- let {
1373
- icon: customIcon,
1374
- isDisabled,
1375
- isFocusable,
1376
- closeOnSelect: customCloseOnSelect,
1377
- children,
1378
- value: optionValue,
1379
- ...computedProps
1380
- } = { ...optionProps, ...props };
1381
- const trulyDisabled = !!isDisabled && !isFocusable;
1382
- const itemRef = (0, import_react.useRef)(null);
1383
- const { index, register, descendants } = useAutocompleteDescendant({
1384
- disabled: trulyDisabled
1385
- });
1386
- const values = descendants.values();
1387
- const frontValues = values.slice(0, index);
1388
- const isMulti = (0, import_utils6.isArray)(value);
1389
- const isDuplicated = !isMulti ? frontValues.some(({ node }) => node.dataset.value === (optionValue != null ? optionValue : "")) : false;
1390
- const isSelected = !isDuplicated && (!isMulti ? (optionValue != null ? optionValue : "") === value : value.includes(optionValue != null ? optionValue : ""));
1391
- const isTarget = "target" in ((_b = (_a = itemRef.current) == null ? void 0 : _a.dataset) != null ? _b : {});
1392
- const isFocused = index === focusedIndex;
1393
- const onClick = (0, import_react.useCallback)(
1394
- (ev) => {
1395
- ev.stopPropagation();
1396
- if (isDisabled) {
1397
- if (inputRef.current) inputRef.current.focus();
1398
- return;
1399
- }
1400
- if (!isTargetOption(ev.currentTarget)) {
1401
- if (inputRef.current) inputRef.current.focus();
1402
- return;
1403
- }
1404
- setFocusedIndex(index);
1405
- onChange(optionValue != null ? optionValue : "");
1406
- if (inputRef.current) inputRef.current.focus();
1407
- if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect) onClose();
1408
- if (omitSelectedValues) onFocusNext(index);
1409
- },
1410
- [
1411
- onFocusNext,
1412
- omitSelectedValues,
1413
- isDisabled,
1414
- optionValue,
1415
- setFocusedIndex,
1416
- index,
1417
- onChange,
1418
- customCloseOnSelect,
1419
- generalCloseOnSelect,
1420
- onClose,
1421
- inputRef
1422
- ]
1423
- );
1424
- (0, import_utils6.useUpdateEffect)(() => {
1425
- if (isSelected) onChangeLabel(optionValue != null ? optionValue : "", { runOmit: false });
1426
- }, [optionValue]);
1427
- const getOptionProps = (0, import_react.useCallback)(
1428
- (props2 = {}, ref = null) => {
1429
- const style = {
1430
- border: "0px",
1431
- clip: "rect(0px, 0px, 0px, 0px)",
1432
- height: "1px",
1433
- width: "1px",
1434
- margin: "-1px",
1435
- padding: "0px",
1436
- overflow: "hidden",
1437
- whiteSpace: "nowrap",
1438
- position: "absolute"
1439
- };
1440
- return {
1441
- ref: (0, import_utils6.mergeRefs)(itemRef, ref, register),
1442
- id: (0, import_react.useId)(),
1443
- role: "option",
1444
- ...computedProps,
1445
- ...props2,
1446
- tabIndex: -1,
1447
- style: !isTarget || omitSelectedValues && isSelected ? style : void 0,
1448
- "data-target": (0, import_utils6.dataAttr)(true),
1449
- "data-value": optionValue != null ? optionValue : "",
1450
- "data-focus": (0, import_utils6.dataAttr)(isFocused),
1451
- "data-disabled": (0, import_utils6.dataAttr)(isDisabled),
1452
- "aria-checked": isSelected,
1453
- "aria-disabled": (0, import_utils6.ariaAttr)(isDisabled),
1454
- onClick: (0, import_utils6.handlerAll)(computedProps.onClick, props2.onClick, onClick)
1455
- };
1456
- },
1457
- [
1458
- optionValue,
1459
- computedProps,
1460
- isDisabled,
1461
- isFocused,
1462
- isSelected,
1463
- isTarget,
1464
- omitSelectedValues,
1465
- onClick,
1466
- register
1467
- ]
1468
- );
1469
- return {
1470
- isSelected,
1471
- isFocused,
1472
- customIcon,
1473
- children,
1474
- getOptionProps
1475
- };
1476
- };
1477
- var useAutocompleteCreate = () => {
1478
- const { isHit, onCreate } = useAutocompleteContext();
1479
- const getCreateProps = (0, import_react.useCallback)(
1480
- (props = {}, ref = null) => {
1481
- const style = {
1482
- border: "0px",
1483
- clip: "rect(0px, 0px, 0px, 0px)",
1484
- height: "1px",
1485
- width: "1px",
1486
- margin: "-1px",
1487
- padding: "0px",
1488
- overflow: "hidden",
1489
- whiteSpace: "nowrap",
1490
- position: "absolute"
1491
- };
1492
- return {
1493
- ref,
1494
- ...props,
1495
- tabIndex: -1,
1496
- style: isHit ? style : void 0,
1497
- "data-focus": (0, import_utils6.dataAttr)(!isHit),
1498
- onClick: (0, import_utils6.handlerAll)(props.onClick, onCreate)
1499
- };
1500
- },
1501
- [isHit, onCreate]
1502
- );
1503
- return { getCreateProps };
1504
- };
1505
- var useAutocompleteEmpty = () => {
1506
- const { isHit, isEmpty } = useAutocompleteContext();
1507
- const getEmptyProps = (0, import_react.useCallback)(
1508
- (props = {}, ref = null) => {
1509
- const style = {
1510
- border: "0px",
1511
- clip: "rect(0px, 0px, 0px, 0px)",
1512
- height: "1px",
1513
- width: "1px",
1514
- margin: "-1px",
1515
- padding: "0px",
1516
- overflow: "hidden",
1517
- whiteSpace: "nowrap",
1518
- position: "absolute"
1519
- };
1520
- return {
1521
- ref,
1522
- ...props,
1523
- tabIndex: -1,
1524
- style: isHit && !isEmpty ? style : void 0
1525
- };
1526
- },
1527
- [isHit, isEmpty]
1528
- );
1529
- return { getEmptyProps };
1530
- };
1531
-
1532
- // src/autocomplete-icon.tsx
1533
- var import_jsx_runtime7 = require("react/jsx-runtime");
1534
- var AutocompleteIcon = (0, import_core7.forwardRef)(
1535
- ({ className, children, __css, ...rest }, ref) => {
1536
- const { styles } = useAutocompleteContext();
1537
- const css = {
1538
- position: "absolute",
1539
- top: "50%",
1540
- transform: "translateY(-50%)",
1541
- display: "inline-flex",
1542
- alignItems: "center",
1543
- justifyContent: "center",
1544
- pointerEvents: "none",
1545
- cursor: "pointer",
1546
- ...styles.icon,
1547
- ...__css
1548
- };
1549
- const validChildren = (0, import_utils7.getValidChildren)(children);
1550
- const cloneChildren = validChildren.map(
1551
- (child) => (0, import_react2.cloneElement)(child, {
1552
- focusable: false,
1553
- "aria-hidden": true,
1554
- style: {
1555
- maxWidth: "1em",
1556
- maxHeight: "1em",
1557
- color: "currentColor"
1558
- }
1559
- })
1560
- );
1561
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1562
- import_core7.ui.div,
1563
- {
1564
- ref,
1565
- className: (0, import_utils7.cx)("ui-autocomplete__icon", className),
1566
- __css: css,
1567
- ...rest,
1568
- children: (0, import_utils7.isValidElement)(children) ? cloneChildren : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_icon.ChevronIcon, {})
1569
- }
1570
- );
1571
- }
1572
- );
1573
- var AutocompleteItemIcon = (0, import_core7.forwardRef)(({ className, ...rest }, ref) => {
1574
- const { styles } = useAutocompleteContext();
1575
- const css = {
1576
- flexShrink: 0,
1577
- display: "inline-flex",
1578
- justifyContent: "center",
1579
- alignItems: "center",
1580
- fontSize: "0.85em",
1581
- ...styles.itemIcon
1582
- };
1583
- return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
1584
- import_core7.ui.span,
1585
- {
1586
- ref,
1587
- className: (0, import_utils7.cx)("ui-autocomplete__item__icon", className),
1588
- __css: css,
1589
- ...rest
1590
- }
1591
- );
1592
- });
1593
1605
 
1594
1606
  // src/autocomplete.tsx
1595
1607
  var import_jsx_runtime8 = require("react/jsx-runtime");
1596
- var Autocomplete = (0, import_core8.forwardRef)(
1608
+ var Autocomplete = (0, import_core9.forwardRef)(
1597
1609
  (props, ref) => {
1598
- const [styles, mergedProps] = (0, import_core8.useMultiComponentStyle)("Autocomplete", props);
1610
+ const [styles, mergedProps] = (0, import_core9.useComponentMultiStyle)("Autocomplete", props);
1599
1611
  let {
1600
1612
  className,
1601
1613
  defaultValue = "",
@@ -1617,7 +1629,7 @@ var Autocomplete = (0, import_core8.forwardRef)(
1617
1629
  footer,
1618
1630
  children,
1619
1631
  ...computedProps
1620
- } = (0, import_core8.omitThemeProps)(mergedProps);
1632
+ } = (0, import_core9.omitThemeProps)(mergedProps);
1621
1633
  const {
1622
1634
  value,
1623
1635
  onClose,
@@ -1654,14 +1666,14 @@ var Autocomplete = (0, import_core8.forwardRef)(
1654
1666
  styles
1655
1667
  },
1656
1668
  children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_popover2.Popover, { ...getPopoverProps(), children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1657
- import_core8.ui.div,
1669
+ import_core9.ui.div,
1658
1670
  {
1659
- className: (0, import_utils8.cx)("ui-autocomplete", className),
1671
+ className: (0, import_utils12.cx)("ui-autocomplete", className),
1660
1672
  __css: css,
1661
1673
  ...getContainerProps(containerProps),
1662
1674
  children: [
1663
1675
  /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1664
- import_core8.ui.div,
1676
+ import_core9.ui.div,
1665
1677
  {
1666
1678
  className: "ui-autocomplete__inner",
1667
1679
  __css: { position: "relative", ...styles.inner },
@@ -1682,8 +1694,8 @@ var Autocomplete = (0, import_core8.forwardRef)(
1682
1694
  !isEmpty ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_portal.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(
1683
1695
  AutocompleteList,
1684
1696
  {
1685
- header: (0, import_utils8.runIfFunc)(header, { value, onClose }),
1686
- footer: (0, import_utils8.runIfFunc)(footer, { value, onClose }),
1697
+ header: (0, import_utils12.runIfFunc)(header, { value, onClose }),
1698
+ footer: (0, import_utils12.runIfFunc)(footer, { value, onClose }),
1687
1699
  contentProps,
1688
1700
  ...listProps,
1689
1701
  children: [
@@ -1694,8 +1706,8 @@ var Autocomplete = (0, import_core8.forwardRef)(
1694
1706
  ) }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_portal.Portal, { ...portalProps, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1695
1707
  AutocompleteList,
1696
1708
  {
1697
- header: (0, import_utils8.runIfFunc)(header, { value, onClose }),
1698
- footer: (0, import_utils8.runIfFunc)(footer, { value, onClose }),
1709
+ header: (0, import_utils12.runIfFunc)(header, { value, onClose }),
1710
+ footer: (0, import_utils12.runIfFunc)(footer, { value, onClose }),
1699
1711
  contentProps,
1700
1712
  ...listProps,
1701
1713
  children: allowCreate && inputValue ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteCreate, { ...createProps }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(AutocompleteEmpty, { ...emptyProps })
@@ -1708,7 +1720,7 @@ var Autocomplete = (0, import_core8.forwardRef)(
1708
1720
  ) });
1709
1721
  }
1710
1722
  );
1711
- var AutocompleteField = (0, import_core8.forwardRef)(
1723
+ var AutocompleteField = (0, import_core9.forwardRef)(
1712
1724
  ({ className, h, minH, placeholder, inputProps, ...rest }, ref) => {
1713
1725
  const { label, inputValue, styles } = useAutocompleteContext();
1714
1726
  const { getInputProps } = useAutocompleteInput();
@@ -1722,13 +1734,13 @@ var AutocompleteField = (0, import_core8.forwardRef)(
1722
1734
  cursor: "text"
1723
1735
  };
1724
1736
  return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_popover2.PopoverTrigger, { children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1725
- import_core8.ui.div,
1737
+ import_core9.ui.div,
1726
1738
  {
1727
- className: (0, import_utils8.cx)("ui-autocomplete__field", className),
1739
+ className: (0, import_utils12.cx)("ui-autocomplete__field", className),
1728
1740
  __css: css,
1729
1741
  ...rest,
1730
1742
  children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
1731
- import_core8.ui.input,
1743
+ import_core9.ui.input,
1732
1744
  {
1733
1745
  className: "ui-autocomplete__field__input",
1734
1746
  display: "inline-block",