@tamagui/floating 2.0.0-rc.4 → 2.0.0-rc.40

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 (191) hide show
  1. package/dist/cjs/Floating.cjs +7 -5
  2. package/dist/cjs/Floating.native.js +19 -13
  3. package/dist/cjs/Floating.native.js.map +1 -1
  4. package/dist/cjs/index.cjs +46 -13
  5. package/dist/cjs/index.native.js +46 -13
  6. package/dist/cjs/index.native.js.map +1 -1
  7. package/dist/cjs/interactions/PopupTriggerMap.cjs +49 -0
  8. package/dist/cjs/interactions/PopupTriggerMap.native.js +97 -0
  9. package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -0
  10. package/dist/cjs/interactions/createFloatingEvents.cjs +50 -0
  11. package/dist/cjs/interactions/createFloatingEvents.native.js +56 -0
  12. package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -0
  13. package/dist/cjs/interactions/safePolygon.cjs +273 -0
  14. package/dist/cjs/interactions/safePolygon.native.js +284 -0
  15. package/dist/cjs/interactions/safePolygon.native.js.map +1 -0
  16. package/dist/cjs/interactions/types.cjs +18 -0
  17. package/dist/cjs/interactions/types.native.js +21 -0
  18. package/dist/cjs/interactions/types.native.js.map +1 -0
  19. package/dist/cjs/interactions/useClick.cjs +124 -0
  20. package/dist/cjs/interactions/useClick.native.js +132 -0
  21. package/dist/cjs/interactions/useClick.native.js.map +1 -0
  22. package/dist/cjs/interactions/useDelayGroup.cjs +115 -0
  23. package/dist/cjs/interactions/useDelayGroup.native.js +125 -0
  24. package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -0
  25. package/dist/cjs/interactions/useFocus.cjs +130 -0
  26. package/dist/cjs/interactions/useFocus.native.js +139 -0
  27. package/dist/cjs/interactions/useFocus.native.js.map +1 -0
  28. package/dist/cjs/interactions/useHover.cjs +357 -0
  29. package/dist/cjs/interactions/useHover.native.js +373 -0
  30. package/dist/cjs/interactions/useHover.native.js.map +1 -0
  31. package/dist/cjs/interactions/useInnerOffset.cjs +128 -0
  32. package/dist/cjs/interactions/useInnerOffset.native.js +141 -0
  33. package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -0
  34. package/dist/cjs/interactions/useInteractions.cjs +105 -0
  35. package/dist/cjs/interactions/useInteractions.native.js +216 -0
  36. package/dist/cjs/interactions/useInteractions.native.js.map +1 -0
  37. package/dist/cjs/interactions/useListNavigation.cjs +418 -0
  38. package/dist/cjs/interactions/useListNavigation.native.js +433 -0
  39. package/dist/cjs/interactions/useListNavigation.native.js.map +1 -0
  40. package/dist/cjs/interactions/useRole.cjs +122 -0
  41. package/dist/cjs/interactions/useRole.native.js +136 -0
  42. package/dist/cjs/interactions/useRole.native.js.map +1 -0
  43. package/dist/cjs/interactions/useTypeahead.cjs +143 -0
  44. package/dist/cjs/interactions/useTypeahead.native.js +159 -0
  45. package/dist/cjs/interactions/useTypeahead.native.js.map +1 -0
  46. package/dist/cjs/interactions/utils.cjs +208 -0
  47. package/dist/cjs/interactions/utils.native.js +227 -0
  48. package/dist/cjs/interactions/utils.native.js.map +1 -0
  49. package/dist/cjs/middleware/inner.cjs +118 -0
  50. package/dist/cjs/middleware/inner.native.js +130 -0
  51. package/dist/cjs/middleware/inner.native.js.map +1 -0
  52. package/dist/cjs/useFloating.cjs +35 -28
  53. package/dist/cjs/useFloating.native.js +51 -47
  54. package/dist/cjs/useFloating.native.js.map +1 -1
  55. package/dist/esm/Floating.native.js +6 -3
  56. package/dist/esm/Floating.native.js.map +1 -1
  57. package/dist/esm/index.js +17 -34
  58. package/dist/esm/index.js.map +1 -6
  59. package/dist/esm/index.mjs +16 -2
  60. package/dist/esm/index.mjs.map +1 -1
  61. package/dist/esm/index.native.js +16 -2
  62. package/dist/esm/index.native.js.map +1 -1
  63. package/dist/esm/interactions/PopupTriggerMap.mjs +24 -0
  64. package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -0
  65. package/dist/esm/interactions/PopupTriggerMap.native.js +69 -0
  66. package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -0
  67. package/dist/esm/interactions/createFloatingEvents.mjs +25 -0
  68. package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -0
  69. package/dist/esm/interactions/createFloatingEvents.native.js +28 -0
  70. package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -0
  71. package/dist/esm/interactions/safePolygon.mjs +248 -0
  72. package/dist/esm/interactions/safePolygon.mjs.map +1 -0
  73. package/dist/esm/interactions/safePolygon.native.js +256 -0
  74. package/dist/esm/interactions/safePolygon.native.js.map +1 -0
  75. package/dist/esm/interactions/types.mjs +2 -0
  76. package/dist/esm/interactions/types.mjs.map +1 -0
  77. package/dist/esm/interactions/types.native.js +2 -0
  78. package/dist/esm/interactions/types.native.js.map +1 -0
  79. package/dist/esm/interactions/useClick.mjs +99 -0
  80. package/dist/esm/interactions/useClick.mjs.map +1 -0
  81. package/dist/esm/interactions/useClick.native.js +104 -0
  82. package/dist/esm/interactions/useClick.native.js.map +1 -0
  83. package/dist/esm/interactions/useDelayGroup.mjs +77 -0
  84. package/dist/esm/interactions/useDelayGroup.mjs.map +1 -0
  85. package/dist/esm/interactions/useDelayGroup.native.js +84 -0
  86. package/dist/esm/interactions/useDelayGroup.native.js.map +1 -0
  87. package/dist/esm/interactions/useFocus.mjs +105 -0
  88. package/dist/esm/interactions/useFocus.mjs.map +1 -0
  89. package/dist/esm/interactions/useFocus.native.js +111 -0
  90. package/dist/esm/interactions/useFocus.native.js.map +1 -0
  91. package/dist/esm/interactions/useHover.mjs +320 -0
  92. package/dist/esm/interactions/useHover.mjs.map +1 -0
  93. package/dist/esm/interactions/useHover.native.js +333 -0
  94. package/dist/esm/interactions/useHover.native.js.map +1 -0
  95. package/dist/esm/interactions/useInnerOffset.mjs +92 -0
  96. package/dist/esm/interactions/useInnerOffset.mjs.map +1 -0
  97. package/dist/esm/interactions/useInnerOffset.native.js +102 -0
  98. package/dist/esm/interactions/useInnerOffset.native.js.map +1 -0
  99. package/dist/esm/interactions/useInteractions.mjs +80 -0
  100. package/dist/esm/interactions/useInteractions.mjs.map +1 -0
  101. package/dist/esm/interactions/useInteractions.native.js +188 -0
  102. package/dist/esm/interactions/useInteractions.native.js.map +1 -0
  103. package/dist/esm/interactions/useListNavigation.mjs +393 -0
  104. package/dist/esm/interactions/useListNavigation.mjs.map +1 -0
  105. package/dist/esm/interactions/useListNavigation.native.js +405 -0
  106. package/dist/esm/interactions/useListNavigation.native.js.map +1 -0
  107. package/dist/esm/interactions/useRole.mjs +86 -0
  108. package/dist/esm/interactions/useRole.mjs.map +1 -0
  109. package/dist/esm/interactions/useRole.native.js +97 -0
  110. package/dist/esm/interactions/useRole.native.js.map +1 -0
  111. package/dist/esm/interactions/useTypeahead.mjs +118 -0
  112. package/dist/esm/interactions/useTypeahead.mjs.map +1 -0
  113. package/dist/esm/interactions/useTypeahead.native.js +131 -0
  114. package/dist/esm/interactions/useTypeahead.native.js.map +1 -0
  115. package/dist/esm/interactions/utils.mjs +162 -0
  116. package/dist/esm/interactions/utils.mjs.map +1 -0
  117. package/dist/esm/interactions/utils.native.js +178 -0
  118. package/dist/esm/interactions/utils.native.js.map +1 -0
  119. package/dist/esm/middleware/inner.mjs +82 -0
  120. package/dist/esm/middleware/inner.mjs.map +1 -0
  121. package/dist/esm/middleware/inner.native.js +91 -0
  122. package/dist/esm/middleware/inner.native.js.map +1 -0
  123. package/dist/esm/useFloating.mjs +8 -3
  124. package/dist/esm/useFloating.mjs.map +1 -1
  125. package/dist/esm/useFloating.native.js +25 -23
  126. package/dist/esm/useFloating.native.js.map +1 -1
  127. package/package.json +8 -10
  128. package/src/Floating.native.tsx +1 -0
  129. package/src/index.ts +49 -0
  130. package/src/interactions/PopupTriggerMap.ts +30 -0
  131. package/src/interactions/createFloatingEvents.ts +34 -0
  132. package/src/interactions/safePolygon.ts +500 -0
  133. package/src/interactions/types.ts +165 -0
  134. package/src/interactions/useClick.ts +148 -0
  135. package/src/interactions/useDelayGroup.ts +114 -0
  136. package/src/interactions/useFocus.ts +164 -0
  137. package/src/interactions/useHover.ts +453 -0
  138. package/src/interactions/useInnerOffset.ts +116 -0
  139. package/src/interactions/useInteractions.ts +101 -0
  140. package/src/interactions/useListNavigation.ts +578 -0
  141. package/src/interactions/useRole.ts +103 -0
  142. package/src/interactions/useTypeahead.ts +173 -0
  143. package/src/interactions/utils.ts +234 -0
  144. package/src/middleware/inner.ts +141 -0
  145. package/src/useFloating.tsx +13 -1
  146. package/types/Floating.native.d.ts +1 -0
  147. package/types/Floating.native.d.ts.map +1 -1
  148. package/types/index.d.ts +17 -2
  149. package/types/index.d.ts.map +1 -1
  150. package/types/interactions/PopupTriggerMap.d.ts +8 -0
  151. package/types/interactions/PopupTriggerMap.d.ts.map +1 -0
  152. package/types/interactions/createFloatingEvents.d.ts +7 -0
  153. package/types/interactions/createFloatingEvents.d.ts.map +1 -0
  154. package/types/interactions/safePolygon.d.ts +4 -0
  155. package/types/interactions/safePolygon.d.ts.map +1 -0
  156. package/types/interactions/types.d.ts +123 -0
  157. package/types/interactions/types.d.ts.map +1 -0
  158. package/types/interactions/useClick.d.ts +3 -0
  159. package/types/interactions/useClick.d.ts.map +1 -0
  160. package/types/interactions/useDelayGroup.d.ts +23 -0
  161. package/types/interactions/useDelayGroup.d.ts.map +1 -0
  162. package/types/interactions/useFocus.d.ts +3 -0
  163. package/types/interactions/useFocus.d.ts.map +1 -0
  164. package/types/interactions/useHover.d.ts +6 -0
  165. package/types/interactions/useHover.d.ts.map +1 -0
  166. package/types/interactions/useInnerOffset.d.ts +3 -0
  167. package/types/interactions/useInnerOffset.d.ts.map +1 -0
  168. package/types/interactions/useInteractions.d.ts +8 -0
  169. package/types/interactions/useInteractions.d.ts.map +1 -0
  170. package/types/interactions/useListNavigation.d.ts +3 -0
  171. package/types/interactions/useListNavigation.d.ts.map +1 -0
  172. package/types/interactions/useRole.d.ts +3 -0
  173. package/types/interactions/useRole.d.ts.map +1 -0
  174. package/types/interactions/useTypeahead.d.ts +3 -0
  175. package/types/interactions/useTypeahead.d.ts.map +1 -0
  176. package/types/interactions/utils.d.ts +46 -0
  177. package/types/interactions/utils.d.ts.map +1 -0
  178. package/types/middleware/inner.d.ts +14 -0
  179. package/types/middleware/inner.d.ts.map +1 -0
  180. package/types/useFloating.d.ts +7 -1
  181. package/types/useFloating.d.ts.map +1 -1
  182. package/dist/cjs/Floating.js +0 -15
  183. package/dist/cjs/Floating.js.map +0 -6
  184. package/dist/cjs/index.js +0 -34
  185. package/dist/cjs/index.js.map +0 -6
  186. package/dist/cjs/useFloating.js +0 -46
  187. package/dist/cjs/useFloating.js.map +0 -6
  188. package/dist/esm/Floating.js +0 -2
  189. package/dist/esm/Floating.js.map +0 -6
  190. package/dist/esm/useFloating.js +0 -23
  191. package/dist/esm/useFloating.js.map +0 -6
