@hanzogui/floating 3.0.5 → 4.3.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 (117) hide show
  1. package/dist/cjs/Floating.cjs +7 -5
  2. package/dist/cjs/Floating.native.js +18 -16
  3. package/dist/cjs/Floating.native.js.map +1 -1
  4. package/dist/cjs/index.cjs +28 -26
  5. package/dist/cjs/index.native.js +28 -26
  6. package/dist/cjs/index.native.js.map +1 -1
  7. package/dist/cjs/interactions/PopupTriggerMap.cjs +21 -12
  8. package/dist/cjs/interactions/PopupTriggerMap.native.js +51 -27
  9. package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -1
  10. package/dist/cjs/interactions/createFloatingEvents.cjs +21 -12
  11. package/dist/cjs/interactions/createFloatingEvents.native.js +22 -13
  12. package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -1
  13. package/dist/cjs/interactions/safePolygon.cjs +213 -131
  14. package/dist/cjs/interactions/safePolygon.native.js +182 -103
  15. package/dist/cjs/interactions/safePolygon.native.js.map +1 -1
  16. package/dist/cjs/interactions/types.cjs +7 -5
  17. package/dist/cjs/interactions/types.native.js +7 -5
  18. package/dist/cjs/interactions/types.native.js.map +1 -1
  19. package/dist/cjs/interactions/useClick.cjs +91 -49
  20. package/dist/cjs/interactions/useClick.native.js +96 -54
  21. package/dist/cjs/interactions/useClick.native.js.map +1 -1
  22. package/dist/cjs/interactions/useDelayGroup.cjs +63 -44
  23. package/dist/cjs/interactions/useDelayGroup.native.js +74 -58
  24. package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -1
  25. package/dist/cjs/interactions/useFocus.cjs +73 -44
  26. package/dist/cjs/interactions/useFocus.native.js +75 -49
  27. package/dist/cjs/interactions/useFocus.native.js.map +1 -1
  28. package/dist/cjs/interactions/useHover.cjs +242 -109
  29. package/dist/cjs/interactions/useHover.native.js +268 -143
  30. package/dist/cjs/interactions/useHover.native.js.map +1 -1
  31. package/dist/cjs/interactions/useInnerOffset.cjs +88 -64
  32. package/dist/cjs/interactions/useInnerOffset.native.js +88 -65
  33. package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -1
  34. package/dist/cjs/interactions/useInteractions.cjs +60 -31
  35. package/dist/cjs/interactions/useInteractions.native.js +133 -81
  36. package/dist/cjs/interactions/useInteractions.native.js.map +1 -1
  37. package/dist/cjs/interactions/useListNavigation.cjs +346 -181
  38. package/dist/cjs/interactions/useListNavigation.native.js +350 -214
  39. package/dist/cjs/interactions/useListNavigation.native.js.map +1 -1
  40. package/dist/cjs/interactions/useRole.cjs +83 -73
  41. package/dist/cjs/interactions/useRole.native.js +107 -99
  42. package/dist/cjs/interactions/useRole.native.js.map +1 -1
  43. package/dist/cjs/interactions/useTypeahead.cjs +115 -65
  44. package/dist/cjs/interactions/useTypeahead.native.js +122 -77
  45. package/dist/cjs/interactions/useTypeahead.native.js.map +1 -1
  46. package/dist/cjs/interactions/utils.cjs +68 -38
  47. package/dist/cjs/interactions/utils.native.js +93 -54
  48. package/dist/cjs/interactions/utils.native.js.map +1 -1
  49. package/dist/cjs/middleware/inner.cjs +80 -67
  50. package/dist/cjs/middleware/inner.native.js +87 -76
  51. package/dist/cjs/middleware/inner.native.js.map +1 -1
  52. package/dist/cjs/useFloating.cjs +48 -45
  53. package/dist/cjs/useFloating.native.js +50 -48
  54. package/dist/cjs/useFloating.native.js.map +1 -1
  55. package/dist/esm/Floating.native.js +5 -5
  56. package/dist/esm/Floating.native.js.map +1 -1
  57. package/dist/esm/interactions/PopupTriggerMap.mjs +9 -2
  58. package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -1
  59. package/dist/esm/interactions/PopupTriggerMap.native.js +39 -17
  60. package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -1
  61. package/dist/esm/interactions/createFloatingEvents.mjs +9 -2
  62. package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -1
  63. package/dist/esm/interactions/createFloatingEvents.native.js +10 -3
  64. package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -1
  65. package/dist/esm/interactions/safePolygon.mjs +201 -121
  66. package/dist/esm/interactions/safePolygon.mjs.map +1 -1
  67. package/dist/esm/interactions/safePolygon.native.js +170 -93
  68. package/dist/esm/interactions/safePolygon.native.js.map +1 -1
  69. package/dist/esm/interactions/useClick.mjs +79 -39
  70. package/dist/esm/interactions/useClick.mjs.map +1 -1
  71. package/dist/esm/interactions/useClick.native.js +82 -42
  72. package/dist/esm/interactions/useClick.native.js.map +1 -1
  73. package/dist/esm/interactions/useDelayGroup.mjs +39 -22
  74. package/dist/esm/interactions/useDelayGroup.mjs.map +1 -1
  75. package/dist/esm/interactions/useDelayGroup.native.js +42 -28
  76. package/dist/esm/interactions/useDelayGroup.native.js.map +1 -1
  77. package/dist/esm/interactions/useFocus.mjs +59 -32
  78. package/dist/esm/interactions/useFocus.mjs.map +1 -1
  79. package/dist/esm/interactions/useFocus.native.js +61 -37
  80. package/dist/esm/interactions/useFocus.native.js.map +1 -1
  81. package/dist/esm/interactions/useHover.mjs +215 -84
  82. package/dist/esm/interactions/useHover.mjs.map +1 -1
  83. package/dist/esm/interactions/useHover.native.js +240 -117
  84. package/dist/esm/interactions/useHover.native.js.map +1 -1
  85. package/dist/esm/interactions/useInnerOffset.mjs +61 -39
  86. package/dist/esm/interactions/useInnerOffset.mjs.map +1 -1
  87. package/dist/esm/interactions/useInnerOffset.native.js +61 -40
  88. package/dist/esm/interactions/useInnerOffset.native.js.map +1 -1
  89. package/dist/esm/interactions/useInteractions.mjs +48 -21
  90. package/dist/esm/interactions/useInteractions.mjs.map +1 -1
  91. package/dist/esm/interactions/useInteractions.native.js +121 -71
  92. package/dist/esm/interactions/useInteractions.native.js.map +1 -1
  93. package/dist/esm/interactions/useListNavigation.mjs +331 -168
  94. package/dist/esm/interactions/useListNavigation.mjs.map +1 -1
  95. package/dist/esm/interactions/useListNavigation.native.js +335 -201
  96. package/dist/esm/interactions/useListNavigation.native.js.map +1 -1
  97. package/dist/esm/interactions/useRole.mjs +59 -51
  98. package/dist/esm/interactions/useRole.mjs.map +1 -1
  99. package/dist/esm/interactions/useRole.native.js +82 -76
  100. package/dist/esm/interactions/useRole.native.js.map +1 -1
  101. package/dist/esm/interactions/useTypeahead.mjs +100 -52
  102. package/dist/esm/interactions/useTypeahead.mjs.map +1 -1
  103. package/dist/esm/interactions/useTypeahead.native.js +107 -64
  104. package/dist/esm/interactions/useTypeahead.native.js.map +1 -1
  105. package/dist/esm/interactions/utils.mjs +56 -28
  106. package/dist/esm/interactions/utils.mjs.map +1 -1
  107. package/dist/esm/interactions/utils.native.js +81 -44
  108. package/dist/esm/interactions/utils.native.js.map +1 -1
  109. package/dist/esm/middleware/inner.mjs +54 -43
  110. package/dist/esm/middleware/inner.mjs.map +1 -1
  111. package/dist/esm/middleware/inner.native.js +61 -52
  112. package/dist/esm/middleware/inner.native.js.map +1 -1
  113. package/dist/esm/useFloating.mjs +22 -21
  114. package/dist/esm/useFloating.mjs.map +1 -1
  115. package/dist/esm/useFloating.native.js +24 -24
  116. package/dist/esm/useFloating.native.js.map +1 -1
  117. package/package.json +3 -3
