tfy-web-components 0.0.43 → 0.0.45

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 (190) hide show
  1. package/dist/{Button-CPJYHldw.js → Button-HHEfL8b9.js} +5 -4
  2. package/dist/{Button-CPJYHldw.js.map → Button-HHEfL8b9.js.map} +1 -1
  3. package/dist/CSPContext-Cldo9QDp.js +13 -0
  4. package/dist/CSPContext-Cldo9QDp.js.map +1 -0
  5. package/dist/{CompositeItem-DJWNsIwE.js → CompositeItem-GNejxLcK.js} +3 -3
  6. package/dist/{CompositeItem-DJWNsIwE.js.map → CompositeItem-GNejxLcK.js.map} +1 -1
  7. package/dist/{CompositeRoot-BlljDWkR.js → CompositeRoot-7_u1HqDT.js} +9 -47
  8. package/dist/CompositeRoot-7_u1HqDT.js.map +1 -0
  9. package/dist/DropdownMenu-Crlf-J4E.js +3304 -0
  10. package/dist/DropdownMenu-Crlf-J4E.js.map +1 -0
  11. package/dist/{Input-Dcxu6SVO.js → Input-BS9fWUAf.js} +3 -3
  12. package/dist/{Input-Dcxu6SVO.js.map → Input-BS9fWUAf.js.map} +1 -1
  13. package/dist/{Modal-BUWlwJcN.js → Modal-DaHG8mjy.js} +10 -10
  14. package/dist/{Modal-BUWlwJcN.js.map → Modal-DaHG8mjy.js.map} +1 -1
  15. package/dist/Popover-A8IyEt2w.js +400 -0
  16. package/dist/Popover-A8IyEt2w.js.map +1 -0
  17. package/dist/{Popover-BqqXJnK1.js → PopoverPopup-teGm7D5T.js} +25 -498
  18. package/dist/PopoverPopup-teGm7D5T.js.map +1 -0
  19. package/dist/PrehydrationScript-B3u_PP2W.js +49 -0
  20. package/dist/PrehydrationScript-B3u_PP2W.js.map +1 -0
  21. package/dist/Select-BtX40h2K.js +2187 -0
  22. package/dist/Select-BtX40h2K.js.map +1 -0
  23. package/dist/{useValueAsRef-BfFRcMg6.js → addEventListener-D-i9O6BG.js} +8 -8
  24. package/dist/addEventListener-D-i9O6BG.js.map +1 -0
  25. package/dist/clamp-D7_nsB8C.js +30 -0
  26. package/dist/clamp-D7_nsB8C.js.map +1 -0
  27. package/dist/components/atoms/Accordion.es.js +9 -9
  28. package/dist/components/atoms/Avatar.es.js +9 -9
  29. package/dist/components/atoms/Avatar.es.js.map +1 -1
  30. package/dist/components/atoms/Badge.d.ts +5 -6
  31. package/dist/components/atoms/Badge.es.js +80 -43
  32. package/dist/components/atoms/Badge.es.js.map +1 -1
  33. package/dist/components/atoms/Button.d.ts +1 -1
  34. package/dist/components/atoms/Button.es.js +2 -2
  35. package/dist/components/atoms/ButtonGroup.es.js +1 -1
  36. package/dist/components/atoms/Combobox.d.ts +34 -0
  37. package/dist/components/atoms/Combobox.es.js +3252 -0
  38. package/dist/components/atoms/Combobox.es.js.map +1 -0
  39. package/dist/components/atoms/ContextMenu.d.ts +12 -0
  40. package/dist/components/atoms/ContextMenu.es.js +259 -0
  41. package/dist/components/atoms/ContextMenu.es.js.map +1 -0
  42. package/dist/components/atoms/DropdownMenu.d.ts +51 -0
  43. package/dist/components/atoms/DropdownMenu.es.js +31 -0
  44. package/dist/components/atoms/DropdownMenu.es.js.map +1 -0
  45. package/dist/components/atoms/IconButton.d.ts +1 -1
  46. package/dist/components/atoms/IconButton.es.js +3 -3
  47. package/dist/components/atoms/IconButton.es.js.map +1 -1
  48. package/dist/components/atoms/IconProvider.es.js +4 -1
  49. package/dist/components/atoms/IconProvider.es.js.map +1 -1
  50. package/dist/components/atoms/Modal.es.js +1 -1
  51. package/dist/components/atoms/OverflowButton.es.js +2 -2
  52. package/dist/components/atoms/PaginationDot.d.ts +14 -0
  53. package/dist/components/atoms/PaginationDot.es.js +58 -0
  54. package/dist/components/atoms/PaginationDot.es.js.map +1 -0
  55. package/dist/components/atoms/PaginationItem.d.ts +15 -0
  56. package/dist/components/atoms/PaginationItem.es.js +87 -0
  57. package/dist/components/atoms/PaginationItem.es.js.map +1 -0
  58. package/dist/components/atoms/Popover.d.ts +10 -0
  59. package/dist/components/atoms/Popover.es.js +50 -0
  60. package/dist/components/atoms/Popover.es.js.map +1 -0
  61. package/dist/components/atoms/Select.d.ts +63 -0
  62. package/dist/components/atoms/Select.es.js +23 -0
  63. package/dist/components/atoms/Select.es.js.map +1 -0
  64. package/dist/components/atoms/Switch.es.js +7 -6
  65. package/dist/components/atoms/Switch.es.js.map +1 -1
  66. package/dist/components/atoms/TabButton.d.ts +31 -6
  67. package/dist/components/atoms/TabButton.es.js +425 -55
  68. package/dist/components/atoms/TabButton.es.js.map +1 -1
  69. package/dist/components/atoms/Tag.d.ts +2 -2
  70. package/dist/components/atoms/Tag.es.js +66 -33
  71. package/dist/components/atoms/Tag.es.js.map +1 -1
  72. package/dist/components/atoms/Tooltip.es.js +1153 -19
  73. package/dist/components/atoms/Tooltip.es.js.map +1 -1
  74. package/dist/components/atoms/stories/OverlayThemePanels.d.ts +8 -0
  75. package/dist/components/molecules/Alert.es.js +3 -3
  76. package/dist/components/molecules/CopyField.es.js +2 -2
  77. package/dist/components/molecules/CustomDrawer.es.js +1 -1
  78. package/dist/components/molecules/Dialog.es.js +1 -1
  79. package/dist/components/molecules/ImagesPreview.es.js +2 -2
  80. package/dist/components/molecules/Input.es.js +2 -2
  81. package/dist/components/molecules/Markdown.es.js +1 -1
  82. package/dist/components/molecules/Pagination.d.ts +58 -0
  83. package/dist/components/molecules/Pagination.es.js +272 -0
  84. package/dist/components/molecules/Pagination.es.js.map +1 -0
  85. package/dist/components/molecules/SimpleCodeEditor.es.js +3 -3
  86. package/dist/components/molecules/SimpleCodeEditor.es.js.map +1 -1
  87. package/dist/components/molecules/TagGroup.d.ts +11 -0
  88. package/dist/components/molecules/TagGroup.es.js +59 -0
  89. package/dist/components/molecules/TagGroup.es.js.map +1 -0
  90. package/dist/components/molecules/ToggleButton.es.js +2 -2
  91. package/dist/components/molecules/TopBar.d.ts +47 -0
  92. package/dist/components/molecules/TopBar.es.js +164 -0
  93. package/dist/components/molecules/TopBar.es.js.map +1 -0
  94. package/dist/components/molecules/agent-chat/AssistantMessage.d.ts +3 -1
  95. package/dist/components/molecules/agent-chat.es.js +4 -3
  96. package/dist/components/molecules/agent-chat.es.js.map +1 -1
  97. package/dist/components/theme/colors.es.js +1 -0
  98. package/dist/components/theme/colors.es.js.map +1 -1
  99. package/dist/composite-DnShFmi7.js +551 -0
  100. package/dist/composite-DnShFmi7.js.map +1 -0
  101. package/dist/{composite-C22yiNy1.js → composite-IA--dSel.js} +2 -2
  102. package/dist/{composite-C22yiNy1.js.map → composite-IA--dSel.js.map} +1 -1
  103. package/dist/constants-BaUKmVF_.js +103 -0
  104. package/dist/constants-BaUKmVF_.js.map +1 -0
  105. package/dist/{index-C-2yrwZl.js → element-B1vbc-LG.js} +69 -111
  106. package/dist/element-B1vbc-LG.js.map +1 -0
  107. package/dist/error-nCTLdGUr.js +6 -0
  108. package/dist/{error-FX4R42W-.js.map → error-nCTLdGUr.js.map} +1 -1
  109. package/dist/index.d.ts +12 -2
  110. package/dist/index.es.js +65 -12
  111. package/dist/index.es.js.map +1 -1
  112. package/dist/{inertValue-IJM5NA30.js → inertValue-C1Ml1s55.js} +2 -2
  113. package/dist/{inertValue-IJM5NA30.js.map → inertValue-C1Ml1s55.js.map} +1 -1
  114. package/dist/isElementDisabled-lq1fKien.js +47 -0
  115. package/dist/isElementDisabled-lq1fKien.js.map +1 -0
  116. package/dist/new-components/atoms/Alert.d.ts +9 -1
  117. package/dist/new-components/atoms/Alert.es.js +38 -13
  118. package/dist/new-components/atoms/Alert.es.js.map +1 -1
  119. package/dist/new-components/atoms/Checkbox.es.js +8 -7
  120. package/dist/new-components/atoms/Checkbox.es.js.map +1 -1
  121. package/dist/new-components/atoms/EmptyState.d.ts +3 -0
  122. package/dist/new-components/atoms/EmptyState.es.js +9 -4
  123. package/dist/new-components/atoms/EmptyState.es.js.map +1 -1
  124. package/dist/new-components/atoms/Popover.es.js +3 -2
  125. package/dist/new-components/atoms/Popover.es.js.map +1 -1
  126. package/dist/new-components/atoms/Radio.es.js +13 -24
  127. package/dist/new-components/atoms/Radio.es.js.map +1 -1
  128. package/dist/new-components/atoms/SegmentedControl.es.js +7 -7
  129. package/dist/new-components/atoms/Slider.es.js +14 -88
  130. package/dist/new-components/atoms/Slider.es.js.map +1 -1
  131. package/dist/new-components/atoms/Toast.d.ts +8 -12
  132. package/dist/new-components/atoms/Toast.es.js +202 -145
  133. package/dist/new-components/atoms/Toast.es.js.map +1 -1
  134. package/dist/new-components/atoms/Toggletip.d.ts +1 -1
  135. package/dist/new-components/atoms/Toggletip.es.js +3 -2
  136. package/dist/new-components/atoms/Toggletip.es.js.map +1 -1
  137. package/dist/new-components/atoms/stories/ThemeComparison.d.ts +2 -1
  138. package/dist/serializeValue-BLvnTy3o.js +17 -0
  139. package/dist/serializeValue-BLvnTy3o.js.map +1 -0
  140. package/dist/stringifyLocale-DOx30wH1.js +13 -0
  141. package/dist/stringifyLocale-DOx30wH1.js.map +1 -0
  142. package/dist/style.css +1 -1
  143. package/dist/tokens.css +24 -6
  144. package/dist/{useAnimationFrame-DwhymJoW.js → useAnimationFrame-DqvuRtgK.js} +2 -2
  145. package/dist/{useAnimationFrame-DwhymJoW.js.map → useAnimationFrame-DqvuRtgK.js.map} +1 -1
  146. package/dist/{useAriaLabelledBy-Lyj6n_TU.js → useAriaLabelledBy-CP4wKTYs.js} +3 -3
  147. package/dist/{useAriaLabelledBy-Lyj6n_TU.js.map → useAriaLabelledBy-CP4wKTYs.js.map} +1 -1
  148. package/dist/{useBaseUiId-CmLtG9DS.js → useBaseUiId-CYT1vFMG.js} +64 -44
  149. package/dist/{useBaseUiId-CmLtG9DS.js.map → useBaseUiId-CYT1vFMG.js.map} +1 -1
  150. package/dist/{useButton-D2BMuSfC.js → useButton-BlHadUfM.js} +4 -4
  151. package/dist/{useButton-D2BMuSfC.js.map → useButton-BlHadUfM.js.map} +1 -1
  152. package/dist/{CompositeList-D4xmSZ5V.js → useCompositeListItem-DlAKWsHE.js} +59 -59
  153. package/dist/useCompositeListItem-DlAKWsHE.js.map +1 -0
  154. package/dist/{useControlled-BSyYkg5C.js → useControlled-DMDWXIzj.js} +2 -2
  155. package/dist/{useControlled-BSyYkg5C.js.map → useControlled-DMDWXIzj.js.map} +1 -1
  156. package/dist/useFocus-C__7iwl1.js +137 -0
  157. package/dist/useFocus-C__7iwl1.js.map +1 -0
  158. package/dist/{useIsoLayoutEffect-e9VA-ICd.js → useIsoLayoutEffect-D2lpsB9D.js} +8 -4
  159. package/dist/{useIsoLayoutEffect-e9VA-ICd.js.map → useIsoLayoutEffect-D2lpsB9D.js.map} +1 -1
  160. package/dist/{usePopupHandleStore-CkW2IoED.js → usePopupHandleStore-C_Vw7xcw.js} +1966 -2002
  161. package/dist/usePopupHandleStore-C_Vw7xcw.js.map +1 -0
  162. package/dist/{Tooltip-uQIVdskf.js → usePositioner-BmYVsMO_.js} +17 -1402
  163. package/dist/usePositioner-BmYVsMO_.js.map +1 -0
  164. package/dist/{useOpenInteractionType-CDFYOw2d.js → useScrollLock-By-42HSc.js} +74 -58
  165. package/dist/useScrollLock-By-42HSc.js.map +1 -0
  166. package/dist/{useLabelableId-CcIE3RU0.js → useSetFieldFocused-CcdG6FNp.js} +27 -35
  167. package/dist/useSetFieldFocused-CcdG6FNp.js.map +1 -0
  168. package/dist/{useTimeout-BXf1hDIL.js → useTimeout-D1vYJgq4.js} +3 -3
  169. package/dist/{useTimeout-BXf1hDIL.js.map → useTimeout-D1vYJgq4.js.map} +1 -1
  170. package/dist/{useTransitionStatus-C9gg_XJ-.js → useTransitionStatus-CHrs3i5F.js} +3 -3
  171. package/dist/{useTransitionStatus-C9gg_XJ-.js.map → useTransitionStatus-CHrs3i5F.js.map} +1 -1
  172. package/dist/useTriggerFocusGuards-CXAhW8P6.js +100 -0
  173. package/dist/useTriggerFocusGuards-CXAhW8P6.js.map +1 -0
  174. package/dist/useValueChanged-BnlOop8k.js +16 -0
  175. package/dist/useValueChanged-BnlOop8k.js.map +1 -0
  176. package/package.json +1 -1
  177. package/dist/CompositeList-D4xmSZ5V.js.map +0 -1
  178. package/dist/CompositeRoot-BlljDWkR.js.map +0 -1
  179. package/dist/Popover-BqqXJnK1.js.map +0 -1
  180. package/dist/Tooltip-uQIVdskf.js.map +0 -1
  181. package/dist/composite-BL4bbAWg.js +0 -66
  182. package/dist/composite-BL4bbAWg.js.map +0 -1
  183. package/dist/error-FX4R42W-.js +0 -6
  184. package/dist/index-C-2yrwZl.js.map +0 -1
  185. package/dist/shadowDom-BfewIqRj.js +0 -52
  186. package/dist/shadowDom-BfewIqRj.js.map +0 -1
  187. package/dist/useLabelableId-CcIE3RU0.js.map +0 -1
  188. package/dist/useOpenInteractionType-CDFYOw2d.js.map +0 -1
  189. package/dist/usePopupHandleStore-CkW2IoED.js.map +0 -1
  190. package/dist/useValueAsRef-BfFRcMg6.js.map +0 -1
