@react-aria/selection 3.7.1 → 3.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -1,823 +1,565 @@
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 $1GWK5$useRef, useEffect as $1GWK5$useEffect, useMemo as $1GWK5$useMemo} from "react";
2
+ import {getFocusableTreeWalker as $1GWK5$getFocusableTreeWalker, focusSafely as $1GWK5$focusSafely} from "@react-aria/focus";
3
+ import {focusWithoutScrolling as $1GWK5$focusWithoutScrolling, useEvent as $1GWK5$useEvent, scrollIntoView as $1GWK5$scrollIntoView, mergeProps as $1GWK5$mergeProps, isAppleDevice as $1GWK5$isAppleDevice, isMac as $1GWK5$isMac} from "@react-aria/utils";
4
+ import {useLocale as $1GWK5$useLocale, useCollator as $1GWK5$useCollator} from "@react-aria/i18n";
5
+ import {usePress as $1GWK5$usePress, useLongPress as $1GWK5$useLongPress} from "@react-aria/interactions";
6
+
7
+ function $parcel$export(e, n, v, s) {
8
+ Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
12
9
  }
10
+ var $f2918947066e8d51$exports = {};
13
11
 
14
- function $d9657c365c2f735bcaf048eee8599a4a$export$isCtrlKeyPressed(e) {
15
- if (isMac()) {
16
- return e.metaKey;
17
- }
12
+ $parcel$export($f2918947066e8d51$exports, "useSelectableCollection", () => $f2918947066e8d51$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 $003bf7ca80eac51f$export$d3e3bd3e26688c04(e) {
19
+ // Ctrl + Arrow Up/Arrow Down has a system wide meaning on macOS, so use Alt instead.
20
+ // On Windows and Ubuntu, Alt + Space has a system wide meaning.
21
+ return $1GWK5$isAppleDevice() ? e.altKey : e.ctrlKey;
22
+ }
23
+ function $003bf7ca80eac51f$export$16792effe837dba3(e) {
24
+ if ($1GWK5$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 $eb39f547daf47539$exports = {};
134
31
 
135
- const navigateToKey = (key, childFocus) => {
136
- if (key != null) {
137
- manager.setFocusedKey(key, childFocus);
32
+ $parcel$export($eb39f547daf47539$exports, "useTypeSelect", () => $eb39f547daf47539$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 $eb39f547daf47539$export$e32c88dfddc6e1d8(options) {
35
+ let { keyboardDelegate: keyboardDelegate , selectionManager: selectionManager , onTypeSelect: onTypeSelect } = options;
36
+ let state = $1GWK5$useRef({
37
+ search: '',
38
+ timeout: null
39
+ }).current;
40
+ let onKeyDown = (e)=>{
41
+ let character = $eb39f547daf47539$var$getStringForKey(e.key);
42
+ if (!character || e.ctrlKey || e.metaKey) return;
43
+ // Do not propagate the Spacebar event if it's meant to be part of the search.
44
+ // When we time out, the search term becomes empty, hence the check on length.
45
+ // Trimming is to account for the case of pressing the Spacebar more than once,
46
+ // which should cycle through the selection/deselection of the focused item.
47
+ if (character === ' ' && state.search.trim().length > 0) {
48
+ e.preventDefault();
49
+ if (!('continuePropagation' in e)) e.stopPropagation();
50
+ }
51
+ state.search += character;
52
+ // Use the delegate to find a key to focus.
53
+ // Prioritize items after the currently focused item, falling back to searching the whole list.
54
+ let key = keyboardDelegate.getKeyForSearch(state.search, selectionManager.focusedKey);
55
+ // If no key found, search from the top.
56
+ if (key == null) key = keyboardDelegate.getKeyForSearch(state.search);
57
+ if (key != null) {
58
+ selectionManager.setFocusedKey(key);
59
+ if (onTypeSelect) onTypeSelect(key);
60
+ }
61
+ clearTimeout(state.timeout);
62
+ state.timeout = setTimeout(()=>{
63
+ state.search = '';
64
+ }, 500);
65
+ };
66
+ return {
67
+ typeSelectProps: {
68
+ // Using a capturing listener to catch the keydown event before
69
+ // other hooks in order to handle the Spacebar event.
70
+ onKeyDownCapture: keyboardDelegate.getKeyForSearch ? onKeyDown : null
143
71
  }
144
- }
145
72
  };
73
+ }
74
+ function $eb39f547daf47539$var$getStringForKey(key) {
75
+ // If the key is of length 1, it is an ASCII value.
76
+ // Otherwise, if there are no ASCII characters in the key name,
77
+ // it is a Unicode character.
78
+ // See https://www.w3.org/TR/uievents-key/
79
+ if (key.length === 1 || !/^[A-Z]/i.test(key)) return key;
80
+ return '';
81
+ }
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 $f2918947066e8d51$export$d6daf82dcd84e87c(options) {
85
+ let { selectionManager: manager , keyboardDelegate: delegate , ref: ref , autoFocus: autoFocus = false , shouldFocusWrap: shouldFocusWrap = false , disallowEmptySelection: disallowEmptySelection = false , disallowSelectAll: disallowSelectAll = false , selectOnFocus: selectOnFocus = manager.selectionBehavior === 'replace' , disallowTypeAhead: disallowTypeAhead = false , shouldUseVirtualFocus: shouldUseVirtualFocus , allowsTabNavigation: allowsTabNavigation = false , isVirtualized: isVirtualized , scrollRef: // If no scrollRef is provided, assume the collection ref is the scrollable region
86
+ scrollRef = ref } = options;
87
+ let { direction: direction } = $1GWK5$useLocale();
88
+ let onKeyDown = (e)=>{
89
+ // Prevent option + tab from doing anything since it doesn't move focus to the cells, only buttons/checkboxes
90
+ if (e.altKey && e.key === 'Tab') e.preventDefault();
91
+ // Keyboard events bubble through portals. Don't handle keyboard events
92
+ // for elements outside the collection (e.g. menus).
93
+ if (!ref.current.contains(e.target)) return;
94
+ const navigateToKey = (key, childFocus)=>{
95
+ if (key != null) {
96
+ manager.setFocusedKey(key, childFocus);
97
+ if (e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(key);
98
+ else if (selectOnFocus && !$003bf7ca80eac51f$export$d3e3bd3e26688c04(e)) manager.replaceSelection(key);
156
99
  }
157
-
158
- navigateToKey(nextKey);
159
- }
160
-
161
- break;
100
+ };
101
+ switch(e.key){
102
+ case 'ArrowDown':
103
+ if (delegate.getKeyBelow) {
104
+ e.preventDefault();
105
+ let nextKey = manager.focusedKey != null ? delegate.getKeyBelow(manager.focusedKey) : delegate.getFirstKey?.();
106
+ if (nextKey == null && shouldFocusWrap) nextKey = delegate.getFirstKey?.(manager.focusedKey);
107
+ navigateToKey(nextKey);
108
+ }
109
+ break;
110
+ case 'ArrowUp':
111
+ if (delegate.getKeyAbove) {
112
+ e.preventDefault();
113
+ let nextKey = manager.focusedKey != null ? delegate.getKeyAbove(manager.focusedKey) : delegate.getLastKey?.();
114
+ if (nextKey == null && shouldFocusWrap) nextKey = delegate.getLastKey?.(manager.focusedKey);
115
+ navigateToKey(nextKey);
116
+ }
117
+ break;
118
+ case 'ArrowLeft':
119
+ if (delegate.getKeyLeftOf) {
120
+ e.preventDefault();
121
+ let nextKey = delegate.getKeyLeftOf(manager.focusedKey);
122
+ navigateToKey(nextKey, direction === 'rtl' ? 'first' : 'last');
123
+ }
124
+ break;
125
+ case 'ArrowRight':
126
+ if (delegate.getKeyRightOf) {
127
+ e.preventDefault();
128
+ let nextKey = delegate.getKeyRightOf(manager.focusedKey);
129
+ navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');
130
+ }
131
+ break;
132
+ case 'Home':
133
+ if (delegate.getFirstKey) {
134
+ e.preventDefault();
135
+ let firstKey = delegate.getFirstKey(manager.focusedKey, $003bf7ca80eac51f$export$16792effe837dba3(e));
136
+ manager.setFocusedKey(firstKey);
137
+ if ($003bf7ca80eac51f$export$16792effe837dba3(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(firstKey);
138
+ else if (selectOnFocus) manager.replaceSelection(firstKey);
139
+ }
140
+ break;
141
+ case 'End':
142
+ if (delegate.getLastKey) {
143
+ e.preventDefault();
144
+ let lastKey = delegate.getLastKey(manager.focusedKey, $003bf7ca80eac51f$export$16792effe837dba3(e));
145
+ manager.setFocusedKey(lastKey);
146
+ if ($003bf7ca80eac51f$export$16792effe837dba3(e) && e.shiftKey && manager.selectionMode === 'multiple') manager.extendSelection(lastKey);
147
+ else if (selectOnFocus) manager.replaceSelection(lastKey);
148
+ }
149
+ break;
150
+ case 'PageDown':
151
+ if (delegate.getKeyPageBelow) {
152
+ e.preventDefault();
153
+ let nextKey = delegate.getKeyPageBelow(manager.focusedKey);
154
+ navigateToKey(nextKey);
155
+ }
156
+ break;
157
+ case 'PageUp':
158
+ if (delegate.getKeyPageAbove) {
159
+ e.preventDefault();
160
+ let nextKey = delegate.getKeyPageAbove(manager.focusedKey);
161
+ navigateToKey(nextKey);
162
+ }
163
+ break;
164
+ case 'a':
165
+ if ($003bf7ca80eac51f$export$16792effe837dba3(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {
166
+ e.preventDefault();
167
+ manager.selectAll();
168
+ }
169
+ break;
170
+ case 'Escape':
171
+ e.preventDefault();
172
+ if (!disallowEmptySelection) manager.clearSelection();
173
+ break;
174
+ case 'Tab':
175
+ if (!allowsTabNavigation) {
176
+ // There may be elements that are "tabbable" inside a collection (e.g. in a grid cell).
177
+ // However, collections should be treated as a single tab stop, with arrow key navigation internally.
178
+ // We don't control the rendering of these, so we can't override the tabIndex to prevent tabbing.
179
+ // Instead, we handle the Tab key, and move focus manually to the first/last tabbable element
180
+ // in the collection, so that the browser default behavior will apply starting from that element
181
+ // rather than the currently focused one.
182
+ if (e.shiftKey) ref.current.focus();
183
+ else {
184
+ let walker = $1GWK5$getFocusableTreeWalker(ref.current, {
185
+ tabbable: true
186
+ });
187
+ let next;
188
+ let last;
189
+ do {
190
+ last = walker.lastChild();
191
+ if (last) next = last;
192
+ }while (last)
193
+ if (next && !next.contains(document.activeElement)) $1GWK5$focusWithoutScrolling(next);
194
+ }
195
+ break;
196
+ }
162
197
  }
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);
198
+ };
199
+ // Store the scroll position so we can restore it later.
200
+ let scrollPos = $1GWK5$useRef({
201
+ top: 0,
202
+ left: 0
203
+ });
204
+ $1GWK5$useEvent(scrollRef, 'scroll', isVirtualized ? null : ()=>{
205
+ scrollPos.current = {
206
+ top: scrollRef.current.scrollTop,
207
+ left: scrollRef.current.scrollLeft
208
+ };
209
+ });
210
+ let onFocus = (e)=>{
211
+ if (manager.isFocused) {
212
+ // If a focus event bubbled through a portal, reset focus state.
213
+ if (!e.currentTarget.contains(e.target)) manager.setFocused(false);
214
+ return;
215
+ }
216
+ // Focus events can bubble through portals. Ignore these events.
217
+ if (!e.currentTarget.contains(e.target)) return;
218
+ manager.setFocused(true);
219
+ if (manager.focusedKey == null) {
220
+ let navigateToFirstKey = (key)=>{
221
+ if (key != null) {
222
+ manager.setFocusedKey(key);
223
+ if (selectOnFocus) manager.replaceSelection(key);
224
+ }
225
+ };
226
+ // If the user hasn't yet interacted with the collection, there will be no focusedKey set.
227
+ // Attempt to detect whether the user is tabbing forward or backward into the collection
228
+ // and either focus the first or last item accordingly.
229
+ let relatedTarget = e.relatedTarget;
230
+ if (relatedTarget && e.currentTarget.compareDocumentPosition(relatedTarget) & Node.DOCUMENT_POSITION_FOLLOWING) navigateToFirstKey(manager.lastSelectedKey ?? delegate.getLastKey());
231
+ else navigateToFirstKey(manager.firstSelectedKey ?? delegate.getFirstKey());
232
+ } else if (!isVirtualized) {
233
+ // Restore the scroll position to what it was before.
234
+ scrollRef.current.scrollTop = scrollPos.current.top;
235
+ scrollRef.current.scrollLeft = scrollPos.current.left;
236
+ // Refocus and scroll the focused item into view if it exists within the scrollable region.
237
+ let element = scrollRef.current.querySelector(`[data-key="${manager.focusedKey}"]`);
238
+ if (element) {
239
+ // This prevents a flash of focus on the first/last element in the collection
240
+ $1GWK5$focusWithoutScrolling(element);
241
+ $1GWK5$scrollIntoView(scrollRef.current, element);
172
242
  }
173
-
174
- navigateToKey(nextKey);
175
- }
176
-
177
- break;
178
243
  }
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;
244
+ };
245
+ let onBlur = (e)=>{
246
+ // Don't set blurred and then focused again if moving focus within the collection.
247
+ if (!e.currentTarget.contains(e.relatedTarget)) manager.setFocused(false);
248
+ };
249
+ const autoFocusRef = $1GWK5$useRef(autoFocus);
250
+ $1GWK5$useEffect(()=>{
251
+ if (autoFocusRef.current) {
252
+ let focusedKey = null;
253
+ // Check focus strategy to determine which item to focus
254
+ if (autoFocus === 'first') focusedKey = delegate.getFirstKey();
255
+ if (autoFocus === 'last') focusedKey = delegate.getLastKey();
256
+ // If there are any selected keys, make the first one the new focus target
257
+ let selectedKeys = manager.selectedKeys;
258
+ if (selectedKeys.size) focusedKey = selectedKeys.values().next().value;
259
+ manager.setFocused(true);
260
+ manager.setFocusedKey(focusedKey);
261
+ // If no default focus key is selected, focus the collection itself.
262
+ if (focusedKey == null && !shouldUseVirtualFocus) $1GWK5$focusSafely(ref.current);
189
263
  }
190
-
191
- case 'ArrowRight':
192
- {
193
- if (delegate.getKeyRightOf) {
264
+ autoFocusRef.current = false;
265
+ // eslint-disable-next-line react-hooks/exhaustive-deps
266
+ }, []);
267
+ // If not virtualized, scroll the focused element into view when the focusedKey changes.
268
+ // When virtualized, Virtualizer handles this internally.
269
+ $1GWK5$useEffect(()=>{
270
+ if (!isVirtualized && manager.focusedKey && scrollRef?.current) {
271
+ let element = scrollRef.current.querySelector(`[data-key="${manager.focusedKey}"]`);
272
+ if (element) $1GWK5$scrollIntoView(scrollRef.current, element);
273
+ }
274
+ }, [
275
+ isVirtualized,
276
+ scrollRef,
277
+ manager.focusedKey
278
+ ]);
279
+ let handlers = {
280
+ onKeyDown: onKeyDown,
281
+ onFocus: onFocus,
282
+ onBlur: onBlur,
283
+ onMouseDown (e) {
284
+ // Ignore events that bubbled through portals.
285
+ if (e.currentTarget.contains(e.target)) // Prevent focus going to the collection when clicking on the scrollbar.
194
286
  e.preventDefault();
195
- let nextKey = delegate.getKeyRightOf(manager.focusedKey);
196
- navigateToKey(nextKey, direction === 'rtl' ? 'last' : 'first');
197
- }
198
-
199
- break;
200
287
  }
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
- }
288
+ };
289
+ let { typeSelectProps: typeSelectProps } = $eb39f547daf47539$export$e32c88dfddc6e1d8({
290
+ keyboardDelegate: delegate,
291
+ selectionManager: manager
292
+ });
293
+ if (!disallowTypeAhead) handlers = $1GWK5$mergeProps(typeSelectProps, handlers);
294
+ // If nothing is focused within the collection, make the collection itself tabbable.
295
+ // This will be marshalled to either the first or last item depending on where focus came from.
296
+ // If using virtual focus, don't set a tabIndex at all so that VoiceOver on iOS 14 doesn't try
297
+ // to move real DOM focus to the element anyway.
298
+ let tabIndex;
299
+ if (!shouldUseVirtualFocus) tabIndex = manager.focusedKey == null ? 0 : -1;
300
+ return {
301
+ collectionProps: {
302
+ ...handlers,
303
+ tabIndex: tabIndex
213
304
  }
305
+ };
306
+ }
214
307
 
215
- break;
216
308
 
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);
309
+ var $28b3f01514e02622$exports = {};
222
310
 
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
- }
311
+ $parcel$export($28b3f01514e02622$exports, "useSelectableItem", () => $28b3f01514e02622$export$ecf600387e221c37);
229
312
 
230
- break;
231
313
 
232
- case 'PageDown':
233
- if (delegate.getKeyPageBelow) {
234
- e.preventDefault();
235
- let nextKey = delegate.getKeyPageBelow(manager.focusedKey);
236
- navigateToKey(nextKey);
237
- }
238
314
 
239
- break;
240
315
 
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
316
 
250
- case 'a':
251
- if ($d9657c365c2f735bcaf048eee8599a4a$export$isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {
252
- e.preventDefault();
253
- manager.selectAll();
317
+ function $28b3f01514e02622$export$ecf600387e221c37(options) {
318
+ let { selectionManager: manager , key: key , ref: ref , shouldSelectOnPressUp: shouldSelectOnPressUp , isVirtualized: isVirtualized , shouldUseVirtualFocus: shouldUseVirtualFocus , focus: focus , isDisabled: isDisabled , onAction: onAction } = options;
319
+ let onSelect = (e)=>{
320
+ if (e.pointerType === 'keyboard' && $003bf7ca80eac51f$export$d3e3bd3e26688c04(e)) manager.toggleSelection(key);
321
+ else {
322
+ if (manager.selectionMode === 'none') return;
323
+ if (manager.selectionMode === 'single') {
324
+ if (manager.isSelected(key) && !manager.disallowEmptySelection) manager.toggleSelection(key);
325
+ else manager.replaceSelection(key);
326
+ } else if (e && e.shiftKey) manager.extendSelection(key);
327
+ else if (manager.selectionBehavior === 'toggle' || e && ($003bf7ca80eac51f$export$16792effe837dba3(e) || e.pointerType === 'touch' || e.pointerType === 'virtual')) // if touch or virtual (VO) then we just want to toggle, otherwise it's impossible to multi select because they don't have modifier keys
328
+ manager.toggleSelection(key);
329
+ else manager.replaceSelection(key);
254
330
  }
255
-
256
- break;
257
-
258
- case 'Escape':
259
- e.preventDefault();
260
-
261
- if (!disallowEmptySelection) {
262
- manager.clearSelection();
331
+ };
332
+ // Focus the associated DOM node when this item becomes the focusedKey
333
+ let isFocused = key === manager.focusedKey;
334
+ $1GWK5$useEffect(()=>{
335
+ if (isFocused && manager.isFocused && !shouldUseVirtualFocus && document.activeElement !== ref.current) {
336
+ if (focus) focus();
337
+ else $1GWK5$focusSafely(ref.current);
263
338
  }
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
- }
339
+ }, [
340
+ ref,
341
+ isFocused,
342
+ manager.focusedKey,
343
+ manager.childFocusStrategy,
344
+ manager.isFocused,
345
+ shouldUseVirtualFocus
346
+ ]);
347
+ // Set tabIndex to 0 if the element is focused, or -1 otherwise so that only the last focused
348
+ // item is tabbable. If using virtual focus, don't set a tabIndex at all so that VoiceOver
349
+ // on iOS 14 doesn't try to move real DOM focus to the item anyway.
350
+ let itemProps = {
351
+ };
352
+ if (!shouldUseVirtualFocus) itemProps = {
353
+ tabIndex: isFocused ? 0 : -1,
354
+ onFocus (e) {
355
+ if (e.target === ref.current) manager.setFocusedKey(key);
300
356
  }
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
357
  };
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;
358
+ let modality = $1GWK5$useRef(null);
359
+ let hasPrimaryAction = onAction && manager.selectionMode === 'none';
360
+ let hasSecondaryAction = onAction && manager.selectionMode !== 'none' && manager.selectionBehavior === 'replace';
361
+ let allowsSelection = !isDisabled && manager.canSelectItem(key);
362
+ // By default, selection occurs on pointer down. This can be strange if selecting an
363
+ // item causes the UI to disappear immediately (e.g. menus).
364
+ // If shouldSelectOnPressUp is true, we use onPressUp instead of onPressStart.
365
+ // onPress requires a pointer down event on the same element as pointer up. For menus,
366
+ // we want to be able to have the pointer down on the trigger that opens the menu and
367
+ // the pointer up on the menu item rather than requiring a separate press.
368
+ // For keyboard events, selection still occurs on key down.
369
+ let itemPressProps = {
370
+ };
371
+ if (shouldSelectOnPressUp) {
372
+ itemPressProps.onPressStart = (e)=>{
373
+ modality.current = e.pointerType;
374
+ if (e.pointerType === 'keyboard') onSelect(e);
375
+ };
376
+ itemPressProps.onPressUp = (e)=>{
377
+ if (e.pointerType !== 'keyboard') onSelect(e);
378
+ };
379
+ itemPressProps.onPress = hasPrimaryAction ? ()=>onAction()
380
+ : null;
381
+ } else {
382
+ // On touch, it feels strange to select on touch down, so we special case this.
383
+ itemPressProps.onPressStart = (e)=>{
384
+ modality.current = e.pointerType;
385
+ if (e.pointerType !== 'touch' && e.pointerType !== 'virtual') onSelect(e);
386
+ };
387
+ itemPressProps.onPress = (e)=>{
388
+ if (e.pointerType === 'touch' || e.pointerType === 'virtual' || hasPrimaryAction) {
389
+ // Single tap on touch with selectionBehavior = 'replace' performs an action, i.e. navigation.
390
+ // Also perform action on press up when selectionMode = 'none'.
391
+ if (hasPrimaryAction || hasSecondaryAction) onAction();
392
+ else onSelect(e);
393
+ }
394
+ };
329
395
  }
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
- }
396
+ if (!isVirtualized) itemProps['data-key'] = key;
397
+ itemPressProps.preventFocusOnPress = shouldUseVirtualFocus;
398
+ let { pressProps: pressProps , isPressed: isPressed } = $1GWK5$usePress(itemPressProps);
399
+ // Double clicking with a mouse with selectionBehavior = 'replace' performs an action.
400
+ let onDoubleClick = hasSecondaryAction ? (e)=>{
401
+ if (modality.current === 'mouse') {
402
+ e.stopPropagation();
403
+ e.preventDefault();
404
+ onAction();
341
405
  }
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
- }
406
+ } : undefined;
407
+ // Long pressing an item with touch when selectionBehavior = 'replace' switches the selection behavior
408
+ // to 'toggle'. This changes the single tap behavior from performing an action (i.e. navigating) to
409
+ // selecting, and may toggle the appearance of a UI affordance like checkboxes on each item.
410
+ // TODO: what about when drag and drop is also enabled??
411
+ let { longPressProps: longPressProps } = $1GWK5$useLongPress({
412
+ isDisabled: !hasSecondaryAction,
413
+ onLongPress (e) {
414
+ if (e.pointerType === 'touch') {
415
+ onSelect(e);
416
+ manager.setSelectionBehavior('toggle');
417
+ }
418
+ }
419
+ });
420
+ // Pressing the Enter key with selectionBehavior = 'replace' performs an action (i.e. navigation).
421
+ let onKeyUp = hasSecondaryAction ? (e)=>{
422
+ if (e.key === 'Enter') onAction();
423
+ } : undefined;
424
+ return {
425
+ itemProps: $1GWK5$mergeProps(itemProps, allowsSelection || hasPrimaryAction ? pressProps : {
426
+ }, hasSecondaryAction ? longPressProps : {
427
+ }, {
428
+ onKeyUp: onKeyUp,
429
+ onDoubleClick: onDoubleClick
430
+ }),
431
+ isPressed: isPressed
432
+ };
433
+ }
399
434
 
400
- manager.setFocused(true);
401
- manager.setFocusedKey(focusedKey); // If no default focus key is selected, focus the collection itself.
402
435
 
403
- if (focusedKey == null && !shouldUseVirtualFocus) {
404
- focusSafely(ref.current);
405
- }
406
- }
436
+ var $95210d28646fd635$exports = {};
407
437
 
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.
438
+ $parcel$export($95210d28646fd635$exports, "useSelectableList", () => $95210d28646fd635$export$b95089534ab7c1fd);
411
439
 
412
- useEffect(() => {
413
- if (!isVirtualized && manager.focusedKey && scrollRef != null && scrollRef.current) {
414
- let element = scrollRef.current.querySelector("[data-key=\"" + manager.focusedKey + "\"]");
440
+ var $57c17da9c35ecb23$exports = {};
415
441
 
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
- }
442
+ $parcel$export($57c17da9c35ecb23$exports, "ListKeyboardDelegate", () => $57c17da9c35ecb23$export$a05409b8bb224a5a);
443
+ class $57c17da9c35ecb23$export$a05409b8bb224a5a {
444
+ constructor(collection, disabledKeys, ref, collator){
445
+ this.collection = collection;
446
+ this.disabledKeys = disabledKeys;
447
+ this.ref = ref;
448
+ this.collator = collator;
432
449
  }
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
- } 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);
450
+ getKeyBelow(key) {
451
+ key = this.collection.getKeyAfter(key);
452
+ while(key != null){
453
+ let item = this.collection.getItem(key);
454
+ if (item.type === 'item' && !this.disabledKeys.has(key)) return key;
455
+ key = this.collection.getKeyAfter(key);
492
456
  }
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
- }
513
457
  }
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);
458
+ getKeyAbove(key) {
459
+ key = this.collection.getKeyBefore(key);
460
+ while(key != null){
461
+ let item = this.collection.getItem(key);
462
+ if (item.type === 'item' && !this.disabledKeys.has(key)) return key;
463
+ key = this.collection.getKeyBefore(key);
527
464
  }
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
- }
553
- };
554
-
555
- itemPressProps.onPressUp = e => {
556
- if (e.pointerType !== 'keyboard') {
557
- onSelect(e);
558
- }
559
- };
560
-
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;
566
-
567
- if (e.pointerType !== 'touch' && e.pointerType !== 'virtual') {
568
- onSelect(e);
569
- }
570
- };
571
-
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);
580
- }
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
- }
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
- }
616
465
  }
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();
466
+ getFirstKey() {
467
+ let key = this.collection.getFirstKey();
468
+ while(key != null){
469
+ let item = this.collection.getItem(key);
470
+ if (item.type === 'item' && !this.disabledKeys.has(key)) return key;
471
+ key = this.collection.getKeyAfter(key);
472
+ }
623
473
  }
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);
474
+ getLastKey() {
475
+ let key = this.collection.getLastKey();
476
+ while(key != null){
477
+ let item = this.collection.getItem(key);
478
+ if (item.type === 'item' && !this.disabledKeys.has(key)) return key;
479
+ key = this.collection.getKeyBefore(key);
480
+ }
668
481
  }
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);
482
+ getItem(key) {
483
+ return this.ref.current.querySelector(`[data-key="${key}"]`);
682
484
  }
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)) {
485
+ getKeyPageAbove(key) {
486
+ let menu = this.ref.current;
487
+ let item = this.getItem(key);
488
+ if (!item) return null;
489
+ let pageY = Math.max(0, item.offsetTop + item.offsetHeight - menu.offsetHeight);
490
+ while(item && item.offsetTop > pageY){
491
+ key = this.getKeyAbove(key);
492
+ item = this.getItem(key);
493
+ }
692
494
  return key;
693
- }
694
-
695
- key = this.collection.getKeyAfter(key);
696
495
  }
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)) {
496
+ getKeyPageBelow(key) {
497
+ let menu = this.ref.current;
498
+ let item = this.getItem(key);
499
+ if (!item) return null;
500
+ let pageY = Math.min(menu.scrollHeight, item.offsetTop - item.offsetHeight + menu.offsetHeight);
501
+ while(item && item.offsetTop < pageY){
502
+ key = this.getKeyBelow(key);
503
+ item = this.getItem(key);
504
+ }
706
505
  return key;
707
- }
708
-
709
- key = this.collection.getKeyBefore(key);
710
506
  }
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);
730
- }
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;
507
+ getKeyForSearch(search, fromKey) {
508
+ if (!this.collator) return null;
509
+ let collection = this.collection;
510
+ let key = fromKey || this.getFirstKey();
511
+ while(key != null){
512
+ let item = collection.getItem(key);
513
+ let substring = item.textValue.slice(0, search.length);
514
+ if (item.textValue && this.collator.compare(substring, search) === 0) return key;
515
+ key = this.getKeyBelow(key);
516
+ }
517
+ return null;
741
518
  }
