@tamagui/floating 2.7.7 → 3.0.0-beta.1093.1

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