@@ -5,33 +5,35 @@ 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: !0
11
- });
12
- },
13
- __copyProps = (to, from, except, desc) => {
14
- if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
8
+ for (var name in all) __defProp(target, name, {
9
+ get: all[name],
10
+ enumerable: true
11
+ });
12
+ };
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, {
15
16
  get: () => from[key],
16
17
  enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
17
18
  });
18
- return to;
19
- };
19
+ }
20
+ return to;
21
+ };
20
22
  var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
21
- value: !0
23
+ value: true
22
24
  }), mod);
23
25
  var useListNavigation_exports = {};
24
26
  __export(useListNavigation_exports, {
25
27
  useListNavigation: () => useListNavigation
26
28
  });
27
29
  module.exports = __toCommonJS(useListNavigation_exports);
28
- var import_react = require("react"),
29
- import_use_event = require("@hanzogui/use-event"),
30
- import_utils = require("./utils.native.js"),
31
- ARROW_UP = "ArrowUp",
32
- ARROW_DOWN = "ArrowDown",
33
- ARROW_LEFT = "ArrowLeft",
34
- ARROW_RIGHT = "ArrowRight";
30
+ var import_react = require("react");
31
+ var import_use_event = require("@hanzogui/use-event");
32
+ var import_utils = require("./utils.native.js");
33
+ var ARROW_UP = "ArrowUp";
34
+ var ARROW_DOWN = "ArrowDown";
35
+ var ARROW_LEFT = "ArrowLeft";
36
+ var ARROW_RIGHT = "ArrowRight";
35
37
  function doSwitch(orientation, vertical, horizontal) {
36
38
  switch (orientation) {
37
39
  case "vertical":
@@ -43,59 +45,59 @@ function doSwitch(orientation, vertical, horizontal) {
43
45
  }
44
46
  }
45
47
  function isMainOrientationKey(key, orientation) {
46
- var vertical = key === ARROW_UP || key === ARROW_DOWN,
47
- horizontal = key === ARROW_LEFT || key === ARROW_RIGHT;
48
+ var vertical = key === ARROW_UP || key === ARROW_DOWN;
49
+ var horizontal = key === ARROW_LEFT || key === ARROW_RIGHT;
48
50
  return doSwitch(orientation, vertical, horizontal);
49
51
  }
50
52
  function isMainOrientationToEndKey(key, orientation, rtl) {
51
- var vertical = key === ARROW_DOWN,
52
- horizontal = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
53
+ var vertical = key === ARROW_DOWN;
54
+ var horizontal = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
53
55
  return doSwitch(orientation, vertical, horizontal) || key === "Enter" || key === " " || key === "";
54
56
  }
55
57
  function isCrossOrientationOpenKey(key, orientation, rtl) {
56
- var vertical = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT,
57
- horizontal = key === ARROW_DOWN;
58
+ var vertical = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;
59
+ var horizontal = key === ARROW_DOWN;
58
60
  return doSwitch(orientation, vertical, horizontal);
59
61
  }
60
62
  function isCrossOrientationCloseKey(key, orientation, rtl) {
61
- var vertical = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT,
62
- horizontal = key === ARROW_UP;
63
+ var vertical = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT;
64
+ var horizontal = key === ARROW_UP;
63
65
  return doSwitch(orientation, vertical, horizontal);
64
66
  }
65
67
  function useListNavigation(context, props) {
66
68
  var {
67
- open,
68
- onOpenChange,
69
- elements
70
- } = context,
71
- {
72
- listRef,
73
- activeIndex,
74
- onNavigate: unstable_onNavigate = function () {},
75
- enabled = !0,
76
- selectedIndex = null,
77
- allowEscape = !1,
78
- loop = !1,
79
- nested = !1,
80
- rtl = !1,
81
- virtual = !1,
82
- focusItemOnOpen = "auto",
83
- focusItemOnHover = !0,
84
- openOnArrowKeyDown = !0,
85
- disabledIndices = void 0,
86
- orientation = "vertical",
87
- scrollItemIntoView = !0
88
- } = props,
89
- typeableComboboxReference = (0, import_utils.isTypeableCombobox)(elements.domReference),
90
- focusItemOnOpenRef = (0, import_react.useRef)(focusItemOnOpen),
91
- indexRef = (0, import_react.useRef)(selectedIndex ?? -1),
92
- keyRef = (0, import_react.useRef)(null),
93
- isPointerModalityRef = (0, import_react.useRef)(!0),
94
- previousMountedRef = (0, import_react.useRef)(!!elements.floating),
95
- previousOpenRef = (0, import_react.useRef)(open),
96
- forceSyncFocusRef = (0, import_react.useRef)(!1),
97
- forceScrollIntoViewRef = (0, import_react.useRef)(!1),
98
- disabledIndicesRef = (0, import_react.useRef)(disabledIndices);
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);
99
101
  disabledIndicesRef.current = disabledIndices;
100
102
  var latestOpenRef = (0, import_react.useRef)(open);
101
103
  latestOpenRef.current = open;
@@ -103,189 +105,323 @@ function useListNavigation(context, props) {
103
105
  scrollItemIntoViewRef.current = scrollItemIntoView;
104
106
  var selectedIndexRef = (0, import_react.useRef)(selectedIndex);
105
107
  selectedIndexRef.current = selectedIndex;
106
- var stableOnNavigate = (0, import_use_event.useEvent)(unstable_onNavigate),
107
- [activeId, setActiveId] = (0, import_react.useState)(),
108
- onNavigate = (0, import_use_event.useEvent)(function () {
109
- stableOnNavigate(indexRef.current === -1 ? null : indexRef.current);
110
- }),
111
- previousOnNavigateRef = (0, import_react.useRef)(onNavigate),
112
- focusItem = (0, import_use_event.useEvent)(function () {
113
- function runFocus(item2) {
114
- virtual ? setActiveId(item2.id) : (0, import_utils.enqueueFocus)(item2, {
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, {
115
120
  sync: forceSyncFocusRef.current,
116
- preventScroll: !0
121
+ preventScroll: true
117
122
  });
118
123
  }
119
- var initialItem = listRef.current[indexRef.current],
120
- forceScrollIntoView = forceScrollIntoViewRef.current;
121
- initialItem && runFocus(initialItem);
122
- var scheduler = forceSyncFocusRef.current ? function (v) {
123
- return v();
124
- } : requestAnimationFrame;
125
- scheduler(function () {
126
- var waitedItem = listRef.current[indexRef.current] || initialItem;
127
- if (waitedItem) {
128
- initialItem || runFocus(waitedItem);
129
- var scrollIntoViewOptions = scrollItemIntoViewRef.current,
130
- shouldScrollIntoView = scrollIntoViewOptions && waitedItem && (forceScrollIntoView || !isPointerModalityRef.current);
131
- if (shouldScrollIntoView) {
132
- var _waitedItem_scrollIntoView;
133
- (_waitedItem_scrollIntoView = waitedItem.scrollIntoView) === null || _waitedItem_scrollIntoView === void 0 || _waitedItem_scrollIntoView.call(waitedItem, typeof scrollIntoViewOptions == "boolean" ? {
134
- block: "nearest",
135
- inline: "nearest"
136
- } : scrollIntoViewOptions);
137
- }
138
- }
139
- });
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
+ }
140
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]);
141
163
  (0, import_react.useLayoutEffect)(function () {
142
- enabled && (open && elements.floating ? focusItemOnOpenRef.current && selectedIndex != null && (forceScrollIntoViewRef.current = !0, indexRef.current = selectedIndex, onNavigate()) : previousMountedRef.current && (indexRef.current = -1, previousOnNavigateRef.current()));
143
- }, [enabled, open, elements.floating, selectedIndex, onNavigate]), (0, import_react.useLayoutEffect)(function () {
144
- if (enabled && open && elements.floating) if (activeIndex == null) {
145
- if (forceSyncFocusRef.current = !1, selectedIndexRef.current != null) return;
146
- if (previousMountedRef.current && (indexRef.current = -1, focusItem()), (!previousOpenRef.current || !previousMountedRef.current) && focusItemOnOpenRef.current && (keyRef.current != null || focusItemOnOpenRef.current === !0 && keyRef.current == null)) {
147
- var runs = 0,
148
- waitForListPopulated = function () {
149
- if (listRef.current[0] == null) {
150
- if (runs < 2) {
151
- var scheduler = runs ? requestAnimationFrame : queueMicrotask;
152
- scheduler(waitForListPopulated);
153
- }
154
- runs++;
155
- } else 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), keyRef.current = null, onNavigate();
156
- };
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
+ };
157
191
  waitForListPopulated();
158
192
  }
159
- } else (0, import_utils.isIndexOutOfListBounds)(listRef, activeIndex) || (indexRef.current = activeIndex, focusItem(), forceScrollIntoViewRef.current = !1);
160
- }, [enabled, open, elements.floating, activeIndex, selectedIndexRef, nested, listRef, orientation, rtl, onNavigate, focusItem, disabledIndicesRef]), (0, import_react.useLayoutEffect)(function () {
161
- previousOnNavigateRef.current = onNavigate, previousOpenRef.current = open, previousMountedRef.current = !!elements.floating;
162
- }), (0, import_react.useLayoutEffect)(function () {
163
- open || (keyRef.current = null, focusItemOnOpenRef.current = focusItemOnOpen);
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
+ }
164
209
  }, [open, focusItemOnOpen]);