@@ -0,0 +1,3252 @@
1
+ import { jsx, jsxs, Fragment } from "react/jsx-runtime";
2
+ import { E as useListNavigation, F as getHighlightReason, G as useTypeahead, H as isMouseWithinBounds, t as dropdownPanelVariants, d as dropdownItemVariants, a as dropdownLabelVariants, b as dropdownListVariants, u as dropdownSeparatorVariants } from "../../DropdownMenu-Crlf-J4E.js";
3
+ import IconProvider from "./IconProvider.es.js";
4
+ import { i as compareItemEquality, j as hasNullItemLabel, k as stringifyAsLabel, l as defaultItemEquality, m as flattenLeafItems, n as isGroupedItems, o as findSelectionIndex, p as stringifyAsValue, q as selectedValueIncludes, r as removeItem, t as findItemIndex, u as useFloatingRootContext, v as useOnFirstRender, w as isSelectedValueDirty, x as resolveSelectedIndex, I as ItemIndicator, L as ListboxSeparator, s as selectChipVariants, y as selectAttachedClass, g as selectTriggerVariants, z as trailingPadding, A as SelectTrailing } from "../../Select-BtX40h2K.js";
5
+ import { c as classNames } from "../../classNames-B1XpQHle.js";
6
+ import { f as formatErrorMessage, e as useRefWithInit, E as EMPTY_ARRAY, d as EMPTY_OBJECT, N as NOOP, a as useStableCallback, u as useIsoLayoutEffect, m as mergeProps, c as useMergedRefs, b as useRenderElement } from "../../useIsoLayoutEffect-D2lpsB9D.js";
7
+ import * as React from "react";
8
+ import { u as useControlled } from "../../useControlled-DMDWXIzj.js";
9
+ import { u as useValueAsRef } from "../../addEventListener-D-i9O6BG.js";
10
+ import { v as visuallyHiddenInput, a as visuallyHidden } from "../../visuallyHidden-B6H2X3_Y.js";
11
+ import { g as getComputedStyle, l as createGenericEventDetails, n as none, o as inputClear, p as inputChange, q as getOverflowAncestors, i as isHTMLElement, c as createChangeEventDetails, r as escapeKey, s as focusOut, v as outsidePress, w as itemPress, x as inputPress, y as imperativeAction, z as closePress, u as useBaseUiId, A as isElement, k as cancelOpen, B as listNavigation, C as keyboard, D as chipRemovePress, E as clearPress } from "../../useBaseUiId-CYT1vFMG.js";
12
+ import { g as getGridNavigatedIndex, i as isIndexOutOfListBounds, s as stopEvent, a as android, b as ios } from "../../composite-DnShFmi7.js";
13
+ import { R as ReactStore, a as attachPreventUnmountOnClose, u as useUnmountAfterClose, b as useDismiss, F as FOCUSABLE_POPUP_PROPS, p as pressableTriggerOpenStateMapping, g as gecko, c as FloatingPortal, D as DROPDOWN_COLLISION_AVOIDANCE, d as popupStateMapping, t as triggerOpenStateMapping } from "../../usePopupHandleStore-C_Vw7xcw.js";
14
+ import { u as useFormContext, a as useFieldRootContext, d as useLabelableId, e as useRegisterFieldControl, f as fieldValidityMapping, b as useLabelableContext, c as useSetFieldFocused, F as FieldRootContext, D as DEFAULT_FIELD_ROOT_CONTEXT, g as DEFAULT_FIELD_STATE_ATTRIBUTES } from "../../useSetFieldFocused-CcdG6FNp.js";
15
+ import { s as stringifyLocale } from "../../stringifyLocale-DOx30wH1.js";
16
+ import { u as useOpenInteractionType, a as useClick, I as InternalBackdrop, F as FloatingFocusManager } from "../../useScrollLock-By-42HSc.js";
17
+ import { u as useValueChanged } from "../../useValueChanged-BnlOop8k.js";
18
+ import { u as useDirection } from "../../DirectionContext-Pb9yafF5.js";
19
+ import { c as contains, g as getTarget, b as closest, a as activeElement } from "../../constants-BaUKmVF_.js";
20
+ import * as ReactDOM from "react-dom";
21
+ import { C as CompositeList, u as useCompositeListItem } from "../../useCompositeListItem-DlAKWsHE.js";
22
+ import { a as useButton } from "../../useButton-BlHadUfM.js";
23
+ import { i as isInteractiveElement, o as ownerDocument } from "../../element-B1vbc-LG.js";
24
+ import { i as inertValue } from "../../inertValue-C1Ml1s55.js";
25
+ import { u as useAnchorPositioning, a as usePositioner, g as getDisabledMountTransitionStyles } from "../../usePositioner-BmYVsMO_.js";
26
+ import { u as useAnchoredPopupScrollLock } from "../../useTriggerFocusGuards-CXAhW8P6.js";
27
+ import { a as useOpenChangeComplete, t as transitionStatusMapping, u as useTransitionStatus } from "../../useTransitionStatus-CHrs3i5F.js";
28
+ import { u as useTimeout } from "../../useTimeout-D1vYJgq4.js";
29
+ import { r as resolveAriaLabelledBy } from "../../clamp-D7_nsB8C.js";
30
+ function gridNavigation(event, prevIndex, listRef, orientation, loopFocus, rtl, disabledIndices, minIndex, maxIndex, cols = 2) {
31
+ const nextIndex = getGridNavigatedIndex(listRef.current, {
32
+ event,
33
+ orientation,
34
+ loopFocus,
35
+ rtl,
36
+ cols,
37
+ disabledIndices,
38
+ minIndex,
39
+ maxIndex,
40
+ // An out-of-range previous index falls back to the first enabled item.
41
+ prevIndex: prevIndex > maxIndex ? minIndex : prevIndex,
42
+ stopEvent: true
43
+ });
44
+ return isIndexOutOfListBounds(listRef.current, nextIndex) ? void 0 : nextIndex;
45
+ }
46
+ const ComboboxRootContext = /* @__PURE__ */ React.createContext(void 0);
47
+ if (process.env.NODE_ENV !== "production") ComboboxRootContext.displayName = "ComboboxRootContext";
48
+ const ComboboxFloatingContext = /* @__PURE__ */ React.createContext(void 0);
49
+ if (process.env.NODE_ENV !== "production") ComboboxFloatingContext.displayName = "ComboboxFloatingContext";
50
+ const ComboboxDerivedItemsContext = /* @__PURE__ */ React.createContext(void 0);
51
+ if (process.env.NODE_ENV !== "production") ComboboxDerivedItemsContext.displayName = "ComboboxDerivedItemsContext";
52
+ const ComboboxHasItemsContext = /* @__PURE__ */ React.createContext(false);
53
+ if (process.env.NODE_ENV !== "production") ComboboxHasItemsContext.displayName = "ComboboxHasItemsContext";
54
+ const ComboboxInputValueContext = /* @__PURE__ */ React.createContext("");
55
+ if (process.env.NODE_ENV !== "production") ComboboxInputValueContext.displayName = "ComboboxInputValueContext";
56
+ function useComboboxRootContext() {
57
+ const context = React.useContext(ComboboxRootContext);
58
+ if (!context) {
59
+ throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: ComboboxRootContext is missing. Combobox parts must be placed within <Combobox.Root>." : formatErrorMessage(22));
60
+ }
61
+ return context;
62
+ }
63
+ function useComboboxFloatingContext() {
64
+ const context = React.useContext(ComboboxFloatingContext);
65
+ if (!context) {
66
+ throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: ComboboxFloatingContext is missing. Combobox parts must be placed within <Combobox.Root>." : formatErrorMessage(23));
67
+ }
68
+ return context;
69
+ }
70
+ function useComboboxDerivedItemsContext() {
71
+ const context = React.useContext(ComboboxDerivedItemsContext);
72
+ if (!context) {
73
+ throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: ComboboxItemsContext is missing. Combobox parts must be placed within <Combobox.Root>." : formatErrorMessage(24));
74
+ }
75
+ return context;
76
+ }
77
+ function useComboboxInputValueContext() {
78
+ return React.useContext(ComboboxInputValueContext);
79
+ }
80
+ function useComboboxHasItemsContext() {
81
+ return React.useContext(ComboboxHasItemsContext);
82
+ }
83
+ const selectors = {
84
+ id: (state) => state.id,
85
+ labelId: (state) => state.labelId,
86
+ items: (state) => state.items,
87
+ selectedValue: (state) => state.selectedValue,
88
+ hasSelectionChips: (state) => {
89
+ const selectedValue = state.selectedValue;
90
+ return Array.isArray(selectedValue) && selectedValue.length > 0;
91
+ },
92
+ hasSelectedValue: (state) => {
93
+ const {
94
+ selectedValue,
95
+ selectionMode
96
+ } = state;
97
+ if (selectedValue == null) {
98
+ return false;
99
+ }
100
+ if (selectionMode === "multiple" && Array.isArray(selectedValue)) {
101
+ return selectedValue.length > 0;
102
+ }
103
+ return true;
104
+ },
105
+ hasNullItemLabel: (state, enabled) => {
106
+ return enabled ? hasNullItemLabel(state.items) : false;
107
+ },
108
+ open: (state) => state.open,
109
+ mounted: (state) => state.mounted,
110
+ forceMounted: (state) => state.forceMounted,
111
+ inline: (state) => state.inline,
112
+ activeIndex: (state) => state.activeIndex,
113
+ selectedIndex: (state) => state.selectedIndex,
114
+ isActive: (state, index) => state.activeIndex === index,
115
+ isSelected: (state, itemValue) => {
116
+ const comparer = state.isItemEqualToValue;
117
+ const selectedValue = state.selectedValue;
118
+ if (Array.isArray(selectedValue)) {
119
+ return selectedValue.some((selectedItem) => compareItemEquality(itemValue, selectedItem, comparer));
120
+ }
121
+ return compareItemEquality(itemValue, selectedValue, comparer);
122
+ },
123
+ transitionStatus: (state) => state.transitionStatus,
124
+ popupProps: (state) => state.popupProps,
125
+ listProps: (state) => state.listProps,
126
+ inputProps: (state) => state.inputProps,
127
+ triggerProps: (state) => state.triggerProps,
128
+ itemRoot: (state) => state.itemRoot,
129
+ positionerElement: (state) => state.positionerElement,
130
+ listElement: (state) => state.listElement,
131
+ popupId: (state) => state.popupId,
132
+ triggerElement: (state) => state.triggerElement,
133
+ inputElement: (state) => state.inputElement,
134
+ inputGroupElement: (state) => state.inputGroupElement,
135
+ popupSide: (state) => state.popupSide,
136
+ openMethod: (state) => state.openMethod,
137
+ inputInsidePopup: (state) => state.inputInsidePopup,
138
+ inputOwnsFormValue: (state) => state.inputOwnsFormValue,
139
+ selectionMode: (state) => state.selectionMode,
140
+ name: (state) => state.name,
141
+ form: (state) => state.form,
142
+ disabled: (state) => state.disabled,
143
+ readOnly: (state) => state.readOnly,
144
+ required: (state) => state.required,
145
+ grid: (state) => state.grid,
146
+ virtualized: (state) => state.virtualized,
147
+ itemToStringLabel: (state) => state.itemToStringLabel,
148
+ isItemEqualToValue: (state) => state.isItemEqualToValue,
149
+ modal: (state) => state.modal,
150
+ autoHighlight: (state) => state.autoHighlight
151
+ };
152
+ function getComboboxPopupId(rootId) {
153
+ return rootId == null ? void 0 : `${rootId}-popup`;
154
+ }
155
+ function createCollatorItemFilter(collatorFilter, itemToStringLabel) {
156
+ return (item, query) => {
157
+ if (item == null) {
158
+ return false;
159
+ }
160
+ return collatorFilter.contains(item, query, itemToStringLabel);
161
+ };
162
+ }
163
+ const filterCache = /* @__PURE__ */ new Map();
164
+ function getFilter(options = {}) {
165
+ const {
166
+ locale,
167
+ ...restOptions
168
+ } = options;
169
+ const collatorOptions = {
170
+ usage: "search",
171
+ sensitivity: "base",
172
+ ignorePunctuation: true,
173
+ ...restOptions
174
+ };
175
+ const cacheKey = `${stringifyLocale(locale)}|${JSON.stringify(collatorOptions)}`;
176
+ const cachedFilter = filterCache.get(cacheKey);
177
+ if (cachedFilter) {
178
+ return cachedFilter;
179
+ }
180
+ const collator = new Intl.Collator(locale, collatorOptions);
181
+ const filter = {
182
+ contains(item, query, itemToString) {
183
+ if (!query) {
184
+ return true;
185
+ }
186
+ const itemString = stringifyAsLabel(item, itemToString);
187
+ for (let i = 0; i <= itemString.length - query.length; i += 1) {
188
+ if (collator.compare(itemString.slice(i, i + query.length), query) === 0) {
189
+ return true;
190
+ }
191
+ }
192
+ return false;
193
+ },
194
+ startsWith(item, query, itemToString) {
195
+ if (!query) {
196
+ return true;
197
+ }
198
+ const itemString = stringifyAsLabel(item, itemToString);
199
+ return collator.compare(itemString.slice(0, query.length), query) === 0;
200
+ },
201
+ endsWith(item, query, itemToString) {
202
+ if (!query) {
203
+ return true;
204
+ }
205
+ const itemString = stringifyAsLabel(item, itemToString);
206
+ const queryLength = query.length;
207
+ return itemString.length >= queryLength && collator.compare(itemString.slice(itemString.length - queryLength), query) === 0;
208
+ }
209
+ };
210
+ filterCache.set(cacheKey, filter);
211
+ return filter;
212
+ }
213
+ const useCoreFilter = getFilter;
214
+ function isScrollableY(element, allowOverflowIntent = false) {
215
+ const {
216
+ overflowY
217
+ } = getComputedStyle(element);
218
+ if (overflowY !== "auto" && overflowY !== "scroll") {
219
+ return false;
220
+ }
221
+ return allowOverflowIntent ? element.clientHeight > 0 : element.scrollHeight > element.clientHeight;
222
+ }
223
+ const NO_ACTIVE_VALUE = Symbol("none");
224
+ const INITIAL_LAST_HIGHLIGHT = {
225
+ value: NO_ACTIVE_VALUE,
226
+ index: -1
227
+ };
228
+ function findCollectionItem(valueToItem, itemValue, isEqual) {
229
+ const exactItem = valueToItem.get(itemValue);
230
+ if (exactItem !== void 0 || isEqual === defaultItemEquality) {
231
+ return exactItem;
232
+ }
233
+ for (const [derivedValue, item] of valueToItem) {
234
+ if (compareItemEquality(derivedValue, itemValue, isEqual)) {
235
+ return item;
236
+ }
237
+ }
238
+ return void 0;
239
+ }
240
+ function AriaCombobox(props) {
241
+ const {
242
+ id: idProp,
243
+ onOpenChangeComplete: onOpenChangeCompleteProp,
244
+ defaultSelectedValue = null,
245
+ selectedValue: selectedValueProp,
246
+ onSelectedValueChange,
247
+ defaultInputValue,
248
+ inputValue: inputValueProp,
249
+ open: openProp,
250
+ defaultOpen = false,
251
+ selectionMode,
252
+ onItemHighlighted: onItemHighlightedProp,
253
+ name: nameProp,
254
+ form,
255
+ disabled: disabledProp = false,
256
+ readOnly = false,
257
+ required = false,
258
+ inputRef: inputRefProp,
259
+ grid = false,
260
+ items: itemsProp,
261
+ filteredItems: filteredItemsProp,
262
+ filter: filterProp,
263
+ filterQuery: filterQueryProp,
264
+ openOnInputClick = true,
265
+ autoHighlight = false,
266
+ keepHighlight = false,
267
+ highlightItemOnHover = true,
268
+ loopFocus = true,
269
+ itemToStringLabel: itemToStringLabelProp,
270
+ itemToStringValue,
271
+ isItemEqualToValue = defaultItemEquality,
272
+ virtualized = false,
273
+ inline: inlineProp = false,
274
+ fillInputOnItemPress = true,
275
+ modal = false,
276
+ limit = -1,
277
+ autoComplete = "list",
278
+ formAutoComplete,
279
+ locale,
280
+ submitOnItemClick = false
281
+ } = props;
282
+ const {
283
+ clearErrors
284
+ } = useFormContext();
285
+ const {
286
+ setDirty,
287
+ validityData,
288
+ setFilled,
289
+ name: fieldName,
290
+ disabled: fieldDisabled,
291
+ setTouched,
292
+ setFocused,
293
+ validationMode,
294
+ validation
295
+ } = useFieldRootContext();
296
+ const direction = useDirection();
297
+ const id = useLabelableId({
298
+ id: idProp
299
+ });
300
+ const collatorFilter = useCoreFilter({
301
+ locale
302
+ });
303
+ const collection = Array.isArray(itemsProp) ? null : itemsProp;
304
+ if (collection && typeof collection.label !== "function") {
305
+ throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: the `items` prop received an object that is not a collection, so its items cannot be read. Pass an array of items, an array of groups with items, or the result of `createItems()`. See https://base-ui.com/react/components/combobox#createitems" : formatErrorMessage(100));
306
+ }
307
+ const items = collection ? collection.data : itemsProp;
308
+ const itemToValue = collection == null ? void 0 : collection.value;
309
+ const storeItems = itemToValue ? void 0 : items;
310
+ const externalWindow = React.useMemo(() => {
311
+ if (!filteredItemsProp || !itemToValue) {
312
+ return void 0;
313
+ }
314
+ const flat = flattenLeafItems(filteredItemsProp);
315
+ const values = flat.map(itemToValue);
316
+ let valueToItem;
317
+ return {
318
+ values,
319
+ findItem(itemValue, isEqual) {
320
+ if (!valueToItem) {
321
+ valueToItem = /* @__PURE__ */ new Map();
322
+ for (let i = 0; i < values.length; i += 1) {
323
+ if (!valueToItem.has(values[i])) {
324
+ valueToItem.set(values[i], flat[i]);
325
+ }
326
+ }
327
+ }
328
+ return findCollectionItem(valueToItem, itemValue, isEqual);
329
+ }
330
+ };
331
+ }, [filteredItemsProp, itemToValue]);
332
+ const itemToStringLabel = React.useMemo(() => {
333
+ if (!collection) {
334
+ return itemToStringLabelProp;
335
+ }
336
+ return (itemValue) => {
337
+ return collection.label(itemValue, isItemEqualToValue, (unresolvedValue) => {
338
+ const externalItem = externalWindow == null ? void 0 : externalWindow.findItem(unresolvedValue, isItemEqualToValue);
339
+ if (externalItem != null) {
340
+ return collection.itemLabel(externalItem);
341
+ }
342
+ return stringifyAsLabel(unresolvedValue, itemToStringLabelProp);
343
+ });
344
+ };
345
+ }, [collection, itemToStringLabelProp, externalWindow, isItemEqualToValue]);
346
+ const filterItemToString = React.useMemo(() => {
347
+ if (!collection) {
348
+ return itemToStringLabelProp;
349
+ }
350
+ return Object.assign((item) => collection.itemLabel(item), {
351
+ selected: (value) => stringifyAsLabel(value, itemToStringLabel)
352
+ });
353
+ }, [collection, itemToStringLabel, itemToStringLabelProp]);
354
+ function stringifyValueLabel(item) {
355
+ return stringifyAsLabel(item, itemToStringLabel);
356
+ }
357
+ const [queryChangedAfterOpen, setQueryChangedAfterOpen] = React.useState(false);
358
+ const [closeQuery, setCloseQuery] = React.useState(null);
359
+ const previousCloseQueryRef = React.useRef(closeQuery);
360
+ const listRef = React.useRef([]);
361
+ const labelsRef = React.useRef([]);
362
+ const popupRef = React.useRef(null);
363
+ const inputRef = React.useRef(null);
364
+ const startDismissRef = React.useRef(null);
365
+ const endDismissRef = React.useRef(null);
366
+ const emptyRef = React.useRef(null);
367
+ const hadInputClearRef = React.useRef(false);
368
+ const chipsContainerRef = React.useRef(null);
369
+ const clearRef = React.useRef(null);
370
+ const selectionEventRef = React.useRef(null);
371
+ const lastHighlightRef = React.useRef(INITIAL_LAST_HIGHLIGHT);
372
+ const pendingQueryHighlightRef = React.useRef(null);
373
+ const valuesRef = React.useRef([]);
374
+ const pointerDownItemRef = React.useRef(null);
375
+ const disabled = fieldDisabled || disabledProp;
376
+ const name = fieldName ?? nameProp;
377
+ const multiple = selectionMode === "multiple";
378
+ const single = selectionMode === "single";
379
+ const hasInputValue = inputValueProp !== void 0 || defaultInputValue !== void 0;
380
+ const hasItems = items !== void 0;
381
+ const hasFilteredItemsProp = filteredItemsProp !== void 0;
382
+ let autoHighlightMode;
383
+ if (autoHighlight === "always") {
384
+ autoHighlightMode = "always";
385
+ } else {
386
+ autoHighlightMode = autoHighlight ? "input-change" : false;
387
+ }
388
+ const [selectedValue, setSelectedValueUnwrapped] = useControlled({
389
+ controlled: selectedValueProp,
390
+ default: multiple ? defaultSelectedValue ?? EMPTY_ARRAY : defaultSelectedValue,
391
+ name: "Combobox",
392
+ state: "selectedValue"
393
+ });
394
+ const filter = React.useMemo(() => {
395
+ if (filterProp === null) {
396
+ return () => true;
397
+ }
398
+ if (filterProp !== void 0) {
399
+ return filterProp;
400
+ }
401
+ return createCollatorItemFilter(collatorFilter, filterItemToString);
402
+ }, [filterProp, collatorFilter, filterItemToString]);
403
+ const initialDefaultInputValue = useRefWithInit(() => {
404
+ if (hasInputValue) {
405
+ return defaultInputValue ?? "";
406
+ }
407
+ if (single) {
408
+ return stringifyValueLabel(selectedValue);
409
+ }
410
+ return "";
411
+ }).current;
412
+ const [inputValue, setInputValueUnwrapped] = useControlled({
413
+ controlled: inputValueProp,
414
+ default: initialDefaultInputValue,
415
+ name: "Combobox",
416
+ state: "inputValue"
417
+ });
418
+ const [open, setOpenUnwrapped] = useControlled({
419
+ controlled: openProp,
420
+ default: defaultOpen,
421
+ name: "Combobox",
422
+ state: "open"
423
+ });
424
+ const isGrouped = isGroupedItems(items);
425
+ const query = !open && closeQuery !== null ? closeQuery : String(inputValue).trim();
426
+ const selectedLabelString = single ? stringifyValueLabel(selectedValue) : "";
427
+ const shouldBypassFiltering = single && !queryChangedAfterOpen && query !== "" && selectedLabelString.length === query.length && collatorFilter.contains(selectedLabelString, query);
428
+ const filterQuery = shouldBypassFiltering ? "" : filterQueryProp ?? query;
429
+ const shouldIgnoreExternalFiltering = hasItems && hasFilteredItemsProp && shouldBypassFiltering && (!collection || collection.hasValue(selectedValue, isItemEqualToValue));
430
+ const flatItems = React.useMemo(() => items ? flattenLeafItems(items) : EMPTY_ARRAY, [items]);
431
+ const filteredItems = React.useMemo(() => {
432
+ if (filteredItemsProp && !shouldIgnoreExternalFiltering) {
433
+ return filteredItemsProp;
434
+ }
435
+ if (!items) {
436
+ return EMPTY_ARRAY;
437
+ }
438
+ if (isGrouped) {
439
+ const groupedItems = items;
440
+ const resultingGroups = [];
441
+ let currentCount = 0;
442
+ for (const group of groupedItems) {
443
+ if (limit > -1 && currentCount >= limit) {
444
+ break;
445
+ }
446
+ const remainingLimit = limit > -1 ? limit - currentCount : Infinity;
447
+ const itemsToTake = filterQuery === "" ? group.items.slice(0, remainingLimit) : [];
448
+ if (filterQuery !== "") {
449
+ for (const item of group.items) {
450
+ if (itemsToTake.length >= remainingLimit) {
451
+ break;
452
+ }
453
+ if (filter(item, filterQuery, filterItemToString)) {
454
+ itemsToTake.push(item);
455
+ }
456
+ }
457
+ }
458
+ if (itemsToTake.length > 0) {
459
+ const newGroup = {
460
+ ...group,
461
+ items: itemsToTake
462
+ };
463
+ resultingGroups.push(newGroup);
464
+ currentCount += itemsToTake.length;
465
+ }
466
+ }
467
+ return resultingGroups;
468
+ }
469
+ if (filterQuery === "") {
470
+ return limit > -1 ? flatItems.slice(0, limit) : (
471
+ // The cast here is done as `flatItems` is readonly.
472
+ // valuesRef.current, a mutable ref, can be set to `flatFilteredValues`, which may
473
+ // reference this exact readonly value, creating a mutation risk.
474
+ // However, <Combobox.Item> can never mutate this value as the mutating effect
475
+ // bails early when `items` is provided, and this is only ever returned
476
+ // when `items` is provided due to the early return at the top of this hook.
477
+ flatItems
478
+ );
479
+ }
480
+ const limitedItems = [];
481
+ for (const item of flatItems) {
482
+ if (limit > -1 && limitedItems.length >= limit) {
483
+ break;
484
+ }
485
+ if (filter(item, filterQuery, filterItemToString)) {
486
+ limitedItems.push(item);
487
+ }
488
+ }
489
+ return limitedItems;
490
+ }, [filteredItemsProp, shouldIgnoreExternalFiltering, items, isGrouped, filterQuery, limit, filter, filterItemToString, flatItems]);
491
+ const flatFilteredValues = React.useMemo(() => {
492
+ if (externalWindow && filteredItems === filteredItemsProp) {
493
+ return externalWindow.values;
494
+ }
495
+ const flat = flattenLeafItems(filteredItems);
496
+ return itemToValue ? flat.map((item) => itemToValue(item)) : flat;
497
+ }, [filteredItems, filteredItemsProp, externalWindow, itemToValue]);
498
+ const store = useRefWithInit(() => {
499
+ let initialSelectedIndex = null;
500
+ if (inlineProp && open && hasItems && selectionMode !== "none") {
501
+ initialSelectedIndex = findSelectionIndex(flatFilteredValues, selectedValue, isItemEqualToValue, multiple);
502
+ }
503
+ return new ReactStore({
504
+ id,
505
+ labelId: void 0,
506
+ selectedValue,
507
+ open,
508
+ items: storeItems,
509
+ selectionMode,
510
+ name,
511
+ form,
512
+ disabled,
513
+ readOnly,
514
+ required,
515
+ grid,
516
+ virtualized,
517
+ openOnInputClick,
518
+ itemToStringLabel,
519
+ isItemEqualToValue,
520
+ modal,
521
+ autoHighlight: autoHighlightMode,
522
+ submitOnItemClick,
523
+ hasInputValue,
524
+ mounted: false,
525
+ forceMounted: false,
526
+ transitionStatus: "idle",
527
+ inline: inlineProp,
528
+ activeIndex: null,
529
+ selectedIndex: initialSelectedIndex,
530
+ popupProps: {},
531
+ listProps: {},
532
+ inputProps: {},
533
+ triggerProps: {},
534
+ itemRoot: {
535
+ props: EMPTY_OBJECT,
536
+ id,
537
+ selectionMode,
538
+ disabled,
539
+ readOnly,
540
+ isItemEqualToValue
541
+ },
542
+ positionerElement: null,
543
+ listElement: null,
544
+ popupId: void 0,
545
+ triggerElement: null,
546
+ inputElement: null,
547
+ inputGroupElement: null,
548
+ popupSide: null,
549
+ openMethod: null,
550
+ inputInsidePopup: true,
551
+ // Avoid duplicate names in the server HTML. Popup inputs aren't rendered
552
+ // until after hydration, so the hidden input takes over then if needed.
553
+ inputOwnsFormValue: selectionMode === "none"
554
+ }, {
555
+ // Placeholder callbacks replaced on first render
556
+ onOpenChangeComplete: NOOP,
557
+ setOpen: NOOP,
558
+ setInputValue: NOOP,
559
+ setSelectedValue: NOOP,
560
+ setIndices: NOOP,
561
+ handleSelection: NOOP,
562
+ forceMount: NOOP,
563
+ requestSubmit: NOOP,
564
+ listRef,
565
+ labelsRef,
566
+ popupRef,
567
+ emptyRef,
568
+ inputRef,
569
+ startDismissRef,
570
+ endDismissRef,
571
+ chipsContainerRef,
572
+ clearRef,
573
+ valuesRef,
574
+ pointerDownItemRef,
575
+ selectionEventRef
576
+ }, selectors);
577
+ }).current;
578
+ const fieldRawValue = selectionMode === "none" ? inputValue : selectedValue;
579
+ const fieldStringValue = React.useMemo(() => {
580
+ if (selectionMode === "none") {
581
+ return fieldRawValue;
582
+ }
583
+ if (Array.isArray(selectedValue)) {
584
+ return selectedValue.map((value) => stringifyAsValue(value, itemToStringValue));
585
+ }
586
+ return stringifyAsValue(selectedValue, itemToStringValue);
587
+ }, [fieldRawValue, itemToStringValue, selectionMode, selectedValue]);
588
+ const onItemHighlighted = useStableCallback(onItemHighlightedProp);
589
+ const onOpenChangeComplete = useStableCallback(onOpenChangeCompleteProp);
590
+ const activeIndex = store.useState("activeIndex");
591
+ const selectedIndex = store.useState("selectedIndex");
592
+ const positionerElement = store.useState("positionerElement");
593
+ const listElement = store.useState("listElement");
594
+ const triggerElement = store.useState("triggerElement");
595
+ const inputElement = store.useState("inputElement");
596
+ const inputGroupElement = store.useState("inputGroupElement");
597
+ const inline = store.useState("inline");
598
+ const inputInsidePopup = store.useState("inputInsidePopup");
599
+ const inputOwnsFormValue = store.useState("inputOwnsFormValue");
600
+ const inputMatchesSelectedValue = single && !inputInsidePopup && inputValue === selectedLabelString;
601
+ const triggerRef = useValueAsRef(triggerElement);
602
+ const {
603
+ openMethod,
604
+ triggerProps
605
+ } = useOpenInteractionType(open);
606
+ const getStringifiedValueForForm = useStableCallback(() => fieldStringValue);
607
+ useRegisterFieldControl(inputInsidePopup ? triggerRef : inputRef, id, fieldRawValue, getStringifiedValueForForm, !disabled, nameProp);
608
+ const forceMount = useStableCallback(() => {
609
+ if (items) {
610
+ labelsRef.current = flatFilteredValues.map(stringifyValueLabel);
611
+ } else {
612
+ store.set("forceMounted", true);
613
+ }
614
+ });
615
+ const emitHighlight = useStableCallback((value, index, type, event) => {
616
+ if (index === -1) {
617
+ if (lastHighlightRef.current === INITIAL_LAST_HIGHLIGHT) {
618
+ return;
619
+ }
620
+ lastHighlightRef.current = INITIAL_LAST_HIGHLIGHT;
621
+ } else {
622
+ lastHighlightRef.current = {
623
+ value,
624
+ index
625
+ };
626
+ }
627
+ onItemHighlighted(value, createGenericEventDetails(type, event, {
628
+ index
629
+ }));
630
+ });
631
+ const setIndices = useStableCallback((options) => {
632
+ const update = {};
633
+ if (options.activeIndex !== void 0) {
634
+ update.activeIndex = options.activeIndex;
635
+ }
636
+ if (options.selectedIndex !== void 0) {
637
+ update.selectedIndex = options.selectedIndex;
638
+ }
639
+ store.update(update);
640
+ const activeIndexOption = options.activeIndex;
641
+ if (activeIndexOption === void 0) {
642
+ return;
643
+ }
644
+ const type = options.type || none;
645
+ if (activeIndexOption === null) {
646
+ emitHighlight(void 0, -1, type, options.event);
647
+ } else {
648
+ emitHighlight(valuesRef.current[activeIndexOption], activeIndexOption, type, options.event);
649
+ }
650
+ });
651
+ const setInputValue = useStableCallback((next, eventDetails) => {
652
+ var _a;
653
+ (_a = props.onInputValueChange) == null ? void 0 : _a.call(props, next, eventDetails);
654
+ if (eventDetails.isCanceled) {
655
+ return;
656
+ }
657
+ hadInputClearRef.current = eventDetails.reason === inputClear;
658
+ if (eventDetails.reason === inputChange) {
659
+ if (open && closeQuery !== null) {
660
+ setCloseQuery(null);
661
+ }
662
+ const event = eventDetails.event;
663
+ const inputType = event.inputType;
664
+ const isTypedInput = event.type === "compositionend" || inputType != null && inputType !== "" && inputType !== "insertReplacementText";
665
+ if (isTypedInput) {
666
+ const hasQuery = next.trim() !== "";
667
+ if (hasQuery) {
668
+ setQueryChangedAfterOpen(true);
669
+ }
670
+ pendingQueryHighlightRef.current = {
671
+ hasQuery
672
+ };
673
+ const list = store.state.listElement;
674
+ if (!store.state.virtualized && list) {
675
+ const popup = popupRef.current;
676
+ for (const ancestor of getOverflowAncestors(list.firstElementChild ?? list)) {
677
+ if (!isHTMLElement(ancestor) || (popup ? !contains(popup, ancestor) : ancestor.getAttribute("role") === "dialog")) {
678
+ break;
679
+ }
680
+ if (isScrollableY(ancestor)) {
681
+ ancestor.scrollTop = 0;
682
+ break;
683
+ }
684
+ }
685
+ }
686
+ if (hasQuery && autoHighlightMode && store.state.activeIndex == null && (open || inline)) {
687
+ store.set("activeIndex", 0);
688
+ }
689
+ }
690
+ } else if (eventDetails.reason === inputClear && next === "" && store.state.inputInsidePopup) {
691
+ pendingQueryHighlightRef.current = {
692
+ hasQuery: false,
693
+ selection: true
694
+ };
695
+ }
696
+ setInputValueUnwrapped(next);
697
+ });
698
+ const handleInterruptedReopen = useStableCallback((isInputChange) => {
699
+ const clearsPendingInput = !isInputChange && inputInsidePopup && !inline && inputValue !== "" && (String(inputValue).trim() === closeQuery || inputValue === selectedLabelString);
700
+ if (!isInputChange && (clearsPendingInput || inputValue === "" || inputMatchesSelectedValue)) {
701
+ setQueryChangedAfterOpen(false);
702
+ }
703
+ setCloseQuery(null);
704
+ if (clearsPendingInput) {
705
+ setInputValue("", createChangeEventDetails(inputClear));
706
+ }
707
+ });
708
+ const [preventUnmountOnClose, setPreventUnmountOnClose] = React.useState(false);
709
+ const setOpen = useStableCallback((nextOpen, eventDetails) => {
710
+ var _a, _b;
711
+ if (open === nextOpen) {
712
+ return;
713
+ }
714
+ if (eventDetails.reason === escapeKey && hasItems && flatFilteredValues.length === 0 && !emptyRef.current) {
715
+ eventDetails.allowPropagation();
716
+ }
717
+ const openEventDetails = eventDetails;
718
+ const shouldPreventUnmountOnClose = attachPreventUnmountOnClose(openEventDetails);
719
+ (_a = props.onOpenChange) == null ? void 0 : _a.call(props, nextOpen, openEventDetails);
720
+ if (((_b = pendingQueryHighlightRef.current) == null ? void 0 : _b.hasQuery) && eventDetails.reason === inputChange === eventDetails.isCanceled) {
721
+ pendingQueryHighlightRef.current = null;
722
+ }
723
+ if (eventDetails.isCanceled) {
724
+ return;
725
+ }
726
+ if (nextOpen && closeQuery !== null) {
727
+ handleInterruptedReopen(eventDetails.reason === inputChange);
728
+ }
729
+ if (!nextOpen && queryChangedAfterOpen) {
730
+ if (single) {
731
+ if (!inline) {
732
+ setCloseQuery(query);
733
+ }
734
+ if (query === "") {
735
+ setQueryChangedAfterOpen(false);
736
+ }
737
+ } else if (multiple) {
738
+ if (!inline) {
739
+ setCloseQuery(query);
740
+ }
741
+ if (inputInsidePopup) {
742
+ setIndices({
743
+ activeIndex: null
744
+ });
745
+ }
746
+ if (!inputInsidePopup || inline) {
747
+ setInputValue("", createChangeEventDetails(inputClear, eventDetails.event, void 0, {
748
+ isItemPress: eventDetails.reason === itemPress
749
+ }));
750
+ }
751
+ }
752
+ }
753
+ if (!nextOpen) {
754
+ setPreventUnmountOnClose(shouldPreventUnmountOnClose());
755
+ }
756
+ setOpenUnwrapped(nextOpen);
757
+ if (!nextOpen && inputInsidePopup && (eventDetails.reason === focusOut || eventDetails.reason === outsidePress)) {
758
+ setTouched(true);
759
+ setFocused(false);
760
+ if (validationMode === "onBlur") {
761
+ const valueToValidate = selectionMode === "none" ? inputValue : selectedValue;
762
+ validation.commit(valueToValidate);
763
+ }
764
+ }
765
+ });
766
+ const setSelectedValue = useStableCallback((nextValue, eventDetails) => {
767
+ onSelectedValueChange == null ? void 0 : onSelectedValueChange(nextValue, eventDetails);
768
+ if (eventDetails.isCanceled) {
769
+ return;
770
+ }
771
+ setSelectedValueUnwrapped(nextValue);
772
+ const shouldFillInput = selectionMode === "none" && popupRef.current && fillInputOnItemPress || single && !store.state.inputInsidePopup;
773
+ if (shouldFillInput) {
774
+ setInputValue(stringifyValueLabel(nextValue), createChangeEventDetails(eventDetails.reason, eventDetails.event));
775
+ }
776
+ });
777
+ const handleSelection = useStableCallback((event, itemValue) => {
778
+ var _a;
779
+ const targetEl = getTarget(event);
780
+ const overrideEvent = selectionEventRef.current ?? event;
781
+ selectionEventRef.current = null;
782
+ const eventDetails = createChangeEventDetails(itemPress, overrideEvent);
783
+ const href = (_a = closest(targetEl, "a")) == null ? void 0 : _a.getAttribute("href");
784
+ if (href) {
785
+ if (href.startsWith("#")) {
786
+ setOpen(false, eventDetails);
787
+ }
788
+ return;
789
+ }
790
+ if (multiple) {
791
+ const currentSelectedValue = Array.isArray(selectedValue) ? selectedValue : [];
792
+ const isCurrentlySelected = selectedValueIncludes(currentSelectedValue, itemValue, isItemEqualToValue);
793
+ const nextValue = isCurrentlySelected ? removeItem(currentSelectedValue, itemValue, isItemEqualToValue) : [...currentSelectedValue, itemValue];
794
+ setSelectedValue(nextValue, eventDetails);
795
+ if (eventDetails.isCanceled) {
796
+ return;
797
+ }
798
+ const wasFiltering = inputRef.current ? inputRef.current.value.trim() !== "" : false;
799
+ if (!wasFiltering) {
800
+ return;
801
+ }
802
+ if (store.state.inputInsidePopup) {
803
+ setInputValue("", createChangeEventDetails(inputClear, eventDetails.event, void 0, {
804
+ isItemPress: true
805
+ }));
806
+ const pendingHighlight = pendingQueryHighlightRef.current;
807
+ if (pendingHighlight && !isCurrentlySelected) {
808
+ pendingHighlight.toggledValue = itemValue;
809
+ }
810
+ } else {
811
+ setOpen(false, eventDetails);
812
+ }
813
+ } else {
814
+ setSelectedValue(itemValue, eventDetails);
815
+ if (eventDetails.isCanceled) {
816
+ return;
817
+ }
818
+ setOpen(false, eventDetails);
819
+ }
820
+ });
821
+ const requestSubmit = useStableCallback(() => {
822
+ var _a, _b;
823
+ const formElement = ((_a = validation.inputRef.current) == null ? void 0 : _a.form) ?? ((_b = store.state.inputElement) == null ? void 0 : _b.form);
824
+ if (formElement && typeof formElement.requestSubmit === "function") {
825
+ formElement.requestSubmit();
826
+ }
827
+ });
828
+ const handleUnmountCleanup = useStableCallback(() => {
829
+ onOpenChangeComplete == null ? void 0 : onOpenChangeComplete(false);
830
+ setQueryChangedAfterOpen(false);
831
+ setCloseQuery(null);
832
+ if (selectionMode === "none") {
833
+ setIndices({
834
+ activeIndex: null,
835
+ selectedIndex: null
836
+ });
837
+ } else {
838
+ setIndices({
839
+ activeIndex: null
840
+ });
841
+ }
842
+ if (multiple && inputRef.current && inputRef.current.value !== "" && !hadInputClearRef.current) {
843
+ setInputValue("", createChangeEventDetails(inputClear));
844
+ }
845
+ if (single) {
846
+ if (store.state.inputInsidePopup) {
847
+ if (inputRef.current && inputRef.current.value !== "") {
848
+ setInputValue("", createChangeEventDetails(inputClear));
849
+ }
850
+ } else {
851
+ const stringVal = stringifyValueLabel(selectedValue);
852
+ if (inputRef.current && inputRef.current.value !== stringVal) {
853
+ const reason = stringVal === "" ? inputClear : none;
854
+ setInputValue(stringVal, createChangeEventDetails(reason));
855
+ }
856
+ }
857
+ }
858
+ });
859
+ const resolvedPopupRef = React.useMemo(() => {
860
+ if (inline && positionerElement) {
861
+ return {
862
+ current: closest(positionerElement, '[role="dialog"]')
863
+ };
864
+ }
865
+ return popupRef;
866
+ }, [inline, positionerElement]);
867
+ const {
868
+ mounted,
869
+ transitionStatus,
870
+ forceUnmount: handleUnmount
871
+ } = useUnmountAfterClose({
872
+ open,
873
+ ref: resolvedPopupRef,
874
+ preventUnmountOnClose,
875
+ setPreventUnmountOnClose,
876
+ onUnmount: handleUnmountCleanup
877
+ });
878
+ React.useImperativeHandle(props.actionsRef, () => ({
879
+ unmount: handleUnmount,
880
+ close: () => setOpen(false, createChangeEventDetails(imperativeAction))
881
+ }), [handleUnmount, setOpen]);
882
+ useIsoLayoutEffect(function syncSelectedIndex() {
883
+ const closeQueryReleased = previousCloseQueryRef.current !== null && closeQuery === null;
884
+ previousCloseQueryRef.current = closeQuery;
885
+ if (open && (!closeQueryReleased || !hasItems)) {
886
+ return;
887
+ }
888
+ if (!open) {
889
+ pointerDownItemRef.current = null;
890
+ }
891
+ if (selectionMode === "none") {
892
+ return;
893
+ }
894
+ const registry = hasItems ? flatFilteredValues : valuesRef.current;
895
+ setIndices({
896
+ selectedIndex: findSelectionIndex(registry, selectedValue, isItemEqualToValue, multiple)
897
+ });
898
+ }, [open, closeQuery, selectedValue, selectionMode, multiple, hasItems, flatFilteredValues, isItemEqualToValue, setIndices]);
899
+ useIsoLayoutEffect(() => {
900
+ if (items) {
901
+ valuesRef.current = flatFilteredValues;
902
+ listRef.current.length = flatFilteredValues.length;
903
+ }
904
+ }, [items, flatFilteredValues]);
905
+ useIsoLayoutEffect(() => {
906
+ var _a;
907
+ if (!open && ((_a = pendingQueryHighlightRef.current) == null ? void 0 : _a.hasQuery)) {
908
+ pendingQueryHighlightRef.current = null;
909
+ }
910
+ }, [open]);
911
+ useIsoLayoutEffect(() => {
912
+ var _a;
913
+ if (!open && inline && resolvedPopupRef.current) {
914
+ pendingQueryHighlightRef.current = null;
915
+ return;
916
+ }
917
+ const candidateItems = hasItems || hasFilteredItemsProp ? flatFilteredValues : valuesRef.current;
918
+ const pendingHighlight = pendingQueryHighlightRef.current;
919
+ if (pendingHighlight) {
920
+ const listIsNavigable = open || inline || ((_a = store.state.positionerElement) == null ? void 0 : _a.hidden) === false;
921
+ if (pendingHighlight.hasQuery) {
922
+ const input = inputRef.current;
923
+ if (!autoHighlightMode || String(inputValue).trim() === "" || inline && autoHighlightMode !== "always" && (!input || activeElement(input.ownerDocument) !== input)) {
924
+ pendingQueryHighlightRef.current = null;
925
+ } else if (listIsNavigable && // Individually rendered items register without re-running this effect, and their
926
+ // registry has holes mid-reindex, so resolve their request immediately.
927
+ (candidateItems[0] !== void 0 || !hasItems && !hasFilteredItemsProp)) {
928
+ store.set("activeIndex", 0);
929
+ pendingQueryHighlightRef.current = null;
930
+ }
931
+ } else if (String(inputValue).trim() === "") {
932
+ pendingQueryHighlightRef.current = null;
933
+ if (listIsNavigable) {
934
+ const clearedBySelection = pendingHighlight.selection;
935
+ if (autoHighlightMode === "always" && !clearedBySelection && store.state.selectionMode === "none") {
936
+ store.set("activeIndex", 0);
937
+ }
938
+ queueMicrotask(() => {
939
+ if (!store.state.open && (!store.state.inline || resolvedPopupRef.current) || inputRef.current && inputRef.current.value.trim() !== "") {
940
+ return;
941
+ }
942
+ const currentSelectedValue = store.state.selectedValue;
943
+ const isMultiple = store.state.selectionMode === "multiple";
944
+ const hasSelection = isMultiple && Array.isArray(currentSelectedValue) ? currentSelectedValue.length > 0 : store.state.selectionMode !== "none" && currentSelectedValue != null;
945
+ if (hasSelection) {
946
+ const registry = hasItems || hasFilteredItemsProp ? flatFilteredValues : valuesRef.current;
947
+ const toggledIndex = findItemIndex(registry, pendingHighlight.toggledValue, store.state.isItemEqualToValue);
948
+ store.set("activeIndex", toggledIndex !== -1 ? toggledIndex : findSelectionIndex(registry, currentSelectedValue, store.state.isItemEqualToValue, isMultiple));
949
+ } else if (clearedBySelection) {
950
+ store.set("activeIndex", null);
951
+ } else if (autoHighlightMode === "always") {
952
+ store.set("activeIndex", 0);
953
+ }
954
+ });
955
+ }
956
+ }
957
+ }
958
+ if (!open && !inline) {
959
+ return;
960
+ }
961
+ const storeActiveIndex = store.state.activeIndex;
962
+ if (storeActiveIndex == null) {
963
+ if (autoHighlightMode === "always" && candidateItems.length > 0) {
964
+ store.set("activeIndex", 0);
965
+ return;
966
+ }
967
+ emitHighlight(void 0, -1, none);
968
+ return;
969
+ }
970
+ if (storeActiveIndex >= candidateItems.length) {
971
+ emitHighlight(void 0, -1, none);
972
+ store.set("activeIndex", null);
973
+ return;
974
+ }
975
+ const itemValue = candidateItems[storeActiveIndex];
976
+ const previouslyHighlightedItemValue = lastHighlightRef.current.value;
977
+ const isSameItem = previouslyHighlightedItemValue !== NO_ACTIVE_VALUE && compareItemEquality(itemValue, previouslyHighlightedItemValue, store.state.isItemEqualToValue);
978
+ if (lastHighlightRef.current.index !== storeActiveIndex || !isSameItem) {
979
+ emitHighlight(itemValue, storeActiveIndex, none);
980
+ }
981
+ }, [
982
+ activeIndex,
983
+ autoHighlightMode,
984
+ emitHighlight,
985
+ hasFilteredItemsProp,
986
+ hasItems,
987
+ flatFilteredValues,
988
+ inline,
989
+ open,
990
+ resolvedPopupRef,
991
+ store,
992
+ // Reruns the effect when the query changes without affecting the deps above, such as
993
+ // clearing the input when no items are filtered out (individually rendered items).
994
+ inputValue
995
+ ]);
996
+ useIsoLayoutEffect(() => {
997
+ if (selectionMode === "none") {
998
+ setFilled(String(inputValue) !== "");
999
+ return;
1000
+ }
1001
+ setFilled(multiple ? Array.isArray(selectedValue) && selectedValue.length > 0 : selectedValue != null);
1002
+ }, [setFilled, selectionMode, inputValue, selectedValue, multiple]);
1003
+ React.useEffect(() => {
1004
+ if (hasItems && autoHighlightMode && flatFilteredValues.length === 0) {
1005
+ setIndices({
1006
+ activeIndex: null
1007
+ });
1008
+ }
1009
+ }, [hasItems, autoHighlightMode, flatFilteredValues.length, setIndices]);
1010
+ function handleQueryChanged() {
1011
+ if (open && query !== "" && query !== String(initialDefaultInputValue) && !inputMatchesSelectedValue) {
1012
+ setQueryChangedAfterOpen(true);
1013
+ }
1014
+ }
1015
+ function handleOpenChanged() {
1016
+ if (open && closeQuery !== null) {
1017
+ handleInterruptedReopen(false);
1018
+ }
1019
+ }
1020
+ let syncedSelectedLabel = false;
1021
+ function syncInputToSelectedLabel() {
1022
+ if (!syncedSelectedLabel && inputValue !== selectedLabelString) {
1023
+ syncedSelectedLabel = true;
1024
+ setInputValue(selectedLabelString, createChangeEventDetails(none));
1025
+ }
1026
+ }
1027
+ function handleSelectedValueChanged() {
1028
+ if (selectionMode === "none") {
1029
+ return;
1030
+ }
1031
+ clearErrors(name);
1032
+ setDirty(isSelectedValueDirty(selectedValue, validityData.initialValue, isItemEqualToValue));
1033
+ validation.change(selectedValue);
1034
+ if (single && !hasInputValue && !inputInsidePopup) {
1035
+ syncInputToSelectedLabel();
1036
+ }
1037
+ }
1038
+ function syncInputAfterItemsOrLabelChange() {
1039
+ if (single && !hasInputValue && !inputInsidePopup && !queryChangedAfterOpen) {
1040
+ syncInputToSelectedLabel();
1041
+ }
1042
+ }
1043
+ function handleInputValueChanged() {
1044
+ if (selectionMode !== "none") {
1045
+ return;
1046
+ }
1047
+ clearErrors(name);
1048
+ setDirty(inputValue !== validityData.initialValue);
1049
+ validation.change(inputValue);
1050
+ }
1051
+ useValueChanged(query, handleQueryChanged);
1052
+ useValueChanged(open, handleOpenChanged);
1053
+ useValueChanged(selectedValue, handleSelectedValueChanged);
1054
+ useValueChanged(selectedLabelString, syncInputAfterItemsOrLabelChange);
1055
+ useValueChanged(items, syncInputAfterItemsOrLabelChange);
1056
+ useValueChanged(inputValue, handleInputValueChanged);
1057
+ const floatingRootContext = useFloatingRootContext({
1058
+ open: inline ? true : open,
1059
+ onOpenChange: setOpen,
1060
+ elements: {
1061
+ reference: inputInsidePopup ? triggerElement : inputElement,
1062
+ floating: positionerElement
1063
+ }
1064
+ });
1065
+ const ariaHasPopup = grid ? "grid" : "listbox";
1066
+ const expanded = open || inline;
1067
+ const ariaExpanded = expanded ? "true" : "false";
1068
+ const role = React.useMemo(() => {
1069
+ const isPlainInput = (inputElement == null ? void 0 : inputElement.tagName) === "INPUT";
1070
+ const shouldTreatAsInput = inputElement == null || isPlainInput;
1071
+ const shouldApplyAria = shouldTreatAsInput || expanded;
1072
+ const reference = shouldTreatAsInput ? {
1073
+ autoComplete: "off",
1074
+ spellCheck: "false",
1075
+ autoCorrect: "off",
1076
+ autoCapitalize: "none"
1077
+ } : {};
1078
+ if (shouldApplyAria) {
1079
+ reference.role = "combobox";
1080
+ reference["aria-expanded"] = ariaExpanded;
1081
+ reference["aria-haspopup"] = ariaHasPopup;
1082
+ reference["aria-controls"] = expanded ? listElement == null ? void 0 : listElement.id : void 0;
1083
+ reference["aria-autocomplete"] = readOnly ? "none" : autoComplete;
1084
+ }
1085
+ return {
1086
+ reference,
1087
+ floating: {
1088
+ role: "presentation"
1089
+ }
1090
+ };
1091
+ }, [inputElement, expanded, ariaExpanded, ariaHasPopup, listElement == null ? void 0 : listElement.id, autoComplete, readOnly]);
1092
+ const click = useClick(floatingRootContext, {
1093
+ enabled: !disabled && openOnInputClick,
1094
+ event: "mousedown-only",
1095
+ toggle: false,
1096
+ // Apply a small delay for touch to let mobile viewport/keyboard positioning settle.
1097
+ // This avoids top-bottom flip flickers if the preferred position is "top" when first tapping.
1098
+ touchOpenDelay: inputInsidePopup ? 0 : 100,
1099
+ reason: inputPress
1100
+ });
1101
+ const dismiss = useDismiss(floatingRootContext, {
1102
+ enabled: !disabled && !inline,
1103
+ outsidePressEvent: {
1104
+ mouse: "sloppy",
1105
+ // The visual viewport (affected by the mobile software keyboard) can be
1106
+ // somewhat small. The user may want to scroll the screen to see more of
1107
+ // the popup.
1108
+ touch: "intentional"
1109
+ },
1110
+ // Without a popup, let the Escape key bubble the event up to other popups' handlers.
1111
+ bubbles: inline ? true : void 0,
1112
+ outsidePress(event) {
1113
+ const target = getTarget(event);
1114
+ return !contains(triggerElement, target) && !contains(clearRef.current, target) && !contains(chipsContainerRef.current, target) && !contains(inputGroupElement, target);
1115
+ }
1116
+ });
1117
+ const listNavigation2 = useListNavigation(floatingRootContext, {
1118
+ enabled: !disabled,
1119
+ id,
1120
+ listRef,
1121
+ activeIndex,
1122
+ selectedIndex,
1123
+ virtual: true,
1124
+ loopFocus,
1125
+ allowEscape: loopFocus && !autoHighlightMode,
1126
+ focusItemOnOpen: queryChangedAfterOpen || selectionMode === "none" && !autoHighlightMode ? false : "auto",
1127
+ focusItemOnHover: highlightItemOnHover,
1128
+ resetOnPointerLeave: !keepHighlight,
1129
+ orientation: grid ? "horizontal" : void 0,
1130
+ rtl: direction === "rtl",
1131
+ disabledIndices: EMPTY_ARRAY,
1132
+ grid: grid ? gridNavigation : void 0,
1133
+ onNavigate(nextActiveIndex, event) {
1134
+ if (!event && !open && !(inline && nextActiveIndex === null) || transitionStatus === "ending") {
1135
+ return;
1136
+ }
1137
+ setIndices({
1138
+ activeIndex: nextActiveIndex,
1139
+ type: getHighlightReason(event),
1140
+ event: event == null ? void 0 : event.nativeEvent
1141
+ });
1142
+ }
1143
+ });
1144
+ const inputProps = React.useMemo(() => mergeProps(listNavigation2.reference, {
1145
+ onKeyDown(event) {
1146
+ if (grid && store.state.activeIndex == null && (event.key === "ArrowLeft" || event.key === "ArrowRight")) {
1147
+ event.preventBaseUIHandler();
1148
+ }
1149
+ }
1150
+ }, dismiss.reference, click.reference, role.reference), [listNavigation2.reference, dismiss.reference, click.reference, role.reference, grid, store]);
1151
+ const popupProps = React.useMemo(() => mergeProps(FOCUSABLE_POPUP_PROPS, dismiss.floating), [dismiss.floating]);
1152
+ const listProps = React.useMemo(() => mergeProps(listNavigation2.floating, role.floating), [listNavigation2.floating, role.floating]);
1153
+ const itemRoot = React.useMemo(() => {
1154
+ const listNavigationItemProps = listNavigation2.item;
1155
+ return {
1156
+ // Combobox keeps focus on the input; item focus would incorrectly sync
1157
+ // list navigation state from DOM focus.
1158
+ props: listNavigationItemProps ? {
1159
+ ...listNavigationItemProps,
1160
+ onFocus: void 0
1161
+ } : EMPTY_OBJECT,
1162
+ id,
1163
+ selectionMode,
1164
+ disabled,
1165
+ readOnly,
1166
+ isItemEqualToValue
1167
+ };
1168
+ }, [listNavigation2.item, id, selectionMode, disabled, readOnly, isItemEqualToValue]);
1169
+ store.useContextCallback("setOpen", setOpen);
1170
+ store.useContextCallback("setInputValue", setInputValue);
1171
+ store.useContextCallback("setSelectedValue", setSelectedValue);
1172
+ store.useContextCallback("setIndices", setIndices);
1173
+ store.useContextCallback("handleSelection", handleSelection);
1174
+ store.useContextCallback("forceMount", forceMount);
1175
+ store.useContextCallback("requestSubmit", requestSubmit);
1176
+ store.useContextCallback("onOpenChangeComplete", onOpenChangeCompleteProp);
1177
+ useOnFirstRender(() => {
1178
+ store.update({
1179
+ inline: inlineProp,
1180
+ popupProps,
1181
+ listProps,
1182
+ inputProps,
1183
+ triggerProps,
1184
+ itemRoot
1185
+ });
1186
+ });
1187
+ const syncedValues = {
1188
+ id,
1189
+ selectedValue,
1190
+ open,
1191
+ mounted,
1192
+ transitionStatus,
1193
+ items: storeItems,
1194
+ inline: inlineProp,
1195
+ popupProps,
1196
+ listProps,
1197
+ inputProps,
1198
+ triggerProps,
1199
+ itemRoot,
1200
+ openMethod,
1201
+ selectionMode,
1202
+ name,
1203
+ form,
1204
+ disabled,
1205
+ readOnly,
1206
+ required,
1207
+ grid,
1208
+ virtualized,
1209
+ openOnInputClick,
1210
+ itemToStringLabel,
1211
+ modal,
1212
+ autoHighlight: autoHighlightMode,
1213
+ isItemEqualToValue,
1214
+ submitOnItemClick,
1215
+ hasInputValue
1216
+ };
1217
+ useIsoLayoutEffect(() => {
1218
+ store.update({
1219
+ ...syncedValues,
1220
+ inputOwnsFormValue: selectionMode === "none" && (inlineProp || !store.state.inputInsidePopup)
1221
+ });
1222
+ }, [store, ...Object.values(syncedValues)]);
1223
+ const hiddenInputRef = useMergedRefs(inputRefProp, validation.inputRef);
1224
+ const itemsContextValue = React.useMemo(() => ({
1225
+ query,
1226
+ hasItems,
1227
+ filteredItems,
1228
+ flatFilteredValues
1229
+ }), [query, hasItems, filteredItems, flatFilteredValues]);
1230
+ const serializedValue = React.useMemo(() => {
1231
+ if (Array.isArray(fieldRawValue)) {
1232
+ return "";
1233
+ }
1234
+ return stringifyAsValue(fieldRawValue, itemToStringValue);
1235
+ }, [fieldRawValue, itemToStringValue]);
1236
+ const hasMultipleSelection = multiple && Array.isArray(selectedValue) && selectedValue.length > 0;
1237
+ const hiddenInputName = multiple || selectionMode === "none" && inputOwnsFormValue ? void 0 : name;
1238
+ const hiddenInputs = React.useMemo(() => {
1239
+ if (!multiple || !Array.isArray(selectedValue) || !name) {
1240
+ return null;
1241
+ }
1242
+ return selectedValue.map((value) => {
1243
+ const currentSerializedValue = stringifyAsValue(value, itemToStringValue);
1244
+ return /* @__PURE__ */ jsx("input", {
1245
+ type: "hidden",
1246
+ form,
1247
+ name,
1248
+ value: currentSerializedValue,
1249
+ disabled
1250
+ }, currentSerializedValue);
1251
+ });
1252
+ }, [multiple, selectedValue, form, name, itemToStringValue, disabled]);
1253
+ const children = /* @__PURE__ */ jsxs(React.Fragment, {
1254
+ children: [props.children, /* @__PURE__ */ jsx("input", {
1255
+ ...validation.getValidationProps(disabled, {
1256
+ // Move focus when the hidden input is focused.
1257
+ onFocus() {
1258
+ var _a;
1259
+ if (inputInsidePopup) {
1260
+ triggerElement == null ? void 0 : triggerElement.focus();
1261
+ return;
1262
+ }
1263
+ (_a = inputRef.current || triggerElement) == null ? void 0 : _a.focus();
1264
+ },
1265
+ // Handle browser autofill.
1266
+ onChange(event) {
1267
+ if (event.nativeEvent.defaultPrevented || disabled || readOnly) {
1268
+ return;
1269
+ }
1270
+ const nextValue = event.currentTarget.value;
1271
+ const nextValueLower = nextValue.toLowerCase();
1272
+ const details = createChangeEventDetails(none, event.nativeEvent);
1273
+ const findSerializedMatchIndex = () => valuesRef.current.findIndex((candidate) => stringifyAsValue(candidate, itemToStringValue).toLowerCase() === nextValueLower || stringifyValueLabel(candidate).toLowerCase() === nextValueLower);
1274
+ function handleChange() {
1275
+ if (multiple) {
1276
+ return;
1277
+ }
1278
+ if (selectionMode === "none") {
1279
+ setInputValue(nextValue, details);
1280
+ return;
1281
+ }
1282
+ let matchingIndex = findSerializedMatchIndex();
1283
+ if (matchingIndex === -1) {
1284
+ matchingIndex = valuesRef.current.findIndex((_, index) => {
1285
+ const renderedLabel = labelsRef.current[index];
1286
+ return renderedLabel != null && renderedLabel.toLowerCase() === nextValueLower;
1287
+ });
1288
+ }
1289
+ const matchingValue = matchingIndex === -1 ? void 0 : valuesRef.current[matchingIndex];
1290
+ if (matchingValue != null) {
1291
+ setSelectedValue == null ? void 0 : setSelectedValue(matchingValue, details);
1292
+ }
1293
+ }
1294
+ if (single) {
1295
+ forceMount();
1296
+ if (items && findSerializedMatchIndex() === -1) {
1297
+ store.set("forceMounted", true);
1298
+ }
1299
+ }
1300
+ queueMicrotask(handleChange);
1301
+ }
1302
+ }),
1303
+ id: id && hiddenInputName == null ? `${id}-hidden-input` : void 0,
1304
+ form,
1305
+ name: hiddenInputName,
1306
+ autoComplete: formAutoComplete,
1307
+ disabled,
1308
+ required: required && !hasMultipleSelection,
1309
+ readOnly,
1310
+ value: serializedValue,
1311
+ ref: hiddenInputRef,
1312
+ style: hiddenInputName ? visuallyHiddenInput : visuallyHidden,
1313
+ tabIndex: -1,
1314
+ "aria-hidden": true,
1315
+ suppressHydrationWarning: true
1316
+ }), hiddenInputs]
1317
+ });
1318
+ return /* @__PURE__ */ jsx(ComboboxRootContext.Provider, {
1319
+ value: store,
1320
+ children: /* @__PURE__ */ jsx(ComboboxFloatingContext.Provider, {
1321
+ value: floatingRootContext,
1322
+ children: /* @__PURE__ */ jsx(ComboboxHasItemsContext.Provider, {
1323
+ value: hasItems,
1324
+ children: /* @__PURE__ */ jsx(ComboboxDerivedItemsContext.Provider, {
1325
+ value: itemsContextValue,
1326
+ children: /* @__PURE__ */ jsx(ComboboxInputValueContext.Provider, {
1327
+ value: inputValue,
1328
+ children
1329
+ })
1330
+ })
1331
+ })
1332
+ })
1333
+ });
1334
+ }
1335
+ function ComboboxRoot(props) {
1336
+ const {
1337
+ multiple = false,
1338
+ defaultValue,
1339
+ value,
1340
+ onValueChange,
1341
+ autoComplete,
1342
+ ...other
1343
+ } = props;
1344
+ return /* @__PURE__ */ jsx(AriaCombobox, {
1345
+ ...other,
1346
+ selectionMode: multiple ? "multiple" : "single",
1347
+ selectedValue: value,
1348
+ defaultSelectedValue: defaultValue,
1349
+ onSelectedValueChange: onValueChange,
1350
+ formAutoComplete: autoComplete
1351
+ });
1352
+ }
1353
+ const popupSide = "data-popup-side";
1354
+ const listEmpty = "data-list-empty";
1355
+ const triggerStateAttributesMapping = {
1356
+ ...pressableTriggerOpenStateMapping,
1357
+ ...fieldValidityMapping,
1358
+ popupSide: (side) => side ? {
1359
+ [popupSide]: side
1360
+ } : null,
1361
+ listEmpty: (empty) => empty ? {
1362
+ [listEmpty]: ""
1363
+ } : null
1364
+ };
1365
+ const ComboboxChipsContext = /* @__PURE__ */ React.createContext(void 0);
1366
+ if (process.env.NODE_ENV !== "production") ComboboxChipsContext.displayName = "ComboboxChipsContext";
1367
+ function useComboboxChipsContext() {
1368
+ return React.useContext(ComboboxChipsContext);
1369
+ }
1370
+ const ComboboxPositionerContext = /* @__PURE__ */ React.createContext(void 0);
1371
+ if (process.env.NODE_ENV !== "production") ComboboxPositionerContext.displayName = "ComboboxPositionerContext";
1372
+ function useComboboxPositionerContext(optional) {
1373
+ const context = React.useContext(ComboboxPositionerContext);
1374
+ if (context === void 0 && !optional) {
1375
+ throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: <Combobox.Popup> and <Combobox.Arrow> must be used within the <Combobox.Positioner> component" : formatErrorMessage(21));
1376
+ }
1377
+ return context;
1378
+ }
1379
+ const ComboboxInternalDismissButton = /* @__PURE__ */ React.forwardRef(function ComboboxInternalDismissButton2(_, forwardedRef) {
1380
+ const store = useComboboxRootContext();
1381
+ const {
1382
+ buttonRef,
1383
+ getButtonProps
1384
+ } = useButton({
1385
+ native: false
1386
+ });
1387
+ const mergedRef = useMergedRefs(forwardedRef, buttonRef);
1388
+ function handleDismiss(event) {
1389
+ store.context.setOpen(false, createChangeEventDetails(closePress, event.nativeEvent, event.currentTarget));
1390
+ }
1391
+ const dismissProps = getButtonProps({
1392
+ onClick: handleDismiss
1393
+ });
1394
+ return /* @__PURE__ */ jsx("span", {
1395
+ ref: mergedRef,
1396
+ ...dismissProps,
1397
+ "aria-label": "Dismiss",
1398
+ tabIndex: void 0,
1399
+ style: visuallyHiddenInput
1400
+ });
1401
+ });
1402
+ if (process.env.NODE_ENV !== "production") ComboboxInternalDismissButton.displayName = "ComboboxInternalDismissButton";
1403
+ function usePopupSide(store) {
1404
+ const mounted = store.useState("mounted");
1405
+ const popupSide2 = store.useState("popupSide");
1406
+ const positionerElement = store.useState("positionerElement");
1407
+ return mounted && positionerElement ? popupSide2 : null;
1408
+ }
1409
+ function useListEmpty() {
1410
+ return useComboboxDerivedItemsContext().filteredItems.length === 0;
1411
+ }
1412
+ function getChipNavigationKeys(direction) {
1413
+ return direction === "rtl" ? ["ArrowRight", "ArrowLeft"] : ["ArrowLeft", "ArrowRight"];
1414
+ }
1415
+ function getIndexAfterChipRemoval(index, chipCount) {
1416
+ const nextIndex = index >= chipCount - 1 ? chipCount - 2 : index;
1417
+ return nextIndex >= 0 ? nextIndex : void 0;
1418
+ }
1419
+ function clickHighlightedItem(store, activeIndex, nativeEvent) {
1420
+ const listItem = store.context.listRef.current[activeIndex];
1421
+ if (listItem) {
1422
+ store.context.selectionEventRef.current = nativeEvent;
1423
+ listItem.click();
1424
+ store.context.selectionEventRef.current = null;
1425
+ }
1426
+ }
1427
+ const ComboboxInput$1 = /* @__PURE__ */ React.forwardRef(function ComboboxInput(componentProps, forwardedRef) {
1428
+ const {
1429
+ render,
1430
+ className,
1431
+ disabled: disabledProp = false,
1432
+ id: idProp,
1433
+ style,
1434
+ ...elementProps
1435
+ } = componentProps;
1436
+ const {
1437
+ state: fieldState,
1438
+ disabled: fieldDisabled,
1439
+ setTouched,
1440
+ validationMode,
1441
+ validation
1442
+ } = useFieldRootContext();
1443
+ const {
1444
+ labelId: fieldLabelId
1445
+ } = useLabelableContext();
1446
+ const comboboxChipsContext = useComboboxChipsContext();
1447
+ const positioning = useComboboxPositionerContext(true);
1448
+ const hasPositionerParent = Boolean(positioning);
1449
+ const store = useComboboxRootContext();
1450
+ const inputValue = useComboboxInputValueContext();
1451
+ const direction = useDirection();
1452
+ const required = store.useState("required");
1453
+ const comboboxDisabled = store.useState("disabled");
1454
+ const readOnly = store.useState("readOnly");
1455
+ const name = store.useState("name");
1456
+ const form = store.useState("form");
1457
+ const selectionMode = store.useState("selectionMode");
1458
+ const autoHighlightMode = store.useState("autoHighlight");
1459
+ const inputProps = store.useState("inputProps");
1460
+ const triggerProps = store.useState("triggerProps");
1461
+ const open = store.useState("open");
1462
+ const mounted = store.useState("mounted");
1463
+ const selectedValue = store.useState("selectedValue");
1464
+ const rootId = store.useState("id");
1465
+ const inline = store.useState("inline");
1466
+ const modal = store.useState("modal");
1467
+ const autoHighlightEnabled = Boolean(autoHighlightMode);
1468
+ const popupSide2 = usePopupSide(store);
1469
+ const disabled = fieldDisabled || comboboxDisabled || disabledProp;
1470
+ const listEmpty2 = useListEmpty();
1471
+ const setFocused = useSetFieldFocused(disabled, store.context.inputRef);
1472
+ const isInsidePopup = hasPositionerParent || inline;
1473
+ const focusManagerModal = !isInsidePopup || modal;
1474
+ const id = useBaseUiId(idProp ?? (!isInsidePopup ? rootId : void 0));
1475
+ const fieldStateForInput = hasPositionerParent ? DEFAULT_FIELD_STATE_ATTRIBUTES : fieldState;
1476
+ const [composingValue, setComposingValue] = React.useState(null);
1477
+ const isComposingRef = React.useRef(false);
1478
+ const lastActiveIndexRef = React.useRef(null);
1479
+ useIsoLayoutEffect(() => {
1480
+ if (!open) {
1481
+ lastActiveIndexRef.current = null;
1482
+ }
1483
+ }, [open]);
1484
+ const inputOwnsFormValue = selectionMode === "none" && !hasPositionerParent;
1485
+ const setInputElement = useStableCallback((element2) => {
1486
+ const nextIsInsidePopup = hasPositionerParent || store.state.inline;
1487
+ if (nextIsInsidePopup && !store.state.hasInputValue) {
1488
+ store.context.setInputValue("", createChangeEventDetails(none));
1489
+ }
1490
+ store.update({
1491
+ inputElement: element2,
1492
+ inputInsidePopup: nextIsInsidePopup,
1493
+ inputOwnsFormValue
1494
+ });
1495
+ });
1496
+ const validationProps = hasPositionerParent ? elementProps : validation.getValidationProps(disabled, elementProps);
1497
+ function clearHighlight(event) {
1498
+ store.context.setIndices({
1499
+ activeIndex: null,
1500
+ selectedIndex: null,
1501
+ type: getHighlightReason(event),
1502
+ event
1503
+ });
1504
+ }
1505
+ const state = {
1506
+ ...fieldStateForInput,
1507
+ open,
1508
+ disabled,
1509
+ readOnly,
1510
+ popupSide: popupSide2,
1511
+ listEmpty: listEmpty2
1512
+ };
1513
+ function handleKeyDown(event) {
1514
+ if (!comboboxChipsContext) {
1515
+ return void 0;
1516
+ }
1517
+ let nextIndex;
1518
+ const renderedChipsCount = comboboxChipsContext.chipsRef.current.length;
1519
+ const [previousChipKey] = getChipNavigationKeys(direction);
1520
+ if (event.key === previousChipKey && (event.currentTarget.selectionStart ?? 0) === 0 && selectedValue.length > 0) {
1521
+ event.preventDefault();
1522
+ nextIndex = renderedChipsCount > 0 ? renderedChipsCount - 1 : void 0;
1523
+ }
1524
+ return nextIndex;
1525
+ }
1526
+ const element = useRenderElement("input", componentProps, {
1527
+ state,
1528
+ ref: [forwardedRef, store.context.inputRef, setInputElement],
1529
+ props: [inputProps, triggerProps, {
1530
+ value: composingValue ?? inputValue,
1531
+ "aria-readonly": readOnly || void 0,
1532
+ "aria-required": required || void 0,
1533
+ "aria-labelledby": fieldLabelId,
1534
+ disabled,
1535
+ readOnly,
1536
+ required: selectionMode === "none" ? required : void 0,
1537
+ form,
1538
+ ...inputOwnsFormValue && name && {
1539
+ name
1540
+ },
1541
+ id,
1542
+ onFocus() {
1543
+ setFocused(true);
1544
+ if (!inline) {
1545
+ return;
1546
+ }
1547
+ const nextActiveIndex = lastActiveIndexRef.current;
1548
+ lastActiveIndexRef.current = null;
1549
+ if (nextActiveIndex == null || // `valuesRef` can be sparse, so guard against restoring a removed slot.
1550
+ !Object.hasOwn(store.context.valuesRef.current, nextActiveIndex)) {
1551
+ return;
1552
+ }
1553
+ store.context.setIndices({
1554
+ activeIndex: nextActiveIndex
1555
+ });
1556
+ },
1557
+ onBlur() {
1558
+ setTouched(true);
1559
+ setFocused(false);
1560
+ const activeIndex = store.state.activeIndex;
1561
+ if (inline && activeIndex !== null && autoHighlightMode !== "always") {
1562
+ lastActiveIndexRef.current = activeIndex;
1563
+ store.context.setIndices({
1564
+ activeIndex: null
1565
+ });
1566
+ }
1567
+ if (validationMode === "onBlur") {
1568
+ const valueToValidate = selectionMode === "none" ? inputValue : selectedValue;
1569
+ validation.commit(valueToValidate);
1570
+ }
1571
+ },
1572
+ onCompositionStart(event) {
1573
+ if (android) {
1574
+ return;
1575
+ }
1576
+ isComposingRef.current = true;
1577
+ setComposingValue(event.currentTarget.value);
1578
+ },
1579
+ onCompositionEnd(event) {
1580
+ isComposingRef.current = false;
1581
+ const next = event.currentTarget.value;
1582
+ setComposingValue(null);
1583
+ store.context.setInputValue(next, createChangeEventDetails(inputChange, event.nativeEvent));
1584
+ },
1585
+ onChange(event) {
1586
+ const nativeEvent = event.nativeEvent;
1587
+ const inputType = nativeEvent.inputType;
1588
+ const autofillLikeInput = !inputType || inputType === "insertReplacementText";
1589
+ const shouldOpenOnInput = isComposingRef.current || !autofillLikeInput;
1590
+ function maybeOpenOnInput(trimmed) {
1591
+ if (readOnly || disabled || !trimmed || !shouldOpenOnInput) {
1592
+ return;
1593
+ }
1594
+ store.context.setOpen(true, createChangeEventDetails(inputChange, nativeEvent));
1595
+ if (!autoHighlightEnabled) {
1596
+ clearHighlight(nativeEvent);
1597
+ }
1598
+ }
1599
+ if (isComposingRef.current) {
1600
+ const nextVal = event.currentTarget.value;
1601
+ setComposingValue(nextVal);
1602
+ if (nextVal === "" && !store.state.openOnInputClick && !store.state.inputInsidePopup) {
1603
+ store.context.setOpen(false, createChangeEventDetails(inputClear, nativeEvent));
1604
+ }
1605
+ const trimmed = nextVal.trim();
1606
+ const shouldMaintainHighlight = autoHighlightEnabled && trimmed !== "";
1607
+ maybeOpenOnInput(trimmed);
1608
+ if (open && store.state.activeIndex !== null && !shouldMaintainHighlight) {
1609
+ clearHighlight(nativeEvent);
1610
+ }
1611
+ return;
1612
+ }
1613
+ const inputChangeDetails = createChangeEventDetails(inputChange, nativeEvent);
1614
+ store.context.setInputValue(event.currentTarget.value, inputChangeDetails);
1615
+ if (inputChangeDetails.isCanceled) {
1616
+ return;
1617
+ }
1618
+ const empty = event.currentTarget.value === "";
1619
+ const clearDetails = createChangeEventDetails(inputClear, nativeEvent);
1620
+ if (empty && !store.state.inputInsidePopup) {
1621
+ if (selectionMode === "single") {
1622
+ store.context.setSelectedValue(null, clearDetails);
1623
+ }
1624
+ if (!store.state.openOnInputClick) {
1625
+ store.context.setOpen(false, clearDetails);
1626
+ }
1627
+ }
1628
+ maybeOpenOnInput(event.currentTarget.value.trim());
1629
+ if (open && store.state.activeIndex !== null && !autoHighlightEnabled) {
1630
+ clearHighlight(nativeEvent);
1631
+ }
1632
+ },
1633
+ onKeyDown(event) {
1634
+ var _a;
1635
+ if (event.ctrlKey || event.shiftKey || event.altKey || event.metaKey) {
1636
+ return;
1637
+ }
1638
+ if (disabled || readOnly) {
1639
+ if (readOnly && event.key === "Enter" && open && store.state.activeIndex !== null) {
1640
+ stopEvent(event);
1641
+ }
1642
+ return;
1643
+ }
1644
+ const input = event.currentTarget;
1645
+ const scrollAmount = input.scrollWidth - input.clientWidth;
1646
+ const isRTL = direction === "rtl";
1647
+ if (event.key === "Home") {
1648
+ stopEvent(event);
1649
+ const cursor = gecko && isRTL ? input.value.length : 0;
1650
+ input.setSelectionRange(cursor, cursor);
1651
+ input.scrollLeft = 0;
1652
+ return;
1653
+ }
1654
+ if (event.key === "End") {
1655
+ stopEvent(event);
1656
+ const cursor = gecko && isRTL ? 0 : input.value.length;
1657
+ input.setSelectionRange(cursor, cursor);
1658
+ input.scrollLeft = isRTL ? -scrollAmount : scrollAmount;
1659
+ return;
1660
+ }
1661
+ if (!mounted && event.key === "Escape") {
1662
+ const isClear = selectionMode === "multiple" && Array.isArray(selectedValue) ? selectedValue.length === 0 : selectedValue === null;
1663
+ const details = createChangeEventDetails(escapeKey, event.nativeEvent);
1664
+ const value = selectionMode === "multiple" ? [] : null;
1665
+ store.context.setInputValue("", details);
1666
+ store.context.setSelectedValue(value, details);
1667
+ if (!isClear && !store.state.inline && !details.isPropagationAllowed) {
1668
+ event.stopPropagation();
1669
+ }
1670
+ return;
1671
+ }
1672
+ if (comboboxChipsContext && event.key === "Backspace" && input.value === "" && Array.isArray(selectedValue) && selectedValue.length > 0) {
1673
+ const renderedChipsCount = comboboxChipsContext.chipsRef.current.length;
1674
+ const removalIndex = renderedChipsCount > 0 ? renderedChipsCount - 1 : selectedValue.length - 1;
1675
+ const newValue = selectedValue.filter((_, index) => index !== removalIndex);
1676
+ clearHighlight(event.nativeEvent);
1677
+ store.context.setSelectedValue(newValue, createChangeEventDetails(none, event.nativeEvent));
1678
+ return;
1679
+ }
1680
+ const nextIndex = handleKeyDown(event);
1681
+ if (nextIndex !== void 0) {
1682
+ (_a = comboboxChipsContext == null ? void 0 : comboboxChipsContext.chipsRef.current[nextIndex]) == null ? void 0 : _a.focus();
1683
+ }
1684
+ if (event.which === 229) {
1685
+ return;
1686
+ }
1687
+ if (event.key === "Enter" && open) {
1688
+ const activeIndex = store.state.activeIndex;
1689
+ const nativeEvent = event.nativeEvent;
1690
+ if (activeIndex === null) {
1691
+ if (inline) {
1692
+ return;
1693
+ }
1694
+ store.context.setOpen(false, createChangeEventDetails(none, nativeEvent));
1695
+ return;
1696
+ }
1697
+ stopEvent(event);
1698
+ clickHighlightedItem(store, activeIndex, nativeEvent);
1699
+ }
1700
+ }
1701
+ }, validationProps],
1702
+ stateAttributesMapping: triggerStateAttributesMapping
1703
+ });
1704
+ const renderedInput = hasPositionerParent ? /* @__PURE__ */ jsx(FieldRootContext.Provider, {
1705
+ value: DEFAULT_FIELD_ROOT_CONTEXT,
1706
+ children: element
1707
+ }) : element;
1708
+ return /* @__PURE__ */ jsxs(React.Fragment, {
1709
+ children: [open && focusManagerModal && /* @__PURE__ */ jsx(ComboboxInternalDismissButton, {
1710
+ ref: store.context.startDismissRef
1711
+ }), renderedInput]
1712
+ });
1713
+ });
1714
+ if (process.env.NODE_ENV !== "production") ComboboxInput$1.displayName = "ComboboxInput";
1715
+ function handleInputPress(event, store, disabled, shouldIgnoreTarget) {
1716
+ var _a;
1717
+ if (event.baseUIHandlerPrevented) {
1718
+ return;
1719
+ }
1720
+ const target = getTarget(event.nativeEvent);
1721
+ const targetElement = isElement(target) ? target : null;
1722
+ if (targetElement !== event.currentTarget && ((shouldIgnoreTarget == null ? void 0 : shouldIgnoreTarget(targetElement)) || isInteractiveElement(targetElement))) {
1723
+ return;
1724
+ }
1725
+ event.preventDefault();
1726
+ if (disabled) {
1727
+ return;
1728
+ }
1729
+ (_a = store.context.inputRef.current) == null ? void 0 : _a.focus();
1730
+ if (store.state.openOnInputClick) {
1731
+ store.context.setOpen(true, createChangeEventDetails(inputPress, event.nativeEvent));
1732
+ }
1733
+ }
1734
+ const ComboboxInputGroup = /* @__PURE__ */ React.forwardRef(function ComboboxInputGroup2(componentProps, forwardedRef) {
1735
+ const {
1736
+ render,
1737
+ className,
1738
+ style,
1739
+ ...elementProps
1740
+ } = componentProps;
1741
+ const {
1742
+ state: fieldState
1743
+ } = useFieldRootContext();
1744
+ const store = useComboboxRootContext();
1745
+ const open = store.useState("open");
1746
+ const comboboxDisabled = store.useState("disabled");
1747
+ const readOnly = store.useState("readOnly");
1748
+ const hasSelectedValue = store.useState("hasSelectedValue");
1749
+ const selectionMode = store.useState("selectionMode");
1750
+ const popupSide2 = usePopupSide(store);
1751
+ const disabled = comboboxDisabled;
1752
+ const listEmpty2 = useListEmpty();
1753
+ const placeholder = selectionMode === "none" ? false : !hasSelectedValue;
1754
+ const state = {
1755
+ ...fieldState,
1756
+ open,
1757
+ disabled,
1758
+ readOnly,
1759
+ popupSide: popupSide2,
1760
+ listEmpty: listEmpty2,
1761
+ placeholder
1762
+ };
1763
+ const setInputGroupElement = useStableCallback((element) => {
1764
+ store.set("inputGroupElement", element);
1765
+ });
1766
+ return useRenderElement("div", componentProps, {
1767
+ ref: [forwardedRef, setInputGroupElement],
1768
+ props: [{
1769
+ role: "group",
1770
+ onMouseDown(event) {
1771
+ handleInputPress(event, store, disabled, (target) => {
1772
+ return contains(store.context.chipsContainerRef.current, target);
1773
+ });
1774
+ }
1775
+ }, elementProps],
1776
+ state,
1777
+ stateAttributesMapping: triggerStateAttributesMapping
1778
+ });
1779
+ });
1780
+ if (process.env.NODE_ENV !== "production") ComboboxInputGroup.displayName = "ComboboxInputGroup";
1781
+ const ComboboxTrigger$1 = /* @__PURE__ */ React.forwardRef(function ComboboxTrigger(componentProps, forwardedRef) {
1782
+ const {
1783
+ render,
1784
+ className,
1785
+ nativeButton = true,
1786
+ disabled: disabledProp = false,
1787
+ id: idProp,
1788
+ style,
1789
+ ...elementProps
1790
+ } = componentProps;
1791
+ const {
1792
+ state: fieldState,
1793
+ disabled: fieldDisabled,
1794
+ setTouched,
1795
+ validationMode,
1796
+ validation
1797
+ } = useFieldRootContext();
1798
+ const {
1799
+ labelId: fieldLabelId
1800
+ } = useLabelableContext();
1801
+ const store = useComboboxRootContext();
1802
+ const selectionMode = store.useState("selectionMode");
1803
+ const comboboxDisabled = store.useState("disabled");
1804
+ const readOnly = store.useState("readOnly");
1805
+ const required = store.useState("required");
1806
+ const positionerElement = store.useState("positionerElement");
1807
+ const listElement = store.useState("listElement");
1808
+ const storedPopupId = store.useState("popupId");
1809
+ const triggerProps = store.useState("triggerProps");
1810
+ const inputInsidePopup = store.useState("inputInsidePopup");
1811
+ const rootId = store.useState("id");
1812
+ const comboboxLabelId = store.useState("labelId");
1813
+ const open = store.useState("open");
1814
+ const selectedValue = store.useState("selectedValue");
1815
+ const activeIndex = store.useState("activeIndex");
1816
+ const selectedIndex = store.useState("selectedIndex");
1817
+ const hasSelectedValue = store.useState("hasSelectedValue");
1818
+ const floatingRootContext = useComboboxFloatingContext();
1819
+ const inputValue = useComboboxInputValueContext();
1820
+ const focusTimeout = useTimeout();
1821
+ const disabled = fieldDisabled || comboboxDisabled || disabledProp;
1822
+ const listEmpty2 = useListEmpty();
1823
+ const popupSide2 = usePopupSide(store);
1824
+ const triggerRef = React.useRef(null);
1825
+ const setFocused = useSetFieldFocused(disabled, triggerRef);
1826
+ useLabelableId({
1827
+ id: inputInsidePopup ? idProp : void 0
1828
+ });
1829
+ const id = inputInsidePopup ? idProp ?? rootId : idProp;
1830
+ const ariaLabelledBy = resolveAriaLabelledBy(fieldLabelId, comboboxLabelId);
1831
+ let ariaControls;
1832
+ if (open && inputInsidePopup) {
1833
+ ariaControls = storedPopupId ?? getComboboxPopupId(rootId);
1834
+ } else if (open) {
1835
+ ariaControls = listElement == null ? void 0 : listElement.id;
1836
+ }
1837
+ const currentPointerTypeRef = React.useRef("");
1838
+ function trackPointerType(event) {
1839
+ currentPointerTypeRef.current = event.pointerType;
1840
+ }
1841
+ const {
1842
+ reference: triggerTypeaheadProps
1843
+ } = useTypeahead(floatingRootContext, {
1844
+ // Typeahead on a closed trigger commits a value rather than moving a highlight, so it stays
1845
+ // gated on `readOnly`.
1846
+ enabled: !open && !readOnly && !comboboxDisabled && selectionMode === "single",
1847
+ listRef: store.context.labelsRef,
1848
+ activeIndex,
1849
+ selectedIndex,
1850
+ onMatch(index) {
1851
+ const nextSelectedValue = store.context.valuesRef.current[index];
1852
+ if (nextSelectedValue !== void 0) {
1853
+ store.context.setSelectedValue(nextSelectedValue, createChangeEventDetails(none));
1854
+ }
1855
+ }
1856
+ });
1857
+ const {
1858
+ reference: triggerClickProps
1859
+ } = useClick(floatingRootContext, {
1860
+ enabled: !comboboxDisabled,
1861
+ event: "mousedown"
1862
+ });
1863
+ const {
1864
+ buttonRef,
1865
+ getButtonProps
1866
+ } = useButton({
1867
+ native: nativeButton,
1868
+ disabled
1869
+ });
1870
+ const state = {
1871
+ ...fieldState,
1872
+ readOnly,
1873
+ open,
1874
+ disabled,
1875
+ popupSide: popupSide2,
1876
+ listEmpty: listEmpty2,
1877
+ placeholder: selectionMode === "none" ? false : !hasSelectedValue
1878
+ };
1879
+ const setTriggerElement = useStableCallback((element2) => {
1880
+ store.set("triggerElement", element2);
1881
+ });
1882
+ const element = useRenderElement("button", componentProps, {
1883
+ ref: [forwardedRef, buttonRef, triggerRef, setTriggerElement],
1884
+ state,
1885
+ props: [triggerProps, triggerClickProps, triggerTypeaheadProps, {
1886
+ id,
1887
+ tabIndex: inputInsidePopup ? 0 : -1,
1888
+ role: inputInsidePopup ? "combobox" : void 0,
1889
+ "aria-expanded": open,
1890
+ "aria-haspopup": inputInsidePopup ? "dialog" : "listbox",
1891
+ "aria-controls": ariaControls,
1892
+ "aria-required": inputInsidePopup ? required || void 0 : void 0,
1893
+ // Only valid alongside the `combobox` role; without it the trigger is a plain button, and
1894
+ // the `Combobox.Input` outside the popup already carries `aria-readonly`.
1895
+ "aria-readonly": inputInsidePopup ? readOnly || void 0 : void 0,
1896
+ "aria-labelledby": ariaLabelledBy,
1897
+ onPointerDown: trackPointerType,
1898
+ onPointerEnter: trackPointerType,
1899
+ onFocus() {
1900
+ setFocused(true);
1901
+ if (disabled) {
1902
+ return;
1903
+ }
1904
+ focusTimeout.start(0, store.context.forceMount);
1905
+ },
1906
+ onBlur(event) {
1907
+ if (contains(positionerElement, event.relatedTarget)) {
1908
+ return;
1909
+ }
1910
+ setTouched(true);
1911
+ setFocused(false);
1912
+ if (validationMode === "onBlur") {
1913
+ const valueToValidate = selectionMode === "none" ? inputValue : selectedValue;
1914
+ validation.commit(valueToValidate);
1915
+ }
1916
+ },
1917
+ onMouseDown(event) {
1918
+ var _a;
1919
+ if (disabled) {
1920
+ return;
1921
+ }
1922
+ if (!inputInsidePopup) {
1923
+ floatingRootContext.set("domReferenceElement", event.currentTarget);
1924
+ }
1925
+ store.context.forceMount();
1926
+ if (currentPointerTypeRef.current !== "touch") {
1927
+ (_a = store.context.inputRef.current) == null ? void 0 : _a.focus();
1928
+ if (!inputInsidePopup) {
1929
+ event.preventDefault();
1930
+ }
1931
+ }
1932
+ if (open) {
1933
+ return;
1934
+ }
1935
+ const doc = ownerDocument(event.currentTarget);
1936
+ function handleMouseUp(mouseEvent) {
1937
+ const currentTriggerElement = store.state.triggerElement;
1938
+ if (!currentTriggerElement) {
1939
+ return;
1940
+ }
1941
+ const mouseUpTarget = getTarget(mouseEvent);
1942
+ const positioner = store.state.positionerElement;
1943
+ const list = store.state.listElement;
1944
+ if (contains(currentTriggerElement, mouseUpTarget) || contains(positioner, mouseUpTarget) || contains(list, mouseUpTarget)) {
1945
+ return;
1946
+ }
1947
+ if (isMouseWithinBounds(mouseEvent, currentTriggerElement)) {
1948
+ return;
1949
+ }
1950
+ store.context.setOpen(false, createChangeEventDetails(cancelOpen, mouseEvent));
1951
+ }
1952
+ if (inputInsidePopup) {
1953
+ doc.addEventListener("mouseup", handleMouseUp, {
1954
+ once: true
1955
+ });
1956
+ }
1957
+ },
1958
+ onKeyDown(event) {
1959
+ var _a;
1960
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
1961
+ stopEvent(event);
1962
+ store.context.setOpen(true, createChangeEventDetails(listNavigation, event.nativeEvent));
1963
+ (_a = store.context.inputRef.current) == null ? void 0 : _a.focus();
1964
+ }
1965
+ }
1966
+ }, validation.getValidationProps(disabled, elementProps), getButtonProps],
1967
+ stateAttributesMapping: triggerStateAttributesMapping
1968
+ });
1969
+ return element;
1970
+ });
1971
+ if (process.env.NODE_ENV !== "production") ComboboxTrigger$1.displayName = "ComboboxTrigger";
1972
+ const GroupCollectionContext = /* @__PURE__ */ React.createContext(null);
1973
+ if (process.env.NODE_ENV !== "production") GroupCollectionContext.displayName = "GroupCollectionContext";
1974
+ function useGroupCollectionContext() {
1975
+ return React.useContext(GroupCollectionContext);
1976
+ }
1977
+ function GroupCollectionProvider(props) {
1978
+ const {
1979
+ children,
1980
+ items
1981
+ } = props;
1982
+ const contextValue = React.useMemo(() => ({
1983
+ items
1984
+ }), [items]);
1985
+ return /* @__PURE__ */ jsx(GroupCollectionContext.Provider, {
1986
+ value: contextValue,
1987
+ children
1988
+ });
1989
+ }
1990
+ function ComboboxCollection(props) {
1991
+ const {
1992
+ children
1993
+ } = props;
1994
+ const {
1995
+ filteredItems
1996
+ } = useComboboxDerivedItemsContext();
1997
+ const groupContext = useGroupCollectionContext();
1998
+ const itemsToRender = groupContext ? groupContext.items : filteredItems;
1999
+ return /* @__PURE__ */ jsx(React.Fragment, {
2000
+ children: itemsToRender.map(children)
2001
+ });
2002
+ }
2003
+ const ComboboxList$1 = /* @__PURE__ */ React.forwardRef(function ComboboxList(componentProps, forwardedRef) {
2004
+ var _ComboboxCollection;
2005
+ const {
2006
+ render,
2007
+ className,
2008
+ style,
2009
+ children,
2010
+ ...elementProps
2011
+ } = componentProps;
2012
+ const store = useComboboxRootContext();
2013
+ const floatingRootContext = useComboboxFloatingContext();
2014
+ const hasPositionerContext = Boolean(useComboboxPositionerContext(true));
2015
+ const {
2016
+ filteredItems,
2017
+ hasItems
2018
+ } = useComboboxDerivedItemsContext();
2019
+ const selectionMode = store.useState("selectionMode");
2020
+ const grid = store.useState("grid");
2021
+ const readOnly = store.useState("readOnly");
2022
+ const listProps = store.useState("listProps");
2023
+ const virtualized = store.useState("virtualized");
2024
+ const forceMounted = store.useState("forceMounted");
2025
+ const multiple = selectionMode === "multiple";
2026
+ const empty = filteredItems.length === 0;
2027
+ const setPositionerElement = useStableCallback((element2) => {
2028
+ store.set("positionerElement", element2);
2029
+ });
2030
+ const setListElement = useStableCallback((element2) => {
2031
+ store.set("listElement", element2);
2032
+ });
2033
+ const resolvedChildren = React.useMemo(() => {
2034
+ if (typeof children === "function") {
2035
+ return _ComboboxCollection || (_ComboboxCollection = /* @__PURE__ */ jsx(ComboboxCollection, {
2036
+ children
2037
+ }));
2038
+ }
2039
+ return children;
2040
+ }, [children]);
2041
+ const state = {
2042
+ empty
2043
+ };
2044
+ const floatingId = floatingRootContext.useState("floatingId");
2045
+ const element = useRenderElement("div", componentProps, {
2046
+ state,
2047
+ ref: [forwardedRef, setListElement, hasPositionerContext ? null : setPositionerElement],
2048
+ props: [listProps, {
2049
+ children: resolvedChildren,
2050
+ tabIndex: -1,
2051
+ id: floatingId,
2052
+ role: grid ? "grid" : "listbox",
2053
+ "aria-multiselectable": multiple ? "true" : void 0,
2054
+ // On a grid the attribute describes cell editability, not selection, so it's left to the
2055
+ // combobox element in that mode.
2056
+ "aria-readonly": !grid && readOnly ? true : void 0,
2057
+ onKeyDown(event) {
2058
+ if (store.state.disabled || store.state.readOnly) {
2059
+ return;
2060
+ }
2061
+ if (event.key === "Enter") {
2062
+ const activeIndex = store.state.activeIndex;
2063
+ if (activeIndex == null) {
2064
+ return;
2065
+ }
2066
+ stopEvent(event);
2067
+ clickHighlightedItem(store, activeIndex, event.nativeEvent);
2068
+ }
2069
+ }
2070
+ }, elementProps]
2071
+ });
2072
+ if (virtualized) {
2073
+ return element;
2074
+ }
2075
+ const labelsRef = hasItems && !forceMounted ? void 0 : store.context.labelsRef;
2076
+ return /* @__PURE__ */ jsx(CompositeList, {
2077
+ elementsRef: store.context.listRef,
2078
+ labelsRef,
2079
+ children: element
2080
+ });
2081
+ });
2082
+ if (process.env.NODE_ENV !== "production") ComboboxList$1.displayName = "ComboboxList";
2083
+ const LIVE_REGION_MARKER = "⁠";
2084
+ const INITIAL_LIVE_REGION_TEXT_MUTATION_RESET_DELAY = 200;
2085
+ function findLastTextNode(root) {
2086
+ const walker = root.ownerDocument.createTreeWalker(root, NodeFilter.SHOW_TEXT);
2087
+ let lastTextNode = null;
2088
+ while (walker.nextNode()) {
2089
+ const textNode = walker.currentNode;
2090
+ if (textNode.nodeValue !== "") {
2091
+ lastTextNode = textNode;
2092
+ }
2093
+ }
2094
+ return lastTextNode;
2095
+ }
2096
+ function useInitialLiveRegionTextMutation(present = true) {
2097
+ const timeout = useTimeout();
2098
+ const rootRef = React.useRef(null);
2099
+ React.useEffect(() => {
2100
+ if (!present || ios) {
2101
+ return void 0;
2102
+ }
2103
+ const root = rootRef.current;
2104
+ if (root == null) {
2105
+ return void 0;
2106
+ }
2107
+ const textNode = findLastTextNode(root);
2108
+ if (textNode == null) {
2109
+ return void 0;
2110
+ }
2111
+ const originalValue = textNode.data;
2112
+ const markedValue = `${originalValue}${LIVE_REGION_MARKER}`;
2113
+ textNode.nodeValue = markedValue;
2114
+ timeout.start(INITIAL_LIVE_REGION_TEXT_MUTATION_RESET_DELAY, () => {
2115
+ if (textNode.nodeValue === markedValue) {
2116
+ textNode.nodeValue = originalValue;
2117
+ }
2118
+ });
2119
+ return () => {
2120
+ timeout.clear();
2121
+ if (textNode.nodeValue === markedValue) {
2122
+ textNode.nodeValue = originalValue;
2123
+ }
2124
+ };
2125
+ }, [present, rootRef, timeout]);
2126
+ return rootRef;
2127
+ }
2128
+ const ComboboxPortalContext = /* @__PURE__ */ React.createContext(void 0);
2129
+ if (process.env.NODE_ENV !== "production") ComboboxPortalContext.displayName = "ComboboxPortalContext";
2130
+ function useComboboxPortalContext() {
2131
+ const context = React.useContext(ComboboxPortalContext);
2132
+ if (context === void 0) {
2133
+ throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: <Combobox.Portal> is missing." : formatErrorMessage(20));
2134
+ }
2135
+ return context;
2136
+ }
2137
+ const ComboboxPortal = /* @__PURE__ */ React.forwardRef(function ComboboxPortal2(props, forwardedRef) {
2138
+ const {
2139
+ keepMounted = false,
2140
+ ...portalProps
2141
+ } = props;
2142
+ const store = useComboboxRootContext();
2143
+ const mounted = store.useState("mounted");
2144
+ const forceMounted = store.useState("forceMounted");
2145
+ const shouldRender = mounted || keepMounted || forceMounted;
2146
+ if (!shouldRender) {
2147
+ return null;
2148
+ }
2149
+ return /* @__PURE__ */ jsx(ComboboxPortalContext.Provider, {
2150
+ value: keepMounted,
2151
+ children: /* @__PURE__ */ jsx(FloatingPortal, {
2152
+ ref: forwardedRef,
2153
+ ...portalProps
2154
+ })
2155
+ });
2156
+ });
2157
+ if (process.env.NODE_ENV !== "production") ComboboxPortal.displayName = "ComboboxPortal";
2158
+ const ComboboxPositioner = /* @__PURE__ */ React.forwardRef(function ComboboxPositioner2(componentProps, forwardedRef) {
2159
+ const {
2160
+ render,
2161
+ className,
2162
+ anchor,
2163
+ // `useAnchorPositioning` applies the same defaults to the undefined values; the names
2164
+ // remain destructured to exclude the props from `elementProps`.
2165
+ positionMethod,
2166
+ side,
2167
+ align,
2168
+ sideOffset,
2169
+ alignOffset,
2170
+ collisionBoundary = "clipping-ancestors",
2171
+ collisionPadding,
2172
+ arrowPadding,
2173
+ sticky,
2174
+ disableAnchorTracking = false,
2175
+ collisionAvoidance = DROPDOWN_COLLISION_AVOIDANCE,
2176
+ style: styleProp,
2177
+ ...elementProps
2178
+ } = componentProps;
2179
+ const store = useComboboxRootContext();
2180
+ const floatingRootContext = useComboboxFloatingContext();
2181
+ const keepMounted = useComboboxPortalContext();
2182
+ const modal = store.useState("modal");
2183
+ const open = store.useState("open");
2184
+ const mounted = store.useState("mounted");
2185
+ const openMethod = store.useState("openMethod");
2186
+ const positionerElement = store.useState("positionerElement");
2187
+ const triggerElement = store.useState("triggerElement");
2188
+ const inputElement = store.useState("inputElement");
2189
+ const inputGroupElement = store.useState("inputGroupElement");
2190
+ const inputInsidePopup = store.useState("inputInsidePopup");
2191
+ const transitionStatus = store.useState("transitionStatus");
2192
+ const empty = useListEmpty();
2193
+ const resolvedAnchor = anchor ?? (inputInsidePopup ? triggerElement : inputGroupElement ?? inputElement);
2194
+ const positioning = useAnchorPositioning({
2195
+ anchor: resolvedAnchor,
2196
+ floatingRootContext,
2197
+ positionMethod,
2198
+ mounted,
2199
+ side,
2200
+ sideOffset,
2201
+ align,
2202
+ alignOffset,
2203
+ arrowPadding,
2204
+ collisionBoundary,
2205
+ collisionPadding,
2206
+ sticky,
2207
+ disableAnchorTracking,
2208
+ keepMounted,
2209
+ collisionAvoidance,
2210
+ lazyFlip: true
2211
+ });
2212
+ useAnchoredPopupScrollLock(open && modal, openMethod === "touch", positionerElement, triggerElement);
2213
+ const state = {
2214
+ open,
2215
+ side: positioning.side,
2216
+ align: positioning.align,
2217
+ anchorHidden: positioning.anchorHidden,
2218
+ empty
2219
+ };
2220
+ useIsoLayoutEffect(() => {
2221
+ store.set("popupSide", positioning.side);
2222
+ }, [store, positioning.side]);
2223
+ const setPositionerElement = useStableCallback((element2) => {
2224
+ store.set("positionerElement", element2);
2225
+ });
2226
+ const element = usePositioner(componentProps, state, {
2227
+ styles: positioning.positionerStyles,
2228
+ transitionStatus,
2229
+ props: elementProps,
2230
+ refs: [forwardedRef, setPositionerElement],
2231
+ hidden: !mounted,
2232
+ inert: !open
2233
+ });
2234
+ return /* @__PURE__ */ jsxs(ComboboxPositionerContext.Provider, {
2235
+ value: positioning,
2236
+ children: [mounted && modal && /* @__PURE__ */ jsx(InternalBackdrop, {
2237
+ inert: inertValue(!open),
2238
+ cutout: inputGroupElement ?? inputElement ?? triggerElement
2239
+ }), element]
2240
+ });
2241
+ });
2242
+ if (process.env.NODE_ENV !== "production") ComboboxPositioner.displayName = "ComboboxPositioner";
2243
+ const stateAttributesMapping$1 = {
2244
+ ...popupStateMapping,
2245
+ ...transitionStatusMapping
2246
+ };
2247
+ const ComboboxPopup = /* @__PURE__ */ React.forwardRef(function ComboboxPopup2(componentProps, forwardedRef) {
2248
+ const {
2249
+ render,
2250
+ className,
2251
+ style,
2252
+ initialFocus,
2253
+ finalFocus,
2254
+ ...elementProps
2255
+ } = componentProps;
2256
+ const store = useComboboxRootContext();
2257
+ const positioning = useComboboxPositionerContext();
2258
+ const floatingRootContext = useComboboxFloatingContext();
2259
+ const mounted = store.useState("mounted");
2260
+ const open = store.useState("open");
2261
+ const openMethod = store.useState("openMethod");
2262
+ const popupProps = store.useState("popupProps");
2263
+ const transitionStatus = store.useState("transitionStatus");
2264
+ const inputInsidePopup = store.useState("inputInsidePopup");
2265
+ const inputElement = store.useState("inputElement");
2266
+ const modal = store.useState("modal");
2267
+ const rootId = store.useState("id");
2268
+ const empty = useListEmpty();
2269
+ const popupId = elementProps.id ?? (inputInsidePopup ? getComboboxPopupId(rootId) : void 0);
2270
+ useIsoLayoutEffect(() => {
2271
+ var _a;
2272
+ store.set("popupId", ((_a = store.context.popupRef.current) == null ? void 0 : _a.id) || popupId);
2273
+ return () => {
2274
+ store.set("popupId", void 0);
2275
+ };
2276
+ }, [store, popupId]);
2277
+ useOpenChangeComplete({
2278
+ open,
2279
+ ref: store.context.popupRef,
2280
+ onComplete() {
2281
+ if (open) {
2282
+ store.context.onOpenChangeComplete(true);
2283
+ }
2284
+ }
2285
+ });
2286
+ const state = {
2287
+ open,
2288
+ side: positioning.side,
2289
+ align: positioning.align,
2290
+ anchorHidden: positioning.anchorHidden,
2291
+ transitionStatus,
2292
+ empty
2293
+ };
2294
+ const element = useRenderElement("div", componentProps, {
2295
+ state,
2296
+ ref: [forwardedRef, store.context.popupRef],
2297
+ props: [popupProps, {
2298
+ id: popupId,
2299
+ role: inputInsidePopup ? "dialog" : "presentation",
2300
+ onFocus(event) {
2301
+ var _a;
2302
+ const target = getTarget(event.nativeEvent);
2303
+ if (openMethod !== "touch" && (contains(store.state.listElement, target) || target === event.currentTarget)) {
2304
+ (_a = store.context.inputRef.current) == null ? void 0 : _a.focus();
2305
+ }
2306
+ }
2307
+ }, getDisabledMountTransitionStyles(transitionStatus), elementProps],
2308
+ stateAttributesMapping: stateAttributesMapping$1
2309
+ });
2310
+ const computedDefaultInitialFocus = inputInsidePopup ? (interactionType) => interactionType === "touch" ? store.context.popupRef.current : inputElement : false;
2311
+ const resolvedInitialFocus = initialFocus === void 0 ? computedDefaultInitialFocus : initialFocus;
2312
+ let resolvedFinalFocus;
2313
+ if (finalFocus != null) {
2314
+ resolvedFinalFocus = finalFocus;
2315
+ } else {
2316
+ resolvedFinalFocus = inputInsidePopup ? void 0 : false;
2317
+ }
2318
+ const focusManagerModal = !inputInsidePopup || modal;
2319
+ return /* @__PURE__ */ jsx(FloatingFocusManager, {
2320
+ context: floatingRootContext,
2321
+ disabled: !mounted,
2322
+ modal: focusManagerModal,
2323
+ openInteractionType: openMethod,
2324
+ initialFocus: resolvedInitialFocus,
2325
+ returnFocus: resolvedFinalFocus,
2326
+ getInsideElements: () => [store.context.startDismissRef.current, store.context.endDismissRef.current],
2327
+ children: /* @__PURE__ */ jsxs(React.Fragment, {
2328
+ children: [element, focusManagerModal && /* @__PURE__ */ jsx(ComboboxInternalDismissButton, {
2329
+ ref: store.context.endDismissRef
2330
+ })]
2331
+ })
2332
+ });
2333
+ });
2334
+ if (process.env.NODE_ENV !== "production") ComboboxPopup.displayName = "ComboboxPopup";
2335
+ const ComboboxGroupContext = /* @__PURE__ */ React.createContext(void 0);
2336
+ if (process.env.NODE_ENV !== "production") ComboboxGroupContext.displayName = "ComboboxGroupContext";
2337
+ function useComboboxGroupContext() {
2338
+ const context = React.useContext(ComboboxGroupContext);
2339
+ if (context === void 0) {
2340
+ throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: ComboboxGroupContext is missing. ComboboxGroup parts must be placed within <Combobox.Group>." : formatErrorMessage(18));
2341
+ }
2342
+ return context;
2343
+ }
2344
+ const ComboboxGroup$1 = /* @__PURE__ */ React.forwardRef(function ComboboxGroup(componentProps, forwardedRef) {
2345
+ const {
2346
+ render,
2347
+ className,
2348
+ style,
2349
+ items,
2350
+ ...elementProps
2351
+ } = componentProps;
2352
+ const store = useComboboxRootContext();
2353
+ const grid = store.useState("grid");
2354
+ const [labelId, setLabelId] = React.useState();
2355
+ const contextValue = React.useMemo(() => ({
2356
+ labelId,
2357
+ setLabelId,
2358
+ items
2359
+ }), [labelId, setLabelId, items]);
2360
+ const element = useRenderElement("div", componentProps, {
2361
+ ref: forwardedRef,
2362
+ props: [{
2363
+ // `group` is not a valid owned element of `grid`, and `row` must be owned
2364
+ // by `grid`, `rowgroup`, or `treegrid`.
2365
+ role: grid ? "rowgroup" : "group",
2366
+ "aria-labelledby": labelId
2367
+ }, elementProps]
2368
+ });
2369
+ const wrappedElement = /* @__PURE__ */ jsx(ComboboxGroupContext.Provider, {
2370
+ value: contextValue,
2371
+ children: element
2372
+ });
2373
+ if (items) {
2374
+ return /* @__PURE__ */ jsx(GroupCollectionProvider, {
2375
+ items,
2376
+ children: wrappedElement
2377
+ });
2378
+ }
2379
+ return wrappedElement;
2380
+ });
2381
+ if (process.env.NODE_ENV !== "production") ComboboxGroup$1.displayName = "ComboboxGroup";
2382
+ const ComboboxGroupLabel = /* @__PURE__ */ React.forwardRef(function ComboboxGroupLabel2(componentProps, forwardedRef) {
2383
+ const {
2384
+ render,
2385
+ className,
2386
+ style,
2387
+ id: idProp,
2388
+ ...elementProps
2389
+ } = componentProps;
2390
+ const {
2391
+ setLabelId
2392
+ } = useComboboxGroupContext();
2393
+ const id = useBaseUiId(idProp);
2394
+ useIsoLayoutEffect(() => {
2395
+ setLabelId(id);
2396
+ return () => {
2397
+ setLabelId((currentId) => currentId === id ? void 0 : currentId);
2398
+ };
2399
+ }, [id, setLabelId]);
2400
+ const element = useRenderElement("div", componentProps, {
2401
+ ref: forwardedRef,
2402
+ props: [{
2403
+ id,
2404
+ "aria-hidden": true
2405
+ }, elementProps]
2406
+ });
2407
+ return element;
2408
+ });
2409
+ if (process.env.NODE_ENV !== "production") ComboboxGroupLabel.displayName = "ComboboxGroupLabel";
2410
+ const ComboboxItemContext = /* @__PURE__ */ React.createContext(void 0);
2411
+ if (process.env.NODE_ENV !== "production") ComboboxItemContext.displayName = "ComboboxItemContext";
2412
+ function useComboboxItemContext() {
2413
+ const context = React.useContext(ComboboxItemContext);
2414
+ if (!context) {
2415
+ throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: ComboboxItemContext is missing. ComboboxItem parts must be placed within <Combobox.Item>." : formatErrorMessage(19));
2416
+ }
2417
+ return context;
2418
+ }
2419
+ const ComboboxRowContext = /* @__PURE__ */ React.createContext(false);
2420
+ if (process.env.NODE_ENV !== "production") ComboboxRowContext.displayName = "ComboboxRowContext";
2421
+ function useComboboxRowContext() {
2422
+ return React.useContext(ComboboxRowContext);
2423
+ }
2424
+ function ComboboxItemInner(props) {
2425
+ const {
2426
+ componentProps,
2427
+ forwardedRef,
2428
+ virtualized,
2429
+ indexFromFilter
2430
+ } = props;
2431
+ const {
2432
+ render,
2433
+ className,
2434
+ style,
2435
+ value: itemValue = null,
2436
+ index: indexProp,
2437
+ disabled: disabledProp = false,
2438
+ nativeButton = false,
2439
+ ...elementProps
2440
+ } = componentProps;
2441
+ const textRef = React.useRef(null);
2442
+ const listItem = useCompositeListItem({
2443
+ guess: true,
2444
+ index: indexProp,
2445
+ textRef
2446
+ });
2447
+ const store = useComboboxRootContext();
2448
+ const isRow = useComboboxRowContext();
2449
+ const hasItems = useComboboxHasItemsContext();
2450
+ const {
2451
+ props: itemProps,
2452
+ id: rootId,
2453
+ selectionMode,
2454
+ disabled: rootDisabled,
2455
+ readOnly,
2456
+ isItemEqualToValue
2457
+ } = store.useState("itemRoot");
2458
+ const disabled = rootDisabled || disabledProp;
2459
+ const selectable = selectionMode !== "none";
2460
+ const index = indexProp ?? indexFromFilter ?? listItem.index;
2461
+ const hasRegistered = index !== -1;
2462
+ const highlighted = store.useState("isActive", index);
2463
+ const matchesSelectedValue = store.useState("isSelected", itemValue);
2464
+ const itemRef = React.useRef(null);
2465
+ const id = rootId != null && hasRegistered ? `${rootId}-${index}` : void 0;
2466
+ const selected = matchesSelectedValue && selectable;
2467
+ useIsoLayoutEffect(() => {
2468
+ const shouldRun = hasRegistered && (virtualized || indexProp != null);
2469
+ if (!shouldRun) {
2470
+ return void 0;
2471
+ }
2472
+ const list = store.context.listRef.current;
2473
+ list[index] = itemRef.current;
2474
+ return () => {
2475
+ delete list[index];
2476
+ };
2477
+ }, [hasRegistered, virtualized, index, indexProp, store]);
2478
+ useIsoLayoutEffect(() => {
2479
+ if (!hasRegistered || hasItems) {
2480
+ return void 0;
2481
+ }
2482
+ const visibleValues = store.context.valuesRef.current;
2483
+ visibleValues[index] = itemValue;
2484
+ return () => {
2485
+ delete visibleValues[index];
2486
+ };
2487
+ }, [hasRegistered, hasItems, index, itemValue, store]);
2488
+ useIsoLayoutEffect(() => {
2489
+ if (!hasRegistered || hasItems) {
2490
+ return;
2491
+ }
2492
+ const selectedValue = store.state.selectedValue;
2493
+ let nextIndex = store.state.selectedIndex;
2494
+ if (store.state.selectionMode === "multiple" && Array.isArray(selectedValue)) {
2495
+ nextIndex = resolveSelectedIndex(index, itemValue, store.context.valuesRef.current, selectedValue, isItemEqualToValue, nextIndex);
2496
+ } else if (compareItemEquality(itemValue, selectedValue, isItemEqualToValue)) {
2497
+ nextIndex = index;
2498
+ }
2499
+ store.set("selectedIndex", nextIndex);
2500
+ }, [hasRegistered, hasItems, store, index, itemValue, isItemEqualToValue]);
2501
+ const {
2502
+ getButtonProps,
2503
+ buttonRef
2504
+ } = useButton({
2505
+ disabled,
2506
+ focusableWhenDisabled: true,
2507
+ native: nativeButton,
2508
+ composite: true
2509
+ });
2510
+ const state = {
2511
+ disabled,
2512
+ selected,
2513
+ highlighted
2514
+ };
2515
+ function commitSelection(nativeEvent) {
2516
+ function selectItem() {
2517
+ store.context.handleSelection(nativeEvent, itemValue);
2518
+ }
2519
+ if (store.state.submitOnItemClick) {
2520
+ ReactDOM.flushSync(selectItem);
2521
+ store.context.requestSubmit();
2522
+ } else {
2523
+ selectItem();
2524
+ }
2525
+ }
2526
+ const defaultProps = {
2527
+ id,
2528
+ role: isRow ? "gridcell" : "option",
2529
+ "aria-selected": selectable ? selected : void 0,
2530
+ // Focusable items steal focus from the input upon mouseup.
2531
+ // Warn if the user renders a natively focusable element like `<button>`,
2532
+ // as it should be a `<div>` instead.
2533
+ tabIndex: void 0,
2534
+ onPointerDownCapture(event) {
2535
+ if (event.isPrimary) {
2536
+ store.context.pointerDownItemRef.current = event.currentTarget;
2537
+ }
2538
+ event.preventDefault();
2539
+ },
2540
+ onMouseDown(event) {
2541
+ event.preventDefault();
2542
+ },
2543
+ onClick(event) {
2544
+ if (disabled || readOnly) {
2545
+ return;
2546
+ }
2547
+ commitSelection(event.nativeEvent);
2548
+ },
2549
+ onMouseUp(event) {
2550
+ const pointerStartedOnItem = store.context.pointerDownItemRef.current === event.currentTarget;
2551
+ store.context.pointerDownItemRef.current = null;
2552
+ if (disabled || readOnly || event.button !== 0 || pointerStartedOnItem || !highlighted) {
2553
+ return;
2554
+ }
2555
+ commitSelection(event.nativeEvent);
2556
+ }
2557
+ };
2558
+ const element = useRenderElement("div", componentProps, {
2559
+ ref: [buttonRef, forwardedRef, listItem.ref, itemRef],
2560
+ state,
2561
+ props: [itemProps, defaultProps, elementProps, getButtonProps]
2562
+ });
2563
+ const contextValue = React.useMemo(() => ({
2564
+ selected,
2565
+ textRef
2566
+ }), [selected, textRef]);
2567
+ return /* @__PURE__ */ jsx(ComboboxItemContext.Provider, {
2568
+ value: contextValue,
2569
+ children: element
2570
+ });
2571
+ }
2572
+ function ComboboxItemVirtualizedIndex(props) {
2573
+ const {
2574
+ componentProps,
2575
+ forwardedRef
2576
+ } = props;
2577
+ const store = useComboboxRootContext();
2578
+ const isItemEqualToValue = store.useState("isItemEqualToValue");
2579
+ const {
2580
+ flatFilteredValues
2581
+ } = useComboboxDerivedItemsContext();
2582
+ const lookupValue = componentProps.value ?? null;
2583
+ const indexFromFilter = findItemIndex(flatFilteredValues, lookupValue, isItemEqualToValue);
2584
+ return /* @__PURE__ */ jsx(ComboboxItemInner, {
2585
+ componentProps,
2586
+ forwardedRef,
2587
+ virtualized: true,
2588
+ indexFromFilter
2589
+ });
2590
+ }
2591
+ const ComboboxItem$1 = /* @__PURE__ */ React.memo(/* @__PURE__ */ React.forwardRef(function ComboboxItem(componentProps, forwardedRef) {
2592
+ const store = useComboboxRootContext();
2593
+ const virtualized = store.useState("virtualized");
2594
+ if (virtualized && componentProps.index == null) {
2595
+ return /* @__PURE__ */ jsx(ComboboxItemVirtualizedIndex, {
2596
+ componentProps,
2597
+ forwardedRef
2598
+ });
2599
+ }
2600
+ return /* @__PURE__ */ jsx(ComboboxItemInner, {
2601
+ componentProps,
2602
+ forwardedRef,
2603
+ virtualized,
2604
+ indexFromFilter: void 0
2605
+ });
2606
+ }));
2607
+ if (process.env.NODE_ENV !== "production") ComboboxItem$1.displayName = "ComboboxItem";
2608
+ const ComboboxItemIndicator = /* @__PURE__ */ React.forwardRef(function ComboboxItemIndicator2(componentProps, forwardedRef) {
2609
+ const {
2610
+ selected
2611
+ } = useComboboxItemContext();
2612
+ const shouldRender = componentProps.keepMounted || selected;
2613
+ if (!shouldRender) {
2614
+ return null;
2615
+ }
2616
+ return /* @__PURE__ */ jsx(ItemIndicator, {
2617
+ ...componentProps,
2618
+ selected,
2619
+ ref: forwardedRef
2620
+ });
2621
+ });
2622
+ if (process.env.NODE_ENV !== "production") ComboboxItemIndicator.displayName = "ComboboxItemIndicator";
2623
+ const ComboboxChips$1 = /* @__PURE__ */ React.forwardRef(function ComboboxChips(componentProps, forwardedRef) {
2624
+ const {
2625
+ render,
2626
+ className,
2627
+ style,
2628
+ ...elementProps
2629
+ } = componentProps;
2630
+ const store = useComboboxRootContext();
2631
+ const hasSelectionChips = store.useState("hasSelectionChips");
2632
+ const chipsRef = React.useRef([]);
2633
+ const element = useRenderElement("div", componentProps, {
2634
+ ref: [forwardedRef, store.context.chipsContainerRef],
2635
+ // NVDA enters browse mode instead of staying in focus mode when navigating with
2636
+ // arrow keys inside a container unless it has a toolbar role.
2637
+ props: [hasSelectionChips ? {
2638
+ role: "toolbar"
2639
+ } : EMPTY_OBJECT, {
2640
+ onMouseDown(event) {
2641
+ handleInputPress(event, store, store.state.disabled);
2642
+ }
2643
+ }, elementProps]
2644
+ });
2645
+ const contextValue = React.useMemo(() => ({
2646
+ chipsRef
2647
+ }), []);
2648
+ return /* @__PURE__ */ jsx(ComboboxChipsContext.Provider, {
2649
+ value: contextValue,
2650
+ children: /* @__PURE__ */ jsx(CompositeList, {
2651
+ elementsRef: chipsRef,
2652
+ children: element
2653
+ })
2654
+ });
2655
+ });
2656
+ if (process.env.NODE_ENV !== "production") ComboboxChips$1.displayName = "ComboboxChips";
2657
+ const ComboboxChipContext = /* @__PURE__ */ React.createContext(void 0);
2658
+ if (process.env.NODE_ENV !== "production") ComboboxChipContext.displayName = "ComboboxChipContext";
2659
+ function useComboboxChipContext() {
2660
+ const context = React.useContext(ComboboxChipContext);
2661
+ if (!context) {
2662
+ throw new Error(process.env.NODE_ENV !== "production" ? "Base UI: ComboboxChipContext is missing. ComboboxChip parts must be placed within <Combobox.Chip>." : formatErrorMessage(17));
2663
+ }
2664
+ return context;
2665
+ }
2666
+ const ComboboxChip$1 = /* @__PURE__ */ React.forwardRef(function ComboboxChip(componentProps, forwardedRef) {
2667
+ const {
2668
+ render,
2669
+ className,
2670
+ style,
2671
+ ...elementProps
2672
+ } = componentProps;
2673
+ const store = useComboboxRootContext();
2674
+ const {
2675
+ chipsRef
2676
+ } = useComboboxChipsContext();
2677
+ const direction = useDirection();
2678
+ const disabled = store.useState("disabled");
2679
+ const readOnly = store.useState("readOnly");
2680
+ const selectedValue = store.useState("selectedValue");
2681
+ const {
2682
+ ref,
2683
+ index
2684
+ } = useCompositeListItem();
2685
+ function handleKeyDown(event) {
2686
+ let nextIndex = index;
2687
+ const [previousChipKey, nextChipKey] = getChipNavigationKeys(direction);
2688
+ if (event.key === previousChipKey) {
2689
+ event.preventDefault();
2690
+ if (index > 0) {
2691
+ nextIndex = index - 1;
2692
+ } else {
2693
+ nextIndex = void 0;
2694
+ }
2695
+ } else if (event.key === nextChipKey) {
2696
+ event.preventDefault();
2697
+ if (index < chipsRef.current.length - 1) {
2698
+ nextIndex = index + 1;
2699
+ } else {
2700
+ nextIndex = void 0;
2701
+ }
2702
+ } else if (event.key === "Backspace" || event.key === "Delete") {
2703
+ nextIndex = getIndexAfterChipRemoval(index, selectedValue.length);
2704
+ stopEvent(event);
2705
+ ReactDOM.flushSync(() => {
2706
+ store.context.setIndices({
2707
+ activeIndex: null,
2708
+ selectedIndex: null,
2709
+ type: keyboard,
2710
+ event: event.nativeEvent
2711
+ });
2712
+ store.context.setSelectedValue(selectedValue.filter((_, i) => i !== index), createChangeEventDetails(none, event.nativeEvent));
2713
+ });
2714
+ } else if (event.key === "Enter" || event.key === " ") {
2715
+ stopEvent(event);
2716
+ nextIndex = void 0;
2717
+ } else if (event.key === "ArrowDown" || event.key === "ArrowUp") {
2718
+ stopEvent(event);
2719
+ ReactDOM.flushSync(() => {
2720
+ store.context.setOpen(true, createChangeEventDetails(listNavigation, event.nativeEvent));
2721
+ });
2722
+ nextIndex = void 0;
2723
+ } else if (
2724
+ // Check for printable characters (letters, numbers, symbols)
2725
+ event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey
2726
+ ) {
2727
+ nextIndex = void 0;
2728
+ }
2729
+ return nextIndex;
2730
+ }
2731
+ const state = {
2732
+ disabled
2733
+ };
2734
+ const element = useRenderElement("div", componentProps, {
2735
+ ref: [forwardedRef, ref],
2736
+ state,
2737
+ props: [{
2738
+ tabIndex: -1,
2739
+ "aria-disabled": disabled || void 0,
2740
+ "aria-readonly": readOnly || void 0,
2741
+ onKeyDown(event) {
2742
+ var _a, _b;
2743
+ if (disabled || readOnly) {
2744
+ return;
2745
+ }
2746
+ const nextIndex = handleKeyDown(event);
2747
+ if (nextIndex === void 0) {
2748
+ (_a = store.context.inputRef.current) == null ? void 0 : _a.focus();
2749
+ } else {
2750
+ (_b = chipsRef.current[nextIndex]) == null ? void 0 : _b.focus();
2751
+ }
2752
+ }
2753
+ }, elementProps]
2754
+ });
2755
+ const contextValue = React.useMemo(() => ({
2756
+ index
2757
+ }), [index]);
2758
+ return /* @__PURE__ */ jsx(ComboboxChipContext.Provider, {
2759
+ value: contextValue,
2760
+ children: element
2761
+ });
2762
+ });
2763
+ if (process.env.NODE_ENV !== "production") ComboboxChip$1.displayName = "ComboboxChip";
2764
+ const ComboboxChipRemove = /* @__PURE__ */ React.forwardRef(function ComboboxChipRemove2(componentProps, forwardedRef) {
2765
+ const {
2766
+ render,
2767
+ className,
2768
+ disabled: disabledProp = false,
2769
+ nativeButton = true,
2770
+ style,
2771
+ ...elementProps
2772
+ } = componentProps;
2773
+ const store = useComboboxRootContext();
2774
+ const {
2775
+ index
2776
+ } = useComboboxChipContext();
2777
+ const comboboxDisabled = store.useState("disabled");
2778
+ const readOnly = store.useState("readOnly");
2779
+ const selectedValue = store.useState("selectedValue");
2780
+ const isItemEqualToValue = store.useState("isItemEqualToValue");
2781
+ const disabled = comboboxDisabled || disabledProp;
2782
+ const {
2783
+ buttonRef,
2784
+ getButtonProps
2785
+ } = useButton({
2786
+ native: nativeButton,
2787
+ disabled: disabled || readOnly,
2788
+ focusableWhenDisabled: true
2789
+ });
2790
+ const state = {
2791
+ disabled
2792
+ };
2793
+ function clearActiveIndexForRemovedItem(removedItem, event) {
2794
+ const activeIndex = store.state.activeIndex;
2795
+ if (activeIndex == null) {
2796
+ return;
2797
+ }
2798
+ const removedIndex = findItemIndex(store.context.valuesRef.current, removedItem, isItemEqualToValue);
2799
+ if (removedIndex !== -1 && activeIndex === removedIndex) {
2800
+ store.context.setIndices({
2801
+ activeIndex: null,
2802
+ type: getHighlightReason(event),
2803
+ event
2804
+ });
2805
+ }
2806
+ }
2807
+ function removeChip(event) {
2808
+ var _a;
2809
+ const eventDetails = createChangeEventDetails(chipRemovePress, event.nativeEvent);
2810
+ const removedItem = selectedValue[index];
2811
+ clearActiveIndexForRemovedItem(removedItem, event.nativeEvent);
2812
+ store.context.setSelectedValue(selectedValue.filter((_, i) => i !== index), eventDetails);
2813
+ (_a = store.context.inputRef.current) == null ? void 0 : _a.focus();
2814
+ return eventDetails;
2815
+ }
2816
+ const element = useRenderElement("button", componentProps, {
2817
+ ref: [forwardedRef, buttonRef],
2818
+ state,
2819
+ props: [{
2820
+ tabIndex: -1,
2821
+ onMouseDown(event) {
2822
+ event.preventDefault();
2823
+ },
2824
+ onClick(event) {
2825
+ const eventDetails = removeChip(event);
2826
+ if (!eventDetails.isPropagationAllowed) {
2827
+ event.stopPropagation();
2828
+ }
2829
+ },
2830
+ onKeyDown(event) {
2831
+ if (event.key === "Enter" || event.key === " ") {
2832
+ const eventDetails = removeChip(event);
2833
+ if (!eventDetails.isPropagationAllowed) {
2834
+ stopEvent(event);
2835
+ }
2836
+ }
2837
+ }
2838
+ }, elementProps, getButtonProps]
2839
+ });
2840
+ return element;
2841
+ });
2842
+ if (process.env.NODE_ENV !== "production") ComboboxChipRemove.displayName = "ComboboxChipRemove";
2843
+ const ComboboxEmpty$1 = /* @__PURE__ */ React.forwardRef(function ComboboxEmpty(componentProps, forwardedRef) {
2844
+ const {
2845
+ render,
2846
+ className,
2847
+ style,
2848
+ children: childrenProp,
2849
+ ...elementProps
2850
+ } = componentProps;
2851
+ const {
2852
+ filteredItems
2853
+ } = useComboboxDerivedItemsContext();
2854
+ const store = useComboboxRootContext();
2855
+ const emptyRef = useInitialLiveRegionTextMutation();
2856
+ const children = filteredItems.length === 0 ? childrenProp : null;
2857
+ return useRenderElement("div", componentProps, {
2858
+ ref: [forwardedRef, store.context.emptyRef, emptyRef],
2859
+ props: [{
2860
+ children,
2861
+ role: "status",
2862
+ "aria-live": "polite",
2863
+ "aria-atomic": true
2864
+ }, elementProps]
2865
+ });
2866
+ });
2867
+ if (process.env.NODE_ENV !== "production") ComboboxEmpty$1.displayName = "ComboboxEmpty";
2868
+ const stateAttributesMapping = {
2869
+ ...transitionStatusMapping,
2870
+ ...triggerOpenStateMapping
2871
+ };
2872
+ const ComboboxClear = /* @__PURE__ */ React.forwardRef(function ComboboxClear2(componentProps, forwardedRef) {
2873
+ const {
2874
+ render,
2875
+ className,
2876
+ disabled: disabledProp = false,
2877
+ nativeButton = true,
2878
+ keepMounted = false,
2879
+ style,
2880
+ ...elementProps
2881
+ } = componentProps;
2882
+ const {
2883
+ disabled: fieldDisabled
2884
+ } = useFieldRootContext();
2885
+ const store = useComboboxRootContext();
2886
+ const selectionMode = store.useState("selectionMode");
2887
+ const comboboxDisabled = store.useState("disabled");
2888
+ const readOnly = store.useState("readOnly");
2889
+ const open = store.useState("open");
2890
+ const selectedValue = store.useState("selectedValue");
2891
+ const hasSelectionChips = store.useState("hasSelectionChips");
2892
+ const inputValue = useComboboxInputValueContext();
2893
+ let visible = false;
2894
+ if (selectionMode === "none") {
2895
+ visible = inputValue !== "";
2896
+ } else if (selectionMode === "single") {
2897
+ visible = selectedValue != null;
2898
+ } else {
2899
+ visible = hasSelectionChips;
2900
+ }
2901
+ const disabled = fieldDisabled || comboboxDisabled || disabledProp;
2902
+ const {
2903
+ buttonRef,
2904
+ getButtonProps
2905
+ } = useButton({
2906
+ native: nativeButton,
2907
+ disabled
2908
+ });
2909
+ const {
2910
+ mounted,
2911
+ transitionStatus,
2912
+ setMounted
2913
+ } = useTransitionStatus(visible);
2914
+ const state = {
2915
+ disabled,
2916
+ visible,
2917
+ open,
2918
+ transitionStatus
2919
+ };
2920
+ useOpenChangeComplete({
2921
+ open: visible,
2922
+ ref: store.context.clearRef,
2923
+ onComplete() {
2924
+ if (!visible) {
2925
+ setMounted(false);
2926
+ }
2927
+ }
2928
+ });
2929
+ const element = useRenderElement("button", componentProps, {
2930
+ state,
2931
+ ref: [forwardedRef, buttonRef, store.context.clearRef],
2932
+ props: [{
2933
+ tabIndex: -1,
2934
+ children: "x",
2935
+ // Avoid stealing focus from the input.
2936
+ onMouseDown(event) {
2937
+ event.preventDefault();
2938
+ },
2939
+ onClick(event) {
2940
+ var _a;
2941
+ if (disabled || readOnly) {
2942
+ return;
2943
+ }
2944
+ const type = getHighlightReason(event);
2945
+ store.context.setInputValue("", createChangeEventDetails(clearPress, event.nativeEvent));
2946
+ if (selectionMode !== "none") {
2947
+ store.context.setSelectedValue(Array.isArray(selectedValue) ? [] : null, createChangeEventDetails(clearPress, event.nativeEvent));
2948
+ store.context.setIndices({
2949
+ activeIndex: null,
2950
+ selectedIndex: null,
2951
+ type,
2952
+ event: event.nativeEvent
2953
+ });
2954
+ } else {
2955
+ store.context.setIndices({
2956
+ activeIndex: null,
2957
+ type,
2958
+ event: event.nativeEvent
2959
+ });
2960
+ }
2961
+ (_a = store.context.inputRef.current) == null ? void 0 : _a.focus();
2962
+ }
2963
+ }, elementProps, getButtonProps],
2964
+ stateAttributesMapping
2965
+ });
2966
+ const shouldRender = keepMounted || mounted;
2967
+ if (!shouldRender) {
2968
+ return null;
2969
+ }
2970
+ return element;
2971
+ });
2972
+ if (process.env.NODE_ENV !== "production") ComboboxClear.displayName = "ComboboxClear";
2973
+ const ComboboxSeparator$1 = ListboxSeparator;
2974
+ const Combobox = ComboboxRoot;
2975
+ function ComboboxInput2({
2976
+ attached,
2977
+ className,
2978
+ clearLabel = "Clear",
2979
+ invalid,
2980
+ showClear = false,
2981
+ variant,
2982
+ wrapperClassName,
2983
+ ...props
2984
+ }) {
2985
+ const isInvalid = invalid ?? false;
2986
+ return /* @__PURE__ */ jsxs(
2987
+ ComboboxInputGroup,
2988
+ {
2989
+ "data-slot": "combobox-input-group",
2990
+ className: classNames(
2991
+ selectTriggerVariants({ invalid: isInvalid, variant }),
2992
+ selectAttachedClass(attached),
2993
+ "w-80 max-w-full has-[[data-disabled]]:opacity-50",
2994
+ "focus-within:outline-2 focus-within:outline-offset-2 focus-within:outline-border-focus",
2995
+ wrapperClassName
2996
+ ),
2997
+ children: [
2998
+ /* @__PURE__ */ jsx(IconProvider, { icon: "magnifying-glass", size: "16", className: "shrink-0 text-icon-secondary" }),
2999
+ /* @__PURE__ */ jsx(
3000
+ ComboboxInput$1,
3001
+ {
3002
+ "data-slot": "combobox-input",
3003
+ "aria-invalid": isInvalid || void 0,
3004
+ className: classNames(
3005
+ "h-full min-w-0 flex-1 bg-transparent text-text-primary outline-none placeholder:text-text-placeholder disabled:cursor-not-allowed",
3006
+ className
3007
+ ),
3008
+ ...props
3009
+ }
3010
+ ),
3011
+ isInvalid ? /* @__PURE__ */ jsx(IconProvider, { icon: "triangle-exclamation", size: "16", className: "text-status-text-error" }) : null,
3012
+ showClear ? /* @__PURE__ */ jsxs(Fragment, { children: [
3013
+ /* @__PURE__ */ jsx(
3014
+ ComboboxClear,
3015
+ {
3016
+ "data-slot": "combobox-clear",
3017
+ "aria-label": clearLabel,
3018
+ className: "flex size-4 shrink-0 items-center justify-center rounded-sm text-icon-primary focus-ring",
3019
+ children: /* @__PURE__ */ jsx(IconProvider, { icon: "xmark", size: "12" })
3020
+ }
3021
+ ),
3022
+ /* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "h-4 w-px shrink-0 bg-border-subtle" })
3023
+ ] }) : null,
3024
+ /* @__PURE__ */ jsx(
3025
+ ComboboxTrigger$1,
3026
+ {
3027
+ "data-slot": "combobox-trigger",
3028
+ "aria-label": "Open",
3029
+ className: "flex size-4 shrink-0 items-center justify-center rounded-sm text-icon-secondary focus-ring",
3030
+ children: /* @__PURE__ */ jsx(IconProvider, { icon: "chevron-down", size: "16", className: "transition-transform in-data-popup-open:rotate-180" })
3031
+ }
3032
+ )
3033
+ ]
3034
+ }
3035
+ );
3036
+ }
3037
+ function ComboboxTrigger2({
3038
+ attached,
3039
+ className,
3040
+ clearLabel = "Clear selection",
3041
+ disabled = false,
3042
+ invalid,
3043
+ onClear,
3044
+ showClear = false,
3045
+ variant,
3046
+ wrapperClassName,
3047
+ ...props
3048
+ }) {
3049
+ const isInvalid = invalid ?? false;
3050
+ const padding = isInvalid ? showClear ? trailingPadding.invalidClear : trailingPadding.invalid : showClear ? trailingPadding.clear : trailingPadding.plain;
3051
+ return /* @__PURE__ */ jsxs(
3052
+ "div",
3053
+ {
3054
+ "data-slot": "combobox-trigger-wrapper",
3055
+ className: classNames("group/select relative w-80 max-w-full has-[[data-disabled]]:opacity-50", wrapperClassName),
3056
+ children: [
3057
+ /* @__PURE__ */ jsx(
3058
+ ComboboxTrigger$1,
3059
+ {
3060
+ "data-slot": "combobox-trigger",
3061
+ "aria-invalid": isInvalid || void 0,
3062
+ disabled,
3063
+ className: classNames(
3064
+ selectTriggerVariants({ invalid: isInvalid, variant }),
3065
+ padding,
3066
+ selectAttachedClass(attached),
3067
+ "cursor-pointer focus-ring data-disabled:cursor-not-allowed data-popup-open:outline-2 data-popup-open:outline-offset-2 data-popup-open:outline-border-focus",
3068
+ className
3069
+ ),
3070
+ ...props
3071
+ }
3072
+ ),
3073
+ /* @__PURE__ */ jsx(
3074
+ SelectTrailing,
3075
+ {
3076
+ clearLabel,
3077
+ disabled,
3078
+ invalid: isInvalid,
3079
+ onClear,
3080
+ showClear
3081
+ }
3082
+ )
3083
+ ]
3084
+ }
3085
+ );
3086
+ }
3087
+ function ComboboxPopupInput({
3088
+ className,
3089
+ wrapperClassName,
3090
+ ...props
3091
+ }) {
3092
+ return /* @__PURE__ */ jsxs(
3093
+ "div",
3094
+ {
3095
+ "data-slot": "combobox-popup-input-wrapper",
3096
+ className: classNames(
3097
+ "mb-space-4 flex h-8 shrink-0 items-center gap-space-8 border-b border-border-subtle px-space-8 pb-space-4 box-content",
3098
+ wrapperClassName
3099
+ ),
3100
+ children: [
3101
+ /* @__PURE__ */ jsx(IconProvider, { icon: "magnifying-glass", size: "16", className: "shrink-0 text-icon-secondary" }),
3102
+ /* @__PURE__ */ jsx(
3103
+ ComboboxInput$1,
3104
+ {
3105
+ "data-slot": "combobox-popup-input",
3106
+ className: classNames(
3107
+ "h-full min-w-0 flex-1 bg-transparent font-lab text-body-md text-text-primary outline-none placeholder:text-text-placeholder",
3108
+ className
3109
+ ),
3110
+ ...props
3111
+ }
3112
+ )
3113
+ ]
3114
+ }
3115
+ );
3116
+ }
3117
+ function ComboboxContent({
3118
+ align = "start",
3119
+ className,
3120
+ collisionAvoidance,
3121
+ container,
3122
+ positionerClassName,
3123
+ side = "bottom",
3124
+ sideOffset = 8,
3125
+ ...props
3126
+ }) {
3127
+ return /* @__PURE__ */ jsx(ComboboxPortal, { container, children: /* @__PURE__ */ jsx(
3128
+ ComboboxPositioner,
3129
+ {
3130
+ "data-slot": "combobox-positioner",
3131
+ align,
3132
+ collisionAvoidance,
3133
+ side,
3134
+ sideOffset,
3135
+ className: classNames("isolate z-[1600] outline-none", positionerClassName),
3136
+ children: /* @__PURE__ */ jsx(
3137
+ ComboboxPopup,
3138
+ {
3139
+ "data-slot": "combobox-content",
3140
+ className: classNames(dropdownPanelVariants({ motion: "select", width: "trigger" }), className),
3141
+ ...props
3142
+ }
3143
+ )
3144
+ }
3145
+ ) });
3146
+ }
3147
+ function ComboboxList2({ className, ...props }) {
3148
+ return /* @__PURE__ */ jsx(
3149
+ ComboboxList$1,
3150
+ {
3151
+ "data-slot": "combobox-list",
3152
+ className: classNames(dropdownListVariants(), "empty:hidden", className),
3153
+ ...props
3154
+ }
3155
+ );
3156
+ }
3157
+ function ComboboxItem2({ children, className, ...props }) {
3158
+ return /* @__PURE__ */ jsxs(ComboboxItem$1, { "data-slot": "combobox-item", className: classNames(dropdownItemVariants(), className), ...props, children: [
3159
+ /* @__PURE__ */ jsx("span", { className: "flex min-w-0 flex-1 items-center gap-space-8 truncate", children }),
3160
+ /* @__PURE__ */ jsx(ComboboxItemIndicator, { className: "flex shrink-0 text-icon-brand", children: /* @__PURE__ */ jsx(IconProvider, { icon: "check", size: "16" }) })
3161
+ ] });
3162
+ }
3163
+ function ComboboxEmpty2({ className, ...props }) {
3164
+ return /* @__PURE__ */ jsx(
3165
+ ComboboxEmpty$1,
3166
+ {
3167
+ "data-slot": "combobox-empty",
3168
+ className: classNames(
3169
+ "flex justify-center px-space-8 py-space-12 font-lab text-body-md text-text-secondary empty:hidden",
3170
+ className
3171
+ ),
3172
+ ...props
3173
+ }
3174
+ );
3175
+ }
3176
+ function ComboboxGroup2({ className, ...props }) {
3177
+ return /* @__PURE__ */ jsx(
3178
+ ComboboxGroup$1,
3179
+ {
3180
+ "data-slot": "combobox-group",
3181
+ className: classNames("flex flex-col gap-space-2", className),
3182
+ ...props
3183
+ }
3184
+ );
3185
+ }
3186
+ function ComboboxLabel({ caps, className, ...props }) {
3187
+ return /* @__PURE__ */ jsx(
3188
+ ComboboxGroupLabel,
3189
+ {
3190
+ "data-slot": "combobox-label",
3191
+ className: classNames(dropdownLabelVariants({ caps }), className),
3192
+ ...props
3193
+ }
3194
+ );
3195
+ }
3196
+ function ComboboxSeparator({ className, ...props }) {
3197
+ return /* @__PURE__ */ jsx(
3198
+ ComboboxSeparator$1,
3199
+ {
3200
+ "data-slot": "combobox-separator",
3201
+ className: classNames(dropdownSeparatorVariants(), className),
3202
+ ...props
3203
+ }
3204
+ );
3205
+ }
3206
+ function ComboboxChips2({ className, ...props }) {
3207
+ return /* @__PURE__ */ jsx(
3208
+ ComboboxChips$1,
3209
+ {
3210
+ "data-slot": "combobox-chips",
3211
+ className: classNames("flex w-80 max-w-full flex-wrap gap-space-4", className),
3212
+ ...props
3213
+ }
3214
+ );
3215
+ }
3216
+ function ComboboxChip2({ children, className, removeLabel = "Remove", ...props }) {
3217
+ return /* @__PURE__ */ jsxs(
3218
+ ComboboxChip$1,
3219
+ {
3220
+ "data-slot": "combobox-chip",
3221
+ className: classNames(selectChipVariants(), "outline-none data-highlighted:border-border-default", className),
3222
+ ...props,
3223
+ children: [
3224
+ children,
3225
+ /* @__PURE__ */ jsx(
3226
+ ComboboxChipRemove,
3227
+ {
3228
+ "aria-label": removeLabel,
3229
+ className: "flex size-2.25 shrink-0 items-center justify-center rounded-sm text-icon-secondary focus-ring hover:text-icon-primary",
3230
+ children: /* @__PURE__ */ jsx(IconProvider, { icon: "xmark", size: 0.75 })
3231
+ }
3232
+ )
3233
+ ]
3234
+ }
3235
+ );
3236
+ }
3237
+ export {
3238
+ Combobox,
3239
+ ComboboxChip2 as ComboboxChip,
3240
+ ComboboxChips2 as ComboboxChips,
3241
+ ComboboxContent,
3242
+ ComboboxEmpty2 as ComboboxEmpty,
3243
+ ComboboxGroup2 as ComboboxGroup,
3244
+ ComboboxInput2 as ComboboxInput,
3245
+ ComboboxItem2 as ComboboxItem,
3246
+ ComboboxLabel,
3247
+ ComboboxList2 as ComboboxList,
3248
+ ComboboxPopupInput,
3249
+ ComboboxSeparator,
3250
+ ComboboxTrigger2 as ComboboxTrigger
3251
+ };
3252
+ //# sourceMappingURL=Combobox.es.js.map