@tamagui/floating 2.0.0-rc.3 → 2.0.0-rc.31
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.native.js +4 -0
- package/dist/cjs/Floating.native.js.map +1 -1
- package/dist/cjs/index.cjs +33 -2
- package/dist/cjs/index.native.js +33 -2
- package/dist/cjs/index.native.js.map +1 -1
- package/dist/cjs/interactions/PopupTriggerMap.cjs +40 -0
- package/dist/cjs/interactions/PopupTriggerMap.native.js +73 -0
- package/dist/cjs/interactions/PopupTriggerMap.native.js.map +1 -0
- package/dist/cjs/interactions/createFloatingEvents.cjs +41 -0
- package/dist/cjs/interactions/createFloatingEvents.native.js +47 -0
- package/dist/cjs/interactions/createFloatingEvents.native.js.map +1 -0
- package/dist/cjs/interactions/safePolygon.cjs +191 -0
- package/dist/cjs/interactions/safePolygon.native.js +205 -0
- package/dist/cjs/interactions/safePolygon.native.js.map +1 -0
- package/dist/cjs/interactions/types.cjs +16 -0
- package/dist/cjs/interactions/types.native.js +19 -0
- package/dist/cjs/interactions/types.native.js.map +1 -0
- package/dist/cjs/interactions/useClick.cjs +82 -0
- package/dist/cjs/interactions/useClick.native.js +90 -0
- package/dist/cjs/interactions/useClick.native.js.map +1 -0
- package/dist/cjs/interactions/useDelayGroup.cjs +96 -0
- package/dist/cjs/interactions/useDelayGroup.native.js +109 -0
- package/dist/cjs/interactions/useDelayGroup.native.js.map +1 -0
- package/dist/cjs/interactions/useFocus.cjs +101 -0
- package/dist/cjs/interactions/useFocus.native.js +113 -0
- package/dist/cjs/interactions/useFocus.native.js.map +1 -0
- package/dist/cjs/interactions/useHover.cjs +224 -0
- package/dist/cjs/interactions/useHover.native.js +248 -0
- package/dist/cjs/interactions/useHover.native.js.map +1 -0
- package/dist/cjs/interactions/useInnerOffset.cjs +104 -0
- package/dist/cjs/interactions/useInnerOffset.native.js +118 -0
- package/dist/cjs/interactions/useInnerOffset.native.js.map +1 -0
- package/dist/cjs/interactions/useInteractions.cjs +76 -0
- package/dist/cjs/interactions/useInteractions.native.js +164 -0
- package/dist/cjs/interactions/useInteractions.native.js.map +1 -0
- package/dist/cjs/interactions/useListNavigation.cjs +253 -0
- package/dist/cjs/interactions/useListNavigation.native.js +297 -0
- package/dist/cjs/interactions/useListNavigation.native.js.map +1 -0
- package/dist/cjs/interactions/useRole.cjs +112 -0
- package/dist/cjs/interactions/useRole.native.js +128 -0
- package/dist/cjs/interactions/useRole.native.js.map +1 -0
- package/dist/cjs/interactions/useTypeahead.cjs +93 -0
- package/dist/cjs/interactions/useTypeahead.native.js +114 -0
- package/dist/cjs/interactions/useTypeahead.native.js.map +1 -0
- package/dist/cjs/interactions/utils.cjs +178 -0
- package/dist/cjs/interactions/utils.native.js +188 -0
- package/dist/cjs/interactions/utils.native.js.map +1 -0
- package/dist/cjs/middleware/inner.cjs +106 -0
- package/dist/cjs/middleware/inner.native.js +120 -0
- package/dist/cjs/middleware/inner.native.js.map +1 -0
- package/dist/cjs/useFloating.cjs +21 -17
- package/dist/cjs/useFloating.native.js +2 -0
- package/dist/cjs/useFloating.native.js.map +1 -1
- package/dist/esm/Floating.native.js +4 -1
- package/dist/esm/Floating.native.js.map +1 -1
- package/dist/esm/index.js +17 -34
- package/dist/esm/index.js.map +1 -6
- package/dist/esm/index.mjs +16 -2
- package/dist/esm/index.mjs.map +1 -1
- package/dist/esm/index.native.js +16 -2
- package/dist/esm/index.native.js.map +1 -1
- package/dist/esm/interactions/PopupTriggerMap.mjs +17 -0
- package/dist/esm/interactions/PopupTriggerMap.mjs.map +1 -0
- package/dist/esm/interactions/PopupTriggerMap.native.js +47 -0
- package/dist/esm/interactions/PopupTriggerMap.native.js.map +1 -0
- package/dist/esm/interactions/createFloatingEvents.mjs +18 -0
- package/dist/esm/interactions/createFloatingEvents.mjs.map +1 -0
- package/dist/esm/interactions/createFloatingEvents.native.js +21 -0
- package/dist/esm/interactions/createFloatingEvents.native.js.map +1 -0
- package/dist/esm/interactions/safePolygon.mjs +168 -0
- package/dist/esm/interactions/safePolygon.mjs.map +1 -0
- package/dist/esm/interactions/safePolygon.native.js +179 -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 +59 -0
- package/dist/esm/interactions/useClick.mjs.map +1 -0
- package/dist/esm/interactions/useClick.native.js +64 -0
- package/dist/esm/interactions/useClick.native.js.map +1 -0
- package/dist/esm/interactions/useDelayGroup.mjs +60 -0
- package/dist/esm/interactions/useDelayGroup.mjs.map +1 -0
- package/dist/esm/interactions/useDelayGroup.native.js +70 -0
- package/dist/esm/interactions/useDelayGroup.native.js.map +1 -0
- package/dist/esm/interactions/useFocus.mjs +78 -0
- package/dist/esm/interactions/useFocus.mjs.map +1 -0
- package/dist/esm/interactions/useFocus.native.js +87 -0
- package/dist/esm/interactions/useFocus.native.js.map +1 -0
- package/dist/esm/interactions/useHover.mjs +189 -0
- package/dist/esm/interactions/useHover.mjs.map +1 -0
- package/dist/esm/interactions/useHover.native.js +210 -0
- package/dist/esm/interactions/useHover.native.js.map +1 -0
- package/dist/esm/interactions/useInnerOffset.mjs +70 -0
- package/dist/esm/interactions/useInnerOffset.mjs.map +1 -0
- package/dist/esm/interactions/useInnerOffset.native.js +81 -0
- package/dist/esm/interactions/useInnerOffset.native.js.map +1 -0
- package/dist/esm/interactions/useInteractions.mjs +53 -0
- package/dist/esm/interactions/useInteractions.mjs.map +1 -0
- package/dist/esm/interactions/useInteractions.native.js +138 -0
- package/dist/esm/interactions/useInteractions.native.js.map +1 -0
- package/dist/esm/interactions/useListNavigation.mjs +230 -0
- package/dist/esm/interactions/useListNavigation.mjs.map +1 -0
- package/dist/esm/interactions/useListNavigation.native.js +271 -0
- package/dist/esm/interactions/useListNavigation.native.js.map +1 -0
- package/dist/esm/interactions/useRole.mjs +78 -0
- package/dist/esm/interactions/useRole.mjs.map +1 -0
- package/dist/esm/interactions/useRole.native.js +91 -0
- package/dist/esm/interactions/useRole.native.js.map +1 -0
- package/dist/esm/interactions/useTypeahead.mjs +70 -0
- package/dist/esm/interactions/useTypeahead.mjs.map +1 -0
- package/dist/esm/interactions/useTypeahead.native.js +88 -0
- package/dist/esm/interactions/useTypeahead.native.js.map +1 -0
- package/dist/esm/interactions/utils.mjs +134 -0
- package/dist/esm/interactions/utils.mjs.map +1 -0
- package/dist/esm/interactions/utils.native.js +141 -0
- package/dist/esm/interactions/utils.native.js.map +1 -0
- package/dist/esm/middleware/inner.mjs +72 -0
- package/dist/esm/middleware/inner.mjs.map +1 -0
- package/dist/esm/middleware/inner.native.js +83 -0
- package/dist/esm/middleware/inner.native.js.map +1 -0
- package/dist/esm/useFloating.mjs +21 -17
- package/dist/esm/useFloating.mjs.map +1 -1
- package/dist/esm/useFloating.native.js +2 -0
- package/dist/esm/useFloating.native.js.map +1 -1
- package/package.json +8 -10
- package/src/Floating.native.tsx +1 -0
- package/src/index.ts +49 -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 +142 -0
- package/src/useFloating.tsx +13 -1
- package/types/Floating.native.d.ts +1 -0
- package/types/Floating.native.d.ts.map +1 -1
- package/types/index.d.ts +17 -2
- package/types/index.d.ts.map +1 -1
- 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 +7 -1
- package/types/useFloating.d.ts.map +1 -1
- package/dist/cjs/Floating.js +0 -15
- package/dist/cjs/Floating.js.map +0 -6
- package/dist/cjs/index.js +0 -34
- package/dist/cjs/index.js.map +0 -6
- package/dist/cjs/useFloating.js +0 -46
- package/dist/cjs/useFloating.js.map +0 -6
- package/dist/esm/Floating.js +0 -2
- package/dist/esm/Floating.js.map +0 -6
- package/dist/esm/useFloating.js +0 -23
- package/dist/esm/useFloating.js.map +0 -6
|
@@ -0,0 +1,297 @@
|
|
|
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: !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, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
21
|
+
value: !0
|
|
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
|
+
import_use_event = require("@tamagui/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";
|
|
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
|
+
var vertical = key === ARROW_UP || key === ARROW_DOWN,
|
|
47
|
+
horizontal = key === ARROW_LEFT || key === ARROW_RIGHT;
|
|
48
|
+
return doSwitch(orientation, vertical, horizontal);
|
|
49
|
+
}
|
|
50
|
+
function isMainOrientationToEndKey(key, orientation, rtl) {
|
|
51
|
+
var vertical = key === ARROW_DOWN,
|
|
52
|
+
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
|
+
var vertical = rtl ? key === ARROW_LEFT : key === ARROW_RIGHT,
|
|
57
|
+
horizontal = key === ARROW_DOWN;
|
|
58
|
+
return doSwitch(orientation, vertical, horizontal);
|
|
59
|
+
}
|
|
60
|
+
function isCrossOrientationCloseKey(key, orientation, rtl) {
|
|
61
|
+
var vertical = rtl ? key === ARROW_RIGHT : key === ARROW_LEFT,
|
|
62
|
+
horizontal = key === ARROW_UP;
|
|
63
|
+
return doSwitch(orientation, vertical, horizontal);
|
|
64
|
+
}
|
|
65
|
+
function useListNavigation(context, props) {
|
|
66
|
+
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);
|
|
99
|
+
disabledIndicesRef.current = disabledIndices;
|
|
100
|
+
var latestOpenRef = (0, import_react.useRef)(open);
|
|
101
|
+
latestOpenRef.current = open;
|
|
102
|
+
var scrollItemIntoViewRef = (0, import_react.useRef)(scrollItemIntoView);
|
|
103
|
+
scrollItemIntoViewRef.current = scrollItemIntoView;
|
|
104
|
+
var selectedIndexRef = (0, import_react.useRef)(selectedIndex);
|
|
105
|
+
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, {
|
|
115
|
+
sync: forceSyncFocusRef.current,
|
|
116
|
+
preventScroll: !0
|
|
117
|
+
});
|
|
118
|
+
}
|
|
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
|
+
});
|
|
140
|
+
});
|
|
141
|
+
(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
|
+
};
|
|
157
|
+
waitForListPopulated();
|
|
158
|
+
}
|
|
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);
|
|
164
|
+
}, [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, {
|
|
181
|
+
startingIndex: currentIndex,
|
|
182
|
+
disabledIndices
|
|
183
|
+
}) : indexRef.current = Math.min(maxIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {
|
|
184
|
+
startingIndex: currentIndex,
|
|
185
|
+
disabledIndices
|
|
186
|
+
})) : loop ? indexRef.current = currentIndex <= minIndex ? allowEscape && currentIndex !== -1 ? listRef.current.length : maxIndex : (0, import_utils.findNonDisabledListIndex)(listRef, {
|
|
187
|
+
startingIndex: currentIndex,
|
|
188
|
+
decrement: !0,
|
|
189
|
+
disabledIndices
|
|
190
|
+
}) : indexRef.current = Math.max(minIndex, (0, import_utils.findNonDisabledListIndex)(listRef, {
|
|
191
|
+
startingIndex: currentIndex,
|
|
192
|
+
decrement: !0,
|
|
193
|
+
disabledIndices
|
|
194
|
+
})), (0, import_utils.isIndexOutOfListBounds)(listRef, indexRef.current) && (indexRef.current = -1), onNavigate();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
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);
|
|
216
|
+
}
|
|
217
|
+
function checkVirtualPointer(event) {
|
|
218
|
+
focusItemOnOpenRef.current = focusItemOnOpen, focusItemOnOpen === "auto" && (0, import_utils.isVirtualPointerEvent)(event.nativeEvent) && (focusItemOnOpenRef.current = !0);
|
|
219
|
+
}
|
|
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;
|
|
233
|
+
}
|
|
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
|
+
}
|
|
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());
|
|
251
|
+
}
|
|
252
|
+
}
|
|
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
|
|
266
|
+
});
|
|
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
|
+
}
|
|
286
|
+
};
|
|
287
|
+
return itemProps;
|
|
288
|
+
}, [latestOpenRef, focusItemOnHover, listRef, onNavigate, virtual, elements.floating]);
|
|
289
|
+
return (0, import_react.useMemo)(function () {
|
|
290
|
+
return enabled ? {
|
|
291
|
+
reference,
|
|
292
|
+
floating,
|
|
293
|
+
item
|
|
294
|
+
} : {};
|
|
295
|
+
}, [enabled, reference, floating, item]);
|
|
296
|
+
}
|
|
297
|
+
//# sourceMappingURL=useListNavigation.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useListNavigation_exports","__export","useListNavigation","module","exports","import_react","require","import_use_event","import_utils","ARROW_UP","ARROW_DOWN","ARROW_LEFT","ARROW_RIGHT","doSwitch","orientation","vertical","horizontal","isMainOrientationKey","key","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","call","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"],"sources":["../../../src/interactions/useListNavigation.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;AAAA,IAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;EAAAC,KAAA;AAAA,IAAAH,GAAA;AAAA,IAAAI,yBAAA;AAAAC,QAAA,CAAAD,yBAAA;EAAAE,iBAAA,EAAAA,CAAA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+G,OAAA,EAAkB,YAAS;MAE9C,SAAOoB,kBAAAtC,aAAA;QACL,IAAOxC,aAAY,CAAAD,OAAA,EAAW;UAC7B,IAAAgF,KAAS,GAAA7G,OAAW,CAAA6B,OAAU,CAAAiF,OAAI,CAAAxC,aAAA;UACrCuC,KAAA,WAAAzF,QAAA,CAAAS,OAAA,KAAAgF,KAAA,KAAAzF,QAAA,CAAAS,OAAA,GAAAgF,KAAA,EAAA3G,UAAA;QACF","ignoreList":[]}
|
|
@@ -0,0 +1,112 @@
|
|
|
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
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
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, {
|
|
15
|
+
get: () => from[key],
|
|
16
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
17
|
+
});
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
value: mod,
|
|
27
|
+
enumerable: !0
|
|
28
|
+
}) : target, mod)),
|
|
29
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
30
|
+
value: !0
|
|
31
|
+
}), mod);
|
|
32
|
+
var useRole_exports = {};
|
|
33
|
+
__export(useRole_exports, {
|
|
34
|
+
useRole: () => useRole
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(useRole_exports);
|
|
37
|
+
var React = __toESM(require("react"), 1);
|
|
38
|
+
const componentRoleToAriaRoleMap = /* @__PURE__ */new Map([["select", "listbox"], ["combobox", "listbox"], ["label", !1]]);
|
|
39
|
+
let idCounter = 0;
|
|
40
|
+
function useRole(context, props = {}) {
|
|
41
|
+
const {
|
|
42
|
+
open,
|
|
43
|
+
elements
|
|
44
|
+
} = context,
|
|
45
|
+
{
|
|
46
|
+
enabled = !0,
|
|
47
|
+
role = "dialog"
|
|
48
|
+
} = props,
|
|
49
|
+
defaultReferenceId = React.useId(),
|
|
50
|
+
referenceId = elements.domReference?.id || defaultReferenceId,
|
|
51
|
+
defaultFloatingId = React.useMemo(() => `floating-${idCounter++}`, []),
|
|
52
|
+
floatingId = React.useMemo(() => elements.floating?.id || defaultFloatingId, [elements.floating, defaultFloatingId]),
|
|
53
|
+
ariaRole = componentRoleToAriaRoleMap.get(role) ?? role,
|
|
54
|
+
reference = React.useMemo(() => ariaRole === "tooltip" || role === "label" ? {
|
|
55
|
+
[`aria-${role === "label" ? "labelledby" : "describedby"}`]: open ? floatingId : void 0
|
|
56
|
+
} : {
|
|
57
|
+
"aria-expanded": open ? "true" : "false",
|
|
58
|
+
"aria-haspopup": ariaRole === "alertdialog" ? "dialog" : ariaRole,
|
|
59
|
+
"aria-controls": open ? floatingId : void 0,
|
|
60
|
+
...(ariaRole === "listbox" && {
|
|
61
|
+
role: "combobox"
|
|
62
|
+
}),
|
|
63
|
+
...(ariaRole === "menu" && {
|
|
64
|
+
id: referenceId
|
|
65
|
+
}),
|
|
66
|
+
...(role === "select" && {
|
|
67
|
+
"aria-autocomplete": "none"
|
|
68
|
+
}),
|
|
69
|
+
...(role === "combobox" && {
|
|
70
|
+
"aria-autocomplete": "list"
|
|
71
|
+
})
|
|
72
|
+
}, [ariaRole, floatingId, open, referenceId, role]),
|
|
73
|
+
floating = React.useMemo(() => {
|
|
74
|
+
const floatingProps = {
|
|
75
|
+
id: floatingId,
|
|
76
|
+
...(ariaRole && {
|
|
77
|
+
role: ariaRole
|
|
78
|
+
})
|
|
79
|
+
};
|
|
80
|
+
return ariaRole === "tooltip" || role === "label" ? floatingProps : {
|
|
81
|
+
...floatingProps,
|
|
82
|
+
...(ariaRole === "menu" && {
|
|
83
|
+
"aria-labelledby": referenceId
|
|
84
|
+
})
|
|
85
|
+
};
|
|
86
|
+
}, [ariaRole, floatingId, referenceId, role]),
|
|
87
|
+
item = React.useCallback(({
|
|
88
|
+
active,
|
|
89
|
+
selected
|
|
90
|
+
}) => {
|
|
91
|
+
const commonProps = {
|
|
92
|
+
role: "option",
|
|
93
|
+
...(active && {
|
|
94
|
+
id: `${floatingId}-fui-option`
|
|
95
|
+
})
|
|
96
|
+
};
|
|
97
|
+
switch (role) {
|
|
98
|
+
case "select":
|
|
99
|
+
case "combobox":
|
|
100
|
+
return {
|
|
101
|
+
...commonProps,
|
|
102
|
+
"aria-selected": selected
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
return {};
|
|
106
|
+
}, [floatingId, role]);
|
|
107
|
+
return React.useMemo(() => enabled ? {
|
|
108
|
+
reference,
|
|
109
|
+
floating,
|
|
110
|
+
item
|
|
111
|
+
} : {}, [enabled, reference, floating, item]);
|
|
112
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf,
|
|
8
|
+
__hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all) __defProp(target, name, {
|
|
11
|
+
get: all[name],
|
|
12
|
+
enumerable: !0
|
|
13
|
+
});
|
|
14
|
+
},
|
|
15
|
+
__copyProps = (to, from, except, desc) => {
|
|
16
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
17
|
+
get: () => from[key],
|
|
18
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
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: !0
|
|
30
|
+
}) : target, mod)),
|
|
31
|
+
__toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
32
|
+
value: !0
|
|
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
|
+
componentRoleToAriaRoleMap = /* @__PURE__ */new Map([["select", "listbox"], ["combobox", "listbox"], ["label", !1]]),
|
|
41
|
+
idCounter = 0;
|
|
42
|
+
function useRole(context) {
|
|
43
|
+
var props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {},
|
|
44
|
+
_elements_domReference,
|
|
45
|
+
{
|
|
46
|
+
open,
|
|
47
|
+
elements
|
|
48
|
+
} = context,
|
|
49
|
+
{
|
|
50
|
+
enabled = !0,
|
|
51
|
+
role = "dialog"
|
|
52
|
+
} = props,
|
|
53
|
+
defaultReferenceId = React.useId(),
|
|
54
|
+
referenceId = ((_elements_domReference = elements.domReference) === null || _elements_domReference === void 0 ? void 0 : _elements_domReference.id) || defaultReferenceId,
|
|
55
|
+
defaultFloatingId = React.useMemo(function () {
|
|
56
|
+
return `floating-${idCounter++}`;
|
|
57
|
+
}, []),
|
|
58
|
+
floatingId = React.useMemo(function () {
|
|
59
|
+
var _elements_floating;
|
|
60
|
+
return ((_elements_floating = elements.floating) === null || _elements_floating === void 0 ? void 0 : _elements_floating.id) || defaultFloatingId;
|
|
61
|
+
}, [elements.floating, defaultFloatingId]),
|
|
62
|
+
_componentRoleToAriaRoleMap_get,
|
|
63
|
+
ariaRole = (_componentRoleToAriaRoleMap_get = componentRoleToAriaRoleMap.get(role)) !== null && _componentRoleToAriaRoleMap_get !== void 0 ? _componentRoleToAriaRoleMap_get : role,
|
|
64
|
+
reference = React.useMemo(function () {
|
|
65
|
+
return ariaRole === "tooltip" || role === "label" ? {
|
|
66
|
+
[`aria-${role === "label" ? "labelledby" : "describedby"}`]: open ? floatingId : void 0
|
|
67
|
+
} : {
|
|
68
|
+
"aria-expanded": open ? "true" : "false",
|
|
69
|
+
"aria-haspopup": ariaRole === "alertdialog" ? "dialog" : ariaRole,
|
|
70
|
+
"aria-controls": open ? floatingId : void 0,
|
|
71
|
+
...(ariaRole === "listbox" && {
|
|
72
|
+
role: "combobox"
|
|
73
|
+
}),
|
|
74
|
+
...(ariaRole === "menu" && {
|
|
75
|
+
id: referenceId
|
|
76
|
+
}),
|
|
77
|
+
...(role === "select" && {
|
|
78
|
+
"aria-autocomplete": "none"
|
|
79
|
+
}),
|
|
80
|
+
...(role === "combobox" && {
|
|
81
|
+
"aria-autocomplete": "list"
|
|
82
|
+
})
|
|
83
|
+
};
|
|
84
|
+
}, [ariaRole, floatingId, open, referenceId, role]),
|
|
85
|
+
floating = React.useMemo(function () {
|
|
86
|
+
var floatingProps = {
|
|
87
|
+
id: floatingId,
|
|
88
|
+
...(ariaRole && {
|
|
89
|
+
role: ariaRole
|
|
90
|
+
})
|
|
91
|
+
};
|
|
92
|
+
return ariaRole === "tooltip" || role === "label" ? floatingProps : {
|
|
93
|
+
...floatingProps,
|
|
94
|
+
...(ariaRole === "menu" && {
|
|
95
|
+
"aria-labelledby": referenceId
|
|
96
|
+
})
|
|
97
|
+
};
|
|
98
|
+
}, [ariaRole, floatingId, referenceId, role]),
|
|
99
|
+
item = React.useCallback(function (param) {
|
|
100
|
+
var {
|
|
101
|
+
active,
|
|
102
|
+
selected
|
|
103
|
+
} = param,
|
|
104
|
+
commonProps = {
|
|
105
|
+
role: "option",
|
|
106
|
+
...(active && {
|
|
107
|
+
id: `${floatingId}-fui-option`
|
|
108
|
+
})
|
|
109
|
+
};
|
|
110
|
+
switch (role) {
|
|
111
|
+
case "select":
|
|
112
|
+
case "combobox":
|
|
113
|
+
return {
|
|
114
|
+
...commonProps,
|
|
115
|
+
"aria-selected": selected
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
return {};
|
|
119
|
+
}, [floatingId, role]);
|
|
120
|
+
return React.useMemo(function () {
|
|
121
|
+
return enabled ? {
|
|
122
|
+
reference,
|
|
123
|
+
floating,
|
|
124
|
+
item
|
|
125
|
+
} : {};
|
|
126
|
+
}, [enabled, reference, floating, item]);
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=useRole.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["__toCommonJS","mod","__copyProps","__defProp","value","useRole_exports","__export","useRole","module","exports","React","__toESM","require","componentRoleToAriaRoleMap","Map","idCounter","context","props","arguments","length","_elements_domReference","open","elements","enabled","role","defaultReferenceId","useId","referenceId","domReference","id","defaultFloatingId","useMemo","floatingId","_elements_floating","floating","_componentRoleToAriaRoleMap_get","ariaRole","get","reference","floatingProps"],"sources":["../../../src/interactions/useRole.ts"],"sourcesContent":[null],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;kBAAA;EAAAA,YAAA,GAAAC,GAAA,IAAAC,WAAA,CAAAC,SAAA;IAAAC,KAAA;EAAA,IAAAH,GAAA;AAAA,IAAAI,eAAA;AAAAC,QAAA,CAAAD,eAAA;EAAAE,OAAA,EAAAA,CAAA,KAAAA;AAAA;AAAAC,MAAA,CAAAC,OAAuB,GAAAT,YAAA,CAAAK,eAAA;AAMvB,IAAAK,KAAM,GAAAC,OAAA,CAAAC,OAAA,QAA6B;EAAAC,0BAAsC,sBAAAC,GAAA,EACvE,CACC,UACA,SAAS,CACX,EAED,CAGO,UAAS,EAId,SAAQ,CAOiB,EACQ,CAEjC,OAEM,EAaA,CAAC,EAGH,CAGK;EACLC,SAAA;AAAiC,SACjCR,QAAAS,OAAiB;EAAwC,IACzDC,KAAA,GAAAC,SAAiB,CAAAC,MAAO,QAAAD,SAAa,iBAAAA,SAAA;IAAAE,sBAAA;IAAA;MAAAC,IAAA;MAAAC;IAAA,IAAAN,OAAA;IAAA;MAAAO,OAAA;MAAAC,IAAA;IAAA,IAAAP,KAAA;IAAAQ,kBAAA,GAAAf,KAAA,CAAAgB,KAAA;IAAAC,WAAA,KAAAP,sBAAA,GAAAE,QAAA,CAAAM,YAAA,cAAAR,sBAAA,uBAAAA,sBAAA,CAAAS,EAAA,KAAAJ,kBAAA;IAAAK,iBAAA,GAAApB,KAAA,CAAAqB,OAAA;MACrC,OAAI,YAAahB,SAAA,EAAa,EAAE;IAAiB,GACjD,EAAI;IAAAiB,UAAa,GAAAtB,KAAA,CAAAqB,OAAgB,aAAY;MAC7C,IAAIE,kBAAS;MACb,OAAI,EAAAA,kBAAuB,GAAEX,QAAA,CAAAY,QAAA,MAAqB,IAAO,IAAAD,kBAAA,uBAAAA,kBAAA,CAAAJ,EAAA,KAAAC,iBAAA;IAC3D,GACC,CAGDR,QAAM,CAAAY,QAAA,EAAgBJ,iBAChB;IACJK,+BAAwB;IAASC,QAAA,IAAAD,+BAAA,GAAAtB,0BAAA,CAAAwB,GAAA,CAAAb,IAAA,eAAAW,+BAAA,cAAAA,+BAAA,GAAAX,IAAA;IAAAc,SAAA,GAAA5B,KAAA,CAAAqB,OAAA;MACnC,OAAAK,QAAA,kBAAAZ,IAAA;QAEA,SAAIA,IAAA,KAAa,sBAAsB,gBAC9B,KAAAH,IAAA,GAGFW,UAAA;MAAA,IACL;QACA,eAAI,EAAaX,IAAA,SAAY;QAC/B,iBAAAe,QAAA,gCAAAA,QAAA;QACE,eAAU,EAAAf,IAAA,GAAYW,UAAA,GAAa,KAAK,CAEtC;QACH,IAAEI,QAAQ,cAAyD;UAClEZ,IAAM;QAAc;QACZ,IACNY,QAAI,KAAU,MAAM,IAAG;UACzBP,EAAA,EAAAF;QAEA;QAAc,IACZH,IAAK;UACL,mBAAK;QACH;QAAO,IAAAA,IACL,KAAG;UAAA,mBACH,EAAiB;QAAA;MACnB;IAGJ,IACFY,QAAA,EACAJ,UAAC,EACHX,IAAA,EAEAM,WAAa,EACXH,IAAA,CAAkD,CAClD;IAACU,QAAS,GAAAxB,KAAA,CAAAqB,OAAW,aAAc;MACrC,IAAAQ,aAAA;QACFV,EAAA,EAAAG,UAAA","ignoreList":[]}
|
|
@@ -0,0 +1,93 @@
|
|
|
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: !0
|
|
9
|
+
});
|
|
10
|
+
},
|
|
11
|
+
__copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from == "object" || typeof from == "function") for (let key of __getOwnPropNames(from)) !__hasOwnProp.call(to, key) && key !== except && __defProp(to, key, {
|
|
13
|
+
get: () => from[key],
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = mod => __copyProps(__defProp({}, "__esModule", {
|
|
19
|
+
value: !0
|
|
20
|
+
}), mod);
|
|
21
|
+
var useTypeahead_exports = {};
|
|
22
|
+
__export(useTypeahead_exports, {
|
|
23
|
+
useTypeahead: () => useTypeahead
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(useTypeahead_exports);
|
|
26
|
+
var import_react = require("react"),
|
|
27
|
+
import_use_event = require("@tamagui/use-event"),
|
|
28
|
+
import_utils = require("./utils.cjs");
|
|
29
|
+
function useTypeahead(context, props) {
|
|
30
|
+
const {
|
|
31
|
+
open,
|
|
32
|
+
dataRef
|
|
33
|
+
} = context,
|
|
34
|
+
{
|
|
35
|
+
listRef,
|
|
36
|
+
activeIndex,
|
|
37
|
+
onMatch: unstable_onMatch,
|
|
38
|
+
onTypingChange: unstable_onTypingChange,
|
|
39
|
+
enabled = !0,
|
|
40
|
+
findMatch = null,
|
|
41
|
+
resetMs = 750,
|
|
42
|
+
ignoreKeys = [],
|
|
43
|
+
selectedIndex = null
|
|
44
|
+
} = props,
|
|
45
|
+
timeoutIdRef = (0, import_react.useRef)(-1),
|
|
46
|
+
stringRef = (0, import_react.useRef)(""),
|
|
47
|
+
prevIndexRef = (0, import_react.useRef)(selectedIndex ?? activeIndex ?? -1),
|
|
48
|
+
matchIndexRef = (0, import_react.useRef)(null),
|
|
49
|
+
onMatch = (0, import_use_event.useEvent)(unstable_onMatch || (() => {})),
|
|
50
|
+
onTypingChange = (0, import_use_event.useEvent)(unstable_onTypingChange || (() => {})),
|
|
51
|
+
findMatchRef = (0, import_react.useRef)(findMatch);
|
|
52
|
+
findMatchRef.current = findMatch;
|
|
53
|
+
const ignoreKeysRef = (0, import_react.useRef)(ignoreKeys);
|
|
54
|
+
ignoreKeysRef.current = ignoreKeys, (0, import_react.useLayoutEffect)(() => {
|
|
55
|
+
open && ((0, import_utils.clearTimeoutIfSet)(timeoutIdRef), matchIndexRef.current = null, stringRef.current = "");
|
|
56
|
+
}, [open]), (0, import_react.useLayoutEffect)(() => {
|
|
57
|
+
open && stringRef.current === "" && (prevIndexRef.current = selectedIndex ?? activeIndex ?? -1);
|
|
58
|
+
}, [open, selectedIndex, activeIndex]);
|
|
59
|
+
const setTypingChange = value => {
|
|
60
|
+
value ? dataRef.current.typing || (dataRef.current.typing = value, onTypingChange(value)) : dataRef.current.typing && (dataRef.current.typing = value, onTypingChange(value));
|
|
61
|
+
},
|
|
62
|
+
onKeyDown = event => {
|
|
63
|
+
function getMatchingIndex(list, orderedList, string) {
|
|
64
|
+
const str = findMatchRef.current ? findMatchRef.current(orderedList, string) : orderedList.find(text => text?.toLocaleLowerCase().indexOf(string.toLocaleLowerCase()) === 0);
|
|
65
|
+
return str ? list.indexOf(str) : -1;
|
|
66
|
+
}
|
|
67
|
+
const listContent = listRef.current;
|
|
68
|
+
if (stringRef.current.length > 0 && stringRef.current[0] !== " " && (getMatchingIndex(listContent, listContent, stringRef.current) === -1 ? setTypingChange(!1) : event.key === " " && (0, import_utils.stopEvent)(event)), listContent == null || ignoreKeysRef.current.includes(event.key) ||
|
|
69
|
+
// character key
|
|
70
|
+
event.key.length !== 1 ||
|
|
71
|
+
// modifier key
|
|
72
|
+
event.ctrlKey || event.metaKey || event.altKey) return;
|
|
73
|
+
open && event.key !== " " && ((0, import_utils.stopEvent)(event), setTypingChange(!0)), listContent.every(text => text ? text[0]?.toLocaleLowerCase() !== text[1]?.toLocaleLowerCase() : !0) && stringRef.current === event.key && (stringRef.current = "", prevIndexRef.current = matchIndexRef.current), stringRef.current += event.key, (0, import_utils.clearTimeoutIfSet)(timeoutIdRef), timeoutIdRef.current = window.setTimeout(() => {
|
|
74
|
+
stringRef.current = "", prevIndexRef.current = matchIndexRef.current, setTypingChange(!1);
|
|
75
|
+
}, resetMs);
|
|
76
|
+
const prevIndex = prevIndexRef.current,
|
|
77
|
+
index = getMatchingIndex(listContent, [...listContent.slice((prevIndex || 0) + 1), ...listContent.slice(0, (prevIndex || 0) + 1)], stringRef.current);
|
|
78
|
+
index !== -1 ? (onMatch(index), matchIndexRef.current = index) : event.key !== " " && (stringRef.current = "", setTypingChange(!1));
|
|
79
|
+
},
|
|
80
|
+
reference = (0, import_react.useMemo)(() => ({
|
|
81
|
+
onKeyDown
|
|
82
|
+
}), [open, enabled]),
|
|
83
|
+
floating = (0, import_react.useMemo)(() => ({
|
|
84
|
+
onKeyDown,
|
|
85
|
+
onKeyUp(event) {
|
|
86
|
+
event.key === " " && setTypingChange(!1);
|
|
87
|
+
}
|
|
88
|
+
}), [open, enabled]);
|
|
89
|
+
return (0, import_react.useMemo)(() => enabled ? {
|
|
90
|
+
reference,
|
|
91
|
+
floating
|
|
92
|
+
} : {}, [enabled, reference, floating]);
|
|
93
|
+
}
|