@react-aria/selection 3.7.1 → 3.8.0

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