165
- var hasActiveIndex = activeIndex != null,
166
- commonOnKeyDown = (0, import_use_event.useEvent)(function (event) {
167
- if (isPointerModalityRef.current = !1, forceSyncFocusRef.current = !0, event.which !== 229 && !(!latestOpenRef.current && event.currentTarget === elements.floating)) {
168
- if (nested && isCrossOrientationCloseKey(event.key, orientation, rtl)) {
169
- (0, import_utils.stopEvent)(event), onOpenChange(!1, event.nativeEvent, "list-navigation"), (0, import_utils.isHTMLElement)(elements.domReference) && elements.domReference.focus();
170
- return;
171
- }
172
- var currentIndex = indexRef.current,
173
- minIndex = (0, import_utils.getMinListIndex)(listRef, disabledIndices),
174
- maxIndex = (0, import_utils.getMaxListIndex)(listRef, disabledIndices);
175
- if (typeableComboboxReference || (event.key === "Home" && ((0, import_utils.stopEvent)(event), indexRef.current = minIndex, onNavigate()), event.key === "End" && ((0, import_utils.stopEvent)(event), indexRef.current = maxIndex, onNavigate())), isMainOrientationKey(event.key, orientation)) {
176
- if ((0, import_utils.stopEvent)(event), open && !virtual && (0, import_utils.activeElement)(event.currentTarget.ownerDocument) === event.currentTarget) {
177
- indexRef.current = isMainOrientationToEndKey(event.key, orientation, rtl) ? minIndex : maxIndex, onNavigate();
178
- return;
179
- }
180
- isMainOrientationToEndKey(event.key, orientation, rtl) ? loop ? indexRef.current = currentIndex >= maxIndex ? allowEscape && currentIndex !== listRef.current.length ? -1 : minIndex : (0, import_utils.findNonDisabledListIndex)(listRef, {
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, {
181
253
  startingIndex: currentIndex,
182
254
  disabledIndices
183
- }) : indexRef.current = Math.min(maxIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {
255
+ });
256
+ } else {
257
+ indexRef.current = Math.min(maxIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {
184
258
  startingIndex: currentIndex,
185
259
  disabledIndices
186
- })) : loop ? indexRef.current = currentIndex <= minIndex ? allowEscape && currentIndex !== -1 ? listRef.current.length : maxIndex : (0, import_utils.findNonDisabledListIndex)(listRef, {
260
+ }));
261
+ }
262
+ } else {
263
+ if (loop) {
264
+ indexRef.current = currentIndex <= minIndex ? allowEscape && currentIndex !== -1 ? listRef.current.length : maxIndex : (0, import_utils.findNonDisabledListIndex)(listRef, {
187
265
  startingIndex: currentIndex,
188
- decrement: !0,
266
+ decrement: true,
189
267
  disabledIndices
190
- }) : indexRef.current = Math.max(minIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {
268
+ });
269
+ } else {
270
+ indexRef.current = Math.max(minIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {
191
271
  startingIndex: currentIndex,
192
- decrement: !0,
272
+ decrement: true,
193
273
  disabledIndices
194
- })), (0, import_utils.isIndexOutOfListBounds)(listRef, indexRef.current) && (indexRef.current = -1), onNavigate();
274
+ }));
195
275
  }
