@react-aria/selection 3.7.1 → 3.8.0

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