@react-aria/selection 3.5.1 → 3.7.2

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