@react-aria/selection 3.7.1 → 3.7.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -1,862 +1,585 @@
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 $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)) {
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
11
  }
83
12
 
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
- }
92
-
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 $e872cdf6539aaf0b$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
- }
165
-
166
- const navigateToKey = (key, childFocus) => {
167
- if (key != null) {
168
- manager.setFocusedKey(key, childFocus);
28
+ $parcel$export($e872cdf6539aaf0b$exports, "useSelectableCollection", () => $e872cdf6539aaf0b$export$d6daf82dcd84e87c);
169
29
 
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
30
 
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
31
 
185
- if (nextKey == null && shouldFocusWrap) {
186
- nextKey = delegate.getFirstKey == null ? void 0 : delegate.getFirstKey(manager.focusedKey);
187
- }
188
32
 
189
- navigateToKey(nextKey);
190
- }
191
33
 
192
- break;
193
- }
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
+ }
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 $f7ddb42583332a58$exports = {};
207
47
 
208
- break;
209
- }
48
+ $parcel$export($f7ddb42583332a58$exports, "useTypeSelect", () => $f7ddb42583332a58$export$e32c88dfddc6e1d8);
210
49
 
211
- case 'ArrowLeft':
212
- {
213
- 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) {
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 $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
+ }
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 $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
+ }
259
213
  }
260
-
261
- break;
262
-
263
- case 'PageDown':
264
- if (delegate.getKeyPageBelow) {
265
- e.preventDefault();
266
- let nextKey = delegate.getKeyPageBelow(manager.focusedKey);
267
- 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;
268
231
  }
269
-
270
- break;
271
-
272
- case 'PageUp':
273
- if (delegate.getKeyPageAbove) {
274
- e.preventDefault();
275
- let nextKey = delegate.getKeyPageAbove(manager.focusedKey);
276
- 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
+ }
277
259
  }
278
-
279
- break;
280
-
281
- case 'a':
282
- if ($d220314dfe032b5c2a0f0c46ec981e5$export$isCtrlKeyPressed(e) && manager.selectionMode === 'multiple' && disallowSelectAll !== true) {
283
- e.preventDefault();
284
- 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);
285
279
  }
286
-
287
- break;
288
-
289
- case 'Escape':
290
- e.preventDefault();
291
-
292
- if (!disallowEmptySelection) {
293
- 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);
294
289
  }
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
- }
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();
331
303
  }
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
304
  };
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
- }
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
372
320
  }
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
- };
321
+ };
492
322
  }
493
323
 
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
324
 
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
325
+ var $d4f3f6d764be397c$exports = {};
536
326
 
327
+ $parcel$export($d4f3f6d764be397c$exports, "useSelectableItem", () => $d4f3f6d764be397c$export$ecf600387e221c37);
537
328
 
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
329
 
551
- let itemProps = {};
552
330
 
553
- if (!shouldUseVirtualFocus) {
554
- itemProps = {
555
- tabIndex: isFocused ? 0 : -1,
556
331
 
557
- onFocus(e) {
558
- if (e.target === ref.current) {
559
- manager.setFocusedKey(key);
560
- }
561
- }
562
332
 
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);
346
+ }
563
347
  };
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
- }
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 = {
586
367
  };
587
-
588
- itemPressProps.onPressUp = e => {
589
- if (e.pointerType !== 'keyboard') {
590
- onSelect(e);
591
- }
368
+ if (!shouldUseVirtualFocus) itemProps = {
369
+ tabIndex: isFocused ? 0 : -1,
370
+ onFocus (e) {
371
+ if (e.target === ref.current) manager.setFocusedKey(key);
372
+ }
592
373
  };
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
- }
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 = {
603
386
  };
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);
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();
613
421
  }
614
- }
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
615
448
  };
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();
656
- }
657
- } : undefined;
658
- return {
659
- itemProps: mergeProps(itemProps, allowsSelection || hasPrimaryAction ? pressProps : {}, hasSecondaryAction ? longPressProps : {}, {
660
- onKeyUp,
661
- onDoubleClick
662
- }),
663
- isPressed
664
- };
665
449
  }
666
450
 
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
451
 
706
- getKeyAbove(key) {
707
- key = this.collection.getKeyBefore(key);
452
+ var $1908cf9b6ab7b508$exports = {};
708
453
 
709
- while (key != null) {
710
- let item = this.collection.getItem(key);
454
+ $parcel$export($1908cf9b6ab7b508$exports, "useSelectableList", () => $1908cf9b6ab7b508$export$b95089534ab7c1fd);
711
455
 
712
- if (item.type === 'item' && !this.disabledKeys.has(key)) {
713
- return key;
714
- }
456
+ var $4c5a6431f43e7e74$exports = {};
715
457
 
716
- 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;
717
465
  }
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);
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
+ }
731
473
  }
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);
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
+ }
745
481
  }
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;
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
+ }
758
489
  }
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);
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
+ }
765
497
  }
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;
498
+ getItem(key) {
499
+ return this.ref.current.querySelector(`[data-key="${key}"]`);
776
500
  }
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);
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;
511
+ }
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;
783
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
+ }
784
536
 
785
- return key;
786
- }
787
537
 
788
- getKeyForSearch(search, fromKey) {
789
- if (!this.collator) {
790
- return null;
791
- }
792
538
 
793
- let collection = this.collection;
794
- let key = fromKey || this.getFirstKey();
795
539
 
796
- while (key != null) {
797
- let item = collection.getItem(key);
798
- let substring = item.textValue.slice(0, search.length);
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
+ };
573
+ }
799
574
 
800
- if (item.textValue && this.collator.compare(substring, search) === 0) {
801
- return key;
802
- }
803
575
 
804
- key = this.getKeyBelow(key);
805
- }
806
576
 
807
- return null;
808
- }
809
577
 
810
- }
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);
811
583
 
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
584
 
861
- exports.useSelectableList = useSelectableList;
862
585
  //# sourceMappingURL=main.js.map