@hanzogui/floating 2.0.0-rc.41-hanzoai.5
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.
- package/LICENSE +21 -0
- package/dist/cjs/Floating.cjs +20 -0
- package/dist/cjs/Floating.native.js +39 -0
- package/dist/cjs/Floating.native.js.map +1 -0
- package/dist/cjs/index.cjs +73 -0
- package/dist/cjs/index.native.js +76 -0
- package/dist/cjs/index.native.js.map +1 -0
- package/dist/cjs/interactions/PopupTriggerMap.cjs +49 -0
- package/dist/cjs/interactions/PopupTriggerMap.native.js +97 -0
- package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -0
- package/dist/cjs/interactions/createFloatingEvents.cjs +50 -0
- package/dist/cjs/interactions/createFloatingEvents.native.js +56 -0
- package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -0
- package/dist/cjs/interactions/safePolygon.cjs +273 -0
- package/dist/cjs/interactions/safePolygon.native.js +284 -0
- package/dist/cjs/interactions/safePolygon.native.js.map +1 -0
- package/dist/cjs/interactions/types.cjs +18 -0
- package/dist/cjs/interactions/types.native.js +21 -0
- package/dist/cjs/interactions/types.native.js.map +1 -0
- package/dist/cjs/interactions/useClick.cjs +124 -0
- package/dist/cjs/interactions/useClick.native.js +132 -0
- package/dist/cjs/interactions/useClick.native.js.map +1 -0
- package/dist/cjs/interactions/useDelayGroup.cjs +115 -0
- package/dist/cjs/interactions/useDelayGroup.native.js +125 -0
- package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -0
- package/dist/cjs/interactions/useFocus.cjs +130 -0
- package/dist/cjs/interactions/useFocus.native.js +139 -0
- package/dist/cjs/interactions/useFocus.native.js.map +1 -0
- package/dist/cjs/interactions/useHover.cjs +357 -0
- package/dist/cjs/interactions/useHover.native.js +373 -0
- package/dist/cjs/interactions/useHover.native.js.map +1 -0
- package/dist/cjs/interactions/useInnerOffset.cjs +128 -0
- package/dist/cjs/interactions/useInnerOffset.native.js +141 -0
- package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -0
- package/dist/cjs/interactions/useInteractions.cjs +105 -0
- package/dist/cjs/interactions/useInteractions.native.js +216 -0
- package/dist/cjs/interactions/useInteractions.native.js.map +1 -0
- package/dist/cjs/interactions/useListNavigation.cjs +418 -0
- package/dist/cjs/interactions/useListNavigation.native.js +433 -0
- package/dist/cjs/interactions/useListNavigation.native.js.map +1 -0
- package/dist/cjs/interactions/useRole.cjs +122 -0
- package/dist/cjs/interactions/useRole.native.js +136 -0
- package/dist/cjs/interactions/useRole.native.js.map +1 -0
- package/dist/cjs/interactions/useTypeahead.cjs +143 -0
- package/dist/cjs/interactions/useTypeahead.native.js +159 -0
- package/dist/cjs/interactions/useTypeahead.native.js.map +1 -0
- package/dist/cjs/interactions/utils.cjs +208 -0
- package/dist/cjs/interactions/utils.native.js +227 -0
- package/dist/cjs/interactions/utils.native.js.map +1 -0
- package/dist/cjs/middleware/inner.cjs +118 -0
- package/dist/cjs/middleware/inner.native.js +130 -0
- package/dist/cjs/middleware/inner.native.js.map +1 -0
- package/dist/cjs/useFloating.cjs +64 -0
- package/dist/cjs/useFloating.native.js +69 -0
- package/dist/cjs/useFloating.native.js.map +1 -0
- package/dist/esm/Floating.mjs +2 -0
- package/dist/esm/Floating.mjs.map +1 -0
- package/dist/esm/Floating.native.js +8 -0
- package/dist/esm/Floating.native.js.map +1 -0
- package/dist/esm/index.js +18 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/index.mjs +18 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/esm/index.native.js +18 -0
- package/dist/esm/index.native.js.map +1 -0
- package/dist/esm/interactions/PopupTriggerMap.mjs +24 -0
- package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -0
- package/dist/esm/interactions/PopupTriggerMap.native.js +69 -0
- package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -0
- package/dist/esm/interactions/createFloatingEvents.mjs +25 -0
- package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -0
- package/dist/esm/interactions/createFloatingEvents.native.js +28 -0
- package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -0
- package/dist/esm/interactions/safePolygon.mjs +248 -0
- package/dist/esm/interactions/safePolygon.mjs.map +1 -0
- package/dist/esm/interactions/safePolygon.native.js +256 -0
- package/dist/esm/interactions/safePolygon.native.js.map +1 -0
- package/dist/esm/interactions/types.mjs +2 -0
- package/dist/esm/interactions/types.mjs.map +1 -0
- package/dist/esm/interactions/types.native.js +2 -0
- package/dist/esm/interactions/types.native.js.map +1 -0
- package/dist/esm/interactions/useClick.mjs +99 -0
- package/dist/esm/interactions/useClick.mjs.map +1 -0
- package/dist/esm/interactions/useClick.native.js +104 -0
- package/dist/esm/interactions/useClick.native.js.map +1 -0
- package/dist/esm/interactions/useDelayGroup.mjs +77 -0
- package/dist/esm/interactions/useDelayGroup.mjs.map +1 -0
- package/dist/esm/interactions/useDelayGroup.native.js +84 -0
- package/dist/esm/interactions/useDelayGroup.native.js.map +1 -0
- package/dist/esm/interactions/useFocus.mjs +105 -0
- package/dist/esm/interactions/useFocus.mjs.map +1 -0
- package/dist/esm/interactions/useFocus.native.js +111 -0
- package/dist/esm/interactions/useFocus.native.js.map +1 -0
- package/dist/esm/interactions/useHover.mjs +320 -0
- package/dist/esm/interactions/useHover.mjs.map +1 -0
- package/dist/esm/interactions/useHover.native.js +333 -0
- package/dist/esm/interactions/useHover.native.js.map +1 -0
- package/dist/esm/interactions/useInnerOffset.mjs +92 -0
- package/dist/esm/interactions/useInnerOffset.mjs.map +1 -0
- package/dist/esm/interactions/useInnerOffset.native.js +102 -0
- package/dist/esm/interactions/useInnerOffset.native.js.map +1 -0
- package/dist/esm/interactions/useInteractions.mjs +80 -0
- package/dist/esm/interactions/useInteractions.mjs.map +1 -0
- package/dist/esm/interactions/useInteractions.native.js +188 -0
- package/dist/esm/interactions/useInteractions.native.js.map +1 -0
- package/dist/esm/interactions/useListNavigation.mjs +393 -0
- package/dist/esm/interactions/useListNavigation.mjs.map +1 -0
- package/dist/esm/interactions/useListNavigation.native.js +405 -0
- package/dist/esm/interactions/useListNavigation.native.js.map +1 -0
- package/dist/esm/interactions/useRole.mjs +86 -0
- package/dist/esm/interactions/useRole.mjs.map +1 -0
- package/dist/esm/interactions/useRole.native.js +97 -0
- package/dist/esm/interactions/useRole.native.js.map +1 -0
- package/dist/esm/interactions/useTypeahead.mjs +118 -0
- package/dist/esm/interactions/useTypeahead.mjs.map +1 -0
- package/dist/esm/interactions/useTypeahead.native.js +131 -0
- package/dist/esm/interactions/useTypeahead.native.js.map +1 -0
- package/dist/esm/interactions/utils.mjs +162 -0
- package/dist/esm/interactions/utils.mjs.map +1 -0
- package/dist/esm/interactions/utils.native.js +178 -0
- package/dist/esm/interactions/utils.native.js.map +1 -0
- package/dist/esm/middleware/inner.mjs +82 -0
- package/dist/esm/middleware/inner.mjs.map +1 -0
- package/dist/esm/middleware/inner.native.js +91 -0
- package/dist/esm/middleware/inner.native.js.map +1 -0
- package/dist/esm/useFloating.mjs +27 -0
- package/dist/esm/useFloating.mjs.map +1 -0
- package/dist/esm/useFloating.native.js +29 -0
- package/dist/esm/useFloating.native.js.map +1 -0
- package/package.json +50 -0
- package/src/Floating.native.tsx +45 -0
- package/src/Floating.tsx +1 -0
- package/src/index.ts +116 -0
- package/src/interactions/PopupTriggerMap.ts +30 -0
- package/src/interactions/createFloatingEvents.ts +34 -0
- package/src/interactions/safePolygon.ts +500 -0
- package/src/interactions/types.ts +165 -0
- package/src/interactions/useClick.ts +148 -0
- package/src/interactions/useDelayGroup.ts +114 -0
- package/src/interactions/useFocus.ts +164 -0
- package/src/interactions/useHover.ts +453 -0
- package/src/interactions/useInnerOffset.ts +116 -0
- package/src/interactions/useInteractions.ts +101 -0
- package/src/interactions/useListNavigation.ts +578 -0
- package/src/interactions/useRole.ts +103 -0
- package/src/interactions/useTypeahead.ts +173 -0
- package/src/interactions/utils.ts +234 -0
- package/src/middleware/inner.ts +141 -0
- package/src/useFloating.tsx +53 -0
- package/types/Floating.d.ts +2 -0
- package/types/Floating.d.ts.map +1 -0
- package/types/Floating.native.d.ts +41 -0
- package/types/Floating.native.d.ts.map +1 -0
- package/types/index.d.ts +19 -0
- package/types/index.d.ts.map +1 -0
- package/types/interactions/PopupTriggerMap.d.ts +8 -0
- package/types/interactions/PopupTriggerMap.d.ts.map +1 -0
- package/types/interactions/createFloatingEvents.d.ts +7 -0
- package/types/interactions/createFloatingEvents.d.ts.map +1 -0
- package/types/interactions/safePolygon.d.ts +4 -0
- package/types/interactions/safePolygon.d.ts.map +1 -0
- package/types/interactions/types.d.ts +123 -0
- package/types/interactions/types.d.ts.map +1 -0
- package/types/interactions/useClick.d.ts +3 -0
- package/types/interactions/useClick.d.ts.map +1 -0
- package/types/interactions/useDelayGroup.d.ts +23 -0
- package/types/interactions/useDelayGroup.d.ts.map +1 -0
- package/types/interactions/useFocus.d.ts +3 -0
- package/types/interactions/useFocus.d.ts.map +1 -0
- package/types/interactions/useHover.d.ts +6 -0
- package/types/interactions/useHover.d.ts.map +1 -0
- package/types/interactions/useInnerOffset.d.ts +3 -0
- package/types/interactions/useInnerOffset.d.ts.map +1 -0
- package/types/interactions/useInteractions.d.ts +8 -0
- package/types/interactions/useInteractions.d.ts.map +1 -0
- package/types/interactions/useListNavigation.d.ts +3 -0
- package/types/interactions/useListNavigation.d.ts.map +1 -0
- package/types/interactions/useRole.d.ts +3 -0
- package/types/interactions/useRole.d.ts.map +1 -0
- package/types/interactions/useTypeahead.d.ts +3 -0
- package/types/interactions/useTypeahead.d.ts.map +1 -0
- package/types/interactions/utils.d.ts +46 -0
- package/types/interactions/utils.d.ts.map +1 -0
- package/types/middleware/inner.d.ts +14 -0
- package/types/middleware/inner.d.ts.map +1 -0
- package/types/useFloating.d.ts +28 -0
- package/types/useFloating.d.ts.map +1 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
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, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
}), mod);
|
|
25
|
+
var useListNavigation_exports = {};
|
|
26
|
+
__export(useListNavigation_exports, {
|
|
27
|
+
useListNavigation: () => useListNavigation
|
|
28
|
+
});
|
|
29
|
+
module.exports = __toCommonJS(useListNavigation_exports);
|
|
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";
|
|
37
|
+
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
|
+
}
|
|
46
|
+
}
|
|
47
|
+
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);
|
|
51
|
+
}
|
|
52
|
+
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 === "";
|
|
56
|
+
}
|
|
57
|
+
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);
|
|
61
|
+
}
|
|
62
|
+
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);
|
|
66
|
+
}
|
|
67
|
+
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]);
|
|
432
|
+
}
|
|
433
|
+
//# sourceMappingURL=useListNavigation.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__defProp","Object","defineProperty","__getOwnPropDesc","getOwnPropertyDescriptor","__getOwnPropNames","getOwnPropertyNames","__hasOwnProp","prototype","hasOwnProperty","__export","target","all","name","get","enumerable","__copyProps","to","from","except","desc","key","call","__toCommonJS","mod","value","useListNavigation_exports","useListNavigation","module","exports","import_react","require","import_use_event","import_utils","ARROW_UP","ARROW_DOWN","ARROW_LEFT","ARROW_RIGHT","doSwitch","orientation","vertical","horizontal","isMainOrientationKey","isMainOrientationToEndKey","rtl","isCrossOrientationOpenKey","isCrossOrientationCloseKey","context","props","open","onOpenChange","elements","listRef","activeIndex","onNavigate","unstable_onNavigate","enabled","selectedIndex","allowEscape","loop","nested","virtual","focusItemOnOpen","focusItemOnHover","openOnArrowKeyDown","disabledIndices","scrollItemIntoView","typeableComboboxReference","isTypeableCombobox","domReference","focusItemOnOpenRef","useRef","indexRef","keyRef","isPointerModalityRef","previousMountedRef","floating","previousOpenRef","forceSyncFocusRef","forceScrollIntoViewRef","disabledIndicesRef","current","latestOpenRef","scrollItemIntoViewRef","selectedIndexRef","stableOnNavigate","useEvent","activeId","setActiveId","useState","previousOnNavigateRef","focusItem","runFocus","item2","id","enqueueFocus","sync","preventScroll","initialItem","forceScrollIntoView","scheduler","v","requestAnimationFrame","waitedItem","scrollIntoViewOptions","shouldScrollIntoView","_waitedItem_scrollIntoView","scrollIntoView","block","inline","useLayoutEffect","runs","waitForListPopulated","queueMicrotask","getMinListIndex","getMaxListIndex","isIndexOutOfListBounds","hasActiveIndex","commonOnKeyDown","event","which","currentTarget","stopEvent","nativeEvent","isHTMLElement","focus","currentIndex","minIndex","maxIndex","activeElement","ownerDocument","length","findNonDisabledListIndex","startingIndex","Math","min","decrement","max","ariaActiveDescendantProp","useMemo","onKeyDown","onPointerMove","reference","checkVirtualMouse","isVirtualClick","checkVirtualPointer","isVirtualPointerEvent","isArrowKey","startsWith","isCrossOpenKey","isMainKey","isNavigationKey","trim","onFocus","onPointerDown","onPointerEnter","onMouseDown","onClick","item","syncCurrentTarget","index","indexOf","itemProps","param","onMouseMove","onPointerLeave","pointerType","_elements_floating"],"sources":["useListNavigation.native.js"],"sourcesContent":["\"use strict\";\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __export = (target, all) => {\n for (var name in all)\n __defProp(target, name, { get: all[name], enumerable: true });\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === \"object\" || typeof from === \"function\") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toCommonJS = (mod) => __copyProps(__defProp({}, \"__esModule\", { value: true }), mod);\nvar useListNavigation_exports = {};\n__export(useListNavigation_exports, {\n useListNavigation: () => useListNavigation\n});\nmodule.exports = __toCommonJS(useListNavigation_exports);\nvar import_react = require(\"react\");\nvar import_use_event = require(\"@hanzogui/use-event\");\nvar import_utils = require(\"./utils\");\nvar ARROW_UP = \"ArrowUp\";\nvar ARROW_DOWN = \"ArrowDown\";\nvar ARROW_LEFT = \"ArrowLeft\";\nvar ARROW_RIGHT = \"ArrowRight\";\nfunction doSwitch(orientation, vertical, horizontal) {\n switch (orientation) {\n case \"vertical\":\n return vertical;\n case \"horizontal\":\n return horizontal;\n default:\n return vertical || horizontal;\n }\n}\nfunction isMainOrientationKey(key, orientation) {\n var vertical = key === ARROW_UP || key === ARROW_DOWN;\n var horizontal = key === ARROW_LEFT || key === ARROW_RIGHT;\n return doSwitch(orientation, vertical, horizontal);\n}\nfunction isMainOrientationToEndKey(key, orientation, rtl) {\n var vertical = key === ARROW_DOWN;\n var horizontal = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;\n return doSwitch(orientation, vertical, horizontal) || key === \"Enter\" || key === \" \" || key === \"\";\n}\nfunction isCrossOrientationOpenKey(key, orientation, rtl) {\n var vertical = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT;\n var horizontal = key === ARROW_DOWN;\n return doSwitch(orientation, vertical, horizontal);\n}\nfunction isCrossOrientationCloseKey(key, orientation, rtl) {\n var vertical = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT;\n var horizontal = key === ARROW_UP;\n return doSwitch(orientation, vertical, horizontal);\n}\nfunction useListNavigation(context, props) {\n var { open, onOpenChange, elements } = context;\n var { listRef, activeIndex, onNavigate: unstable_onNavigate = function() {\n }, 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;\n var typeableComboboxReference = (0, import_utils.isTypeableCombobox)(elements.domReference);\n var focusItemOnOpenRef = (0, import_react.useRef)(focusItemOnOpen);\n var indexRef = (0, import_react.useRef)(selectedIndex !== null && selectedIndex !== void 0 ? selectedIndex : -1);\n var keyRef = (0, import_react.useRef)(null);\n var isPointerModalityRef = (0, import_react.useRef)(true);\n var previousMountedRef = (0, import_react.useRef)(!!elements.floating);\n var previousOpenRef = (0, import_react.useRef)(open);\n var forceSyncFocusRef = (0, import_react.useRef)(false);\n var forceScrollIntoViewRef = (0, import_react.useRef)(false);\n var disabledIndicesRef = (0, import_react.useRef)(disabledIndices);\n disabledIndicesRef.current = disabledIndices;\n var latestOpenRef = (0, import_react.useRef)(open);\n latestOpenRef.current = open;\n var scrollItemIntoViewRef = (0, import_react.useRef)(scrollItemIntoView);\n scrollItemIntoViewRef.current = scrollItemIntoView;\n var selectedIndexRef = (0, import_react.useRef)(selectedIndex);\n selectedIndexRef.current = selectedIndex;\n var stableOnNavigate = (0, import_use_event.useEvent)(unstable_onNavigate);\n var [activeId, setActiveId] = (0, import_react.useState)();\n var onNavigate = (0, import_use_event.useEvent)(function() {\n stableOnNavigate(indexRef.current === -1 ? null : indexRef.current);\n });\n var previousOnNavigateRef = (0, import_react.useRef)(onNavigate);\n var focusItem = (0, import_use_event.useEvent)(function() {\n function runFocus(item2) {\n if (virtual) {\n setActiveId(item2.id);\n } else {\n (0, import_utils.enqueueFocus)(item2, {\n sync: forceSyncFocusRef.current,\n preventScroll: true\n });\n }\n }\n var initialItem = listRef.current[indexRef.current];\n var forceScrollIntoView = forceScrollIntoViewRef.current;\n if (initialItem) {\n runFocus(initialItem);\n }\n var scheduler = forceSyncFocusRef.current ? function(v) {\n return v();\n } : requestAnimationFrame;\n scheduler(function() {\n var waitedItem = listRef.current[indexRef.current] || initialItem;\n if (!waitedItem) return;\n if (!initialItem) {\n runFocus(waitedItem);\n }\n var scrollIntoViewOptions = scrollItemIntoViewRef.current;\n var shouldScrollIntoView = scrollIntoViewOptions && waitedItem && (forceScrollIntoView || !isPointerModalityRef.current);\n if (shouldScrollIntoView) {\n var _waitedItem_scrollIntoView;\n (_waitedItem_scrollIntoView = waitedItem.scrollIntoView) === null || _waitedItem_scrollIntoView === void 0 ? void 0 : _waitedItem_scrollIntoView.call(waitedItem, typeof scrollIntoViewOptions === \"boolean\" ? {\n block: \"nearest\",\n inline: \"nearest\"\n } : scrollIntoViewOptions);\n }\n });\n });\n (0, import_react.useLayoutEffect)(function() {\n if (!enabled) return;\n if (open && elements.floating) {\n if (focusItemOnOpenRef.current && selectedIndex != null) {\n forceScrollIntoViewRef.current = true;\n indexRef.current = selectedIndex;\n onNavigate();\n }\n } else if (previousMountedRef.current) {\n indexRef.current = -1;\n previousOnNavigateRef.current();\n }\n }, [\n enabled,\n open,\n elements.floating,\n selectedIndex,\n onNavigate\n ]);\n (0, import_react.useLayoutEffect)(function() {\n if (!enabled) return;\n if (!open) return;\n if (!elements.floating) return;\n if (activeIndex == null) {\n forceSyncFocusRef.current = false;\n if (selectedIndexRef.current != null) {\n return;\n }\n if (previousMountedRef.current) {\n indexRef.current = -1;\n focusItem();\n }\n if ((!previousOpenRef.current || !previousMountedRef.current) && focusItemOnOpenRef.current && (keyRef.current != null || focusItemOnOpenRef.current === true && keyRef.current == null)) {\n var runs = 0;\n var waitForListPopulated = function() {\n if (listRef.current[0] == null) {\n if (runs < 2) {\n var scheduler = runs ? requestAnimationFrame : queueMicrotask;\n scheduler(waitForListPopulated);\n }\n runs++;\n } else {\n 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);\n keyRef.current = null;\n onNavigate();\n }\n };\n waitForListPopulated();\n }\n } else if (!(0, import_utils.isIndexOutOfListBounds)(listRef, activeIndex)) {\n indexRef.current = activeIndex;\n focusItem();\n forceScrollIntoViewRef.current = false;\n }\n }, [\n enabled,\n open,\n elements.floating,\n activeIndex,\n selectedIndexRef,\n nested,\n listRef,\n orientation,\n rtl,\n onNavigate,\n focusItem,\n disabledIndicesRef\n ]);\n (0, import_react.useLayoutEffect)(function() {\n previousOnNavigateRef.current = onNavigate;\n previousOpenRef.current = open;\n previousMountedRef.current = !!elements.floating;\n });\n (0, import_react.useLayoutEffect)(function() {\n if (!open) {\n keyRef.current = null;\n focusItemOnOpenRef.current = focusItemOnOpen;\n }\n }, [\n open,\n focusItemOnOpen\n ]);\n var hasActiveIndex = activeIndex != null;\n var commonOnKeyDown = (0, import_use_event.useEvent)(function(event) {\n isPointerModalityRef.current = false;\n forceSyncFocusRef.current = true;\n if (event.which === 229) {\n return;\n }\n if (!latestOpenRef.current && event.currentTarget === elements.floating) {\n return;\n }\n if (nested && isCrossOrientationCloseKey(event.key, orientation, rtl)) {\n (0, import_utils.stopEvent)(event);\n onOpenChange(false, event.nativeEvent, \"list-navigation\");\n if ((0, import_utils.isHTMLElement)(elements.domReference)) {\n elements.domReference.focus();\n }\n return;\n }\n var currentIndex = indexRef.current;\n var minIndex = (0, import_utils.getMinListIndex)(listRef, disabledIndices);\n var maxIndex = (0, import_utils.getMaxListIndex)(listRef, disabledIndices);\n if (!typeableComboboxReference) {\n if (event.key === \"Home\") {\n (0, import_utils.stopEvent)(event);\n indexRef.current = minIndex;\n onNavigate();\n }\n if (event.key === \"End\") {\n (0, import_utils.stopEvent)(event);\n indexRef.current = maxIndex;\n onNavigate();\n }\n }\n if (isMainOrientationKey(event.key, orientation)) {\n (0, import_utils.stopEvent)(event);\n if (open && !virtual && (0, import_utils.activeElement)(event.currentTarget.ownerDocument) === event.currentTarget) {\n indexRef.current = isMainOrientationToEndKey(event.key, orientation, rtl) ? minIndex : maxIndex;\n onNavigate();\n return;\n }\n if (isMainOrientationToEndKey(event.key, orientation, rtl)) {\n if (loop) {\n indexRef.current = currentIndex >= maxIndex ? allowEscape && currentIndex !== listRef.current.length ? -1 : minIndex : (0, import_utils.findNonDisabledListIndex)(listRef, {\n startingIndex: currentIndex,\n disabledIndices\n });\n } else {\n indexRef.current = Math.min(maxIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {\n startingIndex: currentIndex,\n disabledIndices\n }));\n }\n } else {\n if (loop) {\n indexRef.current = currentIndex <= minIndex ? allowEscape && currentIndex !== -1 ? listRef.current.length : maxIndex : (0, import_utils.findNonDisabledListIndex)(listRef, {\n startingIndex: currentIndex,\n decrement: true,\n disabledIndices\n });\n } else {\n indexRef.current = Math.max(minIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {\n startingIndex: currentIndex,\n decrement: true,\n disabledIndices\n }));\n }\n }\n if ((0, import_utils.isIndexOutOfListBounds)(listRef, indexRef.current)) {\n indexRef.current = -1;\n }\n onNavigate();\n }\n });\n var ariaActiveDescendantProp = (0, import_react.useMemo)(function() {\n return virtual && open && hasActiveIndex && {\n \"aria-activedescendant\": activeId\n };\n }, [\n virtual,\n open,\n hasActiveIndex,\n activeId\n ]);\n var floating = (0, import_react.useMemo)(function() {\n return {\n \"aria-orientation\": orientation === \"both\" ? void 0 : orientation,\n ...!typeableComboboxReference ? ariaActiveDescendantProp : {},\n onKeyDown: commonOnKeyDown,\n onPointerMove() {\n isPointerModalityRef.current = true;\n }\n };\n }, [\n ariaActiveDescendantProp,\n commonOnKeyDown,\n orientation,\n typeableComboboxReference\n ]);\n var reference = (0, import_react.useMemo)(function() {\n function checkVirtualMouse(event) {\n if (focusItemOnOpen === \"auto\" && (0, import_utils.isVirtualClick)(event.nativeEvent)) {\n focusItemOnOpenRef.current = true;\n }\n }\n function checkVirtualPointer(event) {\n focusItemOnOpenRef.current = focusItemOnOpen;\n if (focusItemOnOpen === \"auto\" && (0, import_utils.isVirtualPointerEvent)(event.nativeEvent)) {\n focusItemOnOpenRef.current = true;\n }\n }\n return {\n ...ariaActiveDescendantProp,\n onKeyDown(event) {\n isPointerModalityRef.current = false;\n var isArrowKey = event.key.startsWith(\"Arrow\");\n var isCrossOpenKey = isCrossOrientationOpenKey(event.key, orientation, rtl);\n var isMainKey = isMainOrientationKey(event.key, orientation);\n var isNavigationKey = (nested ? isCrossOpenKey : isMainKey) || event.key === \"Enter\" || event.key.trim() === \"\";\n if (virtual && open) {\n return commonOnKeyDown(event);\n }\n if (!open && !openOnArrowKeyDown && isArrowKey) {\n return;\n }\n if (isNavigationKey) {\n keyRef.current = event.key;\n }\n if (nested) {\n if (isCrossOpenKey) {\n (0, import_utils.stopEvent)(event);\n if (open) {\n indexRef.current = (0, import_utils.getMinListIndex)(listRef, disabledIndicesRef.current);\n onNavigate();\n } else {\n onOpenChange(true, event.nativeEvent, \"list-navigation\");\n }\n }\n return;\n }\n if (isMainKey) {\n if (selectedIndex != null) {\n indexRef.current = selectedIndex;\n }\n (0, import_utils.stopEvent)(event);\n if (!open && openOnArrowKeyDown) {\n onOpenChange(true, event.nativeEvent, \"list-navigation\");\n } else {\n commonOnKeyDown(event);\n }\n if (open) {\n onNavigate();\n }\n }\n },\n onFocus() {\n if (open && !virtual) {\n indexRef.current = -1;\n onNavigate();\n }\n },\n onPointerDown: checkVirtualPointer,\n onPointerEnter: checkVirtualPointer,\n onMouseDown: checkVirtualMouse,\n onClick: checkVirtualMouse\n };\n }, [\n ariaActiveDescendantProp,\n commonOnKeyDown,\n disabledIndicesRef,\n focusItemOnOpen,\n listRef,\n nested,\n onNavigate,\n onOpenChange,\n open,\n openOnArrowKeyDown,\n orientation,\n rtl,\n selectedIndex,\n virtual\n ]);\n var item = (0, import_react.useMemo)(function() {\n function syncCurrentTarget(currentTarget) {\n if (!latestOpenRef.current) return;\n var index = listRef.current.indexOf(currentTarget);\n if (index !== -1 && indexRef.current !== index) {\n indexRef.current = index;\n onNavigate();\n }\n }\n var itemProps = {\n onFocus(param) {\n var { currentTarget } = param;\n forceSyncFocusRef.current = true;\n syncCurrentTarget(currentTarget);\n },\n onClick: function(param) {\n var { currentTarget } = param;\n return currentTarget.focus({\n preventScroll: true\n });\n },\n // safari\n onMouseMove(param) {\n var { currentTarget } = param;\n forceSyncFocusRef.current = true;\n forceScrollIntoViewRef.current = false;\n if (focusItemOnHover) {\n syncCurrentTarget(currentTarget);\n }\n },\n onPointerLeave(param) {\n var { pointerType } = param;\n if (!isPointerModalityRef.current || pointerType === \"touch\") {\n return;\n }\n forceSyncFocusRef.current = true;\n if (!focusItemOnHover) {\n return;\n }\n indexRef.current = -1;\n onNavigate();\n if (!virtual) {\n var _elements_floating;\n (_elements_floating = elements.floating) === null || _elements_floating === void 0 ? void 0 : _elements_floating.focus({\n preventScroll: true\n });\n }\n }\n };\n return itemProps;\n }, [\n latestOpenRef,\n focusItemOnHover,\n listRef,\n onNavigate,\n virtual,\n elements.floating\n ]);\n return (0, import_react.useMemo)(function() {\n return enabled ? {\n reference,\n floating,\n item\n } : {};\n }, [\n enabled,\n reference,\n floating,\n item\n ]);\n}\n//# sourceMappingURL=useListNavigation.js.map\n"],"mappings":"AAAA,YAAY;;AACZ,IAAIA,SAAS,GAAGC,MAAM,CAACC,cAAc;AACrC,IAAIC,gBAAgB,GAAGF,MAAM,CAACG,wBAAwB;AACtD,IAAIC,iBAAiB,GAAGJ,MAAM,CAACK,mBAAmB;AAClD,IAAIC,YAAY,GAAGN,MAAM,CAACO,SAAS,CAACC,cAAc;AAClD,IAAIC,QAAQ,GAAGA,CAACC,MAAM,EAAEC,GAAG,KAAK;EAC9B,KAAK,IAAIC,IAAI,IAAID,GAAG,EAClBZ,SAAS,CAACW,MAAM,EAAEE,IAAI,EAAE;IAAEC,GAAG,EAAEF,GAAG,CAACC,IAAI,CAAC;IAAEE,UAAU,EAAE;EAAK,CAAC,CAAC;AACjE,CAAC;AACD,IAAIC,WAAW,GAAGA,CAACC,EAAE,EAAEC,IAAI,EAAEC,MAAM,EAAEC,IAAI,KAAK;EAC5C,IAAIF,IAAI,IAAI,OAAOA,IAAI,KAAK,QAAQ,IAAI,OAAOA,IAAI,KAAK,UAAU,EAAE;IAClE,KAAK,IAAIG,GAAG,IAAIhB,iBAAiB,CAACa,IAAI,CAAC,EACrC,IAAI,CAACX,YAAY,CAACe,IAAI,CAACL,EAAE,EAAEI,GAAG,CAAC,IAAIA,GAAG,KAAKF,MAAM,EAC/CnB,SAAS,CAACiB,EAAE,EAAEI,GAAG,EAAE;MAAEP,GAAG,EAAEA,CAAA,KA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B,CAAC1C,KAAK,CAAC;YACrH5B,aAAa,EAAE;UACjB,CAAC,CAAC;QACJ;MACF;IACF,CAAC;IACD,OAAOiE,SAAS;EAClB,CAAC,EAAE,CACDhF,aAAa,EACbnB,gBAAgB,EAChBX,OAAO,EACPE,UAAU,EACVO,OAAO,EACPV,QAAQ,CAACyB,QAAQ,CAClB,CAAC;EACF,OAAO,CAAC,CAAC,EAAE9C,YAAY,CAAC6G,OAAO,EAAE,YAAW;IAC1C,OAAOnF,OAAO,GAAG;MACfsF,SAAS;MACTlE,QAAQ;MACRkF;IACF,CAAC,GAAG,CAAC,CAAC;EACR,CAAC,EAAE,CACDtG,OAAO,EACPsF,SAAS,EACTlE,QAAQ,EACRkF,IAAI,CACL,CAAC;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
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, {
|
|
16
|
+
get: () => from[key],
|
|
17
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return to;
|
|
21
|
+
};
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
28
|
+
value: mod,
|
|
29
|
+
enumerable: true
|
|
30
|
+
}) : target, mod));
|
|
31
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: true
|
|
33
|
+
}), mod);
|
|
34
|
+
var useRole_exports = {};
|
|
35
|
+
__export(useRole_exports, {
|
|
36
|
+
useRole: () => useRole
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(useRole_exports);
|
|
39
|
+
var React = __toESM(require("react"), 1);
|
|
40
|
+
const componentRoleToAriaRoleMap = /* @__PURE__ */new Map([["select", "listbox"], ["combobox", "listbox"], ["label", false]]);
|
|
41
|
+
let idCounter = 0;
|
|
42
|
+
function useRole(context, props = {}) {
|
|
43
|
+
const {
|
|
44
|
+
open,
|
|
45
|
+
elements
|
|
46
|
+
} = context;
|
|
47
|
+
const {
|
|
48
|
+
enabled = true,
|
|
49
|
+
role = "dialog"
|
|
50
|
+
} = props;
|
|
51
|
+
const defaultReferenceId = React.useId();
|
|
52
|
+
const referenceId = elements.domReference?.id || defaultReferenceId;
|
|
53
|
+
const defaultFloatingId = React.useMemo(() => `floating-${idCounter++}`, []);
|
|
54
|
+
const floatingId = React.useMemo(() => elements.floating?.id || defaultFloatingId, [elements.floating, defaultFloatingId]);
|
|
55
|
+
const ariaRole = componentRoleToAriaRoleMap.get(role) ?? role;
|
|
56
|
+
const reference = React.useMemo(() => {
|
|
57
|
+
if (ariaRole === "tooltip" || role === "label") {
|
|
58
|
+
return {
|
|
59
|
+
[`aria-${role === "label" ? "labelledby" : "describedby"}`]: open ? floatingId : void 0
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
"aria-expanded": open ? "true" : "false",
|
|
64
|
+
"aria-haspopup": ariaRole === "alertdialog" ? "dialog" : ariaRole,
|
|
65
|
+
"aria-controls": open ? floatingId : void 0,
|
|
66
|
+
...(ariaRole === "listbox" && {
|
|
67
|
+
role: "combobox"
|
|
68
|
+
}),
|
|
69
|
+
...(ariaRole === "menu" && {
|
|
70
|
+
id: referenceId
|
|
71
|
+
}),
|
|
72
|
+
...(role === "select" && {
|
|
73
|
+
"aria-autocomplete": "none"
|
|
74
|
+
}),
|
|
75
|
+
...(role === "combobox" && {
|
|
76
|
+
"aria-autocomplete": "list"
|
|
77
|
+
})
|
|
78
|
+
};
|
|
79
|
+
}, [ariaRole, floatingId, open, referenceId, role]);
|
|
80
|
+
const floating = React.useMemo(() => {
|
|
81
|
+
const floatingProps = {
|
|
82
|
+
id: floatingId,
|
|
83
|
+
...(ariaRole && {
|
|
84
|
+
role: ariaRole
|
|
85
|
+
})
|
|
86
|
+
};
|
|
87
|
+
if (ariaRole === "tooltip" || role === "label") {
|
|
88
|
+
return floatingProps;
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
...floatingProps,
|
|
92
|
+
...(ariaRole === "menu" && {
|
|
93
|
+
"aria-labelledby": referenceId
|
|
94
|
+
})
|
|
95
|
+
};
|
|
96
|
+
}, [ariaRole, floatingId, referenceId, role]);
|
|
97
|
+
const item = React.useCallback(({
|
|
98
|
+
active,
|
|
99
|
+
selected
|
|
100
|
+
}) => {
|
|
101
|
+
const commonProps = {
|
|
102
|
+
role: "option",
|
|
103
|
+
...(active && {
|
|
104
|
+
id: `${floatingId}-fui-option`
|
|
105
|
+
})
|
|
106
|
+
};
|
|
107
|
+
switch (role) {
|
|
108
|
+
case "select":
|
|
109
|
+
case "combobox":
|
|
110
|
+
return {
|
|
111
|
+
...commonProps,
|
|
112
|
+
"aria-selected": selected
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
return {};
|
|
116
|
+
}, [floatingId, role]);
|
|
117
|
+
return React.useMemo(() => enabled ? {
|
|
118
|
+
reference,
|
|
119
|
+
floating,
|
|
120
|
+
item
|
|
121
|
+
} : {}, [enabled, reference, floating, item]);
|
|
122
|
+
}
|