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