@yamada-ui/autocomplete 0.1.0

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.
@@ -0,0 +1,1246 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/use-autocomplete.tsx
21
+ var use_autocomplete_exports = {};
22
+ __export(use_autocomplete_exports, {
23
+ AutocompleteDescendantsContextProvider: () => AutocompleteDescendantsContextProvider,
24
+ AutocompleteProvider: () => AutocompleteProvider,
25
+ useAutocomplete: () => useAutocomplete,
26
+ useAutocompleteContext: () => useAutocompleteContext,
27
+ useAutocompleteCreate: () => useAutocompleteCreate,
28
+ useAutocompleteDescendant: () => useAutocompleteDescendant,
29
+ useAutocompleteDescendants: () => useAutocompleteDescendants,
30
+ useAutocompleteDescendantsContext: () => useAutocompleteDescendantsContext,
31
+ useAutocompleteEmpty: () => useAutocompleteEmpty,
32
+ useAutocompleteInput: () => useAutocompleteInput,
33
+ useAutocompleteList: () => useAutocompleteList,
34
+ useAutocompleteOption: () => useAutocompleteOption,
35
+ useAutocompleteOptionGroup: () => useAutocompleteOptionGroup
36
+ });
37
+ module.exports = __toCommonJS(use_autocomplete_exports);
38
+ var import_core4 = require("@yamada-ui/core");
39
+ var import_form_control = require("@yamada-ui/form-control");
40
+ var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
41
+ var import_use_descendant = require("@yamada-ui/use-descendant");
42
+ var import_use_outside_click = require("@yamada-ui/use-outside-click");
43
+ var import_utils4 = require("@yamada-ui/utils");
44
+ var import_react2 = require("react");
45
+
46
+ // src/autocomplete-icon.tsx
47
+ var import_core = require("@yamada-ui/core");
48
+ var import_icon = require("@yamada-ui/icon");
49
+ var import_use_clickable = require("@yamada-ui/use-clickable");
50
+ var import_utils = require("@yamada-ui/utils");
51
+ var import_react = require("react");
52
+ var import_jsx_runtime = require("react/jsx-runtime");
53
+ var AutocompleteIcon = (0, import_core.forwardRef)(
54
+ ({ className, children, __css, ...rest }, ref) => {
55
+ const { styles } = useAutocompleteContext();
56
+ const css = {
57
+ position: "absolute",
58
+ top: "50%",
59
+ transform: "translateY(-50%)",
60
+ display: "inline-flex",
61
+ alignItems: "center",
62
+ justifyContent: "center",
63
+ pointerEvents: "none",
64
+ cursor: "pointer",
65
+ ...styles.icon,
66
+ ...__css
67
+ };
68
+ const validChildren = (0, import_utils.getValidChildren)(children);
69
+ const cloneChildren = validChildren.map(
70
+ (child) => (0, import_react.cloneElement)(child, {
71
+ focusable: false,
72
+ "aria-hidden": true,
73
+ style: {
74
+ maxWidth: "1em",
75
+ maxHeight: "1em",
76
+ color: "currentColor"
77
+ }
78
+ })
79
+ );
80
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_core.ui.div, { ref, className: (0, import_utils.cx)("ui-autocomplete-icon", className), __css: css, ...rest, children: (0, import_utils.isValidElement)(children) ? cloneChildren : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_icon.ChevronIcon, {}) });
81
+ }
82
+ );
83
+ var AutocompleteItemIcon = (0, import_core.forwardRef)(
84
+ ({ className, ...rest }, ref) => {
85
+ const { styles } = useAutocompleteContext();
86
+ const css = {
87
+ flexShrink: 0,
88
+ display: "inline-flex",
89
+ justifyContent: "center",
90
+ alignItems: "center",
91
+ fontSize: "0.85em",
92
+ ...styles.itemIcon
93
+ };
94
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
95
+ import_core.ui.span,
96
+ {
97
+ ref,
98
+ className: (0, import_utils.cx)("ui-autocomplete-item-icon", className),
99
+ __css: css,
100
+ ...rest
101
+ }
102
+ );
103
+ }
104
+ );
105
+
106
+ // src/autocomplete-option-group.tsx
107
+ var import_core2 = require("@yamada-ui/core");
108
+ var import_utils2 = require("@yamada-ui/utils");
109
+ var import_jsx_runtime2 = require("react/jsx-runtime");
110
+ var AutocompleteOptionGroup = (0, import_core2.forwardRef)(
111
+ ({ className, color, h, height, minH, minHeight, children, ...rest }, ref) => {
112
+ const { styles } = useAutocompleteContext();
113
+ const { label, getContainerProps, getGroupProps } = useAutocompleteOptionGroup(rest);
114
+ h = h != null ? h : height;
115
+ minH = minH != null ? minH : minHeight;
116
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
117
+ import_core2.ui.li,
118
+ {
119
+ className: "ui-autocomplete-group-container",
120
+ __css: { w: "100%", h: "fit-content", color },
121
+ ...getContainerProps(),
122
+ children: [
123
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
124
+ import_core2.ui.span,
125
+ {
126
+ className: (0, import_utils2.cx)("ui-autocomplete-group-label"),
127
+ __css: styles.groupLabel,
128
+ noOfLines: 1,
129
+ children: label
130
+ }
131
+ ),
132
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
133
+ import_core2.ui.ul,
134
+ {
135
+ ...getGroupProps({}, ref),
136
+ className: (0, import_utils2.cx)("ui-autocomplete-group", className),
137
+ __css: { h, minH, ...styles.group },
138
+ children
139
+ }
140
+ )
141
+ ]
142
+ }
143
+ );
144
+ }
145
+ );
146
+
147
+ // src/autocomplete-option.tsx
148
+ var import_core3 = require("@yamada-ui/core");
149
+ var import_utils3 = require("@yamada-ui/utils");
150
+ var import_jsx_runtime3 = require("react/jsx-runtime");
151
+ var AutocompleteOption = (0, import_core3.forwardRef)(
152
+ ({ className, icon, ...rest }, ref) => {
153
+ const { styles } = useAutocompleteContext();
154
+ const { isSelected, customIcon, children, getOptionProps } = useAutocompleteOption(rest);
155
+ icon = icon != null ? icon : customIcon;
156
+ const css = {
157
+ textDecoration: "none",
158
+ color: "inherit",
159
+ userSelect: "none",
160
+ display: "flex",
161
+ width: "100%",
162
+ alignItems: "center",
163
+ textAlign: "start",
164
+ flex: "0 0 auto",
165
+ outline: 0,
166
+ gap: "0.75rem",
167
+ ...styles.item
168
+ };
169
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
170
+ import_core3.ui.li,
171
+ {
172
+ className: (0, import_utils3.cx)("ui-autocomplete-item", className),
173
+ __css: css,
174
+ ...getOptionProps({}, ref),
175
+ children: [
176
+ icon !== null ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(AutocompleteItemIcon, { opacity: isSelected ? 1 : 0, children: icon || /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CheckIcon, {}) }) : null,
177
+ icon ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_core3.ui.span, { style: { pointerEvents: "none", flex: 1 }, noOfLines: 1, children }) : children
178
+ ]
179
+ }
180
+ );
181
+ }
182
+ );
183
+ 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)(
184
+ "polygon",
185
+ {
186
+ fill: "currentColor",
187
+ points: "5.5 11.9993304 14 3.49933039 12.5 2 5.5 8.99933039 1.5 4.9968652 0 6.49933039"
188
+ }
189
+ ) });
190
+
191
+ // src/use-autocomplete.tsx
192
+ var import_jsx_runtime4 = require("react/jsx-runtime");
193
+ var kanaMap = {
194
+ \uFF76\uFF9E: "\u30AC",
195
+ \uFF77\uFF9E: "\u30AE",
196
+ \uFF78\uFF9E: "\u30B0",
197
+ \uFF79\uFF9E: "\u30B2",
198
+ \uFF7A\uFF9E: "\u30B4",
199
+ \uFF7B\uFF9E: "\u30B6",
200
+ \uFF7C\uFF9E: "\u30B8",
201
+ \uFF7D\uFF9E: "\u30BA",
202
+ \uFF7E\uFF9E: "\u30BC",
203
+ \uFF7F\uFF9E: "\u30BE",
204
+ \uFF80\uFF9E: "\u30C0",
205
+ \uFF81\uFF9E: "\u30C2",
206
+ \uFF82\uFF9E: "\u30C5",
207
+ \uFF83\uFF9E: "\u30C7",
208
+ \uFF84\uFF9E: "\u30C9",
209
+ \uFF8A\uFF9E: "\u30D0",
210
+ \uFF8B\uFF9E: "\u30D3",
211
+ \uFF8C\uFF9E: "\u30D6",
212
+ \uFF8D\uFF9E: "\u30D9",
213
+ \uFF8E\uFF9E: "\u30DC",
214
+ \uFF8A\uFF9F: "\u30D1",
215
+ \uFF8B\uFF9F: "\u30D4",
216
+ \uFF8C\uFF9F: "\u30D7",
217
+ \uFF8D\uFF9F: "\u30DA",
218
+ \uFF8E\uFF9F: "\u30DD",
219
+ \uFF73\uFF9E: "\u30F4",
220
+ \uFF9C\uFF9E: "\u30F7",
221
+ \uFF66\uFF9E: "\u30FA",
222
+ \uFF71: "\u30A2",
223
+ \uFF72: "\u30A4",
224
+ \uFF73: "\u30A6",
225
+ \uFF74: "\u30A8",
226
+ \uFF75: "\u30AA",
227
+ \uFF76: "\u30AB",
228
+ \uFF77: "\u30AD",
229
+ \uFF78: "\u30AF",
230
+ \uFF79: "\u30B1",
231
+ \uFF7A: "\u30B3",
232
+ \uFF7B: "\u30B5",
233
+ \uFF7C: "\u30B7",
234
+ \uFF7D: "\u30B9",
235
+ \uFF7E: "\u30BB",
236
+ \uFF7F: "\u30BD",
237
+ \uFF80: "\u30BF",
238
+ \uFF81: "\u30C1",
239
+ \uFF82: "\u30C4",
240
+ \uFF83: "\u30C6",
241
+ \uFF84: "\u30C8",
242
+ \uFF85: "\u30CA",
243
+ \uFF86: "\u30CB",
244
+ \uFF87: "\u30CC",
245
+ \uFF88: "\u30CD",
246
+ \uFF89: "\u30CE",
247
+ \uFF8A: "\u30CF",
248
+ \uFF8B: "\u30D2",
249
+ \uFF8C: "\u30D5",
250
+ \uFF8D: "\u30D8",
251
+ \uFF8E: "\u30DB",
252
+ \uFF8F: "\u30DE",
253
+ \uFF90: "\u30DF",
254
+ \uFF91: "\u30E0",
255
+ \uFF92: "\u30E1",
256
+ \uFF93: "\u30E2",
257
+ \uFF94: "\u30E4",
258
+ \uFF95: "\u30E6",
259
+ \uFF96: "\u30E8",
260
+ \uFF97: "\u30E9",
261
+ \uFF98: "\u30EA",
262
+ \uFF99: "\u30EB",
263
+ \uFF9A: "\u30EC",
264
+ \uFF9B: "\u30ED",
265
+ \uFF9C: "\u30EF",
266
+ \uFF66: "\u30F2",
267
+ \uFF9D: "\u30F3",
268
+ \uFF67: "\u30A1",
269
+ \uFF68: "\u30A3",
270
+ \uFF69: "\u30A5",
271
+ \uFF6A: "\u30A7",
272
+ \uFF6B: "\u30A9",
273
+ \uFF6F: "\u30C3",
274
+ \uFF6C: "\u30E3",
275
+ \uFF6D: "\u30E5",
276
+ \uFF6E: "\u30E7",
277
+ "\uFF61": "\u3002",
278
+ "\uFF64": "\u3001",
279
+ \uFF70: "\u30FC",
280
+ "\uFF62": "\u300C",
281
+ "\uFF63": "\u300D",
282
+ "\uFF65": "\u30FB"
283
+ };
284
+ var defaultFormat = (value) => {
285
+ value = value.replace(/[!-~]/g, (v) => String.fromCharCode(v.charCodeAt(0) - 65248));
286
+ const reg = new RegExp("(" + Object.keys(kanaMap).join("|") + ")", "g");
287
+ value = value.replace(reg, (v) => kanaMap[v]).replace(/゙/g, "\u309B").replace(/゚/g, "\u309C");
288
+ value = value.toUpperCase();
289
+ return value;
290
+ };
291
+ var flattenData = (data) => {
292
+ const filterData = (data2) => data2.map((data3) => {
293
+ const { value, isDisabled, isFocusable } = data3;
294
+ const trulyDisabled = !!isDisabled && !isFocusable;
295
+ const isMulti = (0, import_utils4.isArray)(value);
296
+ if (trulyDisabled)
297
+ return;
298
+ if (!isMulti) {
299
+ return data3;
300
+ } else {
301
+ return filterData(value);
302
+ }
303
+ }).filter(Boolean);
304
+ return filterData(data).flat(Infinity);
305
+ };
306
+ var isTargetOption = (target) => {
307
+ var _a;
308
+ return (0, import_utils4.isHTMLElement)(target) && !!((_a = target == null ? void 0 : target.getAttribute("role")) == null ? void 0 : _a.startsWith("autocomplete-item"));
309
+ };
310
+ var {
311
+ DescendantsContextProvider: AutocompleteDescendantsContextProvider,
312
+ useDescendantsContext: useAutocompleteDescendantsContext,
313
+ useDescendants: useAutocompleteDescendants,
314
+ useDescendant: useAutocompleteDescendant
315
+ } = (0, import_use_descendant.createDescendant)();
316
+ var [AutocompleteProvider, useAutocompleteContext] = (0, import_utils4.createContext)({
317
+ name: "AutocompleteContext",
318
+ errorMessage: `useAutocompleteContext returned is 'undefined'. Seems you forgot to wrap the components in "<Autocomplete />" or "<MultiAutocomplete />"`
319
+ });
320
+ var useAutocomplete = ({
321
+ defaultIsOpen,
322
+ closeOnSelect = true,
323
+ omitSelectedValues = false,
324
+ maxSelectedValues,
325
+ closeOnBlur = true,
326
+ closeOnEsc = true,
327
+ createOption = false,
328
+ createOrder = "first",
329
+ createSecondOrder = "first",
330
+ emptyMessage = "No results found",
331
+ format = defaultFormat,
332
+ placement = "bottom-start",
333
+ duration = 0.2,
334
+ optionProps,
335
+ placeholder,
336
+ children,
337
+ ...rest
338
+ }) => {
339
+ rest = (0, import_form_control.useFormControlProps)(rest);
340
+ const { id } = rest;
341
+ const formControlProps = (0, import_utils4.pickObject)(rest, import_form_control.formControlProperties);
342
+ const [containerProps, inputProps] = (0, import_utils4.splitObject)(
343
+ (0, import_utils4.omitObject)(rest, ["id", "value", "onChange", "month", "onChangeMonth"]),
344
+ import_core4.layoutStylesProperties
345
+ );
346
+ const descendants = useAutocompleteDescendants();
347
+ const containerRef = (0, import_react2.useRef)(null);
348
+ const listRef = (0, import_react2.useRef)(null);
349
+ const inputRef = (0, import_react2.useRef)(null);
350
+ const timeoutIds = (0, import_react2.useRef)(/* @__PURE__ */ new Set([]));
351
+ const isComposition = (0, import_react2.useRef)(false);
352
+ const [data, setData] = (0, import_react2.useState)(rest.data);
353
+ const [value, setValue] = (0, import_use_controllable_state.useControllableState)({
354
+ value: rest.value,
355
+ defaultValue: rest.defaultValue,
356
+ onChange: rest.onChange
357
+ });
358
+ const [displayValue, setDisplayValue] = (0, import_react2.useState)(void 0);
359
+ const [inputValue, setInputValue] = (0, import_react2.useState)("");
360
+ const [focusedIndex, setFocusedIndex] = (0, import_react2.useState)(-1);
361
+ const [isAllSelected, setIsAllSelected] = (0, import_react2.useState)(false);
362
+ const [isHit, setIsHit] = (0, import_react2.useState)(true);
363
+ const [isOpen, setIsOpen] = (0, import_react2.useState)(defaultIsOpen != null ? defaultIsOpen : false);
364
+ const isFocused = focusedIndex > -1;
365
+ const isCreate = focusedIndex === -2 && createOption;
366
+ const isMulti = (0, import_utils4.isArray)(value);
367
+ const isEmptyValue = !isMulti ? !value : !value.length;
368
+ if (createOption && !(0, import_utils4.isUndefined)(children)) {
369
+ console.warn(
370
+ `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: ${!isMulti ? "Autocomplete" : "MultiAutocomplete"} internally prefers 'children'. If 'createOption' is true, it will not be reflected correctly. If want to reflect, please set 'data' in props.`
371
+ );
372
+ }
373
+ const selectedValues = descendants.enabledValues(
374
+ ({ node }) => {
375
+ var _a;
376
+ return isMulti && value.includes((_a = node.dataset.value) != null ? _a : "");
377
+ }
378
+ );
379
+ const selectedIndexes = selectedValues.map(({ index }) => index);
380
+ const enabledValues = descendants.enabledValues(
381
+ ({ node, index }) => "target" in node.dataset && !selectedIndexes.includes(index)
382
+ );
383
+ const validChildren = (0, import_utils4.getValidChildren)(children);
384
+ const computedChildren = data == null ? void 0 : data.map(({ label, value: value2, ...props }, i) => {
385
+ if (!(0, import_utils4.isArray)(value2)) {
386
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value2, ...props, children: label }, i);
387
+ } else {
388
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOptionGroup, { label, ...props, children: value2.map(
389
+ ({ label: label2, value: value3, ...props2 }, i2) => !(0, import_utils4.isArray)(value3) ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(AutocompleteOption, { value: value3, ...props2, children: label2 }, i2) : null
390
+ ) }, i);
391
+ }
392
+ });
393
+ const isEmpty = !validChildren.length && !(computedChildren == null ? void 0 : computedChildren.length);
394
+ const onOpen = (0, import_react2.useCallback)(() => {
395
+ var _a;
396
+ if (formControlProps.disabled || formControlProps.readOnly)
397
+ return;
398
+ if (!createOption && (isEmpty || isAllSelected))
399
+ return;
400
+ setIsOpen(true);
401
+ if (inputRef.current)
402
+ inputRef.current.focus();
403
+ (_a = rest.onOpen) == null ? void 0 : _a.call(rest);
404
+ }, [createOption, formControlProps, isAllSelected, isEmpty, rest]);
405
+ const onClose = (0, import_react2.useCallback)(() => {
406
+ var _a;
407
+ setIsOpen(false);
408
+ (_a = rest.onClose) == null ? void 0 : _a.call(rest);
409
+ }, [rest]);
410
+ const onFocusFirst = (0, import_react2.useCallback)(() => {
411
+ const id2 = setTimeout(() => {
412
+ if (isEmpty || isAllSelected)
413
+ return;
414
+ const first = descendants.enabledfirstValue(({ node }) => "target" in node.dataset);
415
+ if (!first)
416
+ return;
417
+ if (!isMulti || !omitSelectedValues) {
418
+ setFocusedIndex(first.index);
419
+ } else {
420
+ if (selectedIndexes.includes(first.index)) {
421
+ const enabledFirst = enabledValues[0];
422
+ setFocusedIndex(enabledFirst.index);
423
+ } else {
424
+ setFocusedIndex(first.index);
425
+ }
426
+ }
427
+ });
428
+ timeoutIds.current.add(id2);
429
+ }, [
430
+ descendants,
431
+ enabledValues,
432
+ isAllSelected,
433
+ isEmpty,
434
+ isMulti,
435
+ omitSelectedValues,
436
+ selectedIndexes
437
+ ]);
438
+ const onFocusLast = (0, import_react2.useCallback)(() => {
439
+ const id2 = setTimeout(() => {
440
+ if (isEmpty || isAllSelected)
441
+ return;
442
+ const last = descendants.enabledlastValue(({ node }) => "target" in node.dataset);
443
+ if (!last)
444
+ return;
445
+ if (!isMulti || !omitSelectedValues) {
446
+ setFocusedIndex(last.index);
447
+ } else {
448
+ if (selectedIndexes.includes(last.index)) {
449
+ const enabledlast = enabledValues.reverse()[0];
450
+ setFocusedIndex(enabledlast.index);
451
+ } else {
452
+ setFocusedIndex(last.index);
453
+ }
454
+ }
455
+ });
456
+ timeoutIds.current.add(id2);
457
+ }, [
458
+ descendants,
459
+ enabledValues,
460
+ isAllSelected,
461
+ isEmpty,
462
+ isMulti,
463
+ omitSelectedValues,
464
+ selectedIndexes
465
+ ]);
466
+ const onFocusSelected = (0, import_react2.useCallback)(() => {
467
+ const id2 = setTimeout(() => {
468
+ const values = descendants.enabledValues();
469
+ const selected = values.find(
470
+ ({ node }) => {
471
+ var _a;
472
+ return !isMulti ? node.dataset.value === value : value.includes((_a = node.dataset.value) != null ? _a : "");
473
+ }
474
+ );
475
+ if (selected)
476
+ setFocusedIndex(selected.index);
477
+ });
478
+ timeoutIds.current.add(id2);
479
+ }, [descendants, isMulti, value]);
480
+ const onFocusNext = (0, import_react2.useCallback)(
481
+ (index = focusedIndex) => {
482
+ const id2 = setTimeout(() => {
483
+ var _a;
484
+ const next = descendants.enabledNextValue(index, ({ node }) => "target" in node.dataset);
485
+ if (!next)
486
+ return;
487
+ if (!isMulti || !omitSelectedValues) {
488
+ setFocusedIndex(next.index);
489
+ } else {
490
+ if (selectedIndexes.includes(next.index)) {
491
+ const enabledNext = (_a = enabledValues.find(({ index: index2 }) => next.index < index2)) != null ? _a : enabledValues[0];
492
+ setFocusedIndex(enabledNext.index);
493
+ } else {
494
+ setFocusedIndex(next.index);
495
+ }
496
+ }
497
+ });
498
+ timeoutIds.current.add(id2);
499
+ },
500
+ [descendants, enabledValues, focusedIndex, isMulti, omitSelectedValues, selectedIndexes]
501
+ );
502
+ const onFocusPrev = (0, import_react2.useCallback)(
503
+ (index = focusedIndex) => {
504
+ const id2 = setTimeout(() => {
505
+ var _a;
506
+ const prev = descendants.enabledPrevValue(index, ({ node }) => "target" in node.dataset);
507
+ if (!prev)
508
+ return;
509
+ if (!isMulti || !omitSelectedValues) {
510
+ setFocusedIndex(prev.index);
511
+ } else {
512
+ if (selectedIndexes.includes(prev.index)) {
513
+ const enabledPrev = (_a = enabledValues.reverse().find(({ index: index2 }) => index2 < prev.index)) != null ? _a : enabledValues[0];
514
+ setFocusedIndex(enabledPrev.index);
515
+ } else {
516
+ setFocusedIndex(prev.index);
517
+ }
518
+ }
519
+ });
520
+ timeoutIds.current.add(id2);
521
+ },
522
+ [descendants, enabledValues, focusedIndex, isMulti, omitSelectedValues, selectedIndexes]
523
+ );
524
+ const onFocusFirstOrSelected = isEmptyValue || omitSelectedValues ? onFocusFirst : onFocusSelected;
525
+ const onFocusLastOrSelected = isEmptyValue || omitSelectedValues ? onFocusLast : onFocusSelected;
526
+ const pickOptions = (0, import_react2.useCallback)(
527
+ (value2) => {
528
+ const values = descendants.values();
529
+ let isHit2 = false;
530
+ let isFocused2 = false;
531
+ values.forEach(({ node, index }) => {
532
+ var _a;
533
+ if (format((_a = node.textContent) != null ? _a : "").includes(value2)) {
534
+ isHit2 = true;
535
+ const isDisabled = "disabled" in node.dataset;
536
+ node.dataset.target = "";
537
+ if (!isFocused2 && !isDisabled) {
538
+ isFocused2 = true;
539
+ setFocusedIndex(index);
540
+ }
541
+ } else {
542
+ delete node.dataset.target;
543
+ }
544
+ });
545
+ setIsHit(isHit2);
546
+ },
547
+ [descendants, format]
548
+ );
549
+ const rebirthOptions = (0, import_react2.useCallback)(
550
+ (runFocus = true) => {
551
+ const values = descendants.values();
552
+ values.forEach(({ node }) => {
553
+ node.dataset.target = "";
554
+ });
555
+ if (runFocus)
556
+ onFocusFirst();
557
+ setIsHit(true);
558
+ },
559
+ [descendants, onFocusFirst]
560
+ );
561
+ const onChangeDisplayValue = (0, import_react2.useCallback)(
562
+ (newValue, runOmit = true) => {
563
+ const enabledValues2 = descendants.enabledValues();
564
+ const selectedValues2 = enabledValues2.filter(({ node }) => node.dataset.value === newValue).map(({ node }) => {
565
+ var _a;
566
+ return (_a = node.textContent) != null ? _a : "";
567
+ });
568
+ setDisplayValue((prev) => {
569
+ if (!isMulti) {
570
+ return selectedValues2[0];
571
+ } else {
572
+ selectedValues2.forEach((selectedValue) => {
573
+ const isSelected = (0, import_utils4.isArray)(prev) && prev.includes(selectedValue != null ? selectedValue : "");
574
+ if (!isSelected) {
575
+ prev = [...(0, import_utils4.isArray)(prev) ? prev : [], selectedValue];
576
+ } else if (runOmit) {
577
+ prev = (0, import_utils4.isArray)(prev) ? prev.filter((value2) => value2 !== selectedValue) : void 0;
578
+ }
579
+ });
580
+ return prev;
581
+ }
582
+ });
583
+ },
584
+ [descendants, isMulti]
585
+ );
586
+ const onChange = (0, import_react2.useCallback)(
587
+ (newValue) => {
588
+ setValue((prev) => {
589
+ if (!(0, import_utils4.isArray)(prev)) {
590
+ return newValue;
591
+ } else {
592
+ const isSelected = prev.includes(newValue);
593
+ if (!isSelected) {
594
+ return [...prev, newValue];
595
+ } else {
596
+ return prev.filter((value2) => value2 !== newValue);
597
+ }
598
+ }
599
+ });
600
+ onChangeDisplayValue(newValue);
601
+ setInputValue("");
602
+ rebirthOptions(false);
603
+ },
604
+ [onChangeDisplayValue, rebirthOptions, setValue]
605
+ );
606
+ const onSelect = (0, import_react2.useCallback)(() => {
607
+ var _a, _b;
608
+ let enabledValue = descendants.value(focusedIndex);
609
+ if ("disabled" in ((_a = enabledValue == null ? void 0 : enabledValue.node.dataset) != null ? _a : {}))
610
+ enabledValue = void 0;
611
+ if (!enabledValue)
612
+ return;
613
+ const value2 = (_b = enabledValue.node.dataset.value) != null ? _b : "";
614
+ onChange(value2);
615
+ if (closeOnSelect)
616
+ onClose();
617
+ if (omitSelectedValues)
618
+ onFocusNext();
619
+ }, [closeOnSelect, descendants, focusedIndex, omitSelectedValues, onChange, onClose, onFocusNext]);
620
+ const onSearch = (0, import_react2.useCallback)(
621
+ (ev) => {
622
+ var _a;
623
+ if (!isOpen)
624
+ onOpen();
625
+ (_a = rest.onSearch) == null ? void 0 : _a.call(rest, ev);
626
+ const value2 = ev.target.value;
627
+ const computedValue = format(value2);
628
+ if (computedValue) {
629
+ pickOptions(computedValue);
630
+ } else {
631
+ rebirthOptions();
632
+ }
633
+ setInputValue(value2);
634
+ },
635
+ [isOpen, onOpen, format, rest, pickOptions, rebirthOptions]
636
+ );
637
+ const onCompositionStart = (0, import_react2.useCallback)(() => {
638
+ isComposition.current = true;
639
+ }, []);
640
+ const onCompositionEnd = (0, import_react2.useCallback)(() => {
641
+ isComposition.current = false;
642
+ }, []);
643
+ const onCreate = (0, import_react2.useCallback)(() => {
644
+ var _a;
645
+ if (!listRef.current)
646
+ return;
647
+ const newOption = { label: inputValue, value: inputValue };
648
+ let newData = [];
649
+ if (data)
650
+ newData = data;
651
+ if (createOrder === "first") {
652
+ newData = [newOption, ...newData];
653
+ } else if (createOrder === "last") {
654
+ newData = [...newData, newOption];
655
+ } else {
656
+ const i = newData.findIndex(({ label }) => label === createOrder);
657
+ if (i !== -1 && (0, import_utils4.isArray)(newData[i].value)) {
658
+ if (createSecondOrder === "first") {
659
+ newData[i].value = [newOption, ...newData[i].value];
660
+ } else {
661
+ newData[i].value = [...newData[i].value, newOption];
662
+ }
663
+ } else {
664
+ console.warn(
665
+ `${!isMulti ? "Autocomplete" : "MultiAutocomplete"}: '${createOrder}' specified in createOrder does not exist in the option group.`
666
+ );
667
+ }
668
+ }
669
+ setData(newData);
670
+ onChange(inputValue);
671
+ rebirthOptions(false);
672
+ const index = flattenData(newData).findIndex(({ value: value2 }) => value2 === inputValue);
673
+ setFocusedIndex(index);
674
+ (_a = rest.onCreate) == null ? void 0 : _a.call(rest, newOption, newData);
675
+ }, [inputValue, data, createOrder, onChange, rebirthOptions, rest, createSecondOrder, isMulti]);
676
+ const onDelete = (0, import_react2.useCallback)(() => {
677
+ if (!isMulti) {
678
+ onChange("");
679
+ } else {
680
+ onChange(value[value.length - 1]);
681
+ }
682
+ }, [isMulti, onChange, value]);
683
+ const onClear = (0, import_react2.useCallback)(
684
+ (ev) => {
685
+ ev.stopPropagation();
686
+ setValue([]);
687
+ setDisplayValue(void 0);
688
+ setInputValue("");
689
+ rebirthOptions();
690
+ if (inputRef.current)
691
+ inputRef.current.focus();
692
+ },
693
+ [setDisplayValue, setInputValue, setValue, rebirthOptions, inputRef]
694
+ );
695
+ const onClick = (0, import_react2.useCallback)(() => {
696
+ if (isOpen) {
697
+ if (inputRef.current)
698
+ inputRef.current.focus();
699
+ } else {
700
+ onOpen();
701
+ onFocusFirstOrSelected();
702
+ }
703
+ }, [isOpen, onFocusFirstOrSelected, onOpen]);
704
+ const onFocus = (0, import_react2.useCallback)(() => {
705
+ if (isOpen)
706
+ return;
707
+ onOpen();
708
+ onFocusFirstOrSelected();
709
+ }, [isOpen, onFocusFirstOrSelected, onOpen]);
710
+ const onBlur = (0, import_react2.useCallback)(
711
+ (ev) => {
712
+ const relatedTarget = (0, import_utils4.getEventRelatedTarget)(ev);
713
+ if ((0, import_utils4.isContains)(containerRef.current, relatedTarget))
714
+ return;
715
+ if (!closeOnBlur && isHit)
716
+ return;
717
+ setInputValue("");
718
+ if (isOpen)
719
+ onClose();
720
+ },
721
+ [closeOnBlur, isHit, isOpen, onClose]
722
+ );
723
+ const onKeyDown = (0, import_react2.useCallback)(
724
+ (ev) => {
725
+ if (ev.key === " ")
726
+ ev.key = ev.code;
727
+ if (formControlProps.disabled || formControlProps.readOnly)
728
+ return;
729
+ if (isComposition.current)
730
+ return;
731
+ const enabledDelete = displayValue === inputValue || !inputValue.length;
732
+ const actions = {
733
+ ArrowDown: isFocused ? () => onFocusNext() : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
734
+ ArrowUp: isFocused ? () => onFocusPrev() : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusLastOrSelected) : void 0,
735
+ Space: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
736
+ Enter: isCreate ? onCreate : isFocused ? onSelect : !isOpen ? (0, import_utils4.funcAll)(onOpen, onFocusFirstOrSelected) : void 0,
737
+ Home: isOpen ? onFocusFirst : void 0,
738
+ End: isOpen ? onFocusLast : void 0,
739
+ Escape: closeOnEsc ? onClose : void 0,
740
+ Backspace: !isEmptyValue && enabledDelete ? onDelete : void 0
741
+ };
742
+ const action = actions[ev.key];
743
+ if (!action)
744
+ return;
745
+ ev.preventDefault();
746
+ ev.stopPropagation();
747
+ action(ev);
748
+ },
749
+ [
750
+ formControlProps,
751
+ displayValue,
752
+ inputValue,
753
+ onOpen,
754
+ isFocused,
755
+ onFocusFirstOrSelected,
756
+ onFocusNext,
757
+ onFocusLastOrSelected,
758
+ onFocusPrev,
759
+ isCreate,
760
+ onCreate,
761
+ onSelect,
762
+ isOpen,
763
+ onFocusFirst,
764
+ onFocusLast,
765
+ closeOnEsc,
766
+ onClose,
767
+ isEmptyValue,
768
+ onDelete
769
+ ]
770
+ );
771
+ (0, import_react2.useEffect)(() => {
772
+ if (!isMulti)
773
+ return;
774
+ if (!omitSelectedValues && (0, import_utils4.isUndefined)(maxSelectedValues))
775
+ return;
776
+ const isAll = value.length > 0 && value.length === descendants.count();
777
+ const isMax = value.length === maxSelectedValues;
778
+ if (isAll || isMax) {
779
+ onClose();
780
+ setIsAllSelected(true);
781
+ } else {
782
+ setIsAllSelected(false);
783
+ }
784
+ }, [omitSelectedValues, value, descendants, isMulti, onClose, maxSelectedValues]);
785
+ (0, import_utils4.useUpdateEffect)(() => {
786
+ if (isOpen)
787
+ return;
788
+ setFocusedIndex(-1);
789
+ setInputValue("");
790
+ }, [isOpen]);
791
+ (0, import_utils4.useUpdateEffect)(() => {
792
+ if (!isHit)
793
+ setFocusedIndex(-2);
794
+ }, [isHit]);
795
+ (0, import_utils4.useUnmountEffect)(() => {
796
+ timeoutIds.current.forEach((id2) => clearTimeout(id2));
797
+ timeoutIds.current.clear();
798
+ });
799
+ (0, import_use_outside_click.useOutsideClick)({
800
+ ref: containerRef,
801
+ handler: onClose,
802
+ enabled: closeOnBlur || !isHit
803
+ });
804
+ const getPopoverProps = (0, import_react2.useCallback)(
805
+ (props) => ({
806
+ ...rest,
807
+ ...props,
808
+ isOpen,
809
+ onOpen,
810
+ onClose,
811
+ placement,
812
+ duration,
813
+ trigger: "never",
814
+ closeOnButton: false
815
+ }),
816
+ [duration, isOpen, onClose, onOpen, placement, rest]
817
+ );
818
+ const getContainerProps = (0, import_react2.useCallback)(
819
+ (props = {}, ref = null) => ({
820
+ ref: (0, import_utils4.mergeRefs)(containerRef, ref),
821
+ ...containerProps,
822
+ ...props,
823
+ ...formControlProps,
824
+ onClick: (0, import_utils4.handlerAll)(props.onClick, rest.onClick, onClick),
825
+ onFocus: (0, import_utils4.handlerAll)(props.onFocus, rest.onFocus, onFocus),
826
+ onBlur: (0, import_utils4.handlerAll)(props.onBlur, rest.onBlur, onBlur)
827
+ }),
828
+ [containerProps, formControlProps, onBlur, onClick, onFocus, rest]
829
+ );
830
+ const getFieldProps = (0, import_react2.useCallback)(
831
+ (props = {}, ref = null) => ({
832
+ ref,
833
+ tabIndex: -1,
834
+ ...props,
835
+ ...formControlProps,
836
+ placeholder,
837
+ "data-active": (0, import_utils4.dataAttr)(isOpen),
838
+ "aria-expanded": (0, import_utils4.dataAttr)(isOpen),
839
+ onKeyDown: (0, import_utils4.handlerAll)(props.onKeyDown, rest.onKeyDown, onKeyDown)
840
+ }),
841
+ [formControlProps, placeholder, isOpen, rest, onKeyDown]
842
+ );
843
+ return {
844
+ id,
845
+ descendants,
846
+ value,
847
+ displayValue,
848
+ inputValue,
849
+ isHit,
850
+ isEmpty,
851
+ computedChildren,
852
+ focusedIndex,
853
+ omitSelectedValues,
854
+ closeOnSelect,
855
+ createOption,
856
+ emptyMessage,
857
+ isOpen,
858
+ isAllSelected,
859
+ listRef,
860
+ inputRef,
861
+ optionProps,
862
+ formControlProps,
863
+ setFocusedIndex,
864
+ onChangeDisplayValue,
865
+ onChange,
866
+ onSearch,
867
+ onCreate,
868
+ onClear,
869
+ onCompositionStart,
870
+ onCompositionEnd,
871
+ pickOptions,
872
+ rebirthOptions,
873
+ onOpen,
874
+ onClose,
875
+ onFocusFirst,
876
+ onFocusLast,
877
+ onFocusSelected,
878
+ onFocusNext,
879
+ onFocusPrev,
880
+ getPopoverProps,
881
+ getContainerProps,
882
+ getFieldProps,
883
+ inputProps
884
+ };
885
+ };
886
+ var useAutocompleteInput = () => {
887
+ const {
888
+ id,
889
+ inputRef,
890
+ onSearch,
891
+ onCompositionStart,
892
+ onCompositionEnd,
893
+ isAllSelected,
894
+ formControlProps,
895
+ inputProps
896
+ } = useAutocompleteContext();
897
+ (0, import_utils4.useUpdateEffect)(() => {
898
+ if (isAllSelected && inputRef.current)
899
+ inputRef.current.blur();
900
+ }, [isAllSelected]);
901
+ const getInputProps = (0, import_react2.useCallback)(
902
+ (props = {}, ref = null) => ({
903
+ ref: (0, import_utils4.mergeRefs)(inputRef, ref),
904
+ ...formControlProps,
905
+ ...inputProps,
906
+ ...props,
907
+ id,
908
+ cursor: formControlProps.readOnly ? "default" : "text",
909
+ pointerEvents: formControlProps.disabled || isAllSelected ? "none" : "auto",
910
+ tabIndex: isAllSelected ? -1 : 0,
911
+ onChange: (0, import_utils4.handlerAll)(props.onChange, onSearch),
912
+ onCompositionStart: (0, import_utils4.handlerAll)(
913
+ props.onCompositionStart,
914
+ inputProps.onCompositionStart,
915
+ onCompositionStart
916
+ ),
917
+ onCompositionEnd: (0, import_utils4.handlerAll)(
918
+ props.onCompositionEnd,
919
+ inputProps.onCompositionEnd,
920
+ onCompositionEnd
921
+ )
922
+ }),
923
+ [
924
+ inputProps,
925
+ inputRef,
926
+ formControlProps,
927
+ id,
928
+ isAllSelected,
929
+ onSearch,
930
+ onCompositionStart,
931
+ onCompositionEnd
932
+ ]
933
+ );
934
+ return {
935
+ getInputProps
936
+ };
937
+ };
938
+ var useAutocompleteList = () => {
939
+ const { focusedIndex, isOpen, listRef, rebirthOptions } = useAutocompleteContext();
940
+ const descendants = useAutocompleteDescendantsContext();
941
+ const beforeFocusedIndex = (0, import_react2.useRef)(-1);
942
+ const selectedValue = descendants.value(focusedIndex);
943
+ const onAnimationComplete = (0, import_react2.useCallback)(() => {
944
+ if (!isOpen)
945
+ rebirthOptions(false);
946
+ }, [isOpen, rebirthOptions]);
947
+ (0, import_react2.useEffect)(() => {
948
+ if (!listRef.current || !selectedValue)
949
+ return;
950
+ const parent = listRef.current;
951
+ const child = selectedValue.node;
952
+ const parentHeight = parent.clientHeight;
953
+ const viewTop = parent.scrollTop;
954
+ const viewBottom = viewTop + parentHeight;
955
+ const childHeight = child.clientHeight;
956
+ const childTop = child.offsetTop;
957
+ const childBottom = childTop + childHeight;
958
+ const isInView = viewTop <= childTop && childBottom <= viewBottom;
959
+ const isScrollBottom = beforeFocusedIndex.current < selectedValue.index;
960
+ if (!isInView) {
961
+ if (childBottom <= parentHeight) {
962
+ listRef.current.scrollTo({ top: 0 });
963
+ } else {
964
+ if (!isScrollBottom) {
965
+ listRef.current.scrollTo({ top: childTop + 1 });
966
+ } else {
967
+ listRef.current.scrollTo({ top: childBottom - parentHeight });
968
+ }
969
+ }
970
+ }
971
+ beforeFocusedIndex.current = selectedValue.index;
972
+ }, [listRef, selectedValue]);
973
+ (0, import_utils4.useUpdateEffect)(() => {
974
+ if (!isOpen)
975
+ beforeFocusedIndex.current = -1;
976
+ }, [isOpen]);
977
+ const getListProps = (0, import_react2.useCallback)(
978
+ (props = {}, ref = null) => ({
979
+ as: "ul",
980
+ ref: (0, import_utils4.mergeRefs)(listRef, ref),
981
+ role: "select",
982
+ tabIndex: -1,
983
+ ...props,
984
+ onAnimationComplete: (0, import_utils4.handlerAll)(props.onAnimationComplete, onAnimationComplete)
985
+ }),
986
+ [listRef, onAnimationComplete]
987
+ );
988
+ return {
989
+ getListProps
990
+ };
991
+ };
992
+ var useAutocompleteOptionGroup = ({ label, ...rest }) => {
993
+ const { value, omitSelectedValues } = useAutocompleteContext();
994
+ const isMulti = (0, import_utils4.isArray)(value);
995
+ const descendants = useAutocompleteDescendantsContext();
996
+ const values = descendants.values();
997
+ const selectedValues = isMulti && omitSelectedValues ? descendants.values(({ node }) => {
998
+ var _a;
999
+ return value.includes((_a = node.dataset.value) != null ? _a : "");
1000
+ }) : [];
1001
+ const selectedIndexes = selectedValues.map(({ index }) => index);
1002
+ const childValues = values.filter(
1003
+ ({ node, index }) => {
1004
+ var _a;
1005
+ return ((_a = node.parentElement) == null ? void 0 : _a.dataset.label) === label && !selectedIndexes.includes(index) && "target" in node.dataset;
1006
+ }
1007
+ );
1008
+ const isEmpty = !childValues.length;
1009
+ const computedRest = (0, import_utils4.splitObject)(rest, import_core4.layoutStylesProperties);
1010
+ const getContainerProps = (0, import_react2.useCallback)(
1011
+ (props = {}, ref = null) => {
1012
+ const style = {
1013
+ border: "0px",
1014
+ clip: "rect(0px, 0px, 0px, 0px)",
1015
+ height: "1px",
1016
+ width: "1px",
1017
+ margin: "-1px",
1018
+ padding: "0px",
1019
+ overflow: "hidden",
1020
+ whiteSpace: "nowrap",
1021
+ position: "absolute"
1022
+ };
1023
+ return {
1024
+ ref,
1025
+ ...props,
1026
+ ...computedRest[0],
1027
+ style: isEmpty ? style : void 0,
1028
+ "data-label": label,
1029
+ role: "autocomplete-group-container"
1030
+ };
1031
+ },
1032
+ [computedRest, isEmpty, label]
1033
+ );
1034
+ const getGroupProps = (0, import_react2.useCallback)(
1035
+ (props = {}, ref = null) => ({
1036
+ ref,
1037
+ ...props,
1038
+ ...computedRest[1],
1039
+ "data-label": label,
1040
+ role: "autocomplete-group"
1041
+ }),
1042
+ [computedRest, label]
1043
+ );
1044
+ return {
1045
+ label,
1046
+ getContainerProps,
1047
+ getGroupProps
1048
+ };
1049
+ };
1050
+ var useAutocompleteOption = (props) => {
1051
+ var _a, _b, _c, _d;
1052
+ const {
1053
+ value,
1054
+ omitSelectedValues,
1055
+ onChange,
1056
+ onChangeDisplayValue,
1057
+ focusedIndex,
1058
+ setFocusedIndex,
1059
+ onClose,
1060
+ closeOnSelect: generalCloseOnSelect,
1061
+ optionProps,
1062
+ inputRef,
1063
+ onFocusNext
1064
+ } = useAutocompleteContext();
1065
+ let {
1066
+ icon: customIcon,
1067
+ isDisabled,
1068
+ isFocusable,
1069
+ closeOnSelect: customCloseOnSelect,
1070
+ children,
1071
+ ...computedProps
1072
+ } = { ...optionProps, ...props };
1073
+ const trulyDisabled = !!isDisabled && !isFocusable;
1074
+ const itemRef = (0, import_react2.useRef)(null);
1075
+ const { index, register, descendants } = useAutocompleteDescendant({ disabled: trulyDisabled });
1076
+ const values = descendants.values();
1077
+ const frontValues = values.slice(0, index);
1078
+ const isMulti = (0, import_utils4.isArray)(value);
1079
+ const isDuplicated = !isMulti ? frontValues.some(({ node }) => {
1080
+ var _a2;
1081
+ return node.dataset.value === ((_a2 = computedProps.value) != null ? _a2 : "");
1082
+ }) : false;
1083
+ const isSelected = !isDuplicated && (!isMulti ? ((_a = computedProps.value) != null ? _a : "") === value : value.includes((_b = computedProps.value) != null ? _b : ""));
1084
+ const isTarget = "target" in ((_d = (_c = itemRef.current) == null ? void 0 : _c.dataset) != null ? _d : {});
1085
+ const isFocused = index === focusedIndex;
1086
+ const onClick = (0, import_react2.useCallback)(
1087
+ (ev) => {
1088
+ var _a2;
1089
+ ev.stopPropagation();
1090
+ if (isDisabled) {
1091
+ if (inputRef.current)
1092
+ inputRef.current.focus();
1093
+ return;
1094
+ }
1095
+ if (!isTargetOption(ev.currentTarget)) {
1096
+ if (inputRef.current)
1097
+ inputRef.current.focus();
1098
+ return;
1099
+ }
1100
+ setFocusedIndex(index);
1101
+ onChange((_a2 = computedProps.value) != null ? _a2 : "");
1102
+ if (inputRef.current)
1103
+ inputRef.current.focus();
1104
+ if (customCloseOnSelect != null ? customCloseOnSelect : generalCloseOnSelect)
1105
+ onClose();
1106
+ if (omitSelectedValues)
1107
+ onFocusNext(index);
1108
+ },
1109
+ [
1110
+ onFocusNext,
1111
+ omitSelectedValues,
1112
+ isDisabled,
1113
+ computedProps,
1114
+ setFocusedIndex,
1115
+ index,
1116
+ onChange,
1117
+ customCloseOnSelect,
1118
+ generalCloseOnSelect,
1119
+ onClose,
1120
+ inputRef
1121
+ ]
1122
+ );
1123
+ (0, import_react2.useEffect)(() => {
1124
+ var _a2;
1125
+ if (isSelected)
1126
+ onChangeDisplayValue((_a2 = computedProps.value) != null ? _a2 : "", false);
1127
+ }, [computedProps, isSelected, onChangeDisplayValue]);
1128
+ const getOptionProps = (0, import_react2.useCallback)(
1129
+ (props2 = {}, ref = null) => {
1130
+ var _a2;
1131
+ const style = {
1132
+ border: "0px",
1133
+ clip: "rect(0px, 0px, 0px, 0px)",
1134
+ height: "1px",
1135
+ width: "1px",
1136
+ margin: "-1px",
1137
+ padding: "0px",
1138
+ overflow: "hidden",
1139
+ whiteSpace: "nowrap",
1140
+ position: "absolute"
1141
+ };
1142
+ return {
1143
+ ref: (0, import_utils4.mergeRefs)(itemRef, ref, register),
1144
+ ...(0, import_utils4.omitObject)(computedProps, ["value"]),
1145
+ ...props2,
1146
+ role: "autocomplete-item",
1147
+ tabIndex: -1,
1148
+ style: !isTarget || omitSelectedValues && isSelected ? style : void 0,
1149
+ "data-target": (0, import_utils4.dataAttr)(true),
1150
+ "data-value": (_a2 = computedProps.value) != null ? _a2 : "",
1151
+ "data-focus": (0, import_utils4.dataAttr)(isFocused),
1152
+ "data-disabled": (0, import_utils4.dataAttr)(isDisabled),
1153
+ "aria-checked": (0, import_utils4.ariaAttr)(isSelected),
1154
+ "aria-disabled": (0, import_utils4.ariaAttr)(isDisabled),
1155
+ onClick: (0, import_utils4.handlerAll)(computedProps.onClick, props2.onClick, onClick)
1156
+ };
1157
+ },
1158
+ [
1159
+ computedProps,
1160
+ isDisabled,
1161
+ isFocused,
1162
+ isSelected,
1163
+ isTarget,
1164
+ omitSelectedValues,
1165
+ onClick,
1166
+ register
1167
+ ]
1168
+ );
1169
+ return {
1170
+ isSelected,
1171
+ isFocused,
1172
+ customIcon,
1173
+ children,
1174
+ getOptionProps
1175
+ };
1176
+ };
1177
+ var useAutocompleteCreate = () => {
1178
+ const { isHit, onCreate } = useAutocompleteContext();
1179
+ const getCreateProps = (0, import_react2.useCallback)(
1180
+ (props = {}, ref = null) => {
1181
+ const style = {
1182
+ border: "0px",
1183
+ clip: "rect(0px, 0px, 0px, 0px)",
1184
+ height: "1px",
1185
+ width: "1px",
1186
+ margin: "-1px",
1187
+ padding: "0px",
1188
+ overflow: "hidden",
1189
+ whiteSpace: "nowrap",
1190
+ position: "absolute"
1191
+ };
1192
+ return {
1193
+ ref,
1194
+ ...props,
1195
+ tabIndex: -1,
1196
+ style: isHit ? style : void 0,
1197
+ "data-focus": (0, import_utils4.dataAttr)(!isHit),
1198
+ onClick: (0, import_utils4.handlerAll)(props.onClick, onCreate)
1199
+ };
1200
+ },
1201
+ [isHit, onCreate]
1202
+ );
1203
+ return { getCreateProps };
1204
+ };
1205
+ var useAutocompleteEmpty = () => {
1206
+ const { isHit, isEmpty } = useAutocompleteContext();
1207
+ const getEmptyProps = (0, import_react2.useCallback)(
1208
+ (props = {}, ref = null) => {
1209
+ const style = {
1210
+ border: "0px",
1211
+ clip: "rect(0px, 0px, 0px, 0px)",
1212
+ height: "1px",
1213
+ width: "1px",
1214
+ margin: "-1px",
1215
+ padding: "0px",
1216
+ overflow: "hidden",
1217
+ whiteSpace: "nowrap",
1218
+ position: "absolute"
1219
+ };
1220
+ return {
1221
+ ref,
1222
+ ...props,
1223
+ tabIndex: -1,
1224
+ style: isHit && !isEmpty ? style : void 0
1225
+ };
1226
+ },
1227
+ [isHit, isEmpty]
1228
+ );
1229
+ return { getEmptyProps };
1230
+ };
1231
+ // Annotate the CommonJS export names for ESM import in node:
1232
+ 0 && (module.exports = {
1233
+ AutocompleteDescendantsContextProvider,
1234
+ AutocompleteProvider,
1235
+ useAutocomplete,
1236
+ useAutocompleteContext,
1237
+ useAutocompleteCreate,
1238
+ useAutocompleteDescendant,
1239
+ useAutocompleteDescendants,
1240
+ useAutocompleteDescendantsContext,
1241
+ useAutocompleteEmpty,
1242
+ useAutocompleteInput,
1243
+ useAutocompleteList,
1244
+ useAutocompleteOption,
1245
+ useAutocompleteOptionGroup
1246
+ });