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