196
276
  }
197
- }),
198
- ariaActiveDescendantProp = (0, import_react.useMemo)(function () {
199
- return virtual && open && hasActiveIndex && {
200
- "aria-activedescendant": activeId
201
- };
202
- }, [virtual, open, hasActiveIndex, activeId]),
203
- floating = (0, import_react.useMemo)(function () {
204
- return {
205
- "aria-orientation": orientation === "both" ? void 0 : orientation,
206
- ...(typeableComboboxReference ? {} : ariaActiveDescendantProp),
207
- onKeyDown: commonOnKeyDown,
208
- onPointerMove() {
209
- isPointerModalityRef.current = !0;
210
- }
211
- };
212
- }, [ariaActiveDescendantProp, commonOnKeyDown, orientation, typeableComboboxReference]),
213
- reference = (0, import_react.useMemo)(function () {
214
- function checkVirtualMouse(event) {
215
- focusItemOnOpen === "auto" && (0, import_utils.isVirtualClick)(event.nativeEvent) && (focusItemOnOpenRef.current = !0);
277
+ if ((0, import_utils.isIndexOutOfListBounds)(listRef, indexRef.current)) {
278
+ indexRef.current = -1;
216
279
  }
217
- function checkVirtualPointer(event) {
218
- focusItemOnOpenRef.current = focusItemOnOpen, focusItemOnOpen === "auto" && (0, import_utils.isVirtualPointerEvent)(event.nativeEvent) && (focusItemOnOpenRef.current = !0);
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;
219
295
  }
220
- return {
221
- ...ariaActiveDescendantProp,
222
- onKeyDown(event) {
223
- isPointerModalityRef.current = !1;
224
- var isArrowKey = event.key.startsWith("Arrow"),
225
- isCrossOpenKey = isCrossOrientationOpenKey(event.key, orientation, rtl),
226
- isMainKey = isMainOrientationKey(event.key, orientation),
227
- isNavigationKey = (nested ? isCrossOpenKey : isMainKey) || event.key === "Enter" || event.key.trim() === "";
228
- if (virtual && open) return commonOnKeyDown(event);
229
- if (!(!open && !openOnArrowKeyDown && isArrowKey)) {
230
- if (isNavigationKey && (keyRef.current = event.key), nested) {
231
- isCrossOpenKey && ((0, import_utils.stopEvent)(event), open ? (indexRef.current = (0, import_utils.getMinListIndex)(listRef, disabledIndicesRef.current), onNavigate()) : onOpenChange(!0, event.nativeEvent, "list-navigation"));
232
- return;
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");
233
335
  }
234
- isMainKey && (selectedIndex != null && (indexRef.current = selectedIndex), (0, import_utils.stopEvent)(event), !open && openOnArrowKeyDown ? onOpenChange(!0, event.nativeEvent, "list-navigation") : commonOnKeyDown(event), open && onNavigate());
235
336
  }
236
- },
237
- onFocus() {
238
- open && !virtual && (indexRef.current = -1, onNavigate());
239
- },
240
- onPointerDown: checkVirtualPointer,
241
- onPointerEnter: checkVirtualPointer,
242
- onMouseDown: checkVirtualMouse,
243
- onClick: checkVirtualMouse
244
- };
245
- }, [ariaActiveDescendantProp, commonOnKeyDown, disabledIndicesRef, focusItemOnOpen, listRef, nested, onNavigate, onOpenChange, open, openOnArrowKeyDown, orientation, rtl, selectedIndex, virtual]),
246
- item = (0, import_react.useMemo)(function () {
247
- function syncCurrentTarget(currentTarget) {
248
- if (latestOpenRef.current) {
249
- var index = listRef.current.indexOf(currentTarget);
250
- index !== -1 && indexRef.current !== index && (indexRef.current = index, onNavigate());
337
+ return;
251
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();
252
373
  }
253
- var itemProps = {
254
- onFocus(param) {
255
- var {
256
- currentTarget
257
- } = param;
258
- forceSyncFocusRef.current = !0, syncCurrentTarget(currentTarget);
259
- },
260
- onClick: function (param) {
261
- var {
262
- currentTarget
263
- } = param;
264
- return currentTarget.focus({
265
- preventScroll: !0
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
266
419
  });
267
- },
268
- // safari
269
- onMouseMove(param) {
270
- var {
271
- currentTarget
272
- } = param;
273
- forceSyncFocusRef.current = !0, forceScrollIntoViewRef.current = !1, focusItemOnHover && syncCurrentTarget(currentTarget);
274
- },
275
- onPointerLeave(param) {
276
- var {
277
- pointerType
278
- } = param;
279
- if (!(!isPointerModalityRef.current || pointerType === "touch") && (forceSyncFocusRef.current = !0, !!focusItemOnHover && (indexRef.current = -1, onNavigate(), !virtual))) {
280
- var _elements_floating;
281
- (_elements_floating = elements.floating) === null || _elements_floating === void 0 || _elements_floating.focus({
282
- preventScroll: !0
283
- });
284
- }
285
420
  }
286
- };
287
- return itemProps;
288
- }, [latestOpenRef, focusItemOnHover, listRef, onNavigate, virtual, elements.floating]);
421
+ }
422
+ };
423
+ return itemProps;
424
+ }, [latestOpenRef, focusItemOnHover, listRef, onNavigate, virtual, elements.floating]);
289
425
  return (0, import_react.useMemo)(function () {
290
426
  return enabled ? {
291
427
  reference,