@@ -0,0 +1,418 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all) __defProp(target, name, {
7
+ get: all[name],
8
+ enumerable: true
9
+ });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
14
+ get: () => from[key],
15
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
16
+ });
17
+ }
18
+ return to;
19
+ };
20
+ var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
+ value: true
22
+ }), mod);
23
+ var useListNavigation_exports = {};
24
+ __export(useListNavigation_exports, {
25
+ useListNavigation: () => useListNavigation
26
+ });
27
+ module.exports = __toCommonJS(useListNavigation_exports);
28
+ var import_react = require("react");
29
+ var import_use_event = require("@tamagui/use-event");
30
+ var import_utils = require("./utils.cjs");
31
+ const ARROW_UP = "ArrowUp";
32
+ const ARROW_DOWN = "ArrowDown";
33
+ const ARROW_LEFT = "ArrowLeft";
34
+ const ARROW_RIGHT = "ArrowRight";
35
+ function doSwitch(orientation, vertical, horizontal) {
36
+ switch (orientation) {
37
+ case "vertical":
38
+ return vertical;
39
+ case "horizontal":
40
+ return horizontal;
41
+ default:
42
+ return vertical || horizontal;
43
+ }
44
+ }
45
+ function isMainOrientationKey(key, orientation) {
46
+ const vertical = key === ARROW_UP || key === ARROW_DOWN;
47
+ const horizontal = key === ARROW_LEFT || key === ARROW_RIGHT;
48
+ return doSwitch(orientation, vertical, horizontal);
49
+ }
50
+ function isMainOrientationToEndKey(key, orientation, rtl) {
51
+ const vertical = key === ARROW_DOWN;
52
+ const horizontal = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
53
+ return doSwitch(orientation, vertical, horizontal) || key === "Enter" || key === " " || key === "";
54
+ }
55
+ function isCrossOrientationOpenKey(key, orientation, rtl) {
56
+ const vertical = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
57
+ const horizontal = key === ARROW_DOWN;
58
+ return doSwitch(orientation, vertical, horizontal);
59
+ }
60
+ function isCrossOrientationCloseKey(key, orientation, rtl) {
61
+ const vertical = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT;
62
+ const horizontal = key === ARROW_UP;
63
+ return doSwitch(orientation, vertical, horizontal);
64
+ }
65
+ function useListNavigation(context, props) {
66
+ const {
67
+ open,
68
+ onOpenChange,
69
+ elements
70
+ } = context;
71
+ const {
72
+ listRef,
73
+ activeIndex,
74
+ onNavigate: unstable_onNavigate = () => {},
75
+ enabled = true,
76
+ selectedIndex = null,
77
+ allowEscape = false,
78
+ loop = false,
79
+ nested = false,
80
+ rtl = false,
81
+ virtual = false,
82
+ focusItemOnOpen = "auto",
83
+ focusItemOnHover = true,
84
+ openOnArrowKeyDown = true,
85
+ disabledIndices = void 0,
86
+ orientation = "vertical",
87
+ scrollItemIntoView = true
88
+ } = props;
89
+ const typeableComboboxReference = (0, import_utils.isTypeableCombobox)(elements.domReference);
90
+ const focusItemOnOpenRef = (0, import_react.useRef)(focusItemOnOpen);
91
+ const indexRef = (0, import_react.useRef)(selectedIndex ?? -1);
92
+ const keyRef = (0, import_react.useRef)(null);
93
+ const isPointerModalityRef = (0, import_react.useRef)(true);
94
+ const previousMountedRef = (0, import_react.useRef)(!!elements.floating);
95
+ const previousOpenRef = (0, import_react.useRef)(open);
96
+ const forceSyncFocusRef = (0, import_react.useRef)(false);
97
+ const forceScrollIntoViewRef = (0, import_react.useRef)(false);
98
+ const disabledIndicesRef = (0, import_react.useRef)(disabledIndices);
99
+ disabledIndicesRef.current = disabledIndices;
100
+ const latestOpenRef = (0, import_react.useRef)(open);
101
+ latestOpenRef.current = open;
102
+ const scrollItemIntoViewRef = (0, import_react.useRef)(scrollItemIntoView);
103
+ scrollItemIntoViewRef.current = scrollItemIntoView;
104
+ const selectedIndexRef = (0, import_react.useRef)(selectedIndex);
105
+ selectedIndexRef.current = selectedIndex;
106
+ const stableOnNavigate = (0, import_use_event.useEvent)(unstable_onNavigate);
107
+ const [activeId, setActiveId] = (0, import_react.useState)();
108
+ const onNavigate = (0, import_use_event.useEvent)(() => {
109
+ stableOnNavigate(indexRef.current === -1 ? null : indexRef.current);
110
+ });
111
+ const previousOnNavigateRef = (0, import_react.useRef)(onNavigate);
112
+ const focusItem = (0, import_use_event.useEvent)(() => {
113
+ function runFocus(item2) {
114
+ if (virtual) {
115
+ setActiveId(item2.id);
116
+ } else {
117
+ (0, import_utils.enqueueFocus)(item2, {
118
+ sync: forceSyncFocusRef.current,
119
+ preventScroll: true
120
+ });
121
+ }
122
+ }
123
+ const initialItem = listRef.current[indexRef.current];
124
+ const forceScrollIntoView = forceScrollIntoViewRef.current;
125
+ if (initialItem) {
126
+ runFocus(initialItem);
127
+ }
128
+ const scheduler = forceSyncFocusRef.current ? v => v() : requestAnimationFrame;
129
+ scheduler(() => {
130
+ const waitedItem = listRef.current[indexRef.current] || initialItem;
131
+ if (!waitedItem) return;
132
+ if (!initialItem) {
133
+ runFocus(waitedItem);
134
+ }
135
+ const scrollIntoViewOptions = scrollItemIntoViewRef.current;
136
+ const shouldScrollIntoView = scrollIntoViewOptions && waitedItem && (forceScrollIntoView || !isPointerModalityRef.current);
137
+ if (shouldScrollIntoView) {
138
+ waitedItem.scrollIntoView?.(typeof scrollIntoViewOptions === "boolean" ? {
139
+ block: "nearest",
140
+ inline: "nearest"
141
+ } : scrollIntoViewOptions);
142
+ }
143
+ });
144
+ });
145
+ (0, import_react.useLayoutEffect)(() => {
146
+ if (!enabled) return;
147
+ if (open && elements.floating) {
148
+ if (focusItemOnOpenRef.current && selectedIndex != null) {
149
+ forceScrollIntoViewRef.current = true;
150
+ indexRef.current = selectedIndex;
151
+ onNavigate();
152
+ }
153
+ } else if (previousMountedRef.current) {
154
+ indexRef.current = -1;
155
+ previousOnNavigateRef.current();
156
+ }
157
+ }, [enabled, open, elements.floating, selectedIndex, onNavigate]);
158
+ (0, import_react.useLayoutEffect)(() => {
159
+ if (!enabled) return;
160
+ if (!open) return;
161
+ if (!elements.floating) return;
162
+ if (activeIndex == null) {
163
+ forceSyncFocusRef.current = false;
164
+ if (selectedIndexRef.current != null) {
165
+ return;
166
+ }
167
+ if (previousMountedRef.current) {
168
+ indexRef.current = -1;
169
+ focusItem();
170
+ }
171
+ if ((!previousOpenRef.current || !previousMountedRef.current) && focusItemOnOpenRef.current && (keyRef.current != null || focusItemOnOpenRef.current === true && keyRef.current == null)) {
172
+ let runs = 0;
173
+ const waitForListPopulated = () => {
174
+ if (listRef.current[0] == null) {
175
+ if (runs < 2) {
176
+ const scheduler = runs ? requestAnimationFrame : queueMicrotask;
177
+ scheduler(waitForListPopulated);
178
+ }
179
+ runs++;
180
+ } else {
181
+ indexRef.current = keyRef.current == null || isMainOrientationToEndKey(keyRef.current, orientation, rtl) || nested ? (0, import_utils.getMinListIndex)(listRef, disabledIndicesRef.current) : (0, import_utils.getMaxListIndex)(listRef, disabledIndicesRef.current);
182
+ keyRef.current = null;
183
+ onNavigate();
184
+ }
185
+ };
186
+ waitForListPopulated();
187
+ }
188
+ } else if (!(0, import_utils.isIndexOutOfListBounds)(listRef, activeIndex)) {
189
+ indexRef.current = activeIndex;
190
+ focusItem();
191
+ forceScrollIntoViewRef.current = false;
192
+ }
193
+ }, [enabled, open, elements.floating, activeIndex, selectedIndexRef, nested, listRef, orientation, rtl, onNavigate, focusItem, disabledIndicesRef]);
194
+ (0, import_react.useLayoutEffect)(() => {
195
+ previousOnNavigateRef.current = onNavigate;
196
+ previousOpenRef.current = open;
197
+ previousMountedRef.current = !!elements.floating;
198
+ });
199
+ (0, import_react.useLayoutEffect)(() => {
200
+ if (!open) {
201
+ keyRef.current = null;
202
+ focusItemOnOpenRef.current = focusItemOnOpen;
203
+ }
204
+ }, [open, focusItemOnOpen]);
205
+ const hasActiveIndex = activeIndex != null;
206
+ const commonOnKeyDown = (0, import_use_event.useEvent)(event => {
207
+ isPointerModalityRef.current = false;
208
+ forceSyncFocusRef.current = true;
209
+ if (event.which === 229) {
210
+ return;
211
+ }
212
+ if (!latestOpenRef.current && event.currentTarget === elements.floating) {
213
+ return;
214
+ }
215
+ if (nested && isCrossOrientationCloseKey(event.key, orientation, rtl)) {
216
+ (0, import_utils.stopEvent)(event);
217
+ onOpenChange(false, event.nativeEvent, "list-navigation");
218
+ if ((0, import_utils.isHTMLElement)(elements.domReference)) {
219
+ elements.domReference.focus();
220
+ }
221
+ return;
222
+ }
223
+ const currentIndex = indexRef.current;
224
+ const minIndex = (0, import_utils.getMinListIndex)(listRef, disabledIndices);
225
+ const maxIndex = (0, import_utils.getMaxListIndex)(listRef, disabledIndices);
226
+ if (!typeableComboboxReference) {
227
+ if (event.key === "Home") {
228
+ (0, import_utils.stopEvent)(event);
229
+ indexRef.current = minIndex;
230
+ onNavigate();
231
+ }
232
+ if (event.key === "End") {
233
+ (0, import_utils.stopEvent)(event);
234
+ indexRef.current = maxIndex;
235
+ onNavigate();
236
+ }
237
+ }
238
+ if (isMainOrientationKey(event.key, orientation)) {
239
+ (0, import_utils.stopEvent)(event);
240
+ if (open && !virtual && (0, import_utils.activeElement)(event.currentTarget.ownerDocument) === event.currentTarget) {
241
+ indexRef.current = isMainOrientationToEndKey(event.key, orientation, rtl) ? minIndex : maxIndex;
242
+ onNavigate();
243
+ return;
244
+ }
245
+ if (isMainOrientationToEndKey(event.key, orientation, rtl)) {
246
+ if (loop) {
247
+ indexRef.current = currentIndex >= maxIndex ? allowEscape && currentIndex !== listRef.current.length ? -1 : minIndex : (0, import_utils.findNonDisabledListIndex)(listRef, {
248
+ startingIndex: currentIndex,
249
+ disabledIndices
250
+ });
251
+ } else {
252
+ indexRef.current = Math.min(maxIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {
253
+ startingIndex: currentIndex,
254
+ disabledIndices
255
+ }));
256
+ }
257
+ } else {
258
+ if (loop) {
259
+ indexRef.current = currentIndex <= minIndex ? allowEscape && currentIndex !== -1 ? listRef.current.length : maxIndex : (0, import_utils.findNonDisabledListIndex)(listRef, {
260
+ startingIndex: currentIndex,
261
+ decrement: true,
262
+ disabledIndices
263
+ });
264
+ } else {
265
+ indexRef.current = Math.max(minIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {
266
+ startingIndex: currentIndex,
267
+ decrement: true,
268
+ disabledIndices
269
+ }));
270
+ }
271
+ }
272
+ if ((0, import_utils.isIndexOutOfListBounds)(listRef, indexRef.current)) {
273
+ indexRef.current = -1;
274
+ }
275
+ onNavigate();
276
+ }
277
+ });
278
+ const ariaActiveDescendantProp = (0, import_react.useMemo)(() => {
279
+ return virtual && open && hasActiveIndex && {
280
+ "aria-activedescendant": activeId
281
+ };
282
+ }, [virtual, open, hasActiveIndex, activeId]);
283
+ const floating = (0, import_react.useMemo)(() => {
284
+ return {
285
+ "aria-orientation": orientation === "both" ? void 0 : orientation,
286
+ ...(!typeableComboboxReference ? ariaActiveDescendantProp : {}),
287
+ onKeyDown: commonOnKeyDown,
288
+ onPointerMove() {
289
+ isPointerModalityRef.current = true;
290
+ }
291
+ };
292
+ }, [ariaActiveDescendantProp, commonOnKeyDown, orientation, typeableComboboxReference]);
293
+ const reference = (0, import_react.useMemo)(() => {
294
+ function checkVirtualMouse(event) {
295
+ if (focusItemOnOpen === "auto" && (0, import_utils.isVirtualClick)(event.nativeEvent)) {
296
+ focusItemOnOpenRef.current = true;
297
+ }
298
+ }
299
+ function checkVirtualPointer(event) {
300
+ focusItemOnOpenRef.current = focusItemOnOpen;
301
+ if (focusItemOnOpen === "auto" && (0, import_utils.isVirtualPointerEvent)(event.nativeEvent)) {
302
+ focusItemOnOpenRef.current = true;
303
+ }
304
+ }
305
+ return {
306
+ ...ariaActiveDescendantProp,
307
+ onKeyDown(event) {
308
+ isPointerModalityRef.current = false;
309
+ const isArrowKey = event.key.startsWith("Arrow");
310
+ const isCrossOpenKey = isCrossOrientationOpenKey(event.key, orientation, rtl);
311
+ const isMainKey = isMainOrientationKey(event.key, orientation);
312
+ const isNavigationKey = (nested ? isCrossOpenKey : isMainKey) || event.key === "Enter" || event.key.trim() === "";
313
+ if (virtual && open) {
314
+ return commonOnKeyDown(event);
315
+ }
316
+ if (!open && !openOnArrowKeyDown && isArrowKey) {
317
+ return;
318
+ }
319
+ if (isNavigationKey) {
320
+ keyRef.current = event.key;
321
+ }
322
+ if (nested) {
323
+ if (isCrossOpenKey) {
324
+ (0, import_utils.stopEvent)(event);
325
+ if (open) {
326
+ indexRef.current = (0, import_utils.getMinListIndex)(listRef, disabledIndicesRef.current);
327
+ onNavigate();
328
+ } else {
329
+ onOpenChange(true, event.nativeEvent, "list-navigation");
330
+ }
331
+ }
332
+ return;
333
+ }
334
+ if (isMainKey) {
335
+ if (selectedIndex != null) {
336
+ indexRef.current = selectedIndex;
337
+ }
338
+ (0, import_utils.stopEvent)(event);
339
+ if (!open && openOnArrowKeyDown) {
340
+ onOpenChange(true, event.nativeEvent, "list-navigation");
341
+ } else {
342
+ commonOnKeyDown(event);
343
+ }
344
+ if (open) {
345
+ onNavigate();
346
+ }
347
+ }
348
+ },
349
+ onFocus() {
350
+ if (open && !virtual) {
351
+ indexRef.current = -1;
352
+ onNavigate();
353
+ }
354
+ },
355
+ onPointerDown: checkVirtualPointer,
356
+ onPointerEnter: checkVirtualPointer,
357
+ onMouseDown: checkVirtualMouse,
358
+ onClick: checkVirtualMouse
359
+ };
360
+ }, [ariaActiveDescendantProp, commonOnKeyDown, disabledIndicesRef, focusItemOnOpen, listRef, nested, onNavigate, onOpenChange, open, openOnArrowKeyDown, orientation, rtl, selectedIndex, virtual]);
361
+ const item = (0, import_react.useMemo)(() => {
362
+ function syncCurrentTarget(currentTarget) {
363
+ if (!latestOpenRef.current) return;
364
+ const index = listRef.current.indexOf(currentTarget);
365
+ if (index !== -1 && indexRef.current !== index) {
366
+ indexRef.current = index;
367
+ onNavigate();
368
+ }
369
+ }
370
+ const itemProps = {
371
+ onFocus({
372
+ currentTarget
373
+ }) {
374
+ forceSyncFocusRef.current = true;
375
+ syncCurrentTarget(currentTarget);
376
+ },
377
+ onClick: ({
378
+ currentTarget
379
+ }) => currentTarget.focus({
380
+ preventScroll: true
381
+ }),
382
+ // safari
383
+ onMouseMove({
384
+ currentTarget
385
+ }) {
386
+ forceSyncFocusRef.current = true;
387
+ forceScrollIntoViewRef.current = false;
388
+ if (focusItemOnHover) {
389
+ syncCurrentTarget(currentTarget);
390
+ }
391
+ },
392
+ onPointerLeave({
393
+ pointerType
394
+ }) {
395
+ if (!isPointerModalityRef.current || pointerType === "touch") {
396
+ return;
397
+ }
398
+ forceSyncFocusRef.current = true;
399
+ if (!focusItemOnHover) {
400
+ return;
401
+ }
402
+ indexRef.current = -1;
403
+ onNavigate();
404
+ if (!virtual) {
405
+ elements.floating?.focus({
406
+ preventScroll: true
407
+ });
408
+ }
409
+ }
410
+ };
411
+ return itemProps;
412
+ }, [latestOpenRef, focusItemOnHover, listRef, onNavigate, virtual, elements.floating]);
413
+ return (0, import_react.useMemo)(() => enabled ? {
414
+ reference,
415
+ floating,
416
+ item
417
+ } : {}, [enabled, reference, floating, item]);
418
+ }