519
+ }
742
520
 
743
- let pageY = Math.min(menu.scrollHeight, item.offsetTop - item.offsetHeight + menu.offsetHeight);
744
521
 
745
- while (item && item.offsetTop < pageY) {
746
- key = this.getKeyBelow(key);
747
- item = this.getItem(key);
748
- }
749
522
 
750
- return key;
751
- }
752
523
 
753
- getKeyForSearch(search, fromKey) {
754
- if (!this.collator) {
755
- return null;
756
- }
757
-
758
- let collection = this.collection;
759
- let key = fromKey || this.getFirstKey();
524
+ function $95210d28646fd635$export$b95089534ab7c1fd(props) {
525
+ let { selectionManager: selectionManager , collection: collection , disabledKeys: disabledKeys , ref: ref , keyboardDelegate: keyboardDelegate , autoFocus: autoFocus , shouldFocusWrap: shouldFocusWrap , isVirtualized: isVirtualized , disallowEmptySelection: disallowEmptySelection , selectOnFocus: selectOnFocus = false , disallowTypeAhead: disallowTypeAhead , shouldUseVirtualFocus: shouldUseVirtualFocus , allowsTabNavigation: allowsTabNavigation } = props;
526
+ // By default, a KeyboardDelegate is provided which uses the DOM to query layout information (e.g. for page up/page down).
527
+ // When virtualized, the layout object will be passed in as a prop and override this.
528
+ let collator = $1GWK5$useCollator({
529
+ usage: 'search',
530
+ sensitivity: 'base'
531
+ });
532
+ let delegate = $1GWK5$useMemo(()=>keyboardDelegate || new $57c17da9c35ecb23$export$a05409b8bb224a5a(collection, disabledKeys, ref, collator)
533
+ , [
534
+ keyboardDelegate,
535
+ collection,
536
+ disabledKeys,
537
+ ref,
538
+ collator
539
+ ]);
540
+ let { collectionProps: collectionProps } = $f2918947066e8d51$export$d6daf82dcd84e87c({
541
+ ref: ref,
542
+ selectionManager: selectionManager,
543
+ keyboardDelegate: delegate,
544
+ autoFocus: autoFocus,
545
+ shouldFocusWrap: shouldFocusWrap,
546
+ disallowEmptySelection: disallowEmptySelection,
547
+ selectOnFocus: selectOnFocus,
548
+ disallowTypeAhead: disallowTypeAhead,
549
+ shouldUseVirtualFocus: shouldUseVirtualFocus,
550
+ allowsTabNavigation: allowsTabNavigation,
551
+ isVirtualized: isVirtualized,
552
+ scrollRef: ref
553
+ });
554
+ return {
555
+ listProps: collectionProps
556
+ };
557
+ }
760
558
 
761
- while (key != null) {
762
- let item = collection.getItem(key);
763
- let substring = item.textValue.slice(0, search.length);
764
559
 
765
- if (item.textValue && this.collator.compare(substring, search) === 0) {
766
- return key;
767
- }
768
560
 
769
- key = this.getKeyBelow(key);
770
- }
771
561
 
772
- return null;
773
- }
774
562
 
775
- }
776
563
 
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
- }
564
+ export {$f2918947066e8d51$export$d6daf82dcd84e87c as useSelectableCollection, $28b3f01514e02622$export$ecf600387e221c37 as useSelectableItem, $95210d28646fd635$export$b95089534ab7c1fd as useSelectableList, $57c17da9c35ecb23$export$a05409b8bb224a5a as ListKeyboardDelegate, $eb39f547daf47539$export$e32c88dfddc6e1d8 as useTypeSelect};
823
565
  //# sourceMappingURL=module.js.map