@react-aria/selection 3.5.1 → 3.7.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/main.js +516 -719
- package/dist/main.js.map +1 -1
- package/dist/module.js +500 -690
- package/dist/module.js.map +1 -1
- package/dist/types.d.ts +26 -9
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/useSelectableCollection.ts +62 -17
- package/src/useSelectableItem.ts +106 -15
- package/src/useSelectableList.ts +4 -67
- package/src/utils.ts +34 -0
package/dist/module.js
CHANGED
|
@@ -1,755 +1,565 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
let {
|
|
12
|
-
keyboardDelegate,
|
|
13
|
-
selectionManager,
|
|
14
|
-
onTypeSelect
|
|
15
|
-
} = options;
|
|
16
|
-
let state = useRef({
|
|
17
|
-
search: '',
|
|
18
|
-
timeout: null
|
|
19
|
-
}).current;
|
|
20
|
-
|
|
21
|
-
let onKeyDown = e => {
|
|
22
|
-
let character = $c78d7fa5f7d5832f9b4f97b33a679865$var$getStringForKey(e.key);
|
|
23
|
-
|
|
24
|
-
if (!character || e.ctrlKey || e.metaKey) {
|
|
25
|
-
return;
|
|
26
|
-
} // Do not propagate the Spacebar event if it's meant to be part of the search.
|
|
27
|
-
// When we time out, the search term becomes empty, hence the check on length.
|
|
28
|
-
// Trimming is to account for the case of pressing the Spacebar more than once,
|
|
29
|
-
// which should cycle through the selection/deselection of the focused item.
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (character === ' ' && state.search.trim().length > 0) {
|
|
33
|
-
e.preventDefault();
|
|
34
|
-
|
|
35
|
-
if (!('continuePropagation' in e)) {
|
|
36
|
-
e.stopPropagation();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
1
|
+
import {useRef as $1GWK5$useRef, useEffect as $1GWK5$useEffect, useMemo as $1GWK5$useMemo} from "react";
|
|
2
|
+
import {getFocusableTreeWalker as $1GWK5$getFocusableTreeWalker, focusSafely as $1GWK5$focusSafely} from "@react-aria/focus";
|
|
3
|
+
import {focusWithoutScrolling as $1GWK5$focusWithoutScrolling, useEvent as $1GWK5$useEvent, scrollIntoView as $1GWK5$scrollIntoView, mergeProps as $1GWK5$mergeProps, isAppleDevice as $1GWK5$isAppleDevice, isMac as $1GWK5$isMac} from "@react-aria/utils";
|
|
4
|
+
import {useLocale as $1GWK5$useLocale, useCollator as $1GWK5$useCollator} from "@react-aria/i18n";
|
|
5
|
+
import {usePress as $1GWK5$usePress, useLongPress as $1GWK5$useLongPress} from "@react-aria/interactions";
|
|
6
|
+
|
|
7
|
+
function $parcel$export(e, n, v, s) {
|
|
8
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
9
|
+
}
|
|
10
|
+
var $f2918947066e8d51$exports = {};
|
|
39
11
|
|
|
40
|
-
|
|
41
|
-
// Prioritize items after the currently focused item, falling back to searching the whole list.
|
|
12
|
+
$parcel$export($f2918947066e8d51$exports, "useSelectableCollection", () => $f2918947066e8d51$export$d6daf82dcd84e87c);
|
|
42
13
|
|
|
43
|
-
let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey); // If no key found, search from the top.
|
|
44
14
|
|
|
45
|
-
if (key == null) {
|
|
46
|
-
key = keyboardDelegate.getKeyForSearch(state.search);
|
|
47
|
-
}
|
|
48
15
|
|
|
49
|
-
if (key != null) {
|
|
50
|
-
selectionManager.setFocusedKey(key);
|
|
51
16
|
|
|
52
|
-
if (onTypeSelect) {
|
|
53
|
-
onTypeSelect(key);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
17
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
return {
|
|
64
|
-
typeSelectProps: {
|
|
65
|
-
// Using a capturing listener to catch the keydown event before
|
|
66
|
-
// other hooks in order to handle the Spacebar event.
|
|
67
|
-
onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null
|
|
68
|
-
}
|
|
69
|
-
};
|
|
18
|
+
function $003bf7ca80eac51f$export$d3e3bd3e26688c04(e) {
|
|
19
|
+
// Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.
|
|
20
|
+
// On Windows and Ubuntu, Alt + Space has a system wide meaning.
|
|
21
|
+
return $1GWK5$isAppleDevice() ? e.altKey : e.ctrlKey;
|
|
70
22
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
// Otherwise, if there are no ASCII characters in the key name,
|
|
75
|
-
// it is a Unicode character.
|
|
76
|
-
// See https://www.w3.org/TR/uievents-key/
|
|
77
|
-
if (key.length === 1 || !/^[A-Z]/i.test(key)) {
|
|
78
|
-
return key;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return '';
|
|
23
|
+
function $003bf7ca80eac51f$export$16792effe837dba3(e) {
|
|
24
|
+
if ($1GWK5$isMac()) return e.metaKey;
|
|
25
|
+
return e.ctrlKey;
|
|
82
26
|
}
|
|
83
27
|
|
|
84
|
-
function $a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e) {
|
|
85
|
-
if (isMac()) {
|
|
86
|
-
return e.metaKey;
|
|
87
|
-
}
|
|
88
28
|
|
|
89
|
-
return e.ctrlKey;
|
|
90
|
-
}
|
|
91
29
|
|
|
92
|
-
|
|
93
|
-
* Handles interactions with selectable collections.
|
|
94
|
-
*/
|
|
95
|
-
export function useSelectableCollection(options) {
|
|
96
|
-
let {
|
|
97
|
-
selectionManager: manager,
|
|
98
|
-
keyboardDelegate: delegate,
|
|
99
|
-
ref,
|
|
100
|
-
autoFocus = false,
|
|
101
|
-
shouldFocusWrap = false,
|
|
102
|
-
disallowEmptySelection = false,
|
|
103
|
-
disallowSelectAll = false,
|
|
104
|
-
selectOnFocus = false,
|
|
105
|
-
disallowTypeAhead = false,
|
|
106
|
-
shouldUseVirtualFocus,
|
|
107
|
-
allowsTabNavigation = false
|
|
108
|
-
} = options;
|
|
109
|
-
let {
|
|
110
|
-
direction
|
|
111
|
-
} = useLocale();
|
|
112
|
-
|
|
113
|
-
let onKeyDown = e => {
|
|
114
|
-
// Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes
|
|
115
|
-
if (e.altKey && e.key === 'Tab') {
|
|
116
|
-
e.preventDefault();
|
|
117
|
-
} // Let child element (e.g. menu button) handle the event if the Alt key is pressed.
|
|
118
|
-
// Keyboard events bubble through portals. Don't handle keyboard events
|
|
119
|
-
// for elements outside the collection (e.g. menus).
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
if (e.altKey || !ref.current.contains(e.target)) {
|
|
123
|
-
return;
|
|
124
|
-
}
|
|
30
|
+
var $eb39f547daf47539$exports = {};
|
|
125
31
|
|
|
126
|
-
|
|
127
|
-
if (key != null) {
|
|
128
|
-
manager.setFocusedKey(key, childFocus);
|
|
32
|
+
$parcel$export($eb39f547daf47539$exports, "useTypeSelect", () => $eb39f547daf47539$export$e32c88dfddc6e1d8);
|
|
129
33
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
34
|
+
function $eb39f547daf47539$export$e32c88dfddc6e1d8(options) {
|
|
35
|
+
let { keyboardDelegate: keyboardDelegate , selectionManager: selectionManager , onTypeSelect: onTypeSelect } = options;
|
|
36
|
+
let state = $1GWK5$useRef({
|
|
37
|
+
search: '',
|
|
38
|
+
timeout: null
|
|
39
|
+
}).current;
|
|
40
|
+
let onKeyDown = (e)=>{
|
|
41
|
+
let character = $eb39f547daf47539$var$getStringForKey(e.key);
|
|
42
|
+
if (!character || e.ctrlKey || e.metaKey) return;
|
|
43
|
+
// Do not propagate the Spacebar event if it's meant to be part of the search.
|
|
44
|
+
// When we time out, the search term becomes empty, hence the check on length.
|
|
45
|
+
// Trimming is to account for the case of pressing the Spacebar more than once,
|
|
46
|
+
// which should cycle through the selection/deselection of the focused item.
|
|
47
|
+
if (character === ' ' && state.search.trim().length > 0) {
|
|
48
|
+
e.preventDefault();
|
|
49
|
+
if (!('continuePropagation' in e)) e.stopPropagation();
|
|
50
|
+
}
|
|
51
|
+
state.search += character;
|
|
52
|
+
// Use the delegate to find a key to focus.
|
|
53
|
+
// Prioritize items after the currently focused item, falling back to searching the whole list.
|
|
54
|
+
let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);
|
|
55
|
+
// If no key found, search from the top.
|
|
56
|
+
if (key == null) key = keyboardDelegate.getKeyForSearch(state.search);
|
|
57
|
+
if (key != null) {
|
|
58
|
+
selectionManager.setFocusedKey(key);
|
|
59
|
+
if (onTypeSelect) onTypeSelect(key);
|
|
60
|
+
}
|
|
61
|
+
clearTimeout(state.timeout);
|
|
62
|
+
state.timeout = setTimeout(()=>{
|
|
63
|
+
state.search = '';
|
|
64
|
+
}, 500);
|
|
65
|
+
};
|
|
66
|
+
return {
|
|
67
|
+
typeSelectProps: {
|
|
68
|
+
// Using a capturing listener to catch the keydown event before
|
|
69
|
+
// other hooks in order to handle the Spacebar event.
|
|
70
|
+
onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null
|
|
134
71
|
}
|
|
135
|
-
}
|
|
136
72
|
};
|
|
73
|
+
}
|
|
74
|
+
function $eb39f547daf47539$var$getStringForKey(key) {
|
|
75
|
+
// If the key is of length 1, it is an ASCII value.
|
|
76
|
+
// Otherwise, if there are no ASCII characters in the key name,
|
|
77
|
+
// it is a Unicode character.
|
|
78
|
+
// See https://www.w3.org/TR/uievents-key/
|
|
79
|
+
if (key.length === 1 || !/^[A-Z]/i.test(key)) return key;
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
137
82
|
|
|
138
|
-
switch (e.key) {
|
|
139
|
-
case 'ArrowDown':
|
|
140
|
-
{
|
|
141
|
-
if (delegate.getKeyBelow) {
|
|
142
|
-
e.preventDefault();
|
|
143
|
-
let nextKey = manager.focusedKey != null ? delegate.getKeyBelow(manager.focusedKey) : delegate.getFirstKey == null ? void 0 : delegate.getFirstKey();
|
|
144
83
|
|
|
145
|
-
|
|
146
|
-
|
|
84
|
+
function $f2918947066e8d51$export$d6daf82dcd84e87c(options) {
|
|
85
|
+
let { selectionManager: manager , keyboardDelegate: delegate , ref: ref , autoFocus: autoFocus = false , shouldFocusWrap: shouldFocusWrap = false , disallowEmptySelection: disallowEmptySelection = false , disallowSelectAll: disallowSelectAll = false , selectOnFocus: selectOnFocus = manager.selectionBehavior === 'replace' , disallowTypeAhead: disallowTypeAhead = false , shouldUseVirtualFocus: shouldUseVirtualFocus , allowsTabNavigation: allowsTabNavigation = false , isVirtualized: isVirtualized , scrollRef: // If no scrollRef is provided, assume the collection ref is the scrollable region
|
|
86
|
+
scrollRef = ref } = options;
|
|
87
|
+
let { direction: direction } = $1GWK5$useLocale();
|
|
88
|
+
let onKeyDown = (e)=>{
|
|
89
|
+
// Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes
|
|
90
|
+
if (e.altKey && e.key === 'Tab') e.preventDefault();
|
|
91
|
+
// Keyboard events bubble through portals. Don't handle keyboard events
|
|
92
|
+
// for elements outside the collection (e.g. menus).
|
|
93
|
+
if (!ref.current.contains(e.target)) return;
|
|
94
|
+
const navigateToKey = (key, childFocus)=>{
|
|
95
|
+
if (key != null) {
|
|
96
|
+
manager.setFocusedKey(key, childFocus);
|
|
97
|
+
if (e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(key);
|
|
98
|
+
else if (selectOnFocus && !$003bf7ca80eac51f$export$d3e3bd3e26688c04(e)) manager.replaceSelection(key);
|
|
147
99
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
100
|
+
};
|
|
101
|
+
switch(e.key){
|
|
102
|
+
case 'ArrowDown':
|
|
103
|
+
if (delegate.getKeyBelow) {
|
|
104
|
+
e.preventDefault();
|
|
105
|
+
let nextKey = manager.focusedKey != null ? delegate.getKeyBelow(manager.focusedKey) : delegate.getFirstKey?.();
|
|
106
|
+
if (nextKey == null && shouldFocusWrap) nextKey = delegate.getFirstKey?.(manager.focusedKey);
|
|
107
|
+
navigateToKey(nextKey);
|
|
108
|
+
}
|
|
109
|
+
break;
|
|
110
|
+
case 'ArrowUp':
|
|
111
|
+
if (delegate.getKeyAbove) {
|
|
112
|
+
e.preventDefault();
|
|
113
|
+
let nextKey = manager.focusedKey != null ? delegate.getKeyAbove(manager.focusedKey) : delegate.getLastKey?.();
|
|
114
|
+
if (nextKey == null && shouldFocusWrap) nextKey = delegate.getLastKey?.(manager.focusedKey);
|
|
115
|
+
navigateToKey(nextKey);
|
|
116
|
+
}
|
|
117
|
+
break;
|
|
118
|
+
case 'ArrowLeft':
|
|
119
|
+
if (delegate.getKeyLeftOf) {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
let nextKey = delegate.getKeyLeftOf(manager.focusedKey);
|
|
122
|
+
navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');
|
|
123
|
+
}
|
|
124
|
+
break;
|
|
125
|
+
case 'ArrowRight':
|
|
126
|
+
if (delegate.getKeyRightOf) {
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
let nextKey = delegate.getKeyRightOf(manager.focusedKey);
|
|
129
|
+
navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');
|
|
130
|
+
}
|
|
131
|
+
break;
|
|
132
|
+
case 'Home':
|
|
133
|
+
if (delegate.getFirstKey) {
|
|
134
|
+
e.preventDefault();
|
|
135
|
+
let firstKey = delegate.getFirstKey(manager.focusedKey, $003bf7ca80eac51f$export$16792effe837dba3(e));
|
|
136
|
+
manager.setFocusedKey(firstKey);
|
|
137
|
+
if ($003bf7ca80eac51f$export$16792effe837dba3(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(firstKey);
|
|
138
|
+
else if (selectOnFocus) manager.replaceSelection(firstKey);
|
|
139
|
+
}
|
|
140
|
+
break;
|
|
141
|
+
case 'End':
|
|
142
|
+
if (delegate.getLastKey) {
|
|
143
|
+
e.preventDefault();
|
|
144
|
+
let lastKey = delegate.getLastKey(manager.focusedKey, $003bf7ca80eac51f$export$16792effe837dba3(e));
|
|
145
|
+
manager.setFocusedKey(lastKey);
|
|
146
|
+
if ($003bf7ca80eac51f$export$16792effe837dba3(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(lastKey);
|
|
147
|
+
else if (selectOnFocus) manager.replaceSelection(lastKey);
|
|
148
|
+
}
|
|
149
|
+
break;
|
|
150
|
+
case 'PageDown':
|
|
151
|
+
if (delegate.getKeyPageBelow) {
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
let nextKey = delegate.getKeyPageBelow(manager.focusedKey);
|
|
154
|
+
navigateToKey(nextKey);
|
|
155
|
+
}
|
|
156
|
+
break;
|
|
157
|
+
case 'PageUp':
|
|
158
|
+
if (delegate.getKeyPageAbove) {
|
|
159
|
+
e.preventDefault();
|
|
160
|
+
let nextKey = delegate.getKeyPageAbove(manager.focusedKey);
|
|
161
|
+
navigateToKey(nextKey);
|
|
162
|
+
}
|
|
163
|
+
break;
|
|
164
|
+
case 'a':
|
|
165
|
+
if ($003bf7ca80eac51f$export$16792effe837dba3(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {
|
|
166
|
+
e.preventDefault();
|
|
167
|
+
manager.selectAll();
|
|
168
|
+
}
|
|
169
|
+
break;
|
|
170
|
+
case 'Escape':
|
|
171
|
+
e.preventDefault();
|
|
172
|
+
if (!disallowEmptySelection) manager.clearSelection();
|
|
173
|
+
break;
|
|
174
|
+
case 'Tab':
|
|
175
|
+
if (!allowsTabNavigation) {
|
|
176
|
+
// There may be elements that are "tabbable" inside a collection (e.g. in a grid cell).
|
|
177
|
+
// However, collections should be treated as a single tab stop, with arrow key navigation internally.
|
|
178
|
+
// We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.
|
|
179
|
+
// Instead, we handle the Tab key, and move focus manually to the first/last tabbable element
|
|
180
|
+
// in the collection, so that the browser default behavior will apply starting from that element
|
|
181
|
+
// rather than the currently focused one.
|
|
182
|
+
if (e.shiftKey) ref.current.focus();
|
|
183
|
+
else {
|
|
184
|
+
let walker = $1GWK5$getFocusableTreeWalker(ref.current, {
|
|
185
|
+
tabbable: true
|
|
186
|
+
});
|
|
187
|
+
let next;
|
|
188
|
+
let last;
|
|
189
|
+
do {
|
|
190
|
+
last = walker.lastChild();
|
|
191
|
+
if (last) next = last;
|
|
192
|
+
}while (last)
|
|
193
|
+
if (next && !next.contains(document.activeElement)) $1GWK5$focusWithoutScrolling(next);
|
|
194
|
+
}
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
153
197
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
198
|
+
};
|
|
199
|
+
// Store the scroll position so we can restore it later.
|
|
200
|
+
let scrollPos = $1GWK5$useRef({
|
|
201
|
+
top: 0,
|
|
202
|
+
left: 0
|
|
203
|
+
});
|
|
204
|
+
$1GWK5$useEvent(scrollRef, 'scroll', isVirtualized ? null : ()=>{
|
|
205
|
+
scrollPos.current = {
|
|
206
|
+
top: scrollRef.current.scrollTop,
|
|
207
|
+
left: scrollRef.current.scrollLeft
|
|
208
|
+
};
|
|
209
|
+
});
|
|
210
|
+
let onFocus = (e)=>{
|
|
211
|
+
if (manager.isFocused) {
|
|
212
|
+
// If a focus event bubbled through a portal, reset focus state.
|
|
213
|
+
if (!e.currentTarget.contains(e.target)) manager.setFocused(false);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
// Focus events can bubble through portals. Ignore these events.
|
|
217
|
+
if (!e.currentTarget.contains(e.target)) return;
|
|
218
|
+
manager.setFocused(true);
|
|
219
|
+
if (manager.focusedKey == null) {
|
|
220
|
+
let navigateToFirstKey = (key)=>{
|
|
221
|
+
if (key != null) {
|
|
222
|
+
manager.setFocusedKey(key);
|
|
223
|
+
if (selectOnFocus) manager.replaceSelection(key);
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
// If the user hasn't yet interacted with the collection, there will be no focusedKey set.
|
|
227
|
+
// Attempt to detect whether the user is tabbing forward or backward into the collection
|
|
228
|
+
// and either focus the first or last item accordingly.
|
|
229
|
+
let relatedTarget = e.relatedTarget;
|
|
230
|
+
if (relatedTarget && e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING) navigateToFirstKey(manager.lastSelectedKey ?? delegate.getLastKey());
|
|
231
|
+
else navigateToFirstKey(manager.firstSelectedKey ?? delegate.getFirstKey());
|
|
232
|
+
} else if (!isVirtualized) {
|
|
233
|
+
// Restore the scroll position to what it was before.
|
|
234
|
+
scrollRef.current.scrollTop = scrollPos.current.top;
|
|
235
|
+
scrollRef.current.scrollLeft = scrollPos.current.left;
|
|
236
|
+
// Refocus and scroll the focused item into view if it exists within the scrollable region.
|
|
237
|
+
let element = scrollRef.current.querySelector(`[data-key="${manager.focusedKey}"]`);
|
|
238
|
+
if (element) {
|
|
239
|
+
// This prevents a flash of focus on the first/last element in the collection
|
|
240
|
+
$1GWK5$focusWithoutScrolling(element);
|
|
241
|
+
$1GWK5$scrollIntoView(scrollRef.current, element);
|
|
163
242
|
}
|
|
164
|
-
|
|
165
|
-
navigateToKey(nextKey);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
break;
|
|
169
243
|
}
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
244
|
+
};
|
|
245
|
+
let onBlur = (e)=>{
|
|
246
|
+
// Don't set blurred and then focused again if moving focus within the collection.
|
|
247
|
+
if (!e.currentTarget.contains(e.relatedTarget)) manager.setFocused(false);
|
|
248
|
+
};
|
|
249
|
+
const autoFocusRef = $1GWK5$useRef(autoFocus);
|
|
250
|
+
$1GWK5$useEffect(()=>{
|
|
251
|
+
if (autoFocusRef.current) {
|
|
252
|
+
let focusedKey = null;
|
|
253
|
+
// Check focus strategy to determine which item to focus
|
|
254
|
+
if (autoFocus === 'first') focusedKey = delegate.getFirstKey();
|
|
255
|
+
if (autoFocus === 'last') focusedKey = delegate.getLastKey();
|
|
256
|
+
// If there are any selected keys, make the first one the new focus target
|
|
257
|
+
let selectedKeys = manager.selectedKeys;
|
|
258
|
+
if (selectedKeys.size) focusedKey = selectedKeys.values().next().value;
|
|
259
|
+
manager.setFocused(true);
|
|
260
|
+
manager.setFocusedKey(focusedKey);
|
|
261
|
+
// If no default focus key is selected, focus the collection itself.
|
|
262
|
+
if (focusedKey == null && !shouldUseVirtualFocus) $1GWK5$focusSafely(ref.current);
|
|
180
263
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
264
|
+
autoFocusRef.current = false;
|
|
265
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
266
|
+
}, []);
|
|
267
|
+
// If not virtualized, scroll the focused element into view when the focusedKey changes.
|
|
268
|
+
// When virtualized, Virtualizer handles this internally.
|
|
269
|
+
$1GWK5$useEffect(()=>{
|
|
270
|
+
if (!isVirtualized && manager.focusedKey && scrollRef?.current) {
|
|
271
|
+
let element = scrollRef.current.querySelector(`[data-key="${manager.focusedKey}"]`);
|
|
272
|
+
if (element) $1GWK5$scrollIntoView(scrollRef.current, element);
|
|
273
|
+
}
|
|
274
|
+
}, [
|
|
275
|
+
isVirtualized,
|
|
276
|
+
scrollRef,
|
|
277
|
+
manager.focusedKey
|
|
278
|
+
]);
|
|
279
|
+
let handlers = {
|
|
280
|
+
onKeyDown: onKeyDown,
|
|
281
|
+
onFocus: onFocus,
|
|
282
|
+
onBlur: onBlur,
|
|
283
|
+
onMouseDown (e) {
|
|
284
|
+
// Ignore events that bubbled through portals.
|
|
285
|
+
if (e.currentTarget.contains(e.target)) // Prevent focus going to the collection when clicking on the scrollbar.
|
|
185
286
|
e.preventDefault();
|
|
186
|
-
let nextKey = delegate.getKeyRightOf(manager.focusedKey);
|
|
187
|
-
navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
break;
|
|
191
287
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
288
|
+
};
|
|
289
|
+
let { typeSelectProps: typeSelectProps } = $eb39f547daf47539$export$e32c88dfddc6e1d8({
|
|
290
|
+
keyboardDelegate: delegate,
|
|
291
|
+
selectionManager: manager
|
|
292
|
+
});
|
|
293
|
+
if (!disallowTypeAhead) handlers = $1GWK5$mergeProps(typeSelectProps, handlers);
|
|
294
|
+
// If nothing is focused within the collection, make the collection itself tabbable.
|
|
295
|
+
// This will be marshalled to either the first or last item depending on where focus came from.
|
|
296
|
+
// If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try
|
|
297
|
+
// to move real DOM focus to the element anyway.
|
|
298
|
+
let tabIndex;
|
|
299
|
+
if (!shouldUseVirtualFocus) tabIndex = manager.focusedKey == null ? 0 : -1;
|
|
300
|
+
return {
|
|
301
|
+
collectionProps: {
|
|
302
|
+
...handlers,
|
|
303
|
+
tabIndex: tabIndex
|
|
204
304
|
}
|
|
305
|
+
};
|
|
306
|
+
}
|
|
205
307
|
|
|
206
|
-
break;
|
|
207
|
-
|
|
208
|
-
case 'End':
|
|
209
|
-
if (delegate.getLastKey) {
|
|
210
|
-
e.preventDefault();
|
|
211
|
-
let lastKey = delegate.getLastKey(manager.focusedKey, $a9b9aa71af07c56ab1d89ca45381f4b$var$isCtrlKeyPressed(e));
|
|
212
|
-
manager.setFocusedKey(lastKey);
|
|
213
308
|
|
|
214
|
-
|
|
215
|
-
manager.extendSelection(lastKey);
|
|
216
|
-
} else if (selectOnFocus) {
|
|
217
|
-
manager.replaceSelection(lastKey);
|
|
218
|
-
}
|
|
219
|
-
}
|
|
309
|
+
var $28b3f01514e02622$exports = {};
|
|
220
310
|
|
|
221
|
-
|
|
311
|
+
$parcel$export($28b3f01514e02622$exports, "useSelectableItem", () => $28b3f01514e02622$export$ecf600387e221c37);
|
|
222
312
|
|
|
223
|
-
case 'PageDown':
|
|
224
|
-
if (delegate.getKeyPageBelow) {
|
|
225
|
-
e.preventDefault();
|
|
226
|
-
let nextKey = delegate.getKeyPageBelow(manager.focusedKey);
|
|
227
|
-
navigateToKey(nextKey);
|
|
228
|
-
}
|
|
229
313
|
|
|
230
|
-
break;
|
|
231
314
|
|
|
232
|
-
case 'PageUp':
|
|
233
|
-
if (delegate.getKeyPageAbove) {
|
|
234
|
-
e.preventDefault();
|
|
235
|
-
let nextKey = delegate.getKeyPageAbove(manager.focusedKey);
|
|
236
|
-
navigateToKey(nextKey);
|
|
237
|
-
}
|
|
238
315
|
|
|
239
|
-
break;
|
|
240
316
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
317
|
+
function $28b3f01514e02622$export$ecf600387e221c37(options) {
|
|
318
|
+
let { selectionManager: manager , key: key , ref: ref , shouldSelectOnPressUp: shouldSelectOnPressUp , isVirtualized: isVirtualized , shouldUseVirtualFocus: shouldUseVirtualFocus , focus: focus , isDisabled: isDisabled , onAction: onAction } = options;
|
|
319
|
+
let onSelect = (e)=>{
|
|
320
|
+
if (e.pointerType === 'keyboard' && $003bf7ca80eac51f$export$d3e3bd3e26688c04(e)) manager.toggleSelection(key);
|
|
321
|
+
else {
|
|
322
|
+
if (manager.selectionMode === 'none') return;
|
|
323
|
+
if (manager.selectionMode === 'single') {
|
|
324
|
+
if (manager.isSelected(key) && !manager.disallowEmptySelection) manager.toggleSelection(key);
|
|
325
|
+
else manager.replaceSelection(key);
|
|
326
|
+
} else if (e && e.shiftKey) manager.extendSelection(key);
|
|
327
|
+
else if (manager.selectionBehavior === 'toggle' || e && ($003bf7ca80eac51f$export$16792effe837dba3(e) || e.pointerType === 'touch' || e.pointerType === 'virtual')) // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys
|
|
328
|
+
manager.toggleSelection(key);
|
|
329
|
+
else manager.replaceSelection(key);
|
|
245
330
|
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
manager.clearSelection();
|
|
331
|
+
};
|
|
332
|
+
// Focus the associated DOM node when this item becomes the focusedKey
|
|
333
|
+
let isFocused = key === manager.focusedKey;
|
|
334
|
+
$1GWK5$useEffect(()=>{
|
|
335
|
+
if (isFocused && manager.isFocused && !shouldUseVirtualFocus && document.activeElement !== ref.current) {
|
|
336
|
+
if (focus) focus();
|
|
337
|
+
else $1GWK5$focusSafely(ref.current);
|
|
254
338
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
});
|
|
273
|
-
let next;
|
|
274
|
-
let last;
|
|
275
|
-
|
|
276
|
-
do {
|
|
277
|
-
last = walker.lastChild();
|
|
278
|
-
|
|
279
|
-
if (last) {
|
|
280
|
-
next = last;
|
|
281
|
-
}
|
|
282
|
-
} while (last);
|
|
283
|
-
|
|
284
|
-
if (next && !next.contains(document.activeElement)) {
|
|
285
|
-
focusWithoutScrolling(next);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
break;
|
|
290
|
-
}
|
|
339
|
+
}, [
|
|
340
|
+
ref,
|
|
341
|
+
isFocused,
|
|
342
|
+
manager.focusedKey,
|
|
343
|
+
manager.childFocusStrategy,
|
|
344
|
+
manager.isFocused,
|
|
345
|
+
shouldUseVirtualFocus
|
|
346
|
+
]);
|
|
347
|
+
// Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused
|
|
348
|
+
// item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver
|
|
349
|
+
// on iOS 14 doesn't try to move real DOM focus to the item anyway.
|
|
350
|
+
let itemProps = {
|
|
351
|
+
};
|
|
352
|
+
if (!shouldUseVirtualFocus) itemProps = {
|
|
353
|
+
tabIndex: isFocused ? 0 : -1,
|
|
354
|
+
onFocus (e) {
|
|
355
|
+
if (e.target === ref.current) manager.setFocusedKey(key);
|
|
291
356
|
}
|
|
357
|
+
};
|
|
358
|
+
let modality = $1GWK5$useRef(null);
|
|
359
|
+
let hasPrimaryAction = onAction && manager.selectionMode === 'none';
|
|
360
|
+
let hasSecondaryAction = onAction && manager.selectionMode !== 'none' && manager.selectionBehavior === 'replace';
|
|
361
|
+
let allowsSelection = !isDisabled && manager.canSelectItem(key);
|
|
362
|
+
// By default, selection occurs on pointer down. This can be strange if selecting an
|
|
363
|
+
// item causes the UI to disappear immediately (e.g. menus).
|
|
364
|
+
// If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.
|
|
365
|
+
// onPress requires a pointer down event on the same element as pointer up. For menus,
|
|
366
|
+
// we want to be able to have the pointer down on the trigger that opens the menu and
|
|
367
|
+
// the pointer up on the menu item rather than requiring a separate press.
|
|
368
|
+
// For keyboard events, selection still occurs on key down.
|
|
369
|
+
let itemPressProps = {
|
|
370
|
+
};
|
|
371
|
+
if (shouldSelectOnPressUp) {
|
|
372
|
+
itemPressProps.onPressStart = (e)=>{
|
|
373
|
+
modality.current = e.pointerType;
|
|
374
|
+
if (e.pointerType === 'keyboard') onSelect(e);
|
|
375
|
+
};
|
|
376
|
+
itemPressProps.onPressUp = (e)=>{
|
|
377
|
+
if (e.pointerType !== 'keyboard') onSelect(e);
|
|
378
|
+
};
|
|
379
|
+
itemPressProps.onPress = hasPrimaryAction ? ()=>onAction()
|
|
380
|
+
: null;
|
|
381
|
+
} else {
|
|
382
|
+
// On touch, it feels strange to select on touch down, so we special case this.
|
|
383
|
+
itemPressProps.onPressStart = (e)=>{
|
|
384
|
+
modality.current = e.pointerType;
|
|
385
|
+
if (e.pointerType !== 'touch' && e.pointerType !== 'virtual') onSelect(e);
|
|
386
|
+
};
|
|
387
|
+
itemPressProps.onPress = (e)=>{
|
|
388
|
+
if (e.pointerType === 'touch' || e.pointerType === 'virtual' || hasPrimaryAction) {
|
|
389
|
+
// Single tap on touch with selectionBehavior = 'replace' performs an action, i.e. navigation.
|
|
390
|
+
// Also perform action on press up when selectionMode = 'none'.
|
|
391
|
+
if (hasPrimaryAction || hasSecondaryAction) onAction();
|
|
392
|
+
else onSelect(e);
|
|
393
|
+
}
|
|
394
|
+
};
|
|
292
395
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
|
|
396
|
+
if (!isVirtualized) itemProps['data-key'] = key;
|
|
397
|
+
itemPressProps.preventFocusOnPress = shouldUseVirtualFocus;
|
|
398
|
+
let { pressProps: pressProps , isPressed: isPressed } = $1GWK5$usePress(itemPressProps);
|
|
399
|
+
// Double clicking with a mouse with selectionBehavior = 'replace' performs an action.
|
|
400
|
+
let onDoubleClick = hasSecondaryAction ? (e)=>{
|
|
401
|
+
if (modality.current === 'mouse') {
|
|
402
|
+
e.stopPropagation();
|
|
403
|
+
e.preventDefault();
|
|
404
|
+
onAction();
|
|
405
|
+
}
|
|
406
|
+
} : undefined;
|
|
407
|
+
// Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior
|
|
408
|
+
// to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to
|
|
409
|
+
// selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.
|
|
410
|
+
// TODO: what about when drag and drop is also enabled??
|
|
411
|
+
let { longPressProps: longPressProps } = $1GWK5$useLongPress({
|
|
412
|
+
isDisabled: !hasSecondaryAction,
|
|
413
|
+
onLongPress (e) {
|
|
414
|
+
if (e.pointerType === 'touch') {
|
|
415
|
+
onSelect(e);
|
|
416
|
+
manager.setSelectionBehavior('toggle');
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
// Pressing the Enter key with selectionBehavior = 'replace' performs an action (i.e. navigation).
|
|
421
|
+
let onKeyUp = hasSecondaryAction ? (e)=>{
|
|
422
|
+
if (e.key === 'Enter') onAction();
|
|
423
|
+
} : undefined;
|
|
424
|
+
return {
|
|
425
|
+
itemProps: $1GWK5$mergeProps(itemProps, allowsSelection || hasPrimaryAction ? pressProps : {
|
|
426
|
+
}, hasSecondaryAction ? longPressProps : {
|
|
427
|
+
}, {
|
|
428
|
+
onKeyUp: onKeyUp,
|
|
429
|
+
onDoubleClick: onDoubleClick
|
|
430
|
+
}),
|
|
431
|
+
isPressed: isPressed
|
|
432
|
+
};
|
|
433
|
+
}
|
|
311
434
|
|
|
312
|
-
if (manager.focusedKey == null) {
|
|
313
|
-
// If the user hasn't yet interacted with the collection, there will be no focusedKey set.
|
|
314
|
-
// Attempt to detect whether the user is tabbing forward or backward into the collection
|
|
315
|
-
// and either focus the first or last item accordingly.
|
|
316
|
-
let relatedTarget = e.relatedTarget;
|
|
317
435
|
|
|
318
|
-
|
|
319
|
-
var _manager$lastSelected;
|
|
436
|
+
var $95210d28646fd635$exports = {};
|
|
320
437
|
|
|
321
|
-
|
|
322
|
-
} else {
|
|
323
|
-
var _manager$firstSelecte;
|
|
438
|
+
$parcel$export($95210d28646fd635$exports, "useSelectableList", () => $95210d28646fd635$export$b95089534ab7c1fd);
|
|
324
439
|
|
|
325
|
-
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
};
|
|
440
|
+
var $57c17da9c35ecb23$exports = {};
|
|
329
441
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
442
|
+
$parcel$export($57c17da9c35ecb23$exports, "ListKeyboardDelegate", () => $57c17da9c35ecb23$export$a05409b8bb224a5a);
|
|
443
|
+
class $57c17da9c35ecb23$export$a05409b8bb224a5a {
|
|
444
|
+
constructor(collection, disabledKeys, ref, collator){
|
|
445
|
+
this.collection = collection;
|
|
446
|
+
this.disabledKeys = disabledKeys;
|
|
447
|
+
this.ref = ref;
|
|
448
|
+
this.collator = collator;
|
|
334
449
|
}
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
if (autoFocus === 'first') {
|
|
343
|
-
focusedKey = delegate.getFirstKey();
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
if (autoFocus === 'last') {
|
|
347
|
-
focusedKey = delegate.getLastKey();
|
|
348
|
-
} // If there are any selected keys, make the first one the new focus target
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
let selectedKeys = manager.selectedKeys;
|
|
352
|
-
|
|
353
|
-
if (selectedKeys.size) {
|
|
354
|
-
focusedKey = selectedKeys.values().next().value;
|
|
355
|
-
}
|
|
356
|
-
|
|
357
|
-
manager.setFocused(true);
|
|
358
|
-
manager.setFocusedKey(focusedKey); // If no default focus key is selected, focus the collection itself.
|
|
359
|
-
|
|
360
|
-
if (focusedKey == null && !shouldUseVirtualFocus) {
|
|
361
|
-
focusSafely(ref.current);
|
|
362
|
-
}
|
|
450
|
+
getKeyBelow(key) {
|
|
451
|
+
key = this.collection.getKeyAfter(key);
|
|
452
|
+
while(key != null){
|
|
453
|
+
let item = this.collection.getItem(key);
|
|
454
|
+
if (item.type === 'item' && !this.disabledKeys.has(key)) return key;
|
|
455
|
+
key = this.collection.getKeyAfter(key);
|
|
456
|
+
}
|
|
363
457
|
}
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
onMouseDown(e) {
|
|
373
|
-
// Ignore events that bubbled through portals.
|
|
374
|
-
if (e.currentTarget.contains(e.target)) {
|
|
375
|
-
// Prevent focus going to the collection when clicking on the scrollbar.
|
|
376
|
-
e.preventDefault();
|
|
377
|
-
}
|
|
458
|
+
getKeyAbove(key) {
|
|
459
|
+
key = this.collection.getKeyBefore(key);
|
|
460
|
+
while(key != null){
|
|
461
|
+
let item = this.collection.getItem(key);
|
|
462
|
+
if (item.type === 'item' && !this.disabledKeys.has(key)) return key;
|
|
463
|
+
key = this.collection.getKeyBefore(key);
|
|
464
|
+
}
|
|
378
465
|
}
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
if (!disallowTypeAhead) {
|
|
389
|
-
handlers = mergeProps(typeSelectProps, handlers);
|
|
390
|
-
} // If nothing is focused within the collection, make the collection itself tabbable.
|
|
391
|
-
// This will be marshalled to either the first or last item depending on where focus came from.
|
|
392
|
-
// If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try
|
|
393
|
-
// to move real DOM focus to the element anyway.
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
let tabIndex;
|
|
397
|
-
|
|
398
|
-
if (!shouldUseVirtualFocus) {
|
|
399
|
-
tabIndex = manager.focusedKey == null ? 0 : -1;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
return {
|
|
403
|
-
collectionProps: _babelRuntimeHelpersEsmExtends({}, handlers, {
|
|
404
|
-
tabIndex
|
|
405
|
-
})
|
|
406
|
-
};
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
/**
|
|
410
|
-
* Handles interactions with an item in a selectable collection.
|
|
411
|
-
*/
|
|
412
|
-
export function useSelectableItem(options) {
|
|
413
|
-
let {
|
|
414
|
-
selectionManager: manager,
|
|
415
|
-
key,
|
|
416
|
-
ref,
|
|
417
|
-
shouldSelectOnPressUp,
|
|
418
|
-
isVirtualized,
|
|
419
|
-
shouldUseVirtualFocus,
|
|
420
|
-
focus
|
|
421
|
-
} = options;
|
|
422
|
-
|
|
423
|
-
let onSelect = e => manager.select(key, e); // Focus the associated DOM node when this item becomes the focusedKey
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
let isFocused = key === manager.focusedKey;
|
|
427
|
-
useEffect(() => {
|
|
428
|
-
if (isFocused && manager.isFocused && !shouldUseVirtualFocus && document.activeElement !== ref.current) {
|
|
429
|
-
if (focus) {
|
|
430
|
-
focus();
|
|
431
|
-
} else {
|
|
432
|
-
focusSafely(ref.current);
|
|
433
|
-
}
|
|
466
|
+
getFirstKey() {
|
|
467
|
+
let key = this.collection.getFirstKey();
|
|
468
|
+
while(key != null){
|
|
469
|
+
let item = this.collection.getItem(key);
|
|
470
|
+
if (item.type === 'item' && !this.disabledKeys.has(key)) return key;
|
|
471
|
+
key = this.collection.getKeyAfter(key);
|
|
472
|
+
}
|
|
434
473
|
}
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
if (!shouldUseVirtualFocus) {
|
|
442
|
-
itemProps = {
|
|
443
|
-
tabIndex: isFocused ? 0 : -1,
|
|
444
|
-
|
|
445
|
-
onFocus(e) {
|
|
446
|
-
if (e.target === ref.current) {
|
|
447
|
-
manager.setFocusedKey(key);
|
|
474
|
+
getLastKey() {
|
|
475
|
+
let key = this.collection.getLastKey();
|
|
476
|
+
while(key != null){
|
|
477
|
+
let item = this.collection.getItem(key);
|
|
478
|
+
if (item.type === 'item' && !this.disabledKeys.has(key)) return key;
|
|
479
|
+
key = this.collection.getKeyBefore(key);
|
|
448
480
|
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
};
|
|
452
|
-
} // By default, selection occurs on pointer down. This can be strange if selecting an
|
|
453
|
-
// item causes the UI to disappear immediately (e.g. menus).
|
|
454
|
-
// If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.
|
|
455
|
-
// onPress requires a pointer down event on the same element as pointer up. For menus,
|
|
456
|
-
// we want to be able to have the pointer down on the trigger that opens the menu and
|
|
457
|
-
// the pointer up on the menu item rather than requiring a separate press.
|
|
458
|
-
// For keyboard events, selection still occurs on key down.
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
if (shouldSelectOnPressUp) {
|
|
462
|
-
itemProps.onPressStart = e => {
|
|
463
|
-
if (e.pointerType === 'keyboard') {
|
|
464
|
-
onSelect(e);
|
|
465
|
-
}
|
|
466
|
-
};
|
|
467
|
-
|
|
468
|
-
itemProps.onPressUp = e => {
|
|
469
|
-
if (e.pointerType !== 'keyboard') {
|
|
470
|
-
onSelect(e);
|
|
471
|
-
}
|
|
472
|
-
};
|
|
473
|
-
} else {
|
|
474
|
-
// On touch, it feels strange to select on touch down, so we special case this.
|
|
475
|
-
itemProps.onPressStart = e => {
|
|
476
|
-
if (e.pointerType !== 'touch') {
|
|
477
|
-
onSelect(e);
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
|
|
481
|
-
itemProps.onPress = e => {
|
|
482
|
-
if (e.pointerType === 'touch') {
|
|
483
|
-
onSelect(e);
|
|
484
|
-
}
|
|
485
|
-
};
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
if (!isVirtualized) {
|
|
489
|
-
itemProps['data-key'] = key;
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
return {
|
|
493
|
-
itemProps
|
|
494
|
-
};
|
|
495
|
-
}
|
|
496
|
-
|
|
497
|
-
/*
|
|
498
|
-
* Copyright 2020 Adobe. All rights reserved.
|
|
499
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
500
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
501
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
502
|
-
*
|
|
503
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
504
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
505
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
506
|
-
* governing permissions and limitations under the License.
|
|
507
|
-
*/
|
|
508
|
-
export class ListKeyboardDelegate {
|
|
509
|
-
constructor(collection, disabledKeys, ref, collator) {
|
|
510
|
-
this.collection = void 0;
|
|
511
|
-
this.disabledKeys = void 0;
|
|
512
|
-
this.ref = void 0;
|
|
513
|
-
this.collator = void 0;
|
|
514
|
-
this.collection = collection;
|
|
515
|
-
this.disabledKeys = disabledKeys;
|
|
516
|
-
this.ref = ref;
|
|
517
|
-
this.collator = collator;
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
getKeyBelow(key) {
|
|
521
|
-
key = this.collection.getKeyAfter(key);
|
|
522
|
-
|
|
523
|
-
while (key != null) {
|
|
524
|
-
let item = this.collection.getItem(key);
|
|
525
|
-
|
|
526
|
-
if (item.type === 'item' && !this.disabledKeys.has(key)) {
|
|
527
|
-
return key;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
key = this.collection.getKeyAfter(key);
|
|
531
481
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
getKeyAbove(key) {
|
|
535
|
-
key = this.collection.getKeyBefore(key);
|
|
536
|
-
|
|
537
|
-
while (key != null) {
|
|
538
|
-
let item = this.collection.getItem(key);
|
|
539
|
-
|
|
540
|
-
if (item.type === 'item' && !this.disabledKeys.has(key)) {
|
|
541
|
-
return key;
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
key = this.collection.getKeyBefore(key);
|
|
482
|
+
getItem(key) {
|
|
483
|
+
return this.ref.current.querySelector(`[data-key="${key}"]`);
|
|
545
484
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
485
|
+
getKeyPageAbove(key) {
|
|
486
|
+
let menu = this.ref.current;
|
|
487
|
+
let item = this.getItem(key);
|
|
488
|
+
if (!item) return null;
|
|
489
|
+
let pageY = Math.max(0, item.offsetTop + item.offsetHeight - menu.offsetHeight);
|
|
490
|
+
while(item && item.offsetTop > pageY){
|
|
491
|
+
key = this.getKeyAbove(key);
|
|
492
|
+
item = this.getItem(key);
|
|
493
|
+
}
|
|
555
494
|
return key;
|
|
556
|
-
}
|
|
557
|
-
|
|
558
|
-
key = this.collection.getKeyAfter(key);
|
|
559
495
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
496
|
+
getKeyPageBelow(key) {
|
|
497
|
+
let menu = this.ref.current;
|
|
498
|
+
let item = this.getItem(key);
|
|
499
|
+
if (!item) return null;
|
|
500
|
+
let pageY = Math.min(menu.scrollHeight, item.offsetTop - item.offsetHeight + menu.offsetHeight);
|
|
501
|
+
while(item && item.offsetTop < pageY){
|
|
502
|
+
key = this.getKeyBelow(key);
|
|
503
|
+
item = this.getItem(key);
|
|
504
|
+
}
|
|
569
505
|
return key;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
key = this.collection.getKeyBefore(key);
|
|
573
|
-
}
|
|
574
|
-
}
|
|
575
|
-
|
|
576
|
-
getItem(key) {
|
|
577
|
-
return this.ref.current.querySelector("[data-key=\"" + key + "\"]");
|
|
578
|
-
}
|
|
579
|
-
|
|
580
|
-
getKeyPageAbove(key) {
|
|
581
|
-
let menu = this.ref.current;
|
|
582
|
-
let item = this.getItem(key);
|
|
583
|
-
|
|
584
|
-
if (!item) {
|
|
585
|
-
return null;
|
|
586
|
-
}
|
|
587
|
-
|
|
588
|
-
let pageY = Math.max(0, item.offsetTop + item.offsetHeight - menu.offsetHeight);
|
|
589
|
-
|
|
590
|
-
while (item && item.offsetTop > pageY) {
|
|
591
|
-
key = this.getKeyAbove(key);
|
|
592
|
-
item = this.getItem(key);
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
return key;
|
|
596
|
-
}
|
|
597
|
-
|
|
598
|
-
getKeyPageBelow(key) {
|
|
599
|
-
let menu = this.ref.current;
|
|
600
|
-
let item = this.getItem(key);
|
|
601
|
-
|
|
602
|
-
if (!item) {
|
|
603
|
-
return null;
|
|
604
506
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
507
|
+
getKeyForSearch(search, fromKey) {
|
|
508
|
+
if (!this.collator) return null;
|
|
509
|
+
let collection = this.collection;
|
|
510
|
+
let key = fromKey || this.getFirstKey();
|
|
511
|
+
while(key != null){
|
|
512
|
+
let item = collection.getItem(key);
|
|
513
|
+
let substring = item.textValue.slice(0, search.length);
|
|
514
|
+
if (item.textValue && this.collator.compare(substring, search) === 0) return key;
|
|
515
|
+
key = this.getKeyBelow(key);
|
|
516
|
+
}
|
|
517
|
+
return null;
|
|
611
518
|
}
|
|
519
|
+
}
|
|
612
520
|
|
|
613
|
-
return key;
|
|
614
|
-
}
|
|
615
521
|
|
|
616
|
-
getKeyForSearch(search, fromKey) {
|
|
617
|
-
if (!this.collator) {
|
|
618
|
-
return null;
|
|
619
|
-
}
|
|
620
522
|
|
|
621
|
-
let collection = this.collection;
|
|
622
|
-
let key = fromKey || this.getFirstKey();
|
|
623
523
|
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
524
|
+
function $95210d28646fd635$export$b95089534ab7c1fd(props) {
|
|
525
|
+
let { selectionManager: selectionManager , collection: collection , disabledKeys: disabledKeys , ref: ref , keyboardDelegate: keyboardDelegate , autoFocus: autoFocus , shouldFocusWrap: shouldFocusWrap , isVirtualized: isVirtualized , disallowEmptySelection: disallowEmptySelection , selectOnFocus: selectOnFocus = false , disallowTypeAhead: disallowTypeAhead , shouldUseVirtualFocus: shouldUseVirtualFocus , allowsTabNavigation: allowsTabNavigation } = props;
|
|
526
|
+
// By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
|
|
527
|
+
// When virtualized, the layout object will be passed in as a prop and override this.
|
|
528
|
+
let collator = $1GWK5$useCollator({
|
|
529
|
+
usage: 'search',
|
|
530
|
+
sensitivity: 'base'
|
|
531
|
+
});
|
|
532
|
+
let delegate = $1GWK5$useMemo(()=>keyboardDelegate || new $57c17da9c35ecb23$export$a05409b8bb224a5a(collection, disabledKeys, ref, collator)
|
|
533
|
+
, [
|
|
534
|
+
keyboardDelegate,
|
|
535
|
+
collection,
|
|
536
|
+
disabledKeys,
|
|
537
|
+
ref,
|
|
538
|
+
collator
|
|
539
|
+
]);
|
|
540
|
+
let { collectionProps: collectionProps } = $f2918947066e8d51$export$d6daf82dcd84e87c({
|
|
541
|
+
ref: ref,
|
|
542
|
+
selectionManager: selectionManager,
|
|
543
|
+
keyboardDelegate: delegate,
|
|
544
|
+
autoFocus: autoFocus,
|
|
545
|
+
shouldFocusWrap: shouldFocusWrap,
|
|
546
|
+
disallowEmptySelection: disallowEmptySelection,
|
|
547
|
+
selectOnFocus: selectOnFocus,
|
|
548
|
+
disallowTypeAhead: disallowTypeAhead,
|
|
549
|
+
shouldUseVirtualFocus: shouldUseVirtualFocus,
|
|
550
|
+
allowsTabNavigation: allowsTabNavigation,
|
|
551
|
+
isVirtualized: isVirtualized,
|
|
552
|
+
scrollRef: ref
|
|
553
|
+
});
|
|
554
|
+
return {
|
|
555
|
+
listProps: collectionProps
|
|
556
|
+
};
|
|
557
|
+
}
|
|
631
558
|
|
|
632
|
-
key = this.getKeyBelow(key);
|
|
633
|
-
}
|
|
634
559
|
|
|
635
|
-
return null;
|
|
636
|
-
}
|
|
637
560
|
|
|
638
|
-
}
|
|
639
561
|
|
|
640
|
-
/**
|
|
641
|
-
* Handles interactions with a selectable list.
|
|
642
|
-
*/
|
|
643
|
-
export function useSelectableList(props) {
|
|
644
|
-
let {
|
|
645
|
-
selectionManager,
|
|
646
|
-
collection,
|
|
647
|
-
disabledKeys,
|
|
648
|
-
ref,
|
|
649
|
-
keyboardDelegate,
|
|
650
|
-
autoFocus,
|
|
651
|
-
shouldFocusWrap,
|
|
652
|
-
isVirtualized,
|
|
653
|
-
disallowEmptySelection,
|
|
654
|
-
selectOnFocus = false,
|
|
655
|
-
disallowTypeAhead,
|
|
656
|
-
shouldUseVirtualFocus,
|
|
657
|
-
allowsTabNavigation
|
|
658
|
-
} = props; // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
|
|
659
|
-
// When virtualized, the layout object will be passed in as a prop and override this.
|
|
660
|
-
|
|
661
|
-
let collator = useCollator({
|
|
662
|
-
usage: 'search',
|
|
663
|
-
sensitivity: 'base'
|
|
664
|
-
});
|
|
665
|
-
let delegate = useMemo(() => keyboardDelegate || new ListKeyboardDelegate(collection, disabledKeys, ref, collator), [keyboardDelegate, collection, disabledKeys, ref, collator]); // If not virtualized, scroll the focused element into view when the focusedKey changes.
|
|
666
|
-
// When virtualized, Virtualizer handles this internally.
|
|
667
|
-
|
|
668
|
-
useEffect(() => {
|
|
669
|
-
if (!isVirtualized && selectionManager.focusedKey && ref != null && ref.current) {
|
|
670
|
-
let element = ref.current.querySelector("[data-key=\"" + selectionManager.focusedKey + "\"]");
|
|
671
|
-
|
|
672
|
-
if (element) {
|
|
673
|
-
$a09ba753e08b703267f2392f7fc8e96$var$scrollIntoView(ref.current, element);
|
|
674
|
-
}
|
|
675
|
-
}
|
|
676
|
-
}, [isVirtualized, ref, selectionManager.focusedKey]);
|
|
677
|
-
let {
|
|
678
|
-
collectionProps
|
|
679
|
-
} = useSelectableCollection({
|
|
680
|
-
ref,
|
|
681
|
-
selectionManager,
|
|
682
|
-
keyboardDelegate: delegate,
|
|
683
|
-
autoFocus,
|
|
684
|
-
shouldFocusWrap,
|
|
685
|
-
disallowEmptySelection,
|
|
686
|
-
selectOnFocus,
|
|
687
|
-
disallowTypeAhead,
|
|
688
|
-
shouldUseVirtualFocus,
|
|
689
|
-
allowsTabNavigation
|
|
690
|
-
});
|
|
691
|
-
return {
|
|
692
|
-
listProps: collectionProps
|
|
693
|
-
};
|
|
694
|
-
}
|
|
695
|
-
/**
|
|
696
|
-
* Scrolls `scrollView` so that `element` is visible.
|
|
697
|
-
* Similar to `element.scrollIntoView({block: 'nearest'})` (not supported in Edge),
|
|
698
|
-
* but doesn't affect parents above `scrollView`.
|
|
699
|
-
*/
|
|
700
|
-
|
|
701
|
-
function $a09ba753e08b703267f2392f7fc8e96$var$scrollIntoView(scrollView, element) {
|
|
702
|
-
let offsetX = $a09ba753e08b703267f2392f7fc8e96$var$relativeOffset(scrollView, element, 'left');
|
|
703
|
-
let offsetY = $a09ba753e08b703267f2392f7fc8e96$var$relativeOffset(scrollView, element, 'top');
|
|
704
|
-
let width = element.offsetWidth;
|
|
705
|
-
let height = element.offsetHeight;
|
|
706
|
-
let x = scrollView.scrollLeft;
|
|
707
|
-
let y = scrollView.scrollTop;
|
|
708
|
-
let maxX = x + scrollView.offsetWidth;
|
|
709
|
-
let maxY = y + scrollView.offsetHeight;
|
|
710
|
-
|
|
711
|
-
if (offsetX <= x) {
|
|
712
|
-
x = offsetX;
|
|
713
|
-
} else if (offsetX + width > maxX) {
|
|
714
|
-
x += offsetX + width - maxX;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
if (offsetY <= y) {
|
|
718
|
-
y = offsetY;
|
|
719
|
-
} else if (offsetY + height > maxY) {
|
|
720
|
-
y += offsetY + height - maxY;
|
|
721
|
-
}
|
|
722
|
-
|
|
723
|
-
scrollView.scrollLeft = x;
|
|
724
|
-
scrollView.scrollTop = y;
|
|
725
|
-
}
|
|
726
|
-
/**
|
|
727
|
-
* Computes the offset left or top from child to ancestor by accumulating
|
|
728
|
-
* offsetLeft or offsetTop through intervening offsetParents.
|
|
729
|
-
*/
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
function $a09ba753e08b703267f2392f7fc8e96$var$relativeOffset(ancestor, child, axis) {
|
|
733
|
-
const prop = axis === 'left' ? 'offsetLeft' : 'offsetTop';
|
|
734
|
-
let sum = 0;
|
|
735
|
-
|
|
736
|
-
while (child.offsetParent) {
|
|
737
|
-
sum += child[prop];
|
|
738
|
-
|
|
739
|
-
if (child.offsetParent === ancestor) {
|
|
740
|
-
// Stop once we have found the ancestor we are interested in.
|
|
741
|
-
break;
|
|
742
|
-
} else if (child.offsetParent.contains(ancestor)) {
|
|
743
|
-
// If the ancestor is not `position:relative`, then we stop at
|
|
744
|
-
// _its_ offset parent, and we subtract off _its_ offset, so that
|
|
745
|
-
// we end up with the proper offset from child to ancestor.
|
|
746
|
-
sum -= ancestor[prop];
|
|
747
|
-
break;
|
|
748
|
-
}
|
|
749
562
|
|
|
750
|
-
child = child.offsetParent;
|
|
751
|
-
}
|
|
752
563
|
|
|
753
|
-
|
|
754
|
-
}
|
|
564
|
+
export {$f2918947066e8d51$export$d6daf82dcd84e87c as useSelectableCollection, $28b3f01514e02622$export$ecf600387e221c37 as useSelectableItem, $95210d28646fd635$export$b95089534ab7c1fd as useSelectableList, $57c17da9c35ecb23$export$a05409b8bb224a5a as ListKeyboardDelegate, $eb39f547daf47539$export$e32c88dfddc6e1d8 as useTypeSelect};
|
|
755
565
|
//# sourceMappingURL=module.js.map
|