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